From d28d30889f3968287f7231753b4b4355321d4156 Mon Sep 17 00:00:00 2001 From: Continuous Integration Date: Sun, 22 Sep 2024 08:22:03 +0000 Subject: [PATCH] Publish code coverage. --- coverage_log/amber.png | Bin 0 -> 141 bytes coverage_log/emerald.png | Bin 0 -> 141 bytes coverage_log/gcov.css | 519 + coverage_log/glass.png | Bin 0 -> 167 bytes .../include/internal/index-sort-b.html | 107 + .../include/internal/index-sort-f.html | 107 + .../include/internal/index-sort-l.html | 107 + coverage_log/include/internal/index.html | 107 + .../libspdm_common_lib.h.func-sort-c.html | 89 + .../internal/libspdm_common_lib.h.func.html | 89 + .../internal/libspdm_common_lib.h.gcov.html | 1815 ++++ coverage_log/index-sort-b.html | 539 ++ coverage_log/index-sort-f.html | 539 ++ coverage_log/index-sort-l.html | 539 ++ coverage_log/index.html | 539 ++ .../library/spdm_common_lib/index-sort-b.html | 179 + .../library/spdm_common_lib/index-sort-f.html | 179 + .../library/spdm_common_lib/index-sort-l.html | 179 + .../library/spdm_common_lib/index.html | 179 + ...ibspdm_com_context_data.c.func-sort-c.html | 361 + .../libspdm_com_context_data.c.func.html | 361 + .../libspdm_com_context_data.c.gcov.html | 3384 +++++++ ...om_context_data_session.c.func-sort-c.html | 113 + ...bspdm_com_context_data_session.c.func.html | 113 + ...bspdm_com_context_data_session.c.gcov.html | 386 + ...spdm_com_crypto_service.c.func-sort-c.html | 157 + .../libspdm_com_crypto_service.c.func.html | 157 + .../libspdm_com_crypto_service.c.gcov.html | 1236 +++ ..._crypto_service_session.c.func-sort-c.html | 109 + ...pdm_com_crypto_service_session.c.func.html | 109 + ...pdm_com_crypto_service_session.c.gcov.html | 829 ++ .../libspdm_com_msg_log.c.func-sort-c.html | 105 + .../libspdm_com_msg_log.c.func.html | 105 + .../libspdm_com_msg_log.c.gcov.html | 183 + ...libspdm_com_opaque_data.c.func-sort-c.html | 101 + .../libspdm_com_opaque_data.c.func.html | 101 + .../libspdm_com_opaque_data.c.gcov.html | 418 + .../libspdm_com_support.c.func-sort-c.html | 161 + .../libspdm_com_support.c.func.html | 161 + .../libspdm_com_support.c.gcov.html | 454 + .../spdm_crypt_lib/fips/index-sort-b.html | 239 + .../spdm_crypt_lib/fips/index-sort-f.html | 239 + .../spdm_crypt_lib/fips/index-sort-l.html | 239 + .../library/spdm_crypt_lib/fips/index.html | 239 + .../fips/libspdm_selftest.c.func-sort-c.html | 85 + .../fips/libspdm_selftest.c.func.html | 85 + .../fips/libspdm_selftest.c.gcov.html | 136 + ...ibspdm_selftest_aes_gcm.c.func-sort-c.html | 85 + .../fips/libspdm_selftest_aes_gcm.c.func.html | 85 + .../fips/libspdm_selftest_aes_gcm.c.gcov.html | 261 + .../libspdm_selftest_ecdh.c.func-sort-c.html | 85 + .../fips/libspdm_selftest_ecdh.c.func.html | 85 + .../fips/libspdm_selftest_ecdh.c.gcov.html | 208 + .../libspdm_selftest_ecdsa.c.func-sort-c.html | 89 + .../fips/libspdm_selftest_ecdsa.c.func.html | 89 + .../fips/libspdm_selftest_ecdsa.c.gcov.html | 259 + .../libspdm_selftest_eddsa.c.func-sort-c.html | 85 + .../fips/libspdm_selftest_eddsa.c.func.html | 85 + .../fips/libspdm_selftest_eddsa.c.gcov.html | 361 + .../libspdm_selftest_ffdh.c.func-sort-c.html | 85 + .../fips/libspdm_selftest_ffdh.c.func.html | 85 + .../fips/libspdm_selftest_ffdh.c.gcov.html | 223 + .../libspdm_selftest_hkdf.c.func-sort-c.html | 85 + .../fips/libspdm_selftest_hkdf.c.func.html | 85 + .../fips/libspdm_selftest_hkdf.c.gcov.html | 203 + .../libspdm_selftest_hmac.c.func-sort-c.html | 93 + .../fips/libspdm_selftest_hmac.c.func.html | 93 + .../fips/libspdm_selftest_hmac.c.gcov.html | 286 + ...ibspdm_selftest_rsa_pss.c.func-sort-c.html | 85 + .../fips/libspdm_selftest_rsa_pss.c.func.html | 85 + .../fips/libspdm_selftest_rsa_pss.c.gcov.html | 294 + ...ibspdm_selftest_rsa_ssa.c.func-sort-c.html | 85 + .../fips/libspdm_selftest_rsa_ssa.c.func.html | 85 + .../fips/libspdm_selftest_rsa_ssa.c.gcov.html | 327 + .../libspdm_selftest_sha2.c.func-sort-c.html | 93 + .../fips/libspdm_selftest_sha2.c.func.html | 93 + .../fips/libspdm_selftest_sha2.c.gcov.html | 209 + .../libspdm_selftest_sha3.c.func-sort-c.html | 93 + .../fips/libspdm_selftest_sha3.c.func.html | 93 + .../fips/libspdm_selftest_sha3.c.gcov.html | 287 + .../library/spdm_crypt_lib/index-sort-b.html | 191 + .../library/spdm_crypt_lib/index-sort-f.html | 191 + .../library/spdm_crypt_lib/index-sort-l.html | 191 + .../library/spdm_crypt_lib/index.html | 191 + .../libspdm_crypt_aead.c.func-sort-c.html | 101 + .../libspdm_crypt_aead.c.func.html | 101 + .../libspdm_crypt_aead.c.gcov.html | 291 + .../libspdm_crypt_asym.c.func-sort-c.html | 225 + .../libspdm_crypt_asym.c.func.html | 225 + .../libspdm_crypt_asym.c.gcov.html | 1942 ++++ .../libspdm_crypt_cert.c.func-sort-c.html | 189 + .../libspdm_crypt_cert.c.func.html | 189 + .../libspdm_crypt_cert.c.gcov.html | 2125 +++++ .../libspdm_crypt_dhe.c.func-sort-c.html | 105 + .../libspdm_crypt_dhe.c.func.html | 105 + .../libspdm_crypt_dhe.c.gcov.html | 438 + .../libspdm_crypt_hash.c.func-sort-c.html | 121 + .../libspdm_crypt_hash.c.func.html | 121 + .../libspdm_crypt_hash.c.gcov.html | 606 ++ .../libspdm_crypt_hkdf.c.func-sort-c.html | 89 + .../libspdm_crypt_hkdf.c.func.html | 89 + .../libspdm_crypt_hkdf.c.gcov.html | 214 + .../libspdm_crypt_hmac.c.func-sort-c.html | 109 + .../libspdm_crypt_hmac.c.func.html | 109 + .../libspdm_crypt_hmac.c.gcov.html | 514 + .../libspdm_crypt_rng.c.func-sort-c.html | 85 + .../libspdm_crypt_rng.c.func.html | 85 + .../libspdm_crypt_rng.c.gcov.html | 100 + .../spdm_requester_lib/index-sort-b.html | 467 + .../spdm_requester_lib/index-sort-f.html | 467 + .../spdm_requester_lib/index-sort-l.html | 467 + .../library/spdm_requester_lib/index.html | 467 + .../libspdm_req_challenge.c.func-sort-c.html | 97 + .../libspdm_req_challenge.c.func.html | 97 + .../libspdm_req_challenge.c.gcov.html | 598 ++ .../libspdm_req_common.c.func-sort-c.html | 93 + .../libspdm_req_common.c.func.html | 93 + .../libspdm_req_common.c.gcov.html | 267 + ...m_req_encap_certificate.c.func-sort-c.html | 85 + .../libspdm_req_encap_certificate.c.func.html | 85 + .../libspdm_req_encap_certificate.c.gcov.html | 238 + ...eq_encap_challenge_auth.c.func-sort-c.html | 85 + ...bspdm_req_encap_challenge_auth.c.func.html | 85 + ...bspdm_req_encap_challenge_auth.c.gcov.html | 316 + ...bspdm_req_encap_digests.c.func-sort-c.html | 85 + .../libspdm_req_encap_digests.c.func.html | 85 + .../libspdm_req_encap_digests.c.gcov.html | 253 + ...libspdm_req_encap_error.c.func-sort-c.html | 89 + .../libspdm_req_encap_error.c.func.html | 89 + .../libspdm_req_encap_error.c.gcov.html | 137 + ...dm_req_encap_key_update.c.func-sort-c.html | 85 + .../libspdm_req_encap_key_update.c.func.html | 85 + .../libspdm_req_encap_key_update.c.gcov.html | 238 + ...bspdm_req_encap_request.c.func-sort-c.html | 101 + .../libspdm_req_encap_request.c.func.html | 101 + .../libspdm_req_encap_request.c.gcov.html | 538 ++ ...libspdm_req_end_session.c.func-sort-c.html | 89 + .../libspdm_req_end_session.c.func.html | 89 + .../libspdm_req_end_session.c.gcov.html | 267 + .../libspdm_req_finish.c.func-sort-c.html | 101 + .../libspdm_req_finish.c.func.html | 101 + .../libspdm_req_finish.c.gcov.html | 725 ++ ...dm_req_get_capabilities.c.func-sort-c.html | 93 + .../libspdm_req_get_capabilities.c.func.html | 93 + .../libspdm_req_get_capabilities.c.gcov.html | 496 + ...pdm_req_get_certificate.c.func-sort-c.html | 101 + .../libspdm_req_get_certificate.c.func.html | 101 + .../libspdm_req_get_certificate.c.gcov.html | 589 ++ .../libspdm_req_get_csr.c.func-sort-c.html | 93 + .../libspdm_req_get_csr.c.func.html | 93 + .../libspdm_req_get_csr.c.gcov.html | 395 + ...libspdm_req_get_digests.c.func-sort-c.html | 89 + .../libspdm_req_get_digests.c.func.html | 89 + .../libspdm_req_get_digests.c.gcov.html | 445 + ...pdm_req_get_event_types.c.func-sort-c.html | 89 + .../libspdm_req_get_event_types.c.func.html | 89 + .../libspdm_req_get_event_types.c.gcov.html | 266 + ...m_req_get_key_pair_info.c.func-sort-c.html | 89 + .../libspdm_req_get_key_pair_info.c.func.html | 89 + .../libspdm_req_get_key_pair_info.c.gcov.html | 359 + ...asurement_extension_log.c.func-sort-c.html | 93 + ..._get_measurement_extension_log.c.func.html | 93 + ..._get_measurement_extension_log.c.gcov.html | 382 + ...dm_req_get_measurements.c.func-sort-c.html | 101 + .../libspdm_req_get_measurements.c.func.html | 101 + .../libspdm_req_get_measurements.c.gcov.html | 922 ++ ...libspdm_req_get_version.c.func-sort-c.html | 89 + .../libspdm_req_get_version.c.func.html | 89 + .../libspdm_req_get_version.c.gcov.html | 320 + ...q_handle_error_response.c.func-sort-c.html | 101 + ...spdm_req_handle_error_response.c.func.html | 101 + ...spdm_req_handle_error_response.c.gcov.html | 523 ++ .../libspdm_req_heartbeat.c.func-sort-c.html | 89 + .../libspdm_req_heartbeat.c.func.html | 89 + .../libspdm_req_heartbeat.c.gcov.html | 255 + ...ibspdm_req_key_exchange.c.func-sort-c.html | 101 + .../libspdm_req_key_exchange.c.func.html | 101 + .../libspdm_req_key_exchange.c.gcov.html | 972 ++ .../libspdm_req_key_update.c.func-sort-c.html | 89 + .../libspdm_req_key_update.c.func.html | 89 + .../libspdm_req_key_update.c.gcov.html | 436 + ...eq_negotiate_algorithms.c.func-sort-c.html | 89 + ...bspdm_req_negotiate_algorithms.c.func.html | 89 + ...bspdm_req_negotiate_algorithms.c.gcov.html | 752 ++ ...ibspdm_req_psk_exchange.c.func-sort-c.html | 97 + .../libspdm_req_psk_exchange.c.func.html | 97 + .../libspdm_req_psk_exchange.c.gcov.html | 735 ++ .../libspdm_req_psk_finish.c.func-sort-c.html | 93 + .../libspdm_req_psk_finish.c.func.html | 93 + .../libspdm_req_psk_finish.c.gcov.html | 400 + ...ibspdm_req_send_receive.c.func-sort-c.html | 101 + .../libspdm_req_send_receive.c.func.html | 101 + .../libspdm_req_send_receive.c.gcov.html | 840 ++ ...pdm_req_set_certificate.c.func-sort-c.html | 93 + .../libspdm_req_set_certificate.c.func.html | 93 + .../libspdm_req_set_certificate.c.gcov.html | 361 + ...m_req_set_key_pair_info.c.func-sort-c.html | 89 + .../libspdm_req_set_key_pair_info.c.func.html | 89 + .../libspdm_req_set_key_pair_info.c.gcov.html | 299 + ...q_subscribe_event_types.c.func-sort-c.html | 89 + ...spdm_req_subscribe_event_types.c.func.html | 89 + ...spdm_req_subscribe_event_types.c.gcov.html | 267 + ...spdm_req_vendor_request.c.func-sort-c.html | 89 + .../libspdm_req_vendor_request.c.func.html | 89 + .../libspdm_req_vendor_request.c.gcov.html | 358 + .../spdm_responder_lib/index-sort-b.html | 503 + .../spdm_responder_lib/index-sort-f.html | 503 + .../spdm_responder_lib/index-sort-l.html | 503 + .../library/spdm_responder_lib/index.html | 503 + .../libspdm_rsp_algorithms.c.func-sort-c.html | 89 + .../libspdm_rsp_algorithms.c.func.html | 89 + .../libspdm_rsp_algorithms.c.gcov.html | 960 ++ ...ibspdm_rsp_capabilities.c.func-sort-c.html | 93 + .../libspdm_rsp_capabilities.c.func.html | 93 + .../libspdm_rsp_capabilities.c.gcov.html | 392 + ...libspdm_rsp_certificate.c.func-sort-c.html | 85 + .../libspdm_rsp_certificate.c.func.html | 85 + .../libspdm_rsp_certificate.c.gcov.html | 265 + ...spdm_rsp_challenge_auth.c.func-sort-c.html | 85 + .../libspdm_rsp_challenge_auth.c.func.html | 85 + .../libspdm_rsp_challenge_auth.c.gcov.html | 424 + .../libspdm_rsp_chunk_get.c.func-sort-c.html | 85 + .../libspdm_rsp_chunk_get.c.func.html | 85 + .../libspdm_rsp_chunk_get.c.gcov.html | 260 + ...spdm_rsp_chunk_send_ack.c.func-sort-c.html | 85 + .../libspdm_rsp_chunk_send_ack.c.func.html | 85 + .../libspdm_rsp_chunk_send_ack.c.gcov.html | 333 + .../libspdm_rsp_common.c.func-sort-c.html | 93 + .../libspdm_rsp_common.c.func.html | 93 + .../libspdm_rsp_common.c.gcov.html | 265 + .../libspdm_rsp_csr.c.func-sort-c.html | 85 + .../libspdm_rsp_csr.c.func.html | 85 + .../libspdm_rsp_csr.c.gcov.html | 360 + .../libspdm_rsp_digests.c.func-sort-c.html | 85 + .../libspdm_rsp_digests.c.func.html | 85 + .../libspdm_rsp_digests.c.gcov.html | 285 + ...pdm_rsp_encap_challenge.c.func-sort-c.html | 89 + .../libspdm_rsp_encap_challenge.c.func.html | 89 + .../libspdm_rsp_encap_challenge.c.gcov.html | 354 + ...p_encap_get_certificate.c.func-sort-c.html | 89 + ...spdm_rsp_encap_get_certificate.c.func.html | 89 + ...spdm_rsp_encap_get_certificate.c.gcov.html | 336 + ...m_rsp_encap_get_digests.c.func-sort-c.html | 89 + .../libspdm_rsp_encap_get_digests.c.func.html | 89 + .../libspdm_rsp_encap_get_digests.c.gcov.html | 343 + ...dm_rsp_encap_key_update.c.func-sort-c.html | 89 + .../libspdm_rsp_encap_key_update.c.func.html | 89 + .../libspdm_rsp_encap_key_update.c.gcov.html | 301 + ...spdm_rsp_encap_response.c.func-sort-c.html | 117 + .../libspdm_rsp_encap_response.c.func.html | 117 + .../libspdm_rsp_encap_response.c.gcov.html | 620 ++ ...libspdm_rsp_end_session.c.func-sort-c.html | 85 + .../libspdm_rsp_end_session.c.func.html | 85 + .../libspdm_rsp_end_session.c.gcov.html | 180 + .../libspdm_rsp_error.c.func-sort-c.html | 89 + .../libspdm_rsp_error.c.func.html | 89 + .../libspdm_rsp_error.c.gcov.html | 145 + .../libspdm_rsp_finish.c.func-sort-c.html | 97 + .../libspdm_rsp_finish.c.func.html | 97 + .../libspdm_rsp_finish.c.gcov.html | 747 ++ ...m_rsp_get_key_pair_info.c.func-sort-c.html | 85 + .../libspdm_rsp_get_key_pair_info.c.func.html | 85 + .../libspdm_rsp_get_key_pair_info.c.gcov.html | 242 + ...p_handle_response_state.c.func-sort-c.html | 85 + ...spdm_rsp_handle_response_state.c.func.html | 85 + ...spdm_rsp_handle_response_state.c.gcov.html | 147 + .../libspdm_rsp_heartbeat.c.func-sort-c.html | 85 + .../libspdm_rsp_heartbeat.c.func.html | 85 + .../libspdm_rsp_heartbeat.c.gcov.html | 190 + ...ibspdm_rsp_key_exchange.c.func-sort-c.html | 93 + .../libspdm_rsp_key_exchange.c.func.html | 93 + .../libspdm_rsp_key_exchange.c.gcov.html | 717 ++ .../libspdm_rsp_key_update.c.func-sort-c.html | 85 + .../libspdm_rsp_key_update.c.func.html | 85 + .../libspdm_rsp_key_update.c.gcov.html | 328 + ...asurement_extension_log.c.func-sort-c.html | 85 + ..._rsp_measurement_extension_log.c.func.html | 85 + ..._rsp_measurement_extension_log.c.gcov.html | 243 + ...ibspdm_rsp_measurements.c.func-sort-c.html | 89 + .../libspdm_rsp_measurements.c.func.html | 89 + .../libspdm_rsp_measurements.c.gcov.html | 570 ++ ...ibspdm_rsp_psk_exchange.c.func-sort-c.html | 89 + .../libspdm_rsp_psk_exchange.c.func.html | 89 + .../libspdm_rsp_psk_exchange.c.gcov.html | 564 ++ .../libspdm_rsp_psk_finish.c.func-sort-c.html | 89 + .../libspdm_rsp_psk_finish.c.func.html | 89 + .../libspdm_rsp_psk_finish.c.gcov.html | 337 + ...ibspdm_rsp_receive_send.c.func-sort-c.html | 137 + .../libspdm_rsp_receive_send.c.func.html | 137 + .../libspdm_rsp_receive_send.c.gcov.html | 1005 ++ ...dm_rsp_respond_if_ready.c.func-sort-c.html | 85 + .../libspdm_rsp_respond_if_ready.c.func.html | 85 + .../libspdm_rsp_respond_if_ready.c.gcov.html | 160 + ...pdm_rsp_set_certificate.c.func-sort-c.html | 89 + .../libspdm_rsp_set_certificate.c.func.html | 89 + .../libspdm_rsp_set_certificate.c.gcov.html | 383 + ...p_set_key_pair_info_ack.c.func-sort-c.html | 85 + ...spdm_rsp_set_key_pair_info_ack.c.func.html | 85 + ...spdm_rsp_set_key_pair_info_ack.c.gcov.html | 350 + ...bscribe_event_types_ack.c.func-sort-c.html | 85 + ..._rsp_subscribe_event_types_ack.c.func.html | 85 + ..._rsp_subscribe_event_types_ack.c.gcov.html | 235 + ...p_supported_event_types.c.func-sort-c.html | 85 + ...spdm_rsp_supported_event_types.c.func.html | 85 + ...spdm_rsp_supported_event_types.c.gcov.html | 208 + ...pdm_rsp_vendor_response.c.func-sort-c.html | 93 + .../libspdm_rsp_vendor_response.c.func.html | 93 + .../libspdm_rsp_vendor_response.c.gcov.html | 305 + .../libspdm_rsp_version.c.func-sort-c.html | 89 + .../libspdm_rsp_version.c.func.html | 89 + .../libspdm_rsp_version.c.gcov.html | 220 + .../index-sort-b.html | 143 + .../index-sort-f.html | 143 + .../index-sort-l.html | 143 + .../spdm_secured_message_lib/index.html | 143 + ...pdm_secmes_context_data.c.func-sort-c.html | 149 + .../libspdm_secmes_context_data.c.func.html | 149 + .../libspdm_secmes_context_data.c.gcov.html | 500 + ...dm_secmes_encode_decode.c.func-sort-c.html | 101 + .../libspdm_secmes_encode_decode.c.func.html | 101 + .../libspdm_secmes_encode_decode.c.gcov.html | 774 ++ ...pdm_secmes_key_exchange.c.func-sort-c.html | 97 + .../libspdm_secmes_key_exchange.c.func.html | 97 + .../libspdm_secmes_key_exchange.c.gcov.html | 193 + .../libspdm_secmes_session.c.func-sort-c.html | 173 + .../libspdm_secmes_session.c.func.html | 173 + .../libspdm_secmes_session.c.gcov.html | 1193 +++ .../cipher/aead_aes_gcm.c.func-sort-c.html | 89 + .../cipher/aead_aes_gcm.c.func.html | 89 + .../cipher/aead_aes_gcm.c.gcov.html | 274 + .../cryptlib_mbedtls/cipher/index-sort-b.html | 107 + .../cryptlib_mbedtls/cipher/index-sort-f.html | 107 + .../cryptlib_mbedtls/cipher/index-sort-l.html | 107 + .../cryptlib_mbedtls/cipher/index.html | 107 + .../der/der.c.func-sort-c.html | 89 + .../cryptlib_mbedtls/der/der.c.func.html | 89 + .../cryptlib_mbedtls/der/der.c.gcov.html | 288 + .../cryptlib_mbedtls/der/index-sort-b.html | 107 + .../cryptlib_mbedtls/der/index-sort-f.html | 107 + .../cryptlib_mbedtls/der/index-sort-l.html | 107 + .../os_stub/cryptlib_mbedtls/der/index.html | 107 + .../cryptlib_mbedtls/hash/index-sort-b.html | 107 + .../cryptlib_mbedtls/hash/index-sort-f.html | 107 + .../cryptlib_mbedtls/hash/index-sort-l.html | 107 + .../os_stub/cryptlib_mbedtls/hash/index.html | 107 + .../hash/sha.c.func-sort-c.html | 165 + .../cryptlib_mbedtls/hash/sha.c.func.html | 165 + .../cryptlib_mbedtls/hash/sha.c.gcov.html | 709 ++ .../hmac/hmac_sha.c.func-sort-c.html | 197 + .../hmac/hmac_sha.c.func.html | 197 + .../hmac/hmac_sha.c.gcov.html | 794 ++ .../cryptlib_mbedtls/hmac/index-sort-b.html | 107 + .../cryptlib_mbedtls/hmac/index-sort-f.html | 107 + .../cryptlib_mbedtls/hmac/index-sort-l.html | 107 + .../os_stub/cryptlib_mbedtls/hmac/index.html | 107 + .../kdf/hkdf_sha.c.func-sort-c.html | 129 + .../cryptlib_mbedtls/kdf/hkdf_sha.c.func.html | 129 + .../cryptlib_mbedtls/kdf/hkdf_sha.c.gcov.html | 477 + .../cryptlib_mbedtls/kdf/index-sort-b.html | 107 + .../cryptlib_mbedtls/kdf/index-sort-f.html | 107 + .../cryptlib_mbedtls/kdf/index-sort-l.html | 107 + .../os_stub/cryptlib_mbedtls/kdf/index.html | 107 + .../cryptlib_mbedtls/pem/index-sort-b.html | 107 + .../cryptlib_mbedtls/pem/index-sort-f.html | 107 + .../cryptlib_mbedtls/pem/index-sort-l.html | 107 + .../os_stub/cryptlib_mbedtls/pem/index.html | 107 + .../pem/pem.c.func-sort-c.html | 101 + .../cryptlib_mbedtls/pem/pem.c.func.html | 101 + .../cryptlib_mbedtls/pem/pem.c.gcov.html | 349 + .../cryptlib_mbedtls/pk/dh.c.func-sort-c.html | 105 + .../cryptlib_mbedtls/pk/dh.c.func.html | 105 + .../cryptlib_mbedtls/pk/dh.c.gcov.html | 420 + .../cryptlib_mbedtls/pk/ec.c.func-sort-c.html | 125 + .../cryptlib_mbedtls/pk/ec.c.func.html | 125 + .../cryptlib_mbedtls/pk/ec.c.gcov.html | 927 ++ .../cryptlib_mbedtls/pk/index-sort-b.html | 155 + .../cryptlib_mbedtls/pk/index-sort-f.html | 155 + .../cryptlib_mbedtls/pk/index-sort-l.html | 155 + .../os_stub/cryptlib_mbedtls/pk/index.html | 155 + .../pk/rsa_basic.c.func-sort-c.html | 105 + .../cryptlib_mbedtls/pk/rsa_basic.c.func.html | 105 + .../cryptlib_mbedtls/pk/rsa_basic.c.gcov.html | 492 + .../pk/rsa_ext.c.func-sort-c.html | 109 + .../cryptlib_mbedtls/pk/rsa_ext.c.func.html | 109 + .../cryptlib_mbedtls/pk/rsa_ext.c.gcov.html | 635 ++ .../pk/x509.c.func-sort-c.html | 233 + .../cryptlib_mbedtls/pk/x509.c.func.html | 233 + .../cryptlib_mbedtls/pk/x509.c.gcov.html | 2310 +++++ .../cryptlib_mbedtls/rand/index-sort-b.html | 107 + .../cryptlib_mbedtls/rand/index-sort-f.html | 107 + .../cryptlib_mbedtls/rand/index-sort-l.html | 107 + .../os_stub/cryptlib_mbedtls/rand/index.html | 107 + .../rand/rand.c.func-sort-c.html | 89 + .../cryptlib_mbedtls/rand/rand.c.func.html | 89 + .../cryptlib_mbedtls/rand/rand.c.gcov.html | 152 + .../crt_wrapper_host.c.func-sort-c.html | 93 + .../sys_call/crt_wrapper_host.c.func.html | 93 + .../sys_call/crt_wrapper_host.c.gcov.html | 116 + .../sys_call/index-sort-b.html | 119 + .../sys_call/index-sort-f.html | 119 + .../sys_call/index-sort-l.html | 119 + .../cryptlib_mbedtls/sys_call/index.html | 119 + .../mem_allocation.c.func-sort-c.html | 89 + .../sys_call/mem_allocation.c.func.html | 89 + .../sys_call/mem_allocation.c.gcov.html | 161 + .../debuglib/debuglib.c.func-sort-c.html | 89 + .../os_stub/debuglib/debuglib.c.func.html | 89 + .../os_stub/debuglib/debuglib.c.gcov.html | 168 + .../os_stub/debuglib/index-sort-b.html | 107 + .../os_stub/debuglib/index-sort-f.html | 107 + .../os_stub/debuglib/index-sort-l.html | 107 + coverage_log/os_stub/debuglib/index.html | 107 + .../os_stub/malloclib/index-sort-b.html | 107 + .../os_stub/malloclib/index-sort-f.html | 107 + .../os_stub/malloclib/index-sort-l.html | 107 + coverage_log/os_stub/malloclib/index.html | 107 + .../malloclib/malloclib.c.func-sort-c.html | 93 + .../os_stub/malloclib/malloclib.c.func.html | 93 + .../os_stub/malloclib/malloclib.c.gcov.html | 118 + .../include/mbedtls/cipher.h.func-sort-c.html | 101 + .../include/mbedtls/cipher.h.func.html | 101 + .../include/mbedtls/cipher.h.gcov.html | 1258 +++ .../include/mbedtls/ecp.h.func-sort-c.html | 85 + .../mbedtls/include/mbedtls/ecp.h.func.html | 85 + .../mbedtls/include/mbedtls/ecp.h.gcov.html | 1613 ++++ .../include/mbedtls/error.h.func-sort-c.html | 85 + .../mbedtls/include/mbedtls/error.h.func.html | 85 + .../mbedtls/include/mbedtls/error.h.gcov.html | 286 + .../mbedtls/include/mbedtls/index-sort-b.html | 155 + .../mbedtls/include/mbedtls/index-sort-f.html | 155 + .../mbedtls/include/mbedtls/index-sort-l.html | 155 + .../mbedtls/include/mbedtls/index.html | 155 + .../include/mbedtls/md.h.func-sort-c.html | 85 + .../mbedtls/include/mbedtls/md.h.func.html | 85 + .../mbedtls/include/mbedtls/md.h.gcov.html | 611 ++ .../include/mbedtls/pk.h.func-sort-c.html | 93 + .../mbedtls/include/mbedtls/pk.h.func.html | 93 + .../mbedtls/include/mbedtls/pk.h.gcov.html | 1373 +++ .../mbedtls/library/aes.c.func-sort-c.html | 145 + .../mbedtls/library/aes.c.func.html | 145 + .../mbedtls/library/aes.c.gcov.html | 2379 +++++ .../mbedtls/library/aesni.c.func-sort-c.html | 113 + .../mbedtls/library/aesni.c.func.html | 113 + .../mbedtls/library/aesni.c.gcov.html | 920 ++ .../library/alignment.h.func-sort-c.html | 81 + .../mbedtls/library/alignment.h.func.html | 81 + .../mbedtls/library/alignment.h.gcov.html | 769 ++ .../mbedtls/library/aria.c.func-sort-c.html | 137 + .../mbedtls/library/aria.c.func.html | 137 + .../mbedtls/library/aria.c.gcov.html | 1063 +++ .../library/asn1parse.c.func-sort-c.html | 157 + .../mbedtls/library/asn1parse.c.func.html | 157 + .../mbedtls/library/asn1parse.c.gcov.html | 554 ++ .../library/asn1write.c.func-sort-c.html | 165 + .../mbedtls/library/asn1write.c.func.html | 165 + .../mbedtls/library/asn1write.c.gcov.html | 522 ++ .../mbedtls/library/base64.c.func-sort-c.html | 101 + .../mbedtls/library/base64.c.func.html | 101 + .../mbedtls/library/base64.c.gcov.html | 385 + .../mbedtls/library/bignum.c.func-sort-c.html | 301 + .../mbedtls/library/bignum.c.func.html | 301 + .../mbedtls/library/bignum.c.gcov.html | 2550 +++++ .../library/bignum_core.c.func-sort-c.html | 213 + .../mbedtls/library/bignum_core.c.func.html | 213 + .../mbedtls/library/bignum_core.c.gcov.html | 981 ++ .../library/bignum_core.h.func-sort-c.html | 85 + .../mbedtls/library/bignum_core.h.func.html | 85 + .../mbedtls/library/bignum_core.h.gcov.html | 848 ++ .../library/camellia.c.func-sort-c.html | 121 + .../mbedtls/library/camellia.c.func.html | 121 + .../mbedtls/library/camellia.c.gcov.html | 1147 +++ .../mbedtls/library/ccm.c.func-sort-c.html | 157 + .../mbedtls/library/ccm.c.func.html | 157 + .../mbedtls/library/ccm.c.gcov.html | 849 ++ .../library/chacha20.c.func-sort-c.html | 121 + .../mbedtls/library/chacha20.c.func.html | 121 + .../mbedtls/library/chacha20.c.gcov.html | 582 ++ .../library/chachapoly.c.func-sort-c.html | 133 + .../mbedtls/library/chachapoly.c.func.html | 133 + .../mbedtls/library/chachapoly.c.gcov.html | 563 ++ .../mbedtls/library/cipher.c.func-sort-c.html | 181 + .../mbedtls/library/cipher.c.func.html | 181 + .../mbedtls/library/cipher.c.gcov.html | 1765 ++++ .../library/cipher_wrap.c.func-sort-c.html | 305 + .../mbedtls/library/cipher_wrap.c.func.html | 305 + .../mbedtls/library/cipher_wrap.c.gcov.html | 2567 +++++ .../mbedtls/library/common.h.func-sort-c.html | 81 + .../mbedtls/library/common.h.func.html | 81 + .../mbedtls/library/common.h.gcov.html | 530 ++ .../library/constant_time.c.func-sort-c.html | 101 + .../mbedtls/library/constant_time.c.func.html | 101 + .../mbedtls/library/constant_time.c.gcov.html | 333 + .../constant_time_impl.h.func-sort-c.html | 161 + .../library/constant_time_impl.h.func.html | 161 + .../library/constant_time_impl.h.gcov.html | 641 ++ .../mbedtls/library/ctr.h.func-sort-c.html | 85 + .../mbedtls/library/ctr.h.func.html | 85 + .../mbedtls/library/ctr.h.gcov.html | 120 + .../mbedtls/library/des.c.func-sort-c.html | 165 + .../mbedtls/library/des.c.func.html | 165 + .../mbedtls/library/des.c.gcov.html | 1130 +++ .../mbedtls/library/dhm.c.func-sort-c.html | 153 + .../mbedtls/library/dhm.c.func.html | 153 + .../mbedtls/library/dhm.c.gcov.html | 798 ++ .../mbedtls/library/ecdh.c.func-sort-c.html | 185 + .../mbedtls/library/ecdh.c.func.html | 185 + .../mbedtls/library/ecdh.c.gcov.html | 779 ++ .../mbedtls/library/ecdsa.c.func-sort-c.html | 181 + .../mbedtls/library/ecdsa.c.func.html | 181 + .../mbedtls/library/ecdsa.c.gcov.html | 962 ++ .../mbedtls/library/ecp.c.func-sort-c.html | 457 + .../mbedtls/library/ecp.c.func.html | 457 + .../mbedtls/library/ecp.c.gcov.html | 3803 ++++++++ .../library/ecp_curves.c.func-sort-c.html | 165 + .../mbedtls/library/ecp_curves.c.func.html | 165 + .../mbedtls/library/ecp_curves.c.gcov.html | 5577 +++++++++++ .../mbedtls/library/gcm.c.func-sort-c.html | 149 + .../mbedtls/library/gcm.c.func.html | 149 + .../mbedtls/library/gcm.c.gcov.html | 1416 +++ .../mbedtls/library/hkdf.c.func-sort-c.html | 93 + .../mbedtls/library/hkdf.c.func.html | 93 + .../mbedtls/library/hkdf.c.gcov.html | 246 + .../library/hmac_drbg.c.func-sort-c.html | 137 + .../mbedtls/library/hmac_drbg.c.func.html | 137 + .../mbedtls/library/hmac_drbg.c.gcov.html | 718 ++ .../mbedtls/library/index-sort-b.html | 731 ++ .../mbedtls/library/index-sort-f.html | 731 ++ .../mbedtls/library/index-sort-l.html | 731 ++ .../mbedtlslib/mbedtls/library/index.html | 731 ++ .../mbedtls/library/md.c.func-sort-c.html | 161 + .../mbedtlslib/mbedtls/library/md.c.func.html | 161 + .../mbedtlslib/mbedtls/library/md.c.gcov.html | 1214 +++ .../mbedtls/library/md5.c.func-sort-c.html | 117 + .../mbedtls/library/md5.c.func.html | 117 + .../mbedtls/library/md5.c.gcov.html | 511 + .../mbedtls/library/oid.c.func-sort-c.html | 213 + .../mbedtls/library/oid.c.func.html | 213 + .../mbedtls/library/oid.c.gcov.html | 1275 +++ .../mbedtls/library/pem.c.func-sort-c.html | 121 + .../mbedtls/library/pem.c.func.html | 121 + .../mbedtls/library/pem.c.gcov.html | 632 ++ .../mbedtls/library/pk.c.func-sort-c.html | 169 + .../mbedtlslib/mbedtls/library/pk.c.func.html | 169 + .../mbedtlslib/mbedtls/library/pk.c.gcov.html | 1620 ++++ .../mbedtls/library/pk_ecc.c.func-sort-c.html | 97 + .../mbedtls/library/pk_ecc.c.func.html | 97 + .../mbedtls/library/pk_ecc.c.gcov.html | 340 + .../library/pk_internal.h.func-sort-c.html | 97 + .../mbedtls/library/pk_internal.h.func.html | 97 + .../mbedtls/library/pk_internal.h.gcov.html | 292 + .../library/pk_wrap.c.func-sort-c.html | 193 + .../mbedtls/library/pk_wrap.c.func.html | 193 + .../mbedtls/library/pk_wrap.c.gcov.html | 1669 ++++ .../library/pkparse.c.func-sort-c.html | 129 + .../mbedtls/library/pkparse.c.func.html | 129 + .../mbedtls/library/pkparse.c.gcov.html | 1477 +++ .../library/pkwrite.c.func-sort-c.html | 129 + .../mbedtls/library/pkwrite.c.func.html | 129 + .../mbedtls/library/pkwrite.c.gcov.html | 706 ++ .../library/platform_util.c.func-sort-c.html | 93 + .../mbedtls/library/platform_util.c.func.html | 93 + .../mbedtls/library/platform_util.c.gcov.html | 348 + .../library/poly1305.c.func-sort-c.html | 121 + .../mbedtls/library/poly1305.c.func.html | 121 + .../mbedtls/library/poly1305.c.gcov.html | 577 ++ .../library/ripemd160.c.func-sort-c.html | 117 + .../mbedtls/library/ripemd160.c.func.html | 117 + .../mbedtls/library/ripemd160.c.gcov.html | 575 ++ .../mbedtls/library/rsa.c.func-sort-c.html | 289 + .../mbedtls/library/rsa.c.func.html | 289 + .../mbedtls/library/rsa.c.gcov.html | 3172 +++++++ .../rsa_alt_helpers.c.func-sort-c.html | 101 + .../library/rsa_alt_helpers.c.func.html | 101 + .../library/rsa_alt_helpers.c.gcov.html | 538 ++ .../mbedtls/library/sha1.c.func-sort-c.html | 117 + .../mbedtls/library/sha1.c.func.html | 117 + .../mbedtls/library/sha1.c.gcov.html | 565 ++ .../mbedtls/library/sha256.c.func-sort-c.html | 129 + .../mbedtls/library/sha256.c.func.html | 129 + .../mbedtls/library/sha256.c.gcov.html | 1061 +++ .../mbedtls/library/sha3.c.func-sort-c.html | 125 + .../mbedtls/library/sha3.c.func.html | 125 + .../mbedtls/library/sha3.c.gcov.html | 809 ++ .../mbedtls/library/sha512.c.func-sort-c.html | 129 + .../mbedtls/library/sha512.c.func.html | 129 + .../mbedtls/library/sha512.c.gcov.html | 1197 +++ .../mbedtls/library/x509.c.func-sort-c.html | 221 + .../mbedtls/library/x509.c.func.html | 221 + .../mbedtls/library/x509.c.gcov.html | 1886 ++++ .../library/x509_create.c.func-sort-c.html | 129 + .../mbedtls/library/x509_create.c.func.html | 129 + .../mbedtls/library/x509_create.c.gcov.html | 649 ++ .../library/x509_crt.c.func-sort-c.html | 301 + .../mbedtls/library/x509_crt.c.func.html | 301 + .../mbedtls/library/x509_crt.c.gcov.html | 3394 +++++++ .../library/x509write.c.func-sort-c.html | 85 + .../mbedtls/library/x509write.c.func.html | 85 + .../mbedtls/library/x509write.c.gcov.html | 259 + .../library/x509write_csr.c.func-sort-c.html | 129 + .../mbedtls/library/x509write_csr.c.func.html | 129 + .../mbedtls/library/x509write_csr.c.gcov.html | 416 + .../memlib/compare_mem.c.func-sort-c.html | 85 + .../os_stub/memlib/compare_mem.c.func.html | 85 + .../os_stub/memlib/compare_mem.c.gcov.html | 109 + .../memlib/copy_mem.c.func-sort-c.html | 85 + .../os_stub/memlib/copy_mem.c.func.html | 85 + .../os_stub/memlib/copy_mem.c.gcov.html | 118 + coverage_log/os_stub/memlib/index-sort-b.html | 143 + coverage_log/os_stub/memlib/index-sort-f.html | 143 + coverage_log/os_stub/memlib/index-sort-l.html | 143 + coverage_log/os_stub/memlib/index.html | 143 + .../os_stub/memlib/set_mem.c.func-sort-c.html | 85 + .../os_stub/memlib/set_mem.c.func.html | 85 + .../os_stub/memlib/set_mem.c.gcov.html | 102 + .../memlib/zero_mem.c.func-sort-c.html | 85 + .../os_stub/memlib/zero_mem.c.func.html | 85 + .../os_stub/memlib/zero_mem.c.gcov.html | 125 + .../os_stub/platform_lib/index-sort-b.html | 119 + .../os_stub/platform_lib/index-sort-f.html | 119 + .../os_stub/platform_lib/index-sort-l.html | 119 + coverage_log/os_stub/platform_lib/index.html | 119 + .../time_linux.c.func-sort-c.html | 85 + .../platform_lib/time_linux.c.func.html | 85 + .../platform_lib/time_linux.c.gcov.html | 114 + .../platform_lib/watchdog.c.func-sort-c.html | 93 + .../os_stub/platform_lib/watchdog.c.func.html | 93 + .../os_stub/platform_lib/watchdog.c.gcov.html | 130 + .../platform_lib_null/index-sort-b.html | 107 + .../platform_lib_null/index-sort-f.html | 107 + .../platform_lib_null/index-sort-l.html | 107 + .../os_stub/platform_lib_null/index.html | 107 + .../watchdog.c.func-sort-c.html | 93 + .../platform_lib_null/watchdog.c.func.html | 93 + .../platform_lib_null/watchdog.c.gcov.html | 130 + coverage_log/os_stub/rnglib/index-sort-b.html | 107 + coverage_log/os_stub/rnglib/index-sort-f.html | 107 + coverage_log/os_stub/rnglib/index-sort-l.html | 107 + coverage_log/os_stub/rnglib/index.html | 107 + .../rnglib/rng_linux.c.func-sort-c.html | 85 + .../os_stub/rnglib/rng_linux.c.func.html | 85 + .../os_stub/rnglib/rng_linux.c.gcov.html | 129 + .../spdm_crypt_ext_lib/index-sort-b.html | 107 + .../spdm_crypt_ext_lib/index-sort-f.html | 107 + .../spdm_crypt_ext_lib/index-sort-l.html | 107 + .../os_stub/spdm_crypt_ext_lib/index.html | 107 + .../spdm_crypt_ext.c.func-sort-c.html | 109 + .../spdm_crypt_ext.c.func.html | 109 + .../spdm_crypt_ext.c.gcov.html | 351 + .../cert.c.func-sort-c.html | 121 + .../cert.c.func.html | 121 + .../cert.c.gcov.html | 1380 +++ .../index-sort-b.html | 119 + .../index-sort-f.html | 119 + .../index-sort-l.html | 119 + .../spdm_device_secret_lib_sample/index.html | 119 + .../lib.c.func-sort-c.html | 237 + .../lib.c.func.html | 237 + .../lib.c.gcov.html | 2735 ++++++ coverage_log/ruby.png | Bin 0 -> 141 bytes coverage_log/snow.png | Bin 0 -> 141 bytes .../cmocka/src/cmocka.c.func-sort-c.html | 617 ++ .../cmockalib/cmocka/src/cmocka.c.func.html | 617 ++ .../cmockalib/cmocka/src/cmocka.c.gcov.html | 3724 ++++++++ .../cmockalib/cmocka/src/index-sort-b.html | 107 + .../cmockalib/cmocka/src/index-sort-f.html | 107 + .../cmockalib/cmocka/src/index-sort-l.html | 107 + .../unit_test/cmockalib/cmocka/src/index.html | 107 + .../common.c.func-sort-c.html | 89 + .../common.c.func.html | 89 + .../common.c.gcov.html | 401 + .../spdm_transport_test_lib/index-sort-b.html | 119 + .../spdm_transport_test_lib/index-sort-f.html | 119 + .../spdm_transport_test_lib/index-sort-l.html | 119 + .../spdm_transport_test_lib/index.html | 119 + .../test.c.func-sort-c.html | 101 + .../spdm_transport_test_lib/test.c.func.html | 101 + .../spdm_transport_test_lib/test.c.gcov.html | 266 + .../common.c.func-sort-c.html | 121 + .../spdm_unit_test_common/common.c.func.html | 121 + .../spdm_unit_test_common/common.c.gcov.html | 256 + .../event_support.c.func-sort-c.html | 85 + .../event_support.c.func.html | 85 + .../event_support.c.gcov.html | 186 + .../spdm_unit_test_common/index-sort-b.html | 131 + .../spdm_unit_test_common/index-sort-f.html | 131 + .../spdm_unit_test_common/index-sort-l.html | 131 + .../spdm_unit_test_common/index.html | 131 + .../support.c.func-sort-c.html | 101 + .../spdm_unit_test_common/support.c.func.html | 101 + .../spdm_unit_test_common/support.c.gcov.html | 245 + .../context_data.c.func-sort-c.html | 189 + .../test_spdm_common/context_data.c.func.html | 189 + .../test_spdm_common/context_data.c.gcov.html | 1686 ++++ .../test_spdm_common/index-sort-b.html | 131 + .../test_spdm_common/index-sort-f.html | 131 + .../test_spdm_common/index-sort-l.html | 131 + .../unit_test/test_spdm_common/index.html | 131 + .../support.c.func-sort-c.html | 89 + .../test_spdm_common/support.c.func.html | 89 + .../test_spdm_common/support.c.gcov.html | 107 + .../test_spdm_common.c.func-sort-c.html | 85 + .../test_spdm_common.c.func.html | 85 + .../test_spdm_common.c.gcov.html | 109 + .../test_spdm_crypt/index-sort-b.html | 107 + .../test_spdm_crypt/index-sort-f.html | 107 + .../test_spdm_crypt/index-sort-l.html | 107 + .../unit_test/test_spdm_crypt/index.html | 107 + .../test_spdm_crypt.c.func-sort-c.html | 145 + .../test_spdm_crypt.c.func.html | 145 + .../test_spdm_crypt.c.gcov.html | 1392 +++ .../test_spdm_fips/index-sort-b.html | 107 + .../test_spdm_fips/index-sort-f.html | 107 + .../test_spdm_fips/index-sort-l.html | 107 + .../unit_test/test_spdm_fips/index.html | 107 + .../test_spdm_fips.c.func-sort-c.html | 101 + .../test_spdm_fips/test_spdm_fips.c.func.html | 101 + .../test_spdm_fips/test_spdm_fips.c.gcov.html | 145 + .../challenge.c.func-sort-c.html | 205 + .../test_spdm_requester/challenge.c.func.html | 205 + .../test_spdm_requester/challenge.c.gcov.html | 4115 ++++++++ .../chunk_get.c.func-sort-c.html | 125 + .../test_spdm_requester/chunk_get.c.func.html | 125 + .../test_spdm_requester/chunk_get.c.gcov.html | 957 ++ .../chunk_send.c.func-sort-c.html | 149 + .../chunk_send.c.func.html | 149 + .../chunk_send.c.gcov.html | 605 ++ .../encap_certificate.c.func-sort-c.html | 113 + .../encap_certificate.c.func.html | 113 + .../encap_certificate.c.gcov.html | 645 ++ .../encap_challenge_auth.c.func-sort-c.html | 117 + .../encap_challenge_auth.c.func.html | 117 + .../encap_challenge_auth.c.gcov.html | 682 ++ .../encap_digests.c.func-sort-c.html | 109 + .../encap_digests.c.func.html | 109 + .../encap_digests.c.gcov.html | 523 ++ .../encap_key_update.c.func-sort-c.html | 153 + .../encap_key_update.c.func.html | 153 + .../encap_key_update.c.gcov.html | 1213 +++ .../encap_request.c.func-sort-c.html | 133 + .../encap_request.c.func.html | 133 + .../encap_request.c.gcov.html | 1205 +++ .../end_session.c.func-sort-c.html | 149 + .../end_session.c.func.html | 149 + .../end_session.c.gcov.html | 1866 ++++ .../get_capabilities_err.c.func-sort-c.html | 253 + .../get_capabilities_err.c.func.html | 253 + .../get_capabilities_err.c.gcov.html | 2159 +++++ .../get_digests_err.c.func-sort-c.html | 181 + .../error_test/get_digests_err.c.func.html | 181 + .../error_test/get_digests_err.c.gcov.html | 1728 ++++ .../get_event_types_err.c.func-sort-c.html | 101 + .../get_event_types_err.c.func.html | 101 + .../get_event_types_err.c.gcov.html | 289 + .../get_key_pair_info_err.c.func-sort-c.html | 97 + .../get_key_pair_info_err.c.func.html | 97 + .../get_key_pair_info_err.c.gcov.html | 193 + .../get_measurements_err.c.func-sort-c.html | 245 + .../get_measurements_err.c.func.html | 245 + .../get_measurements_err.c.gcov.html | 4855 ++++++++++ .../get_version_err.c.func-sort-c.html | 157 + .../error_test/get_version_err.c.func.html | 157 + .../error_test/get_version_err.c.gcov.html | 975 ++ .../error_test/index-sort-b.html | 227 + .../error_test/index-sort-f.html | 227 + .../error_test/index-sort-l.html | 227 + .../test_spdm_requester/error_test/index.html | 227 + .../key_exchange_err.c.func-sort-c.html | 221 + .../error_test/key_exchange_err.c.func.html | 221 + .../error_test/key_exchange_err.c.gcov.html | 6473 +++++++++++++ ...egotiate_algorithms_err.c.func-sort-c.html | 265 + .../negotiate_algorithms_err.c.func.html | 265 + .../negotiate_algorithms_err.c.gcov.html | 3281 +++++++ .../set_key_pair_info_err.c.func-sort-c.html | 97 + .../set_key_pair_info_err.c.func.html | 97 + .../set_key_pair_info_err.c.gcov.html | 190 + ...bscribe_event_types_err.c.func-sort-c.html | 109 + .../subscribe_event_types_err.c.func.html | 109 + .../subscribe_event_types_err.c.gcov.html | 342 + .../vendor_request_err.c.func-sort-c.html | 105 + .../error_test/vendor_request_err.c.func.html | 105 + .../error_test/vendor_request_err.c.gcov.html | 325 + .../finish.c.func-sort-c.html | 193 + .../test_spdm_requester/finish.c.func.html | 193 + .../test_spdm_requester/finish.c.gcov.html | 3987 ++++++++ .../get_capabilities.c.func-sort-c.html | 129 + .../get_capabilities.c.func.html | 129 + .../get_capabilities.c.gcov.html | 1572 ++++ .../get_certificate.c.func-sort-c.html | 217 + .../get_certificate.c.func.html | 217 + .../get_certificate.c.gcov.html | 4524 +++++++++ .../get_csr.c.func-sort-c.html | 133 + .../test_spdm_requester/get_csr.c.func.html | 133 + .../test_spdm_requester/get_csr.c.gcov.html | 710 ++ .../get_digests.c.func-sort-c.html | 209 + .../get_digests.c.func.html | 209 + .../get_digests.c.gcov.html | 2121 +++++ .../get_event_types.c.func-sort-c.html | 101 + .../get_event_types.c.func.html | 101 + .../get_event_types.c.gcov.html | 289 + .../get_key_pair_info.c.func-sort-c.html | 101 + .../get_key_pair_info.c.func.html | 101 + .../get_key_pair_info.c.gcov.html | 687 ++ ...asurement_extension_log.c.func-sort-c.html | 137 + .../get_measurement_extension_log.c.func.html | 137 + .../get_measurement_extension_log.c.gcov.html | 1199 +++ .../get_measurements.c.func-sort-c.html | 261 + .../get_measurements.c.func.html | 261 + .../get_measurements.c.gcov.html | 6552 +++++++++++++ .../get_version.c.func-sort-c.html | 113 + .../get_version.c.func.html | 113 + .../get_version.c.gcov.html | 918 ++ .../heartbeat.c.func-sort-c.html | 153 + .../test_spdm_requester/heartbeat.c.func.html | 153 + .../test_spdm_requester/heartbeat.c.gcov.html | 1942 ++++ .../test_spdm_requester/index-sort-b.html | 455 + .../test_spdm_requester/index-sort-f.html | 455 + .../test_spdm_requester/index-sort-l.html | 455 + .../unit_test/test_spdm_requester/index.html | 455 + .../key_exchange.c.func-sort-c.html | 233 + .../key_exchange.c.func.html | 233 + .../key_exchange.c.gcov.html | 8327 +++++++++++++++++ .../key_update.c.func-sort-c.html | 245 + .../key_update.c.func.html | 245 + .../key_update.c.gcov.html | 5843 ++++++++++++ .../negotiate_algorithms.c.func-sort-c.html | 237 + .../negotiate_algorithms.c.func.html | 237 + .../negotiate_algorithms.c.gcov.html | 2332 +++++ .../psk_exchange.c.func-sort-c.html | 205 + .../psk_exchange.c.func.html | 205 + .../psk_exchange.c.gcov.html | 5189 ++++++++++ .../psk_finish.c.func-sort-c.html | 169 + .../psk_finish.c.func.html | 169 + .../psk_finish.c.gcov.html | 2612 ++++++ .../set_certificate.c.func-sort-c.html | 125 + .../set_certificate.c.func.html | 125 + .../set_certificate.c.gcov.html | 723 ++ .../set_key_pair_info.c.func-sort-c.html | 105 + .../set_key_pair_info.c.func.html | 105 + .../set_key_pair_info.c.gcov.html | 341 + .../subscribe_event_types.c.func-sort-c.html | 109 + .../subscribe_event_types.c.func.html | 109 + .../subscribe_event_types.c.gcov.html | 355 + .../test_spdm_requester.c.func-sort-c.html | 85 + .../test_spdm_requester.c.func.html | 85 + .../test_spdm_requester.c.gcov.html | 366 + .../vendor_request.c.func-sort-c.html | 105 + .../vendor_request.c.func.html | 105 + .../vendor_request.c.gcov.html | 327 + .../algorithms.c.func-sort-c.html | 209 + .../algorithms.c.func.html | 209 + .../algorithms.c.gcov.html | 3187 +++++++ .../capabilities.c.func-sort-c.html | 189 + .../capabilities.c.func.html | 189 + .../capabilities.c.gcov.html | 1378 +++ .../certificate.c.func-sort-c.html | 157 + .../certificate.c.func.html | 157 + .../certificate.c.gcov.html | 1467 +++ .../challenge_auth.c.func-sort-c.html | 161 + .../challenge_auth.c.func.html | 161 + .../challenge_auth.c.gcov.html | 1351 +++ .../chunk_get.c.func-sort-c.html | 137 + .../test_spdm_responder/chunk_get.c.func.html | 137 + .../test_spdm_responder/chunk_get.c.gcov.html | 1128 +++ .../chunk_send_ack.c.func-sort-c.html | 173 + .../chunk_send_ack.c.func.html | 173 + .../chunk_send_ack.c.gcov.html | 1852 ++++ .../csr.c.func-sort-c.html | 181 + .../test_spdm_responder/csr.c.func.html | 181 + .../test_spdm_responder/csr.c.gcov.html | 2123 +++++ .../digests.c.func-sort-c.html | 125 + .../test_spdm_responder/digests.c.func.html | 125 + .../test_spdm_responder/digests.c.gcov.html | 722 ++ .../encap_challenge.c.func-sort-c.html | 109 + .../encap_challenge.c.func.html | 109 + .../encap_challenge.c.gcov.html | 593 ++ .../encap_get_certificate.c.func-sort-c.html | 105 + .../encap_get_certificate.c.func.html | 105 + .../encap_get_certificate.c.gcov.html | 689 ++ .../encap_get_digests.c.func-sort-c.html | 113 + .../encap_get_digests.c.func.html | 113 + .../encap_get_digests.c.gcov.html | 592 ++ .../encap_key_update.c.func-sort-c.html | 109 + .../encap_key_update.c.func.html | 109 + .../encap_key_update.c.gcov.html | 359 + .../encap_response.c.func-sort-c.html | 145 + .../encap_response.c.func.html | 145 + .../encap_response.c.gcov.html | 1183 +++ .../end_session.c.func-sort-c.html | 117 + .../end_session.c.func.html | 117 + .../end_session.c.gcov.html | 757 ++ .../error_test/index-sort-b.html | 131 + .../error_test/index-sort-f.html | 131 + .../error_test/index-sort-l.html | 131 + .../test_spdm_responder/error_test/index.html | 131 + ...ibe_event_types_ack_err.c.func-sort-c.html | 97 + .../subscribe_event_types_ack_err.c.func.html | 97 + .../subscribe_event_types_ack_err.c.gcov.html | 246 + ...pported_event_types_err.c.func-sort-c.html | 93 + .../supported_event_types_err.c.func.html | 93 + .../supported_event_types_err.c.gcov.html | 200 + .../vendor_response_err.c.func-sort-c.html | 93 + .../vendor_response_err.c.func.html | 93 + .../vendor_response_err.c.gcov.html | 226 + .../finish.c.func-sort-c.html | 205 + .../test_spdm_responder/finish.c.func.html | 205 + .../test_spdm_responder/finish.c.gcov.html | 3995 ++++++++ .../heartbeat.c.func-sort-c.html | 117 + .../test_spdm_responder/heartbeat.c.func.html | 117 + .../test_spdm_responder/heartbeat.c.gcov.html | 747 ++ .../test_spdm_responder/index-sort-b.html | 479 + .../test_spdm_responder/index-sort-f.html | 479 + .../test_spdm_responder/index-sort-l.html | 479 + .../unit_test/test_spdm_responder/index.html | 479 + .../key_exchange.c.func-sort-c.html | 161 + .../key_exchange.c.func.html | 161 + .../key_exchange.c.gcov.html | 2046 ++++ .../key_pair_info.c.func-sort-c.html | 101 + .../key_pair_info.c.func.html | 101 + .../key_pair_info.c.gcov.html | 308 + .../key_update.c.func-sort-c.html | 205 + .../key_update.c.func.html | 205 + .../key_update.c.gcov.html | 2317 +++++ ...asurement_extension_log.c.func-sort-c.html | 105 + .../measurement_extension_log.c.func.html | 105 + .../measurement_extension_log.c.gcov.html | 470 + .../measurements.c.func-sort-c.html | 225 + .../measurements.c.func.html | 225 + .../measurements.c.gcov.html | 2910 ++++++ .../psk_exchange.c.func-sort-c.html | 153 + .../psk_exchange.c.func.html | 153 + .../psk_exchange.c.gcov.html | 1863 ++++ .../psk_finish.c.func-sort-c.html | 145 + .../psk_finish.c.func.html | 145 + .../psk_finish.c.gcov.html | 1705 ++++ .../receive_send.c.func-sort-c.html | 113 + .../receive_send.c.func.html | 113 + .../receive_send.c.gcov.html | 609 ++ .../respond_if_ready.c.func-sort-c.html | 145 + .../respond_if_ready.c.func.html | 145 + .../respond_if_ready.c.gcov.html | 1496 +++ .../set_certificate_rsp.c.func-sort-c.html | 133 + .../set_certificate_rsp.c.func.html | 133 + .../set_certificate_rsp.c.gcov.html | 1167 +++ .../set_key_pair_info_ack.c.func-sort-c.html | 97 + .../set_key_pair_info_ack.c.func.html | 97 + .../set_key_pair_info_ack.c.gcov.html | 588 ++ ...bscribe_event_types_ack.c.func-sort-c.html | 97 + .../subscribe_event_types_ack.c.func.html | 97 + .../subscribe_event_types_ack.c.gcov.html | 250 + .../supported_event_types.c.func-sort-c.html | 93 + .../supported_event_types.c.func.html | 93 + .../supported_event_types.c.gcov.html | 209 + .../test_spdm_responder.c.func-sort-c.html | 85 + .../test_spdm_responder.c.func.html | 85 + .../test_spdm_responder.c.gcov.html | 360 + .../vendor_response.c.func-sort-c.html | 97 + .../vendor_response.c.func.html | 97 + .../vendor_response.c.gcov.html | 263 + .../version.c.func-sort-c.html | 113 + .../test_spdm_responder/version.c.func.html | 113 + .../test_spdm_responder/version.c.gcov.html | 372 + .../encode_decode.c.func-sort-c.html | 149 + .../encode_decode.c.func.html | 149 + .../encode_decode.c.gcov.html | 1016 ++ .../index-sort-b.html | 119 + .../index-sort-f.html | 119 + .../index-sort-l.html | 119 + .../test_spdm_secured_message/index.html | 119 + ...st_spdm_secured_message.c.func-sort-c.html | 85 + .../test_spdm_secured_message.c.func.html | 85 + .../test_spdm_secured_message.c.gcov.html | 105 + coverage_log/updown.png | Bin 0 -> 117 bytes 972 files changed, 358609 insertions(+) create mode 100644 coverage_log/amber.png create mode 100644 coverage_log/emerald.png create mode 100644 coverage_log/gcov.css create mode 100644 coverage_log/glass.png create mode 100644 coverage_log/include/internal/index-sort-b.html create mode 100644 coverage_log/include/internal/index-sort-f.html create mode 100644 coverage_log/include/internal/index-sort-l.html create mode 100644 coverage_log/include/internal/index.html create mode 100644 coverage_log/include/internal/libspdm_common_lib.h.func-sort-c.html create mode 100644 coverage_log/include/internal/libspdm_common_lib.h.func.html create mode 100644 coverage_log/include/internal/libspdm_common_lib.h.gcov.html create mode 100644 coverage_log/index-sort-b.html create mode 100644 coverage_log/index-sort-f.html create mode 100644 coverage_log/index-sort-l.html create mode 100644 coverage_log/index.html create mode 100644 coverage_log/library/spdm_common_lib/index-sort-b.html create mode 100644 coverage_log/library/spdm_common_lib/index-sort-f.html create mode 100644 coverage_log/library/spdm_common_lib/index-sort-l.html create mode 100644 coverage_log/library/spdm_common_lib/index.html create mode 100644 coverage_log/library/spdm_common_lib/libspdm_com_context_data.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_common_lib/libspdm_com_context_data.c.func.html create mode 100644 coverage_log/library/spdm_common_lib/libspdm_com_context_data.c.gcov.html create mode 100644 coverage_log/library/spdm_common_lib/libspdm_com_context_data_session.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_common_lib/libspdm_com_context_data_session.c.func.html create mode 100644 coverage_log/library/spdm_common_lib/libspdm_com_context_data_session.c.gcov.html create mode 100644 coverage_log/library/spdm_common_lib/libspdm_com_crypto_service.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_common_lib/libspdm_com_crypto_service.c.func.html create mode 100644 coverage_log/library/spdm_common_lib/libspdm_com_crypto_service.c.gcov.html create mode 100644 coverage_log/library/spdm_common_lib/libspdm_com_crypto_service_session.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_common_lib/libspdm_com_crypto_service_session.c.func.html create mode 100644 coverage_log/library/spdm_common_lib/libspdm_com_crypto_service_session.c.gcov.html create mode 100644 coverage_log/library/spdm_common_lib/libspdm_com_msg_log.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_common_lib/libspdm_com_msg_log.c.func.html create mode 100644 coverage_log/library/spdm_common_lib/libspdm_com_msg_log.c.gcov.html create mode 100644 coverage_log/library/spdm_common_lib/libspdm_com_opaque_data.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_common_lib/libspdm_com_opaque_data.c.func.html create mode 100644 coverage_log/library/spdm_common_lib/libspdm_com_opaque_data.c.gcov.html create mode 100644 coverage_log/library/spdm_common_lib/libspdm_com_support.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_common_lib/libspdm_com_support.c.func.html create mode 100644 coverage_log/library/spdm_common_lib/libspdm_com_support.c.gcov.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/index-sort-b.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/index-sort-f.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/index-sort-l.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/index.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest.c.func.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest.c.gcov.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_aes_gcm.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_aes_gcm.c.func.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_aes_gcm.c.gcov.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_ecdh.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_ecdh.c.func.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_ecdh.c.gcov.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_ecdsa.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_ecdsa.c.func.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_ecdsa.c.gcov.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_eddsa.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_eddsa.c.func.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_eddsa.c.gcov.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_ffdh.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_ffdh.c.func.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_ffdh.c.gcov.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_hkdf.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_hkdf.c.func.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_hkdf.c.gcov.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_hmac.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_hmac.c.func.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_hmac.c.gcov.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_rsa_pss.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_rsa_pss.c.func.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_rsa_pss.c.gcov.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_rsa_ssa.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_rsa_ssa.c.func.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_rsa_ssa.c.gcov.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_sha2.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_sha2.c.func.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_sha2.c.gcov.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_sha3.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_sha3.c.func.html create mode 100644 coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_sha3.c.gcov.html create mode 100644 coverage_log/library/spdm_crypt_lib/index-sort-b.html create mode 100644 coverage_log/library/spdm_crypt_lib/index-sort-f.html create mode 100644 coverage_log/library/spdm_crypt_lib/index-sort-l.html create mode 100644 coverage_log/library/spdm_crypt_lib/index.html create mode 100644 coverage_log/library/spdm_crypt_lib/libspdm_crypt_aead.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_crypt_lib/libspdm_crypt_aead.c.func.html create mode 100644 coverage_log/library/spdm_crypt_lib/libspdm_crypt_aead.c.gcov.html create mode 100644 coverage_log/library/spdm_crypt_lib/libspdm_crypt_asym.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_crypt_lib/libspdm_crypt_asym.c.func.html create mode 100644 coverage_log/library/spdm_crypt_lib/libspdm_crypt_asym.c.gcov.html create mode 100644 coverage_log/library/spdm_crypt_lib/libspdm_crypt_cert.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_crypt_lib/libspdm_crypt_cert.c.func.html create mode 100644 coverage_log/library/spdm_crypt_lib/libspdm_crypt_cert.c.gcov.html create mode 100644 coverage_log/library/spdm_crypt_lib/libspdm_crypt_dhe.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_crypt_lib/libspdm_crypt_dhe.c.func.html create mode 100644 coverage_log/library/spdm_crypt_lib/libspdm_crypt_dhe.c.gcov.html create mode 100644 coverage_log/library/spdm_crypt_lib/libspdm_crypt_hash.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_crypt_lib/libspdm_crypt_hash.c.func.html create mode 100644 coverage_log/library/spdm_crypt_lib/libspdm_crypt_hash.c.gcov.html create mode 100644 coverage_log/library/spdm_crypt_lib/libspdm_crypt_hkdf.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_crypt_lib/libspdm_crypt_hkdf.c.func.html create mode 100644 coverage_log/library/spdm_crypt_lib/libspdm_crypt_hkdf.c.gcov.html create mode 100644 coverage_log/library/spdm_crypt_lib/libspdm_crypt_hmac.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_crypt_lib/libspdm_crypt_hmac.c.func.html create mode 100644 coverage_log/library/spdm_crypt_lib/libspdm_crypt_hmac.c.gcov.html create mode 100644 coverage_log/library/spdm_crypt_lib/libspdm_crypt_rng.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_crypt_lib/libspdm_crypt_rng.c.func.html create mode 100644 coverage_log/library/spdm_crypt_lib/libspdm_crypt_rng.c.gcov.html create mode 100644 coverage_log/library/spdm_requester_lib/index-sort-b.html create mode 100644 coverage_log/library/spdm_requester_lib/index-sort-f.html create mode 100644 coverage_log/library/spdm_requester_lib/index-sort-l.html create mode 100644 coverage_log/library/spdm_requester_lib/index.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_challenge.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_challenge.c.func.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_challenge.c.gcov.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_common.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_common.c.func.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_common.c.gcov.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_encap_certificate.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_encap_certificate.c.func.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_encap_certificate.c.gcov.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_encap_challenge_auth.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_encap_challenge_auth.c.func.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_encap_challenge_auth.c.gcov.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_encap_digests.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_encap_digests.c.func.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_encap_digests.c.gcov.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_encap_error.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_encap_error.c.func.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_encap_error.c.gcov.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_encap_key_update.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_encap_key_update.c.func.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_encap_key_update.c.gcov.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_encap_request.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_encap_request.c.func.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_encap_request.c.gcov.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_end_session.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_end_session.c.func.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_end_session.c.gcov.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_finish.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_finish.c.func.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_finish.c.gcov.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_get_capabilities.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_get_capabilities.c.func.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_get_capabilities.c.gcov.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_get_certificate.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_get_certificate.c.func.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_get_certificate.c.gcov.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_get_csr.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_get_csr.c.func.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_get_csr.c.gcov.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_get_digests.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_get_digests.c.func.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_get_digests.c.gcov.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_get_event_types.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_get_event_types.c.func.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_get_event_types.c.gcov.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_get_key_pair_info.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_get_key_pair_info.c.func.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_get_key_pair_info.c.gcov.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_get_measurement_extension_log.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_get_measurement_extension_log.c.func.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_get_measurement_extension_log.c.gcov.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_get_measurements.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_get_measurements.c.func.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_get_measurements.c.gcov.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_get_version.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_get_version.c.func.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_get_version.c.gcov.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_handle_error_response.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_handle_error_response.c.func.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_handle_error_response.c.gcov.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_heartbeat.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_heartbeat.c.func.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_heartbeat.c.gcov.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_key_exchange.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_key_exchange.c.func.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_key_exchange.c.gcov.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_key_update.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_key_update.c.func.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_key_update.c.gcov.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_negotiate_algorithms.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_negotiate_algorithms.c.func.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_negotiate_algorithms.c.gcov.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_psk_exchange.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_psk_exchange.c.func.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_psk_exchange.c.gcov.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_psk_finish.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_psk_finish.c.func.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_psk_finish.c.gcov.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_send_receive.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_send_receive.c.func.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_send_receive.c.gcov.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_set_certificate.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_set_certificate.c.func.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_set_certificate.c.gcov.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_set_key_pair_info.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_set_key_pair_info.c.func.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_set_key_pair_info.c.gcov.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_subscribe_event_types.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_subscribe_event_types.c.func.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_subscribe_event_types.c.gcov.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_vendor_request.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_vendor_request.c.func.html create mode 100644 coverage_log/library/spdm_requester_lib/libspdm_req_vendor_request.c.gcov.html create mode 100644 coverage_log/library/spdm_responder_lib/index-sort-b.html create mode 100644 coverage_log/library/spdm_responder_lib/index-sort-f.html create mode 100644 coverage_log/library/spdm_responder_lib/index-sort-l.html create mode 100644 coverage_log/library/spdm_responder_lib/index.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_algorithms.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_algorithms.c.func.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_algorithms.c.gcov.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_capabilities.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_capabilities.c.func.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_capabilities.c.gcov.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_certificate.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_certificate.c.func.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_certificate.c.gcov.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_challenge_auth.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_challenge_auth.c.func.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_challenge_auth.c.gcov.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_chunk_get.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_chunk_get.c.func.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_chunk_get.c.gcov.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_chunk_send_ack.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_chunk_send_ack.c.func.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_chunk_send_ack.c.gcov.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_common.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_common.c.func.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_common.c.gcov.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_csr.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_csr.c.func.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_csr.c.gcov.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_digests.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_digests.c.func.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_digests.c.gcov.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_challenge.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_challenge.c.func.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_challenge.c.gcov.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_get_certificate.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_get_certificate.c.func.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_get_certificate.c.gcov.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_get_digests.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_get_digests.c.func.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_get_digests.c.gcov.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_key_update.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_key_update.c.func.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_key_update.c.gcov.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_response.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_response.c.func.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_response.c.gcov.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_end_session.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_end_session.c.func.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_end_session.c.gcov.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_error.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_error.c.func.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_error.c.gcov.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_finish.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_finish.c.func.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_finish.c.gcov.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_get_key_pair_info.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_get_key_pair_info.c.func.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_get_key_pair_info.c.gcov.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_handle_response_state.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_handle_response_state.c.func.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_handle_response_state.c.gcov.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_heartbeat.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_heartbeat.c.func.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_heartbeat.c.gcov.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_key_exchange.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_key_exchange.c.func.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_key_exchange.c.gcov.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_key_update.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_key_update.c.func.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_key_update.c.gcov.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_measurement_extension_log.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_measurement_extension_log.c.func.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_measurement_extension_log.c.gcov.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_measurements.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_measurements.c.func.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_measurements.c.gcov.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_psk_exchange.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_psk_exchange.c.func.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_psk_exchange.c.gcov.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_psk_finish.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_psk_finish.c.func.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_psk_finish.c.gcov.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_receive_send.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_receive_send.c.func.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_receive_send.c.gcov.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_respond_if_ready.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_respond_if_ready.c.func.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_respond_if_ready.c.gcov.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_set_certificate.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_set_certificate.c.func.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_set_certificate.c.gcov.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_set_key_pair_info_ack.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_set_key_pair_info_ack.c.func.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_set_key_pair_info_ack.c.gcov.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_subscribe_event_types_ack.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_subscribe_event_types_ack.c.func.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_subscribe_event_types_ack.c.gcov.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_supported_event_types.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_supported_event_types.c.func.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_supported_event_types.c.gcov.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_vendor_response.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_vendor_response.c.func.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_vendor_response.c.gcov.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_version.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_version.c.func.html create mode 100644 coverage_log/library/spdm_responder_lib/libspdm_rsp_version.c.gcov.html create mode 100644 coverage_log/library/spdm_secured_message_lib/index-sort-b.html create mode 100644 coverage_log/library/spdm_secured_message_lib/index-sort-f.html create mode 100644 coverage_log/library/spdm_secured_message_lib/index-sort-l.html create mode 100644 coverage_log/library/spdm_secured_message_lib/index.html create mode 100644 coverage_log/library/spdm_secured_message_lib/libspdm_secmes_context_data.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_secured_message_lib/libspdm_secmes_context_data.c.func.html create mode 100644 coverage_log/library/spdm_secured_message_lib/libspdm_secmes_context_data.c.gcov.html create mode 100644 coverage_log/library/spdm_secured_message_lib/libspdm_secmes_encode_decode.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_secured_message_lib/libspdm_secmes_encode_decode.c.func.html create mode 100644 coverage_log/library/spdm_secured_message_lib/libspdm_secmes_encode_decode.c.gcov.html create mode 100644 coverage_log/library/spdm_secured_message_lib/libspdm_secmes_key_exchange.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_secured_message_lib/libspdm_secmes_key_exchange.c.func.html create mode 100644 coverage_log/library/spdm_secured_message_lib/libspdm_secmes_key_exchange.c.gcov.html create mode 100644 coverage_log/library/spdm_secured_message_lib/libspdm_secmes_session.c.func-sort-c.html create mode 100644 coverage_log/library/spdm_secured_message_lib/libspdm_secmes_session.c.func.html create mode 100644 coverage_log/library/spdm_secured_message_lib/libspdm_secmes_session.c.gcov.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/cipher/aead_aes_gcm.c.func-sort-c.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/cipher/aead_aes_gcm.c.func.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/cipher/aead_aes_gcm.c.gcov.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/cipher/index-sort-b.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/cipher/index-sort-f.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/cipher/index-sort-l.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/cipher/index.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/der/der.c.func-sort-c.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/der/der.c.func.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/der/der.c.gcov.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/der/index-sort-b.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/der/index-sort-f.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/der/index-sort-l.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/der/index.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/hash/index-sort-b.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/hash/index-sort-f.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/hash/index-sort-l.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/hash/index.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/hash/sha.c.func-sort-c.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/hash/sha.c.func.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/hash/sha.c.gcov.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/hmac/hmac_sha.c.func-sort-c.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/hmac/hmac_sha.c.func.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/hmac/hmac_sha.c.gcov.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/hmac/index-sort-b.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/hmac/index-sort-f.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/hmac/index-sort-l.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/hmac/index.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/kdf/hkdf_sha.c.func-sort-c.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/kdf/hkdf_sha.c.func.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/kdf/hkdf_sha.c.gcov.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/kdf/index-sort-b.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/kdf/index-sort-f.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/kdf/index-sort-l.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/kdf/index.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/pem/index-sort-b.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/pem/index-sort-f.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/pem/index-sort-l.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/pem/index.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/pem/pem.c.func-sort-c.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/pem/pem.c.func.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/pem/pem.c.gcov.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/pk/dh.c.func-sort-c.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/pk/dh.c.func.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/pk/dh.c.gcov.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/pk/ec.c.func-sort-c.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/pk/ec.c.func.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/pk/ec.c.gcov.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/pk/index-sort-b.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/pk/index-sort-f.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/pk/index-sort-l.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/pk/index.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/pk/rsa_basic.c.func-sort-c.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/pk/rsa_basic.c.func.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/pk/rsa_basic.c.gcov.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/pk/rsa_ext.c.func-sort-c.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/pk/rsa_ext.c.func.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/pk/rsa_ext.c.gcov.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/pk/x509.c.func-sort-c.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/pk/x509.c.func.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/pk/x509.c.gcov.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/rand/index-sort-b.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/rand/index-sort-f.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/rand/index-sort-l.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/rand/index.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/rand/rand.c.func-sort-c.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/rand/rand.c.func.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/rand/rand.c.gcov.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/sys_call/crt_wrapper_host.c.func-sort-c.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/sys_call/crt_wrapper_host.c.func.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/sys_call/crt_wrapper_host.c.gcov.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/sys_call/index-sort-b.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/sys_call/index-sort-f.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/sys_call/index-sort-l.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/sys_call/index.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/sys_call/mem_allocation.c.func-sort-c.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/sys_call/mem_allocation.c.func.html create mode 100644 coverage_log/os_stub/cryptlib_mbedtls/sys_call/mem_allocation.c.gcov.html create mode 100644 coverage_log/os_stub/debuglib/debuglib.c.func-sort-c.html create mode 100644 coverage_log/os_stub/debuglib/debuglib.c.func.html create mode 100644 coverage_log/os_stub/debuglib/debuglib.c.gcov.html create mode 100644 coverage_log/os_stub/debuglib/index-sort-b.html create mode 100644 coverage_log/os_stub/debuglib/index-sort-f.html create mode 100644 coverage_log/os_stub/debuglib/index-sort-l.html create mode 100644 coverage_log/os_stub/debuglib/index.html create mode 100644 coverage_log/os_stub/malloclib/index-sort-b.html create mode 100644 coverage_log/os_stub/malloclib/index-sort-f.html create mode 100644 coverage_log/os_stub/malloclib/index-sort-l.html create mode 100644 coverage_log/os_stub/malloclib/index.html create mode 100644 coverage_log/os_stub/malloclib/malloclib.c.func-sort-c.html create mode 100644 coverage_log/os_stub/malloclib/malloclib.c.func.html create mode 100644 coverage_log/os_stub/malloclib/malloclib.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/cipher.h.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/cipher.h.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/cipher.h.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/ecp.h.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/ecp.h.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/ecp.h.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/error.h.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/error.h.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/error.h.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/index-sort-b.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/index-sort-f.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/index-sort-l.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/index.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/md.h.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/md.h.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/md.h.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/pk.h.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/pk.h.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/pk.h.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/aes.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/aes.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/aes.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/aesni.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/aesni.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/aesni.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/alignment.h.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/alignment.h.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/alignment.h.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/aria.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/aria.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/aria.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/asn1parse.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/asn1parse.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/asn1parse.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/asn1write.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/asn1write.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/asn1write.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/base64.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/base64.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/base64.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/bignum.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/bignum.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/bignum.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/bignum_core.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/bignum_core.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/bignum_core.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/bignum_core.h.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/bignum_core.h.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/bignum_core.h.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/camellia.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/camellia.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/camellia.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/ccm.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/ccm.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/ccm.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/chacha20.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/chacha20.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/chacha20.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/chachapoly.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/chachapoly.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/chachapoly.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/cipher.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/cipher.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/cipher.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/cipher_wrap.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/cipher_wrap.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/cipher_wrap.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/common.h.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/common.h.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/common.h.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/constant_time.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/constant_time.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/constant_time.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/constant_time_impl.h.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/constant_time_impl.h.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/constant_time_impl.h.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/ctr.h.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/ctr.h.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/ctr.h.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/des.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/des.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/des.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/dhm.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/dhm.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/dhm.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/ecdh.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/ecdh.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/ecdh.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/ecdsa.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/ecdsa.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/ecdsa.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/ecp.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/ecp.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/ecp.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/ecp_curves.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/ecp_curves.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/ecp_curves.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/gcm.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/gcm.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/gcm.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/hkdf.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/hkdf.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/hkdf.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/hmac_drbg.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/hmac_drbg.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/hmac_drbg.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/index-sort-b.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/index-sort-f.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/index-sort-l.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/index.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/md.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/md.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/md.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/md5.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/md5.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/md5.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/oid.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/oid.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/oid.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/pem.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/pem.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/pem.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/pk.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/pk.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/pk.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/pk_ecc.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/pk_ecc.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/pk_ecc.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/pk_internal.h.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/pk_internal.h.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/pk_internal.h.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/pk_wrap.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/pk_wrap.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/pk_wrap.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/pkparse.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/pkparse.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/pkparse.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/pkwrite.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/pkwrite.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/pkwrite.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/platform_util.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/platform_util.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/platform_util.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/poly1305.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/poly1305.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/poly1305.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/ripemd160.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/ripemd160.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/ripemd160.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/rsa.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/rsa.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/rsa.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/rsa_alt_helpers.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/rsa_alt_helpers.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/rsa_alt_helpers.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/sha1.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/sha1.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/sha1.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/sha256.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/sha256.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/sha256.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/sha3.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/sha3.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/sha3.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/sha512.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/sha512.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/sha512.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/x509.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/x509.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/x509.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/x509_create.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/x509_create.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/x509_create.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/x509_crt.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/x509_crt.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/x509_crt.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/x509write.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/x509write.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/x509write.c.gcov.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/x509write_csr.c.func-sort-c.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/x509write_csr.c.func.html create mode 100644 coverage_log/os_stub/mbedtlslib/mbedtls/library/x509write_csr.c.gcov.html create mode 100644 coverage_log/os_stub/memlib/compare_mem.c.func-sort-c.html create mode 100644 coverage_log/os_stub/memlib/compare_mem.c.func.html create mode 100644 coverage_log/os_stub/memlib/compare_mem.c.gcov.html create mode 100644 coverage_log/os_stub/memlib/copy_mem.c.func-sort-c.html create mode 100644 coverage_log/os_stub/memlib/copy_mem.c.func.html create mode 100644 coverage_log/os_stub/memlib/copy_mem.c.gcov.html create mode 100644 coverage_log/os_stub/memlib/index-sort-b.html create mode 100644 coverage_log/os_stub/memlib/index-sort-f.html create mode 100644 coverage_log/os_stub/memlib/index-sort-l.html create mode 100644 coverage_log/os_stub/memlib/index.html create mode 100644 coverage_log/os_stub/memlib/set_mem.c.func-sort-c.html create mode 100644 coverage_log/os_stub/memlib/set_mem.c.func.html create mode 100644 coverage_log/os_stub/memlib/set_mem.c.gcov.html create mode 100644 coverage_log/os_stub/memlib/zero_mem.c.func-sort-c.html create mode 100644 coverage_log/os_stub/memlib/zero_mem.c.func.html create mode 100644 coverage_log/os_stub/memlib/zero_mem.c.gcov.html create mode 100644 coverage_log/os_stub/platform_lib/index-sort-b.html create mode 100644 coverage_log/os_stub/platform_lib/index-sort-f.html create mode 100644 coverage_log/os_stub/platform_lib/index-sort-l.html create mode 100644 coverage_log/os_stub/platform_lib/index.html create mode 100644 coverage_log/os_stub/platform_lib/time_linux.c.func-sort-c.html create mode 100644 coverage_log/os_stub/platform_lib/time_linux.c.func.html create mode 100644 coverage_log/os_stub/platform_lib/time_linux.c.gcov.html create mode 100644 coverage_log/os_stub/platform_lib/watchdog.c.func-sort-c.html create mode 100644 coverage_log/os_stub/platform_lib/watchdog.c.func.html create mode 100644 coverage_log/os_stub/platform_lib/watchdog.c.gcov.html create mode 100644 coverage_log/os_stub/platform_lib_null/index-sort-b.html create mode 100644 coverage_log/os_stub/platform_lib_null/index-sort-f.html create mode 100644 coverage_log/os_stub/platform_lib_null/index-sort-l.html create mode 100644 coverage_log/os_stub/platform_lib_null/index.html create mode 100644 coverage_log/os_stub/platform_lib_null/watchdog.c.func-sort-c.html create mode 100644 coverage_log/os_stub/platform_lib_null/watchdog.c.func.html create mode 100644 coverage_log/os_stub/platform_lib_null/watchdog.c.gcov.html create mode 100644 coverage_log/os_stub/rnglib/index-sort-b.html create mode 100644 coverage_log/os_stub/rnglib/index-sort-f.html create mode 100644 coverage_log/os_stub/rnglib/index-sort-l.html create mode 100644 coverage_log/os_stub/rnglib/index.html create mode 100644 coverage_log/os_stub/rnglib/rng_linux.c.func-sort-c.html create mode 100644 coverage_log/os_stub/rnglib/rng_linux.c.func.html create mode 100644 coverage_log/os_stub/rnglib/rng_linux.c.gcov.html create mode 100644 coverage_log/os_stub/spdm_crypt_ext_lib/index-sort-b.html create mode 100644 coverage_log/os_stub/spdm_crypt_ext_lib/index-sort-f.html create mode 100644 coverage_log/os_stub/spdm_crypt_ext_lib/index-sort-l.html create mode 100644 coverage_log/os_stub/spdm_crypt_ext_lib/index.html create mode 100644 coverage_log/os_stub/spdm_crypt_ext_lib/spdm_crypt_ext.c.func-sort-c.html create mode 100644 coverage_log/os_stub/spdm_crypt_ext_lib/spdm_crypt_ext.c.func.html create mode 100644 coverage_log/os_stub/spdm_crypt_ext_lib/spdm_crypt_ext.c.gcov.html create mode 100644 coverage_log/os_stub/spdm_device_secret_lib_sample/cert.c.func-sort-c.html create mode 100644 coverage_log/os_stub/spdm_device_secret_lib_sample/cert.c.func.html create mode 100644 coverage_log/os_stub/spdm_device_secret_lib_sample/cert.c.gcov.html create mode 100644 coverage_log/os_stub/spdm_device_secret_lib_sample/index-sort-b.html create mode 100644 coverage_log/os_stub/spdm_device_secret_lib_sample/index-sort-f.html create mode 100644 coverage_log/os_stub/spdm_device_secret_lib_sample/index-sort-l.html create mode 100644 coverage_log/os_stub/spdm_device_secret_lib_sample/index.html create mode 100644 coverage_log/os_stub/spdm_device_secret_lib_sample/lib.c.func-sort-c.html create mode 100644 coverage_log/os_stub/spdm_device_secret_lib_sample/lib.c.func.html create mode 100644 coverage_log/os_stub/spdm_device_secret_lib_sample/lib.c.gcov.html create mode 100644 coverage_log/ruby.png create mode 100644 coverage_log/snow.png create mode 100644 coverage_log/unit_test/cmockalib/cmocka/src/cmocka.c.func-sort-c.html create mode 100644 coverage_log/unit_test/cmockalib/cmocka/src/cmocka.c.func.html create mode 100644 coverage_log/unit_test/cmockalib/cmocka/src/cmocka.c.gcov.html create mode 100644 coverage_log/unit_test/cmockalib/cmocka/src/index-sort-b.html create mode 100644 coverage_log/unit_test/cmockalib/cmocka/src/index-sort-f.html create mode 100644 coverage_log/unit_test/cmockalib/cmocka/src/index-sort-l.html create mode 100644 coverage_log/unit_test/cmockalib/cmocka/src/index.html create mode 100644 coverage_log/unit_test/spdm_transport_test_lib/common.c.func-sort-c.html create mode 100644 coverage_log/unit_test/spdm_transport_test_lib/common.c.func.html create mode 100644 coverage_log/unit_test/spdm_transport_test_lib/common.c.gcov.html create mode 100644 coverage_log/unit_test/spdm_transport_test_lib/index-sort-b.html create mode 100644 coverage_log/unit_test/spdm_transport_test_lib/index-sort-f.html create mode 100644 coverage_log/unit_test/spdm_transport_test_lib/index-sort-l.html create mode 100644 coverage_log/unit_test/spdm_transport_test_lib/index.html create mode 100644 coverage_log/unit_test/spdm_transport_test_lib/test.c.func-sort-c.html create mode 100644 coverage_log/unit_test/spdm_transport_test_lib/test.c.func.html create mode 100644 coverage_log/unit_test/spdm_transport_test_lib/test.c.gcov.html create mode 100644 coverage_log/unit_test/spdm_unit_test_common/common.c.func-sort-c.html create mode 100644 coverage_log/unit_test/spdm_unit_test_common/common.c.func.html create mode 100644 coverage_log/unit_test/spdm_unit_test_common/common.c.gcov.html create mode 100644 coverage_log/unit_test/spdm_unit_test_common/event_support.c.func-sort-c.html create mode 100644 coverage_log/unit_test/spdm_unit_test_common/event_support.c.func.html create mode 100644 coverage_log/unit_test/spdm_unit_test_common/event_support.c.gcov.html create mode 100644 coverage_log/unit_test/spdm_unit_test_common/index-sort-b.html create mode 100644 coverage_log/unit_test/spdm_unit_test_common/index-sort-f.html create mode 100644 coverage_log/unit_test/spdm_unit_test_common/index-sort-l.html create mode 100644 coverage_log/unit_test/spdm_unit_test_common/index.html create mode 100644 coverage_log/unit_test/spdm_unit_test_common/support.c.func-sort-c.html create mode 100644 coverage_log/unit_test/spdm_unit_test_common/support.c.func.html create mode 100644 coverage_log/unit_test/spdm_unit_test_common/support.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_common/context_data.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_common/context_data.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_common/context_data.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_common/index-sort-b.html create mode 100644 coverage_log/unit_test/test_spdm_common/index-sort-f.html create mode 100644 coverage_log/unit_test/test_spdm_common/index-sort-l.html create mode 100644 coverage_log/unit_test/test_spdm_common/index.html create mode 100644 coverage_log/unit_test/test_spdm_common/support.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_common/support.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_common/support.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_common/test_spdm_common.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_common/test_spdm_common.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_common/test_spdm_common.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_crypt/index-sort-b.html create mode 100644 coverage_log/unit_test/test_spdm_crypt/index-sort-f.html create mode 100644 coverage_log/unit_test/test_spdm_crypt/index-sort-l.html create mode 100644 coverage_log/unit_test/test_spdm_crypt/index.html create mode 100644 coverage_log/unit_test/test_spdm_crypt/test_spdm_crypt.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_crypt/test_spdm_crypt.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_crypt/test_spdm_crypt.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_fips/index-sort-b.html create mode 100644 coverage_log/unit_test/test_spdm_fips/index-sort-f.html create mode 100644 coverage_log/unit_test/test_spdm_fips/index-sort-l.html create mode 100644 coverage_log/unit_test/test_spdm_fips/index.html create mode 100644 coverage_log/unit_test/test_spdm_fips/test_spdm_fips.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_fips/test_spdm_fips.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_fips/test_spdm_fips.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/challenge.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/challenge.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/challenge.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/chunk_get.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/chunk_get.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/chunk_get.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/chunk_send.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/chunk_send.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/chunk_send.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/encap_certificate.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/encap_certificate.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/encap_certificate.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/encap_challenge_auth.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/encap_challenge_auth.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/encap_challenge_auth.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/encap_digests.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/encap_digests.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/encap_digests.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/encap_key_update.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/encap_key_update.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/encap_key_update.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/encap_request.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/encap_request.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/encap_request.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/end_session.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/end_session.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/end_session.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/error_test/get_capabilities_err.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/error_test/get_capabilities_err.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/error_test/get_capabilities_err.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/error_test/get_digests_err.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/error_test/get_digests_err.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/error_test/get_digests_err.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/error_test/get_event_types_err.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/error_test/get_event_types_err.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/error_test/get_event_types_err.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/error_test/get_key_pair_info_err.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/error_test/get_key_pair_info_err.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/error_test/get_key_pair_info_err.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/error_test/get_measurements_err.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/error_test/get_measurements_err.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/error_test/get_measurements_err.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/error_test/get_version_err.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/error_test/get_version_err.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/error_test/get_version_err.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/error_test/index-sort-b.html create mode 100644 coverage_log/unit_test/test_spdm_requester/error_test/index-sort-f.html create mode 100644 coverage_log/unit_test/test_spdm_requester/error_test/index-sort-l.html create mode 100644 coverage_log/unit_test/test_spdm_requester/error_test/index.html create mode 100644 coverage_log/unit_test/test_spdm_requester/error_test/key_exchange_err.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/error_test/key_exchange_err.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/error_test/key_exchange_err.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/error_test/negotiate_algorithms_err.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/error_test/negotiate_algorithms_err.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/error_test/negotiate_algorithms_err.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/error_test/set_key_pair_info_err.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/error_test/set_key_pair_info_err.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/error_test/set_key_pair_info_err.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/error_test/subscribe_event_types_err.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/error_test/subscribe_event_types_err.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/error_test/subscribe_event_types_err.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/error_test/vendor_request_err.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/error_test/vendor_request_err.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/error_test/vendor_request_err.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/finish.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/finish.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/finish.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/get_capabilities.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/get_capabilities.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/get_capabilities.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/get_certificate.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/get_certificate.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/get_certificate.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/get_csr.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/get_csr.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/get_csr.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/get_digests.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/get_digests.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/get_digests.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/get_event_types.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/get_event_types.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/get_event_types.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/get_key_pair_info.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/get_key_pair_info.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/get_key_pair_info.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/get_measurement_extension_log.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/get_measurement_extension_log.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/get_measurement_extension_log.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/get_measurements.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/get_measurements.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/get_measurements.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/get_version.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/get_version.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/get_version.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/heartbeat.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/heartbeat.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/heartbeat.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/index-sort-b.html create mode 100644 coverage_log/unit_test/test_spdm_requester/index-sort-f.html create mode 100644 coverage_log/unit_test/test_spdm_requester/index-sort-l.html create mode 100644 coverage_log/unit_test/test_spdm_requester/index.html create mode 100644 coverage_log/unit_test/test_spdm_requester/key_exchange.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/key_exchange.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/key_exchange.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/key_update.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/key_update.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/key_update.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/negotiate_algorithms.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/negotiate_algorithms.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/negotiate_algorithms.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/psk_exchange.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/psk_exchange.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/psk_exchange.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/psk_finish.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/psk_finish.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/psk_finish.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/set_certificate.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/set_certificate.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/set_certificate.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/set_key_pair_info.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/set_key_pair_info.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/set_key_pair_info.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/subscribe_event_types.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/subscribe_event_types.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/subscribe_event_types.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/test_spdm_requester.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/test_spdm_requester.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/test_spdm_requester.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_requester/vendor_request.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_requester/vendor_request.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_requester/vendor_request.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_responder/algorithms.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_responder/algorithms.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_responder/algorithms.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_responder/capabilities.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_responder/capabilities.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_responder/capabilities.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_responder/certificate.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_responder/certificate.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_responder/certificate.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_responder/challenge_auth.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_responder/challenge_auth.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_responder/challenge_auth.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_responder/chunk_get.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_responder/chunk_get.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_responder/chunk_get.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_responder/chunk_send_ack.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_responder/chunk_send_ack.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_responder/chunk_send_ack.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_responder/csr.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_responder/csr.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_responder/csr.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_responder/digests.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_responder/digests.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_responder/digests.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_responder/encap_challenge.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_responder/encap_challenge.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_responder/encap_challenge.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_responder/encap_get_certificate.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_responder/encap_get_certificate.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_responder/encap_get_certificate.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_responder/encap_get_digests.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_responder/encap_get_digests.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_responder/encap_get_digests.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_responder/encap_key_update.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_responder/encap_key_update.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_responder/encap_key_update.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_responder/encap_response.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_responder/encap_response.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_responder/encap_response.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_responder/end_session.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_responder/end_session.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_responder/end_session.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_responder/error_test/index-sort-b.html create mode 100644 coverage_log/unit_test/test_spdm_responder/error_test/index-sort-f.html create mode 100644 coverage_log/unit_test/test_spdm_responder/error_test/index-sort-l.html create mode 100644 coverage_log/unit_test/test_spdm_responder/error_test/index.html create mode 100644 coverage_log/unit_test/test_spdm_responder/error_test/subscribe_event_types_ack_err.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_responder/error_test/subscribe_event_types_ack_err.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_responder/error_test/subscribe_event_types_ack_err.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_responder/error_test/supported_event_types_err.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_responder/error_test/supported_event_types_err.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_responder/error_test/supported_event_types_err.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_responder/error_test/vendor_response_err.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_responder/error_test/vendor_response_err.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_responder/error_test/vendor_response_err.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_responder/finish.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_responder/finish.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_responder/finish.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_responder/heartbeat.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_responder/heartbeat.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_responder/heartbeat.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_responder/index-sort-b.html create mode 100644 coverage_log/unit_test/test_spdm_responder/index-sort-f.html create mode 100644 coverage_log/unit_test/test_spdm_responder/index-sort-l.html create mode 100644 coverage_log/unit_test/test_spdm_responder/index.html create mode 100644 coverage_log/unit_test/test_spdm_responder/key_exchange.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_responder/key_exchange.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_responder/key_exchange.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_responder/key_pair_info.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_responder/key_pair_info.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_responder/key_pair_info.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_responder/key_update.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_responder/key_update.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_responder/key_update.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_responder/measurement_extension_log.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_responder/measurement_extension_log.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_responder/measurement_extension_log.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_responder/measurements.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_responder/measurements.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_responder/measurements.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_responder/psk_exchange.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_responder/psk_exchange.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_responder/psk_exchange.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_responder/psk_finish.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_responder/psk_finish.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_responder/psk_finish.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_responder/receive_send.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_responder/receive_send.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_responder/receive_send.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_responder/respond_if_ready.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_responder/respond_if_ready.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_responder/respond_if_ready.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_responder/set_certificate_rsp.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_responder/set_certificate_rsp.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_responder/set_certificate_rsp.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_responder/set_key_pair_info_ack.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_responder/set_key_pair_info_ack.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_responder/set_key_pair_info_ack.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_responder/subscribe_event_types_ack.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_responder/subscribe_event_types_ack.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_responder/subscribe_event_types_ack.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_responder/supported_event_types.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_responder/supported_event_types.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_responder/supported_event_types.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_responder/test_spdm_responder.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_responder/test_spdm_responder.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_responder/test_spdm_responder.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_responder/vendor_response.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_responder/vendor_response.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_responder/vendor_response.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_responder/version.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_responder/version.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_responder/version.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_secured_message/encode_decode.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_secured_message/encode_decode.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_secured_message/encode_decode.c.gcov.html create mode 100644 coverage_log/unit_test/test_spdm_secured_message/index-sort-b.html create mode 100644 coverage_log/unit_test/test_spdm_secured_message/index-sort-f.html create mode 100644 coverage_log/unit_test/test_spdm_secured_message/index-sort-l.html create mode 100644 coverage_log/unit_test/test_spdm_secured_message/index.html create mode 100644 coverage_log/unit_test/test_spdm_secured_message/test_spdm_secured_message.c.func-sort-c.html create mode 100644 coverage_log/unit_test/test_spdm_secured_message/test_spdm_secured_message.c.func.html create mode 100644 coverage_log/unit_test/test_spdm_secured_message/test_spdm_secured_message.c.gcov.html create mode 100644 coverage_log/updown.png diff --git a/coverage_log/amber.png b/coverage_log/amber.png new file mode 100644 index 0000000000000000000000000000000000000000..2cab170d8359081983a4e343848dfe06bc490f12 GIT binary patch literal 141 zcmeAS@N?(olHy`uVBq!ia0vp^j3CU&3?x-=hn)ga>?NMQuI!iC1^G2tW}LqE04T&+ z;1OBOz`!j8!i<;h*8KqrvZOouIx;Y9?C1WI$O`1M1^9%x{(levWG?NMQuI!iC1^Jb!lvI6;R0X`wF(yt=9xVZRt1vCRixIA4P dLn>}1Cji+@42)0J?}79&c)I$ztaD0e0sy@GAL0N2 literal 0 HcmV?d00001 diff --git a/coverage_log/gcov.css b/coverage_log/gcov.css new file mode 100644 index 00000000000..bfd0a83e10b --- /dev/null +++ b/coverage_log/gcov.css @@ -0,0 +1,519 @@ +/* All views: initial background and text color */ +body +{ + color: #000000; + background-color: #FFFFFF; +} + +/* All views: standard link format*/ +a:link +{ + color: #284FA8; + text-decoration: underline; +} + +/* All views: standard link - visited format */ +a:visited +{ + color: #00CB40; + text-decoration: underline; +} + +/* All views: standard link - activated format */ +a:active +{ + color: #FF0040; + text-decoration: underline; +} + +/* All views: main title format */ +td.title +{ + text-align: center; + padding-bottom: 10px; + font-family: sans-serif; + font-size: 20pt; + font-style: italic; + font-weight: bold; +} + +/* All views: header item format */ +td.headerItem +{ + text-align: right; + padding-right: 6px; + font-family: sans-serif; + font-weight: bold; + vertical-align: top; + white-space: nowrap; +} + +/* All views: header item value format */ +td.headerValue +{ + text-align: left; + color: #284FA8; + font-family: sans-serif; + font-weight: bold; + white-space: nowrap; +} + +/* All views: header item coverage table heading */ +td.headerCovTableHead +{ + text-align: center; + padding-right: 6px; + padding-left: 6px; + padding-bottom: 0px; + font-family: sans-serif; + font-size: 80%; + white-space: nowrap; +} + +/* All views: header item coverage table entry */ +td.headerCovTableEntry +{ + text-align: right; + color: #284FA8; + font-family: sans-serif; + font-weight: bold; + white-space: nowrap; + padding-left: 12px; + padding-right: 4px; + background-color: #DAE7FE; +} + +/* All views: header item coverage table entry for high coverage rate */ +td.headerCovTableEntryHi +{ + text-align: right; + color: #000000; + font-family: sans-serif; + font-weight: bold; + white-space: nowrap; + padding-left: 12px; + padding-right: 4px; + background-color: #A7FC9D; +} + +/* All views: header item coverage table entry for medium coverage rate */ +td.headerCovTableEntryMed +{ + text-align: right; + color: #000000; + font-family: sans-serif; + font-weight: bold; + white-space: nowrap; + padding-left: 12px; + padding-right: 4px; + background-color: #FFEA20; +} + +/* All views: header item coverage table entry for ow coverage rate */ +td.headerCovTableEntryLo +{ + text-align: right; + color: #000000; + font-family: sans-serif; + font-weight: bold; + white-space: nowrap; + padding-left: 12px; + padding-right: 4px; + background-color: #FF0000; +} + +/* All views: header legend value for legend entry */ +td.headerValueLeg +{ + text-align: left; + color: #000000; + font-family: sans-serif; + font-size: 80%; + white-space: nowrap; + padding-top: 4px; +} + +/* All views: color of horizontal ruler */ +td.ruler +{ + background-color: #6688D4; +} + +/* All views: version string format */ +td.versionInfo +{ + text-align: center; + padding-top: 2px; + font-family: sans-serif; + font-style: italic; +} + +/* Directory view/File view (all)/Test case descriptions: + table headline format */ +td.tableHead +{ + text-align: center; + color: #FFFFFF; + background-color: #6688D4; + font-family: sans-serif; + font-size: 120%; + font-weight: bold; + white-space: nowrap; + padding-left: 4px; + padding-right: 4px; +} + +span.tableHeadSort +{ + padding-right: 4px; +} + +/* Directory view/File view (all): filename entry format */ +td.coverFile +{ + text-align: left; + padding-left: 10px; + padding-right: 20px; + color: #284FA8; + background-color: #DAE7FE; + font-family: monospace; +} + +/* Directory view/File view (all): bar-graph entry format*/ +td.coverBar +{ + padding-left: 10px; + padding-right: 10px; + background-color: #DAE7FE; +} + +/* Directory view/File view (all): bar-graph outline color */ +td.coverBarOutline +{ + background-color: #000000; +} + +/* Directory view/File view (all): percentage entry for files with + high coverage rate */ +td.coverPerHi +{ + text-align: right; + padding-left: 10px; + padding-right: 10px; + background-color: #A7FC9D; + font-weight: bold; + font-family: sans-serif; +} + +/* Directory view/File view (all): line count entry for files with + high coverage rate */ +td.coverNumHi +{ + text-align: right; + padding-left: 10px; + padding-right: 10px; + background-color: #A7FC9D; + white-space: nowrap; + font-family: sans-serif; +} + +/* Directory view/File view (all): percentage entry for files with + medium coverage rate */ +td.coverPerMed +{ + text-align: right; + padding-left: 10px; + padding-right: 10px; + background-color: #FFEA20; + font-weight: bold; + font-family: sans-serif; +} + +/* Directory view/File view (all): line count entry for files with + medium coverage rate */ +td.coverNumMed +{ + text-align: right; + padding-left: 10px; + padding-right: 10px; + background-color: #FFEA20; + white-space: nowrap; + font-family: sans-serif; +} + +/* Directory view/File view (all): percentage entry for files with + low coverage rate */ +td.coverPerLo +{ + text-align: right; + padding-left: 10px; + padding-right: 10px; + background-color: #FF0000; + font-weight: bold; + font-family: sans-serif; +} + +/* Directory view/File view (all): line count entry for files with + low coverage rate */ +td.coverNumLo +{ + text-align: right; + padding-left: 10px; + padding-right: 10px; + background-color: #FF0000; + white-space: nowrap; + font-family: sans-serif; +} + +/* File view (all): "show/hide details" link format */ +a.detail:link +{ + color: #B8D0FF; + font-size:80%; +} + +/* File view (all): "show/hide details" link - visited format */ +a.detail:visited +{ + color: #B8D0FF; + font-size:80%; +} + +/* File view (all): "show/hide details" link - activated format */ +a.detail:active +{ + color: #FFFFFF; + font-size:80%; +} + +/* File view (detail): test name entry */ +td.testName +{ + text-align: right; + padding-right: 10px; + background-color: #DAE7FE; + font-family: sans-serif; +} + +/* File view (detail): test percentage entry */ +td.testPer +{ + text-align: right; + padding-left: 10px; + padding-right: 10px; + background-color: #DAE7FE; + font-family: sans-serif; +} + +/* File view (detail): test lines count entry */ +td.testNum +{ + text-align: right; + padding-left: 10px; + padding-right: 10px; + background-color: #DAE7FE; + font-family: sans-serif; +} + +/* Test case descriptions: test name format*/ +dt +{ + font-family: sans-serif; + font-weight: bold; +} + +/* Test case descriptions: description table body */ +td.testDescription +{ + padding-top: 10px; + padding-left: 30px; + padding-bottom: 10px; + padding-right: 30px; + background-color: #DAE7FE; +} + +/* Source code view: function entry */ +td.coverFn +{ + text-align: left; + padding-left: 10px; + padding-right: 20px; + color: #284FA8; + background-color: #DAE7FE; + font-family: monospace; +} + +/* Source code view: function entry zero count*/ +td.coverFnLo +{ + text-align: right; + padding-left: 10px; + padding-right: 10px; + background-color: #FF0000; + font-weight: bold; + font-family: sans-serif; +} + +/* Source code view: function entry nonzero count*/ +td.coverFnHi +{ + text-align: right; + padding-left: 10px; + padding-right: 10px; + background-color: #DAE7FE; + font-weight: bold; + font-family: sans-serif; +} + +/* Source code view: source code format */ +pre.source +{ + font-family: monospace; + white-space: pre; + margin-top: 2px; +} + +/* Source code view: line number format */ +span.lineNum +{ + background-color: #EFE383; +} + +/* Source code view: format for lines which were executed */ +td.lineCov, +span.lineCov +{ + background-color: #CAD7FE; +} + +/* Source code view: format for Cov legend */ +span.coverLegendCov +{ + padding-left: 10px; + padding-right: 10px; + padding-bottom: 2px; + background-color: #CAD7FE; +} + +/* Source code view: format for lines which were not executed */ +td.lineNoCov, +span.lineNoCov +{ + background-color: #FF6230; +} + +/* Source code view: format for NoCov legend */ +span.coverLegendNoCov +{ + padding-left: 10px; + padding-right: 10px; + padding-bottom: 2px; + background-color: #FF6230; +} + +/* Source code view (function table): standard link - visited format */ +td.lineNoCov > a:visited, +td.lineCov > a:visited +{ + color: black; + text-decoration: underline; +} + +/* Source code view: format for lines which were executed only in a + previous version */ +span.lineDiffCov +{ + background-color: #B5F7AF; +} + +/* Source code view: format for branches which were executed + * and taken */ +span.branchCov +{ + background-color: #CAD7FE; +} + +/* Source code view: format for branches which were executed + * but not taken */ +span.branchNoCov +{ + background-color: #FF6230; +} + +/* Source code view: format for branches which were not executed */ +span.branchNoExec +{ + background-color: #FF6230; +} + +/* Source code view: format for the source code heading line */ +pre.sourceHeading +{ + white-space: pre; + font-family: monospace; + font-weight: bold; + margin: 0px; +} + +/* All views: header legend value for low rate */ +td.headerValueLegL +{ + font-family: sans-serif; + text-align: center; + white-space: nowrap; + padding-left: 4px; + padding-right: 2px; + background-color: #FF0000; + font-size: 80%; +} + +/* All views: header legend value for med rate */ +td.headerValueLegM +{ + font-family: sans-serif; + text-align: center; + white-space: nowrap; + padding-left: 2px; + padding-right: 2px; + background-color: #FFEA20; + font-size: 80%; +} + +/* All views: header legend value for hi rate */ +td.headerValueLegH +{ + font-family: sans-serif; + text-align: center; + white-space: nowrap; + padding-left: 2px; + padding-right: 4px; + background-color: #A7FC9D; + font-size: 80%; +} + +/* All views except source code view: legend format for low coverage */ +span.coverLegendCovLo +{ + padding-left: 10px; + padding-right: 10px; + padding-top: 2px; + background-color: #FF0000; +} + +/* All views except source code view: legend format for med coverage */ +span.coverLegendCovMed +{ + padding-left: 10px; + padding-right: 10px; + padding-top: 2px; + background-color: #FFEA20; +} + +/* All views except source code view: legend format for hi coverage */ +span.coverLegendCovHi +{ + padding-left: 10px; + padding-right: 10px; + padding-top: 2px; + background-color: #A7FC9D; +} diff --git a/coverage_log/glass.png b/coverage_log/glass.png new file mode 100644 index 0000000000000000000000000000000000000000..e1abc00680a3093c49fdb775ae6bdb6764c95af2 GIT binary patch literal 167 zcmeAS@N?(olHy`uVBq!ia0vp^j3CU&3?x-=hn)gaEa{HEjtmSN`?>!lvI6;R0X`wF z|Ns97GD8ntt^-nxB|(0{3=Yq3q=7g|-tI089jvk*Kn`btM`SSr1Gf+eGhVt|_XjA* zUgGKN%6^Gmn4d%Ph(nkFP>9RZ#WAE}PI3Z}&BVayv3^M*kj3EX>gTe~DWM4f=_Dpv literal 0 HcmV?d00001 diff --git a/coverage_log/include/internal/index-sort-b.html b/coverage_log/include/internal/index-sort-b.html new file mode 100644 index 00000000000..49511f01bbb --- /dev/null +++ b/coverage_log/include/internal/index-sort-b.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - include/internal + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - include/internalHitTotalCoverage
Test:coverage.infoLines:1111100.0 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:44100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
libspdm_common_lib.h +
100.0%
+
100.0 %11 / 11100.0 %2 / 2100.0 %4 / 4
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/include/internal/index-sort-f.html b/coverage_log/include/internal/index-sort-f.html new file mode 100644 index 00000000000..8a6c6a595ca --- /dev/null +++ b/coverage_log/include/internal/index-sort-f.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - include/internal + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - include/internalHitTotalCoverage
Test:coverage.infoLines:1111100.0 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:44100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
libspdm_common_lib.h +
100.0%
+
100.0 %11 / 11100.0 %2 / 2100.0 %4 / 4
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/include/internal/index-sort-l.html b/coverage_log/include/internal/index-sort-l.html new file mode 100644 index 00000000000..0cc79123dc6 --- /dev/null +++ b/coverage_log/include/internal/index-sort-l.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - include/internal + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - include/internalHitTotalCoverage
Test:coverage.infoLines:1111100.0 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:44100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
libspdm_common_lib.h +
100.0%
+
100.0 %11 / 11100.0 %2 / 2100.0 %4 / 4
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/include/internal/index.html b/coverage_log/include/internal/index.html new file mode 100644 index 00000000000..fddfe83dc5f --- /dev/null +++ b/coverage_log/include/internal/index.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - include/internal + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - include/internalHitTotalCoverage
Test:coverage.infoLines:1111100.0 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:44100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
libspdm_common_lib.h +
100.0%
+
100.0 %11 / 11100.0 %2 / 2100.0 %4 / 4
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/include/internal/libspdm_common_lib.h.func-sort-c.html b/coverage_log/include/internal/libspdm_common_lib.h.func-sort-c.html new file mode 100644 index 00000000000..2f8f9067952 --- /dev/null +++ b/coverage_log/include/internal/libspdm_common_lib.h.func-sort-c.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - include/internal/libspdm_common_lib.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - include/internal - libspdm_common_lib.h (source / functions)HitTotalCoverage
Test:coverage.infoLines:1111100.0 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:44100.0 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_le_to_be_641
libspdm_onehot0361
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/include/internal/libspdm_common_lib.h.func.html b/coverage_log/include/internal/libspdm_common_lib.h.func.html new file mode 100644 index 00000000000..57c042ead83 --- /dev/null +++ b/coverage_log/include/internal/libspdm_common_lib.h.func.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - include/internal/libspdm_common_lib.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - include/internal - libspdm_common_lib.h (source / functions)HitTotalCoverage
Test:coverage.infoLines:1111100.0 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:44100.0 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_le_to_be_641
libspdm_onehot0361
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/include/internal/libspdm_common_lib.h.gcov.html b/coverage_log/include/internal/libspdm_common_lib.h.gcov.html new file mode 100644 index 00000000000..a415714f629 --- /dev/null +++ b/coverage_log/include/internal/libspdm_common_lib.h.gcov.html @@ -0,0 +1,1815 @@ + + + + + + + LCOV - coverage.info - include/internal/libspdm_common_lib.h + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - include/internal - libspdm_common_lib.h (source / functions)HitTotalCoverage
Test:coverage.infoLines:1111100.0 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:44100.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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                 :            : #ifndef SPDM_COMMON_LIB_INTERNAL_H
+       8                 :            : #define SPDM_COMMON_LIB_INTERNAL_H
+       9                 :            : 
+      10                 :            : #include "library/spdm_common_lib.h"
+      11                 :            : #include "library/spdm_secured_message_lib.h"
+      12                 :            : #include "library/spdm_return_status.h"
+      13                 :            : #include "library/spdm_crypt_lib.h"
+      14                 :            : #include "hal/library/debuglib.h"
+      15                 :            : #include "hal/library/memlib.h"
+      16                 :            : #include "hal/library/requester/reqasymsignlib.h"
+      17                 :            : #include "hal/library/requester/psklib.h"
+      18                 :            : #include "hal/library/responder/asymsignlib.h"
+      19                 :            : #include "hal/library/responder/csrlib.h"
+      20                 :            : #include "hal/library/responder/measlib.h"
+      21                 :            : #include "hal/library/responder/key_pair_info.h"
+      22                 :            : #include "hal/library/responder/psklib.h"
+      23                 :            : #include "hal/library/responder/setcertlib.h"
+      24                 :            : #include "hal/library/eventlib.h"
+      25                 :            : #include "hal/library/cryptlib.h"
+      26                 :            : 
+      27                 :            : #define INVALID_SESSION_ID 0
+      28                 :            : /* The SPDM specification does not limit the values of CTExponent and RDTExponent.
+      29                 :            :  * libspdm artificially limits their values to 31, which corresponds to approximately 35 minutes
+      30                 :            :  * for CT and RDT. If an endpoint takes longer than 35 minutes to generate an SPDM message then
+      31                 :            :  * libspdm assumes the Integrator would not want to interact with such an endpoint. A maximum value
+      32                 :            :  * of 31 also means that, when calculating CT and RDT, a left-shift will not result in C undefined
+      33                 :            :  * behavior.
+      34                 :            :  */
+      35                 :            : #define LIBSPDM_MAX_CT_EXPONENT 31
+      36                 :            : #define LIBSPDM_MAX_RDT_EXPONENT 31
+      37                 :            : 
+      38                 :            : #define LIBSPDM_MAX_SPDM_SESSION_SEQUENCE_NUMBER 0xFFFFFFFFFFFFFFFFull
+      39                 :            : 
+      40                 :            : typedef struct {
+      41                 :            :     uint8_t spdm_version_count;
+      42                 :            :     spdm_version_number_t spdm_version[SPDM_MAX_VERSION_COUNT];
+      43                 :            : } libspdm_device_version_t;
+      44                 :            : 
+      45                 :            : typedef struct {
+      46                 :            :     uint8_t ct_exponent;
+      47                 :            :     uint64_t rtt;
+      48                 :            :     uint32_t st1;
+      49                 :            :     uint32_t flags;
+      50                 :            :     uint32_t data_transfer_size;
+      51                 :            :     uint32_t sender_data_transfer_size;
+      52                 :            :     uint32_t max_spdm_msg_size;
+      53                 :            :     uint32_t transport_header_size;
+      54                 :            :     uint32_t transport_tail_size;
+      55                 :            : } libspdm_device_capability_t;
+      56                 :            : 
+      57                 :            : typedef struct {
+      58                 :            :     uint8_t measurement_spec;
+      59                 :            :     uint8_t other_params_support;
+      60                 :            :     uint8_t mel_spec;
+      61                 :            :     uint32_t measurement_hash_algo;
+      62                 :            :     uint32_t base_asym_algo;
+      63                 :            :     uint32_t base_hash_algo;
+      64                 :            :     uint16_t dhe_named_group;
+      65                 :            :     uint16_t aead_cipher_suite;
+      66                 :            :     uint16_t req_base_asym_alg;
+      67                 :            :     uint16_t key_schedule;
+      68                 :            : } libspdm_device_algorithm_t;
+      69                 :            : 
+      70                 :            : typedef struct {
+      71                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+      72                 :            :     uint8_t buffer[LIBSPDM_MAX_CERT_CHAIN_SIZE];
+      73                 :            :     size_t buffer_size;
+      74                 :            : #else
+      75                 :            :     uint8_t buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+      76                 :            :     uint32_t buffer_hash_size;
+      77                 :            :     /* leaf cert public key of the peer */
+      78                 :            :     void *leaf_cert_public_key;
+      79                 :            : #endif
+      80                 :            : } libspdm_peer_used_cert_chain_t;
+      81                 :            : 
+      82                 :            : typedef struct {
+      83                 :            :     /* Local device info */
+      84                 :            :     libspdm_device_version_t version;
+      85                 :            :     libspdm_device_capability_t capability;
+      86                 :            :     libspdm_device_algorithm_t algorithm;
+      87                 :            :     libspdm_device_version_t secured_message_version;
+      88                 :            : 
+      89                 :            :     /* My Certificate */
+      90                 :            :     const void *local_cert_chain_provision[SPDM_MAX_SLOT_COUNT];
+      91                 :            :     size_t local_cert_chain_provision_size[SPDM_MAX_SLOT_COUNT];
+      92                 :            :     uint8_t local_supported_slot_mask;
+      93                 :            :     spdm_key_pair_id_t local_key_pair_id[SPDM_MAX_SLOT_COUNT];
+      94                 :            :     spdm_certificate_info_t local_cert_info[SPDM_MAX_SLOT_COUNT];
+      95                 :            :     spdm_key_usage_bit_mask_t local_key_usage_bit_mask[SPDM_MAX_SLOT_COUNT];
+      96                 :            :     /* My raw public key (slot_id - 0xFF) */
+      97                 :            :     const void *local_public_key_provision;
+      98                 :            :     size_t local_public_key_provision_size;
+      99                 :            : 
+     100                 :            :     /* Peer Root Certificate */
+     101                 :            :     const void *peer_root_cert_provision[LIBSPDM_MAX_ROOT_CERT_SUPPORT];
+     102                 :            :     size_t peer_root_cert_provision_size[LIBSPDM_MAX_ROOT_CERT_SUPPORT];
+     103                 :            :     /* Peer raw public key (slot_id - 0xFF) */
+     104                 :            :     const void *peer_public_key_provision;
+     105                 :            :     size_t peer_public_key_provision_size;
+     106                 :            : 
+     107                 :            :     /* Peer Cert verify*/
+     108                 :            :     libspdm_verify_spdm_cert_chain_func verify_peer_spdm_cert_chain;
+     109                 :            : 
+     110                 :            :     /* Responder policy*/
+     111                 :            :     bool basic_mut_auth_requested;
+     112                 :            :     uint8_t mut_auth_requested;
+     113                 :            :     uint8_t heartbeat_period;
+     114                 :            : 
+     115                 :            :     /*The device role*/
+     116                 :            :     bool is_requester;
+     117                 :            : 
+     118                 :            :     uint8_t total_key_pairs;
+     119                 :            : } libspdm_local_context_t;
+     120                 :            : 
+     121                 :            : typedef struct {
+     122                 :            :     /* Connection State */
+     123                 :            :     libspdm_connection_state_t connection_state;
+     124                 :            : 
+     125                 :            :     /* Peer device info (negotiated) */
+     126                 :            :     spdm_version_number_t version;
+     127                 :            :     libspdm_device_capability_t capability;
+     128                 :            :     libspdm_device_algorithm_t algorithm;
+     129                 :            :     spdm_version_number_t secured_message_version;
+     130                 :            : 
+     131                 :            :     /* Peer digests buffer */
+     132                 :            :     uint8_t peer_provisioned_slot_mask;
+     133                 :            :     uint8_t peer_supported_slot_mask;
+     134                 :            :     uint8_t peer_total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
+     135                 :            : 
+     136                 :            :     spdm_key_pair_id_t peer_key_pair_id[SPDM_MAX_SLOT_COUNT];
+     137                 :            :     spdm_certificate_info_t peer_cert_info[SPDM_MAX_SLOT_COUNT];
+     138                 :            :     spdm_key_usage_bit_mask_t peer_key_usage_bit_mask[SPDM_MAX_SLOT_COUNT];
+     139                 :            : 
+     140                 :            :     /* Peer CertificateChain */
+     141                 :            :     libspdm_peer_used_cert_chain_t peer_used_cert_chain[SPDM_MAX_SLOT_COUNT];
+     142                 :            :     uint8_t peer_used_cert_chain_slot_id;
+     143                 :            : 
+     144                 :            :     /* Local Used CertificateChain (for responder, or requester in mut auth) */
+     145                 :            :     const uint8_t *local_used_cert_chain_buffer;
+     146                 :            :     size_t local_used_cert_chain_buffer_size;
+     147                 :            :     uint8_t local_used_cert_chain_slot_id;
+     148                 :            : 
+     149                 :            :     /* Specifies whether the cached negotiated state should be invalidated. (responder only)
+     150                 :            :      * This is a "sticky" bit wherein if it is set to 1 then it cannot be set to 0. */
+     151                 :            :     uint8_t end_session_attributes;
+     152                 :            : 
+     153                 :            :     /* multi-key negotiated result */
+     154                 :            :     bool multi_key_conn_req;
+     155                 :            :     bool multi_key_conn_rsp;
+     156                 :            : } libspdm_connection_info_t;
+     157                 :            : 
+     158                 :            : typedef struct {
+     159                 :            :     size_t max_buffer_size;
+     160                 :            :     size_t buffer_size;
+     161                 :            :     /*uint8_t   buffer[max_buffer_size];*/
+     162                 :            : } libspdm_managed_buffer_t;
+     163                 :            : 
+     164                 :            : typedef struct {
+     165                 :            :     size_t max_buffer_size;
+     166                 :            :     size_t buffer_size;
+     167                 :            :     uint8_t buffer[LIBSPDM_MAX_MESSAGE_VCA_BUFFER_SIZE];
+     168                 :            : } libspdm_vca_managed_buffer_t;
+     169                 :            : 
+     170                 :            : /*
+     171                 :            :  * +--------------------------+------------------------------------------+---------+
+     172                 :            :  * | DIGESTS 1.3              | 4 + (H [+ 4]) * SlotNum = [36, 548]      | [1, 18] |
+     173                 :            :  * +--------------------------+------------------------------------------+---------+
+     174                 :            :  * It is for multi-key.
+     175                 :            :  */
+     176                 :            : #define LIBSPDM_MAX_MESSAGE_D_BUFFER_SIZE (4 + \
+     177                 :            :                                            (LIBSPDM_MAX_HASH_SIZE + 4) * SPDM_MAX_SLOT_COUNT)
+     178                 :            : 
+     179                 :            : typedef struct {
+     180                 :            :     size_t max_buffer_size;
+     181                 :            :     size_t buffer_size;
+     182                 :            :     uint8_t buffer[LIBSPDM_MAX_MESSAGE_D_BUFFER_SIZE];
+     183                 :            : } libspdm_message_d_managed_buffer_t;
+     184                 :            : 
+     185                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     186                 :            : 
+     187                 :            : /*
+     188                 :            :  * +--------------------------+------------------------------------------+---------+
+     189                 :            :  * | GET_DIGESTS 1.3          | 4                                        | 1       |
+     190                 :            :  * | DIGESTS 1.3              | 4 + (H [+ 4]) * SlotNum = [36, 548]      | [1, 18] |
+     191                 :            :  * +--------------------------+------------------------------------------+---------+
+     192                 :            :  * | GET_CERTIFICATE 1.3      | 8                                        | 1       |
+     193                 :            :  * | CERTIFICATE 1.3          | 8 + PortionLen                           | [1, ]   |
+     194                 :            :  * +--------------------------+------------------------------------------+---------+
+     195                 :            :  */
+     196                 :            : #define LIBSPDM_MAX_MESSAGE_B_BUFFER_SIZE (24 + \
+     197                 :            :                                            (LIBSPDM_MAX_HASH_SIZE + 4) * SPDM_MAX_SLOT_COUNT + \
+     198                 :            :                                            LIBSPDM_MAX_CERT_CHAIN_SIZE)
+     199                 :            : 
+     200                 :            : /*
+     201                 :            :  * +--------------------------+------------------------------------------+---------+
+     202                 :            :  * | CHALLENGE 1.3            | 44                                       | 1       |
+     203                 :            :  * | CHALLENGE_AUTH 1.3       | 46 + H * 2 + S [+ O] = [166, 678]        | [6, 23] |
+     204                 :            :  * +--------------------------+------------------------------------------+---------+
+     205                 :            :  */
+     206                 :            : #define LIBSPDM_MAX_MESSAGE_C_BUFFER_SIZE (90 + \
+     207                 :            :                                            LIBSPDM_MAX_HASH_SIZE * 2 + \
+     208                 :            :                                            LIBSPDM_MAX_ASYM_KEY_SIZE + SPDM_MAX_OPAQUE_DATA_SIZE)
+     209                 :            : 
+     210                 :            : /*
+     211                 :            :  * +--------------------------+------------------------------------------+---------+
+     212                 :            :  * | GET_MEASUREMENTS 1.3     | 13 + Nonce (0 or 32)                     | 1       |
+     213                 :            :  * | MEASUREMENTS 1.3         | 50 + MeasRecLen (+ S) [+ O] = [106, 554] | [4, 19] |
+     214                 :            :  * +--------------------------+------------------------------------------+---------+
+     215                 :            :  */
+     216                 :            : #define LIBSPDM_MAX_MESSAGE_M_BUFFER_SIZE (63 + SPDM_NONCE_SIZE + \
+     217                 :            :                                            LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE + \
+     218                 :            :                                            LIBSPDM_MAX_ASYM_KEY_SIZE + SPDM_MAX_OPAQUE_DATA_SIZE)
+     219                 :            : 
+     220                 :            : /*
+     221                 :            :  * +--------------------------+------------------------------------------+---------+
+     222                 :            :  * | KEY_EXCHANGE 1.3         | 42 + D [+ O] = [106, 554]                | [4, 19] |
+     223                 :            :  * | KEY_EXCHANGE_RSP 1.3     | 42 + D + H + S (+ H) [+ O] = [234, 1194] | [8, 40] |
+     224                 :            :  * +--------------------------+------------------------------------------+---------+
+     225                 :            :  * | PSK_EXCHANGE 1.3         | 12 [+ PSKHint] + R [+ O] = 44            | 2       |
+     226                 :            :  * | PSK_EXCHANGE_RSP 1.3     | 12 + R + H (+ H) [+ O] = [108, 172]      | [4, 6]  |
+     227                 :            :  * +--------------------------+------------------------------------------+---------+
+     228                 :            :  */
+     229                 :            : #define LIBSPDM_MAX_MESSAGE_K_BUFFER_SIZE (84 + LIBSPDM_MAX_DHE_KEY_SIZE * 2 + \
+     230                 :            :                                            LIBSPDM_MAX_HASH_SIZE * 2 + LIBSPDM_MAX_ASYM_KEY_SIZE + \
+     231                 :            :                                            SPDM_MAX_OPAQUE_DATA_SIZE * 2)
+     232                 :            : 
+     233                 :            : /*
+     234                 :            :  * +--------------------------+------------------------------------------+---------+
+     235                 :            :  * | FINISH 1.3               | 4 (+ S) + H = [100, 580]                 | [4, 20] |
+     236                 :            :  * | FINISH_RSP 1.3           | 4 (+ H) = [36, 69]                       | [1, 3]  |
+     237                 :            :  * +--------------------------+------------------------------------------+---------+
+     238                 :            :  * | PSK_FINISH 1.3           | 4 + H = [36, 68]                         | [1, 3]  |
+     239                 :            :  * | PSK_FINISH_RSP 1.3       | 4                                        | 1       |
+     240                 :            :  * +--------------------------+------------------------------------------+---------+
+     241                 :            :  */
+     242                 :            : #define LIBSPDM_MAX_MESSAGE_F_BUFFER_SIZE (8 + LIBSPDM_MAX_HASH_SIZE * 2 + \
+     243                 :            :                                            LIBSPDM_MAX_ASYM_KEY_SIZE)
+     244                 :            : 
+     245                 :            : #define LIBSPDM_MAX_MESSAGE_L1L2_BUFFER_SIZE \
+     246                 :            :     (LIBSPDM_MAX_MESSAGE_VCA_BUFFER_SIZE + LIBSPDM_MAX_MESSAGE_M_BUFFER_SIZE)
+     247                 :            : 
+     248                 :            : #define LIBSPDM_MAX_MESSAGE_M1M2_BUFFER_SIZE \
+     249                 :            :     (LIBSPDM_MAX_MESSAGE_VCA_BUFFER_SIZE + \
+     250                 :            :      LIBSPDM_MAX_MESSAGE_B_BUFFER_SIZE + LIBSPDM_MAX_MESSAGE_C_BUFFER_SIZE)
+     251                 :            : 
+     252                 :            : #define LIBSPDM_MAX_MESSAGE_TH_BUFFER_SIZE \
+     253                 :            :     (LIBSPDM_MAX_MESSAGE_VCA_BUFFER_SIZE + \
+     254                 :            :      LIBSPDM_MAX_MESSAGE_D_BUFFER_SIZE + \
+     255                 :            :      LIBSPDM_MAX_HASH_SIZE + LIBSPDM_MAX_MESSAGE_K_BUFFER_SIZE + \
+     256                 :            :      LIBSPDM_MAX_MESSAGE_D_BUFFER_SIZE + \
+     257                 :            :      LIBSPDM_MAX_HASH_SIZE + LIBSPDM_MAX_MESSAGE_F_BUFFER_SIZE)
+     258                 :            : 
+     259                 :            : typedef struct {
+     260                 :            :     size_t max_buffer_size;
+     261                 :            :     size_t buffer_size;
+     262                 :            :     uint8_t buffer[LIBSPDM_MAX_MESSAGE_B_BUFFER_SIZE];
+     263                 :            : } libspdm_message_b_managed_buffer_t;
+     264                 :            : 
+     265                 :            : typedef struct {
+     266                 :            :     size_t max_buffer_size;
+     267                 :            :     size_t buffer_size;
+     268                 :            :     uint8_t buffer[LIBSPDM_MAX_MESSAGE_C_BUFFER_SIZE];
+     269                 :            : } libspdm_message_c_managed_buffer_t;
+     270                 :            : 
+     271                 :            : typedef struct {
+     272                 :            :     size_t max_buffer_size;
+     273                 :            :     size_t buffer_size;
+     274                 :            :     uint8_t buffer[LIBSPDM_MAX_MESSAGE_M_BUFFER_SIZE];
+     275                 :            : } libspdm_message_m_managed_buffer_t;
+     276                 :            : 
+     277                 :            : typedef struct {
+     278                 :            :     size_t max_buffer_size;
+     279                 :            :     size_t buffer_size;
+     280                 :            :     uint8_t buffer[LIBSPDM_MAX_MESSAGE_K_BUFFER_SIZE];
+     281                 :            : } libspdm_message_k_managed_buffer_t;
+     282                 :            : 
+     283                 :            : typedef struct {
+     284                 :            :     size_t max_buffer_size;
+     285                 :            :     size_t buffer_size;
+     286                 :            :     uint8_t buffer[LIBSPDM_MAX_MESSAGE_F_BUFFER_SIZE];
+     287                 :            : } libspdm_message_f_managed_buffer_t;
+     288                 :            : 
+     289                 :            : typedef struct {
+     290                 :            :     size_t max_buffer_size;
+     291                 :            :     size_t buffer_size;
+     292                 :            :     uint8_t buffer[LIBSPDM_MAX_MESSAGE_L1L2_BUFFER_SIZE];
+     293                 :            : } libspdm_l1l2_managed_buffer_t;
+     294                 :            : 
+     295                 :            : typedef struct {
+     296                 :            :     size_t max_buffer_size;
+     297                 :            :     size_t buffer_size;
+     298                 :            :     uint8_t buffer[LIBSPDM_MAX_MESSAGE_M1M2_BUFFER_SIZE];
+     299                 :            : } libspdm_m1m2_managed_buffer_t;
+     300                 :            : 
+     301                 :            : typedef struct {
+     302                 :            :     size_t max_buffer_size;
+     303                 :            :     size_t buffer_size;
+     304                 :            :     uint8_t buffer[LIBSPDM_MAX_MESSAGE_TH_BUFFER_SIZE];
+     305                 :            : } libspdm_th_managed_buffer_t;
+     306                 :            : 
+     307                 :            : #endif /* LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT */
+     308                 :            : 
+     309                 :            : /* signature = Sign(SK, hash(M1))
+     310                 :            :  * Verify(PK, hash(M2), signature)*/
+     311                 :            : 
+     312                 :            : /* M1/M2 = Concatenate (A, B, C)
+     313                 :            :  * A = Concatenate (GET_VERSION, VERSION, GET_CAPABILITIES, CAPABILITIES, NEGOTIATE_ALGORITHMS, ALGORITHMS)
+     314                 :            :  * B = Concatenate (GET_DIGEST, DIGEST, GET_CERTIFICATE, CERTIFICATE)
+     315                 :            :  * C = Concatenate (CHALLENGE, CHALLENGE_AUTH\signature)*/
+     316                 :            : 
+     317                 :            : /* Mut M1/M2 = Concatenate (MutB, MutC)
+     318                 :            :  * MutB = Concatenate (GET_DIGEST, DIGEST, GET_CERTIFICATE, CERTIFICATE)
+     319                 :            :  * MutC = Concatenate (CHALLENGE, CHALLENGE_AUTH\signature)*/
+     320                 :            : 
+     321                 :            : /* signature = Sign(SK, hash(L1))
+     322                 :            :  * Verify(PK, hash(L2), signature)*/
+     323                 :            : 
+     324                 :            : /* L1/L2 = Concatenate (M)
+     325                 :            :  * M = Concatenate (GET_MEASUREMENT, MEASUREMENT\signature)*/
+     326                 :            : 
+     327                 :            : typedef struct {
+     328                 :            :     /* the message_a must be plan text because we do not know the algorithm yet.*/
+     329                 :            :     libspdm_vca_managed_buffer_t message_a;
+     330                 :            :     libspdm_message_d_managed_buffer_t message_d;
+     331                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     332                 :            :     libspdm_message_b_managed_buffer_t message_b;
+     333                 :            :     libspdm_message_c_managed_buffer_t message_c;
+     334                 :            :     libspdm_message_b_managed_buffer_t message_mut_b;
+     335                 :            :     libspdm_message_c_managed_buffer_t message_mut_c;
+     336                 :            :     libspdm_message_m_managed_buffer_t message_m;
+     337                 :            : #else
+     338                 :            :     void *digest_context_m1m2;
+     339                 :            :     void *digest_context_mut_m1m2;
+     340                 :            :     void *digest_context_l1l2;
+     341                 :            : #endif
+     342                 :            : } libspdm_transcript_t;
+     343                 :            : 
+     344                 :            : /* TH for KEY_EXCHANGE response signature: Concatenate (A, D, Ct, K)
+     345                 :            :  * D = DIGEST, if MULTI_KEY_CONN_RSP
+     346                 :            :  * Ct = certificate chain
+     347                 :            :  * K  = Concatenate (KEY_EXCHANGE request, KEY_EXCHANGE response\signature+verify_data)*/
+     348                 :            : 
+     349                 :            : /* TH for KEY_EXCHANGE response HMAC: Concatenate (A, D, Ct, K)
+     350                 :            :  * D = DIGEST, if MULTI_KEY_CONN_RSP
+     351                 :            :  * Ct = certificate chain
+     352                 :            :  * K  = Concatenate (KEY_EXCHANGE request, KEY_EXCHANGE response\verify_data)*/
+     353                 :            : 
+     354                 :            : /* TH for FINISH request signature: Concatenate (A, D, Ct, K, EncapD, CM, F)
+     355                 :            :  * D = DIGEST, if MULTI_KEY_CONN_RSP
+     356                 :            :  * Ct = certificate chain
+     357                 :            :  * K  = Concatenate (KEY_EXCHANGE request, KEY_EXCHANGE response)
+     358                 :            :  * EncapD = Encap DIGEST, if MULTI_KEY_CONN_REQ
+     359                 :            :  * CM = mutual certificate chain
+     360                 :            :  * F  = Concatenate (FINISH request\signature+verify_data)*/
+     361                 :            : 
+     362                 :            : /* TH for FINISH response HMAC: Concatenate (A, D, Ct, K, EncapD, CM, F)
+     363                 :            :  * D = DIGEST, if MULTI_KEY_CONN_RSP
+     364                 :            :  * Ct = certificate chain
+     365                 :            :  * K = Concatenate (KEY_EXCHANGE request, KEY_EXCHANGE response)
+     366                 :            :  * EncapD = Encap DIGEST, if MULTI_KEY_CONN_REQ
+     367                 :            :  * CM = mutual certificate chain, if MutAuth
+     368                 :            :  * F = Concatenate (FINISH request\verify_data)*/
+     369                 :            : 
+     370                 :            : /* th1: Concatenate (A, D, Ct, K)
+     371                 :            :  * D = DIGEST, if MULTI_KEY_CONN_RSP
+     372                 :            :  * Ct = certificate chain
+     373                 :            :  * K  = Concatenate (KEY_EXCHANGE request, KEY_EXCHANGE response)*/
+     374                 :            : 
+     375                 :            : /* th2: Concatenate (A, D, Ct, K, EncapD, CM, F)
+     376                 :            :  * D = DIGEST, if MULTI_KEY_CONN_RSP
+     377                 :            :  * Ct = certificate chain
+     378                 :            :  * K  = Concatenate (KEY_EXCHANGE request, KEY_EXCHANGE response)
+     379                 :            :  * EncapD = Encap DIGEST, if MULTI_KEY_CONN_REQ
+     380                 :            :  * CM = mutual certificate chain, if MutAuth
+     381                 :            :  * F  = Concatenate (FINISH request, FINISH response)*/
+     382                 :            : 
+     383                 :            : /* TH for PSK_EXCHANGE response HMAC: Concatenate (A, K)
+     384                 :            :  * K  = Concatenate (PSK_EXCHANGE request, PSK_EXCHANGE response\verify_data)*/
+     385                 :            : 
+     386                 :            : /* TH for PSK_FINISH response HMAC: Concatenate (A, K, F)
+     387                 :            :  * K  = Concatenate (PSK_EXCHANGE request, PSK_EXCHANGE response)
+     388                 :            :  * F  = Concatenate (PSK_FINISH request\verify_data)*/
+     389                 :            : 
+     390                 :            : /* TH1_PSK1: Concatenate (A, K)
+     391                 :            :  * K  = Concatenate (PSK_EXCHANGE request, PSK_EXCHANGE response\verify_data)*/
+     392                 :            : 
+     393                 :            : /* TH1_PSK2: Concatenate (A, K, F)
+     394                 :            :  * K  = Concatenate (PSK_EXCHANGE request, PSK_EXCHANGE response)
+     395                 :            :  * F  = Concatenate (PSK_FINISH request\verify_data)*/
+     396                 :            : 
+     397                 :            : /* TH2_PSK: Concatenate (A, K, F)
+     398                 :            :  * K  = Concatenate (PSK_EXCHANGE request, PSK_EXCHANGE response)
+     399                 :            :  * F  = Concatenate (PSK_FINISH request, PSK_FINISH response)*/
+     400                 :            : 
+     401                 :            : typedef struct {
+     402                 :            :     libspdm_message_d_managed_buffer_t message_encap_d;
+     403                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     404                 :            :     libspdm_message_k_managed_buffer_t message_k;
+     405                 :            :     libspdm_message_f_managed_buffer_t message_f;
+     406                 :            :     libspdm_message_m_managed_buffer_t message_m;
+     407                 :            : #else
+     408                 :            :     bool message_f_initialized;
+     409                 :            :     void *digest_context_th;
+     410                 :            :     void *digest_context_l1l2;
+     411                 :            :     /* this is back up for message F reset.*/
+     412                 :            :     void *digest_context_th_backup;
+     413                 :            : #endif
+     414                 :            : } libspdm_session_transcript_t;
+     415                 :            : 
+     416                 :            : typedef struct {
+     417                 :            :     uint32_t session_id;
+     418                 :            :     bool use_psk;
+     419                 :            :     uint8_t mut_auth_requested;
+     420                 :            :     uint8_t end_session_attributes;
+     421                 :            :     uint8_t session_policy;
+     422                 :            :     uint8_t heartbeat_period;
+     423                 :            :     libspdm_session_transcript_t session_transcript;
+     424                 :            :     /* Register for the last KEY_UPDATE token and operation (responder only)*/
+     425                 :            :     spdm_key_update_request_t last_key_update_request;
+     426                 :            :     void *secured_message_context;
+     427                 :            : } libspdm_session_info_t;
+     428                 :            : 
+     429                 :            : #define LIBSPDM_MAX_ENCAP_REQUEST_OP_CODE_SEQUENCE_COUNT 3
+     430                 :            : typedef struct {
+     431                 :            :     /* Valid OpCode: GET_DIGEST/GET_CERTIFICATE/CHALLENGE/KEY_UPDATE
+     432                 :            :      * The last one is 0x00, as terminator.*/
+     433                 :            :     uint8_t request_op_code_sequence[LIBSPDM_MAX_ENCAP_REQUEST_OP_CODE_SEQUENCE_COUNT + 1];
+     434                 :            :     uint8_t request_op_code_count;
+     435                 :            :     uint8_t current_request_op_code;
+     436                 :            :     uint8_t request_id;
+     437                 :            :     uint8_t req_slot_id;
+     438                 :            :     spdm_message_header_t last_encap_request_header;
+     439                 :            :     size_t last_encap_request_size;
+     440                 :            :     uint16_t cert_chain_total_len;
+     441                 :            :     uint8_t req_context[SPDM_REQ_CONTEXT_SIZE];
+     442                 :            : } libspdm_encap_context_t;
+     443                 :            : 
+     444                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
+     445                 :            : typedef struct {
+     446                 :            :     bool chunk_in_use;
+     447                 :            :     uint8_t chunk_handle;
+     448                 :            :     uint16_t chunk_seq_no;
+     449                 :            :     size_t chunk_bytes_transferred;
+     450                 :            : 
+     451                 :            :     void* large_message;
+     452                 :            :     size_t large_message_size;
+     453                 :            :     size_t large_message_capacity;
+     454                 :            : } libspdm_chunk_info_t;
+     455                 :            : 
+     456                 :            : typedef struct {
+     457                 :            :     libspdm_chunk_info_t send;
+     458                 :            :     libspdm_chunk_info_t get;
+     459                 :            : } libspdm_chunk_context_t;
+     460                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP */
+     461                 :            : 
+     462                 :            : #if LIBSPDM_ENABLE_MSG_LOG
+     463                 :            : typedef struct {
+     464                 :            :     void *buffer;
+     465                 :            :     size_t max_buffer_size;
+     466                 :            :     uint32_t mode;
+     467                 :            :     size_t buffer_size;
+     468                 :            :     uint32_t status;
+     469                 :            : } libspdm_msg_log_t;
+     470                 :            : #endif /* LIBSPDM_ENABLE_MSG_LOG */
+     471                 :            : 
+     472                 :            : #if LIBSPDM_FIPS_MODE
+     473                 :            : typedef struct {
+     474                 :            :     /**
+     475                 :            :      * Tested algo flag: 0 represents that the algo is not tested.
+     476                 :            :      * See LIBSPDM_FIPS_SELF_TEST_xxx;
+     477                 :            :      **/
+     478                 :            :     uint32_t tested_algo;
+     479                 :            :     /**
+     480                 :            :      * Flag for the result of run algo self_test, 0 represents the result is failed.
+     481                 :            :      * See LIBSPDM_FIPS_SELF_TEST_xxx;
+     482                 :            :      **/
+     483                 :            :     uint32_t self_test_result;
+     484                 :            : } libspdm_fips_selftest_context;
+     485                 :            : #endif /* LIBSPDM_FIPS_MODE */
+     486                 :            : 
+     487                 :            : #define LIBSPDM_CONTEXT_STRUCT_VERSION 0x3
+     488                 :            : 
+     489                 :            : typedef struct {
+     490                 :            :     uint32_t version;
+     491                 :            : 
+     492                 :            :     /* IO information */
+     493                 :            :     libspdm_device_send_message_func send_message;
+     494                 :            :     libspdm_device_receive_message_func receive_message;
+     495                 :            : 
+     496                 :            :     /*
+     497                 :            :      * reserved for request and response in the main dispatch function in SPDM responder.
+     498                 :            :      * this buffer is the transport message received from spdm_context->receive_message()
+     499                 :            :      * or sent to spdm_context->send_message().
+     500                 :            :      * This message may be SPDM transport message or secured SPDM transport message.
+     501                 :            :      **/
+     502                 :            :     libspdm_device_acquire_sender_buffer_func acquire_sender_buffer;
+     503                 :            :     libspdm_device_release_sender_buffer_func release_sender_buffer;
+     504                 :            :     libspdm_device_acquire_receiver_buffer_func acquire_receiver_buffer;
+     505                 :            :     libspdm_device_release_receiver_buffer_func release_receiver_buffer;
+     506                 :            : 
+     507                 :            :     /* Transport Layer information */
+     508                 :            :     libspdm_transport_encode_message_func transport_encode_message;
+     509                 :            :     libspdm_transport_decode_message_func transport_decode_message;
+     510                 :            : 
+     511                 :            :     /* Cached plain text command
+     512                 :            :      * If the command is cipher text, decrypt then cache it. */
+     513                 :            :     void *last_spdm_request;
+     514                 :            :     size_t last_spdm_request_size;
+     515                 :            : 
+     516                 :            :     /* Buffers used for data processing and transport. */
+     517                 :            :     void *scratch_buffer;
+     518                 :            :     size_t scratch_buffer_size;
+     519                 :            :     void *sender_buffer;
+     520                 :            :     size_t sender_buffer_size;
+     521                 :            :     void *receiver_buffer;
+     522                 :            :     size_t receiver_buffer_size;
+     523                 :            : 
+     524                 :            :     /* Cache session_id in this spdm_message, only valid for secured message. */
+     525                 :            :     uint32_t last_spdm_request_session_id;
+     526                 :            :     bool last_spdm_request_session_id_valid;
+     527                 :            : 
+     528                 :            :     /* Cache the error in libspdm_process_request. It is handled in libspdm_build_response. */
+     529                 :            :     libspdm_error_struct_t last_spdm_error;
+     530                 :            : 
+     531                 :            :     /* Register GetResponse function (responder only) */
+     532                 :            :     void *get_response_func;
+     533                 :            : 
+     534                 :            :     /* Register GetEncapResponse function (requester only) */
+     535                 :            :     void *get_encap_response_func;
+     536                 :            :     libspdm_encap_context_t encap_context;
+     537                 :            : 
+     538                 :            :     /* Register spdm_session_state_callback function (responder only)
+     539                 :            :     * Register can know the state after StartSession / EndSession. */
+     540                 :            :     void *spdm_session_state_callback;
+     541                 :            : 
+     542                 :            :     /* Register spdm_connection_state_callback function (responder only)
+     543                 :            :      * Register can know the connection state such as negotiated. */
+     544                 :            :     void *spdm_connection_state_callback;
+     545                 :            : 
+     546                 :            :     /* Register libspdm_key_update_callback function (responder only)
+     547                 :            :      * Register can know when session keys are updated during KEY_UPDATE operations. */
+     548                 :            :     void *spdm_key_update_callback;
+     549                 :            : 
+     550                 :            :     libspdm_local_context_t local_context;
+     551                 :            : 
+     552                 :            :     libspdm_connection_info_t connection_info;
+     553                 :            :     libspdm_transcript_t transcript;
+     554                 :            : 
+     555                 :            :     libspdm_session_info_t session_info[LIBSPDM_MAX_SESSION_COUNT];
+     556                 :            : 
+     557                 :            :     /* Buffer that the Responder uses to store the Requester's certificate chain for
+     558                 :            :      * mutual authentication. */
+     559                 :            :     void *mut_auth_cert_chain_buffer;
+     560                 :            :     size_t mut_auth_cert_chain_buffer_size;
+     561                 :            :     size_t mut_auth_cert_chain_buffer_max_size;
+     562                 :            : 
+     563                 :            :     /* Cache latest session ID for HANDSHAKE_IN_THE_CLEAR */
+     564                 :            :     uint32_t latest_session_id;
+     565                 :            : 
+     566                 :            :     /* Register for Responder state, be initial to Normal (responder only) */
+     567                 :            :     libspdm_response_state_t response_state;
+     568                 :            : 
+     569                 :            :     /* Cached data for SPDM_ERROR_CODE_RESPONSE_NOT_READY/SPDM_RESPOND_IF_READY */
+     570                 :            :     spdm_error_data_response_not_ready_t error_data;
+     571                 :            : #if LIBSPDM_RESPOND_IF_READY_SUPPORT
+     572                 :            :     void *cache_spdm_request;
+     573                 :            :     size_t cache_spdm_request_size;
+     574                 :            : #endif
+     575                 :            :     uint8_t current_token;
+     576                 :            : 
+     577                 :            :     /* Register for the retry times when receive "BUSY" Error response (requester only) */
+     578                 :            :     uint8_t retry_times;
+     579                 :            :     /* Register for the delay time in microseconds between retry requests
+     580                 :            :      * when receive "BUSY" Error response (requester only) */
+     581                 :            :     uint64_t retry_delay_time;
+     582                 :            :     bool crypto_request;
+     583                 :            : 
+     584                 :            :     /* App context data for use by application */
+     585                 :            :     void *app_context_data_ptr;
+     586                 :            : 
+     587                 :            :     /* See LIBSPDM_DATA_HANDLE_ERROR_RETURN_POLICY_*. */
+     588                 :            :     uint8_t handle_error_return_policy;
+     589                 :            : 
+     590                 :            :     /* Max session count for DHE session and PSK session
+     591                 :            :      * Set via LIBSPDM_DATA_MAX_DHE_SESSION_COUNT and LIBSPDM_DATA_MAX_PSK_SESSION_COUNT */
+     592                 :            :     uint32_t max_dhe_session_count;
+     593                 :            :     uint32_t max_psk_session_count;
+     594                 :            : 
+     595                 :            :     /* Current session count for DHE session and PSK session */
+     596                 :            :     uint32_t current_dhe_session_count;
+     597                 :            :     uint32_t current_psk_session_count;
+     598                 :            : 
+     599                 :            :     /* see LIBSPDM_DATA_MAX_SPDM_SESSION_SEQUENCE_NUMBER */
+     600                 :            :     uint64_t max_spdm_session_sequence_number;
+     601                 :            : 
+     602                 :            :     uint8_t sequence_number_endian;
+     603                 :            : 
+     604                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
+     605                 :            :     /* Chunk specific context */
+     606                 :            :     libspdm_chunk_context_t chunk_context;
+     607                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP */
+     608                 :            : 
+     609                 :            : #if LIBSPDM_ENABLE_MSG_LOG
+     610                 :            :     libspdm_msg_log_t msg_log;
+     611                 :            : #endif /* LIBSPDM_ENABLE_MSG_LOG */
+     612                 :            : 
+     613                 :            : #if LIBSPDM_FIPS_MODE
+     614                 :            :     libspdm_fips_selftest_context fips_selftest_context;
+     615                 :            : #endif /* LIBSPDM_FIPS_MODE */
+     616                 :            : 
+     617                 :            :     /* Endianness (BE/LE/Both) to use for signature verification on SPDM 1.0 and 1.1
+     618                 :            :      * This field is ignored for other SPDM versions */
+     619                 :            :     uint8_t spdm_10_11_verify_signature_endian;
+     620                 :            : 
+     621                 :            : #if LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES
+     622                 :            :     libspdm_vendor_response_callback_func vendor_response_callback;
+     623                 :            :     libspdm_vendor_get_id_callback_func vendor_response_get_id;
+     624                 :            : #endif /* LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES */
+     625                 :            : } libspdm_context_t;
+     626                 :            : 
+     627                 :            : #define LIBSPDM_CONTEXT_SIZE_WITHOUT_SECURED_CONTEXT (sizeof(libspdm_context_t))
+     628                 :            : #define LIBSPDM_CONTEXT_SIZE_ALL (LIBSPDM_CONTEXT_SIZE_WITHOUT_SECURED_CONTEXT + \
+     629                 :            :                                   LIBSPDM_SECURED_MESSAGE_CONTEXT_SIZE * LIBSPDM_MAX_SESSION_COUNT)
+     630                 :            : 
+     631                 :            : #if LIBSPDM_DEBUG_PRINT_ENABLE
+     632                 :            : /**
+     633                 :            :  * Return the request code name based on given request code.
+     634                 :            :  *
+     635                 :            :  * @param  request_code                  The SPDM request code.
+     636                 :            :  *
+     637                 :            :  * @return request code name according to the request code.
+     638                 :            :  **/
+     639                 :            : const char *libspdm_get_code_str(uint8_t request_code);
+     640                 :            : 
+     641                 :            : #ifdef LIBSPDM_INTERNAL_DUMP_HEX_STR_OVERRIDE
+     642                 :            : extern void LIBSPDM_INTERNAL_DUMP_HEX_STR_OVERRIDE(const uint8_t *data, size_t size);
+     643                 :            : #define LIBSPDM_INTERNAL_DUMP_HEX_STR(data, size) LIBSPDM_INTERNAL_DUMP_HEX_STR_OVERRIDE(data, size)
+     644                 :            : #else
+     645                 :            : /**
+     646                 :            :  * This function dump raw data.
+     647                 :            :  *
+     648                 :            :  * @param  data  raw data
+     649                 :            :  * @param  size  raw data size
+     650                 :            :  **/
+     651                 :            : void libspdm_internal_dump_hex_str(const uint8_t *data, size_t size);
+     652                 :            : #define LIBSPDM_INTERNAL_DUMP_HEX_STR(data, size) libspdm_internal_dump_hex_str(data, size)
+     653                 :            : #endif /* LIBSPDM_INTERNAL_DUMP_HEX_STR_OVERRIDE */
+     654                 :            : 
+     655                 :            : #ifdef LIBSPDM_INTERNAL_DUMP_DATA_OVERRIDE
+     656                 :            : extern void LIBSPDM_INTERNAL_DUMP_DATA_OVERRIDE(const uint8_t *data, size_t size);
+     657                 :            : #define LIBSPDM_INTERNAL_DUMP_DATA(data, size) LIBSPDM_INTERNAL_DUMP_DATA_OVERRIDE(data, size)
+     658                 :            : #else
+     659                 :            : /**
+     660                 :            :  * This function dump raw data.
+     661                 :            :  *
+     662                 :            :  * @param  data  raw data
+     663                 :            :  * @param  size  raw data size
+     664                 :            :  **/
+     665                 :            : void libspdm_internal_dump_data(const uint8_t *data, size_t size);
+     666                 :            : #define LIBSPDM_INTERNAL_DUMP_DATA(data, size) libspdm_internal_dump_data(data, size)
+     667                 :            : #endif /* LIBSPDM_INTERNAL_DUMP_DATA_OVERRIDE */
+     668                 :            : 
+     669                 :            : #ifdef LIBSPDM_INTERNAL_DUMP_HEX_OVERRIDE
+     670                 :            : extern void LIBSPDM_INTERNAL_DUMP_HEX_OVERRIDE(const uint8_t *data, size_t size);
+     671                 :            : #define LIBSPDM_INTERNAL_DUMP_HEX(data, size) LIBSPDM_INTERNAL_DUMP_HEX_OVERRIDE(data, size)
+     672                 :            : #else
+     673                 :            : /**
+     674                 :            :  * This function dump raw data with column format.
+     675                 :            :  *
+     676                 :            :  * @param  data  raw data
+     677                 :            :  * @param  size  raw data size
+     678                 :            :  **/
+     679                 :            : void libspdm_internal_dump_hex(const uint8_t *data, size_t size);
+     680                 :            : #define LIBSPDM_INTERNAL_DUMP_HEX(data, size) libspdm_internal_dump_hex(data, size)
+     681                 :            : #endif /* LIBSPDM_INTERNAL_DUMP_HEX_OVERRIDE */
+     682                 :            : 
+     683                 :            : #else /* LIBSPDM_DEBUG_PRINT_ENABLE */
+     684                 :            : #define LIBSPDM_INTERNAL_DUMP_HEX(data, size)
+     685                 :            : #define LIBSPDM_INTERNAL_DUMP_HEX_STR(data, size)
+     686                 :            : #define LIBSPDM_INTERNAL_DUMP_DATA(data, size)
+     687                 :            : #endif /* LIBSPDM_DEBUG_PRINT_ENABLE */
+     688                 :            : 
+     689                 :            : /* Required scratch buffer size for libspdm internal usage.
+     690                 :            :  * It may be used to hold the encrypted/decrypted message and/or last sent/received message.
+     691                 :            :  * It may be used to hold the large request/response and intermediate send/receive buffer
+     692                 :            :  * in case of chunking.
+     693                 :            :  *
+     694                 :            :  * If chunking is not supported, it should be at least below.
+     695                 :            :  * +--------------------------+-----------------+-----------------+
+     696                 :            :  * |    SENDER_RECEIVER       |MAX_SPDM_MSG_SIZE|MAX_SPDM_MSG_SIZE|
+     697                 :            :  * +--------------------------+-----------------+-----------------+
+     698                 :            :  * |<-Snd/Rcv buf for chunk ->|<-last request ->|<-cache request->|
+     699                 :            :  *
+     700                 :            :  *
+     701                 :            :  * If chunking is supported, it should be at least below.
+     702                 :            :  * +---------------+--------------+--------------------------+------------------------------+-----------------+-----------------+
+     703                 :            :  * |SECURE_MESSAGE |LARGE_MESSAGE |    SENDER_RECEIVER       | LARGE SENDER_RECEIVER        |MAX_SPDM_MSG_SIZE|MAX_SPDM_MSG_SIZE|
+     704                 :            :  * +---------------+--------------+--------------------------+------------------------------+-----------------+-----------------+
+     705                 :            :  * |<-Secure msg ->|<-Large msg ->|<-Snd/Rcv buf for chunk ->|<-Snd/Rcv buf for large msg ->|<-last request ->|<-cache request->|
+     706                 :            :  *
+     707                 :            :  *
+     708                 :            :  * The value is configurable based on max_spdm_msg_size.
+     709                 :            :  * The value MAY be changed in different libspdm version.
+     710                 :            :  * It is exposed here, just in case the libspdm consumer wants to configure the setting at build time.
+     711                 :            :  */
+     712                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
+     713                 :            : /* first section */
+     714                 :            : uint32_t libspdm_get_scratch_buffer_secure_message_offset(libspdm_context_t *spdm_context);
+     715                 :            : uint32_t libspdm_get_scratch_buffer_secure_message_capacity(libspdm_context_t *spdm_context);
+     716                 :            : 
+     717                 :            : /* second section */
+     718                 :            : uint32_t libspdm_get_scratch_buffer_large_message_offset(libspdm_context_t *spdm_context);
+     719                 :            : uint32_t libspdm_get_scratch_buffer_large_message_capacity(libspdm_context_t *spdm_context);
+     720                 :            : #endif
+     721                 :            : 
+     722                 :            : /* third section */
+     723                 :            : uint32_t libspdm_get_scratch_buffer_sender_receiver_offset(libspdm_context_t *spdm_context);
+     724                 :            : uint32_t libspdm_get_scratch_buffer_sender_receiver_capacity(libspdm_context_t *spdm_context);
+     725                 :            : 
+     726                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
+     727                 :            : /* fourth section */
+     728                 :            : uint32_t libspdm_get_scratch_buffer_large_sender_receiver_offset(libspdm_context_t *spdm_context);
+     729                 :            : uint32_t libspdm_get_scratch_buffer_large_sender_receiver_capacity(libspdm_context_t *spdm_context);
+     730                 :            : #endif
+     731                 :            : 
+     732                 :            : /* fifth section */
+     733                 :            : uint32_t libspdm_get_scratch_buffer_last_spdm_request_offset(libspdm_context_t *spdm_context);
+     734                 :            : uint32_t libspdm_get_scratch_buffer_last_spdm_request_capacity(libspdm_context_t *spdm_context);
+     735                 :            : 
+     736                 :            : #if LIBSPDM_RESPOND_IF_READY_SUPPORT
+     737                 :            : /* sixth section */
+     738                 :            : uint32_t libspdm_get_scratch_buffer_cache_spdm_request_offset(libspdm_context_t *spdm_context);
+     739                 :            : uint32_t libspdm_get_scratch_buffer_cache_spdm_request_capacity(libspdm_context_t *spdm_context);
+     740                 :            : #endif
+     741                 :            : 
+     742                 :            : /* combination */
+     743                 :            : uint32_t libspdm_get_scratch_buffer_capacity(libspdm_context_t *spdm_context);
+     744                 :            : 
+     745                 :            : /**
+     746                 :            :  * Append a new data buffer to the managed buffer.
+     747                 :            :  *
+     748                 :            :  * @param  managed_buffer                The managed buffer to be appended.
+     749                 :            :  * @param  buffer                       The address of the data buffer to be appended to the managed buffer.
+     750                 :            :  * @param  buffer_size                   The size in bytes of the data buffer to be appended to the managed buffer.
+     751                 :            :  *
+     752                 :            :  * @retval RETURN_SUCCESS               The new data buffer is appended to the managed buffer.
+     753                 :            :  * @retval RETURN_BUFFER_TOO_SMALL      The managed buffer is too small to be appended.
+     754                 :            :  **/
+     755                 :            : libspdm_return_t libspdm_append_managed_buffer(void *managed_buffer,
+     756                 :            :                                                const void *buffer, size_t buffer_size);
+     757                 :            : 
+     758                 :            : /**
+     759                 :            :  * Reset the managed buffer.
+     760                 :            :  * The buffer_size is reset to 0.
+     761                 :            :  * The max_buffer_size is unchanged.
+     762                 :            :  * The buffer is not freed.
+     763                 :            :  *
+     764                 :            :  * @param  managed_buffer                The managed buffer.
+     765                 :            :  **/
+     766                 :            : void libspdm_reset_managed_buffer(void *managed_buffer);
+     767                 :            : 
+     768                 :            : /**
+     769                 :            :  * Return the size of managed buffer.
+     770                 :            :  *
+     771                 :            :  * @param  managed_buffer                The managed buffer.
+     772                 :            :  *
+     773                 :            :  * @return the size of managed buffer.
+     774                 :            :  **/
+     775                 :            : size_t libspdm_get_managed_buffer_size(void *managed_buffer);
+     776                 :            : 
+     777                 :            : /**
+     778                 :            :  * Return the address of managed buffer.
+     779                 :            :  *
+     780                 :            :  * @param  managed_buffer                The managed buffer.
+     781                 :            :  *
+     782                 :            :  * @return the address of managed buffer.
+     783                 :            :  **/
+     784                 :            : void *libspdm_get_managed_buffer(void *managed_buffer);
+     785                 :            : 
+     786                 :            : /**
+     787                 :            :  * Init the managed buffer.
+     788                 :            :  *
+     789                 :            :  * @param  managed_buffer                The managed buffer.
+     790                 :            :  * @param  max_buffer_size                The maximum size in bytes of the managed buffer.
+     791                 :            :  **/
+     792                 :            : void libspdm_init_managed_buffer(void *managed_buffer, size_t max_buffer_size);
+     793                 :            : 
+     794                 :            : /**
+     795                 :            :  * Reset message buffer in SPDM context according to request code.
+     796                 :            :  *
+     797                 :            :  * @param  spdm_context                   A pointer to the SPDM context.
+     798                 :            :  * @param  spdm_session_info             A pointer to the SPDM session context.
+     799                 :            :  * @param  spdm_request                   The SPDM request code.
+     800                 :            :  */
+     801                 :            : void libspdm_reset_message_buffer_via_request_code(void *context, void *session_info,
+     802                 :            :                                                    uint8_t request_code);
+     803                 :            : 
+     804                 :            : /**
+     805                 :            :  * This function initializes the session info.
+     806                 :            :  *
+     807                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     808                 :            :  * @param  session_id                    The SPDM session ID.
+     809                 :            :  **/
+     810                 :            : void libspdm_session_info_init(libspdm_context_t *spdm_context,
+     811                 :            :                                libspdm_session_info_t *session_info,
+     812                 :            :                                uint32_t session_id, bool use_psk);
+     813                 :            : 
+     814                 :            : #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
+     815                 :            : /**
+     816                 :            :  * Set the psk_hint to a session info.
+     817                 :            :  *
+     818                 :            :  * @param  session_info   A pointer to a session info.
+     819                 :            :  * @param  psk_hint       Indicate the PSK hint.
+     820                 :            :  * @param  psk_hint_size  The size in bytes of the PSK hint.
+     821                 :            :  */
+     822                 :            : void libspdm_session_info_set_psk_hint(libspdm_session_info_t *session_info,
+     823                 :            :                                        const void *psk_hint,
+     824                 :            :                                        size_t psk_hint_size);
+     825                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP */
+     826                 :            : 
+     827                 :            : /**
+     828                 :            :  * This function returns if a given version is supported based upon the GET_VERSION/VERSION.
+     829                 :            :  *
+     830                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     831                 :            :  * @param  version                      The SPDM version.
+     832                 :            :  *
+     833                 :            :  * @retval true  the version is supported.
+     834                 :            :  * @retval false the version is not supported.
+     835                 :            :  **/
+     836                 :            : bool libspdm_is_version_supported(const libspdm_context_t *spdm_context, uint8_t version);
+     837                 :            : 
+     838                 :            : /**
+     839                 :            :  * This function returns connection version negotiated by GET_VERSION/VERSION.
+     840                 :            :  *
+     841                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     842                 :            :  *
+     843                 :            :  * @return the connection version.
+     844                 :            :  **/
+     845                 :            : uint8_t libspdm_get_connection_version(const libspdm_context_t *spdm_context);
+     846                 :            : 
+     847                 :            : /**
+     848                 :            :  * This function returns if a capabilities flag is supported in current SPDM connection.
+     849                 :            :  *
+     850                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     851                 :            :  * @param  is_requester                  Is the function called from a requester.
+     852                 :            :  * @param  requester_capabilities_flag    The requester capabilities flag to be checked
+     853                 :            :  * @param  responder_capabilities_flag    The responder capabilities flag to be checked
+     854                 :            :  *
+     855                 :            :  * @retval true  the capabilities flag is supported.
+     856                 :            :  * @retval false the capabilities flag is not supported.
+     857                 :            :  **/
+     858                 :            : bool libspdm_is_capabilities_flag_supported(const libspdm_context_t *spdm_context,
+     859                 :            :                                             bool is_requester,
+     860                 :            :                                             uint32_t requester_capabilities_flag,
+     861                 :            :                                             uint32_t responder_capabilities_flag);
+     862                 :            : 
+     863                 :            : /**
+     864                 :            :  * Checks the negotiated SPDM version and endpoint capabilities to determine if encapsulated
+     865                 :            :  * messages are supported or not.
+     866                 :            :  *
+     867                 :            :  * @param  spdm_context  A pointer to the SPDM context.
+     868                 :            :  *
+     869                 :            :  * @retval true   Both endpoints support encapsulated messages.
+     870                 :            :  * @retval false  At least one endpoint does not support encapsulated messages.
+     871                 :            :  **/
+     872                 :            : bool libspdm_is_encap_supported(const libspdm_context_t *spdm_context);
+     873                 :            : 
+     874                 :            : /**
+     875                 :            :  * This function generates the certificate chain hash.
+     876                 :            :  *
+     877                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     878                 :            :  * @param  slot_id                    The slot index of the certificate chain.
+     879                 :            :  * @param  signature                    The buffer to store the certificate chain hash.
+     880                 :            :  *
+     881                 :            :  * @retval true  certificate chain hash is generated.
+     882                 :            :  * @retval false certificate chain hash is not generated.
+     883                 :            :  **/
+     884                 :            : bool libspdm_generate_cert_chain_hash(libspdm_context_t *spdm_context,
+     885                 :            :                                       size_t slot_id, uint8_t *hash);
+     886                 :            : 
+     887                 :            : /**
+     888                 :            :  * This function generates the public key hash.
+     889                 :            :  *
+     890                 :            :  * @param  spdm_context               A pointer to the SPDM context.
+     891                 :            :  * @param  hash                       The buffer to store the public key hash.
+     892                 :            :  *
+     893                 :            :  * @retval true  public key hash is generated.
+     894                 :            :  * @retval false public key hash is not generated.
+     895                 :            :  **/
+     896                 :            : bool libspdm_generate_public_key_hash(libspdm_context_t *spdm_context,
+     897                 :            :                                       uint8_t *hash);
+     898                 :            : 
+     899                 :            : /**
+     900                 :            :  * This function verifies the integrity of peer certificate chain buffer including
+     901                 :            :  * spdm_cert_chain_t header.
+     902                 :            :  *
+     903                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     904                 :            :  * @param  cert_chain_buffer              Certificate chain buffer including spdm_cert_chain_t header.
+     905                 :            :  * @param  cert_chain_buffer_size          size in bytes of the certificate chain buffer.
+     906                 :            :  *
+     907                 :            :  * @retval true  Peer certificate chain buffer integrity verification passed.
+     908                 :            :  * @retval false Peer certificate chain buffer integrity verification failed.
+     909                 :            :  **/
+     910                 :            : bool libspdm_verify_peer_cert_chain_buffer_integrity(libspdm_context_t *spdm_context,
+     911                 :            :                                                      const void *cert_chain_buffer,
+     912                 :            :                                                      size_t cert_chain_buffer_size);
+     913                 :            : 
+     914                 :            : /**
+     915                 :            :  * This function verifies peer certificate chain authority.
+     916                 :            :  *
+     917                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     918                 :            :  * @param  cert_chain_buffer              Certificate chain buffer including spdm_cert_chain_t header.
+     919                 :            :  * @param  cert_chain_buffer_size          size in bytes of the certificate chain buffer.
+     920                 :            :  * @param  trust_anchor                  A buffer to hold the trust_anchor which is used to validate the peer certificate, if not NULL.
+     921                 :            :  * @param  trust_anchor_size             A buffer to hold the trust_anchor_size, if not NULL.
+     922                 :            :  *
+     923                 :            :  * @retval true  Peer certificate chain buffer authority verification passed.
+     924                 :            :  *               Or there is no root_cert in local_context.
+     925                 :            :  * @retval false Peer certificate chain buffer authority verification failed.
+     926                 :            :  **/
+     927                 :            : bool libspdm_verify_peer_cert_chain_buffer_authority(libspdm_context_t *spdm_context,
+     928                 :            :                                                      const void *cert_chain_buffer,
+     929                 :            :                                                      size_t cert_chain_buffer_size,
+     930                 :            :                                                      const void **trust_anchor,
+     931                 :            :                                                      size_t *trust_anchor_size);
+     932                 :            : /**
+     933                 :            :  * This function generates the challenge signature based upon m1m2 for authentication.
+     934                 :            :  *
+     935                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     936                 :            :  * @param  is_requester                  Indicate of the signature generation for a requester or a responder.
+     937                 :            :  * @param  signature                    The buffer to store the challenge signature.
+     938                 :            :  *
+     939                 :            :  * @retval true  challenge signature is generated.
+     940                 :            :  * @retval false challenge signature is not generated.
+     941                 :            :  **/
+     942                 :            : bool libspdm_generate_challenge_auth_signature(libspdm_context_t *spdm_context,
+     943                 :            :                                                bool is_requester,
+     944                 :            :                                                uint8_t *signature);
+     945                 :            : 
+     946                 :            : /**
+     947                 :            :  * This function verifies the certificate chain hash.
+     948                 :            :  *
+     949                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     950                 :            :  * @param  certificate_chain_hash         The certificate chain hash data buffer.
+     951                 :            :  * @param  certificate_chain_hash_size     size in bytes of the certificate chain hash data buffer.
+     952                 :            :  *
+     953                 :            :  * @retval true  hash verification pass.
+     954                 :            :  * @retval false hash verification fail.
+     955                 :            :  **/
+     956                 :            : bool libspdm_verify_certificate_chain_hash(libspdm_context_t *spdm_context,
+     957                 :            :                                            const void *certificate_chain_hash,
+     958                 :            :                                            size_t certificate_chain_hash_size);
+     959                 :            : 
+     960                 :            : /**
+     961                 :            :  * This function verifies the public key hash.
+     962                 :            :  *
+     963                 :            :  * @param  spdm_context            A pointer to the SPDM context.
+     964                 :            :  * @param  public_key_hash         The public key hash data buffer.
+     965                 :            :  * @param  public_key_hash_size    size in bytes of the public key hash data buffer.
+     966                 :            :  *
+     967                 :            :  * @retval true  hash verification pass.
+     968                 :            :  * @retval false hash verification fail.
+     969                 :            :  **/
+     970                 :            : bool libspdm_verify_public_key_hash(libspdm_context_t *spdm_context,
+     971                 :            :                                     const void *public_key_hash,
+     972                 :            :                                     size_t public_key_hash_size);
+     973                 :            : 
+     974                 :            : /**
+     975                 :            :  * This function verifies the challenge signature based upon m1m2.
+     976                 :            :  *
+     977                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     978                 :            :  * @param  is_requester                  Indicate of the signature verification for a requester or a responder.
+     979                 :            :  * @param  sign_data                     The signature data buffer.
+     980                 :            :  * @param  sign_data_size                 size in bytes of the signature data buffer.
+     981                 :            :  *
+     982                 :            :  * @retval true  signature verification pass.
+     983                 :            :  * @retval false signature verification fail.
+     984                 :            :  **/
+     985                 :            : bool libspdm_verify_challenge_auth_signature(libspdm_context_t *spdm_context,
+     986                 :            :                                              bool is_requester,
+     987                 :            :                                              const void *sign_data,
+     988                 :            :                                              size_t sign_data_size);
+     989                 :            : 
+     990                 :            : /**
+     991                 :            :  * This function calculate the measurement summary hash size.
+     992                 :            :  *
+     993                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     994                 :            :  * @param  is_requester                  Is the function called from a requester.
+     995                 :            :  * @param  measurement_summary_hash_type   The type of the measurement summary hash.
+     996                 :            :  *
+     997                 :            :  * @return 0 measurement summary hash type is invalid, NO_MEAS hash type or no MEAS capabilities.
+     998                 :            :  * @return measurement summary hash size according to type.
+     999                 :            :  **/
+    1000                 :            : uint32_t libspdm_get_measurement_summary_hash_size(libspdm_context_t *spdm_context,
+    1001                 :            :                                                    bool is_requester,
+    1002                 :            :                                                    uint8_t measurement_summary_hash_type);
+    1003                 :            : 
+    1004                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1005                 :            : /*
+    1006                 :            :  * This function calculates l1l2.
+    1007                 :            :  * If session_info is NULL, this function will use M cache of SPDM context,
+    1008                 :            :  * else will use M cache of SPDM session context.
+    1009                 :            :  *
+    1010                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+    1011                 :            :  * @param  session_info                  A pointer to the SPDM session context.
+    1012                 :            :  * @param  l1l2                          The buffer to store the l1l2.
+    1013                 :            :  *
+    1014                 :            :  * @retval RETURN_SUCCESS  l1l2 is calculated.
+    1015                 :            :  */
+    1016                 :            : bool libspdm_calculate_l1l2(libspdm_context_t *spdm_context,
+    1017                 :            :                             void *session_info,
+    1018                 :            :                             libspdm_l1l2_managed_buffer_t *l1l2);
+    1019                 :            : #else
+    1020                 :            : /*
+    1021                 :            :  * This function calculates l1l2 hash.
+    1022                 :            :  * If session_info is NULL, this function will use M cache of SPDM context,
+    1023                 :            :  * else will use M cache of SPDM session context.
+    1024                 :            :  *
+    1025                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+    1026                 :            :  * @param  session_info                  A pointer to the SPDM session context.
+    1027                 :            :  * @param  l1l2_hash_size               size in bytes of the l1l2 hash
+    1028                 :            :  * @param  l1l2_hash                   The buffer to store the l1l2 hash
+    1029                 :            :  *
+    1030                 :            :  * @retval RETURN_SUCCESS  l1l2 is calculated.
+    1031                 :            :  */
+    1032                 :            : bool libspdm_calculate_l1l2_hash(libspdm_context_t *spdm_context,
+    1033                 :            :                                  void *session_info,
+    1034                 :            :                                  size_t *l1l2_hash_size, void *l1l2_hash);
+    1035                 :            : #endif /* LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT */
+    1036                 :            : 
+    1037                 :            : /**
+    1038                 :            :  * Get element from multi element opaque data by element id.
+    1039                 :            :  *
+    1040                 :            :  * This function should be called in
+    1041                 :            :  * libspdm_process_opaque_data_supported_version_data/libspdm_process_opaque_data_version_selection_data.
+    1042                 :            :  *
+    1043                 :            :  * @param[in]  data_in_size     Size of multi element opaque data.
+    1044                 :            :  * @param[in]  data_in          A pointer to the multi element opaque data.
+    1045                 :            :  * @param[in]  element_id       Element id.
+    1046                 :            :  * @param[in]  sm_data_id       ID for the Secured Message data type.
+    1047                 :            :  * @param[out] get_element_ptr  Pointer to store found element.
+    1048                 :            :  *
+    1049                 :            :  * @retval true   Get element successfully
+    1050                 :            :  * @retval false  Get element failed
+    1051                 :            :  **/
+    1052                 :            : bool libspdm_get_element_from_opaque_data(libspdm_context_t *spdm_context,
+    1053                 :            :                                           size_t data_in_size, const void *data_in,
+    1054                 :            :                                           uint8_t element_id, uint8_t sm_data_id,
+    1055                 :            :                                           const void **get_element_ptr, size_t *get_element_len);
+    1056                 :            : 
+    1057                 :            : /**
+    1058                 :            :  *  Process general opaque data check
+    1059                 :            :  *
+    1060                 :            :  * @param  data_in_size                  size in bytes of the data_in.
+    1061                 :            :  * @param  data_in                       A pointer to the buffer to store the opaque data version selection.
+    1062                 :            :  *
+    1063                 :            :  * @retval true                           check opaque data successfully
+    1064                 :            :  * @retval false                          check opaque data failed
+    1065                 :            :  **/
+    1066                 :            : bool libspdm_process_general_opaque_data_check(libspdm_context_t *spdm_context,
+    1067                 :            :                                                size_t data_in_size,
+    1068                 :            :                                                const void *data_in);
+    1069                 :            : 
+    1070                 :            : /**
+    1071                 :            :  * Return the size in bytes of opaque data supported version.
+    1072                 :            :  *
+    1073                 :            :  * This function should be called in libspdm_process_opaque_data_supported_version_data.
+    1074                 :            :  *
+    1075                 :            :  * @param  version_count  Secure version count.
+    1076                 :            :  *
+    1077                 :            :  * @return The size in bytes of opaque data supported version.
+    1078                 :            :  **/
+    1079                 :            : size_t libspdm_get_untrusted_opaque_data_supported_version_data_size(
+    1080                 :            :     libspdm_context_t *spdm_context, uint8_t version_count);
+    1081                 :            : 
+    1082                 :            : /**
+    1083                 :            :  * Return the size in bytes of opaque data supported version.
+    1084                 :            :  *
+    1085                 :            :  * This function should be called in KEY_EXCHANGE/PSK_EXCHANGE request generation.
+    1086                 :            :  *
+    1087                 :            :  * @return the size in bytes of opaque data supported version.
+    1088                 :            :  **/
+    1089                 :            : size_t libspdm_get_opaque_data_supported_version_data_size(libspdm_context_t *spdm_context);
+    1090                 :            : 
+    1091                 :            : /**
+    1092                 :            :  * Return the size in bytes of opaque data version selection.
+    1093                 :            :  *
+    1094                 :            :  * This function should be called in KEY_EXCHANGE/PSK_EXCHANGE response generation.
+    1095                 :            :  *
+    1096                 :            :  * @return the size in bytes of opaque data version selection.
+    1097                 :            :  **/
+    1098                 :            : size_t libspdm_get_opaque_data_version_selection_data_size(const libspdm_context_t *spdm_context);
+    1099                 :            : 
+    1100                 :            : /**
+    1101                 :            :  * Return the SPDMversion field of the version number struct.
+    1102                 :            :  *
+    1103                 :            :  * @param  ver                Spdm version number struct.
+    1104                 :            :  *
+    1105                 :            :  * @return the SPDMversion of the version number struct.
+    1106                 :            :  **/
+    1107                 :            : uint8_t libspdm_get_version_from_version_number(const spdm_version_number_t ver);
+    1108                 :            : 
+    1109                 :            : /**
+    1110                 :            :  * Sort SPDMversion in descending order.
+    1111                 :            :  *
+    1112                 :            :  * @param  spdm_context                A pointer to the SPDM context.
+    1113                 :            :  * @param  ver_set                    A pointer to the version set.
+    1114                 :            :  * @param  ver_num                    Version number.
+    1115                 :            :  */
+    1116                 :            : void libspdm_version_number_sort(spdm_version_number_t *ver_set, size_t ver_num);
+    1117                 :            : 
+    1118                 :            : /**
+    1119                 :            :  * Negotiate SPDMversion for connection.
+    1120                 :            :  * ver_set is the local version set of requester, res_ver_set is the version set of responder.
+    1121                 :            :  *
+    1122                 :            :  * @param  common_version             A pointer to store the common version.
+    1123                 :            :  * @param  req_ver_set                A pointer to the requester version set.
+    1124                 :            :  * @param  req_ver_num                Version number of requester.
+    1125                 :            :  * @param  res_ver_set                A pointer to the responder version set.
+    1126                 :            :  * @param  res_ver_num                Version number of responder.
+    1127                 :            :  *
+    1128                 :            :  * @retval true                       Negotiation successfully, connect version be saved to common_version.
+    1129                 :            :  * @retval false                      Negotiation failed.
+    1130                 :            :  */
+    1131                 :            : bool libspdm_negotiate_connection_version(spdm_version_number_t *common_version,
+    1132                 :            :                                           spdm_version_number_t *req_ver_set,
+    1133                 :            :                                           size_t req_ver_num,
+    1134                 :            :                                           const spdm_version_number_t *res_ver_set,
+    1135                 :            :                                           size_t res_ver_num);
+    1136                 :            : 
+    1137                 :            : /**
+    1138                 :            :  * Acquire a device sender buffer for transport layer message.
+    1139                 :            :  *
+    1140                 :            :  * @param  context                       A pointer to the SPDM context.
+    1141                 :            :  * @param  max_msg_size                  size in bytes of the maximum size of sender buffer.
+    1142                 :            :  * @param  msg_buf_ptr                   A pointer to a sender buffer.
+    1143                 :            :  *
+    1144                 :            :  * @retval RETURN_SUCCESS               The sender buffer is acquired.
+    1145                 :            :  **/
+    1146                 :            : libspdm_return_t libspdm_acquire_sender_buffer (
+    1147                 :            :     libspdm_context_t *spdm_context, size_t *max_msg_size, void **msg_buf_ptr);
+    1148                 :            : 
+    1149                 :            : /**
+    1150                 :            :  * Release a device sender buffer for transport layer message.
+    1151                 :            :  *
+    1152                 :            :  * @param  context                       A pointer to the SPDM context.
+    1153                 :            :  *
+    1154                 :            :  * @retval RETURN_SUCCESS               The sender buffer is Released.
+    1155                 :            :  **/
+    1156                 :            : void libspdm_release_sender_buffer (libspdm_context_t *spdm_context);
+    1157                 :            : 
+    1158                 :            : /**
+    1159                 :            :  * Get the sender buffer.
+    1160                 :            :  *
+    1161                 :            :  * @param  context                  A pointer to the SPDM context.
+    1162                 :            :  * @param  sender_buffer            Buffer address of the sender buffer.
+    1163                 :            :  * @param  sender_buffer_size       Size of the sender buffer.
+    1164                 :            :  *
+    1165                 :            :  **/
+    1166                 :            : void libspdm_get_sender_buffer (
+    1167                 :            :     libspdm_context_t *spdm_context,
+    1168                 :            :     void **sender_buffer,
+    1169                 :            :     size_t *sender_buffer_size);
+    1170                 :            : 
+    1171                 :            : /**
+    1172                 :            :  * Acquire a device receiver buffer for transport layer message.
+    1173                 :            :  *
+    1174                 :            :  * @param  context                       A pointer to the SPDM context.
+    1175                 :            :  * @param  max_msg_size                  size in bytes of the maximum size of receiver buffer.
+    1176                 :            :  * @param  msg_buf_pt                    A pointer to a receiver buffer.
+    1177                 :            :  *
+    1178                 :            :  * @retval RETURN_SUCCESS               The receiver buffer is acquired.
+    1179                 :            :  **/
+    1180                 :            : libspdm_return_t libspdm_acquire_receiver_buffer (
+    1181                 :            :     libspdm_context_t *spdm_context, size_t *max_msg_size, void **msg_buf_ptr);
+    1182                 :            : 
+    1183                 :            : /**
+    1184                 :            :  * Release a device receiver buffer for transport layer message.
+    1185                 :            :  *
+    1186                 :            :  * @param  context                       A pointer to the SPDM context.
+    1187                 :            :  *
+    1188                 :            :  * @retval RETURN_SUCCESS               The receiver buffer is Released.
+    1189                 :            :  **/
+    1190                 :            : void libspdm_release_receiver_buffer (libspdm_context_t *spdm_context);
+    1191                 :            : 
+    1192                 :            : /**
+    1193                 :            :  * Get the receiver buffer.
+    1194                 :            :  *
+    1195                 :            :  * @param  context                  A pointer to the SPDM context.
+    1196                 :            :  * @param  receiver_buffer            Buffer address of the receiver buffer.
+    1197                 :            :  * @param  receiver_buffer_size       Size of the receiver buffer.
+    1198                 :            :  *
+    1199                 :            :  **/
+    1200                 :            : void libspdm_get_receiver_buffer (
+    1201                 :            :     libspdm_context_t *spdm_context,
+    1202                 :            :     void **receiver_buffer,
+    1203                 :            :     size_t *receiver_buffer_size);
+    1204                 :            : 
+    1205                 :            : /**
+    1206                 :            :  * Get the certificate slot mask
+    1207                 :            :  *
+    1208                 :            :  * @param[in]   context              A pointer to the SPDM context.
+    1209                 :            :  *
+    1210                 :            :  * @retval slot_mask                 get slot mask
+    1211                 :            :  **/
+    1212                 :            : uint8_t libspdm_get_cert_slot_mask (libspdm_context_t *spdm_context);
+    1213                 :            : 
+    1214                 :            : /**
+    1215                 :            :  * Get the certificate slot count
+    1216                 :            :  *
+    1217                 :            :  * @param[in]   context              A pointer to the SPDM context.
+    1218                 :            :  *
+    1219                 :            :  * @retval slot_count                get slot count
+    1220                 :            :  **/
+    1221                 :            : uint8_t libspdm_get_cert_slot_count(libspdm_context_t *spdm_context);
+    1222                 :            : 
+    1223                 :            : #if LIBSPDM_ENABLE_MSG_LOG
+    1224                 :            : void libspdm_append_msg_log(libspdm_context_t *spdm_context, void *message, size_t message_size);
+    1225                 :            : #endif
+    1226                 :            : 
+    1227                 :            : /**
+    1228                 :            :  * Reset message A cache in SPDM context.
+    1229                 :            :  *
+    1230                 :            :  * @param  spdm_context  A pointer to the SPDM context.
+    1231                 :            :  **/
+    1232                 :            : void libspdm_reset_message_a(libspdm_context_t *spdm_context);
+    1233                 :            : 
+    1234                 :            : /**
+    1235                 :            :  * Reset message D cache in SPDM context.
+    1236                 :            :  *
+    1237                 :            :  * @param  spdm_context       A pointer to the SPDM context.
+    1238                 :            :  * @param  spdm_session_info  A pointer to the SPDM session context.
+    1239                 :            :  **/
+    1240                 :            : void libspdm_reset_message_d(libspdm_context_t *spdm_context);
+    1241                 :            : 
+    1242                 :            : /**
+    1243                 :            :  * Reset message B cache in SPDM context.
+    1244                 :            :  *
+    1245                 :            :  * @param  spdm_context  A pointer to the SPDM context.
+    1246                 :            :  **/
+    1247                 :            : void libspdm_reset_message_b(libspdm_context_t *spdm_context);
+    1248                 :            : 
+    1249                 :            : /**
+    1250                 :            :  * Reset message C cache in SPDM context.
+    1251                 :            :  *
+    1252                 :            :  * @param  spdm_context  A pointer to the SPDM context.
+    1253                 :            :  **/
+    1254                 :            : void libspdm_reset_message_c(libspdm_context_t *spdm_context);
+    1255                 :            : 
+    1256                 :            : /**
+    1257                 :            :  * Reset message MutB cache in SPDM context.
+    1258                 :            :  *
+    1259                 :            :  * @param  spdm_context  A pointer to the SPDM context.
+    1260                 :            :  **/
+    1261                 :            : void libspdm_reset_message_mut_b(libspdm_context_t *spdm_context);
+    1262                 :            : 
+    1263                 :            : /**
+    1264                 :            :  * Reset message MutC cache in SPDM context.
+    1265                 :            :  *
+    1266                 :            :  * @param  spdm_context  A pointer to the SPDM context.
+    1267                 :            :  **/
+    1268                 :            : void libspdm_reset_message_mut_c(libspdm_context_t *spdm_context);
+    1269                 :            : 
+    1270                 :            : /**
+    1271                 :            :  * Reset message M cache in SPDM context.
+    1272                 :            :  * If session_info is NULL, this function will use M cache of SPDM context,
+    1273                 :            :  * else will use M cache of SPDM session context.
+    1274                 :            :  *
+    1275                 :            :  * @param  spdm_context  A pointer to the SPDM context.
+    1276                 :            :  * @param  session_info  A pointer to the SPDM session context.
+    1277                 :            :  **/
+    1278                 :            : void libspdm_reset_message_m(libspdm_context_t *spdm_context, void *session_info);
+    1279                 :            : 
+    1280                 :            : /**
+    1281                 :            :  * Reset message K cache in SPDM context.
+    1282                 :            :  *
+    1283                 :            :  * @param  spdm_context       A pointer to the SPDM context.
+    1284                 :            :  * @param  spdm_session_info  A pointer to the SPDM session context.
+    1285                 :            :  **/
+    1286                 :            : void libspdm_reset_message_k(libspdm_context_t *spdm_context, void *spdm_session_info);
+    1287                 :            : 
+    1288                 :            : /**
+    1289                 :            :  * Reset message EncapD cache in SPDM context.
+    1290                 :            :  *
+    1291                 :            :  * @param  spdm_context       A pointer to the SPDM context.
+    1292                 :            :  * @param  spdm_session_info  A pointer to the SPDM session context.
+    1293                 :            :  **/
+    1294                 :            : void libspdm_reset_message_encap_d(libspdm_context_t *spdm_context, void *spdm_session_info);
+    1295                 :            : 
+    1296                 :            : /**
+    1297                 :            :  * Reset message F cache in SPDM context.
+    1298                 :            :  *
+    1299                 :            :  * @param  spdm_context       A pointer to the SPDM context.
+    1300                 :            :  * @param  spdm_session_info  A pointer to the SPDM session context.
+    1301                 :            :  **/
+    1302                 :            : void libspdm_reset_message_f(libspdm_context_t *spdm_context, void *spdm_session_info);
+    1303                 :            : 
+    1304                 :            : /**
+    1305                 :            :  * Append message A cache in SPDM context.
+    1306                 :            :  *
+    1307                 :            :  * @param  spdm_context  A pointer to the SPDM context.
+    1308                 :            :  * @param  message       Message buffer.
+    1309                 :            :  * @param  message_size  Size in bytes of message buffer.
+    1310                 :            :  *
+    1311                 :            :  * @return RETURN_SUCCESS          message is appended.
+    1312                 :            :  * @return RETURN_OUT_OF_RESOURCES message is not appended because the internal cache is full.
+    1313                 :            :  **/
+    1314                 :            : libspdm_return_t libspdm_append_message_a(libspdm_context_t *spdm_context, const void *message,
+    1315                 :            :                                           size_t message_size);
+    1316                 :            : 
+    1317                 :            : /**
+    1318                 :            :  * Append message D cache in SPDM context.
+    1319                 :            :  *
+    1320                 :            :  * @param  spdm_context  A pointer to the SPDM context.
+    1321                 :            :  * @param  message       Message buffer.
+    1322                 :            :  * @param  message_size  Size in bytes of message buffer.
+    1323                 :            :  *
+    1324                 :            :  * @return RETURN_SUCCESS          message is appended.
+    1325                 :            :  * @return RETURN_OUT_OF_RESOURCES message is not appended because the internal cache is full.
+    1326                 :            :  **/
+    1327                 :            : libspdm_return_t libspdm_append_message_d(libspdm_context_t *spdm_context, const void *message,
+    1328                 :            :                                           size_t message_size);
+    1329                 :            : 
+    1330                 :            : /**
+    1331                 :            :  * Append message B cache in SPDM context.
+    1332                 :            :  *
+    1333                 :            :  * @param  spdm_context  A pointer to the SPDM context.
+    1334                 :            :  * @param  message       Message buffer.
+    1335                 :            :  * @param  message_size  Size in bytes of message buffer.
+    1336                 :            :  *
+    1337                 :            :  * @return RETURN_SUCCESS          message is appended.
+    1338                 :            :  * @return RETURN_OUT_OF_RESOURCES message is not appended because the internal cache is full.
+    1339                 :            :  **/
+    1340                 :            : libspdm_return_t libspdm_append_message_b(libspdm_context_t *spdm_context, const void *message,
+    1341                 :            :                                           size_t message_size);
+    1342                 :            : 
+    1343                 :            : /**
+    1344                 :            :  * Append message C cache in SPDM context.
+    1345                 :            :  *
+    1346                 :            :  * @param  spdm_context  A pointer to the SPDM context.
+    1347                 :            :  * @param  message       Message buffer.
+    1348                 :            :  * @param  message_size  Size in bytes of message buffer.
+    1349                 :            :  *
+    1350                 :            :  * @return RETURN_SUCCESS          message is appended.
+    1351                 :            :  * @return RETURN_OUT_OF_RESOURCES message is not appended because the internal cache is full.
+    1352                 :            :  **/
+    1353                 :            : libspdm_return_t libspdm_append_message_c(libspdm_context_t *spdm_context, const void *message,
+    1354                 :            :                                           size_t message_size);
+    1355                 :            : 
+    1356                 :            : /**
+    1357                 :            :  * Append message MutB cache in SPDM context.
+    1358                 :            :  *
+    1359                 :            :  * @param  spdm_context  A pointer to the SPDM context.
+    1360                 :            :  * @param  message       Message buffer.
+    1361                 :            :  * @param  message_size  Size in bytes of message buffer.
+    1362                 :            :  *
+    1363                 :            :  * @return RETURN_SUCCESS          message is appended.
+    1364                 :            :  * @return RETURN_OUT_OF_RESOURCES message is not appended because the internal cache is full.
+    1365                 :            :  **/
+    1366                 :            : libspdm_return_t libspdm_append_message_mut_b(libspdm_context_t *spdm_context, const void *message,
+    1367                 :            :                                               size_t message_size);
+    1368                 :            : 
+    1369                 :            : /**
+    1370                 :            :  * Append message MutC cache in SPDM context.
+    1371                 :            :  *
+    1372                 :            :  * @param  spdm_context  A pointer to the SPDM context.
+    1373                 :            :  * @param  message       Message buffer.
+    1374                 :            :  * @param  message_size  Size in bytes of message buffer.
+    1375                 :            :  *
+    1376                 :            :  * @return RETURN_SUCCESS          message is appended.
+    1377                 :            :  * @return RETURN_OUT_OF_RESOURCES message is not appended because the internal cache is full.
+    1378                 :            :  **/
+    1379                 :            : libspdm_return_t libspdm_append_message_mut_c(libspdm_context_t *spdm_context, const void *message,
+    1380                 :            :                                               size_t message_size);
+    1381                 :            : 
+    1382                 :            : /**
+    1383                 :            :  * Append message M cache in SPDM context.
+    1384                 :            :  * If session_info is NULL, this function will use M cache of SPDM context,
+    1385                 :            :  * else will use M cache of SPDM session context.
+    1386                 :            :  *
+    1387                 :            :  * @param  spdm_context  A pointer to the SPDM context.
+    1388                 :            :  * @param  session_info  A pointer to the SPDM session context.
+    1389                 :            :  * @param  message       Message buffer.
+    1390                 :            :  * @param  message_size  Size in bytes of message buffer.
+    1391                 :            :  *
+    1392                 :            :  * @return RETURN_SUCCESS          message is appended.
+    1393                 :            :  * @return RETURN_OUT_OF_RESOURCES message is not appended because the internal cache is full.
+    1394                 :            :  **/
+    1395                 :            : libspdm_return_t libspdm_append_message_m(libspdm_context_t *spdm_context,
+    1396                 :            :                                           void *session_info,
+    1397                 :            :                                           const void *message, size_t message_size);
+    1398                 :            : 
+    1399                 :            : /**
+    1400                 :            :  * Append message K cache in SPDM context.
+    1401                 :            :  *
+    1402                 :            :  * @param  spdm_context       A pointer to the SPDM context.
+    1403                 :            :  * @param  spdm_session_info  A pointer to the SPDM session context.
+    1404                 :            :  * @param  is_requester       Indicate of the key generation for a requester or a responder.
+    1405                 :            :  * @param  message            Message buffer.
+    1406                 :            :  * @param  message_size       Size in bytes of message buffer.
+    1407                 :            :  *
+    1408                 :            :  * @return RETURN_SUCCESS          message is appended.
+    1409                 :            :  * @return RETURN_OUT_OF_RESOURCES message is not appended because the internal cache is full.
+    1410                 :            :  **/
+    1411                 :            : libspdm_return_t libspdm_append_message_k(libspdm_context_t *spdm_context,
+    1412                 :            :                                           void *spdm_session_info,
+    1413                 :            :                                           bool is_requester, const void *message,
+    1414                 :            :                                           size_t message_size);
+    1415                 :            : 
+    1416                 :            : /**
+    1417                 :            :  * Append message EncapD cache in SPDM context.
+    1418                 :            :  *
+    1419                 :            :  * @param  spdm_context       A pointer to the SPDM context.
+    1420                 :            :  * @param  spdm_session_info  A pointer to the SPDM session context.
+    1421                 :            :  * @param  is_requester       Indicate of the key generation for a requester or a responder.
+    1422                 :            :  * @param  message            Message buffer.
+    1423                 :            :  * @param  message_size       Size in bytes of message buffer.
+    1424                 :            :  *
+    1425                 :            :  * @return RETURN_SUCCESS          message is appended.
+    1426                 :            :  * @return RETURN_OUT_OF_RESOURCES message is not appended because the internal cache is full.
+    1427                 :            :  **/
+    1428                 :            : libspdm_return_t libspdm_append_message_encap_d(libspdm_context_t *spdm_context,
+    1429                 :            :                                                 void *spdm_session_info,
+    1430                 :            :                                                 bool is_requester, const void *message,
+    1431                 :            :                                                 size_t message_size);
+    1432                 :            : 
+    1433                 :            : /**
+    1434                 :            :  * Append message F cache in SPDM context.
+    1435                 :            :  *
+    1436                 :            :  * @param  spdm_context       A pointer to the SPDM context.
+    1437                 :            :  * @param  spdm_session_info  A pointer to the SPDM session context.
+    1438                 :            :  * @param  is_requester       Indicate of the key generation for a requester or a responder.
+    1439                 :            :  * @param  message            Message buffer.
+    1440                 :            :  * @param  message_size       Size in bytes of message buffer.
+    1441                 :            :  *
+    1442                 :            :  * @return RETURN_SUCCESS          message is appended.
+    1443                 :            :  * @return RETURN_OUT_OF_RESOURCES message is not appended because the internal cache is full.
+    1444                 :            :  **/
+    1445                 :            : libspdm_return_t libspdm_append_message_f(libspdm_context_t *spdm_context,
+    1446                 :            :                                           void *spdm_session_info,
+    1447                 :            :                                           bool is_requester, const void *message,
+    1448                 :            :                                           size_t message_size);
+    1449                 :            : 
+    1450                 :            : /**
+    1451                 :            :  * This function generates a session ID by concatenating req_session_id and rsp_session_id.
+    1452                 :            :  *
+    1453                 :            :  * @param[in]  req_session_id
+    1454                 :            :  * @param[in]  rsp_session_id
+    1455                 :            :  *
+    1456                 :            :  * @return Session ID.
+    1457                 :            :  **/
+    1458                 :            : uint32_t libspdm_generate_session_id(uint16_t req_session_id, uint16_t rsp_session_id);
+    1459                 :            : 
+    1460                 :            : /**
+    1461                 :            :  * This function assigns a new session ID.
+    1462                 :            :  *
+    1463                 :            :  * @param  spdm_context  A pointer to the SPDM context.
+    1464                 :            :  * @param  session_id    The SPDM session ID.
+    1465                 :            :  *
+    1466                 :            :  * @return session info associated with this new session ID.
+    1467                 :            :  **/
+    1468                 :            : void *libspdm_assign_session_id(libspdm_context_t *spdm_context, uint32_t session_id, bool use_psk);
+    1469                 :            : 
+    1470                 :            : /**
+    1471                 :            :  * This function frees a session ID.
+    1472                 :            :  *
+    1473                 :            :  * @param  spdm_context  A pointer to the SPDM context.
+    1474                 :            :  * @param  session_id    The SPDM session ID.
+    1475                 :            :  **/
+    1476                 :            : void libspdm_free_session_id(libspdm_context_t *spdm_context, uint32_t session_id);
+    1477                 :            : 
+    1478                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1479                 :            : /*
+    1480                 :            :  * This function calculates current TH data with message A and message K.
+    1481                 :            :  *
+    1482                 :            :  * @param  spdm_context            A pointer to the SPDM context.
+    1483                 :            :  * @param  session_info            The SPDM session ID.
+    1484                 :            :  * @param  cert_chain_buffer       Certificate chain buffer with spdm_cert_chain_t header.
+    1485                 :            :  * @param  cert_chain_buffer_size  Size in bytes of the certificate chain buffer.
+    1486                 :            :  * @param  th_data_buffer_size     Size in bytes of the th_data_buffer
+    1487                 :            :  * @param  th_data_buffer          The buffer to store the th_data_buffer
+    1488                 :            :  *
+    1489                 :            :  * @retval RETURN_SUCCESS  current TH data is calculated.
+    1490                 :            :  */
+    1491                 :            : bool libspdm_calculate_th_for_exchange(
+    1492                 :            :     libspdm_context_t *spdm_context, void *spdm_session_info,
+    1493                 :            :     const uint8_t *cert_chain_buffer, size_t cert_chain_buffer_size,
+    1494                 :            :     libspdm_th_managed_buffer_t *th_curr);
+    1495                 :            : #else
+    1496                 :            : /*
+    1497                 :            :  * This function calculates current TH hash with message A and message K.
+    1498                 :            :  *
+    1499                 :            :  * @param  spdm_context         A pointer to the SPDM context.
+    1500                 :            :  * @param  session_info         The SPDM session ID.
+    1501                 :            :  * @param  th_hash_buffer_size  Size in bytes of the th_hash_buffer
+    1502                 :            :  * @param  th_hash_buffer       The buffer to store the th_hash_buffer
+    1503                 :            :  *
+    1504                 :            :  * @retval RETURN_SUCCESS  current TH hash is calculated.
+    1505                 :            :  */
+    1506                 :            : bool libspdm_calculate_th_hash_for_exchange(
+    1507                 :            :     libspdm_context_t *spdm_context, void *spdm_session_info,
+    1508                 :            :     size_t *th_hash_buffer_size, void *th_hash_buffer);
+    1509                 :            : 
+    1510                 :            : /*
+    1511                 :            :  * This function calculates current TH hmac with message A and message K, with response finished_key.
+    1512                 :            :  *
+    1513                 :            :  * @param  spdm_context         A pointer to the SPDM context.
+    1514                 :            :  * @param  session_info         The SPDM session ID.
+    1515                 :            :  * @param  th_hmac_buffer_size  Size in bytes of the th_hmac_buffer
+    1516                 :            :  * @param  th_hmac_buffer       The buffer to store the th_hmac_buffer
+    1517                 :            :  *
+    1518                 :            :  * @retval RETURN_SUCCESS  current TH hmac is calculated.
+    1519                 :            :  */
+    1520                 :            : bool libspdm_calculate_th_hmac_for_exchange_rsp(
+    1521                 :            :     libspdm_context_t *spdm_context, void *spdm_session_info, bool is_requester,
+    1522                 :            :     size_t *th_hmac_buffer_size, void *th_hmac_buffer);
+    1523                 :            : #endif
+    1524                 :            : 
+    1525                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1526                 :            : /*
+    1527                 :            :  * This function calculates current TH data with message A, message K and message F.
+    1528                 :            :  *
+    1529                 :            :  * @param  spdm_context                A pointer to the SPDM context.
+    1530                 :            :  * @param  session_info                The SPDM session ID.
+    1531                 :            :  * @param  cert_chain_buffer           Certificate chain buffer with spdm_cert_chain_t header.
+    1532                 :            :  * @param  cert_chain_buffer_size      Size in bytes of the certificate chain buffer.
+    1533                 :            :  * @param  mut_cert_chain_buffer       Certificate chain buffer with spdm_cert_chain_t header in mutual authentication.
+    1534                 :            :  * @param  mut_cert_chain_buffer_size  Size in bytes of the certificate chain buffer in mutual authentication.
+    1535                 :            :  * @param  th_data_buffer_size         Size in bytes of the th_data_buffer.
+    1536                 :            :  * @param  th_data_buffer              The buffer to store the th_data_buffer
+    1537                 :            :  *
+    1538                 :            :  * @retval RETURN_SUCCESS  current TH data is calculated.
+    1539                 :            :  */
+    1540                 :            : bool libspdm_calculate_th_for_finish(libspdm_context_t *spdm_context,
+    1541                 :            :                                      void *spdm_session_info,
+    1542                 :            :                                      const uint8_t *cert_chain_buffer,
+    1543                 :            :                                      size_t cert_chain_buffer_size,
+    1544                 :            :                                      const uint8_t *mut_cert_chain_buffer,
+    1545                 :            :                                      size_t mut_cert_chain_buffer_size,
+    1546                 :            :                                      libspdm_th_managed_buffer_t *th_curr);
+    1547                 :            : #else
+    1548                 :            : /*
+    1549                 :            :  * This function calculates current TH hash with message A, message K and message F.
+    1550                 :            :  *
+    1551                 :            :  * @param  spdm_context         A pointer to the SPDM context.
+    1552                 :            :  * @param  session_info         The SPDM session ID.
+    1553                 :            :  * @param  th_hash_buffer_size  Size in bytes of the th_hash_buffer
+    1554                 :            :  * @param  th_hash_buffer       The buffer to store the th_hash_buffer
+    1555                 :            :  *
+    1556                 :            :  * @retval RETURN_SUCCESS  current TH hash is calculated.
+    1557                 :            :  */
+    1558                 :            : bool libspdm_calculate_th_hash_for_finish(libspdm_context_t *spdm_context,
+    1559                 :            :                                           void *spdm_session_info,
+    1560                 :            :                                           size_t *th_hash_buffer_size,
+    1561                 :            :                                           void *th_hash_buffer);
+    1562                 :            : 
+    1563                 :            : /*
+    1564                 :            :  * This function calculates current TH hmac with message A, message K and message F, with response finished_key.
+    1565                 :            :  *
+    1566                 :            :  * @param  spdm_context         A pointer to the SPDM context.
+    1567                 :            :  * @param  session_info         The SPDM session ID.
+    1568                 :            :  * @param  th_hmac_buffer_size  Size in bytes of the th_hmac_buffer
+    1569                 :            :  * @param  th_hmac_buffer       The buffer to store the th_hmac_buffer
+    1570                 :            :  *
+    1571                 :            :  * @retval RETURN_SUCCESS  current TH hmac is calculated.
+    1572                 :            :  */
+    1573                 :            : bool libspdm_calculate_th_hmac_for_finish_rsp(libspdm_context_t *spdm_context,
+    1574                 :            :                                               void *spdm_session_info,
+    1575                 :            :                                               size_t *th_hmac_buffer_size,
+    1576                 :            :                                               void *th_hmac_buffer);
+    1577                 :            : 
+    1578                 :            : /*
+    1579                 :            :  * This function calculates current TH hmac with message A, message K and message F, with request finished_key.
+    1580                 :            :  *
+    1581                 :            :  * @param  spdm_context         A pointer to the SPDM context.
+    1582                 :            :  * @param  session_info         The SPDM session ID.
+    1583                 :            :  * @param  th_hmac_buffer_size  Size in bytes of the th_hmac_buffer
+    1584                 :            :  * @param  th_hmac_buffer       The buffer to store the th_hmac_buffer
+    1585                 :            :  *
+    1586                 :            :  * @retval RETURN_SUCCESS  current TH hmac is calculated.
+    1587                 :            :  */
+    1588                 :            : bool libspdm_calculate_th_hmac_for_finish_req(libspdm_context_t *spdm_context,
+    1589                 :            :                                               void *spdm_session_info,
+    1590                 :            :                                               size_t *th_hmac_buffer_size,
+    1591                 :            :                                               void *th_hmac_buffer);
+    1592                 :            : #endif
+    1593                 :            : 
+    1594                 :            : /*
+    1595                 :            :  * This function calculates th1 hash.
+    1596                 :            :  *
+    1597                 :            :  * @param  spdm_context   A pointer to the SPDM context.
+    1598                 :            :  * @param  session_info   The SPDM session ID.
+    1599                 :            :  * @param  is_requester   Indicate of the key generation for a requester or a responder.
+    1600                 :            :  * @param  th1_hash_data  Th1 hash.
+    1601                 :            :  *
+    1602                 :            :  * @retval RETURN_SUCCESS  th1 hash is calculated.
+    1603                 :            :  */
+    1604                 :            : bool libspdm_calculate_th1_hash(libspdm_context_t *spdm_context,
+    1605                 :            :                                 void *spdm_session_info,
+    1606                 :            :                                 bool is_requester,
+    1607                 :            :                                 uint8_t *th1_hash_data);
+    1608                 :            : 
+    1609                 :            : /*
+    1610                 :            :  * This function calculates th2 hash.
+    1611                 :            :  *
+    1612                 :            :  * @param  spdm_context   A pointer to the SPDM context.
+    1613                 :            :  * @param  session_info   The SPDM session ID.
+    1614                 :            :  * @param  is_requester   Indicate of the key generation for a requester or a responder.
+    1615                 :            :  * @param  th1_hash_data  Th2 hash
+    1616                 :            :  *
+    1617                 :            :  * @retval RETURN_SUCCESS  th2 hash is calculated.
+    1618                 :            :  */
+    1619                 :            : bool libspdm_calculate_th2_hash(libspdm_context_t *spdm_context,
+    1620                 :            :                                 void *spdm_session_info,
+    1621                 :            :                                 bool is_requester,
+    1622                 :            :                                 uint8_t *th2_hash_data);
+    1623                 :            : 
+    1624                 :            : /**
+    1625                 :            :  * Reads a 24-bit value from memory that may be unaligned.
+    1626                 :            :  *
+    1627                 :            :  * @param  buffer  The pointer to a 24-bit value that may be unaligned.
+    1628                 :            :  *
+    1629                 :            :  * @return The 24-bit value read from buffer.
+    1630                 :            :  **/
+    1631                 :            : uint32_t libspdm_read_uint24(const uint8_t *buffer);
+    1632                 :            : 
+    1633                 :            : /**
+    1634                 :            :  * Writes a 24-bit value to memory that may be unaligned.
+    1635                 :            :  *
+    1636                 :            :  * @param  buffer  The pointer to a 24-bit value that may be unaligned.
+    1637                 :            :  * @param  value   24-bit value to write to buffer.
+    1638                 :            :  **/
+    1639                 :            : void libspdm_write_uint24(uint8_t *buffer, uint32_t value);
+    1640                 :            : 
+    1641                 :            : /**
+    1642                 :            :  * Reads a 16-bit value from memory that may be unaligned.
+    1643                 :            :  *
+    1644                 :            :  * @param  buffer  The pointer to a 16-bit value that may be unaligned.
+    1645                 :            :  *
+    1646                 :            :  * @return The 16-bit value read from buffer.
+    1647                 :            :  **/
+    1648                 :            : uint16_t libspdm_read_uint16(const uint8_t *buffer);
+    1649                 :            : 
+    1650                 :            : /**
+    1651                 :            :  * Writes a 16-bit value to memory that may be unaligned.
+    1652                 :            :  *
+    1653                 :            :  * @param  buffer  The pointer to a 16-bit value that may be unaligned.
+    1654                 :            :  * @param  value   16-bit value to write to buffer.
+    1655                 :            :  **/
+    1656                 :            : void libspdm_write_uint16(uint8_t *buffer, uint16_t value);
+    1657                 :            : 
+    1658                 :            : /**
+    1659                 :            :  * Reads a 32-bit value from memory that may be unaligned.
+    1660                 :            :  *
+    1661                 :            :  * @param  buffer  The pointer to a 32-bit value that may be unaligned.
+    1662                 :            :  *
+    1663                 :            :  * @return The 32-bit value read from buffer.
+    1664                 :            :  **/
+    1665                 :            : uint32_t libspdm_read_uint32(const uint8_t *buffer);
+    1666                 :            : 
+    1667                 :            : /**
+    1668                 :            :  * Writes a 32-bit value to memory that may be unaligned.
+    1669                 :            :  *
+    1670                 :            :  * @param  buffer  The pointer to a 32-bit value that may be unaligned.
+    1671                 :            :  * @param  value   32-bit value to write to buffer.
+    1672                 :            :  **/
+    1673                 :            : void libspdm_write_uint32(uint8_t *buffer, uint32_t value);
+    1674                 :            : 
+    1675                 :            : /**
+    1676                 :            :  * Reads a 64-bit value from memory that may be unaligned.
+    1677                 :            :  *
+    1678                 :            :  * @param  buffer  The pointer to a 64-bit value that may be unaligned.
+    1679                 :            :  *
+    1680                 :            :  * @return The 64-bit value read from buffer.
+    1681                 :            :  **/
+    1682                 :            : uint64_t libspdm_read_uint64(const uint8_t *buffer);
+    1683                 :            : 
+    1684                 :            : /**
+    1685                 :            :  * Writes a 64-bit value to memory that may be unaligned.
+    1686                 :            :  *
+    1687                 :            :  * @param  buffer  The pointer to a 64-bit value that may be unaligned.
+    1688                 :            :  * @param  value   64-bit value to write to buffer.
+    1689                 :            :  **/
+    1690                 :            : void libspdm_write_uint64(uint8_t *buffer, uint64_t value);
+    1691                 :            : 
+    1692                 :            : /**
+    1693                 :            :  * Determine if bitmask has at most one bit set.
+    1694                 :            :  *
+    1695                 :            :  * @param mask  The bitmask to be tested.
+    1696                 :            :  *
+    1697                 :            :  * @return true   At most one bit is set.
+    1698                 :            :  * @return false  More than one bit is set.
+    1699                 :            :  */
+    1700                 :        361 : static inline bool libspdm_onehot0(uint32_t mask)
+    1701                 :            : {
+    1702   [ +  +  +  + ]:        361 :     return !mask || !(mask & (mask - 1));
+    1703                 :            : }
+    1704                 :            : 
+    1705                 :          1 : static inline uint64_t libspdm_le_to_be_64(uint64_t value)
+    1706                 :            : {
+    1707                 :          1 :     return (((value & 0x00000000000000ff) << 56) |
+    1708                 :          1 :             ((value & 0x000000000000ff00) << 40) |
+    1709                 :          1 :             ((value & 0x0000000000ff0000) << 24) |
+    1710                 :          1 :             ((value & 0x00000000ff000000) << 8) |
+    1711                 :          1 :             ((value & 0x000000ff00000000) >> 8) |
+    1712                 :          1 :             ((value & 0x0000ff0000000000) >> 24) |
+    1713                 :          2 :             ((value & 0x00ff000000000000) >> 40) |
+    1714                 :          1 :             ((value & 0xff00000000000000) >> 56));
+    1715                 :            : }
+    1716                 :            : 
+    1717                 :            : /**
+    1718                 :            :  * Return capability flags that are masked by the negotiated SPDM version.
+    1719                 :            :  *
+    1720                 :            :  * @param  spdm_context      A pointer to the SPDM context.
+    1721                 :            :  * @param  is_request_flags  If true then flags are from a request message or Requester.
+    1722                 :            :  *                           If false then flags are from a response message or Responder.
+    1723                 :            :  * @param  flags             A bitmask of capability flags.
+    1724                 :            :  *
+    1725                 :            :  * @return The masked capability flags.
+    1726                 :            :  */
+    1727                 :            : uint32_t libspdm_mask_capability_flags(libspdm_context_t *spdm_context,
+    1728                 :            :                                        bool is_request_flags, uint32_t flags);
+    1729                 :            : 
+    1730                 :            : #endif /* SPDM_COMMON_LIB_INTERNAL_H */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/index-sort-b.html b/coverage_log/index-sort-b.html new file mode 100644 index 00000000000..bb45051e129 --- /dev/null +++ b/coverage_log/index-sort-b.html @@ -0,0 +1,539 @@ + + + + + + + LCOV - coverage.info + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top levelHitTotalCoverage
Test:coverage.infoLines:627748504473.8 %
Date:2024-09-22 08:21:07Functions:2341313274.7 %
Branches:101262347143.1 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Directory Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
unit_test/test_spdm_responder/error_test +
94.4%94.4%
+
94.4 %153 / 16290.0 %9 / 100.0 %0 / 4
unit_test/test_spdm_secured_message +
0.9%0.9%
+
0.9 %3 / 3345.6 %1 / 180.0 %0 / 72
os_stub/cryptlib_mbedtls/hmac +
9.8%9.8%
+
9.8 %12 / 12313.8 %4 / 294.3 %2 / 46
unit_test/cmockalib/cmocka/src +
21.1%21.1%
+
21.1 %308 / 146132.8 %44 / 13414.2 %85 / 598
os_stub/cryptlib_mbedtls/hash +
28.8%28.8%
+
28.8 %45 / 15638.1 %8 / 2120.4 %22 / 108
os_stub/spdm_crypt_ext_lib +
32.9%32.9%
+
32.9 %28 / 85100.0 %7 / 721.9 %7 / 32
os_stub/platform_lib +
50.0%50.0%
+
50.0 %6 / 1225.0 %1 / 425.0 %1 / 4
os_stub/mbedtlslib/mbedtls/library +
33.8%33.8%
+
33.8 %4599 / 1359046.2 %444 / 96225.1 %2400 / 9547
os_stub/mbedtlslib/mbedtls/include/mbedtls +
50.0%50.0%
+
50.0 %21 / 4263.6 %7 / 1131.2 %5 / 16
os_stub/cryptlib_mbedtls/kdf +
40.7%40.7%
+
40.7 %33 / 8133.3 %4 / 1231.2 %20 / 64
os_stub/cryptlib_mbedtls/pk +
50.8%50.8%
+
50.8 %754 / 148466.2 %45 / 6836.8 %311 / 846
os_stub/debuglib +
57.1%57.1%
+
57.1 %8 / 1450.0 %1 / 237.5 %3 / 8
os_stub/spdm_device_secret_lib_sample +
49.4%49.4%
+
49.4 %952 / 192989.8 %44 / 4942.5 %316 / 743
library/spdm_common_lib +
56.0%56.0%
+
56.0 %1242 / 221985.9 %116 / 13543.7 %507 / 1159
os_stub/cryptlib_mbedtls/pem +
60.9%60.9%
+
60.9 %53 / 8740.0 %2 / 544.0 %22 / 50
library/spdm_crypt_lib +
48.4%48.4%
+
48.4 %892 / 184481.9 %77 / 9445.0 %418 / 929
os_stub/malloclib +
90.9%90.9%
+
90.9 %10 / 11100.0 %3 / 350.0 %1 / 2
unit_test/test_spdm_fips +
94.7%94.7%
+
94.7 %18 / 19100.0 %5 / 550.0 %1 / 2
os_stub/rnglib +
58.3%58.3%
+
58.3 %7 / 12100.0 %1 / 150.0 %3 / 6
os_stub/cryptlib_mbedtls/der +
57.4%57.4%
+
57.4 %27 / 47100.0 %2 / 250.0 %14 / 28
library/spdm_secured_message_lib +
67.1%67.1%
+
67.1 %603 / 89967.3 %33 / 4950.7 %143 / 282
library/spdm_crypt_lib/fips +
59.8%59.8%
+
59.8 %335 / 560100.0 %19 / 1951.4 %113 / 220
os_stub/cryptlib_mbedtls/cipher +
74.2%74.2%
+
74.2 %49 / 66100.0 %2 / 251.7 %31 / 60
unit_test/spdm_transport_test_lib +
75.4%75.4%
+
75.4 %107 / 142100.0 %7 / 758.0 %40 / 69
library/spdm_responder_lib +
76.6%76.6%
+
76.6 %2856 / 373089.6 %69 / 7763.1 %1424 / 2255
unit_test/test_spdm_responder +
99.5%99.5%
+
99.5 %14647 / 14727100.0 %457 / 45763.6 %182 / 286
unit_test/test_spdm_requester +
87.7%87.7%
+
87.7 %22445 / 2558598.9 %541 / 54766.5 %1510 / 2271
os_stub/cryptlib_mbedtls/sys_call +
70.8%70.8%
+
70.8 %17 / 2460.0 %3 / 566.7 %4 / 6
unit_test/test_spdm_requester/error_test +
79.1%79.1%
+
79.1 %7297 / 922897.4 %229 / 23566.7 %412 / 618
library/spdm_requester_lib +
78.8%78.8%
+
78.8 %3977 / 505096.6 %86 / 8966.8 %1948 / 2915
unit_test/test_spdm_crypt +
98.4%98.4%
+
98.4 %436 / 443100.0 %16 / 1670.0 %7 / 10
unit_test/spdm_unit_test_common +
89.8%89.8%
+
89.8 %159 / 177100.0 %16 / 1670.2 %59 / 84
os_stub/cryptlib_mbedtls/rand +
94.4%94.4%
+
94.4 %17 / 18100.0 %2 / 275.0 %6 / 8
os_stub/memlib +
90.0%90.0%
+
90.0 %27 / 30100.0 %4 / 477.3 %17 / 22
unit_test/test_spdm_common +
97.5%97.5%
+
97.5 %620 / 636100.0 %30 / 3090.7 %88 / 97
os_stub/platform_lib_null +
0.0%
+
0.0 %0 / 60.0 %0 / 3-0 / 0
include/internal +
100.0%
+
100.0 %11 / 11100.0 %2 / 2100.0 %4 / 4
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/index-sort-f.html b/coverage_log/index-sort-f.html new file mode 100644 index 00000000000..e921daf22b5 --- /dev/null +++ b/coverage_log/index-sort-f.html @@ -0,0 +1,539 @@ + + + + + + + LCOV - coverage.info + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top levelHitTotalCoverage
Test:coverage.infoLines:627748504473.8 %
Date:2024-09-22 08:21:07Functions:2341313274.7 %
Branches:101262347143.1 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Directory Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
os_stub/platform_lib_null +
0.0%
+
0.0 %0 / 60.0 %0 / 3-0 / 0
unit_test/test_spdm_secured_message +
0.9%0.9%
+
0.9 %3 / 3345.6 %1 / 180.0 %0 / 72
os_stub/cryptlib_mbedtls/hmac +
9.8%9.8%
+
9.8 %12 / 12313.8 %4 / 294.3 %2 / 46
os_stub/platform_lib +
50.0%50.0%
+
50.0 %6 / 1225.0 %1 / 425.0 %1 / 4
unit_test/cmockalib/cmocka/src +
21.1%21.1%
+
21.1 %308 / 146132.8 %44 / 13414.2 %85 / 598
os_stub/cryptlib_mbedtls/kdf +
40.7%40.7%
+
40.7 %33 / 8133.3 %4 / 1231.2 %20 / 64
os_stub/cryptlib_mbedtls/hash +
28.8%28.8%
+
28.8 %45 / 15638.1 %8 / 2120.4 %22 / 108
os_stub/cryptlib_mbedtls/pem +
60.9%60.9%
+
60.9 %53 / 8740.0 %2 / 544.0 %22 / 50
os_stub/mbedtlslib/mbedtls/library +
33.8%33.8%
+
33.8 %4599 / 1359046.2 %444 / 96225.1 %2400 / 9547
os_stub/debuglib +
57.1%57.1%
+
57.1 %8 / 1450.0 %1 / 237.5 %3 / 8
os_stub/cryptlib_mbedtls/sys_call +
70.8%70.8%
+
70.8 %17 / 2460.0 %3 / 566.7 %4 / 6
os_stub/mbedtlslib/mbedtls/include/mbedtls +
50.0%50.0%
+
50.0 %21 / 4263.6 %7 / 1131.2 %5 / 16
os_stub/cryptlib_mbedtls/pk +
50.8%50.8%
+
50.8 %754 / 148466.2 %45 / 6836.8 %311 / 846
library/spdm_secured_message_lib +
67.1%67.1%
+
67.1 %603 / 89967.3 %33 / 4950.7 %143 / 282
library/spdm_crypt_lib +
48.4%48.4%
+
48.4 %892 / 184481.9 %77 / 9445.0 %418 / 929
library/spdm_common_lib +
56.0%56.0%
+
56.0 %1242 / 221985.9 %116 / 13543.7 %507 / 1159
library/spdm_responder_lib +
76.6%76.6%
+
76.6 %2856 / 373089.6 %69 / 7763.1 %1424 / 2255
os_stub/spdm_device_secret_lib_sample +
49.4%49.4%
+
49.4 %952 / 192989.8 %44 / 4942.5 %316 / 743
unit_test/test_spdm_responder/error_test +
94.4%94.4%
+
94.4 %153 / 16290.0 %9 / 100.0 %0 / 4
library/spdm_requester_lib +
78.8%78.8%
+
78.8 %3977 / 505096.6 %86 / 8966.8 %1948 / 2915
unit_test/test_spdm_requester/error_test +
79.1%79.1%
+
79.1 %7297 / 922897.4 %229 / 23566.7 %412 / 618
unit_test/test_spdm_requester +
87.7%87.7%
+
87.7 %22445 / 2558598.9 %541 / 54766.5 %1510 / 2271
os_stub/rnglib +
58.3%58.3%
+
58.3 %7 / 12100.0 %1 / 150.0 %3 / 6
include/internal +
100.0%
+
100.0 %11 / 11100.0 %2 / 2100.0 %4 / 4
os_stub/cryptlib_mbedtls/der +
57.4%57.4%
+
57.4 %27 / 47100.0 %2 / 250.0 %14 / 28
os_stub/cryptlib_mbedtls/rand +
94.4%94.4%
+
94.4 %17 / 18100.0 %2 / 275.0 %6 / 8
os_stub/cryptlib_mbedtls/cipher +
74.2%74.2%
+
74.2 %49 / 66100.0 %2 / 251.7 %31 / 60
os_stub/malloclib +
90.9%90.9%
+
90.9 %10 / 11100.0 %3 / 350.0 %1 / 2
os_stub/memlib +
90.0%90.0%
+
90.0 %27 / 30100.0 %4 / 477.3 %17 / 22
unit_test/test_spdm_fips +
94.7%94.7%
+
94.7 %18 / 19100.0 %5 / 550.0 %1 / 2
unit_test/spdm_transport_test_lib +
75.4%75.4%
+
75.4 %107 / 142100.0 %7 / 758.0 %40 / 69
os_stub/spdm_crypt_ext_lib +
32.9%32.9%
+
32.9 %28 / 85100.0 %7 / 721.9 %7 / 32
unit_test/test_spdm_crypt +
98.4%98.4%
+
98.4 %436 / 443100.0 %16 / 1670.0 %7 / 10
unit_test/spdm_unit_test_common +
89.8%89.8%
+
89.8 %159 / 177100.0 %16 / 1670.2 %59 / 84
library/spdm_crypt_lib/fips +
59.8%59.8%
+
59.8 %335 / 560100.0 %19 / 1951.4 %113 / 220
unit_test/test_spdm_common +
97.5%97.5%
+
97.5 %620 / 636100.0 %30 / 3090.7 %88 / 97
unit_test/test_spdm_responder +
99.5%99.5%
+
99.5 %14647 / 14727100.0 %457 / 45763.6 %182 / 286
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/index-sort-l.html b/coverage_log/index-sort-l.html new file mode 100644 index 00000000000..0177a250577 --- /dev/null +++ b/coverage_log/index-sort-l.html @@ -0,0 +1,539 @@ + + + + + + + LCOV - coverage.info + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top levelHitTotalCoverage
Test:coverage.infoLines:627748504473.8 %
Date:2024-09-22 08:21:07Functions:2341313274.7 %
Branches:101262347143.1 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Directory Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
os_stub/platform_lib_null +
0.0%
+
0.0 %0 / 60.0 %0 / 3-0 / 0
unit_test/test_spdm_secured_message +
0.9%0.9%
+
0.9 %3 / 3345.6 %1 / 180.0 %0 / 72
os_stub/cryptlib_mbedtls/hmac +
9.8%9.8%
+
9.8 %12 / 12313.8 %4 / 294.3 %2 / 46
unit_test/cmockalib/cmocka/src +
21.1%21.1%
+
21.1 %308 / 146132.8 %44 / 13414.2 %85 / 598
os_stub/cryptlib_mbedtls/hash +
28.8%28.8%
+
28.8 %45 / 15638.1 %8 / 2120.4 %22 / 108
os_stub/spdm_crypt_ext_lib +
32.9%32.9%
+
32.9 %28 / 85100.0 %7 / 721.9 %7 / 32
os_stub/mbedtlslib/mbedtls/library +
33.8%33.8%
+
33.8 %4599 / 1359046.2 %444 / 96225.1 %2400 / 9547
os_stub/cryptlib_mbedtls/kdf +
40.7%40.7%
+
40.7 %33 / 8133.3 %4 / 1231.2 %20 / 64
library/spdm_crypt_lib +
48.4%48.4%
+
48.4 %892 / 184481.9 %77 / 9445.0 %418 / 929
os_stub/spdm_device_secret_lib_sample +
49.4%49.4%
+
49.4 %952 / 192989.8 %44 / 4942.5 %316 / 743
os_stub/platform_lib +
50.0%50.0%
+
50.0 %6 / 1225.0 %1 / 425.0 %1 / 4
os_stub/mbedtlslib/mbedtls/include/mbedtls +
50.0%50.0%
+
50.0 %21 / 4263.6 %7 / 1131.2 %5 / 16
os_stub/cryptlib_mbedtls/pk +
50.8%50.8%
+
50.8 %754 / 148466.2 %45 / 6836.8 %311 / 846
library/spdm_common_lib +
56.0%56.0%
+
56.0 %1242 / 221985.9 %116 / 13543.7 %507 / 1159
os_stub/debuglib +
57.1%57.1%
+
57.1 %8 / 1450.0 %1 / 237.5 %3 / 8
os_stub/cryptlib_mbedtls/der +
57.4%57.4%
+
57.4 %27 / 47100.0 %2 / 250.0 %14 / 28
os_stub/rnglib +
58.3%58.3%
+
58.3 %7 / 12100.0 %1 / 150.0 %3 / 6
library/spdm_crypt_lib/fips +
59.8%59.8%
+
59.8 %335 / 560100.0 %19 / 1951.4 %113 / 220
os_stub/cryptlib_mbedtls/pem +
60.9%60.9%
+
60.9 %53 / 8740.0 %2 / 544.0 %22 / 50
library/spdm_secured_message_lib +
67.1%67.1%
+
67.1 %603 / 89967.3 %33 / 4950.7 %143 / 282
os_stub/cryptlib_mbedtls/sys_call +
70.8%70.8%
+
70.8 %17 / 2460.0 %3 / 566.7 %4 / 6
os_stub/cryptlib_mbedtls/cipher +
74.2%74.2%
+
74.2 %49 / 66100.0 %2 / 251.7 %31 / 60
unit_test/spdm_transport_test_lib +
75.4%75.4%
+
75.4 %107 / 142100.0 %7 / 758.0 %40 / 69
library/spdm_responder_lib +
76.6%76.6%
+
76.6 %2856 / 373089.6 %69 / 7763.1 %1424 / 2255
library/spdm_requester_lib +
78.8%78.8%
+
78.8 %3977 / 505096.6 %86 / 8966.8 %1948 / 2915
unit_test/test_spdm_requester/error_test +
79.1%79.1%
+
79.1 %7297 / 922897.4 %229 / 23566.7 %412 / 618
unit_test/test_spdm_requester +
87.7%87.7%
+
87.7 %22445 / 2558598.9 %541 / 54766.5 %1510 / 2271
unit_test/spdm_unit_test_common +
89.8%89.8%
+
89.8 %159 / 177100.0 %16 / 1670.2 %59 / 84
os_stub/memlib +
90.0%90.0%
+
90.0 %27 / 30100.0 %4 / 477.3 %17 / 22
os_stub/malloclib +
90.9%90.9%
+
90.9 %10 / 11100.0 %3 / 350.0 %1 / 2
os_stub/cryptlib_mbedtls/rand +
94.4%94.4%
+
94.4 %17 / 18100.0 %2 / 275.0 %6 / 8
unit_test/test_spdm_responder/error_test +
94.4%94.4%
+
94.4 %153 / 16290.0 %9 / 100.0 %0 / 4
unit_test/test_spdm_fips +
94.7%94.7%
+
94.7 %18 / 19100.0 %5 / 550.0 %1 / 2
unit_test/test_spdm_common +
97.5%97.5%
+
97.5 %620 / 636100.0 %30 / 3090.7 %88 / 97
unit_test/test_spdm_crypt +
98.4%98.4%
+
98.4 %436 / 443100.0 %16 / 1670.0 %7 / 10
unit_test/test_spdm_responder +
99.5%99.5%
+
99.5 %14647 / 14727100.0 %457 / 45763.6 %182 / 286
include/internal +
100.0%
+
100.0 %11 / 11100.0 %2 / 2100.0 %4 / 4
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/index.html b/coverage_log/index.html new file mode 100644 index 00000000000..9acfdfb2ab6 --- /dev/null +++ b/coverage_log/index.html @@ -0,0 +1,539 @@ + + + + + + + LCOV - coverage.info + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top levelHitTotalCoverage
Test:coverage.infoLines:627748504473.8 %
Date:2024-09-22 08:21:07Functions:2341313274.7 %
Branches:101262347143.1 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Directory Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
include/internal +
100.0%
+
100.0 %11 / 11100.0 %2 / 2100.0 %4 / 4
library/spdm_common_lib +
56.0%56.0%
+
56.0 %1242 / 221985.9 %116 / 13543.7 %507 / 1159
library/spdm_crypt_lib +
48.4%48.4%
+
48.4 %892 / 184481.9 %77 / 9445.0 %418 / 929
library/spdm_crypt_lib/fips +
59.8%59.8%
+
59.8 %335 / 560100.0 %19 / 1951.4 %113 / 220
library/spdm_requester_lib +
78.8%78.8%
+
78.8 %3977 / 505096.6 %86 / 8966.8 %1948 / 2915
library/spdm_responder_lib +
76.6%76.6%
+
76.6 %2856 / 373089.6 %69 / 7763.1 %1424 / 2255
library/spdm_secured_message_lib +
67.1%67.1%
+
67.1 %603 / 89967.3 %33 / 4950.7 %143 / 282
os_stub/cryptlib_mbedtls/cipher +
74.2%74.2%
+
74.2 %49 / 66100.0 %2 / 251.7 %31 / 60
os_stub/cryptlib_mbedtls/der +
57.4%57.4%
+
57.4 %27 / 47100.0 %2 / 250.0 %14 / 28
os_stub/cryptlib_mbedtls/hash +
28.8%28.8%
+
28.8 %45 / 15638.1 %8 / 2120.4 %22 / 108
os_stub/cryptlib_mbedtls/hmac +
9.8%9.8%
+
9.8 %12 / 12313.8 %4 / 294.3 %2 / 46
os_stub/cryptlib_mbedtls/kdf +
40.7%40.7%
+
40.7 %33 / 8133.3 %4 / 1231.2 %20 / 64
os_stub/cryptlib_mbedtls/pem +
60.9%60.9%
+
60.9 %53 / 8740.0 %2 / 544.0 %22 / 50
os_stub/cryptlib_mbedtls/pk +
50.8%50.8%
+
50.8 %754 / 148466.2 %45 / 6836.8 %311 / 846
os_stub/cryptlib_mbedtls/rand +
94.4%94.4%
+
94.4 %17 / 18100.0 %2 / 275.0 %6 / 8
os_stub/cryptlib_mbedtls/sys_call +
70.8%70.8%
+
70.8 %17 / 2460.0 %3 / 566.7 %4 / 6
os_stub/debuglib +
57.1%57.1%
+
57.1 %8 / 1450.0 %1 / 237.5 %3 / 8
os_stub/malloclib +
90.9%90.9%
+
90.9 %10 / 11100.0 %3 / 350.0 %1 / 2
os_stub/mbedtlslib/mbedtls/include/mbedtls +
50.0%50.0%
+
50.0 %21 / 4263.6 %7 / 1131.2 %5 / 16
os_stub/mbedtlslib/mbedtls/library +
33.8%33.8%
+
33.8 %4599 / 1359046.2 %444 / 96225.1 %2400 / 9547
os_stub/memlib +
90.0%90.0%
+
90.0 %27 / 30100.0 %4 / 477.3 %17 / 22
os_stub/platform_lib +
50.0%50.0%
+
50.0 %6 / 1225.0 %1 / 425.0 %1 / 4
os_stub/platform_lib_null +
0.0%
+
0.0 %0 / 60.0 %0 / 3-0 / 0
os_stub/rnglib +
58.3%58.3%
+
58.3 %7 / 12100.0 %1 / 150.0 %3 / 6
os_stub/spdm_crypt_ext_lib +
32.9%32.9%
+
32.9 %28 / 85100.0 %7 / 721.9 %7 / 32
os_stub/spdm_device_secret_lib_sample +
49.4%49.4%
+
49.4 %952 / 192989.8 %44 / 4942.5 %316 / 743
unit_test/cmockalib/cmocka/src +
21.1%21.1%
+
21.1 %308 / 146132.8 %44 / 13414.2 %85 / 598
unit_test/spdm_transport_test_lib +
75.4%75.4%
+
75.4 %107 / 142100.0 %7 / 758.0 %40 / 69
unit_test/spdm_unit_test_common +
89.8%89.8%
+
89.8 %159 / 177100.0 %16 / 1670.2 %59 / 84
unit_test/test_spdm_common +
97.5%97.5%
+
97.5 %620 / 636100.0 %30 / 3090.7 %88 / 97
unit_test/test_spdm_crypt +
98.4%98.4%
+
98.4 %436 / 443100.0 %16 / 1670.0 %7 / 10
unit_test/test_spdm_fips +
94.7%94.7%
+
94.7 %18 / 19100.0 %5 / 550.0 %1 / 2
unit_test/test_spdm_requester +
87.7%87.7%
+
87.7 %22445 / 2558598.9 %541 / 54766.5 %1510 / 2271
unit_test/test_spdm_requester/error_test +
79.1%79.1%
+
79.1 %7297 / 922897.4 %229 / 23566.7 %412 / 618
unit_test/test_spdm_responder +
99.5%99.5%
+
99.5 %14647 / 14727100.0 %457 / 45763.6 %182 / 286
unit_test/test_spdm_responder/error_test +
94.4%94.4%
+
94.4 %153 / 16290.0 %9 / 100.0 %0 / 4
unit_test/test_spdm_secured_message +
0.9%0.9%
+
0.9 %3 / 3345.6 %1 / 180.0 %0 / 72
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_common_lib/index-sort-b.html b/coverage_log/library/spdm_common_lib/index-sort-b.html new file mode 100644 index 00000000000..f130bbedc26 --- /dev/null +++ b/coverage_log/library/spdm_common_lib/index-sort-b.html @@ -0,0 +1,179 @@ + + + + + + + LCOV - coverage.info - library/spdm_common_lib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_common_libHitTotalCoverage
Test:coverage.infoLines:1242221956.0 %
Date:2024-09-22 08:21:07Functions:11613585.9 %
Branches:507115943.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
libspdm_com_context_data.c +
43.5%43.5%
+
43.5 %636 / 146185.7 %60 / 7033.1 %265 / 801
libspdm_com_msg_log.c +
79.2%79.2%
+
79.2 %38 / 4883.3 %5 / 650.0 %12 / 24
libspdm_com_crypto_service_session.c +
80.2%80.2%
+
80.2 %101 / 126100.0 %7 / 750.0 %27 / 54
libspdm_com_opaque_data.c +
85.2%85.2%
+
85.2 %98 / 115100.0 %5 / 567.6 %50 / 74
libspdm_com_context_data_session.c +
73.5%73.5%
+
73.5 %86 / 11787.5 %7 / 871.4 %40 / 56
libspdm_com_crypto_service.c +
81.8%81.8%
+
81.8 %189 / 23184.2 %16 / 1972.6 %82 / 113
libspdm_com_support.c +
77.7%77.7%
+
77.7 %94 / 12180.0 %16 / 2083.8 %31 / 37
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_common_lib/index-sort-f.html b/coverage_log/library/spdm_common_lib/index-sort-f.html new file mode 100644 index 00000000000..f467ae98a55 --- /dev/null +++ b/coverage_log/library/spdm_common_lib/index-sort-f.html @@ -0,0 +1,179 @@ + + + + + + + LCOV - coverage.info - library/spdm_common_lib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_common_libHitTotalCoverage
Test:coverage.infoLines:1242221956.0 %
Date:2024-09-22 08:21:07Functions:11613585.9 %
Branches:507115943.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
libspdm_com_support.c +
77.7%77.7%
+
77.7 %94 / 12180.0 %16 / 2083.8 %31 / 37
libspdm_com_msg_log.c +
79.2%79.2%
+
79.2 %38 / 4883.3 %5 / 650.0 %12 / 24
libspdm_com_crypto_service.c +
81.8%81.8%
+
81.8 %189 / 23184.2 %16 / 1972.6 %82 / 113
libspdm_com_context_data.c +
43.5%43.5%
+
43.5 %636 / 146185.7 %60 / 7033.1 %265 / 801
libspdm_com_context_data_session.c +
73.5%73.5%
+
73.5 %86 / 11787.5 %7 / 871.4 %40 / 56
libspdm_com_opaque_data.c +
85.2%85.2%
+
85.2 %98 / 115100.0 %5 / 567.6 %50 / 74
libspdm_com_crypto_service_session.c +
80.2%80.2%
+
80.2 %101 / 126100.0 %7 / 750.0 %27 / 54
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_common_lib/index-sort-l.html b/coverage_log/library/spdm_common_lib/index-sort-l.html new file mode 100644 index 00000000000..50a8dc5b109 --- /dev/null +++ b/coverage_log/library/spdm_common_lib/index-sort-l.html @@ -0,0 +1,179 @@ + + + + + + + LCOV - coverage.info - library/spdm_common_lib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_common_libHitTotalCoverage
Test:coverage.infoLines:1242221956.0 %
Date:2024-09-22 08:21:07Functions:11613585.9 %
Branches:507115943.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
libspdm_com_context_data.c +
43.5%43.5%
+
43.5 %636 / 146185.7 %60 / 7033.1 %265 / 801
libspdm_com_context_data_session.c +
73.5%73.5%
+
73.5 %86 / 11787.5 %7 / 871.4 %40 / 56
libspdm_com_support.c +
77.7%77.7%
+
77.7 %94 / 12180.0 %16 / 2083.8 %31 / 37
libspdm_com_msg_log.c +
79.2%79.2%
+
79.2 %38 / 4883.3 %5 / 650.0 %12 / 24
libspdm_com_crypto_service_session.c +
80.2%80.2%
+
80.2 %101 / 126100.0 %7 / 750.0 %27 / 54
libspdm_com_crypto_service.c +
81.8%81.8%
+
81.8 %189 / 23184.2 %16 / 1972.6 %82 / 113
libspdm_com_opaque_data.c +
85.2%85.2%
+
85.2 %98 / 115100.0 %5 / 567.6 %50 / 74
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_common_lib/index.html b/coverage_log/library/spdm_common_lib/index.html new file mode 100644 index 00000000000..83b801febc3 --- /dev/null +++ b/coverage_log/library/spdm_common_lib/index.html @@ -0,0 +1,179 @@ + + + + + + + LCOV - coverage.info - library/spdm_common_lib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_common_libHitTotalCoverage
Test:coverage.infoLines:1242221956.0 %
Date:2024-09-22 08:21:07Functions:11613585.9 %
Branches:507115943.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
libspdm_com_context_data.c +
43.5%43.5%
+
43.5 %636 / 146185.7 %60 / 7033.1 %265 / 801
libspdm_com_context_data_session.c +
73.5%73.5%
+
73.5 %86 / 11787.5 %7 / 871.4 %40 / 56
libspdm_com_crypto_service.c +
81.8%81.8%
+
81.8 %189 / 23184.2 %16 / 1972.6 %82 / 113
libspdm_com_crypto_service_session.c +
80.2%80.2%
+
80.2 %101 / 126100.0 %7 / 750.0 %27 / 54
libspdm_com_msg_log.c +
79.2%79.2%
+
79.2 %38 / 4883.3 %5 / 650.0 %12 / 24
libspdm_com_opaque_data.c +
85.2%85.2%
+
85.2 %98 / 115100.0 %5 / 567.6 %50 / 74
libspdm_com_support.c +
77.7%77.7%
+
77.7 %94 / 12180.0 %16 / 2083.8 %31 / 37
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_common_lib/libspdm_com_context_data.c.func-sort-c.html b/coverage_log/library/spdm_common_lib/libspdm_com_context_data.c.func-sort-c.html new file mode 100644 index 00000000000..cc610dab4b3 --- /dev/null +++ b/coverage_log/library/spdm_common_lib/libspdm_com_context_data.c.func-sort-c.html @@ -0,0 +1,361 @@ + + + + + + + LCOV - coverage.info - library/spdm_common_lib/libspdm_com_context_data.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_common_lib - libspdm_com_context_data.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:636146143.5 %
Date:2024-09-22 08:21:07Functions:607085.7 %
Branches:26580133.1 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_deinit_context0
libspdm_export_fips_selftest_context_from_spdm_context0
libspdm_get_fips_selftest_context_size0
libspdm_get_last_spdm_error_struct0
libspdm_get_receiver_buffer0
libspdm_import_fips_selftest_context_to_spdm_context0
libspdm_init_fips_selftest_context0
libspdm_is_version_supported0
libspdm_register_verify_spdm_cert_chain_func0
libspdm_reset_message_k0
libspdm_get_context_size_without_secured_context1
libspdm_check_context3
libspdm_append_message_encap_d4
libspdm_reset_message_encap_d6
libspdm_append_message_d7
libspdm_append_message_mut_c10
libspdm_is_encap_supported16
libspdm_set_data18
libspdm_reset_message_f21
libspdm_negotiate_connection_version27
libspdm_get_data30
libspdm_get_scratch_buffer_large_message_offset34
libspdm_reset_context42
need_session_info_for_data48
libspdm_append_message_c50
libspdm_reset_message_d50
libspdm_version_number_sort54
libspdm_get_scratch_buffer_cache_spdm_request_offset89
libspdm_get_scratch_buffer_last_spdm_request_offset89
libspdm_get_sizeof_required_scratch_buffer89
libspdm_register_device_io_func89
libspdm_set_scratch_buffer89
libspdm_register_device_buffer_func90
libspdm_register_transport_layer_func91
libspdm_get_context_size96
libspdm_init_context96
libspdm_init_context_with_secured_context97
libspdm_append_message_a169
libspdm_get_version_from_version_number225
libspdm_append_message_f241
libspdm_append_message_k288
libspdm_reset_message_mut_c443
libspdm_reset_message_mut_b444
libspdm_reset_message_c575
libspdm_reset_message_a618
libspdm_append_message_m722
libspdm_reset_message_b999
libspdm_release_receiver_buffer2475
libspdm_acquire_receiver_buffer2481
libspdm_release_sender_buffer2516
libspdm_acquire_sender_buffer2522
libspdm_get_scratch_buffer_secure_message_offset2543
libspdm_get_sender_buffer2581
libspdm_set_last_spdm_error_struct2675
libspdm_append_message_mut_b2835
libspdm_reset_message_m4060
libspdm_reset_message_buffer_via_request_code4196
libspdm_get_scratch_buffer_sender_receiver_offset5259
libspdm_get_scratch_buffer5444
libspdm_get_scratch_buffer_capacity5622
libspdm_append_message_b5932
libspdm_is_capabilities_flag_supported8163
libspdm_get_connection_version10182
libspdm_get_scratch_buffer_cache_spdm_request_capacity11090
libspdm_get_scratch_buffer_large_sender_receiver_offset12491
libspdm_get_scratch_buffer_last_spdm_request_capacity13664
libspdm_get_scratch_buffer_large_sender_receiver_capacity15791
libspdm_get_scratch_buffer_sender_receiver_capacity20969
libspdm_get_scratch_buffer_large_message_capacity23570
libspdm_get_scratch_buffer_secure_message_capacity26127
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_common_lib/libspdm_com_context_data.c.func.html b/coverage_log/library/spdm_common_lib/libspdm_com_context_data.c.func.html new file mode 100644 index 00000000000..751efed022e --- /dev/null +++ b/coverage_log/library/spdm_common_lib/libspdm_com_context_data.c.func.html @@ -0,0 +1,361 @@ + + + + + + + LCOV - coverage.info - library/spdm_common_lib/libspdm_com_context_data.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_common_lib - libspdm_com_context_data.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:636146143.5 %
Date:2024-09-22 08:21:07Functions:607085.7 %
Branches:26580133.1 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_acquire_receiver_buffer2481
libspdm_acquire_sender_buffer2522
libspdm_append_message_a169
libspdm_append_message_b5932
libspdm_append_message_c50
libspdm_append_message_d7
libspdm_append_message_encap_d4
libspdm_append_message_f241
libspdm_append_message_k288
libspdm_append_message_m722
libspdm_append_message_mut_b2835
libspdm_append_message_mut_c10
libspdm_check_context3
libspdm_deinit_context0
libspdm_export_fips_selftest_context_from_spdm_context0
libspdm_get_connection_version10182
libspdm_get_context_size96
libspdm_get_context_size_without_secured_context1
libspdm_get_data30
libspdm_get_fips_selftest_context_size0
libspdm_get_last_spdm_error_struct0
libspdm_get_receiver_buffer0
libspdm_get_scratch_buffer5444
libspdm_get_scratch_buffer_cache_spdm_request_capacity11090
libspdm_get_scratch_buffer_cache_spdm_request_offset89
libspdm_get_scratch_buffer_capacity5622
libspdm_get_scratch_buffer_large_message_capacity23570
libspdm_get_scratch_buffer_large_message_offset34
libspdm_get_scratch_buffer_large_sender_receiver_capacity15791
libspdm_get_scratch_buffer_large_sender_receiver_offset12491
libspdm_get_scratch_buffer_last_spdm_request_capacity13664
libspdm_get_scratch_buffer_last_spdm_request_offset89
libspdm_get_scratch_buffer_secure_message_capacity26127
libspdm_get_scratch_buffer_secure_message_offset2543
libspdm_get_scratch_buffer_sender_receiver_capacity20969
libspdm_get_scratch_buffer_sender_receiver_offset5259
libspdm_get_sender_buffer2581
libspdm_get_sizeof_required_scratch_buffer89
libspdm_get_version_from_version_number225
libspdm_import_fips_selftest_context_to_spdm_context0
libspdm_init_context96
libspdm_init_context_with_secured_context97
libspdm_init_fips_selftest_context0
libspdm_is_capabilities_flag_supported8163
libspdm_is_encap_supported16
libspdm_is_version_supported0
libspdm_negotiate_connection_version27
libspdm_register_device_buffer_func90
libspdm_register_device_io_func89
libspdm_register_transport_layer_func91
libspdm_register_verify_spdm_cert_chain_func0
libspdm_release_receiver_buffer2475
libspdm_release_sender_buffer2516
libspdm_reset_context42
libspdm_reset_message_a618
libspdm_reset_message_b999
libspdm_reset_message_buffer_via_request_code4196
libspdm_reset_message_c575
libspdm_reset_message_d50
libspdm_reset_message_encap_d6
libspdm_reset_message_f21
libspdm_reset_message_k0
libspdm_reset_message_m4060
libspdm_reset_message_mut_b444
libspdm_reset_message_mut_c443
libspdm_set_data18
libspdm_set_last_spdm_error_struct2675
libspdm_set_scratch_buffer89
libspdm_version_number_sort54
need_session_info_for_data48
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_common_lib/libspdm_com_context_data.c.gcov.html b/coverage_log/library/spdm_common_lib/libspdm_com_context_data.c.gcov.html new file mode 100644 index 00000000000..17fc642ee87 --- /dev/null +++ b/coverage_log/library/spdm_common_lib/libspdm_com_context_data.c.gcov.html @@ -0,0 +1,3384 @@ + + + + + + + LCOV - coverage.info - library/spdm_common_lib/libspdm_com_context_data.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_common_lib - libspdm_com_context_data.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:636146143.5 %
Date:2024-09-22 08:21:07Functions:607085.7 %
Branches:26580133.1 %
+
+ + + + + + + + +

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

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_secured_message_context_via_session_info0
libspdm_session_info_set_psk_hint74
libspdm_assign_session_id80
libspdm_generate_session_id80
libspdm_free_session_id110
libspdm_session_info_init670
libspdm_get_secured_message_context_via_session_id817
libspdm_get_session_info_via_session_id1552
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_common_lib/libspdm_com_context_data_session.c.func.html b/coverage_log/library/spdm_common_lib/libspdm_com_context_data_session.c.func.html new file mode 100644 index 00000000000..c5609a0a81e --- /dev/null +++ b/coverage_log/library/spdm_common_lib/libspdm_com_context_data_session.c.func.html @@ -0,0 +1,113 @@ + + + + + + + LCOV - coverage.info - library/spdm_common_lib/libspdm_com_context_data_session.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_common_lib - libspdm_com_context_data_session.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:8611773.5 %
Date:2024-09-22 08:21:07Functions:7887.5 %
Branches:405671.4 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_assign_session_id80
libspdm_free_session_id110
libspdm_generate_session_id80
libspdm_get_secured_message_context_via_session_id817
libspdm_get_secured_message_context_via_session_info0
libspdm_get_session_info_via_session_id1552
libspdm_session_info_init670
libspdm_session_info_set_psk_hint74
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_common_lib/libspdm_com_context_data_session.c.gcov.html b/coverage_log/library/spdm_common_lib/libspdm_com_context_data_session.c.gcov.html new file mode 100644 index 00000000000..40084897621 --- /dev/null +++ b/coverage_log/library/spdm_common_lib/libspdm_com_context_data_session.c.gcov.html @@ -0,0 +1,386 @@ + + + + + + + LCOV - coverage.info - library/spdm_common_lib/libspdm_com_context_data_session.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_common_lib - libspdm_com_context_data_session.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:8611773.5 %
Date:2024-09-22 08:21:07Functions:7887.5 %
Branches:405671.4 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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_secured_message_lib.h"
+       8                 :            : 
+       9                 :            : /**
+      10                 :            :  * This function initializes the session info.
+      11                 :            :  *
+      12                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+      13                 :            :  * @param  session_id                    The SPDM session ID.
+      14                 :            :  **/
+      15                 :        670 : void libspdm_session_info_init(libspdm_context_t *spdm_context,
+      16                 :            :                                libspdm_session_info_t *session_info,
+      17                 :            :                                uint32_t session_id, bool use_psk)
+      18                 :            : {
+      19                 :            :     libspdm_session_type_t session_type;
+      20                 :            :     uint32_t capabilities_flag;
+      21                 :            : 
+      22         [ +  + ]:        670 :     if (session_id != INVALID_SESSION_ID) {
+      23         [ +  + ]:        382 :         if (use_psk) {
+      24   [ +  +  -  + ]:        271 :             LIBSPDM_ASSERT((spdm_context->max_psk_session_count == 0) ||
+      25                 :            :                            (spdm_context->current_psk_session_count <
+      26                 :            :                             spdm_context->max_psk_session_count));
+      27                 :        271 :             spdm_context->current_psk_session_count++;
+      28                 :            :         } else {
+      29   [ +  +  -  + ]:        111 :             LIBSPDM_ASSERT((spdm_context->max_dhe_session_count == 0) ||
+      30                 :            :                            (spdm_context->current_dhe_session_count <
+      31                 :            :                             spdm_context->max_dhe_session_count));
+      32                 :        111 :             spdm_context->current_dhe_session_count++;
+      33                 :            :         }
+      34                 :            :     } else {
+      35         [ +  + ]:        288 :         if (use_psk) {
+      36         [ +  - ]:         56 :             if (spdm_context->current_psk_session_count > 0) {
+      37                 :         56 :                 spdm_context->current_psk_session_count--;
+      38                 :            :             }
+      39                 :            :         } else {
+      40         [ +  + ]:        232 :             if (spdm_context->current_dhe_session_count > 0) {
+      41                 :         60 :                 spdm_context->current_dhe_session_count--;
+      42                 :            :             }
+      43                 :            :         }
+      44                 :            :     }
+      45                 :            : 
+      46                 :        670 :     capabilities_flag = spdm_context->connection_info.capability.flags &
+      47                 :        670 :                         spdm_context->local_context.capability.flags;
+      48   [ +  +  -  - ]:        670 :     switch (capabilities_flag &
+      49                 :            :             (SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP |
+      50                 :            :              SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP)) {
+      51                 :        349 :     case 0:
+      52                 :        349 :         session_type = LIBSPDM_SESSION_TYPE_NONE;
+      53                 :        349 :         break;
+      54                 :        321 :     case (SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP |
+      55                 :            :           SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP):
+      56                 :        321 :         session_type = LIBSPDM_SESSION_TYPE_ENC_MAC;
+      57                 :        321 :         break;
+      58                 :          0 :     case SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP:
+      59                 :          0 :         session_type = LIBSPDM_SESSION_TYPE_MAC_ONLY;
+      60                 :          0 :         break;
+      61                 :          0 :     default:
+      62                 :          0 :         LIBSPDM_ASSERT(false);
+      63                 :          0 :         session_type = LIBSPDM_SESSION_TYPE_MAX;
+      64                 :          0 :         break;
+      65                 :            :     }
+      66                 :            : 
+      67                 :            : #if !(LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT)
+      68         [ +  + ]:        670 :     if (session_info->session_transcript.digest_context_th != NULL) {
+      69                 :        128 :         libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
+      70                 :            :                            session_info->session_transcript.digest_context_th);
+      71                 :        128 :         session_info->session_transcript.digest_context_th = NULL;
+      72                 :            :     }
+      73         [ +  + ]:        670 :     if (session_info->session_transcript.digest_context_th_backup != NULL) {
+      74                 :         59 :         libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
+      75                 :            :                            session_info->session_transcript.digest_context_th_backup);
+      76                 :         59 :         session_info->session_transcript.digest_context_th_backup = NULL;
+      77                 :            :     }
+      78                 :            : #endif
+      79                 :            : 
+      80                 :        670 :     libspdm_zero_mem (&(session_info->last_key_update_request), sizeof(spdm_key_update_request_t));
+      81                 :        670 :     libspdm_zero_mem(session_info, offsetof(libspdm_session_info_t, secured_message_context));
+      82                 :        670 :     libspdm_secured_message_init_context(session_info->secured_message_context);
+      83                 :        670 :     session_info->session_id = session_id;
+      84                 :        670 :     session_info->use_psk = use_psk;
+      85                 :        670 :     libspdm_secured_message_set_use_psk(session_info->secured_message_context, use_psk);
+      86                 :        670 :     libspdm_secured_message_set_session_type(session_info->secured_message_context, session_type);
+      87                 :            : 
+      88                 :            :     /* 277 1.2 explicitly specifies a little-endian sequence number. 1.0 and 1.1 leave it up to the
+      89                 :            :      * Integrator to specify. */
+      90         [ +  + ]:        670 :     if ((spdm_context->connection_info.secured_message_version >> SPDM_VERSION_NUMBER_SHIFT_BIT) >=
+      91                 :            :         SECURED_SPDM_VERSION_12) {
+      92                 :         27 :         libspdm_secured_message_set_sequence_number_endian(
+      93                 :            :             session_info->secured_message_context,
+      94                 :            :             LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_LITTLE_DEC_LITTLE);
+      95                 :            :     } else {
+      96                 :        643 :         libspdm_secured_message_set_sequence_number_endian(session_info->secured_message_context,
+      97                 :        643 :                                                            spdm_context->sequence_number_endian);
+      98                 :            :     }
+      99                 :            : 
+     100                 :        670 :     libspdm_secured_message_set_max_spdm_session_sequence_number(
+     101                 :            :         session_info->secured_message_context, spdm_context->max_spdm_session_sequence_number);
+     102                 :        670 :     libspdm_secured_message_set_algorithms(
+     103                 :            :         session_info->secured_message_context,
+     104                 :        670 :         spdm_context->connection_info.version,
+     105                 :        670 :         spdm_context->connection_info.secured_message_version,
+     106                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+     107                 :        670 :         spdm_context->connection_info.algorithm.dhe_named_group,
+     108                 :        670 :         spdm_context->connection_info.algorithm.aead_cipher_suite,
+     109                 :        670 :         spdm_context->connection_info.algorithm.key_schedule);
+     110                 :        670 :     session_info->session_transcript.message_encap_d.max_buffer_size =
+     111                 :            :         sizeof(session_info->session_transcript.message_encap_d.buffer);
+     112                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     113                 :            :     session_info->session_transcript.message_k.max_buffer_size =
+     114                 :            :         sizeof(session_info->session_transcript.message_k.buffer);
+     115                 :            :     session_info->session_transcript.message_f.max_buffer_size =
+     116                 :            :         sizeof(session_info->session_transcript.message_f.buffer);
+     117                 :            :     session_info->session_transcript.message_m.max_buffer_size =
+     118                 :            :         sizeof(session_info->session_transcript.message_m.buffer);
+     119                 :            : #endif
+     120                 :        670 : }
+     121                 :            : 
+     122                 :            : #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
+     123                 :         74 : void libspdm_session_info_set_psk_hint(libspdm_session_info_t *session_info,
+     124                 :            :                                        const void *psk_hint,
+     125                 :            :                                        size_t psk_hint_size)
+     126                 :            : {
+     127                 :         74 :     libspdm_secured_message_set_psk_hint(
+     128                 :            :         session_info->secured_message_context,
+     129                 :            :         psk_hint,
+     130                 :            :         psk_hint_size);
+     131                 :         74 : }
+     132                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP */
+     133                 :            : 
+     134                 :            : /**
+     135                 :            :  * This function gets the session info via session ID.
+     136                 :            :  *
+     137                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     138                 :            :  * @param  session_id                    The SPDM session ID.
+     139                 :            :  *
+     140                 :            :  * @return session info.
+     141                 :            :  **/
+     142                 :       1552 : void *libspdm_get_session_info_via_session_id(void *spdm_context, uint32_t session_id)
+     143                 :            : {
+     144                 :            :     libspdm_context_t *context;
+     145                 :            :     libspdm_session_info_t *session_info;
+     146                 :            :     size_t index;
+     147                 :            : 
+     148         [ -  + ]:       1552 :     if (session_id == INVALID_SESSION_ID) {
+     149                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR,
+     150                 :            :                        "libspdm_get_session_info_via_session_id - Invalid session_id\n"));
+     151                 :          0 :         LIBSPDM_ASSERT(false);
+     152                 :          0 :         return NULL;
+     153                 :            :     }
+     154                 :            : 
+     155                 :       1552 :     context = spdm_context;
+     156                 :            : 
+     157                 :       1552 :     session_info = (libspdm_session_info_t *)context->session_info;
+     158         [ +  - ]:       1553 :     for (index = 0; index < LIBSPDM_MAX_SESSION_COUNT; index++) {
+     159         [ +  + ]:       1553 :         if (session_info[index].session_id == session_id) {
+     160                 :       1552 :             return &session_info[index];
+     161                 :            :         }
+     162                 :            :     }
+     163                 :            : 
+     164                 :          0 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR,
+     165                 :            :                    "libspdm_get_session_info_via_session_id - not found session_id\n"));
+     166                 :          0 :     return NULL;
+     167                 :            : }
+     168                 :            : 
+     169                 :            : /**
+     170                 :            :  * This function gets the secured message context via session ID.
+     171                 :            :  *
+     172                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     173                 :            :  * @param  session_id                    The SPDM session ID.
+     174                 :            :  *
+     175                 :            :  * @return secured message context.
+     176                 :            :  **/
+     177                 :        817 : void *libspdm_get_secured_message_context_via_session_id(void *spdm_context, uint32_t session_id)
+     178                 :            : {
+     179                 :            :     libspdm_session_info_t *session_info;
+     180                 :            : 
+     181                 :        817 :     session_info = libspdm_get_session_info_via_session_id(spdm_context, session_id);
+     182         [ -  + ]:        817 :     if (session_info == NULL) {
+     183                 :          0 :         return NULL;
+     184                 :            :     } else {
+     185                 :        817 :         return session_info->secured_message_context;
+     186                 :            :     }
+     187                 :            : }
+     188                 :            : 
+     189                 :            : /**
+     190                 :            :  * This function gets the secured message context via session ID.
+     191                 :            :  *
+     192                 :            :  * @param  spdm_session_info              A pointer to the SPDM context.
+     193                 :            :  *
+     194                 :            :  * @return secured message context.
+     195                 :            :  **/
+     196                 :          0 : void *libspdm_get_secured_message_context_via_session_info(void *spdm_session_info)
+     197                 :            : {
+     198                 :            :     libspdm_session_info_t *session_info;
+     199                 :            : 
+     200                 :          0 :     session_info = spdm_session_info;
+     201         [ #  # ]:          0 :     if (session_info == NULL) {
+     202                 :          0 :         return NULL;
+     203                 :            :     } else {
+     204                 :          0 :         return session_info->secured_message_context;
+     205                 :            :     }
+     206                 :            : }
+     207                 :            : 
+     208                 :            : /**
+     209                 :            :  * This function generate a new session ID by concatenating req_session_id and rsp_session_id.
+     210                 :            :  *
+     211                 :            :  * @param[in]  req_session_id
+     212                 :            :  * @param[in]  rsp_session_id
+     213                 :            :  *
+     214                 :            :  * @return this new session ID.
+     215                 :            :  **/
+     216                 :         80 : uint32_t libspdm_generate_session_id(uint16_t req_session_id, uint16_t rsp_session_id)
+     217                 :            : {
+     218                 :            :     uint32_t session_id;
+     219                 :         80 :     session_id = (rsp_session_id << 16) | req_session_id;
+     220                 :         80 :     return session_id;
+     221                 :            : }
+     222                 :            : 
+     223                 :            : /**
+     224                 :            :  * This function assigns a new session ID.
+     225                 :            :  *
+     226                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     227                 :            :  * @param  session_id                    The SPDM session ID.
+     228                 :            :  *
+     229                 :            :  * @return session info associated with this new session ID.
+     230                 :            :  **/
+     231                 :         80 : void *libspdm_assign_session_id(libspdm_context_t *spdm_context, uint32_t session_id, bool use_psk)
+     232                 :            : {
+     233                 :            :     libspdm_session_info_t *session_info;
+     234                 :            :     size_t index;
+     235                 :            : 
+     236         [ -  + ]:         80 :     if (session_id == INVALID_SESSION_ID) {
+     237                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR, "libspdm_assign_session_id - Invalid session_id\n"));
+     238                 :          0 :         LIBSPDM_ASSERT(false);
+     239                 :          0 :         return NULL;
+     240                 :            :     }
+     241                 :            : 
+     242                 :         80 :     session_info = spdm_context->session_info;
+     243                 :            : 
+     244         [ +  + ]:        400 :     for (index = 0; index < LIBSPDM_MAX_SESSION_COUNT; index++) {
+     245         [ -  + ]:        320 :         if (session_info[index].session_id == session_id) {
+     246                 :          0 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR,
+     247                 :            :                            "libspdm_assign_session_id - Duplicated session_id\n"));
+     248                 :          0 :             LIBSPDM_ASSERT(false);
+     249                 :          0 :             return NULL;
+     250                 :            :         }
+     251                 :            :     }
+     252                 :            : 
+     253         [ +  - ]:        121 :     for (index = 0; index < LIBSPDM_MAX_SESSION_COUNT; index++) {
+     254         [ +  + ]:        121 :         if (session_info[index].session_id == INVALID_SESSION_ID) {
+     255                 :         80 :             libspdm_session_info_init(spdm_context,
+     256                 :         80 :                                       &session_info[index], session_id,
+     257                 :            :                                       use_psk);
+     258                 :         80 :             spdm_context->latest_session_id = session_id;
+     259                 :         80 :             return &session_info[index];
+     260                 :            :         }
+     261                 :            :     }
+     262                 :            : 
+     263                 :          0 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR, "libspdm_assign_session_id - MAX session_id\n"));
+     264                 :          0 :     return NULL;
+     265                 :            : }
+     266                 :            : 
+     267                 :            : /**
+     268                 :            :  * This function frees a session ID.
+     269                 :            :  *
+     270                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     271                 :            :  * @param  session_id                    The SPDM session ID.
+     272                 :            :  **/
+     273                 :        110 : void libspdm_free_session_id(libspdm_context_t *spdm_context, uint32_t session_id)
+     274                 :            : {
+     275                 :            :     libspdm_session_info_t *session_info;
+     276                 :            :     size_t index;
+     277                 :            : 
+     278         [ -  + ]:        110 :     if (session_id == INVALID_SESSION_ID) {
+     279                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR, "libspdm_free_session_id - Invalid session_id\n"));
+     280                 :          0 :         LIBSPDM_ASSERT(false);
+     281                 :          0 :         return;
+     282                 :            :     }
+     283                 :            : 
+     284         [ +  + ]:        110 :     if (spdm_context->latest_session_id == session_id) {
+     285                 :         40 :         spdm_context->latest_session_id = INVALID_SESSION_ID;
+     286                 :            :     }
+     287                 :            : 
+     288                 :        110 :     session_info = spdm_context->session_info;
+     289         [ +  - ]:        110 :     for (index = 0; index < LIBSPDM_MAX_SESSION_COUNT; index++) {
+     290         [ +  - ]:        110 :         if (session_info[index].session_id == session_id) {
+     291                 :        110 :             libspdm_session_info_init(spdm_context,
+     292                 :        110 :                                       &session_info[index],
+     293                 :            :                                       INVALID_SESSION_ID,
+     294                 :        110 :                                       session_info[index].use_psk);
+     295                 :        110 :             return;
+     296                 :            :         }
+     297                 :            :     }
+     298                 :            : 
+     299                 :          0 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR, "libspdm_free_session_id - MAX session_id\n"));
+     300                 :          0 :     LIBSPDM_ASSERT(false);
+     301                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_common_lib/libspdm_com_crypto_service.c.func-sort-c.html b/coverage_log/library/spdm_common_lib/libspdm_com_crypto_service.c.func-sort-c.html new file mode 100644 index 00000000000..ccdd5ad44fe --- /dev/null +++ b/coverage_log/library/spdm_common_lib/libspdm_com_crypto_service.c.func-sort-c.html @@ -0,0 +1,157 @@ + + + + + + + LCOV - coverage.info - library/spdm_common_lib/libspdm_com_crypto_service.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_common_lib - libspdm_com_crypto_service.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:18923181.8 %
Date:2024-09-22 08:21:07Functions:161984.2 %
Branches:8211372.6 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_local_cert_chain_data0
libspdm_get_peer_cert_chain_buffer0
libspdm_get_peer_cert_chain_data0
libspdm_generate_public_key_hash2
libspdm_get_local_public_key_buffer2
libspdm_verify_public_key_hash2
libspdm_get_peer_public_key_buffer3
libspdm_get_cert_slot_mask10
libspdm_generate_challenge_auth_signature12
libspdm_get_cert_slot_count16
libspdm_verify_certificate_chain_hash19
libspdm_verify_challenge_auth_signature19
libspdm_verify_peer_cert_chain_buffer_authority29
libspdm_calculate_m1m2_hash31
libspdm_get_local_cert_chain_buffer32
libspdm_verify_peer_cert_chain_buffer_integrity34
libspdm_generate_cert_chain_hash35
libspdm_calculate_l1l2_hash39
libspdm_get_measurement_summary_hash_size103
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_common_lib/libspdm_com_crypto_service.c.func.html b/coverage_log/library/spdm_common_lib/libspdm_com_crypto_service.c.func.html new file mode 100644 index 00000000000..240feeb0a1a --- /dev/null +++ b/coverage_log/library/spdm_common_lib/libspdm_com_crypto_service.c.func.html @@ -0,0 +1,157 @@ + + + + + + + LCOV - coverage.info - library/spdm_common_lib/libspdm_com_crypto_service.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_common_lib - libspdm_com_crypto_service.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:18923181.8 %
Date:2024-09-22 08:21:07Functions:161984.2 %
Branches:8211372.6 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_calculate_l1l2_hash39
libspdm_calculate_m1m2_hash31
libspdm_generate_cert_chain_hash35
libspdm_generate_challenge_auth_signature12
libspdm_generate_public_key_hash2
libspdm_get_cert_slot_count16
libspdm_get_cert_slot_mask10
libspdm_get_local_cert_chain_buffer32
libspdm_get_local_cert_chain_data0
libspdm_get_local_public_key_buffer2
libspdm_get_measurement_summary_hash_size103
libspdm_get_peer_cert_chain_buffer0
libspdm_get_peer_cert_chain_data0
libspdm_get_peer_public_key_buffer3
libspdm_verify_certificate_chain_hash19
libspdm_verify_challenge_auth_signature19
libspdm_verify_peer_cert_chain_buffer_authority29
libspdm_verify_peer_cert_chain_buffer_integrity34
libspdm_verify_public_key_hash2
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_common_lib/libspdm_com_crypto_service.c.gcov.html b/coverage_log/library/spdm_common_lib/libspdm_com_crypto_service.c.gcov.html new file mode 100644 index 00000000000..4e98a75a59b --- /dev/null +++ b/coverage_log/library/spdm_common_lib/libspdm_com_crypto_service.c.gcov.html @@ -0,0 +1,1236 @@ + + + + + + + LCOV - coverage.info - library/spdm_common_lib/libspdm_com_crypto_service.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_common_lib - libspdm_com_crypto_service.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:18923181.8 %
Date:2024-09-22 08:21:07Functions:161984.2 %
Branches:8211372.6 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "internal/libspdm_common_lib.h"
+       8                 :            : 
+       9                 :            : /**
+      10                 :            :  * This function returns peer certificate chain buffer including spdm_cert_chain_t header.
+      11                 :            :  *
+      12                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+      13                 :            :  * @param  cert_chain_buffer              Certificate chain buffer including spdm_cert_chain_t header.
+      14                 :            :  * @param  cert_chain_buffer_size          size in bytes of the certificate chain buffer.
+      15                 :            :  *
+      16                 :            :  * @retval true  Peer certificate chain buffer including spdm_cert_chain_t header is returned.
+      17                 :            :  * @retval false Peer certificate chain buffer including spdm_cert_chain_t header is not found.
+      18                 :            :  **/
+      19                 :          0 : bool libspdm_get_peer_cert_chain_buffer(void *spdm_context,
+      20                 :            :                                         const void **cert_chain_buffer,
+      21                 :            :                                         size_t *cert_chain_buffer_size)
+      22                 :            : {
+      23                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+      24                 :            :     libspdm_context_t *context;
+      25                 :            :     uint8_t slot_id;
+      26                 :            : 
+      27                 :            :     context = spdm_context;
+      28                 :            :     slot_id = context->connection_info.peer_used_cert_chain_slot_id;
+      29                 :            :     LIBSPDM_ASSERT(slot_id < SPDM_MAX_SLOT_COUNT);
+      30                 :            :     if (context->connection_info.peer_used_cert_chain[slot_id].buffer_size != 0) {
+      31                 :            :         *cert_chain_buffer = context->connection_info.peer_used_cert_chain[slot_id].buffer;
+      32                 :            :         *cert_chain_buffer_size = context->connection_info
+      33                 :            :                                   .peer_used_cert_chain[slot_id].buffer_size;
+      34                 :            :         return true;
+      35                 :            :     }
+      36                 :            : #endif
+      37                 :          0 :     return false;
+      38                 :            : }
+      39                 :            : 
+      40                 :            : /**
+      41                 :            :  * This function returns peer certificate chain data without spdm_cert_chain_t header.
+      42                 :            :  *
+      43                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+      44                 :            :  * @param  cert_chain_data                Certificate chain data without spdm_cert_chain_t header.
+      45                 :            :  * @param  cert_chain_data_size            size in bytes of the certificate chain data.
+      46                 :            :  *
+      47                 :            :  * @retval true  Peer certificate chain data without spdm_cert_chain_t header is returned.
+      48                 :            :  * @retval false Peer certificate chain data without spdm_cert_chain_t header is not found.
+      49                 :            :  **/
+      50                 :          0 : bool libspdm_get_peer_cert_chain_data(void *spdm_context,
+      51                 :            :                                       const void **cert_chain_data,
+      52                 :            :                                       size_t *cert_chain_data_size)
+      53                 :            : {
+      54                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+      55                 :            :     libspdm_context_t *context;
+      56                 :            :     size_t hash_size;
+      57                 :            :     bool result;
+      58                 :            : 
+      59                 :            :     context = spdm_context;
+      60                 :            :     hash_size = libspdm_get_hash_size(context->connection_info.algorithm.base_hash_algo);
+      61                 :            : 
+      62                 :            :     result = libspdm_get_peer_cert_chain_buffer(context, cert_chain_data,
+      63                 :            :                                                 cert_chain_data_size);
+      64                 :            :     if (result) {
+      65                 :            :         *cert_chain_data =
+      66                 :            :             (const uint8_t *)*cert_chain_data + sizeof(spdm_cert_chain_t) + hash_size;
+      67                 :            :         *cert_chain_data_size =
+      68                 :            :             *cert_chain_data_size - (sizeof(spdm_cert_chain_t) + hash_size);
+      69                 :            :         return true;
+      70                 :            :     }
+      71                 :            : #endif
+      72                 :          0 :     return false;
+      73                 :            : }
+      74                 :            : 
+      75                 :            : /**
+      76                 :            :  * This function returns local used certificate chain buffer including spdm_cert_chain_t header.
+      77                 :            :  *
+      78                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+      79                 :            :  * @param  cert_chain_buffer              Certificate chain buffer including spdm_cert_chain_t header.
+      80                 :            :  * @param  cert_chain_buffer_size          size in bytes of the certificate chain buffer.
+      81                 :            :  *
+      82                 :            :  * @retval true  Local used certificate chain buffer including spdm_cert_chain_t header is returned.
+      83                 :            :  * @retval false Local used certificate chain buffer including spdm_cert_chain_t header is not found.
+      84                 :            :  **/
+      85                 :         32 : bool libspdm_get_local_cert_chain_buffer(void *spdm_context,
+      86                 :            :                                          const void **cert_chain_buffer,
+      87                 :            :                                          size_t *cert_chain_buffer_size)
+      88                 :            : {
+      89                 :            :     libspdm_context_t *context;
+      90                 :            : 
+      91                 :         32 :     context = spdm_context;
+      92         [ +  - ]:         32 :     if (context->connection_info.local_used_cert_chain_buffer_size != 0) {
+      93                 :         32 :         *cert_chain_buffer = context->connection_info.local_used_cert_chain_buffer;
+      94                 :         32 :         *cert_chain_buffer_size = context->connection_info.local_used_cert_chain_buffer_size;
+      95                 :         32 :         return true;
+      96                 :            :     }
+      97                 :          0 :     return false;
+      98                 :            : }
+      99                 :            : 
+     100                 :            : /**
+     101                 :            :  * This function returns local used certificate chain data without spdm_cert_chain_t header.
+     102                 :            :  *
+     103                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     104                 :            :  * @param  cert_chain_data                Certificate chain data without spdm_cert_chain_t header.
+     105                 :            :  * @param  cert_chain_data_size            size in bytes of the certificate chain data.
+     106                 :            :  *
+     107                 :            :  * @retval true  Local used certificate chain data without spdm_cert_chain_t header is returned.
+     108                 :            :  * @retval false Local used certificate chain data without spdm_cert_chain_t header is not found.
+     109                 :            :  **/
+     110                 :          0 : bool libspdm_get_local_cert_chain_data(void *spdm_context,
+     111                 :            :                                        const void **cert_chain_data,
+     112                 :            :                                        size_t *cert_chain_data_size)
+     113                 :            : {
+     114                 :            :     libspdm_context_t *context;
+     115                 :            :     bool result;
+     116                 :            :     size_t hash_size;
+     117                 :            : 
+     118                 :          0 :     context = spdm_context;
+     119                 :            : 
+     120                 :          0 :     result = libspdm_get_local_cert_chain_buffer(context, cert_chain_data,
+     121                 :            :                                                  cert_chain_data_size);
+     122         [ #  # ]:          0 :     if (!result) {
+     123                 :          0 :         return false;
+     124                 :            :     }
+     125                 :            : 
+     126                 :          0 :     hash_size = libspdm_get_hash_size(context->connection_info.algorithm.base_hash_algo);
+     127                 :            : 
+     128                 :          0 :     *cert_chain_data = (const uint8_t *)*cert_chain_data + sizeof(spdm_cert_chain_t) + hash_size;
+     129                 :          0 :     *cert_chain_data_size = *cert_chain_data_size - (sizeof(spdm_cert_chain_t) + hash_size);
+     130                 :          0 :     return true;
+     131                 :            : }
+     132                 :            : 
+     133                 :            : /**
+     134                 :            :  * This function returns peer public key buffer.
+     135                 :            :  *
+     136                 :            :  * @param  spdm_context                 A pointer to the SPDM context.
+     137                 :            :  * @param  peer_public_key_buffer       Peer public key buffer.
+     138                 :            :  * @param  peer_public_key_buffer_size  Size in bytes of peer public key buffer.
+     139                 :            :  *
+     140                 :            :  * @retval true  Peer public key buffer is returned.
+     141                 :            :  * @retval false Peer public key buffer is not found.
+     142                 :            :  **/
+     143                 :          3 : bool libspdm_get_peer_public_key_buffer(void *spdm_context,
+     144                 :            :                                         const void **peer_public_key_buffer,
+     145                 :            :                                         size_t *peer_public_key_buffer_size)
+     146                 :            : {
+     147                 :            :     libspdm_context_t *context;
+     148                 :            : 
+     149                 :          3 :     context = spdm_context;
+     150         [ +  - ]:          3 :     if (context->local_context.peer_public_key_provision_size != 0) {
+     151                 :          3 :         *peer_public_key_buffer = context->local_context.peer_public_key_provision;
+     152                 :          3 :         *peer_public_key_buffer_size = context->local_context.peer_public_key_provision_size;
+     153                 :          3 :         return true;
+     154                 :            :     }
+     155                 :          0 :     return false;
+     156                 :            : }
+     157                 :            : 
+     158                 :            : /**
+     159                 :            :  * This function returns local public key buffer.
+     160                 :            :  *
+     161                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     162                 :            :  * @param  local_public_key_buffer       Local public key buffer.
+     163                 :            :  * @param  local_public_key_buffer_size  Size in bytes of local public key buffer.
+     164                 :            :  *
+     165                 :            :  * @retval true  Local public key buffer is returned.
+     166                 :            :  * @retval false Local public key buffer is not found.
+     167                 :            :  **/
+     168                 :          2 : bool libspdm_get_local_public_key_buffer(void *spdm_context,
+     169                 :            :                                          const void **local_public_key_buffer,
+     170                 :            :                                          size_t *local_public_key_buffer_size)
+     171                 :            : {
+     172                 :            :     libspdm_context_t *context;
+     173                 :            : 
+     174                 :          2 :     context = spdm_context;
+     175         [ +  - ]:          2 :     if (context->local_context.peer_public_key_provision_size != 0) {
+     176                 :          2 :         *local_public_key_buffer = context->local_context.local_public_key_provision;
+     177                 :          2 :         *local_public_key_buffer_size = context->local_context.local_public_key_provision_size;
+     178                 :          2 :         return true;
+     179                 :            :     }
+     180                 :          0 :     return false;
+     181                 :            : }
+     182                 :            : 
+     183                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     184                 :            : /*
+     185                 :            :  * This function calculates l1l2.
+     186                 :            :  * If session_info is NULL, this function will use M cache of SPDM context,
+     187                 :            :  * else will use M cache of SPDM session context.
+     188                 :            :  *
+     189                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     190                 :            :  * @param  session_info                  A pointer to the SPDM session context.
+     191                 :            :  * @param  l1l2                          The buffer to store the l1l2.
+     192                 :            :  *
+     193                 :            :  * @retval RETURN_SUCCESS  l1l2 is calculated.
+     194                 :            :  */
+     195                 :            : bool libspdm_calculate_l1l2(libspdm_context_t *spdm_context,
+     196                 :            :                             void *session_info,
+     197                 :            :                             libspdm_l1l2_managed_buffer_t *l1l2)
+     198                 :            : {
+     199                 :            :     libspdm_return_t status;
+     200                 :            :     libspdm_session_info_t *spdm_session_info;
+     201                 :            : 
+     202                 :            :     spdm_session_info = session_info;
+     203                 :            : 
+     204                 :            :     libspdm_init_managed_buffer(l1l2, sizeof(l1l2->buffer));
+     205                 :            : 
+     206                 :            :     if ((spdm_context->connection_info.version >> SPDM_VERSION_NUMBER_SHIFT_BIT) >
+     207                 :            :         SPDM_MESSAGE_VERSION_11) {
+     208                 :            : 
+     209                 :            :         /* Need append VCA since 1.2 script*/
+     210                 :            : 
+     211                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "message_a data :\n"));
+     212                 :            :         LIBSPDM_INTERNAL_DUMP_HEX(
+     213                 :            :             libspdm_get_managed_buffer(&spdm_context->transcript.message_a),
+     214                 :            :             libspdm_get_managed_buffer_size(&spdm_context->transcript.message_a));
+     215                 :            :         status = libspdm_append_managed_buffer(
+     216                 :            :             l1l2,
+     217                 :            :             libspdm_get_managed_buffer(&spdm_context->transcript.message_a),
+     218                 :            :             libspdm_get_managed_buffer_size(&spdm_context->transcript.message_a));
+     219                 :            :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     220                 :            :             return false;
+     221                 :            :         }
+     222                 :            :     }
+     223                 :            : 
+     224                 :            :     if (spdm_session_info == NULL) {
+     225                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "message_m data :\n"));
+     226                 :            :         LIBSPDM_INTERNAL_DUMP_HEX(
+     227                 :            :             libspdm_get_managed_buffer(&spdm_context->transcript.message_m),
+     228                 :            :             libspdm_get_managed_buffer_size(&spdm_context->transcript.message_m));
+     229                 :            :         status = libspdm_append_managed_buffer(
+     230                 :            :             l1l2,
+     231                 :            :             libspdm_get_managed_buffer(&spdm_context->transcript.message_m),
+     232                 :            :             libspdm_get_managed_buffer_size(&spdm_context->transcript.message_m));
+     233                 :            :     } else {
+     234                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "use message_m in session :\n"));
+     235                 :            :         LIBSPDM_INTERNAL_DUMP_HEX(
+     236                 :            :             libspdm_get_managed_buffer(&spdm_session_info->session_transcript.message_m),
+     237                 :            :             libspdm_get_managed_buffer_size(&spdm_session_info->session_transcript.message_m));
+     238                 :            :         status = libspdm_append_managed_buffer(
+     239                 :            :             l1l2,
+     240                 :            :             libspdm_get_managed_buffer(&spdm_session_info->session_transcript.message_m),
+     241                 :            :             libspdm_get_managed_buffer_size(&spdm_session_info->session_transcript.message_m));
+     242                 :            :     }
+     243                 :            :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     244                 :            :         return false;
+     245                 :            :     }
+     246                 :            : 
+     247                 :            :     /* Debug code only - calculate and print value of l1l2 hash*/
+     248                 :            :     LIBSPDM_DEBUG_CODE(
+     249                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     250                 :            :         uint32_t hash_size = libspdm_get_hash_size(
+     251                 :            :             spdm_context->connection_info.algorithm.base_hash_algo);
+     252                 :            :         if (!libspdm_hash_all(
+     253                 :            :                 spdm_context->connection_info.algorithm.base_hash_algo,
+     254                 :            :                 libspdm_get_managed_buffer(l1l2),
+     255                 :            :                 libspdm_get_managed_buffer_size(l1l2), hash_data)) {
+     256                 :            :         return false;
+     257                 :            :     }
+     258                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "l1l2 hash - "));
+     259                 :            :         LIBSPDM_INTERNAL_DUMP_DATA(hash_data, hash_size);
+     260                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     261                 :            :         );
+     262                 :            : 
+     263                 :            :     return true;
+     264                 :            : }
+     265                 :            : #else
+     266                 :            : /*
+     267                 :            :  * This function calculates l1l2 hash.
+     268                 :            :  * If session_info is NULL, this function will use M cache of SPDM context,
+     269                 :            :  * else will use M cache of SPDM session context.
+     270                 :            :  *
+     271                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     272                 :            :  * @param  session_info                  A pointer to the SPDM session context.
+     273                 :            :  * @param  l1l2_hash_size               size in bytes of the l1l2 hash
+     274                 :            :  * @param  l1l2_hash                   The buffer to store the l1l2 hash
+     275                 :            :  *
+     276                 :            :  * @retval RETURN_SUCCESS  l1l2 is calculated.
+     277                 :            :  */
+     278                 :         39 : bool libspdm_calculate_l1l2_hash(libspdm_context_t *spdm_context,
+     279                 :            :                                  void *session_info,
+     280                 :            :                                  size_t *l1l2_hash_size, void *l1l2_hash)
+     281                 :            : {
+     282                 :            :     libspdm_session_info_t *spdm_session_info;
+     283                 :            :     bool result;
+     284                 :            : 
+     285                 :            :     uint32_t hash_size;
+     286                 :            : 
+     287                 :         39 :     spdm_session_info = session_info;
+     288                 :            : 
+     289                 :         39 :     hash_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+     290                 :            : 
+     291         [ +  + ]:         39 :     if (spdm_session_info == NULL) {
+     292                 :         37 :         result = libspdm_hash_final (spdm_context->connection_info.algorithm.base_hash_algo,
+     293                 :            :                                      spdm_context->transcript.digest_context_l1l2, l1l2_hash);
+     294                 :            :     } else {
+     295                 :          2 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "use message_m in session :\n"));
+     296                 :          2 :         result = libspdm_hash_final (spdm_context->connection_info.algorithm.base_hash_algo,
+     297                 :            :                                      spdm_session_info->session_transcript.digest_context_l1l2,
+     298                 :            :                                      l1l2_hash);
+     299                 :            :     }
+     300         [ -  + ]:         39 :     if (!result) {
+     301                 :          0 :         return false;
+     302                 :            :     }
+     303                 :         39 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "l1l2 hash - "));
+     304                 :         39 :     LIBSPDM_INTERNAL_DUMP_DATA(l1l2_hash, hash_size);
+     305                 :         39 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     306                 :            : 
+     307                 :         39 :     *l1l2_hash_size = hash_size;
+     308                 :            : 
+     309                 :         39 :     return true;
+     310                 :            : }
+     311                 :            : #endif /* LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT */
+     312                 :            : 
+     313                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     314                 :            : /*
+     315                 :            :  * This function calculates m1m2.
+     316                 :            :  *
+     317                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     318                 :            :  * @param  is_mut                        Indicate if this is from mutual authentication.
+     319                 :            :  * @param  m1m2                          The buffer to store the m1m2
+     320                 :            :  *
+     321                 :            :  * @retval RETURN_SUCCESS  m1m2 is calculated.
+     322                 :            :  */
+     323                 :            : static bool libspdm_calculate_m1m2(void *context, bool is_mut,
+     324                 :            :                                    libspdm_m1m2_managed_buffer_t *m1m2)
+     325                 :            : {
+     326                 :            :     libspdm_context_t *spdm_context;
+     327                 :            :     libspdm_return_t status;
+     328                 :            : 
+     329                 :            :     spdm_context = context;
+     330                 :            : 
+     331                 :            :     libspdm_init_managed_buffer(m1m2, sizeof(m1m2->buffer));
+     332                 :            : 
+     333                 :            :     if (is_mut) {
+     334                 :            :         if ((spdm_context->connection_info.version >> SPDM_VERSION_NUMBER_SHIFT_BIT) >
+     335                 :            :             SPDM_MESSAGE_VERSION_11) {
+     336                 :            :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "message_a data :\n"));
+     337                 :            :             LIBSPDM_INTERNAL_DUMP_HEX(
+     338                 :            :                 libspdm_get_managed_buffer(&spdm_context->transcript.message_a),
+     339                 :            :                 libspdm_get_managed_buffer_size(&spdm_context->transcript.message_a));
+     340                 :            :             status = libspdm_append_managed_buffer(
+     341                 :            :                 m1m2,
+     342                 :            :                 libspdm_get_managed_buffer(&spdm_context->transcript.message_a),
+     343                 :            :                 libspdm_get_managed_buffer_size(&spdm_context->transcript.message_a));
+     344                 :            :             if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     345                 :            :                 return false;
+     346                 :            :             }
+     347                 :            :         }
+     348                 :            : 
+     349                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "message_mut_b data :\n"));
+     350                 :            :         LIBSPDM_INTERNAL_DUMP_HEX(
+     351                 :            :             libspdm_get_managed_buffer(&spdm_context->transcript.message_mut_b),
+     352                 :            :             libspdm_get_managed_buffer_size(&spdm_context->transcript.message_mut_b));
+     353                 :            :         status = libspdm_append_managed_buffer(
+     354                 :            :             m1m2,
+     355                 :            :             libspdm_get_managed_buffer(&spdm_context->transcript.message_mut_b),
+     356                 :            :             libspdm_get_managed_buffer_size(&spdm_context->transcript.message_mut_b));
+     357                 :            :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     358                 :            :             return false;
+     359                 :            :         }
+     360                 :            : 
+     361                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "message_mut_c data :\n"));
+     362                 :            :         LIBSPDM_INTERNAL_DUMP_HEX(
+     363                 :            :             libspdm_get_managed_buffer(&spdm_context->transcript.message_mut_c),
+     364                 :            :             libspdm_get_managed_buffer_size(&spdm_context->transcript.message_mut_c));
+     365                 :            :         status = libspdm_append_managed_buffer(
+     366                 :            :             m1m2,
+     367                 :            :             libspdm_get_managed_buffer(&spdm_context->transcript.message_mut_c),
+     368                 :            :             libspdm_get_managed_buffer_size(&spdm_context->transcript.message_mut_c));
+     369                 :            :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     370                 :            :             return false;
+     371                 :            :         }
+     372                 :            : 
+     373                 :            :         /* Debug code only - calculate and print value of m1m2 mut hash*/
+     374                 :            :         LIBSPDM_DEBUG_CODE(
+     375                 :            :             uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     376                 :            :             uint32_t hash_size = libspdm_get_hash_size(
+     377                 :            :                 spdm_context->connection_info.algorithm.base_hash_algo);
+     378                 :            :             if (!libspdm_hash_all(
+     379                 :            :                     spdm_context->connection_info.algorithm.base_hash_algo,
+     380                 :            :                     libspdm_get_managed_buffer(m1m2),
+     381                 :            :                     libspdm_get_managed_buffer_size(m1m2), hash_data)) {
+     382                 :            :             return false;
+     383                 :            :         }
+     384                 :            :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m1m2 Mut hash - "));
+     385                 :            :             LIBSPDM_INTERNAL_DUMP_DATA(hash_data, hash_size);
+     386                 :            :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     387                 :            :             );
+     388                 :            : 
+     389                 :            :     } else {
+     390                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "message_a data :\n"));
+     391                 :            :         LIBSPDM_INTERNAL_DUMP_HEX(
+     392                 :            :             libspdm_get_managed_buffer(&spdm_context->transcript.message_a),
+     393                 :            :             libspdm_get_managed_buffer_size(&spdm_context->transcript.message_a));
+     394                 :            :         status = libspdm_append_managed_buffer(
+     395                 :            :             m1m2,
+     396                 :            :             libspdm_get_managed_buffer(&spdm_context->transcript.message_a),
+     397                 :            :             libspdm_get_managed_buffer_size(&spdm_context->transcript.message_a));
+     398                 :            :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     399                 :            :             return false;
+     400                 :            :         }
+     401                 :            : 
+     402                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "message_b data :\n"));
+     403                 :            :         LIBSPDM_INTERNAL_DUMP_HEX(
+     404                 :            :             libspdm_get_managed_buffer(&spdm_context->transcript.message_b),
+     405                 :            :             libspdm_get_managed_buffer_size(&spdm_context->transcript.message_b));
+     406                 :            :         status = libspdm_append_managed_buffer(
+     407                 :            :             m1m2,
+     408                 :            :             libspdm_get_managed_buffer(&spdm_context->transcript.message_b),
+     409                 :            :             libspdm_get_managed_buffer_size(&spdm_context->transcript.message_b));
+     410                 :            :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     411                 :            :             return false;
+     412                 :            :         }
+     413                 :            : 
+     414                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "message_c data :\n"));
+     415                 :            :         LIBSPDM_INTERNAL_DUMP_HEX(
+     416                 :            :             libspdm_get_managed_buffer(&spdm_context->transcript.message_c),
+     417                 :            :             libspdm_get_managed_buffer_size(&spdm_context->transcript.message_c));
+     418                 :            :         status = libspdm_append_managed_buffer(
+     419                 :            :             m1m2,
+     420                 :            :             libspdm_get_managed_buffer(&spdm_context->transcript.message_c),
+     421                 :            :             libspdm_get_managed_buffer_size(&spdm_context->transcript.message_c));
+     422                 :            :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     423                 :            :             return false;
+     424                 :            :         }
+     425                 :            : 
+     426                 :            :         /* Debug code only - calculate and print value of m1m2 hash*/
+     427                 :            :         LIBSPDM_DEBUG_CODE(
+     428                 :            :             uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     429                 :            :             uint32_t hash_size = libspdm_get_hash_size(
+     430                 :            :                 spdm_context->connection_info.algorithm.base_hash_algo);
+     431                 :            :             if (!libspdm_hash_all(
+     432                 :            :                     spdm_context->connection_info.algorithm.base_hash_algo,
+     433                 :            :                     libspdm_get_managed_buffer(m1m2),
+     434                 :            :                     libspdm_get_managed_buffer_size(m1m2), hash_data)) {
+     435                 :            :             return false;
+     436                 :            :         }
+     437                 :            :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m1m2 hash - "));
+     438                 :            :             LIBSPDM_INTERNAL_DUMP_DATA(hash_data, hash_size);
+     439                 :            :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     440                 :            :             );
+     441                 :            :     }
+     442                 :            : 
+     443                 :            :     return true;
+     444                 :            : }
+     445                 :            : #else
+     446                 :            : /*
+     447                 :            :  * This function calculates m1m2 hash.
+     448                 :            :  *
+     449                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     450                 :            :  * @param  is_mut                        Indicate if this is from mutual authentication.
+     451                 :            :  * @param  m1m2_hash_size               size in bytes of the m1m2 hash
+     452                 :            :  * @param  m1m2_hash                   The buffer to store the m1m2 hash
+     453                 :            :  *
+     454                 :            :  * @retval RETURN_SUCCESS  m1m2 is calculated.
+     455                 :            :  */
+     456                 :         31 : static bool libspdm_calculate_m1m2_hash(void *context, bool is_mut,
+     457                 :            :                                         size_t *m1m2_hash_size,
+     458                 :            :                                         void *m1m2_hash)
+     459                 :            : {
+     460                 :            :     libspdm_context_t *spdm_context;
+     461                 :            :     uint32_t hash_size;
+     462                 :            :     bool result;
+     463                 :            : 
+     464                 :         31 :     spdm_context = context;
+     465                 :            : 
+     466                 :         31 :     hash_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+     467                 :            : 
+     468         [ +  + ]:         31 :     if (is_mut) {
+     469                 :          6 :         result = libspdm_hash_final (spdm_context->connection_info.algorithm.base_hash_algo,
+     470                 :            :                                      spdm_context->transcript.digest_context_mut_m1m2, m1m2_hash);
+     471         [ -  + ]:          6 :         if (!result) {
+     472                 :          0 :             return false;
+     473                 :            :         }
+     474                 :          6 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m1m2 Mut hash - "));
+     475                 :          6 :         LIBSPDM_INTERNAL_DUMP_DATA(m1m2_hash, hash_size);
+     476                 :          6 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     477                 :            : 
+     478                 :            :     } else {
+     479                 :         25 :         result = libspdm_hash_final (spdm_context->connection_info.algorithm.base_hash_algo,
+     480                 :            :                                      spdm_context->transcript.digest_context_m1m2, m1m2_hash);
+     481         [ -  + ]:         25 :         if (!result) {
+     482                 :          0 :             return false;
+     483                 :            :         }
+     484                 :         25 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m1m2 hash - "));
+     485                 :         25 :         LIBSPDM_INTERNAL_DUMP_DATA(m1m2_hash, hash_size);
+     486                 :         25 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     487                 :            :     }
+     488                 :            : 
+     489                 :         31 :     *m1m2_hash_size = hash_size;
+     490                 :            : 
+     491                 :         31 :     return true;
+     492                 :            : }
+     493                 :            : #endif
+     494                 :            : 
+     495                 :            : /**
+     496                 :            :  * This function generates the certificate chain hash.
+     497                 :            :  *
+     498                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     499                 :            :  * @param  slot_id                    The slot index of the certificate chain.
+     500                 :            :  * @param  signature                    The buffer to store the certificate chain hash.
+     501                 :            :  *
+     502                 :            :  * @retval true  certificate chain hash is generated.
+     503                 :            :  * @retval false certificate chain hash is not generated.
+     504                 :            :  **/
+     505                 :         35 : bool libspdm_generate_cert_chain_hash(libspdm_context_t *spdm_context,
+     506                 :            :                                       size_t slot_id, uint8_t *hash)
+     507                 :            : {
+     508         [ -  + ]:         35 :     LIBSPDM_ASSERT(slot_id < SPDM_MAX_SLOT_COUNT);
+     509                 :         35 :     return libspdm_hash_all(
+     510                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+     511                 :            :         spdm_context->local_context.local_cert_chain_provision[slot_id],
+     512                 :            :         spdm_context->local_context.local_cert_chain_provision_size[slot_id], hash);
+     513                 :            : }
+     514                 :            : 
+     515                 :            : /**
+     516                 :            :  * This function generates the public key hash.
+     517                 :            :  *
+     518                 :            :  * @param  spdm_context               A pointer to the SPDM context.
+     519                 :            :  * @param  hash                       The buffer to store the public key hash.
+     520                 :            :  *
+     521                 :            :  * @retval true  public key hash is generated.
+     522                 :            :  * @retval false public key hash is not generated.
+     523                 :            :  **/
+     524                 :          2 : bool libspdm_generate_public_key_hash(libspdm_context_t *spdm_context,
+     525                 :            :                                       uint8_t *hash)
+     526                 :            : {
+     527                 :          2 :     return libspdm_hash_all(
+     528                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+     529                 :            :         spdm_context->local_context.local_public_key_provision,
+     530                 :            :         spdm_context->local_context.local_public_key_provision_size, hash);
+     531                 :            : }
+     532                 :            : 
+     533                 :            : /**
+     534                 :            :  * Get the certificate slot mask
+     535                 :            :  *
+     536                 :            :  * @param[in]   context              A pointer to the SPDM context.
+     537                 :            :  *
+     538                 :            :  * @retval slot_mask                 get slot mask
+     539                 :            :  **/
+     540                 :         10 : uint8_t libspdm_get_cert_slot_mask(libspdm_context_t *spdm_context)
+     541                 :            : {
+     542                 :            :     size_t index;
+     543                 :            :     uint8_t slot_mask;
+     544                 :            : 
+     545                 :         10 :     slot_mask = 0;
+     546         [ +  + ]:         90 :     for (index = 0; index < SPDM_MAX_SLOT_COUNT; index++) {
+     547         [ +  + ]:         80 :         if (spdm_context->local_context.local_cert_chain_provision[index] != NULL) {
+     548                 :         11 :             slot_mask |= (1 << index);
+     549                 :            :         }
+     550                 :            :     }
+     551                 :            : 
+     552                 :         10 :     return slot_mask;
+     553                 :            : }
+     554                 :            : 
+     555                 :            : /**
+     556                 :            :  * Get the certificate slot count
+     557                 :            :  *
+     558                 :            :  * @param[in]   context              A pointer to the SPDM context.
+     559                 :            :  *
+     560                 :            :  * @retval slot_count                get slot count
+     561                 :            :  **/
+     562                 :         16 : uint8_t libspdm_get_cert_slot_count(libspdm_context_t *spdm_context)
+     563                 :            : {
+     564                 :            :     size_t index;
+     565                 :            :     uint8_t slot_count;
+     566                 :            : 
+     567                 :         16 :     slot_count = 0;
+     568         [ +  + ]:        144 :     for (index = 0; index < SPDM_MAX_SLOT_COUNT; index++) {
+     569         [ +  + ]:        128 :         if (spdm_context->local_context.local_cert_chain_provision[index] != NULL) {
+     570                 :         25 :             slot_count++;
+     571                 :            :         }
+     572                 :            :     }
+     573                 :            : 
+     574                 :         16 :     return slot_count;
+     575                 :            : }
+     576                 :            : 
+     577                 :            : #if LIBSPDM_CERT_PARSE_SUPPORT
+     578                 :            : /**
+     579                 :            :  * This function verifies the integrity of peer certificate chain buffer including
+     580                 :            :  * spdm_cert_chain_t header.
+     581                 :            :  *
+     582                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     583                 :            :  * @param  cert_chain_buffer              Certificate chain buffer including spdm_cert_chain_t header.
+     584                 :            :  * @param  cert_chain_buffer_size          size in bytes of the certificate chain buffer.
+     585                 :            :  *
+     586                 :            :  * @retval true  Peer certificate chain buffer integrity verification passed.
+     587                 :            :  * @retval false Peer certificate chain buffer integrity verification failed.
+     588                 :            :  **/
+     589                 :         34 : bool libspdm_verify_peer_cert_chain_buffer_integrity(libspdm_context_t *spdm_context,
+     590                 :            :                                                      const void *cert_chain_buffer,
+     591                 :            :                                                      size_t cert_chain_buffer_size)
+     592                 :            : {
+     593                 :            :     bool result;
+     594                 :            :     bool is_device_cert_model;
+     595                 :            :     bool is_requester;
+     596                 :            : 
+     597                 :         34 :     is_requester = spdm_context->local_context.is_requester;
+     598                 :            : 
+     599                 :         34 :     is_device_cert_model = false;
+     600                 :            :     /* Responder does not determine Requester's certificate model */
+     601         [ +  - ]:         34 :     if (is_requester) {
+     602         [ +  + ]:         34 :         if((spdm_context->connection_info.capability.flags &
+     603                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ALIAS_CERT_CAP) == 0) {
+     604                 :         31 :             is_device_cert_model = true;
+     605                 :            :         }
+     606                 :            :     }
+     607                 :            : 
+     608         [ +  - ]:         34 :     if (is_requester) {
+     609                 :         34 :         result = libspdm_verify_certificate_chain_buffer(
+     610                 :            :             spdm_context->connection_info.algorithm.base_hash_algo,
+     611                 :            :             spdm_context->connection_info.algorithm.base_asym_algo,
+     612                 :            :             cert_chain_buffer, cert_chain_buffer_size,
+     613                 :            :             false, is_device_cert_model);
+     614                 :            :     } else {
+     615                 :          0 :         result = libspdm_verify_certificate_chain_buffer(
+     616                 :            :             spdm_context->connection_info.algorithm.base_hash_algo,
+     617                 :          0 :             spdm_context->connection_info.algorithm.req_base_asym_alg,
+     618                 :            :             cert_chain_buffer, cert_chain_buffer_size,
+     619                 :            :             true, is_device_cert_model);
+     620                 :            :     }
+     621                 :            : 
+     622                 :         34 :     return result;
+     623                 :            : }
+     624                 :            : 
+     625                 :            : /**
+     626                 :            :  * This function verifies peer certificate chain authority.
+     627                 :            :  *
+     628                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     629                 :            :  * @param  cert_chain_buffer              Certificate chain buffer including spdm_cert_chain_t header.
+     630                 :            :  * @param  cert_chain_buffer_size          size in bytes of the certificate chain buffer.
+     631                 :            :  * @param  trust_anchor                  A buffer to hold the trust_anchor which is used to validate the peer certificate, if not NULL.
+     632                 :            :  * @param  trust_anchor_size             A buffer to hold the trust_anchor_size, if not NULL.
+     633                 :            :  *
+     634                 :            :  * @retval true  Peer certificate chain buffer authority verification passed.
+     635                 :            :  *               Or there is no root_cert in local_context.
+     636                 :            :  * @retval false Peer certificate chain buffer authority verification failed.
+     637                 :            :  **/
+     638                 :         29 : bool libspdm_verify_peer_cert_chain_buffer_authority(libspdm_context_t *spdm_context,
+     639                 :            :                                                      const void *cert_chain_buffer,
+     640                 :            :                                                      size_t cert_chain_buffer_size,
+     641                 :            :                                                      const void **trust_anchor,
+     642                 :            :                                                      size_t *trust_anchor_size)
+     643                 :            : {
+     644                 :            :     const uint8_t *root_cert;
+     645                 :            :     size_t root_cert_size;
+     646                 :            :     uint8_t root_cert_index;
+     647                 :            :     size_t root_cert_hash_size;
+     648                 :            :     uint8_t root_cert_hash[LIBSPDM_MAX_HASH_SIZE];
+     649                 :            :     const uint8_t *received_root_cert;
+     650                 :            :     size_t received_root_cert_size;
+     651                 :            :     bool result;
+     652                 :            : 
+     653                 :         29 :     root_cert_index = 0;
+     654                 :         29 :     root_cert = spdm_context->local_context.peer_root_cert_provision[root_cert_index];
+     655                 :         29 :     root_cert_size = spdm_context->local_context.peer_root_cert_provision_size[root_cert_index];
+     656                 :            : 
+     657                 :         29 :     root_cert_hash_size = libspdm_get_hash_size(
+     658                 :            :         spdm_context->connection_info.algorithm.base_hash_algo);
+     659                 :            : 
+     660   [ +  +  +  - ]:         29 :     if ((root_cert != NULL) && (root_cert_size != 0)) {
+     661   [ +  -  +  - ]:         60 :         while ((root_cert != NULL) && (root_cert_size != 0)) {
+     662                 :         60 :             result = libspdm_hash_all(
+     663                 :            :                 spdm_context->connection_info.algorithm.base_hash_algo,
+     664                 :            :                 root_cert, root_cert_size, root_cert_hash);
+     665         [ -  + ]:         60 :             if (!result) {
+     666                 :          0 :                 LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR,
+     667                 :            :                                "!!! verify_peer_cert_chain_buffer - FAIL (hash calculation) !!!\n"));
+     668                 :          0 :                 return false;
+     669                 :            :             }
+     670                 :            : 
+     671         [ +  + ]:         60 :             if (libspdm_consttime_is_mem_equal((const uint8_t *)cert_chain_buffer +
+     672                 :            :                                                sizeof(spdm_cert_chain_t),
+     673                 :            :                                                root_cert_hash, root_cert_hash_size)) {
+     674                 :         21 :                 break;
+     675                 :            :             }
+     676                 :            : 
+     677                 :            :             #if (LIBSPDM_MAX_ROOT_CERT_SUPPORT) > 1
+     678         [ +  + ]:         39 :             if ((root_cert_index < ((LIBSPDM_MAX_ROOT_CERT_SUPPORT) -1)) &&
+     679         [ +  + ]:         38 :                 (spdm_context->local_context.peer_root_cert_provision[root_cert_index + 1] !=
+     680                 :            :                  NULL)) {
+     681                 :         34 :                 root_cert_index++;
+     682                 :         34 :                 root_cert = spdm_context->local_context.peer_root_cert_provision[root_cert_index];
+     683                 :         34 :                 root_cert_size =
+     684                 :         34 :                     spdm_context->local_context.peer_root_cert_provision_size[root_cert_index];
+     685                 :            :             } else
+     686                 :            :             #endif /* LIBSPDM_MAX_ROOT_CERT_SUPPORT */
+     687                 :            :             {
+     688                 :          5 :                 LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR,
+     689                 :            :                                "!!! verify_peer_cert_chain_buffer - "
+     690                 :            :                                "FAIL (all root cert hash mismatch) !!!\n"));
+     691                 :          5 :                 return false;
+     692                 :            :             }
+     693                 :            :         }
+     694                 :            : 
+     695                 :         21 :         result = libspdm_x509_get_cert_from_cert_chain(
+     696                 :         21 :             (const uint8_t *)cert_chain_buffer + sizeof(spdm_cert_chain_t) + root_cert_hash_size,
+     697                 :         21 :             cert_chain_buffer_size - sizeof(spdm_cert_chain_t) - root_cert_hash_size,
+     698                 :            :             0, &received_root_cert, &received_root_cert_size);
+     699         [ -  + ]:         21 :         if (!result) {
+     700                 :          0 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR,
+     701                 :            :                            "!!! verify_peer_cert_chain_buffer - FAIL (cert retrieval fail) !!!\n"));
+     702                 :          0 :             return false;
+     703                 :            :         }
+     704         [ +  + ]:         21 :         if (libspdm_is_root_certificate(received_root_cert, received_root_cert_size)) {
+     705         [ +  - ]:         20 :             if ((root_cert != NULL) &&
+     706         [ -  + ]:         20 :                 !libspdm_consttime_is_mem_equal(received_root_cert, root_cert, root_cert_size)) {
+     707                 :          0 :                 LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR,
+     708                 :            :                                "!!! verify_peer_cert_chain_buffer - "
+     709                 :            :                                "FAIL (root cert mismatch) !!!\n"));
+     710                 :          0 :                 return false;
+     711                 :            :             }
+     712                 :            :         } else {
+     713         [ -  + ]:          1 :             if (!libspdm_x509_verify_cert(received_root_cert, received_root_cert_size,
+     714                 :            :                                           root_cert, root_cert_size)) {
+     715                 :          0 :                 LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR,
+     716                 :            :                                "!!! verify_peer_cert_chain_buffer - "
+     717                 :            :                                "FAIL (received root cert verify failed)!!!\n"));
+     718                 :          0 :                 return false;
+     719                 :            :             }
+     720                 :            :         }
+     721         [ +  + ]:         21 :         if (trust_anchor != NULL) {
+     722                 :          5 :             *trust_anchor = root_cert;
+     723                 :            :         }
+     724         [ +  + ]:         21 :         if (trust_anchor_size != NULL) {
+     725                 :          5 :             *trust_anchor_size = root_cert_size;
+     726                 :            :         }
+     727                 :            :     }
+     728                 :            :     /*
+     729                 :            :      * When there is no root_cert in local_context, the return is true too.
+     730                 :            :      * No root_cert means the caller wants to verify the trust anchor of the cert chain.
+     731                 :            :      */
+     732                 :         24 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "!!! verify_peer_cert_chain_buffer - PASS !!!\n"));
+     733                 :            : 
+     734                 :         24 :     return true;
+     735                 :            : }
+     736                 :            : #endif
+     737                 :            : 
+     738                 :            : /**
+     739                 :            :  * This function generates the challenge signature based upon m1m2 for authentication.
+     740                 :            :  *
+     741                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     742                 :            :  * @param  is_requester                  Indicate of the signature generation for a requester or a responder.
+     743                 :            :  * @param  signature                    The buffer to store the challenge signature.
+     744                 :            :  *
+     745                 :            :  * @retval true  challenge signature is generated.
+     746                 :            :  * @retval false challenge signature is not generated.
+     747                 :            :  **/
+     748                 :         12 : bool libspdm_generate_challenge_auth_signature(libspdm_context_t *spdm_context,
+     749                 :            :                                                bool is_requester,
+     750                 :            :                                                uint8_t *signature)
+     751                 :            : {
+     752                 :            :     bool result;
+     753                 :            :     size_t signature_size;
+     754                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     755                 :            :     libspdm_m1m2_managed_buffer_t m1m2;
+     756                 :            :     uint8_t *m1m2_buffer;
+     757                 :            :     size_t m1m2_buffer_size;
+     758                 :            : #else
+     759                 :            :     uint8_t m1m2_hash[LIBSPDM_MAX_HASH_SIZE];
+     760                 :            :     size_t m1m2_hash_size;
+     761                 :            : #endif
+     762                 :            : 
+     763                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     764                 :            :     result = libspdm_calculate_m1m2(spdm_context, is_requester, &m1m2);
+     765                 :            :     m1m2_buffer = libspdm_get_managed_buffer(&m1m2);
+     766                 :            :     m1m2_buffer_size = libspdm_get_managed_buffer_size(&m1m2);
+     767                 :            : #else
+     768                 :         12 :     m1m2_hash_size = sizeof(m1m2_hash);
+     769                 :         12 :     result = libspdm_calculate_m1m2_hash(spdm_context, is_requester, &m1m2_hash_size, &m1m2_hash);
+     770                 :            : #endif
+     771         [ +  + ]:         12 :     if (is_requester) {
+     772                 :          3 :         libspdm_reset_message_mut_b(spdm_context);
+     773                 :          3 :         libspdm_reset_message_mut_c(spdm_context);
+     774                 :            :     } else {
+     775                 :          9 :         libspdm_reset_message_b(spdm_context);
+     776                 :          9 :         libspdm_reset_message_c(spdm_context);
+     777                 :            :     }
+     778         [ -  + ]:         12 :     if (!result) {
+     779                 :          0 :         return false;
+     780                 :            :     }
+     781                 :            : 
+     782         [ +  + ]:         12 :     if (is_requester) {
+     783                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP
+     784                 :          6 :         signature_size = libspdm_get_req_asym_signature_size(
+     785                 :          3 :             spdm_context->connection_info.algorithm.req_base_asym_alg);
+     786                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     787                 :            :         result = libspdm_requester_data_sign(
+     788                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+     789                 :            :             spdm_context,
+     790                 :            : #endif
+     791                 :            :             spdm_context->connection_info.version, SPDM_CHALLENGE_AUTH,
+     792                 :            :             spdm_context->connection_info.algorithm.req_base_asym_alg,
+     793                 :            :             spdm_context->connection_info.algorithm.base_hash_algo,
+     794                 :            :             false, m1m2_buffer, m1m2_buffer_size, signature, &signature_size);
+     795                 :            : #else
+     796                 :          3 :         result = libspdm_requester_data_sign(
+     797                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+     798                 :            :             spdm_context,
+     799                 :            : #endif
+     800                 :          3 :             spdm_context->connection_info.version, SPDM_CHALLENGE_AUTH,
+     801                 :          3 :             spdm_context->connection_info.algorithm.req_base_asym_alg,
+     802                 :            :             spdm_context->connection_info.algorithm.base_hash_algo,
+     803                 :            :             true, m1m2_hash, m1m2_hash_size, signature, &signature_size);
+     804                 :            : #endif
+     805                 :            : #else /* LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP */
+     806                 :            :         result = false;
+     807                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP */
+     808                 :            :     } else {
+     809                 :          9 :         signature_size = libspdm_get_asym_signature_size(
+     810                 :            :             spdm_context->connection_info.algorithm.base_asym_algo);
+     811                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     812                 :            :         result = libspdm_responder_data_sign(
+     813                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+     814                 :            :             spdm_context,
+     815                 :            : #endif
+     816                 :            :             spdm_context->connection_info.version, SPDM_CHALLENGE_AUTH,
+     817                 :            :             spdm_context->connection_info.algorithm.base_asym_algo,
+     818                 :            :             spdm_context->connection_info.algorithm.base_hash_algo,
+     819                 :            :             false, m1m2_buffer, m1m2_buffer_size, signature,
+     820                 :            :             &signature_size);
+     821                 :            : #else
+     822                 :          9 :         result = libspdm_responder_data_sign(
+     823                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+     824                 :            :             spdm_context,
+     825                 :            : #endif
+     826                 :          9 :             spdm_context->connection_info.version, SPDM_CHALLENGE_AUTH,
+     827                 :            :             spdm_context->connection_info.algorithm.base_asym_algo,
+     828                 :            :             spdm_context->connection_info.algorithm.base_hash_algo,
+     829                 :            :             true, m1m2_hash, m1m2_hash_size, signature,
+     830                 :            :             &signature_size);
+     831                 :            : #endif
+     832                 :            :     }
+     833                 :            : 
+     834                 :         12 :     return result;
+     835                 :            : }
+     836                 :            : 
+     837                 :            : /**
+     838                 :            :  * This function verifies the certificate chain hash.
+     839                 :            :  *
+     840                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     841                 :            :  * @param  certificate_chain_hash         The certificate chain hash data buffer.
+     842                 :            :  * @param  certificate_chain_hash_size     size in bytes of the certificate chain hash data buffer.
+     843                 :            :  *
+     844                 :            :  * @retval true  hash verification pass.
+     845                 :            :  * @retval false hash verification fail.
+     846                 :            :  **/
+     847                 :         19 : bool libspdm_verify_certificate_chain_hash(libspdm_context_t *spdm_context,
+     848                 :            :                                            const void *certificate_chain_hash,
+     849                 :            :                                            size_t certificate_chain_hash_size)
+     850                 :            : {
+     851                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     852                 :            :     size_t hash_size;
+     853                 :            :     uint8_t cert_chain_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+     854                 :            :     const uint8_t *cert_chain_buffer;
+     855                 :            :     size_t cert_chain_buffer_size;
+     856                 :            :     bool result;
+     857                 :            : #else
+     858                 :            :     uint8_t slot_id;
+     859                 :            : #endif
+     860                 :            : 
+     861                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     862                 :            :     result = libspdm_get_peer_cert_chain_buffer(spdm_context,
+     863                 :            :                                                 (const void **)&cert_chain_buffer,
+     864                 :            :                                                 &cert_chain_buffer_size);
+     865                 :            :     if (!result) {
+     866                 :            :         return false;
+     867                 :            :     }
+     868                 :            : 
+     869                 :            :     hash_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+     870                 :            : 
+     871                 :            :     result = libspdm_hash_all(spdm_context->connection_info.algorithm.base_hash_algo,
+     872                 :            :                               cert_chain_buffer, cert_chain_buffer_size,
+     873                 :            :                               cert_chain_buffer_hash);
+     874                 :            :     if (!result) {
+     875                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR,
+     876                 :            :                        "!!! verify_certificate_chain_hash - FAIL (hash calculation) !!!\n"));
+     877                 :            :         return false;
+     878                 :            :     }
+     879                 :            : 
+     880                 :            :     if (hash_size != certificate_chain_hash_size) {
+     881                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR, "!!! verify_certificate_chain_hash - FAIL !!!\n"));
+     882                 :            :         return false;
+     883                 :            :     }
+     884                 :            :     if (!libspdm_consttime_is_mem_equal(certificate_chain_hash, cert_chain_buffer_hash,
+     885                 :            :                                         certificate_chain_hash_size)) {
+     886                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR, "!!! verify_certificate_chain_hash - FAIL !!!\n"));
+     887                 :            :         return false;
+     888                 :            :     }
+     889                 :            : #else
+     890                 :         19 :     slot_id = spdm_context->connection_info.peer_used_cert_chain_slot_id;
+     891         [ -  + ]:         19 :     LIBSPDM_ASSERT(slot_id < SPDM_MAX_SLOT_COUNT);
+     892                 :            : 
+     893         [ -  + ]:         19 :     LIBSPDM_ASSERT(
+     894                 :            :         spdm_context->connection_info.peer_used_cert_chain[slot_id].buffer_hash_size != 0);
+     895                 :            : 
+     896         [ -  + ]:         19 :     if (spdm_context->connection_info.peer_used_cert_chain[slot_id].buffer_hash_size !=
+     897                 :            :         certificate_chain_hash_size) {
+     898                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR, "!!! verify_certificate_chain_hash - FAIL !!!\n"));
+     899                 :          0 :         return false;
+     900                 :            :     }
+     901                 :            : 
+     902         [ -  + ]:         19 :     if (!libspdm_consttime_is_mem_equal(certificate_chain_hash,
+     903                 :         19 :                                         spdm_context->connection_info.peer_used_cert_chain[slot_id].
+     904                 :            :                                         buffer_hash, certificate_chain_hash_size)) {
+     905                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR, "!!! verify_certificate_chain_hash - FAIL !!!\n"));
+     906                 :          0 :         return false;
+     907                 :            :     }
+     908                 :            : #endif
+     909                 :         19 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "!!! verify_certificate_chain_hash - PASS !!!\n"));
+     910                 :         19 :     return true;
+     911                 :            : }
+     912                 :            : 
+     913                 :            : /**
+     914                 :            :  * This function verifies the public key hash.
+     915                 :            :  *
+     916                 :            :  * @param  spdm_context            A pointer to the SPDM context.
+     917                 :            :  * @param  public_key_hash         The public key hash data buffer.
+     918                 :            :  * @param  public_key_hash_size    size in bytes of the public key hash data buffer.
+     919                 :            :  *
+     920                 :            :  * @retval true  hash verification pass.
+     921                 :            :  * @retval false hash verification fail.
+     922                 :            :  **/
+     923                 :          2 : bool libspdm_verify_public_key_hash(libspdm_context_t *spdm_context,
+     924                 :            :                                     const void *public_key_hash,
+     925                 :            :                                     size_t public_key_hash_size)
+     926                 :            : {
+     927                 :            :     size_t hash_size;
+     928                 :            :     uint8_t public_key_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+     929                 :            :     bool result;
+     930                 :            : 
+     931                 :          2 :     hash_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+     932                 :            : 
+     933                 :          2 :     result = libspdm_hash_all(spdm_context->connection_info.algorithm.base_hash_algo,
+     934                 :            :                               spdm_context->local_context.peer_public_key_provision,
+     935                 :            :                               spdm_context->local_context.peer_public_key_provision_size,
+     936                 :            :                               public_key_buffer_hash);
+     937         [ -  + ]:          2 :     if (!result) {
+     938                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR,
+     939                 :            :                        "!!! verify_public_key_hash - FAIL (hash calculation) !!!\n"));
+     940                 :          0 :         return false;
+     941                 :            :     }
+     942                 :            : 
+     943         [ -  + ]:          2 :     if (hash_size != public_key_hash_size) {
+     944                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR, "!!! verify_public_key_hash - FAIL !!!\n"));
+     945                 :          0 :         return false;
+     946                 :            :     }
+     947         [ -  + ]:          2 :     if (!libspdm_consttime_is_mem_equal(public_key_hash, public_key_buffer_hash,
+     948                 :            :                                         public_key_hash_size)) {
+     949                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR, "!!! verify_public_key_hash - FAIL !!!\n"));
+     950                 :          0 :         return false;
+     951                 :            :     }
+     952                 :            : 
+     953                 :          2 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "!!! verify_public_key_hash - PASS !!!\n"));
+     954                 :          2 :     return true;
+     955                 :            : }
+     956                 :            : 
+     957                 :            : /**
+     958                 :            :  * This function verifies the challenge signature based upon m1m2.
+     959                 :            :  *
+     960                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     961                 :            :  * @param  is_requester                  Indicate of the signature verification for a requester or a responder.
+     962                 :            :  * @param  sign_data                     The signature data buffer.
+     963                 :            :  * @param  sign_data_size                 size in bytes of the signature data buffer.
+     964                 :            :  *
+     965                 :            :  * @retval true  signature verification pass.
+     966                 :            :  * @retval false signature verification fail.
+     967                 :            :  **/
+     968                 :         19 : bool libspdm_verify_challenge_auth_signature(libspdm_context_t *spdm_context,
+     969                 :            :                                              bool is_requester,
+     970                 :            :                                              const void *sign_data,
+     971                 :            :                                              size_t sign_data_size)
+     972                 :            : {
+     973                 :            :     bool result;
+     974                 :            :     void *context;
+     975                 :            :     uint8_t slot_id;
+     976                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     977                 :            :     libspdm_m1m2_managed_buffer_t m1m2;
+     978                 :            :     uint8_t *m1m2_buffer;
+     979                 :            :     size_t m1m2_buffer_size;
+     980                 :            :     const uint8_t *cert_buffer;
+     981                 :            :     size_t cert_buffer_size;
+     982                 :            :     const uint8_t *cert_chain_data;
+     983                 :            :     size_t cert_chain_data_size;
+     984                 :            : #else
+     985                 :            :     uint8_t m1m2_hash[LIBSPDM_MAX_HASH_SIZE];
+     986                 :            :     size_t m1m2_hash_size;
+     987                 :            : #endif
+     988                 :            : 
+     989                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     990                 :            :     result = libspdm_calculate_m1m2(spdm_context, !is_requester, &m1m2);
+     991                 :            :     m1m2_buffer = libspdm_get_managed_buffer(&m1m2);
+     992                 :            :     m1m2_buffer_size = libspdm_get_managed_buffer_size(&m1m2);
+     993                 :            : #else
+     994                 :         19 :     m1m2_hash_size = sizeof(m1m2_hash);
+     995                 :         19 :     result = libspdm_calculate_m1m2_hash(spdm_context, !is_requester, &m1m2_hash_size, &m1m2_hash);
+     996                 :            : #endif
+     997         [ +  + ]:         19 :     if (is_requester) {
+     998                 :         16 :         libspdm_reset_message_b(spdm_context);
+     999                 :         16 :         libspdm_reset_message_c(spdm_context);
+    1000                 :            :     } else {
+    1001                 :          3 :         libspdm_reset_message_mut_b(spdm_context);
+    1002                 :          3 :         libspdm_reset_message_mut_c(spdm_context);
+    1003                 :            :     }
+    1004         [ -  + ]:         19 :     if (!result) {
+    1005                 :          0 :         return false;
+    1006                 :            :     }
+    1007                 :            : 
+    1008                 :         19 :     slot_id = spdm_context->connection_info.peer_used_cert_chain_slot_id;
+    1009   [ +  +  -  + ]:         19 :     LIBSPDM_ASSERT((slot_id < SPDM_MAX_SLOT_COUNT) || (slot_id == 0xFF));
+    1010                 :            : 
+    1011         [ +  + ]:         19 :     if (slot_id == 0xFF) {
+    1012         [ +  + ]:          2 :         if (is_requester) {
+    1013                 :          1 :             result = libspdm_asym_get_public_key_from_der(
+    1014                 :            :                 spdm_context->connection_info.algorithm.base_asym_algo,
+    1015                 :          1 :                 spdm_context->local_context.peer_public_key_provision,
+    1016                 :            :                 spdm_context->local_context.peer_public_key_provision_size,
+    1017                 :            :                 &context);
+    1018                 :            :         } else {
+    1019                 :          1 :             result = libspdm_req_asym_get_public_key_from_der(
+    1020                 :          1 :                 spdm_context->connection_info.algorithm.req_base_asym_alg,
+    1021                 :          1 :                 spdm_context->local_context.peer_public_key_provision,
+    1022                 :            :                 spdm_context->local_context.peer_public_key_provision_size,
+    1023                 :            :                 &context);
+    1024                 :            :         }
+    1025         [ -  + ]:          2 :         if (!result) {
+    1026                 :          0 :             return false;
+    1027                 :            :         }
+    1028                 :            :     } else {
+    1029                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1030                 :            :         result = libspdm_get_peer_cert_chain_data(
+    1031                 :            :             spdm_context, (const void **)&cert_chain_data, &cert_chain_data_size);
+    1032                 :            :         if (!result) {
+    1033                 :            :             return false;
+    1034                 :            :         }
+    1035                 :            : 
+    1036                 :            :         /* Get leaf cert from cert chain*/
+    1037                 :            :         result = libspdm_x509_get_cert_from_cert_chain(
+    1038                 :            :             cert_chain_data, cert_chain_data_size, -1, &cert_buffer, &cert_buffer_size);
+    1039                 :            :         if (!result) {
+    1040                 :            :             return false;
+    1041                 :            :         }
+    1042                 :            : 
+    1043                 :            :         if (is_requester) {
+    1044                 :            :             result = libspdm_asym_get_public_key_from_x509(
+    1045                 :            :                 spdm_context->connection_info.algorithm.base_asym_algo,
+    1046                 :            :                 cert_buffer, cert_buffer_size, &context);
+    1047                 :            :         } else {
+    1048                 :            :             result = libspdm_req_asym_get_public_key_from_x509(
+    1049                 :            :                 spdm_context->connection_info.algorithm.req_base_asym_alg,
+    1050                 :            :                 cert_buffer, cert_buffer_size, &context);
+    1051                 :            :         }
+    1052                 :            :         if (!result) {
+    1053                 :            :             return false;
+    1054                 :            :         }
+    1055                 :            : #else
+    1056                 :         17 :         context = spdm_context->connection_info.peer_used_cert_chain[slot_id].leaf_cert_public_key;
+    1057         [ -  + ]:         17 :         LIBSPDM_ASSERT(context != NULL);
+    1058                 :            : #endif
+    1059                 :            :     }
+    1060                 :            : 
+    1061         [ +  + ]:         19 :     if (is_requester) {
+    1062                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1063                 :            :         result = libspdm_asym_verify_ex(
+    1064                 :            :             spdm_context->connection_info.version, SPDM_CHALLENGE_AUTH,
+    1065                 :            :             spdm_context->connection_info.algorithm.base_asym_algo,
+    1066                 :            :             spdm_context->connection_info.algorithm.base_hash_algo,
+    1067                 :            :             context, m1m2_buffer, m1m2_buffer_size, sign_data, sign_data_size,
+    1068                 :            :             &spdm_context->spdm_10_11_verify_signature_endian);
+    1069                 :            :         libspdm_asym_free(
+    1070                 :            :             spdm_context->connection_info.algorithm.base_asym_algo, context);
+    1071                 :            : #else
+    1072                 :         16 :         result = libspdm_asym_verify_hash_ex(
+    1073                 :         16 :             spdm_context->connection_info.version, SPDM_CHALLENGE_AUTH,
+    1074                 :            :             spdm_context->connection_info.algorithm.base_asym_algo,
+    1075                 :            :             spdm_context->connection_info.algorithm.base_hash_algo,
+    1076                 :            :             context, m1m2_hash, m1m2_hash_size, sign_data, sign_data_size,
+    1077                 :            :             &spdm_context->spdm_10_11_verify_signature_endian);
+    1078         [ +  + ]:         16 :         if (slot_id == 0xFF) {
+    1079                 :          1 :             libspdm_asym_free(
+    1080                 :            :                 spdm_context->connection_info.algorithm.base_asym_algo, context);
+    1081                 :            :         }
+    1082                 :            : #endif
+    1083                 :            :     } else {
+    1084                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1085                 :            :         result = libspdm_req_asym_verify_ex(
+    1086                 :            :             spdm_context->connection_info.version, SPDM_CHALLENGE_AUTH,
+    1087                 :            :             spdm_context->connection_info.algorithm.req_base_asym_alg,
+    1088                 :            :             spdm_context->connection_info.algorithm.base_hash_algo,
+    1089                 :            :             context, m1m2_buffer, m1m2_buffer_size, sign_data, sign_data_size,
+    1090                 :            :             &spdm_context->spdm_10_11_verify_signature_endian);
+    1091                 :            :         libspdm_req_asym_free(
+    1092                 :            :             spdm_context->connection_info.algorithm.req_base_asym_alg, context);
+    1093                 :            : #else
+    1094                 :          3 :         result = libspdm_req_asym_verify_hash_ex(
+    1095                 :          3 :             spdm_context->connection_info.version, SPDM_CHALLENGE_AUTH,
+    1096                 :          3 :             spdm_context->connection_info.algorithm.req_base_asym_alg,
+    1097                 :            :             spdm_context->connection_info.algorithm.base_hash_algo,
+    1098                 :            :             context, m1m2_hash, m1m2_hash_size, sign_data, sign_data_size,
+    1099                 :            :             &spdm_context->spdm_10_11_verify_signature_endian);
+    1100         [ +  + ]:          3 :         if (slot_id == 0xFF) {
+    1101                 :          1 :             libspdm_req_asym_free(
+    1102                 :          1 :                 spdm_context->connection_info.algorithm.req_base_asym_alg, context);
+    1103                 :            :         }
+    1104                 :            : #endif
+    1105                 :            :     }
+    1106         [ +  + ]:         19 :     if (!result) {
+    1107                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR,
+    1108                 :            :                        "!!! verify_challenge_signature - FAIL !!!\n"));
+    1109                 :          1 :         return false;
+    1110                 :            :     }
+    1111                 :            : 
+    1112                 :         18 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "!!! verify_challenge_signature - PASS !!!\n"));
+    1113                 :            : 
+    1114                 :         18 :     return true;
+    1115                 :            : }
+    1116                 :            : 
+    1117                 :            : /**
+    1118                 :            :  * This function calculate the measurement summary hash size.
+    1119                 :            :  *
+    1120                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+    1121                 :            :  * @param  is_requester                  Is the function called from a requester.
+    1122                 :            :  * @param  measurement_summary_hash_type   The type of the measurement summary hash.
+    1123                 :            :  *
+    1124                 :            :  * @return 0 measurement summary hash type is invalid, NO_MEAS hash type or no MEAS capabilities.
+    1125                 :            :  * @return measurement summary hash size according to type.
+    1126                 :            :  **/
+    1127                 :            : uint32_t
+    1128                 :        103 : libspdm_get_measurement_summary_hash_size(libspdm_context_t *spdm_context,
+    1129                 :            :                                           bool is_requester,
+    1130                 :            :                                           uint8_t measurement_summary_hash_type)
+    1131                 :            : {
+    1132         [ +  + ]:        103 :     if (!libspdm_is_capabilities_flag_supported(
+    1133                 :            :             spdm_context, is_requester, 0,
+    1134                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP)) {
+    1135                 :         52 :         return 0;
+    1136                 :            :     }
+    1137                 :            : 
+    1138      [ +  +  + ]:         51 :     switch (measurement_summary_hash_type) {
+    1139                 :         25 :     case SPDM_REQUEST_NO_MEASUREMENT_SUMMARY_HASH:
+    1140                 :         25 :         return 0;
+    1141                 :            :         break;
+    1142                 :            : 
+    1143                 :         24 :     case SPDM_REQUEST_TCB_COMPONENT_MEASUREMENT_HASH:
+    1144                 :            :     case SPDM_REQUEST_ALL_MEASUREMENTS_HASH:
+    1145                 :         24 :         return libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    1146                 :            :         break;
+    1147                 :          2 :     default:
+    1148                 :          2 :         return 0;
+    1149                 :            :         break;
+    1150                 :            :     }
+    1151                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_common_lib/libspdm_com_crypto_service_session.c.func-sort-c.html b/coverage_log/library/spdm_common_lib/libspdm_com_crypto_service_session.c.func-sort-c.html new file mode 100644 index 00000000000..48694a60dd1 --- /dev/null +++ b/coverage_log/library/spdm_common_lib/libspdm_com_crypto_service_session.c.func-sort-c.html @@ -0,0 +1,109 @@ + + + + + + + LCOV - coverage.info - library/spdm_common_lib/libspdm_com_crypto_service_session.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_common_lib - libspdm_com_crypto_service_session.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:10112680.2 %
Date:2024-09-22 08:21:07Functions:77100.0 %
Branches:275450.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_calculate_th_hmac_for_finish_rsp21
libspdm_calculate_th2_hash32
libspdm_calculate_th_hash_for_finish48
libspdm_calculate_th_hmac_for_exchange_rsp52
libspdm_calculate_th1_hash56
libspdm_calculate_th_hash_for_exchange88
libspdm_calculate_th_hmac_for_finish_req89
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_common_lib/libspdm_com_crypto_service_session.c.func.html b/coverage_log/library/spdm_common_lib/libspdm_com_crypto_service_session.c.func.html new file mode 100644 index 00000000000..f67a4c18790 --- /dev/null +++ b/coverage_log/library/spdm_common_lib/libspdm_com_crypto_service_session.c.func.html @@ -0,0 +1,109 @@ + + + + + + + LCOV - coverage.info - library/spdm_common_lib/libspdm_com_crypto_service_session.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_common_lib - libspdm_com_crypto_service_session.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:10112680.2 %
Date:2024-09-22 08:21:07Functions:77100.0 %
Branches:275450.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_calculate_th1_hash56
libspdm_calculate_th2_hash32
libspdm_calculate_th_hash_for_exchange88
libspdm_calculate_th_hash_for_finish48
libspdm_calculate_th_hmac_for_exchange_rsp52
libspdm_calculate_th_hmac_for_finish_req89
libspdm_calculate_th_hmac_for_finish_rsp21
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_common_lib/libspdm_com_crypto_service_session.c.gcov.html b/coverage_log/library/spdm_common_lib/libspdm_com_crypto_service_session.c.gcov.html new file mode 100644 index 00000000000..8c093325a3a --- /dev/null +++ b/coverage_log/library/spdm_common_lib/libspdm_com_crypto_service_session.c.gcov.html @@ -0,0 +1,829 @@ + + + + + + + LCOV - coverage.info - library/spdm_common_lib/libspdm_com_crypto_service_session.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_common_lib - libspdm_com_crypto_service_session.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:10112680.2 %
Date:2024-09-22 08:21:07Functions:77100.0 %
Branches:275450.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 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_secured_message_lib.h"
+       8                 :            : 
+       9                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+      10                 :            : /*
+      11                 :            :  * This function calculates current TH data with message A and message K.
+      12                 :            :  *
+      13                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+      14                 :            :  * @param  session_info                  The SPDM session ID.
+      15                 :            :  * @param  cert_chain_buffer                Certificate chain buffer with spdm_cert_chain_t header.
+      16                 :            :  * @param  cert_chain_buffer_size            size in bytes of the certificate chain buffer.
+      17                 :            :  * @param  th_data_buffer_size             size in bytes of the th_data_buffer
+      18                 :            :  * @param  th_data_buffer                 The buffer to store the th_data_buffer
+      19                 :            :  *
+      20                 :            :  * @retval RETURN_SUCCESS  current TH data is calculated.
+      21                 :            :  */
+      22                 :            : bool libspdm_calculate_th_for_exchange(
+      23                 :            :     libspdm_context_t *spdm_context, void *spdm_session_info, const uint8_t *cert_chain_buffer,
+      24                 :            :     size_t cert_chain_buffer_size,
+      25                 :            :     libspdm_th_managed_buffer_t *th_curr)
+      26                 :            : {
+      27                 :            :     libspdm_session_info_t *session_info;
+      28                 :            :     uint8_t cert_chain_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+      29                 :            :     uint32_t hash_size;
+      30                 :            :     libspdm_return_t status;
+      31                 :            :     bool result;
+      32                 :            : 
+      33                 :            :     session_info = spdm_session_info;
+      34                 :            : 
+      35                 :            :     hash_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+      36                 :            : 
+      37                 :            :     libspdm_init_managed_buffer(th_curr, sizeof(th_curr->buffer));
+      38                 :            : 
+      39                 :            :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "message_a data :\n"));
+      40                 :            :     LIBSPDM_INTERNAL_DUMP_HEX(
+      41                 :            :         libspdm_get_managed_buffer(&spdm_context->transcript.message_a),
+      42                 :            :         libspdm_get_managed_buffer_size(&spdm_context->transcript.message_a));
+      43                 :            :     status = libspdm_append_managed_buffer(
+      44                 :            :         th_curr,
+      45                 :            :         libspdm_get_managed_buffer(&spdm_context->transcript.message_a),
+      46                 :            :         libspdm_get_managed_buffer_size(&spdm_context->transcript.message_a));
+      47                 :            :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+      48                 :            :         return false;
+      49                 :            :     }
+      50                 :            : 
+      51                 :            :     if (cert_chain_buffer != NULL) {
+      52                 :            :         if (spdm_context->connection_info.multi_key_conn_rsp) {
+      53                 :            :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "message_d data :\n"));
+      54                 :            :             LIBSPDM_INTERNAL_DUMP_HEX(
+      55                 :            :                 libspdm_get_managed_buffer(&spdm_context->transcript.message_d),
+      56                 :            :                 libspdm_get_managed_buffer_size(&spdm_context->transcript.message_d));
+      57                 :            :             status = libspdm_append_managed_buffer(
+      58                 :            :                 th_curr,
+      59                 :            :                 libspdm_get_managed_buffer(&spdm_context->transcript.message_d),
+      60                 :            :                 libspdm_get_managed_buffer_size(&spdm_context->transcript.message_d));
+      61                 :            :             if (LIBSPDM_STATUS_IS_ERROR(status)) {
+      62                 :            :                 return false;
+      63                 :            :             }
+      64                 :            :         }
+      65                 :            : 
+      66                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "th_message_ct data :\n"));
+      67                 :            :         LIBSPDM_INTERNAL_DUMP_HEX(cert_chain_buffer, cert_chain_buffer_size);
+      68                 :            :         result = libspdm_hash_all(
+      69                 :            :             spdm_context->connection_info.algorithm.base_hash_algo,
+      70                 :            :             cert_chain_buffer, cert_chain_buffer_size,
+      71                 :            :             cert_chain_buffer_hash);
+      72                 :            :         if (!result) {
+      73                 :            :             return false;
+      74                 :            :         }
+      75                 :            :         status = libspdm_append_managed_buffer(th_curr, cert_chain_buffer_hash, hash_size);
+      76                 :            :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+      77                 :            :             return false;
+      78                 :            :         }
+      79                 :            :     }
+      80                 :            : 
+      81                 :            :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "message_k data :\n"));
+      82                 :            :     LIBSPDM_INTERNAL_DUMP_HEX(
+      83                 :            :         libspdm_get_managed_buffer(&session_info->session_transcript.message_k),
+      84                 :            :         libspdm_get_managed_buffer_size(&session_info->session_transcript.message_k));
+      85                 :            :     status = libspdm_append_managed_buffer(
+      86                 :            :         th_curr,
+      87                 :            :         libspdm_get_managed_buffer(&session_info->session_transcript.message_k),
+      88                 :            :         libspdm_get_managed_buffer_size(&session_info->session_transcript.message_k));
+      89                 :            :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+      90                 :            :         return false;
+      91                 :            :     }
+      92                 :            : 
+      93                 :            :     return true;
+      94                 :            : }
+      95                 :            : #else
+      96                 :            : /*
+      97                 :            :  * This function calculates current TH hash with message A and message K.
+      98                 :            :  *
+      99                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     100                 :            :  * @param  session_info                  The SPDM session ID.
+     101                 :            :  * @param  th_hash_buffer_size             size in bytes of the th_hash_buffer
+     102                 :            :  * @param  th_hash_buffer                 The buffer to store the th_hash_buffer
+     103                 :            :  *
+     104                 :            :  * @retval RETURN_SUCCESS  current TH hash is calculated.
+     105                 :            :  */
+     106                 :         88 : bool libspdm_calculate_th_hash_for_exchange(
+     107                 :            :     libspdm_context_t *spdm_context, void *spdm_session_info,
+     108                 :            :     size_t *th_hash_buffer_size, void *th_hash_buffer)
+     109                 :            : {
+     110                 :            :     libspdm_session_info_t *session_info;
+     111                 :            :     uint32_t hash_size;
+     112                 :            :     void *digest_context_th;
+     113                 :            :     bool result;
+     114                 :            : 
+     115                 :         88 :     session_info = spdm_session_info;
+     116                 :            : 
+     117                 :         88 :     hash_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+     118                 :            : 
+     119         [ -  + ]:         88 :     LIBSPDM_ASSERT(*th_hash_buffer_size >= hash_size);
+     120                 :            : 
+     121                 :            :     /* duplicate the th context, because we still need use original context to continue.*/
+     122                 :         88 :     digest_context_th = libspdm_hash_new (spdm_context->connection_info.algorithm.base_hash_algo);
+     123         [ -  + ]:         88 :     if (digest_context_th == NULL) {
+     124                 :          0 :         return false;
+     125                 :            :     }
+     126                 :         88 :     result = libspdm_hash_duplicate (spdm_context->connection_info.algorithm.base_hash_algo,
+     127                 :         88 :                                      session_info->session_transcript.digest_context_th,
+     128                 :            :                                      digest_context_th);
+     129         [ -  + ]:         88 :     if (!result) {
+     130                 :          0 :         libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
+     131                 :            :                            digest_context_th);
+     132                 :          0 :         return false;
+     133                 :            :     }
+     134                 :         88 :     result = libspdm_hash_final (spdm_context->connection_info.algorithm.base_hash_algo,
+     135                 :            :                                  digest_context_th, th_hash_buffer);
+     136                 :         88 :     libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo, digest_context_th);
+     137         [ -  + ]:         88 :     if (!result) {
+     138                 :          0 :         return false;
+     139                 :            :     }
+     140                 :            : 
+     141                 :         88 :     *th_hash_buffer_size = hash_size;
+     142                 :            : 
+     143                 :         88 :     return true;
+     144                 :            : }
+     145                 :            : 
+     146                 :            : /*
+     147                 :            :  * This function calculates current TH hmac with message A and message K, with response finished_key.
+     148                 :            :  *
+     149                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     150                 :            :  * @param  session_info                  The SPDM session ID.
+     151                 :            :  * @param  th_hmac_buffer_size             size in bytes of the th_hmac_buffer
+     152                 :            :  * @param  th_hmac_buffer                 The buffer to store the th_hmac_buffer
+     153                 :            :  *
+     154                 :            :  * @retval RETURN_SUCCESS  current TH hmac is calculated.
+     155                 :            :  */
+     156                 :         52 : bool libspdm_calculate_th_hmac_for_exchange_rsp(
+     157                 :            :     libspdm_context_t *spdm_context, void *spdm_session_info, bool is_requester,
+     158                 :            :     size_t *th_hmac_buffer_size, void *th_hmac_buffer)
+     159                 :            : {
+     160                 :            :     libspdm_session_info_t *session_info;
+     161                 :            :     void *secured_message_context;
+     162                 :            :     uint32_t hash_size;
+     163                 :            :     void *hash_context_th;
+     164                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     165                 :            :     bool result;
+     166                 :            : 
+     167                 :         52 :     session_info = spdm_session_info;
+     168                 :         52 :     secured_message_context = session_info->secured_message_context;
+     169                 :            : 
+     170                 :         52 :     hash_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+     171                 :            : 
+     172         [ -  + ]:         52 :     LIBSPDM_ASSERT(*th_hmac_buffer_size >= hash_size);
+     173                 :            : 
+     174                 :            :     /* duplicate the th context, because we still need use original context to continue.*/
+     175                 :         52 :     hash_context_th = libspdm_hash_new (spdm_context->connection_info.algorithm.base_hash_algo);
+     176         [ -  + ]:         52 :     if (hash_context_th == NULL) {
+     177                 :          0 :         return false;
+     178                 :            :     }
+     179                 :         52 :     result = libspdm_hash_duplicate (spdm_context->connection_info.algorithm.base_hash_algo,
+     180                 :         52 :                                      session_info->session_transcript.digest_context_th,
+     181                 :            :                                      hash_context_th);
+     182         [ -  + ]:         52 :     if (!result) {
+     183                 :          0 :         libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo, hash_context_th);
+     184                 :          0 :         return false;
+     185                 :            :     }
+     186                 :         52 :     result = libspdm_hash_final (spdm_context->connection_info.algorithm.base_hash_algo,
+     187                 :            :                                  hash_context_th, hash_data);
+     188                 :         52 :     libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo, hash_context_th);
+     189         [ -  + ]:         52 :     if (!result) {
+     190                 :          0 :         return false;
+     191                 :            :     }
+     192                 :            : 
+     193                 :         52 :     result = libspdm_hmac_all_with_response_finished_key (secured_message_context,
+     194                 :            :                                                           hash_data, hash_size, th_hmac_buffer);
+     195         [ -  + ]:         52 :     if (!result) {
+     196                 :          0 :         return false;
+     197                 :            :     }
+     198                 :         52 :     *th_hmac_buffer_size = hash_size;
+     199                 :            : 
+     200                 :         52 :     return true;
+     201                 :            : }
+     202                 :            : #endif
+     203                 :            : 
+     204                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     205                 :            : /*
+     206                 :            :  * This function calculates current TH data with message A, message K and message F.
+     207                 :            :  *
+     208                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     209                 :            :  * @param  session_info                  The SPDM session ID.
+     210                 :            :  * @param  cert_chain_buffer                Certificate chain buffer with spdm_cert_chain_t header.
+     211                 :            :  * @param  cert_chain_buffer_size            size in bytes of the certificate chain buffer.
+     212                 :            :  * @param  mut_cert_chain_buffer             Certificate chain buffer with spdm_cert_chain_t header in mutual authentication.
+     213                 :            :  * @param  mut_cert_chain_buffer_size         size in bytes of the certificate chain buffer in mutual authentication.
+     214                 :            :  * @param  th_data_buffer_size             size in bytes of the th_data_buffer
+     215                 :            :  * @param  th_data_buffer                 The buffer to store the th_data_buffer
+     216                 :            :  *
+     217                 :            :  * @retval RETURN_SUCCESS  current TH data is calculated.
+     218                 :            :  */
+     219                 :            : bool libspdm_calculate_th_for_finish(libspdm_context_t *spdm_context,
+     220                 :            :                                      void *spdm_session_info,
+     221                 :            :                                      const uint8_t *cert_chain_buffer,
+     222                 :            :                                      size_t cert_chain_buffer_size,
+     223                 :            :                                      const uint8_t *mut_cert_chain_buffer,
+     224                 :            :                                      size_t mut_cert_chain_buffer_size,
+     225                 :            :                                      libspdm_th_managed_buffer_t *th_curr)
+     226                 :            : {
+     227                 :            :     libspdm_session_info_t *session_info;
+     228                 :            :     uint8_t cert_chain_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+     229                 :            :     uint8_t mut_cert_chain_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+     230                 :            :     uint32_t hash_size;
+     231                 :            :     libspdm_return_t status;
+     232                 :            :     bool result;
+     233                 :            : 
+     234                 :            :     session_info = spdm_session_info;
+     235                 :            : 
+     236                 :            :     hash_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+     237                 :            : 
+     238                 :            :     libspdm_init_managed_buffer(th_curr, sizeof(th_curr->buffer));
+     239                 :            : 
+     240                 :            :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "message_a data :\n"));
+     241                 :            :     LIBSPDM_INTERNAL_DUMP_HEX(
+     242                 :            :         libspdm_get_managed_buffer(&spdm_context->transcript.message_a),
+     243                 :            :         libspdm_get_managed_buffer_size(&spdm_context->transcript.message_a));
+     244                 :            :     status = libspdm_append_managed_buffer(
+     245                 :            :         th_curr,
+     246                 :            :         libspdm_get_managed_buffer(&spdm_context->transcript.message_a),
+     247                 :            :         libspdm_get_managed_buffer_size(&spdm_context->transcript.message_a));
+     248                 :            :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     249                 :            :         return false;
+     250                 :            :     }
+     251                 :            : 
+     252                 :            :     if (cert_chain_buffer != NULL) {
+     253                 :            :         if (spdm_context->connection_info.multi_key_conn_rsp) {
+     254                 :            :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "message_d data :\n"));
+     255                 :            :             LIBSPDM_INTERNAL_DUMP_HEX(
+     256                 :            :                 libspdm_get_managed_buffer(&spdm_context->transcript.message_d),
+     257                 :            :                 libspdm_get_managed_buffer_size(&spdm_context->transcript.message_d));
+     258                 :            :             status = libspdm_append_managed_buffer(
+     259                 :            :                 th_curr,
+     260                 :            :                 libspdm_get_managed_buffer(&spdm_context->transcript.message_d),
+     261                 :            :                 libspdm_get_managed_buffer_size(&spdm_context->transcript.message_d));
+     262                 :            :             if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     263                 :            :                 return false;
+     264                 :            :             }
+     265                 :            :         }
+     266                 :            : 
+     267                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "th_message_ct data :\n"));
+     268                 :            :         LIBSPDM_INTERNAL_DUMP_HEX(cert_chain_buffer, cert_chain_buffer_size);
+     269                 :            :         result = libspdm_hash_all(
+     270                 :            :             spdm_context->connection_info.algorithm.base_hash_algo,
+     271                 :            :             cert_chain_buffer, cert_chain_buffer_size,
+     272                 :            :             cert_chain_buffer_hash);
+     273                 :            :         if (!result) {
+     274                 :            :             return false;
+     275                 :            :         }
+     276                 :            :         status = libspdm_append_managed_buffer(th_curr, cert_chain_buffer_hash, hash_size);
+     277                 :            :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     278                 :            :             return false;
+     279                 :            :         }
+     280                 :            :     }
+     281                 :            : 
+     282                 :            :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "message_k data :\n"));
+     283                 :            :     LIBSPDM_INTERNAL_DUMP_HEX(
+     284                 :            :         libspdm_get_managed_buffer(&session_info->session_transcript.message_k),
+     285                 :            :         libspdm_get_managed_buffer_size(&session_info->session_transcript.message_k));
+     286                 :            :     status = libspdm_append_managed_buffer(
+     287                 :            :         th_curr,
+     288                 :            :         libspdm_get_managed_buffer(&session_info->session_transcript.message_k),
+     289                 :            :         libspdm_get_managed_buffer_size(&session_info->session_transcript.message_k));
+     290                 :            :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     291                 :            :         return false;
+     292                 :            :     }
+     293                 :            : 
+     294                 :            :     if (mut_cert_chain_buffer != NULL) {
+     295                 :            :         if (spdm_context->connection_info.multi_key_conn_req) {
+     296                 :            :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "message_encap_d data :\n"));
+     297                 :            :             LIBSPDM_INTERNAL_DUMP_HEX(
+     298                 :            :                 libspdm_get_managed_buffer(&session_info->session_transcript.message_encap_d),
+     299                 :            :                 libspdm_get_managed_buffer_size(&session_info->session_transcript.message_encap_d));
+     300                 :            :             status = libspdm_append_managed_buffer(
+     301                 :            :                 th_curr,
+     302                 :            :                 libspdm_get_managed_buffer(&session_info->session_transcript.message_encap_d),
+     303                 :            :                 libspdm_get_managed_buffer_size(&session_info->session_transcript.message_encap_d));
+     304                 :            :             if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     305                 :            :                 return false;
+     306                 :            :             }
+     307                 :            :         }
+     308                 :            : 
+     309                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "th_message_cm data :\n"));
+     310                 :            :         LIBSPDM_INTERNAL_DUMP_HEX(mut_cert_chain_buffer, mut_cert_chain_buffer_size);
+     311                 :            :         result = libspdm_hash_all(
+     312                 :            :             spdm_context->connection_info.algorithm.base_hash_algo,
+     313                 :            :             mut_cert_chain_buffer, mut_cert_chain_buffer_size,
+     314                 :            :             mut_cert_chain_buffer_hash);
+     315                 :            :         if (!result) {
+     316                 :            :             return false;
+     317                 :            :         }
+     318                 :            :         status = libspdm_append_managed_buffer(th_curr, mut_cert_chain_buffer_hash, hash_size);
+     319                 :            :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     320                 :            :             return false;
+     321                 :            :         }
+     322                 :            :     }
+     323                 :            : 
+     324                 :            :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "message_f data :\n"));
+     325                 :            :     LIBSPDM_INTERNAL_DUMP_HEX(
+     326                 :            :         libspdm_get_managed_buffer(&session_info->session_transcript.message_f),
+     327                 :            :         libspdm_get_managed_buffer_size(&session_info->session_transcript.message_f));
+     328                 :            :     status = libspdm_append_managed_buffer(
+     329                 :            :         th_curr,
+     330                 :            :         libspdm_get_managed_buffer(&session_info->session_transcript.message_f),
+     331                 :            :         libspdm_get_managed_buffer_size(&session_info->session_transcript.message_f));
+     332                 :            :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     333                 :            :         return false;
+     334                 :            :     }
+     335                 :            : 
+     336                 :            :     return true;
+     337                 :            : }
+     338                 :            : #else
+     339                 :            : /*
+     340                 :            :  * This function calculates current TH hash with message A, message K and message F.
+     341                 :            :  *
+     342                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     343                 :            :  * @param  session_info                  The SPDM session ID.
+     344                 :            :  * @param  th_hash_buffer_size             size in bytes of the th_hash_buffer
+     345                 :            :  * @param  th_hash_buffer                 The buffer to store the th_hash_buffer
+     346                 :            :  *
+     347                 :            :  * @retval RETURN_SUCCESS  current TH hash is calculated.
+     348                 :            :  */
+     349                 :         48 : bool libspdm_calculate_th_hash_for_finish(libspdm_context_t *spdm_context,
+     350                 :            :                                           void *spdm_session_info,
+     351                 :            :                                           size_t *th_hash_buffer_size,
+     352                 :            :                                           void *th_hash_buffer)
+     353                 :            : {
+     354                 :            :     libspdm_session_info_t *session_info;
+     355                 :            :     uint32_t hash_size;
+     356                 :            :     void *digest_context_th;
+     357                 :            :     bool result;
+     358                 :            : 
+     359                 :         48 :     session_info = spdm_session_info;
+     360                 :            : 
+     361                 :         48 :     hash_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+     362                 :            : 
+     363         [ -  + ]:         48 :     LIBSPDM_ASSERT(*th_hash_buffer_size >= hash_size);
+     364                 :            : 
+     365                 :            :     /* duplicate the th context, because we still need use original context to continue.*/
+     366                 :         48 :     digest_context_th = libspdm_hash_new (spdm_context->connection_info.algorithm.base_hash_algo);
+     367         [ -  + ]:         48 :     if (digest_context_th == NULL) {
+     368                 :          0 :         return false;
+     369                 :            :     }
+     370                 :         48 :     result = libspdm_hash_duplicate (spdm_context->connection_info.algorithm.base_hash_algo,
+     371                 :         48 :                                      session_info->session_transcript.digest_context_th,
+     372                 :            :                                      digest_context_th);
+     373         [ -  + ]:         48 :     if (!result) {
+     374                 :          0 :         libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
+     375                 :            :                            digest_context_th);
+     376                 :          0 :         return false;
+     377                 :            :     }
+     378                 :         48 :     result = libspdm_hash_final (spdm_context->connection_info.algorithm.base_hash_algo,
+     379                 :            :                                  digest_context_th, th_hash_buffer);
+     380                 :         48 :     libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo, digest_context_th);
+     381         [ -  + ]:         48 :     if (!result) {
+     382                 :          0 :         return false;
+     383                 :            :     }
+     384                 :            : 
+     385                 :         48 :     *th_hash_buffer_size = hash_size;
+     386                 :            : 
+     387                 :         48 :     return true;
+     388                 :            : }
+     389                 :            : 
+     390                 :            : /*
+     391                 :            :  * This function calculates current TH hmac with message A, message K and message F, with response finished_key.
+     392                 :            :  *
+     393                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     394                 :            :  * @param  session_info                  The SPDM session ID.
+     395                 :            :  * @param  th_hmac_buffer_size             size in bytes of the th_hmac_buffer
+     396                 :            :  * @param  th_hmac_buffer                 The buffer to store the th_hmac_buffer
+     397                 :            :  *
+     398                 :            :  * @retval RETURN_SUCCESS  current TH hmac is calculated.
+     399                 :            :  */
+     400                 :         21 : bool libspdm_calculate_th_hmac_for_finish_rsp(libspdm_context_t *spdm_context,
+     401                 :            :                                               void *spdm_session_info,
+     402                 :            :                                               size_t *th_hmac_buffer_size,
+     403                 :            :                                               void *th_hmac_buffer)
+     404                 :            : {
+     405                 :            :     libspdm_session_info_t *session_info;
+     406                 :            :     void *secured_message_context;
+     407                 :            :     uint32_t hash_size;
+     408                 :            :     void *hash_context_th;
+     409                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     410                 :            :     bool result;
+     411                 :            : 
+     412                 :         21 :     session_info = spdm_session_info;
+     413                 :         21 :     secured_message_context = session_info->secured_message_context;
+     414                 :            : 
+     415                 :         21 :     hash_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+     416                 :            : 
+     417         [ -  + ]:         21 :     LIBSPDM_ASSERT(*th_hmac_buffer_size >= hash_size);
+     418         [ -  + ]:         21 :     LIBSPDM_ASSERT(session_info->session_transcript.digest_context_th != NULL);
+     419                 :            : 
+     420                 :            :     /* duplicate the th context, because we still need use original context to continue.*/
+     421                 :         21 :     hash_context_th = libspdm_hash_new (spdm_context->connection_info.algorithm.base_hash_algo);
+     422         [ -  + ]:         21 :     if (hash_context_th == NULL) {
+     423                 :          0 :         return false;
+     424                 :            :     }
+     425                 :         21 :     result = libspdm_hash_duplicate (spdm_context->connection_info.algorithm.base_hash_algo,
+     426                 :         21 :                                      session_info->session_transcript.digest_context_th,
+     427                 :            :                                      hash_context_th);
+     428         [ -  + ]:         21 :     if (!result) {
+     429                 :          0 :         libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo, hash_context_th);
+     430                 :          0 :         return false;
+     431                 :            :     }
+     432                 :         21 :     result = libspdm_hash_final (spdm_context->connection_info.algorithm.base_hash_algo,
+     433                 :            :                                  hash_context_th, hash_data);
+     434                 :         21 :     libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo, hash_context_th);
+     435         [ -  + ]:         21 :     if (!result) {
+     436                 :          0 :         return false;
+     437                 :            :     }
+     438                 :            : 
+     439                 :         21 :     result = libspdm_hmac_all_with_response_finished_key (secured_message_context,
+     440                 :            :                                                           hash_data, hash_size, th_hmac_buffer);
+     441         [ -  + ]:         21 :     if (!result) {
+     442                 :          0 :         return false;
+     443                 :            :     }
+     444                 :         21 :     *th_hmac_buffer_size = hash_size;
+     445                 :            : 
+     446                 :         21 :     return true;
+     447                 :            : }
+     448                 :            : 
+     449                 :            : /*
+     450                 :            :  * This function calculates current TH hmac with message A, message K and message F, with request finished_key.
+     451                 :            :  *
+     452                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     453                 :            :  * @param  session_info                  The SPDM session ID.
+     454                 :            :  * @param  th_hmac_buffer_size             size in bytes of the th_hmac_buffer
+     455                 :            :  * @param  th_hmac_buffer                 The buffer to store the th_hmac_buffer
+     456                 :            :  *
+     457                 :            :  * @retval RETURN_SUCCESS  current TH hmac is calculated.
+     458                 :            :  */
+     459                 :         89 : bool libspdm_calculate_th_hmac_for_finish_req(libspdm_context_t *spdm_context,
+     460                 :            :                                               void *spdm_session_info,
+     461                 :            :                                               size_t *th_hmac_buffer_size,
+     462                 :            :                                               void *th_hmac_buffer)
+     463                 :            : {
+     464                 :            :     libspdm_session_info_t *session_info;
+     465                 :            :     void *secured_message_context;
+     466                 :            :     uint32_t hash_size;
+     467                 :            :     void *hash_context_th;
+     468                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     469                 :            :     bool result;
+     470                 :            : 
+     471                 :         89 :     session_info = spdm_session_info;
+     472                 :         89 :     secured_message_context = session_info->secured_message_context;
+     473                 :            : 
+     474                 :         89 :     hash_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+     475                 :            : 
+     476         [ -  + ]:         89 :     LIBSPDM_ASSERT(*th_hmac_buffer_size >= hash_size);
+     477         [ -  + ]:         89 :     LIBSPDM_ASSERT(session_info->session_transcript.digest_context_th != NULL);
+     478                 :            : 
+     479                 :            :     /* duplicate the th context, because we still need use original context to continue.*/
+     480                 :         89 :     hash_context_th = libspdm_hash_new (spdm_context->connection_info.algorithm.base_hash_algo);
+     481         [ -  + ]:         89 :     if (hash_context_th == NULL) {
+     482                 :          0 :         return false;
+     483                 :            :     }
+     484                 :         89 :     result = libspdm_hash_duplicate (spdm_context->connection_info.algorithm.base_hash_algo,
+     485                 :         89 :                                      session_info->session_transcript.digest_context_th,
+     486                 :            :                                      hash_context_th);
+     487         [ -  + ]:         89 :     if (!result) {
+     488                 :          0 :         libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo, hash_context_th);
+     489                 :          0 :         return false;
+     490                 :            :     }
+     491                 :         89 :     result = libspdm_hash_final (spdm_context->connection_info.algorithm.base_hash_algo,
+     492                 :            :                                  hash_context_th, hash_data);
+     493                 :         89 :     libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo, hash_context_th);
+     494         [ -  + ]:         89 :     if (!result) {
+     495                 :          0 :         return false;
+     496                 :            :     }
+     497                 :            : 
+     498                 :         89 :     result = libspdm_hmac_all_with_request_finished_key (secured_message_context,
+     499                 :            :                                                          hash_data, hash_size, th_hmac_buffer);
+     500         [ -  + ]:         89 :     if (!result) {
+     501                 :          0 :         return false;
+     502                 :            :     }
+     503                 :         89 :     *th_hmac_buffer_size = hash_size;
+     504                 :            : 
+     505                 :         89 :     return true;
+     506                 :            : }
+     507                 :            : #endif
+     508                 :            : 
+     509                 :            : /*
+     510                 :            :  * This function calculates th1 hash.
+     511                 :            :  *
+     512                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     513                 :            :  * @param  session_info                  The SPDM session ID.
+     514                 :            :  * @param  is_requester                  Indicate of the key generation for a requester or a responder.
+     515                 :            :  * @param  th1_hash_data                  th1 hash
+     516                 :            :  *
+     517                 :            :  * @retval RETURN_SUCCESS  th1 hash is calculated.
+     518                 :            :  */
+     519                 :         56 : bool libspdm_calculate_th1_hash(libspdm_context_t *spdm_context,
+     520                 :            :                                 void *spdm_session_info,
+     521                 :            :                                 bool is_requester,
+     522                 :            :                                 uint8_t *th1_hash_data)
+     523                 :            : {
+     524                 :            :     libspdm_session_info_t *session_info;
+     525                 :            :     bool result;
+     526                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     527                 :            :     uint8_t slot_id;
+     528                 :            :     uint8_t *cert_chain_buffer;
+     529                 :            :     size_t cert_chain_buffer_size;
+     530                 :            :     uint8_t *th_curr_data;
+     531                 :            :     size_t th_curr_data_size;
+     532                 :            :     libspdm_th_managed_buffer_t th_curr;
+     533                 :            : #endif
+     534                 :            : #if !(LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT) || (LIBSPDM_DEBUG_PRINT_ENABLE)
+     535                 :            :     size_t hash_size;
+     536                 :            : #endif
+     537                 :            : 
+     538                 :         56 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "Calc th1 hash ...\n"));
+     539                 :            : 
+     540                 :         56 :     session_info = spdm_session_info;
+     541                 :            : 
+     542                 :            : #if !(LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT) || (LIBSPDM_DEBUG_PRINT_ENABLE)
+     543                 :         56 :     hash_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+     544                 :            : #endif
+     545                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     546                 :            :     if (!session_info->use_psk) {
+     547                 :            :         if (is_requester) {
+     548                 :            :             slot_id = spdm_context->connection_info.peer_used_cert_chain_slot_id;
+     549                 :            :             LIBSPDM_ASSERT((slot_id < SPDM_MAX_SLOT_COUNT) || (slot_id == 0xFF));
+     550                 :            :             if (slot_id == 0xFF) {
+     551                 :            :                 result = libspdm_get_peer_public_key_buffer(
+     552                 :            :                     spdm_context, (const void **)&cert_chain_buffer,
+     553                 :            :                     &cert_chain_buffer_size);
+     554                 :            :             } else {
+     555                 :            :                 result = libspdm_get_peer_cert_chain_buffer(
+     556                 :            :                     spdm_context, (const void **)&cert_chain_buffer,
+     557                 :            :                     &cert_chain_buffer_size);
+     558                 :            :             }
+     559                 :            :         } else {
+     560                 :            :             slot_id = spdm_context->connection_info.local_used_cert_chain_slot_id;
+     561                 :            :             LIBSPDM_ASSERT((slot_id < SPDM_MAX_SLOT_COUNT) || (slot_id == 0xFF));
+     562                 :            :             if (slot_id == 0xFF) {
+     563                 :            :                 result = libspdm_get_local_public_key_buffer(
+     564                 :            :                     spdm_context, (const void **)&cert_chain_buffer,
+     565                 :            :                     &cert_chain_buffer_size);
+     566                 :            :             } else {
+     567                 :            :                 result = libspdm_get_local_cert_chain_buffer(
+     568                 :            :                     spdm_context, (const void **)&cert_chain_buffer,
+     569                 :            :                     &cert_chain_buffer_size);
+     570                 :            :             }
+     571                 :            :         }
+     572                 :            :         if (!result) {
+     573                 :            :             return false;
+     574                 :            :         }
+     575                 :            :     } else {
+     576                 :            :         cert_chain_buffer = NULL;
+     577                 :            :         cert_chain_buffer_size = 0;
+     578                 :            :     }
+     579                 :            : 
+     580                 :            :     result = libspdm_calculate_th_for_exchange(
+     581                 :            :         spdm_context, session_info, cert_chain_buffer,
+     582                 :            :         cert_chain_buffer_size, &th_curr);
+     583                 :            :     if (!result) {
+     584                 :            :         return false;
+     585                 :            :     }
+     586                 :            :     th_curr_data = libspdm_get_managed_buffer(&th_curr);
+     587                 :            :     th_curr_data_size = libspdm_get_managed_buffer_size(&th_curr);
+     588                 :            : 
+     589                 :            :     result = libspdm_hash_all(spdm_context->connection_info.algorithm.base_hash_algo,
+     590                 :            :                               th_curr_data, th_curr_data_size, th1_hash_data);
+     591                 :            :     if (!result) {
+     592                 :            :         return false;
+     593                 :            :     }
+     594                 :            : #else
+     595                 :         56 :     result = libspdm_calculate_th_hash_for_exchange(
+     596                 :            :         spdm_context, session_info, &hash_size, th1_hash_data);
+     597         [ -  + ]:         56 :     if (!result) {
+     598                 :          0 :         return false;
+     599                 :            :     }
+     600                 :            : #endif
+     601                 :         56 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "th1 hash - "));
+     602                 :         56 :     LIBSPDM_INTERNAL_DUMP_DATA(th1_hash_data, hash_size);
+     603                 :         56 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     604                 :            : 
+     605                 :         56 :     return true;
+     606                 :            : }
+     607                 :            : 
+     608                 :            : /*
+     609                 :            :  * This function calculates th2 hash.
+     610                 :            :  *
+     611                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     612                 :            :  * @param  session_info                  The SPDM session ID.
+     613                 :            :  * @param  is_requester                  Indicate of the key generation for a requester or a responder.
+     614                 :            :  * @param  th1_hash_data                  th2 hash
+     615                 :            :  *
+     616                 :            :  * @retval RETURN_SUCCESS  th2 hash is calculated.
+     617                 :            :  */
+     618                 :         32 : bool libspdm_calculate_th2_hash(libspdm_context_t *spdm_context,
+     619                 :            :                                 void *spdm_session_info,
+     620                 :            :                                 bool is_requester,
+     621                 :            :                                 uint8_t *th2_hash_data)
+     622                 :            : {
+     623                 :            :     libspdm_session_info_t *session_info;
+     624                 :            :     bool result;
+     625                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     626                 :            :     uint8_t slot_id;
+     627                 :            :     uint8_t *cert_chain_buffer;
+     628                 :            :     size_t cert_chain_buffer_size;
+     629                 :            :     uint8_t *mut_cert_chain_buffer;
+     630                 :            :     size_t mut_cert_chain_buffer_size;
+     631                 :            :     uint8_t *th_curr_data;
+     632                 :            :     size_t th_curr_data_size;
+     633                 :            :     libspdm_th_managed_buffer_t th_curr;
+     634                 :            : #endif
+     635                 :            : #if !(LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT) || (LIBSPDM_DEBUG_PRINT_ENABLE)
+     636                 :            :     size_t hash_size;
+     637                 :            : #endif
+     638                 :            : 
+     639                 :         32 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "Calc th2 hash ...\n"));
+     640                 :            : 
+     641                 :         32 :     session_info = spdm_session_info;
+     642                 :            : 
+     643                 :            : #if !(LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT) || (LIBSPDM_DEBUG_PRINT_ENABLE)
+     644                 :         32 :     hash_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+     645                 :            : #endif
+     646                 :            : 
+     647                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     648                 :            :     if (!session_info->use_psk) {
+     649                 :            :         if (is_requester) {
+     650                 :            :             slot_id = spdm_context->connection_info.peer_used_cert_chain_slot_id;
+     651                 :            :             LIBSPDM_ASSERT((slot_id < SPDM_MAX_SLOT_COUNT) || (slot_id == 0xFF));
+     652                 :            :             if (slot_id == 0xFF) {
+     653                 :            :                 result = libspdm_get_peer_public_key_buffer(
+     654                 :            :                     spdm_context, (const void **)&cert_chain_buffer,
+     655                 :            :                     &cert_chain_buffer_size);
+     656                 :            :             } else {
+     657                 :            :                 result = libspdm_get_peer_cert_chain_buffer(
+     658                 :            :                     spdm_context, (const void **)&cert_chain_buffer,
+     659                 :            :                     &cert_chain_buffer_size);
+     660                 :            :             }
+     661                 :            :         } else {
+     662                 :            :             slot_id = spdm_context->connection_info.local_used_cert_chain_slot_id;
+     663                 :            :             LIBSPDM_ASSERT((slot_id < SPDM_MAX_SLOT_COUNT) || (slot_id == 0xFF));
+     664                 :            :             if (slot_id == 0xFF) {
+     665                 :            :                 result = libspdm_get_local_public_key_buffer(
+     666                 :            :                     spdm_context, (const void **)&cert_chain_buffer,
+     667                 :            :                     &cert_chain_buffer_size);
+     668                 :            :             } else {
+     669                 :            :                 result = libspdm_get_local_cert_chain_buffer(
+     670                 :            :                     spdm_context, (const void **)&cert_chain_buffer,
+     671                 :            :                     &cert_chain_buffer_size);
+     672                 :            :             }
+     673                 :            :         }
+     674                 :            :         if (!result) {
+     675                 :            :             return false;
+     676                 :            :         }
+     677                 :            :         if (session_info->mut_auth_requested) {
+     678                 :            :             if (is_requester) {
+     679                 :            :                 slot_id = spdm_context->connection_info.local_used_cert_chain_slot_id;
+     680                 :            :                 LIBSPDM_ASSERT((slot_id < SPDM_MAX_SLOT_COUNT) || (slot_id == 0xFF));
+     681                 :            :                 if (slot_id == 0xFF) {
+     682                 :            :                     result = libspdm_get_local_public_key_buffer(
+     683                 :            :                         spdm_context, (const void **)&mut_cert_chain_buffer,
+     684                 :            :                         &mut_cert_chain_buffer_size);
+     685                 :            :                 } else {
+     686                 :            :                     result = libspdm_get_local_cert_chain_buffer(
+     687                 :            :                         spdm_context, (const void **)&mut_cert_chain_buffer,
+     688                 :            :                         &mut_cert_chain_buffer_size);
+     689                 :            :                 }
+     690                 :            :             } else {
+     691                 :            :                 slot_id = spdm_context->connection_info.peer_used_cert_chain_slot_id;
+     692                 :            :                 LIBSPDM_ASSERT((slot_id < SPDM_MAX_SLOT_COUNT) || (slot_id == 0xFF));
+     693                 :            :                 if (slot_id == 0xFF) {
+     694                 :            :                     result = libspdm_get_peer_public_key_buffer(
+     695                 :            :                         spdm_context, (const void **)&mut_cert_chain_buffer,
+     696                 :            :                         &mut_cert_chain_buffer_size);
+     697                 :            :                 } else {
+     698                 :            :                     result = libspdm_get_peer_cert_chain_buffer(
+     699                 :            :                         spdm_context, (const void **)&mut_cert_chain_buffer,
+     700                 :            :                         &mut_cert_chain_buffer_size);
+     701                 :            :                 }
+     702                 :            :             }
+     703                 :            :             if (!result) {
+     704                 :            :                 return false;
+     705                 :            :             }
+     706                 :            :         } else {
+     707                 :            :             mut_cert_chain_buffer = NULL;
+     708                 :            :             mut_cert_chain_buffer_size = 0;
+     709                 :            :         }
+     710                 :            :     } else {
+     711                 :            :         cert_chain_buffer = NULL;
+     712                 :            :         cert_chain_buffer_size = 0;
+     713                 :            :         mut_cert_chain_buffer = NULL;
+     714                 :            :         mut_cert_chain_buffer_size = 0;
+     715                 :            :     }
+     716                 :            : 
+     717                 :            :     result = libspdm_calculate_th_for_finish(
+     718                 :            :         spdm_context, session_info, cert_chain_buffer,
+     719                 :            :         cert_chain_buffer_size, mut_cert_chain_buffer,
+     720                 :            :         mut_cert_chain_buffer_size, &th_curr);
+     721                 :            :     if (!result) {
+     722                 :            :         return false;
+     723                 :            :     }
+     724                 :            :     th_curr_data = libspdm_get_managed_buffer(&th_curr);
+     725                 :            :     th_curr_data_size = libspdm_get_managed_buffer_size(&th_curr);
+     726                 :            : 
+     727                 :            :     result = libspdm_hash_all(spdm_context->connection_info.algorithm.base_hash_algo,
+     728                 :            :                               th_curr_data, th_curr_data_size, th2_hash_data);
+     729                 :            :     if (!result) {
+     730                 :            :         return false;
+     731                 :            :     }
+     732                 :            : #else
+     733                 :         32 :     result = libspdm_calculate_th_hash_for_finish(
+     734                 :            :         spdm_context, session_info, &hash_size, th2_hash_data);
+     735         [ -  + ]:         32 :     if (!result) {
+     736                 :          0 :         return false;
+     737                 :            :     }
+     738                 :            : #endif
+     739                 :         32 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "th2 hash - "));
+     740                 :         32 :     LIBSPDM_INTERNAL_DUMP_DATA(th2_hash_data, hash_size);
+     741                 :         32 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     742                 :            : 
+     743                 :         32 :     return true;
+     744                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_common_lib/libspdm_com_msg_log.c.func-sort-c.html b/coverage_log/library/spdm_common_lib/libspdm_com_msg_log.c.func-sort-c.html new file mode 100644 index 00000000000..9c71f0c5970 --- /dev/null +++ b/coverage_log/library/spdm_common_lib/libspdm_com_msg_log.c.func-sort-c.html @@ -0,0 +1,105 @@ + + + + + + + LCOV - coverage.info - library/spdm_common_lib/libspdm_com_msg_log.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_common_lib - libspdm_com_msg_log.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:384879.2 %
Date:2024-09-22 08:21:07Functions:5683.3 %
Branches:122450.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_msg_log_status0
libspdm_init_msg_log1
libspdm_reset_msg_log1
libspdm_set_msg_log_mode1
libspdm_get_msg_log_size2579
libspdm_append_msg_log4394
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_common_lib/libspdm_com_msg_log.c.func.html b/coverage_log/library/spdm_common_lib/libspdm_com_msg_log.c.func.html new file mode 100644 index 00000000000..1d03bfdb5c8 --- /dev/null +++ b/coverage_log/library/spdm_common_lib/libspdm_com_msg_log.c.func.html @@ -0,0 +1,105 @@ + + + + + + + LCOV - coverage.info - library/spdm_common_lib/libspdm_com_msg_log.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_common_lib - libspdm_com_msg_log.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:384879.2 %
Date:2024-09-22 08:21:07Functions:5683.3 %
Branches:122450.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_append_msg_log4394
libspdm_get_msg_log_size2579
libspdm_get_msg_log_status0
libspdm_init_msg_log1
libspdm_reset_msg_log1
libspdm_set_msg_log_mode1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_common_lib/libspdm_com_msg_log.c.gcov.html b/coverage_log/library/spdm_common_lib/libspdm_com_msg_log.c.gcov.html new file mode 100644 index 00000000000..90496434697 --- /dev/null +++ b/coverage_log/library/spdm_common_lib/libspdm_com_msg_log.c.gcov.html @@ -0,0 +1,183 @@ + + + + + + + LCOV - coverage.info - library/spdm_common_lib/libspdm_com_msg_log.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_common_lib - libspdm_com_msg_log.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:384879.2 %
Date:2024-09-22 08:21:07Functions:5683.3 %
Branches:122450.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "internal/libspdm_common_lib.h"
+       8                 :            : 
+       9                 :            : #if LIBSPDM_ENABLE_MSG_LOG
+      10                 :          1 : void libspdm_init_msg_log (void *spdm_context, void *msg_buffer, size_t msg_buffer_size)
+      11                 :            : {
+      12                 :            :     libspdm_context_t *context;
+      13                 :            : 
+      14   [ +  -  -  + ]:          1 :     LIBSPDM_ASSERT((spdm_context != NULL) && (msg_buffer != NULL));
+      15         [ -  + ]:          1 :     LIBSPDM_ASSERT(msg_buffer_size != 0);
+      16                 :            : 
+      17                 :          1 :     context = spdm_context;
+      18                 :          1 :     context->msg_log.buffer = msg_buffer;
+      19                 :          1 :     context->msg_log.max_buffer_size = msg_buffer_size;
+      20                 :          1 :     context->msg_log.buffer_size = 0;
+      21                 :          1 :     context->msg_log.mode = 0;
+      22                 :          1 :     context->msg_log.status = 0;
+      23                 :          1 : }
+      24                 :            : 
+      25                 :          1 : void libspdm_set_msg_log_mode (void *spdm_context, uint32_t mode)
+      26                 :            : {
+      27                 :            :     libspdm_context_t *context;
+      28                 :            : 
+      29         [ -  + ]:          1 :     LIBSPDM_ASSERT(spdm_context != NULL);
+      30                 :            : 
+      31                 :          1 :     context = spdm_context;
+      32                 :          1 :     context->msg_log.mode = mode;
+      33                 :          1 : }
+      34                 :            : 
+      35                 :          0 : uint32_t libspdm_get_msg_log_status (void *spdm_context)
+      36                 :            : {
+      37                 :            :     libspdm_context_t *context;
+      38                 :            : 
+      39         [ #  # ]:          0 :     LIBSPDM_ASSERT(spdm_context != NULL);
+      40                 :            : 
+      41                 :          0 :     context = spdm_context;
+      42                 :            : 
+      43                 :          0 :     return context->msg_log.status;
+      44                 :            : }
+      45                 :            : 
+      46                 :       2579 : size_t libspdm_get_msg_log_size (void *spdm_context)
+      47                 :            : {
+      48                 :            :     libspdm_context_t *context;
+      49                 :            : 
+      50         [ -  + ]:       2579 :     LIBSPDM_ASSERT(spdm_context != NULL);
+      51                 :            : 
+      52                 :       2579 :     context = spdm_context;
+      53                 :            : 
+      54                 :       2579 :     return context->msg_log.buffer_size;
+      55                 :            : }
+      56                 :            : 
+      57                 :          1 : void libspdm_reset_msg_log (void *spdm_context)
+      58                 :            : {
+      59                 :            :     libspdm_context_t *context;
+      60                 :            : 
+      61         [ -  + ]:          1 :     LIBSPDM_ASSERT(spdm_context != NULL);
+      62                 :            : 
+      63                 :          1 :     context = spdm_context;
+      64                 :            : 
+      65                 :          1 :     context->msg_log.buffer_size = 0;
+      66                 :          1 :     context->msg_log.mode = 0;
+      67                 :          1 :     context->msg_log.status = 0;
+      68                 :          1 : }
+      69                 :            : 
+      70                 :       4394 : void libspdm_append_msg_log(libspdm_context_t *spdm_context, void *message, size_t message_size)
+      71                 :            : {
+      72   [ +  -  -  + ]:       4394 :     LIBSPDM_ASSERT((spdm_context != NULL) && (message != NULL));
+      73                 :            : 
+      74         [ +  + ]:       4394 :     if (((spdm_context->msg_log.mode & LIBSPDM_MSG_LOG_MODE_ENABLE) != 0) &&
+      75         [ +  - ]:          2 :         ((spdm_context->msg_log.status & LIBSPDM_MSG_LOG_STATUS_BUFFER_FULL) == 0)) {
+      76                 :          2 :         if (spdm_context->msg_log.buffer_size + message_size >
+      77         [ -  + ]:          2 :             spdm_context->msg_log.max_buffer_size) {
+      78                 :          0 :             libspdm_copy_mem((uint8_t *)spdm_context->msg_log.buffer +
+      79                 :          0 :                              spdm_context->msg_log.buffer_size,
+      80                 :            :                              spdm_context->msg_log.max_buffer_size, message,
+      81                 :          0 :                              spdm_context->msg_log.max_buffer_size -
+      82                 :          0 :                              spdm_context->msg_log.buffer_size);
+      83                 :          0 :             spdm_context->msg_log.status |= LIBSPDM_MSG_LOG_STATUS_BUFFER_FULL;
+      84                 :          0 :             spdm_context->msg_log.buffer_size = spdm_context->msg_log.max_buffer_size;
+      85                 :            :         } else {
+      86                 :          2 :             libspdm_copy_mem((uint8_t *)spdm_context->msg_log.buffer +
+      87                 :          2 :                              spdm_context->msg_log.buffer_size,
+      88                 :            :                              spdm_context->msg_log.max_buffer_size, message, message_size);
+      89                 :          2 :             spdm_context->msg_log.buffer_size += message_size;
+      90                 :            :         }
+      91                 :            : 
+      92                 :          2 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "Message Logging Status = [%x] Buffer Size = [%zx] "
+      93                 :            :                        "Max Buffer Size = [%zx]\n", spdm_context->msg_log.status,
+      94                 :            :                        spdm_context->msg_log.buffer_size, spdm_context->msg_log.max_buffer_size));
+      95                 :          2 :         LIBSPDM_INTERNAL_DUMP_HEX(spdm_context->msg_log.buffer, spdm_context->msg_log.buffer_size);
+      96                 :            :     }
+      97                 :       4394 : }
+      98                 :            : #endif /* LIBSPDM_ENABLE_MSG_LOG */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_common_lib/libspdm_com_opaque_data.c.func-sort-c.html b/coverage_log/library/spdm_common_lib/libspdm_com_opaque_data.c.func-sort-c.html new file mode 100644 index 00000000000..d7f5cba5cb0 --- /dev/null +++ b/coverage_log/library/spdm_common_lib/libspdm_com_opaque_data.c.func-sort-c.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - library/spdm_common_lib/libspdm_com_opaque_data.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_common_lib - libspdm_com_opaque_data.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:9811585.2 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:507467.6 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_untrusted_opaque_data_supported_version_data_size23
libspdm_get_element_from_opaque_data63
libspdm_process_general_opaque_data_check74
libspdm_get_opaque_data_version_selection_data_size165
libspdm_get_opaque_data_supported_version_data_size336
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_common_lib/libspdm_com_opaque_data.c.func.html b/coverage_log/library/spdm_common_lib/libspdm_com_opaque_data.c.func.html new file mode 100644 index 00000000000..a371cb8f137 --- /dev/null +++ b/coverage_log/library/spdm_common_lib/libspdm_com_opaque_data.c.func.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - library/spdm_common_lib/libspdm_com_opaque_data.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_common_lib - libspdm_com_opaque_data.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:9811585.2 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:507467.6 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_element_from_opaque_data63
libspdm_get_opaque_data_supported_version_data_size336
libspdm_get_opaque_data_version_selection_data_size165
libspdm_get_untrusted_opaque_data_supported_version_data_size23
libspdm_process_general_opaque_data_check74
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_common_lib/libspdm_com_opaque_data.c.gcov.html b/coverage_log/library/spdm_common_lib/libspdm_com_opaque_data.c.gcov.html new file mode 100644 index 00000000000..fa6e6db3284 --- /dev/null +++ b/coverage_log/library/spdm_common_lib/libspdm_com_opaque_data.c.gcov.html @@ -0,0 +1,418 @@ + + + + + + + LCOV - coverage.info - library/spdm_common_lib/libspdm_com_opaque_data.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_common_lib - libspdm_com_opaque_data.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:9811585.2 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:507467.6 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "internal/libspdm_common_lib.h"
+       8                 :            : 
+       9                 :            : /**
+      10                 :            :  * Return the size in bytes of opaque data version selection.
+      11                 :            :  *
+      12                 :            :  * This function should be called in KEY_EXCHANGE/PSK_EXCHANGE response generation.
+      13                 :            :  *
+      14                 :            :  * @return the size in bytes of opaque data version selection.
+      15                 :            :  **/
+      16                 :        165 : size_t libspdm_get_opaque_data_version_selection_data_size(const libspdm_context_t *spdm_context)
+      17                 :            : {
+      18                 :            :     size_t size;
+      19                 :            : 
+      20         [ -  + ]:        165 :     if (spdm_context->local_context.secured_message_version.spdm_version_count == 0) {
+      21                 :          0 :         return 0;
+      22                 :            :     }
+      23                 :            : 
+      24         [ +  + ]:        165 :     if (libspdm_get_connection_version (spdm_context) >= SPDM_MESSAGE_VERSION_12) {
+      25                 :         18 :         size = sizeof(spdm_general_opaque_data_table_header_t) +
+      26                 :            :                sizeof(secured_message_opaque_element_table_header_t) +
+      27                 :            :                sizeof(secured_message_opaque_element_version_selection_t);
+      28                 :            :     } else {
+      29                 :        147 :         size = sizeof(secured_message_general_opaque_data_table_header_t) +
+      30                 :            :                sizeof(secured_message_opaque_element_table_header_t) +
+      31                 :            :                sizeof(secured_message_opaque_element_version_selection_t);
+      32                 :            :     }
+      33                 :            :     /* Add Padding*/
+      34                 :        165 :     return (size + 3) & ~3;
+      35                 :            : }
+      36                 :            : 
+      37                 :            : /**
+      38                 :            :  * Return the size in bytes of opaque data supported version.
+      39                 :            :  *
+      40                 :            :  * This function should be called in KEY_EXCHANGE/PSK_EXCHANGE request generation.
+      41                 :            :  *
+      42                 :            :  * @return the size in bytes of opaque data supported version.
+      43                 :            :  **/
+      44                 :        336 : size_t libspdm_get_opaque_data_supported_version_data_size(libspdm_context_t *spdm_context)
+      45                 :            : {
+      46                 :            :     size_t size;
+      47                 :            : 
+      48         [ -  + ]:        336 :     if (spdm_context->local_context.secured_message_version.spdm_version_count == 0) {
+      49                 :          0 :         return 0;
+      50                 :            :     }
+      51                 :            : 
+      52         [ +  + ]:        336 :     if (libspdm_get_connection_version (spdm_context) >= SPDM_MESSAGE_VERSION_12) {
+      53                 :         20 :         size = sizeof(spdm_general_opaque_data_table_header_t) +
+      54                 :            :                sizeof(secured_message_opaque_element_table_header_t) +
+      55                 :            :                sizeof(secured_message_opaque_element_supported_version_t) +
+      56                 :         20 :                sizeof(spdm_version_number_t) *
+      57                 :         20 :                spdm_context->local_context.secured_message_version.spdm_version_count;
+      58                 :            :     } else {
+      59                 :        316 :         size = sizeof(secured_message_general_opaque_data_table_header_t) +
+      60                 :            :                sizeof(secured_message_opaque_element_table_header_t) +
+      61                 :            :                sizeof(secured_message_opaque_element_supported_version_t) +
+      62                 :        316 :                sizeof(spdm_version_number_t) *
+      63                 :        316 :                spdm_context->local_context.secured_message_version.spdm_version_count;
+      64                 :            :     }
+      65                 :            :     /* Add Padding*/
+      66                 :        336 :     return (size + 3) & ~3;
+      67                 :            : }
+      68                 :            : 
+      69                 :            : /**
+      70                 :            :  * Return the size in bytes of opaque data supported version.
+      71                 :            :  *
+      72                 :            :  * This function should be called in libspdm_process_opaque_data_supported_version_data.
+      73                 :            :  *
+      74                 :            :  * @param  version_count                 Secure version count.
+      75                 :            :  *
+      76                 :            :  * @return the size in bytes of opaque data supported version.
+      77                 :            :  **/
+      78                 :         23 : size_t libspdm_get_untrusted_opaque_data_supported_version_data_size(
+      79                 :            :     libspdm_context_t *spdm_context, uint8_t version_count)
+      80                 :            : {
+      81                 :            :     size_t size;
+      82                 :            : 
+      83         [ +  + ]:         23 :     if (libspdm_get_connection_version (spdm_context) >= SPDM_MESSAGE_VERSION_12) {
+      84                 :          6 :         size = sizeof(spdm_general_opaque_data_table_header_t) +
+      85                 :            :                sizeof(secured_message_opaque_element_table_header_t) +
+      86                 :            :                sizeof(secured_message_opaque_element_supported_version_t) +
+      87                 :          6 :                sizeof(spdm_version_number_t) * version_count;
+      88                 :            :     } else {
+      89                 :         17 :         size = sizeof(secured_message_general_opaque_data_table_header_t) +
+      90                 :            :                sizeof(secured_message_opaque_element_table_header_t) +
+      91                 :            :                sizeof(secured_message_opaque_element_supported_version_t) +
+      92                 :         17 :                sizeof(spdm_version_number_t) * version_count;
+      93                 :            :     }
+      94                 :            :     /* Add Padding*/
+      95                 :         23 :     return (size + 3) & ~3;
+      96                 :            : }
+      97                 :            : 
+      98                 :            : /**
+      99                 :            :  * Get element from multi element opaque data by element id.
+     100                 :            :  *
+     101                 :            :  * This function should be called in
+     102                 :            :  * libspdm_process_opaque_data_supported_version_data/libspdm_process_opaque_data_version_selection_data.
+     103                 :            :  *
+     104                 :            :  * @param[in]  data_in_size                size of multi element opaque data.
+     105                 :            :  * @param[in]  data_in                     A pointer to the multi element opaque data.
+     106                 :            :  * @param[in]  element_id                  element id.
+     107                 :            :  * @param[in]  sm_data_id                  sm_data_id to identify for the Secured Message data type.
+     108                 :            :  * @param[out] get_element_ptr             pointer to store found element
+     109                 :            :  *
+     110                 :            :  * @retval true                            get element successfully
+     111                 :            :  * @retval false                           get element failed
+     112                 :            :  **/
+     113                 :         63 : bool libspdm_get_element_from_opaque_data(libspdm_context_t *spdm_context,
+     114                 :            :                                           size_t data_in_size, const void *data_in,
+     115                 :            :                                           uint8_t element_id, uint8_t sm_data_id,
+     116                 :            :                                           const void **get_element_ptr, size_t *get_element_len)
+     117                 :            : {
+     118                 :            :     const secured_message_general_opaque_data_table_header_t
+     119                 :            :     *general_opaque_data_table_header;
+     120                 :            :     const spdm_general_opaque_data_table_header_t
+     121                 :            :     *spdm_general_opaque_data_table_header;
+     122                 :            :     const secured_message_opaque_element_table_header_t
+     123                 :            :     *opaque_element_table_header;
+     124                 :            :     const secured_message_opaque_element_header_t
+     125                 :            :     * secured_message_element_header;
+     126                 :            : 
+     127                 :            :     bool result;
+     128                 :            :     uint8_t element_num;
+     129                 :            :     uint8_t element_index;
+     130                 :            :     size_t data_element_size;
+     131                 :            :     size_t current_element_len;
+     132                 :            :     size_t total_element_len;
+     133                 :            : 
+     134                 :         63 :     total_element_len = 0;
+     135                 :         63 :     result = false;
+     136                 :            : 
+     137                 :            :     /*check parameter in*/
+     138         [ -  + ]:         63 :     if (element_id > SPDM_REGISTRY_ID_MAX) {
+     139                 :          0 :         return false;
+     140                 :            :     }
+     141   [ +  -  -  + ]:         63 :     if ((data_in_size == 0) || (data_in == NULL)) {
+     142                 :          0 :         return false;
+     143                 :            :     }
+     144                 :            : 
+     145         [ +  + ]:         63 :     if (libspdm_get_connection_version (spdm_context) >= SPDM_MESSAGE_VERSION_12) {
+     146                 :         13 :         spdm_general_opaque_data_table_header = data_in;
+     147         [ -  + ]:         13 :         if (data_in_size < sizeof(spdm_general_opaque_data_table_header_t)) {
+     148                 :          0 :             return false;
+     149                 :            :         }
+     150         [ -  + ]:         13 :         if (spdm_general_opaque_data_table_header->total_elements < 1) {
+     151                 :          0 :             return false;
+     152                 :            :         }
+     153                 :         13 :         opaque_element_table_header = (const void *)(spdm_general_opaque_data_table_header + 1);
+     154                 :            : 
+     155                 :         13 :         element_num = spdm_general_opaque_data_table_header->total_elements;
+     156                 :            : 
+     157                 :         13 :         data_element_size = data_in_size - sizeof(spdm_general_opaque_data_table_header_t);
+     158                 :            :     } else {
+     159                 :         50 :         general_opaque_data_table_header = data_in;
+     160         [ -  + ]:         50 :         if (data_in_size < sizeof(secured_message_general_opaque_data_table_header_t)) {
+     161                 :          0 :             return false;
+     162                 :            :         }
+     163         [ +  + ]:         50 :         if ((general_opaque_data_table_header->spec_id !=
+     164                 :         49 :              SECURED_MESSAGE_OPAQUE_DATA_SPEC_ID) ||
+     165         [ +  - ]:         49 :             (general_opaque_data_table_header->opaque_version !=
+     166                 :         49 :              SECURED_MESSAGE_OPAQUE_VERSION) ||
+     167         [ -  + ]:         49 :             (general_opaque_data_table_header->total_elements < 1)) {
+     168                 :          1 :             return false;
+     169                 :            :         }
+     170                 :         49 :         opaque_element_table_header = (const void *)(general_opaque_data_table_header + 1);
+     171                 :            : 
+     172                 :         49 :         element_num = general_opaque_data_table_header->total_elements;
+     173                 :            : 
+     174                 :         49 :         data_element_size = data_in_size -
+     175                 :            :                             sizeof(secured_message_general_opaque_data_table_header_t);
+     176                 :            :     }
+     177                 :            : 
+     178         [ +  + ]:        168 :     for (element_index = 0; element_index < element_num; element_index++) {
+     179                 :            :         /*ensure the opaque_element_table_header is valid*/
+     180         [ -  + ]:        110 :         if (total_element_len + sizeof(secured_message_opaque_element_table_header_t) >
+     181                 :            :             data_element_size) {
+     182                 :          0 :             return false;
+     183                 :            :         }
+     184                 :            : 
+     185                 :            :         /*check element header id*/
+     186         [ +  + ]:        110 :         if ((opaque_element_table_header->id > SPDM_REGISTRY_ID_MAX) ||
+     187         [ -  + ]:        106 :             (opaque_element_table_header->vendor_len != 0)) {
+     188                 :          4 :             return false;
+     189                 :            :         }
+     190                 :            : 
+     191                 :        106 :         current_element_len = sizeof(secured_message_opaque_element_table_header_t) +
+     192                 :        106 :                               opaque_element_table_header->opaque_element_data_len;
+     193                 :            :         /* Add Padding*/
+     194                 :        106 :         current_element_len = (current_element_len + 3) & ~3;
+     195                 :            : 
+     196                 :        106 :         total_element_len += current_element_len;
+     197                 :            : 
+     198         [ -  + ]:        106 :         if (data_element_size < total_element_len) {
+     199                 :          0 :             return false;
+     200                 :            :         }
+     201                 :            : 
+     202         [ +  + ]:        106 :         if (opaque_element_table_header->id == element_id) {
+     203                 :         62 :             secured_message_element_header = (const void *)(opaque_element_table_header + 1);
+     204                 :         62 :             if ((const uint8_t *)secured_message_element_header +
+     205                 :            :                 sizeof(secured_message_opaque_element_header_t) >
+     206         [ -  + ]:         62 :                 (const uint8_t *)data_in + data_in_size) {
+     207                 :          0 :                 return false;
+     208                 :            :             }
+     209                 :            : 
+     210         [ +  - ]:         62 :             if ((secured_message_element_header->sm_data_id == sm_data_id) &&
+     211         [ +  - ]:         62 :                 (secured_message_element_header->sm_data_version ==
+     212                 :            :                  SECURED_MESSAGE_OPAQUE_ELEMENT_SMDATA_DATA_VERSION)) {
+     213                 :            :                 /*get element by element id*/
+     214                 :         62 :                 *get_element_ptr = opaque_element_table_header;
+     215                 :         62 :                 *get_element_len = current_element_len;
+     216                 :         62 :                 result = true;
+     217                 :            :             }
+     218                 :            :         }
+     219                 :            : 
+     220                 :            :         /*move to next element*/
+     221                 :        106 :         opaque_element_table_header = (const secured_message_opaque_element_table_header_t *)
+     222                 :            :                                       ((const uint8_t *)opaque_element_table_header +
+     223                 :            :                                        current_element_len);
+     224                 :            :     }
+     225                 :            : 
+     226                 :            :     /*ensure data size is right*/
+     227         [ -  + ]:         58 :     if (data_element_size != total_element_len) {
+     228                 :          0 :         return false;
+     229                 :            :     }
+     230                 :            : 
+     231                 :         58 :     return result;
+     232                 :            : }
+     233                 :            : 
+     234                 :            : /**
+     235                 :            :  *  Process general opaque data check
+     236                 :            :  *
+     237                 :            :  * @param  data_in_size                  size in bytes of the data_in.
+     238                 :            :  * @param  data_in                       A pointer to the buffer to store the opaque data version selection.
+     239                 :            :  *
+     240                 :            :  * @retval true                           check opaque data successfully
+     241                 :            :  * @retval false                          check opaque data failed
+     242                 :            :  **/
+     243                 :         74 : bool libspdm_process_general_opaque_data_check(libspdm_context_t *spdm_context,
+     244                 :            :                                                size_t data_in_size,
+     245                 :            :                                                const void *data_in)
+     246                 :            : {
+     247                 :            :     const spdm_general_opaque_data_table_header_t
+     248                 :            :     *spdm_general_opaque_data_table_header;
+     249                 :            :     const opaque_element_table_header_t
+     250                 :            :     *opaque_element_table_header;
+     251                 :            :     uint8_t element_num;
+     252                 :            :     uint8_t element_index;
+     253                 :            :     uint16_t opaque_element_data_len;
+     254                 :            :     size_t data_element_size;
+     255                 :            :     size_t current_element_len;
+     256                 :            :     size_t total_element_len;
+     257                 :         74 :     uint8_t zero_padding[4] = {0};
+     258                 :            : 
+     259                 :         74 :     total_element_len = 0;
+     260                 :            : 
+     261         [ -  + ]:         74 :     LIBSPDM_ASSERT(data_in_size <= SPDM_MAX_OPAQUE_DATA_SIZE);
+     262                 :            : 
+     263         [ +  + ]:         74 :     if (libspdm_get_connection_version(spdm_context) >= SPDM_MESSAGE_VERSION_12) {
+     264         [ +  + ]:         17 :         if ((spdm_context->connection_info.algorithm.other_params_support &
+     265                 :            :              SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_MASK) == SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1) {
+     266                 :            :             /* Check byte alignment */
+     267         [ -  + ]:         13 :             if ((data_in_size & 3) != 0) {
+     268                 :          0 :                 return false;
+     269                 :            :             }
+     270                 :            : 
+     271                 :         13 :             spdm_general_opaque_data_table_header = data_in;
+     272         [ -  + ]:         13 :             if (data_in_size < sizeof(spdm_general_opaque_data_table_header_t)) {
+     273                 :          0 :                 return false;
+     274                 :            :             }
+     275         [ -  + ]:         13 :             if (spdm_general_opaque_data_table_header->total_elements < 1) {
+     276                 :          0 :                 return false;
+     277                 :            :             }
+     278                 :         13 :             opaque_element_table_header = (const void *)(spdm_general_opaque_data_table_header + 1);
+     279                 :            : 
+     280                 :         13 :             element_num = spdm_general_opaque_data_table_header->total_elements;
+     281                 :            : 
+     282                 :         13 :             data_element_size = data_in_size - sizeof(spdm_general_opaque_data_table_header_t);
+     283                 :            : 
+     284         [ +  + ]:         29 :             for (element_index = 0; element_index < element_num; element_index++) {
+     285                 :            :                 /*ensure the opaque_element_table_header is valid*/
+     286         [ -  + ]:         17 :                 if (total_element_len + sizeof(opaque_element_table_header_t) +
+     287                 :            :                     sizeof(opaque_element_data_len) >
+     288                 :            :                     data_element_size) {
+     289                 :          0 :                     return false;
+     290                 :            :                 }
+     291                 :            : 
+     292                 :            :                 /*check element header id*/
+     293         [ -  + ]:         17 :                 if (opaque_element_table_header->id > SPDM_REGISTRY_ID_MAX) {
+     294                 :          0 :                     return false;
+     295                 :            :                 }
+     296                 :            : 
+     297                 :         17 :                 opaque_element_data_len = *(uint16_t *)((size_t)(opaque_element_table_header + 1)) +
+     298                 :         17 :                                           opaque_element_table_header->vendor_len;
+     299                 :            : 
+     300                 :         17 :                 current_element_len = sizeof(opaque_element_table_header_t) +
+     301                 :         17 :                                       opaque_element_table_header->vendor_len +
+     302                 :         17 :                                       sizeof(opaque_element_data_len) +
+     303                 :            :                                       opaque_element_data_len;
+     304                 :            : 
+     305         [ +  + ]:         17 :                 if ((current_element_len & 3) != 0) {
+     306         [ +  + ]:         11 :                     if (!libspdm_consttime_is_mem_equal(zero_padding,
+     307                 :            :                                                         (uint8_t *)(size_t)
+     308                 :            :                                                         (opaque_element_table_header) +
+     309                 :            :                                                         current_element_len,
+     310                 :         11 :                                                         4 - (current_element_len & 3))) {
+     311                 :          1 :                         return false;
+     312                 :            :                     }
+     313                 :            :                 }
+     314                 :            :                 /* Add Padding*/
+     315                 :         16 :                 current_element_len = (current_element_len + 3) & ~3;
+     316                 :            : 
+     317                 :         16 :                 total_element_len += current_element_len;
+     318                 :            : 
+     319         [ -  + ]:         16 :                 if (total_element_len > data_element_size) {
+     320                 :          0 :                     return false;
+     321                 :            :                 }
+     322                 :            : 
+     323                 :            :                 /*move to next element*/
+     324                 :         16 :                 opaque_element_table_header =
+     325                 :            :                     (const opaque_element_table_header_t *)
+     326                 :            :                     ((const uint8_t *)opaque_element_table_header +
+     327                 :            :                      current_element_len);
+     328                 :            :             }
+     329                 :            :         }
+     330                 :            :     }
+     331                 :            : 
+     332                 :         73 :     return true;
+     333                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_common_lib/libspdm_com_support.c.func-sort-c.html b/coverage_log/library/spdm_common_lib/libspdm_com_support.c.func-sort-c.html new file mode 100644 index 00000000000..69fe15fdf03 --- /dev/null +++ b/coverage_log/library/spdm_common_lib/libspdm_com_support.c.func-sort-c.html @@ -0,0 +1,161 @@ + + + + + + + LCOV - coverage.info - library/spdm_common_lib/libspdm_com_support.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_common_lib - libspdm_com_support.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:9412177.7 %
Date:2024-09-22 08:21:07Functions:162080.0 %
Branches:313783.8 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_fips_mode0
libspdm_module_version0
libspdm_read_uint640
libspdm_write_uint640
libspdm_write_uint324
libspdm_internal_dump_hex_str30
libspdm_mask_capability_flags70
libspdm_init_managed_buffer110
libspdm_write_uint16240
libspdm_read_uint24254
libspdm_read_uint16309
libspdm_append_managed_buffer439
libspdm_read_uint32472
libspdm_get_managed_buffer624
libspdm_get_managed_buffer_size635
libspdm_reset_managed_buffer784
libspdm_write_uint242272
libspdm_get_code_str5128
libspdm_internal_dump_hex7829
libspdm_internal_dump_data16443
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_common_lib/libspdm_com_support.c.func.html b/coverage_log/library/spdm_common_lib/libspdm_com_support.c.func.html new file mode 100644 index 00000000000..9382bf23e15 --- /dev/null +++ b/coverage_log/library/spdm_common_lib/libspdm_com_support.c.func.html @@ -0,0 +1,161 @@ + + + + + + + LCOV - coverage.info - library/spdm_common_lib/libspdm_com_support.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_common_lib - libspdm_com_support.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:9412177.7 %
Date:2024-09-22 08:21:07Functions:162080.0 %
Branches:313783.8 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_append_managed_buffer439
libspdm_get_code_str5128
libspdm_get_fips_mode0
libspdm_get_managed_buffer624
libspdm_get_managed_buffer_size635
libspdm_init_managed_buffer110
libspdm_internal_dump_data16443
libspdm_internal_dump_hex7829
libspdm_internal_dump_hex_str30
libspdm_mask_capability_flags70
libspdm_module_version0
libspdm_read_uint16309
libspdm_read_uint24254
libspdm_read_uint32472
libspdm_read_uint640
libspdm_reset_managed_buffer784
libspdm_write_uint16240
libspdm_write_uint242272
libspdm_write_uint324
libspdm_write_uint640
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_common_lib/libspdm_com_support.c.gcov.html b/coverage_log/library/spdm_common_lib/libspdm_com_support.c.gcov.html new file mode 100644 index 00000000000..75d9c8f38d5 --- /dev/null +++ b/coverage_log/library/spdm_common_lib/libspdm_com_support.c.gcov.html @@ -0,0 +1,454 @@ + + + + + + + LCOV - coverage.info - library/spdm_common_lib/libspdm_com_support.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_common_lib - libspdm_com_support.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:9412177.7 %
Date:2024-09-22 08:21:07Functions:162080.0 %
Branches:313783.8 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "internal/libspdm_common_lib.h"
+       8                 :            : 
+       9                 :            : #if LIBSPDM_DEBUG_PRINT_ENABLE
+      10                 :            : typedef struct {
+      11                 :            :     uint8_t code;
+      12                 :            :     const char *code_str;
+      13                 :            : } libspdm_code_str_struct_t;
+      14                 :            : 
+      15                 :       5128 : const char *libspdm_get_code_str(uint8_t request_code)
+      16                 :            : {
+      17                 :            :     size_t index;
+      18                 :            : 
+      19                 :            :     static libspdm_code_str_struct_t code_str_struct[] = {
+      20                 :            :         /* SPDM response code (1.0) */
+      21                 :            :         { SPDM_DIGESTS, "SPDM_DIGESTS" },
+      22                 :            :         { SPDM_CERTIFICATE, "SPDM_CERTIFICATE" },
+      23                 :            :         { SPDM_CHALLENGE_AUTH, "SPDM_CHALLENGE_AUTH" },
+      24                 :            :         { SPDM_VERSION, "SPDM_VERSION" },
+      25                 :            :         { SPDM_MEASUREMENTS, "SPDM_MEASUREMENTS" },
+      26                 :            :         { SPDM_CAPABILITIES, "SPDM_CAPABILITIES" },
+      27                 :            :         { SPDM_ALGORITHMS, "SPDM_ALGORITHMS" },
+      28                 :            :         { SPDM_VENDOR_DEFINED_RESPONSE, "SPDM_VENDOR_DEFINED_RESPONSE" },
+      29                 :            :         { SPDM_ERROR, "SPDM_ERROR" },
+      30                 :            :         /* SPDM response code (1.1) */
+      31                 :            :         { SPDM_KEY_EXCHANGE_RSP, "SPDM_KEY_EXCHANGE_RSP" },
+      32                 :            :         { SPDM_FINISH_RSP, "SPDM_FINISH_RSP" },
+      33                 :            :         { SPDM_PSK_EXCHANGE_RSP, "SPDM_PSK_EXCHANGE_RSP" },
+      34                 :            :         { SPDM_PSK_FINISH_RSP, "SPDM_PSK_FINISH_RSP" },
+      35                 :            :         { SPDM_HEARTBEAT_ACK, "SPDM_HEARTBEAT_ACK" },
+      36                 :            :         { SPDM_KEY_UPDATE_ACK, "SPDM_KEY_UPDATE_ACK" },
+      37                 :            :         { SPDM_ENCAPSULATED_REQUEST, "SPDM_ENCAPSULATED_REQUEST" },
+      38                 :            :         { SPDM_ENCAPSULATED_RESPONSE_ACK, "SPDM_ENCAPSULATED_RESPONSE_ACK" },
+      39                 :            :         { SPDM_END_SESSION_ACK, "SPDM_END_SESSION_ACK" },
+      40                 :            :         /* SPDM response code (1.2) */
+      41                 :            :         { SPDM_CSR, "SPDM_CSR" },
+      42                 :            :         { SPDM_SET_CERTIFICATE_RSP, "SPDM_SET_CERTIFICATE_RSP" },
+      43                 :            :         { SPDM_CHUNK_SEND_ACK, "SPDM_CHUNK_SEND_ACK" },
+      44                 :            :         { SPDM_CHUNK_RESPONSE, "SPDM_CHUNK_RESPONSE" },
+      45                 :            :         /* SPDM response code (1.3 )*/
+      46                 :            :         { SPDM_SUPPORTED_EVENT_TYPES, "SPDM_SUPPORTED_EVENT_TYPES" },
+      47                 :            :         /* SPDM request code (1.0) */
+      48                 :            :         { SPDM_GET_DIGESTS, "SPDM_GET_DIGESTS" },
+      49                 :            :         { SPDM_GET_CERTIFICATE, "SPDM_GET_CERTIFICATE" },
+      50                 :            :         { SPDM_CHALLENGE, "SPDM_CHALLENGE" },
+      51                 :            :         { SPDM_GET_VERSION, "SPDM_GET_VERSION" },
+      52                 :            :         { SPDM_GET_MEASUREMENTS, "SPDM_GET_MEASUREMENTS" },
+      53                 :            :         { SPDM_GET_CAPABILITIES, "SPDM_GET_CAPABILITIES" },
+      54                 :            :         { SPDM_NEGOTIATE_ALGORITHMS, "SPDM_NEGOTIATE_ALGORITHMS" },
+      55                 :            :         { SPDM_VENDOR_DEFINED_REQUEST, "SPDM_VENDOR_DEFINED_REQUEST" },
+      56                 :            :         { SPDM_RESPOND_IF_READY, "SPDM_RESPOND_IF_READY" },
+      57                 :            :         /* SPDM request code (1.1) */
+      58                 :            :         { SPDM_KEY_EXCHANGE, "SPDM_KEY_EXCHANGE" },
+      59                 :            :         { SPDM_FINISH, "SPDM_FINISH" },
+      60                 :            :         { SPDM_PSK_EXCHANGE, "SPDM_PSK_EXCHANGE" },
+      61                 :            :         { SPDM_PSK_FINISH, "SPDM_PSK_FINISH" },
+      62                 :            :         { SPDM_HEARTBEAT, "SPDM_HEARTBEAT" },
+      63                 :            :         { SPDM_KEY_UPDATE, "SPDM_KEY_UPDATE" },
+      64                 :            :         { SPDM_GET_ENCAPSULATED_REQUEST, "SPDM_GET_ENCAPSULATED_REQUEST" },
+      65                 :            :         { SPDM_DELIVER_ENCAPSULATED_RESPONSE, "SPDM_DELIVER_ENCAPSULATED_RESPONSE" },
+      66                 :            :         { SPDM_END_SESSION, "SPDM_END_SESSION" },
+      67                 :            :         /* SPDM request code (1.2) */
+      68                 :            :         { SPDM_GET_CSR, "SPDM_GET_CSR" },
+      69                 :            :         { SPDM_SET_CERTIFICATE, "SPDM_SET_CERTIFICATE" },
+      70                 :            :         { SPDM_CHUNK_SEND, "SPDM_CHUNK_SEND" },
+      71                 :            :         { SPDM_CHUNK_GET, "SPDM_CHUNK_GET" },
+      72                 :            :         /* SPDM request code (1.3) */
+      73                 :            :         { SPDM_GET_SUPPORTED_EVENT_TYPES, "SPDM_GET_SUPPORTED_EVENT_TYPES" }
+      74                 :            :     };
+      75                 :            : 
+      76         [ +  + ]:      87188 :     for (index = 0; index < LIBSPDM_ARRAY_SIZE(code_str_struct); index++) {
+      77         [ +  + ]:      87142 :         if (request_code == code_str_struct[index].code) {
+      78                 :       5082 :             return code_str_struct[index].code_str;
+      79                 :            :         }
+      80                 :            :     }
+      81                 :            : 
+      82                 :         46 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR, "msg code 0x%x not found!!!\n", request_code));
+      83                 :            : 
+      84                 :         46 :     return "<unknown>";
+      85                 :            : }
+      86                 :            : 
+      87                 :         30 : void libspdm_internal_dump_hex_str(const uint8_t *data, size_t size)
+      88                 :            : {
+      89                 :            :     size_t index;
+      90         [ +  + ]:        990 :     for (index = 0; index < size; index++) {
+      91                 :        960 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "%02x", data[index]));
+      92                 :            :     }
+      93                 :         30 : }
+      94                 :            : 
+      95                 :      16443 : void libspdm_internal_dump_data(const uint8_t *data, size_t size)
+      96                 :            : {
+      97                 :            :     size_t index;
+      98         [ +  + ]:     364353 :     for (index = 0; index < size; index++) {
+      99                 :     347910 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "%02x ", data[index]));
+     100                 :            :     }
+     101                 :      16443 : }
+     102                 :            : 
+     103                 :       7829 : void libspdm_internal_dump_hex(const uint8_t *data, size_t size)
+     104                 :            : {
+     105                 :            :     size_t index;
+     106                 :            :     size_t count;
+     107                 :            :     size_t left;
+     108                 :            : 
+     109                 :            :     #define COLUMN_SIZE (16 * 2)
+     110                 :            : 
+     111                 :       7829 :     count = size / COLUMN_SIZE;
+     112                 :       7829 :     left = size % COLUMN_SIZE;
+     113         [ +  + ]:      14562 :     for (index = 0; index < count; index++) {
+     114                 :       6733 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "%04zx: ", index * COLUMN_SIZE));
+     115                 :       6733 :         LIBSPDM_INTERNAL_DUMP_DATA(data + index * COLUMN_SIZE, COLUMN_SIZE);
+     116                 :       6733 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     117                 :            :     }
+     118                 :            : 
+     119         [ +  + ]:       7829 :     if (left != 0) {
+     120                 :       7512 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "%04zx: ", index * COLUMN_SIZE));
+     121                 :       7512 :         LIBSPDM_INTERNAL_DUMP_DATA(data + index * COLUMN_SIZE, left);
+     122                 :       7512 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     123                 :            :     }
+     124                 :       7829 : }
+     125                 :            : #endif /* LIBSPDM_DEBUG_PRINT_ENABLE */
+     126                 :            : 
+     127                 :            : /**
+     128                 :            :  * Reads a 24-bit value from memory that may be unaligned.
+     129                 :            :  *
+     130                 :            :  * @param  buffer  The pointer to a 24-bit value that may be unaligned.
+     131                 :            :  *
+     132                 :            :  * @return The 24-bit value read from buffer.
+     133                 :            :  **/
+     134                 :        254 : uint32_t libspdm_read_uint24(const uint8_t *buffer)
+     135                 :            : {
+     136                 :        254 :     return (uint32_t)(buffer[0] | buffer[1] << 8 | buffer[2] << 16);
+     137                 :            : }
+     138                 :            : 
+     139                 :            : /**
+     140                 :            :  * Writes a 24-bit value to memory that may be unaligned.
+     141                 :            :  *
+     142                 :            :  * @param  buffer  The pointer to a 24-bit value that may be unaligned.
+     143                 :            :  * @param  value   24-bit value to write to buffer.
+     144                 :            :  **/
+     145                 :       2272 : void libspdm_write_uint24(uint8_t *buffer, uint32_t value)
+     146                 :            : {
+     147                 :       2272 :     buffer[0] = (uint8_t)(value & 0xFF);
+     148                 :       2272 :     buffer[1] = (uint8_t)((value >> 8) & 0xFF);
+     149                 :       2272 :     buffer[2] = (uint8_t)((value >> 16) & 0xFF);
+     150                 :       2272 : }
+     151                 :            : 
+     152                 :            : /**
+     153                 :            :  * Reads a 16-bit value from memory that may be unaligned.
+     154                 :            :  *
+     155                 :            :  * @param  buffer  The pointer to a 16-bit value that may be unaligned.
+     156                 :            :  *
+     157                 :            :  * @return The 16-bit value read from buffer.
+     158                 :            :  **/
+     159                 :        309 : uint16_t libspdm_read_uint16(const uint8_t *buffer)
+     160                 :            : {
+     161                 :        309 :     return (uint16_t)(buffer[0] | buffer[1] << 8);
+     162                 :            : }
+     163                 :            : 
+     164                 :            : /**
+     165                 :            :  * Writes a 16-bit value to memory that may be unaligned.
+     166                 :            :  *
+     167                 :            :  * @param  buffer  The pointer to a 16-bit value that may be unaligned.
+     168                 :            :  * @param  value   16-bit value to write to buffer.
+     169                 :            :  **/
+     170                 :        240 : void libspdm_write_uint16(uint8_t *buffer, uint16_t value)
+     171                 :            : {
+     172                 :        240 :     buffer[0] = (uint8_t)(value & 0xFF);
+     173                 :        240 :     buffer[1] = (uint8_t)((value >> 8) & 0xFF);
+     174                 :        240 : }
+     175                 :            : 
+     176                 :            : /**
+     177                 :            :  * Reads a 32-bit value from memory that may be unaligned.
+     178                 :            :  *
+     179                 :            :  * @param  buffer  The pointer to a 32-bit value that may be unaligned.
+     180                 :            :  *
+     181                 :            :  * @return The 32-bit value read from buffer.
+     182                 :            :  **/
+     183                 :        472 : uint32_t libspdm_read_uint32(const uint8_t *buffer)
+     184                 :            : {
+     185                 :        472 :     return (uint32_t)(buffer[0] | buffer[1] << 8 | buffer[2] << 16 | buffer[3] << 24);
+     186                 :            : }
+     187                 :            : 
+     188                 :            : /**
+     189                 :            :  * Writes a 32-bit value to memory that may be unaligned.
+     190                 :            :  *
+     191                 :            :  * @param  buffer  The pointer to a 32-bit value that may be unaligned.
+     192                 :            :  * @param  value   32-bit value to write to buffer.
+     193                 :            :  **/
+     194                 :          4 : void libspdm_write_uint32(uint8_t *buffer, uint32_t value)
+     195                 :            : {
+     196                 :          4 :     buffer[0] = (uint8_t)(value & 0xFF);
+     197                 :          4 :     buffer[1] = (uint8_t)((value >> 8) & 0xFF);
+     198                 :          4 :     buffer[2] = (uint8_t)((value >> 16) & 0xFF);
+     199                 :          4 :     buffer[3] = (uint8_t)((value >> 24) & 0xFF);
+     200                 :          4 : }
+     201                 :            : 
+     202                 :            : /**
+     203                 :            :  * Reads a 64-bit value from memory that may be unaligned.
+     204                 :            :  *
+     205                 :            :  * @param  buffer  The pointer to a 64-bit value that may be unaligned.
+     206                 :            :  *
+     207                 :            :  * @return The 64-bit value read from buffer.
+     208                 :            :  **/
+     209                 :          0 : uint64_t libspdm_read_uint64(const uint8_t *buffer)
+     210                 :            : {
+     211                 :          0 :     return (uint64_t)(buffer[0]) |
+     212                 :          0 :            ((uint64_t)(buffer[1]) << 8) |
+     213                 :          0 :            ((uint64_t)(buffer[2]) << 16) |
+     214                 :          0 :            ((uint64_t)(buffer[3]) << 24) |
+     215                 :          0 :            ((uint64_t)(buffer[4]) << 32) |
+     216                 :          0 :            ((uint64_t)(buffer[5]) << 40) |
+     217                 :          0 :            ((uint64_t)(buffer[6]) << 48) |
+     218                 :          0 :            ((uint64_t)(buffer[7]) << 56);
+     219                 :            : }
+     220                 :            : 
+     221                 :            : /**
+     222                 :            :  * Writes a 64-bit value to memory that may be unaligned.
+     223                 :            :  *
+     224                 :            :  * @param  buffer  The pointer to a 64-bit value that may be unaligned.
+     225                 :            :  * @param  value   64-bit value to write to buffer.
+     226                 :            :  **/
+     227                 :          0 : void libspdm_write_uint64(uint8_t *buffer, uint64_t value)
+     228                 :            : {
+     229                 :          0 :     buffer[0] = (uint8_t)(value & 0xFF);
+     230                 :          0 :     buffer[1] = (uint8_t)((value >> 8) & 0xFF);
+     231                 :          0 :     buffer[2] = (uint8_t)((value >> 16) & 0xFF);
+     232                 :          0 :     buffer[3] = (uint8_t)((value >> 24) & 0xFF);
+     233                 :          0 :     buffer[4] = (uint8_t)((value >> 32) & 0xFF);
+     234                 :          0 :     buffer[5] = (uint8_t)((value >> 40) & 0xFF);
+     235                 :          0 :     buffer[6] = (uint8_t)((value >> 48) & 0xFF);
+     236                 :          0 :     buffer[7] = (uint8_t)((value >> 56) & 0xFF);
+     237                 :          0 : }
+     238                 :            : 
+     239                 :        439 : libspdm_return_t libspdm_append_managed_buffer(void *m_buffer, const void *buffer,
+     240                 :            :                                                size_t buffer_size)
+     241                 :            : {
+     242                 :            :     libspdm_managed_buffer_t *managed_buffer;
+     243                 :            : 
+     244         [ -  + ]:        439 :     LIBSPDM_ASSERT(buffer != NULL);
+     245                 :            : 
+     246         [ -  + ]:        439 :     if (buffer_size == 0) {
+     247                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     248                 :            :     }
+     249                 :            : 
+     250                 :        439 :     managed_buffer = m_buffer;
+     251                 :            : 
+     252         [ -  + ]:        439 :     LIBSPDM_ASSERT(buffer_size != 0);
+     253         [ -  + ]:        439 :     LIBSPDM_ASSERT(managed_buffer->max_buffer_size >= managed_buffer->buffer_size);
+     254                 :            : 
+     255         [ +  + ]:        439 :     if (buffer_size > managed_buffer->max_buffer_size - managed_buffer->buffer_size) {
+     256                 :            :         /* Do not LIBSPDM_ASSERT here, because command processor will append message from external.*/
+     257                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR,
+     258                 :            :                        "libspdm_append_managed_buffer 0x%x fail, rest 0x%x only\n",
+     259                 :            :                        (uint32_t)buffer_size,
+     260                 :            :                        (uint32_t)(managed_buffer->max_buffer_size - managed_buffer->buffer_size)));
+     261                 :          1 :         return LIBSPDM_STATUS_BUFFER_FULL;
+     262                 :            :     }
+     263         [ -  + ]:        438 :     LIBSPDM_ASSERT(buffer_size <= managed_buffer->max_buffer_size - managed_buffer->buffer_size);
+     264                 :            : 
+     265                 :        438 :     libspdm_copy_mem((uint8_t *)(managed_buffer + 1) + managed_buffer->buffer_size,
+     266                 :            :                      buffer_size, buffer, buffer_size);
+     267                 :        438 :     managed_buffer->buffer_size += buffer_size;
+     268                 :            : 
+     269                 :        438 :     return LIBSPDM_STATUS_SUCCESS;
+     270                 :            : }
+     271                 :            : 
+     272                 :        784 : void libspdm_reset_managed_buffer(void *m_buffer)
+     273                 :            : {
+     274                 :            :     libspdm_managed_buffer_t *managed_buffer;
+     275                 :            : 
+     276                 :        784 :     managed_buffer = m_buffer;
+     277                 :        784 :     managed_buffer->buffer_size = 0;
+     278                 :            : 
+     279                 :        784 :     libspdm_zero_mem(managed_buffer + 1, managed_buffer->max_buffer_size);
+     280                 :        784 : }
+     281                 :            : 
+     282                 :        635 : size_t libspdm_get_managed_buffer_size(void *m_buffer)
+     283                 :            : {
+     284                 :            :     libspdm_managed_buffer_t *managed_buffer;
+     285                 :            : 
+     286                 :        635 :     managed_buffer = m_buffer;
+     287                 :            : 
+     288                 :        635 :     return managed_buffer->buffer_size;
+     289                 :            : }
+     290                 :            : 
+     291                 :        624 : void *libspdm_get_managed_buffer(void *m_buffer)
+     292                 :            : {
+     293                 :            :     libspdm_managed_buffer_t *managed_buffer;
+     294                 :            : 
+     295                 :        624 :     managed_buffer = m_buffer;
+     296                 :            : 
+     297                 :        624 :     return (managed_buffer + 1);
+     298                 :            : }
+     299                 :            : 
+     300                 :        110 : void libspdm_init_managed_buffer(void *m_buffer, size_t max_buffer_size)
+     301                 :            : {
+     302                 :            :     libspdm_managed_buffer_t *managed_buffer;
+     303                 :            : 
+     304                 :        110 :     managed_buffer = m_buffer;
+     305                 :        110 :     managed_buffer->max_buffer_size = max_buffer_size;
+     306                 :            : 
+     307                 :        110 :     libspdm_reset_managed_buffer(m_buffer);
+     308                 :        110 : }
+     309                 :            : 
+     310                 :            : /**
+     311                 :            :  * byte3 - libspdm major version
+     312                 :            :  * byte2 - libspdm minor version
+     313                 :            :  * byte1 - libspdm patch version
+     314                 :            :  * byte0 - libspdm alpha
+     315                 :            :  *         (office release with tag: 0, release candidate with tag: 1, non official release: 0xFF)
+     316                 :            :  **/
+     317                 :          0 : uint32_t libspdm_module_version(void)
+     318                 :            : {
+     319                 :          0 :     return (LIBSPDM_MAJOR_VERSION << 24) |
+     320                 :            :            (LIBSPDM_MINOR_VERSION << 16) |
+     321                 :            :            (LIBSPDM_PATCH_VERSION << 8) |
+     322                 :            :            (LIBSPDM_ALPHA);
+     323                 :            : }
+     324                 :            : 
+     325                 :            : /*true: FIPS enabled, false: FIPS disabled*/
+     326                 :          0 : bool libspdm_get_fips_mode(void)
+     327                 :            : {
+     328                 :            : #if LIBSPDM_FIPS_MODE
+     329                 :          0 :     return true;
+     330                 :            : #else
+     331                 :            :     return false;
+     332                 :            : #endif
+     333                 :            : }
+     334                 :            : 
+     335                 :         70 : uint32_t libspdm_mask_capability_flags(libspdm_context_t *spdm_context,
+     336                 :            :                                        bool is_request_flags, uint32_t flags)
+     337                 :            : {
+     338   [ +  +  +  +  :         70 :     switch (libspdm_get_connection_version(spdm_context)) {
+                      - ]
+     339                 :          9 :     case SPDM_MESSAGE_VERSION_10:
+     340         [ +  + ]:          9 :         if (is_request_flags) {
+     341                 :            :             /* A 1.0 Requester does not have any capability flags. */
+     342                 :          2 :             return 0;
+     343                 :            :         } else {
+     344                 :          7 :             return (flags & SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_10_MASK);
+     345                 :            :         }
+     346                 :         45 :     case SPDM_MESSAGE_VERSION_11:
+     347         [ +  + ]:         45 :         if (is_request_flags) {
+     348                 :         39 :             return (flags & SPDM_GET_CAPABILITIES_REQUEST_FLAGS_11_MASK);
+     349                 :            :         } else {
+     350                 :          6 :             return (flags & SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_11_MASK);
+     351                 :            :         }
+     352                 :         12 :     case SPDM_MESSAGE_VERSION_12:
+     353         [ +  + ]:         12 :         if (is_request_flags) {
+     354                 :         10 :             return (flags & SPDM_GET_CAPABILITIES_REQUEST_FLAGS_12_MASK);
+     355                 :            :         } else {
+     356                 :          2 :             return (flags & SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_12_MASK);
+     357                 :            :         }
+     358                 :          4 :     case SPDM_MESSAGE_VERSION_13:
+     359         [ +  + ]:          4 :         if (is_request_flags) {
+     360                 :          2 :             return (flags & SPDM_GET_CAPABILITIES_REQUEST_FLAGS_13_MASK);
+     361                 :            :         } else {
+     362                 :          2 :             return (flags & SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_13_MASK);
+     363                 :            :         }
+     364                 :          0 :     default:
+     365                 :          0 :         LIBSPDM_ASSERT(false);
+     366                 :          0 :         return 0;
+     367                 :            :     }
+     368                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/index-sort-b.html b/coverage_log/library/spdm_crypt_lib/fips/index-sort-b.html new file mode 100644 index 00000000000..96e06a6b842 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/index-sort-b.html @@ -0,0 +1,239 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fipsHitTotalCoverage
Test:coverage.infoLines:33556059.8 %
Date:2024-09-22 08:21:07Functions:1919100.0 %
Branches:11322051.4 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
libspdm_selftest.c +
100.0%
+
100.0 %21 / 21100.0 %1 / 150.0 %1 / 2
libspdm_selftest_hkdf.c +
61.5%61.5%
+
61.5 %24 / 39100.0 %1 / 150.0 %8 / 16
libspdm_selftest_ecdh.c +
53.3%53.3%
+
53.3 %24 / 45100.0 %1 / 150.0 %9 / 18
libspdm_selftest_ecdsa.c +
53.1%53.1%
+
53.1 %34 / 64100.0 %2 / 250.0 %11 / 22
libspdm_selftest_aes_gcm.c +
57.4%57.4%
+
57.4 %31 / 54100.0 %1 / 150.0 %11 / 22
libspdm_selftest_rsa_pss.c +
52.2%52.2%
+
52.2 %35 / 67100.0 %1 / 150.0 %12 / 24
libspdm_selftest_sha2.c +
78.6%78.6%
+
78.6 %33 / 42100.0 %3 / 350.0 %12 / 24
libspdm_selftest_rsa_ssa.c +
49.3%49.3%
+
49.3 %33 / 67100.0 %1 / 150.0 %12 / 24
libspdm_selftest_ffdh.c +
43.7%43.7%
+
43.7 %31 / 71100.0 %1 / 150.0 %16 / 32
libspdm_selftest_hmac.c +
73.1%73.1%
+
73.1 %57 / 78100.0 %3 / 358.3 %21 / 36
libspdm_selftest_eddsa.c +
100.0%
+
100.0 %3 / 3100.0 %1 / 1-0 / 0
libspdm_selftest_sha3.c +
100.0%
+
100.0 %9 / 9100.0 %3 / 3-0 / 0
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/index-sort-f.html b/coverage_log/library/spdm_crypt_lib/fips/index-sort-f.html new file mode 100644 index 00000000000..5db3007561b --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/index-sort-f.html @@ -0,0 +1,239 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fipsHitTotalCoverage
Test:coverage.infoLines:33556059.8 %
Date:2024-09-22 08:21:07Functions:1919100.0 %
Branches:11322051.4 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
libspdm_selftest_eddsa.c +
100.0%
+
100.0 %3 / 3100.0 %1 / 1-0 / 0
libspdm_selftest_hkdf.c +
61.5%61.5%
+
61.5 %24 / 39100.0 %1 / 150.0 %8 / 16
libspdm_selftest_aes_gcm.c +
57.4%57.4%
+
57.4 %31 / 54100.0 %1 / 150.0 %11 / 22
libspdm_selftest_ffdh.c +
43.7%43.7%
+
43.7 %31 / 71100.0 %1 / 150.0 %16 / 32
libspdm_selftest_rsa_pss.c +
52.2%52.2%
+
52.2 %35 / 67100.0 %1 / 150.0 %12 / 24
libspdm_selftest.c +
100.0%
+
100.0 %21 / 21100.0 %1 / 150.0 %1 / 2
libspdm_selftest_ecdh.c +
53.3%53.3%
+
53.3 %24 / 45100.0 %1 / 150.0 %9 / 18
libspdm_selftest_rsa_ssa.c +
49.3%49.3%
+
49.3 %33 / 67100.0 %1 / 150.0 %12 / 24
libspdm_selftest_ecdsa.c +
53.1%53.1%
+
53.1 %34 / 64100.0 %2 / 250.0 %11 / 22
libspdm_selftest_sha2.c +
78.6%78.6%
+
78.6 %33 / 42100.0 %3 / 350.0 %12 / 24
libspdm_selftest_sha3.c +
100.0%
+
100.0 %9 / 9100.0 %3 / 3-0 / 0
libspdm_selftest_hmac.c +
73.1%73.1%
+
73.1 %57 / 78100.0 %3 / 358.3 %21 / 36
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/index-sort-l.html b/coverage_log/library/spdm_crypt_lib/fips/index-sort-l.html new file mode 100644 index 00000000000..10ba81b1118 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/index-sort-l.html @@ -0,0 +1,239 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fipsHitTotalCoverage
Test:coverage.infoLines:33556059.8 %
Date:2024-09-22 08:21:07Functions:1919100.0 %
Branches:11322051.4 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
libspdm_selftest_ffdh.c +
43.7%43.7%
+
43.7 %31 / 71100.0 %1 / 150.0 %16 / 32
libspdm_selftest_rsa_ssa.c +
49.3%49.3%
+
49.3 %33 / 67100.0 %1 / 150.0 %12 / 24
libspdm_selftest_rsa_pss.c +
52.2%52.2%
+
52.2 %35 / 67100.0 %1 / 150.0 %12 / 24
libspdm_selftest_ecdsa.c +
53.1%53.1%
+
53.1 %34 / 64100.0 %2 / 250.0 %11 / 22
libspdm_selftest_ecdh.c +
53.3%53.3%
+
53.3 %24 / 45100.0 %1 / 150.0 %9 / 18
libspdm_selftest_aes_gcm.c +
57.4%57.4%
+
57.4 %31 / 54100.0 %1 / 150.0 %11 / 22
libspdm_selftest_hkdf.c +
61.5%61.5%
+
61.5 %24 / 39100.0 %1 / 150.0 %8 / 16
libspdm_selftest_hmac.c +
73.1%73.1%
+
73.1 %57 / 78100.0 %3 / 358.3 %21 / 36
libspdm_selftest_sha2.c +
78.6%78.6%
+
78.6 %33 / 42100.0 %3 / 350.0 %12 / 24
libspdm_selftest_eddsa.c +
100.0%
+
100.0 %3 / 3100.0 %1 / 1-0 / 0
libspdm_selftest_sha3.c +
100.0%
+
100.0 %9 / 9100.0 %3 / 3-0 / 0
libspdm_selftest.c +
100.0%
+
100.0 %21 / 21100.0 %1 / 150.0 %1 / 2
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/index.html b/coverage_log/library/spdm_crypt_lib/fips/index.html new file mode 100644 index 00000000000..cd88270d5bc --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/index.html @@ -0,0 +1,239 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fipsHitTotalCoverage
Test:coverage.infoLines:33556059.8 %
Date:2024-09-22 08:21:07Functions:1919100.0 %
Branches:11322051.4 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
libspdm_selftest.c +
100.0%
+
100.0 %21 / 21100.0 %1 / 150.0 %1 / 2
libspdm_selftest_aes_gcm.c +
57.4%57.4%
+
57.4 %31 / 54100.0 %1 / 150.0 %11 / 22
libspdm_selftest_ecdh.c +
53.3%53.3%
+
53.3 %24 / 45100.0 %1 / 150.0 %9 / 18
libspdm_selftest_ecdsa.c +
53.1%53.1%
+
53.1 %34 / 64100.0 %2 / 250.0 %11 / 22
libspdm_selftest_eddsa.c +
100.0%
+
100.0 %3 / 3100.0 %1 / 1-0 / 0
libspdm_selftest_ffdh.c +
43.7%43.7%
+
43.7 %31 / 71100.0 %1 / 150.0 %16 / 32
libspdm_selftest_hkdf.c +
61.5%61.5%
+
61.5 %24 / 39100.0 %1 / 150.0 %8 / 16
libspdm_selftest_hmac.c +
73.1%73.1%
+
73.1 %57 / 78100.0 %3 / 358.3 %21 / 36
libspdm_selftest_rsa_pss.c +
52.2%52.2%
+
52.2 %35 / 67100.0 %1 / 150.0 %12 / 24
libspdm_selftest_rsa_ssa.c +
49.3%49.3%
+
49.3 %33 / 67100.0 %1 / 150.0 %12 / 24
libspdm_selftest_sha2.c +
78.6%78.6%
+
78.6 %33 / 42100.0 %3 / 350.0 %12 / 24
libspdm_selftest_sha3.c +
100.0%
+
100.0 %9 / 9100.0 %3 / 3-0 / 0
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest.c.func-sort-c.html b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest.c.func-sort-c.html new file mode 100644 index 00000000000..e444e1166fb --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips/libspdm_selftest.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fips - libspdm_selftest.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:2121100.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:1250.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_fips_run_selftest1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest.c.func.html b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest.c.func.html new file mode 100644 index 00000000000..fb16e3a31c5 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips/libspdm_selftest.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fips - libspdm_selftest.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:2121100.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:1250.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_fips_run_selftest1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest.c.gcov.html b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest.c.gcov.html new file mode 100644 index 00000000000..11185c11824 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest.c.gcov.html @@ -0,0 +1,136 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips/libspdm_selftest.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fips - libspdm_selftest.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:2121100.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:1250.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2023 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_crypt_lib.h"
+       8                 :            : #include "internal/libspdm_fips_lib.h"
+       9                 :            : #include "internal/libspdm_common_lib.h"
+      10                 :            : 
+      11                 :            : #if LIBSPDM_FIPS_MODE
+      12                 :            : 
+      13                 :            : /*run all of the self-tests and returns the results.*/
+      14                 :          1 : bool libspdm_fips_run_selftest(void *fips_selftest_context)
+      15                 :            : {
+      16                 :            :     libspdm_fips_selftest_context *context;
+      17         [ -  + ]:          1 :     LIBSPDM_ASSERT(fips_selftest_context != NULL);
+      18                 :            : 
+      19                 :          1 :     context = fips_selftest_context;
+      20                 :            : 
+      21                 :          1 :     libspdm_fips_selftest_hmac_sha256(context);
+      22                 :          1 :     libspdm_fips_selftest_hmac_sha384(context);
+      23                 :          1 :     libspdm_fips_selftest_hmac_sha512(context);
+      24                 :            : 
+      25                 :          1 :     libspdm_fips_selftest_aes_gcm(context);
+      26                 :            : 
+      27                 :          1 :     libspdm_fips_selftest_rsa_ssa(context);
+      28                 :          1 :     libspdm_fips_selftest_rsa_pss(context);
+      29                 :            : 
+      30                 :          1 :     libspdm_fips_selftest_hkdf(context);
+      31                 :            : 
+      32                 :          1 :     libspdm_fips_selftest_ecdh(context);
+      33                 :            : 
+      34                 :          1 :     libspdm_fips_selftest_sha256(context);
+      35                 :          1 :     libspdm_fips_selftest_sha384(context);
+      36                 :          1 :     libspdm_fips_selftest_sha512(context);
+      37                 :            : 
+      38                 :          1 :     libspdm_fips_selftest_sha3_256(context);
+      39                 :          1 :     libspdm_fips_selftest_sha3_384(context);
+      40                 :          1 :     libspdm_fips_selftest_sha3_512(context);
+      41                 :            : 
+      42                 :          1 :     libspdm_fips_selftest_ffdh(context);
+      43                 :            : 
+      44                 :          1 :     libspdm_fips_selftest_ecdsa(context);
+      45                 :            : 
+      46                 :          1 :     libspdm_fips_selftest_eddsa(context);
+      47                 :            : 
+      48                 :          1 :     return (context->tested_algo == context->self_test_result);
+      49                 :            : }
+      50                 :            : 
+      51                 :            : #endif/*LIBSPDM_FIPS_MODE*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_aes_gcm.c.func-sort-c.html b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_aes_gcm.c.func-sort-c.html new file mode 100644 index 00000000000..7d2a56bba31 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_aes_gcm.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips/libspdm_selftest_aes_gcm.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fips - libspdm_selftest_aes_gcm.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:315457.4 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:112250.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_fips_selftest_aes_gcm1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_aes_gcm.c.func.html b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_aes_gcm.c.func.html new file mode 100644 index 00000000000..f124592aa9d --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_aes_gcm.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips/libspdm_selftest_aes_gcm.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fips - libspdm_selftest_aes_gcm.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:315457.4 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:112250.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_fips_selftest_aes_gcm1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_aes_gcm.c.gcov.html b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_aes_gcm.c.gcov.html new file mode 100644 index 00000000000..eb54274bd43 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_aes_gcm.c.gcov.html @@ -0,0 +1,261 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips/libspdm_selftest_aes_gcm.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fips - libspdm_selftest_aes_gcm.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:315457.4 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:112250.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2023 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_crypt_lib.h"
+       8                 :            : #include "internal/libspdm_common_lib.h"
+       9                 :            : #include "internal/libspdm_fips_lib.h"
+      10                 :            : 
+      11                 :            : #if LIBSPDM_FIPS_MODE
+      12                 :            : 
+      13                 :            : /**
+      14                 :            :  * AES_GCM self_test
+      15                 :            :  **/
+      16                 :          1 : bool libspdm_fips_selftest_aes_gcm(void *fips_selftest_context)
+      17                 :            : {
+      18                 :          1 :     bool result = true;
+      19                 :            : 
+      20                 :            : #if LIBSPDM_AEAD_GCM_SUPPORT
+      21                 :          1 :     libspdm_fips_selftest_context *context = fips_selftest_context;
+      22         [ -  + ]:          1 :     LIBSPDM_ASSERT(fips_selftest_context != NULL);
+      23                 :            : 
+      24                 :            :     /* any test fail cause the FIPS fail*/
+      25         [ -  + ]:          1 :     if (context->tested_algo != context->self_test_result) {
+      26                 :          0 :         return false;
+      27                 :            :     }
+      28                 :            : 
+      29                 :            :     /* check if run before.*/
+      30         [ -  + ]:          1 :     if ((context->tested_algo & LIBSPDM_FIPS_SELF_TEST_AES_GCM) != 0) {
+      31                 :          0 :         return true;
+      32                 :            :     }
+      33                 :            : 
+      34                 :            :     uint8_t output_ciphertext[1024];
+      35                 :            :     uint8_t output_plaintext[1024];
+      36                 :            :     uint8_t output_tag[1024];
+      37                 :            :     size_t output_ciphertext_size;
+      38                 :            :     size_t output_plaintext_size;
+      39                 :            : 
+      40                 :          1 :     output_ciphertext_size = sizeof(output_ciphertext);
+      41                 :          1 :     output_plaintext_size = sizeof(output_plaintext);
+      42                 :            : 
+      43                 :            :     /*Key to use crypto operation*/
+      44                 :          1 :     const uint8_t key[] = {
+      45                 :            :         0x01, 0xd1, 0xa6, 0x9e, 0x73, 0x7f, 0xf2, 0xea,
+      46                 :            :         0x53, 0x56, 0x6f, 0xa2, 0xd7, 0xc0, 0x80, 0xd6
+      47                 :            :     };
+      48                 :            : 
+      49                 :            :     /*IV to perform the crypto operation upon*/
+      50                 :          1 :     const uint8_t iv[] = {
+      51                 :            :         0x0f, 0x3e, 0xd5, 0x9c, 0xa5, 0xb3, 0x0f, 0xb5,
+      52                 :            :         0xea, 0x4e, 0x13, 0x60
+      53                 :            :     };
+      54                 :            : 
+      55                 :            :     /*Data to perform the crypto operation upon*/
+      56                 :          1 :     const uint8_t input[] = {
+      57                 :            :         0xf6, 0x28, 0xc8, 0x61, 0xe5, 0x97, 0x04, 0xd9,
+      58                 :            :         0xba, 0xc8, 0x00, 0xc0, 0x4c, 0x1a, 0x2d, 0x7e,
+      59                 :            :         0x6c, 0x44, 0x61, 0x3f, 0xa4, 0x64, 0xb0, 0xe1,
+      60                 :            :         0x17, 0x3d, 0x8d, 0xba, 0xc0, 0x14, 0x72, 0xd3,
+      61                 :            :         0xc6, 0x8a, 0x5e, 0xb4, 0xf3, 0x16, 0x7f, 0xd0,
+      62                 :            :         0x21, 0x29, 0x76, 0x85, 0x86, 0x4d, 0x78, 0x86,
+      63                 :            :         0x14, 0x98, 0x32, 0x5e, 0xa6, 0xda, 0x6f, 0xce,
+      64                 :            :         0x98, 0x2c, 0xe9, 0x6e, 0xaa, 0x77, 0x18, 0xb8,
+      65                 :            :         0x89, 0xb7, 0x2d, 0x13, 0xc5, 0x61, 0xb3, 0xaf,
+      66                 :            :         0xe7, 0x13, 0xa7, 0x38, 0x45, 0xd4, 0x4c, 0x4a,
+      67                 :            :         0xc6, 0xdc, 0xe5, 0x29, 0x6c, 0xd5, 0xd9, 0xc6,
+      68                 :            :         0xde, 0xe2, 0x5d, 0x78, 0xfd, 0xa7, 0x3a, 0x45,
+      69                 :            :         0x7e, 0xdf, 0x00, 0xd0, 0x6a, 0xb0, 0xe8, 0x3a,
+      70                 :            :         0x86, 0x48, 0xa7, 0xaf, 0x7e, 0x6f, 0x33, 0xb2
+      71                 :            :     };
+      72                 :            : 
+      73                 :            :     /*Additional auth data*/
+      74                 :          1 :     const uint8_t aad[] = {
+      75                 :            :         0x66, 0x2a, 0x0a, 0x62, 0xe2, 0xb5, 0xa5, 0xa9,
+      76                 :            :         0xae, 0x46, 0x19, 0x16, 0x46, 0xf5, 0x26, 0xd8,
+      77                 :            :         0x8b, 0xf1, 0xac, 0xe1, 0x11, 0xee, 0xcf, 0x66,
+      78                 :            :         0x8c, 0x3b, 0xde, 0x57, 0x42, 0x2b, 0xa8, 0x02,
+      79                 :            :         0xc4, 0x60, 0x24, 0xb3, 0xa3, 0x84, 0xb5, 0x52,
+      80                 :            :         0x12, 0x98, 0xfe, 0x1e
+      81                 :            :     };
+      82                 :            : 
+      83                 :            :     /*Expected ciphertext*/
+      84                 :          1 :     const uint8_t expected_ciphertext[] = {
+      85                 :            :         0x2d, 0x4a, 0x0b, 0x34, 0x20, 0xcd, 0x7a, 0xe7,
+      86                 :            :         0x91, 0x1e, 0x5a, 0x53, 0x5e, 0x2b, 0x7b, 0x8e,
+      87                 :            :         0x42, 0x37, 0xf0, 0xeb, 0x5a, 0x84, 0xc5, 0xea,
+      88                 :            :         0x95, 0xd3, 0xe7, 0xe2, 0xb4, 0xb8, 0x88, 0xe0,
+      89                 :            :         0x4f, 0x28, 0xe3, 0x41, 0x7f, 0x05, 0x8d, 0x7c,
+      90                 :            :         0x4d, 0xae, 0x05, 0x92, 0xfc, 0x27, 0xfc, 0x67,
+      91                 :            :         0x94, 0x9f, 0x24, 0xa5, 0x5e, 0x70, 0xd9, 0xa7,
+      92                 :            :         0xb3, 0xd2, 0x78, 0xf0, 0xcd, 0x75, 0x4e, 0x43,
+      93                 :            :         0xe8, 0xad, 0xd4, 0x54, 0x57, 0xf8, 0x67, 0x1d,
+      94                 :            :         0x31, 0xbf, 0x45, 0xef, 0x1f, 0xaf, 0xec, 0x3b,
+      95                 :            :         0x4b, 0x3c, 0x90, 0x65, 0x83, 0x32, 0x6c, 0x9b,
+      96                 :            :         0x5c, 0xc2, 0x30, 0xc4, 0x5a, 0x6e, 0xec, 0x74,
+      97                 :            :         0xe3, 0x51, 0x11, 0xb5, 0x51, 0x04, 0xc5, 0xc0,
+      98                 :            :         0x68, 0x50, 0xc4, 0xb8, 0xd1, 0x9a, 0x8e, 0x37
+      99                 :            :     };
+     100                 :            : 
+     101                 :            :     /*Expected Auth Tag*/
+     102                 :          1 :     const uint8_t expected_tag[] = {
+     103                 :            :         0xc1, 0x37, 0xee, 0x11, 0x32, 0xf3, 0x75, 0x0a,
+     104                 :            :         0xd6, 0x57, 0x78, 0x77, 0x40, 0x05, 0x91, 0x41
+     105                 :            :     };
+     106                 :            : 
+     107                 :            :     /*KAT test*/
+     108                 :          1 :     libspdm_zero_mem(output_ciphertext, sizeof(output_ciphertext));
+     109                 :          1 :     libspdm_zero_mem(output_tag, sizeof(output_tag));
+     110                 :          1 :     result = libspdm_aead_aes_gcm_encrypt(key, sizeof(key), iv, sizeof(iv), aad, sizeof(aad),
+     111                 :            :                                           input, sizeof(input), output_tag, sizeof(expected_tag),
+     112                 :            :                                           output_ciphertext, &output_ciphertext_size);
+     113         [ -  + ]:          1 :     if (!result) {
+     114                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "aes_gcm encrypt failed \n"));
+     115                 :          0 :         goto update;
+     116                 :            :     }
+     117                 :            : 
+     118         [ -  + ]:          1 :     if (output_ciphertext_size != sizeof(expected_ciphertext)) {
+     119                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "aes_gcm KAT failed \n"));
+     120                 :          0 :         result = false;
+     121                 :          0 :         goto update;
+     122                 :            :     }
+     123                 :            : 
+     124         [ -  + ]:          1 :     if (!libspdm_consttime_is_mem_equal(output_ciphertext, expected_ciphertext,
+     125                 :            :                                         sizeof(expected_ciphertext))) {
+     126                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "aes_gcm KAT failed \n"));
+     127                 :          0 :         result = false;
+     128                 :          0 :         goto update;
+     129                 :            :     }
+     130                 :            : 
+     131         [ -  + ]:          1 :     if (!libspdm_consttime_is_mem_equal(output_tag, expected_tag, sizeof(expected_tag))) {
+     132                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "aes_gcm KAT failed \n"));
+     133                 :          0 :         result = false;
+     134                 :          0 :         goto update;
+     135                 :            :     }
+     136                 :            : 
+     137                 :          1 :     libspdm_zero_mem(output_plaintext, sizeof(output_plaintext));
+     138                 :          1 :     result = libspdm_aead_aes_gcm_decrypt(key, sizeof(key), iv, sizeof(iv), aad, sizeof(aad),
+     139                 :            :                                           expected_ciphertext, sizeof(expected_ciphertext),
+     140                 :            :                                           expected_tag, sizeof(expected_tag),
+     141                 :            :                                           output_plaintext, &output_plaintext_size);
+     142         [ -  + ]:          1 :     if (!result) {
+     143                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "aes_gcm decrypt failed \n"));
+     144                 :          0 :         result = false;
+     145                 :          0 :         goto update;
+     146                 :            :     }
+     147                 :            : 
+     148         [ -  + ]:          1 :     if (output_plaintext_size != sizeof(input)) {
+     149                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "aes_gcm selftest failed \n"));
+     150                 :          0 :         result = false;
+     151                 :          0 :         goto update;
+     152                 :            :     }
+     153                 :            : 
+     154         [ +  - ]:          1 :     if (!libspdm_consttime_is_mem_equal(output_plaintext, input, sizeof(input))) {
+     155                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "aes_gcm selftest failed \n"));
+     156                 :          0 :         result = false;
+     157                 :          0 :         goto update;
+     158                 :            :     }
+     159                 :            : 
+     160                 :          1 : update:
+     161                 :            :     /* mark it as tested*/
+     162                 :          1 :     context->tested_algo |= LIBSPDM_FIPS_SELF_TEST_AES_GCM;
+     163                 :            : 
+     164                 :            :     /* record test result*/
+     165         [ +  - ]:          1 :     if (result) {
+     166                 :          1 :         context->self_test_result |= LIBSPDM_FIPS_SELF_TEST_AES_GCM;
+     167                 :            :     } else {
+     168                 :          0 :         context->self_test_result &= ~LIBSPDM_FIPS_SELF_TEST_AES_GCM;
+     169                 :            :     }
+     170                 :            : 
+     171                 :            : #endif/*LIBSPDM_AEAD_GCM_SUPPORT*/
+     172                 :            : 
+     173                 :          1 :     return result;
+     174                 :            : }
+     175                 :            : 
+     176                 :            : #endif
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_ecdh.c.func-sort-c.html b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_ecdh.c.func-sort-c.html new file mode 100644 index 00000000000..3a9c730d9a5 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_ecdh.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips/libspdm_selftest_ecdh.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fips - libspdm_selftest_ecdh.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:244553.3 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:91850.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_fips_selftest_ecdh1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_ecdh.c.func.html b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_ecdh.c.func.html new file mode 100644 index 00000000000..0ed59446e1a --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_ecdh.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips/libspdm_selftest_ecdh.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fips - libspdm_selftest_ecdh.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:244553.3 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:91850.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_fips_selftest_ecdh1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_ecdh.c.gcov.html b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_ecdh.c.gcov.html new file mode 100644 index 00000000000..d1b9adcd070 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_ecdh.c.gcov.html @@ -0,0 +1,208 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips/libspdm_selftest_ecdh.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fips - libspdm_selftest_ecdh.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:244553.3 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:91850.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2023 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_crypt_lib.h"
+       8                 :            : #include "internal/libspdm_common_lib.h"
+       9                 :            : #include "internal/libspdm_fips_lib.h"
+      10                 :            : 
+      11                 :            : #if LIBSPDM_FIPS_MODE
+      12                 :            : 
+      13                 :            : /**
+      14                 :            :  * ECDH self_test
+      15                 :            :  **/
+      16                 :          1 : bool libspdm_fips_selftest_ecdh(void *fips_selftest_context)
+      17                 :            : {
+      18                 :          1 :     bool result = true;
+      19                 :            : 
+      20                 :            : #if LIBSPDM_ECDHE_SUPPORT
+      21                 :          1 :     libspdm_fips_selftest_context *context = fips_selftest_context;
+      22         [ -  + ]:          1 :     LIBSPDM_ASSERT(fips_selftest_context != NULL);
+      23                 :            : 
+      24                 :            :     /* any test fail cause the FIPS fail*/
+      25         [ -  + ]:          1 :     if (context->tested_algo != context->self_test_result) {
+      26                 :          0 :         return false;
+      27                 :            :     }
+      28                 :            : 
+      29                 :            :     /* check if run before.*/
+      30         [ -  + ]:          1 :     if ((context->tested_algo & LIBSPDM_FIPS_SELF_TEST_ECDH) != 0) {
+      31                 :          0 :         return true;
+      32                 :            :     }
+      33                 :            : 
+      34                 :            :     void *ec_context;
+      35                 :            :     uint8_t common_key[66];
+      36                 :            :     size_t common_key_length;
+      37                 :            : 
+      38                 :          1 :     common_key_length = sizeof(common_key);
+      39                 :          1 :     libspdm_zero_mem(common_key, common_key_length);
+      40                 :            :     /* self private Key*/
+      41                 :          1 :     const uint8_t self_privkey[] = {
+      42                 :            :         0xd6, 0x84, 0xd1, 0x7c, 0xe3, 0x6b, 0xe7, 0x08,
+      43                 :            :         0xbc, 0xd9, 0x89, 0x3f, 0xbb, 0xf4, 0xf2, 0xcf,
+      44                 :            :         0x8d, 0x7f, 0xd4, 0x72, 0xbc, 0xfb, 0x54, 0x29,
+      45                 :            :         0xd9, 0x86, 0xe2, 0x86, 0xc2, 0x38, 0xe5, 0x88
+      46                 :            :     };
+      47                 :            : 
+      48                 :            :     /* peer public Key*/
+      49                 :          1 :     const uint8_t peer_public[] = {
+      50                 :            :         0x54, 0xbc, 0x5f, 0x6b, 0x70, 0x9b, 0x29, 0x5c,
+      51                 :            :         0xa9, 0x43, 0xd0, 0xb7, 0xf3, 0xa2, 0x4b, 0xf0,
+      52                 :            :         0x76, 0xb1, 0xd1, 0x9f, 0x55, 0x6a, 0x4e, 0xa0,
+      53                 :            :         0x40, 0x54, 0xd2, 0xb1, 0x2f, 0x0f, 0xc1, 0x6d,
+      54                 :            :         0xe7, 0x53, 0xe1, 0x3a, 0xd9, 0xb9, 0x2d, 0xd6,
+      55                 :            :         0x3a, 0xda, 0x9d, 0xa9, 0xa9, 0x4e, 0xdd, 0x30,
+      56                 :            :         0x60, 0x24, 0x9f, 0x9d, 0xcb, 0xfc, 0x1a, 0x56,
+      57                 :            :         0x35, 0x63, 0x64, 0xe2, 0x64, 0xcf, 0x00, 0xed
+      58                 :            :     };
+      59                 :            : 
+      60                 :            :     /* expected ecdh common secret*/
+      61                 :          1 :     const uint8_t expected_ecdh_secret[] = {
+      62                 :            :         0x05, 0xd5, 0xc8, 0x66, 0x83, 0x59, 0xe8, 0x33,
+      63                 :            :         0x1d, 0xb7, 0x68, 0x2f, 0x98, 0x71, 0x2f, 0xfe,
+      64                 :            :         0x2d, 0xfa, 0x10, 0xe6, 0x67, 0x89, 0x81, 0xd8,
+      65                 :            :         0x51, 0xd9, 0x72, 0x47, 0x17, 0x7b, 0xa3, 0x5e
+      66                 :            :     };
+      67                 :            : 
+      68                 :          1 :     ec_context = libspdm_ec_new_by_nid(LIBSPDM_CRYPTO_NID_ECDSA_NIST_P256);
+      69         [ -  + ]:          1 :     if (ec_context == NULL) {
+      70                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "ECDH new failed \n"));
+      71                 :          0 :         result = false;
+      72                 :          0 :         goto update;
+      73                 :            :     }
+      74                 :            : 
+      75                 :          1 :     result = libspdm_ec_set_priv_key(ec_context, self_privkey, sizeof(self_privkey));
+      76         [ -  + ]:          1 :     if (!result) {
+      77                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "ECDH set private key failed \n"));
+      78                 :          0 :         libspdm_ec_free(ec_context);
+      79                 :          0 :         result = false;
+      80                 :          0 :         goto update;
+      81                 :            :     }
+      82                 :            : 
+      83                 :          1 :     result = libspdm_ec_compute_key(ec_context, peer_public, sizeof(peer_public), common_key,
+      84                 :            :                                     &common_key_length);
+      85         [ -  + ]:          1 :     if (!result) {
+      86                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "ECDH compute key failed \n"));
+      87                 :          0 :         libspdm_ec_free(ec_context);
+      88                 :          0 :         result = false;
+      89                 :          0 :         goto update;
+      90                 :            :     }
+      91                 :            : 
+      92                 :            :     /*KAT test*/
+      93         [ -  + ]:          1 :     if (common_key_length != sizeof(expected_ecdh_secret)) {
+      94                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "ECDH KAT failed \n"));
+      95                 :          0 :         libspdm_ec_free(ec_context);
+      96                 :          0 :         result = false;
+      97                 :          0 :         goto update;
+      98                 :            :     }
+      99                 :            : 
+     100         [ +  - ]:          1 :     if (!libspdm_consttime_is_mem_equal(common_key, expected_ecdh_secret,
+     101                 :            :                                         sizeof(expected_ecdh_secret))) {
+     102                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "ECDH KAT failed \n"));
+     103                 :          0 :         result = false;
+     104                 :          0 :         goto update;
+     105                 :            :     }
+     106                 :            : 
+     107                 :          1 : update:
+     108                 :            :     /* mark it as tested*/
+     109                 :          1 :     context->tested_algo |= LIBSPDM_FIPS_SELF_TEST_ECDH;
+     110                 :            : 
+     111                 :            :     /* record test result*/
+     112         [ +  - ]:          1 :     if (result) {
+     113                 :          1 :         context->self_test_result |= LIBSPDM_FIPS_SELF_TEST_ECDH;
+     114                 :            :     } else {
+     115                 :          0 :         context->self_test_result &= ~LIBSPDM_FIPS_SELF_TEST_ECDH;
+     116                 :            :     }
+     117                 :            : 
+     118                 :            : #endif/*LIBSPDM_ECDHE_SUPPORT*/
+     119                 :            : 
+     120                 :          1 :     return result;
+     121                 :            : }
+     122                 :            : 
+     123                 :            : #endif/*LIBSPDM_FIPS_MODE*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_ecdsa.c.func-sort-c.html b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_ecdsa.c.func-sort-c.html new file mode 100644 index 00000000000..740d2ce54f0 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_ecdsa.c.func-sort-c.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips/libspdm_selftest_ecdsa.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fips - libspdm_selftest_ecdsa.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:346453.1 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:112250.0 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_fips_selftest_ecdsa1
libspdm_hardcode_random_number_ecdsa4
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_ecdsa.c.func.html b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_ecdsa.c.func.html new file mode 100644 index 00000000000..75b29a3e976 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_ecdsa.c.func.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips/libspdm_selftest_ecdsa.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fips - libspdm_selftest_ecdsa.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:346453.1 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:112250.0 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_fips_selftest_ecdsa1
libspdm_hardcode_random_number_ecdsa4
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_ecdsa.c.gcov.html b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_ecdsa.c.gcov.html new file mode 100644 index 00000000000..952858aeac6 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_ecdsa.c.gcov.html @@ -0,0 +1,259 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips/libspdm_selftest_ecdsa.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fips - libspdm_selftest_ecdsa.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:346453.1 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:112250.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2023 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_crypt_lib.h"
+       8                 :            : #include "internal/libspdm_common_lib.h"
+       9                 :            : #include "internal/libspdm_fips_lib.h"
+      10                 :            : 
+      11                 :            : #if LIBSPDM_FIPS_MODE
+      12                 :            : 
+      13                 :            : /*hardcode random for ecdsa*/
+      14                 :          4 : int libspdm_hardcode_random_number_ecdsa(void *rng_state, unsigned char *output, size_t len)
+      15                 :            : {
+      16                 :            :     /*Random number*/
+      17                 :          4 :     const uint8_t random[] = {
+      18                 :            :         0x01, 0x5b, 0x92, 0x22, 0xfc, 0x35, 0xc5, 0x2b,
+      19                 :            :         0x79, 0x1c, 0xcd, 0x37, 0x07, 0x7d, 0xae, 0x6a,
+      20                 :            :         0x88, 0x1f, 0x7d, 0x03, 0x30, 0x92, 0x67, 0x47,
+      21                 :            :         0x0b, 0xce, 0x31, 0x7c, 0x46, 0xdd, 0x90, 0xbf
+      22                 :            :     };
+      23                 :          4 :     libspdm_copy_mem(output, len, random, sizeof(random));
+      24                 :            : 
+      25                 :          4 :     return 0;
+      26                 :            : }
+      27                 :            : 
+      28                 :            : /**
+      29                 :            :  * ECDSA self_test
+      30                 :            :  **/
+      31                 :          1 : bool libspdm_fips_selftest_ecdsa(void *fips_selftest_context)
+      32                 :            : {
+      33                 :          1 :     bool result = true;
+      34                 :            : 
+      35                 :            : #if LIBSPDM_ECDSA_SUPPORT
+      36                 :          1 :     libspdm_fips_selftest_context *context = fips_selftest_context;
+      37         [ -  + ]:          1 :     LIBSPDM_ASSERT(fips_selftest_context != NULL);
+      38                 :            : 
+      39                 :            :     /* any test fail cause the FIPS fail*/
+      40         [ -  + ]:          1 :     if (context->tested_algo != context->self_test_result) {
+      41                 :          0 :         return false;
+      42                 :            :     }
+      43                 :            : 
+      44                 :            :     /* check if run before.*/
+      45         [ -  + ]:          1 :     if ((context->tested_algo & LIBSPDM_FIPS_SELF_TEST_ECDSA) != 0) {
+      46                 :          0 :         return true;
+      47                 :            :     }
+      48                 :            : 
+      49                 :            :     uint8_t signature[32 * 2];
+      50                 :            :     size_t sig_size;
+      51                 :            :     void *ec_context;
+      52                 :            : 
+      53                 :          1 :     sig_size = sizeof(signature);
+      54                 :          1 :     libspdm_zero_mem(signature, sig_size);
+      55                 :            : 
+      56                 :            :     /* Message hash */
+      57                 :          1 :     const uint8_t message_hash[] = {
+      58                 :            :         0x9a, 0x1b, 0x6d, 0xe3, 0xff, 0xd0, 0x7e, 0x77,
+      59                 :            :         0xe2, 0x54, 0xc6, 0x27, 0x9a, 0xc3, 0x28, 0x07,
+      60                 :            :         0x42, 0x43, 0x1a, 0x32, 0xc8, 0xaf, 0x0c, 0x87,
+      61                 :            :         0x94, 0xff, 0x40, 0x75, 0x09, 0xfe, 0x40, 0xd8
+      62                 :            :     };
+      63                 :            : 
+      64                 :            :     /* Private Key */
+      65                 :          1 :     const uint8_t priv_key[] = {
+      66                 :            :         0xd6, 0x84, 0xd1, 0x7c, 0xe3, 0x6b, 0xe7, 0x08,
+      67                 :            :         0xbc, 0xd9, 0x89, 0x3f, 0xbb, 0xf4, 0xf2, 0xcf,
+      68                 :            :         0x8d, 0x7f, 0xd4, 0x72, 0xbc, 0xfb, 0x54, 0x29,
+      69                 :            :         0xd9, 0x86, 0xe2, 0x86, 0xc2, 0x38, 0xe5, 0xed
+      70                 :            :     };
+      71                 :            : 
+      72                 :            :     /* Public Key */
+      73                 :          1 :     const uint8_t public_key[] = {
+      74                 :            :         0x54, 0xbc, 0x5f, 0x6b, 0x70, 0x9b, 0x29, 0x5c,
+      75                 :            :         0xa9, 0x43, 0xd0, 0xb7, 0xf3, 0xa2, 0x4b, 0xf0,
+      76                 :            :         0x76, 0xb1, 0xd1, 0x9f, 0x55, 0x6a, 0x4e, 0xa0,
+      77                 :            :         0x40, 0x54, 0xd2, 0xb1, 0x2f, 0x0f, 0xc1, 0x6d,
+      78                 :            :         0xe7, 0x53, 0xe1, 0x3a, 0xd9, 0xb9, 0x2d, 0xd6,
+      79                 :            :         0x3a, 0xda, 0x9d, 0xa9, 0xa9, 0x4e, 0xdd, 0x30,
+      80                 :            :         0x60, 0x24, 0x9f, 0x9d, 0xcb, 0xfc, 0x1a, 0x56,
+      81                 :            :         0x35, 0x63, 0x64, 0xe2, 0x64, 0xcf, 0x00, 0xed
+      82                 :            :     };
+      83                 :            : 
+      84                 :            :     /* Expected signature*/
+      85                 :          1 :     const uint8_t expected_signature[] = {
+      86                 :            :         0xe1, 0x6a, 0xe9, 0x76, 0x61, 0x97, 0x8e, 0xe9,
+      87                 :            :         0xc7, 0x0f, 0xe0, 0x20, 0xc0, 0x65, 0xe1, 0x6c,
+      88                 :            :         0x89, 0x6f, 0x24, 0x6b, 0x4e, 0x88, 0x10, 0xcd,
+      89                 :            :         0xb4, 0x9a, 0xcc, 0x20, 0xcf, 0xa5, 0xb0, 0xc9,
+      90                 :            :         0xc1, 0x02, 0x4b, 0xa7, 0x41, 0xef, 0x51, 0x8f,
+      91                 :            :         0xe3, 0x11, 0xec, 0x95, 0xe2, 0xf4, 0x83, 0x97,
+      92                 :            :         0x3d, 0x32, 0x72, 0xf6, 0x4b, 0x34, 0xd3, 0x9f,
+      93                 :            :         0x25, 0x6a, 0x12, 0x3b, 0x7c, 0x87, 0xc4, 0x4d
+      94                 :            :     };
+      95                 :            : 
+      96                 :          1 :     ec_context = libspdm_ec_new_by_nid(LIBSPDM_CRYPTO_NID_ECDSA_NIST_P256);
+      97         [ -  + ]:          1 :     if (ec_context == NULL) {
+      98                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "ec_context new failed \n"));
+      99                 :          0 :         result = false;
+     100                 :          0 :         goto update;
+     101                 :            :     }
+     102                 :            : 
+     103                 :          1 :     result = libspdm_ec_set_pub_key(ec_context, public_key, sizeof(public_key));
+     104         [ -  + ]:          1 :     if (!result) {
+     105                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "ec_context set pub_key failed \n"));
+     106                 :          0 :         libspdm_ec_free(ec_context);
+     107                 :          0 :         result = false;
+     108                 :          0 :         goto update;
+     109                 :            :     }
+     110                 :            : 
+     111                 :          1 :     result = libspdm_ec_set_priv_key(ec_context, priv_key, sizeof(priv_key));
+     112         [ -  + ]:          1 :     if (!result) {
+     113                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "ec_context set priv_key failed \n"));
+     114                 :          0 :         libspdm_ec_free(ec_context);
+     115                 :          0 :         result = false;
+     116                 :          0 :         goto update;
+     117                 :            :     }
+     118                 :            : 
+     119                 :            :     /*ECDSA KAT test*/
+     120                 :          1 :     result = libspdm_ecdsa_sign_ex(ec_context, LIBSPDM_CRYPTO_NID_SHA256,
+     121                 :            :                                    message_hash, sizeof(message_hash),
+     122                 :            :                                    signature, &sig_size,
+     123                 :            :                                    libspdm_hardcode_random_number_ecdsa);
+     124         [ -  + ]:          1 :     if (!result) {
+     125                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "ECDSA sign failed \n"));
+     126                 :          0 :         libspdm_ec_free(ec_context);
+     127                 :          0 :         result = false;
+     128                 :          0 :         goto update;
+     129                 :            :     }
+     130                 :            : 
+     131         [ -  + ]:          1 :     if (sig_size != sizeof(expected_signature)) {
+     132                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "ECDSA KAT failed \n"));
+     133                 :          0 :         libspdm_ec_free(ec_context);
+     134                 :          0 :         result = false;
+     135                 :          0 :         goto update;
+     136                 :            :     }
+     137                 :            : 
+     138         [ -  + ]:          1 :     if (!libspdm_consttime_is_mem_equal(signature, expected_signature,
+     139                 :            :                                         sizeof(expected_signature))) {
+     140                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "ECDSA KAT failed \n"));
+     141                 :          0 :         libspdm_ec_free(ec_context);
+     142                 :          0 :         result = false;
+     143                 :          0 :         goto update;
+     144                 :            :     }
+     145                 :            : 
+     146                 :          1 :     result = libspdm_ecdsa_verify(ec_context, LIBSPDM_CRYPTO_NID_SHA256,
+     147                 :            :                                   message_hash, sizeof(message_hash),
+     148                 :            :                                   signature, sig_size);
+     149         [ -  + ]:          1 :     if (!result) {
+     150                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "ECDSA selftest failed \n"));
+     151                 :          0 :         libspdm_ec_free(ec_context);
+     152                 :          0 :         result = false;
+     153                 :          0 :         goto update;
+     154                 :            :     }
+     155                 :            : 
+     156                 :          1 :     libspdm_ec_free(ec_context);
+     157                 :            : 
+     158                 :          1 : update:
+     159                 :            :     /* mark it as tested*/
+     160                 :          1 :     context->tested_algo |= LIBSPDM_FIPS_SELF_TEST_ECDSA;
+     161                 :            : 
+     162                 :            :     /* record test result*/
+     163         [ +  - ]:          1 :     if (result) {
+     164                 :          1 :         context->self_test_result |= LIBSPDM_FIPS_SELF_TEST_ECDSA;
+     165                 :            :     } else {
+     166                 :          0 :         context->self_test_result &= ~LIBSPDM_FIPS_SELF_TEST_ECDSA;
+     167                 :            :     }
+     168                 :            : 
+     169                 :            : #endif/*LIBSPDM_ECDSA_SUPPORT*/
+     170                 :            : 
+     171                 :          1 :     return result;
+     172                 :            : }
+     173                 :            : 
+     174                 :            : #endif/*LIBSPDM_FIPS_MODE*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_eddsa.c.func-sort-c.html b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_eddsa.c.func-sort-c.html new file mode 100644 index 00000000000..ba34ef9893b --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_eddsa.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips/libspdm_selftest_eddsa.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fips - libspdm_selftest_eddsa.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:33100.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_fips_selftest_eddsa1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_eddsa.c.func.html b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_eddsa.c.func.html new file mode 100644 index 00000000000..24a7c2a29f5 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_eddsa.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips/libspdm_selftest_eddsa.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fips - libspdm_selftest_eddsa.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:33100.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_fips_selftest_eddsa1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_eddsa.c.gcov.html b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_eddsa.c.gcov.html new file mode 100644 index 00000000000..738f57a7d78 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_eddsa.c.gcov.html @@ -0,0 +1,361 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips/libspdm_selftest_eddsa.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fips - libspdm_selftest_eddsa.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:33100.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:00-
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2023 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_crypt_lib.h"
+       8                 :            : #include "internal/libspdm_common_lib.h"
+       9                 :            : #include "internal/libspdm_fips_lib.h"
+      10                 :            : 
+      11                 :            : #if LIBSPDM_FIPS_MODE
+      12                 :            : 
+      13                 :            : /**
+      14                 :            :  * EDDSA self_test
+      15                 :            :  **/
+      16                 :          1 : bool libspdm_fips_selftest_eddsa(void *fips_selftest_context)
+      17                 :            : {
+      18                 :          1 :     bool result = true;
+      19                 :            : 
+      20                 :            : #if LIBSPDM_EDDSA_SUPPORT
+      21                 :            :     libspdm_fips_selftest_context *context = fips_selftest_context;
+      22                 :            :     LIBSPDM_ASSERT(fips_selftest_context != NULL);
+      23                 :            : 
+      24                 :            :     /* any test fail cause the FIPS fail*/
+      25                 :            :     if (context->tested_algo != context->self_test_result) {
+      26                 :            :         return false;
+      27                 :            :     }
+      28                 :            : 
+      29                 :            :     /* check if run before.*/
+      30                 :            :     if ((context->tested_algo & LIBSPDM_FIPS_SELF_TEST_EDDSA) != 0) {
+      31                 :            :         return true;
+      32                 :            :     }
+      33                 :            : 
+      34                 :            : #if LIBSPDM_EDDSA_ED25519_SUPPORT
+      35                 :            : 
+      36                 :            :     void *ecd_25519;
+      37                 :            :     uint8_t signature_25519[32 * 2];
+      38                 :            :     size_t sig25519_size;
+      39                 :            :     uint8_t get_pub_key_25519[32];
+      40                 :            :     size_t get_pub_key_25519_size = sizeof(get_pub_key_25519);
+      41                 :            : 
+      42                 :            :     /*test vectors from https://www.rfc-editor.org/rfc/rfc8032 */
+      43                 :            :     uint8_t message_25519[] = {
+      44                 :            :         0x72
+      45                 :            :     };
+      46                 :            : 
+      47                 :            :     const uint8_t public_key_25519[] = {
+      48                 :            :         0x3d, 0x40, 0x17, 0xc3, 0xe8, 0x43, 0x89, 0x5a, 0x92, 0xb7, 0x0a, 0xa7, 0x4d, 0x1b, 0x7e,
+      49                 :            :         0xbc, 0x9c, 0x98, 0x2c, 0xcf, 0x2e, 0xc4, 0x96, 0x8c, 0xc0, 0xcd, 0x55, 0xf1, 0x2a, 0xf4,
+      50                 :            :         0x66, 0x0c
+      51                 :            :     };
+      52                 :            : 
+      53                 :            :     const uint8_t private_key_25519[] = {
+      54                 :            :         0x4c, 0xcd, 0x08, 0x9b, 0x28, 0xff, 0x96, 0xda, 0x9d, 0xb6, 0xc3, 0x46, 0xec, 0x11, 0x4e,
+      55                 :            :         0x0f, 0x5b, 0x8a, 0x31, 0x9f, 0x35, 0xab, 0xa6, 0x24, 0xda, 0x8c, 0xf6, 0xed, 0x4f, 0xb8,
+      56                 :            :         0xa6, 0xfb
+      57                 :            :     };
+      58                 :            : 
+      59                 :            :     /* Expected signature*/
+      60                 :            :     const uint8_t expected_signature_25519[] = {
+      61                 :            :         0x92, 0xa0, 0x09, 0xa9, 0xf0, 0xd4, 0xca, 0xb8, 0x72, 0x0e, 0x82, 0x0b, 0x5f, 0x64, 0x25,
+      62                 :            :         0x40, 0xa2, 0xb2, 0x7b, 0x54, 0x16, 0x50, 0x3f, 0x8f, 0xb3, 0x76, 0x22, 0x23, 0xeb, 0xdb,
+      63                 :            :         0x69, 0xda, 0x08, 0x5a, 0xc1, 0xe4, 0x3e, 0x15, 0x99, 0x6e, 0x45, 0x8f, 0x36, 0x13, 0xd0,
+      64                 :            :         0xf1, 0x1d, 0x8c, 0x38, 0x7b, 0x2e, 0xae, 0xb4, 0x30, 0x2a, 0xee, 0xb0, 0x0d, 0x29, 0x16,
+      65                 :            :         0x12, 0xbb, 0x0c, 0x00
+      66                 :            :     };
+      67                 :            : 
+      68                 :            :     ecd_25519 = libspdm_ecd_new_by_nid(LIBSPDM_CRYPTO_NID_EDDSA_ED25519);
+      69                 :            :     if (ecd_25519 == NULL) {
+      70                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "EDDSA 25519 gen failed \n"));
+      71                 :            :         result = false;
+      72                 :            :         goto update;
+      73                 :            :     }
+      74                 :            : 
+      75                 :            :     result = libspdm_ecd_set_pub_key(ecd_25519, public_key_25519, sizeof(public_key_25519));
+      76                 :            :     if (!result) {
+      77                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "EDDSA 25519 set public key failed \n"));
+      78                 :            :         libspdm_ecd_free(ecd_25519);
+      79                 :            :         result = false;
+      80                 :            :         goto update;
+      81                 :            :     }
+      82                 :            : 
+      83                 :            :     result =  libspdm_ecd_get_pub_key(ecd_25519, get_pub_key_25519, &get_pub_key_25519_size);
+      84                 :            :     if (!result) {
+      85                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "EDDSA 25519 get pub key failed \n"));
+      86                 :            :         libspdm_ecd_free(ecd_25519);
+      87                 :            :         result = false;
+      88                 :            :         goto update;
+      89                 :            :     }
+      90                 :            : 
+      91                 :            :     if (get_pub_key_25519_size != sizeof(public_key_25519)) {
+      92                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "EDDSA 25519 get key size compare failed \n"));
+      93                 :            :         libspdm_ecd_free(ecd_25519);
+      94                 :            :         result = false;
+      95                 :            :         goto update;
+      96                 :            :     }
+      97                 :            : 
+      98                 :            :     if (!libspdm_consttime_is_mem_equal(get_pub_key_25519, public_key_25519,
+      99                 :            :                                         sizeof(public_key_25519))) {
+     100                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "EDDSA 25519 get key content compare failed \n"));
+     101                 :            :         libspdm_ecd_free(ecd_25519);
+     102                 :            :         result = false;
+     103                 :            :         goto update;
+     104                 :            :     }
+     105                 :            : 
+     106                 :            :     result = libspdm_ecd_set_pri_key(ecd_25519, private_key_25519, sizeof(private_key_25519));
+     107                 :            :     if (!result) {
+     108                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "EDDSA 25519 set private key failed \n"));
+     109                 :            :         libspdm_ecd_free(ecd_25519);
+     110                 :            :         result = false;
+     111                 :            :         goto update;
+     112                 :            :     }
+     113                 :            : 
+     114                 :            :     /* Verify Ed-DSA*/
+     115                 :            :     sig25519_size = sizeof(signature_25519);
+     116                 :            :     result = libspdm_eddsa_sign(ecd_25519, LIBSPDM_CRYPTO_NID_NULL, NULL, 0, message_25519,
+     117                 :            :                                 sizeof(message_25519), signature_25519, &sig25519_size);
+     118                 :            :     if (!result) {
+     119                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "EDDSA 25519 sign failed \n"));
+     120                 :            :         libspdm_ecd_free(ecd_25519);
+     121                 :            :         result = false;
+     122                 :            :         goto update;
+     123                 :            :     }
+     124                 :            : 
+     125                 :            :     if (!libspdm_consttime_is_mem_equal(signature_25519, expected_signature_25519,
+     126                 :            :                                         sizeof(expected_signature_25519))) {
+     127                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "EDDSA 25519 KAT failed \n"));
+     128                 :            :         libspdm_ecd_free(ecd_25519);
+     129                 :            :         result = false;
+     130                 :            :         goto update;
+     131                 :            :     }
+     132                 :            : 
+     133                 :            :     result = libspdm_eddsa_verify(ecd_25519, LIBSPDM_CRYPTO_NID_NULL, NULL, 0, message_25519,
+     134                 :            :                                   sizeof(message_25519), signature_25519, sig25519_size);
+     135                 :            :     if (!result) {
+     136                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "EDDSA 25519 verify failed \n"));
+     137                 :            :         libspdm_ecd_free(ecd_25519);
+     138                 :            :         result = false;
+     139                 :            :         goto update;
+     140                 :            :     }
+     141                 :            : 
+     142                 :            :     libspdm_ecd_free(ecd_25519);
+     143                 :            : 
+     144                 :            : #endif/*LIBSPDM_EDDSA_ED25519_SUPPORT */
+     145                 :            : 
+     146                 :            : #if LIBSPDM_EDDSA_ED448_SUPPORT
+     147                 :            :     void *ecd_448;
+     148                 :            :     uint8_t signature_448[57 * 2];
+     149                 :            :     size_t sig448_size;
+     150                 :            :     uint8_t get_edd48_key[57];
+     151                 :            :     size_t get_pub_key_448_size = sizeof(get_edd48_key);
+     152                 :            : 
+     153                 :            :     /*test vectors from https://www.rfc-editor.org/rfc/rfc8032 */
+     154                 :            :     uint8_t message_448[] = {
+     155                 :            :         0x03
+     156                 :            :     };
+     157                 :            : 
+     158                 :            :     const uint8_t public_key_448[] = {
+     159                 :            :         0x43, 0xba, 0x28, 0xf4, 0x30, 0xcd, 0xff, 0x45, 0x6a, 0xe5, 0x31, 0x54, 0x5f, 0x7e, 0xcd,
+     160                 :            :         0x0a, 0xc8, 0x34, 0xa5, 0x5d, 0x93, 0x58, 0xc0, 0x37, 0x2b, 0xfa, 0x0c, 0x6c, 0x67, 0x98,
+     161                 :            :         0xc0, 0x86, 0x6a, 0xea, 0x01, 0xeb, 0x00, 0x74, 0x28, 0x02, 0xb8, 0x43, 0x8e, 0xa4, 0xcb,
+     162                 :            :         0x82, 0x16, 0x9c, 0x23, 0x51, 0x60, 0x62, 0x7b, 0x4c, 0x3a, 0x94, 0x80
+     163                 :            :     };
+     164                 :            : 
+     165                 :            :     const uint8_t private_key_448[] = {
+     166                 :            :         0xc4, 0xea, 0xb0, 0x5d, 0x35, 0x70, 0x07, 0xc6, 0x32, 0xf3, 0xdb, 0xb4, 0x84, 0x89, 0x92,
+     167                 :            :         0x4d, 0x55, 0x2b, 0x08, 0xfe, 0x0c, 0x35, 0x3a, 0x0d, 0x4a, 0x1f, 0x00, 0xac, 0xda, 0x2c,
+     168                 :            :         0x46, 0x3a, 0xfb, 0xea, 0x67, 0xc5, 0xe8, 0xd2, 0x87, 0x7c, 0x5e, 0x3b, 0xc3, 0x97, 0xa6,
+     169                 :            :         0x59, 0x94, 0x9e, 0xf8, 0x02, 0x1e, 0x95, 0x4e, 0x0a, 0x12, 0x27, 0x4e
+     170                 :            :     };
+     171                 :            : 
+     172                 :            :     /* Expected signature*/
+     173                 :            :     const uint8_t expected_signature_448[] = {
+     174                 :            :         0x26, 0xb8, 0xf9, 0x17, 0x27, 0xbd, 0x62, 0x89, 0x7a, 0xf1, 0x5e, 0x41, 0xeb, 0x43, 0xc3,
+     175                 :            :         0x77, 0xef, 0xb9, 0xc6, 0x10, 0xd4, 0x8f, 0x23, 0x35, 0xcb, 0x0b, 0xd0, 0x08, 0x78, 0x10,
+     176                 :            :         0xf4, 0x35, 0x25, 0x41, 0xb1, 0x43, 0xc4, 0xb9, 0x81, 0xb7, 0xe1, 0x8f, 0x62, 0xde, 0x8c,
+     177                 :            :         0xcd, 0xf6, 0x33, 0xfc, 0x1b, 0xf0, 0x37, 0xab, 0x7c, 0xd7, 0x79, 0x80, 0x5e, 0x0d, 0xbc,
+     178                 :            :         0xc0, 0xaa, 0xe1, 0xcb, 0xce, 0xe1, 0xaf, 0xb2, 0xe0, 0x27, 0xdf, 0x36, 0xbc, 0x04, 0xdc,
+     179                 :            :         0xec, 0xbf, 0x15, 0x43, 0x36, 0xc1, 0x9f, 0x0a, 0xf7, 0xe0, 0xa6, 0x47, 0x29, 0x05, 0xe7,
+     180                 :            :         0x99, 0xf1, 0x95, 0x3d, 0x2a, 0x0f, 0xf3, 0x34, 0x8a, 0xb2, 0x1a, 0xa4, 0xad, 0xaf, 0xd1,
+     181                 :            :         0xd2, 0x34, 0x44, 0x1c, 0xf8, 0x07, 0xc0, 0x3a
+     182                 :            :     };
+     183                 :            : 
+     184                 :            :     ecd_448 = libspdm_ecd_new_by_nid(LIBSPDM_CRYPTO_NID_EDDSA_ED448);
+     185                 :            :     if (ecd_448 == NULL) {
+     186                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "EDDSA 448 gen failed \n"));
+     187                 :            :         result = false;
+     188                 :            :         goto update;
+     189                 :            :     }
+     190                 :            : 
+     191                 :            :     result = libspdm_ecd_set_pub_key(ecd_448, public_key_448, sizeof(public_key_448));
+     192                 :            :     if (!result) {
+     193                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "EDDSA 448 set public key failed \n"));
+     194                 :            :         libspdm_ecd_free(ecd_448);
+     195                 :            :         result = false;
+     196                 :            :         goto update;
+     197                 :            :     }
+     198                 :            : 
+     199                 :            :     result =  libspdm_ecd_get_pub_key(ecd_448, get_edd48_key, &get_pub_key_448_size);
+     200                 :            :     if (!result) {
+     201                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "EDDSA 448 get pub key failed \n"));
+     202                 :            :         libspdm_ecd_free(ecd_448);
+     203                 :            :         result = false;
+     204                 :            :         goto update;
+     205                 :            :     }
+     206                 :            : 
+     207                 :            :     if (get_pub_key_448_size != sizeof(public_key_448)) {
+     208                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "EDDSA 448 get key compare failed \n"));
+     209                 :            :         libspdm_ecd_free(ecd_448);
+     210                 :            :         result = false;
+     211                 :            :         goto update;
+     212                 :            :     }
+     213                 :            : 
+     214                 :            :     if (!libspdm_consttime_is_mem_equal(get_edd48_key, public_key_448,
+     215                 :            :                                         sizeof(public_key_448))) {
+     216                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "EDDSA 448 get key compare failed \n"));
+     217                 :            :         libspdm_ecd_free(ecd_448);
+     218                 :            :         result = false;
+     219                 :            :         goto update;
+     220                 :            :     }
+     221                 :            : 
+     222                 :            :     result = libspdm_ecd_set_pri_key(ecd_448, private_key_448, sizeof(private_key_448));
+     223                 :            :     if (!result) {
+     224                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "EDDSA 448 set private key failed \n"));
+     225                 :            :         libspdm_ecd_free(ecd_448);
+     226                 :            :         result = false;
+     227                 :            :         goto update;
+     228                 :            :     }
+     229                 :            : 
+     230                 :            :     /* Verify Ed-DSA*/
+     231                 :            :     sig448_size = sizeof(signature_448);
+     232                 :            :     result = libspdm_eddsa_sign(ecd_448, LIBSPDM_CRYPTO_NID_NULL, NULL, 0, message_448,
+     233                 :            :                                 sizeof(message_448), signature_448, &sig448_size);
+     234                 :            :     if (!result) {
+     235                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "EDDSA 448 sign failed \n"));
+     236                 :            :         libspdm_ecd_free(ecd_448);
+     237                 :            :         result = false;
+     238                 :            :         goto update;
+     239                 :            :     }
+     240                 :            : 
+     241                 :            :     if (!libspdm_consttime_is_mem_equal(signature_448, expected_signature_448,
+     242                 :            :                                         sizeof(expected_signature_448))) {
+     243                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "EDDSA 448 KAT failed \n"));
+     244                 :            :         libspdm_ecd_free(ecd_448);
+     245                 :            :         result = false;
+     246                 :            :         goto update;
+     247                 :            :     }
+     248                 :            : 
+     249                 :            :     result = libspdm_eddsa_verify(ecd_448, LIBSPDM_CRYPTO_NID_NULL, NULL, 0, message_448,
+     250                 :            :                                   sizeof(message_448), signature_448, sig448_size);
+     251                 :            :     if (!result) {
+     252                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "EDDSA 448 verify failed \n"));
+     253                 :            :         libspdm_ecd_free(ecd_448);
+     254                 :            :         result = false;
+     255                 :            :         goto update;
+     256                 :            :     }
+     257                 :            : 
+     258                 :            :     libspdm_ecd_free(ecd_448);
+     259                 :            : #endif/*LIBSPDM_EDDSA_ED448_SUPPORT*/
+     260                 :            : 
+     261                 :            : update:
+     262                 :            :     /* mark it as tested*/
+     263                 :            :     context->tested_algo |= LIBSPDM_FIPS_SELF_TEST_EDDSA;
+     264                 :            : 
+     265                 :            :     /* record test result*/
+     266                 :            :     if (result) {
+     267                 :            :         context->self_test_result |= LIBSPDM_FIPS_SELF_TEST_EDDSA;
+     268                 :            :     } else {
+     269                 :            :         context->self_test_result &= ~LIBSPDM_FIPS_SELF_TEST_EDDSA;
+     270                 :            :     }
+     271                 :            : 
+     272                 :            : #endif /* LIBSPDM_EDDSA_SUPPORT */
+     273                 :          1 :     return result;
+     274                 :            : }
+     275                 :            : 
+     276                 :            : #endif/*LIBSPDM_FIPS_MODE*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_ffdh.c.func-sort-c.html b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_ffdh.c.func-sort-c.html new file mode 100644 index 00000000000..3ea2739fd70 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_ffdh.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips/libspdm_selftest_ffdh.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fips - libspdm_selftest_ffdh.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:317143.7 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:163250.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_fips_selftest_ffdh1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_ffdh.c.func.html b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_ffdh.c.func.html new file mode 100644 index 00000000000..5d655d7b947 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_ffdh.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips/libspdm_selftest_ffdh.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fips - libspdm_selftest_ffdh.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:317143.7 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:163250.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_fips_selftest_ffdh1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_ffdh.c.gcov.html b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_ffdh.c.gcov.html new file mode 100644 index 00000000000..5355a57b865 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_ffdh.c.gcov.html @@ -0,0 +1,223 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips/libspdm_selftest_ffdh.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fips - libspdm_selftest_ffdh.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:317143.7 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:163250.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2023 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_crypt_lib.h"
+       8                 :            : #include "internal/libspdm_common_lib.h"
+       9                 :            : #include "internal/libspdm_fips_lib.h"
+      10                 :            : 
+      11                 :            : #if LIBSPDM_FIPS_MODE
+      12                 :            : /**
+      13                 :            :  * FFDH self_test
+      14                 :            :  **/
+      15                 :          1 : bool libspdm_fips_selftest_ffdh(void *fips_selftest_context)
+      16                 :            : {
+      17                 :          1 :     bool result = true;
+      18                 :            : 
+      19                 :            : #if LIBSPDM_FFDHE_SUPPORT
+      20                 :          1 :     libspdm_fips_selftest_context *context = fips_selftest_context;
+      21         [ -  + ]:          1 :     LIBSPDM_ASSERT(fips_selftest_context != NULL);
+      22                 :            : 
+      23                 :            :     /* any test fail cause the FIPS fail*/
+      24         [ -  + ]:          1 :     if (context->tested_algo != context->self_test_result) {
+      25                 :          0 :         return false;
+      26                 :            :     }
+      27                 :            : 
+      28                 :            :     /* check if run before.*/
+      29         [ -  + ]:          1 :     if ((context->tested_algo & LIBSPDM_FIPS_SELF_TEST_FFDH) != 0) {
+      30                 :          0 :         return true;
+      31                 :            :     }
+      32                 :            : 
+      33                 :            :     void *dh1;
+      34                 :            :     void *dh2;
+      35                 :            :     uint8_t ff_public_key1[256];
+      36                 :            :     size_t ff_public_key1_length;
+      37                 :            :     uint8_t ff_public_key2[256];
+      38                 :            :     size_t ff_public_key2_length;
+      39                 :            :     uint8_t ff_key1[256];
+      40                 :            :     size_t ff_key1_length;
+      41                 :            :     uint8_t ff_key2[256];
+      42                 :            :     size_t ff_key2_length;
+      43                 :            : 
+      44                 :          1 :     ff_public_key1_length = sizeof(ff_public_key1);
+      45                 :          1 :     ff_public_key2_length = sizeof(ff_public_key2);
+      46                 :          1 :     ff_key1_length = sizeof(ff_key1);
+      47                 :          1 :     ff_key2_length = sizeof(ff_key2);
+      48                 :            : 
+      49                 :          1 :     dh1 = libspdm_dh_new_by_nid(LIBSPDM_CRYPTO_NID_FFDHE2048);
+      50         [ -  + ]:          1 :     if (dh1 == NULL) {
+      51                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "FFDH gen dh1 failed \n"));
+      52                 :          0 :         result = false;
+      53                 :          0 :         goto update;
+      54                 :            :     }
+      55                 :            : 
+      56                 :          1 :     dh2 = libspdm_dh_new_by_nid(LIBSPDM_CRYPTO_NID_FFDHE2048);
+      57         [ -  + ]:          1 :     if (dh2 == NULL) {
+      58                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "FFDH gen dh2 failed \n"));
+      59                 :          0 :         libspdm_dh_free(dh1);
+      60                 :          0 :         result = false;
+      61                 :          0 :         goto update;
+      62                 :            :     }
+      63                 :            : 
+      64                 :          1 :     result = libspdm_dh_generate_key(dh1, ff_public_key1, &ff_public_key1_length);
+      65   [ +  -  -  + ]:          1 :     if (!result || ff_public_key1_length != 256) {
+      66                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "FFDH generate key1 failed \n"));
+      67                 :          0 :         libspdm_dh_free(dh1);
+      68                 :          0 :         libspdm_dh_free(dh2);
+      69                 :          0 :         result = false;
+      70                 :          0 :         goto update;
+      71                 :            :     }
+      72                 :            : 
+      73                 :          1 :     result = libspdm_dh_generate_key(dh2, ff_public_key2, &ff_public_key2_length);
+      74   [ +  -  -  + ]:          1 :     if (!result || ff_public_key2_length != 256) {
+      75                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "FFDH generate key2 failed \n"));
+      76                 :          0 :         libspdm_dh_free(dh1);
+      77                 :          0 :         libspdm_dh_free(dh2);
+      78                 :          0 :         result = false;
+      79                 :          0 :         goto update;
+      80                 :            :     }
+      81                 :            : 
+      82                 :          1 :     result = libspdm_dh_compute_key(dh1, ff_public_key2, ff_public_key2_length,
+      83                 :            :                                     ff_key1, &ff_key1_length);
+      84   [ +  -  -  + ]:          1 :     if (!result || ff_key1_length != 256) {
+      85                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "FFDH compute key failed \n"));
+      86                 :          0 :         libspdm_dh_free(dh1);
+      87                 :          0 :         libspdm_dh_free(dh2);
+      88                 :          0 :         result = false;
+      89                 :          0 :         goto update;
+      90                 :            :     }
+      91                 :            : 
+      92                 :          1 :     result = libspdm_dh_compute_key(dh2, ff_public_key1, ff_public_key1_length,
+      93                 :            :                                     ff_key2, &ff_key2_length);
+      94   [ +  -  -  + ]:          1 :     if (!result || ff_key2_length != 256) {
+      95                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "FFDH compute key failed \n"));
+      96                 :          0 :         libspdm_dh_free(dh1);
+      97                 :          0 :         libspdm_dh_free(dh2);
+      98                 :          0 :         result = false;
+      99                 :          0 :         goto update;
+     100                 :            :     }
+     101                 :            : 
+     102                 :            :     /*self_test*/
+     103         [ -  + ]:          1 :     if (ff_key1_length != ff_key2_length) {
+     104                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "FFDH self_test failed \n"));
+     105                 :          0 :         libspdm_dh_free(dh1);
+     106                 :          0 :         libspdm_dh_free(dh2);
+     107                 :          0 :         result = false;
+     108                 :          0 :         goto update;
+     109                 :            :     }
+     110                 :            : 
+     111         [ -  + ]:          1 :     if (!libspdm_consttime_is_mem_equal(ff_key1, ff_key2, ff_key1_length)) {
+     112                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "FFDH self_test failed \n"));
+     113                 :          0 :         libspdm_dh_free(dh1);
+     114                 :          0 :         libspdm_dh_free(dh2);
+     115                 :          0 :         result = false;
+     116                 :          0 :         goto update;
+     117                 :            :     }
+     118                 :            : 
+     119                 :          1 :     libspdm_dh_free(dh1);
+     120                 :          1 :     libspdm_dh_free(dh2);
+     121                 :            : 
+     122                 :          1 : update:
+     123                 :            :     /* mark it as tested*/
+     124                 :          1 :     context->tested_algo |= LIBSPDM_FIPS_SELF_TEST_FFDH;
+     125                 :            : 
+     126                 :            :     /* record test result*/
+     127         [ +  - ]:          1 :     if (result) {
+     128                 :          1 :         context->self_test_result |= LIBSPDM_FIPS_SELF_TEST_FFDH;
+     129                 :            :     } else {
+     130                 :          0 :         context->self_test_result &= ~LIBSPDM_FIPS_SELF_TEST_FFDH;
+     131                 :            :     }
+     132                 :            : 
+     133                 :            : #endif/*LIBSPDM_FFDHE_SUPPORT*/
+     134                 :            : 
+     135                 :          1 :     return result;
+     136                 :            : }
+     137                 :            : 
+     138                 :            : #endif/*LIBSPDM_FIPS_MODE*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_hkdf.c.func-sort-c.html b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_hkdf.c.func-sort-c.html new file mode 100644 index 00000000000..1e454bb4643 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_hkdf.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips/libspdm_selftest_hkdf.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fips - libspdm_selftest_hkdf.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:243961.5 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:81650.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_fips_selftest_hkdf1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_hkdf.c.func.html b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_hkdf.c.func.html new file mode 100644 index 00000000000..faab88f43cf --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_hkdf.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips/libspdm_selftest_hkdf.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fips - libspdm_selftest_hkdf.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:243961.5 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:81650.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_fips_selftest_hkdf1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_hkdf.c.gcov.html b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_hkdf.c.gcov.html new file mode 100644 index 00000000000..0a32e1f42a1 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_hkdf.c.gcov.html @@ -0,0 +1,203 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips/libspdm_selftest_hkdf.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fips - libspdm_selftest_hkdf.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:243961.5 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:81650.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2023 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_crypt_lib.h"
+       8                 :            : #include "internal/libspdm_common_lib.h"
+       9                 :            : #include "internal/libspdm_fips_lib.h"
+      10                 :            : 
+      11                 :            : #if LIBSPDM_FIPS_MODE
+      12                 :            : 
+      13                 :            : /**
+      14                 :            :  * HKDF KAT test
+      15                 :            :  **/
+      16                 :          1 : bool libspdm_fips_selftest_hkdf(void *fips_selftest_context)
+      17                 :            : {
+      18                 :          1 :     bool result = true;
+      19                 :            : 
+      20                 :            : #if LIBSPDM_SHA256_SUPPORT
+      21                 :          1 :     libspdm_fips_selftest_context *context = fips_selftest_context;
+      22         [ -  + ]:          1 :     LIBSPDM_ASSERT(fips_selftest_context != NULL);
+      23                 :            : 
+      24                 :            :     /* any test fail cause the FIPS fail*/
+      25         [ -  + ]:          1 :     if (context->tested_algo != context->self_test_result) {
+      26                 :          0 :         return false;
+      27                 :            :     }
+      28                 :            : 
+      29                 :            :     /* check if run before.*/
+      30         [ -  + ]:          1 :     if ((context->tested_algo & LIBSPDM_FIPS_SELF_TEST_HKDF) != 0) {
+      31                 :          0 :         return true;
+      32                 :            :     }
+      33                 :            : 
+      34                 :            :     uint8_t prk_out[32];
+      35                 :            :     uint8_t out[42];
+      36                 :            : 
+      37                 :            :     /* Test Vectors https://www.rfc-editor.org/rfc/rfc5869.html */
+      38                 :          1 :     uint8_t hkdf_sha256_ikm[] = {
+      39                 :            :         0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
+      40                 :            :         0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
+      41                 :            :         0x0b, 0x0b
+      42                 :            :     };
+      43                 :            : 
+      44                 :          1 :     uint8_t hkdf_sha256_salt[] = {
+      45                 :            :         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
+      46                 :            :         0x0a, 0x0b, 0x0c,
+      47                 :            :     };
+      48                 :            : 
+      49                 :          1 :     uint8_t hkdf_sha256_info[] = {
+      50                 :            :         0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9,
+      51                 :            :     };
+      52                 :            : 
+      53                 :          1 :     uint8_t hkdf_sha256_prk[] = {
+      54                 :            :         0x07, 0x77, 0x09, 0x36, 0x2c, 0x2e, 0x32, 0xdf, 0x0d, 0xdc,
+      55                 :            :         0x3f, 0x0d, 0xc4, 0x7b, 0xba, 0x63, 0x90, 0xb6, 0xc7, 0x3b,
+      56                 :            :         0xb5, 0x0f, 0x9c, 0x31, 0x22, 0xec, 0x84, 0x4a, 0xd7, 0xc2,
+      57                 :            :         0xb3, 0xe5,
+      58                 :            :     };
+      59                 :            : 
+      60                 :          1 :     uint8_t hkdf_sha256_okm[] = {
+      61                 :            :         0x3c, 0xb2, 0x5f, 0x25, 0xfa, 0xac, 0xd5, 0x7a, 0x90, 0x43,
+      62                 :            :         0x4f, 0x64, 0xd0, 0x36, 0x2f, 0x2a, 0x2d, 0x2d, 0x0a, 0x90,
+      63                 :            :         0xcf, 0x1a, 0x5a, 0x4c, 0x5d, 0xb0, 0x2d, 0x56, 0xec, 0xc4,
+      64                 :            :         0xc5, 0xbf, 0x34, 0x00, 0x72, 0x08, 0xd5, 0xb8, 0x87, 0x18,
+      65                 :            :         0x58, 0x65,
+      66                 :            :     };
+      67                 :            : 
+      68                 :          1 :     libspdm_zero_mem(prk_out, sizeof(prk_out));
+      69                 :          1 :     result = libspdm_hkdf_sha256_extract (
+      70                 :            :         hkdf_sha256_ikm, sizeof(hkdf_sha256_ikm),
+      71                 :            :         hkdf_sha256_salt, sizeof(hkdf_sha256_salt),
+      72                 :            :         prk_out, sizeof(prk_out)
+      73                 :            :         );
+      74         [ -  + ]:          1 :     if (!result) {
+      75                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HKDF extract failed \n"));
+      76                 :          0 :         result = false;
+      77                 :          0 :         goto update;
+      78                 :            :     }
+      79                 :            : 
+      80         [ -  + ]:          1 :     if (!libspdm_consttime_is_mem_equal(prk_out, hkdf_sha256_prk, sizeof(hkdf_sha256_prk))) {
+      81                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HKDF KAT failed \n"));
+      82                 :          0 :         result = false;
+      83                 :          0 :         goto update;
+      84                 :            :     }
+      85                 :            : 
+      86                 :          1 :     libspdm_zero_mem(out, sizeof(out));
+      87                 :          1 :     result = libspdm_hkdf_sha256_expand (hkdf_sha256_prk, sizeof(hkdf_sha256_prk),
+      88                 :            :                                          hkdf_sha256_info, sizeof(hkdf_sha256_info),
+      89                 :            :                                          out, sizeof(out));
+      90         [ -  + ]:          1 :     if (!result) {
+      91                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HKDF expand failed \n"));
+      92                 :          0 :         result = false;
+      93                 :          0 :         goto update;
+      94                 :            :     }
+      95                 :            : 
+      96         [ +  - ]:          1 :     if (!libspdm_consttime_is_mem_equal(out, hkdf_sha256_okm, sizeof(hkdf_sha256_okm))) {
+      97                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HKDF KAT failed \n"));
+      98                 :          0 :         result = false;
+      99                 :          0 :         goto update;
+     100                 :            :     }
+     101                 :            : 
+     102                 :          1 : update:
+     103                 :            :     /* mark it as tested*/
+     104                 :          1 :     context->tested_algo |= LIBSPDM_FIPS_SELF_TEST_HKDF;
+     105                 :            : 
+     106                 :            :     /* record test result*/
+     107         [ +  - ]:          1 :     if (result) {
+     108                 :          1 :         context->self_test_result |= LIBSPDM_FIPS_SELF_TEST_HKDF;
+     109                 :            :     } else {
+     110                 :          0 :         context->self_test_result &= ~LIBSPDM_FIPS_SELF_TEST_HKDF;
+     111                 :            :     }
+     112                 :            : 
+     113                 :            : #endif/*LIBSPDM_SHA256_SUPPORT*/
+     114                 :            : 
+     115                 :          1 :     return result;
+     116                 :            : }
+     117                 :            : 
+     118                 :            : #endif/*LIBSPDM_FIPS_MODE*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_hmac.c.func-sort-c.html b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_hmac.c.func-sort-c.html new file mode 100644 index 00000000000..931d1c23940 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_hmac.c.func-sort-c.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips/libspdm_selftest_hmac.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fips - libspdm_selftest_hmac.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:577873.1 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:213658.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_fips_selftest_hmac_sha2562
libspdm_fips_selftest_hmac_sha3842
libspdm_fips_selftest_hmac_sha5122
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_hmac.c.func.html b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_hmac.c.func.html new file mode 100644 index 00000000000..07210d5c0a1 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_hmac.c.func.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips/libspdm_selftest_hmac.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fips - libspdm_selftest_hmac.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:577873.1 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:213658.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_fips_selftest_hmac_sha2562
libspdm_fips_selftest_hmac_sha3842
libspdm_fips_selftest_hmac_sha5122
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_hmac.c.gcov.html b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_hmac.c.gcov.html new file mode 100644 index 00000000000..4186db6ea92 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_hmac.c.gcov.html @@ -0,0 +1,286 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips/libspdm_selftest_hmac.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fips - libspdm_selftest_hmac.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:577873.1 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:213658.3 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2023 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_crypt_lib.h"
+       8                 :            : #include "internal/libspdm_common_lib.h"
+       9                 :            : #include "internal/libspdm_fips_lib.h"
+      10                 :            : 
+      11                 :            : #if LIBSPDM_FIPS_MODE
+      12                 :            : 
+      13                 :            : /**
+      14                 :            :  * HMAC-SHA256 KAT covers SHA256 KAT.
+      15                 :            :  **/
+      16                 :          2 : bool libspdm_fips_selftest_hmac_sha256(void *fips_selftest_context)
+      17                 :            : {
+      18                 :          2 :     bool result = true;
+      19                 :            : 
+      20                 :            : #if LIBSPDM_SHA256_SUPPORT
+      21                 :          2 :     libspdm_fips_selftest_context *context = fips_selftest_context;
+      22         [ -  + ]:          2 :     LIBSPDM_ASSERT(fips_selftest_context != NULL);
+      23                 :            : 
+      24                 :            :     /* any test fail cause the FIPS fail*/
+      25         [ -  + ]:          2 :     if (context->tested_algo != context->self_test_result) {
+      26                 :          0 :         return false;
+      27                 :            :     }
+      28                 :            : 
+      29                 :            :     /* check if run before.*/
+      30         [ +  + ]:          2 :     if ((context->tested_algo & LIBSPDM_FIPS_SELF_TEST_HMAC_SHA256) != 0) {
+      31                 :          1 :         return true;
+      32                 :            :     }
+      33                 :            : 
+      34                 :          1 :     const uint8_t key[32] = {0};
+      35                 :          1 :     const uint8_t msg[32] = {0};
+      36                 :            : 
+      37                 :            :     uint8_t hmac_256_result[32];
+      38                 :          1 :     const uint8_t hmac_sha256_answer[] = {
+      39                 :            :         0x33, 0xad, 0x0a, 0x1c, 0x60, 0x7e, 0xc0, 0x3b,
+      40                 :            :         0x09, 0xe6, 0xcd, 0x98, 0x93, 0x68, 0x0c, 0xe2,
+      41                 :            :         0x10, 0xad, 0xf3, 0x00, 0xaa, 0x1f, 0x26, 0x60,
+      42                 :            :         0xe1, 0xb2, 0x2e, 0x10, 0xf1, 0x70, 0xf9, 0x2a
+      43                 :            :     };
+      44                 :          1 :     libspdm_zero_mem(hmac_256_result, sizeof(hmac_256_result));
+      45                 :          1 :     result = libspdm_hmac_sha256_all(msg, sizeof(msg), key, sizeof(key), hmac_256_result);
+      46         [ -  + ]:          1 :     if (!result) {
+      47                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "gen hmac_sha256 failed \n"));
+      48                 :          0 :         goto update;
+      49                 :            :     }
+      50                 :            : 
+      51         [ +  - ]:          1 :     if (!libspdm_consttime_is_mem_equal(hmac_256_result, hmac_sha256_answer,
+      52                 :            :                                         sizeof(hmac_sha256_answer))) {
+      53                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "hmac_sha256 KAT failed \n"));
+      54                 :          0 :         result = false;
+      55                 :          0 :         goto update;
+      56                 :            :     }
+      57                 :            : 
+      58                 :          1 : update:
+      59                 :            :     /* mark it as tested*/
+      60                 :          1 :     context->tested_algo |= LIBSPDM_FIPS_SELF_TEST_HMAC_SHA256;
+      61                 :            : 
+      62                 :            :     /* record test result*/
+      63         [ +  - ]:          1 :     if (result) {
+      64                 :          1 :         context->self_test_result |= LIBSPDM_FIPS_SELF_TEST_HMAC_SHA256;
+      65                 :            :     } else {
+      66                 :          0 :         context->self_test_result &= ~LIBSPDM_FIPS_SELF_TEST_HMAC_SHA256;
+      67                 :            :     }
+      68                 :            : 
+      69                 :            : #endif/*LIBSPDM_SHA256_SUPPORT*/
+      70                 :            : 
+      71                 :          1 :     return result;
+      72                 :            : }
+      73                 :            : 
+      74                 :            : /**
+      75                 :            :  * HMAC-SHA384 KAT covers SHA384 KAT.
+      76                 :            :  **/
+      77                 :          2 : bool libspdm_fips_selftest_hmac_sha384(void *fips_selftest_context)
+      78                 :            : {
+      79                 :          2 :     bool result = true;
+      80                 :            : 
+      81                 :            : #if LIBSPDM_SHA384_SUPPORT
+      82                 :          2 :     libspdm_fips_selftest_context *context = fips_selftest_context;
+      83         [ -  + ]:          2 :     LIBSPDM_ASSERT(fips_selftest_context != NULL);
+      84                 :            : 
+      85                 :            :     /* any test fail cause the FIPS fail*/
+      86         [ -  + ]:          2 :     if (context->tested_algo != context->self_test_result) {
+      87                 :          0 :         return false;
+      88                 :            :     }
+      89                 :            : 
+      90                 :            :     /* check if run before.*/
+      91         [ +  + ]:          2 :     if ((context->tested_algo & LIBSPDM_FIPS_SELF_TEST_HMAC_SHA384) != 0) {
+      92                 :          1 :         return true;
+      93                 :            :     }
+      94                 :            : 
+      95                 :          1 :     const uint8_t key[32] = {0};
+      96                 :          1 :     const uint8_t msg[32] = {0};
+      97                 :            : 
+      98                 :            :     uint8_t hmac_384_result[48];
+      99                 :          1 :     const uint8_t hmac_sha384_answer[] = {
+     100                 :            :         0xe6, 0x65, 0xec, 0x75, 0xdc, 0xa3, 0x23, 0xdf,
+     101                 :            :         0x31, 0x80, 0x40, 0x60, 0xe1, 0xb0, 0xd8, 0x28,
+     102                 :            :         0xb5, 0x0a, 0x6a, 0x8a, 0x53, 0x9c, 0xfe, 0xdd,
+     103                 :            :         0x9a, 0xa0, 0x07, 0x4b, 0x5b, 0x36, 0x44, 0x5d,
+     104                 :            :         0xef, 0xbc, 0x47, 0x45, 0x3d, 0xf8, 0xd0, 0xc1,
+     105                 :            :         0x4b, 0x7a, 0xd2, 0x06, 0x2e, 0x7b, 0xbd, 0xb1
+     106                 :            :     };
+     107                 :          1 :     libspdm_zero_mem(hmac_384_result, sizeof(hmac_384_result));
+     108                 :          1 :     result = libspdm_hmac_sha384_all(msg, sizeof(msg), key, sizeof(key), hmac_384_result);
+     109         [ -  + ]:          1 :     if (!result) {
+     110                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "gen hmac_sha384 failed \n"));
+     111                 :          0 :         goto update;
+     112                 :            :     }
+     113                 :            : 
+     114         [ +  - ]:          1 :     if (!libspdm_consttime_is_mem_equal(hmac_384_result, hmac_sha384_answer,
+     115                 :            :                                         sizeof(hmac_sha384_answer))) {
+     116                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "hmac_sha384 KAT failed \n"));
+     117                 :          0 :         result = false;
+     118                 :          0 :         goto update;
+     119                 :            :     }
+     120                 :            : 
+     121                 :          1 : update:
+     122                 :            :     /* mark it as tested*/
+     123                 :          1 :     context->tested_algo |= LIBSPDM_FIPS_SELF_TEST_HMAC_SHA384;
+     124                 :            : 
+     125                 :            :     /* record test result*/
+     126         [ +  - ]:          1 :     if (result) {
+     127                 :          1 :         context->self_test_result |= LIBSPDM_FIPS_SELF_TEST_HMAC_SHA384;
+     128                 :            :     } else {
+     129                 :          0 :         context->self_test_result &= ~LIBSPDM_FIPS_SELF_TEST_HMAC_SHA384;
+     130                 :            :     }
+     131                 :            : 
+     132                 :            : #endif/*LIBSPDM_SHA384_SUPPORT*/
+     133                 :            : 
+     134                 :          1 :     return result;
+     135                 :            : }
+     136                 :            : 
+     137                 :            : /**
+     138                 :            :  * HMAC-SHA512 KAT covers SHA512 KAT.
+     139                 :            :  **/
+     140                 :          2 : bool libspdm_fips_selftest_hmac_sha512(void *fips_selftest_context)
+     141                 :            : {
+     142                 :          2 :     bool result = true;
+     143                 :            : 
+     144                 :            : #if LIBSPDM_SHA512_SUPPORT
+     145                 :          2 :     libspdm_fips_selftest_context *context = fips_selftest_context;
+     146         [ -  + ]:          2 :     LIBSPDM_ASSERT(fips_selftest_context != NULL);
+     147                 :            : 
+     148                 :            :     /* any test fail cause the FIPS fail*/
+     149         [ -  + ]:          2 :     if (context->tested_algo != context->self_test_result) {
+     150                 :          0 :         return false;
+     151                 :            :     }
+     152                 :            : 
+     153                 :            :     /* check if run before.*/
+     154         [ +  + ]:          2 :     if ((context->tested_algo & LIBSPDM_FIPS_SELF_TEST_HMAC_SHA512) != 0) {
+     155                 :          1 :         return true;
+     156                 :            :     }
+     157                 :            : 
+     158                 :          1 :     const uint8_t key[32] = {0};
+     159                 :          1 :     const uint8_t msg[32] = {0};
+     160                 :            : 
+     161                 :            :     uint8_t hmac_512_result[64];
+     162                 :          1 :     const uint8_t hmac_sha512_answer[] = {
+     163                 :            :         0xba, 0xe4, 0x6c, 0xeb, 0xeb, 0xbb, 0x90, 0x40,
+     164                 :            :         0x9a, 0xbc, 0x5a, 0xcf, 0x7a, 0xc2, 0x1f, 0xdb,
+     165                 :            :         0x33, 0x9c, 0x01, 0xce, 0x15, 0x19, 0x2c, 0x52,
+     166                 :            :         0xfb, 0x9e, 0x8a, 0xa1, 0x1a, 0x8d, 0xe9, 0xa4,
+     167                 :            :         0xea, 0x15, 0xa0, 0x45, 0xf2, 0xbe, 0x24, 0x5f,
+     168                 :            :         0xbb, 0x98, 0x91, 0x6a, 0x9a, 0xe8, 0x1b, 0x35,
+     169                 :            :         0x3e, 0x33, 0xb9, 0xc4, 0x2a, 0x55, 0x38, 0x0c,
+     170                 :            :         0x51, 0x58, 0x24, 0x1d, 0xae, 0xb3, 0xc6, 0xdd
+     171                 :            :     };
+     172                 :          1 :     libspdm_zero_mem(hmac_512_result, sizeof(hmac_512_result));
+     173                 :          1 :     result = libspdm_hmac_sha512_all(msg, sizeof(msg), key, sizeof(key), hmac_512_result);
+     174         [ -  + ]:          1 :     if (!result) {
+     175                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "gen hmac_sha512 failed \n"));
+     176                 :          0 :         goto update;
+     177                 :            :     }
+     178                 :            : 
+     179         [ +  - ]:          1 :     if (!libspdm_consttime_is_mem_equal(hmac_512_result, hmac_sha512_answer,
+     180                 :            :                                         sizeof(hmac_sha512_answer))) {
+     181                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "hmac_sha512 KAT failed \n"));
+     182                 :          0 :         result = false;
+     183                 :          0 :         goto update;
+     184                 :            :     }
+     185                 :          1 : update:
+     186                 :            :     /* mark it as tested*/
+     187                 :          1 :     context->tested_algo |= LIBSPDM_FIPS_SELF_TEST_HMAC_SHA512;
+     188                 :            : 
+     189                 :            :     /* record test result*/
+     190         [ +  - ]:          1 :     if (result) {
+     191                 :          1 :         context->self_test_result |= LIBSPDM_FIPS_SELF_TEST_HMAC_SHA512;
+     192                 :            :     } else {
+     193                 :          0 :         context->self_test_result &= ~LIBSPDM_FIPS_SELF_TEST_HMAC_SHA512;
+     194                 :            :     }
+     195                 :            : 
+     196                 :            : #endif/*LIBSPDM_SHA512_SUPPORT*/
+     197                 :            : 
+     198                 :          1 :     return result;
+     199                 :            : }
+     200                 :            : 
+     201                 :            : #endif/*LIBSPDM_FIPS_MODE*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_rsa_pss.c.func-sort-c.html b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_rsa_pss.c.func-sort-c.html new file mode 100644 index 00000000000..bc4150b603f --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_rsa_pss.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips/libspdm_selftest_rsa_pss.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fips - libspdm_selftest_rsa_pss.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:356752.2 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:122450.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_fips_selftest_rsa_pss1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_rsa_pss.c.func.html b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_rsa_pss.c.func.html new file mode 100644 index 00000000000..e93a1d8c5a7 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_rsa_pss.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips/libspdm_selftest_rsa_pss.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fips - libspdm_selftest_rsa_pss.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:356752.2 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:122450.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_fips_selftest_rsa_pss1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_rsa_pss.c.gcov.html b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_rsa_pss.c.gcov.html new file mode 100644 index 00000000000..4122af4f289 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_rsa_pss.c.gcov.html @@ -0,0 +1,294 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips/libspdm_selftest_rsa_pss.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fips - libspdm_selftest_rsa_pss.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:356752.2 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:122450.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2023 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_crypt_lib.h"
+       8                 :            : #include "internal/libspdm_common_lib.h"
+       9                 :            : #include "internal/libspdm_fips_lib.h"
+      10                 :            : #include "library/spdm_crypt_lib.h"
+      11                 :            : 
+      12                 :            : #if LIBSPDM_FIPS_MODE
+      13                 :            : 
+      14                 :            : /**
+      15                 :            :  * RSA_PSS self_test
+      16                 :            :  **/
+      17                 :          1 : bool libspdm_fips_selftest_rsa_pss(void *fips_selftest_context)
+      18                 :            : {
+      19                 :          1 :     bool result = true;
+      20                 :            : 
+      21                 :            : #if (LIBSPDM_RSA_PSS_SUPPORT) && (LIBSPDM_SHA256_SUPPORT)
+      22                 :          1 :     libspdm_fips_selftest_context *context = fips_selftest_context;
+      23         [ -  + ]:          1 :     LIBSPDM_ASSERT(fips_selftest_context != NULL);
+      24                 :            : 
+      25                 :            :     /* any test fail cause the FIPS fail*/
+      26         [ -  + ]:          1 :     if (context->tested_algo != context->self_test_result) {
+      27                 :          0 :         return false;
+      28                 :            :     }
+      29                 :            : 
+      30                 :            :     /* check if run before.*/
+      31         [ -  + ]:          1 :     if ((context->tested_algo & LIBSPDM_FIPS_SELF_TEST_RSA_PSS) != 0) {
+      32                 :          0 :         return true;
+      33                 :            :     }
+      34                 :            : 
+      35                 :            :     uint8_t signature[LIBSPDM_MAX_ASYM_KEY_SIZE];
+      36                 :            :     uint8_t digest[LIBSPDM_MAX_HASH_SIZE];
+      37                 :            :     size_t sig_size;
+      38                 :            :     void *rsa;
+      39                 :            : 
+      40                 :          1 :     sig_size = sizeof(signature);
+      41                 :          1 :     libspdm_zero_mem(signature, sig_size);
+      42                 :          1 :     libspdm_zero_mem(digest, LIBSPDM_MAX_HASH_SIZE);
+      43                 :            : 
+      44                 :            :     /*test vectors from: https://github.com/openssl/openssl/blob/OpenSSL-fips-2_0-stable/fips/rsa/fips_rsa_selftest.c*/
+      45                 :          1 :     const uint8_t public_n[] = {
+      46                 :            :         0xDB, 0x10, 0x1A, 0xC2, 0xA3, 0xF1, 0xDC, 0xFF, 0x13, 0x6B, 0xED, 0x44,
+      47                 :            :         0xDF, 0xF0, 0x02, 0x6D, 0x13, 0xC7, 0x88, 0xDA, 0x70, 0x6B, 0x54, 0xF1,
+      48                 :            :         0xE8, 0x27, 0xDC, 0xC3, 0x0F, 0x99, 0x6A, 0xFA, 0xC6, 0x67, 0xFF, 0x1D,
+      49                 :            :         0x1E, 0x3C, 0x1D, 0xC1, 0xB5, 0x5F, 0x6C, 0xC0, 0xB2, 0x07, 0x3A, 0x6D,
+      50                 :            :         0x41, 0xE4, 0x25, 0x99, 0xAC, 0xFC, 0xD2, 0x0F, 0x02, 0xD3, 0xD1, 0x54,
+      51                 :            :         0x06, 0x1A, 0x51, 0x77, 0xBD, 0xB6, 0xBF, 0xEA, 0xA7, 0x5C, 0x06, 0xA9,
+      52                 :            :         0x5D, 0x69, 0x84, 0x45, 0xD7, 0xF5, 0x05, 0xBA, 0x47, 0xF0, 0x1B, 0xD7,
+      53                 :            :         0x2B, 0x24, 0xEC, 0xCB, 0x9B, 0x1B, 0x10, 0x8D, 0x81, 0xA0, 0xBE, 0xB1,
+      54                 :            :         0x8C, 0x33, 0xE4, 0x36, 0xB8, 0x43, 0xEB, 0x19, 0x2A, 0x81, 0x8D, 0xDE,
+      55                 :            :         0x81, 0x0A, 0x99, 0x48, 0xB6, 0xF6, 0xBC, 0xCD, 0x49, 0x34, 0x3A, 0x8F,
+      56                 :            :         0x26, 0x94, 0xE3, 0x28, 0x82, 0x1A, 0x7C, 0x8F, 0x59, 0x9F, 0x45, 0xE8,
+      57                 :            :         0x5D, 0x1A, 0x45, 0x76, 0x04, 0x56, 0x05, 0xA1, 0xD0, 0x1B, 0x8C, 0x77,
+      58                 :            :         0x6D, 0xAF, 0x53, 0xFA, 0x71, 0xE2, 0x67, 0xE0, 0x9A, 0xFE, 0x03, 0xA9,
+      59                 :            :         0x85, 0xD2, 0xC9, 0xAA, 0xBA, 0x2A, 0xBC, 0xF4, 0xA0, 0x08, 0xF5, 0x13,
+      60                 :            :         0x98, 0x13, 0x5D, 0xF0, 0xD9, 0x33, 0x34, 0x2A, 0x61, 0xC3, 0x89, 0x55,
+      61                 :            :         0xF0, 0xAE, 0x1A, 0x9C, 0x22, 0xEE, 0x19, 0x05, 0x8D, 0x32, 0xFE, 0xEC,
+      62                 :            :         0x9C, 0x84, 0xBA, 0xB7, 0xF9, 0x6C, 0x3A, 0x4F, 0x07, 0xFC, 0x45, 0xEB,
+      63                 :            :         0x12, 0xE5, 0x7B, 0xFD, 0x55, 0xE6, 0x29, 0x69, 0xD1, 0xC2, 0xE8, 0xB9,
+      64                 :            :         0x78, 0x59, 0xF6, 0x79, 0x10, 0xC6, 0x4E, 0xEB, 0x6A, 0x5E, 0xB9, 0x9A,
+      65                 :            :         0xC7, 0xC4, 0x5B, 0x63, 0xDA, 0xA3, 0x3F, 0x5E, 0x92, 0x7A, 0x81, 0x5E,
+      66                 :            :         0xD6, 0xB0, 0xE2, 0x62, 0x8F, 0x74, 0x26, 0xC2, 0x0C, 0xD3, 0x9A, 0x17,
+      67                 :            :         0x47, 0xE6, 0x8E, 0xAB
+      68                 :            :     };
+      69                 :            : 
+      70                 :          1 :     const uint8_t e[] = {
+      71                 :            :         0x00, 0x01, 0x00, 0x01,
+      72                 :            :     };
+      73                 :            : 
+      74                 :          1 :     const uint8_t private_d[] = {
+      75                 :            :         0x52, 0x41, 0xF4, 0xDA, 0x7B, 0xB7, 0x59, 0x55, 0xCA, 0xD4, 0x2F, 0x0F,
+      76                 :            :         0x3A, 0xCB, 0xA4, 0x0D, 0x93, 0x6C, 0xCC, 0x9D, 0xC1, 0xB2, 0xFB, 0xFD,
+      77                 :            :         0xAE, 0x40, 0x31, 0xAC, 0x69, 0x52, 0x21, 0x92, 0xB3, 0x27, 0xDF, 0xEA,
+      78                 :            :         0xEE, 0x2C, 0x82, 0xBB, 0xF7, 0x40, 0x32, 0xD5, 0x14, 0xC4, 0x94, 0x12,
+      79                 :            :         0xEC, 0xB8, 0x1F, 0xCA, 0x59, 0xE3, 0xC1, 0x78, 0xF3, 0x85, 0xD8, 0x47,
+      80                 :            :         0xA5, 0xD7, 0x02, 0x1A, 0x65, 0x79, 0x97, 0x0D, 0x24, 0xF4, 0xF0, 0x67,
+      81                 :            :         0x6E, 0x75, 0x2D, 0xBF, 0x10, 0x3D, 0xA8, 0x7D, 0xEF, 0x7F, 0x60, 0xE4,
+      82                 :            :         0xE6, 0x05, 0x82, 0x89, 0x5D, 0xDF, 0xC6, 0xD2, 0x6C, 0x07, 0x91, 0x33,
+      83                 :            :         0x98, 0x42, 0xF0, 0x02, 0x00, 0x25, 0x38, 0xC5, 0x85, 0x69, 0x8A, 0x7D,
+      84                 :            :         0x2F, 0x95, 0x6C, 0x43, 0x9A, 0xB8, 0x81, 0xE2, 0xD0, 0x07, 0x35, 0xAA,
+      85                 :            :         0x05, 0x41, 0xC9, 0x1E, 0xAF, 0xE4, 0x04, 0x3B, 0x19, 0xB8, 0x73, 0xA2,
+      86                 :            :         0xAC, 0x4B, 0x1E, 0x66, 0x48, 0xD8, 0x72, 0x1F, 0xAC, 0xF6, 0xCB, 0xBC,
+      87                 :            :         0x90, 0x09, 0xCA, 0xEC, 0x0C, 0xDC, 0xF9, 0x2C, 0xD7, 0xEB, 0xAE, 0xA3,
+      88                 :            :         0xA4, 0x47, 0xD7, 0x33, 0x2F, 0x8A, 0xCA, 0xBC, 0x5E, 0xF0, 0x77, 0xE4,
+      89                 :            :         0x97, 0x98, 0x97, 0xC7, 0x10, 0x91, 0x7D, 0x2A, 0xA6, 0xFF, 0x46, 0x83,
+      90                 :            :         0x97, 0xDE, 0xE9, 0xE2, 0x17, 0x03, 0x06, 0x14, 0xE2, 0xD7, 0xB1, 0x1D,
+      91                 :            :         0x77, 0xAF, 0x51, 0x27, 0x5B, 0x5E, 0x69, 0xB8, 0x81, 0xE6, 0x11, 0xC5,
+      92                 :            :         0x43, 0x23, 0x81, 0x04, 0x62, 0xFF, 0xE9, 0x46, 0xB8, 0xD8, 0x44, 0xDB,
+      93                 :            :         0xA5, 0xCC, 0x31, 0x54, 0x34, 0xCE, 0x3E, 0x82, 0xD6, 0xBF, 0x7A, 0x0B,
+      94                 :            :         0x64, 0x21, 0x6D, 0x88, 0x7E, 0x5B, 0x45, 0x12, 0x1E, 0x63, 0x8D, 0x49,
+      95                 :            :         0xA7, 0x1D, 0xD9, 0x1E, 0x06, 0xCD, 0xE8, 0xBA, 0x2C, 0x8C, 0x69, 0x32,
+      96                 :            :         0xEA, 0xBE, 0x60, 0x71
+      97                 :            :     };
+      98                 :            : 
+      99                 :          1 :     const char kat_tbs[] = "OpenSSL FIPS 140-2 Public Key RSA KAT";
+     100                 :          1 :     const uint8_t kat_RSA_PSS_SHA256[] = {
+     101                 :            :         0x51, 0x4F, 0x0B, 0x8A, 0xE6, 0x7F, 0xF0, 0x39, 0x9B, 0x5F, 0x21, 0x26,
+     102                 :            :         0x99, 0x71, 0xDC, 0x64, 0x5A, 0x60, 0x9B, 0xFB, 0xB9, 0x48, 0xE3, 0xD4,
+     103                 :            :         0xDE, 0xAE, 0x2D, 0x87, 0x72, 0x14, 0x2A, 0x01, 0x4C, 0xC7, 0x5C, 0x00,
+     104                 :            :         0x15, 0xAE, 0x23, 0x09, 0x5F, 0xD5, 0xB5, 0x6F, 0x94, 0x59, 0x76, 0xEA,
+     105                 :            :         0x8C, 0x28, 0x90, 0xC4, 0xCD, 0xB9, 0xD7, 0xB5, 0x82, 0x9D, 0x4E, 0x37,
+     106                 :            :         0xE0, 0x79, 0x03, 0x88, 0x9F, 0x31, 0x71, 0x70, 0x80, 0xD6, 0x99, 0x49,
+     107                 :            :         0x20, 0x09, 0x30, 0x64, 0x52, 0xCD, 0x5C, 0x10, 0x72, 0x29, 0x4D, 0x33,
+     108                 :            :         0x10, 0xF6, 0xEB, 0xB7, 0x27, 0x95, 0x55, 0x48, 0xBE, 0x5A, 0xBE, 0xA7,
+     109                 :            :         0x74, 0xCF, 0x0E, 0x95, 0x28, 0xF4, 0x05, 0x98, 0x86, 0xBA, 0x36, 0x5C,
+     110                 :            :         0x91, 0x8F, 0x5D, 0xC1, 0xBD, 0xBE, 0x74, 0xD9, 0x74, 0x7B, 0xEC, 0xD1,
+     111                 :            :         0x4E, 0x79, 0x66, 0x14, 0x24, 0x21, 0x27, 0x2D, 0xCF, 0x93, 0xC0, 0xE1,
+     112                 :            :         0x92, 0x79, 0xE0, 0x4D, 0x65, 0xE2, 0xA4, 0xBA, 0x1F, 0x96, 0x16, 0xB1,
+     113                 :            :         0x90, 0xE1, 0x50, 0xDE, 0x2F, 0xB0, 0x07, 0xAF, 0x84, 0xCC, 0x81, 0x1C,
+     114                 :            :         0x42, 0xA9, 0x1B, 0xF6, 0x25, 0xDF, 0x6F, 0xEB, 0x9A, 0xF0, 0x93, 0xF3,
+     115                 :            :         0x66, 0xE7, 0x88, 0x7B, 0xF9, 0xA5, 0x92, 0xA9, 0xD5, 0x35, 0xAA, 0x33,
+     116                 :            :         0x8F, 0xEA, 0x68, 0xDB, 0x82, 0xE5, 0x69, 0xBB, 0x95, 0x31, 0xC3, 0x4F,
+     117                 :            :         0x0A, 0x68, 0x15, 0x8A, 0x93, 0x91, 0xE2, 0x3B, 0xDC, 0xA4, 0x94, 0x2F,
+     118                 :            :         0x34, 0xBC, 0xCE, 0xC9, 0xA6, 0xF0, 0x49, 0x33, 0x5B, 0x8F, 0xDB, 0x60,
+     119                 :            :         0xE8, 0x37, 0x8C, 0x97, 0xF9, 0xFB, 0x28, 0x0A, 0xF1, 0xAD, 0x4D, 0x9D,
+     120                 :            :         0xC0, 0x57, 0x4D, 0xD0, 0x26, 0x76, 0x36, 0x21, 0x67, 0x97, 0x73, 0xCD,
+     121                 :            :         0x26, 0x3A, 0xCD, 0x44, 0x77, 0xF2, 0x59, 0xBB, 0xDF, 0x77, 0x3B, 0x98,
+     122                 :            :         0xC5, 0x57, 0xB7, 0x5D
+     123                 :            :     };
+     124                 :            : 
+     125                 :          1 :     result = libspdm_sha256_hash_all(kat_tbs, sizeof(kat_tbs) - 1, digest);
+     126         [ -  + ]:          1 :     if (!result) {
+     127                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "Hash sha256 failed \n"));
+     128                 :          0 :         return false;
+     129                 :            :     }
+     130                 :            : 
+     131                 :          1 :     rsa = libspdm_rsa_new();
+     132         [ -  + ]:          1 :     if (rsa == NULL) {
+     133                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "RSA_PSS rsa new failed \n"));
+     134                 :          0 :         result = false;
+     135                 :          0 :         goto update;
+     136                 :            :     }
+     137                 :            : 
+     138                 :          1 :     result = libspdm_rsa_set_key(rsa, LIBSPDM_RSA_KEY_N, public_n, sizeof(public_n));
+     139         [ -  + ]:          1 :     if (!result) {
+     140                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "RSA_PSS rsa set key failed \n"));
+     141                 :          0 :         libspdm_rsa_free(rsa);
+     142                 :          0 :         result = false;
+     143                 :          0 :         goto update;
+     144                 :            :     }
+     145                 :            : 
+     146                 :          1 :     result = libspdm_rsa_set_key(rsa, LIBSPDM_RSA_KEY_E, e, sizeof(e));
+     147         [ -  + ]:          1 :     if (!result) {
+     148                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "RSA_PSS rsa set key failed \n"));
+     149                 :          0 :         libspdm_rsa_free(rsa);
+     150                 :          0 :         result = false;
+     151                 :          0 :         goto update;
+     152                 :            :     }
+     153                 :            : 
+     154                 :          1 :     result = libspdm_rsa_set_key(rsa, LIBSPDM_RSA_KEY_D, private_d, sizeof(private_d));
+     155         [ -  + ]:          1 :     if (!result) {
+     156                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "RSA_PSS rsa set key failed \n"));
+     157                 :          0 :         libspdm_rsa_free(rsa);
+     158                 :          0 :         result = false;
+     159                 :          0 :         goto update;
+     160                 :            :     }
+     161                 :            : 
+     162                 :          1 :     result = libspdm_rsa_pss_sign_fips(rsa, LIBSPDM_CRYPTO_NID_SHA256,
+     163                 :            :                                        digest, LIBSPDM_SHA256_DIGEST_SIZE,
+     164                 :            :                                        signature, &sig_size);
+     165         [ -  + ]:          1 :     if (!result) {
+     166                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "RSA_PSS rsa sign failed \n"));
+     167                 :          0 :         libspdm_rsa_free(rsa);
+     168                 :          0 :         result = false;
+     169                 :          0 :         goto update;
+     170                 :            :     }
+     171                 :            : 
+     172                 :            :     /*KAT test*/
+     173         [ -  + ]:          1 :     if (!libspdm_consttime_is_mem_equal(signature, kat_RSA_PSS_SHA256,
+     174                 :            :                                         sizeof(kat_RSA_PSS_SHA256))) {
+     175                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "RSA_PSS KAT failed \n"));
+     176                 :          0 :         libspdm_rsa_free(rsa);
+     177                 :          0 :         result = false;
+     178                 :          0 :         goto update;
+     179                 :            :     }
+     180                 :            : 
+     181                 :          1 :     result = libspdm_rsa_pss_verify_fips(rsa, LIBSPDM_CRYPTO_NID_SHA256,
+     182                 :            :                                          digest, LIBSPDM_SHA256_DIGEST_SIZE,
+     183                 :            :                                          signature, sig_size);
+     184         [ -  + ]:          1 :     if (!result) {
+     185                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "RSA_PSS selftest failed \n"));
+     186                 :          0 :         libspdm_rsa_free(rsa);
+     187                 :          0 :         result = false;
+     188                 :          0 :         goto update;
+     189                 :            :     }
+     190                 :            : 
+     191                 :          1 :     libspdm_rsa_free(rsa);
+     192                 :            : 
+     193                 :          1 : update:
+     194                 :            :     /* mark it as tested*/
+     195                 :          1 :     context->tested_algo |= LIBSPDM_FIPS_SELF_TEST_RSA_PSS;
+     196                 :            : 
+     197                 :            :     /* record test result*/
+     198         [ +  - ]:          1 :     if (result) {
+     199                 :          1 :         context->self_test_result |= LIBSPDM_FIPS_SELF_TEST_RSA_PSS;
+     200                 :            :     } else {
+     201                 :          0 :         context->self_test_result &= ~LIBSPDM_FIPS_SELF_TEST_RSA_PSS;
+     202                 :            :     }
+     203                 :            : 
+     204                 :            : #endif/*(LIBSPDM_RSA_PSS_SUPPORT) && (LIBSPDM_SHA256_SUPPORT)*/
+     205                 :            : 
+     206                 :          1 :     return result;
+     207                 :            : }
+     208                 :            : 
+     209                 :            : #endif
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_rsa_ssa.c.func-sort-c.html b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_rsa_ssa.c.func-sort-c.html new file mode 100644 index 00000000000..d9ca936ba6a --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_rsa_ssa.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips/libspdm_selftest_rsa_ssa.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fips - libspdm_selftest_rsa_ssa.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:336749.3 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:122450.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_fips_selftest_rsa_ssa1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_rsa_ssa.c.func.html b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_rsa_ssa.c.func.html new file mode 100644 index 00000000000..b3c994cb981 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_rsa_ssa.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips/libspdm_selftest_rsa_ssa.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fips - libspdm_selftest_rsa_ssa.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:336749.3 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:122450.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_fips_selftest_rsa_ssa1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_rsa_ssa.c.gcov.html b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_rsa_ssa.c.gcov.html new file mode 100644 index 00000000000..4441447ca6a --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_rsa_ssa.c.gcov.html @@ -0,0 +1,327 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips/libspdm_selftest_rsa_ssa.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fips - libspdm_selftest_rsa_ssa.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:336749.3 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:122450.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2023 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_crypt_lib.h"
+       8                 :            : #include "internal/libspdm_common_lib.h"
+       9                 :            : #include "internal/libspdm_fips_lib.h"
+      10                 :            : 
+      11                 :            : #if LIBSPDM_FIPS_MODE
+      12                 :            : 
+      13                 :            : /**
+      14                 :            :  * RSA_SSA(RSASSA-PKCS1 v1.5) self_test
+      15                 :            :  **/
+      16                 :          1 : bool libspdm_fips_selftest_rsa_ssa(void *fips_selftest_context)
+      17                 :            : {
+      18                 :          1 :     bool result = true;
+      19                 :            : 
+      20                 :            : #if LIBSPDM_RSA_SSA_SUPPORT
+      21                 :          1 :     libspdm_fips_selftest_context *context = fips_selftest_context;
+      22         [ -  + ]:          1 :     LIBSPDM_ASSERT(fips_selftest_context != NULL);
+      23                 :            : 
+      24                 :            :     /* any test fail cause the FIPS fail*/
+      25         [ -  + ]:          1 :     if (context->tested_algo != context->self_test_result) {
+      26                 :          0 :         return false;
+      27                 :            :     }
+      28                 :            : 
+      29                 :            :     /* check if run before.*/
+      30         [ -  + ]:          1 :     if ((context->tested_algo & LIBSPDM_FIPS_SELF_TEST_RSA_SSA) != 0) {
+      31                 :          0 :         return true;
+      32                 :            :     }
+      33                 :            : 
+      34                 :            :     uint8_t signature[1024];
+      35                 :            :     size_t sig_size;
+      36                 :            :     void *rsa;
+      37                 :            : 
+      38                 :          1 :     sig_size = sizeof(signature);
+      39                 :          1 :     libspdm_zero_mem(signature, sig_size);
+      40                 :            : 
+      41                 :          1 :     const uint8_t public_n[] = {
+      42                 :            :         0xd2, 0x24, 0xb6, 0x24, 0x58, 0x15, 0x1f, 0xef,
+      43                 :            :         0x7c, 0x93, 0x50, 0x10, 0xe9, 0x3f, 0x01, 0x1a,
+      44                 :            :         0xd9, 0x2a, 0x2d, 0x16, 0x28, 0xfc, 0x27, 0xc1,
+      45                 :            :         0x66, 0x33, 0x12, 0xcc, 0x0e, 0x61, 0xf5, 0x90,
+      46                 :            :         0x46, 0x3a, 0x8f, 0x5d, 0x82, 0xdb, 0x99, 0x7f,
+      47                 :            :         0x41, 0xa1, 0x68, 0xaf, 0xb0, 0x15, 0xc4, 0xa5,
+      48                 :            :         0x2a, 0xf4, 0xd9, 0x49, 0x7f, 0x55, 0x57, 0x28,
+      49                 :            :         0xe5, 0xf8, 0xbe, 0xcf, 0xfd, 0x7e, 0x5c, 0x7e,
+      50                 :            :         0x5a, 0x6f, 0xcb, 0x8c, 0xe1, 0x3d, 0x7e, 0x9e,
+      51                 :            :         0x5d, 0x0f, 0x51, 0x97, 0x19, 0x37, 0x81, 0x39,
+      52                 :            :         0x11, 0xcb, 0xf9, 0x8c, 0x2f, 0x9a, 0x83, 0xb1,
+      53                 :            :         0xc9, 0x13, 0x08, 0x5e, 0x38, 0xc4, 0xef, 0x99,
+      54                 :            :         0xbd, 0xc9, 0xe4, 0x05, 0x04, 0xab, 0xfd, 0x9e,
+      55                 :            :         0xc2, 0x95, 0x29, 0xe9, 0x42, 0x8d, 0x3b, 0x06,
+      56                 :            :         0x63, 0x6e, 0xcb, 0x01, 0x7f, 0x9d, 0x10, 0x69,
+      57                 :            :         0xf8, 0x53, 0x64, 0x9a, 0x43, 0x54, 0x62, 0x0f,
+      58                 :            :         0x9a, 0x50, 0xcc, 0x2d, 0x32, 0xfb, 0x5c, 0x22,
+      59                 :            :         0x10, 0x98, 0xa7, 0x52, 0xdb, 0xf2, 0x3a, 0x43,
+      60                 :            :         0x68, 0x28, 0xce, 0x3d, 0x58, 0xc4, 0x8b, 0xd4,
+      61                 :            :         0x94, 0xd7, 0x85, 0xea, 0x4b, 0x01, 0xab, 0x12,
+      62                 :            :         0x7e, 0xc3, 0x04, 0x97, 0xfb, 0xf8, 0x73, 0x79,
+      63                 :            :         0x89, 0x49, 0xf4, 0x06, 0x67, 0x8e, 0x07, 0x4e,
+      64                 :            :         0x0d, 0x91, 0x19, 0x53, 0x55, 0x46, 0xd1, 0xf7,
+      65                 :            :         0x76, 0x18, 0xf7, 0x64, 0x36, 0x10, 0xdd, 0xa7,
+      66                 :            :         0xac, 0x00, 0xca, 0x10, 0x3d, 0x4e, 0x05, 0x6a,
+      67                 :            :         0x7d, 0x42, 0x89, 0xc4, 0x74, 0xf4, 0x93, 0x67,
+      68                 :            :         0x51, 0xe0, 0xc9, 0x76, 0x21, 0x2f, 0xc3, 0xb9,
+      69                 :            :         0x30, 0x28, 0x91, 0x76, 0x56, 0xbf, 0xd8, 0x2d,
+      70                 :            :         0xcf, 0x5b, 0xdc, 0x42, 0xf9, 0x1f, 0xf1, 0xa8,
+      71                 :            :         0xc9, 0x3a, 0x4b, 0x0f, 0xff, 0x7a, 0xa0, 0xf9,
+      72                 :            :         0xe8, 0x87, 0x98, 0x38, 0x30, 0xa8, 0x96, 0x45,
+      73                 :            :         0x28, 0x3a, 0x86, 0x28, 0x02, 0xa2, 0x96, 0xcf
+      74                 :            :     };
+      75                 :            : 
+      76                 :          1 :     const uint8_t e[] = {
+      77                 :            :         0x00, 0x01, 0x00, 0x01,
+      78                 :            :     };
+      79                 :            : 
+      80                 :          1 :     const uint8_t private_d[] = {
+      81                 :            :         0x57, 0x87, 0x04, 0xfa, 0x94, 0x59, 0x90, 0x28,
+      82                 :            :         0xaf, 0x09, 0xa8, 0xc2, 0xb2, 0x74, 0x14, 0xa0,
+      83                 :            :         0xbb, 0x2d, 0x4f, 0x04, 0x38, 0xe3, 0xf6, 0x27,
+      84                 :            :         0x1e, 0xcb, 0x4d, 0x1c, 0x03, 0x2d, 0x98, 0x1b,
+      85                 :            :         0x94, 0xb4, 0xd5, 0x7c, 0x0c, 0x82, 0x2d, 0x28,
+      86                 :            :         0x0d, 0x0d, 0x0e, 0xce, 0x86, 0x98, 0x3a, 0x84,
+      87                 :            :         0xd5, 0x24, 0x90, 0xd0, 0x85, 0x21, 0xe5, 0xa0,
+      88                 :            :         0xda, 0x50, 0xc6, 0x21, 0x59, 0xa3, 0x65, 0x21,
+      89                 :            :         0x17, 0xc8, 0x12, 0xcf, 0x46, 0x0d, 0xd8, 0x0c,
+      90                 :            :         0x5c, 0x14, 0x82, 0x56, 0x5e, 0x21, 0x79, 0x48,
+      91                 :            :         0x6c, 0xfa, 0x39, 0xa1, 0xc3, 0x3e, 0x27, 0x76,
+      92                 :            :         0x48, 0x9b, 0x0d, 0xd4, 0x38, 0xef, 0x06, 0x21,
+      93                 :            :         0x52, 0x24, 0xa2, 0x3d, 0xd8, 0xd9, 0x4e, 0x54,
+      94                 :            :         0xef, 0x15, 0x34, 0x14, 0xbd, 0x2c, 0x98, 0x16,
+      95                 :            :         0x2c, 0x1a, 0x3c, 0xa2, 0x0e, 0x26, 0x3c, 0x6c,
+      96                 :            :         0xf7, 0x0a, 0xbd, 0x0f, 0x67, 0xd5, 0xe0, 0xd5,
+      97                 :            :         0x7f, 0x90, 0x82, 0x49, 0xa7, 0x0f, 0xe8, 0x77,
+      98                 :            :         0xe3, 0x67, 0x39, 0xfe, 0x1f, 0x5f, 0x70, 0xa8,
+      99                 :            :         0x47, 0x77, 0x3a, 0x9a, 0xda, 0xc1, 0x63, 0x7a,
+     100                 :            :         0x5f, 0x98, 0xbc, 0x2a, 0x55, 0xee, 0xfc, 0x7c,
+     101                 :            :         0xe0, 0xf6, 0x0b, 0xe0, 0xe5, 0x77, 0x8c, 0x1f,
+     102                 :            :         0x8e, 0x60, 0xc5, 0xc5, 0x24, 0xb7, 0x95, 0xff,
+     103                 :            :         0x5f, 0xb2, 0xda, 0xf8, 0xb8, 0x3a, 0xc2, 0x9e,
+     104                 :            :         0xe1, 0x68, 0x4f, 0x27, 0xde, 0x24, 0xbb, 0x92,
+     105                 :            :         0xb0, 0x6c, 0xf3, 0x4c, 0xbf, 0x6c, 0x74, 0x05,
+     106                 :            :         0x6f, 0xe9, 0x6c, 0x7a, 0x11, 0x3d, 0xb7, 0xe6,
+     107                 :            :         0xbc, 0xc9, 0x35, 0x4a, 0x5c, 0xc2, 0xd3, 0xf7,
+     108                 :            :         0x54, 0x94, 0xb2, 0x7c, 0x17, 0x01, 0xfa, 0x08,
+     109                 :            :         0xfc, 0xb3, 0xf5, 0x5b, 0xb2, 0xc0, 0x07, 0xdb,
+     110                 :            :         0x23, 0x6b, 0xac, 0xf9, 0x29, 0x8b, 0xe7, 0xa9,
+     111                 :            :         0x0f, 0x48, 0x7f, 0x1d, 0x6e, 0x76, 0x3c, 0x3b,
+     112                 :            :         0x62, 0xe9, 0xc1, 0xfd, 0xd4, 0xc0, 0x9d, 0xf9
+     113                 :            :     };
+     114                 :            : 
+     115                 :          1 :     const uint8_t input_data[] = {
+     116                 :            :         0x19, 0x90, 0x2d, 0x02, 0x34, 0x6e, 0xd5, 0x90,
+     117                 :            :         0x0e, 0x69, 0x51, 0x2f, 0xf2, 0xbd, 0x9d, 0x33,
+     118                 :            :         0x26, 0x71, 0x8f, 0x62, 0xa0, 0x01, 0xbd, 0xfd,
+     119                 :            :         0x94, 0xe2, 0x98, 0x17, 0x24, 0xfd, 0xca, 0xf0
+     120                 :            :     };
+     121                 :            : 
+     122                 :          1 :     const uint8_t expected_sig[] = {
+     123                 :            :         0x7b, 0x5c, 0x58, 0xd7, 0x81, 0xfc, 0xbb, 0x82,
+     124                 :            :         0x65, 0x1f, 0x17, 0xe2, 0x29, 0x75, 0x2a, 0x20,
+     125                 :            :         0xe3, 0xa0, 0x46, 0x3b, 0xd0, 0xd2, 0x10, 0x9a,
+     126                 :            :         0x09, 0x85, 0xe1, 0x4b, 0x68, 0x11, 0x64, 0xc9,
+     127                 :            :         0x44, 0xf4, 0x42, 0x11, 0x31, 0xbe, 0x02, 0xd4,
+     128                 :            :         0x2e, 0xe2, 0x8c, 0xb7, 0x33, 0xb9, 0xec, 0x0f,
+     129                 :            :         0xac, 0xad, 0x07, 0x74, 0xd7, 0xc4, 0xe7, 0x32,
+     130                 :            :         0xae, 0xd0, 0x01, 0xbe, 0x14, 0x5f, 0x40, 0x54,
+     131                 :            :         0x48, 0x4c, 0x24, 0x69, 0x39, 0x6b, 0x43, 0x3d,
+     132                 :            :         0xe3, 0xde, 0x06, 0x57, 0x13, 0xa9, 0x43, 0xef,
+     133                 :            :         0x4e, 0x75, 0x95, 0x5c, 0x77, 0x3e, 0xe1, 0x76,
+     134                 :            :         0x0c, 0xff, 0x51, 0x49, 0xa6, 0x62, 0x2a, 0x82,
+     135                 :            :         0x01, 0x76, 0xec, 0x2c, 0xcd, 0x48, 0x0d, 0x2e,
+     136                 :            :         0x6b, 0xdd, 0x8a, 0xd0, 0x2d, 0xaf, 0x3d, 0x5a,
+     137                 :            :         0xee, 0xc4, 0x6a, 0xdd, 0x04, 0x47, 0xb1, 0x5e,
+     138                 :            :         0xd0, 0x90, 0xee, 0xa6, 0xe7, 0x0f, 0x99, 0xb2,
+     139                 :            :         0x4e, 0xe4, 0xee, 0x30, 0x9e, 0xb2, 0x5e, 0xb9,
+     140                 :            :         0x7c, 0x75, 0xe1, 0xba, 0x60, 0x49, 0x94, 0x9b,
+     141                 :            :         0xd6, 0xa7, 0xe1, 0x9e, 0x24, 0xbc, 0x9e, 0x37,
+     142                 :            :         0xcf, 0x07, 0xea, 0xa8, 0xaf, 0xcc, 0xee, 0xf1,
+     143                 :            :         0x22, 0x2a, 0xdb, 0x3d, 0x4f, 0x29, 0xf4, 0x48,
+     144                 :            :         0x49, 0x56, 0xb4, 0xc6, 0x89, 0x3b, 0x7e, 0xd7,
+     145                 :            :         0x08, 0x7c, 0x2a, 0xb4, 0xcc, 0x6e, 0x4c, 0x12,
+     146                 :            :         0x6f, 0xbc, 0xac, 0xfb, 0xb0, 0xe5, 0xf7, 0xc7,
+     147                 :            :         0x57, 0xb3, 0x84, 0xa6, 0xb9, 0x2f, 0x59, 0xea,
+     148                 :            :         0xaa, 0xf0, 0x9a, 0xe7, 0xff, 0xbc, 0xf8, 0x12,
+     149                 :            :         0x09, 0x6e, 0x2b, 0xf8, 0x24, 0xc0, 0x45, 0xb4,
+     150                 :            :         0x0c, 0x23, 0x05, 0x7d, 0xf5, 0xc6, 0x8a, 0x19,
+     151                 :            :         0x30, 0x8a, 0x40, 0x5a, 0xc6, 0xbd, 0x66, 0xd5,
+     152                 :            :         0xdf, 0xc1, 0xbb, 0x8f, 0x26, 0x2d, 0xd1, 0xaf,
+     153                 :            :         0x46, 0x47, 0xef, 0x2b, 0x3d, 0x73, 0xd5, 0xcb,
+     154                 :            :         0x4a, 0xda, 0xf8, 0x0e, 0xf6, 0xdf, 0x5e, 0x7b
+     155                 :            :     };
+     156                 :            : 
+     157                 :          1 :     rsa = libspdm_rsa_new();
+     158         [ -  + ]:          1 :     if (rsa == NULL) {
+     159                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "RSA_SSA rsa new failed \n"));
+     160                 :          0 :         result = false;
+     161                 :          0 :         goto update;
+     162                 :            :     }
+     163                 :            : 
+     164                 :          1 :     result = libspdm_rsa_set_key(rsa, LIBSPDM_RSA_KEY_N, public_n, sizeof(public_n));
+     165         [ -  + ]:          1 :     if (!result) {
+     166                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "RSA_SSA rsa set key failed \n"));
+     167                 :          0 :         libspdm_rsa_free(rsa);
+     168                 :          0 :         result = false;
+     169                 :          0 :         goto update;
+     170                 :            :     }
+     171                 :            : 
+     172                 :          1 :     result = libspdm_rsa_set_key(rsa, LIBSPDM_RSA_KEY_E, e, sizeof(e));
+     173         [ -  + ]:          1 :     if (!result) {
+     174                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "RSA_SSA rsa set key failed \n"));
+     175                 :          0 :         libspdm_rsa_free(rsa);
+     176                 :          0 :         result = false;
+     177                 :          0 :         goto update;
+     178                 :            :     }
+     179                 :            : 
+     180                 :          1 :     result = libspdm_rsa_set_key(rsa, LIBSPDM_RSA_KEY_D, private_d, sizeof(private_d));
+     181         [ -  + ]:          1 :     if (!result) {
+     182                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "RSA_SSA rsa set key failed \n"));
+     183                 :          0 :         libspdm_rsa_free(rsa);
+     184                 :          0 :         result = false;
+     185                 :          0 :         goto update;
+     186                 :            :     }
+     187                 :            : 
+     188                 :          1 :     result = libspdm_rsa_pkcs1_sign_with_nid(rsa, LIBSPDM_CRYPTO_NID_SHA256,
+     189                 :            :                                              input_data, sizeof(input_data),
+     190                 :            :                                              signature, &sig_size);
+     191         [ -  + ]:          1 :     if (!result) {
+     192                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "RSA_SSA rsa sign failed \n"));
+     193                 :          0 :         libspdm_rsa_free(rsa);
+     194                 :          0 :         result = false;
+     195                 :          0 :         goto update;
+     196                 :            :     }
+     197                 :            : 
+     198                 :            :     /*KAT test*/
+     199         [ -  + ]:          1 :     if (sig_size != sizeof(expected_sig)) {
+     200                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "RSA_SSA KAT failed \n"));
+     201                 :          0 :         libspdm_rsa_free(rsa);
+     202                 :          0 :         result = false;
+     203                 :          0 :         goto update;
+     204                 :            :     }
+     205                 :            : 
+     206         [ -  + ]:          1 :     if (!libspdm_consttime_is_mem_equal(signature, expected_sig,
+     207                 :            :                                         sizeof(expected_sig))) {
+     208                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "RSA_SSA KAT failed \n"));
+     209                 :          0 :         libspdm_rsa_free(rsa);
+     210                 :          0 :         result = false;
+     211                 :          0 :         goto update;
+     212                 :            :     }
+     213                 :            : 
+     214                 :          1 :     result = libspdm_rsa_pkcs1_verify_with_nid(rsa, LIBSPDM_CRYPTO_NID_SHA256,
+     215                 :            :                                                input_data, sizeof(input_data),
+     216                 :            :                                                signature, sig_size);
+     217         [ -  + ]:          1 :     if (!result) {
+     218                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "RSA_SSA selftest failed \n"));
+     219                 :          0 :         libspdm_rsa_free(rsa);
+     220                 :          0 :         result = false;
+     221                 :          0 :         goto update;
+     222                 :            :     }
+     223                 :            : 
+     224                 :          1 :     libspdm_rsa_free(rsa);
+     225                 :            : 
+     226                 :          1 : update:
+     227                 :            :     /* mark it as tested*/
+     228                 :          1 :     context->tested_algo |= LIBSPDM_FIPS_SELF_TEST_RSA_SSA;
+     229                 :            : 
+     230                 :            :     /* record test result*/
+     231         [ +  - ]:          1 :     if (result) {
+     232                 :          1 :         context->self_test_result |= LIBSPDM_FIPS_SELF_TEST_RSA_SSA;
+     233                 :            :     } else {
+     234                 :          0 :         context->self_test_result &= ~LIBSPDM_FIPS_SELF_TEST_RSA_SSA;
+     235                 :            :     }
+     236                 :            : 
+     237                 :            : #endif/*LIBSPDM_RSA_SSA_SUPPORT*/
+     238                 :            : 
+     239                 :          1 :     return result;
+     240                 :            : }
+     241                 :            : 
+     242                 :            : #endif
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_sha2.c.func-sort-c.html b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_sha2.c.func-sort-c.html new file mode 100644 index 00000000000..245924ecae4 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_sha2.c.func-sort-c.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips/libspdm_selftest_sha2.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fips - libspdm_selftest_sha2.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:334278.6 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:122450.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_fips_selftest_sha2561
libspdm_fips_selftest_sha3841
libspdm_fips_selftest_sha5121
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_sha2.c.func.html b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_sha2.c.func.html new file mode 100644 index 00000000000..d9864547062 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_sha2.c.func.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips/libspdm_selftest_sha2.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fips - libspdm_selftest_sha2.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:334278.6 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:122450.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_fips_selftest_sha2561
libspdm_fips_selftest_sha3841
libspdm_fips_selftest_sha5121
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_sha2.c.gcov.html b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_sha2.c.gcov.html new file mode 100644 index 00000000000..f23e85071d8 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_sha2.c.gcov.html @@ -0,0 +1,209 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips/libspdm_selftest_sha2.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fips - libspdm_selftest_sha2.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:334278.6 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:122450.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2023 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_crypt_lib.h"
+       8                 :            : #include "internal/libspdm_fips_lib.h"
+       9                 :            : #include "internal/libspdm_common_lib.h"
+      10                 :            : 
+      11                 :            : #if LIBSPDM_FIPS_MODE
+      12                 :            : 
+      13                 :            : /**
+      14                 :            :  * SHA256 KAT: HMAC-SHA256 KAT covers SHA256 KAT.
+      15                 :            :  **/
+      16                 :          1 : bool libspdm_fips_selftest_sha256(void *fips_selftest_context)
+      17                 :            : {
+      18                 :          1 :     bool result = true;
+      19                 :            : 
+      20                 :            : #if LIBSPDM_SHA256_SUPPORT
+      21                 :          1 :     libspdm_fips_selftest_context *context = fips_selftest_context;
+      22         [ -  + ]:          1 :     LIBSPDM_ASSERT(fips_selftest_context != NULL);
+      23                 :            : 
+      24                 :            :     /* any test fail cause the FIPS fail*/
+      25         [ -  + ]:          1 :     if (context->tested_algo != context->self_test_result) {
+      26                 :          0 :         return false;
+      27                 :            :     }
+      28                 :            : 
+      29                 :            :     /* check if run before.*/
+      30         [ -  + ]:          1 :     if ((context->tested_algo & LIBSPDM_FIPS_SELF_TEST_SHA256) != 0) {
+      31                 :          0 :         return true;
+      32                 :            :     }
+      33                 :            : 
+      34                 :          1 :     result = libspdm_fips_selftest_hmac_sha256(context);
+      35                 :            : 
+      36                 :            :     /* mark it as tested*/
+      37                 :          1 :     context->tested_algo |= LIBSPDM_FIPS_SELF_TEST_SHA256;
+      38                 :            : 
+      39                 :            :     /* record test result*/
+      40         [ +  - ]:          1 :     if (result) {
+      41                 :          1 :         context->self_test_result |= LIBSPDM_FIPS_SELF_TEST_SHA256;
+      42                 :            :     } else {
+      43                 :          0 :         context->self_test_result &= ~LIBSPDM_FIPS_SELF_TEST_SHA256;
+      44                 :            :     }
+      45                 :            : #endif /*LIBSPDM_SHA256_SUPPORT*/
+      46                 :            : 
+      47                 :          1 :     return result;
+      48                 :            : }
+      49                 :            : 
+      50                 :            : /**
+      51                 :            :  * SHA384 KAT: HMAC-SHA384 KAT covers SHA384 KAT.
+      52                 :            :  **/
+      53                 :          1 : bool libspdm_fips_selftest_sha384(void *fips_selftest_context)
+      54                 :            : {
+      55                 :          1 :     bool result = true;
+      56                 :            : 
+      57                 :            : #if LIBSPDM_SHA384_SUPPORT
+      58                 :          1 :     libspdm_fips_selftest_context *context = fips_selftest_context;
+      59         [ -  + ]:          1 :     LIBSPDM_ASSERT(fips_selftest_context != NULL);
+      60                 :            : 
+      61                 :            :     /* any test fail cause the FIPS fail*/
+      62         [ -  + ]:          1 :     if (context->tested_algo != context->self_test_result) {
+      63                 :          0 :         return false;
+      64                 :            :     }
+      65                 :            : 
+      66                 :            :     /* check if run before.*/
+      67         [ -  + ]:          1 :     if ((context->tested_algo & LIBSPDM_FIPS_SELF_TEST_SHA384) != 0) {
+      68                 :          0 :         return true;
+      69                 :            :     }
+      70                 :            : 
+      71                 :          1 :     result = libspdm_fips_selftest_hmac_sha384(context);
+      72                 :            : 
+      73                 :            :     /* mark it as tested*/
+      74                 :          1 :     context->tested_algo |= LIBSPDM_FIPS_SELF_TEST_SHA384;
+      75                 :            : 
+      76                 :            :     /* record test result*/
+      77         [ +  - ]:          1 :     if (result) {
+      78                 :          1 :         context->self_test_result |= LIBSPDM_FIPS_SELF_TEST_SHA384;
+      79                 :            :     } else {
+      80                 :          0 :         context->self_test_result &= ~LIBSPDM_FIPS_SELF_TEST_SHA384;
+      81                 :            :     }
+      82                 :            : #endif /*LIBSPDM_SHA384_SUPPORT*/
+      83                 :            : 
+      84                 :          1 :     return result;
+      85                 :            : }
+      86                 :            : 
+      87                 :            : /**
+      88                 :            :  * SHA512 KAT: HMAC-SHA512 KAT covers SHA512 KAT.
+      89                 :            :  **/
+      90                 :          1 : bool libspdm_fips_selftest_sha512(void *fips_selftest_context)
+      91                 :            : {
+      92                 :          1 :     bool result = true;
+      93                 :            : 
+      94                 :            : #if LIBSPDM_SHA512_SUPPORT
+      95                 :          1 :     libspdm_fips_selftest_context *context = fips_selftest_context;
+      96         [ -  + ]:          1 :     LIBSPDM_ASSERT(fips_selftest_context != NULL);
+      97                 :            : 
+      98                 :            :     /* any test fail cause the FIPS fail*/
+      99         [ -  + ]:          1 :     if (context->tested_algo != context->self_test_result) {
+     100                 :          0 :         return false;
+     101                 :            :     }
+     102                 :            : 
+     103                 :            :     /* check if run before.*/
+     104         [ -  + ]:          1 :     if ((context->tested_algo & LIBSPDM_FIPS_SELF_TEST_SHA512) != 0) {
+     105                 :          0 :         return true;
+     106                 :            :     }
+     107                 :            : 
+     108                 :          1 :     result = libspdm_fips_selftest_hmac_sha512(context);
+     109                 :            : 
+     110                 :            :     /* mark it as tested*/
+     111                 :          1 :     context->tested_algo |= LIBSPDM_FIPS_SELF_TEST_SHA512;
+     112                 :            : 
+     113                 :            :     /* record test result*/
+     114         [ +  - ]:          1 :     if (result) {
+     115                 :          1 :         context->self_test_result |= LIBSPDM_FIPS_SELF_TEST_SHA512;
+     116                 :            :     } else {
+     117                 :          0 :         context->self_test_result &= ~LIBSPDM_FIPS_SELF_TEST_SHA512;
+     118                 :            :     }
+     119                 :            : #endif /*LIBSPDM_SHA512_SUPPORT*/
+     120                 :            : 
+     121                 :          1 :     return result;
+     122                 :            : }
+     123                 :            : 
+     124                 :            : #endif/*LIBSPDM_FIPS_MODE*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_sha3.c.func-sort-c.html b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_sha3.c.func-sort-c.html new file mode 100644 index 00000000000..afab65e82b6 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_sha3.c.func-sort-c.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips/libspdm_selftest_sha3.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fips - libspdm_selftest_sha3.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:99100.0 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_fips_selftest_sha3_2561
libspdm_fips_selftest_sha3_3841
libspdm_fips_selftest_sha3_5121
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_sha3.c.func.html b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_sha3.c.func.html new file mode 100644 index 00000000000..576d9bd55fa --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_sha3.c.func.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips/libspdm_selftest_sha3.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fips - libspdm_selftest_sha3.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:99100.0 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_fips_selftest_sha3_2561
libspdm_fips_selftest_sha3_3841
libspdm_fips_selftest_sha3_5121
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_sha3.c.gcov.html b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_sha3.c.gcov.html new file mode 100644 index 00000000000..b571b4b1440 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/fips/libspdm_selftest_sha3.c.gcov.html @@ -0,0 +1,287 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/fips/libspdm_selftest_sha3.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib/fips - libspdm_selftest_sha3.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:99100.0 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:00-
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2023 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_crypt_lib.h"
+       8                 :            : #include "internal/libspdm_common_lib.h"
+       9                 :            : #include "internal/libspdm_fips_lib.h"
+      10                 :            : 
+      11                 :            : #if LIBSPDM_FIPS_MODE
+      12                 :            : 
+      13                 :            : /**
+      14                 :            :  * SHA3_256 KAT
+      15                 :            :  **/
+      16                 :          1 : bool libspdm_fips_selftest_sha3_256(void *fips_selftest_context)
+      17                 :            : {
+      18                 :          1 :     bool result = true;
+      19                 :            : 
+      20                 :            : #if LIBSPDM_SHA3_256_SUPPORT
+      21                 :            :     libspdm_fips_selftest_context *context = fips_selftest_context;
+      22                 :            :     LIBSPDM_ASSERT(fips_selftest_context != NULL);
+      23                 :            : 
+      24                 :            :     /* any test fail cause the FIPS fail*/
+      25                 :            :     if (context->tested_algo != context->self_test_result) {
+      26                 :            :         return false;
+      27                 :            :     }
+      28                 :            : 
+      29                 :            :     /* check if run before.*/
+      30                 :            :     if ((context->tested_algo & LIBSPDM_FIPS_SELF_TEST_SHA3_256) != 0) {
+      31                 :            :         return true;
+      32                 :            :     }
+      33                 :            : 
+      34                 :            :     const uint8_t msg[] = {0x7f, 0x94};
+      35                 :            :     /*Test Vectors: https://csrc.nist.gov/Projects/Cryptographic-Algorithm-Validation-Program/Secure-Hashing#sha3vsha3vss */
+      36                 :            :     uint8_t sha3_256_result[32];
+      37                 :            :     const uint8_t sha3_256_answer[] = {
+      38                 :            :         0xde, 0x01, 0x6a, 0xcf, 0xc1, 0xa2, 0xe2, 0x2e,
+      39                 :            :         0x39, 0x52, 0x6c, 0x60, 0x9d, 0x9c, 0x69, 0xd8,
+      40                 :            :         0x56, 0xa5, 0x43, 0xfe, 0xbb, 0x3c, 0xb4, 0x26,
+      41                 :            :         0xee, 0x1f, 0x13, 0x18, 0xd7, 0x80, 0xea, 0x88
+      42                 :            :     };
+      43                 :            :     libspdm_zero_mem(sha3_256_result, sizeof(sha3_256_result));
+      44                 :            :     result = libspdm_sha3_256_hash_all(msg, sizeof(msg), sha3_256_result);
+      45                 :            :     if (!result) {
+      46                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "gen sha3_256 failed \n"));
+      47                 :            :         result = false;
+      48                 :            :         goto update;
+      49                 :            :     }
+      50                 :            : 
+      51                 :            :     if (!libspdm_consttime_is_mem_equal(sha3_256_result, sha3_256_answer,
+      52                 :            :                                         sizeof(sha3_256_answer))) {
+      53                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "sha3_256 KAT failed \n"));
+      54                 :            :         result = false;
+      55                 :            :         goto update;
+      56                 :            :     }
+      57                 :            : 
+      58                 :            : update:
+      59                 :            :     /* mark it as tested*/
+      60                 :            :     context->tested_algo |= LIBSPDM_FIPS_SELF_TEST_SHA3_256;
+      61                 :            : 
+      62                 :            :     /* record test result*/
+      63                 :            :     if (result) {
+      64                 :            :         context->self_test_result |= LIBSPDM_FIPS_SELF_TEST_SHA3_256;
+      65                 :            :     } else {
+      66                 :            :         context->self_test_result &= ~LIBSPDM_FIPS_SELF_TEST_SHA3_256;
+      67                 :            :     }
+      68                 :            : 
+      69                 :            : #endif/* LIBSPDM_SHA3_256_SUPPORT */
+      70                 :            : 
+      71                 :          1 :     return result;
+      72                 :            : }
+      73                 :            : 
+      74                 :            : /**
+      75                 :            :  * SHA3_384 KAT
+      76                 :            :  **/
+      77                 :          1 : bool libspdm_fips_selftest_sha3_384(void *fips_selftest_context)
+      78                 :            : {
+      79                 :          1 :     bool result = true;
+      80                 :            : 
+      81                 :            : #if LIBSPDM_SHA3_384_SUPPORT
+      82                 :            :     libspdm_fips_selftest_context *context = fips_selftest_context;
+      83                 :            :     LIBSPDM_ASSERT(fips_selftest_context != NULL);
+      84                 :            : 
+      85                 :            :     /* any test fail cause the FIPS fail*/
+      86                 :            :     if (context->tested_algo != context->self_test_result) {
+      87                 :            :         return false;
+      88                 :            :     }
+      89                 :            : 
+      90                 :            :     /* check if run before.*/
+      91                 :            :     if ((context->tested_algo & LIBSPDM_FIPS_SELF_TEST_SHA3_384) != 0) {
+      92                 :            :         return true;
+      93                 :            :     }
+      94                 :            : 
+      95                 :            :     uint8_t sha3_384_result[48];
+      96                 :            :     /*Test Vectors: https://csrc.nist.gov/Projects/Cryptographic-Algorithm-Validation-Program/Secure-Hashing#sha3vsha3vss */
+      97                 :            :     const uint8_t msg[] = {0x89, 0xcc};
+      98                 :            :     const uint8_t sha3_384_answer[] = {
+      99                 :            :         0xcf, 0x9b, 0xe5, 0x91, 0x0e, 0x2c, 0x4f, 0x89,
+     100                 :            :         0x5b, 0x9e, 0x92, 0x08, 0x02, 0x26, 0x52, 0xbb,
+     101                 :            :         0x4d, 0x6a, 0x7e, 0x85, 0x84, 0x5b, 0x2a, 0x6c,
+     102                 :            :         0x22, 0x1c, 0x22, 0x84, 0x1e, 0xc0, 0x74, 0x64,
+     103                 :            :         0xae, 0xe9, 0xfb, 0x5f, 0x89, 0x38, 0xb2, 0xda,
+     104                 :            :         0xa8, 0x7b, 0xe3, 0x37, 0xf0, 0x38, 0xcb, 0xcf
+     105                 :            :     };
+     106                 :            :     libspdm_zero_mem(sha3_384_result, sizeof(sha3_384_result));
+     107                 :            :     result = libspdm_sha3_384_hash_all(msg, sizeof(msg), sha3_384_result);
+     108                 :            :     if (!result) {
+     109                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "gen sha3_384 failed \n"));
+     110                 :            :         result = false;
+     111                 :            :         goto update;
+     112                 :            :     }
+     113                 :            : 
+     114                 :            :     if (!libspdm_consttime_is_mem_equal(sha3_384_result, sha3_384_answer,
+     115                 :            :                                         sizeof(sha3_384_answer))) {
+     116                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "sha3_384 KAT failed \n"));
+     117                 :            :         result = false;
+     118                 :            :         goto update;
+     119                 :            :     }
+     120                 :            : 
+     121                 :            : update:
+     122                 :            :     /* mark it as tested*/
+     123                 :            :     context->tested_algo |= LIBSPDM_FIPS_SELF_TEST_SHA3_384;
+     124                 :            : 
+     125                 :            :     /* record test result*/
+     126                 :            :     if (result) {
+     127                 :            :         context->self_test_result |= LIBSPDM_FIPS_SELF_TEST_SHA3_384;
+     128                 :            :     } else {
+     129                 :            :         context->self_test_result &= ~LIBSPDM_FIPS_SELF_TEST_SHA3_384;
+     130                 :            :     }
+     131                 :            : 
+     132                 :            : #endif/* LIBSPDM_SHA3_384_SUPPORT */
+     133                 :            : 
+     134                 :          1 :     return result;
+     135                 :            : }
+     136                 :            : 
+     137                 :            : /**
+     138                 :            :  * SHA3_512 KAT
+     139                 :            :  **/
+     140                 :          1 : bool libspdm_fips_selftest_sha3_512(void *fips_selftest_context)
+     141                 :            : {
+     142                 :          1 :     bool result = true;
+     143                 :            : 
+     144                 :            : #if LIBSPDM_SHA3_512_SUPPORT
+     145                 :            :     libspdm_fips_selftest_context *context = fips_selftest_context;
+     146                 :            :     LIBSPDM_ASSERT(fips_selftest_context != NULL);
+     147                 :            : 
+     148                 :            :     /* any test fail cause the FIPS fail*/
+     149                 :            :     if (context->tested_algo != context->self_test_result) {
+     150                 :            :         return false;
+     151                 :            :     }
+     152                 :            : 
+     153                 :            :     /* check if run before.*/
+     154                 :            :     if ((context->tested_algo & LIBSPDM_FIPS_SELF_TEST_SHA3_512) != 0) {
+     155                 :            :         return true;
+     156                 :            :     }
+     157                 :            : 
+     158                 :            :     uint8_t sha3_512_result[64];
+     159                 :            :     /*Test Vectors: https://csrc.nist.gov/Projects/Cryptographic-Algorithm-Validation-Program/Secure-Hashing#sha3vsha3vss */
+     160                 :            :     const uint8_t msg[] = {0xb1, 0x39};
+     161                 :            :     const uint8_t sha3_512_answer[] = {
+     162                 :            :         0xd3, 0xe5, 0xc0, 0x26, 0x47, 0x05, 0xe8, 0x1d,
+     163                 :            :         0x0c, 0x90, 0xf9, 0x9d, 0xae, 0xff, 0x00, 0x89,
+     164                 :            :         0xfa, 0x3e, 0x91, 0x77, 0xd3, 0xd5, 0xbc, 0x74,
+     165                 :            :         0x9c, 0xde, 0x10, 0xf0, 0x35, 0xf4, 0x95, 0x65,
+     166                 :            :         0x55, 0x44, 0xf8, 0x57, 0x79, 0x91, 0x71, 0x2e,
+     167                 :            :         0xb5, 0x18, 0x01, 0x5b, 0xe2, 0x9d, 0x19, 0x5b,
+     168                 :            :         0x7e, 0xbf, 0x61, 0xe8, 0xd2, 0x93, 0x90, 0xea,
+     169                 :            :         0xf1, 0x47, 0x88, 0x08, 0x2b, 0x11, 0x97, 0x6d
+     170                 :            :     };
+     171                 :            :     libspdm_zero_mem(sha3_512_result, sizeof(sha3_512_result));
+     172                 :            :     result = libspdm_sha3_512_hash_all(msg, sizeof(msg), sha3_512_result);
+     173                 :            :     if (!result) {
+     174                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "gen sha3_512 failed \n"));
+     175                 :            :         result = false;
+     176                 :            :         goto update;
+     177                 :            :     }
+     178                 :            : 
+     179                 :            :     if (!libspdm_consttime_is_mem_equal(sha3_512_result, sha3_512_answer,
+     180                 :            :                                         sizeof(sha3_512_answer))) {
+     181                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "sha3_512 KAT failed \n"));
+     182                 :            :         result = false;
+     183                 :            :         goto update;
+     184                 :            :     }
+     185                 :            : 
+     186                 :            : update:
+     187                 :            :     /* mark it as tested*/
+     188                 :            :     context->tested_algo |= LIBSPDM_FIPS_SELF_TEST_SHA3_512;
+     189                 :            : 
+     190                 :            :     /* record test result*/
+     191                 :            :     if (result) {
+     192                 :            :         context->self_test_result |= LIBSPDM_FIPS_SELF_TEST_SHA3_512;
+     193                 :            :     } else {
+     194                 :            :         context->self_test_result &= ~LIBSPDM_FIPS_SELF_TEST_SHA3_512;
+     195                 :            :     }
+     196                 :            : 
+     197                 :            : #endif/* LIBSPDM_SHA3_512_SUPPORT */
+     198                 :            : 
+     199                 :          1 :     return result;
+     200                 :            : }
+     201                 :            : 
+     202                 :            : #endif/*LIBSPDM_FIPS_MODE*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/index-sort-b.html b/coverage_log/library/spdm_crypt_lib/index-sort-b.html new file mode 100644 index 00000000000..ee8101c0437 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/index-sort-b.html @@ -0,0 +1,191 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_libHitTotalCoverage
Test:coverage.infoLines:892184448.4 %
Date:2024-09-22 08:21:07Functions:779481.9 %
Branches:41892945.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
libspdm_crypt_hmac.c +
2.4%2.4%
+
2.4 %4 / 16614.3 %1 / 71.7 %1 / 58
libspdm_crypt_hkdf.c +
17.4%17.4%
+
17.4 %8 / 46100.0 %2 / 212.5 %2 / 16
libspdm_crypt_hash.c +
23.1%23.1%
+
23.1 %50 / 216100.0 %10 / 1018.8 %15 / 80
libspdm_crypt_dhe.c +
37.4%37.4%
+
37.4 %34 / 91100.0 %6 / 630.6 %11 / 36
libspdm_crypt_aead.c +
45.2%45.2%
+
45.2 %28 / 62100.0 %5 / 539.1 %9 / 23
libspdm_crypt_asym.c +
50.9%50.9%
+
50.9 %314 / 61775.0 %27 / 3646.2 %153 / 331
libspdm_crypt_rng.c +
75.0%75.0%
+
75.0 %3 / 4100.0 %1 / 150.0 %1 / 2
libspdm_crypt_cert.c +
70.2%70.2%
+
70.2 %451 / 64292.6 %25 / 2759.0 %226 / 383
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/index-sort-f.html b/coverage_log/library/spdm_crypt_lib/index-sort-f.html new file mode 100644 index 00000000000..8eba518c974 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/index-sort-f.html @@ -0,0 +1,191 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_libHitTotalCoverage
Test:coverage.infoLines:892184448.4 %
Date:2024-09-22 08:21:07Functions:779481.9 %
Branches:41892945.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
libspdm_crypt_hmac.c +
2.4%2.4%
+
2.4 %4 / 16614.3 %1 / 71.7 %1 / 58
libspdm_crypt_asym.c +
50.9%50.9%
+
50.9 %314 / 61775.0 %27 / 3646.2 %153 / 331
libspdm_crypt_cert.c +
70.2%70.2%
+
70.2 %451 / 64292.6 %25 / 2759.0 %226 / 383
libspdm_crypt_rng.c +
75.0%75.0%
+
75.0 %3 / 4100.0 %1 / 150.0 %1 / 2
libspdm_crypt_hkdf.c +
17.4%17.4%
+
17.4 %8 / 46100.0 %2 / 212.5 %2 / 16
libspdm_crypt_aead.c +
45.2%45.2%
+
45.2 %28 / 62100.0 %5 / 539.1 %9 / 23
libspdm_crypt_dhe.c +
37.4%37.4%
+
37.4 %34 / 91100.0 %6 / 630.6 %11 / 36
libspdm_crypt_hash.c +
23.1%23.1%
+
23.1 %50 / 216100.0 %10 / 1018.8 %15 / 80
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/index-sort-l.html b/coverage_log/library/spdm_crypt_lib/index-sort-l.html new file mode 100644 index 00000000000..cdf22b576aa --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/index-sort-l.html @@ -0,0 +1,191 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_libHitTotalCoverage
Test:coverage.infoLines:892184448.4 %
Date:2024-09-22 08:21:07Functions:779481.9 %
Branches:41892945.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
libspdm_crypt_hmac.c +
2.4%2.4%
+
2.4 %4 / 16614.3 %1 / 71.7 %1 / 58
libspdm_crypt_hkdf.c +
17.4%17.4%
+
17.4 %8 / 46100.0 %2 / 212.5 %2 / 16
libspdm_crypt_hash.c +
23.1%23.1%
+
23.1 %50 / 216100.0 %10 / 1018.8 %15 / 80
libspdm_crypt_dhe.c +
37.4%37.4%
+
37.4 %34 / 91100.0 %6 / 630.6 %11 / 36
libspdm_crypt_aead.c +
45.2%45.2%
+
45.2 %28 / 62100.0 %5 / 539.1 %9 / 23
libspdm_crypt_asym.c +
50.9%50.9%
+
50.9 %314 / 61775.0 %27 / 3646.2 %153 / 331
libspdm_crypt_cert.c +
70.2%70.2%
+
70.2 %451 / 64292.6 %25 / 2759.0 %226 / 383
libspdm_crypt_rng.c +
75.0%75.0%
+
75.0 %3 / 4100.0 %1 / 150.0 %1 / 2
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/index.html b/coverage_log/library/spdm_crypt_lib/index.html new file mode 100644 index 00000000000..eecca243a53 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/index.html @@ -0,0 +1,191 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_libHitTotalCoverage
Test:coverage.infoLines:892184448.4 %
Date:2024-09-22 08:21:07Functions:779481.9 %
Branches:41892945.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
libspdm_crypt_aead.c +
45.2%45.2%
+
45.2 %28 / 62100.0 %5 / 539.1 %9 / 23
libspdm_crypt_asym.c +
50.9%50.9%
+
50.9 %314 / 61775.0 %27 / 3646.2 %153 / 331
libspdm_crypt_cert.c +
70.2%70.2%
+
70.2 %451 / 64292.6 %25 / 2759.0 %226 / 383
libspdm_crypt_dhe.c +
37.4%37.4%
+
37.4 %34 / 91100.0 %6 / 630.6 %11 / 36
libspdm_crypt_hash.c +
23.1%23.1%
+
23.1 %50 / 216100.0 %10 / 1018.8 %15 / 80
libspdm_crypt_hkdf.c +
17.4%17.4%
+
17.4 %8 / 46100.0 %2 / 212.5 %2 / 16
libspdm_crypt_hmac.c +
2.4%2.4%
+
2.4 %4 / 16614.3 %1 / 71.7 %1 / 58
libspdm_crypt_rng.c +
75.0%75.0%
+
75.0 %3 / 4100.0 %1 / 150.0 %1 / 2
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/libspdm_crypt_aead.c.func-sort-c.html b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_aead.c.func-sort-c.html new file mode 100644 index 00000000000..b8fefd757a5 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_aead.c.func-sort-c.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/libspdm_crypt_aead.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib - libspdm_crypt_aead.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:286245.2 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:92339.1 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_aead_decryption325
libspdm_aead_encryption464
libspdm_get_aead_iv_size670
libspdm_get_aead_tag_size670
libspdm_get_aead_key_size699
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/libspdm_crypt_aead.c.func.html b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_aead.c.func.html new file mode 100644 index 00000000000..33e043786d3 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_aead.c.func.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/libspdm_crypt_aead.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib - libspdm_crypt_aead.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:286245.2 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:92339.1 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_aead_decryption325
libspdm_aead_encryption464
libspdm_get_aead_iv_size670
libspdm_get_aead_key_size699
libspdm_get_aead_tag_size670
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/libspdm_crypt_aead.c.gcov.html b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_aead.c.gcov.html new file mode 100644 index 00000000000..3981ec5b246 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_aead.c.gcov.html @@ -0,0 +1,291 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/libspdm_crypt_aead.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib - libspdm_crypt_aead.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:286245.2 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:92339.1 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 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_crypt_lib.h"
+       8                 :            : 
+       9                 :        699 : uint32_t libspdm_get_aead_key_size(uint16_t aead_cipher_suite)
+      10                 :            : {
+      11   [ -  +  +  -  :        699 :     switch (aead_cipher_suite) {
+                      + ]
+      12                 :          0 :     case SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_128_GCM:
+      13                 :            : #if LIBSPDM_AEAD_AES_128_GCM_SUPPORT
+      14                 :          0 :         return 16;
+      15                 :            : #else
+      16                 :            :         return 0;
+      17                 :            : #endif
+      18                 :        516 :     case SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_256_GCM:
+      19                 :            : #if LIBSPDM_AEAD_AES_256_GCM_SUPPORT
+      20                 :        516 :         return 32;
+      21                 :            : #else
+      22                 :            :         return 0;
+      23                 :            : #endif
+      24                 :          1 :     case SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_CHACHA20_POLY1305:
+      25                 :            : #if LIBSPDM_AEAD_CHACHA20_POLY1305_SUPPORT
+      26                 :            :         return 32;
+      27                 :            : #else
+      28                 :          1 :         return 0;
+      29                 :            : #endif
+      30                 :          0 :     case SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AEAD_SM4_GCM:
+      31                 :            : #if LIBSPDM_AEAD_SM4_128_GCM_SUPPORT
+      32                 :            :         return 16;
+      33                 :            : #else
+      34                 :          0 :         return 0;
+      35                 :            : #endif
+      36                 :        182 :     default:
+      37                 :        182 :         return 0;
+      38                 :            :     }
+      39                 :            : }
+      40                 :            : 
+      41                 :        670 : uint32_t libspdm_get_aead_iv_size(uint16_t aead_cipher_suite)
+      42                 :            : {
+      43   [ -  +  -  -  :        670 :     switch (aead_cipher_suite) {
+                      + ]
+      44                 :          0 :     case SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_128_GCM:
+      45                 :            : #if LIBSPDM_AEAD_AES_128_GCM_SUPPORT
+      46                 :          0 :         return 12;
+      47                 :            : #else
+      48                 :            :         return 0;
+      49                 :            : #endif
+      50                 :        489 :     case SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_256_GCM:
+      51                 :            : #if LIBSPDM_AEAD_AES_256_GCM_SUPPORT
+      52                 :        489 :         return 12;
+      53                 :            : #else
+      54                 :            :         return 0;
+      55                 :            : #endif
+      56                 :          0 :     case SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_CHACHA20_POLY1305:
+      57                 :            : #if LIBSPDM_AEAD_CHACHA20_POLY1305_SUPPORT
+      58                 :            :         return 12;
+      59                 :            : #else
+      60                 :          0 :         return 0;
+      61                 :            : #endif
+      62                 :          0 :     case SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AEAD_SM4_GCM:
+      63                 :            : #if LIBSPDM_AEAD_SM4_128_GCM_SUPPORT
+      64                 :            :         return 12;
+      65                 :            : #else
+      66                 :          0 :         return 0;
+      67                 :            : #endif
+      68                 :        181 :     default:
+      69                 :        181 :         return 0;
+      70                 :            :     }
+      71                 :            : }
+      72                 :            : 
+      73                 :        670 : uint32_t libspdm_get_aead_tag_size(uint16_t aead_cipher_suite)
+      74                 :            : {
+      75   [ -  +  -  -  :        670 :     switch (aead_cipher_suite) {
+                      + ]
+      76                 :          0 :     case SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_128_GCM:
+      77                 :            : #if LIBSPDM_AEAD_AES_128_GCM_SUPPORT
+      78                 :          0 :         return 16;
+      79                 :            : #else
+      80                 :            :         return 0;
+      81                 :            : #endif
+      82                 :        489 :     case SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_256_GCM:
+      83                 :            : #if LIBSPDM_AEAD_AES_256_GCM_SUPPORT
+      84                 :        489 :         return 16;
+      85                 :            : #else
+      86                 :            :         return 0;
+      87                 :            : #endif
+      88                 :          0 :     case SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_CHACHA20_POLY1305:
+      89                 :            : #if LIBSPDM_AEAD_CHACHA20_POLY1305_SUPPORT
+      90                 :            :         return 16;
+      91                 :            : #else
+      92                 :          0 :         return 0;
+      93                 :            : #endif
+      94                 :          0 :     case SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AEAD_SM4_GCM:
+      95                 :            : #if LIBSPDM_AEAD_SM4_128_GCM_SUPPORT
+      96                 :            :         return 16;
+      97                 :            : #else
+      98                 :          0 :         return 0;
+      99                 :            : #endif
+     100                 :        181 :     default:
+     101                 :        181 :         return 0;
+     102                 :            :     }
+     103                 :            : }
+     104                 :            : 
+     105                 :        464 : bool libspdm_aead_encryption(const spdm_version_number_t secured_message_version,
+     106                 :            :                              uint16_t aead_cipher_suite, const uint8_t *key,
+     107                 :            :                              size_t key_size, const uint8_t *iv,
+     108                 :            :                              size_t iv_size, const uint8_t *a_data,
+     109                 :            :                              size_t a_data_size, const uint8_t *data_in,
+     110                 :            :                              size_t data_in_size, uint8_t *tag_out,
+     111                 :            :                              size_t tag_size, uint8_t *data_out,
+     112                 :            :                              size_t *data_out_size)
+     113                 :            : {
+     114   [ +  -  -  - ]:        464 :     switch (aead_cipher_suite) {
+     115                 :        464 :     case SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_128_GCM:
+     116                 :            :     case SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_256_GCM:
+     117                 :            : #if LIBSPDM_AEAD_GCM_SUPPORT
+     118                 :            : #if !LIBSPDM_AEAD_AES_128_GCM_SUPPORT
+     119                 :            :         LIBSPDM_ASSERT(aead_cipher_suite != SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_128_GCM);
+     120                 :            : #endif
+     121                 :            : #if !LIBSPDM_AEAD_AES_256_GCM_SUPPORT
+     122                 :            :         LIBSPDM_ASSERT(aead_cipher_suite != SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_256_GCM);
+     123                 :            : #endif
+     124                 :        464 :         return libspdm_aead_aes_gcm_encrypt(key, key_size, iv, iv_size, a_data,
+     125                 :            :                                             a_data_size, data_in, data_in_size, tag_out,
+     126                 :            :                                             tag_size, data_out, data_out_size);
+     127                 :            : #else
+     128                 :            :         LIBSPDM_ASSERT(false);
+     129                 :            :         return false;
+     130                 :            : #endif
+     131                 :          0 :     case SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_CHACHA20_POLY1305:
+     132                 :            : #if LIBSPDM_AEAD_CHACHA20_POLY1305_SUPPORT
+     133                 :            :         return libspdm_aead_chacha20_poly1305_encrypt(key, key_size, iv, iv_size, a_data,
+     134                 :            :                                                       a_data_size, data_in, data_in_size, tag_out,
+     135                 :            :                                                       tag_size, data_out, data_out_size);
+     136                 :            : #else
+     137                 :          0 :         LIBSPDM_ASSERT(false);
+     138                 :          0 :         return false;
+     139                 :            : #endif
+     140                 :          0 :     case SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AEAD_SM4_GCM:
+     141                 :            : #if LIBSPDM_AEAD_SM4_SUPPORT
+     142                 :            :         return libspdm_aead_sm4_gcm_encrypt(key, key_size, iv, iv_size, a_data,
+     143                 :            :                                             a_data_size, data_in, data_in_size, tag_out,
+     144                 :            :                                             tag_size, data_out, data_out_size);
+     145                 :            : #else
+     146                 :          0 :         LIBSPDM_ASSERT(false);
+     147                 :          0 :         return false;
+     148                 :            : #endif
+     149                 :          0 :     default:
+     150                 :          0 :         LIBSPDM_ASSERT(false);
+     151                 :          0 :         return false;
+     152                 :            :     }
+     153                 :            : }
+     154                 :            : 
+     155                 :        325 : bool libspdm_aead_decryption(const spdm_version_number_t secured_message_version,
+     156                 :            :                              uint16_t aead_cipher_suite, const uint8_t *key,
+     157                 :            :                              size_t key_size, const uint8_t *iv,
+     158                 :            :                              size_t iv_size, const uint8_t *a_data,
+     159                 :            :                              size_t a_data_size, const uint8_t *data_in,
+     160                 :            :                              size_t data_in_size, const uint8_t *tag,
+     161                 :            :                              size_t tag_size, uint8_t *data_out,
+     162                 :            :                              size_t *data_out_size)
+     163                 :            : {
+     164   [ +  -  -  - ]:        325 :     switch (aead_cipher_suite) {
+     165                 :        325 :     case SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_128_GCM:
+     166                 :            :     case SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_256_GCM:
+     167                 :            : #if LIBSPDM_AEAD_GCM_SUPPORT
+     168                 :            : #if !LIBSPDM_AEAD_AES_128_GCM_SUPPORT
+     169                 :            :         LIBSPDM_ASSERT(aead_cipher_suite != SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_128_GCM);
+     170                 :            : #endif
+     171                 :            : #if !LIBSPDM_AEAD_AES_256_GCM_SUPPORT
+     172                 :            :         LIBSPDM_ASSERT(aead_cipher_suite != SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_256_GCM);
+     173                 :            : #endif
+     174                 :        325 :         return libspdm_aead_aes_gcm_decrypt(key, key_size, iv, iv_size, a_data,
+     175                 :            :                                             a_data_size, data_in, data_in_size, tag,
+     176                 :            :                                             tag_size, data_out, data_out_size);
+     177                 :            : #else
+     178                 :            :         LIBSPDM_ASSERT(false);
+     179                 :            :         return false;
+     180                 :            : #endif
+     181                 :          0 :     case SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_CHACHA20_POLY1305:
+     182                 :            : #if LIBSPDM_AEAD_CHACHA20_POLY1305_SUPPORT
+     183                 :            :         return libspdm_aead_chacha20_poly1305_decrypt(key, key_size, iv, iv_size, a_data,
+     184                 :            :                                                       a_data_size, data_in, data_in_size, tag,
+     185                 :            :                                                       tag_size, data_out, data_out_size);
+     186                 :            : #else
+     187                 :          0 :         LIBSPDM_ASSERT(false);
+     188                 :          0 :         return false;
+     189                 :            : #endif
+     190                 :          0 :     case SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AEAD_SM4_GCM:
+     191                 :            : #if LIBSPDM_AEAD_SM4_SUPPORT
+     192                 :            :         return libspdm_aead_sm4_gcm_decrypt(key, key_size, iv, iv_size, a_data,
+     193                 :            :                                             a_data_size, data_in, data_in_size, tag,
+     194                 :            :                                             tag_size, data_out, data_out_size);
+     195                 :            : #else
+     196                 :          0 :         LIBSPDM_ASSERT(false);
+     197                 :          0 :         return false;
+     198                 :            : #endif
+     199                 :          0 :     default:
+     200                 :          0 :         LIBSPDM_ASSERT(false);
+     201                 :          0 :         return false;
+     202                 :            :     }
+     203                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/libspdm_crypt_asym.c.func-sort-c.html b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_asym.c.func-sort-c.html new file mode 100644 index 00000000000..58afe426417 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_asym.c.func-sort-c.html @@ -0,0 +1,225 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/libspdm_crypt_asym.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib - libspdm_crypt_asym.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:31461750.9 %
Date:2024-09-22 08:21:07Functions:273675.0 %
Branches:15333146.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_asym_verify0
libspdm_asym_verify_ex0
libspdm_asym_verify_hash0
libspdm_get_signing_context_string0
libspdm_req_asym_verify0
libspdm_req_asym_verify_ex0
libspdm_req_asym_verify_hash0
libspdm_rsa_pss_sign_wrap0
libspdm_rsa_pss_verify_wrap0
libspdm_req_asym_get_public_key_from_der2
libspdm_asym_get_public_key_from_der3
libspdm_asym_get_public_key_from_der_wrap5
libspdm_req_asym_sign_hash9
libspdm_copy_signature_swap_endian_ecdsa10
libspdm_copy_signature_swap_endian_rsa10
libspdm_req_asym_sign16
libspdm_copy_signature_swap_endian20
libspdm_req_asym_verify_hash_ex20
libspdm_rsa_pkcs1_verify_with_nid_wrap21
libspdm_rsa_pkcs1_sign_with_nid_wrap25
libspdm_req_asym_free26
libspdm_create_signing_context31
libspdm_asym_sign_hash36
libspdm_req_asym_func_need_hash45
libspdm_is_signature_buffer_palindrome52
libspdm_asym_verify_hash_ex67
libspdm_ecdsa_verify_wrap69
libspdm_is_palindrome69
libspdm_get_req_asym_signature_size74
libspdm_asym_sign87
libspdm_asym_verify_wrap90
libspdm_ecdsa_sign_wrap123
libspdm_asym_sign_wrap148
libspdm_asym_func_need_hash235
libspdm_get_asym_signature_size492
libspdm_asym_free888
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/libspdm_crypt_asym.c.func.html b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_asym.c.func.html new file mode 100644 index 00000000000..34d727682b2 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_asym.c.func.html @@ -0,0 +1,225 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/libspdm_crypt_asym.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib - libspdm_crypt_asym.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:31461750.9 %
Date:2024-09-22 08:21:07Functions:273675.0 %
Branches:15333146.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_asym_free888
libspdm_asym_func_need_hash235
libspdm_asym_get_public_key_from_der3
libspdm_asym_get_public_key_from_der_wrap5
libspdm_asym_sign87
libspdm_asym_sign_hash36
libspdm_asym_sign_wrap148
libspdm_asym_verify0
libspdm_asym_verify_ex0
libspdm_asym_verify_hash0
libspdm_asym_verify_hash_ex67
libspdm_asym_verify_wrap90
libspdm_copy_signature_swap_endian20
libspdm_copy_signature_swap_endian_ecdsa10
libspdm_copy_signature_swap_endian_rsa10
libspdm_create_signing_context31
libspdm_ecdsa_sign_wrap123
libspdm_ecdsa_verify_wrap69
libspdm_get_asym_signature_size492
libspdm_get_req_asym_signature_size74
libspdm_get_signing_context_string0
libspdm_is_palindrome69
libspdm_is_signature_buffer_palindrome52
libspdm_req_asym_free26
libspdm_req_asym_func_need_hash45
libspdm_req_asym_get_public_key_from_der2
libspdm_req_asym_sign16
libspdm_req_asym_sign_hash9
libspdm_req_asym_verify0
libspdm_req_asym_verify_ex0
libspdm_req_asym_verify_hash0
libspdm_req_asym_verify_hash_ex20
libspdm_rsa_pkcs1_sign_with_nid_wrap25
libspdm_rsa_pkcs1_verify_with_nid_wrap21
libspdm_rsa_pss_sign_wrap0
libspdm_rsa_pss_verify_wrap0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/libspdm_crypt_asym.c.gcov.html b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_asym.c.gcov.html new file mode 100644 index 00000000000..383687f7cae --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_asym.c.gcov.html @@ -0,0 +1,1942 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/libspdm_crypt_asym.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib - libspdm_crypt_asym.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:31461750.9 %
Date:2024-09-22 08:21:07Functions:273675.0 %
Branches:15333146.2 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 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_crypt_lib.h"
+       8                 :            : #include "library/spdm_common_lib.h"
+       9                 :            : 
+      10                 :            : typedef struct {
+      11                 :            :     bool is_requester;
+      12                 :            :     uint8_t op_code;
+      13                 :            :     const void *context;
+      14                 :            :     size_t context_size;
+      15                 :            :     size_t zero_pad_size;
+      16                 :            : } libspdm_signing_context_str_t;
+      17                 :            : 
+      18                 :            : static const libspdm_signing_context_str_t m_libspdm_signing_context_str_table[] = {
+      19                 :            :     {false, SPDM_CHALLENGE_AUTH, SPDM_CHALLENGE_AUTH_SIGN_CONTEXT,
+      20                 :            :      SPDM_CHALLENGE_AUTH_SIGN_CONTEXT_SIZE, 36 - SPDM_CHALLENGE_AUTH_SIGN_CONTEXT_SIZE},
+      21                 :            :     {true, SPDM_CHALLENGE_AUTH, SPDM_MUT_CHALLENGE_AUTH_SIGN_CONTEXT,
+      22                 :            :      SPDM_MUT_CHALLENGE_AUTH_SIGN_CONTEXT_SIZE, 36 - SPDM_MUT_CHALLENGE_AUTH_SIGN_CONTEXT_SIZE},
+      23                 :            :     {false, SPDM_MEASUREMENTS, SPDM_MEASUREMENTS_SIGN_CONTEXT, SPDM_MEASUREMENTS_SIGN_CONTEXT_SIZE,
+      24                 :            :      36 - SPDM_MEASUREMENTS_SIGN_CONTEXT_SIZE},
+      25                 :            :     {false, SPDM_KEY_EXCHANGE_RSP, SPDM_KEY_EXCHANGE_RESPONSE_SIGN_CONTEXT,
+      26                 :            :      SPDM_KEY_EXCHANGE_RESPONSE_SIGN_CONTEXT_SIZE,
+      27                 :            :      36 - SPDM_KEY_EXCHANGE_RESPONSE_SIGN_CONTEXT_SIZE},
+      28                 :            :     {true, SPDM_FINISH, SPDM_FINISH_SIGN_CONTEXT, SPDM_FINISH_SIGN_CONTEXT_SIZE,
+      29                 :            :      36 - SPDM_FINISH_SIGN_CONTEXT_SIZE},
+      30                 :            : };
+      31                 :            : 
+      32                 :            : #if LIBSPDM_RSA_SSA_SUPPORT
+      33                 :         25 : static bool libspdm_rsa_pkcs1_sign_with_nid_wrap (void *context, size_t hash_nid,
+      34                 :            :                                                   const uint8_t *param, size_t param_size,
+      35                 :            :                                                   const uint8_t *message,
+      36                 :            :                                                   size_t message_size, uint8_t *signature,
+      37                 :            :                                                   size_t *sig_size)
+      38                 :            : {
+      39                 :         25 :     return libspdm_rsa_pkcs1_sign_with_nid (context, hash_nid,
+      40                 :            :                                             message, message_size, signature, sig_size);
+      41                 :            : }
+      42                 :            : #endif
+      43                 :            : 
+      44                 :            : #if LIBSPDM_RSA_PSS_SUPPORT
+      45                 :          0 : static bool libspdm_rsa_pss_sign_wrap (void *context, size_t hash_nid,
+      46                 :            :                                        const uint8_t *param, size_t param_size,
+      47                 :            :                                        const uint8_t *message,
+      48                 :            :                                        size_t message_size, uint8_t *signature,
+      49                 :            :                                        size_t *sig_size)
+      50                 :            : {
+      51                 :          0 :     return libspdm_rsa_pss_sign (context, hash_nid,
+      52                 :            :                                  message, message_size, signature, sig_size);
+      53                 :            : }
+      54                 :            : #endif
+      55                 :            : 
+      56                 :            : #if LIBSPDM_ECDSA_SUPPORT
+      57                 :        123 : static bool libspdm_ecdsa_sign_wrap (void *context, size_t hash_nid,
+      58                 :            :                                      const uint8_t *param, size_t param_size,
+      59                 :            :                                      const uint8_t *message,
+      60                 :            :                                      size_t message_size, uint8_t *signature,
+      61                 :            :                                      size_t *sig_size)
+      62                 :            : {
+      63                 :        123 :     return libspdm_ecdsa_sign (context, hash_nid,
+      64                 :            :                                message, message_size, signature, sig_size);
+      65                 :            : }
+      66                 :            : #endif
+      67                 :            : 
+      68                 :            : #if (LIBSPDM_EDDSA_ED25519_SUPPORT) || (LIBSPDM_EDDSA_ED448_SUPPORT)
+      69                 :            : static bool libspdm_eddsa_sign_wrap (void *context, size_t hash_nid,
+      70                 :            :                                      const uint8_t *param, size_t param_size,
+      71                 :            :                                      const uint8_t *message,
+      72                 :            :                                      size_t message_size, uint8_t *signature,
+      73                 :            :                                      size_t *sig_size)
+      74                 :            : {
+      75                 :            :     return libspdm_eddsa_sign (context, hash_nid, param, param_size,
+      76                 :            :                                message, message_size, signature, sig_size);
+      77                 :            : }
+      78                 :            : #endif
+      79                 :            : 
+      80                 :            : #if LIBSPDM_SM2_DSA_SUPPORT
+      81                 :            : static bool libspdm_sm2_dsa_sign_wrap (void *context, size_t hash_nid,
+      82                 :            :                                        const uint8_t *param, size_t param_size,
+      83                 :            :                                        const uint8_t *message,
+      84                 :            :                                        size_t message_size, uint8_t *signature,
+      85                 :            :                                        size_t *sig_size)
+      86                 :            : {
+      87                 :            :     return libspdm_sm2_dsa_sign (context, hash_nid, param, param_size,
+      88                 :            :                                  message, message_size, signature, sig_size);
+      89                 :            : }
+      90                 :            : #endif
+      91                 :            : 
+      92                 :            : /**
+      93                 :            :  * Get the SPDM signing context string, which is required since SPDM 1.2.
+      94                 :            :  *
+      95                 :            :  * @param  spdm_version                         negotiated SPDM version
+      96                 :            :  * @param  op_code                              the SPDM opcode which requires the signing
+      97                 :            :  * @param  is_requester                         indicate if the signing is from a requester
+      98                 :            :  * @param  context_size                         SPDM signing context size
+      99                 :            :  **/
+     100                 :          0 : static const void *libspdm_get_signing_context_string (
+     101                 :            :     spdm_version_number_t spdm_version,
+     102                 :            :     uint8_t op_code,
+     103                 :            :     bool is_requester,
+     104                 :            :     size_t *context_size)
+     105                 :            : {
+     106                 :            :     size_t index;
+     107                 :            : 
+     108                 :            :     /* It is introduced in SPDM 1.2*/
+     109         [ #  # ]:          0 :     LIBSPDM_ASSERT((spdm_version >> SPDM_VERSION_NUMBER_SHIFT_BIT) > SPDM_MESSAGE_VERSION_11);
+     110                 :            : 
+     111         [ #  # ]:          0 :     for (index = 0; index < LIBSPDM_ARRAY_SIZE(m_libspdm_signing_context_str_table); index++) {
+     112         [ #  # ]:          0 :         if (m_libspdm_signing_context_str_table[index].is_requester == is_requester &&
+     113         [ #  # ]:          0 :             m_libspdm_signing_context_str_table[index].op_code == op_code) {
+     114                 :          0 :             *context_size = m_libspdm_signing_context_str_table[index].context_size;
+     115                 :          0 :             return m_libspdm_signing_context_str_table[index].context;
+     116                 :            :         }
+     117                 :            :     }
+     118                 :          0 :     LIBSPDM_ASSERT(false);
+     119                 :          0 :     return NULL;
+     120                 :            : }
+     121                 :            : 
+     122                 :            : /**
+     123                 :            :  * Create SPDM signing context, which is required since SPDM 1.2.
+     124                 :            :  *
+     125                 :            :  * @param  spdm_version                         negotiated SPDM version
+     126                 :            :  * @param  op_code                              the SPDM opcode which requires the signing
+     127                 :            :  * @param  is_requester                         indicate if the signing is from a requester
+     128                 :            :  * @param  spdm_signing_context                 SPDM signing context
+     129                 :            :  **/
+     130                 :         31 : static void libspdm_create_signing_context (
+     131                 :            :     spdm_version_number_t spdm_version,
+     132                 :            :     uint8_t op_code,
+     133                 :            :     bool is_requester,
+     134                 :            :     void *spdm_signing_context)
+     135                 :            : {
+     136                 :            :     size_t index;
+     137                 :            :     char *context_str;
+     138                 :            : 
+     139                 :            :     /* It is introduced in SPDM 1.2*/
+     140         [ -  + ]:         31 :     LIBSPDM_ASSERT((spdm_version >> SPDM_VERSION_NUMBER_SHIFT_BIT) > SPDM_MESSAGE_VERSION_11);
+     141                 :            : 
+     142                 :            :     /* So far, it only leaves 1 bytes for version*/
+     143   [ +  -  -  + ]:         31 :     LIBSPDM_ASSERT((((spdm_version >> 12) & 0xF) < 10) &&
+     144                 :            :                    (((spdm_version >> 8) & 0xF) < 10));
+     145                 :            : 
+     146                 :         31 :     context_str = spdm_signing_context;
+     147         [ +  + ]:        155 :     for (index = 0; index < 4; index++) {
+     148                 :        124 :         libspdm_copy_mem(context_str,
+     149                 :            :                          SPDM_VERSION_1_2_SIGNING_PREFIX_CONTEXT_SIZE,
+     150                 :            :                          SPDM_VERSION_1_2_SIGNING_PREFIX_CONTEXT,
+     151                 :            :                          SPDM_VERSION_1_2_SIGNING_PREFIX_CONTEXT_SIZE);
+     152                 :            :         /* patch the version*/
+     153                 :        124 :         context_str[11] = (char)('0' + ((spdm_version >> 12) & 0xF));
+     154                 :        124 :         context_str[13] = (char)('0' + ((spdm_version >> 8) & 0xF));
+     155                 :        124 :         context_str[15] = (char)('*');
+     156                 :        124 :         context_str += SPDM_VERSION_1_2_SIGNING_PREFIX_CONTEXT_SIZE;
+     157                 :            :     }
+     158         [ +  - ]:         82 :     for (index = 0; index < LIBSPDM_ARRAY_SIZE(m_libspdm_signing_context_str_table); index++) {
+     159         [ +  + ]:         82 :         if (m_libspdm_signing_context_str_table[index].is_requester == is_requester &&
+     160         [ +  + ]:         59 :             m_libspdm_signing_context_str_table[index].op_code == op_code) {
+     161                 :         31 :             libspdm_zero_mem (
+     162                 :            :                 context_str,
+     163                 :         31 :                 m_libspdm_signing_context_str_table[index].zero_pad_size);
+     164                 :         31 :             libspdm_copy_mem(context_str + m_libspdm_signing_context_str_table[index].zero_pad_size,
+     165                 :         31 :                              m_libspdm_signing_context_str_table[index].context_size,
+     166                 :         31 :                              m_libspdm_signing_context_str_table[index].context,
+     167                 :         31 :                              m_libspdm_signing_context_str_table[index].context_size);
+     168                 :         31 :             return;
+     169                 :            :         }
+     170                 :            :     }
+     171                 :          0 :     LIBSPDM_ASSERT(false);
+     172                 :            : }
+     173                 :            : 
+     174                 :        492 : uint32_t libspdm_get_asym_signature_size(uint32_t base_asym_algo)
+     175                 :            : {
+     176   [ +  -  -  +  :        492 :     switch (base_asym_algo) {
+          -  -  +  -  +  
+             -  -  -  + ]
+     177                 :         78 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
+     178                 :            : #if LIBSPDM_RSA_SSA_2048_SUPPORT
+     179                 :         78 :         return 256;
+     180                 :            : #else
+     181                 :            :         return 0;
+     182                 :            : #endif
+     183                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048:
+     184                 :            : #if LIBSPDM_RSA_PSS_2048_SUPPORT
+     185                 :          0 :         return 256;
+     186                 :            : #else
+     187                 :            :         return 0;
+     188                 :            : #endif
+     189                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
+     190                 :            : #if LIBSPDM_RSA_SSA_3072_SUPPORT
+     191                 :          0 :         return 384;
+     192                 :            : #else
+     193                 :            :         return 0;
+     194                 :            : #endif
+     195                 :          1 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072:
+     196                 :            : #if LIBSPDM_RSA_PSS_3072_SUPPORT
+     197                 :          1 :         return 384;
+     198                 :            : #else
+     199                 :            :         return 0;
+     200                 :            : #endif
+     201                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
+     202                 :            : #if LIBSPDM_RSA_SSA_4096_SUPPORT
+     203                 :          0 :         return 512;
+     204                 :            : #else
+     205                 :            :         return 0;
+     206                 :            : #endif
+     207                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096:
+     208                 :            : #if LIBSPDM_RSA_PSS_4096_SUPPORT
+     209                 :          0 :         return 512;
+     210                 :            : #else
+     211                 :            :         return 0;
+     212                 :            : #endif
+     213                 :        408 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
+     214                 :            : #if LIBSPDM_ECDSA_P256_SUPPORT
+     215                 :        408 :         return 32 * 2;
+     216                 :            : #else
+     217                 :            :         return 0;
+     218                 :            : #endif
+     219                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
+     220                 :            : #if LIBSPDM_ECDSA_P384_SUPPORT
+     221                 :          0 :         return 48 * 2;
+     222                 :            : #else
+     223                 :            :         return 0;
+     224                 :            : #endif
+     225                 :          2 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
+     226                 :            : #if LIBSPDM_ECDSA_P521_SUPPORT
+     227                 :          2 :         return 66 * 2;
+     228                 :            : #else
+     229                 :            :         return 0;
+     230                 :            : #endif
+     231                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256:
+     232                 :            : #if LIBSPDM_SM2_DSA_P256_SUPPORT
+     233                 :            :         return 32 * 2;
+     234                 :            : #else
+     235                 :          0 :         return 0;
+     236                 :            : #endif
+     237                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
+     238                 :            : #if LIBSPDM_EDDSA_ED25519_SUPPORT
+     239                 :            :         return 32 * 2;
+     240                 :            : #else
+     241                 :          0 :         return 0;
+     242                 :            : #endif
+     243                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
+     244                 :            : #if LIBSPDM_EDDSA_ED448_SUPPORT
+     245                 :            :         return 57 * 2;
+     246                 :            : #else
+     247                 :          0 :         return 0;
+     248                 :            : #endif
+     249                 :          3 :     default:
+     250                 :          3 :         return 0;
+     251                 :            :     }
+     252                 :            : }
+     253                 :            : 
+     254                 :        148 : static bool libspdm_asym_sign_wrap (void *context, size_t hash_nid, uint32_t base_asym_algo,
+     255                 :            :                                     const uint8_t *param, size_t param_size,
+     256                 :            :                                     const uint8_t *message, size_t message_size,
+     257                 :            :                                     uint8_t *signature, size_t *sig_size)
+     258                 :            : {
+     259   [ +  -  +  -  :        148 :     switch (base_asym_algo) {
+                   -  - ]
+     260                 :         25 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
+     261                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
+     262                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
+     263                 :            : #if LIBSPDM_RSA_SSA_SUPPORT
+     264                 :            : #if !LIBSPDM_RSA_SSA_2048_SUPPORT
+     265                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048);
+     266                 :            : #endif
+     267                 :            : #if !LIBSPDM_RSA_SSA_3072_SUPPORT
+     268                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072);
+     269                 :            : #endif
+     270                 :            : #if !LIBSPDM_RSA_SSA_4096_SUPPORT
+     271                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096);
+     272                 :            : #endif
+     273                 :         25 :         return libspdm_rsa_pkcs1_sign_with_nid_wrap(context, hash_nid,
+     274                 :            :                                                     param, param_size,
+     275                 :            :                                                     message, message_size,
+     276                 :            :                                                     signature, sig_size);
+     277                 :            : #else
+     278                 :            :         LIBSPDM_ASSERT(false);
+     279                 :            :         return false;
+     280                 :            : #endif
+     281                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048:
+     282                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072:
+     283                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096:
+     284                 :            : #if LIBSPDM_RSA_PSS_SUPPORT
+     285                 :            : #if !LIBSPDM_RSA_PSS_2048_SUPPORT
+     286                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048);
+     287                 :            : #endif
+     288                 :            : #if !LIBSPDM_RSA_PSS_3072_SUPPORT
+     289                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072);
+     290                 :            : #endif
+     291                 :            : #if !LIBSPDM_RSA_PSS_4096_SUPPORT
+     292                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096);
+     293                 :            : #endif
+     294                 :          0 :         return libspdm_rsa_pss_sign_wrap(context, hash_nid,
+     295                 :            :                                          param, param_size,
+     296                 :            :                                          message, message_size,
+     297                 :            :                                          signature, sig_size);
+     298                 :            : #else
+     299                 :            :         LIBSPDM_ASSERT(false);
+     300                 :            :         return false;
+     301                 :            : #endif
+     302                 :        123 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
+     303                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
+     304                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
+     305                 :            : #if LIBSPDM_ECDSA_SUPPORT
+     306                 :            : #if !LIBSPDM_ECDSA_P256_SUPPORT
+     307                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256);
+     308                 :            : #endif
+     309                 :            : #if !LIBSPDM_ECDSA_P384_SUPPORT
+     310                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384);
+     311                 :            : #endif
+     312                 :            : #if !LIBSPDM_ECDSA_P521_SUPPORT
+     313                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521);
+     314                 :            : #endif
+     315                 :        123 :         return libspdm_ecdsa_sign_wrap(context, hash_nid,
+     316                 :            :                                        param, param_size,
+     317                 :            :                                        message, message_size,
+     318                 :            :                                        signature, sig_size);
+     319                 :            : #else
+     320                 :            :         LIBSPDM_ASSERT(false);
+     321                 :            :         return false;
+     322                 :            : #endif
+     323                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
+     324                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
+     325                 :            : #if (LIBSPDM_EDDSA_ED25519_SUPPORT) || (LIBSPDM_EDDSA_ED448_SUPPORT)
+     326                 :            : #if !LIBSPDM_EDDSA_ED25519_SUPPORT
+     327                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519);
+     328                 :            : #endif
+     329                 :            : #if !LIBSPDM_EDDSA_ED448_SUPPORT
+     330                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448);
+     331                 :            : #endif
+     332                 :            :         return libspdm_eddsa_sign_wrap(context, hash_nid,
+     333                 :            :                                        param, param_size,
+     334                 :            :                                        message, message_size,
+     335                 :            :                                        signature, sig_size);
+     336                 :            : #else
+     337                 :          0 :         LIBSPDM_ASSERT(false);
+     338                 :          0 :         return false;
+     339                 :            : #endif
+     340                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256:
+     341                 :            : #if LIBSPDM_SM2_DSA_SUPPORT
+     342                 :            :         return libspdm_sm2_dsa_sign_wrap(context, hash_nid,
+     343                 :            :                                          param, param_size,
+     344                 :            :                                          message, message_size,
+     345                 :            :                                          signature, sig_size);
+     346                 :            : #else
+     347                 :          0 :         LIBSPDM_ASSERT(false);
+     348                 :          0 :         return false;
+     349                 :            : #endif
+     350                 :          0 :     default:
+     351                 :          0 :         LIBSPDM_ASSERT(false);
+     352                 :          0 :         return false;
+     353                 :            :     }
+     354                 :            : }
+     355                 :            : 
+     356                 :        888 : void libspdm_asym_free(uint32_t base_asym_algo, void *context)
+     357                 :            : {
+     358         [ +  + ]:        888 :     if (context == NULL) {
+     359                 :          2 :         return;
+     360                 :            :     }
+     361   [ +  +  -  -  :        886 :     switch (base_asym_algo) {
+                      - ]
+     362                 :         76 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
+     363                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
+     364                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
+     365                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048:
+     366                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072:
+     367                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096:
+     368                 :            : #if (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT)
+     369                 :         76 :         libspdm_rsa_free(context);
+     370                 :            : #else
+     371                 :            :         LIBSPDM_ASSERT(false);
+     372                 :            : #endif
+     373                 :         76 :         break;
+     374                 :        810 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
+     375                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
+     376                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
+     377                 :            : #if LIBSPDM_ECDSA_SUPPORT
+     378                 :        810 :         libspdm_ec_free(context);
+     379                 :            : #else
+     380                 :            :         LIBSPDM_ASSERT(false);
+     381                 :            : #endif
+     382                 :        810 :         break;
+     383                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
+     384                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
+     385                 :            : #if (LIBSPDM_EDDSA_ED25519_SUPPORT) || (LIBSPDM_EDDSA_ED448_SUPPORT)
+     386                 :            :         libspdm_ecd_free(context);
+     387                 :            : #else
+     388                 :          0 :         LIBSPDM_ASSERT(false);
+     389                 :            : #endif
+     390                 :          0 :         break;
+     391                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256:
+     392                 :            : #if LIBSPDM_SM2_DSA_SUPPORT
+     393                 :            :         libspdm_sm2_dsa_free(context);
+     394                 :            : #else
+     395                 :          0 :         LIBSPDM_ASSERT(false);
+     396                 :            : #endif
+     397                 :          0 :         break;
+     398                 :          0 :     default:
+     399                 :          0 :         LIBSPDM_ASSERT(false);
+     400                 :          0 :         break;
+     401                 :            :     }
+     402                 :            : }
+     403                 :            : 
+     404                 :          5 : static bool libspdm_asym_get_public_key_from_der_wrap(uint32_t base_asym_algo,
+     405                 :            :                                                       const uint8_t *der_data,
+     406                 :            :                                                       size_t der_size,
+     407                 :            :                                                       void **context)
+     408                 :            : {
+     409   [ +  +  -  -  :          5 :     switch (base_asym_algo) {
+                      - ]
+     410                 :          2 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
+     411                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
+     412                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
+     413                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048:
+     414                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072:
+     415                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096:
+     416                 :            : #if (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT)
+     417                 :            : #if !LIBSPDM_RSA_SSA_2048_SUPPORT
+     418                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048);
+     419                 :            : #endif
+     420                 :            : #if !LIBSPDM_RSA_SSA_3072_SUPPORT
+     421                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072);
+     422                 :            : #endif
+     423                 :            : #if !LIBSPDM_RSA_SSA_4096_SUPPORT
+     424                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096);
+     425                 :            : #endif
+     426                 :            : #if !LIBSPDM_RSA_PSS_2048_SUPPORT
+     427                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048);
+     428                 :            : #endif
+     429                 :            : #if !LIBSPDM_RSA_PSS_3072_SUPPORT
+     430                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072);
+     431                 :            : #endif
+     432                 :            : #if !LIBSPDM_RSA_PSS_4096_SUPPORT
+     433                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096);
+     434                 :            : #endif
+     435                 :          2 :         return libspdm_rsa_get_public_key_from_der(der_data, der_size, context);
+     436                 :            : #else
+     437                 :            :         LIBSPDM_ASSERT(false);
+     438                 :            :         return false;
+     439                 :            : #endif
+     440                 :          3 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
+     441                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
+     442                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
+     443                 :            : #if LIBSPDM_ECDSA_SUPPORT
+     444                 :            : #if !LIBSPDM_ECDSA_P256_SUPPORT
+     445                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256);
+     446                 :            : #endif
+     447                 :            : #if !LIBSPDM_ECDSA_P384_SUPPORT
+     448                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384);
+     449                 :            : #endif
+     450                 :            : #if !LIBSPDM_ECDSA_P521_SUPPORT
+     451                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521);
+     452                 :            : #endif
+     453                 :          3 :         return libspdm_ec_get_public_key_from_der(der_data, der_size, context);
+     454                 :            : #else
+     455                 :            :         LIBSPDM_ASSERT(false);
+     456                 :            :         return false;
+     457                 :            : #endif
+     458                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
+     459                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
+     460                 :            : #if (LIBSPDM_EDDSA_ED25519_SUPPORT) || (LIBSPDM_EDDSA_ED448_SUPPORT)
+     461                 :            :         return libspdm_ecd_get_public_key_from_der(der_data, der_size, context);
+     462                 :            : #else
+     463                 :          0 :         LIBSPDM_ASSERT(false);
+     464                 :          0 :         return false;
+     465                 :            : #endif
+     466                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256:
+     467                 :            : #if LIBSPDM_SM2_DSA_SUPPORT
+     468                 :            : #if !LIBSPDM_EDDSA_ED25519_SUPPORT
+     469                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519);
+     470                 :            : #endif
+     471                 :            : #if !LIBSPDM_EDDSA_ED448_SUPPORT
+     472                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448);
+     473                 :            : #endif
+     474                 :            :         return libspdm_sm2_get_public_key_from_der(der_data, der_size, context);
+     475                 :            : #else
+     476                 :          0 :         LIBSPDM_ASSERT(false);
+     477                 :          0 :         return false;
+     478                 :            : #endif
+     479                 :          0 :     default:
+     480                 :          0 :         LIBSPDM_ASSERT(false);
+     481                 :          0 :         return false;
+     482                 :            :     }
+     483                 :            : }
+     484                 :            : 
+     485                 :          3 : bool libspdm_asym_get_public_key_from_der(uint32_t base_asym_algo,
+     486                 :            :                                           const uint8_t *der_data,
+     487                 :            :                                           size_t der_size,
+     488                 :            :                                           void **context)
+     489                 :            : {
+     490                 :          3 :     return libspdm_asym_get_public_key_from_der_wrap(base_asym_algo,
+     491                 :            :                                                      der_data,
+     492                 :            :                                                      der_size,
+     493                 :            :                                                      context);
+     494                 :            : }
+     495                 :            : 
+     496                 :            : /**
+     497                 :            :  * Return if asymmetric function need message hash.
+     498                 :            :  *
+     499                 :            :  * @param  base_asym_algo               SPDM base_asym_algo
+     500                 :            :  *
+     501                 :            :  * @retval true  asymmetric function need message hash
+     502                 :            :  * @retval false asymmetric function need raw message
+     503                 :            :  **/
+     504                 :        235 : static bool libspdm_asym_func_need_hash(uint32_t base_asym_algo)
+     505                 :            : {
+     506   [ +  +  -  - ]:        235 :     switch (base_asym_algo) {
+     507                 :         45 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
+     508                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
+     509                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
+     510                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048:
+     511                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072:
+     512                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096:
+     513                 :         45 :         return true;
+     514                 :        190 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
+     515                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
+     516                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
+     517                 :        190 :         return true;
+     518                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
+     519                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
+     520                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256:
+     521                 :          0 :         return false;
+     522                 :          0 :     default:
+     523                 :          0 :         LIBSPDM_ASSERT(false);
+     524                 :          0 :         break;
+     525                 :            :     }
+     526                 :            : 
+     527                 :          0 :     return false;
+     528                 :            : }
+     529                 :            : 
+     530                 :            : /**
+     531                 :            :  * libspdm_copy_signature_swap_endian_rsa
+     532                 :            :  * Swaps the endianness of a RSA signature buffer. The ECDSA signature buffer is
+     533                 :            :  * actually single internal buffer and can be swapped as a single whole buffer.
+     534                 :            :  *
+     535                 :            :  * There are two known usage models for buffers for this function.
+     536                 :            :  * 1) Source and dest are the same (and their sizes).  This would be an in-place swap.
+     537                 :            :  * 2) Source and dest are completely different (and dest size >= src size). No overlap.
+     538                 :            :  *
+     539                 :            :  * The case where source and dest are overlapped (and not the exact same buffer)
+     540                 :            :  * is not allowed and guarded against with an assert.
+     541                 :            :  **/
+     542                 :         10 : static void libspdm_copy_signature_swap_endian_rsa(
+     543                 :            :     uint8_t* dst,
+     544                 :            :     size_t dst_size,
+     545                 :            :     const uint8_t* src,
+     546                 :            :     size_t src_size)
+     547                 :            : {
+     548                 :            :     /* RSA signature is a single buffer to be swapped */
+     549                 :            :     size_t i;
+     550                 :            : 
+     551         [ +  + ]:         10 :     if (src == dst) {
+     552         [ -  + ]:          4 :         LIBSPDM_ASSERT(dst_size == src_size);
+     553                 :            : 
+     554                 :            :         /* src and dst are same buffer. Swap in place. */
+     555                 :            : 
+     556                 :            :         uint8_t byte;
+     557         [ +  + ]:        516 :         for (i = 0; i < dst_size / 2; i++) {
+     558                 :        512 :             byte = dst[i];
+     559                 :        512 :             dst[i] = dst[dst_size - i - 1];
+     560                 :        512 :             dst[dst_size - i - 1] = byte;
+     561                 :            :         }
+     562                 :            :     } else {
+     563                 :            :         /* src and dst are different buffers.
+     564                 :            :          * Guard against overlap case with assert.
+     565                 :            :          * Overlap case is not an expected usage model. */
+     566         [ -  + ]:          6 :         LIBSPDM_ASSERT(dst_size >= src_size);
+     567   [ +  +  -  +  :          6 :         LIBSPDM_ASSERT((src < dst && src + src_size <= dst) ||
+             +  -  -  + ]
+     568                 :            :                        (dst < src && dst + dst_size <= src));
+     569                 :            : 
+     570         [ +  + ]:       1542 :         for (i = 0; i < src_size; i++) {
+     571                 :       1536 :             dst[i] = src[src_size - i - 1];
+     572                 :            :         }
+     573                 :            :     }
+     574                 :         10 : }
+     575                 :            : 
+     576                 :            : /**
+     577                 :            :  * libspdm_copy_signature_swap_endian_ecdsa
+     578                 :            :  * Swaps the endianness of a ECDSA signature buffer. The ECDSA signature buffer is
+     579                 :            :  * actually two internal buffers, and each internal buffer must be swapped individually.
+     580                 :            :  *
+     581                 :            :  * There are two known usage models for buffers for this function.
+     582                 :            :  * 1) Source and dest are the same (and their sizes).  This would be an in-place swap.
+     583                 :            :  * 2) Source and dest are completely different (and dest size >= src size). No overlap.
+     584                 :            :  *
+     585                 :            :  * The case where source and dest are overlapped (and not the exact same buffer)
+     586                 :            :  * is not allowed and guarded against with an assert.
+     587                 :            :  **/
+     588                 :         10 : static void libspdm_copy_signature_swap_endian_ecdsa(
+     589                 :            :     uint8_t* dst,
+     590                 :            :     size_t dst_size,
+     591                 :            :     const uint8_t* src,
+     592                 :            :     size_t src_size)
+     593                 :            : {
+     594                 :            :     /* ECDSA signature is actually 2 buffers (x & y)
+     595                 :            :      * and each must be swapped individually */
+     596                 :            :     size_t i;
+     597                 :            : 
+     598         [ +  + ]:         10 :     if (src == dst) {
+     599         [ -  + ]:          4 :         LIBSPDM_ASSERT(dst_size == src_size);
+     600                 :            : 
+     601                 :            :         /* src and dst are same buffer. Swap ecdsa 2 internal buffers in place. */
+     602                 :            : 
+     603                 :            :         size_t x_size;
+     604                 :            :         size_t y_size;
+     605                 :            :         uint8_t* x;
+     606                 :            :         uint8_t* y;
+     607                 :            :         uint8_t byte;
+     608                 :            : 
+     609                 :          4 :         x_size = dst_size / 2;
+     610                 :          4 :         y_size = x_size;
+     611                 :            : 
+     612                 :          4 :         x = dst;
+     613                 :          4 :         y = x + x_size;
+     614                 :            : 
+     615         [ +  + ]:         68 :         for (i = 0; i < x_size / 2; i++) {
+     616                 :         64 :             byte = x[i];
+     617                 :         64 :             x[i] = x[x_size - i - 1];
+     618                 :         64 :             x[x_size - i - 1] = byte;
+     619                 :            :         }
+     620                 :            : 
+     621         [ +  + ]:         68 :         for (i = 0; i < y_size / 2; i++) {
+     622                 :         64 :             byte = y[i];
+     623                 :         64 :             y[i] = y[y_size - i - 1];
+     624                 :         64 :             y[y_size - i - 1] = byte;
+     625                 :            :         }
+     626                 :            :     } else {
+     627                 :            :         /* src and dst are different buffers.
+     628                 :            :          * Guard against overlap case with assert.
+     629                 :            :          * Overlap case is not an expected usage model. */
+     630         [ -  + ]:          6 :         LIBSPDM_ASSERT(dst_size >= src_size);
+     631   [ -  +  -  -  :          6 :         LIBSPDM_ASSERT((src < dst && src + src_size <= dst) ||
+             +  -  -  + ]
+     632                 :            :                        (dst < src && dst + dst_size <= src));
+     633                 :            : 
+     634                 :            :         size_t x_size;
+     635                 :            :         size_t y_size;
+     636                 :            : 
+     637                 :            :         const uint8_t* src_x;
+     638                 :            :         const uint8_t* src_y;
+     639                 :            : 
+     640                 :            :         uint8_t* dst_x;
+     641                 :            :         uint8_t* dst_y;
+     642                 :            : 
+     643                 :          6 :         x_size = src_size / 2;
+     644                 :          6 :         y_size = x_size;
+     645                 :            : 
+     646                 :          6 :         src_x = src;
+     647                 :          6 :         src_y = src_x + x_size;
+     648                 :            : 
+     649                 :          6 :         dst_x = dst;
+     650                 :          6 :         dst_y = dst_x + x_size;
+     651                 :            : 
+     652         [ +  + ]:        198 :         for (i = 0; i < x_size; i++) {
+     653                 :        192 :             dst_x[i] = src_x[x_size - i - 1];
+     654                 :            :         }
+     655                 :            : 
+     656         [ +  + ]:        198 :         for (i = 0; i < y_size; i++) {
+     657                 :        192 :             dst_y[i] = src_y[y_size - i - 1];
+     658                 :            :         }
+     659                 :            :     }
+     660                 :         10 : }
+     661                 :            : 
+     662                 :         20 : void libspdm_copy_signature_swap_endian(
+     663                 :            :     uint32_t base_asym_algo,
+     664                 :            :     uint8_t* dst,
+     665                 :            :     size_t dst_size,
+     666                 :            :     const uint8_t* src,
+     667                 :            :     size_t src_size)
+     668                 :            : {
+     669                 :         20 :     const uint32_t spdm_10_11_rsa_algos =
+     670                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048 |
+     671                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048 |
+     672                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072 |
+     673                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072 |
+     674                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096 |
+     675                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096;
+     676                 :            : 
+     677                 :         20 :     const uint32_t spdm_10_11_ecdsa_algos =
+     678                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256 |
+     679                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384 |
+     680                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521;
+     681                 :            : 
+     682         [ +  + ]:         20 :     if (base_asym_algo & spdm_10_11_rsa_algos) {
+     683                 :         10 :         libspdm_copy_signature_swap_endian_rsa(dst, dst_size, src, src_size);
+     684         [ +  - ]:         10 :     } else if (base_asym_algo & spdm_10_11_ecdsa_algos) {
+     685                 :         10 :         libspdm_copy_signature_swap_endian_ecdsa(dst, dst_size, src, src_size);
+     686                 :            :     } else {
+     687                 :            :         /* Currently do not expect asymmetric algorithms other than RSA and ECDSA */
+     688                 :          0 :         LIBSPDM_ASSERT(0);
+     689                 :            :     }
+     690                 :         20 : }
+     691                 :            : 
+     692                 :            : /**
+     693                 :            :  * libspdm_is_palindrome
+     694                 :            :  * Checks to see if a buffer is a palindrome.
+     695                 :            :  * If the buffer is a palindrone, it is the same for both endians,
+     696                 :            :  * and therefore endianness cannot be determined.
+     697                 :            :  **/
+     698                 :         69 : bool libspdm_is_palindrome(const uint8_t* buf, size_t buf_size)
+     699                 :            : {
+     700                 :            :     size_t head;
+     701                 :            :     size_t tail;
+     702                 :            : 
+     703                 :         69 :     head = 0;
+     704                 :         69 :     tail = buf_size - 1;
+     705                 :            : 
+     706         [ +  + ]:        290 :     while (head < tail) {
+     707         [ +  + ]:        267 :         if (buf[head] != buf[tail]) {
+     708                 :         46 :             return false;
+     709                 :            :         }
+     710                 :        221 :         head++;
+     711                 :        221 :         tail--;
+     712                 :            :     }
+     713                 :            : 
+     714                 :         23 :     return true;
+     715                 :            : }
+     716                 :            : 
+     717                 :         52 : bool libspdm_is_signature_buffer_palindrome(
+     718                 :            :     uint32_t base_asym_algo, const uint8_t *buf, size_t buf_size)
+     719                 :            : {
+     720                 :         52 :     const uint32_t spdm_10_11_rsa_algos =
+     721                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048 |
+     722                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048 |
+     723                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072 |
+     724                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072 |
+     725                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096 |
+     726                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096;
+     727                 :            : 
+     728                 :         52 :     const uint32_t spdm_10_11_ecdsa_algos =
+     729                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256 |
+     730                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384 |
+     731                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521;
+     732                 :            : 
+     733         [ +  + ]:         52 :     if (base_asym_algo & spdm_10_11_rsa_algos) {
+     734                 :         27 :         return libspdm_is_palindrome(buf, buf_size);
+     735         [ +  - ]:         25 :     } else if (base_asym_algo & spdm_10_11_ecdsa_algos) {
+     736                 :         25 :         const size_t x_size = buf_size / 2;
+     737                 :         25 :         const size_t y_size = x_size;
+     738                 :            : 
+     739                 :         25 :         const uint8_t *x = buf;
+     740                 :         25 :         const uint8_t *y = buf + x_size;
+     741                 :            : 
+     742   [ +  +  +  + ]:         25 :         return libspdm_is_palindrome(x, x_size) && libspdm_is_palindrome(y, y_size);
+     743                 :            :     } else {
+     744                 :            :         /* Currently do not expect asymmetric algorithms other than RSA and ECDSA */
+     745                 :          0 :         LIBSPDM_ASSERT(0);
+     746                 :          0 :         return false;
+     747                 :            :     }
+     748                 :            : }
+     749                 :            : 
+     750                 :            : #if LIBSPDM_RSA_SSA_SUPPORT
+     751                 :         21 : static bool libspdm_rsa_pkcs1_verify_with_nid_wrap (void *context, size_t hash_nid,
+     752                 :            :                                                     const uint8_t *param, size_t param_size,
+     753                 :            :                                                     const uint8_t *message,
+     754                 :            :                                                     size_t message_size,
+     755                 :            :                                                     const uint8_t *signature,
+     756                 :            :                                                     size_t sig_size)
+     757                 :            : {
+     758                 :         21 :     return libspdm_rsa_pkcs1_verify_with_nid (context, hash_nid,
+     759                 :            :                                               message, message_size, signature, sig_size);
+     760                 :            : }
+     761                 :            : #endif
+     762                 :            : 
+     763                 :            : #if LIBSPDM_RSA_PSS_SUPPORT
+     764                 :          0 : static bool libspdm_rsa_pss_verify_wrap (void *context, size_t hash_nid,
+     765                 :            :                                          const uint8_t *param, size_t param_size,
+     766                 :            :                                          const uint8_t *message,
+     767                 :            :                                          size_t message_size,
+     768                 :            :                                          const uint8_t *signature,
+     769                 :            :                                          size_t sig_size)
+     770                 :            : {
+     771                 :          0 :     return libspdm_rsa_pss_verify (context, hash_nid, message, message_size, signature, sig_size);
+     772                 :            : }
+     773                 :            : #endif
+     774                 :            : 
+     775                 :            : #if LIBSPDM_ECDSA_SUPPORT
+     776                 :         69 : bool libspdm_ecdsa_verify_wrap (void *context, size_t hash_nid,
+     777                 :            :                                 const uint8_t *param, size_t param_size,
+     778                 :            :                                 const uint8_t *message,
+     779                 :            :                                 size_t message_size,
+     780                 :            :                                 const uint8_t *signature,
+     781                 :            :                                 size_t sig_size)
+     782                 :            : {
+     783                 :         69 :     return libspdm_ecdsa_verify (context, hash_nid, message, message_size, signature, sig_size);
+     784                 :            : }
+     785                 :            : #endif
+     786                 :            : 
+     787                 :            : #if (LIBSPDM_EDDSA_ED25519_SUPPORT) || (LIBSPDM_EDDSA_ED448_SUPPORT)
+     788                 :            : bool libspdm_eddsa_verify_wrap (void *context, size_t hash_nid,
+     789                 :            :                                 const uint8_t *param, size_t param_size,
+     790                 :            :                                 const uint8_t *message,
+     791                 :            :                                 size_t message_size,
+     792                 :            :                                 const uint8_t *signature,
+     793                 :            :                                 size_t sig_size)
+     794                 :            : {
+     795                 :            :     return libspdm_eddsa_verify (context, hash_nid, param, param_size,
+     796                 :            :                                  message, message_size, signature, sig_size);
+     797                 :            : }
+     798                 :            : #endif
+     799                 :            : 
+     800                 :            : #if LIBSPDM_SM2_DSA_SUPPORT
+     801                 :            : bool libspdm_sm2_dsa_verify_wrap (void *context, size_t hash_nid,
+     802                 :            :                                   const uint8_t *param, size_t param_size,
+     803                 :            :                                   const uint8_t *message,
+     804                 :            :                                   size_t message_size,
+     805                 :            :                                   const uint8_t *signature,
+     806                 :            :                                   size_t sig_size)
+     807                 :            : {
+     808                 :            :     return libspdm_sm2_dsa_verify (context, hash_nid, param, param_size,
+     809                 :            :                                    message, message_size, signature, sig_size);
+     810                 :            : }
+     811                 :            : #endif
+     812                 :            : 
+     813                 :         90 : static bool libspdm_asym_verify_wrap(
+     814                 :            :     void *context, size_t hash_nid, uint32_t base_asym_algo,
+     815                 :            :     const uint8_t *param, size_t param_size,
+     816                 :            :     const uint8_t *message, size_t message_size,
+     817                 :            :     const uint8_t *signature, size_t sig_size)
+     818                 :            : {
+     819   [ +  -  +  -  :         90 :     switch (base_asym_algo) {
+                   -  - ]
+     820                 :         21 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
+     821                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
+     822                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
+     823                 :            : #if LIBSPDM_RSA_SSA_SUPPORT
+     824                 :            : #if !LIBSPDM_RSA_SSA_2048_SUPPORT
+     825                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048);
+     826                 :            : #endif
+     827                 :            : #if !LIBSPDM_RSA_SSA_3072_SUPPORT
+     828                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072);
+     829                 :            : #endif
+     830                 :            : #if !LIBSPDM_RSA_SSA_4096_SUPPORT
+     831                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096);
+     832                 :            : #endif
+     833                 :         21 :         return libspdm_rsa_pkcs1_verify_with_nid_wrap(context, hash_nid,
+     834                 :            :                                                       param, param_size,
+     835                 :            :                                                       message, message_size,
+     836                 :            :                                                       signature, sig_size);
+     837                 :            : #else
+     838                 :            :         LIBSPDM_ASSERT(false);
+     839                 :            :         return false;
+     840                 :            : #endif
+     841                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048:
+     842                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072:
+     843                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096:
+     844                 :            : #if LIBSPDM_RSA_PSS_SUPPORT
+     845                 :            : #if !LIBSPDM_RSA_PSS_2048_SUPPORT
+     846                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048);
+     847                 :            : #endif
+     848                 :            : #if !LIBSPDM_RSA_PSS_3072_SUPPORT
+     849                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072);
+     850                 :            : #endif
+     851                 :            : #if !LIBSPDM_RSA_PSS_4096_SUPPORT
+     852                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096);
+     853                 :            : #endif
+     854                 :          0 :         return libspdm_rsa_pss_verify_wrap(context, hash_nid,
+     855                 :            :                                            param, param_size,
+     856                 :            :                                            message, message_size,
+     857                 :            :                                            signature, sig_size);
+     858                 :            : #else
+     859                 :            :         LIBSPDM_ASSERT(false);
+     860                 :            :         return false;
+     861                 :            : #endif
+     862                 :         69 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
+     863                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
+     864                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
+     865                 :            : #if LIBSPDM_ECDSA_SUPPORT
+     866                 :            : #if !LIBSPDM_ECDSA_P256_SUPPORT
+     867                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256);
+     868                 :            : #endif
+     869                 :            : #if !LIBSPDM_ECDSA_P384_SUPPORT
+     870                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384);
+     871                 :            : #endif
+     872                 :            : #if !LIBSPDM_ECDSA_P521_SUPPORT
+     873                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521);
+     874                 :            : #endif
+     875                 :         69 :         return libspdm_ecdsa_verify_wrap(context, hash_nid,
+     876                 :            :                                          param, param_size,
+     877                 :            :                                          message, message_size,
+     878                 :            :                                          signature, sig_size);
+     879                 :            : #else
+     880                 :            :         LIBSPDM_ASSERT(false);
+     881                 :            :         return false;
+     882                 :            : #endif
+     883                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
+     884                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
+     885                 :            : #if (LIBSPDM_EDDSA_ED25519_SUPPORT) || (LIBSPDM_EDDSA_ED448_SUPPORT)
+     886                 :            : #if !LIBSPDM_EDDSA_ED25519_SUPPORT
+     887                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519);
+     888                 :            : #endif
+     889                 :            : #if !LIBSPDM_EDDSA_ED448_SUPPORT
+     890                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448);
+     891                 :            : #endif
+     892                 :            :         return libspdm_eddsa_verify_wrap(context, hash_nid,
+     893                 :            :                                          param, param_size,
+     894                 :            :                                          message, message_size,
+     895                 :            :                                          signature, sig_size);
+     896                 :            : #else
+     897                 :          0 :         LIBSPDM_ASSERT(false);
+     898                 :          0 :         return false;
+     899                 :            : #endif
+     900                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256:
+     901                 :            : #if LIBSPDM_SM2_DSA_SUPPORT
+     902                 :            :         return libspdm_sm2_dsa_verify_wrap(context, hash_nid,
+     903                 :            :                                            param, param_size,
+     904                 :            :                                            message, message_size,
+     905                 :            :                                            signature, sig_size);
+     906                 :            : #else
+     907                 :          0 :         LIBSPDM_ASSERT(false);
+     908                 :          0 :         return false;
+     909                 :            : #endif
+     910                 :          0 :     default:
+     911                 :          0 :         LIBSPDM_ASSERT(false);
+     912                 :          0 :         return false;
+     913                 :            :     }
+     914                 :            : }
+     915                 :            : 
+     916                 :          0 : bool libspdm_asym_verify_ex(
+     917                 :            :     spdm_version_number_t spdm_version, uint8_t op_code,
+     918                 :            :     uint32_t base_asym_algo, uint32_t base_hash_algo,
+     919                 :            :     void *context,
+     920                 :            :     const uint8_t *message, size_t message_size,
+     921                 :            :     const uint8_t *signature, size_t sig_size,
+     922                 :            :     uint8_t *endian)
+     923                 :            : {
+     924                 :            :     bool need_hash;
+     925                 :            :     uint8_t message_hash[LIBSPDM_MAX_HASH_SIZE];
+     926                 :            :     size_t hash_size;
+     927                 :            :     bool result;
+     928                 :            :     size_t hash_nid;
+     929                 :            :     uint8_t spdm12_signing_context_with_hash[SPDM_VERSION_1_2_SIGNING_CONTEXT_SIZE +
+     930                 :            :                                              LIBSPDM_MAX_HASH_SIZE];
+     931                 :            :     const void *param;
+     932                 :            :     size_t param_size;
+     933                 :            : 
+     934                 :            :     bool try_big_endian;
+     935                 :            :     bool try_little_endian;
+     936                 :            :     bool little_endian_succeeded;
+     937                 :            :     uint8_t endian_swapped_signature[LIBSPDM_MAX_ASYM_SIG_SIZE];
+     938                 :            : 
+     939                 :          0 :     hash_nid = libspdm_get_hash_nid(base_hash_algo);
+     940                 :          0 :     need_hash = libspdm_asym_func_need_hash(base_asym_algo);
+     941                 :            : 
+     942                 :          0 :     param = NULL;
+     943                 :          0 :     param_size = 0;
+     944                 :            : 
+     945         [ #  # ]:          0 :     if ((spdm_version >> SPDM_VERSION_NUMBER_SHIFT_BIT) > SPDM_MESSAGE_VERSION_11) {
+     946                 :            :         /* Need use SPDM 1.2 signing. */
+     947   [ #  #  #  # ]:          0 :         switch (base_asym_algo) {
+     948                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256:
+     949                 :          0 :             param = "";
+     950                 :          0 :             param_size = 0;
+     951                 :          0 :             break;
+     952                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
+     953                 :          0 :             hash_nid = LIBSPDM_CRYPTO_NID_NULL;
+     954                 :          0 :             break;
+     955                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
+     956                 :          0 :             hash_nid = LIBSPDM_CRYPTO_NID_NULL;
+     957                 :          0 :             param = libspdm_get_signing_context_string (spdm_version, op_code, false, &param_size);
+     958                 :          0 :             break;
+     959                 :          0 :         default:
+     960                 :            :             /* pass thru for rest algorithm */
+     961                 :          0 :             break;
+     962                 :            :         }
+     963                 :            : 
+     964                 :          0 :         libspdm_create_signing_context (spdm_version, op_code, false,
+     965                 :            :                                         spdm12_signing_context_with_hash);
+     966                 :          0 :         hash_size = libspdm_get_hash_size(base_hash_algo);
+     967                 :          0 :         result = libspdm_hash_all(base_hash_algo, message, message_size,
+     968                 :            :                                   &spdm12_signing_context_with_hash[
+     969                 :            :                                       SPDM_VERSION_1_2_SIGNING_CONTEXT_SIZE]);
+     970         [ #  # ]:          0 :         if (!result) {
+     971                 :          0 :             return false;
+     972                 :            :         }
+     973                 :            : 
+     974                 :            :         /* re-assign message and message_size for signing */
+     975                 :          0 :         message = spdm12_signing_context_with_hash;
+     976                 :          0 :         message_size = SPDM_VERSION_1_2_SIGNING_CONTEXT_SIZE + hash_size;
+     977                 :          0 :         try_big_endian = true;
+     978                 :          0 :         try_little_endian = false;
+     979                 :          0 :         little_endian_succeeded = false;
+     980                 :            :         /* Passthru */
+     981                 :            :     } else {
+     982                 :          0 :         try_big_endian =
+     983                 :          0 :             (*endian == LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_ONLY
+     984   [ #  #  #  # ]:          0 :              || *endian == LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_OR_LITTLE);
+     985                 :            : 
+     986                 :          0 :         try_little_endian =
+     987                 :          0 :             (*endian == LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_LITTLE_ONLY
+     988   [ #  #  #  # ]:          0 :              || *endian == LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_OR_LITTLE);
+     989                 :            : 
+     990                 :          0 :         little_endian_succeeded = false;
+     991                 :            :     }
+     992                 :            : 
+     993         [ #  # ]:          0 :     if (need_hash) {
+     994                 :          0 :         hash_size = libspdm_get_hash_size(base_hash_algo);
+     995                 :          0 :         result = libspdm_hash_all(base_hash_algo, message, message_size, message_hash);
+     996         [ #  # ]:          0 :         if (!result) {
+     997                 :          0 :             return false;
+     998                 :            :         }
+     999                 :          0 :         result = false;
+    1000         [ #  # ]:          0 :         if (try_big_endian) {
+    1001                 :          0 :             result = libspdm_asym_verify_wrap(context, hash_nid, base_asym_algo,
+    1002                 :            :                                               param, param_size,
+    1003                 :            :                                               message_hash, hash_size,
+    1004                 :            :                                               signature, sig_size);
+    1005                 :            :         }
+    1006   [ #  #  #  # ]:          0 :         if (!result && try_little_endian) {
+    1007                 :          0 :             libspdm_copy_signature_swap_endian(
+    1008                 :            :                 base_asym_algo,
+    1009                 :            :                 endian_swapped_signature, sizeof(endian_swapped_signature),
+    1010                 :            :                 signature, sig_size);
+    1011                 :            : 
+    1012                 :          0 :             result = libspdm_asym_verify_wrap(context, hash_nid, base_asym_algo,
+    1013                 :            :                                               param, param_size,
+    1014                 :            :                                               message_hash, hash_size,
+    1015                 :            :                                               endian_swapped_signature, sig_size);
+    1016                 :          0 :             little_endian_succeeded = result;
+    1017                 :            :         }
+    1018                 :            :     } else {
+    1019                 :          0 :         result = false;
+    1020         [ #  # ]:          0 :         if (try_big_endian) {
+    1021                 :          0 :             result = libspdm_asym_verify_wrap(context, hash_nid, base_asym_algo,
+    1022                 :            :                                               param, param_size,
+    1023                 :            :                                               message, message_size,
+    1024                 :            :                                               signature, sig_size);
+    1025                 :            :         }
+    1026   [ #  #  #  # ]:          0 :         if (!result && try_little_endian) {
+    1027                 :          0 :             libspdm_copy_signature_swap_endian(
+    1028                 :            :                 base_asym_algo,
+    1029                 :            :                 endian_swapped_signature, sizeof(endian_swapped_signature),
+    1030                 :            :                 signature, sig_size);
+    1031                 :            : 
+    1032                 :          0 :             result = libspdm_asym_verify_wrap(context, hash_nid, base_asym_algo,
+    1033                 :            :                                               param, param_size,
+    1034                 :            :                                               message, message_size,
+    1035                 :            :                                               endian_swapped_signature, sig_size);
+    1036                 :          0 :             little_endian_succeeded = result;
+    1037                 :            :         }
+    1038                 :            :     }
+    1039   [ #  #  #  #  :          0 :     if (try_big_endian && try_little_endian && result) {
+                   #  # ]
+    1040         [ #  # ]:          0 :         if (!libspdm_is_signature_buffer_palindrome(base_asym_algo, signature, sig_size)) {
+    1041         [ #  # ]:          0 :             if (little_endian_succeeded) {
+    1042                 :          0 :                 *endian = LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_LITTLE_ONLY;
+    1043                 :            :             } else {
+    1044                 :          0 :                 *endian = LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_ONLY;
+    1045                 :            :             }
+    1046                 :            :         }
+    1047                 :            :     }
+    1048                 :          0 :     return result;
+    1049                 :            : }
+    1050                 :            : 
+    1051                 :            : 
+    1052                 :         67 : bool libspdm_asym_verify_hash_ex(
+    1053                 :            :     spdm_version_number_t spdm_version, uint8_t op_code,
+    1054                 :            :     uint32_t base_asym_algo, uint32_t base_hash_algo,
+    1055                 :            :     void *context, const uint8_t *message_hash,
+    1056                 :            :     size_t hash_size, const uint8_t *signature,
+    1057                 :            :     size_t sig_size, uint8_t *endian)
+    1058                 :            : {
+    1059                 :            :     bool need_hash;
+    1060                 :            :     uint8_t *message;
+    1061                 :            :     size_t message_size;
+    1062                 :            :     uint8_t full_message_hash[LIBSPDM_MAX_HASH_SIZE];
+    1063                 :            :     bool result;
+    1064                 :            :     size_t hash_nid;
+    1065                 :            :     uint8_t spdm12_signing_context_with_hash[SPDM_VERSION_1_2_SIGNING_CONTEXT_SIZE +
+    1066                 :            :                                              LIBSPDM_MAX_HASH_SIZE];
+    1067                 :            :     const void *param;
+    1068                 :            :     size_t param_size;
+    1069                 :            : 
+    1070                 :            :     bool try_big_endian;
+    1071                 :            :     bool try_little_endian;
+    1072                 :            :     bool little_endian_succeeded;
+    1073                 :            :     uint8_t endian_swapped_signature[LIBSPDM_MAX_ASYM_SIG_SIZE];
+    1074                 :            : 
+    1075                 :         67 :     hash_nid = libspdm_get_hash_nid(base_hash_algo);
+    1076                 :         67 :     need_hash = libspdm_asym_func_need_hash(base_asym_algo);
+    1077         [ -  + ]:         67 :     LIBSPDM_ASSERT (hash_size == libspdm_get_hash_size(base_hash_algo));
+    1078                 :            : 
+    1079                 :         67 :     param = NULL;
+    1080                 :         67 :     param_size = 0;
+    1081                 :         67 :     try_big_endian = true;
+    1082                 :         67 :     try_little_endian = false;
+    1083                 :         67 :     little_endian_succeeded = false;
+    1084                 :            : 
+    1085         [ +  + ]:         67 :     if ((spdm_version >> SPDM_VERSION_NUMBER_SHIFT_BIT) > SPDM_MESSAGE_VERSION_11) {
+    1086                 :            :         /* Need use SPDM 1.2 signing */
+    1087   [ -  -  -  + ]:          9 :         switch (base_asym_algo) {
+    1088                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256:
+    1089                 :          0 :             param = "";
+    1090                 :          0 :             param_size = 0;
+    1091                 :          0 :             break;
+    1092                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
+    1093                 :          0 :             hash_nid = LIBSPDM_CRYPTO_NID_NULL;
+    1094                 :          0 :             break;
+    1095                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
+    1096                 :          0 :             hash_nid = LIBSPDM_CRYPTO_NID_NULL;
+    1097                 :          0 :             param = libspdm_get_signing_context_string (spdm_version, op_code, false, &param_size);
+    1098                 :          0 :             break;
+    1099                 :          9 :         default:
+    1100                 :            :             /* pass thru for rest algorithm */
+    1101                 :          9 :             break;
+    1102                 :            :         }
+    1103                 :            : 
+    1104                 :          9 :         libspdm_create_signing_context (spdm_version, op_code, false,
+    1105                 :            :                                         spdm12_signing_context_with_hash);
+    1106                 :          9 :         libspdm_copy_mem(&spdm12_signing_context_with_hash[SPDM_VERSION_1_2_SIGNING_CONTEXT_SIZE],
+    1107                 :            :                          sizeof(spdm12_signing_context_with_hash)
+    1108                 :            :                          - (&spdm12_signing_context_with_hash[SPDM_VERSION_1_2_SIGNING_CONTEXT_SIZE]
+    1109                 :            :                             - spdm12_signing_context_with_hash),
+    1110                 :            :                          message_hash, hash_size);
+    1111                 :            : 
+    1112                 :            :         /* assign message and message_size for signing */
+    1113                 :          9 :         message = spdm12_signing_context_with_hash;
+    1114                 :          9 :         message_size = SPDM_VERSION_1_2_SIGNING_CONTEXT_SIZE + hash_size;
+    1115                 :            : 
+    1116         [ +  - ]:          9 :         if (need_hash) {
+    1117                 :          9 :             result = libspdm_hash_all(base_hash_algo, message, message_size, full_message_hash);
+    1118         [ -  + ]:          9 :             if (!result) {
+    1119                 :          0 :                 return false;
+    1120                 :            :             }
+    1121                 :          9 :             return libspdm_asym_verify_wrap(context, hash_nid, base_asym_algo,
+    1122                 :            :                                             param, param_size,
+    1123                 :            :                                             full_message_hash, hash_size,
+    1124                 :            :                                             signature, sig_size);
+    1125                 :            :         } else {
+    1126                 :          0 :             return libspdm_asym_verify_wrap(context, hash_nid, base_asym_algo,
+    1127                 :            :                                             param, param_size,
+    1128                 :            :                                             message, message_size,
+    1129                 :            :                                             signature, sig_size);
+    1130                 :            :         }
+    1131                 :            :         /* SPDM 1.2 signing done. */
+    1132                 :            :     } else {
+    1133                 :         58 :         try_big_endian =
+    1134                 :         58 :             (*endian == LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_ONLY
+    1135   [ +  +  +  + ]:         58 :              || *endian == LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_OR_LITTLE);
+    1136                 :            : 
+    1137                 :         58 :         try_little_endian =
+    1138                 :         58 :             (*endian == LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_LITTLE_ONLY
+    1139   [ +  +  +  + ]:         58 :              || *endian == LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_OR_LITTLE);
+    1140                 :            : 
+    1141                 :         58 :         little_endian_succeeded = false;
+    1142                 :            :     }
+    1143                 :            : 
+    1144         [ +  - ]:         58 :     if (need_hash) {
+    1145                 :         58 :         result = false;
+    1146         [ +  + ]:         58 :         if (try_big_endian) {
+    1147                 :         54 :             result = libspdm_asym_verify_wrap(context, hash_nid, base_asym_algo,
+    1148                 :            :                                               param, param_size,
+    1149                 :            :                                               message_hash, hash_size,
+    1150                 :            :                                               signature, sig_size);
+    1151                 :            :         }
+    1152   [ +  +  +  + ]:         58 :         if (!result && try_little_endian) {
+    1153                 :          6 :             libspdm_copy_signature_swap_endian(
+    1154                 :            :                 base_asym_algo,
+    1155                 :            :                 endian_swapped_signature, sizeof(endian_swapped_signature),
+    1156                 :            :                 signature, sig_size);
+    1157                 :            : 
+    1158                 :          6 :             result = libspdm_asym_verify_wrap(context, hash_nid, base_asym_algo,
+    1159                 :            :                                               param, param_size,
+    1160                 :            :                                               message_hash, hash_size,
+    1161                 :            :                                               endian_swapped_signature, sig_size);
+    1162                 :          6 :             little_endian_succeeded = result;
+    1163                 :            :         }
+    1164   [ +  +  +  +  :         58 :         if (try_big_endian && try_little_endian && result) {
+                   +  - ]
+    1165         [ +  - ]:          4 :             if (!libspdm_is_signature_buffer_palindrome(base_asym_algo, signature, sig_size)) {
+    1166         [ +  + ]:          4 :                 if (little_endian_succeeded) {
+    1167                 :          2 :                     *endian = LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_LITTLE_ONLY;
+    1168                 :            :                 } else {
+    1169                 :          2 :                     *endian = LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_ONLY;
+    1170                 :            :                 }
+    1171                 :            :             }
+    1172                 :            :         }
+    1173                 :         58 :         return result;
+    1174                 :            : 
+    1175                 :            :     } else {
+    1176                 :          0 :         LIBSPDM_ASSERT(false);
+    1177                 :          0 :         return false;
+    1178                 :            :     }
+    1179                 :            : }
+    1180                 :            : 
+    1181                 :          0 : bool libspdm_asym_verify(
+    1182                 :            :     spdm_version_number_t spdm_version, uint8_t op_code,
+    1183                 :            :     uint32_t base_asym_algo, uint32_t base_hash_algo,
+    1184                 :            :     void* context, const uint8_t* message,
+    1185                 :            :     size_t message_size, const uint8_t* signature,
+    1186                 :            :     size_t sig_size)
+    1187                 :            : {
+    1188                 :          0 :     uint8_t endian = LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_ONLY;
+    1189                 :          0 :     return libspdm_asym_verify_ex(
+    1190                 :            :         spdm_version, op_code, base_asym_algo, base_hash_algo,
+    1191                 :            :         context, message, message_size, signature, sig_size, &endian);
+    1192                 :            : }
+    1193                 :            : 
+    1194                 :          0 : bool libspdm_asym_verify_hash(
+    1195                 :            :     spdm_version_number_t spdm_version, uint8_t op_code,
+    1196                 :            :     uint32_t base_asym_algo, uint32_t base_hash_algo,
+    1197                 :            :     void* context, const uint8_t* message_hash,
+    1198                 :            :     size_t hash_size, const uint8_t* signature,
+    1199                 :            :     size_t sig_size)
+    1200                 :            : {
+    1201                 :          0 :     uint8_t endian = LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_ONLY;
+    1202                 :          0 :     return libspdm_asym_verify_hash_ex(
+    1203                 :            :         spdm_version, op_code, base_asym_algo, base_hash_algo,
+    1204                 :            :         context, message_hash, hash_size, signature, sig_size, &endian);
+    1205                 :            : }
+    1206                 :            : 
+    1207                 :         87 : bool libspdm_asym_sign(
+    1208                 :            :     spdm_version_number_t spdm_version, uint8_t op_code,
+    1209                 :            :     uint32_t base_asym_algo, uint32_t base_hash_algo,
+    1210                 :            :     void *context, const uint8_t *message,
+    1211                 :            :     size_t message_size, uint8_t *signature,
+    1212                 :            :     size_t *sig_size)
+    1213                 :            : {
+    1214                 :            :     bool need_hash;
+    1215                 :            :     uint8_t message_hash[LIBSPDM_MAX_HASH_SIZE];
+    1216                 :            :     size_t hash_size;
+    1217                 :            :     bool result;
+    1218                 :            :     size_t hash_nid;
+    1219                 :            :     uint8_t spdm12_signing_context_with_hash[SPDM_VERSION_1_2_SIGNING_CONTEXT_SIZE +
+    1220                 :            :                                              LIBSPDM_MAX_HASH_SIZE];
+    1221                 :            :     const void *param;
+    1222                 :            :     size_t param_size;
+    1223                 :            : 
+    1224                 :         87 :     hash_nid = libspdm_get_hash_nid(base_hash_algo);
+    1225                 :         87 :     need_hash = libspdm_asym_func_need_hash(base_asym_algo);
+    1226                 :            : 
+    1227                 :         87 :     param = NULL;
+    1228                 :         87 :     param_size = 0;
+    1229                 :            : 
+    1230         [ +  + ]:         87 :     if ((spdm_version >> SPDM_VERSION_NUMBER_SHIFT_BIT) > SPDM_MESSAGE_VERSION_11) {
+    1231                 :            :         /* Need use SPDM 1.2 signing */
+    1232   [ -  -  -  + ]:         11 :         switch (base_asym_algo) {
+    1233                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256:
+    1234                 :          0 :             param = "";
+    1235                 :          0 :             param_size = 0;
+    1236                 :          0 :             break;
+    1237                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
+    1238                 :          0 :             hash_nid = LIBSPDM_CRYPTO_NID_NULL;
+    1239                 :          0 :             break;
+    1240                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
+    1241                 :          0 :             hash_nid = LIBSPDM_CRYPTO_NID_NULL;
+    1242                 :          0 :             param = libspdm_get_signing_context_string (spdm_version, op_code, false, &param_size);
+    1243                 :          0 :             break;
+    1244                 :         11 :         default:
+    1245                 :            :             /* pass thru for rest algorithm */
+    1246                 :         11 :             break;
+    1247                 :            :         }
+    1248                 :            : 
+    1249                 :         11 :         libspdm_create_signing_context (spdm_version, op_code, false,
+    1250                 :            :                                         spdm12_signing_context_with_hash);
+    1251                 :         11 :         hash_size = libspdm_get_hash_size(base_hash_algo);
+    1252                 :         11 :         result = libspdm_hash_all(base_hash_algo, message, message_size,
+    1253                 :            :                                   &spdm12_signing_context_with_hash[
+    1254                 :            :                                       SPDM_VERSION_1_2_SIGNING_CONTEXT_SIZE]);
+    1255         [ -  + ]:         11 :         if (!result) {
+    1256                 :          0 :             return false;
+    1257                 :            :         }
+    1258                 :            : 
+    1259                 :            :         /* re-assign message and message_size for signing */
+    1260                 :         11 :         message = spdm12_signing_context_with_hash;
+    1261                 :         11 :         message_size = SPDM_VERSION_1_2_SIGNING_CONTEXT_SIZE + hash_size;
+    1262                 :            : 
+    1263                 :            :         /* Passthru*/
+    1264                 :            :     }
+    1265                 :            : 
+    1266         [ +  - ]:         87 :     if (need_hash) {
+    1267                 :         87 :         hash_size = libspdm_get_hash_size(base_hash_algo);
+    1268                 :         87 :         result = libspdm_hash_all(base_hash_algo, message, message_size, message_hash);
+    1269         [ -  + ]:         87 :         if (!result) {
+    1270                 :          0 :             return false;
+    1271                 :            :         }
+    1272                 :         87 :         return libspdm_asym_sign_wrap(context, hash_nid, base_asym_algo,
+    1273                 :            :                                       param, param_size,
+    1274                 :            :                                       message_hash, hash_size,
+    1275                 :            :                                       signature, sig_size);
+    1276                 :            :     } else {
+    1277                 :          0 :         return libspdm_asym_sign_wrap(context, hash_nid, base_asym_algo,
+    1278                 :            :                                       param, param_size,
+    1279                 :            :                                       message, message_size,
+    1280                 :            :                                       signature, sig_size);
+    1281                 :            :     }
+    1282                 :            : }
+    1283                 :            : 
+    1284                 :         36 : bool libspdm_asym_sign_hash(
+    1285                 :            :     spdm_version_number_t spdm_version, uint8_t op_code,
+    1286                 :            :     uint32_t base_asym_algo, uint32_t base_hash_algo,
+    1287                 :            :     void *context, const uint8_t *message_hash,
+    1288                 :            :     size_t hash_size, uint8_t *signature,
+    1289                 :            :     size_t *sig_size)
+    1290                 :            : {
+    1291                 :            :     bool need_hash;
+    1292                 :            :     uint8_t *message;
+    1293                 :            :     size_t message_size;
+    1294                 :            :     uint8_t full_message_hash[LIBSPDM_MAX_HASH_SIZE];
+    1295                 :            :     bool result;
+    1296                 :            :     size_t hash_nid;
+    1297                 :            :     uint8_t spdm12_signing_context_with_hash[SPDM_VERSION_1_2_SIGNING_CONTEXT_SIZE +
+    1298                 :            :                                              LIBSPDM_MAX_HASH_SIZE];
+    1299                 :            :     const void *param;
+    1300                 :            :     size_t param_size;
+    1301                 :            : 
+    1302                 :         36 :     hash_nid = libspdm_get_hash_nid(base_hash_algo);
+    1303                 :         36 :     need_hash = libspdm_asym_func_need_hash(base_asym_algo);
+    1304         [ -  + ]:         36 :     LIBSPDM_ASSERT (hash_size == libspdm_get_hash_size(base_hash_algo));
+    1305                 :            : 
+    1306                 :         36 :     param = NULL;
+    1307                 :         36 :     param_size = 0;
+    1308                 :            : 
+    1309         [ +  + ]:         36 :     if ((spdm_version >> SPDM_VERSION_NUMBER_SHIFT_BIT) > SPDM_MESSAGE_VERSION_11) {
+    1310                 :            :         /* Need use SPDM 1.2 signing */
+    1311   [ -  -  -  + ]:          8 :         switch (base_asym_algo) {
+    1312                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256:
+    1313                 :          0 :             param = "";
+    1314                 :          0 :             param_size = 0;
+    1315                 :          0 :             break;
+    1316                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
+    1317                 :          0 :             hash_nid = LIBSPDM_CRYPTO_NID_NULL;
+    1318                 :          0 :             break;
+    1319                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
+    1320                 :          0 :             hash_nid = LIBSPDM_CRYPTO_NID_NULL;
+    1321                 :          0 :             param = libspdm_get_signing_context_string (spdm_version, op_code, false, &param_size);
+    1322                 :          0 :             break;
+    1323                 :          8 :         default:
+    1324                 :            :             /* pass thru for rest algorithm */
+    1325                 :          8 :             break;
+    1326                 :            :         }
+    1327                 :            : 
+    1328                 :          8 :         libspdm_create_signing_context (spdm_version, op_code, false,
+    1329                 :            :                                         spdm12_signing_context_with_hash);
+    1330                 :          8 :         libspdm_copy_mem(&spdm12_signing_context_with_hash[SPDM_VERSION_1_2_SIGNING_CONTEXT_SIZE],
+    1331                 :            :                          sizeof(spdm12_signing_context_with_hash)
+    1332                 :            :                          - (&spdm12_signing_context_with_hash[SPDM_VERSION_1_2_SIGNING_CONTEXT_SIZE]
+    1333                 :            :                             - spdm12_signing_context_with_hash),
+    1334                 :            :                          message_hash, hash_size);
+    1335                 :            : 
+    1336                 :            :         /* assign message and message_size for signing */
+    1337                 :          8 :         message = spdm12_signing_context_with_hash;
+    1338                 :          8 :         message_size = SPDM_VERSION_1_2_SIGNING_CONTEXT_SIZE + hash_size;
+    1339                 :            : 
+    1340         [ +  - ]:          8 :         if (need_hash) {
+    1341                 :          8 :             result = libspdm_hash_all(base_hash_algo, message, message_size, full_message_hash);
+    1342         [ -  + ]:          8 :             if (!result) {
+    1343                 :          0 :                 return false;
+    1344                 :            :             }
+    1345                 :          8 :             return libspdm_asym_sign_wrap(context, hash_nid, base_asym_algo,
+    1346                 :            :                                           param, param_size,
+    1347                 :            :                                           full_message_hash, hash_size,
+    1348                 :            :                                           signature, sig_size);
+    1349                 :            :         } else {
+    1350                 :          0 :             return libspdm_asym_sign_wrap(context, hash_nid, base_asym_algo,
+    1351                 :            :                                           param, param_size,
+    1352                 :            :                                           message, message_size,
+    1353                 :            :                                           signature, sig_size);
+    1354                 :            :         }
+    1355                 :            : 
+    1356                 :            :         /* SPDM 1.2 signing done. */
+    1357                 :            :     }
+    1358                 :            : 
+    1359         [ +  - ]:         28 :     if (need_hash) {
+    1360                 :         28 :         return libspdm_asym_sign_wrap(context, hash_nid, base_asym_algo,
+    1361                 :            :                                       param, param_size,
+    1362                 :            :                                       message_hash, hash_size,
+    1363                 :            :                                       signature, sig_size);
+    1364                 :            :     } else {
+    1365                 :          0 :         LIBSPDM_ASSERT (false);
+    1366                 :          0 :         return false;
+    1367                 :            :     }
+    1368                 :            : }
+    1369                 :            : 
+    1370                 :         74 : uint32_t libspdm_get_req_asym_signature_size(uint16_t req_base_asym_alg)
+    1371                 :            : {
+    1372                 :         74 :     return libspdm_get_asym_signature_size(req_base_asym_alg);
+    1373                 :            : }
+    1374                 :            : 
+    1375                 :         26 : void libspdm_req_asym_free(uint16_t req_base_asym_alg, void *context)
+    1376                 :            : {
+    1377                 :         26 :     libspdm_asym_free(req_base_asym_alg, context);
+    1378                 :         26 : }
+    1379                 :            : 
+    1380                 :          2 : bool libspdm_req_asym_get_public_key_from_der(uint16_t req_base_asym_alg,
+    1381                 :            :                                               const uint8_t *der_data,
+    1382                 :            :                                               size_t der_size,
+    1383                 :            :                                               void **context)
+    1384                 :            : {
+    1385                 :          2 :     return libspdm_asym_get_public_key_from_der_wrap(req_base_asym_alg,
+    1386                 :            :                                                      der_data,
+    1387                 :            :                                                      der_size,
+    1388                 :            :                                                      context);
+    1389                 :            : }
+    1390                 :            : 
+    1391                 :         45 : bool libspdm_req_asym_func_need_hash(uint16_t req_base_asym_alg)
+    1392                 :            : {
+    1393                 :         45 :     return libspdm_asym_func_need_hash(req_base_asym_alg);
+    1394                 :            : }
+    1395                 :            : 
+    1396                 :          0 : bool libspdm_req_asym_verify_ex(
+    1397                 :            :     spdm_version_number_t spdm_version, uint8_t op_code,
+    1398                 :            :     uint16_t req_base_asym_alg,
+    1399                 :            :     uint32_t base_hash_algo, void *context,
+    1400                 :            :     const uint8_t *message, size_t message_size,
+    1401                 :            :     const uint8_t *signature, size_t sig_size, uint8_t *endian)
+    1402                 :            : {
+    1403                 :            :     bool need_hash;
+    1404                 :            :     uint8_t message_hash[LIBSPDM_MAX_HASH_SIZE];
+    1405                 :            :     size_t hash_size;
+    1406                 :            :     bool result;
+    1407                 :            :     size_t hash_nid;
+    1408                 :            :     uint8_t spdm12_signing_context_with_hash[SPDM_VERSION_1_2_SIGNING_CONTEXT_SIZE +
+    1409                 :            :                                              LIBSPDM_MAX_HASH_SIZE];
+    1410                 :            :     const void *param;
+    1411                 :            :     size_t param_size;
+    1412                 :            : 
+    1413                 :            :     bool try_big_endian;
+    1414                 :            :     bool try_little_endian;
+    1415                 :            :     bool little_endian_succeeded;
+    1416                 :            :     uint8_t endian_swapped_signature[LIBSPDM_MAX_ASYM_SIG_SIZE];
+    1417                 :            : 
+    1418                 :          0 :     hash_nid = libspdm_get_hash_nid(base_hash_algo);
+    1419                 :          0 :     need_hash = libspdm_req_asym_func_need_hash(req_base_asym_alg);
+    1420                 :            : 
+    1421                 :          0 :     param = NULL;
+    1422                 :          0 :     param_size = 0;
+    1423                 :            : 
+    1424         [ #  # ]:          0 :     if ((spdm_version >> SPDM_VERSION_NUMBER_SHIFT_BIT) > SPDM_MESSAGE_VERSION_11) {
+    1425                 :            :         /* Need use SPDM 1.2 signing */
+    1426   [ #  #  #  # ]:          0 :         switch (req_base_asym_alg) {
+    1427                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256:
+    1428                 :          0 :             param = "";
+    1429                 :          0 :             param_size = 0;
+    1430                 :          0 :             break;
+    1431                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
+    1432                 :          0 :             hash_nid = LIBSPDM_CRYPTO_NID_NULL;
+    1433                 :          0 :             break;
+    1434                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
+    1435                 :          0 :             hash_nid = LIBSPDM_CRYPTO_NID_NULL;
+    1436                 :          0 :             param = libspdm_get_signing_context_string (spdm_version, op_code, true, &param_size);
+    1437                 :          0 :             break;
+    1438                 :          0 :         default:
+    1439                 :            :             /* pass thru for rest algorithm */
+    1440                 :          0 :             break;
+    1441                 :            :         }
+    1442                 :            : 
+    1443                 :          0 :         libspdm_create_signing_context (spdm_version, op_code, true,
+    1444                 :            :                                         spdm12_signing_context_with_hash);
+    1445                 :          0 :         hash_size = libspdm_get_hash_size(base_hash_algo);
+    1446                 :          0 :         result = libspdm_hash_all(base_hash_algo, message, message_size,
+    1447                 :            :                                   &spdm12_signing_context_with_hash[
+    1448                 :            :                                       SPDM_VERSION_1_2_SIGNING_CONTEXT_SIZE]);
+    1449         [ #  # ]:          0 :         if (!result) {
+    1450                 :          0 :             return false;
+    1451                 :            :         }
+    1452                 :            : 
+    1453                 :            :         /* re-assign message and message_size for signing */
+    1454                 :          0 :         message = spdm12_signing_context_with_hash;
+    1455                 :          0 :         message_size = SPDM_VERSION_1_2_SIGNING_CONTEXT_SIZE + hash_size;
+    1456                 :          0 :         try_big_endian = true;
+    1457                 :          0 :         try_little_endian = false;
+    1458                 :          0 :         little_endian_succeeded = false;
+    1459                 :            :         /* Passthru */
+    1460                 :            :     } else {
+    1461                 :          0 :         try_big_endian =
+    1462                 :          0 :             (*endian == LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_ONLY
+    1463   [ #  #  #  # ]:          0 :              || *endian == LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_OR_LITTLE);
+    1464                 :            : 
+    1465                 :          0 :         try_little_endian =
+    1466                 :          0 :             (*endian == LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_LITTLE_ONLY
+    1467   [ #  #  #  # ]:          0 :              || *endian == LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_OR_LITTLE);
+    1468                 :            : 
+    1469                 :          0 :         little_endian_succeeded = false;
+    1470                 :            :     }
+    1471                 :            : 
+    1472         [ #  # ]:          0 :     if (need_hash) {
+    1473                 :          0 :         hash_size = libspdm_get_hash_size(base_hash_algo);
+    1474                 :          0 :         result = libspdm_hash_all(base_hash_algo, message, message_size, message_hash);
+    1475         [ #  # ]:          0 :         if (!result) {
+    1476                 :          0 :             return false;
+    1477                 :            :         }
+    1478                 :          0 :         result = false;
+    1479         [ #  # ]:          0 :         if (try_big_endian) {
+    1480                 :          0 :             result = libspdm_asym_verify_wrap(context, hash_nid, req_base_asym_alg,
+    1481                 :            :                                               param, param_size,
+    1482                 :            :                                               message_hash, hash_size,
+    1483                 :            :                                               signature, sig_size);
+    1484                 :            :         }
+    1485   [ #  #  #  # ]:          0 :         if (!result && try_little_endian) {
+    1486                 :          0 :             libspdm_copy_signature_swap_endian(
+    1487                 :            :                 req_base_asym_alg,
+    1488                 :            :                 endian_swapped_signature, sizeof(endian_swapped_signature),
+    1489                 :            :                 signature, sig_size);
+    1490                 :            : 
+    1491                 :          0 :             result = libspdm_asym_verify_wrap(context, hash_nid, req_base_asym_alg,
+    1492                 :            :                                               param, param_size,
+    1493                 :            :                                               message_hash, hash_size,
+    1494                 :            :                                               endian_swapped_signature, sig_size);
+    1495                 :          0 :             little_endian_succeeded = result;
+    1496                 :            :         }
+    1497                 :            :     } else {
+    1498                 :          0 :         result = false;
+    1499         [ #  # ]:          0 :         if (try_big_endian) {
+    1500                 :          0 :             result = libspdm_asym_verify_wrap(context, hash_nid, req_base_asym_alg,
+    1501                 :            :                                               param, param_size,
+    1502                 :            :                                               message, message_size,
+    1503                 :            :                                               signature, sig_size);
+    1504                 :            :         }
+    1505   [ #  #  #  # ]:          0 :         if (!result && try_little_endian) {
+    1506                 :          0 :             libspdm_copy_signature_swap_endian(
+    1507                 :            :                 req_base_asym_alg,
+    1508                 :            :                 endian_swapped_signature, sizeof(endian_swapped_signature),
+    1509                 :            :                 signature, sig_size);
+    1510                 :            : 
+    1511                 :          0 :             result = libspdm_asym_verify_wrap(context, hash_nid, req_base_asym_alg,
+    1512                 :            :                                               param, param_size,
+    1513                 :            :                                               message, message_size,
+    1514                 :            :                                               endian_swapped_signature, sig_size);
+    1515                 :          0 :             little_endian_succeeded = result;
+    1516                 :            :         }
+    1517                 :            :     }
+    1518   [ #  #  #  #  :          0 :     if (try_big_endian && try_little_endian && result) {
+                   #  # ]
+    1519         [ #  # ]:          0 :         if (!libspdm_is_signature_buffer_palindrome(req_base_asym_alg, signature, sig_size)) {
+    1520         [ #  # ]:          0 :             if (little_endian_succeeded) {
+    1521                 :          0 :                 *endian = LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_LITTLE_ONLY;
+    1522                 :            :             } else {
+    1523                 :          0 :                 *endian = LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_ONLY;
+    1524                 :            :             }
+    1525                 :            :         }
+    1526                 :            :     }
+    1527                 :          0 :     return result;
+    1528                 :            : }
+    1529                 :            : 
+    1530                 :         20 : bool libspdm_req_asym_verify_hash_ex(
+    1531                 :            :     spdm_version_number_t spdm_version, uint8_t op_code,
+    1532                 :            :     uint16_t req_base_asym_alg,
+    1533                 :            :     uint32_t base_hash_algo, void *context,
+    1534                 :            :     const uint8_t *message_hash, size_t hash_size,
+    1535                 :            :     const uint8_t *signature, size_t sig_size, uint8_t *endian)
+    1536                 :            : {
+    1537                 :            :     bool need_hash;
+    1538                 :            :     uint8_t *message;
+    1539                 :            :     size_t message_size;
+    1540                 :            :     uint8_t full_message_hash[LIBSPDM_MAX_HASH_SIZE];
+    1541                 :            :     bool result;
+    1542                 :            :     size_t hash_nid;
+    1543                 :            :     uint8_t spdm12_signing_context_with_hash[SPDM_VERSION_1_2_SIGNING_CONTEXT_SIZE +
+    1544                 :            :                                              LIBSPDM_MAX_HASH_SIZE];
+    1545                 :            :     const void *param;
+    1546                 :            :     size_t param_size;
+    1547                 :            : 
+    1548                 :            :     bool try_big_endian;
+    1549                 :            :     bool try_little_endian;
+    1550                 :            :     bool little_endian_succeeded;
+    1551                 :            :     uint8_t endian_swapped_signature[LIBSPDM_MAX_ASYM_SIG_SIZE];
+    1552                 :            : 
+    1553                 :         20 :     hash_nid = libspdm_get_hash_nid(base_hash_algo);
+    1554                 :         20 :     need_hash = libspdm_req_asym_func_need_hash(req_base_asym_alg);
+    1555         [ -  + ]:         20 :     LIBSPDM_ASSERT (hash_size == libspdm_get_hash_size(base_hash_algo));
+    1556                 :            : 
+    1557                 :         20 :     param = NULL;
+    1558                 :         20 :     param_size = 0;
+    1559                 :            : 
+    1560         [ +  + ]:         20 :     if ((spdm_version >> SPDM_VERSION_NUMBER_SHIFT_BIT) > SPDM_MESSAGE_VERSION_11) {
+    1561                 :            :         /* Need use SPDM 1.2 signing */
+    1562   [ -  -  -  + ]:          1 :         switch (req_base_asym_alg) {
+    1563                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256:
+    1564                 :          0 :             param = "";
+    1565                 :          0 :             param_size = 0;
+    1566                 :          0 :             break;
+    1567                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
+    1568                 :          0 :             hash_nid = LIBSPDM_CRYPTO_NID_NULL;
+    1569                 :          0 :             break;
+    1570                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
+    1571                 :          0 :             hash_nid = LIBSPDM_CRYPTO_NID_NULL;
+    1572                 :          0 :             param = libspdm_get_signing_context_string (spdm_version, op_code, true, &param_size);
+    1573                 :          0 :             break;
+    1574                 :          1 :         default:
+    1575                 :            :             /* pass thru for rest algorithm */
+    1576                 :          1 :             break;
+    1577                 :            :         }
+    1578                 :            : 
+    1579                 :          1 :         libspdm_create_signing_context (spdm_version, op_code, true,
+    1580                 :            :                                         spdm12_signing_context_with_hash);
+    1581                 :          1 :         libspdm_copy_mem(&spdm12_signing_context_with_hash[SPDM_VERSION_1_2_SIGNING_CONTEXT_SIZE],
+    1582                 :            :                          sizeof(spdm12_signing_context_with_hash)
+    1583                 :            :                          - (&spdm12_signing_context_with_hash[SPDM_VERSION_1_2_SIGNING_CONTEXT_SIZE]
+    1584                 :            :                             - spdm12_signing_context_with_hash),
+    1585                 :            :                          message_hash, hash_size);
+    1586                 :            : 
+    1587                 :            :         /* assign message and message_size for signing */
+    1588                 :          1 :         message = spdm12_signing_context_with_hash;
+    1589                 :          1 :         message_size = SPDM_VERSION_1_2_SIGNING_CONTEXT_SIZE + hash_size;
+    1590                 :            : 
+    1591         [ +  - ]:          1 :         if (need_hash) {
+    1592                 :          1 :             result = libspdm_hash_all(base_hash_algo, message, message_size,
+    1593                 :            :                                       full_message_hash);
+    1594         [ -  + ]:          1 :             if (!result) {
+    1595                 :          0 :                 return false;
+    1596                 :            :             }
+    1597                 :          1 :             return libspdm_asym_verify_wrap(context, hash_nid, req_base_asym_alg,
+    1598                 :            :                                             param, param_size,
+    1599                 :            :                                             full_message_hash, hash_size,
+    1600                 :            :                                             signature, sig_size);
+    1601                 :            :         } else {
+    1602                 :          0 :             return libspdm_asym_verify_wrap(context, hash_nid, req_base_asym_alg,
+    1603                 :            :                                             param, param_size,
+    1604                 :            :                                             message, message_size,
+    1605                 :            :                                             signature, sig_size);
+    1606                 :            :         }
+    1607                 :            :         /* SPDM 1.2 signing done. */
+    1608                 :            :     } else {
+    1609                 :         19 :         try_big_endian =
+    1610                 :         19 :             (*endian == LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_ONLY
+    1611   [ +  +  +  + ]:         19 :              || *endian == LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_OR_LITTLE);
+    1612                 :            : 
+    1613                 :         19 :         try_little_endian =
+    1614                 :         19 :             (*endian == LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_LITTLE_ONLY
+    1615   [ +  +  +  + ]:         19 :              || *endian == LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_OR_LITTLE);
+    1616                 :            : 
+    1617                 :         19 :         little_endian_succeeded = false;
+    1618                 :            :     }
+    1619                 :            : 
+    1620         [ +  - ]:         19 :     if (need_hash) {
+    1621                 :         19 :         result = false;
+    1622         [ +  + ]:         19 :         if (try_big_endian) {
+    1623                 :         14 :             result = libspdm_asym_verify_wrap(context, hash_nid, req_base_asym_alg,
+    1624                 :            :                                               param, param_size,
+    1625                 :            :                                               message_hash, hash_size,
+    1626                 :            :                                               signature, sig_size);
+    1627                 :            :         }
+    1628   [ +  +  +  + ]:         19 :         if (!result && try_little_endian) {
+    1629                 :          6 :             libspdm_copy_signature_swap_endian(
+    1630                 :            :                 req_base_asym_alg,
+    1631                 :            :                 endian_swapped_signature, sizeof(endian_swapped_signature),
+    1632                 :            :                 signature, sig_size);
+    1633                 :            : 
+    1634                 :          6 :             result = libspdm_asym_verify_wrap(context, hash_nid, req_base_asym_alg,
+    1635                 :            :                                               param, param_size,
+    1636                 :            :                                               message_hash, hash_size,
+    1637                 :            :                                               endian_swapped_signature, sig_size);
+    1638                 :          6 :             little_endian_succeeded = result;
+    1639                 :            :         }
+    1640   [ +  +  +  +  :         19 :         if (try_big_endian && try_little_endian && result) {
+                   +  - ]
+    1641         [ +  - ]:          3 :             if (!libspdm_is_signature_buffer_palindrome(req_base_asym_alg, signature, sig_size)) {
+    1642         [ +  + ]:          3 :                 if (little_endian_succeeded) {
+    1643                 :          1 :                     *endian = LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_LITTLE_ONLY;
+    1644                 :            :                 } else {
+    1645                 :          2 :                     *endian = LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_ONLY;
+    1646                 :            :                 }
+    1647                 :            :             }
+    1648                 :            :         }
+    1649                 :         19 :         return result;
+    1650                 :            :     } else {
+    1651                 :          0 :         LIBSPDM_ASSERT (false);
+    1652                 :          0 :         return false;
+    1653                 :            :     }
+    1654                 :            : }
+    1655                 :            : 
+    1656                 :          0 : bool libspdm_req_asym_verify(
+    1657                 :            :     spdm_version_number_t spdm_version, uint8_t op_code,
+    1658                 :            :     uint16_t req_base_asym_alg,
+    1659                 :            :     uint32_t base_hash_algo, void* context,
+    1660                 :            :     const uint8_t* message, size_t message_size,
+    1661                 :            :     const uint8_t* signature, size_t sig_size)
+    1662                 :            : {
+    1663                 :          0 :     uint8_t endian = LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_ONLY;
+    1664                 :          0 :     return libspdm_req_asym_verify_ex(
+    1665                 :            :         spdm_version, op_code, req_base_asym_alg, base_hash_algo, context,
+    1666                 :            :         message, message_size, signature, sig_size, &endian);
+    1667                 :            : }
+    1668                 :            : 
+    1669                 :          0 : bool libspdm_req_asym_verify_hash(
+    1670                 :            :     spdm_version_number_t spdm_version, uint8_t op_code,
+    1671                 :            :     uint16_t req_base_asym_alg,
+    1672                 :            :     uint32_t base_hash_algo, void* context,
+    1673                 :            :     const uint8_t* message_hash, size_t hash_size,
+    1674                 :            :     const uint8_t* signature, size_t sig_size)
+    1675                 :            : {
+    1676                 :          0 :     uint8_t endian = LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_ONLY;
+    1677                 :          0 :     return libspdm_req_asym_verify_hash_ex(
+    1678                 :            :         spdm_version, op_code, req_base_asym_alg, base_hash_algo, context,
+    1679                 :            :         message_hash, hash_size, signature, sig_size, &endian);
+    1680                 :            : }
+    1681                 :            : 
+    1682                 :         16 : bool libspdm_req_asym_sign(
+    1683                 :            :     spdm_version_number_t spdm_version, uint8_t op_code,
+    1684                 :            :     uint16_t req_base_asym_alg,
+    1685                 :            :     uint32_t base_hash_algo, void *context,
+    1686                 :            :     const uint8_t *message, size_t message_size,
+    1687                 :            :     uint8_t *signature, size_t *sig_size)
+    1688                 :            : {
+    1689                 :            :     bool need_hash;
+    1690                 :            :     uint8_t message_hash[LIBSPDM_MAX_HASH_SIZE];
+    1691                 :            :     size_t hash_size;
+    1692                 :            :     bool result;
+    1693                 :            :     size_t hash_nid;
+    1694                 :            :     uint8_t spdm12_signing_context_with_hash[SPDM_VERSION_1_2_SIGNING_CONTEXT_SIZE +
+    1695                 :            :                                              LIBSPDM_MAX_HASH_SIZE];
+    1696                 :            :     const void *param;
+    1697                 :            :     size_t param_size;
+    1698                 :            : 
+    1699                 :         16 :     hash_nid = libspdm_get_hash_nid(base_hash_algo);
+    1700                 :         16 :     need_hash = libspdm_req_asym_func_need_hash(req_base_asym_alg);
+    1701                 :            : 
+    1702                 :         16 :     param = NULL;
+    1703                 :         16 :     param_size = 0;
+    1704                 :            : 
+    1705         [ +  + ]:         16 :     if ((spdm_version >> SPDM_VERSION_NUMBER_SHIFT_BIT) > SPDM_MESSAGE_VERSION_11) {
+    1706                 :            :         /* Need use SPDM 1.2 signing */
+    1707   [ -  -  -  + ]:          1 :         switch (req_base_asym_alg) {
+    1708                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256:
+    1709                 :          0 :             param = "";
+    1710                 :          0 :             param_size = 0;
+    1711                 :          0 :             break;
+    1712                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
+    1713                 :          0 :             hash_nid = LIBSPDM_CRYPTO_NID_NULL;
+    1714                 :          0 :             break;
+    1715                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
+    1716                 :          0 :             hash_nid = LIBSPDM_CRYPTO_NID_NULL;
+    1717                 :          0 :             param = libspdm_get_signing_context_string (spdm_version, op_code, true, &param_size);
+    1718                 :          0 :             break;
+    1719                 :          1 :         default:
+    1720                 :            :             /* pass thru for rest algorithm */
+    1721                 :          1 :             break;
+    1722                 :            :         }
+    1723                 :            : 
+    1724                 :          1 :         libspdm_create_signing_context (spdm_version, op_code, true,
+    1725                 :            :                                         spdm12_signing_context_with_hash);
+    1726                 :          1 :         hash_size = libspdm_get_hash_size(base_hash_algo);
+    1727                 :          1 :         result = libspdm_hash_all(base_hash_algo, message, message_size,
+    1728                 :            :                                   &spdm12_signing_context_with_hash[
+    1729                 :            :                                       SPDM_VERSION_1_2_SIGNING_CONTEXT_SIZE]);
+    1730         [ -  + ]:          1 :         if (!result) {
+    1731                 :          0 :             return false;
+    1732                 :            :         }
+    1733                 :            : 
+    1734                 :            :         /* re-assign message and message_size for signing */
+    1735                 :          1 :         message = spdm12_signing_context_with_hash;
+    1736                 :          1 :         message_size = SPDM_VERSION_1_2_SIGNING_CONTEXT_SIZE + hash_size;
+    1737                 :            : 
+    1738                 :            :         /* Passthru */
+    1739                 :            :     }
+    1740                 :            : 
+    1741         [ +  - ]:         16 :     if (need_hash) {
+    1742                 :         16 :         hash_size = libspdm_get_hash_size(base_hash_algo);
+    1743                 :         16 :         result = libspdm_hash_all(base_hash_algo, message, message_size,
+    1744                 :            :                                   message_hash);
+    1745         [ -  + ]:         16 :         if (!result) {
+    1746                 :          0 :             return false;
+    1747                 :            :         }
+    1748                 :         16 :         return libspdm_asym_sign_wrap(context, hash_nid, req_base_asym_alg,
+    1749                 :            :                                       param, param_size,
+    1750                 :            :                                       message_hash, hash_size,
+    1751                 :            :                                       signature, sig_size);
+    1752                 :            :     } else {
+    1753                 :          0 :         return libspdm_asym_sign_wrap(context, hash_nid, req_base_asym_alg,
+    1754                 :            :                                       param, param_size,
+    1755                 :            :                                       message, message_size,
+    1756                 :            :                                       signature, sig_size);
+    1757                 :            :     }
+    1758                 :            : }
+    1759                 :            : 
+    1760                 :          9 : bool libspdm_req_asym_sign_hash(
+    1761                 :            :     spdm_version_number_t spdm_version, uint8_t op_code,
+    1762                 :            :     uint16_t req_base_asym_alg,
+    1763                 :            :     uint32_t base_hash_algo, void *context,
+    1764                 :            :     const uint8_t *message_hash, size_t hash_size,
+    1765                 :            :     uint8_t *signature, size_t *sig_size)
+    1766                 :            : {
+    1767                 :            :     bool need_hash;
+    1768                 :            :     uint8_t *message;
+    1769                 :            :     size_t message_size;
+    1770                 :            :     uint8_t full_message_hash[LIBSPDM_MAX_HASH_SIZE];
+    1771                 :            :     bool result;
+    1772                 :            :     size_t hash_nid;
+    1773                 :            :     uint8_t spdm12_signing_context_with_hash[SPDM_VERSION_1_2_SIGNING_CONTEXT_SIZE +
+    1774                 :            :                                              LIBSPDM_MAX_HASH_SIZE];
+    1775                 :            :     const void *param;
+    1776                 :            :     size_t param_size;
+    1777                 :            : 
+    1778                 :          9 :     hash_nid = libspdm_get_hash_nid(base_hash_algo);
+    1779                 :          9 :     need_hash = libspdm_req_asym_func_need_hash(req_base_asym_alg);
+    1780         [ -  + ]:          9 :     LIBSPDM_ASSERT (hash_size == libspdm_get_hash_size(base_hash_algo));
+    1781                 :            : 
+    1782                 :          9 :     param = NULL;
+    1783                 :          9 :     param_size = 0;
+    1784                 :            : 
+    1785         [ +  + ]:          9 :     if ((spdm_version >> SPDM_VERSION_NUMBER_SHIFT_BIT) > SPDM_MESSAGE_VERSION_11) {
+    1786                 :            :         /* Need use SPDM 1.2 signing */
+    1787   [ -  -  -  + ]:          1 :         switch (req_base_asym_alg) {
+    1788                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256:
+    1789                 :          0 :             param = "";
+    1790                 :          0 :             param_size = 0;
+    1791                 :          0 :             break;
+    1792                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
+    1793                 :          0 :             hash_nid = LIBSPDM_CRYPTO_NID_NULL;
+    1794                 :          0 :             break;
+    1795                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
+    1796                 :          0 :             hash_nid = LIBSPDM_CRYPTO_NID_NULL;
+    1797                 :          0 :             param = libspdm_get_signing_context_string (spdm_version, op_code, true, &param_size);
+    1798                 :          0 :             break;
+    1799                 :          1 :         default:
+    1800                 :            :             /* pass thru for rest algorithm */
+    1801                 :          1 :             break;
+    1802                 :            :         }
+    1803                 :            : 
+    1804                 :          1 :         libspdm_create_signing_context (spdm_version, op_code, true,
+    1805                 :            :                                         spdm12_signing_context_with_hash);
+    1806                 :          1 :         libspdm_copy_mem(&spdm12_signing_context_with_hash[SPDM_VERSION_1_2_SIGNING_CONTEXT_SIZE],
+    1807                 :            :                          sizeof(spdm12_signing_context_with_hash)
+    1808                 :            :                          - (&spdm12_signing_context_with_hash[SPDM_VERSION_1_2_SIGNING_CONTEXT_SIZE]
+    1809                 :            :                             - spdm12_signing_context_with_hash),
+    1810                 :            :                          message_hash, hash_size);
+    1811                 :            : 
+    1812                 :            :         /* assign message and message_size for signing */
+    1813                 :          1 :         message = spdm12_signing_context_with_hash;
+    1814                 :          1 :         message_size = SPDM_VERSION_1_2_SIGNING_CONTEXT_SIZE + hash_size;
+    1815                 :            : 
+    1816         [ +  - ]:          1 :         if (need_hash) {
+    1817                 :          1 :             result = libspdm_hash_all(base_hash_algo, message, message_size,
+    1818                 :            :                                       full_message_hash);
+    1819         [ -  + ]:          1 :             if (!result) {
+    1820                 :          0 :                 return false;
+    1821                 :            :             }
+    1822                 :          1 :             return libspdm_asym_sign_wrap(context, hash_nid, req_base_asym_alg,
+    1823                 :            :                                           param, param_size,
+    1824                 :            :                                           full_message_hash, hash_size,
+    1825                 :            :                                           signature, sig_size);
+    1826                 :            :         } else {
+    1827                 :          0 :             return libspdm_asym_sign_wrap(context, hash_nid, req_base_asym_alg,
+    1828                 :            :                                           param, param_size,
+    1829                 :            :                                           message, message_size,
+    1830                 :            :                                           signature, sig_size);
+    1831                 :            :         }
+    1832                 :            : 
+    1833                 :            :         /* SPDM 1.2 signing done. */
+    1834                 :            :     }
+    1835                 :            : 
+    1836         [ +  - ]:          8 :     if (need_hash) {
+    1837                 :          8 :         return libspdm_asym_sign_wrap(context, hash_nid, req_base_asym_alg,
+    1838                 :            :                                       param, param_size,
+    1839                 :            :                                       message_hash, hash_size,
+    1840                 :            :                                       signature, sig_size);
+    1841                 :            :     } else {
+    1842                 :          0 :         LIBSPDM_ASSERT (false);
+    1843                 :          0 :         return false;
+    1844                 :            :     }
+    1845                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/libspdm_crypt_cert.c.func-sort-c.html b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_cert.c.func-sort-c.html new file mode 100644 index 00000000000..4aa7d3cf04c --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_cert.c.func-sort-c.html @@ -0,0 +1,189 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/libspdm_crypt_cert.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib - libspdm_crypt_cert.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:45164270.2 %
Date:2024-09-22 08:21:07Functions:252792.6 %
Branches:22638359.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_req_asym_get_public_key_from_x5090
libspdm_req_asym_get_public_key_from_x5090
libspdm_x509_set_cert_certificate_check_ex5
libspdm_get_dmtf_subject_alt_name6
libspdm_verify_cert_chain_data_ex6
libspdm_verify_certificate_chain_buffer_ex6
libspdm_get_dmtf_subject_alt_name_from_bytes9
libspdm_x509_set_cert_certificate_check9
libspdm_x509_certificate_check_ex13
libspdm_verify_set_cert_leaf_cert_basic_constraints14
libspdm_verify_req_info29
libspdm_verify_certificate_chain_buffer34
libspdm_is_root_certificate59
libspdm_get_leaf_cert_public_key_from_cert_chain205
libspdm_verify_cert_chain_data649
libspdm_x509_certificate_check703
libspdm_verify_leaf_cert_basic_constraints708
libspdm_verify_leaf_cert_spdm_extension720
libspdm_get_public_key_algo_OID724
libspdm_get_public_key_oid724
libspdm_verify_cert_subject_public_key_info724
libspdm_internal_x509_date_time_check728
libspdm_verify_leaf_cert_spdm_eku728
libspdm_x509_common_certificate_check730
libspdm_asym_get_public_key_from_x509933
libspdm_get_asym_get_public_key_from_x509933
libspdm_get_public_key_algo_OID_len1448
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/libspdm_crypt_cert.c.func.html b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_cert.c.func.html new file mode 100644 index 00000000000..eec3c375862 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_cert.c.func.html @@ -0,0 +1,189 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/libspdm_crypt_cert.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib - libspdm_crypt_cert.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:45164270.2 %
Date:2024-09-22 08:21:07Functions:252792.6 %
Branches:22638359.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_asym_get_public_key_from_x509933
libspdm_get_asym_get_public_key_from_x509933
libspdm_get_dmtf_subject_alt_name6
libspdm_get_dmtf_subject_alt_name_from_bytes9
libspdm_get_leaf_cert_public_key_from_cert_chain205
libspdm_get_public_key_algo_OID724
libspdm_get_public_key_algo_OID_len1448
libspdm_get_public_key_oid724
libspdm_get_req_asym_get_public_key_from_x5090
libspdm_internal_x509_date_time_check728
libspdm_is_root_certificate59
libspdm_req_asym_get_public_key_from_x5090
libspdm_verify_cert_chain_data649
libspdm_verify_cert_chain_data_ex6
libspdm_verify_cert_subject_public_key_info724
libspdm_verify_certificate_chain_buffer34
libspdm_verify_certificate_chain_buffer_ex6
libspdm_verify_leaf_cert_basic_constraints708
libspdm_verify_leaf_cert_spdm_eku728
libspdm_verify_leaf_cert_spdm_extension720
libspdm_verify_req_info29
libspdm_verify_set_cert_leaf_cert_basic_constraints14
libspdm_x509_certificate_check703
libspdm_x509_certificate_check_ex13
libspdm_x509_common_certificate_check730
libspdm_x509_set_cert_certificate_check9
libspdm_x509_set_cert_certificate_check_ex5
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/libspdm_crypt_cert.c.gcov.html b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_cert.c.gcov.html new file mode 100644 index 00000000000..fa47350af4c --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_cert.c.gcov.html @@ -0,0 +1,2125 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/libspdm_crypt_cert.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib - libspdm_crypt_cert.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:45164270.2 %
Date:2024-09-22 08:21:07Functions:252792.6 %
Branches:22638359.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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_crypt_lib.h"
+       8                 :            : 
+       9                 :            : #if LIBSPDM_CERT_PARSE_SUPPORT
+      10                 :            : 
+      11                 :            : /**pathLenConstraint is optional.
+      12                 :            :  * In https://www.pkisolutions.com/basic-constraints-certificate-extension/:
+      13                 :            :  * pathLenConstraint: How many CAs are allowed in the chain below current CA certificate.
+      14                 :            :  * This setting has no meaning for end entity certificates.
+      15                 :            :  **/
+      16                 :            : 
+      17                 :            : /**
+      18                 :            :  * leaf cert spdm extension len
+      19                 :            :  * len > 2 * (spdm id-DMTF-spdm size + 2)
+      20                 :            :  **/
+      21                 :            : 
+      22                 :            : #ifndef LIBSPDM_MAX_EXTENSION_LEN
+      23                 :            : #define LIBSPDM_MAX_EXTENSION_LEN 30
+      24                 :            : #endif
+      25                 :            : 
+      26                 :            : #ifndef LIBSPDM_MAX_NAME_SIZE
+      27                 :            : #define LIBSPDM_MAX_NAME_SIZE 100
+      28                 :            : #endif
+      29                 :            : 
+      30                 :            : /*max public key encryption algo oid len*/
+      31                 :            : #ifndef LIBSPDM_MAX_ENCRYPTION_ALGO_OID_LEN
+      32                 :            : #define LIBSPDM_MAX_ENCRYPTION_ALGO_OID_LEN 10
+      33                 :            : #endif
+      34                 :            : 
+      35                 :            : /*leaf cert basic constraints len,CA = false: 30 03 01 01 00*/
+      36                 :            : #ifndef LIBSPDM_MAX_BASIC_CONSTRAINTS_CA_LEN
+      37                 :            : #define LIBSPDM_MAX_BASIC_CONSTRAINTS_CA_LEN 5
+      38                 :            : #endif
+      39                 :            : 
+      40                 :            : /**
+      41                 :            :  * 0x02 is integer;
+      42                 :            :  * 0x82 indicates that the length is expressed in two bytes;
+      43                 :            :  * 0x01 and 0x01 are rsa key len;
+      44                 :            :  **/
+      45                 :            : #if (LIBSPDM_RSA_SSA_2048_SUPPORT) || (LIBSPDM_RSA_PSS_2048_SUPPORT)
+      46                 :            : #define KEY_ENCRY_ALGO_RSA2048_FLAG {0x02, 0x82, 0x01, 0x01}
+      47                 :            : /* the other case is ASN1 code different when integer is 1 on highest position*/
+      48                 :            : #define KEY_ENCRY_ALGO_RSA2048_FLAG_OTHER {0x02, 0x82, 0x01, 0x00}
+      49                 :            : #endif
+      50                 :            : #if (LIBSPDM_RSA_SSA_3072_SUPPORT) || (LIBSPDM_RSA_PSS_3072_SUPPORT)
+      51                 :            : #define KEY_ENCRY_ALGO_RSA3072_FLAG {0x02, 0x82, 0x01, 0x81}
+      52                 :            : /* the other case is ASN1 code different when integer is 1 on highest position*/
+      53                 :            : #define KEY_ENCRY_ALGO_RSA3072_FLAG_OTHER {0x02, 0x82, 0x01, 0x80}
+      54                 :            : #endif
+      55                 :            : #if (LIBSPDM_RSA_SSA_4096_SUPPORT) || (LIBSPDM_RSA_PSS_4096_SUPPORT)
+      56                 :            : #define KEY_ENCRY_ALGO_RSA4096_FLAG {0x02, 0x82, 0x02, 0x01}
+      57                 :            : /* the other case is ASN1 code different when integer is 1 on highest position*/
+      58                 :            : #define KEY_ENCRY_ALGO_RSA4096_FLAG_OTHER {0x02, 0x82, 0x02, 0x00}
+      59                 :            : #endif
+      60                 :            : 
+      61                 :            : /**
+      62                 :            :  * https://oidref.com/1.2.840.10045.3.1.7
+      63                 :            :  * ECC256 curve OID: 1.2.840.10045.3.1.7
+      64                 :            :  * https://oidref.com/1.3.132.0.34
+      65                 :            :  * ECC384 curve OID: 1.3.132.0.34
+      66                 :            :  * https://oidref.com/1.3.132.0.35
+      67                 :            :  * ECC521 curve OID: 1.3.132.0.35
+      68                 :            :  **/
+      69                 :            : #if LIBSPDM_ECDSA_P256_SUPPORT
+      70                 :            : #define KEY_ENCRY_ALGO_ECC256_OID {0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x07}
+      71                 :            : #endif
+      72                 :            : #if LIBSPDM_ECDSA_P384_SUPPORT
+      73                 :            : #define KEY_ENCRY_ALGO_ECC384_OID {0x2B, 0x81, 0x04, 0x00, 0x22}
+      74                 :            : #endif
+      75                 :            : #if LIBSPDM_ECDSA_P521_SUPPORT
+      76                 :            : #define KEY_ENCRY_ALGO_ECC521_OID {0x2B, 0x81, 0x04, 0x00, 0x23}
+      77                 :            : #endif
+      78                 :            : 
+      79                 :            : /**
+      80                 :            :  * EDxxx OID: https://datatracker.ietf.org/doc/html/rfc8420
+      81                 :            :  * ED448 OID: 1.3.101.113
+      82                 :            :  * ED25519 OID: 1.3.101.112
+      83                 :            :  **/
+      84                 :            : #if LIBSPDM_EDDSA_ED25519_SUPPORT
+      85                 :            : #define ENCRY_ALGO_ED25519_OID {0x2B, 0x65, 0x70}
+      86                 :            : #endif
+      87                 :            : #if LIBSPDM_EDDSA_ED448_SUPPORT
+      88                 :            : #define ENCRY_ALGO_ED448_OID {0x2B, 0x65, 0x71}
+      89                 :            : #endif
+      90                 :            : 
+      91                 :            : /*leaf cert basic_constraints false case1: CA: false and CA object is excluded */
+      92                 :            : #define BASIC_CONSTRAINTS_STRING_FALSE_CASE1 {0x30, 0x00}
+      93                 :            : 
+      94                 :            : /*leaf cert basic_constraints false case2: CA: false */
+      95                 :            : #define BASIC_CONSTRAINTS_STRING_FALSE_CASE2 {0x30, 0x03, 0x01, 0x01, 0x00}
+      96                 :            : 
+      97                 :            : /*leaf cert basic_constraints true case: CA: true */
+      98                 :            : #define BASIC_CONSTRAINTS_STRING_TRUE_CASE {0x30, 0x03, 0x01, 0x01, 0xFF}
+      99                 :            : 
+     100                 :            : /**
+     101                 :            :  * Retrieve the asymmetric public key from one DER-encoded X509 certificate.
+     102                 :            :  *
+     103                 :            :  * @param  cert       Pointer to the DER-encoded X509 certificate.
+     104                 :            :  * @param  cert_size  Size of the X509 certificate in bytes.
+     105                 :            :  * @param  context    Pointer to newly generated asymmetric context which contain the retrieved public
+     106                 :            :  *                    key component. Use libspdm_asym_free() function to free the resource.
+     107                 :            :  *
+     108                 :            :  * @retval  true   public key was retrieved successfully.
+     109                 :            :  * @retval  false  Fail to retrieve public key from X509 certificate.
+     110                 :            :  **/
+     111                 :            : typedef bool (*libspdm_asym_get_public_key_from_x509_func)(const uint8_t *cert,
+     112                 :            :                                                            size_t cert_size,
+     113                 :            :                                                            void **context);
+     114                 :            : 
+     115                 :            : /**
+     116                 :            :  * Return asymmetric GET_PUBLIC_KEY_FROM_X509 function, based upon the negotiated asymmetric algorithm.
+     117                 :            :  *
+     118                 :            :  * @param  base_asym_algo                 SPDM base_asym_algo
+     119                 :            :  *
+     120                 :            :  * @return asymmetric GET_PUBLIC_KEY_FROM_X509 function
+     121                 :            :  **/
+     122                 :            : libspdm_asym_get_public_key_from_x509_func
+     123                 :        933 : static libspdm_get_asym_get_public_key_from_x509(uint32_t base_asym_algo)
+     124                 :            : {
+     125   [ +  +  -  -  :        933 :     switch (base_asym_algo) {
+                      - ]
+     126                 :         65 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
+     127                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
+     128                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
+     129                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048:
+     130                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072:
+     131                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096:
+     132                 :            : #if (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT)
+     133                 :            : #if !LIBSPDM_RSA_SSA_2048_SUPPORT
+     134                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048);
+     135                 :            : #endif
+     136                 :            : #if !LIBSPDM_RSA_SSA_3072_SUPPORT
+     137                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072);
+     138                 :            : #endif
+     139                 :            : #if !LIBSPDM_RSA_SSA_4096_SUPPORT
+     140                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096);
+     141                 :            : #endif
+     142                 :            : #if !LIBSPDM_RSA_PSS_2048_SUPPORT
+     143                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048);
+     144                 :            : #endif
+     145                 :            : #if !LIBSPDM_RSA_PSS_3072_SUPPORT
+     146                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072);
+     147                 :            : #endif
+     148                 :            : #if !LIBSPDM_RSA_PSS_4096_SUPPORT
+     149                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096);
+     150                 :            : #endif
+     151                 :         65 :         return libspdm_rsa_get_public_key_from_x509;
+     152                 :            : #else
+     153                 :            :         LIBSPDM_ASSERT(false);
+     154                 :            :         break;
+     155                 :            : #endif
+     156                 :        868 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
+     157                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
+     158                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
+     159                 :            : #if LIBSPDM_ECDSA_SUPPORT
+     160                 :            : #if !LIBSPDM_ECDSA_P256_SUPPORT
+     161                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256);
+     162                 :            : #endif
+     163                 :            : #if !LIBSPDM_ECDSA_P384_SUPPORT
+     164                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384);
+     165                 :            : #endif
+     166                 :            : #if !LIBSPDM_ECDSA_P521_SUPPORT
+     167                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521);
+     168                 :            : #endif
+     169                 :        868 :         return libspdm_ec_get_public_key_from_x509;
+     170                 :            : #else
+     171                 :            :         LIBSPDM_ASSERT(false);
+     172                 :            :         break;
+     173                 :            : #endif
+     174                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
+     175                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
+     176                 :            : #if (LIBSPDM_EDDSA_ED25519_SUPPORT) || (LIBSPDM_EDDSA_ED448_SUPPORT)
+     177                 :            : #if !LIBSPDM_EDDSA_ED25519_SUPPORT
+     178                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519);
+     179                 :            : #endif
+     180                 :            : #if !LIBSPDM_EDDSA_ED448_SUPPORT
+     181                 :            :         LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448);
+     182                 :            : #endif
+     183                 :            :         return libspdm_ecd_get_public_key_from_x509;
+     184                 :            : #else
+     185                 :          0 :         LIBSPDM_ASSERT(false);
+     186                 :          0 :         break;
+     187                 :            : #endif
+     188                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256:
+     189                 :            : #if LIBSPDM_SM2_DSA_SUPPORT
+     190                 :            :         return libspdm_sm2_get_public_key_from_x509;
+     191                 :            : #else
+     192                 :          0 :         LIBSPDM_ASSERT(false);
+     193                 :          0 :         break;
+     194                 :            : #endif
+     195                 :          0 :     default:
+     196                 :          0 :         LIBSPDM_ASSERT(false);
+     197                 :          0 :         break;
+     198                 :            :     }
+     199                 :            : 
+     200                 :          0 :     return NULL;
+     201                 :            : }
+     202                 :            : 
+     203                 :            : /**
+     204                 :            :  * Retrieve the asymmetric public key from one DER-encoded X509 certificate,
+     205                 :            :  * based upon negotiated asymmetric algorithm.
+     206                 :            :  *
+     207                 :            :  * @param  base_asym_algo                 SPDM base_asym_algo
+     208                 :            :  * @param  cert                         Pointer to the DER-encoded X509 certificate.
+     209                 :            :  * @param  cert_size                     size of the X509 certificate in bytes.
+     210                 :            :  * @param  context                      Pointer to newly generated asymmetric context which contain the retrieved public key component.
+     211                 :            :  *                                     Use libspdm_asym_free() function to free the resource.
+     212                 :            :  *
+     213                 :            :  * @retval  true   public key was retrieved successfully.
+     214                 :            :  * @retval  false  Fail to retrieve public key from X509 certificate.
+     215                 :            :  **/
+     216                 :        933 : bool libspdm_asym_get_public_key_from_x509(uint32_t base_asym_algo,
+     217                 :            :                                            const uint8_t *cert,
+     218                 :            :                                            size_t cert_size,
+     219                 :            :                                            void **context)
+     220                 :            : {
+     221                 :            :     libspdm_asym_get_public_key_from_x509_func get_public_key_from_x509_function;
+     222                 :        933 :     get_public_key_from_x509_function = libspdm_get_asym_get_public_key_from_x509(base_asym_algo);
+     223         [ -  + ]:        933 :     if (get_public_key_from_x509_function == NULL) {
+     224                 :          0 :         return false;
+     225                 :            :     }
+     226                 :        933 :     return get_public_key_from_x509_function(cert, cert_size, context);
+     227                 :            : }
+     228                 :            : 
+     229                 :            : /**
+     230                 :            :  * Return requester asymmetric GET_PUBLIC_KEY_FROM_X509 function, based upon the negotiated requester asymmetric algorithm.
+     231                 :            :  *
+     232                 :            :  * @param  req_base_asym_alg               SPDM req_base_asym_alg
+     233                 :            :  *
+     234                 :            :  * @return requester asymmetric GET_PUBLIC_KEY_FROM_X509 function
+     235                 :            :  **/
+     236                 :            : static libspdm_asym_get_public_key_from_x509_func
+     237                 :          0 : libspdm_get_req_asym_get_public_key_from_x509(uint16_t req_base_asym_alg)
+     238                 :            : {
+     239                 :          0 :     return libspdm_get_asym_get_public_key_from_x509(req_base_asym_alg);
+     240                 :            : }
+     241                 :            : 
+     242                 :            : /**
+     243                 :            :  * Retrieve the asymmetric public key from one DER-encoded X509 certificate,
+     244                 :            :  * based upon negotiated requester asymmetric algorithm.
+     245                 :            :  *
+     246                 :            :  * @param  req_base_asym_alg               SPDM req_base_asym_alg
+     247                 :            :  * @param  cert                         Pointer to the DER-encoded X509 certificate.
+     248                 :            :  * @param  cert_size                     size of the X509 certificate in bytes.
+     249                 :            :  * @param  context                      Pointer to newly generated asymmetric context which contain the retrieved public key component.
+     250                 :            :  *                                     Use libspdm_asym_free() function to free the resource.
+     251                 :            :  *
+     252                 :            :  * @retval  true   public key was retrieved successfully.
+     253                 :            :  * @retval  false  Fail to retrieve public key from X509 certificate.
+     254                 :            :  **/
+     255                 :          0 : bool libspdm_req_asym_get_public_key_from_x509(uint16_t req_base_asym_alg,
+     256                 :            :                                                const uint8_t *cert,
+     257                 :            :                                                size_t cert_size,
+     258                 :            :                                                void **context)
+     259                 :            : {
+     260                 :            :     libspdm_asym_get_public_key_from_x509_func get_public_key_from_x509_function;
+     261                 :            :     get_public_key_from_x509_function =
+     262                 :          0 :         libspdm_get_req_asym_get_public_key_from_x509(req_base_asym_alg);
+     263         [ #  # ]:          0 :     if (get_public_key_from_x509_function == NULL) {
+     264                 :          0 :         return false;
+     265                 :            :     }
+     266                 :          0 :     return get_public_key_from_x509_function(cert, cert_size, context);
+     267                 :            : }
+     268                 :            : 
+     269                 :            : /**
+     270                 :            :  * Check the X509 DataTime is within a valid range.
+     271                 :            :  *
+     272                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     273                 :            :  * @param  from                         notBefore Pointer to date_time object.
+     274                 :            :  * @param  from_size                     notBefore date_time object size.
+     275                 :            :  * @param  to                           notAfter Pointer to date_time object.
+     276                 :            :  * @param  to_size                       notAfter date_time object size.
+     277                 :            :  *
+     278                 :            :  * @retval  true   verification pass.
+     279                 :            :  * @retval  false  verification fail.
+     280                 :            :  **/
+     281                 :        728 : static bool libspdm_internal_x509_date_time_check(const uint8_t *from,
+     282                 :            :                                                   size_t from_size,
+     283                 :            :                                                   const uint8_t *to,
+     284                 :            :                                                   size_t to_size)
+     285                 :            : {
+     286                 :            :     int32_t ret;
+     287                 :            :     bool status;
+     288                 :            :     uint8_t f0[64];
+     289                 :            :     uint8_t t0[64];
+     290                 :            :     size_t f0_size;
+     291                 :            :     size_t t0_size;
+     292                 :            : 
+     293                 :        728 :     f0_size = 64;
+     294                 :        728 :     t0_size = 64;
+     295                 :            : 
+     296                 :        728 :     status = libspdm_x509_set_date_time("19700101000000Z", f0, &f0_size);
+     297         [ -  + ]:        728 :     if (!status) {
+     298                 :          0 :         return false;
+     299                 :            :     }
+     300                 :            : 
+     301                 :        728 :     status = libspdm_x509_set_date_time("99991231235959Z", t0, &t0_size);
+     302         [ -  + ]:        728 :     if (!status) {
+     303                 :          0 :         return false;
+     304                 :            :     }
+     305                 :            : 
+     306                 :            :     /* from >= f0*/
+     307                 :        728 :     ret = libspdm_x509_compare_date_time(from, f0);
+     308         [ -  + ]:        728 :     if (ret < 0) {
+     309                 :          0 :         return false;
+     310                 :            :     }
+     311                 :            : 
+     312                 :            :     /* to <= t0*/
+     313                 :        728 :     ret = libspdm_x509_compare_date_time(t0, to);
+     314         [ -  + ]:        728 :     if (ret < 0) {
+     315                 :          0 :         return false;
+     316                 :            :     }
+     317                 :            : 
+     318                 :        728 :     return true;
+     319                 :            : }
+     320                 :            : 
+     321                 :            : /**
+     322                 :            :  * This function returns the SPDM public key encryption algorithm OID len.
+     323                 :            :  *
+     324                 :            :  * @param[in]  base_asym_algo          SPDM base_asym_algo
+     325                 :            :  *
+     326                 :            :  * @return SPDM public key encryption algorithms OID len.
+     327                 :            :  **/
+     328                 :       1448 : static uint32_t libspdm_get_public_key_algo_OID_len(uint32_t base_asym_algo)
+     329                 :            : {
+     330   [ +  -  +  -  :       1448 :     switch (base_asym_algo) {
+          +  -  +  +  +  
+                -  -  - ]
+     331                 :         92 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
+     332                 :            : #if LIBSPDM_RSA_SSA_2048_SUPPORT
+     333                 :         92 :         return 4;
+     334                 :            : #else
+     335                 :            :         return 0;
+     336                 :            : #endif
+     337                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048:
+     338                 :            : #if LIBSPDM_RSA_PSS_2048_SUPPORT
+     339                 :          0 :         return 4;
+     340                 :            : #else
+     341                 :            :         return 0;
+     342                 :            : #endif
+     343                 :          6 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
+     344                 :            : #if LIBSPDM_RSA_SSA_3072_SUPPORT
+     345                 :          6 :         return 4;
+     346                 :            : #else
+     347                 :            :         return 0;
+     348                 :            : #endif
+     349                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072:
+     350                 :            : #if LIBSPDM_RSA_PSS_3072_SUPPORT
+     351                 :          0 :         return 4;
+     352                 :            : #else
+     353                 :            :         return 0;
+     354                 :            : #endif
+     355                 :          4 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
+     356                 :            : #if LIBSPDM_RSA_SSA_4096_SUPPORT
+     357                 :          4 :         return 4;
+     358                 :            : #else
+     359                 :            :         return 0;
+     360                 :            : #endif
+     361                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096:
+     362                 :            : #if LIBSPDM_RSA_PSS_4096_SUPPORT
+     363                 :          0 :         return 4;
+     364                 :            : #else
+     365                 :            :         return 0;
+     366                 :            : #endif
+     367                 :       1342 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
+     368                 :            : #if LIBSPDM_ECDSA_P256_SUPPORT
+     369                 :       1342 :         return 8;
+     370                 :            : #else
+     371                 :            :         return 0;
+     372                 :            : #endif
+     373                 :          2 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
+     374                 :            : #if LIBSPDM_ECDSA_P384_SUPPORT
+     375                 :          2 :         return 5;
+     376                 :            : #else
+     377                 :            :         return 0;
+     378                 :            : #endif
+     379                 :          2 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
+     380                 :            : #if LIBSPDM_ECDSA_P521_SUPPORT
+     381                 :          2 :         return 5;
+     382                 :            : #else
+     383                 :            :         return 0;
+     384                 :            : #endif
+     385                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
+     386                 :            : #if LIBSPDM_EDDSA_ED25519_SUPPORT
+     387                 :            :         return 3;
+     388                 :            : #else
+     389                 :          0 :         return 0;
+     390                 :            : #endif
+     391                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
+     392                 :            : #if LIBSPDM_EDDSA_ED448_SUPPORT
+     393                 :            :         return 3;
+     394                 :            : #else
+     395                 :          0 :         return 0;
+     396                 :            : #endif
+     397                 :          0 :     default:
+     398                 :          0 :         LIBSPDM_ASSERT(false);
+     399                 :          0 :         return 0;
+     400                 :            :     }
+     401                 :            : }
+     402                 :            : 
+     403                 :            : /**
+     404                 :            :  * This function get the SPDM public key encryption algorithm OID.
+     405                 :            :  *
+     406                 :            :  * @param[in]      base_asym_algo                 SPDM base_asym_algo
+     407                 :            :  * @param[in,out]  oid                            SPDM public key encryption algorithm OID
+     408                 :            :  * @param[in,out]  oid_other                      Other SPDM public key encryption algorithm OID
+     409                 :            :  *                                                because of ASN1 code for integer
+     410                 :            :  *
+     411                 :            :  * @retval  true   get OID sucessful.
+     412                 :            :  * @retval  false  get OID fail.
+     413                 :            :  **/
+     414                 :        724 : static bool libspdm_get_public_key_algo_OID(uint32_t base_asym_algo, uint8_t *oid,
+     415                 :            :                                             uint8_t *oid_other)
+     416                 :            : {
+     417                 :            :     uint32_t oid_len;
+     418                 :        724 :     oid_len = libspdm_get_public_key_algo_OID_len(base_asym_algo);
+     419         [ -  + ]:        724 :     if(oid_len == 0) {
+     420                 :          0 :         return false;
+     421                 :            :     }
+     422                 :            : 
+     423   [ +  +  +  +  :        724 :     switch (base_asym_algo) {
+          +  +  -  -  -  
+                      - ]
+     424                 :         46 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
+     425                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048: {
+     426                 :            : #if (LIBSPDM_RSA_SSA_2048_SUPPORT) || (LIBSPDM_RSA_PSS_2048_SUPPORT)
+     427                 :         46 :         uint8_t encry_algo_oid_rsa2048[] = KEY_ENCRY_ALGO_RSA2048_FLAG;
+     428                 :         46 :         uint8_t encry_algo_oid_rsa2048_ohter[] = KEY_ENCRY_ALGO_RSA2048_FLAG_OTHER;
+     429                 :         46 :         libspdm_copy_mem(oid, oid_len, encry_algo_oid_rsa2048, oid_len);
+     430                 :         46 :         libspdm_copy_mem(oid_other, oid_len, encry_algo_oid_rsa2048_ohter, oid_len);
+     431                 :         46 :         return true;
+     432                 :            : #else
+     433                 :            :         return false;
+     434                 :            : #endif
+     435                 :            :     }
+     436                 :          3 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
+     437                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072: {
+     438                 :            : #if (LIBSPDM_RSA_SSA_3072_SUPPORT) || (LIBSPDM_RSA_PSS_3072_SUPPORT)
+     439                 :          3 :         uint8_t encry_algo_oid_rsa3072[] = KEY_ENCRY_ALGO_RSA3072_FLAG;
+     440                 :          3 :         uint8_t encry_algo_oid_rsa3072_ohter[] = KEY_ENCRY_ALGO_RSA3072_FLAG_OTHER;
+     441                 :          3 :         libspdm_copy_mem(oid, oid_len, encry_algo_oid_rsa3072, oid_len);
+     442                 :          3 :         libspdm_copy_mem(oid_other, oid_len, encry_algo_oid_rsa3072_ohter, oid_len);
+     443                 :          3 :         return true;
+     444                 :            : #else
+     445                 :            :         return false;
+     446                 :            : #endif
+     447                 :            :     }
+     448                 :          2 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
+     449                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096: {
+     450                 :            : #if (LIBSPDM_RSA_SSA_4096_SUPPORT) || (LIBSPDM_RSA_PSS_4096_SUPPORT)
+     451                 :          2 :         uint8_t encry_algo_oid_rsa4096[] = KEY_ENCRY_ALGO_RSA4096_FLAG;
+     452                 :          2 :         uint8_t encry_algo_oid_rsa4096_ohter[] = KEY_ENCRY_ALGO_RSA4096_FLAG_OTHER;
+     453                 :          2 :         libspdm_copy_mem(oid, oid_len, encry_algo_oid_rsa4096, oid_len);
+     454                 :          2 :         libspdm_copy_mem(oid_other, oid_len, encry_algo_oid_rsa4096_ohter, oid_len);
+     455                 :          2 :         return true;
+     456                 :            : #else
+     457                 :            :         return false;
+     458                 :            : #endif
+     459                 :            :     }
+     460                 :            : 
+     461                 :        671 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256: {
+     462                 :            : #if LIBSPDM_ECDSA_P256_SUPPORT
+     463                 :        671 :         uint8_t encry_algo_oid_ecc256[] = KEY_ENCRY_ALGO_ECC256_OID;
+     464                 :        671 :         libspdm_copy_mem(oid, oid_len, encry_algo_oid_ecc256, oid_len);
+     465                 :        671 :         return true;
+     466                 :            : #else
+     467                 :            :         return false;
+     468                 :            : #endif
+     469                 :            :     }
+     470                 :          1 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384: {
+     471                 :            : #if LIBSPDM_ECDSA_P384_SUPPORT
+     472                 :          1 :         uint8_t encry_algo_oid_ecc384[] = KEY_ENCRY_ALGO_ECC384_OID;
+     473                 :          1 :         libspdm_copy_mem(oid, oid_len, encry_algo_oid_ecc384, oid_len);
+     474                 :          1 :         return true;
+     475                 :            : #else
+     476                 :            :         return false;
+     477                 :            : #endif
+     478                 :            :     }
+     479                 :          1 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521: {
+     480                 :            : #if LIBSPDM_ECDSA_P521_SUPPORT
+     481                 :          1 :         uint8_t encry_algo_oid_ecc521[] = KEY_ENCRY_ALGO_ECC521_OID;
+     482                 :          1 :         libspdm_copy_mem(oid, oid_len, encry_algo_oid_ecc521, oid_len);
+     483                 :          1 :         return true;
+     484                 :            : #else
+     485                 :            :         return false;
+     486                 :            : #endif
+     487                 :            :     }
+     488                 :            : 
+     489                 :            :     /*sm2 oid  TBD*/
+     490                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256:
+     491                 :          0 :         return true;
+     492                 :            : 
+     493                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519: {
+     494                 :            : #if LIBSPDM_EDDSA_ED25519_SUPPORT
+     495                 :            :         uint8_t encry_algo_oid_ed25519[] = ENCRY_ALGO_ED25519_OID;
+     496                 :            :         libspdm_copy_mem(oid, oid_len, encry_algo_oid_ed25519, oid_len);
+     497                 :            :         return true;
+     498                 :            : #else
+     499                 :          0 :         return false;
+     500                 :            : #endif
+     501                 :            :         break;
+     502                 :            :     }
+     503                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448: {
+     504                 :            : #if LIBSPDM_EDDSA_ED448_SUPPORT
+     505                 :            :         uint8_t encry_algo_oid_ed448[] = ENCRY_ALGO_ED448_OID;
+     506                 :            :         libspdm_copy_mem(oid, oid_len, encry_algo_oid_ed448, oid_len);
+     507                 :            :         return true;
+     508                 :            : #else
+     509                 :          0 :         return false;
+     510                 :            : #endif
+     511                 :            :         break;
+     512                 :            :     }
+     513                 :            : 
+     514                 :          0 :     default:
+     515                 :          0 :         LIBSPDM_ASSERT(false);
+     516                 :          0 :         return false;
+     517                 :            :     }
+     518                 :            : }
+     519                 :            : 
+     520                 :            : /**
+     521                 :            :  * Verify cert public key encryption algorithm is matched to negotiated base_aysm algo
+     522                 :            :  *
+     523                 :            :  * @param[in]      cert                  Pointer to the DER-encoded certificate data.
+     524                 :            :  * @param[in]      cert_size             The size of certificate data in bytes.
+     525                 :            :  * @param[in]      base_asym_algo        SPDM base_asym_algo
+     526                 :            :  * @param[out]     oid                   cert public key encryption algorithm OID
+     527                 :            :  * @param[in]      oid_size              the buffer size for required OID
+     528                 :            :  *
+     529                 :            :  * @retval  true   get public key oid from cert successfully
+     530                 :            :  * @retval  false  get public key oid from cert fail
+     531                 :            :  **/
+     532                 :        724 : static bool libspdm_get_public_key_oid(const uint8_t *cert, size_t cert_size,
+     533                 :            :                                        uint8_t *oid, size_t oid_size, uint32_t base_asym_algo)
+     534                 :            : {
+     535                 :            :     bool ret;
+     536                 :            :     uint8_t *ptr;
+     537                 :            :     int32_t length;
+     538                 :            :     size_t obj_len;
+     539                 :            :     uint8_t *end;
+     540                 :            :     uint8_t index;
+     541                 :            :     uint8_t sequence_time;
+     542                 :            : 
+     543                 :        724 :     length = (int32_t)cert_size;
+     544                 :        724 :     ptr = (uint8_t*)(size_t)cert;
+     545                 :        724 :     obj_len = 0;
+     546                 :        724 :     end = ptr + length;
+     547                 :        724 :     ret = true;
+     548                 :            : 
+     549                 :            :     /* TBSCertificate have 5 sequence before subjectPublicKeyInfo*/
+     550                 :        724 :     sequence_time = 5;
+     551                 :            : 
+     552                 :            :     /*all cert sequence*/
+     553                 :        724 :     ret = libspdm_asn1_get_tag(&ptr, end, &obj_len,
+     554                 :            :                                LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
+     555         [ -  + ]:        724 :     if (!ret) {
+     556                 :          0 :         return false;
+     557                 :            :     }
+     558                 :            : 
+     559                 :            :     /*TBSCertificate sequence*/
+     560                 :        724 :     ret = libspdm_asn1_get_tag(&ptr, end, &obj_len,
+     561                 :            :                                LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
+     562         [ -  + ]:        724 :     if (!ret) {
+     563                 :          0 :         return false;
+     564                 :            :     }
+     565                 :            : 
+     566                 :        724 :     end = ptr + obj_len;
+     567                 :            :     /*version*/
+     568                 :        724 :     ret = libspdm_asn1_get_tag(&ptr, end, &obj_len,
+     569                 :            :                                LIBSPDM_CRYPTO_ASN1_CONTEXT_SPECIFIC |
+     570                 :            :                                LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
+     571         [ -  + ]:        724 :     if (!ret) {
+     572                 :          0 :         return false;
+     573                 :            :     }
+     574                 :            : 
+     575                 :        724 :     ptr += obj_len;
+     576                 :            :     /*serialNumber*/
+     577                 :        724 :     ret = libspdm_asn1_get_tag(&ptr, end, &obj_len, LIBSPDM_CRYPTO_ASN1_INTEGER);
+     578         [ -  + ]:        724 :     if (!ret) {
+     579                 :          0 :         return false;
+     580                 :            :     }
+     581                 :            : 
+     582                 :            :     /**
+     583                 :            :      * signature AlgorithmIdentifier,
+     584                 :            :      * issuer Name,
+     585                 :            :      * validity Validity,
+     586                 :            :      * subject Name,
+     587                 :            :      * subjectPublicKeyInfo
+     588                 :            :      **/
+     589         [ +  + ]:       4344 :     for (index = 0; index < sequence_time; index++) {
+     590                 :       3620 :         ptr += obj_len;
+     591                 :       3620 :         ret = libspdm_asn1_get_tag(&ptr, end, &obj_len,
+     592                 :            :                                    LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
+     593         [ -  + ]:       3620 :         if (!ret) {
+     594                 :          0 :             return false;
+     595                 :            :         }
+     596                 :            :     }
+     597                 :            : 
+     598   [ +  +  -  - ]:        724 :     switch (base_asym_algo)
+     599                 :            :     {
+     600                 :         51 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
+     601                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048:
+     602                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
+     603                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072:
+     604                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
+     605                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096:
+     606                 :         51 :         ret = libspdm_asn1_get_tag(&ptr, end, &obj_len,
+     607                 :            :                                    LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
+     608         [ -  + ]:         51 :         if (!ret) {
+     609                 :          0 :             return false;
+     610                 :            :         }
+     611                 :            : 
+     612                 :         51 :         ptr += obj_len;
+     613                 :         51 :         ret = libspdm_asn1_get_tag(&ptr, end, &obj_len, LIBSPDM_CRYPTO_ASN1_BIT_STRING);
+     614         [ -  + ]:         51 :         if (!ret) {
+     615                 :          0 :             return false;
+     616                 :            :         }
+     617                 :            : 
+     618                 :            :         /*get rsa key len*/
+     619                 :         51 :         ptr++;
+     620                 :         51 :         ret = libspdm_asn1_get_tag(&ptr, end, &obj_len,
+     621                 :            :                                    LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
+     622         [ +  + ]:         51 :         if (!ret) {
+     623                 :          1 :             return false;
+     624                 :            :         }
+     625                 :         50 :         libspdm_copy_mem(oid, oid_size, ptr, oid_size);
+     626                 :         50 :         break;
+     627                 :        673 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
+     628                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
+     629                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
+     630                 :        673 :         ret = libspdm_asn1_get_tag(&ptr, end, &obj_len,
+     631                 :            :                                    LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
+     632         [ -  + ]:        673 :         if (!ret) {
+     633                 :          0 :             return false;
+     634                 :            :         }
+     635                 :        673 :         ret = libspdm_asn1_get_tag(&ptr, end, &obj_len, LIBSPDM_CRYPTO_ASN1_OID);
+     636         [ -  + ]:        673 :         if (!ret) {
+     637                 :          0 :             return false;
+     638                 :            :         }
+     639                 :            : 
+     640                 :            :         /*get ecc second oid*/
+     641                 :        673 :         ptr +=obj_len;
+     642                 :        673 :         ret = libspdm_asn1_get_tag(&ptr, end, &obj_len, LIBSPDM_CRYPTO_ASN1_OID);
+     643         [ -  + ]:        673 :         if (!ret) {
+     644                 :          0 :             return false;
+     645                 :            :         }
+     646                 :            : 
+     647         [ -  + ]:        673 :         if (oid_size != obj_len) {
+     648                 :          0 :             return false;
+     649                 :            :         }
+     650                 :            : 
+     651                 :        673 :         libspdm_copy_mem(oid, oid_size, ptr, obj_len);
+     652                 :        673 :         break;
+     653                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
+     654                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
+     655                 :          0 :         ret = libspdm_asn1_get_tag(&ptr, end, &obj_len,
+     656                 :            :                                    LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
+     657         [ #  # ]:          0 :         if (!ret) {
+     658                 :          0 :             return false;
+     659                 :            :         }
+     660                 :            : 
+     661                 :            :         /*get eddsa oid*/
+     662                 :          0 :         ret = libspdm_asn1_get_tag(&ptr, end, &obj_len, LIBSPDM_CRYPTO_ASN1_OID);
+     663         [ #  # ]:          0 :         if (!ret) {
+     664                 :          0 :             return false;
+     665                 :            :         }
+     666                 :            : 
+     667         [ #  # ]:          0 :         if (oid_size != obj_len) {
+     668                 :          0 :             return false;
+     669                 :            :         }
+     670                 :            : 
+     671                 :          0 :         libspdm_copy_mem(oid, oid_size, ptr, obj_len);
+     672                 :          0 :         break;
+     673                 :          0 :     default:
+     674                 :          0 :         LIBSPDM_ASSERT(false);
+     675                 :          0 :         return false;
+     676                 :            :     }
+     677                 :            : 
+     678                 :        723 :     return true;
+     679                 :            : }
+     680                 :            : 
+     681                 :            : /**
+     682                 :            :  * Verify cert public key encryption algorithm is matched to negotiated base_aysm algo
+     683                 :            :  *
+     684                 :            :  * @param[in]  cert                  Pointer to the DER-encoded certificate data.
+     685                 :            :  * @param[in]  cert_size             The size of certificate data in bytes.
+     686                 :            :  * @param[in]  base_asym_algo        SPDM base_asym_algo
+     687                 :            :  *
+     688                 :            :  * @retval  true   verify pass
+     689                 :            :  * @retval  false  verify fail
+     690                 :            :  **/
+     691                 :        724 : static bool libspdm_verify_cert_subject_public_key_info(const uint8_t *cert, size_t cert_size,
+     692                 :            :                                                         uint32_t base_asym_algo)
+     693                 :            : {
+     694                 :            :     size_t oid_len;
+     695                 :            :     bool status;
+     696                 :            : 
+     697                 :            :     /*public key encrypt algo OID from cert*/
+     698                 :            :     uint8_t cert_public_key_crypt_algo_oid[LIBSPDM_MAX_ENCRYPTION_ALGO_OID_LEN];
+     699                 :            :     /*public key encrypt algo OID from libspdm stored*/
+     700                 :            :     uint8_t libspdm_public_key_crypt_algo_oid[LIBSPDM_MAX_ENCRYPTION_ALGO_OID_LEN];
+     701                 :            :     uint8_t libspdm_public_key_crypt_algo_oid_other[LIBSPDM_MAX_ENCRYPTION_ALGO_OID_LEN];
+     702                 :            : 
+     703                 :        724 :     libspdm_zero_mem(libspdm_public_key_crypt_algo_oid, LIBSPDM_MAX_ENCRYPTION_ALGO_OID_LEN);
+     704                 :        724 :     libspdm_zero_mem(libspdm_public_key_crypt_algo_oid_other, LIBSPDM_MAX_ENCRYPTION_ALGO_OID_LEN);
+     705                 :            : 
+     706                 :            :     /*work around: skip the sm2*/
+     707         [ -  + ]:        724 :     if (base_asym_algo == SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256) {
+     708                 :          0 :         return true;
+     709                 :            :     }
+     710                 :            : 
+     711                 :        724 :     oid_len = libspdm_get_public_key_algo_OID_len(base_asym_algo);
+     712         [ -  + ]:        724 :     if(oid_len == 0) {
+     713                 :          0 :         return false;
+     714                 :            :     }
+     715                 :            :     /*get public key encrypt algo OID from libspdm stored*/
+     716                 :        724 :     status = libspdm_get_public_key_algo_OID(base_asym_algo,
+     717                 :            :                                              libspdm_public_key_crypt_algo_oid,
+     718                 :            :                                              libspdm_public_key_crypt_algo_oid_other);
+     719         [ -  + ]:        724 :     if (!status) {
+     720                 :          0 :         return status;
+     721                 :            :     }
+     722                 :            : 
+     723                 :            :     /*get public key encrypt algo OID from cert*/
+     724                 :        724 :     status = libspdm_get_public_key_oid(cert, cert_size, cert_public_key_crypt_algo_oid, oid_len,
+     725                 :            :                                         base_asym_algo);
+     726   [ +  +  +  + ]:        724 :     if (!status || (!libspdm_consttime_is_mem_equal(cert_public_key_crypt_algo_oid,
+     727                 :          1 :                                                     libspdm_public_key_crypt_algo_oid, oid_len) &&
+     728         [ +  - ]:          1 :                     !libspdm_consttime_is_mem_equal(cert_public_key_crypt_algo_oid,
+     729                 :            :                                                     libspdm_public_key_crypt_algo_oid_other,
+     730                 :            :                                                     oid_len))) {
+     731                 :          2 :         return false;
+     732                 :            :     }
+     733                 :            : 
+     734                 :        722 :     return status;
+     735                 :            : }
+     736                 :            : 
+     737                 :            : /**
+     738                 :            :  * Verify leaf cert basic_constraints CA is false
+     739                 :            :  *
+     740                 :            :  * @param[in]  cert                  Pointer to the DER-encoded certificate data.
+     741                 :            :  * @param[in]  cert_size             The size of certificate data in bytes.
+     742                 :            :  * @param[in]  need_basic_constraints  This value indicates whether basic_constraints must be present in the Cert
+     743                 :            :  *
+     744                 :            :  * @retval  true   verify pass,two case: 1.basic constraints is not present in cert, when need_basic_constraints is false;
+     745                 :            :  *                                       2. cert basic_constraints CA is false;
+     746                 :            :  * @retval  false  verify fail
+     747                 :            :  **/
+     748                 :        708 : static bool libspdm_verify_leaf_cert_basic_constraints(const uint8_t *cert, size_t cert_size,
+     749                 :            :                                                        bool need_basic_constraints)
+     750                 :            : {
+     751                 :            :     bool status;
+     752                 :            :     /*basic_constraints from cert*/
+     753                 :            :     uint8_t cert_basic_constraints[LIBSPDM_MAX_BASIC_CONSTRAINTS_CA_LEN];
+     754                 :            :     size_t len;
+     755                 :            : 
+     756                 :        708 :     uint8_t basic_constraints_false_case1[] = BASIC_CONSTRAINTS_STRING_FALSE_CASE1;
+     757                 :        708 :     uint8_t basic_constraints_false_case2[] = BASIC_CONSTRAINTS_STRING_FALSE_CASE2;
+     758                 :            : 
+     759                 :        708 :     len = LIBSPDM_MAX_BASIC_CONSTRAINTS_CA_LEN;
+     760                 :            : 
+     761                 :        708 :     status = libspdm_x509_get_extended_basic_constraints(cert, cert_size,
+     762                 :            :                                                          cert_basic_constraints, &len);
+     763         [ -  + ]:        708 :     if (!status) {
+     764                 :          0 :         return false;
+     765         [ +  + ]:        708 :     } else if (len == 0) {
+     766                 :            :         /* basic constraints is not present in cert */
+     767         [ +  + ]:          2 :         if (need_basic_constraints) {
+     768                 :          1 :             return false;
+     769                 :            :         } else {
+     770                 :          1 :             return true;
+     771                 :            :         }
+     772                 :            :     }
+     773                 :            : 
+     774   [ +  +  +  - ]:       1410 :     if ((len == sizeof(basic_constraints_false_case1)) &&
+     775                 :        704 :         (libspdm_consttime_is_mem_equal(cert_basic_constraints,
+     776                 :            :                                         basic_constraints_false_case1,
+     777                 :            :                                         sizeof(basic_constraints_false_case1)))) {
+     778                 :        704 :         return true;
+     779                 :            :     }
+     780                 :            : 
+     781   [ +  -  -  + ]:          4 :     if ((len == sizeof(basic_constraints_false_case2)) &&
+     782                 :          2 :         (libspdm_consttime_is_mem_equal(cert_basic_constraints,
+     783                 :            :                                         basic_constraints_false_case2,
+     784                 :            :                                         sizeof(basic_constraints_false_case2)))) {
+     785                 :          0 :         return true;
+     786                 :            :     }
+     787                 :            : 
+     788                 :          2 :     return false;
+     789                 :            : }
+     790                 :            : 
+     791                 :            : /**
+     792                 :            :  * Verify leaf cert basic_constraints CA is false
+     793                 :            :  *
+     794                 :            :  * @param[in]  cert                  Pointer to the DER-encoded certificate data.
+     795                 :            :  * @param[in]  cert_size             The size of certificate data in bytes.
+     796                 :            :  *
+     797                 :            :  * @retval  true   verify pass,two case: 1.basic constraints is not present in cert;
+     798                 :            :  *                                       2. cert basic_constraints CA is false;
+     799                 :            :  * @retval  false  verify fail
+     800                 :            :  **/
+     801                 :         14 : static bool libspdm_verify_set_cert_leaf_cert_basic_constraints(
+     802                 :            :     const uint8_t *cert, size_t cert_size, uint8_t cert_model)
+     803                 :            : {
+     804                 :            :     bool status;
+     805                 :            :     /*basic_constraints from cert*/
+     806                 :            :     uint8_t cert_basic_constraints[LIBSPDM_MAX_BASIC_CONSTRAINTS_CA_LEN];
+     807                 :            :     size_t len;
+     808                 :            : 
+     809                 :         14 :     uint8_t basic_constraints_false_case1[] = BASIC_CONSTRAINTS_STRING_FALSE_CASE1;
+     810                 :         14 :     uint8_t basic_constraints_false_case2[] = BASIC_CONSTRAINTS_STRING_FALSE_CASE2;
+     811                 :         14 :     uint8_t basic_constraints_true_case[] = BASIC_CONSTRAINTS_STRING_TRUE_CASE;
+     812                 :            : 
+     813                 :         14 :     len = LIBSPDM_MAX_BASIC_CONSTRAINTS_CA_LEN;
+     814                 :            : 
+     815                 :         14 :     status = libspdm_x509_get_extended_basic_constraints(cert, cert_size,
+     816                 :            :                                                          cert_basic_constraints, &len);
+     817         [ +  + ]:         14 :     if (cert_model == SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT) {
+     818                 :            :         /*device cert model*/
+     819         [ -  + ]:          8 :         if (!status) {
+     820                 :          0 :             return false;
+     821         [ -  + ]:          8 :         } else if (len == 0) {
+     822                 :            :             /* basic constraints is not present in cert */
+     823                 :          0 :             return true;
+     824                 :            :         }
+     825                 :            : 
+     826   [ +  -  +  - ]:         16 :         if ((len == sizeof(basic_constraints_false_case1)) &&
+     827                 :          8 :             (libspdm_consttime_is_mem_equal(cert_basic_constraints,
+     828                 :            :                                             basic_constraints_false_case1,
+     829                 :            :                                             sizeof(basic_constraints_false_case1)))) {
+     830                 :          8 :             return true;
+     831                 :            :         }
+     832                 :            : 
+     833   [ #  #  #  # ]:          0 :         if ((len == sizeof(basic_constraints_false_case2)) &&
+     834                 :          0 :             (libspdm_consttime_is_mem_equal(cert_basic_constraints,
+     835                 :            :                                             basic_constraints_false_case2,
+     836                 :            :                                             sizeof(basic_constraints_false_case2)))) {
+     837                 :          0 :             return true;
+     838                 :            :         }
+     839                 :            :     } else {
+     840                 :            :         /*alias cert model*/
+     841   [ +  -  +  +  :         10 :         if (status && (len == sizeof(basic_constraints_true_case)) &&
+                   +  - ]
+     842                 :          4 :             (libspdm_consttime_is_mem_equal(cert_basic_constraints,
+     843                 :            :                                             basic_constraints_true_case,
+     844                 :            :                                             sizeof(basic_constraints_true_case)))) {
+     845                 :          4 :             return true;
+     846                 :            :         }
+     847                 :            :     }
+     848                 :            : 
+     849                 :          2 :     return false;
+     850                 :            : }
+     851                 :            : 
+     852                 :            : /**
+     853                 :            :  * Verify leaf cert spdm defined extended key usage
+     854                 :            :  *
+     855                 :            :  * @param[in]  cert                  Pointer to the DER-encoded certificate data.
+     856                 :            :  * @param[in]  cert_size             The size of certificate data in bytes.
+     857                 :            :  * @param[in]  is_requester_cert     Is the function verifying requester or responder cert.
+     858                 :            :  *
+     859                 :            :  * @retval  true   verify pass, two cases:
+     860                 :            :  *                 1. spdm defined eku is not present in cert;
+     861                 :            :  *                 2. spdm defined eku is compliant with requester/responder identity;
+     862                 :            :  * @retval  false  verify fail, two cases:
+     863                 :            :  *                 1. requester's cert has only responder auth oid in eku;
+     864                 :            :  *                 2. responder's cert has only requester auth oid in eku;
+     865                 :            :  **/
+     866                 :        728 : static bool libspdm_verify_leaf_cert_spdm_eku(const uint8_t *cert, size_t cert_size,
+     867                 :            :                                               bool is_requester_cert)
+     868                 :            : {
+     869                 :            :     bool status;
+     870                 :            :     uint8_t eku[256];
+     871                 :            :     size_t eku_size;
+     872                 :            :     bool req_auth_oid_find_success;
+     873                 :            :     bool rsp_auth_oid_find_success;
+     874                 :            :     uint8_t *ptr;
+     875                 :            :     size_t obj_len;
+     876                 :            : 
+     877                 :            :     /* SPDM defined OID */
+     878                 :        728 :     uint8_t eku_requester_auth_oid[] = SPDM_OID_DMTF_EKU_REQUESTER_AUTH;
+     879                 :        728 :     uint8_t eku_responder_auth_oid[] = SPDM_OID_DMTF_EKU_RESPONDER_AUTH;
+     880                 :            : 
+     881                 :        728 :     eku_size = sizeof(eku);
+     882                 :        728 :     status = libspdm_x509_get_extended_key_usage(cert, cert_size, eku, &eku_size);
+     883         [ -  + ]:        728 :     if (!status) {
+     884                 :          0 :         return false;
+     885         [ -  + ]:        728 :     } else if (eku_size == 0) {
+     886                 :            :         /* eku is not present in cert */
+     887                 :          0 :         return true;
+     888                 :            :     }
+     889                 :            : 
+     890                 :        728 :     ptr = eku;
+     891                 :        728 :     obj_len = 0;
+     892                 :        728 :     req_auth_oid_find_success = false;
+     893                 :        728 :     rsp_auth_oid_find_success = false;
+     894                 :            : 
+     895                 :        728 :     status = libspdm_asn1_get_tag(&ptr, eku + eku_size, &obj_len,
+     896                 :            :                                   LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
+     897         [ -  + ]:        728 :     if (!status) {
+     898                 :          0 :         return false;
+     899                 :            :     }
+     900                 :            : 
+     901         [ +  + ]:       2915 :     while(ptr < eku + eku_size) {
+     902                 :       2187 :         status = libspdm_asn1_get_tag(&ptr, eku + eku_size, &obj_len, LIBSPDM_CRYPTO_ASN1_OID);
+     903         [ -  + ]:       2187 :         if (!status) {
+     904                 :          0 :             return false;
+     905                 :            :         }
+     906                 :            : 
+     907   [ +  +  +  + ]:       2195 :         if ((obj_len == sizeof(eku_requester_auth_oid)) &&
+     908                 :          8 :             (libspdm_consttime_is_mem_equal(ptr, eku_requester_auth_oid,
+     909                 :            :                                             sizeof(eku_requester_auth_oid)))) {
+     910                 :          4 :             req_auth_oid_find_success = true;
+     911                 :            :         }
+     912   [ +  +  +  + ]:       2195 :         if ((obj_len == sizeof(eku_responder_auth_oid)) &&
+     913                 :          8 :             (libspdm_consttime_is_mem_equal(ptr, eku_responder_auth_oid,
+     914                 :            :                                             sizeof(eku_responder_auth_oid)))) {
+     915                 :          4 :             rsp_auth_oid_find_success = true;
+     916                 :            :         }
+     917                 :            : 
+     918                 :       2187 :         ptr += obj_len;
+     919                 :            :     }
+     920                 :            : 
+     921         [ -  + ]:        728 :     if (ptr != eku + eku_size) {
+     922                 :          0 :         return false;
+     923                 :            :     }
+     924                 :            : 
+     925         [ +  + ]:        728 :     if (is_requester_cert) {
+     926                 :            :         /* it should not only contain responder auth oid */
+     927   [ +  +  +  + ]:         20 :         if (!req_auth_oid_find_success && rsp_auth_oid_find_success) {
+     928                 :          1 :             return false;
+     929                 :            :         }
+     930                 :            :     } else {
+     931                 :            :         /* it should not only contain requester auth oid */
+     932   [ +  +  +  + ]:        708 :         if (req_auth_oid_find_success && !rsp_auth_oid_find_success) {
+     933                 :          1 :             return false;
+     934                 :            :         }
+     935                 :            :     }
+     936                 :            : 
+     937                 :        726 :     return true;
+     938                 :            : }
+     939                 :            : 
+     940                 :            : /**
+     941                 :            :  * Verify leaf cert spdm defined extension
+     942                 :            :  *
+     943                 :            :  * @param[in]  cert                  Pointer to the DER-encoded certificate data.
+     944                 :            :  * @param[in]  cert_size             The size of certificate data in bytes.
+     945                 :            :  * @param[in]  is_requester_cert     Is the function verifying requester or responder cert.
+     946                 :            :  *
+     947                 :            :  * @retval  true   verify pass
+     948                 :            :  * @retval  false  verify fail,two case: 1. return is not RETURN_SUCCESS or RETURN_NOT_FOUND;
+     949                 :            :  *                                       2. hardware_identity_oid is found in AliasCert model;
+     950                 :            :  **/
+     951                 :        720 : static bool libspdm_verify_leaf_cert_spdm_extension(const uint8_t *cert, size_t cert_size,
+     952                 :            :                                                     bool is_requester_cert,
+     953                 :            :                                                     uint8_t cert_model)
+     954                 :            : {
+     955                 :            :     bool status;
+     956                 :            :     bool find_sucessful;
+     957                 :            :     uint8_t spdm_extension[LIBSPDM_MAX_EXTENSION_LEN];
+     958                 :            :     size_t len;
+     959                 :            :     uint8_t *ptr;
+     960                 :            :     uint8_t *temptr;
+     961                 :            :     size_t obj_len;
+     962                 :            : 
+     963                 :            :     /* SPDM defined OID */
+     964                 :        720 :     uint8_t oid_spdm_extension[] = SPDM_OID_DMTF_SPDM_EXTENSION;
+     965                 :        720 :     uint8_t hardware_identity_oid[] = SPDM_OID_DMTF_HARDWARE_IDENTITY;
+     966                 :            : 
+     967                 :        720 :     len = LIBSPDM_MAX_EXTENSION_LEN;
+     968                 :            : 
+     969   [ +  -  -  + ]:        720 :     if (cert == NULL || cert_size == 0) {
+     970                 :          0 :         return false;
+     971                 :            :     }
+     972                 :            : 
+     973                 :        720 :     status = libspdm_x509_get_extension_data(cert, cert_size,
+     974                 :            :                                              (const uint8_t *)oid_spdm_extension,
+     975                 :            :                                              sizeof(oid_spdm_extension),
+     976                 :            :                                              spdm_extension,
+     977                 :            :                                              &len);
+     978         [ -  + ]:        720 :     if (!status) {
+     979                 :          0 :         return false;
+     980         [ +  + ]:        720 :     } else if(len == 0) {
+     981                 :         13 :         return true;
+     982                 :            :     }
+     983                 :            : 
+     984                 :            :     /*find the spdm hardware identity OID*/
+     985                 :        707 :     find_sucessful = false;
+     986                 :        707 :     ptr = spdm_extension;
+     987                 :        707 :     obj_len = 0;
+     988                 :            : 
+     989                 :            :     /*id-spdm-cert-oids ::= SEQUENCE SIZE (1..MAX) OF id-spdm-cert-oid*/
+     990                 :        707 :     status = libspdm_asn1_get_tag(
+     991                 :            :         &ptr, spdm_extension + len, &obj_len,
+     992                 :            :         LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
+     993         [ -  + ]:        707 :     if (!status) {
+     994                 :          0 :         return false;
+     995                 :            :     }
+     996                 :            : 
+     997         [ +  + ]:       1414 :     while(ptr < spdm_extension + len) {
+     998                 :        707 :         status = libspdm_asn1_get_tag(
+     999                 :            :             &ptr, spdm_extension + len, &obj_len,
+    1000                 :            :             LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
+    1001         [ -  + ]:        707 :         if (!status) {
+    1002                 :          0 :             return false;
+    1003                 :            :         }
+    1004                 :            : 
+    1005                 :        707 :         temptr = ptr + obj_len;
+    1006                 :        707 :         status = libspdm_asn1_get_tag(
+    1007                 :            :             &ptr, spdm_extension + len, &obj_len, LIBSPDM_CRYPTO_ASN1_OID);
+    1008         [ -  + ]:        707 :         if (!status) {
+    1009                 :          0 :             return false;
+    1010                 :            :         }
+    1011   [ +  -  +  - ]:       1414 :         if ((obj_len == sizeof(hardware_identity_oid)) &&
+    1012                 :        707 :             (libspdm_consttime_is_mem_equal(ptr, hardware_identity_oid,
+    1013                 :            :                                             sizeof(hardware_identity_oid)))) {
+    1014                 :        707 :             find_sucessful = true;
+    1015                 :            :         }
+    1016                 :        707 :         ptr = temptr;
+    1017                 :            :     }
+    1018                 :            : 
+    1019         [ -  + ]:        707 :     if (ptr != spdm_extension + len) {
+    1020                 :          0 :         return false;
+    1021                 :            :     }
+    1022                 :            : 
+    1023                 :            :     /* Responder does not determine Requester's certificate model */
+    1024         [ +  + ]:        707 :     if (!is_requester_cert) {
+    1025   [ +  -  +  + ]:        692 :         if ((find_sucessful) && (cert_model == SPDM_CERTIFICATE_INFO_CERT_MODEL_ALIAS_CERT)) {
+    1026                 :            :             /* Hardware_identity_OID is found in alias cert model */
+    1027                 :          4 :             return false;
+    1028                 :            :         }
+    1029                 :            :     }
+    1030                 :            : 
+    1031                 :        703 :     return true;
+    1032                 :            : }
+    1033                 :            : 
+    1034                 :            : /**
+    1035                 :            :  * Certificate common Check for SPDM leaf cert when get_cert and set_cert.
+    1036                 :            :  *
+    1037                 :            :  * @param[in]  cert                  Pointer to the DER-encoded certificate data.
+    1038                 :            :  * @param[in]  cert_size             The size of certificate data in bytes.
+    1039                 :            :  * @param[in]  base_asym_algo        SPDM base_asym_algo
+    1040                 :            :  * @param[in]  base_hash_algo        SPDM base_hash_algo
+    1041                 :            :  * @param[in]  is_requester_cert     Is the function verifying requester or responder cert.
+    1042                 :            :  * @param[in]  cert_model            One of the SPDM_CERTIFICATE_INFO_CERT_MODEL_* macros.
+    1043                 :            :  * @param[in]  set_cert              Is the function verifying a set certificate operation.
+    1044                 :            :  *
+    1045                 :            :  * @retval  true   Success.
+    1046                 :            :  * @retval  false  Certificate is not valid.
+    1047                 :            :  **/
+    1048                 :        730 : bool libspdm_x509_common_certificate_check(const uint8_t *cert, size_t cert_size,
+    1049                 :            :                                            uint32_t base_asym_algo, uint32_t base_hash_algo,
+    1050                 :            :                                            bool is_requester_cert, uint8_t cert_model,
+    1051                 :            :                                            bool set_cert)
+    1052                 :            : {
+    1053                 :            :     uint8_t end_cert_from[64];
+    1054                 :            :     size_t end_cert_from_len;
+    1055                 :            :     uint8_t end_cert_to[64];
+    1056                 :            :     size_t end_cert_to_len;
+    1057                 :            :     size_t asn1_buffer_len;
+    1058                 :            :     bool status;
+    1059                 :            :     size_t cert_version;
+    1060                 :            :     size_t value;
+    1061                 :            :     void *context;
+    1062                 :            : #if LIBSPDM_ADDITIONAL_CHECK_CERT
+    1063                 :            :     size_t signature_algo_oid_size;
+    1064                 :            : #endif /* LIBSPDM_ADDITIONAL_CHECK_CERT */
+    1065                 :            : 
+    1066   [ +  -  -  + ]:        730 :     if (cert == NULL || cert_size == 0) {
+    1067                 :          0 :         return false;
+    1068                 :            :     }
+    1069                 :            : 
+    1070                 :        730 :     status = true;
+    1071                 :        730 :     context = NULL;
+    1072                 :        730 :     end_cert_from_len = 64;
+    1073                 :        730 :     end_cert_to_len = 64;
+    1074                 :            : 
+    1075                 :            :     /* 1. version*/
+    1076                 :        730 :     cert_version = 0;
+    1077                 :        730 :     status = libspdm_x509_get_version(cert, cert_size, &cert_version);
+    1078         [ -  + ]:        730 :     if (!status) {
+    1079                 :          0 :         goto cleanup;
+    1080                 :            :     }
+    1081         [ -  + ]:        730 :     if (cert_version != 2) {
+    1082                 :          0 :         status = false;
+    1083                 :          0 :         goto cleanup;
+    1084                 :            :     }
+    1085                 :            : 
+    1086                 :            :     /* 2. serial_number*/
+    1087                 :        730 :     asn1_buffer_len = 0;
+    1088                 :        730 :     status = libspdm_x509_get_serial_number(cert, cert_size, NULL, &asn1_buffer_len);
+    1089         [ -  + ]:        730 :     if (asn1_buffer_len == 0) {
+    1090                 :          0 :         status = false;
+    1091                 :          0 :         goto cleanup;
+    1092                 :            :     }
+    1093                 :            : 
+    1094                 :            : #if LIBSPDM_ADDITIONAL_CHECK_CERT
+    1095                 :            :     /* 3. Verify signature algorithm. */
+    1096                 :            :     signature_algo_oid_size = 0;
+    1097                 :            :     status = libspdm_x509_get_signature_algorithm(cert, cert_size, NULL, &signature_algo_oid_size);
+    1098                 :            :     if (status) {
+    1099                 :            :         if ((signature_algo_oid_size == 0) &&
+    1100                 :            :             (cert_model != SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT)) {
+    1101                 :            :             status = false;
+    1102                 :            :             goto cleanup;
+    1103                 :            :         }
+    1104                 :            :     } else {
+    1105                 :            :         if (signature_algo_oid_size == 0) {
+    1106                 :            :             status = false;
+    1107                 :            :             goto cleanup;
+    1108                 :            :         }
+    1109                 :            :     }
+    1110                 :            : #endif /* LIBSPDM_ADDITIONAL_CHECK_CERT */
+    1111                 :            : 
+    1112                 :            :     /* 4. Verify public key algorithm.
+    1113                 :            :      *    If this is a SET_CERTIFICATE operation and the endpoint uses the AliasCert model then the
+    1114                 :            :      *    check should be skipped as the Device Certificate CA's public key does not have to use
+    1115                 :            :      *    the same algorithms as the connection's negotiated algorithms. */
+    1116   [ +  +  +  + ]:        730 :     if (!set_cert || (cert_model != SPDM_CERTIFICATE_INFO_CERT_MODEL_ALIAS_CERT)) {
+    1117                 :        724 :         status = libspdm_verify_cert_subject_public_key_info(cert, cert_size, base_asym_algo);
+    1118         [ +  + ]:        724 :         if (!status) {
+    1119                 :          2 :             goto cleanup;
+    1120                 :            :         }
+    1121                 :            :     }
+    1122                 :            : 
+    1123                 :            :     /* 5. issuer_name*/
+    1124                 :        728 :     asn1_buffer_len = 0;
+    1125                 :        728 :     status = libspdm_x509_get_issuer_name(cert, cert_size, NULL, &asn1_buffer_len);
+    1126         [ -  + ]:        728 :     if (status) {
+    1127   [ #  #  #  # ]:          0 :         if ((asn1_buffer_len == 0) &&
+    1128                 :            :             (cert_model != SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT)) {
+    1129                 :          0 :             status = false;
+    1130                 :          0 :             goto cleanup;
+    1131                 :            :         }
+    1132                 :            :     } else {
+    1133         [ -  + ]:        728 :         if (asn1_buffer_len == 0) {
+    1134                 :          0 :             status = false;
+    1135                 :          0 :             goto cleanup;
+    1136                 :            :         }
+    1137                 :            :     }
+    1138                 :            : 
+    1139                 :            :     /* 6. subject_name*/
+    1140                 :        728 :     asn1_buffer_len = 0;
+    1141                 :        728 :     status = libspdm_x509_get_subject_name(cert, cert_size, NULL, &asn1_buffer_len);
+    1142         [ -  + ]:        728 :     if (status) {
+    1143   [ #  #  #  # ]:          0 :         if ((asn1_buffer_len == 0) &&
+    1144                 :            :             (cert_model != SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT)) {
+    1145                 :          0 :             status = false;
+    1146                 :          0 :             goto cleanup;
+    1147                 :            :         }
+    1148                 :            :     } else {
+    1149         [ -  + ]:        728 :         if (asn1_buffer_len == 0) {
+    1150                 :          0 :             status = false;
+    1151                 :          0 :             goto cleanup;
+    1152                 :            :         }
+    1153                 :            :     }
+    1154                 :            : 
+    1155                 :            :     /* 7. validity*/
+    1156                 :        728 :     status = libspdm_x509_get_validity(cert, cert_size, end_cert_from,
+    1157                 :            :                                        &end_cert_from_len, end_cert_to,
+    1158                 :            :                                        &end_cert_to_len);
+    1159         [ +  - ]:        728 :     if (status) {
+    1160   [ -  +  -  - ]:        728 :         if ((end_cert_from_len == 0) &&
+    1161                 :            :             (cert_model != SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT)) {
+    1162                 :          0 :             status = false;
+    1163                 :          0 :             goto cleanup;
+    1164                 :            :         }
+    1165                 :            :     } else {
+    1166         [ #  # ]:          0 :         if (end_cert_from_len == 0) {
+    1167                 :          0 :             status = false;
+    1168                 :          0 :             goto cleanup;
+    1169                 :            :         }
+    1170                 :            :     }
+    1171                 :            : 
+    1172         [ +  - ]:        728 :     if (end_cert_from_len != 0) {
+    1173                 :        728 :         status = libspdm_internal_x509_date_time_check(
+    1174                 :            :             end_cert_from, end_cert_from_len, end_cert_to, end_cert_to_len);
+    1175         [ -  + ]:        728 :         if (!status) {
+    1176                 :          0 :             goto cleanup;
+    1177                 :            :         }
+    1178                 :            :     }
+    1179                 :            : 
+    1180                 :            :     /* 8. subject_public_key*/
+    1181                 :        728 :     status = libspdm_asym_get_public_key_from_x509(base_asym_algo, cert, cert_size, &context);
+    1182         [ -  + ]:        728 :     if (!status) {
+    1183                 :          0 :         goto cleanup;
+    1184                 :            :     }
+    1185                 :            : 
+    1186                 :            :     /* 9. key_usage*/
+    1187                 :        728 :     value = 0;
+    1188                 :        728 :     status = libspdm_x509_get_key_usage(cert, cert_size, &value);
+    1189         [ -  + ]:        728 :     if (!status) {
+    1190                 :          0 :         goto cleanup;
+    1191                 :            :     } else {
+    1192         [ -  + ]:        728 :         if (value == 0) {
+    1193         [ #  # ]:          0 :             if (cert_model != SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT) {
+    1194                 :          0 :                 status = false;
+    1195                 :          0 :                 goto cleanup;
+    1196                 :            :             }
+    1197                 :            :         } else {
+    1198         [ -  + ]:        728 :             if ((LIBSPDM_CRYPTO_X509_KU_DIGITAL_SIGNATURE & value) == 0) {
+    1199                 :          0 :                 status = false;
+    1200                 :          0 :                 goto cleanup;
+    1201                 :            :             }
+    1202                 :            :         }
+    1203                 :            :     }
+    1204                 :            : 
+    1205                 :            :     /* 10. verify spdm defined extended key usage*/
+    1206                 :        728 :     status = libspdm_verify_leaf_cert_spdm_eku(cert, cert_size, is_requester_cert);
+    1207         [ +  + ]:        728 :     if (!status) {
+    1208                 :          2 :         goto cleanup;
+    1209                 :            :     }
+    1210                 :            : 
+    1211   [ +  +  +  + ]:        726 :     if ((!set_cert) || (cert_model == SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT)) {
+    1212                 :            :         /* 11. verify spdm defined extension*/
+    1213                 :        720 :         status = libspdm_verify_leaf_cert_spdm_extension(cert, cert_size,
+    1214                 :            :                                                          is_requester_cert, cert_model);
+    1215         [ +  + ]:        720 :         if (!status) {
+    1216                 :          4 :             goto cleanup;
+    1217                 :            :         }
+    1218                 :            :     }
+    1219                 :            : 
+    1220                 :        722 : cleanup:
+    1221                 :        730 :     libspdm_asym_free(base_asym_algo, context);
+    1222                 :        730 :     return status;
+    1223                 :            : }
+    1224                 :            : 
+    1225                 :            : /**
+    1226                 :            :  * Certificate Check for SPDM leaf cert when get_cert command
+    1227                 :            :  *
+    1228                 :            :  * @param[in]  cert                  Pointer to the DER-encoded certificate data.
+    1229                 :            :  * @param[in]  cert_size             The size of certificate data in bytes.
+    1230                 :            :  * @param[in]  base_asym_algo        SPDM base_asym_algo
+    1231                 :            :  * @param[in]  base_hash_algo        SPDM base_hash_algo
+    1232                 :            :  * @param[in]  is_requester          Is the function verifying a cert as a requester or responder.
+    1233                 :            :  * @param[in]  is_device_cert_model  If true, the local endpoint uses the DeviceCert model.
+    1234                 :            :  *                                   If false, the local endpoint uses the AliasCert model.
+    1235                 :            :  *
+    1236                 :            :  * @retval  true   Success.
+    1237                 :            :  * @retval  false  Certificate is not valid
+    1238                 :            :  **/
+    1239                 :        703 : bool libspdm_x509_certificate_check(const uint8_t *cert, size_t cert_size,
+    1240                 :            :                                     uint32_t base_asym_algo,
+    1241                 :            :                                     uint32_t base_hash_algo,
+    1242                 :            :                                     bool is_requester,
+    1243                 :            :                                     bool is_device_cert_model)
+    1244                 :            : {
+    1245                 :            :     bool status;
+    1246                 :            :     uint8_t cert_model;
+    1247                 :            : 
+    1248         [ +  + ]:        703 :     if (is_device_cert_model) {
+    1249                 :        697 :         cert_model = SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT;
+    1250                 :            :     } else {
+    1251                 :          6 :         cert_model = SPDM_CERTIFICATE_INFO_CERT_MODEL_ALIAS_CERT;
+    1252                 :            :     }
+    1253                 :            : 
+    1254                 :        703 :     status = libspdm_x509_common_certificate_check(cert, cert_size, base_asym_algo,
+    1255                 :            :                                                    base_hash_algo, is_requester,
+    1256                 :            :                                                    cert_model, false);
+    1257         [ +  + ]:        703 :     if (!status) {
+    1258                 :          5 :         return false;
+    1259                 :            :     }
+    1260                 :            : 
+    1261                 :            :     /* verify basic constraints: the leaf cert always is ca:false in get_cert*/
+    1262                 :        698 :     status = libspdm_verify_leaf_cert_basic_constraints(cert, cert_size, false);
+    1263                 :        698 :     return status;
+    1264                 :            : }
+    1265                 :            : 
+    1266                 :            : 
+    1267                 :            : /**
+    1268                 :            :  * Certificate Check for SPDM leaf cert when get_cert command. It is used for SPDM 1.3.
+    1269                 :            :  *
+    1270                 :            :  * @param[in]  cert                  Pointer to the DER-encoded certificate data.
+    1271                 :            :  * @param[in]  cert_size             The size of certificate data in bytes.
+    1272                 :            :  * @param[in]  base_asym_algo        SPDM base_asym_algo
+    1273                 :            :  * @param[in]  base_hash_algo        SPDM base_hash_algo
+    1274                 :            :  * @param[in]  is_requester          Is the function verifying a cert as a requester or responder.
+    1275                 :            :  * @param[in]  cert_model            One of the SPDM_CERTIFICATE_INFO_CERT_MODEL_* macros.
+    1276                 :            :  *
+    1277                 :            :  * @retval  true   Success.
+    1278                 :            :  * @retval  false  Certificate is not valid
+    1279                 :            :  **/
+    1280                 :         13 : bool libspdm_x509_certificate_check_ex(const uint8_t *cert, size_t cert_size,
+    1281                 :            :                                        uint32_t base_asym_algo,
+    1282                 :            :                                        uint32_t base_hash_algo,
+    1283                 :            :                                        bool is_requester,
+    1284                 :            :                                        uint8_t cert_model)
+    1285                 :            : {
+    1286                 :            :     bool status;
+    1287                 :            : 
+    1288                 :         13 :     status = libspdm_x509_common_certificate_check(cert, cert_size, base_asym_algo,
+    1289                 :            :                                                    base_hash_algo, is_requester,
+    1290                 :            :                                                    cert_model, false);
+    1291         [ +  + ]:         13 :     if (!status) {
+    1292                 :          3 :         return false;
+    1293                 :            :     }
+    1294                 :            : 
+    1295                 :            :     /* verify basic constraints: the leaf cert always is ca:false in get_cert
+    1296                 :            :      * basic_constraints is mandatory in SPDM 1.3*/
+    1297                 :         10 :     status = libspdm_verify_leaf_cert_basic_constraints(cert, cert_size, true);
+    1298                 :         10 :     return status;
+    1299                 :            : }
+    1300                 :            : 
+    1301                 :            : /**
+    1302                 :            :  * Certificate Check for SPDM leaf cert when set_cert command.
+    1303                 :            :  *
+    1304                 :            :  * @param[in]  cert                  Pointer to the DER-encoded certificate data.
+    1305                 :            :  * @param[in]  cert_size             The size of certificate data in bytes.
+    1306                 :            :  * @param[in]  base_asym_algo        SPDM base_asym_algo
+    1307                 :            :  * @param[in]  base_hash_algo        SPDM base_hash_algo
+    1308                 :            :  * @param[in]  is_requester          Is the function verifying a cert as a requester or responder.
+    1309                 :            :  * @param[in]  is_device_cert_model  If true, the local endpoint uses the DeviceCert model.
+    1310                 :            :  *                                   If false, the local endpoint uses the AliasCert model.
+    1311                 :            :  *
+    1312                 :            :  * @retval  true   Success.
+    1313                 :            :  * @retval  false  Certificate is not valid.
+    1314                 :            :  **/
+    1315                 :          9 : bool libspdm_x509_set_cert_certificate_check(const uint8_t *cert, size_t cert_size,
+    1316                 :            :                                              uint32_t base_asym_algo, uint32_t base_hash_algo,
+    1317                 :            :                                              bool is_requester, bool is_device_cert_model)
+    1318                 :            : {
+    1319                 :            :     bool status;
+    1320                 :            :     uint8_t cert_model;
+    1321                 :            : 
+    1322         [ +  + ]:          9 :     if (is_device_cert_model) {
+    1323                 :          6 :         cert_model = SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT;
+    1324                 :            :     } else {
+    1325                 :          3 :         cert_model = SPDM_CERTIFICATE_INFO_CERT_MODEL_ALIAS_CERT;
+    1326                 :            :     }
+    1327                 :            : 
+    1328                 :          9 :     status = libspdm_x509_common_certificate_check(cert, cert_size, base_asym_algo,
+    1329                 :            :                                                    base_hash_algo, is_requester,
+    1330                 :            :                                                    cert_model, true);
+    1331         [ -  + ]:          9 :     if (!status) {
+    1332                 :          0 :         return false;
+    1333                 :            :     }
+    1334                 :            : 
+    1335                 :            :     /* verify basic constraints: need check with is_device_cert_model*/
+    1336                 :          9 :     status = libspdm_verify_set_cert_leaf_cert_basic_constraints(
+    1337                 :            :         cert, cert_size, cert_model);
+    1338                 :          9 :     return status;
+    1339                 :            : }
+    1340                 :            : 
+    1341                 :            : /**
+    1342                 :            :  * Certificate Check for SPDM leaf cert when set_cert. It is used for SPDM 1.3.
+    1343                 :            :  *
+    1344                 :            :  * @param[in]  cert                  Pointer to the DER-encoded certificate data.
+    1345                 :            :  * @param[in]  cert_size             The size of certificate data in bytes.
+    1346                 :            :  * @param[in]  base_asym_algo        SPDM base_asym_algo
+    1347                 :            :  * @param[in]  base_hash_algo        SPDM base_hash_algo
+    1348                 :            :  * @param[in]  is_requester          Is the function verifying a cert as a requester or responder.
+    1349                 :            :  * @param[in]  cert_model            One of the SPDM_CERTIFICATE_INFO_CERT_MODEL_* macros.
+    1350                 :            :  *
+    1351                 :            :  * @retval  true   Success.
+    1352                 :            :  * @retval  false  Certificate is not valid.
+    1353                 :            :  **/
+    1354                 :          5 : bool libspdm_x509_set_cert_certificate_check_ex(const uint8_t *cert, size_t cert_size,
+    1355                 :            :                                                 uint32_t base_asym_algo, uint32_t base_hash_algo,
+    1356                 :            :                                                 bool is_requester, uint8_t cert_model)
+    1357                 :            : {
+    1358                 :            :     bool status;
+    1359                 :            : 
+    1360                 :          5 :     status = libspdm_x509_common_certificate_check(cert, cert_size, base_asym_algo,
+    1361                 :            :                                                    base_hash_algo, is_requester,
+    1362                 :            :                                                    cert_model, true);
+    1363         [ -  + ]:          5 :     if (!status) {
+    1364                 :          0 :         return false;
+    1365                 :            :     }
+    1366                 :            : 
+    1367                 :            :     /* verify basic constraints: need check with is_device_cert_model*/
+    1368                 :          5 :     status = libspdm_verify_set_cert_leaf_cert_basic_constraints(
+    1369                 :            :         cert, cert_size, cert_model);
+    1370                 :          5 :     return status;
+    1371                 :            : }
+    1372                 :            : 
+    1373                 :            : /**
+    1374                 :            :  * Return certificate is root cert or not.
+    1375                 :            :  * Certificate is considered as a root certificate if the subjectname equal issuername.
+    1376                 :            :  *
+    1377                 :            :  * @param[in]  cert            Pointer to the DER-encoded certificate data.
+    1378                 :            :  * @param[in]  cert_size        The size of certificate data in bytes.
+    1379                 :            :  *
+    1380                 :            :  * @retval  true   Certificate is self-signed.
+    1381                 :            :  * @retval  false  Certificate is not self-signed.
+    1382                 :            :  **/
+    1383                 :         59 : bool libspdm_is_root_certificate(const uint8_t *cert, size_t cert_size)
+    1384                 :            : {
+    1385                 :            :     uint8_t issuer_name[LIBSPDM_MAX_NAME_SIZE];
+    1386                 :            :     size_t issuer_name_len;
+    1387                 :            :     uint8_t subject_name[LIBSPDM_MAX_NAME_SIZE];
+    1388                 :            :     size_t subject_name_len;
+    1389                 :            :     bool result;
+    1390                 :            : 
+    1391   [ +  -  -  + ]:         59 :     if (cert == NULL || cert_size == 0) {
+    1392                 :          0 :         return false;
+    1393                 :            :     }
+    1394                 :            : 
+    1395                 :            :     /* 1. issuer_name*/
+    1396                 :         59 :     issuer_name_len = sizeof(issuer_name);
+    1397                 :         59 :     result = libspdm_x509_get_issuer_name(cert, cert_size, issuer_name, &issuer_name_len);
+    1398         [ -  + ]:         59 :     if (!result) {
+    1399                 :          0 :         return false;
+    1400                 :            :     }
+    1401                 :            : 
+    1402                 :            :     /* 2. subject_name*/
+    1403                 :         59 :     subject_name_len = sizeof(subject_name);
+    1404                 :         59 :     result = libspdm_x509_get_subject_name(cert, cert_size, subject_name, &subject_name_len);
+    1405         [ -  + ]:         59 :     if (!result) {
+    1406                 :          0 :         return false;
+    1407                 :            :     }
+    1408                 :            : 
+    1409         [ +  + ]:         59 :     if (issuer_name_len != subject_name_len) {
+    1410                 :          3 :         return false;
+    1411                 :            :     }
+    1412         [ -  + ]:         56 :     if (!libspdm_consttime_is_mem_equal(issuer_name, subject_name, issuer_name_len)) {
+    1413                 :          0 :         return false;
+    1414                 :            :     }
+    1415                 :            : 
+    1416                 :         56 :     return true;
+    1417                 :            : }
+    1418                 :            : 
+    1419                 :            : /**
+    1420                 :            :  * Retrieve the SubjectAltName from SubjectAltName Bytes.
+    1421                 :            :  *
+    1422                 :            :  * @param[in]      buffer           Pointer to subjectAltName oct bytes.
+    1423                 :            :  * @param[in]      len              size of buffer in bytes.
+    1424                 :            :  * @param[out]     name_buffer       buffer to contain the retrieved certificate
+    1425                 :            :  *                                 SubjectAltName. At most name_buffer_size bytes will be
+    1426                 :            :  *                                 written. Maybe NULL in order to determine the size
+    1427                 :            :  *                                 buffer needed.
+    1428                 :            :  * @param[in,out]  name_buffer_size   The size in bytes of the name buffer on input,
+    1429                 :            :  *                                 and the size of buffer returned name on output.
+    1430                 :            :  *                                 If name_buffer is NULL then the amount of space needed
+    1431                 :            :  *                                 in buffer (including the final null) is returned.
+    1432                 :            :  * @param[out]     oid              OID of otherName
+    1433                 :            :  * @param[in,out]  oid_size          the buffersize for required OID
+    1434                 :            :  *
+    1435                 :            :  * @retval true                     get the subjectAltName string successfully
+    1436                 :            :  * @retval failed                   get the subjectAltName string failed
+    1437                 :            :  **/
+    1438                 :          9 : bool libspdm_get_dmtf_subject_alt_name_from_bytes(
+    1439                 :            :     uint8_t *buffer, const size_t len, char *name_buffer,
+    1440                 :            :     size_t *name_buffer_size, uint8_t *oid,
+    1441                 :            :     size_t *oid_size)
+    1442                 :            : {
+    1443                 :            :     uint8_t *ptr;
+    1444                 :            :     int32_t length;
+    1445                 :            :     size_t obj_len;
+    1446                 :            :     int32_t ret;
+    1447                 :            : 
+    1448                 :            :     /*copy mem variable*/
+    1449                 :            :     volatile uint8_t* dst;
+    1450                 :            :     const volatile uint8_t* src;
+    1451                 :            :     size_t dst_len;
+    1452                 :            :     size_t src_len;
+    1453                 :            : 
+    1454                 :          9 :     length = (int32_t)len;
+    1455                 :          9 :     ptr = buffer;
+    1456                 :          9 :     obj_len = 0;
+    1457                 :            : 
+    1458                 :            :     /* Sequence*/
+    1459                 :          9 :     ret = libspdm_asn1_get_tag(&ptr, ptr + length, &obj_len,
+    1460                 :            :                                LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
+    1461         [ -  + ]:          9 :     if (!ret) {
+    1462                 :          0 :         return false;
+    1463                 :            :     }
+    1464                 :            : 
+    1465                 :          9 :     ret = libspdm_asn1_get_tag(&ptr, ptr + obj_len, &obj_len,
+    1466                 :            :                                LIBSPDM_CRYPTO_ASN1_CONTEXT_SPECIFIC |
+    1467                 :            :                                LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
+    1468                 :            : 
+    1469                 :          9 :     ret = libspdm_asn1_get_tag(&ptr, ptr + obj_len, &obj_len, LIBSPDM_CRYPTO_ASN1_OID);
+    1470         [ -  + ]:          9 :     if (!ret) {
+    1471                 :          0 :         return false;
+    1472                 :            :     }
+    1473                 :            :     /* CopyData to OID*/
+    1474         [ -  + ]:          9 :     if (*oid_size < (size_t)obj_len) {
+    1475                 :          0 :         *oid_size = (size_t)obj_len;
+    1476                 :          0 :         return false;
+    1477                 :            :     }
+    1478         [ +  - ]:          9 :     if (oid != NULL) {
+    1479                 :          9 :         libspdm_copy_mem(oid, *oid_size, ptr, obj_len);
+    1480                 :          9 :         *oid_size = obj_len;
+    1481                 :            :     }
+    1482                 :            : 
+    1483                 :            :     /* Move to next element*/
+    1484                 :          9 :     ptr += obj_len;
+    1485                 :            : 
+    1486                 :          9 :     ret = libspdm_asn1_get_tag(&ptr, (uint8_t *)(buffer + length), &obj_len,
+    1487                 :            :                                LIBSPDM_CRYPTO_ASN1_CONTEXT_SPECIFIC |
+    1488                 :            :                                LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
+    1489                 :          9 :     ret = libspdm_asn1_get_tag(&ptr, (uint8_t *)(buffer + length), &obj_len,
+    1490                 :            :                                LIBSPDM_CRYPTO_ASN1_UTF8_STRING);
+    1491         [ -  + ]:          9 :     if (!ret) {
+    1492                 :          0 :         return false;
+    1493                 :            :     }
+    1494                 :            : 
+    1495         [ -  + ]:          9 :     if (*name_buffer_size < (size_t)obj_len + 1) {
+    1496                 :          0 :         *name_buffer_size = (size_t)obj_len + 1;
+    1497                 :          0 :         return false;
+    1498                 :            :     }
+    1499                 :            : 
+    1500                 :            :     /* the src and dst adress are overlap,
+    1501                 :            :     * When the function is called by libspdm_get_dmtf_subject_alt_name.
+    1502                 :            :     * libspdm_copy_mem can not be uesed */
+    1503   [ +  -  +  - ]:          9 :     if ((name_buffer != NULL) && (ptr != NULL)) {
+    1504                 :          9 :         dst = (volatile uint8_t*) name_buffer;
+    1505                 :          9 :         src = (const volatile uint8_t*) ptr;
+    1506                 :          9 :         dst_len = *name_buffer_size;
+    1507                 :          9 :         src_len = obj_len;
+    1508                 :            : 
+    1509                 :            :         /* Check for case where "dst_len" may be invalid. Do not zero "dst" in this case. */
+    1510         [ -  + ]:          9 :         if (dst_len > (SIZE_MAX >> 1)) {
+    1511                 :          0 :             LIBSPDM_ASSERT(0);
+    1512                 :          0 :             return false;
+    1513                 :            :         }
+    1514                 :            : 
+    1515                 :            :         /* Guard against invalid lengths. Zero "dst" in these cases. */
+    1516         [ +  - ]:          9 :         if (src_len > dst_len ||
+    1517         [ -  + ]:          9 :             src_len > (SIZE_MAX >> 1)) {
+    1518                 :          0 :             libspdm_zero_mem(name_buffer, dst_len);
+    1519                 :          0 :             LIBSPDM_ASSERT(0);
+    1520                 :          0 :             return false;
+    1521                 :            :         }
+    1522                 :            : 
+    1523         [ +  + ]:        207 :         while (src_len-- != 0) {
+    1524                 :        198 :             *(dst++) = *(src++);
+    1525                 :            :         }
+    1526                 :            : 
+    1527                 :            :         /*encode name buffer to string*/
+    1528                 :          9 :         *name_buffer_size = obj_len + 1;
+    1529                 :          9 :         name_buffer[obj_len] = 0;
+    1530                 :          9 :         return true;
+    1531                 :            :     }
+    1532                 :            : 
+    1533                 :          0 :     return false;
+    1534                 :            : }
+    1535                 :            : 
+    1536                 :            : /**
+    1537                 :            :  * Retrieve the SubjectAltName from one X.509 certificate.
+    1538                 :            :  *
+    1539                 :            :  * @param[in]      cert             Pointer to the DER-encoded X509 certificate.
+    1540                 :            :  * @param[in]      cert_size         size of the X509 certificate in bytes.
+    1541                 :            :  * @param[out]     name_buffer       buffer to contain the retrieved certificate
+    1542                 :            :  *                                 SubjectAltName. At most name_buffer_size bytes will be
+    1543                 :            :  *                                 written. Maybe NULL in order to determine the size
+    1544                 :            :  *                                 buffer needed.
+    1545                 :            :  * @param[in,out]  name_buffer_size   The size in bytes of the name buffer on input,
+    1546                 :            :  *                                 and the size of buffer returned name on output.
+    1547                 :            :  *                                 If name_buffer is NULL then the amount of space needed
+    1548                 :            :  *                                 in buffer (including the final null) is returned.
+    1549                 :            :  * @param[out]     oid              OID of otherName
+    1550                 :            :  * @param[in,out]  oid_size          the buffersize for required OID
+    1551                 :            :  *
+    1552                 :            :  * @retval true                     get the subjectAltName string successfully
+    1553                 :            :  * @retval failed                   get the subjectAltName string failed
+    1554                 :            :  **/
+    1555                 :          6 : bool libspdm_get_dmtf_subject_alt_name(const uint8_t *cert, const size_t cert_size,
+    1556                 :            :                                        char *name_buffer,
+    1557                 :            :                                        size_t *name_buffer_size,
+    1558                 :            :                                        uint8_t *oid, size_t *oid_size)
+    1559                 :            : {
+    1560                 :            :     bool status;
+    1561                 :            :     size_t extension_data_size;
+    1562                 :          6 :     uint8_t oid_subject_alt_name[] = { 0x55, 0x1D, 0x11 };
+    1563                 :            : 
+    1564                 :          6 :     extension_data_size = 0;
+    1565                 :          6 :     status = libspdm_x509_get_extension_data(cert, cert_size,
+    1566                 :            :                                              oid_subject_alt_name,
+    1567                 :            :                                              sizeof(oid_subject_alt_name), NULL,
+    1568                 :            :                                              &extension_data_size);
+    1569   [ +  -  -  + ]:          6 :     if (status || (extension_data_size == 0)) {
+    1570                 :          0 :         *name_buffer_size = 0;
+    1571                 :          0 :         return false;
+    1572                 :            :     }
+    1573         [ -  + ]:          6 :     if (extension_data_size > *name_buffer_size) {
+    1574                 :          0 :         *name_buffer_size = extension_data_size;
+    1575                 :          0 :         return false;
+    1576                 :            :     }
+    1577                 :            :     status =
+    1578                 :          6 :         libspdm_x509_get_extension_data(cert, cert_size,
+    1579                 :            :                                         oid_subject_alt_name,
+    1580                 :            :                                         sizeof(oid_subject_alt_name),
+    1581                 :            :                                         (uint8_t *)name_buffer, name_buffer_size);
+    1582         [ -  + ]:          6 :     if (!status) {
+    1583                 :          0 :         return status;
+    1584                 :            :     }
+    1585                 :            : 
+    1586                 :          6 :     return libspdm_get_dmtf_subject_alt_name_from_bytes(
+    1587                 :            :         (uint8_t *)name_buffer, *name_buffer_size, name_buffer,
+    1588                 :            :         name_buffer_size, oid, oid_size);
+    1589                 :            : }
+    1590                 :            : 
+    1591                 :            : /**
+    1592                 :            :  * This function verifies the integrity of certificate chain data without spdm_cert_chain_t header.
+    1593                 :            :  * It is used for SPDM 1.3.
+    1594                 :            :  *
+    1595                 :            :  * @param  cert_chain_data       The certificate chain data without spdm_cert_chain_t header.
+    1596                 :            :  * @param  cert_chain_data_size  Size in bytes of the certificate chain data.
+    1597                 :            :  * @param  base_asym_algo        SPDM base_asym_algo
+    1598                 :            :  * @param  base_hash_algo        SPDM base_hash_algo
+    1599                 :            :  * @param  is_requester_cert     Is the function verifying requester or responder cert.
+    1600                 :            :  * @param  cert_model            One of the SPDM_CERTIFICATE_INFO_CERT_MODEL_* macros.
+    1601                 :            :  *
+    1602                 :            :  * @retval true  Certificate chain data integrity verification pass.
+    1603                 :            :  * @retval false Certificate chain data integrity verification fail.
+    1604                 :            :  **/
+    1605                 :          6 : bool libspdm_verify_cert_chain_data_ex(uint8_t *cert_chain_data, size_t cert_chain_data_size,
+    1606                 :            :                                        uint32_t base_asym_algo, uint32_t base_hash_algo,
+    1607                 :            :                                        bool is_requester_cert, uint8_t cert_model)
+    1608                 :            : {
+    1609                 :            :     const uint8_t *root_cert_buffer;
+    1610                 :            :     size_t root_cert_buffer_size;
+    1611                 :            :     const uint8_t *leaf_cert_buffer;
+    1612                 :            :     size_t leaf_cert_buffer_size;
+    1613                 :            : 
+    1614         [ -  + ]:          6 :     if (cert_chain_data_size >
+    1615                 :            :         0xFFFF - (sizeof(spdm_cert_chain_t) + LIBSPDM_MAX_HASH_SIZE)) {
+    1616                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+    1617                 :            :                        "!!! VerifyCertificateChainData - FAIL (chain size too large) !!!\n"));
+    1618                 :          0 :         return false;
+    1619                 :            :     }
+    1620                 :            : 
+    1621         [ -  + ]:          6 :     if (!libspdm_x509_get_cert_from_cert_chain(
+    1622                 :            :             cert_chain_data, cert_chain_data_size, 0, &root_cert_buffer,
+    1623                 :            :             &root_cert_buffer_size)) {
+    1624                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+    1625                 :            :                        "!!! VerifyCertificateChainData - FAIL (get root certificate failed)!!!\n"));
+    1626                 :          0 :         return false;
+    1627                 :            :     }
+    1628                 :            : 
+    1629         [ +  + ]:          6 :     if (!libspdm_x509_verify_cert_chain(root_cert_buffer, root_cert_buffer_size,
+    1630                 :            :                                         cert_chain_data, cert_chain_data_size)) {
+    1631                 :          2 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+    1632                 :            :                        "!!! VerifyCertificateChainData - FAIL (cert chain verify failed)!!!\n"));
+    1633                 :          2 :         return false;
+    1634                 :            :     }
+    1635                 :            : 
+    1636         [ -  + ]:          4 :     if (!libspdm_x509_get_cert_from_cert_chain(
+    1637                 :            :             cert_chain_data, cert_chain_data_size, -1,
+    1638                 :            :             &leaf_cert_buffer, &leaf_cert_buffer_size)) {
+    1639                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+    1640                 :            :                        "!!! VerifyCertificateChainData - FAIL (get leaf certificate failed)!!!\n"));
+    1641                 :          0 :         return false;
+    1642                 :            :     }
+    1643                 :            : 
+    1644         [ +  + ]:          4 :     if (!libspdm_x509_certificate_check_ex(leaf_cert_buffer, leaf_cert_buffer_size,
+    1645                 :            :                                            base_asym_algo, base_hash_algo,
+    1646                 :            :                                            is_requester_cert, cert_model)) {
+    1647                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+    1648                 :            :                        "!!! VerifyCertificateChainData - FAIL (leaf certificate check failed)!!!\n"));
+    1649                 :          1 :         return false;
+    1650                 :            :     }
+    1651                 :            : 
+    1652                 :          3 :     return true;
+    1653                 :            : }
+    1654                 :            : /**
+    1655                 :            :  * This function verifies the integrity of certificate chain data without spdm_cert_chain_t header.
+    1656                 :            :  *
+    1657                 :            :  * @param  cert_chain_data          The certificate chain data without spdm_cert_chain_t header.
+    1658                 :            :  * @param  cert_chain_data_size      size in bytes of the certificate chain data.
+    1659                 :            :  * @param  base_asym_algo            SPDM base_asym_algo
+    1660                 :            :  * @param  base_hash_algo            SPDM base_hash_algo
+    1661                 :            :  * @param  is_requester_cert         Is the function verifying requester or responder cert.
+    1662                 :            :  * @param  is_device_cert_model      If true, the cert chain is DeviceCert model;
+    1663                 :            :  *                                   If false, the cert chain is AliasCert model;
+    1664                 :            :  *
+    1665                 :            :  * @retval true  certificate chain data integrity verification pass.
+    1666                 :            :  * @retval false certificate chain data integrity verification fail.
+    1667                 :            :  **/
+    1668                 :        649 : bool libspdm_verify_cert_chain_data(uint8_t *cert_chain_data, size_t cert_chain_data_size,
+    1669                 :            :                                     uint32_t base_asym_algo, uint32_t base_hash_algo,
+    1670                 :            :                                     bool is_requester_cert, bool is_device_cert_model)
+    1671                 :            : {
+    1672                 :            :     const uint8_t *root_cert_buffer;
+    1673                 :            :     size_t root_cert_buffer_size;
+    1674                 :            :     const uint8_t *leaf_cert_buffer;
+    1675                 :            :     size_t leaf_cert_buffer_size;
+    1676                 :            : 
+    1677         [ -  + ]:        649 :     if (cert_chain_data_size >
+    1678                 :            :         0xFFFF - (sizeof(spdm_cert_chain_t) + LIBSPDM_MAX_HASH_SIZE)) {
+    1679                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+    1680                 :            :                        "!!! VerifyCertificateChainData - FAIL (chain size too large) !!!\n"));
+    1681                 :          0 :         return false;
+    1682                 :            :     }
+    1683                 :            : 
+    1684         [ -  + ]:        649 :     if (!libspdm_x509_get_cert_from_cert_chain(
+    1685                 :            :             cert_chain_data, cert_chain_data_size, 0, &root_cert_buffer,
+    1686                 :            :             &root_cert_buffer_size)) {
+    1687                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+    1688                 :            :                        "!!! VerifyCertificateChainData - FAIL (get root certificate failed)!!!\n"));
+    1689                 :          0 :         return false;
+    1690                 :            :     }
+    1691                 :            : 
+    1692         [ -  + ]:        649 :     if (!libspdm_x509_verify_cert_chain(root_cert_buffer, root_cert_buffer_size,
+    1693                 :            :                                         cert_chain_data, cert_chain_data_size)) {
+    1694                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+    1695                 :            :                        "!!! VerifyCertificateChainData - FAIL (cert chain verify failed)!!!\n"));
+    1696                 :          0 :         return false;
+    1697                 :            :     }
+    1698                 :            : 
+    1699         [ -  + ]:        649 :     if (!libspdm_x509_get_cert_from_cert_chain(
+    1700                 :            :             cert_chain_data, cert_chain_data_size, -1,
+    1701                 :            :             &leaf_cert_buffer, &leaf_cert_buffer_size)) {
+    1702                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+    1703                 :            :                        "!!! VerifyCertificateChainData - FAIL (get leaf certificate failed)!!!\n"));
+    1704                 :          0 :         return false;
+    1705                 :            :     }
+    1706                 :            : 
+    1707         [ -  + ]:        649 :     if (!libspdm_x509_certificate_check(leaf_cert_buffer, leaf_cert_buffer_size,
+    1708                 :            :                                         base_asym_algo, base_hash_algo,
+    1709                 :            :                                         is_requester_cert, is_device_cert_model)) {
+    1710                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+    1711                 :            :                        "!!! VerifyCertificateChainData - FAIL (leaf certificate check failed)!!!\n"));
+    1712                 :          0 :         return false;
+    1713                 :            :     }
+    1714                 :            : 
+    1715                 :        649 :     return true;
+    1716                 :            : }
+    1717                 :            : 
+    1718                 :            : /**
+    1719                 :            :  * This function verifies the integrity of certificate chain buffer including
+    1720                 :            :  * spdm_cert_chain_t header. It is used for SPDM 1.3.
+    1721                 :            :  *
+    1722                 :            :  * @param  base_hash_algo          SPDM base_hash_algo
+    1723                 :            :  * @param  base_asym_algo          SPDM base_asym_algo
+    1724                 :            :  * @param  cert_chain_buffer       The certificate chain buffer including spdm_cert_chain_t header.
+    1725                 :            :  * @param  cert_chain_buffer_size  Size in bytes of the certificate chain buffer.
+    1726                 :            :  * @param  is_requester_cert       Is the function verifying requester or responder cert.
+    1727                 :            :  * @param  cert_model              One of the SPDM_CERTIFICATE_INFO_CERT_MODEL_* macros.
+    1728                 :            :  *
+    1729                 :            :  * @retval true   Certificate chain buffer integrity verification pass.
+    1730                 :            :  * @retval false  Certificate chain buffer integrity verification fail.
+    1731                 :            :  **/
+    1732                 :          6 : bool libspdm_verify_certificate_chain_buffer_ex(uint32_t base_hash_algo, uint32_t base_asym_algo,
+    1733                 :            :                                                 const void *cert_chain_buffer,
+    1734                 :            :                                                 size_t cert_chain_buffer_size,
+    1735                 :            :                                                 bool is_requester_cert, uint8_t cert_model)
+    1736                 :            : {
+    1737                 :            :     const uint8_t *cert_chain_data;
+    1738                 :            :     size_t cert_chain_data_size;
+    1739                 :            :     const uint8_t *first_cert_buffer;
+    1740                 :            :     size_t first_cert_buffer_size;
+    1741                 :            :     size_t hash_size;
+    1742                 :            :     uint8_t calc_root_cert_hash[LIBSPDM_MAX_HASH_SIZE];
+    1743                 :            :     const uint8_t *leaf_cert_buffer;
+    1744                 :            :     size_t leaf_cert_buffer_size;
+    1745                 :            :     bool result;
+    1746                 :            :     const spdm_cert_chain_t *cert_chain_header;
+    1747                 :            : 
+    1748                 :          6 :     hash_size = libspdm_get_hash_size(base_hash_algo);
+    1749                 :            : 
+    1750         [ -  + ]:          6 :     if (cert_chain_buffer_size <= sizeof(spdm_cert_chain_t) + hash_size) {
+    1751                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+    1752                 :            :                        "!!! VerifyCertificateChainBuffer - FAIL (buffer too small) !!!\n"));
+    1753                 :          0 :         return false;
+    1754                 :            :     }
+    1755                 :            : 
+    1756                 :          6 :     cert_chain_header = cert_chain_buffer;
+    1757         [ +  + ]:          6 :     if (cert_chain_header->length != cert_chain_buffer_size) {
+    1758                 :          2 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+    1759                 :            :                        "!!! VerifyCertificateChainBuffer - FAIL (cert_chain->length mismatch) !!!\n"));
+    1760                 :          2 :         return false;
+    1761                 :            :     }
+    1762                 :            : 
+    1763                 :          4 :     cert_chain_data = (const uint8_t *)cert_chain_buffer + sizeof(spdm_cert_chain_t) + hash_size;
+    1764                 :          4 :     cert_chain_data_size = cert_chain_buffer_size - sizeof(spdm_cert_chain_t) - hash_size;
+    1765         [ -  + ]:          4 :     if (!libspdm_x509_get_cert_from_cert_chain(
+    1766                 :            :             cert_chain_data, cert_chain_data_size, 0, &first_cert_buffer,
+    1767                 :            :             &first_cert_buffer_size)) {
+    1768                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+    1769                 :            :                        "!!! VerifyCertificateChainBuffer - FAIL (get root certificate failed)!!!\n"));
+    1770                 :          0 :         return false;
+    1771                 :            :     }
+    1772                 :            : 
+    1773         [ +  - ]:          4 :     if (libspdm_is_root_certificate(first_cert_buffer, first_cert_buffer_size)) {
+    1774                 :          4 :         result = libspdm_hash_all(base_hash_algo, first_cert_buffer, first_cert_buffer_size,
+    1775                 :            :                                   calc_root_cert_hash);
+    1776         [ -  + ]:          4 :         if (!result) {
+    1777                 :          0 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+    1778                 :            :                            "!!! VerifyCertificateChainBuffer - FAIL (hash calculation fail) !!!\n"));
+    1779                 :          0 :             return false;
+    1780                 :            :         }
+    1781         [ -  + ]:          4 :         if (!libspdm_consttime_is_mem_equal((const uint8_t *)cert_chain_buffer +
+    1782                 :            :                                             sizeof(spdm_cert_chain_t),
+    1783                 :            :                                             calc_root_cert_hash, hash_size)) {
+    1784                 :          0 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+    1785                 :            :                            "!!! VerifyCertificateChainBuffer - FAIL (cert root hash mismatch) !!!\n"));
+    1786                 :          0 :             return false;
+    1787                 :            :         }
+    1788                 :          4 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+    1789                 :            :                        "!!! VerifyCertificateChainBuffer - PASS (cert root hash match) !!!\n"));
+    1790                 :            :     }
+    1791                 :            : 
+    1792                 :            :     /*If the number of certificates in the certificate chain is more than 1,
+    1793                 :            :      * other certificates need to be verified.*/
+    1794         [ +  - ]:          4 :     if (cert_chain_data_size > first_cert_buffer_size) {
+    1795         [ -  + ]:          4 :         if (!libspdm_x509_verify_cert_chain(first_cert_buffer, first_cert_buffer_size,
+    1796                 :            :                                             cert_chain_data + first_cert_buffer_size,
+    1797                 :            :                                             cert_chain_data_size - first_cert_buffer_size)) {
+    1798                 :          0 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+    1799                 :            :                            "!!! VerifyCertificateChainBuffer - FAIL (cert chain verify failed)!!!\n"));
+    1800                 :          0 :             return false;
+    1801                 :            :         }
+    1802                 :            :     }
+    1803                 :            : 
+    1804         [ -  + ]:          4 :     if (!libspdm_x509_get_cert_from_cert_chain(
+    1805                 :            :             cert_chain_data, cert_chain_data_size, -1,
+    1806                 :            :             &leaf_cert_buffer, &leaf_cert_buffer_size)) {
+    1807                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+    1808                 :            :                        "!!! VerifyCertificateChainBuffer - FAIL (get leaf certificate failed)!!!\n"));
+    1809                 :          0 :         return false;
+    1810                 :            :     }
+    1811                 :            : 
+    1812         [ +  + ]:          4 :     if (!libspdm_x509_certificate_check_ex(leaf_cert_buffer, leaf_cert_buffer_size,
+    1813                 :            :                                            base_asym_algo, base_hash_algo,
+    1814                 :            :                                            is_requester_cert, cert_model)) {
+    1815                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+    1816                 :            :                        "!!! VerifyCertificateChainBuffer - FAIL (leaf certificate check failed)!!!\n"));
+    1817                 :          1 :         return false;
+    1818                 :            :     }
+    1819                 :            : 
+    1820                 :          3 :     return true;
+    1821                 :            : }
+    1822                 :            : 
+    1823                 :         34 : bool libspdm_verify_certificate_chain_buffer(uint32_t base_hash_algo, uint32_t base_asym_algo,
+    1824                 :            :                                              const void *cert_chain_buffer,
+    1825                 :            :                                              size_t cert_chain_buffer_size,
+    1826                 :            :                                              bool is_requester_cert,
+    1827                 :            :                                              bool is_device_cert_model)
+    1828                 :            : {
+    1829                 :            :     const uint8_t *cert_chain_data;
+    1830                 :            :     size_t cert_chain_data_size;
+    1831                 :            :     const uint8_t *first_cert_buffer;
+    1832                 :            :     size_t first_cert_buffer_size;
+    1833                 :            :     size_t hash_size;
+    1834                 :            :     uint8_t calc_root_cert_hash[LIBSPDM_MAX_HASH_SIZE];
+    1835                 :            :     const uint8_t *leaf_cert_buffer;
+    1836                 :            :     size_t leaf_cert_buffer_size;
+    1837                 :            :     bool result;
+    1838                 :            :     const spdm_cert_chain_t *cert_chain_header;
+    1839                 :            : 
+    1840                 :         34 :     hash_size = libspdm_get_hash_size(base_hash_algo);
+    1841                 :            : 
+    1842         [ -  + ]:         34 :     if (cert_chain_buffer_size <= sizeof(spdm_cert_chain_t) + hash_size) {
+    1843                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+    1844                 :            :                        "!!! VerifyCertificateChainBuffer - FAIL (buffer too small) !!!\n"));
+    1845                 :          0 :         return false;
+    1846                 :            :     }
+    1847                 :            : 
+    1848                 :         34 :     cert_chain_header = cert_chain_buffer;
+    1849         [ -  + ]:         34 :     if (cert_chain_header->length != cert_chain_buffer_size) {
+    1850                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+    1851                 :            :                        "!!! VerifyCertificateChainBuffer - FAIL (cert_chain->length mismatch) !!!\n"));
+    1852                 :          0 :         return false;
+    1853                 :            :     }
+    1854                 :            : 
+    1855                 :         34 :     cert_chain_data = (const uint8_t *)cert_chain_buffer + sizeof(spdm_cert_chain_t) + hash_size;
+    1856                 :         34 :     cert_chain_data_size = cert_chain_buffer_size - sizeof(spdm_cert_chain_t) - hash_size;
+    1857         [ -  + ]:         34 :     if (!libspdm_x509_get_cert_from_cert_chain(
+    1858                 :            :             cert_chain_data, cert_chain_data_size, 0, &first_cert_buffer,
+    1859                 :            :             &first_cert_buffer_size)) {
+    1860                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+    1861                 :            :                        "!!! VerifyCertificateChainBuffer - FAIL (get root certificate failed)!!!\n"));
+    1862                 :          0 :         return false;
+    1863                 :            :     }
+    1864                 :            : 
+    1865         [ +  + ]:         34 :     if (libspdm_is_root_certificate(first_cert_buffer, first_cert_buffer_size)) {
+    1866                 :         32 :         result = libspdm_hash_all(base_hash_algo, first_cert_buffer, first_cert_buffer_size,
+    1867                 :            :                                   calc_root_cert_hash);
+    1868         [ -  + ]:         32 :         if (!result) {
+    1869                 :          0 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+    1870                 :            :                            "!!! VerifyCertificateChainBuffer - FAIL (hash calculation fail) !!!\n"));
+    1871                 :          0 :             return false;
+    1872                 :            :         }
+    1873         [ -  + ]:         32 :         if (!libspdm_consttime_is_mem_equal((const uint8_t *)cert_chain_buffer +
+    1874                 :            :                                             sizeof(spdm_cert_chain_t),
+    1875                 :            :                                             calc_root_cert_hash, hash_size)) {
+    1876                 :          0 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+    1877                 :            :                            "!!! VerifyCertificateChainBuffer - FAIL (cert root hash mismatch) !!!\n"));
+    1878                 :          0 :             return false;
+    1879                 :            :         }
+    1880                 :         32 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+    1881                 :            :                        "!!! VerifyCertificateChainBuffer - PASS (cert root hash match) !!!\n"));
+    1882                 :            :     }
+    1883                 :            : 
+    1884                 :            :     /*If the number of certificates in the certificate chain is more than 1,
+    1885                 :            :      * other certificates need to be verified.*/
+    1886         [ +  - ]:         34 :     if (cert_chain_data_size > first_cert_buffer_size) {
+    1887         [ +  + ]:         34 :         if (!libspdm_x509_verify_cert_chain(first_cert_buffer, first_cert_buffer_size,
+    1888                 :            :                                             cert_chain_data + first_cert_buffer_size,
+    1889                 :            :                                             cert_chain_data_size - first_cert_buffer_size)) {
+    1890                 :          3 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+    1891                 :            :                            "!!! VerifyCertificateChainBuffer - FAIL (cert chain verify failed)!!!\n"));
+    1892                 :          3 :             return false;
+    1893                 :            :         }
+    1894                 :            :     }
+    1895                 :            : 
+    1896         [ -  + ]:         31 :     if (!libspdm_x509_get_cert_from_cert_chain(
+    1897                 :            :             cert_chain_data, cert_chain_data_size, -1,
+    1898                 :            :             &leaf_cert_buffer, &leaf_cert_buffer_size)) {
+    1899                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+    1900                 :            :                        "!!! VerifyCertificateChainBuffer - FAIL (get leaf certificate failed)!!!\n"));
+    1901                 :          0 :         return false;
+    1902                 :            :     }
+    1903                 :            : 
+    1904         [ +  + ]:         31 :     if (!libspdm_x509_certificate_check(leaf_cert_buffer, leaf_cert_buffer_size,
+    1905                 :            :                                         base_asym_algo, base_hash_algo,
+    1906                 :            :                                         is_requester_cert, is_device_cert_model)) {
+    1907                 :          2 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+    1908                 :            :                        "!!! VerifyCertificateChainBuffer - FAIL (leaf certificate check failed)!!!\n"));
+    1909                 :          2 :         return false;
+    1910                 :            :     }
+    1911                 :            : 
+    1912                 :         29 :     return true;
+    1913                 :            : }
+    1914                 :            : 
+    1915                 :        205 : bool libspdm_get_leaf_cert_public_key_from_cert_chain(uint32_t base_hash_algo,
+    1916                 :            :                                                       uint32_t base_asym_alg,
+    1917                 :            :                                                       uint8_t *cert_chain_data,
+    1918                 :            :                                                       size_t cert_chain_data_size,
+    1919                 :            :                                                       void **public_key)
+    1920                 :            : {
+    1921                 :            :     size_t hash_size;
+    1922                 :            :     const uint8_t *cert_buffer;
+    1923                 :            :     size_t cert_buffer_size;
+    1924                 :            :     bool result;
+    1925                 :            : 
+    1926                 :        205 :     hash_size = libspdm_get_hash_size(base_hash_algo);
+    1927                 :            : 
+    1928                 :        205 :     cert_chain_data = cert_chain_data + sizeof(spdm_cert_chain_t) + hash_size;
+    1929                 :        205 :     cert_chain_data_size = cert_chain_data_size - (sizeof(spdm_cert_chain_t) + hash_size);
+    1930                 :            : 
+    1931                 :            :     /* Get leaf cert from cert chain */
+    1932                 :        205 :     result = libspdm_x509_get_cert_from_cert_chain(cert_chain_data,
+    1933                 :            :                                                    cert_chain_data_size, -1,
+    1934                 :            :                                                    &cert_buffer, &cert_buffer_size);
+    1935         [ -  + ]:        205 :     if (!result) {
+    1936                 :          0 :         return false;
+    1937                 :            :     }
+    1938                 :            : 
+    1939                 :        205 :     result = libspdm_asym_get_public_key_from_x509(
+    1940                 :            :         base_asym_alg,
+    1941                 :            :         cert_buffer, cert_buffer_size, public_key);
+    1942         [ +  + ]:        205 :     if (!result) {
+    1943                 :          3 :         return false;
+    1944                 :            :     }
+    1945                 :            : 
+    1946                 :        202 :     return true;
+    1947                 :            : }
+    1948                 :            : 
+    1949                 :         29 : bool libspdm_verify_req_info(uint8_t *req_info, uint16_t req_info_len)
+    1950                 :            : {
+    1951                 :            :     bool ret;
+    1952                 :            :     uint8_t *ptr;
+    1953                 :            :     int32_t length;
+    1954                 :            :     size_t obj_len;
+    1955                 :            :     uint8_t *end;
+    1956                 :            : 
+    1957                 :         29 :     length = (int32_t)req_info_len;
+    1958                 :         29 :     ptr = req_info;
+    1959                 :         29 :     obj_len = 0;
+    1960                 :         29 :     end = ptr + length;
+    1961                 :         29 :     ret = true;
+    1962                 :            : 
+    1963         [ +  + ]:         29 :     if (req_info_len == 0) {
+    1964                 :          4 :         return true;
+    1965                 :            :     }
+    1966                 :            : 
+    1967                 :            :     /*req_info sequence*/
+    1968                 :         25 :     ret = libspdm_asn1_get_tag(&ptr, end, &obj_len,
+    1969                 :            :                                LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
+    1970         [ +  + ]:         25 :     if (!ret) {
+    1971                 :          2 :         return false;
+    1972                 :            :     }
+    1973                 :            : 
+    1974                 :            :     /*integer:version*/
+    1975                 :         23 :     ret = libspdm_asn1_get_tag(&ptr, end, &obj_len, LIBSPDM_CRYPTO_ASN1_INTEGER);
+    1976         [ -  + ]:         23 :     if (!ret) {
+    1977                 :          0 :         return false;
+    1978                 :            :     } else {
+    1979                 :         23 :         ptr += obj_len;
+    1980                 :            :     }
+    1981                 :            : 
+    1982                 :            :     /*sequence:subject name*/
+    1983                 :         23 :     ret = libspdm_asn1_get_tag(&ptr, end, &obj_len,
+    1984                 :            :                                LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
+    1985         [ -  + ]:         23 :     if (!ret) {
+    1986                 :          0 :         return false;
+    1987                 :            :     } else {
+    1988                 :         23 :         ptr += obj_len;
+    1989                 :            :     }
+    1990                 :            : 
+    1991                 :            :     /*sequence:subject pkinfo*/
+    1992                 :         23 :     ret = libspdm_asn1_get_tag(&ptr, end, &obj_len,
+    1993                 :            :                                LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
+    1994         [ -  + ]:         23 :     if (!ret) {
+    1995                 :          0 :         return false;
+    1996                 :            :     } else {
+    1997                 :         23 :         ptr += obj_len;
+    1998                 :            :     }
+    1999                 :            : 
+    2000                 :            :     /*[0]: attributes*/
+    2001                 :         23 :     ret = libspdm_asn1_get_tag(&ptr, end, &obj_len,
+    2002                 :            :                                LIBSPDM_CRYPTO_ASN1_CONTEXT_SPECIFIC |
+    2003                 :            :                                LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
+    2004                 :            :     /*req_info format error, don't have attributes tag*/
+    2005         [ -  + ]:         23 :     if (!ret) {
+    2006                 :          0 :         return false;
+    2007                 :            :     }
+    2008                 :            : 
+    2009                 :            :     /*there is no attributes object*/
+    2010         [ -  + ]:         23 :     if (ptr == end) {
+    2011                 :          0 :         return true;
+    2012                 :            :     }
+    2013                 :            : 
+    2014                 :            :     /*there is some attributes object: 0,1,2 ...*/
+    2015         [ +  - ]:         46 :     while (ret)
+    2016                 :            :     {
+    2017                 :         46 :         ret = libspdm_asn1_get_tag(&ptr, end, &obj_len,
+    2018                 :            :                                    LIBSPDM_CRYPTO_ASN1_SEQUENCE |
+    2019                 :            :                                    LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
+    2020         [ +  + ]:         46 :         if (ret) {
+    2021                 :         23 :             ptr += obj_len;
+    2022                 :            :         } else {
+    2023                 :         23 :             break;
+    2024                 :            :         }
+    2025                 :            :     }
+    2026                 :            : 
+    2027         [ +  - ]:         23 :     if (ptr == end) {
+    2028                 :         23 :         return true;
+    2029                 :            :     } else {
+    2030                 :          0 :         return false;
+    2031                 :            :     }
+    2032                 :            : }
+    2033                 :            : 
+    2034                 :            : #endif
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/libspdm_crypt_dhe.c.func-sort-c.html b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_dhe.c.func-sort-c.html new file mode 100644 index 00000000000..484d58d4b1f --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_dhe.c.func-sort-c.html @@ -0,0 +1,105 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/libspdm_crypt_dhe.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib - libspdm_crypt_dhe.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:349137.4 %
Date:2024-09-22 08:21:07Functions:66100.0 %
Branches:113630.6 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_dhe_compute_key73
libspdm_dhe_free164
libspdm_dhe_generate_key164
libspdm_dhe_new164
libspdm_get_dhe_nid164
libspdm_get_dhe_pub_key_size956
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/libspdm_crypt_dhe.c.func.html b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_dhe.c.func.html new file mode 100644 index 00000000000..838237a17a3 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_dhe.c.func.html @@ -0,0 +1,105 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/libspdm_crypt_dhe.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib - libspdm_crypt_dhe.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:349137.4 %
Date:2024-09-22 08:21:07Functions:66100.0 %
Branches:113630.6 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_dhe_compute_key73
libspdm_dhe_free164
libspdm_dhe_generate_key164
libspdm_dhe_new164
libspdm_get_dhe_nid164
libspdm_get_dhe_pub_key_size956
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/libspdm_crypt_dhe.c.gcov.html b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_dhe.c.gcov.html new file mode 100644 index 00000000000..e2ad2fa0c34 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_dhe.c.gcov.html @@ -0,0 +1,438 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/libspdm_crypt_dhe.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib - libspdm_crypt_dhe.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:349137.4 %
Date:2024-09-22 08:21:07Functions:66100.0 %
Branches:113630.6 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 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_crypt_lib.h"
+       8                 :            : 
+       9                 :            : /**
+      10                 :            :  * This function returns the SPDM DHE algorithm key size.
+      11                 :            :  *
+      12                 :            :  * @param  dhe_named_group                SPDM dhe_named_group
+      13                 :            :  *
+      14                 :            :  * @return SPDM DHE algorithm key size.
+      15                 :            :  **/
+      16                 :        956 : uint32_t libspdm_get_dhe_pub_key_size(uint16_t dhe_named_group)
+      17                 :            : {
+      18   [ -  -  -  +  :        956 :     switch (dhe_named_group) {
+             +  +  -  + ]
+      19                 :          0 :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_FFDHE_2048:
+      20                 :            : #if LIBSPDM_FFDHE_2048_SUPPORT
+      21                 :          0 :         return 256;
+      22                 :            : #else
+      23                 :            :         return 0;
+      24                 :            : #endif
+      25                 :          0 :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_FFDHE_3072:
+      26                 :            : #if LIBSPDM_FFDHE_3072_SUPPORT
+      27                 :          0 :         return 384;
+      28                 :            : #else
+      29                 :            :         return 0;
+      30                 :            : #endif
+      31                 :          0 :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_FFDHE_4096:
+      32                 :            : #if LIBSPDM_FFDHE_4096_SUPPORT
+      33                 :          0 :         return 512;
+      34                 :            : #else
+      35                 :            :         return 0;
+      36                 :            : #endif
+      37                 :        772 :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_256_R1:
+      38                 :            : #if LIBSPDM_ECDHE_P256_SUPPORT
+      39                 :        772 :         return 32 * 2;
+      40                 :            : #else
+      41                 :            :         return 0;
+      42                 :            : #endif
+      43                 :          1 :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_384_R1:
+      44                 :            : #if LIBSPDM_ECDHE_P384_SUPPORT
+      45                 :          1 :         return 48 * 2;
+      46                 :            : #else
+      47                 :            :         return 0;
+      48                 :            : #endif
+      49                 :          1 :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_521_R1:
+      50                 :            : #if LIBSPDM_ECDHE_P521_SUPPORT
+      51                 :          1 :         return 66 * 2;
+      52                 :            : #else
+      53                 :            :         return 0;
+      54                 :            : #endif
+      55                 :          0 :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_SM2_P256:
+      56                 :            : #if LIBSPDM_SM2_KEY_EXCHANGE_P256_SUPPORT
+      57                 :            :         return 32 * 2;
+      58                 :            : #else
+      59                 :          0 :         return 0;
+      60                 :            : #endif
+      61                 :        182 :     default:
+      62                 :        182 :         return 0;
+      63                 :            :     }
+      64                 :            : }
+      65                 :            : 
+      66                 :            : /**
+      67                 :            :  * Return cipher ID, based upon the negotiated DHE algorithm.
+      68                 :            :  *
+      69                 :            :  * @param  dhe_named_group                SPDM dhe_named_group
+      70                 :            :  *
+      71                 :            :  * @return DHE cipher ID
+      72                 :            :  **/
+      73                 :        164 : static size_t libspdm_get_dhe_nid(uint16_t dhe_named_group)
+      74                 :            : {
+      75   [ -  -  -  +  :        164 :     switch (dhe_named_group) {
+             -  -  -  - ]
+      76                 :          0 :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_FFDHE_2048:
+      77                 :          0 :         return LIBSPDM_CRYPTO_NID_FFDHE2048;
+      78                 :          0 :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_FFDHE_3072:
+      79                 :          0 :         return LIBSPDM_CRYPTO_NID_FFDHE3072;
+      80                 :          0 :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_FFDHE_4096:
+      81                 :          0 :         return LIBSPDM_CRYPTO_NID_FFDHE4096;
+      82                 :        164 :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_256_R1:
+      83                 :        164 :         return LIBSPDM_CRYPTO_NID_SECP256R1;
+      84                 :          0 :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_384_R1:
+      85                 :          0 :         return LIBSPDM_CRYPTO_NID_SECP384R1;
+      86                 :          0 :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_521_R1:
+      87                 :          0 :         return LIBSPDM_CRYPTO_NID_SECP521R1;
+      88                 :          0 :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_SM2_P256:
+      89                 :          0 :         return LIBSPDM_CRYPTO_NID_SM2_KEY_EXCHANGE_P256;
+      90                 :          0 :     default:
+      91                 :          0 :         return LIBSPDM_CRYPTO_NID_NULL;
+      92                 :            :     }
+      93                 :            : }
+      94                 :            : 
+      95                 :        164 : void *libspdm_dhe_new(spdm_version_number_t spdm_version,
+      96                 :            :                       uint16_t dhe_named_group, bool is_initiator)
+      97                 :            : {
+      98                 :            :     size_t nid;
+      99                 :            : #if LIBSPDM_SM2_KEY_EXCHANGE_SUPPORT
+     100                 :            :     void *context;
+     101                 :            :     bool result;
+     102                 :            :     uint8_t spdm12_key_change_requester_context[
+     103                 :            :         SPDM_VERSION_1_2_KEY_EXCHANGE_REQUESTER_CONTEXT_SIZE];
+     104                 :            :     uint8_t spdm12_key_change_responder_context[
+     105                 :            :         SPDM_VERSION_1_2_KEY_EXCHANGE_RESPONDER_CONTEXT_SIZE];
+     106                 :            : #endif /* LIBSPDM_SM2_KEY_EXCHANGE_SUPPORT */
+     107                 :            : 
+     108                 :        164 :     nid = libspdm_get_dhe_nid(dhe_named_group);
+     109         [ -  + ]:        164 :     if (nid == 0) {
+     110                 :          0 :         return NULL;
+     111                 :            :     }
+     112                 :            : 
+     113   [ -  +  -  - ]:        164 :     switch (dhe_named_group) {
+     114                 :          0 :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_FFDHE_2048:
+     115                 :            :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_FFDHE_3072:
+     116                 :            :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_FFDHE_4096:
+     117                 :            : #if LIBSPDM_FFDHE_SUPPORT
+     118                 :            : #if !LIBSPDM_FFDHE_2048_SUPPORT
+     119                 :            :         LIBSPDM_ASSERT(dhe_named_group != SPDM_ALGORITHMS_DHE_NAMED_GROUP_FFDHE_2048);
+     120                 :            : #endif
+     121                 :            : #if !LIBSPDM_FFDHE_3072_SUPPORT
+     122                 :            :         LIBSPDM_ASSERT(dhe_named_group != SPDM_ALGORITHMS_DHE_NAMED_GROUP_FFDHE_3072);
+     123                 :            : #endif
+     124                 :            : #if !LIBSPDM_FFDHE_4096_SUPPORT
+     125                 :            :         LIBSPDM_ASSERT(dhe_named_group != SPDM_ALGORITHMS_DHE_NAMED_GROUP_FFDHE_4096);
+     126                 :            : #endif
+     127                 :          0 :         return libspdm_dh_new_by_nid(nid);
+     128                 :            : #else
+     129                 :            :         LIBSPDM_ASSERT(false);
+     130                 :            :         return NULL;
+     131                 :            : #endif
+     132                 :            :         break;
+     133                 :        164 :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_256_R1:
+     134                 :            :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_384_R1:
+     135                 :            :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_521_R1:
+     136                 :            : #if LIBSPDM_ECDHE_SUPPORT
+     137                 :            : #if !LIBSPDM_ECDHE_P256_SUPPORT
+     138                 :            :         LIBSPDM_ASSERT(dhe_named_group != SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_256_R1);
+     139                 :            : #endif
+     140                 :            : #if !LIBSPDM_ECDHE_P384_SUPPORT
+     141                 :            :         LIBSPDM_ASSERT(dhe_named_group != SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_384_R1);
+     142                 :            : #endif
+     143                 :            : #if !LIBSPDM_ECDHE_P521_SUPPORT
+     144                 :            :         LIBSPDM_ASSERT(dhe_named_group != SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_521_R1);
+     145                 :            : #endif
+     146                 :        164 :         return libspdm_ec_new_by_nid(nid);
+     147                 :            : #else
+     148                 :            :         LIBSPDM_ASSERT(false);
+     149                 :            :         return NULL;
+     150                 :            : #endif
+     151                 :            :         break;
+     152                 :          0 :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_SM2_P256:
+     153                 :            : #if LIBSPDM_SM2_KEY_EXCHANGE_SUPPORT
+     154                 :            :         context = libspdm_sm2_key_exchange_new_by_nid(nid);
+     155                 :            : 
+     156                 :            :         libspdm_copy_mem(spdm12_key_change_requester_context,
+     157                 :            :                          sizeof(spdm12_key_change_requester_context),
+     158                 :            :                          SPDM_VERSION_1_2_KEY_EXCHANGE_REQUESTER_CONTEXT,
+     159                 :            :                          SPDM_VERSION_1_2_KEY_EXCHANGE_REQUESTER_CONTEXT_SIZE);
+     160                 :            :         libspdm_copy_mem(spdm12_key_change_responder_context,
+     161                 :            :                          sizeof(spdm12_key_change_responder_context),
+     162                 :            :                          SPDM_VERSION_1_2_KEY_EXCHANGE_RESPONDER_CONTEXT,
+     163                 :            :                          SPDM_VERSION_1_2_KEY_EXCHANGE_RESPONDER_CONTEXT_SIZE);
+     164                 :            :         /* patch the version*/
+     165                 :            :         spdm12_key_change_requester_context[25] = (char)('0' + ((spdm_version >> 12) & 0xF));
+     166                 :            :         spdm12_key_change_requester_context[27] = (char)('0' + ((spdm_version >> 8) & 0xF));
+     167                 :            :         spdm12_key_change_responder_context[25] = (char)('0' + ((spdm_version >> 12) & 0xF));
+     168                 :            :         spdm12_key_change_responder_context[27] = (char)('0' + ((spdm_version >> 8) & 0xF));
+     169                 :            : 
+     170                 :            :         result = libspdm_sm2_key_exchange_init (context, LIBSPDM_CRYPTO_NID_SM3_256,
+     171                 :            :                                                 spdm12_key_change_requester_context,
+     172                 :            :                                                 SPDM_VERSION_1_2_KEY_EXCHANGE_REQUESTER_CONTEXT_SIZE,
+     173                 :            :                                                 spdm12_key_change_responder_context,
+     174                 :            :                                                 SPDM_VERSION_1_2_KEY_EXCHANGE_RESPONDER_CONTEXT_SIZE,
+     175                 :            :                                                 is_initiator);
+     176                 :            :         if (!result) {
+     177                 :            :             libspdm_sm2_key_exchange_free (context);
+     178                 :            :             return NULL;
+     179                 :            :         }
+     180                 :            :         return context;
+     181                 :            : #else
+     182                 :          0 :         LIBSPDM_ASSERT(false);
+     183                 :          0 :         return NULL;
+     184                 :            : #endif
+     185                 :            :         break;
+     186                 :          0 :     default:
+     187                 :          0 :         LIBSPDM_ASSERT(false);
+     188                 :          0 :         return NULL;
+     189                 :            :     }
+     190                 :            : }
+     191                 :            : 
+     192                 :        164 : void libspdm_dhe_free(uint16_t dhe_named_group, void *context)
+     193                 :            : {
+     194         [ -  + ]:        164 :     if (context == NULL) {
+     195                 :          0 :         return;
+     196                 :            :     }
+     197   [ -  +  -  - ]:        164 :     switch (dhe_named_group) {
+     198                 :          0 :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_FFDHE_2048:
+     199                 :            :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_FFDHE_3072:
+     200                 :            :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_FFDHE_4096:
+     201                 :            : #if LIBSPDM_FFDHE_SUPPORT
+     202                 :          0 :         libspdm_dh_free(context);
+     203                 :            : #else
+     204                 :            :         LIBSPDM_ASSERT(false);
+     205                 :            : #endif
+     206                 :          0 :         break;
+     207                 :        164 :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_256_R1:
+     208                 :            :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_384_R1:
+     209                 :            :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_521_R1:
+     210                 :            : #if LIBSPDM_ECDHE_SUPPORT
+     211                 :        164 :         libspdm_ec_free(context);
+     212                 :            : #else
+     213                 :            :         LIBSPDM_ASSERT(false);
+     214                 :            : #endif
+     215                 :        164 :         break;
+     216                 :          0 :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_SM2_P256:
+     217                 :            : #if LIBSPDM_SM2_KEY_EXCHANGE_SUPPORT
+     218                 :            :         libspdm_sm2_key_exchange_free(context);
+     219                 :            : #else
+     220                 :          0 :         LIBSPDM_ASSERT(false);
+     221                 :            : #endif
+     222                 :          0 :         break;
+     223                 :          0 :     default:
+     224                 :          0 :         LIBSPDM_ASSERT(false);
+     225                 :          0 :         break;
+     226                 :            :     }
+     227                 :            : }
+     228                 :            : 
+     229                 :        164 : bool libspdm_dhe_generate_key(uint16_t dhe_named_group, void *context,
+     230                 :            :                               uint8_t *public_key,
+     231                 :            :                               size_t *public_key_size)
+     232                 :            : {
+     233   [ -  +  -  - ]:        164 :     switch (dhe_named_group) {
+     234                 :          0 :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_FFDHE_2048:
+     235                 :            :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_FFDHE_3072:
+     236                 :            :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_FFDHE_4096:
+     237                 :            : #if LIBSPDM_FFDHE_SUPPORT
+     238                 :            : #if !LIBSPDM_FFDHE_2048_SUPPORT
+     239                 :            :         LIBSPDM_ASSERT(dhe_named_group != SPDM_ALGORITHMS_DHE_NAMED_GROUP_FFDHE_2048);
+     240                 :            : #endif
+     241                 :            : #if !LIBSPDM_FFDHE_3072_SUPPORT
+     242                 :            :         LIBSPDM_ASSERT(dhe_named_group != SPDM_ALGORITHMS_DHE_NAMED_GROUP_FFDHE_3072);
+     243                 :            : #endif
+     244                 :            : #if !LIBSPDM_FFDHE_4096_SUPPORT
+     245                 :            :         LIBSPDM_ASSERT(dhe_named_group != SPDM_ALGORITHMS_DHE_NAMED_GROUP_FFDHE_4096);
+     246                 :            : #endif
+     247                 :          0 :         return libspdm_dh_generate_key(context, public_key, public_key_size);
+     248                 :            : #else
+     249                 :            :         LIBSPDM_ASSERT(false);
+     250                 :            :         return false;
+     251                 :            : #endif
+     252                 :        164 :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_256_R1:
+     253                 :            :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_384_R1:
+     254                 :            :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_521_R1:
+     255                 :            : #if LIBSPDM_ECDHE_SUPPORT
+     256                 :            : #if !LIBSPDM_ECDHE_P256_SUPPORT
+     257                 :            :         LIBSPDM_ASSERT(dhe_named_group != SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_256_R1);
+     258                 :            : #endif
+     259                 :            : #if !LIBSPDM_ECDHE_P384_SUPPORT
+     260                 :            :         LIBSPDM_ASSERT(dhe_named_group != SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_384_R1);
+     261                 :            : #endif
+     262                 :            : #if !LIBSPDM_ECDHE_P521_SUPPORT
+     263                 :            :         LIBSPDM_ASSERT(dhe_named_group != SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_521_R1);
+     264                 :            : #endif
+     265                 :        164 :         return libspdm_ec_generate_key(context, public_key, public_key_size);
+     266                 :            : #else
+     267                 :            :         LIBSPDM_ASSERT(false);
+     268                 :            :         return false;
+     269                 :            : #endif
+     270                 :          0 :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_SM2_P256:
+     271                 :            : #if LIBSPDM_SM2_KEY_EXCHANGE_SUPPORT
+     272                 :            :         return libspdm_sm2_key_exchange_generate_key(context, public_key, public_key_size);
+     273                 :            : #else
+     274                 :          0 :         LIBSPDM_ASSERT(false);
+     275                 :          0 :         return false;
+     276                 :            : #endif
+     277                 :          0 :     default:
+     278                 :          0 :         LIBSPDM_ASSERT(false);
+     279                 :          0 :         return false;
+     280                 :            :     }
+     281                 :            : }
+     282                 :            : 
+     283                 :         73 : bool libspdm_dhe_compute_key(uint16_t dhe_named_group, void *context,
+     284                 :            :                              const uint8_t *peer_public,
+     285                 :            :                              size_t peer_public_size, uint8_t *key,
+     286                 :            :                              size_t *key_size)
+     287                 :            : {
+     288                 :            : #if LIBSPDM_SM2_KEY_EXCHANGE_SUPPORT
+     289                 :            :     bool ret;
+     290                 :            : #endif
+     291                 :            : 
+     292   [ -  +  -  - ]:         73 :     switch (dhe_named_group) {
+     293                 :          0 :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_FFDHE_2048:
+     294                 :            :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_FFDHE_3072:
+     295                 :            :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_FFDHE_4096:
+     296                 :            : #if LIBSPDM_FFDHE_SUPPORT
+     297                 :            : #if !LIBSPDM_FFDHE_2048_SUPPORT
+     298                 :            :         LIBSPDM_ASSERT(dhe_named_group != SPDM_ALGORITHMS_DHE_NAMED_GROUP_FFDHE_2048);
+     299                 :            : #endif
+     300                 :            : #if !LIBSPDM_FFDHE_3072_SUPPORT
+     301                 :            :         LIBSPDM_ASSERT(dhe_named_group != SPDM_ALGORITHMS_DHE_NAMED_GROUP_FFDHE_3072);
+     302                 :            : #endif
+     303                 :            : #if !LIBSPDM_FFDHE_4096_SUPPORT
+     304                 :            :         LIBSPDM_ASSERT(dhe_named_group != SPDM_ALGORITHMS_DHE_NAMED_GROUP_FFDHE_4096);
+     305                 :            : #endif
+     306                 :          0 :         return libspdm_dh_compute_key(context, peer_public, peer_public_size, key, key_size);
+     307                 :            : #else
+     308                 :            :         LIBSPDM_ASSERT(false);
+     309                 :            :         return false;
+     310                 :            : #endif
+     311                 :         73 :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_256_R1:
+     312                 :            :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_384_R1:
+     313                 :            :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_521_R1:
+     314                 :            : #if LIBSPDM_ECDHE_SUPPORT
+     315                 :            : #if !LIBSPDM_ECDHE_P256_SUPPORT
+     316                 :            :         LIBSPDM_ASSERT(dhe_named_group != SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_256_R1);
+     317                 :            : #endif
+     318                 :            : #if !LIBSPDM_ECDHE_P384_SUPPORT
+     319                 :            :         LIBSPDM_ASSERT(dhe_named_group != SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_384_R1);
+     320                 :            : #endif
+     321                 :            : #if !LIBSPDM_ECDHE_P521_SUPPORT
+     322                 :            :         LIBSPDM_ASSERT(dhe_named_group != SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_521_R1);
+     323                 :            : #endif
+     324                 :         73 :         return libspdm_ec_compute_key(context, peer_public, peer_public_size, key, key_size);
+     325                 :            : #else
+     326                 :            :         LIBSPDM_ASSERT(false);
+     327                 :            :         return false;
+     328                 :            : #endif
+     329                 :          0 :     case SPDM_ALGORITHMS_DHE_NAMED_GROUP_SM2_P256:
+     330                 :            : #if LIBSPDM_SM2_KEY_EXCHANGE_SUPPORT
+     331                 :            :         ret = libspdm_sm2_key_exchange_compute_key(context, peer_public,
+     332                 :            :                                                    peer_public_size, key, key_size);
+     333                 :            :         if (!ret) {
+     334                 :            :             return false;
+     335                 :            :         } else {
+     336                 :            :             /* SM2 key exchange can generate arbitrary length key_size.
+     337                 :            :              * SPDM requires SM2 key_size to be 16. */
+     338                 :            :             LIBSPDM_ASSERT (*key_size >= 16);
+     339                 :            :             *key_size = 16;
+     340                 :            : 
+     341                 :            :             return true;
+     342                 :            :         }
+     343                 :            : #else
+     344                 :          0 :         LIBSPDM_ASSERT(false);
+     345                 :          0 :         return false;
+     346                 :            : #endif
+     347                 :          0 :     default:
+     348                 :          0 :         LIBSPDM_ASSERT(false);
+     349                 :          0 :         return false;
+     350                 :            :     }
+     351                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/libspdm_crypt_hash.c.func-sort-c.html b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_hash.c.func-sort-c.html new file mode 100644 index 00000000000..00c237d9c34 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_hash.c.func-sort-c.html @@ -0,0 +1,121 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/libspdm_crypt_hash.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib - libspdm_crypt_hash.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:5021623.1 %
Date:2024-09-22 08:21:07Functions:1010100.0 %
Branches:158018.8 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_hash_nid241
libspdm_hash_final368
libspdm_hash_duplicate390
libspdm_hash_init424
libspdm_hash_free771
libspdm_hash_new814
libspdm_hash_all1637
libspdm_get_measurement_hash_size1686
libspdm_get_hash_size4285
libspdm_hash_update10536
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/libspdm_crypt_hash.c.func.html b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_hash.c.func.html new file mode 100644 index 00000000000..7faad094632 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_hash.c.func.html @@ -0,0 +1,121 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/libspdm_crypt_hash.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib - libspdm_crypt_hash.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:5021623.1 %
Date:2024-09-22 08:21:07Functions:1010100.0 %
Branches:158018.8 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_hash_nid241
libspdm_get_hash_size4285
libspdm_get_measurement_hash_size1686
libspdm_hash_all1637
libspdm_hash_duplicate390
libspdm_hash_final368
libspdm_hash_free771
libspdm_hash_init424
libspdm_hash_new814
libspdm_hash_update10536
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/libspdm_crypt_hash.c.gcov.html b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_hash.c.gcov.html new file mode 100644 index 00000000000..3a5a10f2b2a --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_hash.c.gcov.html @@ -0,0 +1,606 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/libspdm_crypt_hash.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib - libspdm_crypt_hash.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:5021623.1 %
Date:2024-09-22 08:21:07Functions:1010100.0 %
Branches:158018.8 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 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_crypt_lib.h"
+       8                 :            : 
+       9                 :       4285 : uint32_t libspdm_get_hash_size(uint32_t base_hash_algo)
+      10                 :            : {
+      11   [ +  -  -  -  :       4285 :     switch (base_hash_algo) {
+             +  +  -  + ]
+      12                 :       4112 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256:
+      13                 :            : #if LIBSPDM_SHA256_SUPPORT
+      14                 :       4112 :         return 32;
+      15                 :            : #else
+      16                 :            :         return 0;
+      17                 :            : #endif
+      18                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_256:
+      19                 :            : #if LIBSPDM_SHA3_256_SUPPORT
+      20                 :            :         return 32;
+      21                 :            : #else
+      22                 :          0 :         return 0;
+      23                 :            : #endif
+      24                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_384:
+      25                 :            : #if LIBSPDM_SHA384_SUPPORT
+      26                 :          0 :         return 48;
+      27                 :            : #else
+      28                 :            :         return 0;
+      29                 :            : #endif
+      30                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_384:
+      31                 :            : #if LIBSPDM_SHA3_384_SUPPORT
+      32                 :            :         return 48;
+      33                 :            : #else
+      34                 :          0 :         return 0;
+      35                 :            : #endif
+      36                 :          1 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512:
+      37                 :            : #if LIBSPDM_SHA512_SUPPORT
+      38                 :          1 :         return 64;
+      39                 :            : #else
+      40                 :            :         return 0;
+      41                 :            : #endif
+      42                 :          1 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_512:
+      43                 :            : #if LIBSPDM_SHA3_512_SUPPORT
+      44                 :            :         return 64;
+      45                 :            : #else
+      46                 :          1 :         return 0;
+      47                 :            : #endif
+      48                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SM3_256:
+      49                 :            : #if LIBSPDM_SM3_256_SUPPORT
+      50                 :            :         return 32;
+      51                 :            : #else
+      52                 :          0 :         return 0;
+      53                 :            : #endif
+      54                 :        171 :     default:
+      55                 :        171 :         return 0;
+      56                 :            :     }
+      57                 :            : }
+      58                 :            : 
+      59                 :        241 : size_t libspdm_get_hash_nid(uint32_t base_hash_algo)
+      60                 :            : {
+      61   [ +  -  -  -  :        241 :     switch (base_hash_algo) {
+             -  -  -  - ]
+      62                 :        241 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256:
+      63                 :        241 :         return LIBSPDM_CRYPTO_NID_SHA256;
+      64                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_384:
+      65                 :          0 :         return LIBSPDM_CRYPTO_NID_SHA384;
+      66                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512:
+      67                 :          0 :         return LIBSPDM_CRYPTO_NID_SHA512;
+      68                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_256:
+      69                 :          0 :         return LIBSPDM_CRYPTO_NID_SHA3_256;
+      70                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_384:
+      71                 :          0 :         return LIBSPDM_CRYPTO_NID_SHA3_384;
+      72                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_512:
+      73                 :          0 :         return LIBSPDM_CRYPTO_NID_SHA3_512;
+      74                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SM3_256:
+      75                 :          0 :         return LIBSPDM_CRYPTO_NID_SM3_256;
+      76                 :          0 :     default:
+      77                 :          0 :         return LIBSPDM_CRYPTO_NID_NULL;
+      78                 :            :     }
+      79                 :            : }
+      80                 :            : 
+      81                 :        814 : void *libspdm_hash_new(uint32_t base_hash_algo)
+      82                 :            : {
+      83   [ +  -  -  -  :        814 :     switch (base_hash_algo) {
+             -  -  -  - ]
+      84                 :        814 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256:
+      85                 :            : #if LIBSPDM_SHA256_SUPPORT
+      86                 :        814 :         return libspdm_sha256_new();
+      87                 :            : #else
+      88                 :            :         LIBSPDM_ASSERT(false);
+      89                 :            :         return NULL;
+      90                 :            : #endif
+      91                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_384:
+      92                 :            : #if LIBSPDM_SHA384_SUPPORT
+      93                 :          0 :         return libspdm_sha384_new();
+      94                 :            : #else
+      95                 :            :         LIBSPDM_ASSERT(false);
+      96                 :            :         return NULL;
+      97                 :            : #endif
+      98                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512:
+      99                 :            : #if LIBSPDM_SHA512_SUPPORT
+     100                 :          0 :         return libspdm_sha512_new();
+     101                 :            : #else
+     102                 :            :         LIBSPDM_ASSERT(false);
+     103                 :            :         return NULL;
+     104                 :            : #endif
+     105                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_256:
+     106                 :            : #if LIBSPDM_SHA3_256_SUPPORT
+     107                 :            :         return libspdm_sha3_256_new();
+     108                 :            : #else
+     109                 :          0 :         LIBSPDM_ASSERT(false);
+     110                 :          0 :         return NULL;
+     111                 :            : #endif
+     112                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_384:
+     113                 :            : #if LIBSPDM_SHA3_384_SUPPORT
+     114                 :            :         return libspdm_sha3_384_new();
+     115                 :            : #else
+     116                 :          0 :         LIBSPDM_ASSERT(false);
+     117                 :          0 :         return NULL;
+     118                 :            : #endif
+     119                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_512:
+     120                 :            : #if LIBSPDM_SHA3_512_SUPPORT
+     121                 :            :         return libspdm_sha3_512_new();
+     122                 :            : #else
+     123                 :          0 :         LIBSPDM_ASSERT(false);
+     124                 :          0 :         return NULL;
+     125                 :            : #endif
+     126                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SM3_256:
+     127                 :            : #if LIBSPDM_SM3_256_SUPPORT
+     128                 :            :         return libspdm_sm3_256_new();
+     129                 :            : #else
+     130                 :          0 :         LIBSPDM_ASSERT(false);
+     131                 :          0 :         return NULL;
+     132                 :            : #endif
+     133                 :          0 :     default:
+     134                 :          0 :         LIBSPDM_ASSERT(false);
+     135                 :          0 :         return NULL;
+     136                 :            :     }
+     137                 :            : }
+     138                 :            : 
+     139                 :        771 : void libspdm_hash_free(uint32_t base_hash_algo, void *hash_context)
+     140                 :            : {
+     141         [ -  + ]:        771 :     if (hash_context == NULL) {
+     142                 :          0 :         return;
+     143                 :            :     }
+     144   [ +  -  -  -  :        771 :     switch (base_hash_algo) {
+             -  -  -  - ]
+     145                 :        771 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256:
+     146                 :            : #if LIBSPDM_SHA256_SUPPORT
+     147                 :        771 :         libspdm_sha256_free(hash_context);
+     148                 :            : #else
+     149                 :            :         LIBSPDM_ASSERT(false);
+     150                 :            : #endif
+     151                 :        771 :         break;
+     152                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_384:
+     153                 :            : #if LIBSPDM_SHA384_SUPPORT
+     154                 :          0 :         libspdm_sha384_free(hash_context);
+     155                 :            : #else
+     156                 :            :         LIBSPDM_ASSERT(false);
+     157                 :            : #endif
+     158                 :          0 :         break;
+     159                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512:
+     160                 :            : #if LIBSPDM_SHA512_SUPPORT
+     161                 :          0 :         libspdm_sha512_free(hash_context);
+     162                 :            : #else
+     163                 :            :         LIBSPDM_ASSERT(false);
+     164                 :            : #endif
+     165                 :          0 :         break;
+     166                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_256:
+     167                 :            : #if LIBSPDM_SHA3_256_SUPPORT
+     168                 :            :         libspdm_sha3_256_free(hash_context);
+     169                 :            : #else
+     170                 :          0 :         LIBSPDM_ASSERT(false);
+     171                 :            : #endif
+     172                 :          0 :         break;
+     173                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_384:
+     174                 :            : #if LIBSPDM_SHA3_384_SUPPORT
+     175                 :            :         libspdm_sha3_384_free(hash_context);
+     176                 :            : #else
+     177                 :          0 :         LIBSPDM_ASSERT(false);
+     178                 :            : #endif
+     179                 :          0 :         break;
+     180                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_512:
+     181                 :            : #if LIBSPDM_SHA3_512_SUPPORT
+     182                 :            :         libspdm_sha3_512_free(hash_context);
+     183                 :            : #else
+     184                 :          0 :         LIBSPDM_ASSERT(false);
+     185                 :            : #endif
+     186                 :          0 :         break;
+     187                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SM3_256:
+     188                 :            : #if LIBSPDM_SM3_256_SUPPORT
+     189                 :            :         libspdm_sm3_256_free(hash_context);
+     190                 :            : #else
+     191                 :          0 :         LIBSPDM_ASSERT(false);
+     192                 :            : #endif
+     193                 :          0 :         break;
+     194                 :          0 :     default:
+     195                 :          0 :         LIBSPDM_ASSERT(false);
+     196                 :          0 :         break;
+     197                 :            :     }
+     198                 :            : }
+     199                 :            : 
+     200                 :        424 : bool libspdm_hash_init(uint32_t base_hash_algo, void *hash_context)
+     201                 :            : {
+     202   [ +  -  -  -  :        424 :     switch (base_hash_algo) {
+             -  -  -  - ]
+     203                 :        424 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256:
+     204                 :            : #if LIBSPDM_SHA256_SUPPORT
+     205                 :        424 :         return libspdm_sha256_init(hash_context);
+     206                 :            : #else
+     207                 :            :         LIBSPDM_ASSERT(false);
+     208                 :            :         return false;
+     209                 :            : #endif
+     210                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_384:
+     211                 :            : #if LIBSPDM_SHA384_SUPPORT
+     212                 :          0 :         return libspdm_sha384_init(hash_context);
+     213                 :            : #else
+     214                 :            :         LIBSPDM_ASSERT(false);
+     215                 :            :         return false;
+     216                 :            : #endif
+     217                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512:
+     218                 :            : #if LIBSPDM_SHA512_SUPPORT
+     219                 :          0 :         return libspdm_sha512_init(hash_context);
+     220                 :            : #else
+     221                 :            :         LIBSPDM_ASSERT(false);
+     222                 :            :         return false;
+     223                 :            : #endif
+     224                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_256:
+     225                 :            : #if LIBSPDM_SHA3_256_SUPPORT
+     226                 :            :         return libspdm_sha3_256_init(hash_context);
+     227                 :            : #else
+     228                 :          0 :         LIBSPDM_ASSERT(false);
+     229                 :          0 :         return false;
+     230                 :            : #endif
+     231                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_384:
+     232                 :            : #if LIBSPDM_SHA3_384_SUPPORT
+     233                 :            :         return libspdm_sha3_384_init(hash_context);
+     234                 :            : #else
+     235                 :          0 :         LIBSPDM_ASSERT(false);
+     236                 :          0 :         return false;
+     237                 :            : #endif
+     238                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_512:
+     239                 :            : #if LIBSPDM_SHA3_512_SUPPORT
+     240                 :            :         return libspdm_sha3_512_init(hash_context);
+     241                 :            : #else
+     242                 :          0 :         LIBSPDM_ASSERT(false);
+     243                 :          0 :         return false;
+     244                 :            : #endif
+     245                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SM3_256:
+     246                 :            : #if LIBSPDM_SM3_256_SUPPORT
+     247                 :            :         return libspdm_sm3_256_init(hash_context);
+     248                 :            : #else
+     249                 :          0 :         LIBSPDM_ASSERT(false);
+     250                 :          0 :         return false;
+     251                 :            : #endif
+     252                 :          0 :     default:
+     253                 :          0 :         LIBSPDM_ASSERT(false);
+     254                 :          0 :         return false;
+     255                 :            :     }
+     256                 :            : }
+     257                 :            : 
+     258                 :        390 : bool libspdm_hash_duplicate(uint32_t base_hash_algo, const void *hash_ctx, void *new_hash_ctx)
+     259                 :            : {
+     260   [ +  -  -  -  :        390 :     switch (base_hash_algo) {
+             -  -  -  - ]
+     261                 :        390 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256:
+     262                 :            : #if LIBSPDM_SHA256_SUPPORT
+     263                 :        390 :         return libspdm_sha256_duplicate(hash_ctx, new_hash_ctx);
+     264                 :            : #else
+     265                 :            :         LIBSPDM_ASSERT(false);
+     266                 :            :         return false;
+     267                 :            : #endif
+     268                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_384:
+     269                 :            : #if LIBSPDM_SHA384_SUPPORT
+     270                 :          0 :         return libspdm_sha384_duplicate(hash_ctx, new_hash_ctx);
+     271                 :            : #else
+     272                 :            :         LIBSPDM_ASSERT(false);
+     273                 :            :         return false;
+     274                 :            : #endif
+     275                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512:
+     276                 :            : #if LIBSPDM_SHA512_SUPPORT
+     277                 :          0 :         return libspdm_sha512_duplicate(hash_ctx, new_hash_ctx);
+     278                 :            : #else
+     279                 :            :         LIBSPDM_ASSERT(false);
+     280                 :            :         return false;
+     281                 :            : #endif
+     282                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_256:
+     283                 :            : #if LIBSPDM_SHA3_256_SUPPORT
+     284                 :            :         return libspdm_sha3_256_duplicate(hash_ctx, new_hash_ctx);
+     285                 :            : #else
+     286                 :          0 :         LIBSPDM_ASSERT(false);
+     287                 :          0 :         return false;
+     288                 :            : #endif
+     289                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_384:
+     290                 :            : #if LIBSPDM_SHA3_384_SUPPORT
+     291                 :            :         return libspdm_sha3_384_duplicate(hash_ctx, new_hash_ctx);
+     292                 :            : #else
+     293                 :          0 :         LIBSPDM_ASSERT(false);
+     294                 :          0 :         return false;
+     295                 :            : #endif
+     296                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_512:
+     297                 :            : #if LIBSPDM_SHA3_512_SUPPORT
+     298                 :            :         return libspdm_sha3_512_duplicate(hash_ctx, new_hash_ctx);
+     299                 :            : #else
+     300                 :          0 :         LIBSPDM_ASSERT(false);
+     301                 :          0 :         return false;
+     302                 :            : #endif
+     303                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SM3_256:
+     304                 :            : #if LIBSPDM_SM3_256_SUPPORT
+     305                 :            :         return libspdm_sm3_256_duplicate(hash_ctx, new_hash_ctx);
+     306                 :            : #else
+     307                 :          0 :         LIBSPDM_ASSERT(false);
+     308                 :          0 :         return false;
+     309                 :            : #endif
+     310                 :          0 :     default:
+     311                 :          0 :         LIBSPDM_ASSERT(false);
+     312                 :          0 :         return false;
+     313                 :            :     }
+     314                 :            : }
+     315                 :            : 
+     316                 :      10536 : bool libspdm_hash_update(uint32_t base_hash_algo, void *hash_context,
+     317                 :            :                          const void *data, size_t data_size)
+     318                 :            : {
+     319   [ +  -  -  -  :      10536 :     switch (base_hash_algo) {
+             -  -  -  - ]
+     320                 :      10536 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256:
+     321                 :            : #if LIBSPDM_SHA256_SUPPORT
+     322                 :      10536 :         return libspdm_sha256_update(hash_context, data, data_size);
+     323                 :            : #else
+     324                 :            :         LIBSPDM_ASSERT(false);
+     325                 :            :         return false;
+     326                 :            : #endif
+     327                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_384:
+     328                 :            : #if LIBSPDM_SHA384_SUPPORT
+     329                 :          0 :         return libspdm_sha384_update(hash_context, data, data_size);
+     330                 :            : #else
+     331                 :            :         LIBSPDM_ASSERT(false);
+     332                 :            :         return false;
+     333                 :            : #endif
+     334                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512:
+     335                 :            : #if LIBSPDM_SHA512_SUPPORT
+     336                 :          0 :         return libspdm_sha512_update(hash_context, data, data_size);
+     337                 :            : #else
+     338                 :            :         LIBSPDM_ASSERT(false);
+     339                 :            :         return false;
+     340                 :            : #endif
+     341                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_256:
+     342                 :            : #if LIBSPDM_SHA3_256_SUPPORT
+     343                 :            :         return libspdm_sha3_256_update(hash_context, data, data_size);
+     344                 :            : #else
+     345                 :          0 :         LIBSPDM_ASSERT(false);
+     346                 :          0 :         return false;
+     347                 :            : #endif
+     348                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_384:
+     349                 :            : #if LIBSPDM_SHA3_384_SUPPORT
+     350                 :            :         return libspdm_sha3_384_update(hash_context, data, data_size);
+     351                 :            : #else
+     352                 :          0 :         LIBSPDM_ASSERT(false);
+     353                 :          0 :         return false;
+     354                 :            : #endif
+     355                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_512:
+     356                 :            : #if LIBSPDM_SHA3_512_SUPPORT
+     357                 :            :         return libspdm_sha3_512_update(hash_context, data, data_size);
+     358                 :            : #else
+     359                 :          0 :         LIBSPDM_ASSERT(false);
+     360                 :          0 :         return false;
+     361                 :            : #endif
+     362                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SM3_256:
+     363                 :            : #if LIBSPDM_SM3_256_SUPPORT
+     364                 :            :         return libspdm_sm3_256_update(hash_context, data, data_size);
+     365                 :            : #else
+     366                 :          0 :         LIBSPDM_ASSERT(false);
+     367                 :          0 :         return false;
+     368                 :            : #endif
+     369                 :          0 :     default:
+     370                 :          0 :         LIBSPDM_ASSERT(false);
+     371                 :          0 :         return false;
+     372                 :            :     }
+     373                 :            : }
+     374                 :            : 
+     375                 :        368 : bool libspdm_hash_final(uint32_t base_hash_algo, void *hash_context, uint8_t *hash_value)
+     376                 :            : {
+     377   [ +  -  -  -  :        368 :     switch (base_hash_algo) {
+             -  -  -  - ]
+     378                 :        368 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256:
+     379                 :            : #if LIBSPDM_SHA256_SUPPORT
+     380                 :        368 :         return libspdm_sha256_final(hash_context, hash_value);
+     381                 :            : #else
+     382                 :            :         LIBSPDM_ASSERT(false);
+     383                 :            :         return false;
+     384                 :            : #endif
+     385                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_384:
+     386                 :            : #if LIBSPDM_SHA384_SUPPORT
+     387                 :          0 :         return libspdm_sha384_final(hash_context, hash_value);
+     388                 :            : #else
+     389                 :            :         LIBSPDM_ASSERT(false);
+     390                 :            :         return false;
+     391                 :            : #endif
+     392                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512:
+     393                 :            : #if LIBSPDM_SHA512_SUPPORT
+     394                 :          0 :         return libspdm_sha512_final(hash_context, hash_value);
+     395                 :            : #else
+     396                 :            :         LIBSPDM_ASSERT(false);
+     397                 :            :         return false;
+     398                 :            : #endif
+     399                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_256:
+     400                 :            : #if LIBSPDM_SHA3_256_SUPPORT
+     401                 :            :         return libspdm_sha3_256_final(hash_context, hash_value);
+     402                 :            : #else
+     403                 :          0 :         LIBSPDM_ASSERT(false);
+     404                 :          0 :         return false;
+     405                 :            : #endif
+     406                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_384:
+     407                 :            : #if LIBSPDM_SHA3_384_SUPPORT
+     408                 :            :         return libspdm_sha3_384_final(hash_context, hash_value);
+     409                 :            : #else
+     410                 :          0 :         LIBSPDM_ASSERT(false);
+     411                 :          0 :         return false;
+     412                 :            : #endif
+     413                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_512:
+     414                 :            : #if LIBSPDM_SHA3_512_SUPPORT
+     415                 :            :         return libspdm_sha3_512_final(hash_context, hash_value);
+     416                 :            : #else
+     417                 :          0 :         LIBSPDM_ASSERT(false);
+     418                 :          0 :         return false;
+     419                 :            : #endif
+     420                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SM3_256:
+     421                 :            : #if LIBSPDM_SM3_256_SUPPORT
+     422                 :            :         return libspdm_sm3_256_final(hash_context, hash_value);
+     423                 :            : #else
+     424                 :          0 :         LIBSPDM_ASSERT(false);
+     425                 :          0 :         return false;
+     426                 :            : #endif
+     427                 :          0 :     default:
+     428                 :          0 :         LIBSPDM_ASSERT(false);
+     429                 :          0 :         return false;
+     430                 :            :     }
+     431                 :            : }
+     432                 :            : 
+     433                 :       1637 : bool libspdm_hash_all(uint32_t base_hash_algo, const void *data,
+     434                 :            :                       size_t data_size, uint8_t *hash_value)
+     435                 :            : {
+     436   [ +  -  -  -  :       1637 :     switch (base_hash_algo) {
+             -  -  -  - ]
+     437                 :       1637 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256:
+     438                 :            : #if LIBSPDM_SHA256_SUPPORT
+     439                 :       1637 :         return libspdm_sha256_hash_all(data, data_size, hash_value);
+     440                 :            : #else
+     441                 :            :         LIBSPDM_ASSERT(false);
+     442                 :            :         return false;
+     443                 :            : #endif
+     444                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_384:
+     445                 :            : #if LIBSPDM_SHA384_SUPPORT
+     446                 :          0 :         return libspdm_sha384_hash_all(data, data_size, hash_value);
+     447                 :            : #else
+     448                 :            :         LIBSPDM_ASSERT(false);
+     449                 :            :         return false;
+     450                 :            : #endif
+     451                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512:
+     452                 :            : #if LIBSPDM_SHA512_SUPPORT
+     453                 :          0 :         return libspdm_sha512_hash_all(data, data_size, hash_value);
+     454                 :            : #else
+     455                 :            :         LIBSPDM_ASSERT(false);
+     456                 :            :         return false;
+     457                 :            : #endif
+     458                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_256:
+     459                 :            : #if LIBSPDM_SHA3_256_SUPPORT
+     460                 :            :         return libspdm_sha3_256_hash_all(data, data_size, hash_value);
+     461                 :            : #else
+     462                 :          0 :         LIBSPDM_ASSERT(false);
+     463                 :          0 :         return false;
+     464                 :            : #endif
+     465                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_384:
+     466                 :            : #if LIBSPDM_SHA3_384_SUPPORT
+     467                 :            :         return libspdm_sha3_384_hash_all(data, data_size, hash_value);
+     468                 :            : #else
+     469                 :          0 :         LIBSPDM_ASSERT(false);
+     470                 :          0 :         return false;
+     471                 :            : #endif
+     472                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_512:
+     473                 :            : #if LIBSPDM_SHA3_512_SUPPORT
+     474                 :            :         return libspdm_sha3_512_hash_all(data, data_size, hash_value);
+     475                 :            : #else
+     476                 :          0 :         LIBSPDM_ASSERT(false);
+     477                 :          0 :         return false;
+     478                 :            : #endif
+     479                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SM3_256:
+     480                 :            : #if LIBSPDM_SM3_256_SUPPORT
+     481                 :            :         return libspdm_sm3_256_hash_all(data, data_size, hash_value);
+     482                 :            : #else
+     483                 :          0 :         LIBSPDM_ASSERT(false);
+     484                 :          0 :         return false;
+     485                 :            : #endif
+     486                 :          0 :     default:
+     487                 :          0 :         LIBSPDM_ASSERT(false);
+     488                 :          0 :         return false;
+     489                 :            :     }
+     490                 :            : }
+     491                 :            : 
+     492                 :       1686 : uint32_t libspdm_get_measurement_hash_size(uint32_t measurement_hash_algo)
+     493                 :            : {
+     494   [ -  +  -  -  :       1686 :     switch (measurement_hash_algo) {
+                   -  + ]
+     495                 :          0 :     case SPDM_ALGORITHMS_MEASUREMENT_HASH_ALGO_TPM_ALG_SHA_256:
+     496                 :            :     case SPDM_ALGORITHMS_MEASUREMENT_HASH_ALGO_TPM_ALG_SHA3_256:
+     497                 :          0 :         return 32;
+     498                 :       1685 :     case SPDM_ALGORITHMS_MEASUREMENT_HASH_ALGO_TPM_ALG_SHA_384:
+     499                 :            :     case SPDM_ALGORITHMS_MEASUREMENT_HASH_ALGO_TPM_ALG_SHA3_384:
+     500                 :       1685 :         return 48;
+     501                 :          0 :     case SPDM_ALGORITHMS_MEASUREMENT_HASH_ALGO_TPM_ALG_SHA_512:
+     502                 :            :     case SPDM_ALGORITHMS_MEASUREMENT_HASH_ALGO_TPM_ALG_SHA3_512:
+     503                 :          0 :         return 64;
+     504                 :          0 :     case SPDM_ALGORITHMS_MEASUREMENT_HASH_ALGO_TPM_ALG_SM3_256:
+     505                 :          0 :         return 32;
+     506                 :          0 :     case SPDM_ALGORITHMS_MEASUREMENT_HASH_ALGO_RAW_BIT_STREAM_ONLY:
+     507                 :          0 :         return 0xFFFFFFFF;
+     508                 :          1 :     default:
+     509                 :          1 :         return 0;
+     510                 :            :     }
+     511                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/libspdm_crypt_hkdf.c.func-sort-c.html b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_hkdf.c.func-sort-c.html new file mode 100644 index 00000000000..6f8581fd7f7 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_hkdf.c.func-sort-c.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/libspdm_crypt_hkdf.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib - libspdm_crypt_hkdf.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:84617.4 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:21612.5 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_hkdf_extract188
libspdm_hkdf_expand1226
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/libspdm_crypt_hkdf.c.func.html b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_hkdf.c.func.html new file mode 100644 index 00000000000..bcf75ba35e4 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_hkdf.c.func.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/libspdm_crypt_hkdf.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib - libspdm_crypt_hkdf.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:84617.4 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:21612.5 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_hkdf_expand1226
libspdm_hkdf_extract188
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/libspdm_crypt_hkdf.c.gcov.html b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_hkdf.c.gcov.html new file mode 100644 index 00000000000..329670e1389 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_hkdf.c.gcov.html @@ -0,0 +1,214 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/libspdm_crypt_hkdf.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib - libspdm_crypt_hkdf.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:84617.4 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:21612.5 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 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_crypt_lib.h"
+       8                 :            : 
+       9                 :        188 : bool libspdm_hkdf_extract(uint32_t base_hash_algo, const uint8_t *ikm, size_t ikm_size,
+      10                 :            :                           const uint8_t *salt, size_t salt_size,
+      11                 :            :                           uint8_t *prk_out, size_t prk_out_size)
+      12                 :            : {
+      13   [ +  -  -  -  :        188 :     switch (base_hash_algo) {
+             -  -  -  - ]
+      14                 :        188 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256:
+      15                 :            : #if LIBSPDM_SHA256_SUPPORT
+      16                 :        188 :         return libspdm_hkdf_sha256_extract(ikm, ikm_size, salt, salt_size, prk_out, prk_out_size);
+      17                 :            : #else
+      18                 :            :         LIBSPDM_ASSERT(false);
+      19                 :            :         return false;
+      20                 :            : #endif
+      21                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_384:
+      22                 :            : #if LIBSPDM_SHA384_SUPPORT
+      23                 :          0 :         return libspdm_hkdf_sha384_extract(ikm, ikm_size, salt, salt_size, prk_out, prk_out_size);
+      24                 :            : #else
+      25                 :            :         LIBSPDM_ASSERT(false);
+      26                 :            :         return false;
+      27                 :            : #endif
+      28                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512:
+      29                 :            : #if LIBSPDM_SHA512_SUPPORT
+      30                 :          0 :         return libspdm_hkdf_sha512_extract(ikm, ikm_size, salt, salt_size, prk_out, prk_out_size);
+      31                 :            : #else
+      32                 :            :         LIBSPDM_ASSERT(false);
+      33                 :            :         return false;
+      34                 :            : #endif
+      35                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_256:
+      36                 :            : #if LIBSPDM_SHA3_256_SUPPORT
+      37                 :            :         return libspdm_hkdf_sha3_256_extract(ikm, ikm_size, salt, salt_size, prk_out, prk_out_size);
+      38                 :            : #else
+      39                 :          0 :         LIBSPDM_ASSERT(false);
+      40                 :          0 :         return false;
+      41                 :            : #endif
+      42                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_384:
+      43                 :            : #if LIBSPDM_SHA3_384_SUPPORT
+      44                 :            :         return libspdm_hkdf_sha3_384_extract(ikm, ikm_size, salt, salt_size, prk_out, prk_out_size);
+      45                 :            : #else
+      46                 :          0 :         LIBSPDM_ASSERT(false);
+      47                 :          0 :         return false;
+      48                 :            : #endif
+      49                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_512:
+      50                 :            : #if LIBSPDM_SHA3_512_SUPPORT
+      51                 :            :         return libspdm_hkdf_sha3_512_extract(ikm, ikm_size, salt, salt_size, prk_out, prk_out_size);
+      52                 :            : #else
+      53                 :          0 :         LIBSPDM_ASSERT(false);
+      54                 :          0 :         return false;
+      55                 :            : #endif
+      56                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SM3_256:
+      57                 :            : #if LIBSPDM_SM3_256_SUPPORT
+      58                 :            :         return libspdm_hkdf_sm3_256_extract(ikm, ikm_size, salt, salt_size, prk_out, prk_out_size);
+      59                 :            : #else
+      60                 :          0 :         LIBSPDM_ASSERT(false);
+      61                 :          0 :         return false;
+      62                 :            : #endif
+      63                 :          0 :     default:
+      64                 :          0 :         LIBSPDM_ASSERT(false);
+      65                 :          0 :         return false;
+      66                 :            :     }
+      67                 :            : }
+      68                 :            : 
+      69                 :       1226 : bool libspdm_hkdf_expand(uint32_t base_hash_algo, const uint8_t *prk,
+      70                 :            :                          size_t prk_size, const uint8_t *info,
+      71                 :            :                          size_t info_size, uint8_t *out, size_t out_size)
+      72                 :            : {
+      73   [ +  -  -  -  :       1226 :     switch (base_hash_algo) {
+             -  -  -  - ]
+      74                 :       1226 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256:
+      75                 :            : #if LIBSPDM_SHA256_SUPPORT
+      76                 :       1226 :         return libspdm_hkdf_sha256_expand(prk, prk_size, info, info_size, out, out_size);
+      77                 :            : #else
+      78                 :            :         LIBSPDM_ASSERT(false);
+      79                 :            :         return false;
+      80                 :            : #endif
+      81                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_384:
+      82                 :            : #if LIBSPDM_SHA384_SUPPORT
+      83                 :          0 :         return libspdm_hkdf_sha384_expand(prk, prk_size, info, info_size, out, out_size);
+      84                 :            : #else
+      85                 :            :         LIBSPDM_ASSERT(false);
+      86                 :            :         return false;
+      87                 :            : #endif
+      88                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512:
+      89                 :            : #if LIBSPDM_SHA512_SUPPORT
+      90                 :          0 :         return libspdm_hkdf_sha512_expand(prk, prk_size, info, info_size, out, out_size);
+      91                 :            : #else
+      92                 :            :         LIBSPDM_ASSERT(false);
+      93                 :            :         return false;
+      94                 :            : #endif
+      95                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_256:
+      96                 :            : #if LIBSPDM_SHA3_256_SUPPORT
+      97                 :            :         return libspdm_hkdf_sha3_256_expand(prk, prk_size, info, info_size, out, out_size);
+      98                 :            : #else
+      99                 :          0 :         LIBSPDM_ASSERT(false);
+     100                 :          0 :         return false;
+     101                 :            : #endif
+     102                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_384:
+     103                 :            : #if LIBSPDM_SHA3_384_SUPPORT
+     104                 :            :         return libspdm_hkdf_sha3_384_expand(prk, prk_size, info, info_size, out, out_size);
+     105                 :            : #else
+     106                 :          0 :         LIBSPDM_ASSERT(false);
+     107                 :          0 :         return false;
+     108                 :            : #endif
+     109                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_512:
+     110                 :            : #if LIBSPDM_SHA3_512_SUPPORT
+     111                 :            :         return libspdm_hkdf_sha3_512_expand(prk, prk_size, info, info_size, out, out_size);
+     112                 :            : #else
+     113                 :          0 :         LIBSPDM_ASSERT(false);
+     114                 :          0 :         return false;
+     115                 :            : #endif
+     116                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SM3_256:
+     117                 :            : #if LIBSPDM_SM3_256_SUPPORT
+     118                 :            :         return libspdm_hkdf_sm3_256_expand(prk, prk_size, info, info_size, out, out_size);
+     119                 :            : #else
+     120                 :          0 :         LIBSPDM_ASSERT(false);
+     121                 :          0 :         return false;
+     122                 :            : #endif
+     123                 :          0 :     default:
+     124                 :          0 :         LIBSPDM_ASSERT(false);
+     125                 :          0 :         return false;
+     126                 :            :     }
+     127                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/libspdm_crypt_hmac.c.func-sort-c.html b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_hmac.c.func-sort-c.html new file mode 100644 index 00000000000..0a438d6a9e4 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_hmac.c.func-sort-c.html @@ -0,0 +1,109 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/libspdm_crypt_hmac.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib - libspdm_crypt_hmac.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:41662.4 %
Date:2024-09-22 08:21:07Functions:1714.3 %
Branches:1581.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_hmac_duplicate0
libspdm_hmac_final0
libspdm_hmac_free0
libspdm_hmac_init0
libspdm_hmac_new0
libspdm_hmac_update0
libspdm_hmac_all316
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/libspdm_crypt_hmac.c.func.html b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_hmac.c.func.html new file mode 100644 index 00000000000..f0e22fb2fae --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_hmac.c.func.html @@ -0,0 +1,109 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/libspdm_crypt_hmac.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib - libspdm_crypt_hmac.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:41662.4 %
Date:2024-09-22 08:21:07Functions:1714.3 %
Branches:1581.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_hmac_all316
libspdm_hmac_duplicate0
libspdm_hmac_final0
libspdm_hmac_free0
libspdm_hmac_init0
libspdm_hmac_new0
libspdm_hmac_update0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/libspdm_crypt_hmac.c.gcov.html b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_hmac.c.gcov.html new file mode 100644 index 00000000000..6de356c1d28 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_hmac.c.gcov.html @@ -0,0 +1,514 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/libspdm_crypt_hmac.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib - libspdm_crypt_hmac.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:41662.4 %
Date:2024-09-22 08:21:07Functions:1714.3 %
Branches:1581.7 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 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_crypt_lib.h"
+       8                 :            : 
+       9                 :          0 : void *libspdm_hmac_new(uint32_t base_hash_algo)
+      10                 :            : {
+      11   [ #  #  #  #  :          0 :     switch (base_hash_algo) {
+             #  #  #  # ]
+      12                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256:
+      13                 :            : #if LIBSPDM_SHA256_SUPPORT
+      14                 :          0 :         return libspdm_hmac_sha256_new();
+      15                 :            : #else
+      16                 :            :         LIBSPDM_ASSERT(false);
+      17                 :            :         return false;
+      18                 :            : #endif
+      19                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_384:
+      20                 :            : #if LIBSPDM_SHA384_SUPPORT
+      21                 :          0 :         return libspdm_hmac_sha384_new();
+      22                 :            : #else
+      23                 :            :         LIBSPDM_ASSERT(false);
+      24                 :            :         return false;
+      25                 :            : #endif
+      26                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512:
+      27                 :            : #if LIBSPDM_SHA512_SUPPORT
+      28                 :          0 :         return libspdm_hmac_sha512_new();
+      29                 :            : #else
+      30                 :            :         LIBSPDM_ASSERT(false);
+      31                 :            :         return false;
+      32                 :            : #endif
+      33                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_256:
+      34                 :            : #if LIBSPDM_SHA3_256_SUPPORT
+      35                 :            :         return libspdm_hmac_sha3_256_new();
+      36                 :            : #else
+      37                 :          0 :         LIBSPDM_ASSERT(false);
+      38                 :          0 :         return false;
+      39                 :            : #endif
+      40                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_384:
+      41                 :            : #if LIBSPDM_SHA3_384_SUPPORT
+      42                 :            :         return libspdm_hmac_sha3_384_new();
+      43                 :            : #else
+      44                 :          0 :         LIBSPDM_ASSERT(false);
+      45                 :          0 :         return false;
+      46                 :            : #endif
+      47                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_512:
+      48                 :            : #if LIBSPDM_SHA3_512_SUPPORT
+      49                 :            :         return libspdm_hmac_sha3_512_new();
+      50                 :            : #else
+      51                 :          0 :         LIBSPDM_ASSERT(false);
+      52                 :          0 :         return false;
+      53                 :            : #endif
+      54                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SM3_256:
+      55                 :            : #if LIBSPDM_SM3_256_SUPPORT
+      56                 :            :         return libspdm_hmac_sm3_256_new();
+      57                 :            : #else
+      58                 :          0 :         LIBSPDM_ASSERT(false);
+      59                 :          0 :         return false;
+      60                 :            : #endif
+      61                 :          0 :     default:
+      62                 :          0 :         LIBSPDM_ASSERT(false);
+      63                 :          0 :         return false;
+      64                 :            :     }
+      65                 :            : }
+      66                 :            : 
+      67                 :          0 : void libspdm_hmac_free(uint32_t base_hash_algo, void *hmac_ctx)
+      68                 :            : {
+      69         [ #  # ]:          0 :     if (hmac_ctx == NULL) {
+      70                 :          0 :         return;
+      71                 :            :     }
+      72   [ #  #  #  #  :          0 :     switch (base_hash_algo) {
+             #  #  #  # ]
+      73                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256:
+      74                 :            : #if LIBSPDM_SHA256_SUPPORT
+      75                 :          0 :         libspdm_hmac_sha256_free(hmac_ctx);
+      76                 :            : #else
+      77                 :            :         LIBSPDM_ASSERT(false);
+      78                 :            : #endif
+      79                 :          0 :         break;
+      80                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_384:
+      81                 :            : #if LIBSPDM_SHA384_SUPPORT
+      82                 :          0 :         libspdm_hmac_sha384_free(hmac_ctx);
+      83                 :            : #else
+      84                 :            :         LIBSPDM_ASSERT(false);
+      85                 :            : #endif
+      86                 :          0 :         break;
+      87                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512:
+      88                 :            : #if LIBSPDM_SHA512_SUPPORT
+      89                 :          0 :         libspdm_hmac_sha512_free(hmac_ctx);
+      90                 :            : #else
+      91                 :            :         LIBSPDM_ASSERT(false);
+      92                 :            : #endif
+      93                 :          0 :         break;
+      94                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_256:
+      95                 :            : #if LIBSPDM_SHA3_256_SUPPORT
+      96                 :            :         libspdm_hmac_sha3_256_free(hmac_ctx);
+      97                 :            : #else
+      98                 :          0 :         LIBSPDM_ASSERT(false);
+      99                 :            : #endif
+     100                 :          0 :         break;
+     101                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_384:
+     102                 :            : #if LIBSPDM_SHA3_384_SUPPORT
+     103                 :            :         libspdm_hmac_sha3_384_free(hmac_ctx);
+     104                 :            : #else
+     105                 :          0 :         LIBSPDM_ASSERT(false);
+     106                 :            : #endif
+     107                 :          0 :         break;
+     108                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_512:
+     109                 :            : #if LIBSPDM_SHA3_512_SUPPORT
+     110                 :            :         libspdm_hmac_sha3_512_free(hmac_ctx);
+     111                 :            : #else
+     112                 :          0 :         LIBSPDM_ASSERT(false);
+     113                 :            : #endif
+     114                 :          0 :         break;
+     115                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SM3_256:
+     116                 :            : #if LIBSPDM_SM3_256_SUPPORT
+     117                 :            :         libspdm_hmac_sm3_256_free(hmac_ctx);
+     118                 :            : #else
+     119                 :          0 :         LIBSPDM_ASSERT(false);
+     120                 :            : #endif
+     121                 :          0 :         break;
+     122                 :          0 :     default:
+     123                 :          0 :         LIBSPDM_ASSERT(false);
+     124                 :          0 :         break;
+     125                 :            :     }
+     126                 :            : }
+     127                 :            : 
+     128                 :          0 : bool libspdm_hmac_init(uint32_t base_hash_algo,
+     129                 :            :                        void *hmac_ctx, const uint8_t *key,
+     130                 :            :                        size_t key_size)
+     131                 :            : {
+     132   [ #  #  #  #  :          0 :     switch (base_hash_algo) {
+             #  #  #  # ]
+     133                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256:
+     134                 :            : #if LIBSPDM_SHA256_SUPPORT
+     135                 :          0 :         return libspdm_hmac_sha256_set_key(hmac_ctx, key, key_size);
+     136                 :            : #else
+     137                 :            :         LIBSPDM_ASSERT(false);
+     138                 :            :         return false;
+     139                 :            : #endif
+     140                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_384:
+     141                 :            : #if LIBSPDM_SHA384_SUPPORT
+     142                 :          0 :         return libspdm_hmac_sha384_set_key(hmac_ctx, key, key_size);
+     143                 :            : #else
+     144                 :            :         LIBSPDM_ASSERT(false);
+     145                 :            :         return false;
+     146                 :            : #endif
+     147                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512:
+     148                 :            : #if LIBSPDM_SHA512_SUPPORT
+     149                 :          0 :         return libspdm_hmac_sha512_set_key(hmac_ctx, key, key_size);
+     150                 :            : #else
+     151                 :            :         LIBSPDM_ASSERT(false);
+     152                 :            :         return false;
+     153                 :            : #endif
+     154                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_256:
+     155                 :            : #if LIBSPDM_SHA3_256_SUPPORT
+     156                 :            :         return libspdm_hmac_sha3_256_set_key(hmac_ctx, key, key_size);
+     157                 :            : #else
+     158                 :          0 :         LIBSPDM_ASSERT(false);
+     159                 :          0 :         return false;
+     160                 :            : #endif
+     161                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_384:
+     162                 :            : #if LIBSPDM_SHA3_384_SUPPORT
+     163                 :            :         return libspdm_hmac_sha3_384_set_key(hmac_ctx, key, key_size);
+     164                 :            : #else
+     165                 :          0 :         LIBSPDM_ASSERT(false);
+     166                 :          0 :         return false;
+     167                 :            : #endif
+     168                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_512:
+     169                 :            : #if LIBSPDM_SHA3_512_SUPPORT
+     170                 :            :         return libspdm_hmac_sha3_512_set_key(hmac_ctx, key, key_size);
+     171                 :            : #else
+     172                 :          0 :         LIBSPDM_ASSERT(false);
+     173                 :          0 :         return false;
+     174                 :            : #endif
+     175                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SM3_256:
+     176                 :            : #if LIBSPDM_SM3_256_SUPPORT
+     177                 :            :         return libspdm_hmac_sm3_256_set_key(hmac_ctx, key, key_size);
+     178                 :            : #else
+     179                 :          0 :         LIBSPDM_ASSERT(false);
+     180                 :          0 :         return false;
+     181                 :            : #endif
+     182                 :          0 :     default:
+     183                 :          0 :         LIBSPDM_ASSERT(false);
+     184                 :          0 :         return false;
+     185                 :            :     }
+     186                 :            : }
+     187                 :            : 
+     188                 :          0 : bool libspdm_hmac_duplicate(uint32_t base_hash_algo, const void *hmac_ctx, void *new_hmac_ctx)
+     189                 :            : {
+     190   [ #  #  #  #  :          0 :     switch (base_hash_algo) {
+             #  #  #  # ]
+     191                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256:
+     192                 :            : #if LIBSPDM_SHA256_SUPPORT
+     193                 :          0 :         return libspdm_hmac_sha256_duplicate(hmac_ctx, new_hmac_ctx);
+     194                 :            : #else
+     195                 :            :         LIBSPDM_ASSERT(false);
+     196                 :            :         return false;
+     197                 :            : #endif
+     198                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_384:
+     199                 :            : #if LIBSPDM_SHA384_SUPPORT
+     200                 :          0 :         return libspdm_hmac_sha384_duplicate(hmac_ctx, new_hmac_ctx);
+     201                 :            : #else
+     202                 :            :         LIBSPDM_ASSERT(false);
+     203                 :            :         return false;
+     204                 :            : #endif
+     205                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512:
+     206                 :            : #if LIBSPDM_SHA512_SUPPORT
+     207                 :          0 :         return libspdm_hmac_sha512_duplicate(hmac_ctx, new_hmac_ctx);
+     208                 :            : #else
+     209                 :            :         LIBSPDM_ASSERT(false);
+     210                 :            :         return false;
+     211                 :            : #endif
+     212                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_256:
+     213                 :            : #if LIBSPDM_SHA3_256_SUPPORT
+     214                 :            :         return libspdm_hmac_sha3_256_duplicate(hmac_ctx, new_hmac_ctx);
+     215                 :            : #else
+     216                 :          0 :         LIBSPDM_ASSERT(false);
+     217                 :          0 :         return false;
+     218                 :            : #endif
+     219                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_384:
+     220                 :            : #if LIBSPDM_SHA3_384_SUPPORT
+     221                 :            :         return libspdm_hmac_sha3_384_duplicate(hmac_ctx, new_hmac_ctx);
+     222                 :            : #else
+     223                 :          0 :         LIBSPDM_ASSERT(false);
+     224                 :          0 :         return false;
+     225                 :            : #endif
+     226                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_512:
+     227                 :            : #if LIBSPDM_SHA3_512_SUPPORT
+     228                 :            :         return libspdm_hmac_sha3_512_duplicate(hmac_ctx, new_hmac_ctx);
+     229                 :            : #else
+     230                 :          0 :         LIBSPDM_ASSERT(false);
+     231                 :          0 :         return false;
+     232                 :            : #endif
+     233                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SM3_256:
+     234                 :            : #if LIBSPDM_SM3_256_SUPPORT
+     235                 :            :         return libspdm_hmac_sm3_256_duplicate(hmac_ctx, new_hmac_ctx);
+     236                 :            : #else
+     237                 :          0 :         LIBSPDM_ASSERT(false);
+     238                 :          0 :         return false;
+     239                 :            : #endif
+     240                 :          0 :     default:
+     241                 :          0 :         LIBSPDM_ASSERT(false);
+     242                 :          0 :         return false;
+     243                 :            :     }
+     244                 :            : }
+     245                 :            : 
+     246                 :          0 : bool libspdm_hmac_update(uint32_t base_hash_algo,
+     247                 :            :                          void *hmac_ctx, const void *data,
+     248                 :            :                          size_t data_size)
+     249                 :            : {
+     250   [ #  #  #  #  :          0 :     switch (base_hash_algo) {
+             #  #  #  # ]
+     251                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256:
+     252                 :            : #if LIBSPDM_SHA256_SUPPORT
+     253                 :          0 :         return libspdm_hmac_sha256_update(hmac_ctx, data, data_size);
+     254                 :            : #else
+     255                 :            :         LIBSPDM_ASSERT(false);
+     256                 :            :         return false;
+     257                 :            : #endif
+     258                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_384:
+     259                 :            : #if LIBSPDM_SHA384_SUPPORT
+     260                 :          0 :         return libspdm_hmac_sha384_update(hmac_ctx, data, data_size);
+     261                 :            : #else
+     262                 :            :         LIBSPDM_ASSERT(false);
+     263                 :            :         return false;
+     264                 :            : #endif
+     265                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512:
+     266                 :            : #if LIBSPDM_SHA512_SUPPORT
+     267                 :          0 :         return libspdm_hmac_sha512_update(hmac_ctx, data, data_size);
+     268                 :            : #else
+     269                 :            :         LIBSPDM_ASSERT(false);
+     270                 :            :         return false;
+     271                 :            : #endif
+     272                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_256:
+     273                 :            : #if LIBSPDM_SHA3_256_SUPPORT
+     274                 :            :         return libspdm_hmac_sha3_256_update(hmac_ctx, data, data_size);
+     275                 :            : #else
+     276                 :          0 :         LIBSPDM_ASSERT(false);
+     277                 :          0 :         return false;
+     278                 :            : #endif
+     279                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_384:
+     280                 :            : #if LIBSPDM_SHA3_384_SUPPORT
+     281                 :            :         return libspdm_hmac_sha3_384_update(hmac_ctx, data, data_size);
+     282                 :            : #else
+     283                 :          0 :         LIBSPDM_ASSERT(false);
+     284                 :          0 :         return false;
+     285                 :            : #endif
+     286                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_512:
+     287                 :            : #if LIBSPDM_SHA3_512_SUPPORT
+     288                 :            :         return libspdm_hmac_sha3_512_update(hmac_ctx, data, data_size);
+     289                 :            : #else
+     290                 :          0 :         LIBSPDM_ASSERT(false);
+     291                 :          0 :         return false;
+     292                 :            : #endif
+     293                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SM3_256:
+     294                 :            : #if LIBSPDM_SM3_256_SUPPORT
+     295                 :            :         return libspdm_hmac_sm3_256_update(hmac_ctx, data, data_size);
+     296                 :            : #else
+     297                 :          0 :         LIBSPDM_ASSERT(false);
+     298                 :          0 :         return false;
+     299                 :            : #endif
+     300                 :          0 :     default:
+     301                 :          0 :         LIBSPDM_ASSERT(false);
+     302                 :          0 :         return false;
+     303                 :            :     }
+     304                 :            : }
+     305                 :            : 
+     306                 :          0 : bool libspdm_hmac_final(uint32_t base_hash_algo, void *hmac_ctx,  uint8_t *hmac_value)
+     307                 :            : {
+     308   [ #  #  #  #  :          0 :     switch (base_hash_algo) {
+             #  #  #  # ]
+     309                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256:
+     310                 :            : #if LIBSPDM_SHA256_SUPPORT
+     311                 :          0 :         return libspdm_hmac_sha256_final(hmac_ctx, hmac_value);
+     312                 :            : #else
+     313                 :            :         LIBSPDM_ASSERT(false);
+     314                 :            :         return false;
+     315                 :            : #endif
+     316                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_384:
+     317                 :            : #if LIBSPDM_SHA384_SUPPORT
+     318                 :          0 :         return libspdm_hmac_sha384_final(hmac_ctx, hmac_value);
+     319                 :            : #else
+     320                 :            :         LIBSPDM_ASSERT(false);
+     321                 :            :         return false;
+     322                 :            : #endif
+     323                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512:
+     324                 :            : #if LIBSPDM_SHA512_SUPPORT
+     325                 :          0 :         return libspdm_hmac_sha512_final(hmac_ctx, hmac_value);
+     326                 :            : #else
+     327                 :            :         LIBSPDM_ASSERT(false);
+     328                 :            :         return false;
+     329                 :            : #endif
+     330                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_256:
+     331                 :            : #if LIBSPDM_SHA3_256_SUPPORT
+     332                 :            :         return libspdm_hmac_sha3_256_final(hmac_ctx, hmac_value);
+     333                 :            : #else
+     334                 :          0 :         LIBSPDM_ASSERT(false);
+     335                 :          0 :         return false;
+     336                 :            : #endif
+     337                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_384:
+     338                 :            : #if LIBSPDM_SHA3_384_SUPPORT
+     339                 :            :         return libspdm_hmac_sha3_384_final(hmac_ctx, hmac_value);
+     340                 :            : #else
+     341                 :          0 :         LIBSPDM_ASSERT(false);
+     342                 :          0 :         return false;
+     343                 :            : #endif
+     344                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_512:
+     345                 :            : #if LIBSPDM_SHA3_512_SUPPORT
+     346                 :            :         return libspdm_hmac_sha3_512_final(hmac_ctx, hmac_value);
+     347                 :            : #else
+     348                 :          0 :         LIBSPDM_ASSERT(false);
+     349                 :          0 :         return false;
+     350                 :            : #endif
+     351                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SM3_256:
+     352                 :            : #if LIBSPDM_SM3_256_SUPPORT
+     353                 :            :         return libspdm_hmac_sm3_256_final(hmac_ctx, hmac_value);
+     354                 :            : #else
+     355                 :          0 :         LIBSPDM_ASSERT(false);
+     356                 :          0 :         return false;
+     357                 :            : #endif
+     358                 :          0 :     default:
+     359                 :          0 :         LIBSPDM_ASSERT(false);
+     360                 :          0 :         return false;
+     361                 :            :     }
+     362                 :            : }
+     363                 :            : 
+     364                 :        316 : bool libspdm_hmac_all(uint32_t base_hash_algo, const void *data,
+     365                 :            :                       size_t data_size, const uint8_t *key,
+     366                 :            :                       size_t key_size, uint8_t *hmac_value)
+     367                 :            : {
+     368   [ +  -  -  -  :        316 :     switch (base_hash_algo) {
+             -  -  -  - ]
+     369                 :        316 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256:
+     370                 :            : #if LIBSPDM_SHA256_SUPPORT
+     371                 :        316 :         return libspdm_hmac_sha256_all(data, data_size, key, key_size, hmac_value);
+     372                 :            : #else
+     373                 :            :         LIBSPDM_ASSERT(false);
+     374                 :            :         return false;
+     375                 :            : #endif
+     376                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_384:
+     377                 :            : #if LIBSPDM_SHA384_SUPPORT
+     378                 :          0 :         return libspdm_hmac_sha384_all(data, data_size, key, key_size, hmac_value);
+     379                 :            : #else
+     380                 :            :         LIBSPDM_ASSERT(false);
+     381                 :            :         return false;
+     382                 :            : #endif
+     383                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512:
+     384                 :            : #if LIBSPDM_SHA512_SUPPORT
+     385                 :          0 :         return libspdm_hmac_sha512_all(data, data_size, key, key_size, hmac_value);
+     386                 :            : #else
+     387                 :            :         LIBSPDM_ASSERT(false);
+     388                 :            :         return false;
+     389                 :            : #endif
+     390                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_256:
+     391                 :            : #if LIBSPDM_SHA3_256_SUPPORT
+     392                 :            :         return libspdm_hmac_sha3_256_all(data, data_size, key, key_size, hmac_value);
+     393                 :            : #else
+     394                 :          0 :         LIBSPDM_ASSERT(false);
+     395                 :          0 :         return false;
+     396                 :            : #endif
+     397                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_384:
+     398                 :            : #if LIBSPDM_SHA3_384_SUPPORT
+     399                 :            :         return libspdm_hmac_sha3_384_all(data, data_size, key, key_size, hmac_value);
+     400                 :            : #else
+     401                 :          0 :         LIBSPDM_ASSERT(false);
+     402                 :          0 :         return false;
+     403                 :            : #endif
+     404                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_512:
+     405                 :            : #if LIBSPDM_SHA3_512_SUPPORT
+     406                 :            :         return libspdm_hmac_sha3_512_all(data, data_size, key, key_size, hmac_value);
+     407                 :            : #else
+     408                 :          0 :         LIBSPDM_ASSERT(false);
+     409                 :          0 :         return false;
+     410                 :            : #endif
+     411                 :          0 :     case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SM3_256:
+     412                 :            : #if LIBSPDM_SM3_256_SUPPORT
+     413                 :            :         return libspdm_hmac_sm3_256_all(data, data_size, key, key_size, hmac_value);
+     414                 :            : #else
+     415                 :          0 :         LIBSPDM_ASSERT(false);
+     416                 :          0 :         return false;
+     417                 :            : #endif
+     418                 :          0 :     default:
+     419                 :          0 :         LIBSPDM_ASSERT(false);
+     420                 :          0 :         return false;
+     421                 :            :     }
+     422                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/libspdm_crypt_rng.c.func-sort-c.html b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_rng.c.func-sort-c.html new file mode 100644 index 00000000000..acda4986b39 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_rng.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/libspdm_crypt_rng.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib - libspdm_crypt_rng.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:3475.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:1250.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_random_number1976
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/libspdm_crypt_rng.c.func.html b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_rng.c.func.html new file mode 100644 index 00000000000..3ddb2d1fbb1 --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_rng.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/libspdm_crypt_rng.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib - libspdm_crypt_rng.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:3475.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:1250.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_random_number1976
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_crypt_lib/libspdm_crypt_rng.c.gcov.html b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_rng.c.gcov.html new file mode 100644 index 00000000000..11def5e498a --- /dev/null +++ b/coverage_log/library/spdm_crypt_lib/libspdm_crypt_rng.c.gcov.html @@ -0,0 +1,100 @@ + + + + + + + LCOV - coverage.info - library/spdm_crypt_lib/libspdm_crypt_rng.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_crypt_lib - libspdm_crypt_rng.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:3475.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:1250.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 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_crypt_lib.h"
+       8                 :            : 
+       9                 :       1976 : bool libspdm_get_random_number(size_t size, uint8_t *rand)
+      10                 :            : {
+      11         [ -  + ]:       1976 :     if (size == 0) {
+      12                 :          0 :         return true;
+      13                 :            :     }
+      14                 :       1976 :     return libspdm_random_bytes(rand, size);
+      15                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/index-sort-b.html b/coverage_log/library/spdm_requester_lib/index-sort-b.html new file mode 100644 index 00000000000..f9ebc6e09f4 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/index-sort-b.html @@ -0,0 +1,467 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_libHitTotalCoverage
Test:coverage.infoLines:3977505078.8 %
Date:2024-09-22 08:21:07Functions:868996.6 %
Branches:1948291566.8 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
libspdm_req_encap_error.c +
45.0%45.0%
+
45.0 %9 / 2050.0 %1 / 225.0 %1 / 4
libspdm_req_get_key_pair_info.c +
61.8%61.8%
+
61.8 %76 / 123100.0 %2 / 243.9 %29 / 66
libspdm_req_encap_request.c +
64.0%64.0%
+
64.0 %135 / 21180.0 %4 / 547.9 %45 / 94
libspdm_req_get_event_types.c +
66.7%66.7%
+
66.7 %60 / 90100.0 %2 / 248.1 %25 / 52
libspdm_req_set_key_pair_info.c +
64.2%64.2%
+
64.2 %61 / 95100.0 %2 / 248.2 %27 / 56
libspdm_req_vendor_request.c +
75.6%75.6%
+
75.6 %90 / 119100.0 %2 / 250.0 %33 / 66
libspdm_req_get_measurement_extension_log.c +
70.1%70.1%
+
70.1 %101 / 144100.0 %3 / 354.4 %37 / 68
libspdm_req_get_csr.c +
68.5%68.5%
+
68.5 %89 / 130100.0 %3 / 356.5 %52 / 92
libspdm_req_subscribe_event_types.c +
70.7%70.7%
+
70.7 %58 / 82100.0 %2 / 257.7 %30 / 52
libspdm_req_psk_exchange.c +
70.6%70.6%
+
70.6 %190 / 26975.0 %3 / 458.8 %87 / 148
libspdm_req_handle_error_response.c +
75.0%75.0%
+
75.0 %144 / 192100.0 %5 / 562.1 %72 / 116
libspdm_req_encap_certificate.c +
83.3%83.3%
+
83.3 %50 / 60100.0 %1 / 162.5 %20 / 32
libspdm_req_set_certificate.c +
76.3%76.3%
+
76.3 %90 / 118100.0 %3 / 362.8 %54 / 86
libspdm_req_end_session.c +
80.8%80.8%
+
80.8 %63 / 78100.0 %2 / 265.0 %26 / 40
libspdm_req_send_receive.c +
84.3%84.3%
+
84.3 %280 / 332100.0 %5 / 565.8 %146 / 222
libspdm_req_challenge.c +
78.8%78.8%
+
78.8 %189 / 240100.0 %4 / 466.4 %93 / 140
libspdm_req_heartbeat.c +
80.5%80.5%
+
80.5 %62 / 77100.0 %2 / 266.7 %28 / 42
libspdm_req_get_measurements.c +
75.3%75.3%
+
75.3 %292 / 388100.0 %5 / 567.9 %167 / 246
libspdm_req_get_certificate.c +
71.9%71.9%
+
71.9 %164 / 228100.0 %5 / 568.3 %86 / 126
libspdm_req_psk_finish.c +
79.4%79.4%
+
79.4 %100 / 126100.0 %3 / 368.3 %41 / 60
libspdm_req_encap_challenge_auth.c +
86.0%86.0%
+
86.0 %80 / 93100.0 %1 / 169.2 %36 / 52
libspdm_req_finish.c +
82.8%82.8%
+
82.8 %168 / 203100.0 %5 / 569.6 %71 / 102
libspdm_req_key_exchange.c +
79.7%79.7%
+
79.7 %314 / 394100.0 %5 / 570.7 %133 / 188
libspdm_req_common.c +
88.8%88.8%
+
88.8 %71 / 80100.0 %3 / 372.2 %26 / 36
libspdm_req_key_update.c +
80.4%80.4%
+
80.4 %131 / 163100.0 %2 / 272.3 %68 / 94
libspdm_req_get_capabilities.c +
92.6%92.6%
+
92.6 %188 / 203100.0 %3 / 374.2 %144 / 194
libspdm_req_get_version.c +
85.8%85.8%
+
85.8 %97 / 113100.0 %2 / 276.0 %38 / 50
libspdm_req_encap_digests.c +
88.4%88.4%
+
88.4 %61 / 69100.0 %1 / 177.5 %31 / 40
libspdm_req_encap_key_update.c +
88.1%88.1%
+
88.1 %52 / 59100.0 %1 / 180.8 %21 / 26
libspdm_req_get_digests.c +
92.4%92.4%
+
92.4 %158 / 171100.0 %2 / 284.0 %89 / 106
libspdm_req_negotiate_algorithms.c +
93.2%93.2%
+
93.2 %354 / 380100.0 %2 / 287.7 %192 / 219
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/index-sort-f.html b/coverage_log/library/spdm_requester_lib/index-sort-f.html new file mode 100644 index 00000000000..4da388367fe --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/index-sort-f.html @@ -0,0 +1,467 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_libHitTotalCoverage
Test:coverage.infoLines:3977505078.8 %
Date:2024-09-22 08:21:07Functions:868996.6 %
Branches:1948291566.8 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
libspdm_req_encap_error.c +
45.0%45.0%
+
45.0 %9 / 2050.0 %1 / 225.0 %1 / 4
libspdm_req_psk_exchange.c +
70.6%70.6%
+
70.6 %190 / 26975.0 %3 / 458.8 %87 / 148
libspdm_req_encap_request.c +
64.0%64.0%
+
64.0 %135 / 21180.0 %4 / 547.9 %45 / 94
libspdm_req_encap_certificate.c +
83.3%83.3%
+
83.3 %50 / 60100.0 %1 / 162.5 %20 / 32
libspdm_req_encap_digests.c +
88.4%88.4%
+
88.4 %61 / 69100.0 %1 / 177.5 %31 / 40
libspdm_req_encap_key_update.c +
88.1%88.1%
+
88.1 %52 / 59100.0 %1 / 180.8 %21 / 26
libspdm_req_encap_challenge_auth.c +
86.0%86.0%
+
86.0 %80 / 93100.0 %1 / 169.2 %36 / 52
libspdm_req_get_key_pair_info.c +
61.8%61.8%
+
61.8 %76 / 123100.0 %2 / 243.9 %29 / 66
libspdm_req_negotiate_algorithms.c +
93.2%93.2%
+
93.2 %354 / 380100.0 %2 / 287.7 %192 / 219
libspdm_req_heartbeat.c +
80.5%80.5%
+
80.5 %62 / 77100.0 %2 / 266.7 %28 / 42
libspdm_req_subscribe_event_types.c +
70.7%70.7%
+
70.7 %58 / 82100.0 %2 / 257.7 %30 / 52
libspdm_req_get_digests.c +
92.4%92.4%
+
92.4 %158 / 171100.0 %2 / 284.0 %89 / 106
libspdm_req_set_key_pair_info.c +
64.2%64.2%
+
64.2 %61 / 95100.0 %2 / 248.2 %27 / 56
libspdm_req_get_version.c +
85.8%85.8%
+
85.8 %97 / 113100.0 %2 / 276.0 %38 / 50
libspdm_req_vendor_request.c +
75.6%75.6%
+
75.6 %90 / 119100.0 %2 / 250.0 %33 / 66
libspdm_req_key_update.c +
80.4%80.4%
+
80.4 %131 / 163100.0 %2 / 272.3 %68 / 94
libspdm_req_get_event_types.c +
66.7%66.7%
+
66.7 %60 / 90100.0 %2 / 248.1 %25 / 52
libspdm_req_end_session.c +
80.8%80.8%
+
80.8 %63 / 78100.0 %2 / 265.0 %26 / 40
libspdm_req_psk_finish.c +
79.4%79.4%
+
79.4 %100 / 126100.0 %3 / 368.3 %41 / 60
libspdm_req_common.c +
88.8%88.8%
+
88.8 %71 / 80100.0 %3 / 372.2 %26 / 36
libspdm_req_get_measurement_extension_log.c +
70.1%70.1%
+
70.1 %101 / 144100.0 %3 / 354.4 %37 / 68
libspdm_req_get_csr.c +
68.5%68.5%
+
68.5 %89 / 130100.0 %3 / 356.5 %52 / 92
libspdm_req_get_capabilities.c +
92.6%92.6%
+
92.6 %188 / 203100.0 %3 / 374.2 %144 / 194
libspdm_req_set_certificate.c +
76.3%76.3%
+
76.3 %90 / 118100.0 %3 / 362.8 %54 / 86
libspdm_req_challenge.c +
78.8%78.8%
+
78.8 %189 / 240100.0 %4 / 466.4 %93 / 140
libspdm_req_finish.c +
82.8%82.8%
+
82.8 %168 / 203100.0 %5 / 569.6 %71 / 102
libspdm_req_get_measurements.c +
75.3%75.3%
+
75.3 %292 / 388100.0 %5 / 567.9 %167 / 246
libspdm_req_key_exchange.c +
79.7%79.7%
+
79.7 %314 / 394100.0 %5 / 570.7 %133 / 188
libspdm_req_send_receive.c +
84.3%84.3%
+
84.3 %280 / 332100.0 %5 / 565.8 %146 / 222
libspdm_req_handle_error_response.c +
75.0%75.0%
+
75.0 %144 / 192100.0 %5 / 562.1 %72 / 116
libspdm_req_get_certificate.c +
71.9%71.9%
+
71.9 %164 / 228100.0 %5 / 568.3 %86 / 126
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/index-sort-l.html b/coverage_log/library/spdm_requester_lib/index-sort-l.html new file mode 100644 index 00000000000..6ab6282e496 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/index-sort-l.html @@ -0,0 +1,467 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_libHitTotalCoverage
Test:coverage.infoLines:3977505078.8 %
Date:2024-09-22 08:21:07Functions:868996.6 %
Branches:1948291566.8 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
libspdm_req_encap_error.c +
45.0%45.0%
+
45.0 %9 / 2050.0 %1 / 225.0 %1 / 4
libspdm_req_get_key_pair_info.c +
61.8%61.8%
+
61.8 %76 / 123100.0 %2 / 243.9 %29 / 66
libspdm_req_encap_request.c +
64.0%64.0%
+
64.0 %135 / 21180.0 %4 / 547.9 %45 / 94
libspdm_req_set_key_pair_info.c +
64.2%64.2%
+
64.2 %61 / 95100.0 %2 / 248.2 %27 / 56
libspdm_req_get_event_types.c +
66.7%66.7%
+
66.7 %60 / 90100.0 %2 / 248.1 %25 / 52
libspdm_req_get_csr.c +
68.5%68.5%
+
68.5 %89 / 130100.0 %3 / 356.5 %52 / 92
libspdm_req_get_measurement_extension_log.c +
70.1%70.1%
+
70.1 %101 / 144100.0 %3 / 354.4 %37 / 68
libspdm_req_psk_exchange.c +
70.6%70.6%
+
70.6 %190 / 26975.0 %3 / 458.8 %87 / 148
libspdm_req_subscribe_event_types.c +
70.7%70.7%
+
70.7 %58 / 82100.0 %2 / 257.7 %30 / 52
libspdm_req_get_certificate.c +
71.9%71.9%
+
71.9 %164 / 228100.0 %5 / 568.3 %86 / 126
libspdm_req_handle_error_response.c +
75.0%75.0%
+
75.0 %144 / 192100.0 %5 / 562.1 %72 / 116
libspdm_req_get_measurements.c +
75.3%75.3%
+
75.3 %292 / 388100.0 %5 / 567.9 %167 / 246
libspdm_req_vendor_request.c +
75.6%75.6%
+
75.6 %90 / 119100.0 %2 / 250.0 %33 / 66
libspdm_req_set_certificate.c +
76.3%76.3%
+
76.3 %90 / 118100.0 %3 / 362.8 %54 / 86
libspdm_req_challenge.c +
78.8%78.8%
+
78.8 %189 / 240100.0 %4 / 466.4 %93 / 140
libspdm_req_psk_finish.c +
79.4%79.4%
+
79.4 %100 / 126100.0 %3 / 368.3 %41 / 60
libspdm_req_key_exchange.c +
79.7%79.7%
+
79.7 %314 / 394100.0 %5 / 570.7 %133 / 188
libspdm_req_key_update.c +
80.4%80.4%
+
80.4 %131 / 163100.0 %2 / 272.3 %68 / 94
libspdm_req_heartbeat.c +
80.5%80.5%
+
80.5 %62 / 77100.0 %2 / 266.7 %28 / 42
libspdm_req_end_session.c +
80.8%80.8%
+
80.8 %63 / 78100.0 %2 / 265.0 %26 / 40
libspdm_req_finish.c +
82.8%82.8%
+
82.8 %168 / 203100.0 %5 / 569.6 %71 / 102
libspdm_req_encap_certificate.c +
83.3%83.3%
+
83.3 %50 / 60100.0 %1 / 162.5 %20 / 32
libspdm_req_send_receive.c +
84.3%84.3%
+
84.3 %280 / 332100.0 %5 / 565.8 %146 / 222
libspdm_req_get_version.c +
85.8%85.8%
+
85.8 %97 / 113100.0 %2 / 276.0 %38 / 50
libspdm_req_encap_challenge_auth.c +
86.0%86.0%
+
86.0 %80 / 93100.0 %1 / 169.2 %36 / 52
libspdm_req_encap_key_update.c +
88.1%88.1%
+
88.1 %52 / 59100.0 %1 / 180.8 %21 / 26
libspdm_req_encap_digests.c +
88.4%88.4%
+
88.4 %61 / 69100.0 %1 / 177.5 %31 / 40
libspdm_req_common.c +
88.8%88.8%
+
88.8 %71 / 80100.0 %3 / 372.2 %26 / 36
libspdm_req_get_digests.c +
92.4%92.4%
+
92.4 %158 / 171100.0 %2 / 284.0 %89 / 106
libspdm_req_get_capabilities.c +
92.6%92.6%
+
92.6 %188 / 203100.0 %3 / 374.2 %144 / 194
libspdm_req_negotiate_algorithms.c +
93.2%93.2%
+
93.2 %354 / 380100.0 %2 / 287.7 %192 / 219
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/index.html b/coverage_log/library/spdm_requester_lib/index.html new file mode 100644 index 00000000000..a20d3d02faf --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/index.html @@ -0,0 +1,467 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_libHitTotalCoverage
Test:coverage.infoLines:3977505078.8 %
Date:2024-09-22 08:21:07Functions:868996.6 %
Branches:1948291566.8 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
libspdm_req_challenge.c +
78.8%78.8%
+
78.8 %189 / 240100.0 %4 / 466.4 %93 / 140
libspdm_req_common.c +
88.8%88.8%
+
88.8 %71 / 80100.0 %3 / 372.2 %26 / 36
libspdm_req_encap_certificate.c +
83.3%83.3%
+
83.3 %50 / 60100.0 %1 / 162.5 %20 / 32
libspdm_req_encap_challenge_auth.c +
86.0%86.0%
+
86.0 %80 / 93100.0 %1 / 169.2 %36 / 52
libspdm_req_encap_digests.c +
88.4%88.4%
+
88.4 %61 / 69100.0 %1 / 177.5 %31 / 40
libspdm_req_encap_error.c +
45.0%45.0%
+
45.0 %9 / 2050.0 %1 / 225.0 %1 / 4
libspdm_req_encap_key_update.c +
88.1%88.1%
+
88.1 %52 / 59100.0 %1 / 180.8 %21 / 26
libspdm_req_encap_request.c +
64.0%64.0%
+
64.0 %135 / 21180.0 %4 / 547.9 %45 / 94
libspdm_req_end_session.c +
80.8%80.8%
+
80.8 %63 / 78100.0 %2 / 265.0 %26 / 40
libspdm_req_finish.c +
82.8%82.8%
+
82.8 %168 / 203100.0 %5 / 569.6 %71 / 102
libspdm_req_get_capabilities.c +
92.6%92.6%
+
92.6 %188 / 203100.0 %3 / 374.2 %144 / 194
libspdm_req_get_certificate.c +
71.9%71.9%
+
71.9 %164 / 228100.0 %5 / 568.3 %86 / 126
libspdm_req_get_csr.c +
68.5%68.5%
+
68.5 %89 / 130100.0 %3 / 356.5 %52 / 92
libspdm_req_get_digests.c +
92.4%92.4%
+
92.4 %158 / 171100.0 %2 / 284.0 %89 / 106
libspdm_req_get_event_types.c +
66.7%66.7%
+
66.7 %60 / 90100.0 %2 / 248.1 %25 / 52
libspdm_req_get_key_pair_info.c +
61.8%61.8%
+
61.8 %76 / 123100.0 %2 / 243.9 %29 / 66
libspdm_req_get_measurement_extension_log.c +
70.1%70.1%
+
70.1 %101 / 144100.0 %3 / 354.4 %37 / 68
libspdm_req_get_measurements.c +
75.3%75.3%
+
75.3 %292 / 388100.0 %5 / 567.9 %167 / 246
libspdm_req_get_version.c +
85.8%85.8%
+
85.8 %97 / 113100.0 %2 / 276.0 %38 / 50
libspdm_req_handle_error_response.c +
75.0%75.0%
+
75.0 %144 / 192100.0 %5 / 562.1 %72 / 116
libspdm_req_heartbeat.c +
80.5%80.5%
+
80.5 %62 / 77100.0 %2 / 266.7 %28 / 42
libspdm_req_key_exchange.c +
79.7%79.7%
+
79.7 %314 / 394100.0 %5 / 570.7 %133 / 188
libspdm_req_key_update.c +
80.4%80.4%
+
80.4 %131 / 163100.0 %2 / 272.3 %68 / 94
libspdm_req_negotiate_algorithms.c +
93.2%93.2%
+
93.2 %354 / 380100.0 %2 / 287.7 %192 / 219
libspdm_req_psk_exchange.c +
70.6%70.6%
+
70.6 %190 / 26975.0 %3 / 458.8 %87 / 148
libspdm_req_psk_finish.c +
79.4%79.4%
+
79.4 %100 / 126100.0 %3 / 368.3 %41 / 60
libspdm_req_send_receive.c +
84.3%84.3%
+
84.3 %280 / 332100.0 %5 / 565.8 %146 / 222
libspdm_req_set_certificate.c +
76.3%76.3%
+
76.3 %90 / 118100.0 %3 / 362.8 %54 / 86
libspdm_req_set_key_pair_info.c +
64.2%64.2%
+
64.2 %61 / 95100.0 %2 / 248.2 %27 / 56
libspdm_req_subscribe_event_types.c +
70.7%70.7%
+
70.7 %58 / 82100.0 %2 / 257.7 %30 / 52
libspdm_req_vendor_request.c +
75.6%75.6%
+
75.6 %90 / 119100.0 %2 / 250.0 %33 / 66
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_challenge.c.func-sort-c.html b/coverage_log/library/spdm_requester_lib/libspdm_req_challenge.c.func-sort-c.html new file mode 100644 index 00000000000..eaf36fe7b8e --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_challenge.c.func-sort-c.html @@ -0,0 +1,97 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_challenge.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_challenge.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:18924078.8 %
Date:2024-09-22 08:21:07Functions:44100.0 %
Branches:9314066.4 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_challenge_ex2
libspdm_challenge_ex22
libspdm_challenge43
libspdm_try_challenge48
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_challenge.c.func.html b/coverage_log/library/spdm_requester_lib/libspdm_req_challenge.c.func.html new file mode 100644 index 00000000000..dc705a5bd28 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_challenge.c.func.html @@ -0,0 +1,97 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_challenge.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_challenge.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:18924078.8 %
Date:2024-09-22 08:21:07Functions:44100.0 %
Branches:9314066.4 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_challenge43
libspdm_challenge_ex2
libspdm_challenge_ex22
libspdm_try_challenge48
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_challenge.c.gcov.html b/coverage_log/library/spdm_requester_lib/libspdm_req_challenge.c.gcov.html new file mode 100644 index 00000000000..6c196fdc486 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_challenge.c.gcov.html @@ -0,0 +1,598 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_challenge.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_challenge.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:18924078.8 %
Date:2024-09-22 08:21:07Functions:44100.0 %
Branches:9314066.4 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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_CHAL_CAP
+      10                 :            : 
+      11                 :            : #pragma pack(1)
+      12                 :            : typedef struct {
+      13                 :            :     spdm_message_header_t header;
+      14                 :            :     uint8_t cert_chain_hash[LIBSPDM_MAX_HASH_SIZE];
+      15                 :            :     uint8_t nonce[SPDM_NONCE_SIZE];
+      16                 :            :     uint8_t measurement_summary_hash[LIBSPDM_MAX_HASH_SIZE];
+      17                 :            :     uint16_t opaque_length;
+      18                 :            :     uint8_t opaque_data[SPDM_MAX_OPAQUE_DATA_SIZE];
+      19                 :            :     uint8_t requester_context[SPDM_REQ_CONTEXT_SIZE];
+      20                 :            :     uint8_t signature[LIBSPDM_MAX_ASYM_KEY_SIZE];
+      21                 :            : } libspdm_challenge_auth_response_max_t;
+      22                 :            : #pragma pack()
+      23                 :            : 
+      24                 :            : /**
+      25                 :            :  * This function sends CHALLENGE to authenticate the device based upon the key in one slot.
+      26                 :            :  *
+      27                 :            :  * This function verifies the signature in the challenge auth.
+      28                 :            :  *
+      29                 :            :  * If basic mutual authentication is requested from the responder,
+      30                 :            :  * this function also perform the basic mutual authentication.
+      31                 :            :  *
+      32                 :            :  * @param  spdm_context           A pointer to the SPDM context.
+      33                 :            :  * @param  slot_id                The number of slot for the challenge.
+      34                 :            :  * @param  requester_context      If not NULL, a buffer to hold the requester context (8 bytes).
+      35                 :            :  *                                It is used only if the negotiated version >= 1.3.
+      36                 :            :  * @param  measurement_hash_type  The type of the measurement hash.
+      37                 :            :  * @param  measurement_hash       A pointer to a destination buffer to store the measurement hash.
+      38                 :            :  * @param  slot_mask              A pointer to a destination to store the slot mask.
+      39                 :            :  * @param  requester_nonce_in     If not NULL, a buffer that holds the requester nonce (32 bytes)
+      40                 :            :  * @param  requester_nonce        If not NULL, a buffer to hold the requester nonce (32 bytes).
+      41                 :            :  * @param  responder_nonce        If not NULL, a buffer to hold the responder nonce (32 bytes).
+      42                 :            :  *
+      43                 :            :  * @retval RETURN_SUCCESS               The challenge auth is got successfully.
+      44                 :            :  * @retval RETURN_DEVICE_ERROR          A device error occurs when communicates with the device.
+      45                 :            :  * @retval RETURN_SECURITY_VIOLATION    Any verification fails.
+      46                 :            :  **/
+      47                 :         48 : static libspdm_return_t libspdm_try_challenge(libspdm_context_t *spdm_context,
+      48                 :            :                                               uint8_t slot_id,
+      49                 :            :                                               const void *requester_context,
+      50                 :            :                                               uint8_t measurement_hash_type,
+      51                 :            :                                               void *measurement_hash,
+      52                 :            :                                               uint8_t *slot_mask,
+      53                 :            :                                               const void *requester_nonce_in,
+      54                 :            :                                               void *requester_nonce,
+      55                 :            :                                               void *responder_nonce,
+      56                 :            :                                               void *opaque_data,
+      57                 :            :                                               size_t *opaque_data_size)
+      58                 :            : {
+      59                 :            :     libspdm_return_t status;
+      60                 :            :     bool result;
+      61                 :            :     spdm_challenge_request_t *spdm_request;
+      62                 :            :     size_t spdm_request_size;
+      63                 :            :     libspdm_challenge_auth_response_max_t *spdm_response;
+      64                 :            :     size_t spdm_response_size;
+      65                 :            :     uint8_t *ptr;
+      66                 :            :     void *cert_chain_hash;
+      67                 :            :     size_t hash_size;
+      68                 :            :     uint32_t measurement_summary_hash_size;
+      69                 :            :     void *nonce;
+      70                 :            :     void *measurement_summary_hash;
+      71                 :            :     uint16_t opaque_length;
+      72                 :            :     void *signature;
+      73                 :            :     size_t signature_size;
+      74                 :            :     uint8_t auth_attribute;
+      75                 :            :     uint8_t *message;
+      76                 :            :     size_t message_size;
+      77                 :            :     size_t transport_header_size;
+      78                 :            : 
+      79                 :            :     /* -=[Check Parameters Phase]=- */
+      80   [ +  +  -  + ]:         48 :     LIBSPDM_ASSERT((slot_id < SPDM_MAX_SLOT_COUNT) || (slot_id == 0xff));
+      81   [ +  +  -  + ]:         48 :     LIBSPDM_ASSERT((slot_id != 0xff) ||
+      82                 :            :                    (spdm_context->local_context.peer_public_key_provision_size != 0));
+      83   [ +  +  +  +  :         48 :     LIBSPDM_ASSERT(measurement_hash_type == SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH ||
+                   -  + ]
+      84                 :            :                    measurement_hash_type == SPDM_CHALLENGE_REQUEST_TCB_COMPONENT_MEASUREMENT_HASH ||
+      85                 :            :                    measurement_hash_type == SPDM_CHALLENGE_REQUEST_ALL_MEASUREMENTS_HASH);
+      86                 :            : 
+      87                 :            :     /* -=[Verify State Phase]=- */
+      88         [ +  + ]:         48 :     if (!libspdm_is_capabilities_flag_supported(
+      89                 :            :             spdm_context, true, 0,
+      90                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP)) {
+      91                 :          1 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+      92                 :            :     }
+      93         [ +  + ]:         47 :     if (spdm_context->connection_info.connection_state < LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
+      94                 :          1 :         return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+      95                 :            :     }
+      96                 :            : 
+      97                 :         46 :     libspdm_reset_message_buffer_via_request_code(spdm_context, NULL, SPDM_CHALLENGE);
+      98                 :            : 
+      99                 :            :     /* -=[Construct Request Phase]=- */
+     100                 :         46 :     spdm_context->connection_info.peer_used_cert_chain_slot_id = slot_id;
+     101                 :         46 :     transport_header_size = spdm_context->local_context.capability.transport_header_size;
+     102                 :         46 :     status = libspdm_acquire_sender_buffer (spdm_context, &message_size, (void **)&message);
+     103         [ -  + ]:         46 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     104                 :          0 :         return status;
+     105                 :            :     }
+     106         [ -  + ]:         46 :     LIBSPDM_ASSERT (message_size >= transport_header_size +
+     107                 :            :                     spdm_context->local_context.capability.transport_tail_size);
+     108                 :         46 :     spdm_request = (void *)(message + transport_header_size);
+     109                 :         46 :     spdm_request_size = message_size - transport_header_size -
+     110                 :         46 :                         spdm_context->local_context.capability.transport_tail_size;
+     111                 :            : 
+     112         [ -  + ]:         46 :     LIBSPDM_ASSERT (spdm_request_size >= sizeof(spdm_challenge_request_t));
+     113                 :         46 :     spdm_request->header.spdm_version = libspdm_get_connection_version (spdm_context);
+     114                 :         46 :     spdm_request->header.request_response_code = SPDM_CHALLENGE;
+     115                 :         46 :     spdm_request->header.param1 = slot_id;
+     116                 :         46 :     spdm_request->header.param2 = measurement_hash_type;
+     117         [ +  + ]:         46 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
+     118         [ -  + ]:          2 :         LIBSPDM_ASSERT (spdm_request_size >= sizeof(spdm_challenge_request_t) +
+     119                 :            :                         SPDM_REQ_CONTEXT_SIZE);
+     120                 :          2 :         spdm_request_size = sizeof(spdm_challenge_request_t) + SPDM_REQ_CONTEXT_SIZE;
+     121                 :            :     } else {
+     122                 :         44 :         spdm_request_size = sizeof(spdm_challenge_request_t);
+     123                 :            :     }
+     124         [ +  - ]:         46 :     if (requester_nonce_in == NULL) {
+     125         [ -  + ]:         46 :         if(!libspdm_get_random_number(SPDM_NONCE_SIZE, spdm_request->nonce)) {
+     126                 :          0 :             libspdm_release_sender_buffer (spdm_context);
+     127                 :          0 :             return LIBSPDM_STATUS_LOW_ENTROPY;
+     128                 :            :         }
+     129                 :            :     } else {
+     130                 :          0 :         libspdm_copy_mem(spdm_request->nonce, sizeof(spdm_request->nonce),
+     131                 :            :                          requester_nonce_in, SPDM_NONCE_SIZE);
+     132                 :            :     }
+     133                 :         46 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "RequesterNonce - "));
+     134                 :         46 :     LIBSPDM_INTERNAL_DUMP_DATA(spdm_request->nonce, SPDM_NONCE_SIZE);
+     135                 :         46 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     136         [ -  + ]:         46 :     if (requester_nonce != NULL) {
+     137                 :          0 :         libspdm_copy_mem(requester_nonce, SPDM_NONCE_SIZE, spdm_request->nonce, SPDM_NONCE_SIZE);
+     138                 :            :     }
+     139         [ +  + ]:         46 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
+     140         [ -  + ]:          2 :         if (requester_context == NULL) {
+     141                 :          0 :             libspdm_zero_mem(spdm_request + 1, SPDM_REQ_CONTEXT_SIZE);
+     142                 :            :         } else {
+     143                 :          2 :             libspdm_copy_mem(spdm_request + 1, SPDM_REQ_CONTEXT_SIZE,
+     144                 :            :                              requester_context, SPDM_REQ_CONTEXT_SIZE);
+     145                 :            :         }
+     146                 :          2 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "RequesterContext - "));
+     147                 :          2 :         LIBSPDM_INTERNAL_DUMP_DATA((uint8_t *)(spdm_request + 1), SPDM_REQ_CONTEXT_SIZE);
+     148                 :          2 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     149                 :            :     }
+     150                 :            : 
+     151                 :            :     /* -=[Send Request Phase]=- */
+     152                 :         46 :     status = libspdm_send_spdm_request(spdm_context, NULL, spdm_request_size, spdm_request);
+     153         [ +  + ]:         46 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     154                 :          1 :         libspdm_release_sender_buffer (spdm_context);
+     155                 :          1 :         return status;
+     156                 :            :     }
+     157                 :         45 :     libspdm_release_sender_buffer (spdm_context);
+     158                 :         45 :     spdm_request = (void *)spdm_context->last_spdm_request;
+     159                 :            : 
+     160                 :            :     /* -=[Receive Response Phase]=- */
+     161                 :         45 :     status = libspdm_acquire_receiver_buffer (spdm_context, &message_size, (void **)&message);
+     162         [ -  + ]:         45 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     163                 :          0 :         return status;
+     164                 :            :     }
+     165         [ -  + ]:         45 :     LIBSPDM_ASSERT (message_size >= transport_header_size);
+     166                 :         45 :     spdm_response = (void *)(message);
+     167                 :         45 :     spdm_response_size = message_size;
+     168                 :            : 
+     169                 :         45 :     status = libspdm_receive_spdm_response(
+     170                 :            :         spdm_context, NULL, &spdm_response_size, (void **)&spdm_response);
+     171         [ -  + ]:         45 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     172                 :          0 :         goto receive_done;
+     173                 :            :     }
+     174                 :            : 
+     175                 :            :     /* -=[Validate Response Phase]=- */
+     176         [ -  + ]:         45 :     if (spdm_response_size < sizeof(spdm_message_header_t)) {
+     177                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     178                 :          0 :         goto receive_done;
+     179                 :            :     }
+     180         [ +  + ]:         45 :     if (spdm_response->header.spdm_version != spdm_request->header.spdm_version) {
+     181                 :          1 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     182                 :          1 :         goto receive_done;
+     183                 :            :     }
+     184         [ +  + ]:         44 :     if (spdm_response->header.request_response_code == SPDM_ERROR) {
+     185                 :         24 :         status = libspdm_handle_error_response_main(
+     186                 :            :             spdm_context, NULL,
+     187                 :            :             &spdm_response_size,
+     188                 :            :             (void **)&spdm_response, SPDM_CHALLENGE, SPDM_CHALLENGE_AUTH);
+     189         [ +  + ]:         24 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     190                 :         23 :             goto receive_done;
+     191                 :            :         }
+     192         [ +  + ]:         20 :     } else if (spdm_response->header.request_response_code != SPDM_CHALLENGE_AUTH) {
+     193                 :          1 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     194                 :          1 :         goto receive_done;
+     195                 :            :     }
+     196         [ -  + ]:         20 :     if (spdm_response_size < sizeof(spdm_challenge_auth_response_t)) {
+     197                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     198                 :          0 :         goto receive_done;
+     199                 :            :     }
+     200                 :         20 :     auth_attribute = spdm_response->header.param1;
+     201   [ +  -  +  + ]:         20 :     if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_11 && slot_id == 0xFF) {
+     202         [ -  + ]:          1 :         if ((auth_attribute & SPDM_CHALLENGE_AUTH_RESPONSE_ATTRIBUTE_SLOT_ID_MASK) != 0xF) {
+     203                 :          0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     204                 :          0 :             goto receive_done;
+     205                 :            :         }
+     206                 :            :     } else {
+     207         [ +  - ]:         19 :         if ((spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_11 &&
+     208         [ +  + ]:         19 :              (auth_attribute & SPDM_CHALLENGE_AUTH_RESPONSE_ATTRIBUTE_SLOT_ID_MASK) != slot_id) ||
+     209   [ -  +  -  - ]:         18 :             (spdm_response->header.spdm_version == SPDM_MESSAGE_VERSION_10 &&
+     210                 :            :              auth_attribute != slot_id)) {
+     211                 :          1 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     212                 :          1 :             goto receive_done;
+     213                 :            :         }
+     214         [ +  + ]:         18 :         if ((spdm_response->header.param2 & (1 << slot_id)) == 0) {
+     215                 :          1 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     216                 :          1 :             goto receive_done;
+     217                 :            :         }
+     218                 :            :     }
+     219         [ -  + ]:         18 :     if ((auth_attribute & SPDM_CHALLENGE_AUTH_RESPONSE_ATTRIBUTE_BASIC_MUT_AUTH_REQ) != 0) {
+     220         [ #  # ]:          0 :         if (!libspdm_is_capabilities_flag_supported(
+     221                 :            :                 spdm_context, true,
+     222                 :            :                 SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP,
+     223                 :            :                 SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP)) {
+     224                 :          0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     225                 :          0 :             goto receive_done;
+     226                 :            :         }
+     227                 :            :     }
+     228                 :            : 
+     229                 :            :     /* -=[Process Response Phase]=- */
+     230                 :         18 :     hash_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+     231                 :         18 :     signature_size = libspdm_get_asym_signature_size(
+     232                 :            :         spdm_context->connection_info.algorithm.base_asym_algo);
+     233                 :         18 :     measurement_summary_hash_size = libspdm_get_measurement_summary_hash_size(
+     234                 :            :         spdm_context, true, measurement_hash_type);
+     235                 :            : 
+     236                 :         18 :     if (spdm_response_size <= sizeof(spdm_challenge_auth_response_t) +
+     237         [ -  + ]:         18 :         hash_size + SPDM_NONCE_SIZE + measurement_summary_hash_size + sizeof(uint16_t)) {
+     238                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     239                 :          0 :         goto receive_done;
+     240                 :            :     }
+     241                 :            : 
+     242                 :         18 :     ptr = spdm_response->cert_chain_hash;
+     243                 :            : 
+     244                 :         18 :     cert_chain_hash = ptr;
+     245                 :         18 :     ptr += hash_size;
+     246                 :         18 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "cert_chain_hash (0x%zx) - ", hash_size));
+     247                 :         18 :     LIBSPDM_INTERNAL_DUMP_DATA(cert_chain_hash, hash_size);
+     248                 :         18 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     249         [ +  + ]:         18 :     if (slot_id == 0xFF) {
+     250                 :          1 :         result = libspdm_verify_public_key_hash(spdm_context, cert_chain_hash, hash_size);
+     251                 :            :     } else {
+     252                 :         17 :         result = libspdm_verify_certificate_chain_hash(spdm_context, cert_chain_hash, hash_size);
+     253                 :            :     }
+     254         [ -  + ]:         18 :     if (!result) {
+     255                 :          0 :         status = LIBSPDM_STATUS_VERIF_FAIL;
+     256                 :          0 :         goto receive_done;
+     257                 :            :     }
+     258                 :            : 
+     259                 :         18 :     nonce = ptr;
+     260                 :         18 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "nonce (0x%x) - ", SPDM_NONCE_SIZE));
+     261                 :         18 :     LIBSPDM_INTERNAL_DUMP_DATA(nonce, SPDM_NONCE_SIZE);
+     262                 :         18 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     263                 :         18 :     ptr += SPDM_NONCE_SIZE;
+     264         [ -  + ]:         18 :     if (responder_nonce != NULL) {
+     265                 :          0 :         libspdm_copy_mem(responder_nonce, SPDM_NONCE_SIZE, nonce, SPDM_NONCE_SIZE);
+     266                 :            :     }
+     267                 :            : 
+     268                 :         18 :     measurement_summary_hash = ptr;
+     269                 :         18 :     ptr += measurement_summary_hash_size;
+     270                 :         18 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "measurement_summary_hash (0x%x) - ",
+     271                 :            :                    measurement_summary_hash_size));
+     272                 :         18 :     LIBSPDM_INTERNAL_DUMP_DATA(measurement_summary_hash, measurement_summary_hash_size);
+     273                 :         18 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     274                 :            : 
+     275                 :         18 :     opaque_length = libspdm_read_uint16((const uint8_t *)ptr);
+     276         [ +  + ]:         18 :     if (opaque_length > SPDM_MAX_OPAQUE_DATA_SIZE) {
+     277                 :          1 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     278                 :          1 :         goto receive_done;
+     279                 :            :     }
+     280         [ +  + ]:         17 :     if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_12) {
+     281         [ +  + ]:          4 :         if (((spdm_context->connection_info.algorithm.other_params_support &
+     282                 :            :               SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_MASK) ==
+     283         [ -  + ]:          1 :              SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_NONE) &&
+     284                 :            :             (opaque_length != 0)) {
+     285                 :          0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     286                 :          0 :             goto receive_done;
+     287                 :            :         }
+     288                 :            :     }
+     289                 :         17 :     ptr += sizeof(uint16_t);
+     290         [ +  + ]:         17 :     if (opaque_length != 0) {
+     291                 :          2 :         result = libspdm_process_general_opaque_data_check(spdm_context, opaque_length, ptr);
+     292         [ -  + ]:          2 :         if (!result) {
+     293                 :          0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     294                 :          0 :             goto receive_done;
+     295                 :            :         }
+     296                 :            :     }
+     297                 :            : 
+     298         [ +  + ]:         17 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
+     299                 :          2 :         if (spdm_response_size <
+     300                 :            :             sizeof(spdm_challenge_auth_response_t) + hash_size +
+     301                 :          2 :             SPDM_NONCE_SIZE + measurement_summary_hash_size +
+     302         [ -  + ]:          2 :             sizeof(uint16_t) + opaque_length + SPDM_REQ_CONTEXT_SIZE +
+     303                 :            :             signature_size) {
+     304                 :          0 :             status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     305                 :          0 :             goto receive_done;
+     306                 :            :         }
+     307                 :          2 :         spdm_response_size = sizeof(spdm_challenge_auth_response_t) +
+     308                 :          2 :                              hash_size + SPDM_NONCE_SIZE +
+     309                 :          2 :                              measurement_summary_hash_size + sizeof(uint16_t) +
+     310                 :          2 :                              opaque_length + SPDM_REQ_CONTEXT_SIZE + signature_size;
+     311                 :            :     } else {
+     312                 :         15 :         if (spdm_response_size <
+     313                 :            :             sizeof(spdm_challenge_auth_response_t) + hash_size +
+     314                 :         15 :             SPDM_NONCE_SIZE + measurement_summary_hash_size +
+     315         [ -  + ]:         15 :             sizeof(uint16_t) + opaque_length + signature_size) {
+     316                 :          0 :             status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     317                 :          0 :             goto receive_done;
+     318                 :            :         }
+     319                 :         15 :         spdm_response_size = sizeof(spdm_challenge_auth_response_t) +
+     320                 :         15 :                              hash_size + SPDM_NONCE_SIZE +
+     321                 :         15 :                              measurement_summary_hash_size + sizeof(uint16_t) +
+     322                 :         15 :                              opaque_length + signature_size;
+     323                 :            :     }
+     324                 :            : 
+     325   [ +  +  +  - ]:         17 :     if ((opaque_data != NULL) && (opaque_data_size != NULL)) {
+     326         [ -  + ]:          2 :         if (opaque_length >= *opaque_data_size) {
+     327                 :          0 :             status = LIBSPDM_STATUS_BUFFER_TOO_SMALL;
+     328                 :          0 :             goto receive_done;
+     329                 :            :         }
+     330                 :          2 :         libspdm_copy_mem(opaque_data, *opaque_data_size, ptr, opaque_length);
+     331                 :          2 :         *opaque_data_size = opaque_length;
+     332                 :            :     }
+     333                 :            : 
+     334                 :         17 :     ptr += opaque_length;
+     335         [ +  + ]:         17 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
+     336                 :          2 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "RequesterContext - "));
+     337                 :          2 :         LIBSPDM_INTERNAL_DUMP_DATA(ptr, SPDM_REQ_CONTEXT_SIZE);
+     338                 :          2 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     339         [ +  + ]:          2 :         if (!libspdm_consttime_is_mem_equal(spdm_request + 1, ptr, SPDM_REQ_CONTEXT_SIZE)) {
+     340                 :          1 :             libspdm_reset_message_c(spdm_context);
+     341                 :          1 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     342                 :          1 :             goto receive_done;
+     343                 :            :         }
+     344                 :          1 :         ptr += SPDM_REQ_CONTEXT_SIZE;
+     345                 :            :     }
+     346                 :            : 
+     347                 :         16 :     status = libspdm_append_message_c(spdm_context, spdm_request, spdm_request_size);
+     348         [ -  + ]:         16 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     349                 :          0 :         goto receive_done;
+     350                 :            :     }
+     351                 :         16 :     status = libspdm_append_message_c(spdm_context, spdm_response,
+     352                 :            :                                       spdm_response_size - signature_size);
+     353         [ -  + ]:         16 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     354                 :          0 :         libspdm_reset_message_c(spdm_context);
+     355                 :          0 :         goto receive_done;
+     356                 :            :     }
+     357                 :            : 
+     358                 :         16 :     signature = ptr;
+     359                 :         16 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "signature (0x%zx):\n", signature_size));
+     360                 :         16 :     LIBSPDM_INTERNAL_DUMP_HEX(signature, signature_size);
+     361                 :         16 :     result = libspdm_verify_challenge_auth_signature(spdm_context, true, signature, signature_size);
+     362         [ +  + ]:         16 :     if (!result) {
+     363                 :          1 :         libspdm_reset_message_c(spdm_context);
+     364                 :          1 :         status = LIBSPDM_STATUS_VERIF_FAIL;
+     365                 :          1 :         goto receive_done;
+     366                 :            :     }
+     367                 :            : 
+     368         [ +  - ]:         15 :     if (measurement_hash != NULL) {
+     369                 :         15 :         libspdm_copy_mem(measurement_hash, measurement_summary_hash_size,
+     370                 :            :                          measurement_summary_hash, measurement_summary_hash_size);
+     371                 :            :     }
+     372         [ -  + ]:         15 :     if (slot_mask != NULL) {
+     373                 :          0 :         *slot_mask = spdm_response->header.param2;
+     374                 :            :     }
+     375                 :            : 
+     376                 :            :     /* -=[Update State Phase]=- */
+     377                 :            : #if (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP)
+     378         [ -  + ]:         15 :     if ((auth_attribute & SPDM_CHALLENGE_AUTH_RESPONSE_ATTRIBUTE_BASIC_MUT_AUTH_REQ) != 0) {
+     379                 :            :         /* we must release it here, because libspdm_encapsulated_request() will acquire again. */
+     380                 :          0 :         libspdm_release_receiver_buffer (spdm_context);
+     381                 :            : 
+     382                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "BasicMutAuth :\n"));
+     383                 :          0 :         status = libspdm_encapsulated_request(spdm_context, NULL, 0, NULL);
+     384                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+     385                 :            :                        "libspdm_challenge - libspdm_encapsulated_request - %xu\n", status));
+     386         [ #  # ]:          0 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     387                 :          0 :             libspdm_reset_message_c(spdm_context);
+     388                 :          0 :             return status;
+     389                 :            :         }
+     390                 :          0 :         spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     391                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     392                 :            :     }
+     393                 :            : #endif /* (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP) */
+     394                 :            : 
+     395                 :         15 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     396                 :         15 :     status = LIBSPDM_STATUS_SUCCESS;
+     397                 :            : 
+     398                 :         45 : receive_done:
+     399                 :         45 :     libspdm_release_receiver_buffer (spdm_context);
+     400                 :         45 :     return status;
+     401                 :            : }
+     402                 :            : 
+     403                 :         43 : libspdm_return_t libspdm_challenge(void *spdm_context, void *reserved,
+     404                 :            :                                    uint8_t slot_id,
+     405                 :            :                                    uint8_t measurement_hash_type,
+     406                 :            :                                    void *measurement_hash,
+     407                 :            :                                    uint8_t *slot_mask)
+     408                 :            : {
+     409                 :            :     libspdm_context_t *context;
+     410                 :            :     size_t retry;
+     411                 :            :     uint64_t retry_delay_time;
+     412                 :            :     libspdm_return_t status;
+     413                 :            : 
+     414                 :         43 :     context = spdm_context;
+     415                 :         43 :     context->crypto_request = true;
+     416                 :         43 :     retry = context->retry_times;
+     417                 :         43 :     retry_delay_time = context->retry_delay_time;
+     418                 :            :     do {
+     419                 :         44 :         status = libspdm_try_challenge(context, slot_id, NULL,
+     420                 :            :                                        measurement_hash_type,
+     421                 :            :                                        measurement_hash, slot_mask,
+     422                 :            :                                        NULL, NULL, NULL, NULL, NULL);
+     423         [ +  + ]:         44 :         if (status != LIBSPDM_STATUS_BUSY_PEER) {
+     424                 :         42 :             return status;
+     425                 :            :         }
+     426                 :            : 
+     427                 :          2 :         libspdm_sleep(retry_delay_time);
+     428         [ +  + ]:          2 :     } while (retry-- != 0);
+     429                 :            : 
+     430                 :          1 :     return status;
+     431                 :            : }
+     432                 :            : 
+     433                 :          2 : libspdm_return_t libspdm_challenge_ex(void *spdm_context, void *reserved,
+     434                 :            :                                       uint8_t slot_id,
+     435                 :            :                                       uint8_t measurement_hash_type,
+     436                 :            :                                       void *measurement_hash,
+     437                 :            :                                       uint8_t *slot_mask,
+     438                 :            :                                       const void *requester_nonce_in,
+     439                 :            :                                       void *requester_nonce,
+     440                 :            :                                       void *responder_nonce,
+     441                 :            :                                       void *opaque_data,
+     442                 :            :                                       size_t *opaque_data_size)
+     443                 :            : {
+     444                 :            :     libspdm_context_t *context;
+     445                 :            :     size_t retry;
+     446                 :            :     uint64_t retry_delay_time;
+     447                 :            :     libspdm_return_t status;
+     448                 :            : 
+     449                 :          2 :     context = spdm_context;
+     450                 :          2 :     context->crypto_request = true;
+     451                 :          2 :     retry = context->retry_times;
+     452                 :          2 :     retry_delay_time = context->retry_delay_time;
+     453                 :            :     do {
+     454                 :          2 :         status = libspdm_try_challenge(context, slot_id, NULL,
+     455                 :            :                                        measurement_hash_type,
+     456                 :            :                                        measurement_hash,
+     457                 :            :                                        slot_mask,
+     458                 :            :                                        requester_nonce_in,
+     459                 :            :                                        requester_nonce, responder_nonce,
+     460                 :            :                                        opaque_data,
+     461                 :            :                                        opaque_data_size);
+     462         [ +  - ]:          2 :         if (status != LIBSPDM_STATUS_BUSY_PEER) {
+     463                 :          2 :             return status;
+     464                 :            :         }
+     465                 :            : 
+     466                 :          0 :         libspdm_sleep(retry_delay_time);
+     467         [ #  # ]:          0 :     } while (retry-- != 0);
+     468                 :            : 
+     469                 :          0 :     return status;
+     470                 :            : }
+     471                 :            : 
+     472                 :          2 : libspdm_return_t libspdm_challenge_ex2(void *spdm_context, void *reserved,
+     473                 :            :                                        uint8_t slot_id,
+     474                 :            :                                        const void *requester_context,
+     475                 :            :                                        uint8_t measurement_hash_type,
+     476                 :            :                                        void *measurement_hash,
+     477                 :            :                                        uint8_t *slot_mask,
+     478                 :            :                                        const void *requester_nonce_in,
+     479                 :            :                                        void *requester_nonce,
+     480                 :            :                                        void *responder_nonce,
+     481                 :            :                                        void *opaque_data,
+     482                 :            :                                        size_t *opaque_data_size)
+     483                 :            : {
+     484                 :            :     libspdm_context_t *context;
+     485                 :            :     size_t retry;
+     486                 :            :     uint64_t retry_delay_time;
+     487                 :            :     libspdm_return_t status;
+     488                 :            : 
+     489                 :          2 :     context = spdm_context;
+     490                 :          2 :     context->crypto_request = true;
+     491                 :          2 :     retry = context->retry_times;
+     492                 :          2 :     retry_delay_time = context->retry_delay_time;
+     493                 :            :     do {
+     494                 :          2 :         status = libspdm_try_challenge(context, slot_id, requester_context,
+     495                 :            :                                        measurement_hash_type,
+     496                 :            :                                        measurement_hash,
+     497                 :            :                                        slot_mask,
+     498                 :            :                                        requester_nonce_in,
+     499                 :            :                                        requester_nonce, responder_nonce,
+     500                 :            :                                        opaque_data,
+     501                 :            :                                        opaque_data_size);
+     502         [ +  - ]:          2 :         if (status != LIBSPDM_STATUS_BUSY_PEER) {
+     503                 :          2 :             return status;
+     504                 :            :         }
+     505                 :            : 
+     506                 :          0 :         libspdm_sleep(retry_delay_time);
+     507         [ #  # ]:          0 :     } while (retry-- != 0);
+     508                 :            : 
+     509                 :          0 :     return status;
+     510                 :            : }
+     511                 :            : 
+     512                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_common.c.func-sort-c.html b/coverage_log/library/spdm_requester_lib/libspdm_req_common.c.func-sort-c.html new file mode 100644 index 00000000000..ba1cb930a82 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_common.c.func-sort-c.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_common.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_common.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:718088.8 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:263672.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_process_opaque_data_version_selection_data40
libspdm_allocate_req_session_id167
libspdm_build_opaque_data_supported_version_data168
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_common.c.func.html b/coverage_log/library/spdm_requester_lib/libspdm_req_common.c.func.html new file mode 100644 index 00000000000..40d8ff34e81 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_common.c.func.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_common.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_common.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:718088.8 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:263672.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_allocate_req_session_id167
libspdm_build_opaque_data_supported_version_data168
libspdm_process_opaque_data_version_selection_data40
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_common.c.gcov.html b/coverage_log/library/spdm_requester_lib/libspdm_req_common.c.gcov.html new file mode 100644 index 00000000000..969e38286ae --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_common.c.gcov.html @@ -0,0 +1,267 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_common.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_common.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:718088.8 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:263672.2 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 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                 :        167 : uint16_t libspdm_allocate_req_session_id(libspdm_context_t *spdm_context, bool use_psk)
+      10                 :            : {
+      11                 :            :     uint16_t req_session_id;
+      12                 :            :     libspdm_session_info_t *session_info;
+      13                 :            :     size_t index;
+      14                 :            : 
+      15         [ +  + ]:        167 :     if (use_psk) {
+      16         [ +  + ]:         59 :         if ((spdm_context->max_psk_session_count != 0) &&
+      17         [ +  + ]:         16 :             (spdm_context->current_psk_session_count >= spdm_context->max_psk_session_count)) {
+      18                 :          5 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR,
+      19                 :            :                            "libspdm_allocate_req_session_id - MAX PSK session\n"));
+      20                 :          5 :             return (INVALID_SESSION_ID & 0xFFFF);
+      21                 :            :         }
+      22                 :            :     } else {
+      23         [ +  + ]:        108 :         if ((spdm_context->max_dhe_session_count != 0) &&
+      24         [ +  + ]:         16 :             (spdm_context->current_dhe_session_count >= spdm_context->max_dhe_session_count)) {
+      25                 :          5 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR,
+      26                 :            :                            "libspdm_allocate_req_session_id - MAX DHE session\n"));
+      27                 :          5 :             return (INVALID_SESSION_ID & 0xFFFF);
+      28                 :            :         }
+      29                 :            :     }
+      30                 :            : 
+      31                 :        157 :     session_info = spdm_context->session_info;
+      32         [ +  - ]:        346 :     for (index = 0; index < LIBSPDM_MAX_SESSION_COUNT; index++) {
+      33         [ +  + ]:        346 :         if ((session_info[index].session_id & 0xFFFF) == (INVALID_SESSION_ID & 0xFFFF)) {
+      34                 :        157 :             req_session_id = (uint16_t)(0xFFFF - index);
+      35                 :        157 :             return req_session_id;
+      36                 :            :         }
+      37                 :            :     }
+      38                 :            : 
+      39                 :          0 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR, "libspdm_allocate_req_session_id - MAX session_id\n"));
+      40                 :          0 :     return (INVALID_SESSION_ID & 0xFFFF);
+      41                 :            : }
+      42                 :            : 
+      43                 :        168 : void libspdm_build_opaque_data_supported_version_data(libspdm_context_t *spdm_context,
+      44                 :            :                                                       size_t *data_out_size,
+      45                 :            :                                                       void *data_out)
+      46                 :            : {
+      47                 :            :     size_t final_data_size;
+      48                 :            :     secured_message_general_opaque_data_table_header_t *general_opaque_data_table_header;
+      49                 :            :     spdm_general_opaque_data_table_header_t *spdm_general_opaque_data_table_header;
+      50                 :            :     secured_message_opaque_element_table_header_t *opaque_element_table_header;
+      51                 :            :     secured_message_opaque_element_supported_version_t *opaque_element_support_version;
+      52                 :            :     spdm_version_number_t *versions_list;
+      53                 :            :     void *end;
+      54                 :            : 
+      55         [ -  + ]:        168 :     if (spdm_context->local_context.secured_message_version.spdm_version_count == 0) {
+      56                 :          0 :         *data_out_size = 0;
+      57                 :          0 :         return;
+      58                 :            :     }
+      59                 :            : 
+      60                 :        168 :     final_data_size = libspdm_get_opaque_data_supported_version_data_size(spdm_context);
+      61         [ -  + ]:        168 :     LIBSPDM_ASSERT(*data_out_size >= final_data_size);
+      62                 :            : 
+      63         [ +  + ]:        168 :     if (libspdm_get_connection_version (spdm_context) >= SPDM_MESSAGE_VERSION_12) {
+      64                 :         10 :         spdm_general_opaque_data_table_header = data_out;
+      65                 :         10 :         spdm_general_opaque_data_table_header->total_elements = 1;
+      66                 :         10 :         libspdm_write_uint24(spdm_general_opaque_data_table_header->reserved, 0);
+      67                 :         10 :         opaque_element_table_header = (void *)(spdm_general_opaque_data_table_header + 1);
+      68                 :            :     } else {
+      69                 :        158 :         general_opaque_data_table_header = data_out;
+      70                 :        158 :         general_opaque_data_table_header->spec_id = SECURED_MESSAGE_OPAQUE_DATA_SPEC_ID;
+      71                 :        158 :         general_opaque_data_table_header->opaque_version = SECURED_MESSAGE_OPAQUE_VERSION;
+      72                 :        158 :         general_opaque_data_table_header->total_elements = 1;
+      73                 :        158 :         general_opaque_data_table_header->reserved = 0;
+      74                 :        158 :         opaque_element_table_header = (void *)(general_opaque_data_table_header + 1);
+      75                 :            :     }
+      76                 :            : 
+      77                 :        168 :     opaque_element_table_header->id = SPDM_REGISTRY_ID_DMTF;
+      78                 :        168 :     opaque_element_table_header->vendor_len = 0;
+      79                 :        168 :     opaque_element_table_header->opaque_element_data_len =
+      80                 :        168 :         sizeof(secured_message_opaque_element_supported_version_t) +
+      81                 :        168 :         sizeof(spdm_version_number_t) *
+      82                 :        168 :         spdm_context->local_context.secured_message_version.spdm_version_count;
+      83                 :            : 
+      84                 :        168 :     opaque_element_support_version = (void *)(opaque_element_table_header + 1);
+      85                 :        168 :     opaque_element_support_version->sm_data_version =
+      86                 :            :         SECURED_MESSAGE_OPAQUE_ELEMENT_SMDATA_DATA_VERSION;
+      87                 :        168 :     opaque_element_support_version->sm_data_id =
+      88                 :            :         SECURED_MESSAGE_OPAQUE_ELEMENT_SMDATA_ID_SUPPORTED_VERSION;
+      89                 :        168 :     opaque_element_support_version->version_count =
+      90                 :        168 :         spdm_context->local_context.secured_message_version.spdm_version_count;
+      91                 :            : 
+      92                 :        168 :     versions_list = (void *)(opaque_element_support_version + 1);
+      93                 :        168 :     libspdm_copy_mem(versions_list,
+      94                 :        168 :                      *data_out_size - ((uint8_t*)versions_list - (uint8_t*)data_out),
+      95                 :        168 :                      spdm_context->local_context.secured_message_version.spdm_version,
+      96                 :        168 :                      spdm_context->local_context.secured_message_version.spdm_version_count *
+      97                 :            :                      sizeof(spdm_version_number_t));
+      98                 :            : 
+      99                 :            :     /* Zero Padding. *data_out_size does not need to be changed, because data is 0 padded */
+     100                 :        168 :     end = versions_list + spdm_context->local_context.secured_message_version.spdm_version_count;
+     101                 :        168 :     libspdm_zero_mem(end, (size_t)data_out + final_data_size - (size_t)end);
+     102                 :            : }
+     103                 :            : 
+     104                 :            : /**
+     105                 :            :  * Process opaque data version selection.
+     106                 :            :  *
+     107                 :            :  * This function should be called in KEY_EXCHANGE/PSK_EXCHANGE response parsing in requester.
+     108                 :            :  *
+     109                 :            :  * @param  data_in_size                   size in bytes of the data_in.
+     110                 :            :  * @param  data_in                       A pointer to the buffer to store the opaque data version selection.
+     111                 :            :  *
+     112                 :            :  * @retval RETURN_SUCCESS               The opaque data version selection is processed successfully.
+     113                 :            :  * @retval RETURN_UNSUPPORTED           The data_in is NOT opaque data version selection.
+     114                 :            :  **/
+     115                 :         40 : libspdm_return_t libspdm_process_opaque_data_version_selection_data(libspdm_context_t *spdm_context,
+     116                 :            :                                                                     size_t data_in_size,
+     117                 :            :                                                                     void *data_in)
+     118                 :            : {
+     119                 :            :     const secured_message_opaque_element_table_header_t
+     120                 :            :     *opaque_element_table_header;
+     121                 :            :     const secured_message_opaque_element_version_selection_t
+     122                 :            :     *opaque_element_version_section;
+     123                 :            : 
+     124                 :            :     bool result;
+     125                 :            :     uint8_t secured_message_version_index;
+     126                 :            :     const void *get_element_ptr;
+     127                 :            :     size_t get_element_len;
+     128                 :            : 
+     129                 :         40 :     result = false;
+     130                 :         40 :     get_element_ptr = NULL;
+     131                 :            : 
+     132         [ -  + ]:         40 :     if (spdm_context->local_context.secured_message_version.spdm_version_count == 0) {
+     133                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     134                 :            :     }
+     135                 :            : 
+     136                 :         40 :     result = libspdm_get_element_from_opaque_data(
+     137                 :            :         spdm_context, data_in_size,
+     138                 :            :         data_in, SPDM_REGISTRY_ID_DMTF,
+     139                 :            :         SECURED_MESSAGE_OPAQUE_ELEMENT_SMDATA_ID_VERSION_SELECTION,
+     140                 :            :         &get_element_ptr, &get_element_len);
+     141   [ +  +  -  + ]:         40 :     if ((!result) || (get_element_ptr == NULL)) {
+     142                 :          3 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,"get element error!\n"));
+     143                 :          3 :         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     144                 :            :     }
+     145                 :            : 
+     146                 :         37 :     opaque_element_table_header = (const secured_message_opaque_element_table_header_t*)
+     147                 :            :                                   get_element_ptr;
+     148                 :            : 
+     149                 :            :     /*check for selection vesion data*/
+     150         [ +  - ]:         37 :     if ((opaque_element_table_header->vendor_len != 0) ||
+     151         [ -  + ]:         37 :         (opaque_element_table_header->opaque_element_data_len !=
+     152                 :            :          sizeof(secured_message_opaque_element_version_selection_t))) {
+     153                 :          0 :         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     154                 :            :     }
+     155                 :         37 :     opaque_element_version_section = (const void *)(opaque_element_table_header + 1);
+     156                 :            : 
+     157                 :         37 :     if ((const uint8_t *)opaque_element_version_section +
+     158                 :            :         sizeof(secured_message_opaque_element_version_selection_t) >
+     159         [ -  + ]:         37 :         (const uint8_t *)opaque_element_table_header + get_element_len) {
+     160                 :          0 :         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     161                 :            :     }
+     162                 :            : 
+     163                 :         37 :     for (secured_message_version_index = 0;
+     164                 :         37 :          secured_message_version_index <
+     165         [ +  - ]:         37 :          spdm_context->local_context.secured_message_version.spdm_version_count;
+     166                 :          0 :          secured_message_version_index++) {
+     167         [ +  - ]:         74 :         if (libspdm_get_version_from_version_number(opaque_element_version_section->
+     168                 :            :                                                     selected_version)
+     169                 :            :             ==
+     170                 :         37 :             libspdm_get_version_from_version_number(
+     171                 :         37 :                 spdm_context->local_context.secured_message_version.spdm_version[
+     172                 :            :                     secured_message_version_index])) {
+     173                 :         37 :             libspdm_copy_mem(&(spdm_context->connection_info.secured_message_version),
+     174                 :            :                              sizeof(spdm_context->connection_info.secured_message_version),
+     175                 :         37 :                              &(opaque_element_version_section->selected_version),
+     176                 :            :                              sizeof(spdm_version_number_t));
+     177                 :         37 :             return LIBSPDM_STATUS_SUCCESS;
+     178                 :            :         }
+     179                 :            :     }
+     180                 :            : 
+     181                 :          0 :     return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     182                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_encap_certificate.c.func-sort-c.html b/coverage_log/library/spdm_requester_lib/libspdm_req_encap_certificate.c.func-sort-c.html new file mode 100644 index 00000000000..46222c89408 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_encap_certificate.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_encap_certificate.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_encap_certificate.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:506083.3 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:203262.5 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_encap_response_certificate1406
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_encap_certificate.c.func.html b/coverage_log/library/spdm_requester_lib/libspdm_req_encap_certificate.c.func.html new file mode 100644 index 00000000000..af3c651f92a --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_encap_certificate.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_encap_certificate.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_encap_certificate.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:506083.3 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:203262.5 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_encap_response_certificate1406
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_encap_certificate.c.gcov.html b/coverage_log/library/spdm_requester_lib/libspdm_req_encap_certificate.c.gcov.html new file mode 100644 index 00000000000..9dd46a7e509 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_encap_certificate.c.gcov.html @@ -0,0 +1,238 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_encap_certificate.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_encap_certificate.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:506083.3 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:203262.5 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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_MUT_AUTH_CAP) && (LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP) && \
+      10                 :            :     (LIBSPDM_ENABLE_CAPABILITY_CERT_CAP)
+      11                 :            : 
+      12                 :       1406 : libspdm_return_t libspdm_get_encap_response_certificate(void *spdm_context,
+      13                 :            :                                                         size_t request_size,
+      14                 :            :                                                         void *request,
+      15                 :            :                                                         size_t *response_size,
+      16                 :            :                                                         void *response)
+      17                 :            : {
+      18                 :            :     spdm_get_certificate_request_t *spdm_request;
+      19                 :            :     spdm_certificate_response_t *spdm_response;
+      20                 :            :     uint16_t offset;
+      21                 :            :     uint16_t length;
+      22                 :            :     size_t remainder_length;
+      23                 :            :     uint8_t slot_id;
+      24                 :            :     libspdm_context_t *context;
+      25                 :            :     libspdm_return_t status;
+      26                 :            :     size_t response_capacity;
+      27                 :            : 
+      28                 :       1406 :     context = spdm_context;
+      29                 :       1406 :     spdm_request = request;
+      30                 :            : 
+      31         [ -  + ]:       1406 :     if (libspdm_get_connection_version(context) < SPDM_MESSAGE_VERSION_11) {
+      32                 :          0 :         return libspdm_generate_encap_error_response(
+      33                 :            :             context, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+      34                 :            :             SPDM_GET_CERTIFICATE, response_size, response);
+      35                 :            :     }
+      36                 :            : 
+      37         [ -  + ]:       1406 :     if (spdm_request->header.spdm_version != libspdm_get_connection_version(context)) {
+      38                 :          0 :         return libspdm_generate_encap_error_response(
+      39                 :            :             context, SPDM_ERROR_CODE_VERSION_MISMATCH,
+      40                 :            :             0, response_size, response);
+      41                 :            :     }
+      42                 :            : 
+      43         [ -  + ]:       1406 :     if (!libspdm_is_capabilities_flag_supported(
+      44                 :            :             context, true,
+      45                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP, 0)) {
+      46                 :          0 :         return libspdm_generate_encap_error_response(
+      47                 :            :             context, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+      48                 :            :             SPDM_GET_CERTIFICATE, response_size, response);
+      49                 :            :     }
+      50                 :            : 
+      51         [ -  + ]:       1406 :     if (request_size < sizeof(spdm_get_certificate_request_t)) {
+      52                 :          0 :         return libspdm_generate_encap_error_response(
+      53                 :            :             context, SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+      54                 :            :             response_size, response);
+      55                 :            :     }
+      56                 :            : 
+      57                 :       1406 :     slot_id = spdm_request->header.param1;
+      58                 :            : 
+      59         [ -  + ]:       1406 :     if (slot_id >= SPDM_MAX_SLOT_COUNT) {
+      60                 :          0 :         return libspdm_generate_encap_error_response(
+      61                 :            :             context, SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+      62                 :            :             response_size, response);
+      63                 :            :     }
+      64                 :            : 
+      65                 :       1406 :     if (context->local_context
+      66         [ -  + ]:       1406 :         .local_cert_chain_provision[slot_id] == NULL) {
+      67                 :          0 :         return libspdm_generate_encap_error_response(
+      68                 :            :             context, SPDM_ERROR_CODE_UNSPECIFIED,
+      69                 :            :             0, response_size, response);
+      70                 :            :     }
+      71                 :            : 
+      72                 :       1406 :     offset = spdm_request->offset;
+      73                 :       1406 :     length = spdm_request->length;
+      74                 :            : 
+      75         [ +  + ]:       1406 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
+      76         [ +  - ]:          1 :         if (spdm_request->header.param2 &
+      77                 :            :             SPDM_GET_CERTIFICATE_REQUEST_ATTRIBUTES_SLOT_SIZE_REQUESTED) {
+      78                 :          1 :             offset = 0;
+      79                 :          1 :             length = 0;
+      80                 :            :         }
+      81                 :            :     }
+      82                 :            : 
+      83         [ -  + ]:       1406 :     if (length > LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN) {
+      84                 :          0 :         length = LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN;
+      85                 :            :     }
+      86                 :            : 
+      87                 :       1406 :     if (offset >= context->local_context
+      88         [ +  + ]:       1406 :         .local_cert_chain_provision_size[slot_id]) {
+      89                 :          6 :         return libspdm_generate_encap_error_response(
+      90                 :            :             context, SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+      91                 :            :             response_size, response);
+      92                 :            :     }
+      93                 :            : 
+      94                 :       1400 :     if ((size_t)(offset + length) >
+      95                 :            :         context->local_context
+      96         [ +  + ]:       1400 :         .local_cert_chain_provision_size[slot_id]) {
+      97                 :          2 :         length = (uint16_t)(
+      98                 :            :             context->local_context
+      99                 :          2 :             .local_cert_chain_provision_size[slot_id] -
+     100                 :            :             offset);
+     101                 :            :     }
+     102                 :       1400 :     remainder_length = context->local_context
+     103                 :       1400 :                        .local_cert_chain_provision_size[slot_id] -
+     104                 :       1400 :                        (length + offset);
+     105                 :            : 
+     106                 :       1400 :     libspdm_reset_message_buffer_via_request_code(context, NULL,
+     107                 :       1400 :                                                   spdm_request->header.request_response_code);
+     108                 :            : 
+     109         [ -  + ]:       1400 :     LIBSPDM_ASSERT(*response_size >= sizeof(spdm_certificate_response_t) + length);
+     110                 :       1400 :     response_capacity = *response_size;
+     111                 :       1400 :     *response_size = sizeof(spdm_certificate_response_t) + length;
+     112                 :       1400 :     libspdm_zero_mem(response, *response_size);
+     113                 :       1400 :     spdm_response = response;
+     114                 :            : 
+     115                 :       1400 :     spdm_response->header.spdm_version = spdm_request->header.spdm_version;
+     116                 :       1400 :     spdm_response->header.request_response_code = SPDM_CERTIFICATE;
+     117                 :       1400 :     spdm_response->header.param1 = slot_id;
+     118                 :       1400 :     spdm_response->header.param2 = 0;
+     119         [ +  + ]:       1400 :     if ((spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) &&
+     120         [ -  + ]:          1 :         context->connection_info.multi_key_conn_req) {
+     121                 :          0 :         spdm_response->header.param2 = context->local_context.local_cert_info[slot_id];
+     122                 :            :     }
+     123                 :            : 
+     124                 :       1400 :     spdm_response->portion_length = length;
+     125                 :       1400 :     spdm_response->remainder_length = (uint16_t)remainder_length;
+     126                 :       1400 :     libspdm_copy_mem(spdm_response + 1,
+     127                 :            :                      response_capacity - sizeof(spdm_certificate_response_t),
+     128                 :            :                      (const uint8_t *)context->local_context
+     129                 :       1400 :                      .local_cert_chain_provision[slot_id] + offset,
+     130                 :            :                      length);
+     131                 :            : 
+     132                 :            :     /* Cache*/
+     133                 :            : 
+     134                 :       1400 :     status = libspdm_append_message_mut_b(context, spdm_request,
+     135                 :            :                                           request_size);
+     136         [ -  + ]:       1400 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     137                 :          0 :         return libspdm_generate_encap_error_response(
+     138                 :            :             context, SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     139                 :            :             response_size, response);
+     140                 :            :     }
+     141                 :            : 
+     142                 :       1400 :     status = libspdm_append_message_mut_b(context, spdm_response,
+     143                 :            :                                           *response_size);
+     144         [ -  + ]:       1400 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     145                 :          0 :         return libspdm_generate_encap_error_response(
+     146                 :            :             context, SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     147                 :            :             response_size, response);
+     148                 :            :     }
+     149                 :            : 
+     150                 :       1400 :     return LIBSPDM_STATUS_SUCCESS;
+     151                 :            : }
+     152                 :            : 
+     153                 :            : #endif /* (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (..) */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_encap_challenge_auth.c.func-sort-c.html b/coverage_log/library/spdm_requester_lib/libspdm_req_encap_challenge_auth.c.func-sort-c.html new file mode 100644 index 00000000000..e69605025fc --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_encap_challenge_auth.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_encap_challenge_auth.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_encap_challenge_auth.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:809386.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:365269.2 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_encap_response_challenge_auth7
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_encap_challenge_auth.c.func.html b/coverage_log/library/spdm_requester_lib/libspdm_req_encap_challenge_auth.c.func.html new file mode 100644 index 00000000000..d287c45a158 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_encap_challenge_auth.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_encap_challenge_auth.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_encap_challenge_auth.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:809386.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:365269.2 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_encap_response_challenge_auth7
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_encap_challenge_auth.c.gcov.html b/coverage_log/library/spdm_requester_lib/libspdm_req_encap_challenge_auth.c.gcov.html new file mode 100644 index 00000000000..5c648ae7443 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_encap_challenge_auth.c.gcov.html @@ -0,0 +1,316 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_encap_challenge_auth.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_encap_challenge_auth.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:809386.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:365269.2 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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_MUT_AUTH_CAP) && (LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP) && \
+      10                 :            :     (LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP)
+      11                 :            : 
+      12                 :          7 : libspdm_return_t libspdm_get_encap_response_challenge_auth(
+      13                 :            :     void *spdm_context, size_t request_size, void *request,
+      14                 :            :     size_t *response_size, void *response)
+      15                 :            : {
+      16                 :            :     spdm_challenge_request_t *spdm_request;
+      17                 :            :     spdm_challenge_auth_response_t *spdm_response;
+      18                 :            :     bool result;
+      19                 :            :     size_t signature_size;
+      20                 :            :     uint8_t slot_id;
+      21                 :            :     uint32_t hash_size;
+      22                 :            :     uint8_t *measurement_summary_hash;
+      23                 :            :     uint32_t measurement_summary_hash_size;
+      24                 :            :     uint8_t *ptr;
+      25                 :            :     libspdm_context_t *context;
+      26                 :            :     uint8_t auth_attribute;
+      27                 :            :     libspdm_return_t status;
+      28                 :            :     uint8_t slot_mask;
+      29                 :            :     uint8_t *opaque_data;
+      30                 :            :     size_t opaque_data_size;
+      31                 :            :     size_t spdm_request_size;
+      32                 :            :     size_t spdm_response_size;
+      33                 :            : 
+      34                 :          7 :     context = spdm_context;
+      35                 :          7 :     spdm_request = request;
+      36                 :            : 
+      37         [ -  + ]:          7 :     if (libspdm_get_connection_version(context) < SPDM_MESSAGE_VERSION_11) {
+      38                 :          0 :         return libspdm_generate_encap_error_response(
+      39                 :            :             context, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+      40                 :            :             SPDM_CHALLENGE, response_size, response);
+      41                 :            :     }
+      42                 :            : 
+      43         [ -  + ]:          7 :     if (spdm_request->header.spdm_version != libspdm_get_connection_version(context)) {
+      44                 :          0 :         return libspdm_generate_encap_error_response(
+      45                 :            :             context, SPDM_ERROR_CODE_VERSION_MISMATCH,
+      46                 :            :             0, response_size, response);
+      47                 :            :     }
+      48                 :            : 
+      49         [ +  + ]:          7 :     if (!libspdm_is_capabilities_flag_supported(
+      50                 :            :             context, true,
+      51                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP, 0)) {
+      52                 :          1 :         return libspdm_generate_encap_error_response(
+      53                 :            :             context, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+      54                 :            :             SPDM_CHALLENGE, response_size, response);
+      55                 :            :     }
+      56                 :            : 
+      57         [ -  + ]:          6 :     if (request_size < sizeof(spdm_challenge_request_t)) {
+      58                 :          0 :         return libspdm_generate_encap_error_response(
+      59                 :            :             context, SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+      60                 :            :             response_size, response);
+      61                 :            :     }
+      62                 :          6 :     spdm_request_size = sizeof(spdm_challenge_request_t);
+      63         [ +  + ]:          6 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
+      64         [ -  + ]:          2 :         if (request_size < sizeof(spdm_challenge_request_t) + SPDM_REQ_CONTEXT_SIZE) {
+      65                 :          0 :             return libspdm_generate_encap_error_response(
+      66                 :            :                 context, SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+      67                 :            :                 response_size, response);
+      68                 :            :         }
+      69                 :          2 :         spdm_request_size += SPDM_REQ_CONTEXT_SIZE;
+      70                 :            :     }
+      71                 :            : 
+      72         [ -  + ]:          6 :     if (spdm_request->header.param2 != SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH) {
+      73                 :          0 :         return libspdm_generate_encap_error_response(
+      74                 :            :             context, SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+      75                 :            :             response_size, response);
+      76                 :            :     }
+      77                 :            : 
+      78                 :          6 :     slot_id = spdm_request->header.param1;
+      79                 :            : 
+      80   [ +  +  +  + ]:          6 :     if ((slot_id != 0xFF) &&
+      81                 :            :         (slot_id >= SPDM_MAX_SLOT_COUNT)) {
+      82                 :          2 :         return libspdm_generate_encap_error_response(
+      83                 :            :             context, SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+      84                 :            :             response_size, response);
+      85                 :            :     }
+      86                 :            : 
+      87         [ +  + ]:          4 :     if ((spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) &&
+      88   [ +  +  +  - ]:          2 :         context->connection_info.multi_key_conn_req &&
+      89                 :            :         (slot_id != 0xFF)) {
+      90         [ +  - ]:          1 :         if ((context->local_context.local_key_usage_bit_mask[slot_id] &
+      91                 :            :              SPDM_KEY_USAGE_BIT_MASK_CHALLENGE_USE) == 0) {
+      92                 :          1 :             return libspdm_generate_encap_error_response(
+      93                 :            :                 context, SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+      94                 :            :                 response_size, response);
+      95                 :            :         }
+      96                 :            :     }
+      97                 :            : 
+      98                 :          3 :     libspdm_reset_message_buffer_via_request_code(context, NULL,
+      99                 :          3 :                                                   spdm_request->header.request_response_code);
+     100                 :            : 
+     101                 :          6 :     signature_size = libspdm_get_req_asym_signature_size(
+     102                 :          3 :         context->connection_info.algorithm.req_base_asym_alg);
+     103                 :          3 :     hash_size = libspdm_get_hash_size(
+     104                 :            :         context->connection_info.algorithm.base_hash_algo);
+     105                 :          3 :     measurement_summary_hash_size = 0;
+     106                 :            : 
+     107                 :            :     /* response_size should be large enough to hold a challenge response without opaque data. */
+     108         [ -  + ]:          3 :     LIBSPDM_ASSERT(*response_size >= sizeof(spdm_challenge_auth_response_t) + hash_size +
+     109                 :            :                    SPDM_NONCE_SIZE + measurement_summary_hash_size + sizeof(uint16_t) +
+     110                 :            :                    SPDM_REQ_CONTEXT_SIZE + signature_size);
+     111                 :            : 
+     112                 :          3 :     libspdm_zero_mem(response, *response_size);
+     113                 :          3 :     spdm_response = response;
+     114                 :            : 
+     115                 :          3 :     spdm_response->header.spdm_version = spdm_request->header.spdm_version;
+     116                 :          3 :     spdm_response->header.request_response_code = SPDM_CHALLENGE_AUTH;
+     117                 :          3 :     auth_attribute = (uint8_t)(slot_id & 0xF);
+     118                 :          3 :     spdm_response->header.param1 = auth_attribute;
+     119                 :            : 
+     120         [ +  + ]:          3 :     if (slot_id == 0xFF) {
+     121                 :          1 :         spdm_response->header.param2 = 0;
+     122                 :            :     } else {
+     123                 :          2 :         slot_mask = libspdm_get_cert_slot_mask(context);
+     124         [ +  - ]:          2 :         if (slot_mask != 0) {
+     125                 :          2 :             spdm_response->header.param2 = slot_mask;
+     126                 :            :         } else {
+     127                 :          0 :             return libspdm_generate_encap_error_response(
+     128                 :            :                 context, SPDM_ERROR_CODE_UNSPECIFIED,
+     129                 :            :                 0, response_size, response);
+     130                 :            :         }
+     131                 :            :     }
+     132                 :            : 
+     133                 :          3 :     ptr = (void *)(spdm_response + 1);
+     134         [ +  + ]:          3 :     if (slot_id == 0xFF) {
+     135                 :          1 :         result = libspdm_generate_public_key_hash(context, ptr);
+     136                 :            :     } else {
+     137                 :          2 :         result = libspdm_generate_cert_chain_hash(context, slot_id, ptr);
+     138                 :            :     }
+     139         [ -  + ]:          3 :     if (!result) {
+     140                 :          0 :         return libspdm_generate_encap_error_response(
+     141                 :            :             context, SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     142                 :            :             response_size, response);
+     143                 :            :     }
+     144                 :          3 :     ptr += hash_size;
+     145                 :            : 
+     146         [ -  + ]:          3 :     if(!libspdm_get_random_number(SPDM_NONCE_SIZE, ptr)) {
+     147                 :          0 :         return LIBSPDM_STATUS_LOW_ENTROPY;
+     148                 :            :     }
+     149                 :          3 :     ptr += SPDM_NONCE_SIZE;
+     150                 :            : 
+     151                 :          3 :     measurement_summary_hash = ptr;
+     152                 :          3 :     ptr += measurement_summary_hash_size;
+     153                 :            : 
+     154                 :          3 :     opaque_data_size = *response_size - (sizeof(spdm_challenge_auth_response_t) + hash_size +
+     155                 :          3 :                                          SPDM_NONCE_SIZE + measurement_summary_hash_size +
+     156                 :          3 :                                          sizeof(uint16_t) + signature_size);
+     157                 :          3 :     opaque_data =
+     158                 :          3 :         (uint8_t*)response + sizeof(spdm_challenge_auth_response_t) + hash_size + SPDM_NONCE_SIZE +
+     159                 :          3 :         measurement_summary_hash_size + sizeof(uint16_t);
+     160                 :            : 
+     161                 :          3 :     result = libspdm_encap_challenge_opaque_data(
+     162                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+     163                 :            :         spdm_context,
+     164                 :            : #endif
+     165                 :          3 :         context->connection_info.version,
+     166                 :            :         slot_id,
+     167                 :            :         measurement_summary_hash, measurement_summary_hash_size,
+     168                 :            :         opaque_data, &opaque_data_size);
+     169         [ -  + ]:          3 :     if (!result) {
+     170                 :          0 :         return libspdm_generate_encap_error_response(
+     171                 :            :             context, SPDM_ERROR_CODE_UNSPECIFIED,
+     172                 :            :             0, response_size, response);
+     173                 :            :     }
+     174                 :            : 
+     175                 :            :     /*write opaque_data_size*/
+     176                 :          3 :     libspdm_write_uint16 (ptr, (uint16_t)opaque_data_size);
+     177                 :          3 :     ptr += sizeof(uint16_t);
+     178                 :            : 
+     179                 :            :     /*the opaque_data is stored by libspdm_encap_challenge_opaque_data*/
+     180                 :          3 :     ptr += opaque_data_size;
+     181                 :            : 
+     182         [ +  + ]:          3 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
+     183                 :          1 :         libspdm_copy_mem(ptr, SPDM_REQ_CONTEXT_SIZE,
+     184                 :          1 :                          spdm_request + 1, SPDM_REQ_CONTEXT_SIZE);
+     185                 :          1 :         ptr += SPDM_REQ_CONTEXT_SIZE;
+     186                 :            :     }
+     187                 :            : 
+     188                 :            :     /*get actual response size*/
+     189                 :          3 :     spdm_response_size =
+     190                 :            :         sizeof(spdm_challenge_auth_response_t) + hash_size +
+     191                 :          3 :         SPDM_NONCE_SIZE + measurement_summary_hash_size +
+     192                 :          3 :         sizeof(uint16_t) + opaque_data_size + signature_size;
+     193         [ +  + ]:          3 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
+     194                 :          1 :         spdm_response_size += SPDM_REQ_CONTEXT_SIZE;
+     195                 :            :     }
+     196                 :            : 
+     197         [ -  + ]:          3 :     LIBSPDM_ASSERT(*response_size >= spdm_response_size);
+     198                 :            : 
+     199                 :          3 :     *response_size = spdm_response_size;
+     200                 :            : 
+     201                 :            :     /* Calc Sign*/
+     202                 :            : 
+     203                 :          3 :     status = libspdm_append_message_mut_c(context, spdm_request,
+     204                 :            :                                           spdm_request_size);
+     205         [ -  + ]:          3 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     206                 :          0 :         return libspdm_generate_encap_error_response(
+     207                 :            :             context, SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     208                 :            :             response_size, response);
+     209                 :            :     }
+     210                 :            : 
+     211                 :          3 :     status = libspdm_append_message_mut_c(context, spdm_response,
+     212                 :          3 :                                           (size_t)ptr - (size_t)spdm_response);
+     213         [ -  + ]:          3 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     214                 :          0 :         libspdm_reset_message_mut_c(context);
+     215                 :          0 :         return libspdm_generate_encap_error_response(
+     216                 :            :             context, SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     217                 :            :             response_size, response);
+     218                 :            :     }
+     219                 :            :     result =
+     220                 :          3 :         libspdm_generate_challenge_auth_signature(context, true, ptr);
+     221         [ -  + ]:          3 :     if (!result) {
+     222                 :          0 :         return libspdm_generate_encap_error_response(
+     223                 :            :             context, SPDM_ERROR_CODE_UNSPECIFIED,
+     224                 :            :             0, response_size, response);
+     225                 :            :     }
+     226                 :          3 :     ptr += signature_size;
+     227                 :            : 
+     228                 :          3 :     return LIBSPDM_STATUS_SUCCESS;
+     229                 :            : }
+     230                 :            : 
+     231                 :            : #endif /* (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (..) */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_encap_digests.c.func-sort-c.html b/coverage_log/library/spdm_requester_lib/libspdm_req_encap_digests.c.func-sort-c.html new file mode 100644 index 00000000000..91801fb00f5 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_encap_digests.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_encap_digests.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_encap_digests.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:616988.4 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:314077.5 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_encap_response_digest10
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_encap_digests.c.func.html b/coverage_log/library/spdm_requester_lib/libspdm_req_encap_digests.c.func.html new file mode 100644 index 00000000000..06be8a33f5c --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_encap_digests.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_encap_digests.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_encap_digests.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:616988.4 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:314077.5 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_encap_response_digest10
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_encap_digests.c.gcov.html b/coverage_log/library/spdm_requester_lib/libspdm_req_encap_digests.c.gcov.html new file mode 100644 index 00000000000..e7e074d8122 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_encap_digests.c.gcov.html @@ -0,0 +1,253 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_encap_digests.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_encap_digests.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:616988.4 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:314077.5 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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_MUT_AUTH_CAP) && (LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP) && \
+      10                 :            :     (LIBSPDM_ENABLE_CAPABILITY_CERT_CAP)
+      11                 :            : 
+      12                 :         10 : libspdm_return_t libspdm_get_encap_response_digest(void *spdm_context,
+      13                 :            :                                                    size_t request_size,
+      14                 :            :                                                    void *request,
+      15                 :            :                                                    size_t *response_size,
+      16                 :            :                                                    void *response)
+      17                 :            : {
+      18                 :            :     spdm_get_digest_request_t *spdm_request;
+      19                 :            :     spdm_digest_response_t *spdm_response;
+      20                 :            :     size_t index;
+      21                 :            :     uint32_t hash_size;
+      22                 :            :     uint8_t *digest;
+      23                 :            :     libspdm_context_t *context;
+      24                 :            :     libspdm_return_t status;
+      25                 :            :     bool result;
+      26                 :            :     /*total populated slot count*/
+      27                 :            :     uint8_t slot_count;
+      28                 :            :     /*populated slot index*/
+      29                 :            :     uint8_t slot_index;
+      30                 :            :     uint32_t session_id;
+      31                 :            :     libspdm_session_info_t *session_info;
+      32                 :            :     size_t additional_size;
+      33                 :            :     spdm_key_pair_id_t *key_pair_id;
+      34                 :            :     spdm_certificate_info_t *cert_info;
+      35                 :            :     spdm_key_usage_bit_mask_t *key_usage_bit_mask;
+      36                 :            : 
+      37                 :         10 :     context = spdm_context;
+      38                 :         10 :     spdm_request = request;
+      39                 :            : 
+      40         [ -  + ]:         10 :     if (libspdm_get_connection_version(context) < SPDM_MESSAGE_VERSION_11) {
+      41                 :          0 :         return libspdm_generate_encap_error_response(
+      42                 :            :             context, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+      43                 :            :             SPDM_GET_DIGESTS, response_size, response);
+      44                 :            :     }
+      45                 :            : 
+      46         [ -  + ]:         10 :     if (spdm_request->header.spdm_version != libspdm_get_connection_version(context)) {
+      47                 :          0 :         return libspdm_generate_encap_error_response(
+      48                 :            :             context, SPDM_ERROR_CODE_VERSION_MISMATCH,
+      49                 :            :             0, response_size, response);
+      50                 :            :     }
+      51                 :            : 
+      52         [ -  + ]:         10 :     if (!libspdm_is_capabilities_flag_supported(
+      53                 :            :             context, true,
+      54                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP, 0)) {
+      55                 :          0 :         return libspdm_generate_encap_error_response(
+      56                 :            :             context, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+      57                 :            :             SPDM_GET_DIGESTS, response_size, response);
+      58                 :            :     }
+      59                 :            : 
+      60         [ -  + ]:         10 :     if (request_size < sizeof(spdm_get_digest_request_t)) {
+      61                 :          0 :         return libspdm_generate_encap_error_response(
+      62                 :            :             context, SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+      63                 :            :             response_size, response);
+      64                 :            :     }
+      65                 :            : 
+      66                 :         10 :     libspdm_reset_message_buffer_via_request_code(context, NULL,
+      67                 :         10 :                                                   spdm_request->header.request_response_code);
+      68                 :            : 
+      69                 :         10 :     hash_size = libspdm_get_hash_size(
+      70                 :            :         context->connection_info.algorithm.base_hash_algo);
+      71                 :            : 
+      72                 :         10 :     slot_count = libspdm_get_cert_slot_count(context);
+      73                 :         10 :     additional_size = 0;
+      74         [ +  + ]:         10 :     if ((spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) &&
+      75         [ +  + ]:          3 :         context->connection_info.multi_key_conn_req) {
+      76                 :          2 :         additional_size = sizeof(spdm_key_pair_id_t) + sizeof(spdm_certificate_info_t) +
+      77                 :            :                           sizeof(spdm_key_usage_bit_mask_t);
+      78                 :            :     }
+      79         [ -  + ]:         10 :     LIBSPDM_ASSERT(*response_size >=
+      80                 :            :                    sizeof(spdm_digest_response_t) + (hash_size + additional_size) * slot_count);
+      81                 :         10 :     *response_size = sizeof(spdm_digest_response_t) + (hash_size + additional_size) * slot_count;
+      82                 :         10 :     libspdm_zero_mem(response, *response_size);
+      83                 :         10 :     spdm_response = response;
+      84                 :            : 
+      85                 :         10 :     spdm_response->header.spdm_version = spdm_request->header.spdm_version;
+      86                 :         10 :     spdm_response->header.request_response_code = SPDM_DIGESTS;
+      87                 :         10 :     spdm_response->header.param1 = 0;
+      88                 :         10 :     spdm_response->header.param2 = 0;
+      89                 :            : 
+      90         [ +  + ]:         10 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
+      91                 :          3 :         spdm_response->header.param1 = context->local_context.local_supported_slot_mask;
+      92                 :            :     }
+      93                 :            : 
+      94                 :         10 :     digest = (void *)(spdm_response + 1);
+      95                 :         10 :     key_pair_id = (spdm_key_pair_id_t *)((uint8_t *)digest + hash_size * slot_count);
+      96                 :         10 :     cert_info = (spdm_certificate_info_t *)((uint8_t *)key_pair_id +
+      97                 :         10 :                                             sizeof(spdm_key_pair_id_t) * slot_count);
+      98                 :         10 :     key_usage_bit_mask = (spdm_key_usage_bit_mask_t *)((uint8_t *)cert_info +
+      99                 :         10 :                                                        sizeof(spdm_certificate_info_t) *
+     100                 :            :                                                        slot_count);
+     101                 :            : 
+     102                 :         10 :     slot_index = 0;
+     103         [ +  + ]:         90 :     for (index = 0; index < SPDM_MAX_SLOT_COUNT; index++) {
+     104                 :         80 :         if (context->local_context
+     105         [ +  + ]:         80 :             .local_cert_chain_provision[index] != NULL) {
+     106                 :         12 :             spdm_response->header.param2 |= (1 << index);
+     107                 :         12 :             result = libspdm_generate_cert_chain_hash(context, index,
+     108                 :         12 :                                                       &digest[hash_size * slot_index]);
+     109         [ +  + ]:         12 :             if ((spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) &&
+     110         [ +  + ]:         10 :                 context->connection_info.multi_key_conn_req) {
+     111                 :          9 :                 key_pair_id[slot_index] = context->local_context.local_key_pair_id[index];
+     112                 :          9 :                 cert_info[slot_index] = context->local_context.local_cert_info[index];
+     113                 :          9 :                 key_usage_bit_mask[slot_index] =
+     114                 :          9 :                     context->local_context.local_key_usage_bit_mask[index];
+     115                 :            :             }
+     116                 :         12 :             slot_index++;
+     117         [ -  + ]:         12 :             if (!result) {
+     118                 :          0 :                 return libspdm_generate_encap_error_response(
+     119                 :            :                     context, SPDM_ERROR_CODE_UNSPECIFIED,
+     120                 :            :                     0, response_size, response);
+     121                 :            :             }
+     122                 :            :         }
+     123                 :            :     }
+     124                 :            : 
+     125                 :            :     /* Cache*/
+     126                 :            : 
+     127                 :         10 :     status = libspdm_append_message_mut_b(context, spdm_request,
+     128                 :            :                                           request_size);
+     129         [ -  + ]:         10 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     130                 :          0 :         return libspdm_generate_encap_error_response(
+     131                 :            :             context, SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     132                 :            :             response_size, response);
+     133                 :            :     }
+     134                 :            : 
+     135                 :         10 :     status = libspdm_append_message_mut_b(context, spdm_response,
+     136                 :            :                                           *response_size);
+     137         [ -  + ]:         10 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     138                 :          0 :         return libspdm_generate_encap_error_response(
+     139                 :            :             context, SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     140                 :            :             response_size, response);
+     141                 :            :     }
+     142                 :            : 
+     143         [ +  + ]:         10 :     if (context->last_spdm_request_session_id_valid) {
+     144                 :          3 :         session_id = context->last_spdm_request_session_id;
+     145                 :            :     } else {
+     146                 :          7 :         session_id = context->latest_session_id;
+     147                 :            :     }
+     148         [ +  + ]:         10 :     if (session_id != INVALID_SESSION_ID) {
+     149                 :          3 :         session_info = libspdm_get_session_info_via_session_id(context, session_id);
+     150                 :            :     } else {
+     151                 :          7 :         session_info = NULL;
+     152                 :            :     }
+     153         [ +  + ]:         10 :     if (session_info != NULL) {
+     154         [ +  + ]:          3 :         if (context->connection_info.multi_key_conn_req) {
+     155                 :          2 :             status = libspdm_append_message_encap_d(context, session_info, true,
+     156                 :            :                                                     spdm_response, *response_size);
+     157         [ -  + ]:          2 :             if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     158                 :          0 :                 return libspdm_generate_encap_error_response(
+     159                 :            :                     context, SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     160                 :            :                     response_size, response);
+     161                 :            :             }
+     162                 :            :         }
+     163                 :            :     }
+     164                 :            : 
+     165                 :         10 :     return LIBSPDM_STATUS_SUCCESS;
+     166                 :            : }
+     167                 :            : 
+     168                 :            : #endif /* (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (..) */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_encap_error.c.func-sort-c.html b/coverage_log/library/spdm_requester_lib/libspdm_req_encap_error.c.func-sort-c.html new file mode 100644 index 00000000000..1b68197685a --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_encap_error.c.func-sort-c.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_encap_error.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_encap_error.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:92045.0 %
Date:2024-09-22 08:21:07Functions:1250.0 %
Branches:1425.0 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_generate_encap_extended_error_response0
libspdm_generate_encap_error_response22
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_encap_error.c.func.html b/coverage_log/library/spdm_requester_lib/libspdm_req_encap_error.c.func.html new file mode 100644 index 00000000000..3563e7b07d7 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_encap_error.c.func.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_encap_error.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_encap_error.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:92045.0 %
Date:2024-09-22 08:21:07Functions:1250.0 %
Branches:1425.0 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_generate_encap_error_response22
libspdm_generate_encap_extended_error_response0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_encap_error.c.gcov.html b/coverage_log/library/spdm_requester_lib/libspdm_req_encap_error.c.gcov.html new file mode 100644 index 00000000000..b8852747b27 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_encap_error.c.gcov.html @@ -0,0 +1,137 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_encap_error.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_encap_error.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:92045.0 %
Date:2024-09-22 08:21:07Functions:1250.0 %
Branches:1425.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 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_ENCAP_CAP
+      10                 :            : 
+      11                 :         22 : libspdm_return_t libspdm_generate_encap_error_response(const void *spdm_context,
+      12                 :            :                                                        uint8_t error_code,
+      13                 :            :                                                        uint8_t error_data,
+      14                 :            :                                                        size_t *response_size,
+      15                 :            :                                                        void *response)
+      16                 :            : {
+      17                 :            :     spdm_error_response_t *spdm_response;
+      18                 :            : 
+      19         [ -  + ]:         22 :     LIBSPDM_ASSERT(*response_size >= sizeof(spdm_error_response_t));
+      20                 :         22 :     *response_size = sizeof(spdm_error_response_t);
+      21                 :         22 :     spdm_response = response;
+      22                 :            : 
+      23                 :         22 :     spdm_response->header.spdm_version = libspdm_get_connection_version (spdm_context);
+      24                 :         22 :     spdm_response->header.request_response_code = SPDM_ERROR;
+      25                 :         22 :     spdm_response->header.param1 = error_code;
+      26                 :         22 :     spdm_response->header.param2 = error_data;
+      27                 :            : 
+      28                 :         22 :     return LIBSPDM_STATUS_SUCCESS;
+      29                 :            : }
+      30                 :            : 
+      31                 :          0 : libspdm_return_t libspdm_generate_encap_extended_error_response(
+      32                 :            :     const void *spdm_context, uint8_t error_code, uint8_t error_data,
+      33                 :            :     size_t extended_error_data_size, const uint8_t *extended_error_data,
+      34                 :            :     size_t *response_size, void *response)
+      35                 :            : {
+      36                 :            :     spdm_error_response_t *spdm_response;
+      37         [ #  # ]:          0 :     LIBSPDM_ASSERT(*response_size >=
+      38                 :            :                    sizeof(spdm_error_response_t) + extended_error_data_size);
+      39                 :            : 
+      40                 :          0 :     spdm_response = response;
+      41                 :          0 :     spdm_response->header.spdm_version = libspdm_get_connection_version (spdm_context);
+      42                 :          0 :     spdm_response->header.request_response_code = SPDM_ERROR;
+      43                 :          0 :     spdm_response->header.param1 = error_code;
+      44                 :          0 :     spdm_response->header.param2 = error_data;
+      45                 :          0 :     libspdm_copy_mem(spdm_response + 1, *response_size - (sizeof(spdm_error_response_t)),
+      46                 :            :                      extended_error_data, extended_error_data_size);
+      47                 :          0 :     *response_size =
+      48                 :          0 :         sizeof(spdm_error_response_t) + extended_error_data_size;
+      49                 :          0 :     return LIBSPDM_STATUS_SUCCESS;
+      50                 :            : }
+      51                 :            : 
+      52                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_encap_key_update.c.func-sort-c.html b/coverage_log/library/spdm_requester_lib/libspdm_req_encap_key_update.c.func-sort-c.html new file mode 100644 index 00000000000..be0d3463a31 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_encap_key_update.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_encap_key_update.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_encap_key_update.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:525988.1 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:212680.8 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_encap_response_key_update15
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_encap_key_update.c.func.html b/coverage_log/library/spdm_requester_lib/libspdm_req_encap_key_update.c.func.html new file mode 100644 index 00000000000..03ce4f52221 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_encap_key_update.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_encap_key_update.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_encap_key_update.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:525988.1 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:212680.8 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_encap_response_key_update15
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_encap_key_update.c.gcov.html b/coverage_log/library/spdm_requester_lib/libspdm_req_encap_key_update.c.gcov.html new file mode 100644 index 00000000000..169345ca541 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_encap_key_update.c.gcov.html @@ -0,0 +1,238 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_encap_key_update.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_encap_key_update.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:525988.1 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:212680.8 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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                 :            : #include "internal/libspdm_secured_message_lib.h"
+       9                 :            : 
+      10                 :            : #if LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP
+      11                 :            : 
+      12                 :         15 : libspdm_return_t libspdm_get_encap_response_key_update(void *spdm_context,
+      13                 :            :                                                        size_t request_size,
+      14                 :            :                                                        void *request,
+      15                 :            :                                                        size_t *response_size,
+      16                 :            :                                                        void *response)
+      17                 :            : {
+      18                 :            :     uint32_t session_id;
+      19                 :            :     spdm_key_update_response_t *spdm_response;
+      20                 :            :     spdm_key_update_request_t *spdm_request;
+      21                 :            :     libspdm_context_t *context;
+      22                 :            :     libspdm_session_info_t *session_info;
+      23                 :            :     libspdm_session_state_t session_state;
+      24                 :            :     spdm_key_update_request_t *prev_spdm_request;
+      25                 :            :     spdm_key_update_request_t spdm_key_init_update_operation;
+      26                 :            :     bool result;
+      27                 :            : 
+      28                 :         15 :     context = spdm_context;
+      29                 :         15 :     spdm_request = request;
+      30                 :            : 
+      31         [ -  + ]:         15 :     if (libspdm_get_connection_version(context) < SPDM_MESSAGE_VERSION_11) {
+      32                 :          0 :         return libspdm_generate_encap_error_response(
+      33                 :            :             context, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+      34                 :            :             SPDM_KEY_UPDATE, response_size, response);
+      35                 :            :     }
+      36                 :            : 
+      37         [ -  + ]:         15 :     if (spdm_request->header.spdm_version != libspdm_get_connection_version(context)) {
+      38                 :          0 :         return libspdm_generate_encap_error_response(
+      39                 :            :             context, SPDM_ERROR_CODE_VERSION_MISMATCH,
+      40                 :            :             0, response_size, response);
+      41                 :            :     }
+      42                 :            : 
+      43         [ +  + ]:         15 :     if (!libspdm_is_capabilities_flag_supported(
+      44                 :            :             context, true,
+      45                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP,
+      46                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_UPD_CAP)) {
+      47                 :          1 :         return libspdm_generate_encap_error_response(
+      48                 :            :             context, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+      49                 :            :             SPDM_KEY_UPDATE, response_size, response);
+      50                 :            :     }
+      51                 :            : 
+      52         [ +  + ]:         14 :     if (!context->last_spdm_request_session_id_valid) {
+      53                 :          1 :         return libspdm_generate_encap_error_response(
+      54                 :            :             context, SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+      55                 :            :             response_size, response);
+      56                 :            :     }
+      57                 :         13 :     session_id = context->last_spdm_request_session_id;
+      58                 :            :     session_info =
+      59                 :         13 :         libspdm_get_session_info_via_session_id(context, session_id);
+      60         [ -  + ]:         13 :     if (session_info == NULL) {
+      61                 :          0 :         return libspdm_generate_encap_error_response(
+      62                 :            :             context, SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+      63                 :            :             response_size, response);
+      64                 :            :     }
+      65                 :         13 :     session_state = libspdm_secured_message_get_session_state(
+      66                 :            :         session_info->secured_message_context);
+      67         [ +  + ]:         13 :     if (session_state != LIBSPDM_SESSION_STATE_ESTABLISHED) {
+      68                 :          1 :         return libspdm_generate_encap_error_response(
+      69                 :            :             context, SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+      70                 :            :             response_size, response);
+      71                 :            :     }
+      72                 :            : 
+      73                 :            :     /* this message can only be in secured session
+      74                 :            :      * thus don't need to consider transport layer padding, just check its exact size */
+      75         [ +  + ]:         12 :     if (request_size != sizeof(spdm_key_update_request_t)) {
+      76                 :          2 :         return libspdm_generate_encap_error_response(
+      77                 :            :             context, SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+      78                 :            :             response_size, response);
+      79                 :            :     }
+      80                 :            : 
+      81                 :            :     /*last key operation*/
+      82                 :         10 :     prev_spdm_request = &(session_info->last_key_update_request);
+      83                 :            : 
+      84                 :            :     /*the end status of the successful key update overall flow*/
+      85                 :         10 :     libspdm_zero_mem(&spdm_key_init_update_operation, sizeof(spdm_key_update_request_t));
+      86                 :            : 
+      87                 :         10 :     result = true;
+      88   [ +  +  +  + ]:         10 :     switch (spdm_request->header.param1) {
+      89                 :          5 :     case SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY:
+      90         [ +  + ]:          5 :         if(!libspdm_consttime_is_mem_equal(prev_spdm_request,
+      91                 :            :                                            &spdm_key_init_update_operation,
+      92                 :            :                                            sizeof(spdm_key_update_request_t))) {
+      93                 :          1 :             result = false;
+      94                 :          1 :             break;
+      95                 :            :         }
+      96                 :          4 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+      97                 :            :                        "libspdm_create_update_session_data_key[%x] Responder\n",
+      98                 :            :                        session_id));
+      99                 :          4 :         result = libspdm_create_update_session_data_key(
+     100                 :            :             session_info->secured_message_context,
+     101                 :            :             LIBSPDM_KEY_UPDATE_ACTION_RESPONDER);
+     102                 :            : 
+     103                 :            :         /*save the last update operation*/
+     104                 :          4 :         libspdm_copy_mem(prev_spdm_request, sizeof(spdm_key_update_request_t),
+     105                 :            :                          spdm_request, request_size);
+     106                 :          4 :         break;
+     107                 :          1 :     case SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_ALL_KEYS:
+     108                 :          1 :         result = false;
+     109                 :          1 :         break;
+     110                 :          3 :     case SPDM_KEY_UPDATE_OPERATIONS_TABLE_VERIFY_NEW_KEY:
+     111         [ +  - ]:          3 :         if(prev_spdm_request->header.param1 !=
+     112                 :            :            SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY) {
+     113                 :          3 :             result = false;
+     114                 :          3 :             break;
+     115                 :            :         }
+     116                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+     117                 :            :                        "libspdm_activate_update_session_data_key[%x] Responder new\n",
+     118                 :            :                        session_id));
+     119                 :          0 :         result = libspdm_activate_update_session_data_key(
+     120                 :            :             session_info->secured_message_context,
+     121                 :            :             LIBSPDM_KEY_UPDATE_ACTION_RESPONDER, true);
+     122                 :            : 
+     123                 :            :         /*clear last_key_update_request*/
+     124                 :          0 :         libspdm_zero_mem(prev_spdm_request, sizeof(spdm_key_update_request_t));
+     125                 :          0 :         break;
+     126                 :          1 :     default:
+     127                 :          1 :         result = false;
+     128                 :          1 :         break;
+     129                 :            :     }
+     130                 :            : 
+     131         [ +  + ]:         10 :     if (!result) {
+     132                 :          6 :         return libspdm_generate_encap_error_response(
+     133                 :            :             context, SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     134                 :            :             response_size, response);
+     135                 :            :     }
+     136                 :            : 
+     137                 :          4 :     libspdm_reset_message_buffer_via_request_code(context, session_info,
+     138                 :          4 :                                                   spdm_request->header.request_response_code);
+     139                 :            : 
+     140         [ -  + ]:          4 :     LIBSPDM_ASSERT(*response_size >= sizeof(spdm_key_update_response_t));
+     141                 :          4 :     *response_size = sizeof(spdm_key_update_response_t);
+     142                 :          4 :     libspdm_zero_mem(response, *response_size);
+     143                 :          4 :     spdm_response = response;
+     144                 :            : 
+     145                 :          4 :     spdm_response->header.spdm_version = spdm_request->header.spdm_version;
+     146                 :          4 :     spdm_response->header.request_response_code = SPDM_KEY_UPDATE_ACK;
+     147                 :          4 :     spdm_response->header.param1 = spdm_request->header.param1;
+     148                 :          4 :     spdm_response->header.param2 = spdm_request->header.param2;
+     149                 :            : 
+     150                 :          4 :     return LIBSPDM_STATUS_SUCCESS;
+     151                 :            : }
+     152                 :            : 
+     153                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_encap_request.c.func-sort-c.html b/coverage_log/library/spdm_requester_lib/libspdm_req_encap_request.c.func-sort-c.html new file mode 100644 index 00000000000..097549fd745 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_encap_request.c.func-sort-c.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_encap_request.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_encap_request.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:13521164.0 %
Date:2024-09-22 08:21:07Functions:4580.0 %
Branches:459447.9 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_send_receive_encap_request0
libspdm_get_encap_response_func_via_request_code8
libspdm_process_encapsulated_request8
libspdm_encapsulated_request10
libspdm_register_get_encap_response_func10
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_encap_request.c.func.html b/coverage_log/library/spdm_requester_lib/libspdm_req_encap_request.c.func.html new file mode 100644 index 00000000000..4198746bec1 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_encap_request.c.func.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_encap_request.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_encap_request.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:13521164.0 %
Date:2024-09-22 08:21:07Functions:4580.0 %
Branches:459447.9 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_encapsulated_request10
libspdm_get_encap_response_func_via_request_code8
libspdm_process_encapsulated_request8
libspdm_register_get_encap_response_func10
libspdm_send_receive_encap_request0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_encap_request.c.gcov.html b/coverage_log/library/spdm_requester_lib/libspdm_req_encap_request.c.gcov.html new file mode 100644 index 00000000000..2621fee4df1 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_encap_request.c.gcov.html @@ -0,0 +1,538 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_encap_request.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_encap_request.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:13521164.0 %
Date:2024-09-22 08:21:07Functions:4580.0 %
Branches:459447.9 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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_ENCAP_CAP
+      10                 :            : 
+      11                 :            : typedef struct {
+      12                 :            :     uint8_t request_response_code;
+      13                 :            :     libspdm_get_encap_response_func get_encap_response_func;
+      14                 :            : } libspdm_get_encap_response_struct_t;
+      15                 :            : 
+      16                 :         10 : void libspdm_register_get_encap_response_func(void *spdm_context,
+      17                 :            :                                               const libspdm_get_encap_response_func
+      18                 :            :                                               get_encap_response_func)
+      19                 :            : {
+      20                 :            :     libspdm_context_t *context;
+      21                 :            : 
+      22                 :         10 :     context = spdm_context;
+      23                 :         10 :     context->get_encap_response_func = (void *)get_encap_response_func;
+      24                 :         10 : }
+      25                 :            : 
+      26                 :            : /**
+      27                 :            :  * Return the GET_ENCAP_RESPONSE function via request code.
+      28                 :            :  *
+      29                 :            :  * @param  request_code                  The SPDM request code.
+      30                 :            :  *
+      31                 :            :  * @return GET_ENCAP_RESPONSE function according to the request code.
+      32                 :            :  **/
+      33                 :            : static libspdm_get_encap_response_func
+      34                 :          8 : libspdm_get_encap_response_func_via_request_code(uint8_t request_response_code)
+      35                 :            : {
+      36                 :            :     size_t index;
+      37                 :            : 
+      38                 :          8 :     libspdm_get_encap_response_struct_t get_encap_response_struct[] = {
+      39                 :            :         #if LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP
+      40                 :            :         #if LIBSPDM_ENABLE_CAPABILITY_CERT_CAP
+      41                 :            :         { SPDM_GET_DIGESTS, libspdm_get_encap_response_digest },
+      42                 :            :         { SPDM_GET_CERTIFICATE, libspdm_get_encap_response_certificate },
+      43                 :            :         #endif /* LIBSPDM_ENABLE_CAPABILITY_CERT_CAP*/
+      44                 :            : 
+      45                 :            :         #if LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP
+      46                 :            :         { SPDM_CHALLENGE, libspdm_get_encap_response_challenge_auth },
+      47                 :            :         #endif /* LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP*/
+      48                 :            :         #endif /* LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP */
+      49                 :            : 
+      50                 :            :         { SPDM_KEY_UPDATE, libspdm_get_encap_response_key_update },
+      51                 :            :     };
+      52                 :            : 
+      53         [ +  + ]:         16 :     for (index = 0; index < sizeof(get_encap_response_struct) /
+      54                 :          8 :          sizeof(get_encap_response_struct[0]); index++) {
+      55         [ +  + ]:         15 :         if (request_response_code == get_encap_response_struct[index].request_response_code) {
+      56                 :          7 :             return get_encap_response_struct[index].get_encap_response_func;
+      57                 :            :         }
+      58                 :            :     }
+      59                 :          1 :     return NULL;
+      60                 :            : }
+      61                 :            : 
+      62                 :            : /**
+      63                 :            :  * This function processes encapsulated request.
+      64                 :            :  *
+      65                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+      66                 :            :  * @param  encap_request_size             size in bytes of the request data buffer.
+      67                 :            :  * @param  encap_request                 A pointer to a destination buffer to store the request.
+      68                 :            :  * @param  encap_response_size            size in bytes of the response data buffer.
+      69                 :            :  * @param  encap_response                A pointer to a destination buffer to store the response.
+      70                 :            :  *
+      71                 :            :  * @retval RETURN_SUCCESS               The SPDM response is processed successfully.
+      72                 :            :  * @retval RETURN_DEVICE_ERROR          A device error occurs when the SPDM response is sent to the device.
+      73                 :            :  **/
+      74                 :          8 : static libspdm_return_t libspdm_process_encapsulated_request(libspdm_context_t *spdm_context,
+      75                 :            :                                                              size_t encap_request_size,
+      76                 :            :                                                              void *encap_request,
+      77                 :            :                                                              size_t *encap_response_size,
+      78                 :            :                                                              void *encap_response)
+      79                 :            : {
+      80                 :            :     libspdm_get_encap_response_func get_encap_response_func;
+      81                 :            :     spdm_message_header_t *spdm_requester;
+      82                 :            : 
+      83                 :          8 :     spdm_requester = encap_request;
+      84         [ -  + ]:          8 :     if (encap_request_size < sizeof(spdm_message_header_t)) {
+      85                 :          0 :         return libspdm_generate_encap_error_response(
+      86                 :            :             spdm_context, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+      87                 :          0 :             spdm_requester->request_response_code,
+      88                 :            :             encap_response_size, encap_response);
+      89                 :            :     }
+      90                 :            : 
+      91                 :          8 :     get_encap_response_func = libspdm_get_encap_response_func_via_request_code(
+      92                 :          8 :         spdm_requester->request_response_code);
+      93         [ +  + ]:          8 :     if (get_encap_response_func == NULL) {
+      94                 :          1 :         get_encap_response_func =
+      95                 :            :             (libspdm_get_encap_response_func)
+      96                 :          1 :             spdm_context->get_encap_response_func;
+      97                 :            :     }
+      98         [ +  + ]:          8 :     if (get_encap_response_func != NULL) {
+      99                 :          7 :         return get_encap_response_func(
+     100                 :            :             spdm_context, encap_request_size, encap_request,
+     101                 :            :             encap_response_size, encap_response);
+     102                 :            :     } else {
+     103                 :          1 :         return libspdm_generate_encap_error_response(
+     104                 :            :             spdm_context, SPDM_ERROR_CODE_UNEXPECTED_REQUEST,
+     105                 :            :             0,
+     106                 :            :             encap_response_size, encap_response);
+     107                 :            :     }
+     108                 :            : }
+     109                 :            : 
+     110                 :         10 : libspdm_return_t libspdm_encapsulated_request(libspdm_context_t *spdm_context,
+     111                 :            :                                               const uint32_t *session_id,
+     112                 :            :                                               uint8_t mut_auth_requested,
+     113                 :            :                                               uint8_t *req_slot_id_param)
+     114                 :            : {
+     115                 :            :     libspdm_return_t status;
+     116                 :            :     uint8_t *spdm_request;
+     117                 :            :     size_t spdm_request_size;
+     118                 :            :     spdm_get_encapsulated_request_request_t
+     119                 :            :     *spdm_get_encapsulated_request_request;
+     120                 :            :     spdm_deliver_encapsulated_response_request_t
+     121                 :            :     *spdm_deliver_encapsulated_response_request;
+     122                 :            :     uint8_t *spdm_response;
+     123                 :            :     size_t spdm_response_size;
+     124                 :            :     spdm_encapsulated_request_response_t *libspdm_encapsulated_request_response;
+     125                 :            :     spdm_encapsulated_response_ack_response_t
+     126                 :            :     *spdm_encapsulated_response_ack_response;
+     127                 :            :     libspdm_session_info_t *session_info;
+     128                 :            :     uint8_t request_id;
+     129                 :            :     void *encapsulated_request;
+     130                 :            :     size_t encapsulated_request_size;
+     131                 :            :     void *encapsulated_response;
+     132                 :            :     size_t encapsulated_response_size;
+     133                 :            :     size_t ack_header_size;
+     134                 :            : 
+     135                 :            :     uint8_t *message;
+     136                 :            :     size_t message_size;
+     137                 :            :     size_t transport_header_size;
+     138                 :            : 
+     139                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_CERT_CAP
+     140                 :            :     spdm_get_digest_request_t *get_digests;
+     141                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_CERT_CAP*/
+     142                 :            : 
+     143         [ -  + ]:         10 :     if (!libspdm_is_encap_supported(spdm_context)) {
+     144                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     145                 :            :     }
+     146                 :            : 
+     147         [ -  + ]:         10 :     if (session_id != NULL) {
+     148                 :          0 :         session_info = libspdm_get_session_info_via_session_id(
+     149                 :            :             spdm_context, *session_id);
+     150         [ #  # ]:          0 :         if (session_info == NULL) {
+     151                 :          0 :             LIBSPDM_ASSERT(false);
+     152                 :          0 :             return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+     153                 :            :         }
+     154   [ #  #  #  #  :          0 :         LIBSPDM_ASSERT((mut_auth_requested == 0) ||
+                   #  # ]
+     155                 :            :                        (mut_auth_requested ==
+     156                 :            :                         SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_ENCAP_REQUEST) ||
+     157                 :            :                        (mut_auth_requested ==
+     158                 :            :                         SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_GET_DIGESTS));
+     159                 :            :     } else {
+     160         [ -  + ]:         10 :         LIBSPDM_ASSERT(mut_auth_requested == 0);
+     161                 :            :     }
+     162                 :            : 
+     163                 :            : 
+     164                 :            :     /* Cache*/
+     165                 :            : 
+     166                 :         10 :     libspdm_reset_message_mut_b(spdm_context);
+     167                 :         10 :     libspdm_reset_message_mut_c(spdm_context);
+     168                 :            : 
+     169         [ +  - ]:         10 :     if (session_id == NULL) {
+     170                 :         10 :         spdm_context->last_spdm_request_session_id_valid = false;
+     171                 :         10 :         spdm_context->last_spdm_request_session_id = 0;
+     172                 :            :     } else {
+     173                 :          0 :         spdm_context->last_spdm_request_session_id_valid = true;
+     174                 :          0 :         spdm_context->last_spdm_request_session_id = *session_id;
+     175                 :            :     }
+     176                 :            : 
+     177         [ -  + ]:         10 :     if (mut_auth_requested ==
+     178                 :            :         SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_GET_DIGESTS) {
+     179                 :            : 
+     180                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CERT_CAP
+     181                 :            : 
+     182                 :          0 :         get_digests = (void *)spdm_context->last_spdm_request;
+     183                 :          0 :         get_digests->header.spdm_version = libspdm_get_connection_version (spdm_context);
+     184                 :          0 :         get_digests->header.request_response_code = SPDM_GET_DIGESTS;
+     185                 :          0 :         get_digests->header.param1 = 0;
+     186                 :          0 :         get_digests->header.param2 = 0;
+     187                 :          0 :         spdm_context->last_spdm_request_size = sizeof(spdm_get_digest_request_t);
+     188                 :          0 :         encapsulated_request = (void *)spdm_context->last_spdm_request;
+     189                 :          0 :         encapsulated_request_size = spdm_context->last_spdm_request_size;
+     190                 :          0 :         request_id = 0;
+     191                 :            : #else /* LIBSPDM_ENABLE_CAPABILITY_CERT_CAP*/
+     192                 :            :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     193                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CERT_CAP*/
+     194                 :            :     } else {
+     195                 :            : 
+     196                 :         10 :         transport_header_size = spdm_context->local_context.capability.transport_header_size;
+     197                 :         10 :         status = libspdm_acquire_sender_buffer (spdm_context, &message_size, (void **)&message);
+     198         [ -  + ]:         10 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     199                 :          0 :             return status;
+     200                 :            :         }
+     201         [ -  + ]:         10 :         LIBSPDM_ASSERT (message_size >= transport_header_size +
+     202                 :            :                         spdm_context->local_context.capability.transport_tail_size);
+     203                 :         10 :         spdm_request = (void *)(message + transport_header_size);
+     204                 :         10 :         spdm_request_size = message_size - transport_header_size -
+     205                 :         10 :                             spdm_context->local_context.capability.transport_tail_size;
+     206                 :            : 
+     207                 :         10 :         spdm_context->crypto_request = true;
+     208                 :         10 :         spdm_get_encapsulated_request_request = (void *)spdm_request;
+     209                 :         10 :         spdm_get_encapsulated_request_request->header.spdm_version =
+     210                 :         10 :             libspdm_get_connection_version (spdm_context);
+     211                 :            :         spdm_get_encapsulated_request_request->header
+     212                 :         10 :         .request_response_code = SPDM_GET_ENCAPSULATED_REQUEST;
+     213                 :         10 :         spdm_get_encapsulated_request_request->header.param1 = 0;
+     214                 :         10 :         spdm_get_encapsulated_request_request->header.param2 = 0;
+     215                 :         10 :         spdm_request_size =
+     216                 :            :             sizeof(spdm_get_encapsulated_request_request_t);
+     217                 :         10 :         libspdm_reset_message_buffer_via_request_code(spdm_context, NULL,
+     218                 :         10 :                                                       spdm_get_encapsulated_request_request->header.request_response_code);
+     219                 :         10 :         status = libspdm_send_spdm_request(
+     220                 :            :             spdm_context, session_id, spdm_request_size,
+     221                 :            :             spdm_request);
+     222         [ +  + ]:         10 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     223                 :          1 :             libspdm_release_sender_buffer (spdm_context);
+     224                 :          1 :             return status;
+     225                 :            :         }
+     226                 :          9 :         libspdm_release_sender_buffer (spdm_context);
+     227                 :          9 :         spdm_get_encapsulated_request_request = (void *)spdm_context->last_spdm_request;
+     228                 :            : 
+     229                 :            :         /* receive */
+     230                 :            : 
+     231                 :          9 :         status = libspdm_acquire_receiver_buffer (spdm_context, &message_size, (void **)&message);
+     232         [ -  + ]:          9 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     233                 :          0 :             return status;
+     234                 :            :         }
+     235         [ -  + ]:          9 :         LIBSPDM_ASSERT (message_size >= transport_header_size);
+     236                 :          9 :         spdm_response = (void *)(message);
+     237                 :          9 :         spdm_response_size = message_size;
+     238                 :            : 
+     239                 :          9 :         status = libspdm_receive_spdm_response(
+     240                 :            :             spdm_context, session_id, &spdm_response_size,
+     241                 :            :             (void **)&spdm_response);
+     242                 :          9 :         libspdm_encapsulated_request_response = (void *)spdm_response;
+     243         [ -  + ]:          9 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     244                 :          0 :             libspdm_release_receiver_buffer (spdm_context);
+     245                 :          0 :             return status;
+     246                 :            :         }
+     247                 :          9 :         if (libspdm_encapsulated_request_response->header
+     248         [ -  + ]:          9 :             .request_response_code !=
+     249                 :            :             SPDM_ENCAPSULATED_REQUEST) {
+     250                 :          0 :             libspdm_release_receiver_buffer (spdm_context);
+     251                 :          0 :             return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     252                 :            :         }
+     253                 :          9 :         if (libspdm_encapsulated_request_response->header.spdm_version !=
+     254         [ -  + ]:          9 :             spdm_get_encapsulated_request_request->header.spdm_version) {
+     255                 :          0 :             libspdm_release_receiver_buffer (spdm_context);
+     256                 :          0 :             return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     257                 :            :         }
+     258         [ -  + ]:          9 :         if (spdm_response_size < sizeof(spdm_encapsulated_request_response_t)) {
+     259                 :          0 :             libspdm_release_receiver_buffer (spdm_context);
+     260                 :          0 :             return LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     261                 :            :         }
+     262         [ +  + ]:          9 :         if (spdm_response_size == sizeof(spdm_encapsulated_request_response_t)) {
+     263                 :            : 
+     264                 :            :             /* Done*/
+     265                 :          1 :             libspdm_release_receiver_buffer (spdm_context);
+     266                 :          1 :             return LIBSPDM_STATUS_SUCCESS;
+     267                 :            :         }
+     268                 :          8 :         request_id = libspdm_encapsulated_request_response->header.param1;
+     269                 :            : 
+     270                 :          8 :         encapsulated_request = (void *)(libspdm_encapsulated_request_response + 1);
+     271                 :          8 :         encapsulated_request_size =
+     272                 :          8 :             spdm_response_size - sizeof(spdm_encapsulated_request_response_t);
+     273                 :            : 
+     274                 :          8 :         libspdm_copy_mem (spdm_context->last_spdm_request,
+     275                 :          8 :                           libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context),
+     276                 :            :                           encapsulated_request,
+     277                 :            :                           encapsulated_request_size);
+     278                 :          8 :         spdm_context->last_spdm_request_size = encapsulated_request_size;
+     279                 :          8 :         encapsulated_request = (void *)spdm_context->last_spdm_request;
+     280                 :            : 
+     281                 :          8 :         libspdm_release_receiver_buffer (spdm_context);
+     282                 :            :     }
+     283                 :            : 
+     284                 :            :     while (true) {
+     285                 :            : 
+     286                 :            :         /* Process request*/
+     287                 :          8 :         transport_header_size = spdm_context->local_context.capability.transport_header_size;
+     288                 :          8 :         status = libspdm_acquire_sender_buffer (spdm_context, &message_size, (void **)&message);
+     289         [ -  + ]:          8 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     290                 :          0 :             return status;
+     291                 :            :         }
+     292         [ -  + ]:          8 :         LIBSPDM_ASSERT (message_size >= transport_header_size +
+     293                 :            :                         spdm_context->local_context.capability.transport_tail_size);
+     294                 :          8 :         spdm_request = (void *)(message + transport_header_size);
+     295                 :          8 :         spdm_request_size = message_size - transport_header_size -
+     296                 :          8 :                             spdm_context->local_context.capability.transport_tail_size;
+     297                 :            : 
+     298                 :          8 :         spdm_context->crypto_request = true;
+     299                 :          8 :         spdm_deliver_encapsulated_response_request = (void *)spdm_request;
+     300                 :          8 :         spdm_deliver_encapsulated_response_request->header.spdm_version =
+     301                 :          8 :             libspdm_get_connection_version (spdm_context);
+     302                 :            :         spdm_deliver_encapsulated_response_request->header
+     303                 :          8 :         .request_response_code =
+     304                 :            :             SPDM_DELIVER_ENCAPSULATED_RESPONSE;
+     305                 :          8 :         spdm_deliver_encapsulated_response_request->header.param1 = request_id;
+     306                 :          8 :         spdm_deliver_encapsulated_response_request->header.param2 = 0;
+     307                 :          8 :         encapsulated_response = (void *)(spdm_deliver_encapsulated_response_request + 1);
+     308                 :          8 :         encapsulated_response_size =
+     309                 :          8 :             spdm_request_size - sizeof(spdm_deliver_encapsulated_response_request_t);
+     310                 :            : 
+     311                 :          8 :         status = libspdm_process_encapsulated_request(
+     312                 :            :             spdm_context, encapsulated_request_size,
+     313                 :            :             encapsulated_request, &encapsulated_response_size,
+     314                 :            :             encapsulated_response);
+     315         [ -  + ]:          8 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     316                 :          0 :             libspdm_release_sender_buffer (spdm_context);
+     317                 :          0 :             return status;
+     318                 :            :         }
+     319                 :            : 
+     320                 :          8 :         spdm_request_size =
+     321                 :          8 :             sizeof(spdm_deliver_encapsulated_response_request_t) + encapsulated_response_size;
+     322                 :          8 :         status = libspdm_send_spdm_request(
+     323                 :            :             spdm_context, session_id, spdm_request_size,
+     324                 :            :             spdm_request);
+     325         [ -  + ]:          8 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     326                 :          0 :             libspdm_release_sender_buffer (spdm_context);
+     327                 :          0 :             return status;
+     328                 :            :         }
+     329                 :          8 :         libspdm_release_sender_buffer (spdm_context);
+     330                 :          8 :         spdm_deliver_encapsulated_response_request = (void *)spdm_context->last_spdm_request;
+     331                 :            : 
+     332                 :            :         /* receive */
+     333                 :            : 
+     334                 :          8 :         status = libspdm_acquire_receiver_buffer (spdm_context, &message_size, (void **)&message);
+     335         [ -  + ]:          8 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     336                 :          0 :             return status;
+     337                 :            :         }
+     338         [ -  + ]:          8 :         LIBSPDM_ASSERT (message_size >= transport_header_size);
+     339                 :          8 :         spdm_response = (void *)(message);
+     340                 :          8 :         spdm_response_size = message_size;
+     341                 :            : 
+     342                 :          8 :         status = libspdm_receive_spdm_response(
+     343                 :            :             spdm_context, session_id, &spdm_response_size,
+     344                 :            :             (void **)&spdm_response);
+     345                 :          8 :         spdm_encapsulated_response_ack_response = (void *)spdm_response;
+     346         [ -  + ]:          8 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     347                 :          0 :             libspdm_release_receiver_buffer (spdm_context);
+     348                 :          0 :             return status;
+     349                 :            :         }
+     350                 :          8 :         if (spdm_encapsulated_response_ack_response->header
+     351         [ +  + ]:          8 :             .request_response_code !=
+     352                 :            :             SPDM_ENCAPSULATED_RESPONSE_ACK) {
+     353                 :          1 :             libspdm_release_receiver_buffer (spdm_context);
+     354                 :          1 :             return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     355                 :            :         }
+     356                 :          7 :         if (spdm_encapsulated_response_ack_response->header.spdm_version !=
+     357         [ -  + ]:          7 :             spdm_deliver_encapsulated_response_request->header.spdm_version) {
+     358                 :          0 :             libspdm_release_receiver_buffer (spdm_context);
+     359                 :          0 :             return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     360                 :            :         }
+     361         [ -  + ]:          7 :         if (spdm_encapsulated_response_ack_response->header.spdm_version >=
+     362                 :            :             SPDM_MESSAGE_VERSION_12) {
+     363                 :          0 :             ack_header_size = sizeof(spdm_encapsulated_response_ack_response_t);
+     364                 :            :         } else {
+     365                 :          7 :             ack_header_size = sizeof(spdm_message_header_t);
+     366                 :            :         }
+     367         [ -  + ]:          7 :         if (spdm_response_size < ack_header_size) {
+     368                 :          0 :             libspdm_release_receiver_buffer (spdm_context);
+     369                 :          0 :             return LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     370                 :            :         }
+     371                 :            : 
+     372         [ -  + ]:          7 :         if (spdm_encapsulated_response_ack_response->header.spdm_version >=
+     373                 :            :             SPDM_MESSAGE_VERSION_12) {
+     374                 :          0 :             if (spdm_encapsulated_response_ack_response->ack_request_id !=
+     375         [ #  # ]:          0 :                 spdm_deliver_encapsulated_response_request->header.param1) {
+     376                 :          0 :                 libspdm_release_receiver_buffer (spdm_context);
+     377                 :          0 :                 return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     378                 :            :             }
+     379                 :            :         }
+     380                 :            : 
+     381   [ +  -  +  - ]:          7 :         switch (spdm_encapsulated_response_ack_response->header.param2) {
+     382                 :          6 :         case SPDM_ENCAPSULATED_RESPONSE_ACK_RESPONSE_PAYLOAD_TYPE_ABSENT:
+     383         [ +  + ]:          6 :             if (spdm_response_size == ack_header_size) {
+     384                 :          4 :                 libspdm_release_receiver_buffer (spdm_context);
+     385                 :          4 :                 return LIBSPDM_STATUS_SUCCESS;
+     386                 :            :             } else {
+     387                 :          2 :                 libspdm_release_receiver_buffer (spdm_context);
+     388                 :          2 :                 return LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     389                 :            :             }
+     390                 :            :             break;
+     391                 :          0 :         case SPDM_ENCAPSULATED_RESPONSE_ACK_RESPONSE_PAYLOAD_TYPE_PRESENT:
+     392                 :          0 :             break;
+     393                 :          1 :         case SPDM_ENCAPSULATED_RESPONSE_ACK_RESPONSE_PAYLOAD_TYPE_REQ_SLOT_NUMBER:
+     394         [ +  - ]:          1 :             if (spdm_response_size >= ack_header_size + sizeof(uint8_t)) {
+     395         [ -  + ]:          1 :                 if ((req_slot_id_param != NULL) &&
+     396         [ #  # ]:          0 :                     (*req_slot_id_param == 0)) {
+     397                 :          0 :                     *req_slot_id_param =
+     398                 :          0 :                         *((uint8_t *)spdm_encapsulated_response_ack_response + ack_header_size);
+     399                 :            :                     /* 0xFF or 0xF slot is not allowed. */
+     400         [ #  # ]:          0 :                     if (*req_slot_id_param >= SPDM_MAX_SLOT_COUNT) {
+     401                 :          0 :                         libspdm_release_receiver_buffer (spdm_context);
+     402                 :          0 :                         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     403                 :            :                     }
+     404                 :            : 
+     405         [ #  # ]:          0 :                     if ((spdm_encapsulated_response_ack_response->header.spdm_version >=
+     406                 :          0 :                          SPDM_MESSAGE_VERSION_13) &&
+     407         [ #  # ]:          0 :                         spdm_context->connection_info.multi_key_conn_req) {
+     408                 :          0 :                         if ((spdm_context->local_context.local_key_usage_bit_mask[*req_slot_id_param
+     409         [ #  # ]:          0 :                              ] & SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE) == 0) {
+     410                 :          0 :                             libspdm_release_receiver_buffer (spdm_context);
+     411                 :          0 :                             return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     412                 :            :                         }
+     413                 :            :                     }
+     414                 :            :                 }
+     415                 :          1 :                 libspdm_release_receiver_buffer (spdm_context);
+     416                 :          1 :                 return LIBSPDM_STATUS_SUCCESS;
+     417                 :            :             } else {
+     418                 :          0 :                 libspdm_release_receiver_buffer (spdm_context);
+     419                 :          0 :                 return LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     420                 :            :             }
+     421                 :            :             break;
+     422                 :          0 :         default:
+     423                 :          0 :             libspdm_release_receiver_buffer (spdm_context);
+     424                 :          0 :             return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     425                 :            :         }
+     426                 :          0 :         request_id =
+     427                 :            :             spdm_encapsulated_response_ack_response->header.param1;
+     428                 :            : 
+     429                 :          0 :         encapsulated_request =
+     430                 :            :             ((uint8_t *)spdm_encapsulated_response_ack_response + ack_header_size);
+     431                 :          0 :         encapsulated_request_size = spdm_response_size - ack_header_size;
+     432                 :            : 
+     433                 :          0 :         libspdm_copy_mem (spdm_context->last_spdm_request,
+     434                 :          0 :                           libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context),
+     435                 :            :                           encapsulated_request,
+     436                 :            :                           encapsulated_request_size
+     437                 :            :                           );
+     438                 :          0 :         spdm_context->last_spdm_request_size = encapsulated_request_size;
+     439                 :          0 :         encapsulated_request = (void *)spdm_context->last_spdm_request;
+     440                 :            : 
+     441                 :          0 :         libspdm_release_receiver_buffer (spdm_context);
+     442                 :            :     }
+     443                 :            : 
+     444                 :            :     return LIBSPDM_STATUS_SUCCESS;
+     445                 :            : }
+     446                 :            : 
+     447                 :          0 : libspdm_return_t libspdm_send_receive_encap_request(void *spdm_context, const uint32_t *session_id)
+     448                 :            : {
+     449                 :          0 :     return libspdm_encapsulated_request(spdm_context, session_id, 0, NULL);
+     450                 :            : }
+     451                 :            : 
+     452                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_end_session.c.func-sort-c.html b/coverage_log/library/spdm_requester_lib/libspdm_req_end_session.c.func-sort-c.html new file mode 100644 index 00000000000..930935d1f71 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_end_session.c.func-sort-c.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_end_session.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_end_session.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:637880.8 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:264065.0 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_send_receive_end_session29
libspdm_try_send_receive_end_session30
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_end_session.c.func.html b/coverage_log/library/spdm_requester_lib/libspdm_req_end_session.c.func.html new file mode 100644 index 00000000000..4ecb8183794 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_end_session.c.func.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_end_session.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_end_session.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:637880.8 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:264065.0 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_send_receive_end_session29
libspdm_try_send_receive_end_session30
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_end_session.c.gcov.html b/coverage_log/library/spdm_requester_lib/libspdm_req_end_session.c.gcov.html new file mode 100644 index 00000000000..3ab36dff111 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_end_session.c.gcov.html @@ -0,0 +1,267 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_end_session.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_end_session.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:637880.8 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:264065.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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                 :            : #include "internal/libspdm_secured_message_lib.h"
+       9                 :            : 
+      10                 :            : #if (LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP) || (LIBSPDM_ENABLE_CAPABILITY_PSK_CAP)
+      11                 :            : 
+      12                 :            : #pragma pack(1)
+      13                 :            : typedef struct {
+      14                 :            :     spdm_message_header_t header;
+      15                 :            :     uint8_t dummy_data[sizeof(spdm_error_data_response_not_ready_t)];
+      16                 :            : } libspdm_end_session_response_mine_t;
+      17                 :            : #pragma pack()
+      18                 :            : 
+      19                 :            : /**
+      20                 :            :  * This function sends END_SESSION and receives END_SESSION_ACK for SPDM session end.
+      21                 :            :  *
+      22                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+      23                 :            :  * @param  session_id                    session_id to the END_SESSION request.
+      24                 :            :  * @param  end_session_attributes         end_session_attributes to the END_SESSION_ACK request.
+      25                 :            :  *
+      26                 :            :  * @retval RETURN_SUCCESS               The END_SESSION is sent and the END_SESSION_ACK is received.
+      27                 :            :  * @retval RETURN_DEVICE_ERROR          A device error occurs when communicates with the device.
+      28                 :            :  **/
+      29                 :         30 : static libspdm_return_t libspdm_try_send_receive_end_session(libspdm_context_t *spdm_context,
+      30                 :            :                                                              uint32_t session_id,
+      31                 :            :                                                              uint8_t end_session_attributes)
+      32                 :            : {
+      33                 :            :     libspdm_return_t status;
+      34                 :            :     spdm_end_session_request_t *spdm_request;
+      35                 :            :     size_t spdm_request_size;
+      36                 :            :     libspdm_end_session_response_mine_t *spdm_response;
+      37                 :            :     size_t spdm_response_size;
+      38                 :            :     libspdm_session_info_t *session_info;
+      39                 :            :     libspdm_session_state_t session_state;
+      40                 :            :     uint8_t *message;
+      41                 :            :     size_t message_size;
+      42                 :            :     size_t transport_header_size;
+      43                 :            : 
+      44         [ -  + ]:         30 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_11) {
+      45                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+      46                 :            :     }
+      47                 :            : 
+      48         [ +  + ]:         30 :     if (spdm_context->connection_info.connection_state <
+      49                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
+      50                 :          1 :         return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+      51                 :            :     }
+      52                 :         29 :     session_info = libspdm_get_session_info_via_session_id(spdm_context, session_id);
+      53         [ -  + ]:         29 :     if (session_info == NULL) {
+      54                 :          0 :         LIBSPDM_ASSERT(false);
+      55                 :          0 :         return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+      56                 :            :     }
+      57                 :         29 :     session_state = libspdm_secured_message_get_session_state(
+      58                 :            :         session_info->secured_message_context);
+      59         [ -  + ]:         29 :     if (session_state != LIBSPDM_SESSION_STATE_ESTABLISHED) {
+      60                 :          0 :         return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+      61                 :            :     }
+      62                 :            : 
+      63         [ +  - ]:         29 :     if (!libspdm_is_capabilities_flag_supported(
+      64                 :            :             spdm_context, true, 0,
+      65                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CACHE_CAP)) {
+      66                 :         29 :         end_session_attributes = 0;
+      67                 :            :     }
+      68                 :            : 
+      69                 :         29 :     transport_header_size = spdm_context->local_context.capability.transport_header_size;
+      70                 :         29 :     status = libspdm_acquire_sender_buffer (spdm_context, &message_size, (void **)&message);
+      71         [ -  + ]:         29 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+      72                 :          0 :         return status;
+      73                 :            :     }
+      74         [ -  + ]:         29 :     LIBSPDM_ASSERT (message_size >= transport_header_size +
+      75                 :            :                     spdm_context->local_context.capability.transport_tail_size);
+      76                 :         29 :     spdm_request = (void *)(message + transport_header_size);
+      77                 :         29 :     spdm_request_size = message_size - transport_header_size -
+      78                 :         29 :                         spdm_context->local_context.capability.transport_tail_size;
+      79                 :            : 
+      80         [ -  + ]:         29 :     LIBSPDM_ASSERT (spdm_request_size >= sizeof(spdm_end_session_request_t));
+      81                 :         29 :     spdm_request->header.spdm_version = libspdm_get_connection_version (spdm_context);
+      82                 :         29 :     spdm_request->header.request_response_code = SPDM_END_SESSION;
+      83                 :         29 :     spdm_request->header.param1 = end_session_attributes;
+      84                 :         29 :     spdm_request->header.param2 = 0;
+      85                 :            : 
+      86                 :         29 :     spdm_request_size = sizeof(spdm_end_session_request_t);
+      87                 :         29 :     status = libspdm_send_spdm_request(spdm_context, &session_id, spdm_request_size, spdm_request);
+      88         [ +  + ]:         29 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+      89                 :          1 :         libspdm_release_sender_buffer (spdm_context);
+      90                 :          1 :         return status;
+      91                 :            :     }
+      92                 :            : 
+      93                 :         28 :     libspdm_reset_message_buffer_via_request_code(spdm_context, session_info, SPDM_END_SESSION);
+      94                 :            : 
+      95                 :         28 :     libspdm_release_sender_buffer (spdm_context);
+      96                 :         28 :     spdm_request = (void *)spdm_context->last_spdm_request;
+      97                 :            : 
+      98                 :            :     /* receive */
+      99                 :            : 
+     100                 :         28 :     status = libspdm_acquire_receiver_buffer (spdm_context, &message_size, (void **)&message);
+     101         [ -  + ]:         28 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     102                 :          0 :         return status;
+     103                 :            :     }
+     104         [ -  + ]:         28 :     LIBSPDM_ASSERT (message_size >= transport_header_size);
+     105                 :         28 :     spdm_response = (void *)(message);
+     106                 :         28 :     spdm_response_size = message_size;
+     107                 :            : 
+     108                 :         28 :     status = libspdm_receive_spdm_response(
+     109                 :            :         spdm_context, &session_id, &spdm_response_size, (void **)&spdm_response);
+     110         [ -  + ]:         28 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     111                 :          0 :         goto receive_done;
+     112                 :            :     }
+     113         [ -  + ]:         28 :     if (spdm_response_size < sizeof(spdm_message_header_t)) {
+     114                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     115                 :          0 :         goto receive_done;
+     116                 :            :     }
+     117         [ -  + ]:         28 :     if (spdm_response->header.spdm_version != spdm_request->header.spdm_version) {
+     118                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     119                 :          0 :         goto receive_done;
+     120                 :            :     }
+     121         [ +  + ]:         28 :     if (spdm_response->header.request_response_code == SPDM_ERROR) {
+     122                 :         25 :         status = libspdm_handle_error_response_main(
+     123                 :            :             spdm_context, &session_id, &spdm_response_size,
+     124                 :            :             (void **)&spdm_response, SPDM_END_SESSION, SPDM_END_SESSION_ACK);
+     125         [ +  + ]:         25 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     126                 :         24 :             goto receive_done;
+     127                 :            :         }
+     128         [ -  + ]:          3 :     } else if (spdm_response->header.request_response_code != SPDM_END_SESSION_ACK) {
+     129                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     130                 :          0 :         goto receive_done;
+     131                 :            :     }
+     132                 :            :     /* this message can only be in secured session
+     133                 :            :      * thus don't need to consider transport layer padding, just check its exact size */
+     134         [ -  + ]:          4 :     if (spdm_response_size != sizeof(spdm_end_session_response_t)) {
+     135                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     136                 :          0 :         goto receive_done;
+     137                 :            :     }
+     138                 :            : 
+     139                 :          4 :     session_info->end_session_attributes = end_session_attributes;
+     140                 :            : 
+     141                 :          4 :     libspdm_secured_message_set_session_state(
+     142                 :            :         session_info->secured_message_context,
+     143                 :            :         LIBSPDM_SESSION_STATE_NOT_STARTED);
+     144                 :          4 :     libspdm_free_session_id(spdm_context, session_id);
+     145                 :            : 
+     146                 :          4 :     status = LIBSPDM_STATUS_SUCCESS;
+     147                 :            : 
+     148                 :            :     /* -=[Log Message Phase]=- */
+     149                 :            :     #if LIBSPDM_ENABLE_MSG_LOG
+     150                 :          4 :     libspdm_append_msg_log(spdm_context, spdm_response, spdm_response_size);
+     151                 :            :     #endif /* LIBSPDM_ENABLE_MSG_LOG */
+     152                 :            : 
+     153                 :         28 : receive_done:
+     154                 :         28 :     libspdm_release_receiver_buffer (spdm_context);
+     155                 :         28 :     return status;
+     156                 :            : }
+     157                 :            : 
+     158                 :         29 : libspdm_return_t libspdm_send_receive_end_session(libspdm_context_t *spdm_context,
+     159                 :            :                                                   uint32_t session_id,
+     160                 :            :                                                   uint8_t end_session_attributes)
+     161                 :            : {
+     162                 :            :     size_t retry;
+     163                 :            :     uint64_t retry_delay_time;
+     164                 :            :     libspdm_return_t status;
+     165                 :            : 
+     166                 :         29 :     spdm_context->crypto_request = true;
+     167                 :         29 :     retry = spdm_context->retry_times;
+     168                 :         29 :     retry_delay_time = spdm_context->retry_delay_time;
+     169                 :            :     do {
+     170                 :         30 :         status = libspdm_try_send_receive_end_session(
+     171                 :            :             spdm_context, session_id, end_session_attributes);
+     172         [ +  + ]:         30 :         if (status != LIBSPDM_STATUS_BUSY_PEER) {
+     173                 :         28 :             return status;
+     174                 :            :         }
+     175                 :            : 
+     176                 :          2 :         libspdm_sleep(retry_delay_time);
+     177         [ +  + ]:          2 :     } while (retry-- != 0);
+     178                 :            : 
+     179                 :          1 :     return status;
+     180                 :            : }
+     181                 :            : 
+     182                 :            : #endif /* (LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP) || (LIBSPDM_ENABLE_CAPABILITY_PSK_CAP) */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_finish.c.func-sort-c.html b/coverage_log/library/spdm_requester_lib/libspdm_req_finish.c.func-sort-c.html new file mode 100644 index 00000000000..cd957d7b680 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_finish.c.func-sort-c.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_finish.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_finish.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:16820382.8 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:7110269.6 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_generate_finish_req_signature5
libspdm_verify_finish_rsp_hmac9
libspdm_generate_finish_req_hmac37
libspdm_send_receive_finish40
libspdm_try_send_receive_finish41
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_finish.c.func.html b/coverage_log/library/spdm_requester_lib/libspdm_req_finish.c.func.html new file mode 100644 index 00000000000..6e370e8f62d --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_finish.c.func.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_finish.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_finish.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:16820382.8 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:7110269.6 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_generate_finish_req_hmac37
libspdm_generate_finish_req_signature5
libspdm_send_receive_finish40
libspdm_try_send_receive_finish41
libspdm_verify_finish_rsp_hmac9
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_finish.c.gcov.html b/coverage_log/library/spdm_requester_lib/libspdm_req_finish.c.gcov.html new file mode 100644 index 00000000000..570708a493a --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_finish.c.gcov.html @@ -0,0 +1,725 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_finish.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_finish.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:16820382.8 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:7110269.6 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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                 :            : #include "internal/libspdm_secured_message_lib.h"
+       9                 :            : 
+      10                 :            : #if LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP
+      11                 :            : 
+      12                 :            : #pragma pack(1)
+      13                 :            : typedef struct {
+      14                 :            :     spdm_message_header_t header;
+      15                 :            :     uint8_t signature[LIBSPDM_MAX_ASYM_KEY_SIZE];
+      16                 :            :     uint8_t verify_data[LIBSPDM_MAX_HASH_SIZE];
+      17                 :            : } libspdm_finish_request_mine_t;
+      18                 :            : 
+      19                 :            : typedef struct {
+      20                 :            :     spdm_message_header_t header;
+      21                 :            :     uint8_t verify_data[LIBSPDM_MAX_HASH_SIZE];
+      22                 :            : } libspdm_finish_response_mine_t;
+      23                 :            : #pragma pack()
+      24                 :            : 
+      25                 :          9 : bool libspdm_verify_finish_rsp_hmac(libspdm_context_t *spdm_context,
+      26                 :            :                                     libspdm_session_info_t *session_info,
+      27                 :            :                                     const void *hmac_data, size_t hmac_data_size)
+      28                 :            : {
+      29                 :            :     size_t hash_size;
+      30                 :            :     uint8_t calc_hmac_data[LIBSPDM_MAX_HASH_SIZE];
+      31                 :            :     bool result;
+      32                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+      33                 :            :     uint8_t slot_id;
+      34                 :            :     uint8_t *cert_chain_buffer;
+      35                 :            :     size_t cert_chain_buffer_size;
+      36                 :            :     uint8_t *mut_cert_chain_buffer;
+      37                 :            :     size_t mut_cert_chain_buffer_size;
+      38                 :            :     uint8_t *th_curr_data;
+      39                 :            :     size_t th_curr_data_size;
+      40                 :            :     libspdm_th_managed_buffer_t th_curr;
+      41                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+      42                 :            : #endif
+      43                 :            : 
+      44                 :          9 :     hash_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+      45         [ -  + ]:          9 :     LIBSPDM_ASSERT(hash_size == hmac_data_size);
+      46                 :            : 
+      47                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+      48                 :            :     slot_id = spdm_context->connection_info.peer_used_cert_chain_slot_id;
+      49                 :            :     LIBSPDM_ASSERT((slot_id < SPDM_MAX_SLOT_COUNT) || (slot_id == 0xFF));
+      50                 :            :     if (slot_id == 0xFF) {
+      51                 :            :         result = libspdm_get_peer_public_key_buffer(
+      52                 :            :             spdm_context, (const void **)&cert_chain_buffer, &cert_chain_buffer_size);
+      53                 :            :     } else {
+      54                 :            :         result = libspdm_get_peer_cert_chain_buffer(
+      55                 :            :             spdm_context, (const void **)&cert_chain_buffer, &cert_chain_buffer_size);
+      56                 :            :     }
+      57                 :            :     if (!result) {
+      58                 :            :         return false;
+      59                 :            :     }
+      60                 :            : 
+      61                 :            :     if (session_info->mut_auth_requested) {
+      62                 :            :         slot_id = spdm_context->connection_info.local_used_cert_chain_slot_id;
+      63                 :            :         LIBSPDM_ASSERT((slot_id < SPDM_MAX_SLOT_COUNT) || (slot_id == 0xFF));
+      64                 :            :         if (slot_id == 0xFF) {
+      65                 :            :             result = libspdm_get_local_public_key_buffer(
+      66                 :            :                 spdm_context, (const void **)&mut_cert_chain_buffer, &mut_cert_chain_buffer_size);
+      67                 :            :         } else {
+      68                 :            :             result = libspdm_get_local_cert_chain_buffer(
+      69                 :            :                 spdm_context, (const void **)&mut_cert_chain_buffer, &mut_cert_chain_buffer_size);
+      70                 :            :         }
+      71                 :            :         if (!result) {
+      72                 :            :             return false;
+      73                 :            :         }
+      74                 :            :     } else {
+      75                 :            :         mut_cert_chain_buffer = NULL;
+      76                 :            :         mut_cert_chain_buffer_size = 0;
+      77                 :            :     }
+      78                 :            : 
+      79                 :            :     result = libspdm_calculate_th_for_finish(
+      80                 :            :         spdm_context, session_info, cert_chain_buffer,
+      81                 :            :         cert_chain_buffer_size, mut_cert_chain_buffer,
+      82                 :            :         mut_cert_chain_buffer_size, &th_curr);
+      83                 :            :     if (!result) {
+      84                 :            :         return false;
+      85                 :            :     }
+      86                 :            :     th_curr_data = libspdm_get_managed_buffer(&th_curr);
+      87                 :            :     th_curr_data_size = libspdm_get_managed_buffer_size(&th_curr);
+      88                 :            : 
+      89                 :            :     result = libspdm_hash_all (spdm_context->connection_info.algorithm.base_hash_algo,
+      90                 :            :                                th_curr_data, th_curr_data_size, hash_data);
+      91                 :            :     if (!result) {
+      92                 :            :         return false;
+      93                 :            :     }
+      94                 :            : 
+      95                 :            :     result = libspdm_hmac_all_with_response_finished_key(
+      96                 :            :         session_info->secured_message_context, hash_data,
+      97                 :            :         hash_size, calc_hmac_data);
+      98                 :            :     if (!result) {
+      99                 :            :         return false;
+     100                 :            :     }
+     101                 :            : #else
+     102                 :          9 :     result = libspdm_calculate_th_hmac_for_finish_rsp(
+     103                 :            :         spdm_context, session_info, &hash_size, calc_hmac_data);
+     104         [ -  + ]:          9 :     if (!result) {
+     105                 :          0 :         return false;
+     106                 :            :     }
+     107                 :            : #endif
+     108                 :          9 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "th_curr hmac - "));
+     109                 :          9 :     LIBSPDM_INTERNAL_DUMP_DATA(calc_hmac_data, hash_size);
+     110                 :          9 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     111                 :            : 
+     112         [ +  + ]:          9 :     if (!libspdm_consttime_is_mem_equal(calc_hmac_data, hmac_data, hash_size)) {
+     113                 :          2 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "!!! verify_finish_rsp_hmac - FAIL !!!\n"));
+     114                 :          2 :         return false;
+     115                 :            :     }
+     116                 :          7 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "!!! verify_finish_rsp_hmac - PASS !!!\n"));
+     117                 :            : 
+     118                 :          7 :     return true;
+     119                 :            : }
+     120                 :            : 
+     121                 :         37 : bool libspdm_generate_finish_req_hmac(libspdm_context_t *spdm_context,
+     122                 :            :                                       libspdm_session_info_t *session_info,
+     123                 :            :                                       void *hmac)
+     124                 :            : {
+     125                 :            :     size_t hash_size;
+     126                 :            :     uint8_t calc_hmac_data[LIBSPDM_MAX_HASH_SIZE];
+     127                 :            :     bool result;
+     128                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     129                 :            :     uint8_t slot_id;
+     130                 :            :     uint8_t *cert_chain_buffer;
+     131                 :            :     size_t cert_chain_buffer_size;
+     132                 :            :     uint8_t *mut_cert_chain_buffer;
+     133                 :            :     size_t mut_cert_chain_buffer_size;
+     134                 :            :     uint8_t *th_curr_data;
+     135                 :            :     size_t th_curr_data_size;
+     136                 :            :     libspdm_th_managed_buffer_t th_curr;
+     137                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     138                 :            : #endif
+     139                 :            : 
+     140                 :         37 :     hash_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+     141                 :            : 
+     142                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     143                 :            :     slot_id = spdm_context->connection_info.peer_used_cert_chain_slot_id;
+     144                 :            :     LIBSPDM_ASSERT((slot_id < SPDM_MAX_SLOT_COUNT) || (slot_id == 0xFF));
+     145                 :            :     if (slot_id == 0xFF) {
+     146                 :            :         result = libspdm_get_peer_public_key_buffer(
+     147                 :            :             spdm_context, (const void **)&cert_chain_buffer, &cert_chain_buffer_size);
+     148                 :            :     } else {
+     149                 :            :         result = libspdm_get_peer_cert_chain_buffer(
+     150                 :            :             spdm_context, (const void **)&cert_chain_buffer, &cert_chain_buffer_size);
+     151                 :            :     }
+     152                 :            :     if (!result) {
+     153                 :            :         return false;
+     154                 :            :     }
+     155                 :            : 
+     156                 :            :     if (session_info->mut_auth_requested) {
+     157                 :            :         slot_id = spdm_context->connection_info.local_used_cert_chain_slot_id;
+     158                 :            :         LIBSPDM_ASSERT((slot_id < SPDM_MAX_SLOT_COUNT) || (slot_id == 0xFF));
+     159                 :            :         if (slot_id == 0xFF) {
+     160                 :            :             result = libspdm_get_local_public_key_buffer(
+     161                 :            :                 spdm_context, (const void **)&mut_cert_chain_buffer, &mut_cert_chain_buffer_size);
+     162                 :            :         } else {
+     163                 :            :             result = libspdm_get_local_cert_chain_buffer(
+     164                 :            :                 spdm_context, (const void **)&mut_cert_chain_buffer, &mut_cert_chain_buffer_size);
+     165                 :            :         }
+     166                 :            :         if (!result) {
+     167                 :            :             return false;
+     168                 :            :         }
+     169                 :            :     } else {
+     170                 :            :         mut_cert_chain_buffer = NULL;
+     171                 :            :         mut_cert_chain_buffer_size = 0;
+     172                 :            :     }
+     173                 :            : 
+     174                 :            :     result = libspdm_calculate_th_for_finish(
+     175                 :            :         spdm_context, session_info, cert_chain_buffer,
+     176                 :            :         cert_chain_buffer_size, mut_cert_chain_buffer,
+     177                 :            :         mut_cert_chain_buffer_size, &th_curr);
+     178                 :            :     if (!result) {
+     179                 :            :         return false;
+     180                 :            :     }
+     181                 :            :     th_curr_data = libspdm_get_managed_buffer(&th_curr);
+     182                 :            :     th_curr_data_size = libspdm_get_managed_buffer_size(&th_curr);
+     183                 :            : 
+     184                 :            :     result = libspdm_hash_all (spdm_context->connection_info.algorithm.base_hash_algo,
+     185                 :            :                                th_curr_data, th_curr_data_size, hash_data);
+     186                 :            :     if (!result) {
+     187                 :            :         return false;
+     188                 :            :     }
+     189                 :            : 
+     190                 :            :     result = libspdm_hmac_all_with_request_finished_key(
+     191                 :            :         session_info->secured_message_context, hash_data,
+     192                 :            :         hash_size, calc_hmac_data);
+     193                 :            :     if (!result) {
+     194                 :            :         return false;
+     195                 :            :     }
+     196                 :            : #else
+     197                 :         37 :     result = libspdm_calculate_th_hmac_for_finish_req(
+     198                 :            :         spdm_context, session_info, &hash_size, calc_hmac_data);
+     199         [ -  + ]:         37 :     if (!result) {
+     200                 :          0 :         return false;
+     201                 :            :     }
+     202                 :            : #endif
+     203                 :         37 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "th_curr hmac - "));
+     204                 :         37 :     LIBSPDM_INTERNAL_DUMP_DATA(calc_hmac_data, hash_size);
+     205                 :         37 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     206                 :            : 
+     207                 :         37 :     libspdm_copy_mem(hmac, hash_size, calc_hmac_data, hash_size);
+     208                 :            : 
+     209                 :         37 :     return true;
+     210                 :            : }
+     211                 :            : 
+     212                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP
+     213                 :            : 
+     214                 :          5 : bool libspdm_generate_finish_req_signature(libspdm_context_t *spdm_context,
+     215                 :            :                                            libspdm_session_info_t *session_info,
+     216                 :            :                                            uint8_t *signature)
+     217                 :            : {
+     218                 :            :     bool result;
+     219                 :            :     size_t signature_size;
+     220                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     221                 :            :     uint8_t slot_id;
+     222                 :            :     uint8_t *cert_chain_buffer;
+     223                 :            :     size_t cert_chain_buffer_size;
+     224                 :            :     uint8_t *mut_cert_chain_buffer;
+     225                 :            :     size_t mut_cert_chain_buffer_size;
+     226                 :            :     uint8_t *th_curr_data;
+     227                 :            :     size_t th_curr_data_size;
+     228                 :            :     libspdm_th_managed_buffer_t th_curr;
+     229                 :            : #endif
+     230                 :            : #if !(LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT) || (LIBSPDM_DEBUG_PRINT_ENABLE)
+     231                 :            :     size_t hash_size;
+     232                 :            : #endif
+     233                 :            : #if ((LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT) && (LIBSPDM_DEBUG_BLOCK_ENABLE)) || \
+     234                 :            :     !(LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT)
+     235                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     236                 :            : #endif
+     237                 :            : 
+     238                 :         10 :     signature_size = libspdm_get_req_asym_signature_size(
+     239                 :          5 :         spdm_context->connection_info.algorithm.req_base_asym_alg);
+     240                 :            : 
+     241                 :            : #if !(LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT) || (LIBSPDM_DEBUG_PRINT_ENABLE)
+     242                 :          5 :     hash_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+     243                 :            : #endif
+     244                 :            : 
+     245                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     246                 :            :     slot_id = spdm_context->connection_info.peer_used_cert_chain_slot_id;
+     247                 :            :     LIBSPDM_ASSERT((slot_id < SPDM_MAX_SLOT_COUNT) || (slot_id == 0xFF));
+     248                 :            :     if (slot_id == 0xFF) {
+     249                 :            :         result = libspdm_get_peer_public_key_buffer(
+     250                 :            :             spdm_context, (const void **)&cert_chain_buffer, &cert_chain_buffer_size);
+     251                 :            :     } else {
+     252                 :            :         result = libspdm_get_peer_cert_chain_buffer(
+     253                 :            :             spdm_context, (const void **)&cert_chain_buffer, &cert_chain_buffer_size);
+     254                 :            :     }
+     255                 :            :     if (!result) {
+     256                 :            :         return false;
+     257                 :            :     }
+     258                 :            : 
+     259                 :            :     slot_id = spdm_context->connection_info.local_used_cert_chain_slot_id;
+     260                 :            :     LIBSPDM_ASSERT((slot_id < SPDM_MAX_SLOT_COUNT) || (slot_id == 0xFF));
+     261                 :            :     if (slot_id == 0xFF) {
+     262                 :            :         result = libspdm_get_local_public_key_buffer(
+     263                 :            :             spdm_context, (const void **)&mut_cert_chain_buffer, &mut_cert_chain_buffer_size);
+     264                 :            :     } else {
+     265                 :            :         result = libspdm_get_local_cert_chain_buffer(
+     266                 :            :             spdm_context, (const void **)&mut_cert_chain_buffer, &mut_cert_chain_buffer_size);
+     267                 :            :     }
+     268                 :            :     if (!result) {
+     269                 :            :         return false;
+     270                 :            :     }
+     271                 :            : 
+     272                 :            :     result = libspdm_calculate_th_for_finish(
+     273                 :            :         spdm_context, session_info, cert_chain_buffer,
+     274                 :            :         cert_chain_buffer_size, mut_cert_chain_buffer,
+     275                 :            :         mut_cert_chain_buffer_size, &th_curr);
+     276                 :            :     if (!result) {
+     277                 :            :         return false;
+     278                 :            :     }
+     279                 :            :     th_curr_data = libspdm_get_managed_buffer(&th_curr);
+     280                 :            :     th_curr_data_size = libspdm_get_managed_buffer_size(&th_curr);
+     281                 :            : 
+     282                 :            :     /* Debug code only - required for debug print of th_curr below*/
+     283                 :            :     LIBSPDM_DEBUG_CODE(
+     284                 :            :         if (!libspdm_hash_all(
+     285                 :            :                 spdm_context->connection_info.algorithm.base_hash_algo,
+     286                 :            :                 th_curr_data, th_curr_data_size, hash_data)) {
+     287                 :            :         return false;
+     288                 :            :     }
+     289                 :            :         );
+     290                 :            : #else
+     291                 :          5 :     result = libspdm_calculate_th_hash_for_finish(
+     292                 :            :         spdm_context, session_info, &hash_size, hash_data);
+     293         [ -  + ]:          5 :     if (!result) {
+     294                 :          0 :         return false;
+     295                 :            :     }
+     296                 :            : #endif
+     297                 :          5 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "th_curr hash - "));
+     298                 :          5 :     LIBSPDM_INTERNAL_DUMP_DATA(hash_data, hash_size);
+     299                 :          5 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     300                 :            : 
+     301                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     302                 :            :     result = libspdm_requester_data_sign(
+     303                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+     304                 :            :         spdm_context,
+     305                 :            : #endif
+     306                 :            :         spdm_context->connection_info.version, SPDM_FINISH,
+     307                 :            :         spdm_context->connection_info.algorithm.req_base_asym_alg,
+     308                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+     309                 :            :         false, th_curr_data, th_curr_data_size, signature, &signature_size);
+     310                 :            : #else
+     311                 :          5 :     result = libspdm_requester_data_sign(
+     312                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+     313                 :            :         spdm_context,
+     314                 :            : #endif
+     315                 :          5 :         spdm_context->connection_info.version, SPDM_FINISH,
+     316                 :          5 :         spdm_context->connection_info.algorithm.req_base_asym_alg,
+     317                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+     318                 :            :         true, hash_data, hash_size, signature, &signature_size);
+     319                 :            : #endif
+     320         [ +  - ]:          5 :     if (result) {
+     321                 :          5 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "signature - "));
+     322                 :          5 :         LIBSPDM_INTERNAL_DUMP_DATA(signature, signature_size);
+     323                 :          5 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     324                 :            :     }
+     325                 :            : 
+     326                 :          5 :     return result;
+     327                 :            : }
+     328                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP */
+     329                 :            : 
+     330                 :            : /**
+     331                 :            :  * This function sends FINISH and receives FINISH_RSP for SPDM finish.
+     332                 :            :  *
+     333                 :            :  * @param  spdm_context       A pointer to the SPDM context.
+     334                 :            :  * @param  session_id         session_id to the FINISH request.
+     335                 :            :  * @param  req_slot_id_param  req_slot_id_param to the FINISH request.
+     336                 :            :  *
+     337                 :            :  * @retval RETURN_SUCCESS               The FINISH is sent and the FINISH_RSP is received.
+     338                 :            :  * @retval RETURN_DEVICE_ERROR          A device error occurs when communicates with the device.
+     339                 :            :  **/
+     340                 :         41 : static libspdm_return_t libspdm_try_send_receive_finish(libspdm_context_t *spdm_context,
+     341                 :            :                                                         uint32_t session_id,
+     342                 :            :                                                         uint8_t req_slot_id_param)
+     343                 :            : {
+     344                 :            :     libspdm_return_t status;
+     345                 :            :     libspdm_finish_request_mine_t *spdm_request;
+     346                 :            :     size_t spdm_request_size;
+     347                 :            :     size_t signature_size;
+     348                 :            :     size_t hmac_size;
+     349                 :            :     libspdm_finish_response_mine_t *spdm_response;
+     350                 :            :     size_t spdm_response_size;
+     351                 :            :     libspdm_session_info_t *session_info;
+     352                 :            :     uint8_t *ptr;
+     353                 :            :     bool result;
+     354                 :            :     uint8_t th2_hash_data[LIBSPDM_MAX_HASH_SIZE];
+     355                 :            :     libspdm_session_state_t session_state;
+     356                 :            :     uint8_t *message;
+     357                 :            :     size_t message_size;
+     358                 :            :     size_t transport_header_size;
+     359                 :            : 
+     360                 :            :     /* -=[Check Parameters Phase]=- */
+     361         [ -  + ]:         41 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_11) {
+     362                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     363                 :            :     }
+     364                 :            : 
+     365                 :         41 :     session_info = libspdm_get_session_info_via_session_id(spdm_context, session_id);
+     366         [ -  + ]:         41 :     if (session_info == NULL) {
+     367                 :          0 :         status = LIBSPDM_STATUS_INVALID_PARAMETER;
+     368                 :          0 :         goto error;
+     369                 :            :     }
+     370                 :            : 
+     371                 :            :     /* -=[Verify State Phase]=- */
+     372         [ +  + ]:         41 :     if (!libspdm_is_capabilities_flag_supported(
+     373                 :            :             spdm_context, true,
+     374                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP,
+     375                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP)) {
+     376                 :          1 :         status = LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     377                 :          1 :         goto error;
+     378                 :            :     }
+     379                 :            : 
+     380         [ +  + ]:         40 :     if (spdm_context->connection_info.connection_state < LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
+     381                 :          2 :         status = LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+     382                 :          2 :         goto error;
+     383                 :            :     }
+     384                 :            : 
+     385                 :         38 :     session_state = libspdm_secured_message_get_session_state(
+     386                 :            :         session_info->secured_message_context);
+     387         [ +  + ]:         38 :     if (session_state != LIBSPDM_SESSION_STATE_HANDSHAKING) {
+     388                 :          1 :         status = LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+     389                 :          1 :         goto error;
+     390                 :            :     }
+     391         [ +  + ]:         37 :     if (session_info->mut_auth_requested != 0) {
+     392   [ -  +  -  - ]:          5 :         if ((req_slot_id_param >= SPDM_MAX_SLOT_COUNT) && (req_slot_id_param != 0xFF)) {
+     393                 :          0 :             status = LIBSPDM_STATUS_INVALID_PARAMETER;
+     394                 :          0 :             goto error;
+     395                 :            :         }
+     396                 :            :     } else {
+     397         [ -  + ]:         32 :         if (req_slot_id_param != 0) {
+     398                 :          0 :             status = LIBSPDM_STATUS_INVALID_PARAMETER;
+     399                 :          0 :             goto error;
+     400                 :            :         }
+     401                 :            :     }
+     402                 :            : 
+     403                 :            :     /* -=[Construct Request Phase]=- */
+     404                 :         37 :     transport_header_size = spdm_context->local_context.capability.transport_header_size;
+     405                 :         37 :     status = libspdm_acquire_sender_buffer (spdm_context, &message_size, (void **)&message);
+     406         [ -  + ]:         37 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     407                 :          0 :         goto error;
+     408                 :            :     }
+     409         [ -  + ]:         37 :     LIBSPDM_ASSERT (message_size >= transport_header_size +
+     410                 :            :                     spdm_context->local_context.capability.transport_tail_size);
+     411                 :         37 :     spdm_request = (void *)(message + transport_header_size);
+     412                 :         37 :     spdm_request_size = message_size - transport_header_size -
+     413                 :         37 :                         spdm_context->local_context.capability.transport_tail_size;
+     414                 :            : 
+     415         [ -  + ]:         37 :     LIBSPDM_ASSERT(spdm_request_size >= sizeof(spdm_request->header));
+     416                 :         37 :     spdm_request->header.spdm_version = libspdm_get_connection_version (spdm_context);
+     417                 :         37 :     spdm_request->header.request_response_code = SPDM_FINISH;
+     418                 :         37 :     spdm_request->header.param1 = 0;
+     419                 :         37 :     spdm_request->header.param2 = 0;
+     420                 :         37 :     signature_size = 0;
+     421                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP
+     422         [ +  + ]:         37 :     if (session_info->mut_auth_requested) {
+     423                 :          5 :         spdm_request->header.param1 = SPDM_FINISH_REQUEST_ATTRIBUTES_SIGNATURE_INCLUDED;
+     424                 :          5 :         spdm_request->header.param2 = req_slot_id_param;
+     425                 :          5 :         signature_size = libspdm_get_req_asym_signature_size(
+     426                 :          5 :             spdm_context->connection_info.algorithm.req_base_asym_alg);
+     427                 :            :     }
+     428                 :            : #endif
+     429                 :            : 
+     430                 :         37 :     spdm_context->connection_info.local_used_cert_chain_slot_id = req_slot_id_param;
+     431   [ +  +  +  - ]:         37 :     if (session_info->mut_auth_requested && (req_slot_id_param != 0xFF)) {
+     432         [ -  + ]:          5 :         LIBSPDM_ASSERT(req_slot_id_param < SPDM_MAX_SLOT_COUNT);
+     433                 :          5 :         spdm_context->connection_info.local_used_cert_chain_buffer =
+     434                 :          5 :             spdm_context->local_context.local_cert_chain_provision[req_slot_id_param];
+     435                 :          5 :         spdm_context->connection_info.local_used_cert_chain_buffer_size =
+     436                 :          5 :             spdm_context->local_context.local_cert_chain_provision_size[req_slot_id_param];
+     437                 :            :     }
+     438                 :            : 
+     439                 :         37 :     hmac_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+     440         [ -  + ]:         37 :     LIBSPDM_ASSERT (spdm_request_size >= sizeof(spdm_finish_request_t) + signature_size +
+     441                 :            :                     hmac_size);
+     442                 :         37 :     spdm_request_size = sizeof(spdm_finish_request_t) + signature_size + hmac_size;
+     443                 :         37 :     ptr = spdm_request->signature;
+     444                 :            : 
+     445                 :         37 :     status = libspdm_append_message_f(spdm_context, session_info, true, (uint8_t *)spdm_request,
+     446                 :            :                                       sizeof(spdm_finish_request_t));
+     447         [ -  + ]:         37 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     448                 :          0 :         libspdm_release_sender_buffer (spdm_context);
+     449                 :          0 :         goto error;
+     450                 :            :     }
+     451                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP
+     452         [ +  + ]:         37 :     if (session_info->mut_auth_requested) {
+     453                 :          5 :         result = libspdm_generate_finish_req_signature(spdm_context, session_info, ptr);
+     454         [ -  + ]:          5 :         if (!result) {
+     455                 :          0 :             libspdm_release_sender_buffer (spdm_context);
+     456                 :          0 :             status = LIBSPDM_STATUS_CRYPTO_ERROR;
+     457                 :          0 :             goto error;
+     458                 :            :         }
+     459                 :          5 :         status = libspdm_append_message_f(spdm_context, session_info, true, ptr, signature_size);
+     460         [ -  + ]:          5 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     461                 :          0 :             libspdm_release_sender_buffer (spdm_context);
+     462                 :          0 :             goto error;
+     463                 :            :         }
+     464                 :          5 :         ptr += signature_size;
+     465                 :            :     }
+     466                 :            : #endif
+     467                 :            : 
+     468                 :         37 :     result = libspdm_generate_finish_req_hmac(spdm_context, session_info, ptr);
+     469         [ -  + ]:         37 :     if (!result) {
+     470                 :          0 :         libspdm_release_sender_buffer (spdm_context);
+     471                 :          0 :         status = LIBSPDM_STATUS_CRYPTO_ERROR;
+     472                 :          0 :         goto error;
+     473                 :            :     }
+     474                 :            : 
+     475                 :         37 :     status = libspdm_append_message_f(spdm_context, session_info, true, ptr, hmac_size);
+     476         [ -  + ]:         37 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     477                 :          0 :         libspdm_release_sender_buffer (spdm_context);
+     478                 :          0 :         goto error;
+     479                 :            :     }
+     480                 :            : 
+     481                 :            :     /* -=[Send Request Phase]=- */
+     482                 :         37 :     status = libspdm_send_spdm_request(spdm_context, &session_id, spdm_request_size, spdm_request);
+     483         [ +  + ]:         37 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     484                 :          1 :         libspdm_release_sender_buffer (spdm_context);
+     485                 :          1 :         goto error;
+     486                 :            :     }
+     487                 :            : 
+     488                 :         36 :     libspdm_reset_message_buffer_via_request_code(spdm_context, session_info, SPDM_FINISH);
+     489                 :            : 
+     490                 :         36 :     libspdm_release_sender_buffer (spdm_context);
+     491                 :         36 :     spdm_request = (void *)spdm_context->last_spdm_request;
+     492                 :            : 
+     493                 :            :     /* -=[Receive Response Phase]=- */
+     494                 :         36 :     status = libspdm_acquire_receiver_buffer (spdm_context, &message_size, (void **)&message);
+     495         [ -  + ]:         36 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     496                 :          0 :         goto error;
+     497                 :            :     }
+     498         [ -  + ]:         36 :     LIBSPDM_ASSERT (message_size >= transport_header_size);
+     499                 :         36 :     spdm_response = (void *)(message);
+     500                 :         36 :     spdm_response_size = message_size;
+     501                 :            : 
+     502                 :         36 :     status = libspdm_receive_spdm_response(
+     503                 :            :         spdm_context, &session_id, &spdm_response_size, (void **)&spdm_response);
+     504         [ -  + ]:         36 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     505                 :          0 :         goto receive_done;
+     506                 :            :     }
+     507                 :            : 
+     508                 :            :     /* -=[Validate Response Phase]=- */
+     509         [ -  + ]:         36 :     if (spdm_response_size < sizeof(spdm_message_header_t)) {
+     510                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     511                 :          0 :         goto receive_done;
+     512                 :            :     }
+     513         [ -  + ]:         36 :     if (spdm_response->header.spdm_version != spdm_request->header.spdm_version) {
+     514                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     515                 :          0 :         goto receive_done;
+     516                 :            :     }
+     517         [ +  + ]:         36 :     if (spdm_response->header.request_response_code == SPDM_ERROR) {
+     518         [ +  + ]:         25 :         if (spdm_response->header.param1 == SPDM_ERROR_CODE_DECRYPT_ERROR) {
+     519                 :          2 :             status = LIBSPDM_STATUS_SESSION_MSG_ERROR;
+     520                 :          2 :             goto receive_done;
+     521                 :            :         }
+     522         [ +  + ]:         23 :         if (spdm_response->header.param1 != SPDM_ERROR_CODE_RESPONSE_NOT_READY) {
+     523                 :         21 :             libspdm_reset_message_f (spdm_context, session_info);
+     524                 :            :         }
+     525                 :         23 :         status = libspdm_handle_error_response_main(
+     526                 :            :             spdm_context, &session_id,
+     527                 :            :             &spdm_response_size, (void **)&spdm_response,
+     528                 :            :             SPDM_FINISH, SPDM_FINISH_RSP);
+     529         [ +  + ]:         23 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     530                 :         22 :             goto receive_done;
+     531                 :            :         }
+     532         [ +  + ]:         11 :     } else if (spdm_response->header.request_response_code != SPDM_FINISH_RSP) {
+     533                 :          1 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     534                 :          1 :         goto receive_done;
+     535                 :            :     }
+     536                 :            : 
+     537         [ +  + ]:         11 :     if (!libspdm_is_capabilities_flag_supported(
+     538                 :            :             spdm_context, true,
+     539                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP,
+     540                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)) {
+     541                 :          1 :         hmac_size = 0;
+     542                 :            :     }
+     543                 :            : 
+     544         [ +  + ]:         11 :     if (spdm_response_size < sizeof(spdm_finish_response_t) + hmac_size) {
+     545                 :          1 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     546                 :          1 :         goto receive_done;
+     547                 :            :     }
+     548                 :            : 
+     549                 :         10 :     status = libspdm_append_message_f(spdm_context, session_info, true, spdm_response,
+     550                 :            :                                       sizeof(spdm_finish_response_t));
+     551         [ -  + ]:         10 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     552                 :          0 :         goto receive_done;
+     553                 :            :     }
+     554                 :            : 
+     555         [ +  + ]:         10 :     if (libspdm_is_capabilities_flag_supported(
+     556                 :            :             spdm_context, true,
+     557                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP,
+     558                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)) {
+     559                 :          9 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "verify_data (0x%zx):\n", hmac_size));
+     560                 :          9 :         LIBSPDM_INTERNAL_DUMP_HEX(spdm_response->verify_data, hmac_size);
+     561                 :          9 :         result = libspdm_verify_finish_rsp_hmac(spdm_context, session_info,
+     562                 :          9 :                                                 spdm_response->verify_data,
+     563                 :            :                                                 hmac_size);
+     564         [ +  + ]:          9 :         if (!result) {
+     565                 :          2 :             status = LIBSPDM_STATUS_VERIF_FAIL;
+     566                 :          2 :             goto receive_done;
+     567                 :            :         }
+     568                 :            : 
+     569                 :          7 :         status = libspdm_append_message_f(
+     570                 :            :             spdm_context, session_info, true,
+     571                 :          7 :             (uint8_t *)spdm_response +
+     572                 :            :             sizeof(spdm_finish_response_t),
+     573                 :            :             hmac_size);
+     574         [ -  + ]:          7 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     575                 :          0 :             goto receive_done;
+     576                 :            :         }
+     577                 :            :     }
+     578                 :            : 
+     579                 :            :     /* -=[Process Response Phase]=- */
+     580                 :          8 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "libspdm_generate_session_data_key[%x]\n", session_id));
+     581                 :          8 :     result = libspdm_calculate_th2_hash(spdm_context, session_info, true, th2_hash_data);
+     582         [ -  + ]:          8 :     if (!result) {
+     583                 :          0 :         status = LIBSPDM_STATUS_CRYPTO_ERROR;
+     584                 :          0 :         goto receive_done;
+     585                 :            :     }
+     586                 :          8 :     result = libspdm_generate_session_data_key(
+     587                 :            :         session_info->secured_message_context, th2_hash_data);
+     588         [ -  + ]:          8 :     if (!result) {
+     589                 :          0 :         status = LIBSPDM_STATUS_CRYPTO_ERROR;
+     590                 :          0 :         goto receive_done;
+     591                 :            :     }
+     592                 :            : 
+     593                 :            :     /* -=[Update State Phase]=- */
+     594                 :          8 :     libspdm_secured_message_set_session_state(
+     595                 :            :         session_info->secured_message_context, LIBSPDM_SESSION_STATE_ESTABLISHED);
+     596                 :            : 
+     597                 :            :     /* -=[Log Message Phase]=- */
+     598                 :            :     #if LIBSPDM_ENABLE_MSG_LOG
+     599                 :          8 :     libspdm_append_msg_log(spdm_context, spdm_response, spdm_response_size);
+     600                 :            :     #endif /* LIBSPDM_ENABLE_MSG_LOG */
+     601                 :            : 
+     602                 :          8 :     libspdm_release_receiver_buffer (spdm_context);
+     603                 :            : 
+     604                 :          8 :     return LIBSPDM_STATUS_SUCCESS;
+     605                 :            : 
+     606                 :         28 : receive_done:
+     607                 :         28 :     libspdm_release_receiver_buffer (spdm_context);
+     608                 :         33 : error:
+     609         [ +  + ]:         33 :     if (status != LIBSPDM_STATUS_BUSY_PEER) {
+     610                 :         31 :         libspdm_free_session_id(spdm_context, session_id);
+     611                 :            :     }
+     612                 :            : 
+     613                 :         33 :     return status;
+     614                 :            : }
+     615                 :            : 
+     616                 :         40 : libspdm_return_t libspdm_send_receive_finish(libspdm_context_t *spdm_context,
+     617                 :            :                                              uint32_t session_id,
+     618                 :            :                                              uint8_t req_slot_id_param)
+     619                 :            : {
+     620                 :            :     size_t retry;
+     621                 :            :     uint64_t retry_delay_time;
+     622                 :            :     libspdm_return_t status;
+     623                 :            : 
+     624                 :         40 :     spdm_context->crypto_request = true;
+     625                 :         40 :     retry = spdm_context->retry_times;
+     626                 :         40 :     retry_delay_time = spdm_context->retry_delay_time;
+     627                 :            :     do {
+     628                 :         41 :         status = libspdm_try_send_receive_finish(spdm_context, session_id,
+     629                 :            :                                                  req_slot_id_param);
+     630         [ +  + ]:         41 :         if (status != LIBSPDM_STATUS_BUSY_PEER) {
+     631                 :         39 :             return status;
+     632                 :            :         }
+     633                 :            : 
+     634                 :          2 :         libspdm_sleep(retry_delay_time);
+     635         [ +  + ]:          2 :     } while (retry-- != 0);
+     636                 :            : 
+     637                 :          1 :     return status;
+     638                 :            : }
+     639                 :            : 
+     640                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_get_capabilities.c.func-sort-c.html b/coverage_log/library/spdm_requester_lib/libspdm_req_get_capabilities.c.func-sort-c.html new file mode 100644 index 00000000000..ad5e0138602 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_get_capabilities.c.func-sort-c.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_get_capabilities.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_get_capabilities.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:18820392.6 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:14419474.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
validate_responder_capability34
libspdm_get_capabilities66
libspdm_try_get_capabilities67
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_get_capabilities.c.func.html b/coverage_log/library/spdm_requester_lib/libspdm_req_get_capabilities.c.func.html new file mode 100644 index 00000000000..1dce45639f0 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_get_capabilities.c.func.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_get_capabilities.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_get_capabilities.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:18820392.6 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:14419474.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_capabilities66
libspdm_try_get_capabilities67
validate_responder_capability34
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_get_capabilities.c.gcov.html b/coverage_log/library/spdm_requester_lib/libspdm_req_get_capabilities.c.gcov.html new file mode 100644 index 00000000000..52a3793be58 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_get_capabilities.c.gcov.html @@ -0,0 +1,496 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_get_capabilities.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_get_capabilities.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:18820392.6 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:14419474.2 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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                 :            : /**
+      10                 :            :  * This function validates the Responder's capabilities.
+      11                 :            :  *
+      12                 :            :  * @param  capabilities_flag The Responder's CAPABILITIES.Flags field.
+      13                 :            :  * @param  version           The SPDM message version.
+      14                 :            :  *
+      15                 :            :  * @retval true  The field is valid.
+      16                 :            :  * @retval false The field is invalid.
+      17                 :            :  **/
+      18                 :         34 : static bool validate_responder_capability(uint32_t capabilities_flag, uint8_t version)
+      19                 :            : {
+      20                 :            :     /*uint8_t cache_cap = (uint8_t)(capabilities_flag)&0x01;*/
+      21                 :         34 :     const uint8_t cert_cap = (uint8_t)(capabilities_flag >> 1) & 0x01;
+      22                 :         34 :     const uint8_t chal_cap = (uint8_t)(capabilities_flag >> 2) & 0x01;
+      23                 :         34 :     const uint8_t meas_cap = (uint8_t)(capabilities_flag >> 3) & 0x03;
+      24                 :         34 :     const uint8_t meas_fresh_cap = (uint8_t)(capabilities_flag >> 5) & 0x01;
+      25                 :         34 :     const uint8_t encrypt_cap = (uint8_t)(capabilities_flag >> 6) & 0x01;
+      26                 :         34 :     const uint8_t mac_cap = (uint8_t)(capabilities_flag >> 7) & 0x01;
+      27                 :         34 :     const uint8_t mut_auth_cap = (uint8_t)(capabilities_flag >> 8) & 0x01;
+      28                 :         34 :     const uint8_t key_ex_cap = (uint8_t)(capabilities_flag >> 9) & 0x01;
+      29                 :         34 :     const uint8_t psk_cap = (uint8_t)(capabilities_flag >> 10) & 0x03;
+      30                 :         34 :     const uint8_t encap_cap = (uint8_t)(capabilities_flag >> 12) & 0x01;
+      31                 :         34 :     const uint8_t hbeat_cap = (uint8_t)(capabilities_flag >> 13) & 0x01;
+      32                 :         34 :     const uint8_t key_upd_cap = (uint8_t)(capabilities_flag >> 14) & 0x01;
+      33                 :         34 :     const uint8_t handshake_in_the_clear_cap = (uint8_t)(capabilities_flag >> 15) & 0x01;
+      34                 :         34 :     const uint8_t pub_key_id_cap = (uint8_t)(capabilities_flag >> 16) & 0x01;
+      35                 :            :     /* uint8_t chunk_cap = (uint8_t)(capabilities_flag >> 17) & 0x01; */
+      36                 :         34 :     const uint8_t alias_cert_cap = (uint8_t)(capabilities_flag >> 18) & 0x01;
+      37                 :         34 :     const uint8_t set_cert_cap = (uint8_t)(capabilities_flag >> 19) & 0x01;
+      38                 :         34 :     const uint8_t csr_cap = (uint8_t)(capabilities_flag >> 20) & 0x01;
+      39                 :         34 :     const uint8_t cert_install_reset_cap = (uint8_t)(capabilities_flag >> 21) & 0x01;
+      40                 :         34 :     const uint8_t ep_info_cap = (uint8_t)(capabilities_flag >> 22) & 0x03;
+      41                 :            :     /* const uint8_t mel_cap = (uint8_t)(capabilities_flag >> 24) & 0x01; */
+      42                 :         34 :     const uint8_t event_cap = (uint8_t)(capabilities_flag >> 25) & 0x01;
+      43                 :         34 :     const uint8_t multi_key_cap = (uint8_t)(capabilities_flag >> 26) & 0x03;
+      44                 :         34 :     const uint8_t get_key_pair_info_cap = (uint8_t)(capabilities_flag >> 28) & 0x01;
+      45                 :         34 :     const uint8_t set_key_pair_info_cap = (uint8_t)(capabilities_flag >> 29) & 0x01;
+      46                 :            : 
+      47                 :            :     /* Checks common to all SPDM versions. */
+      48                 :            : 
+      49                 :            :     /* Illegal to return reserved value. */
+      50         [ +  + ]:         34 :     if (meas_cap == 3) {
+      51                 :          1 :         return false;
+      52                 :            :     }
+      53                 :            : 
+      54                 :            :     /* If MEAS_FRESH_CAP is set then MEAS_CAP must be set. */
+      55   [ +  +  +  + ]:         33 :     if ((meas_cap == 0) && (meas_fresh_cap == 1)) {
+      56                 :          1 :         return false;
+      57                 :            :     }
+      58                 :            : 
+      59         [ +  + ]:         32 :     if (version == SPDM_MESSAGE_VERSION_10) {
+      60                 :            :         /* If measurements are not signed then CERT_CAP must equal CHAL_CAP.
+      61                 :            :          * If measurements are signed then CERT_CAP must be set. */
+      62   [ +  +  +  + ]:          7 :         if ((meas_cap == 0) || (meas_cap == 1)) {
+      63         [ +  + ]:          5 :             if (cert_cap != chal_cap) {
+      64                 :          1 :                 return false;
+      65                 :            :             }
+      66         [ +  - ]:          2 :         } else if (meas_cap == 2) {
+      67         [ +  + ]:          2 :             if (cert_cap == 0) {
+      68                 :          1 :                 return false;
+      69                 :            :             }
+      70                 :            :         }
+      71                 :          5 :         return true;
+      72                 :            :     }
+      73                 :            : 
+      74                 :            :     /* Checks common to 1.1 and higher. */
+      75         [ +  - ]:         25 :     if (version >= SPDM_MESSAGE_VERSION_11) {
+      76                 :            :         /* Illegal to return reserved values. */
+      77         [ +  + ]:         25 :         if (psk_cap == 3) {
+      78                 :          1 :             return false;
+      79                 :            :         }
+      80                 :            : 
+      81                 :            :         /* Checks that originate from key exchange capabilities. */
+      82   [ +  +  +  + ]:         24 :         if ((key_ex_cap == 1) || (psk_cap != 0)) {
+      83                 :            :             /* While clearing MAC_CAP and setting ENCRYPT_CAP is legal according to DSP0274, libspdm
+      84                 :            :              * also implements DSP0277 secure messages, which requires at least MAC_CAP to be set.
+      85                 :            :              */
+      86         [ +  + ]:         11 :             if (mac_cap == 0) {
+      87                 :          5 :                 return false;
+      88                 :            :             }
+      89                 :            :         } else {
+      90   [ +  +  +  +  :         13 :             if ((mac_cap == 1) || (encrypt_cap == 1) || (handshake_in_the_clear_cap == 1) ||
+             +  -  +  - ]
+      91         [ -  + ]:         10 :                 (hbeat_cap == 1) || (key_upd_cap == 1)) {
+      92                 :          3 :                 return false;
+      93                 :            :             }
+      94         [ -  + ]:         10 :             if (version == SPDM_MESSAGE_VERSION_13) {
+      95         [ #  # ]:          0 :                 if (event_cap == 1) {
+      96                 :          0 :                     return false;
+      97                 :            :                 }
+      98                 :            :             }
+      99                 :            :         }
+     100   [ +  +  +  + ]:         16 :         if ((key_ex_cap == 0) && (psk_cap != 0)) {
+     101         [ +  - ]:          1 :             if (handshake_in_the_clear_cap == 1) {
+     102                 :          1 :                 return false;
+     103                 :            :             }
+     104                 :            :         }
+     105                 :            : 
+     106                 :            :         /* Checks that originate from certificate or public key capabilities. */
+     107   [ +  +  -  + ]:         15 :         if ((cert_cap == 1) || (pub_key_id_cap == 1)) {
+     108                 :            :             /* Certificate capabilities and public key capabilities cannot both be set. */
+     109   [ +  -  +  + ]:         12 :             if ((cert_cap == 1) && (pub_key_id_cap == 1)) {
+     110                 :          1 :                 return false;
+     111                 :            :             }
+     112   [ +  +  +  -  :         11 :             if ((chal_cap == 0) && (key_ex_cap == 0) && ((meas_cap == 0) || (meas_cap == 1))) {
+             -  +  -  - ]
+     113                 :          1 :                 return false;
+     114                 :            :             }
+     115                 :            :         } else {
+     116                 :            :             /* If certificates or public keys are not enabled then these capabilities
+     117                 :            :              * cannot be enabled. */
+     118   [ +  -  +  -  :          3 :             if ((chal_cap == 1) || (key_ex_cap == 1) || (meas_cap == 2) || (mut_auth_cap == 1)) {
+             +  -  -  + ]
+     119                 :          0 :                 return false;
+     120                 :            :             }
+     121         [ -  + ]:          3 :             if (version == SPDM_MESSAGE_VERSION_13) {
+     122         [ #  # ]:          0 :                 if (ep_info_cap == 2) {
+     123                 :          0 :                     return false;
+     124                 :            :                 }
+     125                 :            :             }
+     126                 :            :         }
+     127                 :            : 
+     128                 :            :         /* Checks that originate from mutual authentication capabilities. */
+     129         [ +  + ]:         13 :         if (mut_auth_cap == 1) {
+     130   [ -  +  -  - ]:          4 :             if ((key_ex_cap == 0) && (chal_cap == 0)) {
+     131                 :          0 :                 return false;
+     132                 :            :             }
+     133                 :            :         }
+     134                 :            :     }
+     135                 :            : 
+     136                 :            :     /* Checks specific to 1.1. */
+     137         [ +  + ]:         13 :     if (version == SPDM_MESSAGE_VERSION_11) {
+     138   [ +  -  +  + ]:          3 :         if ((mut_auth_cap == 1) && (encap_cap == 0)) {
+     139                 :          1 :             return false;
+     140                 :            :         }
+     141                 :            :     }
+     142                 :            : 
+     143                 :            :     /* Checks common to 1.2 and higher. */
+     144         [ +  + ]:         12 :     if (version >= SPDM_MESSAGE_VERSION_12) {
+     145   [ +  +  +  +  :         10 :         if ((cert_cap == 0) && ((alias_cert_cap == 1) || (set_cert_cap == 1))) {
+                   -  + ]
+     146                 :          1 :             return false;
+     147                 :            :         }
+     148   [ +  +  +  - ]:          9 :         if ((csr_cap == 1) && (set_cert_cap == 0)) {
+     149                 :          1 :             return false;
+     150                 :            :         }
+     151   [ +  +  +  -  :          8 :         if ((cert_install_reset_cap == 1) && (csr_cap == 0) && (set_cert_cap == 0)) {
+                   +  - ]
+     152                 :          1 :             return false;
+     153                 :            :         }
+     154                 :            :     }
+     155                 :            : 
+     156                 :            :     /* Checks specific to 1.3. */
+     157         [ +  + ]:          9 :     if (version == SPDM_MESSAGE_VERSION_13) {
+     158                 :            :         /* Illegal to return reserved values. */
+     159   [ +  -  -  + ]:          1 :         if ((ep_info_cap == 3) || (multi_key_cap == 3)) {
+     160                 :          0 :             return false;
+     161                 :            :         }
+     162                 :            :         /* check multi-key */
+     163   [ +  -  -  + ]:          1 :         if ((multi_key_cap != 0) && (get_key_pair_info_cap == 0)) {
+     164                 :          0 :             return false;
+     165                 :            :         }
+     166                 :            :         /* check multi-key and pub_key_id */
+     167         [ -  + ]:          1 :         if (pub_key_id_cap == 1) {
+     168   [ #  #  #  #  :          0 :             if ((multi_key_cap != 0) || (get_key_pair_info_cap == 1) ||
+                   #  # ]
+     169                 :            :                 (set_key_pair_info_cap == 1)) {
+     170                 :          0 :                 return false;
+     171                 :            :             }
+     172                 :            :         }
+     173                 :            :     }
+     174                 :            : 
+     175                 :          9 :     return true;
+     176                 :            : }
+     177                 :            : 
+     178                 :            : /**
+     179                 :            :  * This function sends GET_CAPABILITIES and receives CAPABILITIES.
+     180                 :            :  *
+     181                 :            :  * @param  spdm_context A pointer to the SPDM context.
+     182                 :            :  *
+     183                 :            :  * @retval LIBSPDM_STATUS_SUCCESS
+     184                 :            :  *         GET_CAPABILITIES was sent and CAPABILITIES was received.
+     185                 :            :  * @retval LIBSPDM_STATUS_INVALID_STATE_LOCAL
+     186                 :            :  *         Cannot send GET_CAPABILITIES due to Requester's state. Send GET_VERSION first.
+     187                 :            :  * @retval LIBSPDM_STATUS_INVALID_MSG_SIZE
+     188                 :            :  *         The size of the CAPABILITIES response is invalid.
+     189                 :            :  * @retval LIBSPDM_STATUS_INVALID_MSG_FIELD
+     190                 :            :  *         The CAPABILITIES response contains one or more invalid fields.
+     191                 :            :  * @retval LIBSPDM_STATUS_ERROR_PEER
+     192                 :            :  *         The Responder returned an unexpected error.
+     193                 :            :  * @retval LIBSPDM_STATUS_BUSY_PEER
+     194                 :            :  *         The Responder continually returned Busy error messages.
+     195                 :            :  * @retval LIBSPDM_STATUS_RESYNCH_PEER
+     196                 :            :  *         The Responder returned a RequestResynch error message.
+     197                 :            :  * @retval LIBSPDM_STATUS_BUFFER_FULL
+     198                 :            :  *         The buffer used to store transcripts is exhausted.
+     199                 :            :  **/
+     200                 :         67 : static libspdm_return_t libspdm_try_get_capabilities(libspdm_context_t *spdm_context)
+     201                 :            : {
+     202                 :            :     libspdm_return_t status;
+     203                 :            :     spdm_get_capabilities_request_t *spdm_request;
+     204                 :            :     size_t spdm_request_size;
+     205                 :            :     spdm_capabilities_response_t *spdm_response;
+     206                 :            :     size_t spdm_response_size;
+     207                 :            :     uint8_t *message;
+     208                 :            :     size_t message_size;
+     209                 :            :     size_t transport_header_size;
+     210                 :            : 
+     211                 :            :     /* -=[Verify State Phase]=- */
+     212         [ +  + ]:         67 :     if (spdm_context->connection_info.connection_state != LIBSPDM_CONNECTION_STATE_AFTER_VERSION) {
+     213                 :          1 :         return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+     214                 :            :     }
+     215                 :         66 :     libspdm_reset_message_buffer_via_request_code(spdm_context, NULL, SPDM_GET_CAPABILITIES);
+     216                 :            : 
+     217                 :            :     /* -=[Construct Request Phase]=- */
+     218                 :         66 :     transport_header_size = spdm_context->local_context.capability.transport_header_size;
+     219                 :         66 :     status = libspdm_acquire_sender_buffer (spdm_context, &message_size, (void **)&message);
+     220         [ +  + ]:         66 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     221                 :          1 :         return status;
+     222                 :            :     }
+     223         [ -  + ]:         65 :     LIBSPDM_ASSERT (message_size >= transport_header_size +
+     224                 :            :                     spdm_context->local_context.capability.transport_tail_size);
+     225                 :         65 :     spdm_request = (void *)(message + transport_header_size);
+     226                 :         65 :     spdm_request_size = message_size - transport_header_size -
+     227                 :         65 :                         spdm_context->local_context.capability.transport_tail_size;
+     228                 :            : 
+     229         [ -  + ]:         65 :     LIBSPDM_ASSERT (spdm_request_size >= sizeof(spdm_request->header));
+     230                 :         65 :     libspdm_zero_mem(spdm_request, spdm_request_size);
+     231                 :         65 :     spdm_request->header.spdm_version = libspdm_get_connection_version (spdm_context);
+     232         [ +  + ]:         65 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_12) {
+     233         [ -  + ]:         10 :         LIBSPDM_ASSERT (spdm_request_size >= sizeof(spdm_get_capabilities_request_t));
+     234                 :         10 :         spdm_request_size = sizeof(spdm_get_capabilities_request_t);
+     235         [ +  + ]:         55 :     } else if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_11) {
+     236         [ -  + ]:         35 :         LIBSPDM_ASSERT (spdm_request_size >= sizeof(spdm_get_capabilities_request_t) -
+     237                 :            :                         sizeof(spdm_request->data_transfer_size) -
+     238                 :            :                         sizeof(spdm_request->max_spdm_msg_size));
+     239                 :         35 :         spdm_request_size = sizeof(spdm_get_capabilities_request_t) -
+     240                 :            :                             sizeof(spdm_request->data_transfer_size) -
+     241                 :            :                             sizeof(spdm_request->max_spdm_msg_size);
+     242                 :            :     } else {
+     243                 :         20 :         spdm_request_size = sizeof(spdm_request->header);
+     244                 :            :     }
+     245                 :         65 :     spdm_request->header.request_response_code = SPDM_GET_CAPABILITIES;
+     246                 :         65 :     spdm_request->header.param1 = 0;
+     247                 :         65 :     spdm_request->header.param2 = 0;
+     248         [ +  + ]:         65 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_11) {
+     249                 :         45 :         spdm_request->ct_exponent = spdm_context->local_context.capability.ct_exponent;
+     250                 :         45 :         spdm_request->flags =
+     251                 :         45 :             libspdm_mask_capability_flags(spdm_context, true,
+     252                 :            :                                           spdm_context->local_context.capability.flags);
+     253                 :            :     }
+     254         [ +  + ]:         65 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_12) {
+     255                 :         10 :         spdm_request->data_transfer_size =
+     256                 :         10 :             spdm_context->local_context.capability.data_transfer_size;
+     257                 :         10 :         spdm_request->max_spdm_msg_size =
+     258                 :         10 :             spdm_context->local_context.capability.max_spdm_msg_size;
+     259                 :            :     }
+     260                 :            : 
+     261                 :            :     /* -=[Send Request Phase]=- */
+     262                 :         65 :     status = libspdm_send_spdm_request(spdm_context, NULL, spdm_request_size, spdm_request);
+     263         [ +  + ]:         65 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     264                 :          1 :         libspdm_release_sender_buffer (spdm_context);
+     265                 :          1 :         return status;
+     266                 :            :     }
+     267                 :         64 :     libspdm_release_sender_buffer (spdm_context);
+     268                 :         64 :     spdm_request = (void *)spdm_context->last_spdm_request;
+     269                 :            : 
+     270                 :            :     /* -=[Receive Response Phase]=- */
+     271                 :         64 :     status = libspdm_acquire_receiver_buffer (spdm_context, &message_size, (void **)&message);
+     272         [ +  + ]:         64 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     273                 :          1 :         return status;
+     274                 :            :     }
+     275         [ -  + ]:         63 :     LIBSPDM_ASSERT (message_size >= transport_header_size);
+     276                 :         63 :     spdm_response = (void *)(message);
+     277                 :         63 :     spdm_response_size = message_size;
+     278                 :            : 
+     279                 :         63 :     status = libspdm_receive_spdm_response(spdm_context, NULL, &spdm_response_size,
+     280                 :            :                                            (void **)&spdm_response);
+     281         [ +  + ]:         63 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     282                 :          3 :         goto receive_done;
+     283                 :            :     }
+     284                 :            : 
+     285                 :            :     /* -=[Validate Response Phase]=- */
+     286         [ -  + ]:         60 :     if (spdm_response_size < sizeof(spdm_message_header_t)) {
+     287                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     288                 :          0 :         goto receive_done;
+     289                 :            :     }
+     290         [ +  + ]:         60 :     if (spdm_response->header.spdm_version != spdm_request->header.spdm_version) {
+     291                 :          1 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     292                 :          1 :         goto receive_done;
+     293                 :            :     }
+     294         [ +  + ]:         59 :     if (spdm_response->header.request_response_code == SPDM_ERROR) {
+     295                 :         23 :         status = libspdm_handle_simple_error_response(
+     296                 :         23 :             spdm_context, spdm_response->header.param1);
+     297         [ +  - ]:         23 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     298                 :         23 :             goto receive_done;
+     299                 :            :         }
+     300         [ +  + ]:         36 :     } else if (spdm_response->header.request_response_code != SPDM_CAPABILITIES) {
+     301                 :          1 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     302                 :          1 :         goto receive_done;
+     303                 :            :     }
+     304         [ +  + ]:         35 :     if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_12) {
+     305         [ -  + ]:         10 :         if (spdm_response_size < sizeof(spdm_capabilities_response_t)) {
+     306                 :          0 :             status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     307                 :          0 :             goto receive_done;
+     308                 :            :         }
+     309                 :            :     } else {
+     310         [ +  + ]:         25 :         if (spdm_response_size < sizeof(spdm_capabilities_response_t) -
+     311                 :            :             sizeof(spdm_response->data_transfer_size) - sizeof(spdm_response->max_spdm_msg_size)) {
+     312                 :          1 :             status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     313                 :          1 :             goto receive_done;
+     314                 :            :         }
+     315                 :            :     }
+     316         [ +  + ]:         34 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_12) {
+     317                 :         10 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     318                 :            :     } else {
+     319                 :         24 :         spdm_response_size = sizeof(spdm_capabilities_response_t) -
+     320                 :            :                              sizeof(spdm_response->data_transfer_size) -
+     321                 :            :                              sizeof(spdm_response->max_spdm_msg_size);
+     322                 :            :     }
+     323                 :            : 
+     324         [ +  + ]:         34 :     if (!validate_responder_capability(spdm_response->flags, spdm_response->header.spdm_version)) {
+     325                 :         20 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     326                 :         20 :         goto receive_done;
+     327                 :            :     }
+     328         [ +  + ]:         14 :     if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_12) {
+     329         [ +  + ]:          7 :         if ((spdm_response->data_transfer_size < SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12) ||
+     330         [ +  + ]:          6 :             (spdm_response->data_transfer_size > spdm_response->max_spdm_msg_size)) {
+     331                 :          2 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     332                 :          2 :             goto receive_done;
+     333                 :            :         }
+     334                 :            : 
+     335         [ +  + ]:          5 :         if (((spdm_response->flags & SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP) == 0) &&
+     336         [ +  + ]:          2 :             (spdm_response->data_transfer_size != spdm_response->max_spdm_msg_size)) {
+     337                 :          1 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     338                 :          1 :             goto receive_done;
+     339                 :            :         }
+     340                 :            :     }
+     341                 :            : 
+     342         [ +  + ]:         11 :     if (spdm_response->ct_exponent > LIBSPDM_MAX_CT_EXPONENT) {
+     343                 :          1 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     344                 :          1 :         goto receive_done;
+     345                 :            :     }
+     346                 :            : 
+     347                 :            :     /* -=[Process Response Phase]=- */
+     348                 :         10 :     status = libspdm_append_message_a(spdm_context, spdm_request, spdm_request_size);
+     349         [ +  + ]:         10 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     350                 :          1 :         goto receive_done;
+     351                 :            :     }
+     352                 :            : 
+     353                 :          9 :     status = libspdm_append_message_a(spdm_context, spdm_response, spdm_response_size);
+     354         [ -  + ]:          9 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     355                 :          0 :         goto receive_done;
+     356                 :            :     }
+     357                 :            : 
+     358                 :          9 :     spdm_context->connection_info.capability.ct_exponent = spdm_response->ct_exponent;
+     359                 :          9 :     spdm_context->connection_info.capability.flags =
+     360                 :          9 :         libspdm_mask_capability_flags(spdm_context, false, spdm_response->flags);
+     361                 :            : 
+     362         [ +  + ]:          9 :     if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_12) {
+     363                 :          2 :         spdm_context->connection_info.capability.data_transfer_size =
+     364                 :          2 :             spdm_response->data_transfer_size;
+     365                 :          2 :         spdm_context->connection_info.capability.max_spdm_msg_size =
+     366                 :          2 :             spdm_response->max_spdm_msg_size;
+     367                 :            :     } else {
+     368                 :          7 :         spdm_context->connection_info.capability.data_transfer_size = 0;
+     369                 :          7 :         spdm_context->connection_info.capability.max_spdm_msg_size = 0;
+     370                 :            :     }
+     371                 :            : 
+     372                 :            :     /* -=[Update State Phase]=- */
+     373                 :          9 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+     374                 :          9 :     status = LIBSPDM_STATUS_SUCCESS;
+     375                 :            : 
+     376                 :            :     /* -=[Log Message Phase]=- */
+     377                 :            :     #if LIBSPDM_ENABLE_MSG_LOG
+     378                 :          9 :     libspdm_append_msg_log(spdm_context, spdm_response, spdm_response_size);
+     379                 :            :     #endif /* LIBSPDM_ENABLE_MSG_LOG */
+     380                 :            : 
+     381                 :         63 : receive_done:
+     382                 :         63 :     libspdm_release_receiver_buffer (spdm_context);
+     383                 :         63 :     return status;
+     384                 :            : }
+     385                 :            : 
+     386                 :         66 : libspdm_return_t libspdm_get_capabilities(libspdm_context_t *spdm_context)
+     387                 :            : {
+     388                 :            :     size_t retry;
+     389                 :            :     uint64_t retry_delay_time;
+     390                 :            :     libspdm_return_t status;
+     391                 :            : 
+     392                 :         66 :     spdm_context->crypto_request = false;
+     393                 :         66 :     retry = spdm_context->retry_times;
+     394                 :         66 :     retry_delay_time = spdm_context->retry_delay_time;
+     395                 :            :     do {
+     396                 :         67 :         status = libspdm_try_get_capabilities(spdm_context);
+     397         [ +  + ]:         67 :         if (status != LIBSPDM_STATUS_BUSY_PEER) {
+     398                 :         65 :             return status;
+     399                 :            :         }
+     400                 :            : 
+     401                 :          2 :         libspdm_sleep(retry_delay_time);
+     402         [ +  + ]:          2 :     } while (retry-- != 0);
+     403                 :            : 
+     404                 :          1 :     return status;
+     405                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_get_certificate.c.func-sort-c.html b/coverage_log/library/spdm_requester_lib/libspdm_req_get_certificate.c.func-sort-c.html new file mode 100644 index 00000000000..43a2c1786da --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_get_certificate.c.func-sort-c.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_get_certificate.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_get_certificate.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:16422871.9 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:8612668.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_certificate_choose_length_ex1
libspdm_get_certificate_ex1
libspdm_get_certificate53
libspdm_get_certificate_choose_length54
libspdm_try_get_certificate56
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_get_certificate.c.func.html b/coverage_log/library/spdm_requester_lib/libspdm_req_get_certificate.c.func.html new file mode 100644 index 00000000000..ead27511464 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_get_certificate.c.func.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_get_certificate.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_get_certificate.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:16422871.9 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:8612668.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_certificate53
libspdm_get_certificate_choose_length54
libspdm_get_certificate_choose_length_ex1
libspdm_get_certificate_ex1
libspdm_try_get_certificate56
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_get_certificate.c.gcov.html b/coverage_log/library/spdm_requester_lib/libspdm_req_get_certificate.c.gcov.html new file mode 100644 index 00000000000..7ca7647506e --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_get_certificate.c.gcov.html @@ -0,0 +1,589 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_get_certificate.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_get_certificate.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:16422871.9 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:8612668.3 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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_SEND_GET_CERTIFICATE_SUPPORT
+      10                 :            : 
+      11                 :            : #pragma pack(1)
+      12                 :            : typedef struct {
+      13                 :            :     spdm_message_header_t header;
+      14                 :            :     uint16_t portion_length;
+      15                 :            :     uint16_t remainder_length;
+      16                 :            :     uint8_t cert_chain[LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN];
+      17                 :            : } libspdm_certificate_response_max_t;
+      18                 :            : #pragma pack()
+      19                 :            : 
+      20                 :            : /**
+      21                 :            :  * This function sends GET_CERTIFICATE and receives CERTIFICATE.
+      22                 :            :  *
+      23                 :            :  * This function verify the integrity of the certificate chain.
+      24                 :            :  * root_hash -> Root certificate -> Intermediate certificate -> Leaf certificate.
+      25                 :            :  *
+      26                 :            :  * If the peer root certificate hash is deployed,
+      27                 :            :  * this function also verifies the digest with the root hash in the certificate chain.
+      28                 :            :  *
+      29                 :            :  * @param  spdm_context      A pointer to the SPDM context.
+      30                 :            :  * @param  slot_id           The number of slot for the certificate chain.
+      31                 :            :  * @param  cert_chain_size   On input, indicate the size in bytes of the destination buffer to store
+      32                 :            :  *                           the digest buffer.
+      33                 :            :  *                           On output, indicate the size in bytes of the certificate chain.
+      34                 :            :  * @param  cert_chain        A pointer to a destination buffer to store the certificate chain.
+      35                 :            :  * @param  trust_anchor      A buffer to hold the trust_anchor which is used to validate the peer
+      36                 :            :  *                           certificate, if not NULL.
+      37                 :            :  * @param  trust_anchor_size A buffer to hold the trust_anchor_size, if not NULL.
+      38                 :            :  *
+      39                 :            :  * @retval LIBSPDM_STATUS_SUCCESS
+      40                 :            :  *         GET_CERTIFICATE was sent and CERTIFICATE was received.
+      41                 :            :  * @retval LIBSPDM_STATUS_INVALID_STATE_LOCAL
+      42                 :            :  *         Cannot send GET_CERTIFICATE due to Requester's state.
+      43                 :            :  * @retval LIBSPDM_STATUS_UNSUPPORTED_CAP
+      44                 :            :  *         Cannot send GET_CERTIFICATE because the Requester's and/or Responder's CERT_CAP = 0.
+      45                 :            :  * @retval LIBSPDM_STATUS_INVALID_MSG_SIZE
+      46                 :            :  *         The size of the CERTIFICATE response is invalid.
+      47                 :            :  * @retval LIBSPDM_STATUS_INVALID_MSG_FIELD
+      48                 :            :  *         The CERTIFICATE response contains one or more invalid fields.
+      49                 :            :  * @retval LIBSPDM_STATUS_ERROR_PEER
+      50                 :            :  *         The Responder returned an unexpected error.
+      51                 :            :  * @retval LIBSPDM_STATUS_BUSY_PEER
+      52                 :            :  *         The Responder continually returned Busy error messages.
+      53                 :            :  * @retval LIBSPDM_STATUS_RESYNCH_PEER
+      54                 :            :  *         The Responder returned a RequestResynch error message.
+      55                 :            :  * @retval LIBSPDM_STATUS_BUFFER_FULL
+      56                 :            :  *         The buffer used to store transcripts is exhausted.
+      57                 :            :  * @retval LIBSPDM_STATUS_VERIF_FAIL
+      58                 :            :  *         Verification of the certificate chain failed.
+      59                 :            :  * @retval LIBSPDM_STATUS_INVALID_CERT
+      60                 :            :  *         The certificate is unable to be parsed or contains invalid field values.
+      61                 :            :  * @retval LIBSPDM_STATUS_CRYPTO_ERROR
+      62                 :            :  *         A generic cryptography error occurred.
+      63                 :            :  **/
+      64                 :         56 : static libspdm_return_t libspdm_try_get_certificate(libspdm_context_t *spdm_context,
+      65                 :            :                                                     const uint32_t *session_id,
+      66                 :            :                                                     uint8_t slot_id,
+      67                 :            :                                                     uint16_t length,
+      68                 :            :                                                     size_t *cert_chain_size,
+      69                 :            :                                                     void *cert_chain,
+      70                 :            :                                                     const void **trust_anchor,
+      71                 :            :                                                     size_t *trust_anchor_size)
+      72                 :            : {
+      73                 :            :     bool result;
+      74                 :            :     libspdm_return_t status;
+      75                 :            :     spdm_get_certificate_request_t *spdm_request;
+      76                 :            :     size_t spdm_request_size;
+      77                 :            :     libspdm_certificate_response_max_t *spdm_response;
+      78                 :            :     size_t spdm_response_size;
+      79                 :            :     uint16_t total_responder_cert_chain_buffer_length;
+      80                 :            :     size_t cert_chain_capacity;
+      81                 :            :     size_t cert_chain_size_internal;
+      82                 :            :     uint16_t remainder_length;
+      83                 :            :     uint8_t *message;
+      84                 :            :     size_t message_size;
+      85                 :            :     size_t transport_header_size;
+      86                 :            :     libspdm_session_info_t *session_info;
+      87                 :            :     libspdm_session_state_t session_state;
+      88                 :            :     bool chunk_enabled;
+      89                 :            :     uint8_t cert_model;
+      90                 :            : 
+      91                 :            :     /* -=[Check Parameters Phase]=- */
+      92         [ -  + ]:         56 :     LIBSPDM_ASSERT(slot_id < SPDM_MAX_SLOT_COUNT);
+      93         [ -  + ]:         56 :     LIBSPDM_ASSERT(cert_chain_size != NULL);
+      94         [ -  + ]:         56 :     LIBSPDM_ASSERT(*cert_chain_size > 0);
+      95         [ -  + ]:         56 :     LIBSPDM_ASSERT(cert_chain != NULL);
+      96                 :            : 
+      97                 :            :     /* -=[Verify State Phase]=- */
+      98         [ -  + ]:         56 :     if (!libspdm_is_capabilities_flag_supported(
+      99                 :            :             spdm_context, true, 0,
+     100                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP)) {
+     101                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     102                 :            :     }
+     103         [ +  + ]:         56 :     if (spdm_context->connection_info.connection_state < LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
+     104                 :          1 :         return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+     105                 :            :     }
+     106                 :            : 
+     107                 :         55 :     session_info = NULL;
+     108         [ +  + ]:         55 :     if (session_id != NULL) {
+     109                 :          1 :         session_info = libspdm_get_session_info_via_session_id(spdm_context, *session_id);
+     110         [ -  + ]:          1 :         if (session_info == NULL) {
+     111                 :          0 :             LIBSPDM_ASSERT(false);
+     112                 :          0 :             return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+     113                 :            :         }
+     114                 :          1 :         session_state = libspdm_secured_message_get_session_state(
+     115                 :            :             session_info->secured_message_context);
+     116         [ -  + ]:          1 :         if (session_state != LIBSPDM_SESSION_STATE_ESTABLISHED) {
+     117                 :          0 :             return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+     118                 :            :         }
+     119                 :            :     }
+     120                 :            : 
+     121                 :         55 :     libspdm_reset_message_buffer_via_request_code(spdm_context, session_info, SPDM_GET_CERTIFICATE);
+     122                 :            : 
+     123                 :            :     chunk_enabled =
+     124                 :         55 :         libspdm_is_capabilities_flag_supported(spdm_context, true,
+     125                 :            :                                                SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP,
+     126                 :            :                                                SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP);
+     127                 :            : 
+     128                 :         55 :     remainder_length = 0;
+     129                 :         55 :     total_responder_cert_chain_buffer_length = 0;
+     130                 :         55 :     cert_chain_capacity = *cert_chain_size;
+     131                 :         55 :     cert_chain_size_internal = 0;
+     132                 :            : 
+     133                 :         55 :     transport_header_size = spdm_context->local_context.capability.transport_header_size;
+     134                 :            : 
+     135                 :            :     do {
+     136                 :            :         /* -=[Construct Request Phase]=- */
+     137                 :       1468 :         status = libspdm_acquire_sender_buffer (spdm_context, &message_size, (void **)&message);
+     138         [ -  + ]:       1468 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     139                 :          0 :             return status;
+     140                 :            :         }
+     141         [ -  + ]:       1468 :         LIBSPDM_ASSERT (message_size >= transport_header_size +
+     142                 :            :                         spdm_context->local_context.capability.transport_tail_size);
+     143                 :       1468 :         spdm_request = (void *)(message + transport_header_size);
+     144                 :       1468 :         spdm_request_size = message_size - transport_header_size -
+     145                 :       1468 :                             spdm_context->local_context.capability.transport_tail_size;
+     146                 :            : 
+     147         [ -  + ]:       1468 :         LIBSPDM_ASSERT (spdm_request_size >= sizeof(spdm_get_certificate_request_t));
+     148                 :       1468 :         spdm_request->header.spdm_version = libspdm_get_connection_version (spdm_context);
+     149                 :       1468 :         spdm_request->header.request_response_code = SPDM_GET_CERTIFICATE;
+     150                 :       1468 :         spdm_request->header.param1 = slot_id;
+     151                 :       1468 :         spdm_request->header.param2 = 0;
+     152                 :       1468 :         spdm_request->offset = (uint16_t)cert_chain_size_internal;
+     153         [ +  + ]:       1468 :         if (spdm_request->offset == 0) {
+     154                 :         55 :             spdm_request->length = length;
+     155                 :            :         } else {
+     156                 :       1413 :             spdm_request->length = LIBSPDM_MIN(length, remainder_length);
+     157                 :            :         }
+     158                 :       1468 :         spdm_request_size = sizeof(spdm_get_certificate_request_t);
+     159                 :       1468 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "request (offset 0x%x, size 0x%x):\n",
+     160                 :            :                        spdm_request->offset, spdm_request->length));
+     161                 :            : 
+     162                 :            :         /* -=[Send Request Phase]=- */
+     163                 :            :         status =
+     164                 :       1468 :             libspdm_send_spdm_request(spdm_context, session_id, spdm_request_size, spdm_request);
+     165         [ +  + ]:       1468 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     166                 :          1 :             libspdm_release_sender_buffer (spdm_context);
+     167                 :          1 :             status = LIBSPDM_STATUS_SEND_FAIL;
+     168                 :          1 :             goto done;
+     169                 :            :         }
+     170                 :       1467 :         libspdm_release_sender_buffer (spdm_context);
+     171                 :       1467 :         spdm_request = (void *)spdm_context->last_spdm_request;
+     172                 :            : 
+     173                 :            :         /* -=[Receive Response Phase]=- */
+     174                 :       1467 :         status = libspdm_acquire_receiver_buffer (spdm_context, &message_size, (void **)&message);
+     175         [ -  + ]:       1467 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     176                 :          0 :             return status;
+     177                 :            :         }
+     178         [ -  + ]:       1467 :         LIBSPDM_ASSERT (message_size >= transport_header_size);
+     179                 :       1467 :         spdm_response = (void *)(message);
+     180                 :       1467 :         spdm_response_size = message_size;
+     181                 :            : 
+     182                 :       1467 :         status = libspdm_receive_spdm_response(spdm_context, session_id,
+     183                 :            :                                                &spdm_response_size,
+     184                 :            :                                                (void **)&spdm_response);
+     185         [ -  + ]:       1467 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     186                 :          0 :             libspdm_release_receiver_buffer (spdm_context);
+     187                 :          0 :             status = LIBSPDM_STATUS_RECEIVE_FAIL;
+     188                 :          0 :             goto done;
+     189                 :            :         }
+     190                 :            : 
+     191                 :            :         /* -=[Validate Response Phase]=- */
+     192         [ -  + ]:       1467 :         if (spdm_response_size < sizeof(spdm_message_header_t)) {
+     193                 :          0 :             libspdm_release_receiver_buffer (spdm_context);
+     194                 :          0 :             status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     195                 :          0 :             goto done;
+     196                 :            :         }
+     197         [ -  + ]:       1467 :         if (spdm_response->header.spdm_version != spdm_request->header.spdm_version) {
+     198                 :          0 :             libspdm_release_receiver_buffer (spdm_context);
+     199                 :          0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     200                 :          0 :             goto done;
+     201                 :            :         }
+     202         [ +  + ]:       1467 :         if (spdm_response->header.request_response_code == SPDM_ERROR) {
+     203                 :         24 :             status = libspdm_handle_error_response_main(
+     204                 :            :                 spdm_context, session_id,
+     205                 :            :                 &spdm_response_size,
+     206                 :            :                 (void **)&spdm_response, SPDM_GET_CERTIFICATE,
+     207                 :            :                 SPDM_CERTIFICATE);
+     208         [ +  + ]:         24 :             if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     209                 :         23 :                 libspdm_release_receiver_buffer (spdm_context);
+     210                 :         23 :                 goto done;
+     211                 :            :             }
+     212         [ -  + ]:       1443 :         } else if (spdm_response->header.request_response_code != SPDM_CERTIFICATE) {
+     213                 :          0 :             libspdm_release_receiver_buffer (spdm_context);
+     214                 :          0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     215                 :          0 :             goto done;
+     216                 :            :         }
+     217         [ -  + ]:       1444 :         if (spdm_response_size < sizeof(spdm_certificate_response_t)) {
+     218                 :          0 :             libspdm_release_receiver_buffer (spdm_context);
+     219                 :          0 :             status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     220                 :          0 :             goto done;
+     221                 :            :         }
+     222         [ +  + ]:       1444 :         if ((spdm_response->portion_length > spdm_request->length) ||
+     223         [ +  + ]:       1442 :             (spdm_response->portion_length == 0)) {
+     224                 :          3 :             libspdm_release_receiver_buffer (spdm_context);
+     225                 :          3 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     226                 :          3 :             goto done;
+     227                 :            :         }
+     228         [ +  + ]:       1441 :         if ((spdm_response->header.param1 & SPDM_CERTIFICATE_RESPONSE_SLOT_ID_MASK) != slot_id) {
+     229                 :          1 :             libspdm_release_receiver_buffer (spdm_context);
+     230                 :          1 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     231                 :          1 :             goto done;
+     232                 :            :         }
+     233         [ +  + ]:       1440 :         if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
+     234                 :         10 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "cert_info - 0x%02x\n",
+     235                 :            :                            spdm_response->header.param2));
+     236                 :         10 :             cert_model = spdm_response->header.param2 &
+     237                 :            :                          SPDM_CERTIFICATE_RESPONSE_ATTRIBUTES_CERTIFICATE_INFO_MASK;
+     238         [ +  + ]:         10 :             if (spdm_context->connection_info.multi_key_conn_rsp) {
+     239         [ -  + ]:          8 :                 if (cert_model > SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT) {
+     240                 :          0 :                     libspdm_release_receiver_buffer (spdm_context);
+     241                 :          0 :                     status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     242                 :          0 :                     goto done;
+     243                 :            :                 }
+     244   [ +  +  +  + ]:          8 :                 if ((slot_id == 0) &&
+     245                 :            :                     (cert_model == SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT)) {
+     246                 :          1 :                     libspdm_release_receiver_buffer (spdm_context);
+     247                 :          1 :                     status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     248                 :          1 :                     goto done;
+     249                 :            :                 }
+     250         [ +  + ]:          7 :                 if ((cert_model == SPDM_CERTIFICATE_INFO_CERT_MODEL_NONE) &&
+     251         [ +  - ]:          1 :                     (spdm_response->portion_length != 0)) {
+     252                 :          1 :                     libspdm_release_receiver_buffer (spdm_context);
+     253                 :          1 :                     status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     254                 :          1 :                     goto done;
+     255                 :            :                 }
+     256                 :            :             } else {
+     257         [ -  + ]:          2 :                 if (cert_model != SPDM_CERTIFICATE_INFO_CERT_MODEL_NONE) {
+     258                 :          0 :                     libspdm_release_receiver_buffer (spdm_context);
+     259                 :          0 :                     status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     260                 :          0 :                     goto done;
+     261                 :            :                 }
+     262                 :            :             }
+     263         [ +  + ]:          8 :             if (spdm_context->connection_info.peer_cert_info[slot_id] ==
+     264                 :            :                 SPDM_CERTIFICATE_INFO_CERT_MODEL_NONE) {
+     265                 :          5 :                 spdm_context->connection_info.peer_cert_info[slot_id] = cert_model;
+     266         [ -  + ]:          3 :             } else if (spdm_context->connection_info.peer_cert_info[slot_id] != cert_model) {
+     267                 :          0 :                 libspdm_release_receiver_buffer (spdm_context);
+     268                 :          0 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     269                 :          0 :                 goto done;
+     270                 :            :             }
+     271                 :            :         }
+     272                 :       1438 :         if (spdm_response_size < sizeof(spdm_certificate_response_t) +
+     273         [ -  + ]:       1438 :             spdm_response->portion_length) {
+     274                 :          0 :             libspdm_release_receiver_buffer (spdm_context);
+     275                 :          0 :             status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     276                 :          0 :             goto done;
+     277                 :            :         }
+     278         [ -  + ]:       1438 :         if (spdm_response->portion_length > 0xFFFF - spdm_request->offset) {
+     279                 :          0 :             libspdm_release_receiver_buffer (spdm_context);
+     280                 :          0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     281                 :          0 :             goto done;
+     282                 :            :         }
+     283                 :       1438 :         if (spdm_response->remainder_length > 0xFFFF - spdm_request->offset -
+     284         [ -  + ]:       1438 :             spdm_response->portion_length) {
+     285                 :          0 :             libspdm_release_receiver_buffer (spdm_context);
+     286                 :          0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     287                 :          0 :             goto done;
+     288                 :            :         }
+     289         [ +  + ]:       1438 :         if (spdm_request->offset == 0) {
+     290                 :         26 :             total_responder_cert_chain_buffer_length = spdm_response->portion_length +
+     291                 :         26 :                                                        spdm_response->remainder_length;
+     292                 :       1412 :         } else if (spdm_request->offset + spdm_response->portion_length +
+     293         [ -  + ]:       1412 :                    spdm_response->remainder_length != total_responder_cert_chain_buffer_length) {
+     294                 :          0 :             libspdm_release_receiver_buffer (spdm_context);
+     295                 :          0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     296                 :          0 :             goto done;
+     297                 :            :         }
+     298   [ +  +  +  +  :       1438 :         if (chunk_enabled && (spdm_request->offset == 0) && (spdm_request->length == 0xFFFF) &&
+                   -  + ]
+     299         [ #  # ]:          0 :             (spdm_response->remainder_length != 0)) {
+     300                 :          0 :             libspdm_release_receiver_buffer (spdm_context);
+     301                 :          0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     302                 :          0 :             goto done;
+     303                 :            :         }
+     304                 :            : 
+     305                 :            :         /* -=[Process Response Phase]=- */
+     306                 :       1438 :         remainder_length = spdm_response->remainder_length;
+     307                 :       1438 :         spdm_response_size = sizeof(spdm_certificate_response_t) + spdm_response->portion_length;
+     308                 :            : 
+     309         [ +  + ]:       1438 :         if (session_id == NULL) {
+     310                 :       1436 :             status = libspdm_append_message_b(spdm_context, spdm_request, spdm_request_size);
+     311         [ -  + ]:       1436 :             if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     312                 :          0 :                 libspdm_release_receiver_buffer (spdm_context);
+     313                 :          0 :                 goto done;
+     314                 :            :             }
+     315                 :       1436 :             status = libspdm_append_message_b(spdm_context, spdm_response, spdm_response_size);
+     316         [ -  + ]:       1436 :             if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     317                 :          0 :                 libspdm_release_receiver_buffer (spdm_context);
+     318                 :          0 :                 goto done;
+     319                 :            :             }
+     320                 :            :         }
+     321                 :            : 
+     322         [ -  + ]:       1438 :         if (cert_chain_size_internal + spdm_response->portion_length > cert_chain_capacity) {
+     323                 :          0 :             libspdm_release_receiver_buffer (spdm_context);
+     324                 :          0 :             status = LIBSPDM_STATUS_BUFFER_FULL;
+     325                 :          0 :             goto done;
+     326                 :            :         }
+     327                 :            : 
+     328                 :       1438 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "Certificate (offset 0x%x, size 0x%x):\n",
+     329                 :            :                        spdm_request->offset, spdm_response->portion_length));
+     330                 :       1438 :         LIBSPDM_INTERNAL_DUMP_HEX(spdm_response->cert_chain, spdm_response->portion_length);
+     331                 :            : 
+     332                 :       1438 :         libspdm_copy_mem((uint8_t *)cert_chain + cert_chain_size_internal,
+     333                 :            :                          cert_chain_capacity - cert_chain_size_internal,
+     334                 :       1438 :                          spdm_response->cert_chain,
+     335                 :       1438 :                          spdm_response->portion_length);
+     336                 :            : 
+     337                 :       1438 :         cert_chain_size_internal += spdm_response->portion_length;
+     338                 :            : 
+     339         [ +  + ]:       1438 :         if (spdm_context->connection_info.connection_state <
+     340                 :            :             LIBSPDM_CONNECTION_STATE_AFTER_CERTIFICATE) {
+     341                 :         22 :             spdm_context->connection_info.connection_state =
+     342                 :            :                 LIBSPDM_CONNECTION_STATE_AFTER_CERTIFICATE;
+     343                 :            :         }
+     344                 :            : 
+     345                 :            :         /* -=[Log Message Phase]=- */
+     346                 :            :         #if LIBSPDM_ENABLE_MSG_LOG
+     347                 :       1438 :         libspdm_append_msg_log(spdm_context, spdm_response, spdm_response_size);
+     348                 :            :         #endif /* LIBSPDM_ENABLE_MSG_LOG */
+     349                 :            : 
+     350                 :       1438 :         libspdm_release_receiver_buffer (spdm_context);
+     351         [ +  + ]:       1438 :     } while (remainder_length != 0);
+     352                 :            : 
+     353                 :         25 :     *cert_chain_size = cert_chain_size_internal;
+     354         [ -  + ]:         25 :     LIBSPDM_ASSERT(*cert_chain_size <= SPDM_MAX_CERTIFICATE_CHAIN_SIZE);
+     355                 :            : 
+     356         [ -  + ]:         25 :     if (spdm_context->local_context.verify_peer_spdm_cert_chain != NULL) {
+     357                 :          0 :         result = spdm_context->local_context.verify_peer_spdm_cert_chain (
+     358                 :            :             spdm_context, slot_id, cert_chain_size_internal, cert_chain,
+     359                 :            :             trust_anchor, trust_anchor_size);
+     360         [ #  # ]:          0 :         if (!result) {
+     361                 :          0 :             status = LIBSPDM_STATUS_VERIF_FAIL;
+     362                 :          0 :             goto done;
+     363                 :            :         }
+     364                 :            :     } else {
+     365                 :         25 :         result = libspdm_verify_peer_cert_chain_buffer_integrity(
+     366                 :            :             spdm_context, cert_chain, cert_chain_size_internal);
+     367         [ +  + ]:         25 :         if (!result) {
+     368                 :          5 :             status = LIBSPDM_STATUS_VERIF_FAIL;
+     369                 :          5 :             goto done;
+     370                 :            :         }
+     371                 :            : 
+     372                 :            :         /*verify peer cert chain authority*/
+     373                 :         20 :         result = libspdm_verify_peer_cert_chain_buffer_authority(
+     374                 :            :             spdm_context, cert_chain,cert_chain_size_internal,
+     375                 :            :             trust_anchor, trust_anchor_size);
+     376         [ +  + ]:         20 :         if (!result) {
+     377                 :          2 :             status = LIBSPDM_STATUS_VERIF_NO_AUTHORITY;
+     378                 :            :         }
+     379                 :            :     }
+     380                 :            : 
+     381                 :         20 :     spdm_context->connection_info.peer_used_cert_chain_slot_id = slot_id;
+     382                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     383                 :            :     spdm_context->connection_info.peer_used_cert_chain[slot_id].buffer_size =
+     384                 :            :         cert_chain_size_internal;
+     385                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[slot_id].buffer,
+     386                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[slot_id].buffer),
+     387                 :            :                      cert_chain, cert_chain_size_internal);
+     388                 :            : #else
+     389                 :         20 :     result = libspdm_hash_all(
+     390                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+     391                 :            :         cert_chain, cert_chain_size_internal,
+     392                 :         20 :         spdm_context->connection_info.peer_used_cert_chain[slot_id].buffer_hash);
+     393         [ -  + ]:         20 :     if (!result) {
+     394                 :          0 :         status = LIBSPDM_STATUS_CRYPTO_ERROR;
+     395                 :          0 :         goto done;
+     396                 :            :     }
+     397                 :            : 
+     398                 :         40 :     spdm_context->connection_info.peer_used_cert_chain[slot_id].buffer_hash_size =
+     399                 :         20 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+     400                 :            : 
+     401                 :         20 :     result = libspdm_get_leaf_cert_public_key_from_cert_chain(
+     402                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+     403                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+     404                 :            :         cert_chain, cert_chain_size_internal,
+     405                 :         20 :         &spdm_context->connection_info.peer_used_cert_chain[slot_id].leaf_cert_public_key);
+     406         [ -  + ]:         20 :     if (!result) {
+     407                 :          0 :         status = LIBSPDM_STATUS_INVALID_CERT;
+     408                 :          0 :         goto done;
+     409                 :            :     }
+     410                 :            : #endif
+     411                 :            : 
+     412         [ +  + ]:         20 :     if (status != LIBSPDM_STATUS_VERIF_NO_AUTHORITY) {
+     413                 :         18 :         status = LIBSPDM_STATUS_SUCCESS;
+     414                 :            :     }
+     415                 :          2 : done:
+     416                 :         55 :     return status;
+     417                 :            : }
+     418                 :            : 
+     419                 :         53 : libspdm_return_t libspdm_get_certificate(void *spdm_context, const uint32_t *session_id,
+     420                 :            :                                          uint8_t slot_id,
+     421                 :            :                                          size_t *cert_chain_size,
+     422                 :            :                                          void *cert_chain)
+     423                 :            : {
+     424                 :         53 :     return libspdm_get_certificate_choose_length(spdm_context, session_id, slot_id,
+     425                 :            :                                                  LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN,
+     426                 :            :                                                  cert_chain_size, cert_chain);
+     427                 :            : }
+     428                 :            : 
+     429                 :          1 : libspdm_return_t libspdm_get_certificate_ex(void *spdm_context, const uint32_t *session_id,
+     430                 :            :                                             uint8_t slot_id,
+     431                 :            :                                             size_t *cert_chain_size,
+     432                 :            :                                             void *cert_chain,
+     433                 :            :                                             const void **trust_anchor,
+     434                 :            :                                             size_t *trust_anchor_size)
+     435                 :            : {
+     436                 :          1 :     return libspdm_get_certificate_choose_length_ex(spdm_context, session_id, slot_id,
+     437                 :            :                                                     LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN,
+     438                 :            :                                                     cert_chain_size, cert_chain,
+     439                 :            :                                                     trust_anchor, trust_anchor_size);
+     440                 :            : }
+     441                 :            : 
+     442                 :         54 : libspdm_return_t libspdm_get_certificate_choose_length(void *spdm_context,
+     443                 :            :                                                        const uint32_t *session_id,
+     444                 :            :                                                        uint8_t slot_id,
+     445                 :            :                                                        uint16_t length,
+     446                 :            :                                                        size_t *cert_chain_size,
+     447                 :            :                                                        void *cert_chain)
+     448                 :            : {
+     449                 :            :     libspdm_context_t *context;
+     450                 :            :     size_t retry;
+     451                 :            :     uint64_t retry_delay_time;
+     452                 :            :     libspdm_return_t status;
+     453                 :            : 
+     454                 :         54 :     context = spdm_context;
+     455                 :         54 :     context->crypto_request = true;
+     456                 :         54 :     retry = context->retry_times;
+     457                 :         54 :     retry_delay_time = context->retry_delay_time;
+     458                 :            :     do {
+     459                 :         55 :         status = libspdm_try_get_certificate(context, session_id, slot_id, length,
+     460                 :            :                                              cert_chain_size, cert_chain, NULL, NULL);
+     461         [ +  + ]:         55 :         if (status != LIBSPDM_STATUS_BUSY_PEER) {
+     462                 :         53 :             return status;
+     463                 :            :         }
+     464                 :            : 
+     465                 :          2 :         libspdm_sleep(retry_delay_time);
+     466         [ +  + ]:          2 :     } while (retry-- != 0);
+     467                 :            : 
+     468                 :          1 :     return status;
+     469                 :            : }
+     470                 :            : 
+     471                 :          1 : libspdm_return_t libspdm_get_certificate_choose_length_ex(void *spdm_context,
+     472                 :            :                                                           const uint32_t *session_id,
+     473                 :            :                                                           uint8_t slot_id,
+     474                 :            :                                                           uint16_t length,
+     475                 :            :                                                           size_t *cert_chain_size,
+     476                 :            :                                                           void *cert_chain,
+     477                 :            :                                                           const void **trust_anchor,
+     478                 :            :                                                           size_t *trust_anchor_size)
+     479                 :            : {
+     480                 :            :     libspdm_context_t *context;
+     481                 :            :     size_t retry;
+     482                 :            :     uint64_t retry_delay_time;
+     483                 :            :     libspdm_return_t status;
+     484                 :            : 
+     485                 :          1 :     context = spdm_context;
+     486                 :          1 :     context->crypto_request = true;
+     487                 :          1 :     retry = context->retry_times;
+     488                 :          1 :     retry_delay_time = context->retry_delay_time;
+     489                 :            :     do {
+     490                 :          1 :         status = libspdm_try_get_certificate(context, session_id, slot_id, length,
+     491                 :            :                                              cert_chain_size, cert_chain, trust_anchor,
+     492                 :            :                                              trust_anchor_size);
+     493         [ +  - ]:          1 :         if (status != LIBSPDM_STATUS_BUSY_PEER) {
+     494                 :          1 :             return status;
+     495                 :            :         }
+     496                 :            : 
+     497                 :          0 :         libspdm_sleep(retry_delay_time);
+     498         [ #  # ]:          0 :     } while (retry-- != 0);
+     499                 :            : 
+     500                 :          0 :     return status;
+     501                 :            : }
+     502                 :            : 
+     503                 :            : #endif /* LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_get_csr.c.func-sort-c.html b/coverage_log/library/spdm_requester_lib/libspdm_req_get_csr.c.func-sort-c.html new file mode 100644 index 00000000000..3841edf5bd2 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_get_csr.c.func-sort-c.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_get_csr.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_get_csr.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:8913068.5 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:529256.5 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_csr_ex2
libspdm_get_csr6
libspdm_try_get_csr8
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_get_csr.c.func.html b/coverage_log/library/spdm_requester_lib/libspdm_req_get_csr.c.func.html new file mode 100644 index 00000000000..59b879dbf01 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_get_csr.c.func.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_get_csr.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_get_csr.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:8913068.5 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:529256.5 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_csr6
libspdm_get_csr_ex2
libspdm_try_get_csr8
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_get_csr.c.gcov.html b/coverage_log/library/spdm_requester_lib/libspdm_req_get_csr.c.gcov.html new file mode 100644 index 00000000000..824e4f3c935 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_get_csr.c.gcov.html @@ -0,0 +1,395 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_get_csr.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_get_csr.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:8913068.5 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:529256.5 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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_CSR_CAP
+      10                 :            : 
+      11                 :            : /**
+      12                 :            :  * This function sends GET_CSR
+      13                 :            :  * to get csr from the device.
+      14                 :            :  *
+      15                 :            :  * @param[in]  context                      A pointer to the SPDM context.
+      16                 :            :  * @param[in]  session_id                   Indicates if it is a secured message protected via SPDM session.
+      17                 :            :  *                                          If session_id is NULL, it is a normal message.
+      18                 :            :  *                                          If session_id is NOT NULL, it is a secured message.
+      19                 :            :  * @param[in]  requester_info               requester info to gen CSR
+      20                 :            :  * @param[in]  requester_info_length        The len of requester info
+      21                 :            :  * @param[in]  opaque_data                  opaque data
+      22                 :            :  * @param[in]  opaque_data_length           The len of opaque data
+      23                 :            :  * @param[out] csr                          address to store CSR.
+      24                 :            :  * @param[in, out] csr_len                  on input, *csr_len indicates the max csr buffer size.
+      25                 :            :  *                                          on output, *csr_len indicates the actual csr buffer size.
+      26                 :            :  * @param[in]  request_attribute            Set certificate request attributes. This field is only used for SPDM 1.3 and above.
+      27                 :            :  * @param[in]  key_pair_id                  The value of this field shall be the unique key pair number identifying the desired
+      28                 :            :  *                                          asymmetric key pair to associate with SlotID .
+      29                 :            :  * @param[out] available_csr_tracking_tag   available CSRTrackingTag when the Responder sends a ResetRequired error message
+      30                 :            :  *
+      31                 :            :  * @retval RETURN_SUCCESS               The measurement is got successfully.
+      32                 :            :  * @retval RETURN_DEVICE_ERROR          A device error occurs when communicates with the device.
+      33                 :            :  * @retval RETURN_SECURITY_VIOLATION    Any verification fails.
+      34                 :            :  **/
+      35                 :          8 : static libspdm_return_t libspdm_try_get_csr(libspdm_context_t *spdm_context,
+      36                 :            :                                             const uint32_t *session_id,
+      37                 :            :                                             void *requester_info, uint16_t requester_info_length,
+      38                 :            :                                             void *opaque_data, uint16_t opaque_data_length,
+      39                 :            :                                             void *csr, size_t *csr_len,
+      40                 :            :                                             uint8_t request_attribute,
+      41                 :            :                                             uint8_t key_pair_id,
+      42                 :            :                                             uint8_t *available_csr_tracking_tag)
+      43                 :            : {
+      44                 :            :     libspdm_return_t status;
+      45                 :            :     libspdm_return_t warning;
+      46                 :            :     spdm_get_csr_request_t *spdm_request;
+      47                 :            :     size_t spdm_request_size;
+      48                 :            :     spdm_csr_response_t *spdm_response;
+      49                 :            :     size_t spdm_response_size;
+      50                 :            :     size_t transport_header_size;
+      51                 :            :     uint8_t *message;
+      52                 :            :     size_t message_size;
+      53                 :            :     libspdm_session_info_t *session_info;
+      54                 :            :     libspdm_session_state_t session_state;
+      55                 :            : 
+      56                 :          8 :     warning = LIBSPDM_STATUS_SUCCESS;
+      57                 :            : 
+      58         [ -  + ]:          8 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_12) {
+      59                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+      60                 :            :     }
+      61         [ +  + ]:          8 :     if (libspdm_get_connection_version(spdm_context) == SPDM_MESSAGE_VERSION_12) {
+      62   [ +  -  -  + ]:          5 :         if ((key_pair_id != 0) || (request_attribute != 0)) {
+      63                 :          0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
+      64                 :            :         }
+      65                 :            :     }
+      66                 :            : 
+      67         [ +  + ]:          8 :     if (libspdm_get_connection_version(spdm_context) >= SPDM_MESSAGE_VERSION_13) {
+      68                 :          3 :         const uint8_t csr_cert_model = request_attribute &
+      69                 :            :                                        SPDM_GET_CSR_REQUEST_ATTRIBUTES_CERT_MODEL_MASK;
+      70                 :            : 
+      71                 :            :         /* CSR_CAP for a 1.2 Responder is not checked because it was not defined in SPDM 1.2.0. */
+      72         [ -  + ]:          3 :         if (!libspdm_is_capabilities_flag_supported(
+      73                 :            :                 spdm_context, true, 0,
+      74                 :            :                 SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CSR_CAP)) {
+      75                 :          0 :             return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+      76                 :            :         }
+      77         [ +  + ]:          3 :         if (spdm_context->connection_info.multi_key_conn_rsp) {
+      78         [ -  + ]:          1 :             if (key_pair_id == 0) {
+      79                 :          0 :                 return LIBSPDM_STATUS_INVALID_PARAMETER;
+      80                 :            :             }
+      81   [ -  +  -  - ]:          1 :             if ((csr_cert_model == SPDM_CERTIFICATE_INFO_CERT_MODEL_NONE) ||
+      82                 :            :                 (csr_cert_model > SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT)) {
+      83                 :          1 :                 return LIBSPDM_STATUS_INVALID_PARAMETER;
+      84                 :            :             }
+      85                 :            :         } else {
+      86   [ +  -  -  + ]:          2 :             if ((key_pair_id != 0) || (csr_cert_model != 0)) {
+      87                 :          0 :                 return LIBSPDM_STATUS_INVALID_PARAMETER;
+      88                 :            :             }
+      89                 :            :         }
+      90                 :            :     }
+      91                 :            : 
+      92         [ -  + ]:          7 :     LIBSPDM_ASSERT(opaque_data_length < SPDM_MAX_OPAQUE_DATA_SIZE);
+      93                 :            : 
+      94         [ -  + ]:          7 :     if (spdm_context->connection_info.connection_state <
+      95                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
+      96                 :          0 :         return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+      97                 :            :     }
+      98                 :            : 
+      99         [ -  + ]:          7 :     if (session_id != NULL) {
+     100                 :          0 :         session_info = libspdm_get_session_info_via_session_id(
+     101                 :            :             spdm_context, *session_id);
+     102         [ #  # ]:          0 :         if (session_info == NULL) {
+     103                 :          0 :             LIBSPDM_ASSERT(false);
+     104                 :          0 :             return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+     105                 :            :         }
+     106                 :          0 :         session_state = libspdm_secured_message_get_session_state(
+     107                 :            :             session_info->secured_message_context);
+     108         [ #  # ]:          0 :         if (session_state != LIBSPDM_SESSION_STATE_ESTABLISHED) {
+     109                 :          0 :             return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+     110                 :            :         }
+     111                 :            :     }
+     112                 :            : 
+     113                 :          7 :     transport_header_size = spdm_context->local_context.capability.transport_header_size;
+     114                 :          7 :     status = libspdm_acquire_sender_buffer (spdm_context, &message_size, (void **)&message);
+     115         [ -  + ]:          7 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     116                 :          0 :         return status;
+     117                 :            :     }
+     118         [ -  + ]:          7 :     LIBSPDM_ASSERT (message_size >= transport_header_size +
+     119                 :            :                     spdm_context->local_context.capability.transport_tail_size);
+     120                 :          7 :     spdm_request = (void *)(message + transport_header_size);
+     121                 :          7 :     spdm_request_size = message_size - transport_header_size -
+     122                 :          7 :                         spdm_context->local_context.capability.transport_tail_size;
+     123                 :            : 
+     124         [ -  + ]:          7 :     LIBSPDM_ASSERT (spdm_request_size >= sizeof(spdm_get_csr_request_t) + opaque_data_length
+     125                 :            :                     + requester_info_length);
+     126                 :          7 :     spdm_request->header.spdm_version = libspdm_get_connection_version (spdm_context);
+     127                 :          7 :     spdm_request->header.request_response_code = SPDM_GET_CSR;
+     128                 :          7 :     spdm_request->header.param1 = key_pair_id;
+     129                 :          7 :     spdm_request->header.param2 = request_attribute;
+     130                 :            : 
+     131                 :          7 :     spdm_request->opaque_data_length = opaque_data_length;
+     132                 :          7 :     spdm_request->requester_info_length = requester_info_length;
+     133                 :            : 
+     134         [ +  + ]:          7 :     if (requester_info_length != 0) {
+     135                 :          2 :         libspdm_copy_mem(spdm_request + 1,
+     136                 :            :                          spdm_request_size - sizeof(spdm_get_csr_request_t),
+     137                 :            :                          (uint8_t *)requester_info, requester_info_length);
+     138                 :            :     }
+     139                 :            : 
+     140         [ +  + ]:          7 :     if (((spdm_context->connection_info.algorithm.other_params_support &
+     141         [ -  + ]:          4 :           SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_MASK) == SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_NONE) &&
+     142                 :            :         (opaque_data_length != 0)) {
+     143                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "Overriding opaque_data_length to 0 since there is "
+     144                 :            :                        "no negotiated opaque data format.\n"));
+     145                 :          0 :         opaque_data_length = 0;
+     146                 :          0 :         warning = LIBSPDM_STATUS_OVERRIDDEN_PARAMETER;
+     147                 :            :     }
+     148                 :            : 
+     149         [ +  + ]:          7 :     if (opaque_data_length != 0) {
+     150                 :          2 :         libspdm_copy_mem((uint8_t *)(spdm_request + 1) + requester_info_length,
+     151                 :          2 :                          spdm_request_size - sizeof(spdm_get_csr_request_t) - requester_info_length,
+     152                 :            :                          (uint8_t *)opaque_data, opaque_data_length);
+     153                 :            :     }
+     154                 :            : 
+     155                 :          7 :     spdm_request_size = sizeof(spdm_get_csr_request_t) + opaque_data_length
+     156                 :          7 :                         + requester_info_length;
+     157                 :            : 
+     158                 :          7 :     status = libspdm_send_spdm_request(spdm_context, session_id, spdm_request_size, spdm_request);
+     159         [ +  + ]:          7 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     160                 :          1 :         libspdm_release_sender_buffer (spdm_context);
+     161                 :          1 :         return status;
+     162                 :            :     }
+     163                 :          6 :     libspdm_release_sender_buffer (spdm_context);
+     164                 :          6 :     spdm_request = (void *)spdm_context->last_spdm_request;
+     165                 :            : 
+     166                 :            :     /* receive */
+     167                 :          6 :     status = libspdm_acquire_receiver_buffer (spdm_context, &message_size, (void **)&message);
+     168         [ -  + ]:          6 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     169                 :          0 :         return status;
+     170                 :            :     }
+     171         [ -  + ]:          6 :     LIBSPDM_ASSERT (message_size >= transport_header_size);
+     172                 :          6 :     spdm_response = (void *)(message);
+     173                 :          6 :     spdm_response_size = message_size;
+     174                 :            : 
+     175                 :          6 :     status = libspdm_receive_spdm_response(spdm_context, session_id,
+     176                 :            :                                            &spdm_response_size, (void **)&spdm_response);
+     177                 :            : 
+     178         [ -  + ]:          6 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     179                 :          0 :         goto receive_done;
+     180                 :            :     }
+     181         [ -  + ]:          6 :     if (spdm_response_size < sizeof(spdm_message_header_t)) {
+     182                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     183                 :          0 :         goto receive_done;
+     184                 :            :     }
+     185         [ -  + ]:          6 :     if (spdm_response->header.spdm_version != spdm_request->header.spdm_version) {
+     186                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     187                 :          0 :         goto receive_done;
+     188                 :            :     }
+     189         [ +  + ]:          6 :     if (spdm_response->header.request_response_code == SPDM_ERROR) {
+     190   [ +  -  +  + ]:          6 :         if ((spdm_response->header.param1 == SPDM_ERROR_CODE_RESET_REQUIRED) &&
+     191         [ +  + ]:          5 :             (libspdm_get_connection_version(spdm_context) >= SPDM_MESSAGE_VERSION_13) &&
+     192                 :            :             (available_csr_tracking_tag != NULL)) {
+     193                 :          1 :             *available_csr_tracking_tag = spdm_response->header.param2;
+     194                 :            :         }
+     195                 :            : 
+     196                 :          3 :         status = libspdm_handle_error_response_main(
+     197                 :            :             spdm_context, session_id,
+     198                 :            :             &spdm_response_size,
+     199                 :            :             (void **)&spdm_response, SPDM_GET_CSR, SPDM_CSR);
+     200         [ +  - ]:          3 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     201                 :          3 :             goto receive_done;
+     202                 :            :         }
+     203         [ -  + ]:          3 :     } else if (spdm_response->header.request_response_code != SPDM_CSR) {
+     204                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     205                 :          0 :         goto receive_done;
+     206                 :            :     }
+     207                 :            : 
+     208         [ -  + ]:          3 :     if (spdm_response_size < sizeof(spdm_csr_response_t)) {
+     209                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     210                 :          0 :         goto receive_done;
+     211                 :            :     }
+     212         [ -  + ]:          3 :     if (spdm_response->csr_length == 0) {
+     213                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     214                 :          0 :         goto receive_done;
+     215                 :            :     }
+     216                 :            : 
+     217         [ -  + ]:          3 :     if (spdm_response_size < sizeof(spdm_csr_response_t) + spdm_response->csr_length) {
+     218                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     219                 :          0 :         goto receive_done;
+     220                 :            :     }
+     221         [ -  + ]:          3 :     if (*csr_len < spdm_response->csr_length) {
+     222                 :          0 :         *csr_len = spdm_response->csr_length;
+     223                 :          0 :         status =  LIBSPDM_STATUS_BUFFER_TOO_SMALL;
+     224                 :          0 :         goto receive_done;
+     225                 :            :     }
+     226                 :            : 
+     227                 :          3 :     libspdm_copy_mem(csr, *csr_len, spdm_response + 1, spdm_response->csr_length);
+     228                 :          3 :     *csr_len = spdm_response->csr_length;
+     229                 :            : 
+     230                 :          3 :     status = LIBSPDM_STATUS_SUCCESS;
+     231                 :            : 
+     232                 :          6 : receive_done:
+     233                 :          6 :     libspdm_release_receiver_buffer (spdm_context);
+     234                 :            : 
+     235   [ +  +  -  + ]:          6 :     if (LIBSPDM_STATUS_IS_SUCCESS(status) && LIBSPDM_STATUS_IS_WARNING(warning)) {
+     236                 :          0 :         status = warning;
+     237                 :            :     }
+     238                 :          6 :     return status;
+     239                 :            : }
+     240                 :            : 
+     241                 :          6 : libspdm_return_t libspdm_get_csr(void * spdm_context,
+     242                 :            :                                  const uint32_t *session_id,
+     243                 :            :                                  void * requester_info, uint16_t requester_info_length,
+     244                 :            :                                  void * opaque_data, uint16_t opaque_data_length,
+     245                 :            :                                  void *csr, size_t *csr_len)
+     246                 :            : {
+     247                 :            :     libspdm_context_t *context;
+     248                 :            :     size_t retry;
+     249                 :            :     uint64_t retry_delay_time;
+     250                 :            :     libspdm_return_t status;
+     251                 :            : 
+     252                 :          6 :     context = spdm_context;
+     253                 :          6 :     context->crypto_request = true;
+     254                 :          6 :     retry = context->retry_times;
+     255                 :          6 :     retry_delay_time = context->retry_delay_time;
+     256                 :            :     do {
+     257                 :          6 :         status = libspdm_try_get_csr(context, session_id,
+     258                 :            :                                      requester_info, requester_info_length,
+     259                 :            :                                      opaque_data, opaque_data_length,
+     260                 :            :                                      csr, csr_len,
+     261                 :            :                                      0, 0, NULL);
+     262         [ +  - ]:          6 :         if (status != LIBSPDM_STATUS_BUSY_PEER) {
+     263                 :          6 :             return status;
+     264                 :            :         }
+     265                 :            : 
+     266                 :          0 :         libspdm_sleep(retry_delay_time);
+     267         [ #  # ]:          0 :     } while (retry-- != 0);
+     268                 :            : 
+     269                 :          0 :     return status;
+     270                 :            : }
+     271                 :            : 
+     272                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CSR_CAP_EX
+     273                 :          2 : libspdm_return_t libspdm_get_csr_ex(void * spdm_context,
+     274                 :            :                                     const uint32_t *session_id,
+     275                 :            :                                     void * requester_info, uint16_t requester_info_length,
+     276                 :            :                                     void * opaque_data, uint16_t opaque_data_length,
+     277                 :            :                                     void *csr, size_t *csr_len,
+     278                 :            :                                     uint8_t request_attribute,
+     279                 :            :                                     uint8_t key_pair_id,
+     280                 :            :                                     uint8_t *available_csr_tracking_tag
+     281                 :            :                                     )
+     282                 :            : {
+     283                 :            :     libspdm_context_t *context;
+     284                 :            :     size_t retry;
+     285                 :            :     uint64_t retry_delay_time;
+     286                 :            :     libspdm_return_t status;
+     287                 :            : 
+     288                 :          2 :     context = spdm_context;
+     289                 :          2 :     context->crypto_request = true;
+     290                 :          2 :     retry = context->retry_times;
+     291                 :          2 :     retry_delay_time = context->retry_delay_time;
+     292                 :            :     do {
+     293                 :          2 :         status = libspdm_try_get_csr(context, session_id,
+     294                 :            :                                      requester_info, requester_info_length,
+     295                 :            :                                      opaque_data, opaque_data_length,
+     296                 :            :                                      csr, csr_len,
+     297                 :            :                                      request_attribute, key_pair_id,
+     298                 :            :                                      available_csr_tracking_tag);
+     299         [ +  - ]:          2 :         if (status != LIBSPDM_STATUS_BUSY_PEER) {
+     300                 :          2 :             return status;
+     301                 :            :         }
+     302                 :            : 
+     303                 :          0 :         libspdm_sleep(retry_delay_time);
+     304         [ #  # ]:          0 :     } while (retry-- != 0);
+     305                 :            : 
+     306                 :          0 :     return status;
+     307                 :            : }
+     308                 :            : #endif /*LIBSPDM_ENABLE_CAPABILITY_CSR_CAP_EX*/
+     309                 :            : 
+     310                 :            : #endif /*LIBSPDM_ENABLE_CAPABILITY_CSR_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_get_digests.c.func-sort-c.html b/coverage_log/library/spdm_requester_lib/libspdm_req_get_digests.c.func-sort-c.html new file mode 100644 index 00000000000..bee2a7709c4 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_get_digests.c.func-sort-c.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_get_digests.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_get_digests.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:15817192.4 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:8910684.0 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_digest44
libspdm_try_get_digest44
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_get_digests.c.func.html b/coverage_log/library/spdm_requester_lib/libspdm_req_get_digests.c.func.html new file mode 100644 index 00000000000..67284e1a03f --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_get_digests.c.func.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_get_digests.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_get_digests.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:15817192.4 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:8910684.0 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_digest44
libspdm_try_get_digest44
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_get_digests.c.gcov.html b/coverage_log/library/spdm_requester_lib/libspdm_req_get_digests.c.gcov.html new file mode 100644 index 00000000000..37748cb4b56 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_get_digests.c.gcov.html @@ -0,0 +1,445 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_get_digests.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_get_digests.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:15817192.4 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:8910684.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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_SEND_GET_CERTIFICATE_SUPPORT
+      10                 :            : 
+      11                 :            : #pragma pack(1)
+      12                 :            : typedef struct {
+      13                 :            :     spdm_message_header_t header;
+      14                 :            :     uint8_t digest[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
+      15                 :            :     spdm_key_pair_id_t key_pair_id[SPDM_MAX_SLOT_COUNT];
+      16                 :            :     spdm_certificate_info_t cert_info[SPDM_MAX_SLOT_COUNT];
+      17                 :            :     spdm_key_usage_bit_mask_t key_usage_bit_mask[SPDM_MAX_SLOT_COUNT];
+      18                 :            : } libspdm_digests_response_max_t;
+      19                 :            : #pragma pack()
+      20                 :            : 
+      21                 :            : /**
+      22                 :            :  * This function sends GET_DIGESTS and receives DIGESTS *
+      23                 :            :  *
+      24                 :            :  * @param  context             A pointer to the SPDM context.
+      25                 :            :  * @param  slot_mask           Bitmask of the slots that contain certificates.
+      26                 :            :  * @param  total_digest_buffer A pointer to a destination buffer to store the digests.
+      27                 :            :  *
+      28                 :            :  * @retval LIBSPDM_STATUS_SUCCESS
+      29                 :            :  *         GET_DIGESTS was sent and DIGESTS was received.
+      30                 :            :  * @retval LIBSPDM_STATUS_INVALID_STATE_LOCAL
+      31                 :            :  *         Cannot send GET_DIGESTS due to Requester's state.
+      32                 :            :  * @retval LIBSPDM_STATUS_UNSUPPORTED_CAP
+      33                 :            :  *         Cannot send GET_DIGESTS because the Requester's and/or Responder's CERT_CAP = 0.
+      34                 :            :  * @retval LIBSPDM_STATUS_INVALID_MSG_SIZE
+      35                 :            :  *         The size of the DIGESTS response is invalid.
+      36                 :            :  * @retval LIBSPDM_STATUS_INVALID_MSG_FIELD
+      37                 :            :  *         The DIGESTS response contains one or more invalid fields.
+      38                 :            :  * @retval LIBSPDM_STATUS_ERROR_PEER
+      39                 :            :  *         The Responder returned an unexpected error.
+      40                 :            :  * @retval LIBSPDM_STATUS_BUSY_PEER
+      41                 :            :  *         The Responder continually returned Busy error messages.
+      42                 :            :  * @retval LIBSPDM_STATUS_RESYNCH_PEER
+      43                 :            :  *         The Responder returned a RequestResynch error message.
+      44                 :            :  * @retval LIBSPDM_STATUS_BUFFER_FULL
+      45                 :            :  *         The buffer used to store transcripts is exhausted.
+      46                 :            :  **/
+      47                 :         44 : static libspdm_return_t libspdm_try_get_digest(libspdm_context_t *spdm_context,
+      48                 :            :                                                const uint32_t *session_id,
+      49                 :            :                                                uint8_t *slot_mask,
+      50                 :            :                                                void *total_digest_buffer)
+      51                 :            : {
+      52                 :            :     libspdm_return_t status;
+      53                 :            :     spdm_get_digest_request_t *spdm_request;
+      54                 :            :     size_t spdm_request_size;
+      55                 :            :     libspdm_digests_response_max_t *spdm_response;
+      56                 :            :     size_t spdm_response_size;
+      57                 :            :     size_t digest_size;
+      58                 :            :     size_t digest_count;
+      59                 :            :     size_t index;
+      60                 :            :     uint8_t *message;
+      61                 :            :     size_t message_size;
+      62                 :            :     size_t transport_header_size;
+      63                 :            :     libspdm_session_info_t *session_info;
+      64                 :            :     libspdm_session_state_t session_state;
+      65                 :            :     size_t additional_size;
+      66                 :            :     spdm_key_pair_id_t *key_pair_id;
+      67                 :            :     spdm_certificate_info_t *cert_info;
+      68                 :            :     spdm_key_usage_bit_mask_t *key_usage_bit_mask;
+      69                 :            :     size_t slot_index;
+      70                 :            :     uint8_t cert_model;
+      71                 :         44 :     uint8_t zero_digest[LIBSPDM_MAX_HASH_SIZE] = {0};
+      72                 :            : 
+      73                 :            :     /* -=[Verify State Phase]=- */
+      74         [ +  + ]:         44 :     if (!libspdm_is_capabilities_flag_supported(
+      75                 :            :             spdm_context, true, 0,
+      76                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP)) {
+      77                 :          1 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+      78                 :            :     }
+      79         [ +  + ]:         43 :     if (spdm_context->connection_info.connection_state < LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
+      80                 :          1 :         return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+      81                 :            :     }
+      82                 :            : 
+      83                 :         42 :     session_info = NULL;
+      84         [ +  + ]:         42 :     if (session_id != NULL) {
+      85                 :          1 :         session_info = libspdm_get_session_info_via_session_id(spdm_context, *session_id);
+      86         [ -  + ]:          1 :         if (session_info == NULL) {
+      87                 :          0 :             return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+      88                 :            :         }
+      89                 :          1 :         session_state = libspdm_secured_message_get_session_state(
+      90                 :            :             session_info->secured_message_context);
+      91         [ -  + ]:          1 :         if (session_state != LIBSPDM_SESSION_STATE_ESTABLISHED) {
+      92                 :          0 :             return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+      93                 :            :         }
+      94                 :            :     }
+      95                 :            : 
+      96                 :         42 :     libspdm_reset_message_buffer_via_request_code(spdm_context, session_info, SPDM_GET_DIGESTS);
+      97                 :            : 
+      98                 :            :     /* -=[Construct Request Phase]=- */
+      99                 :         42 :     transport_header_size = spdm_context->local_context.capability.transport_header_size;
+     100                 :         42 :     status = libspdm_acquire_sender_buffer (spdm_context, &message_size, (void **)&message);
+     101         [ +  + ]:         42 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     102                 :          1 :         return status;
+     103                 :            :     }
+     104         [ -  + ]:         41 :     LIBSPDM_ASSERT (message_size >= transport_header_size +
+     105                 :            :                     spdm_context->local_context.capability.transport_tail_size);
+     106                 :         41 :     spdm_request = (void *)(message + transport_header_size);
+     107                 :         41 :     spdm_request_size = message_size - transport_header_size -
+     108                 :         41 :                         spdm_context->local_context.capability.transport_tail_size;
+     109                 :            : 
+     110         [ -  + ]:         41 :     LIBSPDM_ASSERT (spdm_request_size >= sizeof(spdm_get_digest_request_t));
+     111                 :         41 :     spdm_request->header.spdm_version = libspdm_get_connection_version (spdm_context);
+     112                 :         41 :     spdm_request->header.request_response_code = SPDM_GET_DIGESTS;
+     113                 :         41 :     spdm_request->header.param1 = 0;
+     114                 :         41 :     spdm_request->header.param2 = 0;
+     115                 :         41 :     spdm_request_size = sizeof(spdm_get_digest_request_t);
+     116                 :            : 
+     117                 :            :     /* -=[Send Request Phase]=- */
+     118                 :         41 :     status = libspdm_send_spdm_request(spdm_context, session_id, spdm_request_size, spdm_request);
+     119         [ +  + ]:         41 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     120                 :          1 :         libspdm_release_sender_buffer (spdm_context);
+     121                 :          1 :         return status;
+     122                 :            :     }
+     123                 :         40 :     libspdm_release_sender_buffer (spdm_context);
+     124                 :         40 :     spdm_request = (void *)spdm_context->last_spdm_request;
+     125                 :            : 
+     126                 :            :     /* -=[Receive Response Phase]=- */
+     127                 :         40 :     status = libspdm_acquire_receiver_buffer (spdm_context, &message_size, (void **)&message);
+     128         [ +  + ]:         40 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     129                 :          1 :         return status;
+     130                 :            :     }
+     131         [ -  + ]:         39 :     LIBSPDM_ASSERT (message_size >= transport_header_size);
+     132                 :         39 :     spdm_response = (void *)(message);
+     133                 :         39 :     spdm_response_size = message_size;
+     134                 :            : 
+     135                 :         39 :     status = libspdm_receive_spdm_response(
+     136                 :            :         spdm_context, session_id, &spdm_response_size, (void **)&spdm_response);
+     137         [ +  + ]:         39 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     138                 :          1 :         goto receive_done;
+     139                 :            :     }
+     140                 :            : 
+     141                 :            :     /* -=[Validate Response Phase]=- */
+     142         [ -  + ]:         38 :     if (spdm_response_size < sizeof(spdm_message_header_t)) {
+     143                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     144                 :          0 :         goto receive_done;
+     145                 :            :     }
+     146         [ +  + ]:         38 :     if (spdm_response->header.spdm_version != spdm_request->header.spdm_version) {
+     147                 :          1 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     148                 :          1 :         goto receive_done;
+     149                 :            :     }
+     150         [ +  + ]:         37 :     if (spdm_response->header.request_response_code == SPDM_ERROR) {
+     151                 :         22 :         status = libspdm_handle_error_response_main(
+     152                 :            :             spdm_context, session_id,
+     153                 :            :             &spdm_response_size,
+     154                 :            :             (void **)&spdm_response, SPDM_GET_DIGESTS, SPDM_DIGESTS);
+     155         [ +  - ]:         22 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     156                 :         22 :             goto receive_done;
+     157                 :            :         }
+     158         [ +  + ]:         15 :     } else if (spdm_response->header.request_response_code != SPDM_DIGESTS) {
+     159                 :          1 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     160                 :          1 :         goto receive_done;
+     161                 :            :     }
+     162         [ -  + ]:         14 :     if (spdm_response_size < sizeof(spdm_digest_response_t)) {
+     163                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     164                 :          0 :         goto receive_done;
+     165                 :            :     }
+     166                 :            : 
+     167                 :         14 :     digest_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+     168         [ +  - ]:         14 :     if (slot_mask != NULL) {
+     169                 :         14 :         *slot_mask = spdm_response->header.param2;
+     170                 :            :     }
+     171                 :            : 
+     172                 :         14 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "provisioned_slot_mask - 0x%02x\n",
+     173                 :            :                    spdm_response->header.param2));
+     174         [ +  + ]:         14 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
+     175                 :          6 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "supported_slot_mask - 0x%02x\n",
+     176                 :            :                        spdm_response->header.param1));
+     177                 :          6 :         if ((spdm_response->header.param1 & spdm_response->header.param2) !=
+     178         [ -  + ]:          6 :             spdm_response->header.param2) {
+     179                 :          0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     180                 :          0 :             goto receive_done;
+     181                 :            :         }
+     182                 :            :     }
+     183                 :            : 
+     184                 :         14 :     digest_count = 0;
+     185         [ +  + ]:        126 :     for (index = 0; index < SPDM_MAX_SLOT_COUNT; index++) {
+     186         [ +  + ]:        112 :         if (spdm_response->header.param2 & (1 << index)) {
+     187                 :         31 :             digest_count++;
+     188                 :            :         }
+     189                 :            :     }
+     190         [ +  + ]:         14 :     if (digest_count == 0) {
+     191                 :          1 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     192                 :          1 :         goto receive_done;
+     193                 :            :     }
+     194                 :            : 
+     195                 :         13 :     additional_size = 0;
+     196         [ +  + ]:         13 :     if ((spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) &&
+     197         [ +  + ]:          6 :         spdm_context->connection_info.multi_key_conn_rsp) {
+     198                 :          5 :         additional_size = sizeof(spdm_key_pair_id_t) + sizeof(spdm_certificate_info_t) +
+     199                 :            :                           sizeof(spdm_key_usage_bit_mask_t);
+     200                 :            :     }
+     201                 :         13 :     if (spdm_response_size <
+     202         [ +  + ]:         13 :         sizeof(spdm_digest_response_t) + digest_count * (digest_size + additional_size)) {
+     203                 :          1 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     204                 :          1 :         goto receive_done;
+     205                 :            :     }
+     206                 :         12 :     spdm_response_size =
+     207                 :         12 :         sizeof(spdm_digest_response_t) + digest_count * (digest_size + additional_size);
+     208                 :            : 
+     209                 :            :     /* -=[Process Response Phase]=- */
+     210         [ +  + ]:         12 :     if (session_id == NULL) {
+     211                 :         11 :         status = libspdm_append_message_b(spdm_context, spdm_request, spdm_request_size);
+     212         [ -  + ]:         11 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     213                 :          0 :             goto receive_done;
+     214                 :            :         }
+     215                 :            : 
+     216                 :         11 :         status = libspdm_append_message_b(spdm_context, spdm_response, spdm_response_size);
+     217         [ -  + ]:         11 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     218                 :          0 :             goto receive_done;
+     219                 :            :         }
+     220                 :            : 
+     221         [ +  + ]:         11 :         if (spdm_context->connection_info.multi_key_conn_rsp) {
+     222                 :          5 :             status = libspdm_append_message_d(spdm_context, spdm_response, spdm_response_size);
+     223         [ -  + ]:          5 :             if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     224                 :          0 :                 goto receive_done;
+     225                 :            :             }
+     226                 :            :         }
+     227                 :            :     }
+     228                 :            : 
+     229                 :         12 :     key_pair_id =
+     230                 :         12 :         (spdm_key_pair_id_t *)((uint8_t *)spdm_response->digest + digest_size * digest_count);
+     231                 :         12 :     cert_info =
+     232                 :            :         (spdm_certificate_info_t *)((uint8_t *)key_pair_id + sizeof(spdm_key_pair_id_t) *
+     233                 :            :                                     digest_count);
+     234                 :         12 :     key_usage_bit_mask =
+     235                 :            :         (spdm_key_usage_bit_mask_t *)((uint8_t *)cert_info + sizeof(spdm_certificate_info_t) *
+     236                 :            :                                       digest_count);
+     237         [ +  + ]:         39 :     for (index = 0; index < digest_count; index++) {
+     238                 :         27 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "digest (0x%zx) - ", index));
+     239                 :         27 :         LIBSPDM_INTERNAL_DUMP_DATA(&spdm_response->digest[digest_size * index], digest_size);
+     240                 :         27 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     241                 :            :     }
+     242         [ +  + ]:         12 :     if ((spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) &&
+     243         [ +  + ]:          6 :         spdm_context->connection_info.multi_key_conn_rsp) {
+     244         [ +  + ]:         18 :         for (index = 0; index < digest_count; index++) {
+     245                 :         13 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "key_pair_id (0x%zx) - 0x%02x\n", index,
+     246                 :            :                            key_pair_id[index]));
+     247                 :            :         }
+     248         [ +  + ]:         18 :         for (index = 0; index < digest_count; index++) {
+     249                 :         13 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "cert_info (0x%zx) - 0x%02x\n", index,
+     250                 :            :                            cert_info[index]));
+     251                 :            :         }
+     252         [ +  + ]:         18 :         for (index = 0; index < digest_count; index++) {
+     253                 :         13 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "key_usage_bit_mask (0x%zx) - 0x%04x\n", index,
+     254                 :            :                            key_usage_bit_mask[index]));
+     255                 :            :         }
+     256                 :            :     }
+     257                 :            : 
+     258         [ +  - ]:         12 :     if (total_digest_buffer != NULL) {
+     259                 :         12 :         libspdm_copy_mem(total_digest_buffer, digest_size * digest_count,
+     260                 :         12 :                          spdm_response->digest, digest_size * digest_count);
+     261                 :            :     }
+     262                 :            : 
+     263                 :         12 :     spdm_context->connection_info.peer_provisioned_slot_mask = spdm_response->header.param2;
+     264         [ +  + ]:         12 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
+     265                 :          6 :         spdm_context->connection_info.peer_supported_slot_mask = spdm_response->header.param1;
+     266                 :            :     } else {
+     267                 :          6 :         spdm_context->connection_info.peer_supported_slot_mask = spdm_response->header.param2;
+     268                 :            :     }
+     269                 :         12 :     libspdm_copy_mem(
+     270                 :         12 :         spdm_context->connection_info.peer_total_digest_buffer,
+     271                 :            :         sizeof(spdm_context->connection_info.peer_total_digest_buffer),
+     272                 :         12 :         spdm_response->digest, digest_size * digest_count);
+     273                 :         12 :     libspdm_zero_mem(spdm_context->connection_info.peer_key_pair_id,
+     274                 :            :                      sizeof(spdm_context->connection_info.peer_key_pair_id));
+     275                 :         12 :     libspdm_zero_mem(spdm_context->connection_info.peer_cert_info,
+     276                 :            :                      sizeof(spdm_context->connection_info.peer_cert_info));
+     277                 :         12 :     libspdm_zero_mem(spdm_context->connection_info.peer_key_usage_bit_mask,
+     278                 :            :                      sizeof(spdm_context->connection_info.peer_key_usage_bit_mask));
+     279         [ +  + ]:         12 :     if ((spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) &&
+     280         [ +  + ]:          6 :         spdm_context->connection_info.multi_key_conn_rsp) {
+     281                 :          5 :         slot_index = 0;
+     282         [ +  + ]:         22 :         for (index = 0; index < SPDM_MAX_SLOT_COUNT; index++) {
+     283         [ +  + ]:         20 :             if (spdm_response->header.param2 & (1 << index)) {
+     284                 :         13 :                 spdm_context->connection_info.peer_key_pair_id[index] = key_pair_id[slot_index];
+     285                 :         13 :                 cert_model = cert_info[slot_index] & SPDM_CERTIFICATE_INFO_CERT_MODEL_MASK;
+     286         [ -  + ]:         13 :                 if (cert_model > SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT) {
+     287                 :          0 :                     status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     288                 :          0 :                     goto receive_done;
+     289                 :            :                 }
+     290         [ +  + ]:         13 :                 if (index == 0) {
+     291         [ +  + ]:          5 :                     if (cert_model == SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT) {
+     292                 :          1 :                         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     293                 :          1 :                         goto receive_done;
+     294                 :            :                     }
+     295         [ +  + ]:          4 :                     if ((key_usage_bit_mask[slot_index] &
+     296                 :            :                          (SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE |
+     297                 :            :                           SPDM_KEY_USAGE_BIT_MASK_CHALLENGE_USE |
+     298                 :            :                           SPDM_KEY_USAGE_BIT_MASK_MEASUREMENT_USE |
+     299                 :            :                           SPDM_KEY_USAGE_BIT_MASK_ENDPOINT_INFO_USE)) == 0) {
+     300                 :          1 :                         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     301                 :          1 :                         goto receive_done;
+     302                 :            :                     }
+     303                 :            :                 }
+     304         [ +  + ]:         11 :                 if ((cert_model == SPDM_CERTIFICATE_INFO_CERT_MODEL_NONE) &&
+     305         [ +  - ]:          1 :                     (!libspdm_consttime_is_mem_equal(
+     306                 :          1 :                          spdm_response->digest + digest_size * slot_index,
+     307                 :            :                          zero_digest,
+     308                 :            :                          digest_size))) {
+     309                 :          1 :                     status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     310                 :          1 :                     goto receive_done;
+     311                 :            :                 }
+     312                 :         10 :                 spdm_context->connection_info.peer_cert_info[index] = cert_model;
+     313                 :         10 :                 spdm_context->connection_info.peer_key_usage_bit_mask[index] =
+     314                 :         10 :                     key_usage_bit_mask[slot_index];
+     315                 :         10 :                 slot_index++;
+     316                 :            :             }
+     317                 :            :         }
+     318                 :            :     }
+     319                 :            : 
+     320                 :            :     /* -=[Update State Phase]=- */
+     321         [ +  + ]:          9 :     if (spdm_context->connection_info.connection_state < LIBSPDM_CONNECTION_STATE_AFTER_DIGESTS) {
+     322                 :          7 :         spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_DIGESTS;
+     323                 :            :     }
+     324                 :          9 :     status = LIBSPDM_STATUS_SUCCESS;
+     325                 :            : 
+     326                 :            :     /* -=[Log Message Phase]=- */
+     327                 :            :     #if LIBSPDM_ENABLE_MSG_LOG
+     328                 :          9 :     libspdm_append_msg_log(spdm_context, spdm_response, spdm_response_size);
+     329                 :            :     #endif /* LIBSPDM_ENABLE_MSG_LOG */
+     330                 :            : 
+     331                 :         39 : receive_done:
+     332                 :         39 :     libspdm_release_receiver_buffer (spdm_context);
+     333                 :         39 :     return status;
+     334                 :            : }
+     335                 :            : 
+     336                 :         44 : libspdm_return_t libspdm_get_digest(void *spdm_context, const uint32_t *session_id,
+     337                 :            :                                     uint8_t *slot_mask, void *total_digest_buffer)
+     338                 :            : {
+     339                 :            :     libspdm_context_t *context;
+     340                 :            :     size_t retry;
+     341                 :            :     uint64_t retry_delay_time;
+     342                 :            :     libspdm_return_t status;
+     343                 :            : 
+     344                 :         44 :     context = spdm_context;
+     345                 :         44 :     context->crypto_request = true;
+     346                 :         44 :     retry = context->retry_times;
+     347                 :         44 :     retry_delay_time = context->retry_delay_time;
+     348                 :            :     do {
+     349                 :         44 :         status = libspdm_try_get_digest(context, session_id, slot_mask, total_digest_buffer);
+     350         [ +  + ]:         44 :         if (status != LIBSPDM_STATUS_BUSY_PEER) {
+     351                 :         43 :             return status;
+     352                 :            :         }
+     353                 :            : 
+     354                 :          1 :         libspdm_sleep(retry_delay_time);
+     355         [ -  + ]:          1 :     } while (retry-- != 0);
+     356                 :            : 
+     357                 :          1 :     return status;
+     358                 :            : }
+     359                 :            : 
+     360                 :            : #endif /* LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_get_event_types.c.func-sort-c.html b/coverage_log/library/spdm_requester_lib/libspdm_req_get_event_types.c.func-sort-c.html new file mode 100644 index 00000000000..38e449de15e --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_get_event_types.c.func-sort-c.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_get_event_types.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_get_event_types.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:609066.7 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:255248.1 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_event_types2
libspdm_try_get_event_types2
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_get_event_types.c.func.html b/coverage_log/library/spdm_requester_lib/libspdm_req_get_event_types.c.func.html new file mode 100644 index 00000000000..f4a1bbd17a1 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_get_event_types.c.func.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_get_event_types.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_get_event_types.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:609066.7 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:255248.1 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_event_types2
libspdm_try_get_event_types2
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_get_event_types.c.gcov.html b/coverage_log/library/spdm_requester_lib/libspdm_req_get_event_types.c.gcov.html new file mode 100644 index 00000000000..ccaf9d093a3 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_get_event_types.c.gcov.html @@ -0,0 +1,266 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_get_event_types.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_get_event_types.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:609066.7 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:255248.1 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2024 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_EVENT_RECIPIENT_SUPPORT
+      10                 :            : 
+      11                 :          2 : static libspdm_return_t libspdm_try_get_event_types(libspdm_context_t *spdm_context,
+      12                 :            :                                                     uint32_t session_id,
+      13                 :            :                                                     uint8_t *event_group_count,
+      14                 :            :                                                     uint32_t *supported_event_groups_list_len,
+      15                 :            :                                                     void *supported_event_groups_list)
+      16                 :            : {
+      17                 :            :     libspdm_return_t status;
+      18                 :            :     libspdm_session_info_t *session_info;
+      19                 :            :     spdm_get_supported_event_types_request_t *spdm_request;
+      20                 :            :     size_t spdm_request_size;
+      21                 :            :     spdm_supported_event_types_response_t *spdm_response;
+      22                 :            :     size_t spdm_response_size;
+      23                 :            :     size_t transport_header_size;
+      24                 :            :     uint8_t *message;
+      25                 :            :     size_t message_size;
+      26                 :            : 
+      27                 :            :     /* -=[Check Parameters Phase]=- */
+      28         [ -  + ]:          2 :     LIBSPDM_ASSERT(event_group_count != NULL);
+      29         [ -  + ]:          2 :     LIBSPDM_ASSERT(supported_event_groups_list_len != NULL);
+      30         [ -  + ]:          2 :     LIBSPDM_ASSERT(supported_event_groups_list != NULL);
+      31                 :            : 
+      32                 :          2 :     session_info = libspdm_get_session_info_via_session_id(spdm_context, session_id);
+      33                 :            : 
+      34         [ -  + ]:          2 :     if (session_info == NULL) {
+      35                 :          0 :         LIBSPDM_ASSERT(false);
+      36                 :          0 :         return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+      37                 :            :     }
+      38         [ -  + ]:          2 :     if (libspdm_secured_message_get_session_state(session_info->secured_message_context) !=
+      39                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED) {
+      40                 :          0 :         return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+      41                 :            :     }
+      42                 :            : 
+      43                 :            :     /* -=[Verify State Phase]=- */
+      44         [ -  + ]:          2 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_13) {
+      45                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+      46                 :            :     }
+      47         [ -  + ]:          2 :     if (!libspdm_is_capabilities_flag_supported(
+      48                 :            :             spdm_context, true, 0,
+      49                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EVENT_CAP)) {
+      50                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+      51                 :            :     }
+      52                 :            : 
+      53                 :            :     /* -=[Construct Request Phase]=- */
+      54                 :          2 :     transport_header_size = spdm_context->local_context.capability.transport_header_size;
+      55                 :          2 :     status = libspdm_acquire_sender_buffer (spdm_context, &message_size, (void **)&message);
+      56         [ -  + ]:          2 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+      57                 :          0 :         return status;
+      58                 :            :     }
+      59         [ -  + ]:          2 :     LIBSPDM_ASSERT (message_size >= transport_header_size +
+      60                 :            :                     spdm_context->local_context.capability.transport_tail_size);
+      61                 :          2 :     spdm_request = (void *)(message + transport_header_size);
+      62                 :          2 :     spdm_request_size = message_size - transport_header_size -
+      63                 :          2 :                         spdm_context->local_context.capability.transport_tail_size;
+      64                 :            : 
+      65         [ -  + ]:          2 :     LIBSPDM_ASSERT (spdm_request_size >= sizeof(spdm_get_supported_event_types_request_t));
+      66                 :          2 :     spdm_request->header.spdm_version = libspdm_get_connection_version(spdm_context);
+      67                 :          2 :     spdm_request->header.request_response_code = SPDM_GET_SUPPORTED_EVENT_TYPES;
+      68                 :          2 :     spdm_request->header.param1 = 0;
+      69                 :          2 :     spdm_request->header.param2 = 0;
+      70                 :          2 :     spdm_request_size = sizeof(spdm_get_supported_event_types_request_t);
+      71                 :            : 
+      72                 :            :     /* -=[Send Request Phase]=- */
+      73                 :          2 :     status = libspdm_send_spdm_request(spdm_context, &session_id, spdm_request_size, spdm_request);
+      74         [ -  + ]:          2 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+      75                 :          0 :         libspdm_release_sender_buffer (spdm_context);
+      76                 :          0 :         return status;
+      77                 :            :     }
+      78                 :          2 :     libspdm_release_sender_buffer (spdm_context);
+      79                 :          2 :     spdm_request = (void *)spdm_context->last_spdm_request;
+      80                 :            : 
+      81                 :            :     /* -=[Receive Response Phase]=- */
+      82                 :          2 :     status = libspdm_acquire_receiver_buffer(spdm_context, &message_size, (void **)&message);
+      83         [ -  + ]:          2 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+      84                 :          0 :         return status;
+      85                 :            :     }
+      86         [ -  + ]:          2 :     LIBSPDM_ASSERT (message_size >= transport_header_size);
+      87                 :          2 :     spdm_response = (void *)(message);
+      88                 :          2 :     spdm_response_size = message_size;
+      89                 :            : 
+      90                 :          2 :     status = libspdm_receive_spdm_response(
+      91                 :            :         spdm_context, &session_id, &spdm_response_size, (void **)&spdm_response);
+      92         [ -  + ]:          2 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+      93                 :          0 :         goto receive_done;
+      94                 :            :     }
+      95                 :            : 
+      96                 :            :     /* -=[Validate Response Phase]=- */
+      97         [ -  + ]:          2 :     if (spdm_response_size < sizeof(spdm_message_header_t)) {
+      98                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+      99                 :          0 :         goto receive_done;
+     100                 :            :     }
+     101         [ -  + ]:          2 :     if (spdm_response->header.spdm_version != spdm_request->header.spdm_version) {
+     102                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     103                 :          0 :         goto receive_done;
+     104                 :            :     }
+     105         [ -  + ]:          2 :     if (spdm_response->header.request_response_code == SPDM_ERROR) {
+     106                 :          0 :         status = libspdm_handle_error_response_main(
+     107                 :            :             spdm_context, &session_id,
+     108                 :            :             &spdm_response_size, (void **)&spdm_response,
+     109                 :            :             SPDM_GET_SUPPORTED_EVENT_TYPES, SPDM_SUPPORTED_EVENT_TYPES);
+     110         [ #  # ]:          0 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     111                 :          0 :             goto receive_done;
+     112                 :            :         }
+     113         [ -  + ]:          2 :     } else if (spdm_response->header.request_response_code != SPDM_SUPPORTED_EVENT_TYPES) {
+     114                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     115                 :          0 :         goto receive_done;
+     116                 :            :     }
+     117         [ +  + ]:          2 :     if (spdm_response->header.param1 == 0) {
+     118                 :          1 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     119                 :          1 :         goto receive_done;
+     120                 :            :     }
+     121         [ -  + ]:          1 :     if (spdm_response_size < sizeof(spdm_supported_event_types_response_t)) {
+     122                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     123                 :          0 :         goto receive_done;
+     124                 :            :     }
+     125         [ -  + ]:          1 :     if (spdm_response->supported_event_groups_list_len == 0) {
+     126                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     127                 :          0 :         goto receive_done;
+     128         [ -  + ]:          1 :     } else if (spdm_response->supported_event_groups_list_len > *supported_event_groups_list_len) {
+     129                 :          0 :         status = LIBSPDM_STATUS_BUFFER_TOO_SMALL;
+     130                 :          0 :         goto receive_done;
+     131                 :            :     }
+     132                 :          1 :     if (spdm_response_size != sizeof(spdm_supported_event_types_response_t) +
+     133         [ -  + ]:          1 :         (uint64_t)spdm_response->supported_event_groups_list_len) {
+     134                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     135                 :          0 :         goto receive_done;
+     136                 :            :     }
+     137                 :            : 
+     138                 :            :     /* -=[Process Response Phase]=- */
+     139                 :          1 :     *event_group_count = spdm_response->header.param1;
+     140                 :          1 :     libspdm_copy_mem(supported_event_groups_list, *supported_event_groups_list_len,
+     141                 :          1 :                      spdm_response + 1, spdm_response->supported_event_groups_list_len);
+     142                 :          1 :     *supported_event_groups_list_len = spdm_response->supported_event_groups_list_len;
+     143                 :            : 
+     144                 :          2 : receive_done:
+     145                 :          2 :     libspdm_release_receiver_buffer(spdm_context);
+     146                 :            : 
+     147                 :          2 :     return status;
+     148                 :            : }
+     149                 :            : 
+     150                 :          2 : libspdm_return_t libspdm_get_event_types(void *spdm_context,
+     151                 :            :                                          uint32_t session_id,
+     152                 :            :                                          uint8_t *event_group_count,
+     153                 :            :                                          uint32_t *supported_event_groups_list_len,
+     154                 :            :                                          void *supported_event_groups_list)
+     155                 :            : {
+     156                 :            :     size_t retry;
+     157                 :            :     uint64_t retry_delay_time;
+     158                 :            :     libspdm_return_t status;
+     159                 :            :     libspdm_context_t *context;
+     160                 :            : 
+     161                 :          2 :     context = spdm_context;
+     162                 :          2 :     context->crypto_request = true;
+     163                 :          2 :     retry = context->retry_times;
+     164                 :          2 :     retry_delay_time = context->retry_delay_time;
+     165                 :            :     do {
+     166                 :          2 :         status = libspdm_try_get_event_types(context,
+     167                 :            :                                              session_id,
+     168                 :            :                                              event_group_count,
+     169                 :            :                                              supported_event_groups_list_len,
+     170                 :            :                                              supported_event_groups_list);
+     171         [ +  - ]:          2 :         if (status != LIBSPDM_STATUS_BUSY_PEER) {
+     172                 :          2 :             return status;
+     173                 :            :         }
+     174                 :            : 
+     175                 :          0 :         libspdm_sleep(retry_delay_time);
+     176         [ #  # ]:          0 :     } while (retry-- != 0);
+     177                 :            : 
+     178                 :          0 :     return status;
+     179                 :            : }
+     180                 :            : 
+     181                 :            : #endif /* LIBSPDM_EVENT_RECIPIENT_SUPPORT */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_get_key_pair_info.c.func-sort-c.html b/coverage_log/library/spdm_requester_lib/libspdm_req_get_key_pair_info.c.func-sort-c.html new file mode 100644 index 00000000000..485c61a81c1 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_get_key_pair_info.c.func-sort-c.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_get_key_pair_info.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_get_key_pair_info.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:7612361.8 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:296643.9 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_key_pair_info2
libspdm_try_get_key_pair_info2
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_get_key_pair_info.c.func.html b/coverage_log/library/spdm_requester_lib/libspdm_req_get_key_pair_info.c.func.html new file mode 100644 index 00000000000..f33babc9c39 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_get_key_pair_info.c.func.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_get_key_pair_info.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_get_key_pair_info.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:7612361.8 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:296643.9 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_key_pair_info2
libspdm_try_get_key_pair_info2
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_get_key_pair_info.c.gcov.html b/coverage_log/library/spdm_requester_lib/libspdm_req_get_key_pair_info.c.gcov.html new file mode 100644 index 00000000000..5e6009613bb --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_get_key_pair_info.c.gcov.html @@ -0,0 +1,359 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_get_key_pair_info.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_get_key_pair_info.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:7612361.8 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:296643.9 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2024 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_GET_KEY_PAIR_INFO_CAP
+      10                 :            : 
+      11                 :            : typedef struct {
+      12                 :            :     spdm_message_header_t header;
+      13                 :            :     uint8_t total_key_pairs;
+      14                 :            :     uint8_t key_pair_id;
+      15                 :            :     uint16_t capabilities;
+      16                 :            :     uint16_t key_usage_capabilities;
+      17                 :            :     uint16_t current_key_usage;
+      18                 :            :     uint32_t asym_algo_capabilities;
+      19                 :            :     uint32_t current_asym_algo;
+      20                 :            :     uint16_t public_key_info_len;
+      21                 :            :     uint8_t assoc_cert_slot_mask;
+      22                 :            :     uint8_t public_key_info[SPDM_MAX_PUBLIC_KEY_INFO_LEN];
+      23                 :            : } libspdm_key_pair_info_response_max_t;
+      24                 :            : 
+      25                 :            : /**
+      26                 :            :  * This function sends GET_KEY_PAIR_INFO and receives KEY_PAIR_INFO *
+      27                 :            :  *
+      28                 :            :  * @param  context             A pointer to the SPDM context.
+      29                 :            :  *
+      30                 :            :  **/
+      31                 :          2 : static libspdm_return_t libspdm_try_get_key_pair_info(libspdm_context_t *spdm_context,
+      32                 :            :                                                       const uint32_t *session_id,
+      33                 :            :                                                       uint8_t key_pair_id,
+      34                 :            :                                                       uint8_t *total_key_pairs,
+      35                 :            :                                                       uint16_t *capabilities,
+      36                 :            :                                                       uint16_t *key_usage_capabilities,
+      37                 :            :                                                       uint16_t *current_key_usage,
+      38                 :            :                                                       uint32_t *asym_algo_capabilities,
+      39                 :            :                                                       uint32_t *current_asym_algo,
+      40                 :            :                                                       uint8_t *assoc_cert_slot_mask,
+      41                 :            :                                                       uint16_t *public_key_info_len,
+      42                 :            :                                                       void *public_key_info
+      43                 :            :                                                       )
+      44                 :            : {
+      45                 :            :     libspdm_return_t status;
+      46                 :            :     spdm_get_key_pair_info_request_t *spdm_request;
+      47                 :            :     size_t spdm_request_size;
+      48                 :            :     libspdm_key_pair_info_response_max_t *spdm_response;
+      49                 :            :     size_t spdm_response_size;
+      50                 :            :     uint8_t *message;
+      51                 :            :     size_t message_size;
+      52                 :            :     size_t transport_header_size;
+      53                 :            :     libspdm_session_info_t *session_info;
+      54                 :            :     libspdm_session_state_t session_state;
+      55                 :            : 
+      56                 :            :     /* -=[Check Parameters Phase]=- */
+      57         [ -  + ]:          2 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_13) {
+      58                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+      59                 :            :     }
+      60                 :            : 
+      61         [ -  + ]:          2 :     if (key_pair_id == 0) {
+      62                 :          0 :         return LIBSPDM_STATUS_INVALID_PARAMETER;
+      63                 :            :     }
+      64                 :            : 
+      65                 :            :     /* -=[Verify State Phase]=- */
+      66         [ -  + ]:          2 :     if (!libspdm_is_capabilities_flag_supported(
+      67                 :            :             spdm_context, true, 0,
+      68                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_GET_KEY_PAIR_INFO_CAP)) {
+      69                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+      70                 :            :     }
+      71         [ -  + ]:          2 :     if (spdm_context->connection_info.connection_state < LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
+      72                 :          0 :         return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+      73                 :            :     }
+      74                 :            : 
+      75                 :          2 :     session_info = NULL;
+      76         [ -  + ]:          2 :     if (session_id != NULL) {
+      77                 :          0 :         session_info = libspdm_get_session_info_via_session_id(spdm_context, *session_id);
+      78         [ #  # ]:          0 :         if (session_info == NULL) {
+      79                 :          0 :             return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+      80                 :            :         }
+      81                 :          0 :         session_state = libspdm_secured_message_get_session_state(
+      82                 :            :             session_info->secured_message_context);
+      83         [ #  # ]:          0 :         if (session_state != LIBSPDM_SESSION_STATE_ESTABLISHED) {
+      84                 :          0 :             return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+      85                 :            :         }
+      86                 :            :     }
+      87                 :            : 
+      88                 :            :     /* -=[Construct Request Phase]=- */
+      89                 :          2 :     transport_header_size = spdm_context->local_context.capability.transport_header_size;
+      90                 :          2 :     status = libspdm_acquire_sender_buffer (spdm_context, &message_size, (void **)&message);
+      91         [ -  + ]:          2 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+      92                 :          0 :         return status;
+      93                 :            :     }
+      94         [ -  + ]:          2 :     LIBSPDM_ASSERT (message_size >= transport_header_size +
+      95                 :            :                     spdm_context->local_context.capability.transport_tail_size);
+      96                 :          2 :     spdm_request = (void *)(message + transport_header_size);
+      97                 :          2 :     spdm_request_size = message_size - transport_header_size -
+      98                 :          2 :                         spdm_context->local_context.capability.transport_tail_size;
+      99                 :            : 
+     100         [ -  + ]:          2 :     LIBSPDM_ASSERT(spdm_request_size >= sizeof(spdm_get_key_pair_info_request_t));
+     101                 :          2 :     spdm_request->header.spdm_version = libspdm_get_connection_version (spdm_context);
+     102                 :          2 :     spdm_request->header.request_response_code = SPDM_GET_KEY_PAIR_INFO;
+     103                 :          2 :     spdm_request->header.param1 = 0;
+     104                 :          2 :     spdm_request->header.param2 = 0;
+     105                 :          2 :     spdm_request->key_pair_id = key_pair_id;
+     106                 :          2 :     spdm_request_size = sizeof(spdm_get_key_pair_info_request_t);
+     107                 :            : 
+     108                 :            :     /* -=[Send Request Phase]=- */
+     109                 :          2 :     status = libspdm_send_spdm_request(spdm_context, session_id, spdm_request_size, spdm_request);
+     110         [ +  + ]:          2 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     111                 :          1 :         libspdm_release_sender_buffer (spdm_context);
+     112                 :          1 :         return status;
+     113                 :            :     }
+     114                 :          1 :     libspdm_release_sender_buffer (spdm_context);
+     115                 :          1 :     spdm_request = (void *)spdm_context->last_spdm_request;
+     116                 :            : 
+     117                 :            :     /* -=[Receive Response Phase]=- */
+     118                 :          1 :     status = libspdm_acquire_receiver_buffer (spdm_context, &message_size, (void **)&message);
+     119         [ -  + ]:          1 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     120                 :          0 :         return status;
+     121                 :            :     }
+     122         [ -  + ]:          1 :     LIBSPDM_ASSERT (message_size >= transport_header_size);
+     123                 :          1 :     spdm_response = (void *)(message);
+     124                 :          1 :     spdm_response_size = message_size;
+     125                 :            : 
+     126                 :          1 :     status = libspdm_receive_spdm_response(
+     127                 :            :         spdm_context, session_id, &spdm_response_size, (void **)&spdm_response);
+     128         [ -  + ]:          1 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     129                 :          0 :         goto receive_done;
+     130                 :            :     }
+     131                 :            : 
+     132                 :            :     /* -=[Validate Response Phase]=- */
+     133         [ -  + ]:          1 :     if (spdm_response_size < sizeof(spdm_message_header_t)) {
+     134                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     135                 :          0 :         goto receive_done;
+     136                 :            :     }
+     137         [ -  + ]:          1 :     if (spdm_response->header.spdm_version != spdm_request->header.spdm_version) {
+     138                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     139                 :          0 :         goto receive_done;
+     140                 :            :     }
+     141         [ -  + ]:          1 :     if (spdm_response->header.request_response_code == SPDM_ERROR) {
+     142                 :          0 :         status = libspdm_handle_error_response_main(
+     143                 :            :             spdm_context, session_id,
+     144                 :            :             &spdm_response_size,
+     145                 :            :             (void **)&spdm_response, SPDM_GET_KEY_PAIR_INFO, SPDM_KEY_PAIR_INFO);
+     146         [ #  # ]:          0 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     147                 :          0 :             goto receive_done;
+     148                 :            :         }
+     149         [ -  + ]:          1 :     } else if (spdm_response->header.request_response_code != SPDM_KEY_PAIR_INFO) {
+     150                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     151                 :          0 :         goto receive_done;
+     152                 :            :     }
+     153                 :            : 
+     154         [ +  - ]:          1 :     if ((spdm_response->key_pair_id != key_pair_id) ||
+     155         [ -  + ]:          1 :         (spdm_response->key_pair_id > (spdm_response->total_key_pairs))) {
+     156                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     157                 :          0 :         goto receive_done;
+     158                 :            :     }
+     159                 :            : 
+     160         [ -  + ]:          1 :     if (spdm_response_size < sizeof(spdm_key_pair_info_response_t)) {
+     161                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     162                 :          0 :         goto receive_done;
+     163                 :            :     }
+     164                 :            : 
+     165                 :          1 :     if (spdm_response_size < sizeof(spdm_key_pair_info_response_t) +
+     166         [ -  + ]:          1 :         spdm_response->public_key_info_len) {
+     167                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     168                 :          0 :         goto receive_done;
+     169                 :            :     }
+     170                 :          1 :     spdm_response_size = sizeof(spdm_key_pair_info_response_t) + spdm_response->public_key_info_len;
+     171                 :            : 
+     172                 :            :     /* -=[Process Response Phase]=- */
+     173                 :          1 :     *key_usage_capabilities = (spdm_response->key_usage_capabilities) & SPDM_KEY_USAGE_BIT_MASK;
+     174         [ -  + ]:          1 :     if (*key_usage_capabilities == 0) {
+     175                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     176                 :          0 :         goto receive_done;
+     177                 :            :     }
+     178                 :          1 :     *current_key_usage = (spdm_response->current_key_usage) & SPDM_KEY_USAGE_BIT_MASK;
+     179         [ -  + ]:          1 :     if ((*key_usage_capabilities | *current_key_usage) != *key_usage_capabilities) {
+     180                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     181                 :          0 :         goto receive_done;
+     182                 :            :     }
+     183                 :            : 
+     184                 :          1 :     *asym_algo_capabilities = (spdm_response->asym_algo_capabilities) &
+     185                 :            :                               SPDM_KEY_PAIR_ASYM_ALGO_CAP_MASK;
+     186         [ -  + ]:          1 :     if (*asym_algo_capabilities == 0) {
+     187                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     188                 :          0 :         goto receive_done;
+     189                 :            :     }
+     190                 :          1 :     *current_asym_algo = (spdm_response->current_asym_algo) & SPDM_KEY_PAIR_ASYM_ALGO_CAP_MASK;
+     191         [ -  + ]:          1 :     if (!libspdm_onehot0(*current_asym_algo)) {
+     192                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     193                 :          0 :         goto receive_done;
+     194                 :            :     }
+     195         [ -  + ]:          1 :     if ((*asym_algo_capabilities | *current_asym_algo) != *asym_algo_capabilities) {
+     196                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     197                 :          0 :         goto receive_done;
+     198                 :            :     }
+     199                 :            : 
+     200                 :            :     /*If responder doesn't support SET_KEY_PAIR_INFO_CAP,the capabilities should be 0*/
+     201         [ -  + ]:          1 :     if ((!libspdm_is_capabilities_flag_supported(
+     202                 :            :              spdm_context, true, 0,
+     203                 :          0 :              SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_KEY_PAIR_INFO_CAP)) &&
+     204         [ #  # ]:          0 :         ((spdm_response->capabilities & SPDM_KEY_PAIR_CAP_MASK) != 0)) {
+     205                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     206                 :          0 :         goto receive_done;
+     207                 :            :     }
+     208                 :            : 
+     209                 :          1 :     *total_key_pairs = spdm_response->total_key_pairs;
+     210                 :          1 :     *capabilities = spdm_response->capabilities & SPDM_KEY_PAIR_CAP_MASK;
+     211                 :            : 
+     212         [ -  + ]:          1 :     if (*public_key_info_len < spdm_response->public_key_info_len) {
+     213                 :          0 :         status = LIBSPDM_STATUS_BUFFER_FULL;
+     214                 :          0 :         goto receive_done;
+     215                 :            :     }
+     216                 :          1 :     *public_key_info_len = spdm_response->public_key_info_len;
+     217                 :          1 :     *assoc_cert_slot_mask = spdm_response->assoc_cert_slot_mask;
+     218                 :            : 
+     219                 :          1 :     libspdm_copy_mem(public_key_info,
+     220                 :          1 :                      spdm_response->public_key_info_len,
+     221                 :          1 :                      spdm_response->public_key_info,
+     222                 :          1 :                      spdm_response->public_key_info_len);
+     223                 :            : 
+     224                 :          1 :     status = LIBSPDM_STATUS_SUCCESS;
+     225                 :            : 
+     226                 :            :     /* -=[Log Message Phase]=- */
+     227                 :            :     #if LIBSPDM_ENABLE_MSG_LOG
+     228                 :          1 :     libspdm_append_msg_log(spdm_context, spdm_response, spdm_response_size);
+     229                 :            :     #endif /* LIBSPDM_ENABLE_MSG_LOG */
+     230                 :            : 
+     231                 :          1 : receive_done:
+     232                 :          1 :     libspdm_release_receiver_buffer (spdm_context);
+     233                 :          1 :     return status;
+     234                 :            : }
+     235                 :            : 
+     236                 :          2 : libspdm_return_t libspdm_get_key_pair_info(void *spdm_context, const uint32_t *session_id,
+     237                 :            :                                            uint8_t key_pair_id, uint8_t *total_key_pairs,
+     238                 :            :                                            uint16_t *capabilities,
+     239                 :            :                                            uint16_t *key_usage_capabilities,
+     240                 :            :                                            uint16_t *current_key_usage,
+     241                 :            :                                            uint32_t *asym_algo_capabilities,
+     242                 :            :                                            uint32_t *current_asym_algo,
+     243                 :            :                                            uint8_t *assoc_cert_slot_mask,
+     244                 :            :                                            uint16_t *public_key_info_len,
+     245                 :            :                                            void *public_key_info
+     246                 :            :                                            )
+     247                 :            : {
+     248                 :            :     libspdm_context_t *context;
+     249                 :            :     size_t retry;
+     250                 :            :     uint64_t retry_delay_time;
+     251                 :            :     libspdm_return_t status;
+     252                 :            : 
+     253                 :          2 :     context = spdm_context;
+     254                 :          2 :     context->crypto_request = true;
+     255                 :          2 :     retry = context->retry_times;
+     256                 :          2 :     retry_delay_time = context->retry_delay_time;
+     257                 :            :     do {
+     258                 :          2 :         status = libspdm_try_get_key_pair_info(context, session_id, key_pair_id,
+     259                 :            :                                                total_key_pairs, capabilities,
+     260                 :            :                                                key_usage_capabilities, current_key_usage,
+     261                 :            :                                                asym_algo_capabilities, current_asym_algo,
+     262                 :            :                                                assoc_cert_slot_mask, public_key_info_len,
+     263                 :            :                                                public_key_info);
+     264         [ +  - ]:          2 :         if (status != LIBSPDM_STATUS_BUSY_PEER) {
+     265                 :          2 :             return status;
+     266                 :            :         }
+     267                 :            : 
+     268                 :          0 :         libspdm_sleep(retry_delay_time);
+     269         [ #  # ]:          0 :     } while (retry-- != 0);
+     270                 :            : 
+     271                 :          0 :     return status;
+     272                 :            : }
+     273                 :            : 
+     274                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_GET_KEY_PAIR_INFO_CAP */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_get_measurement_extension_log.c.func-sort-c.html b/coverage_log/library/spdm_requester_lib/libspdm_req_get_measurement_extension_log.c.func-sort-c.html new file mode 100644 index 00000000000..452d90e7a62 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_get_measurement_extension_log.c.func-sort-c.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_get_measurement_extension_log.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_get_measurement_extension_log.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:10114470.1 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:376854.4 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_measurement_extension_log9
libspdm_get_measurement_extension_log_choose_length9
libspdm_try_get_measurement_extension_log9
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_get_measurement_extension_log.c.func.html b/coverage_log/library/spdm_requester_lib/libspdm_req_get_measurement_extension_log.c.func.html new file mode 100644 index 00000000000..6897fdae74b --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_get_measurement_extension_log.c.func.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_get_measurement_extension_log.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_get_measurement_extension_log.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:10114470.1 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:376854.4 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_measurement_extension_log9
libspdm_get_measurement_extension_log_choose_length9
libspdm_try_get_measurement_extension_log9
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_get_measurement_extension_log.c.gcov.html b/coverage_log/library/spdm_requester_lib/libspdm_req_get_measurement_extension_log.c.gcov.html new file mode 100644 index 00000000000..ec0005154f8 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_get_measurement_extension_log.c.gcov.html @@ -0,0 +1,382 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_get_measurement_extension_log.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_get_measurement_extension_log.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:10114470.1 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:376854.4 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2024 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_MEL_CAP
+      10                 :            : 
+      11                 :            : #pragma pack(1)
+      12                 :            : typedef struct {
+      13                 :            :     spdm_message_header_t header;
+      14                 :            :     uint32_t portion_length;
+      15                 :            :     uint32_t remainder_length;
+      16                 :            :     uint8_t measure_exten_log[LIBSPDM_MAX_MEL_BLOCK_LEN];
+      17                 :            : } libspdm_measurement_extension_log_response_max_t;
+      18                 :            : #pragma pack()
+      19                 :            : 
+      20                 :            : /**
+      21                 :            :  * This function sends GET_MEASUREMENT_EXTENSION_LOG and receives MEASUREMENT_EXTENSION_LOG.
+      22                 :            :  *
+      23                 :            :  * @param  spdm_context               A pointer to the SPDM context.
+      24                 :            :  * @param  session_id                 Indicates if it is a secured message protected via SPDM session.
+      25                 :            :  *                                    If session_id is NULL, it is a normal message.
+      26                 :            :  *                                    If session_id is not NULL, it is a secured message.
+      27                 :            :  * @param  length                     The len of get MEL in every time.
+      28                 :            :  * @param  mel_size                   On input, indicate the size in bytes of the destination buffer to store.
+      29                 :            :  *                                    On output, indicate the size in bytes of the MEL.
+      30                 :            :  * @param  measure_exten_log          A pointer to a destination buffer to store the MEL.
+      31                 :            :  *
+      32                 :            :  **/
+      33                 :          9 : static libspdm_return_t libspdm_try_get_measurement_extension_log(libspdm_context_t *spdm_context,
+      34                 :            :                                                                   const uint32_t *session_id,
+      35                 :            :                                                                   uint32_t length,
+      36                 :            :                                                                   size_t *mel_size,
+      37                 :            :                                                                   void *measure_exten_log)
+      38                 :            : {
+      39                 :            :     libspdm_return_t status;
+      40                 :            :     spdm_get_measurement_extension_log_request_t *spdm_request;
+      41                 :            :     size_t spdm_request_size;
+      42                 :            :     libspdm_measurement_extension_log_response_max_t *spdm_response;
+      43                 :            :     size_t spdm_response_size;
+      44                 :            :     uint32_t total_responder_mel_buffer_length;
+      45                 :            :     size_t mel_capacity;
+      46                 :            :     size_t mel_size_internal;
+      47                 :            :     uint32_t remainder_length;
+      48                 :            :     uint8_t *message;
+      49                 :            :     size_t message_size;
+      50                 :            :     size_t transport_header_size;
+      51                 :            :     libspdm_session_info_t *session_info;
+      52                 :            :     libspdm_session_state_t session_state;
+      53                 :            :     spdm_measurement_extension_log_dmtf_t *measurement_extension_log;
+      54                 :            : 
+      55                 :            :     /* -=[Check Parameters Phase]=- */
+      56         [ -  + ]:          9 :     LIBSPDM_ASSERT(mel_size != NULL);
+      57         [ -  + ]:          9 :     LIBSPDM_ASSERT(*mel_size > 0);
+      58         [ -  + ]:          9 :     LIBSPDM_ASSERT(measure_exten_log != NULL);
+      59                 :            : 
+      60                 :            :     /* -=[Verify State Phase]=- */
+      61         [ -  + ]:          9 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_13) {
+      62                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+      63                 :            :     }
+      64                 :            : 
+      65         [ -  + ]:          9 :     if (!libspdm_is_capabilities_flag_supported(
+      66                 :            :             spdm_context, true, 0,
+      67                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEL_CAP)) {
+      68                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+      69                 :            :     }
+      70         [ -  + ]:          9 :     if (spdm_context->connection_info.connection_state < LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
+      71                 :          0 :         return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+      72                 :            :     }
+      73                 :            : 
+      74                 :          9 :     session_info = NULL;
+      75         [ -  + ]:          9 :     if (session_id != NULL) {
+      76                 :          0 :         session_info = libspdm_get_session_info_via_session_id(spdm_context, *session_id);
+      77         [ #  # ]:          0 :         if (session_info == NULL) {
+      78                 :          0 :             LIBSPDM_ASSERT(false);
+      79                 :          0 :             return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+      80                 :            :         }
+      81                 :          0 :         session_state = libspdm_secured_message_get_session_state(
+      82                 :            :             session_info->secured_message_context);
+      83         [ #  # ]:          0 :         if (session_state != LIBSPDM_SESSION_STATE_ESTABLISHED) {
+      84                 :          0 :             return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+      85                 :            :         }
+      86                 :            :     }
+      87                 :            : 
+      88                 :          9 :     libspdm_reset_message_buffer_via_request_code(spdm_context, session_info,
+      89                 :            :                                                   SPDM_GET_MEASUREMENT_EXTENSION_LOG);
+      90                 :            : 
+      91                 :          9 :     remainder_length = 0;
+      92                 :          9 :     total_responder_mel_buffer_length = 0;
+      93                 :          9 :     mel_capacity = *mel_size;
+      94                 :          9 :     mel_size_internal = 0;
+      95                 :            : 
+      96                 :          9 :     transport_header_size = spdm_context->local_context.capability.transport_header_size;
+      97                 :            : 
+      98                 :            :     do {
+      99                 :            :         /* -=[Construct Request Phase]=- */
+     100                 :         15 :         status = libspdm_acquire_sender_buffer (spdm_context, &message_size, (void **)&message);
+     101         [ -  + ]:         15 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     102                 :          0 :             return status;
+     103                 :            :         }
+     104         [ -  + ]:         15 :         LIBSPDM_ASSERT (message_size >= transport_header_size +
+     105                 :            :                         spdm_context->local_context.capability.transport_tail_size);
+     106                 :         15 :         spdm_request = (void *)(message + transport_header_size);
+     107                 :         15 :         spdm_request_size = message_size - transport_header_size -
+     108                 :         15 :                             spdm_context->local_context.capability.transport_tail_size;
+     109                 :            : 
+     110                 :         15 :         spdm_request->header.spdm_version = libspdm_get_connection_version (spdm_context);
+     111                 :         15 :         spdm_request->header.request_response_code = SPDM_GET_MEASUREMENT_EXTENSION_LOG;
+     112                 :         15 :         spdm_request->header.param1 = 0;
+     113                 :         15 :         spdm_request->header.param2 = 0;
+     114                 :         15 :         spdm_request->offset = (uint32_t)mel_size_internal;
+     115         [ +  + ]:         15 :         if (spdm_request->offset == 0) {
+     116                 :          9 :             spdm_request->length = length;
+     117                 :            :         } else {
+     118                 :          6 :             spdm_request->length = LIBSPDM_MIN(length, remainder_length);
+     119                 :            :         }
+     120                 :         15 :         spdm_request_size = sizeof(spdm_get_measurement_extension_log_request_t);
+     121                 :         15 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "request (offset 0x%x, size 0x%x):\n",
+     122                 :            :                        spdm_request->offset, spdm_request->length));
+     123                 :            : 
+     124                 :            :         /* -=[Send Request Phase]=- */
+     125                 :            :         status =
+     126                 :         15 :             libspdm_send_spdm_request(spdm_context, session_id, spdm_request_size, spdm_request);
+     127         [ +  + ]:         15 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     128                 :          1 :             libspdm_release_sender_buffer (spdm_context);
+     129                 :          1 :             status = LIBSPDM_STATUS_SEND_FAIL;
+     130                 :          1 :             goto done;
+     131                 :            :         }
+     132                 :         14 :         libspdm_release_sender_buffer (spdm_context);
+     133                 :         14 :         spdm_request = (void *)spdm_context->last_spdm_request;
+     134                 :            : 
+     135                 :            :         /* -=[Receive Response Phase]=- */
+     136                 :         14 :         status = libspdm_acquire_receiver_buffer (spdm_context, &message_size, (void **)&message);
+     137         [ -  + ]:         14 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     138                 :          0 :             return status;
+     139                 :            :         }
+     140         [ -  + ]:         14 :         LIBSPDM_ASSERT (message_size >= transport_header_size);
+     141                 :         14 :         spdm_response = (void *)(message);
+     142                 :         14 :         spdm_response_size = message_size;
+     143                 :            : 
+     144                 :         14 :         status = libspdm_receive_spdm_response(spdm_context, session_id,
+     145                 :            :                                                &spdm_response_size,
+     146                 :            :                                                (void **)&spdm_response);
+     147         [ -  + ]:         14 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     148                 :          0 :             libspdm_release_receiver_buffer (spdm_context);
+     149                 :          0 :             status = LIBSPDM_STATUS_RECEIVE_FAIL;
+     150                 :          0 :             goto done;
+     151                 :            :         }
+     152                 :            : 
+     153                 :            :         /* -=[Validate Response Phase]=- */
+     154         [ -  + ]:         14 :         if (spdm_response_size < sizeof(spdm_message_header_t)) {
+     155                 :          0 :             libspdm_release_receiver_buffer (spdm_context);
+     156                 :          0 :             status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     157                 :          0 :             goto done;
+     158                 :            :         }
+     159         [ -  + ]:         14 :         if (spdm_response->header.spdm_version != spdm_request->header.spdm_version) {
+     160                 :          0 :             libspdm_release_receiver_buffer (spdm_context);
+     161                 :          0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     162                 :          0 :             goto done;
+     163                 :            :         }
+     164         [ -  + ]:         14 :         if (spdm_response->header.request_response_code == SPDM_ERROR) {
+     165                 :          0 :             status = libspdm_handle_error_response_main(
+     166                 :            :                 spdm_context, session_id,
+     167                 :            :                 &spdm_response_size,
+     168                 :            :                 (void **)&spdm_response, SPDM_GET_MEASUREMENT_EXTENSION_LOG,
+     169                 :            :                 SPDM_MEASUREMENT_EXTENSION_LOG);
+     170         [ #  # ]:          0 :             if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     171                 :          0 :                 libspdm_release_receiver_buffer (spdm_context);
+     172                 :          0 :                 goto done;
+     173                 :            :             }
+     174         [ -  + ]:         14 :         } else if (spdm_response->header.request_response_code != SPDM_MEASUREMENT_EXTENSION_LOG) {
+     175                 :          0 :             libspdm_release_receiver_buffer (spdm_context);
+     176                 :          0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     177                 :          0 :             goto done;
+     178                 :            :         }
+     179         [ -  + ]:         14 :         if (spdm_response_size < sizeof(spdm_measurement_extension_log_response_t)) {
+     180                 :          0 :             libspdm_release_receiver_buffer (spdm_context);
+     181                 :          0 :             status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     182                 :          0 :             goto done;
+     183                 :            :         }
+     184         [ +  + ]:         14 :         if ((spdm_response->portion_length > spdm_request->length) ||
+     185         [ -  + ]:         13 :             (spdm_response->portion_length == 0)) {
+     186                 :          1 :             libspdm_release_receiver_buffer (spdm_context);
+     187                 :          1 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     188                 :          1 :             goto done;
+     189                 :            :         }
+     190                 :         13 :         if (spdm_response_size < sizeof(spdm_measurement_extension_log_response_t) +
+     191         [ -  + ]:         13 :             spdm_response->portion_length) {
+     192                 :          0 :             libspdm_release_receiver_buffer (spdm_context);
+     193                 :          0 :             status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     194                 :          0 :             goto done;
+     195                 :            :         }
+     196         [ -  + ]:         13 :         if (spdm_response->portion_length > 0xFFFFFFFF - spdm_request->offset) {
+     197                 :          0 :             libspdm_release_receiver_buffer (spdm_context);
+     198                 :          0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     199                 :          0 :             goto done;
+     200                 :            :         }
+     201                 :         13 :         if (spdm_response->remainder_length > 0xFFFFFFFF - spdm_request->offset -
+     202         [ +  + ]:         13 :             spdm_response->portion_length) {
+     203                 :          1 :             libspdm_release_receiver_buffer (spdm_context);
+     204                 :          1 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     205                 :          1 :             goto done;
+     206                 :            :         }
+     207         [ +  + ]:         12 :         if (spdm_request->offset == 0) {
+     208                 :          6 :             total_responder_mel_buffer_length = spdm_response->portion_length +
+     209                 :          6 :                                                 spdm_response->remainder_length;
+     210                 :          6 :         } else if (spdm_request->offset + spdm_response->portion_length +
+     211         [ +  + ]:          6 :                    spdm_response->remainder_length < total_responder_mel_buffer_length) {
+     212                 :          1 :             libspdm_release_receiver_buffer (spdm_context);
+     213                 :          1 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     214                 :          1 :             goto done;
+     215                 :            :         }
+     216                 :            : 
+     217                 :            :         /* -=[Process Response Phase]=- */
+     218                 :         11 :         remainder_length = spdm_response->remainder_length;
+     219                 :         11 :         spdm_response_size = sizeof(spdm_measurement_extension_log_response_t) +
+     220                 :         11 :                              spdm_response->portion_length;
+     221                 :            : 
+     222         [ -  + ]:         11 :         if (mel_size_internal + spdm_response->portion_length > mel_capacity) {
+     223                 :          0 :             libspdm_release_receiver_buffer (spdm_context);
+     224                 :          0 :             status = LIBSPDM_STATUS_BUFFER_FULL;
+     225                 :          0 :             goto done;
+     226                 :            :         }
+     227                 :            : 
+     228                 :         11 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "MEL (offset 0x%x, size 0x%x):\n",
+     229                 :            :                        spdm_request->offset, spdm_response->portion_length));
+     230                 :         11 :         LIBSPDM_INTERNAL_DUMP_HEX(spdm_response->measure_exten_log, spdm_response->portion_length);
+     231                 :            : 
+     232                 :         11 :         libspdm_copy_mem((uint8_t *)measure_exten_log + mel_size_internal,
+     233                 :            :                          mel_capacity - mel_size_internal,
+     234                 :         11 :                          spdm_response->measure_exten_log,
+     235                 :         11 :                          spdm_response->portion_length);
+     236                 :            : 
+     237                 :         11 :         mel_size_internal += spdm_response->portion_length;
+     238                 :            : 
+     239                 :            :         /* -=[Log Message Phase]=- */
+     240                 :            :         #if LIBSPDM_ENABLE_MSG_LOG
+     241                 :         11 :         libspdm_append_msg_log(spdm_context, spdm_response, spdm_response_size);
+     242                 :            :         #endif /* LIBSPDM_ENABLE_MSG_LOG */
+     243                 :            : 
+     244                 :         11 :         libspdm_release_receiver_buffer (spdm_context);
+     245                 :         11 :         measurement_extension_log = (spdm_measurement_extension_log_dmtf_t *)measure_exten_log;
+     246                 :         11 :     } while (mel_size_internal < sizeof(spdm_measurement_extension_log_dmtf_t) +
+     247         [ +  + ]:         11 :              measurement_extension_log->mel_entries_len);
+     248                 :            : 
+     249                 :          5 :     *mel_size = mel_size_internal;
+     250         [ -  + ]:          5 :     LIBSPDM_ASSERT(*mel_size <= SPDM_MAX_MEASUREMENT_EXTENSION_LOG_SIZE);
+     251                 :            : 
+     252                 :          5 :     status = LIBSPDM_STATUS_SUCCESS;
+     253                 :            : 
+     254                 :          9 : done:
+     255                 :          9 :     return status;
+     256                 :            : }
+     257                 :            : 
+     258                 :          9 : libspdm_return_t libspdm_get_measurement_extension_log(void *spdm_context,
+     259                 :            :                                                        const uint32_t *session_id,
+     260                 :            :                                                        size_t *mel_size,
+     261                 :            :                                                        void *measure_exten_log)
+     262                 :            : {
+     263                 :          9 :     return libspdm_get_measurement_extension_log_choose_length(spdm_context, session_id,
+     264                 :            :                                                                LIBSPDM_MAX_MEL_BLOCK_LEN,
+     265                 :            :                                                                mel_size, measure_exten_log);
+     266                 :            : }
+     267                 :            : 
+     268                 :          9 : libspdm_return_t libspdm_get_measurement_extension_log_choose_length(void *spdm_context,
+     269                 :            :                                                                      const uint32_t *session_id,
+     270                 :            :                                                                      uint32_t length,
+     271                 :            :                                                                      size_t *mel_size,
+     272                 :            :                                                                      void *measure_exten_log)
+     273                 :            : {
+     274                 :            :     libspdm_context_t *context;
+     275                 :            :     size_t retry;
+     276                 :            :     uint64_t retry_delay_time;
+     277                 :            :     libspdm_return_t status;
+     278                 :            : 
+     279                 :          9 :     context = spdm_context;
+     280                 :          9 :     context->crypto_request = true;
+     281                 :          9 :     retry = context->retry_times;
+     282                 :          9 :     retry_delay_time = context->retry_delay_time;
+     283                 :            :     do {
+     284                 :          9 :         status = libspdm_try_get_measurement_extension_log(context, session_id,
+     285                 :            :                                                            length,
+     286                 :            :                                                            mel_size, measure_exten_log);
+     287         [ +  - ]:          9 :         if (status != LIBSPDM_STATUS_BUSY_PEER) {
+     288                 :          9 :             return status;
+     289                 :            :         }
+     290                 :            : 
+     291                 :          0 :         libspdm_sleep(retry_delay_time);
+     292         [ #  # ]:          0 :     } while (retry-- != 0);
+     293                 :            : 
+     294                 :          0 :     return status;
+     295                 :            : }
+     296                 :            : 
+     297                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEL_CAP */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_get_measurements.c.func-sort-c.html b/coverage_log/library/spdm_requester_lib/libspdm_req_get_measurements.c.func-sort-c.html new file mode 100644 index 00000000000..f773edeb916 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_get_measurements.c.func-sort-c.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_get_measurements.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_get_measurements.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:29238875.3 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:16724667.9 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_measurement_ex2
libspdm_get_measurement_ex22
libspdm_verify_measurement_signature23
libspdm_get_measurement301
libspdm_try_get_measurement306
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_get_measurements.c.func.html b/coverage_log/library/spdm_requester_lib/libspdm_req_get_measurements.c.func.html new file mode 100644 index 00000000000..07cc61b0b94 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_get_measurements.c.func.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_get_measurements.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_get_measurements.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:29238875.3 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:16724667.9 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_measurement301
libspdm_get_measurement_ex2
libspdm_get_measurement_ex22
libspdm_try_get_measurement306
libspdm_verify_measurement_signature23
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_get_measurements.c.gcov.html b/coverage_log/library/spdm_requester_lib/libspdm_req_get_measurements.c.gcov.html new file mode 100644 index 00000000000..980e1b11881 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_get_measurements.c.gcov.html @@ -0,0 +1,922 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_get_measurements.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_get_measurements.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:29238875.3 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:16724667.9 %
+
+ + + + + + + + +

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

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_version38
libspdm_try_get_version39
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_get_version.c.func.html b/coverage_log/library/spdm_requester_lib/libspdm_req_get_version.c.func.html new file mode 100644 index 00000000000..887c27d4550 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_get_version.c.func.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_get_version.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_get_version.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:9711385.8 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:385076.0 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_version38
libspdm_try_get_version39
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_get_version.c.gcov.html b/coverage_log/library/spdm_requester_lib/libspdm_req_get_version.c.gcov.html new file mode 100644 index 00000000000..6be92d84ba8 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_get_version.c.gcov.html @@ -0,0 +1,320 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_get_version.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_get_version.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:9711385.8 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:385076.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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                 :            :     uint8_t reserved;
+      13                 :            :     uint8_t version_number_entry_count;
+      14                 :            :     spdm_version_number_t version_number_entry[LIBSPDM_MAX_VERSION_COUNT];
+      15                 :            : } libspdm_version_response_max_t;
+      16                 :            : #pragma pack()
+      17                 :            : 
+      18                 :            : /**
+      19                 :            :  * This function sends GET_VERSION and receives VERSION.
+      20                 :            :  *
+      21                 :            :  * @param  spdm_context         A pointer to the SPDM context.
+      22                 :            :  * @param  version_count        The number of SPDM versions that the Responder supports.
+      23                 :            :  * @param  VersionNumberEntries The list of SPDM versions that the Responder supports.
+      24                 :            :  *
+      25                 :            :  * @retval LIBSPDM_STATUS_SUCCESS
+      26                 :            :  *         GET_VERSION was sent and VERSION was received.
+      27                 :            :  * @retval LIBSPDM_STATUS_INVALID_MSG_SIZE
+      28                 :            :  *         The size of the VERSION response is invalid.
+      29                 :            :  * @retval LIBSPDM_STATUS_INVALID_MSG_FIELD
+      30                 :            :  *         The VERSION response contains one or more invalid fields.
+      31                 :            :  * @retval LIBSPDM_STATUS_ERROR_PEER
+      32                 :            :  *         The Responder returned an unexpected error.
+      33                 :            :  * @retval LIBSPDM_STATUS_BUSY_PEER
+      34                 :            :  *         The Responder continually returned Busy error messages.
+      35                 :            :  * @retval LIBSPDM_STATUS_RESYNCH_PEER
+      36                 :            :  *         The Responder returned a RequestResynch error message.
+      37                 :            :  * @retval LIBSPDM_STATUS_NEGOTIATION_FAIL
+      38                 :            :  *         The Requester and Responder do not support a common SPDM version.
+      39                 :            :  **/
+      40                 :         39 : static libspdm_return_t libspdm_try_get_version(libspdm_context_t *spdm_context,
+      41                 :            :                                                 uint8_t *version_number_entry_count,
+      42                 :            :                                                 spdm_version_number_t *version_number_entry)
+      43                 :            : {
+      44                 :            :     libspdm_return_t status;
+      45                 :            :     bool result;
+      46                 :            :     spdm_get_version_request_t *spdm_request;
+      47                 :            :     size_t spdm_request_size;
+      48                 :            :     libspdm_version_response_max_t *spdm_response;
+      49                 :            :     size_t spdm_response_size;
+      50                 :            :     spdm_version_number_t common_version;
+      51                 :            :     uint8_t *message;
+      52                 :            :     size_t message_size;
+      53                 :            :     size_t transport_header_size;
+      54                 :            : 
+      55                 :            :     /* -=[Set State Phase]=- */
+      56                 :         39 :     libspdm_reset_message_a(spdm_context);
+      57                 :         39 :     libspdm_reset_message_d(spdm_context);
+      58                 :         39 :     libspdm_reset_message_b(spdm_context);
+      59                 :         39 :     libspdm_reset_message_c(spdm_context);
+      60                 :         39 :     libspdm_reset_context(spdm_context);
+      61                 :         39 :     libspdm_reset_message_buffer_via_request_code(spdm_context, NULL, SPDM_GET_VERSION);
+      62                 :            : 
+      63                 :            :     /* -=[Construct Request Phase]=- */
+      64                 :         39 :     transport_header_size = spdm_context->local_context.capability.transport_header_size;
+      65                 :         39 :     status = libspdm_acquire_sender_buffer (spdm_context, &message_size, (void **)&message);
+      66         [ +  + ]:         39 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+      67                 :          1 :         return status;
+      68                 :            :     }
+      69         [ -  + ]:         38 :     LIBSPDM_ASSERT (message_size >= transport_header_size +
+      70                 :            :                     spdm_context->local_context.capability.transport_tail_size);
+      71                 :         38 :     spdm_request = (void *)(message + transport_header_size);
+      72                 :         38 :     spdm_request_size = message_size - transport_header_size -
+      73                 :         38 :                         spdm_context->local_context.capability.transport_tail_size;
+      74                 :            : 
+      75         [ -  + ]:         38 :     LIBSPDM_ASSERT (spdm_request_size >= sizeof(spdm_get_version_request_t));
+      76                 :         38 :     spdm_request->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+      77                 :         38 :     spdm_request->header.request_response_code = SPDM_GET_VERSION;
+      78                 :         38 :     spdm_request->header.param1 = 0;
+      79                 :         38 :     spdm_request->header.param2 = 0;
+      80                 :         38 :     spdm_request_size = sizeof(spdm_get_version_request_t);
+      81                 :            : 
+      82                 :            :     /* -=[Send Request Phase]=- */
+      83                 :         38 :     status = libspdm_send_spdm_request(spdm_context, NULL, spdm_request_size, spdm_request);
+      84         [ +  + ]:         38 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+      85                 :          1 :         libspdm_release_sender_buffer (spdm_context);
+      86                 :          1 :         return status;
+      87                 :            :     }
+      88                 :         37 :     libspdm_release_sender_buffer (spdm_context);
+      89                 :         37 :     spdm_request = (void *)spdm_context->last_spdm_request;
+      90                 :            : 
+      91                 :            :     /* -=[Receive Response Phase]=- */
+      92                 :         37 :     status = libspdm_acquire_receiver_buffer (spdm_context, &message_size, (void **)&message);
+      93         [ +  + ]:         37 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+      94                 :          1 :         return status;
+      95                 :            :     }
+      96         [ -  + ]:         36 :     LIBSPDM_ASSERT (message_size >= transport_header_size);
+      97                 :         36 :     spdm_response = (void *)(message);
+      98                 :         36 :     spdm_response_size = message_size;
+      99                 :            : 
+     100                 :         36 :     status = libspdm_receive_spdm_response(spdm_context, NULL, &spdm_response_size,
+     101                 :            :                                            (void **)&spdm_response);
+     102         [ +  + ]:         36 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     103                 :          1 :         goto receive_done;
+     104                 :            :     }
+     105                 :            : 
+     106                 :            :     /* -=[Validate Response Phase]=- */
+     107         [ -  + ]:         35 :     if (spdm_response_size < sizeof(spdm_message_header_t)) {
+     108                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     109                 :          0 :         goto receive_done;
+     110                 :            :     }
+     111         [ +  + ]:         35 :     if (spdm_response->header.spdm_version != SPDM_MESSAGE_VERSION_10) {
+     112                 :          1 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     113                 :          1 :         goto receive_done;
+     114                 :            :     }
+     115         [ +  + ]:         34 :     if (spdm_response->header.request_response_code == SPDM_ERROR) {
+     116                 :            :         /* Responder shall not respond to the GET_VERSION request message with ErrorCode=ResponseNotReady.*/
+     117         [ +  + ]:         23 :         if (spdm_response->header.param1 == SPDM_ERROR_CODE_RESPONSE_NOT_READY) {
+     118                 :            :             /* Received an unexpected error message. */
+     119                 :          1 :             status = LIBSPDM_STATUS_ERROR_PEER;
+     120                 :          1 :             goto receive_done;
+     121                 :            :         }
+     122                 :         22 :         status = libspdm_handle_simple_error_response(spdm_context, spdm_response->header.param1);
+     123         [ +  - ]:         22 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     124                 :         22 :             goto receive_done;
+     125                 :            :         }
+     126         [ +  + ]:         11 :     } else if (spdm_response->header.request_response_code != SPDM_VERSION) {
+     127                 :          1 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     128                 :          1 :         goto receive_done;
+     129                 :            :     }
+     130         [ +  + ]:         10 :     if (spdm_response_size < sizeof(spdm_version_response_t)) {
+     131                 :          1 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     132                 :          1 :         goto receive_done;
+     133                 :            :     }
+     134         [ +  + ]:          9 :     if (spdm_response->version_number_entry_count > LIBSPDM_MAX_VERSION_COUNT) {
+     135                 :          1 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     136                 :          1 :         goto receive_done;
+     137                 :            :     }
+     138         [ +  + ]:          8 :     if (spdm_response->version_number_entry_count == 0) {
+     139                 :          1 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     140                 :          1 :         goto receive_done;
+     141                 :            :     }
+     142                 :          7 :     if (spdm_response_size < sizeof(spdm_version_response_t) +
+     143         [ +  + ]:          7 :         spdm_response->version_number_entry_count * sizeof(spdm_version_number_t)) {
+     144                 :          1 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     145                 :          1 :         goto receive_done;
+     146                 :            :     }
+     147                 :          6 :     spdm_response_size = sizeof(spdm_version_response_t) +
+     148                 :          6 :                          spdm_response->version_number_entry_count * sizeof(spdm_version_number_t);
+     149                 :            : 
+     150                 :            :     /* -=[Process Response Phase]=- */
+     151                 :          6 :     status = libspdm_append_message_a(spdm_context, spdm_request, spdm_request_size);
+     152         [ -  + ]:          6 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     153                 :          0 :         goto receive_done;
+     154                 :            :     }
+     155                 :            : 
+     156                 :          6 :     status = libspdm_append_message_a(spdm_context, spdm_response, spdm_response_size);
+     157         [ -  + ]:          6 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     158                 :          0 :         libspdm_reset_message_a(spdm_context);
+     159                 :          0 :         goto receive_done;
+     160                 :            :     }
+     161                 :            : 
+     162                 :          6 :     result = libspdm_negotiate_connection_version (
+     163                 :            :         &common_version,
+     164                 :          6 :         spdm_context->local_context.version.spdm_version,
+     165                 :          6 :         spdm_context->local_context.version.spdm_version_count,
+     166                 :          6 :         spdm_response->version_number_entry,
+     167                 :          6 :         spdm_response->version_number_entry_count);
+     168         [ +  + ]:          6 :     if (result == false) {
+     169                 :          1 :         libspdm_reset_message_a(spdm_context);
+     170                 :          1 :         status = LIBSPDM_STATUS_NEGOTIATION_FAIL;
+     171                 :          1 :         goto receive_done;
+     172                 :            :     }
+     173                 :            : 
+     174                 :          5 :     libspdm_copy_mem(&(spdm_context->connection_info.version),
+     175                 :            :                      sizeof(spdm_context->connection_info.version),
+     176                 :            :                      &(common_version), sizeof(spdm_version_number_t));
+     177                 :            : 
+     178   [ -  +  -  - ]:          5 :     if (version_number_entry_count != NULL && version_number_entry != NULL) {
+     179         [ #  # ]:          0 :         if (*version_number_entry_count < spdm_response->version_number_entry_count) {
+     180                 :          0 :             *version_number_entry_count = spdm_response->version_number_entry_count;
+     181                 :          0 :             libspdm_reset_message_a(spdm_context);
+     182                 :          0 :             status = LIBSPDM_STATUS_BUFFER_TOO_SMALL;
+     183                 :          0 :             goto receive_done;
+     184                 :            :         } else {
+     185                 :          0 :             *version_number_entry_count = spdm_response->version_number_entry_count;
+     186                 :          0 :             libspdm_copy_mem(version_number_entry,
+     187                 :          0 :                              spdm_response->version_number_entry_count *
+     188                 :            :                              sizeof(spdm_version_number_t),
+     189                 :          0 :                              spdm_response->version_number_entry,
+     190                 :          0 :                              spdm_response->version_number_entry_count *
+     191                 :            :                              sizeof(spdm_version_number_t));
+     192                 :          0 :             libspdm_version_number_sort (version_number_entry, *version_number_entry_count);
+     193                 :            :         }
+     194                 :            :     }
+     195                 :            : 
+     196                 :            :     /* -=[Update State Phase]=- */
+     197                 :          5 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+     198                 :          5 :     status = LIBSPDM_STATUS_SUCCESS;
+     199                 :            : 
+     200                 :            :     /* -=[Log Message Phase]=- */
+     201                 :            :     #if LIBSPDM_ENABLE_MSG_LOG
+     202                 :          5 :     libspdm_append_msg_log(spdm_context, spdm_response, spdm_response_size);
+     203                 :            :     #endif /* LIBSPDM_ENABLE_MSG_LOG */
+     204                 :            : 
+     205                 :            :     /*Set the role of device*/
+     206                 :          5 :     spdm_context->local_context.is_requester = true;
+     207                 :            : 
+     208                 :         36 : receive_done:
+     209                 :         36 :     libspdm_release_receiver_buffer (spdm_context);
+     210                 :         36 :     return status;
+     211                 :            : }
+     212                 :            : 
+     213                 :         38 : libspdm_return_t libspdm_get_version(libspdm_context_t *spdm_context,
+     214                 :            :                                      uint8_t *version_number_entry_count,
+     215                 :            :                                      spdm_version_number_t *version_number_entry)
+     216                 :            : {
+     217                 :            :     size_t retry;
+     218                 :            :     uint64_t retry_delay_time;
+     219                 :            :     libspdm_return_t status;
+     220                 :            : 
+     221                 :         38 :     spdm_context->crypto_request = false;
+     222                 :         38 :     retry = spdm_context->retry_times;
+     223                 :         38 :     retry_delay_time = spdm_context->retry_delay_time;
+     224                 :            :     do {
+     225                 :         39 :         status = libspdm_try_get_version(spdm_context,
+     226                 :            :                                          version_number_entry_count, version_number_entry);
+     227         [ +  + ]:         39 :         if (status != LIBSPDM_STATUS_BUSY_PEER) {
+     228                 :         37 :             return status;
+     229                 :            :         }
+     230                 :            : 
+     231                 :          2 :         libspdm_sleep(retry_delay_time);
+     232         [ +  + ]:          2 :     } while (retry-- != 0);
+     233                 :            : 
+     234                 :          1 :     return status;
+     235                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_handle_error_response.c.func-sort-c.html b/coverage_log/library/spdm_requester_lib/libspdm_req_handle_error_response.c.func-sort-c.html new file mode 100644 index 00000000000..36e75dfacea --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_handle_error_response.c.func-sort-c.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_handle_error_response.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_handle_error_response.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:14419275.0 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:7211662.1 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_handle_error_large_response5
libspdm_handle_response_not_ready27
libspdm_requester_respond_if_ready27
libspdm_handle_error_response_main362
libspdm_handle_simple_error_response396
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_handle_error_response.c.func.html b/coverage_log/library/spdm_requester_lib/libspdm_req_handle_error_response.c.func.html new file mode 100644 index 00000000000..0a083327998 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_handle_error_response.c.func.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_handle_error_response.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_handle_error_response.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:14419275.0 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:7211662.1 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_handle_error_large_response5
libspdm_handle_error_response_main362
libspdm_handle_response_not_ready27
libspdm_handle_simple_error_response396
libspdm_requester_respond_if_ready27
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_handle_error_response.c.gcov.html b/coverage_log/library/spdm_requester_lib/libspdm_req_handle_error_response.c.gcov.html new file mode 100644 index 00000000000..1d1993ac935 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_handle_error_response.c.gcov.html @@ -0,0 +1,523 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_handle_error_response.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_handle_error_response.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:14419275.0 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:7211662.1 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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_RESPOND_IF_READY_SUPPORT
+      10                 :            : /**
+      11                 :            :  * This function sends RESPOND_IF_READY and receives an expected SPDM response.
+      12                 :            :  *
+      13                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+      14                 :            :  * @param  response_size                 The size of the response.
+      15                 :            :  *                                     On input, it means the size in bytes of response data buffer.
+      16                 :            :  *                                     On output, it means the size in bytes of copied response data buffer if RETURN_SUCCESS is returned.
+      17                 :            :  * @param  response                     The SPDM response message.
+      18                 :            :  * @param  expected_response_code         Indicate the expected response code.
+      19                 :            :  *
+      20                 :            :  * @retval RETURN_SUCCESS               The RESPOND_IF_READY is sent and an expected SPDM response is received.
+      21                 :            :  * @retval RETURN_DEVICE_ERROR          A device error occurs when communicates with the device.
+      22                 :            :  **/
+      23                 :         27 : static libspdm_return_t libspdm_requester_respond_if_ready(libspdm_context_t *spdm_context,
+      24                 :            :                                                            const uint32_t *session_id,
+      25                 :            :                                                            size_t *response_size,
+      26                 :            :                                                            void **response,
+      27                 :            :                                                            uint8_t expected_response_code)
+      28                 :            : {
+      29                 :            :     libspdm_return_t status;
+      30                 :            :     spdm_response_if_ready_request_t *spdm_request;
+      31                 :            :     size_t spdm_request_size;
+      32                 :            :     spdm_message_header_t *spdm_response;
+      33                 :            :     uint8_t *message;
+      34                 :            :     size_t message_size;
+      35                 :            :     size_t transport_header_size;
+      36                 :            : 
+      37                 :            :     /* the response might be in response buffer in normal SPDM message
+      38                 :            :      * or it is in scratch buffer in case of secure SPDM message
+      39                 :            :      * the response buffer is in acquired state, so we release it*/
+      40                 :         27 :     libspdm_release_receiver_buffer (spdm_context);
+      41                 :            : 
+      42                 :            :     /* now we can get sender buffer */
+      43                 :         27 :     transport_header_size = spdm_context->local_context.capability.transport_header_size;
+      44                 :         27 :     status = libspdm_acquire_sender_buffer (spdm_context, &message_size, (void **)&message);
+      45         [ -  + ]:         27 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+      46                 :          0 :         return status;
+      47                 :            :     }
+      48         [ -  + ]:         27 :     LIBSPDM_ASSERT (message_size >= transport_header_size +
+      49                 :            :                     spdm_context->local_context.capability.transport_tail_size);
+      50                 :         27 :     spdm_request = (void *)(message + transport_header_size);
+      51                 :         27 :     spdm_request_size = message_size - transport_header_size -
+      52                 :         27 :                         spdm_context->local_context.capability.transport_tail_size;
+      53                 :            : 
+      54         [ -  + ]:         27 :     LIBSPDM_ASSERT (spdm_request_size >= sizeof(spdm_response_if_ready_request_t));
+      55                 :         27 :     spdm_context->crypto_request = true;
+      56                 :         27 :     spdm_request->header.spdm_version = libspdm_get_connection_version (spdm_context);
+      57                 :         27 :     spdm_request->header.request_response_code = SPDM_RESPOND_IF_READY;
+      58                 :         27 :     spdm_request->header.param1 = spdm_context->error_data.request_code;
+      59                 :         27 :     spdm_request->header.param2 = spdm_context->error_data.token;
+      60                 :         27 :     spdm_request_size = sizeof(spdm_response_if_ready_request_t);
+      61                 :         27 :     status = libspdm_send_spdm_request(spdm_context, session_id, spdm_request_size, spdm_request);
+      62         [ -  + ]:         27 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+      63                 :          0 :         libspdm_release_sender_buffer (spdm_context);
+      64                 :            :         /* need acquire response buffer, so that the caller can release it */
+      65                 :          0 :         status = libspdm_acquire_receiver_buffer (spdm_context, response_size, response);
+      66                 :          0 :         return status;
+      67                 :            :     }
+      68                 :         27 :     libspdm_release_sender_buffer (spdm_context);
+      69                 :         27 :     spdm_request = (void *)spdm_context->last_spdm_request;
+      70                 :            : 
+      71                 :            :     /* receive
+      72                 :            :      * do not release response buffer in case of error, because caller will release it*/
+      73                 :            : 
+      74                 :         27 :     status = libspdm_acquire_receiver_buffer (spdm_context, response_size, response);
+      75         [ -  + ]:         27 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+      76                 :          0 :         return status;
+      77                 :            :     }
+      78         [ -  + ]:         27 :     LIBSPDM_ASSERT (*response_size >= transport_header_size);
+      79                 :            : 
+      80                 :         27 :     status = libspdm_receive_spdm_response(spdm_context, session_id,
+      81                 :            :                                            response_size, response);
+      82         [ -  + ]:         27 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+      83                 :          0 :         return status;
+      84                 :            :     }
+      85                 :         27 :     spdm_response = (void *)(*response);
+      86         [ -  + ]:         27 :     if (*response_size < sizeof(spdm_message_header_t)) {
+      87                 :          0 :         return LIBSPDM_STATUS_INVALID_MSG_SIZE;
+      88                 :            :     }
+      89         [ -  + ]:         27 :     if (spdm_response->spdm_version != spdm_request->header.spdm_version) {
+      90                 :          0 :         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+      91                 :            :     }
+      92         [ +  + ]:         27 :     if (spdm_response->request_response_code == SPDM_ERROR) {
+      93                 :         15 :         status = libspdm_handle_simple_error_response(spdm_context, spdm_response->param1);
+      94                 :         15 :         return status;
+      95                 :            :     }
+      96         [ -  + ]:         12 :     if (spdm_response->request_response_code != expected_response_code) {
+      97                 :          0 :         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+      98                 :            :     }
+      99                 :            : 
+     100                 :         12 :     return LIBSPDM_STATUS_SUCCESS;
+     101                 :            : }
+     102                 :            : #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
+     103                 :            : 
+     104                 :        396 : libspdm_return_t libspdm_handle_simple_error_response(libspdm_context_t *spdm_context,
+     105                 :            :                                                       uint8_t error_code)
+     106                 :            : {
+     107                 :            :     spdm_set_certificate_request_t *last_spdm_request;
+     108                 :            : 
+     109         [ +  + ]:        396 :     if (error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) {
+     110                 :         17 :         return LIBSPDM_STATUS_NOT_READY_PEER;
+     111                 :            :     }
+     112                 :            : 
+     113         [ +  + ]:        379 :     if (error_code == SPDM_ERROR_CODE_BUSY) {
+     114                 :         39 :         return LIBSPDM_STATUS_BUSY_PEER;
+     115                 :            :     }
+     116                 :            : 
+     117                 :        340 :     last_spdm_request = (void *)spdm_context->last_spdm_request;
+     118         [ +  + ]:        340 :     if ((last_spdm_request->header.request_response_code == SPDM_SET_CERTIFICATE) ||
+     119         [ +  + ]:        339 :         (last_spdm_request->header.request_response_code == SPDM_GET_CSR)) {
+     120                 :            : 
+     121         [ +  - ]:          4 :         if (error_code == SPDM_ERROR_CODE_RESET_REQUIRED) {
+     122         [ +  + ]:          4 :             if ((libspdm_get_connection_version(spdm_context) >= SPDM_MESSAGE_VERSION_13) &&
+     123         [ +  + ]:          2 :                 !libspdm_is_capabilities_flag_supported(
+     124                 :            :                     spdm_context, true, 0,
+     125                 :            :                     SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_INSTALL_RESET_CAP)) {
+     126                 :          1 :                 return LIBSPDM_STATUS_ERROR_PEER;
+     127                 :            :             }
+     128                 :            :             /* CERT_INSTALL_RESET_CAP for a 1.2 Responder is not checked because it was not defined
+     129                 :            :              * in SPDM 1.2.0. */
+     130                 :          3 :             return LIBSPDM_STATUS_RESET_REQUIRED_PEER;
+     131                 :            :         }
+     132                 :            :     }
+     133                 :            : 
+     134         [ +  + ]:        336 :     if (error_code == SPDM_ERROR_CODE_REQUEST_RESYNCH) {
+     135                 :         18 :         spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NOT_STARTED;
+     136                 :         18 :         return LIBSPDM_STATUS_RESYNCH_PEER;
+     137                 :            :     }
+     138                 :            : 
+     139                 :        318 :     return LIBSPDM_STATUS_ERROR_PEER;
+     140                 :            : }
+     141                 :            : 
+     142                 :            : #if LIBSPDM_RESPOND_IF_READY_SUPPORT
+     143                 :            : /**
+     144                 :            :  * This function handles RESPONSE_NOT_READY error code.
+     145                 :            :  *
+     146                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     147                 :            :  * @param  response_size                 The size of the response.
+     148                 :            :  *                                     On input, it means the size in bytes of response data buffer.
+     149                 :            :  *                                     On output, it means the size in bytes of copied response data buffer if RETURN_SUCCESS is returned.
+     150                 :            :  * @param  response                     The SPDM response message.
+     151                 :            :  * @param  original_request_code          Indicate the orginal request code.
+     152                 :            :  * @param  expected_response_code         Indicate the expected response code.
+     153                 :            :  *
+     154                 :            :  * @retval RETURN_SUCCESS               The RESPOND_IF_READY is sent and an expected SPDM response is received.
+     155                 :            :  * @retval RETURN_DEVICE_ERROR          A device error occurs when communicates with the device.
+     156                 :            :  **/
+     157                 :         27 : static libspdm_return_t libspdm_handle_response_not_ready(libspdm_context_t *spdm_context,
+     158                 :            :                                                           const uint32_t *session_id,
+     159                 :            :                                                           size_t *response_size,
+     160                 :            :                                                           void **response,
+     161                 :            :                                                           uint8_t original_request_code,
+     162                 :            :                                                           uint8_t expected_response_code)
+     163                 :            : {
+     164                 :            :     spdm_error_response_t *spdm_response;
+     165                 :            :     spdm_error_data_response_not_ready_t *extend_error_data;
+     166                 :            : 
+     167         [ -  + ]:         27 :     if(*response_size < sizeof(spdm_error_response_t) +
+     168                 :            :        sizeof(spdm_error_data_response_not_ready_t)) {
+     169                 :          0 :         return LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     170                 :            :     }
+     171                 :            : 
+     172                 :         27 :     spdm_response = *response;
+     173                 :         27 :     extend_error_data = (spdm_error_data_response_not_ready_t *)(spdm_response + 1);
+     174         [ -  + ]:         27 :     LIBSPDM_ASSERT(spdm_response->header.request_response_code == SPDM_ERROR);
+     175         [ -  + ]:         27 :     LIBSPDM_ASSERT(spdm_response->header.param1 == SPDM_ERROR_CODE_RESPONSE_NOT_READY);
+     176                 :            : 
+     177         [ -  + ]:         27 :     if (extend_error_data->request_code != original_request_code) {
+     178                 :          0 :         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     179                 :            :     }
+     180         [ -  + ]:         27 :     if (extend_error_data->rd_tm <= 1) {
+     181                 :          0 :         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     182                 :            :     }
+     183         [ -  + ]:         27 :     if (extend_error_data->rd_exponent > LIBSPDM_MAX_RDT_EXPONENT) {
+     184                 :          0 :         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     185                 :            :     }
+     186                 :            : 
+     187                 :         27 :     spdm_context->error_data.rd_exponent = extend_error_data->rd_exponent;
+     188                 :         27 :     spdm_context->error_data.request_code = extend_error_data->request_code;
+     189                 :         27 :     spdm_context->error_data.token = extend_error_data->token;
+     190                 :         27 :     spdm_context->error_data.rd_tm = extend_error_data->rd_tm;
+     191                 :            : 
+     192                 :         27 :     libspdm_sleep((uint64_t)1 << extend_error_data->rd_exponent);
+     193                 :            : 
+     194                 :         27 :     return libspdm_requester_respond_if_ready(spdm_context, session_id,
+     195                 :            :                                               response_size, response,
+     196                 :            :                                               expected_response_code);
+     197                 :            : }
+     198                 :            : #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
+     199                 :            : 
+     200                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
+     201                 :          5 : libspdm_return_t libspdm_handle_error_large_response(
+     202                 :            :     libspdm_context_t *spdm_context,
+     203                 :            :     const uint32_t *session_id,
+     204                 :            :     size_t *inout_response_size,
+     205                 :            :     void *inout_response,
+     206                 :            :     size_t response_capacity)
+     207                 :            : {
+     208                 :            :     libspdm_return_t status;
+     209                 :            :     uint8_t chunk_handle;
+     210                 :            :     spdm_error_response_t* error_response;
+     211                 :            :     spdm_error_data_large_response_t* extend_error_data;
+     212                 :            : 
+     213                 :            :     spdm_chunk_get_request_t* spdm_request;
+     214                 :            :     size_t spdm_request_size;
+     215                 :            :     spdm_chunk_response_response_t* spdm_response;
+     216                 :            :     uint8_t* message;
+     217                 :            :     size_t message_size;
+     218                 :            :     size_t transport_header_size;
+     219                 :            : 
+     220                 :            :     uint8_t* scratch_buffer;
+     221                 :            :     size_t scratch_buffer_size;
+     222                 :            :     uint16_t chunk_seq_no;
+     223                 :            :     uint8_t* chunk_ptr;
+     224                 :            :     uint8_t* large_response;
+     225                 :            :     size_t large_response_capacity;
+     226                 :            :     size_t large_response_size;
+     227                 :            :     size_t large_response_size_so_far;
+     228                 :            : 
+     229         [ -  + ]:          5 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_12) {
+     230                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     231                 :            :     }
+     232                 :            : 
+     233                 :            :     /* Fail if requester or responder does not support chunk cap */
+     234         [ -  + ]:          5 :     if (!libspdm_is_capabilities_flag_supported(
+     235                 :            :             spdm_context, true,
+     236                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP,
+     237                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP)) {
+     238                 :          0 :         return LIBSPDM_STATUS_ERROR_PEER;
+     239                 :            :     }
+     240                 :            : 
+     241         [ -  + ]:          5 :     if (*inout_response_size < sizeof(spdm_error_response_t) +
+     242                 :            :         sizeof(spdm_error_data_large_response_t)) {
+     243                 :          0 :         return LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     244                 :            :     }
+     245                 :            : 
+     246                 :          5 :     error_response = inout_response;
+     247                 :          5 :     extend_error_data =
+     248                 :            :         (spdm_error_data_large_response_t*)(error_response + 1);
+     249                 :          5 :     chunk_handle = extend_error_data->handle;
+     250                 :            : 
+     251                 :            :     /* now we can get sender buffer */
+     252                 :          5 :     transport_header_size = spdm_context->local_context.capability.transport_header_size;
+     253                 :            : 
+     254                 :          5 :     libspdm_get_scratch_buffer(spdm_context, (void**)&scratch_buffer, &scratch_buffer_size);
+     255                 :            : 
+     256                 :            :     /* The first section of the scratch
+     257                 :            :      * buffer may be used for other purposes. Use only after that section. */
+     258                 :          5 :     large_response = scratch_buffer + libspdm_get_scratch_buffer_large_message_offset(spdm_context);
+     259                 :          5 :     large_response_capacity = libspdm_get_scratch_buffer_large_message_capacity(spdm_context);
+     260                 :            : 
+     261                 :            :     /* Temporary send/receive buffers for chunking are in the scratch space */
+     262                 :          5 :     message = scratch_buffer + libspdm_get_scratch_buffer_sender_receiver_offset(spdm_context);
+     263                 :          5 :     message_size = libspdm_get_scratch_buffer_sender_receiver_capacity(spdm_context);
+     264                 :            : 
+     265                 :          5 :     libspdm_zero_mem(large_response, large_response_capacity);
+     266                 :          5 :     large_response_size = 0;
+     267                 :          5 :     large_response_size_so_far = 0;
+     268                 :          5 :     chunk_seq_no = 0;
+     269                 :            : 
+     270                 :            :     do {
+     271         [ -  + ]:         68 :         LIBSPDM_ASSERT(message_size >= transport_header_size);
+     272                 :         68 :         spdm_request = (spdm_chunk_get_request_t*)(void*) (message + transport_header_size);
+     273                 :         68 :         spdm_request_size = message_size - transport_header_size;
+     274                 :            : 
+     275         [ -  + ]:         68 :         LIBSPDM_ASSERT(spdm_request_size >= sizeof(spdm_chunk_get_request_t));
+     276                 :         68 :         spdm_request->header.spdm_version = libspdm_get_connection_version(spdm_context);
+     277                 :         68 :         spdm_request->header.request_response_code = SPDM_CHUNK_GET;
+     278                 :         68 :         spdm_request->header.param1 = 0;
+     279                 :         68 :         spdm_request->header.param2 = chunk_handle;
+     280                 :         68 :         spdm_request->chunk_seq_no = chunk_seq_no;
+     281                 :         68 :         spdm_request_size = sizeof(spdm_chunk_get_request_t);
+     282                 :            : 
+     283                 :         68 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+     284                 :            :                        "CHUNK_GET Handle %d SeqNo %d\n", chunk_handle, chunk_seq_no));
+     285                 :            : 
+     286                 :         68 :         status = libspdm_send_spdm_request(spdm_context, session_id,
+     287                 :            :                                            spdm_request_size, spdm_request);
+     288                 :            : 
+     289         [ -  + ]:         68 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     290                 :          0 :             break;
+     291                 :            :         }
+     292                 :            : 
+     293                 :         68 :         libspdm_zero_mem(message, message_size);
+     294                 :         68 :         void* response = message;
+     295                 :         68 :         size_t response_size = message_size;
+     296                 :            : 
+     297                 :         68 :         status = libspdm_receive_spdm_response(
+     298                 :            :             spdm_context, session_id,
+     299                 :            :             &response_size, &response);
+     300                 :            : 
+     301         [ -  + ]:         68 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     302                 :          0 :             break;
+     303                 :            :         }
+     304                 :         68 :         spdm_response = (void*) (response);
+     305         [ -  + ]:         68 :         if (spdm_response->header.spdm_version != libspdm_get_connection_version(spdm_context)) {
+     306                 :          0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     307                 :          0 :             break;
+     308                 :            :         }
+     309         [ -  + ]:         68 :         if (spdm_response->header.request_response_code == SPDM_ERROR) {
+     310                 :          0 :             status = libspdm_handle_simple_error_response(spdm_context,
+     311                 :          0 :                                                           spdm_response->header.param1);
+     312                 :          0 :             break;
+     313                 :            :         }
+     314         [ -  + ]:         68 :         if (spdm_response->header.request_response_code != SPDM_CHUNK_RESPONSE) {
+     315                 :          0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     316                 :          0 :             break;
+     317                 :            :         }
+     318         [ +  + ]:         68 :         if (chunk_seq_no == 0) {
+     319                 :            : 
+     320                 :          5 :             if (response_size
+     321         [ -  + ]:          5 :                 < (sizeof(spdm_chunk_response_response_t) + sizeof(uint32_t))) {
+     322                 :          0 :                 status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     323                 :          0 :                 break;
+     324                 :            :             }
+     325         [ -  + ]:          5 :             if (response_size < SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12) {
+     326                 :          0 :                 status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     327                 :          0 :                 break;
+     328                 :            :             }
+     329                 :            : 
+     330         [ -  + ]:          5 :             if (spdm_response->chunk_size
+     331                 :            :                 < SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12
+     332                 :            :                 - sizeof(spdm_chunk_response_response_t)
+     333                 :            :                 - sizeof(uint32_t)) {
+     334                 :          0 :                 status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     335                 :          0 :                 break;
+     336                 :            :             }
+     337                 :            : 
+     338                 :          5 :             large_response_size = *(uint32_t*) (spdm_response + 1);
+     339                 :          5 :             chunk_ptr = (uint8_t*) (((uint32_t*) (spdm_response + 1)) + 1);
+     340                 :            : 
+     341         [ -  + ]:          5 :             if (spdm_response->chunk_size > large_response_size) {
+     342                 :          0 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     343                 :          0 :                 break;
+     344                 :            :             }
+     345         [ -  + ]:          5 :             if (large_response_size > spdm_context->local_context.capability.max_spdm_msg_size) {
+     346                 :          0 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     347                 :          0 :                 break;
+     348                 :            :             }
+     349         [ -  + ]:          5 :             if (large_response_size <= SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12) {
+     350                 :          0 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     351                 :          0 :                 break;
+     352                 :            :             }
+     353                 :            :         } else {
+     354         [ -  + ]:         63 :             if (response_size < sizeof(spdm_chunk_response_response_t)) {
+     355                 :          0 :                 status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     356                 :          0 :                 break;
+     357                 :            :             }
+     358         [ -  + ]:         63 :             if (spdm_response->chunk_size + large_response_size_so_far > large_response_size) {
+     359                 :          0 :                 status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     360                 :          0 :                 break;
+     361                 :            :             }
+     362                 :            : 
+     363         [ +  + ]:         63 :             if (!(spdm_response->header.param1 & SPDM_CHUNK_GET_RESPONSE_ATTRIBUTE_LAST_CHUNK)) {
+     364         [ -  + ]:         58 :                 if (response_size < SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12) {
+     365                 :          0 :                     status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     366                 :          0 :                     break;
+     367                 :            :                 }
+     368         [ -  + ]:         58 :                 if (spdm_response->chunk_size
+     369                 :            :                     < SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12
+     370                 :            :                     - sizeof(spdm_chunk_response_response_t)) {
+     371                 :          0 :                     status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     372                 :          0 :                     break;
+     373                 :            :                 }
+     374                 :            :             }
+     375                 :            : 
+     376                 :         63 :             chunk_ptr = (uint8_t*) (spdm_response + 1);
+     377                 :            :         }
+     378                 :            : 
+     379         [ -  + ]:         68 :         if (spdm_response->chunk_seq_no != chunk_seq_no) {
+     380                 :          0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     381                 :          0 :             break;
+     382                 :            :         }
+     383                 :            : 
+     384                 :         68 :         libspdm_copy_mem(large_response + large_response_size_so_far,
+     385                 :            :                          large_response_size - large_response_size_so_far,
+     386                 :         68 :                          chunk_ptr, spdm_response->chunk_size);
+     387                 :            : 
+     388                 :         68 :         large_response_size_so_far += spdm_response->chunk_size;
+     389                 :            : 
+     390                 :         68 :         chunk_seq_no++;
+     391                 :            : 
+     392                 :         68 :     } while (LIBSPDM_STATUS_IS_SUCCESS(status)
+     393         [ +  + ]:         68 :              && large_response_size_so_far < large_response_size
+     394   [ +  -  +  - ]:        131 :              && !(spdm_response->header.param1 & SPDM_CHUNK_GET_RESPONSE_ATTRIBUTE_LAST_CHUNK));
+     395                 :            : 
+     396                 :            : 
+     397         [ +  - ]:          5 :     if (LIBSPDM_STATUS_IS_SUCCESS(status)) {
+     398         [ -  + ]:          5 :         if (large_response_size_so_far != large_response_size) {
+     399                 :          0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     400         [ +  - ]:          5 :         } else if (large_response_size <= response_capacity) {
+     401                 :          5 :             libspdm_copy_mem(inout_response, response_capacity,
+     402                 :            :                              large_response, large_response_size);
+     403                 :          5 :             *inout_response_size = large_response_size;
+     404                 :            : 
+     405                 :          5 :             LIBSPDM_INTERNAL_DUMP_HEX(large_response, large_response_size);
+     406                 :            :         }
+     407                 :            :     }
+     408                 :            : 
+     409                 :          5 :     return status;
+     410                 :            : }
+     411                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP */
+     412                 :            : 
+     413                 :        362 : libspdm_return_t libspdm_handle_error_response_main(
+     414                 :            :     libspdm_context_t *spdm_context, const uint32_t *session_id,
+     415                 :            :     size_t *response_size, void **response,
+     416                 :            :     uint8_t original_request_code, uint8_t expected_response_code)
+     417                 :            : {
+     418                 :            :     spdm_message_header_t *spdm_response;
+     419                 :            : 
+     420                 :        362 :     spdm_response = *response;
+     421         [ -  + ]:        362 :     LIBSPDM_ASSERT(spdm_response->request_response_code == SPDM_ERROR);
+     422                 :            : 
+     423   [ +  +  +  + ]:        362 :     if ((spdm_response->param1 == SPDM_ERROR_CODE_DECRYPT_ERROR) && (session_id != NULL)) {
+     424                 :          5 :         libspdm_free_session_id(spdm_context, *session_id);
+     425                 :          5 :         return LIBSPDM_STATUS_SESSION_MSG_ERROR;
+     426         [ +  + ]:        357 :     } else if(spdm_response->param1 == SPDM_ERROR_CODE_RESPONSE_NOT_READY) {
+     427                 :            :         #if LIBSPDM_RESPOND_IF_READY_SUPPORT
+     428                 :         27 :         return libspdm_handle_response_not_ready(spdm_context, session_id,
+     429                 :            :                                                  response_size, response,
+     430                 :            :                                                  original_request_code,
+     431                 :            :                                                  expected_response_code);
+     432                 :            :         #else
+     433                 :            :         return LIBSPDM_STATUS_NOT_READY_PEER;
+     434                 :            :         #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
+     435                 :            :     } else {
+     436                 :        330 :         return libspdm_handle_simple_error_response(spdm_context, spdm_response->param1);
+     437                 :            :     }
+     438                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_heartbeat.c.func-sort-c.html b/coverage_log/library/spdm_requester_lib/libspdm_req_heartbeat.c.func-sort-c.html new file mode 100644 index 00000000000..6186679e13b --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_heartbeat.c.func-sort-c.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_heartbeat.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_heartbeat.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:627780.5 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:284266.7 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_heartbeat30
libspdm_try_heartbeat31
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_heartbeat.c.func.html b/coverage_log/library/spdm_requester_lib/libspdm_req_heartbeat.c.func.html new file mode 100644 index 00000000000..15830d43c41 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_heartbeat.c.func.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_heartbeat.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_heartbeat.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:627780.5 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:284266.7 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_heartbeat30
libspdm_try_heartbeat31
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_heartbeat.c.gcov.html b/coverage_log/library/spdm_requester_lib/libspdm_req_heartbeat.c.gcov.html new file mode 100644 index 00000000000..d2982557cf6 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_heartbeat.c.gcov.html @@ -0,0 +1,255 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_heartbeat.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_heartbeat.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:627780.5 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:284266.7 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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                 :            :     uint8_t dummy_data[sizeof(spdm_error_data_response_not_ready_t)];
+      13                 :            : } libspdm_heartbeat_response_mine_t;
+      14                 :            : #pragma pack()
+      15                 :            : 
+      16                 :            : /**
+      17                 :            :  * This function sends HEARTBEAT to an SPDM Session.
+      18                 :            :  *
+      19                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+      20                 :            :  * @param  session_id                    The session ID of the session.
+      21                 :            :  *
+      22                 :            :  **/
+      23                 :         31 : static libspdm_return_t libspdm_try_heartbeat(libspdm_context_t *spdm_context, uint32_t session_id)
+      24                 :            : {
+      25                 :            :     libspdm_return_t status;
+      26                 :            :     spdm_heartbeat_request_t *spdm_request;
+      27                 :            :     size_t spdm_request_size;
+      28                 :            :     libspdm_heartbeat_response_mine_t *spdm_response;
+      29                 :            :     size_t spdm_response_size;
+      30                 :            :     libspdm_session_info_t *session_info;
+      31                 :            :     libspdm_session_state_t session_state;
+      32                 :            :     uint8_t *message;
+      33                 :            :     size_t message_size;
+      34                 :            :     size_t transport_header_size;
+      35                 :            : 
+      36                 :            :     /* -=[Check Parameters Phase]=- */
+      37         [ -  + ]:         31 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_11) {
+      38                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+      39                 :            :     }
+      40                 :            : 
+      41                 :         31 :     session_info = libspdm_get_session_info_via_session_id(spdm_context, session_id);
+      42         [ -  + ]:         31 :     if (session_info == NULL) {
+      43                 :          0 :         return LIBSPDM_STATUS_INVALID_PARAMETER;
+      44                 :            :     }
+      45                 :            : 
+      46                 :            :     /* -=[Verify State Phase]=- */
+      47         [ -  + ]:         31 :     if (!libspdm_is_capabilities_flag_supported(
+      48                 :            :             spdm_context, true,
+      49                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP,
+      50                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP)) {
+      51                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+      52                 :            :     }
+      53         [ +  + ]:         31 :     if (spdm_context->connection_info.connection_state < LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
+      54                 :          1 :         return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+      55                 :            :     }
+      56                 :         30 :     session_state = libspdm_secured_message_get_session_state(
+      57                 :            :         session_info->secured_message_context);
+      58         [ -  + ]:         30 :     if (session_state != LIBSPDM_SESSION_STATE_ESTABLISHED) {
+      59                 :          0 :         return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+      60                 :            :     }
+      61         [ +  + ]:         30 :     if (session_info->heartbeat_period == 0) {
+      62                 :          1 :         return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+      63                 :            :     }
+      64                 :            : 
+      65                 :            :     /* -=[Construct Request Phase]=- */
+      66                 :         29 :     transport_header_size = spdm_context->local_context.capability.transport_header_size;
+      67                 :         29 :     status = libspdm_acquire_sender_buffer (spdm_context, &message_size, (void **)&message);
+      68         [ -  + ]:         29 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+      69                 :          0 :         return status;
+      70                 :            :     }
+      71         [ -  + ]:         29 :     LIBSPDM_ASSERT (message_size >= transport_header_size +
+      72                 :            :                     spdm_context->local_context.capability.transport_tail_size);
+      73                 :         29 :     spdm_request = (void *)(message + transport_header_size);
+      74                 :         29 :     spdm_request_size = message_size - transport_header_size -
+      75                 :         29 :                         spdm_context->local_context.capability.transport_tail_size;
+      76                 :            : 
+      77         [ -  + ]:         29 :     LIBSPDM_ASSERT (spdm_request_size >= sizeof(spdm_heartbeat_request_t));
+      78                 :         29 :     spdm_request->header.spdm_version = libspdm_get_connection_version (spdm_context);
+      79                 :         29 :     spdm_request->header.request_response_code = SPDM_HEARTBEAT;
+      80                 :         29 :     spdm_request->header.param1 = 0;
+      81                 :         29 :     spdm_request->header.param2 = 0;
+      82                 :         29 :     spdm_request_size = sizeof(spdm_heartbeat_request_t);
+      83                 :            : 
+      84                 :            :     /* -=[Send Request Phase]=- */
+      85                 :         29 :     status = libspdm_send_spdm_request(spdm_context, &session_id, spdm_request_size, spdm_request);
+      86         [ +  + ]:         29 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+      87                 :          1 :         libspdm_release_sender_buffer (spdm_context);
+      88                 :          1 :         return status;
+      89                 :            :     }
+      90                 :         28 :     libspdm_release_sender_buffer (spdm_context);
+      91                 :         28 :     spdm_request = (void *)spdm_context->last_spdm_request;
+      92                 :            : 
+      93                 :         28 :     libspdm_reset_message_buffer_via_request_code(spdm_context, session_info, SPDM_HEARTBEAT);
+      94                 :            : 
+      95                 :            :     /* -=[Receive Response Phase]=- */
+      96                 :         28 :     status = libspdm_acquire_receiver_buffer (spdm_context, &message_size, (void **)&message);
+      97         [ -  + ]:         28 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+      98                 :          0 :         return status;
+      99                 :            :     }
+     100         [ -  + ]:         28 :     LIBSPDM_ASSERT (message_size >= transport_header_size);
+     101                 :         28 :     spdm_response = (void *)(message);
+     102                 :         28 :     spdm_response_size = message_size;
+     103                 :            : 
+     104                 :         28 :     status = libspdm_receive_spdm_response(
+     105                 :            :         spdm_context, &session_id, &spdm_response_size, (void **)&spdm_response);
+     106         [ -  + ]:         28 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     107                 :          0 :         goto receive_done;
+     108                 :            :     }
+     109                 :            : 
+     110                 :            :     /* -=[Validate Response Phase]=- */
+     111         [ -  + ]:         28 :     if (spdm_response_size < sizeof(spdm_message_header_t)) {
+     112                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     113                 :          0 :         goto receive_done;
+     114                 :            :     }
+     115         [ -  + ]:         28 :     if (spdm_response->header.spdm_version != spdm_request->header.spdm_version) {
+     116                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     117                 :          0 :         goto receive_done;
+     118                 :            :     }
+     119         [ +  + ]:         28 :     if (spdm_response->header.request_response_code == SPDM_ERROR) {
+     120                 :         25 :         status = libspdm_handle_error_response_main(
+     121                 :            :             spdm_context, &session_id, &spdm_response_size,
+     122                 :            :             (void **)&spdm_response, SPDM_HEARTBEAT, SPDM_HEARTBEAT_ACK);
+     123         [ +  + ]:         25 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     124                 :         24 :             goto receive_done;
+     125                 :            :         }
+     126         [ -  + ]:          3 :     } else if (spdm_response->header.request_response_code != SPDM_HEARTBEAT_ACK) {
+     127                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     128                 :          0 :         goto receive_done;
+     129                 :            :     }
+     130                 :            :     /* this message can only be in secured session
+     131                 :            :      * thus don't need to consider transport layer padding, just check its exact size */
+     132         [ -  + ]:          4 :     if (spdm_response_size != sizeof(spdm_heartbeat_response_t)) {
+     133                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     134                 :          0 :         goto receive_done;
+     135                 :            :     }
+     136                 :            : 
+     137                 :            :     /* -=[Log Message Phase]=- */
+     138                 :            :     #if LIBSPDM_ENABLE_MSG_LOG
+     139                 :          4 :     libspdm_append_msg_log(spdm_context, spdm_response, spdm_response_size);
+     140                 :            :     #endif /* LIBSPDM_ENABLE_MSG_LOG */
+     141                 :            : 
+     142                 :          4 :     status = LIBSPDM_STATUS_SUCCESS;
+     143                 :            : 
+     144                 :         28 : receive_done:
+     145                 :         28 :     libspdm_release_receiver_buffer (spdm_context);
+     146                 :         28 :     return status;
+     147                 :            : }
+     148                 :            : 
+     149                 :         30 : libspdm_return_t libspdm_heartbeat(void *spdm_context, uint32_t session_id)
+     150                 :            : {
+     151                 :            :     size_t retry;
+     152                 :            :     uint64_t retry_delay_time;
+     153                 :            :     libspdm_return_t status;
+     154                 :            :     libspdm_context_t *context;
+     155                 :            : 
+     156                 :         30 :     context = spdm_context;
+     157                 :         30 :     context->crypto_request = true;
+     158                 :         30 :     retry = context->retry_times;
+     159                 :         30 :     retry_delay_time = context->retry_delay_time;
+     160                 :            :     do {
+     161                 :         31 :         status = libspdm_try_heartbeat(context, session_id);
+     162         [ +  + ]:         31 :         if (status != LIBSPDM_STATUS_BUSY_PEER) {
+     163                 :         29 :             return status;
+     164                 :            :         }
+     165                 :            : 
+     166                 :          2 :         libspdm_sleep(retry_delay_time);
+     167         [ +  + ]:          2 :     } while (retry-- != 0);
+     168                 :            : 
+     169                 :          1 :     return status;
+     170                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_key_exchange.c.func-sort-c.html b/coverage_log/library/spdm_requester_lib/libspdm_req_key_exchange.c.func-sort-c.html new file mode 100644 index 00000000000..3bd498d585d --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_key_exchange.c.func-sort-c.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_key_exchange.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_key_exchange.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:31439479.7 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:13318870.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_send_receive_key_exchange_ex1
libspdm_verify_key_exchange_rsp_hmac19
libspdm_verify_key_exchange_rsp_signature22
libspdm_send_receive_key_exchange93
libspdm_try_send_receive_key_exchange95
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_key_exchange.c.func.html b/coverage_log/library/spdm_requester_lib/libspdm_req_key_exchange.c.func.html new file mode 100644 index 00000000000..3e58ed1fe34 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_key_exchange.c.func.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_key_exchange.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_key_exchange.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:31439479.7 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:13318870.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_send_receive_key_exchange93
libspdm_send_receive_key_exchange_ex1
libspdm_try_send_receive_key_exchange95
libspdm_verify_key_exchange_rsp_hmac19
libspdm_verify_key_exchange_rsp_signature22
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_key_exchange.c.gcov.html b/coverage_log/library/spdm_requester_lib/libspdm_req_key_exchange.c.gcov.html new file mode 100644 index 00000000000..c3ce87026e3 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_key_exchange.c.gcov.html @@ -0,0 +1,972 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_key_exchange.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_key_exchange.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:31439479.7 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:13318870.7 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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                 :            : #include "internal/libspdm_secured_message_lib.h"
+       9                 :            : 
+      10                 :            : #if LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP
+      11                 :            : 
+      12                 :            : #pragma pack(1)
+      13                 :            : typedef struct {
+      14                 :            :     spdm_message_header_t header;
+      15                 :            :     uint16_t req_session_id;
+      16                 :            :     uint8_t session_policy;
+      17                 :            :     uint8_t reserved;
+      18                 :            :     uint8_t random_data[SPDM_RANDOM_DATA_SIZE];
+      19                 :            :     uint8_t exchange_data[LIBSPDM_MAX_DHE_KEY_SIZE];
+      20                 :            :     uint16_t opaque_length;
+      21                 :            :     uint8_t opaque_data[SPDM_MAX_OPAQUE_DATA_SIZE];
+      22                 :            : } libspdm_key_exchange_request_mine_t;
+      23                 :            : 
+      24                 :            : typedef struct {
+      25                 :            :     spdm_message_header_t header;
+      26                 :            :     uint16_t rsp_session_id;
+      27                 :            :     uint8_t mut_auth_requested;
+      28                 :            :     uint8_t req_slot_id_param;
+      29                 :            :     uint8_t random_data[SPDM_RANDOM_DATA_SIZE];
+      30                 :            :     uint8_t exchange_data[LIBSPDM_MAX_DHE_KEY_SIZE];
+      31                 :            :     uint8_t measurement_summary_hash[LIBSPDM_MAX_HASH_SIZE];
+      32                 :            :     uint16_t opaque_length;
+      33                 :            :     uint8_t opaque_data[SPDM_MAX_OPAQUE_DATA_SIZE];
+      34                 :            :     uint8_t signature[LIBSPDM_MAX_ASYM_KEY_SIZE];
+      35                 :            :     uint8_t verify_data[LIBSPDM_MAX_HASH_SIZE];
+      36                 :            : } libspdm_key_exchange_response_max_t;
+      37                 :            : #pragma pack()
+      38                 :            : 
+      39                 :         19 : bool libspdm_verify_key_exchange_rsp_hmac(libspdm_context_t *spdm_context,
+      40                 :            :                                           libspdm_session_info_t *session_info,
+      41                 :            :                                           const void *hmac_data,
+      42                 :            :                                           size_t hmac_data_size)
+      43                 :            : {
+      44                 :            :     size_t hash_size;
+      45                 :            :     uint8_t calc_hmac_data[LIBSPDM_MAX_HASH_SIZE];
+      46                 :            :     bool result;
+      47                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+      48                 :            :     uint8_t slot_id;
+      49                 :            :     uint8_t *cert_chain_buffer;
+      50                 :            :     size_t cert_chain_buffer_size;
+      51                 :            :     uint8_t *th_curr_data;
+      52                 :            :     size_t th_curr_data_size;
+      53                 :            :     libspdm_th_managed_buffer_t th_curr;
+      54                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+      55                 :            : #endif
+      56                 :            : 
+      57                 :         19 :     hash_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+      58         [ -  + ]:         19 :     LIBSPDM_ASSERT(hash_size == hmac_data_size);
+      59                 :            : 
+      60                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+      61                 :            :     slot_id = spdm_context->connection_info.peer_used_cert_chain_slot_id;
+      62                 :            :     LIBSPDM_ASSERT((slot_id < SPDM_MAX_SLOT_COUNT) || (slot_id == 0xFF));
+      63                 :            :     if (slot_id == 0xFF) {
+      64                 :            :         result = libspdm_get_peer_public_key_buffer(
+      65                 :            :             spdm_context, (const void **)&cert_chain_buffer, &cert_chain_buffer_size);
+      66                 :            :     } else {
+      67                 :            :         result = libspdm_get_peer_cert_chain_buffer(
+      68                 :            :             spdm_context, (const void **)&cert_chain_buffer, &cert_chain_buffer_size);
+      69                 :            :     }
+      70                 :            :     if (!result) {
+      71                 :            :         return false;
+      72                 :            :     }
+      73                 :            : 
+      74                 :            :     result = libspdm_calculate_th_for_exchange(
+      75                 :            :         spdm_context, session_info, cert_chain_buffer,
+      76                 :            :         cert_chain_buffer_size, &th_curr);
+      77                 :            :     if (!result) {
+      78                 :            :         return false;
+      79                 :            :     }
+      80                 :            :     th_curr_data = libspdm_get_managed_buffer(&th_curr);
+      81                 :            :     th_curr_data_size = libspdm_get_managed_buffer_size(&th_curr);
+      82                 :            : 
+      83                 :            :     result = libspdm_hash_all (spdm_context->connection_info.algorithm.base_hash_algo,
+      84                 :            :                                th_curr_data, th_curr_data_size, hash_data);
+      85                 :            :     if (!result) {
+      86                 :            :         return false;
+      87                 :            :     }
+      88                 :            : 
+      89                 :            :     result = libspdm_hmac_all_with_response_finished_key(
+      90                 :            :         session_info->secured_message_context, hash_data,
+      91                 :            :         hash_size, calc_hmac_data);
+      92                 :            :     if (!result) {
+      93                 :            :         return false;
+      94                 :            :     }
+      95                 :            : #else
+      96                 :         19 :     result = libspdm_calculate_th_hmac_for_exchange_rsp(
+      97                 :            :         spdm_context, session_info, true, &hash_size, calc_hmac_data);
+      98         [ -  + ]:         19 :     if (!result) {
+      99                 :          0 :         return false;
+     100                 :            :     }
+     101                 :            : #endif
+     102                 :         19 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "th_curr hmac - "));
+     103                 :         19 :     LIBSPDM_INTERNAL_DUMP_DATA(calc_hmac_data, hash_size);
+     104                 :         19 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     105                 :            : 
+     106         [ -  + ]:         19 :     if (!libspdm_consttime_is_mem_equal(calc_hmac_data, hmac_data, hash_size)) {
+     107                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR, "!!! verify_key_exchange_hmac - FAIL !!!\n"));
+     108                 :          0 :         return false;
+     109                 :            :     }
+     110                 :         19 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "!!! verify_key_exchange_hmac - PASS !!!\n"));
+     111                 :            : 
+     112                 :         19 :     return true;
+     113                 :            : }
+     114                 :            : 
+     115                 :         22 : bool libspdm_verify_key_exchange_rsp_signature(
+     116                 :            :     libspdm_context_t *spdm_context, libspdm_session_info_t *session_info,
+     117                 :            :     const void *sign_data, const size_t sign_data_size)
+     118                 :            : {
+     119                 :            :     bool result;
+     120                 :            :     void *context;
+     121                 :            :     uint8_t slot_id;
+     122                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     123                 :            :     uint8_t *cert_chain_buffer;
+     124                 :            :     size_t cert_chain_buffer_size;
+     125                 :            :     uint8_t *th_curr_data;
+     126                 :            :     size_t th_curr_data_size;
+     127                 :            :     libspdm_th_managed_buffer_t th_curr;
+     128                 :            :     const uint8_t *cert_chain_data;
+     129                 :            :     size_t cert_chain_data_size;
+     130                 :            :     const uint8_t *cert_buffer;
+     131                 :            :     size_t cert_buffer_size;
+     132                 :            : #endif
+     133                 :            : #if !(LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT) || (LIBSPDM_DEBUG_PRINT_ENABLE)
+     134                 :            :     size_t hash_size;
+     135                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     136                 :            : 
+     137                 :         22 :     hash_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+     138                 :            : #endif
+     139                 :            : 
+     140                 :         22 :     slot_id = spdm_context->connection_info.peer_used_cert_chain_slot_id;
+     141   [ +  +  -  + ]:         22 :     LIBSPDM_ASSERT((slot_id < SPDM_MAX_SLOT_COUNT) || (slot_id == 0xFF));
+     142                 :            : 
+     143                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     144                 :            :     if (slot_id == 0xFF) {
+     145                 :            :         result = libspdm_get_peer_public_key_buffer(
+     146                 :            :             spdm_context, (const void **)&cert_chain_buffer, &cert_chain_buffer_size);
+     147                 :            :     } else {
+     148                 :            :         result = libspdm_get_peer_cert_chain_buffer(
+     149                 :            :             spdm_context, (const void **)&cert_chain_buffer, &cert_chain_buffer_size);
+     150                 :            :     }
+     151                 :            :     if (!result) {
+     152                 :            :         return false;
+     153                 :            :     }
+     154                 :            : 
+     155                 :            :     result = libspdm_calculate_th_for_exchange(
+     156                 :            :         spdm_context, session_info, cert_chain_buffer,
+     157                 :            :         cert_chain_buffer_size, &th_curr);
+     158                 :            :     if (!result) {
+     159                 :            :         return false;
+     160                 :            :     }
+     161                 :            :     th_curr_data = libspdm_get_managed_buffer(&th_curr);
+     162                 :            :     th_curr_data_size = libspdm_get_managed_buffer_size(&th_curr);
+     163                 :            : 
+     164                 :            :     /* Debug code only - required for debug print of th_curr hash below*/
+     165                 :            :     LIBSPDM_DEBUG_CODE(
+     166                 :            :         if (!libspdm_hash_all(
+     167                 :            :                 spdm_context->connection_info.algorithm.base_hash_algo,
+     168                 :            :                 th_curr_data, th_curr_data_size, hash_data)) {
+     169                 :            :         return false;
+     170                 :            :     }
+     171                 :            :         );
+     172                 :            : #else
+     173                 :         22 :     result = libspdm_calculate_th_hash_for_exchange(
+     174                 :            :         spdm_context, session_info, &hash_size, hash_data);
+     175         [ -  + ]:         22 :     if (!result) {
+     176                 :          0 :         return false;
+     177                 :            :     }
+     178                 :            : #endif
+     179                 :         22 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "th_curr hash - "));
+     180                 :         22 :     LIBSPDM_INTERNAL_DUMP_DATA(hash_data, hash_size);
+     181                 :         22 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     182                 :            : 
+     183                 :         22 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "signature - "));
+     184                 :         22 :     LIBSPDM_INTERNAL_DUMP_DATA(sign_data, sign_data_size);
+     185                 :         22 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     186                 :            : 
+     187         [ +  + ]:         22 :     if (slot_id == 0xFF) {
+     188                 :          1 :         result = libspdm_asym_get_public_key_from_der(
+     189                 :            :             spdm_context->connection_info.algorithm.base_asym_algo,
+     190                 :          1 :             spdm_context->local_context.peer_public_key_provision,
+     191                 :            :             spdm_context->local_context.peer_public_key_provision_size,
+     192                 :            :             &context);
+     193         [ -  + ]:          1 :         if (!result) {
+     194                 :          0 :             return false;
+     195                 :            :         }
+     196                 :            :     } else {
+     197                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     198                 :            :         /* Get leaf cert from cert chain*/
+     199                 :            :         result = libspdm_get_peer_cert_chain_data(
+     200                 :            :             spdm_context, (const void **)&cert_chain_data, &cert_chain_data_size);
+     201                 :            :         if (!result) {
+     202                 :            :             return false;
+     203                 :            :         }
+     204                 :            :         result = libspdm_x509_get_cert_from_cert_chain(
+     205                 :            :             cert_chain_data, cert_chain_data_size, -1, &cert_buffer, &cert_buffer_size);
+     206                 :            :         if (!result) {
+     207                 :            :             return false;
+     208                 :            :         }
+     209                 :            : 
+     210                 :            :         result = libspdm_asym_get_public_key_from_x509(
+     211                 :            :             spdm_context->connection_info.algorithm.base_asym_algo,
+     212                 :            :             cert_buffer, cert_buffer_size, &context);
+     213                 :            :         if (!result) {
+     214                 :            :             return false;
+     215                 :            :         }
+     216                 :            : #else
+     217                 :         21 :         context = spdm_context->connection_info.peer_used_cert_chain[slot_id].leaf_cert_public_key;
+     218         [ -  + ]:         21 :         LIBSPDM_ASSERT(context != NULL);
+     219                 :            : #endif
+     220                 :            :     }
+     221                 :            : 
+     222                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     223                 :            :     result = libspdm_asym_verify_ex(
+     224                 :            :         spdm_context->connection_info.version, SPDM_KEY_EXCHANGE_RSP,
+     225                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+     226                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+     227                 :            :         context, th_curr_data, th_curr_data_size, sign_data, sign_data_size,
+     228                 :            :         &spdm_context->spdm_10_11_verify_signature_endian);
+     229                 :            :     libspdm_asym_free(spdm_context->connection_info.algorithm.base_asym_algo, context);
+     230                 :            : #else
+     231                 :         22 :     result = libspdm_asym_verify_hash_ex(
+     232                 :         22 :         spdm_context->connection_info.version, SPDM_KEY_EXCHANGE_RSP,
+     233                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+     234                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+     235                 :            :         context, hash_data, hash_size, sign_data, sign_data_size,
+     236                 :            :         &spdm_context->spdm_10_11_verify_signature_endian);
+     237         [ +  + ]:         22 :     if (slot_id == 0xFF) {
+     238                 :          1 :         libspdm_asym_free(spdm_context->connection_info.algorithm.base_asym_algo, context);
+     239                 :            :     }
+     240                 :            : #endif
+     241         [ +  + ]:         22 :     if (!result) {
+     242                 :          2 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR, "!!! verify_key_exchange_signature - FAIL !!!\n"));
+     243                 :          2 :         return false;
+     244                 :            :     }
+     245                 :         20 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "!!! verify_key_exchange_signature - PASS !!!\n"));
+     246                 :            : 
+     247                 :         20 :     return true;
+     248                 :            : }
+     249                 :            : 
+     250                 :            : /**
+     251                 :            :  * This function sends KEY_EXCHANGE and receives KEY_EXCHANGE_RSP for SPDM key exchange.
+     252                 :            :  *
+     253                 :            :  * @param  spdm_context           A pointer to the SPDM context.
+     254                 :            :  * @param  measurement_hash_type  Measurement_hash_type to the KEY_EXCHANGE request.
+     255                 :            :  * @param  slot_id                slot_id to the KEY_EXCHANGE request.
+     256                 :            :  * @param  session_policy         The policy for the session.
+     257                 :            :  * @param  session_id             session_id from the KEY_EXCHANGE_RSP response.
+     258                 :            :  * @param  heartbeat_period       Heartbeat_period from the KEY_EXCHANGE_RSP response.
+     259                 :            :  * @param  req_slot_id_param      req_slot_id_param from the KEY_EXCHANGE_RSP response.
+     260                 :            :  * @param  measurement_hash       Measurement_hash from the KEY_EXCHANGE_RSP response.
+     261                 :            :  * @param  requester_nonce_in     If not NULL, a buffer that holds the requester nonce (32 bytes)
+     262                 :            :  * @param  requester_nonce        If not NULL, a buffer to hold the requester nonce (32 bytes).
+     263                 :            :  * @param  responder_nonce        If not NULL, a buffer to hold the responder nonce (32 bytes).
+     264                 :            :  **/
+     265                 :         95 : static libspdm_return_t libspdm_try_send_receive_key_exchange(
+     266                 :            :     libspdm_context_t *spdm_context, uint8_t measurement_hash_type,
+     267                 :            :     uint8_t slot_id, uint8_t session_policy, uint32_t *session_id,
+     268                 :            :     uint8_t *heartbeat_period,
+     269                 :            :     uint8_t *req_slot_id_param, void *measurement_hash,
+     270                 :            :     const void *requester_random_in,
+     271                 :            :     void *requester_random, void *responder_random,
+     272                 :            :     const void *requester_opaque_data, size_t requester_opaque_data_size,
+     273                 :            :     void *responder_opaque_data, size_t *responder_opaque_data_size)
+     274                 :            : {
+     275                 :            :     bool result;
+     276                 :            :     libspdm_return_t status;
+     277                 :            :     libspdm_key_exchange_request_mine_t *spdm_request;
+     278                 :            :     size_t spdm_request_size;
+     279                 :            :     libspdm_key_exchange_response_max_t *spdm_response;
+     280                 :            :     size_t spdm_response_size;
+     281                 :            :     size_t dhe_key_size;
+     282                 :            :     uint32_t measurement_summary_hash_size;
+     283                 :            :     uint32_t signature_size;
+     284                 :            :     uint32_t hmac_size;
+     285                 :            :     uint8_t *ptr;
+     286                 :            :     void *measurement_summary_hash;
+     287                 :            :     uint16_t opaque_length;
+     288                 :            :     uint8_t *signature;
+     289                 :            :     uint8_t *verify_data;
+     290                 :            :     void *dhe_context;
+     291                 :            :     uint16_t req_session_id;
+     292                 :            :     uint16_t rsp_session_id;
+     293                 :            :     libspdm_session_info_t *session_info;
+     294                 :            :     size_t opaque_key_exchange_req_size;
+     295                 :            :     uint8_t th1_hash_data[LIBSPDM_MAX_HASH_SIZE];
+     296                 :            :     uint8_t *message;
+     297                 :            :     size_t message_size;
+     298                 :            :     size_t transport_header_size;
+     299                 :            :     uint8_t mut_auth_requested;
+     300                 :            : 
+     301                 :            :     /* -=[Check Parameters Phase]=- */
+     302   [ +  +  -  + ]:         95 :     LIBSPDM_ASSERT((slot_id < SPDM_MAX_SLOT_COUNT) || (slot_id == 0xff));
+     303   [ +  +  -  + ]:         95 :     LIBSPDM_ASSERT((slot_id != 0xff) ||
+     304                 :            :                    (spdm_context->local_context.peer_public_key_provision_size != 0));
+     305   [ +  +  +  +  :         95 :     LIBSPDM_ASSERT(measurement_hash_type == SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH ||
+                   -  + ]
+     306                 :            :                    measurement_hash_type == SPDM_KEY_EXCHANGE_REQUEST_TCB_COMPONENT_MEASUREMENT_HASH ||
+     307                 :            :                    measurement_hash_type == SPDM_KEY_EXCHANGE_REQUEST_ALL_MEASUREMENTS_HASH);
+     308                 :            : 
+     309                 :            :     /* -=[Verify State Phase]=- */
+     310         [ -  + ]:         95 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_11) {
+     311                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     312                 :            :     }
+     313                 :            : 
+     314         [ +  + ]:         95 :     if (!libspdm_is_capabilities_flag_supported(
+     315                 :            :             spdm_context, true,
+     316                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP,
+     317                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP)) {
+     318                 :          1 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     319                 :            :     }
+     320         [ +  + ]:         94 :     if (spdm_context->connection_info.connection_state < LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
+     321                 :          2 :         return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+     322                 :            :     }
+     323         [ +  + ]:         92 :     if (libspdm_get_connection_version(spdm_context) >= SPDM_MESSAGE_VERSION_12) {
+     324         [ -  + ]:          3 :         if ((spdm_context->connection_info.algorithm.other_params_support &
+     325                 :            :              SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_MASK) != SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1) {
+     326                 :          0 :             return LIBSPDM_STATUS_INVALID_STATE_PEER;
+     327                 :            :         }
+     328                 :            :     }
+     329                 :            : 
+     330                 :         92 :     req_session_id = libspdm_allocate_req_session_id(spdm_context, false);
+     331         [ -  + ]:         92 :     if (req_session_id == (INVALID_SESSION_ID & 0xFFFF)) {
+     332                 :          0 :         return LIBSPDM_STATUS_SESSION_NUMBER_EXCEED;
+     333                 :            :     }
+     334                 :            : 
+     335                 :         92 :     libspdm_reset_message_buffer_via_request_code(spdm_context, NULL, SPDM_KEY_EXCHANGE);
+     336                 :            : 
+     337                 :            :     /* -=[Construct Request Phase]=- */
+     338                 :         92 :     spdm_context->connection_info.peer_used_cert_chain_slot_id = slot_id;
+     339                 :         92 :     transport_header_size = spdm_context->local_context.capability.transport_header_size;
+     340                 :         92 :     status = libspdm_acquire_sender_buffer (spdm_context, &message_size, (void **)&message);
+     341         [ +  + ]:         92 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     342                 :          1 :         return status;
+     343                 :            :     }
+     344         [ -  + ]:         91 :     LIBSPDM_ASSERT (message_size >= transport_header_size +
+     345                 :            :                     spdm_context->local_context.capability.transport_tail_size);
+     346                 :         91 :     spdm_request = (void *)(message + transport_header_size);
+     347                 :         91 :     spdm_request_size = message_size - transport_header_size -
+     348                 :         91 :                         spdm_context->local_context.capability.transport_tail_size;
+     349                 :            : 
+     350         [ -  + ]:         91 :     LIBSPDM_ASSERT (spdm_request_size >= sizeof(spdm_key_exchange_request_t));
+     351                 :         91 :     spdm_request->header.spdm_version = libspdm_get_connection_version (spdm_context);
+     352                 :         91 :     spdm_request->header.request_response_code = SPDM_KEY_EXCHANGE;
+     353                 :         91 :     spdm_request->header.param1 = measurement_hash_type;
+     354                 :         91 :     spdm_request->header.param2 = slot_id;
+     355         [ +  + ]:         91 :     if (requester_random_in == NULL) {
+     356         [ -  + ]:         90 :         if(!libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_request->random_data)) {
+     357                 :          0 :             libspdm_release_sender_buffer (spdm_context);
+     358                 :          0 :             return LIBSPDM_STATUS_LOW_ENTROPY;
+     359                 :            :         }
+     360                 :            :     } else {
+     361                 :          1 :         libspdm_copy_mem(spdm_request->random_data, sizeof(spdm_request->random_data),
+     362                 :            :                          requester_random_in, SPDM_RANDOM_DATA_SIZE);
+     363                 :            :     }
+     364                 :         91 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "RequesterRandomData (0x%x) - ",
+     365                 :            :                    SPDM_RANDOM_DATA_SIZE));
+     366                 :         91 :     LIBSPDM_INTERNAL_DUMP_DATA(spdm_request->random_data, SPDM_RANDOM_DATA_SIZE);
+     367                 :         91 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     368         [ +  + ]:         91 :     if (requester_random != NULL) {
+     369                 :          1 :         libspdm_copy_mem(requester_random, SPDM_RANDOM_DATA_SIZE,
+     370                 :          1 :                          spdm_request->random_data, SPDM_RANDOM_DATA_SIZE);
+     371                 :            :     }
+     372                 :            : 
+     373                 :         91 :     spdm_request->req_session_id = req_session_id;
+     374         [ +  + ]:         91 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_12) {
+     375                 :          3 :         spdm_request->session_policy = session_policy;
+     376                 :            :     } else {
+     377                 :         88 :         spdm_request->session_policy = 0;
+     378                 :            :     }
+     379                 :         91 :     spdm_request->reserved = 0;
+     380                 :            : 
+     381                 :         91 :     ptr = spdm_request->exchange_data;
+     382                 :        182 :     dhe_key_size = libspdm_get_dhe_pub_key_size(
+     383                 :         91 :         spdm_context->connection_info.algorithm.dhe_named_group);
+     384                 :         91 :     dhe_context = libspdm_secured_message_dhe_new(
+     385                 :         91 :         spdm_context->connection_info.version,
+     386                 :         91 :         spdm_context->connection_info.algorithm.dhe_named_group, true);
+     387         [ -  + ]:         91 :     if (dhe_context == NULL) {
+     388                 :          0 :         libspdm_release_sender_buffer (spdm_context);
+     389                 :          0 :         return LIBSPDM_STATUS_CRYPTO_ERROR;
+     390                 :            :     }
+     391                 :            : 
+     392         [ -  + ]:         91 :     LIBSPDM_ASSERT (spdm_request_size >= sizeof(spdm_key_exchange_request_t) + dhe_key_size);
+     393                 :         91 :     result = libspdm_secured_message_dhe_generate_key(
+     394                 :         91 :         spdm_context->connection_info.algorithm.dhe_named_group,
+     395                 :            :         dhe_context, ptr, &dhe_key_size);
+     396         [ -  + ]:         91 :     if (!result) {
+     397                 :          0 :         libspdm_secured_message_dhe_free(
+     398                 :          0 :             spdm_context->connection_info.algorithm.dhe_named_group, dhe_context);
+     399                 :          0 :         libspdm_release_sender_buffer (spdm_context);
+     400                 :          0 :         return LIBSPDM_STATUS_CRYPTO_ERROR;
+     401                 :            :     }
+     402                 :         91 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "RequesterKey (0x%zx):\n", dhe_key_size));
+     403                 :         91 :     LIBSPDM_INTERNAL_DUMP_HEX(ptr, dhe_key_size);
+     404                 :         91 :     ptr += dhe_key_size;
+     405                 :            : 
+     406         [ +  + ]:         91 :     if (requester_opaque_data != NULL) {
+     407         [ -  + ]:          1 :         LIBSPDM_ASSERT(requester_opaque_data_size <= SPDM_MAX_OPAQUE_DATA_SIZE);
+     408                 :            : 
+     409         [ -  + ]:          1 :         LIBSPDM_ASSERT (spdm_request_size >= sizeof(spdm_key_exchange_request_t) + dhe_key_size +
+     410                 :            :                         sizeof(uint16_t) + requester_opaque_data_size);
+     411                 :            : 
+     412                 :          1 :         libspdm_write_uint16(ptr, (uint16_t)requester_opaque_data_size);
+     413                 :          1 :         ptr += sizeof(uint16_t);
+     414                 :            : 
+     415                 :          1 :         libspdm_copy_mem(ptr,
+     416                 :          1 :                          (spdm_request_size - (sizeof(spdm_key_exchange_request_t) + dhe_key_size)),
+     417                 :            :                          requester_opaque_data, requester_opaque_data_size);
+     418                 :          1 :         opaque_key_exchange_req_size = requester_opaque_data_size;
+     419                 :            :     } else {
+     420                 :         90 :         opaque_key_exchange_req_size =
+     421                 :         90 :             libspdm_get_opaque_data_supported_version_data_size(spdm_context);
+     422         [ -  + ]:         90 :         LIBSPDM_ASSERT (spdm_request_size >= sizeof(spdm_key_exchange_request_t) + dhe_key_size +
+     423                 :            :                         sizeof(uint16_t) + opaque_key_exchange_req_size);
+     424                 :            : 
+     425                 :         90 :         libspdm_write_uint16(ptr, (uint16_t)opaque_key_exchange_req_size);
+     426                 :         90 :         ptr += sizeof(uint16_t);
+     427                 :            : 
+     428                 :         90 :         libspdm_build_opaque_data_supported_version_data(
+     429                 :            :             spdm_context, &opaque_key_exchange_req_size, ptr);
+     430                 :            :     }
+     431                 :         91 :     ptr += opaque_key_exchange_req_size;
+     432                 :            : 
+     433                 :         91 :     spdm_request_size = (size_t)ptr - (size_t)spdm_request;
+     434                 :            : 
+     435                 :            :     /* -=[Send Request Phase]=- */
+     436                 :         91 :     status = libspdm_send_spdm_request(spdm_context, NULL, spdm_request_size, spdm_request);
+     437         [ +  + ]:         91 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     438                 :          2 :         libspdm_secured_message_dhe_free(
+     439                 :          2 :             spdm_context->connection_info.algorithm.dhe_named_group, dhe_context);
+     440                 :          2 :         libspdm_release_sender_buffer (spdm_context);
+     441                 :          2 :         return status;
+     442                 :            :     }
+     443                 :         89 :     libspdm_release_sender_buffer (spdm_context);
+     444                 :         89 :     spdm_request = (void *)spdm_context->last_spdm_request;
+     445                 :            : 
+     446                 :            :     /* -=[Receive Response Phase]=- */
+     447                 :         89 :     status = libspdm_acquire_receiver_buffer (spdm_context, &message_size, (void **)&message);
+     448         [ +  + ]:         89 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     449                 :          1 :         libspdm_secured_message_dhe_free(
+     450                 :          1 :             spdm_context->connection_info.algorithm.dhe_named_group, dhe_context);
+     451                 :          1 :         return status;
+     452                 :            :     }
+     453         [ -  + ]:         88 :     LIBSPDM_ASSERT (message_size >= transport_header_size);
+     454                 :         88 :     spdm_response = (void *)(message);
+     455                 :         88 :     spdm_response_size = message_size;
+     456                 :            : 
+     457                 :         88 :     status = libspdm_receive_spdm_response(
+     458                 :            :         spdm_context, NULL, &spdm_response_size, (void **)&spdm_response);
+     459         [ -  + ]:         88 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     460                 :          0 :         libspdm_secured_message_dhe_free(
+     461                 :          0 :             spdm_context->connection_info.algorithm.dhe_named_group, dhe_context);
+     462                 :          0 :         goto receive_done;
+     463                 :            :     }
+     464                 :            : 
+     465                 :            :     /* -=[Validate Response Phase]=- */
+     466         [ -  + ]:         88 :     if (spdm_response_size < sizeof(spdm_message_header_t)) {
+     467                 :          0 :         libspdm_secured_message_dhe_free(
+     468                 :          0 :             spdm_context->connection_info.algorithm.dhe_named_group, dhe_context);
+     469                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     470                 :          0 :         goto receive_done;
+     471                 :            :     }
+     472         [ +  + ]:         88 :     if (spdm_response->header.spdm_version != spdm_request->header.spdm_version) {
+     473                 :          1 :         libspdm_secured_message_dhe_free(
+     474                 :          1 :             spdm_context->connection_info.algorithm.dhe_named_group, dhe_context);
+     475                 :          1 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     476                 :          1 :         goto receive_done;
+     477                 :            :     }
+     478         [ +  + ]:         87 :     if (spdm_response->header.request_response_code == SPDM_ERROR) {
+     479                 :         46 :         status = libspdm_handle_error_response_main(
+     480                 :            :             spdm_context, NULL, &spdm_response_size,
+     481                 :            :             (void **)&spdm_response, SPDM_KEY_EXCHANGE,
+     482                 :            :             SPDM_KEY_EXCHANGE_RSP);
+     483         [ +  + ]:         46 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     484                 :         45 :             libspdm_secured_message_dhe_free(
+     485                 :         45 :                 spdm_context->connection_info.algorithm.dhe_named_group, dhe_context);
+     486                 :         45 :             goto receive_done;
+     487                 :            :         }
+     488         [ +  + ]:         41 :     } else if (spdm_response->header.request_response_code != SPDM_KEY_EXCHANGE_RSP) {
+     489                 :          1 :         libspdm_secured_message_dhe_free(
+     490                 :          1 :             spdm_context->connection_info.algorithm.dhe_named_group, dhe_context);
+     491                 :          1 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     492                 :          1 :         goto receive_done;
+     493                 :            :     }
+     494         [ -  + ]:         41 :     if (spdm_response_size < sizeof(spdm_key_exchange_response_t)) {
+     495                 :          0 :         libspdm_secured_message_dhe_free(
+     496                 :          0 :             spdm_context->connection_info.algorithm.dhe_named_group, dhe_context);
+     497                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     498                 :          0 :         goto receive_done;
+     499                 :            :     }
+     500                 :            : 
+     501         [ +  + ]:         41 :     if (!libspdm_is_capabilities_flag_supported(
+     502                 :            :             spdm_context, true,
+     503                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP,
+     504                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP)) {
+     505         [ +  + ]:         39 :         if (spdm_response->header.param1 != 0) {
+     506                 :          2 :             libspdm_secured_message_dhe_free(
+     507                 :          2 :                 spdm_context->connection_info.algorithm.dhe_named_group, dhe_context);
+     508                 :          2 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     509                 :          2 :             goto receive_done;
+     510                 :            :         }
+     511                 :            :     }
+     512         [ +  + ]:         39 :     if (heartbeat_period != NULL) {
+     513                 :         35 :         *heartbeat_period = spdm_response->header.param1;
+     514                 :            :     }
+     515                 :            : 
+     516                 :         39 :     *req_slot_id_param = spdm_response->req_slot_id_param & 0xf;
+     517                 :         39 :     mut_auth_requested = spdm_response->mut_auth_requested & 0x7;
+     518                 :            : 
+     519         [ +  + ]:         39 :     if (mut_auth_requested != 0) {
+     520                 :         13 :         const bool mut_auth_cap_both = libspdm_is_capabilities_flag_supported(
+     521                 :            :             spdm_context, true,
+     522                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP,
+     523                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP);
+     524                 :         13 :         const bool encap_cap_both = libspdm_is_capabilities_flag_supported(
+     525                 :            :             spdm_context, true,
+     526                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP,
+     527                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP);
+     528                 :         13 :         const bool cert_cap = libspdm_is_capabilities_flag_supported(
+     529                 :            :             spdm_context, true,
+     530                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP,
+     531                 :            :             0);
+     532                 :         13 :         const bool pub_key_id_cap = libspdm_is_capabilities_flag_supported(
+     533                 :            :             spdm_context, true,
+     534                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PUB_KEY_ID_CAP,
+     535                 :            :             0);
+     536                 :            : 
+     537         [ +  + ]:         13 :         if (!mut_auth_cap_both) {
+     538                 :          1 :             libspdm_secured_message_dhe_free(
+     539                 :          1 :                 spdm_context->connection_info.algorithm.dhe_named_group, dhe_context);
+     540                 :          1 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     541                 :          1 :             goto receive_done;
+     542                 :            :         }
+     543   [ +  +  +  + ]:         12 :         if ((mut_auth_requested != SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED) &&
+     544                 :            :             (mut_auth_requested !=
+     545         [ +  + ]:          7 :              SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_ENCAP_REQUEST) &&
+     546                 :            :             (mut_auth_requested !=
+     547                 :            :              SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_GET_DIGESTS)) {
+     548                 :          6 :             libspdm_secured_message_dhe_free(
+     549                 :          6 :                 spdm_context->connection_info.algorithm.dhe_named_group, dhe_context);
+     550                 :          6 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     551                 :          6 :             goto receive_done;
+     552                 :            :         }
+     553                 :            : 
+     554         [ +  + ]:          6 :         if (mut_auth_requested == SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED) {
+     555                 :            :             /* Non-encapsulated flow.
+     556                 :            :              * Requester has either CERT_CAP or PUB_KEY_ID_CAP set. */
+     557                 :            : 
+     558   [ +  +  -  +  :          2 :             if ((cert_cap && (*req_slot_id_param >= SPDM_MAX_SLOT_COUNT)) ||
+                   -  + ]
+     559         [ #  # ]:          0 :                 (pub_key_id_cap && (*req_slot_id_param != 0xf))) {
+     560                 :          1 :                 libspdm_secured_message_dhe_free(
+     561                 :          1 :                     spdm_context->connection_info.algorithm.dhe_named_group, dhe_context);
+     562                 :          1 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     563                 :          1 :                 goto receive_done;
+     564                 :            :             }
+     565         [ -  + ]:          1 :             if ((spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) &&
+     566         [ #  # ]:          0 :                 spdm_context->connection_info.multi_key_conn_req &&
+     567         [ #  # ]:          0 :                 (*req_slot_id_param != 0xf)) {
+     568         [ #  # ]:          0 :                 if ((spdm_context->local_context.local_key_usage_bit_mask[*req_slot_id_param] &
+     569                 :            :                      SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE) == 0) {
+     570                 :          0 :                     libspdm_secured_message_dhe_free(
+     571                 :          0 :                         spdm_context->connection_info.algorithm.dhe_named_group, dhe_context);
+     572                 :          0 :                     status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     573                 :          0 :                     goto receive_done;
+     574                 :            :                 }
+     575                 :            :             }
+     576                 :            :         } else {
+     577                 :            :             /* Encapsulated flow. */
+     578                 :            : 
+     579                 :            :             /* If Responder has Requester's public key then it cannot use the encapsulated flow. */
+     580         [ +  + ]:          4 :             if (pub_key_id_cap) {
+     581                 :          1 :                 libspdm_secured_message_dhe_free(
+     582                 :          1 :                     spdm_context->connection_info.algorithm.dhe_named_group, dhe_context);
+     583                 :          1 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     584                 :          1 :                 goto receive_done;
+     585                 :            :             }
+     586                 :            :             /* Encapsulated flow requires ENCAP_CAP for both endpoints. */
+     587         [ +  + ]:          3 :             if (!encap_cap_both) {
+     588                 :          1 :                 libspdm_secured_message_dhe_free(
+     589                 :          1 :                     spdm_context->connection_info.algorithm.dhe_named_group, dhe_context);
+     590                 :          1 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     591                 :          1 :                 goto receive_done;
+     592                 :            :             }
+     593                 :            :         }
+     594                 :            :     }
+     595                 :            : 
+     596                 :         29 :     signature_size = libspdm_get_asym_signature_size(
+     597                 :            :         spdm_context->connection_info.algorithm.base_asym_algo);
+     598                 :         29 :     measurement_summary_hash_size = libspdm_get_measurement_summary_hash_size(
+     599                 :            :         spdm_context, true, measurement_hash_type);
+     600                 :         29 :     hmac_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+     601                 :            : 
+     602         [ +  + ]:         29 :     if (libspdm_is_capabilities_flag_supported(
+     603                 :            :             spdm_context, true,
+     604                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP,
+     605                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)) {
+     606                 :          1 :         hmac_size = 0;
+     607                 :            :     }
+     608                 :            : 
+     609                 :         29 :     if (spdm_response_size <
+     610                 :         29 :         sizeof(spdm_key_exchange_response_t) + dhe_key_size +
+     611         [ +  + ]:         29 :         measurement_summary_hash_size + sizeof(uint16_t) + signature_size + hmac_size) {
+     612                 :          4 :         libspdm_secured_message_dhe_free(
+     613                 :          4 :             spdm_context->connection_info.algorithm.dhe_named_group, dhe_context);
+     614                 :          4 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     615                 :          4 :         goto receive_done;
+     616                 :            :     }
+     617                 :            : 
+     618                 :         25 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "ResponderRandomData (0x%x) - ", SPDM_RANDOM_DATA_SIZE));
+     619                 :         25 :     LIBSPDM_INTERNAL_DUMP_DATA(spdm_response->random_data, SPDM_RANDOM_DATA_SIZE);
+     620                 :         25 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     621         [ +  + ]:         25 :     if (responder_random != NULL) {
+     622                 :          1 :         libspdm_copy_mem(responder_random, SPDM_RANDOM_DATA_SIZE,
+     623                 :          1 :                          spdm_response->random_data, SPDM_RANDOM_DATA_SIZE);
+     624                 :            :     }
+     625                 :            : 
+     626                 :         25 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "ResponderKey (0x%zx):\n", dhe_key_size));
+     627                 :         25 :     LIBSPDM_INTERNAL_DUMP_HEX(spdm_response->exchange_data, dhe_key_size);
+     628                 :            : 
+     629                 :         25 :     ptr = spdm_response->exchange_data;
+     630                 :         25 :     ptr += dhe_key_size;
+     631                 :            : 
+     632                 :         25 :     measurement_summary_hash = ptr;
+     633                 :         25 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "measurement_summary_hash (0x%x) - ",
+     634                 :            :                    measurement_summary_hash_size));
+     635                 :         25 :     LIBSPDM_INTERNAL_DUMP_DATA(measurement_summary_hash, measurement_summary_hash_size);
+     636                 :         25 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     637                 :            : 
+     638                 :         25 :     ptr += measurement_summary_hash_size;
+     639                 :            : 
+     640                 :         25 :     opaque_length = libspdm_read_uint16((const uint8_t *)ptr);
+     641         [ +  + ]:         25 :     if (opaque_length > SPDM_MAX_OPAQUE_DATA_SIZE) {
+     642                 :          1 :         libspdm_secured_message_dhe_free(
+     643                 :          1 :             spdm_context->connection_info.algorithm.dhe_named_group, dhe_context);
+     644                 :          1 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     645                 :          1 :         goto receive_done;
+     646                 :            :     }
+     647                 :         24 :     ptr += sizeof(uint16_t);
+     648                 :         24 :     if (spdm_response_size <
+     649                 :         24 :         sizeof(spdm_key_exchange_response_t) + dhe_key_size +
+     650                 :         24 :         measurement_summary_hash_size + sizeof(uint16_t) +
+     651         [ +  + ]:         24 :         opaque_length + signature_size + hmac_size) {
+     652                 :          2 :         libspdm_secured_message_dhe_free(
+     653                 :          2 :             spdm_context->connection_info.algorithm.dhe_named_group, dhe_context);
+     654                 :          2 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     655                 :          2 :         goto receive_done;
+     656                 :            :     }
+     657         [ +  - ]:         22 :     if (opaque_length != 0) {
+     658                 :         22 :         result = libspdm_process_general_opaque_data_check(spdm_context, opaque_length, ptr);
+     659         [ -  + ]:         22 :         if (!result) {
+     660                 :          0 :             libspdm_secured_message_dhe_free(
+     661                 :          0 :                 spdm_context->connection_info.algorithm.dhe_named_group, dhe_context);
+     662                 :          0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     663                 :          0 :             goto receive_done;
+     664                 :            :         }
+     665                 :         22 :         status = libspdm_process_opaque_data_version_selection_data(
+     666                 :            :             spdm_context, opaque_length, ptr);
+     667         [ -  + ]:         22 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     668                 :          0 :             libspdm_secured_message_dhe_free(
+     669                 :          0 :                 spdm_context->connection_info.algorithm.dhe_named_group, dhe_context);
+     670                 :          0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     671                 :          0 :             goto receive_done;
+     672                 :            :         }
+     673                 :            :     }
+     674                 :            : 
+     675   [ +  +  +  - ]:         22 :     if ((responder_opaque_data != NULL) && (responder_opaque_data_size != NULL)) {
+     676         [ -  + ]:          1 :         if (opaque_length >= *responder_opaque_data_size) {
+     677                 :          0 :             libspdm_secured_message_dhe_free(
+     678                 :          0 :                 spdm_context->connection_info.algorithm.dhe_named_group, dhe_context);
+     679                 :          0 :             status = LIBSPDM_STATUS_BUFFER_TOO_SMALL;
+     680                 :          0 :             goto receive_done;
+     681                 :            :         }
+     682                 :          1 :         libspdm_copy_mem(responder_opaque_data, *responder_opaque_data_size, ptr, opaque_length);
+     683                 :          1 :         *responder_opaque_data_size = opaque_length;
+     684                 :            :     }
+     685                 :            : 
+     686                 :         22 :     ptr += opaque_length;
+     687                 :            : 
+     688                 :         22 :     spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+     689                 :         22 :                          dhe_key_size + measurement_summary_hash_size +
+     690                 :         22 :                          sizeof(uint16_t) + opaque_length + signature_size + hmac_size;
+     691                 :            : 
+     692                 :         22 :     rsp_session_id = spdm_response->rsp_session_id;
+     693                 :         22 :     *session_id = libspdm_generate_session_id(req_session_id, rsp_session_id);
+     694                 :         22 :     session_info = libspdm_assign_session_id(spdm_context, *session_id, false);
+     695                 :            : 
+     696         [ -  + ]:         22 :     if (session_info == NULL) {
+     697                 :          0 :         libspdm_secured_message_dhe_free(
+     698                 :          0 :             spdm_context->connection_info.algorithm.dhe_named_group, dhe_context);
+     699                 :          0 :         status = LIBSPDM_STATUS_SESSION_NUMBER_EXCEED;
+     700                 :          0 :         goto receive_done;
+     701                 :            :     }
+     702                 :            : 
+     703                 :            :     /* -=[Process Response Phase]=- */
+     704                 :         22 :     status = libspdm_append_message_k(spdm_context, session_info, true, spdm_request,
+     705                 :            :                                       spdm_request_size);
+     706         [ -  + ]:         22 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     707                 :          0 :         libspdm_free_session_id(spdm_context, *session_id);
+     708                 :          0 :         libspdm_secured_message_dhe_free(
+     709                 :          0 :             spdm_context->connection_info.algorithm.dhe_named_group, dhe_context);
+     710                 :          0 :         goto receive_done;
+     711                 :            :     }
+     712                 :            : 
+     713                 :         22 :     status = libspdm_append_message_k(spdm_context, session_info, true, spdm_response,
+     714                 :         22 :                                       spdm_response_size - signature_size - hmac_size);
+     715         [ -  + ]:         22 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     716                 :          0 :         libspdm_free_session_id(spdm_context, *session_id);
+     717                 :          0 :         libspdm_secured_message_dhe_free(
+     718                 :          0 :             spdm_context->connection_info.algorithm.dhe_named_group, dhe_context);
+     719                 :          0 :         goto receive_done;
+     720                 :            :     }
+     721                 :            : 
+     722                 :         22 :     signature = ptr;
+     723                 :         22 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "signature (0x%x):\n", signature_size));
+     724                 :         22 :     LIBSPDM_INTERNAL_DUMP_HEX(signature, signature_size);
+     725                 :         22 :     ptr += signature_size;
+     726                 :         22 :     result = libspdm_verify_key_exchange_rsp_signature(
+     727                 :            :         spdm_context, session_info, signature, signature_size);
+     728         [ +  + ]:         22 :     if (!result) {
+     729                 :          2 :         libspdm_free_session_id(spdm_context, *session_id);
+     730                 :          2 :         libspdm_secured_message_dhe_free(
+     731                 :          2 :             spdm_context->connection_info.algorithm.dhe_named_group, dhe_context);
+     732                 :          2 :         status = LIBSPDM_STATUS_VERIF_FAIL;
+     733                 :          2 :         goto receive_done;
+     734                 :            :     }
+     735                 :            : 
+     736                 :         20 :     status = libspdm_append_message_k(spdm_context, session_info, true, signature, signature_size);
+     737         [ -  + ]:         20 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     738                 :          0 :         libspdm_free_session_id(spdm_context, *session_id);
+     739                 :          0 :         libspdm_secured_message_dhe_free(
+     740                 :          0 :             spdm_context->connection_info.algorithm.dhe_named_group, dhe_context);
+     741                 :          0 :         goto receive_done;
+     742                 :            :     }
+     743                 :            : 
+     744                 :         20 :     result = libspdm_secured_message_dhe_compute_key(
+     745                 :         20 :         spdm_context->connection_info.algorithm.dhe_named_group,
+     746                 :         20 :         dhe_context, spdm_response->exchange_data, dhe_key_size,
+     747                 :            :         session_info->secured_message_context);
+     748                 :         20 :     libspdm_secured_message_dhe_free(
+     749                 :         20 :         spdm_context->connection_info.algorithm.dhe_named_group, dhe_context);
+     750         [ -  + ]:         20 :     if (!result) {
+     751                 :          0 :         libspdm_free_session_id(spdm_context, *session_id);
+     752                 :          0 :         status = LIBSPDM_STATUS_CRYPTO_ERROR;
+     753                 :          0 :         goto receive_done;
+     754                 :            :     }
+     755                 :            : 
+     756                 :         20 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "libspdm_generate_session_handshake_key[%x]\n",
+     757                 :            :                    *session_id));
+     758                 :         20 :     result = libspdm_calculate_th1_hash(spdm_context, session_info, true, th1_hash_data);
+     759         [ -  + ]:         20 :     if (!result) {
+     760                 :          0 :         libspdm_free_session_id(spdm_context, *session_id);
+     761                 :          0 :         status = LIBSPDM_STATUS_CRYPTO_ERROR;
+     762                 :          0 :         goto receive_done;
+     763                 :            :     }
+     764                 :         20 :     result = libspdm_generate_session_handshake_key(
+     765                 :            :         session_info->secured_message_context, th1_hash_data);
+     766         [ -  + ]:         20 :     if (!result) {
+     767                 :          0 :         libspdm_free_session_id(spdm_context, *session_id);
+     768                 :          0 :         status = LIBSPDM_STATUS_CRYPTO_ERROR;
+     769                 :          0 :         goto receive_done;
+     770                 :            :     }
+     771                 :            : 
+     772         [ +  + ]:         20 :     if (!libspdm_is_capabilities_flag_supported(
+     773                 :            :             spdm_context, true,
+     774                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP,
+     775                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)) {
+     776                 :         19 :         verify_data = ptr;
+     777                 :         19 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "verify_data (0x%x):\n", hmac_size));
+     778                 :         19 :         LIBSPDM_INTERNAL_DUMP_HEX(verify_data, hmac_size);
+     779                 :         19 :         result = libspdm_verify_key_exchange_rsp_hmac(
+     780                 :            :             spdm_context, session_info, verify_data, hmac_size);
+     781         [ -  + ]:         19 :         if (!result) {
+     782                 :          0 :             libspdm_free_session_id(spdm_context, *session_id);
+     783                 :          0 :             status = LIBSPDM_STATUS_VERIF_FAIL;
+     784                 :          0 :             goto receive_done;
+     785                 :            :         }
+     786                 :         19 :         ptr += hmac_size;
+     787                 :            : 
+     788                 :         19 :         status = libspdm_append_message_k(spdm_context, session_info, true, verify_data, hmac_size);
+     789         [ -  + ]:         19 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     790                 :          0 :             libspdm_free_session_id(spdm_context, *session_id);
+     791                 :          0 :             goto receive_done;
+     792                 :            :         }
+     793                 :            :     }
+     794                 :            : 
+     795         [ +  - ]:         20 :     if (measurement_hash != NULL) {
+     796                 :         20 :         libspdm_copy_mem(measurement_hash, measurement_summary_hash_size,
+     797                 :            :                          measurement_summary_hash, measurement_summary_hash_size);
+     798                 :            :     }
+     799                 :         20 :     session_info->heartbeat_period = spdm_response->header.param1;
+     800                 :         20 :     session_info->mut_auth_requested = mut_auth_requested;
+     801                 :         20 :     session_info->session_policy = session_policy;
+     802                 :            : 
+     803                 :            :     /* -=[Update State Phase]=- */
+     804                 :         20 :     libspdm_secured_message_set_session_state(
+     805                 :            :         session_info->secured_message_context, LIBSPDM_SESSION_STATE_HANDSHAKING);
+     806                 :            : 
+     807                 :            :     /* -=[Log Message Phase]=- */
+     808                 :            :     #if LIBSPDM_ENABLE_MSG_LOG
+     809                 :         20 :     libspdm_append_msg_log(spdm_context, spdm_response, spdm_response_size);
+     810                 :            :     #endif /* LIBSPDM_ENABLE_MSG_LOG */
+     811                 :            : 
+     812                 :         20 :     status = LIBSPDM_STATUS_SUCCESS;
+     813                 :            : 
+     814                 :         88 : receive_done:
+     815                 :         88 :     libspdm_release_receiver_buffer (spdm_context);
+     816                 :         88 :     return status;
+     817                 :            : }
+     818                 :            : 
+     819                 :         93 : libspdm_return_t libspdm_send_receive_key_exchange(
+     820                 :            :     libspdm_context_t *spdm_context, uint8_t measurement_hash_type,
+     821                 :            :     uint8_t slot_id, uint8_t session_policy, uint32_t *session_id,
+     822                 :            :     uint8_t *heartbeat_period,
+     823                 :            :     uint8_t *req_slot_id_param, void *measurement_hash)
+     824                 :            : {
+     825                 :            :     size_t retry;
+     826                 :            :     uint64_t retry_delay_time;
+     827                 :            :     libspdm_return_t status;
+     828                 :            : 
+     829                 :         93 :     spdm_context->crypto_request = true;
+     830                 :         93 :     retry = spdm_context->retry_times;
+     831                 :         93 :     retry_delay_time = spdm_context->retry_delay_time;
+     832                 :            :     do {
+     833                 :         94 :         status = libspdm_try_send_receive_key_exchange(
+     834                 :            :             spdm_context, measurement_hash_type, slot_id, session_policy,
+     835                 :            :             session_id, heartbeat_period, req_slot_id_param,
+     836                 :            :             measurement_hash,
+     837                 :            :             NULL, NULL, NULL, NULL, 0, NULL, NULL);
+     838         [ +  + ]:         94 :         if (status != LIBSPDM_STATUS_BUSY_PEER) {
+     839                 :         91 :             return status;
+     840                 :            :         }
+     841                 :            : 
+     842                 :          3 :         libspdm_sleep(retry_delay_time);
+     843         [ +  + ]:          3 :     } while (retry-- != 0);
+     844                 :            : 
+     845                 :          2 :     return status;
+     846                 :            : }
+     847                 :            : 
+     848                 :          1 : libspdm_return_t libspdm_send_receive_key_exchange_ex(
+     849                 :            :     libspdm_context_t *spdm_context, uint8_t measurement_hash_type,
+     850                 :            :     uint8_t slot_id, uint8_t session_policy, uint32_t *session_id,
+     851                 :            :     uint8_t *heartbeat_period,
+     852                 :            :     uint8_t *req_slot_id_param, void *measurement_hash,
+     853                 :            :     const void *requester_random_in,
+     854                 :            :     void *requester_random, void *responder_random,
+     855                 :            :     const void *requester_opaque_data,
+     856                 :            :     size_t requester_opaque_data_size,
+     857                 :            :     void *responder_opaque_data,
+     858                 :            :     size_t *responder_opaque_data_size)
+     859                 :            : {
+     860                 :            :     size_t retry;
+     861                 :            :     uint64_t retry_delay_time;
+     862                 :            :     libspdm_return_t status;
+     863                 :            : 
+     864                 :          1 :     spdm_context->crypto_request = true;
+     865                 :          1 :     retry = spdm_context->retry_times;
+     866                 :          1 :     retry_delay_time = spdm_context->retry_delay_time;
+     867                 :            :     do {
+     868                 :          1 :         status = libspdm_try_send_receive_key_exchange(
+     869                 :            :             spdm_context, measurement_hash_type, slot_id, session_policy,
+     870                 :            :             session_id, heartbeat_period, req_slot_id_param,
+     871                 :            :             measurement_hash, requester_random_in,
+     872                 :            :             requester_random, responder_random,
+     873                 :            :             requester_opaque_data, requester_opaque_data_size,
+     874                 :            :             responder_opaque_data, responder_opaque_data_size);
+     875         [ +  - ]:          1 :         if (status != LIBSPDM_STATUS_BUSY_PEER) {
+     876                 :          1 :             return status;
+     877                 :            :         }
+     878                 :            : 
+     879                 :          0 :         libspdm_sleep(retry_delay_time);
+     880         [ #  # ]:          0 :     } while (retry-- != 0);
+     881                 :            : 
+     882                 :          0 :     return status;
+     883                 :            : }
+     884                 :            : 
+     885                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_key_update.c.func-sort-c.html b/coverage_log/library/spdm_requester_lib/libspdm_req_key_update.c.func-sort-c.html new file mode 100644 index 00000000000..71ba9e34ff7 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_key_update.c.func-sort-c.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_key_update.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_key_update.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:13116380.4 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:689472.3 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_key_update83
libspdm_try_key_update92
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_key_update.c.func.html b/coverage_log/library/spdm_requester_lib/libspdm_req_key_update.c.func.html new file mode 100644 index 00000000000..c3eb6e10575 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_key_update.c.func.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_key_update.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_key_update.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:13116380.4 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:689472.3 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_key_update83
libspdm_try_key_update92
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_key_update.c.gcov.html b/coverage_log/library/spdm_requester_lib/libspdm_req_key_update.c.gcov.html new file mode 100644 index 00000000000..2610287d173 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_key_update.c.gcov.html @@ -0,0 +1,436 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_key_update.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_key_update.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:13116380.4 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:689472.3 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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                 :            : #include "internal/libspdm_secured_message_lib.h"
+       9                 :            : 
+      10                 :            : #pragma pack(1)
+      11                 :            : typedef struct {
+      12                 :            :     spdm_message_header_t header;
+      13                 :            :     uint8_t dummy_data[sizeof(spdm_error_data_response_not_ready_t)];
+      14                 :            : } libspdm_key_update_response_mine_t;
+      15                 :            : #pragma pack()
+      16                 :            : 
+      17                 :            : /**
+      18                 :            :  * This function sends KEY_UPDATE
+      19                 :            :  * to update keys for an SPDM Session.
+      20                 :            :  *
+      21                 :            :  * After keys are updated, this function also uses VERIFY_NEW_KEY to verify the key.
+      22                 :            :  *
+      23                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+      24                 :            :  * @param  session_id                    The session ID of the session.
+      25                 :            :  * @param  single_direction              true means the operation is UPDATE_KEY.
+      26                 :            :  *                                     false means the operation is UPDATE_ALL_KEYS.
+      27                 :            :  * @param  key_updated                   true means the operation is to verify key(s).
+      28                 :            :  *                                     false means the operation is to update and verify key(s).
+      29                 :            :  *
+      30                 :            :  * @retval RETURN_SUCCESS               The keys of the session are updated.
+      31                 :            :  * @retval RETURN_DEVICE_ERROR          A device error occurs when communicates with the device.
+      32                 :            :  * @retval RETURN_SECURITY_VIOLATION    Any verification fails.
+      33                 :            :  **/
+      34                 :         92 : static libspdm_return_t libspdm_try_key_update(libspdm_context_t *spdm_context,
+      35                 :            :                                                uint32_t session_id,
+      36                 :            :                                                bool single_direction, bool *key_updated)
+      37                 :            : {
+      38                 :            :     libspdm_return_t status;
+      39                 :            :     bool result;
+      40                 :            :     spdm_key_update_request_t *spdm_request;
+      41                 :            :     size_t spdm_request_size;
+      42                 :            :     libspdm_key_update_response_mine_t *spdm_response;
+      43                 :            :     size_t spdm_response_size;
+      44                 :            :     libspdm_session_info_t *session_info;
+      45                 :            :     libspdm_session_state_t session_state;
+      46                 :            :     uint8_t *message;
+      47                 :            :     size_t message_size;
+      48                 :            :     size_t transport_header_size;
+      49                 :            : 
+      50         [ -  + ]:         92 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_11) {
+      51                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+      52                 :            :     }
+      53                 :            : 
+      54         [ +  + ]:         92 :     if (!libspdm_is_capabilities_flag_supported(
+      55                 :            :             spdm_context, true,
+      56                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP,
+      57                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_UPD_CAP)) {
+      58                 :          1 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+      59                 :            :     }
+      60                 :            : 
+      61         [ +  + ]:         91 :     if (spdm_context->connection_info.connection_state <
+      62                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
+      63                 :          1 :         return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+      64                 :            :     }
+      65                 :            :     session_info =
+      66                 :         90 :         libspdm_get_session_info_via_session_id(spdm_context, session_id);
+      67         [ -  + ]:         90 :     if (session_info == NULL) {
+      68                 :          0 :         LIBSPDM_ASSERT(false);
+      69                 :          0 :         return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+      70                 :            :     }
+      71                 :         90 :     session_state = libspdm_secured_message_get_session_state(
+      72                 :            :         session_info->secured_message_context);
+      73         [ +  + ]:         90 :     if (session_state != LIBSPDM_SESSION_STATE_ESTABLISHED) {
+      74                 :          1 :         return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+      75                 :            :     }
+      76                 :            : 
+      77                 :         89 :     libspdm_reset_message_buffer_via_request_code(spdm_context, session_info, SPDM_KEY_UPDATE);
+      78                 :            : 
+      79         [ +  + ]:         89 :     if(!(*key_updated)) {
+      80                 :            : 
+      81                 :            :         /* Update key*/
+      82                 :            : 
+      83                 :         85 :         transport_header_size = spdm_context->local_context.capability.transport_header_size;
+      84                 :         85 :         status = libspdm_acquire_sender_buffer (spdm_context, &message_size, (void **)&message);
+      85         [ -  + ]:         85 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+      86                 :          0 :             return status;
+      87                 :            :         }
+      88         [ -  + ]:         85 :         LIBSPDM_ASSERT (message_size >= transport_header_size +
+      89                 :            :                         spdm_context->local_context.capability.transport_tail_size);
+      90                 :         85 :         spdm_request = (void *)(message + transport_header_size);
+      91                 :         85 :         spdm_request_size = message_size - transport_header_size -
+      92                 :         85 :                             spdm_context->local_context.capability.transport_tail_size;
+      93                 :            : 
+      94         [ -  + ]:         85 :         LIBSPDM_ASSERT (spdm_request_size >= sizeof(spdm_key_update_request_t));
+      95                 :         85 :         spdm_request->header.spdm_version = libspdm_get_connection_version (spdm_context);
+      96                 :         85 :         spdm_request->header.request_response_code = SPDM_KEY_UPDATE;
+      97         [ +  + ]:         85 :         if (single_direction) {
+      98                 :         57 :             spdm_request->header.param1 = SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY;
+      99                 :            :         } else {
+     100                 :         28 :             spdm_request->header.param1 = SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_ALL_KEYS;
+     101                 :            :         }
+     102                 :         85 :         spdm_request->header.param2 = 0;
+     103                 :            : 
+     104         [ -  + ]:         85 :         if(!libspdm_get_random_number(sizeof(spdm_request->header.param2),
+     105                 :            :                                       &spdm_request->header.param2)) {
+     106                 :          0 :             libspdm_release_sender_buffer (spdm_context);
+     107                 :          0 :             return LIBSPDM_STATUS_LOW_ENTROPY;
+     108                 :            :         }
+     109                 :            : 
+     110                 :         85 :         spdm_request_size = sizeof(spdm_key_update_request_t);
+     111                 :            : 
+     112                 :            :         /* If updating both, create new responder key*/
+     113         [ +  + ]:         85 :         if (!single_direction) {
+     114                 :         28 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+     115                 :            :                            "libspdm_create_update_session_data_key[%x] Responder\n",
+     116                 :            :                            session_id));
+     117                 :         28 :             result = libspdm_create_update_session_data_key(
+     118                 :            :                 session_info->secured_message_context,
+     119                 :            :                 LIBSPDM_KEY_UPDATE_ACTION_RESPONDER);
+     120         [ -  + ]:         28 :             if (!result) {
+     121                 :          0 :                 libspdm_release_sender_buffer (spdm_context);
+     122                 :          0 :                 return LIBSPDM_STATUS_CRYPTO_ERROR;
+     123                 :            :             }
+     124                 :            :         }
+     125                 :            : 
+     126                 :         85 :         status = libspdm_send_spdm_request(spdm_context, &session_id,
+     127                 :            :                                            spdm_request_size, spdm_request);
+     128         [ +  + ]:         85 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     129                 :          1 :             libspdm_release_sender_buffer (spdm_context);
+     130                 :          1 :             return status;
+     131                 :            :         }
+     132                 :            : 
+     133                 :         84 :         libspdm_release_sender_buffer (spdm_context);
+     134                 :         84 :         spdm_request = (void *)spdm_context->last_spdm_request;
+     135                 :            : 
+     136                 :            :         /* receive */
+     137                 :            : 
+     138                 :         84 :         status = libspdm_acquire_receiver_buffer (spdm_context, &message_size, (void **)&message);
+     139         [ -  + ]:         84 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     140                 :          0 :             return status;
+     141                 :            :         }
+     142         [ -  + ]:         84 :         LIBSPDM_ASSERT (message_size >= transport_header_size);
+     143                 :         84 :         spdm_response = (void *)(message);
+     144                 :         84 :         spdm_response_size = message_size;
+     145                 :            : 
+     146                 :         84 :         status = libspdm_receive_spdm_response(
+     147                 :            :             spdm_context, &session_id, &spdm_response_size, (void **)&spdm_response);
+     148                 :            : 
+     149         [ +  - ]:         84 :         if (!LIBSPDM_STATUS_IS_ERROR(status)) {
+     150         [ +  + ]:         84 :             if (spdm_response->header.request_response_code == SPDM_ERROR) {
+     151                 :         50 :                 status = libspdm_handle_error_response_main(
+     152                 :            :                     spdm_context, &session_id,
+     153                 :            :                     &spdm_response_size, (void **)&spdm_response,
+     154                 :            :                     SPDM_KEY_UPDATE, SPDM_KEY_UPDATE_ACK);
+     155         [ -  + ]:         34 :             } else if (spdm_response_size != sizeof(spdm_key_update_response_t)) {
+     156                 :            :                 /* this message can only be in secured session thus
+     157                 :            :                  * don't need to consider transport layer padding, just check its exact size */
+     158                 :          0 :                 status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     159         [ -  + ]:         34 :             } else if (spdm_response->header.spdm_version != spdm_request->header.spdm_version) {
+     160                 :          0 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     161         [ +  + ]:         34 :             } else if ((spdm_response->header.request_response_code !=
+     162                 :         33 :                         SPDM_KEY_UPDATE_ACK) ||
+     163         [ +  + ]:         33 :                        (spdm_response->header.param1 != spdm_request->header.param1) ||
+     164         [ +  + ]:         32 :                        (spdm_response->header.param2 != spdm_request->header.param2)) {
+     165                 :          3 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     166                 :            :             }
+     167                 :            :         }
+     168                 :            : 
+     169         [ +  + ]:         84 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     170         [ +  + ]:         51 :             if (!single_direction) {
+     171                 :         25 :                 LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+     172                 :            :                                "libspdm_activate_update_session_data_key[%x] Responder old\n",
+     173                 :            :                                session_id));
+     174                 :         25 :                 result = libspdm_activate_update_session_data_key(
+     175                 :            :                     session_info->secured_message_context,
+     176                 :            :                     LIBSPDM_KEY_UPDATE_ACTION_RESPONDER, false);
+     177         [ -  + ]:         25 :                 if (!result) {
+     178                 :          0 :                     libspdm_release_receiver_buffer (spdm_context);
+     179                 :          0 :                     return LIBSPDM_STATUS_CRYPTO_ERROR;
+     180                 :            :                 }
+     181                 :            :             }
+     182                 :         51 :             libspdm_release_receiver_buffer (spdm_context);
+     183                 :         51 :             return status;
+     184                 :            :         }
+     185                 :            : 
+     186         [ +  + ]:         33 :         if (!single_direction) {
+     187                 :          3 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+     188                 :            :                            "libspdm_activate_update_session_data_key[%x] Responder new\n",
+     189                 :            :                            session_id));
+     190                 :          3 :             result = libspdm_activate_update_session_data_key(
+     191                 :            :                 session_info->secured_message_context,
+     192                 :            :                 LIBSPDM_KEY_UPDATE_ACTION_RESPONDER, true);
+     193         [ -  + ]:          3 :             if (!result) {
+     194                 :          0 :                 libspdm_release_receiver_buffer (spdm_context);
+     195                 :          0 :                 return LIBSPDM_STATUS_CRYPTO_ERROR;
+     196                 :            :             }
+     197                 :            :         }
+     198                 :            : 
+     199                 :         33 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+     200                 :            :                        "libspdm_create_update_session_data_key[%x] Requester\n",
+     201                 :            :                        session_id));
+     202                 :         33 :         result = libspdm_create_update_session_data_key(
+     203                 :            :             session_info->secured_message_context,
+     204                 :            :             LIBSPDM_KEY_UPDATE_ACTION_REQUESTER);
+     205         [ -  + ]:         33 :         if (!result) {
+     206                 :          0 :             libspdm_release_receiver_buffer (spdm_context);
+     207                 :          0 :             return LIBSPDM_STATUS_CRYPTO_ERROR;
+     208                 :            :         }
+     209                 :         33 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+     210                 :            :                        "libspdm_activate_update_session_data_key[%x] Requester new\n",
+     211                 :            :                        session_id));
+     212                 :         33 :         result = libspdm_activate_update_session_data_key(
+     213                 :            :             session_info->secured_message_context,
+     214                 :            :             LIBSPDM_KEY_UPDATE_ACTION_REQUESTER, true);
+     215         [ -  + ]:         33 :         if (!result) {
+     216                 :          0 :             libspdm_release_receiver_buffer (spdm_context);
+     217                 :          0 :             return LIBSPDM_STATUS_CRYPTO_ERROR;
+     218                 :            :         }
+     219                 :            : 
+     220                 :            :         /* -=[Log Message Phase]=- */
+     221                 :            :         #if LIBSPDM_ENABLE_MSG_LOG
+     222                 :         33 :         libspdm_append_msg_log(spdm_context, spdm_response, spdm_response_size);
+     223                 :            :         #endif /* LIBSPDM_ENABLE_MSG_LOG */
+     224                 :            : 
+     225                 :         33 :         libspdm_release_receiver_buffer (spdm_context);
+     226                 :            :     }
+     227                 :            : 
+     228                 :         37 :     *key_updated = true;
+     229                 :            : 
+     230                 :            : 
+     231                 :            :     /* Verify key*/
+     232                 :            : 
+     233                 :         37 :     transport_header_size = spdm_context->local_context.capability.transport_header_size;
+     234                 :         37 :     status = libspdm_acquire_sender_buffer (spdm_context, &message_size, (void **)&message);
+     235         [ -  + ]:         37 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     236                 :          0 :         return status;
+     237                 :            :     }
+     238         [ -  + ]:         37 :     LIBSPDM_ASSERT (message_size >= transport_header_size +
+     239                 :            :                     spdm_context->local_context.capability.transport_tail_size);
+     240                 :         37 :     spdm_request = (void *)(message + transport_header_size);
+     241                 :         37 :     spdm_request_size = message_size - transport_header_size -
+     242                 :         37 :                         spdm_context->local_context.capability.transport_tail_size;
+     243                 :            : 
+     244         [ -  + ]:         37 :     LIBSPDM_ASSERT (spdm_request_size >= sizeof(spdm_key_update_request_t));
+     245                 :         37 :     spdm_request->header.spdm_version = libspdm_get_connection_version (spdm_context);
+     246                 :         37 :     spdm_request->header.request_response_code = SPDM_KEY_UPDATE;
+     247                 :         37 :     spdm_request->header.param1 = SPDM_KEY_UPDATE_OPERATIONS_TABLE_VERIFY_NEW_KEY;
+     248                 :         37 :     spdm_request->header.param2 = 1;
+     249         [ -  + ]:         37 :     if(!libspdm_get_random_number(sizeof(spdm_request->header.param2),
+     250                 :            :                                   &spdm_request->header.param2)) {
+     251                 :          0 :         libspdm_release_sender_buffer (spdm_context);
+     252                 :          0 :         return LIBSPDM_STATUS_LOW_ENTROPY;
+     253                 :            :     }
+     254                 :         37 :     spdm_request_size = sizeof(spdm_key_update_request_t);
+     255                 :            : 
+     256                 :         37 :     status = libspdm_send_spdm_request(spdm_context, &session_id,
+     257                 :            :                                        spdm_request_size, spdm_request);
+     258         [ -  + ]:         37 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     259                 :          0 :         libspdm_release_sender_buffer (spdm_context);
+     260                 :          0 :         return status;
+     261                 :            :     }
+     262                 :         37 :     libspdm_release_sender_buffer (spdm_context);
+     263                 :         37 :     spdm_request = (void *)spdm_context->last_spdm_request;
+     264                 :            : 
+     265                 :            :     /* receive */
+     266                 :            : 
+     267                 :         37 :     status = libspdm_acquire_receiver_buffer (spdm_context, &message_size, (void **)&message);
+     268         [ -  + ]:         37 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     269                 :          0 :         return status;
+     270                 :            :     }
+     271         [ -  + ]:         37 :     LIBSPDM_ASSERT (message_size >= transport_header_size);
+     272                 :         37 :     spdm_response = (void *)(message);
+     273                 :         37 :     spdm_response_size = message_size;
+     274                 :            : 
+     275                 :         37 :     status = libspdm_receive_spdm_response(
+     276                 :            :         spdm_context, &session_id, &spdm_response_size, (void **)&spdm_response);
+     277         [ -  + ]:         37 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     278                 :          0 :         libspdm_release_receiver_buffer (spdm_context);
+     279                 :          0 :         return status;
+     280                 :            :     }
+     281                 :            : 
+     282         [ +  + ]:         37 :     if (spdm_response->header.request_response_code == SPDM_ERROR) {
+     283                 :         26 :         status = libspdm_handle_error_response_main(
+     284                 :            :             spdm_context, &session_id,
+     285                 :            :             &spdm_response_size, (void **)&spdm_response,
+     286                 :            :             SPDM_KEY_UPDATE, SPDM_KEY_UPDATE_ACK);
+     287         [ +  + ]:         26 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     288                 :         25 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "SpdmVerifyKey[%x] Failed\n", session_id));
+     289                 :         25 :             libspdm_release_receiver_buffer (spdm_context);
+     290                 :         25 :             return status;
+     291                 :            :         }
+     292                 :            :     }
+     293                 :            : 
+     294                 :            :     /* this message can only be in secured session
+     295                 :            :      * thus don't need to consider transport layer padding, just check its exact size */
+     296         [ -  + ]:         12 :     if (spdm_response_size != sizeof(spdm_key_update_response_t)) {
+     297                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "SpdmVerifyKey[%x] Failed\n", session_id));
+     298                 :          0 :         libspdm_release_receiver_buffer (spdm_context);
+     299                 :          0 :         return LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     300                 :            :     }
+     301                 :            : 
+     302         [ -  + ]:         12 :     if (spdm_response->header.spdm_version != spdm_request->header.spdm_version) {
+     303                 :          0 :         libspdm_release_receiver_buffer (spdm_context);
+     304                 :          0 :         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     305                 :            :     }
+     306                 :            : 
+     307         [ +  + ]:         12 :     if ((spdm_response->header.request_response_code !=
+     308                 :         11 :          SPDM_KEY_UPDATE_ACK) ||
+     309         [ +  + ]:         11 :         (spdm_response->header.param1 != spdm_request->header.param1) ||
+     310         [ +  + ]:         10 :         (spdm_response->header.param2 != spdm_request->header.param2)) {
+     311                 :          3 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "SpdmVerifyKey[%x] Failed\n", session_id));
+     312                 :          3 :         libspdm_release_receiver_buffer (spdm_context);
+     313                 :          3 :         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     314                 :            :     }
+     315                 :          9 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "SpdmVerifyKey[%x] Success\n", session_id));
+     316                 :            : 
+     317                 :            :     /* -=[Log Message Phase]=- */
+     318                 :            :     #if LIBSPDM_ENABLE_MSG_LOG
+     319                 :          9 :     libspdm_append_msg_log(spdm_context, spdm_response, spdm_response_size);
+     320                 :            :     #endif /* LIBSPDM_ENABLE_MSG_LOG */
+     321                 :            : 
+     322                 :          9 :     libspdm_release_receiver_buffer (spdm_context);
+     323                 :          9 :     return LIBSPDM_STATUS_SUCCESS;
+     324                 :            : }
+     325                 :            : 
+     326                 :         83 : libspdm_return_t libspdm_key_update(void *spdm_context, uint32_t session_id,
+     327                 :            :                                     bool single_direction)
+     328                 :            : {
+     329                 :            :     libspdm_context_t *context;
+     330                 :            :     size_t retry;
+     331                 :            :     uint64_t retry_delay_time;
+     332                 :            :     libspdm_return_t status;
+     333                 :            :     bool key_updated;
+     334                 :            : 
+     335                 :         83 :     context = spdm_context;
+     336                 :         83 :     key_updated = false;
+     337                 :         83 :     context->crypto_request = true;
+     338                 :         83 :     retry = context->retry_times;
+     339                 :         83 :     retry_delay_time = context->retry_delay_time;
+     340                 :            :     do {
+     341                 :         92 :         status = libspdm_try_key_update(spdm_context, session_id,
+     342                 :            :                                         single_direction, &key_updated);
+     343         [ +  + ]:         92 :         if (status != LIBSPDM_STATUS_BUSY_PEER) {
+     344                 :         80 :             return status;
+     345                 :            :         }
+     346                 :            : 
+     347                 :         12 :         libspdm_sleep(retry_delay_time);
+     348         [ +  + ]:         12 :     } while (retry-- != 0);
+     349                 :            : 
+     350                 :          3 :     return status;
+     351                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_negotiate_algorithms.c.func-sort-c.html b/coverage_log/library/spdm_requester_lib/libspdm_req_negotiate_algorithms.c.func-sort-c.html new file mode 100644 index 00000000000..23d5461d97e --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_negotiate_algorithms.c.func-sort-c.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_negotiate_algorithms.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_negotiate_algorithms.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:35438093.2 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:19221987.7 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_negotiate_algorithms86
libspdm_try_negotiate_algorithms87
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_negotiate_algorithms.c.func.html b/coverage_log/library/spdm_requester_lib/libspdm_req_negotiate_algorithms.c.func.html new file mode 100644 index 00000000000..1a733e9c1bb --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_negotiate_algorithms.c.func.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_negotiate_algorithms.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_negotiate_algorithms.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:35438093.2 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:19221987.7 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_negotiate_algorithms86
libspdm_try_negotiate_algorithms87
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_negotiate_algorithms.c.gcov.html b/coverage_log/library/spdm_requester_lib/libspdm_req_negotiate_algorithms.c.gcov.html new file mode 100644 index 00000000000..6e7cbf70c02 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_negotiate_algorithms.c.gcov.html @@ -0,0 +1,752 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_negotiate_algorithms.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_negotiate_algorithms.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:35438093.2 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:19221987.7 %
+
+ + + + + + + + +

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

Function Name Sort by function nameHit count Sort by hit count
libspdm_send_receive_psk_exchange_ex0
libspdm_verify_psk_exchange_rsp_hmac15
libspdm_send_receive_psk_exchange43
libspdm_try_send_receive_psk_exchange44
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_psk_exchange.c.func.html b/coverage_log/library/spdm_requester_lib/libspdm_req_psk_exchange.c.func.html new file mode 100644 index 00000000000..5cf33f32b47 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_psk_exchange.c.func.html @@ -0,0 +1,97 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_psk_exchange.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_psk_exchange.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:19026970.6 %
Date:2024-09-22 08:21:07Functions:3475.0 %
Branches:8714858.8 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_send_receive_psk_exchange43
libspdm_send_receive_psk_exchange_ex0
libspdm_try_send_receive_psk_exchange44
libspdm_verify_psk_exchange_rsp_hmac15
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_psk_exchange.c.gcov.html b/coverage_log/library/spdm_requester_lib/libspdm_req_psk_exchange.c.gcov.html new file mode 100644 index 00000000000..ebbe009491c --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_psk_exchange.c.gcov.html @@ -0,0 +1,735 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_psk_exchange.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_psk_exchange.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:19026970.6 %
Date:2024-09-22 08:21:07Functions:3475.0 %
Branches:8714858.8 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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                 :            : #include "internal/libspdm_secured_message_lib.h"
+       9                 :            : 
+      10                 :            : #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
+      11                 :            : 
+      12                 :            : #pragma pack(1)
+      13                 :            : typedef struct {
+      14                 :            :     spdm_message_header_t header;
+      15                 :            :     uint16_t req_session_id;
+      16                 :            :     uint16_t psk_hint_length;
+      17                 :            :     uint16_t context_length;
+      18                 :            :     uint16_t opaque_length;
+      19                 :            :     uint8_t psk_hint[LIBSPDM_PSK_MAX_HINT_LENGTH];
+      20                 :            :     uint8_t context[LIBSPDM_PSK_CONTEXT_LENGTH];
+      21                 :            :     uint8_t opaque_data[SPDM_MAX_OPAQUE_DATA_SIZE];
+      22                 :            : } libspdm_psk_exchange_request_mine_t;
+      23                 :            : 
+      24                 :            : typedef struct {
+      25                 :            :     spdm_message_header_t header;
+      26                 :            :     uint16_t rsp_session_id;
+      27                 :            :     uint16_t reserved;
+      28                 :            :     uint16_t context_length;
+      29                 :            :     uint16_t opaque_length;
+      30                 :            :     uint8_t measurement_summary_hash[LIBSPDM_MAX_HASH_SIZE];
+      31                 :            :     uint8_t context[LIBSPDM_PSK_CONTEXT_LENGTH];
+      32                 :            :     uint8_t opaque_data[SPDM_MAX_OPAQUE_DATA_SIZE];
+      33                 :            :     uint8_t verify_data[LIBSPDM_MAX_HASH_SIZE];
+      34                 :            : } libspdm_psk_exchange_response_max_t;
+      35                 :            : #pragma pack()
+      36                 :            : 
+      37                 :         15 : bool libspdm_verify_psk_exchange_rsp_hmac(libspdm_context_t *spdm_context,
+      38                 :            :                                           libspdm_session_info_t *session_info,
+      39                 :            :                                           const void *hmac_data,
+      40                 :            :                                           size_t hmac_data_size)
+      41                 :            : {
+      42                 :            :     size_t hash_size;
+      43                 :            :     uint8_t calc_hmac_data[LIBSPDM_MAX_HASH_SIZE];
+      44                 :            :     bool result;
+      45                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+      46                 :            :     uint8_t *th_curr_data;
+      47                 :            :     size_t th_curr_data_size;
+      48                 :            :     libspdm_th_managed_buffer_t th_curr;
+      49                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+      50                 :            : #endif
+      51                 :            : 
+      52                 :         15 :     hash_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+      53         [ -  + ]:         15 :     LIBSPDM_ASSERT(hash_size == hmac_data_size);
+      54                 :            : 
+      55                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+      56                 :            :     result = libspdm_calculate_th_for_exchange(spdm_context, session_info,
+      57                 :            :                                                NULL, 0, &th_curr);
+      58                 :            :     if (!result) {
+      59                 :            :         return false;
+      60                 :            :     }
+      61                 :            :     th_curr_data = libspdm_get_managed_buffer(&th_curr);
+      62                 :            :     th_curr_data_size = libspdm_get_managed_buffer_size(&th_curr);
+      63                 :            : 
+      64                 :            :     result = libspdm_hash_all (spdm_context->connection_info.algorithm.base_hash_algo,
+      65                 :            :                                th_curr_data, th_curr_data_size, hash_data);
+      66                 :            :     if (!result) {
+      67                 :            :         return false;
+      68                 :            :     }
+      69                 :            : 
+      70                 :            :     result = libspdm_hmac_all_with_response_finished_key(
+      71                 :            :         session_info->secured_message_context, hash_data,
+      72                 :            :         hash_size, calc_hmac_data);
+      73                 :            :     if (!result) {
+      74                 :            :         return false;
+      75                 :            :     }
+      76                 :            : #else
+      77                 :         15 :     result = libspdm_calculate_th_hmac_for_exchange_rsp(
+      78                 :            :         spdm_context, session_info, true, &hash_size, calc_hmac_data);
+      79         [ -  + ]:         15 :     if (!result) {
+      80                 :          0 :         return false;
+      81                 :            :     }
+      82                 :            : #endif
+      83                 :         15 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "th_curr hmac - "));
+      84                 :         15 :     LIBSPDM_INTERNAL_DUMP_DATA(calc_hmac_data, hash_size);
+      85                 :         15 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+      86                 :            : 
+      87         [ +  + ]:         15 :     if (!libspdm_consttime_is_mem_equal(calc_hmac_data, hmac_data, hash_size)) {
+      88                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR, "!!! verify_psk_exchange_rsp_hmac - FAIL !!!\n"));
+      89                 :          1 :         return false;
+      90                 :            :     }
+      91                 :         14 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "!!! verify_psk_exchange_rsp_hmac - PASS !!!\n"));
+      92                 :            : 
+      93                 :         14 :     return true;
+      94                 :            : }
+      95                 :            : 
+      96                 :            : /**
+      97                 :            :  * This function sends PSK_EXCHANGE and receives PSK_EXCHANGE_RSP for SPDM PSK exchange.
+      98                 :            :  *
+      99                 :            :  * @param  spdm_context              A pointer to the SPDM context.
+     100                 :            :  * @param  measurement_hash_type     measurement_hash_type to the PSK_EXCHANGE request.
+     101                 :            :  * @param  session_policy            The policy for the session.
+     102                 :            :  * @param  session_id                session_id from the PSK_EXCHANGE_RSP response.
+     103                 :            :  * @param  heartbeat_period          heartbeat_period from the PSK_EXCHANGE_RSP response.
+     104                 :            :  * @param  measurement_hash          measurement_hash from the PSK_EXCHANGE_RSP response.
+     105                 :            :  * @param  requester_context_in      A buffer to hold the requester context as input, if not NULL.
+     106                 :            :  * @param  requester_context_in_size The size of requester_context_in.
+     107                 :            :  *                                   It must be 32 bytes at least, but not exceed LIBSPDM_PSK_CONTEXT_LENGTH.
+     108                 :            :  * @param  requester_context         A buffer to hold the requester context, if not NULL.
+     109                 :            :  * @param  requester_context_size    On input, the size of requester_context buffer.
+     110                 :            :  *                                   On output, the size of data returned in requester_context buffer.
+     111                 :            :  *                                   It must be 32 bytes at least.
+     112                 :            :  * @param  responder_context         A buffer to hold the responder context, if not NULL.
+     113                 :            :  * @param  responder_context_size    On input, the size of requester_context buffer.
+     114                 :            :  *                                   On output, the size of data returned in requester_context buffer.
+     115                 :            :  *                                   It could be 0 if device does not support context.
+     116                 :            :  * @param  opaque_data               A buffer to hold the responder opaque data, if not NULL.
+     117                 :            :  * @param  responder_opaque_data_size          On input, the size of the opaque data buffer.
+     118                 :            :  *                                   Responder opaque data should be less than 1024 bytes.
+     119                 :            :  *                                   On output, the size of the opaque data.
+     120                 :            :  **/
+     121                 :         44 : static libspdm_return_t libspdm_try_send_receive_psk_exchange(
+     122                 :            :     libspdm_context_t *spdm_context,
+     123                 :            :     const void *psk_hint, uint16_t psk_hint_size,
+     124                 :            :     uint8_t measurement_hash_type,
+     125                 :            :     uint8_t session_policy,
+     126                 :            :     uint32_t *session_id, uint8_t *heartbeat_period,
+     127                 :            :     void *measurement_hash,
+     128                 :            :     const void *requester_context_in,
+     129                 :            :     size_t requester_context_in_size,
+     130                 :            :     void *requester_context,
+     131                 :            :     size_t *requester_context_size,
+     132                 :            :     void *responder_context,
+     133                 :            :     size_t *responder_context_size,
+     134                 :            :     const void *requester_opaque_data,
+     135                 :            :     size_t requester_opaque_data_size,
+     136                 :            :     void *responder_opaque_data,
+     137                 :            :     size_t *responder_opaque_data_size)
+     138                 :            : {
+     139                 :            :     bool result;
+     140                 :            :     libspdm_return_t status;
+     141                 :            :     libspdm_psk_exchange_request_mine_t *spdm_request;
+     142                 :            :     size_t spdm_request_size;
+     143                 :            :     libspdm_psk_exchange_response_max_t *spdm_response;
+     144                 :            :     size_t spdm_response_size;
+     145                 :            :     uint32_t measurement_summary_hash_size;
+     146                 :            :     uint32_t hmac_size;
+     147                 :            :     uint8_t *ptr;
+     148                 :            :     void *measurement_summary_hash;
+     149                 :            :     uint8_t *verify_data;
+     150                 :            :     uint16_t req_session_id;
+     151                 :            :     uint16_t rsp_session_id;
+     152                 :            :     libspdm_session_info_t *session_info;
+     153                 :            :     size_t opaque_psk_exchange_req_size;
+     154                 :            :     uint8_t th1_hash_data[LIBSPDM_MAX_HASH_SIZE];
+     155                 :            :     uint8_t th2_hash_data[LIBSPDM_MAX_HASH_SIZE];
+     156                 :            :     uint32_t algo_size;
+     157                 :            :     uint8_t *message;
+     158                 :            :     size_t message_size;
+     159                 :            :     size_t transport_header_size;
+     160                 :            : 
+     161   [ +  +  +  +  :         44 :     LIBSPDM_ASSERT(measurement_hash_type == SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH ||
+                   -  + ]
+     162                 :            :                    measurement_hash_type == SPDM_PSK_EXCHANGE_REQUEST_TCB_COMPONENT_MEASUREMENT_HASH ||
+     163                 :            :                    measurement_hash_type == SPDM_PSK_EXCHANGE_REQUEST_ALL_MEASUREMENTS_HASH);
+     164                 :            : 
+     165         [ -  + ]:         44 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_11) {
+     166                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     167                 :            :     }
+     168                 :            : 
+     169                 :            :     /* Check capabilities even if GET_CAPABILITIES is not sent.
+     170                 :            :      * Assuming capabilities are provisioned.*/
+     171         [ -  + ]:         44 :     if (!libspdm_is_capabilities_flag_supported(
+     172                 :            :             spdm_context, true,
+     173                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP,
+     174                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP)) {
+     175                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     176                 :            :     }
+     177         [ +  + ]:         44 :     if (spdm_context->connection_info.connection_state < LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
+     178                 :          1 :         return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+     179                 :            :     }
+     180         [ +  + ]:         43 :     if (libspdm_get_connection_version(spdm_context) >= SPDM_MESSAGE_VERSION_12) {
+     181         [ -  + ]:          2 :         if ((spdm_context->connection_info.algorithm.other_params_support &
+     182                 :            :              SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_MASK) != SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1) {
+     183                 :          0 :             return LIBSPDM_STATUS_INVALID_STATE_PEER;
+     184                 :            :         }
+     185                 :            :     }
+     186                 :            : 
+     187                 :         43 :     req_session_id = libspdm_allocate_req_session_id(spdm_context, true);
+     188         [ -  + ]:         43 :     if (req_session_id == (INVALID_SESSION_ID & 0xFFFF)) {
+     189                 :          0 :         return LIBSPDM_STATUS_SESSION_NUMBER_EXCEED;
+     190                 :            :     }
+     191                 :            : 
+     192                 :         43 :     libspdm_reset_message_buffer_via_request_code(spdm_context, NULL, SPDM_PSK_EXCHANGE);
+     193                 :            :     {
+     194                 :            :         /* Double check if algorithm has been provisioned, because ALGORITHM might be skipped.*/
+     195         [ +  + ]:         43 :         if (libspdm_is_capabilities_flag_supported(
+     196                 :            :                 spdm_context, true, 0,
+     197                 :            :                 SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP)) {
+     198                 :         14 :             if (spdm_context->connection_info.algorithm
+     199         [ -  + ]:         14 :                 .measurement_spec !=
+     200                 :            :                 SPDM_MEASUREMENT_SPECIFICATION_DMTF) {
+     201                 :          0 :                 return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+     202                 :            :             }
+     203                 :         14 :             algo_size = libspdm_get_measurement_hash_size(
+     204                 :            :                 spdm_context->connection_info.algorithm.measurement_hash_algo);
+     205         [ -  + ]:         14 :             if (algo_size == 0) {
+     206                 :          0 :                 return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+     207                 :            :             }
+     208                 :            :         }
+     209                 :         43 :         algo_size = libspdm_get_hash_size(
+     210                 :            :             spdm_context->connection_info.algorithm.base_hash_algo);
+     211         [ -  + ]:         43 :         if (algo_size == 0) {
+     212                 :          0 :             return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+     213                 :            :         }
+     214         [ -  + ]:         43 :         if (spdm_context->connection_info.algorithm.key_schedule !=
+     215                 :            :             SPDM_ALGORITHMS_KEY_SCHEDULE_HMAC_HASH) {
+     216                 :          0 :             return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+     217                 :            :         }
+     218                 :            :     }
+     219                 :            : 
+     220                 :         43 :     transport_header_size = spdm_context->local_context.capability.transport_header_size;
+     221                 :         43 :     status = libspdm_acquire_sender_buffer (spdm_context, &message_size, (void **)&message);
+     222         [ -  + ]:         43 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     223                 :          0 :         return status;
+     224                 :            :     }
+     225         [ -  + ]:         43 :     LIBSPDM_ASSERT (message_size >= transport_header_size +
+     226                 :            :                     spdm_context->local_context.capability.transport_tail_size);
+     227                 :         43 :     spdm_request = (void *)(message + transport_header_size);
+     228                 :         43 :     spdm_request_size = message_size - transport_header_size -
+     229                 :         43 :                         spdm_context->local_context.capability.transport_tail_size;
+     230                 :            : 
+     231         [ -  + ]:         43 :     LIBSPDM_ASSERT(spdm_request_size >= sizeof(spdm_psk_exchange_request_t) + psk_hint_size);
+     232                 :         43 :     spdm_request->header.spdm_version = libspdm_get_connection_version (spdm_context);
+     233                 :         43 :     spdm_request->header.request_response_code = SPDM_PSK_EXCHANGE;
+     234                 :         43 :     spdm_request->header.param1 = measurement_hash_type;
+     235         [ +  + ]:         43 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_12) {
+     236                 :          2 :         spdm_request->header.param2 = session_policy;
+     237                 :            :     } else {
+     238                 :         41 :         spdm_request->header.param2 = 0;
+     239                 :            :     }
+     240                 :         43 :     spdm_request->psk_hint_length = psk_hint_size;
+     241         [ +  - ]:         43 :     if (requester_context_in == NULL) {
+     242                 :         43 :         spdm_request->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
+     243                 :            :     } else {
+     244         [ #  # ]:          0 :         LIBSPDM_ASSERT (requester_context_in_size <= LIBSPDM_PSK_CONTEXT_LENGTH);
+     245                 :          0 :         spdm_request->context_length = (uint16_t)requester_context_in_size;
+     246                 :            :     }
+     247                 :            : 
+     248         [ -  + ]:         43 :     if (requester_opaque_data != NULL) {
+     249         [ #  # ]:          0 :         LIBSPDM_ASSERT(requester_opaque_data_size <= SPDM_MAX_OPAQUE_DATA_SIZE);
+     250                 :            : 
+     251                 :          0 :         opaque_psk_exchange_req_size = (uint16_t)requester_opaque_data_size;
+     252                 :            :     } else {
+     253                 :         43 :         opaque_psk_exchange_req_size =
+     254                 :         43 :             libspdm_get_opaque_data_supported_version_data_size(spdm_context);
+     255                 :            :     }
+     256                 :            : 
+     257         [ -  + ]:         43 :     LIBSPDM_ASSERT(spdm_request_size >= sizeof(spdm_psk_exchange_request_t) + psk_hint_size +
+     258                 :            :                    spdm_request->context_length + opaque_psk_exchange_req_size);
+     259                 :         43 :     spdm_request->opaque_length = (uint16_t)opaque_psk_exchange_req_size;
+     260                 :            : 
+     261                 :         43 :     spdm_request->req_session_id = req_session_id;
+     262                 :            : 
+     263                 :         43 :     ptr = spdm_request->psk_hint;
+     264   [ +  +  +  - ]:         43 :     if ((psk_hint != NULL) && (psk_hint_size > 0)) {
+     265                 :         42 :         libspdm_copy_mem(ptr, sizeof(spdm_request->psk_hint),
+     266                 :            :                          psk_hint,
+     267                 :            :                          psk_hint_size);
+     268                 :            :     }
+     269                 :         43 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "psk_hint (0x%x) - ", spdm_request->psk_hint_length));
+     270                 :         43 :     LIBSPDM_INTERNAL_DUMP_DATA(ptr, spdm_request->psk_hint_length);
+     271                 :         43 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     272                 :         43 :     ptr += spdm_request->psk_hint_length;
+     273                 :            : 
+     274         [ +  - ]:         43 :     if (requester_context_in == NULL) {
+     275         [ -  + ]:         43 :         if(!libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr)) {
+     276                 :          0 :             libspdm_release_sender_buffer (spdm_context);
+     277                 :          0 :             return LIBSPDM_STATUS_LOW_ENTROPY;
+     278                 :            :         }
+     279                 :            :     } else {
+     280                 :          0 :         libspdm_copy_mem(ptr, sizeof(spdm_request->context),
+     281                 :          0 :                          requester_context_in, spdm_request->context_length);
+     282                 :            :     }
+     283                 :         43 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "RequesterContextData (0x%x) - ",
+     284                 :            :                    spdm_request->context_length));
+     285                 :         43 :     LIBSPDM_INTERNAL_DUMP_DATA(ptr, spdm_request->context_length);
+     286                 :         43 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     287         [ -  + ]:         43 :     if (requester_context != NULL) {
+     288         [ #  # ]:          0 :         if (*requester_context_size > spdm_request->context_length) {
+     289                 :          0 :             *requester_context_size = spdm_request->context_length;
+     290                 :            :         }
+     291                 :          0 :         libspdm_copy_mem(requester_context, *requester_context_size,
+     292                 :            :                          ptr, *requester_context_size);
+     293                 :            :     }
+     294                 :         43 :     ptr += spdm_request->context_length;
+     295                 :            : 
+     296         [ -  + ]:         43 :     if (requester_opaque_data != NULL) {
+     297                 :          0 :         libspdm_copy_mem(ptr, opaque_psk_exchange_req_size,
+     298                 :            :                          requester_opaque_data, opaque_psk_exchange_req_size);
+     299                 :            :     } else {
+     300                 :         43 :         libspdm_build_opaque_data_supported_version_data(
+     301                 :            :             spdm_context, &opaque_psk_exchange_req_size, ptr);
+     302                 :            :     }
+     303                 :         43 :     ptr += opaque_psk_exchange_req_size;
+     304                 :            : 
+     305                 :         43 :     spdm_request_size = (size_t)ptr - (size_t)spdm_request;
+     306                 :         43 :     status = libspdm_send_spdm_request(spdm_context, NULL, spdm_request_size,
+     307                 :            :                                        spdm_request);
+     308         [ +  + ]:         43 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     309                 :          1 :         libspdm_release_sender_buffer (spdm_context);
+     310                 :          1 :         return status;
+     311                 :            :     }
+     312                 :         42 :     libspdm_release_sender_buffer (spdm_context);
+     313                 :         42 :     spdm_request = (void *)spdm_context->last_spdm_request;
+     314                 :            : 
+     315                 :            :     /* receive */
+     316                 :            : 
+     317                 :         42 :     status = libspdm_acquire_receiver_buffer (spdm_context, &message_size, (void **)&message);
+     318         [ -  + ]:         42 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     319                 :          0 :         return status;
+     320                 :            :     }
+     321         [ -  + ]:         42 :     LIBSPDM_ASSERT (message_size >= transport_header_size);
+     322                 :         42 :     spdm_response = (void *)(message);
+     323                 :         42 :     spdm_response_size = message_size;
+     324                 :            : 
+     325                 :         42 :     status = libspdm_receive_spdm_response(
+     326                 :            :         spdm_context, NULL, &spdm_response_size, (void **)&spdm_response);
+     327         [ -  + ]:         42 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     328                 :          0 :         goto receive_done;
+     329                 :            :     }
+     330         [ -  + ]:         42 :     if (spdm_response_size < sizeof(spdm_message_header_t)) {
+     331                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     332                 :          0 :         goto receive_done;
+     333                 :            :     }
+     334         [ -  + ]:         42 :     if (spdm_response->header.spdm_version != spdm_request->header.spdm_version) {
+     335                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     336                 :          0 :         goto receive_done;
+     337                 :            :     }
+     338         [ +  + ]:         42 :     if (spdm_response->header.request_response_code == SPDM_ERROR) {
+     339                 :         24 :         status = libspdm_handle_error_response_main(
+     340                 :            :             spdm_context, NULL, &spdm_response_size,
+     341                 :            :             (void **)&spdm_response, SPDM_PSK_EXCHANGE,
+     342                 :            :             SPDM_PSK_EXCHANGE_RSP);
+     343         [ +  + ]:         24 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     344                 :         23 :             goto receive_done;
+     345                 :            :         }
+     346         [ -  + ]:         18 :     } else if (spdm_response->header.request_response_code != SPDM_PSK_EXCHANGE_RSP) {
+     347                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     348                 :          0 :         goto receive_done;
+     349                 :            :     }
+     350         [ -  + ]:         19 :     if (spdm_response_size < sizeof(spdm_psk_exchange_response_t)) {
+     351                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     352                 :          0 :         goto receive_done;
+     353                 :            :     }
+     354                 :            : 
+     355         [ +  + ]:         19 :     if (!libspdm_is_capabilities_flag_supported(
+     356                 :            :             spdm_context, true,
+     357                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP,
+     358                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP)) {
+     359         [ +  + ]:         17 :         if (spdm_response->header.param1 != 0) {
+     360                 :          1 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     361                 :          1 :             goto receive_done;
+     362                 :            :         }
+     363                 :            :     }
+     364         [ +  - ]:         18 :     if (heartbeat_period != NULL) {
+     365                 :         18 :         *heartbeat_period = spdm_response->header.param1;
+     366                 :            :     }
+     367                 :            : 
+     368                 :         18 :     measurement_summary_hash_size = libspdm_get_measurement_summary_hash_size(
+     369                 :            :         spdm_context, true, measurement_hash_type);
+     370                 :         18 :     hmac_size = libspdm_get_hash_size(
+     371                 :            :         spdm_context->connection_info.algorithm.base_hash_algo);
+     372                 :            : 
+     373                 :         18 :     if (spdm_response_size <
+     374                 :            :         sizeof(spdm_psk_exchange_response_t) +
+     375                 :         18 :         spdm_response->context_length + spdm_response->opaque_length +
+     376         [ +  + ]:         18 :         measurement_summary_hash_size + hmac_size) {
+     377                 :          2 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     378                 :          2 :         goto receive_done;
+     379                 :            :     }
+     380                 :            : 
+     381                 :         16 :     ptr = (uint8_t *)spdm_response + sizeof(spdm_psk_exchange_response_t) +
+     382                 :         16 :           measurement_summary_hash_size + spdm_response->context_length;
+     383         [ +  + ]:         16 :     if (spdm_response->opaque_length != 0) {
+     384                 :         14 :         result = libspdm_process_general_opaque_data_check(spdm_context,
+     385                 :         14 :                                                            spdm_response->opaque_length, ptr);
+     386         [ -  + ]:         14 :         if (!result) {
+     387                 :          0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     388                 :          0 :             goto receive_done;
+     389                 :            :         }
+     390                 :         14 :         status = libspdm_process_opaque_data_version_selection_data(
+     391                 :         14 :             spdm_context, spdm_response->opaque_length, ptr);
+     392         [ +  + ]:         14 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     393                 :          1 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     394                 :          1 :             goto receive_done;
+     395                 :            :         }
+     396                 :            :     }
+     397                 :            : 
+     398                 :         15 :     spdm_response_size = sizeof(spdm_psk_exchange_response_t) +
+     399                 :         15 :                          spdm_response->context_length +
+     400                 :         15 :                          spdm_response->opaque_length +
+     401                 :         15 :                          measurement_summary_hash_size + hmac_size;
+     402                 :            : 
+     403                 :         15 :     ptr = (uint8_t *)(spdm_response->measurement_summary_hash);
+     404                 :         15 :     measurement_summary_hash = ptr;
+     405                 :         15 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "measurement_summary_hash (0x%x) - ",
+     406                 :            :                    measurement_summary_hash_size));
+     407                 :         15 :     LIBSPDM_INTERNAL_DUMP_DATA(measurement_summary_hash,
+     408                 :            :                                measurement_summary_hash_size);
+     409                 :         15 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     410                 :            : 
+     411                 :         15 :     ptr += measurement_summary_hash_size;
+     412                 :            : 
+     413         [ -  + ]:         15 :     if (spdm_response->opaque_length > SPDM_MAX_OPAQUE_DATA_SIZE) {
+     414                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     415                 :          0 :         goto receive_done;
+     416                 :            :     }
+     417                 :            : 
+     418         [ +  + ]:         15 :     if (libspdm_is_capabilities_flag_supported(
+     419                 :            :             spdm_context, true, 0,
+     420                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER)) {
+     421         [ -  + ]:          2 :         if (spdm_response->context_length != 0) {
+     422                 :          0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     423                 :          0 :             goto receive_done;
+     424                 :            :         }
+     425                 :            :     } else {
+     426         [ -  + ]:         13 :         if (spdm_response->context_length == 0) {
+     427                 :          0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     428                 :          0 :             goto receive_done;
+     429                 :            :         }
+     430                 :            :     }
+     431                 :            : 
+     432                 :         15 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "ResponderContextData (0x%x) - ",
+     433                 :            :                    spdm_response->context_length));
+     434                 :         15 :     LIBSPDM_INTERNAL_DUMP_DATA(ptr, spdm_response->context_length);
+     435                 :         15 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     436         [ -  + ]:         15 :     if (responder_context != NULL) {
+     437         [ #  # ]:          0 :         if (*responder_context_size > spdm_response->context_length) {
+     438                 :          0 :             *responder_context_size = spdm_response->context_length;
+     439                 :            :         }
+     440                 :          0 :         libspdm_copy_mem(responder_context, *responder_context_size,
+     441                 :            :                          ptr, *responder_context_size);
+     442                 :            :     }
+     443                 :            : 
+     444                 :         15 :     ptr += spdm_response->context_length;
+     445                 :            : 
+     446   [ -  +  -  - ]:         15 :     if ((responder_opaque_data != NULL) && (responder_opaque_data_size != NULL)) {
+     447         [ #  # ]:          0 :         if (spdm_response->opaque_length >= *responder_opaque_data_size) {
+     448                 :          0 :             status = LIBSPDM_STATUS_BUFFER_TOO_SMALL;
+     449                 :          0 :             goto receive_done;
+     450                 :            :         }
+     451                 :          0 :         libspdm_copy_mem(responder_opaque_data, *responder_opaque_data_size,
+     452                 :          0 :                          ptr, spdm_response->opaque_length);
+     453                 :          0 :         *responder_opaque_data_size = spdm_response->opaque_length;
+     454                 :            :     }
+     455                 :            : 
+     456                 :         15 :     ptr += spdm_response->opaque_length;
+     457                 :            : 
+     458                 :         15 :     rsp_session_id = spdm_response->rsp_session_id;
+     459                 :         15 :     *session_id = libspdm_generate_session_id(req_session_id, rsp_session_id);
+     460                 :         15 :     session_info = libspdm_assign_session_id(spdm_context, *session_id, true);
+     461         [ -  + ]:         15 :     if (session_info == NULL) {
+     462                 :          0 :         status = LIBSPDM_STATUS_SESSION_NUMBER_EXCEED;
+     463                 :          0 :         goto receive_done;
+     464                 :            :     }
+     465                 :         15 :     libspdm_session_info_set_psk_hint(session_info,
+     466                 :            :                                       psk_hint,
+     467                 :            :                                       psk_hint_size);
+     468                 :            : 
+     469                 :            :     /* Cache session data*/
+     470                 :            : 
+     471                 :         15 :     status = libspdm_append_message_k(spdm_context, session_info, true, spdm_request,
+     472                 :            :                                       spdm_request_size);
+     473         [ -  + ]:         15 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     474                 :          0 :         libspdm_free_session_id(spdm_context, *session_id);
+     475                 :          0 :         goto receive_done;
+     476                 :            :     }
+     477                 :            : 
+     478                 :         15 :     status = libspdm_append_message_k(spdm_context, session_info, true, spdm_response,
+     479                 :            :                                       spdm_response_size - hmac_size);
+     480         [ -  + ]:         15 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     481                 :          0 :         libspdm_free_session_id(spdm_context, *session_id);
+     482                 :          0 :         goto receive_done;
+     483                 :            :     }
+     484                 :            : 
+     485                 :         15 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "libspdm_generate_session_handshake_key[%x]\n",
+     486                 :            :                    *session_id));
+     487                 :         15 :     result = libspdm_calculate_th1_hash(spdm_context, session_info, true,
+     488                 :            :                                         th1_hash_data);
+     489         [ -  + ]:         15 :     if (!result) {
+     490                 :          0 :         libspdm_free_session_id(spdm_context, *session_id);
+     491                 :          0 :         status = LIBSPDM_STATUS_CRYPTO_ERROR;
+     492                 :          0 :         goto receive_done;
+     493                 :            :     }
+     494                 :         15 :     result = libspdm_generate_session_handshake_key(
+     495                 :            :         session_info->secured_message_context, th1_hash_data);
+     496         [ -  + ]:         15 :     if (!result) {
+     497                 :          0 :         libspdm_free_session_id(spdm_context, *session_id);
+     498                 :          0 :         status = LIBSPDM_STATUS_CRYPTO_ERROR;
+     499                 :          0 :         goto receive_done;
+     500                 :            :     }
+     501                 :            : 
+     502                 :         15 :     verify_data = ptr;
+     503                 :         15 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "verify_data (0x%x):\n", hmac_size));
+     504                 :         15 :     LIBSPDM_INTERNAL_DUMP_HEX(verify_data, hmac_size);
+     505                 :         15 :     result = libspdm_verify_psk_exchange_rsp_hmac(spdm_context, session_info,
+     506                 :            :                                                   verify_data, hmac_size);
+     507         [ +  + ]:         15 :     if (!result) {
+     508                 :          1 :         libspdm_free_session_id(spdm_context, *session_id);
+     509                 :          1 :         status = LIBSPDM_STATUS_VERIF_FAIL;
+     510                 :          1 :         goto receive_done;
+     511                 :            :     }
+     512                 :            : 
+     513                 :         14 :     status = libspdm_append_message_k(spdm_context, session_info, true, verify_data, hmac_size);
+     514         [ -  + ]:         14 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     515                 :          0 :         libspdm_free_session_id(spdm_context, *session_id);
+     516                 :          0 :         goto receive_done;
+     517                 :            :     }
+     518                 :            : 
+     519         [ +  - ]:         14 :     if (measurement_hash != NULL) {
+     520                 :         14 :         libspdm_copy_mem(measurement_hash, measurement_summary_hash_size,
+     521                 :            :                          measurement_summary_hash, measurement_summary_hash_size);
+     522                 :            :     }
+     523                 :            : 
+     524                 :         14 :     session_info->session_policy = session_policy;
+     525                 :            : 
+     526                 :         14 :     libspdm_secured_message_set_session_state(
+     527                 :            :         session_info->secured_message_context,
+     528                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+     529                 :            : 
+     530         [ +  + ]:         14 :     if (!libspdm_is_capabilities_flag_supported(
+     531                 :            :             spdm_context, true, 0,
+     532                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT)) {
+     533                 :            :         /* No need to send PSK_FINISH, enter application phase directly.*/
+     534                 :            : 
+     535                 :          2 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "libspdm_generate_session_data_key[%x]\n",
+     536                 :            :                        *session_id));
+     537                 :          2 :         result = libspdm_calculate_th2_hash(spdm_context, session_info,
+     538                 :            :                                             true, th2_hash_data);
+     539         [ -  + ]:          2 :         if (!result) {
+     540                 :          0 :             libspdm_free_session_id(spdm_context, *session_id);
+     541                 :          0 :             status = LIBSPDM_STATUS_CRYPTO_ERROR;
+     542                 :          0 :             goto receive_done;
+     543                 :            :         }
+     544                 :          2 :         result = libspdm_generate_session_data_key(
+     545                 :            :             session_info->secured_message_context, th2_hash_data);
+     546         [ -  + ]:          2 :         if (!result) {
+     547                 :          0 :             libspdm_free_session_id(spdm_context, *session_id);
+     548                 :          0 :             status = LIBSPDM_STATUS_CRYPTO_ERROR;
+     549                 :          0 :             goto receive_done;
+     550                 :            :         }
+     551                 :            : 
+     552                 :          2 :         libspdm_secured_message_set_session_state(
+     553                 :            :             session_info->secured_message_context,
+     554                 :            :             LIBSPDM_SESSION_STATE_ESTABLISHED);
+     555                 :            :     }
+     556                 :            : 
+     557                 :         14 :     session_info->heartbeat_period = spdm_response->header.param1;
+     558                 :            : 
+     559                 :            :     /* -=[Log Message Phase]=- */
+     560                 :            :     #if LIBSPDM_ENABLE_MSG_LOG
+     561                 :         14 :     libspdm_append_msg_log(spdm_context, spdm_response, spdm_response_size);
+     562                 :            :     #endif /* LIBSPDM_ENABLE_MSG_LOG */
+     563                 :            : 
+     564                 :         14 :     status = LIBSPDM_STATUS_SUCCESS;
+     565                 :            : 
+     566                 :         42 : receive_done:
+     567                 :         42 :     libspdm_release_receiver_buffer (spdm_context);
+     568                 :         42 :     return status;
+     569                 :            : }
+     570                 :            : 
+     571                 :         43 : libspdm_return_t libspdm_send_receive_psk_exchange(libspdm_context_t *spdm_context,
+     572                 :            :                                                    const void *psk_hint,
+     573                 :            :                                                    uint16_t psk_hint_size,
+     574                 :            :                                                    uint8_t measurement_hash_type,
+     575                 :            :                                                    uint8_t session_policy,
+     576                 :            :                                                    uint32_t *session_id,
+     577                 :            :                                                    uint8_t *heartbeat_period,
+     578                 :            :                                                    void *measurement_hash)
+     579                 :            : {
+     580                 :            :     size_t retry;
+     581                 :            :     uint64_t retry_delay_time;
+     582                 :            :     libspdm_return_t status;
+     583                 :            : 
+     584                 :         43 :     spdm_context->crypto_request = true;
+     585                 :         43 :     retry = spdm_context->retry_times;
+     586                 :         43 :     retry_delay_time = spdm_context->retry_delay_time;
+     587                 :            :     do {
+     588                 :         44 :         status = libspdm_try_send_receive_psk_exchange(
+     589                 :            :             spdm_context, psk_hint, psk_hint_size,
+     590                 :            :             measurement_hash_type, session_policy, session_id,
+     591                 :            :             heartbeat_period, measurement_hash,
+     592                 :            :             NULL, 0, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL);
+     593         [ +  + ]:         44 :         if (status != LIBSPDM_STATUS_BUSY_PEER) {
+     594                 :         42 :             return status;
+     595                 :            :         }
+     596                 :            : 
+     597                 :          2 :         libspdm_sleep(retry_delay_time);
+     598         [ +  + ]:          2 :     } while (retry-- != 0);
+     599                 :            : 
+     600                 :          1 :     return status;
+     601                 :            : }
+     602                 :            : 
+     603                 :          0 : libspdm_return_t libspdm_send_receive_psk_exchange_ex(libspdm_context_t *spdm_context,
+     604                 :            :                                                       const void *psk_hint,
+     605                 :            :                                                       uint16_t psk_hint_size,
+     606                 :            :                                                       uint8_t measurement_hash_type,
+     607                 :            :                                                       uint8_t session_policy,
+     608                 :            :                                                       uint32_t *session_id,
+     609                 :            :                                                       uint8_t *heartbeat_period,
+     610                 :            :                                                       void *measurement_hash,
+     611                 :            :                                                       const void *requester_context_in,
+     612                 :            :                                                       size_t requester_context_in_size,
+     613                 :            :                                                       void *requester_context,
+     614                 :            :                                                       size_t *requester_context_size,
+     615                 :            :                                                       void *responder_context,
+     616                 :            :                                                       size_t *responder_context_size,
+     617                 :            :                                                       const void *requester_opaque_data,
+     618                 :            :                                                       size_t requester_opaque_data_size,
+     619                 :            :                                                       void *responder_opaque_data,
+     620                 :            :                                                       size_t *responder_opaque_data_size)
+     621                 :            : {
+     622                 :            :     size_t retry;
+     623                 :            :     uint64_t retry_delay_time;
+     624                 :            :     libspdm_return_t status;
+     625                 :            : 
+     626                 :          0 :     spdm_context->crypto_request = true;
+     627                 :          0 :     retry = spdm_context->retry_times;
+     628                 :          0 :     retry_delay_time = spdm_context->retry_delay_time;
+     629                 :            :     do {
+     630                 :          0 :         status = libspdm_try_send_receive_psk_exchange(
+     631                 :            :             spdm_context, psk_hint, psk_hint_size,
+     632                 :            :             measurement_hash_type, session_policy, session_id,
+     633                 :            :             heartbeat_period, measurement_hash,
+     634                 :            :             requester_context_in, requester_context_in_size,
+     635                 :            :             requester_context, requester_context_size,
+     636                 :            :             responder_context, responder_context_size,
+     637                 :            :             requester_opaque_data, requester_opaque_data_size,
+     638                 :            :             responder_opaque_data, responder_opaque_data_size);
+     639         [ #  # ]:          0 :         if (status != LIBSPDM_STATUS_BUSY_PEER) {
+     640                 :          0 :             return status;
+     641                 :            :         }
+     642                 :            : 
+     643                 :          0 :         libspdm_sleep(retry_delay_time);
+     644         [ #  # ]:          0 :     } while (retry-- != 0);
+     645                 :            : 
+     646                 :          0 :     return status;
+     647                 :            : }
+     648                 :            : 
+     649                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_psk_finish.c.func-sort-c.html b/coverage_log/library/spdm_requester_lib/libspdm_req_psk_finish.c.func-sort-c.html new file mode 100644 index 00000000000..be3f0775936 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_psk_finish.c.func-sort-c.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_psk_finish.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_psk_finish.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:10012679.4 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:416068.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_generate_psk_exchange_req_hmac31
libspdm_send_receive_psk_finish33
libspdm_try_send_receive_psk_finish34
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_psk_finish.c.func.html b/coverage_log/library/spdm_requester_lib/libspdm_req_psk_finish.c.func.html new file mode 100644 index 00000000000..22b5defba2e --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_psk_finish.c.func.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_psk_finish.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_psk_finish.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:10012679.4 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:416068.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_generate_psk_exchange_req_hmac31
libspdm_send_receive_psk_finish33
libspdm_try_send_receive_psk_finish34
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_psk_finish.c.gcov.html b/coverage_log/library/spdm_requester_lib/libspdm_req_psk_finish.c.gcov.html new file mode 100644 index 00000000000..cd5beded5fb --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_psk_finish.c.gcov.html @@ -0,0 +1,400 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_psk_finish.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_psk_finish.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:10012679.4 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:416068.3 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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                 :            : #include "internal/libspdm_secured_message_lib.h"
+       9                 :            : 
+      10                 :            : #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
+      11                 :            : 
+      12                 :            : #pragma pack(1)
+      13                 :            : typedef struct {
+      14                 :            :     spdm_message_header_t header;
+      15                 :            :     uint8_t verify_data[LIBSPDM_MAX_HASH_SIZE];
+      16                 :            : } libspdm_psk_finish_request_mine_t;
+      17                 :            : 
+      18                 :            : typedef struct {
+      19                 :            :     spdm_message_header_t header;
+      20                 :            :     uint8_t dummy_data[sizeof(spdm_error_data_response_not_ready_t)];
+      21                 :            : } libspdm_psk_finish_response_max_t;
+      22                 :            : #pragma pack()
+      23                 :            : 
+      24                 :            : /**
+      25                 :            :  * This function generates the PSK finish HMAC based upon TH.
+      26                 :            :  *
+      27                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+      28                 :            :  * @param  session_info                  The session info of an SPDM session.
+      29                 :            :  * @param  hmac                         The buffer to store the finish HMAC.
+      30                 :            :  *
+      31                 :            :  * @retval true  PSK finish HMAC is generated.
+      32                 :            :  * @retval false PSK finish HMAC is not generated.
+      33                 :            :  **/
+      34                 :         31 : bool libspdm_generate_psk_exchange_req_hmac(libspdm_context_t *spdm_context,
+      35                 :            :                                             libspdm_session_info_t *session_info,
+      36                 :            :                                             void *hmac)
+      37                 :            : {
+      38                 :            :     size_t hash_size;
+      39                 :            :     uint8_t calc_hmac_data[LIBSPDM_MAX_HASH_SIZE];
+      40                 :            :     bool result;
+      41                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+      42                 :            :     uint8_t *th_curr_data;
+      43                 :            :     size_t th_curr_data_size;
+      44                 :            :     libspdm_th_managed_buffer_t th_curr;
+      45                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+      46                 :            : #endif
+      47                 :            : 
+      48                 :         31 :     hash_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+      49                 :            : 
+      50                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+      51                 :            :     result = libspdm_calculate_th_for_finish(spdm_context, session_info, NULL,
+      52                 :            :                                              0, NULL, 0, &th_curr);
+      53                 :            :     if (!result) {
+      54                 :            :         return false;
+      55                 :            :     }
+      56                 :            :     th_curr_data = libspdm_get_managed_buffer(&th_curr);
+      57                 :            :     th_curr_data_size = libspdm_get_managed_buffer_size(&th_curr);
+      58                 :            : 
+      59                 :            :     result = libspdm_hash_all (spdm_context->connection_info.algorithm.base_hash_algo,
+      60                 :            :                                th_curr_data, th_curr_data_size, hash_data);
+      61                 :            :     if (!result) {
+      62                 :            :         return false;
+      63                 :            :     }
+      64                 :            : 
+      65                 :            :     result = libspdm_hmac_all_with_request_finished_key(
+      66                 :            :         session_info->secured_message_context, hash_data,
+      67                 :            :         hash_size, calc_hmac_data);
+      68                 :            :     if (!result) {
+      69                 :            :         return false;
+      70                 :            :     }
+      71                 :            : #else
+      72                 :         31 :     result = libspdm_calculate_th_hmac_for_finish_req(
+      73                 :            :         spdm_context, session_info, &hash_size, calc_hmac_data);
+      74         [ -  + ]:         31 :     if (!result) {
+      75                 :          0 :         return false;
+      76                 :            :     }
+      77                 :            : #endif
+      78                 :         31 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "th_curr hmac - "));
+      79                 :         31 :     LIBSPDM_INTERNAL_DUMP_DATA(calc_hmac_data, hash_size);
+      80                 :         31 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+      81                 :            : 
+      82                 :         31 :     libspdm_copy_mem(hmac, hash_size, calc_hmac_data, hash_size);
+      83                 :            : 
+      84                 :         31 :     return true;
+      85                 :            : }
+      86                 :            : 
+      87                 :            : /**
+      88                 :            :  * This function sends PSK_FINISH and receives PSK_FINISH_RSP for SPDM PSK finish.
+      89                 :            :  *
+      90                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+      91                 :            :  * @param  session_id                    session_id to the PSK_FINISH request.
+      92                 :            :  *
+      93                 :            :  * @retval RETURN_SUCCESS               The PSK_FINISH is sent and the PSK_FINISH_RSP is received.
+      94                 :            :  * @retval RETURN_DEVICE_ERROR          A device error occurs when communicates with the device.
+      95                 :            :  **/
+      96                 :         34 : static libspdm_return_t libspdm_try_send_receive_psk_finish(libspdm_context_t *spdm_context,
+      97                 :            :                                                             uint32_t session_id)
+      98                 :            : {
+      99                 :            :     libspdm_return_t status;
+     100                 :            :     libspdm_psk_finish_request_mine_t *spdm_request;
+     101                 :            :     size_t spdm_request_size;
+     102                 :            :     size_t hmac_size;
+     103                 :            :     libspdm_psk_finish_response_max_t *spdm_response;
+     104                 :            :     size_t spdm_response_size;
+     105                 :            :     libspdm_session_info_t *session_info;
+     106                 :            :     uint8_t th2_hash_data[LIBSPDM_MAX_HASH_SIZE];
+     107                 :            :     libspdm_session_state_t session_state;
+     108                 :            :     bool result;
+     109                 :            :     uint8_t *message;
+     110                 :            :     size_t message_size;
+     111                 :            :     size_t transport_header_size;
+     112                 :            : 
+     113         [ -  + ]:         34 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_11) {
+     114                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     115                 :            :     }
+     116                 :            : 
+     117         [ +  + ]:         34 :     if (!libspdm_is_capabilities_flag_supported(
+     118                 :            :             spdm_context, true,
+     119                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP,
+     120                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT)) {
+     121                 :          1 :         status = LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     122                 :          1 :         goto error;
+     123                 :            :     }
+     124                 :            : 
+     125         [ +  + ]:         33 :     if (spdm_context->connection_info.connection_state <
+     126                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
+     127                 :          1 :         status = LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+     128                 :          1 :         goto error;
+     129                 :            :     }
+     130                 :            : 
+     131                 :            :     session_info =
+     132                 :         32 :         libspdm_get_session_info_via_session_id(spdm_context, session_id);
+     133         [ -  + ]:         32 :     if (session_info == NULL) {
+     134                 :          0 :         LIBSPDM_ASSERT(false);
+     135                 :          0 :         status = LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+     136                 :          0 :         goto error;
+     137                 :            :     }
+     138                 :         32 :     session_state = libspdm_secured_message_get_session_state(
+     139                 :            :         session_info->secured_message_context);
+     140         [ +  + ]:         32 :     if (session_state != LIBSPDM_SESSION_STATE_HANDSHAKING) {
+     141                 :          1 :         status = LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+     142                 :          1 :         goto error;
+     143                 :            :     }
+     144                 :            : 
+     145                 :         31 :     transport_header_size = spdm_context->local_context.capability.transport_header_size;
+     146                 :         31 :     status = libspdm_acquire_sender_buffer (spdm_context, &message_size, (void **)&message);
+     147         [ -  + ]:         31 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     148                 :          0 :         return status;
+     149                 :            :     }
+     150         [ -  + ]:         31 :     LIBSPDM_ASSERT (message_size >= transport_header_size +
+     151                 :            :                     spdm_context->local_context.capability.transport_tail_size);
+     152                 :         31 :     spdm_request = (void *)(message + transport_header_size);
+     153                 :         31 :     spdm_request_size = message_size - transport_header_size -
+     154                 :         31 :                         spdm_context->local_context.capability.transport_tail_size;
+     155                 :            : 
+     156         [ -  + ]:         31 :     LIBSPDM_ASSERT (spdm_request_size >= sizeof(spdm_request->header));
+     157                 :         31 :     spdm_request->header.spdm_version = libspdm_get_connection_version (spdm_context);
+     158                 :         31 :     spdm_request->header.request_response_code = SPDM_PSK_FINISH;
+     159                 :         31 :     spdm_request->header.param1 = 0;
+     160                 :         31 :     spdm_request->header.param2 = 0;
+     161                 :            : 
+     162                 :         31 :     hmac_size = libspdm_get_hash_size(
+     163                 :            :         spdm_context->connection_info.algorithm.base_hash_algo);
+     164         [ -  + ]:         31 :     LIBSPDM_ASSERT (spdm_request_size >= sizeof(spdm_request->header) + hmac_size);
+     165                 :         31 :     spdm_request_size = sizeof(spdm_psk_finish_request_t) + hmac_size;
+     166                 :            : 
+     167                 :         31 :     status = libspdm_append_message_f(spdm_context, session_info, true, (uint8_t *)spdm_request,
+     168                 :            :                                       spdm_request_size - hmac_size);
+     169         [ -  + ]:         31 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     170                 :          0 :         libspdm_release_sender_buffer (spdm_context);
+     171                 :          0 :         goto error;
+     172                 :            :     }
+     173                 :            : 
+     174                 :         31 :     result = libspdm_generate_psk_exchange_req_hmac(spdm_context, session_info,
+     175                 :         31 :                                                     spdm_request->verify_data);
+     176         [ -  + ]:         31 :     if (!result) {
+     177                 :          0 :         libspdm_release_sender_buffer (spdm_context);
+     178                 :          0 :         status = LIBSPDM_STATUS_CRYPTO_ERROR;
+     179                 :          0 :         goto error;
+     180                 :            :     }
+     181                 :            : 
+     182                 :         31 :     status = libspdm_append_message_f(spdm_context, session_info, true,
+     183                 :            :                                       (uint8_t *)spdm_request +
+     184                 :         31 :                                       spdm_request_size - hmac_size,
+     185                 :            :                                       hmac_size);
+     186         [ -  + ]:         31 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     187                 :          0 :         libspdm_release_sender_buffer (spdm_context);
+     188                 :          0 :         goto error;
+     189                 :            :     }
+     190                 :            : 
+     191                 :         31 :     status = libspdm_send_spdm_request(spdm_context, &session_id,
+     192                 :            :                                        spdm_request_size, spdm_request);
+     193         [ +  + ]:         31 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     194                 :          1 :         libspdm_release_sender_buffer (spdm_context);
+     195                 :          1 :         goto error;
+     196                 :            :     }
+     197                 :            : 
+     198                 :         30 :     libspdm_reset_message_buffer_via_request_code(spdm_context, session_info,
+     199                 :            :                                                   SPDM_PSK_FINISH);
+     200                 :            : 
+     201                 :         30 :     libspdm_release_sender_buffer (spdm_context);
+     202                 :         30 :     spdm_request = (void *)spdm_context->last_spdm_request;
+     203                 :            : 
+     204                 :            :     /* receive */
+     205                 :            : 
+     206                 :         30 :     status = libspdm_acquire_receiver_buffer (spdm_context, &message_size, (void **)&message);
+     207         [ -  + ]:         30 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     208                 :          0 :         goto error;
+     209                 :            :     }
+     210         [ -  + ]:         30 :     LIBSPDM_ASSERT (message_size >= transport_header_size);
+     211                 :         30 :     spdm_response = (void *)(message);
+     212                 :         30 :     spdm_response_size = message_size;
+     213                 :            : 
+     214                 :         30 :     status = libspdm_receive_spdm_response(
+     215                 :            :         spdm_context, &session_id, &spdm_response_size, (void **)&spdm_response);
+     216         [ -  + ]:         30 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     217                 :          0 :         goto receive_done;
+     218                 :            :     }
+     219         [ -  + ]:         30 :     if (spdm_response_size < sizeof(spdm_message_header_t)) {
+     220                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     221                 :          0 :         goto receive_done;
+     222                 :            :     }
+     223         [ -  + ]:         30 :     if (spdm_response->header.spdm_version != spdm_request->header.spdm_version) {
+     224                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     225                 :          0 :         goto receive_done;
+     226                 :            :     }
+     227         [ +  + ]:         30 :     if (spdm_response->header.request_response_code == SPDM_ERROR) {
+     228         [ +  + ]:         25 :         if (spdm_response->header.param1 == SPDM_ERROR_CODE_DECRYPT_ERROR) {
+     229                 :          2 :             status = LIBSPDM_STATUS_SESSION_MSG_ERROR;
+     230                 :          2 :             goto receive_done;
+     231                 :            :         }
+     232                 :         23 :         status = libspdm_handle_error_response_main(
+     233                 :            :             spdm_context, &session_id,
+     234                 :            :             &spdm_response_size, (void **)&spdm_response,
+     235                 :            :             SPDM_PSK_FINISH, SPDM_PSK_FINISH_RSP);
+     236         [ +  + ]:         23 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     237                 :         22 :             goto receive_done;
+     238                 :            :         }
+     239         [ +  + ]:          5 :     } else if (spdm_response->header.request_response_code !=
+     240                 :            :                SPDM_PSK_FINISH_RSP) {
+     241                 :          1 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     242                 :          1 :         goto receive_done;
+     243                 :            :     }
+     244                 :            :     /* this message can only be in secured session
+     245                 :            :      * thus don't need to consider transport layer padding, just check its exact size */
+     246         [ -  + ]:          5 :     if (spdm_response_size != sizeof(spdm_psk_finish_response_t)) {
+     247                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     248                 :          0 :         goto receive_done;
+     249                 :            :     }
+     250                 :            : 
+     251                 :          5 :     status = libspdm_append_message_f(spdm_context, session_info, true, spdm_response,
+     252                 :            :                                       spdm_response_size);
+     253         [ -  + ]:          5 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     254                 :          0 :         goto receive_done;
+     255                 :            :     }
+     256                 :            : 
+     257                 :          5 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "libspdm_generate_session_data_key[%x]\n", session_id));
+     258                 :          5 :     result = libspdm_calculate_th2_hash(spdm_context, session_info, true,
+     259                 :            :                                         th2_hash_data);
+     260         [ -  + ]:          5 :     if (!result) {
+     261                 :          0 :         status = LIBSPDM_STATUS_CRYPTO_ERROR;
+     262                 :          0 :         goto receive_done;
+     263                 :            :     }
+     264                 :          5 :     result = libspdm_generate_session_data_key(
+     265                 :            :         session_info->secured_message_context, th2_hash_data);
+     266         [ -  + ]:          5 :     if (!result) {
+     267                 :          0 :         status = LIBSPDM_STATUS_CRYPTO_ERROR;
+     268                 :          0 :         goto receive_done;
+     269                 :            :     }
+     270                 :            : 
+     271                 :          5 :     libspdm_secured_message_set_session_state(
+     272                 :            :         session_info->secured_message_context,
+     273                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+     274                 :            : 
+     275                 :            :     /* -=[Log Message Phase]=- */
+     276                 :            :     #if LIBSPDM_ENABLE_MSG_LOG
+     277                 :          5 :     libspdm_append_msg_log(spdm_context, spdm_response, spdm_response_size);
+     278                 :            :     #endif /* LIBSPDM_ENABLE_MSG_LOG */
+     279                 :            : 
+     280                 :          5 :     libspdm_release_receiver_buffer (spdm_context);
+     281                 :          5 :     return LIBSPDM_STATUS_SUCCESS;
+     282                 :            : 
+     283                 :         25 : receive_done:
+     284                 :         25 :     libspdm_release_receiver_buffer (spdm_context);
+     285                 :         29 : error:
+     286         [ +  + ]:         29 :     if (LIBSPDM_STATUS_BUSY_PEER != status) {
+     287                 :         27 :         libspdm_free_session_id(spdm_context, session_id);
+     288                 :            :     }
+     289                 :         29 :     return status;
+     290                 :            : }
+     291                 :            : 
+     292                 :         33 : libspdm_return_t libspdm_send_receive_psk_finish(libspdm_context_t *spdm_context,
+     293                 :            :                                                  uint32_t session_id)
+     294                 :            : {
+     295                 :            :     size_t retry;
+     296                 :            :     uint64_t retry_delay_time;
+     297                 :            :     libspdm_return_t status;
+     298                 :            : 
+     299                 :         33 :     spdm_context->crypto_request = true;
+     300                 :         33 :     retry = spdm_context->retry_times;
+     301                 :         33 :     retry_delay_time = spdm_context->retry_delay_time;
+     302                 :            :     do {
+     303                 :         34 :         status = libspdm_try_send_receive_psk_finish(spdm_context,
+     304                 :            :                                                      session_id);
+     305         [ +  + ]:         34 :         if (status != LIBSPDM_STATUS_BUSY_PEER) {
+     306                 :         32 :             return status;
+     307                 :            :         }
+     308                 :            : 
+     309                 :          2 :         libspdm_sleep(retry_delay_time);
+     310         [ +  + ]:          2 :     } while (retry-- != 0);
+     311                 :            : 
+     312                 :          1 :     return status;
+     313                 :            : }
+     314                 :            : 
+     315                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_send_receive.c.func-sort-c.html b/coverage_log/library/spdm_requester_lib/libspdm_req_send_receive.c.func-sort-c.html new file mode 100644 index 00000000000..4c353c89433 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_send_receive.c.func-sort-c.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_send_receive.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_send_receive.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:28033284.3 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:14622265.8 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_handle_large_request11
libspdm_receive_spdm_response2543
libspdm_receive_response2552
libspdm_send_spdm_request2580
libspdm_send_request2581
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_send_receive.c.func.html b/coverage_log/library/spdm_requester_lib/libspdm_req_send_receive.c.func.html new file mode 100644 index 00000000000..7bd835ab072 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_send_receive.c.func.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_send_receive.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_send_receive.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:28033284.3 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:14622265.8 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_handle_large_request11
libspdm_receive_response2552
libspdm_receive_spdm_response2543
libspdm_send_request2581
libspdm_send_spdm_request2580
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_send_receive.c.gcov.html b/coverage_log/library/spdm_requester_lib/libspdm_req_send_receive.c.gcov.html new file mode 100644 index 00000000000..2e7f6a7f973 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_send_receive.c.gcov.html @@ -0,0 +1,840 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_send_receive.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_send_receive.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:28033284.3 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:14622265.8 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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                 :            : #include "internal/libspdm_secured_message_lib.h"
+       9                 :            : 
+      10                 :       2581 : libspdm_return_t libspdm_send_request(void *spdm_context, const uint32_t *session_id,
+      11                 :            :                                       bool is_app_message,
+      12                 :            :                                       size_t request_size, void *request)
+      13                 :            : {
+      14                 :            :     libspdm_context_t *context;
+      15                 :            :     libspdm_return_t status;
+      16                 :            :     uint8_t *message;
+      17                 :            :     size_t message_size;
+      18                 :            :     uint64_t timeout;
+      19                 :            :     uint8_t *scratch_buffer;
+      20                 :            :     size_t scratch_buffer_size;
+      21                 :            :     size_t transport_header_size;
+      22                 :            :     uint8_t *sender_buffer;
+      23                 :            :     size_t sender_buffer_size;
+      24                 :            : 
+      25                 :       2581 :     context = spdm_context;
+      26                 :            : 
+      27         [ +  + ]:       2581 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+      28                 :            :                    "libspdm_send_spdm_request[%x] msg %s(0x%x), size (0x%zx): \n",
+      29                 :            :                    (session_id != NULL) ? *session_id : 0x0,
+      30                 :            :                    libspdm_get_code_str(((spdm_message_header_t *)request)->
+      31                 :            :                                         request_response_code),
+      32                 :            :                    ((spdm_message_header_t *)request)->request_response_code,
+      33                 :            :                    request_size));
+      34                 :       2581 :     LIBSPDM_INTERNAL_DUMP_HEX(request, request_size);
+      35                 :            : 
+      36                 :       2581 :     transport_header_size = context->local_context.capability.transport_header_size;
+      37                 :       2581 :     libspdm_get_scratch_buffer(context, (void**) &scratch_buffer, &scratch_buffer_size);
+      38                 :       2581 :     libspdm_get_sender_buffer(context, (void**) &sender_buffer, &sender_buffer_size);
+      39                 :            : 
+      40                 :            :     /* This is a problem because original code assumes request is in the sender buffer,
+      41                 :            :      * when it can really be using the scratch space for chunking.
+      42                 :            :      * Did not want to modify ally request handlers to pass this information,
+      43                 :            :      * so just making the determination here by examining scratch/sender buffers.
+      44                 :            :      * This may be something that should be refactored in the future. */
+      45                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
+      46         [ +  - ]:       2581 :     if ((uint8_t*) request >= sender_buffer &&
+      47         [ -  + ]:       2581 :         (uint8_t*)request < sender_buffer + sender_buffer_size) {
+      48                 :          0 :         message = sender_buffer;
+      49                 :          0 :         message_size = sender_buffer_size;
+      50                 :            :     } else {
+      51                 :       2581 :         if ((uint8_t*)request >=
+      52         [ +  - ]:       2581 :             scratch_buffer + libspdm_get_scratch_buffer_sender_receiver_offset(spdm_context)
+      53                 :       2581 :             && (uint8_t*)request <
+      54                 :       5162 :             scratch_buffer + libspdm_get_scratch_buffer_sender_receiver_offset(spdm_context)
+      55         [ +  + ]:       2581 :             + libspdm_get_scratch_buffer_sender_receiver_capacity(spdm_context)) {
+      56                 :        162 :             message = scratch_buffer +
+      57                 :         81 :                       libspdm_get_scratch_buffer_sender_receiver_offset(spdm_context);
+      58                 :         81 :             message_size = libspdm_get_scratch_buffer_sender_receiver_capacity(spdm_context);
+      59                 :       2500 :         } else if ((uint8_t*)request >=
+      60                 :       5000 :                    scratch_buffer +
+      61         [ +  - ]:       2500 :                    libspdm_get_scratch_buffer_large_sender_receiver_offset(spdm_context)
+      62                 :       2500 :                    && (uint8_t*)request <
+      63                 :            :                    scratch_buffer +
+      64                 :       2500 :                    libspdm_get_scratch_buffer_large_sender_receiver_offset(spdm_context) +
+      65         [ +  - ]:       2500 :                    libspdm_get_scratch_buffer_large_sender_receiver_capacity(spdm_context)) {
+      66                 :       5000 :             message = scratch_buffer +
+      67                 :       2500 :                       libspdm_get_scratch_buffer_large_sender_receiver_offset(spdm_context);
+      68                 :       2500 :             message_size = libspdm_get_scratch_buffer_large_sender_receiver_capacity(spdm_context);
+      69                 :            :         }
+      70                 :            :     }
+      71                 :            :     #else /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP */
+      72                 :            :     message = sender_buffer;
+      73                 :            :     message_size = sender_buffer_size;
+      74                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP */
+      75                 :            : 
+      76         [ +  + ]:       2581 :     if (session_id != NULL) {
+      77                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+      78                 :            :          * transport_message is always in sender buffer. */
+      79                 :            : 
+      80                 :        234 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+      81                 :            :                           scratch_buffer_size - transport_header_size,
+      82                 :            :                           request, request_size);
+      83                 :        234 :         request = scratch_buffer + transport_header_size;
+      84                 :            :     }
+      85                 :            : 
+      86                 :            :     /* backup it to last_spdm_request, because the caller wants to compare it with response */
+      87         [ +  + ]:       2581 :     if (((const spdm_message_header_t *)request)->request_response_code != SPDM_RESPOND_IF_READY
+      88         [ +  + ]:       2554 :         && ((const spdm_message_header_t *)request)->request_response_code != SPDM_CHUNK_GET
+      89         [ +  + ]:       2486 :         && ((const spdm_message_header_t*) request)->request_response_code != SPDM_CHUNK_SEND) {
+      90                 :       2473 :         libspdm_copy_mem (context->last_spdm_request,
+      91                 :       2473 :                           libspdm_get_scratch_buffer_last_spdm_request_capacity(context),
+      92                 :            :                           request,
+      93                 :            :                           request_size
+      94                 :            :                           );
+      95                 :       2473 :         context->last_spdm_request_size = request_size;
+      96                 :            :     }
+      97                 :            : 
+      98                 :       2581 :     status = context->transport_encode_message(
+      99                 :            :         context, session_id, is_app_message, true, request_size,
+     100                 :            :         request, &message_size, (void **)&message);
+     101         [ -  + ]:       2581 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     102                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "transport_encode_message status - %xu\n",
+     103                 :            :                        status));
+     104   [ #  #  #  # ]:          0 :         if ((session_id != NULL) &&
+     105         [ #  # ]:          0 :             ((status == LIBSPDM_STATUS_SEQUENCE_NUMBER_OVERFLOW) ||
+     106                 :            :              (status == LIBSPDM_STATUS_CRYPTO_ERROR))) {
+     107                 :          0 :             libspdm_free_session_id(context, *session_id);
+     108                 :            :         }
+     109                 :          0 :         return status;
+     110                 :            :     }
+     111                 :            : 
+     112                 :       2581 :     timeout = context->local_context.capability.rtt;
+     113                 :            : 
+     114                 :       2581 :     status = context->send_message(context, message_size, message,
+     115                 :            :                                    timeout);
+     116         [ +  + ]:       2581 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     117         [ +  + ]:         23 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "libspdm_send_spdm_request[%x] status - %xu\n",
+     118                 :            :                        (session_id != NULL) ? *session_id : 0x0, status));
+     119                 :            :     }
+     120                 :            : 
+     121                 :       2581 :     return status;
+     122                 :            : }
+     123                 :            : 
+     124                 :       2552 : libspdm_return_t libspdm_receive_response(void *spdm_context, const uint32_t *session_id,
+     125                 :            :                                           bool is_app_message,
+     126                 :            :                                           size_t *response_size,
+     127                 :            :                                           void **response)
+     128                 :            : {
+     129                 :            :     libspdm_context_t *context;
+     130                 :            :     void *temp_session_context;
+     131                 :            :     libspdm_return_t status;
+     132                 :            :     uint8_t *message;
+     133                 :            :     size_t message_size;
+     134                 :            :     uint32_t *message_session_id;
+     135                 :            :     bool is_message_app_message;
+     136                 :            :     uint64_t timeout;
+     137                 :            :     size_t transport_header_size;
+     138                 :            :     uint8_t *scratch_buffer;
+     139                 :            :     size_t scratch_buffer_size;
+     140                 :            :     void *backup_response;
+     141                 :            :     size_t backup_response_size;
+     142                 :            :     bool reset_key_update;
+     143                 :            :     bool result;
+     144                 :            : 
+     145                 :       2552 :     context = spdm_context;
+     146                 :            : 
+     147         [ +  + ]:       2552 :     if (context->crypto_request) {
+     148                 :       2370 :         timeout = context->local_context.capability.rtt +
+     149                 :       2370 :                   ((uint64_t)1 << context->connection_info.capability.ct_exponent);
+     150                 :            :     } else {
+     151                 :        182 :         timeout = context->local_context.capability.rtt +
+     152                 :        182 :                   context->local_context.capability.st1;
+     153                 :            :     }
+     154                 :            : 
+     155                 :       2552 :     message = *response;
+     156                 :       2552 :     message_size = *response_size;
+     157                 :       2552 :     status = context->receive_message(context, &message_size,
+     158                 :            :                                       (void **)&message, timeout);
+     159         [ +  + ]:       2552 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     160         [ -  + ]:          9 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+     161                 :            :                        "libspdm_receive_spdm_response[%x] status - %xu\n",
+     162                 :            :                        (session_id != NULL) ? *session_id : 0x0, status));
+     163                 :          9 :         return status;
+     164                 :            :     }
+     165                 :            : 
+     166                 :       2543 :     message_session_id = NULL;
+     167                 :       2543 :     is_message_app_message = false;
+     168                 :            : 
+     169                 :            :     /* always use scratch buffer to response.
+     170                 :            :      * if it is secured message, this scratch buffer will be used.
+     171                 :            :      * if it is normal message, the response ptr will point to receiver buffer. */
+     172                 :       2543 :     transport_header_size = context->local_context.capability.transport_header_size;
+     173                 :       2543 :     libspdm_get_scratch_buffer (context, (void **)&scratch_buffer, &scratch_buffer_size);
+     174                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
+     175                 :       2543 :     *response = scratch_buffer + libspdm_get_scratch_buffer_secure_message_offset(context) +
+     176                 :            :                 transport_header_size;
+     177                 :       2543 :     *response_size = libspdm_get_scratch_buffer_secure_message_capacity(context) -
+     178                 :            :                      transport_header_size;
+     179                 :            :     #else
+     180                 :            :     *response = scratch_buffer + transport_header_size;
+     181                 :            :     *response_size = scratch_buffer_size - transport_header_size;
+     182                 :            :     #endif
+     183                 :            : 
+     184                 :       2543 :     backup_response = *response;
+     185                 :       2543 :     backup_response_size = *response_size;
+     186                 :            : 
+     187                 :       2543 :     status = context->transport_decode_message(
+     188                 :            :         context, &message_session_id, &is_message_app_message,
+     189                 :            :         false, message_size, message, response_size, response);
+     190                 :            : 
+     191                 :       2543 :     reset_key_update = false;
+     192                 :       2543 :     temp_session_context = NULL;
+     193                 :            : 
+     194         [ +  + ]:       2543 :     if (status == LIBSPDM_STATUS_SESSION_TRY_DISCARD_KEY_UPDATE) {
+     195                 :            :         /* Failed to decode, but have backup keys. Try rolling back before aborting.
+     196                 :            :          * message_session_id must be valid for us to have attempted decryption. */
+     197         [ -  + ]:         27 :         if (message_session_id == NULL) {
+     198                 :          0 :             return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+     199                 :            :         }
+     200                 :         27 :         temp_session_context = libspdm_get_secured_message_context_via_session_id(
+     201                 :            :             context, *message_session_id);
+     202         [ -  + ]:         27 :         if (temp_session_context == NULL) {
+     203                 :          0 :             return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+     204                 :            :         }
+     205                 :            : 
+     206                 :         27 :         result = libspdm_activate_update_session_data_key(
+     207                 :            :             temp_session_context, LIBSPDM_KEY_UPDATE_ACTION_RESPONDER, false);
+     208         [ -  + ]:         27 :         if (!result) {
+     209                 :          0 :             return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+     210                 :            :         }
+     211                 :            : 
+     212                 :            :         /* Retry decoding message with backup Requester key.
+     213                 :            :          * Must reset some of the parameters in case they were modified */
+     214                 :         27 :         message_session_id = NULL;
+     215                 :         27 :         is_message_app_message = false;
+     216                 :         27 :         *response = backup_response;
+     217                 :         27 :         *response_size = backup_response_size;
+     218                 :         27 :         status = context->transport_decode_message(
+     219                 :            :             context, &message_session_id, &is_message_app_message,
+     220                 :            :             false, message_size, message, response_size, response);
+     221                 :            : 
+     222                 :         27 :         reset_key_update = true;
+     223                 :            :     }
+     224                 :            : 
+     225         [ +  + ]:       2543 :     if (session_id != NULL) {
+     226         [ -  + ]:        230 :         if (message_session_id == NULL) {
+     227         [ #  # ]:          0 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+     228                 :            :                            "libspdm_receive_spdm_response[%x] GetSessionId - NULL\n",
+     229                 :            :                            (session_id != NULL) ? *session_id : 0x0));
+     230                 :          0 :             goto error;
+     231                 :            :         }
+     232         [ -  + ]:        230 :         if (*message_session_id != *session_id) {
+     233         [ #  # ]:          0 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+     234                 :            :                            "libspdm_receive_spdm_response[%x] GetSessionId - %x\n",
+     235                 :            :                            (session_id != NULL) ? *session_id : 0x0,
+     236                 :            :                            *message_session_id));
+     237                 :          0 :             goto error;
+     238                 :            :         }
+     239                 :            :     } else {
+     240         [ -  + ]:       2313 :         if (message_session_id != NULL) {
+     241         [ #  # ]:          0 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+     242                 :            :                            "libspdm_receive_spdm_response[%x] GetSessionId - %x\n",
+     243                 :            :                            (session_id != NULL) ? *session_id : 0x0,
+     244                 :            :                            *message_session_id));
+     245                 :          0 :             goto error;
+     246                 :            :         }
+     247                 :            :     }
+     248                 :            : 
+     249   [ -  +  -  - ]:       2543 :     if ((is_app_message && !is_message_app_message) ||
+     250   [ +  -  -  + ]:       2543 :         (!is_app_message && is_message_app_message)) {
+     251         [ #  # ]:          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+     252                 :            :                        "libspdm_receive_spdm_response[%x] app_message mismatch\n",
+     253                 :            :                        (session_id != NULL) ? *session_id : 0x0));
+     254                 :          0 :         goto error;
+     255                 :            :     }
+     256                 :            : 
+     257         [ -  + ]:       2543 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     258         [ #  # ]:          0 :         if ((session_id != NULL) &&
+     259         [ #  # ]:          0 :             (context->last_spdm_error.error_code == SPDM_ERROR_CODE_DECRYPT_ERROR)) {
+     260                 :          0 :             libspdm_free_session_id(context, *session_id);
+     261                 :            :         }
+     262         [ #  # ]:          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+     263                 :            :                        "libspdm_receive_spdm_response[%x] status - %xu\n",
+     264                 :            :                        (session_id != NULL) ? *session_id : 0x0, status));
+     265                 :            :     } else {
+     266         [ +  + ]:       2543 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+     267                 :            :                        "libspdm_receive_spdm_response[%x] msg %s(0x%x), size (0x%zx): \n",
+     268                 :            :                        (session_id != NULL) ? *session_id : 0x0,
+     269                 :            :                        libspdm_get_code_str(((spdm_message_header_t *)*response)->
+     270                 :            :                                             request_response_code),
+     271                 :            :                        ((spdm_message_header_t *)*response)->request_response_code,
+     272                 :            :                        *response_size));
+     273                 :       2543 :         LIBSPDM_INTERNAL_DUMP_HEX(*response, *response_size);
+     274                 :            :     }
+     275                 :            : 
+     276                 :            :     /* Handle special case:
+     277                 :            :      * If the Responder returns RESPONSE_NOT_READY error to KEY_UPDATE, the Requester needs
+     278                 :            :      * to activate backup key to parse the error. Then later the Responder will return SUCCESS,
+     279                 :            :      * the Requester needs new key. So we need to restore the environment by
+     280                 :            :      * libspdm_create_update_session_data_key() again.*/
+     281         [ +  + ]:       2543 :     if (reset_key_update) {
+     282                 :            :         /* temp_session_context and message_session_id must necessarily
+     283                 :            :          * be valid for us to reach here. */
+     284   [ +  -  -  + ]:         27 :         if (temp_session_context == NULL || message_session_id == NULL) {
+     285                 :          0 :             return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+     286                 :            :         }
+     287                 :         27 :         result = libspdm_create_update_session_data_key(
+     288                 :            :             temp_session_context, LIBSPDM_KEY_UPDATE_ACTION_RESPONDER);
+     289         [ -  + ]:         27 :         if (!result) {
+     290                 :          0 :             return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+     291                 :            :         }
+     292                 :            :     }
+     293                 :            : 
+     294                 :       2543 :     return status;
+     295                 :            : 
+     296                 :          0 : error:
+     297         [ #  # ]:          0 :     if (context->last_spdm_error.error_code == SPDM_ERROR_CODE_DECRYPT_ERROR) {
+     298                 :          0 :         return LIBSPDM_STATUS_SESSION_MSG_ERROR;
+     299                 :            :     } else {
+     300                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+     301                 :            :     }
+     302                 :            : }
+     303                 :            : 
+     304                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
+     305                 :         11 : libspdm_return_t libspdm_handle_large_request(
+     306                 :            :     libspdm_context_t *spdm_context,
+     307                 :            :     const uint32_t *session_id,
+     308                 :            :     size_t request_size, void *request)
+     309                 :            : {
+     310                 :            :     libspdm_return_t status;
+     311                 :            : 
+     312                 :            :     spdm_chunk_send_request_t *spdm_request;
+     313                 :            :     size_t spdm_request_size;
+     314                 :            :     spdm_chunk_send_ack_response_t *spdm_response;
+     315                 :            :     uint8_t *message;
+     316                 :            :     size_t message_size;
+     317                 :            :     void *response;
+     318                 :            :     size_t response_size;
+     319                 :            :     size_t transport_header_size;
+     320                 :            : 
+     321                 :            :     uint8_t *scratch_buffer;
+     322                 :            :     size_t scratch_buffer_size;
+     323                 :            : 
+     324                 :            :     uint8_t *chunk_ptr;
+     325                 :            :     size_t copy_size;
+     326                 :            :     libspdm_chunk_info_t *send_info;
+     327                 :            :     uint32_t min_data_transfer_size;
+     328                 :            :     spdm_error_response_t *spdm_error;
+     329                 :            : 
+     330         [ -  + ]:         11 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_12) {
+     331                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     332                 :            :     }
+     333                 :            : 
+     334                 :            :     /* Fail if requester or responder does not support chunk cap */
+     335         [ -  + ]:         11 :     if (!libspdm_is_capabilities_flag_supported(
+     336                 :            :             spdm_context, true,
+     337                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP,
+     338                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP)) {
+     339                 :          0 :         return LIBSPDM_STATUS_ERROR_PEER;
+     340                 :            :     }
+     341                 :            : 
+     342                 :            :     /* now we can get sender buffer */
+     343                 :         11 :     transport_header_size = spdm_context->local_context.capability.transport_header_size;
+     344                 :            : 
+     345                 :         11 :     libspdm_get_scratch_buffer(spdm_context, (void**) &scratch_buffer, &scratch_buffer_size);
+     346                 :            : 
+     347                 :            :     /* Temporary send/receive buffers for chunking are in the scratch space */
+     348                 :         11 :     message = scratch_buffer + libspdm_get_scratch_buffer_sender_receiver_offset(spdm_context);
+     349                 :         11 :     message_size = libspdm_get_scratch_buffer_sender_receiver_capacity(spdm_context);
+     350                 :            : 
+     351                 :         11 :     send_info = &spdm_context->chunk_context.send;
+     352                 :         11 :     send_info->chunk_in_use = true;
+     353                 :            : 
+     354                 :            :     /* The first section of the scratch
+     355                 :            :      * buffer may be used for other purposes. Use only after that section. */
+     356                 :         22 :     send_info->large_message = scratch_buffer +
+     357                 :         11 :                                libspdm_get_scratch_buffer_large_message_offset(spdm_context);
+     358                 :         11 :     send_info->large_message_capacity =
+     359                 :         11 :         libspdm_get_scratch_buffer_large_message_capacity(spdm_context);
+     360                 :            : 
+     361                 :         11 :     libspdm_zero_mem(send_info->large_message, send_info->large_message_capacity);
+     362                 :         11 :     libspdm_copy_mem(send_info->large_message, send_info->large_message_capacity,
+     363                 :            :                      request, request_size);
+     364                 :            : 
+     365                 :         11 :     send_info->large_message_size = request_size;
+     366                 :         11 :     send_info->chunk_bytes_transferred = 0;
+     367                 :         11 :     send_info->chunk_seq_no = 0;
+     368                 :         11 :     request = NULL; /* Invalidate to prevent accidental use. */
+     369                 :         11 :     request_size = 0;
+     370                 :            : 
+     371                 :         11 :     min_data_transfer_size = LIBSPDM_MIN(
+     372                 :            :         spdm_context->connection_info.capability.data_transfer_size,
+     373                 :            :         spdm_context->local_context.capability.sender_data_transfer_size);
+     374                 :            : 
+     375                 :            :     do {
+     376         [ -  + ]:         13 :         LIBSPDM_ASSERT(send_info->large_message_capacity >= transport_header_size);
+     377                 :         13 :         spdm_request = (spdm_chunk_send_request_t*) ((uint8_t*) message + transport_header_size);
+     378                 :         13 :         spdm_request_size = message_size - transport_header_size;
+     379                 :            : 
+     380                 :         13 :         spdm_request->header.spdm_version = libspdm_get_connection_version(spdm_context);
+     381                 :         13 :         spdm_request->header.request_response_code = SPDM_CHUNK_SEND;
+     382                 :         13 :         spdm_request->header.param1 = 0;
+     383                 :         13 :         spdm_request->header.param2 = send_info->chunk_handle;
+     384                 :         13 :         spdm_request->chunk_seq_no = send_info->chunk_seq_no;
+     385                 :         13 :         spdm_request->reserved = 0;
+     386                 :         13 :         chunk_ptr = (uint8_t*) (spdm_request + 1);
+     387                 :            : 
+     388                 :         13 :         if (min_data_transfer_size
+     389                 :         13 :             - sizeof(spdm_chunk_send_request_t)
+     390         [ +  + ]:         13 :             < (send_info->large_message_size - send_info->chunk_bytes_transferred)) {
+     391                 :            : 
+     392                 :         11 :             copy_size = min_data_transfer_size
+     393                 :         11 :                         - sizeof(spdm_chunk_send_request_t);
+     394                 :            :         } else {
+     395                 :          2 :             copy_size = (send_info->large_message_size - send_info->chunk_bytes_transferred);
+     396                 :            :         }
+     397                 :            : 
+     398         [ +  + ]:         13 :         if (send_info->chunk_seq_no == 0) {
+     399                 :         11 :             *(uint32_t*) (spdm_request + 1) = (uint32_t) send_info->large_message_size;
+     400                 :         11 :             chunk_ptr += sizeof(uint32_t);
+     401                 :         11 :             copy_size -= sizeof(uint32_t);
+     402                 :            :         }
+     403                 :            : 
+     404                 :         13 :         spdm_request->chunk_size = (uint32_t) copy_size;
+     405                 :            : 
+     406                 :         13 :         libspdm_copy_mem(
+     407                 :         13 :             chunk_ptr, spdm_request_size - ((uint8_t*) spdm_request - (uint8_t*) message),
+     408                 :         13 :             (uint8_t*)send_info->large_message + send_info->chunk_bytes_transferred, copy_size);
+     409                 :            : 
+     410                 :         13 :         send_info->chunk_bytes_transferred += copy_size;
+     411         [ +  + ]:         13 :         if (send_info->chunk_bytes_transferred >= send_info->large_message_size) {
+     412                 :          2 :             spdm_request->header.param1 |= SPDM_CHUNK_SEND_REQUEST_ATTRIBUTE_LAST_CHUNK;
+     413                 :            :         }
+     414                 :            : 
+     415                 :         13 :         spdm_request_size = (chunk_ptr + copy_size) - (uint8_t*)spdm_request;
+     416                 :         13 :         status = libspdm_send_request(
+     417                 :            :             spdm_context, session_id, false,
+     418                 :            :             spdm_request_size, spdm_request);
+     419                 :            : 
+     420         [ +  + ]:         13 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     421                 :          1 :             break;
+     422                 :            :         }
+     423                 :            : 
+     424                 :         12 :         response = message;
+     425                 :         12 :         response_size = message_size;
+     426                 :            : 
+     427                 :         12 :         libspdm_zero_mem(response, response_size);
+     428                 :            : 
+     429                 :         12 :         status = libspdm_receive_response(
+     430                 :            :             spdm_context, session_id, false,
+     431                 :            :             &response_size, &response);
+     432                 :            : 
+     433         [ +  + ]:         12 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     434                 :          1 :             break;
+     435                 :            :         }
+     436                 :         11 :         spdm_response = (void*) (response);
+     437                 :            : 
+     438         [ -  + ]:         11 :         if (response_size < sizeof(spdm_message_header_t)) {
+     439                 :          0 :             status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     440                 :          0 :             break;
+     441                 :            :         }
+     442         [ +  + ]:         11 :         if (spdm_response->header.spdm_version != libspdm_get_connection_version(spdm_context)) {
+     443                 :          1 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     444                 :          1 :             break;
+     445                 :            :         }
+     446                 :            : 
+     447         [ +  + ]:         10 :         if (spdm_response->header.request_response_code == SPDM_ERROR
+     448         [ -  + ]:          1 :             && spdm_response->header.param1 == SPDM_ERROR_CODE_LARGE_RESPONSE) {
+     449                 :            : 
+     450                 :            :             /* It is possible that the CHUNK_SEND_ACK + chunk response is larger
+     451                 :            :              * than the DATA_TRANSFER_SIZE. In this case an ERROR_LARGE_RESPONSE
+     452                 :            :              * is returned directly in the response buffer rather than part of
+     453                 :            :              * the CHUNK_SEND_ACK. Store this error response in scratch buffer
+     454                 :            :              * to be handled when reading response. Also note that in this case
+     455                 :            :              * of large response, the CHUNK_SEND_ACK portion is not sent.
+     456                 :            :              * Only the response portion that requires the CHUNK_GET is sent */
+     457         [ #  # ]:          0 :             if (response_size < send_info->large_message_capacity) {
+     458                 :          0 :                 libspdm_copy_mem(
+     459                 :            :                     send_info->large_message, send_info->large_message_capacity,
+     460                 :            :                     spdm_response, response_size);
+     461                 :          0 :                 send_info->large_message_size = response_size;
+     462                 :          0 :                 break;
+     463                 :            :             } else {
+     464                 :          0 :                 status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     465                 :          0 :                 break;
+     466                 :            :             }
+     467                 :            :         } else {
+     468         [ +  + ]:         10 :             if (spdm_response->header.request_response_code != SPDM_CHUNK_SEND_ACK) {
+     469                 :          1 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     470                 :          1 :                 break;
+     471                 :            :             }
+     472                 :            : 
+     473         [ +  + ]:          9 :             if (response_size < sizeof(spdm_chunk_send_ack_response_t)) {
+     474                 :          1 :                 status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     475                 :          1 :                 break;
+     476                 :            :             }
+     477                 :          8 :             if (spdm_response->header.param1
+     478         [ +  + ]:          8 :                 & SPDM_CHUNK_SEND_ACK_RESPONSE_ATTRIBUTE_EARLY_ERROR_DETECTED) {
+     479                 :            : 
+     480                 :          2 :                 spdm_error = (spdm_error_response_t *) (spdm_response + 1);
+     481         [ -  + ]:          2 :                 if (response_size < (sizeof(spdm_chunk_send_ack_response_t) +
+     482                 :            :                                      sizeof(spdm_error_response_t))) {
+     483                 :          0 :                     status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     484                 :          0 :                     break;
+     485                 :            :                 }
+     486         [ +  - ]:          2 :                 if ((spdm_error->header.spdm_version !=
+     487                 :          2 :                      libspdm_get_connection_version(spdm_context)) ||
+     488         [ -  + ]:          2 :                     (spdm_error->header.request_response_code != SPDM_ERROR)) {
+     489                 :          0 :                     status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     490                 :          0 :                     break;
+     491                 :            :                 }
+     492         [ +  + ]:          2 :                 if (spdm_error->header.param1 == SPDM_ERROR_CODE_LARGE_RESPONSE) {
+     493                 :          1 :                     status = LIBSPDM_STATUS_ERROR_PEER;
+     494                 :          1 :                     break;
+     495                 :            :                 }
+     496                 :            : 
+     497                 :            :                 /* Store the error response in scratch buffer to be read by
+     498                 :            :                  * libspdm_receive_spdm_response and returned to its caller
+     499                 :            :                  * and handled in the error response handling flow */
+     500                 :          1 :                 libspdm_copy_mem(
+     501                 :            :                     send_info->large_message,
+     502                 :            :                     send_info->large_message_capacity,
+     503                 :          1 :                     (uint8_t*) (spdm_response + 1),
+     504                 :            :                     response_size - sizeof(spdm_chunk_send_ack_response_t));
+     505                 :            : 
+     506                 :          1 :                 send_info->large_message_size =
+     507                 :          1 :                     (response_size - sizeof(spdm_chunk_send_ack_response_t));
+     508                 :            : 
+     509                 :          1 :                 status = LIBSPDM_STATUS_SUCCESS;
+     510                 :          1 :                 break;
+     511                 :            :             }
+     512         [ +  + ]:          6 :             if (spdm_response->header.param2 != send_info->chunk_handle) {
+     513                 :          1 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     514                 :          1 :                 break;
+     515                 :            :             }
+     516         [ +  + ]:          5 :             if (send_info->chunk_seq_no != spdm_response->chunk_seq_no) {
+     517                 :          1 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     518                 :          1 :                 break;
+     519                 :            :             }
+     520                 :            : 
+     521                 :          4 :             chunk_ptr = (uint8_t*) (spdm_response + 1);
+     522                 :          4 :             send_info->chunk_seq_no++;
+     523                 :            : 
+     524         [ +  + ]:          4 :             if (send_info->chunk_bytes_transferred >= send_info->large_message_size) {
+     525                 :            : 
+     526                 :            :                 /* All bytes have been transferred. Store response in scratch buffer
+     527                 :            :                  * to be read by libspdm_receive_spdm_response */
+     528                 :          2 :                 libspdm_copy_mem(
+     529                 :            :                     send_info->large_message, send_info->large_message_capacity,
+     530                 :            :                     chunk_ptr, response_size - sizeof(spdm_chunk_send_ack_response_t));
+     531                 :          2 :                 send_info->large_message_size =
+     532                 :          2 :                     (response_size - sizeof(spdm_chunk_send_ack_response_t));
+     533                 :          2 :                 break;
+     534                 :            :             }
+     535                 :            :         }
+     536                 :            : 
+     537                 :          2 :     } while (LIBSPDM_STATUS_IS_SUCCESS(status)
+     538   [ +  -  +  - ]:          2 :              && send_info->chunk_bytes_transferred < send_info->large_message_size);
+     539                 :            : 
+     540         [ +  + ]:         11 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     541                 :            : 
+     542                 :          8 :         send_info->chunk_in_use = false;
+     543                 :          8 :         send_info->chunk_handle++; /* Implicit wrap-around*/
+     544                 :          8 :         send_info->chunk_seq_no = 0;
+     545                 :          8 :         send_info->chunk_bytes_transferred = 0;
+     546                 :          8 :         send_info->large_message = NULL;
+     547                 :          8 :         send_info->large_message_size = 0;
+     548                 :            :     }
+     549                 :            : 
+     550                 :         11 :     return status;
+     551                 :            : }
+     552                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP */
+     553                 :            : 
+     554                 :       2580 : libspdm_return_t libspdm_send_spdm_request(libspdm_context_t *spdm_context,
+     555                 :            :                                            const uint32_t *session_id,
+     556                 :            :                                            size_t request_size, void *request)
+     557                 :            : {
+     558                 :            :     libspdm_session_info_t *session_info;
+     559                 :            :     libspdm_session_state_t session_state;
+     560                 :            :     libspdm_return_t status;
+     561                 :            :     #if LIBSPDM_ENABLE_MSG_LOG
+     562                 :            :     size_t msg_log_size;
+     563                 :            :     #endif /* LIBSPDM_ENABLE_MSG_LOG */
+     564                 :            : 
+     565                 :            :     /* large SPDM message is the SPDM message whose size is greater than the DataTransferSize of the receiving
+     566                 :            :      * SPDM endpoint or greater than the transmit buffer size of the sending SPDM endpoint */
+     567         [ +  + ]:       2580 :     if (((spdm_context->connection_info.capability.data_transfer_size != 0 &&
+     568         [ +  + ]:         13 :           request_size > spdm_context->connection_info.capability.data_transfer_size) ||
+     569         [ +  - ]:       2569 :          (spdm_context->local_context.capability.sender_data_transfer_size != 0 &&
+     570         [ +  + ]:       2569 :           request_size > spdm_context->local_context.capability.sender_data_transfer_size)) &&
+     571         [ -  + ]:         12 :         !libspdm_is_capabilities_flag_supported(
+     572                 :            :             spdm_context, true,
+     573                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP,
+     574                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP)) {
+     575                 :          0 :         return LIBSPDM_STATUS_SEND_FAIL;
+     576                 :            :     }
+     577                 :            : 
+     578   [ +  +  +  + ]:       2852 :     if ((session_id != NULL) &&
+     579                 :        272 :         libspdm_is_capabilities_flag_supported(
+     580                 :            :             spdm_context, true,
+     581                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP,
+     582                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)) {
+     583                 :         38 :         session_info = libspdm_get_session_info_via_session_id(
+     584                 :            :             spdm_context, *session_id);
+     585         [ -  + ]:         38 :         LIBSPDM_ASSERT(session_info != NULL);
+     586         [ -  + ]:         38 :         if (session_info == NULL) {
+     587                 :          0 :             return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+     588                 :            :         }
+     589                 :         38 :         session_state = libspdm_secured_message_get_session_state(
+     590                 :            :             session_info->secured_message_context);
+     591         [ +  - ]:         38 :         if ((session_state == LIBSPDM_SESSION_STATE_HANDSHAKING) &&
+     592         [ +  - ]:         38 :             !session_info->use_psk) {
+     593                 :         38 :             session_id = NULL;
+     594                 :            :         }
+     595                 :            :     }
+     596                 :            : 
+     597         [ +  + ]:       2580 :     if ((spdm_context->connection_info.capability.max_spdm_msg_size != 0) &&
+     598         [ +  + ]:         13 :         (request_size > spdm_context->connection_info.capability.max_spdm_msg_size)) {
+     599                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR, "request_size > rsp max_spdm_msg_size\n"));
+     600                 :          1 :         return LIBSPDM_STATUS_PEER_BUFFER_TOO_SMALL;
+     601                 :            :     }
+     602         [ -  + ]:       2579 :     LIBSPDM_ASSERT (request_size <= spdm_context->local_context.capability.max_spdm_msg_size);
+     603                 :            : 
+     604                 :            :     #if LIBSPDM_ENABLE_MSG_LOG
+     605                 :            :     /* First save the size of the message log buffer. If there is an error it will be reverted. */
+     606                 :       2579 :     msg_log_size = libspdm_get_msg_log_size(spdm_context);
+     607                 :       2579 :     libspdm_append_msg_log(spdm_context, request, request_size);
+     608                 :            :     #endif /* LIBSPDM_ENABLE_MSG_LOG */
+     609                 :            : 
+     610                 :            :     /* large SPDM message is the SPDM message whose size is greater than the DataTransferSize of the receiving
+     611                 :            :      * SPDM endpoint or greater than the transmit buffer size of the sending SPDM endpoint */
+     612         [ +  + ]:       2579 :     if (((const spdm_message_header_t*) request)->request_response_code != SPDM_GET_VERSION
+     613         [ +  + ]:       2541 :         && ((const spdm_message_header_t*) request)->request_response_code != SPDM_GET_CAPABILITIES
+     614         [ +  + ]:       2476 :         && ((spdm_context->connection_info.capability.data_transfer_size != 0 &&
+     615         [ +  + ]:         11 :              request_size > spdm_context->connection_info.capability.data_transfer_size) ||
+     616         [ +  - ]:       2466 :             (spdm_context->local_context.capability.sender_data_transfer_size != 0 &&
+     617         [ +  + ]:       2466 :              request_size > spdm_context->local_context.capability.sender_data_transfer_size))) {
+     618                 :            : 
+     619                 :            :         #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
+     620                 :            :         /* libspdm_send_request is not called with the original request in this flow.
+     621                 :            :          * This leads to the last_spdm_request field not having the original request value.
+     622                 :            :          * The caller assumes the request has been copied to last_spdm_request,
+     623                 :            :          * so that it can compare last_spdm_request's fields with response fields
+     624                 :            :          * Therefore the request must be copied to last_spdm_request here. */
+     625                 :            : 
+     626         [ +  - ]:         11 :         if (((const spdm_message_header_t*) request)->request_response_code != SPDM_RESPOND_IF_READY
+     627         [ +  - ]:         11 :             && ((const spdm_message_header_t*) request)->request_response_code != SPDM_CHUNK_GET
+     628         [ +  - ]:         11 :             && ((const spdm_message_header_t*) request)->request_response_code != SPDM_CHUNK_SEND) {
+     629                 :         11 :             libspdm_copy_mem(
+     630                 :            :                 spdm_context->last_spdm_request,
+     631                 :         11 :                 libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context),
+     632                 :            :                 request, request_size);
+     633                 :         11 :             spdm_context->last_spdm_request_size = request_size;
+     634                 :            :         }
+     635                 :            : 
+     636                 :         11 :         status = libspdm_handle_large_request(
+     637                 :            :             spdm_context, session_id, request_size, request);
+     638                 :            :         #else  /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP*/
+     639                 :            :         status = LIBSPDM_STATUS_BUFFER_TOO_SMALL;
+     640                 :            :         #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP*/
+     641                 :            :     } else {
+     642                 :       2568 :         status = libspdm_send_request(spdm_context, session_id, false, request_size, request);
+     643                 :            :     }
+     644                 :            : 
+     645                 :            :     #if LIBSPDM_ENABLE_MSG_LOG
+     646                 :            :     /* If there is an error in sending the request then revert the request in the message log. */
+     647         [ +  + ]:       2579 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     648                 :         30 :         spdm_context->msg_log.buffer_size = msg_log_size;
+     649                 :            :     }
+     650                 :            :     #endif /* LIBSPDM_ENABLE_MSG_LOG */
+     651                 :            : 
+     652                 :       2579 :     return status;
+     653                 :            : }
+     654                 :            : 
+     655                 :       2543 : libspdm_return_t libspdm_receive_spdm_response(libspdm_context_t *spdm_context,
+     656                 :            :                                                const uint32_t *session_id,
+     657                 :            :                                                size_t *response_size,
+     658                 :            :                                                void **response)
+     659                 :            : {
+     660                 :            :     libspdm_return_t status;
+     661                 :            :     libspdm_session_info_t *session_info;
+     662                 :            :     libspdm_session_state_t session_state;
+     663                 :            : 
+     664                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
+     665                 :            :     spdm_message_header_t *spdm_response;
+     666                 :            :     size_t response_capacity;
+     667                 :            :     libspdm_chunk_info_t *send_info;
+     668                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP */
+     669                 :            : 
+     670   [ +  +  +  + ]:       2810 :     if ((session_id != NULL) &&
+     671                 :        267 :         libspdm_is_capabilities_flag_supported(
+     672                 :            :             spdm_context, true,
+     673                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP,
+     674                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)) {
+     675                 :         37 :         session_info = libspdm_get_session_info_via_session_id(
+     676                 :            :             spdm_context, *session_id);
+     677         [ -  + ]:         37 :         LIBSPDM_ASSERT(session_info != NULL);
+     678         [ -  + ]:         37 :         if (session_info == NULL) {
+     679                 :          0 :             return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+     680                 :            :         }
+     681                 :         37 :         session_state = libspdm_secured_message_get_session_state(
+     682                 :            :             session_info->secured_message_context);
+     683         [ +  - ]:         37 :         if ((session_state == LIBSPDM_SESSION_STATE_HANDSHAKING) &&
+     684         [ +  - ]:         37 :             !session_info->use_psk) {
+     685                 :         37 :             session_id = NULL;
+     686                 :            :         }
+     687                 :            :     }
+     688                 :            : 
+     689                 :            :     #if !(LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP)
+     690                 :            :     status = libspdm_receive_response(spdm_context, session_id, false, response_size, response);
+     691                 :            :     #else /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP */
+     692                 :       2543 :     send_info = &spdm_context->chunk_context.send;
+     693         [ +  + ]:       2543 :     if (send_info->chunk_in_use) {
+     694                 :          3 :         libspdm_copy_mem(*response, *response_size,
+     695                 :          3 :                          send_info->large_message, send_info->large_message_size);
+     696                 :          3 :         *response_size = send_info->large_message_size;
+     697                 :          3 :         response_capacity = send_info->large_message_capacity;
+     698                 :            : 
+     699                 :            :         /* This response may either be an actual response or ERROR_LARGE_RESPONSE,
+     700                 :            :          * the latter which should be handled in the large response handler. */
+     701                 :            : 
+     702                 :          3 :         send_info->chunk_in_use = false;
+     703                 :          3 :         send_info->chunk_handle++; /* Implicit wrap-around*/
+     704                 :          3 :         send_info->chunk_seq_no = 0;
+     705                 :          3 :         send_info->chunk_bytes_transferred = 0;
+     706                 :          3 :         send_info->large_message = NULL;
+     707                 :          3 :         send_info->large_message_size = 0;
+     708                 :          3 :         send_info->large_message_capacity = 0;
+     709                 :          3 :         status = LIBSPDM_STATUS_SUCCESS;
+     710                 :            :     } else {
+     711                 :       2540 :         response_capacity = *response_size;
+     712                 :       2540 :         status = libspdm_receive_response(spdm_context, session_id, false,
+     713                 :            :                                           response_size, response);
+     714         [ +  + ]:       2540 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     715                 :          8 :             goto receive_done;
+     716                 :            :         }
+     717                 :            :     }
+     718                 :            : 
+     719                 :       2535 :     spdm_response = (spdm_message_header_t*) (*response);
+     720                 :            : 
+     721         [ -  + ]:       2535 :     if (*response_size < sizeof(spdm_message_header_t)) {
+     722                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     723                 :          0 :         goto receive_done;
+     724                 :            :     }
+     725                 :            : 
+     726         [ +  + ]:       2535 :     if (spdm_response->request_response_code == SPDM_ERROR
+     727         [ +  + ]:        438 :         && spdm_response->param1 == SPDM_ERROR_CODE_LARGE_RESPONSE) {
+     728                 :          5 :         status = libspdm_handle_error_large_response(
+     729                 :            :             spdm_context, session_id,
+     730                 :            :             response_size, (void*) spdm_response, response_capacity);
+     731                 :            : 
+     732         [ -  + ]:          5 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     733                 :          0 :             goto receive_done;
+     734                 :            :         }
+     735                 :            : 
+     736         [ -  + ]:          5 :         if (*response_size < sizeof(spdm_message_header_t)) {
+     737                 :          0 :             status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     738                 :          0 :             goto receive_done;
+     739                 :            :         }
+     740                 :            : 
+     741                 :            :         /* Per the spec, SPDM_VERSION and SPDM_CAPABILITIES shall not be chunked
+     742                 :            :          * and should be an unexpected error. */
+     743         [ +  - ]:          5 :         if (spdm_response->request_response_code == SPDM_VERSION ||
+     744         [ +  - ]:          5 :             spdm_response->request_response_code == SPDM_CAPABILITIES
+     745                 :            :             ) {
+     746                 :          0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     747                 :          0 :             goto receive_done;
+     748                 :            :         }
+     749                 :            :     }
+     750                 :            : 
+     751                 :       2535 : receive_done:
+     752                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP */
+     753                 :            : 
+     754                 :       2543 :     return status;
+     755                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_set_certificate.c.func-sort-c.html b/coverage_log/library/spdm_requester_lib/libspdm_req_set_certificate.c.func-sort-c.html new file mode 100644 index 00000000000..ccf790eab33 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_set_certificate.c.func-sort-c.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_set_certificate.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_set_certificate.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:9011876.3 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:548662.8 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_set_certificate_ex3
libspdm_set_certificate5
libspdm_try_set_certificate8
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_set_certificate.c.func.html b/coverage_log/library/spdm_requester_lib/libspdm_req_set_certificate.c.func.html new file mode 100644 index 00000000000..60337d20f25 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_set_certificate.c.func.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_set_certificate.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_set_certificate.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:9011876.3 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:548662.8 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_set_certificate5
libspdm_set_certificate_ex3
libspdm_try_set_certificate8
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_set_certificate.c.gcov.html b/coverage_log/library/spdm_requester_lib/libspdm_req_set_certificate.c.gcov.html new file mode 100644 index 00000000000..5fdf8bb5f36 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_set_certificate.c.gcov.html @@ -0,0 +1,361 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_set_certificate.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_set_certificate.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:9011876.3 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:548662.8 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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_SET_CERT_CAP
+      10                 :            : /**
+      11                 :            :  * This function sends SET_CERTIFICATE
+      12                 :            :  * to set certificate from the device.
+      13                 :            :  *
+      14                 :            :  * @param  context                      A pointer to the SPDM context.
+      15                 :            :  * @param  session_id                   Indicates if it is a secured message protected via SPDM session.
+      16                 :            :  *                                      If session_id is NULL, it is a normal message.
+      17                 :            :  *                                      If session_id is NOT NULL, it is a secured message.
+      18                 :            :  * @param  slot_id                      The number of slot for the certificate chain.
+      19                 :            :  * @param  cert_chain                   The pointer for the certificate chain to set.
+      20                 :            :  *                                      The cert chain is a full SPDM certificate chain, including Length and Root Cert Hash.
+      21                 :            :  * @param  cert_chain_size              The size of the certificate chain to set.
+      22                 :            :  * @param  request_attribute            Set certificate request attributes. This field is only used for SPDM 1.3 and above.
+      23                 :            :  *                                      And the bit[0~3] of request_attribute must be 0.
+      24                 :            :  * @param  key_pair_id                  The value of this field shall be the unique key pair number identifying the desired
+      25                 :            :  *                                      asymmetric key pair to associate with SlotID .
+      26                 :            :  *
+      27                 :            :  * @retval RETURN_SUCCESS               The measurement is got successfully.
+      28                 :            :  * @retval RETURN_DEVICE_ERROR          A device error occurs when communicates with the device.
+      29                 :            :  * @retval RETURN_SECURITY_VIOLATION    Any verification fails.
+      30                 :            :  **/
+      31                 :          8 : static libspdm_return_t libspdm_try_set_certificate(libspdm_context_t *spdm_context,
+      32                 :            :                                                     const uint32_t *session_id, uint8_t slot_id,
+      33                 :            :                                                     void *cert_chain, size_t cert_chain_size,
+      34                 :            :                                                     uint8_t request_attribute,
+      35                 :            :                                                     uint8_t key_pair_id)
+      36                 :            : {
+      37                 :            :     libspdm_return_t status;
+      38                 :            :     spdm_set_certificate_request_t *spdm_request;
+      39                 :            :     size_t spdm_request_size;
+      40                 :            :     spdm_set_certificate_response_t *spdm_response;
+      41                 :            :     size_t spdm_response_size;
+      42                 :            :     size_t transport_header_size;
+      43                 :            :     uint8_t *message;
+      44                 :            :     size_t message_size;
+      45                 :            :     libspdm_session_info_t *session_info;
+      46                 :            :     libspdm_session_state_t session_state;
+      47                 :            : 
+      48         [ -  + ]:          8 :     LIBSPDM_ASSERT(slot_id < SPDM_MAX_SLOT_COUNT);
+      49                 :            : 
+      50         [ -  + ]:          8 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_12) {
+      51                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+      52                 :            :     }
+      53         [ +  + ]:          8 :     if (libspdm_get_connection_version (spdm_context) < SPDM_MESSAGE_VERSION_13) {
+      54   [ +  +  -  + ]:          5 :         if ((cert_chain == NULL) || (cert_chain_size == 0)) {
+      55                 :          1 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
+      56                 :            :         }
+      57                 :            :     }
+      58         [ +  + ]:          7 :     if (libspdm_get_connection_version (spdm_context) >= SPDM_MESSAGE_VERSION_13) {
+      59                 :          3 :         const uint8_t set_cert_model =
+      60                 :          3 :             (request_attribute & SPDM_SET_CERTIFICATE_REQUEST_ATTRIBUTES_CERT_MODEL_MASK) >>
+      61                 :            :             SPDM_SET_CERTIFICATE_REQUEST_ATTRIBUTES_CERT_MODEL_OFFSET;
+      62                 :            : 
+      63                 :            :         /* Bit[0~3] of request_attribute must be 0 since this value is provided by the slot_id
+      64                 :            :          * parameter. */
+      65         [ -  + ]:          3 :         if ((request_attribute & SPDM_SET_CERTIFICATE_REQUEST_SLOT_ID_MASK) != 0) {
+      66                 :          0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
+      67                 :            :         }
+      68                 :            : 
+      69                 :            :         /* SET_CERT_CAP for a 1.2 Responder is not checked because it was not defined
+      70                 :            :          * in SPDM 1.2.0. */
+      71         [ -  + ]:          3 :         if (!libspdm_is_capabilities_flag_supported(
+      72                 :            :                 spdm_context, true, 0,
+      73                 :            :                 SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_CERT_CAP)) {
+      74                 :          0 :             return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+      75                 :            :         }
+      76         [ +  + ]:          3 :         if (spdm_context->connection_info.multi_key_conn_rsp) {
+      77         [ -  + ]:          2 :             if (key_pair_id == 0) {
+      78                 :          0 :                 return LIBSPDM_STATUS_INVALID_PARAMETER;
+      79                 :            :             }
+      80         [ +  - ]:          2 :             if ((request_attribute & SPDM_SET_CERTIFICATE_REQUEST_ATTRIBUTES_ERASE) == 0) {
+      81   [ +  +  -  + ]:          2 :                 if ((set_cert_model == SPDM_CERTIFICATE_INFO_CERT_MODEL_NONE) ||
+      82                 :            :                     (set_cert_model > SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT)) {
+      83                 :          1 :                     return LIBSPDM_STATUS_INVALID_PARAMETER;
+      84                 :            :                 }
+      85                 :            :             }
+      86                 :            :         } else {
+      87   [ +  -  -  + ]:          1 :             if ((key_pair_id != 0) || (set_cert_model != 0)) {
+      88                 :          0 :                 return LIBSPDM_STATUS_INVALID_PARAMETER;
+      89                 :            :             }
+      90                 :            :         }
+      91                 :            :     }
+      92                 :            : 
+      93         [ -  + ]:          6 :     if (spdm_context->connection_info.connection_state < LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
+      94                 :          0 :         return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+      95                 :            :     }
+      96                 :            : 
+      97         [ +  + ]:          6 :     if (session_id != NULL) {
+      98                 :          1 :         session_info = libspdm_get_session_info_via_session_id(
+      99                 :            :             spdm_context, *session_id);
+     100         [ -  + ]:          1 :         if (session_info == NULL) {
+     101                 :          0 :             LIBSPDM_ASSERT(false);
+     102                 :          0 :             return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+     103                 :            :         }
+     104                 :          1 :         session_state = libspdm_secured_message_get_session_state(
+     105                 :            :             session_info->secured_message_context);
+     106         [ -  + ]:          1 :         if (session_state != LIBSPDM_SESSION_STATE_ESTABLISHED) {
+     107                 :          0 :             return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+     108                 :            :         }
+     109                 :            :     }
+     110                 :            : 
+     111                 :          6 :     transport_header_size = spdm_context->local_context.capability.transport_header_size;
+     112                 :          6 :     status = libspdm_acquire_sender_buffer (spdm_context, &message_size, (void **)&message);
+     113         [ -  + ]:          6 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     114                 :          0 :         return status;
+     115                 :            :     }
+     116         [ -  + ]:          6 :     LIBSPDM_ASSERT (message_size >= transport_header_size +
+     117                 :            :                     spdm_context->local_context.capability.transport_tail_size);
+     118                 :          6 :     spdm_request = (void *)(message + transport_header_size);
+     119                 :          6 :     spdm_request_size = message_size - transport_header_size -
+     120                 :          6 :                         spdm_context->local_context.capability.transport_tail_size;
+     121                 :            : 
+     122         [ -  + ]:          6 :     LIBSPDM_ASSERT(spdm_request_size >= sizeof(spdm_set_certificate_request_t));
+     123                 :          6 :     spdm_request->header.spdm_version = libspdm_get_connection_version (spdm_context);
+     124                 :          6 :     spdm_request->header.request_response_code = SPDM_SET_CERTIFICATE;
+     125                 :          6 :     spdm_request->header.param1 = slot_id & SPDM_SET_CERTIFICATE_REQUEST_SLOT_ID_MASK;
+     126                 :          6 :     spdm_request->header.param2 = 0;
+     127                 :            : 
+     128         [ +  + ]:          6 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
+     129         [ +  + ]:          2 :         if ((request_attribute & SPDM_SET_CERTIFICATE_REQUEST_ATTRIBUTES_ERASE) != 0) {
+     130                 :            :             /*the CertChain field shall be absent*/
+     131                 :          1 :             cert_chain_size = 0;
+     132                 :            :             /*the value of SetCertModel shall be zero*/
+     133                 :          1 :             spdm_request->header.param1 &= ~SPDM_SET_CERTIFICATE_REQUEST_ATTRIBUTES_CERT_MODEL_MASK;
+     134                 :            :             /*set Erase bit */
+     135                 :          1 :             spdm_request->header.param1 |= SPDM_SET_CERTIFICATE_REQUEST_ATTRIBUTES_ERASE;
+     136                 :            :         } else {
+     137                 :          1 :             spdm_request->header.param1 |= request_attribute;
+     138                 :            :         }
+     139                 :            : 
+     140         [ +  + ]:          2 :         if (spdm_context->connection_info.multi_key_conn_rsp) {
+     141                 :          1 :             spdm_request->header.param2 = key_pair_id;
+     142                 :            :         }
+     143                 :            :     }
+     144                 :            : 
+     145   [ +  +  +  + ]:          6 :     if ((libspdm_get_connection_version (spdm_context) < SPDM_MESSAGE_VERSION_13) ||
+     146                 :            :         (cert_chain_size != 0)) {
+     147         [ -  + ]:          5 :         if (cert_chain == NULL) {
+     148                 :          0 :             libspdm_release_sender_buffer (spdm_context);
+     149                 :          0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
+     150                 :            :         }
+     151                 :            : 
+     152         [ -  + ]:          5 :         LIBSPDM_ASSERT(spdm_request_size >=
+     153                 :            :                        sizeof(spdm_set_certificate_request_t) + cert_chain_size);
+     154                 :          5 :         libspdm_copy_mem(spdm_request + 1,
+     155                 :            :                          spdm_request_size - sizeof(spdm_set_certificate_request_t),
+     156                 :            :                          (uint8_t *)cert_chain, cert_chain_size);
+     157                 :            :     }
+     158                 :            : 
+     159                 :          6 :     spdm_request_size = sizeof(spdm_set_certificate_request_t) + cert_chain_size;
+     160                 :            : 
+     161                 :          6 :     status = libspdm_send_spdm_request(spdm_context, session_id, spdm_request_size, spdm_request);
+     162         [ +  + ]:          6 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     163                 :          1 :         libspdm_release_sender_buffer (spdm_context);
+     164                 :          1 :         return status;
+     165                 :            :     }
+     166                 :          5 :     libspdm_release_sender_buffer (spdm_context);
+     167                 :          5 :     spdm_request = (void *)spdm_context->last_spdm_request;
+     168                 :            : 
+     169                 :            :     /* receive */
+     170                 :          5 :     status = libspdm_acquire_receiver_buffer (spdm_context, &message_size, (void **)&message);
+     171         [ -  + ]:          5 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     172                 :          0 :         return status;
+     173                 :            :     }
+     174         [ -  + ]:          5 :     LIBSPDM_ASSERT (message_size >= transport_header_size);
+     175                 :          5 :     spdm_response = (void *)(message);
+     176                 :          5 :     spdm_response_size = message_size;
+     177                 :            : 
+     178                 :          5 :     status = libspdm_receive_spdm_response(spdm_context, session_id,
+     179                 :            :                                            &spdm_response_size, (void **)&spdm_response);
+     180                 :            : 
+     181         [ -  + ]:          5 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     182                 :          0 :         goto receive_done;
+     183                 :            :     }
+     184         [ -  + ]:          5 :     if (spdm_response_size < sizeof(spdm_message_header_t)) {
+     185                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     186                 :          0 :         goto receive_done;
+     187                 :            :     }
+     188         [ -  + ]:          5 :     if (spdm_response->header.spdm_version != spdm_request->header.spdm_version) {
+     189                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     190                 :          0 :         goto receive_done;
+     191                 :            :     }
+     192         [ +  + ]:          5 :     if (spdm_response->header.request_response_code == SPDM_ERROR) {
+     193                 :          1 :         status = libspdm_handle_error_response_main(
+     194                 :            :             spdm_context, NULL,
+     195                 :            :             &spdm_response_size,
+     196                 :            :             (void **)&spdm_response, SPDM_SET_CERTIFICATE, SPDM_SET_CERTIFICATE_RSP);
+     197         [ +  - ]:          1 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     198                 :          1 :             goto receive_done;
+     199                 :            :         }
+     200         [ -  + ]:          4 :     } else if (spdm_response->header.request_response_code != SPDM_SET_CERTIFICATE_RSP) {
+     201                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     202                 :          0 :         goto receive_done;
+     203                 :            :     }
+     204         [ -  + ]:          4 :     if ((spdm_response->header.param1 & SPDM_CERTIFICATE_RESPONSE_SLOT_ID_MASK) != slot_id) {
+     205                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     206                 :          0 :         goto receive_done;
+     207                 :            :     }
+     208                 :            : 
+     209                 :            :     /* -=[Log Message Phase]=- */
+     210                 :            :     #if LIBSPDM_ENABLE_MSG_LOG
+     211                 :          4 :     libspdm_append_msg_log(spdm_context, spdm_response, spdm_response_size);
+     212                 :            :     #endif /* LIBSPDM_ENABLE_MSG_LOG */
+     213                 :            : 
+     214                 :          4 :     status = LIBSPDM_STATUS_SUCCESS;
+     215                 :            : 
+     216                 :          5 : receive_done:
+     217                 :          5 :     libspdm_release_receiver_buffer (spdm_context);
+     218                 :          5 :     return status;
+     219                 :            : }
+     220                 :            : 
+     221                 :          5 : libspdm_return_t libspdm_set_certificate(void *spdm_context,
+     222                 :            :                                          const uint32_t *session_id, uint8_t slot_id,
+     223                 :            :                                          void *cert_chain, size_t cert_chain_size)
+     224                 :            : {
+     225                 :            :     libspdm_context_t *context;
+     226                 :            :     size_t retry;
+     227                 :            :     uint64_t retry_delay_time;
+     228                 :            :     libspdm_return_t status;
+     229                 :            : 
+     230                 :          5 :     context = spdm_context;
+     231                 :          5 :     context->crypto_request = true;
+     232                 :          5 :     retry = context->retry_times;
+     233                 :          5 :     retry_delay_time = context->retry_delay_time;
+     234                 :            :     do {
+     235                 :          5 :         status = libspdm_try_set_certificate(context, session_id, slot_id,
+     236                 :            :                                              cert_chain, cert_chain_size, 0, 0);
+     237         [ +  - ]:          5 :         if (status != LIBSPDM_STATUS_BUSY_PEER) {
+     238                 :          5 :             return status;
+     239                 :            :         }
+     240                 :            : 
+     241                 :          0 :         libspdm_sleep(retry_delay_time);
+     242         [ #  # ]:          0 :     } while (retry-- != 0);
+     243                 :            : 
+     244                 :          0 :     return status;
+     245                 :            : }
+     246                 :            : 
+     247                 :          3 : libspdm_return_t libspdm_set_certificate_ex(void *spdm_context,
+     248                 :            :                                             const uint32_t *session_id, uint8_t slot_id,
+     249                 :            :                                             void *cert_chain, size_t cert_chain_size,
+     250                 :            :                                             uint8_t request_attribute,
+     251                 :            :                                             uint8_t key_pair_id)
+     252                 :            : {
+     253                 :            :     libspdm_context_t *context;
+     254                 :            :     size_t retry;
+     255                 :            :     uint64_t retry_delay_time;
+     256                 :            :     libspdm_return_t status;
+     257                 :            : 
+     258                 :          3 :     context = spdm_context;
+     259                 :          3 :     context->crypto_request = true;
+     260                 :          3 :     retry = context->retry_times;
+     261                 :          3 :     retry_delay_time = context->retry_delay_time;
+     262                 :            :     do {
+     263                 :          3 :         status = libspdm_try_set_certificate(context, session_id, slot_id,
+     264                 :            :                                              cert_chain, cert_chain_size,
+     265                 :            :                                              request_attribute, key_pair_id);
+     266         [ +  - ]:          3 :         if (status != LIBSPDM_STATUS_BUSY_PEER) {
+     267                 :          3 :             return status;
+     268                 :            :         }
+     269                 :            : 
+     270                 :          0 :         libspdm_sleep(retry_delay_time);
+     271         [ #  # ]:          0 :     } while (retry-- != 0);
+     272                 :            : 
+     273                 :          0 :     return status;
+     274                 :            : }
+     275                 :            : 
+     276                 :            : #endif /*LIBSPDM_ENABLE_CAPABILITY_SET_CERT_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_set_key_pair_info.c.func-sort-c.html b/coverage_log/library/spdm_requester_lib/libspdm_req_set_key_pair_info.c.func-sort-c.html new file mode 100644 index 00000000000..e8d4e22c95f --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_set_key_pair_info.c.func-sort-c.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_set_key_pair_info.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_set_key_pair_info.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:619564.2 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:275648.2 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_set_key_pair_info5
libspdm_try_set_key_pair_info5
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_set_key_pair_info.c.func.html b/coverage_log/library/spdm_requester_lib/libspdm_req_set_key_pair_info.c.func.html new file mode 100644 index 00000000000..a2cf668c768 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_set_key_pair_info.c.func.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_set_key_pair_info.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_set_key_pair_info.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:619564.2 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:275648.2 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_set_key_pair_info5
libspdm_try_set_key_pair_info5
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_set_key_pair_info.c.gcov.html b/coverage_log/library/spdm_requester_lib/libspdm_req_set_key_pair_info.c.gcov.html new file mode 100644 index 00000000000..4a4f8e5130e --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_set_key_pair_info.c.gcov.html @@ -0,0 +1,299 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_set_key_pair_info.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_set_key_pair_info.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:619564.2 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:275648.2 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2024 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_SET_KEY_PAIR_INFO_CAP
+      10                 :            : 
+      11                 :            : /**
+      12                 :            :  * This function sends SET_KEY_PAIR_INFO and receives SET_KEY_PAIR_INFO_ACK
+      13                 :            :  *
+      14                 :            :  * @param  context             A pointer to the SPDM context.
+      15                 :            :  *
+      16                 :            :  **/
+      17                 :          5 : static libspdm_return_t libspdm_try_set_key_pair_info(libspdm_context_t *spdm_context,
+      18                 :            :                                                       const uint32_t *session_id,
+      19                 :            :                                                       uint8_t key_pair_id,
+      20                 :            :                                                       uint8_t operation,
+      21                 :            :                                                       uint16_t desired_key_usage,
+      22                 :            :                                                       uint32_t desired_asym_algo,
+      23                 :            :                                                       uint8_t desired_assoc_cert_slot_mask
+      24                 :            :                                                       )
+      25                 :            : {
+      26                 :            :     libspdm_return_t status;
+      27                 :            :     spdm_set_key_pair_info_request_t *spdm_request;
+      28                 :            :     size_t spdm_request_size;
+      29                 :            :     spdm_set_key_pair_info_ack_response_t *spdm_response;
+      30                 :            :     size_t spdm_response_size;
+      31                 :            :     uint8_t *message;
+      32                 :            :     size_t message_size;
+      33                 :            :     size_t transport_header_size;
+      34                 :            :     libspdm_session_info_t *session_info;
+      35                 :            :     libspdm_session_state_t session_state;
+      36                 :            :     uint8_t *ptr;
+      37                 :            : 
+      38                 :            :     /* -=[Check Parameters Phase]=- */
+      39         [ -  + ]:          5 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_13) {
+      40                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+      41                 :            :     }
+      42                 :            : 
+      43         [ -  + ]:          5 :     if (key_pair_id == 0) {
+      44                 :          0 :         return LIBSPDM_STATUS_INVALID_PARAMETER;
+      45                 :            :     }
+      46                 :            : 
+      47         [ -  + ]:          5 :     if (operation > SPDM_SET_KEY_PAIR_INFO_GENERATE_OPERATION) {
+      48                 :          0 :         return LIBSPDM_STATUS_INVALID_PARAMETER;
+      49                 :            :     }
+      50         [ +  - ]:          5 :     if (operation == SPDM_SET_KEY_PAIR_INFO_ERASE_OPERATION) {
+      51   [ +  -  +  -  :          5 :         if ((desired_key_usage != 0) || (desired_asym_algo != 0) ||
+                   +  + ]
+      52                 :            :             (desired_assoc_cert_slot_mask != 0)) {
+      53                 :          1 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
+      54                 :            :         }
+      55                 :            :     }
+      56                 :            : 
+      57                 :            :     /* -=[Verify State Phase]=- */
+      58         [ -  + ]:          4 :     if (!libspdm_is_capabilities_flag_supported(
+      59                 :            :             spdm_context, true, 0,
+      60                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_KEY_PAIR_INFO_CAP)) {
+      61                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+      62                 :            :     }
+      63         [ -  + ]:          4 :     if (spdm_context->connection_info.connection_state < LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
+      64                 :          0 :         return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+      65                 :            :     }
+      66                 :            : 
+      67                 :          4 :     session_info = NULL;
+      68         [ -  + ]:          4 :     if (session_id != NULL) {
+      69                 :          0 :         session_info = libspdm_get_session_info_via_session_id(spdm_context, *session_id);
+      70         [ #  # ]:          0 :         if (session_info == NULL) {
+      71                 :          0 :             return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+      72                 :            :         }
+      73                 :          0 :         session_state = libspdm_secured_message_get_session_state(
+      74                 :            :             session_info->secured_message_context);
+      75         [ #  # ]:          0 :         if (session_state != LIBSPDM_SESSION_STATE_ESTABLISHED) {
+      76                 :          0 :             return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+      77                 :            :         }
+      78                 :            :     }
+      79                 :            : 
+      80                 :            :     /* -=[Construct Request Phase]=- */
+      81                 :          4 :     transport_header_size = spdm_context->local_context.capability.transport_header_size;
+      82                 :          4 :     status = libspdm_acquire_sender_buffer (spdm_context, &message_size, (void **)&message);
+      83         [ -  + ]:          4 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+      84                 :          0 :         return status;
+      85                 :            :     }
+      86         [ -  + ]:          4 :     LIBSPDM_ASSERT (message_size >= transport_header_size +
+      87                 :            :                     spdm_context->local_context.capability.transport_tail_size);
+      88                 :          4 :     spdm_request = (void *)(message + transport_header_size);
+      89                 :          4 :     spdm_request_size = message_size - transport_header_size -
+      90                 :          4 :                         spdm_context->local_context.capability.transport_tail_size;
+      91                 :            : 
+      92         [ -  + ]:          4 :     LIBSPDM_ASSERT(spdm_request_size >= sizeof(spdm_set_key_pair_info_request_t));
+      93                 :          4 :     spdm_request->header.spdm_version = libspdm_get_connection_version (spdm_context);
+      94                 :          4 :     spdm_request->header.request_response_code = SPDM_SET_KEY_PAIR_INFO;
+      95                 :          4 :     spdm_request->header.param1 = operation;
+      96                 :          4 :     spdm_request->header.param2 = 0;
+      97                 :          4 :     spdm_request->key_pair_id = key_pair_id;
+      98                 :            : 
+      99         [ -  + ]:          4 :     if (operation != SPDM_SET_KEY_PAIR_INFO_ERASE_OPERATION) {
+     100         [ #  # ]:          0 :         LIBSPDM_ASSERT(spdm_request_size >= sizeof(spdm_set_key_pair_info_request_t) +
+     101                 :            :                        sizeof(uint8_t) + sizeof(uint16_t) + sizeof(uint32_t) + sizeof(uint8_t));
+     102                 :          0 :         ptr = (uint8_t*)(spdm_request + 1);
+     103                 :          0 :         *ptr = 0;
+     104                 :          0 :         ptr += sizeof(uint8_t);
+     105                 :            : 
+     106                 :          0 :         libspdm_write_uint16 (ptr, desired_key_usage);
+     107                 :          0 :         ptr += sizeof(uint16_t);
+     108                 :            : 
+     109                 :          0 :         libspdm_write_uint32 (ptr, desired_asym_algo);
+     110                 :          0 :         ptr += sizeof(uint32_t);
+     111                 :            : 
+     112                 :          0 :         *ptr = desired_assoc_cert_slot_mask;
+     113                 :          0 :         ptr += sizeof(uint8_t);
+     114                 :          0 :         spdm_request_size = sizeof(spdm_set_key_pair_info_request_t);
+     115                 :          0 :         spdm_request_size += ((size_t)ptr - (size_t)spdm_request);
+     116                 :            :     } else {
+     117                 :          4 :         spdm_request_size = sizeof(spdm_set_key_pair_info_request_t);
+     118                 :            :     }
+     119                 :            : 
+     120                 :            :     /* -=[Send Request Phase]=- */
+     121                 :          4 :     status = libspdm_send_spdm_request(spdm_context, session_id, spdm_request_size, spdm_request);
+     122         [ +  + ]:          4 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     123                 :          1 :         libspdm_release_sender_buffer (spdm_context);
+     124                 :          1 :         return status;
+     125                 :            :     }
+     126                 :          3 :     libspdm_release_sender_buffer (spdm_context);
+     127                 :          3 :     spdm_request = (void *)spdm_context->last_spdm_request;
+     128                 :            : 
+     129                 :            :     /* -=[Receive Response Phase]=- */
+     130                 :          3 :     status = libspdm_acquire_receiver_buffer (spdm_context, &message_size, (void **)&message);
+     131         [ -  + ]:          3 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     132                 :          0 :         return status;
+     133                 :            :     }
+     134         [ -  + ]:          3 :     LIBSPDM_ASSERT (message_size >= transport_header_size);
+     135                 :          3 :     spdm_response = (void *)(message);
+     136                 :          3 :     spdm_response_size = message_size;
+     137                 :            : 
+     138                 :          3 :     status = libspdm_receive_spdm_response(
+     139                 :            :         spdm_context, session_id, &spdm_response_size, (void **)&spdm_response);
+     140         [ -  + ]:          3 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     141                 :          0 :         goto receive_done;
+     142                 :            :     }
+     143                 :            : 
+     144                 :            :     /* -=[Validate Response Phase]=- */
+     145         [ -  + ]:          3 :     if (spdm_response_size < sizeof(spdm_message_header_t)) {
+     146                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     147                 :          0 :         goto receive_done;
+     148                 :            :     }
+     149         [ +  + ]:          3 :     if (spdm_response->header.spdm_version != spdm_request->header.spdm_version) {
+     150                 :          1 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     151                 :          1 :         goto receive_done;
+     152                 :            :     }
+     153         [ -  + ]:          2 :     if (spdm_response->header.request_response_code == SPDM_ERROR) {
+     154                 :          0 :         status = libspdm_handle_error_response_main(
+     155                 :            :             spdm_context, session_id,
+     156                 :            :             &spdm_response_size,
+     157                 :            :             (void **)&spdm_response, SPDM_SET_KEY_PAIR_INFO, SPDM_SET_KEY_PAIR_INFO_ACK);
+     158         [ #  # ]:          0 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     159                 :          0 :             goto receive_done;
+     160                 :            :         }
+     161         [ +  + ]:          2 :     } else if (spdm_response->header.request_response_code != SPDM_SET_KEY_PAIR_INFO_ACK) {
+     162                 :          1 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     163                 :          1 :         goto receive_done;
+     164                 :            :     }
+     165                 :            : 
+     166                 :          1 :     spdm_response_size = sizeof(spdm_set_key_pair_info_ack_response_t);
+     167                 :            : 
+     168                 :          1 :     status = LIBSPDM_STATUS_SUCCESS;
+     169                 :            : 
+     170                 :            :     /* -=[Log Message Phase]=- */
+     171                 :            :     #if LIBSPDM_ENABLE_MSG_LOG
+     172                 :          1 :     libspdm_append_msg_log(spdm_context, spdm_response, spdm_response_size);
+     173                 :            :     #endif /* LIBSPDM_ENABLE_MSG_LOG */
+     174                 :            : 
+     175                 :          3 : receive_done:
+     176                 :          3 :     libspdm_release_receiver_buffer (spdm_context);
+     177                 :          3 :     return status;
+     178                 :            : }
+     179                 :            : 
+     180                 :          5 : libspdm_return_t libspdm_set_key_pair_info(void *spdm_context, const uint32_t *session_id,
+     181                 :            :                                            uint8_t key_pair_id,
+     182                 :            :                                            uint8_t operation,
+     183                 :            :                                            uint16_t desired_key_usage,
+     184                 :            :                                            uint32_t desired_asym_algo,
+     185                 :            :                                            uint8_t desired_assoc_cert_slot_mask
+     186                 :            :                                            )
+     187                 :            : {
+     188                 :            :     libspdm_context_t *context;
+     189                 :            :     size_t retry;
+     190                 :            :     uint64_t retry_delay_time;
+     191                 :            :     libspdm_return_t status;
+     192                 :            : 
+     193                 :          5 :     context = spdm_context;
+     194                 :          5 :     context->crypto_request = true;
+     195                 :          5 :     retry = context->retry_times;
+     196                 :          5 :     retry_delay_time = context->retry_delay_time;
+     197                 :            :     do {
+     198                 :          5 :         status = libspdm_try_set_key_pair_info(context, session_id, key_pair_id,
+     199                 :            :                                                operation,
+     200                 :            :                                                desired_key_usage,
+     201                 :            :                                                desired_asym_algo,
+     202                 :            :                                                desired_assoc_cert_slot_mask);
+     203         [ +  - ]:          5 :         if (status != LIBSPDM_STATUS_BUSY_PEER) {
+     204                 :          5 :             return status;
+     205                 :            :         }
+     206                 :            : 
+     207                 :          0 :         libspdm_sleep(retry_delay_time);
+     208         [ #  # ]:          0 :     } while (retry-- != 0);
+     209                 :            : 
+     210                 :          0 :     return status;
+     211                 :            : }
+     212                 :            : 
+     213                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_SET_KEY_PAIR_INFO_CAP */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_subscribe_event_types.c.func-sort-c.html b/coverage_log/library/spdm_requester_lib/libspdm_req_subscribe_event_types.c.func-sort-c.html new file mode 100644 index 00000000000..2332a587788 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_subscribe_event_types.c.func-sort-c.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_subscribe_event_types.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_subscribe_event_types.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:588270.7 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:305257.7 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_subscribe_event_types7
try_libspdm_subscribe_event_types7
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_subscribe_event_types.c.func.html b/coverage_log/library/spdm_requester_lib/libspdm_req_subscribe_event_types.c.func.html new file mode 100644 index 00000000000..4f1d3c8fbf2 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_subscribe_event_types.c.func.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_subscribe_event_types.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_subscribe_event_types.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:588270.7 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:305257.7 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_subscribe_event_types7
try_libspdm_subscribe_event_types7
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_subscribe_event_types.c.gcov.html b/coverage_log/library/spdm_requester_lib/libspdm_req_subscribe_event_types.c.gcov.html new file mode 100644 index 00000000000..37dbdb99687 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_subscribe_event_types.c.gcov.html @@ -0,0 +1,267 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_subscribe_event_types.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_subscribe_event_types.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:588270.7 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:305257.7 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2024 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_EVENT_RECIPIENT_SUPPORT
+      10                 :            : 
+      11                 :          7 : static libspdm_return_t try_libspdm_subscribe_event_types(libspdm_context_t *spdm_context,
+      12                 :            :                                                           uint32_t session_id,
+      13                 :            :                                                           uint8_t subscribe_event_group_count,
+      14                 :            :                                                           uint32_t subscribe_list_len,
+      15                 :            :                                                           void *subscribe_list)
+      16                 :            : {
+      17                 :            :     libspdm_return_t status;
+      18                 :            :     libspdm_session_info_t *session_info;
+      19                 :            :     spdm_subscribe_event_types_request_t *spdm_request;
+      20                 :            :     size_t spdm_request_size;
+      21                 :            :     spdm_supported_event_types_response_t *spdm_response;
+      22                 :            :     size_t spdm_response_size;
+      23                 :            :     size_t transport_header_size;
+      24                 :            :     uint8_t *message;
+      25                 :            :     size_t message_size;
+      26                 :            : 
+      27                 :            :     /* -=[Check Parameters Phase]=- */
+      28         [ +  + ]:          7 :     if (subscribe_event_group_count == 0) {
+      29   [ +  +  -  + ]:          4 :         if ((subscribe_list_len != 0) || (subscribe_list != NULL)) {
+      30                 :          1 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
+      31                 :            :         }
+      32                 :            :     } else {
+      33   [ +  +  -  + ]:          3 :         if ((subscribe_list_len == 0) || (subscribe_list == NULL)) {
+      34                 :          1 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
+      35                 :            :         }
+      36                 :            :     }
+      37                 :            : 
+      38                 :          5 :     session_info = libspdm_get_session_info_via_session_id(spdm_context, session_id);
+      39                 :            : 
+      40         [ -  + ]:          5 :     if (session_info == NULL) {
+      41                 :          0 :         LIBSPDM_ASSERT(false);
+      42                 :          0 :         return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+      43                 :            :     }
+      44         [ -  + ]:          5 :     if (libspdm_secured_message_get_session_state(session_info->secured_message_context) !=
+      45                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED) {
+      46                 :          0 :         return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+      47                 :            :     }
+      48                 :            : 
+      49                 :            :     /* -=[Verify State Phase]=- */
+      50         [ +  + ]:          5 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_13) {
+      51                 :          1 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+      52                 :            :     }
+      53         [ +  + ]:          4 :     if (!libspdm_is_capabilities_flag_supported(
+      54                 :            :             spdm_context, true, 0,
+      55                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EVENT_CAP)) {
+      56                 :          1 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+      57                 :            :     }
+      58                 :            : 
+      59                 :            :     /* -=[Construct Request Phase]=- */
+      60                 :          3 :     transport_header_size = spdm_context->local_context.capability.transport_header_size;
+      61                 :          3 :     status = libspdm_acquire_sender_buffer (spdm_context, &message_size, (void **)&message);
+      62         [ -  + ]:          3 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+      63                 :          0 :         return status;
+      64                 :            :     }
+      65         [ -  + ]:          3 :     LIBSPDM_ASSERT (message_size >= transport_header_size +
+      66                 :            :                     spdm_context->local_context.capability.transport_tail_size);
+      67                 :          3 :     spdm_request = (void *)(message + transport_header_size);
+      68                 :          3 :     spdm_request_size = message_size - transport_header_size -
+      69                 :          3 :                         spdm_context->local_context.capability.transport_tail_size;
+      70         [ -  + ]:          3 :     LIBSPDM_ASSERT (spdm_request_size >= sizeof(spdm_subscribe_event_types_request_t));
+      71                 :            : 
+      72         [ -  + ]:          3 :     if (spdm_request_size < sizeof(spdm_request->header)) {
+      73                 :          0 :         libspdm_release_sender_buffer(spdm_context);
+      74                 :          0 :         return LIBSPDM_STATUS_BUFFER_TOO_SMALL;
+      75                 :            :     }
+      76                 :            : 
+      77                 :          3 :     spdm_request->header.spdm_version = libspdm_get_connection_version(spdm_context);
+      78                 :          3 :     spdm_request->header.request_response_code = SPDM_SUBSCRIBE_EVENT_TYPES;
+      79                 :          3 :     spdm_request->header.param1 = subscribe_event_group_count;
+      80                 :          3 :     spdm_request->header.param2 = 0;
+      81                 :            : 
+      82         [ +  + ]:          3 :     if (subscribe_event_group_count == 0) {
+      83                 :          1 :         spdm_request_size = sizeof(spdm_request->header);
+      84                 :            :     } else {
+      85         [ -  + ]:          2 :         if (spdm_request_size < sizeof(spdm_subscribe_event_types_request_t) + subscribe_list_len) {
+      86                 :          0 :             libspdm_release_sender_buffer(spdm_context);
+      87                 :          0 :             return LIBSPDM_STATUS_BUFFER_TOO_SMALL;
+      88                 :            :         }
+      89                 :            : 
+      90                 :          2 :         spdm_request_size = sizeof(spdm_subscribe_event_types_request_t) + subscribe_list_len;
+      91                 :          2 :         spdm_request->subscribe_list_len = subscribe_list_len;
+      92                 :          2 :         libspdm_copy_mem(spdm_request + 1,
+      93                 :            :                          spdm_request_size - sizeof(spdm_subscribe_event_types_request_t),
+      94                 :            :                          subscribe_list,
+      95                 :            :                          subscribe_list_len);
+      96                 :            :     }
+      97                 :            : 
+      98                 :            :     /* -=[Send Request Phase]=- */
+      99                 :          3 :     status = libspdm_send_spdm_request(spdm_context, &session_id, spdm_request_size, spdm_request);
+     100         [ -  + ]:          3 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     101                 :          0 :         libspdm_release_sender_buffer (spdm_context);
+     102                 :          0 :         return status;
+     103                 :            :     }
+     104                 :            : 
+     105                 :          3 :     libspdm_release_sender_buffer(spdm_context);
+     106                 :          3 :     spdm_request = (void *)spdm_context->last_spdm_request;
+     107                 :            : 
+     108                 :            :     /* -=[Receive Response Phase]=- */
+     109                 :          3 :     status = libspdm_acquire_receiver_buffer(spdm_context, &message_size, (void **)&message);
+     110         [ -  + ]:          3 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     111                 :          0 :         return status;
+     112                 :            :     }
+     113         [ -  + ]:          3 :     LIBSPDM_ASSERT (message_size >= transport_header_size);
+     114                 :          3 :     spdm_response = (void *)(message);
+     115                 :          3 :     spdm_response_size = message_size;
+     116                 :            : 
+     117                 :          3 :     status = libspdm_receive_spdm_response(
+     118                 :            :         spdm_context, &session_id, &spdm_response_size, (void **)&spdm_response);
+     119         [ -  + ]:          3 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     120                 :          0 :         goto receive_done;
+     121                 :            :     }
+     122                 :            : 
+     123                 :            :     /* -=[Validate Response Phase]=- */
+     124         [ -  + ]:          3 :     if (spdm_response_size != sizeof(spdm_subscribe_event_types_ack_response_t)) {
+     125                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     126                 :          0 :         goto receive_done;
+     127                 :            :     }
+     128         [ -  + ]:          3 :     if (spdm_response->header.spdm_version != spdm_request->header.spdm_version) {
+     129                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     130                 :          0 :         goto receive_done;
+     131                 :            :     }
+     132         [ -  + ]:          3 :     if (spdm_response->header.request_response_code == SPDM_ERROR) {
+     133                 :          0 :         status = libspdm_handle_error_response_main(
+     134                 :            :             spdm_context, &session_id,
+     135                 :            :             &spdm_response_size, (void **)&spdm_response,
+     136                 :            :             SPDM_SUBSCRIBE_EVENT_TYPES, SPDM_SUBSCRIBE_EVENT_TYPES_ACK);
+     137         [ #  # ]:          0 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     138                 :          0 :             goto receive_done;
+     139                 :            :         }
+     140         [ +  - ]:          3 :     } else if (spdm_response->header.request_response_code != SPDM_SUBSCRIBE_EVENT_TYPES_ACK) {
+     141                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     142                 :          0 :         goto receive_done;
+     143                 :            :     }
+     144                 :            : 
+     145                 :          3 : receive_done:
+     146                 :          3 :     libspdm_release_receiver_buffer(spdm_context);
+     147                 :            : 
+     148                 :          3 :     return status;
+     149                 :            : }
+     150                 :            : 
+     151                 :          7 : libspdm_return_t libspdm_subscribe_event_types(void *spdm_context,
+     152                 :            :                                                uint32_t session_id,
+     153                 :            :                                                uint8_t subscribe_event_group_count,
+     154                 :            :                                                uint32_t subscribe_list_len,
+     155                 :            :                                                void *subscribe_list)
+     156                 :            : {
+     157                 :            :     size_t retry;
+     158                 :            :     uint64_t retry_delay_time;
+     159                 :            :     libspdm_return_t status;
+     160                 :            :     libspdm_context_t *context;
+     161                 :            : 
+     162                 :          7 :     context = spdm_context;
+     163                 :          7 :     context->crypto_request = true;
+     164                 :          7 :     retry = context->retry_times;
+     165                 :          7 :     retry_delay_time = context->retry_delay_time;
+     166                 :            :     do {
+     167                 :          7 :         status = try_libspdm_subscribe_event_types(context,
+     168                 :            :                                                    session_id,
+     169                 :            :                                                    subscribe_event_group_count,
+     170                 :            :                                                    subscribe_list_len,
+     171                 :            :                                                    subscribe_list);
+     172         [ +  - ]:          7 :         if (status != LIBSPDM_STATUS_BUSY_PEER) {
+     173                 :          7 :             return status;
+     174                 :            :         }
+     175                 :            : 
+     176                 :          0 :         libspdm_sleep(retry_delay_time);
+     177         [ #  # ]:          0 :     } while (retry-- != 0);
+     178                 :            : 
+     179                 :          0 :     return status;
+     180                 :            : }
+     181                 :            : 
+     182                 :            : #endif /* LIBSPDM_EVENT_RECIPIENT_SUPPORT */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_vendor_request.c.func-sort-c.html b/coverage_log/library/spdm_requester_lib/libspdm_req_vendor_request.c.func-sort-c.html new file mode 100644 index 00000000000..839f3536509 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_vendor_request.c.func-sort-c.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_vendor_request.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_vendor_request.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:9011975.6 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:336650.0 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_try_vendor_send_request_receive_response2
libspdm_vendor_send_request_receive_response2
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_vendor_request.c.func.html b/coverage_log/library/spdm_requester_lib/libspdm_req_vendor_request.c.func.html new file mode 100644 index 00000000000..f035c87db4e --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_vendor_request.c.func.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_vendor_request.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_vendor_request.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:9011975.6 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:336650.0 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_try_vendor_send_request_receive_response2
libspdm_vendor_send_request_receive_response2
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_requester_lib/libspdm_req_vendor_request.c.gcov.html b/coverage_log/library/spdm_requester_lib/libspdm_req_vendor_request.c.gcov.html new file mode 100644 index 00000000000..2d8836bf4c8 --- /dev/null +++ b/coverage_log/library/spdm_requester_lib/libspdm_req_vendor_request.c.gcov.html @@ -0,0 +1,358 @@ + + + + + + + LCOV - coverage.info - library/spdm_requester_lib/libspdm_req_vendor_request.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_requester_lib - libspdm_req_vendor_request.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:9011975.6 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:336650.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2023-2024 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_VENDOR_DEFINED_MESSAGES
+      10                 :            : 
+      11                 :            : #define SPDM_MAX_VENDOR_PAYLOAD_LEN (SPDM_MAX_VENDOR_ID_LENGTH + 2 + \
+      12                 :            :                                      SPDM_MAX_VENDOR_DEFINED_DATA_LEN)
+      13                 :            : 
+      14                 :            : #pragma pack(1)
+      15                 :            : typedef struct {
+      16                 :            :     spdm_message_header_t header;
+      17                 :            :     uint16_t standard_id;
+      18                 :            :     uint8_t vendor_id_len;
+      19                 :            :     uint8_t vendor_plus_request[SPDM_MAX_VENDOR_PAYLOAD_LEN];
+      20                 :            : } libspdm_vendor_defined_response_msg_max_t;
+      21                 :            : #pragma pack()
+      22                 :            : 
+      23                 :          2 : libspdm_return_t libspdm_try_vendor_send_request_receive_response(
+      24                 :            :     libspdm_context_t *spdm_context,
+      25                 :            :     const uint32_t *session_id,
+      26                 :            :     uint16_t req_standard_id,
+      27                 :            :     uint8_t req_vendor_id_len,
+      28                 :            :     const void *req_vendor_id,
+      29                 :            :     uint16_t req_size,
+      30                 :            :     const void *req_data,
+      31                 :            :     uint16_t *resp_standard_id,
+      32                 :            :     uint8_t *resp_vendor_id_len,
+      33                 :            :     void *resp_vendor_id,
+      34                 :            :     uint16_t *resp_size,
+      35                 :            :     void *resp_data)
+      36                 :            : {
+      37                 :            :     libspdm_return_t status;
+      38                 :            :     spdm_vendor_defined_request_msg_t *spdm_request;
+      39                 :            :     size_t spdm_request_size;
+      40                 :            :     libspdm_vendor_defined_response_msg_max_t *spdm_response;
+      41                 :            :     size_t spdm_response_size;
+      42                 :            :     uint8_t *message;
+      43                 :          2 :     size_t message_size = 0;
+      44                 :            :     size_t transport_header_size;
+      45                 :          2 :     size_t max_payload = 0;
+      46                 :          2 :     uint8_t* vendor_request = NULL;
+      47                 :          2 :     uint8_t *response_ptr = NULL;
+      48                 :          2 :     uint16_t response_size = 0;
+      49                 :            : 
+      50                 :            :     /* -=[Check Parameters Phase]=- */
+      51         [ +  - ]:          2 :     if (spdm_context == NULL ||
+      52   [ +  -  +  -  :          2 :         (req_size != 0 && req_data == NULL) ||
+                   +  - ]
+      53         [ +  - ]:          2 :         resp_standard_id == NULL ||
+      54         [ +  - ]:          2 :         resp_vendor_id_len == NULL ||
+      55         [ +  - ]:          2 :         resp_vendor_id == NULL ||
+      56                 :          2 :         resp_size == NULL ||
+      57   [ +  +  -  + ]:          2 :         (*resp_size != 0 && resp_data == NULL)
+      58                 :            :         ) {
+      59                 :          0 :         return LIBSPDM_STATUS_INVALID_PARAMETER;
+      60                 :            :     }
+      61                 :            : 
+      62         [ -  + ]:          2 :     if (spdm_context->connection_info.connection_state < LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
+      63                 :          0 :         return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+      64                 :            :     }
+      65                 :            : 
+      66                 :          2 :     transport_header_size = spdm_context->local_context.capability.transport_header_size;
+      67                 :            : 
+      68                 :            :     /* -=[Construct Request Phase]=- */
+      69                 :          2 :     status = libspdm_acquire_sender_buffer (spdm_context, &message_size, (void **)&message);
+      70         [ -  + ]:          2 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+      71                 :          0 :         return status;
+      72                 :            :     }
+      73                 :            : 
+      74                 :            :     /* calculate useful payload the sender buffer can hold after
+      75                 :            :      * removing all protocol, spdm and vendor defined message headers
+      76                 :            :      * -3 bytes is for the standard_id and vendor_id_len fields in the vendor header
+      77                 :            :      * -2 bytes is for the payload length field */
+      78                 :          2 :     max_payload = message_size - transport_header_size -
+      79                 :          2 :                   spdm_context->local_context.capability.transport_tail_size
+      80                 :          2 :                   - sizeof(spdm_request->header) - 3 - req_vendor_id_len - 2;
+      81                 :            : 
+      82         [ -  + ]:          2 :     LIBSPDM_ASSERT (message_size >= transport_header_size +
+      83                 :            :                     spdm_context->local_context.capability.transport_tail_size);
+      84                 :            : 
+      85                 :            :     /* do not accept requests exceeding maximum allowed payload */
+      86         [ -  + ]:          2 :     if ((size_t)req_size > max_payload) {
+      87                 :          0 :         return LIBSPDM_STATUS_INVALID_PARAMETER;
+      88                 :            :     }
+      89                 :            : 
+      90                 :          2 :     spdm_request = (void *)(message + transport_header_size);
+      91                 :          2 :     spdm_request_size = message_size - transport_header_size -
+      92                 :          2 :                         spdm_context->local_context.capability.transport_tail_size;
+      93                 :            : 
+      94         [ -  + ]:          2 :     LIBSPDM_ASSERT(spdm_request_size >= sizeof(spdm_vendor_defined_request_msg_t) +
+      95                 :            :                    req_vendor_id_len + sizeof(uint16_t) + req_size);
+      96                 :          2 :     spdm_request->header.spdm_version = libspdm_get_connection_version (spdm_context);
+      97                 :          2 :     spdm_request->header.request_response_code = SPDM_VENDOR_DEFINED_REQUEST;
+      98                 :          2 :     spdm_request->header.param1 = 0;
+      99                 :          2 :     spdm_request->header.param2 = 0;
+     100                 :            :     /* Message header here */
+     101                 :          2 :     spdm_request->standard_id = req_standard_id;
+     102                 :          2 :     spdm_request->len = req_vendor_id_len;
+     103                 :            : 
+     104                 :            :     /* Copy Vendor id */
+     105                 :          2 :     vendor_request = ((uint8_t *)spdm_request) + sizeof(spdm_vendor_defined_request_msg_t);
+     106         [ +  - ]:          2 :     if (req_vendor_id_len != 0) {
+     107                 :          2 :         libspdm_copy_mem(vendor_request, req_vendor_id_len, req_vendor_id, req_vendor_id_len);
+     108                 :          2 :         vendor_request += req_vendor_id_len;
+     109                 :            :     }
+     110                 :            : 
+     111                 :            :     /* Copy request_len */
+     112                 :          2 :     libspdm_copy_mem(vendor_request, sizeof(uint16_t), &req_size, sizeof(uint16_t));
+     113                 :          2 :     vendor_request += sizeof(uint16_t);
+     114                 :            : 
+     115                 :            :     /* Copy payload */
+     116         [ +  - ]:          2 :     if (req_size != 0) {
+     117                 :          2 :         libspdm_copy_mem(vendor_request, req_size, req_data, req_size);
+     118                 :            :     }
+     119                 :            : 
+     120                 :          2 :     spdm_request_size = sizeof(spdm_vendor_defined_request_msg_t) +
+     121                 :          2 :                         req_vendor_id_len + sizeof(uint16_t) + req_size;
+     122                 :            : 
+     123                 :            :     /* -=[Send Request Phase]=- */
+     124                 :            :     status =
+     125                 :          2 :         libspdm_send_spdm_request(spdm_context, session_id, spdm_request_size, spdm_request);
+     126         [ -  + ]:          2 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     127                 :          0 :         libspdm_release_sender_buffer (spdm_context);
+     128                 :          0 :         return LIBSPDM_STATUS_SEND_FAIL;
+     129                 :            :     }
+     130                 :          2 :     libspdm_release_sender_buffer (spdm_context);
+     131                 :          2 :     spdm_request = (void *)spdm_context->last_spdm_request;
+     132                 :            : 
+     133                 :            :     /* -=[Receive Response Phase]=- */
+     134                 :          2 :     status = libspdm_acquire_receiver_buffer (spdm_context, &message_size, (void **)&message);
+     135         [ -  + ]:          2 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     136                 :          0 :         return status;
+     137                 :            :     }
+     138         [ -  + ]:          2 :     LIBSPDM_ASSERT (message_size >= transport_header_size);
+     139                 :          2 :     spdm_response = (void *)(message);
+     140                 :          2 :     spdm_response_size = message_size;
+     141                 :            : 
+     142                 :          2 :     status = libspdm_receive_spdm_response(spdm_context, session_id,
+     143                 :            :                                            &spdm_response_size,
+     144                 :            :                                            (void **)&spdm_response);
+     145                 :            : 
+     146         [ +  + ]:          2 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     147                 :          1 :         status = LIBSPDM_STATUS_RECEIVE_FAIL;
+     148                 :          1 :         goto done;
+     149                 :            :     }
+     150                 :            : 
+     151                 :            :     /* -=[Validate Response Phase]=- */
+     152         [ -  + ]:          1 :     if (spdm_response_size < sizeof(spdm_message_header_t)) {
+     153                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     154                 :          0 :         goto done;
+     155                 :            :     }
+     156         [ -  + ]:          1 :     if (spdm_response->header.spdm_version != spdm_request->header.spdm_version) {
+     157                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     158                 :          0 :         goto done;
+     159                 :            :     }
+     160         [ -  + ]:          1 :     if (spdm_response->header.request_response_code == SPDM_ERROR) {
+     161                 :          0 :         status = libspdm_handle_error_response_main(
+     162                 :            :             spdm_context, session_id,
+     163                 :            :             &spdm_response_size,
+     164                 :            :             (void **)&spdm_response, SPDM_VENDOR_DEFINED_REQUEST,
+     165                 :            :             SPDM_VENDOR_DEFINED_RESPONSE);
+     166         [ #  # ]:          0 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     167                 :          0 :             goto done;
+     168                 :            :         }
+     169         [ -  + ]:          1 :     } else if (spdm_response->header.request_response_code != SPDM_VENDOR_DEFINED_RESPONSE) {
+     170                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     171                 :          0 :         goto done;
+     172                 :            :     }
+     173                 :            : 
+     174         [ -  + ]:          1 :     if (spdm_response_size < sizeof(spdm_vendor_defined_response_msg_t)) {
+     175                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     176                 :          0 :         goto done;
+     177                 :            :     }
+     178                 :            :     /* check response buffer size at least spdm response default header plus
+     179                 :            :      * number of bytes required by vendor id and 2 bytes for response payload size */
+     180                 :          1 :     if (spdm_response_size < sizeof(spdm_vendor_defined_response_msg_t) +
+     181         [ -  + ]:          1 :         spdm_response->vendor_id_len + sizeof(uint16_t)) {
+     182                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     183                 :          0 :         goto done;
+     184                 :            :     }
+     185                 :            : 
+     186                 :          1 :     *resp_standard_id = spdm_response->standard_id;
+     187         [ -  + ]:          1 :     if (*resp_vendor_id_len < spdm_response->vendor_id_len) {
+     188                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     189                 :          0 :         goto done;
+     190                 :            :     }
+     191                 :          1 :     *resp_vendor_id_len = spdm_response->vendor_id_len;
+     192         [ +  - ]:          1 :     if ((*resp_vendor_id_len) != 0) {
+     193                 :          1 :         libspdm_copy_mem(resp_vendor_id, *resp_vendor_id_len, spdm_response->vendor_plus_request,
+     194                 :          1 :                          *resp_vendor_id_len);
+     195                 :            :     }
+     196                 :            : 
+     197                 :            :     /* -=[Process Response Phase]=- */
+     198                 :          1 :     response_ptr = spdm_response->vendor_plus_request + spdm_response->vendor_id_len;
+     199                 :          1 :     response_size = *((uint16_t*)response_ptr);
+     200                 :          1 :     if (spdm_response_size < response_size +
+     201                 :          1 :         sizeof(spdm_vendor_defined_response_msg_t) +
+     202         [ -  + ]:          1 :         spdm_response->vendor_id_len + sizeof(uint16_t)) {
+     203                 :          0 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     204                 :          0 :         goto done;
+     205                 :            :     }
+     206                 :          1 :     response_ptr += sizeof(uint16_t);
+     207         [ -  + ]:          1 :     if (*resp_size < response_size) {
+     208                 :          0 :         status = LIBSPDM_STATUS_BUFFER_TOO_SMALL;
+     209                 :          0 :         goto done;
+     210                 :            :     }
+     211                 :          1 :     libspdm_copy_mem(resp_data, *resp_size, response_ptr, response_size);
+     212                 :          1 :     *resp_size = response_size;
+     213                 :            : 
+     214                 :            :     /* -=[Log Message Phase]=- */
+     215                 :            :     #if LIBSPDM_ENABLE_MSG_LOG
+     216                 :          1 :     libspdm_append_msg_log(spdm_context, spdm_response, spdm_response_size);
+     217                 :            :     #endif /* LIBSPDM_ENABLE_MSG_LOG */
+     218                 :            : 
+     219                 :          1 :     status = LIBSPDM_STATUS_SUCCESS;
+     220                 :          2 : done:
+     221                 :          2 :     libspdm_release_receiver_buffer (spdm_context); /* this will free up response-message, need to find workaround */
+     222                 :          2 :     return status;
+     223                 :            : }
+     224                 :            : 
+     225                 :          2 : libspdm_return_t libspdm_vendor_send_request_receive_response(
+     226                 :            :     void *spdm_context,
+     227                 :            :     const uint32_t *session_id,
+     228                 :            :     uint16_t req_standard_id,
+     229                 :            :     uint8_t req_vendor_id_len,
+     230                 :            :     const void *req_vendor_id,
+     231                 :            :     uint16_t req_size,
+     232                 :            :     const void *req_data,
+     233                 :            :     uint16_t *resp_standard_id,
+     234                 :            :     uint8_t *resp_vendor_id_len,
+     235                 :            :     void *resp_vendor_id,
+     236                 :            :     uint16_t *resp_size,
+     237                 :            :     void *resp_data)
+     238                 :            : {
+     239                 :            :     libspdm_context_t *context;
+     240                 :            :     size_t retry;
+     241                 :            :     uint64_t retry_delay_time;
+     242                 :            :     libspdm_return_t status;
+     243                 :            : 
+     244                 :          2 :     context = spdm_context;
+     245                 :          2 :     context->crypto_request = true;
+     246                 :          2 :     retry = context->retry_times;
+     247                 :          2 :     retry_delay_time = context->retry_delay_time;
+     248                 :            :     do {
+     249                 :          2 :         status = libspdm_try_vendor_send_request_receive_response(
+     250                 :            :             context,
+     251                 :            :             session_id,
+     252                 :            :             req_standard_id,
+     253                 :            :             req_vendor_id_len,
+     254                 :            :             req_vendor_id,
+     255                 :            :             req_size,
+     256                 :            :             req_data,
+     257                 :            :             resp_standard_id,
+     258                 :            :             resp_vendor_id_len,
+     259                 :            :             resp_vendor_id,
+     260                 :            :             resp_size,
+     261                 :            :             resp_data);
+     262         [ +  - ]:          2 :         if (status != LIBSPDM_STATUS_BUSY_PEER) {
+     263                 :          2 :             return status;
+     264                 :            :         }
+     265                 :            : 
+     266                 :          0 :         libspdm_sleep(retry_delay_time);
+     267         [ #  # ]:          0 :     } while (retry-- != 0);
+     268                 :            : 
+     269                 :          0 :     return status;
+     270                 :            : }
+     271                 :            : 
+     272                 :            : #endif /* LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/index-sort-b.html b/coverage_log/library/spdm_responder_lib/index-sort-b.html new file mode 100644 index 00000000000..3d8a937e2cf --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/index-sort-b.html @@ -0,0 +1,503 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_libHitTotalCoverage
Test:coverage.infoLines:2856373076.6 %
Date:2024-09-22 08:21:07Functions:697789.6 %
Branches:1424225563.1 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
libspdm_rsp_receive_send.c +
34.3%34.3%
+
34.3 %111 / 32464.3 %9 / 1424.5 %46 / 188
libspdm_rsp_encap_get_certificate.c +
60.0%60.0%
+
60.0 %75 / 125100.0 %2 / 247.4 %37 / 78
libspdm_rsp_vendor_response.c +
78.8%78.8%
+
78.8 %63 / 80100.0 %3 / 350.0 %18 / 36
libspdm_rsp_set_key_pair_info_ack.c +
69.0%69.0%
+
69.0 %60 / 87100.0 %1 / 150.0 %40 / 80
libspdm_rsp_encap_response.c +
57.5%57.5%
+
57.5 %126 / 21966.7 %6 / 950.4 %57 / 113
libspdm_rsp_encap_key_update.c +
70.4%70.4%
+
70.4 %57 / 81100.0 %2 / 252.2 %24 / 46
libspdm_rsp_measurement_extension_log.c +
74.6%74.6%
+
74.6 %44 / 59100.0 %1 / 152.8 %19 / 36
libspdm_rsp_supported_event_types.c +
76.7%76.7%
+
76.7 %33 / 43100.0 %1 / 153.3 %16 / 30
libspdm_rsp_get_key_pair_info.c +
75.0%75.0%
+
75.0 %39 / 52100.0 %1 / 153.3 %16 / 30
libspdm_rsp_psk_exchange.c +
69.9%69.9%
+
69.9 %128 / 183100.0 %2 / 256.0 %56 / 100
libspdm_rsp_psk_finish.c +
79.0%79.0%
+
79.0 %64 / 81100.0 %2 / 262.5 %30 / 48
libspdm_rsp_encap_challenge.c +
80.7%80.7%
+
80.7 %109 / 135100.0 %2 / 262.9 %39 / 62
libspdm_rsp_subscribe_event_types_ack.c +
75.5%75.5%
+
75.5 %40 / 53100.0 %1 / 163.2 %24 / 38
libspdm_rsp_key_exchange.c +
76.2%76.2%
+
76.2 %173 / 227100.0 %3 / 363.8 %74 / 116
libspdm_rsp_csr.c +
79.3%79.3%
+
79.3 %73 / 92100.0 %1 / 164.9 %48 / 74
libspdm_rsp_version.c +
91.2%91.2%
+
91.2 %52 / 57100.0 %2 / 265.0 %13 / 20
libspdm_rsp_challenge_auth.c +
82.7%82.7%
+
82.7 %115 / 139100.0 %1 / 166.3 %65 / 98
libspdm_rsp_handle_response_state.c +
80.8%80.8%
+
80.8 %21 / 26100.0 %1 / 166.7 %6 / 9
libspdm_rsp_error.c +
100.0%
+
100.0 %24 / 24100.0 %2 / 266.7 %8 / 12
libspdm_rsp_heartbeat.c +
83.8%83.8%
+
83.8 %31 / 37100.0 %1 / 166.7 %16 / 24
libspdm_rsp_set_certificate.c +
79.6%79.6%
+
79.6 %74 / 93100.0 %2 / 267.1 %51 / 76
libspdm_rsp_end_session.c +
85.7%85.7%
+
85.7 %30 / 35100.0 %1 / 170.0 %14 / 20
libspdm_rsp_common.c +
86.2%86.2%
+
86.2 %69 / 80100.0 %3 / 370.0 %28 / 40
libspdm_rsp_finish.c +
84.0%84.0%
+
84.0 %142 / 169100.0 %4 / 470.5 %79 / 112
libspdm_rsp_chunk_send_ack.c +
89.9%89.9%
+
89.9 %107 / 119100.0 %1 / 171.4 %50 / 70
libspdm_rsp_respond_if_ready.c +
80.0%80.0%
+
80.0 %20 / 25100.0 %1 / 172.2 %13 / 18
libspdm_rsp_key_update.c +
89.3%89.3%
+
89.3 %75 / 84100.0 %1 / 175.0 %33 / 44
libspdm_rsp_certificate.c +
87.5%87.5%
+
87.5 %63 / 72100.0 %1 / 175.0 %36 / 48
libspdm_rsp_capabilities.c +
89.1%89.1%
+
89.1 %122 / 137100.0 %3 / 375.4 %95 / 126
libspdm_rsp_measurements.c +
85.3%85.3%
+
85.3 %163 / 191100.0 %2 / 275.6 %90 / 119
libspdm_rsp_encap_get_digests.c +
88.1%88.1%
+
88.1 %111 / 126100.0 %2 / 279.3 %65 / 82
libspdm_rsp_digests.c +
89.3%89.3%
+
89.3 %75 / 84100.0 %1 / 179.6 %43 / 54
libspdm_rsp_chunk_get.c +
96.9%96.9%
+
96.9 %62 / 64100.0 %1 / 181.2 %26 / 32
libspdm_rsp_algorithms.c +
93.3%93.3%
+
93.3 %305 / 327100.0 %2 / 284.7 %149 / 176
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/index-sort-f.html b/coverage_log/library/spdm_responder_lib/index-sort-f.html new file mode 100644 index 00000000000..cb6520a81c5 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/index-sort-f.html @@ -0,0 +1,503 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_libHitTotalCoverage
Test:coverage.infoLines:2856373076.6 %
Date:2024-09-22 08:21:07Functions:697789.6 %
Branches:1424225563.1 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
libspdm_rsp_receive_send.c +
34.3%34.3%
+
34.3 %111 / 32464.3 %9 / 1424.5 %46 / 188
libspdm_rsp_encap_response.c +
57.5%57.5%
+
57.5 %126 / 21966.7 %6 / 950.4 %57 / 113
libspdm_rsp_chunk_send_ack.c +
89.9%89.9%
+
89.9 %107 / 119100.0 %1 / 171.4 %50 / 70
libspdm_rsp_challenge_auth.c +
82.7%82.7%
+
82.7 %115 / 139100.0 %1 / 166.3 %65 / 98
libspdm_rsp_respond_if_ready.c +
80.0%80.0%
+
80.0 %20 / 25100.0 %1 / 172.2 %13 / 18
libspdm_rsp_supported_event_types.c +
76.7%76.7%
+
76.7 %33 / 43100.0 %1 / 153.3 %16 / 30
libspdm_rsp_heartbeat.c +
83.8%83.8%
+
83.8 %31 / 37100.0 %1 / 166.7 %16 / 24
libspdm_rsp_set_key_pair_info_ack.c +
69.0%69.0%
+
69.0 %60 / 87100.0 %1 / 150.0 %40 / 80
libspdm_rsp_get_key_pair_info.c +
75.0%75.0%
+
75.0 %39 / 52100.0 %1 / 153.3 %16 / 30
libspdm_rsp_certificate.c +
87.5%87.5%
+
87.5 %63 / 72100.0 %1 / 175.0 %36 / 48
libspdm_rsp_end_session.c +
85.7%85.7%
+
85.7 %30 / 35100.0 %1 / 170.0 %14 / 20
libspdm_rsp_handle_response_state.c +
80.8%80.8%
+
80.8 %21 / 26100.0 %1 / 166.7 %6 / 9
libspdm_rsp_measurement_extension_log.c +
74.6%74.6%
+
74.6 %44 / 59100.0 %1 / 152.8 %19 / 36
libspdm_rsp_subscribe_event_types_ack.c +
75.5%75.5%
+
75.5 %40 / 53100.0 %1 / 163.2 %24 / 38
libspdm_rsp_csr.c +
79.3%79.3%
+
79.3 %73 / 92100.0 %1 / 164.9 %48 / 74
libspdm_rsp_key_update.c +
89.3%89.3%
+
89.3 %75 / 84100.0 %1 / 175.0 %33 / 44
libspdm_rsp_digests.c +
89.3%89.3%
+
89.3 %75 / 84100.0 %1 / 179.6 %43 / 54
libspdm_rsp_chunk_get.c +
96.9%96.9%
+
96.9 %62 / 64100.0 %1 / 181.2 %26 / 32
libspdm_rsp_encap_get_certificate.c +
60.0%60.0%
+
60.0 %75 / 125100.0 %2 / 247.4 %37 / 78
libspdm_rsp_psk_exchange.c +
69.9%69.9%
+
69.9 %128 / 183100.0 %2 / 256.0 %56 / 100
libspdm_rsp_version.c +
91.2%91.2%
+
91.2 %52 / 57100.0 %2 / 265.0 %13 / 20
libspdm_rsp_psk_finish.c +
79.0%79.0%
+
79.0 %64 / 81100.0 %2 / 262.5 %30 / 48
libspdm_rsp_measurements.c +
85.3%85.3%
+
85.3 %163 / 191100.0 %2 / 275.6 %90 / 119
libspdm_rsp_encap_get_digests.c +
88.1%88.1%
+
88.1 %111 / 126100.0 %2 / 279.3 %65 / 82
libspdm_rsp_set_certificate.c +
79.6%79.6%
+
79.6 %74 / 93100.0 %2 / 267.1 %51 / 76
libspdm_rsp_error.c +
100.0%
+
100.0 %24 / 24100.0 %2 / 266.7 %8 / 12
libspdm_rsp_encap_challenge.c +
80.7%80.7%
+
80.7 %109 / 135100.0 %2 / 262.9 %39 / 62
libspdm_rsp_encap_key_update.c +
70.4%70.4%
+
70.4 %57 / 81100.0 %2 / 252.2 %24 / 46
libspdm_rsp_algorithms.c +
93.3%93.3%
+
93.3 %305 / 327100.0 %2 / 284.7 %149 / 176
libspdm_rsp_capabilities.c +
89.1%89.1%
+
89.1 %122 / 137100.0 %3 / 375.4 %95 / 126
libspdm_rsp_vendor_response.c +
78.8%78.8%
+
78.8 %63 / 80100.0 %3 / 350.0 %18 / 36
libspdm_rsp_key_exchange.c +
76.2%76.2%
+
76.2 %173 / 227100.0 %3 / 363.8 %74 / 116
libspdm_rsp_common.c +
86.2%86.2%
+
86.2 %69 / 80100.0 %3 / 370.0 %28 / 40
libspdm_rsp_finish.c +
84.0%84.0%
+
84.0 %142 / 169100.0 %4 / 470.5 %79 / 112
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/index-sort-l.html b/coverage_log/library/spdm_responder_lib/index-sort-l.html new file mode 100644 index 00000000000..3444646ec66 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/index-sort-l.html @@ -0,0 +1,503 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_libHitTotalCoverage
Test:coverage.infoLines:2856373076.6 %
Date:2024-09-22 08:21:07Functions:697789.6 %
Branches:1424225563.1 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
libspdm_rsp_receive_send.c +
34.3%34.3%
+
34.3 %111 / 32464.3 %9 / 1424.5 %46 / 188
libspdm_rsp_encap_response.c +
57.5%57.5%
+
57.5 %126 / 21966.7 %6 / 950.4 %57 / 113
libspdm_rsp_encap_get_certificate.c +
60.0%60.0%
+
60.0 %75 / 125100.0 %2 / 247.4 %37 / 78
libspdm_rsp_set_key_pair_info_ack.c +
69.0%69.0%
+
69.0 %60 / 87100.0 %1 / 150.0 %40 / 80
libspdm_rsp_psk_exchange.c +
69.9%69.9%
+
69.9 %128 / 183100.0 %2 / 256.0 %56 / 100
libspdm_rsp_encap_key_update.c +
70.4%70.4%
+
70.4 %57 / 81100.0 %2 / 252.2 %24 / 46
libspdm_rsp_measurement_extension_log.c +
74.6%74.6%
+
74.6 %44 / 59100.0 %1 / 152.8 %19 / 36
libspdm_rsp_get_key_pair_info.c +
75.0%75.0%
+
75.0 %39 / 52100.0 %1 / 153.3 %16 / 30
libspdm_rsp_subscribe_event_types_ack.c +
75.5%75.5%
+
75.5 %40 / 53100.0 %1 / 163.2 %24 / 38
libspdm_rsp_key_exchange.c +
76.2%76.2%
+
76.2 %173 / 227100.0 %3 / 363.8 %74 / 116
libspdm_rsp_supported_event_types.c +
76.7%76.7%
+
76.7 %33 / 43100.0 %1 / 153.3 %16 / 30
libspdm_rsp_vendor_response.c +
78.8%78.8%
+
78.8 %63 / 80100.0 %3 / 350.0 %18 / 36
libspdm_rsp_psk_finish.c +
79.0%79.0%
+
79.0 %64 / 81100.0 %2 / 262.5 %30 / 48
libspdm_rsp_csr.c +
79.3%79.3%
+
79.3 %73 / 92100.0 %1 / 164.9 %48 / 74
libspdm_rsp_set_certificate.c +
79.6%79.6%
+
79.6 %74 / 93100.0 %2 / 267.1 %51 / 76
libspdm_rsp_respond_if_ready.c +
80.0%80.0%
+
80.0 %20 / 25100.0 %1 / 172.2 %13 / 18
libspdm_rsp_handle_response_state.c +
80.8%80.8%
+
80.8 %21 / 26100.0 %1 / 166.7 %6 / 9
libspdm_rsp_encap_challenge.c +
80.7%80.7%
+
80.7 %109 / 135100.0 %2 / 262.9 %39 / 62
libspdm_rsp_challenge_auth.c +
82.7%82.7%
+
82.7 %115 / 139100.0 %1 / 166.3 %65 / 98
libspdm_rsp_heartbeat.c +
83.8%83.8%
+
83.8 %31 / 37100.0 %1 / 166.7 %16 / 24
libspdm_rsp_finish.c +
84.0%84.0%
+
84.0 %142 / 169100.0 %4 / 470.5 %79 / 112
libspdm_rsp_measurements.c +
85.3%85.3%
+
85.3 %163 / 191100.0 %2 / 275.6 %90 / 119
libspdm_rsp_end_session.c +
85.7%85.7%
+
85.7 %30 / 35100.0 %1 / 170.0 %14 / 20
libspdm_rsp_common.c +
86.2%86.2%
+
86.2 %69 / 80100.0 %3 / 370.0 %28 / 40
libspdm_rsp_certificate.c +
87.5%87.5%
+
87.5 %63 / 72100.0 %1 / 175.0 %36 / 48
libspdm_rsp_encap_get_digests.c +
88.1%88.1%
+
88.1 %111 / 126100.0 %2 / 279.3 %65 / 82
libspdm_rsp_capabilities.c +
89.1%89.1%
+
89.1 %122 / 137100.0 %3 / 375.4 %95 / 126
libspdm_rsp_key_update.c +
89.3%89.3%
+
89.3 %75 / 84100.0 %1 / 175.0 %33 / 44
libspdm_rsp_digests.c +
89.3%89.3%
+
89.3 %75 / 84100.0 %1 / 179.6 %43 / 54
libspdm_rsp_chunk_send_ack.c +
89.9%89.9%
+
89.9 %107 / 119100.0 %1 / 171.4 %50 / 70
libspdm_rsp_version.c +
91.2%91.2%
+
91.2 %52 / 57100.0 %2 / 265.0 %13 / 20
libspdm_rsp_algorithms.c +
93.3%93.3%
+
93.3 %305 / 327100.0 %2 / 284.7 %149 / 176
libspdm_rsp_chunk_get.c +
96.9%96.9%
+
96.9 %62 / 64100.0 %1 / 181.2 %26 / 32
libspdm_rsp_error.c +
100.0%
+
100.0 %24 / 24100.0 %2 / 266.7 %8 / 12
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/index.html b/coverage_log/library/spdm_responder_lib/index.html new file mode 100644 index 00000000000..0e04b30e60c --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/index.html @@ -0,0 +1,503 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_libHitTotalCoverage
Test:coverage.infoLines:2856373076.6 %
Date:2024-09-22 08:21:07Functions:697789.6 %
Branches:1424225563.1 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
libspdm_rsp_algorithms.c +
93.3%93.3%
+
93.3 %305 / 327100.0 %2 / 284.7 %149 / 176
libspdm_rsp_capabilities.c +
89.1%89.1%
+
89.1 %122 / 137100.0 %3 / 375.4 %95 / 126
libspdm_rsp_certificate.c +
87.5%87.5%
+
87.5 %63 / 72100.0 %1 / 175.0 %36 / 48
libspdm_rsp_challenge_auth.c +
82.7%82.7%
+
82.7 %115 / 139100.0 %1 / 166.3 %65 / 98
libspdm_rsp_chunk_get.c +
96.9%96.9%
+
96.9 %62 / 64100.0 %1 / 181.2 %26 / 32
libspdm_rsp_chunk_send_ack.c +
89.9%89.9%
+
89.9 %107 / 119100.0 %1 / 171.4 %50 / 70
libspdm_rsp_common.c +
86.2%86.2%
+
86.2 %69 / 80100.0 %3 / 370.0 %28 / 40
libspdm_rsp_csr.c +
79.3%79.3%
+
79.3 %73 / 92100.0 %1 / 164.9 %48 / 74
libspdm_rsp_digests.c +
89.3%89.3%
+
89.3 %75 / 84100.0 %1 / 179.6 %43 / 54
libspdm_rsp_encap_challenge.c +
80.7%80.7%
+
80.7 %109 / 135100.0 %2 / 262.9 %39 / 62
libspdm_rsp_encap_get_certificate.c +
60.0%60.0%
+
60.0 %75 / 125100.0 %2 / 247.4 %37 / 78
libspdm_rsp_encap_get_digests.c +
88.1%88.1%
+
88.1 %111 / 126100.0 %2 / 279.3 %65 / 82
libspdm_rsp_encap_key_update.c +
70.4%70.4%
+
70.4 %57 / 81100.0 %2 / 252.2 %24 / 46
libspdm_rsp_encap_response.c +
57.5%57.5%
+
57.5 %126 / 21966.7 %6 / 950.4 %57 / 113
libspdm_rsp_end_session.c +
85.7%85.7%
+
85.7 %30 / 35100.0 %1 / 170.0 %14 / 20
libspdm_rsp_error.c +
100.0%
+
100.0 %24 / 24100.0 %2 / 266.7 %8 / 12
libspdm_rsp_finish.c +
84.0%84.0%
+
84.0 %142 / 169100.0 %4 / 470.5 %79 / 112
libspdm_rsp_get_key_pair_info.c +
75.0%75.0%
+
75.0 %39 / 52100.0 %1 / 153.3 %16 / 30
libspdm_rsp_handle_response_state.c +
80.8%80.8%
+
80.8 %21 / 26100.0 %1 / 166.7 %6 / 9
libspdm_rsp_heartbeat.c +
83.8%83.8%
+
83.8 %31 / 37100.0 %1 / 166.7 %16 / 24
libspdm_rsp_key_exchange.c +
76.2%76.2%
+
76.2 %173 / 227100.0 %3 / 363.8 %74 / 116
libspdm_rsp_key_update.c +
89.3%89.3%
+
89.3 %75 / 84100.0 %1 / 175.0 %33 / 44
libspdm_rsp_measurement_extension_log.c +
74.6%74.6%
+
74.6 %44 / 59100.0 %1 / 152.8 %19 / 36
libspdm_rsp_measurements.c +
85.3%85.3%
+
85.3 %163 / 191100.0 %2 / 275.6 %90 / 119
libspdm_rsp_psk_exchange.c +
69.9%69.9%
+
69.9 %128 / 183100.0 %2 / 256.0 %56 / 100
libspdm_rsp_psk_finish.c +
79.0%79.0%
+
79.0 %64 / 81100.0 %2 / 262.5 %30 / 48
libspdm_rsp_receive_send.c +
34.3%34.3%
+
34.3 %111 / 32464.3 %9 / 1424.5 %46 / 188
libspdm_rsp_respond_if_ready.c +
80.0%80.0%
+
80.0 %20 / 25100.0 %1 / 172.2 %13 / 18
libspdm_rsp_set_certificate.c +
79.6%79.6%
+
79.6 %74 / 93100.0 %2 / 267.1 %51 / 76
libspdm_rsp_set_key_pair_info_ack.c +
69.0%69.0%
+
69.0 %60 / 87100.0 %1 / 150.0 %40 / 80
libspdm_rsp_subscribe_event_types_ack.c +
75.5%75.5%
+
75.5 %40 / 53100.0 %1 / 163.2 %24 / 38
libspdm_rsp_supported_event_types.c +
76.7%76.7%
+
76.7 %33 / 43100.0 %1 / 153.3 %16 / 30
libspdm_rsp_vendor_response.c +
78.8%78.8%
+
78.8 %63 / 80100.0 %3 / 350.0 %18 / 36
libspdm_rsp_version.c +
91.2%91.2%
+
91.2 %52 / 57100.0 %2 / 265.0 %13 / 20
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_algorithms.c.func-sort-c.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_algorithms.c.func-sort-c.html new file mode 100644 index 00000000000..8e1152c6723 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_algorithms.c.func-sort-c.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_algorithms.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_algorithms.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:30532793.3 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:14917684.7 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_response_algorithms42
libspdm_prioritize_algorithm170
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_algorithms.c.func.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_algorithms.c.func.html new file mode 100644 index 00000000000..4a4b30a7e31 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_algorithms.c.func.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_algorithms.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_algorithms.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:30532793.3 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:14917684.7 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_response_algorithms42
libspdm_prioritize_algorithm170
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_algorithms.c.gcov.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_algorithms.c.gcov.html new file mode 100644 index 00000000000..354cb5b7756 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_algorithms.c.gcov.html @@ -0,0 +1,960 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_algorithms.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_algorithms.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:30532793.3 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:14917684.7 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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_responder_lib.h"
+       8                 :            : 
+       9                 :            : /* current version libspdm does not support any ext algo.
+      10                 :            :  * the responder will ignore the ext algo in request.
+      11                 :            :  * the responder will not build ext algo in response.*/
+      12                 :            : #pragma pack(1)
+      13                 :            : typedef struct {
+      14                 :            :     spdm_message_header_t header;
+      15                 :            :     uint16_t length;
+      16                 :            :     uint8_t measurement_specification_sel;
+      17                 :            :     uint8_t other_params_selection;
+      18                 :            :     uint32_t measurement_hash_algo;
+      19                 :            :     uint32_t base_asym_sel;
+      20                 :            :     uint32_t base_hash_sel;
+      21                 :            :     uint8_t reserved2[11];
+      22                 :            :     uint8_t mel_specification_sel;
+      23                 :            :     uint8_t ext_asym_sel_count;
+      24                 :            :     uint8_t ext_hash_sel_count;
+      25                 :            :     uint16_t reserved3;
+      26                 :            :     spdm_negotiate_algorithms_common_struct_table_t struct_table[
+      27                 :            :         SPDM_NEGOTIATE_ALGORITHMS_MAX_NUM_STRUCT_TABLE_ALG];
+      28                 :            : } libspdm_algorithms_response_mine_t;
+      29                 :            : #pragma pack()
+      30                 :            : 
+      31                 :            : /**
+      32                 :            :  * Select the preferred supported algorithm according to the priority_table.
+      33                 :            :  *
+      34                 :            :  * @param  priority_table        The priority table.
+      35                 :            :  * @param  priority_table_count  The count of the priority table entry.
+      36                 :            :  * @param  local_algo            Local supported algorithm.
+      37                 :            :  * @param  peer_algo             Peer supported algorithm.
+      38                 :            :  *
+      39                 :            :  * @return   Preferred supported algorithm
+      40                 :            :  **/
+      41                 :        170 : static uint32_t libspdm_prioritize_algorithm(const uint32_t *priority_table,
+      42                 :            :                                              size_t priority_table_count,
+      43                 :            :                                              uint32_t local_algo, uint32_t peer_algo)
+      44                 :            : {
+      45                 :            :     uint32_t common_algo;
+      46                 :            :     size_t index;
+      47                 :            : 
+      48                 :        170 :     common_algo = (local_algo & peer_algo);
+      49         [ +  + ]:        687 :     for (index = 0; index < priority_table_count; index++) {
+      50         [ +  + ]:        628 :         if ((common_algo & priority_table[index]) != 0) {
+      51                 :        111 :             return priority_table[index];
+      52                 :            :         }
+      53                 :            :     }
+      54                 :            : 
+      55                 :         59 :     return 0;
+      56                 :            : }
+      57                 :            : 
+      58                 :         42 : libspdm_return_t libspdm_get_response_algorithms(libspdm_context_t *spdm_context,
+      59                 :            :                                                  size_t request_size,
+      60                 :            :                                                  const void *request,
+      61                 :            :                                                  size_t *response_size,
+      62                 :            :                                                  void *response)
+      63                 :            : {
+      64                 :            :     const spdm_negotiate_algorithms_request_t *spdm_request;
+      65                 :            :     size_t spdm_request_size;
+      66                 :            :     libspdm_algorithms_response_mine_t *spdm_response;
+      67                 :            :     spdm_negotiate_algorithms_common_struct_table_t *struct_table;
+      68                 :            :     size_t index;
+      69                 :            :     libspdm_return_t status;
+      70                 :            :     uint32_t algo_size;
+      71                 :            :     uint8_t fixed_alg_size;
+      72                 :            :     uint8_t ext_alg_count;
+      73                 :            :     uint16_t ext_alg_total_count;
+      74                 :            :     uint8_t alg_type_pre;
+      75                 :            : 
+      76                 :         42 :     uint32_t hash_priority_table[] = {
+      77                 :            :     #if LIBSPDM_SHA512_SUPPORT
+      78                 :            :         SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512,
+      79                 :            :     #endif
+      80                 :            :     #if LIBSPDM_SHA384_SUPPORT
+      81                 :            :         SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_384,
+      82                 :            :     #endif
+      83                 :            :     #if LIBSPDM_SHA256_SUPPORT
+      84                 :            :         SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+      85                 :            :     #endif
+      86                 :            :     #if LIBSPDM_SHA3_512_SUPPORT
+      87                 :            :         SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_512,
+      88                 :            :     #endif
+      89                 :            :     #if LIBSPDM_SHA3_384_SUPPORT
+      90                 :            :         SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_384,
+      91                 :            :     #endif
+      92                 :            :     #if LIBSPDM_SHA3_256_SUPPORT
+      93                 :            :         SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_256,
+      94                 :            :     #endif
+      95                 :            :     #if LIBSPDM_SM3_256_SUPPORT
+      96                 :            :         SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SM3_256,
+      97                 :            :     #endif
+      98                 :            :         0,
+      99                 :            :     };
+     100                 :            : 
+     101                 :         42 :     uint32_t asym_priority_table[] = {
+     102                 :            :     #if LIBSPDM_ECDSA_P521_SUPPORT
+     103                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521,
+     104                 :            :     #endif
+     105                 :            :     #if LIBSPDM_ECDSA_P384_SUPPORT
+     106                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384,
+     107                 :            :     #endif
+     108                 :            :     #if LIBSPDM_ECDSA_P256_SUPPORT
+     109                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256,
+     110                 :            :     #endif
+     111                 :            :     #if LIBSPDM_RSA_PSS_4096_SUPPORT
+     112                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096,
+     113                 :            :     #endif
+     114                 :            :     #if LIBSPDM_RSA_PSS_3072_SUPPORT
+     115                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072,
+     116                 :            :     #endif
+     117                 :            :     #if LIBSPDM_RSA_PSS_2048_SUPPORT
+     118                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048,
+     119                 :            :     #endif
+     120                 :            :     #if LIBSPDM_RSA_SSA_4096_SUPPORT
+     121                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096,
+     122                 :            :     #endif
+     123                 :            :     #if LIBSPDM_RSA_SSA_3072_SUPPORT
+     124                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072,
+     125                 :            :     #endif
+     126                 :            :     #if LIBSPDM_RSA_SSA_2048_SUPPORT
+     127                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048,
+     128                 :            :     #endif
+     129                 :            :     #if LIBSPDM_EDDSA_ED448_SUPPORT
+     130                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448,
+     131                 :            :     #endif
+     132                 :            :     #if LIBSPDM_EDDSA_ED25519_SUPPORT
+     133                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519,
+     134                 :            :     #endif
+     135                 :            :     #if LIBSPDM_SM2_DSA_P256_SUPPORT
+     136                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256,
+     137                 :            :     #endif
+     138                 :            :         0,
+     139                 :            :     };
+     140                 :            : 
+     141                 :         42 :     uint32_t req_asym_priority_table[] = {
+     142                 :            :     #if LIBSPDM_ECDSA_P521_SUPPORT
+     143                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521,
+     144                 :            :     #endif
+     145                 :            :     #if LIBSPDM_ECDSA_P384_SUPPORT
+     146                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384,
+     147                 :            :     #endif
+     148                 :            :     #if LIBSPDM_ECDSA_P256_SUPPORT
+     149                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256,
+     150                 :            :     #endif
+     151                 :            :     #if LIBSPDM_RSA_PSS_4096_SUPPORT
+     152                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096,
+     153                 :            :     #endif
+     154                 :            :     #if LIBSPDM_RSA_PSS_3072_SUPPORT
+     155                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072,
+     156                 :            :     #endif
+     157                 :            :     #if LIBSPDM_RSA_PSS_2048_SUPPORT
+     158                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048,
+     159                 :            :     #endif
+     160                 :            :     #if LIBSPDM_RSA_SSA_4096_SUPPORT
+     161                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096,
+     162                 :            :     #endif
+     163                 :            :     #if LIBSPDM_RSA_SSA_3072_SUPPORT
+     164                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072,
+     165                 :            :     #endif
+     166                 :            :     #if LIBSPDM_RSA_SSA_2048_SUPPORT
+     167                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048,
+     168                 :            :     #endif
+     169                 :            :     #if LIBSPDM_EDDSA_ED448_SUPPORT
+     170                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448,
+     171                 :            :     #endif
+     172                 :            :     #if LIBSPDM_EDDSA_ED25519_SUPPORT
+     173                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519,
+     174                 :            :     #endif
+     175                 :            :     #if LIBSPDM_SM2_DSA_P256_SUPPORT
+     176                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256,
+     177                 :            :     #endif
+     178                 :            :         0,
+     179                 :            :     };
+     180                 :            : 
+     181                 :         42 :     uint32_t dhe_priority_table[] = {
+     182                 :            :     #if LIBSPDM_ECDHE_P521_SUPPORT
+     183                 :            :         SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_521_R1,
+     184                 :            :     #endif
+     185                 :            :     #if LIBSPDM_ECDHE_P384_SUPPORT
+     186                 :            :         SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_384_R1,
+     187                 :            :     #endif
+     188                 :            :     #if LIBSPDM_ECDHE_P256_SUPPORT
+     189                 :            :         SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_256_R1,
+     190                 :            :     #endif
+     191                 :            :     #if LIBSPDM_FFDHE_4096_SUPPORT
+     192                 :            :         SPDM_ALGORITHMS_DHE_NAMED_GROUP_FFDHE_4096,
+     193                 :            :     #endif
+     194                 :            :     #if LIBSPDM_FFDHE_3072_SUPPORT
+     195                 :            :         SPDM_ALGORITHMS_DHE_NAMED_GROUP_FFDHE_3072,
+     196                 :            :     #endif
+     197                 :            :     #if LIBSPDM_FFDHE_2048_SUPPORT
+     198                 :            :         SPDM_ALGORITHMS_DHE_NAMED_GROUP_FFDHE_2048,
+     199                 :            :     #endif
+     200                 :            :     #if LIBSPDM_SM2_KEY_EXCHANGE_SUPPORT
+     201                 :            :         SPDM_ALGORITHMS_DHE_NAMED_GROUP_SM2_P256,
+     202                 :            :     #endif
+     203                 :            :         0,
+     204                 :            :     };
+     205                 :            : 
+     206                 :         42 :     uint32_t aead_priority_table[] = {
+     207                 :            :     #if LIBSPDM_AEAD_AES_256_GCM_SUPPORT
+     208                 :            :         SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_256_GCM,
+     209                 :            :     #endif
+     210                 :            :     #if LIBSPDM_AEAD_AES_128_GCM_SUPPORT
+     211                 :            :         SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_128_GCM,
+     212                 :            :     #endif
+     213                 :            :     #if LIBSPDM_AEAD_CHACHA20_POLY1305_SUPPORT
+     214                 :            :         SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_CHACHA20_POLY1305,
+     215                 :            :     #endif
+     216                 :            :     #if LIBSPDM_AEAD_SM4_128_GCM_SUPPORT
+     217                 :            :         SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AEAD_SM4_GCM,
+     218                 :            :     #endif
+     219                 :            :         0,
+     220                 :            :     };
+     221                 :            : 
+     222                 :         42 :     uint32_t key_schedule_priority_table[] = {
+     223                 :            :         SPDM_ALGORITHMS_KEY_SCHEDULE_HMAC_HASH,
+     224                 :            :     };
+     225                 :            : 
+     226                 :         42 :     uint32_t measurement_hash_priority_table[] = {
+     227                 :            :     #if LIBSPDM_SHA512_SUPPORT
+     228                 :            :         SPDM_ALGORITHMS_MEASUREMENT_HASH_ALGO_TPM_ALG_SHA_512,
+     229                 :            :     #endif
+     230                 :            :     #if LIBSPDM_SHA384_SUPPORT
+     231                 :            :         SPDM_ALGORITHMS_MEASUREMENT_HASH_ALGO_TPM_ALG_SHA_384,
+     232                 :            :     #endif
+     233                 :            :     #if LIBSPDM_SHA256_SUPPORT
+     234                 :            :         SPDM_ALGORITHMS_MEASUREMENT_HASH_ALGO_TPM_ALG_SHA_256,
+     235                 :            :     #endif
+     236                 :            :     #if LIBSPDM_SHA3_512_SUPPORT
+     237                 :            :         SPDM_ALGORITHMS_MEASUREMENT_HASH_ALGO_TPM_ALG_SHA3_512,
+     238                 :            :     #endif
+     239                 :            :     #if LIBSPDM_SHA3_384_SUPPORT
+     240                 :            :         SPDM_ALGORITHMS_MEASUREMENT_HASH_ALGO_TPM_ALG_SHA3_384,
+     241                 :            :     #endif
+     242                 :            :     #if LIBSPDM_SHA3_256_SUPPORT
+     243                 :            :         SPDM_ALGORITHMS_MEASUREMENT_HASH_ALGO_TPM_ALG_SHA3_256,
+     244                 :            :     #endif
+     245                 :            :     #if LIBSPDM_SM3_256_SUPPORT
+     246                 :            :         SPDM_ALGORITHMS_MEASUREMENT_HASH_ALGO_TPM_ALG_SM3_256,
+     247                 :            :     #endif
+     248                 :            :         SPDM_ALGORITHMS_MEASUREMENT_HASH_ALGO_RAW_BIT_STREAM_ONLY,
+     249                 :            :     };
+     250                 :            : 
+     251                 :         42 :     uint32_t measurement_spec_priority_table[] = {
+     252                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF,
+     253                 :            :     };
+     254                 :            : 
+     255                 :         42 :     uint32_t other_params_support_priority_table[] = {
+     256                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1,
+     257                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_0,
+     258                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_NONE
+     259                 :            :     };
+     260                 :            : 
+     261                 :         42 :     uint32_t mel_spec_priority_table[] = {
+     262                 :            :         SPDM_MEL_SPECIFICATION_DMTF,
+     263                 :            :     };
+     264                 :            : 
+     265                 :         42 :     spdm_request = request;
+     266                 :            : 
+     267                 :         42 :     ext_alg_total_count = 0;
+     268                 :            : 
+     269                 :            :     /* -=[Check Parameters Phase]=- */
+     270         [ -  + ]:         42 :     LIBSPDM_ASSERT(spdm_request->header.request_response_code == SPDM_NEGOTIATE_ALGORITHMS);
+     271         [ -  + ]:         42 :     LIBSPDM_ASSERT(!(((spdm_context->local_context.capability.flags &
+     272                 :            :                        SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP) == 0) ^
+     273                 :            :                      (spdm_context->local_context.algorithm.measurement_spec == 0)));
+     274         [ -  + ]:         42 :     LIBSPDM_ASSERT(!(((spdm_context->local_context.capability.flags &
+     275                 :            :                        SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP) == 0) ^
+     276                 :            :                      (spdm_context->local_context.algorithm.measurement_hash_algo == 0)));
+     277                 :            : 
+     278                 :            :     /* -=[Verify State Phase]=- */
+     279         [ +  + ]:         42 :     if (spdm_context->response_state != LIBSPDM_RESPONSE_STATE_NORMAL) {
+     280                 :          2 :         return libspdm_responder_handle_response_state(
+     281                 :            :             spdm_context,
+     282                 :          2 :             spdm_request->header.request_response_code,
+     283                 :            :             response_size, response);
+     284                 :            :     }
+     285         [ +  + ]:         40 :     if (spdm_context->connection_info.connection_state !=
+     286                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES) {
+     287                 :          1 :         return libspdm_generate_error_response(spdm_context,
+     288                 :            :                                                SPDM_ERROR_CODE_UNEXPECTED_REQUEST,
+     289                 :            :                                                0, response_size, response);
+     290                 :            :     }
+     291                 :            : 
+     292                 :            :     /* -=[Validate Request Phase]=- */
+     293         [ -  + ]:         39 :     if (spdm_request->header.spdm_version != libspdm_get_connection_version(spdm_context)) {
+     294                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     295                 :            :                                                SPDM_ERROR_CODE_VERSION_MISMATCH, 0,
+     296                 :            :                                                response_size, response);
+     297                 :            :     }
+     298         [ +  + ]:         39 :     if (request_size < sizeof(spdm_negotiate_algorithms_request_t)) {
+     299                 :          1 :         return libspdm_generate_error_response(spdm_context,
+     300                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     301                 :            :                                                response_size, response);
+     302                 :            :     }
+     303                 :         38 :     if (request_size <
+     304                 :            :         sizeof(spdm_negotiate_algorithms_request_t) +
+     305                 :         38 :         sizeof(uint32_t) * spdm_request->ext_asym_count +
+     306                 :         38 :         sizeof(uint32_t) * spdm_request->ext_hash_count +
+     307         [ +  + ]:         38 :         sizeof(spdm_negotiate_algorithms_common_struct_table_t) * spdm_request->header.param1) {
+     308                 :          1 :         return libspdm_generate_error_response(spdm_context,
+     309                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     310                 :            :                                                response_size, response);
+     311                 :            :     }
+     312                 :         37 :     struct_table = (void *)((size_t)spdm_request +
+     313                 :         37 :                             sizeof(spdm_negotiate_algorithms_request_t) +
+     314                 :         37 :                             sizeof(uint32_t) * spdm_request->ext_asym_count +
+     315                 :         37 :                             sizeof(uint32_t) * spdm_request->ext_hash_count);
+     316         [ +  + ]:         37 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_11) {
+     317                 :         33 :         alg_type_pre = struct_table->alg_type;
+     318         [ +  + ]:        124 :         for (index = 0; index < spdm_request->header.param1; index++) {
+     319         [ -  + ]:         97 :             if ((size_t)spdm_request + request_size < (size_t)struct_table) {
+     320                 :          0 :                 return libspdm_generate_error_response(
+     321                 :            :                     spdm_context,
+     322                 :            :                     SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     323                 :            :                     response_size, response);
+     324                 :            :             }
+     325         [ -  + ]:         97 :             if ((size_t)spdm_request + request_size - (size_t)struct_table <
+     326                 :            :                 sizeof(spdm_negotiate_algorithms_common_struct_table_t)) {
+     327                 :          0 :                 return libspdm_generate_error_response(
+     328                 :            :                     spdm_context,
+     329                 :            :                     SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     330                 :            :                     response_size, response);
+     331                 :            :             }
+     332         [ +  + ]:         97 :             if ((struct_table->alg_type < SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE) ||
+     333         [ +  + ]:         96 :                 (struct_table->alg_type >
+     334                 :            :                  SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE)) {
+     335                 :          3 :                 return libspdm_generate_error_response(
+     336                 :            :                     spdm_context,
+     337                 :            :                     SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     338                 :            :                     response_size, response);
+     339                 :            :             }
+     340                 :            :             /* AlgType shall monotonically increase for subsequent entries. */
+     341   [ +  +  +  + ]:         94 :             if ((index != 0) && (struct_table->alg_type <= alg_type_pre)) {
+     342                 :          3 :                 return libspdm_generate_error_response(
+     343                 :            :                     spdm_context,
+     344                 :            :                     SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     345                 :            :                     response_size, response);
+     346                 :            :             }
+     347                 :         91 :             alg_type_pre = struct_table->alg_type;
+     348                 :         91 :             fixed_alg_size = (struct_table->alg_count >> 4) & 0xF;
+     349                 :         91 :             ext_alg_count = struct_table->alg_count & 0xF;
+     350                 :         91 :             ext_alg_total_count += ext_alg_count;
+     351         [ -  + ]:         91 :             if (fixed_alg_size != 2) {
+     352                 :          0 :                 return libspdm_generate_error_response(
+     353                 :            :                     spdm_context,
+     354                 :            :                     SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     355                 :            :                     response_size, response);
+     356                 :            :             }
+     357                 :         91 :             if ((size_t)spdm_request + request_size - (size_t)struct_table -
+     358                 :            :                 sizeof(spdm_negotiate_algorithms_common_struct_table_t) <
+     359         [ -  + ]:         91 :                 sizeof(uint32_t) * ext_alg_count) {
+     360                 :          0 :                 return libspdm_generate_error_response(
+     361                 :            :                     spdm_context,
+     362                 :            :                     SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     363                 :            :                     response_size, response);
+     364                 :            :             }
+     365                 :         91 :             struct_table =
+     366                 :         91 :                 (void *)((size_t)struct_table +
+     367                 :         91 :                          sizeof(spdm_negotiate_algorithms_common_struct_table_t) +
+     368                 :         91 :                          sizeof(uint32_t) * ext_alg_count);
+     369                 :            :         }
+     370                 :            :     }
+     371                 :         31 :     ext_alg_total_count += (spdm_request->ext_asym_count + spdm_request->ext_hash_count);
+     372                 :            :     /* Algorithm count check and message size check*/
+     373         [ +  + ]:         31 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_11) {
+     374         [ +  + ]:         27 :         if (ext_alg_total_count > SPDM_NEGOTIATE_ALGORITHMS_REQUEST_MAX_EXT_ALG_COUNT_VERSION_11) {
+     375                 :          1 :             return libspdm_generate_error_response(
+     376                 :            :                 spdm_context,
+     377                 :            :                 SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     378                 :            :                 response_size, response);
+     379                 :            :         }
+     380         [ -  + ]:         26 :         if (spdm_request->length > SPDM_NEGOTIATE_ALGORITHMS_REQUEST_MAX_LENGTH_VERSION_11) {
+     381                 :          0 :             return libspdm_generate_error_response(
+     382                 :            :                 spdm_context,
+     383                 :            :                 SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     384                 :            :                 response_size, response);
+     385                 :            :         }
+     386                 :            :     } else {
+     387         [ +  + ]:          4 :         if (ext_alg_total_count > SPDM_NEGOTIATE_ALGORITHMS_REQUEST_MAX_EXT_ALG_COUNT_VERSION_10) {
+     388                 :          1 :             return libspdm_generate_error_response(
+     389                 :            :                 spdm_context,
+     390                 :            :                 SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     391                 :            :                 response_size, response);
+     392                 :            :         }
+     393         [ -  + ]:          3 :         if (spdm_request->length > SPDM_NEGOTIATE_ALGORITHMS_REQUEST_MAX_LENGTH_VERSION_10) {
+     394                 :          0 :             return libspdm_generate_error_response(
+     395                 :            :                 spdm_context,
+     396                 :            :                 SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     397                 :            :                 response_size, response);
+     398                 :            :         }
+     399                 :            :     }
+     400                 :            : 
+     401                 :         29 :     request_size = (size_t)struct_table - (size_t)spdm_request;
+     402         [ -  + ]:         29 :     if (request_size != spdm_request->length) {
+     403                 :          0 :         return libspdm_generate_error_response(
+     404                 :            :             spdm_context,
+     405                 :            :             SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     406                 :            :             response_size, response);
+     407                 :            :     }
+     408                 :         29 :     spdm_request_size = request_size;
+     409                 :            : 
+     410                 :         29 :     libspdm_reset_message_buffer_via_request_code(spdm_context, NULL,
+     411                 :         29 :                                                   spdm_request->header.request_response_code);
+     412                 :            : 
+     413                 :            :     /* -=[Construct Response Phase]=- */
+     414         [ -  + ]:         29 :     LIBSPDM_ASSERT(*response_size >= sizeof(libspdm_algorithms_response_mine_t));
+     415                 :         29 :     *response_size = sizeof(libspdm_algorithms_response_mine_t);
+     416                 :         29 :     libspdm_zero_mem(response, *response_size);
+     417                 :         29 :     spdm_response = response;
+     418                 :            : 
+     419                 :         29 :     spdm_response->header.spdm_version = spdm_request->header.spdm_version;
+     420         [ +  + ]:         29 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_11) {
+     421                 :            :         /* Number of Algorithms Structure Tables */
+     422                 :         26 :         spdm_response->header.param1 = spdm_request->header.param1;
+     423                 :            :         /* Respond with only the same amount of Algorithms Structure Tables as requested */
+     424                 :         26 :         *response_size = sizeof(libspdm_algorithms_response_mine_t) -
+     425                 :         26 :                          ((SPDM_NEGOTIATE_ALGORITHMS_MAX_NUM_STRUCT_TABLE_ALG  -
+     426                 :         26 :                            spdm_request->header.param1) *
+     427                 :            :                           sizeof(spdm_negotiate_algorithms_common_struct_table_t));
+     428                 :            :     } else {
+     429                 :          3 :         spdm_response->header.param1 = 0;
+     430                 :          3 :         *response_size =
+     431                 :            :             sizeof(libspdm_algorithms_response_mine_t) -
+     432                 :            :             (sizeof(spdm_negotiate_algorithms_common_struct_table_t) *
+     433                 :            :              SPDM_NEGOTIATE_ALGORITHMS_MAX_NUM_STRUCT_TABLE_ALG);
+     434                 :            :     }
+     435                 :         29 :     spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     436                 :         29 :     spdm_response->header.param2 = 0;
+     437                 :         29 :     spdm_response->length = (uint16_t)*response_size;
+     438                 :            : 
+     439                 :         29 :     spdm_context->connection_info.algorithm.measurement_spec =
+     440                 :         29 :         spdm_request->measurement_specification;
+     441         [ +  + ]:         29 :     if (spdm_request->measurement_specification != 0) {
+     442                 :         27 :         spdm_context->connection_info.algorithm.measurement_hash_algo =
+     443                 :         27 :             spdm_context->local_context.algorithm.measurement_hash_algo;
+     444                 :            :     } else {
+     445                 :          2 :         spdm_context->connection_info.algorithm.measurement_hash_algo = 0;
+     446                 :            :     }
+     447                 :         29 :     spdm_context->connection_info.algorithm.base_asym_algo = spdm_request->base_asym_algo;
+     448                 :         29 :     spdm_context->connection_info.algorithm.base_hash_algo = spdm_request->base_hash_algo;
+     449         [ +  + ]:         29 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_11) {
+     450                 :         26 :         struct_table =
+     451                 :         26 :             (void *)((size_t)spdm_request +
+     452                 :         26 :                      sizeof(spdm_negotiate_algorithms_request_t) +
+     453                 :         26 :                      sizeof(uint32_t) * spdm_request->ext_asym_count +
+     454                 :         26 :                      sizeof(uint32_t) * spdm_request->ext_hash_count);
+     455         [ +  + ]:         94 :         for (index = 0; index < spdm_request->header.param1; index++) {
+     456   [ +  +  +  +  :         69 :             switch (struct_table->alg_type) {
+                      - ]
+     457                 :         18 :             case SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE:
+     458         [ -  + ]:         18 :                 if (struct_table->alg_supported == 0) {
+     459                 :          0 :                     return libspdm_generate_error_response(
+     460                 :            :                         spdm_context, SPDM_ERROR_CODE_INVALID_REQUEST,
+     461                 :            :                         0, response_size, response);
+     462                 :            :                 }
+     463                 :            : 
+     464                 :         18 :                 spdm_context->connection_info.algorithm.dhe_named_group =
+     465                 :         18 :                     struct_table->alg_supported;
+     466                 :         18 :                 spdm_response->struct_table[index].alg_type =
+     467                 :            :                     SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE;
+     468                 :         18 :                 spdm_response->struct_table[index].alg_count = 0x20;
+     469                 :         18 :                 spdm_response->struct_table[index].alg_supported =
+     470                 :         36 :                     (uint16_t)libspdm_prioritize_algorithm(
+     471                 :            :                         dhe_priority_table, LIBSPDM_ARRAY_SIZE(dhe_priority_table),
+     472                 :         18 :                         spdm_context->local_context.algorithm.dhe_named_group,
+     473                 :         18 :                         spdm_context->connection_info.algorithm.dhe_named_group);
+     474                 :         18 :                 break;
+     475                 :         18 :             case SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD:
+     476         [ +  + ]:         18 :                 if (struct_table->alg_supported == 0) {
+     477                 :          1 :                     return libspdm_generate_error_response(
+     478                 :            :                         spdm_context, SPDM_ERROR_CODE_INVALID_REQUEST,
+     479                 :            :                         0, response_size, response);
+     480                 :            :                 }
+     481                 :            : 
+     482                 :         17 :                 spdm_context->connection_info.algorithm.aead_cipher_suite =
+     483                 :         17 :                     struct_table->alg_supported;
+     484                 :         17 :                 spdm_response->struct_table[index].alg_type =
+     485                 :            :                     SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD;
+     486                 :         17 :                 spdm_response->struct_table[index].alg_count = 0x20;
+     487                 :         17 :                 spdm_response->struct_table[index].alg_supported =
+     488                 :         34 :                     (uint16_t)libspdm_prioritize_algorithm(
+     489                 :            :                         aead_priority_table, LIBSPDM_ARRAY_SIZE(aead_priority_table),
+     490                 :         17 :                         spdm_context->local_context.algorithm.aead_cipher_suite,
+     491                 :         17 :                         spdm_context->connection_info.algorithm.aead_cipher_suite);
+     492                 :         17 :                 break;
+     493                 :         17 :             case SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG:
+     494         [ -  + ]:         17 :                 if (struct_table->alg_supported == 0) {
+     495                 :          0 :                     return libspdm_generate_error_response(
+     496                 :            :                         spdm_context, SPDM_ERROR_CODE_INVALID_REQUEST,
+     497                 :            :                         0, response_size, response);
+     498                 :            :                 }
+     499                 :            : 
+     500                 :         17 :                 spdm_context->connection_info.algorithm.req_base_asym_alg =
+     501                 :         17 :                     struct_table->alg_supported;
+     502                 :         17 :                 spdm_response->struct_table[index].alg_type =
+     503                 :            :                     SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG;
+     504                 :         17 :                 spdm_response->struct_table[index].alg_count = 0x20;
+     505                 :         17 :                 spdm_response->struct_table[index].alg_supported =
+     506                 :         34 :                     (uint16_t)libspdm_prioritize_algorithm(
+     507                 :            :                         req_asym_priority_table,
+     508                 :            :                         LIBSPDM_ARRAY_SIZE(req_asym_priority_table),
+     509                 :         17 :                         spdm_context->local_context.algorithm.req_base_asym_alg,
+     510                 :         17 :                         spdm_context->connection_info.algorithm.req_base_asym_alg);
+     511                 :         17 :                 break;
+     512                 :         16 :             case SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE:
+     513         [ -  + ]:         16 :                 if (struct_table->alg_supported == 0) {
+     514                 :          0 :                     return libspdm_generate_error_response(
+     515                 :            :                         spdm_context, SPDM_ERROR_CODE_INVALID_REQUEST,
+     516                 :            :                         0, response_size, response);
+     517                 :            :                 }
+     518                 :            : 
+     519                 :         16 :                 spdm_context->connection_info.algorithm.key_schedule =
+     520                 :         16 :                     struct_table->alg_supported;
+     521                 :         16 :                 spdm_response->struct_table[index].alg_type =
+     522                 :            :                     SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE;
+     523                 :         16 :                 spdm_response->struct_table[index].alg_count = 0x20;
+     524                 :         16 :                 spdm_response->struct_table[index].alg_supported =
+     525                 :         32 :                     (uint16_t)libspdm_prioritize_algorithm(
+     526                 :            :                         key_schedule_priority_table,
+     527                 :            :                         LIBSPDM_ARRAY_SIZE(key_schedule_priority_table),
+     528                 :         16 :                         spdm_context->local_context.algorithm.key_schedule,
+     529                 :         16 :                         spdm_context->connection_info.algorithm.key_schedule);
+     530                 :         16 :                 break;
+     531                 :          0 :             default:
+     532                 :            :                 /* Unknown algorithm types do not need to be processed */
+     533                 :          0 :                 break;
+     534                 :            :             }
+     535                 :         68 :             ext_alg_count = struct_table->alg_count & 0xF;
+     536                 :         68 :             struct_table =
+     537                 :         68 :                 (void *)((size_t)struct_table +
+     538                 :         68 :                          sizeof(spdm_negotiate_algorithms_common_struct_table_t) +
+     539                 :         68 :                          sizeof(uint32_t) * ext_alg_count);
+     540                 :            :         }
+     541                 :            :     }
+     542         [ +  + ]:         28 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_12) {
+     543                 :         15 :         spdm_context->connection_info.algorithm.other_params_support =
+     544                 :         15 :             spdm_request->other_params_support & SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_MASK;
+     545         [ +  + ]:         15 :         if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
+     546                 :          8 :             spdm_context->connection_info.algorithm.other_params_support =
+     547                 :          8 :                 spdm_request->other_params_support;
+     548                 :          8 :             spdm_context->connection_info.algorithm.mel_spec =
+     549                 :          8 :                 spdm_request->mel_specification;
+     550                 :            :         }
+     551                 :            :     }
+     552                 :            : 
+     553         [ +  + ]:         28 :     if (libspdm_is_capabilities_flag_supported(
+     554                 :            :             spdm_context, false, 0,
+     555                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP)) {
+     556                 :          2 :         spdm_response->measurement_specification_sel = (uint8_t)libspdm_prioritize_algorithm(
+     557                 :            :             measurement_spec_priority_table,
+     558                 :            :             LIBSPDM_ARRAY_SIZE(measurement_spec_priority_table),
+     559                 :          2 :             spdm_context->local_context.algorithm.measurement_spec,
+     560                 :          2 :             spdm_context->connection_info.algorithm.measurement_spec);
+     561                 :            :     } else {
+     562                 :         26 :         spdm_response->measurement_specification_sel = 0;
+     563                 :            :     }
+     564                 :            : 
+     565                 :         28 :     spdm_response->measurement_hash_algo = libspdm_prioritize_algorithm(
+     566                 :            :         measurement_hash_priority_table,
+     567                 :            :         LIBSPDM_ARRAY_SIZE(measurement_hash_priority_table),
+     568                 :            :         spdm_context->local_context.algorithm.measurement_hash_algo,
+     569                 :            :         spdm_context->connection_info.algorithm.measurement_hash_algo);
+     570                 :            : 
+     571                 :         28 :     spdm_response->base_asym_sel = libspdm_prioritize_algorithm(
+     572                 :            :         asym_priority_table, LIBSPDM_ARRAY_SIZE(asym_priority_table),
+     573                 :            :         spdm_context->local_context.algorithm.base_asym_algo,
+     574                 :            :         spdm_context->connection_info.algorithm.base_asym_algo);
+     575                 :            : 
+     576                 :         28 :     spdm_response->base_hash_sel = libspdm_prioritize_algorithm(
+     577                 :            :         hash_priority_table, LIBSPDM_ARRAY_SIZE(hash_priority_table),
+     578                 :            :         spdm_context->local_context.algorithm.base_hash_algo,
+     579                 :            :         spdm_context->connection_info.algorithm.base_hash_algo);
+     580                 :            : 
+     581                 :            : 
+     582         [ +  + ]:         28 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_12) {
+     583                 :         30 :         spdm_response->other_params_selection = (uint8_t)libspdm_prioritize_algorithm(
+     584                 :            :             other_params_support_priority_table,
+     585                 :            :             LIBSPDM_ARRAY_SIZE(other_params_support_priority_table),
+     586                 :         15 :             spdm_context->local_context.algorithm.other_params_support &
+     587                 :            :             SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_MASK,
+     588                 :         15 :             spdm_context->connection_info.algorithm.other_params_support &
+     589                 :            :             SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_MASK);
+     590         [ +  + ]:         15 :         if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
+     591         [ +  + ]:          8 :             if (libspdm_is_capabilities_flag_supported(
+     592                 :            :                     spdm_context, false, 0,
+     593                 :            :                     SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEL_CAP)) {
+     594                 :          1 :                 spdm_response->mel_specification_sel = (uint8_t)libspdm_prioritize_algorithm(
+     595                 :            :                     mel_spec_priority_table,
+     596                 :            :                     LIBSPDM_ARRAY_SIZE(mel_spec_priority_table),
+     597                 :          1 :                     spdm_context->local_context.algorithm.mel_spec,
+     598                 :          1 :                     spdm_context->connection_info.algorithm.mel_spec);
+     599                 :            :             } else {
+     600                 :          7 :                 spdm_response->mel_specification_sel = 0;
+     601                 :            :             }
+     602                 :            :         }
+     603                 :            :     }
+     604                 :            : 
+     605         [ +  + ]:         28 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
+     606   [ +  +  +  - ]:          8 :         switch (spdm_context->connection_info.capability.flags &
+     607                 :            :                 SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MULTI_KEY_CAP) {
+     608                 :          2 :         case 0:
+     609                 :          2 :             spdm_context->connection_info.multi_key_conn_req = false;
+     610                 :          2 :             break;
+     611                 :          2 :         case SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MULTI_KEY_CAP_ONLY:
+     612                 :          2 :             spdm_context->connection_info.multi_key_conn_req = true;
+     613                 :          2 :             break;
+     614                 :          4 :         case SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MULTI_KEY_CAP_NEG:
+     615         [ +  + ]:          4 :             if ((spdm_context->local_context.algorithm.other_params_support &
+     616                 :            :                  SPDM_ALGORITHMS_MULTI_KEY_CONN) == 0) {
+     617                 :          3 :                 spdm_context->connection_info.multi_key_conn_req = false;
+     618                 :            :             } else {
+     619                 :          1 :                 spdm_context->connection_info.multi_key_conn_req = true;
+     620                 :            :             }
+     621                 :          4 :             break;
+     622                 :          0 :         default:
+     623                 :          0 :             return libspdm_generate_error_response(
+     624                 :            :                 spdm_context, SPDM_ERROR_CODE_INVALID_REQUEST,
+     625                 :            :                 0, response_size, response);
+     626                 :            :         }
+     627         [ +  + ]:          8 :         if (spdm_context->connection_info.multi_key_conn_req) {
+     628                 :          3 :             spdm_response->other_params_selection |= SPDM_ALGORITHMS_MULTI_KEY_CONN;
+     629                 :            :         } else {
+     630                 :          5 :             spdm_response->other_params_selection &= ~SPDM_ALGORITHMS_MULTI_KEY_CONN;
+     631                 :            :         }
+     632                 :            :     }
+     633                 :            : 
+     634                 :         28 :     spdm_context->connection_info.algorithm.measurement_spec =
+     635                 :         28 :         spdm_response->measurement_specification_sel;
+     636                 :         28 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     637                 :         28 :         spdm_response->measurement_hash_algo;
+     638                 :         28 :     spdm_context->connection_info.algorithm.base_asym_algo = spdm_response->base_asym_sel;
+     639                 :         28 :     spdm_context->connection_info.algorithm.base_hash_algo = spdm_response->base_hash_sel;
+     640                 :            : 
+     641         [ +  + ]:         28 :     if (libspdm_is_capabilities_flag_supported(
+     642                 :            :             spdm_context, false, 0,
+     643                 :          2 :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP) &&
+     644         [ +  + ]:          2 :         (spdm_request->measurement_specification != 0)) {
+     645         [ -  + ]:          1 :         if (spdm_context->connection_info.algorithm.measurement_spec !=
+     646                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF) {
+     647                 :          0 :             return libspdm_generate_error_response(
+     648                 :            :                 spdm_context, SPDM_ERROR_CODE_INVALID_REQUEST,
+     649                 :            :                 0, response_size, response);
+     650                 :            :         }
+     651                 :          1 :         algo_size = libspdm_get_measurement_hash_size(
+     652                 :            :             spdm_context->connection_info.algorithm.measurement_hash_algo);
+     653         [ -  + ]:          1 :         if (algo_size == 0) {
+     654                 :          0 :             return libspdm_generate_error_response(
+     655                 :            :                 spdm_context, SPDM_ERROR_CODE_INVALID_REQUEST,
+     656                 :            :                 0, response_size, response);
+     657                 :            :         }
+     658                 :            :     }
+     659                 :            : 
+     660         [ +  - ]:         28 :     if (libspdm_is_capabilities_flag_supported(
+     661                 :            :             spdm_context, false, 0,
+     662         [ +  + ]:         28 :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP) ||
+     663                 :         28 :         libspdm_is_capabilities_flag_supported(
+     664                 :            :             spdm_context, false, 0,
+     665         [ +  + ]:         19 :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP) ||
+     666                 :         19 :         libspdm_is_capabilities_flag_supported(
+     667                 :            :             spdm_context, false, 0,
+     668         [ +  + ]:         17 :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG) ||
+     669                 :         17 :         libspdm_is_capabilities_flag_supported(
+     670                 :            :             spdm_context, false,
+     671                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP,
+     672         [ -  + ]:         10 :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP) ||
+     673                 :         10 :         libspdm_is_capabilities_flag_supported(
+     674                 :            :             spdm_context, false,
+     675                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP,
+     676                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP)) {
+     677                 :         18 :         algo_size = libspdm_get_hash_size(
+     678                 :            :             spdm_context->connection_info.algorithm.base_hash_algo);
+     679         [ +  + ]:         18 :         if (algo_size == 0) {
+     680                 :          1 :             return libspdm_generate_error_response(
+     681                 :            :                 spdm_context,
+     682                 :            :                 SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     683                 :            :                 response_size, response);
+     684                 :            :         }
+     685                 :            :     }
+     686                 :            : 
+     687         [ +  - ]:         27 :     if (libspdm_is_capabilities_flag_supported(
+     688                 :            :             spdm_context, false, 0,
+     689         [ +  + ]:         27 :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP) ||
+     690                 :         27 :         libspdm_is_capabilities_flag_supported(
+     691                 :            :             spdm_context, false, 0,
+     692         [ +  + ]:         19 :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP) ||
+     693                 :         19 :         libspdm_is_capabilities_flag_supported(
+     694                 :            :             spdm_context, false, 0,
+     695         [ +  + ]:         17 :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG) ||
+     696                 :         17 :         libspdm_is_capabilities_flag_supported(
+     697                 :            :             spdm_context, false,
+     698                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP,
+     699                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP)) {
+     700                 :         17 :         algo_size = libspdm_get_asym_signature_size(
+     701                 :            :             spdm_context->connection_info.algorithm.base_asym_algo);
+     702         [ +  + ]:         17 :         if (algo_size == 0) {
+     703                 :          1 :             return libspdm_generate_error_response(
+     704                 :            :                 spdm_context, SPDM_ERROR_CODE_INVALID_REQUEST,
+     705                 :            :                 0, response_size, response);
+     706                 :            :         }
+     707                 :            :     }
+     708                 :            : 
+     709                 :            :     /* -=[Process Request Phase]=- */
+     710         [ +  + ]:         26 :     if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_11) {
+     711         [ +  + ]:         82 :         for (index = 0; index < spdm_response->header.param1; ++index) {
+     712   [ +  +  +  +  :         59 :             switch(spdm_response->struct_table[index].alg_type) {
+                      - ]
+     713                 :         15 :             case SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE:
+     714                 :         15 :                 spdm_context->connection_info.algorithm.dhe_named_group =
+     715                 :         15 :                     spdm_response->struct_table[index].alg_supported;
+     716                 :         15 :                 break;
+     717                 :         15 :             case SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD:
+     718                 :         15 :                 spdm_context->connection_info.algorithm.aead_cipher_suite =
+     719                 :         15 :                     spdm_response->struct_table[index].alg_supported;
+     720                 :         15 :                 break;
+     721                 :         15 :             case SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG:
+     722                 :         15 :                 spdm_context->connection_info.algorithm.req_base_asym_alg =
+     723                 :         15 :                     spdm_response->struct_table[index].alg_supported;
+     724                 :         15 :                 break;
+     725                 :         14 :             case SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE:
+     726                 :         14 :                 spdm_context->connection_info.algorithm.key_schedule =
+     727                 :         14 :                     spdm_response->struct_table[index].alg_supported;
+     728                 :         14 :                 break;
+     729                 :          0 :             default:
+     730                 :            :                 /* Unreachable */
+     731                 :          0 :                 LIBSPDM_ASSERT(false);
+     732                 :          0 :                 break;
+     733                 :            :             }
+     734                 :            :         }
+     735         [ +  + ]:         23 :         if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_12) {
+     736         [ +  + ]:         15 :             if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
+     737                 :          8 :                 spdm_context->connection_info.algorithm.other_params_support =
+     738                 :          8 :                     (spdm_context->connection_info.algorithm.other_params_support &
+     739                 :          8 :                      SPDM_ALGORITHMS_MULTI_KEY_CONN) |
+     740                 :          8 :                     (spdm_response->other_params_selection &
+     741                 :            :                      SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_MASK);
+     742                 :          8 :                 spdm_context->connection_info.algorithm.mel_spec =
+     743                 :          8 :                     spdm_response->mel_specification_sel;
+     744                 :            :             } else {
+     745                 :          7 :                 spdm_context->connection_info.algorithm.other_params_support =
+     746                 :          7 :                     (spdm_response->other_params_selection &
+     747                 :            :                      SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_MASK);
+     748                 :          7 :                 spdm_context->connection_info.algorithm.mel_spec = 0;
+     749                 :            :             }
+     750                 :            :         } else {
+     751                 :          8 :             spdm_context->connection_info.algorithm.other_params_support = 0;
+     752                 :            :         }
+     753                 :            : 
+     754         [ +  + ]:         23 :         if (libspdm_is_capabilities_flag_supported(
+     755                 :            :                 spdm_context, false,
+     756                 :            :                 SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP,
+     757                 :            :                 SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP)) {
+     758                 :         15 :             algo_size = libspdm_get_dhe_pub_key_size(
+     759                 :         15 :                 spdm_context->connection_info.algorithm.dhe_named_group);
+     760         [ +  + ]:         15 :             if (algo_size == 0) {
+     761                 :          1 :                 return libspdm_generate_error_response(
+     762                 :            :                     spdm_context,
+     763                 :            :                     SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     764                 :            :                     response_size, response);
+     765                 :            :             }
+     766                 :            :         }
+     767         [ +  + ]:         22 :         if (libspdm_is_capabilities_flag_supported(
+     768                 :            :                 spdm_context, false,
+     769                 :            :                 SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP,
+     770         [ -  + ]:          8 :                 SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP) ||
+     771                 :          8 :             libspdm_is_capabilities_flag_supported(
+     772                 :            :                 spdm_context, false,
+     773                 :            :                 SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP,
+     774                 :            :                 SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP)) {
+     775                 :         14 :             algo_size = libspdm_get_aead_key_size(
+     776                 :         14 :                 spdm_context->connection_info.algorithm.aead_cipher_suite);
+     777         [ +  + ]:         14 :             if (algo_size == 0) {
+     778                 :          1 :                 return libspdm_generate_error_response(
+     779                 :            :                     spdm_context,
+     780                 :            :                     SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     781                 :            :                     response_size, response);
+     782                 :            :             }
+     783                 :            :         }
+     784         [ +  + ]:         21 :         if (libspdm_is_capabilities_flag_supported(
+     785                 :            :                 spdm_context, false,
+     786                 :            :                 SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP,
+     787                 :            :                 SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP)) {
+     788                 :         13 :             algo_size = libspdm_get_req_asym_signature_size(
+     789                 :         13 :                 spdm_context->connection_info.algorithm.req_base_asym_alg);
+     790         [ +  + ]:         13 :             if (algo_size == 0) {
+     791                 :          1 :                 return libspdm_generate_error_response(
+     792                 :            :                     spdm_context,
+     793                 :            :                     SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     794                 :            :                     response_size, response);
+     795                 :            :             }
+     796                 :            :         }
+     797         [ +  + ]:         20 :         if (libspdm_is_capabilities_flag_supported(
+     798                 :            :                 spdm_context, false,
+     799                 :            :                 SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP,
+     800         [ -  + ]:          8 :                 SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP) ||
+     801                 :          8 :             libspdm_is_capabilities_flag_supported(
+     802                 :            :                 spdm_context, false,
+     803                 :            :                 SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP,
+     804                 :            :                 SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP)) {
+     805         [ +  + ]:         12 :             if (spdm_context->connection_info.algorithm.key_schedule !=
+     806                 :            :                 SPDM_ALGORITHMS_KEY_SCHEDULE_HMAC_HASH) {
+     807                 :          2 :                 return libspdm_generate_error_response(
+     808                 :            :                     spdm_context,
+     809                 :            :                     SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     810                 :            :                     response_size, response);
+     811                 :            :             }
+     812         [ +  + ]:         10 :             if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_12) {
+     813         [ +  + ]:          7 :                 if ((spdm_context->connection_info.algorithm.other_params_support &
+     814                 :            :                      SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_MASK) !=
+     815                 :            :                     SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1) {
+     816                 :          1 :                     return libspdm_generate_error_response(
+     817                 :            :                         spdm_context,
+     818                 :            :                         SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     819                 :            :                         response_size, response);
+     820                 :            :                 }
+     821                 :            :             }
+     822                 :            :         }
+     823                 :            : 
+     824         [ +  + ]:         17 :         if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
+     825         [ +  + ]:          8 :             if ((spdm_context->connection_info.algorithm.other_params_support &
+     826                 :            :                  SPDM_ALGORITHMS_MULTI_KEY_CONN) == 0) {
+     827         [ +  + ]:          5 :                 if ((spdm_context->local_context.capability.flags &
+     828                 :            :                      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MULTI_KEY_CAP) ==
+     829                 :            :                     SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MULTI_KEY_CAP_ONLY) {
+     830                 :          1 :                     return libspdm_generate_error_response(
+     831                 :            :                         spdm_context,
+     832                 :            :                         SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     833                 :            :                         response_size, response);
+     834                 :            :                 }
+     835                 :          4 :                 spdm_context->connection_info.multi_key_conn_rsp = false;
+     836                 :            :             } else {
+     837         [ +  + ]:          3 :                 if ((spdm_context->local_context.capability.flags &
+     838                 :            :                      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MULTI_KEY_CAP) == 0) {
+     839                 :          1 :                     return libspdm_generate_error_response(
+     840                 :            :                         spdm_context,
+     841                 :            :                         SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     842                 :            :                         response_size, response);
+     843                 :            :                 }
+     844                 :          2 :                 spdm_context->connection_info.multi_key_conn_rsp = true;
+     845                 :            :             }
+     846                 :            :         }
+     847                 :            :     } else {
+     848                 :          3 :         spdm_context->connection_info.algorithm.dhe_named_group = 0;
+     849                 :          3 :         spdm_context->connection_info.algorithm.aead_cipher_suite = 0;
+     850                 :          3 :         spdm_context->connection_info.algorithm.req_base_asym_alg = 0;
+     851                 :          3 :         spdm_context->connection_info.algorithm.key_schedule = 0;
+     852                 :          3 :         spdm_context->connection_info.algorithm.other_params_support = 0;
+     853                 :            :     }
+     854                 :            : 
+     855                 :         18 :     status = libspdm_append_message_a(spdm_context, spdm_request, spdm_request_size);
+     856         [ -  + ]:         18 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     857                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     858                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     859                 :            :                                                response_size, response);
+     860                 :            :     }
+     861                 :            : 
+     862                 :         18 :     status = libspdm_append_message_a(spdm_context, spdm_response, *response_size);
+     863         [ -  + ]:         18 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     864                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     865                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     866                 :            :                                                response_size, response);
+     867                 :            :     }
+     868                 :            : 
+     869                 :            :     /* -=[Update State Phase]=- */
+     870                 :         18 :     libspdm_set_connection_state(spdm_context, LIBSPDM_CONNECTION_STATE_NEGOTIATED);
+     871                 :            : 
+     872                 :         18 :     return LIBSPDM_STATUS_SUCCESS;
+     873                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_capabilities.c.func-sort-c.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_capabilities.c.func-sort-c.html new file mode 100644 index 00000000000..e71a750ae63 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_capabilities.c.func-sort-c.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_capabilities.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_capabilities.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:12213789.1 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:9512675.4 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_check_request_flag_compatibility20
libspdm_check_request_version_compatibility20
libspdm_get_response_capabilities23
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_capabilities.c.func.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_capabilities.c.func.html new file mode 100644 index 00000000000..499b70e082f --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_capabilities.c.func.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_capabilities.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_capabilities.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:12213789.1 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:9512675.4 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_check_request_flag_compatibility20
libspdm_check_request_version_compatibility20
libspdm_get_response_capabilities23
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_capabilities.c.gcov.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_capabilities.c.gcov.html new file mode 100644 index 00000000000..81274d47eeb --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_capabilities.c.gcov.html @@ -0,0 +1,392 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_capabilities.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_capabilities.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:12213789.1 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:9512675.4 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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_responder_lib.h"
+       8                 :            : 
+       9                 :            : /**
+      10                 :            :  * This function checks the compatibility of the received SPDM version,
+      11                 :            :  * if received version is valid, subsequent spdm communication will follow this version.
+      12                 :            :  *
+      13                 :            :  * @param  spdm_context  A pointer to the SPDM context.
+      14                 :            :  * @param  version       The SPDM message version.
+      15                 :            :  *
+      16                 :            :  *
+      17                 :            :  * @retval true   The received SPDM version is valid.
+      18                 :            :  * @retval false  The received SPDM version is invalid.
+      19                 :            :  **/
+      20                 :         20 : static bool libspdm_check_request_version_compatibility(libspdm_context_t *spdm_context,
+      21                 :            :                                                         uint8_t version)
+      22                 :            : {
+      23                 :            :     uint8_t local_ver;
+      24                 :            :     size_t index;
+      25                 :            : 
+      26         [ +  - ]:         43 :     for (index = 0; index < spdm_context->local_context.version.spdm_version_count; index++) {
+      27                 :         43 :         local_ver = libspdm_get_version_from_version_number(
+      28                 :         43 :             spdm_context->local_context.version.spdm_version[index]);
+      29         [ +  + ]:         43 :         if (local_ver == version) {
+      30                 :         20 :             spdm_context->connection_info.version = version << SPDM_VERSION_NUMBER_SHIFT_BIT;
+      31                 :         20 :             return true;
+      32                 :            :         }
+      33                 :            :     }
+      34                 :          0 :     return false;
+      35                 :            : }
+      36                 :            : 
+      37                 :            : /**
+      38                 :            :  * This function checks the compatibility of the received GET_CAPABILITES flag.
+      39                 :            :  * Some flags are mutually inclusive/exclusive.
+      40                 :            :  *
+      41                 :            :  * @param  capabilities_flag  The received CAPABILITIES Flag.
+      42                 :            :  * @param  version            The SPDM message version.
+      43                 :            :  *
+      44                 :            :  *
+      45                 :            :  * @retval true   The received Capabilities flag is valid.
+      46                 :            :  * @retval false  The received Capabilities flag is invalid.
+      47                 :            :  **/
+      48                 :         20 : static bool libspdm_check_request_flag_compatibility(uint32_t capabilities_flag, uint8_t version)
+      49                 :            : {
+      50                 :         20 :     const uint8_t cert_cap = (uint8_t)(capabilities_flag >> 1) & 0x01;
+      51                 :         20 :     const uint8_t chal_cap = (uint8_t)(capabilities_flag >> 2) & 0x01;
+      52                 :         20 :     const uint8_t encrypt_cap = (uint8_t)(capabilities_flag >> 6) & 0x01;
+      53                 :         20 :     const uint8_t mac_cap = (uint8_t)(capabilities_flag >> 7) & 0x01;
+      54                 :         20 :     const uint8_t mut_auth_cap = (uint8_t)(capabilities_flag >> 8) & 0x01;
+      55                 :         20 :     const uint8_t key_ex_cap = (uint8_t)(capabilities_flag >> 9) & 0x01;
+      56                 :         20 :     const uint8_t psk_cap = (uint8_t)(capabilities_flag >> 10) & 0x03;
+      57                 :         20 :     const uint8_t encap_cap = (uint8_t)(capabilities_flag >> 12) & 0x01;
+      58                 :         20 :     const uint8_t hbeat_cap = (uint8_t)(capabilities_flag >> 13) & 0x01;
+      59                 :         20 :     const uint8_t key_upd_cap = (uint8_t)(capabilities_flag >> 14) & 0x01;
+      60                 :         20 :     const uint8_t handshake_in_the_clear_cap = (uint8_t)(capabilities_flag >> 15) & 0x01;
+      61                 :         20 :     const uint8_t pub_key_id_cap = (uint8_t)(capabilities_flag >> 16) & 0x01;
+      62                 :         20 :     const uint8_t ep_info_cap = (uint8_t)(capabilities_flag >> 22) & 0x03;
+      63                 :         20 :     const uint8_t event_cap = (uint8_t)(capabilities_flag >> 25) & 0x01;
+      64                 :         20 :     const uint8_t multi_key_cap = (uint8_t)(capabilities_flag >> 26) & 0x03;
+      65                 :            : 
+      66                 :            :     /* Checks common to 1.1 and higher */
+      67         [ +  + ]:         20 :     if (version >= SPDM_MESSAGE_VERSION_11) {
+      68                 :            :         /* Illegal to return reserved values. */
+      69   [ +  -  -  + ]:         18 :         if ((psk_cap == 2) || (psk_cap == 3)) {
+      70                 :          0 :             return false;
+      71                 :            :         }
+      72                 :            : 
+      73                 :            :         /* Checks that originate from key exchange capabilities. */
+      74   [ +  +  +  + ]:         18 :         if ((key_ex_cap == 1) || (psk_cap == 1)) {
+      75                 :            :             /* While clearing MAC_CAP and setting ENCRYPT_CAP is legal according to DSP0274, libspdm
+      76                 :            :              * also implements DSP0277 secure messages, which requires at least MAC_CAP to be set.
+      77                 :            :              */
+      78         [ +  + ]:         12 :             if (mac_cap == 0) {
+      79                 :          3 :                 return false;
+      80                 :            :             }
+      81                 :            :         } else {
+      82   [ +  +  +  +  :          6 :             if ((mac_cap == 1) || (encrypt_cap == 1) || (handshake_in_the_clear_cap == 1) ||
+             +  -  +  - ]
+      83         [ -  + ]:          4 :                 (hbeat_cap == 1) || (key_upd_cap == 1)) {
+      84                 :          2 :                 return false;
+      85                 :            :             }
+      86         [ +  + ]:          4 :             if (version == SPDM_MESSAGE_VERSION_13) {
+      87         [ -  + ]:          1 :                 if (event_cap == 1) {
+      88                 :          0 :                     return false;
+      89                 :            :                 }
+      90                 :            :             }
+      91                 :            :         }
+      92   [ +  +  +  + ]:         13 :         if ((key_ex_cap == 0) && (psk_cap == 1)) {
+      93         [ +  - ]:          1 :             if (handshake_in_the_clear_cap == 1) {
+      94                 :          1 :                 return false;
+      95                 :            :             }
+      96                 :            :         }
+      97                 :            : 
+      98                 :            :         /* Checks that originate from certificate or public key capabilities. */
+      99   [ +  +  +  + ]:         12 :         if ((cert_cap == 1) || (pub_key_id_cap == 1)) {
+     100                 :            :             /* Certificate capabilities and public key capabilities cannot both be set. */
+     101   [ +  +  +  + ]:          8 :             if ((cert_cap == 1) && (pub_key_id_cap == 1)) {
+     102                 :          2 :                 return false;
+     103                 :            :             }
+     104   [ -  +  -  - ]:          6 :             if ((chal_cap == 0) && (key_ex_cap == 0)) {
+     105                 :          0 :                 return false;
+     106                 :            :             }
+     107                 :            :         } else {
+     108                 :            :             /* If certificates or public keys are not enabled then these capabilities
+     109                 :            :              * cannot be enabled. */
+     110   [ +  -  -  + ]:          4 :             if ((chal_cap == 1) || (mut_auth_cap == 1)) {
+     111                 :          0 :                 return false;
+     112                 :            :             }
+     113         [ +  + ]:          4 :             if (version == SPDM_MESSAGE_VERSION_13) {
+     114         [ -  + ]:          1 :                 if (ep_info_cap == 2) {
+     115                 :          0 :                     return false;
+     116                 :            :                 }
+     117                 :            :             }
+     118                 :            :         }
+     119                 :            : 
+     120                 :            :         /* Checks that originate from mutual authentication capabilities. */
+     121         [ +  + ]:         10 :         if (mut_auth_cap == 1) {
+     122   [ -  +  -  - ]:          6 :             if ((key_ex_cap == 0) && (chal_cap == 0)) {
+     123                 :          0 :                 return false;
+     124                 :            :             }
+     125                 :            :         }
+     126                 :            :     }
+     127                 :            : 
+     128                 :            :     /* Checks specific to 1.1. */
+     129         [ +  + ]:         12 :     if (version == SPDM_MESSAGE_VERSION_11) {
+     130   [ +  -  +  + ]:          6 :         if ((mut_auth_cap == 1) && (encap_cap == 0)) {
+     131                 :          1 :             return false;
+     132                 :            :         }
+     133                 :            :     }
+     134                 :            : 
+     135                 :            :     /* Checks specific to 1.3. */
+     136         [ +  + ]:         11 :     if (version == SPDM_MESSAGE_VERSION_13) {
+     137                 :            :         /* Illegal to return reserved values. */
+     138   [ +  -  -  + ]:          1 :         if ((ep_info_cap == 3) || (multi_key_cap == 3)) {
+     139                 :          0 :             return false;
+     140                 :            :         }
+     141                 :            :         /* check multi-key and pub_key_id */
+     142   [ +  -  -  + ]:          1 :         if ((multi_key_cap != 0) && (pub_key_id_cap == 1)) {
+     143                 :          0 :             return false;
+     144                 :            :         }
+     145                 :            :     }
+     146                 :            : 
+     147                 :         11 :     return true;
+     148                 :            : }
+     149                 :            : 
+     150                 :         23 : libspdm_return_t libspdm_get_response_capabilities(libspdm_context_t *spdm_context,
+     151                 :            :                                                    size_t request_size,
+     152                 :            :                                                    const void *request,
+     153                 :            :                                                    size_t *response_size,
+     154                 :            :                                                    void *response)
+     155                 :            : {
+     156                 :            :     const spdm_get_capabilities_request_t *spdm_request;
+     157                 :            :     spdm_capabilities_response_t *spdm_response;
+     158                 :            :     libspdm_return_t status;
+     159                 :            : 
+     160                 :         23 :     spdm_request = request;
+     161                 :            : 
+     162                 :            :     /* -=[Check Parameters Phase]=- */
+     163         [ -  + ]:         23 :     LIBSPDM_ASSERT(spdm_request->header.request_response_code == SPDM_GET_CAPABILITIES);
+     164                 :            : 
+     165                 :            :     /* -=[Verify State Phase]=- */
+     166         [ +  + ]:         23 :     if (spdm_context->response_state != LIBSPDM_RESPONSE_STATE_NORMAL) {
+     167                 :          2 :         return libspdm_responder_handle_response_state(
+     168                 :          2 :             spdm_context, spdm_request->header.request_response_code,  response_size, response);
+     169                 :            :     }
+     170         [ +  + ]:         21 :     if (spdm_context->connection_info.connection_state != LIBSPDM_CONNECTION_STATE_AFTER_VERSION) {
+     171                 :          1 :         return libspdm_generate_error_response(spdm_context,
+     172                 :            :                                                SPDM_ERROR_CODE_UNEXPECTED_REQUEST,
+     173                 :            :                                                0, response_size, response);
+     174                 :            :     }
+     175                 :            : 
+     176                 :            :     /* -=[Validate Request Phase]=- */
+     177         [ -  + ]:         20 :     if (!libspdm_check_request_version_compatibility(
+     178                 :         20 :             spdm_context, spdm_request->header.spdm_version)) {
+     179                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     180                 :            :                                                SPDM_ERROR_CODE_VERSION_MISMATCH, 0,
+     181                 :            :                                                response_size, response);
+     182                 :            :     }
+     183         [ +  + ]:         20 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_12) {
+     184         [ -  + ]:          4 :         if (request_size < sizeof(spdm_get_capabilities_request_t)) {
+     185                 :          0 :             return libspdm_generate_error_response(
+     186                 :            :                 spdm_context, SPDM_ERROR_CODE_INVALID_REQUEST, 0, response_size, response);
+     187                 :            :         } else {
+     188                 :          4 :             request_size = sizeof(spdm_get_capabilities_request_t);
+     189                 :            :         }
+     190         [ +  + ]:         16 :     } else if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_11) {
+     191         [ -  + ]:         14 :         if (request_size < sizeof(spdm_get_capabilities_request_t) -
+     192                 :            :             sizeof(spdm_request->data_transfer_size) - sizeof(spdm_request->max_spdm_msg_size)) {
+     193                 :          0 :             return libspdm_generate_error_response(
+     194                 :            :                 spdm_context, SPDM_ERROR_CODE_INVALID_REQUEST, 0, response_size, response);
+     195                 :            :         } else {
+     196                 :         14 :             request_size = sizeof(spdm_get_capabilities_request_t) -
+     197                 :            :                            sizeof(spdm_request->data_transfer_size) -
+     198                 :            :                            sizeof(spdm_request->max_spdm_msg_size);
+     199                 :            :         }
+     200                 :            :     } else {
+     201         [ -  + ]:          2 :         if (request_size < sizeof(spdm_message_header_t)) {
+     202                 :          0 :             return libspdm_generate_error_response(
+     203                 :            :                 spdm_context, SPDM_ERROR_CODE_INVALID_REQUEST, 0, response_size, response);
+     204                 :            :         } else {
+     205                 :          2 :             request_size = sizeof(spdm_message_header_t);
+     206                 :            :         }
+     207                 :            :     }
+     208         [ +  + ]:         20 :     if (!libspdm_check_request_flag_compatibility(
+     209                 :         20 :             spdm_request->flags, spdm_request->header.spdm_version)) {
+     210                 :          9 :         return libspdm_generate_error_response(spdm_context,
+     211                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     212                 :            :                                                response_size, response);
+     213                 :            :     }
+     214         [ +  + ]:         11 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_12) {
+     215         [ +  - ]:          4 :         if ((spdm_request->data_transfer_size < SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12) ||
+     216         [ +  + ]:          4 :             (spdm_request->data_transfer_size > spdm_request->max_spdm_msg_size)) {
+     217                 :          1 :             return libspdm_generate_error_response(spdm_context,
+     218                 :            :                                                    SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     219                 :            :                                                    response_size, response);
+     220                 :            :         }
+     221         [ +  + ]:          3 :         if (((spdm_request->flags & SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP) == 0) &&
+     222         [ +  + ]:          2 :             (spdm_request->data_transfer_size != spdm_request->max_spdm_msg_size)) {
+     223                 :          1 :             return libspdm_generate_error_response(spdm_context,
+     224                 :            :                                                    SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     225                 :            :                                                    response_size, response);
+     226                 :            :         }
+     227                 :            :     }
+     228         [ +  + ]:          9 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_11) {
+     229         [ +  + ]:          7 :         if (spdm_request->ct_exponent > LIBSPDM_MAX_CT_EXPONENT) {
+     230                 :          1 :             return libspdm_generate_error_response(spdm_context,
+     231                 :            :                                                    SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     232                 :            :                                                    response_size, response);
+     233                 :            :         }
+     234                 :            :     }
+     235                 :            : 
+     236                 :          8 :     libspdm_reset_message_buffer_via_request_code(spdm_context, NULL,
+     237                 :          8 :                                                   spdm_request->header.request_response_code);
+     238                 :            : 
+     239                 :            :     /* -=[Construct Response Phase]=- */
+     240         [ -  + ]:          8 :     LIBSPDM_ASSERT(*response_size >= sizeof(spdm_capabilities_response_t));
+     241                 :          8 :     *response_size = sizeof(spdm_capabilities_response_t);
+     242                 :          8 :     libspdm_zero_mem(response, *response_size);
+     243                 :          8 :     spdm_response = response;
+     244                 :            : 
+     245                 :          8 :     spdm_response->header.spdm_version = spdm_request->header.spdm_version;
+     246                 :          8 :     spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     247                 :          8 :     spdm_response->header.param1 = 0;
+     248                 :          8 :     spdm_response->header.param2 = 0;
+     249                 :          8 :     spdm_response->ct_exponent = spdm_context->local_context.capability.ct_exponent;
+     250                 :          8 :     spdm_response->flags =
+     251                 :          8 :         libspdm_mask_capability_flags(spdm_context, false,
+     252                 :            :                                       spdm_context->local_context.capability.flags);
+     253         [ +  + ]:          8 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_12) {
+     254                 :          2 :         spdm_response->data_transfer_size =
+     255                 :          2 :             spdm_context->local_context.capability.data_transfer_size;
+     256                 :          2 :         spdm_response->max_spdm_msg_size =
+     257                 :          2 :             spdm_context->local_context.capability.max_spdm_msg_size;
+     258                 :            :     }
+     259                 :            : 
+     260         [ +  + ]:          8 :     if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_12) {
+     261                 :          2 :         *response_size = sizeof(spdm_capabilities_response_t);
+     262                 :            :     } else {
+     263                 :          6 :         *response_size = sizeof(spdm_capabilities_response_t) -
+     264                 :            :                          sizeof(spdm_response->data_transfer_size) -
+     265                 :            :                          sizeof(spdm_response->max_spdm_msg_size);
+     266                 :            :     }
+     267                 :            : 
+     268                 :            :     /* -=[Process Request Phase]=- */
+     269                 :          8 :     status = libspdm_append_message_a(spdm_context, spdm_request, request_size);
+     270         [ -  + ]:          8 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     271                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     272                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     273                 :            :                                                response_size, response);
+     274                 :            :     }
+     275                 :          8 :     status = libspdm_append_message_a(spdm_context, spdm_response, *response_size);
+     276                 :            : 
+     277         [ -  + ]:          8 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     278                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     279                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     280                 :            :                                                response_size, response);
+     281                 :            :     }
+     282                 :            : 
+     283         [ +  + ]:          8 :     if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_11) {
+     284                 :          6 :         spdm_context->connection_info.capability.ct_exponent = spdm_request->ct_exponent;
+     285                 :            :     } else {
+     286                 :          2 :         spdm_context->connection_info.capability.ct_exponent = 0;
+     287                 :            :     }
+     288                 :            : 
+     289                 :          8 :     spdm_context->connection_info.capability.flags =
+     290                 :          8 :         libspdm_mask_capability_flags(spdm_context, true, spdm_request->flags);
+     291                 :            : 
+     292         [ +  + ]:          8 :     if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_12) {
+     293                 :          2 :         spdm_context->connection_info.capability.data_transfer_size =
+     294                 :          2 :             spdm_request->data_transfer_size;
+     295                 :          2 :         spdm_context->connection_info.capability.max_spdm_msg_size =
+     296                 :          2 :             spdm_request->max_spdm_msg_size;
+     297                 :            :     } else {
+     298                 :          6 :         spdm_context->connection_info.capability.data_transfer_size = 0;
+     299                 :          6 :         spdm_context->connection_info.capability.max_spdm_msg_size = 0;
+     300                 :            :     }
+     301                 :            : 
+     302                 :            :     /* -=[Update State Phase]=- */
+     303                 :          8 :     libspdm_set_connection_state(spdm_context, LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES);
+     304                 :            : 
+     305                 :          8 :     return LIBSPDM_STATUS_SUCCESS;
+     306                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_certificate.c.func-sort-c.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_certificate.c.func-sort-c.html new file mode 100644 index 00000000000..d1550b37658 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_certificate.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_certificate.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_certificate.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:637287.5 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:364875.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_response_certificate1649
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_certificate.c.func.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_certificate.c.func.html new file mode 100644 index 00000000000..e2f196988df --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_certificate.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_certificate.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_certificate.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:637287.5 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:364875.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_response_certificate1649
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_certificate.c.gcov.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_certificate.c.gcov.html new file mode 100644 index 00000000000..d20cdf43c5e --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_certificate.c.gcov.html @@ -0,0 +1,265 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_certificate.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_certificate.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:637287.5 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:364875.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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                 :            : #include "internal/libspdm_responder_lib.h"
+       7                 :            : 
+       8                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CERT_CAP
+       9                 :            : 
+      10                 :       1649 : libspdm_return_t libspdm_get_response_certificate(libspdm_context_t *spdm_context,
+      11                 :            :                                                   size_t request_size,
+      12                 :            :                                                   const void *request,
+      13                 :            :                                                   size_t *response_size,
+      14                 :            :                                                   void *response)
+      15                 :            : {
+      16                 :            :     const spdm_get_certificate_request_t *spdm_request;
+      17                 :            :     spdm_certificate_response_t *spdm_response;
+      18                 :            :     uint16_t offset;
+      19                 :            :     uint16_t length;
+      20                 :            :     size_t remainder_length;
+      21                 :            :     uint8_t slot_id;
+      22                 :            :     libspdm_return_t status;
+      23                 :            :     size_t response_capacity;
+      24                 :            :     libspdm_session_info_t *session_info;
+      25                 :            :     libspdm_session_state_t session_state;
+      26                 :            : 
+      27                 :       1649 :     spdm_request = request;
+      28                 :            : 
+      29                 :            :     /* -=[Check Parameters Phase]=- */
+      30         [ -  + ]:       1649 :     LIBSPDM_ASSERT(spdm_request->header.request_response_code == SPDM_GET_CERTIFICATE);
+      31                 :            : 
+      32         [ -  + ]:       1649 :     if (spdm_request->header.spdm_version != libspdm_get_connection_version(spdm_context)) {
+      33                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      34                 :            :                                                SPDM_ERROR_CODE_VERSION_MISMATCH, 0,
+      35                 :            :                                                response_size, response);
+      36                 :            :     }
+      37         [ +  + ]:       1649 :     if (spdm_context->response_state != LIBSPDM_RESPONSE_STATE_NORMAL) {
+      38                 :          3 :         return libspdm_responder_handle_response_state(
+      39                 :            :             spdm_context,
+      40                 :          3 :             spdm_request->header.request_response_code,
+      41                 :            :             response_size, response);
+      42                 :            :     }
+      43         [ +  + ]:       1646 :     if (spdm_context->connection_info.connection_state < LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
+      44                 :          1 :         return libspdm_generate_error_response(spdm_context,
+      45                 :            :                                                SPDM_ERROR_CODE_UNEXPECTED_REQUEST,
+      46                 :            :                                                0, response_size, response);
+      47                 :            :     }
+      48                 :       1645 :     session_info = NULL;
+      49         [ +  + ]:       1645 :     if (spdm_context->last_spdm_request_session_id_valid) {
+      50                 :          5 :         session_info = libspdm_get_session_info_via_session_id(
+      51                 :            :             spdm_context,
+      52                 :            :             spdm_context->last_spdm_request_session_id);
+      53         [ -  + ]:          5 :         if (session_info == NULL) {
+      54                 :          0 :             return libspdm_generate_error_response(
+      55                 :            :                 spdm_context,
+      56                 :            :                 SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+      57                 :            :                 response_size, response);
+      58                 :            :         }
+      59                 :          5 :         session_state = libspdm_secured_message_get_session_state(
+      60                 :            :             session_info->secured_message_context);
+      61         [ -  + ]:          5 :         if (session_state != LIBSPDM_SESSION_STATE_ESTABLISHED) {
+      62                 :          0 :             return libspdm_generate_error_response(
+      63                 :            :                 spdm_context,
+      64                 :            :                 SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+      65                 :            :                 response_size, response);
+      66                 :            :         }
+      67                 :            :     }
+      68         [ -  + ]:       1645 :     if (!libspdm_is_capabilities_flag_supported(
+      69                 :            :             spdm_context, false, 0,
+      70                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP)) {
+      71                 :          0 :         return libspdm_generate_error_response(
+      72                 :            :             spdm_context, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+      73                 :            :             SPDM_GET_CERTIFICATE, response_size, response);
+      74                 :            :     }
+      75                 :            : 
+      76         [ -  + ]:       1645 :     if (request_size < sizeof(spdm_get_certificate_request_t)) {
+      77                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      78                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+      79                 :            :                                                response_size, response);
+      80                 :            :     }
+      81                 :            : 
+      82                 :       1645 :     slot_id = spdm_request->header.param1 & SPDM_GET_CERTIFICATE_REQUEST_SLOT_ID_MASK;
+      83                 :            : 
+      84         [ +  + ]:       1645 :     if (slot_id >= SPDM_MAX_SLOT_COUNT) {
+      85                 :          1 :         return libspdm_generate_error_response(spdm_context,
+      86                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+      87                 :            :                                                response_size, response);
+      88                 :            :     }
+      89                 :            : 
+      90         [ -  + ]:       1644 :     if (spdm_context->local_context.local_cert_chain_provision[slot_id] == NULL) {
+      91                 :          0 :         return libspdm_generate_error_response(
+      92                 :            :             spdm_context, SPDM_ERROR_CODE_INVALID_REQUEST,
+      93                 :            :             0, response_size, response);
+      94                 :            :     }
+      95                 :            : 
+      96                 :       1644 :     offset = spdm_request->offset;
+      97                 :       1644 :     length = spdm_request->length;
+      98                 :            : 
+      99         [ +  + ]:       1644 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
+     100         [ +  - ]:          1 :         if (spdm_request->header.param2 &
+     101                 :            :             SPDM_GET_CERTIFICATE_REQUEST_ATTRIBUTES_SLOT_SIZE_REQUESTED) {
+     102                 :          1 :             offset = 0;
+     103                 :          1 :             length = 0;
+     104                 :            :         }
+     105                 :            :     }
+     106                 :            : 
+     107         [ +  + ]:       1644 :     if (offset >= spdm_context->local_context.local_cert_chain_provision_size[slot_id]) {
+     108                 :        126 :         return libspdm_generate_error_response(spdm_context,
+     109                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     110                 :            :                                                response_size, response);
+     111                 :            :     }
+     112                 :            : 
+     113         [ +  + ]:       1518 :     if (!libspdm_is_capabilities_flag_supported(spdm_context, false,
+     114                 :            :                                                 SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP,
+     115                 :            :                                                 SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP)) {
+     116         [ +  + ]:       1515 :         if (length > LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN) {
+     117                 :         67 :             length = LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN;
+     118                 :            :         }
+     119                 :            :     }
+     120                 :       1518 :     if ((size_t)(offset + length) > spdm_context->local_context.
+     121         [ +  + ]:       1518 :         local_cert_chain_provision_size[slot_id]) {
+     122                 :         18 :         length = (uint16_t)(spdm_context->local_context.local_cert_chain_provision_size[slot_id] -
+     123                 :            :                             offset);
+     124                 :            :     }
+     125                 :       1518 :     remainder_length = spdm_context->local_context.local_cert_chain_provision_size[slot_id] -
+     126                 :       1518 :                        (length + offset);
+     127                 :            : 
+     128                 :       1518 :     libspdm_reset_message_buffer_via_request_code(spdm_context, session_info,
+     129                 :       1518 :                                                   spdm_request->header.request_response_code);
+     130                 :            : 
+     131         [ -  + ]:       1518 :     LIBSPDM_ASSERT(*response_size >= sizeof(spdm_certificate_response_t) + length);
+     132                 :       1518 :     response_capacity = *response_size;
+     133                 :       1518 :     *response_size = sizeof(spdm_certificate_response_t) + length;
+     134                 :       1518 :     libspdm_zero_mem(response, *response_size);
+     135                 :       1518 :     spdm_response = response;
+     136                 :            : 
+     137                 :       1518 :     spdm_response->header.spdm_version = spdm_request->header.spdm_version;
+     138                 :       1518 :     spdm_response->header.request_response_code = SPDM_CERTIFICATE;
+     139                 :       1518 :     spdm_response->header.param1 = slot_id;
+     140                 :       1518 :     spdm_response->header.param2 = 0;
+     141         [ +  + ]:       1518 :     if ((spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) &&
+     142         [ -  + ]:          1 :         spdm_context->connection_info.multi_key_conn_rsp) {
+     143                 :          0 :         spdm_response->header.param2 = spdm_context->local_context.local_cert_info[slot_id];
+     144                 :            :     }
+     145                 :            : 
+     146                 :       1518 :     spdm_response->portion_length = length;
+     147                 :       1518 :     spdm_response->remainder_length = (uint16_t)remainder_length;
+     148                 :            : 
+     149                 :       1518 :     libspdm_copy_mem(spdm_response + 1, response_capacity - sizeof(spdm_certificate_response_t),
+     150                 :            :                      (const uint8_t *)spdm_context->local_context
+     151                 :       1518 :                      .local_cert_chain_provision[slot_id] + offset, length);
+     152                 :            : 
+     153         [ +  + ]:       1518 :     if (session_info == NULL) {
+     154                 :            :         /* Log to transcript. */
+     155                 :       1514 :         const size_t spdm_request_size = sizeof(spdm_get_certificate_request_t);
+     156                 :            : 
+     157                 :       1514 :         status = libspdm_append_message_b(spdm_context, spdm_request, spdm_request_size);
+     158         [ -  + ]:       1514 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     159                 :          0 :             return libspdm_generate_error_response(spdm_context,
+     160                 :            :                                                    SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     161                 :            :                                                    response_size, response);
+     162                 :            :         }
+     163                 :            : 
+     164                 :       1514 :         status = libspdm_append_message_b(spdm_context, spdm_response, *response_size);
+     165         [ -  + ]:       1514 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     166                 :          0 :             return libspdm_generate_error_response(spdm_context,
+     167                 :            :                                                    SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     168                 :            :                                                    response_size, response);
+     169                 :            :         }
+     170                 :            :     }
+     171                 :            : 
+     172         [ +  + ]:       1518 :     if (spdm_context->connection_info.connection_state <
+     173                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_CERTIFICATE) {
+     174                 :         13 :         libspdm_set_connection_state(spdm_context, LIBSPDM_CONNECTION_STATE_AFTER_CERTIFICATE);
+     175                 :            :     }
+     176                 :            : 
+     177                 :       1518 :     return LIBSPDM_STATUS_SUCCESS;
+     178                 :            : }
+     179                 :            : 
+     180                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CERT_CAP */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_challenge_auth.c.func-sort-c.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_challenge_auth.c.func-sort-c.html new file mode 100644 index 00000000000..063235a741a --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_challenge_auth.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_challenge_auth.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_challenge_auth.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:11513982.7 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:659866.3 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_response_challenge_auth19
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_challenge_auth.c.func.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_challenge_auth.c.func.html new file mode 100644 index 00000000000..a9f863852cd --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_challenge_auth.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_challenge_auth.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_challenge_auth.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:11513982.7 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:659866.3 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_response_challenge_auth19
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_challenge_auth.c.gcov.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_challenge_auth.c.gcov.html new file mode 100644 index 00000000000..56ac7f5f878 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_challenge_auth.c.gcov.html @@ -0,0 +1,424 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_challenge_auth.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_challenge_auth.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:11513982.7 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:659866.3 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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_responder_lib.h"
+       8                 :            : 
+       9                 :            : 
+      10                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP
+      11                 :            : 
+      12                 :         19 : libspdm_return_t libspdm_get_response_challenge_auth(libspdm_context_t *spdm_context,
+      13                 :            :                                                      size_t request_size,
+      14                 :            :                                                      const void *request,
+      15                 :            :                                                      size_t *response_size,
+      16                 :            :                                                      void *response)
+      17                 :            : {
+      18                 :            :     const spdm_challenge_request_t *spdm_request;
+      19                 :            :     size_t spdm_request_size;
+      20                 :            :     spdm_challenge_auth_response_t *spdm_response;
+      21                 :            :     bool result;
+      22                 :            :     size_t signature_size;
+      23                 :            :     uint8_t slot_id;
+      24                 :            :     uint32_t hash_size;
+      25                 :            :     uint8_t *measurement_summary_hash;
+      26                 :            :     uint32_t measurement_summary_hash_size;
+      27                 :            :     uint8_t *ptr;
+      28                 :            :     uint8_t auth_attribute;
+      29                 :            :     libspdm_return_t status;
+      30                 :            :     uint8_t slot_mask;
+      31                 :            :     uint8_t *opaque_data;
+      32                 :            :     size_t opaque_data_size;
+      33                 :            :     size_t spdm_response_size;
+      34                 :            : 
+      35                 :         19 :     spdm_request = request;
+      36                 :            : 
+      37                 :            :     /* -=[Check Parameters Phase]=- */
+      38         [ -  + ]:         19 :     LIBSPDM_ASSERT(spdm_request->header.request_response_code == SPDM_CHALLENGE);
+      39                 :            : 
+      40         [ -  + ]:         19 :     if (spdm_request->header.spdm_version != libspdm_get_connection_version(spdm_context)) {
+      41                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      42                 :            :                                                SPDM_ERROR_CODE_VERSION_MISMATCH, 0,
+      43                 :            :                                                response_size, response);
+      44                 :            :     }
+      45         [ +  + ]:         19 :     if (spdm_context->response_state != LIBSPDM_RESPONSE_STATE_NORMAL) {
+      46                 :          3 :         return libspdm_responder_handle_response_state(
+      47                 :            :             spdm_context,
+      48                 :          3 :             spdm_request->header.request_response_code,
+      49                 :            :             response_size, response);
+      50                 :            :     }
+      51         [ +  + ]:         16 :     if (spdm_context->last_spdm_request_session_id_valid) {
+      52                 :          1 :         return libspdm_generate_error_response(spdm_context,
+      53                 :            :                                                SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+      54                 :            :                                                response_size, response);
+      55                 :            :     }
+      56         [ +  + ]:         15 :     if (!libspdm_is_capabilities_flag_supported(
+      57                 :            :             spdm_context, false, 0,
+      58                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP)) {
+      59                 :          1 :         return libspdm_generate_error_response(
+      60                 :            :             spdm_context, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+      61                 :            :             SPDM_CHALLENGE, response_size, response);
+      62                 :            :     }
+      63         [ +  + ]:         14 :     if (spdm_context->connection_info.connection_state < LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
+      64                 :          1 :         return libspdm_generate_error_response(spdm_context,
+      65                 :            :                                                SPDM_ERROR_CODE_UNEXPECTED_REQUEST,
+      66                 :            :                                                0, response_size, response);
+      67                 :            :     }
+      68                 :            : 
+      69         [ -  + ]:         13 :     if (request_size < sizeof(spdm_challenge_request_t)) {
+      70                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      71                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+      72                 :            :                                                response_size, response);
+      73                 :            :     }
+      74                 :         13 :     spdm_request_size = sizeof(spdm_challenge_request_t);
+      75         [ +  + ]:         13 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
+      76         [ -  + ]:          2 :         if (request_size < sizeof(spdm_challenge_request_t) + SPDM_REQ_CONTEXT_SIZE) {
+      77                 :          0 :             return libspdm_generate_error_response(spdm_context,
+      78                 :            :                                                    SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+      79                 :            :                                                    response_size, response);
+      80                 :            :         }
+      81                 :          2 :         spdm_request_size += SPDM_REQ_CONTEXT_SIZE;
+      82                 :            :     }
+      83         [ +  + ]:         13 :     if (spdm_request->header.param2 > 0) {
+      84         [ +  + ]:          3 :         if (!libspdm_is_capabilities_flag_supported(
+      85                 :            :                 spdm_context, false, 0,
+      86                 :          2 :                 SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP) ||
+      87         [ +  - ]:          2 :             (spdm_context->connection_info.algorithm.measurement_spec == 0) ||
+      88         [ -  + ]:          2 :             (spdm_context->connection_info.algorithm.measurement_hash_algo == 0) ) {
+      89                 :          1 :             return libspdm_generate_error_response (spdm_context, SPDM_ERROR_CODE_INVALID_REQUEST,
+      90                 :            :                                                     0, response_size, response);
+      91                 :            :         }
+      92                 :            :     }
+      93                 :            : 
+      94                 :         12 :     slot_id = spdm_request->header.param1;
+      95                 :            : 
+      96   [ +  +  +  + ]:         12 :     if ((slot_id != 0xFF) && (slot_id >= SPDM_MAX_SLOT_COUNT)) {
+      97                 :          1 :         return libspdm_generate_error_response(spdm_context,
+      98                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+      99                 :            :                                                response_size, response);
+     100                 :            :     }
+     101                 :            : 
+     102         [ +  + ]:         11 :     if (slot_id != 0xFF) {
+     103         [ +  + ]:         10 :         if (spdm_context->local_context.local_cert_chain_provision[slot_id] == NULL) {
+     104                 :          1 :             return libspdm_generate_error_response(
+     105                 :            :                 spdm_context, SPDM_ERROR_CODE_INVALID_REQUEST,
+     106                 :            :                 0, response_size, response);
+     107                 :            :         }
+     108                 :            :     } else {
+     109         [ -  + ]:          1 :         if (spdm_context->local_context.local_public_key_provision == NULL) {
+     110                 :          0 :             return libspdm_generate_error_response(
+     111                 :            :                 spdm_context, SPDM_ERROR_CODE_INVALID_REQUEST,
+     112                 :            :                 0, response_size, response);
+     113                 :            :         }
+     114                 :            :     }
+     115                 :            : 
+     116         [ +  + ]:         10 :     if ((spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) &&
+     117   [ +  +  +  - ]:          2 :         spdm_context->connection_info.multi_key_conn_rsp &&
+     118                 :            :         (slot_id != 0xFF)) {
+     119         [ +  - ]:          1 :         if ((spdm_context->local_context.local_key_usage_bit_mask[slot_id] &
+     120                 :            :              SPDM_KEY_USAGE_BIT_MASK_CHALLENGE_USE) == 0) {
+     121                 :          1 :             return libspdm_generate_error_response(
+     122                 :            :                 spdm_context, SPDM_ERROR_CODE_INVALID_REQUEST,
+     123                 :            :                 0, response_size, response);
+     124                 :            :         }
+     125                 :            :     }
+     126                 :            : 
+     127                 :          9 :     signature_size = libspdm_get_asym_signature_size(
+     128                 :            :         spdm_context->connection_info.algorithm.base_asym_algo);
+     129                 :          9 :     hash_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+     130                 :          9 :     measurement_summary_hash_size = libspdm_get_measurement_summary_hash_size(
+     131                 :          9 :         spdm_context, false, spdm_request->header.param2);
+     132         [ +  + ]:          9 :     if ((measurement_summary_hash_size == 0) &&
+     133         [ -  + ]:          7 :         (spdm_request->header.param2 != SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH)) {
+     134                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     135                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST,
+     136                 :            :                                                0, response_size, response);
+     137                 :            :     }
+     138                 :            : 
+     139                 :            :     /* response_size should be large enough to hold a challenge response without opaque data. */
+     140         [ -  + ]:          9 :     LIBSPDM_ASSERT(*response_size >= sizeof(spdm_challenge_auth_response_t) + hash_size +
+     141                 :            :                    SPDM_NONCE_SIZE + measurement_summary_hash_size + sizeof(uint16_t) +
+     142                 :            :                    SPDM_REQ_CONTEXT_SIZE + signature_size);
+     143                 :            : 
+     144                 :          9 :     libspdm_zero_mem(response, *response_size);
+     145                 :          9 :     spdm_response = response;
+     146                 :            : 
+     147                 :          9 :     libspdm_reset_message_buffer_via_request_code(spdm_context, NULL,
+     148                 :          9 :                                                   spdm_request->header.request_response_code);
+     149                 :            : 
+     150                 :          9 :     spdm_response->header.spdm_version = spdm_request->header.spdm_version;
+     151                 :          9 :     spdm_response->header.request_response_code = SPDM_CHALLENGE_AUTH;
+     152                 :          9 :     auth_attribute = (uint8_t)(slot_id & 0xF);
+     153         [ +  - ]:          9 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_11) {
+     154         [ -  + ]:          9 :         if (libspdm_is_capabilities_flag_supported(
+     155                 :            :                 spdm_context, false,
+     156                 :            :                 SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP,
+     157         [ #  # ]:          0 :                 SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP) &&
+     158                 :          0 :             libspdm_is_capabilities_flag_supported(
+     159                 :            :                 spdm_context, false,
+     160         [ #  # ]:          0 :                 SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP, 0) &&
+     161                 :          0 :             (libspdm_is_capabilities_flag_supported(
+     162                 :            :                  spdm_context, false,
+     163         [ #  # ]:          0 :                  SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP, 0) ||
+     164                 :          0 :              libspdm_is_capabilities_flag_supported(
+     165                 :            :                  spdm_context, false,
+     166                 :            :                  SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PUB_KEY_ID_CAP, 0))) {
+     167         [ #  # ]:          0 :             if (spdm_context->local_context.basic_mut_auth_requested) {
+     168                 :          0 :                 auth_attribute =
+     169                 :            :                     (uint8_t)(auth_attribute |
+     170                 :            :                               SPDM_CHALLENGE_AUTH_RESPONSE_ATTRIBUTE_BASIC_MUT_AUTH_REQ);
+     171                 :            :             }
+     172                 :            :         }
+     173         [ -  + ]:          9 :         if ((auth_attribute & SPDM_CHALLENGE_AUTH_RESPONSE_ATTRIBUTE_BASIC_MUT_AUTH_REQ) != 0) {
+     174                 :            : #if (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_SEND_CHALLENGE_SUPPORT)
+     175                 :          0 :             libspdm_init_basic_mut_auth_encap_state(spdm_context);
+     176                 :            : #else
+     177                 :            :             auth_attribute =
+     178                 :            :                 (uint8_t)(auth_attribute &
+     179                 :            :                           ~SPDM_CHALLENGE_AUTH_RESPONSE_ATTRIBUTE_BASIC_MUT_AUTH_REQ);
+     180                 :            : #endif
+     181                 :            :         }
+     182                 :            :     }
+     183                 :            : 
+     184                 :          9 :     spdm_response->header.param1 = auth_attribute;
+     185                 :            : 
+     186         [ +  + ]:          9 :     if (slot_id == 0xFF) {
+     187                 :          1 :         spdm_response->header.param2 = 0;
+     188                 :            :     } else {
+     189                 :          8 :         slot_mask = libspdm_get_cert_slot_mask(spdm_context);
+     190         [ +  - ]:          8 :         if (slot_mask != 0) {
+     191                 :          8 :             spdm_response->header.param2 = slot_mask;
+     192                 :            :         } else {
+     193                 :          0 :             return libspdm_generate_error_response(
+     194                 :            :                 spdm_context, SPDM_ERROR_CODE_UNSPECIFIED,
+     195                 :            :                 0, response_size, response);
+     196                 :            :         }
+     197                 :            :     }
+     198                 :            : 
+     199                 :          9 :     ptr = (void *)(spdm_response + 1);
+     200         [ +  + ]:          9 :     if (slot_id == 0xFF) {
+     201                 :          1 :         result = libspdm_generate_public_key_hash(spdm_context, ptr);
+     202                 :            :     } else {
+     203                 :          8 :         result = libspdm_generate_cert_chain_hash(spdm_context, slot_id, ptr);
+     204                 :            :     }
+     205         [ -  + ]:          9 :     if (!result) {
+     206                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     207                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     208                 :            :                                                response_size, response);
+     209                 :            :     }
+     210                 :          9 :     ptr += hash_size;
+     211                 :            : 
+     212                 :          9 :     result = libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
+     213         [ -  + ]:          9 :     if (!result) {
+     214                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     215                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     216                 :            :                                                response_size, response);
+     217                 :            :     }
+     218                 :          9 :     ptr += SPDM_NONCE_SIZE;
+     219                 :            : 
+     220                 :          9 :     measurement_summary_hash = ptr;
+     221                 :            : 
+     222                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
+     223         [ +  + ]:          9 :     if (libspdm_is_capabilities_flag_supported(
+     224                 :            :             spdm_context, false, 0, SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP)) {
+     225                 :          2 :         result = libspdm_generate_measurement_summary_hash(
+     226                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+     227                 :            :             spdm_context,
+     228                 :            : #endif
+     229                 :          2 :             spdm_context->connection_info.version,
+     230                 :            :             spdm_context->connection_info.algorithm.base_hash_algo,
+     231                 :          2 :             spdm_context->connection_info.algorithm.measurement_spec,
+     232                 :            :             spdm_context->connection_info.algorithm.measurement_hash_algo,
+     233                 :          2 :             spdm_request->header.param2,
+     234                 :            :             ptr,
+     235                 :            :             measurement_summary_hash_size);
+     236                 :            :     } else {
+     237                 :          7 :         result = true;
+     238                 :            :     }
+     239                 :            : 
+     240         [ -  + ]:          9 :     if (!result) {
+     241                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     242                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     243                 :            :                                                response_size, response);
+     244                 :            :     }
+     245                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP */
+     246                 :            : 
+     247                 :          9 :     ptr += measurement_summary_hash_size;
+     248                 :            : 
+     249                 :          9 :     opaque_data_size = *response_size - (sizeof(spdm_challenge_auth_response_t) + hash_size +
+     250                 :          9 :                                          SPDM_NONCE_SIZE + measurement_summary_hash_size +
+     251                 :          9 :                                          sizeof(uint16_t) + signature_size);
+     252                 :          9 :     opaque_data =
+     253                 :          9 :         (uint8_t*)response + sizeof(spdm_challenge_auth_response_t) + hash_size + SPDM_NONCE_SIZE +
+     254                 :          9 :         measurement_summary_hash_size + sizeof(uint16_t);
+     255                 :            : 
+     256         [ +  + ]:          9 :     if ((libspdm_get_connection_version(spdm_context) >= SPDM_MESSAGE_VERSION_12) &&
+     257         [ +  - ]:          1 :         ((spdm_context->connection_info.algorithm.other_params_support &
+     258                 :            :           SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_MASK) == SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_NONE)) {
+     259                 :          1 :         opaque_data_size = 0;
+     260                 :            :     } else {
+     261                 :          8 :         result = libspdm_challenge_opaque_data(
+     262                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+     263                 :            :             spdm_context,
+     264                 :            : #endif
+     265                 :          8 :             spdm_context->connection_info.version,
+     266                 :            :             slot_id,
+     267                 :            :             measurement_summary_hash, measurement_summary_hash_size,
+     268                 :            :             opaque_data, &opaque_data_size);
+     269         [ -  + ]:          8 :         if (!result) {
+     270                 :          0 :             return libspdm_generate_error_response(
+     271                 :            :                 spdm_context, SPDM_ERROR_CODE_UNSPECIFIED,
+     272                 :            :                 0, response_size, response);
+     273                 :            :         }
+     274                 :            :     }
+     275                 :            : 
+     276                 :            :     /*write opaque_data_size*/
+     277                 :          9 :     libspdm_write_uint16 (ptr, (uint16_t)opaque_data_size);
+     278                 :          9 :     ptr += sizeof(uint16_t);
+     279                 :            : 
+     280                 :            :     /*the opaque_data is stored by libspdm_challenge_opaque_data*/
+     281                 :          9 :     ptr += opaque_data_size;
+     282                 :            : 
+     283         [ +  + ]:          9 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
+     284                 :          1 :         libspdm_copy_mem(ptr, SPDM_REQ_CONTEXT_SIZE,
+     285                 :          1 :                          spdm_request + 1, SPDM_REQ_CONTEXT_SIZE);
+     286                 :          1 :         ptr += SPDM_REQ_CONTEXT_SIZE;
+     287                 :            :     }
+     288                 :            : 
+     289                 :            :     /*get actual response size*/
+     290                 :          9 :     spdm_response_size =
+     291                 :            :         sizeof(spdm_challenge_auth_response_t) + hash_size +
+     292                 :          9 :         SPDM_NONCE_SIZE + measurement_summary_hash_size +
+     293                 :          9 :         sizeof(uint16_t) + opaque_data_size + signature_size;
+     294         [ +  + ]:          9 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
+     295                 :          1 :         spdm_response_size += SPDM_REQ_CONTEXT_SIZE;
+     296                 :            :     }
+     297                 :            : 
+     298         [ -  + ]:          9 :     LIBSPDM_ASSERT(*response_size >= spdm_response_size);
+     299                 :            : 
+     300                 :          9 :     *response_size = spdm_response_size;
+     301                 :            : 
+     302                 :            :     /* Calc Sign*/
+     303                 :            : 
+     304                 :          9 :     status = libspdm_append_message_c(spdm_context, spdm_request, spdm_request_size);
+     305         [ -  + ]:          9 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     306                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     307                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     308                 :            :                                                response_size, response);
+     309                 :            :     }
+     310                 :            : 
+     311                 :          9 :     status = libspdm_append_message_c(spdm_context, spdm_response,
+     312                 :          9 :                                       (size_t)ptr - (size_t)spdm_response);
+     313         [ -  + ]:          9 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     314                 :          0 :         libspdm_reset_message_c(spdm_context);
+     315                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     316                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     317                 :            :                                                response_size, response);
+     318                 :            :     }
+     319                 :          9 :     result = libspdm_generate_challenge_auth_signature(spdm_context, false, ptr);
+     320         [ -  + ]:          9 :     if (!result) {
+     321                 :          0 :         libspdm_reset_message_c(spdm_context);
+     322                 :          0 :         return libspdm_generate_error_response(
+     323                 :            :             spdm_context, SPDM_ERROR_CODE_UNSPECIFIED,
+     324                 :            :             0, response_size, response);
+     325                 :            :     }
+     326                 :          9 :     ptr += signature_size;
+     327                 :            : 
+     328         [ +  - ]:          9 :     if ((auth_attribute & SPDM_CHALLENGE_AUTH_RESPONSE_ATTRIBUTE_BASIC_MUT_AUTH_REQ) == 0) {
+     329                 :          9 :         libspdm_set_connection_state(spdm_context,
+     330                 :            :                                      LIBSPDM_CONNECTION_STATE_AUTHENTICATED);
+     331                 :            :     }
+     332                 :            : 
+     333                 :          9 :     libspdm_reset_message_b(spdm_context);
+     334                 :          9 :     libspdm_reset_message_c(spdm_context);
+     335                 :            : 
+     336                 :          9 :     return LIBSPDM_STATUS_SUCCESS;
+     337                 :            : }
+     338                 :            : 
+     339                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_chunk_get.c.func-sort-c.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_chunk_get.c.func-sort-c.html new file mode 100644 index 00000000000..decc546caf4 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_chunk_get.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_chunk_get.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_chunk_get.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:626496.9 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:263281.2 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_response_chunk_get13
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_chunk_get.c.func.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_chunk_get.c.func.html new file mode 100644 index 00000000000..c4abd9c5ba9 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_chunk_get.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_chunk_get.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_chunk_get.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:626496.9 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:263281.2 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_response_chunk_get13
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_chunk_get.c.gcov.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_chunk_get.c.gcov.html new file mode 100644 index 00000000000..1d6288eb170 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_chunk_get.c.gcov.html @@ -0,0 +1,260 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_chunk_get.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_chunk_get.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:626496.9 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:263281.2 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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_responder_lib.h"
+       8                 :            : 
+       9                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
+      10                 :            : 
+      11                 :         13 : libspdm_return_t libspdm_get_response_chunk_get(
+      12                 :            :     libspdm_context_t *spdm_context,
+      13                 :            :     size_t request_size,
+      14                 :            :     const void* request,
+      15                 :            :     size_t* response_size,
+      16                 :            :     void* response)
+      17                 :            : {
+      18                 :            :     libspdm_chunk_info_t* get_info;
+      19                 :            :     uint32_t min_data_transfer_size;
+      20                 :            : 
+      21                 :            :     const spdm_chunk_get_request_t* spdm_request;
+      22                 :            :     spdm_chunk_response_response_t* spdm_response;
+      23                 :            : 
+      24                 :            :     uint8_t* spdm_chunk;
+      25                 :            : 
+      26                 :         13 :     spdm_request = (const spdm_chunk_get_request_t*) request;
+      27                 :         13 :     spdm_response = (spdm_chunk_response_response_t*) response;
+      28                 :         13 :     get_info = &spdm_context->chunk_context.get;
+      29                 :            : 
+      30         [ -  + ]:         13 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_12) {
+      31                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      32                 :            :                                                SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+      33                 :            :                                                SPDM_CHUNK_GET,
+      34                 :            :                                                response_size, response);
+      35                 :            :     }
+      36                 :            : 
+      37         [ +  + ]:         13 :     if (!libspdm_is_capabilities_flag_supported(
+      38                 :            :             spdm_context, false, SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP,
+      39                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP)) {
+      40                 :          1 :         return libspdm_generate_error_response(
+      41                 :            :             spdm_context,
+      42                 :            :             SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+      43                 :            :             response_size, response);
+      44                 :            :     }
+      45                 :            : 
+      46                 :            :     /*chunk mechanism can be used for normal or encap state*/
+      47         [ +  + ]:         12 :     if ((spdm_context->response_state != LIBSPDM_RESPONSE_STATE_NORMAL) &&
+      48         [ +  - ]:          1 :         (spdm_context->response_state != LIBSPDM_RESPONSE_STATE_PROCESSING_ENCAP)) {
+      49                 :          1 :         return libspdm_responder_handle_response_state(
+      50                 :            :             spdm_context,
+      51                 :          1 :             spdm_request->header.request_response_code,
+      52                 :            :             response_size, response);
+      53                 :            :     }
+      54                 :            : 
+      55         [ +  + ]:         11 :     if (spdm_context->connection_info.connection_state <
+      56                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES) {
+      57                 :          1 :         return libspdm_generate_error_response(
+      58                 :            :             spdm_context,
+      59                 :            :             SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+      60                 :            :             response_size, response);
+      61                 :            :     }
+      62                 :            : 
+      63         [ +  + ]:         10 :     if (request_size < sizeof(spdm_chunk_get_request_t)) {
+      64                 :          1 :         return libspdm_generate_error_response(
+      65                 :            :             spdm_context,
+      66                 :            :             SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+      67                 :            :             response_size, response);
+      68                 :            :     }
+      69                 :            : 
+      70         [ +  + ]:          9 :     if (spdm_request->header.spdm_version < SPDM_MESSAGE_VERSION_12) {
+      71                 :          1 :         return libspdm_generate_error_response(
+      72                 :            :             spdm_context,
+      73                 :            :             SPDM_ERROR_CODE_UNSUPPORTED_REQUEST, SPDM_CHUNK_GET,
+      74                 :            :             response_size, response);
+      75                 :            :     }
+      76                 :            : 
+      77         [ -  + ]:          8 :     if (spdm_request->header.spdm_version
+      78                 :          8 :         != libspdm_get_connection_version(spdm_context)) {
+      79                 :          0 :         return libspdm_generate_error_response(
+      80                 :            :             spdm_context,
+      81                 :            :             SPDM_ERROR_CODE_VERSION_MISMATCH, 0,
+      82                 :            :             response_size, response);
+      83                 :            :     }
+      84                 :            : 
+      85         [ +  + ]:          8 :     if (get_info->chunk_in_use == false) {
+      86                 :          1 :         return libspdm_generate_error_response(
+      87                 :            :             spdm_context,
+      88                 :            :             SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+      89                 :            :             response_size, response);
+      90                 :            :     }
+      91                 :            : 
+      92         [ +  + ]:          7 :     if (spdm_request->header.param2 != get_info->chunk_handle) {
+      93                 :          1 :         return libspdm_generate_error_response(
+      94                 :            :             spdm_context,
+      95                 :            :             SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+      96                 :            :             response_size, response);
+      97                 :            :     }
+      98                 :            : 
+      99         [ +  + ]:          6 :     if (spdm_request->chunk_seq_no != get_info->chunk_seq_no) {
+     100                 :          2 :         return libspdm_generate_error_response(
+     101                 :            :             spdm_context,
+     102                 :            :             SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     103                 :            :             response_size, response);
+     104                 :            :     }
+     105                 :            : 
+     106                 :          4 :     libspdm_zero_mem(response, *response_size);
+     107                 :            : 
+     108                 :          4 :     min_data_transfer_size = LIBSPDM_MIN(
+     109                 :            :         spdm_context->connection_info.capability.data_transfer_size,
+     110                 :            :         spdm_context->local_context.capability.sender_data_transfer_size);
+     111                 :            : 
+     112                 :            :     /* Assert the data transfer size is smaller than the response size.
+     113                 :            :      * Otherwise there is no reason to chunk this response. */
+     114         [ -  + ]:          4 :     LIBSPDM_ASSERT(min_data_transfer_size < *response_size);
+     115                 :            : 
+     116                 :          4 :     spdm_response->header.spdm_version = spdm_request->header.spdm_version;
+     117                 :          4 :     spdm_response->header.request_response_code = SPDM_CHUNK_RESPONSE;
+     118                 :          4 :     spdm_response->header.param1 = 0;
+     119                 :          4 :     spdm_response->header.param2 = get_info->chunk_handle;
+     120                 :          4 :     spdm_response->chunk_seq_no = get_info->chunk_seq_no;
+     121                 :            : 
+     122         [ +  + ]:          4 :     if (spdm_request->chunk_seq_no == 0) {
+     123                 :          1 :         spdm_response->chunk_size =
+     124                 :            :             min_data_transfer_size
+     125                 :            :             - sizeof(spdm_chunk_response_response_t)
+     126                 :          1 :             - sizeof(uint32_t);
+     127                 :            : 
+     128                 :            :         /* No reason to do chunking if message is smaller than largest chunk size. */
+     129         [ -  + ]:          1 :         LIBSPDM_ASSERT(spdm_response->chunk_size < get_info->large_message_size);
+     130                 :            : 
+     131                 :          1 :         spdm_chunk = (uint8_t*) (spdm_response + 1);
+     132                 :            : 
+     133                 :            :         /* Set LargeMessageSize only in first chunk. */
+     134                 :          1 :         *((uint32_t*) (spdm_chunk)) = (uint32_t)get_info->large_message_size;
+     135                 :          1 :         spdm_chunk += sizeof(uint32_t);
+     136                 :            : 
+     137                 :          1 :         *response_size = sizeof(spdm_chunk_response_response_t)
+     138                 :            :                          + sizeof(uint32_t)
+     139                 :          1 :                          + spdm_response->chunk_size;
+     140                 :            :     } else {
+     141                 :          3 :         spdm_response->chunk_size =
+     142                 :          3 :             LIBSPDM_MIN(min_data_transfer_size
+     143                 :            :                         - sizeof(spdm_chunk_response_response_t),
+     144                 :            :                         (uint32_t) (get_info->large_message_size
+     145                 :            :                                     - get_info->chunk_bytes_transferred));
+     146                 :            : 
+     147                 :          3 :         spdm_chunk = (uint8_t*) (spdm_response + 1);
+     148                 :            : 
+     149                 :          3 :         *response_size = sizeof(spdm_chunk_response_response_t)
+     150                 :          3 :                          + spdm_response->chunk_size;
+     151                 :            :     }
+     152                 :            : 
+     153                 :          4 :     libspdm_copy_mem(spdm_chunk, spdm_response->chunk_size,
+     154                 :          4 :                      (uint8_t*) get_info->large_message + get_info->chunk_bytes_transferred,
+     155                 :          4 :                      spdm_response->chunk_size);
+     156                 :            : 
+     157                 :          4 :     get_info->chunk_seq_no++;
+     158                 :          4 :     get_info->chunk_bytes_transferred += spdm_response->chunk_size;
+     159                 :            : 
+     160         [ -  + ]:          4 :     LIBSPDM_ASSERT(get_info->chunk_bytes_transferred <= get_info->large_message_size);
+     161         [ +  + ]:          4 :     if (get_info->chunk_bytes_transferred == get_info->large_message_size) {
+     162                 :          2 :         get_info->chunk_in_use = false;
+     163                 :          2 :         get_info->chunk_handle++; /* implicit wrap - around to 0. */
+     164                 :          2 :         get_info->chunk_seq_no = 0;
+     165                 :          2 :         get_info->large_message = NULL;
+     166                 :          2 :         get_info->large_message_size = 0;
+     167                 :          2 :         get_info->chunk_bytes_transferred = 0;
+     168                 :            : 
+     169                 :          2 :         spdm_response->header.param1 |= SPDM_CHUNK_GET_RESPONSE_ATTRIBUTE_LAST_CHUNK;
+     170                 :            :     }
+     171                 :            : 
+     172                 :          4 :     return LIBSPDM_STATUS_SUCCESS;
+     173                 :            : }
+     174                 :            : 
+     175                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_chunk_send_ack.c.func-sort-c.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_chunk_send_ack.c.func-sort-c.html new file mode 100644 index 00000000000..c6c3eb36580 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_chunk_send_ack.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_chunk_send_ack.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_chunk_send_ack.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:10711989.9 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:507071.4 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_response_chunk_send21
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_chunk_send_ack.c.func.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_chunk_send_ack.c.func.html new file mode 100644 index 00000000000..584416b8f33 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_chunk_send_ack.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_chunk_send_ack.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_chunk_send_ack.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:10711989.9 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:507071.4 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_response_chunk_send21
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_chunk_send_ack.c.gcov.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_chunk_send_ack.c.gcov.html new file mode 100644 index 00000000000..a6ba848d661 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_chunk_send_ack.c.gcov.html @@ -0,0 +1,333 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_chunk_send_ack.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_chunk_send_ack.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:10711989.9 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:507071.4 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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_responder_lib.h"
+       8                 :            : 
+       9                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
+      10                 :            : 
+      11                 :         21 : libspdm_return_t libspdm_get_response_chunk_send(libspdm_context_t *spdm_context,
+      12                 :            :                                                  size_t request_size,
+      13                 :            :                                                  const void *request,
+      14                 :            :                                                  size_t *response_size,
+      15                 :            :                                                  void *response)
+      16                 :            : {
+      17                 :            :     const spdm_chunk_send_request_t *spdm_request;
+      18                 :            :     spdm_chunk_send_ack_response_t *spdm_response;
+      19                 :            :     libspdm_chunk_info_t *send_info;
+      20                 :         21 :     libspdm_return_t status = LIBSPDM_STATUS_SUCCESS;
+      21                 :            :     const uint8_t *chunk;
+      22                 :            :     uint32_t large_message_size;
+      23                 :            :     uint32_t calc_max_chunk_size;
+      24                 :            :     uint8_t *scratch_buffer;
+      25                 :            :     size_t scratch_buffer_size;
+      26                 :            :     uint8_t* chunk_response;
+      27                 :            :     size_t chunk_response_size;
+      28                 :            : 
+      29                 :         21 :     spdm_request = (const spdm_chunk_send_request_t*) request;
+      30                 :            : 
+      31         [ -  + ]:         21 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_12) {
+      32                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      33                 :            :                                                SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+      34                 :            :                                                SPDM_CHUNK_SEND,
+      35                 :            :                                                response_size, response);
+      36                 :            :     }
+      37                 :            : 
+      38         [ +  + ]:         21 :     if (!libspdm_is_capabilities_flag_supported(
+      39                 :            :             spdm_context, false, SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP,
+      40                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP)) {
+      41                 :          1 :         return libspdm_generate_error_response(
+      42                 :            :             spdm_context,
+      43                 :            :             SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+      44                 :            :             response_size, response);
+      45                 :            :     }
+      46                 :            : 
+      47                 :            :     /*chunk mechanism can be used for normal or encap state*/
+      48         [ +  + ]:         20 :     if ((spdm_context->response_state != LIBSPDM_RESPONSE_STATE_NORMAL) &&
+      49         [ +  - ]:          1 :         (spdm_context->response_state != LIBSPDM_RESPONSE_STATE_PROCESSING_ENCAP)) {
+      50                 :          1 :         return libspdm_responder_handle_response_state(
+      51                 :            :             spdm_context,
+      52                 :          1 :             spdm_request->header.request_response_code,
+      53                 :            :             response_size, response);
+      54                 :            :     }
+      55                 :            : 
+      56         [ +  + ]:         19 :     if (spdm_context->connection_info.connection_state <
+      57                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES) {
+      58                 :          1 :         libspdm_generate_error_response(
+      59                 :            :             spdm_context, SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+      60                 :            :             response_size, response);
+      61                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      62                 :            :     }
+      63                 :            : 
+      64         [ +  + ]:         18 :     if (request_size < sizeof(spdm_chunk_send_request_t)) {
+      65                 :          1 :         libspdm_generate_error_response(
+      66                 :            :             spdm_context, SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+      67                 :            :             response_size, response);
+      68                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      69                 :            :     }
+      70                 :            : 
+      71         [ +  + ]:         17 :     if (spdm_request->header.spdm_version < SPDM_MESSAGE_VERSION_12) {
+      72                 :          1 :         return libspdm_generate_error_response(
+      73                 :            :             spdm_context, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST, SPDM_CHUNK_SEND,
+      74                 :            :             response_size, response);
+      75                 :            :     }
+      76                 :            : 
+      77         [ +  + ]:         16 :     if (spdm_request->header.spdm_version
+      78                 :         16 :         != libspdm_get_connection_version(spdm_context)) {
+      79                 :          1 :         return libspdm_generate_error_response(
+      80                 :            :             spdm_context, SPDM_ERROR_CODE_VERSION_MISMATCH, 0,
+      81                 :            :             response_size, response);
+      82                 :            :     }
+      83                 :            : 
+      84         [ +  + ]:         15 :     if (spdm_context->chunk_context.get.chunk_in_use) {
+      85                 :            :         /* Spec does not support simultanious chunk send and chunk get */
+      86                 :          1 :         return libspdm_generate_error_response(
+      87                 :            :             spdm_context, SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+      88                 :            :             response_size, response);
+      89                 :            :     }
+      90                 :            : 
+      91                 :         14 :     send_info = &spdm_context->chunk_context.send;
+      92                 :            : 
+      93         [ +  + ]:         14 :     if (!send_info->chunk_in_use) {
+      94                 :            : 
+      95         [ -  + ]:          6 :         if (request_size < sizeof(spdm_chunk_send_request_t) + sizeof(uint32_t)) {
+      96                 :          0 :             libspdm_generate_error_response(
+      97                 :            :                 spdm_context, SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+      98                 :            :                 response_size, response);
+      99                 :          0 :             return LIBSPDM_STATUS_SUCCESS;
+     100                 :            :         }
+     101                 :            : 
+     102                 :          6 :         large_message_size = *(const uint32_t*) (spdm_request + 1);
+     103                 :          6 :         chunk = (((const uint8_t*) (spdm_request + 1)) + sizeof(uint32_t));
+     104                 :          6 :         calc_max_chunk_size =
+     105                 :          6 :             (uint32_t)request_size - (sizeof(spdm_chunk_send_request_t) + sizeof(uint32_t));
+     106                 :            : 
+     107         [ +  + ]:          6 :         if (spdm_request->chunk_seq_no != 0
+     108         [ +  - ]:          5 :             || (spdm_request->chunk_size
+     109                 :            :                 < SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12
+     110                 :            :                 - sizeof(spdm_chunk_send_request_t)
+     111                 :            :                 - sizeof(uint32_t))
+     112         [ +  + ]:          5 :             || spdm_request->chunk_size > calc_max_chunk_size
+     113         [ +  + ]:          4 :             || (uint32_t)request_size > spdm_context->local_context.capability.data_transfer_size
+     114         [ +  + ]:          3 :             || large_message_size > spdm_context->local_context.capability.max_spdm_msg_size
+     115         [ +  - ]:          2 :             || large_message_size <= SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12
+     116         [ +  + ]:          2 :             || (spdm_request->header.param1 & SPDM_CHUNK_SEND_REQUEST_ATTRIBUTE_LAST_CHUNK)
+     117                 :            :             ) {
+     118                 :          5 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     119                 :            :         } else {
+     120                 :          1 :             libspdm_get_scratch_buffer(spdm_context, (void**) &scratch_buffer,
+     121                 :            :                                        &scratch_buffer_size);
+     122                 :            : 
+     123                 :          1 :             send_info->chunk_in_use = true;
+     124                 :          1 :             send_info->chunk_handle = spdm_request->header.param2;
+     125                 :          1 :             send_info->chunk_seq_no = spdm_request->chunk_seq_no;
+     126                 :            : 
+     127                 :          2 :             send_info->large_message = scratch_buffer +
+     128                 :          1 :                                        libspdm_get_scratch_buffer_large_message_offset(spdm_context);
+     129                 :          1 :             send_info->large_message_capacity =
+     130                 :          1 :                 libspdm_get_scratch_buffer_large_message_capacity(spdm_context);
+     131                 :          1 :             send_info->large_message_size = large_message_size;
+     132                 :          1 :             send_info->chunk_bytes_transferred = spdm_request->chunk_size;
+     133                 :            : 
+     134                 :          1 :             libspdm_copy_mem(
+     135                 :            :                 send_info->large_message, send_info->large_message_capacity,
+     136                 :          1 :                 chunk, spdm_request->chunk_size);
+     137                 :            :         }
+     138                 :            :     } else {
+     139                 :            : 
+     140                 :          8 :         chunk = (const uint8_t*) (spdm_request + 1);
+     141                 :          8 :         calc_max_chunk_size =
+     142                 :          8 :             (uint32_t)request_size - sizeof(spdm_chunk_send_request_t);
+     143                 :            : 
+     144         [ +  + ]:          8 :         if (spdm_request->chunk_seq_no != send_info->chunk_seq_no + 1
+     145         [ +  + ]:          4 :             || spdm_request->header.param2 != send_info->chunk_handle
+     146         [ +  - ]:          3 :             || spdm_request->chunk_size > calc_max_chunk_size
+     147                 :          3 :             || spdm_request->chunk_size + send_info->chunk_bytes_transferred
+     148         [ +  + ]:          3 :             > send_info->large_message_size) {
+     149                 :          7 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     150         [ +  - ]:          1 :         } else if ((spdm_request->header.param1 & SPDM_CHUNK_SEND_REQUEST_ATTRIBUTE_LAST_CHUNK)
+     151                 :          1 :                    && (spdm_request->chunk_size + send_info->chunk_bytes_transferred
+     152         [ -  + ]:          1 :                        != send_info->large_message_size)) {
+     153                 :          0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     154         [ -  + ]:          1 :         } else if (!(spdm_request->header.param1 & SPDM_CHUNK_SEND_REQUEST_ATTRIBUTE_LAST_CHUNK)
+     155                 :          0 :                    && ((spdm_request->chunk_size + send_info->chunk_bytes_transferred
+     156         [ #  # ]:          0 :                         > send_info->large_message_size)
+     157         [ #  # ]:          0 :                        || (spdm_request->chunk_size
+     158                 :            :                            < SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12
+     159                 :            :                            - sizeof(spdm_chunk_send_request_t))
+     160                 :          0 :                        || ((uint32_t) request_size
+     161         [ #  # ]:          0 :                            > spdm_context->local_context.capability.data_transfer_size))) {
+     162                 :          0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     163                 :            :         } else {
+     164                 :            : 
+     165                 :          1 :             libspdm_copy_mem(
+     166                 :          1 :                 (uint8_t*)send_info->large_message + send_info->chunk_bytes_transferred,
+     167                 :          1 :                 send_info->large_message_size - send_info->chunk_bytes_transferred,
+     168                 :          1 :                 chunk, spdm_request->chunk_size);
+     169                 :            : 
+     170                 :          1 :             send_info->chunk_seq_no = spdm_request->chunk_seq_no;
+     171                 :          1 :             send_info->chunk_bytes_transferred += spdm_request->chunk_size;
+     172         [ +  - ]:          1 :             if (spdm_request->header.param1 & SPDM_CHUNK_SEND_REQUEST_ATTRIBUTE_LAST_CHUNK) {
+     173                 :          1 :                 send_info->chunk_in_use= false;
+     174                 :            :             }
+     175                 :            :         }
+     176                 :            :     }
+     177                 :            : 
+     178         [ -  + ]:         14 :     LIBSPDM_ASSERT(*response_size >= sizeof(spdm_chunk_send_ack_response_t));
+     179                 :            : 
+     180                 :         14 :     libspdm_zero_mem(response, *response_size);
+     181                 :         14 :     spdm_response = response;
+     182                 :            : 
+     183                 :         14 :     spdm_response->header.spdm_version = spdm_request->header.spdm_version;
+     184                 :         14 :     spdm_response->header.request_response_code = SPDM_CHUNK_SEND_ACK;
+     185                 :         14 :     spdm_response->header.param1 = 0;
+     186                 :         14 :     spdm_response->header.param2 = spdm_request->header.param2; /* handle */
+     187                 :         14 :     spdm_response->chunk_seq_no = spdm_request->chunk_seq_no;
+     188                 :            : 
+     189                 :         14 :     chunk_response = (uint8_t*) (spdm_response + 1);
+     190                 :         14 :     chunk_response_size = *response_size - sizeof(spdm_chunk_send_ack_response_t);
+     191                 :            : 
+     192         [ +  + ]:         14 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     193                 :            :         /* Set the EARLY_ERROR_DETECTED bit here, because one of the CHUNK_SEND requests failed.
+     194                 :            :          * If there is an error after all chunks have been sent by the requester correctly,
+     195                 :            :          * the responder reflects the error in the ChunkSendAck.ResponseToLargeRequest buffer,
+     196                 :            :          * and not in the EARLY_ERROR_DETECTED bit. */
+     197                 :            : 
+     198                 :            :         spdm_response->header.param1
+     199                 :         12 :             |= SPDM_CHUNK_SEND_ACK_RESPONSE_ATTRIBUTE_EARLY_ERROR_DETECTED;
+     200                 :            : 
+     201                 :         12 :         libspdm_generate_error_response(
+     202                 :            :             spdm_context, SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     203                 :            :             &chunk_response_size, chunk_response);
+     204                 :            : 
+     205                 :         12 :         *response_size = sizeof(spdm_chunk_send_ack_response_t) + chunk_response_size;
+     206                 :            : 
+     207                 :         12 :         send_info->chunk_in_use = false;
+     208                 :         12 :         send_info->chunk_handle = 0;
+     209                 :         12 :         send_info->chunk_seq_no = 0;
+     210                 :         12 :         send_info->chunk_bytes_transferred = 0;
+     211                 :         12 :         send_info->large_message = NULL;
+     212                 :         12 :         send_info->large_message_size = 0;
+     213         [ +  + ]:          2 :     } else if (send_info->chunk_bytes_transferred == send_info->large_message_size) {
+     214                 :            :         uint8_t opcode;
+     215                 :            : 
+     216                 :          1 :         opcode = ((spdm_message_header_t*)send_info->large_message)->request_response_code;
+     217                 :            :         libspdm_get_spdm_response_func response_func =
+     218                 :          1 :             libspdm_get_response_func_via_request_code(opcode);
+     219                 :            : 
+     220   [ +  -  +  - ]:          1 :         if ((response_func != NULL) &&
+     221         [ +  - ]:          1 :             (opcode != SPDM_CHUNK_SEND) && (opcode != SPDM_CHUNK_GET)) {
+     222                 :          1 :             status = response_func(
+     223                 :            :                 spdm_context,
+     224                 :          1 :                 send_info->large_message_size, send_info->large_message,
+     225                 :            :                 &chunk_response_size, chunk_response);
+     226                 :            :         } else {
+     227                 :          0 :             status = LIBSPDM_STATUS_SUCCESS;
+     228                 :          0 :             libspdm_generate_error_response(
+     229                 :            :                 spdm_context, SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     230                 :            :                 &chunk_response_size, chunk_response);
+     231                 :            :         }
+     232                 :            : 
+     233                 :          1 :         send_info->chunk_in_use = false;
+     234                 :          1 :         send_info->chunk_handle = 0;
+     235                 :          1 :         send_info->chunk_seq_no = 0;
+     236                 :          1 :         send_info->chunk_bytes_transferred = 0;
+     237                 :          1 :         send_info->large_message = NULL;
+     238                 :          1 :         send_info->large_message_size = 0;
+     239                 :            : 
+     240                 :          1 :         *response_size = sizeof(spdm_chunk_send_ack_response_t) + chunk_response_size;
+     241                 :            :     } else {
+     242                 :          1 :         *response_size = sizeof(spdm_chunk_send_ack_response_t);
+     243                 :            :     }
+     244                 :            : 
+     245                 :         14 :     return status;
+     246                 :            : }
+     247                 :            : 
+     248                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_common.c.func-sort-c.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_common.c.func-sort-c.html new file mode 100644 index 00000000000..26e716ab1a9 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_common.c.func-sort-c.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_common.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_common.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:698086.2 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:284070.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_process_opaque_data_supported_version_data23
libspdm_build_opaque_data_version_selection_data81
libspdm_allocate_rsp_session_id115
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_common.c.func.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_common.c.func.html new file mode 100644 index 00000000000..16b18ea4730 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_common.c.func.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_common.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_common.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:698086.2 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:284070.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_allocate_rsp_session_id115
libspdm_build_opaque_data_version_selection_data81
libspdm_process_opaque_data_supported_version_data23
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_common.c.gcov.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_common.c.gcov.html new file mode 100644 index 00000000000..42a929152bb --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_common.c.gcov.html @@ -0,0 +1,265 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_common.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_common.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:698086.2 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:284070.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 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_responder_lib.h"
+       8                 :            : 
+       9                 :        115 : uint16_t libspdm_allocate_rsp_session_id(const libspdm_context_t *spdm_context, bool use_psk)
+      10                 :            : {
+      11                 :            :     uint16_t rsp_session_id;
+      12                 :            :     const libspdm_session_info_t *session_info;
+      13                 :            :     size_t index;
+      14                 :            : 
+      15         [ +  + ]:        115 :     if (use_psk) {
+      16         [ +  + ]:         46 :         if ((spdm_context->max_psk_session_count != 0) &&
+      17         [ +  + ]:         16 :             (spdm_context->current_psk_session_count >= spdm_context->max_psk_session_count)) {
+      18                 :          5 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR,
+      19                 :            :                            "libspdm_allocate_req_session_id - MAX PSK session\n"));
+      20                 :          5 :             return (INVALID_SESSION_ID & 0xFFFF0000) >> 16;
+      21                 :            :         }
+      22                 :            :     } else {
+      23         [ +  + ]:         69 :         if ((spdm_context->max_dhe_session_count != 0) &&
+      24         [ +  + ]:         16 :             (spdm_context->current_dhe_session_count >= spdm_context->max_dhe_session_count)) {
+      25                 :          5 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR,
+      26                 :            :                            "libspdm_allocate_req_session_id - MAX DHE session\n"));
+      27                 :          5 :             return (INVALID_SESSION_ID & 0xFFFF0000) >> 16;
+      28                 :            :         }
+      29                 :            :     }
+      30                 :            : 
+      31                 :        105 :     session_info = spdm_context->session_info;
+      32         [ +  - ]:        149 :     for (index = 0; index < LIBSPDM_MAX_SESSION_COUNT; index++) {
+      33         [ +  + ]:        149 :         if ((session_info[index].session_id & 0xFFFF0000) == (INVALID_SESSION_ID & 0xFFFF0000)) {
+      34                 :        105 :             rsp_session_id = (uint16_t)(0xFFFF - index);
+      35                 :        105 :             return rsp_session_id;
+      36                 :            :         }
+      37                 :            :     }
+      38                 :            : 
+      39                 :          0 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR, "libspdm_allocate_rsp_session_id - MAX session_id\n"));
+      40                 :          0 :     return (INVALID_SESSION_ID & 0xFFFF0000) >> 16;
+      41                 :            : }
+      42                 :            : 
+      43                 :         81 : void libspdm_build_opaque_data_version_selection_data(const libspdm_context_t *spdm_context,
+      44                 :            :                                                       size_t *data_out_size,
+      45                 :            :                                                       void *data_out)
+      46                 :            : {
+      47                 :            :     size_t final_data_size;
+      48                 :            :     secured_message_general_opaque_data_table_header_t *general_opaque_data_table_header;
+      49                 :            :     spdm_general_opaque_data_table_header_t *spdm_general_opaque_data_table_header;
+      50                 :            :     secured_message_opaque_element_table_header_t *opaque_element_table_header;
+      51                 :            :     secured_message_opaque_element_version_selection_t *opaque_element_version_section;
+      52                 :            :     void *end;
+      53                 :            : 
+      54         [ -  + ]:         81 :     if (spdm_context->local_context.secured_message_version.spdm_version_count == 0) {
+      55                 :          0 :         *data_out_size = 0;
+      56                 :          0 :         return;
+      57                 :            :     }
+      58                 :            : 
+      59                 :         81 :     final_data_size = libspdm_get_opaque_data_version_selection_data_size(spdm_context);
+      60         [ -  + ]:         81 :     LIBSPDM_ASSERT(*data_out_size >= final_data_size);
+      61                 :            : 
+      62         [ +  + ]:         81 :     if (libspdm_get_connection_version (spdm_context) >= SPDM_MESSAGE_VERSION_12) {
+      63                 :          9 :         spdm_general_opaque_data_table_header = data_out;
+      64                 :          9 :         spdm_general_opaque_data_table_header->total_elements = 1;
+      65                 :          9 :         libspdm_write_uint24(spdm_general_opaque_data_table_header->reserved, 0);
+      66                 :            : 
+      67                 :          9 :         opaque_element_table_header = (void *)(spdm_general_opaque_data_table_header + 1);
+      68                 :            :     } else {
+      69                 :         72 :         general_opaque_data_table_header = data_out;
+      70                 :         72 :         general_opaque_data_table_header->spec_id = SECURED_MESSAGE_OPAQUE_DATA_SPEC_ID;
+      71                 :         72 :         general_opaque_data_table_header->opaque_version = SECURED_MESSAGE_OPAQUE_VERSION;
+      72                 :         72 :         general_opaque_data_table_header->total_elements = 1;
+      73                 :         72 :         general_opaque_data_table_header->reserved = 0;
+      74                 :            : 
+      75                 :         72 :         opaque_element_table_header = (void *)(general_opaque_data_table_header + 1);
+      76                 :            :     }
+      77                 :         81 :     opaque_element_table_header->id = SPDM_REGISTRY_ID_DMTF;
+      78                 :         81 :     opaque_element_table_header->vendor_len = 0;
+      79                 :         81 :     opaque_element_table_header->opaque_element_data_len =
+      80                 :            :         sizeof(secured_message_opaque_element_version_selection_t);
+      81                 :            : 
+      82                 :         81 :     opaque_element_version_section = (void *)(opaque_element_table_header + 1);
+      83                 :         81 :     opaque_element_version_section->sm_data_version =
+      84                 :            :         SECURED_MESSAGE_OPAQUE_ELEMENT_SMDATA_DATA_VERSION;
+      85                 :         81 :     opaque_element_version_section->sm_data_id =
+      86                 :            :         SECURED_MESSAGE_OPAQUE_ELEMENT_SMDATA_ID_VERSION_SELECTION;
+      87                 :         81 :     opaque_element_version_section->selected_version =
+      88                 :         81 :         spdm_context->connection_info.secured_message_version;
+      89                 :            :     /* Zero Padding*/
+      90                 :         81 :     end = opaque_element_version_section + 1;
+      91                 :         81 :     libspdm_zero_mem(end, (size_t)data_out + final_data_size - (size_t)end);
+      92                 :            : }
+      93                 :            : 
+      94                 :            : libspdm_return_t
+      95                 :         23 : libspdm_process_opaque_data_supported_version_data(libspdm_context_t *spdm_context,
+      96                 :            :                                                    size_t data_in_size,
+      97                 :            :                                                    const void *data_in)
+      98                 :            : {
+      99                 :            :     const secured_message_opaque_element_table_header_t
+     100                 :            :     *opaque_element_table_header;
+     101                 :            :     const secured_message_opaque_element_supported_version_t
+     102                 :            :     *opaque_element_support_version;
+     103                 :            :     const spdm_version_number_t *versions_list;
+     104                 :            :     spdm_version_number_t common_version;
+     105                 :            :     uint8_t version_count;
+     106                 :            : 
+     107                 :            :     bool result;
+     108                 :            :     const void *get_element_ptr;
+     109                 :            :     size_t get_element_len;
+     110                 :            : 
+     111                 :         23 :     result = false;
+     112                 :         23 :     get_element_ptr = NULL;
+     113                 :            : 
+     114         [ -  + ]:         23 :     if (spdm_context->local_context.secured_message_version.spdm_version_count == 0) {
+     115                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     116                 :            :     }
+     117                 :            : 
+     118         [ -  + ]:         23 :     if (data_in_size <
+     119                 :         23 :         libspdm_get_untrusted_opaque_data_supported_version_data_size(spdm_context, 1)) {
+     120                 :          0 :         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     121                 :            :     }
+     122                 :            : 
+     123                 :         23 :     result = libspdm_get_element_from_opaque_data(
+     124                 :            :         spdm_context, data_in_size,
+     125                 :            :         data_in, SPDM_REGISTRY_ID_DMTF,
+     126                 :            :         SECURED_MESSAGE_OPAQUE_ELEMENT_SMDATA_ID_SUPPORTED_VERSION,
+     127                 :            :         &get_element_ptr, &get_element_len);
+     128   [ +  +  -  + ]:         23 :     if ((!result) || (get_element_ptr == NULL)) {
+     129                 :          2 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,"get element error!\n"));
+     130                 :          2 :         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     131                 :            :     }
+     132                 :            : 
+     133                 :         21 :     opaque_element_table_header = (const secured_message_opaque_element_table_header_t*)
+     134                 :            :                                   get_element_ptr;
+     135                 :            : 
+     136                 :            :     /*check for supported version data*/
+     137                 :         21 :     opaque_element_support_version = (const void *)(opaque_element_table_header + 1);
+     138                 :            : 
+     139                 :         21 :     if ((const uint8_t *)opaque_element_support_version +
+     140                 :            :         sizeof(secured_message_opaque_element_supported_version_t) >
+     141         [ -  + ]:         21 :         (const uint8_t *)opaque_element_table_header + get_element_len) {
+     142                 :          0 :         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     143                 :            :     }
+     144                 :            : 
+     145         [ -  + ]:         21 :     if (opaque_element_support_version->version_count == 0) {
+     146                 :          0 :         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     147                 :            :     }
+     148                 :            : 
+     149                 :         21 :     version_count = opaque_element_support_version->version_count;
+     150                 :            : 
+     151         [ +  - ]:         21 :     if ((opaque_element_table_header->vendor_len != 0) ||
+     152                 :         21 :         (opaque_element_table_header->opaque_element_data_len !=
+     153                 :         21 :          sizeof(secured_message_opaque_element_supported_version_t) +
+     154         [ -  + ]:         21 :          sizeof(spdm_version_number_t) * version_count)) {
+     155                 :          0 :         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     156                 :            :     }
+     157                 :            : 
+     158                 :         21 :     versions_list = (const void *)(opaque_element_support_version + 1);
+     159                 :            : 
+     160                 :         21 :     if ((const uint8_t *)versions_list + sizeof(spdm_version_number_t) >
+     161         [ -  + ]:         21 :         (const uint8_t *)opaque_element_table_header + get_element_len) {
+     162                 :          0 :         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     163                 :            :     }
+     164                 :            : 
+     165                 :         21 :     result = libspdm_negotiate_connection_version(
+     166                 :            :         &common_version,
+     167                 :         21 :         spdm_context->local_context.secured_message_version.spdm_version,
+     168                 :         21 :         spdm_context->local_context.secured_message_version.spdm_version_count,
+     169                 :            :         versions_list, version_count);
+     170         [ -  + ]:         21 :     if (!result) {
+     171                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     172                 :            :     }
+     173                 :            : 
+     174                 :         21 :     libspdm_copy_mem(&(spdm_context->connection_info.secured_message_version),
+     175                 :            :                      sizeof(spdm_context->connection_info.secured_message_version),
+     176                 :            :                      &(common_version),
+     177                 :            :                      sizeof(spdm_version_number_t));
+     178                 :            : 
+     179                 :         21 :     return LIBSPDM_STATUS_SUCCESS;
+     180                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_csr.c.func-sort-c.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_csr.c.func-sort-c.html new file mode 100644 index 00000000000..009a58cbfb2 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_csr.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_csr.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_csr.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:739279.3 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:487464.9 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_response_csr31
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_csr.c.func.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_csr.c.func.html new file mode 100644 index 00000000000..ce277b0bd7a --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_csr.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_csr.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_csr.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:739279.3 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:487464.9 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_response_csr31
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_csr.c.gcov.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_csr.c.gcov.html new file mode 100644 index 00000000000..653a47abb84 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_csr.c.gcov.html @@ -0,0 +1,360 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_csr.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_csr.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:739279.3 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:487464.9 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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_responder_lib.h"
+       8                 :            : 
+       9                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CSR_CAP
+      10                 :            : 
+      11                 :         31 : libspdm_return_t libspdm_get_response_csr(libspdm_context_t *spdm_context,
+      12                 :            :                                           size_t request_size, const void *request,
+      13                 :            :                                           size_t *response_size, void *response)
+      14                 :            : {
+      15                 :            :     const spdm_get_csr_request_t *spdm_request;
+      16                 :            :     spdm_csr_response_t *spdm_response;
+      17                 :            :     bool result;
+      18                 :            : 
+      19                 :            :     libspdm_session_info_t *session_info;
+      20                 :            :     libspdm_session_state_t session_state;
+      21                 :            : 
+      22                 :            :     size_t csr_len;
+      23                 :            :     uint8_t *csr_p;
+      24                 :            :     uint16_t requester_info_length;
+      25                 :            :     uint16_t opaque_data_length;
+      26                 :            :     uint8_t *opaque_data;
+      27                 :            :     uint8_t *requester_info;
+      28                 :            :     bool need_reset;
+      29                 :            :     bool is_device_cert_model;
+      30                 :            :     uint8_t csr_tracking_tag;
+      31                 :            : 
+      32                 :         31 :     spdm_request = request;
+      33                 :            : 
+      34                 :            :     /* -=[Check Parameters Phase]=- */
+      35         [ -  + ]:         31 :     LIBSPDM_ASSERT(spdm_request->header.request_response_code == SPDM_GET_CSR);
+      36                 :            : 
+      37         [ -  + ]:         31 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_12) {
+      38                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      39                 :            :                                                SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+      40                 :            :                                                SPDM_GET_CSR,
+      41                 :            :                                                response_size, response);
+      42                 :            :     }
+      43                 :            : 
+      44         [ -  + ]:         31 :     if (spdm_request->header.spdm_version != libspdm_get_connection_version(spdm_context)) {
+      45                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      46                 :            :                                                SPDM_ERROR_CODE_VERSION_MISMATCH, 0,
+      47                 :            :                                                response_size, response);
+      48                 :            :     }
+      49                 :            : 
+      50         [ -  + ]:         31 :     if (spdm_context->response_state != LIBSPDM_RESPONSE_STATE_NORMAL) {
+      51                 :          0 :         return libspdm_responder_handle_response_state(spdm_context,
+      52                 :          0 :                                                        spdm_request->header.request_response_code,
+      53                 :            :                                                        response_size, response);
+      54                 :            :     }
+      55                 :            : 
+      56         [ +  + ]:         31 :     if (request_size < sizeof(spdm_get_csr_request_t)) {
+      57                 :          1 :         return libspdm_generate_error_response(spdm_context,
+      58                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+      59                 :            :                                                response_size, response);
+      60                 :            :     }
+      61                 :            : 
+      62         [ -  + ]:         30 :     if (spdm_context->connection_info.connection_state <
+      63                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
+      64                 :          0 :         return libspdm_generate_error_response(
+      65                 :            :             spdm_context,
+      66                 :            :             SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+      67                 :            :             response_size, response);
+      68                 :            :     }
+      69                 :            : 
+      70         [ -  + ]:         30 :     if (spdm_context->last_spdm_request_session_id_valid) {
+      71                 :          0 :         session_info = libspdm_get_session_info_via_session_id(
+      72                 :            :             spdm_context,
+      73                 :            :             spdm_context->last_spdm_request_session_id);
+      74         [ #  # ]:          0 :         if (session_info == NULL) {
+      75                 :          0 :             return libspdm_generate_error_response(
+      76                 :            :                 spdm_context,
+      77                 :            :                 SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+      78                 :            :                 response_size, response);
+      79                 :            :         }
+      80                 :          0 :         session_state = libspdm_secured_message_get_session_state(
+      81                 :            :             session_info->secured_message_context);
+      82         [ #  # ]:          0 :         if (session_state != LIBSPDM_SESSION_STATE_ESTABLISHED) {
+      83                 :          0 :             return libspdm_generate_error_response(
+      84                 :            :                 spdm_context,
+      85                 :            :                 SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+      86                 :            :                 response_size, response);
+      87                 :            :         }
+      88                 :            :     }
+      89                 :            : 
+      90         [ -  + ]:         30 :     if (!libspdm_is_capabilities_flag_supported(
+      91                 :            :             spdm_context, false, 0,
+      92                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CSR_CAP)) {
+      93                 :          0 :         return libspdm_generate_error_response(
+      94                 :            :             spdm_context, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+      95                 :            :             SPDM_GET_CSR, response_size, response);
+      96                 :            :     }
+      97                 :            : 
+      98                 :         30 :     requester_info_length = spdm_request->requester_info_length;
+      99                 :         30 :     opaque_data_length = spdm_request->opaque_data_length;
+     100                 :            : 
+     101         [ -  + ]:         30 :     if (opaque_data_length > SPDM_MAX_OPAQUE_DATA_SIZE) {
+     102                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     103                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     104                 :            :                                                response_size, response);
+     105                 :            :     }
+     106         [ +  + ]:         30 :     if (((spdm_context->connection_info.algorithm.other_params_support &
+     107                 :            :           SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_MASK) == SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_NONE)
+     108         [ -  + ]:          2 :         && (opaque_data_length != 0)) {
+     109                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     110                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     111                 :            :                                                response_size, response);
+     112                 :            :     }
+     113                 :            : 
+     114                 :         30 :     if (opaque_data_length >
+     115         [ -  + ]:         30 :         request_size - sizeof(spdm_get_csr_request_t)) {
+     116                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     117                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     118                 :            :                                                response_size, response);
+     119                 :            :     }
+     120                 :            : 
+     121                 :         30 :     if (requester_info_length >
+     122         [ -  + ]:         30 :         request_size - sizeof(spdm_get_csr_request_t) - opaque_data_length) {
+     123                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     124                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     125                 :            :                                                response_size, response);
+     126                 :            :     }
+     127                 :            : 
+     128                 :         30 :     requester_info = (void *)((size_t)(spdm_request + 1));
+     129                 :            : 
+     130                 :         30 :     opaque_data = (void *)(requester_info + requester_info_length);
+     131         [ +  + ]:         30 :     if (opaque_data_length != 0) {
+     132                 :          5 :         result = libspdm_process_general_opaque_data_check(spdm_context, opaque_data_length,
+     133                 :            :                                                            opaque_data);
+     134         [ +  + ]:          5 :         if (!result) {
+     135                 :          1 :             return libspdm_generate_error_response(spdm_context,
+     136                 :            :                                                    SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     137                 :            :                                                    response_size, response);
+     138                 :            :         }
+     139                 :            :     }
+     140                 :            : 
+     141                 :         29 :     need_reset = libspdm_is_capabilities_flag_supported(
+     142                 :            :         spdm_context, false, 0,
+     143                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_INSTALL_RESET_CAP);
+     144                 :            : 
+     145                 :         29 :     result = libspdm_verify_req_info(requester_info, requester_info_length);
+     146         [ +  + ]:         29 :     if (!result) {
+     147                 :          2 :         return libspdm_generate_error_response(
+     148                 :            :             spdm_context,
+     149                 :            :             SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     150                 :            :             response_size, response);
+     151                 :            :     }
+     152                 :            : 
+     153         [ -  + ]:         27 :     LIBSPDM_ASSERT(*response_size >= sizeof(spdm_csr_response_t));
+     154                 :            : 
+     155                 :         27 :     spdm_response = response;
+     156                 :         27 :     libspdm_zero_mem(response, *response_size);
+     157                 :            : 
+     158                 :         27 :     is_device_cert_model = false;
+     159                 :            : 
+     160         [ +  + ]:         27 :     if((spdm_context->local_context.capability.flags &
+     161                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ALIAS_CERT_CAP) == 0) {
+     162                 :          8 :         is_device_cert_model = true;
+     163                 :            :     }
+     164                 :            : 
+     165                 :         27 :     csr_len = *response_size - sizeof(spdm_csr_response_t);
+     166                 :         27 :     csr_p = (uint8_t*)(spdm_response + 1);
+     167                 :            : 
+     168                 :         27 :     csr_tracking_tag = 0;
+     169         [ +  + ]:         27 :     if (libspdm_get_connection_version(spdm_context) >= SPDM_MESSAGE_VERSION_13) {
+     170                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CSR_CAP_EX
+     171                 :         17 :         const bool overwrite =
+     172                 :         17 :             (spdm_request->header.param2 & SPDM_GET_CSR_REQUEST_ATTRIBUTES_OVERWRITE) != 0;
+     173                 :         17 :         const uint8_t req_cert_model =
+     174                 :         17 :             spdm_request->header.param2 & SPDM_GET_CSR_REQUEST_ATTRIBUTES_CERT_MODEL_MASK;
+     175                 :         17 :         const uint8_t key_pair_id = spdm_request->header.param1;
+     176                 :            : 
+     177                 :         17 :         csr_tracking_tag =
+     178                 :         17 :             (spdm_request->header.param2 & SPDM_GET_CSR_REQUEST_ATTRIBUTES_CSR_TRACKING_TAG_MASK) >>
+     179                 :            :             SPDM_GET_CSR_REQUEST_ATTRIBUTES_CSR_TRACKING_TAG_OFFSET;
+     180                 :            : 
+     181                 :            :         /* SPDM 1.3 parameters check. */
+     182   [ +  +  +  + ]:         17 :         if ((overwrite && (csr_tracking_tag != 0)) ||
+     183   [ +  +  -  + ]:         16 :             ((!need_reset) && (csr_tracking_tag != 0))) {
+     184                 :          1 :             return libspdm_generate_error_response(spdm_context,
+     185                 :            :                                                    SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     186                 :            :                                                    response_size, response);
+     187                 :            :         }
+     188         [ +  - ]:         16 :         if (spdm_context->connection_info.multi_key_conn_rsp) {
+     189         [ -  + ]:         16 :             if (key_pair_id == 0) {
+     190                 :          0 :                 return libspdm_generate_error_response(spdm_context,
+     191                 :            :                                                        SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     192                 :            :                                                        response_size, response);
+     193                 :            :             }
+     194   [ +  +  -  + ]:         16 :             if ((req_cert_model == SPDM_CERTIFICATE_INFO_CERT_MODEL_NONE) ||
+     195                 :            :                 (req_cert_model > SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT)) {
+     196                 :          1 :                 return libspdm_generate_error_response(spdm_context,
+     197                 :            :                                                        SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     198                 :            :                                                        response_size, response);
+     199                 :            :             }
+     200                 :            :         } else {
+     201   [ #  #  #  # ]:          0 :             if ((key_pair_id != 0) || (req_cert_model != 0)) {
+     202                 :          0 :                 return libspdm_generate_error_response(spdm_context,
+     203                 :            :                                                        SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     204                 :            :                                                        response_size, response);
+     205                 :            :             }
+     206                 :            :         }
+     207                 :            : 
+     208                 :         15 :         result = libspdm_gen_csr_ex(
+     209                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+     210                 :            :             spdm_context,
+     211                 :            : #endif
+     212                 :            :             spdm_context->connection_info.algorithm.base_hash_algo,
+     213                 :            :             spdm_context->connection_info.algorithm.base_asym_algo,
+     214                 :            :             &need_reset, request, request_size,
+     215                 :            :             requester_info, requester_info_length,
+     216                 :            :             opaque_data, opaque_data_length,
+     217                 :            :             &csr_len, csr_p, req_cert_model,
+     218                 :            :             &csr_tracking_tag, key_pair_id, overwrite);
+     219                 :            : #else
+     220                 :            :         return libspdm_generate_error_response(
+     221                 :            :             spdm_context,
+     222                 :            :             SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+     223                 :            :             response_size, response);
+     224                 :            : #endif /*LIBSPDM_ENABLE_CAPABILITY_CSR_CAP_EX*/
+     225                 :            :     } else {
+     226                 :         10 :         result = libspdm_gen_csr(
+     227                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+     228                 :            :             spdm_context,
+     229                 :            : #endif
+     230                 :            :             spdm_context->connection_info.algorithm.base_hash_algo,
+     231                 :            :             spdm_context->connection_info.algorithm.base_asym_algo,
+     232                 :            :             &need_reset, request, request_size,
+     233                 :            :             requester_info, requester_info_length,
+     234                 :            :             opaque_data, opaque_data_length,
+     235                 :            :             &csr_len, csr_p, is_device_cert_model);
+     236                 :            :     }
+     237                 :            : 
+     238         [ +  + ]:         25 :     if (!result) {
+     239   [ +  +  +  - ]:          6 :         if ((csr_tracking_tag == 0xFF) &&
+     240                 :          2 :             (libspdm_get_connection_version(spdm_context) >= SPDM_MESSAGE_VERSION_13)) {
+     241                 :          2 :             return libspdm_generate_error_response(
+     242                 :            :                 spdm_context,
+     243                 :            :                 SPDM_ERROR_CODE_BUSY, 0,
+     244                 :            :                 response_size, response);
+     245                 :            :         } else {
+     246                 :          2 :             return libspdm_generate_error_response(
+     247                 :            :                 spdm_context,
+     248                 :            :                 SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+     249                 :            :                 response_size, response);
+     250                 :            :         }
+     251                 :            :     }
+     252                 :            : 
+     253         [ -  + ]:         21 :     LIBSPDM_ASSERT(*response_size >= sizeof(spdm_csr_response_t) + csr_len);
+     254                 :         21 :     *response_size = sizeof(spdm_csr_response_t) + csr_len;
+     255                 :            : 
+     256         [ +  + ]:         21 :     if (libspdm_is_capabilities_flag_supported(
+     257                 :            :             spdm_context, false, 0,
+     258         [ +  + ]:         15 :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_INSTALL_RESET_CAP) &&
+     259                 :            :         need_reset) {
+     260                 :         13 :         return libspdm_generate_error_response(spdm_context,
+     261                 :            :                                                SPDM_ERROR_CODE_RESET_REQUIRED, csr_tracking_tag,
+     262                 :            :                                                response_size, response);
+     263                 :            :     } else {
+     264                 :          8 :         spdm_response->header.spdm_version = spdm_request->header.spdm_version;
+     265                 :          8 :         spdm_response->header.request_response_code = SPDM_CSR;
+     266                 :          8 :         spdm_response->header.param1 = 0;
+     267                 :          8 :         spdm_response->header.param2 = 0;
+     268                 :          8 :         spdm_response->csr_length = (uint16_t)csr_len;
+     269                 :          8 :         spdm_response->reserved = 0;
+     270                 :            :     }
+     271                 :            : 
+     272                 :          8 :     return LIBSPDM_STATUS_SUCCESS;
+     273                 :            : }
+     274                 :            : 
+     275                 :            : #endif /*LIBSPDM_ENABLE_CAPABILITY_CSR_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_digests.c.func-sort-c.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_digests.c.func-sort-c.html new file mode 100644 index 00000000000..052892b1aa2 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_digests.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_digests.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_digests.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:758489.3 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:435479.6 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_response_digests12
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_digests.c.func.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_digests.c.func.html new file mode 100644 index 00000000000..f5aa439d7cc --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_digests.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_digests.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_digests.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:758489.3 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:435479.6 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_response_digests12
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_digests.c.gcov.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_digests.c.gcov.html new file mode 100644 index 00000000000..92a67c39767 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_digests.c.gcov.html @@ -0,0 +1,285 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_digests.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_digests.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:758489.3 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:435479.6 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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_responder_lib.h"
+       8                 :            : 
+       9                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CERT_CAP
+      10                 :            : 
+      11                 :         12 : libspdm_return_t libspdm_get_response_digests(libspdm_context_t *spdm_context, size_t request_size,
+      12                 :            :                                               const void *request,
+      13                 :            :                                               size_t *response_size,
+      14                 :            :                                               void *response)
+      15                 :            : {
+      16                 :            :     const spdm_get_digest_request_t *spdm_request;
+      17                 :            :     spdm_digest_response_t *spdm_response;
+      18                 :            :     size_t index;
+      19                 :            :     bool no_local_cert_chain;
+      20                 :            :     uint32_t hash_size;
+      21                 :            :     uint8_t *digest;
+      22                 :            :     libspdm_return_t status;
+      23                 :            :     bool result;
+      24                 :            :     libspdm_session_info_t *session_info;
+      25                 :            :     libspdm_session_state_t session_state;
+      26                 :            :     /*total populated slot count*/
+      27                 :            :     uint8_t slot_count;
+      28                 :            :     /*populated slot index*/
+      29                 :            :     uint8_t slot_index;
+      30                 :            :     size_t additional_size;
+      31                 :            :     spdm_key_pair_id_t *key_pair_id;
+      32                 :            :     spdm_certificate_info_t *cert_info;
+      33                 :            :     spdm_key_usage_bit_mask_t *key_usage_bit_mask;
+      34                 :            : 
+      35                 :         12 :     spdm_request = request;
+      36                 :            : 
+      37                 :            :     /* -=[Check Parameters Phase]=- */
+      38         [ -  + ]:         12 :     LIBSPDM_ASSERT(spdm_request->header.request_response_code == SPDM_GET_DIGESTS);
+      39                 :            : 
+      40         [ -  + ]:         12 :     if (spdm_request->header.spdm_version != libspdm_get_connection_version(spdm_context)) {
+      41                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      42                 :            :                                                SPDM_ERROR_CODE_VERSION_MISMATCH, 0,
+      43                 :            :                                                response_size, response);
+      44                 :            :     }
+      45         [ +  + ]:         12 :     if (spdm_context->response_state != LIBSPDM_RESPONSE_STATE_NORMAL) {
+      46                 :          4 :         return libspdm_responder_handle_response_state(
+      47                 :            :             spdm_context,
+      48                 :          4 :             spdm_request->header.request_response_code,
+      49                 :            :             response_size, response);
+      50                 :            :     }
+      51         [ -  + ]:          8 :     if (!libspdm_is_capabilities_flag_supported(
+      52                 :            :             spdm_context, false, 0,
+      53                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP)) {
+      54                 :          0 :         return libspdm_generate_error_response(
+      55                 :            :             spdm_context, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+      56                 :            :             SPDM_GET_DIGESTS, response_size, response);
+      57                 :            :     }
+      58         [ +  + ]:          8 :     if (spdm_context->connection_info.connection_state <
+      59                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
+      60                 :          1 :         return libspdm_generate_error_response(spdm_context,
+      61                 :            :                                                SPDM_ERROR_CODE_UNEXPECTED_REQUEST,
+      62                 :            :                                                0, response_size, response);
+      63                 :            :     }
+      64                 :          7 :     session_info = NULL;
+      65         [ +  + ]:          7 :     if (spdm_context->last_spdm_request_session_id_valid) {
+      66                 :          1 :         session_info = libspdm_get_session_info_via_session_id(
+      67                 :            :             spdm_context,
+      68                 :            :             spdm_context->last_spdm_request_session_id);
+      69         [ -  + ]:          1 :         if (session_info == NULL) {
+      70                 :          0 :             return libspdm_generate_error_response(
+      71                 :            :                 spdm_context,
+      72                 :            :                 SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+      73                 :            :                 response_size, response);
+      74                 :            :         }
+      75                 :          1 :         session_state = libspdm_secured_message_get_session_state(
+      76                 :            :             session_info->secured_message_context);
+      77         [ -  + ]:          1 :         if (session_state != LIBSPDM_SESSION_STATE_ESTABLISHED) {
+      78                 :          0 :             return libspdm_generate_error_response(
+      79                 :            :                 spdm_context,
+      80                 :            :                 SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+      81                 :            :                 response_size, response);
+      82                 :            :         }
+      83                 :            :     }
+      84                 :            : 
+      85         [ -  + ]:          7 :     if (request_size < sizeof(spdm_get_digest_request_t)) {
+      86                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      87                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+      88                 :            :                                                response_size, response);
+      89                 :            :     }
+      90                 :            : 
+      91                 :          7 :     libspdm_reset_message_buffer_via_request_code(spdm_context, session_info,
+      92                 :          7 :                                                   spdm_request->header.request_response_code);
+      93                 :            : 
+      94                 :          7 :     no_local_cert_chain = true;
+      95         [ +  + ]:         63 :     for (index = 0; index < SPDM_MAX_SLOT_COUNT; index++) {
+      96                 :         56 :         if (spdm_context->local_context
+      97         [ +  + ]:         56 :             .local_cert_chain_provision[index] != NULL) {
+      98                 :         13 :             no_local_cert_chain = false;
+      99                 :            :         }
+     100                 :            :     }
+     101         [ +  + ]:          7 :     if (no_local_cert_chain) {
+     102                 :          1 :         return libspdm_generate_error_response(
+     103                 :            :             spdm_context, SPDM_ERROR_CODE_UNSPECIFIED,
+     104                 :            :             0, response_size, response);
+     105                 :            :     }
+     106                 :            : 
+     107                 :          6 :     hash_size = libspdm_get_hash_size(
+     108                 :            :         spdm_context->connection_info.algorithm.base_hash_algo);
+     109                 :            : 
+     110                 :          6 :     slot_count = libspdm_get_cert_slot_count(spdm_context);
+     111                 :          6 :     additional_size = 0;
+     112         [ +  + ]:          6 :     if ((spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) &&
+     113         [ +  + ]:          3 :         spdm_context->connection_info.multi_key_conn_rsp) {
+     114                 :          2 :         additional_size = sizeof(spdm_key_pair_id_t) + sizeof(spdm_certificate_info_t) +
+     115                 :            :                           sizeof(spdm_key_usage_bit_mask_t);
+     116                 :            :     }
+     117         [ -  + ]:          6 :     LIBSPDM_ASSERT(*response_size >=
+     118                 :            :                    sizeof(spdm_digest_response_t) + (hash_size + additional_size) * slot_count);
+     119                 :          6 :     *response_size = sizeof(spdm_digest_response_t) + (hash_size + additional_size) * slot_count;
+     120                 :          6 :     libspdm_zero_mem(response, *response_size);
+     121                 :          6 :     spdm_response = response;
+     122                 :            : 
+     123                 :          6 :     spdm_response->header.spdm_version = spdm_request->header.spdm_version;
+     124                 :          6 :     spdm_response->header.request_response_code = SPDM_DIGESTS;
+     125                 :          6 :     spdm_response->header.param1 = 0;
+     126                 :          6 :     spdm_response->header.param2 = 0;
+     127                 :            : 
+     128         [ +  + ]:          6 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
+     129                 :          3 :         spdm_response->header.param1 = spdm_context->local_context.local_supported_slot_mask;
+     130                 :            :     }
+     131                 :            : 
+     132                 :          6 :     digest = (void *)(spdm_response + 1);
+     133                 :          6 :     key_pair_id = (spdm_key_pair_id_t *)((uint8_t *)digest + hash_size * slot_count);
+     134                 :          6 :     cert_info = (spdm_certificate_info_t *)((uint8_t *)key_pair_id +
+     135                 :          6 :                                             sizeof(spdm_key_pair_id_t) * slot_count);
+     136                 :          6 :     key_usage_bit_mask = (spdm_key_usage_bit_mask_t *)((uint8_t *)cert_info +
+     137                 :          6 :                                                        sizeof(spdm_certificate_info_t) *
+     138                 :            :                                                        slot_count);
+     139                 :            : 
+     140                 :          6 :     slot_index = 0;
+     141         [ +  + ]:         54 :     for (index = 0; index < SPDM_MAX_SLOT_COUNT; index++) {
+     142                 :         48 :         if (spdm_context->local_context
+     143         [ +  + ]:         48 :             .local_cert_chain_provision[index] != NULL) {
+     144                 :         13 :             spdm_response->header.param2 |= (1 << index);
+     145                 :         13 :             result = libspdm_generate_cert_chain_hash(spdm_context, index,
+     146                 :         13 :                                                       &digest[hash_size * slot_index]);
+     147         [ +  + ]:         13 :             if ((spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) &&
+     148         [ +  + ]:         10 :                 spdm_context->connection_info.multi_key_conn_rsp) {
+     149                 :          9 :                 key_pair_id[slot_index] = spdm_context->local_context.local_key_pair_id[index];
+     150                 :          9 :                 cert_info[slot_index] = spdm_context->local_context.local_cert_info[index];
+     151                 :          9 :                 key_usage_bit_mask[slot_index] =
+     152                 :          9 :                     spdm_context->local_context.local_key_usage_bit_mask[index];
+     153                 :            :             }
+     154                 :         13 :             slot_index++;
+     155         [ -  + ]:         13 :             if (!result) {
+     156                 :          0 :                 return libspdm_generate_error_response(
+     157                 :            :                     spdm_context, SPDM_ERROR_CODE_UNSPECIFIED,
+     158                 :            :                     0, response_size, response);
+     159                 :            :             }
+     160                 :            :         }
+     161                 :            :     }
+     162                 :            : 
+     163         [ +  + ]:          6 :     if (session_info == NULL) {
+     164                 :            :         /* Log to transcript. */
+     165                 :          5 :         const size_t spdm_request_size = sizeof(spdm_get_digest_request_t);
+     166                 :            : 
+     167                 :          5 :         status = libspdm_append_message_b(spdm_context, spdm_request, spdm_request_size);
+     168         [ -  + ]:          5 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     169                 :          0 :             return libspdm_generate_error_response(spdm_context,
+     170                 :            :                                                    SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     171                 :            :                                                    response_size, response);
+     172                 :            :         }
+     173                 :            : 
+     174                 :          5 :         status = libspdm_append_message_b(spdm_context, spdm_response, *response_size);
+     175         [ -  + ]:          5 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     176                 :          0 :             return libspdm_generate_error_response(spdm_context,
+     177                 :            :                                                    SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     178                 :            :                                                    response_size, response);
+     179                 :            :         }
+     180                 :            : 
+     181         [ +  + ]:          5 :         if (spdm_context->connection_info.multi_key_conn_rsp) {
+     182                 :          2 :             status = libspdm_append_message_d(spdm_context, spdm_response, *response_size);
+     183         [ -  + ]:          2 :             if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     184                 :          0 :                 return libspdm_generate_error_response(spdm_context,
+     185                 :            :                                                        SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     186                 :            :                                                        response_size, response);
+     187                 :            :             }
+     188                 :            :         }
+     189                 :            :     }
+     190                 :            : 
+     191         [ +  + ]:          6 :     if (spdm_context->connection_info.connection_state <
+     192                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_DIGESTS) {
+     193                 :          5 :         libspdm_set_connection_state(spdm_context,
+     194                 :            :                                      LIBSPDM_CONNECTION_STATE_AFTER_DIGESTS);
+     195                 :            :     }
+     196                 :            : 
+     197                 :          6 :     return LIBSPDM_STATUS_SUCCESS;
+     198                 :            : }
+     199                 :            : 
+     200                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CERT_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_challenge.c.func-sort-c.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_challenge.c.func-sort-c.html new file mode 100644 index 00000000000..f8d8eee985a --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_challenge.c.func-sort-c.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_encap_challenge.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_encap_challenge.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:10913580.7 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:396262.9 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_encap_request_challenge1
libspdm_process_encap_response_challenge_auth6
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_challenge.c.func.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_challenge.c.func.html new file mode 100644 index 00000000000..bf70ab5544d --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_challenge.c.func.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_encap_challenge.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_encap_challenge.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:10913580.7 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:396262.9 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_encap_request_challenge1
libspdm_process_encap_response_challenge_auth6
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_challenge.c.gcov.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_challenge.c.gcov.html new file mode 100644 index 00000000000..5d82e157886 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_challenge.c.gcov.html @@ -0,0 +1,354 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_encap_challenge.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_encap_challenge.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:10913580.7 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:396262.9 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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_responder_lib.h"
+       8                 :            : 
+       9                 :            : #if (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP) && \
+      10                 :            :     (LIBSPDM_SEND_CHALLENGE_SUPPORT)
+      11                 :            : 
+      12                 :          1 : libspdm_return_t libspdm_get_encap_request_challenge(libspdm_context_t *spdm_context,
+      13                 :            :                                                      size_t *encap_request_size,
+      14                 :            :                                                      void *encap_request)
+      15                 :            : {
+      16                 :            :     spdm_challenge_request_t *spdm_request;
+      17                 :            :     size_t spdm_request_size;
+      18                 :            :     libspdm_return_t status;
+      19                 :            : 
+      20                 :          1 :     spdm_context->encap_context.last_encap_request_size = 0;
+      21                 :            : 
+      22         [ -  + ]:          1 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_11) {
+      23                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+      24                 :            :     }
+      25                 :            : 
+      26         [ -  + ]:          1 :     if (!libspdm_is_capabilities_flag_supported(
+      27                 :            :             spdm_context, false,
+      28                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP, 0)) {
+      29                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+      30                 :            :     }
+      31                 :            : 
+      32                 :          1 :     spdm_request_size = sizeof(spdm_challenge_request_t);
+      33         [ -  + ]:          1 :     if (libspdm_get_connection_version (spdm_context) >= SPDM_MESSAGE_VERSION_13) {
+      34                 :          0 :         spdm_request_size = sizeof(spdm_challenge_request_t) + SPDM_REQ_CONTEXT_SIZE;
+      35                 :            :     }
+      36                 :            : 
+      37         [ -  + ]:          1 :     if(*encap_request_size < spdm_request_size) {
+      38                 :          0 :         return LIBSPDM_STATUS_INVALID_MSG_SIZE;
+      39                 :            :     }
+      40                 :          1 :     *encap_request_size = spdm_request_size;
+      41                 :            : 
+      42                 :          1 :     spdm_request = encap_request;
+      43                 :            : 
+      44                 :          1 :     spdm_request->header.spdm_version = libspdm_get_connection_version (spdm_context);
+      45                 :          1 :     spdm_request->header.request_response_code = SPDM_CHALLENGE;
+      46                 :          1 :     spdm_request->header.param1 = spdm_context->encap_context.req_slot_id;
+      47                 :          1 :     spdm_request->header.param2 =
+      48                 :            :         SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH;
+      49         [ -  + ]:          1 :     if(!libspdm_get_random_number(SPDM_NONCE_SIZE, spdm_request->nonce)) {
+      50                 :          0 :         return LIBSPDM_STATUS_LOW_ENTROPY;
+      51                 :            :     }
+      52                 :          1 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "Encap RequesterNonce - "));
+      53                 :          1 :     LIBSPDM_INTERNAL_DUMP_DATA(spdm_request->nonce, SPDM_NONCE_SIZE);
+      54                 :          1 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+      55         [ -  + ]:          1 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
+      56                 :          0 :         libspdm_copy_mem(spdm_request + 1, SPDM_REQ_CONTEXT_SIZE,
+      57                 :          0 :                          spdm_context->encap_context.req_context, SPDM_REQ_CONTEXT_SIZE);
+      58                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "Encap RequesterContext - "));
+      59                 :          0 :         LIBSPDM_INTERNAL_DUMP_DATA((uint8_t *)(spdm_request + 1), SPDM_REQ_CONTEXT_SIZE);
+      60                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+      61                 :            :     }
+      62                 :            : 
+      63                 :          1 :     libspdm_reset_message_buffer_via_request_code(spdm_context, NULL,
+      64                 :          1 :                                                   spdm_request->header.request_response_code);
+      65                 :            : 
+      66                 :            : 
+      67                 :            :     /* Cache data*/
+      68                 :            : 
+      69                 :          1 :     status = libspdm_append_message_mut_c(spdm_context, spdm_request,
+      70                 :            :                                           spdm_request_size);
+      71         [ -  + ]:          1 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+      72                 :          0 :         return LIBSPDM_STATUS_BUFFER_FULL;
+      73                 :            :     }
+      74                 :            : 
+      75                 :          1 :     libspdm_copy_mem(&spdm_context->encap_context.last_encap_request_header,
+      76                 :            :                      sizeof(spdm_context->encap_context.last_encap_request_header),
+      77                 :          1 :                      &spdm_request->header, sizeof(spdm_message_header_t));
+      78                 :          1 :     spdm_context->encap_context.last_encap_request_size = spdm_request_size;
+      79                 :            : 
+      80                 :          1 :     return LIBSPDM_STATUS_SUCCESS;
+      81                 :            : }
+      82                 :            : 
+      83                 :          6 : libspdm_return_t libspdm_process_encap_response_challenge_auth(
+      84                 :            :     libspdm_context_t *spdm_context, size_t encap_response_size,
+      85                 :            :     const void *encap_response, bool *need_continue)
+      86                 :            : {
+      87                 :            :     bool result;
+      88                 :            :     const spdm_challenge_auth_response_t *spdm_response;
+      89                 :            :     size_t spdm_response_size;
+      90                 :            :     const uint8_t *ptr;
+      91                 :            :     const void *cert_chain_hash;
+      92                 :            :     size_t hash_size;
+      93                 :            :     uint32_t measurement_summary_hash_size;
+      94                 :            :     uint16_t opaque_length;
+      95                 :            :     const void *signature;
+      96                 :            :     size_t signature_size;
+      97                 :            :     uint8_t auth_attribute;
+      98                 :            :     libspdm_return_t status;
+      99                 :            : 
+     100                 :          6 :     spdm_response = encap_response;
+     101                 :          6 :     spdm_response_size = encap_response_size;
+     102                 :            : 
+     103         [ -  + ]:          6 :     if (spdm_response_size < sizeof(spdm_message_header_t)) {
+     104                 :          0 :         return LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     105                 :            :     }
+     106         [ -  + ]:          6 :     if (spdm_response->header.spdm_version != libspdm_get_connection_version (spdm_context)) {
+     107                 :          0 :         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     108                 :            :     }
+     109         [ +  + ]:          6 :     if (spdm_response->header.request_response_code == SPDM_ERROR) {
+     110                 :          1 :         status = libspdm_handle_encap_error_response_main(
+     111                 :            :             spdm_context,
+     112                 :          1 :             spdm_response->header.param1);
+     113         [ +  - ]:          1 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     114                 :          1 :             return status;
+     115                 :            :         }
+     116         [ +  + ]:          5 :     } else if (spdm_response->header.request_response_code != SPDM_CHALLENGE_AUTH) {
+     117                 :          1 :         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     118                 :            :     }
+     119         [ -  + ]:          4 :     if (spdm_response_size < sizeof(spdm_challenge_auth_response_t)) {
+     120                 :          0 :         return LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     121                 :            :     }
+     122         [ +  + ]:          4 :     if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
+     123         [ -  + ]:          1 :         if (spdm_response_size < sizeof(spdm_challenge_auth_response_t) + SPDM_REQ_CONTEXT_SIZE) {
+     124                 :          0 :             return LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     125                 :            :         }
+     126                 :            :     }
+     127                 :            : 
+     128                 :          4 :     auth_attribute = spdm_response->header.param1;
+     129         [ +  + ]:          4 :     if (spdm_context->encap_context.req_slot_id == 0xFF) {
+     130         [ -  + ]:          1 :         if ((auth_attribute & SPDM_CHALLENGE_AUTH_RESPONSE_ATTRIBUTE_SLOT_ID_MASK) != 0xF) {
+     131                 :          0 :             return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     132                 :            :         }
+     133         [ -  + ]:          1 :         if (spdm_response->header.param2 != 0) {
+     134                 :          0 :             return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     135                 :            :         }
+     136                 :            :     } else {
+     137                 :          3 :         if ((auth_attribute & SPDM_CHALLENGE_AUTH_RESPONSE_ATTRIBUTE_SLOT_ID_MASK) !=
+     138         [ -  + ]:          3 :             spdm_context->encap_context.req_slot_id) {
+     139                 :          0 :             return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     140                 :            :         }
+     141                 :          3 :         if ((spdm_response->header.param2 &
+     142         [ +  + ]:          3 :              (1 << spdm_context->encap_context.req_slot_id)) == 0) {
+     143                 :          1 :             return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     144                 :            :         }
+     145                 :            :     }
+     146                 :            : 
+     147                 :          3 :     spdm_context->connection_info.peer_used_cert_chain_slot_id =
+     148                 :          3 :         spdm_context->encap_context.req_slot_id;
+     149                 :            : 
+     150                 :          3 :     hash_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+     151                 :          6 :     signature_size = libspdm_get_req_asym_signature_size(
+     152                 :          3 :         spdm_context->connection_info.algorithm.req_base_asym_alg);
+     153                 :          3 :     measurement_summary_hash_size = 0;
+     154                 :            : 
+     155                 :          3 :     if (spdm_response_size <= sizeof(spdm_challenge_auth_response_t) +
+     156                 :          3 :         hash_size + SPDM_NONCE_SIZE +
+     157         [ -  + ]:          3 :         measurement_summary_hash_size +
+     158                 :            :         sizeof(uint16_t)) {
+     159                 :          0 :         return LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     160                 :            :     }
+     161                 :            : 
+     162                 :          3 :     ptr = (const void *)(spdm_response + 1);
+     163                 :            : 
+     164                 :          3 :     cert_chain_hash = ptr;
+     165                 :          3 :     ptr += hash_size;
+     166                 :          3 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "Encap cert_chain_hash (0x%zx) - ", hash_size));
+     167                 :          3 :     LIBSPDM_INTERNAL_DUMP_DATA(cert_chain_hash, hash_size);
+     168                 :          3 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     169         [ +  + ]:          3 :     if (spdm_context->connection_info.peer_used_cert_chain_slot_id == 0xFF) {
+     170                 :          1 :         result = libspdm_verify_public_key_hash(spdm_context, cert_chain_hash, hash_size);
+     171                 :            :     } else {
+     172                 :          2 :         result = libspdm_verify_certificate_chain_hash(spdm_context, cert_chain_hash, hash_size);
+     173                 :            :     }
+     174         [ -  + ]:          3 :     if (!result) {
+     175                 :          0 :         return LIBSPDM_STATUS_INVALID_CERT;
+     176                 :            :     }
+     177                 :            : 
+     178                 :          3 :     LIBSPDM_DEBUG_CODE(
+     179                 :            :         const void *nonce;
+     180                 :            :         nonce = ptr;
+     181                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "Encap nonce (0x%x) - ", SPDM_NONCE_SIZE));
+     182                 :            :         LIBSPDM_INTERNAL_DUMP_DATA(nonce, SPDM_NONCE_SIZE);
+     183                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     184                 :            :         );
+     185                 :          3 :     ptr += SPDM_NONCE_SIZE;
+     186                 :            : 
+     187                 :          3 :     LIBSPDM_DEBUG_CODE(
+     188                 :            :         const void *measurement_summary_hash;
+     189                 :            :         measurement_summary_hash = ptr;
+     190                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "Encap measurement_summary_hash (0x%x) - ",
+     191                 :            :                        measurement_summary_hash_size));
+     192                 :            :         LIBSPDM_INTERNAL_DUMP_DATA(measurement_summary_hash, measurement_summary_hash_size);
+     193                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     194                 :            :         );
+     195                 :          3 :     ptr += measurement_summary_hash_size;
+     196                 :            : 
+     197                 :          3 :     opaque_length = *(const uint16_t *)ptr;
+     198         [ -  + ]:          3 :     if (opaque_length > SPDM_MAX_OPAQUE_DATA_SIZE) {
+     199                 :          0 :         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     200                 :            :     }
+     201                 :          3 :     ptr += sizeof(uint16_t);
+     202                 :            : 
+     203         [ +  + ]:          3 :     if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
+     204                 :          1 :         if (spdm_response_size <
+     205                 :            :             sizeof(spdm_challenge_auth_response_t) + hash_size +
+     206                 :          1 :             SPDM_NONCE_SIZE + measurement_summary_hash_size +
+     207         [ -  + ]:          1 :             sizeof(uint16_t) + opaque_length + SPDM_REQ_CONTEXT_SIZE + signature_size) {
+     208                 :          0 :             return LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     209                 :            :         }
+     210                 :          1 :         spdm_response_size = sizeof(spdm_challenge_auth_response_t) +
+     211                 :          1 :                              hash_size + SPDM_NONCE_SIZE +
+     212                 :          1 :                              measurement_summary_hash_size + sizeof(uint16_t) +
+     213                 :          1 :                              opaque_length + SPDM_REQ_CONTEXT_SIZE + signature_size;
+     214                 :            :     } else {
+     215                 :          2 :         if (spdm_response_size <
+     216                 :            :             sizeof(spdm_challenge_auth_response_t) + hash_size +
+     217                 :          2 :             SPDM_NONCE_SIZE + measurement_summary_hash_size +
+     218         [ -  + ]:          2 :             sizeof(uint16_t) + opaque_length + signature_size) {
+     219                 :          0 :             return LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     220                 :            :         }
+     221                 :          2 :         spdm_response_size = sizeof(spdm_challenge_auth_response_t) +
+     222                 :          2 :                              hash_size + SPDM_NONCE_SIZE +
+     223                 :          2 :                              measurement_summary_hash_size + sizeof(uint16_t) +
+     224                 :          2 :                              opaque_length + signature_size;
+     225                 :            :     }
+     226                 :            : 
+     227                 :          3 :     LIBSPDM_DEBUG_CODE(
+     228                 :            :         const void *opaque;
+     229                 :            :         opaque = ptr;
+     230                 :            :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "Encap opaque (0x%x):\n", opaque_length));
+     231                 :            :         LIBSPDM_INTERNAL_DUMP_HEX(opaque, opaque_length);
+     232                 :            :         );
+     233                 :          3 :     ptr += opaque_length;
+     234                 :            : 
+     235         [ +  + ]:          3 :     if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
+     236         [ -  + ]:          1 :         if (!libspdm_consttime_is_mem_equal(spdm_context->encap_context.req_context, ptr,
+     237                 :            :                                             SPDM_REQ_CONTEXT_SIZE)) {
+     238                 :          0 :             return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     239                 :            :         }
+     240                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "Encap RequesterContext - "));
+     241                 :          1 :         LIBSPDM_INTERNAL_DUMP_DATA(ptr, SPDM_REQ_CONTEXT_SIZE);
+     242                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     243                 :          1 :         ptr += SPDM_REQ_CONTEXT_SIZE;
+     244                 :            :     }
+     245                 :            : 
+     246                 :          3 :     status = libspdm_append_message_mut_c(spdm_context, spdm_response,
+     247                 :            :                                           spdm_response_size - signature_size);
+     248         [ -  + ]:          3 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     249                 :          0 :         return LIBSPDM_STATUS_BUFFER_FULL;
+     250                 :            :     }
+     251                 :            : 
+     252                 :          3 :     signature = ptr;
+     253                 :          3 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "Encap signature (0x%zx):\n", signature_size));
+     254                 :          3 :     LIBSPDM_INTERNAL_DUMP_HEX(signature, signature_size);
+     255                 :          3 :     result = libspdm_verify_challenge_auth_signature(
+     256                 :            :         spdm_context, false, signature, signature_size);
+     257         [ -  + ]:          3 :     if (!result) {
+     258                 :          0 :         return LIBSPDM_STATUS_VERIF_FAIL;
+     259                 :            :     }
+     260                 :            : 
+     261                 :          3 :     libspdm_set_connection_state(spdm_context,
+     262                 :            :                                  LIBSPDM_CONNECTION_STATE_AUTHENTICATED);
+     263                 :            : 
+     264                 :          3 :     *need_continue = false;
+     265                 :            : 
+     266                 :          3 :     return LIBSPDM_STATUS_SUCCESS;
+     267                 :            : }
+     268                 :            : 
+     269                 :            : #endif /* (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (..) */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_get_certificate.c.func-sort-c.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_get_certificate.c.func-sort-c.html new file mode 100644 index 00000000000..e06f229e3f3 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_get_certificate.c.func-sort-c.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_encap_get_certificate.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_encap_get_certificate.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:7512560.0 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:377847.4 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_encap_request_get_certificate2
libspdm_process_encap_response_certificate12
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_get_certificate.c.func.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_get_certificate.c.func.html new file mode 100644 index 00000000000..dad67eb5a58 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_get_certificate.c.func.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_encap_get_certificate.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_encap_get_certificate.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:7512560.0 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:377847.4 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_encap_request_get_certificate2
libspdm_process_encap_response_certificate12
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_get_certificate.c.gcov.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_get_certificate.c.gcov.html new file mode 100644 index 00000000000..f887c5f785b --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_get_certificate.c.gcov.html @@ -0,0 +1,336 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_encap_get_certificate.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_encap_get_certificate.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:7512560.0 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:377847.4 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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_responder_lib.h"
+       8                 :            : 
+       9                 :            : #if (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP) && \
+      10                 :            :     (LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT)
+      11                 :            : 
+      12                 :          2 : libspdm_return_t libspdm_get_encap_request_get_certificate(libspdm_context_t *spdm_context,
+      13                 :            :                                                            size_t *encap_request_size,
+      14                 :            :                                                            void *encap_request)
+      15                 :            : {
+      16                 :            :     spdm_get_certificate_request_t *spdm_request;
+      17                 :            :     libspdm_return_t status;
+      18                 :            : 
+      19                 :          2 :     spdm_context->encap_context.last_encap_request_size = 0;
+      20                 :            : 
+      21         [ -  + ]:          2 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_11) {
+      22                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+      23                 :            :     }
+      24                 :            : 
+      25         [ -  + ]:          2 :     if (!libspdm_is_capabilities_flag_supported(
+      26                 :            :             spdm_context, false,
+      27                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP, 0)) {
+      28                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+      29                 :            :     }
+      30                 :            : 
+      31         [ -  + ]:          2 :     LIBSPDM_ASSERT(*encap_request_size >= sizeof(spdm_get_certificate_request_t));
+      32                 :          2 :     *encap_request_size = sizeof(spdm_get_certificate_request_t);
+      33                 :            : 
+      34                 :          2 :     spdm_request = encap_request;
+      35                 :            : 
+      36                 :          2 :     spdm_request->header.spdm_version = libspdm_get_connection_version (spdm_context);
+      37                 :          2 :     spdm_request->header.request_response_code = SPDM_GET_CERTIFICATE;
+      38                 :          2 :     spdm_request->header.param1 = spdm_context->encap_context.req_slot_id;
+      39                 :          2 :     spdm_request->header.param2 = 0;
+      40                 :          2 :     spdm_request->offset = (uint16_t)spdm_context->mut_auth_cert_chain_buffer_size;;
+      41                 :          2 :     spdm_request->length = LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN;
+      42                 :          2 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "request (offset 0x%x, size 0x%x):\n",
+      43                 :            :                    spdm_request->offset, spdm_request->length));
+      44                 :            : 
+      45                 :          2 :     libspdm_reset_message_buffer_via_request_code(spdm_context, NULL,
+      46                 :          2 :                                                   spdm_request->header.request_response_code);
+      47                 :            : 
+      48                 :            :     /* Cache data*/
+      49                 :          2 :     status = libspdm_append_message_mut_b(spdm_context, spdm_request, *encap_request_size);
+      50         [ -  + ]:          2 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+      51                 :          0 :         return LIBSPDM_STATUS_BUFFER_FULL;
+      52                 :            :     }
+      53                 :            : 
+      54                 :          2 :     libspdm_copy_mem(&spdm_context->encap_context.last_encap_request_header,
+      55                 :            :                      sizeof(spdm_context->encap_context.last_encap_request_header),
+      56                 :          2 :                      &spdm_request->header, sizeof(spdm_message_header_t));
+      57                 :          2 :     spdm_context->encap_context.last_encap_request_size = *encap_request_size;
+      58                 :            : 
+      59                 :          2 :     return LIBSPDM_STATUS_SUCCESS;
+      60                 :            : }
+      61                 :            : 
+      62                 :         12 : libspdm_return_t libspdm_process_encap_response_certificate(
+      63                 :            :     libspdm_context_t *spdm_context, size_t encap_response_size,
+      64                 :            :     const void *encap_response, bool *need_continue)
+      65                 :            : {
+      66                 :            :     const spdm_certificate_response_t *spdm_response;
+      67                 :            :     size_t spdm_response_size;
+      68                 :            :     bool result;
+      69                 :            :     libspdm_return_t status;
+      70                 :            :     uint16_t request_offset;
+      71                 :            :     uint8_t slot_id;
+      72                 :            :     uint8_t *cert_chain_buffer;
+      73                 :            :     size_t cert_chain_buffer_size;
+      74                 :            :     size_t cert_chain_buffer_max_size;
+      75                 :            :     uint8_t cert_model;
+      76                 :            : 
+      77                 :         12 :     spdm_response = encap_response;
+      78                 :         12 :     spdm_response_size = encap_response_size;
+      79                 :            : 
+      80                 :         12 :     cert_chain_buffer = (uint8_t *)spdm_context->mut_auth_cert_chain_buffer;
+      81                 :         12 :     cert_chain_buffer_size = spdm_context->mut_auth_cert_chain_buffer_size;
+      82                 :         12 :     cert_chain_buffer_max_size = spdm_context->mut_auth_cert_chain_buffer_max_size;
+      83                 :            : 
+      84         [ -  + ]:         12 :     if (spdm_response_size < sizeof(spdm_message_header_t)) {
+      85                 :          0 :         return LIBSPDM_STATUS_INVALID_MSG_SIZE;
+      86                 :            :     }
+      87         [ -  + ]:         12 :     if (spdm_response->header.spdm_version != libspdm_get_connection_version (spdm_context)) {
+      88                 :          0 :         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+      89                 :            :     }
+      90         [ +  + ]:         12 :     if (spdm_response->header.request_response_code == SPDM_ERROR) {
+      91                 :          2 :         status = libspdm_handle_encap_error_response_main(
+      92                 :          2 :             spdm_context, spdm_response->header.param1);
+      93         [ +  - ]:          2 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+      94                 :          2 :             return status;
+      95                 :            :         }
+      96         [ -  + ]:         10 :     } else if (spdm_response->header.request_response_code != SPDM_CERTIFICATE) {
+      97                 :          0 :         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+      98                 :            :     }
+      99         [ -  + ]:         10 :     if (encap_response_size < sizeof(spdm_certificate_response_t)) {
+     100                 :          0 :         return LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     101                 :            :     }
+     102         [ +  + ]:         10 :     if ((spdm_response->portion_length > LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN) ||
+     103         [ +  + ]:          9 :         (spdm_response->portion_length == 0)) {
+     104                 :          2 :         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     105                 :            :     }
+     106                 :            : 
+     107                 :          8 :     request_offset = (uint16_t)cert_chain_buffer_size;
+     108                 :            : 
+     109         [ -  + ]:          8 :     if (spdm_response->portion_length > 0xFFFF - request_offset) {
+     110                 :          0 :         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     111                 :            :     }
+     112         [ -  + ]:          8 :     if (spdm_response->remainder_length > 0xFFFF - request_offset - spdm_response->portion_length) {
+     113                 :          0 :         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     114                 :            :     }
+     115         [ +  - ]:          8 :     if (request_offset == 0) {
+     116                 :          8 :         spdm_context->encap_context.cert_chain_total_len = spdm_response->portion_length +
+     117                 :          8 :                                                            spdm_response->remainder_length;
+     118                 :          0 :     } else if (spdm_context->encap_context.cert_chain_total_len !=
+     119         [ #  # ]:          0 :                request_offset + spdm_response->portion_length + spdm_response->remainder_length) {
+     120                 :          0 :         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     121                 :            :     }
+     122                 :          8 :     slot_id = spdm_context->encap_context.req_slot_id;
+     123         [ -  + ]:          8 :     if ((spdm_response->header.param1 & SPDM_CERTIFICATE_RESPONSE_SLOT_ID_MASK) != slot_id) {
+     124                 :          0 :         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     125                 :            :     }
+     126         [ +  + ]:          8 :     if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
+     127                 :          6 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "cert_info - 0x%02x\n",
+     128                 :            :                        spdm_response->header.param2));
+     129                 :          6 :         cert_model = spdm_response->header.param2 &
+     130                 :            :                      SPDM_CERTIFICATE_RESPONSE_ATTRIBUTES_CERTIFICATE_INFO_MASK;
+     131         [ +  + ]:          6 :         if (spdm_context->connection_info.multi_key_conn_req) {
+     132         [ -  + ]:          5 :             if (cert_model > SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT) {
+     133                 :          0 :                 return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     134                 :            :             }
+     135   [ +  +  +  + ]:          5 :             if ((slot_id == 0) &&
+     136                 :            :                 (cert_model == SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT)) {
+     137                 :          1 :                 return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     138                 :            :             }
+     139         [ +  + ]:          4 :             if ((cert_model == SPDM_CERTIFICATE_INFO_CERT_MODEL_NONE) &&
+     140         [ +  - ]:          1 :                 (spdm_response->portion_length != 0)) {
+     141                 :          1 :                 return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     142                 :            :             }
+     143                 :            :         } else {
+     144         [ -  + ]:          1 :             if (cert_model != SPDM_CERTIFICATE_INFO_CERT_MODEL_NONE) {
+     145                 :          0 :                 return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     146                 :            :             }
+     147                 :            :         }
+     148         [ +  - ]:          4 :         if (spdm_context->connection_info.peer_cert_info[slot_id] ==
+     149                 :            :             SPDM_CERTIFICATE_INFO_CERT_MODEL_NONE) {
+     150                 :          4 :             spdm_context->connection_info.peer_cert_info[slot_id] = cert_model;
+     151         [ #  # ]:          0 :         } else if (spdm_context->connection_info.peer_cert_info[slot_id] != cert_model) {
+     152                 :          0 :             return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     153                 :            :         }
+     154                 :            :     }
+     155                 :            : 
+     156         [ -  + ]:          6 :     if (spdm_response_size < sizeof(spdm_certificate_response_t) + spdm_response->portion_length) {
+     157                 :          0 :         return LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     158                 :            :     }
+     159                 :          6 :     spdm_response_size = sizeof(spdm_certificate_response_t) + spdm_response->portion_length;
+     160                 :            : 
+     161                 :            :     /* Cache data*/
+     162                 :            : 
+     163                 :          6 :     status = libspdm_append_message_mut_b(spdm_context, spdm_response, spdm_response_size);
+     164         [ -  + ]:          6 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     165                 :          0 :         return LIBSPDM_STATUS_BUFFER_FULL;
+     166                 :            :     }
+     167                 :            : 
+     168                 :          6 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "Certificate (offset 0x%x, size 0x%x):\n",
+     169                 :            :                    request_offset, spdm_response->portion_length));
+     170                 :          6 :     LIBSPDM_INTERNAL_DUMP_HEX((const void *)(spdm_response + 1), spdm_response->portion_length);
+     171                 :            : 
+     172         [ -  + ]:          6 :     if ((cert_chain_buffer_size + spdm_response->portion_length) > cert_chain_buffer_max_size) {
+     173                 :          0 :         return LIBSPDM_STATUS_BUFFER_FULL;
+     174                 :            :     }
+     175                 :            : 
+     176                 :          6 :     libspdm_copy_mem(cert_chain_buffer + cert_chain_buffer_size,
+     177                 :            :                      cert_chain_buffer_max_size - cert_chain_buffer_size,
+     178                 :          6 :                      (const void *)(spdm_response + 1), spdm_response->portion_length);
+     179                 :            : 
+     180                 :          6 :     cert_chain_buffer_size += spdm_response->portion_length;
+     181                 :          6 :     spdm_context->mut_auth_cert_chain_buffer_size = cert_chain_buffer_size;
+     182                 :            : 
+     183         [ +  - ]:          6 :     if (spdm_response->remainder_length != 0) {
+     184                 :          6 :         *need_continue = true;
+     185                 :            : 
+     186                 :          6 :         return LIBSPDM_STATUS_SUCCESS;
+     187                 :            :     }
+     188                 :            : 
+     189                 :          0 :     *need_continue = false;
+     190                 :            : 
+     191         [ #  # ]:          0 :     if (spdm_context->local_context.verify_peer_spdm_cert_chain != NULL) {
+     192                 :          0 :         result = spdm_context->local_context.verify_peer_spdm_cert_chain (
+     193                 :          0 :             spdm_context, spdm_context->encap_context.req_slot_id,
+     194                 :            :             cert_chain_buffer_size, cert_chain_buffer, NULL, NULL);
+     195         [ #  # ]:          0 :         if (!result) {
+     196                 :          0 :             return LIBSPDM_STATUS_VERIF_FAIL;
+     197                 :            :         }
+     198                 :            :     } else {
+     199                 :          0 :         result = libspdm_verify_peer_cert_chain_buffer_integrity(
+     200                 :            :             spdm_context, cert_chain_buffer, cert_chain_buffer_size);
+     201         [ #  # ]:          0 :         if (!result) {
+     202                 :          0 :             return LIBSPDM_STATUS_VERIF_FAIL;
+     203                 :            :         }
+     204                 :            : 
+     205                 :            :         /*verify peer cert chain authority*/
+     206                 :          0 :         result = libspdm_verify_peer_cert_chain_buffer_authority(
+     207                 :            :             spdm_context, cert_chain_buffer, cert_chain_buffer_size, NULL, NULL);
+     208         [ #  # ]:          0 :         if (!result) {
+     209                 :          0 :             status = LIBSPDM_STATUS_VERIF_NO_AUTHORITY;
+     210                 :            :         }
+     211                 :            :     }
+     212                 :            : 
+     213                 :          0 :     spdm_context->connection_info.peer_used_cert_chain_slot_id =
+     214                 :          0 :         spdm_context->encap_context.req_slot_id;
+     215                 :          0 :     slot_id = spdm_context->encap_context.req_slot_id;
+     216         [ #  # ]:          0 :     LIBSPDM_ASSERT(slot_id < SPDM_MAX_SLOT_COUNT);
+     217                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     218                 :            :     spdm_context->connection_info.peer_used_cert_chain[slot_id].buffer_size =
+     219                 :            :         cert_chain_buffer_size;
+     220                 :            : 
+     221                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[slot_id].buffer,
+     222                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[slot_id].buffer),
+     223                 :            :                      cert_chain_buffer, cert_chain_buffer_size);
+     224                 :            : #else
+     225                 :          0 :     result = libspdm_hash_all(
+     226                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+     227                 :            :         cert_chain_buffer, cert_chain_buffer_size,
+     228                 :          0 :         spdm_context->connection_info.peer_used_cert_chain[slot_id].buffer_hash);
+     229         [ #  # ]:          0 :     if (!result) {
+     230                 :          0 :         return LIBSPDM_STATUS_CRYPTO_ERROR;
+     231                 :            :     }
+     232                 :          0 :     spdm_context->connection_info.peer_used_cert_chain[slot_id].buffer_hash_size =
+     233                 :          0 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+     234                 :            : 
+     235                 :          0 :     result = libspdm_get_leaf_cert_public_key_from_cert_chain(
+     236                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+     237                 :          0 :         spdm_context->connection_info.algorithm.req_base_asym_alg,
+     238                 :            :         cert_chain_buffer, cert_chain_buffer_size,
+     239                 :          0 :         &spdm_context->connection_info.peer_used_cert_chain[slot_id].leaf_cert_public_key);
+     240         [ #  # ]:          0 :     if (!result) {
+     241                 :          0 :         return LIBSPDM_STATUS_INVALID_CERT;
+     242                 :            :     }
+     243                 :            : #endif
+     244         [ #  # ]:          0 :     if (status != LIBSPDM_STATUS_VERIF_NO_AUTHORITY) {
+     245                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     246                 :            :     } else {
+     247                 :          0 :         return LIBSPDM_STATUS_VERIF_NO_AUTHORITY;
+     248                 :            :     }
+     249                 :            : }
+     250                 :            : 
+     251                 :            : #endif /* (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (...) */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_get_digests.c.func-sort-c.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_get_digests.c.func-sort-c.html new file mode 100644 index 00000000000..3c9c6dc932c --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_get_digests.c.func-sort-c.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_encap_get_digests.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_encap_get_digests.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:11112688.1 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:658279.3 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_encap_request_get_digest1
libspdm_process_encap_response_digest11
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_get_digests.c.func.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_get_digests.c.func.html new file mode 100644 index 00000000000..24b560fcc0e --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_get_digests.c.func.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_encap_get_digests.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_encap_get_digests.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:11112688.1 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:658279.3 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_encap_request_get_digest1
libspdm_process_encap_response_digest11
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_get_digests.c.gcov.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_get_digests.c.gcov.html new file mode 100644 index 00000000000..b1f9a29c7c6 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_get_digests.c.gcov.html @@ -0,0 +1,343 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_encap_get_digests.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_encap_get_digests.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:11112688.1 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:658279.3 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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_responder_lib.h"
+       8                 :            : 
+       9                 :            : #if (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP) && \
+      10                 :            :     (LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT)
+      11                 :            : 
+      12                 :          1 : libspdm_return_t libspdm_get_encap_request_get_digest(libspdm_context_t *spdm_context,
+      13                 :            :                                                       size_t *encap_request_size,
+      14                 :            :                                                       void *encap_request)
+      15                 :            : {
+      16                 :            :     spdm_get_digest_request_t *spdm_request;
+      17                 :            :     libspdm_return_t status;
+      18                 :            : 
+      19                 :          1 :     spdm_context->encap_context.last_encap_request_size = 0;
+      20                 :            : 
+      21         [ -  + ]:          1 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_11) {
+      22                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+      23                 :            :     }
+      24                 :            : 
+      25         [ -  + ]:          1 :     if (!libspdm_is_capabilities_flag_supported(
+      26                 :            :             spdm_context, false,
+      27                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP, 0)) {
+      28                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+      29                 :            :     }
+      30                 :            : 
+      31         [ -  + ]:          1 :     LIBSPDM_ASSERT(*encap_request_size >= sizeof(spdm_get_digest_request_t));
+      32                 :          1 :     *encap_request_size = sizeof(spdm_get_digest_request_t);
+      33                 :            : 
+      34                 :          1 :     spdm_request = encap_request;
+      35                 :            : 
+      36                 :          1 :     libspdm_reset_message_buffer_via_request_code(spdm_context, NULL,
+      37                 :          1 :                                                   spdm_request->header.request_response_code);
+      38                 :            : 
+      39                 :          1 :     spdm_request->header.spdm_version = libspdm_get_connection_version (spdm_context);
+      40                 :          1 :     spdm_request->header.request_response_code = SPDM_GET_DIGESTS;
+      41                 :          1 :     spdm_request->header.param1 = 0;
+      42                 :          1 :     spdm_request->header.param2 = 0;
+      43                 :            : 
+      44                 :            : 
+      45                 :            :     /* Cache data*/
+      46                 :            : 
+      47                 :          1 :     status = libspdm_append_message_mut_b(spdm_context, spdm_request,
+      48                 :            :                                           *encap_request_size);
+      49         [ -  + ]:          1 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+      50                 :          0 :         return LIBSPDM_STATUS_BUFFER_FULL;
+      51                 :            :     }
+      52                 :            : 
+      53                 :          1 :     libspdm_copy_mem(&spdm_context->encap_context.last_encap_request_header,
+      54                 :            :                      sizeof(spdm_context->encap_context.last_encap_request_header),
+      55                 :          1 :                      &spdm_request->header, sizeof(spdm_message_header_t));
+      56                 :          1 :     spdm_context->encap_context.last_encap_request_size =
+      57                 :          1 :         *encap_request_size;
+      58                 :            : 
+      59                 :          1 :     return LIBSPDM_STATUS_SUCCESS;
+      60                 :            : }
+      61                 :            : 
+      62                 :         11 : libspdm_return_t libspdm_process_encap_response_digest(
+      63                 :            :     libspdm_context_t *spdm_context, size_t encap_response_size,
+      64                 :            :     const void *encap_response, bool *need_continue)
+      65                 :            : {
+      66                 :            :     const spdm_digest_response_t *spdm_response;
+      67                 :            :     size_t spdm_response_size;
+      68                 :            :     size_t digest_size;
+      69                 :            :     size_t digest_count;
+      70                 :            :     size_t index;
+      71                 :            :     libspdm_return_t status;
+      72                 :            :     uint32_t session_id;
+      73                 :            :     libspdm_session_info_t *session_info;
+      74                 :            :     size_t additional_size;
+      75                 :            :     spdm_key_pair_id_t *key_pair_id;
+      76                 :            :     spdm_certificate_info_t *cert_info;
+      77                 :            :     spdm_key_usage_bit_mask_t *key_usage_bit_mask;
+      78                 :            :     size_t slot_index;
+      79                 :            :     uint8_t cert_model;
+      80                 :         11 :     uint8_t zero_digest[LIBSPDM_MAX_HASH_SIZE] = {0};
+      81                 :            : 
+      82                 :         11 :     spdm_response = encap_response;
+      83                 :         11 :     spdm_response_size = encap_response_size;
+      84                 :            : 
+      85         [ +  + ]:         11 :     if (spdm_response_size < sizeof(spdm_message_header_t)) {
+      86                 :          1 :         return LIBSPDM_STATUS_INVALID_MSG_SIZE;
+      87                 :            :     }
+      88         [ +  + ]:         10 :     if (spdm_response->header.spdm_version != libspdm_get_connection_version (spdm_context)) {
+      89                 :          1 :         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+      90                 :            :     }
+      91         [ +  + ]:          9 :     if (spdm_response->header.request_response_code == SPDM_ERROR) {
+      92                 :          2 :         status = libspdm_handle_encap_error_response_main(
+      93                 :            :             spdm_context,
+      94                 :          2 :             spdm_response->header.param1);
+      95         [ +  - ]:          2 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+      96                 :          2 :             return status;
+      97                 :            :         }
+      98         [ +  + ]:          7 :     } else if (spdm_response->header.request_response_code !=
+      99                 :            :                SPDM_DIGESTS) {
+     100                 :          1 :         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     101                 :            :     }
+     102         [ -  + ]:          6 :     if (spdm_response_size < sizeof(spdm_digest_response_t)) {
+     103                 :          0 :         return LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     104                 :            :     }
+     105                 :            : 
+     106                 :          6 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "provisioned_slot_mask - 0x%02x\n",
+     107                 :            :                    spdm_response->header.param2));
+     108         [ +  + ]:          6 :     if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
+     109                 :          3 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "supported_slot_mask - 0x%02x\n",
+     110                 :            :                        spdm_response->header.param1));
+     111                 :          3 :         if ((spdm_response->header.param1 & spdm_response->header.param2) !=
+     112         [ -  + ]:          3 :             spdm_response->header.param2) {
+     113                 :          0 :             return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     114                 :            :         }
+     115                 :            :     }
+     116                 :            : 
+     117                 :          6 :     digest_size = libspdm_get_hash_size(
+     118                 :            :         spdm_context->connection_info.algorithm.base_hash_algo);
+     119                 :          6 :     digest_count = 0;
+     120         [ +  + ]:         54 :     for (index = 0; index < SPDM_MAX_SLOT_COUNT; index++) {
+     121         [ +  + ]:         48 :         if (spdm_response->header.param2 & (1 << index)) {
+     122                 :         13 :             digest_count++;
+     123                 :            :         }
+     124                 :            :     }
+     125         [ -  + ]:          6 :     if (digest_count == 0) {
+     126                 :          0 :         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     127                 :            :     }
+     128                 :            : 
+     129                 :          6 :     additional_size = 0;
+     130         [ +  + ]:          6 :     if ((spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_13) &&
+     131         [ +  + ]:          3 :         spdm_context->connection_info.multi_key_conn_req) {
+     132                 :          2 :         additional_size = sizeof(spdm_key_pair_id_t) + sizeof(spdm_certificate_info_t) +
+     133                 :            :                           sizeof(spdm_key_usage_bit_mask_t);
+     134                 :            :     }
+     135                 :          6 :     if (spdm_response_size <
+     136         [ -  + ]:          6 :         sizeof(spdm_digest_response_t) + digest_count * (digest_size + additional_size)) {
+     137                 :          0 :         return LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     138                 :            :     }
+     139                 :          6 :     spdm_response_size =
+     140                 :          6 :         sizeof(spdm_digest_response_t) + digest_count * (digest_size + additional_size);
+     141                 :            : 
+     142                 :            :     /* Cache data*/
+     143                 :            : 
+     144                 :          6 :     status = libspdm_append_message_mut_b(spdm_context, spdm_response,
+     145                 :            :                                           spdm_response_size);
+     146         [ -  + ]:          6 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     147                 :          0 :         return LIBSPDM_STATUS_BUFFER_FULL;
+     148                 :            :     }
+     149                 :            : 
+     150         [ +  + ]:          6 :     if (spdm_context->last_spdm_request_session_id_valid) {
+     151                 :          5 :         session_id = spdm_context->last_spdm_request_session_id;
+     152                 :            :     } else {
+     153                 :          1 :         session_id = spdm_context->latest_session_id;
+     154                 :            :     }
+     155         [ +  + ]:          6 :     if (session_id != INVALID_SESSION_ID) {
+     156                 :          5 :         session_info = libspdm_get_session_info_via_session_id(spdm_context, session_id);
+     157                 :            :     } else {
+     158                 :          1 :         session_info = NULL;
+     159                 :            :     }
+     160         [ +  + ]:          6 :     if (session_info != NULL) {
+     161         [ +  + ]:          5 :         if (spdm_context->connection_info.multi_key_conn_req) {
+     162                 :          2 :             status = libspdm_append_message_encap_d(spdm_context, session_info, false,
+     163                 :            :                                                     spdm_response, spdm_response_size);
+     164         [ -  + ]:          2 :             if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     165                 :          0 :                 return LIBSPDM_STATUS_BUFFER_FULL;
+     166                 :            :             }
+     167                 :            :         }
+     168                 :            :     }
+     169                 :            : 
+     170                 :          6 :     key_pair_id =
+     171                 :          6 :         (spdm_key_pair_id_t *)((size_t)(spdm_response + 1) + digest_size * digest_count);
+     172                 :          6 :     cert_info =
+     173                 :            :         (spdm_certificate_info_t *)((uint8_t *)key_pair_id + sizeof(spdm_key_pair_id_t) *
+     174                 :            :                                     digest_count);
+     175                 :          6 :     key_usage_bit_mask =
+     176                 :            :         (spdm_key_usage_bit_mask_t *)((uint8_t *)cert_info + sizeof(spdm_certificate_info_t) *
+     177                 :            :                                       digest_count);
+     178         [ +  + ]:         19 :     for (index = 0; index < digest_count; index++) {
+     179                 :         13 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "digest (0x%zx) - ", index));
+     180                 :         13 :         LIBSPDM_INTERNAL_DUMP_DATA(
+     181                 :            :             (const uint8_t *)(spdm_response + 1) + (digest_size * index), digest_size);
+     182                 :         13 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     183                 :            :     }
+     184         [ +  + ]:          6 :     if ((spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_13) &&
+     185         [ +  + ]:          3 :         spdm_context->connection_info.multi_key_conn_req) {
+     186         [ +  + ]:         11 :         for (index = 0; index < digest_count; index++) {
+     187                 :          9 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "key_pair_id (0x%zx) - 0x%02x\n", index,
+     188                 :            :                            key_pair_id[index]));
+     189                 :            :         }
+     190         [ +  + ]:         11 :         for (index = 0; index < digest_count; index++) {
+     191                 :          9 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "cert_info (0x%zx) - 0x%02x\n", index,
+     192                 :            :                            cert_info[index]));
+     193                 :            :         }
+     194         [ +  + ]:         11 :         for (index = 0; index < digest_count; index++) {
+     195                 :          9 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "key_usage_bit_mask (0x%zx) - 0x%04x\n", index,
+     196                 :            :                            key_usage_bit_mask[index]));
+     197                 :            :         }
+     198                 :            :     }
+     199                 :            : 
+     200                 :          6 :     spdm_context->connection_info.peer_provisioned_slot_mask = spdm_response->header.param2;
+     201         [ +  + ]:          6 :     if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
+     202                 :          3 :         spdm_context->connection_info.peer_supported_slot_mask = spdm_response->header.param1;
+     203                 :            :     } else {
+     204                 :          3 :         spdm_context->connection_info.peer_supported_slot_mask = spdm_response->header.param2;
+     205                 :            :     }
+     206                 :          6 :     libspdm_copy_mem(
+     207                 :          6 :         spdm_context->connection_info.peer_total_digest_buffer,
+     208                 :            :         sizeof(spdm_context->connection_info.peer_total_digest_buffer),
+     209                 :          6 :         spdm_response + 1, digest_size * digest_count);
+     210                 :          6 :     libspdm_zero_mem(spdm_context->connection_info.peer_key_pair_id,
+     211                 :            :                      sizeof(spdm_context->connection_info.peer_key_pair_id));
+     212                 :          6 :     libspdm_zero_mem(spdm_context->connection_info.peer_cert_info,
+     213                 :            :                      sizeof(spdm_context->connection_info.peer_cert_info));
+     214                 :          6 :     libspdm_zero_mem(spdm_context->connection_info.peer_key_usage_bit_mask,
+     215                 :            :                      sizeof(spdm_context->connection_info.peer_key_usage_bit_mask));
+     216         [ +  + ]:          6 :     if ((spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_13) &&
+     217         [ +  + ]:          3 :         spdm_context->connection_info.multi_key_conn_req) {
+     218                 :          2 :         slot_index = 0;
+     219         [ +  + ]:         18 :         for (index = 0; index < SPDM_MAX_SLOT_COUNT; index++) {
+     220         [ +  + ]:         16 :             if (spdm_response->header.param2 & (1 << index)) {
+     221                 :          9 :                 spdm_context->connection_info.peer_key_pair_id[index] = key_pair_id[slot_index];
+     222                 :          9 :                 cert_model = cert_info[slot_index] & SPDM_CERTIFICATE_INFO_CERT_MODEL_MASK;
+     223         [ -  + ]:          9 :                 if (cert_model > SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT) {
+     224                 :          0 :                     return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     225                 :            :                 }
+     226         [ +  + ]:          9 :                 if (index == 0) {
+     227         [ -  + ]:          2 :                     if (cert_model == SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT) {
+     228                 :          0 :                         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     229                 :            :                     }
+     230         [ -  + ]:          2 :                     if ((key_usage_bit_mask[slot_index] &
+     231                 :            :                          (SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE |
+     232                 :            :                           SPDM_KEY_USAGE_BIT_MASK_CHALLENGE_USE |
+     233                 :            :                           SPDM_KEY_USAGE_BIT_MASK_MEASUREMENT_USE |
+     234                 :            :                           SPDM_KEY_USAGE_BIT_MASK_ENDPOINT_INFO_USE)) == 0) {
+     235                 :          0 :                         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     236                 :            :                     }
+     237                 :            :                 }
+     238         [ -  + ]:          9 :                 if ((cert_model == SPDM_CERTIFICATE_INFO_CERT_MODEL_NONE) &&
+     239         [ #  # ]:          0 :                     (!libspdm_consttime_is_mem_equal(
+     240                 :          0 :                          (const uint8_t *)(spdm_response + 1) + digest_size * slot_index,
+     241                 :            :                          zero_digest,
+     242                 :            :                          digest_size))) {
+     243                 :          0 :                     return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     244                 :            :                 }
+     245                 :          9 :                 spdm_context->connection_info.peer_cert_info[index] = cert_model;
+     246                 :          9 :                 spdm_context->connection_info.peer_key_usage_bit_mask[index] =
+     247                 :          9 :                     key_usage_bit_mask[slot_index];
+     248                 :          9 :                 slot_index++;
+     249                 :            :             }
+     250                 :            :         }
+     251                 :            :     }
+     252                 :            : 
+     253                 :          6 :     *need_continue = false;
+     254                 :            : 
+     255                 :          6 :     return LIBSPDM_STATUS_SUCCESS;
+     256                 :            : }
+     257                 :            : 
+     258                 :            : #endif /* (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (...) */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_key_update.c.func-sort-c.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_key_update.c.func-sort-c.html new file mode 100644 index 00000000000..0fecf28c177 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_key_update.c.func-sort-c.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_encap_key_update.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_encap_key_update.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:578170.4 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:244652.2 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_encap_request_key_update2
libspdm_process_encap_response_key_update6
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_key_update.c.func.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_key_update.c.func.html new file mode 100644 index 00000000000..0e8cbf9f9fc --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_key_update.c.func.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_encap_key_update.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_encap_key_update.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:578170.4 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:244652.2 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_encap_request_key_update2
libspdm_process_encap_response_key_update6
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_key_update.c.gcov.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_key_update.c.gcov.html new file mode 100644 index 00000000000..98a0cd6544f --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_key_update.c.gcov.html @@ -0,0 +1,301 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_encap_key_update.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_encap_key_update.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:578170.4 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:244652.2 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 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_responder_lib.h"
+       8                 :            : #include "internal/libspdm_secured_message_lib.h"
+       9                 :            : 
+      10                 :            : #if LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP
+      11                 :            : 
+      12                 :            : /**
+      13                 :            :  * Get the SPDM encapsulated KEY_UPDATE request.
+      14                 :            :  *
+      15                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+      16                 :            :  * @param  encap_request_size             size in bytes of the encapsulated request data.
+      17                 :            :  *                                     On input, it means the size in bytes of encapsulated request data buffer.
+      18                 :            :  *                                     On output, it means the size in bytes of copied encapsulated request data buffer if RETURN_SUCCESS is returned,
+      19                 :            :  *                                     and means the size in bytes of desired encapsulated request data buffer if RETURN_BUFFER_TOO_SMALL is returned.
+      20                 :            :  * @param  encap_request                 A pointer to the encapsulated request data.
+      21                 :            :  *
+      22                 :            :  * @retval RETURN_SUCCESS               The encapsulated request is returned.
+      23                 :            :  * @retval RETURN_BUFFER_TOO_SMALL      The buffer is too small to hold the data.
+      24                 :            :  **/
+      25                 :            : libspdm_return_t
+      26                 :          2 : libspdm_get_encap_request_key_update(libspdm_context_t *spdm_context,
+      27                 :            :                                      size_t *encap_request_size,
+      28                 :            :                                      void *encap_request)
+      29                 :            : {
+      30                 :            :     spdm_key_update_request_t *spdm_request;
+      31                 :            :     uint32_t session_id;
+      32                 :            :     libspdm_session_info_t *session_info;
+      33                 :            :     libspdm_session_state_t session_state;
+      34                 :            :     bool result;
+      35                 :            : 
+      36                 :          2 :     spdm_context->encap_context.last_encap_request_size = 0;
+      37                 :            : 
+      38         [ -  + ]:          2 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_11) {
+      39                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+      40                 :            :     }
+      41                 :            : 
+      42         [ -  + ]:          2 :     if (!libspdm_is_capabilities_flag_supported(
+      43                 :            :             spdm_context, false,
+      44                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP,
+      45                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_UPD_CAP)) {
+      46                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+      47                 :            :     }
+      48                 :            : 
+      49         [ -  + ]:          2 :     if (!spdm_context->last_spdm_request_session_id_valid) {
+      50                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+      51                 :            :     }
+      52                 :          2 :     session_id = spdm_context->last_spdm_request_session_id;
+      53                 :            :     session_info =
+      54                 :          2 :         libspdm_get_session_info_via_session_id(spdm_context, session_id);
+      55         [ -  + ]:          2 :     if (session_info == NULL) {
+      56                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+      57                 :            :     }
+      58                 :          2 :     session_state = libspdm_secured_message_get_session_state(
+      59                 :            :         session_info->secured_message_context);
+      60         [ -  + ]:          2 :     if (session_state != LIBSPDM_SESSION_STATE_ESTABLISHED) {
+      61                 :          0 :         return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+      62                 :            :     }
+      63                 :            : 
+      64         [ -  + ]:          2 :     LIBSPDM_ASSERT(*encap_request_size >= sizeof(spdm_key_update_request_t));
+      65                 :          2 :     *encap_request_size = sizeof(spdm_key_update_request_t);
+      66                 :            : 
+      67                 :          2 :     spdm_request = encap_request;
+      68                 :            : 
+      69                 :          2 :     spdm_request->header.spdm_version = libspdm_get_connection_version (spdm_context);
+      70                 :          2 :     spdm_request->header.request_response_code = SPDM_KEY_UPDATE;
+      71                 :            : 
+      72                 :          2 :     libspdm_reset_message_buffer_via_request_code(spdm_context, session_info,
+      73                 :          2 :                                                   spdm_request->header.request_response_code);
+      74                 :            : 
+      75                 :          2 :     if (spdm_context->encap_context.last_encap_request_header
+      76         [ +  - ]:          2 :         .request_response_code != SPDM_KEY_UPDATE) {
+      77                 :          2 :         spdm_request->header.param1 =
+      78                 :            :             SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY;
+      79                 :          2 :         spdm_request->header.param2 = 0;
+      80         [ -  + ]:          2 :         if(!libspdm_get_random_number(sizeof(spdm_request->header.param2),
+      81                 :            :                                       &spdm_request->header.param2)) {
+      82                 :          0 :             return LIBSPDM_STATUS_LOW_ENTROPY;
+      83                 :            :         }
+      84                 :            :     } else {
+      85                 :          0 :         spdm_request->header.param1 =
+      86                 :            :             SPDM_KEY_UPDATE_OPERATIONS_TABLE_VERIFY_NEW_KEY;
+      87                 :          0 :         spdm_request->header.param2 = 1;
+      88         [ #  # ]:          0 :         if(!libspdm_get_random_number(sizeof(spdm_request->header.param2),
+      89                 :            :                                       &spdm_request->header.param2)) {
+      90                 :          0 :             return LIBSPDM_STATUS_LOW_ENTROPY;
+      91                 :            :         }
+      92                 :            : 
+      93                 :            :         /* Create new key*/
+      94                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+      95                 :            :                        "libspdm_create_update_session_data_key[%x] Responder\n",
+      96                 :            :                        session_id));
+      97                 :          0 :         result = libspdm_create_update_session_data_key(
+      98                 :            :             session_info->secured_message_context,
+      99                 :            :             LIBSPDM_KEY_UPDATE_ACTION_RESPONDER);
+     100         [ #  # ]:          0 :         if (!result) {
+     101                 :          0 :             return LIBSPDM_STATUS_CRYPTO_ERROR;
+     102                 :            :         }
+     103                 :          0 :         libspdm_trigger_key_update_callback(
+     104                 :            :             spdm_context, session_id, LIBSPDM_KEY_UPDATE_OPERATION_CREATE_UPDATE,
+     105                 :            :             LIBSPDM_KEY_UPDATE_ACTION_RESPONDER);
+     106                 :            : 
+     107                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+     108                 :            :                        "libspdm_activate_update_session_data_key[%x] Responder new\n",
+     109                 :            :                        session_id));
+     110                 :          0 :         result = libspdm_activate_update_session_data_key(
+     111                 :            :             session_info->secured_message_context,
+     112                 :            :             LIBSPDM_KEY_UPDATE_ACTION_RESPONDER, true);
+     113         [ #  # ]:          0 :         if (!result) {
+     114                 :          0 :             return LIBSPDM_STATUS_CRYPTO_ERROR;
+     115                 :            :         }
+     116                 :          0 :         libspdm_trigger_key_update_callback(
+     117                 :            :             spdm_context, session_id, LIBSPDM_KEY_UPDATE_OPERATION_COMMIT_UPDATE,
+     118                 :            :             LIBSPDM_KEY_UPDATE_ACTION_RESPONDER);
+     119                 :            :     }
+     120                 :            : 
+     121                 :          2 :     libspdm_copy_mem(&spdm_context->encap_context.last_encap_request_header,
+     122                 :            :                      sizeof(spdm_context->encap_context.last_encap_request_header),
+     123                 :          2 :                      &spdm_request->header, sizeof(spdm_message_header_t));
+     124                 :          2 :     spdm_context->encap_context.last_encap_request_size =
+     125                 :          2 :         *encap_request_size;
+     126                 :            : 
+     127                 :          2 :     return LIBSPDM_STATUS_SUCCESS;
+     128                 :            : }
+     129                 :            : 
+     130                 :            : /**
+     131                 :            :  * Process the SPDM encapsulated KEY_UPDATE response.
+     132                 :            :  *
+     133                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     134                 :            :  * @param  encap_response_size            size in bytes of the encapsulated response data.
+     135                 :            :  * @param  encap_response                A pointer to the encapsulated response data.
+     136                 :            :  * @param  need_continue                     Indicate if encapsulated communication need continue.
+     137                 :            :  *
+     138                 :            :  * @retval RETURN_SUCCESS               The encapsulated response is processed.
+     139                 :            :  * @retval RETURN_BUFFER_TOO_SMALL      The buffer is too small to hold the data.
+     140                 :            :  * @retval RETURN_SECURITY_VIOLATION    Any verification fails.
+     141                 :            :  **/
+     142                 :          6 : libspdm_return_t libspdm_process_encap_response_key_update(
+     143                 :            :     libspdm_context_t *spdm_context, size_t encap_response_size,
+     144                 :            :     const void *encap_response, bool *need_continue)
+     145                 :            : {
+     146                 :            :     spdm_key_update_request_t *spdm_request;
+     147                 :            :     const spdm_key_update_response_t *spdm_response;
+     148                 :            :     size_t spdm_response_size;
+     149                 :            :     uint32_t session_id;
+     150                 :            :     libspdm_session_info_t *session_info;
+     151                 :            :     libspdm_session_state_t session_state;
+     152                 :            : 
+     153         [ +  + ]:          6 :     if (!spdm_context->last_spdm_request_session_id_valid) {
+     154                 :          1 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     155                 :            :     }
+     156                 :          5 :     session_id = spdm_context->last_spdm_request_session_id;
+     157                 :            :     session_info =
+     158                 :          5 :         libspdm_get_session_info_via_session_id(spdm_context, session_id);
+     159         [ -  + ]:          5 :     if (session_info == NULL) {
+     160                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     161                 :            :     }
+     162                 :          5 :     session_state = libspdm_secured_message_get_session_state(
+     163                 :            :         session_info->secured_message_context);
+     164         [ -  + ]:          5 :     if (session_state != LIBSPDM_SESSION_STATE_ESTABLISHED) {
+     165                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     166                 :            :     }
+     167                 :            : 
+     168                 :          5 :     spdm_request =
+     169                 :            :         (void *)&spdm_context->encap_context.last_encap_request_header;
+     170                 :            : 
+     171                 :          5 :     spdm_response = encap_response;
+     172                 :          5 :     spdm_response_size = encap_response_size;
+     173                 :            : 
+     174         [ -  + ]:          5 :     if (spdm_response->header.spdm_version != libspdm_get_connection_version (spdm_context)) {
+     175                 :          0 :         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     176                 :            :     }
+     177                 :            : 
+     178         [ +  + ]:          5 :     if (spdm_response->header.request_response_code == SPDM_ERROR) {
+     179         [ +  - ]:          1 :         if (spdm_response->header.param1 == SPDM_ERROR_CODE_DECRYPT_ERROR) {
+     180                 :          1 :             libspdm_free_session_id(spdm_context, session_id);
+     181                 :          1 :             return LIBSPDM_STATUS_SESSION_MSG_ERROR;
+     182                 :            :         }
+     183                 :            :     }
+     184                 :            : 
+     185                 :            :     /* this message can only be in secured session
+     186                 :            :      * thus don't need to consider transport layer padding, just check its exact size */
+     187         [ +  - ]:          4 :     if ((spdm_response_size != sizeof(spdm_key_update_response_t)) ||
+     188         [ +  - ]:          4 :         (spdm_response->header.request_response_code !=
+     189                 :          4 :          SPDM_KEY_UPDATE_ACK) ||
+     190         [ +  + ]:          4 :         (spdm_response->header.param1 != spdm_request->header.param1) ||
+     191         [ -  + ]:          3 :         (spdm_response->header.param2 != spdm_request->header.param2)) {
+     192         [ +  - ]:          1 :         if (spdm_request->header.param1 !=
+     193                 :            :             SPDM_KEY_UPDATE_OPERATIONS_TABLE_VERIFY_NEW_KEY) {
+     194                 :          1 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "libspdm_key_update[%x] failed\n",
+     195                 :            :                            session_id));
+     196                 :            :         } else {
+     197                 :          0 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "SpdmVerifyKey[%x] failed\n",
+     198                 :            :                            session_id));
+     199                 :            :         }
+     200                 :          1 :         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     201                 :            :     }
+     202                 :            : 
+     203         [ +  + ]:          3 :     if (spdm_request->header.param1 !=
+     204                 :            :         SPDM_KEY_UPDATE_OPERATIONS_TABLE_VERIFY_NEW_KEY) {
+     205                 :          2 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "libspdm_key_update[%x] success\n",
+     206                 :            :                        session_id));
+     207                 :          2 :         *need_continue = true;
+     208                 :            :     } else {
+     209                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "SpdmVerifyKey[%x] Success\n", session_id));
+     210                 :          1 :         *need_continue = false;
+     211                 :            :     }
+     212                 :            : 
+     213                 :          3 :     return LIBSPDM_STATUS_SUCCESS;
+     214                 :            : }
+     215                 :            : 
+     216                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_response.c.func-sort-c.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_response.c.func-sort-c.html new file mode 100644 index 00000000000..3242cf4d88a --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_response.c.func-sort-c.html @@ -0,0 +1,117 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_encap_response.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_encap_response.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:12621957.5 %
Date:2024-09-22 08:21:07Functions:6966.7 %
Branches:5711350.4 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_init_basic_mut_auth_encap_state0
libspdm_init_key_update_encap_state0
libspdm_init_mut_auth_encap_state0
libspdm_handle_encap_error_response_main5
libspdm_encap_move_to_next_op_code6
libspdm_get_response_encapsulated_request6
libspdm_get_response_encapsulated_response_ack9
libspdm_process_encapsulated_response9
libspdm_get_encap_struct_via_op_code11
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_response.c.func.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_response.c.func.html new file mode 100644 index 00000000000..927187c5b4d --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_response.c.func.html @@ -0,0 +1,117 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_encap_response.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_encap_response.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:12621957.5 %
Date:2024-09-22 08:21:07Functions:6966.7 %
Branches:5711350.4 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_encap_move_to_next_op_code6
libspdm_get_encap_struct_via_op_code11
libspdm_get_response_encapsulated_request6
libspdm_get_response_encapsulated_response_ack9
libspdm_handle_encap_error_response_main5
libspdm_init_basic_mut_auth_encap_state0
libspdm_init_key_update_encap_state0
libspdm_init_mut_auth_encap_state0
libspdm_process_encapsulated_response9
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_response.c.gcov.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_response.c.gcov.html new file mode 100644 index 00000000000..65babca4221 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_encap_response.c.gcov.html @@ -0,0 +1,620 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_encap_response.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_encap_response.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:12621957.5 %
Date:2024-09-22 08:21:07Functions:6966.7 %
Branches:5711350.4 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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_responder_lib.h"
+       8                 :            : 
+       9                 :            : #if LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP
+      10                 :            : 
+      11                 :            : /**
+      12                 :            :  * Get the SPDM encapsulated request.
+      13                 :            :  *
+      14                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+      15                 :            :  * @param  encap_request_size             size in bytes of the encapsulated request data.
+      16                 :            :  *                                     On input, it means the size in bytes of encapsulated request data buffer.
+      17                 :            :  *                                     On output, it means the size in bytes of copied encapsulated request data buffer if RETURN_SUCCESS is returned,
+      18                 :            :  *                                     and means the size in bytes of desired encapsulated request data buffer if RETURN_BUFFER_TOO_SMALL is returned.
+      19                 :            :  * @param  encap_request                 A pointer to the encapsulated request data.
+      20                 :            :  *
+      21                 :            :  * @retval RETURN_SUCCESS               The encapsulated request is returned.
+      22                 :            :  * @retval RETURN_BUFFER_TOO_SMALL      The buffer is too small to hold the data.
+      23                 :            :  **/
+      24                 :            : typedef libspdm_return_t (*libspdm_get_encap_request_func)(
+      25                 :            :     libspdm_context_t *spdm_context, size_t *encap_request_size,
+      26                 :            :     void *encap_request);
+      27                 :            : 
+      28                 :            : /**
+      29                 :            :  * Process the SPDM encapsulated response.
+      30                 :            :  *
+      31                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+      32                 :            :  * @param  encap_response_size            size in bytes of the encapsulated response data.
+      33                 :            :  * @param  encap_response                A pointer to the encapsulated response data.
+      34                 :            :  * @param  need_continue                     Indicate if encapsulated communication need continue.
+      35                 :            :  *
+      36                 :            :  * @retval RETURN_SUCCESS               The encapsulated response is processed.
+      37                 :            :  * @retval RETURN_BUFFER_TOO_SMALL      The buffer is too small to hold the data.
+      38                 :            :  * @retval RETURN_SECURITY_VIOLATION    Any verification fails.
+      39                 :            :  **/
+      40                 :            : typedef libspdm_return_t (*libspdm_process_encap_response_func)(
+      41                 :            :     libspdm_context_t *spdm_context, size_t encap_response_size,
+      42                 :            :     const void *encap_response, bool *need_continue);
+      43                 :            : 
+      44                 :            : typedef struct {
+      45                 :            :     uint8_t request_op_code;
+      46                 :            :     libspdm_get_encap_request_func get_encap_request;
+      47                 :            :     libspdm_process_encap_response_func process_encap_response;
+      48                 :            : } libspdm_encap_response_struct_t;
+      49                 :            : 
+      50                 :         11 : static libspdm_return_t libspdm_get_encap_struct_via_op_code
+      51                 :            :     (uint8_t request_op_code, libspdm_encap_response_struct_t *encap_struct)
+      52                 :            : {
+      53                 :            :     size_t index;
+      54                 :            : 
+      55                 :         11 :     libspdm_encap_response_struct_t encap_response_struct[] = {
+      56                 :            :         #if (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT)
+      57                 :            :         { SPDM_GET_DIGESTS, libspdm_get_encap_request_get_digest,
+      58                 :            :           libspdm_process_encap_response_digest },
+      59                 :            : 
+      60                 :            :         { SPDM_GET_CERTIFICATE, libspdm_get_encap_request_get_certificate,
+      61                 :            :           libspdm_process_encap_response_certificate },
+      62                 :            :         #endif /* (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (...) */
+      63                 :            : 
+      64                 :            :         #if (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_SEND_CHALLENGE_SUPPORT)
+      65                 :            :         { SPDM_CHALLENGE, libspdm_get_encap_request_challenge,
+      66                 :            :           libspdm_process_encap_response_challenge_auth },
+      67                 :            :         #endif /* (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_SEND_CHALLENGE_SUPPORT) */
+      68                 :            : 
+      69                 :            :         { SPDM_KEY_UPDATE, libspdm_get_encap_request_key_update,
+      70                 :            :           libspdm_process_encap_response_key_update },
+      71                 :            :     };
+      72                 :            : 
+      73         [ +  - ]:         25 :     for (index = 0; index < LIBSPDM_ARRAY_SIZE(encap_response_struct); index++) {
+      74         [ +  + ]:         25 :         if (encap_response_struct[index].request_op_code == request_op_code) {
+      75                 :         11 :             libspdm_copy_mem(encap_struct, sizeof(libspdm_encap_response_struct_t),
+      76                 :         11 :                              &encap_response_struct[index],
+      77                 :            :                              sizeof(libspdm_encap_response_struct_t));
+      78                 :         11 :             return LIBSPDM_STATUS_SUCCESS;
+      79                 :            :         }
+      80                 :            :     }
+      81                 :          0 :     LIBSPDM_ASSERT(false);
+      82                 :          0 :     return LIBSPDM_STATUS_INVALID_PARAMETER;
+      83                 :            : }
+      84                 :            : 
+      85                 :          6 : static void libspdm_encap_move_to_next_op_code(libspdm_context_t *spdm_context)
+      86                 :            : {
+      87                 :            :     uint8_t index;
+      88                 :            : 
+      89         [ -  + ]:          6 :     LIBSPDM_ASSERT(spdm_context->encap_context.request_op_code_count <=
+      90                 :            :                    LIBSPDM_MAX_ENCAP_REQUEST_OP_CODE_SEQUENCE_COUNT);
+      91         [ +  + ]:          6 :     if (spdm_context->encap_context.current_request_op_code == 0) {
+      92                 :          4 :         spdm_context->encap_context.current_request_op_code =
+      93                 :          4 :             spdm_context->encap_context.request_op_code_sequence[0];
+      94                 :          4 :         return;
+      95                 :            :     }
+      96                 :          2 :     for (index = 0;
+      97         [ +  - ]:          2 :          index < spdm_context->encap_context.request_op_code_count;
+      98                 :          0 :          index++) {
+      99                 :          2 :         if (spdm_context->encap_context.current_request_op_code ==
+     100         [ +  - ]:          2 :             spdm_context->encap_context.request_op_code_sequence[index]) {
+     101                 :          2 :             spdm_context->encap_context.current_request_op_code =
+     102                 :            :                 spdm_context->encap_context
+     103                 :          2 :                 .request_op_code_sequence[index + 1];
+     104                 :          2 :             return;
+     105                 :            :         }
+     106                 :            :     }
+     107                 :          0 :     LIBSPDM_ASSERT(false);
+     108                 :            : }
+     109                 :            : 
+     110                 :            : /**
+     111                 :            :  * Process a SPDM encapsulated response.
+     112                 :            :  *
+     113                 :            :  * @param  spdm_context                  The SPDM context for the device.
+     114                 :            :  * @param  encap_response_size            size in bytes of the request data.
+     115                 :            :  * @param  encap_response                A pointer to the request data.
+     116                 :            :  * @param  encap_request_size             size in bytes of the response data.
+     117                 :            :  * @param  encap_request                 A pointer to the response data.
+     118                 :            :  *
+     119                 :            :  * @retval RETURN_SUCCESS               The SPDM encapsulated request is generated successfully.
+     120                 :            :  * @retval RETURN_UNSUPPORTED           Do not know how to process the request.
+     121                 :            :  **/
+     122                 :          9 : static libspdm_return_t libspdm_process_encapsulated_response(
+     123                 :            :     libspdm_context_t *spdm_context, size_t encap_response_size,
+     124                 :            :     const void *encap_response, size_t *encap_request_size,
+     125                 :            :     void *encap_request)
+     126                 :            : {
+     127                 :            :     libspdm_return_t status;
+     128                 :            :     bool need_continue;
+     129                 :            :     libspdm_encap_response_struct_t encap_response_struct;
+     130                 :            : 
+     131                 :            :     /* Process previous response*/
+     132                 :          9 :     need_continue = false;
+     133                 :            : 
+     134         [ +  + ]:          9 :     if (spdm_context->encap_context.current_request_op_code != 0) {
+     135                 :          5 :         status = libspdm_get_encap_struct_via_op_code(
+     136                 :          5 :             spdm_context->encap_context.current_request_op_code, &encap_response_struct);
+     137         [ -  + ]:          5 :         LIBSPDM_ASSERT(status == LIBSPDM_STATUS_SUCCESS);
+     138         [ -  + ]:          5 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     139                 :          0 :             return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     140                 :            :         }
+     141         [ -  + ]:          5 :         LIBSPDM_ASSERT(encap_response_struct.process_encap_response != NULL);
+     142         [ -  + ]:          5 :         if (encap_response_struct.process_encap_response == NULL) {
+     143                 :          0 :             return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     144                 :            :         }
+     145                 :          5 :         status = encap_response_struct.process_encap_response(
+     146                 :            :             spdm_context, encap_response_size, encap_response,
+     147                 :            :             &need_continue);
+     148         [ +  + ]:          5 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     149                 :            :             /* If the Requester delivers an encapsulated ERROR message with a ResponseNotReady error code,
+     150                 :            :              * the Responder shall terminate the encapsulated request flow by setting Param2 in
+     151                 :            :              * the corresponding ENCAPSULATED_RESPONSE_ACK response message to a value of zero. */
+     152         [ +  - ]:          1 :             if (status == LIBSPDM_STATUS_NOT_READY_PEER) {
+     153                 :          1 :                 *encap_request_size = 0;
+     154                 :          1 :                 spdm_context->encap_context.current_request_op_code = 0;
+     155                 :          1 :                 return LIBSPDM_STATUS_SUCCESS;
+     156                 :            :             } else {
+     157                 :          0 :                 return status;
+     158                 :            :             }
+     159                 :            :         }
+     160                 :            :     }
+     161                 :            : 
+     162                 :          8 :     spdm_context->encap_context.request_id += 1;
+     163                 :            : 
+     164                 :            :     /* Move to next request*/
+     165         [ +  + ]:          8 :     if (!need_continue) {
+     166                 :          6 :         libspdm_encap_move_to_next_op_code(spdm_context);
+     167                 :            :     }
+     168                 :            : 
+     169         [ +  + ]:          8 :     if (spdm_context->encap_context.current_request_op_code == 0) {
+     170                 :            :         /* No more work to do - stop*/
+     171                 :          2 :         *encap_request_size = 0;
+     172                 :          2 :         spdm_context->encap_context.current_request_op_code = 0;
+     173                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     174                 :            :     }
+     175                 :            : 
+     176                 :            :     /* Process the next request*/
+     177                 :          6 :     status = libspdm_get_encap_struct_via_op_code(
+     178                 :          6 :         spdm_context->encap_context.current_request_op_code, &encap_response_struct);
+     179         [ -  + ]:          6 :     LIBSPDM_ASSERT(status == LIBSPDM_STATUS_SUCCESS);
+     180         [ -  + ]:          6 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     181                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     182                 :            :     }
+     183         [ -  + ]:          6 :     LIBSPDM_ASSERT(encap_response_struct.get_encap_request != NULL);
+     184         [ -  + ]:          6 :     if (encap_response_struct.get_encap_request == NULL) {
+     185                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     186                 :            :     }
+     187                 :          6 :     status = encap_response_struct.get_encap_request(
+     188                 :            :         spdm_context, encap_request_size, encap_request);
+     189                 :          6 :     return status;
+     190                 :            : }
+     191                 :            : 
+     192                 :          0 : void libspdm_init_key_update_encap_state(void *spdm_context)
+     193                 :            : {
+     194                 :            :     libspdm_context_t *context;
+     195                 :            : 
+     196                 :          0 :     context = spdm_context;
+     197                 :            : 
+     198                 :          0 :     context->encap_context.current_request_op_code = 0x00;
+     199                 :          0 :     context->encap_context.request_id = 0;
+     200                 :          0 :     context->encap_context.last_encap_request_size = 0;
+     201                 :          0 :     libspdm_zero_mem(&context->encap_context.last_encap_request_header,
+     202                 :            :                      sizeof(context->encap_context.last_encap_request_header));
+     203                 :          0 :     context->response_state = LIBSPDM_RESPONSE_STATE_PROCESSING_ENCAP;
+     204                 :            : 
+     205                 :          0 :     libspdm_reset_message_mut_b(context);
+     206                 :          0 :     libspdm_reset_message_mut_c(context);
+     207                 :            : 
+     208                 :          0 :     libspdm_zero_mem(context->encap_context.request_op_code_sequence,
+     209                 :            :                      sizeof(context->encap_context.request_op_code_sequence));
+     210                 :          0 :     context->encap_context.request_op_code_count = 1;
+     211                 :          0 :     context->encap_context.request_op_code_sequence[0] = SPDM_KEY_UPDATE;
+     212                 :          0 : }
+     213                 :            : 
+     214                 :          6 : libspdm_return_t libspdm_get_response_encapsulated_request(
+     215                 :            :     libspdm_context_t *spdm_context, size_t request_size, const void *request,
+     216                 :            :     size_t *response_size, void *response)
+     217                 :            : {
+     218                 :            :     spdm_encapsulated_request_response_t *spdm_response;
+     219                 :            :     void *encap_request;
+     220                 :            :     size_t encap_request_size;
+     221                 :            :     libspdm_return_t status;
+     222                 :            :     const spdm_get_encapsulated_request_request_t *spdm_request;
+     223                 :            : 
+     224                 :          6 :     spdm_request = request;
+     225                 :            : 
+     226         [ -  + ]:          6 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_11) {
+     227                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     228                 :            :                                                SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+     229                 :            :                                                SPDM_GET_ENCAPSULATED_REQUEST,
+     230                 :            :                                                response_size, response);
+     231                 :            :     }
+     232                 :            : 
+     233         [ -  + ]:          6 :     if (!libspdm_is_encap_supported(spdm_context)) {
+     234                 :          0 :         return libspdm_generate_error_response(
+     235                 :            :             spdm_context, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+     236                 :            :             SPDM_GET_ENCAPSULATED_REQUEST, response_size, response);
+     237                 :            :     }
+     238         [ +  + ]:          6 :     if (spdm_context->response_state != LIBSPDM_RESPONSE_STATE_PROCESSING_ENCAP) {
+     239         [ +  + ]:          2 :         if (spdm_context->response_state == LIBSPDM_RESPONSE_STATE_NORMAL) {
+     240                 :          1 :             return libspdm_generate_error_response(
+     241                 :            :                 spdm_context,
+     242                 :            :                 SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+     243                 :            :                 response_size, response);
+     244                 :            :         }
+     245                 :          1 :         return libspdm_responder_handle_response_state(
+     246                 :            :             spdm_context,
+     247                 :          1 :             spdm_request->header.request_response_code,
+     248                 :            :             response_size, response);
+     249                 :            :     }
+     250                 :            : 
+     251         [ -  + ]:          4 :     if (request_size < sizeof(spdm_get_encapsulated_request_request_t)) {
+     252                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     253                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     254                 :            :                                                response_size, response);
+     255                 :            :     }
+     256                 :            : 
+     257                 :          4 :     libspdm_reset_message_buffer_via_request_code(spdm_context, NULL,
+     258                 :          4 :                                                   spdm_request->header.request_response_code);
+     259                 :            : 
+     260         [ -  + ]:          4 :     LIBSPDM_ASSERT(*response_size > sizeof(spdm_encapsulated_request_response_t));
+     261                 :          4 :     libspdm_zero_mem(response, *response_size);
+     262                 :            : 
+     263                 :          4 :     spdm_response = response;
+     264                 :          4 :     spdm_response->header.spdm_version = spdm_request->header.spdm_version;
+     265                 :          4 :     spdm_response->header.request_response_code = SPDM_ENCAPSULATED_REQUEST;
+     266                 :          4 :     spdm_response->header.param1 = 0;
+     267                 :          4 :     spdm_response->header.param2 = 0;
+     268                 :            : 
+     269                 :          4 :     encap_request_size =
+     270                 :          4 :         *response_size - sizeof(spdm_encapsulated_request_response_t);
+     271                 :          4 :     encap_request = spdm_response + 1;
+     272                 :            : 
+     273                 :          4 :     status = libspdm_process_encapsulated_response(
+     274                 :            :         spdm_context, 0, NULL, &encap_request_size, encap_request);
+     275         [ -  + ]:          4 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     276                 :          0 :         spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+     277                 :          0 :         return libspdm_generate_error_response(
+     278                 :            :             spdm_context, SPDM_ERROR_CODE_INVALID_RESPONSE_CODE, 0,
+     279                 :            :             response_size, response);
+     280                 :            :     }
+     281                 :          4 :     *response_size = sizeof(spdm_encapsulated_request_response_t) +
+     282                 :            :                      encap_request_size;
+     283                 :          4 :     spdm_response->header.param1 = spdm_context->encap_context.request_id;
+     284                 :            : 
+     285         [ -  + ]:          4 :     if (encap_request_size == 0) {
+     286                 :          0 :         spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+     287                 :            :     }
+     288                 :            : 
+     289                 :          4 :     return LIBSPDM_STATUS_SUCCESS;
+     290                 :            : }
+     291                 :            : 
+     292                 :          9 : libspdm_return_t libspdm_get_response_encapsulated_response_ack(
+     293                 :            :     libspdm_context_t *spdm_context, size_t request_size, const void *request,
+     294                 :            :     size_t *response_size, void *response)
+     295                 :            : {
+     296                 :            :     const spdm_deliver_encapsulated_response_request_t *spdm_request;
+     297                 :            :     size_t spdm_request_size;
+     298                 :            :     spdm_encapsulated_response_ack_response_t *spdm_response;
+     299                 :            :     const void *encap_response;
+     300                 :            :     size_t encap_response_size;
+     301                 :            :     void *encap_request;
+     302                 :            :     size_t encap_request_size;
+     303                 :            :     libspdm_return_t status;
+     304                 :            :     size_t ack_header_size;
+     305                 :            : 
+     306                 :          9 :     spdm_request = request;
+     307                 :            : 
+     308         [ -  + ]:          9 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_11) {
+     309                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     310                 :            :                                                SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+     311                 :            :                                                SPDM_DELIVER_ENCAPSULATED_RESPONSE,
+     312                 :            :                                                response_size, response);
+     313                 :            :     }
+     314                 :            : 
+     315         [ -  + ]:          9 :     if (!libspdm_is_capabilities_flag_supported(
+     316                 :            :             spdm_context, false,
+     317                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP,
+     318                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP)) {
+     319                 :          0 :         return libspdm_generate_error_response(
+     320                 :            :             spdm_context, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+     321                 :            :             SPDM_DELIVER_ENCAPSULATED_RESPONSE, response_size,
+     322                 :            :             response);
+     323                 :            :     }
+     324         [ +  + ]:          9 :     if (spdm_context->response_state !=
+     325                 :            :         LIBSPDM_RESPONSE_STATE_PROCESSING_ENCAP) {
+     326         [ +  + ]:          2 :         if (spdm_context->response_state ==
+     327                 :            :             LIBSPDM_RESPONSE_STATE_NORMAL) {
+     328                 :          1 :             return libspdm_generate_error_response(
+     329                 :            :                 spdm_context,
+     330                 :            :                 SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+     331                 :            :                 response_size, response);
+     332                 :            :         }
+     333                 :          1 :         return libspdm_responder_handle_response_state(
+     334                 :            :             spdm_context,
+     335                 :          1 :             spdm_request->header.request_response_code,
+     336                 :            :             response_size, response);
+     337                 :            :     }
+     338                 :            : 
+     339         [ +  + ]:          7 :     if (request_size <=
+     340                 :            :         sizeof(spdm_deliver_encapsulated_response_request_t)) {
+     341                 :          1 :         return libspdm_generate_error_response(spdm_context,
+     342                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     343                 :            :                                                response_size, response);
+     344                 :            :     }
+     345                 :            : 
+     346                 :          6 :     spdm_request_size = request_size;
+     347                 :            : 
+     348                 :          6 :     if (spdm_request->header.param1 !=
+     349         [ +  + ]:          6 :         spdm_context->encap_context.request_id) {
+     350                 :          1 :         return libspdm_generate_error_response(spdm_context,
+     351                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     352                 :            :                                                response_size, response);
+     353                 :            :     }
+     354                 :            : 
+     355                 :          5 :     encap_response = (spdm_request + 1);
+     356                 :          5 :     encap_response_size =
+     357                 :            :         spdm_request_size -
+     358                 :            :         sizeof(spdm_deliver_encapsulated_response_request_t);
+     359                 :            : 
+     360         [ +  + ]:          5 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_12) {
+     361                 :          2 :         ack_header_size = sizeof(spdm_encapsulated_response_ack_response_t);
+     362                 :            :     } else {
+     363                 :          3 :         ack_header_size = sizeof(spdm_message_header_t);
+     364                 :            :     }
+     365                 :            : 
+     366         [ -  + ]:          5 :     LIBSPDM_ASSERT(*response_size > ack_header_size);
+     367                 :          5 :     libspdm_zero_mem(response, *response_size);
+     368                 :            : 
+     369                 :          5 :     spdm_response = response;
+     370                 :          5 :     spdm_response->header.spdm_version = spdm_request->header.spdm_version;
+     371                 :          5 :     spdm_response->header.request_response_code = SPDM_ENCAPSULATED_RESPONSE_ACK;
+     372                 :          5 :     spdm_response->header.param1 = 0;
+     373                 :          5 :     spdm_response->header.param2 = SPDM_ENCAPSULATED_RESPONSE_ACK_RESPONSE_PAYLOAD_TYPE_PRESENT;
+     374                 :            : 
+     375                 :          5 :     encap_request_size = *response_size - ack_header_size;
+     376                 :          5 :     encap_request = (uint8_t *)spdm_response + ack_header_size;
+     377         [ -  + ]:          5 :     if (encap_response_size < sizeof(spdm_message_header_t)) {
+     378                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     379                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     380                 :            :                                                response_size, response);
+     381                 :            :     }
+     382                 :            : 
+     383                 :          5 :     libspdm_reset_message_buffer_via_request_code(spdm_context, NULL,
+     384                 :          5 :                                                   spdm_request->header.request_response_code);
+     385                 :            : 
+     386                 :          5 :     status = libspdm_process_encapsulated_response(
+     387                 :            :         spdm_context, encap_response_size, encap_response,
+     388                 :            :         &encap_request_size, encap_request);
+     389         [ -  + ]:          5 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     390                 :          0 :         spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+     391                 :          0 :         return libspdm_generate_error_response(
+     392                 :            :             spdm_context, SPDM_ERROR_CODE_INVALID_RESPONSE_CODE, 0,
+     393                 :            :             response_size, response);
+     394                 :            :     }
+     395                 :            : 
+     396                 :          5 :     *response_size = ack_header_size + encap_request_size;
+     397                 :          5 :     spdm_response->header.param1 = spdm_context->encap_context.request_id;
+     398                 :            : 
+     399         [ +  + ]:          5 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_12) {
+     400                 :          2 :         spdm_response->ack_request_id = spdm_request->header.param1;
+     401                 :            :     }
+     402                 :            : 
+     403         [ +  + ]:          5 :     if (encap_request_size == 0) {
+     404                 :          3 :         spdm_response->header.param1 = 0;
+     405                 :          3 :         spdm_response->header.param2 =
+     406                 :            :             SPDM_ENCAPSULATED_RESPONSE_ACK_RESPONSE_PAYLOAD_TYPE_ABSENT;
+     407         [ -  + ]:          3 :         if ((spdm_context->encap_context.req_slot_id != 0) &&
+     408         [ #  # ]:          0 :             (spdm_context->encap_context.req_slot_id != 0xFF)) {
+     409                 :          0 :             spdm_response->header.param2 =
+     410                 :            :                 SPDM_ENCAPSULATED_RESPONSE_ACK_RESPONSE_PAYLOAD_TYPE_REQ_SLOT_NUMBER;
+     411                 :          0 :             *response_size = ack_header_size + 1;
+     412                 :          0 :             *(uint8_t *)(spdm_response + 1) =
+     413                 :          0 :                 spdm_context->encap_context.req_slot_id;
+     414                 :            :         }
+     415                 :          3 :         spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+     416                 :            :     }
+     417                 :            : 
+     418                 :          5 :     return LIBSPDM_STATUS_SUCCESS;
+     419                 :            : }
+     420                 :            : 
+     421                 :          5 : libspdm_return_t libspdm_handle_encap_error_response_main(
+     422                 :            :     libspdm_context_t *spdm_context, uint8_t error_code)
+     423                 :            : {
+     424         [ +  + ]:          5 :     if (error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) {
+     425                 :          1 :         return LIBSPDM_STATUS_NOT_READY_PEER;
+     426                 :            :     }
+     427                 :            : 
+     428                 :          4 :     return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     429                 :            : }
+     430                 :            : 
+     431                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP */
+     432                 :            : 
+     433                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP
+     434                 :            : #if LIBSPDM_SEND_CHALLENGE_SUPPORT
+     435                 :          0 : void libspdm_init_basic_mut_auth_encap_state(libspdm_context_t *spdm_context)
+     436                 :            : {
+     437                 :          0 :     spdm_context->encap_context.current_request_op_code = 0x00;
+     438                 :          0 :     spdm_context->encap_context.request_id = 0;
+     439                 :          0 :     spdm_context->encap_context.last_encap_request_size = 0;
+     440                 :          0 :     libspdm_zero_mem(&spdm_context->encap_context.last_encap_request_header,
+     441                 :            :                      sizeof(spdm_context->encap_context.last_encap_request_header));
+     442                 :          0 :     spdm_context->mut_auth_cert_chain_buffer_size = 0;
+     443                 :            : 
+     444                 :            :     /* Clear Cache*/
+     445                 :          0 :     libspdm_reset_message_mut_b(spdm_context);
+     446                 :          0 :     libspdm_reset_message_mut_c(spdm_context);
+     447                 :            : 
+     448                 :            :     /* Possible Sequence:
+     449                 :            :      * 1. Basic Mutual Auth:
+     450                 :            :      *    1.1 GET_DIGEST/GET_CERTIFICATE/CHALLENGE (encap_context.req_slot_id must not be 0xFF)
+     451                 :            :      *    1.2 CHALLENGE (REQUEST_FLAGS_PUB_KEY_ID_CAP, encap_context req_slot_id must be 0xFF)*/
+     452                 :            : 
+     453                 :          0 :     libspdm_zero_mem(spdm_context->encap_context.request_op_code_sequence,
+     454                 :            :                      sizeof(spdm_context->encap_context.request_op_code_sequence));
+     455                 :            :     /* Basic Mutual Auth*/
+     456         [ #  # ]:          0 :     if (libspdm_is_capabilities_flag_supported(
+     457                 :            :             spdm_context, false,
+     458                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PUB_KEY_ID_CAP, 0)) {
+     459         [ #  # ]:          0 :         LIBSPDM_ASSERT (spdm_context->encap_context.req_slot_id == 0xFF);
+     460                 :            : 
+     461                 :          0 :         spdm_context->encap_context.request_op_code_count = 1;
+     462                 :          0 :         spdm_context->encap_context.request_op_code_sequence[0] = SPDM_CHALLENGE;
+     463                 :            :     } else {
+     464         [ #  # ]:          0 :         LIBSPDM_ASSERT (spdm_context->encap_context.req_slot_id != 0xFF);
+     465         [ #  # ]:          0 :         LIBSPDM_ASSERT(spdm_context->mut_auth_cert_chain_buffer != NULL);
+     466         [ #  # ]:          0 :         LIBSPDM_ASSERT(spdm_context->mut_auth_cert_chain_buffer_max_size != 0);
+     467                 :            : 
+     468                 :          0 :         spdm_context->encap_context.request_op_code_count = 3;
+     469                 :          0 :         spdm_context->encap_context.request_op_code_sequence[0] = SPDM_GET_DIGESTS;
+     470                 :          0 :         spdm_context->encap_context.request_op_code_sequence[1] = SPDM_GET_CERTIFICATE;
+     471                 :          0 :         spdm_context->encap_context.request_op_code_sequence[2] = SPDM_CHALLENGE;
+     472                 :            :     }
+     473                 :            : 
+     474                 :          0 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_PROCESSING_ENCAP;
+     475                 :          0 : }
+     476                 :            : #endif /* LIBSPDM_SEND_CHALLENGE_SUPPORT */
+     477                 :            : 
+     478                 :          0 : void libspdm_init_mut_auth_encap_state(libspdm_context_t *spdm_context, uint8_t mut_auth_requested)
+     479                 :            : {
+     480                 :          0 :     spdm_context->encap_context.current_request_op_code = 0x00;
+     481         [ #  # ]:          0 :     if (mut_auth_requested == SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_GET_DIGESTS) {
+     482                 :          0 :         spdm_context->encap_context.current_request_op_code = SPDM_GET_DIGESTS;
+     483                 :            :     }
+     484                 :          0 :     spdm_context->encap_context.request_id = 0;
+     485                 :          0 :     spdm_context->encap_context.last_encap_request_size = 0;
+     486                 :          0 :     libspdm_zero_mem(&spdm_context->encap_context.last_encap_request_header,
+     487                 :            :                      sizeof(spdm_context->encap_context.last_encap_request_header));
+     488                 :          0 :     spdm_context->mut_auth_cert_chain_buffer_size = 0;
+     489                 :            : 
+     490                 :            :     /* Clear Cache */
+     491                 :          0 :     libspdm_reset_message_mut_b(spdm_context);
+     492                 :          0 :     libspdm_reset_message_mut_c(spdm_context);
+     493                 :            : 
+     494                 :            :     /* Possible Sequence:
+     495                 :            :      * 2. Session Mutual Auth: (spdm_context->last_spdm_request_session_id_valid)
+     496                 :            :      *    2.1 GET_DIGEST/GET_CERTIFICATE (MUT_AUTH_REQUESTED_WITH_ENCAP_REQUEST or MUT_AUTH_REQUESTED_WITH_GET_DIGESTS, encap_context.req_slot_id must not be 0xFF)
+     497                 :            :      *    2.2 N/A (REQUEST_FLAGS_PUB_KEY_ID_CAP, MUT_AUTH_REQUESTED, encap_context.req_slot_id may or may not be 0xFF)*/
+     498                 :            : 
+     499                 :          0 :     libspdm_zero_mem(spdm_context->encap_context.request_op_code_sequence,
+     500                 :            :                      sizeof(spdm_context->encap_context.request_op_code_sequence));
+     501                 :            :     /* Session Mutual Auth*/
+     502         [ #  # ]:          0 :     if (libspdm_is_capabilities_flag_supported(
+     503                 :            :             spdm_context, false,
+     504                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PUB_KEY_ID_CAP, 0)) {
+     505         [ #  # ]:          0 :         LIBSPDM_ASSERT(spdm_context->encap_context.req_slot_id == 0xFF);
+     506         [ #  # ]:          0 :         LIBSPDM_ASSERT(mut_auth_requested == SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED);
+     507                 :            :     } else {
+     508         [ #  # ]:          0 :         LIBSPDM_ASSERT(spdm_context->mut_auth_cert_chain_buffer != NULL);
+     509         [ #  # ]:          0 :         LIBSPDM_ASSERT(spdm_context->mut_auth_cert_chain_buffer_max_size != 0);
+     510                 :            :     }
+     511                 :            : 
+     512      [ #  #  # ]:          0 :     switch (mut_auth_requested) {
+     513                 :          0 :     case SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED:
+     514                 :            :         /* no encap is required*/
+     515                 :          0 :         spdm_context->encap_context.request_op_code_count = 0;
+     516                 :          0 :         break;
+     517                 :          0 :     case SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_ENCAP_REQUEST:
+     518                 :            :     case SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_GET_DIGESTS:
+     519         [ #  # ]:          0 :         LIBSPDM_ASSERT (spdm_context->encap_context.req_slot_id != 0xFF);
+     520                 :          0 :         spdm_context->encap_context.request_op_code_count = 2;
+     521                 :          0 :         spdm_context->encap_context.request_op_code_sequence[0] = SPDM_GET_DIGESTS;
+     522                 :          0 :         spdm_context->encap_context.request_op_code_sequence[1] = SPDM_GET_CERTIFICATE;
+     523                 :          0 :         break;
+     524                 :          0 :     default:
+     525                 :          0 :         LIBSPDM_ASSERT (false);
+     526                 :          0 :         spdm_context->encap_context.request_op_code_count = 0;
+     527                 :          0 :         break;
+     528                 :            :     }
+     529                 :            : 
+     530         [ #  # ]:          0 :     if (spdm_context->encap_context.request_op_code_count != 0) {
+     531                 :            :         /* change state only if ENCAP is required */
+     532                 :          0 :         spdm_context->response_state = LIBSPDM_RESPONSE_STATE_PROCESSING_ENCAP;
+     533                 :            :     }
+     534                 :          0 : }
+     535                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_end_session.c.func-sort-c.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_end_session.c.func-sort-c.html new file mode 100644 index 00000000000..fc72b721341 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_end_session.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_end_session.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_end_session.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:303585.7 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:142070.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_response_end_session8
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_end_session.c.func.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_end_session.c.func.html new file mode 100644 index 00000000000..5ae9da41d1f --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_end_session.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_end_session.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_end_session.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:303585.7 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:142070.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_response_end_session8
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_end_session.c.gcov.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_end_session.c.gcov.html new file mode 100644 index 00000000000..ac8a12303de --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_end_session.c.gcov.html @@ -0,0 +1,180 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_end_session.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_end_session.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:303585.7 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:142070.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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_responder_lib.h"
+       8                 :            : 
+       9                 :          8 : libspdm_return_t libspdm_get_response_end_session(libspdm_context_t *spdm_context,
+      10                 :            :                                                   size_t request_size,
+      11                 :            :                                                   const void *request,
+      12                 :            :                                                   size_t *response_size,
+      13                 :            :                                                   void *response)
+      14                 :            : {
+      15                 :            :     spdm_end_session_response_t *spdm_response;
+      16                 :            :     const spdm_end_session_request_t *spdm_request;
+      17                 :            :     libspdm_session_info_t *session_info;
+      18                 :            :     libspdm_session_state_t session_state;
+      19                 :            : 
+      20                 :          8 :     spdm_request = request;
+      21                 :            : 
+      22         [ -  + ]:          8 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_11) {
+      23                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      24                 :            :                                                SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+      25                 :            :                                                SPDM_END_SESSION,
+      26                 :            :                                                response_size, response);
+      27                 :            :     }
+      28                 :            : 
+      29         [ -  + ]:          8 :     if (spdm_request->header.spdm_version != libspdm_get_connection_version(spdm_context)) {
+      30                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      31                 :            :                                                SPDM_ERROR_CODE_VERSION_MISMATCH, 0,
+      32                 :            :                                                response_size, response);
+      33                 :            :     }
+      34         [ +  + ]:          8 :     if (spdm_context->response_state != LIBSPDM_RESPONSE_STATE_NORMAL) {
+      35                 :          3 :         return libspdm_responder_handle_response_state(
+      36                 :            :             spdm_context,
+      37                 :          3 :             spdm_request->header.request_response_code,
+      38                 :            :             response_size, response);
+      39                 :            :     }
+      40         [ +  + ]:          5 :     if (spdm_context->connection_info.connection_state < LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
+      41                 :          1 :         return libspdm_generate_error_response(spdm_context,
+      42                 :            :                                                SPDM_ERROR_CODE_UNEXPECTED_REQUEST,
+      43                 :            :                                                0, response_size, response);
+      44                 :            :     }
+      45                 :            : 
+      46         [ -  + ]:          4 :     if (!spdm_context->last_spdm_request_session_id_valid) {
+      47                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      48                 :            :                                                SPDM_ERROR_CODE_SESSION_REQUIRED, 0,
+      49                 :            :                                                response_size, response);
+      50                 :            :     }
+      51                 :          4 :     session_info = libspdm_get_session_info_via_session_id(
+      52                 :            :         spdm_context, spdm_context->last_spdm_request_session_id);
+      53         [ -  + ]:          4 :     if (session_info == NULL) {
+      54                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      55                 :            :                                                SPDM_ERROR_CODE_SESSION_REQUIRED, 0,
+      56                 :            :                                                response_size, response);
+      57                 :            :     }
+      58                 :          4 :     session_state = libspdm_secured_message_get_session_state(
+      59                 :            :         session_info->secured_message_context);
+      60         [ -  + ]:          4 :     if (session_state != LIBSPDM_SESSION_STATE_ESTABLISHED) {
+      61                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      62                 :            :                                                SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+      63                 :            :                                                response_size, response);
+      64                 :            :     }
+      65                 :            : 
+      66                 :            :     /* this message can only be in secured session
+      67                 :            :      * thus don't need to consider transport layer padding, just check its exact size */
+      68         [ +  + ]:          4 :     if (request_size != sizeof(spdm_end_session_request_t)) {
+      69                 :          1 :         return libspdm_generate_error_response(spdm_context,
+      70                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+      71                 :            :                                                response_size, response);
+      72                 :            :     }
+      73                 :            : 
+      74                 :          3 :     libspdm_reset_message_buffer_via_request_code(spdm_context, session_info,
+      75                 :          3 :                                                   spdm_request->header.request_response_code);
+      76                 :            : 
+      77                 :          3 :     session_info->end_session_attributes = spdm_request->header.param1;
+      78         [ +  + ]:          3 :     if ((spdm_request->header.param1 &
+      79                 :            :          SPDM_END_SESSION_REQUEST_ATTRIBUTES_PRESERVE_NEGOTIATED_STATE_CLEAR) != 0) {
+      80                 :          1 :         spdm_context->connection_info.end_session_attributes |=
+      81                 :            :             SPDM_END_SESSION_REQUEST_ATTRIBUTES_PRESERVE_NEGOTIATED_STATE_CLEAR;
+      82                 :            :     }
+      83                 :            : 
+      84         [ -  + ]:          3 :     LIBSPDM_ASSERT(*response_size >= sizeof(spdm_end_session_response_t));
+      85                 :          3 :     *response_size = sizeof(spdm_end_session_response_t);
+      86                 :          3 :     libspdm_zero_mem(response, *response_size);
+      87                 :          3 :     spdm_response = response;
+      88                 :            : 
+      89                 :          3 :     spdm_response->header.spdm_version = spdm_request->header.spdm_version;
+      90                 :          3 :     spdm_response->header.request_response_code = SPDM_END_SESSION_ACK;
+      91                 :          3 :     spdm_response->header.param1 = 0;
+      92                 :          3 :     spdm_response->header.param2 = 0;
+      93                 :            : 
+      94                 :          3 :     return LIBSPDM_STATUS_SUCCESS;
+      95                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_error.c.func-sort-c.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_error.c.func-sort-c.html new file mode 100644 index 00000000000..823fdef870a --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_error.c.func-sort-c.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_error.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_error.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:2424100.0 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:81266.7 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_generate_extended_error_response16
libspdm_generate_error_response343
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_error.c.func.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_error.c.func.html new file mode 100644 index 00000000000..2f455a5b5ec --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_error.c.func.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_error.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_error.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:2424100.0 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:81266.7 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_generate_error_response343
libspdm_generate_extended_error_response16
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_error.c.gcov.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_error.c.gcov.html new file mode 100644 index 00000000000..5fde472d472 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_error.c.gcov.html @@ -0,0 +1,145 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_error.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_error.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:2424100.0 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:81266.7 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 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_responder_lib.h"
+       8                 :            : 
+       9                 :        343 : libspdm_return_t libspdm_generate_error_response(const void *spdm_context,
+      10                 :            :                                                  uint8_t error_code,
+      11                 :            :                                                  uint8_t error_data,
+      12                 :            :                                                  size_t *response_size,
+      13                 :            :                                                  void *response)
+      14                 :            : {
+      15                 :            :     spdm_error_response_t *spdm_response;
+      16                 :            : 
+      17         [ -  + ]:        343 :     LIBSPDM_ASSERT(*response_size >= sizeof(spdm_error_response_t));
+      18                 :        343 :     *response_size = sizeof(spdm_error_response_t);
+      19                 :        343 :     spdm_response = response;
+      20                 :            : 
+      21                 :        343 :     spdm_response->header.spdm_version = libspdm_get_connection_version (spdm_context);
+      22         [ +  + ]:        343 :     if (spdm_response->header.spdm_version == 0) {
+      23                 :            :         /* if version is not negotiated, then use default version 1.0 */
+      24                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+      25                 :            :     }
+      26                 :        343 :     spdm_response->header.request_response_code = SPDM_ERROR;
+      27                 :        343 :     spdm_response->header.param1 = error_code;
+      28                 :        343 :     spdm_response->header.param2 = error_data;
+      29                 :            : 
+      30         [ +  + ]:        343 :     if (spdm_response->header.spdm_version <= SPDM_MESSAGE_VERSION_11) {
+      31   [ +  -  -  + ]:        257 :         LIBSPDM_ASSERT ((error_code != SPDM_ERROR_CODE_RESPONSE_TOO_LARGE) &&
+      32                 :            :                         (error_code != SPDM_ERROR_CODE_LARGE_RESPONSE));
+      33                 :            :     }
+      34                 :            : 
+      35                 :        343 :     return LIBSPDM_STATUS_SUCCESS;
+      36                 :            : }
+      37                 :            : 
+      38                 :         16 : libspdm_return_t libspdm_generate_extended_error_response(
+      39                 :            :     const void *spdm_context, uint8_t error_code, uint8_t error_data,
+      40                 :            :     size_t extended_error_data_size, const uint8_t *extended_error_data,
+      41                 :            :     size_t *response_size, void *response)
+      42                 :            : {
+      43                 :            :     spdm_error_response_t *spdm_response;
+      44                 :            :     size_t response_capacity;
+      45                 :            : 
+      46         [ -  + ]:         16 :     LIBSPDM_ASSERT(*response_size >=
+      47                 :            :                    sizeof(spdm_error_response_t) + extended_error_data_size);
+      48                 :         16 :     response_capacity = *response_size;
+      49                 :         16 :     *response_size = sizeof(spdm_error_response_t) + extended_error_data_size;
+      50                 :         16 :     spdm_response = response;
+      51                 :            : 
+      52                 :         16 :     spdm_response->header.spdm_version = libspdm_get_connection_version (spdm_context);
+      53                 :         16 :     spdm_response->header.request_response_code = SPDM_ERROR;
+      54                 :         16 :     spdm_response->header.param1 = error_code;
+      55                 :         16 :     spdm_response->header.param2 = error_data;
+      56                 :         16 :     libspdm_copy_mem(spdm_response + 1, response_capacity - sizeof(spdm_error_response_t),
+      57                 :            :                      extended_error_data, extended_error_data_size);
+      58                 :            : 
+      59                 :         16 :     return LIBSPDM_STATUS_SUCCESS;
+      60                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_finish.c.func-sort-c.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_finish.c.func-sort-c.html new file mode 100644 index 00000000000..03746013189 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_finish.c.func-sort-c.html @@ -0,0 +1,97 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_finish.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_finish.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:14216984.0 %
Date:2024-09-22 08:21:07Functions:44100.0 %
Branches:7911270.5 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_verify_finish_req_signature11
libspdm_generate_finish_rsp_hmac12
libspdm_verify_finish_req_hmac15
libspdm_get_response_finish28
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_finish.c.func.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_finish.c.func.html new file mode 100644 index 00000000000..12588d143f8 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_finish.c.func.html @@ -0,0 +1,97 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_finish.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_finish.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:14216984.0 %
Date:2024-09-22 08:21:07Functions:44100.0 %
Branches:7911270.5 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_generate_finish_rsp_hmac12
libspdm_get_response_finish28
libspdm_verify_finish_req_hmac15
libspdm_verify_finish_req_signature11
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_finish.c.gcov.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_finish.c.gcov.html new file mode 100644 index 00000000000..8351aa99fdb --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_finish.c.gcov.html @@ -0,0 +1,747 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_finish.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_finish.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:14216984.0 %
Date:2024-09-22 08:21:07Functions:44100.0 %
Branches:7911270.5 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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_responder_lib.h"
+       8                 :            : #include "internal/libspdm_secured_message_lib.h"
+       9                 :            : 
+      10                 :            : #if LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP
+      11                 :            : 
+      12                 :         15 : bool libspdm_verify_finish_req_hmac(libspdm_context_t *spdm_context,
+      13                 :            :                                     libspdm_session_info_t *session_info,
+      14                 :            :                                     const uint8_t *hmac, size_t hmac_size)
+      15                 :            : {
+      16                 :            :     uint8_t hmac_data[LIBSPDM_MAX_HASH_SIZE];
+      17                 :            :     size_t hash_size;
+      18                 :            :     bool result;
+      19                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+      20                 :            :     uint8_t slot_id;
+      21                 :            :     uint8_t *cert_chain_buffer;
+      22                 :            :     size_t cert_chain_buffer_size;
+      23                 :            :     uint8_t *mut_cert_chain_buffer;
+      24                 :            :     size_t mut_cert_chain_buffer_size;
+      25                 :            :     uint8_t *th_curr_data;
+      26                 :            :     size_t th_curr_data_size;
+      27                 :            :     libspdm_th_managed_buffer_t th_curr;
+      28                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+      29                 :            : #endif
+      30                 :            : 
+      31                 :         15 :     hash_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+      32         [ -  + ]:         15 :     LIBSPDM_ASSERT(hmac_size == hash_size);
+      33                 :            : 
+      34                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+      35                 :            :     slot_id = spdm_context->connection_info.local_used_cert_chain_slot_id;
+      36                 :            :     LIBSPDM_ASSERT((slot_id < SPDM_MAX_SLOT_COUNT) || (slot_id == 0xFF));
+      37                 :            :     if (slot_id == 0xFF) {
+      38                 :            :         result = libspdm_get_local_public_key_buffer(
+      39                 :            :             spdm_context, (const void **)&cert_chain_buffer, &cert_chain_buffer_size);
+      40                 :            :     } else {
+      41                 :            :         result = libspdm_get_local_cert_chain_buffer(
+      42                 :            :             spdm_context, (const void **)&cert_chain_buffer, &cert_chain_buffer_size);
+      43                 :            :     }
+      44                 :            :     if (!result) {
+      45                 :            :         return false;
+      46                 :            :     }
+      47                 :            : 
+      48                 :            :     if (session_info->mut_auth_requested) {
+      49                 :            :         slot_id = spdm_context->connection_info.peer_used_cert_chain_slot_id;
+      50                 :            :         LIBSPDM_ASSERT((slot_id < SPDM_MAX_SLOT_COUNT) || (slot_id == 0xFF));
+      51                 :            :         if (slot_id == 0xFF) {
+      52                 :            :             result = libspdm_get_peer_public_key_buffer(
+      53                 :            :                 spdm_context, (const void **)&mut_cert_chain_buffer, &mut_cert_chain_buffer_size);
+      54                 :            :         } else {
+      55                 :            :             result = libspdm_get_peer_cert_chain_buffer(
+      56                 :            :                 spdm_context, (const void **)&mut_cert_chain_buffer, &mut_cert_chain_buffer_size);
+      57                 :            :         }
+      58                 :            :         if (!result) {
+      59                 :            :             return false;
+      60                 :            :         }
+      61                 :            :     } else {
+      62                 :            :         mut_cert_chain_buffer = NULL;
+      63                 :            :         mut_cert_chain_buffer_size = 0;
+      64                 :            :     }
+      65                 :            : 
+      66                 :            :     result = libspdm_calculate_th_for_finish(
+      67                 :            :         spdm_context, session_info, cert_chain_buffer,
+      68                 :            :         cert_chain_buffer_size, mut_cert_chain_buffer,
+      69                 :            :         mut_cert_chain_buffer_size, &th_curr);
+      70                 :            :     if (!result) {
+      71                 :            :         return false;
+      72                 :            :     }
+      73                 :            :     th_curr_data = libspdm_get_managed_buffer(&th_curr);
+      74                 :            :     th_curr_data_size = libspdm_get_managed_buffer_size(&th_curr);
+      75                 :            : 
+      76                 :            :     result = libspdm_hash_all (spdm_context->connection_info.algorithm.base_hash_algo,
+      77                 :            :                                th_curr_data, th_curr_data_size, hash_data);
+      78                 :            :     if (!result) {
+      79                 :            :         return false;
+      80                 :            :     }
+      81                 :            : 
+      82                 :            :     result = libspdm_hmac_all_with_request_finished_key(
+      83                 :            :         session_info->secured_message_context, hash_data,
+      84                 :            :         hash_size, hmac_data);
+      85                 :            :     if (!result) {
+      86                 :            :         return false;
+      87                 :            :     }
+      88                 :            : #else
+      89                 :         15 :     result = libspdm_calculate_th_hmac_for_finish_req(
+      90                 :            :         spdm_context, session_info, &hash_size, hmac_data);
+      91         [ -  + ]:         15 :     if (!result) {
+      92                 :          0 :         return false;
+      93                 :            :     }
+      94                 :            : #endif
+      95                 :         15 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "th_curr hmac - "));
+      96                 :         15 :     LIBSPDM_INTERNAL_DUMP_DATA(hmac_data, hash_size);
+      97                 :         15 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+      98                 :            : 
+      99         [ +  + ]:         15 :     if (!libspdm_consttime_is_mem_equal(hmac, hmac_data, hash_size)) {
+     100                 :          2 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR, "!!! verify_finish_req_hmac - FAIL !!!\n"));
+     101                 :          2 :         return false;
+     102                 :            :     }
+     103                 :         13 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "!!! verify_finish_req_hmac - PASS !!!\n"));
+     104                 :         13 :     return true;
+     105                 :            : }
+     106                 :            : 
+     107                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP
+     108                 :         11 : bool libspdm_verify_finish_req_signature(libspdm_context_t *spdm_context,
+     109                 :            :                                          libspdm_session_info_t *session_info,
+     110                 :            :                                          const void *sign_data,
+     111                 :            :                                          const size_t sign_data_size)
+     112                 :            : {
+     113                 :            :     bool result;
+     114                 :            :     void *context;
+     115                 :            :     uint8_t slot_id;
+     116                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     117                 :            :     uint8_t *cert_chain_buffer;
+     118                 :            :     size_t cert_chain_buffer_size;
+     119                 :            :     uint8_t *mut_cert_chain_buffer;
+     120                 :            :     size_t mut_cert_chain_buffer_size;
+     121                 :            :     uint8_t *th_curr_data;
+     122                 :            :     size_t th_curr_data_size;
+     123                 :            :     libspdm_th_managed_buffer_t th_curr;
+     124                 :            :     const uint8_t *mut_cert_chain_data;
+     125                 :            :     size_t mut_cert_chain_data_size;
+     126                 :            :     const uint8_t *mut_cert_buffer;
+     127                 :            :     size_t mut_cert_buffer_size;
+     128                 :            : #endif
+     129                 :            : #if ((LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT) && (LIBSPDM_DEBUG_BLOCK_ENABLE)) || \
+     130                 :            :     !(LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT)
+     131                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     132                 :            : #endif
+     133                 :            : #if !(LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT) || (LIBSPDM_DEBUG_PRINT_ENABLE)
+     134                 :            :     size_t hash_size;
+     135                 :            : 
+     136                 :         11 :     hash_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+     137                 :            : #endif
+     138                 :            : 
+     139                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     140                 :            :     slot_id = spdm_context->connection_info.local_used_cert_chain_slot_id;
+     141                 :            :     LIBSPDM_ASSERT((slot_id < SPDM_MAX_SLOT_COUNT) || (slot_id == 0xFF));
+     142                 :            :     if (slot_id == 0xFF) {
+     143                 :            :         result = libspdm_get_local_public_key_buffer(
+     144                 :            :             spdm_context, (const void **)&cert_chain_buffer, &cert_chain_buffer_size);
+     145                 :            :     } else {
+     146                 :            :         result = libspdm_get_local_cert_chain_buffer(
+     147                 :            :             spdm_context, (const void **)&cert_chain_buffer, &cert_chain_buffer_size);
+     148                 :            :     }
+     149                 :            :     if (!result) {
+     150                 :            :         return false;
+     151                 :            :     }
+     152                 :            : 
+     153                 :            :     slot_id = spdm_context->connection_info.peer_used_cert_chain_slot_id;
+     154                 :            :     LIBSPDM_ASSERT((slot_id < SPDM_MAX_SLOT_COUNT) || (slot_id == 0xFF));
+     155                 :            :     if (slot_id == 0xFF) {
+     156                 :            :         result = libspdm_get_peer_public_key_buffer(
+     157                 :            :             spdm_context, (const void **)&mut_cert_chain_buffer, &mut_cert_chain_buffer_size);
+     158                 :            :     } else {
+     159                 :            :         result = libspdm_get_peer_cert_chain_buffer(
+     160                 :            :             spdm_context, (const void **)&mut_cert_chain_buffer, &mut_cert_chain_buffer_size);
+     161                 :            :     }
+     162                 :            :     if (!result) {
+     163                 :            :         return false;
+     164                 :            :     }
+     165                 :            : 
+     166                 :            :     result = libspdm_calculate_th_for_finish(
+     167                 :            :         spdm_context, session_info, cert_chain_buffer,
+     168                 :            :         cert_chain_buffer_size, mut_cert_chain_buffer,
+     169                 :            :         mut_cert_chain_buffer_size, &th_curr);
+     170                 :            :     if (!result) {
+     171                 :            :         return false;
+     172                 :            :     }
+     173                 :            :     th_curr_data = libspdm_get_managed_buffer(&th_curr);
+     174                 :            :     th_curr_data_size = libspdm_get_managed_buffer_size(&th_curr);
+     175                 :            : 
+     176                 :            :     /* Debug code only - required for debug print of th_curr below*/
+     177                 :            :     LIBSPDM_DEBUG_CODE(
+     178                 :            :         if (!libspdm_hash_all(
+     179                 :            :                 spdm_context->connection_info.algorithm.base_hash_algo,
+     180                 :            :                 th_curr_data, th_curr_data_size, hash_data)) {
+     181                 :            :         return false;
+     182                 :            :     }
+     183                 :            :         );
+     184                 :            : #else
+     185                 :         11 :     result = libspdm_calculate_th_hash_for_finish(
+     186                 :            :         spdm_context, session_info, &hash_size, hash_data);
+     187         [ -  + ]:         11 :     if (!result) {
+     188                 :          0 :         return false;
+     189                 :            :     }
+     190                 :            : #endif
+     191                 :         11 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "th_curr hash - "));
+     192                 :         11 :     LIBSPDM_INTERNAL_DUMP_DATA(hash_data, hash_size);
+     193                 :         11 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     194                 :            : 
+     195                 :         11 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "signature - "));
+     196                 :         11 :     LIBSPDM_INTERNAL_DUMP_DATA(sign_data, sign_data_size);
+     197                 :         11 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     198                 :            : 
+     199                 :         11 :     slot_id = spdm_context->connection_info.peer_used_cert_chain_slot_id;
+     200   [ +  +  -  + ]:         11 :     LIBSPDM_ASSERT((slot_id < SPDM_MAX_SLOT_COUNT) || (slot_id == 0xFF));
+     201                 :            : 
+     202         [ +  + ]:         11 :     if (slot_id == 0xFF) {
+     203                 :          1 :         result = libspdm_req_asym_get_public_key_from_der(
+     204                 :          1 :             spdm_context->connection_info.algorithm.req_base_asym_alg,
+     205                 :          1 :             spdm_context->local_context.peer_public_key_provision,
+     206                 :            :             spdm_context->local_context.peer_public_key_provision_size,
+     207                 :            :             &context);
+     208         [ -  + ]:          1 :         if (!result) {
+     209                 :          0 :             return false;
+     210                 :            :         }
+     211                 :            :     } else {
+     212                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     213                 :            :         /* Get leaf cert from cert chain*/
+     214                 :            :         result = libspdm_get_peer_cert_chain_data(spdm_context,
+     215                 :            :                                                   (const void **)&mut_cert_chain_data,
+     216                 :            :                                                   &mut_cert_chain_data_size);
+     217                 :            :         if (!result) {
+     218                 :            :             return false;
+     219                 :            :         }
+     220                 :            : 
+     221                 :            :         result = libspdm_x509_get_cert_from_cert_chain(mut_cert_chain_data,
+     222                 :            :                                                        mut_cert_chain_data_size, -1,
+     223                 :            :                                                        &mut_cert_buffer,
+     224                 :            :                                                        &mut_cert_buffer_size);
+     225                 :            :         if (!result) {
+     226                 :            :             return false;
+     227                 :            :         }
+     228                 :            : 
+     229                 :            :         result = libspdm_req_asym_get_public_key_from_x509(
+     230                 :            :             spdm_context->connection_info.algorithm.req_base_asym_alg,
+     231                 :            :             mut_cert_buffer, mut_cert_buffer_size, &context);
+     232                 :            :         if (!result) {
+     233                 :            :             return false;
+     234                 :            :         }
+     235                 :            : #else
+     236                 :         10 :         context = spdm_context->connection_info.peer_used_cert_chain[slot_id].leaf_cert_public_key;
+     237         [ -  + ]:         10 :         LIBSPDM_ASSERT(context != NULL);
+     238                 :            : #endif
+     239                 :            :     }
+     240                 :            : 
+     241                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     242                 :            :     result = libspdm_req_asym_verify_ex(
+     243                 :            :         spdm_context->connection_info.version, SPDM_FINISH,
+     244                 :            :         spdm_context->connection_info.algorithm.req_base_asym_alg,
+     245                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+     246                 :            :         context, th_curr_data, th_curr_data_size, sign_data, sign_data_size,
+     247                 :            :         &spdm_context->spdm_10_11_verify_signature_endian);
+     248                 :            :     libspdm_req_asym_free(spdm_context->connection_info.algorithm.req_base_asym_alg, context);
+     249                 :            : #else
+     250                 :         11 :     result = libspdm_req_asym_verify_hash_ex(
+     251                 :         11 :         spdm_context->connection_info.version, SPDM_FINISH,
+     252                 :         11 :         spdm_context->connection_info.algorithm.req_base_asym_alg,
+     253                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+     254                 :            :         context, hash_data, hash_size, sign_data, sign_data_size,
+     255                 :            :         &spdm_context->spdm_10_11_verify_signature_endian);
+     256         [ +  + ]:         11 :     if (slot_id == 0xFF) {
+     257                 :          1 :         libspdm_req_asym_free(spdm_context->connection_info.algorithm.req_base_asym_alg, context);
+     258                 :            :     }
+     259                 :            : #endif
+     260                 :            : 
+     261         [ +  + ]:         11 :     if (!result) {
+     262                 :          4 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR, "!!! VerifyFinishSignature - FAIL !!!\n"));
+     263                 :          4 :         return false;
+     264                 :            :     }
+     265                 :          7 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "!!! VerifyFinishSignature - PASS !!!\n"));
+     266                 :            : 
+     267                 :          7 :     return true;
+     268                 :            : }
+     269                 :            : #endif
+     270                 :            : 
+     271                 :         12 : bool libspdm_generate_finish_rsp_hmac(libspdm_context_t *spdm_context,
+     272                 :            :                                       libspdm_session_info_t *session_info,
+     273                 :            :                                       uint8_t *hmac)
+     274                 :            : {
+     275                 :            :     uint8_t hmac_data[LIBSPDM_MAX_HASH_SIZE];
+     276                 :            :     size_t hash_size;
+     277                 :            :     bool result;
+     278                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     279                 :            :     uint8_t slot_id;
+     280                 :            :     uint8_t *cert_chain_buffer;
+     281                 :            :     size_t cert_chain_buffer_size;
+     282                 :            :     uint8_t *mut_cert_chain_buffer;
+     283                 :            :     size_t mut_cert_chain_buffer_size;
+     284                 :            :     uint8_t *th_curr_data;
+     285                 :            :     size_t th_curr_data_size;
+     286                 :            :     libspdm_th_managed_buffer_t th_curr;
+     287                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     288                 :            : #endif
+     289                 :            : 
+     290                 :         12 :     hash_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+     291                 :            : 
+     292                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     293                 :            :     slot_id = spdm_context->connection_info.local_used_cert_chain_slot_id;
+     294                 :            :     LIBSPDM_ASSERT((slot_id < SPDM_MAX_SLOT_COUNT) || (slot_id == 0xFF));
+     295                 :            :     if (slot_id == 0xFF) {
+     296                 :            :         result = libspdm_get_local_public_key_buffer(
+     297                 :            :             spdm_context, (const void **)&cert_chain_buffer, &cert_chain_buffer_size);
+     298                 :            :     } else {
+     299                 :            :         result = libspdm_get_local_cert_chain_buffer(
+     300                 :            :             spdm_context, (const void **)&cert_chain_buffer, &cert_chain_buffer_size);
+     301                 :            :     }
+     302                 :            :     if (!result) {
+     303                 :            :         return false;
+     304                 :            :     }
+     305                 :            : 
+     306                 :            :     if (session_info->mut_auth_requested) {
+     307                 :            :         slot_id = spdm_context->connection_info.peer_used_cert_chain_slot_id;
+     308                 :            :         LIBSPDM_ASSERT((slot_id < SPDM_MAX_SLOT_COUNT) || (slot_id == 0xFF));
+     309                 :            :         if (slot_id == 0xFF) {
+     310                 :            :             result = libspdm_get_peer_public_key_buffer(
+     311                 :            :                 spdm_context, (const void **)&mut_cert_chain_buffer, &mut_cert_chain_buffer_size);
+     312                 :            :         } else {
+     313                 :            :             result = libspdm_get_peer_cert_chain_buffer(
+     314                 :            :                 spdm_context, (const void **)&mut_cert_chain_buffer, &mut_cert_chain_buffer_size);
+     315                 :            :         }
+     316                 :            :         if (!result) {
+     317                 :            :             return false;
+     318                 :            :         }
+     319                 :            :     } else {
+     320                 :            :         mut_cert_chain_buffer = NULL;
+     321                 :            :         mut_cert_chain_buffer_size = 0;
+     322                 :            :     }
+     323                 :            : 
+     324                 :            :     result = libspdm_calculate_th_for_finish(
+     325                 :            :         spdm_context, session_info, cert_chain_buffer,
+     326                 :            :         cert_chain_buffer_size, mut_cert_chain_buffer,
+     327                 :            :         mut_cert_chain_buffer_size, &th_curr);
+     328                 :            :     if (!result) {
+     329                 :            :         return false;
+     330                 :            :     }
+     331                 :            :     th_curr_data = libspdm_get_managed_buffer(&th_curr);
+     332                 :            :     th_curr_data_size = libspdm_get_managed_buffer_size(&th_curr);
+     333                 :            : 
+     334                 :            :     result = libspdm_hash_all (spdm_context->connection_info.algorithm.base_hash_algo,
+     335                 :            :                                th_curr_data, th_curr_data_size, hash_data);
+     336                 :            :     if (!result) {
+     337                 :            :         return false;
+     338                 :            :     }
+     339                 :            : 
+     340                 :            :     result = libspdm_hmac_all_with_response_finished_key(
+     341                 :            :         session_info->secured_message_context, hash_data,
+     342                 :            :         hash_size, hmac_data);
+     343                 :            :     if (!result) {
+     344                 :            :         return false;
+     345                 :            :     }
+     346                 :            : #else
+     347                 :         12 :     result = libspdm_calculate_th_hmac_for_finish_rsp(
+     348                 :            :         spdm_context, session_info, &hash_size, hmac_data);
+     349         [ -  + ]:         12 :     if (!result) {
+     350                 :          0 :         return false;
+     351                 :            :     }
+     352                 :            : #endif
+     353                 :         12 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "th_curr hmac - "));
+     354                 :         12 :     LIBSPDM_INTERNAL_DUMP_DATA(hmac_data, hash_size);
+     355                 :         12 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     356                 :            : 
+     357                 :         12 :     libspdm_copy_mem(hmac, hash_size, hmac_data, hash_size);
+     358                 :            : 
+     359                 :         12 :     return true;
+     360                 :            : }
+     361                 :            : 
+     362                 :         28 : libspdm_return_t libspdm_get_response_finish(libspdm_context_t *spdm_context, size_t request_size,
+     363                 :            :                                              const void *request,
+     364                 :            :                                              size_t *response_size,
+     365                 :            :                                              void *response)
+     366                 :            : {
+     367                 :            :     uint32_t session_id;
+     368                 :            :     bool result;
+     369                 :            :     uint32_t hmac_size;
+     370                 :            :     uint32_t signature_size;
+     371                 :            :     uint8_t req_slot_id;
+     372                 :            :     const spdm_finish_request_t *spdm_request;
+     373                 :            :     spdm_finish_response_t *spdm_response;
+     374                 :            :     libspdm_session_info_t *session_info;
+     375                 :            :     uint8_t th2_hash_data[LIBSPDM_MAX_HASH_SIZE];
+     376                 :            :     libspdm_return_t status;
+     377                 :            :     libspdm_session_state_t session_state;
+     378                 :            : 
+     379                 :         28 :     spdm_request = request;
+     380                 :            : 
+     381                 :            :     /* -=[Check Parameters Phase]=- */
+     382         [ -  + ]:         28 :     LIBSPDM_ASSERT(spdm_request->header.request_response_code == SPDM_FINISH);
+     383                 :            : 
+     384         [ -  + ]:         28 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_11) {
+     385                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     386                 :            :                                                SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+     387                 :            :                                                SPDM_FINISH,
+     388                 :            :                                                response_size, response);
+     389                 :            :     }
+     390                 :            : 
+     391         [ -  + ]:         28 :     if (spdm_request->header.spdm_version != libspdm_get_connection_version(spdm_context)) {
+     392                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     393                 :            :                                                SPDM_ERROR_CODE_VERSION_MISMATCH, 0,
+     394                 :            :                                                response_size, response);
+     395                 :            :     }
+     396         [ +  + ]:         28 :     if (spdm_context->response_state != LIBSPDM_RESPONSE_STATE_NORMAL) {
+     397                 :          3 :         return libspdm_responder_handle_response_state(
+     398                 :            :             spdm_context,
+     399                 :          3 :             spdm_request->header.request_response_code,
+     400                 :            :             response_size, response);
+     401                 :            :     }
+     402         [ +  + ]:         25 :     if (!libspdm_is_capabilities_flag_supported(
+     403                 :            :             spdm_context, false,
+     404                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP,
+     405                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP)) {
+     406                 :          1 :         return libspdm_generate_error_response(
+     407                 :            :             spdm_context, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+     408                 :            :             SPDM_FINISH, response_size, response);
+     409                 :            :     }
+     410         [ +  + ]:         24 :     if (spdm_context->connection_info.connection_state < LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
+     411                 :          1 :         return libspdm_generate_error_response(spdm_context,
+     412                 :            :                                                SPDM_ERROR_CODE_UNEXPECTED_REQUEST,
+     413                 :            :                                                0, response_size, response);
+     414                 :            :     }
+     415         [ +  + ]:         23 :     if (!libspdm_is_capabilities_flag_supported(
+     416                 :            :             spdm_context, false,
+     417                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP,
+     418                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)) {
+     419                 :            :         /* No handshake in clear, then it must be in a session.*/
+     420         [ -  + ]:          1 :         if (!spdm_context->last_spdm_request_session_id_valid) {
+     421                 :          0 :             return libspdm_generate_error_response(
+     422                 :            :                 spdm_context, SPDM_ERROR_CODE_SESSION_REQUIRED, 0, response_size, response);
+     423                 :            :         }
+     424                 :            :     } else {
+     425                 :            :         /* handshake in clear, then it must not be in a session.*/
+     426         [ -  + ]:         22 :         if (spdm_context->last_spdm_request_session_id_valid) {
+     427                 :          0 :             return libspdm_generate_error_response(
+     428                 :            :                 spdm_context, SPDM_ERROR_CODE_SESSION_REQUIRED, 0,
+     429                 :            :                 response_size, response);
+     430                 :            :         }
+     431                 :            :     }
+     432         [ +  + ]:         23 :     if (spdm_context->last_spdm_request_session_id_valid) {
+     433                 :          1 :         session_id = spdm_context->last_spdm_request_session_id;
+     434                 :            :     } else {
+     435                 :         22 :         session_id = spdm_context->latest_session_id;
+     436                 :            :     }
+     437                 :         23 :     session_info = libspdm_get_session_info_via_session_id(spdm_context, session_id);
+     438         [ -  + ]:         23 :     if (session_info == NULL) {
+     439                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     440                 :            :                                                SPDM_ERROR_CODE_SESSION_REQUIRED, 0,
+     441                 :            :                                                response_size, response);
+     442                 :            :     }
+     443         [ -  + ]:         23 :     if (session_info->use_psk) {
+     444                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     445                 :            :                                                SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+     446                 :            :                                                response_size, response);
+     447                 :            :     }
+     448                 :         23 :     session_state = libspdm_secured_message_get_session_state(
+     449                 :            :         session_info->secured_message_context);
+     450         [ +  + ]:         23 :     if (session_state != LIBSPDM_SESSION_STATE_HANDSHAKING) {
+     451                 :          1 :         return libspdm_generate_error_response(spdm_context,
+     452                 :            :                                                SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+     453                 :            :                                                response_size, response);
+     454                 :            :     }
+     455                 :            : 
+     456         [ +  + ]:         22 :     if (((session_info->mut_auth_requested == 0) &&
+     457         [ +  - ]:          9 :          ((spdm_request->header.param1 & SPDM_FINISH_REQUEST_ATTRIBUTES_SIGNATURE_INCLUDED) !=
+     458                 :         22 :           0)) ||
+     459         [ +  + ]:         22 :         ((session_info->mut_auth_requested != 0) &&
+     460         [ -  + ]:         13 :          ((spdm_request->header.param1 & SPDM_FINISH_REQUEST_ATTRIBUTES_SIGNATURE_INCLUDED) ==
+     461                 :            :           0))) {
+     462                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     463                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     464                 :            :                                                response_size, response);
+     465                 :            :     }
+     466                 :            : 
+     467                 :         22 :     hmac_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+     468                 :         22 :     signature_size = 0;
+     469                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP
+     470         [ +  + ]:         22 :     if (session_info->mut_auth_requested) {
+     471                 :         13 :         signature_size = libspdm_get_req_asym_signature_size(
+     472                 :         13 :             spdm_context->connection_info.algorithm.req_base_asym_alg);
+     473                 :            :     }
+     474                 :            : #endif
+     475                 :            : 
+     476                 :         22 :     if (request_size <
+     477         [ +  + ]:         22 :         sizeof(spdm_finish_request_t) + signature_size + hmac_size) {
+     478                 :          1 :         return libspdm_generate_error_response(spdm_context,
+     479                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     480                 :            :                                                response_size, response);
+     481                 :            :     }
+     482                 :            : 
+     483         [ +  + ]:         21 :     if ((spdm_request->header.param1 & SPDM_FINISH_REQUEST_ATTRIBUTES_SIGNATURE_INCLUDED) != 0) {
+     484                 :         13 :         req_slot_id = spdm_request->header.param2;
+     485   [ +  +  +  + ]:         13 :         if ((req_slot_id != 0xFF) &&
+     486                 :            :             (req_slot_id >= SPDM_MAX_SLOT_COUNT)) {
+     487                 :          1 :             return libspdm_generate_error_response(spdm_context,
+     488                 :            :                                                    SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     489                 :            :                                                    response_size, response);
+     490                 :            :         }
+     491                 :            : 
+     492         [ +  - ]:         12 :         if (libspdm_is_capabilities_flag_supported(
+     493                 :            :                 spdm_context, false,
+     494                 :            :                 SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP,
+     495                 :            :                 SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)) {
+     496         [ +  + ]:         12 :             if (((session_info->mut_auth_requested ==
+     497                 :         11 :                   SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_ENCAP_REQUEST) ||
+     498         [ -  + ]:         11 :                  (session_info->mut_auth_requested ==
+     499                 :          1 :                   SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_GET_DIGESTS)) &&
+     500         [ +  - ]:          1 :                 (req_slot_id != spdm_context->encap_context.req_slot_id)) {
+     501                 :          1 :                 return libspdm_generate_error_response(spdm_context,
+     502                 :            :                                                        SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     503                 :            :                                                        response_size, response);
+     504                 :            :             }
+     505                 :            :         }
+     506                 :            :     }
+     507                 :            : 
+     508                 :         19 :     libspdm_reset_message_buffer_via_request_code(spdm_context, session_info,
+     509                 :         19 :                                                   spdm_request->header.request_response_code);
+     510                 :            : 
+     511                 :         19 :     status = libspdm_append_message_f(spdm_context, session_info, false, request,
+     512                 :            :                                       sizeof(spdm_finish_request_t));
+     513         [ -  + ]:         19 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     514                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     515                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     516                 :            :                                                response_size, response);
+     517                 :            :     }
+     518                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP
+     519         [ +  + ]:         19 :     if (session_info->mut_auth_requested) {
+     520                 :         11 :         result = libspdm_verify_finish_req_signature(
+     521                 :            :             spdm_context, session_info,
+     522                 :            :             (const uint8_t *)request + sizeof(spdm_finish_request_t), signature_size);
+     523         [ +  + ]:         11 :         if (!result) {
+     524         [ +  - ]:          4 :             if((spdm_context->handle_error_return_policy &
+     525                 :            :                 LIBSPDM_DATA_HANDLE_ERROR_RETURN_POLICY_DROP_ON_DECRYPT_ERROR) == 0) {
+     526                 :          4 :                 return libspdm_generate_error_response(
+     527                 :            :                     spdm_context, SPDM_ERROR_CODE_DECRYPT_ERROR, 0,
+     528                 :            :                     response_size, response);
+     529                 :            :             } else {
+     530                 :            :                 /**
+     531                 :            :                  * just ignore this message
+     532                 :            :                  * return UNSUPPORTED and clear response_size to continue the dispatch without send response.
+     533                 :            :                  **/
+     534                 :          0 :                 *response_size = 0;
+     535                 :          0 :                 return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     536                 :            :             }
+     537                 :            :         }
+     538                 :          7 :         status = libspdm_append_message_f(
+     539                 :            :             spdm_context, session_info, false,
+     540                 :            :             (const uint8_t *)request + sizeof(spdm_finish_request_t),
+     541                 :            :             signature_size);
+     542         [ -  + ]:          7 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     543                 :          0 :             return libspdm_generate_error_response(
+     544                 :            :                 spdm_context, SPDM_ERROR_CODE_UNSPECIFIED,
+     545                 :            :                 0, response_size, response);
+     546                 :            :         }
+     547                 :            :     }
+     548                 :            : #endif
+     549                 :            : 
+     550                 :         15 :     result = libspdm_verify_finish_req_hmac(
+     551                 :         15 :         spdm_context, session_info, (const uint8_t *)request + signature_size +
+     552                 :            :         sizeof(spdm_finish_request_t), hmac_size);
+     553         [ +  + ]:         15 :     if (!result) {
+     554         [ +  - ]:          2 :         if((spdm_context->handle_error_return_policy &
+     555                 :            :             LIBSPDM_DATA_HANDLE_ERROR_RETURN_POLICY_DROP_ON_DECRYPT_ERROR) == 0) {
+     556                 :          2 :             return libspdm_generate_error_response(
+     557                 :            :                 spdm_context, SPDM_ERROR_CODE_DECRYPT_ERROR, 0,
+     558                 :            :                 response_size, response);
+     559                 :            :         } else {
+     560                 :            :             /**
+     561                 :            :              * just ignore this message
+     562                 :            :              * return UNSUPPORTED and clear response_size to continue the dispatch without send response
+     563                 :            :              **/
+     564                 :          0 :             *response_size = 0;
+     565                 :          0 :             return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     566                 :            :         }
+     567                 :            :     }
+     568                 :            : 
+     569                 :         13 :     status = libspdm_append_message_f(spdm_context, session_info, false,
+     570                 :         13 :                                       (const uint8_t *)request + signature_size +
+     571                 :            :                                       sizeof(spdm_finish_request_t),
+     572                 :            :                                       hmac_size);
+     573         [ -  + ]:         13 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     574                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     575                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     576                 :            :                                                response_size, response);
+     577                 :            :     }
+     578                 :            : 
+     579         [ +  + ]:         13 :     if (!libspdm_is_capabilities_flag_supported(
+     580                 :            :             spdm_context, false,
+     581                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP,
+     582                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)) {
+     583                 :          1 :         hmac_size = 0;
+     584                 :            :     }
+     585                 :            : 
+     586         [ -  + ]:         13 :     LIBSPDM_ASSERT(*response_size >= sizeof(spdm_finish_response_t) + hmac_size);
+     587                 :         13 :     *response_size = sizeof(spdm_finish_response_t) + hmac_size;
+     588                 :         13 :     libspdm_zero_mem(response, *response_size);
+     589                 :         13 :     spdm_response = response;
+     590                 :            : 
+     591                 :         13 :     spdm_response->header.spdm_version = spdm_request->header.spdm_version;
+     592                 :         13 :     spdm_response->header.request_response_code = SPDM_FINISH_RSP;
+     593                 :         13 :     spdm_response->header.param1 = 0;
+     594                 :         13 :     spdm_response->header.param2 = 0;
+     595                 :            : 
+     596                 :         13 :     status = libspdm_append_message_f(spdm_context, session_info, false, spdm_response,
+     597                 :            :                                       sizeof(spdm_finish_response_t));
+     598         [ -  + ]:         13 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     599                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     600                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     601                 :            :                                                response_size, response);
+     602                 :            :     }
+     603                 :            : 
+     604         [ +  + ]:         13 :     if (libspdm_is_capabilities_flag_supported(
+     605                 :            :             spdm_context, false,
+     606                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP,
+     607                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)) {
+     608                 :         12 :         result = libspdm_generate_finish_rsp_hmac(
+     609                 :            :             spdm_context, session_info,
+     610                 :            :             (uint8_t *)spdm_response + sizeof(spdm_finish_request_t));
+     611         [ -  + ]:         12 :         if (!result) {
+     612                 :          0 :             return libspdm_generate_error_response(
+     613                 :            :                 spdm_context,
+     614                 :            :                 SPDM_ERROR_CODE_UNSPECIFIED,
+     615                 :            :                 0, response_size, response);
+     616                 :            :         }
+     617                 :            : 
+     618                 :         12 :         status = libspdm_append_message_f(
+     619                 :            :             spdm_context, session_info, false,
+     620                 :            :             (uint8_t *)spdm_response + sizeof(spdm_finish_request_t),
+     621                 :            :             hmac_size);
+     622         [ -  + ]:         12 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     623                 :          0 :             return libspdm_generate_error_response(
+     624                 :            :                 spdm_context, SPDM_ERROR_CODE_UNSPECIFIED,
+     625                 :            :                 0, response_size, response);
+     626                 :            :         }
+     627                 :            :     }
+     628                 :            : 
+     629                 :         13 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "libspdm_generate_session_data_key[%x]\n", session_id));
+     630                 :         13 :     result = libspdm_calculate_th2_hash(spdm_context, session_info, false, th2_hash_data);
+     631         [ -  + ]:         13 :     if (!result) {
+     632                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     633                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     634                 :            :                                                response_size, response);
+     635                 :            :     }
+     636                 :         13 :     result = libspdm_generate_session_data_key(
+     637                 :            :         session_info->secured_message_context, th2_hash_data);
+     638         [ -  + ]:         13 :     if (!result) {
+     639                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     640                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     641                 :            :                                                response_size, response);
+     642                 :            :     }
+     643                 :            : 
+     644                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_HBEAT_CAP
+     645         [ -  + ]:         13 :     if (libspdm_is_capabilities_flag_supported(
+     646                 :            :             spdm_context, false,
+     647                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP,
+     648                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP)) {
+     649                 :          0 :         result = libspdm_start_watchdog(
+     650                 :          0 :             session_id, spdm_context->local_context.heartbeat_period * 2);
+     651         [ #  # ]:          0 :         if (!result) {
+     652                 :          0 :             return libspdm_generate_error_response(spdm_context,
+     653                 :            :                                                    SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     654                 :            :                                                    response_size, response);
+     655                 :            :         }
+     656                 :            :     }
+     657                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_HBEAT_CAP */
+     658                 :            : 
+     659                 :         13 :     return LIBSPDM_STATUS_SUCCESS;
+     660                 :            : }
+     661                 :            : 
+     662                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_get_key_pair_info.c.func-sort-c.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_get_key_pair_info.c.func-sort-c.html new file mode 100644 index 00000000000..d0ca10118f9 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_get_key_pair_info.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_get_key_pair_info.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_get_key_pair_info.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:395275.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:163053.3 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_response_key_pair_info4
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_get_key_pair_info.c.func.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_get_key_pair_info.c.func.html new file mode 100644 index 00000000000..8638745d54c --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_get_key_pair_info.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_get_key_pair_info.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_get_key_pair_info.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:395275.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:163053.3 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_response_key_pair_info4
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_get_key_pair_info.c.gcov.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_get_key_pair_info.c.gcov.html new file mode 100644 index 00000000000..3b5d9b12a99 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_get_key_pair_info.c.gcov.html @@ -0,0 +1,242 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_get_key_pair_info.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_get_key_pair_info.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:395275.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:163053.3 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2024 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_responder_lib.h"
+       8                 :            : 
+       9                 :            : #if LIBSPDM_ENABLE_CAPABILITY_GET_KEY_PAIR_INFO_CAP
+      10                 :            : 
+      11                 :          4 : libspdm_return_t libspdm_get_response_key_pair_info(libspdm_context_t *spdm_context,
+      12                 :            :                                                     size_t request_size, const void *request,
+      13                 :            :                                                     size_t *response_size, void *response)
+      14                 :            : {
+      15                 :            :     const spdm_get_key_pair_info_request_t *spdm_request;
+      16                 :            :     spdm_key_pair_info_response_t *spdm_response;
+      17                 :            : 
+      18                 :            :     libspdm_session_info_t *session_info;
+      19                 :            :     libspdm_session_state_t session_state;
+      20                 :            : 
+      21                 :            :     uint8_t total_key_pairs;
+      22                 :            :     uint16_t capabilities;
+      23                 :            :     uint16_t key_usage_capabilities;
+      24                 :            :     uint16_t current_key_usage;
+      25                 :            :     uint32_t asym_algo_capabilities;
+      26                 :            :     uint32_t current_asym_algo;
+      27                 :            :     uint16_t public_key_info_len;
+      28                 :            :     uint8_t assoc_cert_slot_mask;
+      29                 :            :     uint8_t key_pair_id;
+      30                 :            :     bool result;
+      31                 :            :     uint8_t *public_key_info;
+      32                 :            : 
+      33                 :          4 :     spdm_request = request;
+      34                 :            : 
+      35                 :            :     /* -=[Check Parameters Phase]=- */
+      36         [ -  + ]:          4 :     LIBSPDM_ASSERT(spdm_request->header.request_response_code == SPDM_GET_KEY_PAIR_INFO);
+      37                 :            : 
+      38         [ -  + ]:          4 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_13) {
+      39                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      40                 :            :                                                SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+      41                 :            :                                                SPDM_GET_KEY_PAIR_INFO,
+      42                 :            :                                                response_size, response);
+      43                 :            :     }
+      44                 :            : 
+      45         [ -  + ]:          4 :     if (spdm_request->header.spdm_version != libspdm_get_connection_version(spdm_context)) {
+      46                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      47                 :            :                                                SPDM_ERROR_CODE_VERSION_MISMATCH, 0,
+      48                 :            :                                                response_size, response);
+      49                 :            :     }
+      50                 :            : 
+      51         [ -  + ]:          4 :     if (spdm_context->response_state != LIBSPDM_RESPONSE_STATE_NORMAL) {
+      52                 :          0 :         return libspdm_responder_handle_response_state(spdm_context,
+      53                 :          0 :                                                        spdm_request->header.request_response_code,
+      54                 :            :                                                        response_size, response);
+      55                 :            :     }
+      56                 :            : 
+      57         [ -  + ]:          4 :     if (request_size < sizeof(spdm_get_key_pair_info_request_t)) {
+      58                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      59                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+      60                 :            :                                                response_size, response);
+      61                 :            :     }
+      62                 :            : 
+      63         [ -  + ]:          4 :     if (spdm_context->connection_info.connection_state <
+      64                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
+      65                 :          0 :         return libspdm_generate_error_response(
+      66                 :            :             spdm_context,
+      67                 :            :             SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+      68                 :            :             response_size, response);
+      69                 :            :     }
+      70                 :            : 
+      71         [ -  + ]:          4 :     if (spdm_context->last_spdm_request_session_id_valid) {
+      72                 :          0 :         session_info = libspdm_get_session_info_via_session_id(
+      73                 :            :             spdm_context,
+      74                 :            :             spdm_context->last_spdm_request_session_id);
+      75         [ #  # ]:          0 :         if (session_info == NULL) {
+      76                 :          0 :             return libspdm_generate_error_response(
+      77                 :            :                 spdm_context,
+      78                 :            :                 SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+      79                 :            :                 response_size, response);
+      80                 :            :         }
+      81                 :          0 :         session_state = libspdm_secured_message_get_session_state(
+      82                 :            :             session_info->secured_message_context);
+      83         [ #  # ]:          0 :         if (session_state != LIBSPDM_SESSION_STATE_ESTABLISHED) {
+      84                 :          0 :             return libspdm_generate_error_response(
+      85                 :            :                 spdm_context,
+      86                 :            :                 SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+      87                 :            :                 response_size, response);
+      88                 :            :         }
+      89                 :            :     }
+      90                 :            : 
+      91         [ +  + ]:          4 :     if (!libspdm_is_capabilities_flag_supported(
+      92                 :            :             spdm_context, false, 0,
+      93                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_GET_KEY_PAIR_INFO_CAP)) {
+      94                 :          1 :         return libspdm_generate_error_response(
+      95                 :            :             spdm_context, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+      96                 :            :             SPDM_GET_KEY_PAIR_INFO, response_size, response);
+      97                 :            :     }
+      98                 :            : 
+      99                 :          3 :     total_key_pairs = spdm_context->local_context.total_key_pairs;
+     100                 :          3 :     key_pair_id = spdm_request->key_pair_id;
+     101   [ +  +  +  + ]:          3 :     if ((key_pair_id == 0) || (key_pair_id > total_key_pairs)) {
+     102                 :          2 :         return libspdm_generate_error_response(spdm_context,
+     103                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     104                 :            :                                                response_size, response);
+     105                 :            :     }
+     106                 :            : 
+     107         [ -  + ]:          1 :     LIBSPDM_ASSERT(*response_size >= sizeof(spdm_key_pair_info_response_t));
+     108                 :          1 :     public_key_info_len = (uint16_t)(*response_size - sizeof(spdm_key_pair_info_response_t));
+     109                 :          1 :     libspdm_zero_mem(response, *response_size);
+     110                 :            : 
+     111                 :          1 :     public_key_info = (uint8_t*)response + sizeof(spdm_key_pair_info_response_t);
+     112                 :          1 :     result = libspdm_read_key_pair_info(
+     113                 :            :         spdm_context,
+     114                 :            :         key_pair_id,
+     115                 :            :         &capabilities,
+     116                 :            :         &key_usage_capabilities,
+     117                 :            :         &current_key_usage,
+     118                 :            :         &asym_algo_capabilities,
+     119                 :            :         &current_asym_algo,
+     120                 :            :         &assoc_cert_slot_mask,
+     121                 :            :         &public_key_info_len,
+     122                 :            :         public_key_info);
+     123         [ -  + ]:          1 :     if (!result) {
+     124                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     125                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     126                 :            :                                                response_size, response);
+     127                 :            :     }
+     128                 :            : 
+     129                 :            :     /*If responder doesn't support SET_KEY_PAIR_INFO_CAP,the capabilities should be 0*/
+     130         [ +  - ]:          1 :     if (!libspdm_is_capabilities_flag_supported(
+     131                 :            :             spdm_context, false, 0,
+     132                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_KEY_PAIR_INFO_CAP)) {
+     133                 :          1 :         capabilities = 0;
+     134                 :            :     }
+     135                 :            : 
+     136                 :          1 :     spdm_response = response;
+     137                 :          1 :     *response_size = sizeof(spdm_key_pair_info_response_t) + public_key_info_len;
+     138                 :            : 
+     139                 :          1 :     spdm_response->header.spdm_version = spdm_request->header.spdm_version;
+     140                 :          1 :     spdm_response->header.request_response_code = SPDM_KEY_PAIR_INFO;
+     141                 :          1 :     spdm_response->header.param1 = 0;
+     142                 :          1 :     spdm_response->header.param2 = 0;
+     143                 :          1 :     spdm_response->total_key_pairs = total_key_pairs;
+     144                 :          1 :     spdm_response->key_pair_id = key_pair_id;
+     145                 :          1 :     spdm_response->capabilities = capabilities & SPDM_KEY_PAIR_CAP_MASK;
+     146                 :          1 :     spdm_response->key_usage_capabilities = key_usage_capabilities & SPDM_KEY_USAGE_BIT_MASK;
+     147                 :          1 :     spdm_response->current_key_usage = current_key_usage & SPDM_KEY_USAGE_BIT_MASK;
+     148                 :          1 :     spdm_response->asym_algo_capabilities = asym_algo_capabilities &
+     149                 :            :                                             SPDM_KEY_PAIR_ASYM_ALGO_CAP_MASK;
+     150                 :          1 :     spdm_response->current_asym_algo = current_asym_algo & SPDM_KEY_PAIR_ASYM_ALGO_CAP_MASK;
+     151                 :          1 :     spdm_response->public_key_info_len = public_key_info_len;
+     152                 :          1 :     spdm_response->assoc_cert_slot_mask = assoc_cert_slot_mask;
+     153                 :            : 
+     154                 :          1 :     return LIBSPDM_STATUS_SUCCESS;
+     155                 :            : }
+     156                 :            : 
+     157                 :            : #endif /*LIBSPDM_ENABLE_CAPABILITY_GET_KEY_PAIR_INFO_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_handle_response_state.c.func-sort-c.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_handle_response_state.c.func-sort-c.html new file mode 100644 index 00000000000..5ed450085b8 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_handle_response_state.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_handle_response_state.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_handle_response_state.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:212680.8 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:6966.7 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_handle_response_state47
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_handle_response_state.c.func.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_handle_response_state.c.func.html new file mode 100644 index 00000000000..049a3cf31a6 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_handle_response_state.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_handle_response_state.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_handle_response_state.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:212680.8 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:6966.7 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_handle_response_state47
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_handle_response_state.c.gcov.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_handle_response_state.c.gcov.html new file mode 100644 index 00000000000..5b95499b2e8 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_handle_response_state.c.gcov.html @@ -0,0 +1,147 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_handle_response_state.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_handle_response_state.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:212680.8 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:6966.7 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 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_responder_lib.h"
+       8                 :            : 
+       9                 :         47 : libspdm_return_t libspdm_responder_handle_response_state(libspdm_context_t *spdm_context,
+      10                 :            :                                                          uint8_t request_code,
+      11                 :            :                                                          size_t *response_size,
+      12                 :            :                                                          void *response)
+      13                 :            : {
+      14                 :            :     libspdm_return_t status;
+      15                 :            : 
+      16   [ +  +  +  -  :         47 :     switch (spdm_context->response_state) {
+                      - ]
+      17                 :         18 :     case LIBSPDM_RESPONSE_STATE_BUSY:
+      18                 :         18 :         return libspdm_generate_error_response(spdm_context, SPDM_ERROR_CODE_BUSY,
+      19                 :            :                                                0, response_size, response);
+      20                 :            :     /* NOTE: Need to reset status to Normal in up level*/
+      21                 :         17 :     case LIBSPDM_RESPONSE_STATE_NEED_RESYNC:
+      22                 :         17 :         status = libspdm_generate_error_response(spdm_context,
+      23                 :            :                                                  SPDM_ERROR_CODE_REQUEST_RESYNCH, 0,
+      24                 :            :                                                  response_size, response);
+      25         [ -  + ]:         17 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+      26                 :          0 :             return status;
+      27                 :            :         }
+      28                 :            :         /* NOTE: Need to let SPDM_VERSION reset the State*/
+      29                 :         17 :         libspdm_set_connection_state(spdm_context,
+      30                 :            :                                      LIBSPDM_CONNECTION_STATE_NOT_STARTED);
+      31                 :         17 :         return LIBSPDM_STATUS_SUCCESS;
+      32                 :            :     #if LIBSPDM_RESPOND_IF_READY_SUPPORT
+      33                 :         12 :     case LIBSPDM_RESPONSE_STATE_NOT_READY:
+      34                 :            :         /*do not update ErrorData if a previous request has not been completed*/
+      35         [ +  + ]:         12 :         if(request_code != SPDM_RESPOND_IF_READY) {
+      36                 :         11 :             spdm_context->cache_spdm_request_size = spdm_context->last_spdm_request_size;
+      37                 :         11 :             libspdm_copy_mem(spdm_context->cache_spdm_request,
+      38                 :         11 :                              libspdm_get_scratch_buffer_cache_spdm_request_capacity(spdm_context),
+      39                 :         11 :                              spdm_context->last_spdm_request,
+      40                 :            :                              spdm_context->last_spdm_request_size);
+      41                 :         11 :             spdm_context->error_data.rd_exponent = 1;
+      42                 :         11 :             spdm_context->error_data.rd_tm = 1;
+      43                 :         11 :             spdm_context->error_data.request_code = request_code;
+      44                 :         11 :             spdm_context->error_data.token = spdm_context->current_token++;
+      45                 :            :         }
+      46                 :         12 :         return libspdm_generate_extended_error_response(
+      47                 :            :             spdm_context, SPDM_ERROR_CODE_RESPONSE_NOT_READY, 0,
+      48                 :            :             sizeof(spdm_error_data_response_not_ready_t),
+      49                 :         12 :             (uint8_t *)(void *)&spdm_context->error_data,
+      50                 :            :             response_size, response);
+      51                 :            :     #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
+      52                 :            :     /* NOTE: Need to reset status to Normal in up level*/
+      53                 :          0 :     case LIBSPDM_RESPONSE_STATE_PROCESSING_ENCAP:
+      54                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      55                 :            :                                                SPDM_ERROR_CODE_REQUEST_IN_FLIGHT,
+      56                 :            :                                                0, response_size, response);
+      57                 :            :     /* NOTE: Need let SPDM_ENCAPSULATED_RESPONSE_ACK reset the State*/
+      58                 :          0 :     default:
+      59                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      60                 :            :     }
+      61                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_heartbeat.c.func-sort-c.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_heartbeat.c.func-sort-c.html new file mode 100644 index 00000000000..d6c4d40efc3 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_heartbeat.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_heartbeat.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_heartbeat.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:313783.8 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:162466.7 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_response_heartbeat8
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_heartbeat.c.func.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_heartbeat.c.func.html new file mode 100644 index 00000000000..80a8a6c7f9f --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_heartbeat.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_heartbeat.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_heartbeat.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:313783.8 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:162466.7 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_response_heartbeat8
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_heartbeat.c.gcov.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_heartbeat.c.gcov.html new file mode 100644 index 00000000000..dcea6ed62eb --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_heartbeat.c.gcov.html @@ -0,0 +1,190 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_heartbeat.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_heartbeat.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:313783.8 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:162466.7 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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_responder_lib.h"
+       8                 :            : 
+       9                 :          8 : libspdm_return_t libspdm_get_response_heartbeat(libspdm_context_t *spdm_context,
+      10                 :            :                                                 size_t request_size,
+      11                 :            :                                                 const void *request,
+      12                 :            :                                                 size_t *response_size,
+      13                 :            :                                                 void *response)
+      14                 :            : {
+      15                 :            :     spdm_heartbeat_response_t *spdm_response;
+      16                 :            :     const spdm_heartbeat_request_t *spdm_request;
+      17                 :            :     libspdm_session_info_t *session_info;
+      18                 :            :     libspdm_session_state_t session_state;
+      19                 :            : 
+      20                 :          8 :     spdm_request = request;
+      21                 :            : 
+      22                 :            :     /* -=[Check Parameters Phase]=- */
+      23         [ -  + ]:          8 :     LIBSPDM_ASSERT(spdm_request->header.request_response_code == SPDM_HEARTBEAT);
+      24                 :            : 
+      25         [ -  + ]:          8 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_11) {
+      26                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      27                 :            :                                                SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+      28                 :            :                                                SPDM_HEARTBEAT,
+      29                 :            :                                                response_size, response);
+      30                 :            :     }
+      31                 :            : 
+      32         [ -  + ]:          8 :     if (spdm_request->header.spdm_version != libspdm_get_connection_version(spdm_context)) {
+      33                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      34                 :            :                                                SPDM_ERROR_CODE_VERSION_MISMATCH, 0,
+      35                 :            :                                                response_size, response);
+      36                 :            :     }
+      37         [ +  + ]:          8 :     if (spdm_context->response_state != LIBSPDM_RESPONSE_STATE_NORMAL) {
+      38                 :          3 :         return libspdm_responder_handle_response_state(
+      39                 :            :             spdm_context,
+      40                 :          3 :             spdm_request->header.request_response_code,
+      41                 :            :             response_size, response);
+      42                 :            :     }
+      43         [ -  + ]:          5 :     if (!libspdm_is_capabilities_flag_supported(
+      44                 :            :             spdm_context, false,
+      45                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP,
+      46                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP)) {
+      47                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      48                 :            :                                                SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+      49                 :            :                                                SPDM_HEARTBEAT, response_size, response);
+      50                 :            :     }
+      51         [ +  + ]:          5 :     if (spdm_context->connection_info.connection_state < LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
+      52                 :          1 :         return libspdm_generate_error_response(spdm_context,
+      53                 :            :                                                SPDM_ERROR_CODE_UNEXPECTED_REQUEST,
+      54                 :            :                                                0, response_size, response);
+      55                 :            :     }
+      56                 :            : 
+      57         [ -  + ]:          4 :     if (!spdm_context->last_spdm_request_session_id_valid) {
+      58                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      59                 :            :                                                SPDM_ERROR_CODE_SESSION_REQUIRED, 0,
+      60                 :            :                                                response_size, response);
+      61                 :            :     }
+      62                 :          4 :     session_info = libspdm_get_session_info_via_session_id(
+      63                 :            :         spdm_context, spdm_context->last_spdm_request_session_id);
+      64         [ -  + ]:          4 :     if (session_info == NULL) {
+      65                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      66                 :            :                                                SPDM_ERROR_CODE_SESSION_REQUIRED, 0,
+      67                 :            :                                                response_size, response);
+      68                 :            :     }
+      69                 :          4 :     session_state = libspdm_secured_message_get_session_state(
+      70                 :            :         session_info->secured_message_context);
+      71         [ -  + ]:          4 :     if (session_state != LIBSPDM_SESSION_STATE_ESTABLISHED) {
+      72                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      73                 :            :                                                SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+      74                 :            :                                                response_size, response);
+      75                 :            :     }
+      76                 :            : 
+      77                 :            :     /* this message can only be in secured session
+      78                 :            :      * thus don't need to consider transport layer padding, just check its exact size */
+      79         [ +  + ]:          4 :     if (request_size != sizeof(spdm_heartbeat_request_t)) {
+      80                 :          1 :         return libspdm_generate_error_response(spdm_context,
+      81                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+      82                 :            :                                                response_size, response);
+      83                 :            :     }
+      84                 :            : 
+      85         [ +  + ]:          3 :     if (session_info->heartbeat_period == 0) {
+      86                 :          1 :         return libspdm_generate_error_response(spdm_context,
+      87                 :            :                                                SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+      88                 :            :                                                response_size, response);
+      89                 :            :     }
+      90                 :            : 
+      91                 :          2 :     libspdm_reset_message_buffer_via_request_code(spdm_context, session_info,
+      92                 :          2 :                                                   spdm_request->header.request_response_code);
+      93                 :            : 
+      94         [ -  + ]:          2 :     LIBSPDM_ASSERT(*response_size >= sizeof(spdm_heartbeat_response_t));
+      95                 :          2 :     *response_size = sizeof(spdm_heartbeat_response_t);
+      96                 :          2 :     libspdm_zero_mem(response, *response_size);
+      97                 :          2 :     spdm_response = response;
+      98                 :            : 
+      99                 :          2 :     spdm_response->header.spdm_version = spdm_request->header.spdm_version;
+     100                 :          2 :     spdm_response->header.request_response_code = SPDM_HEARTBEAT_ACK;
+     101                 :          2 :     spdm_response->header.param1 = 0;
+     102                 :          2 :     spdm_response->header.param2 = 0;
+     103                 :            : 
+     104                 :          2 :     return LIBSPDM_STATUS_SUCCESS;
+     105                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_key_exchange.c.func-sort-c.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_key_exchange.c.func-sort-c.html new file mode 100644 index 00000000000..e58128fa8f3 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_key_exchange.c.func-sort-c.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_key_exchange.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_key_exchange.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:17322776.2 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:7411663.8 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_generate_key_exchange_rsp_hmac7
libspdm_generate_key_exchange_rsp_signature10
libspdm_get_response_key_exchange20
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_key_exchange.c.func.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_key_exchange.c.func.html new file mode 100644 index 00000000000..8d4b5ae5cf3 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_key_exchange.c.func.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_key_exchange.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_key_exchange.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:17322776.2 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:7411663.8 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_generate_key_exchange_rsp_hmac7
libspdm_generate_key_exchange_rsp_signature10
libspdm_get_response_key_exchange20
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_key_exchange.c.gcov.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_key_exchange.c.gcov.html new file mode 100644 index 00000000000..be2ce591dad --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_key_exchange.c.gcov.html @@ -0,0 +1,717 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_key_exchange.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_key_exchange.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:17322776.2 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:7411663.8 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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_responder_lib.h"
+       8                 :            : #include "internal/libspdm_secured_message_lib.h"
+       9                 :            : 
+      10                 :            : #if LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP
+      11                 :            : 
+      12                 :          7 : bool libspdm_generate_key_exchange_rsp_hmac(libspdm_context_t *spdm_context,
+      13                 :            :                                             libspdm_session_info_t *session_info,
+      14                 :            :                                             uint8_t *hmac)
+      15                 :            : {
+      16                 :            :     uint8_t hmac_data[LIBSPDM_MAX_HASH_SIZE];
+      17                 :            :     size_t hash_size;
+      18                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+      19                 :            :     uint8_t slot_id;
+      20                 :            :     uint8_t *cert_chain_buffer;
+      21                 :            :     size_t cert_chain_buffer_size;
+      22                 :            :     uint8_t *th_curr_data;
+      23                 :            :     size_t th_curr_data_size;
+      24                 :            :     libspdm_th_managed_buffer_t th_curr;
+      25                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+      26                 :            : #endif
+      27                 :            :     bool result;
+      28                 :            : 
+      29                 :          7 :     hash_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+      30                 :            : 
+      31                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+      32                 :            :     slot_id = spdm_context->connection_info.local_used_cert_chain_slot_id;
+      33                 :            :     LIBSPDM_ASSERT((slot_id < SPDM_MAX_SLOT_COUNT) || (slot_id == 0xFF));
+      34                 :            :     if (slot_id == 0xFF) {
+      35                 :            :         result = libspdm_get_local_public_key_buffer(
+      36                 :            :             spdm_context, (const void **)&cert_chain_buffer, &cert_chain_buffer_size);
+      37                 :            :     } else {
+      38                 :            :         result = libspdm_get_local_cert_chain_buffer(
+      39                 :            :             spdm_context, (const void **)&cert_chain_buffer, &cert_chain_buffer_size);
+      40                 :            :     }
+      41                 :            :     if (!result) {
+      42                 :            :         return false;
+      43                 :            :     }
+      44                 :            : 
+      45                 :            :     result = libspdm_calculate_th_for_exchange(
+      46                 :            :         spdm_context, session_info, cert_chain_buffer,
+      47                 :            :         cert_chain_buffer_size, &th_curr);
+      48                 :            :     if (!result) {
+      49                 :            :         return false;
+      50                 :            :     }
+      51                 :            :     th_curr_data = libspdm_get_managed_buffer(&th_curr);
+      52                 :            :     th_curr_data_size = libspdm_get_managed_buffer_size(&th_curr);
+      53                 :            : 
+      54                 :            :     result = libspdm_hash_all (spdm_context->connection_info.algorithm.base_hash_algo,
+      55                 :            :                                th_curr_data, th_curr_data_size, hash_data);
+      56                 :            :     if (!result) {
+      57                 :            :         return false;
+      58                 :            :     }
+      59                 :            : 
+      60                 :            :     result = libspdm_hmac_all_with_response_finished_key(
+      61                 :            :         session_info->secured_message_context, hash_data,
+      62                 :            :         hash_size, hmac_data);
+      63                 :            :     if (!result) {
+      64                 :            :         return false;
+      65                 :            :     }
+      66                 :            : #else
+      67                 :          7 :     result = libspdm_calculate_th_hmac_for_exchange_rsp(
+      68                 :            :         spdm_context, session_info, false, &hash_size, hmac_data);
+      69         [ -  + ]:          7 :     if (!result) {
+      70                 :          0 :         return false;
+      71                 :            :     }
+      72                 :            : #endif
+      73                 :          7 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "th_curr hmac - "));
+      74                 :          7 :     LIBSPDM_INTERNAL_DUMP_DATA(hmac_data, hash_size);
+      75                 :          7 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+      76                 :          7 :     libspdm_copy_mem(hmac, hash_size, hmac_data, hash_size);
+      77                 :            : 
+      78                 :          7 :     return true;
+      79                 :            : }
+      80                 :            : 
+      81                 :         10 : bool libspdm_generate_key_exchange_rsp_signature(libspdm_context_t *spdm_context,
+      82                 :            :                                                  libspdm_session_info_t *session_info,
+      83                 :            :                                                  uint8_t *signature)
+      84                 :            : {
+      85                 :            :     bool result;
+      86                 :            :     size_t signature_size;
+      87                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+      88                 :            :     uint8_t slot_id;
+      89                 :            :     uint8_t *th_curr_data;
+      90                 :            :     size_t th_curr_data_size;
+      91                 :            :     libspdm_th_managed_buffer_t th_curr;
+      92                 :            :     const uint8_t *cert_chain_buffer;
+      93                 :            :     size_t cert_chain_buffer_size;
+      94                 :            : #endif
+      95                 :            : #if ((LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT) && (LIBSPDM_DEBUG_BLOCK_ENABLE)) || \
+      96                 :            :     !(LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT)
+      97                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+      98                 :            : #endif
+      99                 :            : #if !(LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT) || (LIBSPDM_DEBUG_PRINT_ENABLE)
+     100                 :            :     size_t hash_size;
+     101                 :            : 
+     102                 :         10 :     hash_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+     103                 :            : #endif
+     104                 :            : 
+     105                 :         10 :     signature_size = libspdm_get_asym_signature_size(
+     106                 :            :         spdm_context->connection_info.algorithm.base_asym_algo);
+     107                 :            : 
+     108                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     109                 :            :     slot_id = spdm_context->connection_info.local_used_cert_chain_slot_id;
+     110                 :            :     LIBSPDM_ASSERT((slot_id < SPDM_MAX_SLOT_COUNT) || (slot_id == 0xFF));
+     111                 :            :     if (slot_id == 0xFF) {
+     112                 :            :         result = libspdm_get_local_public_key_buffer(
+     113                 :            :             spdm_context, (const void **)&cert_chain_buffer, &cert_chain_buffer_size);
+     114                 :            :     } else {
+     115                 :            :         result = libspdm_get_local_cert_chain_buffer(
+     116                 :            :             spdm_context, (const void **)&cert_chain_buffer, &cert_chain_buffer_size);
+     117                 :            :     }
+     118                 :            :     if (!result) {
+     119                 :            :         return false;
+     120                 :            :     }
+     121                 :            : 
+     122                 :            :     result = libspdm_calculate_th_for_exchange(
+     123                 :            :         spdm_context, session_info, cert_chain_buffer,
+     124                 :            :         cert_chain_buffer_size, &th_curr);
+     125                 :            :     if (!result) {
+     126                 :            :         return false;
+     127                 :            :     }
+     128                 :            :     th_curr_data = libspdm_get_managed_buffer(&th_curr);
+     129                 :            :     th_curr_data_size = libspdm_get_managed_buffer_size(&th_curr);
+     130                 :            : 
+     131                 :            :     /* Debug code only - required for debug print of th_curr hash below*/
+     132                 :            :     LIBSPDM_DEBUG_CODE(
+     133                 :            :         if (!libspdm_hash_all(
+     134                 :            :                 spdm_context->connection_info.algorithm.base_hash_algo,
+     135                 :            :                 th_curr_data, th_curr_data_size, hash_data)) {
+     136                 :            :         return false;
+     137                 :            :     }
+     138                 :            :         );
+     139                 :            : #else
+     140                 :         10 :     result = libspdm_calculate_th_hash_for_exchange(
+     141                 :            :         spdm_context, session_info, &hash_size, hash_data);
+     142         [ -  + ]:         10 :     if (!result) {
+     143                 :          0 :         return false;
+     144                 :            :     }
+     145                 :            : #endif
+     146                 :         10 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "th_curr hash - "));
+     147                 :         10 :     LIBSPDM_INTERNAL_DUMP_DATA(hash_data, hash_size);
+     148                 :         10 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     149                 :            : 
+     150                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     151                 :            :     result = libspdm_responder_data_sign(
+     152                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+     153                 :            :         spdm_context,
+     154                 :            : #endif
+     155                 :            :         spdm_context->connection_info.version, SPDM_KEY_EXCHANGE_RSP,
+     156                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+     157                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+     158                 :            :         false, th_curr_data, th_curr_data_size, signature, &signature_size);
+     159                 :            : #else
+     160                 :         10 :     result = libspdm_responder_data_sign(
+     161                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+     162                 :            :         spdm_context,
+     163                 :            : #endif
+     164                 :         10 :         spdm_context->connection_info.version, SPDM_KEY_EXCHANGE_RSP,
+     165                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+     166                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+     167                 :            :         true, hash_data, hash_size, signature, &signature_size);
+     168                 :            : #endif
+     169         [ +  - ]:         10 :     if (result) {
+     170                 :         10 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "signature - "));
+     171                 :         10 :         LIBSPDM_INTERNAL_DUMP_DATA(signature, signature_size);
+     172                 :         10 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     173                 :            :     }
+     174                 :         10 :     return result;
+     175                 :            : }
+     176                 :            : 
+     177                 :         20 : libspdm_return_t libspdm_get_response_key_exchange(libspdm_context_t *spdm_context,
+     178                 :            :                                                    size_t request_size,
+     179                 :            :                                                    const void *request,
+     180                 :            :                                                    size_t *response_size,
+     181                 :            :                                                    void *response)
+     182                 :            : {
+     183                 :            :     const spdm_key_exchange_request_t *spdm_request;
+     184                 :            :     spdm_key_exchange_response_t *spdm_response;
+     185                 :            :     size_t dhe_key_size;
+     186                 :            :     uint32_t measurement_summary_hash_size;
+     187                 :            :     uint32_t signature_size;
+     188                 :            :     uint32_t hmac_size;
+     189                 :            :     const uint8_t *cptr;
+     190                 :            :     uint8_t *ptr;
+     191                 :            :     uint16_t opaque_data_length;
+     192                 :            :     bool result;
+     193                 :            :     uint8_t slot_id;
+     194                 :            :     uint32_t session_id;
+     195                 :            :     void *dhe_context;
+     196                 :            :     libspdm_session_info_t *session_info;
+     197                 :            :     size_t total_size;
+     198                 :            :     uint16_t req_session_id;
+     199                 :            :     uint16_t rsp_session_id;
+     200                 :            :     libspdm_return_t status;
+     201                 :            :     size_t opaque_key_exchange_rsp_size;
+     202                 :            :     uint8_t th1_hash_data[LIBSPDM_MAX_HASH_SIZE];
+     203                 :            : 
+     204                 :         20 :     spdm_request = request;
+     205                 :            : 
+     206                 :            :     /* -=[Check Parameters Phase]=- */
+     207         [ -  + ]:         20 :     LIBSPDM_ASSERT(spdm_request->header.request_response_code == SPDM_KEY_EXCHANGE);
+     208                 :            : 
+     209         [ -  + ]:         20 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_11) {
+     210                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     211                 :            :                                                SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+     212                 :            :                                                SPDM_KEY_EXCHANGE,
+     213                 :            :                                                response_size, response);
+     214                 :            :     }
+     215                 :            : 
+     216         [ -  + ]:         20 :     if (spdm_request->header.spdm_version != libspdm_get_connection_version(spdm_context)) {
+     217                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     218                 :            :                                                SPDM_ERROR_CODE_VERSION_MISMATCH, 0,
+     219                 :            :                                                response_size, response);
+     220                 :            :     }
+     221         [ +  + ]:         20 :     if (spdm_context->response_state != LIBSPDM_RESPONSE_STATE_NORMAL) {
+     222                 :          3 :         return libspdm_responder_handle_response_state(
+     223                 :            :             spdm_context,
+     224                 :          3 :             spdm_request->header.request_response_code,
+     225                 :            :             response_size, response);
+     226                 :            :     }
+     227         [ -  + ]:         17 :     if (!libspdm_is_capabilities_flag_supported(
+     228                 :            :             spdm_context, false,
+     229                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP,
+     230                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP)) {
+     231                 :          0 :         return libspdm_generate_error_response(
+     232                 :            :             spdm_context, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+     233                 :            :             SPDM_KEY_EXCHANGE, response_size, response);
+     234                 :            :     }
+     235         [ +  + ]:         17 :     if (spdm_context->connection_info.connection_state < LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
+     236                 :          1 :         return libspdm_generate_error_response(spdm_context,
+     237                 :            :                                                SPDM_ERROR_CODE_UNEXPECTED_REQUEST,
+     238                 :            :                                                0, response_size, response);
+     239                 :            :     }
+     240         [ +  + ]:         16 :     if (libspdm_get_connection_version(spdm_context) >= SPDM_MESSAGE_VERSION_12) {
+     241         [ -  + ]:          4 :         if ((spdm_context->connection_info.algorithm.other_params_support &
+     242                 :            :              SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_MASK) != SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1) {
+     243                 :          0 :             return libspdm_generate_error_response(
+     244                 :            :                 spdm_context, SPDM_ERROR_CODE_INVALID_REQUEST,
+     245                 :            :                 0, response_size, response);
+     246                 :            :         }
+     247                 :            :     }
+     248         [ -  + ]:         16 :     if (spdm_context->last_spdm_request_session_id_valid) {
+     249                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     250                 :            :                                                SPDM_ERROR_CODE_UNEXPECTED_REQUEST,
+     251                 :            :                                                0, response_size, response);
+     252                 :            :     }
+     253                 :            : 
+     254         [ +  + ]:         16 :     if (spdm_request->header.param1 > 0) {
+     255         [ +  + ]:          4 :         if (!libspdm_is_capabilities_flag_supported(
+     256                 :            :                 spdm_context, false,
+     257                 :          3 :                 0, SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP) ||
+     258         [ +  - ]:          3 :             (spdm_context->connection_info.algorithm.measurement_spec == 0) ||
+     259         [ -  + ]:          3 :             (spdm_context->connection_info.algorithm.measurement_hash_algo == 0) ) {
+     260                 :          1 :             return libspdm_generate_error_response(
+     261                 :            :                 spdm_context, SPDM_ERROR_CODE_INVALID_REQUEST,
+     262                 :            :                 0, response_size, response);
+     263                 :            :         }
+     264                 :            :     }
+     265                 :            : 
+     266                 :         15 :     slot_id = spdm_request->header.param2;
+     267                 :            : 
+     268         [ +  + ]:         15 :     if (libspdm_is_capabilities_flag_supported(
+     269                 :            :             spdm_context, false,
+     270                 :            :             0, SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP)) {
+     271         [ +  + ]:         13 :         if (slot_id >= SPDM_MAX_SLOT_COUNT) {
+     272                 :          1 :             return libspdm_generate_error_response(spdm_context,
+     273                 :            :                                                    SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     274                 :            :                                                    response_size, response);
+     275                 :            :         }
+     276         [ -  + ]:         12 :         if (spdm_context->local_context.local_cert_chain_provision[slot_id] == NULL) {
+     277                 :          0 :             return libspdm_generate_error_response(spdm_context,
+     278                 :            :                                                    SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     279                 :            :                                                    response_size, response);
+     280                 :            :         }
+     281                 :            :     } else {
+     282         [ +  + ]:          2 :         if (slot_id != 0xff) {
+     283                 :          1 :             return libspdm_generate_error_response(spdm_context,
+     284                 :            :                                                    SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     285                 :            :                                                    response_size, response);
+     286                 :            :         }
+     287         [ -  + ]:          1 :         if (spdm_context->local_context.local_public_key_provision == NULL) {
+     288                 :          0 :             return libspdm_generate_error_response(spdm_context,
+     289                 :            :                                                    SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     290                 :            :                                                    response_size, response);
+     291                 :            :         }
+     292                 :            :     }
+     293                 :            : 
+     294         [ +  + ]:         13 :     if ((spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) &&
+     295   [ +  -  +  - ]:          1 :         spdm_context->connection_info.multi_key_conn_rsp &&
+     296                 :            :         (slot_id != 0xff)) {
+     297         [ +  - ]:          1 :         if ((spdm_context->local_context.local_key_usage_bit_mask[slot_id] &
+     298                 :            :              SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE) == 0) {
+     299                 :          1 :             return libspdm_generate_error_response(
+     300                 :            :                 spdm_context, SPDM_ERROR_CODE_INVALID_REQUEST,
+     301                 :            :                 0, response_size, response);
+     302                 :            :         }
+     303                 :            :     }
+     304                 :            : 
+     305                 :         12 :     spdm_context->connection_info.local_used_cert_chain_slot_id = slot_id;
+     306                 :            : 
+     307                 :         12 :     signature_size = libspdm_get_asym_signature_size(
+     308                 :            :         spdm_context->connection_info.algorithm.base_asym_algo);
+     309                 :         12 :     hmac_size = libspdm_get_hash_size(
+     310                 :            :         spdm_context->connection_info.algorithm.base_hash_algo);
+     311                 :         24 :     dhe_key_size = libspdm_get_dhe_pub_key_size(
+     312                 :         12 :         spdm_context->connection_info.algorithm.dhe_named_group);
+     313                 :         12 :     measurement_summary_hash_size = libspdm_get_measurement_summary_hash_size(
+     314                 :         12 :         spdm_context, false, spdm_request->header.param1);
+     315                 :            : 
+     316         [ +  + ]:         12 :     if ((measurement_summary_hash_size == 0) &&
+     317         [ +  + ]:         10 :         (spdm_request->header.param1 != SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH)) {
+     318                 :          1 :         return libspdm_generate_error_response(spdm_context,
+     319                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST,
+     320                 :            :                                                0, response_size, response);
+     321                 :            :     }
+     322         [ +  + ]:         11 :     if (request_size < sizeof(spdm_key_exchange_request_t) + dhe_key_size +
+     323                 :            :         sizeof(uint16_t)) {
+     324                 :          1 :         return libspdm_generate_error_response(spdm_context,
+     325                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     326                 :            :                                                response_size, response);
+     327                 :            :     }
+     328                 :         10 :     opaque_data_length = libspdm_read_uint16((const uint8_t *)request +
+     329                 :         10 :                                              sizeof(spdm_key_exchange_request_t) + dhe_key_size);
+     330                 :         10 :     if (request_size < sizeof(spdm_key_exchange_request_t) + dhe_key_size +
+     331         [ -  + ]:         10 :         sizeof(uint16_t) + opaque_data_length) {
+     332                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     333                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     334                 :            :                                                response_size, response);
+     335                 :            :     }
+     336                 :         10 :     request_size = sizeof(spdm_key_exchange_request_t) + dhe_key_size +
+     337                 :         10 :                    sizeof(uint16_t) + opaque_data_length;
+     338                 :            : 
+     339         [ +  - ]:         10 :     if (opaque_data_length != 0) {
+     340                 :         10 :         cptr = (const uint8_t *)request + sizeof(spdm_key_exchange_request_t) +
+     341                 :         10 :                dhe_key_size + sizeof(uint16_t);
+     342                 :         10 :         result = libspdm_process_general_opaque_data_check(spdm_context, opaque_data_length, cptr);
+     343         [ -  + ]:         10 :         if (!result) {
+     344                 :          0 :             return libspdm_generate_error_response(spdm_context,
+     345                 :            :                                                    SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     346                 :            :                                                    response_size, response);
+     347                 :            :         }
+     348                 :         10 :         status = libspdm_process_opaque_data_supported_version_data(
+     349                 :            :             spdm_context, opaque_data_length, cptr);
+     350         [ -  + ]:         10 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     351                 :          0 :             return libspdm_generate_error_response(spdm_context,
+     352                 :            :                                                    SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     353                 :            :                                                    response_size, response);
+     354                 :            :         }
+     355                 :            :     }
+     356                 :            : 
+     357                 :         10 :     opaque_key_exchange_rsp_size =
+     358                 :         10 :         libspdm_get_opaque_data_version_selection_data_size(spdm_context);
+     359                 :            : 
+     360                 :         10 :     libspdm_reset_message_buffer_via_request_code(spdm_context, NULL,
+     361                 :         10 :                                                   spdm_request->header.request_response_code);
+     362                 :            : 
+     363         [ +  + ]:         10 :     if (libspdm_is_capabilities_flag_supported(
+     364                 :            :             spdm_context, false,
+     365                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP,
+     366                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)) {
+     367                 :          3 :         hmac_size = 0;
+     368                 :            :     }
+     369                 :            : 
+     370                 :         10 :     total_size = sizeof(spdm_key_exchange_response_t) + dhe_key_size +
+     371                 :         10 :                  measurement_summary_hash_size + sizeof(uint16_t) +
+     372                 :         10 :                  opaque_key_exchange_rsp_size + signature_size + hmac_size;
+     373                 :            : 
+     374         [ -  + ]:         10 :     LIBSPDM_ASSERT(*response_size >= total_size);
+     375                 :         10 :     *response_size = total_size;
+     376                 :         10 :     libspdm_zero_mem(response, *response_size);
+     377                 :         10 :     spdm_response = response;
+     378                 :            : 
+     379                 :         10 :     spdm_response->header.spdm_version = spdm_request->header.spdm_version;
+     380                 :         10 :     spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
+     381                 :            : 
+     382         [ -  + ]:         10 :     if (libspdm_is_capabilities_flag_supported(
+     383                 :            :             spdm_context, false,
+     384                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP,
+     385                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP)) {
+     386                 :          0 :         spdm_response->header.param1 = spdm_context->local_context.heartbeat_period;
+     387                 :            :     } else {
+     388                 :         10 :         spdm_response->header.param1 = 0x00;
+     389                 :            :     }
+     390                 :            : 
+     391                 :         10 :     req_session_id = spdm_request->req_session_id;
+     392                 :         10 :     rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
+     393         [ -  + ]:         10 :     if (rsp_session_id == ((INVALID_SESSION_ID & 0xFFFF0000) >> 16)) {
+     394                 :          0 :         return libspdm_generate_error_response(
+     395                 :            :             spdm_context, SPDM_ERROR_CODE_SESSION_LIMIT_EXCEEDED, 0,
+     396                 :            :             response_size, response);
+     397                 :            :     }
+     398                 :         10 :     session_id = libspdm_generate_session_id(req_session_id, rsp_session_id);
+     399                 :         10 :     session_info = libspdm_assign_session_id(spdm_context, session_id, false);
+     400         [ -  + ]:         10 :     if (session_info == NULL) {
+     401                 :          0 :         return libspdm_generate_error_response(
+     402                 :            :             spdm_context, SPDM_ERROR_CODE_SESSION_LIMIT_EXCEEDED, 0,
+     403                 :            :             response_size, response);
+     404                 :            :     }
+     405                 :            : 
+     406         [ -  + ]:         10 :     if (libspdm_is_capabilities_flag_supported(
+     407                 :            :             spdm_context, false,
+     408                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP,
+     409                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP)) {
+     410                 :          0 :         session_info->heartbeat_period = spdm_context->local_context.heartbeat_period;
+     411                 :            :     } else {
+     412                 :         10 :         session_info->heartbeat_period = 0x00;
+     413                 :            :     }
+     414                 :            : 
+     415                 :         10 :     spdm_response->rsp_session_id = rsp_session_id;
+     416                 :            : 
+     417                 :         10 :     spdm_response->mut_auth_requested = 0;
+     418         [ -  + ]:         10 :     if (libspdm_is_capabilities_flag_supported(
+     419                 :            :             spdm_context, false,
+     420                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP,
+     421                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP)) {
+     422                 :          0 :         spdm_response->mut_auth_requested =
+     423                 :          0 :             spdm_context->local_context.mut_auth_requested;
+     424                 :            :     }
+     425         [ -  + ]:         10 :     if (spdm_response->mut_auth_requested != 0) {
+     426                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP
+     427                 :          0 :         spdm_context->connection_info.peer_used_cert_chain_slot_id =
+     428                 :          0 :             spdm_context->encap_context.req_slot_id;
+     429                 :          0 :         libspdm_init_mut_auth_encap_state(
+     430                 :          0 :             spdm_context, spdm_response->mut_auth_requested);
+     431         [ #  # ]:          0 :         if (spdm_response->mut_auth_requested == SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED) {
+     432                 :            :             /* no need to libspdm_init_mut_auth_encap_state() because of no ENCAP message */
+     433                 :          0 :             spdm_response->req_slot_id_param =
+     434                 :          0 :                 (spdm_context->encap_context.req_slot_id & 0xF);
+     435                 :            :         } else {
+     436                 :            :             /* req_slot_id is always 0 if ENCAP message is needed */
+     437                 :          0 :             spdm_response->req_slot_id_param = 0;
+     438                 :            :         }
+     439                 :            : #else
+     440                 :            :         spdm_response->mut_auth_requested = 0;
+     441                 :            :         spdm_response->req_slot_id_param = 0;
+     442                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP */
+     443                 :            :     } else {
+     444                 :         10 :         spdm_response->req_slot_id_param = 0;
+     445                 :            :     }
+     446                 :            : 
+     447         [ -  + ]:         10 :     if(!libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_response->random_data)) {
+     448                 :          0 :         libspdm_free_session_id(spdm_context, session_id);
+     449                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     450                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     451                 :            :                                                response_size, response);
+     452                 :            :     }
+     453                 :            : 
+     454                 :         10 :     ptr = (void *)(spdm_response + 1);
+     455                 :         10 :     dhe_context = libspdm_secured_message_dhe_new(
+     456                 :         10 :         spdm_context->connection_info.version,
+     457                 :         10 :         spdm_context->connection_info.algorithm.dhe_named_group, false);
+     458         [ -  + ]:         10 :     if (dhe_context == NULL) {
+     459                 :          0 :         libspdm_free_session_id(spdm_context, session_id);
+     460                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     461                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     462                 :            :                                                response_size, response);
+     463                 :            :     }
+     464                 :            : 
+     465                 :         10 :     result = libspdm_secured_message_dhe_generate_key(
+     466                 :         10 :         spdm_context->connection_info.algorithm.dhe_named_group,
+     467                 :            :         dhe_context, ptr, &dhe_key_size);
+     468         [ -  + ]:         10 :     if (!result) {
+     469                 :          0 :         libspdm_secured_message_dhe_free(
+     470                 :          0 :             spdm_context->connection_info.algorithm.dhe_named_group,
+     471                 :            :             dhe_context);
+     472                 :          0 :         libspdm_free_session_id(spdm_context, session_id);
+     473                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     474                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     475                 :            :                                                response_size, response);
+     476                 :            :     }
+     477                 :         10 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "Calc SelfKey (0x%zx):\n", dhe_key_size));
+     478                 :         10 :     LIBSPDM_INTERNAL_DUMP_HEX(ptr, dhe_key_size);
+     479                 :            : 
+     480                 :         10 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "Calc peer_key (0x%zx):\n", dhe_key_size));
+     481                 :         10 :     LIBSPDM_INTERNAL_DUMP_HEX((const uint8_t *)request +
+     482                 :            :                               sizeof(spdm_key_exchange_request_t),
+     483                 :            :                               dhe_key_size);
+     484                 :            : 
+     485                 :         10 :     result = libspdm_secured_message_dhe_compute_key(
+     486                 :         10 :         spdm_context->connection_info.algorithm.dhe_named_group,
+     487                 :            :         dhe_context,
+     488                 :            :         (const uint8_t *)request + sizeof(spdm_key_exchange_request_t),
+     489                 :            :         dhe_key_size, session_info->secured_message_context);
+     490                 :         10 :     libspdm_secured_message_dhe_free(
+     491                 :         10 :         spdm_context->connection_info.algorithm.dhe_named_group,
+     492                 :            :         dhe_context);
+     493         [ -  + ]:         10 :     if (!result) {
+     494                 :          0 :         libspdm_free_session_id(spdm_context, session_id);
+     495                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     496                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     497                 :            :                                                response_size, response);
+     498                 :            :     }
+     499                 :            : 
+     500                 :         10 :     ptr += dhe_key_size;
+     501                 :            : 
+     502                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
+     503         [ +  + ]:         10 :     if (libspdm_is_capabilities_flag_supported(
+     504                 :            :             spdm_context, false, 0, SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP)) {
+     505                 :            : 
+     506                 :          2 :         result = libspdm_generate_measurement_summary_hash(
+     507                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+     508                 :            :             spdm_context,
+     509                 :            : #endif
+     510                 :          2 :             spdm_context->connection_info.version,
+     511                 :            :             spdm_context->connection_info.algorithm.base_hash_algo,
+     512                 :          2 :             spdm_context->connection_info.algorithm.measurement_spec,
+     513                 :            :             spdm_context->connection_info.algorithm.measurement_hash_algo,
+     514                 :          2 :             spdm_request->header.param1,
+     515                 :            :             ptr,
+     516                 :            :             measurement_summary_hash_size);
+     517                 :            :     } else {
+     518                 :          8 :         result = true;
+     519                 :            :     }
+     520                 :            : 
+     521         [ -  + ]:         10 :     if (!result) {
+     522                 :          0 :         libspdm_free_session_id(spdm_context, session_id);
+     523                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     524                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     525                 :            :                                                response_size, response);
+     526                 :            :     }
+     527                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP */
+     528                 :            : 
+     529                 :         10 :     ptr += measurement_summary_hash_size;
+     530                 :            : 
+     531                 :         10 :     libspdm_write_uint16(ptr, (uint16_t)opaque_key_exchange_rsp_size);
+     532                 :         10 :     ptr += sizeof(uint16_t);
+     533                 :         10 :     libspdm_build_opaque_data_version_selection_data(
+     534                 :            :         spdm_context, &opaque_key_exchange_rsp_size, ptr);
+     535                 :         10 :     ptr += opaque_key_exchange_rsp_size;
+     536                 :            : 
+     537         [ +  + ]:         10 :     if (slot_id != 0xFF) {
+     538                 :          9 :         spdm_context->connection_info.local_used_cert_chain_buffer =
+     539                 :          9 :             spdm_context->local_context.local_cert_chain_provision[slot_id];
+     540                 :          9 :         spdm_context->connection_info.local_used_cert_chain_buffer_size =
+     541                 :            :             spdm_context->local_context
+     542                 :          9 :             .local_cert_chain_provision_size[slot_id];
+     543                 :            :     }
+     544                 :            : 
+     545                 :         10 :     status = libspdm_append_message_k(spdm_context, session_info, false, request, request_size);
+     546         [ -  + ]:         10 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     547                 :          0 :         libspdm_free_session_id(spdm_context, session_id);
+     548                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     549                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     550                 :            :                                                response_size, response);
+     551                 :            :     }
+     552                 :            : 
+     553                 :         10 :     status = libspdm_append_message_k(spdm_context, session_info, false, spdm_response,
+     554                 :         10 :                                       (size_t)ptr - (size_t)spdm_response);
+     555         [ -  + ]:         10 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     556                 :          0 :         libspdm_free_session_id(spdm_context, session_id);
+     557                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     558                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     559                 :            :                                                response_size, response);
+     560                 :            :     }
+     561                 :         10 :     result = libspdm_generate_key_exchange_rsp_signature(spdm_context,
+     562                 :            :                                                          session_info, ptr);
+     563         [ -  + ]:         10 :     if (!result) {
+     564                 :          0 :         libspdm_free_session_id(spdm_context, session_id);
+     565                 :          0 :         return libspdm_generate_error_response(
+     566                 :            :             spdm_context, SPDM_ERROR_CODE_UNSPECIFIED,
+     567                 :            :             0, response_size, response);
+     568                 :            :     }
+     569                 :            : 
+     570                 :         10 :     status = libspdm_append_message_k(spdm_context, session_info, false, ptr, signature_size);
+     571         [ -  + ]:         10 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     572                 :          0 :         libspdm_free_session_id(spdm_context, session_id);
+     573                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     574                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     575                 :            :                                                response_size, response);
+     576                 :            :     }
+     577                 :            : 
+     578                 :         10 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "libspdm_generate_session_handshake_key[%x]\n",
+     579                 :            :                    session_id));
+     580                 :         10 :     result = libspdm_calculate_th1_hash(spdm_context, session_info, false,
+     581                 :            :                                         th1_hash_data);
+     582         [ -  + ]:         10 :     if (!result) {
+     583                 :          0 :         libspdm_free_session_id(spdm_context, session_id);
+     584                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     585                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     586                 :            :                                                response_size, response);
+     587                 :            :     }
+     588                 :         10 :     result = libspdm_generate_session_handshake_key(
+     589                 :            :         session_info->secured_message_context, th1_hash_data);
+     590         [ -  + ]:         10 :     if (!result) {
+     591                 :          0 :         libspdm_free_session_id(spdm_context, session_id);
+     592                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     593                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     594                 :            :                                                response_size, response);
+     595                 :            :     }
+     596                 :            : 
+     597                 :         10 :     ptr += signature_size;
+     598                 :            : 
+     599         [ +  + ]:         10 :     if (!libspdm_is_capabilities_flag_supported(
+     600                 :            :             spdm_context, false,
+     601                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP,
+     602                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)) {
+     603                 :          7 :         result = libspdm_generate_key_exchange_rsp_hmac(spdm_context,
+     604                 :            :                                                         session_info, ptr);
+     605         [ -  + ]:          7 :         if (!result) {
+     606                 :          0 :             libspdm_free_session_id(spdm_context, session_id);
+     607                 :          0 :             return libspdm_generate_error_response(
+     608                 :            :                 spdm_context,
+     609                 :            :                 SPDM_ERROR_CODE_UNSPECIFIED,
+     610                 :            :                 0, response_size, response);
+     611                 :            :         }
+     612                 :          7 :         status = libspdm_append_message_k(spdm_context, session_info, false, ptr, hmac_size);
+     613         [ -  + ]:          7 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     614                 :          0 :             libspdm_free_session_id(spdm_context, session_id);
+     615                 :          0 :             return libspdm_generate_error_response(
+     616                 :            :                 spdm_context, SPDM_ERROR_CODE_UNSPECIFIED,
+     617                 :            :                 0, response_size, response);
+     618                 :            :         }
+     619                 :            : 
+     620                 :          7 :         ptr += hmac_size;
+     621                 :            :     }
+     622                 :            : 
+     623                 :         10 :     session_info->mut_auth_requested = spdm_response->mut_auth_requested;
+     624         [ +  + ]:         10 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_12) {
+     625                 :          2 :         session_info->session_policy = spdm_request->session_policy;
+     626                 :            :     }
+     627                 :         10 :     libspdm_set_session_state(spdm_context, session_id, LIBSPDM_SESSION_STATE_HANDSHAKING);
+     628                 :            : 
+     629                 :         10 :     return LIBSPDM_STATUS_SUCCESS;
+     630                 :            : }
+     631                 :            : 
+     632                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_key_update.c.func-sort-c.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_key_update.c.func-sort-c.html new file mode 100644 index 00000000000..25718ec57c4 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_key_update.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_key_update.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_key_update.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:758489.3 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:334475.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_response_key_update27
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_key_update.c.func.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_key_update.c.func.html new file mode 100644 index 00000000000..8dc3c17048a --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_key_update.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_key_update.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_key_update.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:758489.3 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:334475.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_response_key_update27
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_key_update.c.gcov.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_key_update.c.gcov.html new file mode 100644 index 00000000000..119c766d925 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_key_update.c.gcov.html @@ -0,0 +1,328 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_key_update.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_key_update.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:758489.3 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:334475.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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_responder_lib.h"
+       8                 :            : #include "internal/libspdm_secured_message_lib.h"
+       9                 :            : 
+      10                 :            : /**
+      11                 :            :  * Process the SPDM KEY_UPDATE request and return the response.
+      12                 :            :  *
+      13                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+      14                 :            :  * @param  request_size                  size in bytes of the request data.
+      15                 :            :  * @param  request                      A pointer to the request data.
+      16                 :            :  * @param  response_size                 size in bytes of the response data.
+      17                 :            :  *                                     On input, it means the size in bytes of response data buffer.
+      18                 :            :  *                                     On output, it means the size in bytes of copied response data buffer if RETURN_SUCCESS is returned,
+      19                 :            :  *                                     and means the size in bytes of desired response data buffer if RETURN_BUFFER_TOO_SMALL is returned.
+      20                 :            :  * @param  response                     A pointer to the response data.
+      21                 :            :  *
+      22                 :            :  * @retval RETURN_SUCCESS               The request is processed and the response is returned.
+      23                 :            :  * @retval RETURN_BUFFER_TOO_SMALL      The buffer is too small to hold the data.
+      24                 :            :  * @retval RETURN_DEVICE_ERROR          A device error occurs when communicates with the device.
+      25                 :            :  * @retval RETURN_SECURITY_VIOLATION    Any verification fails.
+      26                 :            :  **/
+      27                 :         27 : libspdm_return_t libspdm_get_response_key_update(libspdm_context_t *spdm_context,
+      28                 :            :                                                  size_t request_size,
+      29                 :            :                                                  const void *request,
+      30                 :            :                                                  size_t *response_size,
+      31                 :            :                                                  void *response)
+      32                 :            : {
+      33                 :            :     uint32_t session_id;
+      34                 :            :     spdm_key_update_response_t *spdm_response;
+      35                 :            :     const spdm_key_update_request_t *spdm_request;
+      36                 :            :     spdm_key_update_request_t *prev_spdm_request;
+      37                 :            :     libspdm_session_info_t *session_info;
+      38                 :            :     libspdm_session_state_t session_state;
+      39                 :            :     spdm_key_update_request_t spdm_key_init_update_operation;
+      40                 :            :     bool result;
+      41                 :            : 
+      42                 :         27 :     spdm_request = request;
+      43                 :            : 
+      44                 :            :     /* -=[Check Parameters Phase]=- */
+      45         [ -  + ]:         27 :     LIBSPDM_ASSERT(spdm_request->header.request_response_code == SPDM_KEY_UPDATE);
+      46                 :            : 
+      47         [ -  + ]:         27 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_11) {
+      48                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      49                 :            :                                                SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+      50                 :            :                                                SPDM_KEY_UPDATE,
+      51                 :            :                                                response_size, response);
+      52                 :            :     }
+      53                 :            : 
+      54         [ -  + ]:         27 :     if (spdm_request->header.spdm_version != libspdm_get_connection_version(spdm_context)) {
+      55                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      56                 :            :                                                SPDM_ERROR_CODE_VERSION_MISMATCH, 0,
+      57                 :            :                                                response_size, response);
+      58                 :            :     }
+      59         [ +  + ]:         27 :     if (spdm_context->response_state != LIBSPDM_RESPONSE_STATE_NORMAL) {
+      60                 :          3 :         return libspdm_responder_handle_response_state(
+      61                 :            :             spdm_context,
+      62                 :          3 :             spdm_request->header.request_response_code,
+      63                 :            :             response_size, response);
+      64                 :            :     }
+      65                 :            : 
+      66         [ +  + ]:         24 :     if (!libspdm_is_capabilities_flag_supported(
+      67                 :            :             spdm_context, false,
+      68                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP,
+      69                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_UPD_CAP)) {
+      70                 :          1 :         return libspdm_generate_error_response(
+      71                 :            :             spdm_context, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+      72                 :            :             SPDM_KEY_UPDATE, response_size, response);
+      73                 :            :     }
+      74         [ +  + ]:         23 :     if (spdm_context->connection_info.connection_state <
+      75                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
+      76                 :          1 :         return libspdm_generate_error_response(spdm_context,
+      77                 :            :                                                SPDM_ERROR_CODE_UNEXPECTED_REQUEST,
+      78                 :            :                                                0, response_size, response);
+      79                 :            :     }
+      80                 :            : 
+      81         [ -  + ]:         22 :     if (!spdm_context->last_spdm_request_session_id_valid) {
+      82                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      83                 :            :                                                SPDM_ERROR_CODE_SESSION_REQUIRED, 0,
+      84                 :            :                                                response_size, response);
+      85                 :            :     }
+      86                 :         22 :     session_id = spdm_context->last_spdm_request_session_id;
+      87                 :            :     session_info =
+      88                 :         22 :         libspdm_get_session_info_via_session_id(spdm_context, session_id);
+      89         [ -  + ]:         22 :     if (session_info == NULL) {
+      90                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      91                 :            :                                                SPDM_ERROR_CODE_SESSION_REQUIRED, 0,
+      92                 :            :                                                response_size, response);
+      93                 :            :     }
+      94                 :         22 :     session_state = libspdm_secured_message_get_session_state(
+      95                 :            :         session_info->secured_message_context);
+      96         [ +  + ]:         22 :     if (session_state != LIBSPDM_SESSION_STATE_ESTABLISHED) {
+      97                 :          1 :         return libspdm_generate_error_response(spdm_context,
+      98                 :            :                                                SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+      99                 :            :                                                response_size, response);
+     100                 :            :     }
+     101                 :            : 
+     102                 :            :     /* this message can only be in secured session
+     103                 :            :      * thus don't need to consider transport layer padding, just check its exact size */
+     104         [ +  + ]:         21 :     if (request_size != sizeof(spdm_key_update_request_t)) {
+     105                 :          4 :         return libspdm_generate_error_response(spdm_context,
+     106                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     107                 :            :                                                response_size, response);
+     108                 :            :     }
+     109                 :            : 
+     110                 :            :     /*last key operation*/
+     111                 :         17 :     prev_spdm_request = &(session_info->last_key_update_request);
+     112                 :            : 
+     113                 :            :     /*the end status of the successful key update overall flow*/
+     114                 :         17 :     libspdm_zero_mem(&spdm_key_init_update_operation, sizeof(spdm_key_update_request_t));
+     115                 :            : 
+     116   [ +  +  +  + ]:         17 :     switch (spdm_request->header.param1) {
+     117                 :          6 :     case SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY:
+     118         [ +  + ]:          6 :         if(!libspdm_consttime_is_mem_equal(prev_spdm_request,
+     119                 :            :                                            &spdm_key_init_update_operation,
+     120                 :            :                                            sizeof(spdm_key_update_request_t))) {
+     121                 :          2 :             return libspdm_generate_error_response(spdm_context,
+     122                 :            :                                                    SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     123                 :            :                                                    response_size, response);
+     124                 :            :         }
+     125                 :            : 
+     126                 :          4 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+     127                 :            :                        "libspdm_create_update_session_data_key[%x] Requester\n",
+     128                 :            :                        session_id));
+     129                 :          4 :         result = libspdm_create_update_session_data_key(
+     130                 :            :             session_info->secured_message_context,
+     131                 :            :             LIBSPDM_KEY_UPDATE_ACTION_REQUESTER);
+     132         [ -  + ]:          4 :         if (!result) {
+     133                 :          0 :             return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     134                 :            :         }
+     135                 :          4 :         libspdm_trigger_key_update_callback(
+     136                 :            :             spdm_context, session_id, LIBSPDM_KEY_UPDATE_OPERATION_CREATE_UPDATE,
+     137                 :            :             LIBSPDM_KEY_UPDATE_ACTION_REQUESTER);
+     138                 :            : 
+     139                 :            :         /*save the last update operation*/
+     140                 :          4 :         libspdm_copy_mem(prev_spdm_request, sizeof(spdm_key_update_request_t),
+     141                 :            :                          spdm_request, request_size);
+     142                 :          4 :         break;
+     143                 :          5 :     case SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_ALL_KEYS:
+     144         [ +  + ]:          5 :         if(!libspdm_consttime_is_mem_equal(prev_spdm_request,
+     145                 :            :                                            &spdm_key_init_update_operation,
+     146                 :            :                                            sizeof(spdm_key_update_request_t))) {
+     147                 :          2 :             return libspdm_generate_error_response(spdm_context,
+     148                 :            :                                                    SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     149                 :            :                                                    response_size, response);
+     150                 :            :         }
+     151                 :            : 
+     152                 :          3 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+     153                 :            :                        "libspdm_create_update_session_data_key[%x] Requester\n",
+     154                 :            :                        session_id));
+     155                 :          3 :         result = libspdm_create_update_session_data_key(
+     156                 :            :             session_info->secured_message_context,
+     157                 :            :             LIBSPDM_KEY_UPDATE_ACTION_REQUESTER);
+     158         [ -  + ]:          3 :         if (!result) {
+     159                 :          0 :             return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     160                 :            :         }
+     161                 :          3 :         libspdm_trigger_key_update_callback(
+     162                 :            :             spdm_context, session_id, LIBSPDM_KEY_UPDATE_OPERATION_CREATE_UPDATE,
+     163                 :            :             LIBSPDM_KEY_UPDATE_ACTION_REQUESTER);
+     164                 :            : 
+     165                 :          3 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+     166                 :            :                        "libspdm_create_update_session_data_key[%x] Responder\n",
+     167                 :            :                        session_id));
+     168                 :          3 :         result = libspdm_create_update_session_data_key(
+     169                 :            :             session_info->secured_message_context,
+     170                 :            :             LIBSPDM_KEY_UPDATE_ACTION_RESPONDER);
+     171         [ -  + ]:          3 :         if (!result) {
+     172                 :          0 :             return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     173                 :            :         }
+     174                 :          3 :         libspdm_trigger_key_update_callback(
+     175                 :            :             spdm_context, session_id, LIBSPDM_KEY_UPDATE_OPERATION_CREATE_UPDATE,
+     176                 :            :             LIBSPDM_KEY_UPDATE_ACTION_RESPONDER);
+     177                 :            : 
+     178                 :            :         /* We can commit to Responder key. */
+     179                 :          3 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+     180                 :            :                        "libspdm_activate_update_session_data_key[%x] Responder new\n",
+     181                 :            :                        session_id));
+     182                 :          3 :         result = libspdm_activate_update_session_data_key(
+     183                 :            :             session_info->secured_message_context,
+     184                 :            :             LIBSPDM_KEY_UPDATE_ACTION_RESPONDER, true);
+     185         [ -  + ]:          3 :         if (!result) {
+     186                 :          0 :             return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     187                 :            :         }
+     188                 :          3 :         libspdm_trigger_key_update_callback(
+     189                 :            :             spdm_context, session_id, LIBSPDM_KEY_UPDATE_OPERATION_COMMIT_UPDATE,
+     190                 :            :             LIBSPDM_KEY_UPDATE_ACTION_RESPONDER);
+     191                 :            : 
+     192                 :            :         /*save the last update operation*/
+     193                 :          3 :         libspdm_copy_mem(prev_spdm_request, sizeof(spdm_key_update_request_t),
+     194                 :            :                          spdm_request, request_size);
+     195                 :          3 :         break;
+     196                 :          5 :     case SPDM_KEY_UPDATE_OPERATIONS_TABLE_VERIFY_NEW_KEY:
+     197         [ +  + ]:          5 :         if(prev_spdm_request->header.param1 !=
+     198                 :          4 :            SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY &&
+     199         [ +  + ]:          4 :            prev_spdm_request->header.param1 !=
+     200                 :            :            SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_ALL_KEYS) {
+     201                 :          3 :             return libspdm_generate_error_response(spdm_context,
+     202                 :            :                                                    SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     203                 :            :                                                    response_size, response);
+     204                 :            :         }
+     205                 :            :         /* With Requester key verified, we can discard backups. */
+     206                 :          2 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+     207                 :            :                        "libspdm_activate_update_session_data_key[%x] Requester new\n",
+     208                 :            :                        session_id));
+     209                 :          2 :         result = libspdm_activate_update_session_data_key(
+     210                 :            :             session_info->secured_message_context,
+     211                 :            :             LIBSPDM_KEY_UPDATE_ACTION_REQUESTER, true);
+     212         [ -  + ]:          2 :         if (!result) {
+     213                 :          0 :             return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     214                 :            :         }
+     215                 :          2 :         libspdm_trigger_key_update_callback(
+     216                 :            :             spdm_context, session_id, LIBSPDM_KEY_UPDATE_OPERATION_COMMIT_UPDATE,
+     217                 :            :             LIBSPDM_KEY_UPDATE_ACTION_REQUESTER);
+     218                 :            : 
+     219                 :            :         /*clear last_key_update_request*/
+     220                 :          2 :         libspdm_zero_mem (prev_spdm_request, sizeof(spdm_key_update_request_t));
+     221                 :          2 :         break;
+     222                 :          1 :     default:
+     223                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "espurious case\n"));
+     224                 :          1 :         return libspdm_generate_error_response(spdm_context,
+     225                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     226                 :            :                                                response_size, response);
+     227                 :            :     }
+     228                 :            : 
+     229                 :          9 :     libspdm_reset_message_buffer_via_request_code(spdm_context, session_info,
+     230                 :          9 :                                                   spdm_request->header.request_response_code);
+     231                 :            : 
+     232         [ -  + ]:          9 :     LIBSPDM_ASSERT(*response_size >= sizeof(spdm_key_update_response_t));
+     233                 :          9 :     *response_size = sizeof(spdm_key_update_response_t);
+     234                 :          9 :     libspdm_zero_mem(response, *response_size);
+     235                 :          9 :     spdm_response = response;
+     236                 :            : 
+     237                 :          9 :     spdm_response->header.spdm_version = spdm_request->header.spdm_version;
+     238                 :          9 :     spdm_response->header.request_response_code = SPDM_KEY_UPDATE_ACK;
+     239                 :          9 :     spdm_response->header.param1 = spdm_request->header.param1;
+     240                 :          9 :     spdm_response->header.param2 = spdm_request->header.param2;
+     241                 :            : 
+     242                 :          9 :     return LIBSPDM_STATUS_SUCCESS;
+     243                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_measurement_extension_log.c.func-sort-c.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_measurement_extension_log.c.func-sort-c.html new file mode 100644 index 00000000000..8a353fe5c5e --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_measurement_extension_log.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_measurement_extension_log.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_measurement_extension_log.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:445974.6 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:193652.8 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_response_measurement_extension_log5
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_measurement_extension_log.c.func.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_measurement_extension_log.c.func.html new file mode 100644 index 00000000000..592c8a7c1e7 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_measurement_extension_log.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_measurement_extension_log.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_measurement_extension_log.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:445974.6 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:193652.8 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_response_measurement_extension_log5
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_measurement_extension_log.c.gcov.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_measurement_extension_log.c.gcov.html new file mode 100644 index 00000000000..c10e5983bef --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_measurement_extension_log.c.gcov.html @@ -0,0 +1,243 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_measurement_extension_log.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_measurement_extension_log.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:445974.6 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:193652.8 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2024 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                 :            : #include "internal/libspdm_responder_lib.h"
+       7                 :            : 
+       8                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MEL_CAP
+       9                 :            : 
+      10                 :          5 : libspdm_return_t libspdm_get_response_measurement_extension_log(libspdm_context_t *spdm_context,
+      11                 :            :                                                                 size_t request_size,
+      12                 :            :                                                                 const void *request,
+      13                 :            :                                                                 size_t *response_size,
+      14                 :            :                                                                 void *response)
+      15                 :            : {
+      16                 :            :     const spdm_get_measurement_extension_log_request_t *spdm_request;
+      17                 :            :     spdm_measurement_extension_log_response_t *spdm_response;
+      18                 :            :     uint32_t offset;
+      19                 :            :     uint32_t length;
+      20                 :            :     size_t remainder_length;
+      21                 :            :     size_t response_capacity;
+      22                 :            :     libspdm_session_info_t *session_info;
+      23                 :            :     libspdm_session_state_t session_state;
+      24                 :            :     spdm_measurement_extension_log_dmtf_t *spdm_mel;
+      25                 :            :     size_t spdm_mel_len;
+      26                 :            : 
+      27                 :          5 :     spdm_request = request;
+      28                 :            : 
+      29                 :            :     /* -=[Check Parameters Phase]=- */
+      30         [ -  + ]:          5 :     LIBSPDM_ASSERT(spdm_request->header.request_response_code ==
+      31                 :            :                    SPDM_GET_MEASUREMENT_EXTENSION_LOG);
+      32                 :            : 
+      33         [ -  + ]:          5 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_13) {
+      34                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      35                 :            :                                                SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+      36                 :            :                                                0,
+      37                 :            :                                                response_size, response);
+      38                 :            :     }
+      39                 :            : 
+      40         [ -  + ]:          5 :     if (spdm_request->header.spdm_version != libspdm_get_connection_version(spdm_context)) {
+      41                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      42                 :            :                                                SPDM_ERROR_CODE_VERSION_MISMATCH, 0,
+      43                 :            :                                                response_size, response);
+      44                 :            :     }
+      45         [ -  + ]:          5 :     if (spdm_context->response_state != LIBSPDM_RESPONSE_STATE_NORMAL) {
+      46                 :          0 :         return libspdm_responder_handle_response_state(
+      47                 :            :             spdm_context,
+      48                 :          0 :             spdm_request->header.request_response_code,
+      49                 :            :             response_size, response);
+      50                 :            :     }
+      51         [ -  + ]:          5 :     if (spdm_context->connection_info.connection_state < LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
+      52                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      53                 :            :                                                SPDM_ERROR_CODE_UNEXPECTED_REQUEST,
+      54                 :            :                                                0, response_size, response);
+      55                 :            :     }
+      56                 :            : 
+      57                 :          5 :     session_info = NULL;
+      58         [ -  + ]:          5 :     if (spdm_context->last_spdm_request_session_id_valid) {
+      59                 :          0 :         session_info = libspdm_get_session_info_via_session_id(
+      60                 :            :             spdm_context,
+      61                 :            :             spdm_context->last_spdm_request_session_id);
+      62         [ #  # ]:          0 :         if (session_info == NULL) {
+      63                 :          0 :             return libspdm_generate_error_response(
+      64                 :            :                 spdm_context,
+      65                 :            :                 SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+      66                 :            :                 response_size, response);
+      67                 :            :         }
+      68                 :          0 :         session_state = libspdm_secured_message_get_session_state(
+      69                 :            :             session_info->secured_message_context);
+      70         [ #  # ]:          0 :         if (session_state != LIBSPDM_SESSION_STATE_ESTABLISHED) {
+      71                 :          0 :             return libspdm_generate_error_response(
+      72                 :            :                 spdm_context,
+      73                 :            :                 SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+      74                 :            :                 response_size, response);
+      75                 :            :         }
+      76                 :            :     }
+      77         [ -  + ]:          5 :     if (!libspdm_is_capabilities_flag_supported(
+      78                 :            :             spdm_context, false, 0,
+      79                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEL_CAP)) {
+      80                 :          0 :         return libspdm_generate_error_response(
+      81                 :            :             spdm_context, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+      82                 :            :             0, response_size, response);
+      83                 :            :     }
+      84                 :            : 
+      85         [ +  - ]:          5 :     if ((spdm_context->connection_info.algorithm.mel_spec == 0) ||
+      86         [ -  + ]:          5 :         (spdm_context->connection_info.algorithm.measurement_hash_algo == 0) ) {
+      87                 :          0 :         return libspdm_generate_error_response(
+      88                 :            :             spdm_context, SPDM_ERROR_CODE_UNEXPECTED_REQUEST,
+      89                 :            :             0, response_size, response);
+      90                 :            :     }
+      91                 :            : 
+      92         [ -  + ]:          5 :     if (request_size < sizeof(spdm_get_measurement_extension_log_request_t)) {
+      93                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      94                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+      95                 :            :                                                response_size, response);
+      96                 :            :     }
+      97                 :            : 
+      98                 :          5 :     offset = spdm_request->offset;
+      99                 :          5 :     length = spdm_request->length;
+     100                 :            : 
+     101         [ +  - ]:          5 :     if (!libspdm_is_capabilities_flag_supported(spdm_context, false,
+     102                 :            :                                                 SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP,
+     103                 :            :                                                 SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP)) {
+     104         [ +  + ]:          5 :         if (length > LIBSPDM_MAX_MEL_BLOCK_LEN) {
+     105                 :          1 :             length = LIBSPDM_MAX_MEL_BLOCK_LEN;
+     106                 :            :         }
+     107                 :            :     }
+     108                 :            : 
+     109                 :          5 :     spdm_mel = NULL;
+     110                 :          5 :     spdm_mel_len = 0;
+     111         [ -  + ]:          5 :     if (!libspdm_measurement_extension_log_collection(
+     112                 :            :             spdm_context,
+     113                 :          5 :             spdm_context->connection_info.algorithm.mel_spec,
+     114                 :          5 :             spdm_context->connection_info.algorithm.measurement_spec,
+     115                 :            :             spdm_context->connection_info.algorithm.measurement_hash_algo,
+     116                 :            :             (void **)&spdm_mel, &spdm_mel_len)) {
+     117                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     118                 :            :                                                SPDM_ERROR_CODE_OPERATION_FAILED, 0,
+     119                 :            :                                                response_size, response);
+     120                 :            :     }
+     121                 :            : 
+     122         [ +  + ]:          5 :     if (offset >= spdm_mel_len) {
+     123                 :          1 :         return libspdm_generate_error_response(spdm_context,
+     124                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     125                 :            :                                                response_size, response);
+     126                 :            :     }
+     127                 :            : 
+     128         [ +  + ]:          4 :     if ((uint64_t)(offset + length) > spdm_mel_len) {
+     129                 :          3 :         length = (uint32_t)(spdm_mel_len - offset);
+     130                 :            :     }
+     131                 :          4 :     remainder_length = spdm_mel_len - (length + offset);
+     132                 :            : 
+     133                 :          4 :     libspdm_reset_message_buffer_via_request_code(spdm_context, session_info,
+     134                 :          4 :                                                   spdm_request->header.request_response_code);
+     135                 :            : 
+     136         [ -  + ]:          4 :     LIBSPDM_ASSERT(*response_size >= sizeof(spdm_measurement_extension_log_response_t) + length);
+     137                 :            : 
+     138                 :          4 :     response_capacity = *response_size;
+     139                 :          4 :     *response_size = sizeof(spdm_measurement_extension_log_response_t) + length;
+     140                 :          4 :     libspdm_zero_mem(response, *response_size);
+     141                 :          4 :     spdm_response = response;
+     142                 :            : 
+     143                 :          4 :     spdm_response->header.spdm_version = spdm_request->header.spdm_version;
+     144                 :          4 :     spdm_response->header.request_response_code = SPDM_MEASUREMENT_EXTENSION_LOG;
+     145                 :          4 :     spdm_response->header.param1 = 0;
+     146                 :          4 :     spdm_response->header.param2 = 0;
+     147                 :            : 
+     148                 :          4 :     spdm_response->portion_length = length;
+     149                 :          4 :     spdm_response->remainder_length = (uint32_t)remainder_length;
+     150                 :            : 
+     151                 :          4 :     libspdm_copy_mem(spdm_response + 1,
+     152                 :            :                      response_capacity - sizeof(spdm_measurement_extension_log_response_t),
+     153                 :          4 :                      (const uint8_t *)spdm_mel + offset, length);
+     154                 :            : 
+     155                 :          4 :     return LIBSPDM_STATUS_SUCCESS;
+     156                 :            : }
+     157                 :            : 
+     158                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEL_CAP */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_measurements.c.func-sort-c.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_measurements.c.func-sort-c.html new file mode 100644 index 00000000000..5f5b6c83db1 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_measurements.c.func-sort-c.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_measurements.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_measurements.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:16319185.3 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:9011975.6 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_generate_measurement_signature16
libspdm_get_response_measurements137
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_measurements.c.func.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_measurements.c.func.html new file mode 100644 index 00000000000..130697580a9 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_measurements.c.func.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_measurements.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_measurements.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:16319185.3 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:9011975.6 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_generate_measurement_signature16
libspdm_get_response_measurements137
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_measurements.c.gcov.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_measurements.c.gcov.html new file mode 100644 index 00000000000..81fff579a91 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_measurements.c.gcov.html @@ -0,0 +1,570 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_measurements.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_measurements.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:16319185.3 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:9011975.6 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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_responder_lib.h"
+       8                 :            : 
+       9                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
+      10                 :         16 : bool libspdm_generate_measurement_signature(libspdm_context_t *spdm_context,
+      11                 :            :                                             libspdm_session_info_t *session_info,
+      12                 :            :                                             uint8_t *signature)
+      13                 :            : {
+      14                 :            :     size_t signature_size;
+      15                 :            :     bool result;
+      16                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+      17                 :            :     libspdm_l1l2_managed_buffer_t l1l2;
+      18                 :            :     uint8_t *l1l2_buffer;
+      19                 :            :     size_t l1l2_buffer_size;
+      20                 :            : #else
+      21                 :            :     uint8_t l1l2_hash[LIBSPDM_MAX_HASH_SIZE];
+      22                 :            :     size_t l1l2_hash_size;
+      23                 :            : #endif
+      24                 :            : 
+      25                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+      26                 :            :     result = libspdm_calculate_l1l2(spdm_context, session_info, &l1l2);
+      27                 :            : #else
+      28                 :         16 :     l1l2_hash_size = sizeof(l1l2_hash);
+      29                 :         16 :     result = libspdm_calculate_l1l2_hash(spdm_context, session_info, &l1l2_hash_size, l1l2_hash);
+      30                 :            : #endif
+      31                 :         16 :     libspdm_reset_message_m(spdm_context, session_info);
+      32         [ -  + ]:         16 :     if (!result) {
+      33                 :          0 :         return false;
+      34                 :            :     }
+      35                 :            : 
+      36                 :         16 :     signature_size = libspdm_get_asym_signature_size(
+      37                 :            :         spdm_context->connection_info.algorithm.base_asym_algo);
+      38                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+      39                 :            :     l1l2_buffer = libspdm_get_managed_buffer(&l1l2);
+      40                 :            :     l1l2_buffer_size = libspdm_get_managed_buffer_size(&l1l2);
+      41                 :            : 
+      42                 :            :     result = libspdm_responder_data_sign(
+      43                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+      44                 :            :         spdm_context,
+      45                 :            : #endif
+      46                 :            :         spdm_context->connection_info.version, SPDM_MEASUREMENTS,
+      47                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+      48                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+      49                 :            :         false, l1l2_buffer, l1l2_buffer_size, signature, &signature_size);
+      50                 :            : #else
+      51                 :         16 :     result = libspdm_responder_data_sign(
+      52                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+      53                 :            :         spdm_context,
+      54                 :            : #endif
+      55                 :         16 :         spdm_context->connection_info.version, SPDM_MEASUREMENTS,
+      56                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+      57                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+      58                 :            :         true, l1l2_hash, l1l2_hash_size, signature, &signature_size);
+      59                 :            : #endif
+      60                 :         16 :     return result;
+      61                 :            : }
+      62                 :        137 : libspdm_return_t libspdm_get_response_measurements(libspdm_context_t *spdm_context,
+      63                 :            :                                                    size_t request_size,
+      64                 :            :                                                    const void *request,
+      65                 :            :                                                    size_t *response_size,
+      66                 :            :                                                    void *response)
+      67                 :            : {
+      68                 :            :     const spdm_get_measurements_request_t *spdm_request;
+      69                 :            :     size_t spdm_request_size;
+      70                 :            :     spdm_measurements_response_t *spdm_response;
+      71                 :            :     size_t spdm_response_size;
+      72                 :            :     libspdm_return_t status;
+      73                 :            :     size_t signature_size;
+      74                 :            :     uint8_t slot_id_param;
+      75                 :            :     uint8_t measurements_index;
+      76                 :            :     uint8_t measurements_count;
+      77                 :            :     uint8_t *measurements;
+      78                 :            :     size_t measurements_size;
+      79                 :            :     uint8_t *opaque_data;
+      80                 :            :     size_t opaque_data_size;
+      81                 :            :     size_t meas_opaque_buffer_size;
+      82                 :            :     bool ret;
+      83                 :            :     libspdm_session_info_t *session_info;
+      84                 :            :     libspdm_session_state_t session_state;
+      85                 :            :     uint8_t content_changed;
+      86                 :            :     uint8_t *fill_response_ptr;
+      87                 :            : 
+      88                 :        137 :     spdm_request = request;
+      89                 :            : 
+      90                 :            :     /* -=[Check Parameters Phase]=- */
+      91         [ -  + ]:        137 :     LIBSPDM_ASSERT(spdm_request->header.request_response_code == SPDM_GET_MEASUREMENTS);
+      92                 :            : 
+      93         [ +  + ]:        137 :     if (!spdm_context->last_spdm_request_session_id_valid) {
+      94                 :        136 :         session_info = NULL;
+      95                 :            :     } else {
+      96                 :          1 :         session_info = libspdm_get_session_info_via_session_id(
+      97                 :            :             spdm_context,
+      98                 :            :             spdm_context->last_spdm_request_session_id);
+      99         [ -  + ]:          1 :         if (session_info == NULL) {
+     100                 :            :             /* do not reset message_m because it is unclear which context it should be used. */
+     101                 :          0 :             return libspdm_generate_error_response(
+     102                 :            :                 spdm_context,
+     103                 :            :                 SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+     104                 :            :                 response_size, response);
+     105                 :            :         }
+     106                 :          1 :         session_state = libspdm_secured_message_get_session_state(
+     107                 :            :             session_info->secured_message_context);
+     108         [ -  + ]:          1 :         if (session_state != LIBSPDM_SESSION_STATE_ESTABLISHED) {
+     109                 :          0 :             libspdm_reset_message_m(spdm_context, session_info);
+     110                 :          0 :             return libspdm_generate_error_response(
+     111                 :            :                 spdm_context,
+     112                 :            :                 SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+     113                 :            :                 response_size, response);
+     114                 :            :         }
+     115                 :            :     }
+     116                 :            : 
+     117         [ -  + ]:        137 :     if (spdm_request->header.spdm_version != libspdm_get_connection_version(spdm_context)) {
+     118                 :          0 :         libspdm_reset_message_m(spdm_context, session_info);
+     119                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     120                 :            :                                                SPDM_ERROR_CODE_VERSION_MISMATCH, 0,
+     121                 :            :                                                response_size, response);
+     122                 :            :     }
+     123         [ +  + ]:        137 :     if (spdm_context->response_state != LIBSPDM_RESPONSE_STATE_NORMAL) {
+     124                 :            : #if LIBSPDM_RESPOND_IF_READY_SUPPORT
+     125         [ +  + ]:          3 :         if (spdm_context->response_state != LIBSPDM_RESPONSE_STATE_NOT_READY) {
+     126                 :            : #endif
+     127                 :          2 :         libspdm_reset_message_m(spdm_context, session_info);
+     128                 :            : #if LIBSPDM_RESPOND_IF_READY_SUPPORT
+     129                 :            :     }
+     130                 :            : #endif
+     131                 :          3 :         return libspdm_responder_handle_response_state(
+     132                 :            :             spdm_context,
+     133                 :          3 :             spdm_request->header.request_response_code,
+     134                 :            :             response_size, response);
+     135                 :            :     }
+     136                 :            :     /* check local context here, because meas_cap is reserved for requester.*/
+     137         [ +  + ]:        134 :     if (!libspdm_is_capabilities_flag_supported(
+     138                 :            :             spdm_context, false, 0,
+     139                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP)) {
+     140                 :          1 :         libspdm_reset_message_m(spdm_context, session_info);
+     141                 :          1 :         return libspdm_generate_error_response(
+     142                 :            :             spdm_context, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+     143                 :            :             SPDM_GET_MEASUREMENTS, response_size, response);
+     144                 :            :     }
+     145         [ +  - ]:        133 :     if ((spdm_context->connection_info.algorithm.measurement_spec == 0) ||
+     146         [ -  + ]:        133 :         (spdm_context->connection_info.algorithm.measurement_hash_algo == 0) ) {
+     147                 :          0 :         libspdm_reset_message_m(spdm_context, session_info);
+     148                 :          0 :         return libspdm_generate_error_response(
+     149                 :            :             spdm_context, SPDM_ERROR_CODE_UNEXPECTED_REQUEST,
+     150                 :            :             0, response_size, response);
+     151                 :            :     }
+     152         [ +  + ]:        133 :     if (spdm_context->connection_info.connection_state <
+     153                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
+     154                 :          1 :         libspdm_reset_message_m(spdm_context, session_info);
+     155                 :          1 :         return libspdm_generate_error_response(
+     156                 :            :             spdm_context,
+     157                 :            :             SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+     158                 :            :             response_size, response);
+     159                 :            :     }
+     160                 :            : 
+     161         [ +  + ]:        132 :     if ((spdm_request->header.param1 &
+     162                 :            :          SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE) != 0) {
+     163         [ +  + ]:         24 :         if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_11) {
+     164         [ +  + ]:         13 :             if (request_size < sizeof(spdm_get_measurements_request_t)) {
+     165                 :          4 :                 libspdm_reset_message_m(spdm_context, session_info);
+     166                 :          4 :                 return libspdm_generate_error_response(
+     167                 :            :                     spdm_context,
+     168                 :            :                     SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     169                 :            :                     response_size, response);
+     170                 :            :             }
+     171                 :          9 :             spdm_request_size = sizeof(spdm_get_measurements_request_t);
+     172                 :            :         } else {
+     173         [ +  + ]:         11 :             if (request_size <
+     174                 :            :                 sizeof(spdm_get_measurements_request_t) -
+     175                 :            :                 sizeof(spdm_request->slot_id_param)) {
+     176                 :          1 :                 libspdm_reset_message_m(spdm_context, session_info);
+     177                 :          1 :                 return libspdm_generate_error_response(
+     178                 :            :                     spdm_context,
+     179                 :            :                     SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     180                 :            :                     response_size, response);
+     181                 :            :             }
+     182                 :         10 :             spdm_request_size = sizeof(spdm_get_measurements_request_t) -
+     183                 :            :                                 sizeof(spdm_request->slot_id_param);
+     184                 :            :         }
+     185                 :            :     } else {
+     186         [ -  + ]:        108 :         if (request_size < sizeof(spdm_message_header_t)) {
+     187                 :          0 :             libspdm_reset_message_m(spdm_context, session_info);
+     188                 :          0 :             return libspdm_generate_error_response(
+     189                 :            :                 spdm_context, SPDM_ERROR_CODE_INVALID_REQUEST,
+     190                 :            :                 0, response_size, response);
+     191                 :            :         }
+     192                 :        108 :         spdm_request_size = sizeof(spdm_message_header_t);
+     193                 :            :     }
+     194         [ +  + ]:        127 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
+     195         [ -  + ]:          2 :         if (request_size < spdm_request_size + SPDM_REQ_CONTEXT_SIZE) {
+     196                 :          0 :             libspdm_reset_message_m(spdm_context, session_info);
+     197                 :          0 :             return libspdm_generate_error_response(
+     198                 :            :                 spdm_context, SPDM_ERROR_CODE_INVALID_REQUEST,
+     199                 :            :                 0, response_size, response);
+     200                 :            :         }
+     201                 :          2 :         spdm_request_size += SPDM_REQ_CONTEXT_SIZE;
+     202                 :            :     }
+     203                 :            : 
+     204         [ +  + ]:        127 :     if ((spdm_request->header.param1 &
+     205                 :            :          SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE) != 0) {
+     206         [ +  + ]:         19 :         if (!libspdm_is_capabilities_flag_supported(
+     207                 :            :                 spdm_context, false, 0,
+     208                 :            :                 SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG)) {
+     209                 :          1 :             libspdm_reset_message_m(spdm_context, session_info);
+     210                 :          1 :             return libspdm_generate_error_response(
+     211                 :            :                 spdm_context, SPDM_ERROR_CODE_INVALID_REQUEST,
+     212                 :            :                 0, response_size, response);
+     213                 :            :         }
+     214                 :            :     }
+     215                 :            : 
+     216         [ +  + ]:        126 :     if ((spdm_request->header.param1 &
+     217                 :            :          SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE) == 0) {
+     218                 :        108 :         signature_size = 0;
+     219                 :            :     } else {
+     220                 :         18 :         signature_size = libspdm_get_asym_signature_size(
+     221                 :            :             spdm_context->connection_info.algorithm.base_asym_algo);
+     222                 :            :     }
+     223                 :            : 
+     224                 :            : 
+     225                 :            :     /* response_size should be large enough to hold a MEASUREMENTS response without
+     226                 :            :      * measurements or opaque data. */
+     227         [ -  + ]:        126 :     LIBSPDM_ASSERT(*response_size >= (sizeof(spdm_measurements_response_t) +
+     228                 :            :                                       SPDM_NONCE_SIZE + sizeof(uint16_t) + signature_size));
+     229                 :            : 
+     230                 :        126 :     meas_opaque_buffer_size = *response_size - (sizeof(spdm_measurements_response_t) +
+     231                 :            :                                                 SPDM_NONCE_SIZE + sizeof(uint16_t) +
+     232                 :            :                                                 signature_size);
+     233                 :            : 
+     234                 :        126 :     libspdm_zero_mem(response, *response_size);
+     235                 :            : 
+     236                 :        126 :     measurements_index = spdm_request->header.param2;
+     237                 :        126 :     measurements_count = 0;
+     238                 :        126 :     measurements = (uint8_t*)response + sizeof(spdm_measurements_response_t);
+     239                 :        126 :     measurements_size = meas_opaque_buffer_size;
+     240                 :            : 
+     241                 :        126 :     status = libspdm_measurement_collection(
+     242                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+     243                 :            :         spdm_context,
+     244                 :            : #endif
+     245                 :        126 :         spdm_context->connection_info.version,
+     246                 :        126 :         spdm_context->connection_info.algorithm.measurement_spec,
+     247                 :            :         spdm_context->connection_info.algorithm.measurement_hash_algo,
+     248                 :            :         measurements_index,
+     249                 :        126 :         spdm_request->header.param1,
+     250                 :            :         &content_changed,
+     251                 :            :         &measurements_count,
+     252                 :            :         measurements,
+     253                 :            :         &measurements_size);
+     254                 :            : 
+     255         [ +  + ]:        126 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     256         [ +  - ]:          1 :         if (status == LIBSPDM_STATUS_MEAS_INVALID_INDEX) {
+     257                 :          1 :             libspdm_reset_message_m(spdm_context, session_info);
+     258                 :          1 :             return libspdm_generate_error_response(
+     259                 :            :                 spdm_context, SPDM_ERROR_CODE_INVALID_REQUEST,
+     260                 :            :                 0, response_size, response);
+     261                 :            :         } else {
+     262                 :          0 :             libspdm_reset_message_m(spdm_context, session_info);
+     263                 :          0 :             return libspdm_generate_error_response(
+     264                 :            :                 spdm_context, SPDM_ERROR_CODE_UNSPECIFIED,
+     265                 :            :                 0, response_size, response);
+     266                 :            :         }
+     267                 :            :     }
+     268                 :            : 
+     269         [ -  + ]:        125 :     LIBSPDM_ASSERT(measurements_count != 0);
+     270   [ +  +  -  + ]:        125 :     LIBSPDM_ASSERT((measurements_index == 0) || (measurements_size > 0));
+     271         [ -  + ]:        125 :     LIBSPDM_ASSERT(measurements_size <= SPDM_MAX_MEASUREMENT_RECORD_LENGTH);
+     272         [ -  + ]:        125 :     LIBSPDM_ASSERT(measurements_size <= meas_opaque_buffer_size);
+     273                 :            : 
+     274         [ +  + ]:        125 :     if (measurements_index == 0) {
+     275                 :         11 :         measurements_size = 0;
+     276                 :            :     }
+     277                 :            : 
+     278                 :        125 :     opaque_data =
+     279                 :            :         (uint8_t*)response + sizeof(spdm_measurements_response_t) + measurements_size +
+     280                 :        125 :         SPDM_NONCE_SIZE + sizeof(uint16_t);
+     281                 :            : 
+     282         [ +  + ]:        125 :     if ((libspdm_get_connection_version(spdm_context) >= SPDM_MESSAGE_VERSION_12) &&
+     283         [ +  + ]:          8 :         ((spdm_context->connection_info.algorithm.other_params_support &
+     284                 :            :           SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_MASK) == SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_NONE)) {
+     285                 :          4 :         opaque_data_size = 0;
+     286                 :            :     } else {
+     287                 :        121 :         opaque_data_size = meas_opaque_buffer_size - measurements_size;
+     288                 :            : 
+     289                 :        121 :         ret = libspdm_measurement_opaque_data(
+     290                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+     291                 :            :             spdm_context,
+     292                 :            : #endif
+     293                 :        121 :             spdm_context->connection_info.version,
+     294                 :        121 :             spdm_context->connection_info.algorithm.measurement_spec,
+     295                 :            :             spdm_context->connection_info.algorithm.measurement_hash_algo,
+     296                 :            :             measurements_index,
+     297                 :        121 :             spdm_request->header.param1,
+     298                 :            :             opaque_data,
+     299                 :            :             &opaque_data_size);
+     300                 :            : 
+     301         [ -  + ]:        121 :         if (!ret) {
+     302                 :          0 :             libspdm_reset_message_m(spdm_context, session_info);
+     303                 :          0 :             return libspdm_generate_error_response(
+     304                 :            :                 spdm_context, SPDM_ERROR_CODE_UNSPECIFIED,
+     305                 :            :                 0, response_size, response);
+     306                 :            :         }
+     307                 :            :     }
+     308                 :            : 
+     309         [ -  + ]:        125 :     LIBSPDM_ASSERT(opaque_data_size <= (meas_opaque_buffer_size - measurements_size));
+     310                 :            : 
+     311                 :        125 :     spdm_response_size =
+     312                 :            :         sizeof(spdm_measurements_response_t) + measurements_size + SPDM_NONCE_SIZE +
+     313                 :        125 :         sizeof(uint16_t) + opaque_data_size + signature_size;
+     314         [ +  + ]:        125 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
+     315                 :          2 :         spdm_response_size += SPDM_REQ_CONTEXT_SIZE;
+     316                 :            :     }
+     317                 :            : 
+     318         [ -  + ]:        125 :     LIBSPDM_ASSERT(*response_size >= spdm_response_size);
+     319                 :            : 
+     320                 :        125 :     *response_size = spdm_response_size;
+     321                 :        125 :     spdm_response = response;
+     322                 :            : 
+     323      [ +  +  + ]:        125 :     switch (spdm_request->header.param2) {
+     324                 :         11 :     case SPDM_GET_MEASUREMENTS_REQUEST_MEASUREMENT_OPERATION_TOTAL_NUMBER_OF_MEASUREMENTS:
+     325                 :         11 :         spdm_response->header.spdm_version = spdm_request->header.spdm_version;
+     326                 :         11 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
+     327                 :         11 :         spdm_response->header.param1 = measurements_count;
+     328                 :         11 :         spdm_response->header.param2 = 0;
+     329                 :         11 :         spdm_response->number_of_blocks = 0;
+     330                 :         11 :         libspdm_write_uint24(spdm_response->measurement_record_length, 0);
+     331                 :         11 :         break;
+     332                 :          5 :     case SPDM_GET_MEASUREMENTS_REQUEST_MEASUREMENT_OPERATION_ALL_MEASUREMENTS:
+     333   [ +  +  -  + ]:         45 :         LIBSPDM_DEBUG_CODE(
+     334                 :            :             uint8_t index;
+     335                 :            :             size_t debug_measurements_record_size;
+     336                 :            :             size_t debug_measurements_block_size;
+     337                 :            :             spdm_measurement_block_dmtf_t *debug_measurement_block;
+     338                 :            : 
+     339                 :            :             debug_measurements_record_size = 0;
+     340                 :            :             debug_measurement_block = (void *)measurements;
+     341                 :            :             for (index = 0; index < measurements_count; index++) {
+     342                 :            :             debug_measurements_block_size =
+     343                 :            :                 sizeof(spdm_measurement_block_dmtf_t) +
+     344                 :            :                 debug_measurement_block->measurement_block_dmtf_header
+     345                 :            :                 .dmtf_spec_measurement_value_size;
+     346                 :            :             debug_measurements_record_size += debug_measurements_block_size;
+     347                 :            :             debug_measurement_block =
+     348                 :            :                 (void *)((size_t)debug_measurement_block + debug_measurements_block_size);
+     349                 :            :         }
+     350                 :            :             LIBSPDM_ASSERT(debug_measurements_record_size == measurements_size);
+     351                 :            :             );
+     352                 :            : 
+     353                 :          5 :         spdm_response->header.spdm_version = spdm_request->header.spdm_version;
+     354                 :          5 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
+     355                 :          5 :         spdm_response->header.param1 = 0;
+     356                 :          5 :         spdm_response->header.param2 = 0;
+     357                 :          5 :         spdm_response->number_of_blocks = measurements_count;
+     358                 :          5 :         libspdm_write_uint24(spdm_response->measurement_record_length, (uint32_t)measurements_size);
+     359                 :          5 :         break;
+     360                 :        109 :     default:
+     361         [ -  + ]:        109 :         LIBSPDM_ASSERT(measurements_count == 1);
+     362                 :            : 
+     363                 :        109 :         spdm_response->header.spdm_version = spdm_request->header.spdm_version;
+     364                 :        109 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
+     365                 :        109 :         spdm_response->header.param1 = 0;
+     366                 :        109 :         spdm_response->header.param2 = 0;
+     367                 :        109 :         spdm_response->number_of_blocks = 1;
+     368                 :        109 :         libspdm_write_uint24(spdm_response->measurement_record_length, (uint32_t)measurements_size);
+     369                 :        109 :         break;
+     370                 :            :     }
+     371                 :            : 
+     372         [ +  + ]:        125 :     if ((spdm_request->header.param1 &
+     373                 :            :          SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE) != 0) {
+     374         [ +  + ]:         18 :         if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_11) {
+     375                 :          8 :             slot_id_param = spdm_request->slot_id_param &
+     376                 :            :                             SPDM_GET_MEASUREMENTS_REQUEST_SLOT_ID_MASK;
+     377   [ +  +  +  + ]:          8 :             if ((slot_id_param != 0xF) && (slot_id_param >= SPDM_MAX_SLOT_COUNT)) {
+     378                 :          1 :                 libspdm_reset_message_m(spdm_context, session_info);
+     379                 :          1 :                 return libspdm_generate_error_response(
+     380                 :            :                     spdm_context,
+     381                 :            :                     SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     382                 :            :                     response_size, response);
+     383                 :            :             }
+     384         [ +  + ]:          7 :             if (slot_id_param != 0xF) {
+     385                 :          6 :                 if (spdm_context->local_context
+     386         [ -  + ]:          6 :                     .local_cert_chain_provision[slot_id_param] == NULL) {
+     387                 :          0 :                     libspdm_reset_message_m(spdm_context, session_info);
+     388                 :          0 :                     return libspdm_generate_error_response(
+     389                 :            :                         spdm_context, SPDM_ERROR_CODE_INVALID_REQUEST,
+     390                 :            :                         0, response_size, response);
+     391                 :            :                 }
+     392                 :            :             } else {
+     393                 :          1 :                 if (spdm_context->local_context
+     394         [ -  + ]:          1 :                     .local_public_key_provision == NULL) {
+     395                 :          0 :                     libspdm_reset_message_m(spdm_context, session_info);
+     396                 :          0 :                     return libspdm_generate_error_response(
+     397                 :            :                         spdm_context, SPDM_ERROR_CODE_INVALID_REQUEST,
+     398                 :            :                         0, response_size, response);
+     399                 :            :                 }
+     400                 :            :             }
+     401                 :            : 
+     402         [ +  + ]:          7 :             if ((spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) &&
+     403   [ +  -  +  - ]:          1 :                 spdm_context->connection_info.multi_key_conn_rsp &&
+     404                 :            :                 (slot_id_param != 0xF)) {
+     405         [ +  - ]:          1 :                 if ((spdm_context->local_context.local_key_usage_bit_mask[slot_id_param] &
+     406                 :            :                      SPDM_KEY_USAGE_BIT_MASK_MEASUREMENT_USE) == 0) {
+     407                 :          1 :                     return libspdm_generate_error_response(
+     408                 :            :                         spdm_context, SPDM_ERROR_CODE_INVALID_REQUEST,
+     409                 :            :                         0, response_size, response);
+     410                 :            :                 }
+     411                 :            :             }
+     412                 :            : 
+     413                 :          6 :             spdm_response->header.param2 = slot_id_param;
+     414         [ +  + ]:          6 :             if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_12) {
+     415                 :          5 :                 spdm_response->header.param2 = slot_id_param |
+     416                 :          5 :                                                (content_changed &
+     417                 :            :                                                 SPDM_MEASUREMENTS_RESPONSE_CONTENT_CHANGE_MASK);
+     418                 :            :             }
+     419                 :            :         }
+     420                 :            :     }
+     421                 :            : 
+     422                 :        123 :     fill_response_ptr =
+     423                 :        123 :         (uint8_t*)response + sizeof(spdm_measurements_response_t) + measurements_size;
+     424                 :            : 
+     425         [ -  + ]:        123 :     if(!libspdm_get_random_number(SPDM_NONCE_SIZE, fill_response_ptr)) {
+     426                 :          0 :         libspdm_reset_message_m(spdm_context, session_info);
+     427                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     428                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     429                 :            :                                                response_size, response);
+     430                 :            :     }
+     431                 :        123 :     fill_response_ptr += SPDM_NONCE_SIZE;
+     432                 :            : 
+     433                 :        123 :     libspdm_write_uint16(fill_response_ptr, (uint16_t)opaque_data_size);
+     434                 :        123 :     fill_response_ptr += sizeof(uint16_t);
+     435                 :            : 
+     436                 :        123 :     fill_response_ptr += opaque_data_size;
+     437                 :            : 
+     438         [ +  + ]:        123 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
+     439                 :          1 :         libspdm_copy_mem(fill_response_ptr, SPDM_REQ_CONTEXT_SIZE,
+     440                 :          1 :                          (const uint8_t *)spdm_request + spdm_request_size - SPDM_REQ_CONTEXT_SIZE,
+     441                 :            :                          SPDM_REQ_CONTEXT_SIZE);
+     442                 :          1 :         fill_response_ptr += SPDM_REQ_CONTEXT_SIZE;
+     443                 :            :     }
+     444                 :            : 
+     445                 :        123 :     libspdm_reset_message_buffer_via_request_code(spdm_context, session_info,
+     446                 :        123 :                                                   spdm_request->header.request_response_code);
+     447                 :            : 
+     448                 :        123 :     status = libspdm_append_message_m(spdm_context, session_info, spdm_request, spdm_request_size);
+     449         [ -  + ]:        123 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     450                 :          0 :         libspdm_reset_message_m(spdm_context, session_info);
+     451                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     452                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     453                 :            :                                                response_size, response);
+     454                 :            :     }
+     455                 :            : 
+     456                 :        123 :     status = libspdm_append_message_m(spdm_context, session_info,
+     457                 :        123 :                                       spdm_response, *response_size - signature_size);
+     458         [ -  + ]:        123 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     459                 :          0 :         libspdm_reset_message_m(spdm_context, session_info);
+     460                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     461                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     462                 :            :                                                response_size, response);
+     463                 :            :     }
+     464                 :            : 
+     465         [ +  + ]:        123 :     if ((spdm_request->header.param1 &
+     466                 :            :          SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE) != 0) {
+     467                 :            : 
+     468                 :         16 :         ret = libspdm_generate_measurement_signature(spdm_context, session_info, fill_response_ptr);
+     469                 :            : 
+     470         [ -  + ]:         16 :         if (!ret) {
+     471                 :          0 :             libspdm_reset_message_m(spdm_context, session_info);
+     472                 :          0 :             return libspdm_generate_error_response(
+     473                 :            :                 spdm_context,
+     474                 :            :                 SPDM_ERROR_CODE_UNSPECIFIED,
+     475                 :            :                 0,
+     476                 :            :                 response_size, response);
+     477                 :            :         }
+     478                 :            :         /*reset*/
+     479                 :         16 :         libspdm_reset_message_m(spdm_context, session_info);
+     480                 :            :     }
+     481                 :            : 
+     482                 :        123 :     return LIBSPDM_STATUS_SUCCESS;
+     483                 :            : }
+     484                 :            : 
+     485                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_psk_exchange.c.func-sort-c.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_psk_exchange.c.func-sort-c.html new file mode 100644 index 00000000000..f1816aa7ae6 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_psk_exchange.c.func-sort-c.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_psk_exchange.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_psk_exchange.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:12818369.9 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:5610056.0 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_generate_psk_exchange_rsp_hmac11
libspdm_get_response_psk_exchange18
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_psk_exchange.c.func.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_psk_exchange.c.func.html new file mode 100644 index 00000000000..a6954091bae --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_psk_exchange.c.func.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_psk_exchange.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_psk_exchange.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:12818369.9 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:5610056.0 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_generate_psk_exchange_rsp_hmac11
libspdm_get_response_psk_exchange18
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_psk_exchange.c.gcov.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_psk_exchange.c.gcov.html new file mode 100644 index 00000000000..332c4849217 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_psk_exchange.c.gcov.html @@ -0,0 +1,564 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_psk_exchange.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_psk_exchange.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:12818369.9 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:5610056.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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_responder_lib.h"
+       8                 :            : #include "internal/libspdm_secured_message_lib.h"
+       9                 :            : 
+      10                 :            : #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
+      11                 :            : 
+      12                 :            : /**
+      13                 :            :  * This function generates the PSK exchange HMAC based upon TH.
+      14                 :            :  *
+      15                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+      16                 :            :  * @param  session_info                  The session info of an SPDM session.
+      17                 :            :  * @param  hmac                         The buffer to store the PSK exchange HMAC.
+      18                 :            :  *
+      19                 :            :  * @retval true  PSK exchange HMAC is generated.
+      20                 :            :  * @retval false PSK exchange HMAC is not generated.
+      21                 :            :  **/
+      22                 :         11 : static bool libspdm_generate_psk_exchange_rsp_hmac(libspdm_context_t *spdm_context,
+      23                 :            :                                                    libspdm_session_info_t *session_info,
+      24                 :            :                                                    uint8_t *hmac)
+      25                 :            : {
+      26                 :            :     uint8_t hmac_data[LIBSPDM_MAX_HASH_SIZE];
+      27                 :            :     size_t hash_size;
+      28                 :            :     bool result;
+      29                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+      30                 :            :     uint8_t *th_curr_data;
+      31                 :            :     size_t th_curr_data_size;
+      32                 :            :     libspdm_th_managed_buffer_t th_curr;
+      33                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+      34                 :            : #endif
+      35                 :            : 
+      36                 :         11 :     hash_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+      37                 :            : 
+      38                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+      39                 :            :     result = libspdm_calculate_th_for_exchange(spdm_context, session_info,
+      40                 :            :                                                NULL, 0, &th_curr);
+      41                 :            :     if (!result) {
+      42                 :            :         return false;
+      43                 :            :     }
+      44                 :            :     th_curr_data = libspdm_get_managed_buffer(&th_curr);
+      45                 :            :     th_curr_data_size = libspdm_get_managed_buffer_size(&th_curr);
+      46                 :            : 
+      47                 :            :     result = libspdm_hash_all (spdm_context->connection_info.algorithm.base_hash_algo,
+      48                 :            :                                th_curr_data, th_curr_data_size, hash_data);
+      49                 :            :     if (!result) {
+      50                 :            :         return false;
+      51                 :            :     }
+      52                 :            : 
+      53                 :            :     result = libspdm_hmac_all_with_response_finished_key(
+      54                 :            :         session_info->secured_message_context, hash_data,
+      55                 :            :         hash_size, hmac_data);
+      56                 :            :     if (!result) {
+      57                 :            :         return false;
+      58                 :            :     }
+      59                 :            : #else
+      60                 :         11 :     result = libspdm_calculate_th_hmac_for_exchange_rsp(
+      61                 :            :         spdm_context, session_info, false, &hash_size, hmac_data);
+      62         [ -  + ]:         11 :     if (!result) {
+      63                 :          0 :         return false;
+      64                 :            :     }
+      65                 :            : #endif
+      66                 :         11 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "th_curr hmac - "));
+      67                 :         11 :     LIBSPDM_INTERNAL_DUMP_DATA(hmac_data, hash_size);
+      68                 :         11 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+      69                 :            : 
+      70                 :         11 :     libspdm_copy_mem(hmac, hash_size, hmac_data, hash_size);
+      71                 :            : 
+      72                 :         11 :     return true;
+      73                 :            : }
+      74                 :            : 
+      75                 :         18 : libspdm_return_t libspdm_get_response_psk_exchange(libspdm_context_t *spdm_context,
+      76                 :            :                                                    size_t request_size,
+      77                 :            :                                                    const void *request,
+      78                 :            :                                                    size_t *response_size,
+      79                 :            :                                                    void *response)
+      80                 :            : {
+      81                 :            :     const spdm_psk_exchange_request_t *spdm_request;
+      82                 :            :     spdm_psk_exchange_response_t *spdm_response;
+      83                 :            :     bool result;
+      84                 :            :     uint32_t session_id;
+      85                 :            :     uint32_t measurement_summary_hash_size;
+      86                 :            :     uint32_t hmac_size;
+      87                 :            :     const uint8_t *cptr;
+      88                 :            :     uint8_t *ptr;
+      89                 :            :     libspdm_session_info_t *session_info;
+      90                 :            :     size_t total_size;
+      91                 :            :     uint16_t req_session_id;
+      92                 :            :     uint16_t rsp_session_id;
+      93                 :            :     libspdm_return_t status;
+      94                 :            :     size_t opaque_psk_exchange_rsp_size;
+      95                 :            :     uint8_t th1_hash_data[LIBSPDM_MAX_HASH_SIZE];
+      96                 :            :     uint8_t th2_hash_data[LIBSPDM_MAX_HASH_SIZE];
+      97                 :            :     uint32_t algo_size;
+      98                 :            :     uint16_t context_length;
+      99                 :            :     const void *psk_hint;
+     100                 :            :     size_t psk_hint_size;
+     101                 :            : 
+     102                 :         18 :     spdm_request = request;
+     103                 :            : 
+     104                 :            :     /* -=[Check Parameters Phase]=- */
+     105         [ -  + ]:         18 :     LIBSPDM_ASSERT(spdm_request->header.request_response_code == SPDM_PSK_EXCHANGE);
+     106                 :            : 
+     107         [ -  + ]:         18 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_11) {
+     108                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     109                 :            :                                                SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+     110                 :            :                                                SPDM_PSK_EXCHANGE,
+     111                 :            :                                                response_size, response);
+     112                 :            :     }
+     113                 :            : 
+     114         [ -  + ]:         18 :     if (spdm_request->header.spdm_version != libspdm_get_connection_version(spdm_context)) {
+     115                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     116                 :            :                                                SPDM_ERROR_CODE_VERSION_MISMATCH, 0,
+     117                 :            :                                                response_size, response);
+     118                 :            :     }
+     119         [ +  + ]:         18 :     if (spdm_context->response_state != LIBSPDM_RESPONSE_STATE_NORMAL) {
+     120                 :          3 :         return libspdm_responder_handle_response_state(
+     121                 :            :             spdm_context,
+     122                 :          3 :             spdm_request->header.request_response_code,
+     123                 :            :             response_size, response);
+     124                 :            :     }
+     125                 :            :     /* Check capabilities even if GET_CAPABILITIES is not sent.
+     126                 :            :      * Assuming capabilities are provisioned.*/
+     127         [ -  + ]:         15 :     if (!libspdm_is_capabilities_flag_supported(
+     128                 :            :             spdm_context, false,
+     129                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP,
+     130                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP)) {
+     131                 :          0 :         return libspdm_generate_error_response(
+     132                 :            :             spdm_context, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+     133                 :            :             SPDM_PSK_EXCHANGE, response_size, response);
+     134                 :            :     }
+     135         [ +  + ]:         15 :     if (spdm_context->connection_info.connection_state < LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
+     136                 :          1 :         return libspdm_generate_error_response(spdm_context,
+     137                 :            :                                                SPDM_ERROR_CODE_UNEXPECTED_REQUEST,
+     138                 :            :                                                0, response_size, response);
+     139                 :            :     }
+     140         [ +  + ]:         14 :     if (libspdm_get_connection_version(spdm_context) >= SPDM_MESSAGE_VERSION_12) {
+     141         [ -  + ]:          2 :         if ((spdm_context->connection_info.algorithm.other_params_support &
+     142                 :            :              SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_MASK) != SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1) {
+     143                 :          0 :             return libspdm_generate_error_response(
+     144                 :            :                 spdm_context, SPDM_ERROR_CODE_INVALID_REQUEST,
+     145                 :            :                 0, response_size, response);
+     146                 :            :         }
+     147                 :            :     }
+     148         [ -  + ]:         14 :     if (spdm_context->last_spdm_request_session_id_valid) {
+     149                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     150                 :            :                                                SPDM_ERROR_CODE_UNEXPECTED_REQUEST,
+     151                 :            :                                                0, response_size, response);
+     152                 :            :     }
+     153                 :            : 
+     154                 :            :     {
+     155                 :            :         /* Double check if algorithm has been provisioned, because ALGORITHM might be skipped.*/
+     156         [ -  + ]:         14 :         if (libspdm_is_capabilities_flag_supported(
+     157                 :            :                 spdm_context, true, 0,
+     158                 :            :                 SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP)) {
+     159                 :          0 :             if (spdm_context->connection_info.algorithm
+     160         [ #  # ]:          0 :                 .measurement_spec != SPDM_MEASUREMENT_SPECIFICATION_DMTF) {
+     161                 :          0 :                 return libspdm_generate_error_response(
+     162                 :            :                     spdm_context,
+     163                 :            :                     SPDM_ERROR_CODE_INVALID_REQUEST,
+     164                 :            :                     0, response_size,
+     165                 :            :                     response);
+     166                 :            :             }
+     167                 :          0 :             algo_size = libspdm_get_measurement_hash_size(
+     168                 :            :                 spdm_context->connection_info.algorithm
+     169                 :            :                 .measurement_hash_algo);
+     170         [ #  # ]:          0 :             if (algo_size == 0) {
+     171                 :          0 :                 return libspdm_generate_error_response(
+     172                 :            :                     spdm_context,
+     173                 :            :                     SPDM_ERROR_CODE_INVALID_REQUEST,
+     174                 :            :                     0, response_size,
+     175                 :            :                     response);
+     176                 :            :             }
+     177                 :            :         }
+     178                 :         14 :         algo_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+     179         [ -  + ]:         14 :         if (algo_size == 0) {
+     180                 :          0 :             return libspdm_generate_error_response(
+     181                 :            :                 spdm_context,
+     182                 :            :                 SPDM_ERROR_CODE_INVALID_REQUEST,
+     183                 :            :                 0, response_size, response);
+     184                 :            :         }
+     185         [ -  + ]:         14 :         if (spdm_context->connection_info.algorithm.key_schedule !=
+     186                 :            :             SPDM_ALGORITHMS_KEY_SCHEDULE_HMAC_HASH) {
+     187                 :          0 :             return libspdm_generate_error_response(
+     188                 :            :                 spdm_context,
+     189                 :            :                 SPDM_ERROR_CODE_INVALID_REQUEST,
+     190                 :            :                 0, response_size, response);
+     191                 :            :         }
+     192                 :            :     }
+     193                 :            : 
+     194         [ +  + ]:         14 :     if (spdm_request->header.param1 > 0) {
+     195         [ +  + ]:          4 :         if (!libspdm_is_capabilities_flag_supported(
+     196                 :            :                 spdm_context, false,
+     197                 :          3 :                 0, SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP) ||
+     198         [ +  - ]:          3 :             (spdm_context->connection_info.algorithm.measurement_spec == 0) ||
+     199         [ -  + ]:          3 :             (spdm_context->connection_info.algorithm.measurement_hash_algo == 0) ) {
+     200                 :          1 :             return libspdm_generate_error_response(
+     201                 :            :                 spdm_context, SPDM_ERROR_CODE_INVALID_REQUEST,
+     202                 :            :                 0, response_size, response);
+     203                 :            :         }
+     204                 :            :     }
+     205                 :            : 
+     206                 :         13 :     measurement_summary_hash_size = libspdm_get_measurement_summary_hash_size(
+     207                 :         13 :         spdm_context, false, spdm_request->header.param1);
+     208         [ +  + ]:         13 :     if ((measurement_summary_hash_size == 0) &&
+     209         [ +  + ]:         11 :         (spdm_request->header.param1 != SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH)) {
+     210                 :          1 :         return libspdm_generate_error_response(spdm_context,
+     211                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST,
+     212                 :            :                                                0, response_size, response);
+     213                 :            :     }
+     214                 :            : 
+     215                 :         12 :     hmac_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+     216                 :            : 
+     217         [ -  + ]:         12 :     if (request_size < sizeof(spdm_psk_exchange_request_t)) {
+     218                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     219                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     220                 :            :                                                response_size, response);
+     221                 :            :     }
+     222                 :         12 :     if (request_size < sizeof(spdm_psk_exchange_request_t) +
+     223                 :         12 :         spdm_request->psk_hint_length +
+     224                 :         12 :         spdm_request->context_length +
+     225         [ +  + ]:         12 :         spdm_request->opaque_length) {
+     226                 :          1 :         return libspdm_generate_error_response(spdm_context,
+     227                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     228                 :            :                                                response_size, response);
+     229                 :            :     }
+     230                 :         11 :     request_size = sizeof(spdm_psk_exchange_request_t) +
+     231                 :         11 :                    spdm_request->psk_hint_length +
+     232                 :         11 :                    spdm_request->context_length +
+     233                 :         11 :                    spdm_request->opaque_length;
+     234                 :            : 
+     235         [ +  + ]:         11 :     if (spdm_request->opaque_length != 0) {
+     236                 :          9 :         cptr = (const uint8_t *)request + sizeof(spdm_psk_exchange_request_t) +
+     237                 :          9 :                spdm_request->psk_hint_length + spdm_request->context_length;
+     238                 :          9 :         result = libspdm_process_general_opaque_data_check(spdm_context,
+     239                 :          9 :                                                            spdm_request->opaque_length, cptr);
+     240         [ -  + ]:          9 :         if (!result) {
+     241                 :          0 :             return libspdm_generate_error_response(spdm_context,
+     242                 :            :                                                    SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     243                 :            :                                                    response_size, response);
+     244                 :            :         }
+     245                 :          9 :         status = libspdm_process_opaque_data_supported_version_data(
+     246                 :          9 :             spdm_context, spdm_request->opaque_length, cptr);
+     247         [ -  + ]:          9 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     248                 :          0 :             return libspdm_generate_error_response(spdm_context,
+     249                 :            :                                                    SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     250                 :            :                                                    response_size, response);
+     251                 :            :         }
+     252                 :            :     }
+     253                 :            : 
+     254                 :         11 :     opaque_psk_exchange_rsp_size =
+     255                 :         11 :         libspdm_get_opaque_data_version_selection_data_size(spdm_context);
+     256         [ +  - ]:         11 :     if (libspdm_is_capabilities_flag_supported(
+     257                 :            :             spdm_context, false, 0,
+     258                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT)) {
+     259                 :         11 :         context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
+     260                 :            :     } else {
+     261                 :          0 :         context_length = 0;
+     262                 :            :     }
+     263                 :         11 :     total_size = sizeof(spdm_psk_exchange_response_t) +
+     264                 :         11 :                  measurement_summary_hash_size + context_length +
+     265                 :         11 :                  opaque_psk_exchange_rsp_size + hmac_size;
+     266                 :            : 
+     267         [ -  + ]:         11 :     LIBSPDM_ASSERT(*response_size >= total_size);
+     268                 :         11 :     *response_size = total_size;
+     269                 :         11 :     libspdm_zero_mem(response, *response_size);
+     270                 :         11 :     spdm_response = response;
+     271                 :            : 
+     272                 :         11 :     spdm_response->header.spdm_version = spdm_request->header.spdm_version;
+     273                 :         11 :     spdm_response->header.request_response_code = SPDM_PSK_EXCHANGE_RSP;
+     274         [ -  + ]:         11 :     if (libspdm_is_capabilities_flag_supported(
+     275                 :            :             spdm_context, false,
+     276                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP,
+     277                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP)) {
+     278                 :          0 :         spdm_response->header.param1 = spdm_context->local_context.heartbeat_period;
+     279                 :            :     } else {
+     280                 :         11 :         spdm_response->header.param1 = 0x00;
+     281                 :            :     }
+     282                 :            : 
+     283                 :         11 :     req_session_id = spdm_request->req_session_id;
+     284                 :         11 :     rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, true);
+     285         [ -  + ]:         11 :     if (rsp_session_id == ((INVALID_SESSION_ID & 0xFFFF0000) >> 16)) {
+     286                 :          0 :         return libspdm_generate_error_response(
+     287                 :            :             spdm_context, SPDM_ERROR_CODE_SESSION_LIMIT_EXCEEDED, 0,
+     288                 :            :             response_size, response);
+     289                 :            :     }
+     290         [ +  + ]:         11 :     if (spdm_request->psk_hint_length == 0) {
+     291                 :          2 :         psk_hint_size = 0;
+     292                 :          2 :         psk_hint = NULL;
+     293         [ +  - ]:          9 :     } else if(spdm_request->psk_hint_length <= LIBSPDM_PSK_MAX_HINT_LENGTH ) {
+     294                 :          9 :         psk_hint_size = spdm_request->psk_hint_length;
+     295                 :          9 :         psk_hint = (const uint8_t *)request +
+     296                 :            :                    sizeof(spdm_psk_exchange_request_t);
+     297                 :            :     } else {
+     298                 :          0 :         return libspdm_generate_error_response(
+     299                 :            :             spdm_context, SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     300                 :            :             response_size, response);
+     301                 :            :     }
+     302                 :         11 :     session_id = libspdm_generate_session_id(req_session_id, rsp_session_id);
+     303                 :         11 :     session_info = libspdm_assign_session_id(spdm_context, session_id, true);
+     304         [ -  + ]:         11 :     if (session_info == NULL) {
+     305                 :          0 :         return libspdm_generate_error_response(
+     306                 :            :             spdm_context, SPDM_ERROR_CODE_SESSION_LIMIT_EXCEEDED, 0,
+     307                 :            :             response_size, response);
+     308                 :            :     }
+     309                 :         11 :     libspdm_session_info_set_psk_hint(session_info, psk_hint, psk_hint_size);
+     310                 :            : 
+     311                 :         11 :     libspdm_reset_message_buffer_via_request_code(spdm_context, NULL,
+     312                 :         11 :                                                   spdm_request->header.request_response_code);
+     313                 :            : 
+     314                 :         11 :     spdm_response->rsp_session_id = rsp_session_id;
+     315                 :         11 :     spdm_response->reserved = 0;
+     316                 :            : 
+     317                 :         11 :     spdm_response->context_length = context_length;
+     318                 :         11 :     spdm_response->opaque_length = (uint16_t)opaque_psk_exchange_rsp_size;
+     319                 :            : 
+     320                 :         11 :     ptr = (void *)(spdm_response + 1);
+     321                 :            : 
+     322                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
+     323         [ +  + ]:         11 :     if (libspdm_is_capabilities_flag_supported(
+     324                 :            :             spdm_context, false, 0,  SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP)) {
+     325                 :            : 
+     326                 :          2 :         result = libspdm_generate_measurement_summary_hash(
+     327                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+     328                 :            :             spdm_context,
+     329                 :            : #endif
+     330                 :          2 :             spdm_context->connection_info.version,
+     331                 :            :             spdm_context->connection_info.algorithm.base_hash_algo,
+     332                 :          2 :             spdm_context->connection_info.algorithm.measurement_spec,
+     333                 :            :             spdm_context->connection_info.algorithm.measurement_hash_algo,
+     334                 :          2 :             spdm_request->header.param1,
+     335                 :            :             ptr,
+     336                 :            :             measurement_summary_hash_size);
+     337                 :            :     } else {
+     338                 :          9 :         result = true;
+     339                 :            :     }
+     340                 :            : 
+     341         [ -  + ]:         11 :     if (!result) {
+     342                 :          0 :         libspdm_free_session_id(spdm_context, session_id);
+     343                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     344                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     345                 :            :                                                response_size, response);
+     346                 :            :     }
+     347                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP */
+     348                 :            : 
+     349                 :         11 :     ptr += measurement_summary_hash_size;
+     350                 :            : 
+     351         [ +  - ]:         11 :     if (context_length != 0) {
+     352         [ -  + ]:         11 :         if(!libspdm_get_random_number(context_length, ptr)) {
+     353                 :          0 :             libspdm_free_session_id(spdm_context, session_id);
+     354                 :          0 :             return libspdm_generate_error_response(spdm_context,
+     355                 :            :                                                    SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     356                 :            :                                                    response_size, response);
+     357                 :            :         }
+     358                 :         11 :         ptr += context_length;
+     359                 :            :     }
+     360                 :            : 
+     361                 :         11 :     libspdm_build_opaque_data_version_selection_data(
+     362                 :            :         spdm_context, &opaque_psk_exchange_rsp_size, ptr);
+     363                 :            : 
+     364                 :         11 :     ptr += opaque_psk_exchange_rsp_size;
+     365                 :            : 
+     366                 :         11 :     status = libspdm_append_message_k(spdm_context, session_info, false, request, request_size);
+     367         [ -  + ]:         11 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     368                 :          0 :         libspdm_free_session_id(spdm_context, session_id);
+     369                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     370                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     371                 :            :                                                response_size, response);
+     372                 :            :     }
+     373                 :            : 
+     374                 :         11 :     status = libspdm_append_message_k(spdm_context, session_info, false, spdm_response,
+     375                 :         11 :                                       (size_t)ptr - (size_t)spdm_response);
+     376         [ -  + ]:         11 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     377                 :          0 :         libspdm_free_session_id(spdm_context, session_id);
+     378                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     379                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     380                 :            :                                                response_size, response);
+     381                 :            :     }
+     382                 :            : 
+     383                 :         11 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "libspdm_generate_session_handshake_key[%x]\n",
+     384                 :            :                    session_id));
+     385                 :         11 :     result = libspdm_calculate_th1_hash(spdm_context, session_info, false,
+     386                 :            :                                         th1_hash_data);
+     387         [ -  + ]:         11 :     if (!result) {
+     388                 :          0 :         libspdm_free_session_id(spdm_context, session_id);
+     389                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     390                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     391                 :            :                                                response_size, response);
+     392                 :            :     }
+     393                 :         11 :     result = libspdm_generate_session_handshake_key(
+     394                 :            :         session_info->secured_message_context, th1_hash_data);
+     395         [ -  + ]:         11 :     if (!result) {
+     396                 :          0 :         libspdm_free_session_id(spdm_context, session_id);
+     397                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     398                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     399                 :            :                                                response_size, response);
+     400                 :            :     }
+     401                 :            : 
+     402                 :         11 :     result = libspdm_generate_psk_exchange_rsp_hmac(spdm_context, session_info,
+     403                 :            :                                                     ptr);
+     404         [ -  + ]:         11 :     if (!result) {
+     405                 :          0 :         libspdm_free_session_id(spdm_context, session_id);
+     406                 :          0 :         return libspdm_generate_error_response(
+     407                 :            :             spdm_context, SPDM_ERROR_CODE_UNSPECIFIED,
+     408                 :            :             0, response_size, response);
+     409                 :            :     }
+     410                 :         11 :     status = libspdm_append_message_k(spdm_context, session_info, false, ptr, hmac_size);
+     411         [ -  + ]:         11 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     412                 :          0 :         libspdm_free_session_id(spdm_context, session_id);
+     413                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     414                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     415                 :            :                                                response_size, response);
+     416                 :            :     }
+     417                 :         11 :     ptr += hmac_size;
+     418                 :            : 
+     419         [ +  + ]:         11 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_12) {
+     420                 :          2 :         session_info->session_policy = spdm_request->header.param2;
+     421                 :            :     }
+     422                 :         11 :     libspdm_set_session_state(spdm_context, session_id, LIBSPDM_SESSION_STATE_HANDSHAKING);
+     423                 :            : 
+     424         [ -  + ]:         11 :     if (!libspdm_is_capabilities_flag_supported(
+     425                 :            :             spdm_context, false, 0,
+     426                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT)) {
+     427                 :            :         /* No need to receive PSK_FINISH, enter application phase directly.*/
+     428                 :            : 
+     429                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "libspdm_generate_session_data_key[%x]\n",
+     430                 :            :                        session_id));
+     431                 :          0 :         result = libspdm_calculate_th2_hash(spdm_context, session_info,
+     432                 :            :                                             false, th2_hash_data);
+     433         [ #  # ]:          0 :         if (!result) {
+     434                 :          0 :             libspdm_free_session_id(spdm_context, session_id);
+     435                 :          0 :             return libspdm_generate_error_response(
+     436                 :            :                 spdm_context, SPDM_ERROR_CODE_UNSPECIFIED,
+     437                 :            :                 0, response_size, response);
+     438                 :            :         }
+     439                 :          0 :         result = libspdm_generate_session_data_key(
+     440                 :            :             session_info->secured_message_context, th2_hash_data);
+     441         [ #  # ]:          0 :         if (!result) {
+     442                 :          0 :             libspdm_free_session_id(spdm_context, session_id);
+     443                 :          0 :             return libspdm_generate_error_response(
+     444                 :            :                 spdm_context, SPDM_ERROR_CODE_UNSPECIFIED,
+     445                 :            :                 0, response_size, response);
+     446                 :            :         }
+     447                 :            : 
+     448                 :            :         #if LIBSPDM_ENABLE_CAPABILITY_HBEAT_CAP
+     449         [ #  # ]:          0 :         if (libspdm_is_capabilities_flag_supported(
+     450                 :            :                 spdm_context, false,
+     451                 :            :                 SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP,
+     452                 :            :                 SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP)) {
+     453                 :          0 :             result = libspdm_start_watchdog(
+     454                 :          0 :                 session_id, spdm_context->local_context.heartbeat_period * 2);
+     455         [ #  # ]:          0 :             if (!result) {
+     456                 :          0 :                 libspdm_free_session_id(spdm_context, session_id);
+     457                 :          0 :                 return libspdm_generate_error_response(
+     458                 :            :                     spdm_context, SPDM_ERROR_CODE_UNSPECIFIED,
+     459                 :            :                     0, response_size, response);
+     460                 :            :             }
+     461                 :            :         }
+     462                 :            :         #endif /* LIBSPDM_ENABLE_CAPABILITY_HBEAT_CAP */
+     463                 :            : 
+     464                 :          0 :         libspdm_set_session_state(spdm_context, session_id, LIBSPDM_SESSION_STATE_ESTABLISHED);
+     465                 :            :     }
+     466                 :            : 
+     467         [ -  + ]:         11 :     if (libspdm_is_capabilities_flag_supported(
+     468                 :            :             spdm_context, false,
+     469                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP,
+     470                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP)) {
+     471                 :          0 :         session_info->heartbeat_period = spdm_context->local_context.heartbeat_period;
+     472                 :            :     } else {
+     473                 :         11 :         session_info->heartbeat_period = 0x00;
+     474                 :            :     }
+     475                 :            : 
+     476                 :         11 :     return LIBSPDM_STATUS_SUCCESS;
+     477                 :            : }
+     478                 :            : 
+     479                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_psk_finish.c.func-sort-c.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_psk_finish.c.func-sort-c.html new file mode 100644 index 00000000000..bf91c149190 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_psk_finish.c.func-sort-c.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_psk_finish.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_psk_finish.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:648179.0 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:304862.5 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_verify_psk_finish_req_hmac6
libspdm_get_response_psk_finish15
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_psk_finish.c.func.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_psk_finish.c.func.html new file mode 100644 index 00000000000..3f5d8821e60 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_psk_finish.c.func.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_psk_finish.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_psk_finish.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:648179.0 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:304862.5 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_response_psk_finish15
libspdm_verify_psk_finish_req_hmac6
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_psk_finish.c.gcov.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_psk_finish.c.gcov.html new file mode 100644 index 00000000000..bc71b3de655 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_psk_finish.c.gcov.html @@ -0,0 +1,337 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_psk_finish.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_psk_finish.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:648179.0 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:304862.5 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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_responder_lib.h"
+       8                 :            : #include "internal/libspdm_secured_message_lib.h"
+       9                 :            : 
+      10                 :            : #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
+      11                 :            : 
+      12                 :          6 : bool libspdm_verify_psk_finish_req_hmac(libspdm_context_t *spdm_context,
+      13                 :            :                                         libspdm_session_info_t *session_info,
+      14                 :            :                                         const uint8_t *hmac, size_t hmac_size)
+      15                 :            : {
+      16                 :            :     uint8_t hmac_data[LIBSPDM_MAX_HASH_SIZE];
+      17                 :            :     size_t hash_size;
+      18                 :            :     bool result;
+      19                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+      20                 :            :     uint8_t *th_curr_data;
+      21                 :            :     size_t th_curr_data_size;
+      22                 :            :     libspdm_th_managed_buffer_t th_curr;
+      23                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+      24                 :            : #endif
+      25                 :            : 
+      26                 :          6 :     hash_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+      27         [ -  + ]:          6 :     LIBSPDM_ASSERT(hmac_size == hash_size);
+      28                 :            : 
+      29                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+      30                 :            :     result = libspdm_calculate_th_for_finish(spdm_context, session_info, NULL,
+      31                 :            :                                              0, NULL, 0, &th_curr);
+      32                 :            :     if (!result) {
+      33                 :            :         return false;
+      34                 :            :     }
+      35                 :            :     th_curr_data = libspdm_get_managed_buffer(&th_curr);
+      36                 :            :     th_curr_data_size = libspdm_get_managed_buffer_size(&th_curr);
+      37                 :            : 
+      38                 :            :     result = libspdm_hash_all (spdm_context->connection_info.algorithm.base_hash_algo,
+      39                 :            :                                th_curr_data, th_curr_data_size, hash_data);
+      40                 :            :     if (!result) {
+      41                 :            :         return false;
+      42                 :            :     }
+      43                 :            : 
+      44                 :            :     result = libspdm_hmac_all_with_request_finished_key(
+      45                 :            :         session_info->secured_message_context, hash_data,
+      46                 :            :         hash_size, hmac_data);
+      47                 :            :     if (!result) {
+      48                 :            :         return false;
+      49                 :            :     }
+      50                 :            : #else
+      51                 :          6 :     result = libspdm_calculate_th_hmac_for_finish_req(
+      52                 :            :         spdm_context, session_info, &hash_size, hmac_data);
+      53         [ -  + ]:          6 :     if (!result) {
+      54                 :          0 :         return false;
+      55                 :            :     }
+      56                 :            : #endif
+      57                 :          6 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "Calc th_curr hmac - "));
+      58                 :          6 :     LIBSPDM_INTERNAL_DUMP_DATA(hmac_data, hash_size);
+      59                 :          6 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+      60                 :            : 
+      61         [ +  + ]:          6 :     if (!libspdm_consttime_is_mem_equal(hmac, hmac_data, hash_size)) {
+      62                 :          2 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR, "!!! verify_psk_finish_req_hmac - FAIL !!!\n"));
+      63                 :          2 :         return false;
+      64                 :            :     }
+      65                 :          4 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "!!! verify_psk_finish_req_hmac - PASS !!!\n"));
+      66                 :          4 :     return true;
+      67                 :            : }
+      68                 :            : 
+      69                 :         15 : libspdm_return_t libspdm_get_response_psk_finish(libspdm_context_t *spdm_context,
+      70                 :            :                                                  size_t request_size,
+      71                 :            :                                                  const void *request,
+      72                 :            :                                                  size_t *response_size,
+      73                 :            :                                                  void *response)
+      74                 :            : {
+      75                 :            :     uint32_t session_id;
+      76                 :            :     bool result;
+      77                 :            :     uint32_t hmac_size;
+      78                 :            :     spdm_psk_finish_response_t *spdm_response;
+      79                 :            :     libspdm_session_info_t *session_info;
+      80                 :            :     uint8_t th2_hash_data[LIBSPDM_MAX_HASH_SIZE];
+      81                 :            :     const spdm_psk_finish_request_t *spdm_request;
+      82                 :            :     libspdm_return_t status;
+      83                 :            :     libspdm_session_state_t session_state;
+      84                 :            : 
+      85                 :         15 :     spdm_request = request;
+      86                 :            : 
+      87                 :            :     /* -=[Check Parameters Phase]=- */
+      88         [ -  + ]:         15 :     LIBSPDM_ASSERT(spdm_request->header.request_response_code == SPDM_PSK_FINISH);
+      89                 :            : 
+      90         [ -  + ]:         15 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_11) {
+      91                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      92                 :            :                                                SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+      93                 :            :                                                SPDM_PSK_FINISH,
+      94                 :            :                                                response_size, response);
+      95                 :            :     }
+      96                 :            : 
+      97         [ -  + ]:         15 :     if (spdm_request->header.spdm_version != libspdm_get_connection_version(spdm_context)) {
+      98                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      99                 :            :                                                SPDM_ERROR_CODE_VERSION_MISMATCH, 0,
+     100                 :            :                                                response_size, response);
+     101                 :            :     }
+     102         [ +  + ]:         15 :     if (spdm_context->response_state != LIBSPDM_RESPONSE_STATE_NORMAL) {
+     103                 :          3 :         return libspdm_responder_handle_response_state(
+     104                 :            :             spdm_context,
+     105                 :          3 :             spdm_request->header.request_response_code,
+     106                 :            :             response_size, response);
+     107                 :            :     }
+     108         [ +  + ]:         12 :     if (!libspdm_is_capabilities_flag_supported(
+     109                 :            :             spdm_context, false,
+     110                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP,
+     111                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT)) {
+     112                 :          1 :         return libspdm_generate_error_response(
+     113                 :            :             spdm_context, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+     114                 :            :             SPDM_PSK_FINISH, response_size, response);
+     115                 :            :     }
+     116         [ +  + ]:         11 :     if (spdm_context->connection_info.connection_state < LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
+     117                 :          1 :         return libspdm_generate_error_response(spdm_context,
+     118                 :            :                                                SPDM_ERROR_CODE_UNEXPECTED_REQUEST,
+     119                 :            :                                                0, response_size, response);
+     120                 :            :     }
+     121                 :            : 
+     122         [ -  + ]:         10 :     if (!spdm_context->last_spdm_request_session_id_valid) {
+     123                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     124                 :            :                                                SPDM_ERROR_CODE_SESSION_REQUIRED, 0,
+     125                 :            :                                                response_size, response);
+     126                 :            :     }
+     127                 :         10 :     session_id = spdm_context->last_spdm_request_session_id;
+     128                 :            :     session_info =
+     129                 :         10 :         libspdm_get_session_info_via_session_id(spdm_context, session_id);
+     130         [ -  + ]:         10 :     if (session_info == NULL) {
+     131                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     132                 :            :                                                SPDM_ERROR_CODE_SESSION_REQUIRED, 0,
+     133                 :            :                                                response_size, response);
+     134                 :            :     }
+     135         [ -  + ]:         10 :     if (!session_info->use_psk) {
+     136                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     137                 :            :                                                SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+     138                 :            :                                                response_size, response);
+     139                 :            :     }
+     140                 :         10 :     session_state = libspdm_secured_message_get_session_state(
+     141                 :            :         session_info->secured_message_context);
+     142         [ +  + ]:         10 :     if (session_state != LIBSPDM_SESSION_STATE_HANDSHAKING) {
+     143                 :          1 :         return libspdm_generate_error_response(spdm_context,
+     144                 :            :                                                SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+     145                 :            :                                                response_size, response);
+     146                 :            :     }
+     147                 :            : 
+     148                 :            :     /* remove HMAC*/
+     149                 :          9 :     hmac_size = libspdm_get_hash_size(
+     150                 :            :         spdm_context->connection_info.algorithm.base_hash_algo);
+     151                 :            : 
+     152                 :            :     /* this message can only be in secured session
+     153                 :            :      * thus don't need to consider transport layer padding, just check its exact size */
+     154         [ +  + ]:          9 :     if (request_size != sizeof(spdm_psk_finish_request_t) + hmac_size) {
+     155                 :          3 :         return libspdm_generate_error_response(spdm_context,
+     156                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     157                 :            :                                                response_size, response);
+     158                 :            :     }
+     159                 :            : 
+     160                 :          6 :     libspdm_reset_message_buffer_via_request_code(spdm_context, session_info,
+     161                 :          6 :                                                   spdm_request->header.request_response_code);
+     162                 :            : 
+     163                 :          6 :     status = libspdm_append_message_f(spdm_context, session_info, false, request,
+     164                 :            :                                       request_size - hmac_size);
+     165         [ -  + ]:          6 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     166                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     167                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     168                 :            :                                                response_size, response);
+     169                 :            :     }
+     170                 :            : 
+     171         [ -  + ]:          6 :     LIBSPDM_ASSERT(*response_size >= sizeof(spdm_psk_finish_response_t));
+     172                 :          6 :     *response_size = sizeof(spdm_psk_finish_response_t);
+     173                 :          6 :     libspdm_zero_mem(response, *response_size);
+     174                 :          6 :     spdm_response = response;
+     175                 :            : 
+     176                 :          6 :     spdm_response->header.spdm_version = spdm_request->header.spdm_version;
+     177                 :          6 :     spdm_response->header.request_response_code = SPDM_PSK_FINISH_RSP;
+     178                 :          6 :     spdm_response->header.param1 = 0;
+     179                 :          6 :     spdm_response->header.param2 = 0;
+     180                 :            : 
+     181                 :          6 :     result = libspdm_verify_psk_finish_req_hmac(
+     182                 :            :         spdm_context, session_info,
+     183                 :            :         (const uint8_t *)request + sizeof(spdm_psk_finish_request_t),
+     184                 :            :         hmac_size);
+     185         [ +  + ]:          6 :     if (!result) {
+     186         [ +  - ]:          2 :         if((spdm_context->handle_error_return_policy &
+     187                 :            :             LIBSPDM_DATA_HANDLE_ERROR_RETURN_POLICY_DROP_ON_DECRYPT_ERROR) == 0) {
+     188                 :          2 :             return libspdm_generate_error_response(
+     189                 :            :                 spdm_context, SPDM_ERROR_CODE_DECRYPT_ERROR, 0,
+     190                 :            :                 response_size, response);
+     191                 :            :         } else {
+     192                 :            :             /**
+     193                 :            :              * just ignore this message
+     194                 :            :              * return UNSUPPORTED and clear response_size to continue the dispatch without send response
+     195                 :            :              **/
+     196                 :          0 :             *response_size = 0;
+     197                 :          0 :             return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     198                 :            :         }
+     199                 :            :     }
+     200                 :          4 :     status = libspdm_append_message_f(
+     201                 :            :         spdm_context, session_info, false,
+     202                 :          4 :         (const uint8_t *)request + request_size - hmac_size,
+     203                 :            :         hmac_size);
+     204         [ -  + ]:          4 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     205                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     206                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     207                 :            :                                                response_size, response);
+     208                 :            :     }
+     209                 :            : 
+     210                 :          4 :     status = libspdm_append_message_f(spdm_context, session_info, false, spdm_response,
+     211                 :            :                                       *response_size);
+     212         [ -  + ]:          4 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     213                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     214                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     215                 :            :                                                response_size, response);
+     216                 :            :     }
+     217                 :            : 
+     218                 :          4 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "libspdm_generate_session_data_key[%x]\n", session_id));
+     219                 :          4 :     result = libspdm_calculate_th2_hash(spdm_context, session_info, false,
+     220                 :            :                                         th2_hash_data);
+     221         [ -  + ]:          4 :     if (!result) {
+     222                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     223                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     224                 :            :                                                response_size, response);
+     225                 :            :     }
+     226                 :          4 :     result = libspdm_generate_session_data_key(
+     227                 :            :         session_info->secured_message_context, th2_hash_data);
+     228         [ -  + ]:          4 :     if (!result) {
+     229                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     230                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     231                 :            :                                                response_size, response);
+     232                 :            :     }
+     233                 :            : 
+     234                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_HBEAT_CAP
+     235         [ -  + ]:          4 :     if (libspdm_is_capabilities_flag_supported(
+     236                 :            :             spdm_context, false,
+     237                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP,
+     238                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP)) {
+     239                 :          0 :         result = libspdm_start_watchdog(
+     240                 :          0 :             session_id, spdm_context->local_context.heartbeat_period * 2);
+     241         [ #  # ]:          0 :         if (!result) {
+     242                 :          0 :             return libspdm_generate_error_response(spdm_context,
+     243                 :            :                                                    SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     244                 :            :                                                    response_size, response);
+     245                 :            :         }
+     246                 :            :     }
+     247                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_HBEAT_CAP */
+     248                 :            : 
+     249                 :          4 :     return LIBSPDM_STATUS_SUCCESS;
+     250                 :            : }
+     251                 :            : 
+     252                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_receive_send.c.func-sort-c.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_receive_send.c.func-sort-c.html new file mode 100644 index 00000000000..0f4184c0156 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_receive_send.c.func-sort-c.html @@ -0,0 +1,137 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_receive_send.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_receive_send.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:11132434.3 %
Date:2024-09-22 08:21:07Functions:91464.3 %
Branches:4618824.5 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_process_request0
libspdm_register_connection_state_callback_func0
libspdm_register_get_response_func0
libspdm_register_key_update_callback_func0
libspdm_register_session_state_callback_func0
libspdm_build_response4
libspdm_get_response_func_via_last_request4
libspdm_get_response_func_via_request_code14
libspdm_trigger_key_update_callback15
libspdm_set_session_state21
libspdm_trigger_session_state_callback21
libspdm_trigger_connection_state_callback78
libspdm_set_connection_state80
libspdm_register_cert_chain_buffer89
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_receive_send.c.func.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_receive_send.c.func.html new file mode 100644 index 00000000000..73d12e74aa1 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_receive_send.c.func.html @@ -0,0 +1,137 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_receive_send.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_receive_send.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:11132434.3 %
Date:2024-09-22 08:21:07Functions:91464.3 %
Branches:4618824.5 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_build_response4
libspdm_get_response_func_via_last_request4
libspdm_get_response_func_via_request_code14
libspdm_process_request0
libspdm_register_cert_chain_buffer89
libspdm_register_connection_state_callback_func0
libspdm_register_get_response_func0
libspdm_register_key_update_callback_func0
libspdm_register_session_state_callback_func0
libspdm_set_connection_state80
libspdm_set_session_state21
libspdm_trigger_connection_state_callback78
libspdm_trigger_key_update_callback15
libspdm_trigger_session_state_callback21
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_receive_send.c.gcov.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_receive_send.c.gcov.html new file mode 100644 index 00000000000..5060c687336 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_receive_send.c.gcov.html @@ -0,0 +1,1005 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_receive_send.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_receive_send.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:11132434.3 %
Date:2024-09-22 08:21:07Functions:91464.3 %
Branches:4618824.5 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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_responder_lib.h"
+       8                 :            : #include "internal/libspdm_secured_message_lib.h"
+       9                 :            : 
+      10                 :            : /**
+      11                 :            :  * Return the GET_SPDM_RESPONSE function via request code.
+      12                 :            :  *
+      13                 :            :  * @param  request_code                  The SPDM request code.
+      14                 :            :  *
+      15                 :            :  * @return GET_SPDM_RESPONSE function according to the request code.
+      16                 :            :  **/
+      17                 :         14 : libspdm_get_spdm_response_func libspdm_get_response_func_via_request_code(uint8_t request_code)
+      18                 :            : {
+      19                 :            :     size_t index;
+      20                 :            : 
+      21                 :            :     typedef struct {
+      22                 :            :         uint8_t request_response_code;
+      23                 :            :         libspdm_get_spdm_response_func get_response_func;
+      24                 :            :     } libspdm_get_response_struct_t;
+      25                 :            : 
+      26                 :         14 :     libspdm_get_response_struct_t get_response_struct[] = {
+      27                 :            :         { SPDM_GET_VERSION, libspdm_get_response_version },
+      28                 :            :         { SPDM_GET_CAPABILITIES, libspdm_get_response_capabilities },
+      29                 :            :         { SPDM_NEGOTIATE_ALGORITHMS, libspdm_get_response_algorithms },
+      30                 :            : 
+      31                 :            :         #if LIBSPDM_ENABLE_CAPABILITY_CERT_CAP
+      32                 :            :         { SPDM_GET_DIGESTS, libspdm_get_response_digests },
+      33                 :            :         { SPDM_GET_CERTIFICATE, libspdm_get_response_certificate },
+      34                 :            :         #endif /* LIBSPDM_ENABLE_CAPABILITY_CERT_CAP */
+      35                 :            : 
+      36                 :            :         #if LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP
+      37                 :            :         { SPDM_CHALLENGE, libspdm_get_response_challenge_auth },
+      38                 :            :         #endif /* LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP*/
+      39                 :            : 
+      40                 :            :         #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
+      41                 :            :         { SPDM_GET_MEASUREMENTS, libspdm_get_response_measurements },
+      42                 :            :         #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP*/
+      43                 :            : 
+      44                 :            :         #if LIBSPDM_ENABLE_CAPABILITY_MEL_CAP
+      45                 :            :         { SPDM_GET_MEASUREMENT_EXTENSION_LOG, libspdm_get_response_measurement_extension_log },
+      46                 :            :         #endif /* LIBSPDM_ENABLE_CAPABILITY_MEL_CAP */
+      47                 :            : 
+      48                 :            :         #if LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP
+      49                 :            :         { SPDM_KEY_EXCHANGE, libspdm_get_response_key_exchange },
+      50                 :            :         #endif /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP*/
+      51                 :            : 
+      52                 :            :         #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
+      53                 :            :         { SPDM_PSK_EXCHANGE, libspdm_get_response_psk_exchange },
+      54                 :            :         #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP*/
+      55                 :            : 
+      56                 :            :         #if LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP
+      57                 :            :         { SPDM_GET_ENCAPSULATED_REQUEST, libspdm_get_response_encapsulated_request },
+      58                 :            :         { SPDM_DELIVER_ENCAPSULATED_RESPONSE, libspdm_get_response_encapsulated_response_ack },
+      59                 :            :         #endif /* LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP */
+      60                 :            : 
+      61                 :            :         #if LIBSPDM_RESPOND_IF_READY_SUPPORT
+      62                 :            :         { SPDM_RESPOND_IF_READY, libspdm_get_response_respond_if_ready },
+      63                 :            :         #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
+      64                 :            : 
+      65                 :            :         #if LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP
+      66                 :            :         { SPDM_FINISH, libspdm_get_response_finish },
+      67                 :            :         #endif /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP*/
+      68                 :            : 
+      69                 :            :         #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
+      70                 :            :         { SPDM_PSK_FINISH, libspdm_get_response_psk_finish },
+      71                 :            :         #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP*/
+      72                 :            : 
+      73                 :            :         #if (LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP) || (LIBSPDM_ENABLE_CAPABILITY_PSK_CAP)
+      74                 :            :         { SPDM_END_SESSION, libspdm_get_response_end_session },
+      75                 :            :         { SPDM_HEARTBEAT, libspdm_get_response_heartbeat },
+      76                 :            :         { SPDM_KEY_UPDATE, libspdm_get_response_key_update },
+      77                 :            :         #endif /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP || LIBSPDM_ENABLE_CAPABILITY_PSK_CAP*/
+      78                 :            : 
+      79                 :            :         #if LIBSPDM_ENABLE_CAPABILITY_CSR_CAP
+      80                 :            :         { SPDM_GET_CSR, libspdm_get_response_csr },
+      81                 :            :         #endif /*LIBSPDM_ENABLE_CAPABILITY_CSR_CAP*/
+      82                 :            : 
+      83                 :            :         #if LIBSPDM_ENABLE_CAPABILITY_SET_CERT_CAP
+      84                 :            :         { SPDM_SET_CERTIFICATE, libspdm_get_response_set_certificate },
+      85                 :            :         #endif /*LIBSPDM_ENABLE_CAPABILITY_SET_CERT_CAP*/
+      86                 :            : 
+      87                 :            :         #if LIBSPDM_ENABLE_CAPABILITY_GET_KEY_PAIR_INFO_CAP
+      88                 :            :         { SPDM_GET_KEY_PAIR_INFO, libspdm_get_response_key_pair_info },
+      89                 :            :         #endif /*LIBSPDM_ENABLE_CAPABILITY_GET_KEY_PAIR_INFO_CAP*/
+      90                 :            : 
+      91                 :            :         #if LIBSPDM_ENABLE_CAPABILITY_SET_KEY_PAIR_INFO_CAP
+      92                 :            :         { SPDM_SET_KEY_PAIR_INFO, libspdm_get_response_set_key_pair_info_ack },
+      93                 :            :         #endif /*LIBSPDM_ENABLE_CAPABILITY_SET_KEY_PAIR_INFO_CAP*/
+      94                 :            : 
+      95                 :            :         #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
+      96                 :            :         { SPDM_CHUNK_GET, libspdm_get_response_chunk_get},
+      97                 :            :         { SPDM_CHUNK_SEND, libspdm_get_response_chunk_send},
+      98                 :            :         #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP */
+      99                 :            : 
+     100                 :            :         #if LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP
+     101                 :            :         { SPDM_SUPPORTED_EVENT_TYPES, libspdm_get_response_supported_event_types },
+     102                 :            :         { SPDM_SUBSCRIBE_EVENT_TYPES, libspdm_get_response_subscribe_event_types_ack },
+     103                 :            :         #endif /* LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP */
+     104                 :            : 
+     105                 :            :         #if LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES
+     106                 :            :         { SPDM_VENDOR_DEFINED_REQUEST, libspdm_get_vendor_defined_response },
+     107                 :            :         #endif /*LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES*/
+     108                 :            :     };
+     109                 :            : 
+     110         [ +  - ]:        145 :     for (index = 0; index < LIBSPDM_ARRAY_SIZE(get_response_struct); index++) {
+     111         [ +  + ]:        145 :         if (request_code == get_response_struct[index].request_response_code) {
+     112                 :         14 :             return get_response_struct[index].get_response_func;
+     113                 :            :         }
+     114                 :            :     }
+     115                 :          0 :     return NULL;
+     116                 :            : }
+     117                 :            : 
+     118                 :            : /**
+     119                 :            :  * Return the GET_SPDM_RESPONSE function via last request.
+     120                 :            :  *
+     121                 :            :  * @param  spdm_context                  The SPDM context for the device.
+     122                 :            :  *
+     123                 :            :  * @return GET_SPDM_RESPONSE function according to the last request.
+     124                 :            :  **/
+     125                 :          4 : static libspdm_get_spdm_response_func libspdm_get_response_func_via_last_request(
+     126                 :            :     libspdm_context_t *spdm_context)
+     127                 :            : {
+     128                 :            :     spdm_message_header_t *spdm_request;
+     129                 :            : 
+     130                 :          4 :     spdm_request = (void *)spdm_context->last_spdm_request;
+     131                 :          4 :     return libspdm_get_response_func_via_request_code(spdm_request->request_response_code);
+     132                 :            : }
+     133                 :            : 
+     134                 :            : /**
+     135                 :            :  * Process a SPDM request from a device.
+     136                 :            :  *
+     137                 :            :  * @param  spdm_context                  The SPDM context for the device.
+     138                 :            :  * @param  session_id                    Indicate if the request is a secured message.
+     139                 :            :  *                                     If session_id is NULL, it is a normal message.
+     140                 :            :  *                                     If session_id is NOT NULL, it is a secured message.
+     141                 :            :  * @param  is_app_message                 Indicates if it is an APP message or SPDM message.
+     142                 :            :  * @param  request_size                  size in bytes of the request data buffer.
+     143                 :            :  * @param  request                      A pointer to a destination buffer to store the request.
+     144                 :            :  *                                     The caller is responsible for having
+     145                 :            :  *                                     either implicit or explicit ownership of the buffer.
+     146                 :            :  *
+     147                 :            :  * @retval RETURN_SUCCESS               The SPDM request is received successfully.
+     148                 :            :  * @retval RETURN_DEVICE_ERROR          A device error occurs when the SPDM request is received from the device.
+     149                 :            :  **/
+     150                 :          0 : libspdm_return_t libspdm_process_request(void *spdm_context, uint32_t **session_id,
+     151                 :            :                                          bool *is_app_message,
+     152                 :            :                                          size_t request_size, void *request)
+     153                 :            : {
+     154                 :            :     libspdm_context_t *context;
+     155                 :            :     void *temp_session_context;
+     156                 :            :     libspdm_return_t status;
+     157                 :            :     libspdm_session_info_t *session_info;
+     158                 :            :     uint32_t *message_session_id;
+     159                 :            :     uint8_t *decoded_message_ptr;
+     160                 :            :     size_t decoded_message_size;
+     161                 :            :     uint8_t *backup_decoded_message_ptr;
+     162                 :            :     size_t backup_decoded_message_size;
+     163                 :            :     bool result;
+     164                 :            :     bool reset_key_update;
+     165                 :            : 
+     166                 :          0 :     context = spdm_context;
+     167                 :            :     size_t transport_header_size;
+     168                 :            :     uint8_t *scratch_buffer;
+     169                 :            :     size_t scratch_buffer_size;
+     170                 :            : 
+     171         [ #  # ]:          0 :     if (request == NULL) {
+     172                 :          0 :         return LIBSPDM_STATUS_INVALID_PARAMETER;
+     173                 :            :     }
+     174         [ #  # ]:          0 :     if (request_size == 0) {
+     175                 :          0 :         return LIBSPDM_STATUS_INVALID_PARAMETER;
+     176                 :            :     }
+     177                 :            : 
+     178                 :          0 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "SpdmReceiveRequest[.] ...\n"));
+     179                 :            : 
+     180                 :          0 :     message_session_id = NULL;
+     181                 :          0 :     context->last_spdm_request_session_id_valid = false;
+     182                 :          0 :     context->last_spdm_request_size =
+     183                 :          0 :         libspdm_get_scratch_buffer_last_spdm_request_capacity(context);
+     184                 :            : 
+     185                 :            :     /* always use scratch buffer to response.
+     186                 :            :      * if it is secured message, this scratch buffer will be used.
+     187                 :            :      * if it is normal message, the response ptr will point to receiver buffer. */
+     188                 :          0 :     transport_header_size = context->local_context.capability.transport_header_size;
+     189                 :          0 :     libspdm_get_scratch_buffer (context, (void **)&scratch_buffer, &scratch_buffer_size);
+     190                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
+     191                 :          0 :     decoded_message_ptr = scratch_buffer +
+     192                 :          0 :                           libspdm_get_scratch_buffer_secure_message_offset(context) +
+     193                 :            :                           transport_header_size;
+     194                 :          0 :     decoded_message_size = libspdm_get_scratch_buffer_secure_message_capacity(context) -
+     195                 :            :                            transport_header_size;
+     196                 :            :     #else
+     197                 :            :     decoded_message_ptr = scratch_buffer + transport_header_size;
+     198                 :            :     decoded_message_size = scratch_buffer_size - transport_header_size;
+     199                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP */
+     200                 :            : 
+     201                 :          0 :     backup_decoded_message_ptr = decoded_message_ptr;
+     202                 :          0 :     backup_decoded_message_size = decoded_message_size;
+     203                 :            : 
+     204                 :          0 :     status = context->transport_decode_message(
+     205                 :            :         context, &message_session_id, is_app_message, true,
+     206                 :            :         request_size, request, &decoded_message_size,
+     207                 :            :         (void **)&decoded_message_ptr);
+     208                 :            : 
+     209                 :          0 :     reset_key_update = false;
+     210                 :          0 :     temp_session_context = NULL;
+     211                 :            : 
+     212         [ #  # ]:          0 :     if (status == LIBSPDM_STATUS_SESSION_TRY_DISCARD_KEY_UPDATE) {
+     213                 :            :         /* Failed to decode, but have backup keys. Try rolling back before aborting.
+     214                 :            :          * message_session_id must be valid for us to have attempted decryption. */
+     215         [ #  # ]:          0 :         if (message_session_id == NULL) {
+     216                 :          0 :             return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+     217                 :            :         }
+     218                 :          0 :         temp_session_context = libspdm_get_secured_message_context_via_session_id(
+     219                 :            :             context, *message_session_id);
+     220         [ #  # ]:          0 :         if (temp_session_context == NULL) {
+     221                 :          0 :             return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+     222                 :            :         }
+     223                 :            : 
+     224                 :          0 :         result = libspdm_activate_update_session_data_key(
+     225                 :            :             temp_session_context, LIBSPDM_KEY_UPDATE_ACTION_REQUESTER, false);
+     226         [ #  # ]:          0 :         if (!result) {
+     227                 :          0 :             return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+     228                 :            :         }
+     229                 :          0 :         libspdm_trigger_key_update_callback(
+     230                 :            :             context, *message_session_id,
+     231                 :            :             LIBSPDM_KEY_UPDATE_OPERATION_DISCARD_UPDATE,
+     232                 :            :             LIBSPDM_KEY_UPDATE_ACTION_REQUESTER);
+     233                 :            : 
+     234                 :            :         /* Retry decoding message with backup Requester key.
+     235                 :            :          * Must reset some of the parameters in case they were modified */
+     236                 :          0 :         message_session_id = NULL;
+     237                 :          0 :         decoded_message_ptr = backup_decoded_message_ptr;
+     238                 :          0 :         decoded_message_size = backup_decoded_message_size;
+     239                 :          0 :         status = context->transport_decode_message(
+     240                 :            :             context, &message_session_id, is_app_message, true,
+     241                 :            :             request_size, request, &decoded_message_size,
+     242                 :            :             (void **)&decoded_message_ptr);
+     243                 :            : 
+     244                 :          0 :         reset_key_update = true;
+     245                 :            :     }
+     246                 :            : 
+     247         [ #  # ]:          0 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     248                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "transport_decode_message : %xu\n", status));
+     249         [ #  # ]:          0 :         if (context->last_spdm_error.error_code != 0) {
+     250                 :            : 
+     251                 :            :             /* If the SPDM error code is Non-Zero, that means we need send the error message back to requester.
+     252                 :            :              * In this case, we need return SUCCESS and let caller invoke libspdm_build_response() to send an ERROR message.*/
+     253                 :            : 
+     254                 :          0 :             *session_id = &context->last_spdm_error.session_id;
+     255                 :          0 :             *is_app_message = false;
+     256                 :          0 :             return LIBSPDM_STATUS_SUCCESS;
+     257                 :            :         }
+     258                 :          0 :         return status;
+     259                 :            :     }
+     260                 :            : 
+     261                 :            :     /* Handle special case for bi-directional communication:
+     262                 :            :      * If the Requester returns RESPONSE_NOT_READY error to KEY_UPDATE, the Responder needs
+     263                 :            :      * to activate backup key to parse the error. Then later the Requester will return SUCCESS,
+     264                 :            :      * the Responder needs new key. So we need to restore the environment by
+     265                 :            :      * libspdm_create_update_session_data_key() again.*/
+     266         [ #  # ]:          0 :     if (reset_key_update) {
+     267                 :            :         /* temp_session_context and message_session_id must necessarily
+     268                 :            :          * be valid for us to reach here. */
+     269   [ #  #  #  # ]:          0 :         if (temp_session_context == NULL || message_session_id == NULL) {
+     270                 :          0 :             return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+     271                 :            :         }
+     272                 :          0 :         result = libspdm_create_update_session_data_key(
+     273                 :            :             temp_session_context, LIBSPDM_KEY_UPDATE_ACTION_REQUESTER);
+     274         [ #  # ]:          0 :         if (!result) {
+     275                 :          0 :             return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+     276                 :            :         }
+     277                 :          0 :         libspdm_trigger_key_update_callback(
+     278                 :            :             context, *message_session_id,
+     279                 :            :             LIBSPDM_KEY_UPDATE_OPERATION_CREATE_UPDATE,
+     280                 :            :             LIBSPDM_KEY_UPDATE_ACTION_REQUESTER);
+     281                 :            :     }
+     282                 :            : 
+     283                 :          0 :     context->last_spdm_request_size = decoded_message_size;
+     284                 :          0 :     libspdm_copy_mem (context->last_spdm_request,
+     285                 :          0 :                       libspdm_get_scratch_buffer_last_spdm_request_capacity(context),
+     286                 :            :                       decoded_message_ptr,
+     287                 :            :                       decoded_message_size);
+     288                 :            : 
+     289         [ #  # ]:          0 :     if (!(*is_app_message)) {
+     290                 :            :         /* Check for minimal SPDM message size. */
+     291         [ #  # ]:          0 :         if (context->last_spdm_request_size < sizeof(spdm_message_header_t)) {
+     292                 :          0 :             return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     293                 :            :         }
+     294                 :            :     }
+     295                 :            : 
+     296                 :          0 :     *session_id = message_session_id;
+     297                 :            : 
+     298         [ #  # ]:          0 :     if (message_session_id != NULL) {
+     299                 :          0 :         session_info = libspdm_get_session_info_via_session_id(context, *message_session_id);
+     300         [ #  # ]:          0 :         if (session_info == NULL) {
+     301                 :          0 :             return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     302                 :            :         }
+     303                 :          0 :         context->last_spdm_request_session_id = *message_session_id;
+     304                 :          0 :         context->last_spdm_request_session_id_valid = true;
+     305                 :            :     }
+     306                 :            : 
+     307         [ #  # ]:          0 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "SpdmReceiveRequest[%x] msg %s(0x%x), size (0x%zx): \n",
+     308                 :            :                    (message_session_id != NULL) ? *message_session_id : 0,
+     309                 :            :                    libspdm_get_code_str(((spdm_message_header_t *)context->last_spdm_request)->
+     310                 :            :                                         request_response_code),
+     311                 :            :                    ((spdm_message_header_t *)context->last_spdm_request)->request_response_code,
+     312                 :            :                    context->last_spdm_request_size));
+     313                 :          0 :     LIBSPDM_INTERNAL_DUMP_HEX((uint8_t *)context->last_spdm_request,
+     314                 :            :                               context->last_spdm_request_size);
+     315                 :            : 
+     316                 :          0 :     return LIBSPDM_STATUS_SUCCESS;
+     317                 :            : }
+     318                 :            : 
+     319                 :            : /**
+     320                 :            :  * Notify the session state to a session APP.
+     321                 :            :  *
+     322                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     323                 :            :  * @param  session_id                    The session_id of a session.
+     324                 :            :  * @param  session_state                 The state of a session.
+     325                 :            :  **/
+     326                 :         21 : static void libspdm_trigger_session_state_callback(libspdm_context_t *spdm_context,
+     327                 :            :                                                    uint32_t session_id,
+     328                 :            :                                                    libspdm_session_state_t session_state)
+     329                 :            : {
+     330         [ -  + ]:         21 :     if (spdm_context->spdm_session_state_callback != NULL) {
+     331                 :          0 :         ((libspdm_session_state_callback_func)
+     332                 :          0 :          spdm_context->spdm_session_state_callback)(spdm_context, session_id, session_state);
+     333                 :            :     }
+     334                 :         21 : }
+     335                 :            : 
+     336                 :            : /**
+     337                 :            :  * Set session_state to an SPDM secured message context and trigger callback.
+     338                 :            :  *
+     339                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     340                 :            :  * @param  session_id                    Indicate the SPDM session ID.
+     341                 :            :  * @param  session_state                 Indicate the SPDM session state.
+     342                 :            :  */
+     343                 :         21 : void libspdm_set_session_state(libspdm_context_t *spdm_context,
+     344                 :            :                                uint32_t session_id,
+     345                 :            :                                libspdm_session_state_t session_state)
+     346                 :            : {
+     347                 :            :     libspdm_session_info_t *session_info;
+     348                 :            :     libspdm_session_state_t old_session_state;
+     349                 :            : 
+     350                 :         21 :     session_info = libspdm_get_session_info_via_session_id(spdm_context, session_id);
+     351         [ -  + ]:         21 :     if (session_info == NULL) {
+     352                 :          0 :         LIBSPDM_ASSERT(false);
+     353                 :          0 :         return;
+     354                 :            :     }
+     355                 :            : 
+     356                 :         21 :     old_session_state = libspdm_secured_message_get_session_state(
+     357                 :            :         session_info->secured_message_context);
+     358         [ +  - ]:         21 :     if (old_session_state != session_state) {
+     359                 :         21 :         libspdm_secured_message_set_session_state(
+     360                 :            :             session_info->secured_message_context, session_state);
+     361                 :         21 :         libspdm_trigger_session_state_callback(
+     362                 :            :             spdm_context, session_info->session_id, session_state);
+     363                 :            :     }
+     364                 :            : }
+     365                 :            : 
+     366                 :            : /**
+     367                 :            :  * Notify the connection state to an SPDM context register.
+     368                 :            :  *
+     369                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     370                 :            :  * @param  connection_state              Indicate the SPDM connection state.
+     371                 :            :  **/
+     372                 :         78 : static void libspdm_trigger_connection_state_callback(libspdm_context_t *spdm_context,
+     373                 :            :                                                       const libspdm_connection_state_t
+     374                 :            :                                                       connection_state)
+     375                 :            : {
+     376         [ -  + ]:         78 :     if (spdm_context->spdm_connection_state_callback != NULL) {
+     377                 :          0 :         ((libspdm_connection_state_callback_func)
+     378                 :          0 :          spdm_context->spdm_connection_state_callback)(spdm_context, connection_state);
+     379                 :            :     }
+     380                 :         78 : }
+     381                 :            : 
+     382                 :            : /**
+     383                 :            :  * Set connection_state to an SPDM context and trigger callback.
+     384                 :            :  *
+     385                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     386                 :            :  * @param  connection_state              Indicate the SPDM connection state.
+     387                 :            :  */
+     388                 :         80 : void libspdm_set_connection_state(libspdm_context_t *spdm_context,
+     389                 :            :                                   libspdm_connection_state_t connection_state)
+     390                 :            : {
+     391         [ +  + ]:         80 :     if (spdm_context->connection_info.connection_state != connection_state) {
+     392                 :         78 :         spdm_context->connection_info.connection_state = connection_state;
+     393                 :         78 :         libspdm_trigger_connection_state_callback(spdm_context, connection_state);
+     394                 :            :     }
+     395                 :         80 : }
+     396                 :            : 
+     397                 :         15 : void libspdm_trigger_key_update_callback(void *spdm_context, uint32_t session_id,
+     398                 :            :                                          libspdm_key_update_operation_t key_update_op,
+     399                 :            :                                          libspdm_key_update_action_t key_update_action)
+     400                 :            : {
+     401                 :            :     libspdm_context_t *context;
+     402                 :            : 
+     403                 :         15 :     context = spdm_context;
+     404         [ -  + ]:         15 :     if (context->spdm_key_update_callback != NULL) {
+     405                 :          0 :         ((libspdm_key_update_callback_func)
+     406                 :          0 :          context->spdm_key_update_callback)(context, session_id, key_update_op,
+     407                 :            :                                             key_update_action);
+     408                 :            :     }
+     409                 :         15 : }
+     410                 :            : 
+     411                 :            : /**
+     412                 :            :  * Build a SPDM response to a device.
+     413                 :            :  *
+     414                 :            :  * @param  spdm_context                  The SPDM context for the device.
+     415                 :            :  * @param  session_id                    Indicate if the response is a secured message.
+     416                 :            :  *                                     If session_id is NULL, it is a normal message.
+     417                 :            :  *                                     If session_id is NOT NULL, it is a secured message.
+     418                 :            :  * @param  is_app_message                 Indicates if it is an APP message or SPDM message.
+     419                 :            :  * @param  response_size                 size in bytes of the response data buffer.
+     420                 :            :  * @param  response                     A pointer to a destination buffer to store the response.
+     421                 :            :  *                                     The caller is responsible for having
+     422                 :            :  *                                     either implicit or explicit ownership of the buffer.
+     423                 :            :  *
+     424                 :            :  * @retval RETURN_SUCCESS               The SPDM response is sent successfully.
+     425                 :            :  * @retval RETURN_DEVICE_ERROR          A device error occurs when the SPDM response is sent to the device.
+     426                 :            :  * @retval RETURN_UNSUPPORTED           Just ignore this message: return UNSUPPORTED and clear response_size.
+     427                 :            :  *                                      Continue the dispatch without send response.
+     428                 :            :  **/
+     429                 :          4 : libspdm_return_t libspdm_build_response(void *spdm_context, const uint32_t *session_id,
+     430                 :            :                                         bool is_app_message,
+     431                 :            :                                         size_t *response_size,
+     432                 :            :                                         void **response)
+     433                 :            : {
+     434                 :            :     libspdm_context_t *context;
+     435                 :            :     uint8_t *my_response;
+     436                 :            :     size_t my_response_size;
+     437                 :            :     libspdm_return_t status;
+     438                 :            :     libspdm_get_spdm_response_func get_response_func;
+     439                 :            :     libspdm_session_info_t *session_info;
+     440                 :            :     spdm_message_header_t *spdm_request;
+     441                 :            :     spdm_message_header_t *spdm_response;
+     442                 :            :     size_t transport_header_size;
+     443                 :            :     uint8_t *scratch_buffer;
+     444                 :            :     size_t scratch_buffer_size;
+     445                 :            :     uint8_t request_response_code;
+     446                 :            :     uint32_t actual_size;
+     447                 :            : 
+     448                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_HBEAT_CAP
+     449                 :            :     bool result;
+     450                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_HBEAT_CAP */
+     451                 :            : 
+     452                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
+     453                 :            :     uint8_t *large_buffer;
+     454                 :            :     size_t large_buffer_size;
+     455                 :            :     libspdm_chunk_info_t* get_info;
+     456                 :            :     spdm_chunk_response_response_t *chunk_rsp;
+     457                 :            :     uint8_t *chunk_ptr;
+     458                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP */
+     459                 :            : 
+     460                 :          4 :     context = spdm_context;
+     461                 :          4 :     status = LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     462                 :            : 
+     463                 :            :     /* For secure message, setup my_response to scratch buffer
+     464                 :            :      * For non-secure message, setup my_response to sender buffer*/
+     465                 :          4 :     transport_header_size = context->local_context.capability.transport_header_size;
+     466         [ -  + ]:          4 :     if (session_id != NULL) {
+     467                 :          0 :         libspdm_get_scratch_buffer (context, (void **)&scratch_buffer, &scratch_buffer_size);
+     468                 :            :         #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
+     469                 :          0 :         my_response = scratch_buffer + libspdm_get_scratch_buffer_secure_message_offset(context) +
+     470                 :            :                       transport_header_size;
+     471                 :          0 :         my_response_size = libspdm_get_scratch_buffer_secure_message_capacity(context) -
+     472                 :          0 :                            transport_header_size -
+     473                 :          0 :                            context->local_context.capability.transport_tail_size;
+     474                 :            :         #else
+     475                 :            :         my_response = scratch_buffer + transport_header_size;
+     476                 :            :         my_response_size = scratch_buffer_size - transport_header_size -
+     477                 :            :                            context->local_context.capability.transport_tail_size;
+     478                 :            :         #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP */
+     479                 :            :     } else {
+     480                 :          4 :         my_response = (uint8_t *)*response + transport_header_size;
+     481                 :          4 :         my_response_size = *response_size - transport_header_size -
+     482                 :          4 :                            context->local_context.capability.transport_tail_size;
+     483                 :            :     }
+     484                 :          4 :     libspdm_zero_mem(my_response, my_response_size);
+     485                 :            : 
+     486                 :          4 :     spdm_response = (void *)my_response;
+     487                 :            : 
+     488         [ -  + ]:          4 :     if (context->last_spdm_error.error_code != 0) {
+     489                 :            : 
+     490                 :            :         /* Error in libspdm_process_request(), and we need send error message directly.*/
+     491                 :            : 
+     492      [ #  #  # ]:          0 :         switch (context->last_spdm_error.error_code) {
+     493                 :          0 :         case SPDM_ERROR_CODE_DECRYPT_ERROR:
+     494                 :            :             /* session ID is valid. Use it to encrypt the error message.*/
+     495         [ #  # ]:          0 :             if((context->handle_error_return_policy &
+     496                 :            :                 LIBSPDM_DATA_HANDLE_ERROR_RETURN_POLICY_DROP_ON_DECRYPT_ERROR) == 0) {
+     497                 :          0 :                 status = libspdm_generate_error_response(
+     498                 :            :                     context, SPDM_ERROR_CODE_DECRYPT_ERROR, 0,
+     499                 :            :                     &my_response_size, my_response);
+     500                 :            :             } else {
+     501                 :            :                 /**
+     502                 :            :                  * just ignore this message
+     503                 :            :                  * return UNSUPPORTED and clear response_size to continue the dispatch without send response
+     504                 :            :                  **/
+     505                 :          0 :                 *response_size = 0;
+     506                 :          0 :                 status = LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     507                 :            :             }
+     508                 :          0 :             break;
+     509                 :          0 :         case SPDM_ERROR_CODE_INVALID_SESSION:
+     510                 :            :             /**
+     511                 :            :              * don't use session ID, because we dont know which right session ID should be used.
+     512                 :            :              * just ignore this message
+     513                 :            :              * return UNSUPPORTED and clear response_size to continue the dispatch without send response
+     514                 :            :              **/
+     515                 :          0 :             *response_size = 0;
+     516                 :          0 :             status = LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     517                 :          0 :             break;
+     518                 :          0 :         default:
+     519                 :          0 :             LIBSPDM_ASSERT(false);
+     520                 :          0 :             status = LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     521                 :            :         }
+     522                 :            : 
+     523         [ #  # ]:          0 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     524         [ #  # ]:          0 :             if ((session_id != NULL) &&
+     525         [ #  # ]:          0 :                 (context->last_spdm_error.error_code == SPDM_ERROR_CODE_DECRYPT_ERROR)) {
+     526                 :          0 :                 libspdm_free_session_id(context, *session_id);
+     527                 :            :             }
+     528                 :          0 :             return status;
+     529                 :            :         }
+     530                 :            : 
+     531         [ #  # ]:          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "SpdmSendResponse[%x]: msg %s(0x%x), size (0x%zx): \n",
+     532                 :            :                        (session_id != NULL) ? *session_id : 0,
+     533                 :            :                        libspdm_get_code_str(spdm_response->request_response_code),
+     534                 :            :                        spdm_response->request_response_code,
+     535                 :            :                        my_response_size));
+     536                 :          0 :         LIBSPDM_INTERNAL_DUMP_HEX(my_response, my_response_size);
+     537                 :            : 
+     538                 :          0 :         status = context->transport_encode_message(
+     539                 :            :             context, session_id, false, false,
+     540                 :            :             my_response_size, my_response, response_size, response);
+     541         [ #  # ]:          0 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     542   [ #  #  #  # ]:          0 :             if ((session_id != NULL) &&
+     543         [ #  # ]:          0 :                 ((status == LIBSPDM_STATUS_SEQUENCE_NUMBER_OVERFLOW) ||
+     544                 :            :                  (status == LIBSPDM_STATUS_CRYPTO_ERROR))) {
+     545                 :          0 :                 libspdm_free_session_id(context, *session_id);
+     546                 :            :             }
+     547                 :          0 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "transport_encode_message : %xu\n", status));
+     548                 :          0 :             return status;
+     549                 :            :         }
+     550                 :            : 
+     551         [ #  # ]:          0 :         if ((session_id != NULL) &&
+     552         [ #  # ]:          0 :             (context->last_spdm_error.error_code == SPDM_ERROR_CODE_DECRYPT_ERROR)) {
+     553                 :          0 :             libspdm_free_session_id(context, *session_id);
+     554                 :            :         }
+     555                 :            : 
+     556                 :          0 :         libspdm_zero_mem(&context->last_spdm_error, sizeof(context->last_spdm_error));
+     557                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     558                 :            :     }
+     559                 :            : 
+     560         [ -  + ]:          4 :     if (session_id != NULL) {
+     561                 :          0 :         session_info = libspdm_get_session_info_via_session_id(context, *session_id);
+     562         [ #  # ]:          0 :         if (session_info == NULL) {
+     563                 :          0 :             LIBSPDM_ASSERT(false);
+     564                 :          0 :             return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     565                 :            :         }
+     566                 :            :     }
+     567                 :            : 
+     568         [ -  + ]:          4 :     if (*response == NULL) {
+     569                 :          0 :         return LIBSPDM_STATUS_INVALID_PARAMETER;
+     570                 :            :     }
+     571         [ -  + ]:          4 :     if (response_size == NULL) {
+     572                 :          0 :         return LIBSPDM_STATUS_INVALID_PARAMETER;
+     573                 :            :     }
+     574         [ -  + ]:          4 :     if (*response_size == 0) {
+     575                 :          0 :         return LIBSPDM_STATUS_INVALID_PARAMETER;
+     576                 :            :     }
+     577                 :            : 
+     578         [ -  + ]:          4 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "SpdmSendResponse[%x] ...\n",
+     579                 :            :                    (session_id != NULL) ? *session_id : 0));
+     580                 :            : 
+     581                 :          4 :     spdm_request = (void *)context->last_spdm_request;
+     582         [ -  + ]:          4 :     if (context->last_spdm_request_size == 0) {
+     583                 :          0 :         return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+     584                 :            :     }
+     585                 :            : 
+     586                 :          4 :     get_response_func = NULL;
+     587         [ +  - ]:          4 :     if (!is_app_message) {
+     588                 :          4 :         get_response_func = libspdm_get_response_func_via_last_request(context);
+     589                 :            : 
+     590                 :            :         #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
+     591                 :            :         /* If responder is expecting chunk_get or chunk_send requests
+     592                 :            :          * and gets other requests instead, drop out of chunking mode */
+     593         [ -  + ]:          4 :         if (context->chunk_context.get.chunk_in_use
+     594         [ #  # ]:          0 :             && get_response_func != libspdm_get_response_chunk_get) {
+     595                 :            : 
+     596                 :          0 :             context->chunk_context.get.chunk_in_use = false;
+     597                 :          0 :             context->chunk_context.get.chunk_handle++; /* implicit wrap - around to 0. */
+     598                 :          0 :             context->chunk_context.get.chunk_seq_no = 0;
+     599                 :            : 
+     600                 :          0 :             context->chunk_context.get.large_message = NULL;
+     601                 :          0 :             context->chunk_context.get.large_message_size = 0;
+     602                 :          0 :             context->chunk_context.get.chunk_bytes_transferred = 0;
+     603                 :            :         }
+     604         [ -  + ]:          4 :         if (context->chunk_context.send.chunk_in_use
+     605         [ #  # ]:          0 :             && get_response_func != libspdm_get_response_chunk_send) {
+     606                 :            : 
+     607                 :          0 :             context->chunk_context.send.chunk_in_use = false;
+     608                 :          0 :             context->chunk_context.send.chunk_handle = 0;
+     609                 :          0 :             context->chunk_context.send.chunk_seq_no = 0;
+     610                 :            : 
+     611                 :          0 :             context->chunk_context.send.large_message = NULL;
+     612                 :          0 :             context->chunk_context.send.large_message_size = 0;
+     613                 :          0 :             context->chunk_context.send.chunk_bytes_transferred = 0;
+     614                 :            :         }
+     615                 :            :         #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP */
+     616                 :            : 
+     617         [ +  - ]:          4 :         if (get_response_func != NULL) {
+     618                 :          4 :             status = get_response_func(
+     619                 :            :                 context,
+     620                 :            :                 context->last_spdm_request_size,
+     621                 :          4 :                 context->last_spdm_request,
+     622                 :            :                 &my_response_size, my_response);
+     623                 :            :         }
+     624                 :            :     }
+     625   [ +  -  -  + ]:          4 :     if (is_app_message || (get_response_func == NULL)) {
+     626         [ #  # ]:          0 :         if (context->get_response_func != NULL) {
+     627                 :          0 :             status = ((libspdm_get_response_func) context->get_response_func)(
+     628                 :            :                 context, session_id, is_app_message,
+     629                 :            :                 context->last_spdm_request_size,
+     630                 :          0 :                 context->last_spdm_request,
+     631                 :            :                 &my_response_size, my_response);
+     632                 :            :         } else {
+     633                 :          0 :             status = LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     634                 :            :         }
+     635                 :            :     }
+     636                 :            : 
+     637         [ +  - ]:          4 :     if (status == LIBSPDM_STATUS_SUCCESS) {
+     638         [ -  + ]:          4 :         LIBSPDM_ASSERT (my_response_size <= context->local_context.capability.max_spdm_msg_size);
+     639                 :            :         /* large SPDM message is the SPDM message whose size is greater than the DataTransferSize of the receiving
+     640                 :            :          * SPDM endpoint or greater than the transmit buffer size of the sending SPDM endpoint */
+     641         [ +  - ]:          4 :         if ((context->connection_info.capability.max_spdm_msg_size != 0) &&
+     642         [ +  + ]:          4 :             (my_response_size > context->connection_info.capability.max_spdm_msg_size)) {
+     643                 :          1 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR, "my_response_size > req max_spdm_msg_size\n"));
+     644                 :          1 :             actual_size = (uint32_t)my_response_size;
+     645                 :          1 :             status = libspdm_generate_extended_error_response(context,
+     646                 :            :                                                               SPDM_ERROR_CODE_RESPONSE_TOO_LARGE,
+     647                 :            :                                                               0,
+     648                 :            :                                                               sizeof(uint32_t),
+     649                 :            :                                                               (uint8_t *)&actual_size,
+     650                 :            :                                                               &my_response_size, my_response);
+     651         [ +  - ]:          3 :         } else if ((((context->connection_info.capability.data_transfer_size != 0) &&
+     652         [ +  + ]:          3 :                      (my_response_size > context->connection_info.capability.data_transfer_size)) ||
+     653         [ +  - ]:          2 :                     ((context->local_context.capability.sender_data_transfer_size != 0) &&
+     654                 :          2 :                      (my_response_size >
+     655   [ +  -  +  - ]:          5 :                       context->local_context.capability.sender_data_transfer_size))) &&
+     656                 :          3 :                    libspdm_is_capabilities_flag_supported(
+     657                 :            :                        context, false, SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP,
+     658                 :            :                        SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP)) {
+     659                 :            :             #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
+     660                 :            : 
+     661                 :          3 :             get_info = &context->chunk_context.get;
+     662                 :            : 
+     663                 :            :             /* Saving multiple large responses is not an expected use case.
+     664                 :            :              * Therefore, if the requester did not perform chunk_get requests for
+     665                 :            :              * previous large responses, they will be lost. */
+     666         [ -  + ]:          3 :             if (get_info->chunk_in_use) {
+     667                 :          0 :                 LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR,
+     668                 :            :                                "Warning: Overwriting previous unrequested chunk_get info.\n"));
+     669                 :            :             }
+     670                 :            : 
+     671                 :          3 :             libspdm_get_scratch_buffer(context, (void **)&scratch_buffer, &scratch_buffer_size);
+     672                 :            : 
+     673                 :            :             /* The first section of the scratch
+     674                 :            :              * buffer may be used for other purposes. Use only after that section. */
+     675                 :            : 
+     676                 :          6 :             large_buffer = (uint8_t*)scratch_buffer +
+     677                 :          3 :                            libspdm_get_scratch_buffer_large_message_offset(spdm_context);
+     678                 :          3 :             large_buffer_size = libspdm_get_scratch_buffer_large_message_capacity(spdm_context);
+     679                 :            : 
+     680                 :          3 :             get_info->chunk_in_use = true;
+     681                 :            :             /* Increment chunk_handle here as opposed to end of chunk_get handler
+     682                 :            :              * in case requester never issues chunk_get. */
+     683                 :          3 :             get_info->chunk_handle++;
+     684                 :          3 :             get_info->chunk_seq_no = 0;
+     685                 :          3 :             get_info->chunk_bytes_transferred = 0;
+     686                 :            : 
+     687                 :          3 :             libspdm_zero_mem(large_buffer, large_buffer_size);
+     688                 :            : 
+     689                 :            :             /* It's possible that the large response that was to be sent to the requester was
+     690                 :            :              * a CHUNK_SEND_ACK + non-chunk response. In this case, to prevent chunking within
+     691                 :            :              * chunking, only send back the actual response, by saving only non-chunk portion
+     692                 :            :              * in the scratch buffer, used to respond to the next CHUNK_GET request. */
+     693                 :          3 :             if (((spdm_message_header_t*) my_response)
+     694         [ -  + ]:          3 :                 ->request_response_code == SPDM_CHUNK_SEND_ACK) {
+     695                 :          0 :                 libspdm_copy_mem(large_buffer, large_buffer_size,
+     696                 :          0 :                                  my_response + sizeof(spdm_chunk_send_ack_response_t),
+     697                 :            :                                  my_response_size - sizeof(spdm_chunk_send_ack_response_t));
+     698                 :            : 
+     699                 :          0 :                 get_info->large_message = large_buffer;
+     700                 :          0 :                 get_info->large_message_size =
+     701                 :          0 :                     my_response_size - sizeof(spdm_chunk_send_ack_response_t);
+     702                 :            :             } else {
+     703                 :          3 :                 libspdm_copy_mem(large_buffer, large_buffer_size,
+     704                 :            :                                  my_response, my_response_size);
+     705                 :            : 
+     706                 :          3 :                 get_info->large_message = large_buffer;
+     707                 :          3 :                 get_info->large_message_size = my_response_size;
+     708                 :            :             }
+     709                 :            : 
+     710                 :          3 :             status = libspdm_generate_extended_error_response(context,
+     711                 :            :                                                               SPDM_ERROR_CODE_LARGE_RESPONSE, 0,
+     712                 :            :                                                               sizeof(uint8_t),
+     713                 :          3 :                                                               &get_info->chunk_handle,
+     714                 :            :                                                               &my_response_size, my_response);
+     715                 :            :             #else
+     716                 :            :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR,
+     717                 :            :                            "Warning: Could not save chunk. Scratch buffer too small.\n"));
+     718                 :            : 
+     719                 :            :             status = libspdm_generate_extended_error_response(context,
+     720                 :            :                                                               SPDM_ERROR_CODE_LARGE_RESPONSE,
+     721                 :            :                                                               0, 0, NULL,
+     722                 :            :                                                               &my_response_size, my_response);
+     723                 :            :             #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP */
+     724                 :            : 
+     725         [ -  + ]:          3 :             if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     726                 :          0 :                 return status;
+     727                 :            :             }
+     728                 :            :         }
+     729                 :            :     }
+     730                 :            : 
+     731                 :            :     /* if return the status: Responder drop the response
+     732                 :            :      * just ignore this message
+     733                 :            :      * return UNSUPPORTED and clear response_size to continue the dispatch without send response.*/
+     734   [ -  +  -  - ]:          4 :     if((my_response_size == 0) && (status == LIBSPDM_STATUS_UNSUPPORTED_CAP)) {
+     735                 :          0 :         *response_size = 0;
+     736                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     737                 :            :     }
+     738                 :            : 
+     739         [ -  + ]:          4 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     740                 :          0 :         status = libspdm_generate_error_response(
+     741                 :            :             context, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+     742                 :          0 :             spdm_request->request_response_code, &my_response_size,
+     743                 :            :             my_response);
+     744         [ #  # ]:          0 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     745                 :          0 :             return status;
+     746                 :            :         }
+     747                 :            :     }
+     748                 :            : 
+     749         [ -  + ]:          4 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "SpdmSendResponse[%x]: msg %s(0x%x), size (0x%zx): \n",
+     750                 :            :                    (session_id != NULL) ? *session_id : 0,
+     751                 :            :                    libspdm_get_code_str(spdm_response->request_response_code),
+     752                 :            :                    spdm_response->request_response_code,
+     753                 :            :                    my_response_size));
+     754                 :          4 :     LIBSPDM_INTERNAL_DUMP_HEX(my_response, my_response_size);
+     755                 :            : 
+     756                 :          4 :     status = context->transport_encode_message(
+     757                 :            :         context, session_id, is_app_message, false,
+     758                 :            :         my_response_size, my_response, response_size, response);
+     759         [ -  + ]:          4 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     760   [ #  #  #  # ]:          0 :         if ((session_id != NULL) &&
+     761         [ #  # ]:          0 :             ((status == LIBSPDM_STATUS_SEQUENCE_NUMBER_OVERFLOW) ||
+     762                 :            :              (status == LIBSPDM_STATUS_CRYPTO_ERROR))) {
+     763                 :          0 :             libspdm_free_session_id(context, *session_id);
+     764                 :            :         }
+     765                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "transport_encode_message : %xu\n", status));
+     766                 :          0 :         return status;
+     767                 :            :     }
+     768                 :            : 
+     769                 :          4 :     request_response_code = spdm_response->request_response_code;
+     770                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
+     771      [ -  -  + ]:          4 :     switch (request_response_code) {
+     772                 :          0 :     case SPDM_CHUNK_SEND_ACK:
+     773         [ #  # ]:          0 :         if (my_response_size > sizeof(spdm_chunk_send_ack_response_t)) {
+     774                 :          0 :             request_response_code =
+     775                 :          0 :                 ((spdm_message_header_t*)(my_response + sizeof(spdm_chunk_send_ack_response_t)))
+     776                 :            :                 ->request_response_code;
+     777                 :            :         }
+     778                 :          0 :         break;
+     779                 :          0 :     case SPDM_CHUNK_RESPONSE:
+     780                 :          0 :         chunk_rsp = (spdm_chunk_response_response_t *)my_response;
+     781                 :          0 :         chunk_ptr = (uint8_t*) (((uint32_t*) (chunk_rsp + 1)) + 1);
+     782         [ #  # ]:          0 :         if (chunk_rsp->chunk_seq_no == 0) {
+     783                 :          0 :             request_response_code = ((spdm_message_header_t*)chunk_ptr)->request_response_code;
+     784                 :            :         }
+     785                 :          0 :         break;
+     786                 :          4 :     default:
+     787                 :          4 :         break;
+     788                 :            :     }
+     789                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP */
+     790                 :            : 
+     791         [ -  + ]:          4 :     if (session_id != NULL) {
+     792   [ #  #  #  # ]:          0 :         switch (request_response_code) {
+     793                 :          0 :         case SPDM_FINISH_RSP:
+     794         [ #  # ]:          0 :             if (!libspdm_is_capabilities_flag_supported(
+     795                 :            :                     context, false,
+     796                 :            :                     SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP,
+     797                 :            :                     SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)) {
+     798                 :          0 :                 libspdm_set_session_state(
+     799                 :            :                     context, *session_id,
+     800                 :            :                     LIBSPDM_SESSION_STATE_ESTABLISHED);
+     801                 :            :             }
+     802                 :          0 :             break;
+     803                 :          0 :         case SPDM_PSK_FINISH_RSP:
+     804                 :          0 :             libspdm_set_session_state(context, *session_id,
+     805                 :            :                                       LIBSPDM_SESSION_STATE_ESTABLISHED);
+     806                 :          0 :             break;
+     807                 :          0 :         case SPDM_END_SESSION_ACK:
+     808                 :          0 :             libspdm_set_session_state(context, *session_id,
+     809                 :            :                                       LIBSPDM_SESSION_STATE_NOT_STARTED);
+     810                 :            :             #if LIBSPDM_ENABLE_CAPABILITY_HBEAT_CAP
+     811         [ #  # ]:          0 :             if (libspdm_is_capabilities_flag_supported(
+     812                 :            :                     context, false,
+     813                 :            :                     SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP,
+     814                 :            :                     SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP)) {
+     815                 :          0 :                 result = libspdm_stop_watchdog(*session_id);
+     816         [ #  # ]:          0 :                 if (!result) {
+     817                 :          0 :                     LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR, "libspdm_stop_watchdog error\n"));
+     818                 :            :                     /* No need to return error for internal watchdog error. */
+     819                 :            :                 }
+     820                 :            :             }
+     821                 :            :             #endif /* LIBSPDM_ENABLE_CAPABILITY_HBEAT_CAP */
+     822                 :          0 :             libspdm_free_session_id(context, *session_id);
+     823                 :          0 :             break;
+     824                 :          0 :         default:
+     825                 :            :             #if LIBSPDM_ENABLE_CAPABILITY_HBEAT_CAP
+     826         [ #  # ]:          0 :             if (libspdm_is_capabilities_flag_supported(
+     827                 :            :                     context, false,
+     828                 :            :                     SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP,
+     829                 :            :                     SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP)) {
+     830                 :            :                 /* reset watchdog in any session messages. */
+     831                 :          0 :                 result = libspdm_reset_watchdog(*session_id);
+     832         [ #  # ]:          0 :                 if (!result) {
+     833                 :          0 :                     LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR, "libspdm_reset_watchdog error\n"));
+     834                 :            :                     /* No need to return error for internal watchdog error. */
+     835                 :            :                 }
+     836                 :            :             }
+     837                 :            :             #endif /* LIBSPDM_ENABLE_CAPABILITY_HBEAT_CAP */
+     838                 :          0 :             break;
+     839                 :            :         }
+     840                 :            :     } else {
+     841         [ -  + ]:          4 :         switch (request_response_code) {
+     842                 :          0 :         case SPDM_FINISH_RSP:
+     843         [ #  # ]:          0 :             if (libspdm_is_capabilities_flag_supported(
+     844                 :            :                     context, false,
+     845                 :            :                     SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP,
+     846                 :            :                     SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)) {
+     847                 :          0 :                 libspdm_set_session_state(
+     848                 :            :                     context,
+     849                 :            :                     context->latest_session_id,
+     850                 :            :                     LIBSPDM_SESSION_STATE_ESTABLISHED);
+     851                 :            :             }
+     852                 :          0 :             break;
+     853                 :          4 :         default:
+     854                 :            :             /* No session state update needed */
+     855                 :          4 :             break;
+     856                 :            :         }
+     857                 :            :     }
+     858                 :            : 
+     859                 :          4 :     return LIBSPDM_STATUS_SUCCESS;
+     860                 :            : }
+     861                 :            : 
+     862                 :          0 : void libspdm_register_get_response_func(void *context, libspdm_get_response_func get_response_func)
+     863                 :            : {
+     864                 :            :     libspdm_context_t *spdm_context;
+     865                 :            : 
+     866                 :          0 :     spdm_context = context;
+     867                 :          0 :     spdm_context->get_response_func = (void *)get_response_func;
+     868                 :          0 : }
+     869                 :            : 
+     870                 :          0 : void libspdm_register_session_state_callback_func(
+     871                 :            :     void *spdm_context,
+     872                 :            :     libspdm_session_state_callback_func spdm_session_state_callback)
+     873                 :            : {
+     874                 :            :     libspdm_context_t *context;
+     875                 :            : 
+     876         [ #  # ]:          0 :     LIBSPDM_ASSERT(spdm_context != NULL);
+     877                 :            : 
+     878                 :          0 :     context = spdm_context;
+     879                 :            : 
+     880                 :          0 :     context->spdm_session_state_callback = (void *)spdm_session_state_callback;
+     881                 :          0 : }
+     882                 :            : 
+     883                 :          0 : void libspdm_register_connection_state_callback_func(
+     884                 :            :     void *spdm_context,
+     885                 :            :     libspdm_connection_state_callback_func spdm_connection_state_callback)
+     886                 :            : {
+     887                 :            :     libspdm_context_t *context;
+     888                 :            : 
+     889         [ #  # ]:          0 :     LIBSPDM_ASSERT(spdm_context != NULL);
+     890                 :            : 
+     891                 :          0 :     context = spdm_context;
+     892                 :          0 :     context->spdm_connection_state_callback = (void *)spdm_connection_state_callback;
+     893                 :          0 : }
+     894                 :            : 
+     895                 :          0 : void libspdm_register_key_update_callback_func(
+     896                 :            :     void *spdm_context, libspdm_key_update_callback_func spdm_key_update_callback)
+     897                 :            : {
+     898                 :            :     libspdm_context_t *context;
+     899                 :            : 
+     900         [ #  # ]:          0 :     LIBSPDM_ASSERT(spdm_context != NULL);
+     901                 :            : 
+     902                 :          0 :     context = spdm_context;
+     903                 :          0 :     context->spdm_key_update_callback = (void *)spdm_key_update_callback;
+     904                 :          0 : }
+     905                 :            : 
+     906                 :            : #if (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP) && \
+     907                 :            :     (LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT)
+     908                 :         89 : void libspdm_register_cert_chain_buffer(
+     909                 :            :     void *spdm_context, void *cert_chain_buffer, size_t cert_chain_buffer_max_size)
+     910                 :            : {
+     911                 :            :     libspdm_context_t *context;
+     912                 :            : 
+     913         [ -  + ]:         89 :     LIBSPDM_ASSERT(spdm_context != NULL);
+     914                 :            : 
+     915                 :         89 :     context = spdm_context;
+     916                 :         89 :     context->mut_auth_cert_chain_buffer = cert_chain_buffer;
+     917                 :         89 :     context->mut_auth_cert_chain_buffer_max_size = cert_chain_buffer_max_size;
+     918                 :         89 :     context->mut_auth_cert_chain_buffer_size = 0;
+     919                 :         89 : }
+     920                 :            : #endif
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_respond_if_ready.c.func-sort-c.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_respond_if_ready.c.func-sort-c.html new file mode 100644 index 00000000000..b87dd459001 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_respond_if_ready.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_respond_if_ready.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_respond_if_ready.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:202580.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:131872.2 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_response_respond_if_ready13
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_respond_if_ready.c.func.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_respond_if_ready.c.func.html new file mode 100644 index 00000000000..12aea1ecca9 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_respond_if_ready.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_respond_if_ready.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_respond_if_ready.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:202580.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:131872.2 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_response_respond_if_ready13
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_respond_if_ready.c.gcov.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_respond_if_ready.c.gcov.html new file mode 100644 index 00000000000..29a5ed1279d --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_respond_if_ready.c.gcov.html @@ -0,0 +1,160 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_respond_if_ready.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_respond_if_ready.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:202580.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:131872.2 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 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_responder_lib.h"
+       8                 :            : 
+       9                 :            : #if LIBSPDM_RESPOND_IF_READY_SUPPORT
+      10                 :            : 
+      11                 :         13 : libspdm_return_t libspdm_get_response_respond_if_ready(libspdm_context_t *spdm_context,
+      12                 :            :                                                        size_t request_size,
+      13                 :            :                                                        const void *request,
+      14                 :            :                                                        size_t *response_size,
+      15                 :            :                                                        void *response)
+      16                 :            : {
+      17                 :            :     const spdm_message_header_t *spdm_request;
+      18                 :            :     libspdm_get_spdm_response_func get_response_func;
+      19                 :            :     libspdm_return_t status;
+      20                 :            : 
+      21                 :         13 :     spdm_request = request;
+      22                 :            : 
+      23                 :            :     /* -=[Check Parameters Phase]=- */
+      24         [ -  + ]:         13 :     LIBSPDM_ASSERT(spdm_request->request_response_code == SPDM_RESPOND_IF_READY);
+      25                 :            : 
+      26         [ -  + ]:         13 :     if (spdm_request->spdm_version != libspdm_get_connection_version(spdm_context)) {
+      27                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      28                 :            :                                                SPDM_ERROR_CODE_VERSION_MISMATCH, 0,
+      29                 :            :                                                response_size, response);
+      30                 :            :     }
+      31         [ +  + ]:         13 :     if (spdm_context->response_state == LIBSPDM_RESPONSE_STATE_NEED_RESYNC ||
+      32         [ +  + ]:         12 :         spdm_context->response_state == LIBSPDM_RESPONSE_STATE_NOT_READY) {
+      33                 :          2 :         return libspdm_responder_handle_response_state(
+      34                 :          2 :             spdm_context, spdm_request->request_response_code,
+      35                 :            :             response_size, response);
+      36                 :            :     }
+      37                 :            : 
+      38         [ -  + ]:         11 :     if (request_size < sizeof(spdm_message_header_t)) {
+      39                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      40                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+      41                 :            :                                                response_size, response);
+      42                 :            :     }
+      43                 :            : 
+      44         [ +  + ]:         11 :     if (spdm_request->param1 != spdm_context->error_data.request_code) {
+      45                 :          1 :         return libspdm_generate_error_response(spdm_context,
+      46                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+      47                 :            :                                                response_size, response);
+      48                 :            :     }
+      49         [ -  + ]:         10 :     if (spdm_request->param1 == SPDM_RESPOND_IF_READY) {
+      50                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      51                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+      52                 :            :                                                response_size, response);
+      53                 :            :     }
+      54         [ +  + ]:         10 :     if (spdm_request->param2 != spdm_context->error_data.token) {
+      55                 :          1 :         return libspdm_generate_error_response(spdm_context,
+      56                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+      57                 :            :                                                response_size, response);
+      58                 :            :     }
+      59                 :            : 
+      60                 :          9 :     get_response_func = NULL;
+      61                 :          9 :     get_response_func = libspdm_get_response_func_via_request_code(spdm_request->param1);
+      62         [ -  + ]:          9 :     if (get_response_func == NULL) {
+      63                 :          0 :         return libspdm_generate_error_response(
+      64                 :            :             spdm_context, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+      65                 :          0 :             spdm_request->param1, response_size, response);
+      66                 :            :     }
+      67                 :          9 :     status = get_response_func(spdm_context,
+      68                 :            :                                spdm_context->cache_spdm_request_size,
+      69                 :          9 :                                spdm_context->cache_spdm_request,
+      70                 :            :                                response_size, response);
+      71                 :            : 
+      72                 :          9 :     return status;
+      73                 :            : }
+      74                 :            : 
+      75                 :            : #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_set_certificate.c.func-sort-c.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_set_certificate.c.func-sort-c.html new file mode 100644 index 00000000000..3c5b3b66104 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_set_certificate.c.func-sort-c.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_set_certificate.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_set_certificate.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:749379.6 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:517667.1 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_set_cert_verify_certchain7
libspdm_get_response_set_certificate13
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_set_certificate.c.func.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_set_certificate.c.func.html new file mode 100644 index 00000000000..a80279d051b --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_set_certificate.c.func.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_set_certificate.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_set_certificate.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:749379.6 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:517667.1 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_response_set_certificate13
libspdm_set_cert_verify_certchain7
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_set_certificate.c.gcov.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_set_certificate.c.gcov.html new file mode 100644 index 00000000000..bb3e5778d1a --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_set_certificate.c.gcov.html @@ -0,0 +1,383 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_set_certificate.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_set_certificate.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:749379.6 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:517667.1 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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_responder_lib.h"
+       8                 :            : 
+       9                 :            : #if LIBSPDM_ENABLE_CAPABILITY_SET_CERT_CAP
+      10                 :            : 
+      11                 :            : #if LIBSPDM_CERT_PARSE_SUPPORT
+      12                 :            : /*set_cert verify cert_chain*/
+      13                 :          7 : static bool libspdm_set_cert_verify_certchain(const uint8_t *cert_chain, size_t cert_chain_size,
+      14                 :            :                                               uint32_t base_asym_algo, uint32_t base_hash_algo,
+      15                 :            :                                               bool is_device_cert_model)
+      16                 :            : {
+      17                 :            :     const uint8_t *root_cert_buffer;
+      18                 :            :     size_t root_cert_buffer_size;
+      19                 :            :     const uint8_t *leaf_cert_buffer;
+      20                 :            :     size_t leaf_cert_buffer_size;
+      21                 :            : 
+      22                 :            :     /*get root cert*/
+      23         [ -  + ]:          7 :     if (!libspdm_x509_get_cert_from_cert_chain(
+      24                 :            :             cert_chain, cert_chain_size, 0, &root_cert_buffer,
+      25                 :            :             &root_cert_buffer_size)) {
+      26                 :          0 :         return false;
+      27                 :            :     }
+      28                 :            : 
+      29                 :            :     /*verify cert_chain*/
+      30         [ -  + ]:          7 :     if (!libspdm_x509_verify_cert_chain(root_cert_buffer, root_cert_buffer_size,
+      31                 :            :                                         cert_chain, cert_chain_size)) {
+      32                 :          0 :         return false;
+      33                 :            :     }
+      34                 :            : 
+      35                 :            :     /*get leaf cert*/
+      36         [ -  + ]:          7 :     if (!libspdm_x509_get_cert_from_cert_chain(
+      37                 :            :             cert_chain, cert_chain_size, -1, &leaf_cert_buffer,
+      38                 :            :             &leaf_cert_buffer_size)) {
+      39                 :          0 :         return false;
+      40                 :            :     }
+      41                 :            : 
+      42                 :            :     /*verify leaf cert*/
+      43         [ -  + ]:          7 :     if (!libspdm_x509_set_cert_certificate_check(leaf_cert_buffer, leaf_cert_buffer_size,
+      44                 :            :                                                  base_asym_algo, base_hash_algo,
+      45                 :            :                                                  false, is_device_cert_model)) {
+      46                 :          0 :         return false;
+      47                 :            :     }
+      48                 :            : 
+      49                 :          7 :     return true;
+      50                 :            : }
+      51                 :            : #endif /*LIBSPDM_CERT_PARSE_SUPPORT*/
+      52                 :            : 
+      53                 :         13 : libspdm_return_t libspdm_get_response_set_certificate(libspdm_context_t *spdm_context,
+      54                 :            :                                                       size_t request_size, const void *request,
+      55                 :            :                                                       size_t *response_size, void *response)
+      56                 :            : {
+      57                 :            :     const spdm_set_certificate_request_t *spdm_request;
+      58                 :            :     spdm_set_certificate_response_t *spdm_response;
+      59                 :            : 
+      60                 :            :     bool result;
+      61                 :            :     uint8_t slot_id;
+      62                 :            :     bool erase;
+      63                 :            : 
+      64                 :            :     size_t root_cert_hash_size;
+      65                 :            :     const spdm_cert_chain_t *cert_chain_header;
+      66                 :            :     size_t cert_chain_size;
+      67                 :            :     const void * cert_chain;
+      68                 :            : 
+      69                 :            :     libspdm_session_info_t *session_info;
+      70                 :            :     libspdm_session_state_t session_state;
+      71                 :            : 
+      72                 :            :     bool is_device_cert_model;
+      73                 :            : 
+      74                 :         13 :     spdm_request = request;
+      75                 :            : 
+      76                 :            :     /* -=[Check Parameters Phase]=- */
+      77         [ -  + ]:         13 :     LIBSPDM_ASSERT(spdm_request->header.request_response_code == SPDM_SET_CERTIFICATE);
+      78                 :            : 
+      79         [ -  + ]:         13 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_12) {
+      80                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      81                 :            :                                                SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+      82                 :            :                                                SPDM_SET_CERTIFICATE,
+      83                 :            :                                                response_size, response);
+      84                 :            :     }
+      85                 :            : 
+      86         [ -  + ]:         13 :     if (spdm_request->header.spdm_version != libspdm_get_connection_version(spdm_context)) {
+      87                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      88                 :            :                                                SPDM_ERROR_CODE_VERSION_MISMATCH, 0,
+      89                 :            :                                                response_size, response);
+      90                 :            :     }
+      91                 :            : 
+      92         [ +  + ]:         13 :     if (spdm_context->response_state != LIBSPDM_RESPONSE_STATE_NORMAL) {
+      93                 :          2 :         return libspdm_responder_handle_response_state(spdm_context,
+      94                 :          2 :                                                        spdm_request->header.request_response_code,
+      95                 :            :                                                        response_size, response);
+      96                 :            :     }
+      97                 :            : 
+      98         [ -  + ]:         11 :     if (spdm_context->connection_info.connection_state <
+      99                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
+     100                 :          0 :         return libspdm_generate_error_response(
+     101                 :            :             spdm_context,
+     102                 :            :             SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+     103                 :            :             response_size, response);
+     104                 :            :     }
+     105                 :            : 
+     106         [ +  + ]:         11 :     if (spdm_context->last_spdm_request_session_id_valid) {
+     107                 :          6 :         session_info = libspdm_get_session_info_via_session_id(
+     108                 :            :             spdm_context,
+     109                 :            :             spdm_context->last_spdm_request_session_id);
+     110         [ -  + ]:          6 :         if (session_info == NULL) {
+     111                 :          0 :             return libspdm_generate_error_response(
+     112                 :            :                 spdm_context,
+     113                 :            :                 SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+     114                 :            :                 response_size, response);
+     115                 :            :         }
+     116                 :          6 :         session_state = libspdm_secured_message_get_session_state(
+     117                 :            :             session_info->secured_message_context);
+     118         [ -  + ]:          6 :         if (session_state != LIBSPDM_SESSION_STATE_ESTABLISHED) {
+     119                 :          0 :             return libspdm_generate_error_response(
+     120                 :            :                 spdm_context,
+     121                 :            :                 SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+     122                 :            :                 response_size, response);
+     123                 :            :         }
+     124                 :            :     }
+     125                 :            : 
+     126         [ -  + ]:         11 :     if (!libspdm_is_capabilities_flag_supported(
+     127                 :            :             spdm_context, false, 0,
+     128                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_CERT_CAP)) {
+     129                 :          0 :         return libspdm_generate_error_response(
+     130                 :            :             spdm_context, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+     131                 :            :             SPDM_SET_CERTIFICATE, response_size, response);
+     132                 :            :     }
+     133                 :            : 
+     134                 :         11 :     slot_id = spdm_request->header.param1 & SPDM_SET_CERTIFICATE_REQUEST_SLOT_ID_MASK;
+     135         [ -  + ]:         11 :     if (slot_id >= SPDM_MAX_SLOT_COUNT) {
+     136                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     137                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     138                 :            :                                                response_size, response);
+     139                 :            :     }
+     140                 :            : 
+     141         [ +  + ]:         11 :     if ((!libspdm_is_in_trusted_environment(
+     142                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+     143                 :            :              spdm_context
+     144                 :            : #endif
+     145         [ +  + ]:         10 :              )) &&
+     146                 :          5 :         (slot_id != 0) &&
+     147         [ +  + ]:          5 :         (!spdm_context->last_spdm_request_session_id_valid)) {
+     148                 :          1 :         return libspdm_generate_error_response(spdm_context,
+     149                 :            :                                                SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+     150                 :            :                                                response_size, response);
+     151                 :            :     }
+     152                 :            : 
+     153                 :         10 :     root_cert_hash_size = libspdm_get_hash_size(
+     154                 :            :         spdm_context->connection_info.algorithm.base_hash_algo);
+     155                 :            : 
+     156         [ +  + ]:         10 :     if (libspdm_get_connection_version(spdm_context) >= SPDM_MESSAGE_VERSION_13) {
+     157                 :          3 :         const uint8_t set_cert_model =
+     158                 :          3 :             (spdm_request->header.param1 &
+     159                 :          3 :              SPDM_SET_CERTIFICATE_REQUEST_ATTRIBUTES_CERT_MODEL_MASK) >>
+     160                 :            :             SPDM_SET_CERTIFICATE_REQUEST_ATTRIBUTES_CERT_MODEL_OFFSET;
+     161                 :          3 :         const uint8_t key_pair_id = spdm_request->header.param2;
+     162                 :            : 
+     163                 :          3 :         erase = (spdm_request->header.param1 & SPDM_SET_CERTIFICATE_REQUEST_ATTRIBUTES_ERASE) != 0;
+     164                 :            : 
+     165         [ +  + ]:          3 :         if (spdm_context->connection_info.multi_key_conn_rsp) {
+     166         [ -  + ]:          2 :             if (key_pair_id == 0) {
+     167                 :          0 :                 return libspdm_generate_error_response(spdm_context,
+     168                 :            :                                                        SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     169                 :            :                                                        response_size, response);
+     170                 :            :             }
+     171         [ +  - ]:          2 :             if (!erase) {
+     172   [ +  +  -  + ]:          2 :                 if ((set_cert_model == SPDM_CERTIFICATE_INFO_CERT_MODEL_NONE) ||
+     173                 :            :                     (set_cert_model > SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT)) {
+     174                 :          1 :                     return libspdm_generate_error_response(spdm_context,
+     175                 :            :                                                            SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     176                 :            :                                                            response_size, response);
+     177                 :            :                 }
+     178                 :            :             }
+     179                 :            :         } else {
+     180   [ +  -  -  + ]:          1 :             if ((key_pair_id != 0) || (set_cert_model != 0)) {
+     181                 :          0 :                 return libspdm_generate_error_response(spdm_context,
+     182                 :            :                                                        SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     183                 :            :                                                        response_size, response);
+     184                 :            :             }
+     185                 :            :         }
+     186                 :            :     }
+     187                 :            : 
+     188   [ +  +  +  + ]:          9 :     if ((libspdm_get_connection_version(spdm_context) >= SPDM_MESSAGE_VERSION_13) && erase) {
+     189                 :            :         /*the CertChain field shall be absent;the value of SetCertModel shall be zero*/
+     190         [ +  - ]:          1 :         if ((request_size < sizeof(spdm_set_certificate_request_t)) ||
+     191         [ -  + ]:          1 :             ((spdm_request->header.param1 &
+     192                 :            :               SPDM_SET_CERTIFICATE_REQUEST_ATTRIBUTES_CERT_MODEL_MASK) != 0)) {
+     193                 :          0 :             return libspdm_generate_error_response(spdm_context,
+     194                 :            :                                                    SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     195                 :            :                                                    response_size, response);
+     196                 :            :         }
+     197                 :            : 
+     198                 :            :         /* erase slot_id cert_chain*/
+     199                 :          1 :         result = libspdm_write_certificate_to_nvm(
+     200                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+     201                 :            :             spdm_context,
+     202                 :            : #endif
+     203                 :            :             slot_id, NULL, 0, 0, 0);
+     204         [ -  + ]:          1 :         if (!result) {
+     205                 :          0 :             return libspdm_generate_error_response(spdm_context,
+     206                 :            :                                                    SPDM_ERROR_CODE_OPERATION_FAILED, 0,
+     207                 :            :                                                    response_size, response);
+     208                 :            :         }
+     209                 :            :     } else {
+     210                 :          8 :         if (request_size < sizeof(spdm_set_certificate_request_t) +
+     211         [ +  + ]:          8 :             sizeof(spdm_cert_chain_t) + root_cert_hash_size) {
+     212                 :          1 :             return libspdm_generate_error_response(spdm_context,
+     213                 :            :                                                    SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     214                 :            :                                                    response_size, response);
+     215                 :            :         }
+     216                 :            : 
+     217                 :            :         /*point to full SPDM certificate chain*/
+     218                 :          7 :         cert_chain = (const void*)(spdm_request + 1);
+     219                 :          7 :         cert_chain_header = cert_chain;
+     220                 :            : 
+     221         [ -  + ]:          7 :         if (cert_chain_header->length < sizeof(spdm_cert_chain_t) + root_cert_hash_size) {
+     222                 :          0 :             return libspdm_generate_error_response(spdm_context,
+     223                 :            :                                                    SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     224                 :            :                                                    response_size, response);
+     225                 :            :         }
+     226         [ -  + ]:          7 :         if (cert_chain_header->length > request_size - sizeof(spdm_set_certificate_request_t)) {
+     227                 :          0 :             return libspdm_generate_error_response(spdm_context,
+     228                 :            :                                                    SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     229                 :            :                                                    response_size, response);
+     230                 :            :         }
+     231                 :            : 
+     232                 :            :         /*get actual cert_chain size*/
+     233                 :          7 :         cert_chain_size = cert_chain_header->length - sizeof(spdm_cert_chain_t) -
+     234                 :            :                           root_cert_hash_size;
+     235                 :            : 
+     236                 :            :         /*point to actual cert_chain*/
+     237                 :          7 :         cert_chain = (const void*)((const uint8_t *)cert_chain
+     238                 :          7 :                                    + sizeof(spdm_cert_chain_t) + root_cert_hash_size);
+     239                 :            : 
+     240                 :          7 :         is_device_cert_model = false;
+     241         [ +  + ]:          7 :         if((spdm_context->local_context.capability.flags &
+     242                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ALIAS_CERT_CAP) == 0) {
+     243                 :          6 :             is_device_cert_model = true;
+     244                 :            :         }
+     245                 :            : 
+     246                 :            : #if LIBSPDM_CERT_PARSE_SUPPORT
+     247                 :            :         /*check the cert_chain*/
+     248                 :          7 :         result = libspdm_set_cert_verify_certchain(cert_chain, cert_chain_size,
+     249                 :            :                                                    spdm_context->connection_info.algorithm.base_asym_algo,
+     250                 :            :                                                    spdm_context->connection_info.algorithm.base_hash_algo,
+     251                 :            :                                                    is_device_cert_model);
+     252         [ -  + ]:          7 :         if (!result) {
+     253                 :          0 :             return libspdm_generate_error_response(spdm_context,
+     254                 :            :                                                    SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     255                 :            :                                                    response_size, response);
+     256                 :            :         }
+     257                 :            : #endif /*LIBSPDM_CERT_PARSE_SUPPORT*/
+     258                 :            : 
+     259                 :            :         /* set certificate to NV*/
+     260                 :          7 :         result = libspdm_write_certificate_to_nvm(
+     261                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+     262                 :            :             spdm_context,
+     263                 :            : #endif
+     264                 :            :             slot_id, cert_chain,
+     265                 :            :             cert_chain_size,
+     266                 :            :             spdm_context->connection_info.algorithm.base_hash_algo,
+     267                 :            :             spdm_context->connection_info.algorithm.base_asym_algo);
+     268         [ -  + ]:          7 :         if (!result) {
+     269                 :          0 :             return libspdm_generate_error_response(spdm_context,
+     270                 :            :                                                    SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     271                 :            :                                                    response_size, response);
+     272                 :            :         }
+     273                 :            :     }
+     274                 :            : 
+     275         [ -  + ]:          8 :     LIBSPDM_ASSERT(*response_size >= sizeof(spdm_set_certificate_response_t));
+     276                 :          8 :     *response_size = sizeof(spdm_set_certificate_response_t);
+     277                 :          8 :     libspdm_zero_mem(response, *response_size);
+     278                 :          8 :     spdm_response = response;
+     279                 :            : 
+     280                 :            :     /*requires a reset to complete the SET_CERTIFICATE request*/
+     281         [ +  + ]:          8 :     if (libspdm_is_capabilities_flag_supported(
+     282                 :            :             spdm_context, false, 0,
+     283                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_INSTALL_RESET_CAP)) {
+     284                 :            :         /*the device will reset to set cert*/
+     285                 :          1 :         return libspdm_generate_error_response(spdm_context,
+     286                 :            :                                                SPDM_ERROR_CODE_RESET_REQUIRED, 0,
+     287                 :            :                                                response_size, response);
+     288                 :            :     } else {
+     289                 :          7 :         spdm_response->header.spdm_version = spdm_request->header.spdm_version;
+     290                 :          7 :         spdm_response->header.request_response_code = SPDM_SET_CERTIFICATE_RSP;
+     291                 :          7 :         spdm_response->header.param1 = slot_id;
+     292                 :          7 :         spdm_response->header.param2 = 0;
+     293                 :            :     }
+     294                 :            : 
+     295                 :          7 :     return LIBSPDM_STATUS_SUCCESS;
+     296                 :            : }
+     297                 :            : 
+     298                 :            : #endif /*LIBSPDM_ENABLE_CAPABILITY_SET_CERT_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_set_key_pair_info_ack.c.func-sort-c.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_set_key_pair_info_ack.c.func-sort-c.html new file mode 100644 index 00000000000..b7010e4744a --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_set_key_pair_info_ack.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_set_key_pair_info_ack.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_set_key_pair_info_ack.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:608769.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:408050.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_response_set_key_pair_info_ack14
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_set_key_pair_info_ack.c.func.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_set_key_pair_info_ack.c.func.html new file mode 100644 index 00000000000..404d3815efa --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_set_key_pair_info_ack.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_set_key_pair_info_ack.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_set_key_pair_info_ack.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:608769.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:408050.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_response_set_key_pair_info_ack14
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_set_key_pair_info_ack.c.gcov.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_set_key_pair_info_ack.c.gcov.html new file mode 100644 index 00000000000..96e480e12ba --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_set_key_pair_info_ack.c.gcov.html @@ -0,0 +1,350 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_set_key_pair_info_ack.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_set_key_pair_info_ack.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:608769.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:408050.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2024 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_responder_lib.h"
+       8                 :            : 
+       9                 :            : #if LIBSPDM_ENABLE_CAPABILITY_SET_KEY_PAIR_INFO_CAP
+      10                 :            : 
+      11                 :         14 : libspdm_return_t libspdm_get_response_set_key_pair_info_ack(libspdm_context_t *spdm_context,
+      12                 :            :                                                             size_t request_size,
+      13                 :            :                                                             const void *request,
+      14                 :            :                                                             size_t *response_size,
+      15                 :            :                                                             void *response)
+      16                 :            : {
+      17                 :            :     const spdm_set_key_pair_info_request_t *spdm_request;
+      18                 :            :     spdm_set_key_pair_info_ack_response_t *spdm_response;
+      19                 :            : 
+      20                 :            :     libspdm_session_info_t *session_info;
+      21                 :            :     libspdm_session_state_t session_state;
+      22                 :            : 
+      23                 :            :     uint16_t capabilities;
+      24                 :            :     uint16_t key_usage_capabilities;
+      25                 :            :     uint16_t current_key_usage;
+      26                 :            :     uint32_t asym_algo_capabilities;
+      27                 :            :     uint32_t current_asym_algo;
+      28                 :            :     uint8_t assoc_cert_slot_mask;
+      29                 :            :     uint8_t key_pair_id;
+      30                 :            :     uint8_t total_key_pairs;
+      31                 :            :     bool result;
+      32                 :            : 
+      33                 :            :     uint16_t desired_key_usage;
+      34                 :            :     uint32_t desired_asym_algo;
+      35                 :            :     uint8_t desired_assoc_cert_slot_mask;
+      36                 :            :     uint8_t operation;
+      37                 :            :     bool need_reset;
+      38                 :            :     const uint8_t *ptr;
+      39                 :            : 
+      40                 :         14 :     spdm_request = request;
+      41                 :            : 
+      42                 :            :     /* -=[Check Parameters Phase]=- */
+      43         [ -  + ]:         14 :     LIBSPDM_ASSERT(spdm_request->header.request_response_code == SPDM_SET_KEY_PAIR_INFO);
+      44                 :            : 
+      45         [ -  + ]:         14 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_13) {
+      46                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      47                 :            :                                                SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+      48                 :            :                                                SPDM_SET_KEY_PAIR_INFO,
+      49                 :            :                                                response_size, response);
+      50                 :            :     }
+      51                 :            : 
+      52         [ -  + ]:         14 :     if (spdm_request->header.spdm_version != libspdm_get_connection_version(spdm_context)) {
+      53                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      54                 :            :                                                SPDM_ERROR_CODE_VERSION_MISMATCH, 0,
+      55                 :            :                                                response_size, response);
+      56                 :            :     }
+      57                 :            : 
+      58         [ -  + ]:         14 :     if (spdm_context->response_state != LIBSPDM_RESPONSE_STATE_NORMAL) {
+      59                 :          0 :         return libspdm_responder_handle_response_state(spdm_context,
+      60                 :          0 :                                                        spdm_request->header.request_response_code,
+      61                 :            :                                                        response_size, response);
+      62                 :            :     }
+      63                 :            : 
+      64         [ -  + ]:         14 :     if (request_size < sizeof(spdm_set_key_pair_info_request_t)) {
+      65                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      66                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+      67                 :            :                                                response_size, response);
+      68                 :            :     }
+      69                 :            : 
+      70         [ -  + ]:         14 :     if (spdm_context->connection_info.connection_state <
+      71                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
+      72                 :          0 :         return libspdm_generate_error_response(
+      73                 :            :             spdm_context,
+      74                 :            :             SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+      75                 :            :             response_size, response);
+      76                 :            :     }
+      77                 :            : 
+      78         [ -  + ]:         14 :     if (spdm_context->last_spdm_request_session_id_valid) {
+      79                 :          0 :         session_info = libspdm_get_session_info_via_session_id(
+      80                 :            :             spdm_context,
+      81                 :            :             spdm_context->last_spdm_request_session_id);
+      82         [ #  # ]:          0 :         if (session_info == NULL) {
+      83                 :          0 :             return libspdm_generate_error_response(
+      84                 :            :                 spdm_context,
+      85                 :            :                 SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+      86                 :            :                 response_size, response);
+      87                 :            :         }
+      88                 :          0 :         session_state = libspdm_secured_message_get_session_state(
+      89                 :            :             session_info->secured_message_context);
+      90         [ #  # ]:          0 :         if (session_state != LIBSPDM_SESSION_STATE_ESTABLISHED) {
+      91                 :          0 :             return libspdm_generate_error_response(
+      92                 :            :                 spdm_context,
+      93                 :            :                 SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+      94                 :            :                 response_size, response);
+      95                 :            :         }
+      96                 :            :     }
+      97                 :            : 
+      98         [ -  + ]:         14 :     if (!libspdm_is_capabilities_flag_supported(
+      99                 :            :             spdm_context, false, 0,
+     100                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_KEY_PAIR_INFO_CAP)) {
+     101                 :          0 :         return libspdm_generate_error_response(
+     102                 :            :             spdm_context, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+     103                 :            :             SPDM_SET_KEY_PAIR_INFO, response_size, response);
+     104                 :            :     }
+     105                 :            : 
+     106                 :         14 :     total_key_pairs = spdm_context->local_context.total_key_pairs;
+     107                 :         14 :     key_pair_id = spdm_request->key_pair_id;
+     108   [ +  +  -  + ]:         14 :     if ((key_pair_id == 0) || (key_pair_id > total_key_pairs)) {
+     109                 :          1 :         return libspdm_generate_error_response(spdm_context,
+     110                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     111                 :            :                                                response_size, response);
+     112                 :            :     }
+     113                 :            : 
+     114         [ -  + ]:         13 :     LIBSPDM_ASSERT(*response_size >= sizeof(spdm_set_key_pair_info_ack_response_t));
+     115                 :            : 
+     116                 :         13 :     libspdm_zero_mem(response, *response_size);
+     117                 :            : 
+     118                 :         13 :     result = libspdm_read_key_pair_info(
+     119                 :            :         spdm_context,
+     120                 :            :         key_pair_id,
+     121                 :            :         &capabilities,
+     122                 :            :         &key_usage_capabilities,
+     123                 :            :         &current_key_usage,
+     124                 :            :         &asym_algo_capabilities,
+     125                 :            :         &current_asym_algo,
+     126                 :            :         &assoc_cert_slot_mask,
+     127                 :            :         NULL, NULL);
+     128         [ -  + ]:         13 :     if (!result) {
+     129                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     130                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     131                 :            :                                                response_size, response);
+     132                 :            :     }
+     133                 :            : 
+     134                 :         13 :     operation = spdm_request->header.param1;
+     135                 :            : 
+     136         [ +  + ]:         13 :     if (operation != SPDM_SET_KEY_PAIR_INFO_ERASE_OPERATION) {
+     137         [ +  + ]:          9 :         if (request_size < sizeof(spdm_set_key_pair_info_request_t) +
+     138                 :            :             sizeof(uint8_t) + sizeof(uint16_t) + sizeof(uint32_t) + sizeof(uint8_t)) {
+     139                 :          1 :             return libspdm_generate_error_response(spdm_context,
+     140                 :            :                                                    SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     141                 :            :                                                    response_size, response);
+     142                 :            :         }
+     143                 :            : 
+     144                 :          8 :         ptr = (const uint8_t*)(spdm_request + 1);
+     145                 :          8 :         ptr += sizeof(uint8_t);
+     146                 :            : 
+     147                 :          8 :         desired_key_usage = libspdm_read_uint16((const uint8_t *)ptr);
+     148                 :          8 :         ptr += sizeof(uint16_t);
+     149                 :            : 
+     150                 :          8 :         desired_asym_algo = libspdm_read_uint32((const uint8_t *)ptr);
+     151                 :          8 :         ptr += sizeof(uint32_t);
+     152                 :            : 
+     153                 :          8 :         desired_assoc_cert_slot_mask = *ptr;
+     154                 :            :     } else {
+     155                 :          4 :         desired_key_usage = 0;
+     156                 :          4 :         desired_asym_algo = 0;
+     157                 :          4 :         desired_assoc_cert_slot_mask = 0;
+     158                 :            :     }
+     159                 :            : 
+     160   [ -  +  -  - ]:         12 :     if (((capabilities & SPDM_KEY_PAIR_CAP_GEN_KEY_CAP) == 0) &&
+     161                 :            :         (operation == SPDM_SET_KEY_PAIR_INFO_GENERATE_OPERATION)) {
+     162                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     163                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     164                 :            :                                                response_size, response);
+     165                 :            :     }
+     166   [ -  +  -  - ]:         12 :     if (((capabilities & SPDM_KEY_PAIR_CAP_ERASABLE_CAP) == 0) &&
+     167                 :            :         (operation == SPDM_SET_KEY_PAIR_INFO_ERASE_OPERATION)) {
+     168                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     169                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     170                 :            :                                                response_size, response);
+     171                 :            :     }
+     172   [ -  +  -  - ]:         12 :     if (((capabilities & SPDM_KEY_PAIR_CAP_CERT_ASSOC_CAP) == 0) &&
+     173                 :          0 :         (desired_assoc_cert_slot_mask != 0) &&
+     174         [ #  # ]:          0 :         (desired_assoc_cert_slot_mask != assoc_cert_slot_mask)) {
+     175                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     176                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     177                 :            :                                                response_size, response);
+     178                 :            :     }
+     179                 :            : 
+     180   [ -  +  -  - ]:         12 :     if (((capabilities & SPDM_KEY_PAIR_CAP_KEY_USAGE_CAP) == 0) && (desired_key_usage != 0)) {
+     181                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     182                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     183                 :            :                                                response_size, response);
+     184                 :            :     }
+     185         [ +  + ]:         12 :     if ((desired_key_usage != 0) &&
+     186         [ -  + ]:          4 :         ((key_usage_capabilities | desired_key_usage) != key_usage_capabilities)) {
+     187                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     188                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     189                 :            :                                                response_size, response);
+     190                 :            :     }
+     191                 :            : 
+     192   [ -  +  -  - ]:         12 :     if (((capabilities & SPDM_KEY_PAIR_CAP_ASYM_ALGO_CAP) == 0) && (desired_asym_algo != 0)) {
+     193                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     194                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     195                 :            :                                                response_size, response);
+     196                 :            :     }
+     197         [ +  + ]:         12 :     if(!libspdm_onehot0(desired_asym_algo)) {
+     198                 :          1 :         return libspdm_generate_error_response(spdm_context,
+     199                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     200                 :            :                                                response_size, response);
+     201                 :            :     }
+     202         [ +  + ]:         11 :     if ((desired_asym_algo != 0) &&
+     203         [ -  + ]:          3 :         ((asym_algo_capabilities | desired_asym_algo) != asym_algo_capabilities)) {
+     204                 :          0 :         return libspdm_generate_error_response(
+     205                 :            :             spdm_context, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+     206                 :            :             SPDM_SET_KEY_PAIR_INFO, response_size, response);
+     207                 :            :     }
+     208                 :            : 
+     209         [ -  + ]:         11 :     if (((capabilities & SPDM_KEY_PAIR_CAP_SHAREABLE_CAP) == 0) &&
+     210         [ #  # ]:          0 :         (!libspdm_onehot0(desired_assoc_cert_slot_mask))) {
+     211                 :          0 :         return libspdm_generate_error_response(
+     212                 :            :             spdm_context, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+     213                 :            :             SPDM_SET_KEY_PAIR_INFO, response_size, response);
+     214                 :            :     }
+     215                 :            : 
+     216         [ -  + ]:         11 :     if (operation > SPDM_SET_KEY_PAIR_INFO_GENERATE_OPERATION) {
+     217                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     218                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     219                 :            :                                                response_size, response);
+     220                 :            :     }
+     221                 :            : 
+     222   [ +  +  -  + ]:         11 :     if ((operation == SPDM_SET_KEY_PAIR_INFO_ERASE_OPERATION) ||
+     223                 :            :         (operation == SPDM_SET_KEY_PAIR_INFO_GENERATE_OPERATION)) {
+     224         [ +  + ]:          4 :         if (assoc_cert_slot_mask != 0) {
+     225                 :          1 :             return libspdm_generate_error_response(spdm_context,
+     226                 :            :                                                    SPDM_ERROR_CODE_OPERATION_FAILED, 0,
+     227                 :            :                                                    response_size, response);
+     228                 :            :         }
+     229                 :            :     }
+     230                 :            : 
+     231                 :         10 :     need_reset = libspdm_is_capabilities_flag_supported(
+     232                 :            :         spdm_context, false, 0,
+     233                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_INSTALL_RESET_CAP);
+     234                 :         10 :     result = libspdm_write_key_pair_info(
+     235                 :            :         spdm_context,
+     236                 :            :         key_pair_id,
+     237                 :            :         operation,
+     238                 :            :         desired_key_usage,
+     239                 :            :         desired_asym_algo,
+     240                 :            :         desired_assoc_cert_slot_mask,
+     241                 :            :         &need_reset);
+     242         [ -  + ]:         10 :     if (!result) {
+     243                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     244                 :            :                                                SPDM_ERROR_CODE_OPERATION_FAILED, 0,
+     245                 :            :                                                response_size, response);
+     246                 :            :     }
+     247                 :            : 
+     248                 :         10 :     spdm_response = response;
+     249                 :         10 :     *response_size = sizeof(spdm_set_key_pair_info_ack_response_t);
+     250                 :            : 
+     251         [ +  + ]:         10 :     if (need_reset) {
+     252                 :          4 :         return libspdm_generate_error_response(spdm_context,
+     253                 :            :                                                SPDM_ERROR_CODE_RESET_REQUIRED, 0,
+     254                 :            :                                                response_size, response);
+     255                 :            :     } else {
+     256                 :          6 :         spdm_response->header.spdm_version = spdm_request->header.spdm_version;
+     257                 :          6 :         spdm_response->header.request_response_code = SPDM_SET_KEY_PAIR_INFO_ACK;
+     258                 :          6 :         spdm_response->header.param1 = 0;
+     259                 :          6 :         spdm_response->header.param2 = 0;
+     260                 :            :     }
+     261                 :            : 
+     262                 :          6 :     return LIBSPDM_STATUS_SUCCESS;
+     263                 :            : }
+     264                 :            : 
+     265                 :            : #endif /*LIBSPDM_ENABLE_CAPABILITY_SET_KEY_PAIR_INFO_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_subscribe_event_types_ack.c.func-sort-c.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_subscribe_event_types_ack.c.func-sort-c.html new file mode 100644 index 00000000000..0fbab351865 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_subscribe_event_types_ack.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_subscribe_event_types_ack.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_subscribe_event_types_ack.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:405375.5 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:243863.2 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_response_subscribe_event_types_ack4
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_subscribe_event_types_ack.c.func.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_subscribe_event_types_ack.c.func.html new file mode 100644 index 00000000000..2af7ebfbfaf --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_subscribe_event_types_ack.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_subscribe_event_types_ack.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_subscribe_event_types_ack.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:405375.5 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:243863.2 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_response_subscribe_event_types_ack4
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_subscribe_event_types_ack.c.gcov.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_subscribe_event_types_ack.c.gcov.html new file mode 100644 index 00000000000..e6e37c83048 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_subscribe_event_types_ack.c.gcov.html @@ -0,0 +1,235 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_subscribe_event_types_ack.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_subscribe_event_types_ack.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:405375.5 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:243863.2 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2024 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_responder_lib.h"
+       8                 :            : #include "internal/libspdm_secured_message_lib.h"
+       9                 :            : 
+      10                 :            : #if LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP
+      11                 :            : 
+      12                 :          4 : libspdm_return_t libspdm_get_response_subscribe_event_types_ack(libspdm_context_t *spdm_context,
+      13                 :            :                                                                 size_t request_size,
+      14                 :            :                                                                 const void *request,
+      15                 :            :                                                                 size_t *response_size,
+      16                 :            :                                                                 void *response)
+      17                 :            : {
+      18                 :            :     spdm_subscribe_event_types_ack_response_t *spdm_response;
+      19                 :            :     const spdm_subscribe_event_types_request_t *spdm_request;
+      20                 :          4 :     const size_t response_buffer_size = *response_size;
+      21                 :            :     uint32_t session_id;
+      22                 :            :     libspdm_session_info_t *session_info;
+      23                 :            :     libspdm_session_state_t session_state;
+      24                 :            :     uint8_t subscribe_event_group_count;
+      25                 :            :     uint32_t subscribe_list_len;
+      26                 :            :     const void *subscribe_list;
+      27                 :            : 
+      28                 :          4 :     spdm_request = request;
+      29                 :            : 
+      30                 :            :     /* -=[Check Parameters Phase]=- */
+      31         [ -  + ]:          4 :     LIBSPDM_ASSERT(spdm_request->header.request_response_code == SPDM_SUBSCRIBE_EVENT_TYPES);
+      32                 :            : 
+      33                 :            :     /* -=[Verify State Phase]=- */
+      34         [ -  + ]:          4 :     if (spdm_context->response_state != LIBSPDM_RESPONSE_STATE_NORMAL) {
+      35                 :          0 :         return libspdm_responder_handle_response_state(
+      36                 :            :             spdm_context,
+      37                 :          0 :             spdm_request->header.request_response_code,
+      38                 :            :             response_size, response);
+      39                 :            :     }
+      40         [ -  + ]:          4 :     if (spdm_context->connection_info.connection_state < LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
+      41                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      42                 :            :                                                SPDM_ERROR_CODE_UNEXPECTED_REQUEST,
+      43                 :            :                                                0, response_size, response);
+      44                 :            :     }
+      45         [ +  + ]:          4 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_13) {
+      46                 :          1 :         return libspdm_generate_error_response(spdm_context,
+      47                 :            :                                                SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+      48                 :            :                                                SPDM_SUBSCRIBE_EVENT_TYPES,
+      49                 :            :                                                response_size, response);
+      50                 :            :     }
+      51         [ +  + ]:          3 :     if (!libspdm_is_capabilities_flag_supported(
+      52                 :            :             spdm_context, false,
+      53                 :            :             0, SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EVENT_CAP)) {
+      54                 :          1 :         return libspdm_generate_error_response(
+      55                 :            :             spdm_context, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+      56                 :            :             SPDM_SUBSCRIBE_EVENT_TYPES, response_size, response);
+      57                 :            :     }
+      58         [ -  + ]:          2 :     if (!spdm_context->last_spdm_request_session_id_valid) {
+      59                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      60                 :            :                                                SPDM_ERROR_CODE_SESSION_REQUIRED, 0,
+      61                 :            :                                                response_size, response);
+      62                 :            :     }
+      63                 :          2 :     session_id = spdm_context->last_spdm_request_session_id;
+      64                 :          2 :     session_info = libspdm_get_session_info_via_session_id(spdm_context, session_id);
+      65         [ -  + ]:          2 :     if (session_info == NULL) {
+      66                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      67                 :            :                                                SPDM_ERROR_CODE_SESSION_REQUIRED, 0,
+      68                 :            :                                                response_size, response);
+      69                 :            :     }
+      70                 :          2 :     session_state = libspdm_secured_message_get_session_state(
+      71                 :            :         session_info->secured_message_context);
+      72         [ -  + ]:          2 :     if (session_state != LIBSPDM_SESSION_STATE_ESTABLISHED) {
+      73                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      74                 :            :                                                SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+      75                 :            :                                                response_size, response);
+      76                 :            :     }
+      77                 :            : 
+      78                 :            :     /* -=[Validate Request Phase]=- */
+      79         [ -  + ]:          2 :     if (request_size < sizeof(spdm_message_header_t)) {
+      80                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      81                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+      82                 :            :                                                response_size, response);
+      83                 :            :     }
+      84         [ -  + ]:          2 :     if (spdm_request->header.spdm_version != libspdm_get_connection_version(spdm_context)) {
+      85                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      86                 :            :                                                SPDM_ERROR_CODE_VERSION_MISMATCH, 0,
+      87                 :            :                                                response_size, response);
+      88                 :            :     }
+      89                 :            : 
+      90                 :          2 :     subscribe_event_group_count = spdm_request->header.param1;
+      91                 :            : 
+      92                 :            :     /* This message can only be in secured session.
+      93                 :            :      * Thus don't need to consider transport layer padding, just check its exact size. */
+      94         [ +  + ]:          2 :     if (subscribe_event_group_count == 0) {
+      95         [ -  + ]:          1 :         if (request_size != sizeof(spdm_message_header_t)) {
+      96                 :          0 :             return libspdm_generate_error_response(spdm_context,
+      97                 :            :                                                    SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+      98                 :            :                                                    response_size, response);
+      99                 :            :         }
+     100                 :            :     } else {
+     101         [ -  + ]:          1 :         if (request_size < sizeof(spdm_subscribe_event_types_request_t)) {
+     102                 :          0 :             return libspdm_generate_error_response(spdm_context,
+     103                 :            :                                                    SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     104                 :            :                                                    response_size, response);
+     105                 :            :         }
+     106                 :          1 :         if (request_size != (sizeof(spdm_subscribe_event_types_request_t) +
+     107         [ -  + ]:          1 :                              spdm_request->subscribe_list_len)) {
+     108                 :          0 :             return libspdm_generate_error_response(spdm_context,
+     109                 :            :                                                    SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     110                 :            :                                                    response_size, response);
+     111                 :            :         }
+     112                 :            :     }
+     113                 :            : 
+     114   [ +  +  -  + ]:          2 :     if ((subscribe_event_group_count != 0) && (spdm_request->subscribe_list_len == 0)) {
+     115                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     116                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     117                 :            :                                                response_size, response);
+     118                 :            :     }
+     119                 :            : 
+     120         [ +  + ]:          2 :     if (subscribe_event_group_count == 0) {
+     121                 :          1 :         subscribe_list_len = 0;
+     122                 :          1 :         subscribe_list = NULL;
+     123                 :            :     } else {
+     124                 :          1 :         subscribe_list_len = spdm_request->subscribe_list_len;
+     125                 :          1 :         subscribe_list = (const void *)(spdm_request + 1);
+     126                 :            :     }
+     127                 :            : 
+     128         [ -  + ]:          2 :     if (!libspdm_event_subscribe(spdm_context, spdm_context->connection_info.version,
+     129                 :            :                                  subscribe_event_group_count, subscribe_list_len, subscribe_list)) {
+     130                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     131                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     132                 :            :                                                response_size, response);
+     133                 :            :     }
+     134                 :            : 
+     135                 :            :     /* -=[Construct Response Phase]=- */
+     136         [ -  + ]:          2 :     LIBSPDM_ASSERT(response_buffer_size >= sizeof(spdm_subscribe_event_types_ack_response_t));
+     137                 :          2 :     libspdm_zero_mem(response, response_buffer_size);
+     138                 :          2 :     spdm_response = response;
+     139                 :            : 
+     140                 :          2 :     spdm_response->header.spdm_version = libspdm_get_connection_version(spdm_context);
+     141                 :          2 :     spdm_response->header.request_response_code = SPDM_SUBSCRIBE_EVENT_TYPES_ACK;
+     142                 :          2 :     spdm_response->header.param1 = 0;
+     143                 :          2 :     spdm_response->header.param2 = 0;
+     144                 :            : 
+     145                 :          2 :     *response_size = sizeof(spdm_subscribe_event_types_ack_response_t);
+     146                 :            : 
+     147                 :          2 :     return LIBSPDM_STATUS_SUCCESS;
+     148                 :            : }
+     149                 :            : 
+     150                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_supported_event_types.c.func-sort-c.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_supported_event_types.c.func-sort-c.html new file mode 100644 index 00000000000..41756a44d40 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_supported_event_types.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_supported_event_types.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_supported_event_types.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:334376.7 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:163053.3 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_response_supported_event_types2
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_supported_event_types.c.func.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_supported_event_types.c.func.html new file mode 100644 index 00000000000..0f4ca75e884 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_supported_event_types.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_supported_event_types.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_supported_event_types.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:334376.7 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:163053.3 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_response_supported_event_types2
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_supported_event_types.c.gcov.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_supported_event_types.c.gcov.html new file mode 100644 index 00000000000..07a8472662a --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_supported_event_types.c.gcov.html @@ -0,0 +1,208 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_supported_event_types.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_supported_event_types.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:334376.7 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:163053.3 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2024 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_responder_lib.h"
+       8                 :            : #include "internal/libspdm_secured_message_lib.h"
+       9                 :            : 
+      10                 :            : #if LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP
+      11                 :            : 
+      12                 :          2 : libspdm_return_t libspdm_get_response_supported_event_types(libspdm_context_t *spdm_context,
+      13                 :            :                                                             size_t request_size,
+      14                 :            :                                                             const void *request,
+      15                 :            :                                                             size_t *response_size,
+      16                 :            :                                                             void *response)
+      17                 :            : {
+      18                 :            :     spdm_supported_event_types_response_t *spdm_response;
+      19                 :            :     const spdm_get_supported_event_types_request_t *spdm_request;
+      20                 :          2 :     const size_t response_buffer_size = *response_size;
+      21                 :            :     uint32_t supported_event_groups_list_len;
+      22                 :            :     uint8_t event_group_count;
+      23                 :            :     uint32_t session_id;
+      24                 :            :     libspdm_session_info_t *session_info;
+      25                 :            :     libspdm_session_state_t session_state;
+      26                 :            : 
+      27                 :          2 :     spdm_request = request;
+      28                 :            : 
+      29                 :            :     /* -=[Check Parameters Phase]=- */
+      30         [ -  + ]:          2 :     LIBSPDM_ASSERT(spdm_request->header.request_response_code == SPDM_GET_SUPPORTED_EVENT_TYPES);
+      31                 :            : 
+      32                 :            :     /* -=[Verify State Phase]=- */
+      33         [ -  + ]:          2 :     if (spdm_context->response_state != LIBSPDM_RESPONSE_STATE_NORMAL) {
+      34                 :          0 :         return libspdm_responder_handle_response_state(
+      35                 :            :             spdm_context,
+      36                 :          0 :             spdm_request->header.request_response_code,
+      37                 :            :             response_size, response);
+      38                 :            :     }
+      39         [ -  + ]:          2 :     if (spdm_context->connection_info.connection_state < LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
+      40                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      41                 :            :                                                SPDM_ERROR_CODE_UNEXPECTED_REQUEST,
+      42                 :            :                                                0, response_size, response);
+      43                 :            :     }
+      44         [ -  + ]:          2 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_13) {
+      45                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      46                 :            :                                                SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+      47                 :            :                                                SPDM_GET_SUPPORTED_EVENT_TYPES,
+      48                 :            :                                                response_size, response);
+      49                 :            :     }
+      50         [ +  + ]:          2 :     if (!libspdm_is_capabilities_flag_supported(
+      51                 :            :             spdm_context, false,
+      52                 :            :             0, SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EVENT_CAP)) {
+      53                 :          1 :         return libspdm_generate_error_response(
+      54                 :            :             spdm_context, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
+      55                 :            :             SPDM_GET_SUPPORTED_EVENT_TYPES, response_size, response);
+      56                 :            :     }
+      57         [ -  + ]:          1 :     if (!spdm_context->last_spdm_request_session_id_valid) {
+      58                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      59                 :            :                                                SPDM_ERROR_CODE_SESSION_REQUIRED, 0,
+      60                 :            :                                                response_size, response);
+      61                 :            :     }
+      62                 :          1 :     session_id = spdm_context->last_spdm_request_session_id;
+      63                 :          1 :     session_info = libspdm_get_session_info_via_session_id(spdm_context, session_id);
+      64         [ -  + ]:          1 :     if (session_info == NULL) {
+      65                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      66                 :            :                                                SPDM_ERROR_CODE_SESSION_REQUIRED, 0,
+      67                 :            :                                                response_size, response);
+      68                 :            :     }
+      69                 :          1 :     session_state = libspdm_secured_message_get_session_state(
+      70                 :            :         session_info->secured_message_context);
+      71         [ -  + ]:          1 :     if (session_state != LIBSPDM_SESSION_STATE_ESTABLISHED) {
+      72                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      73                 :            :                                                SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+      74                 :            :                                                response_size, response);
+      75                 :            :     }
+      76                 :            :     /* This message can only be in secured session.
+      77                 :            :      * Thus don't need to consider transport layer padding, just check its exact size. */
+      78         [ -  + ]:          1 :     if (request_size != sizeof(spdm_get_supported_event_types_request_t)) {
+      79                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      80                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+      81                 :            :                                                response_size, response);
+      82                 :            :     }
+      83         [ -  + ]:          1 :     if (spdm_request->header.spdm_version != libspdm_get_connection_version(spdm_context)) {
+      84                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      85                 :            :                                                SPDM_ERROR_CODE_VERSION_MISMATCH, 0,
+      86                 :            :                                                response_size, response);
+      87                 :            :     }
+      88                 :            : 
+      89                 :            :     /* -=[Construct Response Phase]=- */
+      90         [ -  + ]:          1 :     LIBSPDM_ASSERT(response_buffer_size >= sizeof(spdm_supported_event_types_response_t));
+      91                 :          1 :     libspdm_zero_mem(response, response_buffer_size);
+      92                 :          1 :     spdm_response = response;
+      93                 :            : 
+      94                 :          1 :     spdm_response->header.spdm_version = libspdm_get_connection_version(spdm_context);
+      95                 :          1 :     spdm_response->header.request_response_code = SPDM_SUPPORTED_EVENT_TYPES;
+      96                 :          1 :     spdm_response->header.param2 = 0;
+      97                 :            : 
+      98                 :          1 :     supported_event_groups_list_len = (uint32_t)response_buffer_size -
+      99                 :            :                                       sizeof(spdm_supported_event_types_response_t);
+     100                 :            : 
+     101         [ -  + ]:          1 :     if (!libspdm_event_get_types(spdm_context, spdm_context->connection_info.version,
+     102                 :          1 :                                  (void *)(spdm_response + 1), &supported_event_groups_list_len,
+     103                 :            :                                  &event_group_count)) {
+     104                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     105                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     106                 :            :                                                response_size, response);
+     107                 :            :     }
+     108                 :            : 
+     109         [ -  + ]:          1 :     LIBSPDM_ASSERT(supported_event_groups_list_len > 0);
+     110         [ -  + ]:          1 :     LIBSPDM_ASSERT(supported_event_groups_list_len <=
+     111                 :            :                    (response_buffer_size - sizeof(spdm_supported_event_types_response_t)));
+     112         [ -  + ]:          1 :     LIBSPDM_ASSERT(event_group_count > 0);
+     113                 :            : 
+     114                 :          1 :     spdm_response->header.param1 = event_group_count;
+     115                 :          1 :     spdm_response->supported_event_groups_list_len = supported_event_groups_list_len;
+     116                 :            : 
+     117                 :          1 :     *response_size = sizeof(spdm_supported_event_types_response_t) +
+     118                 :            :                      supported_event_groups_list_len;
+     119                 :            : 
+     120                 :          1 :     return LIBSPDM_STATUS_SUCCESS;
+     121                 :            : }
+     122                 :            : 
+     123                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_vendor_response.c.func-sort-c.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_vendor_response.c.func-sort-c.html new file mode 100644 index 00000000000..6a9607e5da2 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_vendor_response.c.func-sort-c.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_vendor_response.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_vendor_response.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:638078.8 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:183650.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_vendor_defined_response4
libspdm_register_vendor_get_id_callback_func4
libspdm_register_vendor_callback_func5
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_vendor_response.c.func.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_vendor_response.c.func.html new file mode 100644 index 00000000000..c1301c6d9af --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_vendor_response.c.func.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_vendor_response.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_vendor_response.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:638078.8 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:183650.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_vendor_defined_response4
libspdm_register_vendor_callback_func5
libspdm_register_vendor_get_id_callback_func4
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_vendor_response.c.gcov.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_vendor_response.c.gcov.html new file mode 100644 index 00000000000..f2657069040 --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_vendor_response.c.gcov.html @@ -0,0 +1,305 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_vendor_response.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_vendor_response.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:638078.8 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:183650.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2023-2024 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_responder_lib.h"
+       8                 :            : 
+       9                 :            : #if LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES
+      10                 :            : 
+      11                 :            : /* expected number of bytes for VENDOR MESSAGE HEADERS */
+      12                 :            : #define SPDM_VENDOR_DEFINED_FIXED_HEADER_LEN 7
+      13                 :            : 
+      14                 :          4 : libspdm_return_t libspdm_register_vendor_get_id_callback_func(void *spdm_context,
+      15                 :            :                                                               libspdm_vendor_get_id_callback_func resp_callback)
+      16                 :            : {
+      17                 :            : 
+      18                 :          4 :     libspdm_context_t *context = (libspdm_context_t *)spdm_context;
+      19                 :          4 :     context->vendor_response_get_id = resp_callback;
+      20                 :          4 :     return LIBSPDM_STATUS_SUCCESS;
+      21                 :            : }
+      22                 :            : 
+      23                 :          5 : libspdm_return_t libspdm_register_vendor_callback_func(void *spdm_context,
+      24                 :            :                                                        libspdm_vendor_response_callback_func resp_callback)
+      25                 :            : {
+      26                 :            : 
+      27                 :          5 :     libspdm_context_t *context = (libspdm_context_t *)spdm_context;
+      28                 :          5 :     context->vendor_response_callback = resp_callback;
+      29                 :          5 :     return LIBSPDM_STATUS_SUCCESS;
+      30                 :            : }
+      31                 :            : 
+      32                 :          4 : libspdm_return_t libspdm_get_vendor_defined_response(libspdm_context_t *spdm_context,
+      33                 :            :                                                      size_t request_size,
+      34                 :            :                                                      const void *request,
+      35                 :            :                                                      size_t *response_size,
+      36                 :            :                                                      void *response)
+      37                 :            : {
+      38                 :            :     const spdm_vendor_defined_request_msg_t *spdm_request;
+      39                 :            :     spdm_vendor_defined_response_msg_t *spdm_response;
+      40                 :            :     uint16_t header_length;
+      41                 :          4 :     size_t response_capacity = 0;
+      42                 :          4 :     libspdm_return_t status = LIBSPDM_STATUS_SUCCESS;
+      43                 :            : 
+      44                 :          4 :     libspdm_session_info_t *session_info = NULL;
+      45                 :          4 :     libspdm_session_state_t session_state = 0;
+      46                 :          4 :     const uint32_t *session_id = NULL;
+      47                 :          4 :     uint8_t *resp_data = NULL;
+      48                 :            :     const uint8_t *req_vendor_id;
+      49                 :            :     const uint8_t *req_data;
+      50                 :          4 :     uint16_t resp_size = 0;
+      51                 :          4 :     uint16_t req_size = 0;
+      52                 :            : 
+      53                 :            :     /* -=[Check Parameters Phase]=- */
+      54   [ +  -  +  + ]:          4 :     if (request == NULL ||
+      55         [ -  + ]:          3 :         response == NULL ||
+      56                 :            :         response_size == NULL) {
+      57                 :          1 :         return LIBSPDM_STATUS_INVALID_PARAMETER;
+      58                 :            :     }
+      59                 :            : 
+      60         [ -  + ]:          3 :     if (spdm_context->last_spdm_request_session_id_valid) {
+      61                 :          0 :         session_info = libspdm_get_session_info_via_session_id(
+      62                 :            :             spdm_context,
+      63                 :            :             spdm_context->last_spdm_request_session_id);
+      64         [ #  # ]:          0 :         if (session_info == NULL) {
+      65                 :          0 :             return libspdm_generate_error_response(
+      66                 :            :                 spdm_context,
+      67                 :            :                 SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+      68                 :            :                 response_size, response);
+      69                 :            :         }
+      70                 :          0 :         session_state = libspdm_secured_message_get_session_state(
+      71                 :            :             session_info->secured_message_context);
+      72         [ #  # ]:          0 :         if (session_state != LIBSPDM_SESSION_STATE_ESTABLISHED) {
+      73                 :          0 :             return libspdm_generate_error_response(
+      74                 :            :                 spdm_context,
+      75                 :            :                 SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
+      76                 :            :                 response_size, response);
+      77                 :            :         }
+      78                 :          0 :         session_id = &session_info->session_id;
+      79                 :            :     }
+      80                 :            : 
+      81                 :            :     /* Check if caller is using the old Vendor Defined API */
+      82         [ +  + ]:          3 :     if ((spdm_context->vendor_response_callback == NULL ||
+      83         [ -  + ]:          2 :          spdm_context->vendor_response_get_id == NULL)) {
+      84                 :            : 
+      85         [ +  - ]:          1 :         if (spdm_context->get_response_func != NULL) {
+      86                 :            : 
+      87                 :          1 :             return ((libspdm_get_response_func)spdm_context->get_response_func)(
+      88                 :            :                 spdm_context,
+      89                 :            :                 session_id,
+      90                 :            :                 false,
+      91                 :            :                 request_size,
+      92                 :            :                 request,
+      93                 :            :                 response_size,
+      94                 :            :                 response
+      95                 :            :                 );
+      96                 :            :         } else
+      97                 :          0 :             return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+      98                 :            :     }
+      99                 :            : 
+     100                 :          2 :     spdm_request = request;
+     101                 :            : 
+     102         [ -  + ]:          2 :     if (spdm_request->header.spdm_version != libspdm_get_connection_version(spdm_context)) {
+     103                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     104                 :            :                                                SPDM_ERROR_CODE_VERSION_MISMATCH, 0,
+     105                 :            :                                                response_size, response);
+     106                 :            :     }
+     107         [ -  + ]:          2 :     if (spdm_context->response_state != LIBSPDM_RESPONSE_STATE_NORMAL) {
+     108                 :          0 :         return libspdm_responder_handle_response_state(
+     109                 :            :             spdm_context,
+     110                 :          0 :             spdm_request->header.request_response_code,
+     111                 :            :             response_size, response);
+     112                 :            :     }
+     113         [ -  + ]:          2 :     if (spdm_context->connection_info.connection_state < LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
+     114                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     115                 :            :                                                SPDM_ERROR_CODE_UNEXPECTED_REQUEST,
+     116                 :            :                                                0, response_size, response);
+     117                 :            :     }
+     118                 :            : 
+     119         [ -  + ]:          2 :     if (request_size < sizeof(spdm_vendor_defined_request_msg_t)) {
+     120                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     121                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     122                 :            :                                                response_size, response);
+     123                 :            :     }
+     124                 :          2 :     if (request_size < sizeof(spdm_vendor_defined_request_msg_t) +
+     125         [ -  + ]:          2 :         spdm_request->len + sizeof(uint16_t)) {
+     126                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     127                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     128                 :            :                                                response_size, response);
+     129                 :            :     }
+     130                 :          2 :     req_vendor_id = ((const uint8_t *)request) +
+     131                 :            :                     sizeof(spdm_vendor_defined_request_msg_t);
+     132                 :          2 :     req_size = *(const uint16_t *)(req_vendor_id + spdm_request->len);
+     133                 :          2 :     if (request_size < sizeof(spdm_vendor_defined_request_msg_t) +
+     134         [ -  + ]:          2 :         spdm_request->len + sizeof(uint16_t) + req_size) {
+     135                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     136                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     137                 :            :                                                response_size, response);
+     138                 :            :     }
+     139                 :            : 
+     140         [ -  + ]:          2 :     if (spdm_context->vendor_response_get_id == NULL) {
+     141                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     142                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     143                 :            :                                                response_size, response);
+     144                 :            :     }
+     145                 :            : 
+     146         [ -  + ]:          2 :     if (spdm_context->vendor_response_callback == NULL) {
+     147                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     148                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+     149                 :            :                                                response_size, response);
+     150                 :            :     }
+     151                 :            : 
+     152                 :          2 :     libspdm_reset_message_buffer_via_request_code(spdm_context, NULL,
+     153                 :          2 :                                                   spdm_request->header.request_response_code);
+     154                 :            : 
+     155                 :            :     /* length of spdm request/response header before payload start */
+     156                 :          2 :     header_length = sizeof(spdm_vendor_defined_response_msg_t) + spdm_request->len +
+     157                 :            :                     sizeof(uint16_t);
+     158                 :            : 
+     159         [ -  + ]:          2 :     LIBSPDM_ASSERT(*response_size >= header_length);
+     160                 :            :     LIBSPDM_ASSERT(
+     161                 :            :         sizeof(spdm_vendor_defined_response_msg_t) == SPDM_VENDOR_DEFINED_FIXED_HEADER_LEN);
+     162                 :          2 :     response_capacity = *response_size - header_length;
+     163                 :          2 :     libspdm_zero_mem(response, header_length);
+     164                 :          2 :     spdm_response = response;
+     165                 :            : 
+     166                 :          2 :     spdm_response->header.spdm_version = spdm_request->header.spdm_version;
+     167                 :          2 :     spdm_response->header.request_response_code = SPDM_VENDOR_DEFINED_RESPONSE;
+     168                 :          2 :     spdm_response->header.param1 = 0;
+     169                 :          2 :     spdm_response->header.param2 = 0;
+     170                 :            : 
+     171                 :            :     /* SPDM Response format
+     172                 :            :      *  1 byte SPDMVersion
+     173                 :            :      *  1 byte RequestResponseCode
+     174                 :            :      *  2 bytes Reserved
+     175                 :            :      *  2 bytes StandardID
+     176                 :            :      *  1 bytes VendorID Length Len1, based on StandardID
+     177                 :            :      *  Len1 bytes VendorID
+     178                 :            :      *  2 bytes Response Length Len2
+     179                 :            :      *  Len2 bytes Response Payload
+     180                 :            :      */
+     181                 :            : 
+     182                 :            :     /* replace capacity with size */
+     183                 :          2 :     spdm_response->len = SPDM_MAX_VENDOR_ID_LENGTH;
+     184                 :          2 :     resp_data = ((uint8_t *)response) + sizeof(spdm_vendor_defined_response_msg_t);
+     185                 :            : 
+     186                 :          2 :     req_data = ((const uint8_t *)request) +
+     187                 :            :                sizeof(spdm_vendor_defined_request_msg_t) +
+     188                 :          2 :                ((const spdm_vendor_defined_request_msg_t*)request)->len +
+     189                 :            :                sizeof(uint16_t);
+     190                 :            : 
+     191                 :          2 :     status = spdm_context->vendor_response_get_id(
+     192                 :            :         spdm_context,
+     193                 :            :         &spdm_response->standard_id,
+     194                 :            :         &spdm_response->len,
+     195                 :            :         resp_data);
+     196                 :            : 
+     197                 :            :     /* move pointer and adjust buffer size */
+     198                 :          2 :     resp_data += spdm_response->len + sizeof(uint16_t);
+     199                 :          2 :     response_capacity -= spdm_response->len + sizeof(uint16_t);
+     200                 :          2 :     resp_size = (uint16_t)response_capacity;
+     201                 :            : 
+     202                 :          2 :     status = spdm_context->vendor_response_callback(spdm_context,
+     203                 :          2 :                                                     spdm_request->standard_id,
+     204                 :          2 :                                                     spdm_request->len,
+     205                 :            :                                                     req_vendor_id, req_size, req_data,
+     206                 :            :                                                     &resp_size,
+     207                 :            :                                                     resp_data
+     208                 :            :                                                     );
+     209                 :            : 
+     210                 :            :     /* store back the response payload size */
+     211                 :          2 :     *((uint16_t*)(resp_data - sizeof(uint16_t))) = resp_size;
+     212                 :          2 :     *response_size = resp_size + (size_t)header_length;
+     213                 :            : 
+     214                 :            :     LIBSPDM_ASSERT(sizeof(spdm_vendor_defined_request_msg_t) ==
+     215                 :            :                    SPDM_VENDOR_DEFINED_FIXED_HEADER_LEN);
+     216                 :            : 
+     217                 :          2 :     return status;
+     218                 :            : }
+     219                 :            : 
+     220                 :            : #endif /* LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_version.c.func-sort-c.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_version.c.func-sort-c.html new file mode 100644 index 00000000000..649f7ddcbfa --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_version.c.func-sort-c.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_version.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_version.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:525791.2 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:132065.0 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
generate_invalid_version_error1
libspdm_get_response_version5
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_version.c.func.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_version.c.func.html new file mode 100644 index 00000000000..360f9d4613c --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_version.c.func.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_version.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_version.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:525791.2 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:132065.0 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
generate_invalid_version_error1
libspdm_get_response_version5
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_responder_lib/libspdm_rsp_version.c.gcov.html b/coverage_log/library/spdm_responder_lib/libspdm_rsp_version.c.gcov.html new file mode 100644 index 00000000000..7a78db5831a --- /dev/null +++ b/coverage_log/library/spdm_responder_lib/libspdm_rsp_version.c.gcov.html @@ -0,0 +1,220 @@ + + + + + + + LCOV - coverage.info - library/spdm_responder_lib/libspdm_rsp_version.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_responder_lib - libspdm_rsp_version.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:525791.2 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:132065.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 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_responder_lib.h"
+       8                 :            : 
+       9                 :            : #pragma pack(1)
+      10                 :            : typedef struct {
+      11                 :            :     spdm_message_header_t header;
+      12                 :            :     uint8_t reserved;
+      13                 :            :     uint8_t version_number_entry_count;
+      14                 :            :     spdm_version_number_t version_number_entry[SPDM_MAX_VERSION_COUNT];
+      15                 :            : } libspdm_version_response_mine_t;
+      16                 :            : #pragma pack()
+      17                 :            : 
+      18                 :          1 : static libspdm_return_t generate_invalid_version_error(size_t *response_size, void *response)
+      19                 :            : {
+      20                 :            :     spdm_error_response_t *spdm_response;
+      21                 :            : 
+      22                 :          1 :     spdm_response = response;
+      23                 :          1 :     *response_size = sizeof(spdm_error_response_t);
+      24                 :            : 
+      25                 :          1 :     spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+      26                 :          1 :     spdm_response->header.request_response_code = SPDM_ERROR;
+      27                 :          1 :     spdm_response->header.param1 = SPDM_ERROR_CODE_VERSION_MISMATCH;
+      28                 :          1 :     spdm_response->header.param2 = 0;
+      29                 :            : 
+      30                 :          1 :     return LIBSPDM_STATUS_SUCCESS;
+      31                 :            : }
+      32                 :            : 
+      33                 :          5 : libspdm_return_t libspdm_get_response_version(libspdm_context_t *spdm_context, size_t request_size,
+      34                 :            :                                               const void *request,
+      35                 :            :                                               size_t *response_size,
+      36                 :            :                                               void *response)
+      37                 :            : {
+      38                 :            :     const spdm_get_version_request_t *spdm_request;
+      39                 :            :     libspdm_version_response_mine_t *spdm_response;
+      40                 :            :     libspdm_return_t status;
+      41                 :            : 
+      42                 :          5 :     spdm_request = request;
+      43                 :            : 
+      44                 :            :     /* -=[Check Parameters Phase]=- */
+      45         [ -  + ]:          5 :     LIBSPDM_ASSERT(spdm_request->header.request_response_code == SPDM_GET_VERSION);
+      46                 :            : 
+      47                 :            :     /* -=[Validate Request Phase]=- */
+      48         [ -  + ]:          5 :     if (request_size < sizeof(spdm_get_version_request_t)) {
+      49                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      50                 :            :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
+      51                 :            :                                                response_size, response);
+      52                 :            :     }
+      53                 :            : 
+      54         [ -  + ]:          5 :     if (spdm_context->last_spdm_request_session_id_valid) {
+      55                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      56                 :            :                                                SPDM_ERROR_CODE_UNEXPECTED_REQUEST,
+      57                 :            :                                                0, response_size, response);
+      58                 :            :     }
+      59                 :            : 
+      60         [ +  + ]:          5 :     if (spdm_request->header.spdm_version != SPDM_MESSAGE_VERSION_10) {
+      61                 :            :         /* If the GET_VERSION request is improperly formed then the version of the error message
+      62                 :            :          * must be 1.0, regardless of what the negotiated version is. */
+      63                 :          1 :         return generate_invalid_version_error(response_size, response);
+      64                 :            :     }
+      65                 :            : 
+      66                 :          4 :     libspdm_set_connection_state(spdm_context, LIBSPDM_CONNECTION_STATE_NOT_STARTED);
+      67                 :            : 
+      68         [ +  + ]:          4 :     if ((spdm_context->response_state == LIBSPDM_RESPONSE_STATE_NEED_RESYNC) ||
+      69         [ -  + ]:          3 :         (spdm_context->response_state == LIBSPDM_RESPONSE_STATE_PROCESSING_ENCAP)) {
+      70                 :            :         /* receiving a GET_VERSION resets a need to resynchronization*/
+      71                 :          1 :         spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+      72                 :            :     }
+      73         [ +  + ]:          4 :     if (spdm_context->response_state != LIBSPDM_RESPONSE_STATE_NORMAL) {
+      74                 :          1 :         return libspdm_responder_handle_response_state(
+      75                 :            :             spdm_context,
+      76                 :          1 :             spdm_request->header.request_response_code,
+      77                 :            :             response_size, response);
+      78                 :            :     }
+      79                 :            : 
+      80                 :            :     /* -=[Process Request Phase]=- */
+      81                 :          3 :     libspdm_reset_message_buffer_via_request_code(spdm_context, NULL,
+      82                 :          3 :                                                   spdm_request->header.request_response_code);
+      83                 :            : 
+      84                 :          3 :     libspdm_reset_message_a(spdm_context);
+      85                 :          3 :     libspdm_reset_message_d(spdm_context);
+      86                 :          3 :     libspdm_reset_message_b(spdm_context);
+      87                 :          3 :     libspdm_reset_message_c(spdm_context);
+      88                 :            : 
+      89                 :          3 :     request_size = sizeof(spdm_get_version_request_t);
+      90                 :          3 :     status = libspdm_append_message_a(spdm_context, spdm_request, request_size);
+      91         [ -  + ]:          3 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+      92                 :          0 :         return libspdm_generate_error_response(spdm_context,
+      93                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+      94                 :            :                                                response_size, response);
+      95                 :            :     }
+      96                 :            : 
+      97                 :          3 :     libspdm_reset_context(spdm_context);
+      98                 :            : 
+      99                 :            :     /* -=[Construct Response Phase]=- */
+     100         [ -  + ]:          3 :     LIBSPDM_ASSERT(*response_size >= sizeof(libspdm_version_response_mine_t));
+     101                 :          3 :     *response_size =
+     102                 :          3 :         sizeof(spdm_version_response_t) +
+     103                 :          3 :         spdm_context->local_context.version.spdm_version_count *
+     104                 :            :         sizeof(spdm_version_number_t);
+     105                 :          3 :     libspdm_zero_mem(response, *response_size);
+     106                 :          3 :     spdm_response = response;
+     107                 :            : 
+     108                 :          3 :     spdm_response->header.spdm_version = spdm_request->header.spdm_version;
+     109                 :          3 :     spdm_response->header.request_response_code = SPDM_VERSION;
+     110                 :          3 :     spdm_response->header.param1 = 0;
+     111                 :          3 :     spdm_response->header.param2 = 0;
+     112                 :          3 :     spdm_response->version_number_entry_count =
+     113                 :          3 :         spdm_context->local_context.version.spdm_version_count;
+     114                 :          3 :     libspdm_copy_mem(spdm_response->version_number_entry,
+     115                 :            :                      sizeof(spdm_response->version_number_entry),
+     116                 :          3 :                      spdm_context->local_context.version.spdm_version,
+     117                 :            :                      sizeof(spdm_version_number_t) *
+     118                 :          3 :                      spdm_context->local_context.version.spdm_version_count);
+     119                 :            : 
+     120                 :          3 :     status = libspdm_append_message_a(spdm_context, spdm_response, *response_size);
+     121         [ -  + ]:          3 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     122                 :          0 :         libspdm_reset_message_a(spdm_context);
+     123                 :          0 :         return libspdm_generate_error_response(spdm_context,
+     124                 :            :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
+     125                 :            :                                                response_size, response);
+     126                 :            :     }
+     127                 :            : 
+     128                 :            :     /* -=[Update State Phase]=- */
+     129                 :          3 :     libspdm_set_connection_state(spdm_context, LIBSPDM_CONNECTION_STATE_AFTER_VERSION);
+     130                 :            : 
+     131                 :            :     /*Set the role of device*/
+     132                 :          3 :     spdm_context->local_context.is_requester = false;
+     133                 :            : 
+     134                 :          3 :     return LIBSPDM_STATUS_SUCCESS;
+     135                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_secured_message_lib/index-sort-b.html b/coverage_log/library/spdm_secured_message_lib/index-sort-b.html new file mode 100644 index 00000000000..45331a7422a --- /dev/null +++ b/coverage_log/library/spdm_secured_message_lib/index-sort-b.html @@ -0,0 +1,143 @@ + + + + + + + LCOV - coverage.info - library/spdm_secured_message_lib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_secured_message_libHitTotalCoverage
Test:coverage.infoLines:60389967.1 %
Date:2024-09-22 08:21:07Functions:334967.3 %
Branches:14328250.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
libspdm_secmes_context_data.c +
51.0%51.0%
+
51.0 %78 / 15382.4 %14 / 1736.4 %8 / 22
libspdm_secmes_encode_decode.c +
56.1%56.1%
+
56.1 %184 / 32880.0 %4 / 543.0 %68 / 158
libspdm_secmes_key_exchange.c +
94.1%94.1%
+
94.1 %16 / 17100.0 %4 / 450.0 %1 / 2
libspdm_secmes_session.c +
81.0%81.0%
+
81.0 %325 / 40147.8 %11 / 2366.0 %66 / 100
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_secured_message_lib/index-sort-f.html b/coverage_log/library/spdm_secured_message_lib/index-sort-f.html new file mode 100644 index 00000000000..cb1737ee171 --- /dev/null +++ b/coverage_log/library/spdm_secured_message_lib/index-sort-f.html @@ -0,0 +1,143 @@ + + + + + + + LCOV - coverage.info - library/spdm_secured_message_lib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_secured_message_libHitTotalCoverage
Test:coverage.infoLines:60389967.1 %
Date:2024-09-22 08:21:07Functions:334967.3 %
Branches:14328250.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
libspdm_secmes_session.c +
81.0%81.0%
+
81.0 %325 / 40147.8 %11 / 2366.0 %66 / 100
libspdm_secmes_encode_decode.c +
56.1%56.1%
+
56.1 %184 / 32880.0 %4 / 543.0 %68 / 158
libspdm_secmes_context_data.c +
51.0%51.0%
+
51.0 %78 / 15382.4 %14 / 1736.4 %8 / 22
libspdm_secmes_key_exchange.c +
94.1%94.1%
+
94.1 %16 / 17100.0 %4 / 450.0 %1 / 2
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_secured_message_lib/index-sort-l.html b/coverage_log/library/spdm_secured_message_lib/index-sort-l.html new file mode 100644 index 00000000000..ee7f0f8e88a --- /dev/null +++ b/coverage_log/library/spdm_secured_message_lib/index-sort-l.html @@ -0,0 +1,143 @@ + + + + + + + LCOV - coverage.info - library/spdm_secured_message_lib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_secured_message_libHitTotalCoverage
Test:coverage.infoLines:60389967.1 %
Date:2024-09-22 08:21:07Functions:334967.3 %
Branches:14328250.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
libspdm_secmes_context_data.c +
51.0%51.0%
+
51.0 %78 / 15382.4 %14 / 1736.4 %8 / 22
libspdm_secmes_encode_decode.c +
56.1%56.1%
+
56.1 %184 / 32880.0 %4 / 543.0 %68 / 158
libspdm_secmes_session.c +
81.0%81.0%
+
81.0 %325 / 40147.8 %11 / 2366.0 %66 / 100
libspdm_secmes_key_exchange.c +
94.1%94.1%
+
94.1 %16 / 17100.0 %4 / 450.0 %1 / 2
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_secured_message_lib/index.html b/coverage_log/library/spdm_secured_message_lib/index.html new file mode 100644 index 00000000000..c20e3080ef8 --- /dev/null +++ b/coverage_log/library/spdm_secured_message_lib/index.html @@ -0,0 +1,143 @@ + + + + + + + LCOV - coverage.info - library/spdm_secured_message_lib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_secured_message_libHitTotalCoverage
Test:coverage.infoLines:60389967.1 %
Date:2024-09-22 08:21:07Functions:334967.3 %
Branches:14328250.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
libspdm_secmes_context_data.c +
51.0%51.0%
+
51.0 %78 / 15382.4 %14 / 1736.4 %8 / 22
libspdm_secmes_encode_decode.c +
56.1%56.1%
+
56.1 %184 / 32880.0 %4 / 543.0 %68 / 158
libspdm_secmes_key_exchange.c +
94.1%94.1%
+
94.1 %16 / 17100.0 %4 / 450.0 %1 / 2
libspdm_secmes_session.c +
81.0%81.0%
+
81.0 %325 / 40147.8 %11 / 2366.0 %66 / 100
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_secured_message_lib/libspdm_secmes_context_data.c.func-sort-c.html b/coverage_log/library/spdm_secured_message_lib/libspdm_secmes_context_data.c.func-sort-c.html new file mode 100644 index 00000000000..af7db318a11 --- /dev/null +++ b/coverage_log/library/spdm_secured_message_lib/libspdm_secmes_context_data.c.func-sort-c.html @@ -0,0 +1,149 @@ + + + + + + + LCOV - coverage.info - library/spdm_secured_message_lib/libspdm_secmes_context_data.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_secured_message_lib - libspdm_secmes_context_data.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:7815351.0 %
Date:2024-09-22 08:21:07Functions:141782.4 %
Branches:82236.4 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_secured_message_export_session_keys0
libspdm_secured_message_import_dhe_secret0
libspdm_secured_message_import_session_keys0
libspdm_secured_message_clear_export_master_secret1
libspdm_secured_message_export_master_secret3
libspdm_secured_message_get_last_spdm_error_struct28
libspdm_secured_message_set_psk_hint74
libspdm_secured_message_get_context_size196
libspdm_secured_message_set_last_spdm_error_struct327
libspdm_secured_message_set_session_state379
libspdm_secured_message_get_session_state497
libspdm_secured_message_set_algorithms670
libspdm_secured_message_set_max_spdm_session_sequence_number670
libspdm_secured_message_set_sequence_number_endian670
libspdm_secured_message_set_session_type670
libspdm_secured_message_set_use_psk670
libspdm_secured_message_init_context1058
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_secured_message_lib/libspdm_secmes_context_data.c.func.html b/coverage_log/library/spdm_secured_message_lib/libspdm_secmes_context_data.c.func.html new file mode 100644 index 00000000000..6c471bb45d7 --- /dev/null +++ b/coverage_log/library/spdm_secured_message_lib/libspdm_secmes_context_data.c.func.html @@ -0,0 +1,149 @@ + + + + + + + LCOV - coverage.info - library/spdm_secured_message_lib/libspdm_secmes_context_data.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_secured_message_lib - libspdm_secmes_context_data.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:7815351.0 %
Date:2024-09-22 08:21:07Functions:141782.4 %
Branches:82236.4 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_secured_message_clear_export_master_secret1
libspdm_secured_message_export_master_secret3
libspdm_secured_message_export_session_keys0
libspdm_secured_message_get_context_size196
libspdm_secured_message_get_last_spdm_error_struct28
libspdm_secured_message_get_session_state497
libspdm_secured_message_import_dhe_secret0
libspdm_secured_message_import_session_keys0
libspdm_secured_message_init_context1058
libspdm_secured_message_set_algorithms670
libspdm_secured_message_set_last_spdm_error_struct327
libspdm_secured_message_set_max_spdm_session_sequence_number670
libspdm_secured_message_set_psk_hint74
libspdm_secured_message_set_sequence_number_endian670
libspdm_secured_message_set_session_state379
libspdm_secured_message_set_session_type670
libspdm_secured_message_set_use_psk670
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_secured_message_lib/libspdm_secmes_context_data.c.gcov.html b/coverage_log/library/spdm_secured_message_lib/libspdm_secmes_context_data.c.gcov.html new file mode 100644 index 00000000000..2baa815f622 --- /dev/null +++ b/coverage_log/library/spdm_secured_message_lib/libspdm_secmes_context_data.c.gcov.html @@ -0,0 +1,500 @@ + + + + + + + LCOV - coverage.info - library/spdm_secured_message_lib/libspdm_secmes_context_data.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_secured_message_lib - libspdm_secmes_context_data.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:7815351.0 %
Date:2024-09-22 08:21:07Functions:141782.4 %
Branches:82236.4 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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_secured_message_lib.h"
+       8                 :            : 
+       9                 :            : /**
+      10                 :            :  * Return the size in bytes of a single SPDM secured message context.
+      11                 :            :  *
+      12                 :            :  * @return the size in bytes of a single SPDM secured message context.
+      13                 :            :  **/
+      14                 :        196 : size_t libspdm_secured_message_get_context_size(void)
+      15                 :            : {
+      16                 :        196 :     return sizeof(libspdm_secured_message_context_t);
+      17                 :            : }
+      18                 :            : 
+      19                 :            : /**
+      20                 :            :  * Initialize an SPDM secured message context.
+      21                 :            :  *
+      22                 :            :  * The size in bytes of the spdm_secured_message_context can be returned by libspdm_secured_message_get_context_size.
+      23                 :            :  *
+      24                 :            :  * @param  spdm_secured_message_context    A pointer to the SPDM secured message context.
+      25                 :            :  */
+      26                 :       1058 : void libspdm_secured_message_init_context(void *spdm_secured_message_context)
+      27                 :            : {
+      28                 :            :     libspdm_secured_message_context_t *secured_message_context;
+      29                 :            : 
+      30                 :       1058 :     secured_message_context = spdm_secured_message_context;
+      31                 :       1058 :     libspdm_zero_mem(secured_message_context, sizeof(libspdm_secured_message_context_t));
+      32                 :       1058 : }
+      33                 :            : 
+      34                 :            : /**
+      35                 :            :  * Set use_psk to an SPDM secured message context.
+      36                 :            :  *
+      37                 :            :  * @param  spdm_secured_message_context    A pointer to the SPDM secured message context.
+      38                 :            :  * @param  use_psk                       Indicate if the SPDM session use PSK.
+      39                 :            :  */
+      40                 :        670 : void libspdm_secured_message_set_use_psk(void *spdm_secured_message_context, bool use_psk)
+      41                 :            : {
+      42                 :            :     libspdm_secured_message_context_t *secured_message_context;
+      43                 :            : 
+      44                 :        670 :     secured_message_context = spdm_secured_message_context;
+      45                 :        670 :     secured_message_context->use_psk = use_psk;
+      46                 :        670 : }
+      47                 :            : 
+      48                 :            : /**
+      49                 :            :  * Set session_state to an SPDM secured message context.
+      50                 :            :  *
+      51                 :            :  * @param  spdm_secured_message_context    A pointer to the SPDM secured message context.
+      52                 :            :  * @param  session_state                 Indicate the SPDM session state.
+      53                 :            :  */
+      54                 :        379 : void libspdm_secured_message_set_session_state(
+      55                 :            :     void *spdm_secured_message_context,
+      56                 :            :     libspdm_session_state_t session_state)
+      57                 :            : {
+      58                 :            :     libspdm_secured_message_context_t *secured_message_context;
+      59                 :            : 
+      60                 :        379 :     secured_message_context = spdm_secured_message_context;
+      61                 :        379 :     secured_message_context->session_state = session_state;
+      62                 :            : 
+      63         [ +  + ]:        379 :     if (session_state == LIBSPDM_SESSION_STATE_ESTABLISHED) {
+      64                 :            :         /* session handshake key should be zeroized after handshake phase. */
+      65                 :        201 :         libspdm_clear_handshake_secret(secured_message_context);
+      66                 :        201 :         libspdm_clear_master_secret(secured_message_context);
+      67                 :            :     }
+      68                 :        379 : }
+      69                 :            : 
+      70                 :            : /**
+      71                 :            :  * Return session_state of an SPDM secured message context.
+      72                 :            :  *
+      73                 :            :  * @param  spdm_secured_message_context    A pointer to the SPDM secured message context.
+      74                 :            :  *
+      75                 :            :  * @return the SPDM session state.
+      76                 :            :  */
+      77                 :            : libspdm_session_state_t
+      78                 :        497 : libspdm_secured_message_get_session_state(void *spdm_secured_message_context)
+      79                 :            : {
+      80                 :            :     libspdm_secured_message_context_t *secured_message_context;
+      81                 :            : 
+      82                 :        497 :     secured_message_context = spdm_secured_message_context;
+      83                 :        497 :     return secured_message_context->session_state;
+      84                 :            : }
+      85                 :            : 
+      86                 :            : /**
+      87                 :            :  * Set session_type to an SPDM secured message context.
+      88                 :            :  *
+      89                 :            :  * @param  spdm_secured_message_context    A pointer to the SPDM secured message context.
+      90                 :            :  * @param  session_type                  Indicate the SPDM session type.
+      91                 :            :  */
+      92                 :        670 : void libspdm_secured_message_set_session_type(void *spdm_secured_message_context,
+      93                 :            :                                               libspdm_session_type_t session_type)
+      94                 :            : {
+      95                 :            :     libspdm_secured_message_context_t *secured_message_context;
+      96                 :            : 
+      97                 :        670 :     secured_message_context = spdm_secured_message_context;
+      98                 :        670 :     secured_message_context->session_type = session_type;
+      99                 :        670 : }
+     100                 :            : 
+     101                 :            : /**
+     102                 :            :  * Set algorithm to an SPDM secured message context.
+     103                 :            :  *
+     104                 :            :  * @param  spdm_secured_message_context    A pointer to the SPDM secured message context.
+     105                 :            :  * @param  base_hash_algo                 Indicate the negotiated base_hash_algo for the SPDM session.
+     106                 :            :  * @param  dhe_named_group                Indicate the negotiated dhe_named_group for the SPDM session.
+     107                 :            :  * @param  aead_cipher_suite              Indicate the negotiated aead_cipher_suite for the SPDM session.
+     108                 :            :  * @param  key_schedule                  Indicate the negotiated key_schedule for the SPDM session.
+     109                 :            :  */
+     110                 :        670 : void libspdm_secured_message_set_algorithms(void *spdm_secured_message_context,
+     111                 :            :                                             const spdm_version_number_t version,
+     112                 :            :                                             const spdm_version_number_t secured_message_version,
+     113                 :            :                                             uint32_t base_hash_algo,
+     114                 :            :                                             uint16_t dhe_named_group,
+     115                 :            :                                             uint16_t aead_cipher_suite,
+     116                 :            :                                             uint16_t key_schedule)
+     117                 :            : {
+     118                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     119                 :            : 
+     120                 :        670 :     secured_message_context = spdm_secured_message_context;
+     121                 :        670 :     secured_message_context->version = version;
+     122                 :        670 :     secured_message_context->secured_message_version = secured_message_version;
+     123                 :        670 :     secured_message_context->base_hash_algo = base_hash_algo;
+     124                 :        670 :     secured_message_context->dhe_named_group = dhe_named_group;
+     125                 :        670 :     secured_message_context->aead_cipher_suite = aead_cipher_suite;
+     126                 :        670 :     secured_message_context->key_schedule = key_schedule;
+     127                 :            : 
+     128                 :        670 :     secured_message_context->hash_size =
+     129                 :        670 :         libspdm_get_hash_size(secured_message_context->base_hash_algo);
+     130                 :       1340 :     secured_message_context->dhe_key_size = libspdm_get_dhe_pub_key_size(
+     131                 :        670 :         secured_message_context->dhe_named_group);
+     132                 :       1340 :     secured_message_context->aead_key_size = libspdm_get_aead_key_size(
+     133                 :        670 :         secured_message_context->aead_cipher_suite);
+     134                 :       1340 :     secured_message_context->aead_iv_size = libspdm_get_aead_iv_size(
+     135                 :        670 :         secured_message_context->aead_cipher_suite);
+     136                 :       1340 :     secured_message_context->aead_tag_size = libspdm_get_aead_tag_size(
+     137                 :        670 :         secured_message_context->aead_cipher_suite);
+     138                 :        670 : }
+     139                 :            : 
+     140                 :            : #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
+     141                 :         74 : void libspdm_secured_message_set_psk_hint(void *spdm_secured_message_context,
+     142                 :            :                                           const void *psk_hint,
+     143                 :            :                                           size_t psk_hint_size)
+     144                 :            : {
+     145                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     146                 :            : 
+     147                 :         74 :     secured_message_context = spdm_secured_message_context;
+     148   [ +  +  +  - ]:         74 :     if ((psk_hint != NULL) && (psk_hint_size > 0)) {
+     149                 :         72 :         secured_message_context->psk_hint_size = psk_hint_size;
+     150                 :         72 :         libspdm_copy_mem(secured_message_context->psk_hint,
+     151                 :            :                          LIBSPDM_PSK_MAX_HINT_LENGTH,
+     152                 :            :                          psk_hint,
+     153                 :            :                          psk_hint_size);
+     154                 :            :     }
+     155                 :         74 : }
+     156                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP */
+     157                 :            : 
+     158                 :            : /**
+     159                 :            :  * Set the maximum sequence_number to an SPDM secured message context.
+     160                 :            :  *
+     161                 :            :  * @param  spdm_secured_message_context      A pointer to the SPDM secured message context.
+     162                 :            :  * @param  max_spdm_session_sequence_number  Indicate the maximum sequence_number in SPDM session.
+     163                 :            :  */
+     164                 :        670 : void libspdm_secured_message_set_max_spdm_session_sequence_number(
+     165                 :            :     void *spdm_secured_message_context,
+     166                 :            :     uint64_t max_spdm_session_sequence_number)
+     167                 :            : {
+     168                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     169                 :            : 
+     170                 :        670 :     secured_message_context = spdm_secured_message_context;
+     171                 :        670 :     secured_message_context->max_spdm_session_sequence_number = max_spdm_session_sequence_number;
+     172                 :        670 : }
+     173                 :            : 
+     174                 :        670 : void libspdm_secured_message_set_sequence_number_endian (
+     175                 :            :     void *spdm_secured_message_context,
+     176                 :            :     uint8_t endian_value)
+     177                 :            : {
+     178                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     179                 :            : 
+     180                 :        670 :     secured_message_context = spdm_secured_message_context;
+     181                 :        670 :     secured_message_context->sequence_number_endian = endian_value;
+     182                 :        670 : }
+     183                 :            : 
+     184                 :            : /**
+     185                 :            :  * Import the DHE Secret to an SPDM secured message context.
+     186                 :            :  *
+     187                 :            :  * @param  spdm_secured_message_context    A pointer to the SPDM secured message context.
+     188                 :            :  * @param  dhe_secret                    Indicate the DHE secret.
+     189                 :            :  * @param  dhe_secret_size                The size in bytes of the DHE secret.
+     190                 :            :  *
+     191                 :            :  * @retval RETURN_SUCCESS  DHE Secret is imported.
+     192                 :            :  */
+     193                 :          0 : bool libspdm_secured_message_import_dhe_secret(void *spdm_secured_message_context,
+     194                 :            :                                                const void *dhe_secret,
+     195                 :            :                                                size_t dhe_secret_size)
+     196                 :            : {
+     197                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     198                 :            : 
+     199                 :          0 :     secured_message_context = spdm_secured_message_context;
+     200         [ #  # ]:          0 :     if (dhe_secret_size > secured_message_context->dhe_key_size) {
+     201                 :          0 :         return false;
+     202                 :            :     }
+     203                 :          0 :     secured_message_context->dhe_key_size = dhe_secret_size;
+     204                 :          0 :     libspdm_copy_mem(secured_message_context->master_secret.dhe_secret,
+     205                 :            :                      sizeof(secured_message_context->master_secret.dhe_secret),
+     206                 :            :                      dhe_secret, dhe_secret_size);
+     207                 :          0 :     return true;
+     208                 :            : }
+     209                 :            : 
+     210                 :          3 : bool libspdm_secured_message_export_master_secret(
+     211                 :            :     void *spdm_secured_message_context, void *export_master_secret,
+     212                 :            :     size_t *export_master_secret_size)
+     213                 :            : {
+     214                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     215                 :            : 
+     216                 :          3 :     secured_message_context = spdm_secured_message_context;
+     217                 :            : 
+     218         [ +  + ]:          3 :     if (*export_master_secret_size > secured_message_context->hash_size) {
+     219                 :          1 :         *export_master_secret_size = secured_message_context->hash_size;
+     220                 :            :     }
+     221                 :            : 
+     222                 :          3 :     libspdm_copy_mem(export_master_secret, *export_master_secret_size,
+     223                 :          3 :                      secured_message_context->export_master_secret,
+     224                 :            :                      *export_master_secret_size);
+     225                 :            : 
+     226                 :          3 :     return true;
+     227                 :            : }
+     228                 :            : 
+     229                 :          1 : void libspdm_secured_message_clear_export_master_secret(void *spdm_secured_message_context)
+     230                 :            : {
+     231                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     232                 :            : 
+     233         [ -  + ]:          1 :     LIBSPDM_ASSERT(spdm_secured_message_context != NULL);
+     234                 :            : 
+     235                 :          1 :     secured_message_context = spdm_secured_message_context;
+     236                 :            : 
+     237                 :          1 :     libspdm_zero_mem(secured_message_context->export_master_secret,
+     238                 :            :                      sizeof(secured_message_context->export_master_secret));
+     239                 :          1 : }
+     240                 :            : 
+     241                 :            : /**
+     242                 :            :  * Export the session_keys from an SPDM secured message context.
+     243                 :            :  *
+     244                 :            :  * @param  spdm_secured_message_context    A pointer to the SPDM secured message context.
+     245                 :            :  * @param  session_keys                  Indicate the buffer to store the session_keys in libspdm_secure_session_keys_struct_t.
+     246                 :            :  * @param  session_keys_size              The size in bytes of the session_keys in libspdm_secure_session_keys_struct_t.
+     247                 :            :  *
+     248                 :            :  * @retval RETURN_SUCCESS  session_keys are exported.
+     249                 :            :  */
+     250                 :          0 : bool libspdm_secured_message_export_session_keys(void *spdm_secured_message_context,
+     251                 :            :                                                  void *session_keys,
+     252                 :            :                                                  size_t *session_keys_size)
+     253                 :            : {
+     254                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     255                 :            :     size_t struct_size;
+     256                 :            :     libspdm_secure_session_keys_struct_t *session_keys_struct;
+     257                 :            :     uint8_t *ptr;
+     258                 :            : 
+     259                 :          0 :     secured_message_context = spdm_secured_message_context;
+     260                 :          0 :     struct_size = sizeof(libspdm_secure_session_keys_struct_t) +
+     261                 :          0 :                   (secured_message_context->aead_key_size +
+     262                 :          0 :                    secured_message_context->aead_iv_size + sizeof(uint64_t)) * 2;
+     263                 :            : 
+     264         [ #  # ]:          0 :     if (*session_keys_size < struct_size) {
+     265                 :          0 :         *session_keys_size = struct_size;
+     266                 :          0 :         return false;
+     267                 :            :     }
+     268                 :            : 
+     269                 :          0 :     session_keys_struct = session_keys;
+     270                 :          0 :     session_keys_struct->version = LIBSPDM_SECURE_SESSION_KEYS_STRUCT_VERSION;
+     271                 :          0 :     session_keys_struct->aead_key_size = (uint32_t)secured_message_context->aead_key_size;
+     272                 :          0 :     session_keys_struct->aead_iv_size =  (uint32_t)secured_message_context->aead_iv_size;
+     273                 :            : 
+     274                 :          0 :     ptr = (void *)(session_keys_struct + 1);
+     275                 :          0 :     libspdm_copy_mem(ptr,
+     276                 :          0 :                      *session_keys_size - (ptr - (uint8_t*)session_keys),
+     277                 :          0 :                      secured_message_context->application_secret.request_data_encryption_key,
+     278                 :            :                      secured_message_context->aead_key_size);
+     279                 :          0 :     ptr += secured_message_context->aead_key_size;
+     280                 :          0 :     libspdm_copy_mem(ptr,
+     281                 :          0 :                      *session_keys_size - (ptr - (uint8_t*)session_keys),
+     282                 :          0 :                      secured_message_context->application_secret.request_data_salt,
+     283                 :            :                      secured_message_context->aead_iv_size);
+     284                 :          0 :     ptr += secured_message_context->aead_iv_size;
+     285                 :          0 :     libspdm_copy_mem(ptr,
+     286                 :          0 :                      *session_keys_size - (ptr - (uint8_t*)session_keys),
+     287                 :          0 :                      &secured_message_context->application_secret.request_data_sequence_number,
+     288                 :            :                      sizeof(uint64_t));
+     289                 :          0 :     ptr += sizeof(uint64_t);
+     290                 :          0 :     libspdm_copy_mem(ptr,
+     291                 :          0 :                      *session_keys_size - (ptr - (uint8_t*)session_keys),
+     292                 :          0 :                      secured_message_context->application_secret.response_data_encryption_key,
+     293                 :            :                      secured_message_context->aead_key_size);
+     294                 :          0 :     ptr += secured_message_context->aead_key_size;
+     295                 :          0 :     libspdm_copy_mem(ptr,
+     296                 :          0 :                      *session_keys_size - (ptr - (uint8_t*)session_keys),
+     297                 :          0 :                      secured_message_context->application_secret.response_data_salt,
+     298                 :            :                      secured_message_context->aead_iv_size);
+     299                 :          0 :     ptr += secured_message_context->aead_iv_size;
+     300                 :          0 :     libspdm_copy_mem(ptr,
+     301                 :          0 :                      *session_keys_size - (ptr - (uint8_t*)session_keys),
+     302                 :          0 :                      &secured_message_context->application_secret.response_data_sequence_number,
+     303                 :            :                      sizeof(uint64_t));
+     304                 :          0 :     ptr += sizeof(uint64_t);
+     305                 :          0 :     return true;
+     306                 :            : }
+     307                 :            : 
+     308                 :            : /**
+     309                 :            :  * Import the session_keys from an SPDM secured message context.
+     310                 :            :  *
+     311                 :            :  * @param  spdm_secured_message_context    A pointer to the SPDM secured message context.
+     312                 :            :  * @param  session_keys                  Indicate the buffer to store the session_keys in libspdm_secure_session_keys_struct_t.
+     313                 :            :  * @param  session_keys_size              The size in bytes of the session_keys in libspdm_secure_session_keys_struct_t.
+     314                 :            :  *
+     315                 :            :  * @retval RETURN_SUCCESS  session_keys are imported.
+     316                 :            :  */
+     317                 :            : bool
+     318                 :          0 : libspdm_secured_message_import_session_keys(void *spdm_secured_message_context,
+     319                 :            :                                             const void *session_keys,
+     320                 :            :                                             size_t session_keys_size)
+     321                 :            : {
+     322                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     323                 :            :     size_t struct_size;
+     324                 :            :     const libspdm_secure_session_keys_struct_t *session_keys_struct;
+     325                 :            :     const uint8_t *ptr;
+     326                 :            : 
+     327                 :          0 :     secured_message_context = spdm_secured_message_context;
+     328                 :          0 :     struct_size = sizeof(libspdm_secure_session_keys_struct_t) +
+     329                 :          0 :                   (secured_message_context->aead_key_size +
+     330                 :          0 :                    secured_message_context->aead_iv_size + sizeof(uint64_t)) * 2;
+     331                 :            : 
+     332         [ #  # ]:          0 :     if (session_keys_size != struct_size) {
+     333                 :          0 :         return false;
+     334                 :            :     }
+     335                 :            : 
+     336                 :          0 :     session_keys_struct = session_keys;
+     337         [ #  # ]:          0 :     if ((session_keys_struct->version !=
+     338                 :          0 :          LIBSPDM_SECURE_SESSION_KEYS_STRUCT_VERSION) ||
+     339                 :          0 :         (session_keys_struct->aead_key_size !=
+     340         [ #  # ]:          0 :          secured_message_context->aead_key_size) ||
+     341                 :          0 :         (session_keys_struct->aead_iv_size !=
+     342         [ #  # ]:          0 :          secured_message_context->aead_iv_size)) {
+     343                 :          0 :         return false;
+     344                 :            :     }
+     345                 :            : 
+     346                 :          0 :     ptr = (const void *)(session_keys_struct + 1);
+     347                 :          0 :     libspdm_copy_mem(secured_message_context->application_secret.request_data_encryption_key,
+     348                 :            :                      sizeof(secured_message_context->application_secret
+     349                 :            :                             .request_data_encryption_key),
+     350                 :            :                      ptr, secured_message_context->aead_key_size);
+     351                 :          0 :     ptr += secured_message_context->aead_key_size;
+     352                 :          0 :     libspdm_copy_mem(secured_message_context->application_secret.request_data_salt,
+     353                 :            :                      sizeof(secured_message_context->application_secret
+     354                 :            :                             .request_data_salt),
+     355                 :            :                      ptr, secured_message_context->aead_iv_size);
+     356                 :          0 :     ptr += secured_message_context->aead_iv_size;
+     357                 :          0 :     libspdm_copy_mem(&secured_message_context->application_secret.request_data_sequence_number,
+     358                 :            :                      sizeof(secured_message_context->application_secret
+     359                 :            :                             .request_data_sequence_number),
+     360                 :            :                      ptr, sizeof(uint64_t));
+     361                 :          0 :     ptr += sizeof(uint64_t);
+     362                 :          0 :     libspdm_copy_mem(secured_message_context->application_secret
+     363                 :          0 :                      .response_data_encryption_key,
+     364                 :            :                      sizeof(secured_message_context->application_secret
+     365                 :            :                             .response_data_encryption_key),
+     366                 :            :                      ptr, secured_message_context->aead_key_size);
+     367                 :          0 :     ptr += secured_message_context->aead_key_size;
+     368                 :          0 :     libspdm_copy_mem(secured_message_context->application_secret.response_data_salt,
+     369                 :            :                      sizeof(secured_message_context->application_secret.response_data_salt),
+     370                 :            :                      ptr, secured_message_context->aead_iv_size);
+     371                 :          0 :     ptr += secured_message_context->aead_iv_size;
+     372                 :          0 :     libspdm_copy_mem(&secured_message_context->application_secret.response_data_sequence_number,
+     373                 :            :                      sizeof(secured_message_context->application_secret
+     374                 :            :                             .response_data_sequence_number),
+     375                 :            :                      ptr, sizeof(uint64_t));
+     376                 :          0 :     ptr += sizeof(uint64_t);
+     377                 :          0 :     return true;
+     378                 :            : }
+     379                 :            : 
+     380                 :            : /**
+     381                 :            :  * Get the last SPDM error struct of an SPDM context.
+     382                 :            :  *
+     383                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     384                 :            :  * @param  last_spdm_error                Last SPDM error struct of an SPDM context.
+     385                 :            :  */
+     386                 :         28 : void libspdm_secured_message_get_last_spdm_error_struct(
+     387                 :            :     void *spdm_secured_message_context,
+     388                 :            :     libspdm_error_struct_t *last_spdm_error)
+     389                 :            : {
+     390                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     391                 :            : 
+     392                 :         28 :     secured_message_context = spdm_secured_message_context;
+     393                 :         28 :     libspdm_copy_mem(last_spdm_error, sizeof(libspdm_error_struct_t),
+     394                 :         28 :                      &secured_message_context->last_spdm_error,
+     395                 :            :                      sizeof(libspdm_error_struct_t));
+     396                 :         28 : }
+     397                 :            : 
+     398                 :            : /**
+     399                 :            :  * Set the last SPDM error struct of an SPDM context.
+     400                 :            :  *
+     401                 :            :  * @param  spdm_context                  A pointer to the SPDM context.
+     402                 :            :  * @param  last_spdm_error                Last SPDM error struct of an SPDM context.
+     403                 :            :  */
+     404                 :        327 : void libspdm_secured_message_set_last_spdm_error_struct(
+     405                 :            :     void *spdm_secured_message_context,
+     406                 :            :     const libspdm_error_struct_t *last_spdm_error)
+     407                 :            : {
+     408                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     409                 :            : 
+     410                 :        327 :     secured_message_context = spdm_secured_message_context;
+     411                 :        327 :     libspdm_copy_mem(&secured_message_context->last_spdm_error,
+     412                 :            :                      sizeof(secured_message_context->last_spdm_error),
+     413                 :            :                      last_spdm_error,
+     414                 :            :                      sizeof(libspdm_error_struct_t));
+     415                 :        327 : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_secured_message_lib/libspdm_secmes_encode_decode.c.func-sort-c.html b/coverage_log/library/spdm_secured_message_lib/libspdm_secmes_encode_decode.c.func-sort-c.html new file mode 100644 index 00000000000..d6080db8621 --- /dev/null +++ b/coverage_log/library/spdm_secured_message_lib/libspdm_secmes_encode_decode.c.func-sort-c.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - library/spdm_secured_message_lib/libspdm_secmes_encode_decode.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_secured_message_lib - libspdm_secmes_encode_decode.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:18432856.1 %
Date:2024-09-22 08:21:07Functions:4580.0 %
Branches:6815843.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
swap_endian0
is_sequence_number_endian_determined325
libspdm_decode_secured_message326
libspdm_encode_secured_message464
generate_iv790
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_secured_message_lib/libspdm_secmes_encode_decode.c.func.html b/coverage_log/library/spdm_secured_message_lib/libspdm_secmes_encode_decode.c.func.html new file mode 100644 index 00000000000..93f9e43e098 --- /dev/null +++ b/coverage_log/library/spdm_secured_message_lib/libspdm_secmes_encode_decode.c.func.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - library/spdm_secured_message_lib/libspdm_secmes_encode_decode.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_secured_message_lib - libspdm_secmes_encode_decode.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:18432856.1 %
Date:2024-09-22 08:21:07Functions:4580.0 %
Branches:6815843.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
generate_iv790
is_sequence_number_endian_determined325
libspdm_decode_secured_message326
libspdm_encode_secured_message464
swap_endian0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_secured_message_lib/libspdm_secmes_encode_decode.c.gcov.html b/coverage_log/library/spdm_secured_message_lib/libspdm_secmes_encode_decode.c.gcov.html new file mode 100644 index 00000000000..231f058994e --- /dev/null +++ b/coverage_log/library/spdm_secured_message_lib/libspdm_secmes_encode_decode.c.gcov.html @@ -0,0 +1,774 @@ + + + + + + + LCOV - coverage.info - library/spdm_secured_message_lib/libspdm_secmes_encode_decode.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_secured_message_lib - libspdm_secmes_encode_decode.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:18432856.1 %
Date:2024-09-22 08:21:07Functions:4580.0 %
Branches:6815843.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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_secured_message_lib.h"
+       8                 :            : 
+       9                 :        790 : static void generate_iv(uint64_t sequence_number, uint8_t *iv, const uint8_t *salt,
+      10                 :            :                         size_t aead_iv_size, uint8_t endian)
+      11                 :            : {
+      12                 :            :     uint8_t iv_temp[LIBSPDM_MAX_AEAD_IV_SIZE];
+      13                 :            :     size_t index;
+      14                 :            : 
+      15                 :            :     /* Form the AEAD IV from the salt and the sequence number. */
+      16                 :        790 :     libspdm_copy_mem(iv, LIBSPDM_MAX_AEAD_IV_SIZE, salt, aead_iv_size);
+      17                 :            : 
+      18      [ +  -  - ]:        790 :     switch (endian) {
+      19                 :        790 :     case LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_LITTLE_DEC_LITTLE:
+      20                 :            :     case LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_LITTLE_DEC_BOTH:
+      21                 :            :         /* If little-endian then the sequence number is zero-extended to the higher indices.
+      22                 :            :          * The sequence number begins at the lowest index (0). */
+      23                 :        790 :         libspdm_copy_mem(iv_temp, sizeof(iv_temp), &sequence_number, sizeof(sequence_number));
+      24         [ +  + ]:       7110 :         for (index = 0; index < sizeof(sequence_number); index++) {
+      25                 :       6320 :             iv[index] = iv[index] ^ iv_temp[index];
+      26                 :            :         }
+      27                 :        790 :         break;
+      28                 :          0 :     case LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_BIG_DEC_BIG:
+      29                 :            :     case LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_BIG_DEC_BOTH:
+      30                 :            :         /* If big-endian then the sequence number is zero-extended to the lower indices.
+      31                 :            :          * The sequence number ends at the highest index (aead_size - 1). */
+      32                 :          0 :         sequence_number = libspdm_le_to_be_64(sequence_number);
+      33                 :          0 :         libspdm_copy_mem(iv_temp + (aead_iv_size - sizeof(sequence_number)),
+      34                 :            :                          aead_iv_size,
+      35                 :            :                          &sequence_number,
+      36                 :            :                          sizeof(sequence_number));
+      37         [ #  # ]:          0 :         for (index = aead_iv_size - sizeof(sequence_number); index < aead_iv_size; index++) {
+      38                 :          0 :             iv[index] = iv[index] ^ iv_temp[index];
+      39                 :            :         }
+      40                 :          0 :         break;
+      41                 :            :     }
+      42                 :        790 : }
+      43                 :            : 
+      44                 :          0 : static uint8_t swap_endian(uint8_t endian)
+      45                 :            : {
+      46      [ #  #  # ]:          0 :     switch (endian) {
+      47                 :          0 :     case LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_LITTLE_DEC_BOTH:
+      48                 :          0 :         return LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_BIG_DEC_BIG;
+      49                 :          0 :     case LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_BIG_DEC_BOTH:
+      50                 :          0 :         return LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_LITTLE_DEC_LITTLE;
+      51                 :          0 :     default:
+      52                 :          0 :         LIBSPDM_ASSERT(0);
+      53                 :          0 :         return 0;
+      54                 :            :     }
+      55                 :            : }
+      56                 :            : 
+      57                 :        325 : static bool is_sequence_number_endian_determined(uint8_t endian)
+      58                 :            : {
+      59                 :            :     return ((endian == LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_BIG_DEC_BIG) ||
+      60   [ +  -  +  - ]:        325 :             (endian == LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_LITTLE_DEC_LITTLE)) ? true : false;
+      61                 :            : }
+      62                 :            : 
+      63                 :            : /**
+      64                 :            :  * Encode an application message to a secured message.
+      65                 :            :  *
+      66                 :            :  * @param  spdm_secured_message_context    A pointer to the SPDM secured message context.
+      67                 :            :  * @param  session_id                      The session ID of the SPDM session.
+      68                 :            :  * @param  is_request_message              Indicates if it is a request message.
+      69                 :            :  * @param  app_message_size                size in bytes of the application message data buffer.
+      70                 :            :  * @param  app_message                     A pointer to a source buffer to store the application message.
+      71                 :            :  *                                         It shall point to the scratch buffer in spdm_context.
+      72                 :            :  *                                         On input, the app_message pointer shall point to a big enough buffer.
+      73                 :            :  *                                         Before app_message, there is room for spdm_secured_message_cipher_header_t.
+      74                 :            :  *                                         After (app_message + app_message_size), there is room for random bytes.
+      75                 :            :  * @param  secured_message_size            size in bytes of the secured message data buffer.
+      76                 :            :  * @param  secured_message                 A pointer to a destination buffer to store the secured message.
+      77                 :            :  *                                         It shall point to the acquired sender buffer.
+      78                 :            :  * @param  spdm_secured_message_callbacks  A pointer to a secured message callback functions structure.
+      79                 :            :  *
+      80                 :            :  * @retval RETURN_SUCCESS               The application message is encoded successfully.
+      81                 :            :  * @retval RETURN_INVALID_PARAMETER     The message is NULL or the message_size is zero.
+      82                 :            :  **/
+      83                 :        464 : libspdm_return_t libspdm_encode_secured_message(
+      84                 :            :     void *spdm_secured_message_context, uint32_t session_id,
+      85                 :            :     bool is_request_message, size_t app_message_size,
+      86                 :            :     void *app_message, size_t *secured_message_size,
+      87                 :            :     void *secured_message,
+      88                 :            :     const libspdm_secured_message_callbacks_t *spdm_secured_message_callbacks)
+      89                 :            : {
+      90                 :            :     libspdm_secured_message_context_t *secured_message_context;
+      91                 :            :     size_t total_secured_message_size;
+      92                 :            :     size_t plain_text_size;
+      93                 :            :     size_t cipher_text_size;
+      94                 :            :     size_t aead_tag_size;
+      95                 :            :     size_t aead_key_size;
+      96                 :            :     size_t aead_iv_size;
+      97                 :            :     uint8_t *a_data;
+      98                 :            :     uint8_t *enc_msg;
+      99                 :            :     uint8_t *dec_msg;
+     100                 :            :     uint8_t *tag;
+     101                 :            :     spdm_secured_message_a_data_header1_t *record_header1;
+     102                 :            :     spdm_secured_message_a_data_header2_t *record_header2;
+     103                 :            :     size_t record_header_size;
+     104                 :            :     spdm_secured_message_cipher_header_t *enc_msg_header;
+     105                 :            :     bool result;
+     106                 :            :     const uint8_t *key;
+     107                 :            :     uint8_t *salt;
+     108                 :            :     uint8_t iv[LIBSPDM_MAX_AEAD_IV_SIZE];
+     109                 :            :     uint64_t sequence_number;
+     110                 :            :     uint64_t sequence_num_in_header;
+     111                 :            :     uint8_t sequence_num_in_header_size;
+     112                 :            :     libspdm_session_type_t session_type;
+     113                 :            :     uint32_t rand_count;
+     114                 :            :     uint32_t max_rand_count;
+     115                 :            :     libspdm_session_state_t session_state;
+     116                 :            :     spdm_version_number_t secured_spdm_version;
+     117                 :            :     uint8_t version;
+     118                 :            : 
+     119                 :        464 :     secured_message_context = spdm_secured_message_context;
+     120                 :        464 :     secured_spdm_version = spdm_secured_message_callbacks->get_secured_spdm_version(
+     121                 :        464 :         secured_message_context->secured_message_version);
+     122                 :        464 :     version = (uint8_t)(secured_spdm_version >> SPDM_VERSION_NUMBER_SHIFT_BIT);
+     123         [ -  + ]:        464 :     if (version > SECURED_SPDM_VERSION_12) {
+     124                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     125                 :            :     }
+     126                 :            : 
+     127                 :        464 :     session_type = secured_message_context->session_type;
+     128   [ +  -  -  + ]:        464 :     LIBSPDM_ASSERT((session_type == LIBSPDM_SESSION_TYPE_MAC_ONLY) ||
+     129                 :            :                    (session_type == LIBSPDM_SESSION_TYPE_ENC_MAC));
+     130                 :        464 :     session_state = secured_message_context->session_state;
+     131   [ +  +  -  + ]:        464 :     LIBSPDM_ASSERT((session_state == LIBSPDM_SESSION_STATE_HANDSHAKING) ||
+     132                 :            :                    (session_state == LIBSPDM_SESSION_STATE_ESTABLISHED));
+     133                 :            : 
+     134                 :        464 :     aead_tag_size = secured_message_context->aead_tag_size;
+     135                 :        464 :     aead_key_size = secured_message_context->aead_key_size;
+     136                 :        464 :     aead_iv_size = secured_message_context->aead_iv_size;
+     137                 :            : 
+     138      [ +  +  - ]:        464 :     switch (session_state) {
+     139                 :         67 :     case LIBSPDM_SESSION_STATE_HANDSHAKING:
+     140         [ +  + ]:         67 :         if (is_request_message) {
+     141                 :         34 :             key = (const uint8_t *)secured_message_context->handshake_secret.
+     142                 :            :                   request_handshake_encryption_key;
+     143                 :         34 :             salt = (uint8_t *)secured_message_context->handshake_secret.
+     144                 :            :                    request_handshake_salt;
+     145                 :         34 :             sequence_number = secured_message_context->handshake_secret
+     146                 :            :                               .request_handshake_sequence_number;
+     147                 :            :         } else {
+     148                 :         33 :             key = (const uint8_t *)secured_message_context->handshake_secret.
+     149                 :            :                   response_handshake_encryption_key;
+     150                 :         33 :             salt = (uint8_t *)secured_message_context->handshake_secret.
+     151                 :            :                    response_handshake_salt;
+     152                 :         33 :             sequence_number = secured_message_context->handshake_secret
+     153                 :            :                               .response_handshake_sequence_number;
+     154                 :            :         }
+     155                 :         67 :         break;
+     156                 :        397 :     case LIBSPDM_SESSION_STATE_ESTABLISHED:
+     157         [ +  + ]:        397 :         if (is_request_message) {
+     158                 :        200 :             key = (const uint8_t *)secured_message_context->application_secret.
+     159                 :            :                   request_data_encryption_key;
+     160                 :        200 :             salt = (uint8_t *)secured_message_context->application_secret.
+     161                 :            :                    request_data_salt;
+     162                 :        200 :             sequence_number = secured_message_context->application_secret
+     163                 :            :                               .request_data_sequence_number;
+     164                 :            :         } else {
+     165                 :        197 :             key = (const uint8_t *)secured_message_context->application_secret.
+     166                 :            :                   response_data_encryption_key;
+     167                 :        197 :             salt = (uint8_t *)secured_message_context->application_secret.
+     168                 :            :                    response_data_salt;
+     169                 :        197 :             sequence_number = secured_message_context->application_secret
+     170                 :            :                               .response_data_sequence_number;
+     171                 :            :         }
+     172                 :        397 :         break;
+     173                 :          0 :     default:
+     174                 :          0 :         LIBSPDM_ASSERT(false);
+     175                 :          0 :         return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+     176                 :            :         break;
+     177                 :            :     }
+     178                 :            : 
+     179         [ -  + ]:        464 :     if (sequence_number >= secured_message_context->max_spdm_session_sequence_number) {
+     180                 :          0 :         return LIBSPDM_STATUS_SEQUENCE_NUMBER_OVERFLOW;
+     181                 :            :     }
+     182                 :            : 
+     183                 :        464 :     generate_iv(sequence_number, iv, salt, aead_iv_size,
+     184                 :        464 :                 secured_message_context->sequence_number_endian);
+     185                 :            : 
+     186                 :        464 :     sequence_num_in_header = 0;
+     187                 :        464 :     sequence_num_in_header_size = spdm_secured_message_callbacks->get_sequence_number(
+     188                 :            :         sequence_number, (uint8_t *)&sequence_num_in_header);
+     189         [ -  + ]:        464 :     LIBSPDM_ASSERT(sequence_num_in_header_size <= sizeof(sequence_num_in_header));
+     190                 :            : 
+     191         [ +  + ]:        464 :     if (session_state == LIBSPDM_SESSION_STATE_HANDSHAKING) {
+     192         [ +  + ]:         67 :         if (is_request_message) {
+     193                 :         34 :             secured_message_context->handshake_secret.request_handshake_sequence_number++;
+     194                 :            :         } else {
+     195                 :         33 :             secured_message_context->handshake_secret.response_handshake_sequence_number++;
+     196                 :            :         }
+     197                 :            :     } else {
+     198         [ +  + ]:        397 :         if (is_request_message) {
+     199                 :        200 :             secured_message_context->application_secret.request_data_sequence_number++;
+     200                 :            :         } else {
+     201                 :        197 :             secured_message_context->application_secret.response_data_sequence_number++;
+     202                 :            :         }
+     203                 :            :     }
+     204                 :            : 
+     205                 :        464 :     record_header_size = sizeof(spdm_secured_message_a_data_header1_t) +
+     206                 :        464 :                          sequence_num_in_header_size +
+     207                 :            :                          sizeof(spdm_secured_message_a_data_header2_t);
+     208                 :            : 
+     209      [ +  -  - ]:        464 :     switch (session_type) {
+     210                 :        464 :     case LIBSPDM_SESSION_TYPE_ENC_MAC:
+     211                 :        464 :         max_rand_count = spdm_secured_message_callbacks->get_max_random_number_count();
+     212         [ +  - ]:        464 :         if (max_rand_count != 0) {
+     213                 :        464 :             rand_count = 0;
+     214                 :        464 :             result = libspdm_get_random_number(sizeof(rand_count), (uint8_t *)&rand_count);
+     215         [ -  + ]:        464 :             if (!result) {
+     216                 :          0 :                 return LIBSPDM_STATUS_LOW_ENTROPY;
+     217                 :            :             }
+     218                 :        464 :             rand_count = (uint8_t)((rand_count % max_rand_count) + 1);
+     219                 :            :         } else {
+     220                 :          0 :             rand_count = 0;
+     221                 :            :         }
+     222                 :            : 
+     223                 :        464 :         plain_text_size = sizeof(spdm_secured_message_cipher_header_t) + app_message_size +
+     224                 :            :                           rand_count;
+     225                 :        464 :         cipher_text_size = plain_text_size;
+     226                 :        464 :         total_secured_message_size = record_header_size + cipher_text_size + aead_tag_size;
+     227                 :            : 
+     228         [ -  + ]:        464 :         LIBSPDM_ASSERT(*secured_message_size >= total_secured_message_size);
+     229         [ -  + ]:        464 :         if (*secured_message_size < total_secured_message_size) {
+     230                 :          0 :             *secured_message_size = total_secured_message_size;
+     231                 :          0 :             return LIBSPDM_STATUS_BUFFER_TOO_SMALL;
+     232                 :            :         }
+     233                 :        464 :         *secured_message_size = total_secured_message_size;
+     234                 :        464 :         record_header1 = (void *)secured_message;
+     235                 :        464 :         record_header2 = (void *)((uint8_t *)record_header1 +
+     236                 :        464 :                                   sizeof(spdm_secured_message_a_data_header1_t) +
+     237                 :            :                                   sequence_num_in_header_size);
+     238                 :        464 :         record_header1->session_id = session_id;
+     239                 :        464 :         libspdm_copy_mem(record_header1 + 1,
+     240                 :        464 :                          *secured_message_size
+     241                 :        464 :                          - ((uint8_t*)(record_header1 + 1) - (uint8_t*)secured_message),
+     242                 :            :                          &sequence_num_in_header,
+     243                 :            :                          sequence_num_in_header_size);
+     244                 :        464 :         record_header2->length = (uint16_t)(cipher_text_size + aead_tag_size);
+     245                 :            : 
+     246                 :        464 :         enc_msg_header =
+     247                 :            :             (void *)((uint8_t *)app_message - sizeof(spdm_secured_message_cipher_header_t));
+     248                 :        464 :         enc_msg_header->application_data_length = (uint16_t)app_message_size;
+     249                 :        464 :         result = libspdm_get_random_number(rand_count,
+     250                 :            :                                            (uint8_t *)enc_msg_header +
+     251                 :        464 :                                            sizeof(spdm_secured_message_cipher_header_t) +
+     252                 :            :                                            app_message_size);
+     253         [ -  + ]:        464 :         if (!result) {
+     254                 :          0 :             return LIBSPDM_STATUS_LOW_ENTROPY;
+     255                 :            :         }
+     256                 :            : 
+     257                 :        464 :         a_data = (uint8_t *)record_header1;
+     258                 :        464 :         enc_msg = (uint8_t *)(record_header2 + 1);
+     259                 :        464 :         dec_msg = (uint8_t *)enc_msg_header;
+     260                 :        464 :         tag = (uint8_t *)record_header1 + record_header_size +
+     261                 :            :               cipher_text_size;
+     262                 :            : 
+     263                 :        464 :         result = libspdm_aead_encryption(
+     264                 :        464 :             secured_message_context->secured_message_version,
+     265                 :        464 :             secured_message_context->aead_cipher_suite, key,
+     266                 :            :             aead_key_size, iv, aead_iv_size, (uint8_t *)a_data,
+     267                 :            :             record_header_size, dec_msg, cipher_text_size, tag,
+     268                 :            :             aead_tag_size, enc_msg, &cipher_text_size);
+     269                 :        464 :         break;
+     270                 :            : 
+     271                 :          0 :     case LIBSPDM_SESSION_TYPE_MAC_ONLY:
+     272                 :          0 :         total_secured_message_size =
+     273                 :          0 :             record_header_size + app_message_size + aead_tag_size;
+     274                 :            : 
+     275         [ #  # ]:          0 :         LIBSPDM_ASSERT(*secured_message_size >= total_secured_message_size);
+     276         [ #  # ]:          0 :         if (*secured_message_size < total_secured_message_size) {
+     277                 :          0 :             *secured_message_size = total_secured_message_size;
+     278                 :          0 :             return LIBSPDM_STATUS_BUFFER_TOO_SMALL;
+     279                 :            :         }
+     280                 :          0 :         *secured_message_size = total_secured_message_size;
+     281                 :          0 :         record_header1 = (void *)secured_message;
+     282                 :          0 :         record_header2 =
+     283                 :            :             (void *)((uint8_t *)record_header1 +
+     284                 :          0 :                      sizeof(spdm_secured_message_a_data_header1_t) +
+     285                 :            :                      sequence_num_in_header_size);
+     286                 :          0 :         record_header1->session_id = session_id;
+     287                 :          0 :         libspdm_copy_mem(record_header1 + 1,
+     288                 :          0 :                          *secured_message_size
+     289                 :          0 :                          - ((uint8_t*)(record_header1 + 1) - (uint8_t*)secured_message),
+     290                 :            :                          &sequence_num_in_header,
+     291                 :            :                          sequence_num_in_header_size);
+     292                 :          0 :         record_header2->length =
+     293                 :          0 :             (uint16_t)(app_message_size + aead_tag_size);
+     294                 :          0 :         libspdm_copy_mem(record_header2 + 1,
+     295                 :          0 :                          *secured_message_size
+     296                 :          0 :                          - ((uint8_t*)(record_header2 + 1) - (uint8_t*)secured_message),
+     297                 :            :                          app_message, app_message_size);
+     298                 :          0 :         a_data = (uint8_t *)record_header1;
+     299                 :          0 :         tag = (uint8_t *)record_header1 + record_header_size + app_message_size;
+     300                 :            : 
+     301                 :          0 :         result = libspdm_aead_encryption(
+     302                 :          0 :             secured_message_context->secured_message_version,
+     303                 :          0 :             secured_message_context->aead_cipher_suite, key,
+     304                 :            :             aead_key_size, iv, aead_iv_size, (uint8_t *)a_data,
+     305                 :            :             record_header_size + app_message_size, NULL, 0, tag,
+     306                 :            :             aead_tag_size, NULL, NULL);
+     307                 :          0 :         break;
+     308                 :            : 
+     309                 :          0 :     default:
+     310                 :          0 :         LIBSPDM_ASSERT(false);
+     311                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     312                 :            :     }
+     313         [ -  + ]:        464 :     if (!result) {
+     314                 :          0 :         return LIBSPDM_STATUS_CRYPTO_ERROR;
+     315                 :            :     }
+     316                 :        464 :     return LIBSPDM_STATUS_SUCCESS;
+     317                 :            : }
+     318                 :            : 
+     319                 :            : /**
+     320                 :            :  * Decode an application message from a secured message.
+     321                 :            :  *
+     322                 :            :  * @param  spdm_secured_message_context    A pointer to the SPDM secured message context.
+     323                 :            :  * @param  session_id                      The session ID of the SPDM session.
+     324                 :            :  * @param  is_request_message              Indicates if it is a request message.
+     325                 :            :  * @param  secured_message_size            size in bytes of the secured message data buffer.
+     326                 :            :  * @param  secured_message                 A pointer to a source buffer to store the secured message.
+     327                 :            :  *                                         It shall point to the acquired receiver buffer.
+     328                 :            :  * @param  app_message_size                size in bytes of the application message data buffer.
+     329                 :            :  * @param  app_message                     A pointer to a destination buffer to store the application message.
+     330                 :            :  *                                         It shall point to the scratch buffer in spdm_context.
+     331                 :            :  *                                         On input, the app_message pointer shall point to a big enough buffer to hold the decrypted message
+     332                 :            :  *                                         On output, the app_message pointer shall be inside of [app_message, app_message + app_message_size]
+     333                 :            :  * @param  spdm_secured_message_callbacks  A pointer to a secured message callback functions structure.
+     334                 :            :  *
+     335                 :            :  * @retval RETURN_SUCCESS               The application message is decoded successfully.
+     336                 :            :  * @retval RETURN_INVALID_PARAMETER     The message is NULL or the message_size is zero.
+     337                 :            :  * @retval RETURN_UNSUPPORTED           The secured_message is unsupported.
+     338                 :            :  **/
+     339                 :        326 : libspdm_return_t libspdm_decode_secured_message(
+     340                 :            :     void *spdm_secured_message_context, uint32_t session_id,
+     341                 :            :     bool is_request_message, size_t secured_message_size,
+     342                 :            :     void *secured_message, size_t *app_message_size,
+     343                 :            :     void **app_message,
+     344                 :            :     const libspdm_secured_message_callbacks_t *spdm_secured_message_callbacks)
+     345                 :            : {
+     346                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     347                 :            :     size_t plain_text_size;
+     348                 :            :     size_t cipher_text_size;
+     349                 :            :     size_t aead_tag_size;
+     350                 :            :     size_t aead_key_size;
+     351                 :            :     size_t aead_iv_size;
+     352                 :            :     const uint8_t *a_data;
+     353                 :            :     const uint8_t *enc_msg;
+     354                 :            :     uint8_t *dec_msg;
+     355                 :            :     const uint8_t *tag;
+     356                 :            :     spdm_secured_message_a_data_header1_t *record_header1;
+     357                 :            :     spdm_secured_message_a_data_header2_t *record_header2;
+     358                 :            :     size_t record_header_size;
+     359                 :            :     spdm_secured_message_cipher_header_t *enc_msg_header;
+     360                 :            :     bool result;
+     361                 :            :     const uint8_t *key;
+     362                 :            :     uint8_t *salt;
+     363                 :            :     uint8_t iv[LIBSPDM_MAX_AEAD_IV_SIZE];
+     364                 :            :     uint64_t sequence_number;
+     365                 :            :     uint64_t sequence_num_in_header;
+     366                 :            :     uint8_t sequence_num_in_header_size;
+     367                 :            :     libspdm_session_type_t session_type;
+     368                 :            :     libspdm_session_state_t session_state;
+     369                 :            :     libspdm_error_struct_t spdm_error;
+     370                 :            :     spdm_version_number_t secured_spdm_version;
+     371                 :            :     uint8_t version;
+     372                 :            : 
+     373                 :        326 :     spdm_error.error_code = 0;
+     374                 :        326 :     spdm_error.session_id = 0;
+     375                 :        326 :     libspdm_secured_message_set_last_spdm_error_struct(spdm_secured_message_context, &spdm_error);
+     376                 :            : 
+     377                 :        326 :     spdm_error.error_code = SPDM_ERROR_CODE_DECRYPT_ERROR;
+     378                 :        326 :     spdm_error.session_id = session_id;
+     379                 :            : 
+     380                 :        326 :     secured_message_context = spdm_secured_message_context;
+     381                 :        326 :     secured_spdm_version = spdm_secured_message_callbacks->get_secured_spdm_version(
+     382                 :        326 :         secured_message_context->secured_message_version);
+     383                 :        326 :     version = (uint8_t)(secured_spdm_version >> SPDM_VERSION_NUMBER_SHIFT_BIT);
+     384         [ -  + ]:        326 :     if (version > SECURED_SPDM_VERSION_12) {
+     385                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     386                 :            :     }
+     387                 :            : 
+     388                 :        326 :     session_type = secured_message_context->session_type;
+     389   [ +  -  -  + ]:        326 :     LIBSPDM_ASSERT((session_type == LIBSPDM_SESSION_TYPE_MAC_ONLY) ||
+     390                 :            :                    (session_type == LIBSPDM_SESSION_TYPE_ENC_MAC));
+     391                 :        326 :     session_state = secured_message_context->session_state;
+     392   [ +  +  -  + ]:        326 :     LIBSPDM_ASSERT((session_state == LIBSPDM_SESSION_STATE_HANDSHAKING) ||
+     393                 :            :                    (session_state == LIBSPDM_SESSION_STATE_ESTABLISHED));
+     394                 :            : 
+     395                 :        326 :     aead_tag_size = secured_message_context->aead_tag_size;
+     396                 :        326 :     aead_key_size = secured_message_context->aead_key_size;
+     397                 :        326 :     aead_iv_size = secured_message_context->aead_iv_size;
+     398                 :            : 
+     399      [ +  +  - ]:        326 :     switch (session_state) {
+     400                 :         34 :     case LIBSPDM_SESSION_STATE_HANDSHAKING:
+     401         [ +  + ]:         34 :         if (is_request_message) {
+     402                 :          1 :             key = (const uint8_t *)secured_message_context->handshake_secret.
+     403                 :            :                   request_handshake_encryption_key;
+     404                 :          1 :             salt = (uint8_t *)secured_message_context->handshake_secret.
+     405                 :            :                    request_handshake_salt;
+     406                 :          1 :             sequence_number =
+     407                 :            :                 secured_message_context->handshake_secret.request_handshake_sequence_number;
+     408                 :            :         } else {
+     409                 :         33 :             key = (const uint8_t *)secured_message_context->handshake_secret.
+     410                 :            :                   response_handshake_encryption_key;
+     411                 :         33 :             salt = (uint8_t *)secured_message_context->handshake_secret.
+     412                 :            :                    response_handshake_salt;
+     413                 :         33 :             sequence_number =
+     414                 :            :                 secured_message_context->handshake_secret.response_handshake_sequence_number;
+     415                 :            :         }
+     416                 :         34 :         break;
+     417                 :        292 :     case LIBSPDM_SESSION_STATE_ESTABLISHED:
+     418         [ +  + ]:        292 :         if (is_request_message) {
+     419                 :         66 :             key = (const uint8_t *)secured_message_context->application_secret.
+     420                 :            :                   request_data_encryption_key;
+     421                 :         66 :             salt = (uint8_t *)secured_message_context->application_secret.
+     422                 :            :                    request_data_salt;
+     423                 :         66 :             sequence_number =
+     424                 :            :                 secured_message_context->application_secret.request_data_sequence_number;
+     425                 :            :         } else {
+     426                 :        226 :             key = (const uint8_t *)secured_message_context->application_secret.
+     427                 :            :                   response_data_encryption_key;
+     428                 :        226 :             salt = (uint8_t *)secured_message_context->application_secret.
+     429                 :            :                    response_data_salt;
+     430                 :        226 :             sequence_number =
+     431                 :            :                 secured_message_context->application_secret.response_data_sequence_number;
+     432                 :            :         }
+     433                 :        292 :         break;
+     434                 :          0 :     default:
+     435                 :          0 :         LIBSPDM_ASSERT(false);
+     436                 :          0 :         return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
+     437                 :            :     }
+     438                 :            : 
+     439         [ -  + ]:        326 :     if (sequence_number >= secured_message_context->max_spdm_session_sequence_number) {
+     440                 :          0 :         libspdm_secured_message_set_last_spdm_error_struct(
+     441                 :            :             spdm_secured_message_context, &spdm_error);
+     442                 :          0 :         return LIBSPDM_STATUS_SEQUENCE_NUMBER_OVERFLOW;
+     443                 :            :     }
+     444                 :            : 
+     445                 :        326 :     generate_iv(sequence_number, iv, salt, aead_iv_size,
+     446                 :        326 :                 secured_message_context->sequence_number_endian);
+     447                 :            : 
+     448                 :        326 :     sequence_num_in_header = 0;
+     449                 :            :     sequence_num_in_header_size =
+     450                 :        326 :         spdm_secured_message_callbacks->get_sequence_number(
+     451                 :            :             sequence_number, (uint8_t *)&sequence_num_in_header);
+     452         [ -  + ]:        326 :     LIBSPDM_ASSERT(sequence_num_in_header_size <= sizeof(sequence_num_in_header));
+     453                 :            : 
+     454         [ +  + ]:        326 :     if (session_state == LIBSPDM_SESSION_STATE_HANDSHAKING) {
+     455         [ +  + ]:         34 :         if (is_request_message) {
+     456                 :          1 :             secured_message_context->handshake_secret.request_handshake_sequence_number++;
+     457                 :            :         } else {
+     458                 :         33 :             secured_message_context->handshake_secret.response_handshake_sequence_number++;
+     459                 :            :         }
+     460                 :            :     } else {
+     461         [ +  + ]:        292 :         if (is_request_message) {
+     462                 :         66 :             secured_message_context->application_secret.request_data_sequence_number++;
+     463                 :            :         } else {
+     464                 :        226 :             secured_message_context->application_secret.response_data_sequence_number++;
+     465                 :            :         }
+     466                 :            :     }
+     467                 :            : 
+     468                 :        326 :     record_header_size = sizeof(spdm_secured_message_a_data_header1_t) +
+     469                 :        326 :                          sequence_num_in_header_size +
+     470                 :            :                          sizeof(spdm_secured_message_a_data_header2_t);
+     471                 :            : 
+     472      [ +  -  - ]:        326 :     switch (session_type) {
+     473                 :        326 :     case LIBSPDM_SESSION_TYPE_ENC_MAC:
+     474         [ -  + ]:        326 :         if (secured_message_size < record_header_size + aead_tag_size) {
+     475                 :          0 :             libspdm_secured_message_set_last_spdm_error_struct(
+     476                 :            :                 spdm_secured_message_context, &spdm_error);
+     477                 :          0 :             return LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     478                 :            :         }
+     479                 :        326 :         record_header1 = secured_message;
+     480                 :        326 :         record_header2 =
+     481                 :            :             (void *)((uint8_t *)record_header1 +
+     482                 :        326 :                      sizeof(spdm_secured_message_a_data_header1_t) +
+     483                 :            :                      sequence_num_in_header_size);
+     484         [ -  + ]:        326 :         if (record_header1->session_id != session_id) {
+     485                 :          0 :             libspdm_secured_message_set_last_spdm_error_struct(
+     486                 :            :                 spdm_secured_message_context, &spdm_error);
+     487                 :          0 :             return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     488                 :            :         }
+     489         [ +  + ]:        326 :         if (!libspdm_consttime_is_mem_equal(record_header1 + 1, &sequence_num_in_header,
+     490                 :            :                                             sequence_num_in_header_size)) {
+     491                 :          1 :             libspdm_secured_message_set_last_spdm_error_struct(
+     492                 :            :                 spdm_secured_message_context, &spdm_error);
+     493                 :          1 :             return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     494                 :            :         }
+     495         [ -  + ]:        325 :         if (record_header2->length > secured_message_size - record_header_size) {
+     496                 :          0 :             libspdm_secured_message_set_last_spdm_error_struct(
+     497                 :            :                 spdm_secured_message_context, &spdm_error);
+     498                 :          0 :             return LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     499                 :            :         }
+     500         [ -  + ]:        325 :         if (record_header2->length < aead_tag_size) {
+     501                 :          0 :             libspdm_secured_message_set_last_spdm_error_struct(
+     502                 :            :                 spdm_secured_message_context, &spdm_error);
+     503                 :          0 :             return LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     504                 :            :         }
+     505                 :        325 :         cipher_text_size = (record_header2->length - aead_tag_size);
+     506         [ -  + ]:        325 :         if (cipher_text_size > *app_message_size) {
+     507                 :          0 :             return LIBSPDM_STATUS_BUFFER_TOO_SMALL;
+     508                 :            :         }
+     509                 :        325 :         libspdm_zero_mem(*app_message, *app_message_size);
+     510                 :        325 :         enc_msg_header = (void *)(record_header2 + 1);
+     511                 :        325 :         a_data = (const uint8_t *)record_header1;
+     512                 :        325 :         enc_msg = (const uint8_t *)enc_msg_header;
+     513                 :        325 :         dec_msg = (uint8_t *)*app_message;
+     514                 :        325 :         enc_msg_header = (void *)dec_msg;
+     515                 :        325 :         tag = (const uint8_t *)record_header1 + record_header_size + cipher_text_size;
+     516                 :            : 
+     517                 :        325 :         result = libspdm_aead_decryption(
+     518                 :        325 :             secured_message_context->secured_message_version,
+     519                 :        325 :             secured_message_context->aead_cipher_suite, key,
+     520                 :            :             aead_key_size, iv, aead_iv_size, a_data,
+     521                 :            :             record_header_size, enc_msg, cipher_text_size, tag,
+     522                 :            :             aead_tag_size, dec_msg, &cipher_text_size);
+     523                 :            : 
+     524                 :            :         /* When the sequence number is 0 then it has the same encoding in both
+     525                 :            :          * big and little endian. The endianness can only be determined on the subsequent
+     526                 :            :          * decryption. */
+     527         [ -  + ]:        325 :         if (!is_sequence_number_endian_determined(
+     528         [ -  - ]:        325 :                 secured_message_context->sequence_number_endian) && (sequence_number == 1)) {
+     529                 :            : 
+     530                 :          0 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "Sequence number endianness is not determined.\n"));
+     531                 :          0 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "Attempting to determine endianness.\n"));
+     532                 :            : 
+     533         [ #  # ]:          0 :             if (result) {
+     534                 :            :                 /* Endianness is correct so set the endianness. */
+     535         [ #  # ]:          0 :                 if (secured_message_context->sequence_number_endian ==
+     536                 :            :                     LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_LITTLE_DEC_BOTH) {
+     537                 :          0 :                     secured_message_context->sequence_number_endian =
+     538                 :            :                         LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_LITTLE_DEC_LITTLE;
+     539                 :            :                 } else {
+     540                 :          0 :                     secured_message_context->sequence_number_endian =
+     541                 :            :                         LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_BIG_DEC_BIG;
+     542                 :            :                 }
+     543                 :            :             } else {
+     544                 :            :                 /* Endianness may be incorrect so try with the opposite endianness. */
+     545                 :          0 :                 generate_iv(sequence_number, iv, salt, aead_iv_size,
+     546                 :          0 :                             swap_endian(secured_message_context->sequence_number_endian));
+     547                 :            : 
+     548                 :          0 :                 result = libspdm_aead_decryption(
+     549                 :          0 :                     secured_message_context->secured_message_version,
+     550                 :          0 :                     secured_message_context->aead_cipher_suite, key,
+     551                 :            :                     aead_key_size, iv, aead_iv_size, a_data,
+     552                 :            :                     record_header_size, enc_msg, cipher_text_size, tag,
+     553                 :            :                     aead_tag_size, dec_msg, &cipher_text_size);
+     554                 :            : 
+     555         [ #  # ]:          0 :                 if (result) {
+     556                 :            :                     /* Endianness is correct so set the endianness. */
+     557                 :          0 :                     secured_message_context->sequence_number_endian =
+     558                 :          0 :                         swap_endian(secured_message_context->sequence_number_endian);
+     559                 :            :                 }
+     560                 :            :             }
+     561                 :            :         }
+     562                 :            : 
+     563         [ +  + ]:        325 :         if (!result) {
+     564                 :            :             /* Backup keys are valid, fail and alert rollback and retry is possible. */
+     565   [ -  +  -  - ]:         27 :             if ((is_request_message && secured_message_context->requester_backup_valid) ||
+     566   [ +  -  +  - ]:         27 :                 ((!is_request_message) && secured_message_context->responder_backup_valid)) {
+     567                 :         27 :                 return LIBSPDM_STATUS_SESSION_TRY_DISCARD_KEY_UPDATE;
+     568                 :            :             }
+     569                 :            : 
+     570                 :          0 :             libspdm_secured_message_set_last_spdm_error_struct(
+     571                 :            :                 spdm_secured_message_context, &spdm_error);
+     572                 :          0 :             return LIBSPDM_STATUS_CRYPTO_ERROR;
+     573                 :            :         }
+     574                 :        298 :         plain_text_size = enc_msg_header->application_data_length;
+     575         [ -  + ]:        298 :         if (plain_text_size > cipher_text_size) {
+     576                 :          0 :             libspdm_secured_message_set_last_spdm_error_struct(
+     577                 :            :                 spdm_secured_message_context, &spdm_error);
+     578                 :          0 :             return LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     579                 :            :         }
+     580                 :            : 
+     581         [ -  + ]:        298 :         LIBSPDM_ASSERT(*app_message_size >= plain_text_size);
+     582                 :        298 :         *app_message = enc_msg_header + 1;
+     583                 :        298 :         *app_message_size = plain_text_size;
+     584                 :        298 :         break;
+     585                 :            : 
+     586                 :          0 :     case LIBSPDM_SESSION_TYPE_MAC_ONLY:
+     587         [ #  # ]:          0 :         if (secured_message_size < record_header_size + aead_tag_size) {
+     588                 :          0 :             libspdm_secured_message_set_last_spdm_error_struct(
+     589                 :            :                 spdm_secured_message_context, &spdm_error);
+     590                 :          0 :             return LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     591                 :            :         }
+     592                 :          0 :         record_header1 = secured_message;
+     593                 :          0 :         record_header2 =
+     594                 :            :             (void *)((uint8_t *)record_header1 +
+     595                 :          0 :                      sizeof(spdm_secured_message_a_data_header1_t) +
+     596                 :            :                      sequence_num_in_header_size);
+     597         [ #  # ]:          0 :         if (record_header1->session_id != session_id) {
+     598                 :          0 :             libspdm_secured_message_set_last_spdm_error_struct(
+     599                 :            :                 spdm_secured_message_context, &spdm_error);
+     600                 :          0 :             return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     601                 :            :         }
+     602         [ #  # ]:          0 :         if (!libspdm_consttime_is_mem_equal(record_header1 + 1, &sequence_num_in_header,
+     603                 :            :                                             sequence_num_in_header_size)) {
+     604                 :          0 :             libspdm_secured_message_set_last_spdm_error_struct(
+     605                 :            :                 spdm_secured_message_context, &spdm_error);
+     606                 :          0 :             return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     607                 :            :         }
+     608                 :          0 :         if (record_header2->length >
+     609         [ #  # ]:          0 :             secured_message_size - record_header_size) {
+     610                 :          0 :             libspdm_secured_message_set_last_spdm_error_struct(
+     611                 :            :                 spdm_secured_message_context, &spdm_error);
+     612                 :          0 :             return LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     613                 :            :         }
+     614         [ #  # ]:          0 :         if (record_header2->length < aead_tag_size) {
+     615                 :          0 :             libspdm_secured_message_set_last_spdm_error_struct(
+     616                 :            :                 spdm_secured_message_context, &spdm_error);
+     617                 :          0 :             return LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     618                 :            :         }
+     619                 :          0 :         a_data = (uint8_t *)record_header1;
+     620                 :          0 :         tag = (uint8_t *)record_header1 + record_header_size +
+     621                 :          0 :               record_header2->length - aead_tag_size;
+     622                 :            : 
+     623                 :          0 :         result = libspdm_aead_decryption(
+     624                 :          0 :             secured_message_context->secured_message_version,
+     625                 :          0 :             secured_message_context->aead_cipher_suite, key,
+     626                 :            :             aead_key_size, iv, aead_iv_size, a_data,
+     627                 :          0 :             record_header_size + record_header2->length - aead_tag_size,
+     628                 :            :             NULL, 0, tag, aead_tag_size, NULL, NULL);
+     629                 :            : 
+     630                 :            :         /* When the sequence number is 0 then it has the same encoding in both
+     631                 :            :          * big and little endian. The endianness can only be determined on the subsequent
+     632                 :            :          * decryption. */
+     633         [ #  # ]:          0 :         if (!is_sequence_number_endian_determined(
+     634         [ #  # ]:          0 :                 secured_message_context->sequence_number_endian) && (sequence_number == 1)) {
+     635         [ #  # ]:          0 :             if (result) {
+     636                 :            :                 /* Endianness is correct so set the endianness. */
+     637         [ #  # ]:          0 :                 if (secured_message_context->sequence_number_endian ==
+     638                 :            :                     LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_LITTLE_DEC_BOTH) {
+     639                 :          0 :                     secured_message_context->sequence_number_endian =
+     640                 :            :                         LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_LITTLE_DEC_LITTLE;
+     641                 :            :                 } else {
+     642                 :          0 :                     secured_message_context->sequence_number_endian =
+     643                 :            :                         LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_BIG_DEC_BIG;
+     644                 :            :                 }
+     645                 :            :             } else {
+     646                 :            :                 /* Endianness may be incorrect so try with the opposite endianness. */
+     647                 :          0 :                 generate_iv(sequence_number, iv, salt, aead_iv_size,
+     648                 :          0 :                             swap_endian(secured_message_context->sequence_number_endian));
+     649                 :            : 
+     650                 :          0 :                 result = libspdm_aead_decryption(
+     651                 :          0 :                     secured_message_context->secured_message_version,
+     652                 :          0 :                     secured_message_context->aead_cipher_suite, key,
+     653                 :            :                     aead_key_size, iv, aead_iv_size, a_data,
+     654                 :          0 :                     record_header_size + record_header2->length - aead_tag_size,
+     655                 :            :                     NULL, 0, tag, aead_tag_size, NULL, NULL);
+     656                 :            : 
+     657         [ #  # ]:          0 :                 if (result) {
+     658                 :            :                     /* Endianness is correct so set the endianness. */
+     659                 :          0 :                     secured_message_context->sequence_number_endian =
+     660                 :          0 :                         swap_endian(secured_message_context->sequence_number_endian);
+     661                 :            :                 }
+     662                 :            :             }
+     663                 :            :         }
+     664                 :            : 
+     665         [ #  # ]:          0 :         if (!result) {
+     666                 :            :             /* Backup keys are valid, fail and alert rollback and retry is possible. */
+     667   [ #  #  #  # ]:          0 :             if ((is_request_message && secured_message_context->requester_backup_valid) ||
+     668   [ #  #  #  # ]:          0 :                 ((!is_request_message) && secured_message_context->responder_backup_valid)) {
+     669                 :          0 :                 return LIBSPDM_STATUS_SESSION_TRY_DISCARD_KEY_UPDATE;
+     670                 :            :             }
+     671                 :            : 
+     672                 :          0 :             libspdm_secured_message_set_last_spdm_error_struct(
+     673                 :            :                 spdm_secured_message_context, &spdm_error);
+     674                 :          0 :             return LIBSPDM_STATUS_CRYPTO_ERROR;
+     675                 :            :         }
+     676                 :            : 
+     677                 :          0 :         plain_text_size = record_header2->length - aead_tag_size;
+     678         [ #  # ]:          0 :         LIBSPDM_ASSERT(*app_message_size >= plain_text_size);
+     679                 :          0 :         *app_message = record_header2 + 1;
+     680                 :          0 :         *app_message_size = plain_text_size;
+     681                 :          0 :         break;
+     682                 :            : 
+     683                 :          0 :     default:
+     684                 :          0 :         LIBSPDM_ASSERT(false);
+     685                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     686                 :            :     }
+     687                 :            : 
+     688                 :        298 :     return LIBSPDM_STATUS_SUCCESS;
+     689                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_secured_message_lib/libspdm_secmes_key_exchange.c.func-sort-c.html b/coverage_log/library/spdm_secured_message_lib/libspdm_secmes_key_exchange.c.func-sort-c.html new file mode 100644 index 00000000000..870feb0b1d2 --- /dev/null +++ b/coverage_log/library/spdm_secured_message_lib/libspdm_secmes_key_exchange.c.func-sort-c.html @@ -0,0 +1,97 @@ + + + + + + + LCOV - coverage.info - library/spdm_secured_message_lib/libspdm_secmes_key_exchange.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_secured_message_lib - libspdm_secmes_key_exchange.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:161794.1 %
Date:2024-09-22 08:21:07Functions:44100.0 %
Branches:1250.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_secured_message_dhe_compute_key30
libspdm_secured_message_dhe_free101
libspdm_secured_message_dhe_generate_key101
libspdm_secured_message_dhe_new101
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_secured_message_lib/libspdm_secmes_key_exchange.c.func.html b/coverage_log/library/spdm_secured_message_lib/libspdm_secmes_key_exchange.c.func.html new file mode 100644 index 00000000000..aa1c835801a --- /dev/null +++ b/coverage_log/library/spdm_secured_message_lib/libspdm_secmes_key_exchange.c.func.html @@ -0,0 +1,97 @@ + + + + + + + LCOV - coverage.info - library/spdm_secured_message_lib/libspdm_secmes_key_exchange.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_secured_message_lib - libspdm_secmes_key_exchange.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:161794.1 %
Date:2024-09-22 08:21:07Functions:44100.0 %
Branches:1250.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_secured_message_dhe_compute_key30
libspdm_secured_message_dhe_free101
libspdm_secured_message_dhe_generate_key101
libspdm_secured_message_dhe_new101
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_secured_message_lib/libspdm_secmes_key_exchange.c.gcov.html b/coverage_log/library/spdm_secured_message_lib/libspdm_secmes_key_exchange.c.gcov.html new file mode 100644 index 00000000000..6a93e014d6c --- /dev/null +++ b/coverage_log/library/spdm_secured_message_lib/libspdm_secmes_key_exchange.c.gcov.html @@ -0,0 +1,193 @@ + + + + + + + LCOV - coverage.info - library/spdm_secured_message_lib/libspdm_secmes_key_exchange.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_secured_message_lib - libspdm_secmes_key_exchange.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:161794.1 %
Date:2024-09-22 08:21:07Functions:44100.0 %
Branches:1250.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 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_secured_message_lib.h"
+       8                 :            : 
+       9                 :            : /**
+      10                 :            :  * Allocates and Initializes one Diffie-Hellman Ephemeral (DHE) context for subsequent use,
+      11                 :            :  * based upon negotiated DHE algorithm.
+      12                 :            :  *
+      13                 :            :  * @param  dhe_named_group                SPDM dhe_named_group
+      14                 :            :  * @param  is_initiator                   if the caller is initiator.
+      15                 :            :  *                                       true: initiator
+      16                 :            :  *                                       false: not an initiator
+      17                 :            :  *
+      18                 :            :  * @return  Pointer to the Diffie-Hellman context that has been initialized.
+      19                 :            :  **/
+      20                 :        101 : void *libspdm_secured_message_dhe_new(spdm_version_number_t spdm_version,
+      21                 :            :                                       uint16_t dhe_named_group, bool is_initiator)
+      22                 :            : {
+      23                 :        101 :     return libspdm_dhe_new(spdm_version, dhe_named_group, is_initiator);
+      24                 :            : }
+      25                 :            : 
+      26                 :            : /**
+      27                 :            :  * Release the specified DHE context,
+      28                 :            :  * based upon negotiated DHE algorithm.
+      29                 :            :  *
+      30                 :            :  * @param  dhe_named_group                SPDM dhe_named_group
+      31                 :            :  * @param  dhe_context                   Pointer to the DHE context to be released.
+      32                 :            :  **/
+      33                 :        101 : void libspdm_secured_message_dhe_free(uint16_t dhe_named_group, void *dhe_context)
+      34                 :            : {
+      35                 :        101 :     libspdm_dhe_free(dhe_named_group, dhe_context);
+      36                 :        101 : }
+      37                 :            : 
+      38                 :            : /**
+      39                 :            :  * Generates DHE public key,
+      40                 :            :  * based upon negotiated DHE algorithm.
+      41                 :            :  *
+      42                 :            :  * This function generates random secret exponent, and computes the public key, which is
+      43                 :            :  * returned via parameter public_key and public_key_size. DH context is updated accordingly.
+      44                 :            :  * If the public_key buffer is too small to hold the public key, false is returned and
+      45                 :            :  * public_key_size is set to the required buffer size to obtain the public key.
+      46                 :            :  *
+      47                 :            :  * @param  dhe_named_group                SPDM dhe_named_group
+      48                 :            :  * @param  dhe_context                   Pointer to the DHE context.
+      49                 :            :  * @param  public_key                    Pointer to the buffer to receive generated public key.
+      50                 :            :  * @param  public_key_size                On input, the size of public_key buffer in bytes.
+      51                 :            :  *                                     On output, the size of data returned in public_key buffer in bytes.
+      52                 :            :  *
+      53                 :            :  * @retval true   DHE public key generation succeeded.
+      54                 :            :  * @retval false  DHE public key generation failed.
+      55                 :            :  * @retval false  public_key_size is not large enough.
+      56                 :            :  **/
+      57                 :        101 : bool libspdm_secured_message_dhe_generate_key(uint16_t dhe_named_group,
+      58                 :            :                                               void *dhe_context,
+      59                 :            :                                               uint8_t *public_key,
+      60                 :            :                                               size_t *public_key_size)
+      61                 :            : {
+      62                 :        101 :     return libspdm_dhe_generate_key(dhe_named_group, dhe_context, public_key, public_key_size);
+      63                 :            : }
+      64                 :            : 
+      65                 :            : /**
+      66                 :            :  * Computes exchanged common key,
+      67                 :            :  * based upon negotiated DHE algorithm.
+      68                 :            :  *
+      69                 :            :  * Given peer's public key, this function computes the exchanged common key, based on its own
+      70                 :            :  * context including value of prime modulus and random secret exponent.
+      71                 :            :  *
+      72                 :            :  * @param  dhe_named_group                SPDM dhe_named_group
+      73                 :            :  * @param  dhe_context                   Pointer to the DHE context.
+      74                 :            :  * @param  peer_public_key                Pointer to the peer's public key.
+      75                 :            :  * @param  peer_public_key_size            size of peer's public key in bytes.
+      76                 :            :  * @param  key                          Pointer to the buffer to receive generated key.
+      77                 :            :  * @param  spdm_secured_message_context    A pointer to the SPDM secured message context.
+      78                 :            :  *
+      79                 :            :  * @retval true   DHE exchanged key generation succeeded.
+      80                 :            :  * @retval false  DHE exchanged key generation failed.
+      81                 :            :  * @retval false  key_size is not large enough.
+      82                 :            :  **/
+      83                 :         30 : bool libspdm_secured_message_dhe_compute_key(
+      84                 :            :     uint16_t dhe_named_group, void *dhe_context,
+      85                 :            :     const uint8_t *peer_public, size_t peer_public_size,
+      86                 :            :     void *spdm_secured_message_context)
+      87                 :            : {
+      88                 :            :     libspdm_secured_message_context_t *secured_message_context;
+      89                 :            :     uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+      90                 :            :     size_t final_key_size;
+      91                 :            :     bool ret;
+      92                 :            : 
+      93                 :         30 :     secured_message_context = spdm_secured_message_context;
+      94                 :            : 
+      95                 :         30 :     final_key_size = sizeof(final_key);
+      96                 :         30 :     ret = libspdm_dhe_compute_key(dhe_named_group, dhe_context, peer_public,
+      97                 :            :                                   peer_public_size, final_key,
+      98                 :            :                                   &final_key_size);
+      99         [ -  + ]:         30 :     if (!ret) {
+     100                 :          0 :         return ret;
+     101                 :            :     }
+     102                 :         30 :     libspdm_copy_mem(secured_message_context->master_secret.dhe_secret,
+     103                 :            :                      sizeof(secured_message_context->master_secret.dhe_secret),
+     104                 :            :                      final_key, final_key_size);
+     105                 :         30 :     libspdm_zero_mem(final_key, final_key_size);
+     106                 :         30 :     secured_message_context->dhe_key_size = final_key_size;
+     107                 :         30 :     return true;
+     108                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_secured_message_lib/libspdm_secmes_session.c.func-sort-c.html b/coverage_log/library/spdm_secured_message_lib/libspdm_secmes_session.c.func-sort-c.html new file mode 100644 index 00000000000..fa52f5f1240 --- /dev/null +++ b/coverage_log/library/spdm_secured_message_lib/libspdm_secmes_session.c.func-sort-c.html @@ -0,0 +1,173 @@ + + + + + + + LCOV - coverage.info - library/spdm_secured_message_lib/libspdm_secmes_session.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_secured_message_lib - libspdm_secmes_session.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:32540181.0 %
Date:2024-09-22 08:21:07Functions:112347.8 %
Branches:6610066.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_hmac_duplicate_with_request_finished_key0
libspdm_hmac_duplicate_with_response_finished_key0
libspdm_hmac_final_with_request_finished_key0
libspdm_hmac_final_with_response_finished_key0
libspdm_hmac_free_with_request_finished_key0
libspdm_hmac_free_with_response_finished_key0
libspdm_hmac_init_with_request_finished_key0
libspdm_hmac_init_with_response_finished_key0
libspdm_hmac_new_with_request_finished_key0
libspdm_hmac_new_with_response_finished_key0
libspdm_hmac_update_with_request_finished_key0
libspdm_hmac_update_with_response_finished_key0
libspdm_generate_session_data_key32
libspdm_generate_session_handshake_key56
libspdm_hmac_all_with_response_finished_key73
libspdm_hmac_all_with_request_finished_key89
libspdm_activate_update_session_data_key93
libspdm_create_update_session_data_key102
libspdm_generate_finished_key112
libspdm_clear_handshake_secret201
libspdm_clear_master_secret201
libspdm_generate_aead_key_and_iv278
libspdm_bin_concat1235
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_secured_message_lib/libspdm_secmes_session.c.func.html b/coverage_log/library/spdm_secured_message_lib/libspdm_secmes_session.c.func.html new file mode 100644 index 00000000000..327f19611b8 --- /dev/null +++ b/coverage_log/library/spdm_secured_message_lib/libspdm_secmes_session.c.func.html @@ -0,0 +1,173 @@ + + + + + + + LCOV - coverage.info - library/spdm_secured_message_lib/libspdm_secmes_session.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_secured_message_lib - libspdm_secmes_session.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:32540181.0 %
Date:2024-09-22 08:21:07Functions:112347.8 %
Branches:6610066.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_activate_update_session_data_key93
libspdm_bin_concat1235
libspdm_clear_handshake_secret201
libspdm_clear_master_secret201
libspdm_create_update_session_data_key102
libspdm_generate_aead_key_and_iv278
libspdm_generate_finished_key112
libspdm_generate_session_data_key32
libspdm_generate_session_handshake_key56
libspdm_hmac_all_with_request_finished_key89
libspdm_hmac_all_with_response_finished_key73
libspdm_hmac_duplicate_with_request_finished_key0
libspdm_hmac_duplicate_with_response_finished_key0
libspdm_hmac_final_with_request_finished_key0
libspdm_hmac_final_with_response_finished_key0
libspdm_hmac_free_with_request_finished_key0
libspdm_hmac_free_with_response_finished_key0
libspdm_hmac_init_with_request_finished_key0
libspdm_hmac_init_with_response_finished_key0
libspdm_hmac_new_with_request_finished_key0
libspdm_hmac_new_with_response_finished_key0
libspdm_hmac_update_with_request_finished_key0
libspdm_hmac_update_with_response_finished_key0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/library/spdm_secured_message_lib/libspdm_secmes_session.c.gcov.html b/coverage_log/library/spdm_secured_message_lib/libspdm_secmes_session.c.gcov.html new file mode 100644 index 00000000000..2b4f48772ef --- /dev/null +++ b/coverage_log/library/spdm_secured_message_lib/libspdm_secmes_session.c.gcov.html @@ -0,0 +1,1193 @@ + + + + + + + LCOV - coverage.info - library/spdm_secured_message_lib/libspdm_secmes_session.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - library/spdm_secured_message_lib - libspdm_secmes_session.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:32540181.0 %
Date:2024-09-22 08:21:07Functions:112347.8 %
Branches:6610066.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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_secured_message_lib.h"
+       8                 :            : 
+       9                 :            : /**
+      10                 :            :  * This function concatenates binary data, which is used as info in HKDF expand later.
+      11                 :            :  *
+      12                 :            :  * @param  label        An ascii string label for the libspdm_bin_concat.
+      13                 :            :  * @param  label_size   The size in bytes of the ASCII string label, not including NULL terminator.
+      14                 :            :  * @param  context      A pre-defined hash value as the context for the libspdm_bin_concat.
+      15                 :            :  * @param  length       16 bits length for the libspdm_bin_concat.
+      16                 :            :  * @param  hash_size    The size in bytes of the context hash.
+      17                 :            :  * @param  out_bin      The buffer to store the output binary.
+      18                 :            :  * @param  out_bin_size The size in bytes for the out_bin.
+      19                 :            :  **/
+      20                 :       1235 : void libspdm_bin_concat(spdm_version_number_t spdm_version,
+      21                 :            :                         const char *label, size_t label_size,
+      22                 :            :                         const uint8_t *context, uint16_t length,
+      23                 :            :                         size_t hash_size, uint8_t *out_bin,
+      24                 :            :                         size_t *out_bin_size)
+      25                 :            : {
+      26                 :            :     size_t final_size;
+      27                 :            : 
+      28                 :            :     /* The correct version characters (1.1 or 1.2) will replace the x.x. */
+      29                 :            :     #define LIBSPDM_BIN_CONCAT_LABEL "spdmx.x "
+      30                 :            : 
+      31                 :       1235 :     final_size = sizeof(uint16_t) + sizeof(LIBSPDM_BIN_CONCAT_LABEL) - 1 + label_size;
+      32         [ +  + ]:       1235 :     if (context != NULL) {
+      33                 :        269 :         final_size += hash_size;
+      34                 :            :     }
+      35                 :            : 
+      36         [ -  + ]:       1235 :     LIBSPDM_ASSERT(*out_bin_size >= final_size);
+      37                 :            : 
+      38                 :       1235 :     *out_bin_size = final_size;
+      39                 :            : 
+      40                 :       1235 :     libspdm_copy_mem(out_bin, *out_bin_size, &length, sizeof(uint16_t));
+      41                 :       1235 :     libspdm_copy_mem(out_bin + sizeof(uint16_t), *out_bin_size - sizeof(uint16_t),
+      42                 :            :                      LIBSPDM_BIN_CONCAT_LABEL, sizeof(LIBSPDM_BIN_CONCAT_LABEL) - 1);
+      43                 :            : 
+      44                 :            :     /* Patch the version. */
+      45                 :       1235 :     out_bin[6] = (char)('0' + ((spdm_version >> 12) & 0xF));
+      46                 :       1235 :     out_bin[8] = (char)('0' + ((spdm_version >> 8) & 0xF));
+      47                 :       1235 :     libspdm_copy_mem(out_bin + sizeof(uint16_t) + sizeof(LIBSPDM_BIN_CONCAT_LABEL) - 1,
+      48                 :       1235 :                      *out_bin_size - (sizeof(uint16_t) + sizeof(LIBSPDM_BIN_CONCAT_LABEL) - 1),
+      49                 :            :                      label, label_size);
+      50                 :            : 
+      51         [ +  + ]:       1235 :     if (context != NULL) {
+      52                 :        269 :         libspdm_copy_mem(out_bin + sizeof(uint16_t) + sizeof(LIBSPDM_BIN_CONCAT_LABEL) -
+      53                 :        269 :                          1 + label_size,
+      54                 :        269 :                          *out_bin_size - (sizeof(uint16_t) + sizeof(LIBSPDM_BIN_CONCAT_LABEL) -
+      55                 :            :                                           1 + label_size), context, hash_size);
+      56                 :            :     }
+      57                 :            : 
+      58                 :            :     #undef LIBSPDM_BIN_CONCAT_LABEL
+      59                 :       1235 : }
+      60                 :            : 
+      61                 :            : /**
+      62                 :            :  * This function generates SPDM AEAD key and IV for a session.
+      63                 :            :  *
+      64                 :            :  * @param  spdm_secured_message_context    A pointer to the SPDM secured message context.
+      65                 :            :  * @param  major_secret                  The major secret.
+      66                 :            :  * @param  key                          The buffer to store the AEAD key.
+      67                 :            :  * @param  iv                           The buffer to store the AEAD IV.
+      68                 :            :  *
+      69                 :            :  * @retval RETURN_SUCCESS  SPDM AEAD key and IV for a session is generated.
+      70                 :            :  **/
+      71                 :        278 : bool libspdm_generate_aead_key_and_iv(
+      72                 :            :     libspdm_secured_message_context_t *secured_message_context,
+      73                 :            :     const uint8_t *major_secret, uint8_t *key, uint8_t *iv)
+      74                 :            : {
+      75                 :            :     bool status;
+      76                 :            :     size_t hash_size;
+      77                 :            :     size_t key_length;
+      78                 :            :     size_t iv_length;
+      79                 :            :     uint8_t bin_str5[128];
+      80                 :            :     size_t bin_str5_size;
+      81                 :            :     uint8_t bin_str6[128];
+      82                 :            :     size_t bin_str6_size;
+      83                 :            : 
+      84                 :        278 :     hash_size = secured_message_context->hash_size;
+      85                 :        278 :     key_length = secured_message_context->aead_key_size;
+      86                 :        278 :     iv_length = secured_message_context->aead_iv_size;
+      87                 :            : 
+      88                 :        278 :     bin_str5_size = sizeof(bin_str5);
+      89                 :        278 :     libspdm_bin_concat(secured_message_context->version,
+      90                 :            :                        SPDM_BIN_STR_5_LABEL, sizeof(SPDM_BIN_STR_5_LABEL) - 1,
+      91                 :        278 :                        NULL, (uint16_t)key_length, hash_size, bin_str5,
+      92                 :            :                        &bin_str5_size);
+      93                 :            : 
+      94                 :        278 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "bin_str5 (0x%zx):\n", bin_str5_size));
+      95                 :        278 :     LIBSPDM_INTERNAL_DUMP_HEX(bin_str5, bin_str5_size);
+      96                 :        278 :     status = libspdm_hkdf_expand(secured_message_context->base_hash_algo,
+      97                 :            :                                  major_secret, hash_size, bin_str5,
+      98                 :            :                                  bin_str5_size, key, key_length);
+      99         [ -  + ]:        278 :     if (!status) {
+     100                 :          0 :         return false;
+     101                 :            :     }
+     102                 :        278 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "key (0x%zx) - ", key_length));
+     103                 :        278 :     LIBSPDM_INTERNAL_DUMP_DATA(key, key_length);
+     104                 :        278 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     105                 :            : 
+     106                 :        278 :     bin_str6_size = sizeof(bin_str6);
+     107                 :        278 :     libspdm_bin_concat(secured_message_context->version,
+     108                 :            :                        SPDM_BIN_STR_6_LABEL, sizeof(SPDM_BIN_STR_6_LABEL) - 1,
+     109                 :        278 :                        NULL, (uint16_t)iv_length, hash_size, bin_str6,
+     110                 :            :                        &bin_str6_size);
+     111                 :            : 
+     112                 :        278 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "bin_str6 (0x%zx):\n", bin_str6_size));
+     113                 :        278 :     LIBSPDM_INTERNAL_DUMP_HEX(bin_str6, bin_str6_size);
+     114                 :        278 :     status = libspdm_hkdf_expand(secured_message_context->base_hash_algo,
+     115                 :            :                                  major_secret, hash_size, bin_str6,
+     116                 :            :                                  bin_str6_size, iv, iv_length);
+     117         [ -  + ]:        278 :     if (!status) {
+     118                 :          0 :         return false;
+     119                 :            :     }
+     120                 :        278 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "iv (0x%zx) - ", iv_length));
+     121                 :        278 :     LIBSPDM_INTERNAL_DUMP_DATA(iv, iv_length);
+     122                 :        278 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     123                 :            : 
+     124                 :        278 :     return true;
+     125                 :            : }
+     126                 :            : 
+     127                 :            : /**
+     128                 :            :  * This function generates SPDM finished_key for a session.
+     129                 :            :  *
+     130                 :            :  * @param  spdm_secured_message_context    A pointer to the SPDM secured message context.
+     131                 :            :  * @param  handshake_secret              The handshake secret.
+     132                 :            :  * @param  finished_key                  The buffer to store the finished key.
+     133                 :            :  *
+     134                 :            :  * @retval RETURN_SUCCESS  SPDM finished_key for a session is generated.
+     135                 :            :  **/
+     136                 :        112 : bool libspdm_generate_finished_key(
+     137                 :            :     libspdm_secured_message_context_t *secured_message_context,
+     138                 :            :     const uint8_t *handshake_secret, uint8_t *finished_key)
+     139                 :            : {
+     140                 :            :     bool status;
+     141                 :            :     size_t hash_size;
+     142                 :            :     uint8_t bin_str7[128];
+     143                 :            :     size_t bin_str7_size;
+     144                 :            : 
+     145                 :        112 :     hash_size = secured_message_context->hash_size;
+     146                 :            : 
+     147                 :        112 :     bin_str7_size = sizeof(bin_str7);
+     148                 :        112 :     libspdm_bin_concat(secured_message_context->version,
+     149                 :            :                        SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+     150                 :        112 :                        NULL, (uint16_t)hash_size, hash_size, bin_str7,
+     151                 :            :                        &bin_str7_size);
+     152                 :            : 
+     153                 :        112 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "bin_str7 (0x%zx):\n", bin_str7_size));
+     154                 :        112 :     LIBSPDM_INTERNAL_DUMP_HEX(bin_str7, bin_str7_size);
+     155                 :        112 :     status = libspdm_hkdf_expand(secured_message_context->base_hash_algo,
+     156                 :            :                                  handshake_secret, hash_size, bin_str7,
+     157                 :            :                                  bin_str7_size, finished_key, hash_size);
+     158         [ -  + ]:        112 :     if (!status) {
+     159                 :          0 :         return false;
+     160                 :            :     }
+     161                 :        112 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "finished_key (0x%zx) - ", hash_size));
+     162                 :        112 :     LIBSPDM_INTERNAL_DUMP_DATA(finished_key, hash_size);
+     163                 :        112 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     164                 :            : 
+     165                 :        112 :     return true;
+     166                 :            : }
+     167                 :            : 
+     168                 :            : /**
+     169                 :            :  * This function generates SPDM HandshakeKey for a session.
+     170                 :            :  *
+     171                 :            :  * @param  spdm_secured_message_context    A pointer to the SPDM secured message context.
+     172                 :            :  * @param  th1_hash_data                  th1 hash
+     173                 :            :  *
+     174                 :            :  * @retval RETURN_SUCCESS  SPDM HandshakeKey for a session is generated.
+     175                 :            :  **/
+     176                 :         56 : bool libspdm_generate_session_handshake_key(void *spdm_secured_message_context,
+     177                 :            :                                             const uint8_t *th1_hash_data)
+     178                 :            : {
+     179                 :            :     bool status;
+     180                 :            :     size_t hash_size;
+     181                 :            :     uint8_t bin_str1[128];
+     182                 :            :     size_t bin_str1_size;
+     183                 :            :     uint8_t bin_str2[128];
+     184                 :            :     size_t bin_str2_size;
+     185                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     186                 :            :     uint8_t salt0[LIBSPDM_MAX_HASH_SIZE];
+     187                 :            : 
+     188                 :         56 :     secured_message_context = spdm_secured_message_context;
+     189                 :            : 
+     190                 :         56 :     hash_size = secured_message_context->hash_size;
+     191                 :            : 
+     192         [ +  + ]:         56 :     if (!(secured_message_context->use_psk)) {
+     193                 :         30 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "[DHE Secret]: "));
+     194                 :         30 :         LIBSPDM_INTERNAL_DUMP_HEX_STR(
+     195                 :            :             secured_message_context->master_secret.dhe_secret,
+     196                 :            :             secured_message_context->dhe_key_size);
+     197                 :         30 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     198                 :         30 :         libspdm_zero_mem(salt0, sizeof(salt0));
+     199                 :         30 :         status = libspdm_hkdf_extract(
+     200                 :            :             secured_message_context->base_hash_algo,
+     201                 :         30 :             secured_message_context->master_secret.dhe_secret,
+     202                 :            :             secured_message_context->dhe_key_size,
+     203                 :            :             salt0, hash_size,
+     204                 :         30 :             secured_message_context->master_secret.handshake_secret, hash_size);
+     205         [ -  + ]:         30 :         if (!status) {
+     206                 :          0 :             return false;
+     207                 :            :         }
+     208                 :         30 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "handshake_secret (0x%zx) - ", hash_size));
+     209                 :         30 :         LIBSPDM_INTERNAL_DUMP_DATA(
+     210                 :            :             secured_message_context->master_secret.handshake_secret,
+     211                 :            :             hash_size);
+     212                 :         30 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     213                 :            :     }
+     214                 :            : 
+     215                 :         56 :     bin_str1_size = sizeof(bin_str1);
+     216                 :         56 :     libspdm_bin_concat(secured_message_context->version,
+     217                 :            :                        SPDM_BIN_STR_1_LABEL, sizeof(SPDM_BIN_STR_1_LABEL) - 1,
+     218                 :         56 :                        th1_hash_data, (uint16_t)hash_size, hash_size,
+     219                 :            :                        bin_str1, &bin_str1_size);
+     220                 :            : 
+     221                 :         56 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "bin_str1 (0x%zx):\n", bin_str1_size));
+     222                 :         56 :     LIBSPDM_INTERNAL_DUMP_HEX(bin_str1, bin_str1_size);
+     223                 :            : 
+     224                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
+     225         [ +  + ]:         56 :     if (secured_message_context->use_psk) {
+     226                 :         26 :         status = libspdm_psk_handshake_secret_hkdf_expand(
+     227                 :         26 :             secured_message_context->version,
+     228                 :            :             secured_message_context->base_hash_algo,
+     229                 :         26 :             secured_message_context->psk_hint,
+     230                 :            :             secured_message_context->psk_hint_size, bin_str1,
+     231                 :            :             bin_str1_size,
+     232                 :         26 :             secured_message_context->handshake_secret.request_handshake_secret,
+     233                 :            :             hash_size);
+     234                 :            : 
+     235         [ -  + ]:         26 :         if (!status) {
+     236                 :          0 :             return false;
+     237                 :            :         }
+     238                 :            :     }
+     239                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP */
+     240         [ +  + ]:         56 :     if (!(secured_message_context->use_psk)) {
+     241                 :         30 :         status = libspdm_hkdf_expand(
+     242                 :            :             secured_message_context->base_hash_algo,
+     243                 :         30 :             secured_message_context->master_secret.handshake_secret,
+     244                 :            :             hash_size, bin_str1, bin_str1_size,
+     245                 :         30 :             secured_message_context->handshake_secret.request_handshake_secret,
+     246                 :            :             hash_size);
+     247                 :            : 
+     248         [ -  + ]:         30 :         if (!status) {
+     249                 :          0 :             return false;
+     250                 :            :         }
+     251                 :            :     }
+     252                 :            : 
+     253                 :         56 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "request_handshake_secret (0x%zx) - ", hash_size));
+     254                 :         56 :     LIBSPDM_INTERNAL_DUMP_DATA(secured_message_context->handshake_secret
+     255                 :            :                                .request_handshake_secret,
+     256                 :            :                                hash_size);
+     257                 :         56 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     258                 :         56 :     bin_str2_size = sizeof(bin_str2);
+     259                 :         56 :     libspdm_bin_concat(secured_message_context->version,
+     260                 :            :                        SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+     261                 :         56 :                        th1_hash_data, (uint16_t)hash_size, hash_size,
+     262                 :            :                        bin_str2, &bin_str2_size);
+     263                 :            : 
+     264                 :         56 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "bin_str2 (0x%zx):\n", bin_str2_size));
+     265                 :         56 :     LIBSPDM_INTERNAL_DUMP_HEX(bin_str2, bin_str2_size);
+     266                 :            : 
+     267                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
+     268         [ +  + ]:         56 :     if (secured_message_context->use_psk) {
+     269                 :         26 :         status = libspdm_psk_handshake_secret_hkdf_expand(
+     270                 :         26 :             secured_message_context->version,
+     271                 :            :             secured_message_context->base_hash_algo,
+     272                 :         26 :             secured_message_context->psk_hint,
+     273                 :            :             secured_message_context->psk_hint_size, bin_str2,
+     274                 :            :             bin_str2_size,
+     275                 :         26 :             secured_message_context->handshake_secret.response_handshake_secret,
+     276                 :            :             hash_size);
+     277                 :            : 
+     278         [ -  + ]:         26 :         if (!status) {
+     279                 :          0 :             return false;
+     280                 :            :         }
+     281                 :            :     }
+     282                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP */
+     283         [ +  + ]:         56 :     if (!(secured_message_context->use_psk)) {
+     284                 :         30 :         status = libspdm_hkdf_expand(
+     285                 :            :             secured_message_context->base_hash_algo,
+     286                 :         30 :             secured_message_context->master_secret.handshake_secret,
+     287                 :            :             hash_size, bin_str2, bin_str2_size,
+     288                 :         30 :             secured_message_context->handshake_secret.response_handshake_secret,
+     289                 :            :             hash_size);
+     290                 :            : 
+     291         [ -  + ]:         30 :         if (!status) {
+     292                 :          0 :             return false;
+     293                 :            :         }
+     294                 :            :     }
+     295                 :            : 
+     296                 :         56 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "response_handshake_secret (0x%zx) - ", hash_size));
+     297                 :         56 :     LIBSPDM_INTERNAL_DUMP_DATA(secured_message_context->handshake_secret.response_handshake_secret,
+     298                 :            :                                hash_size);
+     299                 :         56 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     300                 :            : 
+     301                 :         56 :     status = libspdm_generate_finished_key(
+     302                 :            :         secured_message_context,
+     303                 :            :         secured_message_context->handshake_secret
+     304                 :         56 :         .request_handshake_secret,
+     305                 :         56 :         secured_message_context->handshake_secret.request_finished_key);
+     306         [ -  + ]:         56 :     if (!status) {
+     307                 :          0 :         return status;
+     308                 :            :     }
+     309                 :            : 
+     310                 :         56 :     status = libspdm_generate_finished_key(
+     311                 :            :         secured_message_context,
+     312                 :         56 :         secured_message_context->handshake_secret.response_handshake_secret,
+     313                 :         56 :         secured_message_context->handshake_secret.response_finished_key);
+     314         [ -  + ]:         56 :     if (!status) {
+     315                 :          0 :         return status;
+     316                 :            :     }
+     317                 :            : 
+     318                 :         56 :     status = libspdm_generate_aead_key_and_iv(secured_message_context,
+     319                 :            :                                               secured_message_context->handshake_secret
+     320                 :         56 :                                               .request_handshake_secret,
+     321                 :            :                                               secured_message_context->handshake_secret
+     322                 :         56 :                                               .request_handshake_encryption_key,
+     323                 :            :                                               secured_message_context->handshake_secret
+     324                 :         56 :                                               .request_handshake_salt);
+     325         [ -  + ]:         56 :     if (!status) {
+     326                 :          0 :         return status;
+     327                 :            :     }
+     328                 :         56 :     secured_message_context->handshake_secret.request_handshake_sequence_number = 0;
+     329                 :            : 
+     330                 :         56 :     status = libspdm_generate_aead_key_and_iv(
+     331                 :            :         secured_message_context,
+     332                 :         56 :         secured_message_context->handshake_secret.response_handshake_secret,
+     333                 :         56 :         secured_message_context->handshake_secret.response_handshake_encryption_key,
+     334                 :         56 :         secured_message_context->handshake_secret.response_handshake_salt);
+     335         [ -  + ]:         56 :     if (!status) {
+     336                 :          0 :         return status;
+     337                 :            :     }
+     338                 :            : 
+     339                 :         56 :     secured_message_context->handshake_secret.response_handshake_sequence_number = 0;
+     340                 :         56 :     libspdm_zero_mem(secured_message_context->master_secret.dhe_secret, LIBSPDM_MAX_DHE_KEY_SIZE);
+     341                 :            : 
+     342                 :         56 :     return true;
+     343                 :            : }
+     344                 :            : 
+     345                 :            : /**
+     346                 :            :  * This function generates SPDM DataKey for a session.
+     347                 :            :  *
+     348                 :            :  * @param  spdm_secured_message_context    A pointer to the SPDM secured message context.
+     349                 :            :  * @param  th2_hash_data                  th2 hash
+     350                 :            :  *
+     351                 :            :  * @retval RETURN_SUCCESS  SPDM DataKey for a session is generated.
+     352                 :            :  **/
+     353                 :         32 : bool libspdm_generate_session_data_key(void *spdm_secured_message_context,
+     354                 :            :                                        const uint8_t *th2_hash_data)
+     355                 :            : {
+     356                 :            :     bool status;
+     357                 :            :     size_t hash_size;
+     358                 :            :     uint8_t salt1[LIBSPDM_MAX_HASH_SIZE];
+     359                 :            :     uint8_t bin_str0[128];
+     360                 :            :     size_t bin_str0_size;
+     361                 :            :     uint8_t bin_str3[128];
+     362                 :            :     size_t bin_str3_size;
+     363                 :            :     uint8_t bin_str4[128];
+     364                 :            :     size_t bin_str4_size;
+     365                 :            :     uint8_t bin_str8[128];
+     366                 :            :     size_t bin_str8_size;
+     367                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     368                 :            :     uint8_t zero_filled_buffer[LIBSPDM_MAX_HASH_SIZE];
+     369                 :            : 
+     370                 :         32 :     secured_message_context = spdm_secured_message_context;
+     371                 :            : 
+     372                 :         32 :     hash_size = secured_message_context->hash_size;
+     373                 :            : 
+     374         [ +  + ]:         32 :     if (!(secured_message_context->use_psk)) {
+     375                 :         21 :         bin_str0_size = sizeof(bin_str0);
+     376                 :         21 :         libspdm_bin_concat(secured_message_context->version,
+     377                 :            :                            SPDM_BIN_STR_0_LABEL,
+     378                 :            :                            sizeof(SPDM_BIN_STR_0_LABEL) - 1, NULL,
+     379                 :         21 :                            (uint16_t)hash_size, hash_size, bin_str0,
+     380                 :            :                            &bin_str0_size);
+     381                 :            : 
+     382                 :         21 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "bin_str0 (0x%zx):\n", bin_str0_size));
+     383                 :         21 :         LIBSPDM_INTERNAL_DUMP_HEX(bin_str0, bin_str0_size);
+     384                 :            : 
+     385                 :         21 :         status = libspdm_hkdf_expand(
+     386                 :            :             secured_message_context->base_hash_algo,
+     387                 :         21 :             secured_message_context->master_secret.handshake_secret,
+     388                 :            :             hash_size, bin_str0, bin_str0_size, salt1, hash_size);
+     389         [ -  + ]:         21 :         if (!status) {
+     390                 :          0 :             return false;
+     391                 :            :         }
+     392                 :         21 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "salt1 (0x%zx) - ", hash_size));
+     393                 :         21 :         LIBSPDM_INTERNAL_DUMP_DATA(salt1, hash_size);
+     394                 :         21 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     395                 :            : 
+     396                 :         21 :         libspdm_zero_mem(zero_filled_buffer, sizeof(zero_filled_buffer));
+     397                 :         21 :         status = libspdm_hkdf_extract(
+     398                 :            :             secured_message_context->base_hash_algo,
+     399                 :            :             zero_filled_buffer, hash_size, salt1, hash_size,
+     400                 :         21 :             secured_message_context->master_secret.master_secret, hash_size);
+     401         [ -  + ]:         21 :         if (!status) {
+     402                 :          0 :             goto cleanup;
+     403                 :            :         }
+     404                 :         21 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "master_secret (0x%zx) - ", hash_size));
+     405                 :         21 :         LIBSPDM_INTERNAL_DUMP_DATA(
+     406                 :            :             secured_message_context->master_secret.master_secret,
+     407                 :            :             hash_size);
+     408                 :         21 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     409                 :            :     }
+     410                 :            : 
+     411                 :         32 :     bin_str3_size = sizeof(bin_str3);
+     412                 :         32 :     libspdm_bin_concat(secured_message_context->version,
+     413                 :            :                        SPDM_BIN_STR_3_LABEL, sizeof(SPDM_BIN_STR_3_LABEL) - 1,
+     414                 :         32 :                        th2_hash_data, (uint16_t)hash_size, hash_size,
+     415                 :            :                        bin_str3, &bin_str3_size);
+     416                 :            : 
+     417                 :         32 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "bin_str3 (0x%zx):\n", bin_str3_size));
+     418                 :         32 :     LIBSPDM_INTERNAL_DUMP_HEX(bin_str3, bin_str3_size);
+     419                 :            : 
+     420                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
+     421         [ +  + ]:         32 :     if (secured_message_context->use_psk) {
+     422                 :         11 :         status = libspdm_psk_master_secret_hkdf_expand(
+     423                 :         11 :             secured_message_context->version,
+     424                 :            :             secured_message_context->base_hash_algo,
+     425                 :         11 :             secured_message_context->psk_hint,
+     426                 :            :             secured_message_context->psk_hint_size, bin_str3,
+     427                 :            :             bin_str3_size,
+     428                 :         11 :             secured_message_context->application_secret.request_data_secret,
+     429                 :            :             hash_size);
+     430                 :            : 
+     431         [ -  + ]:         11 :         if (!status) {
+     432                 :          0 :             goto cleanup;
+     433                 :            :         }
+     434                 :            :     }
+     435                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP */
+     436         [ +  + ]:         32 :     if (!(secured_message_context->use_psk)) {
+     437                 :         21 :         status = libspdm_hkdf_expand(
+     438                 :            :             secured_message_context->base_hash_algo,
+     439                 :         21 :             secured_message_context->master_secret.master_secret,
+     440                 :            :             hash_size, bin_str3, bin_str3_size,
+     441                 :         21 :             secured_message_context->application_secret.request_data_secret,
+     442                 :            :             hash_size);
+     443                 :            : 
+     444         [ -  + ]:         21 :         if (!status) {
+     445                 :          0 :             goto cleanup;
+     446                 :            :         }
+     447                 :            :     }
+     448                 :            : 
+     449                 :         32 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "request_data_secret (0x%zx) - ", hash_size));
+     450                 :         32 :     LIBSPDM_INTERNAL_DUMP_DATA(
+     451                 :            :         secured_message_context->application_secret.request_data_secret,
+     452                 :            :         hash_size);
+     453                 :         32 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     454                 :         32 :     bin_str4_size = sizeof(bin_str4);
+     455                 :         32 :     libspdm_bin_concat(secured_message_context->version,
+     456                 :            :                        SPDM_BIN_STR_4_LABEL, sizeof(SPDM_BIN_STR_4_LABEL) - 1,
+     457                 :         32 :                        th2_hash_data, (uint16_t)hash_size, hash_size,
+     458                 :            :                        bin_str4, &bin_str4_size);
+     459                 :            : 
+     460                 :         32 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "bin_str4 (0x%zx):\n", bin_str4_size));
+     461                 :         32 :     LIBSPDM_INTERNAL_DUMP_HEX(bin_str4, bin_str4_size);
+     462                 :            : 
+     463                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
+     464         [ +  + ]:         32 :     if (secured_message_context->use_psk) {
+     465                 :         11 :         status = libspdm_psk_master_secret_hkdf_expand(
+     466                 :         11 :             secured_message_context->version,
+     467                 :            :             secured_message_context->base_hash_algo,
+     468                 :         11 :             secured_message_context->psk_hint,
+     469                 :            :             secured_message_context->psk_hint_size, bin_str4,
+     470                 :            :             bin_str4_size,
+     471                 :         11 :             secured_message_context->application_secret.response_data_secret,
+     472                 :            :             hash_size);
+     473                 :            : 
+     474         [ -  + ]:         11 :         if (!status) {
+     475                 :          0 :             goto cleanup;
+     476                 :            :         }
+     477                 :            :     }
+     478                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP */
+     479         [ +  + ]:         32 :     if (!(secured_message_context->use_psk)) {
+     480                 :         21 :         status = libspdm_hkdf_expand(
+     481                 :            :             secured_message_context->base_hash_algo,
+     482                 :         21 :             secured_message_context->master_secret.master_secret,
+     483                 :            :             hash_size, bin_str4, bin_str4_size,
+     484                 :         21 :             secured_message_context->application_secret.response_data_secret,
+     485                 :            :             hash_size);
+     486                 :            : 
+     487         [ -  + ]:         21 :         if (!status) {
+     488                 :          0 :             goto cleanup;
+     489                 :            :         }
+     490                 :            :     }
+     491                 :            : 
+     492                 :         32 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "response_data_secret (0x%zx) - ", hash_size));
+     493                 :         32 :     LIBSPDM_INTERNAL_DUMP_DATA(
+     494                 :            :         secured_message_context->application_secret.response_data_secret,
+     495                 :            :         hash_size);
+     496                 :         32 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     497                 :            : 
+     498                 :         32 :     bin_str8_size = sizeof(bin_str8);
+     499                 :         32 :     libspdm_bin_concat(secured_message_context->version,
+     500                 :            :                        SPDM_BIN_STR_8_LABEL, sizeof(SPDM_BIN_STR_8_LABEL) - 1,
+     501                 :         32 :                        th2_hash_data, (uint16_t)hash_size, hash_size,
+     502                 :            :                        bin_str8, &bin_str8_size);
+     503                 :            : 
+     504                 :         32 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "bin_str8 (0x%zx):\n", bin_str8_size));
+     505                 :         32 :     LIBSPDM_INTERNAL_DUMP_HEX(bin_str8, bin_str8_size);
+     506                 :            : 
+     507                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
+     508         [ +  + ]:         32 :     if (secured_message_context->use_psk) {
+     509                 :         11 :         status = libspdm_psk_master_secret_hkdf_expand(
+     510                 :         11 :             secured_message_context->version,
+     511                 :            :             secured_message_context->base_hash_algo,
+     512                 :         11 :             secured_message_context->psk_hint,
+     513                 :            :             secured_message_context->psk_hint_size, bin_str8,
+     514                 :            :             bin_str8_size,
+     515                 :         11 :             secured_message_context->export_master_secret,
+     516                 :            :             hash_size);
+     517                 :            : 
+     518         [ -  + ]:         11 :         if (!status) {
+     519                 :          0 :             goto cleanup;
+     520                 :            :         }
+     521                 :            :     }
+     522                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP */
+     523         [ +  + ]:         32 :     if (!(secured_message_context->use_psk)) {
+     524                 :         21 :         status = libspdm_hkdf_expand(
+     525                 :            :             secured_message_context->base_hash_algo,
+     526                 :         21 :             secured_message_context->master_secret.master_secret,
+     527                 :            :             hash_size, bin_str8, bin_str8_size,
+     528                 :         21 :             secured_message_context->export_master_secret,
+     529                 :            :             hash_size);
+     530                 :            : 
+     531         [ -  + ]:         21 :         if (!status) {
+     532                 :          0 :             goto cleanup;
+     533                 :            :         }
+     534                 :            :     }
+     535                 :            : 
+     536                 :         32 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "export_master_secret (0x%zx) - ", hash_size));
+     537                 :         32 :     LIBSPDM_INTERNAL_DUMP_DATA(
+     538                 :            :         secured_message_context->export_master_secret, hash_size);
+     539                 :         32 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     540                 :            : 
+     541                 :         32 :     status = libspdm_generate_aead_key_and_iv(
+     542                 :            :         secured_message_context,
+     543                 :         32 :         secured_message_context->application_secret.request_data_secret,
+     544                 :         32 :         secured_message_context->application_secret.request_data_encryption_key,
+     545                 :         32 :         secured_message_context->application_secret.request_data_salt);
+     546         [ -  + ]:         32 :     if (!status) {
+     547                 :          0 :         goto cleanup;
+     548                 :            :     }
+     549                 :         32 :     secured_message_context->application_secret.request_data_sequence_number = 0;
+     550                 :            : 
+     551                 :         32 :     status = libspdm_generate_aead_key_and_iv(
+     552                 :            :         secured_message_context,
+     553                 :         32 :         secured_message_context->application_secret.response_data_secret,
+     554                 :         32 :         secured_message_context->application_secret.response_data_encryption_key,
+     555                 :         32 :         secured_message_context->application_secret.response_data_salt);
+     556         [ -  + ]:         32 :     if (!status) {
+     557                 :          0 :         goto cleanup;
+     558                 :            :     }
+     559                 :         32 :     secured_message_context->application_secret.response_data_sequence_number = 0;
+     560                 :            : 
+     561                 :         32 : cleanup:
+     562                 :            :     /*zero salt1 for security*/
+     563                 :         32 :     libspdm_zero_mem(salt1, hash_size);
+     564                 :         32 :     return status;
+     565                 :            : }
+     566                 :            : 
+     567                 :            : /**
+     568                 :            :  * This function creates the updates of SPDM DataKey for a session.
+     569                 :            :  *
+     570                 :            :  * @param  spdm_secured_message_context    A pointer to the SPDM secured message context.
+     571                 :            :  * @param  action                       Indicate of the key update action.
+     572                 :            :  *
+     573                 :            :  * @retval RETURN_SUCCESS  SPDM DataKey update is created.
+     574                 :            :  **/
+     575                 :        102 : bool libspdm_create_update_session_data_key(void *spdm_secured_message_context,
+     576                 :            :                                             libspdm_key_update_action_t action)
+     577                 :            : {
+     578                 :            :     bool status;
+     579                 :            :     size_t hash_size;
+     580                 :            :     uint8_t bin_str9[128];
+     581                 :            :     size_t bin_str9_size;
+     582                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     583                 :            : 
+     584                 :        102 :     secured_message_context = spdm_secured_message_context;
+     585                 :            : 
+     586                 :        102 :     hash_size = secured_message_context->hash_size;
+     587                 :            : 
+     588                 :        102 :     bin_str9_size = sizeof(bin_str9);
+     589                 :        102 :     libspdm_bin_concat(secured_message_context->version,
+     590                 :            :                        SPDM_BIN_STR_9_LABEL, sizeof(SPDM_BIN_STR_9_LABEL) - 1,
+     591                 :        102 :                        NULL, (uint16_t)hash_size, hash_size, bin_str9,
+     592                 :            :                        &bin_str9_size);
+     593                 :            : 
+     594                 :        102 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "bin_str9 (0x%zx):\n", bin_str9_size));
+     595                 :        102 :     LIBSPDM_INTERNAL_DUMP_HEX(bin_str9, bin_str9_size);
+     596                 :            : 
+     597         [ +  + ]:        102 :     if (action == LIBSPDM_KEY_UPDATE_ACTION_REQUESTER) {
+     598                 :         40 :         libspdm_copy_mem(&secured_message_context->application_secret_backup
+     599                 :            :                          .request_data_secret,
+     600                 :            :                          sizeof(secured_message_context->application_secret_backup
+     601                 :            :                                 .request_data_secret),
+     602                 :         40 :                          &secured_message_context->application_secret
+     603                 :            :                          .request_data_secret,
+     604                 :            :                          LIBSPDM_MAX_HASH_SIZE);
+     605                 :         40 :         libspdm_copy_mem(&secured_message_context->application_secret_backup
+     606                 :            :                          .request_data_encryption_key,
+     607                 :            :                          sizeof(secured_message_context->application_secret_backup
+     608                 :            :                                 .request_data_encryption_key),
+     609                 :         40 :                          &secured_message_context->application_secret
+     610                 :            :                          .request_data_encryption_key,
+     611                 :            :                          LIBSPDM_MAX_AEAD_KEY_SIZE);
+     612                 :         40 :         libspdm_copy_mem(&secured_message_context->application_secret_backup
+     613                 :            :                          .request_data_salt,
+     614                 :            :                          sizeof(secured_message_context->application_secret_backup
+     615                 :            :                                 .request_data_salt),
+     616                 :         40 :                          &secured_message_context->application_secret
+     617                 :            :                          .request_data_salt,
+     618                 :            :                          LIBSPDM_MAX_AEAD_IV_SIZE);
+     619                 :            :         secured_message_context->application_secret_backup
+     620                 :         40 :         .request_data_sequence_number =
+     621                 :         40 :             secured_message_context->application_secret.request_data_sequence_number;
+     622                 :            : 
+     623                 :         40 :         status = libspdm_hkdf_expand(
+     624                 :            :             secured_message_context->base_hash_algo,
+     625                 :         40 :             secured_message_context->application_secret.request_data_secret,
+     626                 :            :             hash_size, bin_str9, bin_str9_size,
+     627                 :         40 :             secured_message_context->application_secret.request_data_secret,
+     628                 :            :             hash_size);
+     629         [ -  + ]:         40 :         if (!status) {
+     630                 :          0 :             return false;
+     631                 :            :         }
+     632                 :         40 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "RequestDataSecretUpdate (0x%zx) - ", hash_size));
+     633                 :         40 :         LIBSPDM_INTERNAL_DUMP_DATA(secured_message_context->application_secret.request_data_secret,
+     634                 :            :                                    hash_size);
+     635                 :         40 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     636                 :            : 
+     637                 :         40 :         status = libspdm_generate_aead_key_and_iv(
+     638                 :            :             secured_message_context,
+     639                 :         40 :             secured_message_context->application_secret.request_data_secret,
+     640                 :         40 :             secured_message_context->application_secret.request_data_encryption_key,
+     641                 :         40 :             secured_message_context->application_secret.request_data_salt);
+     642         [ -  + ]:         40 :         if (!status) {
+     643                 :          0 :             return status;
+     644                 :            :         }
+     645                 :         40 :         secured_message_context->application_secret.request_data_sequence_number = 0;
+     646                 :            : 
+     647                 :         40 :         secured_message_context->requester_backup_valid = true;
+     648         [ +  - ]:         62 :     } else if (action == LIBSPDM_KEY_UPDATE_ACTION_RESPONDER) {
+     649                 :         62 :         libspdm_copy_mem(&secured_message_context->application_secret_backup
+     650                 :            :                          .response_data_secret,
+     651                 :            :                          sizeof(secured_message_context->application_secret_backup
+     652                 :            :                                 .response_data_secret),
+     653                 :         62 :                          &secured_message_context->application_secret
+     654                 :            :                          .response_data_secret,
+     655                 :            :                          LIBSPDM_MAX_HASH_SIZE);
+     656                 :         62 :         libspdm_copy_mem(&secured_message_context->application_secret_backup
+     657                 :            :                          .response_data_encryption_key,
+     658                 :            :                          sizeof(secured_message_context->application_secret_backup
+     659                 :            :                                 .response_data_encryption_key),
+     660                 :         62 :                          &secured_message_context->application_secret
+     661                 :            :                          .response_data_encryption_key,
+     662                 :            :                          LIBSPDM_MAX_AEAD_KEY_SIZE);
+     663                 :         62 :         libspdm_copy_mem(&secured_message_context->application_secret_backup
+     664                 :            :                          .response_data_salt,
+     665                 :            :                          sizeof(secured_message_context->application_secret_backup
+     666                 :            :                                 .response_data_salt),
+     667                 :         62 :                          &secured_message_context->application_secret
+     668                 :            :                          .response_data_salt,
+     669                 :            :                          LIBSPDM_MAX_AEAD_IV_SIZE);
+     670                 :            :         secured_message_context->application_secret_backup
+     671                 :         62 :         .response_data_sequence_number =
+     672                 :         62 :             secured_message_context->application_secret.response_data_sequence_number;
+     673                 :            : 
+     674                 :         62 :         status = libspdm_hkdf_expand(
+     675                 :            :             secured_message_context->base_hash_algo,
+     676                 :         62 :             secured_message_context->application_secret.response_data_secret,
+     677                 :            :             hash_size, bin_str9, bin_str9_size,
+     678                 :         62 :             secured_message_context->application_secret.response_data_secret,
+     679                 :            :             hash_size);
+     680         [ -  + ]:         62 :         if (!status) {
+     681                 :          0 :             return false;
+     682                 :            :         }
+     683                 :         62 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "ResponseDataSecretUpdate (0x%zx) - ",
+     684                 :            :                        hash_size));
+     685                 :         62 :         LIBSPDM_INTERNAL_DUMP_DATA(secured_message_context->application_secret.response_data_secret,
+     686                 :            :                                    hash_size);
+     687                 :         62 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     688                 :            : 
+     689                 :         62 :         status = libspdm_generate_aead_key_and_iv(
+     690                 :            :             secured_message_context,
+     691                 :         62 :             secured_message_context->application_secret.response_data_secret,
+     692                 :         62 :             secured_message_context->application_secret.response_data_encryption_key,
+     693                 :         62 :             secured_message_context->application_secret.response_data_salt);
+     694         [ -  + ]:         62 :         if (!status) {
+     695                 :          0 :             return status;
+     696                 :            :         }
+     697                 :         62 :         secured_message_context->application_secret.response_data_sequence_number = 0;
+     698                 :            : 
+     699                 :         62 :         secured_message_context->responder_backup_valid = true;
+     700                 :            :     } else {
+     701                 :          0 :         return false;
+     702                 :            :     }
+     703                 :            : 
+     704                 :        102 :     return true;
+     705                 :            : }
+     706                 :            : 
+     707                 :        201 : void libspdm_clear_handshake_secret(void *spdm_secured_message_context)
+     708                 :            : {
+     709                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     710                 :            : 
+     711                 :        201 :     secured_message_context = spdm_secured_message_context;
+     712                 :            : 
+     713                 :        201 :     libspdm_zero_mem(secured_message_context->master_secret.handshake_secret,
+     714                 :            :                      LIBSPDM_MAX_HASH_SIZE);
+     715                 :        201 :     libspdm_zero_mem(&(secured_message_context->handshake_secret),
+     716                 :            :                      sizeof(libspdm_session_info_struct_handshake_secret_t));
+     717                 :            : 
+     718                 :        201 :     secured_message_context->requester_backup_valid = false;
+     719                 :        201 :     secured_message_context->responder_backup_valid = false;
+     720                 :        201 : }
+     721                 :            : 
+     722                 :        201 : void libspdm_clear_master_secret(void *spdm_secured_message_context)
+     723                 :            : {
+     724                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     725                 :            : 
+     726                 :        201 :     secured_message_context = spdm_secured_message_context;
+     727                 :            : 
+     728                 :        201 :     libspdm_zero_mem(secured_message_context->master_secret.master_secret, LIBSPDM_MAX_HASH_SIZE);
+     729                 :        201 : }
+     730                 :            : 
+     731                 :            : /**
+     732                 :            :  * This function activates the update of SPDM DataKey for a session.
+     733                 :            :  *
+     734                 :            :  * @param  spdm_secured_message_context    A pointer to the SPDM secured message context.
+     735                 :            :  * @param  action                       Indicate of the key update action.
+     736                 :            :  * @param  use_new_key                    Indicate if the new key should be used.
+     737                 :            :  *
+     738                 :            :  * @retval RETURN_SUCCESS  SPDM DataKey update is activated.
+     739                 :            :  **/
+     740                 :         93 : bool libspdm_activate_update_session_data_key(void *spdm_secured_message_context,
+     741                 :            :                                               libspdm_key_update_action_t action,
+     742                 :            :                                               bool use_new_key)
+     743                 :            : {
+     744                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     745                 :            : 
+     746                 :         93 :     secured_message_context = spdm_secured_message_context;
+     747                 :            : 
+     748         [ +  + ]:         93 :     if (!use_new_key) {
+     749         [ -  + ]:         52 :         if ((action == LIBSPDM_KEY_UPDATE_ACTION_REQUESTER) &&
+     750         [ #  # ]:          0 :             secured_message_context->requester_backup_valid) {
+     751                 :          0 :             libspdm_copy_mem(&secured_message_context->application_secret
+     752                 :            :                              .request_data_secret,
+     753                 :            :                              sizeof(secured_message_context->application_secret
+     754                 :            :                                     .request_data_secret),
+     755                 :          0 :                              &secured_message_context
+     756                 :            :                              ->application_secret_backup
+     757                 :            :                              .request_data_secret,
+     758                 :            :                              LIBSPDM_MAX_HASH_SIZE);
+     759                 :          0 :             libspdm_copy_mem(&secured_message_context->application_secret
+     760                 :            :                              .request_data_encryption_key,
+     761                 :            :                              sizeof(secured_message_context->application_secret
+     762                 :            :                                     .request_data_encryption_key),
+     763                 :          0 :                              &secured_message_context
+     764                 :            :                              ->application_secret_backup
+     765                 :            :                              .request_data_encryption_key,
+     766                 :            :                              LIBSPDM_MAX_AEAD_KEY_SIZE);
+     767                 :          0 :             libspdm_copy_mem(&secured_message_context->application_secret
+     768                 :            :                              .request_data_salt,
+     769                 :            :                              sizeof(secured_message_context->application_secret
+     770                 :            :                                     .request_data_salt),
+     771                 :          0 :                              &secured_message_context
+     772                 :            :                              ->application_secret_backup
+     773                 :            :                              .request_data_salt,
+     774                 :            :                              LIBSPDM_MAX_AEAD_IV_SIZE);
+     775                 :            :             secured_message_context->application_secret
+     776                 :          0 :             .request_data_sequence_number =
+     777                 :          0 :                 secured_message_context->application_secret_backup.request_data_sequence_number;
+     778         [ +  - ]:         52 :         } else if ((action == LIBSPDM_KEY_UPDATE_ACTION_RESPONDER) &&
+     779         [ +  - ]:         52 :                    secured_message_context->responder_backup_valid) {
+     780                 :         52 :             libspdm_copy_mem(&secured_message_context->application_secret
+     781                 :            :                              .response_data_secret,
+     782                 :            :                              sizeof(secured_message_context->application_secret
+     783                 :            :                                     .response_data_secret),
+     784                 :         52 :                              &secured_message_context
+     785                 :            :                              ->application_secret_backup
+     786                 :            :                              .response_data_secret,
+     787                 :            :                              LIBSPDM_MAX_HASH_SIZE);
+     788                 :         52 :             libspdm_copy_mem(&secured_message_context->application_secret
+     789                 :            :                              .response_data_encryption_key,
+     790                 :            :                              sizeof(secured_message_context->application_secret
+     791                 :            :                                     .response_data_encryption_key),
+     792                 :         52 :                              &secured_message_context
+     793                 :            :                              ->application_secret_backup
+     794                 :            :                              .response_data_encryption_key,
+     795                 :            :                              LIBSPDM_MAX_AEAD_KEY_SIZE);
+     796                 :         52 :             libspdm_copy_mem(&secured_message_context->application_secret
+     797                 :            :                              .response_data_salt,
+     798                 :            :                              sizeof(secured_message_context->application_secret
+     799                 :            :                                     .response_data_salt),
+     800                 :         52 :                              &secured_message_context
+     801                 :            :                              ->application_secret_backup
+     802                 :            :                              .response_data_salt,
+     803                 :            :                              LIBSPDM_MAX_AEAD_IV_SIZE);
+     804                 :         52 :             secured_message_context->application_secret.response_data_sequence_number =
+     805                 :         52 :                 secured_message_context->application_secret_backup.response_data_sequence_number;
+     806                 :            :         }
+     807                 :            :     }
+     808                 :            : 
+     809         [ +  + ]:         93 :     if (action == LIBSPDM_KEY_UPDATE_ACTION_REQUESTER) {
+     810                 :         35 :         libspdm_zero_mem(&secured_message_context->application_secret_backup.request_data_secret,
+     811                 :            :                          LIBSPDM_MAX_HASH_SIZE);
+     812                 :         35 :         libspdm_zero_mem(&secured_message_context->application_secret_backup
+     813                 :            :                          .request_data_encryption_key,
+     814                 :            :                          LIBSPDM_MAX_AEAD_KEY_SIZE);
+     815                 :         35 :         libspdm_zero_mem(&secured_message_context->application_secret_backup.request_data_salt,
+     816                 :            :                          LIBSPDM_MAX_AEAD_IV_SIZE);
+     817                 :         35 :         secured_message_context->application_secret_backup.request_data_sequence_number = 0;
+     818                 :         35 :         secured_message_context->requester_backup_valid = false;
+     819         [ +  - ]:         58 :     } else if (action == LIBSPDM_KEY_UPDATE_ACTION_RESPONDER) {
+     820                 :         58 :         libspdm_zero_mem(&secured_message_context->application_secret_backup.response_data_secret,
+     821                 :            :                          LIBSPDM_MAX_HASH_SIZE);
+     822                 :         58 :         libspdm_zero_mem(&secured_message_context->application_secret_backup
+     823                 :            :                          .response_data_encryption_key,
+     824                 :            :                          LIBSPDM_MAX_AEAD_KEY_SIZE);
+     825                 :         58 :         libspdm_zero_mem(&secured_message_context->application_secret_backup.response_data_salt,
+     826                 :            :                          LIBSPDM_MAX_AEAD_IV_SIZE);
+     827                 :         58 :         secured_message_context->application_secret_backup.response_data_sequence_number = 0;
+     828                 :         58 :         secured_message_context->responder_backup_valid = false;
+     829                 :            :     }
+     830                 :            : 
+     831                 :         93 :     return true;
+     832                 :            : }
+     833                 :            : 
+     834                 :            : /**
+     835                 :            :  * Allocates and initializes one HMAC context for subsequent use, with request_finished_key.
+     836                 :            :  *
+     837                 :            :  * @param  spdm_secured_message_context    A pointer to the SPDM secured message context.
+     838                 :            :  *
+     839                 :            :  * @return Pointer to the HMAC context that has been initialized.
+     840                 :            :  **/
+     841                 :          0 : void *libspdm_hmac_new_with_request_finished_key(void *spdm_secured_message_context)
+     842                 :            : {
+     843                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     844                 :            : 
+     845                 :          0 :     secured_message_context = spdm_secured_message_context;
+     846                 :          0 :     return libspdm_hmac_new(secured_message_context->base_hash_algo);
+     847                 :            : }
+     848                 :            : 
+     849                 :            : /**
+     850                 :            :  * Release the specified HMAC context, with request_finished_key.
+     851                 :            :  *
+     852                 :            :  * @param  spdm_secured_message_context    A pointer to the SPDM secured message context.
+     853                 :            :  * @param  hmac_ctx                   Pointer to the HMAC context to be released.
+     854                 :            :  **/
+     855                 :          0 : void libspdm_hmac_free_with_request_finished_key(
+     856                 :            :     void *spdm_secured_message_context, void *hmac_ctx)
+     857                 :            : {
+     858                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     859                 :            : 
+     860                 :          0 :     secured_message_context = spdm_secured_message_context;
+     861                 :          0 :     libspdm_hmac_free(secured_message_context->base_hash_algo, hmac_ctx);
+     862                 :          0 : }
+     863                 :            : 
+     864                 :            : /**
+     865                 :            :  * Set request_finished_key for subsequent use. It must be done before any
+     866                 :            :  * calling to hmac_update().
+     867                 :            :  *
+     868                 :            :  * @param  spdm_secured_message_context    A pointer to the SPDM secured message context.
+     869                 :            :  * @param  hmac_ctx  Pointer to HMAC context.
+     870                 :            :  *
+     871                 :            :  * @retval true   The key is set successfully.
+     872                 :            :  * @retval false  The key is set unsuccessfully.
+     873                 :            :  **/
+     874                 :          0 : bool libspdm_hmac_init_with_request_finished_key(
+     875                 :            :     void *spdm_secured_message_context, void *hmac_ctx)
+     876                 :            : {
+     877                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     878                 :            : 
+     879                 :          0 :     secured_message_context = spdm_secured_message_context;
+     880                 :          0 :     return libspdm_hmac_init(
+     881                 :            :         secured_message_context->base_hash_algo, hmac_ctx,
+     882                 :          0 :         secured_message_context->handshake_secret.request_finished_key,
+     883                 :            :         secured_message_context->hash_size);
+     884                 :            : }
+     885                 :            : 
+     886                 :            : /**
+     887                 :            :  * Makes a copy of an existing HMAC context, with request_finished_key.
+     888                 :            :  *
+     889                 :            :  * @param  spdm_secured_message_context    A pointer to the SPDM secured message context.
+     890                 :            :  * @param  hmac_ctx     Pointer to HMAC context being copied.
+     891                 :            :  * @param  new_hmac_ctx  Pointer to new HMAC context.
+     892                 :            :  *
+     893                 :            :  * @retval true   HMAC context copy succeeded.
+     894                 :            :  * @retval false  HMAC context copy failed.
+     895                 :            :  **/
+     896                 :          0 : bool libspdm_hmac_duplicate_with_request_finished_key(
+     897                 :            :     void *spdm_secured_message_context,
+     898                 :            :     const void *hmac_ctx, void *new_hmac_ctx)
+     899                 :            : {
+     900                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     901                 :            : 
+     902                 :          0 :     secured_message_context = spdm_secured_message_context;
+     903                 :          0 :     return libspdm_hmac_duplicate(secured_message_context->base_hash_algo, hmac_ctx, new_hmac_ctx);
+     904                 :            : }
+     905                 :            : 
+     906                 :            : /**
+     907                 :            :  * Digests the input data and updates HMAC context, with request_finished_key.
+     908                 :            :  *
+     909                 :            :  * @param  spdm_secured_message_context    A pointer to the SPDM secured message context.
+     910                 :            :  * @param  hmac_ctx     Pointer to HMAC context being copied.
+     911                 :            :  * @param  data              Pointer to the buffer containing the data to be digested.
+     912                 :            :  * @param  data_size          size of data buffer in bytes.
+     913                 :            :  *
+     914                 :            :  * @retval true   HMAC data digest succeeded.
+     915                 :            :  * @retval false  HMAC data digest failed.
+     916                 :            :  **/
+     917                 :          0 : bool libspdm_hmac_update_with_request_finished_key(
+     918                 :            :     void *spdm_secured_message_context,
+     919                 :            :     void *hmac_ctx, const void *data,
+     920                 :            :     size_t data_size)
+     921                 :            : {
+     922                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     923                 :            : 
+     924                 :          0 :     secured_message_context = spdm_secured_message_context;
+     925                 :          0 :     return libspdm_hmac_update(secured_message_context->base_hash_algo, hmac_ctx, data, data_size);
+     926                 :            : }
+     927                 :            : 
+     928                 :            : /**
+     929                 :            :  * Completes computation of the HMAC digest value, with request_finished_key.
+     930                 :            :  *
+     931                 :            :  * @param  spdm_secured_message_context    A pointer to the SPDM secured message context.
+     932                 :            :  * @param  hmac_ctx     Pointer to HMAC context being copied.
+     933                 :            :  * @param  hmac_value          Pointer to a buffer that receives the HMAC digest value
+     934                 :            :  *
+     935                 :            :  * @retval true   HMAC data digest succeeded.
+     936                 :            :  * @retval false  HMAC data digest failed.
+     937                 :            :  **/
+     938                 :          0 : bool libspdm_hmac_final_with_request_finished_key(
+     939                 :            :     void *spdm_secured_message_context,
+     940                 :            :     void *hmac_ctx,  uint8_t *hmac_value)
+     941                 :            : {
+     942                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     943                 :            : 
+     944                 :          0 :     secured_message_context = spdm_secured_message_context;
+     945                 :          0 :     return libspdm_hmac_final(secured_message_context->base_hash_algo, hmac_ctx, hmac_value);
+     946                 :            : }
+     947                 :            : 
+     948                 :            : /**
+     949                 :            :  * Computes the HMAC of a input data buffer, with request_finished_key.
+     950                 :            :  *
+     951                 :            :  * @param  spdm_secured_message_context    A pointer to the SPDM secured message context.
+     952                 :            :  * @param  data                         Pointer to the buffer containing the data to be HMACed.
+     953                 :            :  * @param  data_size                     size of data buffer in bytes.
+     954                 :            :  * @param  hash_value                    Pointer to a buffer that receives the HMAC value.
+     955                 :            :  *
+     956                 :            :  * @retval true   HMAC computation succeeded.
+     957                 :            :  * @retval false  HMAC computation failed.
+     958                 :            :  **/
+     959                 :         89 : bool libspdm_hmac_all_with_request_finished_key(void *spdm_secured_message_context,
+     960                 :            :                                                 const void *data, size_t data_size,
+     961                 :            :                                                 uint8_t *hmac_value)
+     962                 :            : {
+     963                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     964                 :            : 
+     965                 :         89 :     secured_message_context = spdm_secured_message_context;
+     966                 :        178 :     return libspdm_hmac_all(
+     967                 :            :         secured_message_context->base_hash_algo, data, data_size,
+     968                 :         89 :         secured_message_context->handshake_secret.request_finished_key,
+     969                 :            :         secured_message_context->hash_size, hmac_value);
+     970                 :            : }
+     971                 :            : 
+     972                 :            : /**
+     973                 :            :  * Allocates and initializes one HMAC context for subsequent use, with response_finished_key.
+     974                 :            :  *
+     975                 :            :  * @param  spdm_secured_message_context    A pointer to the SPDM secured message context.
+     976                 :            :  *
+     977                 :            :  * @return Pointer to the HMAC context that has been initialized.
+     978                 :            :  **/
+     979                 :          0 : void *libspdm_hmac_new_with_response_finished_key(void *spdm_secured_message_context)
+     980                 :            : {
+     981                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     982                 :            : 
+     983                 :          0 :     secured_message_context = spdm_secured_message_context;
+     984                 :          0 :     return libspdm_hmac_new(secured_message_context->base_hash_algo);
+     985                 :            : }
+     986                 :            : 
+     987                 :            : /**
+     988                 :            :  * Release the specified HMAC context, with response_finished_key.
+     989                 :            :  *
+     990                 :            :  * @param  spdm_secured_message_context    A pointer to the SPDM secured message context.
+     991                 :            :  * @param  hmac_ctx                   Pointer to the HMAC context to be released.
+     992                 :            :  **/
+     993                 :          0 : void libspdm_hmac_free_with_response_finished_key(
+     994                 :            :     void *spdm_secured_message_context, void *hmac_ctx)
+     995                 :            : {
+     996                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     997                 :            : 
+     998                 :          0 :     secured_message_context = spdm_secured_message_context;
+     999                 :          0 :     libspdm_hmac_free(secured_message_context->base_hash_algo, hmac_ctx);
+    1000                 :          0 : }
+    1001                 :            : 
+    1002                 :            : /**
+    1003                 :            :  * Set response_finished_key for subsequent use. It must be done before any
+    1004                 :            :  * calling to hmac_update().
+    1005                 :            :  *
+    1006                 :            :  * @param  spdm_secured_message_context    A pointer to the SPDM secured message context.
+    1007                 :            :  * @param  hmac_ctx  Pointer to HMAC context.
+    1008                 :            :  *
+    1009                 :            :  * @retval true   The key is set successfully.
+    1010                 :            :  * @retval false  The key is set unsuccessfully.
+    1011                 :            :  **/
+    1012                 :          0 : bool libspdm_hmac_init_with_response_finished_key(
+    1013                 :            :     void *spdm_secured_message_context, void *hmac_ctx)
+    1014                 :            : {
+    1015                 :            :     libspdm_secured_message_context_t *secured_message_context;
+    1016                 :            : 
+    1017                 :          0 :     secured_message_context = spdm_secured_message_context;
+    1018                 :          0 :     return libspdm_hmac_init(
+    1019                 :            :         secured_message_context->base_hash_algo, hmac_ctx,
+    1020                 :          0 :         secured_message_context->handshake_secret.response_finished_key,
+    1021                 :            :         secured_message_context->hash_size);
+    1022                 :            : }
+    1023                 :            : 
+    1024                 :            : /**
+    1025                 :            :  * Makes a copy of an existing HMAC context, with response_finished_key.
+    1026                 :            :  *
+    1027                 :            :  * @param  spdm_secured_message_context    A pointer to the SPDM secured message context.
+    1028                 :            :  * @param  hmac_ctx     Pointer to HMAC context being copied.
+    1029                 :            :  * @param  new_hmac_ctx  Pointer to new HMAC context.
+    1030                 :            :  *
+    1031                 :            :  * @retval true   HMAC context copy succeeded.
+    1032                 :            :  * @retval false  HMAC context copy failed.
+    1033                 :            :  **/
+    1034                 :          0 : bool libspdm_hmac_duplicate_with_response_finished_key(
+    1035                 :            :     void *spdm_secured_message_context,
+    1036                 :            :     const void *hmac_ctx, void *new_hmac_ctx)
+    1037                 :            : {
+    1038                 :            :     libspdm_secured_message_context_t *secured_message_context;
+    1039                 :            : 
+    1040                 :          0 :     secured_message_context = spdm_secured_message_context;
+    1041                 :          0 :     return libspdm_hmac_duplicate(secured_message_context->base_hash_algo, hmac_ctx, new_hmac_ctx);
+    1042                 :            : }
+    1043                 :            : 
+    1044                 :            : /**
+    1045                 :            :  * Digests the input data and updates HMAC context, with response_finished_key.
+    1046                 :            :  *
+    1047                 :            :  * @param  spdm_secured_message_context    A pointer to the SPDM secured message context.
+    1048                 :            :  * @param  hmac_ctx     Pointer to HMAC context being copied.
+    1049                 :            :  * @param  data              Pointer to the buffer containing the data to be digested.
+    1050                 :            :  * @param  data_size          size of data buffer in bytes.
+    1051                 :            :  *
+    1052                 :            :  * @retval true   HMAC data digest succeeded.
+    1053                 :            :  * @retval false  HMAC data digest failed.
+    1054                 :            :  **/
+    1055                 :          0 : bool libspdm_hmac_update_with_response_finished_key(
+    1056                 :            :     void *spdm_secured_message_context,
+    1057                 :            :     void *hmac_ctx, const void *data,
+    1058                 :            :     size_t data_size)
+    1059                 :            : {
+    1060                 :            :     libspdm_secured_message_context_t *secured_message_context;
+    1061                 :            : 
+    1062                 :          0 :     secured_message_context = spdm_secured_message_context;
+    1063                 :          0 :     return libspdm_hmac_update(secured_message_context->base_hash_algo, hmac_ctx, data, data_size);
+    1064                 :            : }
+    1065                 :            : 
+    1066                 :            : /**
+    1067                 :            :  * Completes computation of the HMAC digest value, with response_finished_key.
+    1068                 :            :  *
+    1069                 :            :  * @param  spdm_secured_message_context    A pointer to the SPDM secured message context.
+    1070                 :            :  * @param  hmac_ctx     Pointer to HMAC context being copied.
+    1071                 :            :  * @param  hmac_value          Pointer to a buffer that receives the HMAC digest value
+    1072                 :            :  *
+    1073                 :            :  * @retval true   HMAC data digest succeeded.
+    1074                 :            :  * @retval false  HMAC data digest failed.
+    1075                 :            :  **/
+    1076                 :          0 : bool libspdm_hmac_final_with_response_finished_key(
+    1077                 :            :     void *spdm_secured_message_context,
+    1078                 :            :     void *hmac_ctx,  uint8_t *hmac_value)
+    1079                 :            : {
+    1080                 :            :     libspdm_secured_message_context_t *secured_message_context;
+    1081                 :            : 
+    1082                 :          0 :     secured_message_context = spdm_secured_message_context;
+    1083                 :          0 :     return libspdm_hmac_final(secured_message_context->base_hash_algo, hmac_ctx, hmac_value);
+    1084                 :            : }
+    1085                 :            : 
+    1086                 :            : /**
+    1087                 :            :  * Computes the HMAC of a input data buffer, with response_finished_key.
+    1088                 :            :  *
+    1089                 :            :  * @param  spdm_secured_message_context    A pointer to the SPDM secured message context.
+    1090                 :            :  * @param  data                         Pointer to the buffer containing the data to be HMACed.
+    1091                 :            :  * @param  data_size                     size of data buffer in bytes.
+    1092                 :            :  * @param  hash_value                    Pointer to a buffer that receives the HMAC value.
+    1093                 :            :  *
+    1094                 :            :  * @retval true   HMAC computation succeeded.
+    1095                 :            :  * @retval false  HMAC computation failed.
+    1096                 :            :  **/
+    1097                 :         73 : bool libspdm_hmac_all_with_response_finished_key(
+    1098                 :            :     void *spdm_secured_message_context, const void *data,
+    1099                 :            :     size_t data_size, uint8_t *hmac_value)
+    1100                 :            : {
+    1101                 :            :     libspdm_secured_message_context_t *secured_message_context;
+    1102                 :            : 
+    1103                 :         73 :     secured_message_context = spdm_secured_message_context;
+    1104                 :        146 :     return libspdm_hmac_all(
+    1105                 :            :         secured_message_context->base_hash_algo, data, data_size,
+    1106                 :         73 :         secured_message_context->handshake_secret.response_finished_key,
+    1107                 :            :         secured_message_context->hash_size, hmac_value);
+    1108                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/cipher/aead_aes_gcm.c.func-sort-c.html b/coverage_log/os_stub/cryptlib_mbedtls/cipher/aead_aes_gcm.c.func-sort-c.html new file mode 100644 index 00000000000..ddff487870e --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/cipher/aead_aes_gcm.c.func-sort-c.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/cipher/aead_aes_gcm.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/cipher - aead_aes_gcm.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:496674.2 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:316051.7 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_aead_aes_gcm_decrypt326
libspdm_aead_aes_gcm_encrypt465
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/cipher/aead_aes_gcm.c.func.html b/coverage_log/os_stub/cryptlib_mbedtls/cipher/aead_aes_gcm.c.func.html new file mode 100644 index 00000000000..b797e02d3fe --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/cipher/aead_aes_gcm.c.func.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/cipher/aead_aes_gcm.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/cipher - aead_aes_gcm.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:496674.2 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:316051.7 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_aead_aes_gcm_decrypt326
libspdm_aead_aes_gcm_encrypt465
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/cipher/aead_aes_gcm.c.gcov.html b/coverage_log/os_stub/cryptlib_mbedtls/cipher/aead_aes_gcm.c.gcov.html new file mode 100644 index 00000000000..e1300c442cd --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/cipher/aead_aes_gcm.c.gcov.html @@ -0,0 +1,274 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/cipher/aead_aes_gcm.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/cipher - aead_aes_gcm.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:496674.2 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:316051.7 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 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                 :            : /** @file
+       8                 :            :  * AEAD (AES-GCM) Wrapper Implementation.
+       9                 :            :  *
+      10                 :            :  * RFC 5116 - An Interface and Algorithms for Authenticated Encryption
+      11                 :            :  * NIST SP800-38d - Cipher Modes of Operation: Galois / Counter Mode(GCM) and GMAC
+      12                 :            :  **/
+      13                 :            : 
+      14                 :            : #include "internal_crypt_lib.h"
+      15                 :            : #include <mbedtls/gcm.h>
+      16                 :            : 
+      17                 :            : /**
+      18                 :            :  * Performs AEAD AES-GCM authenticated encryption on a data buffer and additional authenticated data (AAD).
+      19                 :            :  *
+      20                 :            :  * iv_size must be 12, otherwise false is returned.
+      21                 :            :  * key_size must be 16, 24 or 32, otherwise false is returned.
+      22                 :            :  * tag_size must be 12, 13, 14, 15, 16, otherwise false is returned.
+      23                 :            :  *
+      24                 :            :  * @param[in]   key         Pointer to the encryption key.
+      25                 :            :  * @param[in]   key_size     size of the encryption key in bytes.
+      26                 :            :  * @param[in]   iv          Pointer to the IV value.
+      27                 :            :  * @param[in]   iv_size      size of the IV value in bytes.
+      28                 :            :  * @param[in]   a_data       Pointer to the additional authenticated data (AAD).
+      29                 :            :  * @param[in]   a_data_size   size of the additional authenticated data (AAD) in bytes.
+      30                 :            :  * @param[in]   data_in      Pointer to the input data buffer to be encrypted.
+      31                 :            :  * @param[in]   data_in_size  size of the input data buffer in bytes.
+      32                 :            :  * @param[out]  tag_out      Pointer to a buffer that receives the authentication tag output.
+      33                 :            :  * @param[in]   tag_size     size of the authentication tag in bytes.
+      34                 :            :  * @param[out]  data_out     Pointer to a buffer that receives the encryption output.
+      35                 :            :  * @param[out]  data_out_size size of the output data buffer in bytes.
+      36                 :            :  *
+      37                 :            :  * @retval true   AEAD AES-GCM authenticated encryption succeeded.
+      38                 :            :  * @retval false  AEAD AES-GCM authenticated encryption failed.
+      39                 :            :  *
+      40                 :            :  **/
+      41                 :        465 : bool libspdm_aead_aes_gcm_encrypt(const uint8_t *key, size_t key_size,
+      42                 :            :                                   const uint8_t *iv, size_t iv_size,
+      43                 :            :                                   const uint8_t *a_data, size_t a_data_size,
+      44                 :            :                                   const uint8_t *data_in, size_t data_in_size,
+      45                 :            :                                   uint8_t *tag_out, size_t tag_size,
+      46                 :            :                                   uint8_t *data_out, size_t *data_out_size)
+      47                 :            : {
+      48                 :            :     mbedtls_gcm_context ctx;
+      49                 :            :     int ret;
+      50                 :            : 
+      51         [ -  + ]:        465 :     if (data_in_size > INT_MAX) {
+      52                 :          0 :         return false;
+      53                 :            :     }
+      54         [ -  + ]:        465 :     if (a_data_size > INT_MAX) {
+      55                 :          0 :         return false;
+      56                 :            :     }
+      57         [ -  + ]:        465 :     if (iv_size != 12) {
+      58                 :          0 :         return false;
+      59                 :            :     }
+      60         [ +  - ]:        465 :     switch (key_size) {
+      61                 :        465 :     case 16:
+      62                 :            :     case 24:
+      63                 :            :     case 32:
+      64                 :        465 :         break;
+      65                 :          0 :     default:
+      66                 :          0 :         return false;
+      67                 :            :     }
+      68   [ +  -  +  -  :        465 :     if ((tag_size != 12) && (tag_size != 13) && (tag_size != 14) &&
+             +  -  +  - ]
+      69         [ -  + ]:        465 :         (tag_size != 15) && (tag_size != 16)) {
+      70                 :          0 :         return false;
+      71                 :            :     }
+      72         [ +  - ]:        465 :     if (data_out_size != NULL) {
+      73         [ +  - ]:        465 :         if ((*data_out_size > INT_MAX) ||
+      74         [ -  + ]:        465 :             (*data_out_size < data_in_size)) {
+      75                 :          0 :             return false;
+      76                 :            :         }
+      77                 :            :     }
+      78                 :            : 
+      79                 :        465 :     mbedtls_gcm_init(&ctx);
+      80                 :            : 
+      81                 :        465 :     ret = mbedtls_gcm_setkey(&ctx, MBEDTLS_CIPHER_ID_AES, key,
+      82                 :            :                              (uint32_t)(key_size * 8));
+      83         [ -  + ]:        465 :     if (ret != 0) {
+      84                 :          0 :         return false;
+      85                 :            :     }
+      86                 :            : 
+      87                 :        465 :     ret = mbedtls_gcm_crypt_and_tag(&ctx, MBEDTLS_GCM_ENCRYPT,
+      88                 :        465 :                                     (uint32_t)data_in_size, iv,
+      89                 :        465 :                                     (uint32_t)iv_size, a_data,
+      90                 :        465 :                                     (uint32_t)a_data_size, data_in, data_out,
+      91                 :            :                                     tag_size, tag_out);
+      92                 :        465 :     mbedtls_gcm_free(&ctx);
+      93         [ -  + ]:        465 :     if (ret != 0) {
+      94                 :          0 :         return false;
+      95                 :            :     }
+      96         [ +  - ]:        465 :     if (data_out_size != NULL) {
+      97                 :        465 :         *data_out_size = data_in_size;
+      98                 :            :     }
+      99                 :            : 
+     100                 :        465 :     return true;
+     101                 :            : }
+     102                 :            : 
+     103                 :            : /**
+     104                 :            :  * Performs AEAD AES-GCM authenticated decryption on a data buffer and additional authenticated data (AAD).
+     105                 :            :  *
+     106                 :            :  * iv_size must be 12, otherwise false is returned.
+     107                 :            :  * key_size must be 16, 24 or 32, otherwise false is returned.
+     108                 :            :  * tag_size must be 12, 13, 14, 15, 16, otherwise false is returned.
+     109                 :            :  * If additional authenticated data verification fails, false is returned.
+     110                 :            :  *
+     111                 :            :  * @param[in]   key         Pointer to the encryption key.
+     112                 :            :  * @param[in]   key_size     size of the encryption key in bytes.
+     113                 :            :  * @param[in]   iv          Pointer to the IV value.
+     114                 :            :  * @param[in]   iv_size      size of the IV value in bytes.
+     115                 :            :  * @param[in]   a_data       Pointer to the additional authenticated data (AAD).
+     116                 :            :  * @param[in]   a_data_size   size of the additional authenticated data (AAD) in bytes.
+     117                 :            :  * @param[in]   data_in      Pointer to the input data buffer to be decrypted.
+     118                 :            :  * @param[in]   data_in_size  size of the input data buffer in bytes.
+     119                 :            :  * @param[in]   tag         Pointer to a buffer that contains the authentication tag.
+     120                 :            :  * @param[in]   tag_size     size of the authentication tag in bytes.
+     121                 :            :  * @param[out]  data_out     Pointer to a buffer that receives the decryption output.
+     122                 :            :  * @param[out]  data_out_size size of the output data buffer in bytes.
+     123                 :            :  *
+     124                 :            :  * @retval true   AEAD AES-GCM authenticated decryption succeeded.
+     125                 :            :  * @retval false  AEAD AES-GCM authenticated decryption failed.
+     126                 :            :  *
+     127                 :            :  **/
+     128                 :        326 : bool libspdm_aead_aes_gcm_decrypt(const uint8_t *key, size_t key_size,
+     129                 :            :                                   const uint8_t *iv, size_t iv_size,
+     130                 :            :                                   const uint8_t *a_data, size_t a_data_size,
+     131                 :            :                                   const uint8_t *data_in, size_t data_in_size,
+     132                 :            :                                   const uint8_t *tag, size_t tag_size,
+     133                 :            :                                   uint8_t *data_out, size_t *data_out_size)
+     134                 :            : {
+     135                 :            :     mbedtls_gcm_context ctx;
+     136                 :            :     int ret;
+     137                 :            : 
+     138         [ -  + ]:        326 :     if (data_in_size > INT_MAX) {
+     139                 :          0 :         return false;
+     140                 :            :     }
+     141         [ -  + ]:        326 :     if (a_data_size > INT_MAX) {
+     142                 :          0 :         return false;
+     143                 :            :     }
+     144         [ -  + ]:        326 :     if (iv_size != 12) {
+     145                 :          0 :         return false;
+     146                 :            :     }
+     147         [ +  - ]:        326 :     switch (key_size) {
+     148                 :        326 :     case 16:
+     149                 :            :     case 24:
+     150                 :            :     case 32:
+     151                 :        326 :         break;
+     152                 :          0 :     default:
+     153                 :          0 :         return false;
+     154                 :            :     }
+     155   [ +  -  +  -  :        326 :     if ((tag_size != 12) && (tag_size != 13) && (tag_size != 14) &&
+             +  -  +  - ]
+     156         [ -  + ]:        326 :         (tag_size != 15) && (tag_size != 16)) {
+     157                 :          0 :         return false;
+     158                 :            :     }
+     159         [ +  - ]:        326 :     if (data_out_size != NULL) {
+     160         [ +  - ]:        326 :         if ((*data_out_size > INT_MAX) ||
+     161         [ -  + ]:        326 :             (*data_out_size < data_in_size)) {
+     162                 :          0 :             return false;
+     163                 :            :         }
+     164                 :            :     }
+     165                 :            : 
+     166                 :        326 :     mbedtls_gcm_init(&ctx);
+     167                 :            : 
+     168                 :        326 :     ret = mbedtls_gcm_setkey(&ctx, MBEDTLS_CIPHER_ID_AES, key,
+     169                 :            :                              (uint32_t)(key_size * 8));
+     170         [ -  + ]:        326 :     if (ret != 0) {
+     171                 :          0 :         return false;
+     172                 :            :     }
+     173                 :            : 
+     174                 :        326 :     ret = mbedtls_gcm_auth_decrypt(&ctx, (uint32_t)data_in_size, iv,
+     175                 :        326 :                                    (uint32_t)iv_size, a_data,
+     176                 :        326 :                                    (uint32_t)a_data_size, tag,
+     177                 :        326 :                                    (uint32_t)tag_size, data_in, data_out);
+     178                 :        326 :     mbedtls_gcm_free(&ctx);
+     179         [ +  + ]:        326 :     if (ret != 0) {
+     180                 :         27 :         return false;
+     181                 :            :     }
+     182         [ +  - ]:        299 :     if (data_out_size != NULL) {
+     183                 :        299 :         *data_out_size = data_in_size;
+     184                 :            :     }
+     185                 :            : 
+     186                 :        299 :     return true;
+     187                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/cipher/index-sort-b.html b/coverage_log/os_stub/cryptlib_mbedtls/cipher/index-sort-b.html new file mode 100644 index 00000000000..9a07c27a206 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/cipher/index-sort-b.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/cipher + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/cipherHitTotalCoverage
Test:coverage.infoLines:496674.2 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:316051.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
aead_aes_gcm.c +
74.2%74.2%
+
74.2 %49 / 66100.0 %2 / 251.7 %31 / 60
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/cipher/index-sort-f.html b/coverage_log/os_stub/cryptlib_mbedtls/cipher/index-sort-f.html new file mode 100644 index 00000000000..569c6672408 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/cipher/index-sort-f.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/cipher + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/cipherHitTotalCoverage
Test:coverage.infoLines:496674.2 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:316051.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
aead_aes_gcm.c +
74.2%74.2%
+
74.2 %49 / 66100.0 %2 / 251.7 %31 / 60
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/cipher/index-sort-l.html b/coverage_log/os_stub/cryptlib_mbedtls/cipher/index-sort-l.html new file mode 100644 index 00000000000..f328d56fbea --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/cipher/index-sort-l.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/cipher + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/cipherHitTotalCoverage
Test:coverage.infoLines:496674.2 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:316051.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
aead_aes_gcm.c +
74.2%74.2%
+
74.2 %49 / 66100.0 %2 / 251.7 %31 / 60
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/cipher/index.html b/coverage_log/os_stub/cryptlib_mbedtls/cipher/index.html new file mode 100644 index 00000000000..88388ef8179 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/cipher/index.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/cipher + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/cipherHitTotalCoverage
Test:coverage.infoLines:496674.2 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:316051.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
aead_aes_gcm.c +
74.2%74.2%
+
74.2 %49 / 66100.0 %2 / 251.7 %31 / 60
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/der/der.c.func-sort-c.html b/coverage_log/os_stub/cryptlib_mbedtls/der/der.c.func-sort-c.html new file mode 100644 index 00000000000..54ac34a8d73 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/der/der.c.func-sort-c.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/der/der.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/der - der.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:274757.4 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:142850.0 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_rsa_get_public_key_from_der2
libspdm_ec_get_public_key_from_der3
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/der/der.c.func.html b/coverage_log/os_stub/cryptlib_mbedtls/der/der.c.func.html new file mode 100644 index 00000000000..8b5a1835f6e --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/der/der.c.func.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/der/der.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/der - der.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:274757.4 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:142850.0 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_ec_get_public_key_from_der3
libspdm_rsa_get_public_key_from_der2
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/der/der.c.gcov.html b/coverage_log/os_stub/cryptlib_mbedtls/der/der.c.gcov.html new file mode 100644 index 00000000000..970aecde6d2 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/der/der.c.gcov.html @@ -0,0 +1,288 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/der/der.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/der - der.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:274757.4 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:142850.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 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                 :            : /** @file
+       8                 :            :  * DER (Distinguished Encoding Rules) format Handler Wrapper Implementation.
+       9                 :            :  **/
+      10                 :            : 
+      11                 :            : #include "internal_crypt_lib.h"
+      12                 :            : #include <mbedtls/pk.h>
+      13                 :            : #include <mbedtls/rsa.h>
+      14                 :            : #include <mbedtls/ecp.h>
+      15                 :            : #include <mbedtls/ecdh.h>
+      16                 :            : #include <mbedtls/ecdsa.h>
+      17                 :            : 
+      18                 :            : #if (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT)
+      19                 :            : /**
+      20                 :            :  * Retrieve the RSA Public key from the DER key data.
+      21                 :            :  *
+      22                 :            :  * The public key is ASN.1 DER-encoded as RFC7250 describes,
+      23                 :            :  * namely, the SubjectPublicKeyInfo structure of a X.509 certificate.
+      24                 :            :  *
+      25                 :            :  * @param[in]  der_data     Pointer to the DER-encoded key data to be retrieved.
+      26                 :            :  * @param[in]  der_size     size of the DER key data in bytes.
+      27                 :            :  * @param[out] rsa_context  Pointer to newly generated RSA context which contain the retrieved
+      28                 :            :  *                          RSA public key component. Use libspdm_rsa_free() function to free the
+      29                 :            :  *                          resource.
+      30                 :            :  *
+      31                 :            :  * If der_data is NULL, then return false.
+      32                 :            :  * If rsa_context is NULL, then return false.
+      33                 :            :  *
+      34                 :            :  * @retval  true   RSA Public key was retrieved successfully.
+      35                 :            :  * @retval  false  Invalid DER key data.
+      36                 :            :  *
+      37                 :            :  **/
+      38                 :          2 : bool libspdm_rsa_get_public_key_from_der(const uint8_t *der_data,
+      39                 :            :                                          size_t der_size,
+      40                 :            :                                          void **rsa_context)
+      41                 :            : {
+      42                 :            :     int ret;
+      43                 :            :     mbedtls_pk_context pk;
+      44                 :            :     mbedtls_rsa_context *rsa;
+      45                 :            : 
+      46   [ +  -  +  -  :          2 :     if (der_data == NULL || rsa_context == NULL || der_size > INT_MAX) {
+                   -  + ]
+      47                 :          0 :         return false;
+      48                 :            :     }
+      49                 :            : 
+      50                 :          2 :     mbedtls_pk_init(&pk);
+      51                 :            : 
+      52                 :          2 :     ret = mbedtls_pk_parse_public_key(&pk, der_data, der_size);
+      53         [ -  + ]:          2 :     if (ret != 0) {
+      54                 :          0 :         mbedtls_pk_free(&pk);
+      55                 :          0 :         return false;
+      56                 :            :     }
+      57                 :            : 
+      58         [ -  + ]:          2 :     if (mbedtls_pk_get_type(&pk) != MBEDTLS_PK_RSA) {
+      59                 :          0 :         mbedtls_pk_free(&pk);
+      60                 :          0 :         return false;
+      61                 :            :     }
+      62                 :            : 
+      63                 :          2 :     rsa = libspdm_rsa_new();
+      64         [ -  + ]:          2 :     if (rsa == NULL) {
+      65                 :          0 :         return false;
+      66                 :            :     }
+      67                 :          2 :     ret = mbedtls_rsa_copy(rsa, mbedtls_pk_rsa(pk));
+      68         [ -  + ]:          2 :     if (ret != 0) {
+      69                 :          0 :         libspdm_rsa_free(rsa);
+      70                 :          0 :         mbedtls_pk_free(&pk);
+      71                 :          0 :         return false;
+      72                 :            :     }
+      73                 :          2 :     mbedtls_pk_free(&pk);
+      74                 :            : 
+      75                 :          2 :     *rsa_context = rsa;
+      76                 :          2 :     return true;
+      77                 :            : }
+      78                 :            : #endif /* (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT) */
+      79                 :            : 
+      80                 :            : #if LIBSPDM_ECDSA_SUPPORT
+      81                 :            : /**
+      82                 :            :  * Retrieve the EC Public key from the DER key data.
+      83                 :            :  *
+      84                 :            :  * The public key is ASN.1 DER-encoded as RFC7250 describes,
+      85                 :            :  * namely, the SubjectPublicKeyInfo structure of a X.509 certificate.
+      86                 :            :  *
+      87                 :            :  * @param[in]  der_data    Pointer to the DER-encoded key data to be retrieved.
+      88                 :            :  * @param[in]  der_size    size of the DER key data in bytes.
+      89                 :            :  * @param[out] ec_context  Pointer to newly generated EC DSA context which contain the retrieved
+      90                 :            :  *                         EC public key component. Use libspdm_ec_free() function to free the
+      91                 :            :  *                         resource.
+      92                 :            :  *
+      93                 :            :  * If der_data is NULL, then return false.
+      94                 :            :  * If ec_context is NULL, then return false.
+      95                 :            :  *
+      96                 :            :  * @retval  true   EC Public key was retrieved successfully.
+      97                 :            :  * @retval  false  Invalid DER key data.
+      98                 :            :  *
+      99                 :            :  **/
+     100                 :          3 : bool libspdm_ec_get_public_key_from_der(const uint8_t *der_data,
+     101                 :            :                                         size_t der_size,
+     102                 :            :                                         void **ec_context)
+     103                 :            : {
+     104                 :            :     int ret;
+     105                 :            :     mbedtls_pk_context pk;
+     106                 :            :     mbedtls_ecdh_context *ecdh;
+     107                 :            : 
+     108   [ +  -  +  -  :          3 :     if (der_data == NULL || ec_context == NULL || der_size > INT_MAX) {
+                   -  + ]
+     109                 :          0 :         return false;
+     110                 :            :     }
+     111                 :            : 
+     112                 :          3 :     mbedtls_pk_init(&pk);
+     113                 :            : 
+     114                 :          3 :     ret = mbedtls_pk_parse_public_key(&pk, der_data, der_size);
+     115         [ -  + ]:          3 :     if (ret != 0) {
+     116                 :          0 :         mbedtls_pk_free(&pk);
+     117                 :          0 :         return false;
+     118                 :            :     }
+     119                 :            : 
+     120         [ -  + ]:          3 :     if (mbedtls_pk_get_type(&pk) != MBEDTLS_PK_ECKEY) {
+     121                 :          0 :         mbedtls_pk_free(&pk);
+     122                 :          0 :         return false;
+     123                 :            :     }
+     124                 :            : 
+     125                 :          3 :     ecdh = allocate_zero_pool(sizeof(mbedtls_ecdh_context));
+     126         [ -  + ]:          3 :     if (ecdh == NULL) {
+     127                 :          0 :         mbedtls_pk_free(&pk);
+     128                 :          0 :         return false;
+     129                 :            :     }
+     130                 :          3 :     mbedtls_ecdh_init(ecdh);
+     131                 :            : 
+     132                 :          3 :     ret = mbedtls_ecdh_get_params(ecdh, mbedtls_pk_ec(pk),
+     133                 :            :                                   MBEDTLS_ECDH_OURS);
+     134         [ -  + ]:          3 :     if (ret != 0) {
+     135                 :          0 :         mbedtls_ecdh_free(ecdh);
+     136                 :          0 :         free_pool(ecdh);
+     137                 :          0 :         mbedtls_pk_free(&pk);
+     138                 :          0 :         return false;
+     139                 :            :     }
+     140                 :          3 :     mbedtls_pk_free(&pk);
+     141                 :            : 
+     142                 :          3 :     *ec_context = ecdh;
+     143                 :          3 :     return true;
+     144                 :            : }
+     145                 :            : #endif /* LIBSPDM_ECDSA_SUPPORT */
+     146                 :            : 
+     147                 :            : #if (LIBSPDM_EDDSA_ED25519_SUPPORT) || (LIBSPDM_EDDSA_ED448_SUPPORT)
+     148                 :            : /**
+     149                 :            :  * Retrieve the Ed Public key from the DER key data.
+     150                 :            :  *
+     151                 :            :  * The public key is ASN.1 DER-encoded as RFC7250 describes,
+     152                 :            :  * namely, the SubjectPublicKeyInfo structure of a X.509 certificate.
+     153                 :            :  *
+     154                 :            :  * @param[in]  der_data     Pointer to the DER-encoded key data to be retrieved.
+     155                 :            :  * @param[in]  der_size     size of the DER key data in bytes.
+     156                 :            :  * @param[out] ecd_context  Pointer to newly generated Ed DSA context which contain the retrieved
+     157                 :            :  *                          Ed public key component. Use libspdm_ecd_free() function to free the
+     158                 :            :  *                          resource.
+     159                 :            :  *
+     160                 :            :  * If der_data is NULL, then return false.
+     161                 :            :  * If ecd_context is NULL, then return false.
+     162                 :            :  *
+     163                 :            :  * @retval  true   Ed Public key was retrieved successfully.
+     164                 :            :  * @retval  false  Invalid DER key data.
+     165                 :            :  *
+     166                 :            :  **/
+     167                 :            : bool libspdm_ecd_get_public_key_from_der(const uint8_t *der_data,
+     168                 :            :                                          size_t der_size,
+     169                 :            :                                          void **ecd_context)
+     170                 :            : {
+     171                 :            :     return false;
+     172                 :            : }
+     173                 :            : #endif /* (LIBSPDM_EDDSA_ED25519_SUPPORT) || (LIBSPDM_EDDSA_ED448_SUPPORT) */
+     174                 :            : 
+     175                 :            : #if LIBSPDM_SM2_DSA_SUPPORT
+     176                 :            : /**
+     177                 :            :  * Retrieve the sm2 Public key from the DER key data.
+     178                 :            :  *
+     179                 :            :  * The public key is ASN.1 DER-encoded as RFC7250 describes,
+     180                 :            :  * namely, the SubjectPublicKeyInfo structure of a X.509 certificate.
+     181                 :            :  *
+     182                 :            :  * @param[in]  der_data     Pointer to the DER-encoded key data to be retrieved.
+     183                 :            :  * @param[in]  der_size     size of the DER key data in bytes.
+     184                 :            :  * @param[out] sm2_context  Pointer to newly generated sm2 context which contain the retrieved
+     185                 :            :  *                          sm2 public key component. Use sm2_free() function to free the
+     186                 :            :  *                          resource.
+     187                 :            :  *
+     188                 :            :  * If der_data is NULL, then return false.
+     189                 :            :  * If sm2_context is NULL, then return false.
+     190                 :            :  *
+     191                 :            :  * @retval  true   sm2 Public key was retrieved successfully.
+     192                 :            :  * @retval  false  Invalid DER key data.
+     193                 :            :  *
+     194                 :            :  **/
+     195                 :            : bool libspdm_sm2_get_public_key_from_der(const uint8_t *der_data,
+     196                 :            :                                          size_t der_size,
+     197                 :            :                                          void **sm2_context)
+     198                 :            : {
+     199                 :            :     return false;
+     200                 :            : }
+     201                 :            : #endif /* LIBSPDM_SM2_DSA_SUPPORT */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/der/index-sort-b.html b/coverage_log/os_stub/cryptlib_mbedtls/der/index-sort-b.html new file mode 100644 index 00000000000..04a99c29256 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/der/index-sort-b.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/der + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/derHitTotalCoverage
Test:coverage.infoLines:274757.4 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:142850.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
der.c +
57.4%57.4%
+
57.4 %27 / 47100.0 %2 / 250.0 %14 / 28
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/der/index-sort-f.html b/coverage_log/os_stub/cryptlib_mbedtls/der/index-sort-f.html new file mode 100644 index 00000000000..58fe87e363d --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/der/index-sort-f.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/der + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/derHitTotalCoverage
Test:coverage.infoLines:274757.4 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:142850.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
der.c +
57.4%57.4%
+
57.4 %27 / 47100.0 %2 / 250.0 %14 / 28
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/der/index-sort-l.html b/coverage_log/os_stub/cryptlib_mbedtls/der/index-sort-l.html new file mode 100644 index 00000000000..3c37250ad16 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/der/index-sort-l.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/der + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/derHitTotalCoverage
Test:coverage.infoLines:274757.4 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:142850.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
der.c +
57.4%57.4%
+
57.4 %27 / 47100.0 %2 / 250.0 %14 / 28
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/der/index.html b/coverage_log/os_stub/cryptlib_mbedtls/der/index.html new file mode 100644 index 00000000000..4e3e959f256 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/der/index.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/der + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/derHitTotalCoverage
Test:coverage.infoLines:274757.4 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:142850.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
der.c +
57.4%57.4%
+
57.4 %27 / 47100.0 %2 / 250.0 %14 / 28
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/hash/index-sort-b.html b/coverage_log/os_stub/cryptlib_mbedtls/hash/index-sort-b.html new file mode 100644 index 00000000000..86ec01887c6 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/hash/index-sort-b.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/hash + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/hashHitTotalCoverage
Test:coverage.infoLines:4515628.8 %
Date:2024-09-22 08:21:07Functions:82138.1 %
Branches:2210820.4 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
sha.c +
28.8%28.8%
+
28.8 %45 / 15638.1 %8 / 2120.4 %22 / 108
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/hash/index-sort-f.html b/coverage_log/os_stub/cryptlib_mbedtls/hash/index-sort-f.html new file mode 100644 index 00000000000..512911fbe19 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/hash/index-sort-f.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/hash + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/hashHitTotalCoverage
Test:coverage.infoLines:4515628.8 %
Date:2024-09-22 08:21:07Functions:82138.1 %
Branches:2210820.4 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
sha.c +
28.8%28.8%
+
28.8 %45 / 15638.1 %8 / 2120.4 %22 / 108
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/hash/index-sort-l.html b/coverage_log/os_stub/cryptlib_mbedtls/hash/index-sort-l.html new file mode 100644 index 00000000000..51356877f94 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/hash/index-sort-l.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/hash + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/hashHitTotalCoverage
Test:coverage.infoLines:4515628.8 %
Date:2024-09-22 08:21:07Functions:82138.1 %
Branches:2210820.4 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
sha.c +
28.8%28.8%
+
28.8 %45 / 15638.1 %8 / 2120.4 %22 / 108
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/hash/index.html b/coverage_log/os_stub/cryptlib_mbedtls/hash/index.html new file mode 100644 index 00000000000..d94d959fe07 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/hash/index.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/hash + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/hashHitTotalCoverage
Test:coverage.infoLines:4515628.8 %
Date:2024-09-22 08:21:07Functions:82138.1 %
Branches:2210820.4 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
sha.c +
28.8%28.8%
+
28.8 %45 / 15638.1 %8 / 2120.4 %22 / 108
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/hash/sha.c.func-sort-c.html b/coverage_log/os_stub/cryptlib_mbedtls/hash/sha.c.func-sort-c.html new file mode 100644 index 00000000000..a44c3ccd0b9 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/hash/sha.c.func-sort-c.html @@ -0,0 +1,165 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/hash/sha.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/hash - sha.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:4515628.8 %
Date:2024-09-22 08:21:07Functions:82138.1 %
Branches:2210820.4 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_sha384_duplicate0
libspdm_sha384_final0
libspdm_sha384_free0
libspdm_sha384_init0
libspdm_sha384_new0
libspdm_sha384_update0
libspdm_sha512_duplicate0
libspdm_sha512_final0
libspdm_sha512_free0
libspdm_sha512_hash_all0
libspdm_sha512_init0
libspdm_sha512_new0
libspdm_sha512_update0
libspdm_sha384_hash_all214
libspdm_sha256_final368
libspdm_sha256_duplicate390
libspdm_sha256_init424
libspdm_sha256_free771
libspdm_sha256_new814
libspdm_sha256_hash_all1638
libspdm_sha256_update10536
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/hash/sha.c.func.html b/coverage_log/os_stub/cryptlib_mbedtls/hash/sha.c.func.html new file mode 100644 index 00000000000..691d3256727 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/hash/sha.c.func.html @@ -0,0 +1,165 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/hash/sha.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/hash - sha.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:4515628.8 %
Date:2024-09-22 08:21:07Functions:82138.1 %
Branches:2210820.4 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_sha256_duplicate390
libspdm_sha256_final368
libspdm_sha256_free771
libspdm_sha256_hash_all1638
libspdm_sha256_init424
libspdm_sha256_new814
libspdm_sha256_update10536
libspdm_sha384_duplicate0
libspdm_sha384_final0
libspdm_sha384_free0
libspdm_sha384_hash_all214
libspdm_sha384_init0
libspdm_sha384_new0
libspdm_sha384_update0
libspdm_sha512_duplicate0
libspdm_sha512_final0
libspdm_sha512_free0
libspdm_sha512_hash_all0
libspdm_sha512_init0
libspdm_sha512_new0
libspdm_sha512_update0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/hash/sha.c.gcov.html b/coverage_log/os_stub/cryptlib_mbedtls/hash/sha.c.gcov.html new file mode 100644 index 00000000000..5e32fbcfae6 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/hash/sha.c.gcov.html @@ -0,0 +1,709 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/hash/sha.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/hash - sha.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:4515628.8 %
Date:2024-09-22 08:21:07Functions:82138.1 %
Branches:2210820.4 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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                 :            : /** @file
+       8                 :            :  * SHA-256/384/512 digest Wrapper Implementation.
+       9                 :            :  **/
+      10                 :            : 
+      11                 :            : #include "internal_crypt_lib.h"
+      12                 :            : #include <mbedtls/sha256.h>
+      13                 :            : #include <mbedtls/sha512.h>
+      14                 :            : 
+      15                 :            : /**
+      16                 :            :  * Allocates and initializes one HASH_CTX context for subsequent SHA256 use.
+      17                 :            :  *
+      18                 :            :  * @return  Pointer to the HASH_CTX context that has been initialized.
+      19                 :            :  *         If the allocations fails, libspdm_sha256_new() returns NULL.
+      20                 :            :  *
+      21                 :            :  **/
+      22                 :        814 : void *libspdm_sha256_new(void)
+      23                 :            : {
+      24                 :            :     void *hmac_md_ctx;
+      25                 :            : 
+      26                 :        814 :     hmac_md_ctx = allocate_zero_pool(sizeof(mbedtls_sha256_context));
+      27         [ -  + ]:        814 :     if (hmac_md_ctx == NULL) {
+      28                 :          0 :         return NULL;
+      29                 :            :     }
+      30                 :            : 
+      31                 :        814 :     return hmac_md_ctx;
+      32                 :            : }
+      33                 :            : 
+      34                 :            : /**
+      35                 :            :  * Release the specified HASH_CTX context.
+      36                 :            :  *
+      37                 :            :  * @param[in]  sha256_ctx  Pointer to the HASH_CTX context to be released.
+      38                 :            :  *
+      39                 :            :  **/
+      40                 :        771 : void libspdm_sha256_free(void *sha256_ctx)
+      41                 :            : {
+      42                 :        771 :     mbedtls_sha256_free(sha256_ctx);
+      43                 :        771 :     free_pool (sha256_ctx);
+      44                 :        771 : }
+      45                 :            : 
+      46                 :            : /**
+      47                 :            :  * Initializes user-supplied memory pointed by sha256_context as SHA-256 hash context for
+      48                 :            :  * subsequent use.
+      49                 :            :  *
+      50                 :            :  * If sha256_context is NULL, then return false.
+      51                 :            :  *
+      52                 :            :  * @param[out]  sha256_context  Pointer to SHA-256 context being initialized.
+      53                 :            :  *
+      54                 :            :  * @retval true   SHA-256 context initialization succeeded.
+      55                 :            :  * @retval false  SHA-256 context initialization failed.
+      56                 :            :  *
+      57                 :            :  **/
+      58                 :        424 : bool libspdm_sha256_init(void *sha256_context)
+      59                 :            : {
+      60                 :            :     int ret;
+      61                 :            : 
+      62         [ -  + ]:        424 :     if (sha256_context == NULL) {
+      63                 :          0 :         return false;
+      64                 :            :     }
+      65                 :            : 
+      66                 :        424 :     mbedtls_sha256_init(sha256_context);
+      67                 :            : 
+      68                 :        424 :     ret = mbedtls_sha256_starts(sha256_context, false);
+      69         [ -  + ]:        424 :     if (ret != 0) {
+      70                 :          0 :         return false;
+      71                 :            :     }
+      72                 :        424 :     return true;
+      73                 :            : }
+      74                 :            : 
+      75                 :            : /**
+      76                 :            :  * Makes a copy of an existing SHA-256 context.
+      77                 :            :  *
+      78                 :            :  * If sha256_context is NULL, then return false.
+      79                 :            :  * If new_sha256_context is NULL, then return false.
+      80                 :            :  *
+      81                 :            :  * @param[in]  sha256_context     Pointer to SHA-256 context being copied.
+      82                 :            :  * @param[out] new_sha256_context  Pointer to new SHA-256 context.
+      83                 :            :  *
+      84                 :            :  * @retval true   SHA-256 context copy succeeded.
+      85                 :            :  * @retval false  SHA-256 context copy failed.
+      86                 :            :  *
+      87                 :            :  **/
+      88                 :        390 : bool libspdm_sha256_duplicate(const void *sha256_context,
+      89                 :            :                               void *new_sha256_context)
+      90                 :            : {
+      91   [ +  -  -  + ]:        390 :     if (sha256_context == NULL || new_sha256_context == NULL) {
+      92                 :          0 :         return false;
+      93                 :            :     }
+      94                 :            : 
+      95                 :        390 :     mbedtls_sha256_clone(new_sha256_context, sha256_context);
+      96                 :            : 
+      97                 :        390 :     return true;
+      98                 :            : }
+      99                 :            : 
+     100                 :            : /**
+     101                 :            :  * Digests the input data and updates SHA-256 context.
+     102                 :            :  *
+     103                 :            :  * This function performs SHA-256 digest on a data buffer of the specified size.
+     104                 :            :  * It can be called multiple times to compute the digest of long or discontinuous data streams.
+     105                 :            :  * SHA-256 context should be already correctly initialized by libspdm_sha256_init(), and should not be finalized
+     106                 :            :  * by libspdm_sha256_final(). Behavior with invalid context is undefined.
+     107                 :            :  *
+     108                 :            :  * If sha256_context is NULL, then return false.
+     109                 :            :  *
+     110                 :            :  * @param[in, out]  sha256_context  Pointer to the SHA-256 context.
+     111                 :            :  * @param[in]       data           Pointer to the buffer containing the data to be hashed.
+     112                 :            :  * @param[in]       data_size       size of data buffer in bytes.
+     113                 :            :  *
+     114                 :            :  * @retval true   SHA-256 data digest succeeded.
+     115                 :            :  * @retval false  SHA-256 data digest failed.
+     116                 :            :  *
+     117                 :            :  **/
+     118                 :      10536 : bool libspdm_sha256_update(void *sha256_context, const void *data,
+     119                 :            :                            size_t data_size)
+     120                 :            : {
+     121                 :            :     int ret;
+     122                 :            : 
+     123         [ -  + ]:      10536 :     if (sha256_context == NULL) {
+     124                 :          0 :         return false;
+     125                 :            :     }
+     126                 :            : 
+     127   [ +  +  -  + ]:      10536 :     if (data == NULL && data_size != 0) {
+     128                 :          0 :         return false;
+     129                 :            :     }
+     130         [ -  + ]:      10536 :     if (data_size > INT_MAX) {
+     131                 :          0 :         return false;
+     132                 :            :     }
+     133                 :            : 
+     134                 :      10536 :     ret = mbedtls_sha256_update(sha256_context, data, data_size);
+     135         [ -  + ]:      10536 :     if (ret != 0) {
+     136                 :          0 :         return false;
+     137                 :            :     }
+     138                 :      10536 :     return true;
+     139                 :            : }
+     140                 :            : 
+     141                 :            : /**
+     142                 :            :  * Completes computation of the SHA-256 digest value.
+     143                 :            :  *
+     144                 :            :  * This function completes SHA-256 hash computation and retrieves the digest value into
+     145                 :            :  * the specified memory. After this function has been called, the SHA-256 context cannot
+     146                 :            :  * be used again.
+     147                 :            :  * SHA-256 context should be already correctly initialized by libspdm_sha256_init(), and should not be
+     148                 :            :  * finalized by libspdm_sha256_final(). Behavior with invalid SHA-256 context is undefined.
+     149                 :            :  *
+     150                 :            :  * If sha256_context is NULL, then return false.
+     151                 :            :  * If hash_value is NULL, then return false.
+     152                 :            :  *
+     153                 :            :  * @param[in, out]  sha256_context  Pointer to the SHA-256 context.
+     154                 :            :  * @param[out]      hash_value      Pointer to a buffer that receives the SHA-256 digest
+     155                 :            :  *                                value (32 bytes).
+     156                 :            :  *
+     157                 :            :  * @retval true   SHA-256 digest computation succeeded.
+     158                 :            :  * @retval false  SHA-256 digest computation failed.
+     159                 :            :  *
+     160                 :            :  **/
+     161                 :        368 : bool libspdm_sha256_final(void *sha256_context, uint8_t *hash_value)
+     162                 :            : {
+     163                 :            :     int ret;
+     164                 :            : 
+     165   [ +  -  -  + ]:        368 :     if (sha256_context == NULL || hash_value == NULL) {
+     166                 :          0 :         return false;
+     167                 :            :     }
+     168                 :            : 
+     169                 :        368 :     ret = mbedtls_sha256_finish(sha256_context, hash_value);
+     170                 :        368 :     mbedtls_sha256_free(sha256_context);
+     171         [ -  + ]:        368 :     if (ret != 0) {
+     172                 :          0 :         return false;
+     173                 :            :     }
+     174                 :        368 :     return true;
+     175                 :            : }
+     176                 :            : 
+     177                 :            : /**
+     178                 :            :  * Computes the SHA-256 message digest of a input data buffer.
+     179                 :            :  *
+     180                 :            :  * This function performs the SHA-256 message digest of a given data buffer, and places
+     181                 :            :  * the digest value into the specified memory.
+     182                 :            :  *
+     183                 :            :  * If this interface is not supported, then return false.
+     184                 :            :  *
+     185                 :            :  * @param[in]   data        Pointer to the buffer containing the data to be hashed.
+     186                 :            :  * @param[in]   data_size    size of data buffer in bytes.
+     187                 :            :  * @param[out]  hash_value   Pointer to a buffer that receives the SHA-256 digest
+     188                 :            :  *                         value (32 bytes).
+     189                 :            :  *
+     190                 :            :  * @retval true   SHA-256 digest computation succeeded.
+     191                 :            :  * @retval false  SHA-256 digest computation failed.
+     192                 :            :  * @retval false  This interface is not supported.
+     193                 :            :  *
+     194                 :            :  **/
+     195                 :       1638 : bool libspdm_sha256_hash_all(const void *data, size_t data_size,
+     196                 :            :                              uint8_t *hash_value)
+     197                 :            : {
+     198                 :            :     int ret;
+     199                 :            : 
+     200         [ -  + ]:       1638 :     if (hash_value == NULL) {
+     201                 :          0 :         return false;
+     202                 :            :     }
+     203   [ -  +  -  - ]:       1638 :     if (data == NULL && data_size != 0) {
+     204                 :          0 :         return false;
+     205                 :            :     }
+     206         [ -  + ]:       1638 :     if (data_size > INT_MAX) {
+     207                 :          0 :         return false;
+     208                 :            :     }
+     209                 :            : 
+     210                 :       1638 :     ret = mbedtls_sha256(data, data_size, hash_value, false);
+     211         [ -  + ]:       1638 :     if (ret != 0) {
+     212                 :          0 :         return false;
+     213                 :            :     }
+     214                 :       1638 :     return true;
+     215                 :            : }
+     216                 :            : 
+     217                 :            : /**
+     218                 :            :  * Allocates and initializes one HASH_CTX context for subsequent SHA384 use.
+     219                 :            :  *
+     220                 :            :  * @return  Pointer to the HASH_CTX context that has been initialized.
+     221                 :            :  *         If the allocations fails, libspdm_sha384_new() returns NULL.
+     222                 :            :  *
+     223                 :            :  **/
+     224                 :          0 : void *libspdm_sha384_new(void)
+     225                 :            : {
+     226                 :            :     void *hmac_md_ctx;
+     227                 :            : 
+     228                 :          0 :     hmac_md_ctx = allocate_zero_pool(sizeof(mbedtls_sha512_context));
+     229         [ #  # ]:          0 :     if (hmac_md_ctx == NULL) {
+     230                 :          0 :         return NULL;
+     231                 :            :     }
+     232                 :            : 
+     233                 :          0 :     return hmac_md_ctx;
+     234                 :            : }
+     235                 :            : 
+     236                 :            : /**
+     237                 :            :  * Release the specified HASH_CTX context.
+     238                 :            :  *
+     239                 :            :  * @param[in]  sha384_ctx  Pointer to the HASH_CTX context to be released.
+     240                 :            :  *
+     241                 :            :  **/
+     242                 :          0 : void libspdm_sha384_free(void *sha384_ctx)
+     243                 :            : {
+     244                 :          0 :     mbedtls_sha512_free(sha384_ctx);
+     245                 :          0 :     free_pool (sha384_ctx);
+     246                 :          0 : }
+     247                 :            : 
+     248                 :            : /**
+     249                 :            :  * Initializes user-supplied memory pointed by sha384_context as SHA-384 hash context for
+     250                 :            :  * subsequent use.
+     251                 :            :  *
+     252                 :            :  * If sha384_context is NULL, then return false.
+     253                 :            :  *
+     254                 :            :  * @param[out]  sha384_context  Pointer to SHA-384 context being initialized.
+     255                 :            :  *
+     256                 :            :  * @retval true   SHA-384 context initialization succeeded.
+     257                 :            :  * @retval false  SHA-384 context initialization failed.
+     258                 :            :  *
+     259                 :            :  **/
+     260                 :          0 : bool libspdm_sha384_init(void *sha384_context)
+     261                 :            : {
+     262                 :            :     int ret;
+     263                 :            : 
+     264         [ #  # ]:          0 :     if (sha384_context == NULL) {
+     265                 :          0 :         return false;
+     266                 :            :     }
+     267                 :            : 
+     268                 :          0 :     mbedtls_sha512_init(sha384_context);
+     269                 :            : 
+     270                 :          0 :     ret = mbedtls_sha512_starts(sha384_context, true);
+     271         [ #  # ]:          0 :     if (ret != 0) {
+     272                 :          0 :         return false;
+     273                 :            :     }
+     274                 :          0 :     return true;
+     275                 :            : }
+     276                 :            : 
+     277                 :            : /**
+     278                 :            :  * Makes a copy of an existing SHA-384 context.
+     279                 :            :  *
+     280                 :            :  * If sha384_context is NULL, then return false.
+     281                 :            :  * If new_sha384_context is NULL, then return false.
+     282                 :            :  * If this interface is not supported, then return false.
+     283                 :            :  *
+     284                 :            :  * @param[in]  sha384_context     Pointer to SHA-384 context being copied.
+     285                 :            :  * @param[out] new_sha384_context  Pointer to new SHA-384 context.
+     286                 :            :  *
+     287                 :            :  * @retval true   SHA-384 context copy succeeded.
+     288                 :            :  * @retval false  SHA-384 context copy failed.
+     289                 :            :  * @retval false  This interface is not supported.
+     290                 :            :  *
+     291                 :            :  **/
+     292                 :          0 : bool libspdm_sha384_duplicate(const void *sha384_context,
+     293                 :            :                               void *new_sha384_context)
+     294                 :            : {
+     295   [ #  #  #  # ]:          0 :     if (sha384_context == NULL || new_sha384_context == NULL) {
+     296                 :          0 :         return false;
+     297                 :            :     }
+     298                 :            : 
+     299                 :          0 :     mbedtls_sha512_clone(new_sha384_context, sha384_context);
+     300                 :            : 
+     301                 :          0 :     return true;
+     302                 :            : }
+     303                 :            : 
+     304                 :            : /**
+     305                 :            :  * Digests the input data and updates SHA-384 context.
+     306                 :            :  *
+     307                 :            :  * This function performs SHA-384 digest on a data buffer of the specified size.
+     308                 :            :  * It can be called multiple times to compute the digest of long or discontinuous data streams.
+     309                 :            :  * SHA-384 context should be already correctly initialized by libspdm_sha384_init(), and should not be finalized
+     310                 :            :  * by libspdm_sha384_final(). Behavior with invalid context is undefined.
+     311                 :            :  *
+     312                 :            :  * If sha384_context is NULL, then return false.
+     313                 :            :  *
+     314                 :            :  * @param[in, out]  sha384_context  Pointer to the SHA-384 context.
+     315                 :            :  * @param[in]       data           Pointer to the buffer containing the data to be hashed.
+     316                 :            :  * @param[in]       data_size       size of data buffer in bytes.
+     317                 :            :  *
+     318                 :            :  * @retval true   SHA-384 data digest succeeded.
+     319                 :            :  * @retval false  SHA-384 data digest failed.
+     320                 :            :  *
+     321                 :            :  **/
+     322                 :          0 : bool libspdm_sha384_update(void *sha384_context, const void *data,
+     323                 :            :                            size_t data_size)
+     324                 :            : {
+     325                 :            :     int ret;
+     326                 :            : 
+     327         [ #  # ]:          0 :     if (sha384_context == NULL) {
+     328                 :          0 :         return false;
+     329                 :            :     }
+     330                 :            : 
+     331   [ #  #  #  # ]:          0 :     if (data == NULL && data_size != 0) {
+     332                 :          0 :         return false;
+     333                 :            :     }
+     334         [ #  # ]:          0 :     if (data_size > INT_MAX) {
+     335                 :          0 :         return false;
+     336                 :            :     }
+     337                 :            : 
+     338                 :          0 :     ret = mbedtls_sha512_update(sha384_context, data, data_size);
+     339         [ #  # ]:          0 :     if (ret != 0) {
+     340                 :          0 :         return false;
+     341                 :            :     }
+     342                 :          0 :     return true;
+     343                 :            : }
+     344                 :            : 
+     345                 :            : /**
+     346                 :            :  * Completes computation of the SHA-384 digest value.
+     347                 :            :  *
+     348                 :            :  * This function completes SHA-384 hash computation and retrieves the digest value into
+     349                 :            :  * the specified memory. After this function has been called, the SHA-384 context cannot
+     350                 :            :  * be used again.
+     351                 :            :  * SHA-384 context should be already correctly initialized by libspdm_sha384_init(), and should not be
+     352                 :            :  * finalized by libspdm_sha384_final(). Behavior with invalid SHA-384 context is undefined.
+     353                 :            :  *
+     354                 :            :  * If sha384_context is NULL, then return false.
+     355                 :            :  * If hash_value is NULL, then return false.
+     356                 :            :  *
+     357                 :            :  * @param[in, out]  sha384_context  Pointer to the SHA-384 context.
+     358                 :            :  * @param[out]      hash_value      Pointer to a buffer that receives the SHA-384 digest
+     359                 :            :  *                                value (48 bytes).
+     360                 :            :  *
+     361                 :            :  * @retval true   SHA-384 digest computation succeeded.
+     362                 :            :  * @retval false  SHA-384 digest computation failed.
+     363                 :            :  *
+     364                 :            :  **/
+     365                 :          0 : bool libspdm_sha384_final(void *sha384_context, uint8_t *hash_value)
+     366                 :            : {
+     367                 :            :     int ret;
+     368                 :            : 
+     369   [ #  #  #  # ]:          0 :     if (sha384_context == NULL || hash_value == NULL) {
+     370                 :          0 :         return false;
+     371                 :            :     }
+     372                 :            : 
+     373                 :          0 :     ret = mbedtls_sha512_finish(sha384_context, hash_value);
+     374                 :            : 
+     375                 :          0 :     mbedtls_sha512_free(sha384_context);
+     376         [ #  # ]:          0 :     if (ret != 0) {
+     377                 :          0 :         return false;
+     378                 :            :     }
+     379                 :          0 :     return true;
+     380                 :            : }
+     381                 :            : 
+     382                 :            : /**
+     383                 :            :  * Computes the SHA-384 message digest of a input data buffer.
+     384                 :            :  *
+     385                 :            :  * This function performs the SHA-384 message digest of a given data buffer, and places
+     386                 :            :  * the digest value into the specified memory.
+     387                 :            :  *
+     388                 :            :  * If this interface is not supported, then return false.
+     389                 :            :  *
+     390                 :            :  * @param[in]   data        Pointer to the buffer containing the data to be hashed.
+     391                 :            :  * @param[in]   data_size    size of data buffer in bytes.
+     392                 :            :  * @param[out]  hash_value   Pointer to a buffer that receives the SHA-384 digest
+     393                 :            :  *                         value (48 bytes).
+     394                 :            :  *
+     395                 :            :  * @retval true   SHA-384 digest computation succeeded.
+     396                 :            :  * @retval false  SHA-384 digest computation failed.
+     397                 :            :  * @retval false  This interface is not supported.
+     398                 :            :  *
+     399                 :            :  **/
+     400                 :        214 : bool libspdm_sha384_hash_all(const void *data, size_t data_size,
+     401                 :            :                              uint8_t *hash_value)
+     402                 :            : {
+     403                 :            :     int ret;
+     404                 :            : 
+     405         [ -  + ]:        214 :     if (hash_value == NULL) {
+     406                 :          0 :         return false;
+     407                 :            :     }
+     408   [ -  +  -  - ]:        214 :     if (data == NULL && data_size != 0) {
+     409                 :          0 :         return false;
+     410                 :            :     }
+     411         [ -  + ]:        214 :     if (data_size > INT_MAX) {
+     412                 :          0 :         return false;
+     413                 :            :     }
+     414                 :            : 
+     415                 :        214 :     ret = mbedtls_sha512(data, data_size, hash_value, true);
+     416         [ -  + ]:        214 :     if (ret != 0) {
+     417                 :          0 :         return false;
+     418                 :            :     }
+     419                 :        214 :     return true;
+     420                 :            : }
+     421                 :            : 
+     422                 :            : /**
+     423                 :            :  * Allocates and initializes one HASH_CTX context for subsequent SHA512 use.
+     424                 :            :  *
+     425                 :            :  * @return  Pointer to the HASH_CTX context that has been initialized.
+     426                 :            :  *         If the allocations fails, libspdm_sha512_new() returns NULL.
+     427                 :            :  *
+     428                 :            :  **/
+     429                 :          0 : void *libspdm_sha512_new(void)
+     430                 :            : {
+     431                 :            :     void *hmac_md_ctx;
+     432                 :            : 
+     433                 :          0 :     hmac_md_ctx = allocate_zero_pool(sizeof(mbedtls_sha512_context));
+     434         [ #  # ]:          0 :     if (hmac_md_ctx == NULL) {
+     435                 :          0 :         return NULL;
+     436                 :            :     }
+     437                 :            : 
+     438                 :          0 :     return hmac_md_ctx;
+     439                 :            : }
+     440                 :            : 
+     441                 :            : /**
+     442                 :            :  * Release the specified HASH_CTX context.
+     443                 :            :  *
+     444                 :            :  * @param[in]  sha512_ctx  Pointer to the HASH_CTX context to be released.
+     445                 :            :  *
+     446                 :            :  **/
+     447                 :          0 : void libspdm_sha512_free(void *sha512_ctx)
+     448                 :            : {
+     449                 :          0 :     mbedtls_sha512_free(sha512_ctx);
+     450                 :          0 :     free_pool (sha512_ctx);
+     451                 :          0 : }
+     452                 :            : 
+     453                 :            : /**
+     454                 :            :  * Initializes user-supplied memory pointed by sha512_context as SHA-512 hash context for
+     455                 :            :  * subsequent use.
+     456                 :            :  *
+     457                 :            :  * If sha512_context is NULL, then return false.
+     458                 :            :  *
+     459                 :            :  * @param[out]  sha512_context  Pointer to SHA-512 context being initialized.
+     460                 :            :  *
+     461                 :            :  * @retval true   SHA-512 context initialization succeeded.
+     462                 :            :  * @retval false  SHA-512 context initialization failed.
+     463                 :            :  *
+     464                 :            :  **/
+     465                 :          0 : bool libspdm_sha512_init(void *sha512_context)
+     466                 :            : {
+     467                 :            :     int ret;
+     468                 :            : 
+     469         [ #  # ]:          0 :     if (sha512_context == NULL) {
+     470                 :          0 :         return false;
+     471                 :            :     }
+     472                 :            : 
+     473                 :          0 :     mbedtls_sha512_init(sha512_context);
+     474                 :            : 
+     475                 :          0 :     ret = mbedtls_sha512_starts(sha512_context, false);
+     476         [ #  # ]:          0 :     if (ret != 0) {
+     477                 :          0 :         return false;
+     478                 :            :     }
+     479                 :          0 :     return true;
+     480                 :            : }
+     481                 :            : 
+     482                 :            : /**
+     483                 :            :  * Makes a copy of an existing SHA-512 context.
+     484                 :            :  *
+     485                 :            :  * If sha512_context is NULL, then return false.
+     486                 :            :  * If new_sha512_context is NULL, then return false.
+     487                 :            :  * If this interface is not supported, then return false.
+     488                 :            :  *
+     489                 :            :  * @param[in]  sha512_context     Pointer to SHA-512 context being copied.
+     490                 :            :  * @param[out] new_sha512_context  Pointer to new SHA-512 context.
+     491                 :            :  *
+     492                 :            :  * @retval true   SHA-512 context copy succeeded.
+     493                 :            :  * @retval false  SHA-512 context copy failed.
+     494                 :            :  * @retval false  This interface is not supported.
+     495                 :            :  *
+     496                 :            :  **/
+     497                 :          0 : bool libspdm_sha512_duplicate(const void *sha512_context,
+     498                 :            :                               void *new_sha512_context)
+     499                 :            : {
+     500   [ #  #  #  # ]:          0 :     if (sha512_context == NULL || new_sha512_context == NULL) {
+     501                 :          0 :         return false;
+     502                 :            :     }
+     503                 :            : 
+     504                 :          0 :     mbedtls_sha512_clone(new_sha512_context, sha512_context);
+     505                 :            : 
+     506                 :          0 :     return true;
+     507                 :            : }
+     508                 :            : 
+     509                 :            : /**
+     510                 :            :  * Digests the input data and updates SHA-512 context.
+     511                 :            :  *
+     512                 :            :  * This function performs SHA-512 digest on a data buffer of the specified size.
+     513                 :            :  * It can be called multiple times to compute the digest of long or discontinuous data streams.
+     514                 :            :  * SHA-512 context should be already correctly initialized by libspdm_sha512_init(), and should not be finalized
+     515                 :            :  * by libspdm_sha512_final(). Behavior with invalid context is undefined.
+     516                 :            :  *
+     517                 :            :  * If sha512_context is NULL, then return false.
+     518                 :            :  *
+     519                 :            :  * @param[in, out]  sha512_context  Pointer to the SHA-512 context.
+     520                 :            :  * @param[in]       data           Pointer to the buffer containing the data to be hashed.
+     521                 :            :  * @param[in]       data_size       size of data buffer in bytes.
+     522                 :            :  *
+     523                 :            :  * @retval true   SHA-512 data digest succeeded.
+     524                 :            :  * @retval false  SHA-512 data digest failed.
+     525                 :            :  *
+     526                 :            :  **/
+     527                 :          0 : bool libspdm_sha512_update(void *sha512_context, const void *data,
+     528                 :            :                            size_t data_size)
+     529                 :            : {
+     530                 :            :     int ret;
+     531                 :            : 
+     532         [ #  # ]:          0 :     if (sha512_context == NULL) {
+     533                 :          0 :         return false;
+     534                 :            :     }
+     535                 :            : 
+     536   [ #  #  #  # ]:          0 :     if (data == NULL && data_size != 0) {
+     537                 :          0 :         return false;
+     538                 :            :     }
+     539         [ #  # ]:          0 :     if (data_size > INT_MAX) {
+     540                 :          0 :         return false;
+     541                 :            :     }
+     542                 :            : 
+     543                 :          0 :     ret = mbedtls_sha512_update(sha512_context, data, data_size);
+     544         [ #  # ]:          0 :     if (ret != 0) {
+     545                 :          0 :         return false;
+     546                 :            :     }
+     547                 :          0 :     return true;
+     548                 :            : }
+     549                 :            : 
+     550                 :            : /**
+     551                 :            :  * Completes computation of the SHA-512 digest value.
+     552                 :            :  *
+     553                 :            :  * This function completes SHA-512 hash computation and retrieves the digest value into
+     554                 :            :  * the specified memory. After this function has been called, the SHA-512 context cannot
+     555                 :            :  * be used again.
+     556                 :            :  * SHA-512 context should be already correctly initialized by libspdm_sha512_init(), and should not be
+     557                 :            :  * finalized by libspdm_sha512_final(). Behavior with invalid SHA-512 context is undefined.
+     558                 :            :  *
+     559                 :            :  * If sha512_context is NULL, then return false.
+     560                 :            :  * If hash_value is NULL, then return false.
+     561                 :            :  *
+     562                 :            :  * @param[in, out]  sha512_context  Pointer to the SHA-512 context.
+     563                 :            :  * @param[out]      hash_value      Pointer to a buffer that receives the SHA-512 digest
+     564                 :            :  *                                value (64 bytes).
+     565                 :            :  *
+     566                 :            :  * @retval true   SHA-512 digest computation succeeded.
+     567                 :            :  * @retval false  SHA-512 digest computation failed.
+     568                 :            :  *
+     569                 :            :  **/
+     570                 :          0 : bool libspdm_sha512_final(void *sha512_context, uint8_t *hash_value)
+     571                 :            : {
+     572                 :            :     int ret;
+     573                 :            : 
+     574   [ #  #  #  # ]:          0 :     if (sha512_context == NULL || hash_value == NULL) {
+     575                 :          0 :         return false;
+     576                 :            :     }
+     577                 :            : 
+     578                 :          0 :     ret = mbedtls_sha512_finish(sha512_context, hash_value);
+     579                 :          0 :     mbedtls_sha512_free(sha512_context);
+     580         [ #  # ]:          0 :     if (ret != 0) {
+     581                 :          0 :         return false;
+     582                 :            :     }
+     583                 :          0 :     return true;
+     584                 :            : }
+     585                 :            : 
+     586                 :            : /**
+     587                 :            :  * Computes the SHA-512 message digest of a input data buffer.
+     588                 :            :  *
+     589                 :            :  * This function performs the SHA-512 message digest of a given data buffer, and places
+     590                 :            :  * the digest value into the specified memory.
+     591                 :            :  *
+     592                 :            :  * If this interface is not supported, then return false.
+     593                 :            :  *
+     594                 :            :  * @param[in]   data        Pointer to the buffer containing the data to be hashed.
+     595                 :            :  * @param[in]   data_size    size of data buffer in bytes.
+     596                 :            :  * @param[out]  hash_value   Pointer to a buffer that receives the SHA-512 digest
+     597                 :            :  *                         value (64 bytes).
+     598                 :            :  *
+     599                 :            :  * @retval true   SHA-512 digest computation succeeded.
+     600                 :            :  * @retval false  SHA-512 digest computation failed.
+     601                 :            :  * @retval false  This interface is not supported.
+     602                 :            :  *
+     603                 :            :  **/
+     604                 :          0 : bool libspdm_sha512_hash_all(const void *data, size_t data_size,
+     605                 :            :                              uint8_t *hash_value)
+     606                 :            : {
+     607                 :            :     int ret;
+     608                 :            : 
+     609         [ #  # ]:          0 :     if (hash_value == NULL) {
+     610                 :          0 :         return false;
+     611                 :            :     }
+     612   [ #  #  #  # ]:          0 :     if (data == NULL && data_size != 0) {
+     613                 :          0 :         return false;
+     614                 :            :     }
+     615         [ #  # ]:          0 :     if (data_size > INT_MAX) {
+     616                 :          0 :         return false;
+     617                 :            :     }
+     618                 :            : 
+     619                 :          0 :     ret = mbedtls_sha512(data, data_size, hash_value, false);
+     620         [ #  # ]:          0 :     if (ret != 0) {
+     621                 :          0 :         return false;
+     622                 :            :     }
+     623                 :          0 :     return true;
+     624                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/hmac/hmac_sha.c.func-sort-c.html b/coverage_log/os_stub/cryptlib_mbedtls/hmac/hmac_sha.c.func-sort-c.html new file mode 100644 index 00000000000..ede40655e08 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/hmac/hmac_sha.c.func-sort-c.html @@ -0,0 +1,197 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/hmac/hmac_sha.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/hmac - hmac_sha.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:121239.8 %
Date:2024-09-22 08:21:07Functions:42913.8 %
Branches:2464.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
hmac_md_duplicate0
hmac_md_final0
hmac_md_free0
hmac_md_get_blocksize0
hmac_md_new0
hmac_md_set_key0
hmac_md_update0
libspdm_hmac_sha256_duplicate0
libspdm_hmac_sha256_final0
libspdm_hmac_sha256_free0
libspdm_hmac_sha256_new0
libspdm_hmac_sha256_set_key0
libspdm_hmac_sha256_update0
libspdm_hmac_sha384_duplicate0
libspdm_hmac_sha384_final0
libspdm_hmac_sha384_free0
libspdm_hmac_sha384_new0
libspdm_hmac_sha384_set_key0
libspdm_hmac_sha384_update0
libspdm_hmac_sha512_duplicate0
libspdm_hmac_sha512_final0
libspdm_hmac_sha512_free0
libspdm_hmac_sha512_new0
libspdm_hmac_sha512_set_key0
libspdm_hmac_sha512_update0
libspdm_hmac_sha384_all1
libspdm_hmac_sha512_all1
libspdm_hmac_sha256_all317
hmac_md_all319
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/hmac/hmac_sha.c.func.html b/coverage_log/os_stub/cryptlib_mbedtls/hmac/hmac_sha.c.func.html new file mode 100644 index 00000000000..dcd2a599809 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/hmac/hmac_sha.c.func.html @@ -0,0 +1,197 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/hmac/hmac_sha.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/hmac - hmac_sha.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:121239.8 %
Date:2024-09-22 08:21:07Functions:42913.8 %
Branches:2464.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
hmac_md_all319
hmac_md_duplicate0
hmac_md_final0
hmac_md_free0
hmac_md_get_blocksize0
hmac_md_new0
hmac_md_set_key0
hmac_md_update0
libspdm_hmac_sha256_all317
libspdm_hmac_sha256_duplicate0
libspdm_hmac_sha256_final0
libspdm_hmac_sha256_free0
libspdm_hmac_sha256_new0
libspdm_hmac_sha256_set_key0
libspdm_hmac_sha256_update0
libspdm_hmac_sha384_all1
libspdm_hmac_sha384_duplicate0
libspdm_hmac_sha384_final0
libspdm_hmac_sha384_free0
libspdm_hmac_sha384_new0
libspdm_hmac_sha384_set_key0
libspdm_hmac_sha384_update0
libspdm_hmac_sha512_all1
libspdm_hmac_sha512_duplicate0
libspdm_hmac_sha512_final0
libspdm_hmac_sha512_free0
libspdm_hmac_sha512_new0
libspdm_hmac_sha512_set_key0
libspdm_hmac_sha512_update0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/hmac/hmac_sha.c.gcov.html b/coverage_log/os_stub/cryptlib_mbedtls/hmac/hmac_sha.c.gcov.html new file mode 100644 index 00000000000..103759fb556 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/hmac/hmac_sha.c.gcov.html @@ -0,0 +1,794 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/hmac/hmac_sha.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/hmac - hmac_sha.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:121239.8 %
Date:2024-09-22 08:21:07Functions:42913.8 %
Branches:2464.3 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 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                 :            : /** @file
+       8                 :            :  * HMAC-SHA256/384/512 Wrapper Implementation.
+       9                 :            :  **/
+      10                 :            : 
+      11                 :            : #include "internal_crypt_lib.h"
+      12                 :            : #include <mbedtls/md.h>
+      13                 :            : 
+      14                 :            : /**
+      15                 :            :  * Allocates and initializes one HMAC_CTX context for subsequent HMAC-MD use.
+      16                 :            :  *
+      17                 :            :  * @return  Pointer to the HMAC_CTX context that has been initialized.
+      18                 :            :  *         If the allocations fails, hmac_md_new() returns NULL.
+      19                 :            :  *
+      20                 :            :  **/
+      21                 :          0 : void *hmac_md_new(void)
+      22                 :            : {
+      23                 :            :     void *hmac_md_ctx;
+      24                 :            : 
+      25                 :          0 :     hmac_md_ctx = allocate_zero_pool(sizeof(mbedtls_md_context_t));
+      26         [ #  # ]:          0 :     if (hmac_md_ctx == NULL) {
+      27                 :          0 :         return NULL;
+      28                 :            :     }
+      29                 :            : 
+      30                 :          0 :     return hmac_md_ctx;
+      31                 :            : }
+      32                 :            : 
+      33                 :            : /**
+      34                 :            :  * Release the specified HMAC_CTX context.
+      35                 :            :  *
+      36                 :            :  * @param[in]  hmac_md_ctx  Pointer to the HMAC_CTX context to be released.
+      37                 :            :  *
+      38                 :            :  **/
+      39                 :          0 : void hmac_md_free(void *hmac_md_ctx)
+      40                 :            : {
+      41                 :          0 :     mbedtls_md_free(hmac_md_ctx);
+      42                 :          0 :     free_pool (hmac_md_ctx);
+      43                 :          0 : }
+      44                 :            : 
+      45                 :            : /**
+      46                 :            :  * Set user-supplied key for subsequent use. It must be done before any
+      47                 :            :  * calling to hmac_md_update().
+      48                 :            :  *
+      49                 :            :  * If hmac_md_ctx is NULL, then return false.
+      50                 :            :  *
+      51                 :            :  * @param[in]   md_type             message digest Type.
+      52                 :            :  * @param[out]  hmac_md_ctx      Pointer to HMAC-MD context.
+      53                 :            :  * @param[in]   key                Pointer to the user-supplied key.
+      54                 :            :  * @param[in]   key_size            key size in bytes.
+      55                 :            :  *
+      56                 :            :  * @retval true   The key is set successfully.
+      57                 :            :  * @retval false  The key is set unsuccessfully.
+      58                 :            :  *
+      59                 :            :  **/
+      60                 :          0 : bool hmac_md_set_key(const mbedtls_md_type_t md_type, void *hmac_md_ctx,
+      61                 :            :                      const uint8_t *key, size_t key_size)
+      62                 :            : {
+      63                 :            :     const mbedtls_md_info_t *md_info;
+      64                 :            :     int ret;
+      65                 :            : 
+      66   [ #  #  #  # ]:          0 :     if (hmac_md_ctx == NULL || key_size > INT_MAX) {
+      67                 :          0 :         return false;
+      68                 :            :     }
+      69                 :            : 
+      70                 :          0 :     libspdm_zero_mem(hmac_md_ctx, sizeof(mbedtls_md_context_t));
+      71                 :          0 :     mbedtls_md_init(hmac_md_ctx);
+      72                 :            : 
+      73                 :          0 :     md_info = mbedtls_md_info_from_type(md_type);
+      74         [ #  # ]:          0 :     LIBSPDM_ASSERT(md_info != NULL);
+      75                 :            : 
+      76                 :          0 :     ret = mbedtls_md_setup(hmac_md_ctx, md_info, 1);
+      77         [ #  # ]:          0 :     if (ret != 0) {
+      78                 :          0 :         return false;
+      79                 :            :     }
+      80                 :            : 
+      81                 :          0 :     ret = mbedtls_md_hmac_starts(hmac_md_ctx, key, key_size);
+      82         [ #  # ]:          0 :     if (ret != 0) {
+      83                 :          0 :         return false;
+      84                 :            :     }
+      85                 :          0 :     return true;
+      86                 :            : }
+      87                 :            : 
+      88                 :            : /**
+      89                 :            :  * Return block size in md_type.
+      90                 :            :  * This function is use to enable hmac_duplicate.
+      91                 :            :  *
+      92                 :            :  * @param[in]   md_type          mbedtls Type.
+      93                 :            :  *
+      94                 :            :  * @retval blocksize in md_type
+      95                 :            :  **/
+      96                 :          0 : int hmac_md_get_blocksize( mbedtls_md_type_t md_type )
+      97                 :            : {
+      98   [ #  #  #  # ]:          0 :     switch( md_type )
+      99                 :            :     {
+     100                 :          0 :     case MBEDTLS_MD_SHA256:
+     101                 :          0 :         return 64;
+     102                 :          0 :     case MBEDTLS_MD_SHA384:
+     103                 :          0 :         return 128;
+     104                 :          0 :     case MBEDTLS_MD_SHA512:
+     105                 :          0 :         return 128;
+     106                 :          0 :     default:
+     107                 :          0 :         LIBSPDM_ASSERT(false);
+     108                 :          0 :         return 0;
+     109                 :            :     }
+     110                 :            : }
+     111                 :            : 
+     112                 :            : /**
+     113                 :            :  * Makes a copy of an existing HMAC-MD context.
+     114                 :            :  *
+     115                 :            :  * If hmac_md_ctx is NULL, then return false.
+     116                 :            :  * If new_hmac_md_ctx is NULL, then return false.
+     117                 :            :  *
+     118                 :            :  * @param[in]  md_type          message digest Type.
+     119                 :            :  * @param[in]  hmac_md_ctx      Pointer to HMAC-MD context being copied.
+     120                 :            :  * @param[out] new_hmac_md_ctx  Pointer to new HMAC-MD context.
+     121                 :            :  *
+     122                 :            :  * @retval true   HMAC-MD context copy succeeded.
+     123                 :            :  * @retval false  HMAC-MD context copy failed.
+     124                 :            :  *
+     125                 :            :  **/
+     126                 :          0 : bool hmac_md_duplicate(const mbedtls_md_type_t md_type, const void *hmac_md_ctx,
+     127                 :            :                        void *new_hmac_md_ctx)
+     128                 :            : {
+     129                 :            :     int ret;
+     130                 :            :     const mbedtls_md_info_t *md_info;
+     131                 :            : 
+     132   [ #  #  #  # ]:          0 :     if (hmac_md_ctx == NULL || new_hmac_md_ctx == NULL) {
+     133                 :          0 :         return false;
+     134                 :            :     }
+     135                 :            : 
+     136                 :          0 :     libspdm_zero_mem(new_hmac_md_ctx, sizeof(mbedtls_md_context_t));
+     137                 :          0 :     mbedtls_md_init(new_hmac_md_ctx);
+     138                 :            : 
+     139                 :          0 :     md_info = mbedtls_md_info_from_type(md_type);
+     140         [ #  # ]:          0 :     LIBSPDM_ASSERT(md_info != NULL);
+     141                 :            : 
+     142                 :          0 :     ret = mbedtls_md_setup(new_hmac_md_ctx, md_info, 1);
+     143         [ #  # ]:          0 :     if (ret != 0) {
+     144                 :          0 :         return false;
+     145                 :            :     }
+     146                 :          0 :     ret = mbedtls_md_clone(new_hmac_md_ctx, hmac_md_ctx);
+     147         [ #  # ]:          0 :     if (ret != 0) {
+     148                 :          0 :         return false;
+     149                 :            :     }
+     150                 :            :     /*Temporary solution to the problem of context clone.
+     151                 :            :      * There are not any standard function in mbedtls to clone a complete hmac context.*/
+     152                 :          0 :     libspdm_copy_mem(((mbedtls_md_context_t *)new_hmac_md_ctx)->MBEDTLS_PRIVATE(hmac_ctx),
+     153                 :          0 :                      hmac_md_get_blocksize(md_type) * 2,
+     154                 :          0 :                      ((const mbedtls_md_context_t *)hmac_md_ctx)->MBEDTLS_PRIVATE(hmac_ctx),
+     155                 :          0 :                      hmac_md_get_blocksize(md_type) * 2);
+     156                 :          0 :     return true;
+     157                 :            : }
+     158                 :            : 
+     159                 :            : /**
+     160                 :            :  * Digests the input data and updates HMAC-MD context.
+     161                 :            :  *
+     162                 :            :  * This function performs HMAC-MD digest on a data buffer of the specified size.
+     163                 :            :  * It can be called multiple times to compute the digest of long or discontinuous data streams.
+     164                 :            :  * HMAC-MD context should be initialized by hmac_md_new(), and should not be finalized
+     165                 :            :  * by hmac_md_final(). Behavior with invalid context is undefined.
+     166                 :            :  *
+     167                 :            :  * If hmac_md_ctx is NULL, then return false.
+     168                 :            :  *
+     169                 :            :  * @param[in, out]  hmac_md_ctx     Pointer to the HMAC-MD context.
+     170                 :            :  * @param[in]       data              Pointer to the buffer containing the data to be digested.
+     171                 :            :  * @param[in]       data_size          size of data buffer in bytes.
+     172                 :            :  *
+     173                 :            :  * @retval true   HMAC-MD data digest succeeded.
+     174                 :            :  * @retval false  HMAC-MD data digest failed.
+     175                 :            :  *
+     176                 :            :  **/
+     177                 :          0 : bool hmac_md_update(void *hmac_md_ctx, const void *data,
+     178                 :            :                     size_t data_size)
+     179                 :            : {
+     180                 :            :     int ret;
+     181                 :            : 
+     182         [ #  # ]:          0 :     if (hmac_md_ctx == NULL) {
+     183                 :          0 :         return false;
+     184                 :            :     }
+     185                 :            : 
+     186   [ #  #  #  # ]:          0 :     if (data == NULL && data_size != 0) {
+     187                 :          0 :         return false;
+     188                 :            :     }
+     189         [ #  # ]:          0 :     if (data_size > INT_MAX) {
+     190                 :          0 :         return false;
+     191                 :            :     }
+     192                 :            : 
+     193                 :          0 :     ret = mbedtls_md_hmac_update(hmac_md_ctx, data, data_size);
+     194         [ #  # ]:          0 :     if (ret != 0) {
+     195                 :          0 :         return false;
+     196                 :            :     }
+     197                 :          0 :     return true;
+     198                 :            : }
+     199                 :            : 
+     200                 :            : /**
+     201                 :            :  * Completes computation of the HMAC-MD digest value.
+     202                 :            :  *
+     203                 :            :  * This function completes HMAC-MD hash computation and retrieves the digest value into
+     204                 :            :  * the specified memory. After this function has been called, the HMAC-MD context cannot
+     205                 :            :  * be used again.
+     206                 :            :  * HMAC-MD context should be initialized by hmac_md_new(), and should not be finalized
+     207                 :            :  * by hmac_md_final(). Behavior with invalid HMAC-MD context is undefined.
+     208                 :            :  *
+     209                 :            :  * If hmac_md_ctx is NULL, then return false.
+     210                 :            :  * If hmac_value is NULL, then return false.
+     211                 :            :  *
+     212                 :            :  * @param[in, out]  hmac_md_ctx      Pointer to the HMAC-MD context.
+     213                 :            :  * @param[out]      hmac_value          Pointer to a buffer that receives the HMAC-MD digest
+     214                 :            :  *                                    value.
+     215                 :            :  *
+     216                 :            :  * @retval true   HMAC-MD digest computation succeeded.
+     217                 :            :  * @retval false  HMAC-MD digest computation failed.
+     218                 :            :  *
+     219                 :            :  **/
+     220                 :          0 : bool hmac_md_final(void *hmac_md_ctx, uint8_t *hmac_value)
+     221                 :            : {
+     222                 :            :     int ret;
+     223                 :            : 
+     224   [ #  #  #  # ]:          0 :     if (hmac_md_ctx == NULL || hmac_value == NULL) {
+     225                 :          0 :         return false;
+     226                 :            :     }
+     227                 :            : 
+     228                 :          0 :     ret = mbedtls_md_hmac_finish(hmac_md_ctx, hmac_value);
+     229                 :          0 :     mbedtls_md_free(hmac_md_ctx);
+     230         [ #  # ]:          0 :     if (ret != 0) {
+     231                 :          0 :         return false;
+     232                 :            :     }
+     233                 :          0 :     return true;
+     234                 :            : }
+     235                 :            : 
+     236                 :            : /**
+     237                 :            :  * Computes the HMAC-MD digest of a input data buffer.
+     238                 :            :  *
+     239                 :            :  * This function performs the HMAC-MD digest of a given data buffer, and places
+     240                 :            :  * the digest value into the specified memory.
+     241                 :            :  *
+     242                 :            :  * If this interface is not supported, then return false.
+     243                 :            :  *
+     244                 :            :  * @param[in]   md_type      message digest Type.
+     245                 :            :  * @param[in]   data        Pointer to the buffer containing the data to be digested.
+     246                 :            :  * @param[in]   data_size    size of data buffer in bytes.
+     247                 :            :  * @param[in]   key         Pointer to the user-supplied key.
+     248                 :            :  * @param[in]   key_size     key size in bytes.
+     249                 :            :  * @param[out]  hash_value   Pointer to a buffer that receives the HMAC-MD digest
+     250                 :            :  *                         value.
+     251                 :            :  *
+     252                 :            :  * @retval true   HMAC-MD digest computation succeeded.
+     253                 :            :  * @retval false  HMAC-MD digest computation failed.
+     254                 :            :  * @retval false  This interface is not supported.
+     255                 :            :  *
+     256                 :            :  **/
+     257                 :        319 : bool hmac_md_all(const mbedtls_md_type_t md_type, const void *data,
+     258                 :            :                  size_t data_size, const uint8_t *key, size_t key_size,
+     259                 :            :                  uint8_t *hmac_value)
+     260                 :            : {
+     261                 :            :     const mbedtls_md_info_t *md_info;
+     262                 :            :     int ret;
+     263                 :            : 
+     264                 :        319 :     md_info = mbedtls_md_info_from_type(md_type);
+     265         [ -  + ]:        319 :     LIBSPDM_ASSERT(md_info != NULL);
+     266                 :            : 
+     267                 :        319 :     ret = mbedtls_md_hmac(md_info, key, key_size, data, data_size,
+     268                 :            :                           hmac_value);
+     269         [ -  + ]:        319 :     if (ret != 0) {
+     270                 :          0 :         return false;
+     271                 :            :     }
+     272                 :        319 :     return true;
+     273                 :            : }
+     274                 :            : 
+     275                 :            : /**
+     276                 :            :  * Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA256 use.
+     277                 :            :  *
+     278                 :            :  * @return  Pointer to the HMAC_CTX context that has been initialized.
+     279                 :            :  *         If the allocations fails, libspdm_hmac_sha256_new() returns NULL.
+     280                 :            :  *
+     281                 :            :  **/
+     282                 :          0 : void *libspdm_hmac_sha256_new(void)
+     283                 :            : {
+     284                 :          0 :     return hmac_md_new();
+     285                 :            : }
+     286                 :            : 
+     287                 :            : /**
+     288                 :            :  * Release the specified HMAC_CTX context.
+     289                 :            :  *
+     290                 :            :  * @param[in]  hmac_sha256_ctx  Pointer to the HMAC_CTX context to be released.
+     291                 :            :  *
+     292                 :            :  **/
+     293                 :          0 : void libspdm_hmac_sha256_free(void *hmac_sha256_ctx)
+     294                 :            : {
+     295                 :          0 :     hmac_md_free(hmac_sha256_ctx);
+     296                 :          0 : }
+     297                 :            : 
+     298                 :            : /**
+     299                 :            :  * Set user-supplied key for subsequent use. It must be done before any
+     300                 :            :  * calling to libspdm_hmac_sha256_update().
+     301                 :            :  *
+     302                 :            :  * If hmac_sha256_ctx is NULL, then return false.
+     303                 :            :  *
+     304                 :            :  * @param[out]  hmac_sha256_ctx  Pointer to HMAC-SHA256 context.
+     305                 :            :  * @param[in]   key                Pointer to the user-supplied key.
+     306                 :            :  * @param[in]   key_size            key size in bytes.
+     307                 :            :  *
+     308                 :            :  * @retval true   The key is set successfully.
+     309                 :            :  * @retval false  The key is set unsuccessfully.
+     310                 :            :  *
+     311                 :            :  **/
+     312                 :          0 : bool libspdm_hmac_sha256_set_key(void *hmac_sha256_ctx, const uint8_t *key,
+     313                 :            :                                  size_t key_size)
+     314                 :            : {
+     315                 :          0 :     return hmac_md_set_key(MBEDTLS_MD_SHA256, hmac_sha256_ctx, key,
+     316                 :            :                            key_size);
+     317                 :            : }
+     318                 :            : 
+     319                 :            : /**
+     320                 :            :  * Makes a copy of an existing HMAC-SHA256 context.
+     321                 :            :  *
+     322                 :            :  * If hmac_sha256_ctx is NULL, then return false.
+     323                 :            :  * If new_hmac_sha256_ctx is NULL, then return false.
+     324                 :            :  *
+     325                 :            :  * @param[in]  hmac_sha256_ctx     Pointer to HMAC-SHA256 context being copied.
+     326                 :            :  * @param[out] new_hmac_sha256_ctx  Pointer to new HMAC-SHA256 context.
+     327                 :            :  *
+     328                 :            :  * @retval true   HMAC-SHA256 context copy succeeded.
+     329                 :            :  * @retval false  HMAC-SHA256 context copy failed.
+     330                 :            :  *
+     331                 :            :  **/
+     332                 :          0 : bool libspdm_hmac_sha256_duplicate(const void *hmac_sha256_ctx,
+     333                 :            :                                    void *new_hmac_sha256_ctx)
+     334                 :            : {
+     335                 :          0 :     return hmac_md_duplicate(MBEDTLS_MD_SHA256, hmac_sha256_ctx, new_hmac_sha256_ctx);
+     336                 :            : }
+     337                 :            : 
+     338                 :            : /**
+     339                 :            :  * Digests the input data and updates HMAC-SHA256 context.
+     340                 :            :  *
+     341                 :            :  * This function performs HMAC-SHA256 digest on a data buffer of the specified size.
+     342                 :            :  * It can be called multiple times to compute the digest of long or discontinuous data streams.
+     343                 :            :  * HMAC-SHA256 context should be initialized by libspdm_hmac_sha256_new(), and should not be finalized
+     344                 :            :  * by libspdm_hmac_sha256_final(). Behavior with invalid context is undefined.
+     345                 :            :  *
+     346                 :            :  * If hmac_sha256_ctx is NULL, then return false.
+     347                 :            :  *
+     348                 :            :  * @param[in, out]  hmac_sha256_ctx Pointer to the HMAC-SHA256 context.
+     349                 :            :  * @param[in]       data              Pointer to the buffer containing the data to be digested.
+     350                 :            :  * @param[in]       data_size          size of data buffer in bytes.
+     351                 :            :  *
+     352                 :            :  * @retval true   HMAC-SHA256 data digest succeeded.
+     353                 :            :  * @retval false  HMAC-SHA256 data digest failed.
+     354                 :            :  *
+     355                 :            :  **/
+     356                 :          0 : bool libspdm_hmac_sha256_update(void *hmac_sha256_ctx, const void *data,
+     357                 :            :                                 size_t data_size)
+     358                 :            : {
+     359                 :          0 :     return hmac_md_update(hmac_sha256_ctx, data, data_size);
+     360                 :            : }
+     361                 :            : 
+     362                 :            : /**
+     363                 :            :  * Completes computation of the HMAC-SHA256 digest value.
+     364                 :            :  *
+     365                 :            :  * This function completes HMAC-SHA256 hash computation and retrieves the digest value into
+     366                 :            :  * the specified memory. After this function has been called, the HMAC-SHA256 context cannot
+     367                 :            :  * be used again.
+     368                 :            :  * HMAC-SHA256 context should be initialized by libspdm_hmac_sha256_new(), and should not be finalized
+     369                 :            :  * by libspdm_hmac_sha256_final(). Behavior with invalid HMAC-SHA256 context is undefined.
+     370                 :            :  *
+     371                 :            :  * If hmac_sha256_ctx is NULL, then return false.
+     372                 :            :  * If hmac_value is NULL, then return false.
+     373                 :            :  *
+     374                 :            :  * @param[in, out]  hmac_sha256_ctx  Pointer to the HMAC-SHA256 context.
+     375                 :            :  * @param[out]      hmac_value          Pointer to a buffer that receives the HMAC-SHA256 digest
+     376                 :            :  *                                    value (32 bytes).
+     377                 :            :  *
+     378                 :            :  * @retval true   HMAC-SHA256 digest computation succeeded.
+     379                 :            :  * @retval false  HMAC-SHA256 digest computation failed.
+     380                 :            :  *
+     381                 :            :  **/
+     382                 :          0 : bool libspdm_hmac_sha256_final(void *hmac_sha256_ctx, uint8_t *hmac_value)
+     383                 :            : {
+     384                 :          0 :     return hmac_md_final(hmac_sha256_ctx, hmac_value);
+     385                 :            : }
+     386                 :            : 
+     387                 :            : /**
+     388                 :            :  * Computes the HMAC-SHA256 digest of a input data buffer.
+     389                 :            :  *
+     390                 :            :  * This function performs the HMAC-SHA256 digest of a given data buffer, and places
+     391                 :            :  * the digest value into the specified memory.
+     392                 :            :  *
+     393                 :            :  * If this interface is not supported, then return false.
+     394                 :            :  *
+     395                 :            :  * @param[in]   data        Pointer to the buffer containing the data to be digested.
+     396                 :            :  * @param[in]   data_size    size of data buffer in bytes.
+     397                 :            :  * @param[in]   key         Pointer to the user-supplied key.
+     398                 :            :  * @param[in]   key_size     key size in bytes.
+     399                 :            :  * @param[out]  hash_value   Pointer to a buffer that receives the HMAC-SHA256 digest
+     400                 :            :  *                         value (32 bytes).
+     401                 :            :  *
+     402                 :            :  * @retval true   HMAC-SHA256 digest computation succeeded.
+     403                 :            :  * @retval false  HMAC-SHA256 digest computation failed.
+     404                 :            :  * @retval false  This interface is not supported.
+     405                 :            :  *
+     406                 :            :  **/
+     407                 :        317 : bool libspdm_hmac_sha256_all(const void *data, size_t data_size,
+     408                 :            :                              const uint8_t *key, size_t key_size,
+     409                 :            :                              uint8_t *hmac_value)
+     410                 :            : {
+     411                 :        317 :     return hmac_md_all(MBEDTLS_MD_SHA256, data, data_size, key, key_size,
+     412                 :            :                        hmac_value);
+     413                 :            : }
+     414                 :            : 
+     415                 :            : /**
+     416                 :            :  * Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA384 use.
+     417                 :            :  *
+     418                 :            :  * @return  Pointer to the HMAC_CTX context that has been initialized.
+     419                 :            :  *         If the allocations fails, libspdm_hmac_sha384_new() returns NULL.
+     420                 :            :  *
+     421                 :            :  **/
+     422                 :          0 : void *libspdm_hmac_sha384_new(void)
+     423                 :            : {
+     424                 :          0 :     return hmac_md_new();
+     425                 :            : }
+     426                 :            : 
+     427                 :            : /**
+     428                 :            :  * Release the specified HMAC_CTX context.
+     429                 :            :  *
+     430                 :            :  * @param[in]  hmac_sha384_ctx  Pointer to the HMAC_CTX context to be released.
+     431                 :            :  *
+     432                 :            :  **/
+     433                 :          0 : void libspdm_hmac_sha384_free(void *hmac_sha384_ctx)
+     434                 :            : {
+     435                 :          0 :     hmac_md_free(hmac_sha384_ctx);
+     436                 :          0 : }
+     437                 :            : 
+     438                 :            : /**
+     439                 :            :  * Set user-supplied key for subsequent use. It must be done before any
+     440                 :            :  * calling to libspdm_hmac_sha384_update().
+     441                 :            :  *
+     442                 :            :  * If hmac_sha384_ctx is NULL, then return false.
+     443                 :            :  * If this interface is not supported, then return false.
+     444                 :            :  *
+     445                 :            :  * @param[out]  hmac_sha384_ctx  Pointer to HMAC-SHA384 context.
+     446                 :            :  * @param[in]   key                Pointer to the user-supplied key.
+     447                 :            :  * @param[in]   key_size            key size in bytes.
+     448                 :            :  *
+     449                 :            :  * @retval true   The key is set successfully.
+     450                 :            :  * @retval false  The key is set unsuccessfully.
+     451                 :            :  * @retval false  This interface is not supported.
+     452                 :            :  *
+     453                 :            :  **/
+     454                 :          0 : bool libspdm_hmac_sha384_set_key(void *hmac_sha384_ctx, const uint8_t *key,
+     455                 :            :                                  size_t key_size)
+     456                 :            : {
+     457                 :          0 :     return hmac_md_set_key(MBEDTLS_MD_SHA384, hmac_sha384_ctx, key,
+     458                 :            :                            key_size);
+     459                 :            : }
+     460                 :            : 
+     461                 :            : /**
+     462                 :            :  * Makes a copy of an existing HMAC-SHA384 context.
+     463                 :            :  *
+     464                 :            :  * If hmac_sha384_ctx is NULL, then return false.
+     465                 :            :  * If new_hmac_sha384_ctx is NULL, then return false.
+     466                 :            :  * If this interface is not supported, then return false.
+     467                 :            :  *
+     468                 :            :  * @param[in]  hmac_sha384_ctx     Pointer to HMAC-SHA384 context being copied.
+     469                 :            :  * @param[out] new_hmac_sha384_ctx  Pointer to new HMAC-SHA384 context.
+     470                 :            :  *
+     471                 :            :  * @retval true   HMAC-SHA384 context copy succeeded.
+     472                 :            :  * @retval false  HMAC-SHA384 context copy failed.
+     473                 :            :  * @retval false  This interface is not supported.
+     474                 :            :  *
+     475                 :            :  **/
+     476                 :          0 : bool libspdm_hmac_sha384_duplicate(const void *hmac_sha384_ctx,
+     477                 :            :                                    void *new_hmac_sha384_ctx)
+     478                 :            : {
+     479                 :          0 :     return hmac_md_duplicate(MBEDTLS_MD_SHA384, hmac_sha384_ctx, new_hmac_sha384_ctx);
+     480                 :            : }
+     481                 :            : 
+     482                 :            : /**
+     483                 :            :  * Digests the input data and updates HMAC-SHA384 context.
+     484                 :            :  *
+     485                 :            :  * This function performs HMAC-SHA384 digest on a data buffer of the specified size.
+     486                 :            :  * It can be called multiple times to compute the digest of long or discontinuous data streams.
+     487                 :            :  * HMAC-SHA384 context should be initialized by libspdm_hmac_sha384_new(), and should not be finalized
+     488                 :            :  * by libspdm_hmac_sha384_final(). Behavior with invalid context is undefined.
+     489                 :            :  *
+     490                 :            :  * If hmac_sha384_ctx is NULL, then return false.
+     491                 :            :  * If this interface is not supported, then return false.
+     492                 :            :  *
+     493                 :            :  * @param[in, out]  hmac_sha384_ctx Pointer to the HMAC-SHA384 context.
+     494                 :            :  * @param[in]       data              Pointer to the buffer containing the data to be digested.
+     495                 :            :  * @param[in]       data_size          size of data buffer in bytes.
+     496                 :            :  *
+     497                 :            :  * @retval true   HMAC-SHA384 data digest succeeded.
+     498                 :            :  * @retval false  HMAC-SHA384 data digest failed.
+     499                 :            :  * @retval false  This interface is not supported.
+     500                 :            :  *
+     501                 :            :  **/
+     502                 :          0 : bool libspdm_hmac_sha384_update(void *hmac_sha384_ctx, const void *data,
+     503                 :            :                                 size_t data_size)
+     504                 :            : {
+     505                 :          0 :     return hmac_md_update(hmac_sha384_ctx, data, data_size);
+     506                 :            : }
+     507                 :            : 
+     508                 :            : /**
+     509                 :            :  * Completes computation of the HMAC-SHA384 digest value.
+     510                 :            :  *
+     511                 :            :  * This function completes HMAC-SHA384 hash computation and retrieves the digest value into
+     512                 :            :  * the specified memory. After this function has been called, the HMAC-SHA384 context cannot
+     513                 :            :  * be used again.
+     514                 :            :  * HMAC-SHA384 context should be initialized by libspdm_hmac_sha384_new(), and should not be finalized
+     515                 :            :  * by libspdm_hmac_sha384_final(). Behavior with invalid HMAC-SHA384 context is undefined.
+     516                 :            :  *
+     517                 :            :  * If hmac_sha384_ctx is NULL, then return false.
+     518                 :            :  * If hmac_value is NULL, then return false.
+     519                 :            :  * If this interface is not supported, then return false.
+     520                 :            :  *
+     521                 :            :  * @param[in, out]  hmac_sha384_ctx  Pointer to the HMAC-SHA384 context.
+     522                 :            :  * @param[out]      hmac_value          Pointer to a buffer that receives the HMAC-SHA384 digest
+     523                 :            :  *                                    value (48 bytes).
+     524                 :            :  *
+     525                 :            :  * @retval true   HMAC-SHA384 digest computation succeeded.
+     526                 :            :  * @retval false  HMAC-SHA384 digest computation failed.
+     527                 :            :  * @retval false  This interface is not supported.
+     528                 :            :  *
+     529                 :            :  **/
+     530                 :          0 : bool libspdm_hmac_sha384_final(void *hmac_sha384_ctx, uint8_t *hmac_value)
+     531                 :            : {
+     532                 :          0 :     return hmac_md_final(hmac_sha384_ctx, hmac_value);
+     533                 :            : }
+     534                 :            : 
+     535                 :            : /**
+     536                 :            :  * Computes the HMAC-SHA384 digest of a input data buffer.
+     537                 :            :  *
+     538                 :            :  * This function performs the HMAC-SHA384 digest of a given data buffer, and places
+     539                 :            :  * the digest value into the specified memory.
+     540                 :            :  *
+     541                 :            :  * If this interface is not supported, then return false.
+     542                 :            :  *
+     543                 :            :  * @param[in]   data        Pointer to the buffer containing the data to be digested.
+     544                 :            :  * @param[in]   data_size    size of data buffer in bytes.
+     545                 :            :  * @param[in]   key         Pointer to the user-supplied key.
+     546                 :            :  * @param[in]   key_size     key size in bytes.
+     547                 :            :  * @param[out]  hash_value   Pointer to a buffer that receives the HMAC-SHA384 digest
+     548                 :            :  *                         value (48 bytes).
+     549                 :            :  *
+     550                 :            :  * @retval true   HMAC-SHA384 digest computation succeeded.
+     551                 :            :  * @retval false  HMAC-SHA384 digest computation failed.
+     552                 :            :  * @retval false  This interface is not supported.
+     553                 :            :  *
+     554                 :            :  **/
+     555                 :          1 : bool libspdm_hmac_sha384_all(const void *data, size_t data_size,
+     556                 :            :                              const uint8_t *key, size_t key_size,
+     557                 :            :                              uint8_t *hmac_value)
+     558                 :            : {
+     559                 :          1 :     return hmac_md_all(MBEDTLS_MD_SHA384, data, data_size, key, key_size,
+     560                 :            :                        hmac_value);
+     561                 :            : }
+     562                 :            : 
+     563                 :            : /**
+     564                 :            :  * Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA512 use.
+     565                 :            :  *
+     566                 :            :  * @return  Pointer to the HMAC_CTX context that has been initialized.
+     567                 :            :  *         If the allocations fails, libspdm_hmac_sha512_new() returns NULL.
+     568                 :            :  *
+     569                 :            :  **/
+     570                 :          0 : void *libspdm_hmac_sha512_new(void)
+     571                 :            : {
+     572                 :          0 :     return hmac_md_new();
+     573                 :            : }
+     574                 :            : 
+     575                 :            : /**
+     576                 :            :  * Release the specified HMAC_CTX context.
+     577                 :            :  *
+     578                 :            :  * @param[in]  hmac_sha512_ctx  Pointer to the HMAC_CTX context to be released.
+     579                 :            :  *
+     580                 :            :  **/
+     581                 :          0 : void libspdm_hmac_sha512_free(void *hmac_sha512_ctx)
+     582                 :            : {
+     583                 :          0 :     hmac_md_free(hmac_sha512_ctx);
+     584                 :          0 : }
+     585                 :            : 
+     586                 :            : /**
+     587                 :            :  * Set user-supplied key for subsequent use. It must be done before any
+     588                 :            :  * calling to libspdm_hmac_sha512_update().
+     589                 :            :  *
+     590                 :            :  * If hmac_sha512_ctx is NULL, then return false.
+     591                 :            :  * If this interface is not supported, then return false.
+     592                 :            :  *
+     593                 :            :  * @param[out]  hmac_sha512_ctx  Pointer to HMAC-SHA512 context.
+     594                 :            :  * @param[in]   key                Pointer to the user-supplied key.
+     595                 :            :  * @param[in]   key_size            key size in bytes.
+     596                 :            :  *
+     597                 :            :  * @retval true   The key is set successfully.
+     598                 :            :  * @retval false  The key is set unsuccessfully.
+     599                 :            :  * @retval false  This interface is not supported.
+     600                 :            :  *
+     601                 :            :  **/
+     602                 :          0 : bool libspdm_hmac_sha512_set_key(void *hmac_sha512_ctx, const uint8_t *key,
+     603                 :            :                                  size_t key_size)
+     604                 :            : {
+     605                 :          0 :     return hmac_md_set_key(MBEDTLS_MD_SHA512, hmac_sha512_ctx, key,
+     606                 :            :                            key_size);
+     607                 :            : }
+     608                 :            : 
+     609                 :            : /**
+     610                 :            :  * Makes a copy of an existing HMAC-SHA512 context.
+     611                 :            :  *
+     612                 :            :  * If hmac_sha512_ctx is NULL, then return false.
+     613                 :            :  * If new_hmac_sha512_ctx is NULL, then return false.
+     614                 :            :  * If this interface is not supported, then return false.
+     615                 :            :  *
+     616                 :            :  * @param[in]  hmac_sha512_ctx     Pointer to HMAC-SHA512 context being copied.
+     617                 :            :  * @param[out] new_hmac_sha512_ctx  Pointer to new HMAC-SHA512 context.
+     618                 :            :  *
+     619                 :            :  * @retval true   HMAC-SHA512 context copy succeeded.
+     620                 :            :  * @retval false  HMAC-SHA512 context copy failed.
+     621                 :            :  * @retval false  This interface is not supported.
+     622                 :            :  *
+     623                 :            :  **/
+     624                 :          0 : bool libspdm_hmac_sha512_duplicate(const void *hmac_sha512_ctx,
+     625                 :            :                                    void *new_hmac_sha512_ctx)
+     626                 :            : {
+     627                 :          0 :     return hmac_md_duplicate(MBEDTLS_MD_SHA512, hmac_sha512_ctx, new_hmac_sha512_ctx);
+     628                 :            : }
+     629                 :            : 
+     630                 :            : /**
+     631                 :            :  * Digests the input data and updates HMAC-SHA512 context.
+     632                 :            :  *
+     633                 :            :  * This function performs HMAC-SHA512 digest on a data buffer of the specified size.
+     634                 :            :  * It can be called multiple times to compute the digest of long or discontinuous data streams.
+     635                 :            :  * HMAC-SHA512 context should be initialized by libspdm_hmac_sha512_new(), and should not be finalized
+     636                 :            :  * by libspdm_hmac_sha512_final(). Behavior with invalid context is undefined.
+     637                 :            :  *
+     638                 :            :  * If hmac_sha512_ctx is NULL, then return false.
+     639                 :            :  * If this interface is not supported, then return false.
+     640                 :            :  *
+     641                 :            :  * @param[in, out]  hmac_sha512_ctx Pointer to the HMAC-SHA512 context.
+     642                 :            :  * @param[in]       data              Pointer to the buffer containing the data to be digested.
+     643                 :            :  * @param[in]       data_size          size of data buffer in bytes.
+     644                 :            :  *
+     645                 :            :  * @retval true   HMAC-SHA512 data digest succeeded.
+     646                 :            :  * @retval false  HMAC-SHA512 data digest failed.
+     647                 :            :  * @retval false  This interface is not supported.
+     648                 :            :  *
+     649                 :            :  **/
+     650                 :          0 : bool libspdm_hmac_sha512_update(void *hmac_sha512_ctx, const void *data,
+     651                 :            :                                 size_t data_size)
+     652                 :            : {
+     653                 :          0 :     return hmac_md_update(hmac_sha512_ctx, data, data_size);
+     654                 :            : }
+     655                 :            : 
+     656                 :            : /**
+     657                 :            :  * Completes computation of the HMAC-SHA512 digest value.
+     658                 :            :  *
+     659                 :            :  * This function completes HMAC-SHA512 hash computation and retrieves the digest value into
+     660                 :            :  * the specified memory. After this function has been called, the HMAC-SHA512 context cannot
+     661                 :            :  * be used again.
+     662                 :            :  * HMAC-SHA512 context should be initialized by libspdm_hmac_sha512_new(), and should not be finalized
+     663                 :            :  * by libspdm_hmac_sha512_final(). Behavior with invalid HMAC-SHA512 context is undefined.
+     664                 :            :  *
+     665                 :            :  * If hmac_sha512_ctx is NULL, then return false.
+     666                 :            :  * If hmac_value is NULL, then return false.
+     667                 :            :  * If this interface is not supported, then return false.
+     668                 :            :  *
+     669                 :            :  * @param[in, out]  hmac_sha512_ctx  Pointer to the HMAC-SHA512 context.
+     670                 :            :  * @param[out]      hmac_value          Pointer to a buffer that receives the HMAC-SHA512 digest
+     671                 :            :  *                                    value (64 bytes).
+     672                 :            :  *
+     673                 :            :  * @retval true   HMAC-SHA512 digest computation succeeded.
+     674                 :            :  * @retval false  HMAC-SHA512 digest computation failed.
+     675                 :            :  * @retval false  This interface is not supported.
+     676                 :            :  *
+     677                 :            :  **/
+     678                 :          0 : bool libspdm_hmac_sha512_final(void *hmac_sha512_ctx, uint8_t *hmac_value)
+     679                 :            : {
+     680                 :          0 :     return hmac_md_final(hmac_sha512_ctx, hmac_value);
+     681                 :            : }
+     682                 :            : 
+     683                 :            : /**
+     684                 :            :  * Computes the HMAC-SHA512 digest of a input data buffer.
+     685                 :            :  *
+     686                 :            :  * This function performs the HMAC-SHA512 digest of a given data buffer, and places
+     687                 :            :  * the digest value into the specified memory.
+     688                 :            :  *
+     689                 :            :  * If this interface is not supported, then return false.
+     690                 :            :  *
+     691                 :            :  * @param[in]   data        Pointer to the buffer containing the data to be digested.
+     692                 :            :  * @param[in]   data_size    size of data buffer in bytes.
+     693                 :            :  * @param[in]   key         Pointer to the user-supplied key.
+     694                 :            :  * @param[in]   key_size     key size in bytes.
+     695                 :            :  * @param[out]  hash_value   Pointer to a buffer that receives the HMAC-SHA512 digest
+     696                 :            :  *                         value (64 bytes).
+     697                 :            :  *
+     698                 :            :  * @retval true   HMAC-SHA512 digest computation succeeded.
+     699                 :            :  * @retval false  HMAC-SHA512 digest computation failed.
+     700                 :            :  * @retval false  This interface is not supported.
+     701                 :            :  *
+     702                 :            :  **/
+     703                 :          1 : bool libspdm_hmac_sha512_all(const void *data, size_t data_size,
+     704                 :            :                              const uint8_t *key, size_t key_size,
+     705                 :            :                              uint8_t *hmac_value)
+     706                 :            : {
+     707                 :          1 :     return hmac_md_all(MBEDTLS_MD_SHA512, data, data_size, key, key_size,
+     708                 :            :                        hmac_value);
+     709                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/hmac/index-sort-b.html b/coverage_log/os_stub/cryptlib_mbedtls/hmac/index-sort-b.html new file mode 100644 index 00000000000..cecd705be95 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/hmac/index-sort-b.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/hmac + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/hmacHitTotalCoverage
Test:coverage.infoLines:121239.8 %
Date:2024-09-22 08:21:07Functions:42913.8 %
Branches:2464.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
hmac_sha.c +
9.8%9.8%
+
9.8 %12 / 12313.8 %4 / 294.3 %2 / 46
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/hmac/index-sort-f.html b/coverage_log/os_stub/cryptlib_mbedtls/hmac/index-sort-f.html new file mode 100644 index 00000000000..c14dd304a20 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/hmac/index-sort-f.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/hmac + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/hmacHitTotalCoverage
Test:coverage.infoLines:121239.8 %
Date:2024-09-22 08:21:07Functions:42913.8 %
Branches:2464.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
hmac_sha.c +
9.8%9.8%
+
9.8 %12 / 12313.8 %4 / 294.3 %2 / 46
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/hmac/index-sort-l.html b/coverage_log/os_stub/cryptlib_mbedtls/hmac/index-sort-l.html new file mode 100644 index 00000000000..197b3168f1b --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/hmac/index-sort-l.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/hmac + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/hmacHitTotalCoverage
Test:coverage.infoLines:121239.8 %
Date:2024-09-22 08:21:07Functions:42913.8 %
Branches:2464.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
hmac_sha.c +
9.8%9.8%
+
9.8 %12 / 12313.8 %4 / 294.3 %2 / 46
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/hmac/index.html b/coverage_log/os_stub/cryptlib_mbedtls/hmac/index.html new file mode 100644 index 00000000000..a14e9f8dccf --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/hmac/index.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/hmac + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/hmacHitTotalCoverage
Test:coverage.infoLines:121239.8 %
Date:2024-09-22 08:21:07Functions:42913.8 %
Branches:2464.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
hmac_sha.c +
9.8%9.8%
+
9.8 %12 / 12313.8 %4 / 294.3 %2 / 46
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/kdf/hkdf_sha.c.func-sort-c.html b/coverage_log/os_stub/cryptlib_mbedtls/kdf/hkdf_sha.c.func-sort-c.html new file mode 100644 index 00000000000..236873d9671 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/kdf/hkdf_sha.c.func-sort-c.html @@ -0,0 +1,129 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/kdf/hkdf_sha.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/kdf - hkdf_sha.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:338140.7 %
Date:2024-09-22 08:21:07Functions:41233.3 %
Branches:206431.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
hkdf_md_extract_and_expand0
libspdm_hkdf_sha256_extract_and_expand0
libspdm_hkdf_sha384_expand0
libspdm_hkdf_sha384_extract0
libspdm_hkdf_sha384_extract_and_expand0
libspdm_hkdf_sha512_expand0
libspdm_hkdf_sha512_extract0
libspdm_hkdf_sha512_extract_and_expand0
hkdf_md_extract189
libspdm_hkdf_sha256_extract189
hkdf_md_expand1227
libspdm_hkdf_sha256_expand1227
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/kdf/hkdf_sha.c.func.html b/coverage_log/os_stub/cryptlib_mbedtls/kdf/hkdf_sha.c.func.html new file mode 100644 index 00000000000..9745eba5294 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/kdf/hkdf_sha.c.func.html @@ -0,0 +1,129 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/kdf/hkdf_sha.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/kdf - hkdf_sha.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:338140.7 %
Date:2024-09-22 08:21:07Functions:41233.3 %
Branches:206431.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
hkdf_md_expand1227
hkdf_md_extract189
hkdf_md_extract_and_expand0
libspdm_hkdf_sha256_expand1227
libspdm_hkdf_sha256_extract189
libspdm_hkdf_sha256_extract_and_expand0
libspdm_hkdf_sha384_expand0
libspdm_hkdf_sha384_extract0
libspdm_hkdf_sha384_extract_and_expand0
libspdm_hkdf_sha512_expand0
libspdm_hkdf_sha512_extract0
libspdm_hkdf_sha512_extract_and_expand0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/kdf/hkdf_sha.c.gcov.html b/coverage_log/os_stub/cryptlib_mbedtls/kdf/hkdf_sha.c.gcov.html new file mode 100644 index 00000000000..ddbd33fcb42 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/kdf/hkdf_sha.c.gcov.html @@ -0,0 +1,477 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/kdf/hkdf_sha.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/kdf - hkdf_sha.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:338140.7 %
Date:2024-09-22 08:21:07Functions:41233.3 %
Branches:206431.2 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 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                 :            : /** @file
+       8                 :            :  * HMAC-SHA256/384/512 KDF Wrapper Implementation.
+       9                 :            :  *
+      10                 :            :  * RFC 5869: HMAC-based Extract-and-Expand key Derivation Function (HKDF)
+      11                 :            :  **/
+      12                 :            : 
+      13                 :            : #include "internal_crypt_lib.h"
+      14                 :            : #include <mbedtls/hkdf.h>
+      15                 :            : 
+      16                 :            : /**
+      17                 :            :  * Derive HMAC-based Extract-and-Expand key Derivation Function (HKDF).
+      18                 :            :  *
+      19                 :            :  * @param[in]   md_type           message digest Type.
+      20                 :            :  * @param[in]   key              Pointer to the user-supplied key.
+      21                 :            :  * @param[in]   key_size          key size in bytes.
+      22                 :            :  * @param[in]   salt             Pointer to the salt(non-secret) value.
+      23                 :            :  * @param[in]   salt_size         salt size in bytes.
+      24                 :            :  * @param[in]   info             Pointer to the application specific info.
+      25                 :            :  * @param[in]   info_size         info size in bytes.
+      26                 :            :  * @param[out]  out              Pointer to buffer to receive hkdf value.
+      27                 :            :  * @param[in]   out_size          size of hkdf bytes to generate.
+      28                 :            :  *
+      29                 :            :  * @retval true   Hkdf generated successfully.
+      30                 :            :  * @retval false  Hkdf generation failed.
+      31                 :            :  *
+      32                 :            :  **/
+      33                 :          0 : bool hkdf_md_extract_and_expand(const mbedtls_md_type_t md_type,
+      34                 :            :                                 const uint8_t *key, size_t key_size,
+      35                 :            :                                 const uint8_t *salt, size_t salt_size,
+      36                 :            :                                 const uint8_t *info, size_t info_size,
+      37                 :            :                                 uint8_t *out, size_t out_size)
+      38                 :            : {
+      39                 :            :     const mbedtls_md_info_t *md;
+      40                 :            :     int ret;
+      41                 :            : 
+      42   [ #  #  #  #  :          0 :     if (key == NULL || salt == NULL || info == NULL || out == NULL ||
+          #  #  #  #  #  
+                      # ]
+      43   [ #  #  #  #  :          0 :         key_size > INT_MAX || salt_size > INT_MAX || info_size > INT_MAX ||
+                   #  # ]
+      44                 :            :         out_size > INT_MAX) {
+      45                 :          0 :         return false;
+      46                 :            :     }
+      47                 :            : 
+      48                 :          0 :     md = mbedtls_md_info_from_type(md_type);
+      49         [ #  # ]:          0 :     LIBSPDM_ASSERT(md != NULL);
+      50                 :            : 
+      51                 :          0 :     ret = mbedtls_hkdf(md, salt, (uint32_t)salt_size, key, (uint32_t)key_size,
+      52                 :          0 :                        info, (uint32_t)info_size, out, (uint32_t)out_size);
+      53         [ #  # ]:          0 :     if (ret != 0) {
+      54                 :          0 :         return false;
+      55                 :            :     }
+      56                 :            : 
+      57                 :          0 :     return true;
+      58                 :            : }
+      59                 :            : 
+      60                 :            : /**
+      61                 :            :  * Derive HMAC-based Extract key Derivation Function (HKDF).
+      62                 :            :  *
+      63                 :            :  * @param[in]   md_type           message digest Type.
+      64                 :            :  * @param[in]   key              Pointer to the user-supplied key.
+      65                 :            :  * @param[in]   key_size          key size in bytes.
+      66                 :            :  * @param[in]   salt             Pointer to the salt(non-secret) value.
+      67                 :            :  * @param[in]   salt_size         salt size in bytes.
+      68                 :            :  * @param[out]  prk_out           Pointer to buffer to receive hkdf value.
+      69                 :            :  * @param[in]   prk_out_size       size of hkdf bytes to generate.
+      70                 :            :  *
+      71                 :            :  * @retval true   Hkdf generated successfully.
+      72                 :            :  * @retval false  Hkdf generation failed.
+      73                 :            :  *
+      74                 :            :  **/
+      75                 :        189 : bool hkdf_md_extract(const mbedtls_md_type_t md_type, const uint8_t *key,
+      76                 :            :                      size_t key_size, const uint8_t *salt,
+      77                 :            :                      size_t salt_size, uint8_t *prk_out,
+      78                 :            :                      size_t prk_out_size)
+      79                 :            : {
+      80                 :            :     const mbedtls_md_info_t *md;
+      81                 :            :     int ret;
+      82                 :            :     size_t md_size;
+      83                 :            : 
+      84   [ +  -  +  -  :        189 :     if (key == NULL || salt == NULL || prk_out == NULL ||
+             +  -  +  - ]
+      85   [ +  -  -  + ]:        189 :         key_size > INT_MAX || salt_size > INT_MAX ||
+      86                 :            :         prk_out_size > INT_MAX) {
+      87                 :          0 :         return false;
+      88                 :            :     }
+      89                 :            : 
+      90                 :        189 :     md_size = 0;
+      91   [ +  -  -  - ]:        189 :     switch (md_type) {
+      92                 :        189 :     case MBEDTLS_MD_SHA256:
+      93                 :        189 :         md_size = LIBSPDM_SHA256_DIGEST_SIZE;
+      94                 :        189 :         break;
+      95                 :          0 :     case MBEDTLS_MD_SHA384:
+      96                 :          0 :         md_size = LIBSPDM_SHA384_DIGEST_SIZE;
+      97                 :          0 :         break;
+      98                 :          0 :     case MBEDTLS_MD_SHA512:
+      99                 :          0 :         md_size = LIBSPDM_SHA512_DIGEST_SIZE;
+     100                 :          0 :         break;
+     101                 :          0 :     default:
+     102                 :          0 :         return false;
+     103                 :            :     }
+     104         [ -  + ]:        189 :     if (prk_out_size != md_size) {
+     105                 :          0 :         return false;
+     106                 :            :     }
+     107                 :            : 
+     108                 :        189 :     md = mbedtls_md_info_from_type(md_type);
+     109         [ -  + ]:        189 :     LIBSPDM_ASSERT(md != NULL);
+     110                 :            : 
+     111                 :        189 :     ret = mbedtls_hkdf_extract(md, salt, (uint32_t)salt_size, key,
+     112                 :        189 :                                (uint32_t)key_size, prk_out);
+     113         [ -  + ]:        189 :     if (ret != 0) {
+     114                 :          0 :         return false;
+     115                 :            :     }
+     116                 :            : 
+     117                 :        189 :     return true;
+     118                 :            : }
+     119                 :            : 
+     120                 :            : /**
+     121                 :            :  * Derive HMAC-based Expand key Derivation Function (HKDF).
+     122                 :            :  *
+     123                 :            :  * @param[in]   md_type           message digest Type.
+     124                 :            :  * @param[in]   prk              Pointer to the user-supplied key.
+     125                 :            :  * @param[in]   prk_size          key size in bytes.
+     126                 :            :  * @param[in]   info             Pointer to the application specific info.
+     127                 :            :  * @param[in]   info_size         info size in bytes.
+     128                 :            :  * @param[out]  out              Pointer to buffer to receive hkdf value.
+     129                 :            :  * @param[in]   out_size          size of hkdf bytes to generate.
+     130                 :            :  *
+     131                 :            :  * @retval true   Hkdf generated successfully.
+     132                 :            :  * @retval false  Hkdf generation failed.
+     133                 :            :  *
+     134                 :            :  **/
+     135                 :       1227 : bool hkdf_md_expand(const mbedtls_md_type_t md_type, const uint8_t *prk,
+     136                 :            :                     size_t prk_size, const uint8_t *info,
+     137                 :            :                     size_t info_size, uint8_t *out, size_t out_size)
+     138                 :            : {
+     139                 :            :     const mbedtls_md_info_t *md;
+     140                 :            :     int ret;
+     141                 :            :     size_t md_size;
+     142                 :            : 
+     143   [ +  -  +  -  :       1227 :     if (prk == NULL || info == NULL || out == NULL || prk_size > INT_MAX ||
+          +  -  +  -  +  
+                      - ]
+     144         [ -  + ]:       1227 :         info_size > INT_MAX || out_size > INT_MAX) {
+     145                 :          0 :         return false;
+     146                 :            :     }
+     147                 :            : 
+     148   [ +  -  -  - ]:       1227 :     switch (md_type) {
+     149                 :       1227 :     case MBEDTLS_MD_SHA256:
+     150                 :       1227 :         md_size = LIBSPDM_SHA256_DIGEST_SIZE;
+     151                 :       1227 :         break;
+     152                 :          0 :     case MBEDTLS_MD_SHA384:
+     153                 :          0 :         md_size = LIBSPDM_SHA384_DIGEST_SIZE;
+     154                 :          0 :         break;
+     155                 :          0 :     case MBEDTLS_MD_SHA512:
+     156                 :          0 :         md_size = LIBSPDM_SHA512_DIGEST_SIZE;
+     157                 :          0 :         break;
+     158                 :          0 :     default:
+     159                 :          0 :         LIBSPDM_ASSERT(false);
+     160                 :          0 :         return false;
+     161                 :            :     }
+     162         [ -  + ]:       1227 :     if (prk_size != md_size) {
+     163                 :          0 :         return false;
+     164                 :            :     }
+     165                 :            : 
+     166                 :       1227 :     md = mbedtls_md_info_from_type(md_type);
+     167         [ -  + ]:       1227 :     LIBSPDM_ASSERT(md != NULL);
+     168                 :            : 
+     169                 :       1227 :     ret = mbedtls_hkdf_expand(md, prk, (uint32_t)prk_size, info,
+     170                 :       1227 :                               (uint32_t)info_size, out, (uint32_t)out_size);
+     171         [ -  + ]:       1227 :     if (ret != 0) {
+     172                 :          0 :         return false;
+     173                 :            :     }
+     174                 :            : 
+     175                 :       1227 :     return true;
+     176                 :            : }
+     177                 :            : 
+     178                 :            : /**
+     179                 :            :  * Derive SHA256 HMAC-based Extract-and-Expand key Derivation Function (HKDF).
+     180                 :            :  *
+     181                 :            :  * @param[in]   key              Pointer to the user-supplied key.
+     182                 :            :  * @param[in]   key_size          key size in bytes.
+     183                 :            :  * @param[in]   salt             Pointer to the salt(non-secret) value.
+     184                 :            :  * @param[in]   salt_size         salt size in bytes.
+     185                 :            :  * @param[in]   info             Pointer to the application specific info.
+     186                 :            :  * @param[in]   info_size         info size in bytes.
+     187                 :            :  * @param[out]  out              Pointer to buffer to receive hkdf value.
+     188                 :            :  * @param[in]   out_size          size of hkdf bytes to generate.
+     189                 :            :  *
+     190                 :            :  * @retval true   Hkdf generated successfully.
+     191                 :            :  * @retval false  Hkdf generation failed.
+     192                 :            :  *
+     193                 :            :  **/
+     194                 :          0 : bool libspdm_hkdf_sha256_extract_and_expand(const uint8_t *key, size_t key_size,
+     195                 :            :                                             const uint8_t *salt, size_t salt_size,
+     196                 :            :                                             const uint8_t *info, size_t info_size,
+     197                 :            :                                             uint8_t *out, size_t out_size)
+     198                 :            : {
+     199                 :          0 :     return hkdf_md_extract_and_expand(MBEDTLS_MD_SHA256, key, key_size,
+     200                 :            :                                       salt, salt_size, info, info_size, out,
+     201                 :            :                                       out_size);
+     202                 :            : }
+     203                 :            : 
+     204                 :            : /**
+     205                 :            :  * Derive SHA256 HMAC-based Extract key Derivation Function (HKDF).
+     206                 :            :  *
+     207                 :            :  * @param[in]   key              Pointer to the user-supplied key.
+     208                 :            :  * @param[in]   key_size          key size in bytes.
+     209                 :            :  * @param[in]   salt             Pointer to the salt(non-secret) value.
+     210                 :            :  * @param[in]   salt_size         salt size in bytes.
+     211                 :            :  * @param[out]  prk_out           Pointer to buffer to receive hkdf value.
+     212                 :            :  * @param[in]   prk_out_size       size of hkdf bytes to generate.
+     213                 :            :  *
+     214                 :            :  * @retval true   Hkdf generated successfully.
+     215                 :            :  * @retval false  Hkdf generation failed.
+     216                 :            :  *
+     217                 :            :  **/
+     218                 :        189 : bool libspdm_hkdf_sha256_extract(const uint8_t *key, size_t key_size,
+     219                 :            :                                  const uint8_t *salt, size_t salt_size,
+     220                 :            :                                  uint8_t *prk_out, size_t prk_out_size)
+     221                 :            : {
+     222                 :        189 :     return hkdf_md_extract(MBEDTLS_MD_SHA256, key, key_size, salt,
+     223                 :            :                            salt_size, prk_out, prk_out_size);
+     224                 :            : }
+     225                 :            : 
+     226                 :            : /**
+     227                 :            :  * Derive SHA256 HMAC-based Expand key Derivation Function (HKDF).
+     228                 :            :  *
+     229                 :            :  * @param[in]   prk              Pointer to the user-supplied key.
+     230                 :            :  * @param[in]   prk_size          key size in bytes.
+     231                 :            :  * @param[in]   info             Pointer to the application specific info.
+     232                 :            :  * @param[in]   info_size         info size in bytes.
+     233                 :            :  * @param[out]  out              Pointer to buffer to receive hkdf value.
+     234                 :            :  * @param[in]   out_size          size of hkdf bytes to generate.
+     235                 :            :  *
+     236                 :            :  * @retval true   Hkdf generated successfully.
+     237                 :            :  * @retval false  Hkdf generation failed.
+     238                 :            :  *
+     239                 :            :  **/
+     240                 :       1227 : bool libspdm_hkdf_sha256_expand(const uint8_t *prk, size_t prk_size,
+     241                 :            :                                 const uint8_t *info, size_t info_size,
+     242                 :            :                                 uint8_t *out, size_t out_size)
+     243                 :            : {
+     244                 :       1227 :     return hkdf_md_expand(MBEDTLS_MD_SHA256, prk, prk_size, info, info_size,
+     245                 :            :                           out, out_size);
+     246                 :            : }
+     247                 :            : 
+     248                 :            : /**
+     249                 :            :  * Derive SHA384 HMAC-based Extract-and-Expand key Derivation Function (HKDF).
+     250                 :            :  *
+     251                 :            :  * @param[in]   key              Pointer to the user-supplied key.
+     252                 :            :  * @param[in]   key_size          key size in bytes.
+     253                 :            :  * @param[in]   salt             Pointer to the salt(non-secret) value.
+     254                 :            :  * @param[in]   salt_size         salt size in bytes.
+     255                 :            :  * @param[in]   info             Pointer to the application specific info.
+     256                 :            :  * @param[in]   info_size         info size in bytes.
+     257                 :            :  * @param[out]  out              Pointer to buffer to receive hkdf value.
+     258                 :            :  * @param[in]   out_size          size of hkdf bytes to generate.
+     259                 :            :  *
+     260                 :            :  * @retval true   Hkdf generated successfully.
+     261                 :            :  * @retval false  Hkdf generation failed.
+     262                 :            :  *
+     263                 :            :  **/
+     264                 :          0 : bool libspdm_hkdf_sha384_extract_and_expand(const uint8_t *key, size_t key_size,
+     265                 :            :                                             const uint8_t *salt, size_t salt_size,
+     266                 :            :                                             const uint8_t *info, size_t info_size,
+     267                 :            :                                             uint8_t *out, size_t out_size)
+     268                 :            : {
+     269                 :          0 :     return hkdf_md_extract_and_expand(MBEDTLS_MD_SHA384, key, key_size,
+     270                 :            :                                       salt, salt_size, info, info_size, out,
+     271                 :            :                                       out_size);
+     272                 :            : }
+     273                 :            : 
+     274                 :            : /**
+     275                 :            :  * Derive SHA384 HMAC-based Extract key Derivation Function (HKDF).
+     276                 :            :  *
+     277                 :            :  * @param[in]   key              Pointer to the user-supplied key.
+     278                 :            :  * @param[in]   key_size          key size in bytes.
+     279                 :            :  * @param[in]   salt             Pointer to the salt(non-secret) value.
+     280                 :            :  * @param[in]   salt_size         salt size in bytes.
+     281                 :            :  * @param[out]  prk_out           Pointer to buffer to receive hkdf value.
+     282                 :            :  * @param[in]   prk_out_size       size of hkdf bytes to generate.
+     283                 :            :  *
+     284                 :            :  * @retval true   Hkdf generated successfully.
+     285                 :            :  * @retval false  Hkdf generation failed.
+     286                 :            :  *
+     287                 :            :  **/
+     288                 :          0 : bool libspdm_hkdf_sha384_extract(const uint8_t *key, size_t key_size,
+     289                 :            :                                  const uint8_t *salt, size_t salt_size,
+     290                 :            :                                  uint8_t *prk_out, size_t prk_out_size)
+     291                 :            : {
+     292                 :          0 :     return hkdf_md_extract(MBEDTLS_MD_SHA384, key, key_size, salt,
+     293                 :            :                            salt_size, prk_out, prk_out_size);
+     294                 :            : }
+     295                 :            : 
+     296                 :            : /**
+     297                 :            :  * Derive SHA384 HMAC-based Expand key Derivation Function (HKDF).
+     298                 :            :  *
+     299                 :            :  * @param[in]   prk              Pointer to the user-supplied key.
+     300                 :            :  * @param[in]   prk_size          key size in bytes.
+     301                 :            :  * @param[in]   info             Pointer to the application specific info.
+     302                 :            :  * @param[in]   info_size         info size in bytes.
+     303                 :            :  * @param[out]  out              Pointer to buffer to receive hkdf value.
+     304                 :            :  * @param[in]   out_size          size of hkdf bytes to generate.
+     305                 :            :  *
+     306                 :            :  * @retval true   Hkdf generated successfully.
+     307                 :            :  * @retval false  Hkdf generation failed.
+     308                 :            :  *
+     309                 :            :  **/
+     310                 :          0 : bool libspdm_hkdf_sha384_expand(const uint8_t *prk, size_t prk_size,
+     311                 :            :                                 const uint8_t *info, size_t info_size,
+     312                 :            :                                 uint8_t *out, size_t out_size)
+     313                 :            : {
+     314                 :          0 :     return hkdf_md_expand(MBEDTLS_MD_SHA384, prk, prk_size, info, info_size,
+     315                 :            :                           out, out_size);
+     316                 :            : }
+     317                 :            : 
+     318                 :            : /**
+     319                 :            :  * Derive SHA512 HMAC-based Extract-and-Expand key Derivation Function (HKDF).
+     320                 :            :  *
+     321                 :            :  * @param[in]   key              Pointer to the user-supplied key.
+     322                 :            :  * @param[in]   key_size          key size in bytes.
+     323                 :            :  * @param[in]   salt             Pointer to the salt(non-secret) value.
+     324                 :            :  * @param[in]   salt_size         salt size in bytes.
+     325                 :            :  * @param[in]   info             Pointer to the application specific info.
+     326                 :            :  * @param[in]   info_size         info size in bytes.
+     327                 :            :  * @param[out]  out              Pointer to buffer to receive hkdf value.
+     328                 :            :  * @param[in]   out_size          size of hkdf bytes to generate.
+     329                 :            :  *
+     330                 :            :  * @retval true   Hkdf generated successfully.
+     331                 :            :  * @retval false  Hkdf generation failed.
+     332                 :            :  *
+     333                 :            :  **/
+     334                 :          0 : bool libspdm_hkdf_sha512_extract_and_expand(const uint8_t *key, size_t key_size,
+     335                 :            :                                             const uint8_t *salt, size_t salt_size,
+     336                 :            :                                             const uint8_t *info, size_t info_size,
+     337                 :            :                                             uint8_t *out, size_t out_size)
+     338                 :            : {
+     339                 :          0 :     return hkdf_md_extract_and_expand(MBEDTLS_MD_SHA512, key, key_size,
+     340                 :            :                                       salt, salt_size, info, info_size, out,
+     341                 :            :                                       out_size);
+     342                 :            : }
+     343                 :            : 
+     344                 :            : /**
+     345                 :            :  * Derive SHA512 HMAC-based Extract key Derivation Function (HKDF).
+     346                 :            :  *
+     347                 :            :  * @param[in]   key              Pointer to the user-supplied key.
+     348                 :            :  * @param[in]   key_size          key size in bytes.
+     349                 :            :  * @param[in]   salt             Pointer to the salt(non-secret) value.
+     350                 :            :  * @param[in]   salt_size         salt size in bytes.
+     351                 :            :  * @param[out]  prk_out           Pointer to buffer to receive hkdf value.
+     352                 :            :  * @param[in]   prk_out_size       size of hkdf bytes to generate.
+     353                 :            :  *
+     354                 :            :  * @retval true   Hkdf generated successfully.
+     355                 :            :  * @retval false  Hkdf generation failed.
+     356                 :            :  *
+     357                 :            :  **/
+     358                 :          0 : bool libspdm_hkdf_sha512_extract(const uint8_t *key, size_t key_size,
+     359                 :            :                                  const uint8_t *salt, size_t salt_size,
+     360                 :            :                                  uint8_t *prk_out, size_t prk_out_size)
+     361                 :            : {
+     362                 :          0 :     return hkdf_md_extract(MBEDTLS_MD_SHA512, key, key_size, salt,
+     363                 :            :                            salt_size, prk_out, prk_out_size);
+     364                 :            : }
+     365                 :            : 
+     366                 :            : /**
+     367                 :            :  * Derive SHA512 HMAC-based Expand key Derivation Function (HKDF).
+     368                 :            :  *
+     369                 :            :  * @param[in]   prk              Pointer to the user-supplied key.
+     370                 :            :  * @param[in]   prk_size          key size in bytes.
+     371                 :            :  * @param[in]   info             Pointer to the application specific info.
+     372                 :            :  * @param[in]   info_size         info size in bytes.
+     373                 :            :  * @param[out]  out              Pointer to buffer to receive hkdf value.
+     374                 :            :  * @param[in]   out_size          size of hkdf bytes to generate.
+     375                 :            :  *
+     376                 :            :  * @retval true   Hkdf generated successfully.
+     377                 :            :  * @retval false  Hkdf generation failed.
+     378                 :            :  *
+     379                 :            :  **/
+     380                 :          0 : bool libspdm_hkdf_sha512_expand(const uint8_t *prk, size_t prk_size,
+     381                 :            :                                 const uint8_t *info, size_t info_size,
+     382                 :            :                                 uint8_t *out, size_t out_size)
+     383                 :            : {
+     384                 :          0 :     return hkdf_md_expand(MBEDTLS_MD_SHA512, prk, prk_size, info, info_size,
+     385                 :            :                           out, out_size);
+     386                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/kdf/index-sort-b.html b/coverage_log/os_stub/cryptlib_mbedtls/kdf/index-sort-b.html new file mode 100644 index 00000000000..835147230f8 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/kdf/index-sort-b.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/kdf + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/kdfHitTotalCoverage
Test:coverage.infoLines:338140.7 %
Date:2024-09-22 08:21:07Functions:41233.3 %
Branches:206431.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
hkdf_sha.c +
40.7%40.7%
+
40.7 %33 / 8133.3 %4 / 1231.2 %20 / 64
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/kdf/index-sort-f.html b/coverage_log/os_stub/cryptlib_mbedtls/kdf/index-sort-f.html new file mode 100644 index 00000000000..b0c7cd0ac02 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/kdf/index-sort-f.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/kdf + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/kdfHitTotalCoverage
Test:coverage.infoLines:338140.7 %
Date:2024-09-22 08:21:07Functions:41233.3 %
Branches:206431.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
hkdf_sha.c +
40.7%40.7%
+
40.7 %33 / 8133.3 %4 / 1231.2 %20 / 64
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/kdf/index-sort-l.html b/coverage_log/os_stub/cryptlib_mbedtls/kdf/index-sort-l.html new file mode 100644 index 00000000000..aedde5591b4 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/kdf/index-sort-l.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/kdf + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/kdfHitTotalCoverage
Test:coverage.infoLines:338140.7 %
Date:2024-09-22 08:21:07Functions:41233.3 %
Branches:206431.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
hkdf_sha.c +
40.7%40.7%
+
40.7 %33 / 8133.3 %4 / 1231.2 %20 / 64
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/kdf/index.html b/coverage_log/os_stub/cryptlib_mbedtls/kdf/index.html new file mode 100644 index 00000000000..6d0a093e1d7 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/kdf/index.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/kdf + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/kdfHitTotalCoverage
Test:coverage.infoLines:338140.7 %
Date:2024-09-22 08:21:07Functions:41233.3 %
Branches:206431.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
hkdf_sha.c +
40.7%40.7%
+
40.7 %33 / 8133.3 %4 / 1231.2 %20 / 64
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/pem/index-sort-b.html b/coverage_log/os_stub/cryptlib_mbedtls/pem/index-sort-b.html new file mode 100644 index 00000000000..e31614d1eb8 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/pem/index-sort-b.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/pem + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/pemHitTotalCoverage
Test:coverage.infoLines:538760.9 %
Date:2024-09-22 08:21:07Functions:2540.0 %
Branches:225044.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
pem.c +
60.9%60.9%
+
60.9 %53 / 8740.0 %2 / 544.0 %22 / 50
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/pem/index-sort-f.html b/coverage_log/os_stub/cryptlib_mbedtls/pem/index-sort-f.html new file mode 100644 index 00000000000..d9d776ce473 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/pem/index-sort-f.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/pem + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/pemHitTotalCoverage
Test:coverage.infoLines:538760.9 %
Date:2024-09-22 08:21:07Functions:2540.0 %
Branches:225044.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
pem.c +
60.9%60.9%
+
60.9 %53 / 8740.0 %2 / 544.0 %22 / 50
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/pem/index-sort-l.html b/coverage_log/os_stub/cryptlib_mbedtls/pem/index-sort-l.html new file mode 100644 index 00000000000..c15a31d765e --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/pem/index-sort-l.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/pem + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/pemHitTotalCoverage
Test:coverage.infoLines:538760.9 %
Date:2024-09-22 08:21:07Functions:2540.0 %
Branches:225044.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
pem.c +
60.9%60.9%
+
60.9 %53 / 8740.0 %2 / 544.0 %22 / 50
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/pem/index.html b/coverage_log/os_stub/cryptlib_mbedtls/pem/index.html new file mode 100644 index 00000000000..859afdcda39 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/pem/index.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/pem + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/pemHitTotalCoverage
Test:coverage.infoLines:538760.9 %
Date:2024-09-22 08:21:07Functions:2540.0 %
Branches:225044.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
pem.c +
60.9%60.9%
+
60.9 %53 / 8740.0 %2 / 544.0 %22 / 50
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/pem/pem.c.func-sort-c.html b/coverage_log/os_stub/cryptlib_mbedtls/pem/pem.c.func-sort-c.html new file mode 100644 index 00000000000..f6e87d43370 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/pem/pem.c.func-sort-c.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/pem/pem.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/pem - pem.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:538760.9 %
Date:2024-09-22 08:21:07Functions:2540.0 %
Branches:225044.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
ascii_str_len0
libspdm_ecd_get_private_key_from_pem0
libspdm_sm2_get_private_key_from_pem0
libspdm_rsa_get_private_key_from_pem25
libspdm_ec_get_private_key_from_pem128
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/pem/pem.c.func.html b/coverage_log/os_stub/cryptlib_mbedtls/pem/pem.c.func.html new file mode 100644 index 00000000000..e0e9bb55df0 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/pem/pem.c.func.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/pem/pem.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/pem - pem.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:538760.9 %
Date:2024-09-22 08:21:07Functions:2540.0 %
Branches:225044.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
ascii_str_len0
libspdm_ec_get_private_key_from_pem128
libspdm_ecd_get_private_key_from_pem0
libspdm_rsa_get_private_key_from_pem25
libspdm_sm2_get_private_key_from_pem0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/pem/pem.c.gcov.html b/coverage_log/os_stub/cryptlib_mbedtls/pem/pem.c.gcov.html new file mode 100644 index 00000000000..00e1349bdba --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/pem/pem.c.gcov.html @@ -0,0 +1,349 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/pem/pem.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/pem - pem.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:538760.9 %
Date:2024-09-22 08:21:07Functions:2540.0 %
Branches:225044.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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                 :            : /** @file
+       8                 :            :  * PEM (Privacy Enhanced Mail) format Handler Wrapper Implementation.
+       9                 :            :  **/
+      10                 :            : 
+      11                 :            : #include "internal_crypt_lib.h"
+      12                 :            : #include <mbedtls/pem.h>
+      13                 :            : #include <mbedtls/pk.h>
+      14                 :            : #include <mbedtls/rsa.h>
+      15                 :            : #include <mbedtls/ecp.h>
+      16                 :            : #include <mbedtls/ecdh.h>
+      17                 :            : #include <mbedtls/ecdsa.h>
+      18                 :            : 
+      19                 :          0 : static size_t ascii_str_len(const char *string)
+      20                 :            : {
+      21                 :            :     size_t length;
+      22                 :            : 
+      23         [ #  # ]:          0 :     LIBSPDM_ASSERT(string != NULL);
+      24         [ #  # ]:          0 :     if (string == NULL) {
+      25                 :          0 :         return 0;
+      26                 :            :     }
+      27                 :            : 
+      28         [ #  # ]:          0 :     for (length = 0; *string != '\0'; string++, length++) {
+      29                 :            :         ;
+      30                 :            :     }
+      31                 :          0 :     return length;
+      32                 :            : }
+      33                 :            : 
+      34                 :            : #if (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT)
+      35                 :            : /**
+      36                 :            :  * Retrieve the RSA Private key from the password-protected PEM key data.
+      37                 :            :  *
+      38                 :            :  * @param[in]  pem_data      Pointer to the PEM-encoded key data to be retrieved.
+      39                 :            :  * @param[in]  pem_size      size of the PEM key data in bytes.
+      40                 :            :  * @param[in]  password     NULL-terminated passphrase used for encrypted PEM key data.
+      41                 :            :  * @param[out] rsa_context   Pointer to newly generated RSA context which contain the retrieved
+      42                 :            :  *                         RSA private key component. Use libspdm_rsa_free() function to free the
+      43                 :            :  *                         resource.
+      44                 :            :  *
+      45                 :            :  * If pem_data is NULL, then return false.
+      46                 :            :  * If rsa_context is NULL, then return false.
+      47                 :            :  *
+      48                 :            :  * @retval  true   RSA Private key was retrieved successfully.
+      49                 :            :  * @retval  false  Invalid PEM key data or incorrect password.
+      50                 :            :  *
+      51                 :            :  **/
+      52                 :         25 : bool libspdm_rsa_get_private_key_from_pem(const uint8_t *pem_data,
+      53                 :            :                                           size_t pem_size,
+      54                 :            :                                           const char *password,
+      55                 :            :                                           void **rsa_context)
+      56                 :            : {
+      57                 :            :     int ret;
+      58                 :            :     mbedtls_pk_context pk;
+      59                 :            :     mbedtls_rsa_context *rsa;
+      60                 :            :     uint8_t *new_pem_data;
+      61                 :            :     size_t password_len;
+      62                 :            : 
+      63   [ +  -  +  -  :         25 :     if (pem_data == NULL || rsa_context == NULL || pem_size > INT_MAX) {
+                   -  + ]
+      64                 :          0 :         return false;
+      65                 :            :     }
+      66                 :            : 
+      67                 :         25 :     new_pem_data = NULL;
+      68         [ +  - ]:         25 :     if (pem_data[pem_size - 1] != 0) {
+      69                 :         25 :         new_pem_data = allocate_pool(pem_size + 1);
+      70         [ -  + ]:         25 :         if (new_pem_data == NULL) {
+      71                 :          0 :             return false;
+      72                 :            :         }
+      73                 :         25 :         libspdm_copy_mem(new_pem_data, pem_size + 1, pem_data, pem_size);
+      74                 :         25 :         new_pem_data[pem_size] = 0;
+      75                 :         25 :         pem_data = new_pem_data;
+      76                 :         25 :         pem_size += 1;
+      77                 :            :     }
+      78                 :            : 
+      79                 :         25 :     mbedtls_pk_init(&pk);
+      80                 :            : 
+      81         [ -  + ]:         25 :     if (password != NULL) {
+      82                 :          0 :         password_len = ascii_str_len(password);
+      83                 :            :     } else {
+      84                 :         25 :         password_len = 0;
+      85                 :            :     }
+      86                 :            : 
+      87                 :         25 :     ret = mbedtls_pk_parse_key(&pk, pem_data, pem_size,
+      88                 :            :                                (const uint8_t *)password, password_len,
+      89                 :            :                                NULL, NULL);
+      90                 :            : 
+      91         [ +  - ]:         25 :     if (new_pem_data != NULL) {
+      92                 :         25 :         free_pool(new_pem_data);
+      93                 :         25 :         new_pem_data = NULL;
+      94                 :            :     }
+      95                 :            : 
+      96         [ -  + ]:         25 :     if (ret != 0) {
+      97                 :          0 :         mbedtls_pk_free(&pk);
+      98                 :          0 :         return false;
+      99                 :            :     }
+     100                 :            : 
+     101         [ -  + ]:         25 :     if (mbedtls_pk_get_type(&pk) != MBEDTLS_PK_RSA) {
+     102                 :          0 :         mbedtls_pk_free(&pk);
+     103                 :          0 :         return false;
+     104                 :            :     }
+     105                 :            : 
+     106                 :         25 :     rsa = libspdm_rsa_new();
+     107         [ -  + ]:         25 :     if (rsa == NULL) {
+     108                 :          0 :         return false;
+     109                 :            :     }
+     110                 :         25 :     ret = mbedtls_rsa_copy(rsa, mbedtls_pk_rsa(pk));
+     111         [ -  + ]:         25 :     if (ret != 0) {
+     112                 :          0 :         libspdm_rsa_free(rsa);
+     113                 :          0 :         mbedtls_pk_free(&pk);
+     114                 :          0 :         return false;
+     115                 :            :     }
+     116                 :         25 :     mbedtls_pk_free(&pk);
+     117                 :            : 
+     118                 :         25 :     *rsa_context = rsa;
+     119                 :         25 :     return true;
+     120                 :            : }
+     121                 :            : #endif /* (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT) */
+     122                 :            : 
+     123                 :            : /**
+     124                 :            :  * Retrieve the EC Private key from the password-protected PEM key data.
+     125                 :            :  *
+     126                 :            :  * @param[in]  pem_data      Pointer to the PEM-encoded key data to be retrieved.
+     127                 :            :  * @param[in]  pem_size      size of the PEM key data in bytes.
+     128                 :            :  * @param[in]  password     NULL-terminated passphrase used for encrypted PEM key data.
+     129                 :            :  * @param[out] ec_context    Pointer to newly generated EC DSA context which contain the retrieved
+     130                 :            :  *                         EC private key component. Use libspdm_ec_free() function to free the
+     131                 :            :  *                         resource.
+     132                 :            :  *
+     133                 :            :  * If pem_data is NULL, then return false.
+     134                 :            :  * If ec_context is NULL, then return false.
+     135                 :            :  *
+     136                 :            :  * @retval  true   EC Private key was retrieved successfully.
+     137                 :            :  * @retval  false  Invalid PEM key data or incorrect password.
+     138                 :            :  *
+     139                 :            :  **/
+     140                 :        128 : bool libspdm_ec_get_private_key_from_pem(const uint8_t *pem_data, size_t pem_size,
+     141                 :            :                                          const char *password,
+     142                 :            :                                          void **ec_context)
+     143                 :            : {
+     144                 :            :     int ret;
+     145                 :            :     mbedtls_pk_context pk;
+     146                 :            :     mbedtls_ecdh_context *ecdh;
+     147                 :            :     uint8_t *new_pem_data;
+     148                 :            :     size_t password_len;
+     149                 :            : 
+     150   [ +  -  +  -  :        128 :     if (pem_data == NULL || ec_context == NULL || pem_size > INT_MAX) {
+                   -  + ]
+     151                 :          0 :         return false;
+     152                 :            :     }
+     153                 :            : 
+     154                 :        128 :     new_pem_data = NULL;
+     155         [ +  - ]:        128 :     if (pem_data[pem_size - 1] != 0) {
+     156                 :        128 :         new_pem_data = allocate_pool(pem_size + 1);
+     157         [ -  + ]:        128 :         if (new_pem_data == NULL) {
+     158                 :          0 :             return false;
+     159                 :            :         }
+     160                 :        128 :         libspdm_copy_mem(new_pem_data, pem_size + 1, pem_data, pem_size);
+     161                 :        128 :         new_pem_data[pem_size] = 0;
+     162                 :        128 :         pem_data = new_pem_data;
+     163                 :        128 :         pem_size += 1;
+     164                 :            :     }
+     165                 :            : 
+     166                 :        128 :     mbedtls_pk_init(&pk);
+     167                 :            : 
+     168         [ -  + ]:        128 :     if (password != NULL) {
+     169                 :          0 :         password_len = ascii_str_len(password);
+     170                 :            :     } else {
+     171                 :        128 :         password_len = 0;
+     172                 :            :     }
+     173                 :            : 
+     174                 :        128 :     ret = mbedtls_pk_parse_key(&pk, pem_data, pem_size,
+     175                 :            :                                (const uint8_t *)password, password_len,
+     176                 :            :                                NULL, NULL);
+     177                 :            : 
+     178         [ +  - ]:        128 :     if (new_pem_data != NULL) {
+     179                 :        128 :         free_pool(new_pem_data);
+     180                 :        128 :         new_pem_data = NULL;
+     181                 :            :     }
+     182                 :            : 
+     183         [ -  + ]:        128 :     if (ret != 0) {
+     184                 :          0 :         mbedtls_pk_free(&pk);
+     185                 :          0 :         return false;
+     186                 :            :     }
+     187                 :            : 
+     188         [ -  + ]:        128 :     if (mbedtls_pk_get_type(&pk) != MBEDTLS_PK_ECKEY) {
+     189                 :          0 :         mbedtls_pk_free(&pk);
+     190                 :          0 :         return false;
+     191                 :            :     }
+     192                 :            : 
+     193                 :        128 :     ecdh = allocate_zero_pool(sizeof(mbedtls_ecdh_context));
+     194         [ -  + ]:        128 :     if (ecdh == NULL) {
+     195                 :          0 :         mbedtls_pk_free(&pk);
+     196                 :          0 :         return false;
+     197                 :            :     }
+     198                 :        128 :     mbedtls_ecdh_init(ecdh);
+     199                 :            : 
+     200                 :        128 :     ret = mbedtls_ecdh_get_params(ecdh, mbedtls_pk_ec(pk),
+     201                 :            :                                   MBEDTLS_ECDH_OURS);
+     202         [ -  + ]:        128 :     if (ret != 0) {
+     203                 :          0 :         mbedtls_ecdh_free(ecdh);
+     204                 :          0 :         free_pool(ecdh);
+     205                 :          0 :         mbedtls_pk_free(&pk);
+     206                 :          0 :         return false;
+     207                 :            :     }
+     208                 :        128 :     mbedtls_pk_free(&pk);
+     209                 :            : 
+     210                 :        128 :     *ec_context = ecdh;
+     211                 :        128 :     return true;
+     212                 :            : }
+     213                 :            : 
+     214                 :            : /**
+     215                 :            :  * Retrieve the Ed Private key from the password-protected PEM key data.
+     216                 :            :  *
+     217                 :            :  * @param[in]  pem_data      Pointer to the PEM-encoded key data to be retrieved.
+     218                 :            :  * @param[in]  pem_size      size of the PEM key data in bytes.
+     219                 :            :  * @param[in]  password     NULL-terminated passphrase used for encrypted PEM key data.
+     220                 :            :  * @param[out] ecd_context    Pointer to newly generated Ed DSA context which contain the retrieved
+     221                 :            :  *                         Ed private key component. Use libspdm_ecd_free() function to free the
+     222                 :            :  *                         resource.
+     223                 :            :  *
+     224                 :            :  * If pem_data is NULL, then return false.
+     225                 :            :  * If ecd_context is NULL, then return false.
+     226                 :            :  *
+     227                 :            :  * @retval  true   Ed Private key was retrieved successfully.
+     228                 :            :  * @retval  false  Invalid PEM key data or incorrect password.
+     229                 :            :  *
+     230                 :            :  **/
+     231                 :          0 : bool libspdm_ecd_get_private_key_from_pem(const uint8_t *pem_data,
+     232                 :            :                                           size_t pem_size,
+     233                 :            :                                           const char *password,
+     234                 :            :                                           void **ecd_context)
+     235                 :            : {
+     236                 :          0 :     return false;
+     237                 :            : }
+     238                 :            : 
+     239                 :            : /**
+     240                 :            :  * Retrieve the sm2 Private key from the password-protected PEM key data.
+     241                 :            :  *
+     242                 :            :  * @param[in]  pem_data      Pointer to the PEM-encoded key data to be retrieved.
+     243                 :            :  * @param[in]  pem_size      size of the PEM key data in bytes.
+     244                 :            :  * @param[in]  password     NULL-terminated passphrase used for encrypted PEM key data.
+     245                 :            :  * @param[out] sm2_context   Pointer to newly generated sm2 context which contain the retrieved
+     246                 :            :  *                         sm2 private key component. Use sm2_free() function to free the
+     247                 :            :  *                         resource.
+     248                 :            :  *
+     249                 :            :  * If pem_data is NULL, then return false.
+     250                 :            :  * If sm2_context is NULL, then return false.
+     251                 :            :  *
+     252                 :            :  * @retval  true   sm2 Private key was retrieved successfully.
+     253                 :            :  * @retval  false  Invalid PEM key data or incorrect password.
+     254                 :            :  *
+     255                 :            :  **/
+     256                 :          0 : bool libspdm_sm2_get_private_key_from_pem(const uint8_t *pem_data,
+     257                 :            :                                           size_t pem_size,
+     258                 :            :                                           const char *password,
+     259                 :            :                                           void **sm2_context)
+     260                 :            : {
+     261                 :          0 :     return false;
+     262                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/pk/dh.c.func-sort-c.html b/coverage_log/os_stub/cryptlib_mbedtls/pk/dh.c.func-sort-c.html new file mode 100644 index 00000000000..096fca1cb08 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/pk/dh.c.func-sort-c.html @@ -0,0 +1,105 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/pk/dh.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/pk - dh.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:4910646.2 %
Date:2024-09-22 08:21:07Functions:4666.7 %
Branches:215836.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_dh_generate_parameter0
libspdm_dh_set_parameter0
libspdm_dh_compute_key2
libspdm_dh_free2
libspdm_dh_generate_key2
libspdm_dh_new_by_nid2
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/pk/dh.c.func.html b/coverage_log/os_stub/cryptlib_mbedtls/pk/dh.c.func.html new file mode 100644 index 00000000000..df22eb44360 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/pk/dh.c.func.html @@ -0,0 +1,105 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/pk/dh.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/pk - dh.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:4910646.2 %
Date:2024-09-22 08:21:07Functions:4666.7 %
Branches:215836.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_dh_compute_key2
libspdm_dh_free2
libspdm_dh_generate_key2
libspdm_dh_generate_parameter0
libspdm_dh_new_by_nid2
libspdm_dh_set_parameter0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/pk/dh.c.gcov.html b/coverage_log/os_stub/cryptlib_mbedtls/pk/dh.c.gcov.html new file mode 100644 index 00000000000..f94ddec6d02 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/pk/dh.c.gcov.html @@ -0,0 +1,420 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/pk/dh.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/pk - dh.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:4910646.2 %
Date:2024-09-22 08:21:07Functions:4666.7 %
Branches:215836.2 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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                 :            : /** @file
+       8                 :            :  * Diffie-Hellman Wrapper Implementation over.
+       9                 :            :  *
+      10                 :            :  * RFC 7919 - Negotiated Finite Field Diffie-Hellman Ephemeral (FFDHE) Parameters
+      11                 :            :  **/
+      12                 :            : 
+      13                 :            : #include "internal_crypt_lib.h"
+      14                 :            : #include <mbedtls/dhm.h>
+      15                 :            : #include <mbedtls/bignum.h>
+      16                 :            : #include <string.h>
+      17                 :            : 
+      18                 :            : #if LIBSPDM_FFDHE_SUPPORT
+      19                 :            : 
+      20                 :            : static const unsigned char m_ffehde2048_p[] =
+      21                 :            :     MBEDTLS_DHM_RFC7919_FFDHE2048_P_BIN;
+      22                 :            : static const unsigned char m_ffehde3072_p[] =
+      23                 :            :     MBEDTLS_DHM_RFC7919_FFDHE3072_P_BIN;
+      24                 :            : static const unsigned char m_ffehde4096_p[] =
+      25                 :            :     MBEDTLS_DHM_RFC7919_FFDHE4096_P_BIN;
+      26                 :            : static const unsigned char m_ffehde2048_g[] =
+      27                 :            :     MBEDTLS_DHM_RFC7919_FFDHE2048_G_BIN;
+      28                 :            : static const unsigned char m_ffehde3072_g[] =
+      29                 :            :     MBEDTLS_DHM_RFC7919_FFDHE3072_G_BIN;
+      30                 :            : static const unsigned char m_ffehde4096_g[] =
+      31                 :            :     MBEDTLS_DHM_RFC7919_FFDHE4096_G_BIN;
+      32                 :            : 
+      33                 :            : /**
+      34                 :            :  * Allocates and Initializes one Diffie-Hellman context for subsequent use
+      35                 :            :  * with the NID.
+      36                 :            :  *
+      37                 :            :  * @param nid cipher NID
+      38                 :            :  *
+      39                 :            :  * @return  Pointer to the Diffie-Hellman context that has been initialized.
+      40                 :            :  *         If the allocations fails, dh_new() returns NULL.
+      41                 :            :  *
+      42                 :            :  **/
+      43                 :          2 : void *libspdm_dh_new_by_nid(size_t nid)
+      44                 :            : {
+      45                 :            :     mbedtls_dhm_context *ctx;
+      46                 :            :     int ret;
+      47                 :            : 
+      48                 :          2 :     ctx = allocate_zero_pool(sizeof(mbedtls_dhm_context));
+      49         [ -  + ]:          2 :     if (ctx == NULL) {
+      50                 :          0 :         return NULL;
+      51                 :            :     }
+      52                 :            : 
+      53                 :          2 :     mbedtls_dhm_init(ctx);
+      54                 :            : 
+      55   [ +  -  -  - ]:          2 :     switch (nid) {
+      56                 :          2 :     case LIBSPDM_CRYPTO_NID_FFDHE2048:
+      57                 :          2 :         ret = mbedtls_mpi_read_binary(&ctx->MBEDTLS_PRIVATE(P), m_ffehde2048_p,
+      58                 :            :                                       sizeof(m_ffehde2048_p));
+      59         [ -  + ]:          2 :         if (ret != 0) {
+      60                 :          0 :             goto error;
+      61                 :            :         }
+      62                 :          2 :         ret = mbedtls_mpi_read_binary(&ctx->MBEDTLS_PRIVATE(G), m_ffehde2048_g,
+      63                 :            :                                       sizeof(m_ffehde2048_g));
+      64         [ -  + ]:          2 :         if (ret != 0) {
+      65                 :          0 :             goto error;
+      66                 :            :         }
+      67                 :          2 :         break;
+      68                 :          0 :     case LIBSPDM_CRYPTO_NID_FFDHE3072:
+      69                 :          0 :         ret = mbedtls_mpi_read_binary(&ctx->MBEDTLS_PRIVATE(P), m_ffehde3072_p,
+      70                 :            :                                       sizeof(m_ffehde3072_p));
+      71         [ #  # ]:          0 :         if (ret != 0) {
+      72                 :          0 :             goto error;
+      73                 :            :         }
+      74                 :          0 :         ret = mbedtls_mpi_read_binary(&ctx->MBEDTLS_PRIVATE(G), m_ffehde3072_g,
+      75                 :            :                                       sizeof(m_ffehde3072_g));
+      76         [ #  # ]:          0 :         if (ret != 0) {
+      77                 :          0 :             goto error;
+      78                 :            :         }
+      79                 :          0 :         break;
+      80                 :          0 :     case LIBSPDM_CRYPTO_NID_FFDHE4096:
+      81                 :          0 :         ret = mbedtls_mpi_read_binary(&ctx->MBEDTLS_PRIVATE(P), m_ffehde4096_p,
+      82                 :            :                                       sizeof(m_ffehde4096_p));
+      83         [ #  # ]:          0 :         if (ret != 0) {
+      84                 :          0 :             goto error;
+      85                 :            :         }
+      86                 :          0 :         ret = mbedtls_mpi_read_binary(&ctx->MBEDTLS_PRIVATE(G), m_ffehde4096_g,
+      87                 :            :                                       sizeof(m_ffehde4096_g));
+      88         [ #  # ]:          0 :         if (ret != 0) {
+      89                 :          0 :             goto error;
+      90                 :            :         }
+      91                 :          0 :         break;
+      92                 :          0 :     default:
+      93                 :          0 :         goto error;
+      94                 :            :     }
+      95                 :          2 :     return ctx;
+      96                 :          0 : error:
+      97                 :          0 :     free_pool(ctx);
+      98                 :          0 :     return NULL;
+      99                 :            : }
+     100                 :            : 
+     101                 :            : /**
+     102                 :            :  * Release the specified DH context.
+     103                 :            :  *
+     104                 :            :  * If dh_context is NULL, then return false.
+     105                 :            :  *
+     106                 :            :  * @param[in]  dh_context  Pointer to the DH context to be released.
+     107                 :            :  *
+     108                 :            :  **/
+     109                 :          2 : void libspdm_dh_free(void *dh_context)
+     110                 :            : {
+     111                 :          2 :     mbedtls_dhm_free(dh_context);
+     112                 :          2 :     free_pool(dh_context);
+     113                 :          2 : }
+     114                 :            : 
+     115                 :            : /**
+     116                 :            :  * Generates DH parameter.
+     117                 :            :  *
+     118                 :            :  * Given generator g, and length of prime number p in bits, this function generates p,
+     119                 :            :  * and sets DH context according to value of g and p.
+     120                 :            :  *
+     121                 :            :  * If dh_context is NULL, then return false.
+     122                 :            :  * If prime is NULL, then return false.
+     123                 :            :  *
+     124                 :            :  * @param[in, out]  dh_context    Pointer to the DH context.
+     125                 :            :  * @param[in]       generator    value of generator.
+     126                 :            :  * @param[in]       prime_length  length in bits of prime to be generated.
+     127                 :            :  * @param[out]      prime        Pointer to the buffer to receive the generated prime number.
+     128                 :            :  *
+     129                 :            :  * @retval true   DH parameter generation succeeded.
+     130                 :            :  * @retval false  value of generator is not supported.
+     131                 :            :  * @retval false  PRNG fails to generate random prime number with prime_length.
+     132                 :            :  *
+     133                 :            :  **/
+     134                 :          0 : bool libspdm_dh_generate_parameter(void *dh_context, size_t generator,
+     135                 :            :                                    size_t prime_length, uint8_t *prime)
+     136                 :            : {
+     137                 :          0 :     return false;
+     138                 :            : }
+     139                 :            : 
+     140                 :            : /**
+     141                 :            :  * Sets generator and prime parameters for DH.
+     142                 :            :  *
+     143                 :            :  * Given generator g, and prime number p, this function and sets DH
+     144                 :            :  * context accordingly.
+     145                 :            :  *
+     146                 :            :  * If dh_context is NULL, then return false.
+     147                 :            :  * If prime is NULL, then return false.
+     148                 :            :  *
+     149                 :            :  * @param[in, out]  dh_context    Pointer to the DH context.
+     150                 :            :  * @param[in]       generator    value of generator.
+     151                 :            :  * @param[in]       prime_length  length in bits of prime to be generated.
+     152                 :            :  * @param[in]       prime        Pointer to the prime number.
+     153                 :            :  *
+     154                 :            :  * @retval true   DH parameter setting succeeded.
+     155                 :            :  * @retval false  value of generator is not supported.
+     156                 :            :  * @retval false  value of generator is not suitable for the prime.
+     157                 :            :  * @retval false  value of prime is not a prime number.
+     158                 :            :  * @retval false  value of prime is not a safe prime number.
+     159                 :            :  *
+     160                 :            :  **/
+     161                 :          0 : bool libspdm_dh_set_parameter(void *dh_context, size_t generator,
+     162                 :            :                               size_t prime_length, const uint8_t *prime)
+     163                 :            : {
+     164                 :          0 :     return false;
+     165                 :            : }
+     166                 :            : 
+     167                 :            : /**
+     168                 :            :  * Generates DH public key.
+     169                 :            :  *
+     170                 :            :  * This function generates random secret exponent, and computes the public key, which is
+     171                 :            :  * returned via parameter public_key and public_key_size. DH context is updated accordingly.
+     172                 :            :  * If the public_key buffer is too small to hold the public key, false is returned and
+     173                 :            :  * public_key_size is set to the required buffer size to obtain the public key.
+     174                 :            :  *
+     175                 :            :  * If dh_context is NULL, then return false.
+     176                 :            :  * If public_key_size is NULL, then return false.
+     177                 :            :  * If public_key_size is large enough but public_key is NULL, then return false.
+     178                 :            :  *
+     179                 :            :  * For FFDHE2048, the public_size is 256.
+     180                 :            :  * For FFDHE3072, the public_size is 384.
+     181                 :            :  * For FFDHE4096, the public_size is 512.
+     182                 :            :  *
+     183                 :            :  * @param[in, out]  dh_context      Pointer to the DH context.
+     184                 :            :  * @param[out]      public_key      Pointer to the buffer to receive generated public key.
+     185                 :            :  * @param[in, out]  public_key_size  On input, the size of public_key buffer in bytes.
+     186                 :            :  *                                On output, the size of data returned in public_key buffer in bytes.
+     187                 :            :  *
+     188                 :            :  * @retval true   DH public key generation succeeded.
+     189                 :            :  * @retval false  DH public key generation failed.
+     190                 :            :  * @retval false  public_key_size is not large enough.
+     191                 :            :  *
+     192                 :            :  **/
+     193                 :          2 : bool libspdm_dh_generate_key(void *dh_context, uint8_t *public_key,
+     194                 :            :                              size_t *public_key_size)
+     195                 :            : {
+     196                 :            :     int ret;
+     197                 :            :     mbedtls_dhm_context *ctx;
+     198                 :            :     size_t final_pub_key_size;
+     199                 :            : 
+     200                 :            : 
+     201                 :            :     /* Check input parameters.*/
+     202                 :            : 
+     203   [ +  -  -  + ]:          2 :     if (dh_context == NULL || public_key_size == NULL) {
+     204                 :          0 :         return false;
+     205                 :            :     }
+     206                 :            : 
+     207   [ -  +  -  - ]:          2 :     if (public_key == NULL && *public_key_size != 0) {
+     208                 :          0 :         return false;
+     209                 :            :     }
+     210                 :            : 
+     211                 :          2 :     ctx = dh_context;
+     212   [ +  -  -  - ]:          2 :     switch (mbedtls_mpi_size(&ctx->MBEDTLS_PRIVATE(P))) {
+     213                 :          2 :     case 256:
+     214                 :          2 :         final_pub_key_size = 256;
+     215                 :          2 :         break;
+     216                 :          0 :     case 384:
+     217                 :          0 :         final_pub_key_size = 384;
+     218                 :          0 :         break;
+     219                 :          0 :     case 512:
+     220                 :          0 :         final_pub_key_size = 512;
+     221                 :          0 :         break;
+     222                 :          0 :     default:
+     223                 :          0 :         return false;
+     224                 :            :     }
+     225         [ -  + ]:          2 :     if (*public_key_size < final_pub_key_size) {
+     226                 :          0 :         *public_key_size = final_pub_key_size;
+     227                 :          0 :         return false;
+     228                 :            :     }
+     229                 :          2 :     *public_key_size = final_pub_key_size;
+     230                 :          2 :     libspdm_zero_mem(public_key, *public_key_size);
+     231                 :            : 
+     232                 :          2 :     ret = mbedtls_dhm_make_public(dh_context, (uint32_t)*public_key_size,
+     233                 :          2 :                                   public_key, (uint32_t)*public_key_size,
+     234                 :            :                                   libspdm_myrand, NULL);
+     235         [ -  + ]:          2 :     if (ret != 0) {
+     236                 :          0 :         return false;
+     237                 :            :     }
+     238                 :            : 
+     239                 :          2 :     return true;
+     240                 :            : }
+     241                 :            : 
+     242                 :            : /**
+     243                 :            :  * Computes exchanged common key.
+     244                 :            :  *
+     245                 :            :  * Given peer's public key, this function computes the exchanged common key, based on its own
+     246                 :            :  * context including value of prime modulus and random secret exponent.
+     247                 :            :  *
+     248                 :            :  * If dh_context is NULL, then return false.
+     249                 :            :  * If peer_public_key is NULL, then return false.
+     250                 :            :  * If key_size is NULL, then return false.
+     251                 :            :  * If key is NULL, then return false.
+     252                 :            :  * If key_size is not large enough, then return false.
+     253                 :            :  *
+     254                 :            :  * For FFDHE2048, the peer_public_size is 256.
+     255                 :            :  * For FFDHE3072, the peer_public_size is 384.
+     256                 :            :  * For FFDHE4096, the peer_public_size is 512.
+     257                 :            :  *
+     258                 :            :  * @param[in, out]  dh_context          Pointer to the DH context.
+     259                 :            :  * @param[in]       peer_public_key      Pointer to the peer's public key.
+     260                 :            :  * @param[in]       peer_public_key_size  size of peer's public key in bytes.
+     261                 :            :  * @param[out]      key                Pointer to the buffer to receive generated key.
+     262                 :            :  * @param[in, out]  key_size            On input, the size of key buffer in bytes.
+     263                 :            :  *                                    On output, the size of data returned in key buffer in bytes.
+     264                 :            :  *
+     265                 :            :  * @retval true   DH exchanged key generation succeeded.
+     266                 :            :  * @retval false  DH exchanged key generation failed.
+     267                 :            :  * @retval false  key_size is not large enough.
+     268                 :            :  *
+     269                 :            :  **/
+     270                 :          2 : bool libspdm_dh_compute_key(void *dh_context, const uint8_t *peer_public_key,
+     271                 :            :                             size_t peer_public_key_size, uint8_t *key,
+     272                 :            :                             size_t *key_size)
+     273                 :            : {
+     274                 :            :     int ret;
+     275                 :            :     mbedtls_dhm_context *ctx;
+     276                 :            :     size_t return_size;
+     277                 :            :     size_t dh_key_size;
+     278                 :            : 
+     279                 :            :     /* Check input parameters.*/
+     280                 :            : 
+     281   [ +  -  +  -  :          2 :     if (dh_context == NULL || peer_public_key == NULL || key_size == NULL ||
+             +  -  -  + ]
+     282                 :            :         key == NULL) {
+     283                 :          0 :         return false;
+     284                 :            :     }
+     285                 :            : 
+     286         [ -  + ]:          2 :     if (peer_public_key_size > INT_MAX) {
+     287                 :          0 :         return false;
+     288                 :            :     }
+     289                 :            : 
+     290                 :          2 :     ctx = dh_context;
+     291   [ +  -  -  - ]:          2 :     switch (mbedtls_mpi_size(&ctx->MBEDTLS_PRIVATE(P))) {
+     292                 :          2 :     case 256:
+     293                 :          2 :         dh_key_size = 256;
+     294                 :          2 :         break;
+     295                 :          0 :     case 384:
+     296                 :          0 :         dh_key_size = 384;
+     297                 :          0 :         break;
+     298                 :          0 :     case 512:
+     299                 :          0 :         dh_key_size = 512;
+     300                 :          0 :         break;
+     301                 :          0 :     default:
+     302                 :          0 :         return false;
+     303                 :            :     }
+     304         [ -  + ]:          2 :     if (peer_public_key_size != dh_key_size) {
+     305                 :          0 :         return false;
+     306                 :            :     }
+     307         [ -  + ]:          2 :     if (*key_size < dh_key_size) {
+     308                 :          0 :         return false;
+     309                 :            :     }
+     310                 :          2 :     *key_size = dh_key_size;
+     311                 :            : 
+     312                 :          2 :     ret = mbedtls_dhm_read_public(dh_context, peer_public_key,
+     313                 :            :                                   peer_public_key_size);
+     314         [ -  + ]:          2 :     if (ret != 0) {
+     315                 :          0 :         return false;
+     316                 :            :     }
+     317                 :            : 
+     318                 :          2 :     return_size = 0;
+     319                 :          2 :     ret = mbedtls_dhm_calc_secret(dh_context, key, *key_size, &return_size,
+     320                 :            :                                   libspdm_myrand, NULL);
+     321         [ -  + ]:          2 :     if (ret != 0) {
+     322                 :          0 :         return false;
+     323                 :            :     }
+     324                 :            : 
+     325                 :            :     /*change the key, for example: from 0x123400 to 0x001234*/
+     326         [ -  + ]:          2 :     if (return_size < dh_key_size) {
+     327                 :          0 :         memmove(key + dh_key_size - return_size, key, return_size);
+     328                 :          0 :         libspdm_zero_mem(key, dh_key_size - return_size);
+     329                 :            :     }
+     330                 :            : 
+     331                 :          2 :     return true;
+     332                 :            : }
+     333                 :            : 
+     334                 :            : #endif /* LIBSPDM_FFDHE_SUPPORT */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/pk/ec.c.func-sort-c.html b/coverage_log/os_stub/cryptlib_mbedtls/pk/ec.c.func-sort-c.html new file mode 100644 index 00000000000..86a1e94d64d --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/pk/ec.c.func-sort-c.html @@ -0,0 +1,125 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/pk/ec.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/pk - ec.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:18137548.3 %
Date:2024-09-22 08:21:07Functions:91181.8 %
Branches:7520636.4 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_ec_check_key0
libspdm_ec_get_pub_key0
libspdm_ec_set_pub_key1
libspdm_ecdsa_sign_ex1
libspdm_ec_set_priv_key2
libspdm_ecdsa_verify70
libspdm_ec_compute_key74
libspdm_ecdsa_sign123
libspdm_ec_generate_key164
libspdm_ec_new_by_nid166
libspdm_ec_free975
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/pk/ec.c.func.html b/coverage_log/os_stub/cryptlib_mbedtls/pk/ec.c.func.html new file mode 100644 index 00000000000..6921e195522 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/pk/ec.c.func.html @@ -0,0 +1,125 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/pk/ec.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/pk - ec.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:18137548.3 %
Date:2024-09-22 08:21:07Functions:91181.8 %
Branches:7520636.4 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_ec_check_key0
libspdm_ec_compute_key74
libspdm_ec_free975
libspdm_ec_generate_key164
libspdm_ec_get_pub_key0
libspdm_ec_new_by_nid166
libspdm_ec_set_priv_key2
libspdm_ec_set_pub_key1
libspdm_ecdsa_sign123
libspdm_ecdsa_sign_ex1
libspdm_ecdsa_verify70
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/pk/ec.c.gcov.html b/coverage_log/os_stub/cryptlib_mbedtls/pk/ec.c.gcov.html new file mode 100644 index 00000000000..b206e60efaa --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/pk/ec.c.gcov.html @@ -0,0 +1,927 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/pk/ec.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/pk - ec.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:18137548.3 %
Date:2024-09-22 08:21:07Functions:91181.8 %
Branches:7520636.4 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 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                 :            : /** @file
+       8                 :            :  * Elliptic Curve Wrapper Implementation.
+       9                 :            :  *
+      10                 :            :  * RFC 8422 - Elliptic Curve Cryptography (ECC) Cipher Suites
+      11                 :            :  * FIPS 186-4 - Digital signature Standard (DSS)
+      12                 :            :  **/
+      13                 :            : 
+      14                 :            : #include "internal_crypt_lib.h"
+      15                 :            : #include <mbedtls/ecp.h>
+      16                 :            : #include <mbedtls/ecdh.h>
+      17                 :            : #include <mbedtls/ecdsa.h>
+      18                 :            : #include <mbedtls/bignum.h>
+      19                 :            : 
+      20                 :            : /**
+      21                 :            :  * Allocates and Initializes one Elliptic Curve context for subsequent use
+      22                 :            :  * with the NID.
+      23                 :            :  *
+      24                 :            :  * @param nid cipher NID
+      25                 :            :  *
+      26                 :            :  * @return  Pointer to the Elliptic Curve context that has been initialized.
+      27                 :            :  *         If the allocations fails, libspdm_ec_new_by_nid() returns NULL.
+      28                 :            :  *
+      29                 :            :  **/
+      30                 :        166 : void *libspdm_ec_new_by_nid(size_t nid)
+      31                 :            : {
+      32                 :            :     mbedtls_ecdh_context *ctx;
+      33                 :            :     mbedtls_ecp_group_id grp_id;
+      34                 :            :     int ret;
+      35                 :            : 
+      36                 :        166 :     ctx = allocate_zero_pool(sizeof(mbedtls_ecdh_context));
+      37         [ -  + ]:        166 :     if (ctx == NULL) {
+      38                 :          0 :         return NULL;
+      39                 :            :     }
+      40   [ +  -  -  - ]:        166 :     switch (nid) {
+      41                 :        166 :     case LIBSPDM_CRYPTO_NID_SECP256R1:
+      42                 :            :     case LIBSPDM_CRYPTO_NID_ECDSA_NIST_P256:
+      43                 :        166 :         grp_id = MBEDTLS_ECP_DP_SECP256R1;
+      44                 :        166 :         break;
+      45                 :          0 :     case LIBSPDM_CRYPTO_NID_SECP384R1:
+      46                 :            :     case LIBSPDM_CRYPTO_NID_ECDSA_NIST_P384:
+      47                 :          0 :         grp_id = MBEDTLS_ECP_DP_SECP384R1;
+      48                 :          0 :         break;
+      49                 :          0 :     case LIBSPDM_CRYPTO_NID_SECP521R1:
+      50                 :            :     case LIBSPDM_CRYPTO_NID_ECDSA_NIST_P521:
+      51                 :          0 :         grp_id = MBEDTLS_ECP_DP_SECP521R1;
+      52                 :          0 :         break;
+      53                 :          0 :     default:
+      54                 :          0 :         goto error;
+      55                 :            :     }
+      56                 :            : 
+      57                 :        166 :     mbedtls_ecdh_init(ctx);
+      58                 :        166 :     ret = mbedtls_ecdh_setup(ctx, grp_id);
+      59         [ -  + ]:        166 :     if (ret != 0) {
+      60                 :          0 :         goto error;
+      61                 :            :     }
+      62                 :        166 :     return ctx;
+      63                 :          0 : error:
+      64                 :          0 :     free_pool(ctx);
+      65                 :          0 :     return NULL;
+      66                 :            : }
+      67                 :            : 
+      68                 :            : /**
+      69                 :            :  * Release the specified EC context.
+      70                 :            :  *
+      71                 :            :  * @param[in]  ec_context  Pointer to the EC context to be released.
+      72                 :            :  *
+      73                 :            :  **/
+      74                 :        975 : void libspdm_ec_free(void *ec_context)
+      75                 :            : {
+      76                 :        975 :     mbedtls_ecdh_free(ec_context);
+      77                 :        975 :     free_pool(ec_context);
+      78                 :        975 : }
+      79                 :            : 
+      80                 :            : /**
+      81                 :            :  * Sets the public key component into the established EC context.
+      82                 :            :  *
+      83                 :            :  * For P-256, the public_size is 64. first 32-byte is X, second 32-byte is Y.
+      84                 :            :  * For P-384, the public_size is 96. first 48-byte is X, second 48-byte is Y.
+      85                 :            :  * For P-521, the public_size is 132. first 66-byte is X, second 66-byte is Y.
+      86                 :            :  *
+      87                 :            :  * @param[in, out]  ec_context      Pointer to EC context being set.
+      88                 :            :  * @param[in]       public         Pointer to the buffer to receive generated public X,Y.
+      89                 :            :  * @param[in]       public_size     The size of public buffer in bytes.
+      90                 :            :  *
+      91                 :            :  * @retval  true   EC public key component was set successfully.
+      92                 :            :  * @retval  false  Invalid EC public key component.
+      93                 :            :  *
+      94                 :            :  **/
+      95                 :          1 : bool libspdm_ec_set_pub_key(void *ec_context, const uint8_t *public_key,
+      96                 :            :                             size_t public_key_size)
+      97                 :            : {
+      98                 :            :     mbedtls_ecdh_context *ctx;
+      99                 :            :     int ret;
+     100                 :            :     size_t half_size;
+     101                 :            : 
+     102   [ +  -  -  + ]:          1 :     if (ec_context == NULL || public_key == NULL) {
+     103                 :          0 :         return false;
+     104                 :            :     }
+     105                 :            : 
+     106                 :          1 :     ctx = ec_context;
+     107   [ +  -  -  - ]:          1 :     switch (mbedtls_ecdh_get_grp_id(ctx)) {
+     108                 :          1 :     case MBEDTLS_ECP_DP_SECP256R1:
+     109                 :          1 :         half_size = 32;
+     110                 :          1 :         break;
+     111                 :          0 :     case MBEDTLS_ECP_DP_SECP384R1:
+     112                 :          0 :         half_size = 48;
+     113                 :          0 :         break;
+     114                 :          0 :     case MBEDTLS_ECP_DP_SECP521R1:
+     115                 :          0 :         half_size = 66;
+     116                 :          0 :         break;
+     117                 :          0 :     default:
+     118                 :          0 :         return false;
+     119                 :            :     }
+     120         [ -  + ]:          1 :     if (public_key_size != half_size * 2) {
+     121                 :          0 :         return false;
+     122                 :            :     }
+     123                 :            : 
+     124                 :          1 :     ret = mbedtls_mpi_read_binary(&ctx->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(X),
+     125                 :            :                                   public_key, half_size);
+     126         [ -  + ]:          1 :     if (ret != 0) {
+     127                 :          0 :         return false;
+     128                 :            :     }
+     129                 :          1 :     ret = mbedtls_mpi_read_binary(&ctx->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(Y),
+     130                 :          1 :                                   public_key + half_size, half_size);
+     131         [ -  + ]:          1 :     if (ret != 0) {
+     132                 :          0 :         return false;
+     133                 :            :     }
+     134                 :          1 :     ret = mbedtls_mpi_lset(&ctx->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(Z), 1);
+     135         [ -  + ]:          1 :     if (ret != 0) {
+     136                 :          0 :         return false;
+     137                 :            :     }
+     138                 :            : 
+     139                 :          1 :     return true;
+     140                 :            : }
+     141                 :            : 
+     142                 :            : /**
+     143                 :            :  * Sets the private key component into the established EC context.
+     144                 :            :  *
+     145                 :            :  * For P-256, the private_key_size is 32 byte.
+     146                 :            :  * For P-384, the private_key_size is 48 byte.
+     147                 :            :  * For P-521, the private_key_size is 66 byte.
+     148                 :            :  *
+     149                 :            :  * @param[in, out]  ec_context       Pointer to EC context being set.
+     150                 :            :  * @param[in]       private_key      Pointer to the private key buffer.
+     151                 :            :  * @param[in]       private_key_size The size of private key buffer in bytes.
+     152                 :            :  *
+     153                 :            :  * @retval  true   EC private key component was set successfully.
+     154                 :            :  * @retval  false  Invalid EC private key component.
+     155                 :            :  *
+     156                 :            :  **/
+     157                 :          2 : bool libspdm_ec_set_priv_key(void *ec_context, const uint8_t *private_key,
+     158                 :            :                              size_t private_key_size)
+     159                 :            : {
+     160                 :            :     mbedtls_ecdh_context *ctx;
+     161                 :            :     int ret;
+     162                 :            :     size_t half_size;
+     163                 :            : 
+     164   [ +  -  -  + ]:          2 :     if (ec_context == NULL || private_key == NULL) {
+     165                 :          0 :         return false;
+     166                 :            :     }
+     167                 :            : 
+     168                 :          2 :     ctx = ec_context;
+     169   [ +  -  -  - ]:          2 :     switch (mbedtls_ecdh_get_grp_id(ctx)) {
+     170                 :          2 :     case MBEDTLS_ECP_DP_SECP256R1:
+     171                 :          2 :         half_size = 32;
+     172                 :          2 :         break;
+     173                 :          0 :     case MBEDTLS_ECP_DP_SECP384R1:
+     174                 :          0 :         half_size = 48;
+     175                 :          0 :         break;
+     176                 :          0 :     case MBEDTLS_ECP_DP_SECP521R1:
+     177                 :          0 :         half_size = 66;
+     178                 :          0 :         break;
+     179                 :          0 :     default:
+     180                 :          0 :         return false;
+     181                 :            :     }
+     182         [ -  + ]:          2 :     if (private_key_size != half_size) {
+     183                 :          0 :         return false;
+     184                 :            :     }
+     185                 :            : 
+     186                 :          2 :     ret = mbedtls_mpi_read_binary(&ctx->MBEDTLS_PRIVATE(d), private_key,
+     187                 :            :                                   private_key_size);
+     188         [ -  + ]:          2 :     if (ret != 0) {
+     189                 :          0 :         return false;
+     190                 :            :     }
+     191                 :            : 
+     192                 :          2 :     return true;
+     193                 :            : }
+     194                 :            : 
+     195                 :            : /**
+     196                 :            :  * Gets the public key component from the established EC context.
+     197                 :            :  *
+     198                 :            :  * For P-256, the public_size is 64. first 32-byte is X, second 32-byte is Y.
+     199                 :            :  * For P-384, the public_size is 96. first 48-byte is X, second 48-byte is Y.
+     200                 :            :  * For P-521, the public_size is 132. first 66-byte is X, second 66-byte is Y.
+     201                 :            :  *
+     202                 :            :  * @param[in, out]  ec_context      Pointer to EC context being set.
+     203                 :            :  * @param[out]      public         Pointer to the buffer to receive generated public X,Y.
+     204                 :            :  * @param[in, out]  public_size     On input, the size of public buffer in bytes.
+     205                 :            :  *                                On output, the size of data returned in public buffer in bytes.
+     206                 :            :  *
+     207                 :            :  * @retval  true   EC key component was retrieved successfully.
+     208                 :            :  * @retval  false  Invalid EC key component.
+     209                 :            :  *
+     210                 :            :  **/
+     211                 :          0 : bool libspdm_ec_get_pub_key(void *ec_context, uint8_t *public_key,
+     212                 :            :                             size_t *public_key_size)
+     213                 :            : {
+     214                 :            :     mbedtls_ecdh_context *ctx;
+     215                 :            :     int ret;
+     216                 :            :     size_t half_size;
+     217                 :            :     size_t x_size;
+     218                 :            :     size_t y_size;
+     219                 :            : 
+     220   [ #  #  #  # ]:          0 :     if (ec_context == NULL || public_key_size == NULL) {
+     221                 :          0 :         return false;
+     222                 :            :     }
+     223                 :            : 
+     224   [ #  #  #  # ]:          0 :     if (public_key == NULL && *public_key_size != 0) {
+     225                 :          0 :         return false;
+     226                 :            :     }
+     227                 :            : 
+     228                 :          0 :     ctx = ec_context;
+     229   [ #  #  #  # ]:          0 :     switch (mbedtls_ecdh_get_grp_id(ctx)) {
+     230                 :          0 :     case MBEDTLS_ECP_DP_SECP256R1:
+     231                 :          0 :         half_size = 32;
+     232                 :          0 :         break;
+     233                 :          0 :     case MBEDTLS_ECP_DP_SECP384R1:
+     234                 :          0 :         half_size = 48;
+     235                 :          0 :         break;
+     236                 :          0 :     case MBEDTLS_ECP_DP_SECP521R1:
+     237                 :          0 :         half_size = 66;
+     238                 :          0 :         break;
+     239                 :          0 :     default:
+     240                 :          0 :         return false;
+     241                 :            :     }
+     242         [ #  # ]:          0 :     if (*public_key_size < half_size * 2) {
+     243                 :          0 :         *public_key_size = half_size * 2;
+     244                 :          0 :         return false;
+     245                 :            :     }
+     246                 :          0 :     *public_key_size = half_size * 2;
+     247                 :          0 :     libspdm_zero_mem(public_key, *public_key_size);
+     248                 :            : 
+     249                 :          0 :     x_size = mbedtls_mpi_size(&ctx->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(X));
+     250                 :          0 :     y_size = mbedtls_mpi_size(&ctx->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(Y));
+     251   [ #  #  #  # ]:          0 :     LIBSPDM_ASSERT(x_size <= half_size && y_size <= half_size);
+     252                 :            : 
+     253                 :          0 :     ret = mbedtls_mpi_write_binary(&ctx->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(X),
+     254                 :          0 :                                    &public_key[0 + half_size - x_size], x_size);
+     255         [ #  # ]:          0 :     if (ret != 0) {
+     256                 :          0 :         return false;
+     257                 :            :     }
+     258                 :          0 :     ret = mbedtls_mpi_write_binary(&ctx->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(Y),
+     259                 :          0 :                                    &public_key[half_size + half_size - y_size],
+     260                 :            :                                    y_size);
+     261         [ #  # ]:          0 :     if (ret != 0) {
+     262                 :          0 :         return false;
+     263                 :            :     }
+     264                 :            : 
+     265                 :          0 :     return true;
+     266                 :            : }
+     267                 :            : 
+     268                 :            : /**
+     269                 :            :  * Validates key components of EC context.
+     270                 :            :  * NOTE: This function performs integrity checks on all the EC key material, so
+     271                 :            :  *      the EC key structure must contain all the private key data.
+     272                 :            :  *
+     273                 :            :  * If ec_context is NULL, then return false.
+     274                 :            :  *
+     275                 :            :  * @param[in]  ec_context  Pointer to EC context to check.
+     276                 :            :  *
+     277                 :            :  * @retval  true   EC key components are valid.
+     278                 :            :  * @retval  false  EC key components are not valid.
+     279                 :            :  *
+     280                 :            :  **/
+     281                 :          0 : bool libspdm_ec_check_key(const void *ec_context)
+     282                 :            : {
+     283                 :            :     /* TBD*/
+     284                 :          0 :     return true;
+     285                 :            : }
+     286                 :            : 
+     287                 :            : /**
+     288                 :            :  * Generates EC key and returns EC public key (X, Y).
+     289                 :            :  *
+     290                 :            :  * This function generates random secret, and computes the public key (X, Y), which is
+     291                 :            :  * returned via parameter public, public_size.
+     292                 :            :  * X is the first half of public with size being public_size / 2,
+     293                 :            :  * Y is the second half of public with size being public_size / 2.
+     294                 :            :  * EC context is updated accordingly.
+     295                 :            :  * If the public buffer is too small to hold the public X, Y, false is returned and
+     296                 :            :  * public_size is set to the required buffer size to obtain the public X, Y.
+     297                 :            :  *
+     298                 :            :  * For P-256, the public_size is 64. first 32-byte is X, second 32-byte is Y.
+     299                 :            :  * For P-384, the public_size is 96. first 48-byte is X, second 48-byte is Y.
+     300                 :            :  * For P-521, the public_size is 132. first 66-byte is X, second 66-byte is Y.
+     301                 :            :  *
+     302                 :            :  * If ec_context is NULL, then return false.
+     303                 :            :  * If public_size is NULL, then return false.
+     304                 :            :  * If public_size is large enough but public is NULL, then return false.
+     305                 :            :  *
+     306                 :            :  * @param[in, out]  ec_context      Pointer to the EC context.
+     307                 :            :  * @param[out]      public_data     Pointer to the buffer to receive generated public X,Y.
+     308                 :            :  * @param[in, out]  public_size     On input, the size of public buffer in bytes.
+     309                 :            :  *                                On output, the size of data returned in public buffer in bytes.
+     310                 :            :  *
+     311                 :            :  * @retval true   EC public X,Y generation succeeded.
+     312                 :            :  * @retval false  EC public X,Y generation failed.
+     313                 :            :  * @retval false  public_size is not large enough.
+     314                 :            :  *
+     315                 :            :  **/
+     316                 :        164 : bool libspdm_ec_generate_key(void *ec_context, uint8_t *public_data,
+     317                 :            :                              size_t *public_size)
+     318                 :            : {
+     319                 :            :     mbedtls_ecdh_context *ctx;
+     320                 :            :     int ret;
+     321                 :            :     size_t half_size;
+     322                 :            :     size_t x_size;
+     323                 :            :     size_t y_size;
+     324                 :            : 
+     325   [ +  -  -  + ]:        164 :     if (ec_context == NULL || public_size == NULL) {
+     326                 :          0 :         return false;
+     327                 :            :     }
+     328                 :            : 
+     329   [ -  +  -  - ]:        164 :     if (public_data == NULL && *public_size != 0) {
+     330                 :          0 :         return false;
+     331                 :            :     }
+     332                 :            : 
+     333                 :        164 :     ctx = ec_context;
+     334                 :        164 :     ret = mbedtls_ecdh_gen_public(&ctx->MBEDTLS_PRIVATE(grp),
+     335                 :            :                                   &ctx->MBEDTLS_PRIVATE(d),
+     336                 :            :                                   &ctx->MBEDTLS_PRIVATE(Q), libspdm_myrand,
+     337                 :            :                                   NULL);
+     338         [ -  + ]:        164 :     if (ret != 0) {
+     339                 :          0 :         return false;
+     340                 :            :     }
+     341                 :            : 
+     342   [ +  -  -  - ]:        164 :     switch (mbedtls_ecdh_get_grp_id(ctx)) {
+     343                 :        164 :     case MBEDTLS_ECP_DP_SECP256R1:
+     344                 :        164 :         half_size = 32;
+     345                 :        164 :         break;
+     346                 :          0 :     case MBEDTLS_ECP_DP_SECP384R1:
+     347                 :          0 :         half_size = 48;
+     348                 :          0 :         break;
+     349                 :          0 :     case MBEDTLS_ECP_DP_SECP521R1:
+     350                 :          0 :         half_size = 66;
+     351                 :          0 :         break;
+     352                 :          0 :     default:
+     353                 :          0 :         return false;
+     354                 :            :     }
+     355         [ -  + ]:        164 :     if (*public_size < half_size * 2) {
+     356                 :          0 :         *public_size = half_size * 2;
+     357                 :          0 :         return false;
+     358                 :            :     }
+     359                 :        164 :     *public_size = half_size * 2;
+     360                 :        164 :     libspdm_zero_mem(public_data, *public_size);
+     361                 :            : 
+     362                 :        164 :     x_size = mbedtls_mpi_size(&ctx->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(X));
+     363                 :        164 :     y_size = mbedtls_mpi_size(&ctx->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(Y));
+     364   [ +  -  -  + ]:        164 :     LIBSPDM_ASSERT(x_size <= half_size && y_size <= half_size);
+     365                 :            : 
+     366                 :        164 :     ret = mbedtls_mpi_write_binary(&ctx->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(X),
+     367                 :        164 :                                    &public_data[0 + half_size - x_size], x_size);
+     368         [ -  + ]:        164 :     if (ret != 0) {
+     369                 :          0 :         return false;
+     370                 :            :     }
+     371                 :        164 :     ret = mbedtls_mpi_write_binary(&ctx->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(Y),
+     372                 :        164 :                                    &public_data[half_size + half_size - y_size],
+     373                 :            :                                    y_size);
+     374         [ -  + ]:        164 :     if (ret != 0) {
+     375                 :          0 :         return false;
+     376                 :            :     }
+     377                 :            : 
+     378                 :        164 :     return true;
+     379                 :            : }
+     380                 :            : 
+     381                 :            : /**
+     382                 :            :  * Computes exchanged common key.
+     383                 :            :  *
+     384                 :            :  * Given peer's public key (X, Y), this function computes the exchanged common key,
+     385                 :            :  * based on its own context including value of curve parameter and random secret.
+     386                 :            :  * X is the first half of peer_public with size being peer_public_size / 2,
+     387                 :            :  * Y is the second half of peer_public with size being peer_public_size / 2.
+     388                 :            :  *
+     389                 :            :  * If ec_context is NULL, then return false.
+     390                 :            :  * If peer_public is NULL, then return false.
+     391                 :            :  * If peer_public_size is 0, then return false.
+     392                 :            :  * If key is NULL, then return false.
+     393                 :            :  * If key_size is not large enough, then return false.
+     394                 :            :  *
+     395                 :            :  * For P-256, the peer_public_size is 64. first 32-byte is X, second 32-byte is Y. The key_size is 32.
+     396                 :            :  * For P-384, the peer_public_size is 96. first 48-byte is X, second 48-byte is Y. The key_size is 48.
+     397                 :            :  * For P-521, the peer_public_size is 132. first 66-byte is X, second 66-byte is Y. The key_size is 66.
+     398                 :            :  *
+     399                 :            :  * @param[in, out]  ec_context          Pointer to the EC context.
+     400                 :            :  * @param[in]       peer_public         Pointer to the peer's public X,Y.
+     401                 :            :  * @param[in]       peer_public_size     size of peer's public X,Y in bytes.
+     402                 :            :  * @param[out]      key                Pointer to the buffer to receive generated key.
+     403                 :            :  * @param[in, out]  key_size            On input, the size of key buffer in bytes.
+     404                 :            :  *                                    On output, the size of data returned in key buffer in bytes.
+     405                 :            :  *
+     406                 :            :  * @retval true   EC exchanged key generation succeeded.
+     407                 :            :  * @retval false  EC exchanged key generation failed.
+     408                 :            :  * @retval false  key_size is not large enough.
+     409                 :            :  *
+     410                 :            :  **/
+     411                 :         74 : bool libspdm_ec_compute_key(void *ec_context, const uint8_t *peer_public,
+     412                 :            :                             size_t peer_public_size, uint8_t *key,
+     413                 :            :                             size_t *key_size)
+     414                 :            : {
+     415                 :            :     mbedtls_ecdh_context *ctx;
+     416                 :            :     size_t half_size;
+     417                 :            :     int ret;
+     418                 :            : 
+     419   [ +  -  +  -  :         74 :     if (ec_context == NULL || peer_public == NULL || key_size == NULL ||
+             +  -  -  + ]
+     420                 :            :         key == NULL) {
+     421                 :          0 :         return false;
+     422                 :            :     }
+     423                 :            : 
+     424         [ -  + ]:         74 :     if (peer_public_size > INT_MAX) {
+     425                 :          0 :         return false;
+     426                 :            :     }
+     427                 :            : 
+     428                 :         74 :     ctx = ec_context;
+     429   [ +  -  -  - ]:         74 :     switch (mbedtls_ecdh_get_grp_id(ctx)) {
+     430                 :         74 :     case MBEDTLS_ECP_DP_SECP256R1:
+     431                 :         74 :         half_size = 32;
+     432                 :         74 :         break;
+     433                 :          0 :     case MBEDTLS_ECP_DP_SECP384R1:
+     434                 :          0 :         half_size = 48;
+     435                 :          0 :         break;
+     436                 :          0 :     case MBEDTLS_ECP_DP_SECP521R1:
+     437                 :          0 :         half_size = 66;
+     438                 :          0 :         break;
+     439                 :          0 :     default:
+     440                 :          0 :         return false;
+     441                 :            :     }
+     442         [ -  + ]:         74 :     if (peer_public_size != half_size * 2) {
+     443                 :          0 :         return false;
+     444                 :            :     }
+     445                 :            : 
+     446                 :         74 :     ret = mbedtls_mpi_read_binary(&ctx->MBEDTLS_PRIVATE(Qp).MBEDTLS_PRIVATE(X),
+     447                 :            :                                   peer_public, half_size);
+     448         [ -  + ]:         74 :     if (ret != 0) {
+     449                 :          0 :         return false;
+     450                 :            :     }
+     451                 :         74 :     ret = mbedtls_mpi_read_binary(&ctx->MBEDTLS_PRIVATE(Qp).MBEDTLS_PRIVATE(Y),
+     452                 :         74 :                                   peer_public + half_size, half_size);
+     453         [ -  + ]:         74 :     if (ret != 0) {
+     454                 :          0 :         return false;
+     455                 :            :     }
+     456                 :         74 :     ret = mbedtls_mpi_lset(&ctx->MBEDTLS_PRIVATE(Qp).MBEDTLS_PRIVATE(Z), 1);
+     457         [ -  + ]:         74 :     if (ret != 0) {
+     458                 :          0 :         return false;
+     459                 :            :     }
+     460                 :            : 
+     461                 :         74 :     ret = mbedtls_ecdh_compute_shared(&ctx->MBEDTLS_PRIVATE(grp),
+     462                 :            :                                       &ctx->MBEDTLS_PRIVATE(z),
+     463                 :         74 :                                       &ctx->MBEDTLS_PRIVATE(Qp),
+     464                 :         74 :                                       &ctx->MBEDTLS_PRIVATE(d),
+     465                 :            :                                       libspdm_myrand, NULL);
+     466         [ -  + ]:         74 :     if (ret != 0) {
+     467                 :          0 :         return false;
+     468                 :            :     }
+     469                 :            : 
+     470         [ -  + ]:         74 :     if (mbedtls_mpi_size(&ctx->MBEDTLS_PRIVATE(z)) > *key_size) {
+     471                 :          0 :         return false;
+     472                 :            :     }
+     473                 :            : 
+     474                 :         74 :     *key_size = ctx->MBEDTLS_PRIVATE(grp).pbits / 8 +
+     475                 :         74 :                 ((ctx->MBEDTLS_PRIVATE(grp).pbits % 8) != 0);
+     476                 :         74 :     ret = mbedtls_mpi_write_binary(&ctx->MBEDTLS_PRIVATE(z), key, *key_size);
+     477         [ -  + ]:         74 :     if (ret != 0) {
+     478                 :          0 :         return false;
+     479                 :            :     }
+     480                 :            : 
+     481                 :         74 :     return true;
+     482                 :            : }
+     483                 :            : 
+     484                 :            : /**
+     485                 :            :  * Carries out the EC-DSA signature.
+     486                 :            :  *
+     487                 :            :  * This function carries out the EC-DSA signature.
+     488                 :            :  * If the signature buffer is too small to hold the contents of signature, false
+     489                 :            :  * is returned and sig_size is set to the required buffer size to obtain the signature.
+     490                 :            :  *
+     491                 :            :  * If ec_context is NULL, then return false.
+     492                 :            :  * If message_hash is NULL, then return false.
+     493                 :            :  * If hash_size need match the hash_nid. hash_nid could be SHA256, SHA384, SHA512, SHA3_256, SHA3_384, SHA3_512.
+     494                 :            :  * If sig_size is large enough but signature is NULL, then return false.
+     495                 :            :  *
+     496                 :            :  * For P-256, the sig_size is 64. first 32-byte is R, second 32-byte is S.
+     497                 :            :  * For P-384, the sig_size is 96. first 48-byte is R, second 48-byte is S.
+     498                 :            :  * For P-521, the sig_size is 132. first 66-byte is R, second 66-byte is S.
+     499                 :            :  *
+     500                 :            :  * @param[in]       ec_context    Pointer to EC context for signature generation.
+     501                 :            :  * @param[in]       hash_nid      hash NID
+     502                 :            :  * @param[in]       message_hash  Pointer to octet message hash to be signed.
+     503                 :            :  * @param[in]       hash_size     size of the message hash in bytes.
+     504                 :            :  * @param[out]      signature    Pointer to buffer to receive EC-DSA signature.
+     505                 :            :  * @param[in, out]  sig_size      On input, the size of signature buffer in bytes.
+     506                 :            :  *                              On output, the size of data returned in signature buffer in bytes.
+     507                 :            :  *
+     508                 :            :  * @retval  true   signature successfully generated in EC-DSA.
+     509                 :            :  * @retval  false  signature generation failed.
+     510                 :            :  * @retval  false  sig_size is too small.
+     511                 :            :  *
+     512                 :            :  **/
+     513                 :        123 : bool libspdm_ecdsa_sign(void *ec_context, size_t hash_nid,
+     514                 :            :                         const uint8_t *message_hash, size_t hash_size,
+     515                 :            :                         uint8_t *signature, size_t *sig_size)
+     516                 :            : {
+     517                 :            :     int ret;
+     518                 :            :     mbedtls_ecdh_context *ctx;
+     519                 :            :     mbedtls_mpi bn_r;
+     520                 :            :     mbedtls_mpi bn_s;
+     521                 :            :     size_t r_size;
+     522                 :            :     size_t s_size;
+     523                 :            :     size_t half_size;
+     524                 :            : 
+     525   [ +  -  -  + ]:        123 :     if (ec_context == NULL || message_hash == NULL) {
+     526                 :          0 :         return false;
+     527                 :            :     }
+     528                 :            : 
+     529         [ -  + ]:        123 :     if (signature == NULL) {
+     530                 :          0 :         return false;
+     531                 :            :     }
+     532                 :            : 
+     533                 :        123 :     ctx = ec_context;
+     534   [ +  -  -  - ]:        123 :     switch (mbedtls_ecdh_get_grp_id(ctx)) {
+     535                 :        123 :     case MBEDTLS_ECP_DP_SECP256R1:
+     536                 :        123 :         half_size = 32;
+     537                 :        123 :         break;
+     538                 :          0 :     case MBEDTLS_ECP_DP_SECP384R1:
+     539                 :          0 :         half_size = 48;
+     540                 :          0 :         break;
+     541                 :          0 :     case MBEDTLS_ECP_DP_SECP521R1:
+     542                 :          0 :         half_size = 66;
+     543                 :          0 :         break;
+     544                 :          0 :     default:
+     545                 :          0 :         return false;
+     546                 :            :     }
+     547         [ -  + ]:        123 :     if (*sig_size < (size_t)(half_size * 2)) {
+     548                 :          0 :         *sig_size = half_size * 2;
+     549                 :          0 :         return false;
+     550                 :            :     }
+     551                 :        123 :     *sig_size = half_size * 2;
+     552                 :        123 :     libspdm_zero_mem(signature, *sig_size);
+     553                 :            : 
+     554   [ +  -  -  - ]:        123 :     switch (hash_nid) {
+     555                 :        123 :     case LIBSPDM_CRYPTO_NID_SHA256:
+     556         [ -  + ]:        123 :         if (hash_size != LIBSPDM_SHA256_DIGEST_SIZE) {
+     557                 :          0 :             return false;
+     558                 :            :         }
+     559                 :        123 :         break;
+     560                 :            : 
+     561                 :          0 :     case LIBSPDM_CRYPTO_NID_SHA384:
+     562         [ #  # ]:          0 :         if (hash_size != LIBSPDM_SHA384_DIGEST_SIZE) {
+     563                 :          0 :             return false;
+     564                 :            :         }
+     565                 :          0 :         break;
+     566                 :            : 
+     567                 :          0 :     case LIBSPDM_CRYPTO_NID_SHA512:
+     568         [ #  # ]:          0 :         if (hash_size != LIBSPDM_SHA512_DIGEST_SIZE) {
+     569                 :          0 :             return false;
+     570                 :            :         }
+     571                 :          0 :         break;
+     572                 :            : 
+     573                 :          0 :     default:
+     574                 :          0 :         return false;
+     575                 :            :     }
+     576                 :            : 
+     577                 :        123 :     mbedtls_mpi_init(&bn_r);
+     578                 :        123 :     mbedtls_mpi_init(&bn_s);
+     579                 :            : 
+     580                 :        123 :     ret = mbedtls_ecdsa_sign(&ctx->MBEDTLS_PRIVATE(grp), &bn_r, &bn_s,
+     581                 :        123 :                              &ctx->MBEDTLS_PRIVATE(d), message_hash,
+     582                 :            :                              hash_size, libspdm_myrand, NULL);
+     583         [ -  + ]:        123 :     if (ret != 0) {
+     584                 :          0 :         return false;
+     585                 :            :     }
+     586                 :            : 
+     587                 :        123 :     r_size = mbedtls_mpi_size(&bn_r);
+     588                 :        123 :     s_size = mbedtls_mpi_size(&bn_s);
+     589   [ +  -  -  + ]:        123 :     LIBSPDM_ASSERT(r_size <= half_size && s_size <= half_size);
+     590                 :            : 
+     591                 :        123 :     ret = mbedtls_mpi_write_binary(
+     592                 :        123 :         &bn_r, &signature[0 + half_size - r_size], r_size);
+     593         [ -  + ]:        123 :     if (ret != 0) {
+     594                 :          0 :         mbedtls_mpi_free(&bn_r);
+     595                 :          0 :         mbedtls_mpi_free(&bn_s);
+     596                 :          0 :         return false;
+     597                 :            :     }
+     598                 :        123 :     ret = mbedtls_mpi_write_binary(
+     599                 :        123 :         &bn_s, &signature[half_size + half_size - s_size], s_size);
+     600         [ -  + ]:        123 :     if (ret != 0) {
+     601                 :          0 :         mbedtls_mpi_free(&bn_r);
+     602                 :          0 :         mbedtls_mpi_free(&bn_s);
+     603                 :          0 :         return false;
+     604                 :            :     }
+     605                 :            : 
+     606                 :        123 :     mbedtls_mpi_free(&bn_r);
+     607                 :        123 :     mbedtls_mpi_free(&bn_s);
+     608                 :            : 
+     609                 :        123 :     return true;
+     610                 :            : }
+     611                 :            : 
+     612                 :            : /**
+     613                 :            :  * Verifies the EC-DSA signature.
+     614                 :            :  *
+     615                 :            :  * If ec_context is NULL, then return false.
+     616                 :            :  * If message_hash is NULL, then return false.
+     617                 :            :  * If signature is NULL, then return false.
+     618                 :            :  * If hash_size need match the hash_nid. hash_nid could be SHA256, SHA384, SHA512, SHA3_256, SHA3_384, SHA3_512.
+     619                 :            :  *
+     620                 :            :  * For P-256, the sig_size is 64. first 32-byte is R, second 32-byte is S.
+     621                 :            :  * For P-384, the sig_size is 96. first 48-byte is R, second 48-byte is S.
+     622                 :            :  * For P-521, the sig_size is 132. first 66-byte is R, second 66-byte is S.
+     623                 :            :  *
+     624                 :            :  * @param[in]  ec_context    Pointer to EC context for signature verification.
+     625                 :            :  * @param[in]  hash_nid      hash NID
+     626                 :            :  * @param[in]  message_hash  Pointer to octet message hash to be checked.
+     627                 :            :  * @param[in]  hash_size     size of the message hash in bytes.
+     628                 :            :  * @param[in]  signature    Pointer to EC-DSA signature to be verified.
+     629                 :            :  * @param[in]  sig_size      size of signature in bytes.
+     630                 :            :  *
+     631                 :            :  * @retval  true   Valid signature encoded in EC-DSA.
+     632                 :            :  * @retval  false  Invalid signature or invalid EC context.
+     633                 :            :  *
+     634                 :            :  **/
+     635                 :         70 : bool libspdm_ecdsa_verify(void *ec_context, size_t hash_nid,
+     636                 :            :                           const uint8_t *message_hash, size_t hash_size,
+     637                 :            :                           const uint8_t *signature, size_t sig_size)
+     638                 :            : {
+     639                 :            :     int ret;
+     640                 :            :     mbedtls_ecdh_context *ctx;
+     641                 :            :     mbedtls_mpi bn_r;
+     642                 :            :     mbedtls_mpi bn_s;
+     643                 :            :     size_t half_size;
+     644                 :            : 
+     645   [ +  -  +  -  :         70 :     if (ec_context == NULL || message_hash == NULL || signature == NULL) {
+                   -  + ]
+     646                 :          0 :         return false;
+     647                 :            :     }
+     648                 :            : 
+     649   [ +  -  -  + ]:         70 :     if (sig_size > INT_MAX || sig_size == 0) {
+     650                 :          0 :         return false;
+     651                 :            :     }
+     652                 :            : 
+     653                 :         70 :     ctx = ec_context;
+     654   [ +  -  -  - ]:         70 :     switch (mbedtls_ecdh_get_grp_id(ctx)) {
+     655                 :         70 :     case MBEDTLS_ECP_DP_SECP256R1:
+     656                 :         70 :         half_size = 32;
+     657                 :         70 :         break;
+     658                 :          0 :     case MBEDTLS_ECP_DP_SECP384R1:
+     659                 :          0 :         half_size = 48;
+     660                 :          0 :         break;
+     661                 :          0 :     case MBEDTLS_ECP_DP_SECP521R1:
+     662                 :          0 :         half_size = 66;
+     663                 :          0 :         break;
+     664                 :          0 :     default:
+     665                 :          0 :         return false;
+     666                 :            :     }
+     667         [ -  + ]:         70 :     if (sig_size != (size_t)(half_size * 2)) {
+     668                 :          0 :         return false;
+     669                 :            :     }
+     670                 :            : 
+     671   [ +  -  -  - ]:         70 :     switch (hash_nid) {
+     672                 :         70 :     case LIBSPDM_CRYPTO_NID_SHA256:
+     673         [ -  + ]:         70 :         if (hash_size != LIBSPDM_SHA256_DIGEST_SIZE) {
+     674                 :          0 :             return false;
+     675                 :            :         }
+     676                 :         70 :         break;
+     677                 :            : 
+     678                 :          0 :     case LIBSPDM_CRYPTO_NID_SHA384:
+     679         [ #  # ]:          0 :         if (hash_size != LIBSPDM_SHA384_DIGEST_SIZE) {
+     680                 :          0 :             return false;
+     681                 :            :         }
+     682                 :          0 :         break;
+     683                 :            : 
+     684                 :          0 :     case LIBSPDM_CRYPTO_NID_SHA512:
+     685         [ #  # ]:          0 :         if (hash_size != LIBSPDM_SHA512_DIGEST_SIZE) {
+     686                 :          0 :             return false;
+     687                 :            :         }
+     688                 :          0 :         break;
+     689                 :            : 
+     690                 :          0 :     default:
+     691                 :          0 :         return false;
+     692                 :            :     }
+     693                 :            : 
+     694                 :         70 :     mbedtls_mpi_init(&bn_r);
+     695                 :         70 :     mbedtls_mpi_init(&bn_s);
+     696                 :            : 
+     697                 :         70 :     ret = mbedtls_mpi_read_binary(&bn_r, signature, half_size);
+     698         [ -  + ]:         70 :     if (ret != 0) {
+     699                 :          0 :         mbedtls_mpi_free(&bn_r);
+     700                 :          0 :         mbedtls_mpi_free(&bn_s);
+     701                 :          0 :         return false;
+     702                 :            :     }
+     703                 :         70 :     ret = mbedtls_mpi_read_binary(&bn_s, signature + half_size, half_size);
+     704         [ -  + ]:         70 :     if (ret != 0) {
+     705                 :          0 :         mbedtls_mpi_free(&bn_r);
+     706                 :          0 :         mbedtls_mpi_free(&bn_s);
+     707                 :          0 :         return false;
+     708                 :            :     }
+     709                 :            : 
+     710                 :         70 :     ret = mbedtls_ecdsa_verify(&ctx->MBEDTLS_PRIVATE(grp), message_hash,
+     711                 :         70 :                                hash_size, &ctx->MBEDTLS_PRIVATE(Q),
+     712                 :            :                                &bn_r, &bn_s);
+     713                 :         70 :     mbedtls_mpi_free(&bn_r);
+     714                 :         70 :     mbedtls_mpi_free(&bn_s);
+     715                 :            : 
+     716         [ +  + ]:         70 :     if (ret != 0) {
+     717                 :         15 :         return false;
+     718                 :            :     }
+     719                 :            : 
+     720                 :         55 :     return true;
+     721                 :            : }
+     722                 :            : 
+     723                 :            : #if LIBSPDM_FIPS_MODE
+     724                 :            : /**
+     725                 :            :  * Carries out the EC-DSA signature with caller input random function. This API can be used for FIPS test.
+     726                 :            :  *
+     727                 :            :  * @param[in]       ec_context    Pointer to EC context for signature generation.
+     728                 :            :  * @param[in]       hash_nid      hash NID
+     729                 :            :  * @param[in]       message_hash  Pointer to octet message hash to be signed.
+     730                 :            :  * @param[in]       hash_size     Size of the message hash in bytes.
+     731                 :            :  * @param[out]      signature     Pointer to buffer to receive EC-DSA signature.
+     732                 :            :  * @param[in, out]  sig_size      On input, the size of signature buffer in bytes.
+     733                 :            :  *                                On output, the size of data returned in signature buffer in bytes.
+     734                 :            :  * @param[in]       random_func   random number function
+     735                 :            :  *
+     736                 :            :  * @retval  true   signature successfully generated in EC-DSA.
+     737                 :            :  * @retval  false  signature generation failed.
+     738                 :            :  * @retval  false  sig_size is too small.
+     739                 :            :  **/
+     740                 :          1 : bool libspdm_ecdsa_sign_ex(void *ec_context, size_t hash_nid,
+     741                 :            :                            const uint8_t *message_hash, size_t hash_size,
+     742                 :            :                            uint8_t *signature, size_t *sig_size,
+     743                 :            :                            int (*random_func)(void *, unsigned char *, size_t))
+     744                 :            : {
+     745                 :            :     int ret;
+     746                 :            :     mbedtls_ecdh_context *ctx;
+     747                 :            :     mbedtls_mpi bn_r;
+     748                 :            :     mbedtls_mpi bn_s;
+     749                 :            :     size_t r_size;
+     750                 :            :     size_t s_size;
+     751                 :            :     size_t half_size;
+     752                 :            : 
+     753   [ +  -  -  + ]:          1 :     if (ec_context == NULL || message_hash == NULL) {
+     754                 :          0 :         return false;
+     755                 :            :     }
+     756                 :            : 
+     757         [ -  + ]:          1 :     if (signature == NULL) {
+     758                 :          0 :         return false;
+     759                 :            :     }
+     760                 :            : 
+     761                 :          1 :     ctx = ec_context;
+     762   [ +  -  -  - ]:          1 :     switch (mbedtls_ecdh_get_grp_id(ctx)) {
+     763                 :          1 :     case MBEDTLS_ECP_DP_SECP256R1:
+     764                 :          1 :         half_size = 32;
+     765                 :          1 :         break;
+     766                 :          0 :     case MBEDTLS_ECP_DP_SECP384R1:
+     767                 :          0 :         half_size = 48;
+     768                 :          0 :         break;
+     769                 :          0 :     case MBEDTLS_ECP_DP_SECP521R1:
+     770                 :          0 :         half_size = 66;
+     771                 :          0 :         break;
+     772                 :          0 :     default:
+     773                 :          0 :         return false;
+     774                 :            :     }
+     775         [ -  + ]:          1 :     if (*sig_size < (size_t)(half_size * 2)) {
+     776                 :          0 :         *sig_size = half_size * 2;
+     777                 :          0 :         return false;
+     778                 :            :     }
+     779                 :          1 :     *sig_size = half_size * 2;
+     780                 :          1 :     libspdm_zero_mem(signature, *sig_size);
+     781                 :            : 
+     782   [ +  -  -  - ]:          1 :     switch (hash_nid) {
+     783                 :          1 :     case LIBSPDM_CRYPTO_NID_SHA256:
+     784         [ -  + ]:          1 :         if (hash_size != LIBSPDM_SHA256_DIGEST_SIZE) {
+     785                 :          0 :             return false;
+     786                 :            :         }
+     787                 :          1 :         break;
+     788                 :            : 
+     789                 :          0 :     case LIBSPDM_CRYPTO_NID_SHA384:
+     790         [ #  # ]:          0 :         if (hash_size != LIBSPDM_SHA384_DIGEST_SIZE) {
+     791                 :          0 :             return false;
+     792                 :            :         }
+     793                 :          0 :         break;
+     794                 :            : 
+     795                 :          0 :     case LIBSPDM_CRYPTO_NID_SHA512:
+     796         [ #  # ]:          0 :         if (hash_size != LIBSPDM_SHA512_DIGEST_SIZE) {
+     797                 :          0 :             return false;
+     798                 :            :         }
+     799                 :          0 :         break;
+     800                 :            : 
+     801                 :          0 :     default:
+     802                 :          0 :         return false;
+     803                 :            :     }
+     804                 :            : 
+     805                 :          1 :     mbedtls_mpi_init(&bn_r);
+     806                 :          1 :     mbedtls_mpi_init(&bn_s);
+     807                 :            : 
+     808                 :            :     /*retrieve random number*/
+     809                 :          1 :     ret = mbedtls_ecdsa_sign(&ctx->MBEDTLS_PRIVATE(grp), &bn_r, &bn_s,
+     810                 :          1 :                              &ctx->MBEDTLS_PRIVATE(d), message_hash,
+     811                 :            :                              hash_size, random_func, NULL);
+     812         [ -  + ]:          1 :     if (ret != 0) {
+     813                 :          0 :         return false;
+     814                 :            :     }
+     815                 :            : 
+     816                 :          1 :     r_size = mbedtls_mpi_size(&bn_r);
+     817                 :          1 :     s_size = mbedtls_mpi_size(&bn_s);
+     818   [ +  -  -  + ]:          1 :     LIBSPDM_ASSERT(r_size <= half_size && s_size <= half_size);
+     819                 :            : 
+     820                 :          1 :     ret = mbedtls_mpi_write_binary(
+     821                 :          1 :         &bn_r, &signature[0 + half_size - r_size], r_size);
+     822         [ -  + ]:          1 :     if (ret != 0) {
+     823                 :          0 :         mbedtls_mpi_free(&bn_r);
+     824                 :          0 :         mbedtls_mpi_free(&bn_s);
+     825                 :          0 :         return false;
+     826                 :            :     }
+     827                 :          1 :     ret = mbedtls_mpi_write_binary(
+     828                 :          1 :         &bn_s, &signature[half_size + half_size - s_size], s_size);
+     829         [ -  + ]:          1 :     if (ret != 0) {
+     830                 :          0 :         mbedtls_mpi_free(&bn_r);
+     831                 :          0 :         mbedtls_mpi_free(&bn_s);
+     832                 :          0 :         return false;
+     833                 :            :     }
+     834                 :            : 
+     835                 :          1 :     mbedtls_mpi_free(&bn_r);
+     836                 :          1 :     mbedtls_mpi_free(&bn_s);
+     837                 :            : 
+     838                 :          1 :     return true;
+     839                 :            : }
+     840                 :            : #endif/*LIBSPDM_FIPS_MODE*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/pk/index-sort-b.html b/coverage_log/os_stub/cryptlib_mbedtls/pk/index-sort-b.html new file mode 100644 index 00000000000..282951f8643 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/pk/index-sort-b.html @@ -0,0 +1,155 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/pk + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/pkHitTotalCoverage
Test:coverage.infoLines:754148450.8 %
Date:2024-09-22 08:21:07Functions:456866.2 %
Branches:31184636.8 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
rsa_ext.c +
18.3%18.3%
+
18.3 %35 / 19142.9 %3 / 715.3 %17 / 111
rsa_basic.c +
43.0%43.0%
+
43.0 %61 / 14283.3 %5 / 631.2 %30 / 96
dh.c +
46.2%46.2%
+
46.2 %49 / 10666.7 %4 / 636.2 %21 / 58
ec.c +
48.3%48.3%
+
48.3 %181 / 37581.8 %9 / 1136.4 %75 / 206
x509.c +
63.9%63.9%
+
63.9 %428 / 67063.2 %24 / 3844.8 %168 / 375
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/pk/index-sort-f.html b/coverage_log/os_stub/cryptlib_mbedtls/pk/index-sort-f.html new file mode 100644 index 00000000000..dc4dffcf63d --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/pk/index-sort-f.html @@ -0,0 +1,155 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/pk + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/pkHitTotalCoverage
Test:coverage.infoLines:754148450.8 %
Date:2024-09-22 08:21:07Functions:456866.2 %
Branches:31184636.8 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
rsa_ext.c +
18.3%18.3%
+
18.3 %35 / 19142.9 %3 / 715.3 %17 / 111
x509.c +
63.9%63.9%
+
63.9 %428 / 67063.2 %24 / 3844.8 %168 / 375
dh.c +
46.2%46.2%
+
46.2 %49 / 10666.7 %4 / 636.2 %21 / 58
ec.c +
48.3%48.3%
+
48.3 %181 / 37581.8 %9 / 1136.4 %75 / 206
rsa_basic.c +
43.0%43.0%
+
43.0 %61 / 14283.3 %5 / 631.2 %30 / 96
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/pk/index-sort-l.html b/coverage_log/os_stub/cryptlib_mbedtls/pk/index-sort-l.html new file mode 100644 index 00000000000..04bcaae26a0 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/pk/index-sort-l.html @@ -0,0 +1,155 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/pk + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/pkHitTotalCoverage
Test:coverage.infoLines:754148450.8 %
Date:2024-09-22 08:21:07Functions:456866.2 %
Branches:31184636.8 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
rsa_ext.c +
18.3%18.3%
+
18.3 %35 / 19142.9 %3 / 715.3 %17 / 111
rsa_basic.c +
43.0%43.0%
+
43.0 %61 / 14283.3 %5 / 631.2 %30 / 96
dh.c +
46.2%46.2%
+
46.2 %49 / 10666.7 %4 / 636.2 %21 / 58
ec.c +
48.3%48.3%
+
48.3 %181 / 37581.8 %9 / 1136.4 %75 / 206
x509.c +
63.9%63.9%
+
63.9 %428 / 67063.2 %24 / 3844.8 %168 / 375
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/pk/index.html b/coverage_log/os_stub/cryptlib_mbedtls/pk/index.html new file mode 100644 index 00000000000..a5be07006f6 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/pk/index.html @@ -0,0 +1,155 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/pk + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/pkHitTotalCoverage
Test:coverage.infoLines:754148450.8 %
Date:2024-09-22 08:21:07Functions:456866.2 %
Branches:31184636.8 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
dh.c +
46.2%46.2%
+
46.2 %49 / 10666.7 %4 / 636.2 %21 / 58
ec.c +
48.3%48.3%
+
48.3 %181 / 37581.8 %9 / 1136.4 %75 / 206
rsa_basic.c +
43.0%43.0%
+
43.0 %61 / 14283.3 %5 / 631.2 %30 / 96
rsa_ext.c +
18.3%18.3%
+
18.3 %35 / 19142.9 %3 / 715.3 %17 / 111
x509.c +
63.9%63.9%
+
63.9 %428 / 67063.2 %24 / 3844.8 %168 / 375
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/pk/rsa_basic.c.func-sort-c.html b/coverage_log/os_stub/cryptlib_mbedtls/pk/rsa_basic.c.func-sort-c.html new file mode 100644 index 00000000000..d244b86884e --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/pk/rsa_basic.c.func-sort-c.html @@ -0,0 +1,105 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/pk/rsa_basic.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/pk - rsa_basic.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:6114243.0 %
Date:2024-09-22 08:21:07Functions:5683.3 %
Branches:309631.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_rsa_pss_verify0
libspdm_rsa_pss_verify_fips1
libspdm_rsa_set_key6
libspdm_rsa_pkcs1_verify_with_nid22
libspdm_rsa_free78
libspdm_rsa_new91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/pk/rsa_basic.c.func.html b/coverage_log/os_stub/cryptlib_mbedtls/pk/rsa_basic.c.func.html new file mode 100644 index 00000000000..71e8b4d2978 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/pk/rsa_basic.c.func.html @@ -0,0 +1,105 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/pk/rsa_basic.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/pk - rsa_basic.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:6114243.0 %
Date:2024-09-22 08:21:07Functions:5683.3 %
Branches:309631.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_rsa_free78
libspdm_rsa_new91
libspdm_rsa_pkcs1_verify_with_nid22
libspdm_rsa_pss_verify0
libspdm_rsa_pss_verify_fips1
libspdm_rsa_set_key6
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/pk/rsa_basic.c.gcov.html b/coverage_log/os_stub/cryptlib_mbedtls/pk/rsa_basic.c.gcov.html new file mode 100644 index 00000000000..6d0f37e7510 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/pk/rsa_basic.c.gcov.html @@ -0,0 +1,492 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/pk/rsa_basic.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/pk - rsa_basic.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:6114243.0 %
Date:2024-09-22 08:21:07Functions:5683.3 %
Branches:309631.2 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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                 :            : /** @file
+       8                 :            :  * RSA Asymmetric Cipher Wrapper Implementation.
+       9                 :            :  *
+      10                 :            :  * This file implements following APIs which provide basic capabilities for RSA:
+      11                 :            :  * 1) libspdm_rsa_new
+      12                 :            :  * 2) libspdm_rsa_free
+      13                 :            :  * 3) libspdm_rsa_set_key
+      14                 :            :  * 4) rsa_pkcs1_verify
+      15                 :            :  *
+      16                 :            :  * RFC 8017 - PKCS #1: RSA Cryptography Specifications version 2.2
+      17                 :            :  **/
+      18                 :            : 
+      19                 :            : #include "internal_crypt_lib.h"
+      20                 :            : 
+      21                 :            : #include <mbedtls/rsa.h>
+      22                 :            : 
+      23                 :            : #if (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT)
+      24                 :            : /**
+      25                 :            :  * Allocates and initializes one RSA context for subsequent use.
+      26                 :            :  *
+      27                 :            :  * @return  Pointer to the RSA context that has been initialized.
+      28                 :            :  *         If the allocations fails, libspdm_rsa_new() returns NULL.
+      29                 :            :  *
+      30                 :            :  **/
+      31                 :         91 : void *libspdm_rsa_new(void)
+      32                 :            : {
+      33                 :            :     void *rsa_context;
+      34                 :            : 
+      35                 :         91 :     rsa_context = allocate_zero_pool(sizeof(mbedtls_rsa_context));
+      36         [ -  + ]:         91 :     if (rsa_context == NULL) {
+      37                 :          0 :         return rsa_context;
+      38                 :            :     }
+      39                 :            : 
+      40                 :         91 :     mbedtls_rsa_init(rsa_context);
+      41                 :            : 
+      42                 :         91 :     return rsa_context;
+      43                 :            : }
+      44                 :            : 
+      45                 :            : /**
+      46                 :            :  * Release the specified RSA context.
+      47                 :            :  *
+      48                 :            :  * @param[in]  rsa_context  Pointer to the RSA context to be released.
+      49                 :            :  *
+      50                 :            :  **/
+      51                 :         78 : void libspdm_rsa_free(void *rsa_context)
+      52                 :            : {
+      53                 :         78 :     mbedtls_rsa_free(rsa_context);
+      54                 :         78 :     free_pool(rsa_context);
+      55                 :         78 : }
+      56                 :            : 
+      57                 :            : /**
+      58                 :            :  * Sets the tag-designated key component into the established RSA context.
+      59                 :            :  *
+      60                 :            :  * This function sets the tag-designated RSA key component into the established
+      61                 :            :  * RSA context from the user-specified non-negative integer (octet string format
+      62                 :            :  * represented in RSA PKCS#1).
+      63                 :            :  * If big_number is NULL, then the specified key component in RSA context is cleared.
+      64                 :            :  *
+      65                 :            :  * If rsa_context is NULL, then return false.
+      66                 :            :  *
+      67                 :            :  * @param[in, out]  rsa_context  Pointer to RSA context being set.
+      68                 :            :  * @param[in]       key_tag      tag of RSA key component being set.
+      69                 :            :  * @param[in]       big_number   Pointer to octet integer buffer.
+      70                 :            :  *                             If NULL, then the specified key component in RSA
+      71                 :            :  *                             context is cleared.
+      72                 :            :  * @param[in]       bn_size      size of big number buffer in bytes.
+      73                 :            :  *                             If big_number is NULL, then it is ignored.
+      74                 :            :  *
+      75                 :            :  * @retval  true   RSA key component was set successfully.
+      76                 :            :  * @retval  false  Invalid RSA key component tag.
+      77                 :            :  *
+      78                 :            :  **/
+      79                 :          6 : bool libspdm_rsa_set_key(void *rsa_context, const libspdm_rsa_key_tag_t key_tag,
+      80                 :            :                          const uint8_t *big_number, size_t bn_size)
+      81                 :            : {
+      82                 :            :     mbedtls_rsa_context *rsa_key;
+      83                 :            :     int ret;
+      84                 :            :     mbedtls_mpi value;
+      85                 :            : 
+      86                 :            : 
+      87                 :            :     /* Check input parameters.*/
+      88                 :            : 
+      89   [ +  -  -  + ]:          6 :     if (rsa_context == NULL || bn_size > INT_MAX) {
+      90                 :          0 :         return false;
+      91                 :            :     }
+      92                 :            : 
+      93                 :          6 :     mbedtls_mpi_init(&value);
+      94                 :            : 
+      95                 :          6 :     rsa_key = (mbedtls_rsa_context *)rsa_context;
+      96                 :            : 
+      97                 :            :     /* if big_number is Null clear*/
+      98         [ +  - ]:          6 :     if (big_number) {
+      99                 :          6 :         ret = mbedtls_mpi_read_binary(&value, big_number, bn_size);
+     100         [ -  + ]:          6 :         if (ret != 0) {
+     101                 :          0 :             mbedtls_mpi_free(&value);
+     102                 :          0 :             return false;
+     103                 :            :         }
+     104                 :            :     }
+     105                 :            : 
+     106   [ +  +  +  -  :          6 :     switch (key_tag) {
+                   -  - ]
+     107                 :          2 :     case LIBSPDM_RSA_KEY_N:
+     108                 :          2 :         ret = mbedtls_rsa_import(rsa_key, &value, NULL, NULL, NULL,
+     109                 :            :                                  NULL);
+     110                 :          2 :         break;
+     111                 :          2 :     case LIBSPDM_RSA_KEY_E:
+     112                 :          2 :         ret = mbedtls_rsa_import(rsa_key, NULL, NULL, NULL, NULL,
+     113                 :            :                                  &value);
+     114                 :          2 :         break;
+     115                 :          2 :     case LIBSPDM_RSA_KEY_D:
+     116                 :          2 :         ret = mbedtls_rsa_import(rsa_key, NULL, NULL, NULL, &value,
+     117                 :            :                                  NULL);
+     118                 :          2 :         break;
+     119                 :          0 :     case LIBSPDM_RSA_KEY_Q:
+     120                 :          0 :         ret = mbedtls_rsa_import(rsa_key, NULL, NULL, &value, NULL,
+     121                 :            :                                  NULL);
+     122                 :          0 :         break;
+     123                 :          0 :     case LIBSPDM_RSA_KEY_P:
+     124                 :          0 :         ret = mbedtls_rsa_import(rsa_key, NULL, &value, NULL, NULL,
+     125                 :            :                                  NULL);
+     126                 :          0 :         break;
+     127                 :          0 :     case LIBSPDM_RSA_KEY_DP:
+     128                 :            :     case LIBSPDM_RSA_KEY_DQ:
+     129                 :            :     case LIBSPDM_RSA_KEY_Q_INV:
+     130                 :            :     default:
+     131                 :          0 :         ret = -1;
+     132                 :          0 :         break;
+     133                 :            :     }
+     134                 :            : 
+     135                 :          6 :     mbedtls_mpi_free(&value);
+     136                 :          6 :     return ret == 0;
+     137                 :            : }
+     138                 :            : #endif /* (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT) */
+     139                 :            : 
+     140                 :            : #if LIBSPDM_RSA_SSA_SUPPORT
+     141                 :            : /**
+     142                 :            :  * Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in
+     143                 :            :  * RSA PKCS#1.
+     144                 :            :  *
+     145                 :            :  * If rsa_context is NULL, then return false.
+     146                 :            :  * If message_hash is NULL, then return false.
+     147                 :            :  * If signature is NULL, then return false.
+     148                 :            :  * If hash_size need match the hash_nid. hash_nid could be SHA256, SHA384, SHA512, SHA3_256, SHA3_384, SHA3_512.
+     149                 :            :  *
+     150                 :            :  * @param[in]  rsa_context   Pointer to RSA context for signature verification.
+     151                 :            :  * @param[in]  hash_nid      hash NID
+     152                 :            :  * @param[in]  message_hash  Pointer to octet message hash to be checked.
+     153                 :            :  * @param[in]  hash_size     size of the message hash in bytes.
+     154                 :            :  * @param[in]  signature    Pointer to RSA PKCS1-v1_5 signature to be verified.
+     155                 :            :  * @param[in]  sig_size      size of signature in bytes.
+     156                 :            :  *
+     157                 :            :  * @retval  true   Valid signature encoded in PKCS1-v1_5.
+     158                 :            :  * @retval  false  Invalid signature or invalid RSA context.
+     159                 :            :  *
+     160                 :            :  **/
+     161                 :         22 : bool libspdm_rsa_pkcs1_verify_with_nid(void *rsa_context, size_t hash_nid,
+     162                 :            :                                        const uint8_t *message_hash,
+     163                 :            :                                        size_t hash_size, const uint8_t *signature,
+     164                 :            :                                        size_t sig_size)
+     165                 :            : {
+     166                 :            :     int ret;
+     167                 :            :     mbedtls_md_type_t md_alg;
+     168                 :            :     mbedtls_rsa_context *rsa_key;
+     169                 :            : 
+     170   [ +  -  +  -  :         22 :     if (rsa_context == NULL || message_hash == NULL || signature == NULL) {
+                   -  + ]
+     171                 :          0 :         return false;
+     172                 :            :     }
+     173                 :            : 
+     174   [ +  -  -  + ]:         22 :     if (sig_size > INT_MAX || sig_size == 0) {
+     175                 :          0 :         return false;
+     176                 :            :     }
+     177                 :            : 
+     178                 :         22 :     rsa_key = (mbedtls_rsa_context *)rsa_context;
+     179         [ -  + ]:         22 :     if (mbedtls_rsa_complete(rsa_key) != 0) {
+     180                 :          0 :         return false;
+     181                 :            :     }
+     182                 :            : 
+     183   [ +  -  -  - ]:         22 :     switch (hash_nid) {
+     184                 :         22 :     case LIBSPDM_CRYPTO_NID_SHA256:
+     185                 :         22 :         md_alg = MBEDTLS_MD_SHA256;
+     186         [ -  + ]:         22 :         if (hash_size != LIBSPDM_SHA256_DIGEST_SIZE) {
+     187                 :          0 :             return false;
+     188                 :            :         }
+     189                 :         22 :         break;
+     190                 :            : 
+     191                 :          0 :     case LIBSPDM_CRYPTO_NID_SHA384:
+     192                 :          0 :         md_alg = MBEDTLS_MD_SHA384;
+     193         [ #  # ]:          0 :         if (hash_size != LIBSPDM_SHA384_DIGEST_SIZE) {
+     194                 :          0 :             return false;
+     195                 :            :         }
+     196                 :          0 :         break;
+     197                 :            : 
+     198                 :          0 :     case LIBSPDM_CRYPTO_NID_SHA512:
+     199                 :          0 :         md_alg = MBEDTLS_MD_SHA512;
+     200         [ #  # ]:          0 :         if (hash_size != LIBSPDM_SHA512_DIGEST_SIZE) {
+     201                 :          0 :             return false;
+     202                 :            :         }
+     203                 :          0 :         break;
+     204                 :            : 
+     205                 :          0 :     default:
+     206                 :          0 :         return false;
+     207                 :            :     }
+     208                 :            : 
+     209         [ -  + ]:         22 :     if (mbedtls_rsa_get_len(rsa_context) != sig_size) {
+     210                 :          0 :         return false;
+     211                 :            :     }
+     212                 :            : 
+     213                 :         22 :     mbedtls_rsa_set_padding(rsa_context, MBEDTLS_RSA_PKCS_V15, md_alg);
+     214                 :            : 
+     215                 :         22 :     ret = mbedtls_rsa_pkcs1_verify(rsa_context, md_alg,
+     216                 :            :                                    (uint32_t)hash_size, message_hash,
+     217                 :            :                                    signature);
+     218         [ +  + ]:         22 :     if (ret != 0) {
+     219                 :          7 :         return false;
+     220                 :            :     }
+     221                 :         15 :     return true;
+     222                 :            : }
+     223                 :            : #endif /* LIBSPDM_RSA_SSA_SUPPORT */
+     224                 :            : 
+     225                 :            : #if LIBSPDM_RSA_PSS_SUPPORT
+     226                 :            : /**
+     227                 :            :  * Verifies the RSA-SSA signature with EMSA-PSS encoding scheme defined in
+     228                 :            :  * RSA PKCS#1 v2.2.
+     229                 :            :  *
+     230                 :            :  * The salt length is same as digest length.
+     231                 :            :  *
+     232                 :            :  * If rsa_context is NULL, then return false.
+     233                 :            :  * If message_hash is NULL, then return false.
+     234                 :            :  * If signature is NULL, then return false.
+     235                 :            :  * If hash_size need match the hash_nid. nid could be SHA256, SHA384, SHA512, SHA3_256, SHA3_384, SHA3_512.
+     236                 :            :  *
+     237                 :            :  * @param[in]  rsa_context   Pointer to RSA context for signature verification.
+     238                 :            :  * @param[in]  hash_nid      hash NID
+     239                 :            :  * @param[in]  message_hash  Pointer to octet message hash to be checked.
+     240                 :            :  * @param[in]  hash_size     size of the message hash in bytes.
+     241                 :            :  * @param[in]  signature    Pointer to RSA-SSA PSS signature to be verified.
+     242                 :            :  * @param[in]  sig_size      size of signature in bytes.
+     243                 :            :  *
+     244                 :            :  * @retval  true   Valid signature encoded in RSA-SSA PSS.
+     245                 :            :  * @retval  false  Invalid signature or invalid RSA context.
+     246                 :            :  *
+     247                 :            :  **/
+     248                 :          0 : bool libspdm_rsa_pss_verify(void *rsa_context, size_t hash_nid,
+     249                 :            :                             const uint8_t *message_hash, size_t hash_size,
+     250                 :            :                             const uint8_t *signature, size_t sig_size)
+     251                 :            : {
+     252                 :            :     int ret;
+     253                 :            :     mbedtls_md_type_t md_alg;
+     254                 :            :     mbedtls_rsa_context *rsa_key;
+     255                 :            : 
+     256   [ #  #  #  #  :          0 :     if (rsa_context == NULL || message_hash == NULL || signature == NULL) {
+                   #  # ]
+     257                 :          0 :         return false;
+     258                 :            :     }
+     259                 :            : 
+     260   [ #  #  #  # ]:          0 :     if (sig_size > INT_MAX || sig_size == 0) {
+     261                 :          0 :         return false;
+     262                 :            :     }
+     263                 :            : 
+     264                 :          0 :     rsa_key = (mbedtls_rsa_context *)rsa_context;
+     265         [ #  # ]:          0 :     if (mbedtls_rsa_complete(rsa_key) != 0) {
+     266                 :          0 :         return false;
+     267                 :            :     }
+     268                 :            : 
+     269   [ #  #  #  # ]:          0 :     switch (hash_nid) {
+     270                 :          0 :     case LIBSPDM_CRYPTO_NID_SHA256:
+     271                 :          0 :         md_alg = MBEDTLS_MD_SHA256;
+     272         [ #  # ]:          0 :         if (hash_size != LIBSPDM_SHA256_DIGEST_SIZE) {
+     273                 :          0 :             return false;
+     274                 :            :         }
+     275                 :          0 :         break;
+     276                 :            : 
+     277                 :          0 :     case LIBSPDM_CRYPTO_NID_SHA384:
+     278                 :          0 :         md_alg = MBEDTLS_MD_SHA384;
+     279         [ #  # ]:          0 :         if (hash_size != LIBSPDM_SHA384_DIGEST_SIZE) {
+     280                 :          0 :             return false;
+     281                 :            :         }
+     282                 :          0 :         break;
+     283                 :            : 
+     284                 :          0 :     case LIBSPDM_CRYPTO_NID_SHA512:
+     285                 :          0 :         md_alg = MBEDTLS_MD_SHA512;
+     286         [ #  # ]:          0 :         if (hash_size != LIBSPDM_SHA512_DIGEST_SIZE) {
+     287                 :          0 :             return false;
+     288                 :            :         }
+     289                 :          0 :         break;
+     290                 :            : 
+     291                 :          0 :     default:
+     292                 :          0 :         return false;
+     293                 :            :     }
+     294                 :            : 
+     295         [ #  # ]:          0 :     if (mbedtls_rsa_get_len(rsa_context) != sig_size) {
+     296                 :          0 :         return false;
+     297                 :            :     }
+     298                 :            : 
+     299                 :          0 :     mbedtls_rsa_set_padding(rsa_context, MBEDTLS_RSA_PKCS_V21, md_alg);
+     300                 :            : 
+     301                 :          0 :     ret = mbedtls_rsa_rsassa_pss_verify(rsa_context, md_alg,
+     302                 :            :                                         (uint32_t)hash_size, message_hash,
+     303                 :            :                                         signature);
+     304         [ #  # ]:          0 :     if (ret != 0) {
+     305                 :          0 :         return false;
+     306                 :            :     }
+     307                 :          0 :     return true;
+     308                 :            : }
+     309                 :            : 
+     310                 :            : #if LIBSPDM_FIPS_MODE
+     311                 :            : /**
+     312                 :            :  * Verifies the RSA-SSA signature with EMSA-PSS encoding scheme defined in
+     313                 :            :  * RSA PKCS#1 v2.2 for FIPS test.
+     314                 :            :  *
+     315                 :            :  * The salt length is zero.
+     316                 :            :  *
+     317                 :            :  * If rsa_context is NULL, then return false.
+     318                 :            :  * If message_hash is NULL, then return false.
+     319                 :            :  * If signature is NULL, then return false.
+     320                 :            :  * If hash_size need match the hash_nid. nid could be SHA256, SHA384, SHA512, SHA3_256, SHA3_384, SHA3_512.
+     321                 :            :  *
+     322                 :            :  * @param[in]  rsa_context   Pointer to RSA context for signature verification.
+     323                 :            :  * @param[in]  hash_nid      hash NID
+     324                 :            :  * @param[in]  message_hash  Pointer to octet message hash to be checked.
+     325                 :            :  * @param[in]  hash_size     size of the message hash in bytes.
+     326                 :            :  * @param[in]  signature    Pointer to RSA-SSA PSS signature to be verified.
+     327                 :            :  * @param[in]  sig_size      size of signature in bytes.
+     328                 :            :  *
+     329                 :            :  * @retval  true   Valid signature encoded in RSA-SSA PSS.
+     330                 :            :  * @retval  false  Invalid signature or invalid RSA context.
+     331                 :            :  *
+     332                 :            :  **/
+     333                 :          1 : bool libspdm_rsa_pss_verify_fips(void *rsa_context, size_t hash_nid,
+     334                 :            :                                  const uint8_t *message_hash, size_t hash_size,
+     335                 :            :                                  const uint8_t *signature, size_t sig_size)
+     336                 :            : {
+     337                 :            :     int ret;
+     338                 :            :     mbedtls_md_type_t md_alg;
+     339                 :            :     mbedtls_rsa_context *rsa_key;
+     340                 :            :     mbedtls_md_type_t mgf1_hash_id;
+     341                 :            : 
+     342   [ +  -  +  -  :          1 :     if (rsa_context == NULL || message_hash == NULL || signature == NULL) {
+                   -  + ]
+     343                 :          0 :         return false;
+     344                 :            :     }
+     345                 :            : 
+     346   [ +  -  -  + ]:          1 :     if (sig_size > INT_MAX || sig_size == 0) {
+     347                 :          0 :         return false;
+     348                 :            :     }
+     349                 :            : 
+     350                 :          1 :     rsa_key = (mbedtls_rsa_context *)rsa_context;
+     351         [ -  + ]:          1 :     if (mbedtls_rsa_complete(rsa_key) != 0) {
+     352                 :          0 :         return false;
+     353                 :            :     }
+     354                 :            : 
+     355   [ +  -  -  - ]:          1 :     switch (hash_nid) {
+     356                 :          1 :     case LIBSPDM_CRYPTO_NID_SHA256:
+     357                 :          1 :         md_alg = MBEDTLS_MD_SHA256;
+     358         [ -  + ]:          1 :         if (hash_size != LIBSPDM_SHA256_DIGEST_SIZE) {
+     359                 :          0 :             return false;
+     360                 :            :         }
+     361                 :          1 :         break;
+     362                 :            : 
+     363                 :          0 :     case LIBSPDM_CRYPTO_NID_SHA384:
+     364                 :          0 :         md_alg = MBEDTLS_MD_SHA384;
+     365         [ #  # ]:          0 :         if (hash_size != LIBSPDM_SHA384_DIGEST_SIZE) {
+     366                 :          0 :             return false;
+     367                 :            :         }
+     368                 :          0 :         break;
+     369                 :            : 
+     370                 :          0 :     case LIBSPDM_CRYPTO_NID_SHA512:
+     371                 :          0 :         md_alg = MBEDTLS_MD_SHA512;
+     372         [ #  # ]:          0 :         if (hash_size != LIBSPDM_SHA512_DIGEST_SIZE) {
+     373                 :          0 :             return false;
+     374                 :            :         }
+     375                 :          0 :         break;
+     376                 :            : 
+     377                 :          0 :     default:
+     378                 :          0 :         return false;
+     379                 :            :     }
+     380                 :            : 
+     381         [ -  + ]:          1 :     if (mbedtls_rsa_get_len(rsa_context) != sig_size) {
+     382                 :          0 :         return false;
+     383                 :            :     }
+     384                 :            : 
+     385                 :          1 :     mbedtls_rsa_set_padding(rsa_context, MBEDTLS_RSA_PKCS_V21, md_alg);
+     386                 :            : 
+     387                 :          2 :     mgf1_hash_id = (rsa_key->MBEDTLS_PRIVATE(hash_id) != MBEDTLS_MD_NONE) ?
+     388         [ +  - ]:          1 :                    (mbedtls_md_type_t) rsa_key->MBEDTLS_PRIVATE(hash_id) : md_alg;
+     389                 :            : 
+     390                 :            :     /*salt len is 0*/
+     391                 :          1 :     ret = mbedtls_rsa_rsassa_pss_verify_ext(rsa_context, md_alg,
+     392                 :            :                                             (uint32_t)hash_size, message_hash,
+     393                 :            :                                             mgf1_hash_id,
+     394                 :            :                                             0,
+     395                 :            :                                             signature);
+     396         [ -  + ]:          1 :     if (ret != 0) {
+     397                 :          0 :         return false;
+     398                 :            :     }
+     399                 :          1 :     return true;
+     400                 :            : }
+     401                 :            : #endif /*LIBSPDM_FIPS_MODE*/
+     402                 :            : 
+     403                 :            : #endif /* LIBSPDM_RSA_PSS_SUPPORT */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/pk/rsa_ext.c.func-sort-c.html b/coverage_log/os_stub/cryptlib_mbedtls/pk/rsa_ext.c.func-sort-c.html new file mode 100644 index 00000000000..ca189f78268 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/pk/rsa_ext.c.func-sort-c.html @@ -0,0 +1,109 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/pk/rsa_ext.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/pk - rsa_ext.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:3519118.3 %
Date:2024-09-22 08:21:07Functions:3742.9 %
Branches:1711115.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_rsa_check_key0
libspdm_rsa_generate_key0
libspdm_rsa_get_key0
libspdm_rsa_pss_sign0
libspdm_rsa_pss_sign_fips1
libspdm_myrand_rsapss_fips5
libspdm_rsa_pkcs1_sign_with_nid26
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/pk/rsa_ext.c.func.html b/coverage_log/os_stub/cryptlib_mbedtls/pk/rsa_ext.c.func.html new file mode 100644 index 00000000000..d82a459bc08 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/pk/rsa_ext.c.func.html @@ -0,0 +1,109 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/pk/rsa_ext.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/pk - rsa_ext.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:3519118.3 %
Date:2024-09-22 08:21:07Functions:3742.9 %
Branches:1711115.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_myrand_rsapss_fips5
libspdm_rsa_check_key0
libspdm_rsa_generate_key0
libspdm_rsa_get_key0
libspdm_rsa_pkcs1_sign_with_nid26
libspdm_rsa_pss_sign0
libspdm_rsa_pss_sign_fips1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/pk/rsa_ext.c.gcov.html b/coverage_log/os_stub/cryptlib_mbedtls/pk/rsa_ext.c.gcov.html new file mode 100644 index 00000000000..473617f5ca4 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/pk/rsa_ext.c.gcov.html @@ -0,0 +1,635 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/pk/rsa_ext.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/pk - rsa_ext.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:3519118.3 %
Date:2024-09-22 08:21:07Functions:3742.9 %
Branches:1711115.3 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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                 :            : /** @file
+       8                 :            :  * RSA Asymmetric Cipher Wrapper Implementation.
+       9                 :            :  *
+      10                 :            :  * This file implements following APIs which provide more capabilities for RSA:
+      11                 :            :  * 1) libspdm_rsa_get_key
+      12                 :            :  * 2) libspdm_rsa_generate_key
+      13                 :            :  * 3) libspdm_rsa_check_key
+      14                 :            :  * 4) rsa_pkcs1_sign
+      15                 :            :  *
+      16                 :            :  * RFC 8017 - PKCS #1: RSA Cryptography Specifications version 2.2
+      17                 :            :  **/
+      18                 :            : 
+      19                 :            : #include "internal_crypt_lib.h"
+      20                 :            : #include <mbedtls/rsa.h>
+      21                 :            : 
+      22                 :            : #if (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT)
+      23                 :            : /**
+      24                 :            :  * Gets the tag-designated RSA key component from the established RSA context.
+      25                 :            :  *
+      26                 :            :  * This function retrieves the tag-designated RSA key component from the
+      27                 :            :  * established RSA context as a non-negative integer (octet string format
+      28                 :            :  * represented in RSA PKCS#1).
+      29                 :            :  * If specified key component has not been set or has been cleared, then returned
+      30                 :            :  * bn_size is set to 0.
+      31                 :            :  * If the big_number buffer is too small to hold the contents of the key, false
+      32                 :            :  * is returned and bn_size is set to the required buffer size to obtain the key.
+      33                 :            :  *
+      34                 :            :  * If rsa_context is NULL, then return false.
+      35                 :            :  * If bn_size is NULL, then return false.
+      36                 :            :  * If bn_size is large enough but big_number is NULL, then return false.
+      37                 :            :  *
+      38                 :            :  * @param[in, out]  rsa_context  Pointer to RSA context being set.
+      39                 :            :  * @param[in]       key_tag      tag of RSA key component being set.
+      40                 :            :  * @param[out]      big_number   Pointer to octet integer buffer.
+      41                 :            :  * @param[in, out]  bn_size      On input, the size of big number buffer in bytes.
+      42                 :            :  *                             On output, the size of data returned in big number buffer in bytes.
+      43                 :            :  *
+      44                 :            :  * @retval  true   RSA key component was retrieved successfully.
+      45                 :            :  * @retval  false  Invalid RSA key component tag.
+      46                 :            :  * @retval  false  bn_size is too small.
+      47                 :            :  *
+      48                 :            :  **/
+      49                 :          0 : bool libspdm_rsa_get_key(void *rsa_context, const libspdm_rsa_key_tag_t key_tag,
+      50                 :            :                          uint8_t *big_number, size_t *bn_size)
+      51                 :            : {
+      52                 :            :     mbedtls_rsa_context *rsa_key;
+      53                 :            :     int ret;
+      54                 :            :     mbedtls_mpi value;
+      55                 :            :     size_t size;
+      56                 :            : 
+      57                 :            : 
+      58                 :            :     /* Check input parameters.*/
+      59                 :            : 
+      60   [ #  #  #  # ]:          0 :     if (rsa_context == NULL || *bn_size > INT_MAX) {
+      61                 :          0 :         return false;
+      62                 :            :     }
+      63                 :            : 
+      64                 :            :     /* Init mbedtls_mpi*/
+      65                 :            : 
+      66                 :          0 :     mbedtls_mpi_init(&value);
+      67                 :          0 :     size = *bn_size;
+      68                 :          0 :     *bn_size = 0;
+      69                 :            : 
+      70                 :          0 :     rsa_key = (mbedtls_rsa_context *)rsa_context;
+      71                 :            : 
+      72   [ #  #  #  #  :          0 :     switch (key_tag) {
+                   #  # ]
+      73                 :          0 :     case LIBSPDM_RSA_KEY_N:
+      74                 :          0 :         ret = mbedtls_rsa_export(rsa_key, &value, NULL, NULL, NULL,
+      75                 :            :                                  NULL);
+      76                 :          0 :         break;
+      77                 :          0 :     case LIBSPDM_RSA_KEY_E:
+      78                 :          0 :         ret = mbedtls_rsa_export(rsa_key, NULL, NULL, NULL, NULL,
+      79                 :            :                                  &value);
+      80                 :          0 :         break;
+      81                 :          0 :     case LIBSPDM_RSA_KEY_D:
+      82                 :          0 :         ret = mbedtls_rsa_export(rsa_key, NULL, NULL, NULL, &value,
+      83                 :            :                                  NULL);
+      84                 :          0 :         break;
+      85                 :          0 :     case LIBSPDM_RSA_KEY_Q:
+      86                 :          0 :         ret = mbedtls_rsa_export(rsa_key, NULL, NULL, &value, NULL,
+      87                 :            :                                  NULL);
+      88                 :          0 :         break;
+      89                 :          0 :     case LIBSPDM_RSA_KEY_P:
+      90                 :          0 :         ret = mbedtls_rsa_export(rsa_key, NULL, &value, NULL, NULL,
+      91                 :            :                                  NULL);
+      92                 :          0 :         break;
+      93                 :          0 :     case LIBSPDM_RSA_KEY_DP:
+      94                 :            :     case LIBSPDM_RSA_KEY_DQ:
+      95                 :            :     case LIBSPDM_RSA_KEY_Q_INV:
+      96                 :            :     default:
+      97                 :          0 :         ret = -1;
+      98                 :          0 :         break;
+      99                 :            :     }
+     100                 :            : 
+     101         [ #  # ]:          0 :     if (ret != 0) {
+     102                 :          0 :         return false;
+     103                 :            :     }
+     104                 :            : 
+     105         [ #  # ]:          0 :     if (!mbedtls_mpi_size(&value)) {
+     106                 :          0 :         ret = 0;
+     107                 :          0 :         goto end;
+     108                 :            :     }
+     109                 :            : 
+     110                 :          0 :     *bn_size = size;
+     111                 :            : 
+     112         [ #  # ]:          0 :     if (ret == 0) {
+     113                 :          0 :         size = mbedtls_mpi_size(&value);
+     114                 :            :     }
+     115         [ #  # ]:          0 :     if (size == 0) {
+     116                 :          0 :         ret = 1;
+     117                 :          0 :         goto end;
+     118                 :            :     }
+     119                 :            : 
+     120         [ #  # ]:          0 :     if (*bn_size < size) {
+     121                 :          0 :         ret = 1;
+     122                 :          0 :         *bn_size = size;
+     123                 :          0 :         goto end;
+     124                 :            :     }
+     125                 :            : 
+     126         [ #  # ]:          0 :     if (big_number == NULL) {
+     127                 :          0 :         ret = 0;
+     128                 :          0 :         *bn_size = size;
+     129                 :          0 :         goto end;
+     130                 :            :     }
+     131                 :            : 
+     132   [ #  #  #  # ]:          0 :     if (big_number != NULL && ret == 0) {
+     133                 :          0 :         ret = mbedtls_mpi_write_binary(&value, big_number, size);
+     134                 :          0 :         *bn_size = size;
+     135                 :            :     }
+     136                 :          0 : end:
+     137                 :          0 :     mbedtls_mpi_free(&value);
+     138                 :          0 :     return ret == 0;
+     139                 :            : }
+     140                 :            : 
+     141                 :            : /**
+     142                 :            :  * Generates RSA key components.
+     143                 :            :  *
+     144                 :            :  * This function generates RSA key components. It takes RSA public exponent E and
+     145                 :            :  * length in bits of RSA modulus N as input, and generates all key components.
+     146                 :            :  * If public_exponent is NULL, the default RSA public exponent (0x10001) will be used.
+     147                 :            :  *
+     148                 :            :  * If rsa_context is NULL, then return false.
+     149                 :            :  *
+     150                 :            :  * @param[in, out]  rsa_context           Pointer to RSA context being set.
+     151                 :            :  * @param[in]       modulus_length        length of RSA modulus N in bits.
+     152                 :            :  * @param[in]       public_exponent       Pointer to RSA public exponent.
+     153                 :            :  * @param[in]       public_exponent_size   size of RSA public exponent buffer in bytes.
+     154                 :            :  *
+     155                 :            :  * @retval  true   RSA key component was generated successfully.
+     156                 :            :  * @retval  false  Invalid RSA key component tag.
+     157                 :            :  *
+     158                 :            :  **/
+     159                 :          0 : bool libspdm_rsa_generate_key(void *rsa_context, size_t modulus_length,
+     160                 :            :                               const uint8_t *public_exponent,
+     161                 :            :                               size_t public_exponent_size)
+     162                 :            : {
+     163                 :          0 :     int32_t ret = 0;
+     164                 :            :     mbedtls_rsa_context *rsa;
+     165                 :            :     uint32_t e;
+     166                 :            : 
+     167                 :            : 
+     168                 :            :     /* Check input parameters.*/
+     169   [ #  #  #  #  :          0 :     if (rsa_context == NULL || modulus_length > INT_MAX ||
+                   #  # ]
+     170                 :            :         public_exponent_size > INT_MAX) {
+     171                 :          0 :         return false;
+     172                 :            :     }
+     173                 :            : 
+     174                 :          0 :     rsa = (mbedtls_rsa_context *)rsa_context;
+     175                 :            : 
+     176         [ #  # ]:          0 :     if (public_exponent == NULL) {
+     177                 :          0 :         e = 0x10001;
+     178                 :            :     } else {
+     179         [ #  # ]:          0 :         if (public_exponent_size == 0) {
+     180                 :          0 :             return false;
+     181                 :            :         }
+     182                 :            : 
+     183   [ #  #  #  #  :          0 :         switch (public_exponent_size) {
+                      # ]
+     184                 :          0 :         case 1:
+     185                 :          0 :             e = public_exponent[0];
+     186                 :          0 :             break;
+     187                 :          0 :         case 2:
+     188                 :          0 :             e = public_exponent[0] << 8 | public_exponent[1];
+     189                 :          0 :             break;
+     190                 :          0 :         case 3:
+     191                 :          0 :             e = public_exponent[0] << 16 | public_exponent[1] << 8 |
+     192                 :          0 :                 public_exponent[2];
+     193                 :          0 :             break;
+     194                 :          0 :         case 4:
+     195                 :          0 :             e = public_exponent[0] << 24 | public_exponent[1] << 16 |
+     196                 :          0 :                 public_exponent[2] << 8 | public_exponent[3];
+     197                 :          0 :             break;
+     198                 :          0 :         default:
+     199                 :          0 :             return false;
+     200                 :            :         }
+     201                 :            :     }
+     202                 :            : 
+     203         [ #  # ]:          0 :     if (ret == 0) {
+     204                 :          0 :         ret = mbedtls_rsa_gen_key(rsa, libspdm_myrand, NULL,
+     205                 :            :                                   (uint32_t)modulus_length, e);
+     206                 :            :     }
+     207                 :            : 
+     208                 :          0 :     return ret == 0;
+     209                 :            : }
+     210                 :            : 
+     211                 :            : /**
+     212                 :            :  * Validates key components of RSA context.
+     213                 :            :  * NOTE: This function performs integrity checks on all the RSA key material, so
+     214                 :            :  *      the RSA key structure must contain all the private key data.
+     215                 :            :  *
+     216                 :            :  * This function validates key components of RSA context in following aspects:
+     217                 :            :  * - Whether p is a prime
+     218                 :            :  * - Whether q is a prime
+     219                 :            :  * - Whether n = p * q
+     220                 :            :  * - Whether d*e = 1  mod lcm(p-1,q-1)
+     221                 :            :  *
+     222                 :            :  * If rsa_context is NULL, then return false.
+     223                 :            :  *
+     224                 :            :  * @param[in]  rsa_context  Pointer to RSA context to check.
+     225                 :            :  *
+     226                 :            :  * @retval  true   RSA key components are valid.
+     227                 :            :  * @retval  false  RSA key components are not valid.
+     228                 :            :  *
+     229                 :            :  **/
+     230                 :          0 : bool libspdm_rsa_check_key(void *rsa_context)
+     231                 :            : {
+     232                 :            :     int ret;
+     233                 :            : 
+     234         [ #  # ]:          0 :     if (rsa_context == NULL) {
+     235                 :          0 :         return false;
+     236                 :            :     }
+     237                 :            : 
+     238                 :          0 :     ret = mbedtls_rsa_complete(rsa_context);
+     239         [ #  # ]:          0 :     if (ret == 0) {
+     240                 :          0 :         ret = mbedtls_rsa_check_privkey(rsa_context);
+     241                 :            :     }
+     242                 :          0 :     return ret == 0;
+     243                 :            : }
+     244                 :            : #endif /* (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT) */
+     245                 :            : 
+     246                 :            : #if LIBSPDM_RSA_SSA_SUPPORT
+     247                 :            : /**
+     248                 :            :  * Carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme.
+     249                 :            :  *
+     250                 :            :  * This function carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme defined in
+     251                 :            :  * RSA PKCS#1.
+     252                 :            :  * If the signature buffer is too small to hold the contents of signature, false
+     253                 :            :  * is returned and sig_size is set to the required buffer size to obtain the signature.
+     254                 :            :  *
+     255                 :            :  * If rsa_context is NULL, then return false.
+     256                 :            :  * If message_hash is NULL, then return false.
+     257                 :            :  * If hash_size need match the hash_nid. hash_nid could be SHA256, SHA384, SHA512, SHA3_256, SHA3_384, SHA3_512.
+     258                 :            :  * If sig_size is large enough but signature is NULL, then return false.
+     259                 :            :  * If this interface is not supported, then return false.
+     260                 :            :  *
+     261                 :            :  * @param[in]      rsa_context   Pointer to RSA context for signature generation.
+     262                 :            :  * @param[in]      hash_nid      hash NID
+     263                 :            :  * @param[in]      message_hash  Pointer to octet message hash to be signed.
+     264                 :            :  * @param[in]      hash_size     size of the message hash in bytes.
+     265                 :            :  * @param[out]     signature    Pointer to buffer to receive RSA PKCS1-v1_5 signature.
+     266                 :            :  * @param[in, out] sig_size      On input, the size of signature buffer in bytes.
+     267                 :            :  *                             On output, the size of data returned in signature buffer in bytes.
+     268                 :            :  *
+     269                 :            :  * @retval  true   signature successfully generated in PKCS1-v1_5.
+     270                 :            :  * @retval  false  signature generation failed.
+     271                 :            :  * @retval  false  sig_size is too small.
+     272                 :            :  * @retval  false  This interface is not supported.
+     273                 :            :  *
+     274                 :            :  **/
+     275                 :         26 : bool libspdm_rsa_pkcs1_sign_with_nid(void *rsa_context, size_t hash_nid,
+     276                 :            :                                      const uint8_t *message_hash,
+     277                 :            :                                      size_t hash_size, uint8_t *signature,
+     278                 :            :                                      size_t *sig_size)
+     279                 :            : {
+     280                 :            :     int ret;
+     281                 :            :     mbedtls_md_type_t md_alg;
+     282                 :            :     mbedtls_rsa_context *rsa_key;
+     283                 :            : 
+     284   [ +  -  -  + ]:         26 :     if (rsa_context == NULL || message_hash == NULL) {
+     285                 :          0 :         return false;
+     286                 :            :     }
+     287                 :            : 
+     288                 :         26 :     rsa_key = (mbedtls_rsa_context *)rsa_context;
+     289         [ -  + ]:         26 :     if (mbedtls_rsa_complete(rsa_key) != 0) {
+     290                 :          0 :         return false;
+     291                 :            :     }
+     292                 :            : 
+     293   [ +  -  -  - ]:         26 :     switch (hash_nid) {
+     294                 :         26 :     case LIBSPDM_CRYPTO_NID_SHA256:
+     295                 :         26 :         md_alg = MBEDTLS_MD_SHA256;
+     296         [ -  + ]:         26 :         if (hash_size != LIBSPDM_SHA256_DIGEST_SIZE) {
+     297                 :          0 :             return false;
+     298                 :            :         }
+     299                 :         26 :         break;
+     300                 :            : 
+     301                 :          0 :     case LIBSPDM_CRYPTO_NID_SHA384:
+     302                 :          0 :         md_alg = MBEDTLS_MD_SHA384;
+     303         [ #  # ]:          0 :         if (hash_size != LIBSPDM_SHA384_DIGEST_SIZE) {
+     304                 :          0 :             return false;
+     305                 :            :         }
+     306                 :          0 :         break;
+     307                 :            : 
+     308                 :          0 :     case LIBSPDM_CRYPTO_NID_SHA512:
+     309                 :          0 :         md_alg = MBEDTLS_MD_SHA512;
+     310         [ #  # ]:          0 :         if (hash_size != LIBSPDM_SHA512_DIGEST_SIZE) {
+     311                 :          0 :             return false;
+     312                 :            :         }
+     313                 :          0 :         break;
+     314                 :            : 
+     315                 :          0 :     default:
+     316                 :          0 :         return false;
+     317                 :            :     }
+     318                 :            : 
+     319         [ -  + ]:         26 :     if (mbedtls_rsa_get_len(rsa_context) > *sig_size) {
+     320                 :          0 :         *sig_size = mbedtls_rsa_get_len(rsa_context);
+     321                 :          0 :         return false;
+     322                 :            :     }
+     323                 :            : 
+     324                 :         26 :     mbedtls_rsa_set_padding(rsa_context, MBEDTLS_RSA_PKCS_V15, md_alg);
+     325                 :            : 
+     326                 :         26 :     ret = mbedtls_rsa_pkcs1_sign(rsa_context, libspdm_myrand, NULL,
+     327                 :            :                                  md_alg,
+     328                 :            :                                  (uint32_t)hash_size, message_hash,
+     329                 :            :                                  signature);
+     330         [ -  + ]:         26 :     if (ret != 0) {
+     331                 :          0 :         return false;
+     332                 :            :     }
+     333                 :         26 :     *sig_size = mbedtls_rsa_get_len(rsa_context);
+     334                 :         26 :     return true;
+     335                 :            : }
+     336                 :            : #endif /* LIBSPDM_RSA_SSA_SUPPORT */
+     337                 :            : 
+     338                 :            : #if LIBSPDM_RSA_PSS_SUPPORT
+     339                 :            : /**
+     340                 :            :  * Carries out the RSA-SSA signature generation with EMSA-PSS encoding scheme.
+     341                 :            :  *
+     342                 :            :  * This function carries out the RSA-SSA signature generation with EMSA-PSS encoding scheme defined in
+     343                 :            :  * RSA PKCS#1 v2.2.
+     344                 :            :  *
+     345                 :            :  * The salt length is same as digest length.
+     346                 :            :  *
+     347                 :            :  * If the signature buffer is too small to hold the contents of signature, false
+     348                 :            :  * is returned and sig_size is set to the required buffer size to obtain the signature.
+     349                 :            :  *
+     350                 :            :  * If rsa_context is NULL, then return false.
+     351                 :            :  * If message_hash is NULL, then return false.
+     352                 :            :  * If hash_size need match the hash_nid. nid could be SHA256, SHA384, SHA512, SHA3_256, SHA3_384, SHA3_512.
+     353                 :            :  * If sig_size is large enough but signature is NULL, then return false.
+     354                 :            :  *
+     355                 :            :  * @param[in]       rsa_context   Pointer to RSA context for signature generation.
+     356                 :            :  * @param[in]       hash_nid      hash NID
+     357                 :            :  * @param[in]       message_hash  Pointer to octet message hash to be signed.
+     358                 :            :  * @param[in]       hash_size     size of the message hash in bytes.
+     359                 :            :  * @param[out]      signature    Pointer to buffer to receive RSA-SSA PSS signature.
+     360                 :            :  * @param[in, out]  sig_size      On input, the size of signature buffer in bytes.
+     361                 :            :  *                              On output, the size of data returned in signature buffer in bytes.
+     362                 :            :  *
+     363                 :            :  * @retval  true   signature successfully generated in RSA-SSA PSS.
+     364                 :            :  * @retval  false  signature generation failed.
+     365                 :            :  * @retval  false  sig_size is too small.
+     366                 :            :  *
+     367                 :            :  **/
+     368                 :          0 : bool libspdm_rsa_pss_sign(void *rsa_context, size_t hash_nid,
+     369                 :            :                           const uint8_t *message_hash, size_t hash_size,
+     370                 :            :                           uint8_t *signature, size_t *sig_size)
+     371                 :            : {
+     372                 :            :     int ret;
+     373                 :            :     mbedtls_md_type_t md_alg;
+     374                 :            :     mbedtls_rsa_context *rsa_key;
+     375                 :            : 
+     376   [ #  #  #  # ]:          0 :     if (rsa_context == NULL || message_hash == NULL) {
+     377                 :          0 :         return false;
+     378                 :            :     }
+     379                 :            : 
+     380                 :          0 :     rsa_key = (mbedtls_rsa_context *)rsa_context;
+     381         [ #  # ]:          0 :     if (mbedtls_rsa_complete(rsa_key) != 0) {
+     382                 :          0 :         return false;
+     383                 :            :     }
+     384                 :            : 
+     385   [ #  #  #  # ]:          0 :     switch (hash_nid) {
+     386                 :          0 :     case LIBSPDM_CRYPTO_NID_SHA256:
+     387                 :          0 :         md_alg = MBEDTLS_MD_SHA256;
+     388         [ #  # ]:          0 :         if (hash_size != LIBSPDM_SHA256_DIGEST_SIZE) {
+     389                 :          0 :             return false;
+     390                 :            :         }
+     391                 :          0 :         break;
+     392                 :            : 
+     393                 :          0 :     case LIBSPDM_CRYPTO_NID_SHA384:
+     394                 :          0 :         md_alg = MBEDTLS_MD_SHA384;
+     395         [ #  # ]:          0 :         if (hash_size != LIBSPDM_SHA384_DIGEST_SIZE) {
+     396                 :          0 :             return false;
+     397                 :            :         }
+     398                 :          0 :         break;
+     399                 :            : 
+     400                 :          0 :     case LIBSPDM_CRYPTO_NID_SHA512:
+     401                 :          0 :         md_alg = MBEDTLS_MD_SHA512;
+     402         [ #  # ]:          0 :         if (hash_size != LIBSPDM_SHA512_DIGEST_SIZE) {
+     403                 :          0 :             return false;
+     404                 :            :         }
+     405                 :          0 :         break;
+     406                 :            : 
+     407                 :          0 :     default:
+     408                 :          0 :         return false;
+     409                 :            :     }
+     410                 :            : 
+     411         [ #  # ]:          0 :     if (signature == NULL) {
+     412                 :            : 
+     413                 :            :         /* If signature is NULL, return safe signature_size*/
+     414                 :            : 
+     415                 :          0 :         *sig_size = MBEDTLS_MPI_MAX_SIZE;
+     416                 :          0 :         return false;
+     417                 :            :     }
+     418                 :            : 
+     419                 :          0 :     mbedtls_rsa_set_padding(rsa_context, MBEDTLS_RSA_PKCS_V21, md_alg);
+     420                 :            : 
+     421                 :          0 :     ret = mbedtls_rsa_rsassa_pss_sign(rsa_context, libspdm_myrand, NULL,
+     422                 :            :                                       md_alg,
+     423                 :            :                                       (uint32_t)hash_size, message_hash,
+     424                 :            :                                       signature);
+     425                 :            : 
+     426         [ #  # ]:          0 :     if (ret != 0) {
+     427                 :          0 :         return false;
+     428                 :            :     }
+     429                 :          0 :     *sig_size = mbedtls_rsa_get_len(rsa_context);
+     430                 :          0 :     return true;
+     431                 :            : }
+     432                 :            : 
+     433                 :            : #if LIBSPDM_FIPS_MODE
+     434                 :            : 
+     435                 :            : /*random function() for RSA_PSS*/
+     436                 :          5 : int libspdm_myrand_rsapss_fips(void *rng_state, unsigned char *output, size_t len)
+     437                 :            : {
+     438                 :            : 
+     439                 :            :     bool result;
+     440                 :            : 
+     441         [ +  + ]:          5 :     if (len == 0) {
+     442                 :          1 :         return 0;
+     443                 :            :     } else {
+     444                 :          4 :         result = libspdm_random_bytes(output, len);
+     445                 :            :         /* The MbedTLS function f_rng, which myrand implements, is not
+     446                 :            :          * documented well. From looking at code: zero is considered success,
+     447                 :            :          * while non-zero return value is considered failure.*/
+     448                 :            : 
+     449         [ +  - ]:          4 :         return result ? 0 : -1;
+     450                 :            :     }
+     451                 :            : }
+     452                 :            : 
+     453                 :            : /**
+     454                 :            :  * Carries out the RSA-SSA signature generation with EMSA-PSS encoding scheme for FIPS test.
+     455                 :            :  *
+     456                 :            :  * This function carries out the RSA-SSA signature generation with EMSA-PSS encoding scheme defined in
+     457                 :            :  * RSA PKCS#1 v2.2 for FIPS test.
+     458                 :            :  *
+     459                 :            :  * The salt length is zero.
+     460                 :            :  *
+     461                 :            :  * If the signature buffer is too small to hold the contents of signature, false
+     462                 :            :  * is returned and sig_size is set to the required buffer size to obtain the signature.
+     463                 :            :  *
+     464                 :            :  * If rsa_context is NULL, then return false.
+     465                 :            :  * If message_hash is NULL, then return false.
+     466                 :            :  * If hash_size need match the hash_nid. nid could be SHA256, SHA384, SHA512, SHA3_256, SHA3_384, SHA3_512.
+     467                 :            :  * If sig_size is large enough but signature is NULL, then return false.
+     468                 :            :  *
+     469                 :            :  * @param[in]       rsa_context   Pointer to RSA context for signature generation.
+     470                 :            :  * @param[in]       hash_nid      hash NID
+     471                 :            :  * @param[in]       message_hash  Pointer to octet message hash to be signed.
+     472                 :            :  * @param[in]       hash_size     size of the message hash in bytes.
+     473                 :            :  * @param[out]      signature    Pointer to buffer to receive RSA-SSA PSS signature.
+     474                 :            :  * @param[in, out]  sig_size      On input, the size of signature buffer in bytes.
+     475                 :            :  *                              On output, the size of data returned in signature buffer in bytes.
+     476                 :            :  *
+     477                 :            :  * @retval  true   signature successfully generated in RSA-SSA PSS.
+     478                 :            :  * @retval  false  signature generation failed.
+     479                 :            :  * @retval  false  sig_size is too small.
+     480                 :            :  *
+     481                 :            :  **/
+     482                 :          1 : bool libspdm_rsa_pss_sign_fips(void *rsa_context, size_t hash_nid,
+     483                 :            :                                const uint8_t *message_hash, size_t hash_size,
+     484                 :            :                                uint8_t *signature, size_t *sig_size)
+     485                 :            : {
+     486                 :            :     int ret;
+     487                 :            :     mbedtls_md_type_t md_alg;
+     488                 :            :     mbedtls_rsa_context *rsa_key;
+     489                 :            : 
+     490   [ +  -  -  + ]:          1 :     if (rsa_context == NULL || message_hash == NULL) {
+     491                 :          0 :         return false;
+     492                 :            :     }
+     493                 :            : 
+     494                 :          1 :     rsa_key = (mbedtls_rsa_context *)rsa_context;
+     495         [ -  + ]:          1 :     if (mbedtls_rsa_complete(rsa_key) != 0) {
+     496                 :          0 :         return false;
+     497                 :            :     }
+     498                 :            : 
+     499   [ +  -  -  - ]:          1 :     switch (hash_nid) {
+     500                 :          1 :     case LIBSPDM_CRYPTO_NID_SHA256:
+     501                 :          1 :         md_alg = MBEDTLS_MD_SHA256;
+     502         [ -  + ]:          1 :         if (hash_size != LIBSPDM_SHA256_DIGEST_SIZE) {
+     503                 :          0 :             return false;
+     504                 :            :         }
+     505                 :          1 :         break;
+     506                 :            : 
+     507                 :          0 :     case LIBSPDM_CRYPTO_NID_SHA384:
+     508                 :          0 :         md_alg = MBEDTLS_MD_SHA384;
+     509         [ #  # ]:          0 :         if (hash_size != LIBSPDM_SHA384_DIGEST_SIZE) {
+     510                 :          0 :             return false;
+     511                 :            :         }
+     512                 :          0 :         break;
+     513                 :            : 
+     514                 :          0 :     case LIBSPDM_CRYPTO_NID_SHA512:
+     515                 :          0 :         md_alg = MBEDTLS_MD_SHA512;
+     516         [ #  # ]:          0 :         if (hash_size != LIBSPDM_SHA512_DIGEST_SIZE) {
+     517                 :          0 :             return false;
+     518                 :            :         }
+     519                 :          0 :         break;
+     520                 :            : 
+     521                 :          0 :     default:
+     522                 :          0 :         return false;
+     523                 :            :     }
+     524                 :            : 
+     525         [ -  + ]:          1 :     if (signature == NULL) {
+     526                 :            : 
+     527                 :            :         /* If signature is NULL, return safe signature_size*/
+     528                 :            : 
+     529                 :          0 :         *sig_size = MBEDTLS_MPI_MAX_SIZE;
+     530                 :          0 :         return false;
+     531                 :            :     }
+     532                 :            : 
+     533                 :          1 :     mbedtls_rsa_set_padding(rsa_context, MBEDTLS_RSA_PKCS_V21, md_alg);
+     534                 :            : 
+     535                 :            :     /*salt len is 0*/
+     536                 :          1 :     ret = mbedtls_rsa_rsassa_pss_sign_ext(rsa_context, libspdm_myrand_rsapss_fips, NULL,
+     537                 :            :                                           md_alg, (uint32_t)hash_size, message_hash,
+     538                 :            :                                           0, signature);
+     539         [ -  + ]:          1 :     if (ret != 0) {
+     540                 :          0 :         return false;
+     541                 :            :     }
+     542                 :          1 :     *sig_size = mbedtls_rsa_get_len(rsa_context);
+     543                 :          1 :     return true;
+     544                 :            : }
+     545                 :            : #endif /*LIBSPDM_FIPS_MODE*/
+     546                 :            : 
+     547                 :            : #endif /* LIBSPDM_RSA_PSS_SUPPORT */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/pk/x509.c.func-sort-c.html b/coverage_log/os_stub/cryptlib_mbedtls/pk/x509.c.func-sort-c.html new file mode 100644 index 00000000000..518aee61cd6 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/pk/x509.c.func-sort-c.html @@ -0,0 +1,233 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/pk/x509.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/pk - x509.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:42867063.9 %
Date:2024-09-22 08:21:07Functions:243863.2 %
Branches:16837544.8 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_ecd_get_public_key_from_x5090
libspdm_internal_x509_get_issuer_nid_name0
libspdm_internal_x509_get_nid_name0
libspdm_internal_x509_get_subject_nid_name0
libspdm_sm2_get_public_key_from_x5090
libspdm_x509_construct_certificate_stack0
libspdm_x509_construct_certificate_stack_v0
libspdm_x509_free0
libspdm_x509_get_common_name0
libspdm_x509_get_issuer_common_name0
libspdm_x509_get_issuer_orgnization_name0
libspdm_x509_get_organization_name0
libspdm_x509_get_tbs_cert0
libspdm_x509_stack_free0
libspdm_convert_subject_to_string2
libspdm_set_attribute_for_req2
libspdm_gen_x509_csr6
libspdm_x509_construct_certificate6
libspdm_rsa_get_public_key_from_x50967
libspdm_x509_verify_cert_chain705
libspdm_x509_get_extended_basic_constraints722
libspdm_x509_get_extended_key_usage728
libspdm_x509_get_key_usage728
libspdm_x509_get_validity728
libspdm_x509_get_serial_number730
libspdm_x509_get_version730
libspdm_x509_get_issuer_name787
libspdm_x509_get_subject_name787
libspdm_ec_get_public_key_from_x509870
libspdm_internal_x509_check_time1456
libspdm_x509_compare_date_time1456
libspdm_x509_set_date_time1456
libspdm_internal_x509_find_extension_data2182
libspdm_x509_get_extension_data2182
libspdm_x509_verify_cert2255
libspdm_x509_get_cert_from_cert_chain2334
libspdm_internal_atoi8736
libspdm_asn1_get_tag14000
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/pk/x509.c.func.html b/coverage_log/os_stub/cryptlib_mbedtls/pk/x509.c.func.html new file mode 100644 index 00000000000..4977712017d --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/pk/x509.c.func.html @@ -0,0 +1,233 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/pk/x509.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/pk - x509.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:42867063.9 %
Date:2024-09-22 08:21:07Functions:243863.2 %
Branches:16837544.8 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_asn1_get_tag14000
libspdm_convert_subject_to_string2
libspdm_ec_get_public_key_from_x509870
libspdm_ecd_get_public_key_from_x5090
libspdm_gen_x509_csr6
libspdm_internal_atoi8736
libspdm_internal_x509_check_time1456
libspdm_internal_x509_find_extension_data2182
libspdm_internal_x509_get_issuer_nid_name0
libspdm_internal_x509_get_nid_name0
libspdm_internal_x509_get_subject_nid_name0
libspdm_rsa_get_public_key_from_x50967
libspdm_set_attribute_for_req2
libspdm_sm2_get_public_key_from_x5090
libspdm_x509_compare_date_time1456
libspdm_x509_construct_certificate6
libspdm_x509_construct_certificate_stack0
libspdm_x509_construct_certificate_stack_v0
libspdm_x509_free0
libspdm_x509_get_cert_from_cert_chain2334
libspdm_x509_get_common_name0
libspdm_x509_get_extended_basic_constraints722
libspdm_x509_get_extended_key_usage728
libspdm_x509_get_extension_data2182
libspdm_x509_get_issuer_common_name0
libspdm_x509_get_issuer_name787
libspdm_x509_get_issuer_orgnization_name0
libspdm_x509_get_key_usage728
libspdm_x509_get_organization_name0
libspdm_x509_get_serial_number730
libspdm_x509_get_subject_name787
libspdm_x509_get_tbs_cert0
libspdm_x509_get_validity728
libspdm_x509_get_version730
libspdm_x509_set_date_time1456
libspdm_x509_stack_free0
libspdm_x509_verify_cert2255
libspdm_x509_verify_cert_chain705
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/pk/x509.c.gcov.html b/coverage_log/os_stub/cryptlib_mbedtls/pk/x509.c.gcov.html new file mode 100644 index 00000000000..dca7f0b9040 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/pk/x509.c.gcov.html @@ -0,0 +1,2310 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/pk/x509.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/pk - x509.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:42867063.9 %
Date:2024-09-22 08:21:07Functions:243863.2 %
Branches:16837544.8 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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                 :            : /** @file
+       8                 :            :  * X.509 Certificate Handler Wrapper Implementation.
+       9                 :            :  **/
+      10                 :            : 
+      11                 :            : #include <stdarg.h>
+      12                 :            : #include "internal_crypt_lib.h"
+      13                 :            : #include <mbedtls/x509.h>
+      14                 :            : #include <mbedtls/x509_crt.h>
+      15                 :            : #include <mbedtls/rsa.h>
+      16                 :            : #include <mbedtls/ecp.h>
+      17                 :            : #include <mbedtls/ecdh.h>
+      18                 :            : #include <mbedtls/ecdsa.h>
+      19                 :            : #include <mbedtls/x509_csr.h>
+      20                 :            : #include <mbedtls/entropy.h>
+      21                 :            : #include <mbedtls/ctr_drbg.h>
+      22                 :            : #include <mbedtls/oid.h>
+      23                 :            : #include <mbedtls/bignum.h>
+      24                 :            : #include <string.h>
+      25                 :            : 
+      26                 :            : #if LIBSPDM_CERT_PARSE_SUPPORT
+      27                 :            : 
+      28                 :            : /* OID*/
+      29                 :            : 
+      30                 :            : #define OID_COMMON_NAME       { 0x55, 0x04, 0x03 }
+      31                 :            : #define OID_ORGANIZATION_NAME { 0x55, 0x04, 0x0A }
+      32                 :            : #define OID_EXT_KEY_USAGE     { 0x55, 0x1D, 0x25 }
+      33                 :            : #define OID_BASIC_CONSTRAINTS { 0x55, 0x1D, 0x13 }
+      34                 :            : 
+      35                 :            : static const uint8_t m_libspdm_oid_common_name[] = OID_COMMON_NAME;
+      36                 :            : static const uint8_t m_libspdm_oid_organization_name[] = OID_ORGANIZATION_NAME;
+      37                 :            : static const uint8_t m_libspdm_oid_ext_key_usage[] = OID_EXT_KEY_USAGE;
+      38                 :            : static const uint8_t m_libspdm_oid_basic_constraints[] = OID_BASIC_CONSTRAINTS;
+      39                 :            : 
+      40                 :            : typedef struct {
+      41                 :            :     const char *name; /* String representation of AttributeType, e.g.
+      42                 :            :                        * "CN" or "emailAddress". */
+      43                 :            :     size_t name_len;  /* Length of 'name', without trailing 0 byte. */
+      44                 :            :     const char *oid;  /* String representation of OID of AttributeType,
+      45                 :            :                        * as per RFC 5280, Appendix A.1. */
+      46                 :            :     size_t oid_len;
+      47                 :            :     int default_tag;  /* The default character encoding used for the
+      48                 :            :                        * given attribute type, e.g.
+      49                 :            :                        * MBEDTLS_ASN1_UTF8_STRING for UTF-8. */
+      50                 :            : } libspdm_x509_subject_descriptor_t;
+      51                 :            : 
+      52                 :            : #define LIBSPDM_ADD_STRLEN( s )     s, sizeof( s ) - 1
+      53                 :            : 
+      54                 :            : /*
+      55                 :            :  * EC public keys:
+      56                 :            :  *  SubjectPublicKeyInfo  ::=  SEQUENCE  {      1 + 2
+      57                 :            :  *    algorithm         AlgorithmIdentifier,    1 + 1 (sequence)
+      58                 :            :  *                                            + 1 + 1 + 7 (ec oid)
+      59                 :            :  *                                            + 1 + 1 + 9 (namedCurve oid)
+      60                 :            :  *    subjectPublicKey  BIT STRING              1 + 2 + 1               [1]
+      61                 :            :  *                                            + 1 (point format)        [1]
+      62                 :            :  *                                            + 2 * ECP_MAX (coords)    [1]
+      63                 :            :  *  }
+      64                 :            :  */
+      65                 :            : #define LIBSPDM_ECP_PUB_DER_MAX_BYTES   (30 + 2 * MBEDTLS_ECP_MAX_BYTES)
+      66                 :            : 
+      67                 :            : /*
+      68                 :            :  * RSA public keys:
+      69                 :            :  *  SubjectPublicKeyInfo  ::=  SEQUENCE  {          1 + 3
+      70                 :            :  *       algorithm            AlgorithmIdentifier,  1 + 1 (sequence)
+      71                 :            :  *                                                + 1 + 1 + 9 (rsa oid)
+      72                 :            :  *                                                + 1 + 1 (params null)
+      73                 :            :  *       subjectPublicKey     BIT STRING }          1 + 3 + (1 + below)
+      74                 :            :  *  RSAPublicKey ::= SEQUENCE {                     1 + 3
+      75                 :            :  *      modulus           INTEGER,  -- n            1 + 3 + MPI_MAX + 1
+      76                 :            :  *      publicExponent    INTEGER   -- e            1 + 3 + MPI_MAX + 1
+      77                 :            :  *  }
+      78                 :            :  */
+      79                 :            : #define LIBSPDM_RSA_PUB_DER_MAX_BYTES   (38 + 2 * MBEDTLS_MPI_MAX_SIZE)
+      80                 :            : 
+      81                 :            : #define LIBSPDM_MAX_PUBKEY_DER_BUFFER_SIZE (LIBSPDM_RSA_PUB_DER_MAX_BYTES > \
+      82                 :            :                                             LIBSPDM_ECP_PUB_DER_MAX_BYTES ? \
+      83                 :            :                                             LIBSPDM_RSA_PUB_DER_MAX_BYTES : \
+      84                 :            :                                             LIBSPDM_ECP_PUB_DER_MAX_BYTES )
+      85                 :            : 
+      86                 :            : #define LIBSPDM_MAX_SUBJECT_BUFFER_SIZE MBEDTLS_X509_MAX_DN_NAME_SIZE
+      87                 :            : 
+      88                 :            : /**
+      89                 :            :  * Construct a X509 object from DER-encoded certificate data.
+      90                 :            :  *
+      91                 :            :  * If cert is NULL, then return false.
+      92                 :            :  * If single_x509_cert is NULL, then return false.
+      93                 :            :  *
+      94                 :            :  * @param[in]  cert            Pointer to the DER-encoded certificate data.
+      95                 :            :  * @param[in]  cert_size        The size of certificate data in bytes.
+      96                 :            :  * @param[out] single_x509_cert  The generated X509 object.
+      97                 :            :  *
+      98                 :            :  * @retval     true            The X509 object generation succeeded.
+      99                 :            :  * @retval     false           The operation failed.
+     100                 :            :  *
+     101                 :            :  **/
+     102                 :          6 : bool libspdm_x509_construct_certificate(const uint8_t *cert, size_t cert_size,
+     103                 :            :                                         uint8_t **single_x509_cert)
+     104                 :            : {
+     105                 :            :     mbedtls_x509_crt *mbedtls_cert;
+     106                 :            :     int ret;
+     107                 :            : 
+     108   [ +  -  +  -  :          6 :     if (cert == NULL || single_x509_cert == NULL || cert_size == 0) {
+                   -  + ]
+     109                 :          0 :         return false;
+     110                 :            :     }
+     111                 :            : 
+     112                 :          6 :     mbedtls_cert = allocate_pool(sizeof(mbedtls_x509_crt));
+     113         [ -  + ]:          6 :     if (mbedtls_cert == NULL) {
+     114                 :          0 :         return false;
+     115                 :            :     }
+     116                 :            : 
+     117                 :          6 :     mbedtls_x509_crt_init(mbedtls_cert);
+     118                 :            : 
+     119                 :          6 :     *single_x509_cert = (uint8_t *)(void *)mbedtls_cert;
+     120                 :          6 :     ret = mbedtls_x509_crt_parse_der(mbedtls_cert, cert, cert_size);
+     121                 :            : 
+     122                 :          6 :     return ret == 0;
+     123                 :            : }
+     124                 :            : 
+     125                 :          0 : static bool libspdm_x509_construct_certificate_stack_v(uint8_t **x509_stack,
+     126                 :            :                                                        va_list args)
+     127                 :            : {
+     128                 :            :     uint8_t *cert;
+     129                 :            :     size_t cert_size;
+     130                 :            :     int ret;
+     131                 :            : 
+     132         [ #  # ]:          0 :     if (x509_stack == NULL) {
+     133                 :          0 :         return false;
+     134                 :            :     }
+     135                 :            : 
+     136                 :          0 :     ret = 0;
+     137                 :          0 :     mbedtls_x509_crt *crt = (mbedtls_x509_crt *)*x509_stack;
+     138         [ #  # ]:          0 :     if (crt == NULL) {
+     139                 :          0 :         crt = allocate_pool(sizeof(mbedtls_x509_crt));
+     140         [ #  # ]:          0 :         if (crt == NULL) {
+     141                 :          0 :             return false;
+     142                 :            :         }
+     143                 :          0 :         mbedtls_x509_crt_init(crt);
+     144                 :          0 :         *x509_stack = (uint8_t *)crt;
+     145                 :            :     }
+     146                 :            : 
+     147                 :            :     for (;;) {
+     148                 :            : 
+     149                 :            :         /* If cert is NULL, then it is the end of the list.*/
+     150                 :            : 
+     151                 :          0 :         cert = va_arg(args, uint8_t *);
+     152         [ #  # ]:          0 :         if (cert == NULL) {
+     153                 :          0 :             break;
+     154                 :            :         }
+     155                 :            : 
+     156                 :          0 :         cert_size = va_arg(args, size_t);
+     157         [ #  # ]:          0 :         if (cert_size == 0) {
+     158                 :          0 :             break;
+     159                 :            :         }
+     160                 :            : 
+     161                 :          0 :         ret = mbedtls_x509_crt_parse_der(crt, cert, cert_size);
+     162                 :            : 
+     163         [ #  # ]:          0 :         if (ret != 0) {
+     164                 :          0 :             break;
+     165                 :            :         }
+     166                 :            :     }
+     167                 :          0 :     return ret == 0;
+     168                 :            : }
+     169                 :            : 
+     170                 :            : /**
+     171                 :            :  * Construct a X509 stack object from a list of DER-encoded certificate data.
+     172                 :            :  *
+     173                 :            :  * If x509_stack is NULL, then return false.
+     174                 :            :  *
+     175                 :            :  * @param[in, out]  x509_stack  On input, pointer to an existing or NULL X509 stack object.
+     176                 :            :  *                            On output, pointer to the X509 stack object with new
+     177                 :            :  *                            inserted X509 certificate.
+     178                 :            :  * @param           ...        A list of DER-encoded single certificate data followed
+     179                 :            :  *                            by certificate size. A NULL terminates the list. The
+     180                 :            :  *                            pairs are the arguments to libspdm_x509_construct_certificate().
+     181                 :            :  *
+     182                 :            :  * @retval     true            The X509 stack construction succeeded.
+     183                 :            :  * @retval     false           The construction operation failed.
+     184                 :            :  *
+     185                 :            :  **/
+     186                 :          0 : bool libspdm_x509_construct_certificate_stack(uint8_t **x509_stack, ...)
+     187                 :            : {
+     188                 :            :     va_list args;
+     189                 :            :     bool result;
+     190                 :            : 
+     191                 :          0 :     va_start(args, x509_stack);
+     192                 :          0 :     result = libspdm_x509_construct_certificate_stack_v(x509_stack, args);
+     193                 :          0 :     va_end(args);
+     194                 :          0 :     return result;
+     195                 :            : }
+     196                 :            : 
+     197                 :            : /**
+     198                 :            :  * Release the specified X509 object.
+     199                 :            :  *
+     200                 :            :  * If x509_cert is NULL, then return false.
+     201                 :            :  *
+     202                 :            :  * @param[in]  x509_cert  Pointer to the X509 object to be released.
+     203                 :            :  *
+     204                 :            :  **/
+     205                 :          0 : void libspdm_x509_free(void *x509_cert)
+     206                 :            : {
+     207         [ #  # ]:          0 :     if (x509_cert) {
+     208                 :          0 :         mbedtls_x509_crt_free(x509_cert);
+     209                 :          0 :         free_pool(x509_cert);
+     210                 :            :     }
+     211                 :          0 : }
+     212                 :            : 
+     213                 :            : /**
+     214                 :            :  * Release the specified X509 stack object.
+     215                 :            :  *
+     216                 :            :  * If x509_stack is NULL, then return false.
+     217                 :            :  *
+     218                 :            :  * @param[in]  x509_stack  Pointer to the X509 stack object to be released.
+     219                 :            :  *
+     220                 :            :  **/
+     221                 :          0 : void libspdm_x509_stack_free(void *x509_stack)
+     222                 :            : {
+     223         [ #  # ]:          0 :     if (x509_stack == NULL) {
+     224                 :          0 :         return;
+     225                 :            :     }
+     226                 :            : 
+     227                 :          0 :     mbedtls_x509_crt_free(x509_stack);
+     228                 :            : }
+     229                 :            : 
+     230                 :            : /**
+     231                 :            :  * Retrieve the tag and length of the tag.
+     232                 :            :  *
+     233                 :            :  * @param ptr      The position in the ASN.1 data
+     234                 :            :  * @param end      end of data
+     235                 :            :  * @param length   The variable that will receive the length
+     236                 :            :  * @param tag      The expected tag
+     237                 :            :  *
+     238                 :            :  * @retval      true   Get tag successful
+     239                 :            :  * @retval      FALSe  Failed to get tag or tag not match
+     240                 :            :  **/
+     241                 :      14000 : bool libspdm_asn1_get_tag(uint8_t **ptr, const uint8_t *end, size_t *length,
+     242                 :            :                           uint32_t tag)
+     243                 :            : {
+     244         [ +  + ]:      14000 :     if (mbedtls_asn1_get_tag(ptr, end, length, (int32_t)tag) == 0) {
+     245                 :      13971 :         return true;
+     246                 :            :     } else {
+     247                 :         29 :         return false;
+     248                 :            :     }
+     249                 :            : }
+     250                 :            : 
+     251                 :            : /**
+     252                 :            :  * Retrieve the subject bytes from one X.509 certificate.
+     253                 :            :  *
+     254                 :            :  * @param[in]      cert         Pointer to the DER-encoded X509 certificate.
+     255                 :            :  * @param[in]      cert_size     size of the X509 certificate in bytes.
+     256                 :            :  * @param[out]     cert_subject  Pointer to the retrieved certificate subject bytes.
+     257                 :            :  * @param[in, out] subject_size  The size in bytes of the cert_subject buffer on input,
+     258                 :            :  *                             and the size of buffer returned cert_subject on output.
+     259                 :            :  *
+     260                 :            :  * If cert is NULL, then return false.
+     261                 :            :  * If subject_size is NULL, then return false.
+     262                 :            :  *
+     263                 :            :  * @retval  true   If the subject_size is not equal 0. The certificate subject retrieved successfully.
+     264                 :            :  * @retval  true   If the subject_size is equal 0. The certificate parse successful. But the cert doesn't have subject.
+     265                 :            :  * @retval  false  If the subject_size is not equal 0. The certificate subject retrieved successfully.But the subject_size is too small for the result.
+     266                 :            :  * @retval  false  If the subject_size is equal 0. Invalid certificate.
+     267                 :            :  **/
+     268                 :        787 : bool libspdm_x509_get_subject_name(const uint8_t *cert, size_t cert_size,
+     269                 :            :                                    uint8_t *cert_subject,
+     270                 :            :                                    size_t *subject_size)
+     271                 :            : {
+     272                 :            :     mbedtls_x509_crt crt;
+     273                 :            :     int ret;
+     274                 :            :     bool status;
+     275                 :            : 
+     276                 :            :     /* Check input parameters.*/
+     277   [ +  -  +  -  :        787 :     if (cert == NULL || cert == 0 || subject_size == NULL) {
+                   -  + ]
+     278         [ #  # ]:          0 :         if (subject_size != NULL) {
+     279                 :          0 :             *subject_size = 0;
+     280                 :            :         }
+     281                 :          0 :         return false;
+     282                 :            :     }
+     283                 :            : 
+     284                 :        787 :     status = false;
+     285                 :            : 
+     286                 :        787 :     mbedtls_x509_crt_init(&crt);
+     287                 :            : 
+     288                 :        787 :     ret = mbedtls_x509_crt_parse_der(&crt, cert, cert_size);
+     289                 :            : 
+     290         [ +  - ]:        787 :     if (ret == 0) {
+     291         [ +  + ]:        787 :         if (*subject_size < crt.subject_raw.len) {
+     292                 :        728 :             *subject_size = crt.subject_raw.len;
+     293                 :        728 :             status = false;
+     294                 :        728 :             goto cleanup;
+     295                 :            :         }
+     296         [ +  - ]:         59 :         if (cert_subject != NULL) {
+     297                 :         59 :             libspdm_copy_mem(cert_subject, *subject_size,
+     298                 :         59 :                              crt.subject_raw.p, crt.subject_raw.len);
+     299                 :            :         }
+     300                 :         59 :         *subject_size = crt.subject_raw.len;
+     301                 :         59 :         status = true;
+     302                 :            :     } else {
+     303                 :          0 :         *subject_size = 0;
+     304                 :            :     }
+     305                 :            : 
+     306                 :        787 : cleanup:
+     307                 :        787 :     mbedtls_x509_crt_free(&crt);
+     308                 :            : 
+     309                 :        787 :     return status;
+     310                 :            : }
+     311                 :            : 
+     312                 :            : bool
+     313                 :          0 : libspdm_internal_x509_get_nid_name(mbedtls_x509_name *name, const uint8_t *oid,
+     314                 :            :                                    size_t oid_size, char *common_name,
+     315                 :            :                                    size_t *common_name_size)
+     316                 :            : {
+     317                 :            :     const mbedtls_asn1_named_data *data;
+     318                 :            : 
+     319                 :          0 :     data = mbedtls_asn1_find_named_data(name, (const char *)oid, oid_size);
+     320         [ #  # ]:          0 :     if (data != NULL) {
+     321         [ #  # ]:          0 :         if (*common_name_size <= data->val.len) {
+     322                 :          0 :             *common_name_size = data->val.len + 1;
+     323                 :          0 :             return false;
+     324                 :            :         }
+     325         [ #  # ]:          0 :         if (common_name != NULL) {
+     326                 :          0 :             libspdm_copy_mem(common_name, *common_name_size, data->val.p, data->val.len);
+     327                 :          0 :             common_name[data->val.len] = '\0';
+     328                 :            :         }
+     329                 :          0 :         *common_name_size = data->val.len + 1;
+     330                 :          0 :         return true;
+     331                 :            :     } else {
+     332                 :          0 :         *common_name_size = 0;
+     333                 :          0 :         return false;
+     334                 :            :     }
+     335                 :            : }
+     336                 :            : 
+     337                 :            : bool
+     338                 :          0 : libspdm_internal_x509_get_subject_nid_name(const uint8_t *cert, size_t cert_size,
+     339                 :            :                                            const uint8_t *oid, size_t oid_size,
+     340                 :            :                                            char *common_name,
+     341                 :            :                                            size_t *common_name_size)
+     342                 :            : {
+     343                 :            :     mbedtls_x509_crt crt;
+     344                 :            :     int ret;
+     345                 :            :     mbedtls_x509_name *name;
+     346                 :            :     bool status;
+     347                 :            : 
+     348         [ #  # ]:          0 :     if (cert == NULL) {
+     349                 :          0 :         return false;
+     350                 :            :     }
+     351                 :            : 
+     352                 :          0 :     status = false;
+     353                 :            : 
+     354                 :          0 :     mbedtls_x509_crt_init(&crt);
+     355                 :            : 
+     356                 :          0 :     ret = mbedtls_x509_crt_parse_der(&crt, cert, cert_size);
+     357                 :            : 
+     358         [ #  # ]:          0 :     if (ret == 0) {
+     359                 :          0 :         name = &(crt.subject);
+     360                 :          0 :         status = libspdm_internal_x509_get_nid_name(
+     361                 :            :             name, oid, oid_size, common_name, common_name_size);
+     362                 :            :     }
+     363                 :            : 
+     364                 :          0 :     mbedtls_x509_crt_free(&crt);
+     365                 :            : 
+     366                 :          0 :     return status;
+     367                 :            : }
+     368                 :            : 
+     369                 :            : bool
+     370                 :          0 : libspdm_internal_x509_get_issuer_nid_name(const uint8_t *cert, size_t cert_size,
+     371                 :            :                                           const uint8_t *oid, size_t oid_size,
+     372                 :            :                                           char *common_name,
+     373                 :            :                                           size_t *common_name_size)
+     374                 :            : {
+     375                 :            :     mbedtls_x509_crt crt;
+     376                 :            :     int ret;
+     377                 :            :     mbedtls_x509_name *name;
+     378                 :            :     bool status;
+     379                 :            : 
+     380         [ #  # ]:          0 :     if (cert == NULL) {
+     381                 :          0 :         return false;
+     382                 :            :     }
+     383                 :            : 
+     384                 :          0 :     status = false;
+     385                 :            : 
+     386                 :          0 :     mbedtls_x509_crt_init(&crt);
+     387                 :            : 
+     388                 :          0 :     ret = mbedtls_x509_crt_parse_der(&crt, cert, cert_size);
+     389                 :            : 
+     390         [ #  # ]:          0 :     if (ret == 0) {
+     391                 :          0 :         name = &(crt.issuer);
+     392                 :          0 :         status = libspdm_internal_x509_get_nid_name(
+     393                 :            :             name, oid, oid_size, common_name, common_name_size);
+     394                 :            :     }
+     395                 :            : 
+     396                 :          0 :     mbedtls_x509_crt_free(&crt);
+     397                 :            : 
+     398                 :          0 :     return status;
+     399                 :            : }
+     400                 :            : 
+     401                 :            : /**
+     402                 :            :  * Retrieve the common name (CN) string from one X.509 certificate.
+     403                 :            :  *
+     404                 :            :  * @param[in]      cert             Pointer to the DER-encoded X509 certificate.
+     405                 :            :  * @param[in]      cert_size         size of the X509 certificate in bytes.
+     406                 :            :  * @param[out]     common_name       buffer to contain the retrieved certificate common
+     407                 :            :  *                                 name string. At most common_name_size bytes will be
+     408                 :            :  *                                 written and the string will be null terminated. May be
+     409                 :            :  *                                 NULL in order to determine the size buffer needed.
+     410                 :            :  * @param[in,out]  common_name_size   The size in bytes of the common_name buffer on input,
+     411                 :            :  *                                 and the size of buffer returned common_name on output.
+     412                 :            :  *                                 If common_name is NULL then the amount of space needed
+     413                 :            :  *                                 in buffer (including the final null) is returned.
+     414                 :            :  *
+     415                 :            :  * @retval RETURN_SUCCESS           The certificate common_name retrieved successfully.
+     416                 :            :  * @retval RETURN_INVALID_PARAMETER If cert is NULL.
+     417                 :            :  *                                 If common_name_size is NULL.
+     418                 :            :  *                                 If common_name is not NULL and *common_name_size is 0.
+     419                 :            :  *                                 If Certificate is invalid.
+     420                 :            :  * @retval RETURN_NOT_FOUND         If no common_name entry exists.
+     421                 :            :  * @retval RETURN_BUFFER_TOO_SMALL  If the common_name is NULL. The required buffer size
+     422                 :            :  *                                 (including the final null) is returned in the
+     423                 :            :  *                                 common_name_size parameter.
+     424                 :            :  * @retval RETURN_UNSUPPORTED       The operation is not supported.
+     425                 :            :  *
+     426                 :            :  **/
+     427                 :          0 : bool libspdm_x509_get_common_name(const uint8_t *cert, size_t cert_size,
+     428                 :            :                                   char *common_name,
+     429                 :            :                                   size_t *common_name_size)
+     430                 :            : {
+     431                 :          0 :     return libspdm_internal_x509_get_subject_nid_name(
+     432                 :            :         cert, cert_size, (const uint8_t *)m_libspdm_oid_common_name,
+     433                 :            :         sizeof(m_libspdm_oid_common_name), common_name, common_name_size);
+     434                 :            : }
+     435                 :            : 
+     436                 :            : /**
+     437                 :            :  * Retrieve the organization name (O) string from one X.509 certificate.
+     438                 :            :  *
+     439                 :            :  * @param[in]      cert             Pointer to the DER-encoded X509 certificate.
+     440                 :            :  * @param[in]      cert_size         size of the X509 certificate in bytes.
+     441                 :            :  * @param[out]     name_buffer       buffer to contain the retrieved certificate organization
+     442                 :            :  *                                 name string. At most name_buffer_size bytes will be
+     443                 :            :  *                                 written and the string will be null terminated. May be
+     444                 :            :  *                                 NULL in order to determine the size buffer needed.
+     445                 :            :  * @param[in,out]  name_buffer_size   The size in bytes of the name buffer on input,
+     446                 :            :  *                                 and the size of buffer returned name on output.
+     447                 :            :  *                                 If name_buffer is NULL then the amount of space needed
+     448                 :            :  *                                 in buffer (including the final null) is returned.
+     449                 :            :  *
+     450                 :            :  * @retval RETURN_SUCCESS           The certificate Organization name retrieved successfully.
+     451                 :            :  * @retval RETURN_INVALID_PARAMETER If cert is NULL.
+     452                 :            :  *                                 If name_buffer_size is NULL.
+     453                 :            :  *                                 If name_buffer is not NULL and *common_name_size is 0.
+     454                 :            :  *                                 If Certificate is invalid.
+     455                 :            :  * @retval RETURN_NOT_FOUND         If no Organization name entry exists.
+     456                 :            :  * @retval RETURN_BUFFER_TOO_SMALL  If the name_buffer is NULL. The required buffer size
+     457                 :            :  *                                 (including the final null) is returned in the
+     458                 :            :  *                                 common_name_size parameter.
+     459                 :            :  * @retval RETURN_UNSUPPORTED       The operation is not supported.
+     460                 :            :  *
+     461                 :            :  **/
+     462                 :            : bool
+     463                 :          0 : libspdm_x509_get_organization_name(const uint8_t *cert, size_t cert_size,
+     464                 :            :                                    char *name_buffer,
+     465                 :            :                                    size_t *name_buffer_size)
+     466                 :            : {
+     467                 :          0 :     return libspdm_internal_x509_get_subject_nid_name(
+     468                 :            :         cert, cert_size, m_libspdm_oid_organization_name,
+     469                 :            :         sizeof(m_libspdm_oid_organization_name), name_buffer, name_buffer_size);
+     470                 :            : }
+     471                 :            : 
+     472                 :            : #if (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT)
+     473                 :            : /**
+     474                 :            :  * Retrieve the RSA public key from one DER-encoded X509 certificate.
+     475                 :            :  *
+     476                 :            :  * @param[in]  cert         Pointer to the DER-encoded X509 certificate.
+     477                 :            :  * @param[in]  cert_size     size of the X509 certificate in bytes.
+     478                 :            :  * @param[out] rsa_context   Pointer to newly generated RSA context which contain the retrieved
+     479                 :            :  *                         RSA public key component. Use libspdm_rsa_free() function to free the
+     480                 :            :  *                         resource.
+     481                 :            :  *
+     482                 :            :  * If cert is NULL, then return false.
+     483                 :            :  * If rsa_context is NULL, then return false.
+     484                 :            :  *
+     485                 :            :  * @retval  true   RSA public key was retrieved successfully.
+     486                 :            :  * @retval  false  Fail to retrieve RSA public key from X509 certificate.
+     487                 :            :  *
+     488                 :            :  **/
+     489                 :         67 : bool libspdm_rsa_get_public_key_from_x509(const uint8_t *cert, size_t cert_size,
+     490                 :            :                                           void **rsa_context)
+     491                 :            : {
+     492                 :            :     mbedtls_x509_crt crt;
+     493                 :            :     mbedtls_rsa_context *rsa;
+     494                 :            :     int ret;
+     495                 :            : 
+     496                 :         67 :     mbedtls_x509_crt_init(&crt);
+     497                 :            : 
+     498         [ -  + ]:         67 :     if (mbedtls_x509_crt_parse_der(&crt, cert, cert_size) != 0) {
+     499                 :          0 :         return false;
+     500                 :            :     }
+     501                 :            : 
+     502         [ +  + ]:         67 :     if (mbedtls_pk_get_type(&crt.pk) != MBEDTLS_PK_RSA) {
+     503                 :          5 :         mbedtls_x509_crt_free(&crt);
+     504                 :          5 :         return false;
+     505                 :            :     }
+     506                 :            : 
+     507                 :         62 :     rsa = libspdm_rsa_new();
+     508         [ -  + ]:         62 :     if (rsa == NULL) {
+     509                 :          0 :         mbedtls_x509_crt_free(&crt);
+     510                 :          0 :         return false;
+     511                 :            :     }
+     512                 :         62 :     ret = mbedtls_rsa_copy(rsa, mbedtls_pk_rsa(crt.pk));
+     513         [ -  + ]:         62 :     if (ret != 0) {
+     514                 :          0 :         libspdm_rsa_free(rsa);
+     515                 :          0 :         mbedtls_x509_crt_free(&crt);
+     516                 :          0 :         return false;
+     517                 :            :     }
+     518                 :         62 :     mbedtls_x509_crt_free(&crt);
+     519                 :            : 
+     520                 :         62 :     *rsa_context = rsa;
+     521                 :         62 :     return true;
+     522                 :            : }
+     523                 :            : #endif /* (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT) */
+     524                 :            : 
+     525                 :            : /**
+     526                 :            :  * Retrieve the EC public key from one DER-encoded X509 certificate.
+     527                 :            :  *
+     528                 :            :  * @param[in]  cert         Pointer to the DER-encoded X509 certificate.
+     529                 :            :  * @param[in]  cert_size     size of the X509 certificate in bytes.
+     530                 :            :  * @param[out] ec_context    Pointer to newly generated EC DSA context which contain the retrieved
+     531                 :            :  *                         EC public key component. Use libspdm_ec_free() function to free the
+     532                 :            :  *                         resource.
+     533                 :            :  *
+     534                 :            :  * If cert is NULL, then return false.
+     535                 :            :  * If ec_context is NULL, then return false.
+     536                 :            :  *
+     537                 :            :  * @retval  true   EC public key was retrieved successfully.
+     538                 :            :  * @retval  false  Fail to retrieve EC public key from X509 certificate.
+     539                 :            :  *
+     540                 :            :  **/
+     541                 :        870 : bool libspdm_ec_get_public_key_from_x509(const uint8_t *cert, size_t cert_size,
+     542                 :            :                                          void **ec_context)
+     543                 :            : {
+     544                 :            :     mbedtls_x509_crt crt;
+     545                 :            :     mbedtls_ecdh_context *ecdh;
+     546                 :            :     int ret;
+     547                 :            : 
+     548                 :        870 :     mbedtls_x509_crt_init(&crt);
+     549                 :            : 
+     550         [ -  + ]:        870 :     if (mbedtls_x509_crt_parse_der(&crt, cert, cert_size) != 0) {
+     551                 :          0 :         return false;
+     552                 :            :     }
+     553                 :            : 
+     554         [ -  + ]:        870 :     if (mbedtls_pk_get_type(&crt.pk) != MBEDTLS_PK_ECKEY) {
+     555                 :          0 :         mbedtls_x509_crt_free(&crt);
+     556                 :          0 :         return false;
+     557                 :            :     }
+     558                 :            : 
+     559                 :        870 :     ecdh = allocate_zero_pool(sizeof(mbedtls_ecdh_context));
+     560         [ -  + ]:        870 :     if (ecdh == NULL) {
+     561                 :          0 :         mbedtls_x509_crt_free(&crt);
+     562                 :          0 :         return false;
+     563                 :            :     }
+     564                 :        870 :     mbedtls_ecdh_init(ecdh);
+     565                 :            : 
+     566                 :        870 :     ret = mbedtls_ecdh_get_params(ecdh, mbedtls_pk_ec(crt.pk),
+     567                 :            :                                   MBEDTLS_ECDH_OURS);
+     568         [ -  + ]:        870 :     if (ret != 0) {
+     569                 :          0 :         mbedtls_ecdh_free(ecdh);
+     570                 :          0 :         free_pool(ecdh);
+     571                 :          0 :         mbedtls_x509_crt_free(&crt);
+     572                 :          0 :         return false;
+     573                 :            :     }
+     574                 :        870 :     mbedtls_x509_crt_free(&crt);
+     575                 :            : 
+     576                 :        870 :     *ec_context = ecdh;
+     577                 :        870 :     return true;
+     578                 :            : }
+     579                 :            : 
+     580                 :            : /**
+     581                 :            :  * Retrieve the Ed public key from one DER-encoded X509 certificate.
+     582                 :            :  *
+     583                 :            :  * @param[in]  cert         Pointer to the DER-encoded X509 certificate.
+     584                 :            :  * @param[in]  cert_size     size of the X509 certificate in bytes.
+     585                 :            :  * @param[out] ecd_context    Pointer to newly generated Ed DSA context which contain the retrieved
+     586                 :            :  *                         Ed public key component. Use libspdm_ecd_free() function to free the
+     587                 :            :  *                         resource.
+     588                 :            :  *
+     589                 :            :  * If cert is NULL, then return false.
+     590                 :            :  * If ecd_context is NULL, then return false.
+     591                 :            :  *
+     592                 :            :  * @retval  true   Ed public key was retrieved successfully.
+     593                 :            :  * @retval  false  Fail to retrieve Ed public key from X509 certificate.
+     594                 :            :  *
+     595                 :            :  **/
+     596                 :          0 : bool libspdm_ecd_get_public_key_from_x509(const uint8_t *cert, size_t cert_size,
+     597                 :            :                                           void **ecd_context)
+     598                 :            : {
+     599                 :          0 :     return false;
+     600                 :            : }
+     601                 :            : 
+     602                 :            : /**
+     603                 :            :  * Retrieve the sm2 public key from one DER-encoded X509 certificate.
+     604                 :            :  *
+     605                 :            :  * @param[in]  cert         Pointer to the DER-encoded X509 certificate.
+     606                 :            :  * @param[in]  cert_size     size of the X509 certificate in bytes.
+     607                 :            :  * @param[out] sm2_context   Pointer to newly generated sm2 context which contain the retrieved
+     608                 :            :  *                         sm2 public key component. Use sm2_free() function to free the
+     609                 :            :  *                         resource.
+     610                 :            :  *
+     611                 :            :  * If cert is NULL, then return false.
+     612                 :            :  * If ecd_context is NULL, then return false.
+     613                 :            :  *
+     614                 :            :  * @retval  true   sm2 public key was retrieved successfully.
+     615                 :            :  * @retval  false  Fail to retrieve sm2 public key from X509 certificate.
+     616                 :            :  *
+     617                 :            :  **/
+     618                 :          0 : bool libspdm_sm2_get_public_key_from_x509(const uint8_t *cert, size_t cert_size,
+     619                 :            :                                           void **sm2_context)
+     620                 :            : {
+     621                 :          0 :     return false;
+     622                 :            : }
+     623                 :            : 
+     624                 :            : /**
+     625                 :            :  * Verify one X509 certificate was issued by the trusted CA.
+     626                 :            :  *
+     627                 :            :  * @param[in]      cert         Pointer to the DER-encoded X509 certificate to be verified.
+     628                 :            :  * @param[in]      cert_size     size of the X509 certificate in bytes.
+     629                 :            :  * @param[in]      ca_cert       Pointer to the DER-encoded trusted CA certificate.
+     630                 :            :  * @param[in]      ca_cert_size   size of the CA Certificate in bytes.
+     631                 :            :  *
+     632                 :            :  * If cert is NULL, then return false.
+     633                 :            :  * If ca_cert is NULL, then return false.
+     634                 :            :  *
+     635                 :            :  * @retval  true   The certificate was issued by the trusted CA.
+     636                 :            :  * @retval  false  Invalid certificate or the certificate was not issued by the given
+     637                 :            :  *                trusted CA.
+     638                 :            :  *
+     639                 :            :  **/
+     640                 :       2255 : bool libspdm_x509_verify_cert(const uint8_t *cert, size_t cert_size,
+     641                 :            :                               const uint8_t *ca_cert, size_t ca_cert_size)
+     642                 :            : {
+     643                 :            :     int ret;
+     644                 :            :     mbedtls_x509_crt ca, end;
+     645                 :       2255 :     uint32_t v_flag = 0;
+     646                 :       2255 :     mbedtls_x509_crt_profile profile = { 0 };
+     647                 :            : 
+     648   [ +  -  -  + ]:       2255 :     if (cert == NULL || ca_cert == NULL) {
+     649                 :          0 :         return false;
+     650                 :            :     }
+     651                 :            : 
+     652                 :       2255 :     libspdm_copy_mem(&profile, sizeof(profile),
+     653                 :            :                      &mbedtls_x509_crt_profile_default,
+     654                 :            :                      sizeof(mbedtls_x509_crt_profile));
+     655                 :            : 
+     656                 :       2255 :     mbedtls_x509_crt_init(&ca);
+     657                 :       2255 :     mbedtls_x509_crt_init(&end);
+     658                 :            : 
+     659                 :       2255 :     ret = mbedtls_x509_crt_parse_der(&ca, ca_cert, ca_cert_size);
+     660                 :            : 
+     661         [ +  - ]:       2255 :     if (ret == 0) {
+     662                 :       2255 :         ret = mbedtls_x509_crt_parse_der(&end, cert, cert_size);
+     663                 :            :     }
+     664                 :            : 
+     665         [ +  - ]:       2255 :     if (ret == 0) {
+     666                 :       2255 :         ret = mbedtls_x509_crt_verify_with_profile(
+     667                 :            :             &end, &ca, NULL, &profile, NULL, &v_flag, NULL, NULL);
+     668                 :            :     }
+     669                 :            : 
+     670                 :       2255 :     mbedtls_x509_crt_free(&ca);
+     671                 :       2255 :     mbedtls_x509_crt_free(&end);
+     672                 :            : 
+     673                 :       2255 :     return ret == 0;
+     674                 :            : }
+     675                 :            : 
+     676                 :            : /**
+     677                 :            :  * Verify one X509 certificate was issued by the trusted CA.
+     678                 :            :  *
+     679                 :            :  * @param[in]      cert_chain         One or more ASN.1 DER-encoded X.509 certificates
+     680                 :            :  *                                  where the first certificate is signed by the Root
+     681                 :            :  *                                  Certificate or is the Root Cerificate itself. and
+     682                 :            :  *                                  subsequent cerificate is signed by the preceding
+     683                 :            :  *                                  cerificate.
+     684                 :            :  * @param[in]      cert_chain_length   Total length of the certificate chain, in bytes.
+     685                 :            :  *
+     686                 :            :  * @param[in]      root_cert          Trusted Root Certificate buffer
+     687                 :            :  *
+     688                 :            :  * @param[in]      root_cert_length    Trusted Root Certificate buffer length
+     689                 :            :  *
+     690                 :            :  * @retval  true   All cerificates was issued by the first certificate in X509Certchain.
+     691                 :            :  * @retval  false  Invalid certificate or the certificate was not issued by the given
+     692                 :            :  *                trusted CA.
+     693                 :            :  **/
+     694                 :        705 : bool libspdm_x509_verify_cert_chain(const uint8_t *root_cert, size_t root_cert_length,
+     695                 :            :                                     const uint8_t *cert_chain, size_t cert_chain_length)
+     696                 :            : {
+     697                 :            :     size_t asn1_len;
+     698                 :            :     size_t preceding_cert_len;
+     699                 :            :     const uint8_t *preceding_cert;
+     700                 :            :     size_t current_cert_len;
+     701                 :            :     const unsigned char *current_cert;
+     702                 :            :     const unsigned char *tmp_ptr;
+     703                 :            :     int ret;
+     704                 :            :     bool verify_flag;
+     705                 :            : 
+     706                 :        705 :     verify_flag = false;
+     707                 :        705 :     preceding_cert = root_cert;
+     708                 :        705 :     preceding_cert_len = root_cert_length;
+     709                 :            : 
+     710                 :        705 :     current_cert = (const unsigned char *)cert_chain;
+     711                 :            : 
+     712                 :            : 
+     713                 :            :     /* Get Current certificate from certificates buffer and Verify with preciding cert*/
+     714                 :            : 
+     715                 :            :     do {
+     716                 :       2956 :         tmp_ptr = current_cert;
+     717                 :       2956 :         ret = mbedtls_asn1_get_tag(
+     718                 :       2956 :             &tmp_ptr, cert_chain + cert_chain_length, &asn1_len,
+     719                 :            :             MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE);
+     720         [ +  + ]:       2956 :         if (ret != 0) {
+     721         [ +  + ]:        702 :             if (current_cert < cert_chain + cert_chain_length) {
+     722                 :          2 :                 verify_flag = false;
+     723                 :            :             }
+     724                 :        702 :             break;
+     725                 :            :         }
+     726                 :            : 
+     727                 :       2254 :         current_cert_len = asn1_len + (tmp_ptr - current_cert);
+     728                 :            : 
+     729         [ -  + ]:       2254 :         if (current_cert + current_cert_len > cert_chain + cert_chain_length) {
+     730                 :          0 :             verify_flag = false;
+     731                 :          0 :             break;
+     732                 :            :         }
+     733                 :            : 
+     734                 :       2254 :         if (libspdm_x509_verify_cert(current_cert, current_cert_len,
+     735                 :            :                                      preceding_cert,
+     736         [ +  + ]:       2254 :                                      preceding_cert_len) == false) {
+     737                 :          3 :             verify_flag = false;
+     738                 :          3 :             break;
+     739                 :            :         } else {
+     740                 :       2251 :             verify_flag = true;
+     741                 :            :         }
+     742                 :            : 
+     743                 :            : 
+     744                 :            :         /* Save preceding certificate*/
+     745                 :            : 
+     746                 :       2251 :         preceding_cert = current_cert;
+     747                 :       2251 :         preceding_cert_len = current_cert_len;
+     748                 :            : 
+     749                 :            : 
+     750                 :            :         /* Move current certificate to next;*/
+     751                 :            : 
+     752                 :       2251 :         current_cert = current_cert + current_cert_len;
+     753                 :            :     } while (true);
+     754                 :            : 
+     755                 :        705 :     return verify_flag;
+     756                 :            : }
+     757                 :            : 
+     758                 :            : /**
+     759                 :            :  * Get one X509 certificate from cert_chain.
+     760                 :            :  *
+     761                 :            :  * @param[in]      cert_chain         One or more ASN.1 DER-encoded X.509 certificates
+     762                 :            :  *                                  where the first certificate is signed by the Root
+     763                 :            :  *                                  Certificate or is the Root Cerificate itself. and
+     764                 :            :  *                                  subsequent cerificate is signed by the preceding
+     765                 :            :  *                                  cerificate.
+     766                 :            :  * @param[in]      cert_chain_length   Total length of the certificate chain, in bytes.
+     767                 :            :  *
+     768                 :            :  * @param[in]      cert_index         index of certificate.
+     769                 :            :  *
+     770                 :            :  * @param[out]     cert              The certificate at the index of cert_chain.
+     771                 :            :  * @param[out]     cert_length        The length certificate at the index of cert_chain.
+     772                 :            :  *
+     773                 :            :  * @retval  true   Success.
+     774                 :            :  * @retval  false  Failed to get certificate from certificate chain.
+     775                 :            :  **/
+     776                 :       2334 : bool libspdm_x509_get_cert_from_cert_chain(const uint8_t *cert_chain,
+     777                 :            :                                            size_t cert_chain_length,
+     778                 :            :                                            const int32_t cert_index, const uint8_t **cert,
+     779                 :            :                                            size_t *cert_length)
+     780                 :            : {
+     781                 :            :     size_t asn1_len;
+     782                 :            :     int32_t current_index;
+     783                 :            :     size_t current_cert_len;
+     784                 :            :     const unsigned char *current_cert;
+     785                 :            :     const unsigned char *tmp_ptr;
+     786                 :            :     int ret;
+     787                 :            : 
+     788                 :       2334 :     current_cert_len = 0;
+     789                 :            : 
+     790                 :            :     /* Check input parameters.*/
+     791                 :            : 
+     792   [ +  -  +  -  :       2334 :     if ((cert_chain == NULL) || (cert == NULL) || (cert_index < -1) ||
+             +  -  -  + ]
+     793                 :            :         (cert_length == NULL)) {
+     794                 :          0 :         return false;
+     795                 :            :     }
+     796                 :            : 
+     797                 :       2334 :     current_cert = (const unsigned char *)cert_chain;
+     798                 :       2334 :     current_index = -1;
+     799                 :            : 
+     800                 :            : 
+     801                 :            :     /* Traverse the certificate chain*/
+     802                 :            : 
+     803                 :            :     while (true) {
+     804                 :            : 
+     805                 :            :         /* Get asn1 tag len*/
+     806                 :            : 
+     807                 :       5240 :         tmp_ptr = current_cert;
+     808                 :       5240 :         ret = mbedtls_asn1_get_tag(
+     809                 :       5240 :             &tmp_ptr, cert_chain + cert_chain_length, &asn1_len,
+     810                 :            :             MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE);
+     811         [ +  + ]:       5240 :         if (ret != 0) {
+     812                 :        910 :             break;
+     813                 :            :         }
+     814                 :            : 
+     815                 :       4330 :         current_cert_len = asn1_len + (tmp_ptr - current_cert);
+     816         [ -  + ]:       4330 :         if (current_cert + current_cert_len > cert_chain + cert_chain_length) {
+     817                 :          0 :             return false;
+     818                 :            :         }
+     819                 :            : 
+     820                 :       4330 :         current_index++;
+     821                 :            : 
+     822         [ +  + ]:       4330 :         if (current_index == cert_index) {
+     823                 :       1424 :             *cert = current_cert;
+     824                 :       1424 :             *cert_length = current_cert_len;
+     825                 :       1424 :             return true;
+     826                 :            :         }
+     827                 :            : 
+     828                 :            : 
+     829                 :            :         /* Move to next*/
+     830                 :            : 
+     831                 :       2906 :         current_cert = current_cert + current_cert_len;
+     832                 :            :     }
+     833                 :            : 
+     834                 :            : 
+     835                 :            :     /* If cert_index is -1, Return the last certificate*/
+     836                 :            : 
+     837   [ +  -  +  - ]:        910 :     if (cert_index == -1 && current_index >= 0) {
+     838                 :        910 :         *cert = current_cert - current_cert_len;
+     839                 :        910 :         *cert_length = current_cert_len;
+     840                 :        910 :         return true;
+     841                 :            :     }
+     842                 :            : 
+     843                 :          0 :     return false;
+     844                 :            : }
+     845                 :            : 
+     846                 :            : /**
+     847                 :            :  * Retrieve the TBSCertificate from one given X.509 certificate.
+     848                 :            :  *
+     849                 :            :  * @param[in]      cert         Pointer to the given DER-encoded X509 certificate.
+     850                 :            :  * @param[in]      cert_size     size of the X509 certificate in bytes.
+     851                 :            :  * @param[out]     tbs_cert      DER-Encoded to-Be-Signed certificate.
+     852                 :            :  * @param[out]     tbs_cert_size  size of the TBS certificate in bytes.
+     853                 :            :  *
+     854                 :            :  * If cert is NULL, then return false.
+     855                 :            :  * If tbs_cert is NULL, then return false.
+     856                 :            :  * If tbs_cert_size is NULL, then return false.
+     857                 :            :  *
+     858                 :            :  * @retval  true   The TBSCertificate was retrieved successfully.
+     859                 :            :  * @retval  false  Invalid X.509 certificate.
+     860                 :            :  *
+     861                 :            :  **/
+     862                 :          0 : bool libspdm_x509_get_tbs_cert(const uint8_t *cert, size_t cert_size,
+     863                 :            :                                uint8_t **tbs_cert, size_t *tbs_cert_size)
+     864                 :            : {
+     865                 :          0 :     return false;
+     866                 :            : }
+     867                 :            : 
+     868                 :            : /**
+     869                 :            :  * Retrieve the version from one X.509 certificate.
+     870                 :            :  *
+     871                 :            :  * If cert is NULL, then return false.
+     872                 :            :  * If cert_size is 0, then return false.
+     873                 :            :  * If this interface is not supported, then return false.
+     874                 :            :  *
+     875                 :            :  * @param[in]      cert         Pointer to the DER-encoded X509 certificate.
+     876                 :            :  * @param[in]      cert_size     size of the X509 certificate in bytes.
+     877                 :            :  * @param[out]     version      Pointer to the retrieved version integer.
+     878                 :            :  *
+     879                 :            :  * @retval RETURN_SUCCESS           The certificate version retrieved successfully.
+     880                 :            :  * @retval RETURN_INVALID_PARAMETER If  cert is NULL or cert_size is Zero.
+     881                 :            :  * @retval RETURN_UNSUPPORTED       The operation is not supported.
+     882                 :            :  *
+     883                 :            :  **/
+     884                 :        730 : bool libspdm_x509_get_version(const uint8_t *cert, size_t cert_size,
+     885                 :            :                               size_t *version)
+     886                 :            : {
+     887                 :            :     mbedtls_x509_crt crt;
+     888                 :            :     int ret;
+     889                 :            :     bool status;
+     890                 :            : 
+     891         [ -  + ]:        730 :     if (cert == NULL) {
+     892                 :          0 :         return false;
+     893                 :            :     }
+     894                 :            : 
+     895                 :        730 :     status = false;
+     896                 :            : 
+     897                 :        730 :     mbedtls_x509_crt_init(&crt);
+     898                 :            : 
+     899                 :        730 :     ret = mbedtls_x509_crt_parse_der(&crt, cert, cert_size);
+     900                 :            : 
+     901         [ +  - ]:        730 :     if (ret == 0) {
+     902                 :        730 :         *version = crt.version - 1;
+     903                 :        730 :         status = true;
+     904                 :            :     }
+     905                 :            : 
+     906                 :        730 :     mbedtls_x509_crt_free(&crt);
+     907                 :            : 
+     908                 :        730 :     return status;
+     909                 :            : }
+     910                 :            : 
+     911                 :            : /**
+     912                 :            :  * Retrieve the serialNumber from one X.509 certificate.
+     913                 :            :  *
+     914                 :            :  * If cert is NULL, then return false.
+     915                 :            :  * If cert_size is 0, then return false.
+     916                 :            :  * If this interface is not supported, then return false.
+     917                 :            :  *
+     918                 :            :  * @param[in]      cert         Pointer to the DER-encoded X509 certificate.
+     919                 :            :  * @param[in]      cert_size     size of the X509 certificate in bytes.
+     920                 :            :  * @param[out]     serial_number  Pointer to the retrieved certificate serial_number bytes.
+     921                 :            :  * @param[in, out] serial_number_size  The size in bytes of the serial_number buffer on input,
+     922                 :            :  *                             and the size of buffer returned serial_number on output.
+     923                 :            :  *
+     924                 :            :  * @retval RETURN_SUCCESS           The certificate serialNumber retrieved successfully.
+     925                 :            :  * @retval RETURN_INVALID_PARAMETER If cert is NULL or cert_size is Zero.
+     926                 :            :  *                                 If serial_number_size is NULL.
+     927                 :            :  *                                 If Certificate is invalid.
+     928                 :            :  * @retval RETURN_NOT_FOUND         If no serial_number exists.
+     929                 :            :  * @retval RETURN_BUFFER_TOO_SMALL  If the serial_number is NULL. The required buffer size
+     930                 :            :  *                                 (including the final null) is returned in the
+     931                 :            :  *                                 serial_number_size parameter.
+     932                 :            :  * @retval RETURN_UNSUPPORTED       The operation is not supported.
+     933                 :            :  **/
+     934                 :        730 : bool libspdm_x509_get_serial_number(const uint8_t *cert, size_t cert_size,
+     935                 :            :                                     uint8_t *serial_number,
+     936                 :            :                                     size_t *serial_number_size)
+     937                 :            : {
+     938                 :            :     mbedtls_x509_crt crt;
+     939                 :            :     int ret;
+     940                 :            :     bool status;
+     941                 :            : 
+     942         [ -  + ]:        730 :     if (cert == NULL) {
+     943                 :          0 :         return false;
+     944                 :            :     }
+     945                 :            : 
+     946                 :        730 :     status = false;
+     947                 :            : 
+     948                 :        730 :     mbedtls_x509_crt_init(&crt);
+     949                 :            : 
+     950                 :        730 :     ret = mbedtls_x509_crt_parse_der(&crt, cert, cert_size);
+     951                 :            : 
+     952         [ -  + ]:        730 :     if (ret == 0) {
+     953         [ +  - ]:        730 :         if (*serial_number_size <= crt.serial.len) {
+     954                 :        730 :             *serial_number_size = crt.serial.len + 1;
+     955                 :        730 :             status = false;
+     956                 :        730 :             goto cleanup;
+     957                 :            :         }
+     958         [ #  # ]:          0 :         if (serial_number != NULL) {
+     959                 :          0 :             libspdm_copy_mem(serial_number, *serial_number_size, crt.serial.p, crt.serial.len);
+     960                 :          0 :             serial_number[crt.serial.len] = '\0';
+     961                 :            :         }
+     962                 :          0 :         *serial_number_size = crt.serial.len + 1;
+     963                 :          0 :         status = true;
+     964                 :            :     }
+     965                 :          0 : cleanup:
+     966                 :        730 :     mbedtls_x509_crt_free(&crt);
+     967                 :            : 
+     968                 :        730 :     return status;
+     969                 :            : }
+     970                 :            : 
+     971                 :            : /**
+     972                 :            :  * Retrieve the issuer bytes from one X.509 certificate.
+     973                 :            :  *
+     974                 :            :  * If cert is NULL, then return false.
+     975                 :            :  * If issuer_size is NULL, then return false.
+     976                 :            :  * If this interface is not supported, then return false.
+     977                 :            :  *
+     978                 :            :  * @param[in]      cert         Pointer to the DER-encoded X509 certificate.
+     979                 :            :  * @param[in]      cert_size     size of the X509 certificate in bytes.
+     980                 :            :  * @param[out]     cert_issuer  Pointer to the retrieved certificate subject bytes.
+     981                 :            :  * @param[in, out] issuer_size  The size in bytes of the cert_issuer buffer on input,
+     982                 :            :  *                             and the size of buffer returned cert_issuer on output.
+     983                 :            :  *
+     984                 :            :  * @retval  true   If the issuer_size is not equal 0. The certificate issuer retrieved successfully.
+     985                 :            :  * @retval  true   If the issuer_size is equal 0. The certificate parse successful. But the cert doesn't have issuer.
+     986                 :            :  * @retval  false  If the issuer_size is not equal 0. The certificate issuer retrieved successfully. But the issuer_size is too small for the result.
+     987                 :            :  * @retval  false  If the issuer_size is equal 0. Invalid certificate.
+     988                 :            :  *
+     989                 :            :  **/
+     990                 :        787 : bool libspdm_x509_get_issuer_name(const uint8_t *cert, size_t cert_size,
+     991                 :            :                                   uint8_t *cert_issuer,
+     992                 :            :                                   size_t *issuer_size)
+     993                 :            : {
+     994                 :            :     mbedtls_x509_crt crt;
+     995                 :            :     int ret;
+     996                 :            :     bool status;
+     997                 :            : 
+     998                 :            :     /* Check input parameters.*/
+     999   [ +  -  +  -  :        787 :     if (cert == NULL || cert_size == 0 || issuer_size == NULL) {
+                   -  + ]
+    1000         [ #  # ]:          0 :         if (issuer_size != NULL) {
+    1001                 :          0 :             *issuer_size = 0;
+    1002                 :            :         }
+    1003                 :          0 :         return false;
+    1004                 :            :     }
+    1005                 :            : 
+    1006                 :        787 :     status = false;
+    1007                 :            : 
+    1008                 :        787 :     mbedtls_x509_crt_init(&crt);
+    1009                 :            : 
+    1010                 :        787 :     ret = mbedtls_x509_crt_parse_der(&crt, cert, cert_size);
+    1011                 :            : 
+    1012         [ +  - ]:        787 :     if (ret == 0) {
+    1013         [ +  + ]:        787 :         if (*issuer_size < crt.issuer_raw.len) {
+    1014                 :        728 :             *issuer_size = crt.issuer_raw.len;
+    1015                 :        728 :             status = false;
+    1016                 :        728 :             goto cleanup;
+    1017                 :            :         }
+    1018         [ +  - ]:         59 :         if (cert_issuer != NULL) {
+    1019                 :         59 :             libspdm_copy_mem(cert_issuer, *issuer_size, crt.issuer_raw.p, crt.issuer_raw.len);
+    1020                 :            :         }
+    1021                 :         59 :         *issuer_size = crt.issuer_raw.len;
+    1022                 :         59 :         status = true;
+    1023                 :            :     } else {
+    1024                 :          0 :         *issuer_size = 0;
+    1025                 :            :     }
+    1026                 :            : 
+    1027                 :        787 : cleanup:
+    1028                 :        787 :     mbedtls_x509_crt_free(&crt);
+    1029                 :            : 
+    1030                 :        787 :     return status;
+    1031                 :            : }
+    1032                 :            : 
+    1033                 :            : /**
+    1034                 :            :  * Retrieve the issuer common name (CN) string from one X.509 certificate.
+    1035                 :            :  *
+    1036                 :            :  * @param[in]      cert             Pointer to the DER-encoded X509 certificate.
+    1037                 :            :  * @param[in]      cert_size         size of the X509 certificate in bytes.
+    1038                 :            :  * @param[out]     common_name       buffer to contain the retrieved certificate issuer common
+    1039                 :            :  *                                 name string. At most common_name_size bytes will be
+    1040                 :            :  *                                 written and the string will be null terminated. May be
+    1041                 :            :  *                                 NULL in order to determine the size buffer needed.
+    1042                 :            :  * @param[in,out]  common_name_size   The size in bytes of the common_name buffer on input,
+    1043                 :            :  *                                 and the size of buffer returned common_name on output.
+    1044                 :            :  *                                 If common_name is NULL then the amount of space needed
+    1045                 :            :  *                                 in buffer (including the final null) is returned.
+    1046                 :            :  *
+    1047                 :            :  * @retval RETURN_SUCCESS           The certificate Issuer common_name retrieved successfully.
+    1048                 :            :  * @retval RETURN_INVALID_PARAMETER If cert is NULL.
+    1049                 :            :  *                                 If common_name_size is NULL.
+    1050                 :            :  *                                 If common_name is not NULL and *common_name_size is 0.
+    1051                 :            :  *                                 If Certificate is invalid.
+    1052                 :            :  * @retval RETURN_NOT_FOUND         If no common_name entry exists.
+    1053                 :            :  * @retval RETURN_BUFFER_TOO_SMALL  If the common_name is NULL. The required buffer size
+    1054                 :            :  *                                 (including the final null) is returned in the
+    1055                 :            :  *                                 common_name_size parameter.
+    1056                 :            :  * @retval RETURN_UNSUPPORTED       The operation is not supported.
+    1057                 :            :  *
+    1058                 :            :  **/
+    1059                 :            : bool
+    1060                 :          0 : libspdm_x509_get_issuer_common_name(const uint8_t *cert, size_t cert_size,
+    1061                 :            :                                     char *common_name,
+    1062                 :            :                                     size_t *common_name_size)
+    1063                 :            : {
+    1064                 :          0 :     return libspdm_internal_x509_get_issuer_nid_name(cert, cert_size,
+    1065                 :            :                                                      m_libspdm_oid_common_name,
+    1066                 :            :                                                      sizeof(m_libspdm_oid_common_name),
+    1067                 :            :                                                      common_name, common_name_size);
+    1068                 :            : }
+    1069                 :            : 
+    1070                 :            : /**
+    1071                 :            :  * Retrieve the issuer organization name (O) string from one X.509 certificate.
+    1072                 :            :  *
+    1073                 :            :  * @param[in]      cert             Pointer to the DER-encoded X509 certificate.
+    1074                 :            :  * @param[in]      cert_size         size of the X509 certificate in bytes.
+    1075                 :            :  * @param[out]     name_buffer       buffer to contain the retrieved certificate issuer organization
+    1076                 :            :  *                                 name string. At most name_buffer_size bytes will be
+    1077                 :            :  *                                 written and the string will be null terminated. May be
+    1078                 :            :  *                                 NULL in order to determine the size buffer needed.
+    1079                 :            :  * @param[in,out]  name_buffer_size   The size in bytes of the name buffer on input,
+    1080                 :            :  *                                 and the size of buffer returned name on output.
+    1081                 :            :  *                                 If name_buffer is NULL then the amount of space needed
+    1082                 :            :  *                                 in buffer (including the final null) is returned.
+    1083                 :            :  *
+    1084                 :            :  * @retval RETURN_SUCCESS           The certificate issuer Organization name retrieved successfully.
+    1085                 :            :  * @retval RETURN_INVALID_PARAMETER If cert is NULL.
+    1086                 :            :  *                                 If name_buffer_size is NULL.
+    1087                 :            :  *                                 If name_buffer is not NULL and *common_name_size is 0.
+    1088                 :            :  *                                 If Certificate is invalid.
+    1089                 :            :  * @retval RETURN_NOT_FOUND         If no Organization name entry exists.
+    1090                 :            :  * @retval RETURN_BUFFER_TOO_SMALL  If the name_buffer is NULL. The required buffer size
+    1091                 :            :  *                                 (including the final null) is returned in the
+    1092                 :            :  *                                 common_name_size parameter.
+    1093                 :            :  * @retval RETURN_UNSUPPORTED       The operation is not supported.
+    1094                 :            :  *
+    1095                 :            :  **/
+    1096                 :            : bool
+    1097                 :          0 : libspdm_x509_get_issuer_orgnization_name(const uint8_t *cert, size_t cert_size,
+    1098                 :            :                                          char *name_buffer,
+    1099                 :            :                                          size_t *name_buffer_size)
+    1100                 :            : {
+    1101                 :          0 :     return libspdm_internal_x509_get_issuer_nid_name(
+    1102                 :            :         cert, cert_size, m_libspdm_oid_organization_name,
+    1103                 :            :         sizeof(m_libspdm_oid_organization_name), name_buffer, name_buffer_size);
+    1104                 :            : }
+    1105                 :            : 
+    1106                 :            : #if LIBSPDM_ADDITIONAL_CHECK_CERT
+    1107                 :            : /**
+    1108                 :            :  * Retrieve the signature algorithm from one X.509 certificate.
+    1109                 :            :  *
+    1110                 :            :  * @param[in]      cert             Pointer to the DER-encoded X509 certificate.
+    1111                 :            :  * @param[in]      cert_size         size of the X509 certificate in bytes.
+    1112                 :            :  * @param[out]     oid              signature algorithm Object identifier buffer.
+    1113                 :            :  * @param[in,out]  oid_size          signature algorithm Object identifier buffer size
+    1114                 :            :  *
+    1115                 :            :  * @retval  true    if the oid_size is equal 0, the cert parse successfully, but cert doesn't have signature algo.
+    1116                 :            :  * @retval  true    if the oid_size is not equal 0, the cert parse and get signature algo successfully.
+    1117                 :            :  * @retval  false   if the oid_size is equal 0, the cert parse failed.
+    1118                 :            :  * @retval  false   if the oid_size is not equal 0, the cert parse and get signature algo successfully, but the input buffer size is small.
+    1119                 :            :  **/
+    1120                 :            : bool libspdm_x509_get_signature_algorithm(const uint8_t *cert,
+    1121                 :            :                                           size_t cert_size, uint8_t *oid,
+    1122                 :            :                                           size_t *oid_size)
+    1123                 :            : {
+    1124                 :            :     mbedtls_x509_crt crt;
+    1125                 :            :     int ret;
+    1126                 :            :     bool status;
+    1127                 :            : 
+    1128                 :            :     /* Check input parameters.*/
+    1129                 :            :     if (cert == NULL || cert_size == 0 || oid_size == NULL) {
+    1130                 :            :         if (oid_size != NULL) {
+    1131                 :            :             *oid_size = 0;
+    1132                 :            :         }
+    1133                 :            :         return false;
+    1134                 :            :     }
+    1135                 :            : 
+    1136                 :            :     status = false;
+    1137                 :            : 
+    1138                 :            :     mbedtls_x509_crt_init(&crt);
+    1139                 :            : 
+    1140                 :            :     ret = mbedtls_x509_crt_parse_der(&crt, cert, cert_size);
+    1141                 :            : 
+    1142                 :            :     if (ret == 0) {
+    1143                 :            :         if (*oid_size < crt.sig_oid.len) {
+    1144                 :            :             *oid_size = crt.serial.len;
+    1145                 :            :             status = false;
+    1146                 :            :             goto cleanup;
+    1147                 :            :         }
+    1148                 :            :         if (oid != NULL) {
+    1149                 :            :             libspdm_copy_mem(oid, *oid_size, crt.sig_oid.p, crt.sig_oid.len);
+    1150                 :            :         }
+    1151                 :            :         *oid_size = crt.sig_oid.len;
+    1152                 :            :         status = true;
+    1153                 :            :     } else {
+    1154                 :            :         *oid_size = 0;
+    1155                 :            :     }
+    1156                 :            : 
+    1157                 :            : cleanup:
+    1158                 :            :     mbedtls_x509_crt_free(&crt);
+    1159                 :            : 
+    1160                 :            :     return status;
+    1161                 :            : }
+    1162                 :            : #endif /* LIBSPDM_ADDITIONAL_CHECK_CERT */
+    1163                 :            : 
+    1164                 :            : /**
+    1165                 :            :  * Find first Extension data match with given OID
+    1166                 :            :  *
+    1167                 :            :  * @param[in]      start             Pointer to the DER-encoded extensions data
+    1168                 :            :  * @param[in]      end               extensions data size in bytes
+    1169                 :            :  * @param[in ]     oid               OID for match
+    1170                 :            :  * @param[in ]     oid_size           OID size in bytes
+    1171                 :            :  * @param[out]     find_extension_data output matched extension data.
+    1172                 :            :  * @param[out]     find_extension_data_len matched extension data size.
+    1173                 :            :  *
+    1174                 :            :  **/
+    1175                 :            : static bool
+    1176                 :       2182 : libspdm_internal_x509_find_extension_data(uint8_t *start, uint8_t *end, const uint8_t *oid,
+    1177                 :            :                                           size_t oid_size, uint8_t **find_extension_data,
+    1178                 :            :                                           size_t *find_extension_data_len)
+    1179                 :            : {
+    1180                 :            :     uint8_t *ptr;
+    1181                 :            :     uint8_t *extension_ptr;
+    1182                 :            :     size_t obj_len;
+    1183                 :            :     int ret;
+    1184                 :            :     bool status;
+    1185                 :            :     size_t find_extension_len;
+    1186                 :            :     size_t header_len;
+    1187                 :            : 
+    1188                 :            :     /*If no Extension entry match oid*/
+    1189                 :       2182 :     status = false;
+    1190                 :       2182 :     ptr = start;
+    1191                 :            : 
+    1192                 :       2182 :     ret = 0;
+    1193                 :            : 
+    1194                 :            :     while (true) {
+    1195                 :            :         /*
+    1196                 :            :          * Extension  ::=  SEQUENCE  {
+    1197                 :            :          *      extnID      OBJECT IDENTIFIER,
+    1198                 :            :          *      critical    bool DEFAULT false,
+    1199                 :            :          *      extnValue   OCTET STRING  }
+    1200                 :            :          */
+    1201                 :       8759 :         extension_ptr = ptr;
+    1202                 :       8759 :         ret = mbedtls_asn1_get_tag(&ptr, end, &obj_len,
+    1203                 :            :                                    MBEDTLS_ASN1_CONSTRUCTED |
+    1204                 :            :                                    MBEDTLS_ASN1_SEQUENCE);
+    1205         [ +  + ]:       8759 :         if (ret == 0) {
+    1206                 :       8744 :             header_len = (size_t)(ptr - extension_ptr);
+    1207                 :       8744 :             find_extension_len = obj_len;
+    1208                 :            :             /* Get Object Identifier*/
+    1209                 :       8744 :             ret = mbedtls_asn1_get_tag(&ptr, end, &obj_len,
+    1210                 :            :                                        MBEDTLS_ASN1_OID);
+    1211                 :            :         } else {
+    1212                 :         15 :             break;
+    1213                 :            :         }
+    1214                 :            : 
+    1215   [ +  -  +  + ]:       8744 :         if (ret == 0 && libspdm_consttime_is_mem_equal(ptr, oid, oid_size)) {
+    1216                 :       2167 :             ptr += obj_len;
+    1217                 :            : 
+    1218                 :       2167 :             ret = mbedtls_asn1_get_tag(&ptr, end, &obj_len,
+    1219                 :            :                                        MBEDTLS_ASN1_BOOLEAN);
+    1220         [ +  + ]:       2167 :             if (ret == 0) {
+    1221                 :       1443 :                 ptr += obj_len;
+    1222                 :            :             }
+    1223                 :            : 
+    1224                 :       2167 :             ret = mbedtls_asn1_get_tag(&ptr, end, &obj_len,
+    1225                 :            :                                        MBEDTLS_ASN1_OCTET_STRING);
+    1226                 :            :         } else {
+    1227                 :       6577 :             ret = 1;
+    1228                 :            :         }
+    1229                 :            : 
+    1230         [ +  + ]:       8744 :         if (ret == 0) {
+    1231                 :       2167 :             *find_extension_data = ptr;
+    1232                 :       2167 :             *find_extension_data_len = obj_len;
+    1233                 :       2167 :             status = true;
+    1234                 :       2167 :             break;
+    1235                 :            :         }
+    1236                 :            : 
+    1237                 :            :         /* move to next*/
+    1238                 :       6577 :         ptr = extension_ptr + header_len + find_extension_len;
+    1239                 :       6577 :         ret = 0;
+    1240                 :            :     }
+    1241                 :            : 
+    1242                 :       2182 :     return status;
+    1243                 :            : }
+    1244                 :            : 
+    1245                 :            : /**
+    1246                 :            :  * Retrieve Extension data from one X.509 certificate.
+    1247                 :            :  *
+    1248                 :            :  * @param[in]      cert             Pointer to the DER-encoded X509 certificate.
+    1249                 :            :  * @param[in]      cert_size         size of the X509 certificate in bytes.
+    1250                 :            :  * @param[in]      oid              Object identifier buffer
+    1251                 :            :  * @param[in]      oid_size          Object identifier buffer size
+    1252                 :            :  * @param[out]     extension_data    Extension bytes.
+    1253                 :            :  * @param[in, out] extension_data_size Extension bytes size.
+    1254                 :            :  *
+    1255                 :            :  * @retval true   If the returned extension_data_size == 0, it means that cert and oid are valid, but the oid extension is not found;
+    1256                 :            :  *                If the returned extension_data_size != 0, it means that cert and oid are valid, and the oid extension is found;
+    1257                 :            :  * @retval false  If the returned extension_data_size == 0, it means that cert or oid are invalid;
+    1258                 :            :  *                If the returned extension_data_size != 0, it means that cert and oid are valid, and the oid extension is found,
+    1259                 :            :  *                                                          but the store buffer is too small.
+    1260                 :            :  **/
+    1261                 :       2182 : bool libspdm_x509_get_extension_data(const uint8_t *cert, size_t cert_size,
+    1262                 :            :                                      const uint8_t *oid, size_t oid_size,
+    1263                 :            :                                      uint8_t *extension_data,
+    1264                 :            :                                      size_t *extension_data_size)
+    1265                 :            : {
+    1266                 :            :     mbedtls_x509_crt crt;
+    1267                 :            :     int ret;
+    1268                 :            :     bool status;
+    1269                 :            :     uint8_t *ptr;
+    1270                 :            :     uint8_t *end;
+    1271                 :            :     size_t obj_len;
+    1272                 :            : 
+    1273                 :       2182 :     ptr = NULL;
+    1274                 :       2182 :     end = NULL;
+    1275                 :       2182 :     obj_len = 0;
+    1276                 :            : 
+    1277   [ +  -  +  -  :       2182 :     if (cert == NULL || cert_size == 0 || oid == NULL || oid_size == 0 ||
+          +  -  +  -  -  
+                      + ]
+    1278                 :            :         extension_data_size == NULL) {
+    1279         [ #  # ]:          0 :         if (extension_data_size != NULL) {
+    1280                 :          0 :             *extension_data_size = 0;
+    1281                 :            :         }
+    1282                 :          0 :         return false;
+    1283                 :            :     }
+    1284                 :            : 
+    1285                 :       2182 :     status = false;
+    1286                 :            : 
+    1287                 :       2182 :     mbedtls_x509_crt_init(&crt);
+    1288                 :            : 
+    1289                 :       2182 :     ret = mbedtls_x509_crt_parse_der(&crt, cert, cert_size);
+    1290                 :            : 
+    1291         [ +  - ]:       2182 :     if (ret == 0) {
+    1292                 :       2182 :         ptr = crt.v3_ext.p;
+    1293                 :       2182 :         end = crt.v3_ext.p + crt.v3_ext.len;
+    1294                 :       2182 :         ret = mbedtls_asn1_get_tag(&ptr, end, &obj_len,
+    1295                 :            :                                    MBEDTLS_ASN1_CONSTRUCTED |
+    1296                 :            :                                    MBEDTLS_ASN1_SEQUENCE);
+    1297                 :            :     }
+    1298                 :            : 
+    1299         [ +  - ]:       2182 :     if (ret == 0) {
+    1300                 :       2182 :         status = libspdm_internal_x509_find_extension_data(
+    1301                 :            :             ptr, end, oid, oid_size, &ptr, &obj_len);
+    1302         [ +  + ]:       2182 :         if (!status) {
+    1303                 :         15 :             status = true;
+    1304                 :         15 :             *extension_data_size = 0;
+    1305                 :         15 :             goto cleanup;
+    1306                 :            :         }
+    1307                 :            :     }
+    1308                 :            : 
+    1309         [ +  - ]:       2167 :     if (status) {
+    1310         [ +  + ]:       2167 :         if (*extension_data_size < obj_len) {
+    1311                 :          6 :             *extension_data_size = obj_len;
+    1312                 :          6 :             status = false;
+    1313                 :          6 :             goto cleanup;
+    1314                 :            :         }
+    1315         [ +  - ]:       2161 :         if (oid != NULL) {
+    1316                 :       2161 :             libspdm_copy_mem(extension_data, *extension_data_size, ptr, obj_len);
+    1317                 :            :         }
+    1318                 :       2161 :         *extension_data_size = obj_len;
+    1319                 :            :     } else {
+    1320                 :          0 :         *extension_data_size = 0;
+    1321                 :            :     }
+    1322                 :            : 
+    1323                 :       2182 : cleanup:
+    1324                 :       2182 :     mbedtls_x509_crt_free(&crt);
+    1325                 :            : 
+    1326                 :       2182 :     return status;
+    1327                 :            : }
+    1328                 :            : 
+    1329                 :            : /**
+    1330                 :            :  * Retrieve the Validity from one X.509 certificate
+    1331                 :            :  *
+    1332                 :            :  * If cert is NULL, then return false.
+    1333                 :            :  * If CertIssuerSize is NULL, then return false.
+    1334                 :            :  * If this interface is not supported, then return false.
+    1335                 :            :  *
+    1336                 :            :  * @param[in]      cert         Pointer to the DER-encoded X509 certificate.
+    1337                 :            :  * @param[in]      cert_size     size of the X509 certificate in bytes.
+    1338                 :            :  * @param[out]     from         notBefore Pointer to date_time object.
+    1339                 :            :  * @param[in,out]  from_size     notBefore date_time object size.
+    1340                 :            :  * @param[out]     to           notAfter Pointer to date_time object.
+    1341                 :            :  * @param[in,out]  to_size       notAfter date_time object size.
+    1342                 :            :  *
+    1343                 :            :  * Note: libspdm_x509_compare_date_time to compare date_time oject
+    1344                 :            :  *      x509SetDateTime to get a date_time object from a date_time_str
+    1345                 :            :  *
+    1346                 :            :  * @retval  true   The certificate Validity retrieved successfully.
+    1347                 :            :  * @retval  false  Invalid certificate, or Validity retrieve failed.
+    1348                 :            :  * @retval  false  This interface is not supported.
+    1349                 :            :  **/
+    1350                 :        728 : bool libspdm_x509_get_validity(const uint8_t *cert, size_t cert_size,
+    1351                 :            :                                uint8_t *from, size_t *from_size, uint8_t *to,
+    1352                 :            :                                size_t *to_size)
+    1353                 :            : {
+    1354                 :            :     mbedtls_x509_crt crt;
+    1355                 :            :     int ret;
+    1356                 :            :     bool status;
+    1357                 :            :     size_t t_size;
+    1358                 :            :     size_t f_size;
+    1359                 :            :     mbedtls_x509_time zero_time;
+    1360                 :            : 
+    1361                 :            :     /* Check input parameters.*/
+    1362   [ +  -  +  -  :        728 :     if (cert == NULL || from_size == NULL || to_size == NULL ||
+             +  -  -  + ]
+    1363                 :            :         cert_size == 0) {
+    1364         [ #  # ]:          0 :         if (from_size != NULL) {
+    1365                 :          0 :             *from_size = 0;
+    1366                 :            :         }
+    1367         [ #  # ]:          0 :         if (to_size != NULL) {
+    1368                 :          0 :             *to_size = 0;
+    1369                 :            :         }
+    1370                 :          0 :         return false;
+    1371                 :            :     }
+    1372                 :            : 
+    1373                 :        728 :     status = false;
+    1374                 :            : 
+    1375                 :        728 :     mbedtls_x509_crt_init(&crt);
+    1376                 :        728 :     libspdm_zero_mem(&zero_time, sizeof(mbedtls_x509_time));
+    1377                 :            : 
+    1378                 :        728 :     ret = mbedtls_x509_crt_parse_der(&crt, cert, cert_size);
+    1379                 :            : 
+    1380         [ +  - ]:        728 :     if (ret == 0) {
+    1381                 :        728 :         f_size = sizeof(mbedtls_x509_time);
+    1382   [ -  +  -  - ]:        728 :         if ((libspdm_consttime_is_mem_equal(&zero_time, &(crt.valid_from), f_size)) &&
+    1383                 :          0 :             (libspdm_consttime_is_mem_equal(&zero_time, &(crt.valid_to), f_size))) {
+    1384                 :          0 :             *from_size = 0;
+    1385                 :          0 :             *to_size = 0;
+    1386                 :          0 :             status = true;
+    1387                 :          0 :             goto done;
+    1388                 :            :         }
+    1389                 :            : 
+    1390         [ -  + ]:        728 :         if (*from_size < f_size) {
+    1391                 :          0 :             *from_size = f_size;
+    1392                 :          0 :             goto done;
+    1393                 :            :         }
+    1394         [ +  - ]:        728 :         if (from != NULL) {
+    1395                 :        728 :             libspdm_copy_mem(from, *from_size, &(crt.valid_from), f_size);
+    1396                 :            :         }
+    1397                 :        728 :         *from_size = f_size;
+    1398                 :            : 
+    1399                 :        728 :         t_size = sizeof(mbedtls_x509_time);
+    1400         [ -  + ]:        728 :         if (*to_size < t_size) {
+    1401                 :          0 :             *to_size = t_size;
+    1402                 :          0 :             goto done;
+    1403                 :            :         }
+    1404         [ +  - ]:        728 :         if (to != NULL) {
+    1405                 :        728 :             libspdm_copy_mem(to, *to_size, &(crt.valid_to),
+    1406                 :            :                              sizeof(mbedtls_x509_time));
+    1407                 :            :         }
+    1408                 :        728 :         *to_size = t_size;
+    1409                 :        728 :         status = true;
+    1410                 :            :     } else {
+    1411                 :          0 :         *from_size = 0;
+    1412                 :          0 :         *to_size = 0;
+    1413                 :            :     }
+    1414                 :            : 
+    1415                 :        728 : done:
+    1416                 :        728 :     mbedtls_x509_crt_free(&crt);
+    1417                 :            : 
+    1418                 :        728 :     return status;
+    1419                 :            : }
+    1420                 :            : 
+    1421                 :            : /**
+    1422                 :            :  * Retrieve the key usage from one X.509 certificate.
+    1423                 :            :  *
+    1424                 :            :  * @param[in]      cert             Pointer to the DER-encoded X509 certificate.
+    1425                 :            :  * @param[in]      cert_size         size of the X509 certificate in bytes.
+    1426                 :            :  * @param[out]     usage            key usage (LIBSPDM_CRYPTO_X509_KU_*)
+    1427                 :            :  *
+    1428                 :            :  * @retval  true   if the usage is no equal 0. The certificate key usage retrieved successfully.
+    1429                 :            :  * @retval  true   if the usage is equal 0. The certificate parse successfully, but the cert doesn't have key usage.
+    1430                 :            :  * @retval  false  Invalid certificate, or usage is NULL.
+    1431                 :            :  **/
+    1432                 :        728 : bool libspdm_x509_get_key_usage(const uint8_t *cert, size_t cert_size,
+    1433                 :            :                                 size_t *usage)
+    1434                 :            : {
+    1435                 :            :     mbedtls_x509_crt crt;
+    1436                 :            :     int ret;
+    1437                 :            :     bool status;
+    1438                 :            : 
+    1439                 :            :     /* Check input parameters.*/
+    1440   [ +  -  +  -  :        728 :     if (cert == NULL || cert_size == 0 || usage == NULL) {
+                   -  + ]
+    1441         [ #  # ]:          0 :         if (usage != NULL) {
+    1442                 :          0 :             *usage = 0;
+    1443                 :            :         }
+    1444                 :          0 :         return false;
+    1445                 :            :     }
+    1446                 :            : 
+    1447                 :        728 :     status = false;
+    1448                 :            : 
+    1449                 :        728 :     mbedtls_x509_crt_init(&crt);
+    1450                 :            : 
+    1451                 :        728 :     ret = mbedtls_x509_crt_parse_der(&crt, cert, cert_size);
+    1452                 :            : 
+    1453         [ +  - ]:        728 :     if (ret == 0) {
+    1454                 :        728 :         *usage = crt.MBEDTLS_PRIVATE(key_usage);
+    1455                 :        728 :         status = true;
+    1456                 :            :     } else {
+    1457                 :          0 :         *usage = 0;
+    1458                 :            :     }
+    1459                 :        728 :     mbedtls_x509_crt_free(&crt);
+    1460                 :            : 
+    1461                 :        728 :     return status;
+    1462                 :            : }
+    1463                 :            : 
+    1464                 :            : /**
+    1465                 :            :  * Retrieve the Extended key usage from one X.509 certificate.
+    1466                 :            :  *
+    1467                 :            :  * @param[in]      cert             Pointer to the DER-encoded X509 certificate.
+    1468                 :            :  * @param[in]      cert_size         size of the X509 certificate in bytes.
+    1469                 :            :  * @param[out]     usage            key usage bytes.
+    1470                 :            :  * @param[in, out] usage_size        key usage buffer sizs in bytes.
+    1471                 :            :  *
+    1472                 :            :  * @retval true   If the returned usage_size == 0, it means that cert and oid are valid, but the Extended key usage is not found;
+    1473                 :            :  *                If the returned usage_size != 0, it means that cert and oid are valid, and the Extended key usage is found;
+    1474                 :            :  * @retval false  If the returned usage_size == 0, it means that cert or oid are invalid;
+    1475                 :            :  *                If the returned usage_size != 0, it means that cert and oid are valid, and the Extended key usage is found,
+    1476                 :            :  *                                                 but the store buffer is too small.
+    1477                 :            :  **/
+    1478                 :        728 : bool libspdm_x509_get_extended_key_usage(const uint8_t *cert,
+    1479                 :            :                                          size_t cert_size, uint8_t *usage,
+    1480                 :            :                                          size_t *usage_size)
+    1481                 :            : {
+    1482                 :            :     bool status;
+    1483                 :            : 
+    1484   [ +  -  +  -  :        728 :     if (cert == NULL || cert_size == 0 || usage_size == NULL) {
+                   -  + ]
+    1485                 :          0 :         return false;
+    1486                 :            :     }
+    1487                 :            : 
+    1488                 :        728 :     status = libspdm_x509_get_extension_data(cert, cert_size,
+    1489                 :            :                                              m_libspdm_oid_ext_key_usage,
+    1490                 :            :                                              sizeof(m_libspdm_oid_ext_key_usage), usage,
+    1491                 :            :                                              usage_size);
+    1492                 :            : 
+    1493                 :        728 :     return status;
+    1494                 :            : }
+    1495                 :            : 
+    1496                 :            : /**
+    1497                 :            :  * Retrieve the basic constraints from one X.509 certificate.
+    1498                 :            :  *
+    1499                 :            :  * @param[in]      cert                     Pointer to the DER-encoded X509 certificate.
+    1500                 :            :  * @param[in]      cert_size                size of the X509 certificate in bytes.
+    1501                 :            :  * @param[out]     basic_constraints        basic constraints bytes.
+    1502                 :            :  * @param[in, out] basic_constraints_size   basic constraints buffer sizs in bytes.
+    1503                 :            :  *
+    1504                 :            :  * @retval true   If the returned basic_constraints_size == 0, it means that cert and oid are valid, but the basic_constraints is not found;
+    1505                 :            :  *                If the returned basic_constraints_size != 0, it means that cert and oid are valid, and the basic_constraints is found;
+    1506                 :            :  * @retval false  If the returned basic_constraints_size == 0, it means that cert or oid are invalid;
+    1507                 :            :  *                If the returned basic_constraints_size != 0, it means that cert and oid are valid, and the basic_constraints is found,
+    1508                 :            :  *                                                             but the store buffer is too small.
+    1509                 :            :  **/
+    1510                 :        722 : bool libspdm_x509_get_extended_basic_constraints(const uint8_t *cert,
+    1511                 :            :                                                  size_t cert_size,
+    1512                 :            :                                                  uint8_t *basic_constraints,
+    1513                 :            :                                                  size_t *basic_constraints_size)
+    1514                 :            : {
+    1515                 :            :     bool status;
+    1516                 :            : 
+    1517   [ +  -  +  -  :        722 :     if (cert == NULL || cert_size == 0 || basic_constraints_size == NULL) {
+                   -  + ]
+    1518                 :          0 :         return false;
+    1519                 :            :     }
+    1520                 :            : 
+    1521                 :        722 :     status = libspdm_x509_get_extension_data(cert, cert_size,
+    1522                 :            :                                              m_libspdm_oid_basic_constraints,
+    1523                 :            :                                              sizeof(m_libspdm_oid_basic_constraints),
+    1524                 :            :                                              basic_constraints,
+    1525                 :            :                                              basic_constraints_size);
+    1526                 :        722 :     return status;
+    1527                 :            : }
+    1528                 :            : 
+    1529                 :            : /**
+    1530                 :            :  * Return 0 if before <= after, 1 otherwise
+    1531                 :            :  **/
+    1532                 :       1456 : static int32_t libspdm_internal_x509_check_time(const mbedtls_x509_time *before,
+    1533                 :            :                                                 const mbedtls_x509_time *after)
+    1534                 :            : {
+    1535         [ +  - ]:       1456 :     if (before->year > after->year) {
+    1536                 :       1456 :         return (1);
+    1537                 :            :     }
+    1538                 :            : 
+    1539   [ #  #  #  # ]:          0 :     if (before->year == after->year && before->mon > after->mon) {
+    1540                 :          0 :         return (1);
+    1541                 :            :     }
+    1542                 :            : 
+    1543   [ #  #  #  # ]:          0 :     if (before->year == after->year && before->mon == after->mon &&
+    1544         [ #  # ]:          0 :         before->day > after->day) {
+    1545                 :          0 :         return (1);
+    1546                 :            :     }
+    1547                 :            : 
+    1548   [ #  #  #  # ]:          0 :     if (before->year == after->year && before->mon == after->mon &&
+    1549   [ #  #  #  # ]:          0 :         before->day == after->day && before->hour > after->hour) {
+    1550                 :          0 :         return (1);
+    1551                 :            :     }
+    1552                 :            : 
+    1553   [ #  #  #  # ]:          0 :     if (before->year == after->year && before->mon == after->mon &&
+    1554   [ #  #  #  # ]:          0 :         before->day == after->day && before->hour == after->hour &&
+    1555         [ #  # ]:          0 :         before->min > after->min) {
+    1556                 :          0 :         return (1);
+    1557                 :            :     }
+    1558                 :            : 
+    1559   [ #  #  #  # ]:          0 :     if (before->year == after->year && before->mon == after->mon &&
+    1560   [ #  #  #  # ]:          0 :         before->day == after->day && before->hour == after->hour &&
+    1561   [ #  #  #  # ]:          0 :         before->min == after->min && before->sec > after->sec) {
+    1562                 :          0 :         return (1);
+    1563                 :            :     }
+    1564                 :            : 
+    1565                 :          0 :     return (0);
+    1566                 :            : }
+    1567                 :            : 
+    1568                 :       8736 : static int32_t libspdm_internal_atoi(const char *p_start, char const *p_end)
+    1569                 :            : {
+    1570                 :       8736 :     const char *p = p_start;
+    1571                 :       8736 :     int32_t k = 0;
+    1572         [ +  + ]:      29120 :     while (p < p_end) {
+    1573                 :            : 
+    1574                 :            :         /* k = k * 2³ + k * 2¹ = k * 8 + k * 2 = k * 10*/
+    1575                 :            : 
+    1576                 :      20384 :         k = (k << 3) + (k << 1) + (*p) - '0';
+    1577                 :      20384 :         p++;
+    1578                 :            :     }
+    1579                 :       8736 :     return k;
+    1580                 :            : }
+    1581                 :            : 
+    1582                 :            : /**
+    1583                 :            :  * format a date_time object into DataTime buffer
+    1584                 :            :  *
+    1585                 :            :  * If date_time_str is NULL, then return false.
+    1586                 :            :  * If date_time_size is NULL, then return false.
+    1587                 :            :  * If this interface is not supported, then return false.
+    1588                 :            :  *
+    1589                 :            :  * @param[in]      date_time_str      date_time string like YYYYMMDDhhmmssZ
+    1590                 :            :  *                                 Ref: https://www.w3.org/TR/NOTE-datetime
+    1591                 :            :  *                                 Z stand for UTC time
+    1592                 :            :  * @param[out]     date_time         Pointer to a date_time object.
+    1593                 :            :  * @param[in,out]  date_time_size     date_time object buffer size.
+    1594                 :            :  *
+    1595                 :            :  * @retval RETURN_SUCCESS           The date_time object create successfully.
+    1596                 :            :  * @retval RETURN_INVALID_PARAMETER If date_time_str is NULL.
+    1597                 :            :  *                                 If date_time_size is NULL.
+    1598                 :            :  *                                 If date_time is not NULL and *date_time_size is 0.
+    1599                 :            :  *                                 If year month day hour minute second combination is invalid datetime.
+    1600                 :            :  * @retval RETURN_BUFFER_TOO_SMALL  If the date_time is NULL. The required buffer size
+    1601                 :            :  *                                 (including the final null) is returned in the
+    1602                 :            :  *                                 date_time_size parameter.
+    1603                 :            :  * @retval RETURN_UNSUPPORTED       The operation is not supported.
+    1604                 :            :  **/
+    1605                 :       1456 : bool libspdm_x509_set_date_time(const char *date_time_str, void *date_time, size_t *date_time_size)
+    1606                 :            : {
+    1607                 :            :     mbedtls_x509_time dt;
+    1608                 :            : 
+    1609                 :            :     int32_t year;
+    1610                 :            :     int32_t month;
+    1611                 :            :     int32_t day;
+    1612                 :            :     int32_t hour;
+    1613                 :            :     int32_t minute;
+    1614                 :            :     int32_t second;
+    1615                 :            :     bool status;
+    1616                 :            :     const char *p;
+    1617                 :            : 
+    1618                 :       1456 :     p = date_time_str;
+    1619                 :            : 
+    1620                 :       1456 :     year = libspdm_internal_atoi(p, p + 4);
+    1621                 :       1456 :     p += 4;
+    1622                 :       1456 :     month = libspdm_internal_atoi(p, p + 2);
+    1623                 :       1456 :     p += 2;
+    1624                 :       1456 :     day = libspdm_internal_atoi(p, p + 2);
+    1625                 :       1456 :     p += 2;
+    1626                 :       1456 :     hour = libspdm_internal_atoi(p, p + 2);
+    1627                 :       1456 :     p += 2;
+    1628                 :       1456 :     minute = libspdm_internal_atoi(p, p + 2);
+    1629                 :       1456 :     p += 2;
+    1630                 :       1456 :     second = libspdm_internal_atoi(p, p + 2);
+    1631                 :       1456 :     p += 2;
+    1632                 :       1456 :     dt.year = (int)year;
+    1633                 :       1456 :     dt.mon = (int)month;
+    1634                 :       1456 :     dt.day = (int)day;
+    1635                 :       1456 :     dt.hour = (int)hour;
+    1636                 :       1456 :     dt.min = (int)minute;
+    1637                 :       1456 :     dt.sec = (int)second;
+    1638                 :            : 
+    1639         [ -  + ]:       1456 :     if (*date_time_size < sizeof(mbedtls_x509_time)) {
+    1640                 :          0 :         *date_time_size = sizeof(mbedtls_x509_time);
+    1641                 :          0 :         status = false;
+    1642                 :          0 :         goto cleanup;
+    1643                 :            :     }
+    1644         [ +  - ]:       1456 :     if (date_time != NULL) {
+    1645                 :       1456 :         libspdm_copy_mem(date_time, *date_time_size, &dt, sizeof(mbedtls_x509_time));
+    1646                 :            :     }
+    1647                 :       1456 :     *date_time_size = sizeof(mbedtls_x509_time);
+    1648                 :       1456 :     status = true;
+    1649                 :       1456 : cleanup:
+    1650                 :       1456 :     return status;
+    1651                 :            : }
+    1652                 :            : 
+    1653                 :            : /**
+    1654                 :            :  * Compare date_time1 object and date_time2 object.
+    1655                 :            :  *
+    1656                 :            :  * If date_time1 is NULL, then return -2.
+    1657                 :            :  * If date_time2 is NULL, then return -2.
+    1658                 :            :  * If date_time1 == date_time2, then return 0
+    1659                 :            :  * If date_time1 > date_time2, then return 1
+    1660                 :            :  * If date_time1 < date_time2, then return -1
+    1661                 :            :  *
+    1662                 :            :  * @param[in]      date_time1         Pointer to a date_time Ojbect
+    1663                 :            :  * @param[in]      date_time2         Pointer to a date_time Object
+    1664                 :            :  *
+    1665                 :            :  * @retval  0      If date_time1 == date_time2
+    1666                 :            :  * @retval  1      If date_time1 > date_time2
+    1667                 :            :  * @retval  -1     If date_time1 < date_time2
+    1668                 :            :  **/
+    1669                 :       1456 : int32_t libspdm_x509_compare_date_time(const void *date_time1, const void *date_time2)
+    1670                 :            : {
+    1671   [ +  -  -  + ]:       1456 :     if (date_time1 == NULL || date_time2 == NULL) {
+    1672                 :          0 :         return -2;
+    1673                 :            :     }
+    1674         [ -  + ]:       1456 :     if (libspdm_consttime_is_mem_equal(date_time2, date_time1, sizeof(mbedtls_x509_time))) {
+    1675                 :          0 :         return 0;
+    1676                 :            :     }
+    1677         [ -  + ]:       1456 :     if (libspdm_internal_x509_check_time((const mbedtls_x509_time *)date_time1,
+    1678                 :            :                                          (const mbedtls_x509_time *)date_time2) == 0) {
+    1679                 :          0 :         return -1;
+    1680                 :            :     } else {
+    1681                 :       1456 :         return 1;
+    1682                 :            :     }
+    1683                 :            : }
+    1684                 :            : 
+    1685                 :          2 : static bool libspdm_convert_subject_to_string(uint8_t *ptr, size_t obj_len,
+    1686                 :            :                                               uint8_t *buffer, int32_t buff_len)
+    1687                 :            : {
+    1688                 :            :     bool ret;
+    1689                 :            :     uint8_t *end;
+    1690                 :            :     uint8_t *internal_p;
+    1691                 :            : 
+    1692                 :            :     libspdm_x509_subject_descriptor_t *cur;
+    1693                 :            :     /* X.509 DN attributes from RFC 5280, Appendix A.1. */
+    1694                 :          2 :     libspdm_x509_subject_descriptor_t x509_attrs[] =
+    1695                 :            :     {
+    1696                 :            :         { LIBSPDM_ADD_STRLEN( "CN" ), LIBSPDM_ADD_STRLEN( MBEDTLS_OID_AT_CN ),
+    1697                 :            :           MBEDTLS_ASN1_UTF8_STRING },
+    1698                 :            :         { LIBSPDM_ADD_STRLEN( "C" ), LIBSPDM_ADD_STRLEN( MBEDTLS_OID_AT_COUNTRY ),
+    1699                 :            :           MBEDTLS_ASN1_PRINTABLE_STRING },
+    1700                 :            :         { LIBSPDM_ADD_STRLEN( "O" ), LIBSPDM_ADD_STRLEN( MBEDTLS_OID_AT_ORGANIZATION ),
+    1701                 :            :           MBEDTLS_ASN1_UTF8_STRING },
+    1702                 :            :         { LIBSPDM_ADD_STRLEN( "L" ), LIBSPDM_ADD_STRLEN( MBEDTLS_OID_AT_LOCALITY ),
+    1703                 :            :           MBEDTLS_ASN1_UTF8_STRING },
+    1704                 :            :         { LIBSPDM_ADD_STRLEN( "R" ), LIBSPDM_ADD_STRLEN( MBEDTLS_OID_PKCS9_EMAIL ),
+    1705                 :            :           MBEDTLS_ASN1_IA5_STRING },
+    1706                 :            :         { LIBSPDM_ADD_STRLEN( "OU" ), LIBSPDM_ADD_STRLEN( MBEDTLS_OID_AT_ORG_UNIT ),
+    1707                 :            :           MBEDTLS_ASN1_UTF8_STRING },
+    1708                 :            :         { LIBSPDM_ADD_STRLEN( "ST" ), LIBSPDM_ADD_STRLEN( MBEDTLS_OID_AT_STATE ),
+    1709                 :            :           MBEDTLS_ASN1_UTF8_STRING },
+    1710                 :            :         { LIBSPDM_ADD_STRLEN( "emailAddress" ), LIBSPDM_ADD_STRLEN( MBEDTLS_OID_PKCS9_EMAIL ),
+    1711                 :            :           MBEDTLS_ASN1_IA5_STRING },
+    1712                 :            :         { LIBSPDM_ADD_STRLEN( "serialNumber" ), LIBSPDM_ADD_STRLEN( MBEDTLS_OID_AT_SERIAL_NUMBER ),
+    1713                 :            :           MBEDTLS_ASN1_PRINTABLE_STRING },
+    1714                 :            :         { LIBSPDM_ADD_STRLEN( "postalAddress" ),
+    1715                 :            :           LIBSPDM_ADD_STRLEN( MBEDTLS_OID_AT_POSTAL_ADDRESS ), MBEDTLS_ASN1_PRINTABLE_STRING },
+    1716                 :            :         { LIBSPDM_ADD_STRLEN( "postalCode" ), LIBSPDM_ADD_STRLEN( MBEDTLS_OID_AT_POSTAL_CODE ),
+    1717                 :            :           MBEDTLS_ASN1_PRINTABLE_STRING },
+    1718                 :            :         { LIBSPDM_ADD_STRLEN( "dnQualifier" ), LIBSPDM_ADD_STRLEN( MBEDTLS_OID_AT_DN_QUALIFIER ),
+    1719                 :            :           MBEDTLS_ASN1_PRINTABLE_STRING },
+    1720                 :            :         { LIBSPDM_ADD_STRLEN( "title" ), LIBSPDM_ADD_STRLEN( MBEDTLS_OID_AT_TITLE ),
+    1721                 :            :           MBEDTLS_ASN1_UTF8_STRING },
+    1722                 :            :         { LIBSPDM_ADD_STRLEN( "SN" ), LIBSPDM_ADD_STRLEN( MBEDTLS_OID_AT_SUR_NAME ),
+    1723                 :            :           MBEDTLS_ASN1_UTF8_STRING },
+    1724                 :            :         { LIBSPDM_ADD_STRLEN( "GN" ), LIBSPDM_ADD_STRLEN( MBEDTLS_OID_AT_GIVEN_NAME ),
+    1725                 :            :           MBEDTLS_ASN1_UTF8_STRING },
+    1726                 :            :         { LIBSPDM_ADD_STRLEN( "initials" ), LIBSPDM_ADD_STRLEN( MBEDTLS_OID_AT_INITIALS ),
+    1727                 :            :           MBEDTLS_ASN1_UTF8_STRING },
+    1728                 :            :         { LIBSPDM_ADD_STRLEN( "pseudonym" ), LIBSPDM_ADD_STRLEN( MBEDTLS_OID_AT_PSEUDONYM ),
+    1729                 :            :           MBEDTLS_ASN1_UTF8_STRING },
+    1730                 :            :         { LIBSPDM_ADD_STRLEN( "generationQualifier" ),
+    1731                 :            :           LIBSPDM_ADD_STRLEN( MBEDTLS_OID_AT_GENERATION_QUALIFIER ),
+    1732                 :            :           MBEDTLS_ASN1_UTF8_STRING },
+    1733                 :            :         { LIBSPDM_ADD_STRLEN( "DC" ), LIBSPDM_ADD_STRLEN( MBEDTLS_OID_DOMAIN_COMPONENT ),
+    1734                 :            :           MBEDTLS_ASN1_IA5_STRING },
+    1735                 :            :         { NULL, 0, NULL, 0, MBEDTLS_ASN1_NULL }
+    1736                 :            :     };
+    1737                 :            : 
+    1738                 :          2 :     end = ptr + obj_len;
+    1739                 :            : 
+    1740         [ +  + ]:          8 :     while(ptr != end) {
+    1741                 :            :         /*SET*/
+    1742                 :          6 :         ret = libspdm_asn1_get_tag(&ptr, end, &obj_len,
+    1743                 :            :                                    LIBSPDM_CRYPTO_ASN1_SET | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
+    1744         [ -  + ]:          6 :         if (!ret) {
+    1745                 :          0 :             return false;
+    1746                 :            :         }
+    1747                 :          6 :         internal_p = ptr;
+    1748                 :            :         /*move to next SET*/
+    1749                 :          6 :         ptr += obj_len;
+    1750                 :            : 
+    1751                 :            :         /*sequece*/
+    1752                 :          6 :         ret = libspdm_asn1_get_tag(&internal_p, end, &obj_len,
+    1753                 :            :                                    LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
+    1754         [ -  + ]:          6 :         if (!ret) {
+    1755                 :          0 :             return false;
+    1756                 :            :         }
+    1757                 :            : 
+    1758                 :            :         /*OID*/
+    1759                 :          6 :         ret = libspdm_asn1_get_tag(&internal_p, end, &obj_len, LIBSPDM_CRYPTO_ASN1_OID);
+    1760         [ -  + ]:          6 :         if (!ret) {
+    1761                 :          0 :             return false;
+    1762                 :            :         }
+    1763                 :            : 
+    1764         [ +  - ]:         24 :         for (cur = x509_attrs; cur->name != NULL; cur++) {
+    1765   [ +  +  +  + ]:         46 :             if ((cur->oid_len == obj_len) &&
+    1766                 :         22 :                 (libspdm_consttime_is_mem_equal(cur->oid, internal_p, obj_len))) {
+    1767                 :            :                 /*Concat subject string*/
+    1768                 :            : 
+    1769                 :            :                 /*for example: CN=*/
+    1770                 :          6 :                 libspdm_copy_mem(buffer, buff_len, cur->name, cur->name_len);
+    1771                 :          6 :                 buff_len = (int32_t)(buff_len - cur->name_len);
+    1772                 :          6 :                 buffer += cur->name_len;
+    1773                 :          6 :                 *buffer = '=';
+    1774                 :          6 :                 buff_len--;
+    1775                 :          6 :                 buffer++;
+    1776                 :            : 
+    1777                 :            :                 /*move to string*/
+    1778                 :          6 :                 internal_p += obj_len;
+    1779                 :          6 :                 ret = libspdm_asn1_get_tag(&internal_p, end, &obj_len, cur->default_tag);
+    1780         [ -  + ]:          6 :                 if (!ret) {
+    1781                 :          0 :                     return false;
+    1782                 :            :                 }
+    1783                 :            : 
+    1784                 :            :                 /*for example: AU,*/
+    1785                 :          6 :                 libspdm_copy_mem(buffer, buff_len, internal_p, obj_len);
+    1786                 :          6 :                 buff_len = (int32_t)(buff_len - obj_len);
+    1787                 :          6 :                 buffer += obj_len;
+    1788                 :          6 :                 *buffer = ',';
+    1789                 :          6 :                 buff_len--;
+    1790                 :          6 :                 buffer++;
+    1791                 :            : 
+    1792         [ -  + ]:          6 :                 if (buff_len < 0) {
+    1793                 :          0 :                     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,"the buffer is too small"));
+    1794                 :          0 :                     return false;
+    1795                 :            :                 }
+    1796                 :          6 :                 break;
+    1797                 :            :             }
+    1798                 :            :         }
+    1799                 :            : 
+    1800                 :            :         /*can not find the same oid, the subject is wrong*/
+    1801         [ -  + ]:          6 :         if (cur->name == NULL) {
+    1802                 :          0 :             return false;
+    1803                 :            :         }
+    1804                 :            :     }
+    1805                 :            : 
+    1806                 :          2 :     *buffer = '\0';
+    1807                 :          2 :     return true;
+    1808                 :            : }
+    1809                 :            : 
+    1810                 :            : /**
+    1811                 :            :  * Set all attributes object form req_info to CSR
+    1812                 :            :  *
+    1813                 :            :  * @param[in]      req                   CSR to set attributes
+    1814                 :            :  * @param[in]      req_info              requester info to gen CSR
+    1815                 :            :  * @param[in]      req_info_len          The len of requester info
+    1816                 :            :  *
+    1817                 :            :  * @retval  true   Success Set.
+    1818                 :            :  * @retval  false  Set failed.
+    1819                 :            :  **/
+    1820                 :          2 : bool libspdm_set_attribute_for_req(mbedtls_x509write_csr *req,
+    1821                 :            :                                    uint8_t *req_info, size_t req_info_len,
+    1822                 :            :                                    uint8_t *pub_key_der, size_t pub_key_der_len)
+    1823                 :            : {
+    1824                 :            :     uint8_t *ptr;
+    1825                 :            :     int32_t length;
+    1826                 :            :     size_t obj_len;
+    1827                 :            :     bool ret;
+    1828                 :            :     uint8_t *end;
+    1829                 :            :     uint8_t *ptr_old;
+    1830                 :            : 
+    1831                 :            :     uint8_t *oid;
+    1832                 :            :     size_t oid_len;
+    1833                 :            :     uint8_t *val;
+    1834                 :            :     size_t val_len;
+    1835                 :            : 
+    1836                 :            :     uint8_t *pkinfo;
+    1837                 :            :     size_t pkinfo_len;
+    1838                 :            :     uint8_t buffer[LIBSPDM_MAX_SUBJECT_BUFFER_SIZE];
+    1839                 :            : 
+    1840                 :          2 :     length = (int32_t)req_info_len;
+    1841                 :          2 :     ptr = req_info;
+    1842                 :          2 :     obj_len = 0;
+    1843                 :          2 :     end = ptr + length;
+    1844                 :          2 :     ret = false;
+    1845                 :            : 
+    1846         [ -  + ]:          2 :     if (req_info == NULL) {
+    1847                 :          0 :         return false;
+    1848                 :            :     }
+    1849                 :            : 
+    1850                 :            :     /*req_info sequence, all req_info format is ok because the req_info has been verified before*/
+    1851                 :          2 :     ret = libspdm_asn1_get_tag(&ptr, end, &obj_len,
+    1852                 :            :                                LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
+    1853                 :            : 
+    1854                 :            :     /*integer:version*/
+    1855                 :          2 :     ret = libspdm_asn1_get_tag(&ptr, end, &obj_len, LIBSPDM_CRYPTO_ASN1_INTEGER);
+    1856                 :            :     /*check req_info verson. spec PKCS#10: It shall be 0 for this version of the standard.*/
+    1857   [ +  -  -  + ]:          2 :     if ((obj_len != 1) || (*ptr != 0)) {
+    1858                 :          0 :         return false;
+    1859                 :            :     }
+    1860                 :          2 :     ptr += obj_len;
+    1861                 :            : 
+    1862                 :            :     /*sequence:subject name*/
+    1863                 :          2 :     ret = libspdm_asn1_get_tag(&ptr, end, &obj_len,
+    1864                 :            :                                LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
+    1865                 :            : 
+    1866                 :            :     /**/
+    1867                 :          2 :     libspdm_zero_mem(buffer, sizeof(buffer));
+    1868                 :          2 :     ret = libspdm_convert_subject_to_string(ptr, obj_len, buffer, LIBSPDM_MAX_SUBJECT_BUFFER_SIZE);
+    1869         [ -  + ]:          2 :     if (!ret) {
+    1870                 :          0 :         return false;
+    1871                 :            :     }
+    1872                 :            : 
+    1873                 :            :     /*set subject name*/
+    1874                 :          2 :     ret = mbedtls_x509write_csr_set_subject_name(req, (const char *)buffer);
+    1875         [ -  + ]:          2 :     if (ret != 0) {
+    1876                 :          0 :         return false;
+    1877                 :            :     }
+    1878                 :            : 
+    1879                 :          2 :     ptr += obj_len;
+    1880                 :            : 
+    1881                 :          2 :     pkinfo = ptr;
+    1882                 :            :     /*sequence:subject pkinfo*/
+    1883                 :          2 :     ret = libspdm_asn1_get_tag(&ptr, end, &obj_len,
+    1884                 :            :                                LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
+    1885                 :            : 
+    1886                 :          2 :     pkinfo_len = obj_len + ptr - pkinfo;
+    1887                 :            :     /*check the public key info*/
+    1888   [ +  -  -  + ]:          4 :     if (!((pkinfo_len == pub_key_der_len) &&
+    1889                 :          2 :           (libspdm_consttime_is_mem_equal(pub_key_der, pkinfo, pkinfo_len)))) {
+    1890                 :          0 :         return false;
+    1891                 :            :     }
+    1892                 :            : 
+    1893                 :          2 :     ptr += obj_len;
+    1894                 :            : 
+    1895                 :            :     /*[0]: attributes*/
+    1896                 :          2 :     ret = libspdm_asn1_get_tag(&ptr, end, &obj_len,
+    1897                 :            :                                LIBSPDM_CRYPTO_ASN1_CONTEXT_SPECIFIC |
+    1898                 :            :                                LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
+    1899                 :            :     /*there is no attributes*/
+    1900         [ -  + ]:          2 :     if (ptr == end) {
+    1901                 :          0 :         return true;
+    1902                 :            :     }
+    1903                 :            : 
+    1904                 :            :     /*there is some attributes object: 1,2 ...*/
+    1905         [ +  + ]:          4 :     while (ret)
+    1906                 :            :     {
+    1907                 :          2 :         ret = libspdm_asn1_get_tag(&ptr, end, &obj_len,
+    1908                 :            :                                    LIBSPDM_CRYPTO_ASN1_SEQUENCE |
+    1909                 :            :                                    LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
+    1910         [ +  - ]:          2 :         if (ret) {
+    1911                 :            :             /*save old positon*/
+    1912                 :          2 :             ptr_old = ptr;
+    1913                 :            : 
+    1914                 :            :             /*move to the next sequence*/
+    1915                 :          2 :             ptr += obj_len;
+    1916                 :            : 
+    1917                 :            :             /*get attributes oid*/
+    1918                 :          2 :             ret = libspdm_asn1_get_tag(&ptr_old, end, &obj_len, LIBSPDM_CRYPTO_ASN1_OID);
+    1919         [ -  + ]:          2 :             if (!ret) {
+    1920                 :          0 :                 return false;
+    1921                 :            :             }
+    1922                 :          2 :             oid = ptr_old;
+    1923                 :          2 :             oid_len = obj_len;
+    1924                 :            : 
+    1925                 :          2 :             ptr_old += obj_len;
+    1926                 :            :             /*get attributes val*/
+    1927                 :          2 :             ret = libspdm_asn1_get_tag(&ptr_old, end, &obj_len,
+    1928                 :            :                                        LIBSPDM_CRYPTO_ASN1_SET |
+    1929                 :            :                                        LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
+    1930         [ -  + ]:          2 :             if (!ret) {
+    1931                 :          0 :                 return false;
+    1932                 :            :             }
+    1933                 :          2 :             ret = libspdm_asn1_get_tag(&ptr_old, end, &obj_len, LIBSPDM_CRYPTO_ASN1_UTF8_STRING);
+    1934         [ -  + ]:          2 :             if (!ret) {
+    1935                 :          0 :                 return false;
+    1936                 :            :             }
+    1937                 :          2 :             val = ptr_old;
+    1938                 :          2 :             val_len = obj_len;
+    1939                 :            : 
+    1940                 :            :             /*set attributes*/
+    1941                 :          2 :             ret = mbedtls_x509write_csr_set_extension(req, (const char *)oid, oid_len, 0, val,
+    1942                 :            :                                                       val_len);
+    1943                 :            : 
+    1944         [ -  + ]:          2 :             if (ret) {
+    1945                 :          0 :                 return false;
+    1946                 :            :             }
+    1947                 :            : 
+    1948                 :            :         } else {
+    1949                 :          0 :             break;
+    1950                 :            :         }
+    1951                 :            :     }
+    1952                 :            : 
+    1953         [ +  - ]:          2 :     if (ptr == end) {
+    1954                 :          2 :         return true;
+    1955                 :            :     } else {
+    1956                 :          0 :         return false;
+    1957                 :            :     }
+    1958                 :            : }
+    1959                 :            : 
+    1960                 :            : /**
+    1961                 :            :  * Gen CSR
+    1962                 :            :  *
+    1963                 :            :  * @param[in]      hash_nid              hash algo for sign
+    1964                 :            :  * @param[in]      asym_nid              asym algo for sign
+    1965                 :            :  *
+    1966                 :            :  * @param[in]      requester_info        requester info to gen CSR
+    1967                 :            :  * @param[in]      requester_info_length The len of requester info
+    1968                 :            :  *
+    1969                 :            :  * @param[in]       is_ca                if true, set basic_constraints: CA:true; Otherwise, set to false.
+    1970                 :            :  *
+    1971                 :            :  * @param[in]      context               Pointer to asymmetric context
+    1972                 :            :  * @param[in]      subject_name          Subject name: should be break with ',' in the middle
+    1973                 :            :  *                                       example: "C=AA,CN=BB"
+    1974                 :            :  * Subject names should contain a comma-separated list of OID types and values:
+    1975                 :            :  * The valid OID type name is in:
+    1976                 :            :  * {"CN", "commonName", "C", "countryName", "O", "organizationName","L",
+    1977                 :            :  * "OU", "organizationalUnitName", "ST", "stateOrProvinceName", "emailAddress",
+    1978                 :            :  * "serialNumber", "postalAddress", "postalCode", "dnQualifier", "title",
+    1979                 :            :  * "SN","givenName","GN", "initials", "pseudonym", "generationQualifier", "domainComponent", "DC"}.
+    1980                 :            :  * Note: The object of C and countryName should be CSR Supported Country Codes
+    1981                 :            :  *
+    1982                 :            :  * @param[in, out]      csr_len               For input, csr_len is the size of store CSR buffer.
+    1983                 :            :  *                                            For output, csr_len is CSR len for DER format
+    1984                 :            :  * @param[in, out]      csr_pointer           For input, csr_pointer is buffer address to store CSR.
+    1985                 :            :  *                                            For output, csr_pointer is address for stored CSR.
+    1986                 :            :  *                                            The csr_pointer address will be changed.
+    1987                 :            :  * @param[in]           base_cert             An optional leaf certificate whose
+    1988                 :            :  *                                            extensions should be copied to the CSR
+    1989                 :            :  *
+    1990                 :            :  * @retval  true   Success.
+    1991                 :            :  * @retval  false  Failed to gen CSR.
+    1992                 :            :  **/
+    1993                 :          6 : bool libspdm_gen_x509_csr(size_t hash_nid, size_t asym_nid,
+    1994                 :            :                           uint8_t *requester_info, size_t requester_info_length,
+    1995                 :            :                           bool is_ca,
+    1996                 :            :                           void *context, char *subject_name,
+    1997                 :            :                           size_t *csr_len, uint8_t *csr_pointer,
+    1998                 :            :                           void *base_cert)
+    1999                 :            : {
+    2000                 :            :     int ret;
+    2001                 :            :     bool result;
+    2002                 :            :     size_t csr_buffer_size;
+    2003                 :            : 
+    2004                 :            :     mbedtls_x509write_csr req;
+    2005                 :            :     mbedtls_md_type_t md_alg;
+    2006                 :            :     mbedtls_asn1_sequence extns;
+    2007                 :            :     mbedtls_asn1_sequence *next_oid;
+    2008                 :            :     mbedtls_x509_buf buf;
+    2009                 :            :     mbedtls_x509_crt *cert;
+    2010                 :            :     mbedtls_pk_context key;
+    2011                 :            : 
+    2012                 :            :     uint8_t pubkey_buffer[LIBSPDM_MAX_PUBKEY_DER_BUFFER_SIZE];
+    2013                 :            :     uint8_t *pubkey_der_data;
+    2014                 :            :     size_t pubkey_der_len;
+    2015                 :            :     size_t oid_tag_len;
+    2016                 :            : 
+    2017                 :            :     /*basic_constraints: CA: false */
+    2018                 :            :     #define BASIC_CONSTRAINTS_STRING_FALSE {0x30, 0x00}
+    2019                 :          6 :     uint8_t basic_constraints_false[] = BASIC_CONSTRAINTS_STRING_FALSE;
+    2020                 :            : 
+    2021                 :            :     /*basic_constraints: CA: true */
+    2022                 :            :     #define BASIC_CONSTRAINTS_STRING_TRUE {0x30, 0x03, 0x01, 0x01, 0xFF}
+    2023                 :          6 :     uint8_t basic_constraints_true[] = BASIC_CONSTRAINTS_STRING_TRUE;
+    2024                 :            : 
+    2025                 :            :     /* Init */
+    2026                 :          6 :     mbedtls_x509write_csr_init(&req);
+    2027                 :          6 :     mbedtls_pk_init(&key);
+    2028                 :          6 :     csr_buffer_size = *csr_len;
+    2029                 :          6 :     next_oid = NULL;
+    2030                 :            : 
+    2031                 :          6 :     ret = 1;
+    2032      [ -  +  - ]:          6 :     switch (asym_nid)
+    2033                 :            :     {
+    2034                 :          0 :     case LIBSPDM_CRYPTO_NID_RSASSA2048:
+    2035                 :            :     case LIBSPDM_CRYPTO_NID_RSAPSS2048:
+    2036                 :            :     case LIBSPDM_CRYPTO_NID_RSASSA3072:
+    2037                 :            :     case LIBSPDM_CRYPTO_NID_RSAPSS3072:
+    2038                 :            :     case LIBSPDM_CRYPTO_NID_RSASSA4096:
+    2039                 :            :     case LIBSPDM_CRYPTO_NID_RSAPSS4096:
+    2040                 :          0 :         ret = mbedtls_pk_setup(&key, mbedtls_pk_info_from_type(MBEDTLS_PK_RSA));
+    2041         [ #  # ]:          0 :         if (ret != 0) {
+    2042                 :          0 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,"failed\n ! mbedtls_pk_setup %d", ret));
+    2043                 :          0 :             goto free_all;
+    2044                 :            :         }
+    2045                 :          0 :         ret = mbedtls_rsa_copy(mbedtls_pk_rsa(key), (mbedtls_rsa_context *)context);
+    2046         [ #  # ]:          0 :         if (ret != 0) {
+    2047                 :          0 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,"failed\n ! mbedtls_rsa_copy %d", ret));
+    2048                 :          0 :             goto free_all;
+    2049                 :            :         }
+    2050                 :          0 :         ret = mbedtls_rsa_complete(mbedtls_pk_rsa(key));
+    2051         [ #  # ]:          0 :         if (ret != 0) {
+    2052                 :          0 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,"failed\n ! mbedtls_rsa_complete %d", ret));
+    2053                 :          0 :             goto free_all;
+    2054                 :            :         }
+    2055                 :          0 :         break;
+    2056                 :          6 :     case LIBSPDM_CRYPTO_NID_ECDSA_NIST_P256:
+    2057                 :            :     case LIBSPDM_CRYPTO_NID_ECDSA_NIST_P384:
+    2058                 :            :     case LIBSPDM_CRYPTO_NID_ECDSA_NIST_P521:
+    2059                 :          6 :         ret = mbedtls_pk_setup(&key, mbedtls_pk_info_from_type(MBEDTLS_PK_ECKEY));
+    2060         [ -  + ]:          6 :         if (ret != 0) {
+    2061                 :          0 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,"failed\n ! mbedtls_pk_setup %d", ret));
+    2062                 :          0 :             goto free_all;
+    2063                 :            :         }
+    2064                 :            :         /*mbedtls_ecdh_context include mbedtls_ecdsa_context,can be treated as mbedtls_ecdsa_context*/
+    2065                 :          6 :         ret = mbedtls_ecdsa_from_keypair(mbedtls_pk_ec(key), (mbedtls_ecdsa_context *)context);
+    2066         [ -  + ]:          6 :         if (ret != 0) {
+    2067                 :          0 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,"failed\n ! mbedtls_ecdsa_from_keypair %d", ret));
+    2068                 :          0 :             goto free_all;
+    2069                 :            :         }
+    2070                 :          6 :         break;
+    2071                 :          0 :     default:
+    2072                 :          0 :         return false;
+    2073                 :            :     }
+    2074                 :            : 
+    2075   [ +  -  -  - ]:          6 :     switch (hash_nid)
+    2076                 :            :     {
+    2077                 :          6 :     case LIBSPDM_CRYPTO_NID_SHA256:
+    2078                 :          6 :         md_alg = MBEDTLS_MD_SHA256;
+    2079                 :          6 :         break;
+    2080                 :          0 :     case LIBSPDM_CRYPTO_NID_SHA384:
+    2081                 :          0 :         md_alg = MBEDTLS_MD_SHA384;
+    2082                 :          0 :         break;
+    2083                 :          0 :     case LIBSPDM_CRYPTO_NID_SHA512:
+    2084                 :          0 :         md_alg = MBEDTLS_MD_SHA512;
+    2085                 :          0 :         break;
+    2086                 :          0 :     default:
+    2087                 :          0 :         ret = 1;
+    2088                 :          0 :         goto free_all;
+    2089                 :            :     }
+    2090                 :            : 
+    2091                 :            :     /* Set the md alg */
+    2092                 :          6 :     mbedtls_x509write_csr_set_md_alg(&req, md_alg);
+    2093                 :            : 
+    2094                 :            :     /* Set the subject name */
+    2095         [ +  - ]:          6 :     if (subject_name != NULL) {
+    2096                 :          6 :         ret = mbedtls_x509write_csr_set_subject_name(&req, subject_name);
+    2097         [ -  + ]:          6 :         if (ret != 0) {
+    2098                 :          0 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+    2099                 :            :                            "failed\n ! mbedtls_x509write_csr_set_subject_name returned %d", ret));
+    2100                 :          0 :             goto free_all;
+    2101                 :            :         }
+    2102                 :            :     }
+    2103                 :            : 
+    2104                 :          6 :     libspdm_zero_mem(pubkey_buffer, sizeof(pubkey_buffer));
+    2105                 :          6 :     pubkey_der_len = mbedtls_pk_write_pubkey_der(&key, pubkey_buffer, sizeof(pubkey_buffer));
+    2106         [ +  - ]:          6 :     if (pubkey_der_len > 0) {
+    2107                 :            :         /*Note: data is written at the end of the buffer!*/
+    2108                 :          6 :         pubkey_der_data = pubkey_buffer + sizeof(pubkey_buffer) - pubkey_der_len;
+    2109                 :            :     } else {
+    2110                 :          0 :         goto free_all;
+    2111                 :            :     }
+    2112                 :            : 
+    2113                 :            :     /* requester info parse
+    2114                 :            :      * check the req_info version and subjectPKInfo;
+    2115                 :            :      * get attribute and subject from req_info and set them to CSR;
+    2116                 :            :      **/
+    2117         [ +  + ]:          6 :     if (requester_info_length != 0) {
+    2118                 :          2 :         result = libspdm_set_attribute_for_req(&req, requester_info, requester_info_length,
+    2119                 :            :                                                pubkey_der_data, pubkey_der_len);
+    2120         [ -  + ]:          2 :         if (!result) {
+    2121                 :          0 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,"set_attribute failed !\n"));
+    2122                 :          0 :             goto free_all;
+    2123                 :            :         }
+    2124                 :            :     }
+    2125                 :            : 
+    2126                 :            :     /* Set key */
+    2127                 :          6 :     mbedtls_x509write_csr_set_key(&req, &key);
+    2128                 :            : 
+    2129                 :            :     /*set basicConstraints*/
+    2130   [ +  +  +  +  :          6 :     if (mbedtls_x509write_csr_set_extension(&req, MBEDTLS_OID_BASIC_CONSTRAINTS,
+                   -  + ]
+    2131                 :            :                                             MBEDTLS_OID_SIZE(MBEDTLS_OID_BASIC_CONSTRAINTS),
+    2132                 :            :                                             0,
+    2133                 :            :                                             is_ca ? basic_constraints_true : basic_constraints_false,
+    2134                 :            :                                             is_ca ?
+    2135                 :            :                                             sizeof(basic_constraints_true) :
+    2136                 :            :                                             sizeof(basic_constraints_false)
+    2137                 :            :                                             ) != 0) {
+    2138                 :          0 :         ret = 1;
+    2139                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+    2140                 :            :                        "mbedtls_x509write_csr_set_extension set basicConstraints failed \n"));
+    2141                 :          0 :         goto free_all;
+    2142                 :            :     }
+    2143                 :            : 
+    2144         [ +  - ]:          6 :     if (base_cert != NULL) {
+    2145                 :          6 :         cert = base_cert;
+    2146                 :          6 :         buf = cert->v3_ext;
+    2147         [ -  + ]:          6 :         if (mbedtls_asn1_get_sequence_of(&buf.p, buf.p + buf.len, &extns,
+    2148                 :            :                                          MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) {
+    2149                 :          0 :             ret = 1;
+    2150                 :          0 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+    2151                 :            :                            "mbedtls_x509write_csr_set_extension unable to get sequence\n"));
+    2152                 :          0 :             goto free_all;
+    2153                 :            :         }
+    2154                 :            : 
+    2155                 :          6 :         next_oid = &extns;
+    2156                 :            :     }
+    2157                 :            : 
+    2158         [ +  + ]:         42 :     while (next_oid) {
+    2159         [ -  + ]:         36 :         if (mbedtls_asn1_get_tag(&(next_oid->buf.p), next_oid->buf.p + next_oid->buf.len,
+    2160                 :            :                                  &oid_tag_len, MBEDTLS_ASN1_OID)) {
+    2161                 :          0 :             ret = 1;
+    2162                 :          0 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+    2163                 :            :                            "mbedtls_x509write_csr_set_extension unable to get OID tag\n"));
+    2164                 :          0 :             goto free_all;
+    2165                 :            :         }
+    2166                 :            : 
+    2167   [ +  +  +  +  :         36 :         if (MBEDTLS_OID_CMP_RAW(MBEDTLS_OID_BASIC_CONSTRAINTS, next_oid->buf.p, oid_tag_len) == 0) {
+                   +  + ]
+    2168                 :          6 :             next_oid = next_oid->next;
+    2169                 :          6 :             continue;
+    2170                 :            :         }
+    2171                 :            : 
+    2172   [ +  +  +  -  :         30 :         if (MBEDTLS_OID_CMP_RAW(MBEDTLS_OID_AUTHORITY_KEY_IDENTIFIER, next_oid->buf.p,
+                   -  + ]
+    2173                 :            :                                 oid_tag_len) == 0) {
+    2174                 :          0 :             next_oid = next_oid->next;
+    2175                 :          0 :             continue;
+    2176                 :            :         }
+    2177                 :            : 
+    2178         [ -  + ]:         30 :         if (mbedtls_x509write_csr_set_extension(&req, (const char *)next_oid->buf.p,
+    2179                 :            :                                                 oid_tag_len, 0,
+    2180                 :         30 :                                                 next_oid->buf.p + oid_tag_len,
+    2181                 :         30 :                                                 next_oid->buf.len - oid_tag_len
+    2182                 :            :                                                 ) != 0) {
+    2183                 :          0 :             ret = 1;
+    2184                 :          0 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+    2185                 :            :                            "mbedtls_x509write_csr_set_extension set custom OID failed \n"));
+    2186                 :          0 :             goto free_all;
+    2187                 :            :         }
+    2188                 :            : 
+    2189                 :         30 :         next_oid = next_oid->next;
+    2190                 :            :     }
+    2191                 :            : 
+    2192                 :            :     /*csr data is written at the end of the buffer*/
+    2193                 :          6 :     ret = mbedtls_x509write_csr_der(&req, csr_pointer, csr_buffer_size, libspdm_myrand, NULL);
+    2194         [ -  + ]:          6 :     if (ret <= 0) {
+    2195                 :          0 :         ret = 1;
+    2196                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,"mbedtls_x509write_csr_der failed \n"));
+    2197                 :          0 :         goto free_all;
+    2198                 :            :     }
+    2199                 :            : 
+    2200                 :          6 :     *csr_len = (size_t)ret;
+    2201                 :            :     /*make csr_pointer store csr data*/
+    2202                 :          6 :     memmove(csr_pointer, csr_pointer + csr_buffer_size - *csr_len, *csr_len);
+    2203                 :            : 
+    2204                 :          6 :     ret = 0;
+    2205                 :          6 : free_all:
+    2206                 :          6 :     mbedtls_x509write_csr_free(&req);
+    2207                 :          6 :     mbedtls_pk_free(&key);
+    2208                 :            : 
+    2209                 :          6 :     return(ret == 0);
+    2210                 :            : }
+    2211                 :            : 
+    2212                 :            : #endif
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/rand/index-sort-b.html b/coverage_log/os_stub/cryptlib_mbedtls/rand/index-sort-b.html new file mode 100644 index 00000000000..dc67c5a4ce0 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/rand/index-sort-b.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/rand + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/randHitTotalCoverage
Test:coverage.infoLines:171894.4 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:6875.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
rand.c +
94.4%94.4%
+
94.4 %17 / 18100.0 %2 / 275.0 %6 / 8
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/rand/index-sort-f.html b/coverage_log/os_stub/cryptlib_mbedtls/rand/index-sort-f.html new file mode 100644 index 00000000000..35e9b8b0b5d --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/rand/index-sort-f.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/rand + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/randHitTotalCoverage
Test:coverage.infoLines:171894.4 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:6875.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
rand.c +
94.4%94.4%
+
94.4 %17 / 18100.0 %2 / 275.0 %6 / 8
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/rand/index-sort-l.html b/coverage_log/os_stub/cryptlib_mbedtls/rand/index-sort-l.html new file mode 100644 index 00000000000..a10ea8c8c44 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/rand/index-sort-l.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/rand + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/randHitTotalCoverage
Test:coverage.infoLines:171894.4 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:6875.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
rand.c +
94.4%94.4%
+
94.4 %17 / 18100.0 %2 / 275.0 %6 / 8
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/rand/index.html b/coverage_log/os_stub/cryptlib_mbedtls/rand/index.html new file mode 100644 index 00000000000..928d5f14343 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/rand/index.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/rand + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/randHitTotalCoverage
Test:coverage.infoLines:171894.4 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:6875.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
rand.c +
94.4%94.4%
+
94.4 %17 / 18100.0 %2 / 275.0 %6 / 8
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/rand/rand.c.func-sort-c.html b/coverage_log/os_stub/cryptlib_mbedtls/rand/rand.c.func-sort-c.html new file mode 100644 index 00000000000..a19886f112e --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/rand/rand.c.func-sort-c.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/rand/rand.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/rand - rand.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:171894.4 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:6875.0 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_myrand1256
libspdm_random_bytes3236
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/rand/rand.c.func.html b/coverage_log/os_stub/cryptlib_mbedtls/rand/rand.c.func.html new file mode 100644 index 00000000000..574ca4d118b --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/rand/rand.c.func.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/rand/rand.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/rand - rand.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:171894.4 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:6875.0 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_myrand1256
libspdm_random_bytes3236
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/rand/rand.c.gcov.html b/coverage_log/os_stub/cryptlib_mbedtls/rand/rand.c.gcov.html new file mode 100644 index 00000000000..4878bfa563f --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/rand/rand.c.gcov.html @@ -0,0 +1,152 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/rand/rand.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/rand - rand.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:171894.4 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:6875.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 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                 :            : /** @file
+       8                 :            :  * Pseudorandom Number generator Wrapper Implementation.
+       9                 :            :  **/
+      10                 :            : 
+      11                 :            : #include "internal_crypt_lib.h"
+      12                 :            : #include "library/rnglib.h"
+      13                 :            : 
+      14                 :            : /**
+      15                 :            :  * Generates a random byte stream of the specified size.
+      16                 :            :  *
+      17                 :            :  * If output is NULL, then return false.
+      18                 :            :  * If this interface is not supported, then return false.
+      19                 :            :  *
+      20                 :            :  * @param[out]  output  Pointer to buffer to receive random value.
+      21                 :            :  * @param[in]   size    Size of random bytes to generate.
+      22                 :            :  *
+      23                 :            :  * @retval true   Random byte stream generated successfully.
+      24                 :            :  * @retval false  Generation of random byte stream failed.
+      25                 :            :  **/
+      26                 :       3236 : bool libspdm_random_bytes(uint8_t *output, size_t size)
+      27                 :            : {
+      28                 :            :     bool ret;
+      29                 :            :     uint64_t temp_rand;
+      30                 :            :     size_t dst_size;
+      31                 :            : 
+      32                 :       3236 :     ret = false;
+      33                 :       3236 :     dst_size = size;
+      34                 :            : 
+      35         [ +  + ]:      15673 :     while (size > 0) {
+      36                 :            :         /* Use rnglib to get random number*/
+      37                 :      12437 :         ret = libspdm_get_random_number_64(&temp_rand);
+      38                 :            : 
+      39         [ -  + ]:      12437 :         if (!ret) {
+      40                 :          0 :             return ret;
+      41                 :            :         }
+      42                 :            : 
+      43         [ +  + ]:      12437 :         if (size >= sizeof(uint64_t)) {
+      44                 :      11332 :             libspdm_copy_mem(output, dst_size, &temp_rand, sizeof(uint64_t));
+      45                 :      11332 :             output += sizeof(uint64_t);
+      46                 :      11332 :             size -= sizeof(uint64_t);
+      47                 :      11332 :             dst_size -= sizeof(uint64_t);
+      48                 :            :         } else {
+      49                 :       1105 :             libspdm_copy_mem(output, dst_size, &temp_rand, size);
+      50                 :       1105 :             size = 0;
+      51                 :            :         }
+      52                 :            :     }
+      53                 :            : 
+      54                 :       3236 :     return ret;
+      55                 :            : }
+      56                 :            : 
+      57                 :       1256 : int libspdm_myrand(void *rng_state, unsigned char *output, size_t len)
+      58                 :            : {
+      59                 :       1256 :     bool result = libspdm_random_bytes(output, len);
+      60                 :            : 
+      61                 :            : 
+      62                 :            :     /* The MbedTLS function f_rng, which myrand implements, is not
+      63                 :            :      * documented well. From looking at code: zero is considered success,
+      64                 :            :      * while non-zero return value is considered failure.*/
+      65                 :            : 
+      66         [ +  - ]:       1256 :     return result ? 0 : -1;
+      67                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/sys_call/crt_wrapper_host.c.func-sort-c.html b/coverage_log/os_stub/cryptlib_mbedtls/sys_call/crt_wrapper_host.c.func-sort-c.html new file mode 100644 index 00000000000..63103b7bdc9 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/sys_call/crt_wrapper_host.c.func-sort-c.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/sys_call/crt_wrapper_host.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/sys_call - crt_wrapper_host.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:3933.3 %
Date:2024-09-22 08:21:07Functions:1333.3 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
my_printf0
my_snprintf0
mbedtls_platform_zeroize2660043
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/sys_call/crt_wrapper_host.c.func.html b/coverage_log/os_stub/cryptlib_mbedtls/sys_call/crt_wrapper_host.c.func.html new file mode 100644 index 00000000000..6756c76fb12 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/sys_call/crt_wrapper_host.c.func.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/sys_call/crt_wrapper_host.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/sys_call - crt_wrapper_host.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:3933.3 %
Date:2024-09-22 08:21:07Functions:1333.3 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_platform_zeroize2660043
my_printf0
my_snprintf0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/sys_call/crt_wrapper_host.c.gcov.html b/coverage_log/os_stub/cryptlib_mbedtls/sys_call/crt_wrapper_host.c.gcov.html new file mode 100644 index 00000000000..c9916a17242 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/sys_call/crt_wrapper_host.c.gcov.html @@ -0,0 +1,116 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/sys_call/crt_wrapper_host.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/sys_call - crt_wrapper_host.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:3933.3 %
Date:2024-09-22 08:21:07Functions:1333.3 %
Branches:00-
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 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                 :            : /** @file
+       8                 :            :  * C Run-Time Libraries (CRT) Wrapper Implementation.
+       9                 :            :  **/
+      10                 :            : 
+      11                 :            : #include <base.h>
+      12                 :            : #include "library/debuglib.h"
+      13                 :            : #include "library/memlib.h"
+      14                 :            : #include <stddef.h>
+      15                 :            : 
+      16                 :          0 : int my_printf(const char *fmt, ...)
+      17                 :            : {
+      18                 :          0 :     LIBSPDM_ASSERT(false);
+      19                 :          0 :     return 0;
+      20                 :            : }
+      21                 :            : 
+      22                 :          0 : int my_snprintf(char *str, size_t size, const char *format, ...)
+      23                 :            : {
+      24                 :          0 :     LIBSPDM_ASSERT(false);
+      25                 :          0 :     return 0;
+      26                 :            : }
+      27                 :            : 
+      28                 :    2660043 : void mbedtls_platform_zeroize(void *buf, size_t len)
+      29                 :            : {
+      30                 :    2660043 :     libspdm_zero_mem(buf, len);
+      31                 :    2660043 : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/sys_call/index-sort-b.html b/coverage_log/os_stub/cryptlib_mbedtls/sys_call/index-sort-b.html new file mode 100644 index 00000000000..4ba8f34535e --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/sys_call/index-sort-b.html @@ -0,0 +1,119 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/sys_call + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/sys_callHitTotalCoverage
Test:coverage.infoLines:172470.8 %
Date:2024-09-22 08:21:07Functions:3560.0 %
Branches:4666.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
mem_allocation.c +
93.3%93.3%
+
93.3 %14 / 15100.0 %2 / 266.7 %4 / 6
crt_wrapper_host.c +
33.3%33.3%
+
33.3 %3 / 933.3 %1 / 3-0 / 0
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/sys_call/index-sort-f.html b/coverage_log/os_stub/cryptlib_mbedtls/sys_call/index-sort-f.html new file mode 100644 index 00000000000..1dd1e7cb4e3 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/sys_call/index-sort-f.html @@ -0,0 +1,119 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/sys_call + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/sys_callHitTotalCoverage
Test:coverage.infoLines:172470.8 %
Date:2024-09-22 08:21:07Functions:3560.0 %
Branches:4666.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
crt_wrapper_host.c +
33.3%33.3%
+
33.3 %3 / 933.3 %1 / 3-0 / 0
mem_allocation.c +
93.3%93.3%
+
93.3 %14 / 15100.0 %2 / 266.7 %4 / 6
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/sys_call/index-sort-l.html b/coverage_log/os_stub/cryptlib_mbedtls/sys_call/index-sort-l.html new file mode 100644 index 00000000000..2fbb7666828 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/sys_call/index-sort-l.html @@ -0,0 +1,119 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/sys_call + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/sys_callHitTotalCoverage
Test:coverage.infoLines:172470.8 %
Date:2024-09-22 08:21:07Functions:3560.0 %
Branches:4666.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
crt_wrapper_host.c +
33.3%33.3%
+
33.3 %3 / 933.3 %1 / 3-0 / 0
mem_allocation.c +
93.3%93.3%
+
93.3 %14 / 15100.0 %2 / 266.7 %4 / 6
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/sys_call/index.html b/coverage_log/os_stub/cryptlib_mbedtls/sys_call/index.html new file mode 100644 index 00000000000..ef5a5942cab --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/sys_call/index.html @@ -0,0 +1,119 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/sys_call + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/sys_callHitTotalCoverage
Test:coverage.infoLines:172470.8 %
Date:2024-09-22 08:21:07Functions:3560.0 %
Branches:4666.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
crt_wrapper_host.c +
33.3%33.3%
+
33.3 %3 / 933.3 %1 / 3-0 / 0
mem_allocation.c +
93.3%93.3%
+
93.3 %14 / 15100.0 %2 / 266.7 %4 / 6
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/sys_call/mem_allocation.c.func-sort-c.html b/coverage_log/os_stub/cryptlib_mbedtls/sys_call/mem_allocation.c.func-sort-c.html new file mode 100644 index 00000000000..7015778a450 --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/sys_call/mem_allocation.c.func-sort-c.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/sys_call/mem_allocation.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/sys_call - mem_allocation.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:141593.3 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:4666.7 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
my_calloc2557180
my_free2570709
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/sys_call/mem_allocation.c.func.html b/coverage_log/os_stub/cryptlib_mbedtls/sys_call/mem_allocation.c.func.html new file mode 100644 index 00000000000..fc45484ef9b --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/sys_call/mem_allocation.c.func.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/sys_call/mem_allocation.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/sys_call - mem_allocation.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:141593.3 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:4666.7 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
my_calloc2557180
my_free2570709
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/cryptlib_mbedtls/sys_call/mem_allocation.c.gcov.html b/coverage_log/os_stub/cryptlib_mbedtls/sys_call/mem_allocation.c.gcov.html new file mode 100644 index 00000000000..8ef2131af3e --- /dev/null +++ b/coverage_log/os_stub/cryptlib_mbedtls/sys_call/mem_allocation.c.gcov.html @@ -0,0 +1,161 @@ + + + + + + + LCOV - coverage.info - os_stub/cryptlib_mbedtls/sys_call/mem_allocation.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/cryptlib_mbedtls/sys_call - mem_allocation.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:141593.3 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:4666.7 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 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                 :            : /** @file
+       8                 :            :  * Base Memory Allocation Routines Wrapper.
+       9                 :            :  **/
+      10                 :            : 
+      11                 :            : #include <base.h>
+      12                 :            : #include "library/debuglib.h"
+      13                 :            : #include "library/malloclib.h"
+      14                 :            : #include <stddef.h>
+      15                 :            : 
+      16                 :            : 
+      17                 :            : /* Extra header to record the memory buffer size from malloc routine.*/
+      18                 :            : 
+      19                 :            : #define CRYPTMEM_HEAD_VERSION 0x1
+      20                 :            : typedef struct {
+      21                 :            :     uint32_t version;
+      22                 :            :     uint32_t reserved;
+      23                 :            :     size_t size;
+      24                 :            : } CRYPTMEM_HEAD;
+      25                 :            : 
+      26                 :            : #define CRYPTMEM_OVERHEAD sizeof(CRYPTMEM_HEAD)
+      27                 :            : 
+      28                 :            : 
+      29                 :            : /* -- Memory-Allocation Routines --*/
+      30                 :            : 
+      31                 :            : 
+      32                 :            : /* Allocates memory blocks */
+      33                 :    2557180 : void *my_calloc(size_t num, size_t size)
+      34                 :            : {
+      35                 :            :     CRYPTMEM_HEAD *pool_hdr;
+      36                 :            :     size_t new_size;
+      37                 :            :     void *data;
+      38                 :            : 
+      39                 :            : 
+      40                 :            :     /* Adjust the size by the buffer header overhead*/
+      41                 :            : 
+      42                 :    2557180 :     new_size = (size_t)(size * num) + CRYPTMEM_OVERHEAD;
+      43                 :            : 
+      44                 :    2557180 :     data = allocate_zero_pool(new_size);
+      45         [ +  - ]:    2557180 :     if (data != NULL) {
+      46                 :    2557180 :         pool_hdr = (CRYPTMEM_HEAD *)data;
+      47                 :            : 
+      48                 :            :         /* Record the memory brief information*/
+      49                 :            : 
+      50                 :    2557180 :         pool_hdr->version = CRYPTMEM_HEAD_VERSION;
+      51                 :    2557180 :         pool_hdr->size = size;
+      52                 :            : 
+      53                 :    2557180 :         return (void *)(pool_hdr + 1);
+      54                 :            :     } else {
+      55                 :            : 
+      56                 :            :         /* The buffer allocation failed.*/
+      57                 :            : 
+      58                 :          0 :         return NULL;
+      59                 :            :     }
+      60                 :            : }
+      61                 :            : 
+      62                 :            : /* De-allocates or frees a memory block */
+      63                 :    2570709 : void my_free(void *ptr)
+      64                 :            : {
+      65                 :            :     CRYPTMEM_HEAD *pool_hdr;
+      66                 :            : 
+      67                 :            : 
+      68                 :            :     /* In Standard C, free() handles a null pointer argument transparently. This
+      69                 :            :      * is not true of free_pool() below, so protect it.*/
+      70                 :            : 
+      71         [ +  + ]:    2570709 :     if (ptr != NULL) {
+      72                 :    2556482 :         pool_hdr = (CRYPTMEM_HEAD *)ptr - 1;
+      73         [ -  + ]:    2556482 :         LIBSPDM_ASSERT(pool_hdr->version == CRYPTMEM_HEAD_VERSION);
+      74                 :    2556482 :         free_pool(pool_hdr);
+      75                 :            :     }
+      76                 :    2570709 : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/debuglib/debuglib.c.func-sort-c.html b/coverage_log/os_stub/debuglib/debuglib.c.func-sort-c.html new file mode 100644 index 00000000000..e6b41685df8 --- /dev/null +++ b/coverage_log/os_stub/debuglib/debuglib.c.func-sort-c.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - os_stub/debuglib/debuglib.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/debuglib - debuglib.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:81457.1 %
Date:2024-09-22 08:21:07Functions:1250.0 %
Branches:3837.5 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_debug_assert0
libspdm_debug_print392497
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/debuglib/debuglib.c.func.html b/coverage_log/os_stub/debuglib/debuglib.c.func.html new file mode 100644 index 00000000000..ca1c6e904b8 --- /dev/null +++ b/coverage_log/os_stub/debuglib/debuglib.c.func.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - os_stub/debuglib/debuglib.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/debuglib - debuglib.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:81457.1 %
Date:2024-09-22 08:21:07Functions:1250.0 %
Branches:3837.5 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_debug_assert0
libspdm_debug_print392497
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/debuglib/debuglib.c.gcov.html b/coverage_log/os_stub/debuglib/debuglib.c.gcov.html new file mode 100644 index 00000000000..536e3c65a6c --- /dev/null +++ b/coverage_log/os_stub/debuglib/debuglib.c.gcov.html @@ -0,0 +1,168 @@ + + + + + + + LCOV - coverage.info - os_stub/debuglib/debuglib.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/debuglib - debuglib.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:81457.1 %
Date:2024-09-22 08:21:07Functions:1250.0 %
Branches:3837.5 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 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 <base.h>
+       8                 :            : 
+       9                 :            : #include <stdio.h>
+      10                 :            : #include <stdlib.h>
+      11                 :            : #include <string.h>
+      12                 :            : #include <assert.h>
+      13                 :            : #include <stdarg.h>
+      14                 :            : 
+      15                 :            : #include "library/debuglib.h"
+      16                 :            : 
+      17                 :            : #if LIBSPDM_DEBUG_ASSERT_ENABLE
+      18                 :            : #define LIBSPDM_DEBUG_LIBSPDM_ASSERT_NATIVE 0
+      19                 :            : #define LIBSPDM_DEBUG_LIBSPDM_ASSERT_DEADLOOP 1
+      20                 :            : #define LIBSPDM_DEBUG_LIBSPDM_ASSERT_BREAKPOINT 2
+      21                 :            : #define LIBSPDM_DEBUG_LIBSPDM_ASSERT_EXIT 3
+      22                 :            : 
+      23                 :            : #ifndef LIBSPDM_DEBUG_LIBSPDM_ASSERT_CONFIG
+      24                 :            : #define LIBSPDM_DEBUG_LIBSPDM_ASSERT_CONFIG LIBSPDM_DEBUG_LIBSPDM_ASSERT_DEADLOOP
+      25                 :            : #endif
+      26                 :            : 
+      27                 :          0 : void libspdm_debug_assert(const char *file_name, size_t line_number, const char *description)
+      28                 :            : {
+      29                 :          0 :     printf("LIBSPDM_ASSERT: %s(%zu): %s\n", file_name, line_number, description);
+      30                 :            : 
+      31                 :            : #if (LIBSPDM_DEBUG_LIBSPDM_ASSERT_CONFIG == LIBSPDM_DEBUG_LIBSPDM_ASSERT_DEADLOOP)
+      32                 :            :     {
+      33                 :          0 :         volatile int32_t ___i = 1;
+      34         [ #  # ]:          0 :         while (___i)
+      35                 :            :             ;
+      36                 :            :     }
+      37                 :            : #elif (LIBSPDM_DEBUG_LIBSPDM_ASSERT_CONFIG == LIBSPDM_DEBUG_LIBSPDM_ASSERT_BREAKPOINT)
+      38                 :            : #if defined(_MSC_EXTENSIONS)
+      39                 :            :     __debugbreak();
+      40                 :            : #endif
+      41                 :            : #if defined(__GNUC__)
+      42                 :            :     __asm__ __volatile__ ("int $3");
+      43                 :            : #endif
+      44                 :            : #elif (LIBSPDM_DEBUG_LIBSPDM_ASSERT_CONFIG == LIBSPDM_DEBUG_LIBSPDM_ASSERT_EXIT)
+      45                 :            :     exit(1);
+      46                 :            : #else
+      47                 :            :     assert(false);
+      48                 :            : #endif
+      49                 :          0 : }
+      50                 :            : #endif /* LIBSPDM_DEBUG_ASSERT_ENABLE */
+      51                 :            : 
+      52                 :            : #if LIBSPDM_DEBUG_PRINT_ENABLE
+      53                 :            : 
+      54                 :            : /* Define the maximum debug and assert message length that this library supports. */
+      55                 :            : #define LIBSPDM_MAX_DEBUG_MESSAGE_LENGTH 0x100
+      56                 :            : 
+      57                 :            : #ifndef LIBSPDM_DEBUG_LEVEL_CONFIG
+      58                 :            : #define LIBSPDM_DEBUG_LEVEL_CONFIG (LIBSPDM_DEBUG_INFO | LIBSPDM_DEBUG_ERROR)
+      59                 :            : #endif
+      60                 :            : 
+      61                 :     392497 : void libspdm_debug_print(size_t error_level, const char *format, ...)
+      62                 :            : {
+      63                 :            :     char buffer[LIBSPDM_MAX_DEBUG_MESSAGE_LENGTH];
+      64                 :            :     va_list marker;
+      65                 :            :     int status;
+      66                 :            : 
+      67         [ -  + ]:     392497 :     if ((error_level & LIBSPDM_DEBUG_LEVEL_CONFIG) == 0) {
+      68                 :          0 :         return;
+      69                 :            :     }
+      70                 :            : 
+      71                 :     392497 :     va_start(marker, format);
+      72                 :     392497 :     status = vsnprintf(buffer, sizeof(buffer), format, marker);
+      73                 :     392497 :     va_end(marker);
+      74                 :            : 
+      75                 :            :     /* If status is negative then an encoding error has ocurred. */
+      76         [ -  + ]:     392497 :     assert(status >= 0);
+      77                 :            :     /* If status is greater than or equal to the size of the buffer then the buffer is not
+      78                 :            :      * large enough to handle the formatted string. */
+      79         [ -  + ]:     392497 :     assert(status < sizeof(buffer));
+      80                 :            : 
+      81                 :     392497 :     printf("%s", buffer);
+      82                 :            : }
+      83                 :            : #endif /* LIBSPDM_DEBUG_PRINT_ENABLE */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/debuglib/index-sort-b.html b/coverage_log/os_stub/debuglib/index-sort-b.html new file mode 100644 index 00000000000..d15c7eddc6f --- /dev/null +++ b/coverage_log/os_stub/debuglib/index-sort-b.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/debuglib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/debuglibHitTotalCoverage
Test:coverage.infoLines:81457.1 %
Date:2024-09-22 08:21:07Functions:1250.0 %
Branches:3837.5 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
debuglib.c +
57.1%57.1%
+
57.1 %8 / 1450.0 %1 / 237.5 %3 / 8
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/debuglib/index-sort-f.html b/coverage_log/os_stub/debuglib/index-sort-f.html new file mode 100644 index 00000000000..fb723903fd0 --- /dev/null +++ b/coverage_log/os_stub/debuglib/index-sort-f.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/debuglib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/debuglibHitTotalCoverage
Test:coverage.infoLines:81457.1 %
Date:2024-09-22 08:21:07Functions:1250.0 %
Branches:3837.5 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
debuglib.c +
57.1%57.1%
+
57.1 %8 / 1450.0 %1 / 237.5 %3 / 8
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/debuglib/index-sort-l.html b/coverage_log/os_stub/debuglib/index-sort-l.html new file mode 100644 index 00000000000..a8a7d99e9bc --- /dev/null +++ b/coverage_log/os_stub/debuglib/index-sort-l.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/debuglib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/debuglibHitTotalCoverage
Test:coverage.infoLines:81457.1 %
Date:2024-09-22 08:21:07Functions:1250.0 %
Branches:3837.5 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
debuglib.c +
57.1%57.1%
+
57.1 %8 / 1450.0 %1 / 237.5 %3 / 8
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/debuglib/index.html b/coverage_log/os_stub/debuglib/index.html new file mode 100644 index 00000000000..9c39fc56a7b --- /dev/null +++ b/coverage_log/os_stub/debuglib/index.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/debuglib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/debuglibHitTotalCoverage
Test:coverage.infoLines:81457.1 %
Date:2024-09-22 08:21:07Functions:1250.0 %
Branches:3837.5 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
debuglib.c +
57.1%57.1%
+
57.1 %8 / 1450.0 %1 / 237.5 %3 / 8
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/malloclib/index-sort-b.html b/coverage_log/os_stub/malloclib/index-sort-b.html new file mode 100644 index 00000000000..496162d5422 --- /dev/null +++ b/coverage_log/os_stub/malloclib/index-sort-b.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/malloclib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/malloclibHitTotalCoverage
Test:coverage.infoLines:101190.9 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:1250.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
malloclib.c +
90.9%90.9%
+
90.9 %10 / 11100.0 %3 / 350.0 %1 / 2
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/malloclib/index-sort-f.html b/coverage_log/os_stub/malloclib/index-sort-f.html new file mode 100644 index 00000000000..024cbe4217c --- /dev/null +++ b/coverage_log/os_stub/malloclib/index-sort-f.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/malloclib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/malloclibHitTotalCoverage
Test:coverage.infoLines:101190.9 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:1250.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
malloclib.c +
90.9%90.9%
+
90.9 %10 / 11100.0 %3 / 350.0 %1 / 2
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/malloclib/index-sort-l.html b/coverage_log/os_stub/malloclib/index-sort-l.html new file mode 100644 index 00000000000..f29a02093f5 --- /dev/null +++ b/coverage_log/os_stub/malloclib/index-sort-l.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/malloclib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/malloclibHitTotalCoverage
Test:coverage.infoLines:101190.9 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:1250.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
malloclib.c +
90.9%90.9%
+
90.9 %10 / 11100.0 %3 / 350.0 %1 / 2
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/malloclib/index.html b/coverage_log/os_stub/malloclib/index.html new file mode 100644 index 00000000000..642124ec82d --- /dev/null +++ b/coverage_log/os_stub/malloclib/index.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/malloclib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/malloclibHitTotalCoverage
Test:coverage.infoLines:101190.9 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:1250.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
malloclib.c +
90.9%90.9%
+
90.9 %10 / 11100.0 %3 / 350.0 %1 / 2
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/malloclib/malloclib.c.func-sort-c.html b/coverage_log/os_stub/malloclib/malloclib.c.func-sort-c.html new file mode 100644 index 00000000000..178aabf82ca --- /dev/null +++ b/coverage_log/os_stub/malloclib/malloclib.c.func-sort-c.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - os_stub/malloclib/malloclib.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/malloclib - malloclib.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:101190.9 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:1250.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
allocate_pool159
free_pool2558461
allocate_zero_pool2559254
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/malloclib/malloclib.c.func.html b/coverage_log/os_stub/malloclib/malloclib.c.func.html new file mode 100644 index 00000000000..76e21d1d2e3 --- /dev/null +++ b/coverage_log/os_stub/malloclib/malloclib.c.func.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - os_stub/malloclib/malloclib.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/malloclib - malloclib.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:101190.9 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:1250.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
allocate_pool159
allocate_zero_pool2559254
free_pool2558461
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/malloclib/malloclib.c.gcov.html b/coverage_log/os_stub/malloclib/malloclib.c.gcov.html new file mode 100644 index 00000000000..e3a53e89c4d --- /dev/null +++ b/coverage_log/os_stub/malloclib/malloclib.c.gcov.html @@ -0,0 +1,118 @@ + + + + + + + LCOV - coverage.info - os_stub/malloclib/malloclib.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/malloclib - malloclib.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:101190.9 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:1250.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 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 <base.h>
+       8                 :            : 
+       9                 :            : #include <stdio.h>
+      10                 :            : #include <stdlib.h>
+      11                 :            : #include <string.h>
+      12                 :            : #include <assert.h>
+      13                 :            : 
+      14                 :        159 : void *allocate_pool(size_t AllocationSize)
+      15                 :            : {
+      16                 :        159 :     return malloc(AllocationSize);
+      17                 :            : }
+      18                 :            : 
+      19                 :    2559254 : void *allocate_zero_pool(size_t AllocationSize)
+      20                 :            : {
+      21                 :            :     void *buffer;
+      22                 :    2559254 :     buffer = malloc(AllocationSize);
+      23         [ -  + ]:    2559254 :     if (buffer == NULL) {
+      24                 :          0 :         return NULL;
+      25                 :            :     }
+      26                 :    2559254 :     memset(buffer, 0, AllocationSize);
+      27                 :    2559254 :     return buffer;
+      28                 :            : }
+      29                 :            : 
+      30                 :    2558461 : void free_pool(void *buffer)
+      31                 :            : {
+      32                 :    2558461 :     free(buffer);
+      33                 :    2558461 : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/cipher.h.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/cipher.h.func-sort-c.html new file mode 100644 index 00000000000..9c408dab74b --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/cipher.h.func-sort-c.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/include/mbedtls/cipher.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/include/mbedtls - cipher.h (source / functions)HitTotalCoverage
Test:coverage.infoLines:92240.9 %
Date:2024-09-22 08:21:07Functions:3560.0 %
Branches:31225.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_cipher_get_iv_size0
mbedtls_cipher_info_get_iv_size0
mbedtls_cipher_info_get_block_size791
mbedtls_cipher_info_get_key_bitlen3160
mbedtls_cipher_get_block_size3654
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/cipher.h.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/cipher.h.func.html new file mode 100644 index 00000000000..ed777047665 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/cipher.h.func.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/include/mbedtls/cipher.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/include/mbedtls - cipher.h (source / functions)HitTotalCoverage
Test:coverage.infoLines:92240.9 %
Date:2024-09-22 08:21:07Functions:3560.0 %
Branches:31225.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_cipher_get_block_size3654
mbedtls_cipher_get_iv_size0
mbedtls_cipher_info_get_block_size791
mbedtls_cipher_info_get_iv_size0
mbedtls_cipher_info_get_key_bitlen3160
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/cipher.h.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/cipher.h.gcov.html new file mode 100644 index 00000000000..2a7618283aa --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/cipher.h.gcov.html @@ -0,0 +1,1258 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/include/mbedtls/cipher.h + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/include/mbedtls - cipher.h (source / functions)HitTotalCoverage
Test:coverage.infoLines:92240.9 %
Date:2024-09-22 08:21:07Functions:3560.0 %
Branches:31225.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  * \file cipher.h
+       3                 :            :  *
+       4                 :            :  * \brief This file contains an abstraction interface for use with the cipher
+       5                 :            :  * primitives provided by the library. It provides a common interface to all of
+       6                 :            :  * the available cipher operations.
+       7                 :            :  *
+       8                 :            :  * \author Adriaan de Jong <dejong@fox-it.com>
+       9                 :            :  */
+      10                 :            : /*
+      11                 :            :  *  Copyright The Mbed TLS Contributors
+      12                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+      13                 :            :  */
+      14                 :            : 
+      15                 :            : #ifndef MBEDTLS_CIPHER_H
+      16                 :            : #define MBEDTLS_CIPHER_H
+      17                 :            : #include "mbedtls/private_access.h"
+      18                 :            : 
+      19                 :            : #include "mbedtls/build_info.h"
+      20                 :            : 
+      21                 :            : #include <stddef.h>
+      22                 :            : #include "mbedtls/platform_util.h"
+      23                 :            : 
+      24                 :            : #if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CCM_C) || defined(MBEDTLS_CHACHAPOLY_C)
+      25                 :            : #define MBEDTLS_CIPHER_MODE_AEAD
+      26                 :            : #endif
+      27                 :            : 
+      28                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+      29                 :            : #define MBEDTLS_CIPHER_MODE_WITH_PADDING
+      30                 :            : #endif
+      31                 :            : 
+      32                 :            : #if defined(MBEDTLS_CIPHER_NULL_CIPHER) || \
+      33                 :            :     defined(MBEDTLS_CHACHA20_C)
+      34                 :            : #define MBEDTLS_CIPHER_MODE_STREAM
+      35                 :            : #endif
+      36                 :            : 
+      37                 :            : /** The selected feature is not available. */
+      38                 :            : #define MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE  -0x6080
+      39                 :            : /** Bad input parameters. */
+      40                 :            : #define MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA       -0x6100
+      41                 :            : /** Failed to allocate memory. */
+      42                 :            : #define MBEDTLS_ERR_CIPHER_ALLOC_FAILED         -0x6180
+      43                 :            : /** Input data contains invalid padding and is rejected. */
+      44                 :            : #define MBEDTLS_ERR_CIPHER_INVALID_PADDING      -0x6200
+      45                 :            : /** Decryption of block requires a full block. */
+      46                 :            : #define MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED  -0x6280
+      47                 :            : /** Authentication failed (for AEAD modes). */
+      48                 :            : #define MBEDTLS_ERR_CIPHER_AUTH_FAILED          -0x6300
+      49                 :            : /** The context is invalid. For example, because it was freed. */
+      50                 :            : #define MBEDTLS_ERR_CIPHER_INVALID_CONTEXT      -0x6380
+      51                 :            : 
+      52                 :            : #define MBEDTLS_CIPHER_VARIABLE_IV_LEN     0x01    /**< Cipher accepts IVs of variable length. */
+      53                 :            : #define MBEDTLS_CIPHER_VARIABLE_KEY_LEN    0x02    /**< Cipher accepts keys of variable length. */
+      54                 :            : 
+      55                 :            : #ifdef __cplusplus
+      56                 :            : extern "C" {
+      57                 :            : #endif
+      58                 :            : 
+      59                 :            : /**
+      60                 :            :  * \brief     Supported cipher types.
+      61                 :            :  *
+      62                 :            :  * \warning   DES/3DES are considered weak ciphers and their use
+      63                 :            :  *            constitutes a security risk. We recommend considering stronger
+      64                 :            :  *            ciphers instead.
+      65                 :            :  */
+      66                 :            : typedef enum {
+      67                 :            :     MBEDTLS_CIPHER_ID_NONE = 0,  /**< Placeholder to mark the end of cipher ID lists. */
+      68                 :            :     MBEDTLS_CIPHER_ID_NULL,      /**< The identity cipher, treated as a stream cipher. */
+      69                 :            :     MBEDTLS_CIPHER_ID_AES,       /**< The AES cipher. */
+      70                 :            :     MBEDTLS_CIPHER_ID_DES,       /**< The DES cipher. \warning DES is considered weak. */
+      71                 :            :     MBEDTLS_CIPHER_ID_3DES,      /**< The Triple DES cipher. \warning 3DES is considered weak. */
+      72                 :            :     MBEDTLS_CIPHER_ID_CAMELLIA,  /**< The Camellia cipher. */
+      73                 :            :     MBEDTLS_CIPHER_ID_ARIA,      /**< The Aria cipher. */
+      74                 :            :     MBEDTLS_CIPHER_ID_CHACHA20,  /**< The ChaCha20 cipher. */
+      75                 :            : } mbedtls_cipher_id_t;
+      76                 :            : 
+      77                 :            : /**
+      78                 :            :  * \brief     Supported {cipher type, cipher mode} pairs.
+      79                 :            :  *
+      80                 :            :  * \warning   DES/3DES are considered weak ciphers and their use
+      81                 :            :  *            constitutes a security risk. We recommend considering stronger
+      82                 :            :  *            ciphers instead.
+      83                 :            :  */
+      84                 :            : typedef enum {
+      85                 :            :     MBEDTLS_CIPHER_NONE = 0,             /**< Placeholder to mark the end of cipher-pair lists. */
+      86                 :            :     MBEDTLS_CIPHER_NULL,                 /**< The identity stream cipher. */
+      87                 :            :     MBEDTLS_CIPHER_AES_128_ECB,          /**< AES cipher with 128-bit ECB mode. */
+      88                 :            :     MBEDTLS_CIPHER_AES_192_ECB,          /**< AES cipher with 192-bit ECB mode. */
+      89                 :            :     MBEDTLS_CIPHER_AES_256_ECB,          /**< AES cipher with 256-bit ECB mode. */
+      90                 :            :     MBEDTLS_CIPHER_AES_128_CBC,          /**< AES cipher with 128-bit CBC mode. */
+      91                 :            :     MBEDTLS_CIPHER_AES_192_CBC,          /**< AES cipher with 192-bit CBC mode. */
+      92                 :            :     MBEDTLS_CIPHER_AES_256_CBC,          /**< AES cipher with 256-bit CBC mode. */
+      93                 :            :     MBEDTLS_CIPHER_AES_128_CFB128,       /**< AES cipher with 128-bit CFB128 mode. */
+      94                 :            :     MBEDTLS_CIPHER_AES_192_CFB128,       /**< AES cipher with 192-bit CFB128 mode. */
+      95                 :            :     MBEDTLS_CIPHER_AES_256_CFB128,       /**< AES cipher with 256-bit CFB128 mode. */
+      96                 :            :     MBEDTLS_CIPHER_AES_128_CTR,          /**< AES cipher with 128-bit CTR mode. */
+      97                 :            :     MBEDTLS_CIPHER_AES_192_CTR,          /**< AES cipher with 192-bit CTR mode. */
+      98                 :            :     MBEDTLS_CIPHER_AES_256_CTR,          /**< AES cipher with 256-bit CTR mode. */
+      99                 :            :     MBEDTLS_CIPHER_AES_128_GCM,          /**< AES cipher with 128-bit GCM mode. */
+     100                 :            :     MBEDTLS_CIPHER_AES_192_GCM,          /**< AES cipher with 192-bit GCM mode. */
+     101                 :            :     MBEDTLS_CIPHER_AES_256_GCM,          /**< AES cipher with 256-bit GCM mode. */
+     102                 :            :     MBEDTLS_CIPHER_CAMELLIA_128_ECB,     /**< Camellia cipher with 128-bit ECB mode. */
+     103                 :            :     MBEDTLS_CIPHER_CAMELLIA_192_ECB,     /**< Camellia cipher with 192-bit ECB mode. */
+     104                 :            :     MBEDTLS_CIPHER_CAMELLIA_256_ECB,     /**< Camellia cipher with 256-bit ECB mode. */
+     105                 :            :     MBEDTLS_CIPHER_CAMELLIA_128_CBC,     /**< Camellia cipher with 128-bit CBC mode. */
+     106                 :            :     MBEDTLS_CIPHER_CAMELLIA_192_CBC,     /**< Camellia cipher with 192-bit CBC mode. */
+     107                 :            :     MBEDTLS_CIPHER_CAMELLIA_256_CBC,     /**< Camellia cipher with 256-bit CBC mode. */
+     108                 :            :     MBEDTLS_CIPHER_CAMELLIA_128_CFB128,  /**< Camellia cipher with 128-bit CFB128 mode. */
+     109                 :            :     MBEDTLS_CIPHER_CAMELLIA_192_CFB128,  /**< Camellia cipher with 192-bit CFB128 mode. */
+     110                 :            :     MBEDTLS_CIPHER_CAMELLIA_256_CFB128,  /**< Camellia cipher with 256-bit CFB128 mode. */
+     111                 :            :     MBEDTLS_CIPHER_CAMELLIA_128_CTR,     /**< Camellia cipher with 128-bit CTR mode. */
+     112                 :            :     MBEDTLS_CIPHER_CAMELLIA_192_CTR,     /**< Camellia cipher with 192-bit CTR mode. */
+     113                 :            :     MBEDTLS_CIPHER_CAMELLIA_256_CTR,     /**< Camellia cipher with 256-bit CTR mode. */
+     114                 :            :     MBEDTLS_CIPHER_CAMELLIA_128_GCM,     /**< Camellia cipher with 128-bit GCM mode. */
+     115                 :            :     MBEDTLS_CIPHER_CAMELLIA_192_GCM,     /**< Camellia cipher with 192-bit GCM mode. */
+     116                 :            :     MBEDTLS_CIPHER_CAMELLIA_256_GCM,     /**< Camellia cipher with 256-bit GCM mode. */
+     117                 :            :     MBEDTLS_CIPHER_DES_ECB,              /**< DES cipher with ECB mode. \warning DES is considered weak. */
+     118                 :            :     MBEDTLS_CIPHER_DES_CBC,              /**< DES cipher with CBC mode. \warning DES is considered weak. */
+     119                 :            :     MBEDTLS_CIPHER_DES_EDE_ECB,          /**< DES cipher with EDE ECB mode. \warning 3DES is considered weak. */
+     120                 :            :     MBEDTLS_CIPHER_DES_EDE_CBC,          /**< DES cipher with EDE CBC mode. \warning 3DES is considered weak. */
+     121                 :            :     MBEDTLS_CIPHER_DES_EDE3_ECB,         /**< DES cipher with EDE3 ECB mode. \warning 3DES is considered weak. */
+     122                 :            :     MBEDTLS_CIPHER_DES_EDE3_CBC,         /**< DES cipher with EDE3 CBC mode. \warning 3DES is considered weak. */
+     123                 :            :     MBEDTLS_CIPHER_AES_128_CCM,          /**< AES cipher with 128-bit CCM mode. */
+     124                 :            :     MBEDTLS_CIPHER_AES_192_CCM,          /**< AES cipher with 192-bit CCM mode. */
+     125                 :            :     MBEDTLS_CIPHER_AES_256_CCM,          /**< AES cipher with 256-bit CCM mode. */
+     126                 :            :     MBEDTLS_CIPHER_AES_128_CCM_STAR_NO_TAG, /**< AES cipher with 128-bit CCM_STAR_NO_TAG mode. */
+     127                 :            :     MBEDTLS_CIPHER_AES_192_CCM_STAR_NO_TAG, /**< AES cipher with 192-bit CCM_STAR_NO_TAG mode. */
+     128                 :            :     MBEDTLS_CIPHER_AES_256_CCM_STAR_NO_TAG, /**< AES cipher with 256-bit CCM_STAR_NO_TAG mode. */
+     129                 :            :     MBEDTLS_CIPHER_CAMELLIA_128_CCM,     /**< Camellia cipher with 128-bit CCM mode. */
+     130                 :            :     MBEDTLS_CIPHER_CAMELLIA_192_CCM,     /**< Camellia cipher with 192-bit CCM mode. */
+     131                 :            :     MBEDTLS_CIPHER_CAMELLIA_256_CCM,     /**< Camellia cipher with 256-bit CCM mode. */
+     132                 :            :     MBEDTLS_CIPHER_CAMELLIA_128_CCM_STAR_NO_TAG, /**< Camellia cipher with 128-bit CCM_STAR_NO_TAG mode. */
+     133                 :            :     MBEDTLS_CIPHER_CAMELLIA_192_CCM_STAR_NO_TAG, /**< Camellia cipher with 192-bit CCM_STAR_NO_TAG mode. */
+     134                 :            :     MBEDTLS_CIPHER_CAMELLIA_256_CCM_STAR_NO_TAG, /**< Camellia cipher with 256-bit CCM_STAR_NO_TAG mode. */
+     135                 :            :     MBEDTLS_CIPHER_ARIA_128_ECB,         /**< Aria cipher with 128-bit key and ECB mode. */
+     136                 :            :     MBEDTLS_CIPHER_ARIA_192_ECB,         /**< Aria cipher with 192-bit key and ECB mode. */
+     137                 :            :     MBEDTLS_CIPHER_ARIA_256_ECB,         /**< Aria cipher with 256-bit key and ECB mode. */
+     138                 :            :     MBEDTLS_CIPHER_ARIA_128_CBC,         /**< Aria cipher with 128-bit key and CBC mode. */
+     139                 :            :     MBEDTLS_CIPHER_ARIA_192_CBC,         /**< Aria cipher with 192-bit key and CBC mode. */
+     140                 :            :     MBEDTLS_CIPHER_ARIA_256_CBC,         /**< Aria cipher with 256-bit key and CBC mode. */
+     141                 :            :     MBEDTLS_CIPHER_ARIA_128_CFB128,      /**< Aria cipher with 128-bit key and CFB-128 mode. */
+     142                 :            :     MBEDTLS_CIPHER_ARIA_192_CFB128,      /**< Aria cipher with 192-bit key and CFB-128 mode. */
+     143                 :            :     MBEDTLS_CIPHER_ARIA_256_CFB128,      /**< Aria cipher with 256-bit key and CFB-128 mode. */
+     144                 :            :     MBEDTLS_CIPHER_ARIA_128_CTR,         /**< Aria cipher with 128-bit key and CTR mode. */
+     145                 :            :     MBEDTLS_CIPHER_ARIA_192_CTR,         /**< Aria cipher with 192-bit key and CTR mode. */
+     146                 :            :     MBEDTLS_CIPHER_ARIA_256_CTR,         /**< Aria cipher with 256-bit key and CTR mode. */
+     147                 :            :     MBEDTLS_CIPHER_ARIA_128_GCM,         /**< Aria cipher with 128-bit key and GCM mode. */
+     148                 :            :     MBEDTLS_CIPHER_ARIA_192_GCM,         /**< Aria cipher with 192-bit key and GCM mode. */
+     149                 :            :     MBEDTLS_CIPHER_ARIA_256_GCM,         /**< Aria cipher with 256-bit key and GCM mode. */
+     150                 :            :     MBEDTLS_CIPHER_ARIA_128_CCM,         /**< Aria cipher with 128-bit key and CCM mode. */
+     151                 :            :     MBEDTLS_CIPHER_ARIA_192_CCM,         /**< Aria cipher with 192-bit key and CCM mode. */
+     152                 :            :     MBEDTLS_CIPHER_ARIA_256_CCM,         /**< Aria cipher with 256-bit key and CCM mode. */
+     153                 :            :     MBEDTLS_CIPHER_ARIA_128_CCM_STAR_NO_TAG, /**< Aria cipher with 128-bit key and CCM_STAR_NO_TAG mode. */
+     154                 :            :     MBEDTLS_CIPHER_ARIA_192_CCM_STAR_NO_TAG, /**< Aria cipher with 192-bit key and CCM_STAR_NO_TAG mode. */
+     155                 :            :     MBEDTLS_CIPHER_ARIA_256_CCM_STAR_NO_TAG, /**< Aria cipher with 256-bit key and CCM_STAR_NO_TAG mode. */
+     156                 :            :     MBEDTLS_CIPHER_AES_128_OFB,          /**< AES 128-bit cipher in OFB mode. */
+     157                 :            :     MBEDTLS_CIPHER_AES_192_OFB,          /**< AES 192-bit cipher in OFB mode. */
+     158                 :            :     MBEDTLS_CIPHER_AES_256_OFB,          /**< AES 256-bit cipher in OFB mode. */
+     159                 :            :     MBEDTLS_CIPHER_AES_128_XTS,          /**< AES 128-bit cipher in XTS block mode. */
+     160                 :            :     MBEDTLS_CIPHER_AES_256_XTS,          /**< AES 256-bit cipher in XTS block mode. */
+     161                 :            :     MBEDTLS_CIPHER_CHACHA20,             /**< ChaCha20 stream cipher. */
+     162                 :            :     MBEDTLS_CIPHER_CHACHA20_POLY1305,    /**< ChaCha20-Poly1305 AEAD cipher. */
+     163                 :            :     MBEDTLS_CIPHER_AES_128_KW,           /**< AES cipher with 128-bit NIST KW mode. */
+     164                 :            :     MBEDTLS_CIPHER_AES_192_KW,           /**< AES cipher with 192-bit NIST KW mode. */
+     165                 :            :     MBEDTLS_CIPHER_AES_256_KW,           /**< AES cipher with 256-bit NIST KW mode. */
+     166                 :            :     MBEDTLS_CIPHER_AES_128_KWP,          /**< AES cipher with 128-bit NIST KWP mode. */
+     167                 :            :     MBEDTLS_CIPHER_AES_192_KWP,          /**< AES cipher with 192-bit NIST KWP mode. */
+     168                 :            :     MBEDTLS_CIPHER_AES_256_KWP,          /**< AES cipher with 256-bit NIST KWP mode. */
+     169                 :            : } mbedtls_cipher_type_t;
+     170                 :            : 
+     171                 :            : /** Supported cipher modes. */
+     172                 :            : typedef enum {
+     173                 :            :     MBEDTLS_MODE_NONE = 0,               /**< None.                        */
+     174                 :            :     MBEDTLS_MODE_ECB,                    /**< The ECB cipher mode.         */
+     175                 :            :     MBEDTLS_MODE_CBC,                    /**< The CBC cipher mode.         */
+     176                 :            :     MBEDTLS_MODE_CFB,                    /**< The CFB cipher mode.         */
+     177                 :            :     MBEDTLS_MODE_OFB,                    /**< The OFB cipher mode.         */
+     178                 :            :     MBEDTLS_MODE_CTR,                    /**< The CTR cipher mode.         */
+     179                 :            :     MBEDTLS_MODE_GCM,                    /**< The GCM cipher mode.         */
+     180                 :            :     MBEDTLS_MODE_STREAM,                 /**< The stream cipher mode.      */
+     181                 :            :     MBEDTLS_MODE_CCM,                    /**< The CCM cipher mode.         */
+     182                 :            :     MBEDTLS_MODE_CCM_STAR_NO_TAG,        /**< The CCM*-no-tag cipher mode. */
+     183                 :            :     MBEDTLS_MODE_XTS,                    /**< The XTS cipher mode.         */
+     184                 :            :     MBEDTLS_MODE_CHACHAPOLY,             /**< The ChaCha-Poly cipher mode. */
+     185                 :            :     MBEDTLS_MODE_KW,                     /**< The SP800-38F KW mode */
+     186                 :            :     MBEDTLS_MODE_KWP,                    /**< The SP800-38F KWP mode */
+     187                 :            : } mbedtls_cipher_mode_t;
+     188                 :            : 
+     189                 :            : /** Supported cipher padding types. */
+     190                 :            : typedef enum {
+     191                 :            :     MBEDTLS_PADDING_PKCS7 = 0,     /**< PKCS7 padding (default).        */
+     192                 :            :     MBEDTLS_PADDING_ONE_AND_ZEROS, /**< ISO/IEC 7816-4 padding.         */
+     193                 :            :     MBEDTLS_PADDING_ZEROS_AND_LEN, /**< ANSI X.923 padding.             */
+     194                 :            :     MBEDTLS_PADDING_ZEROS,         /**< Zero padding (not reversible). */
+     195                 :            :     MBEDTLS_PADDING_NONE,          /**< Never pad (full blocks only).   */
+     196                 :            : } mbedtls_cipher_padding_t;
+     197                 :            : 
+     198                 :            : /** Type of operation. */
+     199                 :            : typedef enum {
+     200                 :            :     MBEDTLS_OPERATION_NONE = -1,
+     201                 :            :     MBEDTLS_DECRYPT = 0,
+     202                 :            :     MBEDTLS_ENCRYPT,
+     203                 :            : } mbedtls_operation_t;
+     204                 :            : 
+     205                 :            : enum {
+     206                 :            :     /** Undefined key length. */
+     207                 :            :     MBEDTLS_KEY_LENGTH_NONE = 0,
+     208                 :            :     /** Key length, in bits (including parity), for DES keys. \warning DES is considered weak. */
+     209                 :            :     MBEDTLS_KEY_LENGTH_DES  = 64,
+     210                 :            :     /** Key length in bits, including parity, for DES in two-key EDE. \warning 3DES is considered weak. */
+     211                 :            :     MBEDTLS_KEY_LENGTH_DES_EDE = 128,
+     212                 :            :     /** Key length in bits, including parity, for DES in three-key EDE. \warning 3DES is considered weak. */
+     213                 :            :     MBEDTLS_KEY_LENGTH_DES_EDE3 = 192,
+     214                 :            : };
+     215                 :            : 
+     216                 :            : /** Maximum length of any IV, in Bytes. */
+     217                 :            : /* This should ideally be derived automatically from list of ciphers.
+     218                 :            :  * This should be kept in sync with MBEDTLS_SSL_MAX_IV_LENGTH defined
+     219                 :            :  * in library/ssl_misc.h. */
+     220                 :            : #define MBEDTLS_MAX_IV_LENGTH      16
+     221                 :            : 
+     222                 :            : /** Maximum block size of any cipher, in Bytes. */
+     223                 :            : /* This should ideally be derived automatically from list of ciphers.
+     224                 :            :  * This should be kept in sync with MBEDTLS_SSL_MAX_BLOCK_LENGTH defined
+     225                 :            :  * in library/ssl_misc.h. */
+     226                 :            : #define MBEDTLS_MAX_BLOCK_LENGTH   16
+     227                 :            : 
+     228                 :            : /** Maximum key length, in Bytes. */
+     229                 :            : /* This should ideally be derived automatically from list of ciphers.
+     230                 :            :  * For now, only check whether XTS is enabled which uses 64 Byte keys,
+     231                 :            :  * and use 32 Bytes as an upper bound for the maximum key length otherwise.
+     232                 :            :  * This should be kept in sync with MBEDTLS_SSL_MAX_BLOCK_LENGTH defined
+     233                 :            :  * in library/ssl_misc.h, which however deliberately ignores the case of XTS
+     234                 :            :  * since the latter isn't used in SSL/TLS. */
+     235                 :            : #if defined(MBEDTLS_CIPHER_MODE_XTS)
+     236                 :            : #define MBEDTLS_MAX_KEY_LENGTH     64
+     237                 :            : #else
+     238                 :            : #define MBEDTLS_MAX_KEY_LENGTH     32
+     239                 :            : #endif /* MBEDTLS_CIPHER_MODE_XTS */
+     240                 :            : 
+     241                 :            : /**
+     242                 :            :  * Base cipher information (opaque struct).
+     243                 :            :  */
+     244                 :            : typedef struct mbedtls_cipher_base_t mbedtls_cipher_base_t;
+     245                 :            : 
+     246                 :            : /**
+     247                 :            :  * CMAC context (opaque struct).
+     248                 :            :  */
+     249                 :            : typedef struct mbedtls_cmac_context_t mbedtls_cmac_context_t;
+     250                 :            : 
+     251                 :            : /**
+     252                 :            :  * Cipher information. Allows calling cipher functions
+     253                 :            :  * in a generic way.
+     254                 :            :  *
+     255                 :            :  * \note        The library does not support custom cipher info structures,
+     256                 :            :  *              only built-in structures returned by the functions
+     257                 :            :  *              mbedtls_cipher_info_from_string(),
+     258                 :            :  *              mbedtls_cipher_info_from_type(),
+     259                 :            :  *              mbedtls_cipher_info_from_values(),
+     260                 :            :  *              mbedtls_cipher_info_from_psa().
+     261                 :            :  *
+     262                 :            :  * \note        Some fields store a value that has been right-shifted to save
+     263                 :            :  *              code-size, so should not be used directly. The accessor
+     264                 :            :  *              functions adjust for this and return the "natural" value.
+     265                 :            :  */
+     266                 :            : typedef struct mbedtls_cipher_info_t {
+     267                 :            :     /** Name of the cipher. */
+     268                 :            :     const char *MBEDTLS_PRIVATE(name);
+     269                 :            : 
+     270                 :            :     /** The block size, in bytes. */
+     271                 :            :     unsigned int MBEDTLS_PRIVATE(block_size) : 5;
+     272                 :            : 
+     273                 :            :     /** IV or nonce size, in bytes (right shifted by #MBEDTLS_IV_SIZE_SHIFT).
+     274                 :            :      * For ciphers that accept variable IV sizes,
+     275                 :            :      * this is the recommended size.
+     276                 :            :      */
+     277                 :            :     unsigned int MBEDTLS_PRIVATE(iv_size) : 3;
+     278                 :            : 
+     279                 :            :     /** The cipher key length, in bits (right shifted by #MBEDTLS_KEY_BITLEN_SHIFT).
+     280                 :            :      * This is the default length for variable sized ciphers.
+     281                 :            :      * Includes parity bits for ciphers like DES.
+     282                 :            :      */
+     283                 :            :     unsigned int MBEDTLS_PRIVATE(key_bitlen) : 4;
+     284                 :            : 
+     285                 :            :     /** The cipher mode (as per mbedtls_cipher_mode_t).
+     286                 :            :      * For example, MBEDTLS_MODE_CBC.
+     287                 :            :      */
+     288                 :            :     unsigned int MBEDTLS_PRIVATE(mode) : 4;
+     289                 :            : 
+     290                 :            :     /** Full cipher identifier (as per mbedtls_cipher_type_t).
+     291                 :            :      * For example, MBEDTLS_CIPHER_AES_256_CBC.
+     292                 :            :      *
+     293                 :            :      * This could be 7 bits, but 8 bits retains byte alignment for the
+     294                 :            :      * next field, which reduces code size to access that field.
+     295                 :            :      */
+     296                 :            :     unsigned int MBEDTLS_PRIVATE(type) : 8;
+     297                 :            : 
+     298                 :            :     /** Bitflag comprised of MBEDTLS_CIPHER_VARIABLE_IV_LEN and
+     299                 :            :      *  MBEDTLS_CIPHER_VARIABLE_KEY_LEN indicating whether the
+     300                 :            :      *  cipher supports variable IV or variable key sizes, respectively.
+     301                 :            :      */
+     302                 :            :     unsigned int MBEDTLS_PRIVATE(flags) : 2;
+     303                 :            : 
+     304                 :            :     /** Index to LUT for base cipher information and functions. */
+     305                 :            :     unsigned int MBEDTLS_PRIVATE(base_idx) : 5;
+     306                 :            : 
+     307                 :            : } mbedtls_cipher_info_t;
+     308                 :            : 
+     309                 :            : /* For internal use only.
+     310                 :            :  * These are used to more compactly represent the fields above. */
+     311                 :            : #define MBEDTLS_KEY_BITLEN_SHIFT  6
+     312                 :            : #define MBEDTLS_IV_SIZE_SHIFT     2
+     313                 :            : /**
+     314                 :            :  * Generic cipher context.
+     315                 :            :  */
+     316                 :            : typedef struct mbedtls_cipher_context_t {
+     317                 :            :     /** Information about the associated cipher. */
+     318                 :            :     const mbedtls_cipher_info_t *MBEDTLS_PRIVATE(cipher_info);
+     319                 :            : 
+     320                 :            :     /** Key length to use. */
+     321                 :            :     int MBEDTLS_PRIVATE(key_bitlen);
+     322                 :            : 
+     323                 :            :     /** Operation that the key of the context has been
+     324                 :            :      * initialized for.
+     325                 :            :      */
+     326                 :            :     mbedtls_operation_t MBEDTLS_PRIVATE(operation);
+     327                 :            : 
+     328                 :            : #if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING)
+     329                 :            :     /** Padding functions to use, if relevant for
+     330                 :            :      * the specific cipher mode.
+     331                 :            :      */
+     332                 :            :     void(*MBEDTLS_PRIVATE(add_padding))(unsigned char *output, size_t olen, size_t data_len);
+     333                 :            :     int(*MBEDTLS_PRIVATE(get_padding))(unsigned char *input, size_t ilen, size_t *data_len);
+     334                 :            : #endif
+     335                 :            : 
+     336                 :            :     /** Buffer for input that has not been processed yet. */
+     337                 :            :     unsigned char MBEDTLS_PRIVATE(unprocessed_data)[MBEDTLS_MAX_BLOCK_LENGTH];
+     338                 :            : 
+     339                 :            :     /** Number of Bytes that have not been processed yet. */
+     340                 :            :     size_t MBEDTLS_PRIVATE(unprocessed_len);
+     341                 :            : 
+     342                 :            :     /** Current IV or NONCE_COUNTER for CTR-mode, data unit (or sector) number
+     343                 :            :      * for XTS-mode. */
+     344                 :            :     unsigned char MBEDTLS_PRIVATE(iv)[MBEDTLS_MAX_IV_LENGTH];
+     345                 :            : 
+     346                 :            :     /** IV size in Bytes, for ciphers with variable-length IVs. */
+     347                 :            :     size_t MBEDTLS_PRIVATE(iv_size);
+     348                 :            : 
+     349                 :            :     /** The cipher-specific context. */
+     350                 :            :     void *MBEDTLS_PRIVATE(cipher_ctx);
+     351                 :            : 
+     352                 :            : #if defined(MBEDTLS_CMAC_C)
+     353                 :            :     /** CMAC-specific context. */
+     354                 :            :     mbedtls_cmac_context_t *MBEDTLS_PRIVATE(cmac_ctx);
+     355                 :            : #endif
+     356                 :            : 
+     357                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_DEPRECATED_REMOVED)
+     358                 :            :     /** Indicates whether the cipher operations should be performed
+     359                 :            :      *  by Mbed TLS' own crypto library or an external implementation
+     360                 :            :      *  of the PSA Crypto API.
+     361                 :            :      *  This is unset if the cipher context was established through
+     362                 :            :      *  mbedtls_cipher_setup(), and set if it was established through
+     363                 :            :      *  mbedtls_cipher_setup_psa().
+     364                 :            :      */
+     365                 :            :     unsigned char MBEDTLS_PRIVATE(psa_enabled);
+     366                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO && !MBEDTLS_DEPRECATED_REMOVED */
+     367                 :            : 
+     368                 :            : } mbedtls_cipher_context_t;
+     369                 :            : 
+     370                 :            : /**
+     371                 :            :  * \brief This function retrieves the list of ciphers supported
+     372                 :            :  *        by the generic cipher module.
+     373                 :            :  *
+     374                 :            :  *        For any cipher identifier in the returned list, you can
+     375                 :            :  *        obtain the corresponding generic cipher information structure
+     376                 :            :  *        via mbedtls_cipher_info_from_type(), which can then be used
+     377                 :            :  *        to prepare a cipher context via mbedtls_cipher_setup().
+     378                 :            :  *
+     379                 :            :  *
+     380                 :            :  * \return      A statically-allocated array of cipher identifiers
+     381                 :            :  *              of type cipher_type_t. The last entry is zero.
+     382                 :            :  */
+     383                 :            : const int *mbedtls_cipher_list(void);
+     384                 :            : 
+     385                 :            : /**
+     386                 :            :  * \brief               This function retrieves the cipher-information
+     387                 :            :  *                      structure associated with the given cipher name.
+     388                 :            :  *
+     389                 :            :  * \param cipher_name   Name of the cipher to search for. This must not be
+     390                 :            :  *                      \c NULL.
+     391                 :            :  *
+     392                 :            :  * \return              The cipher information structure associated with the
+     393                 :            :  *                      given \p cipher_name.
+     394                 :            :  * \return              \c NULL if the associated cipher information is not found.
+     395                 :            :  */
+     396                 :            : const mbedtls_cipher_info_t *mbedtls_cipher_info_from_string(const char *cipher_name);
+     397                 :            : 
+     398                 :            : /**
+     399                 :            :  * \brief               This function retrieves the cipher-information
+     400                 :            :  *                      structure associated with the given cipher type.
+     401                 :            :  *
+     402                 :            :  * \param cipher_type   Type of the cipher to search for.
+     403                 :            :  *
+     404                 :            :  * \return              The cipher information structure associated with the
+     405                 :            :  *                      given \p cipher_type.
+     406                 :            :  * \return              \c NULL if the associated cipher information is not found.
+     407                 :            :  */
+     408                 :            : const mbedtls_cipher_info_t *mbedtls_cipher_info_from_type(const mbedtls_cipher_type_t cipher_type);
+     409                 :            : 
+     410                 :            : /**
+     411                 :            :  * \brief               This function retrieves the cipher-information
+     412                 :            :  *                      structure associated with the given cipher ID,
+     413                 :            :  *                      key size and mode.
+     414                 :            :  *
+     415                 :            :  * \param cipher_id     The ID of the cipher to search for. For example,
+     416                 :            :  *                      #MBEDTLS_CIPHER_ID_AES.
+     417                 :            :  * \param key_bitlen    The length of the key in bits.
+     418                 :            :  * \param mode          The cipher mode. For example, #MBEDTLS_MODE_CBC.
+     419                 :            :  *
+     420                 :            :  * \return              The cipher information structure associated with the
+     421                 :            :  *                      given \p cipher_id.
+     422                 :            :  * \return              \c NULL if the associated cipher information is not found.
+     423                 :            :  */
+     424                 :            : const mbedtls_cipher_info_t *mbedtls_cipher_info_from_values(const mbedtls_cipher_id_t cipher_id,
+     425                 :            :                                                              int key_bitlen,
+     426                 :            :                                                              const mbedtls_cipher_mode_t mode);
+     427                 :            : 
+     428                 :            : /**
+     429                 :            :  * \brief               Retrieve the identifier for a cipher info structure.
+     430                 :            :  *
+     431                 :            :  * \param[in] info      The cipher info structure to query.
+     432                 :            :  *                      This may be \c NULL.
+     433                 :            :  *
+     434                 :            :  * \return              The full cipher identifier (\c MBEDTLS_CIPHER_xxx).
+     435                 :            :  * \return              #MBEDTLS_CIPHER_NONE if \p info is \c NULL.
+     436                 :            :  */
+     437                 :            : static inline mbedtls_cipher_type_t mbedtls_cipher_info_get_type(
+     438                 :            :     const mbedtls_cipher_info_t *info)
+     439                 :            : {
+     440                 :            :     if (info == NULL) {
+     441                 :            :         return MBEDTLS_CIPHER_NONE;
+     442                 :            :     } else {
+     443                 :            :         return (mbedtls_cipher_type_t) info->MBEDTLS_PRIVATE(type);
+     444                 :            :     }
+     445                 :            : }
+     446                 :            : 
+     447                 :            : /**
+     448                 :            :  * \brief               Retrieve the operation mode for a cipher info structure.
+     449                 :            :  *
+     450                 :            :  * \param[in] info      The cipher info structure to query.
+     451                 :            :  *                      This may be \c NULL.
+     452                 :            :  *
+     453                 :            :  * \return              The cipher mode (\c MBEDTLS_MODE_xxx).
+     454                 :            :  * \return              #MBEDTLS_MODE_NONE if \p info is \c NULL.
+     455                 :            :  */
+     456                 :            : static inline mbedtls_cipher_mode_t mbedtls_cipher_info_get_mode(
+     457                 :            :     const mbedtls_cipher_info_t *info)
+     458                 :            : {
+     459                 :            :     if (info == NULL) {
+     460                 :            :         return MBEDTLS_MODE_NONE;
+     461                 :            :     } else {
+     462                 :            :         return (mbedtls_cipher_mode_t) info->MBEDTLS_PRIVATE(mode);
+     463                 :            :     }
+     464                 :            : }
+     465                 :            : 
+     466                 :            : /**
+     467                 :            :  * \brief               Retrieve the key size for a cipher info structure.
+     468                 :            :  *
+     469                 :            :  * \param[in] info      The cipher info structure to query.
+     470                 :            :  *                      This may be \c NULL.
+     471                 :            :  *
+     472                 :            :  * \return              The key length in bits.
+     473                 :            :  *                      For variable-sized ciphers, this is the default length.
+     474                 :            :  *                      For DES, this includes the parity bits.
+     475                 :            :  * \return              \c 0 if \p info is \c NULL.
+     476                 :            :  */
+     477                 :       3160 : static inline size_t mbedtls_cipher_info_get_key_bitlen(
+     478                 :            :     const mbedtls_cipher_info_t *info)
+     479                 :            : {
+     480         [ -  + ]:       3160 :     if (info == NULL) {
+     481                 :          0 :         return 0;
+     482                 :            :     } else {
+     483                 :       3160 :         return ((size_t) info->MBEDTLS_PRIVATE(key_bitlen)) << MBEDTLS_KEY_BITLEN_SHIFT;
+     484                 :            :     }
+     485                 :            : }
+     486                 :            : 
+     487                 :            : /**
+     488                 :            :  * \brief               Retrieve the human-readable name for a
+     489                 :            :  *                      cipher info structure.
+     490                 :            :  *
+     491                 :            :  * \param[in] info      The cipher info structure to query.
+     492                 :            :  *                      This may be \c NULL.
+     493                 :            :  *
+     494                 :            :  * \return              The cipher name, which is a human readable string,
+     495                 :            :  *                      with static storage duration.
+     496                 :            :  * \return              \c NULL if \p info is \c NULL.
+     497                 :            :  */
+     498                 :            : static inline const char *mbedtls_cipher_info_get_name(
+     499                 :            :     const mbedtls_cipher_info_t *info)
+     500                 :            : {
+     501                 :            :     if (info == NULL) {
+     502                 :            :         return NULL;
+     503                 :            :     } else {
+     504                 :            :         return info->MBEDTLS_PRIVATE(name);
+     505                 :            :     }
+     506                 :            : }
+     507                 :            : 
+     508                 :            : /**
+     509                 :            :  * \brief       This function returns the size of the IV or nonce
+     510                 :            :  *              for the cipher info structure, in bytes.
+     511                 :            :  *
+     512                 :            :  * \param info  The cipher info structure. This may be \c NULL.
+     513                 :            :  *
+     514                 :            :  * \return      The recommended IV size.
+     515                 :            :  * \return      \c 0 for ciphers not using an IV or a nonce.
+     516                 :            :  * \return      \c 0 if \p info is \c NULL.
+     517                 :            :  */
+     518                 :          0 : static inline size_t mbedtls_cipher_info_get_iv_size(
+     519                 :            :     const mbedtls_cipher_info_t *info)
+     520                 :            : {
+     521         [ #  # ]:          0 :     if (info == NULL) {
+     522                 :          0 :         return 0;
+     523                 :            :     }
+     524                 :            : 
+     525                 :          0 :     return ((size_t) info->MBEDTLS_PRIVATE(iv_size)) << MBEDTLS_IV_SIZE_SHIFT;
+     526                 :            : }
+     527                 :            : 
+     528                 :            : /**
+     529                 :            :  * \brief        This function returns the block size of the given
+     530                 :            :  *               cipher info structure in bytes.
+     531                 :            :  *
+     532                 :            :  * \param info   The cipher info structure. This may be \c NULL.
+     533                 :            :  *
+     534                 :            :  * \return       The block size of the cipher.
+     535                 :            :  * \return       \c 1 if the cipher is a stream cipher.
+     536                 :            :  * \return       \c 0 if \p info is \c NULL.
+     537                 :            :  */
+     538                 :        791 : static inline size_t mbedtls_cipher_info_get_block_size(
+     539                 :            :     const mbedtls_cipher_info_t *info)
+     540                 :            : {
+     541         [ -  + ]:        791 :     if (info == NULL) {
+     542                 :          0 :         return 0;
+     543                 :            :     }
+     544                 :            : 
+     545                 :        791 :     return (size_t) (info->MBEDTLS_PRIVATE(block_size));
+     546                 :            : }
+     547                 :            : 
+     548                 :            : /**
+     549                 :            :  * \brief        This function returns a non-zero value if the key length for
+     550                 :            :  *               the given cipher is variable.
+     551                 :            :  *
+     552                 :            :  * \param info   The cipher info structure. This may be \c NULL.
+     553                 :            :  *
+     554                 :            :  * \return       Non-zero if the key length is variable, \c 0 otherwise.
+     555                 :            :  * \return       \c 0 if the given pointer is \c NULL.
+     556                 :            :  */
+     557                 :            : static inline int mbedtls_cipher_info_has_variable_key_bitlen(
+     558                 :            :     const mbedtls_cipher_info_t *info)
+     559                 :            : {
+     560                 :            :     if (info == NULL) {
+     561                 :            :         return 0;
+     562                 :            :     }
+     563                 :            : 
+     564                 :            :     return info->MBEDTLS_PRIVATE(flags) & MBEDTLS_CIPHER_VARIABLE_KEY_LEN;
+     565                 :            : }
+     566                 :            : 
+     567                 :            : /**
+     568                 :            :  * \brief        This function returns a non-zero value if the IV size for
+     569                 :            :  *               the given cipher is variable.
+     570                 :            :  *
+     571                 :            :  * \param info   The cipher info structure. This may be \c NULL.
+     572                 :            :  *
+     573                 :            :  * \return       Non-zero if the IV size is variable, \c 0 otherwise.
+     574                 :            :  * \return       \c 0 if the given pointer is \c NULL.
+     575                 :            :  */
+     576                 :            : static inline int mbedtls_cipher_info_has_variable_iv_size(
+     577                 :            :     const mbedtls_cipher_info_t *info)
+     578                 :            : {
+     579                 :            :     if (info == NULL) {
+     580                 :            :         return 0;
+     581                 :            :     }
+     582                 :            : 
+     583                 :            :     return info->MBEDTLS_PRIVATE(flags) & MBEDTLS_CIPHER_VARIABLE_IV_LEN;
+     584                 :            : }
+     585                 :            : 
+     586                 :            : /**
+     587                 :            :  * \brief               This function initializes a \p ctx as NONE.
+     588                 :            :  *
+     589                 :            :  * \param ctx           The context to be initialized. This must not be \c NULL.
+     590                 :            :  */
+     591                 :            : void mbedtls_cipher_init(mbedtls_cipher_context_t *ctx);
+     592                 :            : 
+     593                 :            : /**
+     594                 :            :  * \brief               This function frees and clears the cipher-specific
+     595                 :            :  *                      context of \p ctx. Freeing \p ctx itself remains the
+     596                 :            :  *                      responsibility of the caller.
+     597                 :            :  *
+     598                 :            :  * \param ctx           The context to be freed. If this is \c NULL, the
+     599                 :            :  *                      function has no effect, otherwise this must point to an
+     600                 :            :  *                      initialized context.
+     601                 :            :  */
+     602                 :            : void mbedtls_cipher_free(mbedtls_cipher_context_t *ctx);
+     603                 :            : 
+     604                 :            : 
+     605                 :            : /**
+     606                 :            :  * \brief               This function prepares a cipher context for
+     607                 :            :  *                      use with the given cipher primitive.
+     608                 :            :  *
+     609                 :            :  * \note                After calling this function, you should call
+     610                 :            :  *                      mbedtls_cipher_setkey() and, if the mode uses padding,
+     611                 :            :  *                      mbedtls_cipher_set_padding_mode(), then for each
+     612                 :            :  *                      message to encrypt or decrypt with this key, either:
+     613                 :            :  *                      - mbedtls_cipher_crypt() for one-shot processing with
+     614                 :            :  *                      non-AEAD modes;
+     615                 :            :  *                      - mbedtls_cipher_auth_encrypt_ext() or
+     616                 :            :  *                      mbedtls_cipher_auth_decrypt_ext() for one-shot
+     617                 :            :  *                      processing with AEAD modes or NIST_KW;
+     618                 :            :  *                      - for multi-part processing, see the documentation of
+     619                 :            :  *                      mbedtls_cipher_reset().
+     620                 :            :  *
+     621                 :            :  * \param ctx           The context to prepare. This must be initialized by
+     622                 :            :  *                      a call to mbedtls_cipher_init() first.
+     623                 :            :  * \param cipher_info   The cipher to use.
+     624                 :            :  *
+     625                 :            :  * \return              \c 0 on success.
+     626                 :            :  * \return              #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on
+     627                 :            :  *                      parameter-verification failure.
+     628                 :            :  * \return              #MBEDTLS_ERR_CIPHER_ALLOC_FAILED if allocation of the
+     629                 :            :  *                      cipher-specific context fails.
+     630                 :            :  */
+     631                 :            : int mbedtls_cipher_setup(mbedtls_cipher_context_t *ctx,
+     632                 :            :                          const mbedtls_cipher_info_t *cipher_info);
+     633                 :            : 
+     634                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+     635                 :            : #if !defined(MBEDTLS_DEPRECATED_REMOVED)
+     636                 :            : /**
+     637                 :            :  * \brief               This function initializes a cipher context for
+     638                 :            :  *                      PSA-based use with the given cipher primitive.
+     639                 :            :  *
+     640                 :            :  * \deprecated          This function is deprecated and will be removed in a
+     641                 :            :  *                      future version of the library.
+     642                 :            :  *                      Please use psa_aead_xxx() / psa_cipher_xxx() directly
+     643                 :            :  *                      instead.
+     644                 :            :  *
+     645                 :            :  * \note                See #MBEDTLS_USE_PSA_CRYPTO for information on PSA.
+     646                 :            :  *
+     647                 :            :  * \param ctx           The context to initialize. May not be \c NULL.
+     648                 :            :  * \param cipher_info   The cipher to use.
+     649                 :            :  * \param taglen        For AEAD ciphers, the length in bytes of the
+     650                 :            :  *                      authentication tag to use. Subsequent uses of
+     651                 :            :  *                      mbedtls_cipher_auth_encrypt_ext() or
+     652                 :            :  *                      mbedtls_cipher_auth_decrypt_ext() must provide
+     653                 :            :  *                      the same tag length.
+     654                 :            :  *                      For non-AEAD ciphers, the value must be \c 0.
+     655                 :            :  *
+     656                 :            :  * \return              \c 0 on success.
+     657                 :            :  * \return              #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on
+     658                 :            :  *                      parameter-verification failure.
+     659                 :            :  * \return              #MBEDTLS_ERR_CIPHER_ALLOC_FAILED if allocation of the
+     660                 :            :  *                      cipher-specific context fails.
+     661                 :            :  */
+     662                 :            : int MBEDTLS_DEPRECATED mbedtls_cipher_setup_psa(mbedtls_cipher_context_t *ctx,
+     663                 :            :                                                 const mbedtls_cipher_info_t *cipher_info,
+     664                 :            :                                                 size_t taglen);
+     665                 :            : #endif /* MBEDTLS_DEPRECATED_REMOVED */
+     666                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO */
+     667                 :            : 
+     668                 :            : /**
+     669                 :            :  * \brief        This function returns the block size of the given cipher
+     670                 :            :  *               in bytes.
+     671                 :            :  *
+     672                 :            :  * \param ctx    The context of the cipher.
+     673                 :            :  *
+     674                 :            :  * \return       The block size of the underlying cipher.
+     675                 :            :  * \return       \c 1 if the cipher is a stream cipher.
+     676                 :            :  * \return       \c 0 if \p ctx has not been initialized.
+     677                 :            :  */
+     678                 :       3654 : static inline unsigned int mbedtls_cipher_get_block_size(
+     679                 :            :     const mbedtls_cipher_context_t *ctx)
+     680                 :            : {
+     681         [ -  + ]:       3654 :     if (ctx->MBEDTLS_PRIVATE(cipher_info) == NULL) {
+     682                 :          0 :         return 0;
+     683                 :            :     }
+     684                 :            : 
+     685                 :       3654 :     return (unsigned int) ctx->MBEDTLS_PRIVATE(cipher_info)->MBEDTLS_PRIVATE(block_size);
+     686                 :            : }
+     687                 :            : 
+     688                 :            : /**
+     689                 :            :  * \brief        This function returns the mode of operation for
+     690                 :            :  *               the cipher. For example, MBEDTLS_MODE_CBC.
+     691                 :            :  *
+     692                 :            :  * \param ctx    The context of the cipher. This must be initialized.
+     693                 :            :  *
+     694                 :            :  * \return       The mode of operation.
+     695                 :            :  * \return       #MBEDTLS_MODE_NONE if \p ctx has not been initialized.
+     696                 :            :  */
+     697                 :            : static inline mbedtls_cipher_mode_t mbedtls_cipher_get_cipher_mode(
+     698                 :            :     const mbedtls_cipher_context_t *ctx)
+     699                 :            : {
+     700                 :            :     if (ctx->MBEDTLS_PRIVATE(cipher_info) == NULL) {
+     701                 :            :         return MBEDTLS_MODE_NONE;
+     702                 :            :     }
+     703                 :            : 
+     704                 :            :     return (mbedtls_cipher_mode_t) ctx->MBEDTLS_PRIVATE(cipher_info)->MBEDTLS_PRIVATE(mode);
+     705                 :            : }
+     706                 :            : 
+     707                 :            : /**
+     708                 :            :  * \brief       This function returns the size of the IV or nonce
+     709                 :            :  *              of the cipher, in Bytes.
+     710                 :            :  *
+     711                 :            :  * \param ctx   The context of the cipher. This must be initialized.
+     712                 :            :  *
+     713                 :            :  * \return      The recommended IV size if no IV has been set.
+     714                 :            :  * \return      \c 0 for ciphers not using an IV or a nonce.
+     715                 :            :  * \return      The actual size if an IV has been set.
+     716                 :            :  */
+     717                 :          0 : static inline int mbedtls_cipher_get_iv_size(
+     718                 :            :     const mbedtls_cipher_context_t *ctx)
+     719                 :            : {
+     720         [ #  # ]:          0 :     if (ctx->MBEDTLS_PRIVATE(cipher_info) == NULL) {
+     721                 :          0 :         return 0;
+     722                 :            :     }
+     723                 :            : 
+     724         [ #  # ]:          0 :     if (ctx->MBEDTLS_PRIVATE(iv_size) != 0) {
+     725                 :          0 :         return (int) ctx->MBEDTLS_PRIVATE(iv_size);
+     726                 :            :     }
+     727                 :            : 
+     728                 :          0 :     return (int) (((int) ctx->MBEDTLS_PRIVATE(cipher_info)->MBEDTLS_PRIVATE(iv_size)) <<
+     729                 :            :                   MBEDTLS_IV_SIZE_SHIFT);
+     730                 :            : }
+     731                 :            : 
+     732                 :            : /**
+     733                 :            :  * \brief               This function returns the type of the given cipher.
+     734                 :            :  *
+     735                 :            :  * \param ctx           The context of the cipher. This must be initialized.
+     736                 :            :  *
+     737                 :            :  * \return              The type of the cipher.
+     738                 :            :  * \return              #MBEDTLS_CIPHER_NONE if \p ctx has not been initialized.
+     739                 :            :  */
+     740                 :            : static inline mbedtls_cipher_type_t mbedtls_cipher_get_type(
+     741                 :            :     const mbedtls_cipher_context_t *ctx)
+     742                 :            : {
+     743                 :            :     if (ctx->MBEDTLS_PRIVATE(cipher_info) == NULL) {
+     744                 :            :         return MBEDTLS_CIPHER_NONE;
+     745                 :            :     }
+     746                 :            : 
+     747                 :            :     return (mbedtls_cipher_type_t) ctx->MBEDTLS_PRIVATE(cipher_info)->MBEDTLS_PRIVATE(type);
+     748                 :            : }
+     749                 :            : 
+     750                 :            : /**
+     751                 :            :  * \brief               This function returns the name of the given cipher
+     752                 :            :  *                      as a string.
+     753                 :            :  *
+     754                 :            :  * \param ctx           The context of the cipher. This must be initialized.
+     755                 :            :  *
+     756                 :            :  * \return              The name of the cipher.
+     757                 :            :  * \return              NULL if \p ctx has not been not initialized.
+     758                 :            :  */
+     759                 :            : static inline const char *mbedtls_cipher_get_name(
+     760                 :            :     const mbedtls_cipher_context_t *ctx)
+     761                 :            : {
+     762                 :            :     if (ctx->MBEDTLS_PRIVATE(cipher_info) == NULL) {
+     763                 :            :         return 0;
+     764                 :            :     }
+     765                 :            : 
+     766                 :            :     return ctx->MBEDTLS_PRIVATE(cipher_info)->MBEDTLS_PRIVATE(name);
+     767                 :            : }
+     768                 :            : 
+     769                 :            : /**
+     770                 :            :  * \brief               This function returns the key length of the cipher.
+     771                 :            :  *
+     772                 :            :  * \param ctx           The context of the cipher. This must be initialized.
+     773                 :            :  *
+     774                 :            :  * \return              The key length of the cipher in bits.
+     775                 :            :  * \return              #MBEDTLS_KEY_LENGTH_NONE if \p ctx has not been
+     776                 :            :  *                      initialized.
+     777                 :            :  */
+     778                 :            : static inline int mbedtls_cipher_get_key_bitlen(
+     779                 :            :     const mbedtls_cipher_context_t *ctx)
+     780                 :            : {
+     781                 :            :     if (ctx->MBEDTLS_PRIVATE(cipher_info) == NULL) {
+     782                 :            :         return MBEDTLS_KEY_LENGTH_NONE;
+     783                 :            :     }
+     784                 :            : 
+     785                 :            :     return (int) ctx->MBEDTLS_PRIVATE(cipher_info)->MBEDTLS_PRIVATE(key_bitlen) <<
+     786                 :            :            MBEDTLS_KEY_BITLEN_SHIFT;
+     787                 :            : }
+     788                 :            : 
+     789                 :            : /**
+     790                 :            :  * \brief          This function returns the operation of the given cipher.
+     791                 :            :  *
+     792                 :            :  * \param ctx      The context of the cipher. This must be initialized.
+     793                 :            :  *
+     794                 :            :  * \return         The type of operation: #MBEDTLS_ENCRYPT or #MBEDTLS_DECRYPT.
+     795                 :            :  * \return         #MBEDTLS_OPERATION_NONE if \p ctx has not been initialized.
+     796                 :            :  */
+     797                 :            : static inline mbedtls_operation_t mbedtls_cipher_get_operation(
+     798                 :            :     const mbedtls_cipher_context_t *ctx)
+     799                 :            : {
+     800                 :            :     if (ctx->MBEDTLS_PRIVATE(cipher_info) == NULL) {
+     801                 :            :         return MBEDTLS_OPERATION_NONE;
+     802                 :            :     }
+     803                 :            : 
+     804                 :            :     return ctx->MBEDTLS_PRIVATE(operation);
+     805                 :            : }
+     806                 :            : 
+     807                 :            : /**
+     808                 :            :  * \brief               This function sets the key to use with the given context.
+     809                 :            :  *
+     810                 :            :  * \param ctx           The generic cipher context. This must be initialized and
+     811                 :            :  *                      bound to a cipher information structure.
+     812                 :            :  * \param key           The key to use. This must be a readable buffer of at
+     813                 :            :  *                      least \p key_bitlen Bits.
+     814                 :            :  * \param key_bitlen    The key length to use, in Bits.
+     815                 :            :  * \param operation     The operation that the key will be used for:
+     816                 :            :  *                      #MBEDTLS_ENCRYPT or #MBEDTLS_DECRYPT.
+     817                 :            :  *
+     818                 :            :  * \return              \c 0 on success.
+     819                 :            :  * \return              #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on
+     820                 :            :  *                      parameter-verification failure.
+     821                 :            :  * \return              A cipher-specific error code on failure.
+     822                 :            :  */
+     823                 :            : int mbedtls_cipher_setkey(mbedtls_cipher_context_t *ctx,
+     824                 :            :                           const unsigned char *key,
+     825                 :            :                           int key_bitlen,
+     826                 :            :                           const mbedtls_operation_t operation);
+     827                 :            : 
+     828                 :            : #if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING)
+     829                 :            : /**
+     830                 :            :  * \brief               This function sets the padding mode, for cipher modes
+     831                 :            :  *                      that use padding.
+     832                 :            :  *
+     833                 :            :  *
+     834                 :            :  * \param ctx           The generic cipher context. This must be initialized and
+     835                 :            :  *                      bound to a cipher information structure.
+     836                 :            :  * \param mode          The padding mode.
+     837                 :            :  *
+     838                 :            :  * \return              \c 0 on success.
+     839                 :            :  * \return              #MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE
+     840                 :            :  *                      if the selected padding mode is not supported.
+     841                 :            :  * \return              #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA if the cipher mode
+     842                 :            :  *                      does not support padding.
+     843                 :            :  */
+     844                 :            : int mbedtls_cipher_set_padding_mode(mbedtls_cipher_context_t *ctx,
+     845                 :            :                                     mbedtls_cipher_padding_t mode);
+     846                 :            : #endif /* MBEDTLS_CIPHER_MODE_WITH_PADDING */
+     847                 :            : 
+     848                 :            : /**
+     849                 :            :  * \brief           This function sets the initialization vector (IV)
+     850                 :            :  *                  or nonce.
+     851                 :            :  *
+     852                 :            :  * \note            Some ciphers do not use IVs nor nonce. For these
+     853                 :            :  *                  ciphers, this function has no effect.
+     854                 :            :  *
+     855                 :            :  * \note            For #MBEDTLS_CIPHER_CHACHA20, the nonce length must
+     856                 :            :  *                  be 12, and the initial counter value is 0.
+     857                 :            :  *
+     858                 :            :  * \note            For #MBEDTLS_CIPHER_CHACHA20_POLY1305, the nonce length
+     859                 :            :  *                  must be 12.
+     860                 :            :  *
+     861                 :            :  * \param ctx       The generic cipher context. This must be initialized and
+     862                 :            :  *                  bound to a cipher information structure.
+     863                 :            :  * \param iv        The IV to use, or NONCE_COUNTER for CTR-mode ciphers. This
+     864                 :            :  *                  must be a readable buffer of at least \p iv_len Bytes.
+     865                 :            :  * \param iv_len    The IV length for ciphers with variable-size IV.
+     866                 :            :  *                  This parameter is discarded by ciphers with fixed-size IV.
+     867                 :            :  *
+     868                 :            :  * \return          \c 0 on success.
+     869                 :            :  * \return          #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on
+     870                 :            :  *                  parameter-verification failure.
+     871                 :            :  */
+     872                 :            : int mbedtls_cipher_set_iv(mbedtls_cipher_context_t *ctx,
+     873                 :            :                           const unsigned char *iv,
+     874                 :            :                           size_t iv_len);
+     875                 :            : 
+     876                 :            : /**
+     877                 :            :  * \brief         This function resets the cipher state.
+     878                 :            :  *
+     879                 :            :  * \note          With non-AEAD ciphers, the order of calls for each message
+     880                 :            :  *                is as follows:
+     881                 :            :  *                1. mbedtls_cipher_set_iv() if the mode uses an IV/nonce.
+     882                 :            :  *                2. mbedtls_cipher_reset()
+     883                 :            :  *                3. mbedtls_cipher_update() one or more times
+     884                 :            :  *                4. mbedtls_cipher_finish()
+     885                 :            :  *                .
+     886                 :            :  *                This sequence can be repeated to encrypt or decrypt multiple
+     887                 :            :  *                messages with the same key.
+     888                 :            :  *
+     889                 :            :  * \note          With AEAD ciphers, the order of calls for each message
+     890                 :            :  *                is as follows:
+     891                 :            :  *                1. mbedtls_cipher_set_iv() if the mode uses an IV/nonce.
+     892                 :            :  *                2. mbedtls_cipher_reset()
+     893                 :            :  *                3. mbedtls_cipher_update_ad()
+     894                 :            :  *                4. mbedtls_cipher_update() one or more times
+     895                 :            :  *                5. mbedtls_cipher_finish()
+     896                 :            :  *                6. mbedtls_cipher_check_tag() (for decryption) or
+     897                 :            :  *                mbedtls_cipher_write_tag() (for encryption).
+     898                 :            :  *                .
+     899                 :            :  *                This sequence can be repeated to encrypt or decrypt multiple
+     900                 :            :  *                messages with the same key.
+     901                 :            :  *
+     902                 :            :  * \param ctx     The generic cipher context. This must be bound to a key.
+     903                 :            :  *
+     904                 :            :  * \return        \c 0 on success.
+     905                 :            :  * \return        #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on
+     906                 :            :  *                parameter-verification failure.
+     907                 :            :  */
+     908                 :            : int mbedtls_cipher_reset(mbedtls_cipher_context_t *ctx);
+     909                 :            : 
+     910                 :            : #if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C)
+     911                 :            : /**
+     912                 :            :  * \brief               This function adds additional data for AEAD ciphers.
+     913                 :            :  *                      Currently supported with GCM and ChaCha20+Poly1305.
+     914                 :            :  *
+     915                 :            :  * \param ctx           The generic cipher context. This must be initialized.
+     916                 :            :  * \param ad            The additional data to use. This must be a readable
+     917                 :            :  *                      buffer of at least \p ad_len Bytes.
+     918                 :            :  * \param ad_len        The length of \p ad in Bytes.
+     919                 :            :  *
+     920                 :            :  * \return              \c 0 on success.
+     921                 :            :  * \return              A specific error code on failure.
+     922                 :            :  */
+     923                 :            : int mbedtls_cipher_update_ad(mbedtls_cipher_context_t *ctx,
+     924                 :            :                              const unsigned char *ad, size_t ad_len);
+     925                 :            : #endif /* MBEDTLS_GCM_C || MBEDTLS_CHACHAPOLY_C */
+     926                 :            : 
+     927                 :            : /**
+     928                 :            :  * \brief               The generic cipher update function. It encrypts or
+     929                 :            :  *                      decrypts using the given cipher context. Writes as
+     930                 :            :  *                      many block-sized blocks of data as possible to output.
+     931                 :            :  *                      Any data that cannot be written immediately is either
+     932                 :            :  *                      added to the next block, or flushed when
+     933                 :            :  *                      mbedtls_cipher_finish() is called.
+     934                 :            :  *                      Exception: For MBEDTLS_MODE_ECB, expects a single block
+     935                 :            :  *                      in size. For example, 16 Bytes for AES.
+     936                 :            :  *
+     937                 :            :  * \param ctx           The generic cipher context. This must be initialized and
+     938                 :            :  *                      bound to a key.
+     939                 :            :  * \param input         The buffer holding the input data. This must be a
+     940                 :            :  *                      readable buffer of at least \p ilen Bytes.
+     941                 :            :  * \param ilen          The length of the input data.
+     942                 :            :  * \param output        The buffer for the output data. This must be able to
+     943                 :            :  *                      hold at least `ilen + block_size`. This must not be the
+     944                 :            :  *                      same buffer as \p input.
+     945                 :            :  * \param olen          The length of the output data, to be updated with the
+     946                 :            :  *                      actual number of Bytes written. This must not be
+     947                 :            :  *                      \c NULL.
+     948                 :            :  *
+     949                 :            :  * \return              \c 0 on success.
+     950                 :            :  * \return              #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on
+     951                 :            :  *                      parameter-verification failure.
+     952                 :            :  * \return              #MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE on an
+     953                 :            :  *                      unsupported mode for a cipher.
+     954                 :            :  * \return              A cipher-specific error code on failure.
+     955                 :            :  */
+     956                 :            : int mbedtls_cipher_update(mbedtls_cipher_context_t *ctx,
+     957                 :            :                           const unsigned char *input,
+     958                 :            :                           size_t ilen, unsigned char *output,
+     959                 :            :                           size_t *olen);
+     960                 :            : 
+     961                 :            : /**
+     962                 :            :  * \brief               The generic cipher finalization function. If data still
+     963                 :            :  *                      needs to be flushed from an incomplete block, the data
+     964                 :            :  *                      contained in it is padded to the size of
+     965                 :            :  *                      the last block, and written to the \p output buffer.
+     966                 :            :  *
+     967                 :            :  * \param ctx           The generic cipher context. This must be initialized and
+     968                 :            :  *                      bound to a key.
+     969                 :            :  * \param output        The buffer to write data to. This needs to be a writable
+     970                 :            :  *                      buffer of at least block_size Bytes.
+     971                 :            :  * \param olen          The length of the data written to the \p output buffer.
+     972                 :            :  *                      This may not be \c NULL.
+     973                 :            :  *
+     974                 :            :  * \return              \c 0 on success.
+     975                 :            :  * \return              #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on
+     976                 :            :  *                      parameter-verification failure.
+     977                 :            :  * \return              #MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED on decryption
+     978                 :            :  *                      expecting a full block but not receiving one.
+     979                 :            :  * \return              #MBEDTLS_ERR_CIPHER_INVALID_PADDING on invalid padding
+     980                 :            :  *                      while decrypting.
+     981                 :            :  * \return              A cipher-specific error code on failure.
+     982                 :            :  */
+     983                 :            : int mbedtls_cipher_finish(mbedtls_cipher_context_t *ctx,
+     984                 :            :                           unsigned char *output, size_t *olen);
+     985                 :            : 
+     986                 :            : #if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C)
+     987                 :            : /**
+     988                 :            :  * \brief               This function writes a tag for AEAD ciphers.
+     989                 :            :  *                      Currently supported with GCM and ChaCha20+Poly1305.
+     990                 :            :  *                      This must be called after mbedtls_cipher_finish().
+     991                 :            :  *
+     992                 :            :  * \param ctx           The generic cipher context. This must be initialized,
+     993                 :            :  *                      bound to a key, and have just completed a cipher
+     994                 :            :  *                      operation through mbedtls_cipher_finish() the tag for
+     995                 :            :  *                      which should be written.
+     996                 :            :  * \param tag           The buffer to write the tag to. This must be a writable
+     997                 :            :  *                      buffer of at least \p tag_len Bytes.
+     998                 :            :  * \param tag_len       The length of the tag to write.
+     999                 :            :  *
+    1000                 :            :  * \return              \c 0 on success.
+    1001                 :            :  * \return              A specific error code on failure.
+    1002                 :            :  */
+    1003                 :            : int mbedtls_cipher_write_tag(mbedtls_cipher_context_t *ctx,
+    1004                 :            :                              unsigned char *tag, size_t tag_len);
+    1005                 :            : 
+    1006                 :            : /**
+    1007                 :            :  * \brief               This function checks the tag for AEAD ciphers.
+    1008                 :            :  *                      Currently supported with GCM and ChaCha20+Poly1305.
+    1009                 :            :  *                      This must be called after mbedtls_cipher_finish().
+    1010                 :            :  *
+    1011                 :            :  * \param ctx           The generic cipher context. This must be initialized.
+    1012                 :            :  * \param tag           The buffer holding the tag. This must be a readable
+    1013                 :            :  *                      buffer of at least \p tag_len Bytes.
+    1014                 :            :  * \param tag_len       The length of the tag to check.
+    1015                 :            :  *
+    1016                 :            :  * \return              \c 0 on success.
+    1017                 :            :  * \return              A specific error code on failure.
+    1018                 :            :  */
+    1019                 :            : int mbedtls_cipher_check_tag(mbedtls_cipher_context_t *ctx,
+    1020                 :            :                              const unsigned char *tag, size_t tag_len);
+    1021                 :            : #endif /* MBEDTLS_GCM_C || MBEDTLS_CHACHAPOLY_C */
+    1022                 :            : 
+    1023                 :            : /**
+    1024                 :            :  * \brief               The generic all-in-one encryption/decryption function,
+    1025                 :            :  *                      for all ciphers except AEAD constructs.
+    1026                 :            :  *
+    1027                 :            :  * \param ctx           The generic cipher context. This must be initialized.
+    1028                 :            :  * \param iv            The IV to use, or NONCE_COUNTER for CTR-mode ciphers.
+    1029                 :            :  *                      This must be a readable buffer of at least \p iv_len
+    1030                 :            :  *                      Bytes.
+    1031                 :            :  * \param iv_len        The IV length for ciphers with variable-size IV.
+    1032                 :            :  *                      This parameter is discarded by ciphers with fixed-size
+    1033                 :            :  *                      IV.
+    1034                 :            :  * \param input         The buffer holding the input data. This must be a
+    1035                 :            :  *                      readable buffer of at least \p ilen Bytes.
+    1036                 :            :  * \param ilen          The length of the input data in Bytes.
+    1037                 :            :  * \param output        The buffer for the output data. This must be able to
+    1038                 :            :  *                      hold at least `ilen + block_size`. This must not be the
+    1039                 :            :  *                      same buffer as \p input.
+    1040                 :            :  * \param olen          The length of the output data, to be updated with the
+    1041                 :            :  *                      actual number of Bytes written. This must not be
+    1042                 :            :  *                      \c NULL.
+    1043                 :            :  *
+    1044                 :            :  * \note                Some ciphers do not use IVs nor nonce. For these
+    1045                 :            :  *                      ciphers, use \p iv = NULL and \p iv_len = 0.
+    1046                 :            :  *
+    1047                 :            :  * \return              \c 0 on success.
+    1048                 :            :  * \return              #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on
+    1049                 :            :  *                      parameter-verification failure.
+    1050                 :            :  * \return              #MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED on decryption
+    1051                 :            :  *                      expecting a full block but not receiving one.
+    1052                 :            :  * \return              #MBEDTLS_ERR_CIPHER_INVALID_PADDING on invalid padding
+    1053                 :            :  *                      while decrypting.
+    1054                 :            :  * \return              A cipher-specific error code on failure.
+    1055                 :            :  */
+    1056                 :            : int mbedtls_cipher_crypt(mbedtls_cipher_context_t *ctx,
+    1057                 :            :                          const unsigned char *iv, size_t iv_len,
+    1058                 :            :                          const unsigned char *input, size_t ilen,
+    1059                 :            :                          unsigned char *output, size_t *olen);
+    1060                 :            : 
+    1061                 :            : #if defined(MBEDTLS_CIPHER_MODE_AEAD) || defined(MBEDTLS_NIST_KW_C)
+    1062                 :            : /**
+    1063                 :            :  * \brief               The authenticated encryption (AEAD/NIST_KW) function.
+    1064                 :            :  *
+    1065                 :            :  * \note                For AEAD modes, the tag will be appended to the
+    1066                 :            :  *                      ciphertext, as recommended by RFC 5116.
+    1067                 :            :  *                      (NIST_KW doesn't have a separate tag.)
+    1068                 :            :  *
+    1069                 :            :  * \param ctx           The generic cipher context. This must be initialized and
+    1070                 :            :  *                      bound to a key, with an AEAD algorithm or NIST_KW.
+    1071                 :            :  * \param iv            The nonce to use. This must be a readable buffer of
+    1072                 :            :  *                      at least \p iv_len Bytes and may be \c NULL if \p
+    1073                 :            :  *                      iv_len is \c 0.
+    1074                 :            :  * \param iv_len        The length of the nonce. For AEAD ciphers, this must
+    1075                 :            :  *                      satisfy the constraints imposed by the cipher used.
+    1076                 :            :  *                      For NIST_KW, this must be \c 0.
+    1077                 :            :  * \param ad            The additional data to authenticate. This must be a
+    1078                 :            :  *                      readable buffer of at least \p ad_len Bytes, and may
+    1079                 :            :  *                      be \c NULL is \p ad_len is \c 0.
+    1080                 :            :  * \param ad_len        The length of \p ad. For NIST_KW, this must be \c 0.
+    1081                 :            :  * \param input         The buffer holding the input data. This must be a
+    1082                 :            :  *                      readable buffer of at least \p ilen Bytes, and may be
+    1083                 :            :  *                      \c NULL if \p ilen is \c 0.
+    1084                 :            :  * \param ilen          The length of the input data.
+    1085                 :            :  * \param output        The buffer for the output data. This must be a
+    1086                 :            :  *                      writable buffer of at least \p output_len Bytes, and
+    1087                 :            :  *                      must not be \c NULL.
+    1088                 :            :  * \param output_len    The length of the \p output buffer in Bytes. For AEAD
+    1089                 :            :  *                      ciphers, this must be at least \p ilen + \p tag_len.
+    1090                 :            :  *                      For NIST_KW, this must be at least \p ilen + 8
+    1091                 :            :  *                      (rounded up to a multiple of 8 if KWP is used);
+    1092                 :            :  *                      \p ilen + 15 is always a safe value.
+    1093                 :            :  * \param olen          This will be filled with the actual number of Bytes
+    1094                 :            :  *                      written to the \p output buffer. This must point to a
+    1095                 :            :  *                      writable object of type \c size_t.
+    1096                 :            :  * \param tag_len       The desired length of the authentication tag. For AEAD
+    1097                 :            :  *                      ciphers, this must match the constraints imposed by
+    1098                 :            :  *                      the cipher used, and in particular must not be \c 0.
+    1099                 :            :  *                      For NIST_KW, this must be \c 0.
+    1100                 :            :  *
+    1101                 :            :  * \return              \c 0 on success.
+    1102                 :            :  * \return              #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on
+    1103                 :            :  *                      parameter-verification failure.
+    1104                 :            :  * \return              A cipher-specific error code on failure.
+    1105                 :            :  */
+    1106                 :            : int mbedtls_cipher_auth_encrypt_ext(mbedtls_cipher_context_t *ctx,
+    1107                 :            :                                     const unsigned char *iv, size_t iv_len,
+    1108                 :            :                                     const unsigned char *ad, size_t ad_len,
+    1109                 :            :                                     const unsigned char *input, size_t ilen,
+    1110                 :            :                                     unsigned char *output, size_t output_len,
+    1111                 :            :                                     size_t *olen, size_t tag_len);
+    1112                 :            : 
+    1113                 :            : /**
+    1114                 :            :  * \brief               The authenticated encryption (AEAD/NIST_KW) function.
+    1115                 :            :  *
+    1116                 :            :  * \note                If the data is not authentic, then the output buffer
+    1117                 :            :  *                      is zeroed out to prevent the unauthentic plaintext being
+    1118                 :            :  *                      used, making this interface safer.
+    1119                 :            :  *
+    1120                 :            :  * \note                For AEAD modes, the tag must be appended to the
+    1121                 :            :  *                      ciphertext, as recommended by RFC 5116.
+    1122                 :            :  *                      (NIST_KW doesn't have a separate tag.)
+    1123                 :            :  *
+    1124                 :            :  * \param ctx           The generic cipher context. This must be initialized and
+    1125                 :            :  *                      bound to a key, with an AEAD algorithm or NIST_KW.
+    1126                 :            :  * \param iv            The nonce to use. This must be a readable buffer of
+    1127                 :            :  *                      at least \p iv_len Bytes and may be \c NULL if \p
+    1128                 :            :  *                      iv_len is \c 0.
+    1129                 :            :  * \param iv_len        The length of the nonce. For AEAD ciphers, this must
+    1130                 :            :  *                      satisfy the constraints imposed by the cipher used.
+    1131                 :            :  *                      For NIST_KW, this must be \c 0.
+    1132                 :            :  * \param ad            The additional data to authenticate. This must be a
+    1133                 :            :  *                      readable buffer of at least \p ad_len Bytes, and may
+    1134                 :            :  *                      be \c NULL is \p ad_len is \c 0.
+    1135                 :            :  * \param ad_len        The length of \p ad. For NIST_KW, this must be \c 0.
+    1136                 :            :  * \param input         The buffer holding the input data. This must be a
+    1137                 :            :  *                      readable buffer of at least \p ilen Bytes, and may be
+    1138                 :            :  *                      \c NULL if \p ilen is \c 0.
+    1139                 :            :  * \param ilen          The length of the input data. For AEAD ciphers this
+    1140                 :            :  *                      must be at least \p tag_len. For NIST_KW this must be
+    1141                 :            :  *                      at least \c 8.
+    1142                 :            :  * \param output        The buffer for the output data. This must be a
+    1143                 :            :  *                      writable buffer of at least \p output_len Bytes, and
+    1144                 :            :  *                      may be \c NULL if \p output_len is \c 0.
+    1145                 :            :  * \param output_len    The length of the \p output buffer in Bytes. For AEAD
+    1146                 :            :  *                      ciphers, this must be at least \p ilen - \p tag_len.
+    1147                 :            :  *                      For NIST_KW, this must be at least \p ilen - 8.
+    1148                 :            :  * \param olen          This will be filled with the actual number of Bytes
+    1149                 :            :  *                      written to the \p output buffer. This must point to a
+    1150                 :            :  *                      writable object of type \c size_t.
+    1151                 :            :  * \param tag_len       The actual length of the authentication tag. For AEAD
+    1152                 :            :  *                      ciphers, this must match the constraints imposed by
+    1153                 :            :  *                      the cipher used, and in particular must not be \c 0.
+    1154                 :            :  *                      For NIST_KW, this must be \c 0.
+    1155                 :            :  *
+    1156                 :            :  * \return              \c 0 on success.
+    1157                 :            :  * \return              #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on
+    1158                 :            :  *                      parameter-verification failure.
+    1159                 :            :  * \return              #MBEDTLS_ERR_CIPHER_AUTH_FAILED if data is not authentic.
+    1160                 :            :  * \return              A cipher-specific error code on failure.
+    1161                 :            :  */
+    1162                 :            : int mbedtls_cipher_auth_decrypt_ext(mbedtls_cipher_context_t *ctx,
+    1163                 :            :                                     const unsigned char *iv, size_t iv_len,
+    1164                 :            :                                     const unsigned char *ad, size_t ad_len,
+    1165                 :            :                                     const unsigned char *input, size_t ilen,
+    1166                 :            :                                     unsigned char *output, size_t output_len,
+    1167                 :            :                                     size_t *olen, size_t tag_len);
+    1168                 :            : #endif /* MBEDTLS_CIPHER_MODE_AEAD || MBEDTLS_NIST_KW_C */
+    1169                 :            : #ifdef __cplusplus
+    1170                 :            : }
+    1171                 :            : #endif
+    1172                 :            : 
+    1173                 :            : #endif /* MBEDTLS_CIPHER_H */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/ecp.h.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/ecp.h.func-sort-c.html new file mode 100644 index 00000000000..5de0eb0d7b7 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/ecp.h.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/include/mbedtls/ecp.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/include/mbedtls - ecp.h (source / functions)HitTotalCoverage
Test:coverage.infoLines:22100.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_ecp_group_a_is_minus_3480691
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/ecp.h.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/ecp.h.func.html new file mode 100644 index 00000000000..45d47cced3a --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/ecp.h.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/include/mbedtls/ecp.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/include/mbedtls - ecp.h (source / functions)HitTotalCoverage
Test:coverage.infoLines:22100.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_ecp_group_a_is_minus_3480691
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/ecp.h.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/ecp.h.gcov.html new file mode 100644 index 00000000000..25d9aec2251 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/ecp.h.gcov.html @@ -0,0 +1,1613 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/include/mbedtls/ecp.h + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/include/mbedtls - ecp.h (source / functions)HitTotalCoverage
Test:coverage.infoLines:22100.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:00-
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  * \file ecp.h
+       3                 :            :  *
+       4                 :            :  * \brief This file provides an API for Elliptic Curves over GF(P) (ECP).
+       5                 :            :  *
+       6                 :            :  * The use of ECP in cryptography and TLS is defined in
+       7                 :            :  * <em>Standards for Efficient Cryptography Group (SECG): SEC1
+       8                 :            :  * Elliptic Curve Cryptography</em> and
+       9                 :            :  * <em>RFC-4492: Elliptic Curve Cryptography (ECC) Cipher Suites
+      10                 :            :  * for Transport Layer Security (TLS)</em>.
+      11                 :            :  *
+      12                 :            :  * <em>RFC-2409: The Internet Key Exchange (IKE)</em> defines ECP
+      13                 :            :  * group types.
+      14                 :            :  *
+      15                 :            :  */
+      16                 :            : 
+      17                 :            : /*
+      18                 :            :  *  Copyright The Mbed TLS Contributors
+      19                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+      20                 :            :  */
+      21                 :            : 
+      22                 :            : #ifndef MBEDTLS_ECP_H
+      23                 :            : #define MBEDTLS_ECP_H
+      24                 :            : #include "mbedtls/private_access.h"
+      25                 :            : 
+      26                 :            : #include "mbedtls/build_info.h"
+      27                 :            : #include "mbedtls/platform_util.h"
+      28                 :            : 
+      29                 :            : #include "mbedtls/bignum.h"
+      30                 :            : 
+      31                 :            : /*
+      32                 :            :  * ECP error codes
+      33                 :            :  */
+      34                 :            : /** Bad input parameters to function. */
+      35                 :            : #define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
+      36                 :            : /** The buffer is too small to write to. */
+      37                 :            : #define MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL                  -0x4F00
+      38                 :            : /** The requested feature is not available, for example, the requested curve is not supported. */
+      39                 :            : #define MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE               -0x4E80
+      40                 :            : /** The signature is not valid. */
+      41                 :            : #define MBEDTLS_ERR_ECP_VERIFY_FAILED                     -0x4E00
+      42                 :            : /** Memory allocation failed. */
+      43                 :            : #define MBEDTLS_ERR_ECP_ALLOC_FAILED                      -0x4D80
+      44                 :            : /** Generation of random value, such as ephemeral key, failed. */
+      45                 :            : #define MBEDTLS_ERR_ECP_RANDOM_FAILED                     -0x4D00
+      46                 :            : /** Invalid private or public key. */
+      47                 :            : #define MBEDTLS_ERR_ECP_INVALID_KEY                       -0x4C80
+      48                 :            : /** The buffer contains a valid signature followed by more data. */
+      49                 :            : #define MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH                  -0x4C00
+      50                 :            : /** Operation in progress, call again with the same parameters to continue. */
+      51                 :            : #define MBEDTLS_ERR_ECP_IN_PROGRESS                       -0x4B00
+      52                 :            : 
+      53                 :            : /* Flags indicating whether to include code that is specific to certain
+      54                 :            :  * types of curves. These flags are for internal library use only. */
+      55                 :            : #if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) || \
+      56                 :            :     defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) || \
+      57                 :            :     defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) || \
+      58                 :            :     defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED) || \
+      59                 :            :     defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED) || \
+      60                 :            :     defined(MBEDTLS_ECP_DP_BP256R1_ENABLED) || \
+      61                 :            :     defined(MBEDTLS_ECP_DP_BP384R1_ENABLED) || \
+      62                 :            :     defined(MBEDTLS_ECP_DP_BP512R1_ENABLED) || \
+      63                 :            :     defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED) || \
+      64                 :            :     defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED) || \
+      65                 :            :     defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED)
+      66                 :            : #define MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED
+      67                 :            : #endif
+      68                 :            : #if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED) || \
+      69                 :            :     defined(MBEDTLS_ECP_DP_CURVE448_ENABLED)
+      70                 :            : #define MBEDTLS_ECP_MONTGOMERY_ENABLED
+      71                 :            : #endif
+      72                 :            : 
+      73                 :            : #ifdef __cplusplus
+      74                 :            : extern "C" {
+      75                 :            : #endif
+      76                 :            : 
+      77                 :            : /**
+      78                 :            :  * Domain-parameter identifiers: curve, subgroup, and generator.
+      79                 :            :  *
+      80                 :            :  * \note Only curves over prime fields are supported.
+      81                 :            :  *
+      82                 :            :  * \warning This library does not support validation of arbitrary domain
+      83                 :            :  * parameters. Therefore, only standardized domain parameters from trusted
+      84                 :            :  * sources should be used. See mbedtls_ecp_group_load().
+      85                 :            :  */
+      86                 :            : /* Note: when adding a new curve:
+      87                 :            :  * - Add it at the end of this enum, otherwise you'll break the ABI by
+      88                 :            :  *   changing the numerical value for existing curves.
+      89                 :            :  * - Increment MBEDTLS_ECP_DP_MAX below if needed.
+      90                 :            :  * - Update the calculation of MBEDTLS_ECP_MAX_BITS below.
+      91                 :            :  * - Add the corresponding MBEDTLS_ECP_DP_xxx_ENABLED macro definition to
+      92                 :            :  *   mbedtls_config.h.
+      93                 :            :  * - List the curve as a dependency of MBEDTLS_ECP_C and
+      94                 :            :  *   MBEDTLS_ECDSA_C if supported in check_config.h.
+      95                 :            :  * - Add the curve to the appropriate curve type macro
+      96                 :            :  *   MBEDTLS_ECP_yyy_ENABLED above.
+      97                 :            :  * - Add the necessary definitions to ecp_curves.c.
+      98                 :            :  * - Add the curve to the ecp_supported_curves array in ecp.c.
+      99                 :            :  * - Add the curve to applicable profiles in x509_crt.c.
+     100                 :            :  * - Add the curve to applicable presets in ssl_tls.c.
+     101                 :            :  */
+     102                 :            : typedef enum {
+     103                 :            :     MBEDTLS_ECP_DP_NONE = 0,       /*!< Curve not defined. */
+     104                 :            :     MBEDTLS_ECP_DP_SECP192R1,      /*!< Domain parameters for the 192-bit curve defined by FIPS 186-4 and SEC1. */
+     105                 :            :     MBEDTLS_ECP_DP_SECP224R1,      /*!< Domain parameters for the 224-bit curve defined by FIPS 186-4 and SEC1. */
+     106                 :            :     MBEDTLS_ECP_DP_SECP256R1,      /*!< Domain parameters for the 256-bit curve defined by FIPS 186-4 and SEC1. */
+     107                 :            :     MBEDTLS_ECP_DP_SECP384R1,      /*!< Domain parameters for the 384-bit curve defined by FIPS 186-4 and SEC1. */
+     108                 :            :     MBEDTLS_ECP_DP_SECP521R1,      /*!< Domain parameters for the 521-bit curve defined by FIPS 186-4 and SEC1. */
+     109                 :            :     MBEDTLS_ECP_DP_BP256R1,        /*!< Domain parameters for 256-bit Brainpool curve. */
+     110                 :            :     MBEDTLS_ECP_DP_BP384R1,        /*!< Domain parameters for 384-bit Brainpool curve. */
+     111                 :            :     MBEDTLS_ECP_DP_BP512R1,        /*!< Domain parameters for 512-bit Brainpool curve. */
+     112                 :            :     MBEDTLS_ECP_DP_CURVE25519,     /*!< Domain parameters for Curve25519. */
+     113                 :            :     MBEDTLS_ECP_DP_SECP192K1,      /*!< Domain parameters for 192-bit "Koblitz" curve. */
+     114                 :            :     MBEDTLS_ECP_DP_SECP224K1,      /*!< Domain parameters for 224-bit "Koblitz" curve. */
+     115                 :            :     MBEDTLS_ECP_DP_SECP256K1,      /*!< Domain parameters for 256-bit "Koblitz" curve. */
+     116                 :            :     MBEDTLS_ECP_DP_CURVE448,       /*!< Domain parameters for Curve448. */
+     117                 :            : } mbedtls_ecp_group_id;
+     118                 :            : 
+     119                 :            : /**
+     120                 :            :  * The number of supported curves, plus one for #MBEDTLS_ECP_DP_NONE.
+     121                 :            :  */
+     122                 :            : #define MBEDTLS_ECP_DP_MAX     14
+     123                 :            : 
+     124                 :            : /*
+     125                 :            :  * Curve types
+     126                 :            :  */
+     127                 :            : typedef enum {
+     128                 :            :     MBEDTLS_ECP_TYPE_NONE = 0,
+     129                 :            :     MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS,    /* y^2 = x^3 + a x + b      */
+     130                 :            :     MBEDTLS_ECP_TYPE_MONTGOMERY,           /* y^2 = x^3 + a x^2 + x    */
+     131                 :            : } mbedtls_ecp_curve_type;
+     132                 :            : 
+     133                 :            : /**
+     134                 :            :  * Curve information, for use by other modules.
+     135                 :            :  *
+     136                 :            :  * The fields of this structure are part of the public API and can be
+     137                 :            :  * accessed directly by applications. Future versions of the library may
+     138                 :            :  * add extra fields or reorder existing fields.
+     139                 :            :  */
+     140                 :            : typedef struct mbedtls_ecp_curve_info {
+     141                 :            :     mbedtls_ecp_group_id grp_id;    /*!< An internal identifier. */
+     142                 :            :     uint16_t tls_id;                /*!< The TLS NamedCurve identifier. */
+     143                 :            :     uint16_t bit_size;              /*!< The curve size in bits. */
+     144                 :            :     const char *name;               /*!< A human-friendly name. */
+     145                 :            : } mbedtls_ecp_curve_info;
+     146                 :            : 
+     147                 :            : /**
+     148                 :            :  * \brief           The ECP point structure, in Jacobian coordinates.
+     149                 :            :  *
+     150                 :            :  * \note            All functions expect and return points satisfying
+     151                 :            :  *                  the following condition: <code>Z == 0</code> or
+     152                 :            :  *                  <code>Z == 1</code>. Other values of \p Z are
+     153                 :            :  *                  used only by internal functions.
+     154                 :            :  *                  The point is zero, or "at infinity", if <code>Z == 0</code>.
+     155                 :            :  *                  Otherwise, \p X and \p Y are its standard (affine)
+     156                 :            :  *                  coordinates.
+     157                 :            :  */
+     158                 :            : typedef struct mbedtls_ecp_point {
+     159                 :            :     mbedtls_mpi MBEDTLS_PRIVATE(X);          /*!< The X coordinate of the ECP point. */
+     160                 :            :     mbedtls_mpi MBEDTLS_PRIVATE(Y);          /*!< The Y coordinate of the ECP point. */
+     161                 :            :     mbedtls_mpi MBEDTLS_PRIVATE(Z);          /*!< The Z coordinate of the ECP point. */
+     162                 :            : }
+     163                 :            : mbedtls_ecp_point;
+     164                 :            : 
+     165                 :            : #if !defined(MBEDTLS_ECP_ALT)
+     166                 :            : /*
+     167                 :            :  * default Mbed TLS elliptic curve arithmetic implementation
+     168                 :            :  *
+     169                 :            :  * (in case MBEDTLS_ECP_ALT is defined then the developer has to provide an
+     170                 :            :  * alternative implementation for the whole module and it will replace this
+     171                 :            :  * one.)
+     172                 :            :  */
+     173                 :            : 
+     174                 :            : /**
+     175                 :            :  * \brief           The ECP group structure.
+     176                 :            :  *
+     177                 :            :  * We consider two types of curve equations:
+     178                 :            :  * <ul><li>Short Weierstrass: <code>y^2 = x^3 + A x + B mod P</code>
+     179                 :            :  * (SEC1 + RFC-4492)</li>
+     180                 :            :  * <li>Montgomery: <code>y^2 = x^3 + A x^2 + x mod P</code> (Curve25519,
+     181                 :            :  * Curve448)</li></ul>
+     182                 :            :  * In both cases, the generator (\p G) for a prime-order subgroup is fixed.
+     183                 :            :  *
+     184                 :            :  * For Short Weierstrass, this subgroup is the whole curve, and its
+     185                 :            :  * cardinality is denoted by \p N. Our code requires that \p N is an
+     186                 :            :  * odd prime as mbedtls_ecp_mul() requires an odd number, and
+     187                 :            :  * mbedtls_ecdsa_sign() requires that it is prime for blinding purposes.
+     188                 :            :  *
+     189                 :            :  * The default implementation only initializes \p A without setting it to the
+     190                 :            :  * authentic value for curves with <code>A = -3</code>(SECP256R1, etc), in which
+     191                 :            :  * case you need to load \p A by yourself when using domain parameters directly,
+     192                 :            :  * for example:
+     193                 :            :  * \code
+     194                 :            :  * mbedtls_mpi_init(&A);
+     195                 :            :  * mbedtls_ecp_group_init(&grp);
+     196                 :            :  * CHECK_RETURN(mbedtls_ecp_group_load(&grp, grp_id));
+     197                 :            :  * if (mbedtls_ecp_group_a_is_minus_3(&grp)) {
+     198                 :            :  *     CHECK_RETURN(mbedtls_mpi_sub_int(&A, &grp.P, 3));
+     199                 :            :  * } else {
+     200                 :            :  *     CHECK_RETURN(mbedtls_mpi_copy(&A, &grp.A));
+     201                 :            :  * }
+     202                 :            :  *
+     203                 :            :  * do_something_with_a(&A);
+     204                 :            :  *
+     205                 :            :  * cleanup:
+     206                 :            :  * mbedtls_mpi_free(&A);
+     207                 :            :  * mbedtls_ecp_group_free(&grp);
+     208                 :            :  * \endcode
+     209                 :            :  *
+     210                 :            :  * For Montgomery curves, we do not store \p A, but <code>(A + 2) / 4</code>,
+     211                 :            :  * which is the quantity used in the formulas. Additionally, \p nbits is
+     212                 :            :  * not the size of \p N but the required size for private keys.
+     213                 :            :  *
+     214                 :            :  * If \p modp is NULL, reduction modulo \p P is done using a generic algorithm.
+     215                 :            :  * Otherwise, \p modp must point to a function that takes an \p mbedtls_mpi in the
+     216                 :            :  * range of <code>0..2^(2*pbits)-1</code>, and transforms it in-place to an integer
+     217                 :            :  * which is congruent mod \p P to the given MPI, and is close enough to \p pbits
+     218                 :            :  * in size, so that it may be efficiently brought in the 0..P-1 range by a few
+     219                 :            :  * additions or subtractions. Therefore, it is only an approximative modular
+     220                 :            :  * reduction. It must return 0 on success and non-zero on failure.
+     221                 :            :  *
+     222                 :            :  * \note        Alternative implementations of the ECP module must obey the
+     223                 :            :  *              following constraints.
+     224                 :            :  *              * Group IDs must be distinct: if two group structures have
+     225                 :            :  *                the same ID, then they must be identical.
+     226                 :            :  *              * The fields \c id, \c P, \c A, \c B, \c G, \c N,
+     227                 :            :  *                \c pbits and \c nbits must have the same type and semantics
+     228                 :            :  *                as in the built-in implementation.
+     229                 :            :  *                They must be available for reading, but direct modification
+     230                 :            :  *                of these fields does not need to be supported.
+     231                 :            :  *                They do not need to be at the same offset in the structure.
+     232                 :            :  */
+     233                 :            : typedef struct mbedtls_ecp_group {
+     234                 :            :     mbedtls_ecp_group_id id;    /*!< An internal group identifier. */
+     235                 :            :     mbedtls_mpi P;              /*!< The prime modulus of the base field. */
+     236                 :            :     mbedtls_mpi A;              /*!< For Short Weierstrass: \p A in the equation. Note that
+     237                 :            :                                      \p A is not set to the authentic value in some cases.
+     238                 :            :                                      Refer to detailed description of ::mbedtls_ecp_group if
+     239                 :            :                                      using domain parameters in the structure.
+     240                 :            :                                      For Montgomery curves: <code>(A + 2) / 4</code>. */
+     241                 :            :     mbedtls_mpi B;              /*!< For Short Weierstrass: \p B in the equation.
+     242                 :            :                                      For Montgomery curves: unused. */
+     243                 :            :     mbedtls_ecp_point G;        /*!< The generator of the subgroup used. */
+     244                 :            :     mbedtls_mpi N;              /*!< The order of \p G. */
+     245                 :            :     size_t pbits;               /*!< The number of bits in \p P.*/
+     246                 :            :     size_t nbits;               /*!< For Short Weierstrass: The number of bits in \p P.
+     247                 :            :                                      For Montgomery curves: the number of bits in the
+     248                 :            :                                      private keys. */
+     249                 :            :     /* End of public fields */
+     250                 :            : 
+     251                 :            :     unsigned int MBEDTLS_PRIVATE(h);             /*!< \internal 1 if the constants are static. */
+     252                 :            :     int(*MBEDTLS_PRIVATE(modp))(mbedtls_mpi *);  /*!< The function for fast pseudo-reduction
+     253                 :            :                                                     mod \p P (see above).*/
+     254                 :            :     int(*MBEDTLS_PRIVATE(t_pre))(mbedtls_ecp_point *, void *);   /*!< Unused. */
+     255                 :            :     int(*MBEDTLS_PRIVATE(t_post))(mbedtls_ecp_point *, void *);  /*!< Unused. */
+     256                 :            :     void *MBEDTLS_PRIVATE(t_data);               /*!< Unused. */
+     257                 :            :     mbedtls_ecp_point *MBEDTLS_PRIVATE(T);       /*!< Pre-computed points for ecp_mul_comb(). */
+     258                 :            :     size_t MBEDTLS_PRIVATE(T_size);              /*!< The number of dynamic allocated pre-computed points. */
+     259                 :            : }
+     260                 :            : mbedtls_ecp_group;
+     261                 :            : 
+     262                 :            : /**
+     263                 :            :  * \name SECTION: Module settings
+     264                 :            :  *
+     265                 :            :  * The configuration options you can set for this module are in this section.
+     266                 :            :  * Either change them in mbedtls_config.h, or define them using the compiler command line.
+     267                 :            :  * \{
+     268                 :            :  */
+     269                 :            : 
+     270                 :            : #if !defined(MBEDTLS_ECP_WINDOW_SIZE)
+     271                 :            : /*
+     272                 :            :  * Maximum "window" size used for point multiplication.
+     273                 :            :  * Default: a point where higher memory usage yields diminishing performance
+     274                 :            :  *          returns.
+     275                 :            :  * Minimum value: 2. Maximum value: 7.
+     276                 :            :  *
+     277                 :            :  * Result is an array of at most ( 1 << ( MBEDTLS_ECP_WINDOW_SIZE - 1 ) )
+     278                 :            :  * points used for point multiplication. This value is directly tied to EC
+     279                 :            :  * peak memory usage, so decreasing it by one should roughly cut memory usage
+     280                 :            :  * by two (if large curves are in use).
+     281                 :            :  *
+     282                 :            :  * Reduction in size may reduce speed, but larger curves are impacted first.
+     283                 :            :  * Sample performances (in ECDHE handshakes/s, with FIXED_POINT_OPTIM = 1):
+     284                 :            :  *      w-size:     6       5       4       3       2
+     285                 :            :  *      521       145     141     135     120      97
+     286                 :            :  *      384       214     209     198     177     146
+     287                 :            :  *      256       320     320     303     262     226
+     288                 :            :  *      224       475     475     453     398     342
+     289                 :            :  *      192       640     640     633     587     476
+     290                 :            :  */
+     291                 :            : #define MBEDTLS_ECP_WINDOW_SIZE    4   /**< The maximum window size used. */
+     292                 :            : #endif /* MBEDTLS_ECP_WINDOW_SIZE */
+     293                 :            : 
+     294                 :            : #if !defined(MBEDTLS_ECP_FIXED_POINT_OPTIM)
+     295                 :            : /*
+     296                 :            :  * Trade code size for speed on fixed-point multiplication.
+     297                 :            :  *
+     298                 :            :  * This speeds up repeated multiplication of the generator (that is, the
+     299                 :            :  * multiplication in ECDSA signatures, and half of the multiplications in
+     300                 :            :  * ECDSA verification and ECDHE) by a factor roughly 3 to 4.
+     301                 :            :  *
+     302                 :            :  * For each n-bit Short Weierstrass curve that is enabled, this adds 4n bytes
+     303                 :            :  * of code size if n < 384 and 8n otherwise.
+     304                 :            :  *
+     305                 :            :  * Change this value to 0 to reduce code size.
+     306                 :            :  */
+     307                 :            : #define MBEDTLS_ECP_FIXED_POINT_OPTIM  1   /**< Enable fixed-point speed-up. */
+     308                 :            : #endif /* MBEDTLS_ECP_FIXED_POINT_OPTIM */
+     309                 :            : 
+     310                 :            : /** \} name SECTION: Module settings */
+     311                 :            : 
+     312                 :            : #else  /* MBEDTLS_ECP_ALT */
+     313                 :            : #include "ecp_alt.h"
+     314                 :            : #endif /* MBEDTLS_ECP_ALT */
+     315                 :            : 
+     316                 :            : /**
+     317                 :            :  * The maximum size of the groups, that is, of \c N and \c P.
+     318                 :            :  */
+     319                 :            : #if !defined(MBEDTLS_ECP_LIGHT)
+     320                 :            : /* Dummy definition to help code that has optional ECP support and
+     321                 :            :  * defines an MBEDTLS_ECP_MAX_BYTES-sized array unconditionally. */
+     322                 :            : #define MBEDTLS_ECP_MAX_BITS 1
+     323                 :            : /* Note: the curves must be listed in DECREASING size! */
+     324                 :            : #elif defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED)
+     325                 :            : #define MBEDTLS_ECP_MAX_BITS 521
+     326                 :            : #elif defined(MBEDTLS_ECP_DP_BP512R1_ENABLED)
+     327                 :            : #define MBEDTLS_ECP_MAX_BITS 512
+     328                 :            : #elif defined(MBEDTLS_ECP_DP_CURVE448_ENABLED)
+     329                 :            : #define MBEDTLS_ECP_MAX_BITS 448
+     330                 :            : #elif defined(MBEDTLS_ECP_DP_BP384R1_ENABLED)
+     331                 :            : #define MBEDTLS_ECP_MAX_BITS 384
+     332                 :            : #elif defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED)
+     333                 :            : #define MBEDTLS_ECP_MAX_BITS 384
+     334                 :            : #elif defined(MBEDTLS_ECP_DP_BP256R1_ENABLED)
+     335                 :            : #define MBEDTLS_ECP_MAX_BITS 256
+     336                 :            : #elif defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED)
+     337                 :            : #define MBEDTLS_ECP_MAX_BITS 256
+     338                 :            : #elif defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED)
+     339                 :            : #define MBEDTLS_ECP_MAX_BITS 256
+     340                 :            : #elif defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED)
+     341                 :            : #define MBEDTLS_ECP_MAX_BITS 255
+     342                 :            : #elif defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED)
+     343                 :            : #define MBEDTLS_ECP_MAX_BITS 225 // n is slightly above 2^224
+     344                 :            : #elif defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED)
+     345                 :            : #define MBEDTLS_ECP_MAX_BITS 224
+     346                 :            : #elif defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED)
+     347                 :            : #define MBEDTLS_ECP_MAX_BITS 192
+     348                 :            : #elif defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED)
+     349                 :            : #define MBEDTLS_ECP_MAX_BITS 192
+     350                 :            : #else /* !MBEDTLS_ECP_LIGHT */
+     351                 :            : #error "Missing definition of MBEDTLS_ECP_MAX_BITS"
+     352                 :            : #endif /* !MBEDTLS_ECP_LIGHT */
+     353                 :            : 
+     354                 :            : #define MBEDTLS_ECP_MAX_BYTES    ((MBEDTLS_ECP_MAX_BITS + 7) / 8)
+     355                 :            : #define MBEDTLS_ECP_MAX_PT_LEN   (2 * MBEDTLS_ECP_MAX_BYTES + 1)
+     356                 :            : 
+     357                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+     358                 :            : 
+     359                 :            : /**
+     360                 :            :  * \brief           Internal restart context for multiplication
+     361                 :            :  *
+     362                 :            :  * \note            Opaque struct
+     363                 :            :  */
+     364                 :            : typedef struct mbedtls_ecp_restart_mul mbedtls_ecp_restart_mul_ctx;
+     365                 :            : 
+     366                 :            : /**
+     367                 :            :  * \brief           Internal restart context for ecp_muladd()
+     368                 :            :  *
+     369                 :            :  * \note            Opaque struct
+     370                 :            :  */
+     371                 :            : typedef struct mbedtls_ecp_restart_muladd mbedtls_ecp_restart_muladd_ctx;
+     372                 :            : 
+     373                 :            : /**
+     374                 :            :  * \brief           General context for resuming ECC operations
+     375                 :            :  */
+     376                 :            : typedef struct {
+     377                 :            :     unsigned MBEDTLS_PRIVATE(ops_done);                  /*!<  current ops count             */
+     378                 :            :     unsigned MBEDTLS_PRIVATE(depth);                     /*!<  call depth (0 = top-level)    */
+     379                 :            :     mbedtls_ecp_restart_mul_ctx *MBEDTLS_PRIVATE(rsm);   /*!<  ecp_mul_comb() sub-context    */
+     380                 :            :     mbedtls_ecp_restart_muladd_ctx *MBEDTLS_PRIVATE(ma); /*!<  ecp_muladd() sub-context      */
+     381                 :            : } mbedtls_ecp_restart_ctx;
+     382                 :            : 
+     383                 :            : /*
+     384                 :            :  * Operation counts for restartable functions
+     385                 :            :  */
+     386                 :            : #define MBEDTLS_ECP_OPS_CHK   3 /*!< basic ops count for ecp_check_pubkey()  */
+     387                 :            : #define MBEDTLS_ECP_OPS_DBL   8 /*!< basic ops count for ecp_double_jac()    */
+     388                 :            : #define MBEDTLS_ECP_OPS_ADD  11 /*!< basic ops count for see ecp_add_mixed() */
+     389                 :            : #define MBEDTLS_ECP_OPS_INV 120 /*!< empirical equivalent for mpi_mod_inv()  */
+     390                 :            : 
+     391                 :            : /**
+     392                 :            :  * \brief           Internal; for restartable functions in other modules.
+     393                 :            :  *                  Check and update basic ops budget.
+     394                 :            :  *
+     395                 :            :  * \param grp       Group structure
+     396                 :            :  * \param rs_ctx    Restart context
+     397                 :            :  * \param ops       Number of basic ops to do
+     398                 :            :  *
+     399                 :            :  * \return          \c 0 if doing \p ops basic ops is still allowed,
+     400                 :            :  * \return          #MBEDTLS_ERR_ECP_IN_PROGRESS otherwise.
+     401                 :            :  */
+     402                 :            : int mbedtls_ecp_check_budget(const mbedtls_ecp_group *grp,
+     403                 :            :                              mbedtls_ecp_restart_ctx *rs_ctx,
+     404                 :            :                              unsigned ops);
+     405                 :            : 
+     406                 :            : /* Utility macro for checking and updating ops budget */
+     407                 :            : #define MBEDTLS_ECP_BUDGET(ops)   \
+     408                 :            :     MBEDTLS_MPI_CHK(mbedtls_ecp_check_budget(grp, rs_ctx, \
+     409                 :            :                                              (unsigned) (ops)));
+     410                 :            : 
+     411                 :            : #else /* MBEDTLS_ECP_RESTARTABLE */
+     412                 :            : 
+     413                 :            : #define MBEDTLS_ECP_BUDGET(ops)     /* no-op; for compatibility */
+     414                 :            : 
+     415                 :            : /* We want to declare restartable versions of existing functions anyway */
+     416                 :            : typedef void mbedtls_ecp_restart_ctx;
+     417                 :            : 
+     418                 :            : #endif /* MBEDTLS_ECP_RESTARTABLE */
+     419                 :            : 
+     420                 :            : /**
+     421                 :            :  * \brief    The ECP key-pair structure.
+     422                 :            :  *
+     423                 :            :  * A generic key-pair that may be used for ECDSA and fixed ECDH, for example.
+     424                 :            :  *
+     425                 :            :  * \note    Members are deliberately in the same order as in the
+     426                 :            :  *          ::mbedtls_ecdsa_context structure.
+     427                 :            :  */
+     428                 :            : typedef struct mbedtls_ecp_keypair {
+     429                 :            :     mbedtls_ecp_group MBEDTLS_PRIVATE(grp);      /*!<  Elliptic curve and base point     */
+     430                 :            :     mbedtls_mpi MBEDTLS_PRIVATE(d);              /*!<  our secret value                  */
+     431                 :            :     mbedtls_ecp_point MBEDTLS_PRIVATE(Q);        /*!<  our public value                  */
+     432                 :            : }
+     433                 :            : mbedtls_ecp_keypair;
+     434                 :            : 
+     435                 :            : /**
+     436                 :            :  * The uncompressed point format for Short Weierstrass curves
+     437                 :            :  * (MBEDTLS_ECP_DP_SECP_XXX and MBEDTLS_ECP_DP_BP_XXX).
+     438                 :            :  */
+     439                 :            : #define MBEDTLS_ECP_PF_UNCOMPRESSED    0
+     440                 :            : /**
+     441                 :            :  * The compressed point format for Short Weierstrass curves
+     442                 :            :  * (MBEDTLS_ECP_DP_SECP_XXX and MBEDTLS_ECP_DP_BP_XXX).
+     443                 :            :  *
+     444                 :            :  * \warning     While this format is supported for all concerned curves for
+     445                 :            :  *              writing, when it comes to parsing, it is not supported for all
+     446                 :            :  *              curves. Specifically, parsing compressed points on
+     447                 :            :  *              MBEDTLS_ECP_DP_SECP224R1 and MBEDTLS_ECP_DP_SECP224K1 is not
+     448                 :            :  *              supported.
+     449                 :            :  */
+     450                 :            : #define MBEDTLS_ECP_PF_COMPRESSED      1
+     451                 :            : 
+     452                 :            : /*
+     453                 :            :  * Some other constants from RFC 4492
+     454                 :            :  */
+     455                 :            : #define MBEDTLS_ECP_TLS_NAMED_CURVE    3   /**< The named_curve of ECCurveType. */
+     456                 :            : 
+     457                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+     458                 :            : /**
+     459                 :            :  * \brief           Set the maximum number of basic operations done in a row.
+     460                 :            :  *
+     461                 :            :  *                  If more operations are needed to complete a computation,
+     462                 :            :  *                  #MBEDTLS_ERR_ECP_IN_PROGRESS will be returned by the
+     463                 :            :  *                  function performing the computation. It is then the
+     464                 :            :  *                  caller's responsibility to either call again with the same
+     465                 :            :  *                  parameters until it returns 0 or an error code; or to free
+     466                 :            :  *                  the restart context if the operation is to be aborted.
+     467                 :            :  *
+     468                 :            :  *                  It is strictly required that all input parameters and the
+     469                 :            :  *                  restart context be the same on successive calls for the
+     470                 :            :  *                  same operation, but output parameters need not be the
+     471                 :            :  *                  same; they must not be used until the function finally
+     472                 :            :  *                  returns 0.
+     473                 :            :  *
+     474                 :            :  *                  This only applies to functions whose documentation
+     475                 :            :  *                  mentions they may return #MBEDTLS_ERR_ECP_IN_PROGRESS (or
+     476                 :            :  *                  #MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS for functions in the
+     477                 :            :  *                  SSL module). For functions that accept a "restart context"
+     478                 :            :  *                  argument, passing NULL disables restart and makes the
+     479                 :            :  *                  function equivalent to the function with the same name
+     480                 :            :  *                  with \c _restartable removed. For functions in the ECDH
+     481                 :            :  *                  module, restart is disabled unless the function accepts
+     482                 :            :  *                  an "ECDH context" argument and
+     483                 :            :  *                  mbedtls_ecdh_enable_restart() was previously called on
+     484                 :            :  *                  that context. For function in the SSL module, restart is
+     485                 :            :  *                  only enabled for specific sides and key exchanges
+     486                 :            :  *                  (currently only for clients and ECDHE-ECDSA).
+     487                 :            :  *
+     488                 :            :  * \warning         Using the PSA interruptible interfaces with keys in local
+     489                 :            :  *                  storage and no accelerator driver will also call this
+     490                 :            :  *                  function to set the values specified via those interfaces,
+     491                 :            :  *                  overwriting values previously set. Care should be taken if
+     492                 :            :  *                  mixing these two interfaces.
+     493                 :            :  *
+     494                 :            :  * \param max_ops   Maximum number of basic operations done in a row.
+     495                 :            :  *                  Default: 0 (unlimited).
+     496                 :            :  *                  Lower (non-zero) values mean ECC functions will block for
+     497                 :            :  *                  a lesser maximum amount of time.
+     498                 :            :  *
+     499                 :            :  * \note            A "basic operation" is defined as a rough equivalent of a
+     500                 :            :  *                  multiplication in GF(p) for the NIST P-256 curve.
+     501                 :            :  *                  As an indication, with default settings, a scalar
+     502                 :            :  *                  multiplication (full run of \c mbedtls_ecp_mul()) is:
+     503                 :            :  *                  - about 3300 basic operations for P-256
+     504                 :            :  *                  - about 9400 basic operations for P-384
+     505                 :            :  *
+     506                 :            :  * \note            Very low values are not always respected: sometimes
+     507                 :            :  *                  functions need to block for a minimum number of
+     508                 :            :  *                  operations, and will do so even if max_ops is set to a
+     509                 :            :  *                  lower value.  That minimum depends on the curve size, and
+     510                 :            :  *                  can be made lower by decreasing the value of
+     511                 :            :  *                  \c MBEDTLS_ECP_WINDOW_SIZE.  As an indication, here is the
+     512                 :            :  *                  lowest effective value for various curves and values of
+     513                 :            :  *                  that parameter (w for short):
+     514                 :            :  *                          w=6     w=5     w=4     w=3     w=2
+     515                 :            :  *                  P-256   208     208     160     136     124
+     516                 :            :  *                  P-384   682     416     320     272     248
+     517                 :            :  *                  P-521  1364     832     640     544     496
+     518                 :            :  *
+     519                 :            :  * \note            This setting is currently ignored by Curve25519.
+     520                 :            :  */
+     521                 :            : void mbedtls_ecp_set_max_ops(unsigned max_ops);
+     522                 :            : 
+     523                 :            : /**
+     524                 :            :  * \brief           Check if restart is enabled (max_ops != 0)
+     525                 :            :  *
+     526                 :            :  * \return          \c 0 if \c max_ops == 0 (restart disabled)
+     527                 :            :  * \return          \c 1 otherwise (restart enabled)
+     528                 :            :  */
+     529                 :            : int mbedtls_ecp_restart_is_enabled(void);
+     530                 :            : #endif /* MBEDTLS_ECP_RESTARTABLE */
+     531                 :            : 
+     532                 :            : /*
+     533                 :            :  * Get the type of a curve
+     534                 :            :  */
+     535                 :            : mbedtls_ecp_curve_type mbedtls_ecp_get_type(const mbedtls_ecp_group *grp);
+     536                 :            : 
+     537                 :            : /**
+     538                 :            :  * \brief           This function retrieves the information defined in
+     539                 :            :  *                  mbedtls_ecp_curve_info() for all supported curves.
+     540                 :            :  *
+     541                 :            :  * \note            This function returns information about all curves
+     542                 :            :  *                  supported by the library. Some curves may not be
+     543                 :            :  *                  supported for all algorithms. Call mbedtls_ecdh_can_do()
+     544                 :            :  *                  or mbedtls_ecdsa_can_do() to check if a curve is
+     545                 :            :  *                  supported for ECDH or ECDSA.
+     546                 :            :  *
+     547                 :            :  * \return          A statically allocated array. The last entry is 0.
+     548                 :            :  */
+     549                 :            : const mbedtls_ecp_curve_info *mbedtls_ecp_curve_list(void);
+     550                 :            : 
+     551                 :            : /**
+     552                 :            :  * \brief           This function retrieves the list of internal group
+     553                 :            :  *                  identifiers of all supported curves in the order of
+     554                 :            :  *                  preference.
+     555                 :            :  *
+     556                 :            :  * \note            This function returns information about all curves
+     557                 :            :  *                  supported by the library. Some curves may not be
+     558                 :            :  *                  supported for all algorithms. Call mbedtls_ecdh_can_do()
+     559                 :            :  *                  or mbedtls_ecdsa_can_do() to check if a curve is
+     560                 :            :  *                  supported for ECDH or ECDSA.
+     561                 :            :  *
+     562                 :            :  * \return          A statically allocated array,
+     563                 :            :  *                  terminated with MBEDTLS_ECP_DP_NONE.
+     564                 :            :  */
+     565                 :            : const mbedtls_ecp_group_id *mbedtls_ecp_grp_id_list(void);
+     566                 :            : 
+     567                 :            : /**
+     568                 :            :  * \brief           This function retrieves curve information from an internal
+     569                 :            :  *                  group identifier.
+     570                 :            :  *
+     571                 :            :  * \param grp_id    An \c MBEDTLS_ECP_DP_XXX value.
+     572                 :            :  *
+     573                 :            :  * \return          The associated curve information on success.
+     574                 :            :  * \return          NULL on failure.
+     575                 :            :  */
+     576                 :            : const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_grp_id(mbedtls_ecp_group_id grp_id);
+     577                 :            : 
+     578                 :            : /**
+     579                 :            :  * \brief           This function retrieves curve information from a TLS
+     580                 :            :  *                  NamedCurve value.
+     581                 :            :  *
+     582                 :            :  * \param tls_id    An \c MBEDTLS_ECP_DP_XXX value.
+     583                 :            :  *
+     584                 :            :  * \return          The associated curve information on success.
+     585                 :            :  * \return          NULL on failure.
+     586                 :            :  */
+     587                 :            : const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_tls_id(uint16_t tls_id);
+     588                 :            : 
+     589                 :            : /**
+     590                 :            :  * \brief           This function retrieves curve information from a
+     591                 :            :  *                  human-readable name.
+     592                 :            :  *
+     593                 :            :  * \param name      The human-readable name.
+     594                 :            :  *
+     595                 :            :  * \return          The associated curve information on success.
+     596                 :            :  * \return          NULL on failure.
+     597                 :            :  */
+     598                 :            : const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_name(const char *name);
+     599                 :            : 
+     600                 :            : /**
+     601                 :            :  * \brief           This function initializes a point as zero.
+     602                 :            :  *
+     603                 :            :  * \param pt        The point to initialize.
+     604                 :            :  */
+     605                 :            : void mbedtls_ecp_point_init(mbedtls_ecp_point *pt);
+     606                 :            : 
+     607                 :            : /**
+     608                 :            :  * \brief           This function initializes an ECP group context
+     609                 :            :  *                  without loading any domain parameters.
+     610                 :            :  *
+     611                 :            :  * \note            After this function is called, domain parameters
+     612                 :            :  *                  for various ECP groups can be loaded through the
+     613                 :            :  *                  mbedtls_ecp_group_load() or mbedtls_ecp_tls_read_group()
+     614                 :            :  *                  functions.
+     615                 :            :  */
+     616                 :            : void mbedtls_ecp_group_init(mbedtls_ecp_group *grp);
+     617                 :            : 
+     618                 :            : /**
+     619                 :            :  * \brief           This function initializes a key pair as an invalid one.
+     620                 :            :  *
+     621                 :            :  * \param key       The key pair to initialize.
+     622                 :            :  */
+     623                 :            : void mbedtls_ecp_keypair_init(mbedtls_ecp_keypair *key);
+     624                 :            : 
+     625                 :            : /**
+     626                 :            :  * \brief           This function frees the components of a point.
+     627                 :            :  *
+     628                 :            :  * \param pt        The point to free.
+     629                 :            :  */
+     630                 :            : void mbedtls_ecp_point_free(mbedtls_ecp_point *pt);
+     631                 :            : 
+     632                 :            : /**
+     633                 :            :  * \brief           This function frees the components of an ECP group.
+     634                 :            :  *
+     635                 :            :  * \param grp       The group to free. This may be \c NULL, in which
+     636                 :            :  *                  case this function returns immediately. If it is not
+     637                 :            :  *                  \c NULL, it must point to an initialized ECP group.
+     638                 :            :  */
+     639                 :            : void mbedtls_ecp_group_free(mbedtls_ecp_group *grp);
+     640                 :            : 
+     641                 :            : /**
+     642                 :            :  * \brief           This function frees the components of a key pair.
+     643                 :            :  *
+     644                 :            :  * \param key       The key pair to free. This may be \c NULL, in which
+     645                 :            :  *                  case this function returns immediately. If it is not
+     646                 :            :  *                  \c NULL, it must point to an initialized ECP key pair.
+     647                 :            :  */
+     648                 :            : void mbedtls_ecp_keypair_free(mbedtls_ecp_keypair *key);
+     649                 :            : 
+     650                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+     651                 :            : /**
+     652                 :            :  * \brief           Initialize a restart context.
+     653                 :            :  *
+     654                 :            :  * \param ctx       The restart context to initialize. This must
+     655                 :            :  *                  not be \c NULL.
+     656                 :            :  */
+     657                 :            : void mbedtls_ecp_restart_init(mbedtls_ecp_restart_ctx *ctx);
+     658                 :            : 
+     659                 :            : /**
+     660                 :            :  * \brief           Free the components of a restart context.
+     661                 :            :  *
+     662                 :            :  * \param ctx       The restart context to free. This may be \c NULL, in which
+     663                 :            :  *                  case this function returns immediately. If it is not
+     664                 :            :  *                  \c NULL, it must point to an initialized restart context.
+     665                 :            :  */
+     666                 :            : void mbedtls_ecp_restart_free(mbedtls_ecp_restart_ctx *ctx);
+     667                 :            : #endif /* MBEDTLS_ECP_RESTARTABLE */
+     668                 :            : 
+     669                 :            : /**
+     670                 :            :  * \brief           This function copies the contents of point \p Q into
+     671                 :            :  *                  point \p P.
+     672                 :            :  *
+     673                 :            :  * \param P         The destination point. This must be initialized.
+     674                 :            :  * \param Q         The source point. This must be initialized.
+     675                 :            :  *
+     676                 :            :  * \return          \c 0 on success.
+     677                 :            :  * \return          #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure.
+     678                 :            :  * \return          Another negative error code for other kinds of failure.
+     679                 :            :  */
+     680                 :            : int mbedtls_ecp_copy(mbedtls_ecp_point *P, const mbedtls_ecp_point *Q);
+     681                 :            : 
+     682                 :            : /**
+     683                 :            :  * \brief           This function copies the contents of group \p src into
+     684                 :            :  *                  group \p dst.
+     685                 :            :  *
+     686                 :            :  * \param dst       The destination group. This must be initialized.
+     687                 :            :  * \param src       The source group. This must be initialized.
+     688                 :            :  *
+     689                 :            :  * \return          \c 0 on success.
+     690                 :            :  * \return          #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure.
+     691                 :            :  * \return          Another negative error code on other kinds of failure.
+     692                 :            :  */
+     693                 :            : int mbedtls_ecp_group_copy(mbedtls_ecp_group *dst,
+     694                 :            :                            const mbedtls_ecp_group *src);
+     695                 :            : 
+     696                 :            : /**
+     697                 :            :  * \brief           This function sets a point to the point at infinity.
+     698                 :            :  *
+     699                 :            :  * \param pt        The point to set. This must be initialized.
+     700                 :            :  *
+     701                 :            :  * \return          \c 0 on success.
+     702                 :            :  * \return          #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure.
+     703                 :            :  * \return          Another negative error code on other kinds of failure.
+     704                 :            :  */
+     705                 :            : int mbedtls_ecp_set_zero(mbedtls_ecp_point *pt);
+     706                 :            : 
+     707                 :            : /**
+     708                 :            :  * \brief           This function checks if a point is the point at infinity.
+     709                 :            :  *
+     710                 :            :  * \param pt        The point to test. This must be initialized.
+     711                 :            :  *
+     712                 :            :  * \return          \c 1 if the point is zero.
+     713                 :            :  * \return          \c 0 if the point is non-zero.
+     714                 :            :  * \return          A negative error code on failure.
+     715                 :            :  */
+     716                 :            : int mbedtls_ecp_is_zero(mbedtls_ecp_point *pt);
+     717                 :            : 
+     718                 :            : /**
+     719                 :            :  * \brief           This function compares two points.
+     720                 :            :  *
+     721                 :            :  * \note            This assumes that the points are normalized. Otherwise,
+     722                 :            :  *                  they may compare as "not equal" even if they are.
+     723                 :            :  *
+     724                 :            :  * \param P         The first point to compare. This must be initialized.
+     725                 :            :  * \param Q         The second point to compare. This must be initialized.
+     726                 :            :  *
+     727                 :            :  * \return          \c 0 if the points are equal.
+     728                 :            :  * \return          #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if the points are not equal.
+     729                 :            :  */
+     730                 :            : int mbedtls_ecp_point_cmp(const mbedtls_ecp_point *P,
+     731                 :            :                           const mbedtls_ecp_point *Q);
+     732                 :            : 
+     733                 :            : /**
+     734                 :            :  * \brief           This function imports a non-zero point from two ASCII
+     735                 :            :  *                  strings.
+     736                 :            :  *
+     737                 :            :  * \param P         The destination point. This must be initialized.
+     738                 :            :  * \param radix     The numeric base of the input.
+     739                 :            :  * \param x         The first affine coordinate, as a null-terminated string.
+     740                 :            :  * \param y         The second affine coordinate, as a null-terminated string.
+     741                 :            :  *
+     742                 :            :  * \return          \c 0 on success.
+     743                 :            :  * \return          An \c MBEDTLS_ERR_MPI_XXX error code on failure.
+     744                 :            :  */
+     745                 :            : int mbedtls_ecp_point_read_string(mbedtls_ecp_point *P, int radix,
+     746                 :            :                                   const char *x, const char *y);
+     747                 :            : 
+     748                 :            : /**
+     749                 :            :  * \brief           This function exports a point into unsigned binary data.
+     750                 :            :  *
+     751                 :            :  * \param grp       The group to which the point should belong.
+     752                 :            :  *                  This must be initialized and have group parameters
+     753                 :            :  *                  set, for example through mbedtls_ecp_group_load().
+     754                 :            :  * \param P         The point to export. This must be initialized.
+     755                 :            :  * \param format    The point format. This must be either
+     756                 :            :  *                  #MBEDTLS_ECP_PF_COMPRESSED or #MBEDTLS_ECP_PF_UNCOMPRESSED.
+     757                 :            :  *                  (For groups without these formats, this parameter is
+     758                 :            :  *                  ignored. But it still has to be either of the above
+     759                 :            :  *                  values.)
+     760                 :            :  * \param olen      The address at which to store the length of
+     761                 :            :  *                  the output in Bytes. This must not be \c NULL.
+     762                 :            :  * \param buf       The output buffer. This must be a writable buffer
+     763                 :            :  *                  of length \p buflen Bytes.
+     764                 :            :  * \param buflen    The length of the output buffer \p buf in Bytes.
+     765                 :            :  *
+     766                 :            :  * \return          \c 0 on success.
+     767                 :            :  * \return          #MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL if the output buffer
+     768                 :            :  *                  is too small to hold the point.
+     769                 :            :  * \return          #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the point format
+     770                 :            :  *                  or the export for the given group is not implemented.
+     771                 :            :  * \return          Another negative error code on other kinds of failure.
+     772                 :            :  */
+     773                 :            : int mbedtls_ecp_point_write_binary(const mbedtls_ecp_group *grp,
+     774                 :            :                                    const mbedtls_ecp_point *P,
+     775                 :            :                                    int format, size_t *olen,
+     776                 :            :                                    unsigned char *buf, size_t buflen);
+     777                 :            : 
+     778                 :            : /**
+     779                 :            :  * \brief           This function imports a point from unsigned binary data.
+     780                 :            :  *
+     781                 :            :  * \note            This function does not check that the point actually
+     782                 :            :  *                  belongs to the given group, see mbedtls_ecp_check_pubkey()
+     783                 :            :  *                  for that.
+     784                 :            :  *
+     785                 :            :  * \note            For compressed points, see #MBEDTLS_ECP_PF_COMPRESSED for
+     786                 :            :  *                  limitations.
+     787                 :            :  *
+     788                 :            :  * \param grp       The group to which the point should belong.
+     789                 :            :  *                  This must be initialized and have group parameters
+     790                 :            :  *                  set, for example through mbedtls_ecp_group_load().
+     791                 :            :  * \param P         The destination context to import the point to.
+     792                 :            :  *                  This must be initialized.
+     793                 :            :  * \param buf       The input buffer. This must be a readable buffer
+     794                 :            :  *                  of length \p ilen Bytes.
+     795                 :            :  * \param ilen      The length of the input buffer \p buf in Bytes.
+     796                 :            :  *
+     797                 :            :  * \return          \c 0 on success.
+     798                 :            :  * \return          #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if the input is invalid.
+     799                 :            :  * \return          #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure.
+     800                 :            :  * \return          #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the import for the
+     801                 :            :  *                  given group is not implemented.
+     802                 :            :  */
+     803                 :            : int mbedtls_ecp_point_read_binary(const mbedtls_ecp_group *grp,
+     804                 :            :                                   mbedtls_ecp_point *P,
+     805                 :            :                                   const unsigned char *buf, size_t ilen);
+     806                 :            : 
+     807                 :            : /**
+     808                 :            :  * \brief           This function imports a point from a TLS ECPoint record.
+     809                 :            :  *
+     810                 :            :  * \note            On function return, \p *buf is updated to point immediately
+     811                 :            :  *                  after the ECPoint record.
+     812                 :            :  *
+     813                 :            :  * \param grp       The ECP group to use.
+     814                 :            :  *                  This must be initialized and have group parameters
+     815                 :            :  *                  set, for example through mbedtls_ecp_group_load().
+     816                 :            :  * \param pt        The destination point.
+     817                 :            :  * \param buf       The address of the pointer to the start of the input buffer.
+     818                 :            :  * \param len       The length of the buffer.
+     819                 :            :  *
+     820                 :            :  * \return          \c 0 on success.
+     821                 :            :  * \return          An \c MBEDTLS_ERR_MPI_XXX error code on initialization
+     822                 :            :  *                  failure.
+     823                 :            :  * \return          #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if input is invalid.
+     824                 :            :  */
+     825                 :            : int mbedtls_ecp_tls_read_point(const mbedtls_ecp_group *grp,
+     826                 :            :                                mbedtls_ecp_point *pt,
+     827                 :            :                                const unsigned char **buf, size_t len);
+     828                 :            : 
+     829                 :            : /**
+     830                 :            :  * \brief           This function exports a point as a TLS ECPoint record
+     831                 :            :  *                  defined in RFC 4492, Section 5.4.
+     832                 :            :  *
+     833                 :            :  * \param grp       The ECP group to use.
+     834                 :            :  *                  This must be initialized and have group parameters
+     835                 :            :  *                  set, for example through mbedtls_ecp_group_load().
+     836                 :            :  * \param pt        The point to be exported. This must be initialized.
+     837                 :            :  * \param format    The point format to use. This must be either
+     838                 :            :  *                  #MBEDTLS_ECP_PF_COMPRESSED or #MBEDTLS_ECP_PF_UNCOMPRESSED.
+     839                 :            :  * \param olen      The address at which to store the length in Bytes
+     840                 :            :  *                  of the data written.
+     841                 :            :  * \param buf       The target buffer. This must be a writable buffer of
+     842                 :            :  *                  length \p blen Bytes.
+     843                 :            :  * \param blen      The length of the target buffer \p buf in Bytes.
+     844                 :            :  *
+     845                 :            :  * \return          \c 0 on success.
+     846                 :            :  * \return          #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if the input is invalid.
+     847                 :            :  * \return          #MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL if the target buffer
+     848                 :            :  *                  is too small to hold the exported point.
+     849                 :            :  * \return          Another negative error code on other kinds of failure.
+     850                 :            :  */
+     851                 :            : int mbedtls_ecp_tls_write_point(const mbedtls_ecp_group *grp,
+     852                 :            :                                 const mbedtls_ecp_point *pt,
+     853                 :            :                                 int format, size_t *olen,
+     854                 :            :                                 unsigned char *buf, size_t blen);
+     855                 :            : 
+     856                 :            : /**
+     857                 :            :  * \brief           This function sets up an ECP group context
+     858                 :            :  *                  from a standardized set of domain parameters.
+     859                 :            :  *
+     860                 :            :  * \note            The index should be a value of the NamedCurve enum,
+     861                 :            :  *                  as defined in <em>RFC-4492: Elliptic Curve Cryptography
+     862                 :            :  *                  (ECC) Cipher Suites for Transport Layer Security (TLS)</em>,
+     863                 :            :  *                  usually in the form of an \c MBEDTLS_ECP_DP_XXX macro.
+     864                 :            :  *
+     865                 :            :  * \param grp       The group context to setup. This must be initialized.
+     866                 :            :  * \param id        The identifier of the domain parameter set to load.
+     867                 :            :  *
+     868                 :            :  * \return          \c 0 on success.
+     869                 :            :  * \return          #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if \p id doesn't
+     870                 :            :  *                  correspond to a known group.
+     871                 :            :  * \return          Another negative error code on other kinds of failure.
+     872                 :            :  */
+     873                 :            : int mbedtls_ecp_group_load(mbedtls_ecp_group *grp, mbedtls_ecp_group_id id);
+     874                 :            : 
+     875                 :            : /**
+     876                 :            :  * \brief           This function sets up an ECP group context from a TLS
+     877                 :            :  *                  ECParameters record as defined in RFC 4492, Section 5.4.
+     878                 :            :  *
+     879                 :            :  * \note            The read pointer \p buf is updated to point right after
+     880                 :            :  *                  the ECParameters record on exit.
+     881                 :            :  *
+     882                 :            :  * \param grp       The group context to setup. This must be initialized.
+     883                 :            :  * \param buf       The address of the pointer to the start of the input buffer.
+     884                 :            :  * \param len       The length of the input buffer \c *buf in Bytes.
+     885                 :            :  *
+     886                 :            :  * \return          \c 0 on success.
+     887                 :            :  * \return          #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if input is invalid.
+     888                 :            :  * \return          #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the group is not
+     889                 :            :  *                  recognized.
+     890                 :            :  * \return          Another negative error code on other kinds of failure.
+     891                 :            :  */
+     892                 :            : int mbedtls_ecp_tls_read_group(mbedtls_ecp_group *grp,
+     893                 :            :                                const unsigned char **buf, size_t len);
+     894                 :            : 
+     895                 :            : /**
+     896                 :            :  * \brief           This function extracts an elliptic curve group ID from a
+     897                 :            :  *                  TLS ECParameters record as defined in RFC 4492, Section 5.4.
+     898                 :            :  *
+     899                 :            :  * \note            The read pointer \p buf is updated to point right after
+     900                 :            :  *                  the ECParameters record on exit.
+     901                 :            :  *
+     902                 :            :  * \param grp       The address at which to store the group id.
+     903                 :            :  *                  This must not be \c NULL.
+     904                 :            :  * \param buf       The address of the pointer to the start of the input buffer.
+     905                 :            :  * \param len       The length of the input buffer \c *buf in Bytes.
+     906                 :            :  *
+     907                 :            :  * \return          \c 0 on success.
+     908                 :            :  * \return          #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if input is invalid.
+     909                 :            :  * \return          #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the group is not
+     910                 :            :  *                  recognized.
+     911                 :            :  * \return          Another negative error code on other kinds of failure.
+     912                 :            :  */
+     913                 :            : int mbedtls_ecp_tls_read_group_id(mbedtls_ecp_group_id *grp,
+     914                 :            :                                   const unsigned char **buf,
+     915                 :            :                                   size_t len);
+     916                 :            : /**
+     917                 :            :  * \brief           This function exports an elliptic curve as a TLS
+     918                 :            :  *                  ECParameters record as defined in RFC 4492, Section 5.4.
+     919                 :            :  *
+     920                 :            :  * \param grp       The ECP group to be exported.
+     921                 :            :  *                  This must be initialized and have group parameters
+     922                 :            :  *                  set, for example through mbedtls_ecp_group_load().
+     923                 :            :  * \param olen      The address at which to store the number of Bytes written.
+     924                 :            :  *                  This must not be \c NULL.
+     925                 :            :  * \param buf       The buffer to write to. This must be a writable buffer
+     926                 :            :  *                  of length \p blen Bytes.
+     927                 :            :  * \param blen      The length of the output buffer \p buf in Bytes.
+     928                 :            :  *
+     929                 :            :  * \return          \c 0 on success.
+     930                 :            :  * \return          #MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL if the output
+     931                 :            :  *                  buffer is too small to hold the exported group.
+     932                 :            :  * \return          Another negative error code on other kinds of failure.
+     933                 :            :  */
+     934                 :            : int mbedtls_ecp_tls_write_group(const mbedtls_ecp_group *grp,
+     935                 :            :                                 size_t *olen,
+     936                 :            :                                 unsigned char *buf, size_t blen);
+     937                 :            : 
+     938                 :            : /**
+     939                 :            :  * \brief           This function performs a scalar multiplication of a point
+     940                 :            :  *                  by an integer: \p R = \p m * \p P.
+     941                 :            :  *
+     942                 :            :  *                  It is not thread-safe to use same group in multiple threads.
+     943                 :            :  *
+     944                 :            :  * \note            To prevent timing attacks, this function
+     945                 :            :  *                  executes the exact same sequence of base-field
+     946                 :            :  *                  operations for any valid \p m. It avoids any if-branch or
+     947                 :            :  *                  array index depending on the value of \p m. It also uses
+     948                 :            :  *                  \p f_rng to randomize some intermediate results.
+     949                 :            :  *
+     950                 :            :  * \param grp       The ECP group to use.
+     951                 :            :  *                  This must be initialized and have group parameters
+     952                 :            :  *                  set, for example through mbedtls_ecp_group_load().
+     953                 :            :  * \param R         The point in which to store the result of the calculation.
+     954                 :            :  *                  This must be initialized.
+     955                 :            :  * \param m         The integer by which to multiply. This must be initialized.
+     956                 :            :  * \param P         The point to multiply. This must be initialized.
+     957                 :            :  * \param f_rng     The RNG function. This must not be \c NULL.
+     958                 :            :  * \param p_rng     The RNG context to be passed to \p f_rng. This may be \c
+     959                 :            :  *                  NULL if \p f_rng doesn't need a context.
+     960                 :            :  *
+     961                 :            :  * \return          \c 0 on success.
+     962                 :            :  * \return          #MBEDTLS_ERR_ECP_INVALID_KEY if \p m is not a valid private
+     963                 :            :  *                  key, or \p P is not a valid public key.
+     964                 :            :  * \return          #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure.
+     965                 :            :  * \return          Another negative error code on other kinds of failure.
+     966                 :            :  */
+     967                 :            : int mbedtls_ecp_mul(mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
+     968                 :            :                     const mbedtls_mpi *m, const mbedtls_ecp_point *P,
+     969                 :            :                     int (*f_rng)(void *, unsigned char *, size_t), void *p_rng);
+     970                 :            : 
+     971                 :            : /**
+     972                 :            :  * \brief           This function performs multiplication of a point by
+     973                 :            :  *                  an integer: \p R = \p m * \p P in a restartable way.
+     974                 :            :  *
+     975                 :            :  * \see             mbedtls_ecp_mul()
+     976                 :            :  *
+     977                 :            :  * \note            This function does the same as \c mbedtls_ecp_mul(), but
+     978                 :            :  *                  it can return early and restart according to the limit set
+     979                 :            :  *                  with \c mbedtls_ecp_set_max_ops() to reduce blocking.
+     980                 :            :  *
+     981                 :            :  * \param grp       The ECP group to use.
+     982                 :            :  *                  This must be initialized and have group parameters
+     983                 :            :  *                  set, for example through mbedtls_ecp_group_load().
+     984                 :            :  * \param R         The point in which to store the result of the calculation.
+     985                 :            :  *                  This must be initialized.
+     986                 :            :  * \param m         The integer by which to multiply. This must be initialized.
+     987                 :            :  * \param P         The point to multiply. This must be initialized.
+     988                 :            :  * \param f_rng     The RNG function. This must not be \c NULL.
+     989                 :            :  * \param p_rng     The RNG context to be passed to \p f_rng. This may be \c
+     990                 :            :  *                  NULL if \p f_rng doesn't need a context.
+     991                 :            :  * \param rs_ctx    The restart context (NULL disables restart).
+     992                 :            :  *
+     993                 :            :  * \return          \c 0 on success.
+     994                 :            :  * \return          #MBEDTLS_ERR_ECP_INVALID_KEY if \p m is not a valid private
+     995                 :            :  *                  key, or \p P is not a valid public key.
+     996                 :            :  * \return          #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure.
+     997                 :            :  * \return          #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of
+     998                 :            :  *                  operations was reached: see \c mbedtls_ecp_set_max_ops().
+     999                 :            :  * \return          Another negative error code on other kinds of failure.
+    1000                 :            :  */
+    1001                 :            : int mbedtls_ecp_mul_restartable(mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
+    1002                 :            :                                 const mbedtls_mpi *m, const mbedtls_ecp_point *P,
+    1003                 :            :                                 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
+    1004                 :            :                                 mbedtls_ecp_restart_ctx *rs_ctx);
+    1005                 :            : 
+    1006                 :            : #if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
+    1007                 :            : /**
+    1008                 :            :  * \brief           This function checks if domain parameter A of the curve is
+    1009                 :            :  *                  \c -3.
+    1010                 :            :  *
+    1011                 :            :  * \note            This function is only defined for short Weierstrass curves.
+    1012                 :            :  *                  It may not be included in builds without any short
+    1013                 :            :  *                  Weierstrass curve.
+    1014                 :            :  *
+    1015                 :            :  * \param grp       The ECP group to use.
+    1016                 :            :  *                  This must be initialized and have group parameters
+    1017                 :            :  *                  set, for example through mbedtls_ecp_group_load().
+    1018                 :            :  *
+    1019                 :            :  * \return          \c 1 if <code>A = -3</code>.
+    1020                 :            :  * \return          \c 0 Otherwise.
+    1021                 :            :  */
+    1022                 :     480691 : static inline int mbedtls_ecp_group_a_is_minus_3(const mbedtls_ecp_group *grp)
+    1023                 :            : {
+    1024                 :     480691 :     return grp->A.MBEDTLS_PRIVATE(p) == NULL;
+    1025                 :            : }
+    1026                 :            : 
+    1027                 :            : /**
+    1028                 :            :  * \brief           This function performs multiplication and addition of two
+    1029                 :            :  *                  points by integers: \p R = \p m * \p P + \p n * \p Q
+    1030                 :            :  *
+    1031                 :            :  *                  It is not thread-safe to use same group in multiple threads.
+    1032                 :            :  *
+    1033                 :            :  * \note            In contrast to mbedtls_ecp_mul(), this function does not
+    1034                 :            :  *                  guarantee a constant execution flow and timing.
+    1035                 :            :  *
+    1036                 :            :  * \note            This function is only defined for short Weierstrass curves.
+    1037                 :            :  *                  It may not be included in builds without any short
+    1038                 :            :  *                  Weierstrass curve.
+    1039                 :            :  *
+    1040                 :            :  * \param grp       The ECP group to use.
+    1041                 :            :  *                  This must be initialized and have group parameters
+    1042                 :            :  *                  set, for example through mbedtls_ecp_group_load().
+    1043                 :            :  * \param R         The point in which to store the result of the calculation.
+    1044                 :            :  *                  This must be initialized.
+    1045                 :            :  * \param m         The integer by which to multiply \p P.
+    1046                 :            :  *                  This must be initialized.
+    1047                 :            :  * \param P         The point to multiply by \p m. This must be initialized.
+    1048                 :            :  * \param n         The integer by which to multiply \p Q.
+    1049                 :            :  *                  This must be initialized.
+    1050                 :            :  * \param Q         The point to be multiplied by \p n.
+    1051                 :            :  *                  This must be initialized.
+    1052                 :            :  *
+    1053                 :            :  * \return          \c 0 on success.
+    1054                 :            :  * \return          #MBEDTLS_ERR_ECP_INVALID_KEY if \p m or \p n are not
+    1055                 :            :  *                  valid private keys, or \p P or \p Q are not valid public
+    1056                 :            :  *                  keys.
+    1057                 :            :  * \return          #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure.
+    1058                 :            :  * \return          #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if \p grp does not
+    1059                 :            :  *                  designate a short Weierstrass curve.
+    1060                 :            :  * \return          Another negative error code on other kinds of failure.
+    1061                 :            :  */
+    1062                 :            : int mbedtls_ecp_muladd(mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
+    1063                 :            :                        const mbedtls_mpi *m, const mbedtls_ecp_point *P,
+    1064                 :            :                        const mbedtls_mpi *n, const mbedtls_ecp_point *Q);
+    1065                 :            : 
+    1066                 :            : /**
+    1067                 :            :  * \brief           This function performs multiplication and addition of two
+    1068                 :            :  *                  points by integers: \p R = \p m * \p P + \p n * \p Q in a
+    1069                 :            :  *                  restartable way.
+    1070                 :            :  *
+    1071                 :            :  * \see             \c mbedtls_ecp_muladd()
+    1072                 :            :  *
+    1073                 :            :  * \note            This function works the same as \c mbedtls_ecp_muladd(),
+    1074                 :            :  *                  but it can return early and restart according to the limit
+    1075                 :            :  *                  set with \c mbedtls_ecp_set_max_ops() to reduce blocking.
+    1076                 :            :  *
+    1077                 :            :  * \note            This function is only defined for short Weierstrass curves.
+    1078                 :            :  *                  It may not be included in builds without any short
+    1079                 :            :  *                  Weierstrass curve.
+    1080                 :            :  *
+    1081                 :            :  * \param grp       The ECP group to use.
+    1082                 :            :  *                  This must be initialized and have group parameters
+    1083                 :            :  *                  set, for example through mbedtls_ecp_group_load().
+    1084                 :            :  * \param R         The point in which to store the result of the calculation.
+    1085                 :            :  *                  This must be initialized.
+    1086                 :            :  * \param m         The integer by which to multiply \p P.
+    1087                 :            :  *                  This must be initialized.
+    1088                 :            :  * \param P         The point to multiply by \p m. This must be initialized.
+    1089                 :            :  * \param n         The integer by which to multiply \p Q.
+    1090                 :            :  *                  This must be initialized.
+    1091                 :            :  * \param Q         The point to be multiplied by \p n.
+    1092                 :            :  *                  This must be initialized.
+    1093                 :            :  * \param rs_ctx    The restart context (NULL disables restart).
+    1094                 :            :  *
+    1095                 :            :  * \return          \c 0 on success.
+    1096                 :            :  * \return          #MBEDTLS_ERR_ECP_INVALID_KEY if \p m or \p n are not
+    1097                 :            :  *                  valid private keys, or \p P or \p Q are not valid public
+    1098                 :            :  *                  keys.
+    1099                 :            :  * \return          #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure.
+    1100                 :            :  * \return          #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if \p grp does not
+    1101                 :            :  *                  designate a short Weierstrass curve.
+    1102                 :            :  * \return          #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of
+    1103                 :            :  *                  operations was reached: see \c mbedtls_ecp_set_max_ops().
+    1104                 :            :  * \return          Another negative error code on other kinds of failure.
+    1105                 :            :  */
+    1106                 :            : int mbedtls_ecp_muladd_restartable(
+    1107                 :            :     mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
+    1108                 :            :     const mbedtls_mpi *m, const mbedtls_ecp_point *P,
+    1109                 :            :     const mbedtls_mpi *n, const mbedtls_ecp_point *Q,
+    1110                 :            :     mbedtls_ecp_restart_ctx *rs_ctx);
+    1111                 :            : #endif /* MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED */
+    1112                 :            : 
+    1113                 :            : /**
+    1114                 :            :  * \brief           This function checks that a point is a valid public key
+    1115                 :            :  *                  on this curve.
+    1116                 :            :  *
+    1117                 :            :  *                  It only checks that the point is non-zero, has
+    1118                 :            :  *                  valid coordinates and lies on the curve. It does not verify
+    1119                 :            :  *                  that it is indeed a multiple of \c G. This additional
+    1120                 :            :  *                  check is computationally more expensive, is not required
+    1121                 :            :  *                  by standards, and should not be necessary if the group
+    1122                 :            :  *                  used has a small cofactor. In particular, it is useless for
+    1123                 :            :  *                  the NIST groups which all have a cofactor of 1.
+    1124                 :            :  *
+    1125                 :            :  * \note            This function uses bare components rather than an
+    1126                 :            :  *                  ::mbedtls_ecp_keypair structure, to ease use with other
+    1127                 :            :  *                  structures, such as ::mbedtls_ecdh_context or
+    1128                 :            :  *                  ::mbedtls_ecdsa_context.
+    1129                 :            :  *
+    1130                 :            :  * \param grp       The ECP group the point should belong to.
+    1131                 :            :  *                  This must be initialized and have group parameters
+    1132                 :            :  *                  set, for example through mbedtls_ecp_group_load().
+    1133                 :            :  * \param pt        The point to check. This must be initialized.
+    1134                 :            :  *
+    1135                 :            :  * \return          \c 0 if the point is a valid public key.
+    1136                 :            :  * \return          #MBEDTLS_ERR_ECP_INVALID_KEY if the point is not
+    1137                 :            :  *                  a valid public key for the given curve.
+    1138                 :            :  * \return          Another negative error code on other kinds of failure.
+    1139                 :            :  */
+    1140                 :            : int mbedtls_ecp_check_pubkey(const mbedtls_ecp_group *grp,
+    1141                 :            :                              const mbedtls_ecp_point *pt);
+    1142                 :            : 
+    1143                 :            : /**
+    1144                 :            :  * \brief           This function checks that an \c mbedtls_mpi is a
+    1145                 :            :  *                  valid private key for this curve.
+    1146                 :            :  *
+    1147                 :            :  * \note            This function uses bare components rather than an
+    1148                 :            :  *                  ::mbedtls_ecp_keypair structure to ease use with other
+    1149                 :            :  *                  structures, such as ::mbedtls_ecdh_context or
+    1150                 :            :  *                  ::mbedtls_ecdsa_context.
+    1151                 :            :  *
+    1152                 :            :  * \param grp       The ECP group the private key should belong to.
+    1153                 :            :  *                  This must be initialized and have group parameters
+    1154                 :            :  *                  set, for example through mbedtls_ecp_group_load().
+    1155                 :            :  * \param d         The integer to check. This must be initialized.
+    1156                 :            :  *
+    1157                 :            :  * \return          \c 0 if the point is a valid private key.
+    1158                 :            :  * \return          #MBEDTLS_ERR_ECP_INVALID_KEY if the point is not a valid
+    1159                 :            :  *                  private key for the given curve.
+    1160                 :            :  * \return          Another negative error code on other kinds of failure.
+    1161                 :            :  */
+    1162                 :            : int mbedtls_ecp_check_privkey(const mbedtls_ecp_group *grp,
+    1163                 :            :                               const mbedtls_mpi *d);
+    1164                 :            : 
+    1165                 :            : /**
+    1166                 :            :  * \brief           This function generates a private key.
+    1167                 :            :  *
+    1168                 :            :  * \param grp       The ECP group to generate a private key for.
+    1169                 :            :  *                  This must be initialized and have group parameters
+    1170                 :            :  *                  set, for example through mbedtls_ecp_group_load().
+    1171                 :            :  * \param d         The destination MPI (secret part). This must be initialized.
+    1172                 :            :  * \param f_rng     The RNG function. This must not be \c NULL.
+    1173                 :            :  * \param p_rng     The RNG parameter to be passed to \p f_rng. This may be
+    1174                 :            :  *                  \c NULL if \p f_rng doesn't need a context argument.
+    1175                 :            :  *
+    1176                 :            :  * \return          \c 0 on success.
+    1177                 :            :  * \return          An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX error code
+    1178                 :            :  *                  on failure.
+    1179                 :            :  */
+    1180                 :            : int mbedtls_ecp_gen_privkey(const mbedtls_ecp_group *grp,
+    1181                 :            :                             mbedtls_mpi *d,
+    1182                 :            :                             int (*f_rng)(void *, unsigned char *, size_t),
+    1183                 :            :                             void *p_rng);
+    1184                 :            : 
+    1185                 :            : /**
+    1186                 :            :  * \brief           This function generates a keypair with a configurable base
+    1187                 :            :  *                  point.
+    1188                 :            :  *
+    1189                 :            :  * \note            This function uses bare components rather than an
+    1190                 :            :  *                  ::mbedtls_ecp_keypair structure to ease use with other
+    1191                 :            :  *                  structures, such as ::mbedtls_ecdh_context or
+    1192                 :            :  *                  ::mbedtls_ecdsa_context.
+    1193                 :            :  *
+    1194                 :            :  * \param grp       The ECP group to generate a key pair for.
+    1195                 :            :  *                  This must be initialized and have group parameters
+    1196                 :            :  *                  set, for example through mbedtls_ecp_group_load().
+    1197                 :            :  * \param G         The base point to use. This must be initialized
+    1198                 :            :  *                  and belong to \p grp. It replaces the default base
+    1199                 :            :  *                  point \c grp->G used by mbedtls_ecp_gen_keypair().
+    1200                 :            :  * \param d         The destination MPI (secret part).
+    1201                 :            :  *                  This must be initialized.
+    1202                 :            :  * \param Q         The destination point (public part).
+    1203                 :            :  *                  This must be initialized.
+    1204                 :            :  * \param f_rng     The RNG function. This must not be \c NULL.
+    1205                 :            :  * \param p_rng     The RNG context to be passed to \p f_rng. This may
+    1206                 :            :  *                  be \c NULL if \p f_rng doesn't need a context argument.
+    1207                 :            :  *
+    1208                 :            :  * \return          \c 0 on success.
+    1209                 :            :  * \return          An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX error code
+    1210                 :            :  *                  on failure.
+    1211                 :            :  */
+    1212                 :            : int mbedtls_ecp_gen_keypair_base(mbedtls_ecp_group *grp,
+    1213                 :            :                                  const mbedtls_ecp_point *G,
+    1214                 :            :                                  mbedtls_mpi *d, mbedtls_ecp_point *Q,
+    1215                 :            :                                  int (*f_rng)(void *, unsigned char *, size_t),
+    1216                 :            :                                  void *p_rng);
+    1217                 :            : 
+    1218                 :            : /**
+    1219                 :            :  * \brief           This function generates an ECP keypair.
+    1220                 :            :  *
+    1221                 :            :  * \note            This function uses bare components rather than an
+    1222                 :            :  *                  ::mbedtls_ecp_keypair structure to ease use with other
+    1223                 :            :  *                  structures, such as ::mbedtls_ecdh_context or
+    1224                 :            :  *                  ::mbedtls_ecdsa_context.
+    1225                 :            :  *
+    1226                 :            :  * \param grp       The ECP group to generate a key pair for.
+    1227                 :            :  *                  This must be initialized and have group parameters
+    1228                 :            :  *                  set, for example through mbedtls_ecp_group_load().
+    1229                 :            :  * \param d         The destination MPI (secret part).
+    1230                 :            :  *                  This must be initialized.
+    1231                 :            :  * \param Q         The destination point (public part).
+    1232                 :            :  *                  This must be initialized.
+    1233                 :            :  * \param f_rng     The RNG function. This must not be \c NULL.
+    1234                 :            :  * \param p_rng     The RNG context to be passed to \p f_rng. This may
+    1235                 :            :  *                  be \c NULL if \p f_rng doesn't need a context argument.
+    1236                 :            :  *
+    1237                 :            :  * \return          \c 0 on success.
+    1238                 :            :  * \return          An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX error code
+    1239                 :            :  *                  on failure.
+    1240                 :            :  */
+    1241                 :            : int mbedtls_ecp_gen_keypair(mbedtls_ecp_group *grp, mbedtls_mpi *d,
+    1242                 :            :                             mbedtls_ecp_point *Q,
+    1243                 :            :                             int (*f_rng)(void *, unsigned char *, size_t),
+    1244                 :            :                             void *p_rng);
+    1245                 :            : 
+    1246                 :            : /**
+    1247                 :            :  * \brief           This function generates an ECP key.
+    1248                 :            :  *
+    1249                 :            :  * \param grp_id    The ECP group identifier.
+    1250                 :            :  * \param key       The destination key. This must be initialized.
+    1251                 :            :  * \param f_rng     The RNG function to use. This must not be \c NULL.
+    1252                 :            :  * \param p_rng     The RNG context to be passed to \p f_rng. This may
+    1253                 :            :  *                  be \c NULL if \p f_rng doesn't need a context argument.
+    1254                 :            :  *
+    1255                 :            :  * \return          \c 0 on success.
+    1256                 :            :  * \return          An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX error code
+    1257                 :            :  *                  on failure.
+    1258                 :            :  */
+    1259                 :            : int mbedtls_ecp_gen_key(mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key,
+    1260                 :            :                         int (*f_rng)(void *, unsigned char *, size_t),
+    1261                 :            :                         void *p_rng);
+    1262                 :            : 
+    1263                 :            : /** \brief          Set the public key in a key pair object.
+    1264                 :            :  *
+    1265                 :            :  * \note            This function does not check that the point actually
+    1266                 :            :  *                  belongs to the given group. Call mbedtls_ecp_check_pubkey()
+    1267                 :            :  *                  on \p Q before calling this function to check that.
+    1268                 :            :  *
+    1269                 :            :  * \note            This function does not check that the public key matches
+    1270                 :            :  *                  the private key that is already in \p key, if any.
+    1271                 :            :  *                  To check the consistency of the resulting key pair object,
+    1272                 :            :  *                  call mbedtls_ecp_check_pub_priv() after setting both
+    1273                 :            :  *                  the public key and the private key.
+    1274                 :            :  *
+    1275                 :            :  * \param grp_id    The ECP group identifier.
+    1276                 :            :  * \param key       The key pair object. It must be initialized.
+    1277                 :            :  *                  If its group has already been set, it must match \p grp_id.
+    1278                 :            :  *                  If its group has not been set, it will be set to \p grp_id.
+    1279                 :            :  *                  If the public key has already been set, it is overwritten.
+    1280                 :            :  * \param Q         The public key to copy. This must be a point on the
+    1281                 :            :  *                  curve indicated by \p grp_id.
+    1282                 :            :  *
+    1283                 :            :  * \return          \c 0 on success.
+    1284                 :            :  * \return          #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if \p key does not
+    1285                 :            :  *                  match \p grp_id.
+    1286                 :            :  * \return          #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the operation for
+    1287                 :            :  *                  the group is not implemented.
+    1288                 :            :  * \return          #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure.
+    1289                 :            :  * \return          Another negative error code on other kinds of failure.
+    1290                 :            :  */
+    1291                 :            : int mbedtls_ecp_set_public_key(mbedtls_ecp_group_id grp_id,
+    1292                 :            :                                mbedtls_ecp_keypair *key,
+    1293                 :            :                                const mbedtls_ecp_point *Q);
+    1294                 :            : 
+    1295                 :            : /**
+    1296                 :            :  * \brief           This function reads an elliptic curve private key.
+    1297                 :            :  *
+    1298                 :            :  * \note            This function does not set the public key in the
+    1299                 :            :  *                  key pair object. Without a public key, the key pair object
+    1300                 :            :  *                  cannot be used with operations that require the public key.
+    1301                 :            :  *                  Call mbedtls_ecp_keypair_calc_public() to set the public
+    1302                 :            :  *                  key from the private key. Alternatively, you can call
+    1303                 :            :  *                  mbedtls_ecp_set_public_key() to set the public key part,
+    1304                 :            :  *                  and then optionally mbedtls_ecp_check_pub_priv() to check
+    1305                 :            :  *                  that the private and public parts are consistent.
+    1306                 :            :  *
+    1307                 :            :  * \note            If a public key has already been set in the key pair
+    1308                 :            :  *                  object, this function does not check that it is consistent
+    1309                 :            :  *                  with the private key. Call mbedtls_ecp_check_pub_priv()
+    1310                 :            :  *                  after setting both the public key and the private key
+    1311                 :            :  *                  to make that check.
+    1312                 :            :  *
+    1313                 :            :  * \param grp_id    The ECP group identifier.
+    1314                 :            :  * \param key       The destination key.
+    1315                 :            :  * \param buf       The buffer containing the binary representation of the
+    1316                 :            :  *                  key. (Big endian integer for Weierstrass curves, byte
+    1317                 :            :  *                  string for Montgomery curves.)
+    1318                 :            :  * \param buflen    The length of the buffer in bytes.
+    1319                 :            :  *
+    1320                 :            :  * \return          \c 0 on success.
+    1321                 :            :  * \return          #MBEDTLS_ERR_ECP_INVALID_KEY error if the key is
+    1322                 :            :  *                  invalid.
+    1323                 :            :  * \return          #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed.
+    1324                 :            :  * \return          #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the operation for
+    1325                 :            :  *                  the group is not implemented.
+    1326                 :            :  * \return          Another negative error code on different kinds of failure.
+    1327                 :            :  */
+    1328                 :            : int mbedtls_ecp_read_key(mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key,
+    1329                 :            :                          const unsigned char *buf, size_t buflen);
+    1330                 :            : 
+    1331                 :            : #if !defined(MBEDTLS_DEPRECATED_REMOVED)
+    1332                 :            : /**
+    1333                 :            :  * \brief           This function exports an elliptic curve private key.
+    1334                 :            :  *
+    1335                 :            :  * \deprecated      Note that although this function accepts an output
+    1336                 :            :  *                  buffer that is smaller or larger than the key, most key
+    1337                 :            :  *                  import interfaces require the output to have exactly
+    1338                 :            :  *                  key's nominal length. It is generally simplest to
+    1339                 :            :  *                  pass the key's nominal length as \c buflen, after
+    1340                 :            :  *                  checking that the output buffer is large enough.
+    1341                 :            :  *                  See the description of the \p buflen parameter for
+    1342                 :            :  *                  how to calculate the nominal length.
+    1343                 :            :  *                  To avoid this difficulty, use mbedtls_ecp_write_key_ext()
+    1344                 :            :  *                  instead.
+    1345                 :            :  *                  mbedtls_ecp_write_key() is deprecated and will be
+    1346                 :            :  *                  removed in a future version of the library.
+    1347                 :            :  *
+    1348                 :            :  * \note            If the private key was not set in \p key,
+    1349                 :            :  *                  the output is unspecified. Future versions
+    1350                 :            :  *                  may return an error in that case.
+    1351                 :            :  *
+    1352                 :            :  * \param key       The private key.
+    1353                 :            :  * \param buf       The output buffer for containing the binary representation
+    1354                 :            :  *                  of the key.
+    1355                 :            :  *                  For Weierstrass curves, this is the big-endian
+    1356                 :            :  *                  representation, padded with null bytes at the beginning
+    1357                 :            :  *                  to reach \p buflen bytes.
+    1358                 :            :  *                  For Montgomery curves, this is the standard byte string
+    1359                 :            :  *                  representation (which is little-endian), padded with
+    1360                 :            :  *                  null bytes at the end to reach \p buflen bytes.
+    1361                 :            :  * \param buflen    The total length of the buffer in bytes.
+    1362                 :            :  *                  The length of the output is
+    1363                 :            :  *                  (`grp->nbits` + 7) / 8 bytes
+    1364                 :            :  *                  where `grp->nbits` is the private key size in bits.
+    1365                 :            :  *                  For Weierstrass keys, if the output buffer is smaller,
+    1366                 :            :  *                  leading zeros are trimmed to fit if possible. For
+    1367                 :            :  *                  Montgomery keys, the output buffer must always be large
+    1368                 :            :  *                  enough for the nominal length.
+    1369                 :            :  *
+    1370                 :            :  * \return          \c 0 on success.
+    1371                 :            :  * \return          #MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL or
+    1372                 :            :  *                  #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if the \p key
+    1373                 :            :  *                  representation is larger than the available space in \p buf.
+    1374                 :            :  * \return          Another negative error code on different kinds of failure.
+    1375                 :            :  */
+    1376                 :            : int MBEDTLS_DEPRECATED mbedtls_ecp_write_key(mbedtls_ecp_keypair *key,
+    1377                 :            :                                              unsigned char *buf, size_t buflen);
+    1378                 :            : #endif /* MBEDTLS_DEPRECATED_REMOVED */
+    1379                 :            : 
+    1380                 :            : /**
+    1381                 :            :  * \brief           This function exports an elliptic curve private key.
+    1382                 :            :  *
+    1383                 :            :  * \param key       The private key.
+    1384                 :            :  * \param olen      On success, the length of the private key.
+    1385                 :            :  *                  This is always (`grp->nbits` + 7) / 8 bytes
+    1386                 :            :  *                  where `grp->nbits` is the private key size in bits.
+    1387                 :            :  * \param buf       The output buffer for containing the binary representation
+    1388                 :            :  *                  of the key.
+    1389                 :            :  * \param buflen    The total length of the buffer in bytes.
+    1390                 :            :  *                  #MBEDTLS_ECP_MAX_BYTES is always sufficient.
+    1391                 :            :  *
+    1392                 :            :  * \return          \c 0 on success.
+    1393                 :            :  * \return          #MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL if the \p key
+    1394                 :            :  *                  representation is larger than the available space in \p buf.
+    1395                 :            :  * \return          #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if no private key is
+    1396                 :            :  *                  set in \p key.
+    1397                 :            :  * \return          Another negative error code on different kinds of failure.
+    1398                 :            :  */
+    1399                 :            : int mbedtls_ecp_write_key_ext(const mbedtls_ecp_keypair *key,
+    1400                 :            :                               size_t *olen, unsigned char *buf, size_t buflen);
+    1401                 :            : 
+    1402                 :            : /**
+    1403                 :            :  * \brief           This function exports an elliptic curve public key.
+    1404                 :            :  *
+    1405                 :            :  * \note            If the public key was not set in \p key,
+    1406                 :            :  *                  the output is unspecified. Future versions
+    1407                 :            :  *                  may return an error in that case.
+    1408                 :            :  *
+    1409                 :            :  * \param key       The public key.
+    1410                 :            :  * \param format    The point format. This must be either
+    1411                 :            :  *                  #MBEDTLS_ECP_PF_COMPRESSED or #MBEDTLS_ECP_PF_UNCOMPRESSED.
+    1412                 :            :  *                  (For groups without these formats, this parameter is
+    1413                 :            :  *                  ignored. But it still has to be either of the above
+    1414                 :            :  *                  values.)
+    1415                 :            :  * \param olen      The address at which to store the length of
+    1416                 :            :  *                  the output in Bytes. This must not be \c NULL.
+    1417                 :            :  * \param buf       The output buffer. This must be a writable buffer
+    1418                 :            :  *                  of length \p buflen Bytes.
+    1419                 :            :  * \param buflen    The length of the output buffer \p buf in Bytes.
+    1420                 :            :  *
+    1421                 :            :  * \return          \c 0 on success.
+    1422                 :            :  * \return          #MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL if the output buffer
+    1423                 :            :  *                  is too small to hold the point.
+    1424                 :            :  * \return          #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the point format
+    1425                 :            :  *                  or the export for the given group is not implemented.
+    1426                 :            :  * \return          Another negative error code on other kinds of failure.
+    1427                 :            :  */
+    1428                 :            : int mbedtls_ecp_write_public_key(const mbedtls_ecp_keypair *key,
+    1429                 :            :                                  int format, size_t *olen,
+    1430                 :            :                                  unsigned char *buf, size_t buflen);
+    1431                 :            : 
+    1432                 :            : /**
+    1433                 :            :  * \brief           This function checks that the keypair objects
+    1434                 :            :  *                  \p pub and \p prv have the same group and the
+    1435                 :            :  *                  same public point, and that the private key in
+    1436                 :            :  *                  \p prv is consistent with the public key.
+    1437                 :            :  *
+    1438                 :            :  * \param pub       The keypair structure holding the public key. This
+    1439                 :            :  *                  must be initialized. If it contains a private key, that
+    1440                 :            :  *                  part is ignored.
+    1441                 :            :  * \param prv       The keypair structure holding the full keypair.
+    1442                 :            :  *                  This must be initialized.
+    1443                 :            :  * \param f_rng     The RNG function. This must not be \c NULL.
+    1444                 :            :  * \param p_rng     The RNG context to be passed to \p f_rng. This may be \c
+    1445                 :            :  *                  NULL if \p f_rng doesn't need a context.
+    1446                 :            :  *
+    1447                 :            :  * \return          \c 0 on success, meaning that the keys are valid and match.
+    1448                 :            :  * \return          #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if the keys are invalid or do not match.
+    1449                 :            :  * \return          An \c MBEDTLS_ERR_ECP_XXX or an \c MBEDTLS_ERR_MPI_XXX
+    1450                 :            :  *                  error code on calculation failure.
+    1451                 :            :  */
+    1452                 :            : int mbedtls_ecp_check_pub_priv(
+    1453                 :            :     const mbedtls_ecp_keypair *pub, const mbedtls_ecp_keypair *prv,
+    1454                 :            :     int (*f_rng)(void *, unsigned char *, size_t), void *p_rng);
+    1455                 :            : 
+    1456                 :            : /** \brief          Calculate the public key from a private key in a key pair.
+    1457                 :            :  *
+    1458                 :            :  * \param key       A keypair structure. It must have a private key set.
+    1459                 :            :  *                  If the public key is set, it will be overwritten.
+    1460                 :            :  * \param f_rng     The RNG function. This must not be \c NULL.
+    1461                 :            :  * \param p_rng     The RNG context to be passed to \p f_rng. This may be \c
+    1462                 :            :  *                  NULL if \p f_rng doesn't need a context.
+    1463                 :            :  *
+    1464                 :            :  * \return          \c 0 on success. The key pair object can be used for
+    1465                 :            :  *                  operations that require the public key.
+    1466                 :            :  * \return          An \c MBEDTLS_ERR_ECP_XXX or an \c MBEDTLS_ERR_MPI_XXX
+    1467                 :            :  *                  error code on calculation failure.
+    1468                 :            :  */
+    1469                 :            : int mbedtls_ecp_keypair_calc_public(
+    1470                 :            :     mbedtls_ecp_keypair *key,
+    1471                 :            :     int (*f_rng)(void *, unsigned char *, size_t), void *p_rng);
+    1472                 :            : 
+    1473                 :            : /** \brief          Query the group that a key pair belongs to.
+    1474                 :            :  *
+    1475                 :            :  * \param key       The key pair to query.
+    1476                 :            :  *
+    1477                 :            :  * \return          The group ID for the group registered in the key pair
+    1478                 :            :  *                  object.
+    1479                 :            :  *                  This is \c MBEDTLS_ECP_DP_NONE if no group has been set
+    1480                 :            :  *                  in the key pair object.
+    1481                 :            :  */
+    1482                 :            : mbedtls_ecp_group_id mbedtls_ecp_keypair_get_group_id(
+    1483                 :            :     const mbedtls_ecp_keypair *key);
+    1484                 :            : 
+    1485                 :            : /**
+    1486                 :            :  * \brief           This function exports generic key-pair parameters.
+    1487                 :            :  *
+    1488                 :            :  *                  Each of the output parameters can be a null pointer
+    1489                 :            :  *                  if you do not need that parameter.
+    1490                 :            :  *
+    1491                 :            :  * \note            If the private key or the public key was not set in \p key,
+    1492                 :            :  *                  the corresponding output is unspecified. Future versions
+    1493                 :            :  *                  may return an error in that case.
+    1494                 :            :  *
+    1495                 :            :  * \param key       The key pair to export from.
+    1496                 :            :  * \param grp       Slot for exported ECP group.
+    1497                 :            :  *                  It must either be null or point to an initialized ECP group.
+    1498                 :            :  * \param d         Slot for the exported secret value.
+    1499                 :            :  *                  It must either be null or point to an initialized mpi.
+    1500                 :            :  * \param Q         Slot for the exported public value.
+    1501                 :            :  *                  It must either be null or point to an initialized ECP point.
+    1502                 :            :  *
+    1503                 :            :  * \return          \c 0 on success,
+    1504                 :            :  * \return          #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure.
+    1505                 :            :  * \return          #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if key id doesn't
+    1506                 :            :  *                  correspond to a known group.
+    1507                 :            :  * \return          Another negative error code on other kinds of failure.
+    1508                 :            :  */
+    1509                 :            : int mbedtls_ecp_export(const mbedtls_ecp_keypair *key, mbedtls_ecp_group *grp,
+    1510                 :            :                        mbedtls_mpi *d, mbedtls_ecp_point *Q);
+    1511                 :            : 
+    1512                 :            : #if defined(MBEDTLS_SELF_TEST)
+    1513                 :            : 
+    1514                 :            : /**
+    1515                 :            :  * \brief          The ECP checkup routine.
+    1516                 :            :  *
+    1517                 :            :  * \return         \c 0 on success.
+    1518                 :            :  * \return         \c 1 on failure.
+    1519                 :            :  */
+    1520                 :            : int mbedtls_ecp_self_test(int verbose);
+    1521                 :            : 
+    1522                 :            : #endif /* MBEDTLS_SELF_TEST */
+    1523                 :            : 
+    1524                 :            : #ifdef __cplusplus
+    1525                 :            : }
+    1526                 :            : #endif
+    1527                 :            : 
+    1528                 :            : #endif /* ecp.h */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/error.h.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/error.h.func-sort-c.html new file mode 100644 index 00000000000..01a05346d59 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/error.h.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/include/mbedtls/error.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/include/mbedtls - error.h (source / functions)HitTotalCoverage
Test:coverage.infoLines:020.0 %
Date:2024-09-22 08:21:07Functions:010.0 %
Branches:00-
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_error_add0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/error.h.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/error.h.func.html new file mode 100644 index 00000000000..a3defa19bb4 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/error.h.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/include/mbedtls/error.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/include/mbedtls - error.h (source / functions)HitTotalCoverage
Test:coverage.infoLines:020.0 %
Date:2024-09-22 08:21:07Functions:010.0 %
Branches:00-
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_error_add0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/error.h.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/error.h.gcov.html new file mode 100644 index 00000000000..4059e24cc1a --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/error.h.gcov.html @@ -0,0 +1,286 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/include/mbedtls/error.h + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/include/mbedtls - error.h (source / functions)HitTotalCoverage
Test:coverage.infoLines:020.0 %
Date:2024-09-22 08:21:07Functions:010.0 %
Branches:00-
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  * \file error.h
+       3                 :            :  *
+       4                 :            :  * \brief Error to string translation
+       5                 :            :  */
+       6                 :            : /*
+       7                 :            :  *  Copyright The Mbed TLS Contributors
+       8                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       9                 :            :  */
+      10                 :            : #ifndef MBEDTLS_ERROR_H
+      11                 :            : #define MBEDTLS_ERROR_H
+      12                 :            : 
+      13                 :            : #include "mbedtls/build_info.h"
+      14                 :            : 
+      15                 :            : #include <stddef.h>
+      16                 :            : 
+      17                 :            : /**
+      18                 :            :  * Error code layout.
+      19                 :            :  *
+      20                 :            :  * Currently we try to keep all error codes within the negative space of 16
+      21                 :            :  * bits signed integers to support all platforms (-0x0001 - -0x7FFF). In
+      22                 :            :  * addition we'd like to give two layers of information on the error if
+      23                 :            :  * possible.
+      24                 :            :  *
+      25                 :            :  * For that purpose the error codes are segmented in the following manner:
+      26                 :            :  *
+      27                 :            :  * 16 bit error code bit-segmentation
+      28                 :            :  *
+      29                 :            :  * 1 bit  - Unused (sign bit)
+      30                 :            :  * 3 bits - High level module ID
+      31                 :            :  * 5 bits - Module-dependent error code
+      32                 :            :  * 7 bits - Low level module errors
+      33                 :            :  *
+      34                 :            :  * For historical reasons, low-level error codes are divided in even and odd,
+      35                 :            :  * even codes were assigned first, and -1 is reserved for other errors.
+      36                 :            :  *
+      37                 :            :  * Low-level module errors (0x0002-0x007E, 0x0001-0x007F)
+      38                 :            :  *
+      39                 :            :  * Module   Nr  Codes assigned
+      40                 :            :  * ERROR     2  0x006E          0x0001
+      41                 :            :  * MPI       7  0x0002-0x0010
+      42                 :            :  * GCM       3  0x0012-0x0016   0x0013-0x0013
+      43                 :            :  * THREADING 3  0x001A-0x001E
+      44                 :            :  * AES       5  0x0020-0x0022   0x0021-0x0025
+      45                 :            :  * CAMELLIA  3  0x0024-0x0026   0x0027-0x0027
+      46                 :            :  * BASE64    2  0x002A-0x002C
+      47                 :            :  * OID       1  0x002E-0x002E   0x000B-0x000B
+      48                 :            :  * PADLOCK   1  0x0030-0x0030
+      49                 :            :  * DES       2  0x0032-0x0032   0x0033-0x0033
+      50                 :            :  * CTR_DBRG  4  0x0034-0x003A
+      51                 :            :  * ENTROPY   3  0x003C-0x0040   0x003D-0x003F
+      52                 :            :  * NET      13  0x0042-0x0052   0x0043-0x0049
+      53                 :            :  * ARIA      4  0x0058-0x005E
+      54                 :            :  * ASN1      7  0x0060-0x006C
+      55                 :            :  * CMAC      1  0x007A-0x007A
+      56                 :            :  * PBKDF2    1  0x007C-0x007C
+      57                 :            :  * HMAC_DRBG 4                  0x0003-0x0009
+      58                 :            :  * CCM       3                  0x000D-0x0011
+      59                 :            :  * MD5       1                  0x002F-0x002F
+      60                 :            :  * RIPEMD160 1                  0x0031-0x0031
+      61                 :            :  * SHA1      1                  0x0035-0x0035 0x0073-0x0073
+      62                 :            :  * SHA256    1                  0x0037-0x0037 0x0074-0x0074
+      63                 :            :  * SHA512    1                  0x0039-0x0039 0x0075-0x0075
+      64                 :            :  * SHA-3     1                  0x0076-0x0076
+      65                 :            :  * CHACHA20  3                  0x0051-0x0055
+      66                 :            :  * POLY1305  3                  0x0057-0x005B
+      67                 :            :  * CHACHAPOLY 2 0x0054-0x0056
+      68                 :            :  * PLATFORM  2  0x0070-0x0072
+      69                 :            :  * LMS       5  0x0011-0x0019
+      70                 :            :  *
+      71                 :            :  * High-level module nr (3 bits - 0x0...-0x7...)
+      72                 :            :  * Name      ID  Nr of Errors
+      73                 :            :  * PEM       1   9
+      74                 :            :  * PKCS#12   1   4 (Started from top)
+      75                 :            :  * X509      2   20
+      76                 :            :  * PKCS5     2   4 (Started from top)
+      77                 :            :  * DHM       3   11
+      78                 :            :  * PK        3   15 (Started from top)
+      79                 :            :  * RSA       4   11
+      80                 :            :  * ECP       4   10 (Started from top)
+      81                 :            :  * MD        5   5
+      82                 :            :  * HKDF      5   1 (Started from top)
+      83                 :            :  * PKCS7     5   12 (Started from 0x5300)
+      84                 :            :  * SSL       5   2 (Started from 0x5F00)
+      85                 :            :  * CIPHER    6   8 (Started from 0x6080)
+      86                 :            :  * SSL       6   22 (Started from top, plus 0x6000)
+      87                 :            :  * SSL       7   20 (Started from 0x7000, gaps at
+      88                 :            :  *                   0x7380, 0x7900-0x7980, 0x7A80-0x7E80)
+      89                 :            :  *
+      90                 :            :  * Module dependent error code (5 bits 0x.00.-0x.F8.)
+      91                 :            :  */
+      92                 :            : 
+      93                 :            : #ifdef __cplusplus
+      94                 :            : extern "C" {
+      95                 :            : #endif
+      96                 :            : 
+      97                 :            : /** Generic error */
+      98                 :            : #define MBEDTLS_ERR_ERROR_GENERIC_ERROR       -0x0001
+      99                 :            : /** This is a bug in the library */
+     100                 :            : #define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
+     101                 :            : 
+     102                 :            : /** Hardware accelerator failed */
+     103                 :            : #define MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED     -0x0070
+     104                 :            : /** The requested feature is not supported by the platform */
+     105                 :            : #define MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED -0x0072
+     106                 :            : 
+     107                 :            : /**
+     108                 :            :  * \brief Combines a high-level and low-level error code together.
+     109                 :            :  *
+     110                 :            :  *        Wrapper macro for mbedtls_error_add(). See that function for
+     111                 :            :  *        more details.
+     112                 :            :  */
+     113                 :            : #define MBEDTLS_ERROR_ADD(high, low) \
+     114                 :            :     mbedtls_error_add(high, low, __FILE__, __LINE__)
+     115                 :            : 
+     116                 :            : #if defined(MBEDTLS_TEST_HOOKS)
+     117                 :            : /**
+     118                 :            :  * \brief Testing hook called before adding/combining two error codes together.
+     119                 :            :  *        Only used when invasive testing is enabled via MBEDTLS_TEST_HOOKS.
+     120                 :            :  */
+     121                 :            : extern void (*mbedtls_test_hook_error_add)(int, int, const char *, int);
+     122                 :            : #endif
+     123                 :            : 
+     124                 :            : /**
+     125                 :            :  * \brief Combines a high-level and low-level error code together.
+     126                 :            :  *
+     127                 :            :  *        This function can be called directly however it is usually
+     128                 :            :  *        called via the #MBEDTLS_ERROR_ADD macro.
+     129                 :            :  *
+     130                 :            :  *        While a value of zero is not a negative error code, it is still an
+     131                 :            :  *        error code (that denotes success) and can be combined with both a
+     132                 :            :  *        negative error code or another value of zero.
+     133                 :            :  *
+     134                 :            :  * \note  When invasive testing is enabled via #MBEDTLS_TEST_HOOKS, also try to
+     135                 :            :  *        call \link mbedtls_test_hook_error_add \endlink.
+     136                 :            :  *
+     137                 :            :  * \param high      high-level error code. See error.h for more details.
+     138                 :            :  * \param low       low-level error code. See error.h for more details.
+     139                 :            :  * \param file      file where this error code addition occurred.
+     140                 :            :  * \param line      line where this error code addition occurred.
+     141                 :            :  */
+     142                 :          0 : static inline int mbedtls_error_add(int high, int low,
+     143                 :            :                                     const char *file, int line)
+     144                 :            : {
+     145                 :            : #if defined(MBEDTLS_TEST_HOOKS)
+     146                 :            :     if (*mbedtls_test_hook_error_add != NULL) {
+     147                 :            :         (*mbedtls_test_hook_error_add)(high, low, file, line);
+     148                 :            :     }
+     149                 :            : #endif
+     150                 :            :     (void) file;
+     151                 :            :     (void) line;
+     152                 :            : 
+     153                 :          0 :     return high + low;
+     154                 :            : }
+     155                 :            : 
+     156                 :            : /**
+     157                 :            :  * \brief Translate an Mbed TLS error code into a string representation.
+     158                 :            :  *        The result is truncated if necessary and always includes a
+     159                 :            :  *        terminating null byte.
+     160                 :            :  *
+     161                 :            :  * \param errnum    error code
+     162                 :            :  * \param buffer    buffer to place representation in
+     163                 :            :  * \param buflen    length of the buffer
+     164                 :            :  */
+     165                 :            : void mbedtls_strerror(int errnum, char *buffer, size_t buflen);
+     166                 :            : 
+     167                 :            : /**
+     168                 :            :  * \brief Translate the high-level part of an Mbed TLS error code into a string
+     169                 :            :  *        representation.
+     170                 :            :  *
+     171                 :            :  * This function returns a const pointer to an un-modifiable string. The caller
+     172                 :            :  * must not try to modify the string. It is intended to be used mostly for
+     173                 :            :  * logging purposes.
+     174                 :            :  *
+     175                 :            :  * \param error_code    error code
+     176                 :            :  *
+     177                 :            :  * \return The string representation of the error code, or \c NULL if the error
+     178                 :            :  *         code is unknown.
+     179                 :            :  */
+     180                 :            : const char *mbedtls_high_level_strerr(int error_code);
+     181                 :            : 
+     182                 :            : /**
+     183                 :            :  * \brief Translate the low-level part of an Mbed TLS error code into a string
+     184                 :            :  *        representation.
+     185                 :            :  *
+     186                 :            :  * This function returns a const pointer to an un-modifiable string. The caller
+     187                 :            :  * must not try to modify the string. It is intended to be used mostly for
+     188                 :            :  * logging purposes.
+     189                 :            :  *
+     190                 :            :  * \param error_code    error code
+     191                 :            :  *
+     192                 :            :  * \return The string representation of the error code, or \c NULL if the error
+     193                 :            :  *         code is unknown.
+     194                 :            :  */
+     195                 :            : const char *mbedtls_low_level_strerr(int error_code);
+     196                 :            : 
+     197                 :            : #ifdef __cplusplus
+     198                 :            : }
+     199                 :            : #endif
+     200                 :            : 
+     201                 :            : #endif /* error.h */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/index-sort-b.html b/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/index-sort-b.html new file mode 100644 index 00000000000..aa955f594ac --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/index-sort-b.html @@ -0,0 +1,155 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/include/mbedtls + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/include/mbedtlsHitTotalCoverage
Test:coverage.infoLines:214250.0 %
Date:2024-09-22 08:21:07Functions:71163.6 %
Branches:51631.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
cipher.h +
40.9%40.9%
+
40.9 %9 / 2260.0 %3 / 525.0 %3 / 12
pk.h +
57.1%57.1%
+
57.1 %8 / 1466.7 %2 / 350.0 %2 / 4
error.h +
0.0%
+
0.0 %0 / 20.0 %0 / 1-0 / 0
md.h +
100.0%
+
100.0 %2 / 2100.0 %1 / 1-0 / 0
ecp.h +
100.0%
+
100.0 %2 / 2100.0 %1 / 1-0 / 0
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/index-sort-f.html b/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/index-sort-f.html new file mode 100644 index 00000000000..b8228819063 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/index-sort-f.html @@ -0,0 +1,155 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/include/mbedtls + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/include/mbedtlsHitTotalCoverage
Test:coverage.infoLines:214250.0 %
Date:2024-09-22 08:21:07Functions:71163.6 %
Branches:51631.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
error.h +
0.0%
+
0.0 %0 / 20.0 %0 / 1-0 / 0
cipher.h +
40.9%40.9%
+
40.9 %9 / 2260.0 %3 / 525.0 %3 / 12
pk.h +
57.1%57.1%
+
57.1 %8 / 1466.7 %2 / 350.0 %2 / 4
md.h +
100.0%
+
100.0 %2 / 2100.0 %1 / 1-0 / 0
ecp.h +
100.0%
+
100.0 %2 / 2100.0 %1 / 1-0 / 0
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/index-sort-l.html b/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/index-sort-l.html new file mode 100644 index 00000000000..8156e9e5256 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/index-sort-l.html @@ -0,0 +1,155 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/include/mbedtls + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/include/mbedtlsHitTotalCoverage
Test:coverage.infoLines:214250.0 %
Date:2024-09-22 08:21:07Functions:71163.6 %
Branches:51631.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
error.h +
0.0%
+
0.0 %0 / 20.0 %0 / 1-0 / 0
cipher.h +
40.9%40.9%
+
40.9 %9 / 2260.0 %3 / 525.0 %3 / 12
pk.h +
57.1%57.1%
+
57.1 %8 / 1466.7 %2 / 350.0 %2 / 4
md.h +
100.0%
+
100.0 %2 / 2100.0 %1 / 1-0 / 0
ecp.h +
100.0%
+
100.0 %2 / 2100.0 %1 / 1-0 / 0
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/index.html b/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/index.html new file mode 100644 index 00000000000..94528021114 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/index.html @@ -0,0 +1,155 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/include/mbedtls + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/include/mbedtlsHitTotalCoverage
Test:coverage.infoLines:214250.0 %
Date:2024-09-22 08:21:07Functions:71163.6 %
Branches:51631.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
cipher.h +
40.9%40.9%
+
40.9 %9 / 2260.0 %3 / 525.0 %3 / 12
ecp.h +
100.0%
+
100.0 %2 / 2100.0 %1 / 1-0 / 0
error.h +
0.0%
+
0.0 %0 / 20.0 %0 / 1-0 / 0
md.h +
100.0%
+
100.0 %2 / 2100.0 %1 / 1-0 / 0
pk.h +
57.1%57.1%
+
57.1 %8 / 1466.7 %2 / 350.0 %2 / 4
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/md.h.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/md.h.func-sort-c.html new file mode 100644 index 00000000000..3b10faa8b0d --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/md.h.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/include/mbedtls/md.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/include/mbedtls - md.h (source / functions)HitTotalCoverage
Test:coverage.infoLines:22100.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_md_get_size_from_type311
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/md.h.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/md.h.func.html new file mode 100644 index 00000000000..fe646e48f37 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/md.h.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/include/mbedtls/md.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/include/mbedtls - md.h (source / functions)HitTotalCoverage
Test:coverage.infoLines:22100.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_md_get_size_from_type311
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/md.h.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/md.h.gcov.html new file mode 100644 index 00000000000..de96010b57c --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/md.h.gcov.html @@ -0,0 +1,611 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/include/mbedtls/md.h + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/include/mbedtls - md.h (source / functions)HitTotalCoverage
Test:coverage.infoLines:22100.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:00-
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  * \file md.h
+       3                 :            :  *
+       4                 :            :  * \brief   This file contains the generic functions for message-digest
+       5                 :            :  *          (hashing) and HMAC.
+       6                 :            :  *
+       7                 :            :  * \author Adriaan de Jong <dejong@fox-it.com>
+       8                 :            :  */
+       9                 :            : /*
+      10                 :            :  *  Copyright The Mbed TLS Contributors
+      11                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+      12                 :            :  */
+      13                 :            : 
+      14                 :            : #ifndef MBEDTLS_MD_H
+      15                 :            : #define MBEDTLS_MD_H
+      16                 :            : #include "mbedtls/private_access.h"
+      17                 :            : 
+      18                 :            : #include <stddef.h>
+      19                 :            : 
+      20                 :            : #include "mbedtls/build_info.h"
+      21                 :            : #include "mbedtls/platform_util.h"
+      22                 :            : 
+      23                 :            : /** The selected feature is not available. */
+      24                 :            : #define MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE                -0x5080
+      25                 :            : /** Bad input parameters to function. */
+      26                 :            : #define MBEDTLS_ERR_MD_BAD_INPUT_DATA                     -0x5100
+      27                 :            : /** Failed to allocate memory. */
+      28                 :            : #define MBEDTLS_ERR_MD_ALLOC_FAILED                       -0x5180
+      29                 :            : /** Opening or reading of file failed. */
+      30                 :            : #define MBEDTLS_ERR_MD_FILE_IO_ERROR                      -0x5200
+      31                 :            : 
+      32                 :            : #ifdef __cplusplus
+      33                 :            : extern "C" {
+      34                 :            : #endif
+      35                 :            : 
+      36                 :            : /**
+      37                 :            :  * \brief     Supported message digests.
+      38                 :            :  *
+      39                 :            :  * \warning   MD5 and SHA-1 are considered weak message digests and
+      40                 :            :  *            their use constitutes a security risk. We recommend considering
+      41                 :            :  *            stronger message digests instead.
+      42                 :            :  *
+      43                 :            :  */
+      44                 :            : /* Note: these are aligned with the definitions of PSA_ALG_ macros for hashes,
+      45                 :            :  * in order to enable an efficient implementation of conversion functions.
+      46                 :            :  * This is tested by md_to_from_psa() in test_suite_md. */
+      47                 :            : typedef enum {
+      48                 :            :     MBEDTLS_MD_NONE=0,    /**< None. */
+      49                 :            :     MBEDTLS_MD_MD5=0x03,       /**< The MD5 message digest. */
+      50                 :            :     MBEDTLS_MD_RIPEMD160=0x04, /**< The RIPEMD-160 message digest. */
+      51                 :            :     MBEDTLS_MD_SHA1=0x05,      /**< The SHA-1 message digest. */
+      52                 :            :     MBEDTLS_MD_SHA224=0x08,    /**< The SHA-224 message digest. */
+      53                 :            :     MBEDTLS_MD_SHA256=0x09,    /**< The SHA-256 message digest. */
+      54                 :            :     MBEDTLS_MD_SHA384=0x0a,    /**< The SHA-384 message digest. */
+      55                 :            :     MBEDTLS_MD_SHA512=0x0b,    /**< The SHA-512 message digest. */
+      56                 :            :     MBEDTLS_MD_SHA3_224=0x10,  /**< The SHA3-224 message digest. */
+      57                 :            :     MBEDTLS_MD_SHA3_256=0x11,  /**< The SHA3-256 message digest. */
+      58                 :            :     MBEDTLS_MD_SHA3_384=0x12,  /**< The SHA3-384 message digest. */
+      59                 :            :     MBEDTLS_MD_SHA3_512=0x13,  /**< The SHA3-512 message digest. */
+      60                 :            : } mbedtls_md_type_t;
+      61                 :            : 
+      62                 :            : /* Note: this should always be >= PSA_HASH_MAX_SIZE
+      63                 :            :  * in all builds with both CRYPTO_C and MD_LIGHT.
+      64                 :            :  *
+      65                 :            :  * This is to make things easier for modules such as TLS that may define a
+      66                 :            :  * buffer size using MD_MAX_SIZE in a part of the code that's common to PSA
+      67                 :            :  * and legacy, then assume the buffer's size is PSA_HASH_MAX_SIZE in another
+      68                 :            :  * part of the code based on PSA.
+      69                 :            :  */
+      70                 :            : #if defined(MBEDTLS_MD_CAN_SHA512) || defined(MBEDTLS_MD_CAN_SHA3_512)
+      71                 :            : #define MBEDTLS_MD_MAX_SIZE         64  /* longest known is SHA512 */
+      72                 :            : #elif defined(MBEDTLS_MD_CAN_SHA384) || defined(MBEDTLS_MD_CAN_SHA3_384)
+      73                 :            : #define MBEDTLS_MD_MAX_SIZE         48  /* longest known is SHA384 */
+      74                 :            : #elif defined(MBEDTLS_MD_CAN_SHA256) || defined(MBEDTLS_MD_CAN_SHA3_256)
+      75                 :            : #define MBEDTLS_MD_MAX_SIZE         32  /* longest known is SHA256 */
+      76                 :            : #elif defined(MBEDTLS_MD_CAN_SHA224) || defined(MBEDTLS_MD_CAN_SHA3_224)
+      77                 :            : #define MBEDTLS_MD_MAX_SIZE         28  /* longest known is SHA224 */
+      78                 :            : #else
+      79                 :            : #define MBEDTLS_MD_MAX_SIZE         20  /* longest known is SHA1 or RIPE MD-160
+      80                 :            :                                            or smaller (MD5 and earlier) */
+      81                 :            : #endif
+      82                 :            : 
+      83                 :            : #if defined(MBEDTLS_MD_CAN_SHA3_224)
+      84                 :            : #define MBEDTLS_MD_MAX_BLOCK_SIZE         144 /* the longest known is SHA3-224 */
+      85                 :            : #elif defined(MBEDTLS_MD_CAN_SHA3_256)
+      86                 :            : #define MBEDTLS_MD_MAX_BLOCK_SIZE         136
+      87                 :            : #elif defined(MBEDTLS_MD_CAN_SHA512) || defined(MBEDTLS_MD_CAN_SHA384)
+      88                 :            : #define MBEDTLS_MD_MAX_BLOCK_SIZE         128
+      89                 :            : #elif defined(MBEDTLS_MD_CAN_SHA3_384)
+      90                 :            : #define MBEDTLS_MD_MAX_BLOCK_SIZE         104
+      91                 :            : #elif defined(MBEDTLS_MD_CAN_SHA3_512)
+      92                 :            : #define MBEDTLS_MD_MAX_BLOCK_SIZE         72
+      93                 :            : #else
+      94                 :            : #define MBEDTLS_MD_MAX_BLOCK_SIZE         64
+      95                 :            : #endif
+      96                 :            : 
+      97                 :            : /**
+      98                 :            :  * Opaque struct.
+      99                 :            :  *
+     100                 :            :  * Constructed using either #mbedtls_md_info_from_string or
+     101                 :            :  * #mbedtls_md_info_from_type.
+     102                 :            :  *
+     103                 :            :  * Fields can be accessed with #mbedtls_md_get_size,
+     104                 :            :  * #mbedtls_md_get_type and #mbedtls_md_get_name.
+     105                 :            :  */
+     106                 :            : /* Defined internally in library/md_wrap.h. */
+     107                 :            : typedef struct mbedtls_md_info_t mbedtls_md_info_t;
+     108                 :            : 
+     109                 :            : /**
+     110                 :            :  * Used internally to indicate whether a context uses legacy or PSA.
+     111                 :            :  *
+     112                 :            :  * Internal use only.
+     113                 :            :  */
+     114                 :            : typedef enum {
+     115                 :            :     MBEDTLS_MD_ENGINE_LEGACY = 0,
+     116                 :            :     MBEDTLS_MD_ENGINE_PSA,
+     117                 :            : } mbedtls_md_engine_t;
+     118                 :            : 
+     119                 :            : /**
+     120                 :            :  * The generic message-digest context.
+     121                 :            :  */
+     122                 :            : typedef struct mbedtls_md_context_t {
+     123                 :            :     /** Information about the associated message digest. */
+     124                 :            :     const mbedtls_md_info_t *MBEDTLS_PRIVATE(md_info);
+     125                 :            : 
+     126                 :            : #if defined(MBEDTLS_MD_SOME_PSA)
+     127                 :            :     /** Are hash operations dispatched to PSA or legacy? */
+     128                 :            :     mbedtls_md_engine_t MBEDTLS_PRIVATE(engine);
+     129                 :            : #endif
+     130                 :            : 
+     131                 :            :     /** The digest-specific context (legacy) or the PSA operation. */
+     132                 :            :     void *MBEDTLS_PRIVATE(md_ctx);
+     133                 :            : 
+     134                 :            : #if defined(MBEDTLS_MD_C)
+     135                 :            :     /** The HMAC part of the context. */
+     136                 :            :     void *MBEDTLS_PRIVATE(hmac_ctx);
+     137                 :            : #endif
+     138                 :            : } mbedtls_md_context_t;
+     139                 :            : 
+     140                 :            : /**
+     141                 :            :  * \brief           This function returns the message-digest information
+     142                 :            :  *                  associated with the given digest type.
+     143                 :            :  *
+     144                 :            :  * \param md_type   The type of digest to search for.
+     145                 :            :  *
+     146                 :            :  * \return          The message-digest information associated with \p md_type.
+     147                 :            :  * \return          NULL if the associated message-digest information is not found.
+     148                 :            :  */
+     149                 :            : const mbedtls_md_info_t *mbedtls_md_info_from_type(mbedtls_md_type_t md_type);
+     150                 :            : 
+     151                 :            : /**
+     152                 :            :  * \brief           This function initializes a message-digest context without
+     153                 :            :  *                  binding it to a particular message-digest algorithm.
+     154                 :            :  *
+     155                 :            :  *                  This function should always be called first. It prepares the
+     156                 :            :  *                  context for mbedtls_md_setup() for binding it to a
+     157                 :            :  *                  message-digest algorithm.
+     158                 :            :  */
+     159                 :            : void mbedtls_md_init(mbedtls_md_context_t *ctx);
+     160                 :            : 
+     161                 :            : /**
+     162                 :            :  * \brief           This function clears the internal structure of \p ctx and
+     163                 :            :  *                  frees any embedded internal structure, but does not free
+     164                 :            :  *                  \p ctx itself.
+     165                 :            :  *
+     166                 :            :  *                  If you have called mbedtls_md_setup() on \p ctx, you must
+     167                 :            :  *                  call mbedtls_md_free() when you are no longer using the
+     168                 :            :  *                  context.
+     169                 :            :  *                  Calling this function if you have previously
+     170                 :            :  *                  called mbedtls_md_init() and nothing else is optional.
+     171                 :            :  *                  You must not call this function if you have not called
+     172                 :            :  *                  mbedtls_md_init().
+     173                 :            :  */
+     174                 :            : void mbedtls_md_free(mbedtls_md_context_t *ctx);
+     175                 :            : 
+     176                 :            : 
+     177                 :            : /**
+     178                 :            :  * \brief           This function selects the message digest algorithm to use,
+     179                 :            :  *                  and allocates internal structures.
+     180                 :            :  *
+     181                 :            :  *                  It should be called after mbedtls_md_init() or
+     182                 :            :  *                  mbedtls_md_free(). Makes it necessary to call
+     183                 :            :  *                  mbedtls_md_free() later.
+     184                 :            :  *
+     185                 :            :  * \param ctx       The context to set up.
+     186                 :            :  * \param md_info   The information structure of the message-digest algorithm
+     187                 :            :  *                  to use.
+     188                 :            :  * \param hmac      Defines if HMAC is used. 0: HMAC is not used (saves some memory),
+     189                 :            :  *                  or non-zero: HMAC is used with this context.
+     190                 :            :  *
+     191                 :            :  * \return          \c 0 on success.
+     192                 :            :  * \return          #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
+     193                 :            :  *                  failure.
+     194                 :            :  * \return          #MBEDTLS_ERR_MD_ALLOC_FAILED on memory-allocation failure.
+     195                 :            :  */
+     196                 :            : MBEDTLS_CHECK_RETURN_TYPICAL
+     197                 :            : int mbedtls_md_setup(mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac);
+     198                 :            : 
+     199                 :            : /**
+     200                 :            :  * \brief           This function clones the state of a message-digest
+     201                 :            :  *                  context.
+     202                 :            :  *
+     203                 :            :  * \note            You must call mbedtls_md_setup() on \c dst before calling
+     204                 :            :  *                  this function.
+     205                 :            :  *
+     206                 :            :  * \note            The two contexts must have the same type,
+     207                 :            :  *                  for example, both are SHA-256.
+     208                 :            :  *
+     209                 :            :  * \warning         This function clones the message-digest state, not the
+     210                 :            :  *                  HMAC state.
+     211                 :            :  *
+     212                 :            :  * \param dst       The destination context.
+     213                 :            :  * \param src       The context to be cloned.
+     214                 :            :  *
+     215                 :            :  * \return          \c 0 on success.
+     216                 :            :  * \return          #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification failure.
+     217                 :            :  * \return          #MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE if both contexts are
+     218                 :            :  *                  not using the same engine. This can be avoided by moving
+     219                 :            :  *                  the call to psa_crypto_init() before the first call to
+     220                 :            :  *                  mbedtls_md_setup().
+     221                 :            :  */
+     222                 :            : MBEDTLS_CHECK_RETURN_TYPICAL
+     223                 :            : int mbedtls_md_clone(mbedtls_md_context_t *dst,
+     224                 :            :                      const mbedtls_md_context_t *src);
+     225                 :            : 
+     226                 :            : /**
+     227                 :            :  * \brief           This function extracts the message-digest size from the
+     228                 :            :  *                  message-digest information structure.
+     229                 :            :  *
+     230                 :            :  * \param md_info   The information structure of the message-digest algorithm
+     231                 :            :  *                  to use.
+     232                 :            :  *
+     233                 :            :  * \return          The size of the message-digest output in Bytes.
+     234                 :            :  */
+     235                 :            : unsigned char mbedtls_md_get_size(const mbedtls_md_info_t *md_info);
+     236                 :            : 
+     237                 :            : /**
+     238                 :            :  * \brief           This function gives the message-digest size associated to
+     239                 :            :  *                  message-digest type.
+     240                 :            :  *
+     241                 :            :  * \param md_type   The message-digest type.
+     242                 :            :  *
+     243                 :            :  * \return          The size of the message-digest output in Bytes,
+     244                 :            :  *                  or 0 if the message-digest type is not known.
+     245                 :            :  */
+     246                 :        311 : static inline unsigned char mbedtls_md_get_size_from_type(mbedtls_md_type_t md_type)
+     247                 :            : {
+     248                 :        311 :     return mbedtls_md_get_size(mbedtls_md_info_from_type(md_type));
+     249                 :            : }
+     250                 :            : 
+     251                 :            : /**
+     252                 :            :  * \brief           This function extracts the message-digest type from the
+     253                 :            :  *                  message-digest information structure.
+     254                 :            :  *
+     255                 :            :  * \param md_info   The information structure of the message-digest algorithm
+     256                 :            :  *                  to use.
+     257                 :            :  *
+     258                 :            :  * \return          The type of the message digest.
+     259                 :            :  */
+     260                 :            : mbedtls_md_type_t mbedtls_md_get_type(const mbedtls_md_info_t *md_info);
+     261                 :            : 
+     262                 :            : /**
+     263                 :            :  * \brief           This function starts a message-digest computation.
+     264                 :            :  *
+     265                 :            :  *                  You must call this function after setting up the context
+     266                 :            :  *                  with mbedtls_md_setup(), and before passing data with
+     267                 :            :  *                  mbedtls_md_update().
+     268                 :            :  *
+     269                 :            :  * \param ctx       The generic message-digest context.
+     270                 :            :  *
+     271                 :            :  * \return          \c 0 on success.
+     272                 :            :  * \return          #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
+     273                 :            :  *                  failure.
+     274                 :            :  */
+     275                 :            : MBEDTLS_CHECK_RETURN_TYPICAL
+     276                 :            : int mbedtls_md_starts(mbedtls_md_context_t *ctx);
+     277                 :            : 
+     278                 :            : /**
+     279                 :            :  * \brief           This function feeds an input buffer into an ongoing
+     280                 :            :  *                  message-digest computation.
+     281                 :            :  *
+     282                 :            :  *                  You must call mbedtls_md_starts() before calling this
+     283                 :            :  *                  function. You may call this function multiple times.
+     284                 :            :  *                  Afterwards, call mbedtls_md_finish().
+     285                 :            :  *
+     286                 :            :  * \param ctx       The generic message-digest context.
+     287                 :            :  * \param input     The buffer holding the input data.
+     288                 :            :  * \param ilen      The length of the input data.
+     289                 :            :  *
+     290                 :            :  * \return          \c 0 on success.
+     291                 :            :  * \return          #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
+     292                 :            :  *                  failure.
+     293                 :            :  */
+     294                 :            : MBEDTLS_CHECK_RETURN_TYPICAL
+     295                 :            : int mbedtls_md_update(mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen);
+     296                 :            : 
+     297                 :            : /**
+     298                 :            :  * \brief           This function finishes the digest operation,
+     299                 :            :  *                  and writes the result to the output buffer.
+     300                 :            :  *
+     301                 :            :  *                  Call this function after a call to mbedtls_md_starts(),
+     302                 :            :  *                  followed by any number of calls to mbedtls_md_update().
+     303                 :            :  *                  Afterwards, you may either clear the context with
+     304                 :            :  *                  mbedtls_md_free(), or call mbedtls_md_starts() to reuse
+     305                 :            :  *                  the context for another digest operation with the same
+     306                 :            :  *                  algorithm.
+     307                 :            :  *
+     308                 :            :  * \param ctx       The generic message-digest context.
+     309                 :            :  * \param output    The buffer for the generic message-digest checksum result.
+     310                 :            :  *
+     311                 :            :  * \return          \c 0 on success.
+     312                 :            :  * \return          #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
+     313                 :            :  *                  failure.
+     314                 :            :  */
+     315                 :            : MBEDTLS_CHECK_RETURN_TYPICAL
+     316                 :            : int mbedtls_md_finish(mbedtls_md_context_t *ctx, unsigned char *output);
+     317                 :            : 
+     318                 :            : /**
+     319                 :            :  * \brief          This function calculates the message-digest of a buffer,
+     320                 :            :  *                 with respect to a configurable message-digest algorithm
+     321                 :            :  *                 in a single call.
+     322                 :            :  *
+     323                 :            :  *                 The result is calculated as
+     324                 :            :  *                 Output = message_digest(input buffer).
+     325                 :            :  *
+     326                 :            :  * \param md_info  The information structure of the message-digest algorithm
+     327                 :            :  *                 to use.
+     328                 :            :  * \param input    The buffer holding the data.
+     329                 :            :  * \param ilen     The length of the input data.
+     330                 :            :  * \param output   The generic message-digest checksum result.
+     331                 :            :  *
+     332                 :            :  * \return         \c 0 on success.
+     333                 :            :  * \return         #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
+     334                 :            :  *                 failure.
+     335                 :            :  */
+     336                 :            : MBEDTLS_CHECK_RETURN_TYPICAL
+     337                 :            : int mbedtls_md(const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen,
+     338                 :            :                unsigned char *output);
+     339                 :            : 
+     340                 :            : /**
+     341                 :            :  * \brief           This function returns the list of digests supported by the
+     342                 :            :  *                  generic digest module.
+     343                 :            :  *
+     344                 :            :  * \note            The list starts with the strongest available hashes.
+     345                 :            :  *
+     346                 :            :  * \return          A statically allocated array of digests. Each element
+     347                 :            :  *                  in the returned list is an integer belonging to the
+     348                 :            :  *                  message-digest enumeration #mbedtls_md_type_t.
+     349                 :            :  *                  The last entry is 0.
+     350                 :            :  */
+     351                 :            : const int *mbedtls_md_list(void);
+     352                 :            : 
+     353                 :            : /**
+     354                 :            :  * \brief           This function returns the message-digest information
+     355                 :            :  *                  associated with the given digest name.
+     356                 :            :  *
+     357                 :            :  * \param md_name   The name of the digest to search for.
+     358                 :            :  *
+     359                 :            :  * \return          The message-digest information associated with \p md_name.
+     360                 :            :  * \return          NULL if the associated message-digest information is not found.
+     361                 :            :  */
+     362                 :            : const mbedtls_md_info_t *mbedtls_md_info_from_string(const char *md_name);
+     363                 :            : 
+     364                 :            : /**
+     365                 :            :  * \brief           This function returns the name of the message digest for
+     366                 :            :  *                  the message-digest information structure given.
+     367                 :            :  *
+     368                 :            :  * \param md_info   The information structure of the message-digest algorithm
+     369                 :            :  *                  to use.
+     370                 :            :  *
+     371                 :            :  * \return          The name of the message digest.
+     372                 :            :  */
+     373                 :            : const char *mbedtls_md_get_name(const mbedtls_md_info_t *md_info);
+     374                 :            : 
+     375                 :            : /**
+     376                 :            :  * \brief           This function returns the message-digest information
+     377                 :            :  *                  from the given context.
+     378                 :            :  *
+     379                 :            :  * \param ctx       The context from which to extract the information.
+     380                 :            :  *                  This must be initialized (or \c NULL).
+     381                 :            :  *
+     382                 :            :  * \return          The message-digest information associated with \p ctx.
+     383                 :            :  * \return          \c NULL if \p ctx is \c NULL.
+     384                 :            :  */
+     385                 :            : const mbedtls_md_info_t *mbedtls_md_info_from_ctx(
+     386                 :            :     const mbedtls_md_context_t *ctx);
+     387                 :            : 
+     388                 :            : #if defined(MBEDTLS_FS_IO)
+     389                 :            : /**
+     390                 :            :  * \brief          This function calculates the message-digest checksum
+     391                 :            :  *                 result of the contents of the provided file.
+     392                 :            :  *
+     393                 :            :  *                 The result is calculated as
+     394                 :            :  *                 Output = message_digest(file contents).
+     395                 :            :  *
+     396                 :            :  * \param md_info  The information structure of the message-digest algorithm
+     397                 :            :  *                 to use.
+     398                 :            :  * \param path     The input file name.
+     399                 :            :  * \param output   The generic message-digest checksum result.
+     400                 :            :  *
+     401                 :            :  * \return         \c 0 on success.
+     402                 :            :  * \return         #MBEDTLS_ERR_MD_FILE_IO_ERROR on an I/O error accessing
+     403                 :            :  *                 the file pointed by \p path.
+     404                 :            :  * \return         #MBEDTLS_ERR_MD_BAD_INPUT_DATA if \p md_info was NULL.
+     405                 :            :  */
+     406                 :            : MBEDTLS_CHECK_RETURN_TYPICAL
+     407                 :            : int mbedtls_md_file(const mbedtls_md_info_t *md_info, const char *path,
+     408                 :            :                     unsigned char *output);
+     409                 :            : #endif /* MBEDTLS_FS_IO */
+     410                 :            : 
+     411                 :            : /**
+     412                 :            :  * \brief           This function sets the HMAC key and prepares to
+     413                 :            :  *                  authenticate a new message.
+     414                 :            :  *
+     415                 :            :  *                  Call this function after mbedtls_md_setup(), to use
+     416                 :            :  *                  the MD context for an HMAC calculation, then call
+     417                 :            :  *                  mbedtls_md_hmac_update() to provide the input data, and
+     418                 :            :  *                  mbedtls_md_hmac_finish() to get the HMAC value.
+     419                 :            :  *
+     420                 :            :  * \param ctx       The message digest context containing an embedded HMAC
+     421                 :            :  *                  context.
+     422                 :            :  * \param key       The HMAC secret key.
+     423                 :            :  * \param keylen    The length of the HMAC key in Bytes.
+     424                 :            :  *
+     425                 :            :  * \return          \c 0 on success.
+     426                 :            :  * \return          #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
+     427                 :            :  *                  failure.
+     428                 :            :  */
+     429                 :            : MBEDTLS_CHECK_RETURN_TYPICAL
+     430                 :            : int mbedtls_md_hmac_starts(mbedtls_md_context_t *ctx, const unsigned char *key,
+     431                 :            :                            size_t keylen);
+     432                 :            : 
+     433                 :            : /**
+     434                 :            :  * \brief           This function feeds an input buffer into an ongoing HMAC
+     435                 :            :  *                  computation.
+     436                 :            :  *
+     437                 :            :  *                  Call mbedtls_md_hmac_starts() or mbedtls_md_hmac_reset()
+     438                 :            :  *                  before calling this function.
+     439                 :            :  *                  You may call this function multiple times to pass the
+     440                 :            :  *                  input piecewise.
+     441                 :            :  *                  Afterwards, call mbedtls_md_hmac_finish().
+     442                 :            :  *
+     443                 :            :  * \param ctx       The message digest context containing an embedded HMAC
+     444                 :            :  *                  context.
+     445                 :            :  * \param input     The buffer holding the input data.
+     446                 :            :  * \param ilen      The length of the input data.
+     447                 :            :  *
+     448                 :            :  * \return          \c 0 on success.
+     449                 :            :  * \return          #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
+     450                 :            :  *                  failure.
+     451                 :            :  */
+     452                 :            : MBEDTLS_CHECK_RETURN_TYPICAL
+     453                 :            : int mbedtls_md_hmac_update(mbedtls_md_context_t *ctx, const unsigned char *input,
+     454                 :            :                            size_t ilen);
+     455                 :            : 
+     456                 :            : /**
+     457                 :            :  * \brief           This function finishes the HMAC operation, and writes
+     458                 :            :  *                  the result to the output buffer.
+     459                 :            :  *
+     460                 :            :  *                  Call this function after mbedtls_md_hmac_starts() and
+     461                 :            :  *                  mbedtls_md_hmac_update() to get the HMAC value. Afterwards
+     462                 :            :  *                  you may either call mbedtls_md_free() to clear the context,
+     463                 :            :  *                  or call mbedtls_md_hmac_reset() to reuse the context with
+     464                 :            :  *                  the same HMAC key.
+     465                 :            :  *
+     466                 :            :  * \param ctx       The message digest context containing an embedded HMAC
+     467                 :            :  *                  context.
+     468                 :            :  * \param output    The generic HMAC checksum result.
+     469                 :            :  *
+     470                 :            :  * \return          \c 0 on success.
+     471                 :            :  * \return          #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
+     472                 :            :  *                  failure.
+     473                 :            :  */
+     474                 :            : MBEDTLS_CHECK_RETURN_TYPICAL
+     475                 :            : int mbedtls_md_hmac_finish(mbedtls_md_context_t *ctx, unsigned char *output);
+     476                 :            : 
+     477                 :            : /**
+     478                 :            :  * \brief           This function prepares to authenticate a new message with
+     479                 :            :  *                  the same key as the previous HMAC operation.
+     480                 :            :  *
+     481                 :            :  *                  You may call this function after mbedtls_md_hmac_finish().
+     482                 :            :  *                  Afterwards call mbedtls_md_hmac_update() to pass the new
+     483                 :            :  *                  input.
+     484                 :            :  *
+     485                 :            :  * \param ctx       The message digest context containing an embedded HMAC
+     486                 :            :  *                  context.
+     487                 :            :  *
+     488                 :            :  * \return          \c 0 on success.
+     489                 :            :  * \return          #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
+     490                 :            :  *                  failure.
+     491                 :            :  */
+     492                 :            : MBEDTLS_CHECK_RETURN_TYPICAL
+     493                 :            : int mbedtls_md_hmac_reset(mbedtls_md_context_t *ctx);
+     494                 :            : 
+     495                 :            : /**
+     496                 :            :  * \brief          This function calculates the full generic HMAC
+     497                 :            :  *                 on the input buffer with the provided key.
+     498                 :            :  *
+     499                 :            :  *                 The function allocates the context, performs the
+     500                 :            :  *                 calculation, and frees the context.
+     501                 :            :  *
+     502                 :            :  *                 The HMAC result is calculated as
+     503                 :            :  *                 output = generic HMAC(hmac key, input buffer).
+     504                 :            :  *
+     505                 :            :  * \param md_info  The information structure of the message-digest algorithm
+     506                 :            :  *                 to use.
+     507                 :            :  * \param key      The HMAC secret key.
+     508                 :            :  * \param keylen   The length of the HMAC secret key in Bytes.
+     509                 :            :  * \param input    The buffer holding the input data.
+     510                 :            :  * \param ilen     The length of the input data.
+     511                 :            :  * \param output   The generic HMAC result.
+     512                 :            :  *
+     513                 :            :  * \return         \c 0 on success.
+     514                 :            :  * \return         #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
+     515                 :            :  *                 failure.
+     516                 :            :  */
+     517                 :            : MBEDTLS_CHECK_RETURN_TYPICAL
+     518                 :            : int mbedtls_md_hmac(const mbedtls_md_info_t *md_info, const unsigned char *key, size_t keylen,
+     519                 :            :                     const unsigned char *input, size_t ilen,
+     520                 :            :                     unsigned char *output);
+     521                 :            : 
+     522                 :            : #ifdef __cplusplus
+     523                 :            : }
+     524                 :            : #endif
+     525                 :            : 
+     526                 :            : #endif /* MBEDTLS_MD_H */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/pk.h.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/pk.h.func-sort-c.html new file mode 100644 index 00000000000..744a74b48e4 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/pk.h.func-sort-c.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/include/mbedtls/pk.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/include/mbedtls - pk.h (source / functions)HitTotalCoverage
Test:coverage.infoLines:81457.1 %
Date:2024-09-22 08:21:07Functions:2366.7 %
Branches:2450.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_pk_get_len0
mbedtls_pk_ec1019
mbedtls_pk_rsa1216
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/pk.h.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/pk.h.func.html new file mode 100644 index 00000000000..b30643644fa --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/pk.h.func.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/include/mbedtls/pk.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/include/mbedtls - pk.h (source / functions)HitTotalCoverage
Test:coverage.infoLines:81457.1 %
Date:2024-09-22 08:21:07Functions:2366.7 %
Branches:2450.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_pk_ec1019
mbedtls_pk_get_len0
mbedtls_pk_rsa1216
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/pk.h.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/pk.h.gcov.html new file mode 100644 index 00000000000..02c3c8feb20 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/include/mbedtls/pk.h.gcov.html @@ -0,0 +1,1373 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/include/mbedtls/pk.h + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/include/mbedtls - pk.h (source / functions)HitTotalCoverage
Test:coverage.infoLines:81457.1 %
Date:2024-09-22 08:21:07Functions:2366.7 %
Branches:2450.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  * \file pk.h
+       3                 :            :  *
+       4                 :            :  * \brief Public Key abstraction layer
+       5                 :            :  */
+       6                 :            : /*
+       7                 :            :  *  Copyright The Mbed TLS Contributors
+       8                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       9                 :            :  */
+      10                 :            : 
+      11                 :            : #ifndef MBEDTLS_PK_H
+      12                 :            : #define MBEDTLS_PK_H
+      13                 :            : #include "mbedtls/private_access.h"
+      14                 :            : 
+      15                 :            : #include "mbedtls/build_info.h"
+      16                 :            : 
+      17                 :            : #include "mbedtls/md.h"
+      18                 :            : 
+      19                 :            : #if defined(MBEDTLS_RSA_C)
+      20                 :            : #include "mbedtls/rsa.h"
+      21                 :            : #endif
+      22                 :            : 
+      23                 :            : #if defined(MBEDTLS_ECP_C)
+      24                 :            : #include "mbedtls/ecp.h"
+      25                 :            : #endif
+      26                 :            : 
+      27                 :            : #if defined(MBEDTLS_ECDSA_C)
+      28                 :            : #include "mbedtls/ecdsa.h"
+      29                 :            : #endif
+      30                 :            : 
+      31                 :            : #if defined(MBEDTLS_PSA_CRYPTO_CLIENT)
+      32                 :            : #include "psa/crypto.h"
+      33                 :            : #endif
+      34                 :            : 
+      35                 :            : /** Memory allocation failed. */
+      36                 :            : #define MBEDTLS_ERR_PK_ALLOC_FAILED        -0x3F80
+      37                 :            : /** Type mismatch, eg attempt to encrypt with an ECDSA key */
+      38                 :            : #define MBEDTLS_ERR_PK_TYPE_MISMATCH       -0x3F00
+      39                 :            : /** Bad input parameters to function. */
+      40                 :            : #define MBEDTLS_ERR_PK_BAD_INPUT_DATA      -0x3E80
+      41                 :            : /** Read/write of file failed. */
+      42                 :            : #define MBEDTLS_ERR_PK_FILE_IO_ERROR       -0x3E00
+      43                 :            : /** Unsupported key version */
+      44                 :            : #define MBEDTLS_ERR_PK_KEY_INVALID_VERSION -0x3D80
+      45                 :            : /** Invalid key tag or value. */
+      46                 :            : #define MBEDTLS_ERR_PK_KEY_INVALID_FORMAT  -0x3D00
+      47                 :            : /** Key algorithm is unsupported (only RSA and EC are supported). */
+      48                 :            : #define MBEDTLS_ERR_PK_UNKNOWN_PK_ALG      -0x3C80
+      49                 :            : /** Private key password can't be empty. */
+      50                 :            : #define MBEDTLS_ERR_PK_PASSWORD_REQUIRED   -0x3C00
+      51                 :            : /** Given private key password does not allow for correct decryption. */
+      52                 :            : #define MBEDTLS_ERR_PK_PASSWORD_MISMATCH   -0x3B80
+      53                 :            : /** The pubkey tag or value is invalid (only RSA and EC are supported). */
+      54                 :            : #define MBEDTLS_ERR_PK_INVALID_PUBKEY      -0x3B00
+      55                 :            : /** The algorithm tag or value is invalid. */
+      56                 :            : #define MBEDTLS_ERR_PK_INVALID_ALG         -0x3A80
+      57                 :            : /** Elliptic curve is unsupported (only NIST curves are supported). */
+      58                 :            : #define MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE -0x3A00
+      59                 :            : /** Unavailable feature, e.g. RSA disabled for RSA key. */
+      60                 :            : #define MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE -0x3980
+      61                 :            : /** The buffer contains a valid signature followed by more data. */
+      62                 :            : #define MBEDTLS_ERR_PK_SIG_LEN_MISMATCH    -0x3900
+      63                 :            : /** The output buffer is too small. */
+      64                 :            : #define MBEDTLS_ERR_PK_BUFFER_TOO_SMALL    -0x3880
+      65                 :            : 
+      66                 :            : #ifdef __cplusplus
+      67                 :            : extern "C" {
+      68                 :            : #endif
+      69                 :            : 
+      70                 :            : /**
+      71                 :            :  * \brief          Public key types
+      72                 :            :  */
+      73                 :            : typedef enum {
+      74                 :            :     MBEDTLS_PK_NONE=0,
+      75                 :            :     MBEDTLS_PK_RSA,
+      76                 :            :     MBEDTLS_PK_ECKEY,
+      77                 :            :     MBEDTLS_PK_ECKEY_DH,
+      78                 :            :     MBEDTLS_PK_ECDSA,
+      79                 :            :     MBEDTLS_PK_RSA_ALT,
+      80                 :            :     MBEDTLS_PK_RSASSA_PSS,
+      81                 :            :     MBEDTLS_PK_OPAQUE,
+      82                 :            : } mbedtls_pk_type_t;
+      83                 :            : 
+      84                 :            : /**
+      85                 :            :  * \brief           Options for RSASSA-PSS signature verification.
+      86                 :            :  *                  See \c mbedtls_rsa_rsassa_pss_verify_ext()
+      87                 :            :  */
+      88                 :            : typedef struct mbedtls_pk_rsassa_pss_options {
+      89                 :            :     /** The digest to use for MGF1 in PSS.
+      90                 :            :      *
+      91                 :            :      * \note When #MBEDTLS_USE_PSA_CRYPTO is enabled and #MBEDTLS_RSA_C is
+      92                 :            :      *       disabled, this must be equal to the \c md_alg argument passed
+      93                 :            :      *       to mbedtls_pk_verify_ext(). In a future version of the library,
+      94                 :            :      *       this constraint may apply whenever #MBEDTLS_USE_PSA_CRYPTO is
+      95                 :            :      *       enabled regardless of the status of #MBEDTLS_RSA_C.
+      96                 :            :      */
+      97                 :            :     mbedtls_md_type_t mgf1_hash_id;
+      98                 :            : 
+      99                 :            :     /** The expected length of the salt, in bytes. This may be
+     100                 :            :      * #MBEDTLS_RSA_SALT_LEN_ANY to accept any salt length.
+     101                 :            :      *
+     102                 :            :      * \note When #MBEDTLS_USE_PSA_CRYPTO is enabled, only
+     103                 :            :      *       #MBEDTLS_RSA_SALT_LEN_ANY is valid. Any other value may be
+     104                 :            :      *       ignored (allowing any salt length).
+     105                 :            :      */
+     106                 :            :     int expected_salt_len;
+     107                 :            : 
+     108                 :            : } mbedtls_pk_rsassa_pss_options;
+     109                 :            : 
+     110                 :            : /**
+     111                 :            :  * \brief           Maximum size of a signature made by mbedtls_pk_sign().
+     112                 :            :  */
+     113                 :            : /* We need to set MBEDTLS_PK_SIGNATURE_MAX_SIZE to the maximum signature
+     114                 :            :  * size among the supported signature types. Do it by starting at 0,
+     115                 :            :  * then incrementally increasing to be large enough for each supported
+     116                 :            :  * signature mechanism.
+     117                 :            :  *
+     118                 :            :  * The resulting value can be 0, for example if MBEDTLS_ECDH_C is enabled
+     119                 :            :  * (which allows the pk module to be included) but neither MBEDTLS_ECDSA_C
+     120                 :            :  * nor MBEDTLS_RSA_C nor any opaque signature mechanism (PSA or RSA_ALT).
+     121                 :            :  */
+     122                 :            : #define MBEDTLS_PK_SIGNATURE_MAX_SIZE 0
+     123                 :            : 
+     124                 :            : #if (defined(MBEDTLS_RSA_C) || defined(MBEDTLS_PK_RSA_ALT_SUPPORT)) && \
+     125                 :            :     MBEDTLS_MPI_MAX_SIZE > MBEDTLS_PK_SIGNATURE_MAX_SIZE
+     126                 :            : /* For RSA, the signature can be as large as the bignum module allows.
+     127                 :            :  * For RSA_ALT, the signature size is not necessarily tied to what the
+     128                 :            :  * bignum module can do, but in the absence of any specific setting,
+     129                 :            :  * we use that (rsa_alt_sign_wrap in library/pk_wrap.h will check). */
+     130                 :            : #undef MBEDTLS_PK_SIGNATURE_MAX_SIZE
+     131                 :            : #define MBEDTLS_PK_SIGNATURE_MAX_SIZE MBEDTLS_MPI_MAX_SIZE
+     132                 :            : #endif
+     133                 :            : 
+     134                 :            : #if defined(MBEDTLS_ECDSA_C) &&                                 \
+     135                 :            :     MBEDTLS_ECDSA_MAX_LEN > MBEDTLS_PK_SIGNATURE_MAX_SIZE
+     136                 :            : /* For ECDSA, the ecdsa module exports a constant for the maximum
+     137                 :            :  * signature size. */
+     138                 :            : #undef MBEDTLS_PK_SIGNATURE_MAX_SIZE
+     139                 :            : #define MBEDTLS_PK_SIGNATURE_MAX_SIZE MBEDTLS_ECDSA_MAX_LEN
+     140                 :            : #endif
+     141                 :            : 
+     142                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+     143                 :            : #if PSA_SIGNATURE_MAX_SIZE > MBEDTLS_PK_SIGNATURE_MAX_SIZE
+     144                 :            : /* PSA_SIGNATURE_MAX_SIZE is the maximum size of a signature made
+     145                 :            :  * through the PSA API in the PSA representation. */
+     146                 :            : #undef MBEDTLS_PK_SIGNATURE_MAX_SIZE
+     147                 :            : #define MBEDTLS_PK_SIGNATURE_MAX_SIZE PSA_SIGNATURE_MAX_SIZE
+     148                 :            : #endif
+     149                 :            : 
+     150                 :            : #if PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE + 11 > MBEDTLS_PK_SIGNATURE_MAX_SIZE
+     151                 :            : /* The Mbed TLS representation is different for ECDSA signatures:
+     152                 :            :  * PSA uses the raw concatenation of r and s,
+     153                 :            :  * whereas Mbed TLS uses the ASN.1 representation (SEQUENCE of two INTEGERs).
+     154                 :            :  * Add the overhead of ASN.1: up to (1+2) + 2 * (1+2+1) for the
+     155                 :            :  * types, lengths (represented by up to 2 bytes), and potential leading
+     156                 :            :  * zeros of the INTEGERs and the SEQUENCE. */
+     157                 :            : #undef MBEDTLS_PK_SIGNATURE_MAX_SIZE
+     158                 :            : #define MBEDTLS_PK_SIGNATURE_MAX_SIZE (PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE + 11)
+     159                 :            : #endif
+     160                 :            : #endif /* defined(MBEDTLS_USE_PSA_CRYPTO) */
+     161                 :            : 
+     162                 :            : /* Internal helper to define which fields in the pk_context structure below
+     163                 :            :  * should be used for EC keys: legacy ecp_keypair or the raw (PSA friendly)
+     164                 :            :  * format. It should be noted that this only affects how data is stored, not
+     165                 :            :  * which functions are used for various operations. The overall picture looks
+     166                 :            :  * like this:
+     167                 :            :  * - if USE_PSA is not defined and ECP_C is defined then use ecp_keypair data
+     168                 :            :  *   structure and legacy functions
+     169                 :            :  * - if USE_PSA is defined and
+     170                 :            :  *     - if ECP_C then use ecp_keypair structure, convert data to a PSA friendly
+     171                 :            :  *       format and use PSA functions
+     172                 :            :  *     - if !ECP_C then use new raw data and PSA functions directly.
+     173                 :            :  *
+     174                 :            :  * The main reason for the "intermediate" (USE_PSA + ECP_C) above is that as long
+     175                 :            :  * as ECP_C is defined mbedtls_pk_ec() gives the user a read/write access to the
+     176                 :            :  * ecp_keypair structure inside the pk_context so they can modify it using
+     177                 :            :  * ECP functions which are not under PK module's control.
+     178                 :            :  */
+     179                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY) && \
+     180                 :            :     !defined(MBEDTLS_ECP_C)
+     181                 :            : #define MBEDTLS_PK_USE_PSA_EC_DATA
+     182                 :            : #endif
+     183                 :            : 
+     184                 :            : /**
+     185                 :            :  * \brief           Types for interfacing with the debug module
+     186                 :            :  */
+     187                 :            : typedef enum {
+     188                 :            :     MBEDTLS_PK_DEBUG_NONE = 0,
+     189                 :            :     MBEDTLS_PK_DEBUG_MPI,
+     190                 :            :     MBEDTLS_PK_DEBUG_ECP,
+     191                 :            :     MBEDTLS_PK_DEBUG_PSA_EC,
+     192                 :            : } mbedtls_pk_debug_type;
+     193                 :            : 
+     194                 :            : /**
+     195                 :            :  * \brief           Item to send to the debug module
+     196                 :            :  */
+     197                 :            : typedef struct mbedtls_pk_debug_item {
+     198                 :            :     mbedtls_pk_debug_type MBEDTLS_PRIVATE(type);
+     199                 :            :     const char *MBEDTLS_PRIVATE(name);
+     200                 :            :     void *MBEDTLS_PRIVATE(value);
+     201                 :            : } mbedtls_pk_debug_item;
+     202                 :            : 
+     203                 :            : /** Maximum number of item send for debugging, plus 1 */
+     204                 :            : #define MBEDTLS_PK_DEBUG_MAX_ITEMS 3
+     205                 :            : 
+     206                 :            : /**
+     207                 :            :  * \brief           Public key information and operations
+     208                 :            :  *
+     209                 :            :  * \note        The library does not support custom pk info structures,
+     210                 :            :  *              only built-in structures returned by
+     211                 :            :  *              mbedtls_cipher_info_from_type().
+     212                 :            :  */
+     213                 :            : typedef struct mbedtls_pk_info_t mbedtls_pk_info_t;
+     214                 :            : 
+     215                 :            : #define MBEDTLS_PK_MAX_EC_PUBKEY_RAW_LEN \
+     216                 :            :     PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS)
+     217                 :            : /**
+     218                 :            :  * \brief           Public key container
+     219                 :            :  */
+     220                 :            : typedef struct mbedtls_pk_context {
+     221                 :            :     const mbedtls_pk_info_t *MBEDTLS_PRIVATE(pk_info);    /**< Public key information         */
+     222                 :            :     void *MBEDTLS_PRIVATE(pk_ctx);                        /**< Underlying public key context  */
+     223                 :            :     /* The following field is used to store the ID of a private key in the
+     224                 :            :      * following cases:
+     225                 :            :      * - opaque key when MBEDTLS_USE_PSA_CRYPTO is defined
+     226                 :            :      * - normal key when MBEDTLS_PK_USE_PSA_EC_DATA is defined. In this case:
+     227                 :            :      *    - the pk_ctx above is not not used to store the private key anymore.
+     228                 :            :      *      Actually that field not populated at all in this case because also
+     229                 :            :      *      the public key will be stored in raw format as explained below
+     230                 :            :      *    - this ID is used for all private key operations (ex: sign, check
+     231                 :            :      *      key pair, key write, etc) using PSA functions
+     232                 :            :      *
+     233                 :            :      * Note: this private key storing solution only affects EC keys, not the
+     234                 :            :      *       other ones. The latters still use the pk_ctx to store their own
+     235                 :            :      *       context. */
+     236                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+     237                 :            :     mbedtls_svc_key_id_t MBEDTLS_PRIVATE(priv_id);      /**< Key ID for opaque keys */
+     238                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO */
+     239                 :            :     /* The following fields are meant for storing the public key in raw format
+     240                 :            :      * which is handy for:
+     241                 :            :      * - easily importing it into the PSA context
+     242                 :            :      * - reducing the ECP module dependencies in the PK one.
+     243                 :            :      *
+     244                 :            :      * When MBEDTLS_PK_USE_PSA_EC_DATA is enabled:
+     245                 :            :      * - the pk_ctx above is not used anymore for storing the public key
+     246                 :            :      *   inside the ecp_keypair structure
+     247                 :            :      * - the following fields are used for all public key operations: signature
+     248                 :            :      *   verify, key pair check and key write.
+     249                 :            :      * - For a key pair, priv_id contains the private key. For a public key,
+     250                 :            :      *   priv_id is null.
+     251                 :            :      * Of course, when MBEDTLS_PK_USE_PSA_EC_DATA is not enabled, the legacy
+     252                 :            :      * ecp_keypair structure is used for storing the public key and performing
+     253                 :            :      * all the operations.
+     254                 :            :      *
+     255                 :            :      * Note: This new public key storing solution only works for EC keys, not
+     256                 :            :      *       other ones. The latters still use pk_ctx to store their own
+     257                 :            :      *       context.
+     258                 :            :      */
+     259                 :            : #if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
+     260                 :            :     uint8_t MBEDTLS_PRIVATE(pub_raw)[MBEDTLS_PK_MAX_EC_PUBKEY_RAW_LEN]; /**< Raw public key   */
+     261                 :            :     size_t MBEDTLS_PRIVATE(pub_raw_len);            /**< Valid bytes in "pub_raw" */
+     262                 :            :     psa_ecc_family_t MBEDTLS_PRIVATE(ec_family);    /**< EC family of pk */
+     263                 :            :     size_t MBEDTLS_PRIVATE(ec_bits);                /**< Curve's bits of pk */
+     264                 :            : #endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
+     265                 :            : } mbedtls_pk_context;
+     266                 :            : 
+     267                 :            : #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
+     268                 :            : /**
+     269                 :            :  * \brief           Context for resuming operations
+     270                 :            :  */
+     271                 :            : typedef struct {
+     272                 :            :     const mbedtls_pk_info_t *MBEDTLS_PRIVATE(pk_info);    /**< Public key information         */
+     273                 :            :     void *MBEDTLS_PRIVATE(rs_ctx);                        /**< Underlying restart context     */
+     274                 :            : } mbedtls_pk_restart_ctx;
+     275                 :            : #else /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
+     276                 :            : /* Now we can declare functions that take a pointer to that */
+     277                 :            : typedef void mbedtls_pk_restart_ctx;
+     278                 :            : #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
+     279                 :            : 
+     280                 :            : #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
+     281                 :            : /**
+     282                 :            :  * \brief           Types for RSA-alt abstraction
+     283                 :            :  */
+     284                 :            : typedef int (*mbedtls_pk_rsa_alt_decrypt_func)(void *ctx, size_t *olen,
+     285                 :            :                                                const unsigned char *input, unsigned char *output,
+     286                 :            :                                                size_t output_max_len);
+     287                 :            : typedef int (*mbedtls_pk_rsa_alt_sign_func)(void *ctx,
+     288                 :            :                                             int (*f_rng)(void *, unsigned char *, size_t),
+     289                 :            :                                             void *p_rng,
+     290                 :            :                                             mbedtls_md_type_t md_alg, unsigned int hashlen,
+     291                 :            :                                             const unsigned char *hash, unsigned char *sig);
+     292                 :            : typedef size_t (*mbedtls_pk_rsa_alt_key_len_func)(void *ctx);
+     293                 :            : #endif /* MBEDTLS_PK_RSA_ALT_SUPPORT */
+     294                 :            : 
+     295                 :            : /**
+     296                 :            :  * \brief           Return information associated with the given PK type
+     297                 :            :  *
+     298                 :            :  * \param pk_type   PK type to search for.
+     299                 :            :  *
+     300                 :            :  * \return          The PK info associated with the type or NULL if not found.
+     301                 :            :  */
+     302                 :            : const mbedtls_pk_info_t *mbedtls_pk_info_from_type(mbedtls_pk_type_t pk_type);
+     303                 :            : 
+     304                 :            : /**
+     305                 :            :  * \brief           Initialize a #mbedtls_pk_context (as NONE).
+     306                 :            :  *
+     307                 :            :  * \param ctx       The context to initialize.
+     308                 :            :  *                  This must not be \c NULL.
+     309                 :            :  */
+     310                 :            : void mbedtls_pk_init(mbedtls_pk_context *ctx);
+     311                 :            : 
+     312                 :            : /**
+     313                 :            :  * \brief           Free the components of a #mbedtls_pk_context.
+     314                 :            :  *
+     315                 :            :  * \param ctx       The context to clear. It must have been initialized.
+     316                 :            :  *                  If this is \c NULL, this function does nothing.
+     317                 :            :  *
+     318                 :            :  * \note            For contexts that have been set up with
+     319                 :            :  *                  mbedtls_pk_setup_opaque(), this does not free the underlying
+     320                 :            :  *                  PSA key and you still need to call psa_destroy_key()
+     321                 :            :  *                  independently if you want to destroy that key.
+     322                 :            :  */
+     323                 :            : void mbedtls_pk_free(mbedtls_pk_context *ctx);
+     324                 :            : 
+     325                 :            : #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
+     326                 :            : /**
+     327                 :            :  * \brief           Initialize a restart context
+     328                 :            :  *
+     329                 :            :  * \param ctx       The context to initialize.
+     330                 :            :  *                  This must not be \c NULL.
+     331                 :            :  */
+     332                 :            : void mbedtls_pk_restart_init(mbedtls_pk_restart_ctx *ctx);
+     333                 :            : 
+     334                 :            : /**
+     335                 :            :  * \brief           Free the components of a restart context
+     336                 :            :  *
+     337                 :            :  * \param ctx       The context to clear. It must have been initialized.
+     338                 :            :  *                  If this is \c NULL, this function does nothing.
+     339                 :            :  */
+     340                 :            : void mbedtls_pk_restart_free(mbedtls_pk_restart_ctx *ctx);
+     341                 :            : #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
+     342                 :            : 
+     343                 :            : /**
+     344                 :            :  * \brief           Initialize a PK context with the information given
+     345                 :            :  *                  and allocates the type-specific PK subcontext.
+     346                 :            :  *
+     347                 :            :  * \param ctx       Context to initialize. It must not have been set
+     348                 :            :  *                  up yet (type #MBEDTLS_PK_NONE).
+     349                 :            :  * \param info      Information to use
+     350                 :            :  *
+     351                 :            :  * \return          0 on success,
+     352                 :            :  *                  MBEDTLS_ERR_PK_BAD_INPUT_DATA on invalid input,
+     353                 :            :  *                  MBEDTLS_ERR_PK_ALLOC_FAILED on allocation failure.
+     354                 :            :  *
+     355                 :            :  * \note            For contexts holding an RSA-alt key, use
+     356                 :            :  *                  \c mbedtls_pk_setup_rsa_alt() instead.
+     357                 :            :  */
+     358                 :            : int mbedtls_pk_setup(mbedtls_pk_context *ctx, const mbedtls_pk_info_t *info);
+     359                 :            : 
+     360                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+     361                 :            : /**
+     362                 :            :  * \brief           Initialize a PK context to wrap a PSA key.
+     363                 :            :  *
+     364                 :            :  * \note            This function replaces mbedtls_pk_setup() for contexts
+     365                 :            :  *                  that wrap a (possibly opaque) PSA key instead of
+     366                 :            :  *                  storing and manipulating the key material directly.
+     367                 :            :  *
+     368                 :            :  * \param ctx       The context to initialize. It must be empty (type NONE).
+     369                 :            :  * \param key       The PSA key to wrap, which must hold an ECC or RSA key
+     370                 :            :  *                  pair (see notes below).
+     371                 :            :  *
+     372                 :            :  * \note            The wrapped key must remain valid as long as the
+     373                 :            :  *                  wrapping PK context is in use, that is at least between
+     374                 :            :  *                  the point this function is called and the point
+     375                 :            :  *                  mbedtls_pk_free() is called on this context. The wrapped
+     376                 :            :  *                  key might then be independently used or destroyed.
+     377                 :            :  *
+     378                 :            :  * \note            This function is currently only available for ECC or RSA
+     379                 :            :  *                  key pairs (that is, keys containing private key material).
+     380                 :            :  *                  Support for other key types may be added later.
+     381                 :            :  *
+     382                 :            :  * \return          \c 0 on success.
+     383                 :            :  * \return          #MBEDTLS_ERR_PK_BAD_INPUT_DATA on invalid input
+     384                 :            :  *                  (context already used, invalid key identifier).
+     385                 :            :  * \return          #MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE if the key is not an
+     386                 :            :  *                  ECC key pair.
+     387                 :            :  * \return          #MBEDTLS_ERR_PK_ALLOC_FAILED on allocation failure.
+     388                 :            :  */
+     389                 :            : int mbedtls_pk_setup_opaque(mbedtls_pk_context *ctx,
+     390                 :            :                             const mbedtls_svc_key_id_t key);
+     391                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO */
+     392                 :            : 
+     393                 :            : #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
+     394                 :            : /**
+     395                 :            :  * \brief           Initialize an RSA-alt context
+     396                 :            :  *
+     397                 :            :  * \param ctx       Context to initialize. It must not have been set
+     398                 :            :  *                  up yet (type #MBEDTLS_PK_NONE).
+     399                 :            :  * \param key       RSA key pointer
+     400                 :            :  * \param decrypt_func  Decryption function
+     401                 :            :  * \param sign_func     Signing function
+     402                 :            :  * \param key_len_func  Function returning key length in bytes
+     403                 :            :  *
+     404                 :            :  * \return          0 on success, or MBEDTLS_ERR_PK_BAD_INPUT_DATA if the
+     405                 :            :  *                  context wasn't already initialized as RSA_ALT.
+     406                 :            :  *
+     407                 :            :  * \note            This function replaces \c mbedtls_pk_setup() for RSA-alt.
+     408                 :            :  */
+     409                 :            : int mbedtls_pk_setup_rsa_alt(mbedtls_pk_context *ctx, void *key,
+     410                 :            :                              mbedtls_pk_rsa_alt_decrypt_func decrypt_func,
+     411                 :            :                              mbedtls_pk_rsa_alt_sign_func sign_func,
+     412                 :            :                              mbedtls_pk_rsa_alt_key_len_func key_len_func);
+     413                 :            : #endif /* MBEDTLS_PK_RSA_ALT_SUPPORT */
+     414                 :            : 
+     415                 :            : /**
+     416                 :            :  * \brief           Get the size in bits of the underlying key
+     417                 :            :  *
+     418                 :            :  * \param ctx       The context to query. It must have been initialized.
+     419                 :            :  *
+     420                 :            :  * \return          Key size in bits, or 0 on error
+     421                 :            :  */
+     422                 :            : size_t mbedtls_pk_get_bitlen(const mbedtls_pk_context *ctx);
+     423                 :            : 
+     424                 :            : /**
+     425                 :            :  * \brief           Get the length in bytes of the underlying key
+     426                 :            :  *
+     427                 :            :  * \param ctx       The context to query. It must have been initialized.
+     428                 :            :  *
+     429                 :            :  * \return          Key length in bytes, or 0 on error
+     430                 :            :  */
+     431                 :          0 : static inline size_t mbedtls_pk_get_len(const mbedtls_pk_context *ctx)
+     432                 :            : {
+     433                 :          0 :     return (mbedtls_pk_get_bitlen(ctx) + 7) / 8;
+     434                 :            : }
+     435                 :            : 
+     436                 :            : /**
+     437                 :            :  * \brief           Tell if a context can do the operation given by type
+     438                 :            :  *
+     439                 :            :  * \param ctx       The context to query. It must have been initialized.
+     440                 :            :  * \param type      The desired type.
+     441                 :            :  *
+     442                 :            :  * \return          1 if the context can do operations on the given type.
+     443                 :            :  * \return          0 if the context cannot do the operations on the given
+     444                 :            :  *                  type. This is always the case for a context that has
+     445                 :            :  *                  been initialized but not set up, or that has been
+     446                 :            :  *                  cleared with mbedtls_pk_free().
+     447                 :            :  */
+     448                 :            : int mbedtls_pk_can_do(const mbedtls_pk_context *ctx, mbedtls_pk_type_t type);
+     449                 :            : 
+     450                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+     451                 :            : /**
+     452                 :            :  * \brief           Tell if context can do the operation given by PSA algorithm
+     453                 :            :  *
+     454                 :            :  * \param ctx       The context to query. It must have been initialized.
+     455                 :            :  * \param alg       PSA algorithm to check against, the following are allowed:
+     456                 :            :  *                  PSA_ALG_RSA_PKCS1V15_SIGN(hash),
+     457                 :            :  *                  PSA_ALG_RSA_PSS(hash),
+     458                 :            :  *                  PSA_ALG_RSA_PKCS1V15_CRYPT,
+     459                 :            :  *                  PSA_ALG_ECDSA(hash),
+     460                 :            :  *                  PSA_ALG_ECDH, where hash is a specific hash.
+     461                 :            :  * \param usage     PSA usage flag to check against, must be composed of:
+     462                 :            :  *                  PSA_KEY_USAGE_SIGN_HASH
+     463                 :            :  *                  PSA_KEY_USAGE_DECRYPT
+     464                 :            :  *                  PSA_KEY_USAGE_DERIVE.
+     465                 :            :  *                  Context key must match all passed usage flags.
+     466                 :            :  *
+     467                 :            :  * \warning         Since the set of allowed algorithms and usage flags may be
+     468                 :            :  *                  expanded in the future, the return value \c 0 should not
+     469                 :            :  *                  be taken in account for non-allowed algorithms and usage
+     470                 :            :  *                  flags.
+     471                 :            :  *
+     472                 :            :  * \return          1 if the context can do operations on the given type.
+     473                 :            :  * \return          0 if the context cannot do the operations on the given
+     474                 :            :  *                  type, for non-allowed algorithms and usage flags, or
+     475                 :            :  *                  for a context that has been initialized but not set up
+     476                 :            :  *                  or that has been cleared with mbedtls_pk_free().
+     477                 :            :  */
+     478                 :            : int mbedtls_pk_can_do_ext(const mbedtls_pk_context *ctx, psa_algorithm_t alg,
+     479                 :            :                           psa_key_usage_t usage);
+     480                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO */
+     481                 :            : 
+     482                 :            : #if defined(MBEDTLS_PSA_CRYPTO_CLIENT)
+     483                 :            : /**
+     484                 :            :  * \brief           Determine valid PSA attributes that can be used to
+     485                 :            :  *                  import a key into PSA.
+     486                 :            :  *
+     487                 :            :  * The attributes determined by this function are suitable
+     488                 :            :  * for calling mbedtls_pk_import_into_psa() to create
+     489                 :            :  * a PSA key with the same key material.
+     490                 :            :  *
+     491                 :            :  * The typical flow of operations involving this function is
+     492                 :            :  * ```
+     493                 :            :  * psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
+     494                 :            :  * int ret = mbedtls_pk_get_psa_attributes(pk, &attributes);
+     495                 :            :  * if (ret != 0) ...; // error handling omitted
+     496                 :            :  * // Tweak attributes if desired
+     497                 :            :  * psa_key_id_t key_id = 0;
+     498                 :            :  * ret = mbedtls_pk_import_into_psa(pk, &attributes, &key_id);
+     499                 :            :  * if (ret != 0) ...; // error handling omitted
+     500                 :            :  * ```
+     501                 :            :  *
+     502                 :            :  * \note            This function does not support RSA-alt contexts
+     503                 :            :  *                  (set up with mbedtls_pk_setup_rsa_alt()).
+     504                 :            :  *
+     505                 :            :  * \param[in] pk    The PK context to use. It must have been set up.
+     506                 :            :  *                  It can either contain a key pair or just a public key.
+     507                 :            :  * \param usage     A single `PSA_KEY_USAGE_xxx` flag among the following:
+     508                 :            :  *                  - #PSA_KEY_USAGE_DECRYPT: \p pk must contain a
+     509                 :            :  *                    key pair. The output \p attributes will contain a
+     510                 :            :  *                    key pair type, and the usage policy will allow
+     511                 :            :  *                    #PSA_KEY_USAGE_ENCRYPT as well as
+     512                 :            :  *                    #PSA_KEY_USAGE_DECRYPT.
+     513                 :            :  *                  - #PSA_KEY_USAGE_DERIVE: \p pk must contain a
+     514                 :            :  *                    key pair. The output \p attributes will contain a
+     515                 :            :  *                    key pair type.
+     516                 :            :  *                  - #PSA_KEY_USAGE_ENCRYPT: The output
+     517                 :            :  *                    \p attributes will contain a public key type.
+     518                 :            :  *                  - #PSA_KEY_USAGE_SIGN_HASH: \p pk must contain a
+     519                 :            :  *                    key pair. The output \p attributes will contain a
+     520                 :            :  *                    key pair type, and the usage policy will allow
+     521                 :            :  *                    #PSA_KEY_USAGE_VERIFY_HASH as well as
+     522                 :            :  *                    #PSA_KEY_USAGE_SIGN_HASH.
+     523                 :            :  *                  - #PSA_KEY_USAGE_SIGN_MESSAGE: \p pk must contain a
+     524                 :            :  *                    key pair. The output \p attributes will contain a
+     525                 :            :  *                    key pair type, and the usage policy will allow
+     526                 :            :  *                    #PSA_KEY_USAGE_VERIFY_MESSAGE as well as
+     527                 :            :  *                    #PSA_KEY_USAGE_SIGN_MESSAGE.
+     528                 :            :  *                  - #PSA_KEY_USAGE_VERIFY_HASH: The output
+     529                 :            :  *                    \p attributes will contain a public key type.
+     530                 :            :  *                  - #PSA_KEY_USAGE_VERIFY_MESSAGE: The output
+     531                 :            :  *                    \p attributes will contain a public key type.
+     532                 :            :  * \param[out] attributes
+     533                 :            :  *                  On success, valid attributes to import the key into PSA.
+     534                 :            :  *                  - The lifetime and key identifier are unchanged. If the
+     535                 :            :  *                    attribute structure was initialized or reset before
+     536                 :            :  *                    calling this function, this will result in a volatile
+     537                 :            :  *                    key. Call psa_set_key_identifier() before or after this
+     538                 :            :  *                    function if you wish to create a persistent key. Call
+     539                 :            :  *                    psa_set_key_lifetime() before or after this function if
+     540                 :            :  *                    you wish to import the key in a secure element.
+     541                 :            :  *                  - The key type and bit-size are determined by the contents
+     542                 :            :  *                    of the PK context. If the PK context contains a key
+     543                 :            :  *                    pair, the key type can be either a key pair type or
+     544                 :            :  *                    the corresponding public key type, depending on
+     545                 :            :  *                    \p usage. If the PK context contains a public key,
+     546                 :            :  *                    the key type is a public key type.
+     547                 :            :  *                  - The key's policy is determined by the key type and
+     548                 :            :  *                    the \p usage parameter. The usage always allows
+     549                 :            :  *                    \p usage, exporting and copying the key, and
+     550                 :            :  *                    possibly other permissions as documented for the
+     551                 :            :  *                    \p usage parameter.
+     552                 :            :  *                    The permitted algorithm policy is determined as follows
+     553                 :            :  *                    based on the #mbedtls_pk_type_t type of \p pk,
+     554                 :            :  *                    the chosen \p usage and other factors:
+     555                 :            :  *                      - #MBEDTLS_PK_RSA whose underlying
+     556                 :            :  *                        #mbedtls_rsa_context has the padding mode
+     557                 :            :  *                        #MBEDTLS_RSA_PKCS_V15:
+     558                 :            :  *                        #PSA_ALG_RSA_PKCS1V15_SIGN(#PSA_ALG_ANY_HASH)
+     559                 :            :  *                        if \p usage is SIGN/VERIFY, and
+     560                 :            :  *                        #PSA_ALG_RSA_PKCS1V15_CRYPT
+     561                 :            :  *                        if \p usage is ENCRYPT/DECRYPT.
+     562                 :            :  *                      - #MBEDTLS_PK_RSA whose underlying
+     563                 :            :  *                        #mbedtls_rsa_context has the padding mode
+     564                 :            :  *                        #MBEDTLS_RSA_PKCS_V21 and the digest type
+     565                 :            :  *                        corresponding to the PSA algorithm \c hash:
+     566                 :            :  *                        #PSA_ALG_RSA_PSS_ANY_SALT(#PSA_ALG_ANY_HASH)
+     567                 :            :  *                        if \p usage is SIGN/VERIFY, and
+     568                 :            :  *                        #PSA_ALG_RSA_OAEP(\c hash)
+     569                 :            :  *                        if \p usage is ENCRYPT/DECRYPT.
+     570                 :            :  *                      - #MBEDTLS_PK_RSA_ALT: not supported.
+     571                 :            :  *                      - #MBEDTLS_PK_ECDSA or #MBEDTLS_PK_ECKEY
+     572                 :            :  *                        if \p usage is SIGN/VERIFY:
+     573                 :            :  *                        #PSA_ALG_DETERMINISTIC_ECDSA(#PSA_ALG_ANY_HASH)
+     574                 :            :  *                        if #MBEDTLS_ECDSA_DETERMINISTIC is enabled,
+     575                 :            :  *                        otherwise #PSA_ALG_ECDSA(#PSA_ALG_ANY_HASH).
+     576                 :            :  *                      - #MBEDTLS_PK_ECKEY_DH or #MBEDTLS_PK_ECKEY
+     577                 :            :  *                        if \p usage is DERIVE:
+     578                 :            :  *                        #PSA_ALG_ECDH.
+     579                 :            :  *                      - #MBEDTLS_PK_OPAQUE: same as the primary algorithm
+     580                 :            :  *                        set for the underlying PSA key, except that
+     581                 :            :  *                        sign/decrypt flags are removed if the type is
+     582                 :            :  *                        set to a public key type.
+     583                 :            :  *                        The underlying key must allow \p usage.
+     584                 :            :  *                        Note that the enrollment algorithm set with
+     585                 :            :  *                        psa_set_key_enrollment_algorithm() is not copied.
+     586                 :            :  *
+     587                 :            :  * \return          0 on success.
+     588                 :            :  *                  #MBEDTLS_ERR_PK_TYPE_MISMATCH if \p pk does not contain
+     589                 :            :  *                  a key of the type identified in \p attributes.
+     590                 :            :  *                  Another error code on other failures.
+     591                 :            :  */
+     592                 :            : int mbedtls_pk_get_psa_attributes(const mbedtls_pk_context *pk,
+     593                 :            :                                   psa_key_usage_t usage,
+     594                 :            :                                   psa_key_attributes_t *attributes);
+     595                 :            : 
+     596                 :            : /**
+     597                 :            :  * \brief           Import a key into the PSA key store.
+     598                 :            :  *
+     599                 :            :  * This function is equivalent to calling psa_import_key()
+     600                 :            :  * with the key material from \p pk.
+     601                 :            :  *
+     602                 :            :  * The typical way to use this function is:
+     603                 :            :  * -# Call mbedtls_pk_get_psa_attributes() to obtain
+     604                 :            :  *    attributes for the given key.
+     605                 :            :  * -# If desired, modify the attributes, for example:
+     606                 :            :  *     - To create a persistent key, call
+     607                 :            :  *       psa_set_key_identifier() and optionally
+     608                 :            :  *       psa_set_key_lifetime().
+     609                 :            :  *     - To import only the public part of a key pair:
+     610                 :            :  *
+     611                 :            :  *           psa_set_key_type(&attributes,
+     612                 :            :  *                            PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(
+     613                 :            :  *                                psa_get_key_type(&attributes)));
+     614                 :            :  *     - Restrict the key usage if desired.
+     615                 :            :  * -# Call mbedtls_pk_import_into_psa().
+     616                 :            :  *
+     617                 :            :  * \note            This function does not support RSA-alt contexts
+     618                 :            :  *                  (set up with mbedtls_pk_setup_rsa_alt()).
+     619                 :            :  *
+     620                 :            :  * \param[in] pk    The PK context to use. It must have been set up.
+     621                 :            :  *                  It can either contain a key pair or just a public key.
+     622                 :            :  * \param[in] attributes
+     623                 :            :  *                  The attributes to use for the new key. They must be
+     624                 :            :  *                  compatible with \p pk. In particular, the key type
+     625                 :            :  *                  must match the content of \p pk.
+     626                 :            :  *                  If \p pk contains a key pair, the key type in
+     627                 :            :  *                  attributes can be either the key pair type or the
+     628                 :            :  *                  corresponding public key type (to import only the
+     629                 :            :  *                  public part).
+     630                 :            :  * \param[out] key_id
+     631                 :            :  *                  On success, the identifier of the newly created key.
+     632                 :            :  *                  On error, this is #MBEDTLS_SVC_KEY_ID_INIT.
+     633                 :            :  *
+     634                 :            :  * \return          0 on success.
+     635                 :            :  *                  #MBEDTLS_ERR_PK_TYPE_MISMATCH if \p pk does not contain
+     636                 :            :  *                  a key of the type identified in \p attributes.
+     637                 :            :  *                  Another error code on other failures.
+     638                 :            :  */
+     639                 :            : int mbedtls_pk_import_into_psa(const mbedtls_pk_context *pk,
+     640                 :            :                                const psa_key_attributes_t *attributes,
+     641                 :            :                                mbedtls_svc_key_id_t *key_id);
+     642                 :            : 
+     643                 :            : /**
+     644                 :            :  * \brief           Create a PK context starting from a key stored in PSA.
+     645                 :            :  *                  This key:
+     646                 :            :  *                  - must be exportable and
+     647                 :            :  *                  - must be an RSA or EC key pair or public key (FFDH is not supported in PK).
+     648                 :            :  *
+     649                 :            :  *                  The resulting PK object will be a transparent type:
+     650                 :            :  *                  - #MBEDTLS_PK_RSA for RSA keys or
+     651                 :            :  *                  - #MBEDTLS_PK_ECKEY for EC keys.
+     652                 :            :  *
+     653                 :            :  *                  Once this functions returns the PK object will be completely
+     654                 :            :  *                  independent from the original PSA key that it was generated
+     655                 :            :  *                  from.
+     656                 :            :  *                  Calling mbedtls_pk_sign(), mbedtls_pk_verify(),
+     657                 :            :  *                  mbedtls_pk_encrypt(), mbedtls_pk_decrypt() on the resulting
+     658                 :            :  *                  PK context will perform the corresponding algorithm for that
+     659                 :            :  *                  PK context type.
+     660                 :            :  *                  * For ECDSA, the choice of deterministic vs randomized will
+     661                 :            :  *                    be based on the compile-time setting #MBEDTLS_ECDSA_DETERMINISTIC.
+     662                 :            :  *                  * For an RSA key, the output PK context will allow both
+     663                 :            :  *                    encrypt/decrypt and sign/verify regardless of the original
+     664                 :            :  *                    key's policy.
+     665                 :            :  *                    The original key's policy determines the output key's padding
+     666                 :            :  *                    mode: PCKS1 v2.1 is set if the PSA key policy is OAEP or PSS,
+     667                 :            :  *                    otherwise PKCS1 v1.5 is set.
+     668                 :            :  *
+     669                 :            :  * \param key_id    The key identifier of the key stored in PSA.
+     670                 :            :  * \param pk        The PK context that will be filled. It must be initialized,
+     671                 :            :  *                  but not set up.
+     672                 :            :  *
+     673                 :            :  * \return          0 on success.
+     674                 :            :  * \return          #MBEDTLS_ERR_PK_BAD_INPUT_DATA in case the provided input
+     675                 :            :  *                  parameters are not correct.
+     676                 :            :  */
+     677                 :            : int mbedtls_pk_copy_from_psa(mbedtls_svc_key_id_t key_id, mbedtls_pk_context *pk);
+     678                 :            : 
+     679                 :            : /**
+     680                 :            :  * \brief           Create a PK context for the public key of a PSA key.
+     681                 :            :  *
+     682                 :            :  *                  The key must be an RSA or ECC key. It can be either a
+     683                 :            :  *                  public key or a key pair, and only the public key is copied.
+     684                 :            :  *                  The resulting PK object will be a transparent type:
+     685                 :            :  *                  - #MBEDTLS_PK_RSA for RSA keys or
+     686                 :            :  *                  - #MBEDTLS_PK_ECKEY for EC keys.
+     687                 :            :  *
+     688                 :            :  *                  Once this functions returns the PK object will be completely
+     689                 :            :  *                  independent from the original PSA key that it was generated
+     690                 :            :  *                  from.
+     691                 :            :  *                  Calling mbedtls_pk_verify() or
+     692                 :            :  *                  mbedtls_pk_encrypt() on the resulting
+     693                 :            :  *                  PK context will perform the corresponding algorithm for that
+     694                 :            :  *                  PK context type.
+     695                 :            :  *
+     696                 :            :  *                  For an RSA key, the output PK context will allow both
+     697                 :            :  *                  encrypt and verify regardless of the original key's policy.
+     698                 :            :  *                  The original key's policy determines the output key's padding
+     699                 :            :  *                  mode: PCKS1 v2.1 is set if the PSA key policy is OAEP or PSS,
+     700                 :            :  *                  otherwise PKCS1 v1.5 is set.
+     701                 :            :  *
+     702                 :            :  * \param key_id    The key identifier of the key stored in PSA.
+     703                 :            :  * \param pk        The PK context that will be filled. It must be initialized,
+     704                 :            :  *                  but not set up.
+     705                 :            :  *
+     706                 :            :  * \return          0 on success.
+     707                 :            :  * \return          MBEDTLS_ERR_PK_BAD_INPUT_DATA in case the provided input
+     708                 :            :  *                  parameters are not correct.
+     709                 :            :  */
+     710                 :            : int mbedtls_pk_copy_public_from_psa(mbedtls_svc_key_id_t key_id, mbedtls_pk_context *pk);
+     711                 :            : #endif /* MBEDTLS_PSA_CRYPTO_CLIENT */
+     712                 :            : 
+     713                 :            : /**
+     714                 :            :  * \brief           Verify signature (including padding if relevant).
+     715                 :            :  *
+     716                 :            :  * \param ctx       The PK context to use. It must have been set up.
+     717                 :            :  * \param md_alg    Hash algorithm used.
+     718                 :            :  *                  This can be #MBEDTLS_MD_NONE if the signature algorithm
+     719                 :            :  *                  does not rely on a hash algorithm (non-deterministic
+     720                 :            :  *                  ECDSA, RSA PKCS#1 v1.5).
+     721                 :            :  *                  For PKCS#1 v1.5, if \p md_alg is #MBEDTLS_MD_NONE, then
+     722                 :            :  *                  \p hash is the DigestInfo structure used by RFC 8017
+     723                 :            :  *                  &sect;9.2 steps 3&ndash;6. If \p md_alg is a valid hash
+     724                 :            :  *                  algorithm then \p hash is the digest itself, and this
+     725                 :            :  *                  function calculates the DigestInfo encoding internally.
+     726                 :            :  * \param hash      Hash of the message to sign
+     727                 :            :  * \param hash_len  Hash length
+     728                 :            :  * \param sig       Signature to verify
+     729                 :            :  * \param sig_len   Signature length
+     730                 :            :  *
+     731                 :            :  * \note            For keys of type #MBEDTLS_PK_RSA, the signature algorithm is
+     732                 :            :  *                  either PKCS#1 v1.5 or PSS (accepting any salt length),
+     733                 :            :  *                  depending on the padding mode in the underlying RSA context.
+     734                 :            :  *                  For a pk object constructed by parsing, this is PKCS#1 v1.5
+     735                 :            :  *                  by default. Use mbedtls_pk_verify_ext() to explicitly select
+     736                 :            :  *                  a different algorithm.
+     737                 :            :  *
+     738                 :            :  * \return          0 on success (signature is valid),
+     739                 :            :  *                  #MBEDTLS_ERR_PK_SIG_LEN_MISMATCH if there is a valid
+     740                 :            :  *                  signature in \p sig but its length is less than \p sig_len,
+     741                 :            :  *                  or a specific error code.
+     742                 :            :  */
+     743                 :            : int mbedtls_pk_verify(mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg,
+     744                 :            :                       const unsigned char *hash, size_t hash_len,
+     745                 :            :                       const unsigned char *sig, size_t sig_len);
+     746                 :            : 
+     747                 :            : /**
+     748                 :            :  * \brief           Restartable version of \c mbedtls_pk_verify()
+     749                 :            :  *
+     750                 :            :  * \note            Performs the same job as \c mbedtls_pk_verify(), but can
+     751                 :            :  *                  return early and restart according to the limit set with
+     752                 :            :  *                  \c mbedtls_ecp_set_max_ops() to reduce blocking for ECC
+     753                 :            :  *                  operations. For RSA, same as \c mbedtls_pk_verify().
+     754                 :            :  *
+     755                 :            :  * \param ctx       The PK context to use. It must have been set up.
+     756                 :            :  * \param md_alg    Hash algorithm used (see notes)
+     757                 :            :  * \param hash      Hash of the message to sign
+     758                 :            :  * \param hash_len  Hash length or 0 (see notes)
+     759                 :            :  * \param sig       Signature to verify
+     760                 :            :  * \param sig_len   Signature length
+     761                 :            :  * \param rs_ctx    Restart context (NULL to disable restart)
+     762                 :            :  *
+     763                 :            :  * \return          See \c mbedtls_pk_verify(), or
+     764                 :            :  * \return          #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of
+     765                 :            :  *                  operations was reached: see \c mbedtls_ecp_set_max_ops().
+     766                 :            :  */
+     767                 :            : int mbedtls_pk_verify_restartable(mbedtls_pk_context *ctx,
+     768                 :            :                                   mbedtls_md_type_t md_alg,
+     769                 :            :                                   const unsigned char *hash, size_t hash_len,
+     770                 :            :                                   const unsigned char *sig, size_t sig_len,
+     771                 :            :                                   mbedtls_pk_restart_ctx *rs_ctx);
+     772                 :            : 
+     773                 :            : /**
+     774                 :            :  * \brief           Verify signature, with options.
+     775                 :            :  *                  (Includes verification of the padding depending on type.)
+     776                 :            :  *
+     777                 :            :  * \param type      Signature type (inc. possible padding type) to verify
+     778                 :            :  * \param options   Pointer to type-specific options, or NULL
+     779                 :            :  * \param ctx       The PK context to use. It must have been set up.
+     780                 :            :  * \param md_alg    Hash algorithm used (see notes)
+     781                 :            :  * \param hash      Hash of the message to sign
+     782                 :            :  * \param hash_len  Hash length or 0 (see notes)
+     783                 :            :  * \param sig       Signature to verify
+     784                 :            :  * \param sig_len   Signature length
+     785                 :            :  *
+     786                 :            :  * \return          0 on success (signature is valid),
+     787                 :            :  *                  #MBEDTLS_ERR_PK_TYPE_MISMATCH if the PK context can't be
+     788                 :            :  *                  used for this type of signatures,
+     789                 :            :  *                  #MBEDTLS_ERR_PK_SIG_LEN_MISMATCH if there is a valid
+     790                 :            :  *                  signature in \p sig but its length is less than \p sig_len,
+     791                 :            :  *                  or a specific error code.
+     792                 :            :  *
+     793                 :            :  * \note            If hash_len is 0, then the length associated with md_alg
+     794                 :            :  *                  is used instead, or an error returned if it is invalid.
+     795                 :            :  *
+     796                 :            :  * \note            md_alg may be MBEDTLS_MD_NONE, only if hash_len != 0
+     797                 :            :  *
+     798                 :            :  * \note            If type is MBEDTLS_PK_RSASSA_PSS, then options must point
+     799                 :            :  *                  to a mbedtls_pk_rsassa_pss_options structure,
+     800                 :            :  *                  otherwise it must be NULL. Note that if
+     801                 :            :  *                  #MBEDTLS_USE_PSA_CRYPTO is defined, the salt length is not
+     802                 :            :  *                  verified as PSA_ALG_RSA_PSS_ANY_SALT is used.
+     803                 :            :  */
+     804                 :            : int mbedtls_pk_verify_ext(mbedtls_pk_type_t type, const void *options,
+     805                 :            :                           mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg,
+     806                 :            :                           const unsigned char *hash, size_t hash_len,
+     807                 :            :                           const unsigned char *sig, size_t sig_len);
+     808                 :            : 
+     809                 :            : /**
+     810                 :            :  * \brief           Make signature, including padding if relevant.
+     811                 :            :  *
+     812                 :            :  * \param ctx       The PK context to use. It must have been set up
+     813                 :            :  *                  with a private key.
+     814                 :            :  * \param md_alg    Hash algorithm used (see notes)
+     815                 :            :  * \param hash      Hash of the message to sign
+     816                 :            :  * \param hash_len  Hash length
+     817                 :            :  * \param sig       Place to write the signature.
+     818                 :            :  *                  It must have enough room for the signature.
+     819                 :            :  *                  #MBEDTLS_PK_SIGNATURE_MAX_SIZE is always enough.
+     820                 :            :  *                  You may use a smaller buffer if it is large enough
+     821                 :            :  *                  given the key type.
+     822                 :            :  * \param sig_size  The size of the \p sig buffer in bytes.
+     823                 :            :  * \param sig_len   On successful return,
+     824                 :            :  *                  the number of bytes written to \p sig.
+     825                 :            :  * \param f_rng     RNG function, must not be \c NULL.
+     826                 :            :  * \param p_rng     RNG parameter
+     827                 :            :  *
+     828                 :            :  * \note            For keys of type #MBEDTLS_PK_RSA, the signature algorithm is
+     829                 :            :  *                  either PKCS#1 v1.5 or PSS (using the largest possible salt
+     830                 :            :  *                  length up to the hash length), depending on the padding mode
+     831                 :            :  *                  in the underlying RSA context. For a pk object constructed
+     832                 :            :  *                  by parsing, this is PKCS#1 v1.5 by default. Use
+     833                 :            :  *                  mbedtls_pk_verify_ext() to explicitly select a different
+     834                 :            :  *                  algorithm.
+     835                 :            :  *
+     836                 :            :  * \return          0 on success, or a specific error code.
+     837                 :            :  *
+     838                 :            :  * \note            For RSA, md_alg may be MBEDTLS_MD_NONE if hash_len != 0.
+     839                 :            :  *                  For ECDSA, md_alg may never be MBEDTLS_MD_NONE.
+     840                 :            :  */
+     841                 :            : int mbedtls_pk_sign(mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg,
+     842                 :            :                     const unsigned char *hash, size_t hash_len,
+     843                 :            :                     unsigned char *sig, size_t sig_size, size_t *sig_len,
+     844                 :            :                     int (*f_rng)(void *, unsigned char *, size_t), void *p_rng);
+     845                 :            : 
+     846                 :            : /**
+     847                 :            :  * \brief           Make signature given a signature type.
+     848                 :            :  *
+     849                 :            :  * \param pk_type   Signature type.
+     850                 :            :  * \param ctx       The PK context to use. It must have been set up
+     851                 :            :  *                  with a private key.
+     852                 :            :  * \param md_alg    Hash algorithm used (see notes)
+     853                 :            :  * \param hash      Hash of the message to sign
+     854                 :            :  * \param hash_len  Hash length
+     855                 :            :  * \param sig       Place to write the signature.
+     856                 :            :  *                  It must have enough room for the signature.
+     857                 :            :  *                  #MBEDTLS_PK_SIGNATURE_MAX_SIZE is always enough.
+     858                 :            :  *                  You may use a smaller buffer if it is large enough
+     859                 :            :  *                  given the key type.
+     860                 :            :  * \param sig_size  The size of the \p sig buffer in bytes.
+     861                 :            :  * \param sig_len   On successful return,
+     862                 :            :  *                  the number of bytes written to \p sig.
+     863                 :            :  * \param f_rng     RNG function, must not be \c NULL.
+     864                 :            :  * \param p_rng     RNG parameter
+     865                 :            :  *
+     866                 :            :  * \return          0 on success, or a specific error code.
+     867                 :            :  *
+     868                 :            :  * \note            When \p pk_type is #MBEDTLS_PK_RSASSA_PSS,
+     869                 :            :  *                  see #PSA_ALG_RSA_PSS for a description of PSS options used.
+     870                 :            :  *
+     871                 :            :  * \note            For RSA, md_alg may be MBEDTLS_MD_NONE if hash_len != 0.
+     872                 :            :  *                  For ECDSA, md_alg may never be MBEDTLS_MD_NONE.
+     873                 :            :  *
+     874                 :            :  */
+     875                 :            : int mbedtls_pk_sign_ext(mbedtls_pk_type_t pk_type,
+     876                 :            :                         mbedtls_pk_context *ctx,
+     877                 :            :                         mbedtls_md_type_t md_alg,
+     878                 :            :                         const unsigned char *hash, size_t hash_len,
+     879                 :            :                         unsigned char *sig, size_t sig_size, size_t *sig_len,
+     880                 :            :                         int (*f_rng)(void *, unsigned char *, size_t),
+     881                 :            :                         void *p_rng);
+     882                 :            : 
+     883                 :            : /**
+     884                 :            :  * \brief           Restartable version of \c mbedtls_pk_sign()
+     885                 :            :  *
+     886                 :            :  * \note            Performs the same job as \c mbedtls_pk_sign(), but can
+     887                 :            :  *                  return early and restart according to the limit set with
+     888                 :            :  *                  \c mbedtls_ecp_set_max_ops() to reduce blocking for ECC
+     889                 :            :  *                  operations. For RSA, same as \c mbedtls_pk_sign().
+     890                 :            :  *
+     891                 :            :  * \param ctx       The PK context to use. It must have been set up
+     892                 :            :  *                  with a private key.
+     893                 :            :  * \param md_alg    Hash algorithm used (see notes for mbedtls_pk_sign())
+     894                 :            :  * \param hash      Hash of the message to sign
+     895                 :            :  * \param hash_len  Hash length
+     896                 :            :  * \param sig       Place to write the signature.
+     897                 :            :  *                  It must have enough room for the signature.
+     898                 :            :  *                  #MBEDTLS_PK_SIGNATURE_MAX_SIZE is always enough.
+     899                 :            :  *                  You may use a smaller buffer if it is large enough
+     900                 :            :  *                  given the key type.
+     901                 :            :  * \param sig_size  The size of the \p sig buffer in bytes.
+     902                 :            :  * \param sig_len   On successful return,
+     903                 :            :  *                  the number of bytes written to \p sig.
+     904                 :            :  * \param f_rng     RNG function, must not be \c NULL.
+     905                 :            :  * \param p_rng     RNG parameter
+     906                 :            :  * \param rs_ctx    Restart context (NULL to disable restart)
+     907                 :            :  *
+     908                 :            :  * \return          See \c mbedtls_pk_sign().
+     909                 :            :  * \return          #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of
+     910                 :            :  *                  operations was reached: see \c mbedtls_ecp_set_max_ops().
+     911                 :            :  */
+     912                 :            : int mbedtls_pk_sign_restartable(mbedtls_pk_context *ctx,
+     913                 :            :                                 mbedtls_md_type_t md_alg,
+     914                 :            :                                 const unsigned char *hash, size_t hash_len,
+     915                 :            :                                 unsigned char *sig, size_t sig_size, size_t *sig_len,
+     916                 :            :                                 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
+     917                 :            :                                 mbedtls_pk_restart_ctx *rs_ctx);
+     918                 :            : 
+     919                 :            : /**
+     920                 :            :  * \brief           Decrypt message (including padding if relevant).
+     921                 :            :  *
+     922                 :            :  * \param ctx       The PK context to use. It must have been set up
+     923                 :            :  *                  with a private key.
+     924                 :            :  * \param input     Input to decrypt
+     925                 :            :  * \param ilen      Input size
+     926                 :            :  * \param output    Decrypted output
+     927                 :            :  * \param olen      Decrypted message length
+     928                 :            :  * \param osize     Size of the output buffer
+     929                 :            :  * \param f_rng     RNG function, must not be \c NULL.
+     930                 :            :  * \param p_rng     RNG parameter
+     931                 :            :  *
+     932                 :            :  * \note            For keys of type #MBEDTLS_PK_RSA, the signature algorithm is
+     933                 :            :  *                  either PKCS#1 v1.5 or OAEP, depending on the padding mode in
+     934                 :            :  *                  the underlying RSA context. For a pk object constructed by
+     935                 :            :  *                  parsing, this is PKCS#1 v1.5 by default.
+     936                 :            :  *
+     937                 :            :  * \return          0 on success, or a specific error code.
+     938                 :            :  */
+     939                 :            : int mbedtls_pk_decrypt(mbedtls_pk_context *ctx,
+     940                 :            :                        const unsigned char *input, size_t ilen,
+     941                 :            :                        unsigned char *output, size_t *olen, size_t osize,
+     942                 :            :                        int (*f_rng)(void *, unsigned char *, size_t), void *p_rng);
+     943                 :            : 
+     944                 :            : /**
+     945                 :            :  * \brief           Encrypt message (including padding if relevant).
+     946                 :            :  *
+     947                 :            :  * \param ctx       The PK context to use. It must have been set up.
+     948                 :            :  * \param input     Message to encrypt
+     949                 :            :  * \param ilen      Message size
+     950                 :            :  * \param output    Encrypted output
+     951                 :            :  * \param olen      Encrypted output length
+     952                 :            :  * \param osize     Size of the output buffer
+     953                 :            :  * \param f_rng     RNG function, must not be \c NULL.
+     954                 :            :  * \param p_rng     RNG parameter
+     955                 :            :  *
+     956                 :            :  * \note            For keys of type #MBEDTLS_PK_RSA, the signature algorithm is
+     957                 :            :  *                  either PKCS#1 v1.5 or OAEP, depending on the padding mode in
+     958                 :            :  *                  the underlying RSA context. For a pk object constructed by
+     959                 :            :  *                  parsing, this is PKCS#1 v1.5 by default.
+     960                 :            :  *
+     961                 :            :  * \note            \p f_rng is used for padding generation.
+     962                 :            :  *
+     963                 :            :  * \return          0 on success, or a specific error code.
+     964                 :            :  */
+     965                 :            : int mbedtls_pk_encrypt(mbedtls_pk_context *ctx,
+     966                 :            :                        const unsigned char *input, size_t ilen,
+     967                 :            :                        unsigned char *output, size_t *olen, size_t osize,
+     968                 :            :                        int (*f_rng)(void *, unsigned char *, size_t), void *p_rng);
+     969                 :            : 
+     970                 :            : /**
+     971                 :            :  * \brief           Check if a public-private pair of keys matches.
+     972                 :            :  *
+     973                 :            :  * \param pub       Context holding a public key.
+     974                 :            :  * \param prv       Context holding a private (and public) key.
+     975                 :            :  * \param f_rng     RNG function, must not be \c NULL.
+     976                 :            :  * \param p_rng     RNG parameter
+     977                 :            :  *
+     978                 :            :  * \return          \c 0 on success (keys were checked and match each other).
+     979                 :            :  * \return          #MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE if the keys could not
+     980                 :            :  *                  be checked - in that case they may or may not match.
+     981                 :            :  * \return          #MBEDTLS_ERR_PK_BAD_INPUT_DATA if a context is invalid.
+     982                 :            :  * \return          Another non-zero value if the keys do not match.
+     983                 :            :  */
+     984                 :            : int mbedtls_pk_check_pair(const mbedtls_pk_context *pub,
+     985                 :            :                           const mbedtls_pk_context *prv,
+     986                 :            :                           int (*f_rng)(void *, unsigned char *, size_t),
+     987                 :            :                           void *p_rng);
+     988                 :            : 
+     989                 :            : /**
+     990                 :            :  * \brief           Export debug information
+     991                 :            :  *
+     992                 :            :  * \param ctx       The PK context to use. It must have been initialized.
+     993                 :            :  * \param items     Place to write debug items
+     994                 :            :  *
+     995                 :            :  * \return          0 on success or MBEDTLS_ERR_PK_BAD_INPUT_DATA
+     996                 :            :  */
+     997                 :            : int mbedtls_pk_debug(const mbedtls_pk_context *ctx, mbedtls_pk_debug_item *items);
+     998                 :            : 
+     999                 :            : /**
+    1000                 :            :  * \brief           Access the type name
+    1001                 :            :  *
+    1002                 :            :  * \param ctx       The PK context to use. It must have been initialized.
+    1003                 :            :  *
+    1004                 :            :  * \return          Type name on success, or "invalid PK"
+    1005                 :            :  */
+    1006                 :            : const char *mbedtls_pk_get_name(const mbedtls_pk_context *ctx);
+    1007                 :            : 
+    1008                 :            : /**
+    1009                 :            :  * \brief           Get the key type
+    1010                 :            :  *
+    1011                 :            :  * \param ctx       The PK context to use. It must have been initialized.
+    1012                 :            :  *
+    1013                 :            :  * \return          Type on success.
+    1014                 :            :  * \return          #MBEDTLS_PK_NONE for a context that has not been set up.
+    1015                 :            :  */
+    1016                 :            : mbedtls_pk_type_t mbedtls_pk_get_type(const mbedtls_pk_context *ctx);
+    1017                 :            : 
+    1018                 :            : #if defined(MBEDTLS_RSA_C)
+    1019                 :            : /**
+    1020                 :            :  * Quick access to an RSA context inside a PK context.
+    1021                 :            :  *
+    1022                 :            :  * \warning This function can only be used when the type of the context, as
+    1023                 :            :  * returned by mbedtls_pk_get_type(), is #MBEDTLS_PK_RSA.
+    1024                 :            :  * Ensuring that is the caller's responsibility.
+    1025                 :            :  * Alternatively, you can check whether this function returns NULL.
+    1026                 :            :  *
+    1027                 :            :  * \return The internal RSA context held by the PK context, or NULL.
+    1028                 :            :  */
+    1029                 :       1216 : static inline mbedtls_rsa_context *mbedtls_pk_rsa(const mbedtls_pk_context pk)
+    1030                 :            : {
+    1031         [ +  - ]:       1216 :     switch (mbedtls_pk_get_type(&pk)) {
+    1032                 :       1216 :         case MBEDTLS_PK_RSA:
+    1033                 :       1216 :             return (mbedtls_rsa_context *) (pk).MBEDTLS_PRIVATE(pk_ctx);
+    1034                 :          0 :         default:
+    1035                 :          0 :             return NULL;
+    1036                 :            :     }
+    1037                 :            : }
+    1038                 :            : #endif /* MBEDTLS_RSA_C */
+    1039                 :            : 
+    1040                 :            : #if defined(MBEDTLS_ECP_C)
+    1041                 :            : /**
+    1042                 :            :  * Quick access to an EC context inside a PK context.
+    1043                 :            :  *
+    1044                 :            :  * \warning This function can only be used when the type of the context, as
+    1045                 :            :  * returned by mbedtls_pk_get_type(), is #MBEDTLS_PK_ECKEY,
+    1046                 :            :  * #MBEDTLS_PK_ECKEY_DH, or #MBEDTLS_PK_ECDSA.
+    1047                 :            :  * Ensuring that is the caller's responsibility.
+    1048                 :            :  * Alternatively, you can check whether this function returns NULL.
+    1049                 :            :  *
+    1050                 :            :  * \return The internal EC context held by the PK context, or NULL.
+    1051                 :            :  */
+    1052                 :       1019 : static inline mbedtls_ecp_keypair *mbedtls_pk_ec(const mbedtls_pk_context pk)
+    1053                 :            : {
+    1054         [ +  - ]:       1019 :     switch (mbedtls_pk_get_type(&pk)) {
+    1055                 :       1019 :         case MBEDTLS_PK_ECKEY:
+    1056                 :            :         case MBEDTLS_PK_ECKEY_DH:
+    1057                 :            :         case MBEDTLS_PK_ECDSA:
+    1058                 :       1019 :             return (mbedtls_ecp_keypair *) (pk).MBEDTLS_PRIVATE(pk_ctx);
+    1059                 :          0 :         default:
+    1060                 :          0 :             return NULL;
+    1061                 :            :     }
+    1062                 :            : }
+    1063                 :            : #endif /* MBEDTLS_ECP_C */
+    1064                 :            : 
+    1065                 :            : #if defined(MBEDTLS_PK_PARSE_C)
+    1066                 :            : /** \ingroup pk_module */
+    1067                 :            : /**
+    1068                 :            :  * \brief           Parse a private key in PEM or DER format
+    1069                 :            :  *
+    1070                 :            :  * \note            If #MBEDTLS_USE_PSA_CRYPTO is enabled, the PSA crypto
+    1071                 :            :  *                  subsystem must have been initialized by calling
+    1072                 :            :  *                  psa_crypto_init() before calling this function.
+    1073                 :            :  *
+    1074                 :            :  * \param ctx       The PK context to fill. It must have been initialized
+    1075                 :            :  *                  but not set up.
+    1076                 :            :  * \param key       Input buffer to parse.
+    1077                 :            :  *                  The buffer must contain the input exactly, with no
+    1078                 :            :  *                  extra trailing material. For PEM, the buffer must
+    1079                 :            :  *                  contain a null-terminated string.
+    1080                 :            :  * \param keylen    Size of \b key in bytes.
+    1081                 :            :  *                  For PEM data, this includes the terminating null byte,
+    1082                 :            :  *                  so \p keylen must be equal to `strlen(key) + 1`.
+    1083                 :            :  * \param pwd       Optional password for decryption.
+    1084                 :            :  *                  Pass \c NULL if expecting a non-encrypted key.
+    1085                 :            :  *                  Pass a string of \p pwdlen bytes if expecting an encrypted
+    1086                 :            :  *                  key; a non-encrypted key will also be accepted.
+    1087                 :            :  *                  The empty password is not supported.
+    1088                 :            :  * \param pwdlen    Size of the password in bytes.
+    1089                 :            :  *                  Ignored if \p pwd is \c NULL.
+    1090                 :            :  * \param f_rng     RNG function, must not be \c NULL. Used for blinding.
+    1091                 :            :  * \param p_rng     RNG parameter
+    1092                 :            :  *
+    1093                 :            :  * \note            On entry, ctx must be empty, either freshly initialised
+    1094                 :            :  *                  with mbedtls_pk_init() or reset with mbedtls_pk_free(). If you need a
+    1095                 :            :  *                  specific key type, check the result with mbedtls_pk_can_do().
+    1096                 :            :  *
+    1097                 :            :  * \note            The key is also checked for correctness.
+    1098                 :            :  *
+    1099                 :            :  * \return          0 if successful, or a specific PK or PEM error code
+    1100                 :            :  */
+    1101                 :            : int mbedtls_pk_parse_key(mbedtls_pk_context *ctx,
+    1102                 :            :                          const unsigned char *key, size_t keylen,
+    1103                 :            :                          const unsigned char *pwd, size_t pwdlen,
+    1104                 :            :                          int (*f_rng)(void *, unsigned char *, size_t), void *p_rng);
+    1105                 :            : 
+    1106                 :            : /** \ingroup pk_module */
+    1107                 :            : /**
+    1108                 :            :  * \brief           Parse a public key in PEM or DER format
+    1109                 :            :  *
+    1110                 :            :  * \note            If #MBEDTLS_USE_PSA_CRYPTO is enabled, the PSA crypto
+    1111                 :            :  *                  subsystem must have been initialized by calling
+    1112                 :            :  *                  psa_crypto_init() before calling this function.
+    1113                 :            :  *
+    1114                 :            :  * \param ctx       The PK context to fill. It must have been initialized
+    1115                 :            :  *                  but not set up.
+    1116                 :            :  * \param key       Input buffer to parse.
+    1117                 :            :  *                  The buffer must contain the input exactly, with no
+    1118                 :            :  *                  extra trailing material. For PEM, the buffer must
+    1119                 :            :  *                  contain a null-terminated string.
+    1120                 :            :  * \param keylen    Size of \b key in bytes.
+    1121                 :            :  *                  For PEM data, this includes the terminating null byte,
+    1122                 :            :  *                  so \p keylen must be equal to `strlen(key) + 1`.
+    1123                 :            :  *
+    1124                 :            :  * \note            On entry, ctx must be empty, either freshly initialised
+    1125                 :            :  *                  with mbedtls_pk_init() or reset with mbedtls_pk_free(). If you need a
+    1126                 :            :  *                  specific key type, check the result with mbedtls_pk_can_do().
+    1127                 :            :  *
+    1128                 :            :  * \note            For compressed points, see #MBEDTLS_ECP_PF_COMPRESSED for
+    1129                 :            :  *                  limitations.
+    1130                 :            :  *
+    1131                 :            :  * \note            The key is also checked for correctness.
+    1132                 :            :  *
+    1133                 :            :  * \return          0 if successful, or a specific PK or PEM error code
+    1134                 :            :  */
+    1135                 :            : int mbedtls_pk_parse_public_key(mbedtls_pk_context *ctx,
+    1136                 :            :                                 const unsigned char *key, size_t keylen);
+    1137                 :            : 
+    1138                 :            : #if defined(MBEDTLS_FS_IO)
+    1139                 :            : /** \ingroup pk_module */
+    1140                 :            : /**
+    1141                 :            :  * \brief           Load and parse a private key
+    1142                 :            :  *
+    1143                 :            :  * \note            If #MBEDTLS_USE_PSA_CRYPTO is enabled, the PSA crypto
+    1144                 :            :  *                  subsystem must have been initialized by calling
+    1145                 :            :  *                  psa_crypto_init() before calling this function.
+    1146                 :            :  *
+    1147                 :            :  * \param ctx       The PK context to fill. It must have been initialized
+    1148                 :            :  *                  but not set up.
+    1149                 :            :  * \param path      filename to read the private key from
+    1150                 :            :  * \param password  Optional password to decrypt the file.
+    1151                 :            :  *                  Pass \c NULL if expecting a non-encrypted key.
+    1152                 :            :  *                  Pass a null-terminated string if expecting an encrypted
+    1153                 :            :  *                  key; a non-encrypted key will also be accepted.
+    1154                 :            :  *                  The empty password is not supported.
+    1155                 :            :  * \param f_rng     RNG function, must not be \c NULL. Used for blinding.
+    1156                 :            :  * \param p_rng     RNG parameter
+    1157                 :            :  *
+    1158                 :            :  * \note            On entry, ctx must be empty, either freshly initialised
+    1159                 :            :  *                  with mbedtls_pk_init() or reset with mbedtls_pk_free(). If you need a
+    1160                 :            :  *                  specific key type, check the result with mbedtls_pk_can_do().
+    1161                 :            :  *
+    1162                 :            :  * \note            The key is also checked for correctness.
+    1163                 :            :  *
+    1164                 :            :  * \return          0 if successful, or a specific PK or PEM error code
+    1165                 :            :  */
+    1166                 :            : int mbedtls_pk_parse_keyfile(mbedtls_pk_context *ctx,
+    1167                 :            :                              const char *path, const char *password,
+    1168                 :            :                              int (*f_rng)(void *, unsigned char *, size_t), void *p_rng);
+    1169                 :            : 
+    1170                 :            : /** \ingroup pk_module */
+    1171                 :            : /**
+    1172                 :            :  * \brief           Load and parse a public key
+    1173                 :            :  *
+    1174                 :            :  * \param ctx       The PK context to fill. It must have been initialized
+    1175                 :            :  *                  but not set up.
+    1176                 :            :  * \param path      filename to read the public key from
+    1177                 :            :  *
+    1178                 :            :  * \note            On entry, ctx must be empty, either freshly initialised
+    1179                 :            :  *                  with mbedtls_pk_init() or reset with mbedtls_pk_free(). If
+    1180                 :            :  *                  you need a specific key type, check the result with
+    1181                 :            :  *                  mbedtls_pk_can_do().
+    1182                 :            :  *
+    1183                 :            :  * \note            The key is also checked for correctness.
+    1184                 :            :  *
+    1185                 :            :  * \return          0 if successful, or a specific PK or PEM error code
+    1186                 :            :  */
+    1187                 :            : int mbedtls_pk_parse_public_keyfile(mbedtls_pk_context *ctx, const char *path);
+    1188                 :            : #endif /* MBEDTLS_FS_IO */
+    1189                 :            : #endif /* MBEDTLS_PK_PARSE_C */
+    1190                 :            : 
+    1191                 :            : #if defined(MBEDTLS_PK_WRITE_C)
+    1192                 :            : /**
+    1193                 :            :  * \brief           Write a private key to a PKCS#1 or SEC1 DER structure
+    1194                 :            :  *                  Note: data is written at the end of the buffer! Use the
+    1195                 :            :  *                        return value to determine where you should start
+    1196                 :            :  *                        using the buffer
+    1197                 :            :  *
+    1198                 :            :  * \param ctx       PK context which must contain a valid private key.
+    1199                 :            :  * \param buf       buffer to write to
+    1200                 :            :  * \param size      size of the buffer
+    1201                 :            :  *
+    1202                 :            :  * \return          length of data written if successful, or a specific
+    1203                 :            :  *                  error code
+    1204                 :            :  */
+    1205                 :            : int mbedtls_pk_write_key_der(const mbedtls_pk_context *ctx, unsigned char *buf, size_t size);
+    1206                 :            : 
+    1207                 :            : /**
+    1208                 :            :  * \brief           Write a public key to a SubjectPublicKeyInfo DER structure
+    1209                 :            :  *                  Note: data is written at the end of the buffer! Use the
+    1210                 :            :  *                        return value to determine where you should start
+    1211                 :            :  *                        using the buffer
+    1212                 :            :  *
+    1213                 :            :  * \param ctx       PK context which must contain a valid public or private key.
+    1214                 :            :  * \param buf       buffer to write to
+    1215                 :            :  * \param size      size of the buffer
+    1216                 :            :  *
+    1217                 :            :  * \return          length of data written if successful, or a specific
+    1218                 :            :  *                  error code
+    1219                 :            :  */
+    1220                 :            : int mbedtls_pk_write_pubkey_der(const mbedtls_pk_context *ctx, unsigned char *buf, size_t size);
+    1221                 :            : 
+    1222                 :            : #if defined(MBEDTLS_PEM_WRITE_C)
+    1223                 :            : /**
+    1224                 :            :  * \brief           Write a public key to a PEM string
+    1225                 :            :  *
+    1226                 :            :  * \param ctx       PK context which must contain a valid public or private key.
+    1227                 :            :  * \param buf       Buffer to write to. The output includes a
+    1228                 :            :  *                  terminating null byte.
+    1229                 :            :  * \param size      Size of the buffer in bytes.
+    1230                 :            :  *
+    1231                 :            :  * \return          0 if successful, or a specific error code
+    1232                 :            :  */
+    1233                 :            : int mbedtls_pk_write_pubkey_pem(const mbedtls_pk_context *ctx, unsigned char *buf, size_t size);
+    1234                 :            : 
+    1235                 :            : /**
+    1236                 :            :  * \brief           Write a private key to a PKCS#1 or SEC1 PEM string
+    1237                 :            :  *
+    1238                 :            :  * \param ctx       PK context which must contain a valid private key.
+    1239                 :            :  * \param buf       Buffer to write to. The output includes a
+    1240                 :            :  *                  terminating null byte.
+    1241                 :            :  * \param size      Size of the buffer in bytes.
+    1242                 :            :  *
+    1243                 :            :  * \return          0 if successful, or a specific error code
+    1244                 :            :  */
+    1245                 :            : int mbedtls_pk_write_key_pem(const mbedtls_pk_context *ctx, unsigned char *buf, size_t size);
+    1246                 :            : #endif /* MBEDTLS_PEM_WRITE_C */
+    1247                 :            : #endif /* MBEDTLS_PK_WRITE_C */
+    1248                 :            : 
+    1249                 :            : /*
+    1250                 :            :  * WARNING: Low-level functions. You probably do not want to use these unless
+    1251                 :            :  *          you are certain you do ;)
+    1252                 :            :  */
+    1253                 :            : 
+    1254                 :            : #if defined(MBEDTLS_PK_PARSE_C)
+    1255                 :            : /**
+    1256                 :            :  * \brief           Parse a SubjectPublicKeyInfo DER structure
+    1257                 :            :  *
+    1258                 :            :  * \param p         the position in the ASN.1 data
+    1259                 :            :  * \param end       end of the buffer
+    1260                 :            :  * \param pk        The PK context to fill. It must have been initialized
+    1261                 :            :  *                  but not set up.
+    1262                 :            :  *
+    1263                 :            :  * \return          0 if successful, or a specific PK error code
+    1264                 :            :  */
+    1265                 :            : int mbedtls_pk_parse_subpubkey(unsigned char **p, const unsigned char *end,
+    1266                 :            :                                mbedtls_pk_context *pk);
+    1267                 :            : #endif /* MBEDTLS_PK_PARSE_C */
+    1268                 :            : 
+    1269                 :            : #if defined(MBEDTLS_PK_WRITE_C)
+    1270                 :            : /**
+    1271                 :            :  * \brief           Write a subjectPublicKey to ASN.1 data
+    1272                 :            :  *                  Note: function works backwards in data buffer
+    1273                 :            :  *
+    1274                 :            :  * \param p         reference to current position pointer
+    1275                 :            :  * \param start     start of the buffer (for bounds-checking)
+    1276                 :            :  * \param key       PK context which must contain a valid public or private key.
+    1277                 :            :  *
+    1278                 :            :  * \return          the length written or a negative error code
+    1279                 :            :  */
+    1280                 :            : int mbedtls_pk_write_pubkey(unsigned char **p, unsigned char *start,
+    1281                 :            :                             const mbedtls_pk_context *key);
+    1282                 :            : #endif /* MBEDTLS_PK_WRITE_C */
+    1283                 :            : 
+    1284                 :            : #ifdef __cplusplus
+    1285                 :            : }
+    1286                 :            : #endif
+    1287                 :            : 
+    1288                 :            : #endif /* MBEDTLS_PK_H */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/aes.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/aes.c.func-sort-c.html new file mode 100644 index 00000000000..d42fc70176b --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/aes.c.func-sort-c.html @@ -0,0 +1,145 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/aes.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - aes.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:6250312.3 %
Date:2024-09-22 08:21:07Functions:61637.5 %
Branches:3025411.8 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
aes_maybe_realign0
mbedtls_aes_crypt_cbc0
mbedtls_aes_crypt_cfb1280
mbedtls_aes_crypt_cfb80
mbedtls_aes_crypt_ctr0
mbedtls_aes_crypt_ofb0
mbedtls_aes_self_test0
mbedtls_aes_setkey_dec0
mbedtls_internal_aes_decrypt0
mbedtls_internal_aes_encrypt0
aes_gen_tables2
mbedtls_aes_free791
mbedtls_aes_init791
mbedtls_aes_rk_offset791
mbedtls_aes_setkey_enc791
mbedtls_aes_crypt_ecb3654
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/aes.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/aes.c.func.html new file mode 100644 index 00000000000..47770c6c994 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/aes.c.func.html @@ -0,0 +1,145 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/aes.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - aes.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:6250312.3 %
Date:2024-09-22 08:21:07Functions:61637.5 %
Branches:3025411.8 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
aes_gen_tables2
aes_maybe_realign0
mbedtls_aes_crypt_cbc0
mbedtls_aes_crypt_cfb1280
mbedtls_aes_crypt_cfb80
mbedtls_aes_crypt_ctr0
mbedtls_aes_crypt_ecb3654
mbedtls_aes_crypt_ofb0
mbedtls_aes_free791
mbedtls_aes_init791
mbedtls_aes_rk_offset791
mbedtls_aes_self_test0
mbedtls_aes_setkey_dec0
mbedtls_aes_setkey_enc791
mbedtls_internal_aes_decrypt0
mbedtls_internal_aes_encrypt0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/aes.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/aes.c.gcov.html new file mode 100644 index 00000000000..e80613c596c --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/aes.c.gcov.html @@ -0,0 +1,2379 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/aes.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - aes.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:6250312.3 %
Date:2024-09-22 08:21:07Functions:61637.5 %
Branches:3025411.8 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  *  FIPS-197 compliant AES implementation
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  */
+       7                 :            : /*
+       8                 :            :  *  The AES block cipher was designed by Vincent Rijmen and Joan Daemen.
+       9                 :            :  *
+      10                 :            :  *  https://csrc.nist.gov/csrc/media/projects/cryptographic-standards-and-guidelines/documents/aes-development/rijndael-ammended.pdf
+      11                 :            :  *  http://csrc.nist.gov/publications/fips/fips197/fips-197.pdf
+      12                 :            :  */
+      13                 :            : 
+      14                 :            : #include "common.h"
+      15                 :            : 
+      16                 :            : #if defined(MBEDTLS_AES_C)
+      17                 :            : 
+      18                 :            : #include <string.h>
+      19                 :            : 
+      20                 :            : #include "mbedtls/aes.h"
+      21                 :            : #include "mbedtls/platform.h"
+      22                 :            : #include "mbedtls/platform_util.h"
+      23                 :            : #include "mbedtls/error.h"
+      24                 :            : 
+      25                 :            : #if defined(MBEDTLS_AES_USE_HARDWARE_ONLY)
+      26                 :            : #if !((defined(MBEDTLS_ARCH_IS_ARMV8_A) && defined(MBEDTLS_AESCE_C)) || \
+      27                 :            :     (defined(MBEDTLS_ARCH_IS_X64)       && defined(MBEDTLS_AESNI_C)) || \
+      28                 :            :     (defined(MBEDTLS_ARCH_IS_X86)       && defined(MBEDTLS_AESNI_C)))
+      29                 :            : #error "MBEDTLS_AES_USE_HARDWARE_ONLY defined, but not all prerequisites"
+      30                 :            : #endif
+      31                 :            : #endif
+      32                 :            : 
+      33                 :            : #if defined(MBEDTLS_ARCH_IS_X86)
+      34                 :            : #if defined(MBEDTLS_PADLOCK_C)
+      35                 :            : #if !defined(MBEDTLS_HAVE_ASM)
+      36                 :            : #error "MBEDTLS_PADLOCK_C defined, but not all prerequisites"
+      37                 :            : #endif
+      38                 :            : #if defined(MBEDTLS_AES_USE_HARDWARE_ONLY)
+      39                 :            : #error "MBEDTLS_AES_USE_HARDWARE_ONLY cannot be defined when " \
+      40                 :            :     "MBEDTLS_PADLOCK_C is set"
+      41                 :            : #endif
+      42                 :            : #endif
+      43                 :            : #endif
+      44                 :            : 
+      45                 :            : #if defined(MBEDTLS_PADLOCK_C)
+      46                 :            : #include "padlock.h"
+      47                 :            : #endif
+      48                 :            : #if defined(MBEDTLS_AESNI_C)
+      49                 :            : #include "aesni.h"
+      50                 :            : #endif
+      51                 :            : #if defined(MBEDTLS_AESCE_C)
+      52                 :            : #include "aesce.h"
+      53                 :            : #endif
+      54                 :            : 
+      55                 :            : #include "mbedtls/platform.h"
+      56                 :            : #include "ctr.h"
+      57                 :            : 
+      58                 :            : /*
+      59                 :            :  * This is a convenience shorthand macro to check if we need reverse S-box and
+      60                 :            :  * reverse tables. It's private and only defined in this file.
+      61                 :            :  */
+      62                 :            : #if (!defined(MBEDTLS_AES_DECRYPT_ALT) || \
+      63                 :            :     (!defined(MBEDTLS_AES_SETKEY_DEC_ALT) && !defined(MBEDTLS_AES_USE_HARDWARE_ONLY))) && \
+      64                 :            :     !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
+      65                 :            : #define MBEDTLS_AES_NEED_REVERSE_TABLES
+      66                 :            : #endif
+      67                 :            : 
+      68                 :            : #if !defined(MBEDTLS_AES_ALT)
+      69                 :            : 
+      70                 :            : #if defined(MBEDTLS_VIA_PADLOCK_HAVE_CODE)
+      71                 :            : static int aes_padlock_ace = -1;
+      72                 :            : #endif
+      73                 :            : 
+      74                 :            : #if defined(MBEDTLS_AES_ROM_TABLES)
+      75                 :            : /*
+      76                 :            :  * Forward S-box
+      77                 :            :  */
+      78                 :            : MBEDTLS_MAYBE_UNUSED static const unsigned char FSb[256] =
+      79                 :            : {
+      80                 :            :     0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5,
+      81                 :            :     0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76,
+      82                 :            :     0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0,
+      83                 :            :     0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0,
+      84                 :            :     0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F, 0xF7, 0xCC,
+      85                 :            :     0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15,
+      86                 :            :     0x04, 0xC7, 0x23, 0xC3, 0x18, 0x96, 0x05, 0x9A,
+      87                 :            :     0x07, 0x12, 0x80, 0xE2, 0xEB, 0x27, 0xB2, 0x75,
+      88                 :            :     0x09, 0x83, 0x2C, 0x1A, 0x1B, 0x6E, 0x5A, 0xA0,
+      89                 :            :     0x52, 0x3B, 0xD6, 0xB3, 0x29, 0xE3, 0x2F, 0x84,
+      90                 :            :     0x53, 0xD1, 0x00, 0xED, 0x20, 0xFC, 0xB1, 0x5B,
+      91                 :            :     0x6A, 0xCB, 0xBE, 0x39, 0x4A, 0x4C, 0x58, 0xCF,
+      92                 :            :     0xD0, 0xEF, 0xAA, 0xFB, 0x43, 0x4D, 0x33, 0x85,
+      93                 :            :     0x45, 0xF9, 0x02, 0x7F, 0x50, 0x3C, 0x9F, 0xA8,
+      94                 :            :     0x51, 0xA3, 0x40, 0x8F, 0x92, 0x9D, 0x38, 0xF5,
+      95                 :            :     0xBC, 0xB6, 0xDA, 0x21, 0x10, 0xFF, 0xF3, 0xD2,
+      96                 :            :     0xCD, 0x0C, 0x13, 0xEC, 0x5F, 0x97, 0x44, 0x17,
+      97                 :            :     0xC4, 0xA7, 0x7E, 0x3D, 0x64, 0x5D, 0x19, 0x73,
+      98                 :            :     0x60, 0x81, 0x4F, 0xDC, 0x22, 0x2A, 0x90, 0x88,
+      99                 :            :     0x46, 0xEE, 0xB8, 0x14, 0xDE, 0x5E, 0x0B, 0xDB,
+     100                 :            :     0xE0, 0x32, 0x3A, 0x0A, 0x49, 0x06, 0x24, 0x5C,
+     101                 :            :     0xC2, 0xD3, 0xAC, 0x62, 0x91, 0x95, 0xE4, 0x79,
+     102                 :            :     0xE7, 0xC8, 0x37, 0x6D, 0x8D, 0xD5, 0x4E, 0xA9,
+     103                 :            :     0x6C, 0x56, 0xF4, 0xEA, 0x65, 0x7A, 0xAE, 0x08,
+     104                 :            :     0xBA, 0x78, 0x25, 0x2E, 0x1C, 0xA6, 0xB4, 0xC6,
+     105                 :            :     0xE8, 0xDD, 0x74, 0x1F, 0x4B, 0xBD, 0x8B, 0x8A,
+     106                 :            :     0x70, 0x3E, 0xB5, 0x66, 0x48, 0x03, 0xF6, 0x0E,
+     107                 :            :     0x61, 0x35, 0x57, 0xB9, 0x86, 0xC1, 0x1D, 0x9E,
+     108                 :            :     0xE1, 0xF8, 0x98, 0x11, 0x69, 0xD9, 0x8E, 0x94,
+     109                 :            :     0x9B, 0x1E, 0x87, 0xE9, 0xCE, 0x55, 0x28, 0xDF,
+     110                 :            :     0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, 0x68,
+     111                 :            :     0x41, 0x99, 0x2D, 0x0F, 0xB0, 0x54, 0xBB, 0x16
+     112                 :            : };
+     113                 :            : 
+     114                 :            : /*
+     115                 :            :  * Forward tables
+     116                 :            :  */
+     117                 :            : #define FT \
+     118                 :            : \
+     119                 :            :     V(A5, 63, 63, C6), V(84, 7C, 7C, F8), V(99, 77, 77, EE), V(8D, 7B, 7B, F6), \
+     120                 :            :     V(0D, F2, F2, FF), V(BD, 6B, 6B, D6), V(B1, 6F, 6F, DE), V(54, C5, C5, 91), \
+     121                 :            :     V(50, 30, 30, 60), V(03, 01, 01, 02), V(A9, 67, 67, CE), V(7D, 2B, 2B, 56), \
+     122                 :            :     V(19, FE, FE, E7), V(62, D7, D7, B5), V(E6, AB, AB, 4D), V(9A, 76, 76, EC), \
+     123                 :            :     V(45, CA, CA, 8F), V(9D, 82, 82, 1F), V(40, C9, C9, 89), V(87, 7D, 7D, FA), \
+     124                 :            :     V(15, FA, FA, EF), V(EB, 59, 59, B2), V(C9, 47, 47, 8E), V(0B, F0, F0, FB), \
+     125                 :            :     V(EC, AD, AD, 41), V(67, D4, D4, B3), V(FD, A2, A2, 5F), V(EA, AF, AF, 45), \
+     126                 :            :     V(BF, 9C, 9C, 23), V(F7, A4, A4, 53), V(96, 72, 72, E4), V(5B, C0, C0, 9B), \
+     127                 :            :     V(C2, B7, B7, 75), V(1C, FD, FD, E1), V(AE, 93, 93, 3D), V(6A, 26, 26, 4C), \
+     128                 :            :     V(5A, 36, 36, 6C), V(41, 3F, 3F, 7E), V(02, F7, F7, F5), V(4F, CC, CC, 83), \
+     129                 :            :     V(5C, 34, 34, 68), V(F4, A5, A5, 51), V(34, E5, E5, D1), V(08, F1, F1, F9), \
+     130                 :            :     V(93, 71, 71, E2), V(73, D8, D8, AB), V(53, 31, 31, 62), V(3F, 15, 15, 2A), \
+     131                 :            :     V(0C, 04, 04, 08), V(52, C7, C7, 95), V(65, 23, 23, 46), V(5E, C3, C3, 9D), \
+     132                 :            :     V(28, 18, 18, 30), V(A1, 96, 96, 37), V(0F, 05, 05, 0A), V(B5, 9A, 9A, 2F), \
+     133                 :            :     V(09, 07, 07, 0E), V(36, 12, 12, 24), V(9B, 80, 80, 1B), V(3D, E2, E2, DF), \
+     134                 :            :     V(26, EB, EB, CD), V(69, 27, 27, 4E), V(CD, B2, B2, 7F), V(9F, 75, 75, EA), \
+     135                 :            :     V(1B, 09, 09, 12), V(9E, 83, 83, 1D), V(74, 2C, 2C, 58), V(2E, 1A, 1A, 34), \
+     136                 :            :     V(2D, 1B, 1B, 36), V(B2, 6E, 6E, DC), V(EE, 5A, 5A, B4), V(FB, A0, A0, 5B), \
+     137                 :            :     V(F6, 52, 52, A4), V(4D, 3B, 3B, 76), V(61, D6, D6, B7), V(CE, B3, B3, 7D), \
+     138                 :            :     V(7B, 29, 29, 52), V(3E, E3, E3, DD), V(71, 2F, 2F, 5E), V(97, 84, 84, 13), \
+     139                 :            :     V(F5, 53, 53, A6), V(68, D1, D1, B9), V(00, 00, 00, 00), V(2C, ED, ED, C1), \
+     140                 :            :     V(60, 20, 20, 40), V(1F, FC, FC, E3), V(C8, B1, B1, 79), V(ED, 5B, 5B, B6), \
+     141                 :            :     V(BE, 6A, 6A, D4), V(46, CB, CB, 8D), V(D9, BE, BE, 67), V(4B, 39, 39, 72), \
+     142                 :            :     V(DE, 4A, 4A, 94), V(D4, 4C, 4C, 98), V(E8, 58, 58, B0), V(4A, CF, CF, 85), \
+     143                 :            :     V(6B, D0, D0, BB), V(2A, EF, EF, C5), V(E5, AA, AA, 4F), V(16, FB, FB, ED), \
+     144                 :            :     V(C5, 43, 43, 86), V(D7, 4D, 4D, 9A), V(55, 33, 33, 66), V(94, 85, 85, 11), \
+     145                 :            :     V(CF, 45, 45, 8A), V(10, F9, F9, E9), V(06, 02, 02, 04), V(81, 7F, 7F, FE), \
+     146                 :            :     V(F0, 50, 50, A0), V(44, 3C, 3C, 78), V(BA, 9F, 9F, 25), V(E3, A8, A8, 4B), \
+     147                 :            :     V(F3, 51, 51, A2), V(FE, A3, A3, 5D), V(C0, 40, 40, 80), V(8A, 8F, 8F, 05), \
+     148                 :            :     V(AD, 92, 92, 3F), V(BC, 9D, 9D, 21), V(48, 38, 38, 70), V(04, F5, F5, F1), \
+     149                 :            :     V(DF, BC, BC, 63), V(C1, B6, B6, 77), V(75, DA, DA, AF), V(63, 21, 21, 42), \
+     150                 :            :     V(30, 10, 10, 20), V(1A, FF, FF, E5), V(0E, F3, F3, FD), V(6D, D2, D2, BF), \
+     151                 :            :     V(4C, CD, CD, 81), V(14, 0C, 0C, 18), V(35, 13, 13, 26), V(2F, EC, EC, C3), \
+     152                 :            :     V(E1, 5F, 5F, BE), V(A2, 97, 97, 35), V(CC, 44, 44, 88), V(39, 17, 17, 2E), \
+     153                 :            :     V(57, C4, C4, 93), V(F2, A7, A7, 55), V(82, 7E, 7E, FC), V(47, 3D, 3D, 7A), \
+     154                 :            :     V(AC, 64, 64, C8), V(E7, 5D, 5D, BA), V(2B, 19, 19, 32), V(95, 73, 73, E6), \
+     155                 :            :     V(A0, 60, 60, C0), V(98, 81, 81, 19), V(D1, 4F, 4F, 9E), V(7F, DC, DC, A3), \
+     156                 :            :     V(66, 22, 22, 44), V(7E, 2A, 2A, 54), V(AB, 90, 90, 3B), V(83, 88, 88, 0B), \
+     157                 :            :     V(CA, 46, 46, 8C), V(29, EE, EE, C7), V(D3, B8, B8, 6B), V(3C, 14, 14, 28), \
+     158                 :            :     V(79, DE, DE, A7), V(E2, 5E, 5E, BC), V(1D, 0B, 0B, 16), V(76, DB, DB, AD), \
+     159                 :            :     V(3B, E0, E0, DB), V(56, 32, 32, 64), V(4E, 3A, 3A, 74), V(1E, 0A, 0A, 14), \
+     160                 :            :     V(DB, 49, 49, 92), V(0A, 06, 06, 0C), V(6C, 24, 24, 48), V(E4, 5C, 5C, B8), \
+     161                 :            :     V(5D, C2, C2, 9F), V(6E, D3, D3, BD), V(EF, AC, AC, 43), V(A6, 62, 62, C4), \
+     162                 :            :     V(A8, 91, 91, 39), V(A4, 95, 95, 31), V(37, E4, E4, D3), V(8B, 79, 79, F2), \
+     163                 :            :     V(32, E7, E7, D5), V(43, C8, C8, 8B), V(59, 37, 37, 6E), V(B7, 6D, 6D, DA), \
+     164                 :            :     V(8C, 8D, 8D, 01), V(64, D5, D5, B1), V(D2, 4E, 4E, 9C), V(E0, A9, A9, 49), \
+     165                 :            :     V(B4, 6C, 6C, D8), V(FA, 56, 56, AC), V(07, F4, F4, F3), V(25, EA, EA, CF), \
+     166                 :            :     V(AF, 65, 65, CA), V(8E, 7A, 7A, F4), V(E9, AE, AE, 47), V(18, 08, 08, 10), \
+     167                 :            :     V(D5, BA, BA, 6F), V(88, 78, 78, F0), V(6F, 25, 25, 4A), V(72, 2E, 2E, 5C), \
+     168                 :            :     V(24, 1C, 1C, 38), V(F1, A6, A6, 57), V(C7, B4, B4, 73), V(51, C6, C6, 97), \
+     169                 :            :     V(23, E8, E8, CB), V(7C, DD, DD, A1), V(9C, 74, 74, E8), V(21, 1F, 1F, 3E), \
+     170                 :            :     V(DD, 4B, 4B, 96), V(DC, BD, BD, 61), V(86, 8B, 8B, 0D), V(85, 8A, 8A, 0F), \
+     171                 :            :     V(90, 70, 70, E0), V(42, 3E, 3E, 7C), V(C4, B5, B5, 71), V(AA, 66, 66, CC), \
+     172                 :            :     V(D8, 48, 48, 90), V(05, 03, 03, 06), V(01, F6, F6, F7), V(12, 0E, 0E, 1C), \
+     173                 :            :     V(A3, 61, 61, C2), V(5F, 35, 35, 6A), V(F9, 57, 57, AE), V(D0, B9, B9, 69), \
+     174                 :            :     V(91, 86, 86, 17), V(58, C1, C1, 99), V(27, 1D, 1D, 3A), V(B9, 9E, 9E, 27), \
+     175                 :            :     V(38, E1, E1, D9), V(13, F8, F8, EB), V(B3, 98, 98, 2B), V(33, 11, 11, 22), \
+     176                 :            :     V(BB, 69, 69, D2), V(70, D9, D9, A9), V(89, 8E, 8E, 07), V(A7, 94, 94, 33), \
+     177                 :            :     V(B6, 9B, 9B, 2D), V(22, 1E, 1E, 3C), V(92, 87, 87, 15), V(20, E9, E9, C9), \
+     178                 :            :     V(49, CE, CE, 87), V(FF, 55, 55, AA), V(78, 28, 28, 50), V(7A, DF, DF, A5), \
+     179                 :            :     V(8F, 8C, 8C, 03), V(F8, A1, A1, 59), V(80, 89, 89, 09), V(17, 0D, 0D, 1A), \
+     180                 :            :     V(DA, BF, BF, 65), V(31, E6, E6, D7), V(C6, 42, 42, 84), V(B8, 68, 68, D0), \
+     181                 :            :     V(C3, 41, 41, 82), V(B0, 99, 99, 29), V(77, 2D, 2D, 5A), V(11, 0F, 0F, 1E), \
+     182                 :            :     V(CB, B0, B0, 7B), V(FC, 54, 54, A8), V(D6, BB, BB, 6D), V(3A, 16, 16, 2C)
+     183                 :            : 
+     184                 :            : #define V(a, b, c, d) 0x##a##b##c##d
+     185                 :            : MBEDTLS_MAYBE_UNUSED static const uint32_t FT0[256] = { FT };
+     186                 :            : #undef V
+     187                 :            : 
+     188                 :            : #define V(a, b, c, d) 0x##b##c##d##a
+     189                 :            : MBEDTLS_MAYBE_UNUSED static const uint32_t FT1[256] = { FT };
+     190                 :            : #undef V
+     191                 :            : 
+     192                 :            : #define V(a, b, c, d) 0x##c##d##a##b
+     193                 :            : MBEDTLS_MAYBE_UNUSED static const uint32_t FT2[256] = { FT };
+     194                 :            : #undef V
+     195                 :            : 
+     196                 :            : #define V(a, b, c, d) 0x##d##a##b##c
+     197                 :            : MBEDTLS_MAYBE_UNUSED static const uint32_t FT3[256] = { FT };
+     198                 :            : #undef V
+     199                 :            : 
+     200                 :            : #undef FT
+     201                 :            : 
+     202                 :            : /*
+     203                 :            :  * Reverse S-box
+     204                 :            :  */
+     205                 :            : MBEDTLS_MAYBE_UNUSED static const unsigned char RSb[256] =
+     206                 :            : {
+     207                 :            :     0x52, 0x09, 0x6A, 0xD5, 0x30, 0x36, 0xA5, 0x38,
+     208                 :            :     0xBF, 0x40, 0xA3, 0x9E, 0x81, 0xF3, 0xD7, 0xFB,
+     209                 :            :     0x7C, 0xE3, 0x39, 0x82, 0x9B, 0x2F, 0xFF, 0x87,
+     210                 :            :     0x34, 0x8E, 0x43, 0x44, 0xC4, 0xDE, 0xE9, 0xCB,
+     211                 :            :     0x54, 0x7B, 0x94, 0x32, 0xA6, 0xC2, 0x23, 0x3D,
+     212                 :            :     0xEE, 0x4C, 0x95, 0x0B, 0x42, 0xFA, 0xC3, 0x4E,
+     213                 :            :     0x08, 0x2E, 0xA1, 0x66, 0x28, 0xD9, 0x24, 0xB2,
+     214                 :            :     0x76, 0x5B, 0xA2, 0x49, 0x6D, 0x8B, 0xD1, 0x25,
+     215                 :            :     0x72, 0xF8, 0xF6, 0x64, 0x86, 0x68, 0x98, 0x16,
+     216                 :            :     0xD4, 0xA4, 0x5C, 0xCC, 0x5D, 0x65, 0xB6, 0x92,
+     217                 :            :     0x6C, 0x70, 0x48, 0x50, 0xFD, 0xED, 0xB9, 0xDA,
+     218                 :            :     0x5E, 0x15, 0x46, 0x57, 0xA7, 0x8D, 0x9D, 0x84,
+     219                 :            :     0x90, 0xD8, 0xAB, 0x00, 0x8C, 0xBC, 0xD3, 0x0A,
+     220                 :            :     0xF7, 0xE4, 0x58, 0x05, 0xB8, 0xB3, 0x45, 0x06,
+     221                 :            :     0xD0, 0x2C, 0x1E, 0x8F, 0xCA, 0x3F, 0x0F, 0x02,
+     222                 :            :     0xC1, 0xAF, 0xBD, 0x03, 0x01, 0x13, 0x8A, 0x6B,
+     223                 :            :     0x3A, 0x91, 0x11, 0x41, 0x4F, 0x67, 0xDC, 0xEA,
+     224                 :            :     0x97, 0xF2, 0xCF, 0xCE, 0xF0, 0xB4, 0xE6, 0x73,
+     225                 :            :     0x96, 0xAC, 0x74, 0x22, 0xE7, 0xAD, 0x35, 0x85,
+     226                 :            :     0xE2, 0xF9, 0x37, 0xE8, 0x1C, 0x75, 0xDF, 0x6E,
+     227                 :            :     0x47, 0xF1, 0x1A, 0x71, 0x1D, 0x29, 0xC5, 0x89,
+     228                 :            :     0x6F, 0xB7, 0x62, 0x0E, 0xAA, 0x18, 0xBE, 0x1B,
+     229                 :            :     0xFC, 0x56, 0x3E, 0x4B, 0xC6, 0xD2, 0x79, 0x20,
+     230                 :            :     0x9A, 0xDB, 0xC0, 0xFE, 0x78, 0xCD, 0x5A, 0xF4,
+     231                 :            :     0x1F, 0xDD, 0xA8, 0x33, 0x88, 0x07, 0xC7, 0x31,
+     232                 :            :     0xB1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xEC, 0x5F,
+     233                 :            :     0x60, 0x51, 0x7F, 0xA9, 0x19, 0xB5, 0x4A, 0x0D,
+     234                 :            :     0x2D, 0xE5, 0x7A, 0x9F, 0x93, 0xC9, 0x9C, 0xEF,
+     235                 :            :     0xA0, 0xE0, 0x3B, 0x4D, 0xAE, 0x2A, 0xF5, 0xB0,
+     236                 :            :     0xC8, 0xEB, 0xBB, 0x3C, 0x83, 0x53, 0x99, 0x61,
+     237                 :            :     0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26,
+     238                 :            :     0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C, 0x7D
+     239                 :            : };
+     240                 :            : 
+     241                 :            : /*
+     242                 :            :  * Reverse tables
+     243                 :            :  */
+     244                 :            : #define RT \
+     245                 :            : \
+     246                 :            :     V(50, A7, F4, 51), V(53, 65, 41, 7E), V(C3, A4, 17, 1A), V(96, 5E, 27, 3A), \
+     247                 :            :     V(CB, 6B, AB, 3B), V(F1, 45, 9D, 1F), V(AB, 58, FA, AC), V(93, 03, E3, 4B), \
+     248                 :            :     V(55, FA, 30, 20), V(F6, 6D, 76, AD), V(91, 76, CC, 88), V(25, 4C, 02, F5), \
+     249                 :            :     V(FC, D7, E5, 4F), V(D7, CB, 2A, C5), V(80, 44, 35, 26), V(8F, A3, 62, B5), \
+     250                 :            :     V(49, 5A, B1, DE), V(67, 1B, BA, 25), V(98, 0E, EA, 45), V(E1, C0, FE, 5D), \
+     251                 :            :     V(02, 75, 2F, C3), V(12, F0, 4C, 81), V(A3, 97, 46, 8D), V(C6, F9, D3, 6B), \
+     252                 :            :     V(E7, 5F, 8F, 03), V(95, 9C, 92, 15), V(EB, 7A, 6D, BF), V(DA, 59, 52, 95), \
+     253                 :            :     V(2D, 83, BE, D4), V(D3, 21, 74, 58), V(29, 69, E0, 49), V(44, C8, C9, 8E), \
+     254                 :            :     V(6A, 89, C2, 75), V(78, 79, 8E, F4), V(6B, 3E, 58, 99), V(DD, 71, B9, 27), \
+     255                 :            :     V(B6, 4F, E1, BE), V(17, AD, 88, F0), V(66, AC, 20, C9), V(B4, 3A, CE, 7D), \
+     256                 :            :     V(18, 4A, DF, 63), V(82, 31, 1A, E5), V(60, 33, 51, 97), V(45, 7F, 53, 62), \
+     257                 :            :     V(E0, 77, 64, B1), V(84, AE, 6B, BB), V(1C, A0, 81, FE), V(94, 2B, 08, F9), \
+     258                 :            :     V(58, 68, 48, 70), V(19, FD, 45, 8F), V(87, 6C, DE, 94), V(B7, F8, 7B, 52), \
+     259                 :            :     V(23, D3, 73, AB), V(E2, 02, 4B, 72), V(57, 8F, 1F, E3), V(2A, AB, 55, 66), \
+     260                 :            :     V(07, 28, EB, B2), V(03, C2, B5, 2F), V(9A, 7B, C5, 86), V(A5, 08, 37, D3), \
+     261                 :            :     V(F2, 87, 28, 30), V(B2, A5, BF, 23), V(BA, 6A, 03, 02), V(5C, 82, 16, ED), \
+     262                 :            :     V(2B, 1C, CF, 8A), V(92, B4, 79, A7), V(F0, F2, 07, F3), V(A1, E2, 69, 4E), \
+     263                 :            :     V(CD, F4, DA, 65), V(D5, BE, 05, 06), V(1F, 62, 34, D1), V(8A, FE, A6, C4), \
+     264                 :            :     V(9D, 53, 2E, 34), V(A0, 55, F3, A2), V(32, E1, 8A, 05), V(75, EB, F6, A4), \
+     265                 :            :     V(39, EC, 83, 0B), V(AA, EF, 60, 40), V(06, 9F, 71, 5E), V(51, 10, 6E, BD), \
+     266                 :            :     V(F9, 8A, 21, 3E), V(3D, 06, DD, 96), V(AE, 05, 3E, DD), V(46, BD, E6, 4D), \
+     267                 :            :     V(B5, 8D, 54, 91), V(05, 5D, C4, 71), V(6F, D4, 06, 04), V(FF, 15, 50, 60), \
+     268                 :            :     V(24, FB, 98, 19), V(97, E9, BD, D6), V(CC, 43, 40, 89), V(77, 9E, D9, 67), \
+     269                 :            :     V(BD, 42, E8, B0), V(88, 8B, 89, 07), V(38, 5B, 19, E7), V(DB, EE, C8, 79), \
+     270                 :            :     V(47, 0A, 7C, A1), V(E9, 0F, 42, 7C), V(C9, 1E, 84, F8), V(00, 00, 00, 00), \
+     271                 :            :     V(83, 86, 80, 09), V(48, ED, 2B, 32), V(AC, 70, 11, 1E), V(4E, 72, 5A, 6C), \
+     272                 :            :     V(FB, FF, 0E, FD), V(56, 38, 85, 0F), V(1E, D5, AE, 3D), V(27, 39, 2D, 36), \
+     273                 :            :     V(64, D9, 0F, 0A), V(21, A6, 5C, 68), V(D1, 54, 5B, 9B), V(3A, 2E, 36, 24), \
+     274                 :            :     V(B1, 67, 0A, 0C), V(0F, E7, 57, 93), V(D2, 96, EE, B4), V(9E, 91, 9B, 1B), \
+     275                 :            :     V(4F, C5, C0, 80), V(A2, 20, DC, 61), V(69, 4B, 77, 5A), V(16, 1A, 12, 1C), \
+     276                 :            :     V(0A, BA, 93, E2), V(E5, 2A, A0, C0), V(43, E0, 22, 3C), V(1D, 17, 1B, 12), \
+     277                 :            :     V(0B, 0D, 09, 0E), V(AD, C7, 8B, F2), V(B9, A8, B6, 2D), V(C8, A9, 1E, 14), \
+     278                 :            :     V(85, 19, F1, 57), V(4C, 07, 75, AF), V(BB, DD, 99, EE), V(FD, 60, 7F, A3), \
+     279                 :            :     V(9F, 26, 01, F7), V(BC, F5, 72, 5C), V(C5, 3B, 66, 44), V(34, 7E, FB, 5B), \
+     280                 :            :     V(76, 29, 43, 8B), V(DC, C6, 23, CB), V(68, FC, ED, B6), V(63, F1, E4, B8), \
+     281                 :            :     V(CA, DC, 31, D7), V(10, 85, 63, 42), V(40, 22, 97, 13), V(20, 11, C6, 84), \
+     282                 :            :     V(7D, 24, 4A, 85), V(F8, 3D, BB, D2), V(11, 32, F9, AE), V(6D, A1, 29, C7), \
+     283                 :            :     V(4B, 2F, 9E, 1D), V(F3, 30, B2, DC), V(EC, 52, 86, 0D), V(D0, E3, C1, 77), \
+     284                 :            :     V(6C, 16, B3, 2B), V(99, B9, 70, A9), V(FA, 48, 94, 11), V(22, 64, E9, 47), \
+     285                 :            :     V(C4, 8C, FC, A8), V(1A, 3F, F0, A0), V(D8, 2C, 7D, 56), V(EF, 90, 33, 22), \
+     286                 :            :     V(C7, 4E, 49, 87), V(C1, D1, 38, D9), V(FE, A2, CA, 8C), V(36, 0B, D4, 98), \
+     287                 :            :     V(CF, 81, F5, A6), V(28, DE, 7A, A5), V(26, 8E, B7, DA), V(A4, BF, AD, 3F), \
+     288                 :            :     V(E4, 9D, 3A, 2C), V(0D, 92, 78, 50), V(9B, CC, 5F, 6A), V(62, 46, 7E, 54), \
+     289                 :            :     V(C2, 13, 8D, F6), V(E8, B8, D8, 90), V(5E, F7, 39, 2E), V(F5, AF, C3, 82), \
+     290                 :            :     V(BE, 80, 5D, 9F), V(7C, 93, D0, 69), V(A9, 2D, D5, 6F), V(B3, 12, 25, CF), \
+     291                 :            :     V(3B, 99, AC, C8), V(A7, 7D, 18, 10), V(6E, 63, 9C, E8), V(7B, BB, 3B, DB), \
+     292                 :            :     V(09, 78, 26, CD), V(F4, 18, 59, 6E), V(01, B7, 9A, EC), V(A8, 9A, 4F, 83), \
+     293                 :            :     V(65, 6E, 95, E6), V(7E, E6, FF, AA), V(08, CF, BC, 21), V(E6, E8, 15, EF), \
+     294                 :            :     V(D9, 9B, E7, BA), V(CE, 36, 6F, 4A), V(D4, 09, 9F, EA), V(D6, 7C, B0, 29), \
+     295                 :            :     V(AF, B2, A4, 31), V(31, 23, 3F, 2A), V(30, 94, A5, C6), V(C0, 66, A2, 35), \
+     296                 :            :     V(37, BC, 4E, 74), V(A6, CA, 82, FC), V(B0, D0, 90, E0), V(15, D8, A7, 33), \
+     297                 :            :     V(4A, 98, 04, F1), V(F7, DA, EC, 41), V(0E, 50, CD, 7F), V(2F, F6, 91, 17), \
+     298                 :            :     V(8D, D6, 4D, 76), V(4D, B0, EF, 43), V(54, 4D, AA, CC), V(DF, 04, 96, E4), \
+     299                 :            :     V(E3, B5, D1, 9E), V(1B, 88, 6A, 4C), V(B8, 1F, 2C, C1), V(7F, 51, 65, 46), \
+     300                 :            :     V(04, EA, 5E, 9D), V(5D, 35, 8C, 01), V(73, 74, 87, FA), V(2E, 41, 0B, FB), \
+     301                 :            :     V(5A, 1D, 67, B3), V(52, D2, DB, 92), V(33, 56, 10, E9), V(13, 47, D6, 6D), \
+     302                 :            :     V(8C, 61, D7, 9A), V(7A, 0C, A1, 37), V(8E, 14, F8, 59), V(89, 3C, 13, EB), \
+     303                 :            :     V(EE, 27, A9, CE), V(35, C9, 61, B7), V(ED, E5, 1C, E1), V(3C, B1, 47, 7A), \
+     304                 :            :     V(59, DF, D2, 9C), V(3F, 73, F2, 55), V(79, CE, 14, 18), V(BF, 37, C7, 73), \
+     305                 :            :     V(EA, CD, F7, 53), V(5B, AA, FD, 5F), V(14, 6F, 3D, DF), V(86, DB, 44, 78), \
+     306                 :            :     V(81, F3, AF, CA), V(3E, C4, 68, B9), V(2C, 34, 24, 38), V(5F, 40, A3, C2), \
+     307                 :            :     V(72, C3, 1D, 16), V(0C, 25, E2, BC), V(8B, 49, 3C, 28), V(41, 95, 0D, FF), \
+     308                 :            :     V(71, 01, A8, 39), V(DE, B3, 0C, 08), V(9C, E4, B4, D8), V(90, C1, 56, 64), \
+     309                 :            :     V(61, 84, CB, 7B), V(70, B6, 32, D5), V(74, 5C, 6C, 48), V(42, 57, B8, D0)
+     310                 :            : 
+     311                 :            : 
+     312                 :            : #define V(a, b, c, d) 0x##a##b##c##d
+     313                 :            : MBEDTLS_MAYBE_UNUSED static const uint32_t RT0[256] = { RT };
+     314                 :            : #undef V
+     315                 :            : 
+     316                 :            : #define V(a, b, c, d) 0x##b##c##d##a
+     317                 :            : MBEDTLS_MAYBE_UNUSED static const uint32_t RT1[256] = { RT };
+     318                 :            : #undef V
+     319                 :            : 
+     320                 :            : #define V(a, b, c, d) 0x##c##d##a##b
+     321                 :            : MBEDTLS_MAYBE_UNUSED static const uint32_t RT2[256] = { RT };
+     322                 :            : #undef V
+     323                 :            : 
+     324                 :            : #define V(a, b, c, d) 0x##d##a##b##c
+     325                 :            : MBEDTLS_MAYBE_UNUSED static const uint32_t RT3[256] = { RT };
+     326                 :            : #undef V
+     327                 :            : 
+     328                 :            : #undef RT
+     329                 :            : 
+     330                 :            : /*
+     331                 :            :  * Round constants
+     332                 :            :  */
+     333                 :            : MBEDTLS_MAYBE_UNUSED static const uint32_t round_constants[10] =
+     334                 :            : {
+     335                 :            :     0x00000001, 0x00000002, 0x00000004, 0x00000008,
+     336                 :            :     0x00000010, 0x00000020, 0x00000040, 0x00000080,
+     337                 :            :     0x0000001B, 0x00000036
+     338                 :            : };
+     339                 :            : 
+     340                 :            : #else /* MBEDTLS_AES_ROM_TABLES */
+     341                 :            : 
+     342                 :            : /*
+     343                 :            :  * Forward S-box & tables
+     344                 :            :  */
+     345                 :            : MBEDTLS_MAYBE_UNUSED static unsigned char FSb[256];
+     346                 :            : MBEDTLS_MAYBE_UNUSED static uint32_t FT0[256];
+     347                 :            : MBEDTLS_MAYBE_UNUSED static uint32_t FT1[256];
+     348                 :            : MBEDTLS_MAYBE_UNUSED static uint32_t FT2[256];
+     349                 :            : MBEDTLS_MAYBE_UNUSED static uint32_t FT3[256];
+     350                 :            : 
+     351                 :            : /*
+     352                 :            :  * Reverse S-box & tables
+     353                 :            :  */
+     354                 :            : MBEDTLS_MAYBE_UNUSED static unsigned char RSb[256];
+     355                 :            : 
+     356                 :            : MBEDTLS_MAYBE_UNUSED static uint32_t RT0[256];
+     357                 :            : MBEDTLS_MAYBE_UNUSED static uint32_t RT1[256];
+     358                 :            : MBEDTLS_MAYBE_UNUSED static uint32_t RT2[256];
+     359                 :            : MBEDTLS_MAYBE_UNUSED static uint32_t RT3[256];
+     360                 :            : 
+     361                 :            : /*
+     362                 :            :  * Round constants
+     363                 :            :  */
+     364                 :            : MBEDTLS_MAYBE_UNUSED static uint32_t round_constants[10];
+     365                 :            : 
+     366                 :            : /*
+     367                 :            :  * Tables generation code
+     368                 :            :  */
+     369                 :            : #define ROTL8(x) (((x) << 8) & 0xFFFFFFFF) | ((x) >> 24)
+     370                 :            : #define XTIME(x) (((x) << 1) ^ (((x) & 0x80) ? 0x1B : 0x00))
+     371                 :            : #define MUL(x, y) (((x) && (y)) ? pow[(log[(x)]+log[(y)]) % 255] : 0)
+     372                 :            : 
+     373                 :            : MBEDTLS_MAYBE_UNUSED static int aes_init_done = 0;
+     374                 :            : 
+     375                 :          2 : MBEDTLS_MAYBE_UNUSED static void aes_gen_tables(void)
+     376                 :            : {
+     377                 :            :     int i;
+     378                 :            :     uint8_t x, y, z;
+     379                 :            :     uint8_t pow[256];
+     380                 :            :     uint8_t log[256];
+     381                 :            : 
+     382                 :            :     /*
+     383                 :            :      * compute pow and log tables over GF(2^8)
+     384                 :            :      */
+     385         [ +  + ]:        514 :     for (i = 0, x = 1; i < 256; i++) {
+     386                 :        512 :         pow[i] = x;
+     387                 :        512 :         log[x] = (uint8_t) i;
+     388         [ +  + ]:        512 :         x ^= XTIME(x);
+     389                 :            :     }
+     390                 :            : 
+     391                 :            :     /*
+     392                 :            :      * calculate the round constants
+     393                 :            :      */
+     394         [ +  + ]:         22 :     for (i = 0, x = 1; i < 10; i++) {
+     395                 :         20 :         round_constants[i] = x;
+     396         [ +  + ]:         20 :         x = XTIME(x);
+     397                 :            :     }
+     398                 :            : 
+     399                 :            :     /*
+     400                 :            :      * generate the forward and reverse S-boxes
+     401                 :            :      */
+     402                 :          2 :     FSb[0x00] = 0x63;
+     403                 :            : #if defined(MBEDTLS_AES_NEED_REVERSE_TABLES)
+     404                 :          2 :     RSb[0x63] = 0x00;
+     405                 :            : #endif
+     406                 :            : 
+     407         [ +  + ]:        512 :     for (i = 1; i < 256; i++) {
+     408                 :        510 :         x = pow[255 - log[i]];
+     409                 :            : 
+     410                 :        510 :         y  = x; y = (y << 1) | (y >> 7);
+     411                 :        510 :         x ^= y; y = (y << 1) | (y >> 7);
+     412                 :        510 :         x ^= y; y = (y << 1) | (y >> 7);
+     413                 :        510 :         x ^= y; y = (y << 1) | (y >> 7);
+     414                 :        510 :         x ^= y ^ 0x63;
+     415                 :            : 
+     416                 :        510 :         FSb[i] = x;
+     417                 :            : #if defined(MBEDTLS_AES_NEED_REVERSE_TABLES)
+     418                 :        510 :         RSb[x] = (unsigned char) i;
+     419                 :            : #endif
+     420                 :            :     }
+     421                 :            : 
+     422                 :            :     /*
+     423                 :            :      * generate the forward and reverse tables
+     424                 :            :      */
+     425         [ +  + ]:        514 :     for (i = 0; i < 256; i++) {
+     426                 :        512 :         x = FSb[i];
+     427         [ +  + ]:        512 :         y = XTIME(x);
+     428                 :        512 :         z = y ^ x;
+     429                 :            : 
+     430                 :        512 :         FT0[i] = ((uint32_t) y) ^
+     431                 :        512 :                  ((uint32_t) x <<  8) ^
+     432                 :        512 :                  ((uint32_t) x << 16) ^
+     433                 :        512 :                  ((uint32_t) z << 24);
+     434                 :            : 
+     435                 :            : #if !defined(MBEDTLS_AES_FEWER_TABLES)
+     436                 :        512 :         FT1[i] = ROTL8(FT0[i]);
+     437                 :        512 :         FT2[i] = ROTL8(FT1[i]);
+     438                 :        512 :         FT3[i] = ROTL8(FT2[i]);
+     439                 :            : #endif /* !MBEDTLS_AES_FEWER_TABLES */
+     440                 :            : 
+     441                 :            : #if defined(MBEDTLS_AES_NEED_REVERSE_TABLES)
+     442                 :        512 :         x = RSb[i];
+     443                 :            : 
+     444         [ +  + ]:        512 :         RT0[i] = ((uint32_t) MUL(0x0E, x)) ^
+     445         [ +  + ]:        512 :                  ((uint32_t) MUL(0x09, x) <<  8) ^
+     446         [ +  + ]:        512 :                  ((uint32_t) MUL(0x0D, x) << 16) ^
+     447         [ +  + ]:        512 :                  ((uint32_t) MUL(0x0B, x) << 24);
+     448                 :            : 
+     449                 :            : #if !defined(MBEDTLS_AES_FEWER_TABLES)
+     450                 :        512 :         RT1[i] = ROTL8(RT0[i]);
+     451                 :        512 :         RT2[i] = ROTL8(RT1[i]);
+     452                 :        512 :         RT3[i] = ROTL8(RT2[i]);
+     453                 :            : #endif /* !MBEDTLS_AES_FEWER_TABLES */
+     454                 :            : #endif /* MBEDTLS_AES_NEED_REVERSE_TABLES */
+     455                 :            :     }
+     456                 :          2 : }
+     457                 :            : 
+     458                 :            : #undef ROTL8
+     459                 :            : 
+     460                 :            : #endif /* MBEDTLS_AES_ROM_TABLES */
+     461                 :            : 
+     462                 :            : #if defined(MBEDTLS_AES_FEWER_TABLES)
+     463                 :            : 
+     464                 :            : #define ROTL8(x)  ((uint32_t) ((x) <<  8) + (uint32_t) ((x) >> 24))
+     465                 :            : #define ROTL16(x) ((uint32_t) ((x) << 16) + (uint32_t) ((x) >> 16))
+     466                 :            : #define ROTL24(x) ((uint32_t) ((x) << 24) + (uint32_t) ((x) >>  8))
+     467                 :            : 
+     468                 :            : #define AES_RT0(idx) RT0[idx]
+     469                 :            : #define AES_RT1(idx) ROTL8(RT0[idx])
+     470                 :            : #define AES_RT2(idx) ROTL16(RT0[idx])
+     471                 :            : #define AES_RT3(idx) ROTL24(RT0[idx])
+     472                 :            : 
+     473                 :            : #define AES_FT0(idx) FT0[idx]
+     474                 :            : #define AES_FT1(idx) ROTL8(FT0[idx])
+     475                 :            : #define AES_FT2(idx) ROTL16(FT0[idx])
+     476                 :            : #define AES_FT3(idx) ROTL24(FT0[idx])
+     477                 :            : 
+     478                 :            : #else /* MBEDTLS_AES_FEWER_TABLES */
+     479                 :            : 
+     480                 :            : #define AES_RT0(idx) RT0[idx]
+     481                 :            : #define AES_RT1(idx) RT1[idx]
+     482                 :            : #define AES_RT2(idx) RT2[idx]
+     483                 :            : #define AES_RT3(idx) RT3[idx]
+     484                 :            : 
+     485                 :            : #define AES_FT0(idx) FT0[idx]
+     486                 :            : #define AES_FT1(idx) FT1[idx]
+     487                 :            : #define AES_FT2(idx) FT2[idx]
+     488                 :            : #define AES_FT3(idx) FT3[idx]
+     489                 :            : 
+     490                 :            : #endif /* MBEDTLS_AES_FEWER_TABLES */
+     491                 :            : 
+     492                 :        791 : void mbedtls_aes_init(mbedtls_aes_context *ctx)
+     493                 :            : {
+     494                 :        791 :     memset(ctx, 0, sizeof(mbedtls_aes_context));
+     495                 :        791 : }
+     496                 :            : 
+     497                 :        791 : void mbedtls_aes_free(mbedtls_aes_context *ctx)
+     498                 :            : {
+     499         [ -  + ]:        791 :     if (ctx == NULL) {
+     500                 :          0 :         return;
+     501                 :            :     }
+     502                 :            : 
+     503                 :        791 :     mbedtls_platform_zeroize(ctx, sizeof(mbedtls_aes_context));
+     504                 :            : }
+     505                 :            : 
+     506                 :            : #if defined(MBEDTLS_CIPHER_MODE_XTS)
+     507                 :            : void mbedtls_aes_xts_init(mbedtls_aes_xts_context *ctx)
+     508                 :            : {
+     509                 :            :     mbedtls_aes_init(&ctx->crypt);
+     510                 :            :     mbedtls_aes_init(&ctx->tweak);
+     511                 :            : }
+     512                 :            : 
+     513                 :            : void mbedtls_aes_xts_free(mbedtls_aes_xts_context *ctx)
+     514                 :            : {
+     515                 :            :     if (ctx == NULL) {
+     516                 :            :         return;
+     517                 :            :     }
+     518                 :            : 
+     519                 :            :     mbedtls_aes_free(&ctx->crypt);
+     520                 :            :     mbedtls_aes_free(&ctx->tweak);
+     521                 :            : }
+     522                 :            : #endif /* MBEDTLS_CIPHER_MODE_XTS */
+     523                 :            : 
+     524                 :            : /* Some implementations need the round keys to be aligned.
+     525                 :            :  * Return an offset to be added to buf, such that (buf + offset) is
+     526                 :            :  * correctly aligned.
+     527                 :            :  * Note that the offset is in units of elements of buf, i.e. 32-bit words,
+     528                 :            :  * i.e. an offset of 1 means 4 bytes and so on.
+     529                 :            :  */
+     530                 :            : #if (defined(MBEDTLS_VIA_PADLOCK_HAVE_CODE)) ||        \
+     531                 :            :     (defined(MBEDTLS_AESNI_C) && MBEDTLS_AESNI_HAVE_CODE == 2)
+     532                 :            : #define MAY_NEED_TO_ALIGN
+     533                 :            : #endif
+     534                 :            : 
+     535                 :        791 : MBEDTLS_MAYBE_UNUSED static unsigned mbedtls_aes_rk_offset(uint32_t *buf)
+     536                 :            : {
+     537                 :            : #if defined(MAY_NEED_TO_ALIGN)
+     538                 :            :     int align_16_bytes = 0;
+     539                 :            : 
+     540                 :            : #if defined(MBEDTLS_VIA_PADLOCK_HAVE_CODE)
+     541                 :            :     if (aes_padlock_ace == -1) {
+     542                 :            :         aes_padlock_ace = mbedtls_padlock_has_support(MBEDTLS_PADLOCK_ACE);
+     543                 :            :     }
+     544                 :            :     if (aes_padlock_ace) {
+     545                 :            :         align_16_bytes = 1;
+     546                 :            :     }
+     547                 :            : #endif
+     548                 :            : 
+     549                 :            : #if defined(MBEDTLS_AESNI_C) && MBEDTLS_AESNI_HAVE_CODE == 2
+     550                 :            :     if (mbedtls_aesni_has_support(MBEDTLS_AESNI_AES)) {
+     551                 :            :         align_16_bytes = 1;
+     552                 :            :     }
+     553                 :            : #endif
+     554                 :            : 
+     555                 :            :     if (align_16_bytes) {
+     556                 :            :         /* These implementations needs 16-byte alignment
+     557                 :            :          * for the round key array. */
+     558                 :            :         unsigned delta = ((uintptr_t) buf & 0x0000000fU) / 4;
+     559                 :            :         if (delta == 0) {
+     560                 :            :             return 0;
+     561                 :            :         } else {
+     562                 :            :             return 4 - delta; // 16 bytes = 4 uint32_t
+     563                 :            :         }
+     564                 :            :     }
+     565                 :            : #else /* MAY_NEED_TO_ALIGN */
+     566                 :            :     (void) buf;
+     567                 :            : #endif /* MAY_NEED_TO_ALIGN */
+     568                 :            : 
+     569                 :        791 :     return 0;
+     570                 :            : }
+     571                 :            : 
+     572                 :            : /*
+     573                 :            :  * AES key schedule (encryption)
+     574                 :            :  */
+     575                 :            : #if !defined(MBEDTLS_AES_SETKEY_ENC_ALT)
+     576                 :        791 : int mbedtls_aes_setkey_enc(mbedtls_aes_context *ctx, const unsigned char *key,
+     577                 :            :                            unsigned int keybits)
+     578                 :            : {
+     579                 :            :     uint32_t *RK;
+     580                 :            : 
+     581   [ +  -  +  - ]:        791 :     switch (keybits) {
+     582                 :          2 :         case 128: ctx->nr = 10; break;
+     583                 :            : #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
+     584                 :          0 :         case 192: ctx->nr = 12; break;
+     585                 :        789 :         case 256: ctx->nr = 14; break;
+     586                 :            : #endif /* !MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
+     587                 :          0 :         default: return MBEDTLS_ERR_AES_INVALID_KEY_LENGTH;
+     588                 :            :     }
+     589                 :            : 
+     590                 :            : #if !defined(MBEDTLS_AES_ROM_TABLES)
+     591         [ +  + ]:        791 :     if (aes_init_done == 0) {
+     592                 :          2 :         aes_gen_tables();
+     593                 :          2 :         aes_init_done = 1;
+     594                 :            :     }
+     595                 :            : #endif
+     596                 :            : 
+     597                 :        791 :     ctx->rk_offset = mbedtls_aes_rk_offset(ctx->buf);
+     598                 :        791 :     RK = ctx->buf + ctx->rk_offset;
+     599                 :            : 
+     600                 :            : #if defined(MBEDTLS_AESNI_HAVE_CODE)
+     601         [ +  - ]:        791 :     if (mbedtls_aesni_has_support(MBEDTLS_AESNI_AES)) {
+     602                 :        791 :         return mbedtls_aesni_setkey_enc((unsigned char *) RK, key, keybits);
+     603                 :            :     }
+     604                 :            : #endif
+     605                 :            : 
+     606                 :            : #if defined(MBEDTLS_AESCE_HAVE_CODE)
+     607                 :            :     if (MBEDTLS_AESCE_HAS_SUPPORT()) {
+     608                 :            :         return mbedtls_aesce_setkey_enc((unsigned char *) RK, key, keybits);
+     609                 :            :     }
+     610                 :            : #endif
+     611                 :            : 
+     612                 :            : #if !defined(MBEDTLS_AES_USE_HARDWARE_ONLY)
+     613         [ #  # ]:          0 :     for (unsigned int i = 0; i < (keybits >> 5); i++) {
+     614                 :          0 :         RK[i] = MBEDTLS_GET_UINT32_LE(key, i << 2);
+     615                 :            :     }
+     616                 :            : 
+     617   [ #  #  #  # ]:          0 :     switch (ctx->nr) {
+     618                 :          0 :         case 10:
+     619                 :            : 
+     620         [ #  # ]:          0 :             for (unsigned int i = 0; i < 10; i++, RK += 4) {
+     621                 :          0 :                 RK[4]  = RK[0] ^ round_constants[i] ^
+     622                 :          0 :                          ((uint32_t) FSb[MBEDTLS_BYTE_1(RK[3])]) ^
+     623                 :          0 :                          ((uint32_t) FSb[MBEDTLS_BYTE_2(RK[3])] <<  8) ^
+     624                 :          0 :                          ((uint32_t) FSb[MBEDTLS_BYTE_3(RK[3])] << 16) ^
+     625                 :          0 :                          ((uint32_t) FSb[MBEDTLS_BYTE_0(RK[3])] << 24);
+     626                 :            : 
+     627                 :          0 :                 RK[5]  = RK[1] ^ RK[4];
+     628                 :          0 :                 RK[6]  = RK[2] ^ RK[5];
+     629                 :          0 :                 RK[7]  = RK[3] ^ RK[6];
+     630                 :            :             }
+     631                 :          0 :             break;
+     632                 :            : 
+     633                 :            : #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
+     634                 :          0 :         case 12:
+     635                 :            : 
+     636         [ #  # ]:          0 :             for (unsigned int i = 0; i < 8; i++, RK += 6) {
+     637                 :          0 :                 RK[6]  = RK[0] ^ round_constants[i] ^
+     638                 :          0 :                          ((uint32_t) FSb[MBEDTLS_BYTE_1(RK[5])]) ^
+     639                 :          0 :                          ((uint32_t) FSb[MBEDTLS_BYTE_2(RK[5])] <<  8) ^
+     640                 :          0 :                          ((uint32_t) FSb[MBEDTLS_BYTE_3(RK[5])] << 16) ^
+     641                 :          0 :                          ((uint32_t) FSb[MBEDTLS_BYTE_0(RK[5])] << 24);
+     642                 :            : 
+     643                 :          0 :                 RK[7]  = RK[1] ^ RK[6];
+     644                 :          0 :                 RK[8]  = RK[2] ^ RK[7];
+     645                 :          0 :                 RK[9]  = RK[3] ^ RK[8];
+     646                 :          0 :                 RK[10] = RK[4] ^ RK[9];
+     647                 :          0 :                 RK[11] = RK[5] ^ RK[10];
+     648                 :            :             }
+     649                 :          0 :             break;
+     650                 :            : 
+     651                 :          0 :         case 14:
+     652                 :            : 
+     653         [ #  # ]:          0 :             for (unsigned int i = 0; i < 7; i++, RK += 8) {
+     654                 :          0 :                 RK[8]  = RK[0] ^ round_constants[i] ^
+     655                 :          0 :                          ((uint32_t) FSb[MBEDTLS_BYTE_1(RK[7])]) ^
+     656                 :          0 :                          ((uint32_t) FSb[MBEDTLS_BYTE_2(RK[7])] <<  8) ^
+     657                 :          0 :                          ((uint32_t) FSb[MBEDTLS_BYTE_3(RK[7])] << 16) ^
+     658                 :          0 :                          ((uint32_t) FSb[MBEDTLS_BYTE_0(RK[7])] << 24);
+     659                 :            : 
+     660                 :          0 :                 RK[9]  = RK[1] ^ RK[8];
+     661                 :          0 :                 RK[10] = RK[2] ^ RK[9];
+     662                 :          0 :                 RK[11] = RK[3] ^ RK[10];
+     663                 :            : 
+     664                 :          0 :                 RK[12] = RK[4] ^
+     665                 :          0 :                          ((uint32_t) FSb[MBEDTLS_BYTE_0(RK[11])]) ^
+     666                 :          0 :                          ((uint32_t) FSb[MBEDTLS_BYTE_1(RK[11])] <<  8) ^
+     667                 :          0 :                          ((uint32_t) FSb[MBEDTLS_BYTE_2(RK[11])] << 16) ^
+     668                 :          0 :                          ((uint32_t) FSb[MBEDTLS_BYTE_3(RK[11])] << 24);
+     669                 :            : 
+     670                 :          0 :                 RK[13] = RK[5] ^ RK[12];
+     671                 :          0 :                 RK[14] = RK[6] ^ RK[13];
+     672                 :          0 :                 RK[15] = RK[7] ^ RK[14];
+     673                 :            :             }
+     674                 :          0 :             break;
+     675                 :            : #endif /* !MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
+     676                 :            :     }
+     677                 :            : 
+     678                 :          0 :     return 0;
+     679                 :            : #endif /* !MBEDTLS_AES_USE_HARDWARE_ONLY */
+     680                 :            : }
+     681                 :            : #endif /* !MBEDTLS_AES_SETKEY_ENC_ALT */
+     682                 :            : 
+     683                 :            : /*
+     684                 :            :  * AES key schedule (decryption)
+     685                 :            :  */
+     686                 :            : #if !defined(MBEDTLS_AES_SETKEY_DEC_ALT) && !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
+     687                 :          0 : int mbedtls_aes_setkey_dec(mbedtls_aes_context *ctx, const unsigned char *key,
+     688                 :            :                            unsigned int keybits)
+     689                 :            : {
+     690                 :            : #if !defined(MBEDTLS_AES_USE_HARDWARE_ONLY)
+     691                 :            :     uint32_t *SK;
+     692                 :            : #endif
+     693                 :            :     int ret;
+     694                 :            :     mbedtls_aes_context cty;
+     695                 :            :     uint32_t *RK;
+     696                 :            : 
+     697                 :            : 
+     698                 :          0 :     mbedtls_aes_init(&cty);
+     699                 :            : 
+     700                 :          0 :     ctx->rk_offset = mbedtls_aes_rk_offset(ctx->buf);
+     701                 :          0 :     RK = ctx->buf + ctx->rk_offset;
+     702                 :            : 
+     703                 :            :     /* Also checks keybits */
+     704         [ #  # ]:          0 :     if ((ret = mbedtls_aes_setkey_enc(&cty, key, keybits)) != 0) {
+     705                 :          0 :         goto exit;
+     706                 :            :     }
+     707                 :            : 
+     708                 :          0 :     ctx->nr = cty.nr;
+     709                 :            : 
+     710                 :            : #if defined(MBEDTLS_AESNI_HAVE_CODE)
+     711         [ #  # ]:          0 :     if (mbedtls_aesni_has_support(MBEDTLS_AESNI_AES)) {
+     712                 :          0 :         mbedtls_aesni_inverse_key((unsigned char *) RK,
+     713                 :          0 :                                   (const unsigned char *) (cty.buf + cty.rk_offset), ctx->nr);
+     714                 :          0 :         goto exit;
+     715                 :            :     }
+     716                 :            : #endif
+     717                 :            : 
+     718                 :            : #if defined(MBEDTLS_AESCE_HAVE_CODE)
+     719                 :            :     if (MBEDTLS_AESCE_HAS_SUPPORT()) {
+     720                 :            :         mbedtls_aesce_inverse_key(
+     721                 :            :             (unsigned char *) RK,
+     722                 :            :             (const unsigned char *) (cty.buf + cty.rk_offset),
+     723                 :            :             ctx->nr);
+     724                 :            :         goto exit;
+     725                 :            :     }
+     726                 :            : #endif
+     727                 :            : 
+     728                 :            : #if !defined(MBEDTLS_AES_USE_HARDWARE_ONLY)
+     729                 :          0 :     SK = cty.buf + cty.rk_offset + cty.nr * 4;
+     730                 :            : 
+     731                 :          0 :     *RK++ = *SK++;
+     732                 :          0 :     *RK++ = *SK++;
+     733                 :          0 :     *RK++ = *SK++;
+     734                 :          0 :     *RK++ = *SK++;
+     735                 :          0 :     SK -= 8;
+     736         [ #  # ]:          0 :     for (int i = ctx->nr - 1; i > 0; i--, SK -= 8) {
+     737         [ #  # ]:          0 :         for (int j = 0; j < 4; j++, SK++) {
+     738                 :          0 :             *RK++ = AES_RT0(FSb[MBEDTLS_BYTE_0(*SK)]) ^
+     739                 :          0 :                     AES_RT1(FSb[MBEDTLS_BYTE_1(*SK)]) ^
+     740                 :          0 :                     AES_RT2(FSb[MBEDTLS_BYTE_2(*SK)]) ^
+     741                 :          0 :                     AES_RT3(FSb[MBEDTLS_BYTE_3(*SK)]);
+     742                 :            :         }
+     743                 :            :     }
+     744                 :            : 
+     745                 :          0 :     *RK++ = *SK++;
+     746                 :          0 :     *RK++ = *SK++;
+     747                 :          0 :     *RK++ = *SK++;
+     748                 :          0 :     *RK++ = *SK++;
+     749                 :            : #endif /* !MBEDTLS_AES_USE_HARDWARE_ONLY */
+     750                 :          0 : exit:
+     751                 :          0 :     mbedtls_aes_free(&cty);
+     752                 :            : 
+     753                 :          0 :     return ret;
+     754                 :            : }
+     755                 :            : #endif /* !MBEDTLS_AES_SETKEY_DEC_ALT && !MBEDTLS_BLOCK_CIPHER_NO_DECRYPT */
+     756                 :            : 
+     757                 :            : #if defined(MBEDTLS_CIPHER_MODE_XTS)
+     758                 :            : static int mbedtls_aes_xts_decode_keys(const unsigned char *key,
+     759                 :            :                                        unsigned int keybits,
+     760                 :            :                                        const unsigned char **key1,
+     761                 :            :                                        unsigned int *key1bits,
+     762                 :            :                                        const unsigned char **key2,
+     763                 :            :                                        unsigned int *key2bits)
+     764                 :            : {
+     765                 :            :     const unsigned int half_keybits = keybits / 2;
+     766                 :            :     const unsigned int half_keybytes = half_keybits / 8;
+     767                 :            : 
+     768                 :            :     switch (keybits) {
+     769                 :            :         case 256: break;
+     770                 :            :         case 512: break;
+     771                 :            :         default: return MBEDTLS_ERR_AES_INVALID_KEY_LENGTH;
+     772                 :            :     }
+     773                 :            : 
+     774                 :            :     *key1bits = half_keybits;
+     775                 :            :     *key2bits = half_keybits;
+     776                 :            :     *key1 = &key[0];
+     777                 :            :     *key2 = &key[half_keybytes];
+     778                 :            : 
+     779                 :            :     return 0;
+     780                 :            : }
+     781                 :            : 
+     782                 :            : int mbedtls_aes_xts_setkey_enc(mbedtls_aes_xts_context *ctx,
+     783                 :            :                                const unsigned char *key,
+     784                 :            :                                unsigned int keybits)
+     785                 :            : {
+     786                 :            :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     787                 :            :     const unsigned char *key1, *key2;
+     788                 :            :     unsigned int key1bits, key2bits;
+     789                 :            : 
+     790                 :            :     ret = mbedtls_aes_xts_decode_keys(key, keybits, &key1, &key1bits,
+     791                 :            :                                       &key2, &key2bits);
+     792                 :            :     if (ret != 0) {
+     793                 :            :         return ret;
+     794                 :            :     }
+     795                 :            : 
+     796                 :            :     /* Set the tweak key. Always set tweak key for the encryption mode. */
+     797                 :            :     ret = mbedtls_aes_setkey_enc(&ctx->tweak, key2, key2bits);
+     798                 :            :     if (ret != 0) {
+     799                 :            :         return ret;
+     800                 :            :     }
+     801                 :            : 
+     802                 :            :     /* Set crypt key for encryption. */
+     803                 :            :     return mbedtls_aes_setkey_enc(&ctx->crypt, key1, key1bits);
+     804                 :            : }
+     805                 :            : 
+     806                 :            : int mbedtls_aes_xts_setkey_dec(mbedtls_aes_xts_context *ctx,
+     807                 :            :                                const unsigned char *key,
+     808                 :            :                                unsigned int keybits)
+     809                 :            : {
+     810                 :            :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     811                 :            :     const unsigned char *key1, *key2;
+     812                 :            :     unsigned int key1bits, key2bits;
+     813                 :            : 
+     814                 :            :     ret = mbedtls_aes_xts_decode_keys(key, keybits, &key1, &key1bits,
+     815                 :            :                                       &key2, &key2bits);
+     816                 :            :     if (ret != 0) {
+     817                 :            :         return ret;
+     818                 :            :     }
+     819                 :            : 
+     820                 :            :     /* Set the tweak key. Always set tweak key for encryption. */
+     821                 :            :     ret = mbedtls_aes_setkey_enc(&ctx->tweak, key2, key2bits);
+     822                 :            :     if (ret != 0) {
+     823                 :            :         return ret;
+     824                 :            :     }
+     825                 :            : 
+     826                 :            :     /* Set crypt key for decryption. */
+     827                 :            :     return mbedtls_aes_setkey_dec(&ctx->crypt, key1, key1bits);
+     828                 :            : }
+     829                 :            : #endif /* MBEDTLS_CIPHER_MODE_XTS */
+     830                 :            : 
+     831                 :            : #define AES_FROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3)                 \
+     832                 :            :     do                                                      \
+     833                 :            :     {                                                       \
+     834                 :            :         (X0) = *RK++ ^ AES_FT0(MBEDTLS_BYTE_0(Y0)) ^    \
+     835                 :            :                AES_FT1(MBEDTLS_BYTE_1(Y1)) ^    \
+     836                 :            :                AES_FT2(MBEDTLS_BYTE_2(Y2)) ^    \
+     837                 :            :                AES_FT3(MBEDTLS_BYTE_3(Y3));     \
+     838                 :            :                                                             \
+     839                 :            :         (X1) = *RK++ ^ AES_FT0(MBEDTLS_BYTE_0(Y1)) ^    \
+     840                 :            :                AES_FT1(MBEDTLS_BYTE_1(Y2)) ^    \
+     841                 :            :                AES_FT2(MBEDTLS_BYTE_2(Y3)) ^    \
+     842                 :            :                AES_FT3(MBEDTLS_BYTE_3(Y0));     \
+     843                 :            :                                                             \
+     844                 :            :         (X2) = *RK++ ^ AES_FT0(MBEDTLS_BYTE_0(Y2)) ^    \
+     845                 :            :                AES_FT1(MBEDTLS_BYTE_1(Y3)) ^    \
+     846                 :            :                AES_FT2(MBEDTLS_BYTE_2(Y0)) ^    \
+     847                 :            :                AES_FT3(MBEDTLS_BYTE_3(Y1));     \
+     848                 :            :                                                             \
+     849                 :            :         (X3) = *RK++ ^ AES_FT0(MBEDTLS_BYTE_0(Y3)) ^    \
+     850                 :            :                AES_FT1(MBEDTLS_BYTE_1(Y0)) ^    \
+     851                 :            :                AES_FT2(MBEDTLS_BYTE_2(Y1)) ^    \
+     852                 :            :                AES_FT3(MBEDTLS_BYTE_3(Y2));     \
+     853                 :            :     } while (0)
+     854                 :            : 
+     855                 :            : #define AES_RROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3)                 \
+     856                 :            :     do                                                      \
+     857                 :            :     {                                                       \
+     858                 :            :         (X0) = *RK++ ^ AES_RT0(MBEDTLS_BYTE_0(Y0)) ^    \
+     859                 :            :                AES_RT1(MBEDTLS_BYTE_1(Y3)) ^    \
+     860                 :            :                AES_RT2(MBEDTLS_BYTE_2(Y2)) ^    \
+     861                 :            :                AES_RT3(MBEDTLS_BYTE_3(Y1));     \
+     862                 :            :                                                             \
+     863                 :            :         (X1) = *RK++ ^ AES_RT0(MBEDTLS_BYTE_0(Y1)) ^    \
+     864                 :            :                AES_RT1(MBEDTLS_BYTE_1(Y0)) ^    \
+     865                 :            :                AES_RT2(MBEDTLS_BYTE_2(Y3)) ^    \
+     866                 :            :                AES_RT3(MBEDTLS_BYTE_3(Y2));     \
+     867                 :            :                                                             \
+     868                 :            :         (X2) = *RK++ ^ AES_RT0(MBEDTLS_BYTE_0(Y2)) ^    \
+     869                 :            :                AES_RT1(MBEDTLS_BYTE_1(Y1)) ^    \
+     870                 :            :                AES_RT2(MBEDTLS_BYTE_2(Y0)) ^    \
+     871                 :            :                AES_RT3(MBEDTLS_BYTE_3(Y3));     \
+     872                 :            :                                                             \
+     873                 :            :         (X3) = *RK++ ^ AES_RT0(MBEDTLS_BYTE_0(Y3)) ^    \
+     874                 :            :                AES_RT1(MBEDTLS_BYTE_1(Y2)) ^    \
+     875                 :            :                AES_RT2(MBEDTLS_BYTE_2(Y1)) ^    \
+     876                 :            :                AES_RT3(MBEDTLS_BYTE_3(Y0));     \
+     877                 :            :     } while (0)
+     878                 :            : 
+     879                 :            : /*
+     880                 :            :  * AES-ECB block encryption
+     881                 :            :  */
+     882                 :            : #if !defined(MBEDTLS_AES_ENCRYPT_ALT)
+     883                 :          0 : int mbedtls_internal_aes_encrypt(mbedtls_aes_context *ctx,
+     884                 :            :                                  const unsigned char input[16],
+     885                 :            :                                  unsigned char output[16])
+     886                 :            : {
+     887                 :            :     int i;
+     888                 :          0 :     uint32_t *RK = ctx->buf + ctx->rk_offset;
+     889                 :            :     struct {
+     890                 :            :         uint32_t X[4];
+     891                 :            :         uint32_t Y[4];
+     892                 :            :     } t;
+     893                 :            : 
+     894                 :          0 :     t.X[0] = MBEDTLS_GET_UINT32_LE(input,  0); t.X[0] ^= *RK++;
+     895                 :          0 :     t.X[1] = MBEDTLS_GET_UINT32_LE(input,  4); t.X[1] ^= *RK++;
+     896                 :          0 :     t.X[2] = MBEDTLS_GET_UINT32_LE(input,  8); t.X[2] ^= *RK++;
+     897                 :          0 :     t.X[3] = MBEDTLS_GET_UINT32_LE(input, 12); t.X[3] ^= *RK++;
+     898                 :            : 
+     899         [ #  # ]:          0 :     for (i = (ctx->nr >> 1) - 1; i > 0; i--) {
+     900                 :          0 :         AES_FROUND(t.Y[0], t.Y[1], t.Y[2], t.Y[3], t.X[0], t.X[1], t.X[2], t.X[3]);
+     901                 :          0 :         AES_FROUND(t.X[0], t.X[1], t.X[2], t.X[3], t.Y[0], t.Y[1], t.Y[2], t.Y[3]);
+     902                 :            :     }
+     903                 :            : 
+     904                 :          0 :     AES_FROUND(t.Y[0], t.Y[1], t.Y[2], t.Y[3], t.X[0], t.X[1], t.X[2], t.X[3]);
+     905                 :            : 
+     906                 :          0 :     t.X[0] = *RK++ ^ \
+     907                 :          0 :              ((uint32_t) FSb[MBEDTLS_BYTE_0(t.Y[0])]) ^
+     908                 :          0 :              ((uint32_t) FSb[MBEDTLS_BYTE_1(t.Y[1])] <<  8) ^
+     909                 :          0 :              ((uint32_t) FSb[MBEDTLS_BYTE_2(t.Y[2])] << 16) ^
+     910                 :          0 :              ((uint32_t) FSb[MBEDTLS_BYTE_3(t.Y[3])] << 24);
+     911                 :            : 
+     912                 :          0 :     t.X[1] = *RK++ ^ \
+     913                 :          0 :              ((uint32_t) FSb[MBEDTLS_BYTE_0(t.Y[1])]) ^
+     914                 :          0 :              ((uint32_t) FSb[MBEDTLS_BYTE_1(t.Y[2])] <<  8) ^
+     915                 :          0 :              ((uint32_t) FSb[MBEDTLS_BYTE_2(t.Y[3])] << 16) ^
+     916                 :          0 :              ((uint32_t) FSb[MBEDTLS_BYTE_3(t.Y[0])] << 24);
+     917                 :            : 
+     918                 :          0 :     t.X[2] = *RK++ ^ \
+     919                 :          0 :              ((uint32_t) FSb[MBEDTLS_BYTE_0(t.Y[2])]) ^
+     920                 :          0 :              ((uint32_t) FSb[MBEDTLS_BYTE_1(t.Y[3])] <<  8) ^
+     921                 :          0 :              ((uint32_t) FSb[MBEDTLS_BYTE_2(t.Y[0])] << 16) ^
+     922                 :          0 :              ((uint32_t) FSb[MBEDTLS_BYTE_3(t.Y[1])] << 24);
+     923                 :            : 
+     924                 :          0 :     t.X[3] = *RK++ ^ \
+     925                 :          0 :              ((uint32_t) FSb[MBEDTLS_BYTE_0(t.Y[3])]) ^
+     926                 :          0 :              ((uint32_t) FSb[MBEDTLS_BYTE_1(t.Y[0])] <<  8) ^
+     927                 :          0 :              ((uint32_t) FSb[MBEDTLS_BYTE_2(t.Y[1])] << 16) ^
+     928                 :          0 :              ((uint32_t) FSb[MBEDTLS_BYTE_3(t.Y[2])] << 24);
+     929                 :            : 
+     930                 :          0 :     MBEDTLS_PUT_UINT32_LE(t.X[0], output,  0);
+     931                 :          0 :     MBEDTLS_PUT_UINT32_LE(t.X[1], output,  4);
+     932                 :          0 :     MBEDTLS_PUT_UINT32_LE(t.X[2], output,  8);
+     933                 :          0 :     MBEDTLS_PUT_UINT32_LE(t.X[3], output, 12);
+     934                 :            : 
+     935                 :          0 :     mbedtls_platform_zeroize(&t, sizeof(t));
+     936                 :            : 
+     937                 :          0 :     return 0;
+     938                 :            : }
+     939                 :            : #endif /* !MBEDTLS_AES_ENCRYPT_ALT */
+     940                 :            : 
+     941                 :            : /*
+     942                 :            :  * AES-ECB block decryption
+     943                 :            :  */
+     944                 :            : #if !defined(MBEDTLS_AES_DECRYPT_ALT) && !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
+     945                 :          0 : int mbedtls_internal_aes_decrypt(mbedtls_aes_context *ctx,
+     946                 :            :                                  const unsigned char input[16],
+     947                 :            :                                  unsigned char output[16])
+     948                 :            : {
+     949                 :            :     int i;
+     950                 :          0 :     uint32_t *RK = ctx->buf + ctx->rk_offset;
+     951                 :            :     struct {
+     952                 :            :         uint32_t X[4];
+     953                 :            :         uint32_t Y[4];
+     954                 :            :     } t;
+     955                 :            : 
+     956                 :          0 :     t.X[0] = MBEDTLS_GET_UINT32_LE(input,  0); t.X[0] ^= *RK++;
+     957                 :          0 :     t.X[1] = MBEDTLS_GET_UINT32_LE(input,  4); t.X[1] ^= *RK++;
+     958                 :          0 :     t.X[2] = MBEDTLS_GET_UINT32_LE(input,  8); t.X[2] ^= *RK++;
+     959                 :          0 :     t.X[3] = MBEDTLS_GET_UINT32_LE(input, 12); t.X[3] ^= *RK++;
+     960                 :            : 
+     961         [ #  # ]:          0 :     for (i = (ctx->nr >> 1) - 1; i > 0; i--) {
+     962                 :          0 :         AES_RROUND(t.Y[0], t.Y[1], t.Y[2], t.Y[3], t.X[0], t.X[1], t.X[2], t.X[3]);
+     963                 :          0 :         AES_RROUND(t.X[0], t.X[1], t.X[2], t.X[3], t.Y[0], t.Y[1], t.Y[2], t.Y[3]);
+     964                 :            :     }
+     965                 :            : 
+     966                 :          0 :     AES_RROUND(t.Y[0], t.Y[1], t.Y[2], t.Y[3], t.X[0], t.X[1], t.X[2], t.X[3]);
+     967                 :            : 
+     968                 :          0 :     t.X[0] = *RK++ ^ \
+     969                 :          0 :              ((uint32_t) RSb[MBEDTLS_BYTE_0(t.Y[0])]) ^
+     970                 :          0 :              ((uint32_t) RSb[MBEDTLS_BYTE_1(t.Y[3])] <<  8) ^
+     971                 :          0 :              ((uint32_t) RSb[MBEDTLS_BYTE_2(t.Y[2])] << 16) ^
+     972                 :          0 :              ((uint32_t) RSb[MBEDTLS_BYTE_3(t.Y[1])] << 24);
+     973                 :            : 
+     974                 :          0 :     t.X[1] = *RK++ ^ \
+     975                 :          0 :              ((uint32_t) RSb[MBEDTLS_BYTE_0(t.Y[1])]) ^
+     976                 :          0 :              ((uint32_t) RSb[MBEDTLS_BYTE_1(t.Y[0])] <<  8) ^
+     977                 :          0 :              ((uint32_t) RSb[MBEDTLS_BYTE_2(t.Y[3])] << 16) ^
+     978                 :          0 :              ((uint32_t) RSb[MBEDTLS_BYTE_3(t.Y[2])] << 24);
+     979                 :            : 
+     980                 :          0 :     t.X[2] = *RK++ ^ \
+     981                 :          0 :              ((uint32_t) RSb[MBEDTLS_BYTE_0(t.Y[2])]) ^
+     982                 :          0 :              ((uint32_t) RSb[MBEDTLS_BYTE_1(t.Y[1])] <<  8) ^
+     983                 :          0 :              ((uint32_t) RSb[MBEDTLS_BYTE_2(t.Y[0])] << 16) ^
+     984                 :          0 :              ((uint32_t) RSb[MBEDTLS_BYTE_3(t.Y[3])] << 24);
+     985                 :            : 
+     986                 :          0 :     t.X[3] = *RK++ ^ \
+     987                 :          0 :              ((uint32_t) RSb[MBEDTLS_BYTE_0(t.Y[3])]) ^
+     988                 :          0 :              ((uint32_t) RSb[MBEDTLS_BYTE_1(t.Y[2])] <<  8) ^
+     989                 :          0 :              ((uint32_t) RSb[MBEDTLS_BYTE_2(t.Y[1])] << 16) ^
+     990                 :          0 :              ((uint32_t) RSb[MBEDTLS_BYTE_3(t.Y[0])] << 24);
+     991                 :            : 
+     992                 :          0 :     MBEDTLS_PUT_UINT32_LE(t.X[0], output,  0);
+     993                 :          0 :     MBEDTLS_PUT_UINT32_LE(t.X[1], output,  4);
+     994                 :          0 :     MBEDTLS_PUT_UINT32_LE(t.X[2], output,  8);
+     995                 :          0 :     MBEDTLS_PUT_UINT32_LE(t.X[3], output, 12);
+     996                 :            : 
+     997                 :          0 :     mbedtls_platform_zeroize(&t, sizeof(t));
+     998                 :            : 
+     999                 :          0 :     return 0;
+    1000                 :            : }
+    1001                 :            : #endif /* !MBEDTLS_AES_DECRYPT_ALT && !MBEDTLS_BLOCK_CIPHER_NO_DECRYPT */
+    1002                 :            : 
+    1003                 :            : /* VIA Padlock and our intrinsics-based implementation of AESNI require
+    1004                 :            :  * the round keys to be aligned on a 16-byte boundary. We take care of this
+    1005                 :            :  * before creating them, but the AES context may have moved (this can happen
+    1006                 :            :  * if the library is called from a language with managed memory), and in later
+    1007                 :            :  * calls it might have a different alignment with respect to 16-byte memory.
+    1008                 :            :  * So we may need to realign.
+    1009                 :            :  */
+    1010                 :          0 : MBEDTLS_MAYBE_UNUSED static void aes_maybe_realign(mbedtls_aes_context *ctx)
+    1011                 :            : {
+    1012                 :          0 :     unsigned new_offset = mbedtls_aes_rk_offset(ctx->buf);
+    1013         [ #  # ]:          0 :     if (new_offset != ctx->rk_offset) {
+    1014                 :          0 :         memmove(ctx->buf + new_offset,     // new address
+    1015                 :          0 :                 ctx->buf + ctx->rk_offset, // current address
+    1016                 :          0 :                 (ctx->nr + 1) * 16);       // number of round keys * bytes per rk
+    1017                 :          0 :         ctx->rk_offset = new_offset;
+    1018                 :            :     }
+    1019                 :          0 : }
+    1020                 :            : 
+    1021                 :            : /*
+    1022                 :            :  * AES-ECB block encryption/decryption
+    1023                 :            :  */
+    1024                 :       3654 : int mbedtls_aes_crypt_ecb(mbedtls_aes_context *ctx,
+    1025                 :            :                           int mode,
+    1026                 :            :                           const unsigned char input[16],
+    1027                 :            :                           unsigned char output[16])
+    1028                 :            : {
+    1029   [ -  +  -  - ]:       3654 :     if (mode != MBEDTLS_AES_ENCRYPT && mode != MBEDTLS_AES_DECRYPT) {
+    1030                 :          0 :         return MBEDTLS_ERR_AES_BAD_INPUT_DATA;
+    1031                 :            :     }
+    1032                 :            : 
+    1033                 :            : #if defined(MAY_NEED_TO_ALIGN)
+    1034                 :            :     aes_maybe_realign(ctx);
+    1035                 :            : #endif
+    1036                 :            : 
+    1037                 :            : #if defined(MBEDTLS_AESNI_HAVE_CODE)
+    1038         [ +  - ]:       3654 :     if (mbedtls_aesni_has_support(MBEDTLS_AESNI_AES)) {
+    1039                 :       3654 :         return mbedtls_aesni_crypt_ecb(ctx, mode, input, output);
+    1040                 :            :     }
+    1041                 :            : #endif
+    1042                 :            : 
+    1043                 :            : #if defined(MBEDTLS_AESCE_HAVE_CODE)
+    1044                 :            :     if (MBEDTLS_AESCE_HAS_SUPPORT()) {
+    1045                 :            :         return mbedtls_aesce_crypt_ecb(ctx, mode, input, output);
+    1046                 :            :     }
+    1047                 :            : #endif
+    1048                 :            : 
+    1049                 :            : #if defined(MBEDTLS_VIA_PADLOCK_HAVE_CODE)
+    1050                 :            :     if (aes_padlock_ace > 0) {
+    1051                 :            :         return mbedtls_padlock_xcryptecb(ctx, mode, input, output);
+    1052                 :            :     }
+    1053                 :            : #endif
+    1054                 :            : 
+    1055                 :            : #if !defined(MBEDTLS_AES_USE_HARDWARE_ONLY)
+    1056                 :            : #if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
+    1057         [ #  # ]:          0 :     if (mode == MBEDTLS_AES_DECRYPT) {
+    1058                 :          0 :         return mbedtls_internal_aes_decrypt(ctx, input, output);
+    1059                 :            :     } else
+    1060                 :            : #endif
+    1061                 :            :     {
+    1062                 :          0 :         return mbedtls_internal_aes_encrypt(ctx, input, output);
+    1063                 :            :     }
+    1064                 :            : #endif /* !MBEDTLS_AES_USE_HARDWARE_ONLY */
+    1065                 :            : }
+    1066                 :            : 
+    1067                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+    1068                 :            : 
+    1069                 :            : /*
+    1070                 :            :  * AES-CBC buffer encryption/decryption
+    1071                 :            :  */
+    1072                 :          0 : int mbedtls_aes_crypt_cbc(mbedtls_aes_context *ctx,
+    1073                 :            :                           int mode,
+    1074                 :            :                           size_t length,
+    1075                 :            :                           unsigned char iv[16],
+    1076                 :            :                           const unsigned char *input,
+    1077                 :            :                           unsigned char *output)
+    1078                 :            : {
+    1079                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1080                 :            :     unsigned char temp[16];
+    1081                 :            : 
+    1082   [ #  #  #  # ]:          0 :     if (mode != MBEDTLS_AES_ENCRYPT && mode != MBEDTLS_AES_DECRYPT) {
+    1083                 :          0 :         return MBEDTLS_ERR_AES_BAD_INPUT_DATA;
+    1084                 :            :     }
+    1085                 :            : 
+    1086                 :            :     /* Nothing to do if length is zero. */
+    1087         [ #  # ]:          0 :     if (length == 0) {
+    1088                 :          0 :         return 0;
+    1089                 :            :     }
+    1090                 :            : 
+    1091         [ #  # ]:          0 :     if (length % 16) {
+    1092                 :          0 :         return MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH;
+    1093                 :            :     }
+    1094                 :            : 
+    1095                 :            : #if defined(MBEDTLS_VIA_PADLOCK_HAVE_CODE)
+    1096                 :            :     if (aes_padlock_ace > 0) {
+    1097                 :            :         if (mbedtls_padlock_xcryptcbc(ctx, mode, length, iv, input, output) == 0) {
+    1098                 :            :             return 0;
+    1099                 :            :         }
+    1100                 :            : 
+    1101                 :            :         // If padlock data misaligned, we just fall back to
+    1102                 :            :         // unaccelerated mode
+    1103                 :            :         //
+    1104                 :            :     }
+    1105                 :            : #endif
+    1106                 :            : 
+    1107                 :          0 :     const unsigned char *ivp = iv;
+    1108                 :            : 
+    1109         [ #  # ]:          0 :     if (mode == MBEDTLS_AES_DECRYPT) {
+    1110         [ #  # ]:          0 :         while (length > 0) {
+    1111                 :          0 :             memcpy(temp, input, 16);
+    1112                 :          0 :             ret = mbedtls_aes_crypt_ecb(ctx, mode, input, output);
+    1113         [ #  # ]:          0 :             if (ret != 0) {
+    1114                 :          0 :                 goto exit;
+    1115                 :            :             }
+    1116                 :            :             /* Avoid using the NEON implementation of mbedtls_xor. Because of the dependency on
+    1117                 :            :              * the result for the next block in CBC, and the cost of transferring that data from
+    1118                 :            :              * NEON registers, NEON is slower on aarch64. */
+    1119                 :            :             mbedtls_xor_no_simd(output, output, iv, 16);
+    1120                 :            : 
+    1121                 :          0 :             memcpy(iv, temp, 16);
+    1122                 :            : 
+    1123                 :          0 :             input  += 16;
+    1124                 :          0 :             output += 16;
+    1125                 :          0 :             length -= 16;
+    1126                 :            :         }
+    1127                 :            :     } else {
+    1128         [ #  # ]:          0 :         while (length > 0) {
+    1129                 :            :             mbedtls_xor_no_simd(output, input, ivp, 16);
+    1130                 :            : 
+    1131                 :          0 :             ret = mbedtls_aes_crypt_ecb(ctx, mode, output, output);
+    1132         [ #  # ]:          0 :             if (ret != 0) {
+    1133                 :          0 :                 goto exit;
+    1134                 :            :             }
+    1135                 :          0 :             ivp = output;
+    1136                 :            : 
+    1137                 :          0 :             input  += 16;
+    1138                 :          0 :             output += 16;
+    1139                 :          0 :             length -= 16;
+    1140                 :            :         }
+    1141                 :          0 :         memcpy(iv, ivp, 16);
+    1142                 :            :     }
+    1143                 :          0 :     ret = 0;
+    1144                 :            : 
+    1145                 :          0 : exit:
+    1146                 :          0 :     return ret;
+    1147                 :            : }
+    1148                 :            : #endif /* MBEDTLS_CIPHER_MODE_CBC */
+    1149                 :            : 
+    1150                 :            : #if defined(MBEDTLS_CIPHER_MODE_XTS)
+    1151                 :            : 
+    1152                 :            : typedef unsigned char mbedtls_be128[16];
+    1153                 :            : 
+    1154                 :            : /*
+    1155                 :            :  * GF(2^128) multiplication function
+    1156                 :            :  *
+    1157                 :            :  * This function multiplies a field element by x in the polynomial field
+    1158                 :            :  * representation. It uses 64-bit word operations to gain speed but compensates
+    1159                 :            :  * for machine endianness and hence works correctly on both big and little
+    1160                 :            :  * endian machines.
+    1161                 :            :  */
+    1162                 :            : #if defined(MBEDTLS_AESCE_C) || defined(MBEDTLS_AESNI_C)
+    1163                 :            : MBEDTLS_OPTIMIZE_FOR_PERFORMANCE
+    1164                 :            : #endif
+    1165                 :            : static inline void mbedtls_gf128mul_x_ble(unsigned char r[16],
+    1166                 :            :                                           const unsigned char x[16])
+    1167                 :            : {
+    1168                 :            :     uint64_t a, b, ra, rb;
+    1169                 :            : 
+    1170                 :            :     a = MBEDTLS_GET_UINT64_LE(x, 0);
+    1171                 :            :     b = MBEDTLS_GET_UINT64_LE(x, 8);
+    1172                 :            : 
+    1173                 :            :     ra = (a << 1)  ^ 0x0087 >> (8 - ((b >> 63) << 3));
+    1174                 :            :     rb = (a >> 63) | (b << 1);
+    1175                 :            : 
+    1176                 :            :     MBEDTLS_PUT_UINT64_LE(ra, r, 0);
+    1177                 :            :     MBEDTLS_PUT_UINT64_LE(rb, r, 8);
+    1178                 :            : }
+    1179                 :            : 
+    1180                 :            : /*
+    1181                 :            :  * AES-XTS buffer encryption/decryption
+    1182                 :            :  *
+    1183                 :            :  * Use of MBEDTLS_OPTIMIZE_FOR_PERFORMANCE here and for mbedtls_gf128mul_x_ble()
+    1184                 :            :  * is a 3x performance improvement for gcc -Os, if we have hardware AES support.
+    1185                 :            :  */
+    1186                 :            : #if defined(MBEDTLS_AESCE_C) || defined(MBEDTLS_AESNI_C)
+    1187                 :            : MBEDTLS_OPTIMIZE_FOR_PERFORMANCE
+    1188                 :            : #endif
+    1189                 :            : int mbedtls_aes_crypt_xts(mbedtls_aes_xts_context *ctx,
+    1190                 :            :                           int mode,
+    1191                 :            :                           size_t length,
+    1192                 :            :                           const unsigned char data_unit[16],
+    1193                 :            :                           const unsigned char *input,
+    1194                 :            :                           unsigned char *output)
+    1195                 :            : {
+    1196                 :            :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1197                 :            :     size_t blocks = length / 16;
+    1198                 :            :     size_t leftover = length % 16;
+    1199                 :            :     unsigned char tweak[16];
+    1200                 :            :     unsigned char prev_tweak[16];
+    1201                 :            :     unsigned char tmp[16];
+    1202                 :            : 
+    1203                 :            :     if (mode != MBEDTLS_AES_ENCRYPT && mode != MBEDTLS_AES_DECRYPT) {
+    1204                 :            :         return MBEDTLS_ERR_AES_BAD_INPUT_DATA;
+    1205                 :            :     }
+    1206                 :            : 
+    1207                 :            :     /* Data units must be at least 16 bytes long. */
+    1208                 :            :     if (length < 16) {
+    1209                 :            :         return MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH;
+    1210                 :            :     }
+    1211                 :            : 
+    1212                 :            :     /* NIST SP 800-38E disallows data units larger than 2**20 blocks. */
+    1213                 :            :     if (length > (1 << 20) * 16) {
+    1214                 :            :         return MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH;
+    1215                 :            :     }
+    1216                 :            : 
+    1217                 :            :     /* Compute the tweak. */
+    1218                 :            :     ret = mbedtls_aes_crypt_ecb(&ctx->tweak, MBEDTLS_AES_ENCRYPT,
+    1219                 :            :                                 data_unit, tweak);
+    1220                 :            :     if (ret != 0) {
+    1221                 :            :         return ret;
+    1222                 :            :     }
+    1223                 :            : 
+    1224                 :            :     while (blocks--) {
+    1225                 :            :         if (MBEDTLS_UNLIKELY(leftover && (mode == MBEDTLS_AES_DECRYPT) && blocks == 0)) {
+    1226                 :            :             /* We are on the last block in a decrypt operation that has
+    1227                 :            :              * leftover bytes, so we need to use the next tweak for this block,
+    1228                 :            :              * and this tweak for the leftover bytes. Save the current tweak for
+    1229                 :            :              * the leftovers and then update the current tweak for use on this,
+    1230                 :            :              * the last full block. */
+    1231                 :            :             memcpy(prev_tweak, tweak, sizeof(tweak));
+    1232                 :            :             mbedtls_gf128mul_x_ble(tweak, tweak);
+    1233                 :            :         }
+    1234                 :            : 
+    1235                 :            :         mbedtls_xor(tmp, input, tweak, 16);
+    1236                 :            : 
+    1237                 :            :         ret = mbedtls_aes_crypt_ecb(&ctx->crypt, mode, tmp, tmp);
+    1238                 :            :         if (ret != 0) {
+    1239                 :            :             return ret;
+    1240                 :            :         }
+    1241                 :            : 
+    1242                 :            :         mbedtls_xor(output, tmp, tweak, 16);
+    1243                 :            : 
+    1244                 :            :         /* Update the tweak for the next block. */
+    1245                 :            :         mbedtls_gf128mul_x_ble(tweak, tweak);
+    1246                 :            : 
+    1247                 :            :         output += 16;
+    1248                 :            :         input += 16;
+    1249                 :            :     }
+    1250                 :            : 
+    1251                 :            :     if (leftover) {
+    1252                 :            :         /* If we are on the leftover bytes in a decrypt operation, we need to
+    1253                 :            :          * use the previous tweak for these bytes (as saved in prev_tweak). */
+    1254                 :            :         unsigned char *t = mode == MBEDTLS_AES_DECRYPT ? prev_tweak : tweak;
+    1255                 :            : 
+    1256                 :            :         /* We are now on the final part of the data unit, which doesn't divide
+    1257                 :            :          * evenly by 16. It's time for ciphertext stealing. */
+    1258                 :            :         size_t i;
+    1259                 :            :         unsigned char *prev_output = output - 16;
+    1260                 :            : 
+    1261                 :            :         /* Copy ciphertext bytes from the previous block to our output for each
+    1262                 :            :          * byte of ciphertext we won't steal. */
+    1263                 :            :         for (i = 0; i < leftover; i++) {
+    1264                 :            :             output[i] = prev_output[i];
+    1265                 :            :         }
+    1266                 :            : 
+    1267                 :            :         /* Copy the remainder of the input for this final round. */
+    1268                 :            :         mbedtls_xor(tmp, input, t, leftover);
+    1269                 :            : 
+    1270                 :            :         /* Copy ciphertext bytes from the previous block for input in this
+    1271                 :            :          * round. */
+    1272                 :            :         mbedtls_xor(tmp + i, prev_output + i, t + i, 16 - i);
+    1273                 :            : 
+    1274                 :            :         ret = mbedtls_aes_crypt_ecb(&ctx->crypt, mode, tmp, tmp);
+    1275                 :            :         if (ret != 0) {
+    1276                 :            :             return ret;
+    1277                 :            :         }
+    1278                 :            : 
+    1279                 :            :         /* Write the result back to the previous block, overriding the previous
+    1280                 :            :          * output we copied. */
+    1281                 :            :         mbedtls_xor(prev_output, tmp, t, 16);
+    1282                 :            :     }
+    1283                 :            : 
+    1284                 :            :     return 0;
+    1285                 :            : }
+    1286                 :            : #endif /* MBEDTLS_CIPHER_MODE_XTS */
+    1287                 :            : 
+    1288                 :            : #if defined(MBEDTLS_CIPHER_MODE_CFB)
+    1289                 :            : /*
+    1290                 :            :  * AES-CFB128 buffer encryption/decryption
+    1291                 :            :  */
+    1292                 :          0 : int mbedtls_aes_crypt_cfb128(mbedtls_aes_context *ctx,
+    1293                 :            :                              int mode,
+    1294                 :            :                              size_t length,
+    1295                 :            :                              size_t *iv_off,
+    1296                 :            :                              unsigned char iv[16],
+    1297                 :            :                              const unsigned char *input,
+    1298                 :            :                              unsigned char *output)
+    1299                 :            : {
+    1300                 :            :     int c;
+    1301                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1302                 :            :     size_t n;
+    1303                 :            : 
+    1304   [ #  #  #  # ]:          0 :     if (mode != MBEDTLS_AES_ENCRYPT && mode != MBEDTLS_AES_DECRYPT) {
+    1305                 :          0 :         return MBEDTLS_ERR_AES_BAD_INPUT_DATA;
+    1306                 :            :     }
+    1307                 :            : 
+    1308                 :          0 :     n = *iv_off;
+    1309                 :            : 
+    1310         [ #  # ]:          0 :     if (n > 15) {
+    1311                 :          0 :         return MBEDTLS_ERR_AES_BAD_INPUT_DATA;
+    1312                 :            :     }
+    1313                 :            : 
+    1314         [ #  # ]:          0 :     if (mode == MBEDTLS_AES_DECRYPT) {
+    1315         [ #  # ]:          0 :         while (length--) {
+    1316         [ #  # ]:          0 :             if (n == 0) {
+    1317                 :          0 :                 ret = mbedtls_aes_crypt_ecb(ctx, MBEDTLS_AES_ENCRYPT, iv, iv);
+    1318         [ #  # ]:          0 :                 if (ret != 0) {
+    1319                 :          0 :                     goto exit;
+    1320                 :            :                 }
+    1321                 :            :             }
+    1322                 :            : 
+    1323                 :          0 :             c = *input++;
+    1324                 :          0 :             *output++ = (unsigned char) (c ^ iv[n]);
+    1325                 :          0 :             iv[n] = (unsigned char) c;
+    1326                 :            : 
+    1327                 :          0 :             n = (n + 1) & 0x0F;
+    1328                 :            :         }
+    1329                 :            :     } else {
+    1330         [ #  # ]:          0 :         while (length--) {
+    1331         [ #  # ]:          0 :             if (n == 0) {
+    1332                 :          0 :                 ret = mbedtls_aes_crypt_ecb(ctx, MBEDTLS_AES_ENCRYPT, iv, iv);
+    1333         [ #  # ]:          0 :                 if (ret != 0) {
+    1334                 :          0 :                     goto exit;
+    1335                 :            :                 }
+    1336                 :            :             }
+    1337                 :            : 
+    1338                 :          0 :             iv[n] = *output++ = (unsigned char) (iv[n] ^ *input++);
+    1339                 :            : 
+    1340                 :          0 :             n = (n + 1) & 0x0F;
+    1341                 :            :         }
+    1342                 :            :     }
+    1343                 :            : 
+    1344                 :          0 :     *iv_off = n;
+    1345                 :          0 :     ret = 0;
+    1346                 :            : 
+    1347                 :          0 : exit:
+    1348                 :          0 :     return ret;
+    1349                 :            : }
+    1350                 :            : 
+    1351                 :            : /*
+    1352                 :            :  * AES-CFB8 buffer encryption/decryption
+    1353                 :            :  */
+    1354                 :          0 : int mbedtls_aes_crypt_cfb8(mbedtls_aes_context *ctx,
+    1355                 :            :                            int mode,
+    1356                 :            :                            size_t length,
+    1357                 :            :                            unsigned char iv[16],
+    1358                 :            :                            const unsigned char *input,
+    1359                 :            :                            unsigned char *output)
+    1360                 :            : {
+    1361                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1362                 :            :     unsigned char c;
+    1363                 :            :     unsigned char ov[17];
+    1364                 :            : 
+    1365   [ #  #  #  # ]:          0 :     if (mode != MBEDTLS_AES_ENCRYPT && mode != MBEDTLS_AES_DECRYPT) {
+    1366                 :          0 :         return MBEDTLS_ERR_AES_BAD_INPUT_DATA;
+    1367                 :            :     }
+    1368         [ #  # ]:          0 :     while (length--) {
+    1369                 :          0 :         memcpy(ov, iv, 16);
+    1370                 :          0 :         ret = mbedtls_aes_crypt_ecb(ctx, MBEDTLS_AES_ENCRYPT, iv, iv);
+    1371         [ #  # ]:          0 :         if (ret != 0) {
+    1372                 :          0 :             goto exit;
+    1373                 :            :         }
+    1374                 :            : 
+    1375         [ #  # ]:          0 :         if (mode == MBEDTLS_AES_DECRYPT) {
+    1376                 :          0 :             ov[16] = *input;
+    1377                 :            :         }
+    1378                 :            : 
+    1379                 :          0 :         c = *output++ = (unsigned char) (iv[0] ^ *input++);
+    1380                 :            : 
+    1381         [ #  # ]:          0 :         if (mode == MBEDTLS_AES_ENCRYPT) {
+    1382                 :          0 :             ov[16] = c;
+    1383                 :            :         }
+    1384                 :            : 
+    1385                 :          0 :         memcpy(iv, ov + 1, 16);
+    1386                 :            :     }
+    1387                 :          0 :     ret = 0;
+    1388                 :            : 
+    1389                 :          0 : exit:
+    1390                 :          0 :     return ret;
+    1391                 :            : }
+    1392                 :            : #endif /* MBEDTLS_CIPHER_MODE_CFB */
+    1393                 :            : 
+    1394                 :            : #if defined(MBEDTLS_CIPHER_MODE_OFB)
+    1395                 :            : /*
+    1396                 :            :  * AES-OFB (Output Feedback Mode) buffer encryption/decryption
+    1397                 :            :  */
+    1398                 :          0 : int mbedtls_aes_crypt_ofb(mbedtls_aes_context *ctx,
+    1399                 :            :                           size_t length,
+    1400                 :            :                           size_t *iv_off,
+    1401                 :            :                           unsigned char iv[16],
+    1402                 :            :                           const unsigned char *input,
+    1403                 :            :                           unsigned char *output)
+    1404                 :            : {
+    1405                 :          0 :     int ret = 0;
+    1406                 :            :     size_t n;
+    1407                 :            : 
+    1408                 :          0 :     n = *iv_off;
+    1409                 :            : 
+    1410         [ #  # ]:          0 :     if (n > 15) {
+    1411                 :          0 :         return MBEDTLS_ERR_AES_BAD_INPUT_DATA;
+    1412                 :            :     }
+    1413                 :            : 
+    1414         [ #  # ]:          0 :     while (length--) {
+    1415         [ #  # ]:          0 :         if (n == 0) {
+    1416                 :          0 :             ret = mbedtls_aes_crypt_ecb(ctx, MBEDTLS_AES_ENCRYPT, iv, iv);
+    1417         [ #  # ]:          0 :             if (ret != 0) {
+    1418                 :          0 :                 goto exit;
+    1419                 :            :             }
+    1420                 :            :         }
+    1421                 :          0 :         *output++ =  *input++ ^ iv[n];
+    1422                 :            : 
+    1423                 :          0 :         n = (n + 1) & 0x0F;
+    1424                 :            :     }
+    1425                 :            : 
+    1426                 :          0 :     *iv_off = n;
+    1427                 :            : 
+    1428                 :          0 : exit:
+    1429                 :          0 :     return ret;
+    1430                 :            : }
+    1431                 :            : #endif /* MBEDTLS_CIPHER_MODE_OFB */
+    1432                 :            : 
+    1433                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR)
+    1434                 :            : /*
+    1435                 :            :  * AES-CTR buffer encryption/decryption
+    1436                 :            :  */
+    1437                 :          0 : int mbedtls_aes_crypt_ctr(mbedtls_aes_context *ctx,
+    1438                 :            :                           size_t length,
+    1439                 :            :                           size_t *nc_off,
+    1440                 :            :                           unsigned char nonce_counter[16],
+    1441                 :            :                           unsigned char stream_block[16],
+    1442                 :            :                           const unsigned char *input,
+    1443                 :            :                           unsigned char *output)
+    1444                 :            : {
+    1445                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1446                 :            : 
+    1447                 :          0 :     size_t offset = *nc_off;
+    1448                 :            : 
+    1449         [ #  # ]:          0 :     if (offset > 0x0F) {
+    1450                 :          0 :         return MBEDTLS_ERR_AES_BAD_INPUT_DATA;
+    1451                 :            :     }
+    1452                 :            : 
+    1453         [ #  # ]:          0 :     for (size_t i = 0; i < length;) {
+    1454                 :          0 :         size_t n = 16;
+    1455         [ #  # ]:          0 :         if (offset == 0) {
+    1456                 :          0 :             ret = mbedtls_aes_crypt_ecb(ctx, MBEDTLS_AES_ENCRYPT, nonce_counter, stream_block);
+    1457         [ #  # ]:          0 :             if (ret != 0) {
+    1458                 :          0 :                 goto exit;
+    1459                 :            :             }
+    1460                 :          0 :             mbedtls_ctr_increment_counter(nonce_counter);
+    1461                 :            :         } else {
+    1462                 :          0 :             n -= offset;
+    1463                 :            :         }
+    1464                 :            : 
+    1465         [ #  # ]:          0 :         if (n > (length - i)) {
+    1466                 :          0 :             n = (length - i);
+    1467                 :            :         }
+    1468                 :          0 :         mbedtls_xor(&output[i], &input[i], &stream_block[offset], n);
+    1469                 :            :         // offset might be non-zero for the last block, but in that case, we don't use it again
+    1470                 :          0 :         offset = 0;
+    1471                 :          0 :         i += n;
+    1472                 :            :     }
+    1473                 :            : 
+    1474                 :            :     // capture offset for future resumption
+    1475                 :          0 :     *nc_off = (*nc_off + length) % 16;
+    1476                 :            : 
+    1477                 :          0 :     ret = 0;
+    1478                 :            : 
+    1479                 :          0 : exit:
+    1480                 :          0 :     return ret;
+    1481                 :            : }
+    1482                 :            : #endif /* MBEDTLS_CIPHER_MODE_CTR */
+    1483                 :            : 
+    1484                 :            : #endif /* !MBEDTLS_AES_ALT */
+    1485                 :            : 
+    1486                 :            : #if defined(MBEDTLS_SELF_TEST)
+    1487                 :            : /*
+    1488                 :            :  * AES test vectors from:
+    1489                 :            :  *
+    1490                 :            :  * http://csrc.nist.gov/archive/aes/rijndael/rijndael-vals.zip
+    1491                 :            :  */
+    1492                 :            : #if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
+    1493                 :            : static const unsigned char aes_test_ecb_dec[][16] =
+    1494                 :            : {
+    1495                 :            :     { 0x44, 0x41, 0x6A, 0xC2, 0xD1, 0xF5, 0x3C, 0x58,
+    1496                 :            :       0x33, 0x03, 0x91, 0x7E, 0x6B, 0xE9, 0xEB, 0xE0 },
+    1497                 :            : #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
+    1498                 :            :     { 0x48, 0xE3, 0x1E, 0x9E, 0x25, 0x67, 0x18, 0xF2,
+    1499                 :            :       0x92, 0x29, 0x31, 0x9C, 0x19, 0xF1, 0x5B, 0xA4 },
+    1500                 :            :     { 0x05, 0x8C, 0xCF, 0xFD, 0xBB, 0xCB, 0x38, 0x2D,
+    1501                 :            :       0x1F, 0x6F, 0x56, 0x58, 0x5D, 0x8A, 0x4A, 0xDE }
+    1502                 :            : #endif
+    1503                 :            : };
+    1504                 :            : #endif
+    1505                 :            : 
+    1506                 :            : static const unsigned char aes_test_ecb_enc[][16] =
+    1507                 :            : {
+    1508                 :            :     { 0xC3, 0x4C, 0x05, 0x2C, 0xC0, 0xDA, 0x8D, 0x73,
+    1509                 :            :       0x45, 0x1A, 0xFE, 0x5F, 0x03, 0xBE, 0x29, 0x7F },
+    1510                 :            : #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
+    1511                 :            :     { 0xF3, 0xF6, 0x75, 0x2A, 0xE8, 0xD7, 0x83, 0x11,
+    1512                 :            :       0x38, 0xF0, 0x41, 0x56, 0x06, 0x31, 0xB1, 0x14 },
+    1513                 :            :     { 0x8B, 0x79, 0xEE, 0xCC, 0x93, 0xA0, 0xEE, 0x5D,
+    1514                 :            :       0xFF, 0x30, 0xB4, 0xEA, 0x21, 0x63, 0x6D, 0xA4 }
+    1515                 :            : #endif
+    1516                 :            : };
+    1517                 :            : 
+    1518                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+    1519                 :            : static const unsigned char aes_test_cbc_dec[][16] =
+    1520                 :            : {
+    1521                 :            :     { 0xFA, 0xCA, 0x37, 0xE0, 0xB0, 0xC8, 0x53, 0x73,
+    1522                 :            :       0xDF, 0x70, 0x6E, 0x73, 0xF7, 0xC9, 0xAF, 0x86 },
+    1523                 :            : #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
+    1524                 :            :     { 0x5D, 0xF6, 0x78, 0xDD, 0x17, 0xBA, 0x4E, 0x75,
+    1525                 :            :       0xB6, 0x17, 0x68, 0xC6, 0xAD, 0xEF, 0x7C, 0x7B },
+    1526                 :            :     { 0x48, 0x04, 0xE1, 0x81, 0x8F, 0xE6, 0x29, 0x75,
+    1527                 :            :       0x19, 0xA3, 0xE8, 0x8C, 0x57, 0x31, 0x04, 0x13 }
+    1528                 :            : #endif
+    1529                 :            : };
+    1530                 :            : 
+    1531                 :            : static const unsigned char aes_test_cbc_enc[][16] =
+    1532                 :            : {
+    1533                 :            :     { 0x8A, 0x05, 0xFC, 0x5E, 0x09, 0x5A, 0xF4, 0x84,
+    1534                 :            :       0x8A, 0x08, 0xD3, 0x28, 0xD3, 0x68, 0x8E, 0x3D },
+    1535                 :            : #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
+    1536                 :            :     { 0x7B, 0xD9, 0x66, 0xD5, 0x3A, 0xD8, 0xC1, 0xBB,
+    1537                 :            :       0x85, 0xD2, 0xAD, 0xFA, 0xE8, 0x7B, 0xB1, 0x04 },
+    1538                 :            :     { 0xFE, 0x3C, 0x53, 0x65, 0x3E, 0x2F, 0x45, 0xB5,
+    1539                 :            :       0x6F, 0xCD, 0x88, 0xB2, 0xCC, 0x89, 0x8F, 0xF0 }
+    1540                 :            : #endif
+    1541                 :            : };
+    1542                 :            : #endif /* MBEDTLS_CIPHER_MODE_CBC */
+    1543                 :            : 
+    1544                 :            : #if defined(MBEDTLS_CIPHER_MODE_CFB)
+    1545                 :            : /*
+    1546                 :            :  * AES-CFB128 test vectors from:
+    1547                 :            :  *
+    1548                 :            :  * http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf
+    1549                 :            :  */
+    1550                 :            : static const unsigned char aes_test_cfb128_key[][32] =
+    1551                 :            : {
+    1552                 :            :     { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6,
+    1553                 :            :       0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C },
+    1554                 :            : #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
+    1555                 :            :     { 0x8E, 0x73, 0xB0, 0xF7, 0xDA, 0x0E, 0x64, 0x52,
+    1556                 :            :       0xC8, 0x10, 0xF3, 0x2B, 0x80, 0x90, 0x79, 0xE5,
+    1557                 :            :       0x62, 0xF8, 0xEA, 0xD2, 0x52, 0x2C, 0x6B, 0x7B },
+    1558                 :            :     { 0x60, 0x3D, 0xEB, 0x10, 0x15, 0xCA, 0x71, 0xBE,
+    1559                 :            :       0x2B, 0x73, 0xAE, 0xF0, 0x85, 0x7D, 0x77, 0x81,
+    1560                 :            :       0x1F, 0x35, 0x2C, 0x07, 0x3B, 0x61, 0x08, 0xD7,
+    1561                 :            :       0x2D, 0x98, 0x10, 0xA3, 0x09, 0x14, 0xDF, 0xF4 }
+    1562                 :            : #endif
+    1563                 :            : };
+    1564                 :            : 
+    1565                 :            : static const unsigned char aes_test_cfb128_iv[16] =
+    1566                 :            : {
+    1567                 :            :     0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+    1568                 :            :     0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
+    1569                 :            : };
+    1570                 :            : 
+    1571                 :            : static const unsigned char aes_test_cfb128_pt[64] =
+    1572                 :            : {
+    1573                 :            :     0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
+    1574                 :            :     0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A,
+    1575                 :            :     0xAE, 0x2D, 0x8A, 0x57, 0x1E, 0x03, 0xAC, 0x9C,
+    1576                 :            :     0x9E, 0xB7, 0x6F, 0xAC, 0x45, 0xAF, 0x8E, 0x51,
+    1577                 :            :     0x30, 0xC8, 0x1C, 0x46, 0xA3, 0x5C, 0xE4, 0x11,
+    1578                 :            :     0xE5, 0xFB, 0xC1, 0x19, 0x1A, 0x0A, 0x52, 0xEF,
+    1579                 :            :     0xF6, 0x9F, 0x24, 0x45, 0xDF, 0x4F, 0x9B, 0x17,
+    1580                 :            :     0xAD, 0x2B, 0x41, 0x7B, 0xE6, 0x6C, 0x37, 0x10
+    1581                 :            : };
+    1582                 :            : 
+    1583                 :            : static const unsigned char aes_test_cfb128_ct[][64] =
+    1584                 :            : {
+    1585                 :            :     { 0x3B, 0x3F, 0xD9, 0x2E, 0xB7, 0x2D, 0xAD, 0x20,
+    1586                 :            :       0x33, 0x34, 0x49, 0xF8, 0xE8, 0x3C, 0xFB, 0x4A,
+    1587                 :            :       0xC8, 0xA6, 0x45, 0x37, 0xA0, 0xB3, 0xA9, 0x3F,
+    1588                 :            :       0xCD, 0xE3, 0xCD, 0xAD, 0x9F, 0x1C, 0xE5, 0x8B,
+    1589                 :            :       0x26, 0x75, 0x1F, 0x67, 0xA3, 0xCB, 0xB1, 0x40,
+    1590                 :            :       0xB1, 0x80, 0x8C, 0xF1, 0x87, 0xA4, 0xF4, 0xDF,
+    1591                 :            :       0xC0, 0x4B, 0x05, 0x35, 0x7C, 0x5D, 0x1C, 0x0E,
+    1592                 :            :       0xEA, 0xC4, 0xC6, 0x6F, 0x9F, 0xF7, 0xF2, 0xE6 },
+    1593                 :            : #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
+    1594                 :            :     { 0xCD, 0xC8, 0x0D, 0x6F, 0xDD, 0xF1, 0x8C, 0xAB,
+    1595                 :            :       0x34, 0xC2, 0x59, 0x09, 0xC9, 0x9A, 0x41, 0x74,
+    1596                 :            :       0x67, 0xCE, 0x7F, 0x7F, 0x81, 0x17, 0x36, 0x21,
+    1597                 :            :       0x96, 0x1A, 0x2B, 0x70, 0x17, 0x1D, 0x3D, 0x7A,
+    1598                 :            :       0x2E, 0x1E, 0x8A, 0x1D, 0xD5, 0x9B, 0x88, 0xB1,
+    1599                 :            :       0xC8, 0xE6, 0x0F, 0xED, 0x1E, 0xFA, 0xC4, 0xC9,
+    1600                 :            :       0xC0, 0x5F, 0x9F, 0x9C, 0xA9, 0x83, 0x4F, 0xA0,
+    1601                 :            :       0x42, 0xAE, 0x8F, 0xBA, 0x58, 0x4B, 0x09, 0xFF },
+    1602                 :            :     { 0xDC, 0x7E, 0x84, 0xBF, 0xDA, 0x79, 0x16, 0x4B,
+    1603                 :            :       0x7E, 0xCD, 0x84, 0x86, 0x98, 0x5D, 0x38, 0x60,
+    1604                 :            :       0x39, 0xFF, 0xED, 0x14, 0x3B, 0x28, 0xB1, 0xC8,
+    1605                 :            :       0x32, 0x11, 0x3C, 0x63, 0x31, 0xE5, 0x40, 0x7B,
+    1606                 :            :       0xDF, 0x10, 0x13, 0x24, 0x15, 0xE5, 0x4B, 0x92,
+    1607                 :            :       0xA1, 0x3E, 0xD0, 0xA8, 0x26, 0x7A, 0xE2, 0xF9,
+    1608                 :            :       0x75, 0xA3, 0x85, 0x74, 0x1A, 0xB9, 0xCE, 0xF8,
+    1609                 :            :       0x20, 0x31, 0x62, 0x3D, 0x55, 0xB1, 0xE4, 0x71 }
+    1610                 :            : #endif
+    1611                 :            : };
+    1612                 :            : #endif /* MBEDTLS_CIPHER_MODE_CFB */
+    1613                 :            : 
+    1614                 :            : #if defined(MBEDTLS_CIPHER_MODE_OFB)
+    1615                 :            : /*
+    1616                 :            :  * AES-OFB test vectors from:
+    1617                 :            :  *
+    1618                 :            :  * https://csrc.nist.gov/publications/detail/sp/800-38a/final
+    1619                 :            :  */
+    1620                 :            : static const unsigned char aes_test_ofb_key[][32] =
+    1621                 :            : {
+    1622                 :            :     { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6,
+    1623                 :            :       0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C },
+    1624                 :            : #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
+    1625                 :            :     { 0x8E, 0x73, 0xB0, 0xF7, 0xDA, 0x0E, 0x64, 0x52,
+    1626                 :            :       0xC8, 0x10, 0xF3, 0x2B, 0x80, 0x90, 0x79, 0xE5,
+    1627                 :            :       0x62, 0xF8, 0xEA, 0xD2, 0x52, 0x2C, 0x6B, 0x7B },
+    1628                 :            :     { 0x60, 0x3D, 0xEB, 0x10, 0x15, 0xCA, 0x71, 0xBE,
+    1629                 :            :       0x2B, 0x73, 0xAE, 0xF0, 0x85, 0x7D, 0x77, 0x81,
+    1630                 :            :       0x1F, 0x35, 0x2C, 0x07, 0x3B, 0x61, 0x08, 0xD7,
+    1631                 :            :       0x2D, 0x98, 0x10, 0xA3, 0x09, 0x14, 0xDF, 0xF4 }
+    1632                 :            : #endif
+    1633                 :            : };
+    1634                 :            : 
+    1635                 :            : static const unsigned char aes_test_ofb_iv[16] =
+    1636                 :            : {
+    1637                 :            :     0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+    1638                 :            :     0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
+    1639                 :            : };
+    1640                 :            : 
+    1641                 :            : static const unsigned char aes_test_ofb_pt[64] =
+    1642                 :            : {
+    1643                 :            :     0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
+    1644                 :            :     0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A,
+    1645                 :            :     0xAE, 0x2D, 0x8A, 0x57, 0x1E, 0x03, 0xAC, 0x9C,
+    1646                 :            :     0x9E, 0xB7, 0x6F, 0xAC, 0x45, 0xAF, 0x8E, 0x51,
+    1647                 :            :     0x30, 0xC8, 0x1C, 0x46, 0xA3, 0x5C, 0xE4, 0x11,
+    1648                 :            :     0xE5, 0xFB, 0xC1, 0x19, 0x1A, 0x0A, 0x52, 0xEF,
+    1649                 :            :     0xF6, 0x9F, 0x24, 0x45, 0xDF, 0x4F, 0x9B, 0x17,
+    1650                 :            :     0xAD, 0x2B, 0x41, 0x7B, 0xE6, 0x6C, 0x37, 0x10
+    1651                 :            : };
+    1652                 :            : 
+    1653                 :            : static const unsigned char aes_test_ofb_ct[][64] =
+    1654                 :            : {
+    1655                 :            :     { 0x3B, 0x3F, 0xD9, 0x2E, 0xB7, 0x2D, 0xAD, 0x20,
+    1656                 :            :       0x33, 0x34, 0x49, 0xF8, 0xE8, 0x3C, 0xFB, 0x4A,
+    1657                 :            :       0x77, 0x89, 0x50, 0x8d, 0x16, 0x91, 0x8f, 0x03,
+    1658                 :            :       0xf5, 0x3c, 0x52, 0xda, 0xc5, 0x4e, 0xd8, 0x25,
+    1659                 :            :       0x97, 0x40, 0x05, 0x1e, 0x9c, 0x5f, 0xec, 0xf6,
+    1660                 :            :       0x43, 0x44, 0xf7, 0xa8, 0x22, 0x60, 0xed, 0xcc,
+    1661                 :            :       0x30, 0x4c, 0x65, 0x28, 0xf6, 0x59, 0xc7, 0x78,
+    1662                 :            :       0x66, 0xa5, 0x10, 0xd9, 0xc1, 0xd6, 0xae, 0x5e },
+    1663                 :            : #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
+    1664                 :            :     { 0xCD, 0xC8, 0x0D, 0x6F, 0xDD, 0xF1, 0x8C, 0xAB,
+    1665                 :            :       0x34, 0xC2, 0x59, 0x09, 0xC9, 0x9A, 0x41, 0x74,
+    1666                 :            :       0xfc, 0xc2, 0x8b, 0x8d, 0x4c, 0x63, 0x83, 0x7c,
+    1667                 :            :       0x09, 0xe8, 0x17, 0x00, 0xc1, 0x10, 0x04, 0x01,
+    1668                 :            :       0x8d, 0x9a, 0x9a, 0xea, 0xc0, 0xf6, 0x59, 0x6f,
+    1669                 :            :       0x55, 0x9c, 0x6d, 0x4d, 0xaf, 0x59, 0xa5, 0xf2,
+    1670                 :            :       0x6d, 0x9f, 0x20, 0x08, 0x57, 0xca, 0x6c, 0x3e,
+    1671                 :            :       0x9c, 0xac, 0x52, 0x4b, 0xd9, 0xac, 0xc9, 0x2a },
+    1672                 :            :     { 0xDC, 0x7E, 0x84, 0xBF, 0xDA, 0x79, 0x16, 0x4B,
+    1673                 :            :       0x7E, 0xCD, 0x84, 0x86, 0x98, 0x5D, 0x38, 0x60,
+    1674                 :            :       0x4f, 0xeb, 0xdc, 0x67, 0x40, 0xd2, 0x0b, 0x3a,
+    1675                 :            :       0xc8, 0x8f, 0x6a, 0xd8, 0x2a, 0x4f, 0xb0, 0x8d,
+    1676                 :            :       0x71, 0xab, 0x47, 0xa0, 0x86, 0xe8, 0x6e, 0xed,
+    1677                 :            :       0xf3, 0x9d, 0x1c, 0x5b, 0xba, 0x97, 0xc4, 0x08,
+    1678                 :            :       0x01, 0x26, 0x14, 0x1d, 0x67, 0xf3, 0x7b, 0xe8,
+    1679                 :            :       0x53, 0x8f, 0x5a, 0x8b, 0xe7, 0x40, 0xe4, 0x84 }
+    1680                 :            : #endif
+    1681                 :            : };
+    1682                 :            : #endif /* MBEDTLS_CIPHER_MODE_OFB */
+    1683                 :            : 
+    1684                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR)
+    1685                 :            : /*
+    1686                 :            :  * AES-CTR test vectors from:
+    1687                 :            :  *
+    1688                 :            :  * http://www.faqs.org/rfcs/rfc3686.html
+    1689                 :            :  */
+    1690                 :            : 
+    1691                 :            : static const unsigned char aes_test_ctr_key[][16] =
+    1692                 :            : {
+    1693                 :            :     { 0xAE, 0x68, 0x52, 0xF8, 0x12, 0x10, 0x67, 0xCC,
+    1694                 :            :       0x4B, 0xF7, 0xA5, 0x76, 0x55, 0x77, 0xF3, 0x9E },
+    1695                 :            :     { 0x7E, 0x24, 0x06, 0x78, 0x17, 0xFA, 0xE0, 0xD7,
+    1696                 :            :       0x43, 0xD6, 0xCE, 0x1F, 0x32, 0x53, 0x91, 0x63 },
+    1697                 :            :     { 0x76, 0x91, 0xBE, 0x03, 0x5E, 0x50, 0x20, 0xA8,
+    1698                 :            :       0xAC, 0x6E, 0x61, 0x85, 0x29, 0xF9, 0xA0, 0xDC }
+    1699                 :            : };
+    1700                 :            : 
+    1701                 :            : static const unsigned char aes_test_ctr_nonce_counter[][16] =
+    1702                 :            : {
+    1703                 :            :     { 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00,
+    1704                 :            :       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 },
+    1705                 :            :     { 0x00, 0x6C, 0xB6, 0xDB, 0xC0, 0x54, 0x3B, 0x59,
+    1706                 :            :       0xDA, 0x48, 0xD9, 0x0B, 0x00, 0x00, 0x00, 0x01 },
+    1707                 :            :     { 0x00, 0xE0, 0x01, 0x7B, 0x27, 0x77, 0x7F, 0x3F,
+    1708                 :            :       0x4A, 0x17, 0x86, 0xF0, 0x00, 0x00, 0x00, 0x01 }
+    1709                 :            : };
+    1710                 :            : 
+    1711                 :            : static const unsigned char aes_test_ctr_pt[][48] =
+    1712                 :            : {
+    1713                 :            :     { 0x53, 0x69, 0x6E, 0x67, 0x6C, 0x65, 0x20, 0x62,
+    1714                 :            :       0x6C, 0x6F, 0x63, 0x6B, 0x20, 0x6D, 0x73, 0x67 },
+    1715                 :            :     { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+    1716                 :            :       0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
+    1717                 :            :       0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+    1718                 :            :       0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F },
+    1719                 :            : 
+    1720                 :            :     { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+    1721                 :            :       0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
+    1722                 :            :       0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+    1723                 :            :       0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
+    1724                 :            :       0x20, 0x21, 0x22, 0x23 }
+    1725                 :            : };
+    1726                 :            : 
+    1727                 :            : static const unsigned char aes_test_ctr_ct[][48] =
+    1728                 :            : {
+    1729                 :            :     { 0xE4, 0x09, 0x5D, 0x4F, 0xB7, 0xA7, 0xB3, 0x79,
+    1730                 :            :       0x2D, 0x61, 0x75, 0xA3, 0x26, 0x13, 0x11, 0xB8 },
+    1731                 :            :     { 0x51, 0x04, 0xA1, 0x06, 0x16, 0x8A, 0x72, 0xD9,
+    1732                 :            :       0x79, 0x0D, 0x41, 0xEE, 0x8E, 0xDA, 0xD3, 0x88,
+    1733                 :            :       0xEB, 0x2E, 0x1E, 0xFC, 0x46, 0xDA, 0x57, 0xC8,
+    1734                 :            :       0xFC, 0xE6, 0x30, 0xDF, 0x91, 0x41, 0xBE, 0x28 },
+    1735                 :            :     { 0xC1, 0xCF, 0x48, 0xA8, 0x9F, 0x2F, 0xFD, 0xD9,
+    1736                 :            :       0xCF, 0x46, 0x52, 0xE9, 0xEF, 0xDB, 0x72, 0xD7,
+    1737                 :            :       0x45, 0x40, 0xA4, 0x2B, 0xDE, 0x6D, 0x78, 0x36,
+    1738                 :            :       0xD5, 0x9A, 0x5C, 0xEA, 0xAE, 0xF3, 0x10, 0x53,
+    1739                 :            :       0x25, 0xB2, 0x07, 0x2F }
+    1740                 :            : };
+    1741                 :            : 
+    1742                 :            : static const int aes_test_ctr_len[3] =
+    1743                 :            : { 16, 32, 36 };
+    1744                 :            : #endif /* MBEDTLS_CIPHER_MODE_CTR */
+    1745                 :            : 
+    1746                 :            : #if defined(MBEDTLS_CIPHER_MODE_XTS)
+    1747                 :            : /*
+    1748                 :            :  * AES-XTS test vectors from:
+    1749                 :            :  *
+    1750                 :            :  * IEEE P1619/D16 Annex B
+    1751                 :            :  * https://web.archive.org/web/20150629024421/http://grouper.ieee.org/groups/1619/email/pdf00086.pdf
+    1752                 :            :  * (Archived from original at http://grouper.ieee.org/groups/1619/email/pdf00086.pdf)
+    1753                 :            :  */
+    1754                 :            : static const unsigned char aes_test_xts_key[][32] =
+    1755                 :            : {
+    1756                 :            :     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    1757                 :            :       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    1758                 :            :       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    1759                 :            :       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+    1760                 :            :     { 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
+    1761                 :            :       0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
+    1762                 :            :       0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
+    1763                 :            :       0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22 },
+    1764                 :            :     { 0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8,
+    1765                 :            :       0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf2, 0xf1, 0xf0,
+    1766                 :            :       0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
+    1767                 :            :       0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22 },
+    1768                 :            : };
+    1769                 :            : 
+    1770                 :            : static const unsigned char aes_test_xts_pt32[][32] =
+    1771                 :            : {
+    1772                 :            :     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    1773                 :            :       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    1774                 :            :       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    1775                 :            :       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+    1776                 :            :     { 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
+    1777                 :            :       0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
+    1778                 :            :       0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
+    1779                 :            :       0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 },
+    1780                 :            :     { 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
+    1781                 :            :       0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
+    1782                 :            :       0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
+    1783                 :            :       0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 },
+    1784                 :            : };
+    1785                 :            : 
+    1786                 :            : static const unsigned char aes_test_xts_ct32[][32] =
+    1787                 :            : {
+    1788                 :            :     { 0x91, 0x7c, 0xf6, 0x9e, 0xbd, 0x68, 0xb2, 0xec,
+    1789                 :            :       0x9b, 0x9f, 0xe9, 0xa3, 0xea, 0xdd, 0xa6, 0x92,
+    1790                 :            :       0xcd, 0x43, 0xd2, 0xf5, 0x95, 0x98, 0xed, 0x85,
+    1791                 :            :       0x8c, 0x02, 0xc2, 0x65, 0x2f, 0xbf, 0x92, 0x2e },
+    1792                 :            :     { 0xc4, 0x54, 0x18, 0x5e, 0x6a, 0x16, 0x93, 0x6e,
+    1793                 :            :       0x39, 0x33, 0x40, 0x38, 0xac, 0xef, 0x83, 0x8b,
+    1794                 :            :       0xfb, 0x18, 0x6f, 0xff, 0x74, 0x80, 0xad, 0xc4,
+    1795                 :            :       0x28, 0x93, 0x82, 0xec, 0xd6, 0xd3, 0x94, 0xf0 },
+    1796                 :            :     { 0xaf, 0x85, 0x33, 0x6b, 0x59, 0x7a, 0xfc, 0x1a,
+    1797                 :            :       0x90, 0x0b, 0x2e, 0xb2, 0x1e, 0xc9, 0x49, 0xd2,
+    1798                 :            :       0x92, 0xdf, 0x4c, 0x04, 0x7e, 0x0b, 0x21, 0x53,
+    1799                 :            :       0x21, 0x86, 0xa5, 0x97, 0x1a, 0x22, 0x7a, 0x89 },
+    1800                 :            : };
+    1801                 :            : 
+    1802                 :            : static const unsigned char aes_test_xts_data_unit[][16] =
+    1803                 :            : {
+    1804                 :            :     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    1805                 :            :       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+    1806                 :            :     { 0x33, 0x33, 0x33, 0x33, 0x33, 0x00, 0x00, 0x00,
+    1807                 :            :       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+    1808                 :            :     { 0x33, 0x33, 0x33, 0x33, 0x33, 0x00, 0x00, 0x00,
+    1809                 :            :       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+    1810                 :            : };
+    1811                 :            : 
+    1812                 :            : #endif /* MBEDTLS_CIPHER_MODE_XTS */
+    1813                 :            : 
+    1814                 :            : /*
+    1815                 :            :  * Checkup routine
+    1816                 :            :  */
+    1817                 :          0 : int mbedtls_aes_self_test(int verbose)
+    1818                 :            : {
+    1819                 :          0 :     int ret = 0, i, j, u, mode;
+    1820                 :            :     unsigned int keybits;
+    1821                 :            :     unsigned char key[32];
+    1822                 :            :     unsigned char buf[64];
+    1823                 :            :     const unsigned char *aes_tests;
+    1824                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC) || defined(MBEDTLS_CIPHER_MODE_CFB) || \
+    1825                 :            :     defined(MBEDTLS_CIPHER_MODE_OFB)
+    1826                 :            :     unsigned char iv[16];
+    1827                 :            : #endif
+    1828                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+    1829                 :            :     unsigned char prv[16];
+    1830                 :            : #endif
+    1831                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR) || defined(MBEDTLS_CIPHER_MODE_CFB) || \
+    1832                 :            :     defined(MBEDTLS_CIPHER_MODE_OFB)
+    1833                 :            :     size_t offset;
+    1834                 :            : #endif
+    1835                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR) || defined(MBEDTLS_CIPHER_MODE_XTS)
+    1836                 :            :     int len;
+    1837                 :            : #endif
+    1838                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR)
+    1839                 :            :     unsigned char nonce_counter[16];
+    1840                 :            :     unsigned char stream_block[16];
+    1841                 :            : #endif
+    1842                 :            :     mbedtls_aes_context ctx;
+    1843                 :            : 
+    1844                 :          0 :     memset(key, 0, 32);
+    1845                 :          0 :     mbedtls_aes_init(&ctx);
+    1846                 :            : 
+    1847         [ #  # ]:          0 :     if (verbose != 0) {
+    1848                 :            : #if defined(MBEDTLS_AES_ALT)
+    1849                 :            :         mbedtls_printf("  AES note: alternative implementation.\n");
+    1850                 :            : #else /* MBEDTLS_AES_ALT */
+    1851                 :            : #if defined(MBEDTLS_AESNI_HAVE_CODE)
+    1852                 :            : #if MBEDTLS_AESNI_HAVE_CODE == 1
+    1853                 :          0 :         mbedtls_printf("  AES note: AESNI code present (assembly implementation).\n");
+    1854                 :            : #elif MBEDTLS_AESNI_HAVE_CODE == 2
+    1855                 :            :         mbedtls_printf("  AES note: AESNI code present (intrinsics implementation).\n");
+    1856                 :            : #else
+    1857                 :            : #error "Unrecognised value for MBEDTLS_AESNI_HAVE_CODE"
+    1858                 :            : #endif
+    1859         [ #  # ]:          0 :         if (mbedtls_aesni_has_support(MBEDTLS_AESNI_AES)) {
+    1860                 :          0 :             mbedtls_printf("  AES note: using AESNI.\n");
+    1861                 :            :         } else
+    1862                 :            : #endif
+    1863                 :            : #if defined(MBEDTLS_VIA_PADLOCK_HAVE_CODE)
+    1864                 :            :         if (mbedtls_padlock_has_support(MBEDTLS_PADLOCK_ACE)) {
+    1865                 :            :             mbedtls_printf("  AES note: using VIA Padlock.\n");
+    1866                 :            :         } else
+    1867                 :            : #endif
+    1868                 :            : #if defined(MBEDTLS_AESCE_HAVE_CODE)
+    1869                 :            :         if (MBEDTLS_AESCE_HAS_SUPPORT()) {
+    1870                 :            :             mbedtls_printf("  AES note: using AESCE.\n");
+    1871                 :            :         } else
+    1872                 :            : #endif
+    1873                 :            :         {
+    1874                 :            : #if !defined(MBEDTLS_AES_USE_HARDWARE_ONLY)
+    1875                 :          0 :             mbedtls_printf("  AES note: built-in implementation.\n");
+    1876                 :            : #endif
+    1877                 :            :         }
+    1878                 :            : #endif /* MBEDTLS_AES_ALT */
+    1879                 :            :     }
+    1880                 :            : 
+    1881                 :            :     /*
+    1882                 :            :      * ECB mode
+    1883                 :            :      */
+    1884                 :            :     {
+    1885                 :            :         static const int num_tests =
+    1886                 :            :             sizeof(aes_test_ecb_enc) / sizeof(*aes_test_ecb_enc);
+    1887                 :            : 
+    1888         [ #  # ]:          0 :         for (i = 0; i < num_tests << 1; i++) {
+    1889                 :          0 :             u = i >> 1;
+    1890                 :          0 :             keybits = 128 + u * 64;
+    1891                 :          0 :             mode = i & 1;
+    1892                 :            : 
+    1893         [ #  # ]:          0 :             if (verbose != 0) {
+    1894         [ #  # ]:          0 :                 mbedtls_printf("  AES-ECB-%3u (%s): ", keybits,
+    1895                 :            :                                (mode == MBEDTLS_AES_DECRYPT) ? "dec" : "enc");
+    1896                 :            :             }
+    1897                 :            : #if defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
+    1898                 :            :             if (mode == MBEDTLS_AES_DECRYPT) {
+    1899                 :            :                 if (verbose != 0) {
+    1900                 :            :                     mbedtls_printf("skipped\n");
+    1901                 :            :                 }
+    1902                 :            :                 continue;
+    1903                 :            :             }
+    1904                 :            : #endif
+    1905                 :            : 
+    1906                 :          0 :             memset(buf, 0, 16);
+    1907                 :            : 
+    1908                 :            : #if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
+    1909         [ #  # ]:          0 :             if (mode == MBEDTLS_AES_DECRYPT) {
+    1910                 :          0 :                 ret = mbedtls_aes_setkey_dec(&ctx, key, keybits);
+    1911                 :          0 :                 aes_tests = aes_test_ecb_dec[u];
+    1912                 :            :             } else
+    1913                 :            : #endif
+    1914                 :            :             {
+    1915                 :          0 :                 ret = mbedtls_aes_setkey_enc(&ctx, key, keybits);
+    1916                 :          0 :                 aes_tests = aes_test_ecb_enc[u];
+    1917                 :            :             }
+    1918                 :            : 
+    1919                 :            :             /*
+    1920                 :            :              * AES-192 is an optional feature that may be unavailable when
+    1921                 :            :              * there is an alternative underlying implementation i.e. when
+    1922                 :            :              * MBEDTLS_AES_ALT is defined.
+    1923                 :            :              */
+    1924   [ #  #  #  # ]:          0 :             if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED && keybits == 192) {
+    1925                 :          0 :                 mbedtls_printf("skipped\n");
+    1926                 :          0 :                 continue;
+    1927         [ #  # ]:          0 :             } else if (ret != 0) {
+    1928                 :          0 :                 goto exit;
+    1929                 :            :             }
+    1930                 :            : 
+    1931         [ #  # ]:          0 :             for (j = 0; j < 10000; j++) {
+    1932                 :          0 :                 ret = mbedtls_aes_crypt_ecb(&ctx, mode, buf, buf);
+    1933         [ #  # ]:          0 :                 if (ret != 0) {
+    1934                 :          0 :                     goto exit;
+    1935                 :            :                 }
+    1936                 :            :             }
+    1937                 :            : 
+    1938         [ #  # ]:          0 :             if (memcmp(buf, aes_tests, 16) != 0) {
+    1939                 :          0 :                 ret = 1;
+    1940                 :          0 :                 goto exit;
+    1941                 :            :             }
+    1942                 :            : 
+    1943         [ #  # ]:          0 :             if (verbose != 0) {
+    1944                 :          0 :                 mbedtls_printf("passed\n");
+    1945                 :            :             }
+    1946                 :            :         }
+    1947                 :            : 
+    1948         [ #  # ]:          0 :         if (verbose != 0) {
+    1949                 :          0 :             mbedtls_printf("\n");
+    1950                 :            :         }
+    1951                 :            :     }
+    1952                 :            : 
+    1953                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+    1954                 :            :     /*
+    1955                 :            :      * CBC mode
+    1956                 :            :      */
+    1957                 :            :     {
+    1958                 :            :         static const int num_tests =
+    1959                 :            :             sizeof(aes_test_cbc_dec) / sizeof(*aes_test_cbc_dec);
+    1960                 :            : 
+    1961         [ #  # ]:          0 :         for (i = 0; i < num_tests << 1; i++) {
+    1962                 :          0 :             u = i >> 1;
+    1963                 :          0 :             keybits = 128 + u * 64;
+    1964                 :          0 :             mode = i & 1;
+    1965                 :            : 
+    1966         [ #  # ]:          0 :             if (verbose != 0) {
+    1967         [ #  # ]:          0 :                 mbedtls_printf("  AES-CBC-%3u (%s): ", keybits,
+    1968                 :            :                                (mode == MBEDTLS_AES_DECRYPT) ? "dec" : "enc");
+    1969                 :            :             }
+    1970                 :            : 
+    1971                 :          0 :             memset(iv, 0, 16);
+    1972                 :          0 :             memset(prv, 0, 16);
+    1973                 :          0 :             memset(buf, 0, 16);
+    1974                 :            : 
+    1975         [ #  # ]:          0 :             if (mode == MBEDTLS_AES_DECRYPT) {
+    1976                 :          0 :                 ret = mbedtls_aes_setkey_dec(&ctx, key, keybits);
+    1977                 :          0 :                 aes_tests = aes_test_cbc_dec[u];
+    1978                 :            :             } else {
+    1979                 :          0 :                 ret = mbedtls_aes_setkey_enc(&ctx, key, keybits);
+    1980                 :          0 :                 aes_tests = aes_test_cbc_enc[u];
+    1981                 :            :             }
+    1982                 :            : 
+    1983                 :            :             /*
+    1984                 :            :              * AES-192 is an optional feature that may be unavailable when
+    1985                 :            :              * there is an alternative underlying implementation i.e. when
+    1986                 :            :              * MBEDTLS_AES_ALT is defined.
+    1987                 :            :              */
+    1988   [ #  #  #  # ]:          0 :             if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED && keybits == 192) {
+    1989                 :          0 :                 mbedtls_printf("skipped\n");
+    1990                 :          0 :                 continue;
+    1991         [ #  # ]:          0 :             } else if (ret != 0) {
+    1992                 :          0 :                 goto exit;
+    1993                 :            :             }
+    1994                 :            : 
+    1995         [ #  # ]:          0 :             for (j = 0; j < 10000; j++) {
+    1996         [ #  # ]:          0 :                 if (mode == MBEDTLS_AES_ENCRYPT) {
+    1997                 :            :                     unsigned char tmp[16];
+    1998                 :            : 
+    1999                 :          0 :                     memcpy(tmp, prv, 16);
+    2000                 :          0 :                     memcpy(prv, buf, 16);
+    2001                 :          0 :                     memcpy(buf, tmp, 16);
+    2002                 :            :                 }
+    2003                 :            : 
+    2004                 :          0 :                 ret = mbedtls_aes_crypt_cbc(&ctx, mode, 16, iv, buf, buf);
+    2005         [ #  # ]:          0 :                 if (ret != 0) {
+    2006                 :          0 :                     goto exit;
+    2007                 :            :                 }
+    2008                 :            : 
+    2009                 :            :             }
+    2010                 :            : 
+    2011         [ #  # ]:          0 :             if (memcmp(buf, aes_tests, 16) != 0) {
+    2012                 :          0 :                 ret = 1;
+    2013                 :          0 :                 goto exit;
+    2014                 :            :             }
+    2015                 :            : 
+    2016         [ #  # ]:          0 :             if (verbose != 0) {
+    2017                 :          0 :                 mbedtls_printf("passed\n");
+    2018                 :            :             }
+    2019                 :            :         }
+    2020                 :            : 
+    2021         [ #  # ]:          0 :         if (verbose != 0) {
+    2022                 :          0 :             mbedtls_printf("\n");
+    2023                 :            :         }
+    2024                 :            :     }
+    2025                 :            : #endif /* MBEDTLS_CIPHER_MODE_CBC */
+    2026                 :            : 
+    2027                 :            : #if defined(MBEDTLS_CIPHER_MODE_CFB)
+    2028                 :            :     /*
+    2029                 :            :      * CFB128 mode
+    2030                 :            :      */
+    2031                 :            :     {
+    2032                 :            :         static const int num_tests =
+    2033                 :            :             sizeof(aes_test_cfb128_key) / sizeof(*aes_test_cfb128_key);
+    2034                 :            : 
+    2035         [ #  # ]:          0 :         for (i = 0; i < num_tests << 1; i++) {
+    2036                 :          0 :             u = i >> 1;
+    2037                 :          0 :             keybits = 128 + u * 64;
+    2038                 :          0 :             mode = i & 1;
+    2039                 :            : 
+    2040         [ #  # ]:          0 :             if (verbose != 0) {
+    2041         [ #  # ]:          0 :                 mbedtls_printf("  AES-CFB128-%3u (%s): ", keybits,
+    2042                 :            :                                (mode == MBEDTLS_AES_DECRYPT) ? "dec" : "enc");
+    2043                 :            :             }
+    2044                 :            : 
+    2045                 :          0 :             memcpy(iv,  aes_test_cfb128_iv, 16);
+    2046                 :          0 :             memcpy(key, aes_test_cfb128_key[u], keybits / 8);
+    2047                 :            : 
+    2048                 :          0 :             offset = 0;
+    2049                 :          0 :             ret = mbedtls_aes_setkey_enc(&ctx, key, keybits);
+    2050                 :            :             /*
+    2051                 :            :              * AES-192 is an optional feature that may be unavailable when
+    2052                 :            :              * there is an alternative underlying implementation i.e. when
+    2053                 :            :              * MBEDTLS_AES_ALT is defined.
+    2054                 :            :              */
+    2055   [ #  #  #  # ]:          0 :             if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED && keybits == 192) {
+    2056                 :          0 :                 mbedtls_printf("skipped\n");
+    2057                 :          0 :                 continue;
+    2058         [ #  # ]:          0 :             } else if (ret != 0) {
+    2059                 :          0 :                 goto exit;
+    2060                 :            :             }
+    2061                 :            : 
+    2062         [ #  # ]:          0 :             if (mode == MBEDTLS_AES_DECRYPT) {
+    2063                 :          0 :                 memcpy(buf, aes_test_cfb128_ct[u], 64);
+    2064                 :          0 :                 aes_tests = aes_test_cfb128_pt;
+    2065                 :            :             } else {
+    2066                 :          0 :                 memcpy(buf, aes_test_cfb128_pt, 64);
+    2067                 :          0 :                 aes_tests = aes_test_cfb128_ct[u];
+    2068                 :            :             }
+    2069                 :            : 
+    2070                 :          0 :             ret = mbedtls_aes_crypt_cfb128(&ctx, mode, 64, &offset, iv, buf, buf);
+    2071         [ #  # ]:          0 :             if (ret != 0) {
+    2072                 :          0 :                 goto exit;
+    2073                 :            :             }
+    2074                 :            : 
+    2075         [ #  # ]:          0 :             if (memcmp(buf, aes_tests, 64) != 0) {
+    2076                 :          0 :                 ret = 1;
+    2077                 :          0 :                 goto exit;
+    2078                 :            :             }
+    2079                 :            : 
+    2080         [ #  # ]:          0 :             if (verbose != 0) {
+    2081                 :          0 :                 mbedtls_printf("passed\n");
+    2082                 :            :             }
+    2083                 :            :         }
+    2084                 :            : 
+    2085         [ #  # ]:          0 :         if (verbose != 0) {
+    2086                 :          0 :             mbedtls_printf("\n");
+    2087                 :            :         }
+    2088                 :            :     }
+    2089                 :            : #endif /* MBEDTLS_CIPHER_MODE_CFB */
+    2090                 :            : 
+    2091                 :            : #if defined(MBEDTLS_CIPHER_MODE_OFB)
+    2092                 :            :     /*
+    2093                 :            :      * OFB mode
+    2094                 :            :      */
+    2095                 :            :     {
+    2096                 :            :         static const int num_tests =
+    2097                 :            :             sizeof(aes_test_ofb_key) / sizeof(*aes_test_ofb_key);
+    2098                 :            : 
+    2099         [ #  # ]:          0 :         for (i = 0; i < num_tests << 1; i++) {
+    2100                 :          0 :             u = i >> 1;
+    2101                 :          0 :             keybits = 128 + u * 64;
+    2102                 :          0 :             mode = i & 1;
+    2103                 :            : 
+    2104         [ #  # ]:          0 :             if (verbose != 0) {
+    2105         [ #  # ]:          0 :                 mbedtls_printf("  AES-OFB-%3u (%s): ", keybits,
+    2106                 :            :                                (mode == MBEDTLS_AES_DECRYPT) ? "dec" : "enc");
+    2107                 :            :             }
+    2108                 :            : 
+    2109                 :          0 :             memcpy(iv,  aes_test_ofb_iv, 16);
+    2110                 :          0 :             memcpy(key, aes_test_ofb_key[u], keybits / 8);
+    2111                 :            : 
+    2112                 :          0 :             offset = 0;
+    2113                 :          0 :             ret = mbedtls_aes_setkey_enc(&ctx, key, keybits);
+    2114                 :            :             /*
+    2115                 :            :              * AES-192 is an optional feature that may be unavailable when
+    2116                 :            :              * there is an alternative underlying implementation i.e. when
+    2117                 :            :              * MBEDTLS_AES_ALT is defined.
+    2118                 :            :              */
+    2119   [ #  #  #  # ]:          0 :             if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED && keybits == 192) {
+    2120                 :          0 :                 mbedtls_printf("skipped\n");
+    2121                 :          0 :                 continue;
+    2122         [ #  # ]:          0 :             } else if (ret != 0) {
+    2123                 :          0 :                 goto exit;
+    2124                 :            :             }
+    2125                 :            : 
+    2126         [ #  # ]:          0 :             if (mode == MBEDTLS_AES_DECRYPT) {
+    2127                 :          0 :                 memcpy(buf, aes_test_ofb_ct[u], 64);
+    2128                 :          0 :                 aes_tests = aes_test_ofb_pt;
+    2129                 :            :             } else {
+    2130                 :          0 :                 memcpy(buf, aes_test_ofb_pt, 64);
+    2131                 :          0 :                 aes_tests = aes_test_ofb_ct[u];
+    2132                 :            :             }
+    2133                 :            : 
+    2134                 :          0 :             ret = mbedtls_aes_crypt_ofb(&ctx, 64, &offset, iv, buf, buf);
+    2135         [ #  # ]:          0 :             if (ret != 0) {
+    2136                 :          0 :                 goto exit;
+    2137                 :            :             }
+    2138                 :            : 
+    2139         [ #  # ]:          0 :             if (memcmp(buf, aes_tests, 64) != 0) {
+    2140                 :          0 :                 ret = 1;
+    2141                 :          0 :                 goto exit;
+    2142                 :            :             }
+    2143                 :            : 
+    2144         [ #  # ]:          0 :             if (verbose != 0) {
+    2145                 :          0 :                 mbedtls_printf("passed\n");
+    2146                 :            :             }
+    2147                 :            :         }
+    2148                 :            : 
+    2149         [ #  # ]:          0 :         if (verbose != 0) {
+    2150                 :          0 :             mbedtls_printf("\n");
+    2151                 :            :         }
+    2152                 :            :     }
+    2153                 :            : #endif /* MBEDTLS_CIPHER_MODE_OFB */
+    2154                 :            : 
+    2155                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR)
+    2156                 :            :     /*
+    2157                 :            :      * CTR mode
+    2158                 :            :      */
+    2159                 :            :     {
+    2160                 :            :         static const int num_tests =
+    2161                 :            :             sizeof(aes_test_ctr_key) / sizeof(*aes_test_ctr_key);
+    2162                 :            : 
+    2163         [ #  # ]:          0 :         for (i = 0; i < num_tests << 1; i++) {
+    2164                 :          0 :             u = i >> 1;
+    2165                 :          0 :             mode = i & 1;
+    2166                 :            : 
+    2167         [ #  # ]:          0 :             if (verbose != 0) {
+    2168         [ #  # ]:          0 :                 mbedtls_printf("  AES-CTR-128 (%s): ",
+    2169                 :            :                                (mode == MBEDTLS_AES_DECRYPT) ? "dec" : "enc");
+    2170                 :            :             }
+    2171                 :            : 
+    2172                 :          0 :             memcpy(nonce_counter, aes_test_ctr_nonce_counter[u], 16);
+    2173                 :          0 :             memcpy(key, aes_test_ctr_key[u], 16);
+    2174                 :            : 
+    2175                 :          0 :             offset = 0;
+    2176         [ #  # ]:          0 :             if ((ret = mbedtls_aes_setkey_enc(&ctx, key, 128)) != 0) {
+    2177                 :          0 :                 goto exit;
+    2178                 :            :             }
+    2179                 :            : 
+    2180                 :          0 :             len = aes_test_ctr_len[u];
+    2181                 :            : 
+    2182         [ #  # ]:          0 :             if (mode == MBEDTLS_AES_DECRYPT) {
+    2183                 :          0 :                 memcpy(buf, aes_test_ctr_ct[u], len);
+    2184                 :          0 :                 aes_tests = aes_test_ctr_pt[u];
+    2185                 :            :             } else {
+    2186                 :          0 :                 memcpy(buf, aes_test_ctr_pt[u], len);
+    2187                 :          0 :                 aes_tests = aes_test_ctr_ct[u];
+    2188                 :            :             }
+    2189                 :            : 
+    2190                 :          0 :             ret = mbedtls_aes_crypt_ctr(&ctx, len, &offset, nonce_counter,
+    2191                 :            :                                         stream_block, buf, buf);
+    2192         [ #  # ]:          0 :             if (ret != 0) {
+    2193                 :          0 :                 goto exit;
+    2194                 :            :             }
+    2195                 :            : 
+    2196         [ #  # ]:          0 :             if (memcmp(buf, aes_tests, len) != 0) {
+    2197                 :          0 :                 ret = 1;
+    2198                 :          0 :                 goto exit;
+    2199                 :            :             }
+    2200                 :            : 
+    2201         [ #  # ]:          0 :             if (verbose != 0) {
+    2202                 :          0 :                 mbedtls_printf("passed\n");
+    2203                 :            :             }
+    2204                 :            :         }
+    2205                 :            :     }
+    2206                 :            : 
+    2207         [ #  # ]:          0 :     if (verbose != 0) {
+    2208                 :          0 :         mbedtls_printf("\n");
+    2209                 :            :     }
+    2210                 :            : #endif /* MBEDTLS_CIPHER_MODE_CTR */
+    2211                 :            : 
+    2212                 :            : #if defined(MBEDTLS_CIPHER_MODE_XTS)
+    2213                 :            :     /*
+    2214                 :            :      * XTS mode
+    2215                 :            :      */
+    2216                 :            :     {
+    2217                 :            :         static const int num_tests =
+    2218                 :            :             sizeof(aes_test_xts_key) / sizeof(*aes_test_xts_key);
+    2219                 :            :         mbedtls_aes_xts_context ctx_xts;
+    2220                 :            : 
+    2221                 :            :         mbedtls_aes_xts_init(&ctx_xts);
+    2222                 :            : 
+    2223                 :            :         for (i = 0; i < num_tests << 1; i++) {
+    2224                 :            :             const unsigned char *data_unit;
+    2225                 :            :             u = i >> 1;
+    2226                 :            :             mode = i & 1;
+    2227                 :            : 
+    2228                 :            :             if (verbose != 0) {
+    2229                 :            :                 mbedtls_printf("  AES-XTS-128 (%s): ",
+    2230                 :            :                                (mode == MBEDTLS_AES_DECRYPT) ? "dec" : "enc");
+    2231                 :            :             }
+    2232                 :            : 
+    2233                 :            :             memset(key, 0, sizeof(key));
+    2234                 :            :             memcpy(key, aes_test_xts_key[u], 32);
+    2235                 :            :             data_unit = aes_test_xts_data_unit[u];
+    2236                 :            : 
+    2237                 :            :             len = sizeof(*aes_test_xts_ct32);
+    2238                 :            : 
+    2239                 :            :             if (mode == MBEDTLS_AES_DECRYPT) {
+    2240                 :            :                 ret = mbedtls_aes_xts_setkey_dec(&ctx_xts, key, 256);
+    2241                 :            :                 if (ret != 0) {
+    2242                 :            :                     goto exit;
+    2243                 :            :                 }
+    2244                 :            :                 memcpy(buf, aes_test_xts_ct32[u], len);
+    2245                 :            :                 aes_tests = aes_test_xts_pt32[u];
+    2246                 :            :             } else {
+    2247                 :            :                 ret = mbedtls_aes_xts_setkey_enc(&ctx_xts, key, 256);
+    2248                 :            :                 if (ret != 0) {
+    2249                 :            :                     goto exit;
+    2250                 :            :                 }
+    2251                 :            :                 memcpy(buf, aes_test_xts_pt32[u], len);
+    2252                 :            :                 aes_tests = aes_test_xts_ct32[u];
+    2253                 :            :             }
+    2254                 :            : 
+    2255                 :            : 
+    2256                 :            :             ret = mbedtls_aes_crypt_xts(&ctx_xts, mode, len, data_unit,
+    2257                 :            :                                         buf, buf);
+    2258                 :            :             if (ret != 0) {
+    2259                 :            :                 goto exit;
+    2260                 :            :             }
+    2261                 :            : 
+    2262                 :            :             if (memcmp(buf, aes_tests, len) != 0) {
+    2263                 :            :                 ret = 1;
+    2264                 :            :                 goto exit;
+    2265                 :            :             }
+    2266                 :            : 
+    2267                 :            :             if (verbose != 0) {
+    2268                 :            :                 mbedtls_printf("passed\n");
+    2269                 :            :             }
+    2270                 :            :         }
+    2271                 :            : 
+    2272                 :            :         if (verbose != 0) {
+    2273                 :            :             mbedtls_printf("\n");
+    2274                 :            :         }
+    2275                 :            : 
+    2276                 :            :         mbedtls_aes_xts_free(&ctx_xts);
+    2277                 :            :     }
+    2278                 :            : #endif /* MBEDTLS_CIPHER_MODE_XTS */
+    2279                 :            : 
+    2280                 :          0 :     ret = 0;
+    2281                 :            : 
+    2282                 :          0 : exit:
+    2283   [ #  #  #  # ]:          0 :     if (ret != 0 && verbose != 0) {
+    2284                 :          0 :         mbedtls_printf("failed\n");
+    2285                 :            :     }
+    2286                 :            : 
+    2287                 :          0 :     mbedtls_aes_free(&ctx);
+    2288                 :            : 
+    2289                 :          0 :     return ret;
+    2290                 :            : }
+    2291                 :            : 
+    2292                 :            : #endif /* MBEDTLS_SELF_TEST */
+    2293                 :            : 
+    2294                 :            : #endif /* MBEDTLS_AES_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/aesni.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/aesni.c.func-sort-c.html new file mode 100644 index 00000000000..cfd95bc14a8 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/aesni.c.func-sort-c.html @@ -0,0 +1,113 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/aesni.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - aesni.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:284168.3 %
Date:2024-09-22 08:21:07Functions:6875.0 %
Branches:81266.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
aesni_setkey_enc_1920
mbedtls_aesni_inverse_key0
aesni_setkey_enc_1282
aesni_setkey_enc_256789
mbedtls_aesni_setkey_enc791
mbedtls_aesni_crypt_ecb3654
mbedtls_aesni_gcm_mult3658
mbedtls_aesni_has_support5236
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/aesni.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/aesni.c.func.html new file mode 100644 index 00000000000..5f668071ffa --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/aesni.c.func.html @@ -0,0 +1,113 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/aesni.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - aesni.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:284168.3 %
Date:2024-09-22 08:21:07Functions:6875.0 %
Branches:81266.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
aesni_setkey_enc_1282
aesni_setkey_enc_1920
aesni_setkey_enc_256789
mbedtls_aesni_crypt_ecb3654
mbedtls_aesni_gcm_mult3658
mbedtls_aesni_has_support5236
mbedtls_aesni_inverse_key0
mbedtls_aesni_setkey_enc791
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/aesni.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/aesni.c.gcov.html new file mode 100644 index 00000000000..335295bcf6b --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/aesni.c.gcov.html @@ -0,0 +1,920 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/aesni.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - aesni.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:284168.3 %
Date:2024-09-22 08:21:07Functions:6875.0 %
Branches:81266.7 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  *  AES-NI support functions
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  */
+       7                 :            : 
+       8                 :            : /*
+       9                 :            :  * [AES-WP] https://www.intel.com/content/www/us/en/developer/articles/tool/intel-advanced-encryption-standard-aes-instructions-set.html
+      10                 :            :  * [CLMUL-WP] https://www.intel.com/content/www/us/en/develop/download/intel-carry-less-multiplication-instruction-and-its-usage-for-computing-the-gcm-mode.html
+      11                 :            :  */
+      12                 :            : 
+      13                 :            : #include "common.h"
+      14                 :            : 
+      15                 :            : #if defined(MBEDTLS_AESNI_C)
+      16                 :            : 
+      17                 :            : #include "aesni.h"
+      18                 :            : 
+      19                 :            : #include <string.h>
+      20                 :            : 
+      21                 :            : #if defined(MBEDTLS_AESNI_HAVE_CODE)
+      22                 :            : 
+      23                 :            : #if MBEDTLS_AESNI_HAVE_CODE == 2
+      24                 :            : #if defined(__GNUC__)
+      25                 :            : #include <cpuid.h>
+      26                 :            : #elif defined(_MSC_VER)
+      27                 :            : #include <intrin.h>
+      28                 :            : #else
+      29                 :            : #error "`__cpuid` required by MBEDTLS_AESNI_C is not supported by the compiler"
+      30                 :            : #endif
+      31                 :            : #include <immintrin.h>
+      32                 :            : #endif
+      33                 :            : 
+      34                 :            : #if defined(MBEDTLS_ARCH_IS_X86)
+      35                 :            : #if defined(MBEDTLS_COMPILER_IS_GCC)
+      36                 :            : #pragma GCC push_options
+      37                 :            : #pragma GCC target ("pclmul,sse2,aes")
+      38                 :            : #define MBEDTLS_POP_TARGET_PRAGMA
+      39                 :            : #elif defined(__clang__) && (__clang_major__ >= 5)
+      40                 :            : #pragma clang attribute push (__attribute__((target("pclmul,sse2,aes"))), apply_to=function)
+      41                 :            : #define MBEDTLS_POP_TARGET_PRAGMA
+      42                 :            : #endif
+      43                 :            : #endif
+      44                 :            : 
+      45                 :            : #if !defined(MBEDTLS_AES_USE_HARDWARE_ONLY)
+      46                 :            : /*
+      47                 :            :  * AES-NI support detection routine
+      48                 :            :  */
+      49                 :       5236 : int mbedtls_aesni_has_support(unsigned int what)
+      50                 :            : {
+      51                 :            :     static int done = 0;
+      52                 :            :     static unsigned int c = 0;
+      53                 :            : 
+      54         [ +  + ]:       5236 :     if (!done) {
+      55                 :            : #if MBEDTLS_AESNI_HAVE_CODE == 2
+      56                 :            :         static int info[4] = { 0, 0, 0, 0 };
+      57                 :            : #if defined(_MSC_VER)
+      58                 :            :         __cpuid(info, 1);
+      59                 :            : #else
+      60                 :            :         __cpuid(1, info[0], info[1], info[2], info[3]);
+      61                 :            : #endif
+      62                 :            :         c = info[2];
+      63                 :            : #else /* AESNI using asm */
+      64                 :          2 :         asm ("movl  $1, %%eax   \n\t"
+      65                 :            :              "cpuid             \n\t"
+      66                 :            :              : "=c" (c)
+      67                 :            :              :
+      68                 :            :              : "eax", "ebx", "edx");
+      69                 :            : #endif /* MBEDTLS_AESNI_HAVE_CODE */
+      70                 :          2 :         done = 1;
+      71                 :            :     }
+      72                 :            : 
+      73                 :       5236 :     return (c & what) != 0;
+      74                 :            : }
+      75                 :            : #endif /* !MBEDTLS_AES_USE_HARDWARE_ONLY */
+      76                 :            : 
+      77                 :            : #if MBEDTLS_AESNI_HAVE_CODE == 2
+      78                 :            : 
+      79                 :            : /*
+      80                 :            :  * AES-NI AES-ECB block en(de)cryption
+      81                 :            :  */
+      82                 :            : int mbedtls_aesni_crypt_ecb(mbedtls_aes_context *ctx,
+      83                 :            :                             int mode,
+      84                 :            :                             const unsigned char input[16],
+      85                 :            :                             unsigned char output[16])
+      86                 :            : {
+      87                 :            :     const __m128i *rk = (const __m128i *) (ctx->buf + ctx->rk_offset);
+      88                 :            :     unsigned nr = ctx->nr; // Number of remaining rounds
+      89                 :            : 
+      90                 :            :     // Load round key 0
+      91                 :            :     __m128i state;
+      92                 :            :     memcpy(&state, input, 16);
+      93                 :            :     state = _mm_xor_si128(state, rk[0]);  // state ^= *rk;
+      94                 :            :     ++rk;
+      95                 :            :     --nr;
+      96                 :            : 
+      97                 :            : #if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
+      98                 :            :     if (mode == MBEDTLS_AES_DECRYPT) {
+      99                 :            :         while (nr != 0) {
+     100                 :            :             state = _mm_aesdec_si128(state, *rk);
+     101                 :            :             ++rk;
+     102                 :            :             --nr;
+     103                 :            :         }
+     104                 :            :         state = _mm_aesdeclast_si128(state, *rk);
+     105                 :            :     } else
+     106                 :            : #else
+     107                 :            :     (void) mode;
+     108                 :            : #endif
+     109                 :            :     {
+     110                 :            :         while (nr != 0) {
+     111                 :            :             state = _mm_aesenc_si128(state, *rk);
+     112                 :            :             ++rk;
+     113                 :            :             --nr;
+     114                 :            :         }
+     115                 :            :         state = _mm_aesenclast_si128(state, *rk);
+     116                 :            :     }
+     117                 :            : 
+     118                 :            :     memcpy(output, &state, 16);
+     119                 :            :     return 0;
+     120                 :            : }
+     121                 :            : 
+     122                 :            : /*
+     123                 :            :  * GCM multiplication: c = a times b in GF(2^128)
+     124                 :            :  * Based on [CLMUL-WP] algorithms 1 (with equation 27) and 5.
+     125                 :            :  */
+     126                 :            : 
+     127                 :            : static void gcm_clmul(const __m128i aa, const __m128i bb,
+     128                 :            :                       __m128i *cc, __m128i *dd)
+     129                 :            : {
+     130                 :            :     /*
+     131                 :            :      * Caryless multiplication dd:cc = aa * bb
+     132                 :            :      * using [CLMUL-WP] algorithm 1 (p. 12).
+     133                 :            :      */
+     134                 :            :     *cc = _mm_clmulepi64_si128(aa, bb, 0x00); // a0*b0 = c1:c0
+     135                 :            :     *dd = _mm_clmulepi64_si128(aa, bb, 0x11); // a1*b1 = d1:d0
+     136                 :            :     __m128i ee = _mm_clmulepi64_si128(aa, bb, 0x10); // a0*b1 = e1:e0
+     137                 :            :     __m128i ff = _mm_clmulepi64_si128(aa, bb, 0x01); // a1*b0 = f1:f0
+     138                 :            :     ff = _mm_xor_si128(ff, ee);                      // e1+f1:e0+f0
+     139                 :            :     ee = ff;                                         // e1+f1:e0+f0
+     140                 :            :     ff = _mm_srli_si128(ff, 8);                      // 0:e1+f1
+     141                 :            :     ee = _mm_slli_si128(ee, 8);                      // e0+f0:0
+     142                 :            :     *dd = _mm_xor_si128(*dd, ff);                    // d1:d0+e1+f1
+     143                 :            :     *cc = _mm_xor_si128(*cc, ee);                    // c1+e0+f0:c0
+     144                 :            : }
+     145                 :            : 
+     146                 :            : static void gcm_shift(__m128i *cc, __m128i *dd)
+     147                 :            : {
+     148                 :            :     /* [CMUCL-WP] Algorithm 5 Step 1: shift cc:dd one bit to the left,
+     149                 :            :      * taking advantage of [CLMUL-WP] eq 27 (p. 18). */
+     150                 :            :     //                                        // *cc = r1:r0
+     151                 :            :     //                                        // *dd = r3:r2
+     152                 :            :     __m128i cc_lo = _mm_slli_epi64(*cc, 1);   // r1<<1:r0<<1
+     153                 :            :     __m128i dd_lo = _mm_slli_epi64(*dd, 1);   // r3<<1:r2<<1
+     154                 :            :     __m128i cc_hi = _mm_srli_epi64(*cc, 63);  // r1>>63:r0>>63
+     155                 :            :     __m128i dd_hi = _mm_srli_epi64(*dd, 63);  // r3>>63:r2>>63
+     156                 :            :     __m128i xmm5 = _mm_srli_si128(cc_hi, 8);  // 0:r1>>63
+     157                 :            :     cc_hi = _mm_slli_si128(cc_hi, 8);         // r0>>63:0
+     158                 :            :     dd_hi = _mm_slli_si128(dd_hi, 8);         // 0:r1>>63
+     159                 :            : 
+     160                 :            :     *cc = _mm_or_si128(cc_lo, cc_hi);         // r1<<1|r0>>63:r0<<1
+     161                 :            :     *dd = _mm_or_si128(_mm_or_si128(dd_lo, dd_hi), xmm5); // r3<<1|r2>>62:r2<<1|r1>>63
+     162                 :            : }
+     163                 :            : 
+     164                 :            : static __m128i gcm_reduce(__m128i xx)
+     165                 :            : {
+     166                 :            :     //                                            // xx = x1:x0
+     167                 :            :     /* [CLMUL-WP] Algorithm 5 Step 2 */
+     168                 :            :     __m128i aa = _mm_slli_epi64(xx, 63);          // x1<<63:x0<<63 = stuff:a
+     169                 :            :     __m128i bb = _mm_slli_epi64(xx, 62);          // x1<<62:x0<<62 = stuff:b
+     170                 :            :     __m128i cc = _mm_slli_epi64(xx, 57);          // x1<<57:x0<<57 = stuff:c
+     171                 :            :     __m128i dd = _mm_slli_si128(_mm_xor_si128(_mm_xor_si128(aa, bb), cc), 8); // a+b+c:0
+     172                 :            :     return _mm_xor_si128(dd, xx);                 // x1+a+b+c:x0 = d:x0
+     173                 :            : }
+     174                 :            : 
+     175                 :            : static __m128i gcm_mix(__m128i dx)
+     176                 :            : {
+     177                 :            :     /* [CLMUL-WP] Algorithm 5 Steps 3 and 4 */
+     178                 :            :     __m128i ee = _mm_srli_epi64(dx, 1);           // e1:x0>>1 = e1:e0'
+     179                 :            :     __m128i ff = _mm_srli_epi64(dx, 2);           // f1:x0>>2 = f1:f0'
+     180                 :            :     __m128i gg = _mm_srli_epi64(dx, 7);           // g1:x0>>7 = g1:g0'
+     181                 :            : 
+     182                 :            :     // e0'+f0'+g0' is almost e0+f0+g0, except for some missing
+     183                 :            :     // bits carried from d. Now get those bits back in.
+     184                 :            :     __m128i eh = _mm_slli_epi64(dx, 63);          // d<<63:stuff
+     185                 :            :     __m128i fh = _mm_slli_epi64(dx, 62);          // d<<62:stuff
+     186                 :            :     __m128i gh = _mm_slli_epi64(dx, 57);          // d<<57:stuff
+     187                 :            :     __m128i hh = _mm_srli_si128(_mm_xor_si128(_mm_xor_si128(eh, fh), gh), 8); // 0:missing bits of d
+     188                 :            : 
+     189                 :            :     return _mm_xor_si128(_mm_xor_si128(_mm_xor_si128(_mm_xor_si128(ee, ff), gg), hh), dx);
+     190                 :            : }
+     191                 :            : 
+     192                 :            : void mbedtls_aesni_gcm_mult(unsigned char c[16],
+     193                 :            :                             const unsigned char a[16],
+     194                 :            :                             const unsigned char b[16])
+     195                 :            : {
+     196                 :            :     __m128i aa = { 0 }, bb = { 0 }, cc, dd;
+     197                 :            : 
+     198                 :            :     /* The inputs are in big-endian order, so byte-reverse them */
+     199                 :            :     for (size_t i = 0; i < 16; i++) {
+     200                 :            :         ((uint8_t *) &aa)[i] = a[15 - i];
+     201                 :            :         ((uint8_t *) &bb)[i] = b[15 - i];
+     202                 :            :     }
+     203                 :            : 
+     204                 :            :     gcm_clmul(aa, bb, &cc, &dd);
+     205                 :            :     gcm_shift(&cc, &dd);
+     206                 :            :     /*
+     207                 :            :      * Now reduce modulo the GCM polynomial x^128 + x^7 + x^2 + x + 1
+     208                 :            :      * using [CLMUL-WP] algorithm 5 (p. 18).
+     209                 :            :      * Currently dd:cc holds x3:x2:x1:x0 (already shifted).
+     210                 :            :      */
+     211                 :            :     __m128i dx = gcm_reduce(cc);
+     212                 :            :     __m128i xh = gcm_mix(dx);
+     213                 :            :     cc = _mm_xor_si128(xh, dd); // x3+h1:x2+h0
+     214                 :            : 
+     215                 :            :     /* Now byte-reverse the outputs */
+     216                 :            :     for (size_t i = 0; i < 16; i++) {
+     217                 :            :         c[i] = ((uint8_t *) &cc)[15 - i];
+     218                 :            :     }
+     219                 :            : 
+     220                 :            :     return;
+     221                 :            : }
+     222                 :            : 
+     223                 :            : /*
+     224                 :            :  * Compute decryption round keys from encryption round keys
+     225                 :            :  */
+     226                 :            : #if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
+     227                 :            : void mbedtls_aesni_inverse_key(unsigned char *invkey,
+     228                 :            :                                const unsigned char *fwdkey, int nr)
+     229                 :            : {
+     230                 :            :     __m128i *ik = (__m128i *) invkey;
+     231                 :            :     const __m128i *fk = (const __m128i *) fwdkey + nr;
+     232                 :            : 
+     233                 :            :     *ik = *fk;
+     234                 :            :     for (--fk, ++ik; fk > (const __m128i *) fwdkey; --fk, ++ik) {
+     235                 :            :         *ik = _mm_aesimc_si128(*fk);
+     236                 :            :     }
+     237                 :            :     *ik = *fk;
+     238                 :            : }
+     239                 :            : #endif
+     240                 :            : 
+     241                 :            : /*
+     242                 :            :  * Key expansion, 128-bit case
+     243                 :            :  */
+     244                 :            : static __m128i aesni_set_rk_128(__m128i state, __m128i xword)
+     245                 :            : {
+     246                 :            :     /*
+     247                 :            :      * Finish generating the next round key.
+     248                 :            :      *
+     249                 :            :      * On entry state is r3:r2:r1:r0 and xword is X:stuff:stuff:stuff
+     250                 :            :      * with X = rot( sub( r3 ) ) ^ RCON (obtained with AESKEYGENASSIST).
+     251                 :            :      *
+     252                 :            :      * On exit, xword is r7:r6:r5:r4
+     253                 :            :      * with r4 = X + r0, r5 = r4 + r1, r6 = r5 + r2, r7 = r6 + r3
+     254                 :            :      * and this is returned, to be written to the round key buffer.
+     255                 :            :      */
+     256                 :            :     xword = _mm_shuffle_epi32(xword, 0xff);   // X:X:X:X
+     257                 :            :     xword = _mm_xor_si128(xword, state);      // X+r3:X+r2:X+r1:r4
+     258                 :            :     state = _mm_slli_si128(state, 4);         // r2:r1:r0:0
+     259                 :            :     xword = _mm_xor_si128(xword, state);      // X+r3+r2:X+r2+r1:r5:r4
+     260                 :            :     state = _mm_slli_si128(state, 4);         // r1:r0:0:0
+     261                 :            :     xword = _mm_xor_si128(xword, state);      // X+r3+r2+r1:r6:r5:r4
+     262                 :            :     state = _mm_slli_si128(state, 4);         // r0:0:0:0
+     263                 :            :     state = _mm_xor_si128(xword, state);      // r7:r6:r5:r4
+     264                 :            :     return state;
+     265                 :            : }
+     266                 :            : 
+     267                 :            : static void aesni_setkey_enc_128(unsigned char *rk_bytes,
+     268                 :            :                                  const unsigned char *key)
+     269                 :            : {
+     270                 :            :     __m128i *rk = (__m128i *) rk_bytes;
+     271                 :            : 
+     272                 :            :     memcpy(&rk[0], key, 16);
+     273                 :            :     rk[1] = aesni_set_rk_128(rk[0], _mm_aeskeygenassist_si128(rk[0], 0x01));
+     274                 :            :     rk[2] = aesni_set_rk_128(rk[1], _mm_aeskeygenassist_si128(rk[1], 0x02));
+     275                 :            :     rk[3] = aesni_set_rk_128(rk[2], _mm_aeskeygenassist_si128(rk[2], 0x04));
+     276                 :            :     rk[4] = aesni_set_rk_128(rk[3], _mm_aeskeygenassist_si128(rk[3], 0x08));
+     277                 :            :     rk[5] = aesni_set_rk_128(rk[4], _mm_aeskeygenassist_si128(rk[4], 0x10));
+     278                 :            :     rk[6] = aesni_set_rk_128(rk[5], _mm_aeskeygenassist_si128(rk[5], 0x20));
+     279                 :            :     rk[7] = aesni_set_rk_128(rk[6], _mm_aeskeygenassist_si128(rk[6], 0x40));
+     280                 :            :     rk[8] = aesni_set_rk_128(rk[7], _mm_aeskeygenassist_si128(rk[7], 0x80));
+     281                 :            :     rk[9] = aesni_set_rk_128(rk[8], _mm_aeskeygenassist_si128(rk[8], 0x1B));
+     282                 :            :     rk[10] = aesni_set_rk_128(rk[9], _mm_aeskeygenassist_si128(rk[9], 0x36));
+     283                 :            : }
+     284                 :            : 
+     285                 :            : /*
+     286                 :            :  * Key expansion, 192-bit case
+     287                 :            :  */
+     288                 :            : #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
+     289                 :            : static void aesni_set_rk_192(__m128i *state0, __m128i *state1, __m128i xword,
+     290                 :            :                              unsigned char *rk)
+     291                 :            : {
+     292                 :            :     /*
+     293                 :            :      * Finish generating the next 6 quarter-keys.
+     294                 :            :      *
+     295                 :            :      * On entry state0 is r3:r2:r1:r0, state1 is stuff:stuff:r5:r4
+     296                 :            :      * and xword is stuff:stuff:X:stuff with X = rot( sub( r3 ) ) ^ RCON
+     297                 :            :      * (obtained with AESKEYGENASSIST).
+     298                 :            :      *
+     299                 :            :      * On exit, state0 is r9:r8:r7:r6 and state1 is stuff:stuff:r11:r10
+     300                 :            :      * and those are written to the round key buffer.
+     301                 :            :      */
+     302                 :            :     xword = _mm_shuffle_epi32(xword, 0x55);   // X:X:X:X
+     303                 :            :     xword = _mm_xor_si128(xword, *state0);    // X+r3:X+r2:X+r1:X+r0
+     304                 :            :     *state0 = _mm_slli_si128(*state0, 4);     // r2:r1:r0:0
+     305                 :            :     xword = _mm_xor_si128(xword, *state0);    // X+r3+r2:X+r2+r1:X+r1+r0:X+r0
+     306                 :            :     *state0 = _mm_slli_si128(*state0, 4);     // r1:r0:0:0
+     307                 :            :     xword = _mm_xor_si128(xword, *state0);    // X+r3+r2+r1:X+r2+r1+r0:X+r1+r0:X+r0
+     308                 :            :     *state0 = _mm_slli_si128(*state0, 4);     // r0:0:0:0
+     309                 :            :     xword = _mm_xor_si128(xword, *state0);    // X+r3+r2+r1+r0:X+r2+r1+r0:X+r1+r0:X+r0
+     310                 :            :     *state0 = xword;                          // = r9:r8:r7:r6
+     311                 :            : 
+     312                 :            :     xword = _mm_shuffle_epi32(xword, 0xff);   // r9:r9:r9:r9
+     313                 :            :     xword = _mm_xor_si128(xword, *state1);    // stuff:stuff:r9+r5:r9+r4
+     314                 :            :     *state1 = _mm_slli_si128(*state1, 4);     // stuff:stuff:r4:0
+     315                 :            :     xword = _mm_xor_si128(xword, *state1);    // stuff:stuff:r9+r5+r4:r9+r4
+     316                 :            :     *state1 = xword;                          // = stuff:stuff:r11:r10
+     317                 :            : 
+     318                 :            :     /* Store state0 and the low half of state1 into rk, which is conceptually
+     319                 :            :      * an array of 24-byte elements. Since 24 is not a multiple of 16,
+     320                 :            :      * rk is not necessarily aligned so just `*rk = *state0` doesn't work. */
+     321                 :            :     memcpy(rk, state0, 16);
+     322                 :            :     memcpy(rk + 16, state1, 8);
+     323                 :            : }
+     324                 :            : 
+     325                 :            : static void aesni_setkey_enc_192(unsigned char *rk,
+     326                 :            :                                  const unsigned char *key)
+     327                 :            : {
+     328                 :            :     /* First round: use original key */
+     329                 :            :     memcpy(rk, key, 24);
+     330                 :            :     /* aes.c guarantees that rk is aligned on a 16-byte boundary. */
+     331                 :            :     __m128i state0 = ((__m128i *) rk)[0];
+     332                 :            :     __m128i state1 = _mm_loadl_epi64(((__m128i *) rk) + 1);
+     333                 :            : 
+     334                 :            :     aesni_set_rk_192(&state0, &state1, _mm_aeskeygenassist_si128(state1, 0x01), rk + 24 * 1);
+     335                 :            :     aesni_set_rk_192(&state0, &state1, _mm_aeskeygenassist_si128(state1, 0x02), rk + 24 * 2);
+     336                 :            :     aesni_set_rk_192(&state0, &state1, _mm_aeskeygenassist_si128(state1, 0x04), rk + 24 * 3);
+     337                 :            :     aesni_set_rk_192(&state0, &state1, _mm_aeskeygenassist_si128(state1, 0x08), rk + 24 * 4);
+     338                 :            :     aesni_set_rk_192(&state0, &state1, _mm_aeskeygenassist_si128(state1, 0x10), rk + 24 * 5);
+     339                 :            :     aesni_set_rk_192(&state0, &state1, _mm_aeskeygenassist_si128(state1, 0x20), rk + 24 * 6);
+     340                 :            :     aesni_set_rk_192(&state0, &state1, _mm_aeskeygenassist_si128(state1, 0x40), rk + 24 * 7);
+     341                 :            :     aesni_set_rk_192(&state0, &state1, _mm_aeskeygenassist_si128(state1, 0x80), rk + 24 * 8);
+     342                 :            : }
+     343                 :            : #endif /* !MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
+     344                 :            : 
+     345                 :            : /*
+     346                 :            :  * Key expansion, 256-bit case
+     347                 :            :  */
+     348                 :            : #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
+     349                 :            : static void aesni_set_rk_256(__m128i state0, __m128i state1, __m128i xword,
+     350                 :            :                              __m128i *rk0, __m128i *rk1)
+     351                 :            : {
+     352                 :            :     /*
+     353                 :            :      * Finish generating the next two round keys.
+     354                 :            :      *
+     355                 :            :      * On entry state0 is r3:r2:r1:r0, state1 is r7:r6:r5:r4 and
+     356                 :            :      * xword is X:stuff:stuff:stuff with X = rot( sub( r7 )) ^ RCON
+     357                 :            :      * (obtained with AESKEYGENASSIST).
+     358                 :            :      *
+     359                 :            :      * On exit, *rk0 is r11:r10:r9:r8 and *rk1 is r15:r14:r13:r12
+     360                 :            :      */
+     361                 :            :     xword = _mm_shuffle_epi32(xword, 0xff);
+     362                 :            :     xword = _mm_xor_si128(xword, state0);
+     363                 :            :     state0 = _mm_slli_si128(state0, 4);
+     364                 :            :     xword = _mm_xor_si128(xword, state0);
+     365                 :            :     state0 = _mm_slli_si128(state0, 4);
+     366                 :            :     xword = _mm_xor_si128(xword, state0);
+     367                 :            :     state0 = _mm_slli_si128(state0, 4);
+     368                 :            :     state0 = _mm_xor_si128(state0, xword);
+     369                 :            :     *rk0 = state0;
+     370                 :            : 
+     371                 :            :     /* Set xword to stuff:Y:stuff:stuff with Y = subword( r11 )
+     372                 :            :      * and proceed to generate next round key from there */
+     373                 :            :     xword = _mm_aeskeygenassist_si128(state0, 0x00);
+     374                 :            :     xword = _mm_shuffle_epi32(xword, 0xaa);
+     375                 :            :     xword = _mm_xor_si128(xword, state1);
+     376                 :            :     state1 = _mm_slli_si128(state1, 4);
+     377                 :            :     xword = _mm_xor_si128(xword, state1);
+     378                 :            :     state1 = _mm_slli_si128(state1, 4);
+     379                 :            :     xword = _mm_xor_si128(xword, state1);
+     380                 :            :     state1 = _mm_slli_si128(state1, 4);
+     381                 :            :     state1 = _mm_xor_si128(state1, xword);
+     382                 :            :     *rk1 = state1;
+     383                 :            : }
+     384                 :            : 
+     385                 :            : static void aesni_setkey_enc_256(unsigned char *rk_bytes,
+     386                 :            :                                  const unsigned char *key)
+     387                 :            : {
+     388                 :            :     __m128i *rk = (__m128i *) rk_bytes;
+     389                 :            : 
+     390                 :            :     memcpy(&rk[0], key, 16);
+     391                 :            :     memcpy(&rk[1], key + 16, 16);
+     392                 :            : 
+     393                 :            :     /*
+     394                 :            :      * Main "loop" - Generating one more key than necessary,
+     395                 :            :      * see definition of mbedtls_aes_context.buf
+     396                 :            :      */
+     397                 :            :     aesni_set_rk_256(rk[0], rk[1], _mm_aeskeygenassist_si128(rk[1], 0x01), &rk[2], &rk[3]);
+     398                 :            :     aesni_set_rk_256(rk[2], rk[3], _mm_aeskeygenassist_si128(rk[3], 0x02), &rk[4], &rk[5]);
+     399                 :            :     aesni_set_rk_256(rk[4], rk[5], _mm_aeskeygenassist_si128(rk[5], 0x04), &rk[6], &rk[7]);
+     400                 :            :     aesni_set_rk_256(rk[6], rk[7], _mm_aeskeygenassist_si128(rk[7], 0x08), &rk[8], &rk[9]);
+     401                 :            :     aesni_set_rk_256(rk[8], rk[9], _mm_aeskeygenassist_si128(rk[9], 0x10), &rk[10], &rk[11]);
+     402                 :            :     aesni_set_rk_256(rk[10], rk[11], _mm_aeskeygenassist_si128(rk[11], 0x20), &rk[12], &rk[13]);
+     403                 :            :     aesni_set_rk_256(rk[12], rk[13], _mm_aeskeygenassist_si128(rk[13], 0x40), &rk[14], &rk[15]);
+     404                 :            : }
+     405                 :            : #endif /* !MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
+     406                 :            : 
+     407                 :            : #if defined(MBEDTLS_POP_TARGET_PRAGMA)
+     408                 :            : #if defined(__clang__)
+     409                 :            : #pragma clang attribute pop
+     410                 :            : #elif defined(__GNUC__)
+     411                 :            : #pragma GCC pop_options
+     412                 :            : #endif
+     413                 :            : #undef MBEDTLS_POP_TARGET_PRAGMA
+     414                 :            : #endif
+     415                 :            : 
+     416                 :            : #else /* MBEDTLS_AESNI_HAVE_CODE == 1 */
+     417                 :            : 
+     418                 :            : #if defined(__has_feature)
+     419                 :            : #if __has_feature(memory_sanitizer)
+     420                 :            : #warning \
+     421                 :            :     "MBEDTLS_AESNI_C is known to cause spurious error reports with some memory sanitizers as they do not understand the assembly code."
+     422                 :            : #endif
+     423                 :            : #endif
+     424                 :            : 
+     425                 :            : /*
+     426                 :            :  * Binutils needs to be at least 2.19 to support AES-NI instructions.
+     427                 :            :  * Unfortunately, a lot of users have a lower version now (2014-04).
+     428                 :            :  * Emit bytecode directly in order to support "old" version of gas.
+     429                 :            :  *
+     430                 :            :  * Opcodes from the Intel architecture reference manual, vol. 3.
+     431                 :            :  * We always use registers, so we don't need prefixes for memory operands.
+     432                 :            :  * Operand macros are in gas order (src, dst) as opposed to Intel order
+     433                 :            :  * (dst, src) in order to blend better into the surrounding assembly code.
+     434                 :            :  */
+     435                 :            : #define AESDEC(regs)      ".byte 0x66,0x0F,0x38,0xDE," regs "\n\t"
+     436                 :            : #define AESDECLAST(regs)  ".byte 0x66,0x0F,0x38,0xDF," regs "\n\t"
+     437                 :            : #define AESENC(regs)      ".byte 0x66,0x0F,0x38,0xDC," regs "\n\t"
+     438                 :            : #define AESENCLAST(regs)  ".byte 0x66,0x0F,0x38,0xDD," regs "\n\t"
+     439                 :            : #define AESIMC(regs)      ".byte 0x66,0x0F,0x38,0xDB," regs "\n\t"
+     440                 :            : #define AESKEYGENA(regs, imm)  ".byte 0x66,0x0F,0x3A,0xDF," regs "," imm "\n\t"
+     441                 :            : #define PCLMULQDQ(regs, imm)   ".byte 0x66,0x0F,0x3A,0x44," regs "," imm "\n\t"
+     442                 :            : 
+     443                 :            : #define xmm0_xmm0   "0xC0"
+     444                 :            : #define xmm0_xmm1   "0xC8"
+     445                 :            : #define xmm0_xmm2   "0xD0"
+     446                 :            : #define xmm0_xmm3   "0xD8"
+     447                 :            : #define xmm0_xmm4   "0xE0"
+     448                 :            : #define xmm1_xmm0   "0xC1"
+     449                 :            : #define xmm1_xmm2   "0xD1"
+     450                 :            : 
+     451                 :            : /*
+     452                 :            :  * AES-NI AES-ECB block en(de)cryption
+     453                 :            :  */
+     454                 :       3654 : int mbedtls_aesni_crypt_ecb(mbedtls_aes_context *ctx,
+     455                 :            :                             int mode,
+     456                 :            :                             const unsigned char input[16],
+     457                 :            :                             unsigned char output[16])
+     458                 :            : {
+     459                 :       3654 :     asm ("movdqu    (%3), %%xmm0    \n\t" // load input
+     460                 :            :          "movdqu    (%1), %%xmm1    \n\t" // load round key 0
+     461                 :            :          "pxor      %%xmm1, %%xmm0  \n\t" // round 0
+     462                 :            :          "add       $16, %1         \n\t" // point to next round key
+     463                 :            :          "subl      $1, %0          \n\t" // normal rounds = nr - 1
+     464                 :            :          "test      %2, %2          \n\t" // mode?
+     465                 :            :          "jz        2f              \n\t" // 0 = decrypt
+     466                 :            : 
+     467                 :            :          "1:                        \n\t" // encryption loop
+     468                 :            :          "movdqu    (%1), %%xmm1    \n\t" // load round key
+     469                 :            :          AESENC(xmm1_xmm0)                // do round
+     470                 :            :          "add       $16, %1         \n\t" // point to next round key
+     471                 :            :          "subl      $1, %0          \n\t" // loop
+     472                 :            :          "jnz       1b              \n\t"
+     473                 :            :          "movdqu    (%1), %%xmm1    \n\t" // load round key
+     474                 :            :          AESENCLAST(xmm1_xmm0)            // last round
+     475                 :            : #if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
+     476                 :            :          "jmp       3f              \n\t"
+     477                 :            : 
+     478                 :            :          "2:                        \n\t" // decryption loop
+     479                 :            :          "movdqu    (%1), %%xmm1    \n\t"
+     480                 :            :          AESDEC(xmm1_xmm0)                // do round
+     481                 :            :          "add       $16, %1         \n\t"
+     482                 :            :          "subl      $1, %0          \n\t"
+     483                 :            :          "jnz       2b              \n\t"
+     484                 :            :          "movdqu    (%1), %%xmm1    \n\t" // load round key
+     485                 :            :          AESDECLAST(xmm1_xmm0)            // last round
+     486                 :            : #endif
+     487                 :            : 
+     488                 :            :          "3:                        \n\t"
+     489                 :            :          "movdqu    %%xmm0, (%4)    \n\t" // export output
+     490                 :            :          :
+     491                 :       3654 :          : "r" (ctx->nr), "r" (ctx->buf + ctx->rk_offset), "r" (mode), "r" (input), "r" (output)
+     492                 :            :          : "memory", "cc", "xmm0", "xmm1");
+     493                 :            : 
+     494                 :            : 
+     495                 :       3654 :     return 0;
+     496                 :            : }
+     497                 :            : 
+     498                 :            : /*
+     499                 :            :  * GCM multiplication: c = a times b in GF(2^128)
+     500                 :            :  * Based on [CLMUL-WP] algorithms 1 (with equation 27) and 5.
+     501                 :            :  */
+     502                 :       3658 : void mbedtls_aesni_gcm_mult(unsigned char c[16],
+     503                 :            :                             const unsigned char a[16],
+     504                 :            :                             const unsigned char b[16])
+     505                 :            : {
+     506                 :            :     unsigned char aa[16], bb[16], cc[16];
+     507                 :            :     size_t i;
+     508                 :            : 
+     509                 :            :     /* The inputs are in big-endian order, so byte-reverse them */
+     510         [ +  + ]:      62186 :     for (i = 0; i < 16; i++) {
+     511                 :      58528 :         aa[i] = a[15 - i];
+     512                 :      58528 :         bb[i] = b[15 - i];
+     513                 :            :     }
+     514                 :            : 
+     515                 :       3658 :     asm ("movdqu (%0), %%xmm0               \n\t" // a1:a0
+     516                 :            :          "movdqu (%1), %%xmm1               \n\t" // b1:b0
+     517                 :            : 
+     518                 :            :          /*
+     519                 :            :           * Caryless multiplication xmm2:xmm1 = xmm0 * xmm1
+     520                 :            :           * using [CLMUL-WP] algorithm 1 (p. 12).
+     521                 :            :           */
+     522                 :            :          "movdqa %%xmm1, %%xmm2             \n\t" // copy of b1:b0
+     523                 :            :          "movdqa %%xmm1, %%xmm3             \n\t" // same
+     524                 :            :          "movdqa %%xmm1, %%xmm4             \n\t" // same
+     525                 :            :          PCLMULQDQ(xmm0_xmm1, "0x00")             // a0*b0 = c1:c0
+     526                 :            :          PCLMULQDQ(xmm0_xmm2, "0x11")             // a1*b1 = d1:d0
+     527                 :            :          PCLMULQDQ(xmm0_xmm3, "0x10")             // a0*b1 = e1:e0
+     528                 :            :          PCLMULQDQ(xmm0_xmm4, "0x01")             // a1*b0 = f1:f0
+     529                 :            :          "pxor %%xmm3, %%xmm4               \n\t" // e1+f1:e0+f0
+     530                 :            :          "movdqa %%xmm4, %%xmm3             \n\t" // same
+     531                 :            :          "psrldq $8, %%xmm4                 \n\t" // 0:e1+f1
+     532                 :            :          "pslldq $8, %%xmm3                 \n\t" // e0+f0:0
+     533                 :            :          "pxor %%xmm4, %%xmm2               \n\t" // d1:d0+e1+f1
+     534                 :            :          "pxor %%xmm3, %%xmm1               \n\t" // c1+e0+f1:c0
+     535                 :            : 
+     536                 :            :          /*
+     537                 :            :           * Now shift the result one bit to the left,
+     538                 :            :           * taking advantage of [CLMUL-WP] eq 27 (p. 18)
+     539                 :            :           */
+     540                 :            :          "movdqa %%xmm1, %%xmm3             \n\t" // r1:r0
+     541                 :            :          "movdqa %%xmm2, %%xmm4             \n\t" // r3:r2
+     542                 :            :          "psllq $1, %%xmm1                  \n\t" // r1<<1:r0<<1
+     543                 :            :          "psllq $1, %%xmm2                  \n\t" // r3<<1:r2<<1
+     544                 :            :          "psrlq $63, %%xmm3                 \n\t" // r1>>63:r0>>63
+     545                 :            :          "psrlq $63, %%xmm4                 \n\t" // r3>>63:r2>>63
+     546                 :            :          "movdqa %%xmm3, %%xmm5             \n\t" // r1>>63:r0>>63
+     547                 :            :          "pslldq $8, %%xmm3                 \n\t" // r0>>63:0
+     548                 :            :          "pslldq $8, %%xmm4                 \n\t" // r2>>63:0
+     549                 :            :          "psrldq $8, %%xmm5                 \n\t" // 0:r1>>63
+     550                 :            :          "por %%xmm3, %%xmm1                \n\t" // r1<<1|r0>>63:r0<<1
+     551                 :            :          "por %%xmm4, %%xmm2                \n\t" // r3<<1|r2>>62:r2<<1
+     552                 :            :          "por %%xmm5, %%xmm2                \n\t" // r3<<1|r2>>62:r2<<1|r1>>63
+     553                 :            : 
+     554                 :            :          /*
+     555                 :            :           * Now reduce modulo the GCM polynomial x^128 + x^7 + x^2 + x + 1
+     556                 :            :           * using [CLMUL-WP] algorithm 5 (p. 18).
+     557                 :            :           * Currently xmm2:xmm1 holds x3:x2:x1:x0 (already shifted).
+     558                 :            :           */
+     559                 :            :          /* Step 2 (1) */
+     560                 :            :          "movdqa %%xmm1, %%xmm3             \n\t" // x1:x0
+     561                 :            :          "movdqa %%xmm1, %%xmm4             \n\t" // same
+     562                 :            :          "movdqa %%xmm1, %%xmm5             \n\t" // same
+     563                 :            :          "psllq $63, %%xmm3                 \n\t" // x1<<63:x0<<63 = stuff:a
+     564                 :            :          "psllq $62, %%xmm4                 \n\t" // x1<<62:x0<<62 = stuff:b
+     565                 :            :          "psllq $57, %%xmm5                 \n\t" // x1<<57:x0<<57 = stuff:c
+     566                 :            : 
+     567                 :            :          /* Step 2 (2) */
+     568                 :            :          "pxor %%xmm4, %%xmm3               \n\t" // stuff:a+b
+     569                 :            :          "pxor %%xmm5, %%xmm3               \n\t" // stuff:a+b+c
+     570                 :            :          "pslldq $8, %%xmm3                 \n\t" // a+b+c:0
+     571                 :            :          "pxor %%xmm3, %%xmm1               \n\t" // x1+a+b+c:x0 = d:x0
+     572                 :            : 
+     573                 :            :          /* Steps 3 and 4 */
+     574                 :            :          "movdqa %%xmm1,%%xmm0              \n\t" // d:x0
+     575                 :            :          "movdqa %%xmm1,%%xmm4              \n\t" // same
+     576                 :            :          "movdqa %%xmm1,%%xmm5              \n\t" // same
+     577                 :            :          "psrlq $1, %%xmm0                  \n\t" // e1:x0>>1 = e1:e0'
+     578                 :            :          "psrlq $2, %%xmm4                  \n\t" // f1:x0>>2 = f1:f0'
+     579                 :            :          "psrlq $7, %%xmm5                  \n\t" // g1:x0>>7 = g1:g0'
+     580                 :            :          "pxor %%xmm4, %%xmm0               \n\t" // e1+f1:e0'+f0'
+     581                 :            :          "pxor %%xmm5, %%xmm0               \n\t" // e1+f1+g1:e0'+f0'+g0'
+     582                 :            :          // e0'+f0'+g0' is almost e0+f0+g0, ex\tcept for some missing
+     583                 :            :          // bits carried from d. Now get those\t bits back in.
+     584                 :            :          "movdqa %%xmm1,%%xmm3              \n\t" // d:x0
+     585                 :            :          "movdqa %%xmm1,%%xmm4              \n\t" // same
+     586                 :            :          "movdqa %%xmm1,%%xmm5              \n\t" // same
+     587                 :            :          "psllq $63, %%xmm3                 \n\t" // d<<63:stuff
+     588                 :            :          "psllq $62, %%xmm4                 \n\t" // d<<62:stuff
+     589                 :            :          "psllq $57, %%xmm5                 \n\t" // d<<57:stuff
+     590                 :            :          "pxor %%xmm4, %%xmm3               \n\t" // d<<63+d<<62:stuff
+     591                 :            :          "pxor %%xmm5, %%xmm3               \n\t" // missing bits of d:stuff
+     592                 :            :          "psrldq $8, %%xmm3                 \n\t" // 0:missing bits of d
+     593                 :            :          "pxor %%xmm3, %%xmm0               \n\t" // e1+f1+g1:e0+f0+g0
+     594                 :            :          "pxor %%xmm1, %%xmm0               \n\t" // h1:h0
+     595                 :            :          "pxor %%xmm2, %%xmm0               \n\t" // x3+h1:x2+h0
+     596                 :            : 
+     597                 :            :          "movdqu %%xmm0, (%2)               \n\t" // done
+     598                 :            :          :
+     599                 :            :          : "r" (aa), "r" (bb), "r" (cc)
+     600                 :            :          : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5");
+     601                 :            : 
+     602                 :            :     /* Now byte-reverse the outputs */
+     603         [ +  + ]:      62186 :     for (i = 0; i < 16; i++) {
+     604                 :      58528 :         c[i] = cc[15 - i];
+     605                 :            :     }
+     606                 :            : 
+     607                 :       3658 :     return;
+     608                 :            : }
+     609                 :            : 
+     610                 :            : /*
+     611                 :            :  * Compute decryption round keys from encryption round keys
+     612                 :            :  */
+     613                 :            : #if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
+     614                 :          0 : void mbedtls_aesni_inverse_key(unsigned char *invkey,
+     615                 :            :                                const unsigned char *fwdkey, int nr)
+     616                 :            : {
+     617                 :          0 :     unsigned char *ik = invkey;
+     618                 :          0 :     const unsigned char *fk = fwdkey + 16 * nr;
+     619                 :            : 
+     620                 :          0 :     memcpy(ik, fk, 16);
+     621                 :            : 
+     622         [ #  # ]:          0 :     for (fk -= 16, ik += 16; fk > fwdkey; fk -= 16, ik += 16) {
+     623                 :          0 :         asm ("movdqu (%0), %%xmm0       \n\t"
+     624                 :            :              AESIMC(xmm0_xmm0)
+     625                 :            :              "movdqu %%xmm0, (%1)       \n\t"
+     626                 :            :              :
+     627                 :            :              : "r" (fk), "r" (ik)
+     628                 :            :              : "memory", "xmm0");
+     629                 :            :     }
+     630                 :            : 
+     631                 :          0 :     memcpy(ik, fk, 16);
+     632                 :          0 : }
+     633                 :            : #endif
+     634                 :            : 
+     635                 :            : /*
+     636                 :            :  * Key expansion, 128-bit case
+     637                 :            :  */
+     638                 :          2 : static void aesni_setkey_enc_128(unsigned char *rk,
+     639                 :            :                                  const unsigned char *key)
+     640                 :            : {
+     641                 :          2 :     asm ("movdqu (%1), %%xmm0               \n\t" // copy the original key
+     642                 :            :          "movdqu %%xmm0, (%0)               \n\t" // as round key 0
+     643                 :            :          "jmp 2f                            \n\t" // skip auxiliary routine
+     644                 :            : 
+     645                 :            :          /*
+     646                 :            :           * Finish generating the next round key.
+     647                 :            :           *
+     648                 :            :           * On entry xmm0 is r3:r2:r1:r0 and xmm1 is X:stuff:stuff:stuff
+     649                 :            :           * with X = rot( sub( r3 ) ) ^ RCON.
+     650                 :            :           *
+     651                 :            :           * On exit, xmm0 is r7:r6:r5:r4
+     652                 :            :           * with r4 = X + r0, r5 = r4 + r1, r6 = r5 + r2, r7 = r6 + r3
+     653                 :            :           * and those are written to the round key buffer.
+     654                 :            :           */
+     655                 :            :          "1:                                \n\t"
+     656                 :            :          "pshufd $0xff, %%xmm1, %%xmm1      \n\t" // X:X:X:X
+     657                 :            :          "pxor %%xmm0, %%xmm1               \n\t" // X+r3:X+r2:X+r1:r4
+     658                 :            :          "pslldq $4, %%xmm0                 \n\t" // r2:r1:r0:0
+     659                 :            :          "pxor %%xmm0, %%xmm1               \n\t" // X+r3+r2:X+r2+r1:r5:r4
+     660                 :            :          "pslldq $4, %%xmm0                 \n\t" // etc
+     661                 :            :          "pxor %%xmm0, %%xmm1               \n\t"
+     662                 :            :          "pslldq $4, %%xmm0                 \n\t"
+     663                 :            :          "pxor %%xmm1, %%xmm0               \n\t" // update xmm0 for next time!
+     664                 :            :          "add $16, %0                       \n\t" // point to next round key
+     665                 :            :          "movdqu %%xmm0, (%0)               \n\t" // write it
+     666                 :            :          "ret                               \n\t"
+     667                 :            : 
+     668                 :            :          /* Main "loop" */
+     669                 :            :          "2:                                \n\t"
+     670                 :            :          AESKEYGENA(xmm0_xmm1, "0x01")      "call 1b \n\t"
+     671                 :            :          AESKEYGENA(xmm0_xmm1, "0x02")      "call 1b \n\t"
+     672                 :            :          AESKEYGENA(xmm0_xmm1, "0x04")      "call 1b \n\t"
+     673                 :            :          AESKEYGENA(xmm0_xmm1, "0x08")      "call 1b \n\t"
+     674                 :            :          AESKEYGENA(xmm0_xmm1, "0x10")      "call 1b \n\t"
+     675                 :            :          AESKEYGENA(xmm0_xmm1, "0x20")      "call 1b \n\t"
+     676                 :            :          AESKEYGENA(xmm0_xmm1, "0x40")      "call 1b \n\t"
+     677                 :            :          AESKEYGENA(xmm0_xmm1, "0x80")      "call 1b \n\t"
+     678                 :            :          AESKEYGENA(xmm0_xmm1, "0x1B")      "call 1b \n\t"
+     679                 :            :          AESKEYGENA(xmm0_xmm1, "0x36")      "call 1b \n\t"
+     680                 :            :          :
+     681                 :            :          : "r" (rk), "r" (key)
+     682                 :            :          : "memory", "cc", "0");
+     683                 :          2 : }
+     684                 :            : 
+     685                 :            : /*
+     686                 :            :  * Key expansion, 192-bit case
+     687                 :            :  */
+     688                 :            : #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
+     689                 :          0 : static void aesni_setkey_enc_192(unsigned char *rk,
+     690                 :            :                                  const unsigned char *key)
+     691                 :            : {
+     692                 :          0 :     asm ("movdqu (%1), %%xmm0   \n\t" // copy original round key
+     693                 :            :          "movdqu %%xmm0, (%0)   \n\t"
+     694                 :            :          "add $16, %0           \n\t"
+     695                 :            :          "movq 16(%1), %%xmm1   \n\t"
+     696                 :            :          "movq %%xmm1, (%0)     \n\t"
+     697                 :            :          "add $8, %0            \n\t"
+     698                 :            :          "jmp 2f                \n\t" // skip auxiliary routine
+     699                 :            : 
+     700                 :            :          /*
+     701                 :            :           * Finish generating the next 6 quarter-keys.
+     702                 :            :           *
+     703                 :            :           * On entry xmm0 is r3:r2:r1:r0, xmm1 is stuff:stuff:r5:r4
+     704                 :            :           * and xmm2 is stuff:stuff:X:stuff with X = rot( sub( r3 ) ) ^ RCON.
+     705                 :            :           *
+     706                 :            :           * On exit, xmm0 is r9:r8:r7:r6 and xmm1 is stuff:stuff:r11:r10
+     707                 :            :           * and those are written to the round key buffer.
+     708                 :            :           */
+     709                 :            :          "1:                            \n\t"
+     710                 :            :          "pshufd $0x55, %%xmm2, %%xmm2  \n\t" // X:X:X:X
+     711                 :            :          "pxor %%xmm0, %%xmm2           \n\t" // X+r3:X+r2:X+r1:r4
+     712                 :            :          "pslldq $4, %%xmm0             \n\t" // etc
+     713                 :            :          "pxor %%xmm0, %%xmm2           \n\t"
+     714                 :            :          "pslldq $4, %%xmm0             \n\t"
+     715                 :            :          "pxor %%xmm0, %%xmm2           \n\t"
+     716                 :            :          "pslldq $4, %%xmm0             \n\t"
+     717                 :            :          "pxor %%xmm2, %%xmm0           \n\t" // update xmm0 = r9:r8:r7:r6
+     718                 :            :          "movdqu %%xmm0, (%0)           \n\t"
+     719                 :            :          "add $16, %0                   \n\t"
+     720                 :            :          "pshufd $0xff, %%xmm0, %%xmm2  \n\t" // r9:r9:r9:r9
+     721                 :            :          "pxor %%xmm1, %%xmm2           \n\t" // stuff:stuff:r9+r5:r10
+     722                 :            :          "pslldq $4, %%xmm1             \n\t" // r2:r1:r0:0
+     723                 :            :          "pxor %%xmm2, %%xmm1           \n\t" // xmm1 = stuff:stuff:r11:r10
+     724                 :            :          "movq %%xmm1, (%0)             \n\t"
+     725                 :            :          "add $8, %0                    \n\t"
+     726                 :            :          "ret                           \n\t"
+     727                 :            : 
+     728                 :            :          "2:                            \n\t"
+     729                 :            :          AESKEYGENA(xmm1_xmm2, "0x01")  "call 1b \n\t"
+     730                 :            :          AESKEYGENA(xmm1_xmm2, "0x02")  "call 1b \n\t"
+     731                 :            :          AESKEYGENA(xmm1_xmm2, "0x04")  "call 1b \n\t"
+     732                 :            :          AESKEYGENA(xmm1_xmm2, "0x08")  "call 1b \n\t"
+     733                 :            :          AESKEYGENA(xmm1_xmm2, "0x10")  "call 1b \n\t"
+     734                 :            :          AESKEYGENA(xmm1_xmm2, "0x20")  "call 1b \n\t"
+     735                 :            :          AESKEYGENA(xmm1_xmm2, "0x40")  "call 1b \n\t"
+     736                 :            :          AESKEYGENA(xmm1_xmm2, "0x80")  "call 1b \n\t"
+     737                 :            : 
+     738                 :            :          :
+     739                 :            :          : "r" (rk), "r" (key)
+     740                 :            :          : "memory", "cc", "0");
+     741                 :          0 : }
+     742                 :            : #endif /* !MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
+     743                 :            : 
+     744                 :            : /*
+     745                 :            :  * Key expansion, 256-bit case
+     746                 :            :  */
+     747                 :            : #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
+     748                 :        789 : static void aesni_setkey_enc_256(unsigned char *rk,
+     749                 :            :                                  const unsigned char *key)
+     750                 :            : {
+     751                 :        789 :     asm ("movdqu (%1), %%xmm0           \n\t"
+     752                 :            :          "movdqu %%xmm0, (%0)           \n\t"
+     753                 :            :          "add $16, %0                   \n\t"
+     754                 :            :          "movdqu 16(%1), %%xmm1         \n\t"
+     755                 :            :          "movdqu %%xmm1, (%0)           \n\t"
+     756                 :            :          "jmp 2f                        \n\t" // skip auxiliary routine
+     757                 :            : 
+     758                 :            :          /*
+     759                 :            :           * Finish generating the next two round keys.
+     760                 :            :           *
+     761                 :            :           * On entry xmm0 is r3:r2:r1:r0, xmm1 is r7:r6:r5:r4 and
+     762                 :            :           * xmm2 is X:stuff:stuff:stuff with X = rot( sub( r7 )) ^ RCON
+     763                 :            :           *
+     764                 :            :           * On exit, xmm0 is r11:r10:r9:r8 and xmm1 is r15:r14:r13:r12
+     765                 :            :           * and those have been written to the output buffer.
+     766                 :            :           */
+     767                 :            :          "1:                                \n\t"
+     768                 :            :          "pshufd $0xff, %%xmm2, %%xmm2      \n\t"
+     769                 :            :          "pxor %%xmm0, %%xmm2               \n\t"
+     770                 :            :          "pslldq $4, %%xmm0                 \n\t"
+     771                 :            :          "pxor %%xmm0, %%xmm2               \n\t"
+     772                 :            :          "pslldq $4, %%xmm0                 \n\t"
+     773                 :            :          "pxor %%xmm0, %%xmm2               \n\t"
+     774                 :            :          "pslldq $4, %%xmm0                 \n\t"
+     775                 :            :          "pxor %%xmm2, %%xmm0               \n\t"
+     776                 :            :          "add $16, %0                       \n\t"
+     777                 :            :          "movdqu %%xmm0, (%0)               \n\t"
+     778                 :            : 
+     779                 :            :          /* Set xmm2 to stuff:Y:stuff:stuff with Y = subword( r11 )
+     780                 :            :           * and proceed to generate next round key from there */
+     781                 :            :          AESKEYGENA(xmm0_xmm2, "0x00")
+     782                 :            :          "pshufd $0xaa, %%xmm2, %%xmm2      \n\t"
+     783                 :            :          "pxor %%xmm1, %%xmm2               \n\t"
+     784                 :            :          "pslldq $4, %%xmm1                 \n\t"
+     785                 :            :          "pxor %%xmm1, %%xmm2               \n\t"
+     786                 :            :          "pslldq $4, %%xmm1                 \n\t"
+     787                 :            :          "pxor %%xmm1, %%xmm2               \n\t"
+     788                 :            :          "pslldq $4, %%xmm1                 \n\t"
+     789                 :            :          "pxor %%xmm2, %%xmm1               \n\t"
+     790                 :            :          "add $16, %0                       \n\t"
+     791                 :            :          "movdqu %%xmm1, (%0)               \n\t"
+     792                 :            :          "ret                               \n\t"
+     793                 :            : 
+     794                 :            :          /*
+     795                 :            :           * Main "loop" - Generating one more key than necessary,
+     796                 :            :           * see definition of mbedtls_aes_context.buf
+     797                 :            :           */
+     798                 :            :          "2:                                \n\t"
+     799                 :            :          AESKEYGENA(xmm1_xmm2, "0x01")      "call 1b \n\t"
+     800                 :            :          AESKEYGENA(xmm1_xmm2, "0x02")      "call 1b \n\t"
+     801                 :            :          AESKEYGENA(xmm1_xmm2, "0x04")      "call 1b \n\t"
+     802                 :            :          AESKEYGENA(xmm1_xmm2, "0x08")      "call 1b \n\t"
+     803                 :            :          AESKEYGENA(xmm1_xmm2, "0x10")      "call 1b \n\t"
+     804                 :            :          AESKEYGENA(xmm1_xmm2, "0x20")      "call 1b \n\t"
+     805                 :            :          AESKEYGENA(xmm1_xmm2, "0x40")      "call 1b \n\t"
+     806                 :            :          :
+     807                 :            :          : "r" (rk), "r" (key)
+     808                 :            :          : "memory", "cc", "0");
+     809                 :        789 : }
+     810                 :            : #endif /* !MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
+     811                 :            : 
+     812                 :            : #endif  /* MBEDTLS_AESNI_HAVE_CODE */
+     813                 :            : 
+     814                 :            : /*
+     815                 :            :  * Key expansion, wrapper
+     816                 :            :  */
+     817                 :        791 : int mbedtls_aesni_setkey_enc(unsigned char *rk,
+     818                 :            :                              const unsigned char *key,
+     819                 :            :                              size_t bits)
+     820                 :            : {
+     821   [ +  -  +  - ]:        791 :     switch (bits) {
+     822                 :          2 :         case 128: aesni_setkey_enc_128(rk, key); break;
+     823                 :            : #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
+     824                 :          0 :         case 192: aesni_setkey_enc_192(rk, key); break;
+     825                 :        789 :         case 256: aesni_setkey_enc_256(rk, key); break;
+     826                 :            : #endif /* !MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
+     827                 :          0 :         default: return MBEDTLS_ERR_AES_INVALID_KEY_LENGTH;
+     828                 :            :     }
+     829                 :            : 
+     830                 :        791 :     return 0;
+     831                 :            : }
+     832                 :            : 
+     833                 :            : #endif /* MBEDTLS_AESNI_HAVE_CODE */
+     834                 :            : 
+     835                 :            : #endif /* MBEDTLS_AESNI_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/alignment.h.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/alignment.h.func-sort-c.html new file mode 100644 index 00000000000..a859bcd3bec --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/alignment.h.func-sort-c.html @@ -0,0 +1,81 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/alignment.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - alignment.h (source / functions)HitTotalCoverage
Test:coverage.infoLines:81266.7 %
Date:2024-09-22 08:21:07Functions:00-
Branches:00-
+
+ +
+ + + + + + +

Function Name Sort by function nameHit count Sort by hit count
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/alignment.h.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/alignment.h.func.html new file mode 100644 index 00000000000..eb5cff134fa --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/alignment.h.func.html @@ -0,0 +1,81 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/alignment.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - alignment.h (source / functions)HitTotalCoverage
Test:coverage.infoLines:81266.7 %
Date:2024-09-22 08:21:07Functions:00-
Branches:00-
+
+ +
+ + + + + + +

Function Name Sort by function nameHit count Sort by hit count
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/alignment.h.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/alignment.h.gcov.html new file mode 100644 index 00000000000..499713ffcb1 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/alignment.h.gcov.html @@ -0,0 +1,769 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/alignment.h + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - alignment.h (source / functions)HitTotalCoverage
Test:coverage.infoLines:81266.7 %
Date:2024-09-22 08:21:07Functions:00-
Branches:00-
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  * \file alignment.h
+       3                 :            :  *
+       4                 :            :  * \brief Utility code for dealing with unaligned memory accesses
+       5                 :            :  */
+       6                 :            : /*
+       7                 :            :  *  Copyright The Mbed TLS Contributors
+       8                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       9                 :            :  */
+      10                 :            : 
+      11                 :            : #ifndef MBEDTLS_LIBRARY_ALIGNMENT_H
+      12                 :            : #define MBEDTLS_LIBRARY_ALIGNMENT_H
+      13                 :            : 
+      14                 :            : #include <stdint.h>
+      15                 :            : #include <string.h>
+      16                 :            : #include <stdlib.h>
+      17                 :            : 
+      18                 :            : /*
+      19                 :            :  * Define MBEDTLS_EFFICIENT_UNALIGNED_ACCESS for architectures where unaligned memory
+      20                 :            :  * accesses are known to be efficient.
+      21                 :            :  *
+      22                 :            :  * All functions defined here will behave correctly regardless, but might be less
+      23                 :            :  * efficient when this is not defined.
+      24                 :            :  */
+      25                 :            : #if defined(__ARM_FEATURE_UNALIGNED) \
+      26                 :            :     || defined(MBEDTLS_ARCH_IS_X86) || defined(MBEDTLS_ARCH_IS_X64) \
+      27                 :            :     || defined(MBEDTLS_PLATFORM_IS_WINDOWS_ON_ARM64)
+      28                 :            : /*
+      29                 :            :  * __ARM_FEATURE_UNALIGNED is defined where appropriate by armcc, gcc 7, clang 9
+      30                 :            :  * (and later versions) for Arm v7 and later; all x86 platforms should have
+      31                 :            :  * efficient unaligned access.
+      32                 :            :  *
+      33                 :            :  * https://learn.microsoft.com/en-us/cpp/build/arm64-windows-abi-conventions?view=msvc-170#alignment
+      34                 :            :  * specifies that on Windows-on-Arm64, unaligned access is safe (except for uncached
+      35                 :            :  * device memory).
+      36                 :            :  */
+      37                 :            : #define MBEDTLS_EFFICIENT_UNALIGNED_ACCESS
+      38                 :            : #endif
+      39                 :            : 
+      40                 :            : #if defined(__IAR_SYSTEMS_ICC__) && \
+      41                 :            :     (defined(MBEDTLS_ARCH_IS_ARM64) || defined(MBEDTLS_ARCH_IS_ARM32) \
+      42                 :            :     || defined(__ICCRX__) || defined(__ICCRL78__) || defined(__ICCRISCV__))
+      43                 :            : #pragma language=save
+      44                 :            : #pragma language=extended
+      45                 :            : #define MBEDTLS_POP_IAR_LANGUAGE_PRAGMA
+      46                 :            : /* IAR recommend this technique for accessing unaligned data in
+      47                 :            :  * https://www.iar.com/knowledge/support/technical-notes/compiler/accessing-unaligned-data
+      48                 :            :  * This results in a single load / store instruction (if unaligned access is supported).
+      49                 :            :  * According to that document, this is only supported on certain architectures.
+      50                 :            :  */
+      51                 :            :     #define UINT_UNALIGNED
+      52                 :            : typedef uint16_t __packed mbedtls_uint16_unaligned_t;
+      53                 :            : typedef uint32_t __packed mbedtls_uint32_unaligned_t;
+      54                 :            : typedef uint64_t __packed mbedtls_uint64_unaligned_t;
+      55                 :            : #elif defined(MBEDTLS_COMPILER_IS_GCC) && (MBEDTLS_GCC_VERSION >= 40504) && \
+      56                 :            :     ((MBEDTLS_GCC_VERSION < 60300) || (!defined(MBEDTLS_EFFICIENT_UNALIGNED_ACCESS)))
+      57                 :            : /*
+      58                 :            :  * gcc may generate a branch to memcpy for calls like `memcpy(dest, src, 4)` rather than
+      59                 :            :  * generating some LDR or LDRB instructions (similar for stores).
+      60                 :            :  *
+      61                 :            :  * This is architecture dependent: x86-64 seems fine even with old gcc; 32-bit Arm
+      62                 :            :  * is affected. To keep it simple, we enable for all architectures.
+      63                 :            :  *
+      64                 :            :  * For versions of gcc < 5.4.0 this issue always happens.
+      65                 :            :  * For gcc < 6.3.0, this issue happens at -O0
+      66                 :            :  * For all versions, this issue happens iff unaligned access is not supported.
+      67                 :            :  *
+      68                 :            :  * For gcc 4.x, this implementation will generate byte-by-byte loads even if unaligned access is
+      69                 :            :  * supported, which is correct but not optimal.
+      70                 :            :  *
+      71                 :            :  * For performance (and code size, in some cases), we want to avoid the branch and just generate
+      72                 :            :  * some inline load/store instructions since the access is small and constant-size.
+      73                 :            :  *
+      74                 :            :  * The manual states:
+      75                 :            :  * "The packed attribute specifies that a variable or structure field should have the smallest
+      76                 :            :  *  possible alignment—one byte for a variable"
+      77                 :            :  * https://gcc.gnu.org/onlinedocs/gcc-4.5.4/gcc/Variable-Attributes.html
+      78                 :            :  *
+      79                 :            :  * Previous implementations used __attribute__((__aligned__(1)), but had issues with a gcc bug:
+      80                 :            :  * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94662
+      81                 :            :  *
+      82                 :            :  * Tested with several versions of GCC from 4.5.0 up to 13.2.0
+      83                 :            :  * We don't enable for older than 4.5.0 as this has not been tested.
+      84                 :            :  */
+      85                 :            :  #define UINT_UNALIGNED_STRUCT
+      86                 :            : typedef struct {
+      87                 :            :     uint16_t x;
+      88                 :            : } __attribute__((packed)) mbedtls_uint16_unaligned_t;
+      89                 :            : typedef struct {
+      90                 :            :     uint32_t x;
+      91                 :            : } __attribute__((packed)) mbedtls_uint32_unaligned_t;
+      92                 :            : typedef struct {
+      93                 :            :     uint64_t x;
+      94                 :            : } __attribute__((packed)) mbedtls_uint64_unaligned_t;
+      95                 :            :  #endif
+      96                 :            : 
+      97                 :            : /*
+      98                 :            :  * We try to force mbedtls_(get|put)_unaligned_uintXX to be always inline, because this results
+      99                 :            :  * in code that is both smaller and faster. IAR and gcc both benefit from this when optimising
+     100                 :            :  * for size.
+     101                 :            :  */
+     102                 :            : 
+     103                 :            : /**
+     104                 :            :  * Read the unsigned 16 bits integer from the given address, which need not
+     105                 :            :  * be aligned.
+     106                 :            :  *
+     107                 :            :  * \param   p pointer to 2 bytes of data
+     108                 :            :  * \return  Data at the given address
+     109                 :            :  */
+     110                 :            : #if defined(__IAR_SYSTEMS_ICC__)
+     111                 :            : #pragma inline = forced
+     112                 :            : #elif defined(__GNUC__)
+     113                 :            : __attribute__((always_inline))
+     114                 :            : #endif
+     115                 :            : static inline uint16_t mbedtls_get_unaligned_uint16(const void *p)
+     116                 :            : {
+     117                 :            :     uint16_t r;
+     118                 :            : #if defined(UINT_UNALIGNED)
+     119                 :            :     mbedtls_uint16_unaligned_t *p16 = (mbedtls_uint16_unaligned_t *) p;
+     120                 :            :     r = *p16;
+     121                 :            : #elif defined(UINT_UNALIGNED_STRUCT)
+     122                 :            :     mbedtls_uint16_unaligned_t *p16 = (mbedtls_uint16_unaligned_t *) p;
+     123                 :            :     r = p16->x;
+     124                 :            : #else
+     125                 :          0 :     memcpy(&r, p, sizeof(r));
+     126                 :            : #endif
+     127                 :          0 :     return r;
+     128                 :            : }
+     129                 :            : 
+     130                 :            : /**
+     131                 :            :  * Write the unsigned 16 bits integer to the given address, which need not
+     132                 :            :  * be aligned.
+     133                 :            :  *
+     134                 :            :  * \param   p pointer to 2 bytes of data
+     135                 :            :  * \param   x data to write
+     136                 :            :  */
+     137                 :            : #if defined(__IAR_SYSTEMS_ICC__)
+     138                 :            : #pragma inline = forced
+     139                 :            : #elif defined(__GNUC__)
+     140                 :            : __attribute__((always_inline))
+     141                 :            : #endif
+     142                 :            : static inline void mbedtls_put_unaligned_uint16(void *p, uint16_t x)
+     143                 :            : {
+     144                 :            : #if defined(UINT_UNALIGNED)
+     145                 :            :     mbedtls_uint16_unaligned_t *p16 = (mbedtls_uint16_unaligned_t *) p;
+     146                 :            :     *p16 = x;
+     147                 :            : #elif defined(UINT_UNALIGNED_STRUCT)
+     148                 :            :     mbedtls_uint16_unaligned_t *p16 = (mbedtls_uint16_unaligned_t *) p;
+     149                 :            :     p16->x = x;
+     150                 :            : #else
+     151                 :          0 :     memcpy(p, &x, sizeof(x));
+     152                 :            : #endif
+     153                 :          0 : }
+     154                 :            : 
+     155                 :            : /**
+     156                 :            :  * Read the unsigned 32 bits integer from the given address, which need not
+     157                 :            :  * be aligned.
+     158                 :            :  *
+     159                 :            :  * \param   p pointer to 4 bytes of data
+     160                 :            :  * \return  Data at the given address
+     161                 :            :  */
+     162                 :            : #if defined(__IAR_SYSTEMS_ICC__)
+     163                 :            : #pragma inline = forced
+     164                 :            : #elif defined(__GNUC__)
+     165                 :            : __attribute__((always_inline))
+     166                 :            : #endif
+     167                 :            : static inline uint32_t mbedtls_get_unaligned_uint32(const void *p)
+     168                 :            : {
+     169                 :            :     uint32_t r;
+     170                 :            : #if defined(UINT_UNALIGNED)
+     171                 :            :     mbedtls_uint32_unaligned_t *p32 = (mbedtls_uint32_unaligned_t *) p;
+     172                 :            :     r = *p32;
+     173                 :            : #elif defined(UINT_UNALIGNED_STRUCT)
+     174                 :            :     mbedtls_uint32_unaligned_t *p32 = (mbedtls_uint32_unaligned_t *) p;
+     175                 :            :     r = p32->x;
+     176                 :            : #else
+     177                 :     721368 :     memcpy(&r, p, sizeof(r));
+     178                 :            : #endif
+     179                 :     721368 :     return r;
+     180                 :            : }
+     181                 :            : 
+     182                 :            : /**
+     183                 :            :  * Write the unsigned 32 bits integer to the given address, which need not
+     184                 :            :  * be aligned.
+     185                 :            :  *
+     186                 :            :  * \param   p pointer to 4 bytes of data
+     187                 :            :  * \param   x data to write
+     188                 :            :  */
+     189                 :            : #if defined(__IAR_SYSTEMS_ICC__)
+     190                 :            : #pragma inline = forced
+     191                 :            : #elif defined(__GNUC__)
+     192                 :            : __attribute__((always_inline))
+     193                 :            : #endif
+     194                 :            : static inline void mbedtls_put_unaligned_uint32(void *p, uint32_t x)
+     195                 :            : {
+     196                 :            : #if defined(UINT_UNALIGNED)
+     197                 :            :     mbedtls_uint32_unaligned_t *p32 = (mbedtls_uint32_unaligned_t *) p;
+     198                 :            :     *p32 = x;
+     199                 :            : #elif defined(UINT_UNALIGNED_STRUCT)
+     200                 :            :     mbedtls_uint32_unaligned_t *p32 = (mbedtls_uint32_unaligned_t *) p;
+     201                 :            :     p32->x = x;
+     202                 :            : #else
+     203                 :      77166 :     memcpy(p, &x, sizeof(x));
+     204                 :            : #endif
+     205                 :      77166 : }
+     206                 :            : 
+     207                 :            : /**
+     208                 :            :  * Read the unsigned 64 bits integer from the given address, which need not
+     209                 :            :  * be aligned.
+     210                 :            :  *
+     211                 :            :  * \param   p pointer to 8 bytes of data
+     212                 :            :  * \return  Data at the given address
+     213                 :            :  */
+     214                 :            : #if defined(__IAR_SYSTEMS_ICC__)
+     215                 :            : #pragma inline = forced
+     216                 :            : #elif defined(__GNUC__)
+     217                 :            : __attribute__((always_inline))
+     218                 :            : #endif
+     219                 :            : static inline uint64_t mbedtls_get_unaligned_uint64(const void *p)
+     220                 :            : {
+     221                 :            :     uint64_t r;
+     222                 :            : #if defined(UINT_UNALIGNED)
+     223                 :            :     mbedtls_uint64_unaligned_t *p64 = (mbedtls_uint64_unaligned_t *) p;
+     224                 :            :     r = *p64;
+     225                 :            : #elif defined(UINT_UNALIGNED_STRUCT)
+     226                 :            :     mbedtls_uint64_unaligned_t *p64 = (mbedtls_uint64_unaligned_t *) p;
+     227                 :            :     r = p64->x;
+     228                 :            : #else
+     229                 :    9240936 :     memcpy(&r, p, sizeof(r));
+     230                 :            : #endif
+     231                 :    9240936 :     return r;
+     232                 :            : }
+     233                 :            : 
+     234                 :            : /**
+     235                 :            :  * Write the unsigned 64 bits integer to the given address, which need not
+     236                 :            :  * be aligned.
+     237                 :            :  *
+     238                 :            :  * \param   p pointer to 8 bytes of data
+     239                 :            :  * \param   x data to write
+     240                 :            :  */
+     241                 :            : #if defined(__IAR_SYSTEMS_ICC__)
+     242                 :            : #pragma inline = forced
+     243                 :            : #elif defined(__GNUC__)
+     244                 :            : __attribute__((always_inline))
+     245                 :            : #endif
+     246                 :            : static inline void mbedtls_put_unaligned_uint64(void *p, uint64_t x)
+     247                 :            : {
+     248                 :            : #if defined(UINT_UNALIGNED)
+     249                 :            :     mbedtls_uint64_unaligned_t *p64 = (mbedtls_uint64_unaligned_t *) p;
+     250                 :            :     *p64 = x;
+     251                 :            : #elif defined(UINT_UNALIGNED_STRUCT)
+     252                 :            :     mbedtls_uint64_unaligned_t *p64 = (mbedtls_uint64_unaligned_t *) p;
+     253                 :            :     p64->x = x;
+     254                 :            : #else
+     255                 :    4618376 :     memcpy(p, &x, sizeof(x));
+     256                 :            : #endif
+     257                 :    4618376 : }
+     258                 :            : 
+     259                 :            : #if defined(MBEDTLS_POP_IAR_LANGUAGE_PRAGMA)
+     260                 :            : #pragma language=restore
+     261                 :            : #endif
+     262                 :            : 
+     263                 :            : /** Byte Reading Macros
+     264                 :            :  *
+     265                 :            :  * Given a multi-byte integer \p x, MBEDTLS_BYTE_n retrieves the n-th
+     266                 :            :  * byte from x, where byte 0 is the least significant byte.
+     267                 :            :  */
+     268                 :            : #define MBEDTLS_BYTE_0(x) ((uint8_t) ((x)         & 0xff))
+     269                 :            : #define MBEDTLS_BYTE_1(x) ((uint8_t) (((x) >>  8) & 0xff))
+     270                 :            : #define MBEDTLS_BYTE_2(x) ((uint8_t) (((x) >> 16) & 0xff))
+     271                 :            : #define MBEDTLS_BYTE_3(x) ((uint8_t) (((x) >> 24) & 0xff))
+     272                 :            : #define MBEDTLS_BYTE_4(x) ((uint8_t) (((x) >> 32) & 0xff))
+     273                 :            : #define MBEDTLS_BYTE_5(x) ((uint8_t) (((x) >> 40) & 0xff))
+     274                 :            : #define MBEDTLS_BYTE_6(x) ((uint8_t) (((x) >> 48) & 0xff))
+     275                 :            : #define MBEDTLS_BYTE_7(x) ((uint8_t) (((x) >> 56) & 0xff))
+     276                 :            : 
+     277                 :            : /*
+     278                 :            :  * Detect GCC built-in byteswap routines
+     279                 :            :  */
+     280                 :            : #if defined(__GNUC__) && defined(__GNUC_PREREQ)
+     281                 :            : #if __GNUC_PREREQ(4, 8)
+     282                 :            : #define MBEDTLS_BSWAP16 __builtin_bswap16
+     283                 :            : #endif /* __GNUC_PREREQ(4,8) */
+     284                 :            : #if __GNUC_PREREQ(4, 3)
+     285                 :            : #define MBEDTLS_BSWAP32 __builtin_bswap32
+     286                 :            : #define MBEDTLS_BSWAP64 __builtin_bswap64
+     287                 :            : #endif /* __GNUC_PREREQ(4,3) */
+     288                 :            : #endif /* defined(__GNUC__) && defined(__GNUC_PREREQ) */
+     289                 :            : 
+     290                 :            : /*
+     291                 :            :  * Detect Clang built-in byteswap routines
+     292                 :            :  */
+     293                 :            : #if defined(__clang__) && defined(__has_builtin)
+     294                 :            : #if __has_builtin(__builtin_bswap16) && !defined(MBEDTLS_BSWAP16)
+     295                 :            : #define MBEDTLS_BSWAP16 __builtin_bswap16
+     296                 :            : #endif /* __has_builtin(__builtin_bswap16) */
+     297                 :            : #if __has_builtin(__builtin_bswap32) && !defined(MBEDTLS_BSWAP32)
+     298                 :            : #define MBEDTLS_BSWAP32 __builtin_bswap32
+     299                 :            : #endif /* __has_builtin(__builtin_bswap32) */
+     300                 :            : #if __has_builtin(__builtin_bswap64) && !defined(MBEDTLS_BSWAP64)
+     301                 :            : #define MBEDTLS_BSWAP64 __builtin_bswap64
+     302                 :            : #endif /* __has_builtin(__builtin_bswap64) */
+     303                 :            : #endif /* defined(__clang__) && defined(__has_builtin) */
+     304                 :            : 
+     305                 :            : /*
+     306                 :            :  * Detect MSVC built-in byteswap routines
+     307                 :            :  */
+     308                 :            : #if defined(_MSC_VER)
+     309                 :            : #if !defined(MBEDTLS_BSWAP16)
+     310                 :            : #define MBEDTLS_BSWAP16 _byteswap_ushort
+     311                 :            : #endif
+     312                 :            : #if !defined(MBEDTLS_BSWAP32)
+     313                 :            : #define MBEDTLS_BSWAP32 _byteswap_ulong
+     314                 :            : #endif
+     315                 :            : #if !defined(MBEDTLS_BSWAP64)
+     316                 :            : #define MBEDTLS_BSWAP64 _byteswap_uint64
+     317                 :            : #endif
+     318                 :            : #endif /* defined(_MSC_VER) */
+     319                 :            : 
+     320                 :            : /* Detect armcc built-in byteswap routine */
+     321                 :            : #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 410000) && !defined(MBEDTLS_BSWAP32)
+     322                 :            : #if defined(__ARM_ACLE)  /* ARM Compiler 6 - earlier versions don't need a header */
+     323                 :            : #include <arm_acle.h>
+     324                 :            : #endif
+     325                 :            : #define MBEDTLS_BSWAP32 __rev
+     326                 :            : #endif
+     327                 :            : 
+     328                 :            : /* Detect IAR built-in byteswap routine */
+     329                 :            : #if defined(__IAR_SYSTEMS_ICC__)
+     330                 :            : #if defined(__ARM_ACLE)
+     331                 :            : #include <arm_acle.h>
+     332                 :            : #define MBEDTLS_BSWAP16(x) ((uint16_t) __rev16((uint32_t) (x)))
+     333                 :            : #define MBEDTLS_BSWAP32 __rev
+     334                 :            : #define MBEDTLS_BSWAP64 __revll
+     335                 :            : #endif
+     336                 :            : #endif
+     337                 :            : 
+     338                 :            : /*
+     339                 :            :  * Where compiler built-ins are not present, fall back to C code that the
+     340                 :            :  * compiler may be able to detect and transform into the relevant bswap or
+     341                 :            :  * similar instruction.
+     342                 :            :  */
+     343                 :            : #if !defined(MBEDTLS_BSWAP16)
+     344                 :            : static inline uint16_t mbedtls_bswap16(uint16_t x)
+     345                 :            : {
+     346                 :            :     return
+     347                 :            :         (x & 0x00ff) << 8 |
+     348                 :            :         (x & 0xff00) >> 8;
+     349                 :            : }
+     350                 :            : #define MBEDTLS_BSWAP16 mbedtls_bswap16
+     351                 :            : #endif /* !defined(MBEDTLS_BSWAP16) */
+     352                 :            : 
+     353                 :            : #if !defined(MBEDTLS_BSWAP32)
+     354                 :            : static inline uint32_t mbedtls_bswap32(uint32_t x)
+     355                 :            : {
+     356                 :            :     return
+     357                 :            :         (x & 0x000000ff) << 24 |
+     358                 :            :         (x & 0x0000ff00) <<  8 |
+     359                 :            :         (x & 0x00ff0000) >>  8 |
+     360                 :            :         (x & 0xff000000) >> 24;
+     361                 :            : }
+     362                 :            : #define MBEDTLS_BSWAP32 mbedtls_bswap32
+     363                 :            : #endif /* !defined(MBEDTLS_BSWAP32) */
+     364                 :            : 
+     365                 :            : #if !defined(MBEDTLS_BSWAP64)
+     366                 :            : static inline uint64_t mbedtls_bswap64(uint64_t x)
+     367                 :            : {
+     368                 :            :     return
+     369                 :            :         (x & 0x00000000000000ffULL) << 56 |
+     370                 :            :         (x & 0x000000000000ff00ULL) << 40 |
+     371                 :            :         (x & 0x0000000000ff0000ULL) << 24 |
+     372                 :            :         (x & 0x00000000ff000000ULL) <<  8 |
+     373                 :            :         (x & 0x000000ff00000000ULL) >>  8 |
+     374                 :            :         (x & 0x0000ff0000000000ULL) >> 24 |
+     375                 :            :         (x & 0x00ff000000000000ULL) >> 40 |
+     376                 :            :         (x & 0xff00000000000000ULL) >> 56;
+     377                 :            : }
+     378                 :            : #define MBEDTLS_BSWAP64 mbedtls_bswap64
+     379                 :            : #endif /* !defined(MBEDTLS_BSWAP64) */
+     380                 :            : 
+     381                 :            : #if !defined(__BYTE_ORDER__)
+     382                 :            : 
+     383                 :            : #if defined(__LITTLE_ENDIAN__)
+     384                 :            : /* IAR defines __xxx_ENDIAN__, but not __BYTE_ORDER__ */
+     385                 :            : #define MBEDTLS_IS_BIG_ENDIAN 0
+     386                 :            : #elif defined(__BIG_ENDIAN__)
+     387                 :            : #define MBEDTLS_IS_BIG_ENDIAN 1
+     388                 :            : #else
+     389                 :            : static const uint16_t mbedtls_byte_order_detector = { 0x100 };
+     390                 :            : #define MBEDTLS_IS_BIG_ENDIAN (*((unsigned char *) (&mbedtls_byte_order_detector)) == 0x01)
+     391                 :            : #endif
+     392                 :            : 
+     393                 :            : #else
+     394                 :            : 
+     395                 :            : #if (__BYTE_ORDER__) == (__ORDER_BIG_ENDIAN__)
+     396                 :            : #define MBEDTLS_IS_BIG_ENDIAN 1
+     397                 :            : #else
+     398                 :            : #define MBEDTLS_IS_BIG_ENDIAN 0
+     399                 :            : #endif
+     400                 :            : 
+     401                 :            : #endif /* !defined(__BYTE_ORDER__) */
+     402                 :            : 
+     403                 :            : /**
+     404                 :            :  * Get the unsigned 32 bits integer corresponding to four bytes in
+     405                 :            :  * big-endian order (MSB first).
+     406                 :            :  *
+     407                 :            :  * \param   data    Base address of the memory to get the four bytes from.
+     408                 :            :  * \param   offset  Offset from \p data of the first and most significant
+     409                 :            :  *                  byte of the four bytes to build the 32 bits unsigned
+     410                 :            :  *                  integer from.
+     411                 :            :  */
+     412                 :            : #define MBEDTLS_GET_UINT32_BE(data, offset)                                \
+     413                 :            :     ((MBEDTLS_IS_BIG_ENDIAN)                                               \
+     414                 :            :         ? mbedtls_get_unaligned_uint32((data) + (offset))                  \
+     415                 :            :         : MBEDTLS_BSWAP32(mbedtls_get_unaligned_uint32((data) + (offset))) \
+     416                 :            :     )
+     417                 :            : 
+     418                 :            : /**
+     419                 :            :  * Put in memory a 32 bits unsigned integer in big-endian order.
+     420                 :            :  *
+     421                 :            :  * \param   n       32 bits unsigned integer to put in memory.
+     422                 :            :  * \param   data    Base address of the memory where to put the 32
+     423                 :            :  *                  bits unsigned integer in.
+     424                 :            :  * \param   offset  Offset from \p data where to put the most significant
+     425                 :            :  *                  byte of the 32 bits unsigned integer \p n.
+     426                 :            :  */
+     427                 :            : #define MBEDTLS_PUT_UINT32_BE(n, data, offset)                                   \
+     428                 :            :     {                                                                            \
+     429                 :            :         if (MBEDTLS_IS_BIG_ENDIAN)                                               \
+     430                 :            :         {                                                                        \
+     431                 :            :             mbedtls_put_unaligned_uint32((data) + (offset), (uint32_t) (n));     \
+     432                 :            :         }                                                                        \
+     433                 :            :         else                                                                     \
+     434                 :            :         {                                                                        \
+     435                 :            :             mbedtls_put_unaligned_uint32((data) + (offset), MBEDTLS_BSWAP32((uint32_t) (n))); \
+     436                 :            :         }                                                                        \
+     437                 :            :     }
+     438                 :            : 
+     439                 :            : /**
+     440                 :            :  * Get the unsigned 32 bits integer corresponding to four bytes in
+     441                 :            :  * little-endian order (LSB first).
+     442                 :            :  *
+     443                 :            :  * \param   data    Base address of the memory to get the four bytes from.
+     444                 :            :  * \param   offset  Offset from \p data of the first and least significant
+     445                 :            :  *                  byte of the four bytes to build the 32 bits unsigned
+     446                 :            :  *                  integer from.
+     447                 :            :  */
+     448                 :            : #define MBEDTLS_GET_UINT32_LE(data, offset)                                \
+     449                 :            :     ((MBEDTLS_IS_BIG_ENDIAN)                                               \
+     450                 :            :         ? MBEDTLS_BSWAP32(mbedtls_get_unaligned_uint32((data) + (offset))) \
+     451                 :            :         : mbedtls_get_unaligned_uint32((data) + (offset))                  \
+     452                 :            :     )
+     453                 :            : 
+     454                 :            : 
+     455                 :            : /**
+     456                 :            :  * Put in memory a 32 bits unsigned integer in little-endian order.
+     457                 :            :  *
+     458                 :            :  * \param   n       32 bits unsigned integer to put in memory.
+     459                 :            :  * \param   data    Base address of the memory where to put the 32
+     460                 :            :  *                  bits unsigned integer in.
+     461                 :            :  * \param   offset  Offset from \p data where to put the least significant
+     462                 :            :  *                  byte of the 32 bits unsigned integer \p n.
+     463                 :            :  */
+     464                 :            : #define MBEDTLS_PUT_UINT32_LE(n, data, offset)                                   \
+     465                 :            :     {                                                                            \
+     466                 :            :         if (MBEDTLS_IS_BIG_ENDIAN)                                               \
+     467                 :            :         {                                                                        \
+     468                 :            :             mbedtls_put_unaligned_uint32((data) + (offset), MBEDTLS_BSWAP32((uint32_t) (n))); \
+     469                 :            :         }                                                                        \
+     470                 :            :         else                                                                     \
+     471                 :            :         {                                                                        \
+     472                 :            :             mbedtls_put_unaligned_uint32((data) + (offset), ((uint32_t) (n)));   \
+     473                 :            :         }                                                                        \
+     474                 :            :     }
+     475                 :            : 
+     476                 :            : /**
+     477                 :            :  * Get the unsigned 16 bits integer corresponding to two bytes in
+     478                 :            :  * little-endian order (LSB first).
+     479                 :            :  *
+     480                 :            :  * \param   data    Base address of the memory to get the two bytes from.
+     481                 :            :  * \param   offset  Offset from \p data of the first and least significant
+     482                 :            :  *                  byte of the two bytes to build the 16 bits unsigned
+     483                 :            :  *                  integer from.
+     484                 :            :  */
+     485                 :            : #define MBEDTLS_GET_UINT16_LE(data, offset)                                \
+     486                 :            :     ((MBEDTLS_IS_BIG_ENDIAN)                                               \
+     487                 :            :         ? MBEDTLS_BSWAP16(mbedtls_get_unaligned_uint16((data) + (offset))) \
+     488                 :            :         : mbedtls_get_unaligned_uint16((data) + (offset))                  \
+     489                 :            :     )
+     490                 :            : 
+     491                 :            : /**
+     492                 :            :  * Put in memory a 16 bits unsigned integer in little-endian order.
+     493                 :            :  *
+     494                 :            :  * \param   n       16 bits unsigned integer to put in memory.
+     495                 :            :  * \param   data    Base address of the memory where to put the 16
+     496                 :            :  *                  bits unsigned integer in.
+     497                 :            :  * \param   offset  Offset from \p data where to put the least significant
+     498                 :            :  *                  byte of the 16 bits unsigned integer \p n.
+     499                 :            :  */
+     500                 :            : #define MBEDTLS_PUT_UINT16_LE(n, data, offset)                                   \
+     501                 :            :     {                                                                            \
+     502                 :            :         if (MBEDTLS_IS_BIG_ENDIAN)                                               \
+     503                 :            :         {                                                                        \
+     504                 :            :             mbedtls_put_unaligned_uint16((data) + (offset), MBEDTLS_BSWAP16((uint16_t) (n))); \
+     505                 :            :         }                                                                        \
+     506                 :            :         else                                                                     \
+     507                 :            :         {                                                                        \
+     508                 :            :             mbedtls_put_unaligned_uint16((data) + (offset), (uint16_t) (n));     \
+     509                 :            :         }                                                                        \
+     510                 :            :     }
+     511                 :            : 
+     512                 :            : /**
+     513                 :            :  * Get the unsigned 16 bits integer corresponding to two bytes in
+     514                 :            :  * big-endian order (MSB first).
+     515                 :            :  *
+     516                 :            :  * \param   data    Base address of the memory to get the two bytes from.
+     517                 :            :  * \param   offset  Offset from \p data of the first and most significant
+     518                 :            :  *                  byte of the two bytes to build the 16 bits unsigned
+     519                 :            :  *                  integer from.
+     520                 :            :  */
+     521                 :            : #define MBEDTLS_GET_UINT16_BE(data, offset)                                \
+     522                 :            :     ((MBEDTLS_IS_BIG_ENDIAN)                                               \
+     523                 :            :         ? mbedtls_get_unaligned_uint16((data) + (offset))                  \
+     524                 :            :         : MBEDTLS_BSWAP16(mbedtls_get_unaligned_uint16((data) + (offset))) \
+     525                 :            :     )
+     526                 :            : 
+     527                 :            : /**
+     528                 :            :  * Put in memory a 16 bits unsigned integer in big-endian order.
+     529                 :            :  *
+     530                 :            :  * \param   n       16 bits unsigned integer to put in memory.
+     531                 :            :  * \param   data    Base address of the memory where to put the 16
+     532                 :            :  *                  bits unsigned integer in.
+     533                 :            :  * \param   offset  Offset from \p data where to put the most significant
+     534                 :            :  *                  byte of the 16 bits unsigned integer \p n.
+     535                 :            :  */
+     536                 :            : #define MBEDTLS_PUT_UINT16_BE(n, data, offset)                                   \
+     537                 :            :     {                                                                            \
+     538                 :            :         if (MBEDTLS_IS_BIG_ENDIAN)                                               \
+     539                 :            :         {                                                                        \
+     540                 :            :             mbedtls_put_unaligned_uint16((data) + (offset), (uint16_t) (n));     \
+     541                 :            :         }                                                                        \
+     542                 :            :         else                                                                     \
+     543                 :            :         {                                                                        \
+     544                 :            :             mbedtls_put_unaligned_uint16((data) + (offset), MBEDTLS_BSWAP16((uint16_t) (n))); \
+     545                 :            :         }                                                                        \
+     546                 :            :     }
+     547                 :            : 
+     548                 :            : /**
+     549                 :            :  * Get the unsigned 24 bits integer corresponding to three bytes in
+     550                 :            :  * big-endian order (MSB first).
+     551                 :            :  *
+     552                 :            :  * \param   data    Base address of the memory to get the three bytes from.
+     553                 :            :  * \param   offset  Offset from \p data of the first and most significant
+     554                 :            :  *                  byte of the three bytes to build the 24 bits unsigned
+     555                 :            :  *                  integer from.
+     556                 :            :  */
+     557                 :            : #define MBEDTLS_GET_UINT24_BE(data, offset)        \
+     558                 :            :     (                                              \
+     559                 :            :         ((uint32_t) (data)[(offset)] << 16)        \
+     560                 :            :         | ((uint32_t) (data)[(offset) + 1] << 8)   \
+     561                 :            :         | ((uint32_t) (data)[(offset) + 2])        \
+     562                 :            :     )
+     563                 :            : 
+     564                 :            : /**
+     565                 :            :  * Put in memory a 24 bits unsigned integer in big-endian order.
+     566                 :            :  *
+     567                 :            :  * \param   n       24 bits unsigned integer to put in memory.
+     568                 :            :  * \param   data    Base address of the memory where to put the 24
+     569                 :            :  *                  bits unsigned integer in.
+     570                 :            :  * \param   offset  Offset from \p data where to put the most significant
+     571                 :            :  *                  byte of the 24 bits unsigned integer \p n.
+     572                 :            :  */
+     573                 :            : #define MBEDTLS_PUT_UINT24_BE(n, data, offset)                \
+     574                 :            :     {                                                         \
+     575                 :            :         (data)[(offset)] = MBEDTLS_BYTE_2(n);                 \
+     576                 :            :         (data)[(offset) + 1] = MBEDTLS_BYTE_1(n);             \
+     577                 :            :         (data)[(offset) + 2] = MBEDTLS_BYTE_0(n);             \
+     578                 :            :     }
+     579                 :            : 
+     580                 :            : /**
+     581                 :            :  * Get the unsigned 24 bits integer corresponding to three bytes in
+     582                 :            :  * little-endian order (LSB first).
+     583                 :            :  *
+     584                 :            :  * \param   data    Base address of the memory to get the three bytes from.
+     585                 :            :  * \param   offset  Offset from \p data of the first and least significant
+     586                 :            :  *                  byte of the three bytes to build the 24 bits unsigned
+     587                 :            :  *                  integer from.
+     588                 :            :  */
+     589                 :            : #define MBEDTLS_GET_UINT24_LE(data, offset)               \
+     590                 :            :     (                                                     \
+     591                 :            :         ((uint32_t) (data)[(offset)])                     \
+     592                 :            :         | ((uint32_t) (data)[(offset) + 1] <<  8)         \
+     593                 :            :         | ((uint32_t) (data)[(offset) + 2] << 16)         \
+     594                 :            :     )
+     595                 :            : 
+     596                 :            : /**
+     597                 :            :  * Put in memory a 24 bits unsigned integer in little-endian order.
+     598                 :            :  *
+     599                 :            :  * \param   n       24 bits unsigned integer to put in memory.
+     600                 :            :  * \param   data    Base address of the memory where to put the 24
+     601                 :            :  *                  bits unsigned integer in.
+     602                 :            :  * \param   offset  Offset from \p data where to put the least significant
+     603                 :            :  *                  byte of the 24 bits unsigned integer \p n.
+     604                 :            :  */
+     605                 :            : #define MBEDTLS_PUT_UINT24_LE(n, data, offset)                \
+     606                 :            :     {                                                         \
+     607                 :            :         (data)[(offset)] = MBEDTLS_BYTE_0(n);                 \
+     608                 :            :         (data)[(offset) + 1] = MBEDTLS_BYTE_1(n);             \
+     609                 :            :         (data)[(offset) + 2] = MBEDTLS_BYTE_2(n);             \
+     610                 :            :     }
+     611                 :            : 
+     612                 :            : /**
+     613                 :            :  * Get the unsigned 64 bits integer corresponding to eight bytes in
+     614                 :            :  * big-endian order (MSB first).
+     615                 :            :  *
+     616                 :            :  * \param   data    Base address of the memory to get the eight bytes from.
+     617                 :            :  * \param   offset  Offset from \p data of the first and most significant
+     618                 :            :  *                  byte of the eight bytes to build the 64 bits unsigned
+     619                 :            :  *                  integer from.
+     620                 :            :  */
+     621                 :            : #define MBEDTLS_GET_UINT64_BE(data, offset)                                \
+     622                 :            :     ((MBEDTLS_IS_BIG_ENDIAN)                                               \
+     623                 :            :         ? mbedtls_get_unaligned_uint64((data) + (offset))                  \
+     624                 :            :         : MBEDTLS_BSWAP64(mbedtls_get_unaligned_uint64((data) + (offset))) \
+     625                 :            :     )
+     626                 :            : 
+     627                 :            : /**
+     628                 :            :  * Put in memory a 64 bits unsigned integer in big-endian order.
+     629                 :            :  *
+     630                 :            :  * \param   n       64 bits unsigned integer to put in memory.
+     631                 :            :  * \param   data    Base address of the memory where to put the 64
+     632                 :            :  *                  bits unsigned integer in.
+     633                 :            :  * \param   offset  Offset from \p data where to put the most significant
+     634                 :            :  *                  byte of the 64 bits unsigned integer \p n.
+     635                 :            :  */
+     636                 :            : #define MBEDTLS_PUT_UINT64_BE(n, data, offset)                                   \
+     637                 :            :     {                                                                            \
+     638                 :            :         if (MBEDTLS_IS_BIG_ENDIAN)                                               \
+     639                 :            :         {                                                                        \
+     640                 :            :             mbedtls_put_unaligned_uint64((data) + (offset), (uint64_t) (n));     \
+     641                 :            :         }                                                                        \
+     642                 :            :         else                                                                     \
+     643                 :            :         {                                                                        \
+     644                 :            :             mbedtls_put_unaligned_uint64((data) + (offset), MBEDTLS_BSWAP64((uint64_t) (n))); \
+     645                 :            :         }                                                                        \
+     646                 :            :     }
+     647                 :            : 
+     648                 :            : /**
+     649                 :            :  * Get the unsigned 64 bits integer corresponding to eight bytes in
+     650                 :            :  * little-endian order (LSB first).
+     651                 :            :  *
+     652                 :            :  * \param   data    Base address of the memory to get the eight bytes from.
+     653                 :            :  * \param   offset  Offset from \p data of the first and least significant
+     654                 :            :  *                  byte of the eight bytes to build the 64 bits unsigned
+     655                 :            :  *                  integer from.
+     656                 :            :  */
+     657                 :            : #define MBEDTLS_GET_UINT64_LE(data, offset)                                \
+     658                 :            :     ((MBEDTLS_IS_BIG_ENDIAN)                                               \
+     659                 :            :         ? MBEDTLS_BSWAP64(mbedtls_get_unaligned_uint64((data) + (offset))) \
+     660                 :            :         : mbedtls_get_unaligned_uint64((data) + (offset))                  \
+     661                 :            :     )
+     662                 :            : 
+     663                 :            : /**
+     664                 :            :  * Put in memory a 64 bits unsigned integer in little-endian order.
+     665                 :            :  *
+     666                 :            :  * \param   n       64 bits unsigned integer to put in memory.
+     667                 :            :  * \param   data    Base address of the memory where to put the 64
+     668                 :            :  *                  bits unsigned integer in.
+     669                 :            :  * \param   offset  Offset from \p data where to put the least significant
+     670                 :            :  *                  byte of the 64 bits unsigned integer \p n.
+     671                 :            :  */
+     672                 :            : #define MBEDTLS_PUT_UINT64_LE(n, data, offset)                                   \
+     673                 :            :     {                                                                            \
+     674                 :            :         if (MBEDTLS_IS_BIG_ENDIAN)                                               \
+     675                 :            :         {                                                                        \
+     676                 :            :             mbedtls_put_unaligned_uint64((data) + (offset), MBEDTLS_BSWAP64((uint64_t) (n))); \
+     677                 :            :         }                                                                        \
+     678                 :            :         else                                                                     \
+     679                 :            :         {                                                                        \
+     680                 :            :             mbedtls_put_unaligned_uint64((data) + (offset), (uint64_t) (n));     \
+     681                 :            :         }                                                                        \
+     682                 :            :     }
+     683                 :            : 
+     684                 :            : #endif /* MBEDTLS_LIBRARY_ALIGNMENT_H */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/aria.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/aria.c.func-sort-c.html new file mode 100644 index 00000000000..3c65f7e86ef --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/aria.c.func-sort-c.html @@ -0,0 +1,137 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/aria.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - aria.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:02910.0 %
Date:2024-09-22 08:21:07Functions:0140.0 %
Branches:01500.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
aria_a0
aria_fe_xor0
aria_fo_xor0
aria_rot1280
aria_sl0
mbedtls_aria_crypt_cbc0
mbedtls_aria_crypt_cfb1280
mbedtls_aria_crypt_ctr0
mbedtls_aria_crypt_ecb0
mbedtls_aria_free0
mbedtls_aria_init0
mbedtls_aria_self_test0
mbedtls_aria_setkey_dec0
mbedtls_aria_setkey_enc0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/aria.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/aria.c.func.html new file mode 100644 index 00000000000..d3f2497e0cd --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/aria.c.func.html @@ -0,0 +1,137 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/aria.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - aria.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:02910.0 %
Date:2024-09-22 08:21:07Functions:0140.0 %
Branches:01500.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
aria_a0
aria_fe_xor0
aria_fo_xor0
aria_rot1280
aria_sl0
mbedtls_aria_crypt_cbc0
mbedtls_aria_crypt_cfb1280
mbedtls_aria_crypt_ctr0
mbedtls_aria_crypt_ecb0
mbedtls_aria_free0
mbedtls_aria_init0
mbedtls_aria_self_test0
mbedtls_aria_setkey_dec0
mbedtls_aria_setkey_enc0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/aria.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/aria.c.gcov.html new file mode 100644 index 00000000000..990ffc5ea42 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/aria.c.gcov.html @@ -0,0 +1,1063 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/aria.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - aria.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:02910.0 %
Date:2024-09-22 08:21:07Functions:0140.0 %
Branches:01500.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  *  ARIA implementation
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  */
+       7                 :            : 
+       8                 :            : /*
+       9                 :            :  * This implementation is based on the following standards:
+      10                 :            :  * [1] http://210.104.33.10/ARIA/doc/ARIA-specification-e.pdf
+      11                 :            :  * [2] https://tools.ietf.org/html/rfc5794
+      12                 :            :  */
+      13                 :            : 
+      14                 :            : #include "common.h"
+      15                 :            : 
+      16                 :            : #if defined(MBEDTLS_ARIA_C)
+      17                 :            : 
+      18                 :            : #include "mbedtls/aria.h"
+      19                 :            : 
+      20                 :            : #include <string.h>
+      21                 :            : 
+      22                 :            : #include "mbedtls/platform.h"
+      23                 :            : 
+      24                 :            : #if !defined(MBEDTLS_ARIA_ALT)
+      25                 :            : 
+      26                 :            : #include "mbedtls/platform_util.h"
+      27                 :            : 
+      28                 :            : /*
+      29                 :            :  * modify byte order: ( A B C D ) -> ( B A D C ), i.e. swap pairs of bytes
+      30                 :            :  *
+      31                 :            :  * This is submatrix P1 in [1] Appendix B.1
+      32                 :            :  *
+      33                 :            :  * Common compilers fail to translate this to minimal number of instructions,
+      34                 :            :  * so let's provide asm versions for common platforms with C fallback.
+      35                 :            :  */
+      36                 :            : #if defined(MBEDTLS_HAVE_ASM)
+      37                 :            : #if defined(__arm__) /* rev16 available from v6 up */
+      38                 :            : /* armcc5 --gnu defines __GNUC__ but doesn't support GNU's extended asm */
+      39                 :            : #if defined(__GNUC__) && \
+      40                 :            :     (!defined(__ARMCC_VERSION) || __ARMCC_VERSION >= 6000000) && \
+      41                 :            :     __ARM_ARCH >= 6
+      42                 :            : static inline uint32_t aria_p1(uint32_t x)
+      43                 :            : {
+      44                 :            :     uint32_t r;
+      45                 :            :     __asm("rev16 %0, %1" : "=l" (r) : "l" (x));
+      46                 :            :     return r;
+      47                 :            : }
+      48                 :            : #define ARIA_P1 aria_p1
+      49                 :            : #elif defined(__ARMCC_VERSION) && __ARMCC_VERSION < 6000000 && \
+      50                 :            :     (__TARGET_ARCH_ARM >= 6 || __TARGET_ARCH_THUMB >= 3)
+      51                 :            : static inline uint32_t aria_p1(uint32_t x)
+      52                 :            : {
+      53                 :            :     uint32_t r;
+      54                 :            :     __asm("rev16 r, x");
+      55                 :            :     return r;
+      56                 :            : }
+      57                 :            : #define ARIA_P1 aria_p1
+      58                 :            : #endif
+      59                 :            : #endif /* arm */
+      60                 :            : #if defined(__GNUC__) && \
+      61                 :            :     defined(__i386__) || defined(__amd64__) || defined(__x86_64__)
+      62                 :            : /* I couldn't find an Intel equivalent of rev16, so two instructions */
+      63                 :            : #define ARIA_P1(x) ARIA_P2(ARIA_P3(x))
+      64                 :            : #endif /* x86 gnuc */
+      65                 :            : #endif /* MBEDTLS_HAVE_ASM && GNUC */
+      66                 :            : #if !defined(ARIA_P1)
+      67                 :            : #define ARIA_P1(x) ((((x) >> 8) & 0x00FF00FF) ^ (((x) & 0x00FF00FF) << 8))
+      68                 :            : #endif
+      69                 :            : 
+      70                 :            : /*
+      71                 :            :  * modify byte order: ( A B C D ) -> ( C D A B ), i.e. rotate by 16 bits
+      72                 :            :  *
+      73                 :            :  * This is submatrix P2 in [1] Appendix B.1
+      74                 :            :  *
+      75                 :            :  * Common compilers will translate this to a single instruction.
+      76                 :            :  */
+      77                 :            : #define ARIA_P2(x) (((x) >> 16) ^ ((x) << 16))
+      78                 :            : 
+      79                 :            : /*
+      80                 :            :  * modify byte order: ( A B C D ) -> ( D C B A ), i.e. change endianness
+      81                 :            :  *
+      82                 :            :  * This is submatrix P3 in [1] Appendix B.1
+      83                 :            :  */
+      84                 :            : #define ARIA_P3(x) MBEDTLS_BSWAP32(x)
+      85                 :            : 
+      86                 :            : /*
+      87                 :            :  * ARIA Affine Transform
+      88                 :            :  * (a, b, c, d) = state in/out
+      89                 :            :  *
+      90                 :            :  * If we denote the first byte of input by 0, ..., the last byte by f,
+      91                 :            :  * then inputs are: a = 0123, b = 4567, c = 89ab, d = cdef.
+      92                 :            :  *
+      93                 :            :  * Reading [1] 2.4 or [2] 2.4.3 in columns and performing simple
+      94                 :            :  * rearrangements on adjacent pairs, output is:
+      95                 :            :  *
+      96                 :            :  * a = 3210 + 4545 + 6767 + 88aa + 99bb + dccd + effe
+      97                 :            :  *   = 3210 + 4567 + 6745 + 89ab + 98ba + dcfe + efcd
+      98                 :            :  * b = 0101 + 2323 + 5476 + 8998 + baab + eecc + ffdd
+      99                 :            :  *   = 0123 + 2301 + 5476 + 89ab + ba98 + efcd + fedc
+     100                 :            :  * c = 0022 + 1133 + 4554 + 7667 + ab89 + dcdc + fefe
+     101                 :            :  *   = 0123 + 1032 + 4567 + 7654 + ab89 + dcfe + fedc
+     102                 :            :  * d = 1001 + 2332 + 6644 + 7755 + 9898 + baba + cdef
+     103                 :            :  *   = 1032 + 2301 + 6745 + 7654 + 98ba + ba98 + cdef
+     104                 :            :  *
+     105                 :            :  * Note: another presentation of the A transform can be found as the first
+     106                 :            :  * half of App. B.1 in [1] in terms of 4-byte operators P1, P2, P3 and P4.
+     107                 :            :  * The implementation below uses only P1 and P2 as they are sufficient.
+     108                 :            :  */
+     109                 :          0 : static inline void aria_a(uint32_t *a, uint32_t *b,
+     110                 :            :                           uint32_t *c, uint32_t *d)
+     111                 :            : {
+     112                 :            :     uint32_t ta, tb, tc;
+     113                 :          0 :     ta  =  *b;                      // 4567
+     114                 :          0 :     *b  =  *a;                      // 0123
+     115                 :          0 :     *a  =  ARIA_P2(ta);             // 6745
+     116                 :          0 :     tb  =  ARIA_P2(*d);             // efcd
+     117                 :          0 :     *d  =  ARIA_P1(*c);             // 98ba
+     118                 :          0 :     *c  =  ARIA_P1(tb);             // fedc
+     119                 :          0 :     ta  ^= *d;                      // 4567+98ba
+     120                 :          0 :     tc  =  ARIA_P2(*b);             // 2301
+     121                 :          0 :     ta  =  ARIA_P1(ta) ^ tc ^ *c;   // 2301+5476+89ab+fedc
+     122                 :          0 :     tb  ^= ARIA_P2(*d);             // ba98+efcd
+     123                 :          0 :     tc  ^= ARIA_P1(*a);             // 2301+7654
+     124                 :          0 :     *b  ^= ta ^ tb;                 // 0123+2301+5476+89ab+ba98+efcd+fedc OUT
+     125                 :          0 :     tb  =  ARIA_P2(tb) ^ ta;        // 2301+5476+89ab+98ba+cdef+fedc
+     126                 :          0 :     *a  ^= ARIA_P1(tb);             // 3210+4567+6745+89ab+98ba+dcfe+efcd OUT
+     127                 :          0 :     ta  =  ARIA_P2(ta);             // 0123+7654+ab89+dcfe
+     128                 :          0 :     *d  ^= ARIA_P1(ta) ^ tc;        // 1032+2301+6745+7654+98ba+ba98+cdef OUT
+     129                 :          0 :     tc  =  ARIA_P2(tc);             // 0123+5476
+     130                 :          0 :     *c  ^= ARIA_P1(tc) ^ ta;        // 0123+1032+4567+7654+ab89+dcfe+fedc OUT
+     131                 :          0 : }
+     132                 :            : 
+     133                 :            : /*
+     134                 :            :  * ARIA Substitution Layer SL1 / SL2
+     135                 :            :  * (a, b, c, d) = state in/out
+     136                 :            :  * (sa, sb, sc, sd) = 256 8-bit S-Boxes (see below)
+     137                 :            :  *
+     138                 :            :  * By passing sb1, sb2, is1, is2 as S-Boxes you get SL1
+     139                 :            :  * By passing is1, is2, sb1, sb2 as S-Boxes you get SL2
+     140                 :            :  */
+     141                 :          0 : static inline void aria_sl(uint32_t *a, uint32_t *b,
+     142                 :            :                            uint32_t *c, uint32_t *d,
+     143                 :            :                            const uint8_t sa[256], const uint8_t sb[256],
+     144                 :            :                            const uint8_t sc[256], const uint8_t sd[256])
+     145                 :            : {
+     146                 :          0 :     *a = ((uint32_t) sa[MBEDTLS_BYTE_0(*a)]) ^
+     147                 :          0 :          (((uint32_t) sb[MBEDTLS_BYTE_1(*a)]) <<  8) ^
+     148                 :          0 :          (((uint32_t) sc[MBEDTLS_BYTE_2(*a)]) << 16) ^
+     149                 :          0 :          (((uint32_t) sd[MBEDTLS_BYTE_3(*a)]) << 24);
+     150                 :          0 :     *b = ((uint32_t) sa[MBEDTLS_BYTE_0(*b)]) ^
+     151                 :          0 :          (((uint32_t) sb[MBEDTLS_BYTE_1(*b)]) <<  8) ^
+     152                 :          0 :          (((uint32_t) sc[MBEDTLS_BYTE_2(*b)]) << 16) ^
+     153                 :          0 :          (((uint32_t) sd[MBEDTLS_BYTE_3(*b)]) << 24);
+     154                 :          0 :     *c = ((uint32_t) sa[MBEDTLS_BYTE_0(*c)]) ^
+     155                 :          0 :          (((uint32_t) sb[MBEDTLS_BYTE_1(*c)]) <<  8) ^
+     156                 :          0 :          (((uint32_t) sc[MBEDTLS_BYTE_2(*c)]) << 16) ^
+     157                 :          0 :          (((uint32_t) sd[MBEDTLS_BYTE_3(*c)]) << 24);
+     158                 :          0 :     *d = ((uint32_t) sa[MBEDTLS_BYTE_0(*d)]) ^
+     159                 :          0 :          (((uint32_t) sb[MBEDTLS_BYTE_1(*d)]) <<  8) ^
+     160                 :          0 :          (((uint32_t) sc[MBEDTLS_BYTE_2(*d)]) << 16) ^
+     161                 :          0 :          (((uint32_t) sd[MBEDTLS_BYTE_3(*d)]) << 24);
+     162                 :          0 : }
+     163                 :            : 
+     164                 :            : /*
+     165                 :            :  * S-Boxes
+     166                 :            :  */
+     167                 :            : static const uint8_t aria_sb1[256] =
+     168                 :            : {
+     169                 :            :     0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5, 0x30, 0x01, 0x67, 0x2B,
+     170                 :            :     0xFE, 0xD7, 0xAB, 0x76, 0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0,
+     171                 :            :     0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0, 0xB7, 0xFD, 0x93, 0x26,
+     172                 :            :     0x36, 0x3F, 0xF7, 0xCC, 0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15,
+     173                 :            :     0x04, 0xC7, 0x23, 0xC3, 0x18, 0x96, 0x05, 0x9A, 0x07, 0x12, 0x80, 0xE2,
+     174                 :            :     0xEB, 0x27, 0xB2, 0x75, 0x09, 0x83, 0x2C, 0x1A, 0x1B, 0x6E, 0x5A, 0xA0,
+     175                 :            :     0x52, 0x3B, 0xD6, 0xB3, 0x29, 0xE3, 0x2F, 0x84, 0x53, 0xD1, 0x00, 0xED,
+     176                 :            :     0x20, 0xFC, 0xB1, 0x5B, 0x6A, 0xCB, 0xBE, 0x39, 0x4A, 0x4C, 0x58, 0xCF,
+     177                 :            :     0xD0, 0xEF, 0xAA, 0xFB, 0x43, 0x4D, 0x33, 0x85, 0x45, 0xF9, 0x02, 0x7F,
+     178                 :            :     0x50, 0x3C, 0x9F, 0xA8, 0x51, 0xA3, 0x40, 0x8F, 0x92, 0x9D, 0x38, 0xF5,
+     179                 :            :     0xBC, 0xB6, 0xDA, 0x21, 0x10, 0xFF, 0xF3, 0xD2, 0xCD, 0x0C, 0x13, 0xEC,
+     180                 :            :     0x5F, 0x97, 0x44, 0x17, 0xC4, 0xA7, 0x7E, 0x3D, 0x64, 0x5D, 0x19, 0x73,
+     181                 :            :     0x60, 0x81, 0x4F, 0xDC, 0x22, 0x2A, 0x90, 0x88, 0x46, 0xEE, 0xB8, 0x14,
+     182                 :            :     0xDE, 0x5E, 0x0B, 0xDB, 0xE0, 0x32, 0x3A, 0x0A, 0x49, 0x06, 0x24, 0x5C,
+     183                 :            :     0xC2, 0xD3, 0xAC, 0x62, 0x91, 0x95, 0xE4, 0x79, 0xE7, 0xC8, 0x37, 0x6D,
+     184                 :            :     0x8D, 0xD5, 0x4E, 0xA9, 0x6C, 0x56, 0xF4, 0xEA, 0x65, 0x7A, 0xAE, 0x08,
+     185                 :            :     0xBA, 0x78, 0x25, 0x2E, 0x1C, 0xA6, 0xB4, 0xC6, 0xE8, 0xDD, 0x74, 0x1F,
+     186                 :            :     0x4B, 0xBD, 0x8B, 0x8A, 0x70, 0x3E, 0xB5, 0x66, 0x48, 0x03, 0xF6, 0x0E,
+     187                 :            :     0x61, 0x35, 0x57, 0xB9, 0x86, 0xC1, 0x1D, 0x9E, 0xE1, 0xF8, 0x98, 0x11,
+     188                 :            :     0x69, 0xD9, 0x8E, 0x94, 0x9B, 0x1E, 0x87, 0xE9, 0xCE, 0x55, 0x28, 0xDF,
+     189                 :            :     0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, 0x68, 0x41, 0x99, 0x2D, 0x0F,
+     190                 :            :     0xB0, 0x54, 0xBB, 0x16
+     191                 :            : };
+     192                 :            : 
+     193                 :            : static const uint8_t aria_sb2[256] =
+     194                 :            : {
+     195                 :            :     0xE2, 0x4E, 0x54, 0xFC, 0x94, 0xC2, 0x4A, 0xCC, 0x62, 0x0D, 0x6A, 0x46,
+     196                 :            :     0x3C, 0x4D, 0x8B, 0xD1, 0x5E, 0xFA, 0x64, 0xCB, 0xB4, 0x97, 0xBE, 0x2B,
+     197                 :            :     0xBC, 0x77, 0x2E, 0x03, 0xD3, 0x19, 0x59, 0xC1, 0x1D, 0x06, 0x41, 0x6B,
+     198                 :            :     0x55, 0xF0, 0x99, 0x69, 0xEA, 0x9C, 0x18, 0xAE, 0x63, 0xDF, 0xE7, 0xBB,
+     199                 :            :     0x00, 0x73, 0x66, 0xFB, 0x96, 0x4C, 0x85, 0xE4, 0x3A, 0x09, 0x45, 0xAA,
+     200                 :            :     0x0F, 0xEE, 0x10, 0xEB, 0x2D, 0x7F, 0xF4, 0x29, 0xAC, 0xCF, 0xAD, 0x91,
+     201                 :            :     0x8D, 0x78, 0xC8, 0x95, 0xF9, 0x2F, 0xCE, 0xCD, 0x08, 0x7A, 0x88, 0x38,
+     202                 :            :     0x5C, 0x83, 0x2A, 0x28, 0x47, 0xDB, 0xB8, 0xC7, 0x93, 0xA4, 0x12, 0x53,
+     203                 :            :     0xFF, 0x87, 0x0E, 0x31, 0x36, 0x21, 0x58, 0x48, 0x01, 0x8E, 0x37, 0x74,
+     204                 :            :     0x32, 0xCA, 0xE9, 0xB1, 0xB7, 0xAB, 0x0C, 0xD7, 0xC4, 0x56, 0x42, 0x26,
+     205                 :            :     0x07, 0x98, 0x60, 0xD9, 0xB6, 0xB9, 0x11, 0x40, 0xEC, 0x20, 0x8C, 0xBD,
+     206                 :            :     0xA0, 0xC9, 0x84, 0x04, 0x49, 0x23, 0xF1, 0x4F, 0x50, 0x1F, 0x13, 0xDC,
+     207                 :            :     0xD8, 0xC0, 0x9E, 0x57, 0xE3, 0xC3, 0x7B, 0x65, 0x3B, 0x02, 0x8F, 0x3E,
+     208                 :            :     0xE8, 0x25, 0x92, 0xE5, 0x15, 0xDD, 0xFD, 0x17, 0xA9, 0xBF, 0xD4, 0x9A,
+     209                 :            :     0x7E, 0xC5, 0x39, 0x67, 0xFE, 0x76, 0x9D, 0x43, 0xA7, 0xE1, 0xD0, 0xF5,
+     210                 :            :     0x68, 0xF2, 0x1B, 0x34, 0x70, 0x05, 0xA3, 0x8A, 0xD5, 0x79, 0x86, 0xA8,
+     211                 :            :     0x30, 0xC6, 0x51, 0x4B, 0x1E, 0xA6, 0x27, 0xF6, 0x35, 0xD2, 0x6E, 0x24,
+     212                 :            :     0x16, 0x82, 0x5F, 0xDA, 0xE6, 0x75, 0xA2, 0xEF, 0x2C, 0xB2, 0x1C, 0x9F,
+     213                 :            :     0x5D, 0x6F, 0x80, 0x0A, 0x72, 0x44, 0x9B, 0x6C, 0x90, 0x0B, 0x5B, 0x33,
+     214                 :            :     0x7D, 0x5A, 0x52, 0xF3, 0x61, 0xA1, 0xF7, 0xB0, 0xD6, 0x3F, 0x7C, 0x6D,
+     215                 :            :     0xED, 0x14, 0xE0, 0xA5, 0x3D, 0x22, 0xB3, 0xF8, 0x89, 0xDE, 0x71, 0x1A,
+     216                 :            :     0xAF, 0xBA, 0xB5, 0x81
+     217                 :            : };
+     218                 :            : 
+     219                 :            : static const uint8_t aria_is1[256] =
+     220                 :            : {
+     221                 :            :     0x52, 0x09, 0x6A, 0xD5, 0x30, 0x36, 0xA5, 0x38, 0xBF, 0x40, 0xA3, 0x9E,
+     222                 :            :     0x81, 0xF3, 0xD7, 0xFB, 0x7C, 0xE3, 0x39, 0x82, 0x9B, 0x2F, 0xFF, 0x87,
+     223                 :            :     0x34, 0x8E, 0x43, 0x44, 0xC4, 0xDE, 0xE9, 0xCB, 0x54, 0x7B, 0x94, 0x32,
+     224                 :            :     0xA6, 0xC2, 0x23, 0x3D, 0xEE, 0x4C, 0x95, 0x0B, 0x42, 0xFA, 0xC3, 0x4E,
+     225                 :            :     0x08, 0x2E, 0xA1, 0x66, 0x28, 0xD9, 0x24, 0xB2, 0x76, 0x5B, 0xA2, 0x49,
+     226                 :            :     0x6D, 0x8B, 0xD1, 0x25, 0x72, 0xF8, 0xF6, 0x64, 0x86, 0x68, 0x98, 0x16,
+     227                 :            :     0xD4, 0xA4, 0x5C, 0xCC, 0x5D, 0x65, 0xB6, 0x92, 0x6C, 0x70, 0x48, 0x50,
+     228                 :            :     0xFD, 0xED, 0xB9, 0xDA, 0x5E, 0x15, 0x46, 0x57, 0xA7, 0x8D, 0x9D, 0x84,
+     229                 :            :     0x90, 0xD8, 0xAB, 0x00, 0x8C, 0xBC, 0xD3, 0x0A, 0xF7, 0xE4, 0x58, 0x05,
+     230                 :            :     0xB8, 0xB3, 0x45, 0x06, 0xD0, 0x2C, 0x1E, 0x8F, 0xCA, 0x3F, 0x0F, 0x02,
+     231                 :            :     0xC1, 0xAF, 0xBD, 0x03, 0x01, 0x13, 0x8A, 0x6B, 0x3A, 0x91, 0x11, 0x41,
+     232                 :            :     0x4F, 0x67, 0xDC, 0xEA, 0x97, 0xF2, 0xCF, 0xCE, 0xF0, 0xB4, 0xE6, 0x73,
+     233                 :            :     0x96, 0xAC, 0x74, 0x22, 0xE7, 0xAD, 0x35, 0x85, 0xE2, 0xF9, 0x37, 0xE8,
+     234                 :            :     0x1C, 0x75, 0xDF, 0x6E, 0x47, 0xF1, 0x1A, 0x71, 0x1D, 0x29, 0xC5, 0x89,
+     235                 :            :     0x6F, 0xB7, 0x62, 0x0E, 0xAA, 0x18, 0xBE, 0x1B, 0xFC, 0x56, 0x3E, 0x4B,
+     236                 :            :     0xC6, 0xD2, 0x79, 0x20, 0x9A, 0xDB, 0xC0, 0xFE, 0x78, 0xCD, 0x5A, 0xF4,
+     237                 :            :     0x1F, 0xDD, 0xA8, 0x33, 0x88, 0x07, 0xC7, 0x31, 0xB1, 0x12, 0x10, 0x59,
+     238                 :            :     0x27, 0x80, 0xEC, 0x5F, 0x60, 0x51, 0x7F, 0xA9, 0x19, 0xB5, 0x4A, 0x0D,
+     239                 :            :     0x2D, 0xE5, 0x7A, 0x9F, 0x93, 0xC9, 0x9C, 0xEF, 0xA0, 0xE0, 0x3B, 0x4D,
+     240                 :            :     0xAE, 0x2A, 0xF5, 0xB0, 0xC8, 0xEB, 0xBB, 0x3C, 0x83, 0x53, 0x99, 0x61,
+     241                 :            :     0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26, 0xE1, 0x69, 0x14, 0x63,
+     242                 :            :     0x55, 0x21, 0x0C, 0x7D
+     243                 :            : };
+     244                 :            : 
+     245                 :            : static const uint8_t aria_is2[256] =
+     246                 :            : {
+     247                 :            :     0x30, 0x68, 0x99, 0x1B, 0x87, 0xB9, 0x21, 0x78, 0x50, 0x39, 0xDB, 0xE1,
+     248                 :            :     0x72, 0x09, 0x62, 0x3C, 0x3E, 0x7E, 0x5E, 0x8E, 0xF1, 0xA0, 0xCC, 0xA3,
+     249                 :            :     0x2A, 0x1D, 0xFB, 0xB6, 0xD6, 0x20, 0xC4, 0x8D, 0x81, 0x65, 0xF5, 0x89,
+     250                 :            :     0xCB, 0x9D, 0x77, 0xC6, 0x57, 0x43, 0x56, 0x17, 0xD4, 0x40, 0x1A, 0x4D,
+     251                 :            :     0xC0, 0x63, 0x6C, 0xE3, 0xB7, 0xC8, 0x64, 0x6A, 0x53, 0xAA, 0x38, 0x98,
+     252                 :            :     0x0C, 0xF4, 0x9B, 0xED, 0x7F, 0x22, 0x76, 0xAF, 0xDD, 0x3A, 0x0B, 0x58,
+     253                 :            :     0x67, 0x88, 0x06, 0xC3, 0x35, 0x0D, 0x01, 0x8B, 0x8C, 0xC2, 0xE6, 0x5F,
+     254                 :            :     0x02, 0x24, 0x75, 0x93, 0x66, 0x1E, 0xE5, 0xE2, 0x54, 0xD8, 0x10, 0xCE,
+     255                 :            :     0x7A, 0xE8, 0x08, 0x2C, 0x12, 0x97, 0x32, 0xAB, 0xB4, 0x27, 0x0A, 0x23,
+     256                 :            :     0xDF, 0xEF, 0xCA, 0xD9, 0xB8, 0xFA, 0xDC, 0x31, 0x6B, 0xD1, 0xAD, 0x19,
+     257                 :            :     0x49, 0xBD, 0x51, 0x96, 0xEE, 0xE4, 0xA8, 0x41, 0xDA, 0xFF, 0xCD, 0x55,
+     258                 :            :     0x86, 0x36, 0xBE, 0x61, 0x52, 0xF8, 0xBB, 0x0E, 0x82, 0x48, 0x69, 0x9A,
+     259                 :            :     0xE0, 0x47, 0x9E, 0x5C, 0x04, 0x4B, 0x34, 0x15, 0x79, 0x26, 0xA7, 0xDE,
+     260                 :            :     0x29, 0xAE, 0x92, 0xD7, 0x84, 0xE9, 0xD2, 0xBA, 0x5D, 0xF3, 0xC5, 0xB0,
+     261                 :            :     0xBF, 0xA4, 0x3B, 0x71, 0x44, 0x46, 0x2B, 0xFC, 0xEB, 0x6F, 0xD5, 0xF6,
+     262                 :            :     0x14, 0xFE, 0x7C, 0x70, 0x5A, 0x7D, 0xFD, 0x2F, 0x18, 0x83, 0x16, 0xA5,
+     263                 :            :     0x91, 0x1F, 0x05, 0x95, 0x74, 0xA9, 0xC1, 0x5B, 0x4A, 0x85, 0x6D, 0x13,
+     264                 :            :     0x07, 0x4F, 0x4E, 0x45, 0xB2, 0x0F, 0xC9, 0x1C, 0xA6, 0xBC, 0xEC, 0x73,
+     265                 :            :     0x90, 0x7B, 0xCF, 0x59, 0x8F, 0xA1, 0xF9, 0x2D, 0xF2, 0xB1, 0x00, 0x94,
+     266                 :            :     0x37, 0x9F, 0xD0, 0x2E, 0x9C, 0x6E, 0x28, 0x3F, 0x80, 0xF0, 0x3D, 0xD3,
+     267                 :            :     0x25, 0x8A, 0xB5, 0xE7, 0x42, 0xB3, 0xC7, 0xEA, 0xF7, 0x4C, 0x11, 0x33,
+     268                 :            :     0x03, 0xA2, 0xAC, 0x60
+     269                 :            : };
+     270                 :            : 
+     271                 :            : /*
+     272                 :            :  * Helper for key schedule: r = FO( p, k ) ^ x
+     273                 :            :  */
+     274                 :          0 : static void aria_fo_xor(uint32_t r[4], const uint32_t p[4],
+     275                 :            :                         const uint32_t k[4], const uint32_t x[4])
+     276                 :            : {
+     277                 :            :     uint32_t a, b, c, d;
+     278                 :            : 
+     279                 :          0 :     a = p[0] ^ k[0];
+     280                 :          0 :     b = p[1] ^ k[1];
+     281                 :          0 :     c = p[2] ^ k[2];
+     282                 :          0 :     d = p[3] ^ k[3];
+     283                 :            : 
+     284                 :          0 :     aria_sl(&a, &b, &c, &d, aria_sb1, aria_sb2, aria_is1, aria_is2);
+     285                 :          0 :     aria_a(&a, &b, &c, &d);
+     286                 :            : 
+     287                 :          0 :     r[0] = a ^ x[0];
+     288                 :          0 :     r[1] = b ^ x[1];
+     289                 :          0 :     r[2] = c ^ x[2];
+     290                 :          0 :     r[3] = d ^ x[3];
+     291                 :          0 : }
+     292                 :            : 
+     293                 :            : /*
+     294                 :            :  * Helper for key schedule: r = FE( p, k ) ^ x
+     295                 :            :  */
+     296                 :          0 : static void aria_fe_xor(uint32_t r[4], const uint32_t p[4],
+     297                 :            :                         const uint32_t k[4], const uint32_t x[4])
+     298                 :            : {
+     299                 :            :     uint32_t a, b, c, d;
+     300                 :            : 
+     301                 :          0 :     a = p[0] ^ k[0];
+     302                 :          0 :     b = p[1] ^ k[1];
+     303                 :          0 :     c = p[2] ^ k[2];
+     304                 :          0 :     d = p[3] ^ k[3];
+     305                 :            : 
+     306                 :          0 :     aria_sl(&a, &b, &c, &d, aria_is1, aria_is2, aria_sb1, aria_sb2);
+     307                 :          0 :     aria_a(&a, &b, &c, &d);
+     308                 :            : 
+     309                 :          0 :     r[0] = a ^ x[0];
+     310                 :          0 :     r[1] = b ^ x[1];
+     311                 :          0 :     r[2] = c ^ x[2];
+     312                 :          0 :     r[3] = d ^ x[3];
+     313                 :          0 : }
+     314                 :            : 
+     315                 :            : /*
+     316                 :            :  * Big endian 128-bit rotation: r = a ^ (b <<< n), used only in key setup.
+     317                 :            :  *
+     318                 :            :  * We chose to store bytes into 32-bit words in little-endian format (see
+     319                 :            :  * MBEDTLS_GET_UINT32_LE / MBEDTLS_PUT_UINT32_LE ) so we need to reverse
+     320                 :            :  * bytes here.
+     321                 :            :  */
+     322                 :          0 : static void aria_rot128(uint32_t r[4], const uint32_t a[4],
+     323                 :            :                         const uint32_t b[4], uint8_t n)
+     324                 :            : {
+     325                 :            :     uint8_t i, j;
+     326                 :            :     uint32_t t, u;
+     327                 :            : 
+     328                 :          0 :     const uint8_t n1 = n % 32;              // bit offset
+     329         [ #  # ]:          0 :     const uint8_t n2 = n1 ? 32 - n1 : 0;    // reverse bit offset
+     330                 :            : 
+     331                 :          0 :     j = (n / 32) % 4;                       // initial word offset
+     332                 :          0 :     t = ARIA_P3(b[j]);                      // big endian
+     333         [ #  # ]:          0 :     for (i = 0; i < 4; i++) {
+     334                 :          0 :         j = (j + 1) % 4;                    // get next word, big endian
+     335                 :          0 :         u = ARIA_P3(b[j]);
+     336                 :          0 :         t <<= n1;                           // rotate
+     337                 :          0 :         t |= u >> n2;
+     338                 :          0 :         t = ARIA_P3(t);                     // back to little endian
+     339                 :          0 :         r[i] = a[i] ^ t;                    // store
+     340                 :          0 :         t = u;                              // move to next word
+     341                 :            :     }
+     342                 :          0 : }
+     343                 :            : 
+     344                 :            : /*
+     345                 :            :  * Set encryption key
+     346                 :            :  */
+     347                 :          0 : int mbedtls_aria_setkey_enc(mbedtls_aria_context *ctx,
+     348                 :            :                             const unsigned char *key, unsigned int keybits)
+     349                 :            : {
+     350                 :            :     /* round constant masks */
+     351                 :          0 :     const uint32_t rc[3][4] =
+     352                 :            :     {
+     353                 :            :         {   0xB7C17C51, 0x940A2227, 0xE8AB13FE, 0xE06E9AFA  },
+     354                 :            :         {   0xCC4AB16D, 0x20C8219E, 0xD5B128FF, 0xB0E25DEF  },
+     355                 :            :         {   0x1D3792DB, 0x70E92621, 0x75972403, 0x0EC9E804  }
+     356                 :            :     };
+     357                 :            : 
+     358                 :            :     int i;
+     359                 :            :     uint32_t w[4][4], *w2;
+     360                 :            : 
+     361   [ #  #  #  #  :          0 :     if (keybits != 128 && keybits != 192 && keybits != 256) {
+                   #  # ]
+     362                 :          0 :         return MBEDTLS_ERR_ARIA_BAD_INPUT_DATA;
+     363                 :            :     }
+     364                 :            : 
+     365                 :            :     /* Copy key to W0 (and potential remainder to W1) */
+     366                 :          0 :     w[0][0] = MBEDTLS_GET_UINT32_LE(key,  0);
+     367                 :          0 :     w[0][1] = MBEDTLS_GET_UINT32_LE(key,  4);
+     368                 :          0 :     w[0][2] = MBEDTLS_GET_UINT32_LE(key,  8);
+     369                 :          0 :     w[0][3] = MBEDTLS_GET_UINT32_LE(key, 12);
+     370                 :            : 
+     371                 :          0 :     memset(w[1], 0, 16);
+     372         [ #  # ]:          0 :     if (keybits >= 192) {
+     373                 :          0 :         w[1][0] = MBEDTLS_GET_UINT32_LE(key, 16);    // 192 bit key
+     374                 :          0 :         w[1][1] = MBEDTLS_GET_UINT32_LE(key, 20);
+     375                 :            :     }
+     376         [ #  # ]:          0 :     if (keybits == 256) {
+     377                 :          0 :         w[1][2] = MBEDTLS_GET_UINT32_LE(key, 24);    // 256 bit key
+     378                 :          0 :         w[1][3] = MBEDTLS_GET_UINT32_LE(key, 28);
+     379                 :            :     }
+     380                 :            : 
+     381                 :          0 :     i = (keybits - 128) >> 6;               // index: 0, 1, 2
+     382                 :          0 :     ctx->nr = 12 + 2 * i;                   // no. rounds: 12, 14, 16
+     383                 :            : 
+     384                 :          0 :     aria_fo_xor(w[1], w[0], rc[i], w[1]);   // W1 = FO(W0, CK1) ^ KR
+     385         [ #  # ]:          0 :     i = i < 2 ? i + 1 : 0;
+     386                 :          0 :     aria_fe_xor(w[2], w[1], rc[i], w[0]);   // W2 = FE(W1, CK2) ^ W0
+     387         [ #  # ]:          0 :     i = i < 2 ? i + 1 : 0;
+     388                 :          0 :     aria_fo_xor(w[3], w[2], rc[i], w[1]);   // W3 = FO(W2, CK3) ^ W1
+     389                 :            : 
+     390         [ #  # ]:          0 :     for (i = 0; i < 4; i++) {               // create round keys
+     391                 :          0 :         w2 = w[(i + 1) & 3];
+     392                 :          0 :         aria_rot128(ctx->rk[i], w[i], w2, 128 - 19);
+     393                 :          0 :         aria_rot128(ctx->rk[i +  4], w[i], w2, 128 - 31);
+     394                 :          0 :         aria_rot128(ctx->rk[i +  8], w[i], w2,       61);
+     395                 :          0 :         aria_rot128(ctx->rk[i + 12], w[i], w2,       31);
+     396                 :            :     }
+     397                 :          0 :     aria_rot128(ctx->rk[16], w[0], w[1], 19);
+     398                 :            : 
+     399                 :            :     /* w holds enough info to reconstruct the round keys */
+     400                 :          0 :     mbedtls_platform_zeroize(w, sizeof(w));
+     401                 :            : 
+     402                 :          0 :     return 0;
+     403                 :            : }
+     404                 :            : 
+     405                 :            : /*
+     406                 :            :  * Set decryption key
+     407                 :            :  */
+     408                 :            : #if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
+     409                 :          0 : int mbedtls_aria_setkey_dec(mbedtls_aria_context *ctx,
+     410                 :            :                             const unsigned char *key, unsigned int keybits)
+     411                 :            : {
+     412                 :            :     int i, j, k, ret;
+     413                 :            : 
+     414                 :          0 :     ret = mbedtls_aria_setkey_enc(ctx, key, keybits);
+     415         [ #  # ]:          0 :     if (ret != 0) {
+     416                 :          0 :         return ret;
+     417                 :            :     }
+     418                 :            : 
+     419                 :            :     /* flip the order of round keys */
+     420         [ #  # ]:          0 :     for (i = 0, j = ctx->nr; i < j; i++, j--) {
+     421         [ #  # ]:          0 :         for (k = 0; k < 4; k++) {
+     422                 :          0 :             uint32_t t = ctx->rk[i][k];
+     423                 :          0 :             ctx->rk[i][k] = ctx->rk[j][k];
+     424                 :          0 :             ctx->rk[j][k] = t;
+     425                 :            :         }
+     426                 :            :     }
+     427                 :            : 
+     428                 :            :     /* apply affine transform to middle keys */
+     429         [ #  # ]:          0 :     for (i = 1; i < ctx->nr; i++) {
+     430                 :          0 :         aria_a(&ctx->rk[i][0], &ctx->rk[i][1],
+     431                 :            :                &ctx->rk[i][2], &ctx->rk[i][3]);
+     432                 :            :     }
+     433                 :            : 
+     434                 :          0 :     return 0;
+     435                 :            : }
+     436                 :            : #endif /* !MBEDTLS_BLOCK_CIPHER_NO_DECRYPT */
+     437                 :            : 
+     438                 :            : /*
+     439                 :            :  * Encrypt a block
+     440                 :            :  */
+     441                 :          0 : int mbedtls_aria_crypt_ecb(mbedtls_aria_context *ctx,
+     442                 :            :                            const unsigned char input[MBEDTLS_ARIA_BLOCKSIZE],
+     443                 :            :                            unsigned char output[MBEDTLS_ARIA_BLOCKSIZE])
+     444                 :            : {
+     445                 :            :     int i;
+     446                 :            : 
+     447                 :            :     uint32_t a, b, c, d;
+     448                 :            : 
+     449                 :          0 :     a = MBEDTLS_GET_UINT32_LE(input,  0);
+     450                 :          0 :     b = MBEDTLS_GET_UINT32_LE(input,  4);
+     451                 :          0 :     c = MBEDTLS_GET_UINT32_LE(input,  8);
+     452                 :          0 :     d = MBEDTLS_GET_UINT32_LE(input, 12);
+     453                 :            : 
+     454                 :          0 :     i = 0;
+     455                 :            :     while (1) {
+     456                 :          0 :         a ^= ctx->rk[i][0];
+     457                 :          0 :         b ^= ctx->rk[i][1];
+     458                 :          0 :         c ^= ctx->rk[i][2];
+     459                 :          0 :         d ^= ctx->rk[i][3];
+     460                 :          0 :         i++;
+     461                 :            : 
+     462                 :          0 :         aria_sl(&a, &b, &c, &d, aria_sb1, aria_sb2, aria_is1, aria_is2);
+     463                 :          0 :         aria_a(&a, &b, &c, &d);
+     464                 :            : 
+     465                 :          0 :         a ^= ctx->rk[i][0];
+     466                 :          0 :         b ^= ctx->rk[i][1];
+     467                 :          0 :         c ^= ctx->rk[i][2];
+     468                 :          0 :         d ^= ctx->rk[i][3];
+     469                 :          0 :         i++;
+     470                 :            : 
+     471                 :          0 :         aria_sl(&a, &b, &c, &d, aria_is1, aria_is2, aria_sb1, aria_sb2);
+     472         [ #  # ]:          0 :         if (i >= ctx->nr) {
+     473                 :          0 :             break;
+     474                 :            :         }
+     475                 :          0 :         aria_a(&a, &b, &c, &d);
+     476                 :            :     }
+     477                 :            : 
+     478                 :            :     /* final key mixing */
+     479                 :          0 :     a ^= ctx->rk[i][0];
+     480                 :          0 :     b ^= ctx->rk[i][1];
+     481                 :          0 :     c ^= ctx->rk[i][2];
+     482                 :          0 :     d ^= ctx->rk[i][3];
+     483                 :            : 
+     484                 :          0 :     MBEDTLS_PUT_UINT32_LE(a, output,  0);
+     485                 :          0 :     MBEDTLS_PUT_UINT32_LE(b, output,  4);
+     486                 :          0 :     MBEDTLS_PUT_UINT32_LE(c, output,  8);
+     487                 :          0 :     MBEDTLS_PUT_UINT32_LE(d, output, 12);
+     488                 :            : 
+     489                 :          0 :     return 0;
+     490                 :            : }
+     491                 :            : 
+     492                 :            : /* Initialize context */
+     493                 :          0 : void mbedtls_aria_init(mbedtls_aria_context *ctx)
+     494                 :            : {
+     495                 :          0 :     memset(ctx, 0, sizeof(mbedtls_aria_context));
+     496                 :          0 : }
+     497                 :            : 
+     498                 :            : /* Clear context */
+     499                 :          0 : void mbedtls_aria_free(mbedtls_aria_context *ctx)
+     500                 :            : {
+     501         [ #  # ]:          0 :     if (ctx == NULL) {
+     502                 :          0 :         return;
+     503                 :            :     }
+     504                 :            : 
+     505                 :          0 :     mbedtls_platform_zeroize(ctx, sizeof(mbedtls_aria_context));
+     506                 :            : }
+     507                 :            : 
+     508                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+     509                 :            : /*
+     510                 :            :  * ARIA-CBC buffer encryption/decryption
+     511                 :            :  */
+     512                 :          0 : int mbedtls_aria_crypt_cbc(mbedtls_aria_context *ctx,
+     513                 :            :                            int mode,
+     514                 :            :                            size_t length,
+     515                 :            :                            unsigned char iv[MBEDTLS_ARIA_BLOCKSIZE],
+     516                 :            :                            const unsigned char *input,
+     517                 :            :                            unsigned char *output)
+     518                 :            : {
+     519                 :            :     unsigned char temp[MBEDTLS_ARIA_BLOCKSIZE];
+     520                 :            : 
+     521   [ #  #  #  # ]:          0 :     if ((mode != MBEDTLS_ARIA_ENCRYPT) && (mode != MBEDTLS_ARIA_DECRYPT)) {
+     522                 :          0 :         return MBEDTLS_ERR_ARIA_BAD_INPUT_DATA;
+     523                 :            :     }
+     524                 :            : 
+     525         [ #  # ]:          0 :     if (length % MBEDTLS_ARIA_BLOCKSIZE) {
+     526                 :          0 :         return MBEDTLS_ERR_ARIA_INVALID_INPUT_LENGTH;
+     527                 :            :     }
+     528                 :            : 
+     529         [ #  # ]:          0 :     if (mode == MBEDTLS_ARIA_DECRYPT) {
+     530         [ #  # ]:          0 :         while (length > 0) {
+     531                 :          0 :             memcpy(temp, input, MBEDTLS_ARIA_BLOCKSIZE);
+     532                 :          0 :             mbedtls_aria_crypt_ecb(ctx, input, output);
+     533                 :            : 
+     534                 :            :             mbedtls_xor(output, output, iv, MBEDTLS_ARIA_BLOCKSIZE);
+     535                 :            : 
+     536                 :          0 :             memcpy(iv, temp, MBEDTLS_ARIA_BLOCKSIZE);
+     537                 :            : 
+     538                 :          0 :             input  += MBEDTLS_ARIA_BLOCKSIZE;
+     539                 :          0 :             output += MBEDTLS_ARIA_BLOCKSIZE;
+     540                 :          0 :             length -= MBEDTLS_ARIA_BLOCKSIZE;
+     541                 :            :         }
+     542                 :            :     } else {
+     543         [ #  # ]:          0 :         while (length > 0) {
+     544                 :            :             mbedtls_xor(output, input, iv, MBEDTLS_ARIA_BLOCKSIZE);
+     545                 :            : 
+     546                 :          0 :             mbedtls_aria_crypt_ecb(ctx, output, output);
+     547                 :          0 :             memcpy(iv, output, MBEDTLS_ARIA_BLOCKSIZE);
+     548                 :            : 
+     549                 :          0 :             input  += MBEDTLS_ARIA_BLOCKSIZE;
+     550                 :          0 :             output += MBEDTLS_ARIA_BLOCKSIZE;
+     551                 :          0 :             length -= MBEDTLS_ARIA_BLOCKSIZE;
+     552                 :            :         }
+     553                 :            :     }
+     554                 :            : 
+     555                 :          0 :     return 0;
+     556                 :            : }
+     557                 :            : #endif /* MBEDTLS_CIPHER_MODE_CBC */
+     558                 :            : 
+     559                 :            : #if defined(MBEDTLS_CIPHER_MODE_CFB)
+     560                 :            : /*
+     561                 :            :  * ARIA-CFB128 buffer encryption/decryption
+     562                 :            :  */
+     563                 :          0 : int mbedtls_aria_crypt_cfb128(mbedtls_aria_context *ctx,
+     564                 :            :                               int mode,
+     565                 :            :                               size_t length,
+     566                 :            :                               size_t *iv_off,
+     567                 :            :                               unsigned char iv[MBEDTLS_ARIA_BLOCKSIZE],
+     568                 :            :                               const unsigned char *input,
+     569                 :            :                               unsigned char *output)
+     570                 :            : {
+     571                 :            :     unsigned char c;
+     572                 :            :     size_t n;
+     573                 :            : 
+     574   [ #  #  #  # ]:          0 :     if ((mode != MBEDTLS_ARIA_ENCRYPT) && (mode != MBEDTLS_ARIA_DECRYPT)) {
+     575                 :          0 :         return MBEDTLS_ERR_ARIA_BAD_INPUT_DATA;
+     576                 :            :     }
+     577                 :            : 
+     578                 :          0 :     n = *iv_off;
+     579                 :            : 
+     580                 :            :     /* An overly large value of n can lead to an unlimited
+     581                 :            :      * buffer overflow. */
+     582         [ #  # ]:          0 :     if (n >= MBEDTLS_ARIA_BLOCKSIZE) {
+     583                 :          0 :         return MBEDTLS_ERR_ARIA_BAD_INPUT_DATA;
+     584                 :            :     }
+     585                 :            : 
+     586         [ #  # ]:          0 :     if (mode == MBEDTLS_ARIA_DECRYPT) {
+     587         [ #  # ]:          0 :         while (length--) {
+     588         [ #  # ]:          0 :             if (n == 0) {
+     589                 :          0 :                 mbedtls_aria_crypt_ecb(ctx, iv, iv);
+     590                 :            :             }
+     591                 :            : 
+     592                 :          0 :             c = *input++;
+     593                 :          0 :             *output++ = c ^ iv[n];
+     594                 :          0 :             iv[n] = c;
+     595                 :            : 
+     596                 :          0 :             n = (n + 1) & 0x0F;
+     597                 :            :         }
+     598                 :            :     } else {
+     599         [ #  # ]:          0 :         while (length--) {
+     600         [ #  # ]:          0 :             if (n == 0) {
+     601                 :          0 :                 mbedtls_aria_crypt_ecb(ctx, iv, iv);
+     602                 :            :             }
+     603                 :            : 
+     604                 :          0 :             iv[n] = *output++ = (unsigned char) (iv[n] ^ *input++);
+     605                 :            : 
+     606                 :          0 :             n = (n + 1) & 0x0F;
+     607                 :            :         }
+     608                 :            :     }
+     609                 :            : 
+     610                 :          0 :     *iv_off = n;
+     611                 :            : 
+     612                 :          0 :     return 0;
+     613                 :            : }
+     614                 :            : #endif /* MBEDTLS_CIPHER_MODE_CFB */
+     615                 :            : 
+     616                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR)
+     617                 :            : /*
+     618                 :            :  * ARIA-CTR buffer encryption/decryption
+     619                 :            :  */
+     620                 :          0 : int mbedtls_aria_crypt_ctr(mbedtls_aria_context *ctx,
+     621                 :            :                            size_t length,
+     622                 :            :                            size_t *nc_off,
+     623                 :            :                            unsigned char nonce_counter[MBEDTLS_ARIA_BLOCKSIZE],
+     624                 :            :                            unsigned char stream_block[MBEDTLS_ARIA_BLOCKSIZE],
+     625                 :            :                            const unsigned char *input,
+     626                 :            :                            unsigned char *output)
+     627                 :            : {
+     628                 :            :     int c, i;
+     629                 :            :     size_t n;
+     630                 :            : 
+     631                 :          0 :     n = *nc_off;
+     632                 :            :     /* An overly large value of n can lead to an unlimited
+     633                 :            :      * buffer overflow. */
+     634         [ #  # ]:          0 :     if (n >= MBEDTLS_ARIA_BLOCKSIZE) {
+     635                 :          0 :         return MBEDTLS_ERR_ARIA_BAD_INPUT_DATA;
+     636                 :            :     }
+     637                 :            : 
+     638         [ #  # ]:          0 :     while (length--) {
+     639         [ #  # ]:          0 :         if (n == 0) {
+     640                 :          0 :             mbedtls_aria_crypt_ecb(ctx, nonce_counter,
+     641                 :            :                                    stream_block);
+     642                 :            : 
+     643         [ #  # ]:          0 :             for (i = MBEDTLS_ARIA_BLOCKSIZE; i > 0; i--) {
+     644         [ #  # ]:          0 :                 if (++nonce_counter[i - 1] != 0) {
+     645                 :          0 :                     break;
+     646                 :            :                 }
+     647                 :            :             }
+     648                 :            :         }
+     649                 :          0 :         c = *input++;
+     650                 :          0 :         *output++ = (unsigned char) (c ^ stream_block[n]);
+     651                 :            : 
+     652                 :          0 :         n = (n + 1) & 0x0F;
+     653                 :            :     }
+     654                 :            : 
+     655                 :          0 :     *nc_off = n;
+     656                 :            : 
+     657                 :          0 :     return 0;
+     658                 :            : }
+     659                 :            : #endif /* MBEDTLS_CIPHER_MODE_CTR */
+     660                 :            : #endif /* !MBEDTLS_ARIA_ALT */
+     661                 :            : 
+     662                 :            : #if defined(MBEDTLS_SELF_TEST)
+     663                 :            : 
+     664                 :            : /*
+     665                 :            :  * Basic ARIA ECB test vectors from RFC 5794
+     666                 :            :  */
+     667                 :            : static const uint8_t aria_test1_ecb_key[32] =           // test key
+     668                 :            : {
+     669                 :            :     0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,     // 128 bit
+     670                 :            :     0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
+     671                 :            :     0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,     // 192 bit
+     672                 :            :     0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F      // 256 bit
+     673                 :            : };
+     674                 :            : 
+     675                 :            : static const uint8_t aria_test1_ecb_pt[MBEDTLS_ARIA_BLOCKSIZE] =            // plaintext
+     676                 :            : {
+     677                 :            :     0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,     // same for all
+     678                 :            :     0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF      // key sizes
+     679                 :            : };
+     680                 :            : 
+     681                 :            : static const uint8_t aria_test1_ecb_ct[3][MBEDTLS_ARIA_BLOCKSIZE] =         // ciphertext
+     682                 :            : {
+     683                 :            :     { 0xD7, 0x18, 0xFB, 0xD6, 0xAB, 0x64, 0x4C, 0x73,   // 128 bit
+     684                 :            :       0x9D, 0xA9, 0x5F, 0x3B, 0xE6, 0x45, 0x17, 0x78 },
+     685                 :            :     { 0x26, 0x44, 0x9C, 0x18, 0x05, 0xDB, 0xE7, 0xAA,   // 192 bit
+     686                 :            :       0x25, 0xA4, 0x68, 0xCE, 0x26, 0x3A, 0x9E, 0x79 },
+     687                 :            :     { 0xF9, 0x2B, 0xD7, 0xC7, 0x9F, 0xB7, 0x2E, 0x2F,   // 256 bit
+     688                 :            :       0x2B, 0x8F, 0x80, 0xC1, 0x97, 0x2D, 0x24, 0xFC }
+     689                 :            : };
+     690                 :            : 
+     691                 :            : /*
+     692                 :            :  * Mode tests from "Test Vectors for ARIA"  Version 1.0
+     693                 :            :  * http://210.104.33.10/ARIA/doc/ARIA-testvector-e.pdf
+     694                 :            :  */
+     695                 :            : #if (defined(MBEDTLS_CIPHER_MODE_CBC) || defined(MBEDTLS_CIPHER_MODE_CFB) || \
+     696                 :            :     defined(MBEDTLS_CIPHER_MODE_CTR))
+     697                 :            : static const uint8_t aria_test2_key[32] =
+     698                 :            : {
+     699                 :            :     0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,     // 128 bit
+     700                 :            :     0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
+     701                 :            :     0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,     // 192 bit
+     702                 :            :     0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff      // 256 bit
+     703                 :            : };
+     704                 :            : 
+     705                 :            : static const uint8_t aria_test2_pt[48] =
+     706                 :            : {
+     707                 :            :     0x11, 0x11, 0x11, 0x11, 0xaa, 0xaa, 0xaa, 0xaa,     // same for all
+     708                 :            :     0x11, 0x11, 0x11, 0x11, 0xbb, 0xbb, 0xbb, 0xbb,
+     709                 :            :     0x11, 0x11, 0x11, 0x11, 0xcc, 0xcc, 0xcc, 0xcc,
+     710                 :            :     0x11, 0x11, 0x11, 0x11, 0xdd, 0xdd, 0xdd, 0xdd,
+     711                 :            :     0x22, 0x22, 0x22, 0x22, 0xaa, 0xaa, 0xaa, 0xaa,
+     712                 :            :     0x22, 0x22, 0x22, 0x22, 0xbb, 0xbb, 0xbb, 0xbb,
+     713                 :            : };
+     714                 :            : #endif
+     715                 :            : 
+     716                 :            : #if (defined(MBEDTLS_CIPHER_MODE_CBC) || defined(MBEDTLS_CIPHER_MODE_CFB))
+     717                 :            : static const uint8_t aria_test2_iv[MBEDTLS_ARIA_BLOCKSIZE] =
+     718                 :            : {
+     719                 :            :     0x0f, 0x1e, 0x2d, 0x3c, 0x4b, 0x5a, 0x69, 0x78,     // same for CBC, CFB
+     720                 :            :     0x87, 0x96, 0xa5, 0xb4, 0xc3, 0xd2, 0xe1, 0xf0      // CTR has zero IV
+     721                 :            : };
+     722                 :            : #endif
+     723                 :            : 
+     724                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+     725                 :            : static const uint8_t aria_test2_cbc_ct[3][48] =         // CBC ciphertext
+     726                 :            : {
+     727                 :            :     { 0x49, 0xd6, 0x18, 0x60, 0xb1, 0x49, 0x09, 0x10,   // 128-bit key
+     728                 :            :       0x9c, 0xef, 0x0d, 0x22, 0xa9, 0x26, 0x81, 0x34,
+     729                 :            :       0xfa, 0xdf, 0x9f, 0xb2, 0x31, 0x51, 0xe9, 0x64,
+     730                 :            :       0x5f, 0xba, 0x75, 0x01, 0x8b, 0xdb, 0x15, 0x38,
+     731                 :            :       0xb5, 0x33, 0x34, 0x63, 0x4b, 0xbf, 0x7d, 0x4c,
+     732                 :            :       0xd4, 0xb5, 0x37, 0x70, 0x33, 0x06, 0x0c, 0x15 },
+     733                 :            :     { 0xaf, 0xe6, 0xcf, 0x23, 0x97, 0x4b, 0x53, 0x3c,   // 192-bit key
+     734                 :            :       0x67, 0x2a, 0x82, 0x62, 0x64, 0xea, 0x78, 0x5f,
+     735                 :            :       0x4e, 0x4f, 0x7f, 0x78, 0x0d, 0xc7, 0xf3, 0xf1,
+     736                 :            :       0xe0, 0x96, 0x2b, 0x80, 0x90, 0x23, 0x86, 0xd5,
+     737                 :            :       0x14, 0xe9, 0xc3, 0xe7, 0x72, 0x59, 0xde, 0x92,
+     738                 :            :       0xdd, 0x11, 0x02, 0xff, 0xab, 0x08, 0x6c, 0x1e },
+     739                 :            :     { 0x52, 0x3a, 0x8a, 0x80, 0x6a, 0xe6, 0x21, 0xf1,   // 256-bit key
+     740                 :            :       0x55, 0xfd, 0xd2, 0x8d, 0xbc, 0x34, 0xe1, 0xab,
+     741                 :            :       0x7b, 0x9b, 0x42, 0x43, 0x2a, 0xd8, 0xb2, 0xef,
+     742                 :            :       0xb9, 0x6e, 0x23, 0xb1, 0x3f, 0x0a, 0x6e, 0x52,
+     743                 :            :       0xf3, 0x61, 0x85, 0xd5, 0x0a, 0xd0, 0x02, 0xc5,
+     744                 :            :       0xf6, 0x01, 0xbe, 0xe5, 0x49, 0x3f, 0x11, 0x8b }
+     745                 :            : };
+     746                 :            : #endif /* MBEDTLS_CIPHER_MODE_CBC */
+     747                 :            : 
+     748                 :            : #if defined(MBEDTLS_CIPHER_MODE_CFB)
+     749                 :            : static const uint8_t aria_test2_cfb_ct[3][48] =         // CFB ciphertext
+     750                 :            : {
+     751                 :            :     { 0x37, 0x20, 0xe5, 0x3b, 0xa7, 0xd6, 0x15, 0x38,   // 128-bit key
+     752                 :            :       0x34, 0x06, 0xb0, 0x9f, 0x0a, 0x05, 0xa2, 0x00,
+     753                 :            :       0xc0, 0x7c, 0x21, 0xe6, 0x37, 0x0f, 0x41, 0x3a,
+     754                 :            :       0x5d, 0x13, 0x25, 0x00, 0xa6, 0x82, 0x85, 0x01,
+     755                 :            :       0x7c, 0x61, 0xb4, 0x34, 0xc7, 0xb7, 0xca, 0x96,
+     756                 :            :       0x85, 0xa5, 0x10, 0x71, 0x86, 0x1e, 0x4d, 0x4b },
+     757                 :            :     { 0x41, 0x71, 0xf7, 0x19, 0x2b, 0xf4, 0x49, 0x54,   // 192-bit key
+     758                 :            :       0x94, 0xd2, 0x73, 0x61, 0x29, 0x64, 0x0f, 0x5c,
+     759                 :            :       0x4d, 0x87, 0xa9, 0xa2, 0x13, 0x66, 0x4c, 0x94,
+     760                 :            :       0x48, 0x47, 0x7c, 0x6e, 0xcc, 0x20, 0x13, 0x59,
+     761                 :            :       0x8d, 0x97, 0x66, 0x95, 0x2d, 0xd8, 0xc3, 0x86,
+     762                 :            :       0x8f, 0x17, 0xe3, 0x6e, 0xf6, 0x6f, 0xd8, 0x4b },
+     763                 :            :     { 0x26, 0x83, 0x47, 0x05, 0xb0, 0xf2, 0xc0, 0xe2,   // 256-bit key
+     764                 :            :       0x58, 0x8d, 0x4a, 0x7f, 0x09, 0x00, 0x96, 0x35,
+     765                 :            :       0xf2, 0x8b, 0xb9, 0x3d, 0x8c, 0x31, 0xf8, 0x70,
+     766                 :            :       0xec, 0x1e, 0x0b, 0xdb, 0x08, 0x2b, 0x66, 0xfa,
+     767                 :            :       0x40, 0x2d, 0xd9, 0xc2, 0x02, 0xbe, 0x30, 0x0c,
+     768                 :            :       0x45, 0x17, 0xd1, 0x96, 0xb1, 0x4d, 0x4c, 0xe1 }
+     769                 :            : };
+     770                 :            : #endif /* MBEDTLS_CIPHER_MODE_CFB */
+     771                 :            : 
+     772                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR)
+     773                 :            : static const uint8_t aria_test2_ctr_ct[3][48] =         // CTR ciphertext
+     774                 :            : {
+     775                 :            :     { 0xac, 0x5d, 0x7d, 0xe8, 0x05, 0xa0, 0xbf, 0x1c,   // 128-bit key
+     776                 :            :       0x57, 0xc8, 0x54, 0x50, 0x1a, 0xf6, 0x0f, 0xa1,
+     777                 :            :       0x14, 0x97, 0xe2, 0xa3, 0x45, 0x19, 0xde, 0xa1,
+     778                 :            :       0x56, 0x9e, 0x91, 0xe5, 0xb5, 0xcc, 0xae, 0x2f,
+     779                 :            :       0xf3, 0xbf, 0xa1, 0xbf, 0x97, 0x5f, 0x45, 0x71,
+     780                 :            :       0xf4, 0x8b, 0xe1, 0x91, 0x61, 0x35, 0x46, 0xc3 },
+     781                 :            :     { 0x08, 0x62, 0x5c, 0xa8, 0xfe, 0x56, 0x9c, 0x19,   // 192-bit key
+     782                 :            :       0xba, 0x7a, 0xf3, 0x76, 0x0a, 0x6e, 0xd1, 0xce,
+     783                 :            :       0xf4, 0xd1, 0x99, 0x26, 0x3e, 0x99, 0x9d, 0xde,
+     784                 :            :       0x14, 0x08, 0x2d, 0xbb, 0xa7, 0x56, 0x0b, 0x79,
+     785                 :            :       0xa4, 0xc6, 0xb4, 0x56, 0xb8, 0x70, 0x7d, 0xce,
+     786                 :            :       0x75, 0x1f, 0x98, 0x54, 0xf1, 0x88, 0x93, 0xdf },
+     787                 :            :     { 0x30, 0x02, 0x6c, 0x32, 0x96, 0x66, 0x14, 0x17,   // 256-bit key
+     788                 :            :       0x21, 0x17, 0x8b, 0x99, 0xc0, 0xa1, 0xf1, 0xb2,
+     789                 :            :       0xf0, 0x69, 0x40, 0x25, 0x3f, 0x7b, 0x30, 0x89,
+     790                 :            :       0xe2, 0xa3, 0x0e, 0xa8, 0x6a, 0xa3, 0xc8, 0x8f,
+     791                 :            :       0x59, 0x40, 0xf0, 0x5a, 0xd7, 0xee, 0x41, 0xd7,
+     792                 :            :       0x13, 0x47, 0xbb, 0x72, 0x61, 0xe3, 0x48, 0xf1 }
+     793                 :            : };
+     794                 :            : #endif /* MBEDTLS_CIPHER_MODE_CFB */
+     795                 :            : 
+     796                 :            : #define ARIA_SELF_TEST_ASSERT(cond)                   \
+     797                 :            :     do {                                            \
+     798                 :            :         if (cond) {                                \
+     799                 :            :             if (verbose)                           \
+     800                 :            :             mbedtls_printf("failed\n");       \
+     801                 :            :             goto exit;                              \
+     802                 :            :         } else {                                    \
+     803                 :            :             if (verbose)                           \
+     804                 :            :             mbedtls_printf("passed\n");       \
+     805                 :            :         }                                           \
+     806                 :            :     } while (0)
+     807                 :            : 
+     808                 :            : /*
+     809                 :            :  * Checkup routine
+     810                 :            :  */
+     811                 :          0 : int mbedtls_aria_self_test(int verbose)
+     812                 :            : {
+     813                 :            :     int i;
+     814                 :            :     uint8_t blk[MBEDTLS_ARIA_BLOCKSIZE];
+     815                 :            :     mbedtls_aria_context ctx;
+     816                 :          0 :     int ret = 1;
+     817                 :            : 
+     818                 :            : #if (defined(MBEDTLS_CIPHER_MODE_CFB) || defined(MBEDTLS_CIPHER_MODE_CTR))
+     819                 :            :     size_t j;
+     820                 :            : #endif
+     821                 :            : 
+     822                 :            : #if (defined(MBEDTLS_CIPHER_MODE_CBC) || \
+     823                 :            :     defined(MBEDTLS_CIPHER_MODE_CFB) || \
+     824                 :            :     defined(MBEDTLS_CIPHER_MODE_CTR))
+     825                 :            :     uint8_t buf[48], iv[MBEDTLS_ARIA_BLOCKSIZE];
+     826                 :            : #endif
+     827                 :            : 
+     828                 :          0 :     mbedtls_aria_init(&ctx);
+     829                 :            : 
+     830                 :            :     /*
+     831                 :            :      * Test set 1
+     832                 :            :      */
+     833         [ #  # ]:          0 :     for (i = 0; i < 3; i++) {
+     834                 :            :         /* test ECB encryption */
+     835         [ #  # ]:          0 :         if (verbose) {
+     836                 :          0 :             mbedtls_printf("  ARIA-ECB-%d (enc): ", 128 + 64 * i);
+     837                 :            :         }
+     838                 :          0 :         mbedtls_aria_setkey_enc(&ctx, aria_test1_ecb_key, 128 + 64 * i);
+     839                 :          0 :         mbedtls_aria_crypt_ecb(&ctx, aria_test1_ecb_pt, blk);
+     840   [ #  #  #  #  :          0 :         ARIA_SELF_TEST_ASSERT(
+                   #  # ]
+     841                 :            :             memcmp(blk, aria_test1_ecb_ct[i], MBEDTLS_ARIA_BLOCKSIZE)
+     842                 :            :             != 0);
+     843                 :            : 
+     844                 :            :         /* test ECB decryption */
+     845         [ #  # ]:          0 :         if (verbose) {
+     846                 :          0 :             mbedtls_printf("  ARIA-ECB-%d (dec): ", 128 + 64 * i);
+     847                 :            : #if defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
+     848                 :            :             mbedtls_printf("skipped\n");
+     849                 :            : #endif
+     850                 :            :         }
+     851                 :            : 
+     852                 :            : #if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
+     853                 :          0 :         mbedtls_aria_setkey_dec(&ctx, aria_test1_ecb_key, 128 + 64 * i);
+     854                 :          0 :         mbedtls_aria_crypt_ecb(&ctx, aria_test1_ecb_ct[i], blk);
+     855   [ #  #  #  #  :          0 :         ARIA_SELF_TEST_ASSERT(
+                   #  # ]
+     856                 :            :             memcmp(blk, aria_test1_ecb_pt, MBEDTLS_ARIA_BLOCKSIZE)
+     857                 :            :             != 0);
+     858                 :            : #endif
+     859                 :            :     }
+     860         [ #  # ]:          0 :     if (verbose) {
+     861                 :          0 :         mbedtls_printf("\n");
+     862                 :            :     }
+     863                 :            : 
+     864                 :            :     /*
+     865                 :            :      * Test set 2
+     866                 :            :      */
+     867                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+     868         [ #  # ]:          0 :     for (i = 0; i < 3; i++) {
+     869                 :            :         /* Test CBC encryption */
+     870         [ #  # ]:          0 :         if (verbose) {
+     871                 :          0 :             mbedtls_printf("  ARIA-CBC-%d (enc): ", 128 + 64 * i);
+     872                 :            :         }
+     873                 :          0 :         mbedtls_aria_setkey_enc(&ctx, aria_test2_key, 128 + 64 * i);
+     874                 :          0 :         memcpy(iv, aria_test2_iv, MBEDTLS_ARIA_BLOCKSIZE);
+     875                 :          0 :         memset(buf, 0x55, sizeof(buf));
+     876                 :          0 :         mbedtls_aria_crypt_cbc(&ctx, MBEDTLS_ARIA_ENCRYPT, 48, iv,
+     877                 :            :                                aria_test2_pt, buf);
+     878   [ #  #  #  #  :          0 :         ARIA_SELF_TEST_ASSERT(memcmp(buf, aria_test2_cbc_ct[i], 48)
+                   #  # ]
+     879                 :            :                               != 0);
+     880                 :            : 
+     881                 :            :         /* Test CBC decryption */
+     882         [ #  # ]:          0 :         if (verbose) {
+     883                 :          0 :             mbedtls_printf("  ARIA-CBC-%d (dec): ", 128 + 64 * i);
+     884                 :            :         }
+     885                 :          0 :         mbedtls_aria_setkey_dec(&ctx, aria_test2_key, 128 + 64 * i);
+     886                 :          0 :         memcpy(iv, aria_test2_iv, MBEDTLS_ARIA_BLOCKSIZE);
+     887                 :          0 :         memset(buf, 0xAA, sizeof(buf));
+     888                 :          0 :         mbedtls_aria_crypt_cbc(&ctx, MBEDTLS_ARIA_DECRYPT, 48, iv,
+     889                 :          0 :                                aria_test2_cbc_ct[i], buf);
+     890   [ #  #  #  #  :          0 :         ARIA_SELF_TEST_ASSERT(memcmp(buf, aria_test2_pt, 48) != 0);
+                   #  # ]
+     891                 :            :     }
+     892         [ #  # ]:          0 :     if (verbose) {
+     893                 :          0 :         mbedtls_printf("\n");
+     894                 :            :     }
+     895                 :            : 
+     896                 :            : #endif /* MBEDTLS_CIPHER_MODE_CBC */
+     897                 :            : 
+     898                 :            : #if defined(MBEDTLS_CIPHER_MODE_CFB)
+     899         [ #  # ]:          0 :     for (i = 0; i < 3; i++) {
+     900                 :            :         /* Test CFB encryption */
+     901         [ #  # ]:          0 :         if (verbose) {
+     902                 :          0 :             mbedtls_printf("  ARIA-CFB-%d (enc): ", 128 + 64 * i);
+     903                 :            :         }
+     904                 :          0 :         mbedtls_aria_setkey_enc(&ctx, aria_test2_key, 128 + 64 * i);
+     905                 :          0 :         memcpy(iv, aria_test2_iv, MBEDTLS_ARIA_BLOCKSIZE);
+     906                 :          0 :         memset(buf, 0x55, sizeof(buf));
+     907                 :          0 :         j = 0;
+     908                 :          0 :         mbedtls_aria_crypt_cfb128(&ctx, MBEDTLS_ARIA_ENCRYPT, 48, &j, iv,
+     909                 :            :                                   aria_test2_pt, buf);
+     910   [ #  #  #  #  :          0 :         ARIA_SELF_TEST_ASSERT(memcmp(buf, aria_test2_cfb_ct[i], 48) != 0);
+                   #  # ]
+     911                 :            : 
+     912                 :            :         /* Test CFB decryption */
+     913         [ #  # ]:          0 :         if (verbose) {
+     914                 :          0 :             mbedtls_printf("  ARIA-CFB-%d (dec): ", 128 + 64 * i);
+     915                 :            :         }
+     916                 :          0 :         mbedtls_aria_setkey_enc(&ctx, aria_test2_key, 128 + 64 * i);
+     917                 :          0 :         memcpy(iv, aria_test2_iv, MBEDTLS_ARIA_BLOCKSIZE);
+     918                 :          0 :         memset(buf, 0xAA, sizeof(buf));
+     919                 :          0 :         j = 0;
+     920                 :          0 :         mbedtls_aria_crypt_cfb128(&ctx, MBEDTLS_ARIA_DECRYPT, 48, &j,
+     921                 :          0 :                                   iv, aria_test2_cfb_ct[i], buf);
+     922   [ #  #  #  #  :          0 :         ARIA_SELF_TEST_ASSERT(memcmp(buf, aria_test2_pt, 48) != 0);
+                   #  # ]
+     923                 :            :     }
+     924         [ #  # ]:          0 :     if (verbose) {
+     925                 :          0 :         mbedtls_printf("\n");
+     926                 :            :     }
+     927                 :            : #endif /* MBEDTLS_CIPHER_MODE_CFB */
+     928                 :            : 
+     929                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR)
+     930         [ #  # ]:          0 :     for (i = 0; i < 3; i++) {
+     931                 :            :         /* Test CTR encryption */
+     932         [ #  # ]:          0 :         if (verbose) {
+     933                 :          0 :             mbedtls_printf("  ARIA-CTR-%d (enc): ", 128 + 64 * i);
+     934                 :            :         }
+     935                 :          0 :         mbedtls_aria_setkey_enc(&ctx, aria_test2_key, 128 + 64 * i);
+     936                 :          0 :         memset(iv, 0, MBEDTLS_ARIA_BLOCKSIZE);                      // IV = 0
+     937                 :          0 :         memset(buf, 0x55, sizeof(buf));
+     938                 :          0 :         j = 0;
+     939                 :          0 :         mbedtls_aria_crypt_ctr(&ctx, 48, &j, iv, blk,
+     940                 :            :                                aria_test2_pt, buf);
+     941   [ #  #  #  #  :          0 :         ARIA_SELF_TEST_ASSERT(memcmp(buf, aria_test2_ctr_ct[i], 48) != 0);
+                   #  # ]
+     942                 :            : 
+     943                 :            :         /* Test CTR decryption */
+     944         [ #  # ]:          0 :         if (verbose) {
+     945                 :          0 :             mbedtls_printf("  ARIA-CTR-%d (dec): ", 128 + 64 * i);
+     946                 :            :         }
+     947                 :          0 :         mbedtls_aria_setkey_enc(&ctx, aria_test2_key, 128 + 64 * i);
+     948                 :          0 :         memset(iv, 0, MBEDTLS_ARIA_BLOCKSIZE);                      // IV = 0
+     949                 :          0 :         memset(buf, 0xAA, sizeof(buf));
+     950                 :          0 :         j = 0;
+     951                 :          0 :         mbedtls_aria_crypt_ctr(&ctx, 48, &j, iv, blk,
+     952                 :          0 :                                aria_test2_ctr_ct[i], buf);
+     953   [ #  #  #  #  :          0 :         ARIA_SELF_TEST_ASSERT(memcmp(buf, aria_test2_pt, 48) != 0);
+                   #  # ]
+     954                 :            :     }
+     955         [ #  # ]:          0 :     if (verbose) {
+     956                 :          0 :         mbedtls_printf("\n");
+     957                 :            :     }
+     958                 :            : #endif /* MBEDTLS_CIPHER_MODE_CTR */
+     959                 :            : 
+     960                 :          0 :     ret = 0;
+     961                 :            : 
+     962                 :          0 : exit:
+     963                 :          0 :     mbedtls_aria_free(&ctx);
+     964                 :          0 :     return ret;
+     965                 :            : }
+     966                 :            : 
+     967                 :            : #endif /* MBEDTLS_SELF_TEST */
+     968                 :            : 
+     969                 :            : #endif /* MBEDTLS_ARIA_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/asn1parse.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/asn1parse.c.func-sort-c.html new file mode 100644 index 00000000000..a27d99d07e0 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/asn1parse.c.func-sort-c.html @@ -0,0 +1,157 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/asn1parse.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - asn1parse.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:14519175.9 %
Date:2024-09-22 08:21:07Functions:161984.2 %
Branches:6511059.1 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_asn1_free_named_data0
mbedtls_asn1_get_alg_null0
mbedtls_asn1_get_enum0
mbedtls_asn1_free_named_data_list20
mbedtls_asn1_find_named_data62
mbedtls_asn1_get_mpi2870
mbedtls_asn1_get_bitstring9975
mbedtls_asn1_get_sequence_of9981
mbedtls_asn1_traverse_sequence_of9981
asn1_get_tagged_int12431
mbedtls_asn1_get_int12431
mbedtls_asn1_free_named_data_list_shallow24238
mbedtls_asn1_get_bitstring_null24383
asn1_get_sequence_of_cb28221
mbedtls_asn1_get_alg36533
mbedtls_asn1_sequence_free48476
mbedtls_asn1_get_bool66676
mbedtls_asn1_get_tag690744
mbedtls_asn1_get_len734705
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/asn1parse.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/asn1parse.c.func.html new file mode 100644 index 00000000000..cd2e6a41951 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/asn1parse.c.func.html @@ -0,0 +1,157 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/asn1parse.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - asn1parse.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:14519175.9 %
Date:2024-09-22 08:21:07Functions:161984.2 %
Branches:6511059.1 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
asn1_get_sequence_of_cb28221
asn1_get_tagged_int12431
mbedtls_asn1_find_named_data62
mbedtls_asn1_free_named_data0
mbedtls_asn1_free_named_data_list20
mbedtls_asn1_free_named_data_list_shallow24238
mbedtls_asn1_get_alg36533
mbedtls_asn1_get_alg_null0
mbedtls_asn1_get_bitstring9975
mbedtls_asn1_get_bitstring_null24383
mbedtls_asn1_get_bool66676
mbedtls_asn1_get_enum0
mbedtls_asn1_get_int12431
mbedtls_asn1_get_len734705
mbedtls_asn1_get_mpi2870
mbedtls_asn1_get_sequence_of9981
mbedtls_asn1_get_tag690744
mbedtls_asn1_sequence_free48476
mbedtls_asn1_traverse_sequence_of9981
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/asn1parse.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/asn1parse.c.gcov.html new file mode 100644 index 00000000000..25761dc0819 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/asn1parse.c.gcov.html @@ -0,0 +1,554 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/asn1parse.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - asn1parse.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:14519175.9 %
Date:2024-09-22 08:21:07Functions:161984.2 %
Branches:6511059.1 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  *  Generic ASN.1 parsing
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  */
+       7                 :            : 
+       8                 :            : #include "common.h"
+       9                 :            : 
+      10                 :            : #if defined(MBEDTLS_ASN1_PARSE_C) || defined(MBEDTLS_X509_CREATE_C) || \
+      11                 :            :     defined(MBEDTLS_PSA_UTIL_HAVE_ECDSA)
+      12                 :            : 
+      13                 :            : #include "mbedtls/asn1.h"
+      14                 :            : #include "mbedtls/platform_util.h"
+      15                 :            : #include "mbedtls/error.h"
+      16                 :            : 
+      17                 :            : #include <string.h>
+      18                 :            : 
+      19                 :            : #if defined(MBEDTLS_BIGNUM_C)
+      20                 :            : #include "mbedtls/bignum.h"
+      21                 :            : #endif
+      22                 :            : 
+      23                 :            : #include "mbedtls/platform.h"
+      24                 :            : 
+      25                 :            : /*
+      26                 :            :  * ASN.1 DER decoding routines
+      27                 :            :  */
+      28                 :     734705 : int mbedtls_asn1_get_len(unsigned char **p,
+      29                 :            :                          const unsigned char *end,
+      30                 :            :                          size_t *len)
+      31                 :            : {
+      32         [ -  + ]:     734705 :     if ((end - *p) < 1) {
+      33                 :          0 :         return MBEDTLS_ERR_ASN1_OUT_OF_DATA;
+      34                 :            :     }
+      35                 :            : 
+      36         [ +  + ]:     734705 :     if ((**p & 0x80) == 0) {
+      37                 :     677644 :         *len = *(*p)++;
+      38                 :            :     } else {
+      39                 :      57061 :         int n = (**p) & 0x7F;
+      40   [ +  -  -  + ]:      57061 :         if (n == 0 || n > 4) {
+      41                 :          0 :             return MBEDTLS_ERR_ASN1_INVALID_LENGTH;
+      42                 :            :         }
+      43         [ -  + ]:      57061 :         if ((end - *p) <= n) {
+      44                 :          0 :             return MBEDTLS_ERR_ASN1_OUT_OF_DATA;
+      45                 :            :         }
+      46                 :      57061 :         *len = 0;
+      47                 :      57061 :         (*p)++;
+      48         [ +  + ]:     152398 :         while (n--) {
+      49                 :      95337 :             *len = (*len << 8) | **p;
+      50                 :      95337 :             (*p)++;
+      51                 :            :         }
+      52                 :            :     }
+      53                 :            : 
+      54         [ -  + ]:     734705 :     if (*len > (size_t) (end - *p)) {
+      55                 :          0 :         return MBEDTLS_ERR_ASN1_OUT_OF_DATA;
+      56                 :            :     }
+      57                 :            : 
+      58                 :     734705 :     return 0;
+      59                 :            : }
+      60                 :            : 
+      61                 :     690744 : int mbedtls_asn1_get_tag(unsigned char **p,
+      62                 :            :                          const unsigned char *end,
+      63                 :            :                          size_t *len, int tag)
+      64                 :            : {
+      65         [ +  + ]:     690744 :     if ((end - *p) < 1) {
+      66                 :       1648 :         return MBEDTLS_ERR_ASN1_OUT_OF_DATA;
+      67                 :            :     }
+      68                 :            : 
+      69         [ +  + ]:     689096 :     if (**p != tag) {
+      70                 :      67503 :         return MBEDTLS_ERR_ASN1_UNEXPECTED_TAG;
+      71                 :            :     }
+      72                 :            : 
+      73                 :     621593 :     (*p)++;
+      74                 :            : 
+      75                 :     621593 :     return mbedtls_asn1_get_len(p, end, len);
+      76                 :            : }
+      77                 :            : #endif /* MBEDTLS_ASN1_PARSE_C || MBEDTLS_X509_CREATE_C || MBEDTLS_PSA_UTIL_HAVE_ECDSA */
+      78                 :            : 
+      79                 :            : #if defined(MBEDTLS_ASN1_PARSE_C)
+      80                 :      66676 : int mbedtls_asn1_get_bool(unsigned char **p,
+      81                 :            :                           const unsigned char *end,
+      82                 :            :                           int *val)
+      83                 :            : {
+      84                 :      66676 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+      85                 :            :     size_t len;
+      86                 :            : 
+      87         [ +  + ]:      66676 :     if ((ret = mbedtls_asn1_get_tag(p, end, &len, MBEDTLS_ASN1_BOOLEAN)) != 0) {
+      88                 :      42388 :         return ret;
+      89                 :            :     }
+      90                 :            : 
+      91         [ -  + ]:      24288 :     if (len != 1) {
+      92                 :          0 :         return MBEDTLS_ERR_ASN1_INVALID_LENGTH;
+      93                 :            :     }
+      94                 :            : 
+      95                 :      24288 :     *val = (**p != 0) ? 1 : 0;
+      96                 :      24288 :     (*p)++;
+      97                 :            : 
+      98                 :      24288 :     return 0;
+      99                 :            : }
+     100                 :            : 
+     101                 :      12431 : static int asn1_get_tagged_int(unsigned char **p,
+     102                 :            :                                const unsigned char *end,
+     103                 :            :                                int tag, int *val)
+     104                 :            : {
+     105                 :      12431 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     106                 :            :     size_t len;
+     107                 :            : 
+     108         [ -  + ]:      12431 :     if ((ret = mbedtls_asn1_get_tag(p, end, &len, tag)) != 0) {
+     109                 :          0 :         return ret;
+     110                 :            :     }
+     111                 :            : 
+     112                 :            :     /*
+     113                 :            :      * len==0 is malformed (0 must be represented as 020100 for INTEGER,
+     114                 :            :      * or 0A0100 for ENUMERATED tags
+     115                 :            :      */
+     116         [ -  + ]:      12431 :     if (len == 0) {
+     117                 :          0 :         return MBEDTLS_ERR_ASN1_INVALID_LENGTH;
+     118                 :            :     }
+     119                 :            :     /* This is a cryptography library. Reject negative integers. */
+     120         [ -  + ]:      12431 :     if ((**p & 0x80) != 0) {
+     121                 :          0 :         return MBEDTLS_ERR_ASN1_INVALID_LENGTH;
+     122                 :            :     }
+     123                 :            : 
+     124                 :            :     /* Skip leading zeros. */
+     125   [ +  +  +  + ]:      12609 :     while (len > 0 && **p == 0) {
+     126                 :        178 :         ++(*p);
+     127                 :        178 :         --len;
+     128                 :            :     }
+     129                 :            : 
+     130                 :            :     /* Reject integers that don't fit in an int. This code assumes that
+     131                 :            :      * the int type has no padding bit. */
+     132         [ -  + ]:      12431 :     if (len > sizeof(int)) {
+     133                 :          0 :         return MBEDTLS_ERR_ASN1_INVALID_LENGTH;
+     134                 :            :     }
+     135   [ -  +  -  - ]:      12431 :     if (len == sizeof(int) && (**p & 0x80) != 0) {
+     136                 :          0 :         return MBEDTLS_ERR_ASN1_INVALID_LENGTH;
+     137                 :            :     }
+     138                 :            : 
+     139                 :      12431 :     *val = 0;
+     140         [ +  + ]:      24684 :     while (len-- > 0) {
+     141                 :      12253 :         *val = (*val << 8) | **p;
+     142                 :      12253 :         (*p)++;
+     143                 :            :     }
+     144                 :            : 
+     145                 :      12431 :     return 0;
+     146                 :            : }
+     147                 :            : 
+     148                 :      12431 : int mbedtls_asn1_get_int(unsigned char **p,
+     149                 :            :                          const unsigned char *end,
+     150                 :            :                          int *val)
+     151                 :            : {
+     152                 :      12431 :     return asn1_get_tagged_int(p, end, MBEDTLS_ASN1_INTEGER, val);
+     153                 :            : }
+     154                 :            : 
+     155                 :          0 : int mbedtls_asn1_get_enum(unsigned char **p,
+     156                 :            :                           const unsigned char *end,
+     157                 :            :                           int *val)
+     158                 :            : {
+     159                 :          0 :     return asn1_get_tagged_int(p, end, MBEDTLS_ASN1_ENUMERATED, val);
+     160                 :            : }
+     161                 :            : 
+     162                 :            : #if defined(MBEDTLS_BIGNUM_C)
+     163                 :       2870 : int mbedtls_asn1_get_mpi(unsigned char **p,
+     164                 :            :                          const unsigned char *end,
+     165                 :            :                          mbedtls_mpi *X)
+     166                 :            : {
+     167                 :       2870 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     168                 :            :     size_t len;
+     169                 :            : 
+     170         [ -  + ]:       2870 :     if ((ret = mbedtls_asn1_get_tag(p, end, &len, MBEDTLS_ASN1_INTEGER)) != 0) {
+     171                 :          0 :         return ret;
+     172                 :            :     }
+     173                 :            : 
+     174                 :       2870 :     ret = mbedtls_mpi_read_binary(X, *p, len);
+     175                 :            : 
+     176                 :       2870 :     *p += len;
+     177                 :            : 
+     178                 :       2870 :     return ret;
+     179                 :            : }
+     180                 :            : #endif /* MBEDTLS_BIGNUM_C */
+     181                 :            : 
+     182                 :       9975 : int mbedtls_asn1_get_bitstring(unsigned char **p, const unsigned char *end,
+     183                 :            :                                mbedtls_asn1_bitstring *bs)
+     184                 :            : {
+     185                 :       9975 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     186                 :            : 
+     187                 :            :     /* Certificate type is a single byte bitstring */
+     188         [ -  + ]:       9975 :     if ((ret = mbedtls_asn1_get_tag(p, end, &bs->len, MBEDTLS_ASN1_BIT_STRING)) != 0) {
+     189                 :          0 :         return ret;
+     190                 :            :     }
+     191                 :            : 
+     192                 :            :     /* Check length, subtract one for actual bit string length */
+     193         [ -  + ]:       9975 :     if (bs->len < 1) {
+     194                 :          0 :         return MBEDTLS_ERR_ASN1_OUT_OF_DATA;
+     195                 :            :     }
+     196                 :       9975 :     bs->len -= 1;
+     197                 :            : 
+     198                 :            :     /* Get number of unused bits, ensure unused bits <= 7 */
+     199                 :       9975 :     bs->unused_bits = **p;
+     200         [ -  + ]:       9975 :     if (bs->unused_bits > 7) {
+     201                 :          0 :         return MBEDTLS_ERR_ASN1_INVALID_LENGTH;
+     202                 :            :     }
+     203                 :       9975 :     (*p)++;
+     204                 :            : 
+     205                 :            :     /* Get actual bitstring */
+     206                 :       9975 :     bs->p = *p;
+     207                 :       9975 :     *p += bs->len;
+     208                 :            : 
+     209         [ -  + ]:       9975 :     if (*p != end) {
+     210                 :          0 :         return MBEDTLS_ERR_ASN1_LENGTH_MISMATCH;
+     211                 :            :     }
+     212                 :            : 
+     213                 :       9975 :     return 0;
+     214                 :            : }
+     215                 :            : 
+     216                 :            : /*
+     217                 :            :  * Traverse an ASN.1 "SEQUENCE OF <tag>"
+     218                 :            :  * and call a callback for each entry found.
+     219                 :            :  */
+     220                 :       9981 : int mbedtls_asn1_traverse_sequence_of(
+     221                 :            :     unsigned char **p,
+     222                 :            :     const unsigned char *end,
+     223                 :            :     unsigned char tag_must_mask, unsigned char tag_must_val,
+     224                 :            :     unsigned char tag_may_mask, unsigned char tag_may_val,
+     225                 :            :     int (*cb)(void *ctx, int tag,
+     226                 :            :               unsigned char *start, size_t len),
+     227                 :            :     void *ctx)
+     228                 :            : {
+     229                 :            :     int ret;
+     230                 :            :     size_t len;
+     231                 :            : 
+     232                 :            :     /* Get main sequence tag */
+     233         [ -  + ]:       9981 :     if ((ret = mbedtls_asn1_get_tag(p, end, &len,
+     234                 :            :                                     MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
+     235                 :          0 :         return ret;
+     236                 :            :     }
+     237                 :            : 
+     238         [ -  + ]:       9981 :     if (*p + len != end) {
+     239                 :          0 :         return MBEDTLS_ERR_ASN1_LENGTH_MISMATCH;
+     240                 :            :     }
+     241                 :            : 
+     242         [ +  + ]:      38202 :     while (*p < end) {
+     243                 :      28221 :         unsigned char const tag = *(*p)++;
+     244                 :            : 
+     245         [ -  + ]:      28221 :         if ((tag & tag_must_mask) != tag_must_val) {
+     246                 :          0 :             return MBEDTLS_ERR_ASN1_UNEXPECTED_TAG;
+     247                 :            :         }
+     248                 :            : 
+     249         [ -  + ]:      28221 :         if ((ret = mbedtls_asn1_get_len(p, end, &len)) != 0) {
+     250                 :          0 :             return ret;
+     251                 :            :         }
+     252                 :            : 
+     253         [ +  - ]:      28221 :         if ((tag & tag_may_mask) == tag_may_val) {
+     254         [ +  - ]:      28221 :             if (cb != NULL) {
+     255                 :      28221 :                 ret = cb(ctx, tag, *p, len);
+     256         [ -  + ]:      28221 :                 if (ret != 0) {
+     257                 :          0 :                     return ret;
+     258                 :            :                 }
+     259                 :            :             }
+     260                 :            :         }
+     261                 :            : 
+     262                 :      28221 :         *p += len;
+     263                 :            :     }
+     264                 :            : 
+     265                 :       9981 :     return 0;
+     266                 :            : }
+     267                 :            : 
+     268                 :            : /*
+     269                 :            :  * Get a bit string without unused bits
+     270                 :            :  */
+     271                 :      24383 : int mbedtls_asn1_get_bitstring_null(unsigned char **p, const unsigned char *end,
+     272                 :            :                                     size_t *len)
+     273                 :            : {
+     274                 :      24383 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     275                 :            : 
+     276         [ -  + ]:      24383 :     if ((ret = mbedtls_asn1_get_tag(p, end, len, MBEDTLS_ASN1_BIT_STRING)) != 0) {
+     277                 :          0 :         return ret;
+     278                 :            :     }
+     279                 :            : 
+     280         [ -  + ]:      24383 :     if (*len == 0) {
+     281                 :          0 :         return MBEDTLS_ERR_ASN1_INVALID_DATA;
+     282                 :            :     }
+     283                 :      24383 :     --(*len);
+     284                 :            : 
+     285         [ -  + ]:      24383 :     if (**p != 0) {
+     286                 :          0 :         return MBEDTLS_ERR_ASN1_INVALID_DATA;
+     287                 :            :     }
+     288                 :      24383 :     ++(*p);
+     289                 :            : 
+     290                 :      24383 :     return 0;
+     291                 :            : }
+     292                 :            : 
+     293                 :      48476 : void mbedtls_asn1_sequence_free(mbedtls_asn1_sequence *seq)
+     294                 :            : {
+     295         [ +  + ]:      68194 :     while (seq != NULL) {
+     296                 :      19718 :         mbedtls_asn1_sequence *next = seq->next;
+     297                 :      19718 :         mbedtls_free(seq);
+     298                 :      19718 :         seq = next;
+     299                 :            :     }
+     300                 :      48476 : }
+     301                 :            : 
+     302                 :            : typedef struct {
+     303                 :            :     int tag;
+     304                 :            :     mbedtls_asn1_sequence *cur;
+     305                 :            : } asn1_get_sequence_of_cb_ctx_t;
+     306                 :            : 
+     307                 :      28221 : static int asn1_get_sequence_of_cb(void *ctx,
+     308                 :            :                                    int tag,
+     309                 :            :                                    unsigned char *start,
+     310                 :            :                                    size_t len)
+     311                 :            : {
+     312                 :      28221 :     asn1_get_sequence_of_cb_ctx_t *cb_ctx =
+     313                 :            :         (asn1_get_sequence_of_cb_ctx_t *) ctx;
+     314                 :      28221 :     mbedtls_asn1_sequence *cur =
+     315                 :            :         cb_ctx->cur;
+     316                 :            : 
+     317         [ +  + ]:      28221 :     if (cur->buf.p != NULL) {
+     318                 :      18240 :         cur->next =
+     319                 :      18240 :             mbedtls_calloc(1, sizeof(mbedtls_asn1_sequence));
+     320                 :            : 
+     321         [ -  + ]:      18240 :         if (cur->next == NULL) {
+     322                 :          0 :             return MBEDTLS_ERR_ASN1_ALLOC_FAILED;
+     323                 :            :         }
+     324                 :            : 
+     325                 :      18240 :         cur = cur->next;
+     326                 :            :     }
+     327                 :            : 
+     328                 :      28221 :     cur->buf.p = start;
+     329                 :      28221 :     cur->buf.len = len;
+     330                 :      28221 :     cur->buf.tag = tag;
+     331                 :            : 
+     332                 :      28221 :     cb_ctx->cur = cur;
+     333                 :      28221 :     return 0;
+     334                 :            : }
+     335                 :            : 
+     336                 :            : /*
+     337                 :            :  *  Parses and splits an ASN.1 "SEQUENCE OF <tag>"
+     338                 :            :  */
+     339                 :       9981 : int mbedtls_asn1_get_sequence_of(unsigned char **p,
+     340                 :            :                                  const unsigned char *end,
+     341                 :            :                                  mbedtls_asn1_sequence *cur,
+     342                 :            :                                  int tag)
+     343                 :            : {
+     344                 :       9981 :     asn1_get_sequence_of_cb_ctx_t cb_ctx = { tag, cur };
+     345                 :       9981 :     memset(cur, 0, sizeof(mbedtls_asn1_sequence));
+     346                 :       9981 :     return mbedtls_asn1_traverse_sequence_of(
+     347                 :            :         p, end, 0xFF, tag, 0, 0,
+     348                 :            :         asn1_get_sequence_of_cb, &cb_ctx);
+     349                 :            : }
+     350                 :            : 
+     351                 :      36533 : int mbedtls_asn1_get_alg(unsigned char **p,
+     352                 :            :                          const unsigned char *end,
+     353                 :            :                          mbedtls_asn1_buf *alg, mbedtls_asn1_buf *params)
+     354                 :            : {
+     355                 :      36533 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     356                 :            :     size_t len;
+     357                 :            : 
+     358         [ -  + ]:      36533 :     if ((ret = mbedtls_asn1_get_tag(p, end, &len,
+     359                 :            :                                     MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
+     360                 :          0 :         return ret;
+     361                 :            :     }
+     362                 :            : 
+     363         [ -  + ]:      36533 :     if ((end - *p) < 1) {
+     364                 :          0 :         return MBEDTLS_ERR_ASN1_OUT_OF_DATA;
+     365                 :            :     }
+     366                 :            : 
+     367                 :      36533 :     alg->tag = **p;
+     368                 :      36533 :     end = *p + len;
+     369                 :            : 
+     370         [ -  + ]:      36533 :     if ((ret = mbedtls_asn1_get_tag(p, end, &alg->len, MBEDTLS_ASN1_OID)) != 0) {
+     371                 :          0 :         return ret;
+     372                 :            :     }
+     373                 :            : 
+     374                 :      36533 :     alg->p = *p;
+     375                 :      36533 :     *p += alg->len;
+     376                 :            : 
+     377         [ +  + ]:      36533 :     if (*p == end) {
+     378                 :      22040 :         mbedtls_platform_zeroize(params, sizeof(mbedtls_asn1_buf));
+     379                 :      22040 :         return 0;
+     380                 :            :     }
+     381                 :            : 
+     382                 :      14493 :     params->tag = **p;
+     383                 :      14493 :     (*p)++;
+     384                 :            : 
+     385         [ -  + ]:      14493 :     if ((ret = mbedtls_asn1_get_len(p, end, &params->len)) != 0) {
+     386                 :          0 :         return ret;
+     387                 :            :     }
+     388                 :            : 
+     389                 :      14493 :     params->p = *p;
+     390                 :      14493 :     *p += params->len;
+     391                 :            : 
+     392         [ -  + ]:      14493 :     if (*p != end) {
+     393                 :          0 :         return MBEDTLS_ERR_ASN1_LENGTH_MISMATCH;
+     394                 :            :     }
+     395                 :            : 
+     396                 :      14493 :     return 0;
+     397                 :            : }
+     398                 :            : 
+     399                 :          0 : int mbedtls_asn1_get_alg_null(unsigned char **p,
+     400                 :            :                               const unsigned char *end,
+     401                 :            :                               mbedtls_asn1_buf *alg)
+     402                 :            : {
+     403                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     404                 :            :     mbedtls_asn1_buf params;
+     405                 :            : 
+     406                 :          0 :     memset(&params, 0, sizeof(mbedtls_asn1_buf));
+     407                 :            : 
+     408         [ #  # ]:          0 :     if ((ret = mbedtls_asn1_get_alg(p, end, alg, &params)) != 0) {
+     409                 :          0 :         return ret;
+     410                 :            :     }
+     411                 :            : 
+     412   [ #  #  #  #  :          0 :     if ((params.tag != MBEDTLS_ASN1_NULL && params.tag != 0) || params.len != 0) {
+                   #  # ]
+     413                 :          0 :         return MBEDTLS_ERR_ASN1_INVALID_DATA;
+     414                 :            :     }
+     415                 :            : 
+     416                 :          0 :     return 0;
+     417                 :            : }
+     418                 :            : 
+     419                 :            : #if !defined(MBEDTLS_DEPRECATED_REMOVED)
+     420                 :          0 : void mbedtls_asn1_free_named_data(mbedtls_asn1_named_data *cur)
+     421                 :            : {
+     422         [ #  # ]:          0 :     if (cur == NULL) {
+     423                 :          0 :         return;
+     424                 :            :     }
+     425                 :            : 
+     426                 :          0 :     mbedtls_free(cur->oid.p);
+     427                 :          0 :     mbedtls_free(cur->val.p);
+     428                 :            : 
+     429                 :          0 :     mbedtls_platform_zeroize(cur, sizeof(mbedtls_asn1_named_data));
+     430                 :            : }
+     431                 :            : #endif /* MBEDTLS_DEPRECATED_REMOVED */
+     432                 :            : 
+     433                 :         20 : void mbedtls_asn1_free_named_data_list(mbedtls_asn1_named_data **head)
+     434                 :            : {
+     435                 :            :     mbedtls_asn1_named_data *cur;
+     436                 :            : 
+     437         [ +  + ]:         82 :     while ((cur = *head) != NULL) {
+     438                 :         62 :         *head = cur->next;
+     439                 :         62 :         mbedtls_free(cur->oid.p);
+     440                 :         62 :         mbedtls_free(cur->val.p);
+     441                 :         62 :         mbedtls_free(cur);
+     442                 :            :     }
+     443                 :         20 : }
+     444                 :            : 
+     445                 :      24238 : void mbedtls_asn1_free_named_data_list_shallow(mbedtls_asn1_named_data *name)
+     446                 :            : {
+     447         [ +  + ]:      24358 :     for (mbedtls_asn1_named_data *next; name != NULL; name = next) {
+     448                 :        120 :         next = name->next;
+     449                 :        120 :         mbedtls_free(name);
+     450                 :            :     }
+     451                 :      24238 : }
+     452                 :            : 
+     453                 :         62 : const mbedtls_asn1_named_data *mbedtls_asn1_find_named_data(const mbedtls_asn1_named_data *list,
+     454                 :            :                                                             const char *oid, size_t len)
+     455                 :            : {
+     456         [ +  + ]:        188 :     while (list != NULL) {
+     457         [ +  + ]:        126 :         if (list->oid.len == len &&
+     458         [ -  + ]:         84 :             memcmp(list->oid.p, oid, len) == 0) {
+     459                 :          0 :             break;
+     460                 :            :         }
+     461                 :            : 
+     462                 :        126 :         list = list->next;
+     463                 :            :     }
+     464                 :            : 
+     465                 :         62 :     return list;
+     466                 :            : }
+     467                 :            : 
+     468                 :            : #endif /* MBEDTLS_ASN1_PARSE_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/asn1write.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/asn1write.c.func-sort-c.html new file mode 100644 index 00000000000..694f5c1a023 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/asn1write.c.func-sort-c.html @@ -0,0 +1,165 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/asn1write.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - asn1write.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:9017352.0 %
Date:2024-09-22 08:21:07Functions:112152.4 %
Branches:409641.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_asn1_write_algorithm_identifier0
mbedtls_asn1_write_bitstring0
mbedtls_asn1_write_bool0
mbedtls_asn1_write_enum0
mbedtls_asn1_write_ia5_string0
mbedtls_asn1_write_named_bitstring0
mbedtls_asn1_write_null0
mbedtls_asn1_write_octet_string0
mbedtls_asn1_write_printable_string0
mbedtls_asn1_write_utf8_string0
asn1_write_tagged_int6
mbedtls_asn1_write_int6
mbedtls_asn1_write_mpi12
mbedtls_asn1_write_algorithm_identifier_ext18
mbedtls_asn1_write_tagged_string18
mbedtls_asn1_write_oid54
mbedtls_asn1_store_named_data62
mbedtls_asn1_write_len_and_tag108
mbedtls_asn1_write_raw_buffer148
mbedtls_asn1_write_len336
mbedtls_asn1_write_tag336
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/asn1write.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/asn1write.c.func.html new file mode 100644 index 00000000000..08dde807bae --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/asn1write.c.func.html @@ -0,0 +1,165 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/asn1write.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - asn1write.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:9017352.0 %
Date:2024-09-22 08:21:07Functions:112152.4 %
Branches:409641.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
asn1_write_tagged_int6
mbedtls_asn1_store_named_data62
mbedtls_asn1_write_algorithm_identifier0
mbedtls_asn1_write_algorithm_identifier_ext18
mbedtls_asn1_write_bitstring0
mbedtls_asn1_write_bool0
mbedtls_asn1_write_enum0
mbedtls_asn1_write_ia5_string0
mbedtls_asn1_write_int6
mbedtls_asn1_write_len336
mbedtls_asn1_write_len_and_tag108
mbedtls_asn1_write_mpi12
mbedtls_asn1_write_named_bitstring0
mbedtls_asn1_write_null0
mbedtls_asn1_write_octet_string0
mbedtls_asn1_write_oid54
mbedtls_asn1_write_printable_string0
mbedtls_asn1_write_raw_buffer148
mbedtls_asn1_write_tag336
mbedtls_asn1_write_tagged_string18
mbedtls_asn1_write_utf8_string0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/asn1write.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/asn1write.c.gcov.html new file mode 100644 index 00000000000..ca26b81f7a9 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/asn1write.c.gcov.html @@ -0,0 +1,522 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/asn1write.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - asn1write.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:9017352.0 %
Date:2024-09-22 08:21:07Functions:112152.4 %
Branches:409641.7 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  * ASN.1 buffer writing functionality
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  */
+       7                 :            : 
+       8                 :            : #include "common.h"
+       9                 :            : 
+      10                 :            : #if defined(MBEDTLS_ASN1_WRITE_C) || defined(MBEDTLS_X509_USE_C) || \
+      11                 :            :     defined(MBEDTLS_PSA_UTIL_HAVE_ECDSA)
+      12                 :            : 
+      13                 :            : #include "mbedtls/asn1write.h"
+      14                 :            : #include "mbedtls/error.h"
+      15                 :            : 
+      16                 :            : #include <string.h>
+      17                 :            : 
+      18                 :            : #include "mbedtls/platform.h"
+      19                 :            : 
+      20                 :            : #if defined(MBEDTLS_ASN1_PARSE_C)
+      21                 :            : #include "mbedtls/asn1.h"
+      22                 :            : #endif
+      23                 :            : 
+      24                 :        336 : int mbedtls_asn1_write_len(unsigned char **p, const unsigned char *start, size_t len)
+      25                 :            : {
+      26                 :            : #if SIZE_MAX > 0xFFFFFFFF
+      27         [ -  + ]:        336 :     if (len > 0xFFFFFFFF) {
+      28                 :          0 :         return MBEDTLS_ERR_ASN1_INVALID_LENGTH;
+      29                 :            :     }
+      30                 :            : #endif
+      31                 :            : 
+      32                 :        336 :     int required = 1;
+      33                 :            : 
+      34         [ +  + ]:        336 :     if (len >= 0x80) {
+      35         [ +  + ]:         84 :         for (size_t l = len; l != 0; l >>= 8) {
+      36                 :         48 :             required++;
+      37                 :            :         }
+      38                 :            :     }
+      39                 :            : 
+      40         [ -  + ]:        336 :     if (required > (*p - start)) {
+      41                 :          0 :         return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL;
+      42                 :            :     }
+      43                 :            : 
+      44                 :            :     do {
+      45                 :        348 :         *--(*p) = MBEDTLS_BYTE_0(len);
+      46                 :        348 :         len >>= 8;
+      47         [ +  + ]:        348 :     } while (len);
+      48                 :            : 
+      49         [ +  + ]:        336 :     if (required > 1) {
+      50                 :         36 :         *--(*p) = (unsigned char) (0x80 + required - 1);
+      51                 :            :     }
+      52                 :            : 
+      53                 :        336 :     return required;
+      54                 :            : }
+      55                 :            : 
+      56                 :        336 : int mbedtls_asn1_write_tag(unsigned char **p, const unsigned char *start, unsigned char tag)
+      57                 :            : {
+      58         [ -  + ]:        336 :     if (*p - start < 1) {
+      59                 :          0 :         return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL;
+      60                 :            :     }
+      61                 :            : 
+      62                 :        336 :     *--(*p) = tag;
+      63                 :            : 
+      64                 :        336 :     return 1;
+      65                 :            : }
+      66                 :            : #endif /* MBEDTLS_ASN1_WRITE_C || MBEDTLS_X509_USE_C || MBEDTLS_PSA_UTIL_HAVE_ECDSA */
+      67                 :            : 
+      68                 :            : #if defined(MBEDTLS_ASN1_WRITE_C)
+      69                 :        108 : static int mbedtls_asn1_write_len_and_tag(unsigned char **p,
+      70                 :            :                                           const unsigned char *start,
+      71                 :            :                                           size_t len,
+      72                 :            :                                           unsigned char tag)
+      73                 :            : {
+      74                 :        108 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+      75                 :            : 
+      76         [ -  + ]:        108 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(p, start, len));
+      77         [ -  + ]:        108 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(p, start, tag));
+      78                 :            : 
+      79                 :        108 :     return (int) len;
+      80                 :            : }
+      81                 :            : 
+      82                 :        148 : int mbedtls_asn1_write_raw_buffer(unsigned char **p, const unsigned char *start,
+      83                 :            :                                   const unsigned char *buf, size_t size)
+      84                 :            : {
+      85                 :        148 :     size_t len = 0;
+      86                 :            : 
+      87   [ +  -  -  + ]:        148 :     if (*p < start || (size_t) (*p - start) < size) {
+      88                 :          0 :         return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL;
+      89                 :            :     }
+      90                 :            : 
+      91                 :        148 :     len = size;
+      92                 :        148 :     (*p) -= len;
+      93                 :        148 :     memcpy(*p, buf, len);
+      94                 :            : 
+      95                 :        148 :     return (int) len;
+      96                 :            : }
+      97                 :            : 
+      98                 :            : #if defined(MBEDTLS_BIGNUM_C)
+      99                 :         12 : int mbedtls_asn1_write_mpi(unsigned char **p, const unsigned char *start, const mbedtls_mpi *X)
+     100                 :            : {
+     101                 :         12 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     102                 :         12 :     size_t len = 0;
+     103                 :            : 
+     104                 :            :     // Write the MPI
+     105                 :            :     //
+     106                 :         12 :     len = mbedtls_mpi_size(X);
+     107                 :            : 
+     108                 :            :     /* DER represents 0 with a sign bit (0=nonnegative) and 7 value bits, not
+     109                 :            :      * as 0 digits. We need to end up with 020100, not with 0200. */
+     110         [ -  + ]:         12 :     if (len == 0) {
+     111                 :          0 :         len = 1;
+     112                 :            :     }
+     113                 :            : 
+     114   [ +  -  -  + ]:         12 :     if (*p < start || (size_t) (*p - start) < len) {
+     115                 :          0 :         return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL;
+     116                 :            :     }
+     117                 :            : 
+     118                 :         12 :     (*p) -= len;
+     119         [ -  + ]:         12 :     MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(X, *p, len));
+     120                 :            : 
+     121                 :            :     // DER format assumes 2s complement for numbers, so the leftmost bit
+     122                 :            :     // should be 0 for positive numbers and 1 for negative numbers.
+     123                 :            :     //
+     124   [ +  -  +  + ]:         12 :     if (X->s == 1 && **p & 0x80) {
+     125         [ -  + ]:          4 :         if (*p - start < 1) {
+     126                 :          0 :             return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL;
+     127                 :            :         }
+     128                 :            : 
+     129                 :          4 :         *--(*p) = 0x00;
+     130                 :          4 :         len += 1;
+     131                 :            :     }
+     132                 :            : 
+     133                 :         12 :     ret = mbedtls_asn1_write_len_and_tag(p, start, len, MBEDTLS_ASN1_INTEGER);
+     134                 :            : 
+     135                 :         12 : cleanup:
+     136                 :         12 :     return ret;
+     137                 :            : }
+     138                 :            : #endif /* MBEDTLS_BIGNUM_C */
+     139                 :            : 
+     140                 :          0 : int mbedtls_asn1_write_null(unsigned char **p, const unsigned char *start)
+     141                 :            : {
+     142                 :            :     // Write NULL
+     143                 :            :     //
+     144                 :          0 :     return mbedtls_asn1_write_len_and_tag(p, start, 0, MBEDTLS_ASN1_NULL);
+     145                 :            : }
+     146                 :            : 
+     147                 :         54 : int mbedtls_asn1_write_oid(unsigned char **p, const unsigned char *start,
+     148                 :            :                            const char *oid, size_t oid_len)
+     149                 :            : {
+     150                 :         54 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     151                 :         54 :     size_t len = 0;
+     152                 :            : 
+     153         [ -  + ]:         54 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_raw_buffer(p, start,
+     154                 :            :                                                             (const unsigned char *) oid, oid_len));
+     155                 :         54 :     return mbedtls_asn1_write_len_and_tag(p, start, len, MBEDTLS_ASN1_OID);
+     156                 :            : }
+     157                 :            : 
+     158                 :          0 : int mbedtls_asn1_write_algorithm_identifier(unsigned char **p, const unsigned char *start,
+     159                 :            :                                             const char *oid, size_t oid_len,
+     160                 :            :                                             size_t par_len)
+     161                 :            : {
+     162                 :          0 :     return mbedtls_asn1_write_algorithm_identifier_ext(p, start, oid, oid_len, par_len, 1);
+     163                 :            : }
+     164                 :            : 
+     165                 :         18 : int mbedtls_asn1_write_algorithm_identifier_ext(unsigned char **p, const unsigned char *start,
+     166                 :            :                                                 const char *oid, size_t oid_len,
+     167                 :            :                                                 size_t par_len, int has_par)
+     168                 :            : {
+     169                 :         18 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     170                 :         18 :     size_t len = 0;
+     171                 :            : 
+     172         [ +  + ]:         18 :     if (has_par) {
+     173         [ -  + ]:         12 :         if (par_len == 0) {
+     174         [ #  # ]:          0 :             MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_null(p, start));
+     175                 :            :         } else {
+     176                 :         12 :             len += par_len;
+     177                 :            :         }
+     178                 :            :     }
+     179                 :            : 
+     180         [ -  + ]:         18 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_oid(p, start, oid, oid_len));
+     181                 :            : 
+     182                 :         18 :     return mbedtls_asn1_write_len_and_tag(p, start, len,
+     183                 :            :                                           MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE);
+     184                 :            : }
+     185                 :            : 
+     186                 :          0 : int mbedtls_asn1_write_bool(unsigned char **p, const unsigned char *start, int boolean)
+     187                 :            : {
+     188                 :          0 :     size_t len = 0;
+     189                 :            : 
+     190         [ #  # ]:          0 :     if (*p - start < 1) {
+     191                 :          0 :         return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL;
+     192                 :            :     }
+     193                 :            : 
+     194         [ #  # ]:          0 :     *--(*p) = (boolean) ? 255 : 0;
+     195                 :          0 :     len++;
+     196                 :            : 
+     197                 :          0 :     return mbedtls_asn1_write_len_and_tag(p, start, len, MBEDTLS_ASN1_BOOLEAN);
+     198                 :            : }
+     199                 :            : 
+     200                 :          6 : static int asn1_write_tagged_int(unsigned char **p, const unsigned char *start, int val, int tag)
+     201                 :            : {
+     202                 :          6 :     size_t len = 0;
+     203                 :            : 
+     204                 :            :     do {
+     205         [ -  + ]:          6 :         if (*p - start < 1) {
+     206                 :          0 :             return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL;
+     207                 :            :         }
+     208                 :          6 :         len += 1;
+     209                 :          6 :         *--(*p) = val & 0xff;
+     210                 :          6 :         val >>= 8;
+     211         [ -  + ]:          6 :     } while (val > 0);
+     212                 :            : 
+     213         [ -  + ]:          6 :     if (**p & 0x80) {
+     214         [ #  # ]:          0 :         if (*p - start < 1) {
+     215                 :          0 :             return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL;
+     216                 :            :         }
+     217                 :          0 :         *--(*p) = 0x00;
+     218                 :          0 :         len += 1;
+     219                 :            :     }
+     220                 :            : 
+     221                 :          6 :     return mbedtls_asn1_write_len_and_tag(p, start, len, tag);
+     222                 :            : }
+     223                 :            : 
+     224                 :          6 : int mbedtls_asn1_write_int(unsigned char **p, const unsigned char *start, int val)
+     225                 :            : {
+     226                 :          6 :     return asn1_write_tagged_int(p, start, val, MBEDTLS_ASN1_INTEGER);
+     227                 :            : }
+     228                 :            : 
+     229                 :          0 : int mbedtls_asn1_write_enum(unsigned char **p, const unsigned char *start, int val)
+     230                 :            : {
+     231                 :          0 :     return asn1_write_tagged_int(p, start, val, MBEDTLS_ASN1_ENUMERATED);
+     232                 :            : }
+     233                 :            : 
+     234                 :         18 : int mbedtls_asn1_write_tagged_string(unsigned char **p, const unsigned char *start, int tag,
+     235                 :            :                                      const char *text, size_t text_len)
+     236                 :            : {
+     237                 :         18 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     238                 :         18 :     size_t len = 0;
+     239                 :            : 
+     240         [ -  + ]:         18 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_raw_buffer(p, start,
+     241                 :            :                                                             (const unsigned char *) text,
+     242                 :            :                                                             text_len));
+     243                 :            : 
+     244                 :         18 :     return mbedtls_asn1_write_len_and_tag(p, start, len, tag);
+     245                 :            : }
+     246                 :            : 
+     247                 :          0 : int mbedtls_asn1_write_utf8_string(unsigned char **p, const unsigned char *start,
+     248                 :            :                                    const char *text, size_t text_len)
+     249                 :            : {
+     250                 :          0 :     return mbedtls_asn1_write_tagged_string(p, start, MBEDTLS_ASN1_UTF8_STRING, text, text_len);
+     251                 :            : }
+     252                 :            : 
+     253                 :          0 : int mbedtls_asn1_write_printable_string(unsigned char **p, const unsigned char *start,
+     254                 :            :                                         const char *text, size_t text_len)
+     255                 :            : {
+     256                 :          0 :     return mbedtls_asn1_write_tagged_string(p, start, MBEDTLS_ASN1_PRINTABLE_STRING, text,
+     257                 :            :                                             text_len);
+     258                 :            : }
+     259                 :            : 
+     260                 :          0 : int mbedtls_asn1_write_ia5_string(unsigned char **p, const unsigned char *start,
+     261                 :            :                                   const char *text, size_t text_len)
+     262                 :            : {
+     263                 :          0 :     return mbedtls_asn1_write_tagged_string(p, start, MBEDTLS_ASN1_IA5_STRING, text, text_len);
+     264                 :            : }
+     265                 :            : 
+     266                 :          0 : int mbedtls_asn1_write_named_bitstring(unsigned char **p,
+     267                 :            :                                        const unsigned char *start,
+     268                 :            :                                        const unsigned char *buf,
+     269                 :            :                                        size_t bits)
+     270                 :            : {
+     271                 :            :     size_t unused_bits, byte_len;
+     272                 :            :     const unsigned char *cur_byte;
+     273                 :            :     unsigned char cur_byte_shifted;
+     274                 :            :     unsigned char bit;
+     275                 :            : 
+     276                 :          0 :     byte_len = (bits + 7) / 8;
+     277                 :          0 :     unused_bits = (byte_len * 8) - bits;
+     278                 :            : 
+     279                 :            :     /*
+     280                 :            :      * Named bitstrings require that trailing 0s are excluded in the encoding
+     281                 :            :      * of the bitstring. Trailing 0s are considered part of the 'unused' bits
+     282                 :            :      * when encoding this value in the first content octet
+     283                 :            :      */
+     284         [ #  # ]:          0 :     if (bits != 0) {
+     285                 :          0 :         cur_byte = buf + byte_len - 1;
+     286                 :          0 :         cur_byte_shifted = *cur_byte >> unused_bits;
+     287                 :            : 
+     288                 :            :         for (;;) {
+     289                 :          0 :             bit = cur_byte_shifted & 0x1;
+     290                 :          0 :             cur_byte_shifted >>= 1;
+     291                 :            : 
+     292         [ #  # ]:          0 :             if (bit != 0) {
+     293                 :          0 :                 break;
+     294                 :            :             }
+     295                 :            : 
+     296                 :          0 :             bits--;
+     297         [ #  # ]:          0 :             if (bits == 0) {
+     298                 :          0 :                 break;
+     299                 :            :             }
+     300                 :            : 
+     301         [ #  # ]:          0 :             if (bits % 8 == 0) {
+     302                 :          0 :                 cur_byte_shifted = *--cur_byte;
+     303                 :            :             }
+     304                 :            :         }
+     305                 :            :     }
+     306                 :            : 
+     307                 :          0 :     return mbedtls_asn1_write_bitstring(p, start, buf, bits);
+     308                 :            : }
+     309                 :            : 
+     310                 :          0 : int mbedtls_asn1_write_bitstring(unsigned char **p, const unsigned char *start,
+     311                 :            :                                  const unsigned char *buf, size_t bits)
+     312                 :            : {
+     313                 :          0 :     size_t len = 0;
+     314                 :            :     size_t unused_bits, byte_len;
+     315                 :            : 
+     316                 :          0 :     byte_len = (bits + 7) / 8;
+     317                 :          0 :     unused_bits = (byte_len * 8) - bits;
+     318                 :            : 
+     319   [ #  #  #  # ]:          0 :     if (*p < start || (size_t) (*p - start) < byte_len + 1) {
+     320                 :          0 :         return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL;
+     321                 :            :     }
+     322                 :            : 
+     323                 :          0 :     len = byte_len + 1;
+     324                 :            : 
+     325                 :            :     /* Write the bitstring. Ensure the unused bits are zeroed */
+     326         [ #  # ]:          0 :     if (byte_len > 0) {
+     327                 :          0 :         byte_len--;
+     328                 :          0 :         *--(*p) = buf[byte_len] & ~((0x1 << unused_bits) - 1);
+     329                 :          0 :         (*p) -= byte_len;
+     330                 :          0 :         memcpy(*p, buf, byte_len);
+     331                 :            :     }
+     332                 :            : 
+     333                 :            :     /* Write unused bits */
+     334                 :          0 :     *--(*p) = (unsigned char) unused_bits;
+     335                 :            : 
+     336                 :          0 :     return mbedtls_asn1_write_len_and_tag(p, start, len, MBEDTLS_ASN1_BIT_STRING);
+     337                 :            : }
+     338                 :            : 
+     339                 :          0 : int mbedtls_asn1_write_octet_string(unsigned char **p, const unsigned char *start,
+     340                 :            :                                     const unsigned char *buf, size_t size)
+     341                 :            : {
+     342                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     343                 :          0 :     size_t len = 0;
+     344                 :            : 
+     345         [ #  # ]:          0 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_raw_buffer(p, start, buf, size));
+     346                 :            : 
+     347                 :          0 :     return mbedtls_asn1_write_len_and_tag(p, start, len, MBEDTLS_ASN1_OCTET_STRING);
+     348                 :            : }
+     349                 :            : 
+     350                 :            : 
+     351                 :            : #if !defined(MBEDTLS_ASN1_PARSE_C)
+     352                 :            : /* This is a copy of the ASN.1 parsing function mbedtls_asn1_find_named_data(),
+     353                 :            :  * which is replicated to avoid a dependency ASN1_WRITE_C on ASN1_PARSE_C. */
+     354                 :            : static mbedtls_asn1_named_data *asn1_find_named_data(
+     355                 :            :     mbedtls_asn1_named_data *list,
+     356                 :            :     const char *oid, size_t len)
+     357                 :            : {
+     358                 :            :     while (list != NULL) {
+     359                 :            :         if (list->oid.len == len &&
+     360                 :            :             memcmp(list->oid.p, oid, len) == 0) {
+     361                 :            :             break;
+     362                 :            :         }
+     363                 :            : 
+     364                 :            :         list = list->next;
+     365                 :            :     }
+     366                 :            : 
+     367                 :            :     return list;
+     368                 :            : }
+     369                 :            : #else
+     370                 :            : #define asn1_find_named_data(list, oid, len) \
+     371                 :            :     ((mbedtls_asn1_named_data *) mbedtls_asn1_find_named_data(list, oid, len))
+     372                 :            : #endif
+     373                 :            : 
+     374                 :         62 : mbedtls_asn1_named_data *mbedtls_asn1_store_named_data(
+     375                 :            :     mbedtls_asn1_named_data **head,
+     376                 :            :     const char *oid, size_t oid_len,
+     377                 :            :     const unsigned char *val,
+     378                 :            :     size_t val_len)
+     379                 :            : {
+     380                 :            :     mbedtls_asn1_named_data *cur;
+     381                 :            : 
+     382         [ +  - ]:         62 :     if ((cur = asn1_find_named_data(*head, oid, oid_len)) == NULL) {
+     383                 :            :         // Add new entry if not present yet based on OID
+     384                 :            :         //
+     385                 :         62 :         cur = (mbedtls_asn1_named_data *) mbedtls_calloc(1,
+     386                 :            :                                                          sizeof(mbedtls_asn1_named_data));
+     387         [ -  + ]:         62 :         if (cur == NULL) {
+     388                 :          0 :             return NULL;
+     389                 :            :         }
+     390                 :            : 
+     391                 :         62 :         cur->oid.len = oid_len;
+     392                 :         62 :         cur->oid.p = mbedtls_calloc(1, oid_len);
+     393         [ -  + ]:         62 :         if (cur->oid.p == NULL) {
+     394                 :          0 :             mbedtls_free(cur);
+     395                 :          0 :             return NULL;
+     396                 :            :         }
+     397                 :            : 
+     398                 :         62 :         memcpy(cur->oid.p, oid, oid_len);
+     399                 :            : 
+     400                 :         62 :         cur->val.len = val_len;
+     401         [ +  - ]:         62 :         if (val_len != 0) {
+     402                 :         62 :             cur->val.p = mbedtls_calloc(1, val_len);
+     403         [ -  + ]:         62 :             if (cur->val.p == NULL) {
+     404                 :          0 :                 mbedtls_free(cur->oid.p);
+     405                 :          0 :                 mbedtls_free(cur);
+     406                 :          0 :                 return NULL;
+     407                 :            :             }
+     408                 :            :         }
+     409                 :            : 
+     410                 :         62 :         cur->next = *head;
+     411                 :         62 :         *head = cur;
+     412         [ #  # ]:          0 :     } else if (val_len == 0) {
+     413                 :          0 :         mbedtls_free(cur->val.p);
+     414                 :          0 :         cur->val.p = NULL;
+     415         [ #  # ]:          0 :     } else if (cur->val.len != val_len) {
+     416                 :            :         /*
+     417                 :            :          * Enlarge existing value buffer if needed
+     418                 :            :          * Preserve old data until the allocation succeeded, to leave list in
+     419                 :            :          * a consistent state in case allocation fails.
+     420                 :            :          */
+     421                 :          0 :         void *p = mbedtls_calloc(1, val_len);
+     422         [ #  # ]:          0 :         if (p == NULL) {
+     423                 :          0 :             return NULL;
+     424                 :            :         }
+     425                 :            : 
+     426                 :          0 :         mbedtls_free(cur->val.p);
+     427                 :          0 :         cur->val.p = p;
+     428                 :          0 :         cur->val.len = val_len;
+     429                 :            :     }
+     430                 :            : 
+     431   [ +  +  +  - ]:         62 :     if (val != NULL && val_len != 0) {
+     432                 :         24 :         memcpy(cur->val.p, val, val_len);
+     433                 :            :     }
+     434                 :            : 
+     435                 :         62 :     return cur;
+     436                 :            : }
+     437                 :            : #endif /* MBEDTLS_ASN1_WRITE_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/base64.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/base64.c.func-sort-c.html new file mode 100644 index 00000000000..4c6eaa128a4 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/base64.c.func-sort-c.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/base64.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - base64.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:4912539.2 %
Date:2024-09-22 08:21:07Functions:2540.0 %
Branches:338439.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_base64_encode0
mbedtls_base64_self_test0
mbedtls_ct_base64_enc_char0
mbedtls_base64_decode306
mbedtls_ct_base64_dec_value192456
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/base64.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/base64.c.func.html new file mode 100644 index 00000000000..9e8e7574523 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/base64.c.func.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/base64.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - base64.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:4912539.2 %
Date:2024-09-22 08:21:07Functions:2540.0 %
Branches:338439.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_base64_decode306
mbedtls_base64_encode0
mbedtls_base64_self_test0
mbedtls_ct_base64_dec_value192456
mbedtls_ct_base64_enc_char0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/base64.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/base64.c.gcov.html new file mode 100644 index 00000000000..f2231f3ca34 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/base64.c.gcov.html @@ -0,0 +1,385 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/base64.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - base64.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:4912539.2 %
Date:2024-09-22 08:21:07Functions:2540.0 %
Branches:338439.3 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  *  RFC 1521 base64 encoding/decoding
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  */
+       7                 :            : 
+       8                 :            : #include <limits.h>
+       9                 :            : 
+      10                 :            : #include "common.h"
+      11                 :            : 
+      12                 :            : #if defined(MBEDTLS_BASE64_C)
+      13                 :            : 
+      14                 :            : #include "mbedtls/base64.h"
+      15                 :            : #include "base64_internal.h"
+      16                 :            : #include "constant_time_internal.h"
+      17                 :            : 
+      18                 :            : #include <stdint.h>
+      19                 :            : 
+      20                 :            : #if defined(MBEDTLS_SELF_TEST)
+      21                 :            : #include <string.h>
+      22                 :            : #include "mbedtls/platform.h"
+      23                 :            : #endif /* MBEDTLS_SELF_TEST */
+      24                 :            : 
+      25                 :            : MBEDTLS_STATIC_TESTABLE
+      26                 :          0 : unsigned char mbedtls_ct_base64_enc_char(unsigned char value)
+      27                 :            : {
+      28                 :          0 :     unsigned char digit = 0;
+      29                 :            :     /* For each range of values, if value is in that range, mask digit with
+      30                 :            :      * the corresponding value. Since value can only be in a single range,
+      31                 :            :      * only at most one masking will change digit. */
+      32                 :          0 :     digit |= mbedtls_ct_uchar_in_range_if(0, 25, value, 'A' + value);
+      33                 :          0 :     digit |= mbedtls_ct_uchar_in_range_if(26, 51, value, 'a' + value - 26);
+      34                 :          0 :     digit |= mbedtls_ct_uchar_in_range_if(52, 61, value, '0' + value - 52);
+      35                 :          0 :     digit |= mbedtls_ct_uchar_in_range_if(62, 62, value, '+');
+      36                 :          0 :     digit |= mbedtls_ct_uchar_in_range_if(63, 63, value, '/');
+      37                 :          0 :     return digit;
+      38                 :            : }
+      39                 :            : 
+      40                 :            : MBEDTLS_STATIC_TESTABLE
+      41                 :     192456 : signed char mbedtls_ct_base64_dec_value(unsigned char c)
+      42                 :            : {
+      43                 :     192456 :     unsigned char val = 0;
+      44                 :            :     /* For each range of digits, if c is in that range, mask val with
+      45                 :            :      * the corresponding value. Since c can only be in a single range,
+      46                 :            :      * only at most one masking will change val. Set val to one plus
+      47                 :            :      * the desired value so that it stays 0 if c is in none of the ranges. */
+      48                 :     192456 :     val |= mbedtls_ct_uchar_in_range_if('A', 'Z', c, c - 'A' +  0 + 1);
+      49                 :     192456 :     val |= mbedtls_ct_uchar_in_range_if('a', 'z', c, c - 'a' + 26 + 1);
+      50                 :     192456 :     val |= mbedtls_ct_uchar_in_range_if('0', '9', c, c - '0' + 52 + 1);
+      51                 :     192456 :     val |= mbedtls_ct_uchar_in_range_if('+', '+', c, c - '+' + 62 + 1);
+      52                 :     192456 :     val |= mbedtls_ct_uchar_in_range_if('/', '/', c, c - '/' + 63 + 1);
+      53                 :            :     /* At this point, val is 0 if c is an invalid digit and v+1 if c is
+      54                 :            :      * a digit with the value v. */
+      55                 :     192456 :     return val - 1;
+      56                 :            : }
+      57                 :            : 
+      58                 :            : /*
+      59                 :            :  * Encode a buffer into base64 format
+      60                 :            :  */
+      61                 :          0 : int mbedtls_base64_encode(unsigned char *dst, size_t dlen, size_t *olen,
+      62                 :            :                           const unsigned char *src, size_t slen)
+      63                 :            : {
+      64                 :            :     size_t i, n;
+      65                 :            :     int C1, C2, C3;
+      66                 :            :     unsigned char *p;
+      67                 :            : 
+      68         [ #  # ]:          0 :     if (slen == 0) {
+      69                 :          0 :         *olen = 0;
+      70                 :          0 :         return 0;
+      71                 :            :     }
+      72                 :            : 
+      73                 :          0 :     n = slen / 3 + (slen % 3 != 0);
+      74                 :            : 
+      75         [ #  # ]:          0 :     if (n > (SIZE_MAX - 1) / 4) {
+      76                 :          0 :         *olen = SIZE_MAX;
+      77                 :          0 :         return MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL;
+      78                 :            :     }
+      79                 :            : 
+      80                 :          0 :     n *= 4;
+      81                 :            : 
+      82   [ #  #  #  # ]:          0 :     if ((dlen < n + 1) || (NULL == dst)) {
+      83                 :          0 :         *olen = n + 1;
+      84                 :          0 :         return MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL;
+      85                 :            :     }
+      86                 :            : 
+      87                 :          0 :     n = (slen / 3) * 3;
+      88                 :            : 
+      89         [ #  # ]:          0 :     for (i = 0, p = dst; i < n; i += 3) {
+      90                 :          0 :         C1 = *src++;
+      91                 :          0 :         C2 = *src++;
+      92                 :          0 :         C3 = *src++;
+      93                 :            : 
+      94                 :          0 :         *p++ = mbedtls_ct_base64_enc_char((C1 >> 2) & 0x3F);
+      95                 :          0 :         *p++ = mbedtls_ct_base64_enc_char((((C1 &  3) << 4) + (C2 >> 4))
+      96                 :          0 :                                           & 0x3F);
+      97                 :          0 :         *p++ = mbedtls_ct_base64_enc_char((((C2 & 15) << 2) + (C3 >> 6))
+      98                 :          0 :                                           & 0x3F);
+      99                 :          0 :         *p++ = mbedtls_ct_base64_enc_char(C3 & 0x3F);
+     100                 :            :     }
+     101                 :            : 
+     102         [ #  # ]:          0 :     if (i < slen) {
+     103                 :          0 :         C1 = *src++;
+     104         [ #  # ]:          0 :         C2 = ((i + 1) < slen) ? *src++ : 0;
+     105                 :            : 
+     106                 :          0 :         *p++ = mbedtls_ct_base64_enc_char((C1 >> 2) & 0x3F);
+     107                 :          0 :         *p++ = mbedtls_ct_base64_enc_char((((C1 & 3) << 4) + (C2 >> 4))
+     108                 :          0 :                                           & 0x3F);
+     109                 :            : 
+     110         [ #  # ]:          0 :         if ((i + 1) < slen) {
+     111                 :          0 :             *p++ = mbedtls_ct_base64_enc_char(((C2 & 15) << 2) & 0x3F);
+     112                 :            :         } else {
+     113                 :          0 :             *p++ = '=';
+     114                 :            :         }
+     115                 :            : 
+     116                 :          0 :         *p++ = '=';
+     117                 :            :     }
+     118                 :            : 
+     119                 :          0 :     *olen = (size_t) (p - dst);
+     120                 :          0 :     *p = 0;
+     121                 :            : 
+     122                 :          0 :     return 0;
+     123                 :            : }
+     124                 :            : 
+     125                 :            : /*
+     126                 :            :  * Decode a base64-formatted buffer
+     127                 :            :  */
+     128                 :        306 : int mbedtls_base64_decode(unsigned char *dst, size_t dlen, size_t *olen,
+     129                 :            :                           const unsigned char *src, size_t slen)
+     130                 :            : {
+     131                 :            :     size_t i; /* index in source */
+     132                 :            :     size_t n; /* number of digits or trailing = in source */
+     133                 :            :     uint32_t x; /* value accumulator */
+     134                 :        306 :     unsigned accumulated_digits = 0;
+     135                 :        306 :     unsigned equals = 0;
+     136                 :        306 :     int spaces_present = 0;
+     137                 :            :     unsigned char *p;
+     138                 :            : 
+     139                 :            :     /* First pass: check for validity and get output length */
+     140         [ +  + ]:     132746 :     for (i = n = 0; i < slen; i++) {
+     141                 :            :         /* Skip spaces before checking for EOL */
+     142                 :     132440 :         spaces_present = 0;
+     143   [ +  -  -  + ]:     132440 :         while (i < slen && src[i] == ' ') {
+     144                 :          0 :             ++i;
+     145                 :          0 :             spaces_present = 1;
+     146                 :            :         }
+     147                 :            : 
+     148                 :            :         /* Spaces at end of buffer are OK */
+     149         [ -  + ]:     132440 :         if (i == slen) {
+     150                 :          0 :             break;
+     151                 :            :         }
+     152                 :            : 
+     153         [ +  + ]:     132440 :         if ((slen - i) >= 2 &&
+     154   [ +  +  +  - ]:     132134 :             src[i] == '\r' && src[i + 1] == '\n') {
+     155                 :       2068 :             continue;
+     156                 :            :         }
+     157                 :            : 
+     158         [ +  + ]:     130372 :         if (src[i] == '\n') {
+     159                 :       2068 :             continue;
+     160                 :            :         }
+     161                 :            : 
+     162                 :            :         /* Space inside a line is an error */
+     163         [ -  + ]:     128304 :         if (spaces_present) {
+     164                 :          0 :             return MBEDTLS_ERR_BASE64_INVALID_CHARACTER;
+     165                 :            :         }
+     166                 :            : 
+     167         [ -  + ]:     128304 :         if (src[i] > 127) {
+     168                 :          0 :             return MBEDTLS_ERR_BASE64_INVALID_CHARACTER;
+     169                 :            :         }
+     170                 :            : 
+     171         [ -  + ]:     128304 :         if (src[i] == '=') {
+     172         [ #  # ]:          0 :             if (++equals > 2) {
+     173                 :          0 :                 return MBEDTLS_ERR_BASE64_INVALID_CHARACTER;
+     174                 :            :             }
+     175                 :            :         } else {
+     176         [ -  + ]:     128304 :             if (equals != 0) {
+     177                 :          0 :                 return MBEDTLS_ERR_BASE64_INVALID_CHARACTER;
+     178                 :            :             }
+     179         [ -  + ]:     128304 :             if (mbedtls_ct_base64_dec_value(src[i]) < 0) {
+     180                 :          0 :                 return MBEDTLS_ERR_BASE64_INVALID_CHARACTER;
+     181                 :            :             }
+     182                 :            :         }
+     183                 :     128304 :         n++;
+     184                 :            :     }
+     185                 :            : 
+     186         [ -  + ]:        306 :     if (n == 0) {
+     187                 :          0 :         *olen = 0;
+     188                 :          0 :         return 0;
+     189                 :            :     }
+     190                 :            : 
+     191                 :            :     /* The following expression is to calculate the following formula without
+     192                 :            :      * risk of integer overflow in n:
+     193                 :            :      *     n = ( ( n * 6 ) + 7 ) >> 3;
+     194                 :            :      */
+     195                 :        306 :     n = (6 * (n >> 3)) + ((6 * (n & 0x7) + 7) >> 3);
+     196                 :        306 :     n -= equals;
+     197                 :            : 
+     198   [ +  +  -  + ]:        306 :     if (dst == NULL || dlen < n) {
+     199                 :        153 :         *olen = n;
+     200                 :        153 :         return MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL;
+     201                 :            :     }
+     202                 :            : 
+     203                 :        153 :     equals = 0;
+     204         [ +  + ]:      66373 :     for (x = 0, p = dst; i > 0; i--, src++) {
+     205   [ +  +  +  +  :      66220 :         if (*src == '\r' || *src == '\n' || *src == ' ') {
+                   -  + ]
+     206                 :       2068 :             continue;
+     207                 :            :         }
+     208                 :            : 
+     209                 :      64152 :         x = x << 6;
+     210         [ -  + ]:      64152 :         if (*src == '=') {
+     211                 :          0 :             ++equals;
+     212                 :            :         } else {
+     213                 :      64152 :             x |= mbedtls_ct_base64_dec_value(*src);
+     214                 :            :         }
+     215                 :            : 
+     216         [ +  + ]:      64152 :         if (++accumulated_digits == 4) {
+     217                 :      16038 :             accumulated_digits = 0;
+     218                 :      16038 :             *p++ = MBEDTLS_BYTE_2(x);
+     219         [ +  - ]:      16038 :             if (equals <= 1) {
+     220                 :      16038 :                 *p++ = MBEDTLS_BYTE_1(x);
+     221                 :            :             }
+     222         [ +  - ]:      16038 :             if (equals <= 0) {
+     223                 :      16038 :                 *p++ = MBEDTLS_BYTE_0(x);
+     224                 :            :             }
+     225                 :            :         }
+     226                 :            :     }
+     227                 :            : 
+     228                 :        153 :     *olen = (size_t) (p - dst);
+     229                 :            : 
+     230                 :        153 :     return 0;
+     231                 :            : }
+     232                 :            : 
+     233                 :            : #if defined(MBEDTLS_SELF_TEST)
+     234                 :            : 
+     235                 :            : static const unsigned char base64_test_dec[64] =
+     236                 :            : {
+     237                 :            :     0x24, 0x48, 0x6E, 0x56, 0x87, 0x62, 0x5A, 0xBD,
+     238                 :            :     0xBF, 0x17, 0xD9, 0xA2, 0xC4, 0x17, 0x1A, 0x01,
+     239                 :            :     0x94, 0xED, 0x8F, 0x1E, 0x11, 0xB3, 0xD7, 0x09,
+     240                 :            :     0x0C, 0xB6, 0xE9, 0x10, 0x6F, 0x22, 0xEE, 0x13,
+     241                 :            :     0xCA, 0xB3, 0x07, 0x05, 0x76, 0xC9, 0xFA, 0x31,
+     242                 :            :     0x6C, 0x08, 0x34, 0xFF, 0x8D, 0xC2, 0x6C, 0x38,
+     243                 :            :     0x00, 0x43, 0xE9, 0x54, 0x97, 0xAF, 0x50, 0x4B,
+     244                 :            :     0xD1, 0x41, 0xBA, 0x95, 0x31, 0x5A, 0x0B, 0x97
+     245                 :            : };
+     246                 :            : 
+     247                 :            : static const unsigned char base64_test_enc[] =
+     248                 :            :     "JEhuVodiWr2/F9mixBcaAZTtjx4Rs9cJDLbpEG8i7hPK"
+     249                 :            :     "swcFdsn6MWwINP+Nwmw4AEPpVJevUEvRQbqVMVoLlw==";
+     250                 :            : 
+     251                 :            : /*
+     252                 :            :  * Checkup routine
+     253                 :            :  */
+     254                 :          0 : int mbedtls_base64_self_test(int verbose)
+     255                 :            : {
+     256                 :            :     size_t len;
+     257                 :            :     const unsigned char *src;
+     258                 :            :     unsigned char buffer[128];
+     259                 :            : 
+     260         [ #  # ]:          0 :     if (verbose != 0) {
+     261                 :          0 :         mbedtls_printf("  Base64 encoding test: ");
+     262                 :            :     }
+     263                 :            : 
+     264                 :          0 :     src = base64_test_dec;
+     265                 :            : 
+     266         [ #  # ]:          0 :     if (mbedtls_base64_encode(buffer, sizeof(buffer), &len, src, 64) != 0 ||
+     267         [ #  # ]:          0 :         memcmp(base64_test_enc, buffer, 88) != 0) {
+     268         [ #  # ]:          0 :         if (verbose != 0) {
+     269                 :          0 :             mbedtls_printf("failed\n");
+     270                 :            :         }
+     271                 :            : 
+     272                 :          0 :         return 1;
+     273                 :            :     }
+     274                 :            : 
+     275         [ #  # ]:          0 :     if (verbose != 0) {
+     276                 :          0 :         mbedtls_printf("passed\n  Base64 decoding test: ");
+     277                 :            :     }
+     278                 :            : 
+     279                 :          0 :     src = base64_test_enc;
+     280                 :            : 
+     281         [ #  # ]:          0 :     if (mbedtls_base64_decode(buffer, sizeof(buffer), &len, src, 88) != 0 ||
+     282         [ #  # ]:          0 :         memcmp(base64_test_dec, buffer, 64) != 0) {
+     283         [ #  # ]:          0 :         if (verbose != 0) {
+     284                 :          0 :             mbedtls_printf("failed\n");
+     285                 :            :         }
+     286                 :            : 
+     287                 :          0 :         return 1;
+     288                 :            :     }
+     289                 :            : 
+     290         [ #  # ]:          0 :     if (verbose != 0) {
+     291                 :          0 :         mbedtls_printf("passed\n\n");
+     292                 :            :     }
+     293                 :            : 
+     294                 :          0 :     return 0;
+     295                 :            : }
+     296                 :            : 
+     297                 :            : #endif /* MBEDTLS_SELF_TEST */
+     298                 :            : 
+     299                 :            : #endif /* MBEDTLS_BASE64_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/bignum.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/bignum.c.func-sort-c.html new file mode 100644 index 00000000000..3b6bf868d4e --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/bignum.c.func-sort-c.html @@ -0,0 +1,301 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/bignum.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - bignum.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:46989552.4 %
Date:2024-09-22 08:21:07Functions:385569.1 %
Branches:30180437.4 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_mpi_div_int0
mbedtls_mpi_gen_prime0
mbedtls_mpi_is_prime_ext0
mbedtls_mpi_lt_mpi_ct0
mbedtls_mpi_mod_int0
mbedtls_mpi_read_binary_le0
mbedtls_mpi_read_string0
mbedtls_mpi_safe_cond_swap0
mbedtls_mpi_self_test0
mbedtls_mpi_set_bit0
mbedtls_mpi_swap0
mbedtls_mpi_write_binary_le0
mbedtls_mpi_write_string0
mpi_check_small_factors0
mpi_get_digit0
mpi_miller_rabin0
mpi_write_hlp0
mbedtls_mpi_add_int2
mbedtls_mpi_fill_random108
mbedtls_mpi_exp_mod416
mbedtls_mpi_write_binary1031
mbedtls_mpi_random1162
mbedtls_mpi_inv_mod9093
mbedtls_mpi_gcd9097
mbedtls_mpi_mod_mpi14239
mbedtls_mpi_div_mpi14241
mbedtls_mpi_sub_int14401
mbedtls_mpi_size15596
mbedtls_mpi_read_binary29686
mbedtls_mpi_shrink29917
mbedtls_mpi_resize_clear30956
mbedtls_int_div_int36658
mbedtls_mpi_mul_int565278
mbedtls_mpi_get_bit838698
mbedtls_mpi_shift_l2116906
mbedtls_mpi_lsb3384454
mbedtls_mpi_add_abs3757562
mbedtls_mpi_copy4480713
mbedtls_ct_mpi_sign_if4606486
mbedtls_mpi_safe_cond_assign4606486
mbedtls_mpi_mul_mpi6033544
mbedtls_mpi_lset6352708
mbedtls_mpi_bitlen8194680
mbedtls_mpi_add_mpi8578022
mbedtls_mpi_sub_mpi10242507
mbedtls_mpi_cmp_int11166763
mbedtls_mpi_free12723539
mbedtls_mpi_init12798231
mbedtls_mpi_cmp_abs15077244
mbedtls_mpi_shift_r15083781
mpi_sint_abs17533874
add_sub_mpi18820529
mbedtls_mpi_sub_abs19538283
mbedtls_mpi_cmp_mpi26507254
mbedtls_mpi_grow48801241
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/bignum.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/bignum.c.func.html new file mode 100644 index 00000000000..fe85987602a --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/bignum.c.func.html @@ -0,0 +1,301 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/bignum.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - bignum.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:46989552.4 %
Date:2024-09-22 08:21:07Functions:385569.1 %
Branches:30180437.4 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
add_sub_mpi18820529
mbedtls_ct_mpi_sign_if4606486
mbedtls_int_div_int36658
mbedtls_mpi_add_abs3757562
mbedtls_mpi_add_int2
mbedtls_mpi_add_mpi8578022
mbedtls_mpi_bitlen8194680
mbedtls_mpi_cmp_abs15077244
mbedtls_mpi_cmp_int11166763
mbedtls_mpi_cmp_mpi26507254
mbedtls_mpi_copy4480713
mbedtls_mpi_div_int0
mbedtls_mpi_div_mpi14241
mbedtls_mpi_exp_mod416
mbedtls_mpi_fill_random108
mbedtls_mpi_free12723539
mbedtls_mpi_gcd9097
mbedtls_mpi_gen_prime0
mbedtls_mpi_get_bit838698
mbedtls_mpi_grow48801241
mbedtls_mpi_init12798231
mbedtls_mpi_inv_mod9093
mbedtls_mpi_is_prime_ext0
mbedtls_mpi_lsb3384454
mbedtls_mpi_lset6352708
mbedtls_mpi_lt_mpi_ct0
mbedtls_mpi_mod_int0
mbedtls_mpi_mod_mpi14239
mbedtls_mpi_mul_int565278
mbedtls_mpi_mul_mpi6033544
mbedtls_mpi_random1162
mbedtls_mpi_read_binary29686
mbedtls_mpi_read_binary_le0
mbedtls_mpi_read_string0
mbedtls_mpi_resize_clear30956
mbedtls_mpi_safe_cond_assign4606486
mbedtls_mpi_safe_cond_swap0
mbedtls_mpi_self_test0
mbedtls_mpi_set_bit0
mbedtls_mpi_shift_l2116906
mbedtls_mpi_shift_r15083781
mbedtls_mpi_shrink29917
mbedtls_mpi_size15596
mbedtls_mpi_sub_abs19538283
mbedtls_mpi_sub_int14401
mbedtls_mpi_sub_mpi10242507
mbedtls_mpi_swap0
mbedtls_mpi_write_binary1031
mbedtls_mpi_write_binary_le0
mbedtls_mpi_write_string0
mpi_check_small_factors0
mpi_get_digit0
mpi_miller_rabin0
mpi_sint_abs17533874
mpi_write_hlp0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/bignum.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/bignum.c.gcov.html new file mode 100644 index 00000000000..925a4fd7eb3 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/bignum.c.gcov.html @@ -0,0 +1,2550 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/bignum.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - bignum.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:46989552.4 %
Date:2024-09-22 08:21:07Functions:385569.1 %
Branches:30180437.4 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  *  Multi-precision integer library
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  */
+       7                 :            : 
+       8                 :            : /*
+       9                 :            :  *  The following sources were referenced in the design of this Multi-precision
+      10                 :            :  *  Integer library:
+      11                 :            :  *
+      12                 :            :  *  [1] Handbook of Applied Cryptography - 1997
+      13                 :            :  *      Menezes, van Oorschot and Vanstone
+      14                 :            :  *
+      15                 :            :  *  [2] Multi-Precision Math
+      16                 :            :  *      Tom St Denis
+      17                 :            :  *      https://github.com/libtom/libtommath/blob/develop/tommath.pdf
+      18                 :            :  *
+      19                 :            :  *  [3] GNU Multi-Precision Arithmetic Library
+      20                 :            :  *      https://gmplib.org/manual/index.html
+      21                 :            :  *
+      22                 :            :  */
+      23                 :            : 
+      24                 :            : #include "common.h"
+      25                 :            : 
+      26                 :            : #if defined(MBEDTLS_BIGNUM_C)
+      27                 :            : 
+      28                 :            : #include "mbedtls/bignum.h"
+      29                 :            : #include "bignum_core.h"
+      30                 :            : #include "bn_mul.h"
+      31                 :            : #include "mbedtls/platform_util.h"
+      32                 :            : #include "mbedtls/error.h"
+      33                 :            : #include "constant_time_internal.h"
+      34                 :            : 
+      35                 :            : #include <limits.h>
+      36                 :            : #include <string.h>
+      37                 :            : 
+      38                 :            : #include "mbedtls/platform.h"
+      39                 :            : 
+      40                 :            : 
+      41                 :            : 
+      42                 :            : /*
+      43                 :            :  * Conditionally select an MPI sign in constant time.
+      44                 :            :  * (MPI sign is the field s in mbedtls_mpi. It is unsigned short and only 1 and -1 are valid
+      45                 :            :  * values.)
+      46                 :            :  */
+      47                 :    4606486 : static inline signed short mbedtls_ct_mpi_sign_if(mbedtls_ct_condition_t cond,
+      48                 :            :                                                   signed short sign1, signed short sign2)
+      49                 :            : {
+      50                 :    4606486 :     return (signed short) mbedtls_ct_uint_if(cond, sign1 + 1, sign2 + 1) - 1;
+      51                 :            : }
+      52                 :            : 
+      53                 :            : /*
+      54                 :            :  * Compare signed values in constant time
+      55                 :            :  */
+      56                 :          0 : int mbedtls_mpi_lt_mpi_ct(const mbedtls_mpi *X,
+      57                 :            :                           const mbedtls_mpi *Y,
+      58                 :            :                           unsigned *ret)
+      59                 :            : {
+      60                 :            :     mbedtls_ct_condition_t different_sign, X_is_negative, Y_is_negative, result;
+      61                 :            : 
+      62         [ #  # ]:          0 :     if (X->n != Y->n) {
+      63                 :          0 :         return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
+      64                 :            :     }
+      65                 :            : 
+      66                 :            :     /*
+      67                 :            :      * Set N_is_negative to MBEDTLS_CT_FALSE if N >= 0, MBEDTLS_CT_TRUE if N < 0.
+      68                 :            :      * We know that N->s == 1 if N >= 0 and N->s == -1 if N < 0.
+      69                 :            :      */
+      70                 :          0 :     X_is_negative = mbedtls_ct_bool((X->s & 2) >> 1);
+      71                 :          0 :     Y_is_negative = mbedtls_ct_bool((Y->s & 2) >> 1);
+      72                 :            : 
+      73                 :            :     /*
+      74                 :            :      * If the signs are different, then the positive operand is the bigger.
+      75                 :            :      * That is if X is negative (X_is_negative == 1), then X < Y is true and it
+      76                 :            :      * is false if X is positive (X_is_negative == 0).
+      77                 :            :      */
+      78                 :          0 :     different_sign = mbedtls_ct_bool_ne(X_is_negative, Y_is_negative); // true if different sign
+      79                 :          0 :     result = mbedtls_ct_bool_and(different_sign, X_is_negative);
+      80                 :            : 
+      81                 :            :     /*
+      82                 :            :      * Assuming signs are the same, compare X and Y. We switch the comparison
+      83                 :            :      * order if they are negative so that we get the right result, regardles of
+      84                 :            :      * sign.
+      85                 :            :      */
+      86                 :            : 
+      87                 :            :     /* This array is used to conditionally swap the pointers in const time */
+      88                 :          0 :     void * const p[2] = { X->p, Y->p };
+      89                 :          0 :     size_t i = mbedtls_ct_size_if_else_0(X_is_negative, 1);
+      90                 :          0 :     mbedtls_ct_condition_t lt = mbedtls_mpi_core_lt_ct(p[i], p[i ^ 1], X->n);
+      91                 :            : 
+      92                 :            :     /*
+      93                 :            :      * Store in result iff the signs are the same (i.e., iff different_sign == false). If
+      94                 :            :      * the signs differ, result has already been set, so we don't change it.
+      95                 :            :      */
+      96                 :          0 :     result = mbedtls_ct_bool_or(result,
+      97                 :            :                                 mbedtls_ct_bool_and(mbedtls_ct_bool_not(different_sign), lt));
+      98                 :            : 
+      99                 :          0 :     *ret = mbedtls_ct_uint_if_else_0(result, 1);
+     100                 :            : 
+     101                 :          0 :     return 0;
+     102                 :            : }
+     103                 :            : 
+     104                 :            : /*
+     105                 :            :  * Conditionally assign X = Y, without leaking information
+     106                 :            :  * about whether the assignment was made or not.
+     107                 :            :  * (Leaking information about the respective sizes of X and Y is ok however.)
+     108                 :            :  */
+     109                 :            : #if defined(_MSC_VER) && defined(MBEDTLS_PLATFORM_IS_WINDOWS_ON_ARM64) && \
+     110                 :            :     (_MSC_FULL_VER < 193131103)
+     111                 :            : /*
+     112                 :            :  * MSVC miscompiles this function if it's inlined prior to Visual Studio 2022 version 17.1. See:
+     113                 :            :  * https://developercommunity.visualstudio.com/t/c-compiler-miscompiles-part-of-mbedtls-library-on/1646989
+     114                 :            :  */
+     115                 :            : __declspec(noinline)
+     116                 :            : #endif
+     117                 :    4606486 : int mbedtls_mpi_safe_cond_assign(mbedtls_mpi *X,
+     118                 :            :                                  const mbedtls_mpi *Y,
+     119                 :            :                                  unsigned char assign)
+     120                 :            : {
+     121                 :    4606486 :     int ret = 0;
+     122                 :            : 
+     123         [ -  + ]:    4606486 :     MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, Y->n));
+     124                 :            : 
+     125                 :            :     {
+     126                 :    4606486 :         mbedtls_ct_condition_t do_assign = mbedtls_ct_bool(assign);
+     127                 :            : 
+     128                 :    4606486 :         X->s = mbedtls_ct_mpi_sign_if(do_assign, Y->s, X->s);
+     129                 :            : 
+     130                 :    4606486 :         mbedtls_mpi_core_cond_assign(X->p, Y->p, Y->n, do_assign);
+     131                 :            : 
+     132                 :    4606486 :         mbedtls_ct_condition_t do_not_assign = mbedtls_ct_bool_not(do_assign);
+     133         [ +  + ]:    4622356 :         for (size_t i = Y->n; i < X->n; i++) {
+     134                 :      15870 :             X->p[i] = mbedtls_ct_mpi_uint_if_else_0(do_not_assign, X->p[i]);
+     135                 :            :         }
+     136                 :            :     }
+     137                 :            : 
+     138                 :    4606486 : cleanup:
+     139                 :    4606486 :     return ret;
+     140                 :            : }
+     141                 :            : 
+     142                 :            : /*
+     143                 :            :  * Conditionally swap X and Y, without leaking information
+     144                 :            :  * about whether the swap was made or not.
+     145                 :            :  * Here it is not ok to simply swap the pointers, which would lead to
+     146                 :            :  * different memory access patterns when X and Y are used afterwards.
+     147                 :            :  */
+     148                 :          0 : int mbedtls_mpi_safe_cond_swap(mbedtls_mpi *X,
+     149                 :            :                                mbedtls_mpi *Y,
+     150                 :            :                                unsigned char swap)
+     151                 :            : {
+     152                 :          0 :     int ret = 0;
+     153                 :            :     int s;
+     154                 :            : 
+     155         [ #  # ]:          0 :     if (X == Y) {
+     156                 :          0 :         return 0;
+     157                 :            :     }
+     158                 :            : 
+     159                 :          0 :     mbedtls_ct_condition_t do_swap = mbedtls_ct_bool(swap);
+     160                 :            : 
+     161         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, Y->n));
+     162         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_grow(Y, X->n));
+     163                 :            : 
+     164                 :          0 :     s = X->s;
+     165                 :          0 :     X->s = mbedtls_ct_mpi_sign_if(do_swap, Y->s, X->s);
+     166                 :          0 :     Y->s = mbedtls_ct_mpi_sign_if(do_swap, s, Y->s);
+     167                 :            : 
+     168                 :          0 :     mbedtls_mpi_core_cond_swap(X->p, Y->p, X->n, do_swap);
+     169                 :            : 
+     170                 :          0 : cleanup:
+     171                 :          0 :     return ret;
+     172                 :            : }
+     173                 :            : 
+     174                 :            : /* Implementation that should never be optimized out by the compiler */
+     175                 :            : #define mbedtls_mpi_zeroize_and_free(v, n) mbedtls_zeroize_and_free(v, ciL * (n))
+     176                 :            : 
+     177                 :            : /*
+     178                 :            :  * Initialize one MPI
+     179                 :            :  */
+     180                 :   12798231 : void mbedtls_mpi_init(mbedtls_mpi *X)
+     181                 :            : {
+     182                 :   12798231 :     X->s = 1;
+     183                 :   12798231 :     X->n = 0;
+     184                 :   12798231 :     X->p = NULL;
+     185                 :   12798231 : }
+     186                 :            : 
+     187                 :            : /*
+     188                 :            :  * Unallocate one MPI
+     189                 :            :  */
+     190                 :   12723539 : void mbedtls_mpi_free(mbedtls_mpi *X)
+     191                 :            : {
+     192         [ -  + ]:   12723539 :     if (X == NULL) {
+     193                 :          0 :         return;
+     194                 :            :     }
+     195                 :            : 
+     196         [ +  + ]:   12723539 :     if (X->p != NULL) {
+     197                 :    2227636 :         mbedtls_mpi_zeroize_and_free(X->p, X->n);
+     198                 :            :     }
+     199                 :            : 
+     200                 :   12723539 :     X->s = 1;
+     201                 :   12723539 :     X->n = 0;
+     202                 :   12723539 :     X->p = NULL;
+     203                 :            : }
+     204                 :            : 
+     205                 :            : /*
+     206                 :            :  * Enlarge to the specified number of limbs
+     207                 :            :  */
+     208                 :   48801241 : int mbedtls_mpi_grow(mbedtls_mpi *X, size_t nblimbs)
+     209                 :            : {
+     210                 :            :     mbedtls_mpi_uint *p;
+     211                 :            : 
+     212         [ -  + ]:   48801241 :     if (nblimbs > MBEDTLS_MPI_MAX_LIMBS) {
+     213                 :          0 :         return MBEDTLS_ERR_MPI_ALLOC_FAILED;
+     214                 :            :     }
+     215                 :            : 
+     216         [ +  + ]:   48801241 :     if (X->n < nblimbs) {
+     217         [ -  + ]:    2472869 :         if ((p = (mbedtls_mpi_uint *) mbedtls_calloc(nblimbs, ciL)) == NULL) {
+     218                 :          0 :             return MBEDTLS_ERR_MPI_ALLOC_FAILED;
+     219                 :            :         }
+     220                 :            : 
+     221         [ +  + ]:    2472869 :         if (X->p != NULL) {
+     222                 :     244589 :             memcpy(p, X->p, X->n * ciL);
+     223                 :     244589 :             mbedtls_mpi_zeroize_and_free(X->p, X->n);
+     224                 :            :         }
+     225                 :            : 
+     226                 :            :         /* nblimbs fits in n because we ensure that MBEDTLS_MPI_MAX_LIMBS
+     227                 :            :          * fits, and we've checked that nblimbs <= MBEDTLS_MPI_MAX_LIMBS. */
+     228                 :    2472869 :         X->n = (unsigned short) nblimbs;
+     229                 :    2472869 :         X->p = p;
+     230                 :            :     }
+     231                 :            : 
+     232                 :   48801241 :     return 0;
+     233                 :            : }
+     234                 :            : 
+     235                 :            : /*
+     236                 :            :  * Resize down as much as possible,
+     237                 :            :  * while keeping at least the specified number of limbs
+     238                 :            :  */
+     239                 :      29917 : int mbedtls_mpi_shrink(mbedtls_mpi *X, size_t nblimbs)
+     240                 :            : {
+     241                 :            :     mbedtls_mpi_uint *p;
+     242                 :            :     size_t i;
+     243                 :            : 
+     244         [ -  + ]:      29917 :     if (nblimbs > MBEDTLS_MPI_MAX_LIMBS) {
+     245                 :          0 :         return MBEDTLS_ERR_MPI_ALLOC_FAILED;
+     246                 :            :     }
+     247                 :            : 
+     248                 :            :     /* Actually resize up if there are currently fewer than nblimbs limbs. */
+     249         [ -  + ]:      29917 :     if (X->n <= nblimbs) {
+     250                 :          0 :         return mbedtls_mpi_grow(X, nblimbs);
+     251                 :            :     }
+     252                 :            :     /* After this point, then X->n > nblimbs and in particular X->n > 0. */
+     253                 :            : 
+     254         [ +  - ]:     197364 :     for (i = X->n - 1; i > 0; i--) {
+     255         [ +  + ]:     197364 :         if (X->p[i] != 0) {
+     256                 :      29917 :             break;
+     257                 :            :         }
+     258                 :            :     }
+     259                 :      29917 :     i++;
+     260                 :            : 
+     261         [ +  + ]:      29917 :     if (i < nblimbs) {
+     262                 :        255 :         i = nblimbs;
+     263                 :            :     }
+     264                 :            : 
+     265         [ -  + ]:      29917 :     if ((p = (mbedtls_mpi_uint *) mbedtls_calloc(i, ciL)) == NULL) {
+     266                 :          0 :         return MBEDTLS_ERR_MPI_ALLOC_FAILED;
+     267                 :            :     }
+     268                 :            : 
+     269         [ +  - ]:      29917 :     if (X->p != NULL) {
+     270                 :      29917 :         memcpy(p, X->p, i * ciL);
+     271                 :      29917 :         mbedtls_mpi_zeroize_and_free(X->p, X->n);
+     272                 :            :     }
+     273                 :            : 
+     274                 :            :     /* i fits in n because we ensure that MBEDTLS_MPI_MAX_LIMBS
+     275                 :            :      * fits, and we've checked that i <= nblimbs <= MBEDTLS_MPI_MAX_LIMBS. */
+     276                 :      29917 :     X->n = (unsigned short) i;
+     277                 :      29917 :     X->p = p;
+     278                 :            : 
+     279                 :      29917 :     return 0;
+     280                 :            : }
+     281                 :            : 
+     282                 :            : /* Resize X to have exactly n limbs and set it to 0. */
+     283                 :      30956 : static int mbedtls_mpi_resize_clear(mbedtls_mpi *X, size_t limbs)
+     284                 :            : {
+     285         [ -  + ]:      30956 :     if (limbs == 0) {
+     286                 :          0 :         mbedtls_mpi_free(X);
+     287                 :          0 :         return 0;
+     288         [ +  + ]:      30956 :     } else if (X->n == limbs) {
+     289                 :         77 :         memset(X->p, 0, limbs * ciL);
+     290                 :         77 :         X->s = 1;
+     291                 :         77 :         return 0;
+     292                 :            :     } else {
+     293                 :      30879 :         mbedtls_mpi_free(X);
+     294                 :      30879 :         return mbedtls_mpi_grow(X, limbs);
+     295                 :            :     }
+     296                 :            : }
+     297                 :            : 
+     298                 :            : /*
+     299                 :            :  * Copy the contents of Y into X.
+     300                 :            :  *
+     301                 :            :  * This function is not constant-time. Leading zeros in Y may be removed.
+     302                 :            :  *
+     303                 :            :  * Ensure that X does not shrink. This is not guaranteed by the public API,
+     304                 :            :  * but some code in the bignum module might still rely on this property.
+     305                 :            :  */
+     306                 :    4480713 : int mbedtls_mpi_copy(mbedtls_mpi *X, const mbedtls_mpi *Y)
+     307                 :            : {
+     308                 :    4480713 :     int ret = 0;
+     309                 :            :     size_t i;
+     310                 :            : 
+     311         [ +  + ]:    4480713 :     if (X == Y) {
+     312                 :      64000 :         return 0;
+     313                 :            :     }
+     314                 :            : 
+     315         [ +  + ]:    4416713 :     if (Y->n == 0) {
+     316         [ -  + ]:       1702 :         if (X->n != 0) {
+     317                 :          0 :             X->s = 1;
+     318                 :          0 :             memset(X->p, 0, X->n * ciL);
+     319                 :            :         }
+     320                 :       1702 :         return 0;
+     321                 :            :     }
+     322                 :            : 
+     323         [ +  + ]:   25720738 :     for (i = Y->n - 1; i > 0; i--) {
+     324         [ +  + ]:   25695526 :         if (Y->p[i] != 0) {
+     325                 :    4389799 :             break;
+     326                 :            :         }
+     327                 :            :     }
+     328                 :    4415011 :     i++;
+     329                 :            : 
+     330                 :    4415011 :     X->s = Y->s;
+     331                 :            : 
+     332         [ +  + ]:    4415011 :     if (X->n < i) {
+     333         [ -  + ]:    1851296 :         MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, i));
+     334                 :            :     } else {
+     335                 :    2563715 :         memset(X->p + i, 0, (X->n - i) * ciL);
+     336                 :            :     }
+     337                 :            : 
+     338                 :    4415011 :     memcpy(X->p, Y->p, i * ciL);
+     339                 :            : 
+     340                 :    4415011 : cleanup:
+     341                 :            : 
+     342                 :    4415011 :     return ret;
+     343                 :            : }
+     344                 :            : 
+     345                 :            : /*
+     346                 :            :  * Swap the contents of X and Y
+     347                 :            :  */
+     348                 :          0 : void mbedtls_mpi_swap(mbedtls_mpi *X, mbedtls_mpi *Y)
+     349                 :            : {
+     350                 :            :     mbedtls_mpi T;
+     351                 :            : 
+     352                 :          0 :     memcpy(&T,  X, sizeof(mbedtls_mpi));
+     353                 :          0 :     memcpy(X,  Y, sizeof(mbedtls_mpi));
+     354                 :          0 :     memcpy(Y, &T, sizeof(mbedtls_mpi));
+     355                 :          0 : }
+     356                 :            : 
+     357                 :   17533874 : static inline mbedtls_mpi_uint mpi_sint_abs(mbedtls_mpi_sint z)
+     358                 :            : {
+     359         [ +  + ]:   17533874 :     if (z >= 0) {
+     360                 :   17531068 :         return z;
+     361                 :            :     }
+     362                 :            :     /* Take care to handle the most negative value (-2^(biL-1)) correctly.
+     363                 :            :      * A naive -z would have undefined behavior.
+     364                 :            :      * Write this in a way that makes popular compilers happy (GCC, Clang,
+     365                 :            :      * MSVC). */
+     366                 :       2806 :     return (mbedtls_mpi_uint) 0 - (mbedtls_mpi_uint) z;
+     367                 :            : }
+     368                 :            : 
+     369                 :            : /* Convert x to a sign, i.e. to 1, if x is positive, or -1, if x is negative.
+     370                 :            :  * This looks awkward but generates smaller code than (x < 0 ? -1 : 1) */
+     371                 :            : #define TO_SIGN(x) ((mbedtls_mpi_sint) (((mbedtls_mpi_uint) x) >> (biL - 1)) * -2 + 1)
+     372                 :            : 
+     373                 :            : /*
+     374                 :            :  * Set value from integer
+     375                 :            :  */
+     376                 :    6352708 : int mbedtls_mpi_lset(mbedtls_mpi *X, mbedtls_mpi_sint z)
+     377                 :            : {
+     378                 :    6352708 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     379                 :            : 
+     380         [ -  + ]:    6352708 :     MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, 1));
+     381                 :    6352708 :     memset(X->p, 0, X->n * ciL);
+     382                 :            : 
+     383                 :    6352708 :     X->p[0] = mpi_sint_abs(z);
+     384                 :    6352708 :     X->s    = TO_SIGN(z);
+     385                 :            : 
+     386                 :    6352708 : cleanup:
+     387                 :            : 
+     388                 :    6352708 :     return ret;
+     389                 :            : }
+     390                 :            : 
+     391                 :            : /*
+     392                 :            :  * Get a specific bit
+     393                 :            :  */
+     394                 :     838698 : int mbedtls_mpi_get_bit(const mbedtls_mpi *X, size_t pos)
+     395                 :            : {
+     396         [ +  + ]:     838698 :     if (X->n * biL <= pos) {
+     397                 :       6788 :         return 0;
+     398                 :            :     }
+     399                 :            : 
+     400                 :     831910 :     return (X->p[pos / biL] >> (pos % biL)) & 0x01;
+     401                 :            : }
+     402                 :            : 
+     403                 :            : /*
+     404                 :            :  * Set a bit to a specific value of 0 or 1
+     405                 :            :  */
+     406                 :          0 : int mbedtls_mpi_set_bit(mbedtls_mpi *X, size_t pos, unsigned char val)
+     407                 :            : {
+     408                 :          0 :     int ret = 0;
+     409                 :          0 :     size_t off = pos / biL;
+     410                 :          0 :     size_t idx = pos % biL;
+     411                 :            : 
+     412   [ #  #  #  # ]:          0 :     if (val != 0 && val != 1) {
+     413                 :          0 :         return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
+     414                 :            :     }
+     415                 :            : 
+     416         [ #  # ]:          0 :     if (X->n * biL <= pos) {
+     417         [ #  # ]:          0 :         if (val == 0) {
+     418                 :          0 :             return 0;
+     419                 :            :         }
+     420                 :            : 
+     421         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, off + 1));
+     422                 :            :     }
+     423                 :            : 
+     424                 :          0 :     X->p[off] &= ~((mbedtls_mpi_uint) 0x01 << idx);
+     425                 :          0 :     X->p[off] |= (mbedtls_mpi_uint) val << idx;
+     426                 :            : 
+     427                 :          0 : cleanup:
+     428                 :            : 
+     429                 :          0 :     return ret;
+     430                 :            : }
+     431                 :            : 
+     432                 :            : /*
+     433                 :            :  * Return the number of less significant zero-bits
+     434                 :            :  */
+     435                 :    3384454 : size_t mbedtls_mpi_lsb(const mbedtls_mpi *X)
+     436                 :            : {
+     437                 :            :     size_t i;
+     438                 :            : 
+     439                 :            : #if defined(__has_builtin)
+     440                 :            : #if (MBEDTLS_MPI_UINT_MAX == UINT_MAX) && __has_builtin(__builtin_ctz)
+     441                 :            :     #define mbedtls_mpi_uint_ctz __builtin_ctz
+     442                 :            : #elif (MBEDTLS_MPI_UINT_MAX == ULONG_MAX) && __has_builtin(__builtin_ctzl)
+     443                 :            :     #define mbedtls_mpi_uint_ctz __builtin_ctzl
+     444                 :            : #elif (MBEDTLS_MPI_UINT_MAX == ULLONG_MAX) && __has_builtin(__builtin_ctzll)
+     445                 :            :     #define mbedtls_mpi_uint_ctz __builtin_ctzll
+     446                 :            : #endif
+     447                 :            : #endif
+     448                 :            : 
+     449                 :            : #if defined(mbedtls_mpi_uint_ctz)
+     450         [ +  - ]:    3384454 :     for (i = 0; i < X->n; i++) {
+     451         [ +  - ]:    3384454 :         if (X->p[i] != 0) {
+     452                 :    3384454 :             return i * biL + mbedtls_mpi_uint_ctz(X->p[i]);
+     453                 :            :         }
+     454                 :            :     }
+     455                 :            : #else
+     456                 :            :     size_t count = 0;
+     457                 :            :     for (i = 0; i < X->n; i++) {
+     458                 :            :         for (size_t j = 0; j < biL; j++, count++) {
+     459                 :            :             if (((X->p[i] >> j) & 1) != 0) {
+     460                 :            :                 return count;
+     461                 :            :             }
+     462                 :            :         }
+     463                 :            :     }
+     464                 :            : #endif
+     465                 :            : 
+     466                 :          0 :     return 0;
+     467                 :            : }
+     468                 :            : 
+     469                 :            : /*
+     470                 :            :  * Return the number of bits
+     471                 :            :  */
+     472                 :    8194680 : size_t mbedtls_mpi_bitlen(const mbedtls_mpi *X)
+     473                 :            : {
+     474                 :    8194680 :     return mbedtls_mpi_core_bitlen(X->p, X->n);
+     475                 :            : }
+     476                 :            : 
+     477                 :            : /*
+     478                 :            :  * Return the total size in bytes
+     479                 :            :  */
+     480                 :      15596 : size_t mbedtls_mpi_size(const mbedtls_mpi *X)
+     481                 :            : {
+     482                 :      15596 :     return (mbedtls_mpi_bitlen(X) + 7) >> 3;
+     483                 :            : }
+     484                 :            : 
+     485                 :            : /*
+     486                 :            :  * Convert an ASCII character to digit value
+     487                 :            :  */
+     488                 :          0 : static int mpi_get_digit(mbedtls_mpi_uint *d, int radix, char c)
+     489                 :            : {
+     490                 :          0 :     *d = 255;
+     491                 :            : 
+     492   [ #  #  #  # ]:          0 :     if (c >= 0x30 && c <= 0x39) {
+     493                 :          0 :         *d = c - 0x30;
+     494                 :            :     }
+     495   [ #  #  #  # ]:          0 :     if (c >= 0x41 && c <= 0x46) {
+     496                 :          0 :         *d = c - 0x37;
+     497                 :            :     }
+     498   [ #  #  #  # ]:          0 :     if (c >= 0x61 && c <= 0x66) {
+     499                 :          0 :         *d = c - 0x57;
+     500                 :            :     }
+     501                 :            : 
+     502         [ #  # ]:          0 :     if (*d >= (mbedtls_mpi_uint) radix) {
+     503                 :          0 :         return MBEDTLS_ERR_MPI_INVALID_CHARACTER;
+     504                 :            :     }
+     505                 :            : 
+     506                 :          0 :     return 0;
+     507                 :            : }
+     508                 :            : 
+     509                 :            : /*
+     510                 :            :  * Import from an ASCII string
+     511                 :            :  */
+     512                 :          0 : int mbedtls_mpi_read_string(mbedtls_mpi *X, int radix, const char *s)
+     513                 :            : {
+     514                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     515                 :            :     size_t i, j, slen, n;
+     516                 :          0 :     int sign = 1;
+     517                 :            :     mbedtls_mpi_uint d;
+     518                 :            :     mbedtls_mpi T;
+     519                 :            : 
+     520   [ #  #  #  # ]:          0 :     if (radix < 2 || radix > 16) {
+     521                 :          0 :         return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
+     522                 :            :     }
+     523                 :            : 
+     524                 :          0 :     mbedtls_mpi_init(&T);
+     525                 :            : 
+     526         [ #  # ]:          0 :     if (s[0] == 0) {
+     527                 :          0 :         mbedtls_mpi_free(X);
+     528                 :          0 :         return 0;
+     529                 :            :     }
+     530                 :            : 
+     531         [ #  # ]:          0 :     if (s[0] == '-') {
+     532                 :          0 :         ++s;
+     533                 :          0 :         sign = -1;
+     534                 :            :     }
+     535                 :            : 
+     536                 :          0 :     slen = strlen(s);
+     537                 :            : 
+     538         [ #  # ]:          0 :     if (radix == 16) {
+     539         [ #  # ]:          0 :         if (slen > SIZE_MAX >> 2) {
+     540                 :          0 :             return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
+     541                 :            :         }
+     542                 :            : 
+     543                 :          0 :         n = BITS_TO_LIMBS(slen << 2);
+     544                 :            : 
+     545         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, n));
+     546         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_lset(X, 0));
+     547                 :            : 
+     548         [ #  # ]:          0 :         for (i = slen, j = 0; i > 0; i--, j++) {
+     549         [ #  # ]:          0 :             MBEDTLS_MPI_CHK(mpi_get_digit(&d, radix, s[i - 1]));
+     550                 :          0 :             X->p[j / (2 * ciL)] |= d << ((j % (2 * ciL)) << 2);
+     551                 :            :         }
+     552                 :            :     } else {
+     553         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_lset(X, 0));
+     554                 :            : 
+     555         [ #  # ]:          0 :         for (i = 0; i < slen; i++) {
+     556         [ #  # ]:          0 :             MBEDTLS_MPI_CHK(mpi_get_digit(&d, radix, s[i]));
+     557         [ #  # ]:          0 :             MBEDTLS_MPI_CHK(mbedtls_mpi_mul_int(&T, X, radix));
+     558         [ #  # ]:          0 :             MBEDTLS_MPI_CHK(mbedtls_mpi_add_int(X, &T, d));
+     559                 :            :         }
+     560                 :            :     }
+     561                 :            : 
+     562   [ #  #  #  # ]:          0 :     if (sign < 0 && mbedtls_mpi_bitlen(X) != 0) {
+     563                 :          0 :         X->s = -1;
+     564                 :            :     }
+     565                 :            : 
+     566                 :          0 : cleanup:
+     567                 :            : 
+     568                 :          0 :     mbedtls_mpi_free(&T);
+     569                 :            : 
+     570                 :          0 :     return ret;
+     571                 :            : }
+     572                 :            : 
+     573                 :            : /*
+     574                 :            :  * Helper to write the digits high-order first.
+     575                 :            :  */
+     576                 :          0 : static int mpi_write_hlp(mbedtls_mpi *X, int radix,
+     577                 :            :                          char **p, const size_t buflen)
+     578                 :            : {
+     579                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     580                 :            :     mbedtls_mpi_uint r;
+     581                 :          0 :     size_t length = 0;
+     582                 :          0 :     char *p_end = *p + buflen;
+     583                 :            : 
+     584                 :            :     do {
+     585         [ #  # ]:          0 :         if (length >= buflen) {
+     586                 :          0 :             return MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL;
+     587                 :            :         }
+     588                 :            : 
+     589         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_mod_int(&r, X, radix));
+     590         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_div_int(X, NULL, X, radix));
+     591                 :            :         /*
+     592                 :            :          * Write the residue in the current position, as an ASCII character.
+     593                 :            :          */
+     594         [ #  # ]:          0 :         if (r < 0xA) {
+     595                 :          0 :             *(--p_end) = (char) ('0' + r);
+     596                 :            :         } else {
+     597                 :          0 :             *(--p_end) = (char) ('A' + (r - 0xA));
+     598                 :            :         }
+     599                 :            : 
+     600                 :          0 :         length++;
+     601         [ #  # ]:          0 :     } while (mbedtls_mpi_cmp_int(X, 0) != 0);
+     602                 :            : 
+     603                 :          0 :     memmove(*p, p_end, length);
+     604                 :          0 :     *p += length;
+     605                 :            : 
+     606                 :          0 : cleanup:
+     607                 :            : 
+     608                 :          0 :     return ret;
+     609                 :            : }
+     610                 :            : 
+     611                 :            : /*
+     612                 :            :  * Export into an ASCII string
+     613                 :            :  */
+     614                 :          0 : int mbedtls_mpi_write_string(const mbedtls_mpi *X, int radix,
+     615                 :            :                              char *buf, size_t buflen, size_t *olen)
+     616                 :            : {
+     617                 :          0 :     int ret = 0;
+     618                 :            :     size_t n;
+     619                 :            :     char *p;
+     620                 :            :     mbedtls_mpi T;
+     621                 :            : 
+     622   [ #  #  #  # ]:          0 :     if (radix < 2 || radix > 16) {
+     623                 :          0 :         return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
+     624                 :            :     }
+     625                 :            : 
+     626                 :          0 :     n = mbedtls_mpi_bitlen(X);   /* Number of bits necessary to present `n`. */
+     627         [ #  # ]:          0 :     if (radix >=  4) {
+     628                 :          0 :         n >>= 1;                 /* Number of 4-adic digits necessary to present
+     629                 :            :                                   * `n`. If radix > 4, this might be a strict
+     630                 :            :                                   * overapproximation of the number of
+     631                 :            :                                   * radix-adic digits needed to present `n`. */
+     632                 :            :     }
+     633         [ #  # ]:          0 :     if (radix >= 16) {
+     634                 :          0 :         n >>= 1;                 /* Number of hexadecimal digits necessary to
+     635                 :            :                                   * present `n`. */
+     636                 :            : 
+     637                 :            :     }
+     638                 :          0 :     n += 1; /* Terminating null byte */
+     639                 :          0 :     n += 1; /* Compensate for the divisions above, which round down `n`
+     640                 :            :              * in case it's not even. */
+     641                 :          0 :     n += 1; /* Potential '-'-sign. */
+     642                 :          0 :     n += (n & 1);   /* Make n even to have enough space for hexadecimal writing,
+     643                 :            :                      * which always uses an even number of hex-digits. */
+     644                 :            : 
+     645         [ #  # ]:          0 :     if (buflen < n) {
+     646                 :          0 :         *olen = n;
+     647                 :          0 :         return MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL;
+     648                 :            :     }
+     649                 :            : 
+     650                 :          0 :     p = buf;
+     651                 :          0 :     mbedtls_mpi_init(&T);
+     652                 :            : 
+     653         [ #  # ]:          0 :     if (X->s == -1) {
+     654                 :          0 :         *p++ = '-';
+     655                 :          0 :         buflen--;
+     656                 :            :     }
+     657                 :            : 
+     658         [ #  # ]:          0 :     if (radix == 16) {
+     659                 :            :         int c;
+     660                 :            :         size_t i, j, k;
+     661                 :            : 
+     662         [ #  # ]:          0 :         for (i = X->n, k = 0; i > 0; i--) {
+     663         [ #  # ]:          0 :             for (j = ciL; j > 0; j--) {
+     664                 :          0 :                 c = (X->p[i - 1] >> ((j - 1) << 3)) & 0xFF;
+     665                 :            : 
+     666   [ #  #  #  #  :          0 :                 if (c == 0 && k == 0 && (i + j) != 2) {
+                   #  # ]
+     667                 :          0 :                     continue;
+     668                 :            :                 }
+     669                 :            : 
+     670                 :          0 :                 *(p++) = "0123456789ABCDEF" [c / 16];
+     671                 :          0 :                 *(p++) = "0123456789ABCDEF" [c % 16];
+     672                 :          0 :                 k = 1;
+     673                 :            :             }
+     674                 :            :         }
+     675                 :            :     } else {
+     676         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&T, X));
+     677                 :            : 
+     678         [ #  # ]:          0 :         if (T.s == -1) {
+     679                 :          0 :             T.s = 1;
+     680                 :            :         }
+     681                 :            : 
+     682         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mpi_write_hlp(&T, radix, &p, buflen));
+     683                 :            :     }
+     684                 :            : 
+     685                 :          0 :     *p++ = '\0';
+     686                 :          0 :     *olen = (size_t) (p - buf);
+     687                 :            : 
+     688                 :          0 : cleanup:
+     689                 :            : 
+     690                 :          0 :     mbedtls_mpi_free(&T);
+     691                 :            : 
+     692                 :          0 :     return ret;
+     693                 :            : }
+     694                 :            : 
+     695                 :            : #if defined(MBEDTLS_FS_IO)
+     696                 :            : /*
+     697                 :            :  * Read X from an opened file
+     698                 :            :  */
+     699                 :            : int mbedtls_mpi_read_file(mbedtls_mpi *X, int radix, FILE *fin)
+     700                 :            : {
+     701                 :            :     mbedtls_mpi_uint d;
+     702                 :            :     size_t slen;
+     703                 :            :     char *p;
+     704                 :            :     /*
+     705                 :            :      * Buffer should have space for (short) label and decimal formatted MPI,
+     706                 :            :      * newline characters and '\0'
+     707                 :            :      */
+     708                 :            :     char s[MBEDTLS_MPI_RW_BUFFER_SIZE];
+     709                 :            : 
+     710                 :            :     if (radix < 2 || radix > 16) {
+     711                 :            :         return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
+     712                 :            :     }
+     713                 :            : 
+     714                 :            :     memset(s, 0, sizeof(s));
+     715                 :            :     if (fgets(s, sizeof(s) - 1, fin) == NULL) {
+     716                 :            :         return MBEDTLS_ERR_MPI_FILE_IO_ERROR;
+     717                 :            :     }
+     718                 :            : 
+     719                 :            :     slen = strlen(s);
+     720                 :            :     if (slen == sizeof(s) - 2) {
+     721                 :            :         return MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL;
+     722                 :            :     }
+     723                 :            : 
+     724                 :            :     if (slen > 0 && s[slen - 1] == '\n') {
+     725                 :            :         slen--; s[slen] = '\0';
+     726                 :            :     }
+     727                 :            :     if (slen > 0 && s[slen - 1] == '\r') {
+     728                 :            :         slen--; s[slen] = '\0';
+     729                 :            :     }
+     730                 :            : 
+     731                 :            :     p = s + slen;
+     732                 :            :     while (p-- > s) {
+     733                 :            :         if (mpi_get_digit(&d, radix, *p) != 0) {
+     734                 :            :             break;
+     735                 :            :         }
+     736                 :            :     }
+     737                 :            : 
+     738                 :            :     return mbedtls_mpi_read_string(X, radix, p + 1);
+     739                 :            : }
+     740                 :            : 
+     741                 :            : /*
+     742                 :            :  * Write X into an opened file (or stdout if fout == NULL)
+     743                 :            :  */
+     744                 :            : int mbedtls_mpi_write_file(const char *p, const mbedtls_mpi *X, int radix, FILE *fout)
+     745                 :            : {
+     746                 :            :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     747                 :            :     size_t n, slen, plen;
+     748                 :            :     /*
+     749                 :            :      * Buffer should have space for (short) label and decimal formatted MPI,
+     750                 :            :      * newline characters and '\0'
+     751                 :            :      */
+     752                 :            :     char s[MBEDTLS_MPI_RW_BUFFER_SIZE];
+     753                 :            : 
+     754                 :            :     if (radix < 2 || radix > 16) {
+     755                 :            :         return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
+     756                 :            :     }
+     757                 :            : 
+     758                 :            :     memset(s, 0, sizeof(s));
+     759                 :            : 
+     760                 :            :     MBEDTLS_MPI_CHK(mbedtls_mpi_write_string(X, radix, s, sizeof(s) - 2, &n));
+     761                 :            : 
+     762                 :            :     if (p == NULL) {
+     763                 :            :         p = "";
+     764                 :            :     }
+     765                 :            : 
+     766                 :            :     plen = strlen(p);
+     767                 :            :     slen = strlen(s);
+     768                 :            :     s[slen++] = '\r';
+     769                 :            :     s[slen++] = '\n';
+     770                 :            : 
+     771                 :            :     if (fout != NULL) {
+     772                 :            :         if (fwrite(p, 1, plen, fout) != plen ||
+     773                 :            :             fwrite(s, 1, slen, fout) != slen) {
+     774                 :            :             return MBEDTLS_ERR_MPI_FILE_IO_ERROR;
+     775                 :            :         }
+     776                 :            :     } else {
+     777                 :            :         mbedtls_printf("%s%s", p, s);
+     778                 :            :     }
+     779                 :            : 
+     780                 :            : cleanup:
+     781                 :            : 
+     782                 :            :     return ret;
+     783                 :            : }
+     784                 :            : #endif /* MBEDTLS_FS_IO */
+     785                 :            : 
+     786                 :            : /*
+     787                 :            :  * Import X from unsigned binary data, little endian
+     788                 :            :  *
+     789                 :            :  * This function is guaranteed to return an MPI with exactly the necessary
+     790                 :            :  * number of limbs (in particular, it does not skip 0s in the input).
+     791                 :            :  */
+     792                 :          0 : int mbedtls_mpi_read_binary_le(mbedtls_mpi *X,
+     793                 :            :                                const unsigned char *buf, size_t buflen)
+     794                 :            : {
+     795                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     796                 :          0 :     const size_t limbs = CHARS_TO_LIMBS(buflen);
+     797                 :            : 
+     798                 :            :     /* Ensure that target MPI has exactly the necessary number of limbs */
+     799         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_resize_clear(X, limbs));
+     800                 :            : 
+     801         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_core_read_le(X->p, X->n, buf, buflen));
+     802                 :            : 
+     803                 :          0 : cleanup:
+     804                 :            : 
+     805                 :            :     /*
+     806                 :            :      * This function is also used to import keys. However, wiping the buffers
+     807                 :            :      * upon failure is not necessary because failure only can happen before any
+     808                 :            :      * input is copied.
+     809                 :            :      */
+     810                 :          0 :     return ret;
+     811                 :            : }
+     812                 :            : 
+     813                 :            : /*
+     814                 :            :  * Import X from unsigned binary data, big endian
+     815                 :            :  *
+     816                 :            :  * This function is guaranteed to return an MPI with exactly the necessary
+     817                 :            :  * number of limbs (in particular, it does not skip 0s in the input).
+     818                 :            :  */
+     819                 :      29686 : int mbedtls_mpi_read_binary(mbedtls_mpi *X, const unsigned char *buf, size_t buflen)
+     820                 :            : {
+     821                 :      29686 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     822                 :      29686 :     const size_t limbs = CHARS_TO_LIMBS(buflen);
+     823                 :            : 
+     824                 :            :     /* Ensure that target MPI has exactly the necessary number of limbs */
+     825         [ -  + ]:      29686 :     MBEDTLS_MPI_CHK(mbedtls_mpi_resize_clear(X, limbs));
+     826                 :            : 
+     827         [ +  - ]:      29686 :     MBEDTLS_MPI_CHK(mbedtls_mpi_core_read_be(X->p, X->n, buf, buflen));
+     828                 :            : 
+     829                 :      29686 : cleanup:
+     830                 :            : 
+     831                 :            :     /*
+     832                 :            :      * This function is also used to import keys. However, wiping the buffers
+     833                 :            :      * upon failure is not necessary because failure only can happen before any
+     834                 :            :      * input is copied.
+     835                 :            :      */
+     836                 :      29686 :     return ret;
+     837                 :            : }
+     838                 :            : 
+     839                 :            : /*
+     840                 :            :  * Export X into unsigned binary data, little endian
+     841                 :            :  */
+     842                 :          0 : int mbedtls_mpi_write_binary_le(const mbedtls_mpi *X,
+     843                 :            :                                 unsigned char *buf, size_t buflen)
+     844                 :            : {
+     845                 :          0 :     return mbedtls_mpi_core_write_le(X->p, X->n, buf, buflen);
+     846                 :            : }
+     847                 :            : 
+     848                 :            : /*
+     849                 :            :  * Export X into unsigned binary data, big endian
+     850                 :            :  */
+     851                 :       1031 : int mbedtls_mpi_write_binary(const mbedtls_mpi *X,
+     852                 :            :                              unsigned char *buf, size_t buflen)
+     853                 :            : {
+     854                 :       1031 :     return mbedtls_mpi_core_write_be(X->p, X->n, buf, buflen);
+     855                 :            : }
+     856                 :            : 
+     857                 :            : /*
+     858                 :            :  * Left-shift: X <<= count
+     859                 :            :  */
+     860                 :    2116906 : int mbedtls_mpi_shift_l(mbedtls_mpi *X, size_t count)
+     861                 :            : {
+     862                 :    2116906 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     863                 :            :     size_t i;
+     864                 :            : 
+     865                 :    2116906 :     i = mbedtls_mpi_bitlen(X) + count;
+     866                 :            : 
+     867         [ +  + ]:    2116906 :     if (X->n * biL < i) {
+     868         [ -  + ]:      10835 :         MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, BITS_TO_LIMBS(i)));
+     869                 :            :     }
+     870                 :            : 
+     871                 :    2116906 :     ret = 0;
+     872                 :            : 
+     873                 :    2116906 :     mbedtls_mpi_core_shift_l(X->p, X->n, count);
+     874                 :    2116906 : cleanup:
+     875                 :            : 
+     876                 :    2116906 :     return ret;
+     877                 :            : }
+     878                 :            : 
+     879                 :            : /*
+     880                 :            :  * Right-shift: X >>= count
+     881                 :            :  */
+     882                 :   15083781 : int mbedtls_mpi_shift_r(mbedtls_mpi *X, size_t count)
+     883                 :            : {
+     884         [ +  - ]:   15083781 :     if (X->n != 0) {
+     885                 :   15083781 :         mbedtls_mpi_core_shift_r(X->p, X->n, count);
+     886                 :            :     }
+     887                 :   15083781 :     return 0;
+     888                 :            : }
+     889                 :            : 
+     890                 :            : /*
+     891                 :            :  * Compare unsigned values
+     892                 :            :  */
+     893                 :   15077244 : int mbedtls_mpi_cmp_abs(const mbedtls_mpi *X, const mbedtls_mpi *Y)
+     894                 :            : {
+     895                 :            :     size_t i, j;
+     896                 :            : 
+     897         [ +  + ]:   69136728 :     for (i = X->n; i > 0; i--) {
+     898         [ +  + ]:   69122436 :         if (X->p[i - 1] != 0) {
+     899                 :   15062952 :             break;
+     900                 :            :         }
+     901                 :            :     }
+     902                 :            : 
+     903         [ +  + ]:   37939753 :     for (j = Y->n; j > 0; j--) {
+     904         [ +  + ]:   37935857 :         if (Y->p[j - 1] != 0) {
+     905                 :   15073348 :             break;
+     906                 :            :         }
+     907                 :            :     }
+     908                 :            : 
+     909                 :            :     /* If i == j == 0, i.e. abs(X) == abs(Y),
+     910                 :            :      * we end up returning 0 at the end of the function. */
+     911                 :            : 
+     912         [ +  + ]:   15077244 :     if (i > j) {
+     913                 :    1535050 :         return 1;
+     914                 :            :     }
+     915         [ +  + ]:   13542194 :     if (j > i) {
+     916                 :      26873 :         return -1;
+     917                 :            :     }
+     918                 :            : 
+     919         [ +  + ]:   13607366 :     for (; i > 0; i--) {
+     920         [ +  + ]:   13586279 :         if (X->p[i - 1] > Y->p[i - 1]) {
+     921                 :    4541931 :             return 1;
+     922                 :            :         }
+     923         [ +  + ]:    9044348 :         if (X->p[i - 1] < Y->p[i - 1]) {
+     924                 :    8952303 :             return -1;
+     925                 :            :         }
+     926                 :            :     }
+     927                 :            : 
+     928                 :      21087 :     return 0;
+     929                 :            : }
+     930                 :            : 
+     931                 :            : /*
+     932                 :            :  * Compare signed values
+     933                 :            :  */
+     934                 :   26507254 : int mbedtls_mpi_cmp_mpi(const mbedtls_mpi *X, const mbedtls_mpi *Y)
+     935                 :            : {
+     936                 :            :     size_t i, j;
+     937                 :            : 
+     938         [ +  + ]:  132259332 :     for (i = X->n; i > 0; i--) {
+     939         [ +  + ]:  132234458 :         if (X->p[i - 1] != 0) {
+     940                 :   26482380 :             break;
+     941                 :            :         }
+     942                 :            :     }
+     943                 :            : 
+     944         [ +  + ]:   43762023 :     for (j = Y->n; j > 0; j--) {
+     945         [ +  + ]:   32835321 :         if (Y->p[j - 1] != 0) {
+     946                 :   15580552 :             break;
+     947                 :            :         }
+     948                 :            :     }
+     949                 :            : 
+     950   [ +  +  +  + ]:   26507254 :     if (i == 0 && j == 0) {
+     951                 :      24868 :         return 0;
+     952                 :            :     }
+     953                 :            : 
+     954         [ +  + ]:   26482386 :     if (i > j) {
+     955                 :   13763732 :         return X->s;
+     956                 :            :     }
+     957         [ +  + ]:   12718654 :     if (j > i) {
+     958                 :      68830 :         return -Y->s;
+     959                 :            :     }
+     960                 :            : 
+     961   [ +  -  -  + ]:   12649824 :     if (X->s > 0 && Y->s < 0) {
+     962                 :          0 :         return 1;
+     963                 :            :     }
+     964   [ +  -  -  + ]:   12649824 :     if (Y->s > 0 && X->s < 0) {
+     965                 :          0 :         return -1;
+     966                 :            :     }
+     967                 :            : 
+     968         [ +  + ]:   13021998 :     for (; i > 0; i--) {
+     969         [ +  + ]:   12766720 :         if (X->p[i - 1] > Y->p[i - 1]) {
+     970                 :    1677035 :             return X->s;
+     971                 :            :         }
+     972         [ +  + ]:   11089685 :         if (X->p[i - 1] < Y->p[i - 1]) {
+     973                 :   10717511 :             return -X->s;
+     974                 :            :         }
+     975                 :            :     }
+     976                 :            : 
+     977                 :     255278 :     return 0;
+     978                 :            : }
+     979                 :            : 
+     980                 :            : /*
+     981                 :            :  * Compare signed values
+     982                 :            :  */
+     983                 :   11166763 : int mbedtls_mpi_cmp_int(const mbedtls_mpi *X, mbedtls_mpi_sint z)
+     984                 :            : {
+     985                 :            :     mbedtls_mpi Y;
+     986                 :            :     mbedtls_mpi_uint p[1];
+     987                 :            : 
+     988                 :   11166763 :     *p  = mpi_sint_abs(z);
+     989                 :   11166763 :     Y.s = TO_SIGN(z);
+     990                 :   11166763 :     Y.n = 1;
+     991                 :   11166763 :     Y.p = p;
+     992                 :            : 
+     993                 :   11166763 :     return mbedtls_mpi_cmp_mpi(X, &Y);
+     994                 :            : }
+     995                 :            : 
+     996                 :            : /*
+     997                 :            :  * Unsigned addition: X = |A| + |B|  (HAC 14.7)
+     998                 :            :  */
+     999                 :    3757562 : int mbedtls_mpi_add_abs(mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B)
+    1000                 :            : {
+    1001                 :    3757562 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1002                 :            :     size_t j;
+    1003                 :            :     mbedtls_mpi_uint *p;
+    1004                 :            :     mbedtls_mpi_uint c;
+    1005                 :            : 
+    1006         [ -  + ]:    3757562 :     if (X == B) {
+    1007                 :          0 :         const mbedtls_mpi *T = A; A = X; B = T;
+    1008                 :            :     }
+    1009                 :            : 
+    1010         [ +  + ]:    3757562 :     if (X != A) {
+    1011         [ -  + ]:     466383 :         MBEDTLS_MPI_CHK(mbedtls_mpi_copy(X, A));
+    1012                 :            :     }
+    1013                 :            : 
+    1014                 :            :     /*
+    1015                 :            :      * X must always be positive as a result of unsigned additions.
+    1016                 :            :      */
+    1017                 :    3757562 :     X->s = 1;
+    1018                 :            : 
+    1019         [ +  + ]:    6877889 :     for (j = B->n; j > 0; j--) {
+    1020         [ +  + ]:    6877057 :         if (B->p[j - 1] != 0) {
+    1021                 :    3756730 :             break;
+    1022                 :            :         }
+    1023                 :            :     }
+    1024                 :            : 
+    1025                 :            :     /* Exit early to avoid undefined behavior on NULL+0 when X->n == 0
+    1026                 :            :      * and B is 0 (of any size). */
+    1027         [ +  + ]:    3757562 :     if (j == 0) {
+    1028                 :        832 :         return 0;
+    1029                 :            :     }
+    1030                 :            : 
+    1031         [ -  + ]:    3756730 :     MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, j));
+    1032                 :            : 
+    1033                 :            :     /* j is the number of non-zero limbs of B. Add those to X. */
+    1034                 :            : 
+    1035                 :    3756730 :     p = X->p;
+    1036                 :            : 
+    1037                 :    3756730 :     c = mbedtls_mpi_core_add(p, p, B->p, j);
+    1038                 :            : 
+    1039                 :    3756730 :     p += j;
+    1040                 :            : 
+    1041                 :            :     /* Now propagate any carry */
+    1042                 :            : 
+    1043         [ +  + ]:    5394304 :     while (c != 0) {
+    1044         [ +  + ]:    1637574 :         if (j >= X->n) {
+    1045         [ -  + ]:      17432 :             MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, j + 1));
+    1046                 :      17432 :             p = X->p + j;
+    1047                 :            :         }
+    1048                 :            : 
+    1049                 :    1637574 :         *p += c; c = (*p < c); j++; p++;
+    1050                 :            :     }
+    1051                 :            : 
+    1052                 :    3756730 : cleanup:
+    1053                 :            : 
+    1054                 :    3756730 :     return ret;
+    1055                 :            : }
+    1056                 :            : 
+    1057                 :            : /*
+    1058                 :            :  * Unsigned subtraction: X = |A| - |B|  (HAC 14.9, 14.10)
+    1059                 :            :  */
+    1060                 :   19538283 : int mbedtls_mpi_sub_abs(mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B)
+    1061                 :            : {
+    1062                 :   19538283 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1063                 :            :     size_t n;
+    1064                 :            :     mbedtls_mpi_uint carry;
+    1065                 :            : 
+    1066         [ +  + ]:   71758507 :     for (n = B->n; n > 0; n--) {
+    1067         [ +  + ]:   71740319 :         if (B->p[n - 1] != 0) {
+    1068                 :   19520095 :             break;
+    1069                 :            :         }
+    1070                 :            :     }
+    1071         [ -  + ]:   19538283 :     if (n > A->n) {
+    1072                 :            :         /* B >= (2^ciL)^n > A */
+    1073                 :          0 :         ret = MBEDTLS_ERR_MPI_NEGATIVE_VALUE;
+    1074                 :          0 :         goto cleanup;
+    1075                 :            :     }
+    1076                 :            : 
+    1077         [ -  + ]:   19538283 :     MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, A->n));
+    1078                 :            : 
+    1079                 :            :     /* Set the high limbs of X to match A. Don't touch the lower limbs
+    1080                 :            :      * because X might be aliased to B, and we must not overwrite the
+    1081                 :            :      * significant digits of B. */
+    1082   [ +  +  +  + ]:   19538283 :     if (A->n > n && A != X) {
+    1083                 :    2773926 :         memcpy(X->p + n, A->p + n, (A->n - n) * ciL);
+    1084                 :            :     }
+    1085         [ +  + ]:   19538283 :     if (X->n > A->n) {
+    1086                 :    6163908 :         memset(X->p + A->n, 0, (X->n - A->n) * ciL);
+    1087                 :            :     }
+    1088                 :            : 
+    1089                 :   19538283 :     carry = mbedtls_mpi_core_sub(X->p, A->p, B->p, n);
+    1090         [ +  + ]:   19538283 :     if (carry != 0) {
+    1091                 :            :         /* Propagate the carry through the rest of X. */
+    1092                 :    4298254 :         carry = mbedtls_mpi_core_sub_int(X->p + n, X->p + n, carry, X->n - n);
+    1093                 :            : 
+    1094                 :            :         /* If we have further carry/borrow, the result is negative. */
+    1095         [ -  + ]:    4298254 :         if (carry != 0) {
+    1096                 :          0 :             ret = MBEDTLS_ERR_MPI_NEGATIVE_VALUE;
+    1097                 :          0 :             goto cleanup;
+    1098                 :            :         }
+    1099                 :            :     }
+    1100                 :            : 
+    1101                 :            :     /* X should always be positive as a result of unsigned subtractions. */
+    1102                 :   19538283 :     X->s = 1;
+    1103                 :            : 
+    1104                 :   19538283 : cleanup:
+    1105                 :   19538283 :     return ret;
+    1106                 :            : }
+    1107                 :            : 
+    1108                 :            : /* Common function for signed addition and subtraction.
+    1109                 :            :  * Calculate A + B * flip_B where flip_B is 1 or -1.
+    1110                 :            :  */
+    1111                 :   18820529 : static int add_sub_mpi(mbedtls_mpi *X,
+    1112                 :            :                        const mbedtls_mpi *A, const mbedtls_mpi *B,
+    1113                 :            :                        int flip_B)
+    1114                 :            : {
+    1115                 :            :     int ret, s;
+    1116                 :            : 
+    1117                 :   18820529 :     s = A->s;
+    1118         [ +  + ]:   18820529 :     if (A->s * B->s * flip_B < 0) {
+    1119                 :   15063003 :         int cmp = mbedtls_mpi_cmp_abs(A, B);
+    1120         [ +  + ]:   15063003 :         if (cmp >= 0) {
+    1121         [ -  + ]:    6094456 :             MBEDTLS_MPI_CHK(mbedtls_mpi_sub_abs(X, A, B));
+    1122                 :            :             /* If |A| = |B|, the result is 0 and we must set the sign bit
+    1123                 :            :              * to +1 regardless of which of A or B was negative. Otherwise,
+    1124                 :            :              * since |A| > |B|, the sign is the sign of A. */
+    1125         [ +  + ]:    6094456 :             X->s = cmp == 0 ? 1 : s;
+    1126                 :            :         } else {
+    1127         [ -  + ]:    8968547 :             MBEDTLS_MPI_CHK(mbedtls_mpi_sub_abs(X, B, A));
+    1128                 :            :             /* Since |A| < |B|, the sign is the opposite of A. */
+    1129                 :    8968547 :             X->s = -s;
+    1130                 :            :         }
+    1131                 :            :     } else {
+    1132         [ -  + ]:    3757526 :         MBEDTLS_MPI_CHK(mbedtls_mpi_add_abs(X, A, B));
+    1133                 :    3757526 :         X->s = s;
+    1134                 :            :     }
+    1135                 :            : 
+    1136                 :   18820529 : cleanup:
+    1137                 :            : 
+    1138                 :   18820529 :     return ret;
+    1139                 :            : }
+    1140                 :            : 
+    1141                 :            : /*
+    1142                 :            :  * Signed addition: X = A + B
+    1143                 :            :  */
+    1144                 :    8578022 : int mbedtls_mpi_add_mpi(mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B)
+    1145                 :            : {
+    1146                 :    8578022 :     return add_sub_mpi(X, A, B, 1);
+    1147                 :            : }
+    1148                 :            : 
+    1149                 :            : /*
+    1150                 :            :  * Signed subtraction: X = A - B
+    1151                 :            :  */
+    1152                 :   10242507 : int mbedtls_mpi_sub_mpi(mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B)
+    1153                 :            : {
+    1154                 :   10242507 :     return add_sub_mpi(X, A, B, -1);
+    1155                 :            : }
+    1156                 :            : 
+    1157                 :            : /*
+    1158                 :            :  * Signed addition: X = A + b
+    1159                 :            :  */
+    1160                 :          2 : int mbedtls_mpi_add_int(mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint b)
+    1161                 :            : {
+    1162                 :            :     mbedtls_mpi B;
+    1163                 :            :     mbedtls_mpi_uint p[1];
+    1164                 :            : 
+    1165                 :          2 :     p[0] = mpi_sint_abs(b);
+    1166                 :          2 :     B.s = TO_SIGN(b);
+    1167                 :          2 :     B.n = 1;
+    1168                 :          2 :     B.p = p;
+    1169                 :            : 
+    1170                 :          2 :     return mbedtls_mpi_add_mpi(X, A, &B);
+    1171                 :            : }
+    1172                 :            : 
+    1173                 :            : /*
+    1174                 :            :  * Signed subtraction: X = A - b
+    1175                 :            :  */
+    1176                 :      14401 : int mbedtls_mpi_sub_int(mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint b)
+    1177                 :            : {
+    1178                 :            :     mbedtls_mpi B;
+    1179                 :            :     mbedtls_mpi_uint p[1];
+    1180                 :            : 
+    1181                 :      14401 :     p[0] = mpi_sint_abs(b);
+    1182                 :      14401 :     B.s = TO_SIGN(b);
+    1183                 :      14401 :     B.n = 1;
+    1184                 :      14401 :     B.p = p;
+    1185                 :            : 
+    1186                 :      14401 :     return mbedtls_mpi_sub_mpi(X, A, &B);
+    1187                 :            : }
+    1188                 :            : 
+    1189                 :            : /*
+    1190                 :            :  * Baseline multiplication: X = A * B  (HAC 14.12)
+    1191                 :            :  */
+    1192                 :    6033544 : int mbedtls_mpi_mul_mpi(mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B)
+    1193                 :            : {
+    1194                 :    6033544 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1195                 :            :     size_t i, j;
+    1196                 :            :     mbedtls_mpi TA, TB;
+    1197                 :    6033544 :     int result_is_zero = 0;
+    1198                 :            : 
+    1199                 :    6033544 :     mbedtls_mpi_init(&TA);
+    1200                 :    6033544 :     mbedtls_mpi_init(&TB);
+    1201                 :            : 
+    1202         [ +  + ]:    6033544 :     if (X == A) {
+    1203         [ -  + ]:    1717547 :         MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TA, A)); A = &TA;
+    1204                 :            :     }
+    1205         [ +  + ]:    6033544 :     if (X == B) {
+    1206         [ -  + ]:      20083 :         MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TB, B)); B = &TB;
+    1207                 :            :     }
+    1208                 :            : 
+    1209         [ +  - ]:   20513012 :     for (i = A->n; i > 0; i--) {
+    1210         [ +  + ]:   20513012 :         if (A->p[i - 1] != 0) {
+    1211                 :    6033544 :             break;
+    1212                 :            :         }
+    1213                 :            :     }
+    1214         [ -  + ]:    6033544 :     if (i == 0) {
+    1215                 :          0 :         result_is_zero = 1;
+    1216                 :            :     }
+    1217                 :            : 
+    1218         [ +  - ]:   27115799 :     for (j = B->n; j > 0; j--) {
+    1219         [ +  + ]:   27115799 :         if (B->p[j - 1] != 0) {
+    1220                 :    6033544 :             break;
+    1221                 :            :         }
+    1222                 :            :     }
+    1223         [ -  + ]:    6033544 :     if (j == 0) {
+    1224                 :          0 :         result_is_zero = 1;
+    1225                 :            :     }
+    1226                 :            : 
+    1227         [ -  + ]:    6033544 :     MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, i + j));
+    1228         [ -  + ]:    6033544 :     MBEDTLS_MPI_CHK(mbedtls_mpi_lset(X, 0));
+    1229                 :            : 
+    1230                 :    6033544 :     mbedtls_mpi_core_mul(X->p, A->p, i, B->p, j);
+    1231                 :            : 
+    1232                 :            :     /* If the result is 0, we don't shortcut the operation, which reduces
+    1233                 :            :      * but does not eliminate side channels leaking the zero-ness. We do
+    1234                 :            :      * need to take care to set the sign bit properly since the library does
+    1235                 :            :      * not fully support an MPI object with a value of 0 and s == -1. */
+    1236         [ -  + ]:    6033544 :     if (result_is_zero) {
+    1237                 :          0 :         X->s = 1;
+    1238                 :            :     } else {
+    1239                 :    6033544 :         X->s = A->s * B->s;
+    1240                 :            :     }
+    1241                 :            : 
+    1242                 :    6033544 : cleanup:
+    1243                 :            : 
+    1244                 :    6033544 :     mbedtls_mpi_free(&TB); mbedtls_mpi_free(&TA);
+    1245                 :            : 
+    1246                 :    6033544 :     return ret;
+    1247                 :            : }
+    1248                 :            : 
+    1249                 :            : /*
+    1250                 :            :  * Baseline multiplication: X = A * b
+    1251                 :            :  */
+    1252                 :     565278 : int mbedtls_mpi_mul_int(mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_uint b)
+    1253                 :            : {
+    1254                 :     565278 :     size_t n = A->n;
+    1255   [ +  -  +  + ]:    8676452 :     while (n > 0 && A->p[n - 1] == 0) {
+    1256                 :    8111174 :         --n;
+    1257                 :            :     }
+    1258                 :            : 
+    1259                 :            :     /* The general method below doesn't work if b==0. */
+    1260   [ +  +  -  + ]:     565278 :     if (b == 0 || n == 0) {
+    1261                 :          4 :         return mbedtls_mpi_lset(X, 0);
+    1262                 :            :     }
+    1263                 :            : 
+    1264                 :            :     /* Calculate A*b as A + A*(b-1) to take advantage of mbedtls_mpi_core_mla */
+    1265                 :     565274 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1266                 :            :     /* In general, A * b requires 1 limb more than b. If
+    1267                 :            :      * A->p[n - 1] * b / b == A->p[n - 1], then A * b fits in the same
+    1268                 :            :      * number of limbs as A and the call to grow() is not required since
+    1269                 :            :      * copy() will take care of the growth if needed. However, experimentally,
+    1270                 :            :      * making the call to grow() unconditional causes slightly fewer
+    1271                 :            :      * calls to calloc() in ECP code, presumably because it reuses the
+    1272                 :            :      * same mpi for a while and this way the mpi is more likely to directly
+    1273                 :            :      * grow to its final size.
+    1274                 :            :      *
+    1275                 :            :      * Note that calculating A*b as 0 + A*b doesn't work as-is because
+    1276                 :            :      * A,X can be the same. */
+    1277         [ -  + ]:     565274 :     MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, n + 1));
+    1278         [ -  + ]:     565274 :     MBEDTLS_MPI_CHK(mbedtls_mpi_copy(X, A));
+    1279                 :     565274 :     mbedtls_mpi_core_mla(X->p, X->n, A->p, n, b - 1);
+    1280                 :            : 
+    1281                 :     565274 : cleanup:
+    1282                 :     565274 :     return ret;
+    1283                 :            : }
+    1284                 :            : 
+    1285                 :            : /*
+    1286                 :            :  * Unsigned integer divide - double mbedtls_mpi_uint dividend, u1/u0, and
+    1287                 :            :  * mbedtls_mpi_uint divisor, d
+    1288                 :            :  */
+    1289                 :      36658 : static mbedtls_mpi_uint mbedtls_int_div_int(mbedtls_mpi_uint u1,
+    1290                 :            :                                             mbedtls_mpi_uint u0,
+    1291                 :            :                                             mbedtls_mpi_uint d,
+    1292                 :            :                                             mbedtls_mpi_uint *r)
+    1293                 :            : {
+    1294                 :            : #if defined(MBEDTLS_HAVE_UDBL)
+    1295                 :            :     mbedtls_t_udbl dividend, quotient;
+    1296                 :            : #else
+    1297                 :            :     const mbedtls_mpi_uint radix = (mbedtls_mpi_uint) 1 << biH;
+    1298                 :            :     const mbedtls_mpi_uint uint_halfword_mask = ((mbedtls_mpi_uint) 1 << biH) - 1;
+    1299                 :            :     mbedtls_mpi_uint d0, d1, q0, q1, rAX, r0, quotient;
+    1300                 :            :     mbedtls_mpi_uint u0_msw, u0_lsw;
+    1301                 :            :     size_t s;
+    1302                 :            : #endif
+    1303                 :            : 
+    1304                 :            :     /*
+    1305                 :            :      * Check for overflow
+    1306                 :            :      */
+    1307   [ +  -  -  + ]:      36658 :     if (0 == d || u1 >= d) {
+    1308         [ #  # ]:          0 :         if (r != NULL) {
+    1309                 :          0 :             *r = ~(mbedtls_mpi_uint) 0u;
+    1310                 :            :         }
+    1311                 :            : 
+    1312                 :          0 :         return ~(mbedtls_mpi_uint) 0u;
+    1313                 :            :     }
+    1314                 :            : 
+    1315                 :            : #if defined(MBEDTLS_HAVE_UDBL)
+    1316                 :      36658 :     dividend  = (mbedtls_t_udbl) u1 << biL;
+    1317                 :      36658 :     dividend |= (mbedtls_t_udbl) u0;
+    1318                 :      36658 :     quotient = dividend / d;
+    1319         [ -  + ]:      36658 :     if (quotient > ((mbedtls_t_udbl) 1 << biL) - 1) {
+    1320                 :          0 :         quotient = ((mbedtls_t_udbl) 1 << biL) - 1;
+    1321                 :            :     }
+    1322                 :            : 
+    1323         [ -  + ]:      36658 :     if (r != NULL) {
+    1324                 :          0 :         *r = (mbedtls_mpi_uint) (dividend - (quotient * d));
+    1325                 :            :     }
+    1326                 :            : 
+    1327                 :      36658 :     return (mbedtls_mpi_uint) quotient;
+    1328                 :            : #else
+    1329                 :            : 
+    1330                 :            :     /*
+    1331                 :            :      * Algorithm D, Section 4.3.1 - The Art of Computer Programming
+    1332                 :            :      *   Vol. 2 - Seminumerical Algorithms, Knuth
+    1333                 :            :      */
+    1334                 :            : 
+    1335                 :            :     /*
+    1336                 :            :      * Normalize the divisor, d, and dividend, u0, u1
+    1337                 :            :      */
+    1338                 :            :     s = mbedtls_mpi_core_clz(d);
+    1339                 :            :     d = d << s;
+    1340                 :            : 
+    1341                 :            :     u1 = u1 << s;
+    1342                 :            :     u1 |= (u0 >> (biL - s)) & (-(mbedtls_mpi_sint) s >> (biL - 1));
+    1343                 :            :     u0 =  u0 << s;
+    1344                 :            : 
+    1345                 :            :     d1 = d >> biH;
+    1346                 :            :     d0 = d & uint_halfword_mask;
+    1347                 :            : 
+    1348                 :            :     u0_msw = u0 >> biH;
+    1349                 :            :     u0_lsw = u0 & uint_halfword_mask;
+    1350                 :            : 
+    1351                 :            :     /*
+    1352                 :            :      * Find the first quotient and remainder
+    1353                 :            :      */
+    1354                 :            :     q1 = u1 / d1;
+    1355                 :            :     r0 = u1 - d1 * q1;
+    1356                 :            : 
+    1357                 :            :     while (q1 >= radix || (q1 * d0 > radix * r0 + u0_msw)) {
+    1358                 :            :         q1 -= 1;
+    1359                 :            :         r0 += d1;
+    1360                 :            : 
+    1361                 :            :         if (r0 >= radix) {
+    1362                 :            :             break;
+    1363                 :            :         }
+    1364                 :            :     }
+    1365                 :            : 
+    1366                 :            :     rAX = (u1 * radix) + (u0_msw - q1 * d);
+    1367                 :            :     q0 = rAX / d1;
+    1368                 :            :     r0 = rAX - q0 * d1;
+    1369                 :            : 
+    1370                 :            :     while (q0 >= radix || (q0 * d0 > radix * r0 + u0_lsw)) {
+    1371                 :            :         q0 -= 1;
+    1372                 :            :         r0 += d1;
+    1373                 :            : 
+    1374                 :            :         if (r0 >= radix) {
+    1375                 :            :             break;
+    1376                 :            :         }
+    1377                 :            :     }
+    1378                 :            : 
+    1379                 :            :     if (r != NULL) {
+    1380                 :            :         *r = (rAX * radix + u0_lsw - q0 * d) >> s;
+    1381                 :            :     }
+    1382                 :            : 
+    1383                 :            :     quotient = q1 * radix + q0;
+    1384                 :            : 
+    1385                 :            :     return quotient;
+    1386                 :            : #endif
+    1387                 :            : }
+    1388                 :            : 
+    1389                 :            : /*
+    1390                 :            :  * Division by mbedtls_mpi: A = Q * B + R  (HAC 14.20)
+    1391                 :            :  */
+    1392                 :      14241 : int mbedtls_mpi_div_mpi(mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A,
+    1393                 :            :                         const mbedtls_mpi *B)
+    1394                 :            : {
+    1395                 :      14241 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1396                 :            :     size_t i, n, t, k;
+    1397                 :            :     mbedtls_mpi X, Y, Z, T1, T2;
+    1398                 :            :     mbedtls_mpi_uint TP2[3];
+    1399                 :            : 
+    1400         [ -  + ]:      14241 :     if (mbedtls_mpi_cmp_int(B, 0) == 0) {
+    1401                 :          0 :         return MBEDTLS_ERR_MPI_DIVISION_BY_ZERO;
+    1402                 :            :     }
+    1403                 :            : 
+    1404                 :      14241 :     mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y); mbedtls_mpi_init(&Z);
+    1405                 :      14241 :     mbedtls_mpi_init(&T1);
+    1406                 :            :     /*
+    1407                 :            :      * Avoid dynamic memory allocations for constant-size T2.
+    1408                 :            :      *
+    1409                 :            :      * T2 is used for comparison only and the 3 limbs are assigned explicitly,
+    1410                 :            :      * so nobody increase the size of the MPI and we're safe to use an on-stack
+    1411                 :            :      * buffer.
+    1412                 :            :      */
+    1413                 :      14241 :     T2.s = 1;
+    1414                 :      14241 :     T2.n = sizeof(TP2) / sizeof(*TP2);
+    1415                 :      14241 :     T2.p = TP2;
+    1416                 :            : 
+    1417         [ +  + ]:      14241 :     if (mbedtls_mpi_cmp_abs(A, B) < 0) {
+    1418         [ -  + ]:      10629 :         if (Q != NULL) {
+    1419         [ #  # ]:          0 :             MBEDTLS_MPI_CHK(mbedtls_mpi_lset(Q, 0));
+    1420                 :            :         }
+    1421         [ +  - ]:      10629 :         if (R != NULL) {
+    1422         [ -  + ]:      10629 :             MBEDTLS_MPI_CHK(mbedtls_mpi_copy(R, A));
+    1423                 :            :         }
+    1424                 :      10629 :         return 0;
+    1425                 :            :     }
+    1426                 :            : 
+    1427         [ -  + ]:       3612 :     MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&X, A));
+    1428         [ -  + ]:       3612 :     MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&Y, B));
+    1429                 :       3612 :     X.s = Y.s = 1;
+    1430                 :            : 
+    1431         [ -  + ]:       3612 :     MBEDTLS_MPI_CHK(mbedtls_mpi_grow(&Z, A->n + 2));
+    1432         [ -  + ]:       3612 :     MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&Z,  0));
+    1433         [ -  + ]:       3612 :     MBEDTLS_MPI_CHK(mbedtls_mpi_grow(&T1, A->n + 2));
+    1434                 :            : 
+    1435                 :       3612 :     k = mbedtls_mpi_bitlen(&Y) % biL;
+    1436         [ +  - ]:       3612 :     if (k < biL - 1) {
+    1437                 :       3612 :         k = biL - 1 - k;
+    1438         [ -  + ]:       3612 :         MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(&X, k));
+    1439         [ -  + ]:       3612 :         MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(&Y, k));
+    1440                 :            :     } else {
+    1441                 :          0 :         k = 0;
+    1442                 :            :     }
+    1443                 :            : 
+    1444                 :       3612 :     n = X.n - 1;
+    1445                 :       3612 :     t = Y.n - 1;
+    1446         [ -  + ]:       3612 :     MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(&Y, biL * (n - t)));
+    1447                 :            : 
+    1448         [ +  + ]:       3990 :     while (mbedtls_mpi_cmp_mpi(&X, &Y) >= 0) {
+    1449                 :        378 :         Z.p[n - t]++;
+    1450         [ -  + ]:        378 :         MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&X, &X, &Y));
+    1451                 :            :     }
+    1452         [ -  + ]:       3612 :     MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&Y, biL * (n - t)));
+    1453                 :            : 
+    1454         [ +  + ]:      40270 :     for (i = n; i > t; i--) {
+    1455         [ -  + ]:      36658 :         if (X.p[i] >= Y.p[t]) {
+    1456                 :          0 :             Z.p[i - t - 1] = ~(mbedtls_mpi_uint) 0u;
+    1457                 :            :         } else {
+    1458                 :      36658 :             Z.p[i - t - 1] = mbedtls_int_div_int(X.p[i], X.p[i - 1],
+    1459                 :      36658 :                                                  Y.p[t], NULL);
+    1460                 :            :         }
+    1461                 :            : 
+    1462         [ +  - ]:      36658 :         T2.p[0] = (i < 2) ? 0 : X.p[i - 2];
+    1463         [ +  - ]:      36658 :         T2.p[1] = (i < 1) ? 0 : X.p[i - 1];
+    1464                 :      36658 :         T2.p[2] = X.p[i];
+    1465                 :            : 
+    1466                 :      36658 :         Z.p[i - t - 1]++;
+    1467                 :            :         do {
+    1468                 :      62264 :             Z.p[i - t - 1]--;
+    1469                 :            : 
+    1470         [ -  + ]:      62264 :             MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&T1, 0));
+    1471         [ +  - ]:      62264 :             T1.p[0] = (t < 1) ? 0 : Y.p[t - 1];
+    1472                 :      62264 :             T1.p[1] = Y.p[t];
+    1473         [ -  + ]:      62264 :             MBEDTLS_MPI_CHK(mbedtls_mpi_mul_int(&T1, &T1, Z.p[i - t - 1]));
+    1474         [ +  + ]:      62264 :         } while (mbedtls_mpi_cmp_mpi(&T1, &T2) > 0);
+    1475                 :            : 
+    1476         [ -  + ]:      36658 :         MBEDTLS_MPI_CHK(mbedtls_mpi_mul_int(&T1, &Y, Z.p[i - t - 1]));
+    1477         [ -  + ]:      36658 :         MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(&T1,  biL * (i - t - 1)));
+    1478         [ -  + ]:      36658 :         MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&X, &X, &T1));
+    1479                 :            : 
+    1480         [ -  + ]:      36658 :         if (mbedtls_mpi_cmp_int(&X, 0) < 0) {
+    1481         [ #  # ]:          0 :             MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&T1, &Y));
+    1482         [ #  # ]:          0 :             MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(&T1, biL * (i - t - 1)));
+    1483         [ #  # ]:          0 :             MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&X, &X, &T1));
+    1484                 :          0 :             Z.p[i - t - 1]--;
+    1485                 :            :         }
+    1486                 :            :     }
+    1487                 :            : 
+    1488         [ +  + ]:       3612 :     if (Q != NULL) {
+    1489         [ -  + ]:          2 :         MBEDTLS_MPI_CHK(mbedtls_mpi_copy(Q, &Z));
+    1490                 :          2 :         Q->s = A->s * B->s;
+    1491                 :            :     }
+    1492                 :            : 
+    1493         [ +  + ]:       3612 :     if (R != NULL) {
+    1494         [ -  + ]:       3610 :         MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&X, k));
+    1495                 :       3610 :         X.s = A->s;
+    1496         [ -  + ]:       3610 :         MBEDTLS_MPI_CHK(mbedtls_mpi_copy(R, &X));
+    1497                 :            : 
+    1498         [ +  - ]:       3610 :         if (mbedtls_mpi_cmp_int(R, 0) == 0) {
+    1499                 :          0 :             R->s = 1;
+    1500                 :            :         }
+    1501                 :            :     }
+    1502                 :            : 
+    1503                 :       3612 : cleanup:
+    1504                 :            : 
+    1505                 :       3612 :     mbedtls_mpi_free(&X); mbedtls_mpi_free(&Y); mbedtls_mpi_free(&Z);
+    1506                 :       3612 :     mbedtls_mpi_free(&T1);
+    1507                 :       3612 :     mbedtls_platform_zeroize(TP2, sizeof(TP2));
+    1508                 :            : 
+    1509                 :       3612 :     return ret;
+    1510                 :            : }
+    1511                 :            : 
+    1512                 :            : /*
+    1513                 :            :  * Division by int: A = Q * b + R
+    1514                 :            :  */
+    1515                 :          0 : int mbedtls_mpi_div_int(mbedtls_mpi *Q, mbedtls_mpi *R,
+    1516                 :            :                         const mbedtls_mpi *A,
+    1517                 :            :                         mbedtls_mpi_sint b)
+    1518                 :            : {
+    1519                 :            :     mbedtls_mpi B;
+    1520                 :            :     mbedtls_mpi_uint p[1];
+    1521                 :            : 
+    1522                 :          0 :     p[0] = mpi_sint_abs(b);
+    1523                 :          0 :     B.s = TO_SIGN(b);
+    1524                 :          0 :     B.n = 1;
+    1525                 :          0 :     B.p = p;
+    1526                 :            : 
+    1527                 :          0 :     return mbedtls_mpi_div_mpi(Q, R, A, &B);
+    1528                 :            : }
+    1529                 :            : 
+    1530                 :            : /*
+    1531                 :            :  * Modulo: R = A mod B
+    1532                 :            :  */
+    1533                 :      14239 : int mbedtls_mpi_mod_mpi(mbedtls_mpi *R, const mbedtls_mpi *A, const mbedtls_mpi *B)
+    1534                 :            : {
+    1535                 :      14239 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1536                 :            : 
+    1537         [ -  + ]:      14239 :     if (mbedtls_mpi_cmp_int(B, 0) < 0) {
+    1538                 :          0 :         return MBEDTLS_ERR_MPI_NEGATIVE_VALUE;
+    1539                 :            :     }
+    1540                 :            : 
+    1541         [ -  + ]:      14239 :     MBEDTLS_MPI_CHK(mbedtls_mpi_div_mpi(NULL, R, A, B));
+    1542                 :            : 
+    1543         [ +  + ]:      14252 :     while (mbedtls_mpi_cmp_int(R, 0) < 0) {
+    1544         [ -  + ]:         13 :         MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(R, R, B));
+    1545                 :            :     }
+    1546                 :            : 
+    1547         [ -  + ]:      14239 :     while (mbedtls_mpi_cmp_mpi(R, B) >= 0) {
+    1548         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(R, R, B));
+    1549                 :            :     }
+    1550                 :            : 
+    1551                 :      14239 : cleanup:
+    1552                 :            : 
+    1553                 :      14239 :     return ret;
+    1554                 :            : }
+    1555                 :            : 
+    1556                 :            : /*
+    1557                 :            :  * Modulo: r = A mod b
+    1558                 :            :  */
+    1559                 :          0 : int mbedtls_mpi_mod_int(mbedtls_mpi_uint *r, const mbedtls_mpi *A, mbedtls_mpi_sint b)
+    1560                 :            : {
+    1561                 :            :     size_t i;
+    1562                 :            :     mbedtls_mpi_uint x, y, z;
+    1563                 :            : 
+    1564         [ #  # ]:          0 :     if (b == 0) {
+    1565                 :          0 :         return MBEDTLS_ERR_MPI_DIVISION_BY_ZERO;
+    1566                 :            :     }
+    1567                 :            : 
+    1568         [ #  # ]:          0 :     if (b < 0) {
+    1569                 :          0 :         return MBEDTLS_ERR_MPI_NEGATIVE_VALUE;
+    1570                 :            :     }
+    1571                 :            : 
+    1572                 :            :     /*
+    1573                 :            :      * handle trivial cases
+    1574                 :            :      */
+    1575   [ #  #  #  # ]:          0 :     if (b == 1 || A->n == 0) {
+    1576                 :          0 :         *r = 0;
+    1577                 :          0 :         return 0;
+    1578                 :            :     }
+    1579                 :            : 
+    1580         [ #  # ]:          0 :     if (b == 2) {
+    1581                 :          0 :         *r = A->p[0] & 1;
+    1582                 :          0 :         return 0;
+    1583                 :            :     }
+    1584                 :            : 
+    1585                 :            :     /*
+    1586                 :            :      * general case
+    1587                 :            :      */
+    1588         [ #  # ]:          0 :     for (i = A->n, y = 0; i > 0; i--) {
+    1589                 :          0 :         x  = A->p[i - 1];
+    1590                 :          0 :         y  = (y << biH) | (x >> biH);
+    1591                 :          0 :         z  = y / b;
+    1592                 :          0 :         y -= z * b;
+    1593                 :            : 
+    1594                 :          0 :         x <<= biH;
+    1595                 :          0 :         y  = (y << biH) | (x >> biH);
+    1596                 :          0 :         z  = y / b;
+    1597                 :          0 :         y -= z * b;
+    1598                 :            :     }
+    1599                 :            : 
+    1600                 :            :     /*
+    1601                 :            :      * If A is negative, then the current y represents a negative value.
+    1602                 :            :      * Flipping it to the positive side.
+    1603                 :            :      */
+    1604   [ #  #  #  # ]:          0 :     if (A->s < 0 && y != 0) {
+    1605                 :          0 :         y = b - y;
+    1606                 :            :     }
+    1607                 :            : 
+    1608                 :          0 :     *r = y;
+    1609                 :            : 
+    1610                 :          0 :     return 0;
+    1611                 :            : }
+    1612                 :            : 
+    1613                 :        416 : int mbedtls_mpi_exp_mod(mbedtls_mpi *X, const mbedtls_mpi *A,
+    1614                 :            :                         const mbedtls_mpi *E, const mbedtls_mpi *N,
+    1615                 :            :                         mbedtls_mpi *prec_RR)
+    1616                 :            : {
+    1617                 :        416 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1618                 :            : 
+    1619   [ +  -  -  + ]:        416 :     if (mbedtls_mpi_cmp_int(N, 0) <= 0 || (N->p[0] & 1) == 0) {
+    1620                 :          0 :         return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
+    1621                 :            :     }
+    1622                 :            : 
+    1623         [ -  + ]:        416 :     if (mbedtls_mpi_cmp_int(E, 0) < 0) {
+    1624                 :          0 :         return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
+    1625                 :            :     }
+    1626                 :            : 
+    1627   [ +  -  -  + ]:        832 :     if (mbedtls_mpi_bitlen(E) > MBEDTLS_MPI_MAX_BITS ||
+    1628                 :        416 :         mbedtls_mpi_bitlen(N) > MBEDTLS_MPI_MAX_BITS) {
+    1629                 :          0 :         return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
+    1630                 :            :     }
+    1631                 :            : 
+    1632                 :            :     /*
+    1633                 :            :      * Ensure that the exponent that we are passing to the core is not NULL.
+    1634                 :            :      */
+    1635         [ -  + ]:        416 :     if (E->n == 0) {
+    1636                 :          0 :         ret = mbedtls_mpi_lset(X, 1);
+    1637                 :          0 :         return ret;
+    1638                 :            :     }
+    1639                 :            : 
+    1640                 :            :     /*
+    1641                 :            :      * Allocate working memory for mbedtls_mpi_core_exp_mod()
+    1642                 :            :      */
+    1643                 :        416 :     size_t T_limbs = mbedtls_mpi_core_exp_mod_working_limbs(N->n, E->n);
+    1644                 :        416 :     mbedtls_mpi_uint *T = (mbedtls_mpi_uint *) mbedtls_calloc(T_limbs, sizeof(mbedtls_mpi_uint));
+    1645         [ -  + ]:        416 :     if (T == NULL) {
+    1646                 :          0 :         return MBEDTLS_ERR_MPI_ALLOC_FAILED;
+    1647                 :            :     }
+    1648                 :            : 
+    1649                 :            :     mbedtls_mpi RR;
+    1650                 :        416 :     mbedtls_mpi_init(&RR);
+    1651                 :            : 
+    1652                 :            :     /*
+    1653                 :            :      * If 1st call, pre-compute R^2 mod N
+    1654                 :            :      */
+    1655   [ +  -  +  + ]:        416 :     if (prec_RR == NULL || prec_RR->p == NULL) {
+    1656         [ -  + ]:        350 :         MBEDTLS_MPI_CHK(mbedtls_mpi_core_get_mont_r2_unsafe(&RR, N));
+    1657                 :            : 
+    1658         [ +  - ]:        350 :         if (prec_RR != NULL) {
+    1659                 :        350 :             *prec_RR = RR;
+    1660                 :            :         }
+    1661                 :            :     } else {
+    1662         [ -  + ]:         66 :         MBEDTLS_MPI_CHK(mbedtls_mpi_grow(prec_RR, N->n));
+    1663                 :         66 :         RR = *prec_RR;
+    1664                 :            :     }
+    1665                 :            : 
+    1666                 :            :     /*
+    1667                 :            :      * To preserve constness we need to make a copy of A. Using X for this to
+    1668                 :            :      * save memory.
+    1669                 :            :      */
+    1670         [ -  + ]:        416 :     MBEDTLS_MPI_CHK(mbedtls_mpi_copy(X, A));
+    1671                 :            : 
+    1672                 :            :     /*
+    1673                 :            :      * Compensate for negative A (and correct at the end).
+    1674                 :            :      */
+    1675                 :        416 :     X->s = 1;
+    1676                 :            : 
+    1677                 :            :     /*
+    1678                 :            :      * Make sure that X is in a form that is safe for consumption by
+    1679                 :            :      * the core functions.
+    1680                 :            :      *
+    1681                 :            :      * - The core functions will not touch the limbs of X above N->n. The
+    1682                 :            :      *   result will be correct if those limbs are 0, which the mod call
+    1683                 :            :      *   ensures.
+    1684                 :            :      * - Also, X must have at least as many limbs as N for the calls to the
+    1685                 :            :      *   core functions.
+    1686                 :            :      */
+    1687         [ +  + ]:        416 :     if (mbedtls_mpi_cmp_mpi(X, N) >= 0) {
+    1688         [ -  + ]:         54 :         MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(X, X, N));
+    1689                 :            :     }
+    1690         [ -  + ]:        416 :     MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, N->n));
+    1691                 :            : 
+    1692                 :            :     /*
+    1693                 :            :      * Convert to and from Montgomery around mbedtls_mpi_core_exp_mod().
+    1694                 :            :      */
+    1695                 :            :     {
+    1696                 :        416 :         mbedtls_mpi_uint mm = mbedtls_mpi_core_montmul_init(N->p);
+    1697                 :        416 :         mbedtls_mpi_core_to_mont_rep(X->p, X->p, N->p, N->n, mm, RR.p, T);
+    1698                 :        416 :         mbedtls_mpi_core_exp_mod(X->p, X->p, N->p, N->n, E->p, E->n, RR.p, T);
+    1699                 :        416 :         mbedtls_mpi_core_from_mont_rep(X->p, X->p, N->p, N->n, mm, T);
+    1700                 :            :     }
+    1701                 :            : 
+    1702                 :            :     /*
+    1703                 :            :      * Correct for negative A.
+    1704                 :            :      */
+    1705   [ +  -  -  - ]:        416 :     if (A->s == -1 && (E->p[0] & 1) != 0) {
+    1706                 :          0 :         mbedtls_ct_condition_t is_x_non_zero = mbedtls_mpi_core_check_zero_ct(X->p, X->n);
+    1707                 :          0 :         X->s = mbedtls_ct_mpi_sign_if(is_x_non_zero, -1, 1);
+    1708                 :            : 
+    1709         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(X, N, X));
+    1710                 :            :     }
+    1711                 :            : 
+    1712                 :        416 : cleanup:
+    1713                 :            : 
+    1714                 :        416 :     mbedtls_mpi_zeroize_and_free(T, T_limbs);
+    1715                 :            : 
+    1716   [ +  -  -  + ]:        416 :     if (prec_RR == NULL || prec_RR->p == NULL) {
+    1717                 :          0 :         mbedtls_mpi_free(&RR);
+    1718                 :            :     }
+    1719                 :            : 
+    1720                 :        416 :     return ret;
+    1721                 :            : }
+    1722                 :            : 
+    1723                 :            : /*
+    1724                 :            :  * Greatest common divisor: G = gcd(A, B)  (HAC 14.54)
+    1725                 :            :  */
+    1726                 :       9097 : int mbedtls_mpi_gcd(mbedtls_mpi *G, const mbedtls_mpi *A, const mbedtls_mpi *B)
+    1727                 :            : {
+    1728                 :       9097 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1729                 :            :     size_t lz, lzt;
+    1730                 :            :     mbedtls_mpi TA, TB;
+    1731                 :            : 
+    1732                 :       9097 :     mbedtls_mpi_init(&TA); mbedtls_mpi_init(&TB);
+    1733                 :            : 
+    1734         [ -  + ]:       9097 :     MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TA, A));
+    1735         [ -  + ]:       9097 :     MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TB, B));
+    1736                 :            : 
+    1737                 :       9097 :     lz = mbedtls_mpi_lsb(&TA);
+    1738                 :       9097 :     lzt = mbedtls_mpi_lsb(&TB);
+    1739                 :            : 
+    1740                 :            :     /* The loop below gives the correct result when A==0 but not when B==0.
+    1741                 :            :      * So have a special case for B==0. Leverage the fact that we just
+    1742                 :            :      * calculated the lsb and lsb(B)==0 iff B is odd or 0 to make the test
+    1743                 :            :      * slightly more efficient than cmp_int(). */
+    1744   [ +  -  -  + ]:       9097 :     if (lzt == 0 && mbedtls_mpi_get_bit(&TB, 0) == 0) {
+    1745                 :          0 :         ret = mbedtls_mpi_copy(G, A);
+    1746                 :          0 :         goto cleanup;
+    1747                 :            :     }
+    1748                 :            : 
+    1749         [ +  + ]:       9097 :     if (lzt < lz) {
+    1750                 :       5201 :         lz = lzt;
+    1751                 :            :     }
+    1752                 :            : 
+    1753                 :       9097 :     TA.s = TB.s = 1;
+    1754                 :            : 
+    1755                 :            :     /* We mostly follow the procedure described in HAC 14.54, but with some
+    1756                 :            :      * minor differences:
+    1757                 :            :      * - Sequences of multiplications or divisions by 2 are grouped into a
+    1758                 :            :      *   single shift operation.
+    1759                 :            :      * - The procedure in HAC assumes that 0 < TB <= TA.
+    1760                 :            :      *     - The condition TB <= TA is not actually necessary for correctness.
+    1761                 :            :      *       TA and TB have symmetric roles except for the loop termination
+    1762                 :            :      *       condition, and the shifts at the beginning of the loop body
+    1763                 :            :      *       remove any significance from the ordering of TA vs TB before
+    1764                 :            :      *       the shifts.
+    1765                 :            :      *     - If TA = 0, the loop goes through 0 iterations and the result is
+    1766                 :            :      *       correctly TB.
+    1767                 :            :      *     - The case TB = 0 was short-circuited above.
+    1768                 :            :      *
+    1769                 :            :      * For the correctness proof below, decompose the original values of
+    1770                 :            :      * A and B as
+    1771                 :            :      *   A = sa * 2^a * A' with A'=0 or A' odd, and sa = +-1
+    1772                 :            :      *   B = sb * 2^b * B' with B'=0 or B' odd, and sb = +-1
+    1773                 :            :      * Then gcd(A, B) = 2^{min(a,b)} * gcd(A',B'),
+    1774                 :            :      * and gcd(A',B') is odd or 0.
+    1775                 :            :      *
+    1776                 :            :      * At the beginning, we have TA = |A| and TB = |B| so gcd(A,B) = gcd(TA,TB).
+    1777                 :            :      * The code maintains the following invariant:
+    1778                 :            :      *     gcd(A,B) = 2^k * gcd(TA,TB) for some k   (I)
+    1779                 :            :      */
+    1780                 :            : 
+    1781                 :            :     /* Proof that the loop terminates:
+    1782                 :            :      * At each iteration, either the right-shift by 1 is made on a nonzero
+    1783                 :            :      * value and the nonnegative integer bitlen(TA) + bitlen(TB) decreases
+    1784                 :            :      * by at least 1, or the right-shift by 1 is made on zero and then
+    1785                 :            :      * TA becomes 0 which ends the loop (TB cannot be 0 if it is right-shifted
+    1786                 :            :      * since in that case TB is calculated from TB-TA with the condition TB>TA).
+    1787                 :            :      */
+    1788         [ +  + ]:    1692226 :     while (mbedtls_mpi_cmp_int(&TA, 0) != 0) {
+    1789                 :            :         /* Divisions by 2 preserve the invariant (I). */
+    1790         [ -  + ]:    1683129 :         MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&TA, mbedtls_mpi_lsb(&TA)));
+    1791         [ -  + ]:    1683129 :         MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&TB, mbedtls_mpi_lsb(&TB)));
+    1792                 :            : 
+    1793                 :            :         /* Set either TA or TB to |TA-TB|/2. Since TA and TB are both odd,
+    1794                 :            :          * TA-TB is even so the division by 2 has an integer result.
+    1795                 :            :          * Invariant (I) is preserved since any odd divisor of both TA and TB
+    1796                 :            :          * also divides |TA-TB|/2, and any odd divisor of both TA and |TA-TB|/2
+    1797                 :            :          * also divides TB, and any odd divisor of both TB and |TA-TB|/2 also
+    1798                 :            :          * divides TA.
+    1799                 :            :          */
+    1800         [ +  + ]:    1683129 :         if (mbedtls_mpi_cmp_mpi(&TA, &TB) >= 0) {
+    1801         [ -  + ]:     858058 :             MBEDTLS_MPI_CHK(mbedtls_mpi_sub_abs(&TA, &TA, &TB));
+    1802         [ -  + ]:     858058 :             MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&TA, 1));
+    1803                 :            :         } else {
+    1804         [ -  + ]:     825071 :             MBEDTLS_MPI_CHK(mbedtls_mpi_sub_abs(&TB, &TB, &TA));
+    1805         [ -  + ]:     825071 :             MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&TB, 1));
+    1806                 :            :         }
+    1807                 :            :         /* Note that one of TA or TB is still odd. */
+    1808                 :            :     }
+    1809                 :            : 
+    1810                 :            :     /* By invariant (I), gcd(A,B) = 2^k * gcd(TA,TB) for some k.
+    1811                 :            :      * At the loop exit, TA = 0, so gcd(TA,TB) = TB.
+    1812                 :            :      * - If there was at least one loop iteration, then one of TA or TB is odd,
+    1813                 :            :      *   and TA = 0, so TB is odd and gcd(TA,TB) = gcd(A',B'). In this case,
+    1814                 :            :      *   lz = min(a,b) so gcd(A,B) = 2^lz * TB.
+    1815                 :            :      * - If there was no loop iteration, then A was 0, and gcd(A,B) = B.
+    1816                 :            :      *   In this case, lz = 0 and B = TB so gcd(A,B) = B = 2^lz * TB as well.
+    1817                 :            :      */
+    1818                 :            : 
+    1819         [ -  + ]:       9097 :     MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(&TB, lz));
+    1820         [ +  - ]:       9097 :     MBEDTLS_MPI_CHK(mbedtls_mpi_copy(G, &TB));
+    1821                 :            : 
+    1822                 :       9097 : cleanup:
+    1823                 :            : 
+    1824                 :       9097 :     mbedtls_mpi_free(&TA); mbedtls_mpi_free(&TB);
+    1825                 :            : 
+    1826                 :       9097 :     return ret;
+    1827                 :            : }
+    1828                 :            : 
+    1829                 :            : /*
+    1830                 :            :  * Fill X with size bytes of random.
+    1831                 :            :  * The bytes returned from the RNG are used in a specific order which
+    1832                 :            :  * is suitable for deterministic ECDSA (see the specification of
+    1833                 :            :  * mbedtls_mpi_random() and the implementation in mbedtls_mpi_fill_random()).
+    1834                 :            :  */
+    1835                 :        108 : int mbedtls_mpi_fill_random(mbedtls_mpi *X, size_t size,
+    1836                 :            :                             int (*f_rng)(void *, unsigned char *, size_t),
+    1837                 :            :                             void *p_rng)
+    1838                 :            : {
+    1839                 :        108 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1840                 :        108 :     const size_t limbs = CHARS_TO_LIMBS(size);
+    1841                 :            : 
+    1842                 :            :     /* Ensure that target MPI has exactly the necessary number of limbs */
+    1843         [ -  + ]:        108 :     MBEDTLS_MPI_CHK(mbedtls_mpi_resize_clear(X, limbs));
+    1844         [ -  + ]:        108 :     if (size == 0) {
+    1845                 :          0 :         return 0;
+    1846                 :            :     }
+    1847                 :            : 
+    1848                 :        108 :     ret = mbedtls_mpi_core_fill_random(X->p, X->n, size, f_rng, p_rng);
+    1849                 :            : 
+    1850                 :        108 : cleanup:
+    1851                 :        108 :     return ret;
+    1852                 :            : }
+    1853                 :            : 
+    1854                 :       1162 : int mbedtls_mpi_random(mbedtls_mpi *X,
+    1855                 :            :                        mbedtls_mpi_sint min,
+    1856                 :            :                        const mbedtls_mpi *N,
+    1857                 :            :                        int (*f_rng)(void *, unsigned char *, size_t),
+    1858                 :            :                        void *p_rng)
+    1859                 :            : {
+    1860         [ -  + ]:       1162 :     if (min < 0) {
+    1861                 :          0 :         return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
+    1862                 :            :     }
+    1863         [ -  + ]:       1162 :     if (mbedtls_mpi_cmp_int(N, min) <= 0) {
+    1864                 :          0 :         return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
+    1865                 :            :     }
+    1866                 :            : 
+    1867                 :            :     /* Ensure that target MPI has exactly the same number of limbs
+    1868                 :            :      * as the upper bound, even if the upper bound has leading zeros.
+    1869                 :            :      * This is necessary for mbedtls_mpi_core_random. */
+    1870                 :       1162 :     int ret = mbedtls_mpi_resize_clear(X, N->n);
+    1871         [ -  + ]:       1162 :     if (ret != 0) {
+    1872                 :          0 :         return ret;
+    1873                 :            :     }
+    1874                 :            : 
+    1875                 :       1162 :     return mbedtls_mpi_core_random(X->p, min, N->p, X->n, f_rng, p_rng);
+    1876                 :            : }
+    1877                 :            : 
+    1878                 :            : /*
+    1879                 :            :  * Modular inverse: X = A^-1 mod N  (HAC 14.61 / 14.64)
+    1880                 :            :  */
+    1881                 :       9093 : int mbedtls_mpi_inv_mod(mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *N)
+    1882                 :            : {
+    1883                 :       9093 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1884                 :            :     mbedtls_mpi G, TA, TU, U1, U2, TB, TV, V1, V2;
+    1885                 :            : 
+    1886         [ -  + ]:       9093 :     if (mbedtls_mpi_cmp_int(N, 1) <= 0) {
+    1887                 :          0 :         return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
+    1888                 :            :     }
+    1889                 :            : 
+    1890                 :       9093 :     mbedtls_mpi_init(&TA); mbedtls_mpi_init(&TU); mbedtls_mpi_init(&U1); mbedtls_mpi_init(&U2);
+    1891                 :       9093 :     mbedtls_mpi_init(&G); mbedtls_mpi_init(&TB); mbedtls_mpi_init(&TV);
+    1892                 :       9093 :     mbedtls_mpi_init(&V1); mbedtls_mpi_init(&V2);
+    1893                 :            : 
+    1894         [ -  + ]:       9093 :     MBEDTLS_MPI_CHK(mbedtls_mpi_gcd(&G, A, N));
+    1895                 :            : 
+    1896         [ -  + ]:       9093 :     if (mbedtls_mpi_cmp_int(&G, 1) != 0) {
+    1897                 :          0 :         ret = MBEDTLS_ERR_MPI_NOT_ACCEPTABLE;
+    1898                 :          0 :         goto cleanup;
+    1899                 :            :     }
+    1900                 :            : 
+    1901         [ -  + ]:       9093 :     MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&TA, A, N));
+    1902         [ -  + ]:       9093 :     MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TU, &TA));
+    1903         [ -  + ]:       9093 :     MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TB, N));
+    1904         [ -  + ]:       9093 :     MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TV, N));
+    1905                 :            : 
+    1906         [ -  + ]:       9093 :     MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&U1, 1));
+    1907         [ -  + ]:       9093 :     MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&U2, 0));
+    1908         [ -  + ]:       9093 :     MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&V1, 0));
+    1909         [ -  + ]:       9093 :     MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&V2, 1));
+    1910                 :            : 
+    1911                 :            :     do {
+    1912         [ +  + ]:    3365346 :         while ((TU.p[0] & 1) == 0) {
+    1913         [ -  + ]:    1685698 :             MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&TU, 1));
+    1914                 :            : 
+    1915   [ +  +  -  + ]:    1685698 :             if ((U1.p[0] & 1) != 0 || (U2.p[0] & 1) != 0) {
+    1916         [ -  + ]:     708092 :                 MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&U1, &U1, &TB));
+    1917         [ -  + ]:     708092 :                 MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&U2, &U2, &TA));
+    1918                 :            :             }
+    1919                 :            : 
+    1920         [ -  + ]:    1685698 :             MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&U1, 1));
+    1921         [ -  + ]:    1685698 :             MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&U2, 1));
+    1922                 :            :         }
+    1923                 :            : 
+    1924         [ +  + ]:    3336328 :         while ((TV.p[0] & 1) == 0) {
+    1925         [ -  + ]:    1656680 :             MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&TV, 1));
+    1926                 :            : 
+    1927   [ +  +  -  + ]:    1656680 :             if ((V1.p[0] & 1) != 0 || (V2.p[0] & 1) != 0) {
+    1928         [ -  + ]:     752842 :                 MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&V1, &V1, &TB));
+    1929         [ -  + ]:     752842 :                 MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&V2, &V2, &TA));
+    1930                 :            :             }
+    1931                 :            : 
+    1932         [ -  + ]:    1656680 :             MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&V1, 1));
+    1933         [ -  + ]:    1656680 :             MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&V2, 1));
+    1934                 :            :         }
+    1935                 :            : 
+    1936         [ +  + ]:    1679648 :         if (mbedtls_mpi_cmp_mpi(&TU, &TV) >= 0) {
+    1937         [ -  + ]:     857356 :             MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&TU, &TU, &TV));
+    1938         [ -  + ]:     857356 :             MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&U1, &U1, &V1));
+    1939         [ -  + ]:     857356 :             MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&U2, &U2, &V2));
+    1940                 :            :         } else {
+    1941         [ -  + ]:     822292 :             MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&TV, &TV, &TU));
+    1942         [ -  + ]:     822292 :             MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&V1, &V1, &U1));
+    1943         [ -  + ]:     822292 :             MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&V2, &V2, &U2));
+    1944                 :            :         }
+    1945         [ +  + ]:    1679648 :     } while (mbedtls_mpi_cmp_int(&TU, 0) != 0);
+    1946                 :            : 
+    1947         [ +  + ]:      10020 :     while (mbedtls_mpi_cmp_int(&V1, 0) < 0) {
+    1948         [ -  + ]:        927 :         MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&V1, &V1, N));
+    1949                 :            :     }
+    1950                 :            : 
+    1951         [ +  + ]:       9100 :     while (mbedtls_mpi_cmp_mpi(&V1, N) >= 0) {
+    1952         [ -  + ]:          7 :         MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&V1, &V1, N));
+    1953                 :            :     }
+    1954                 :            : 
+    1955         [ +  - ]:       9093 :     MBEDTLS_MPI_CHK(mbedtls_mpi_copy(X, &V1));
+    1956                 :            : 
+    1957                 :       9093 : cleanup:
+    1958                 :            : 
+    1959                 :       9093 :     mbedtls_mpi_free(&TA); mbedtls_mpi_free(&TU); mbedtls_mpi_free(&U1); mbedtls_mpi_free(&U2);
+    1960                 :       9093 :     mbedtls_mpi_free(&G); mbedtls_mpi_free(&TB); mbedtls_mpi_free(&TV);
+    1961                 :       9093 :     mbedtls_mpi_free(&V1); mbedtls_mpi_free(&V2);
+    1962                 :            : 
+    1963                 :       9093 :     return ret;
+    1964                 :            : }
+    1965                 :            : 
+    1966                 :            : #if defined(MBEDTLS_GENPRIME)
+    1967                 :            : 
+    1968                 :            : /* Gaps between primes, starting at 3. https://oeis.org/A001223 */
+    1969                 :            : static const unsigned char small_prime_gaps[] = {
+    1970                 :            :     2, 2, 4, 2, 4, 2, 4, 6,
+    1971                 :            :     2, 6, 4, 2, 4, 6, 6, 2,
+    1972                 :            :     6, 4, 2, 6, 4, 6, 8, 4,
+    1973                 :            :     2, 4, 2, 4, 14, 4, 6, 2,
+    1974                 :            :     10, 2, 6, 6, 4, 6, 6, 2,
+    1975                 :            :     10, 2, 4, 2, 12, 12, 4, 2,
+    1976                 :            :     4, 6, 2, 10, 6, 6, 6, 2,
+    1977                 :            :     6, 4, 2, 10, 14, 4, 2, 4,
+    1978                 :            :     14, 6, 10, 2, 4, 6, 8, 6,
+    1979                 :            :     6, 4, 6, 8, 4, 8, 10, 2,
+    1980                 :            :     10, 2, 6, 4, 6, 8, 4, 2,
+    1981                 :            :     4, 12, 8, 4, 8, 4, 6, 12,
+    1982                 :            :     2, 18, 6, 10, 6, 6, 2, 6,
+    1983                 :            :     10, 6, 6, 2, 6, 6, 4, 2,
+    1984                 :            :     12, 10, 2, 4, 6, 6, 2, 12,
+    1985                 :            :     4, 6, 8, 10, 8, 10, 8, 6,
+    1986                 :            :     6, 4, 8, 6, 4, 8, 4, 14,
+    1987                 :            :     10, 12, 2, 10, 2, 4, 2, 10,
+    1988                 :            :     14, 4, 2, 4, 14, 4, 2, 4,
+    1989                 :            :     20, 4, 8, 10, 8, 4, 6, 6,
+    1990                 :            :     14, 4, 6, 6, 8, 6, /*reaches 997*/
+    1991                 :            :     0 /* the last entry is effectively unused */
+    1992                 :            : };
+    1993                 :            : 
+    1994                 :            : /*
+    1995                 :            :  * Small divisors test (X must be positive)
+    1996                 :            :  *
+    1997                 :            :  * Return values:
+    1998                 :            :  * 0: no small factor (possible prime, more tests needed)
+    1999                 :            :  * 1: certain prime
+    2000                 :            :  * MBEDTLS_ERR_MPI_NOT_ACCEPTABLE: certain non-prime
+    2001                 :            :  * other negative: error
+    2002                 :            :  */
+    2003                 :          0 : static int mpi_check_small_factors(const mbedtls_mpi *X)
+    2004                 :            : {
+    2005                 :          0 :     int ret = 0;
+    2006                 :            :     size_t i;
+    2007                 :            :     mbedtls_mpi_uint r;
+    2008                 :          0 :     unsigned p = 3; /* The first odd prime */
+    2009                 :            : 
+    2010         [ #  # ]:          0 :     if ((X->p[0] & 1) == 0) {
+    2011                 :          0 :         return MBEDTLS_ERR_MPI_NOT_ACCEPTABLE;
+    2012                 :            :     }
+    2013                 :            : 
+    2014         [ #  # ]:          0 :     for (i = 0; i < sizeof(small_prime_gaps); p += small_prime_gaps[i], i++) {
+    2015         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_mod_int(&r, X, p));
+    2016         [ #  # ]:          0 :         if (r == 0) {
+    2017         [ #  # ]:          0 :             if (mbedtls_mpi_cmp_int(X, p) == 0) {
+    2018                 :          0 :                 return 1;
+    2019                 :            :             } else {
+    2020                 :          0 :                 return MBEDTLS_ERR_MPI_NOT_ACCEPTABLE;
+    2021                 :            :             }
+    2022                 :            :         }
+    2023                 :            :     }
+    2024                 :            : 
+    2025                 :          0 : cleanup:
+    2026                 :          0 :     return ret;
+    2027                 :            : }
+    2028                 :            : 
+    2029                 :            : /*
+    2030                 :            :  * Miller-Rabin pseudo-primality test  (HAC 4.24)
+    2031                 :            :  */
+    2032                 :          0 : static int mpi_miller_rabin(const mbedtls_mpi *X, size_t rounds,
+    2033                 :            :                             int (*f_rng)(void *, unsigned char *, size_t),
+    2034                 :            :                             void *p_rng)
+    2035                 :            : {
+    2036                 :            :     int ret, count;
+    2037                 :            :     size_t i, j, k, s;
+    2038                 :            :     mbedtls_mpi W, R, T, A, RR;
+    2039                 :            : 
+    2040                 :          0 :     mbedtls_mpi_init(&W); mbedtls_mpi_init(&R);
+    2041                 :          0 :     mbedtls_mpi_init(&T); mbedtls_mpi_init(&A);
+    2042                 :          0 :     mbedtls_mpi_init(&RR);
+    2043                 :            : 
+    2044                 :            :     /*
+    2045                 :            :      * W = |X| - 1
+    2046                 :            :      * R = W >> lsb( W )
+    2047                 :            :      */
+    2048         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&W, X, 1));
+    2049                 :          0 :     s = mbedtls_mpi_lsb(&W);
+    2050         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&R, &W));
+    2051         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&R, s));
+    2052                 :            : 
+    2053         [ #  # ]:          0 :     for (i = 0; i < rounds; i++) {
+    2054                 :            :         /*
+    2055                 :            :          * pick a random A, 1 < A < |X| - 1
+    2056                 :            :          */
+    2057                 :          0 :         count = 0;
+    2058                 :            :         do {
+    2059         [ #  # ]:          0 :             MBEDTLS_MPI_CHK(mbedtls_mpi_fill_random(&A, X->n * ciL, f_rng, p_rng));
+    2060                 :            : 
+    2061                 :          0 :             j = mbedtls_mpi_bitlen(&A);
+    2062                 :          0 :             k = mbedtls_mpi_bitlen(&W);
+    2063         [ #  # ]:          0 :             if (j > k) {
+    2064                 :          0 :                 A.p[A.n - 1] &= ((mbedtls_mpi_uint) 1 << (k - (A.n - 1) * biL - 1)) - 1;
+    2065                 :            :             }
+    2066                 :            : 
+    2067         [ #  # ]:          0 :             if (count++ > 30) {
+    2068                 :          0 :                 ret = MBEDTLS_ERR_MPI_NOT_ACCEPTABLE;
+    2069                 :          0 :                 goto cleanup;
+    2070                 :            :             }
+    2071                 :            : 
+    2072   [ #  #  #  # ]:          0 :         } while (mbedtls_mpi_cmp_mpi(&A, &W) >= 0 ||
+    2073                 :          0 :                  mbedtls_mpi_cmp_int(&A, 1)  <= 0);
+    2074                 :            : 
+    2075                 :            :         /*
+    2076                 :            :          * A = A^R mod |X|
+    2077                 :            :          */
+    2078         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_exp_mod(&A, &A, &R, X, &RR));
+    2079                 :            : 
+    2080   [ #  #  #  # ]:          0 :         if (mbedtls_mpi_cmp_mpi(&A, &W) == 0 ||
+    2081                 :          0 :             mbedtls_mpi_cmp_int(&A,  1) == 0) {
+    2082                 :          0 :             continue;
+    2083                 :            :         }
+    2084                 :            : 
+    2085                 :          0 :         j = 1;
+    2086   [ #  #  #  # ]:          0 :         while (j < s && mbedtls_mpi_cmp_mpi(&A, &W) != 0) {
+    2087                 :            :             /*
+    2088                 :            :              * A = A * A mod |X|
+    2089                 :            :              */
+    2090         [ #  # ]:          0 :             MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&T, &A, &A));
+    2091         [ #  # ]:          0 :             MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&A, &T, X));
+    2092                 :            : 
+    2093         [ #  # ]:          0 :             if (mbedtls_mpi_cmp_int(&A, 1) == 0) {
+    2094                 :          0 :                 break;
+    2095                 :            :             }
+    2096                 :            : 
+    2097                 :          0 :             j++;
+    2098                 :            :         }
+    2099                 :            : 
+    2100                 :            :         /*
+    2101                 :            :          * not prime if A != |X| - 1 or A == 1
+    2102                 :            :          */
+    2103   [ #  #  #  # ]:          0 :         if (mbedtls_mpi_cmp_mpi(&A, &W) != 0 ||
+    2104                 :          0 :             mbedtls_mpi_cmp_int(&A,  1) == 0) {
+    2105                 :          0 :             ret = MBEDTLS_ERR_MPI_NOT_ACCEPTABLE;
+    2106                 :          0 :             break;
+    2107                 :            :         }
+    2108                 :            :     }
+    2109                 :            : 
+    2110                 :          0 : cleanup:
+    2111                 :          0 :     mbedtls_mpi_free(&W); mbedtls_mpi_free(&R);
+    2112                 :          0 :     mbedtls_mpi_free(&T); mbedtls_mpi_free(&A);
+    2113                 :          0 :     mbedtls_mpi_free(&RR);
+    2114                 :            : 
+    2115                 :          0 :     return ret;
+    2116                 :            : }
+    2117                 :            : 
+    2118                 :            : /*
+    2119                 :            :  * Pseudo-primality test: small factors, then Miller-Rabin
+    2120                 :            :  */
+    2121                 :          0 : int mbedtls_mpi_is_prime_ext(const mbedtls_mpi *X, int rounds,
+    2122                 :            :                              int (*f_rng)(void *, unsigned char *, size_t),
+    2123                 :            :                              void *p_rng)
+    2124                 :            : {
+    2125                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    2126                 :            :     mbedtls_mpi XX;
+    2127                 :            : 
+    2128                 :          0 :     XX.s = 1;
+    2129                 :          0 :     XX.n = X->n;
+    2130                 :          0 :     XX.p = X->p;
+    2131                 :            : 
+    2132   [ #  #  #  # ]:          0 :     if (mbedtls_mpi_cmp_int(&XX, 0) == 0 ||
+    2133                 :          0 :         mbedtls_mpi_cmp_int(&XX, 1) == 0) {
+    2134                 :          0 :         return MBEDTLS_ERR_MPI_NOT_ACCEPTABLE;
+    2135                 :            :     }
+    2136                 :            : 
+    2137         [ #  # ]:          0 :     if (mbedtls_mpi_cmp_int(&XX, 2) == 0) {
+    2138                 :          0 :         return 0;
+    2139                 :            :     }
+    2140                 :            : 
+    2141         [ #  # ]:          0 :     if ((ret = mpi_check_small_factors(&XX)) != 0) {
+    2142         [ #  # ]:          0 :         if (ret == 1) {
+    2143                 :          0 :             return 0;
+    2144                 :            :         }
+    2145                 :            : 
+    2146                 :          0 :         return ret;
+    2147                 :            :     }
+    2148                 :            : 
+    2149                 :          0 :     return mpi_miller_rabin(&XX, rounds, f_rng, p_rng);
+    2150                 :            : }
+    2151                 :            : 
+    2152                 :            : /*
+    2153                 :            :  * Prime number generation
+    2154                 :            :  *
+    2155                 :            :  * To generate an RSA key in a way recommended by FIPS 186-4, both primes must
+    2156                 :            :  * be either 1024 bits or 1536 bits long, and flags must contain
+    2157                 :            :  * MBEDTLS_MPI_GEN_PRIME_FLAG_LOW_ERR.
+    2158                 :            :  */
+    2159                 :          0 : int mbedtls_mpi_gen_prime(mbedtls_mpi *X, size_t nbits, int flags,
+    2160                 :            :                           int (*f_rng)(void *, unsigned char *, size_t),
+    2161                 :            :                           void *p_rng)
+    2162                 :            : {
+    2163                 :            : #ifdef MBEDTLS_HAVE_INT64
+    2164                 :            : // ceil(2^63.5)
+    2165                 :            : #define CEIL_MAXUINT_DIV_SQRT2 0xb504f333f9de6485ULL
+    2166                 :            : #else
+    2167                 :            : // ceil(2^31.5)
+    2168                 :            : #define CEIL_MAXUINT_DIV_SQRT2 0xb504f334U
+    2169                 :            : #endif
+    2170                 :          0 :     int ret = MBEDTLS_ERR_MPI_NOT_ACCEPTABLE;
+    2171                 :            :     size_t k, n;
+    2172                 :            :     int rounds;
+    2173                 :            :     mbedtls_mpi_uint r;
+    2174                 :            :     mbedtls_mpi Y;
+    2175                 :            : 
+    2176   [ #  #  #  # ]:          0 :     if (nbits < 3 || nbits > MBEDTLS_MPI_MAX_BITS) {
+    2177                 :          0 :         return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
+    2178                 :            :     }
+    2179                 :            : 
+    2180                 :          0 :     mbedtls_mpi_init(&Y);
+    2181                 :            : 
+    2182                 :          0 :     n = BITS_TO_LIMBS(nbits);
+    2183                 :            : 
+    2184         [ #  # ]:          0 :     if ((flags & MBEDTLS_MPI_GEN_PRIME_FLAG_LOW_ERR) == 0) {
+    2185                 :            :         /*
+    2186                 :            :          * 2^-80 error probability, number of rounds chosen per HAC, table 4.4
+    2187                 :            :          */
+    2188   [ #  #  #  # ]:          0 :         rounds = ((nbits >= 1300) ?  2 : (nbits >=  850) ?  3 :
+    2189   [ #  #  #  # ]:          0 :                   (nbits >=  650) ?  4 : (nbits >=  350) ?  8 :
+    2190   [ #  #  #  # ]:          0 :                   (nbits >=  250) ? 12 : (nbits >=  150) ? 18 : 27);
+    2191                 :            :     } else {
+    2192                 :            :         /*
+    2193                 :            :          * 2^-100 error probability, number of rounds computed based on HAC,
+    2194                 :            :          * fact 4.48
+    2195                 :            :          */
+    2196   [ #  #  #  # ]:          0 :         rounds = ((nbits >= 1450) ?  4 : (nbits >=  1150) ?  5 :
+    2197   [ #  #  #  # ]:          0 :                   (nbits >= 1000) ?  6 : (nbits >=   850) ?  7 :
+    2198   [ #  #  #  # ]:          0 :                   (nbits >=  750) ?  8 : (nbits >=   500) ? 13 :
+    2199   [ #  #  #  # ]:          0 :                   (nbits >=  250) ? 28 : (nbits >=   150) ? 40 : 51);
+    2200                 :            :     }
+    2201                 :            : 
+    2202                 :            :     while (1) {
+    2203         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_fill_random(X, n * ciL, f_rng, p_rng));
+    2204                 :            :         /* make sure generated number is at least (nbits-1)+0.5 bits (FIPS 186-4 §B.3.3 steps 4.4, 5.5) */
+    2205         [ #  # ]:          0 :         if (X->p[n-1] < CEIL_MAXUINT_DIV_SQRT2) {
+    2206                 :          0 :             continue;
+    2207                 :            :         }
+    2208                 :            : 
+    2209                 :          0 :         k = n * biL;
+    2210         [ #  # ]:          0 :         if (k > nbits) {
+    2211         [ #  # ]:          0 :             MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(X, k - nbits));
+    2212                 :            :         }
+    2213                 :          0 :         X->p[0] |= 1;
+    2214                 :            : 
+    2215         [ #  # ]:          0 :         if ((flags & MBEDTLS_MPI_GEN_PRIME_FLAG_DH) == 0) {
+    2216                 :          0 :             ret = mbedtls_mpi_is_prime_ext(X, rounds, f_rng, p_rng);
+    2217                 :            : 
+    2218         [ #  # ]:          0 :             if (ret != MBEDTLS_ERR_MPI_NOT_ACCEPTABLE) {
+    2219                 :          0 :                 goto cleanup;
+    2220                 :            :             }
+    2221                 :            :         } else {
+    2222                 :            :             /*
+    2223                 :            :              * A necessary condition for Y and X = 2Y + 1 to be prime
+    2224                 :            :              * is X = 2 mod 3 (which is equivalent to Y = 2 mod 3).
+    2225                 :            :              * Make sure it is satisfied, while keeping X = 3 mod 4
+    2226                 :            :              */
+    2227                 :            : 
+    2228                 :          0 :             X->p[0] |= 2;
+    2229                 :            : 
+    2230         [ #  # ]:          0 :             MBEDTLS_MPI_CHK(mbedtls_mpi_mod_int(&r, X, 3));
+    2231         [ #  # ]:          0 :             if (r == 0) {
+    2232         [ #  # ]:          0 :                 MBEDTLS_MPI_CHK(mbedtls_mpi_add_int(X, X, 8));
+    2233         [ #  # ]:          0 :             } else if (r == 1) {
+    2234         [ #  # ]:          0 :                 MBEDTLS_MPI_CHK(mbedtls_mpi_add_int(X, X, 4));
+    2235                 :            :             }
+    2236                 :            : 
+    2237                 :            :             /* Set Y = (X-1) / 2, which is X / 2 because X is odd */
+    2238         [ #  # ]:          0 :             MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&Y, X));
+    2239         [ #  # ]:          0 :             MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&Y, 1));
+    2240                 :            : 
+    2241                 :            :             while (1) {
+    2242                 :            :                 /*
+    2243                 :            :                  * First, check small factors for X and Y
+    2244                 :            :                  * before doing Miller-Rabin on any of them
+    2245                 :            :                  */
+    2246   [ #  #  #  # ]:          0 :                 if ((ret = mpi_check_small_factors(X)) == 0 &&
+    2247         [ #  # ]:          0 :                     (ret = mpi_check_small_factors(&Y)) == 0 &&
+    2248                 :          0 :                     (ret = mpi_miller_rabin(X, rounds, f_rng, p_rng))
+    2249         [ #  # ]:          0 :                     == 0 &&
+    2250                 :          0 :                     (ret = mpi_miller_rabin(&Y, rounds, f_rng, p_rng))
+    2251                 :            :                     == 0) {
+    2252                 :          0 :                     goto cleanup;
+    2253                 :            :                 }
+    2254                 :            : 
+    2255         [ #  # ]:          0 :                 if (ret != MBEDTLS_ERR_MPI_NOT_ACCEPTABLE) {
+    2256                 :          0 :                     goto cleanup;
+    2257                 :            :                 }
+    2258                 :            : 
+    2259                 :            :                 /*
+    2260                 :            :                  * Next candidates. We want to preserve Y = (X-1) / 2 and
+    2261                 :            :                  * Y = 1 mod 2 and Y = 2 mod 3 (eq X = 3 mod 4 and X = 2 mod 3)
+    2262                 :            :                  * so up Y by 6 and X by 12.
+    2263                 :            :                  */
+    2264         [ #  # ]:          0 :                 MBEDTLS_MPI_CHK(mbedtls_mpi_add_int(X,  X, 12));
+    2265         [ #  # ]:          0 :                 MBEDTLS_MPI_CHK(mbedtls_mpi_add_int(&Y, &Y, 6));
+    2266                 :            :             }
+    2267                 :            :         }
+    2268                 :            :     }
+    2269                 :            : 
+    2270                 :          0 : cleanup:
+    2271                 :            : 
+    2272                 :          0 :     mbedtls_mpi_free(&Y);
+    2273                 :            : 
+    2274                 :          0 :     return ret;
+    2275                 :            : }
+    2276                 :            : 
+    2277                 :            : #endif /* MBEDTLS_GENPRIME */
+    2278                 :            : 
+    2279                 :            : #if defined(MBEDTLS_SELF_TEST)
+    2280                 :            : 
+    2281                 :            : #define GCD_PAIR_COUNT  3
+    2282                 :            : 
+    2283                 :            : static const int gcd_pairs[GCD_PAIR_COUNT][3] =
+    2284                 :            : {
+    2285                 :            :     { 693, 609, 21 },
+    2286                 :            :     { 1764, 868, 28 },
+    2287                 :            :     { 768454923, 542167814, 1 }
+    2288                 :            : };
+    2289                 :            : 
+    2290                 :            : /*
+    2291                 :            :  * Checkup routine
+    2292                 :            :  */
+    2293                 :          0 : int mbedtls_mpi_self_test(int verbose)
+    2294                 :            : {
+    2295                 :            :     int ret, i;
+    2296                 :            :     mbedtls_mpi A, E, N, X, Y, U, V;
+    2297                 :            : 
+    2298                 :          0 :     mbedtls_mpi_init(&A); mbedtls_mpi_init(&E); mbedtls_mpi_init(&N); mbedtls_mpi_init(&X);
+    2299                 :          0 :     mbedtls_mpi_init(&Y); mbedtls_mpi_init(&U); mbedtls_mpi_init(&V);
+    2300                 :            : 
+    2301         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_read_string(&A, 16,
+    2302                 :            :                                             "EFE021C2645FD1DC586E69184AF4A31E" \
+    2303                 :            :                                             "D5F53E93B5F123FA41680867BA110131" \
+    2304                 :            :                                             "944FE7952E2517337780CB0DB80E61AA" \
+    2305                 :            :                                             "E7C8DDC6C5C6AADEB34EB38A2F40D5E6"));
+    2306                 :            : 
+    2307         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_read_string(&E, 16,
+    2308                 :            :                                             "B2E7EFD37075B9F03FF989C7C5051C20" \
+    2309                 :            :                                             "34D2A323810251127E7BF8625A4F49A5" \
+    2310                 :            :                                             "F3E27F4DA8BD59C47D6DAABA4C8127BD" \
+    2311                 :            :                                             "5B5C25763222FEFCCFC38B832366C29E"));
+    2312                 :            : 
+    2313         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_read_string(&N, 16,
+    2314                 :            :                                             "0066A198186C18C10B2F5ED9B522752A" \
+    2315                 :            :                                             "9830B69916E535C8F047518A889A43A5" \
+    2316                 :            :                                             "94B6BED27A168D31D4A52F88925AA8F5"));
+    2317                 :            : 
+    2318         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&X, &A, &N));
+    2319                 :            : 
+    2320         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_read_string(&U, 16,
+    2321                 :            :                                             "602AB7ECA597A3D6B56FF9829A5E8B85" \
+    2322                 :            :                                             "9E857EA95A03512E2BAE7391688D264A" \
+    2323                 :            :                                             "A5663B0341DB9CCFD2C4C5F421FEC814" \
+    2324                 :            :                                             "8001B72E848A38CAE1C65F78E56ABDEF" \
+    2325                 :            :                                             "E12D3C039B8A02D6BE593F0BBBDA56F1" \
+    2326                 :            :                                             "ECF677152EF804370C1A305CAF3B5BF1" \
+    2327                 :            :                                             "30879B56C61DE584A0F53A2447A51E"));
+    2328                 :            : 
+    2329         [ #  # ]:          0 :     if (verbose != 0) {
+    2330                 :          0 :         mbedtls_printf("  MPI test #1 (mul_mpi): ");
+    2331                 :            :     }
+    2332                 :            : 
+    2333         [ #  # ]:          0 :     if (mbedtls_mpi_cmp_mpi(&X, &U) != 0) {
+    2334         [ #  # ]:          0 :         if (verbose != 0) {
+    2335                 :          0 :             mbedtls_printf("failed\n");
+    2336                 :            :         }
+    2337                 :            : 
+    2338                 :          0 :         ret = 1;
+    2339                 :          0 :         goto cleanup;
+    2340                 :            :     }
+    2341                 :            : 
+    2342         [ #  # ]:          0 :     if (verbose != 0) {
+    2343                 :          0 :         mbedtls_printf("passed\n");
+    2344                 :            :     }
+    2345                 :            : 
+    2346         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_div_mpi(&X, &Y, &A, &N));
+    2347                 :            : 
+    2348         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_read_string(&U, 16,
+    2349                 :            :                                             "256567336059E52CAE22925474705F39A94"));
+    2350                 :            : 
+    2351         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_read_string(&V, 16,
+    2352                 :            :                                             "6613F26162223DF488E9CD48CC132C7A" \
+    2353                 :            :                                             "0AC93C701B001B092E4E5B9F73BCD27B" \
+    2354                 :            :                                             "9EE50D0657C77F374E903CDFA4C642"));
+    2355                 :            : 
+    2356         [ #  # ]:          0 :     if (verbose != 0) {
+    2357                 :          0 :         mbedtls_printf("  MPI test #2 (div_mpi): ");
+    2358                 :            :     }
+    2359                 :            : 
+    2360   [ #  #  #  # ]:          0 :     if (mbedtls_mpi_cmp_mpi(&X, &U) != 0 ||
+    2361                 :          0 :         mbedtls_mpi_cmp_mpi(&Y, &V) != 0) {
+    2362         [ #  # ]:          0 :         if (verbose != 0) {
+    2363                 :          0 :             mbedtls_printf("failed\n");
+    2364                 :            :         }
+    2365                 :            : 
+    2366                 :          0 :         ret = 1;
+    2367                 :          0 :         goto cleanup;
+    2368                 :            :     }
+    2369                 :            : 
+    2370         [ #  # ]:          0 :     if (verbose != 0) {
+    2371                 :          0 :         mbedtls_printf("passed\n");
+    2372                 :            :     }
+    2373                 :            : 
+    2374         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_exp_mod(&X, &A, &E, &N, NULL));
+    2375                 :            : 
+    2376         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_read_string(&U, 16,
+    2377                 :            :                                             "36E139AEA55215609D2816998ED020BB" \
+    2378                 :            :                                             "BD96C37890F65171D948E9BC7CBAA4D9" \
+    2379                 :            :                                             "325D24D6A3C12710F10A09FA08AB87"));
+    2380                 :            : 
+    2381         [ #  # ]:          0 :     if (verbose != 0) {
+    2382                 :          0 :         mbedtls_printf("  MPI test #3 (exp_mod): ");
+    2383                 :            :     }
+    2384                 :            : 
+    2385         [ #  # ]:          0 :     if (mbedtls_mpi_cmp_mpi(&X, &U) != 0) {
+    2386         [ #  # ]:          0 :         if (verbose != 0) {
+    2387                 :          0 :             mbedtls_printf("failed\n");
+    2388                 :            :         }
+    2389                 :            : 
+    2390                 :          0 :         ret = 1;
+    2391                 :          0 :         goto cleanup;
+    2392                 :            :     }
+    2393                 :            : 
+    2394         [ #  # ]:          0 :     if (verbose != 0) {
+    2395                 :          0 :         mbedtls_printf("passed\n");
+    2396                 :            :     }
+    2397                 :            : 
+    2398         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_inv_mod(&X, &A, &N));
+    2399                 :            : 
+    2400         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_read_string(&U, 16,
+    2401                 :            :                                             "003A0AAEDD7E784FC07D8F9EC6E3BFD5" \
+    2402                 :            :                                             "C3DBA76456363A10869622EAC2DD84EC" \
+    2403                 :            :                                             "C5B8A74DAC4D09E03B5E0BE779F2DF61"));
+    2404                 :            : 
+    2405         [ #  # ]:          0 :     if (verbose != 0) {
+    2406                 :          0 :         mbedtls_printf("  MPI test #4 (inv_mod): ");
+    2407                 :            :     }
+    2408                 :            : 
+    2409         [ #  # ]:          0 :     if (mbedtls_mpi_cmp_mpi(&X, &U) != 0) {
+    2410         [ #  # ]:          0 :         if (verbose != 0) {
+    2411                 :          0 :             mbedtls_printf("failed\n");
+    2412                 :            :         }
+    2413                 :            : 
+    2414                 :          0 :         ret = 1;
+    2415                 :          0 :         goto cleanup;
+    2416                 :            :     }
+    2417                 :            : 
+    2418         [ #  # ]:          0 :     if (verbose != 0) {
+    2419                 :          0 :         mbedtls_printf("passed\n");
+    2420                 :            :     }
+    2421                 :            : 
+    2422         [ #  # ]:          0 :     if (verbose != 0) {
+    2423                 :          0 :         mbedtls_printf("  MPI test #5 (simple gcd): ");
+    2424                 :            :     }
+    2425                 :            : 
+    2426         [ #  # ]:          0 :     for (i = 0; i < GCD_PAIR_COUNT; i++) {
+    2427         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&X, gcd_pairs[i][0]));
+    2428         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&Y, gcd_pairs[i][1]));
+    2429                 :            : 
+    2430         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_gcd(&A, &X, &Y));
+    2431                 :            : 
+    2432         [ #  # ]:          0 :         if (mbedtls_mpi_cmp_int(&A, gcd_pairs[i][2]) != 0) {
+    2433         [ #  # ]:          0 :             if (verbose != 0) {
+    2434                 :          0 :                 mbedtls_printf("failed at %d\n", i);
+    2435                 :            :             }
+    2436                 :            : 
+    2437                 :          0 :             ret = 1;
+    2438                 :          0 :             goto cleanup;
+    2439                 :            :         }
+    2440                 :            :     }
+    2441                 :            : 
+    2442         [ #  # ]:          0 :     if (verbose != 0) {
+    2443                 :          0 :         mbedtls_printf("passed\n");
+    2444                 :            :     }
+    2445                 :            : 
+    2446                 :          0 : cleanup:
+    2447                 :            : 
+    2448   [ #  #  #  # ]:          0 :     if (ret != 0 && verbose != 0) {
+    2449                 :          0 :         mbedtls_printf("Unexpected error, return code = %08X\n", (unsigned int) ret);
+    2450                 :            :     }
+    2451                 :            : 
+    2452                 :          0 :     mbedtls_mpi_free(&A); mbedtls_mpi_free(&E); mbedtls_mpi_free(&N); mbedtls_mpi_free(&X);
+    2453                 :          0 :     mbedtls_mpi_free(&Y); mbedtls_mpi_free(&U); mbedtls_mpi_free(&V);
+    2454                 :            : 
+    2455         [ #  # ]:          0 :     if (verbose != 0) {
+    2456                 :          0 :         mbedtls_printf("\n");
+    2457                 :            :     }
+    2458                 :            : 
+    2459                 :          0 :     return ret;
+    2460                 :            : }
+    2461                 :            : 
+    2462                 :            : #endif /* MBEDTLS_SELF_TEST */
+    2463                 :            : 
+    2464                 :            : #endif /* MBEDTLS_BIGNUM_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/bignum_core.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/bignum_core.c.func-sort-c.html new file mode 100644 index 00000000000..60bc345d2a4 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/bignum_core.c.func-sort-c.html @@ -0,0 +1,213 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/bignum_core.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - bignum_core.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:24931080.3 %
Date:2024-09-22 08:21:07Functions:283384.8 %
Branches:9213866.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_mpi_core_add_if0
mbedtls_mpi_core_check_zero_ct0
mbedtls_mpi_core_cond_swap0
mbedtls_mpi_core_read_le0
mbedtls_mpi_core_write_le0
mbedtls_mpi_core_get_mont_r2_unsafe377
exp_mod_precompute_window416
mbedtls_mpi_core_exp_mod416
mbedtls_mpi_core_exp_mod_working_limbs416
mbedtls_mpi_core_from_mont_rep416
mbedtls_mpi_core_to_mont_rep443
exp_mod_get_window_size832
mbedtls_mpi_core_montmul_init859
mbedtls_mpi_core_write_be1031
mbedtls_mpi_core_lt_ct1162
mbedtls_mpi_core_random1162
mbedtls_mpi_core_uint_le_mpi1162
mbedtls_mpi_core_fill_random1270
mbedtls_mpi_core_read_be29686
mbedtls_mpi_core_bigendian_to_host30956
mbedtls_mpi_core_ct_uint_table_lookup49982
mbedtls_mpi_core_montmul155964
mpi_bigendian_to_host196424
mbedtls_mpi_core_shift_l2116906
mbedtls_mpi_core_add3756730
mbedtls_mpi_core_sub_int4298254
mbedtls_mpi_core_cond_assign4869638
mbedtls_mpi_core_mul6033544
mbedtls_mpi_core_clz8195840
mbedtls_mpi_core_bitlen8195842
mbedtls_mpi_core_shift_r15084943
mbedtls_mpi_core_sub19694247
mbedtls_mpi_core_mla33826696
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/bignum_core.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/bignum_core.c.func.html new file mode 100644 index 00000000000..a4a3d65df5f --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/bignum_core.c.func.html @@ -0,0 +1,213 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/bignum_core.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - bignum_core.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:24931080.3 %
Date:2024-09-22 08:21:07Functions:283384.8 %
Branches:9213866.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
exp_mod_get_window_size832
exp_mod_precompute_window416
mbedtls_mpi_core_add3756730
mbedtls_mpi_core_add_if0
mbedtls_mpi_core_bigendian_to_host30956
mbedtls_mpi_core_bitlen8195842
mbedtls_mpi_core_check_zero_ct0
mbedtls_mpi_core_clz8195840
mbedtls_mpi_core_cond_assign4869638
mbedtls_mpi_core_cond_swap0
mbedtls_mpi_core_ct_uint_table_lookup49982
mbedtls_mpi_core_exp_mod416
mbedtls_mpi_core_exp_mod_working_limbs416
mbedtls_mpi_core_fill_random1270
mbedtls_mpi_core_from_mont_rep416
mbedtls_mpi_core_get_mont_r2_unsafe377
mbedtls_mpi_core_lt_ct1162
mbedtls_mpi_core_mla33826696
mbedtls_mpi_core_montmul155964
mbedtls_mpi_core_montmul_init859
mbedtls_mpi_core_mul6033544
mbedtls_mpi_core_random1162
mbedtls_mpi_core_read_be29686
mbedtls_mpi_core_read_le0
mbedtls_mpi_core_shift_l2116906
mbedtls_mpi_core_shift_r15084943
mbedtls_mpi_core_sub19694247
mbedtls_mpi_core_sub_int4298254
mbedtls_mpi_core_to_mont_rep443
mbedtls_mpi_core_uint_le_mpi1162
mbedtls_mpi_core_write_be1031
mbedtls_mpi_core_write_le0
mpi_bigendian_to_host196424
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/bignum_core.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/bignum_core.c.gcov.html new file mode 100644 index 00000000000..12ffc605806 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/bignum_core.c.gcov.html @@ -0,0 +1,981 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/bignum_core.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - bignum_core.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:24931080.3 %
Date:2024-09-22 08:21:07Functions:283384.8 %
Branches:9213866.7 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  *  Core bignum functions
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  */
+       7                 :            : 
+       8                 :            : #include "common.h"
+       9                 :            : 
+      10                 :            : #if defined(MBEDTLS_BIGNUM_C)
+      11                 :            : 
+      12                 :            : #include <string.h>
+      13                 :            : 
+      14                 :            : #include "mbedtls/error.h"
+      15                 :            : #include "mbedtls/platform_util.h"
+      16                 :            : #include "constant_time_internal.h"
+      17                 :            : 
+      18                 :            : #include "mbedtls/platform.h"
+      19                 :            : 
+      20                 :            : #include "bignum_core.h"
+      21                 :            : #include "bn_mul.h"
+      22                 :            : #include "constant_time_internal.h"
+      23                 :            : 
+      24                 :    8195840 : size_t mbedtls_mpi_core_clz(mbedtls_mpi_uint a)
+      25                 :            : {
+      26                 :            : #if defined(__has_builtin)
+      27                 :            : #if (MBEDTLS_MPI_UINT_MAX == UINT_MAX) && __has_builtin(__builtin_clz)
+      28                 :            :     #define core_clz __builtin_clz
+      29                 :            : #elif (MBEDTLS_MPI_UINT_MAX == ULONG_MAX) && __has_builtin(__builtin_clzl)
+      30                 :            :     #define core_clz __builtin_clzl
+      31                 :            : #elif (MBEDTLS_MPI_UINT_MAX == ULLONG_MAX) && __has_builtin(__builtin_clzll)
+      32                 :            :     #define core_clz __builtin_clzll
+      33                 :            : #endif
+      34                 :            : #endif
+      35                 :            : #if defined(core_clz)
+      36                 :    8195840 :     return (size_t) core_clz(a);
+      37                 :            : #else
+      38                 :            :     size_t j;
+      39                 :            :     mbedtls_mpi_uint mask = (mbedtls_mpi_uint) 1 << (biL - 1);
+      40                 :            : 
+      41                 :            :     for (j = 0; j < biL; j++) {
+      42                 :            :         if (a & mask) {
+      43                 :            :             break;
+      44                 :            :         }
+      45                 :            : 
+      46                 :            :         mask >>= 1;
+      47                 :            :     }
+      48                 :            : 
+      49                 :            :     return j;
+      50                 :            : #endif
+      51                 :            : }
+      52                 :            : 
+      53                 :    8195842 : size_t mbedtls_mpi_core_bitlen(const mbedtls_mpi_uint *A, size_t A_limbs)
+      54                 :            : {
+      55                 :            :     int i;
+      56                 :            :     size_t j;
+      57                 :            : 
+      58         [ +  + ]:   25913978 :     for (i = ((int) A_limbs) - 1; i >= 0; i--) {
+      59         [ +  + ]:   25913976 :         if (A[i] != 0) {
+      60                 :    8195840 :             j = biL - mbedtls_mpi_core_clz(A[i]);
+      61                 :    8195840 :             return (i * biL) + j;
+      62                 :            :         }
+      63                 :            :     }
+      64                 :            : 
+      65                 :          2 :     return 0;
+      66                 :            : }
+      67                 :            : 
+      68                 :     196424 : static mbedtls_mpi_uint mpi_bigendian_to_host(mbedtls_mpi_uint a)
+      69                 :            : {
+      70                 :            :     if (MBEDTLS_IS_BIG_ENDIAN) {
+      71                 :            :         /* Nothing to do on bigendian systems. */
+      72                 :            :         return a;
+      73                 :            :     } else {
+      74                 :            : #if defined(MBEDTLS_HAVE_INT32)
+      75                 :            :         return (mbedtls_mpi_uint) MBEDTLS_BSWAP32(a);
+      76                 :            : #elif defined(MBEDTLS_HAVE_INT64)
+      77                 :     196424 :         return (mbedtls_mpi_uint) MBEDTLS_BSWAP64(a);
+      78                 :            : #endif
+      79                 :            :     }
+      80                 :            : }
+      81                 :            : 
+      82                 :      30956 : void mbedtls_mpi_core_bigendian_to_host(mbedtls_mpi_uint *A,
+      83                 :            :                                         size_t A_limbs)
+      84                 :            : {
+      85                 :            :     mbedtls_mpi_uint *cur_limb_left;
+      86                 :            :     mbedtls_mpi_uint *cur_limb_right;
+      87         [ -  + ]:      30956 :     if (A_limbs == 0) {
+      88                 :          0 :         return;
+      89                 :            :     }
+      90                 :            : 
+      91                 :            :     /*
+      92                 :            :      * Traverse limbs and
+      93                 :            :      * - adapt byte-order in each limb
+      94                 :            :      * - swap the limbs themselves.
+      95                 :            :      * For that, simultaneously traverse the limbs from left to right
+      96                 :            :      * and from right to left, as long as the left index is not bigger
+      97                 :            :      * than the right index (it's not a problem if limbs is odd and the
+      98                 :            :      * indices coincide in the last iteration).
+      99                 :            :      */
+     100                 :      30956 :     for (cur_limb_left = A, cur_limb_right = A + (A_limbs - 1);
+     101         [ +  + ]:     129168 :          cur_limb_left <= cur_limb_right;
+     102                 :      98212 :          cur_limb_left++, cur_limb_right--) {
+     103                 :            :         mbedtls_mpi_uint tmp;
+     104                 :            :         /* Note that if cur_limb_left == cur_limb_right,
+     105                 :            :          * this code effectively swaps the bytes only once. */
+     106                 :      98212 :         tmp             = mpi_bigendian_to_host(*cur_limb_left);
+     107                 :      98212 :         *cur_limb_left  = mpi_bigendian_to_host(*cur_limb_right);
+     108                 :      98212 :         *cur_limb_right = tmp;
+     109                 :            :     }
+     110                 :            : }
+     111                 :            : 
+     112                 :            : /* Whether min <= A, in constant time.
+     113                 :            :  * A_limbs must be at least 1. */
+     114                 :       1162 : mbedtls_ct_condition_t mbedtls_mpi_core_uint_le_mpi(mbedtls_mpi_uint min,
+     115                 :            :                                                     const mbedtls_mpi_uint *A,
+     116                 :            :                                                     size_t A_limbs)
+     117                 :            : {
+     118                 :            :     /* min <= least significant limb? */
+     119                 :       1162 :     mbedtls_ct_condition_t min_le_lsl = mbedtls_ct_uint_ge(A[0], min);
+     120                 :            : 
+     121                 :            :     /* limbs other than the least significant one are all zero? */
+     122                 :       1162 :     mbedtls_ct_condition_t msll_mask = MBEDTLS_CT_FALSE;
+     123         [ +  + ]:       4704 :     for (size_t i = 1; i < A_limbs; i++) {
+     124                 :       3542 :         msll_mask = mbedtls_ct_bool_or(msll_mask, mbedtls_ct_bool(A[i]));
+     125                 :            :     }
+     126                 :            : 
+     127                 :            :     /* min <= A iff the lowest limb of A is >= min or the other limbs
+     128                 :            :      * are not all zero. */
+     129                 :       1162 :     return mbedtls_ct_bool_or(msll_mask, min_le_lsl);
+     130                 :            : }
+     131                 :            : 
+     132                 :       1162 : mbedtls_ct_condition_t mbedtls_mpi_core_lt_ct(const mbedtls_mpi_uint *A,
+     133                 :            :                                               const mbedtls_mpi_uint *B,
+     134                 :            :                                               size_t limbs)
+     135                 :            : {
+     136                 :       1162 :     mbedtls_ct_condition_t ret = MBEDTLS_CT_FALSE, cond = MBEDTLS_CT_FALSE, done = MBEDTLS_CT_FALSE;
+     137                 :            : 
+     138         [ +  + ]:       5866 :     for (size_t i = limbs; i > 0; i--) {
+     139                 :            :         /*
+     140                 :            :          * If B[i - 1] < A[i - 1] then A < B is false and the result must
+     141                 :            :          * remain 0.
+     142                 :            :          *
+     143                 :            :          * Again even if we can make a decision, we just mark the result and
+     144                 :            :          * the fact that we are done and continue looping.
+     145                 :            :          */
+     146                 :       4704 :         cond = mbedtls_ct_uint_lt(B[i - 1], A[i - 1]);
+     147                 :       4704 :         done = mbedtls_ct_bool_or(done, cond);
+     148                 :            : 
+     149                 :            :         /*
+     150                 :            :          * If A[i - 1] < B[i - 1] then A < B is true.
+     151                 :            :          *
+     152                 :            :          * Again even if we can make a decision, we just mark the result and
+     153                 :            :          * the fact that we are done and continue looping.
+     154                 :            :          */
+     155                 :       4704 :         cond = mbedtls_ct_uint_lt(A[i - 1], B[i - 1]);
+     156                 :       4704 :         ret  = mbedtls_ct_bool_or(ret, mbedtls_ct_bool_and(cond, mbedtls_ct_bool_not(done)));
+     157                 :       4704 :         done = mbedtls_ct_bool_or(done, cond);
+     158                 :            :     }
+     159                 :            : 
+     160                 :            :     /*
+     161                 :            :      * If all the limbs were equal, then the numbers are equal, A < B is false
+     162                 :            :      * and leaving the result 0 is correct.
+     163                 :            :      */
+     164                 :            : 
+     165                 :       1162 :     return ret;
+     166                 :            : }
+     167                 :            : 
+     168                 :    4869638 : void mbedtls_mpi_core_cond_assign(mbedtls_mpi_uint *X,
+     169                 :            :                                   const mbedtls_mpi_uint *A,
+     170                 :            :                                   size_t limbs,
+     171                 :            :                                   mbedtls_ct_condition_t assign)
+     172                 :            : {
+     173         [ -  + ]:    4869638 :     if (X == A) {
+     174                 :          0 :         return;
+     175                 :            :     }
+     176                 :            : 
+     177                 :            :     /* This function is very performance-sensitive for RSA. For this reason
+     178                 :            :      * we have the loop below, instead of calling mbedtls_ct_memcpy_if
+     179                 :            :      * (this is more optimal since here we don't have to handle the case where
+     180                 :            :      * we copy awkwardly sized data).
+     181                 :            :      */
+     182         [ +  + ]:   29879518 :     for (size_t i = 0; i < limbs; i++) {
+     183                 :   25009880 :         X[i] = mbedtls_ct_mpi_uint_if(assign, A[i], X[i]);
+     184                 :            :     }
+     185                 :            : }
+     186                 :            : 
+     187                 :          0 : void mbedtls_mpi_core_cond_swap(mbedtls_mpi_uint *X,
+     188                 :            :                                 mbedtls_mpi_uint *Y,
+     189                 :            :                                 size_t limbs,
+     190                 :            :                                 mbedtls_ct_condition_t swap)
+     191                 :            : {
+     192         [ #  # ]:          0 :     if (X == Y) {
+     193                 :          0 :         return;
+     194                 :            :     }
+     195                 :            : 
+     196         [ #  # ]:          0 :     for (size_t i = 0; i < limbs; i++) {
+     197                 :          0 :         mbedtls_mpi_uint tmp = X[i];
+     198                 :          0 :         X[i] = mbedtls_ct_mpi_uint_if(swap, Y[i], X[i]);
+     199                 :          0 :         Y[i] = mbedtls_ct_mpi_uint_if(swap, tmp, Y[i]);
+     200                 :            :     }
+     201                 :            : }
+     202                 :            : 
+     203                 :          0 : int mbedtls_mpi_core_read_le(mbedtls_mpi_uint *X,
+     204                 :            :                              size_t X_limbs,
+     205                 :            :                              const unsigned char *input,
+     206                 :            :                              size_t input_length)
+     207                 :            : {
+     208                 :          0 :     const size_t limbs = CHARS_TO_LIMBS(input_length);
+     209                 :            : 
+     210         [ #  # ]:          0 :     if (X_limbs < limbs) {
+     211                 :          0 :         return MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL;
+     212                 :            :     }
+     213                 :            : 
+     214         [ #  # ]:          0 :     if (X != NULL) {
+     215                 :          0 :         memset(X, 0, X_limbs * ciL);
+     216                 :            : 
+     217         [ #  # ]:          0 :         for (size_t i = 0; i < input_length; i++) {
+     218                 :          0 :             size_t offset = ((i % ciL) << 3);
+     219                 :          0 :             X[i / ciL] |= ((mbedtls_mpi_uint) input[i]) << offset;
+     220                 :            :         }
+     221                 :            :     }
+     222                 :            : 
+     223                 :          0 :     return 0;
+     224                 :            : }
+     225                 :            : 
+     226                 :      29686 : int mbedtls_mpi_core_read_be(mbedtls_mpi_uint *X,
+     227                 :            :                              size_t X_limbs,
+     228                 :            :                              const unsigned char *input,
+     229                 :            :                              size_t input_length)
+     230                 :            : {
+     231                 :      29686 :     const size_t limbs = CHARS_TO_LIMBS(input_length);
+     232                 :            : 
+     233         [ -  + ]:      29686 :     if (X_limbs < limbs) {
+     234                 :          0 :         return MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL;
+     235                 :            :     }
+     236                 :            : 
+     237                 :            :     /* If X_limbs is 0, input_length must also be 0 (from previous test).
+     238                 :            :      * Nothing to do. */
+     239         [ -  + ]:      29686 :     if (X_limbs == 0) {
+     240                 :          0 :         return 0;
+     241                 :            :     }
+     242                 :            : 
+     243                 :      29686 :     memset(X, 0, X_limbs * ciL);
+     244                 :            : 
+     245                 :            :     /* memcpy() with (NULL, 0) is undefined behaviour */
+     246         [ +  - ]:      29686 :     if (input_length != 0) {
+     247                 :      29686 :         size_t overhead = (X_limbs * ciL) - input_length;
+     248                 :      29686 :         unsigned char *Xp = (unsigned char *) X;
+     249                 :      29686 :         memcpy(Xp + overhead, input, input_length);
+     250                 :            :     }
+     251                 :            : 
+     252                 :      29686 :     mbedtls_mpi_core_bigendian_to_host(X, X_limbs);
+     253                 :            : 
+     254                 :      29686 :     return 0;
+     255                 :            : }
+     256                 :            : 
+     257                 :          0 : int mbedtls_mpi_core_write_le(const mbedtls_mpi_uint *A,
+     258                 :            :                               size_t A_limbs,
+     259                 :            :                               unsigned char *output,
+     260                 :            :                               size_t output_length)
+     261                 :            : {
+     262                 :          0 :     size_t stored_bytes = A_limbs * ciL;
+     263                 :            :     size_t bytes_to_copy;
+     264                 :            : 
+     265         [ #  # ]:          0 :     if (stored_bytes < output_length) {
+     266                 :          0 :         bytes_to_copy = stored_bytes;
+     267                 :            :     } else {
+     268                 :          0 :         bytes_to_copy = output_length;
+     269                 :            : 
+     270                 :            :         /* The output buffer is smaller than the allocated size of A.
+     271                 :            :          * However A may fit if its leading bytes are zero. */
+     272         [ #  # ]:          0 :         for (size_t i = bytes_to_copy; i < stored_bytes; i++) {
+     273         [ #  # ]:          0 :             if (GET_BYTE(A, i) != 0) {
+     274                 :          0 :                 return MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL;
+     275                 :            :             }
+     276                 :            :         }
+     277                 :            :     }
+     278                 :            : 
+     279         [ #  # ]:          0 :     for (size_t i = 0; i < bytes_to_copy; i++) {
+     280                 :          0 :         output[i] = GET_BYTE(A, i);
+     281                 :            :     }
+     282                 :            : 
+     283         [ #  # ]:          0 :     if (stored_bytes < output_length) {
+     284                 :            :         /* Write trailing 0 bytes */
+     285                 :          0 :         memset(output + stored_bytes, 0, output_length - stored_bytes);
+     286                 :            :     }
+     287                 :            : 
+     288                 :          0 :     return 0;
+     289                 :            : }
+     290                 :            : 
+     291                 :       1031 : int mbedtls_mpi_core_write_be(const mbedtls_mpi_uint *X,
+     292                 :            :                               size_t X_limbs,
+     293                 :            :                               unsigned char *output,
+     294                 :            :                               size_t output_length)
+     295                 :            : {
+     296                 :            :     size_t stored_bytes;
+     297                 :            :     size_t bytes_to_copy;
+     298                 :            :     unsigned char *p;
+     299                 :            : 
+     300                 :       1031 :     stored_bytes = X_limbs * ciL;
+     301                 :            : 
+     302         [ -  + ]:       1031 :     if (stored_bytes < output_length) {
+     303                 :            :         /* There is enough space in the output buffer. Write initial
+     304                 :            :          * null bytes and record the position at which to start
+     305                 :            :          * writing the significant bytes. In this case, the execution
+     306                 :            :          * trace of this function does not depend on the value of the
+     307                 :            :          * number. */
+     308                 :          0 :         bytes_to_copy = stored_bytes;
+     309                 :          0 :         p = output + output_length - stored_bytes;
+     310                 :          0 :         memset(output, 0, output_length - stored_bytes);
+     311                 :            :     } else {
+     312                 :            :         /* The output buffer is smaller than the allocated size of X.
+     313                 :            :          * However X may fit if its leading bytes are zero. */
+     314                 :       1031 :         bytes_to_copy = output_length;
+     315                 :       1031 :         p = output;
+     316         [ +  + ]:      35586 :         for (size_t i = bytes_to_copy; i < stored_bytes; i++) {
+     317         [ -  + ]:      34555 :             if (GET_BYTE(X, i) != 0) {
+     318                 :          0 :                 return MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL;
+     319                 :            :             }
+     320                 :            :         }
+     321                 :            :     }
+     322                 :            : 
+     323         [ +  + ]:     169412 :     for (size_t i = 0; i < bytes_to_copy; i++) {
+     324                 :     168381 :         p[bytes_to_copy - i - 1] = GET_BYTE(X, i);
+     325                 :            :     }
+     326                 :            : 
+     327                 :       1031 :     return 0;
+     328                 :            : }
+     329                 :            : 
+     330                 :   15084943 : void mbedtls_mpi_core_shift_r(mbedtls_mpi_uint *X, size_t limbs,
+     331                 :            :                               size_t count)
+     332                 :            : {
+     333                 :            :     size_t i, v0, v1;
+     334                 :   15084943 :     mbedtls_mpi_uint r0 = 0, r1;
+     335                 :            : 
+     336                 :   15084943 :     v0 = count /  biL;
+     337                 :   15084943 :     v1 = count & (biL - 1);
+     338                 :            : 
+     339   [ +  -  -  +  :   15084943 :     if (v0 > limbs || (v0 == limbs && v1 > 0)) {
+                   -  - ]
+     340                 :          0 :         memset(X, 0, limbs * ciL);
+     341                 :          0 :         return;
+     342                 :            :     }
+     343                 :            : 
+     344                 :            :     /*
+     345                 :            :      * shift by count / limb_size
+     346                 :            :      */
+     347         [ +  + ]:   15084943 :     if (v0 > 0) {
+     348         [ +  + ]:      42270 :         for (i = 0; i < limbs - v0; i++) {
+     349                 :      38659 :             X[i] = X[i + v0];
+     350                 :            :         }
+     351                 :            : 
+     352         [ +  + ]:      40269 :         for (; i < limbs; i++) {
+     353                 :      36658 :             X[i] = 0;
+     354                 :            :         }
+     355                 :            :     }
+     356                 :            : 
+     357                 :            :     /*
+     358                 :            :      * shift by count % limb_size
+     359                 :            :      */
+     360         [ +  + ]:   15084943 :     if (v1 > 0) {
+     361         [ +  + ]:   76071753 :         for (i = limbs; i > 0; i--) {
+     362                 :   63515472 :             r1 = X[i - 1] << (biL - v1);
+     363                 :   63515472 :             X[i - 1] >>= v1;
+     364                 :   63515472 :             X[i - 1] |= r0;
+     365                 :   63515472 :             r0 = r1;
+     366                 :            :         }
+     367                 :            :     }
+     368                 :            : }
+     369                 :            : 
+     370                 :    2116906 : void mbedtls_mpi_core_shift_l(mbedtls_mpi_uint *X, size_t limbs,
+     371                 :            :                               size_t count)
+     372                 :            : {
+     373                 :            :     size_t i, v0, v1;
+     374                 :    2116906 :     mbedtls_mpi_uint r0 = 0, r1;
+     375                 :            : 
+     376                 :    2116906 :     v0 = count / (biL);
+     377                 :    2116906 :     v1 = count & (biL - 1);
+     378                 :            : 
+     379                 :            :     /*
+     380                 :            :      * shift by count / limb_size
+     381                 :            :      */
+     382         [ +  + ]:    2116906 :     if (v0 > 0) {
+     383         [ +  + ]:    2017391 :         for (i = limbs; i > v0; i--) {
+     384                 :    1980356 :             X[i - 1] = X[i - v0 - 1];
+     385                 :            :         }
+     386                 :            : 
+     387         [ +  + ]:     746056 :         for (; i > 0; i--) {
+     388                 :     709021 :             X[i - 1] = 0;
+     389                 :            :         }
+     390                 :            :     }
+     391                 :            : 
+     392                 :            :     /*
+     393                 :            :      * shift by count % limb_size
+     394                 :            :      */
+     395         [ +  + ]:    2116906 :     if (v1 > 0) {
+     396         [ +  + ]:   20720614 :         for (i = v0; i < limbs; i++) {
+     397                 :   18653452 :             r1 = X[i] >> (biL - v1);
+     398                 :   18653452 :             X[i] <<= v1;
+     399                 :   18653452 :             X[i] |= r0;
+     400                 :   18653452 :             r0 = r1;
+     401                 :            :         }
+     402                 :            :     }
+     403                 :    2116906 : }
+     404                 :            : 
+     405                 :    3756730 : mbedtls_mpi_uint mbedtls_mpi_core_add(mbedtls_mpi_uint *X,
+     406                 :            :                                       const mbedtls_mpi_uint *A,
+     407                 :            :                                       const mbedtls_mpi_uint *B,
+     408                 :            :                                       size_t limbs)
+     409                 :            : {
+     410                 :    3756730 :     mbedtls_mpi_uint c = 0;
+     411                 :            : 
+     412         [ +  + ]:   20940184 :     for (size_t i = 0; i < limbs; i++) {
+     413                 :   17183454 :         mbedtls_mpi_uint t = c + A[i];
+     414                 :   17183454 :         c = (t < A[i]);
+     415                 :   17183454 :         t += B[i];
+     416                 :   17183454 :         c += (t < B[i]);
+     417                 :   17183454 :         X[i] = t;
+     418                 :            :     }
+     419                 :            : 
+     420                 :    3756730 :     return c;
+     421                 :            : }
+     422                 :            : 
+     423                 :          0 : mbedtls_mpi_uint mbedtls_mpi_core_add_if(mbedtls_mpi_uint *X,
+     424                 :            :                                          const mbedtls_mpi_uint *A,
+     425                 :            :                                          size_t limbs,
+     426                 :            :                                          unsigned cond)
+     427                 :            : {
+     428                 :          0 :     mbedtls_mpi_uint c = 0;
+     429                 :            : 
+     430                 :          0 :     mbedtls_ct_condition_t do_add = mbedtls_ct_bool(cond);
+     431                 :            : 
+     432         [ #  # ]:          0 :     for (size_t i = 0; i < limbs; i++) {
+     433                 :          0 :         mbedtls_mpi_uint add = mbedtls_ct_mpi_uint_if_else_0(do_add, A[i]);
+     434                 :          0 :         mbedtls_mpi_uint t = c + X[i];
+     435                 :          0 :         c = (t < X[i]);
+     436                 :          0 :         t += add;
+     437                 :          0 :         c += (t < add);
+     438                 :          0 :         X[i] = t;
+     439                 :            :     }
+     440                 :            : 
+     441                 :          0 :     return c;
+     442                 :            : }
+     443                 :            : 
+     444                 :   19694247 : mbedtls_mpi_uint mbedtls_mpi_core_sub(mbedtls_mpi_uint *X,
+     445                 :            :                                       const mbedtls_mpi_uint *A,
+     446                 :            :                                       const mbedtls_mpi_uint *B,
+     447                 :            :                                       size_t limbs)
+     448                 :            : {
+     449                 :   19694247 :     mbedtls_mpi_uint c = 0;
+     450                 :            : 
+     451         [ +  + ]:  102411105 :     for (size_t i = 0; i < limbs; i++) {
+     452                 :   82716858 :         mbedtls_mpi_uint z = (A[i] < c);
+     453                 :   82716858 :         mbedtls_mpi_uint t = A[i] - c;
+     454                 :   82716858 :         c = (t < B[i]) + z;
+     455                 :   82716858 :         X[i] = t - B[i];
+     456                 :            :     }
+     457                 :            : 
+     458                 :   19694247 :     return c;
+     459                 :            : }
+     460                 :            : 
+     461                 :   33826696 : mbedtls_mpi_uint mbedtls_mpi_core_mla(mbedtls_mpi_uint *d, size_t d_len,
+     462                 :            :                                       const mbedtls_mpi_uint *s, size_t s_len,
+     463                 :            :                                       mbedtls_mpi_uint b)
+     464                 :            : {
+     465                 :   33826696 :     mbedtls_mpi_uint c = 0; /* carry */
+     466                 :            :     /*
+     467                 :            :      * It is a documented precondition of this function that d_len >= s_len.
+     468                 :            :      * If that's not the case, we swap these round: this turns what would be
+     469                 :            :      * a buffer overflow into an incorrect result.
+     470                 :            :      */
+     471         [ -  + ]:   33826696 :     if (d_len < s_len) {
+     472                 :          0 :         s_len = d_len;
+     473                 :            :     }
+     474                 :   33826696 :     size_t excess_len = d_len - s_len;
+     475                 :   33826696 :     size_t steps_x8 = s_len / 8;
+     476                 :   33826696 :     size_t steps_x1 = s_len & 7;
+     477                 :            : 
+     478         [ +  + ]:   80792922 :     while (steps_x8--) {
+     479                 :   46966226 :         MULADDC_X8_INIT
+     480                 :            :         MULADDC_X8_CORE
+     481                 :            :             MULADDC_X8_STOP
+     482                 :            :     }
+     483                 :            : 
+     484         [ +  + ]:  136120569 :     while (steps_x1--) {
+     485                 :  102293873 :         MULADDC_X1_INIT
+     486                 :            :         MULADDC_X1_CORE
+     487                 :            :             MULADDC_X1_STOP
+     488                 :            :     }
+     489                 :            : 
+     490         [ +  + ]:   84410872 :     while (excess_len--) {
+     491                 :   50584176 :         *d += c;
+     492                 :   50584176 :         c = (*d < c);
+     493                 :   50584176 :         d++;
+     494                 :            :     }
+     495                 :            : 
+     496                 :   33826696 :     return c;
+     497                 :            : }
+     498                 :            : 
+     499                 :    6033544 : void mbedtls_mpi_core_mul(mbedtls_mpi_uint *X,
+     500                 :            :                           const mbedtls_mpi_uint *A, size_t A_limbs,
+     501                 :            :                           const mbedtls_mpi_uint *B, size_t B_limbs)
+     502                 :            : {
+     503                 :    6033544 :     memset(X, 0, (A_limbs + B_limbs) * ciL);
+     504                 :            : 
+     505         [ +  + ]:   30111208 :     for (size_t i = 0; i < B_limbs; i++) {
+     506                 :   24077664 :         (void) mbedtls_mpi_core_mla(X + i, A_limbs + 1, A, A_limbs, B[i]);
+     507                 :            :     }
+     508                 :    6033544 : }
+     509                 :            : 
+     510                 :            : /*
+     511                 :            :  * Fast Montgomery initialization (thanks to Tom St Denis).
+     512                 :            :  */
+     513                 :        859 : mbedtls_mpi_uint mbedtls_mpi_core_montmul_init(const mbedtls_mpi_uint *N)
+     514                 :            : {
+     515                 :        859 :     mbedtls_mpi_uint x = N[0];
+     516                 :            : 
+     517                 :        859 :     x += ((N[0] + 2) & 4) << 1;
+     518                 :            : 
+     519         [ +  + ]:       4295 :     for (unsigned int i = biL; i >= 8; i /= 2) {
+     520                 :       3436 :         x *= (2 - (N[0] * x));
+     521                 :            :     }
+     522                 :            : 
+     523                 :        859 :     return ~x + 1;
+     524                 :            : }
+     525                 :            : 
+     526                 :     155964 : void mbedtls_mpi_core_montmul(mbedtls_mpi_uint *X,
+     527                 :            :                               const mbedtls_mpi_uint *A,
+     528                 :            :                               const mbedtls_mpi_uint *B,
+     529                 :            :                               size_t B_limbs,
+     530                 :            :                               const mbedtls_mpi_uint *N,
+     531                 :            :                               size_t AN_limbs,
+     532                 :            :                               mbedtls_mpi_uint mm,
+     533                 :            :                               mbedtls_mpi_uint *T)
+     534                 :            : {
+     535                 :     155964 :     memset(T, 0, (2 * AN_limbs + 1) * ciL);
+     536                 :            : 
+     537         [ +  + ]:    4747843 :     for (size_t i = 0; i < AN_limbs; i++) {
+     538                 :            :         /* T = (T + u0*B + u1*N) / 2^biL */
+     539                 :    4591879 :         mbedtls_mpi_uint u0 = A[i];
+     540                 :    4591879 :         mbedtls_mpi_uint u1 = (T[0] + u0 * B[0]) * mm;
+     541                 :            : 
+     542                 :    4591879 :         (void) mbedtls_mpi_core_mla(T, AN_limbs + 2, B, B_limbs, u0);
+     543                 :    4591879 :         (void) mbedtls_mpi_core_mla(T, AN_limbs + 2, N, AN_limbs, u1);
+     544                 :            : 
+     545                 :    4591879 :         T++;
+     546                 :            :     }
+     547                 :            : 
+     548                 :            :     /*
+     549                 :            :      * The result we want is (T >= N) ? T - N : T.
+     550                 :            :      *
+     551                 :            :      * For better constant-time properties in this function, we always do the
+     552                 :            :      * subtraction, with the result in X.
+     553                 :            :      *
+     554                 :            :      * We also look to see if there was any carry in the final additions in the
+     555                 :            :      * loop above.
+     556                 :            :      */
+     557                 :            : 
+     558                 :     155964 :     mbedtls_mpi_uint carry  = T[AN_limbs];
+     559                 :     155964 :     mbedtls_mpi_uint borrow = mbedtls_mpi_core_sub(X, T, N, AN_limbs);
+     560                 :            : 
+     561                 :            :     /*
+     562                 :            :      * Using R as the Montgomery radix (auxiliary modulus) i.e. 2^(biL*AN_limbs):
+     563                 :            :      *
+     564                 :            :      * T can be in one of 3 ranges:
+     565                 :            :      *
+     566                 :            :      * 1) T < N      : (carry, borrow) = (0, 1): we want T
+     567                 :            :      * 2) N <= T < R : (carry, borrow) = (0, 0): we want X
+     568                 :            :      * 3) T >= R     : (carry, borrow) = (1, 1): we want X
+     569                 :            :      *
+     570                 :            :      * and (carry, borrow) = (1, 0) can't happen.
+     571                 :            :      *
+     572                 :            :      * So the correct return value is already in X if (carry ^ borrow) = 0,
+     573                 :            :      * but is in (the lower AN_limbs limbs of) T if (carry ^ borrow) = 1.
+     574                 :            :      */
+     575                 :     155964 :     mbedtls_ct_memcpy_if(mbedtls_ct_bool(carry ^ borrow),
+     576                 :            :                          (unsigned char *) X,
+     577                 :            :                          (unsigned char *) T,
+     578                 :            :                          NULL,
+     579                 :            :                          AN_limbs * sizeof(mbedtls_mpi_uint));
+     580                 :     155964 : }
+     581                 :            : 
+     582                 :        377 : int mbedtls_mpi_core_get_mont_r2_unsafe(mbedtls_mpi *X,
+     583                 :            :                                         const mbedtls_mpi *N)
+     584                 :            : {
+     585                 :        377 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     586                 :            : 
+     587         [ -  + ]:        377 :     MBEDTLS_MPI_CHK(mbedtls_mpi_lset(X, 1));
+     588         [ -  + ]:        377 :     MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(X, N->n * 2 * biL));
+     589         [ -  + ]:        377 :     MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(X, X, N));
+     590         [ +  - ]:        377 :     MBEDTLS_MPI_CHK(mbedtls_mpi_shrink(X, N->n));
+     591                 :            : 
+     592                 :        377 : cleanup:
+     593                 :        377 :     return ret;
+     594                 :            : }
+     595                 :            : 
+     596                 :            : MBEDTLS_STATIC_TESTABLE
+     597                 :      49982 : void mbedtls_mpi_core_ct_uint_table_lookup(mbedtls_mpi_uint *dest,
+     598                 :            :                                            const mbedtls_mpi_uint *table,
+     599                 :            :                                            size_t limbs,
+     600                 :            :                                            size_t count,
+     601                 :            :                                            size_t index)
+     602                 :            : {
+     603         [ +  + ]:     313134 :     for (size_t i = 0; i < count; i++, table += limbs) {
+     604                 :     263152 :         mbedtls_ct_condition_t assign = mbedtls_ct_uint_eq(i, index);
+     605                 :     263152 :         mbedtls_mpi_core_cond_assign(dest, table, limbs, assign);
+     606                 :            :     }
+     607                 :      49982 : }
+     608                 :            : 
+     609                 :            : /* Fill X with n_bytes random bytes.
+     610                 :            :  * X must already have room for those bytes.
+     611                 :            :  * The ordering of the bytes returned from the RNG is suitable for
+     612                 :            :  * deterministic ECDSA (see RFC 6979 §3.3 and the specification of
+     613                 :            :  * mbedtls_mpi_core_random()).
+     614                 :            :  */
+     615                 :       1270 : int mbedtls_mpi_core_fill_random(
+     616                 :            :     mbedtls_mpi_uint *X, size_t X_limbs,
+     617                 :            :     size_t n_bytes,
+     618                 :            :     int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
+     619                 :            : {
+     620                 :       1270 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     621                 :       1270 :     const size_t limbs = CHARS_TO_LIMBS(n_bytes);
+     622                 :       1270 :     const size_t overhead = (limbs * ciL) - n_bytes;
+     623                 :            : 
+     624         [ -  + ]:       1270 :     if (X_limbs < limbs) {
+     625                 :          0 :         return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
+     626                 :            :     }
+     627                 :            : 
+     628                 :       1270 :     memset(X, 0, overhead);
+     629                 :       1270 :     memset((unsigned char *) X + limbs * ciL, 0, (X_limbs - limbs) * ciL);
+     630         [ -  + ]:       1270 :     MBEDTLS_MPI_CHK(f_rng(p_rng, (unsigned char *) X + overhead, n_bytes));
+     631                 :       1270 :     mbedtls_mpi_core_bigendian_to_host(X, limbs);
+     632                 :            : 
+     633                 :       1270 : cleanup:
+     634                 :       1270 :     return ret;
+     635                 :            : }
+     636                 :            : 
+     637                 :       1162 : int mbedtls_mpi_core_random(mbedtls_mpi_uint *X,
+     638                 :            :                             mbedtls_mpi_uint min,
+     639                 :            :                             const mbedtls_mpi_uint *N,
+     640                 :            :                             size_t limbs,
+     641                 :            :                             int (*f_rng)(void *, unsigned char *, size_t),
+     642                 :            :                             void *p_rng)
+     643                 :            : {
+     644                 :       1162 :     mbedtls_ct_condition_t ge_lower = MBEDTLS_CT_TRUE, lt_upper = MBEDTLS_CT_FALSE;
+     645                 :       1162 :     size_t n_bits = mbedtls_mpi_core_bitlen(N, limbs);
+     646                 :       1162 :     size_t n_bytes = (n_bits + 7) / 8;
+     647                 :       1162 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     648                 :            : 
+     649                 :            :     /*
+     650                 :            :      * When min == 0, each try has at worst a probability 1/2 of failing
+     651                 :            :      * (the msb has a probability 1/2 of being 0, and then the result will
+     652                 :            :      * be < N), so after 30 tries failure probability is a most 2**(-30).
+     653                 :            :      *
+     654                 :            :      * When N is just below a power of 2, as is the case when generating
+     655                 :            :      * a random scalar on most elliptic curves, 1 try is enough with
+     656                 :            :      * overwhelming probability. When N is just above a power of 2,
+     657                 :            :      * as when generating a random scalar on secp224k1, each try has
+     658                 :            :      * a probability of failing that is almost 1/2.
+     659                 :            :      *
+     660                 :            :      * The probabilities are almost the same if min is nonzero but negligible
+     661                 :            :      * compared to N. This is always the case when N is crypto-sized, but
+     662                 :            :      * it's convenient to support small N for testing purposes. When N
+     663                 :            :      * is small, use a higher repeat count, otherwise the probability of
+     664                 :            :      * failure is macroscopic.
+     665                 :            :      */
+     666         [ +  - ]:       1162 :     int count = (n_bytes > 4 ? 30 : 250);
+     667                 :            : 
+     668                 :            :     /*
+     669                 :            :      * Match the procedure given in RFC 6979 §3.3 (deterministic ECDSA)
+     670                 :            :      * when f_rng is a suitably parametrized instance of HMAC_DRBG:
+     671                 :            :      * - use the same byte ordering;
+     672                 :            :      * - keep the leftmost n_bits bits of the generated octet string;
+     673                 :            :      * - try until result is in the desired range.
+     674                 :            :      * This also avoids any bias, which is especially important for ECDSA.
+     675                 :            :      */
+     676                 :            :     do {
+     677         [ -  + ]:       1162 :         MBEDTLS_MPI_CHK(mbedtls_mpi_core_fill_random(X, limbs,
+     678                 :            :                                                      n_bytes,
+     679                 :            :                                                      f_rng, p_rng));
+     680                 :       1162 :         mbedtls_mpi_core_shift_r(X, limbs, 8 * n_bytes - n_bits);
+     681                 :            : 
+     682         [ -  + ]:       1162 :         if (--count == 0) {
+     683                 :          0 :             ret = MBEDTLS_ERR_MPI_NOT_ACCEPTABLE;
+     684                 :          0 :             goto cleanup;
+     685                 :            :         }
+     686                 :            : 
+     687                 :       1162 :         ge_lower = mbedtls_mpi_core_uint_le_mpi(min, X, limbs);
+     688                 :       1162 :         lt_upper = mbedtls_mpi_core_lt_ct(X, N, limbs);
+     689         [ -  + ]:       1162 :     } while (mbedtls_ct_bool_and(ge_lower, lt_upper) == MBEDTLS_CT_FALSE);
+     690                 :            : 
+     691                 :       1162 : cleanup:
+     692                 :       1162 :     return ret;
+     693                 :            : }
+     694                 :            : 
+     695                 :        832 : static size_t exp_mod_get_window_size(size_t Ebits)
+     696                 :            : {
+     697                 :            : #if MBEDTLS_MPI_WINDOW_SIZE >= 6
+     698                 :            :     return (Ebits > 671) ? 6 : (Ebits > 239) ? 5 : (Ebits >  79) ? 4 : 1;
+     699                 :            : #elif MBEDTLS_MPI_WINDOW_SIZE == 5
+     700                 :            :     return (Ebits > 239) ? 5 : (Ebits >  79) ? 4 : 1;
+     701                 :            : #elif MBEDTLS_MPI_WINDOW_SIZE > 1
+     702         [ +  + ]:        832 :     return (Ebits >  79) ? MBEDTLS_MPI_WINDOW_SIZE : 1;
+     703                 :            : #else
+     704                 :            :     (void) Ebits;
+     705                 :            :     return 1;
+     706                 :            : #endif
+     707                 :            : }
+     708                 :            : 
+     709                 :        416 : size_t mbedtls_mpi_core_exp_mod_working_limbs(size_t AN_limbs, size_t E_limbs)
+     710                 :            : {
+     711                 :        416 :     const size_t wsize = exp_mod_get_window_size(E_limbs * biL);
+     712                 :        416 :     const size_t welem = ((size_t) 1) << wsize;
+     713                 :            : 
+     714                 :            :     /* How big does each part of the working memory pool need to be? */
+     715                 :        416 :     const size_t table_limbs   = welem * AN_limbs;
+     716                 :        416 :     const size_t select_limbs  = AN_limbs;
+     717                 :        416 :     const size_t temp_limbs    = 2 * AN_limbs + 1;
+     718                 :            : 
+     719                 :        416 :     return table_limbs + select_limbs + temp_limbs;
+     720                 :            : }
+     721                 :            : 
+     722                 :        416 : static void exp_mod_precompute_window(const mbedtls_mpi_uint *A,
+     723                 :            :                                       const mbedtls_mpi_uint *N,
+     724                 :            :                                       size_t AN_limbs,
+     725                 :            :                                       mbedtls_mpi_uint mm,
+     726                 :            :                                       const mbedtls_mpi_uint *RR,
+     727                 :            :                                       size_t welem,
+     728                 :            :                                       mbedtls_mpi_uint *Wtable,
+     729                 :            :                                       mbedtls_mpi_uint *temp)
+     730                 :            : {
+     731                 :            :     /* W[0] = 1 (in Montgomery presentation) */
+     732                 :        416 :     memset(Wtable, 0, AN_limbs * ciL);
+     733                 :        416 :     Wtable[0] = 1;
+     734                 :        416 :     mbedtls_mpi_core_montmul(Wtable, Wtable, RR, AN_limbs, N, AN_limbs, mm, temp);
+     735                 :            : 
+     736                 :            :     /* W[1] = A (already in Montgomery presentation) */
+     737                 :        416 :     mbedtls_mpi_uint *W1 = Wtable + AN_limbs;
+     738                 :        416 :     memcpy(W1, A, AN_limbs * ciL);
+     739                 :            : 
+     740                 :            :     /* W[i+1] = W[i] * W[1], i >= 2 */
+     741                 :        416 :     mbedtls_mpi_uint *Wprev = W1;
+     742         [ +  + ]:        776 :     for (size_t i = 2; i < welem; i++) {
+     743                 :        360 :         mbedtls_mpi_uint *Wcur = Wprev + AN_limbs;
+     744                 :        360 :         mbedtls_mpi_core_montmul(Wcur, Wprev, W1, AN_limbs, N, AN_limbs, mm, temp);
+     745                 :        360 :         Wprev = Wcur;
+     746                 :            :     }
+     747                 :        416 : }
+     748                 :            : 
+     749                 :            : /* Exponentiation: X := A^E mod N.
+     750                 :            :  *
+     751                 :            :  * A must already be in Montgomery form.
+     752                 :            :  *
+     753                 :            :  * As in other bignum functions, assume that AN_limbs and E_limbs are nonzero.
+     754                 :            :  *
+     755                 :            :  * RR must contain 2^{2*biL} mod N.
+     756                 :            :  *
+     757                 :            :  * The algorithm is a variant of Left-to-right k-ary exponentiation: HAC 14.82
+     758                 :            :  * (The difference is that the body in our loop processes a single bit instead
+     759                 :            :  * of a full window.)
+     760                 :            :  */
+     761                 :        416 : void mbedtls_mpi_core_exp_mod(mbedtls_mpi_uint *X,
+     762                 :            :                               const mbedtls_mpi_uint *A,
+     763                 :            :                               const mbedtls_mpi_uint *N,
+     764                 :            :                               size_t AN_limbs,
+     765                 :            :                               const mbedtls_mpi_uint *E,
+     766                 :            :                               size_t E_limbs,
+     767                 :            :                               const mbedtls_mpi_uint *RR,
+     768                 :            :                               mbedtls_mpi_uint *T)
+     769                 :            : {
+     770                 :        416 :     const size_t wsize = exp_mod_get_window_size(E_limbs * biL);
+     771                 :        416 :     const size_t welem = ((size_t) 1) << wsize;
+     772                 :            : 
+     773                 :            :     /* This is how we will use the temporary storage T, which must have space
+     774                 :            :      * for table_limbs, select_limbs and (2 * AN_limbs + 1) for montmul. */
+     775                 :        416 :     const size_t table_limbs  = welem * AN_limbs;
+     776                 :        416 :     const size_t select_limbs = AN_limbs;
+     777                 :            : 
+     778                 :            :     /* Pointers to specific parts of the temporary working memory pool */
+     779                 :        416 :     mbedtls_mpi_uint *const Wtable  = T;
+     780                 :        416 :     mbedtls_mpi_uint *const Wselect = Wtable  +  table_limbs;
+     781                 :        416 :     mbedtls_mpi_uint *const temp    = Wselect + select_limbs;
+     782                 :            : 
+     783                 :            :     /*
+     784                 :            :      * Window precomputation
+     785                 :            :      */
+     786                 :            : 
+     787                 :        416 :     const mbedtls_mpi_uint mm = mbedtls_mpi_core_montmul_init(N);
+     788                 :            : 
+     789                 :            :     /* Set Wtable[i] = A^(2^i) (in Montgomery representation) */
+     790                 :        416 :     exp_mod_precompute_window(A, N, AN_limbs,
+     791                 :            :                               mm, RR,
+     792                 :            :                               welem, Wtable, temp);
+     793                 :            : 
+     794                 :            :     /*
+     795                 :            :      * Fixed window exponentiation
+     796                 :            :      */
+     797                 :            : 
+     798                 :            :     /* X = 1 (in Montgomery presentation) initially */
+     799                 :        416 :     memcpy(X, Wtable, AN_limbs * ciL);
+     800                 :            : 
+     801                 :            :     /* We'll process the bits of E from most significant
+     802                 :            :      * (limb_index=E_limbs-1, E_bit_index=biL-1) to least significant
+     803                 :            :      * (limb_index=0, E_bit_index=0). */
+     804                 :        416 :     size_t E_limb_index = E_limbs;
+     805                 :        416 :     size_t E_bit_index = 0;
+     806                 :            :     /* At any given time, window contains window_bits bits from E.
+     807                 :            :      * window_bits can go up to wsize. */
+     808                 :        416 :     size_t window_bits = 0;
+     809                 :        416 :     mbedtls_mpi_uint window = 0;
+     810                 :            : 
+     811                 :            :     do {
+     812                 :            :         /* Square */
+     813                 :     104320 :         mbedtls_mpi_core_montmul(X, X, X, AN_limbs, N, AN_limbs, mm, temp);
+     814                 :            : 
+     815                 :            :         /* Move to the next bit of the exponent */
+     816         [ +  + ]:     104320 :         if (E_bit_index == 0) {
+     817                 :       1630 :             --E_limb_index;
+     818                 :       1630 :             E_bit_index = biL - 1;
+     819                 :            :         } else {
+     820                 :     102690 :             --E_bit_index;
+     821                 :            :         }
+     822                 :            :         /* Insert next exponent bit into window */
+     823                 :     104320 :         ++window_bits;
+     824                 :     104320 :         window <<= 1;
+     825                 :     104320 :         window |= (E[E_limb_index] >> E_bit_index) & 1;
+     826                 :            : 
+     827                 :            :         /* Clear window if it's full. Also clear the window at the end,
+     828                 :            :          * when we've finished processing the exponent. */
+     829   [ +  +  +  + ]:     104320 :         if (window_bits == wsize ||
+     830         [ +  + ]:        888 :             (E_bit_index == 0 && E_limb_index == 0)) {
+     831                 :            :             /* Select Wtable[window] without leaking window through
+     832                 :            :              * memory access patterns. */
+     833                 :      49982 :             mbedtls_mpi_core_ct_uint_table_lookup(Wselect, Wtable,
+     834                 :            :                                                   AN_limbs, welem, window);
+     835                 :            :             /* Multiply X by the selected element. */
+     836                 :      49982 :             mbedtls_mpi_core_montmul(X, X, Wselect, AN_limbs, N, AN_limbs, mm,
+     837                 :            :                                      temp);
+     838                 :      49982 :             window = 0;
+     839                 :      49982 :             window_bits = 0;
+     840                 :            :         }
+     841   [ +  +  +  + ]:     104320 :     } while (!(E_bit_index == 0 && E_limb_index == 0));
+     842                 :        416 : }
+     843                 :            : 
+     844                 :    4298254 : mbedtls_mpi_uint mbedtls_mpi_core_sub_int(mbedtls_mpi_uint *X,
+     845                 :            :                                           const mbedtls_mpi_uint *A,
+     846                 :            :                                           mbedtls_mpi_uint c,  /* doubles as carry */
+     847                 :            :                                           size_t limbs)
+     848                 :            : {
+     849         [ +  + ]:   24303952 :     for (size_t i = 0; i < limbs; i++) {
+     850                 :   20005698 :         mbedtls_mpi_uint s = A[i];
+     851                 :   20005698 :         mbedtls_mpi_uint t = s - c;
+     852                 :   20005698 :         c = (t > s);
+     853                 :   20005698 :         X[i] = t;
+     854                 :            :     }
+     855                 :            : 
+     856                 :    4298254 :     return c;
+     857                 :            : }
+     858                 :            : 
+     859                 :          0 : mbedtls_ct_condition_t mbedtls_mpi_core_check_zero_ct(const mbedtls_mpi_uint *A,
+     860                 :            :                                                       size_t limbs)
+     861                 :            : {
+     862                 :          0 :     volatile const mbedtls_mpi_uint *force_read_A = A;
+     863                 :          0 :     mbedtls_mpi_uint bits = 0;
+     864                 :            : 
+     865         [ #  # ]:          0 :     for (size_t i = 0; i < limbs; i++) {
+     866                 :          0 :         bits |= force_read_A[i];
+     867                 :            :     }
+     868                 :            : 
+     869                 :          0 :     return mbedtls_ct_bool(bits);
+     870                 :            : }
+     871                 :            : 
+     872                 :        443 : void mbedtls_mpi_core_to_mont_rep(mbedtls_mpi_uint *X,
+     873                 :            :                                   const mbedtls_mpi_uint *A,
+     874                 :            :                                   const mbedtls_mpi_uint *N,
+     875                 :            :                                   size_t AN_limbs,
+     876                 :            :                                   mbedtls_mpi_uint mm,
+     877                 :            :                                   const mbedtls_mpi_uint *rr,
+     878                 :            :                                   mbedtls_mpi_uint *T)
+     879                 :            : {
+     880                 :        443 :     mbedtls_mpi_core_montmul(X, A, rr, AN_limbs, N, AN_limbs, mm, T);
+     881                 :        443 : }
+     882                 :            : 
+     883                 :        416 : void mbedtls_mpi_core_from_mont_rep(mbedtls_mpi_uint *X,
+     884                 :            :                                     const mbedtls_mpi_uint *A,
+     885                 :            :                                     const mbedtls_mpi_uint *N,
+     886                 :            :                                     size_t AN_limbs,
+     887                 :            :                                     mbedtls_mpi_uint mm,
+     888                 :            :                                     mbedtls_mpi_uint *T)
+     889                 :            : {
+     890                 :        416 :     const mbedtls_mpi_uint Rinv = 1;    /* 1/R in Mont. rep => 1 */
+     891                 :            : 
+     892                 :        416 :     mbedtls_mpi_core_montmul(X, A, &Rinv, 1, N, AN_limbs, mm, T);
+     893                 :        416 : }
+     894                 :            : 
+     895                 :            : #endif /* MBEDTLS_BIGNUM_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/bignum_core.h.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/bignum_core.h.func-sort-c.html new file mode 100644 index 00000000000..170045d8f4a --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/bignum_core.h.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/bignum_core.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - bignum_core.h (source / functions)HitTotalCoverage
Test:coverage.infoLines:22100.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_mpi_core_montmul_working_limbs27
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/bignum_core.h.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/bignum_core.h.func.html new file mode 100644 index 00000000000..1b65e74df1d --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/bignum_core.h.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/bignum_core.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - bignum_core.h (source / functions)HitTotalCoverage
Test:coverage.infoLines:22100.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_mpi_core_montmul_working_limbs27
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/bignum_core.h.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/bignum_core.h.gcov.html new file mode 100644 index 00000000000..23be7ca43e5 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/bignum_core.h.gcov.html @@ -0,0 +1,848 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/bignum_core.h + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - bignum_core.h (source / functions)HitTotalCoverage
Test:coverage.infoLines:22100.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:00-
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Core bignum functions
+       3                 :            :  *
+       4                 :            :  *  This interface should only be used by the legacy bignum module (bignum.h)
+       5                 :            :  *  and the modular bignum modules (bignum_mod.c, bignum_mod_raw.c). All other
+       6                 :            :  *  modules should use the high-level modular bignum interface (bignum_mod.h)
+       7                 :            :  *  or the legacy bignum interface (bignum.h).
+       8                 :            :  *
+       9                 :            :  * This module is about processing non-negative integers with a fixed upper
+      10                 :            :  * bound that's of the form 2^n-1 where n is a multiple of #biL.
+      11                 :            :  * These can be thought of integers written in base 2^#biL with a fixed
+      12                 :            :  * number of digits. Digits in this base are called *limbs*.
+      13                 :            :  * Many operations treat these numbers as the principal representation of
+      14                 :            :  * a number modulo 2^n or a smaller bound.
+      15                 :            :  *
+      16                 :            :  * The functions in this module obey the following conventions unless
+      17                 :            :  * explicitly indicated otherwise:
+      18                 :            :  *
+      19                 :            :  * - **Overflow**: some functions indicate overflow from the range
+      20                 :            :  *   [0, 2^n-1] by returning carry parameters, while others operate
+      21                 :            :  *   modulo and so cannot overflow. This should be clear from the function
+      22                 :            :  *   documentation.
+      23                 :            :  * - **Bignum parameters**: Bignums are passed as pointers to an array of
+      24                 :            :  *   limbs. A limb has the type #mbedtls_mpi_uint. Unless otherwise specified:
+      25                 :            :  *     - Bignum parameters called \p A, \p B, ... are inputs, and are
+      26                 :            :  *       not modified by the function.
+      27                 :            :  *     - For operations modulo some number, the modulus is called \p N
+      28                 :            :  *       and is input-only.
+      29                 :            :  *     - Bignum parameters called \p X, \p Y are outputs or input-output.
+      30                 :            :  *       The initial content of output-only parameters is ignored.
+      31                 :            :  *     - Some functions use different names that reflect traditional
+      32                 :            :  *       naming of operands of certain operations (e.g.
+      33                 :            :  *       divisor/dividend/quotient/remainder).
+      34                 :            :  *     - \p T is a temporary storage area. The initial content of such
+      35                 :            :  *       parameter is ignored and the final content is unspecified.
+      36                 :            :  * - **Bignum sizes**: bignum sizes are always expressed in limbs.
+      37                 :            :  *   Most functions work on bignums of a given size and take a single
+      38                 :            :  *   \p limbs parameter that applies to all parameters that are limb arrays.
+      39                 :            :  *   All bignum sizes must be at least 1 and must be significantly less than
+      40                 :            :  *   #SIZE_MAX. The behavior if a size is 0 is undefined. The behavior if the
+      41                 :            :  *   total size of all parameters overflows #SIZE_MAX is undefined.
+      42                 :            :  * - **Parameter ordering**: for bignum parameters, outputs come before inputs.
+      43                 :            :  *   Temporaries come last.
+      44                 :            :  * - **Aliasing**: in general, output bignums may be aliased to one or more
+      45                 :            :  *   inputs. As an exception, parameters that are documented as a modulus value
+      46                 :            :  *   may not be aliased to an output. Outputs may not be aliased to one another.
+      47                 :            :  *   Temporaries may not be aliased to any other parameter.
+      48                 :            :  * - **Overlap**: apart from aliasing of limb array pointers (where two
+      49                 :            :  *   arguments are equal pointers), overlap is not supported and may result
+      50                 :            :  *   in undefined behavior.
+      51                 :            :  * - **Error handling**: This is a low-level module. Functions generally do not
+      52                 :            :  *   try to protect against invalid arguments such as nonsensical sizes or
+      53                 :            :  *   null pointers. Note that some functions that operate on bignums of
+      54                 :            :  *   different sizes have constraints about their size, and violating those
+      55                 :            :  *   constraints may lead to buffer overflows.
+      56                 :            :  * - **Modular representatives**: functions that operate modulo \p N expect
+      57                 :            :  *   all modular inputs to be in the range [0, \p N - 1] and guarantee outputs
+      58                 :            :  *   in the range [0, \p N - 1]. If an input is out of range, outputs are
+      59                 :            :  *   fully unspecified, though bignum values out of range should not cause
+      60                 :            :  *   buffer overflows (beware that this is not extensively tested).
+      61                 :            :  */
+      62                 :            : 
+      63                 :            : /*
+      64                 :            :  *  Copyright The Mbed TLS Contributors
+      65                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+      66                 :            :  */
+      67                 :            : 
+      68                 :            : #ifndef MBEDTLS_BIGNUM_CORE_H
+      69                 :            : #define MBEDTLS_BIGNUM_CORE_H
+      70                 :            : 
+      71                 :            : #include "common.h"
+      72                 :            : 
+      73                 :            : #if defined(MBEDTLS_BIGNUM_C)
+      74                 :            : #include "mbedtls/bignum.h"
+      75                 :            : #endif
+      76                 :            : 
+      77                 :            : #include "constant_time_internal.h"
+      78                 :            : 
+      79                 :            : #define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
+      80                 :            : #define biL    (ciL << 3)                     /** bits  in limb  */
+      81                 :            : #define biH    (ciL << 2)                     /** half limb size */
+      82                 :            : 
+      83                 :            : /*
+      84                 :            :  * Convert between bits/chars and number of limbs
+      85                 :            :  * Divide first in order to avoid potential overflows
+      86                 :            :  */
+      87                 :            : #define BITS_TO_LIMBS(i)  ((i) / biL + ((i) % biL != 0))
+      88                 :            : #define CHARS_TO_LIMBS(i) ((i) / ciL + ((i) % ciL != 0))
+      89                 :            : /* Get a specific byte, without range checks. */
+      90                 :            : #define GET_BYTE(X, i)                                \
+      91                 :            :     (((X)[(i) / ciL] >> (((i) % ciL) * 8)) & 0xff)
+      92                 :            : 
+      93                 :            : /** Count leading zero bits in a given integer.
+      94                 :            :  *
+      95                 :            :  * \warning     The result is undefined if \p a == 0
+      96                 :            :  *
+      97                 :            :  * \param a     Integer to count leading zero bits.
+      98                 :            :  *
+      99                 :            :  * \return      The number of leading zero bits in \p a, if \p a != 0.
+     100                 :            :  *              If \p a == 0, the result is undefined.
+     101                 :            :  */
+     102                 :            : size_t mbedtls_mpi_core_clz(mbedtls_mpi_uint a);
+     103                 :            : 
+     104                 :            : /** Return the minimum number of bits required to represent the value held
+     105                 :            :  * in the MPI.
+     106                 :            :  *
+     107                 :            :  * \note This function returns 0 if all the limbs of \p A are 0.
+     108                 :            :  *
+     109                 :            :  * \param[in] A     The address of the MPI.
+     110                 :            :  * \param A_limbs   The number of limbs of \p A.
+     111                 :            :  *
+     112                 :            :  * \return      The number of bits in \p A.
+     113                 :            :  */
+     114                 :            : size_t mbedtls_mpi_core_bitlen(const mbedtls_mpi_uint *A, size_t A_limbs);
+     115                 :            : 
+     116                 :            : /** Convert a big-endian byte array aligned to the size of mbedtls_mpi_uint
+     117                 :            :  * into the storage form used by mbedtls_mpi.
+     118                 :            :  *
+     119                 :            :  * \param[in,out] A     The address of the MPI.
+     120                 :            :  * \param A_limbs       The number of limbs of \p A.
+     121                 :            :  */
+     122                 :            : void mbedtls_mpi_core_bigendian_to_host(mbedtls_mpi_uint *A,
+     123                 :            :                                         size_t A_limbs);
+     124                 :            : 
+     125                 :            : /** \brief         Compare a machine integer with an MPI.
+     126                 :            :  *
+     127                 :            :  *                 This function operates in constant time with respect
+     128                 :            :  *                 to the values of \p min and \p A.
+     129                 :            :  *
+     130                 :            :  * \param min      A machine integer.
+     131                 :            :  * \param[in] A    An MPI.
+     132                 :            :  * \param A_limbs  The number of limbs of \p A.
+     133                 :            :  *                 This must be at least 1.
+     134                 :            :  *
+     135                 :            :  * \return         MBEDTLS_CT_TRUE if \p min is less than or equal to \p A, otherwise MBEDTLS_CT_FALSE.
+     136                 :            :  */
+     137                 :            : mbedtls_ct_condition_t mbedtls_mpi_core_uint_le_mpi(mbedtls_mpi_uint min,
+     138                 :            :                                                     const mbedtls_mpi_uint *A,
+     139                 :            :                                                     size_t A_limbs);
+     140                 :            : 
+     141                 :            : /**
+     142                 :            :  * \brief          Check if one unsigned MPI is less than another in constant
+     143                 :            :  *                 time.
+     144                 :            :  *
+     145                 :            :  * \param A        The left-hand MPI. This must point to an array of limbs
+     146                 :            :  *                 with the same allocated length as \p B.
+     147                 :            :  * \param B        The right-hand MPI. This must point to an array of limbs
+     148                 :            :  *                 with the same allocated length as \p A.
+     149                 :            :  * \param limbs    The number of limbs in \p A and \p B.
+     150                 :            :  *                 This must not be 0.
+     151                 :            :  *
+     152                 :            :  * \return         MBEDTLS_CT_TRUE  if \p A is less than \p B.
+     153                 :            :  *                 MBEDTLS_CT_FALSE if \p A is greater than or equal to \p B.
+     154                 :            :  */
+     155                 :            : mbedtls_ct_condition_t mbedtls_mpi_core_lt_ct(const mbedtls_mpi_uint *A,
+     156                 :            :                                               const mbedtls_mpi_uint *B,
+     157                 :            :                                               size_t limbs);
+     158                 :            : 
+     159                 :            : /**
+     160                 :            :  * \brief   Perform a safe conditional copy of an MPI which doesn't reveal
+     161                 :            :  *          whether assignment was done or not.
+     162                 :            :  *
+     163                 :            :  * \param[out] X        The address of the destination MPI.
+     164                 :            :  *                      This must be initialized. Must have enough limbs to
+     165                 :            :  *                      store the full value of \p A.
+     166                 :            :  * \param[in]  A        The address of the source MPI. This must be initialized.
+     167                 :            :  * \param      limbs    The number of limbs of \p A.
+     168                 :            :  * \param      assign   The condition deciding whether to perform the
+     169                 :            :  *                      assignment or not. Callers will need to use
+     170                 :            :  *                      the constant time interface (e.g. `mbedtls_ct_bool()`)
+     171                 :            :  *                      to construct this argument.
+     172                 :            :  *
+     173                 :            :  * \note           This function avoids leaking any information about whether
+     174                 :            :  *                 the assignment was done or not.
+     175                 :            :  */
+     176                 :            : void mbedtls_mpi_core_cond_assign(mbedtls_mpi_uint *X,
+     177                 :            :                                   const mbedtls_mpi_uint *A,
+     178                 :            :                                   size_t limbs,
+     179                 :            :                                   mbedtls_ct_condition_t assign);
+     180                 :            : 
+     181                 :            : /**
+     182                 :            :  * \brief   Perform a safe conditional swap of two MPIs which doesn't reveal
+     183                 :            :  *          whether the swap was done or not.
+     184                 :            :  *
+     185                 :            :  * \param[in,out] X         The address of the first MPI.
+     186                 :            :  *                          This must be initialized.
+     187                 :            :  * \param[in,out] Y         The address of the second MPI.
+     188                 :            :  *                          This must be initialized.
+     189                 :            :  * \param         limbs     The number of limbs of \p X and \p Y.
+     190                 :            :  * \param         swap      The condition deciding whether to perform
+     191                 :            :  *                          the swap or not.
+     192                 :            :  *
+     193                 :            :  * \note           This function avoids leaking any information about whether
+     194                 :            :  *                 the swap was done or not.
+     195                 :            :  */
+     196                 :            : void mbedtls_mpi_core_cond_swap(mbedtls_mpi_uint *X,
+     197                 :            :                                 mbedtls_mpi_uint *Y,
+     198                 :            :                                 size_t limbs,
+     199                 :            :                                 mbedtls_ct_condition_t swap);
+     200                 :            : 
+     201                 :            : /** Import X from unsigned binary data, little-endian.
+     202                 :            :  *
+     203                 :            :  * The MPI needs to have enough limbs to store the full value (including any
+     204                 :            :  * most significant zero bytes in the input).
+     205                 :            :  *
+     206                 :            :  * \param[out] X         The address of the MPI.
+     207                 :            :  * \param X_limbs        The number of limbs of \p X.
+     208                 :            :  * \param[in] input      The input buffer to import from.
+     209                 :            :  * \param input_length   The length bytes of \p input.
+     210                 :            :  *
+     211                 :            :  * \return       \c 0 if successful.
+     212                 :            :  * \return       #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p X isn't
+     213                 :            :  *               large enough to hold the value in \p input.
+     214                 :            :  */
+     215                 :            : int mbedtls_mpi_core_read_le(mbedtls_mpi_uint *X,
+     216                 :            :                              size_t X_limbs,
+     217                 :            :                              const unsigned char *input,
+     218                 :            :                              size_t input_length);
+     219                 :            : 
+     220                 :            : /** Import X from unsigned binary data, big-endian.
+     221                 :            :  *
+     222                 :            :  * The MPI needs to have enough limbs to store the full value (including any
+     223                 :            :  * most significant zero bytes in the input).
+     224                 :            :  *
+     225                 :            :  * \param[out] X        The address of the MPI.
+     226                 :            :  *                      May only be #NULL if \p X_limbs is 0 and \p input_length
+     227                 :            :  *                      is 0.
+     228                 :            :  * \param X_limbs       The number of limbs of \p X.
+     229                 :            :  * \param[in] input     The input buffer to import from.
+     230                 :            :  *                      May only be #NULL if \p input_length is 0.
+     231                 :            :  * \param input_length  The length in bytes of \p input.
+     232                 :            :  *
+     233                 :            :  * \return       \c 0 if successful.
+     234                 :            :  * \return       #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p X isn't
+     235                 :            :  *               large enough to hold the value in \p input.
+     236                 :            :  */
+     237                 :            : int mbedtls_mpi_core_read_be(mbedtls_mpi_uint *X,
+     238                 :            :                              size_t X_limbs,
+     239                 :            :                              const unsigned char *input,
+     240                 :            :                              size_t input_length);
+     241                 :            : 
+     242                 :            : /** Export A into unsigned binary data, little-endian.
+     243                 :            :  *
+     244                 :            :  * \note If \p output is shorter than \p A the export is still successful if the
+     245                 :            :  *       value held in \p A fits in the buffer (that is, if enough of the most
+     246                 :            :  *       significant bytes of \p A are 0).
+     247                 :            :  *
+     248                 :            :  * \param[in] A         The address of the MPI.
+     249                 :            :  * \param A_limbs       The number of limbs of \p A.
+     250                 :            :  * \param[out] output   The output buffer to export to.
+     251                 :            :  * \param output_length The length in bytes of \p output.
+     252                 :            :  *
+     253                 :            :  * \return       \c 0 if successful.
+     254                 :            :  * \return       #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p output isn't
+     255                 :            :  *               large enough to hold the value of \p A.
+     256                 :            :  */
+     257                 :            : int mbedtls_mpi_core_write_le(const mbedtls_mpi_uint *A,
+     258                 :            :                               size_t A_limbs,
+     259                 :            :                               unsigned char *output,
+     260                 :            :                               size_t output_length);
+     261                 :            : 
+     262                 :            : /** Export A into unsigned binary data, big-endian.
+     263                 :            :  *
+     264                 :            :  * \note If \p output is shorter than \p A the export is still successful if the
+     265                 :            :  *       value held in \p A fits in the buffer (that is, if enough of the most
+     266                 :            :  *       significant bytes of \p A are 0).
+     267                 :            :  *
+     268                 :            :  * \param[in] A         The address of the MPI.
+     269                 :            :  * \param A_limbs       The number of limbs of \p A.
+     270                 :            :  * \param[out] output   The output buffer to export to.
+     271                 :            :  * \param output_length The length in bytes of \p output.
+     272                 :            :  *
+     273                 :            :  * \return       \c 0 if successful.
+     274                 :            :  * \return       #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p output isn't
+     275                 :            :  *               large enough to hold the value of \p A.
+     276                 :            :  */
+     277                 :            : int mbedtls_mpi_core_write_be(const mbedtls_mpi_uint *A,
+     278                 :            :                               size_t A_limbs,
+     279                 :            :                               unsigned char *output,
+     280                 :            :                               size_t output_length);
+     281                 :            : 
+     282                 :            : /** \brief              Shift an MPI in-place right by a number of bits.
+     283                 :            :  *
+     284                 :            :  *                      Shifting by more bits than there are bit positions
+     285                 :            :  *                      in \p X is valid and results in setting \p X to 0.
+     286                 :            :  *
+     287                 :            :  *                      This function's execution time depends on the value
+     288                 :            :  *                      of \p count (and of course \p limbs).
+     289                 :            :  *
+     290                 :            :  * \param[in,out] X     The number to shift.
+     291                 :            :  * \param limbs         The number of limbs of \p X. This must be at least 1.
+     292                 :            :  * \param count         The number of bits to shift by.
+     293                 :            :  */
+     294                 :            : void mbedtls_mpi_core_shift_r(mbedtls_mpi_uint *X, size_t limbs,
+     295                 :            :                               size_t count);
+     296                 :            : 
+     297                 :            : /**
+     298                 :            :  * \brief               Shift an MPI in-place left by a number of bits.
+     299                 :            :  *
+     300                 :            :  *                      Shifting by more bits than there are bit positions
+     301                 :            :  *                      in \p X will produce an unspecified result.
+     302                 :            :  *
+     303                 :            :  *                      This function's execution time depends on the value
+     304                 :            :  *                      of \p count (and of course \p limbs).
+     305                 :            :  * \param[in,out] X     The number to shift.
+     306                 :            :  * \param limbs         The number of limbs of \p X. This must be at least 1.
+     307                 :            :  * \param count         The number of bits to shift by.
+     308                 :            :  */
+     309                 :            : void mbedtls_mpi_core_shift_l(mbedtls_mpi_uint *X, size_t limbs,
+     310                 :            :                               size_t count);
+     311                 :            : 
+     312                 :            : /**
+     313                 :            :  * \brief Add two fixed-size large unsigned integers, returning the carry.
+     314                 :            :  *
+     315                 :            :  * Calculates `A + B` where `A` and `B` have the same size.
+     316                 :            :  *
+     317                 :            :  * This function operates modulo `2^(biL*limbs)` and returns the carry
+     318                 :            :  * (1 if there was a wraparound, and 0 otherwise).
+     319                 :            :  *
+     320                 :            :  * \p X may be aliased to \p A or \p B.
+     321                 :            :  *
+     322                 :            :  * \param[out] X    The result of the addition.
+     323                 :            :  * \param[in] A     Little-endian presentation of the left operand.
+     324                 :            :  * \param[in] B     Little-endian presentation of the right operand.
+     325                 :            :  * \param limbs     Number of limbs of \p X, \p A and \p B.
+     326                 :            :  *
+     327                 :            :  * \return          1 if `A + B >= 2^(biL*limbs)`, 0 otherwise.
+     328                 :            :  */
+     329                 :            : mbedtls_mpi_uint mbedtls_mpi_core_add(mbedtls_mpi_uint *X,
+     330                 :            :                                       const mbedtls_mpi_uint *A,
+     331                 :            :                                       const mbedtls_mpi_uint *B,
+     332                 :            :                                       size_t limbs);
+     333                 :            : 
+     334                 :            : /**
+     335                 :            :  * \brief Conditional addition of two fixed-size large unsigned integers,
+     336                 :            :  *        returning the carry.
+     337                 :            :  *
+     338                 :            :  * Functionally equivalent to
+     339                 :            :  *
+     340                 :            :  * ```
+     341                 :            :  * if( cond )
+     342                 :            :  *    X += A;
+     343                 :            :  * return carry;
+     344                 :            :  * ```
+     345                 :            :  *
+     346                 :            :  * This function operates modulo `2^(biL*limbs)`.
+     347                 :            :  *
+     348                 :            :  * \param[in,out] X  The pointer to the (little-endian) array
+     349                 :            :  *                   representing the bignum to accumulate onto.
+     350                 :            :  * \param[in] A      The pointer to the (little-endian) array
+     351                 :            :  *                   representing the bignum to conditionally add
+     352                 :            :  *                   to \p X. This may be aliased to \p X but may not
+     353                 :            :  *                   overlap otherwise.
+     354                 :            :  * \param limbs      Number of limbs of \p X and \p A.
+     355                 :            :  * \param cond       Condition bit dictating whether addition should
+     356                 :            :  *                   happen or not. This must be \c 0 or \c 1.
+     357                 :            :  *
+     358                 :            :  * \warning          If \p cond is neither 0 nor 1, the result of this function
+     359                 :            :  *                   is unspecified, and the resulting value in \p X might be
+     360                 :            :  *                   neither its original value nor \p X + \p A.
+     361                 :            :  *
+     362                 :            :  * \return           1 if `X + cond * A >= 2^(biL*limbs)`, 0 otherwise.
+     363                 :            :  */
+     364                 :            : mbedtls_mpi_uint mbedtls_mpi_core_add_if(mbedtls_mpi_uint *X,
+     365                 :            :                                          const mbedtls_mpi_uint *A,
+     366                 :            :                                          size_t limbs,
+     367                 :            :                                          unsigned cond);
+     368                 :            : 
+     369                 :            : /**
+     370                 :            :  * \brief Subtract two fixed-size large unsigned integers, returning the borrow.
+     371                 :            :  *
+     372                 :            :  * Calculate `A - B` where \p A and \p B have the same size.
+     373                 :            :  * This function operates modulo `2^(biL*limbs)` and returns the carry
+     374                 :            :  * (1 if there was a wraparound, i.e. if `A < B`, and 0 otherwise).
+     375                 :            :  *
+     376                 :            :  * \p X may be aliased to \p A or \p B, or even both, but may not overlap
+     377                 :            :  * either otherwise.
+     378                 :            :  *
+     379                 :            :  * \param[out] X    The result of the subtraction.
+     380                 :            :  * \param[in] A     Little-endian presentation of left operand.
+     381                 :            :  * \param[in] B     Little-endian presentation of right operand.
+     382                 :            :  * \param limbs     Number of limbs of \p X, \p A and \p B.
+     383                 :            :  *
+     384                 :            :  * \return          1 if `A < B`.
+     385                 :            :  *                  0 if `A >= B`.
+     386                 :            :  */
+     387                 :            : mbedtls_mpi_uint mbedtls_mpi_core_sub(mbedtls_mpi_uint *X,
+     388                 :            :                                       const mbedtls_mpi_uint *A,
+     389                 :            :                                       const mbedtls_mpi_uint *B,
+     390                 :            :                                       size_t limbs);
+     391                 :            : 
+     392                 :            : /**
+     393                 :            :  * \brief Perform a fixed-size multiply accumulate operation: X += b * A
+     394                 :            :  *
+     395                 :            :  * \p X may be aliased to \p A (when \p X_limbs == \p A_limbs), but may not
+     396                 :            :  * otherwise overlap.
+     397                 :            :  *
+     398                 :            :  * This function operates modulo `2^(biL*X_limbs)`.
+     399                 :            :  *
+     400                 :            :  * \param[in,out] X  The pointer to the (little-endian) array
+     401                 :            :  *                   representing the bignum to accumulate onto.
+     402                 :            :  * \param X_limbs    The number of limbs of \p X. This must be
+     403                 :            :  *                   at least \p A_limbs.
+     404                 :            :  * \param[in] A      The pointer to the (little-endian) array
+     405                 :            :  *                   representing the bignum to multiply with.
+     406                 :            :  *                   This may be aliased to \p X but may not overlap
+     407                 :            :  *                   otherwise.
+     408                 :            :  * \param A_limbs    The number of limbs of \p A.
+     409                 :            :  * \param b          X scalar to multiply with.
+     410                 :            :  *
+     411                 :            :  * \return           The carry at the end of the operation.
+     412                 :            :  */
+     413                 :            : mbedtls_mpi_uint mbedtls_mpi_core_mla(mbedtls_mpi_uint *X, size_t X_limbs,
+     414                 :            :                                       const mbedtls_mpi_uint *A, size_t A_limbs,
+     415                 :            :                                       mbedtls_mpi_uint b);
+     416                 :            : 
+     417                 :            : /**
+     418                 :            :  * \brief Perform a known-size multiplication
+     419                 :            :  *
+     420                 :            :  * \p X may not be aliased to any of the inputs for this function.
+     421                 :            :  * \p A may be aliased to \p B.
+     422                 :            :  *
+     423                 :            :  * \param[out] X     The pointer to the (little-endian) array to receive
+     424                 :            :  *                   the product of \p A_limbs and \p B_limbs.
+     425                 :            :  *                   This must be of length \p A_limbs + \p B_limbs.
+     426                 :            :  * \param[in] A      The pointer to the (little-endian) array
+     427                 :            :  *                   representing the first factor.
+     428                 :            :  * \param A_limbs    The number of limbs in \p A.
+     429                 :            :  * \param[in] B      The pointer to the (little-endian) array
+     430                 :            :  *                   representing the second factor.
+     431                 :            :  * \param B_limbs    The number of limbs in \p B.
+     432                 :            :  */
+     433                 :            : void mbedtls_mpi_core_mul(mbedtls_mpi_uint *X,
+     434                 :            :                           const mbedtls_mpi_uint *A, size_t A_limbs,
+     435                 :            :                           const mbedtls_mpi_uint *B, size_t B_limbs);
+     436                 :            : 
+     437                 :            : /**
+     438                 :            :  * \brief Calculate initialisation value for fast Montgomery modular
+     439                 :            :  *        multiplication
+     440                 :            :  *
+     441                 :            :  * \param[in] N  Little-endian presentation of the modulus. This must have
+     442                 :            :  *               at least one limb.
+     443                 :            :  *
+     444                 :            :  * \return       The initialisation value for fast Montgomery modular multiplication
+     445                 :            :  */
+     446                 :            : mbedtls_mpi_uint mbedtls_mpi_core_montmul_init(const mbedtls_mpi_uint *N);
+     447                 :            : 
+     448                 :            : /**
+     449                 :            :  * \brief Montgomery multiplication: X = A * B * R^-1 mod N (HAC 14.36)
+     450                 :            :  *
+     451                 :            :  * \p A and \p B must be in canonical form. That is, < \p N.
+     452                 :            :  *
+     453                 :            :  * \p X may be aliased to \p A or \p N, or even \p B (if \p AN_limbs ==
+     454                 :            :  * \p B_limbs) but may not overlap any parameters otherwise.
+     455                 :            :  *
+     456                 :            :  * \p A and \p B may alias each other, if \p AN_limbs == \p B_limbs. They may
+     457                 :            :  * not alias \p N (since they must be in canonical form, they cannot == \p N).
+     458                 :            :  *
+     459                 :            :  * \param[out]    X         The destination MPI, as a little-endian array of
+     460                 :            :  *                          length \p AN_limbs.
+     461                 :            :  *                          On successful completion, X contains the result of
+     462                 :            :  *                          the multiplication `A * B * R^-1` mod N where
+     463                 :            :  *                          `R = 2^(biL*AN_limbs)`.
+     464                 :            :  * \param[in]     A         Little-endian presentation of first operand.
+     465                 :            :  *                          Must have the same number of limbs as \p N.
+     466                 :            :  * \param[in]     B         Little-endian presentation of second operand.
+     467                 :            :  * \param[in]     B_limbs   The number of limbs in \p B.
+     468                 :            :  *                          Must be <= \p AN_limbs.
+     469                 :            :  * \param[in]     N         Little-endian presentation of the modulus.
+     470                 :            :  *                          This must be odd, and have exactly the same number
+     471                 :            :  *                          of limbs as \p A.
+     472                 :            :  *                          It may alias \p X, but must not alias or otherwise
+     473                 :            :  *                          overlap any of the other parameters.
+     474                 :            :  * \param[in]     AN_limbs  The number of limbs in \p X, \p A and \p N.
+     475                 :            :  * \param         mm        The Montgomery constant for \p N: -N^-1 mod 2^biL.
+     476                 :            :  *                          This can be calculated by `mbedtls_mpi_core_montmul_init()`.
+     477                 :            :  * \param[in,out] T         Temporary storage of size at least 2*AN_limbs+1 limbs.
+     478                 :            :  *                          Its initial content is unused and
+     479                 :            :  *                          its final content is indeterminate.
+     480                 :            :  *                          It must not alias or otherwise overlap any of the
+     481                 :            :  *                          other parameters.
+     482                 :            :  */
+     483                 :            : void mbedtls_mpi_core_montmul(mbedtls_mpi_uint *X,
+     484                 :            :                               const mbedtls_mpi_uint *A,
+     485                 :            :                               const mbedtls_mpi_uint *B, size_t B_limbs,
+     486                 :            :                               const mbedtls_mpi_uint *N, size_t AN_limbs,
+     487                 :            :                               mbedtls_mpi_uint mm, mbedtls_mpi_uint *T);
+     488                 :            : 
+     489                 :            : /**
+     490                 :            :  * \brief Calculate the square of the Montgomery constant. (Needed
+     491                 :            :  *        for conversion and operations in Montgomery form.)
+     492                 :            :  *
+     493                 :            :  * \param[out] X  A pointer to the result of the calculation of
+     494                 :            :  *                the square of the Montgomery constant:
+     495                 :            :  *                2^{2*n*biL} mod N.
+     496                 :            :  * \param[in]  N  Little-endian presentation of the modulus, which must be odd.
+     497                 :            :  *
+     498                 :            :  * \return        0 if successful.
+     499                 :            :  * \return        #MBEDTLS_ERR_MPI_ALLOC_FAILED if there is not enough space
+     500                 :            :  *                to store the value of Montgomery constant squared.
+     501                 :            :  * \return        #MBEDTLS_ERR_MPI_DIVISION_BY_ZERO if \p N modulus is zero.
+     502                 :            :  * \return        #MBEDTLS_ERR_MPI_NEGATIVE_VALUE if \p N modulus is negative.
+     503                 :            :  */
+     504                 :            : int mbedtls_mpi_core_get_mont_r2_unsafe(mbedtls_mpi *X,
+     505                 :            :                                         const mbedtls_mpi *N);
+     506                 :            : 
+     507                 :            : #if defined(MBEDTLS_TEST_HOOKS)
+     508                 :            : /**
+     509                 :            :  * Copy an MPI from a table without leaking the index.
+     510                 :            :  *
+     511                 :            :  * \param dest              The destination buffer. This must point to a writable
+     512                 :            :  *                          buffer of at least \p limbs limbs.
+     513                 :            :  * \param table             The address of the table. This must point to a readable
+     514                 :            :  *                          array of \p count elements of \p limbs limbs each.
+     515                 :            :  * \param limbs             The number of limbs in each table entry.
+     516                 :            :  * \param count             The number of entries in \p table.
+     517                 :            :  * \param index             The (secret) table index to look up. This must be in the
+     518                 :            :  *                          range `0 .. count-1`.
+     519                 :            :  */
+     520                 :            : void mbedtls_mpi_core_ct_uint_table_lookup(mbedtls_mpi_uint *dest,
+     521                 :            :                                            const mbedtls_mpi_uint *table,
+     522                 :            :                                            size_t limbs,
+     523                 :            :                                            size_t count,
+     524                 :            :                                            size_t index);
+     525                 :            : #endif /* MBEDTLS_TEST_HOOKS */
+     526                 :            : 
+     527                 :            : /**
+     528                 :            :  * \brief          Fill an integer with a number of random bytes.
+     529                 :            :  *
+     530                 :            :  * \param X        The destination MPI.
+     531                 :            :  * \param X_limbs  The number of limbs of \p X.
+     532                 :            :  * \param bytes    The number of random bytes to generate.
+     533                 :            :  * \param f_rng    The RNG function to use. This must not be \c NULL.
+     534                 :            :  * \param p_rng    The RNG parameter to be passed to \p f_rng. This may be
+     535                 :            :  *                 \c NULL if \p f_rng doesn't need a context argument.
+     536                 :            :  *
+     537                 :            :  * \return         \c 0 if successful.
+     538                 :            :  * \return         #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if \p X does not have
+     539                 :            :  *                 enough room for \p bytes bytes.
+     540                 :            :  * \return         A negative error code on RNG failure.
+     541                 :            :  *
+     542                 :            :  * \note           The bytes obtained from the RNG are interpreted
+     543                 :            :  *                 as a big-endian representation of an MPI; this can
+     544                 :            :  *                 be relevant in applications like deterministic ECDSA.
+     545                 :            :  */
+     546                 :            : int mbedtls_mpi_core_fill_random(mbedtls_mpi_uint *X, size_t X_limbs,
+     547                 :            :                                  size_t bytes,
+     548                 :            :                                  int (*f_rng)(void *, unsigned char *, size_t),
+     549                 :            :                                  void *p_rng);
+     550                 :            : 
+     551                 :            : /** Generate a random number uniformly in a range.
+     552                 :            :  *
+     553                 :            :  * This function generates a random number between \p min inclusive and
+     554                 :            :  * \p N exclusive.
+     555                 :            :  *
+     556                 :            :  * The procedure complies with RFC 6979 §3.3 (deterministic ECDSA)
+     557                 :            :  * when the RNG is a suitably parametrized instance of HMAC_DRBG
+     558                 :            :  * and \p min is \c 1.
+     559                 :            :  *
+     560                 :            :  * \note           There are `N - min` possible outputs. The lower bound
+     561                 :            :  *                 \p min can be reached, but the upper bound \p N cannot.
+     562                 :            :  *
+     563                 :            :  * \param X        The destination MPI, with \p limbs limbs.
+     564                 :            :  *                 It must not be aliased with \p N or otherwise overlap it.
+     565                 :            :  * \param min      The minimum value to return.
+     566                 :            :  * \param N        The upper bound of the range, exclusive, with \p limbs limbs.
+     567                 :            :  *                 In other words, this is one plus the maximum value to return.
+     568                 :            :  *                 \p N must be strictly larger than \p min.
+     569                 :            :  * \param limbs    The number of limbs of \p N and \p X.
+     570                 :            :  *                 This must not be 0.
+     571                 :            :  * \param f_rng    The RNG function to use. This must not be \c NULL.
+     572                 :            :  * \param p_rng    The RNG parameter to be passed to \p f_rng.
+     573                 :            :  *
+     574                 :            :  * \return         \c 0 if successful.
+     575                 :            :  * \return         #MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if the implementation was
+     576                 :            :  *                 unable to find a suitable value within a limited number
+     577                 :            :  *                 of attempts. This has a negligible probability if \p N
+     578                 :            :  *                 is significantly larger than \p min, which is the case
+     579                 :            :  *                 for all usual cryptographic applications.
+     580                 :            :  */
+     581                 :            : int mbedtls_mpi_core_random(mbedtls_mpi_uint *X,
+     582                 :            :                             mbedtls_mpi_uint min,
+     583                 :            :                             const mbedtls_mpi_uint *N,
+     584                 :            :                             size_t limbs,
+     585                 :            :                             int (*f_rng)(void *, unsigned char *, size_t),
+     586                 :            :                             void *p_rng);
+     587                 :            : 
+     588                 :            : /**
+     589                 :            :  * \brief          Returns the number of limbs of working memory required for
+     590                 :            :  *                 a call to `mbedtls_mpi_core_exp_mod()`.
+     591                 :            :  *
+     592                 :            :  * \note           This will always be at least
+     593                 :            :  *                 `mbedtls_mpi_core_montmul_working_limbs(AN_limbs)`,
+     594                 :            :  *                 i.e. sufficient for a call to `mbedtls_mpi_core_montmul()`.
+     595                 :            :  *
+     596                 :            :  * \param AN_limbs The number of limbs in the input `A` and the modulus `N`
+     597                 :            :  *                 (they must be the same size) that will be given to
+     598                 :            :  *                 `mbedtls_mpi_core_exp_mod()`.
+     599                 :            :  * \param E_limbs  The number of limbs in the exponent `E` that will be given
+     600                 :            :  *                 to `mbedtls_mpi_core_exp_mod()`.
+     601                 :            :  *
+     602                 :            :  * \return         The number of limbs of working memory required by
+     603                 :            :  *                 `mbedtls_mpi_core_exp_mod()`.
+     604                 :            :  */
+     605                 :            : size_t mbedtls_mpi_core_exp_mod_working_limbs(size_t AN_limbs, size_t E_limbs);
+     606                 :            : 
+     607                 :            : /**
+     608                 :            :  * \brief            Perform a modular exponentiation with secret exponent:
+     609                 :            :  *                   X = A^E mod N, where \p A is already in Montgomery form.
+     610                 :            :  *
+     611                 :            :  * \p X may be aliased to \p A, but not to \p RR or \p E, even if \p E_limbs ==
+     612                 :            :  * \p AN_limbs.
+     613                 :            :  *
+     614                 :            :  * \param[out] X     The destination MPI, as a little endian array of length
+     615                 :            :  *                   \p AN_limbs.
+     616                 :            :  * \param[in] A      The base MPI, as a little endian array of length \p AN_limbs.
+     617                 :            :  *                   Must be in Montgomery form.
+     618                 :            :  * \param[in] N      The modulus, as a little endian array of length \p AN_limbs.
+     619                 :            :  * \param AN_limbs   The number of limbs in \p X, \p A, \p N, \p RR.
+     620                 :            :  * \param[in] E      The exponent, as a little endian array of length \p E_limbs.
+     621                 :            :  * \param E_limbs    The number of limbs in \p E.
+     622                 :            :  * \param[in] RR     The precomputed residue of 2^{2*biL} modulo N, as a little
+     623                 :            :  *                   endian array of length \p AN_limbs.
+     624                 :            :  * \param[in,out] T  Temporary storage of at least the number of limbs returned
+     625                 :            :  *                   by `mbedtls_mpi_core_exp_mod_working_limbs()`.
+     626                 :            :  *                   Its initial content is unused and its final content is
+     627                 :            :  *                   indeterminate.
+     628                 :            :  *                   It must not alias or otherwise overlap any of the other
+     629                 :            :  *                   parameters.
+     630                 :            :  *                   It is up to the caller to zeroize \p T when it is no
+     631                 :            :  *                   longer needed, and before freeing it if it was dynamically
+     632                 :            :  *                   allocated.
+     633                 :            :  */
+     634                 :            : void mbedtls_mpi_core_exp_mod(mbedtls_mpi_uint *X,
+     635                 :            :                               const mbedtls_mpi_uint *A,
+     636                 :            :                               const mbedtls_mpi_uint *N, size_t AN_limbs,
+     637                 :            :                               const mbedtls_mpi_uint *E, size_t E_limbs,
+     638                 :            :                               const mbedtls_mpi_uint *RR,
+     639                 :            :                               mbedtls_mpi_uint *T);
+     640                 :            : 
+     641                 :            : /**
+     642                 :            :  * \brief Subtract unsigned integer from known-size large unsigned integers.
+     643                 :            :  *        Return the borrow.
+     644                 :            :  *
+     645                 :            :  * \param[out] X    The result of the subtraction.
+     646                 :            :  * \param[in] A     The left operand.
+     647                 :            :  * \param b         The unsigned scalar to subtract.
+     648                 :            :  * \param limbs     Number of limbs of \p X and \p A.
+     649                 :            :  *
+     650                 :            :  * \return          1 if `A < b`.
+     651                 :            :  *                  0 if `A >= b`.
+     652                 :            :  */
+     653                 :            : mbedtls_mpi_uint mbedtls_mpi_core_sub_int(mbedtls_mpi_uint *X,
+     654                 :            :                                           const mbedtls_mpi_uint *A,
+     655                 :            :                                           mbedtls_mpi_uint b,
+     656                 :            :                                           size_t limbs);
+     657                 :            : 
+     658                 :            : /**
+     659                 :            :  * \brief Determine if a given MPI has the value \c 0 in constant time with
+     660                 :            :  *        respect to the value (but not with respect to the number of limbs).
+     661                 :            :  *
+     662                 :            :  * \param[in] A   The MPI to test.
+     663                 :            :  * \param limbs   Number of limbs in \p A.
+     664                 :            :  *
+     665                 :            :  * \return        MBEDTLS_CT_FALSE if `A == 0`
+     666                 :            :  *                MBEDTLS_CT_TRUE  if `A != 0`.
+     667                 :            :  */
+     668                 :            : mbedtls_ct_condition_t mbedtls_mpi_core_check_zero_ct(const mbedtls_mpi_uint *A,
+     669                 :            :                                                       size_t limbs);
+     670                 :            : 
+     671                 :            : /**
+     672                 :            :  * \brief          Returns the number of limbs of working memory required for
+     673                 :            :  *                 a call to `mbedtls_mpi_core_montmul()`.
+     674                 :            :  *
+     675                 :            :  * \param AN_limbs The number of limbs in the input `A` and the modulus `N`
+     676                 :            :  *                 (they must be the same size) that will be given to
+     677                 :            :  *                 `mbedtls_mpi_core_montmul()` or one of the other functions
+     678                 :            :  *                 that specifies this as the amount of working memory needed.
+     679                 :            :  *
+     680                 :            :  * \return         The number of limbs of working memory required by
+     681                 :            :  *                 `mbedtls_mpi_core_montmul()` (or other similar function).
+     682                 :            :  */
+     683                 :         27 : static inline size_t mbedtls_mpi_core_montmul_working_limbs(size_t AN_limbs)
+     684                 :            : {
+     685                 :         27 :     return 2 * AN_limbs + 1;
+     686                 :            : }
+     687                 :            : 
+     688                 :            : /** Convert an MPI into Montgomery form.
+     689                 :            :  *
+     690                 :            :  * \p X may be aliased to \p A, but may not otherwise overlap it.
+     691                 :            :  *
+     692                 :            :  * \p X may not alias \p N (it is in canonical form, so must be strictly less
+     693                 :            :  * than \p N). Nor may it alias or overlap \p rr (this is unlikely to be
+     694                 :            :  * required in practice.)
+     695                 :            :  *
+     696                 :            :  * This function is a thin wrapper around `mbedtls_mpi_core_montmul()` that is
+     697                 :            :  * an alternative to calling `mbedtls_mpi_mod_raw_to_mont_rep()` when we
+     698                 :            :  * don't want to allocate memory.
+     699                 :            :  *
+     700                 :            :  * \param[out]    X         The result of the conversion.
+     701                 :            :  *                          Must have the same number of limbs as \p A.
+     702                 :            :  * \param[in]     A         The MPI to convert into Montgomery form.
+     703                 :            :  *                          Must have the same number of limbs as the modulus.
+     704                 :            :  * \param[in]     N         The address of the modulus, which gives the size of
+     705                 :            :  *                          the base `R` = 2^(biL*N->limbs).
+     706                 :            :  * \param[in]     AN_limbs  The number of limbs in \p X, \p A, \p N and \p rr.
+     707                 :            :  * \param         mm        The Montgomery constant for \p N: -N^-1 mod 2^biL.
+     708                 :            :  *                          This can be determined by calling
+     709                 :            :  *                          `mbedtls_mpi_core_montmul_init()`.
+     710                 :            :  * \param[in]     rr        The residue for `2^{2*n*biL} mod N`.
+     711                 :            :  * \param[in,out] T         Temporary storage of size at least
+     712                 :            :  *                          `mbedtls_mpi_core_montmul_working_limbs(AN_limbs)`
+     713                 :            :  *                          limbs.
+     714                 :            :  *                          Its initial content is unused and
+     715                 :            :  *                          its final content is indeterminate.
+     716                 :            :  *                          It must not alias or otherwise overlap any of the
+     717                 :            :  *                          other parameters.
+     718                 :            :  */
+     719                 :            : void mbedtls_mpi_core_to_mont_rep(mbedtls_mpi_uint *X,
+     720                 :            :                                   const mbedtls_mpi_uint *A,
+     721                 :            :                                   const mbedtls_mpi_uint *N,
+     722                 :            :                                   size_t AN_limbs,
+     723                 :            :                                   mbedtls_mpi_uint mm,
+     724                 :            :                                   const mbedtls_mpi_uint *rr,
+     725                 :            :                                   mbedtls_mpi_uint *T);
+     726                 :            : 
+     727                 :            : /** Convert an MPI from Montgomery form.
+     728                 :            :  *
+     729                 :            :  * \p X may be aliased to \p A, but may not otherwise overlap it.
+     730                 :            :  *
+     731                 :            :  * \p X may not alias \p N (it is in canonical form, so must be strictly less
+     732                 :            :  * than \p N).
+     733                 :            :  *
+     734                 :            :  * This function is a thin wrapper around `mbedtls_mpi_core_montmul()` that is
+     735                 :            :  * an alternative to calling `mbedtls_mpi_mod_raw_from_mont_rep()` when we
+     736                 :            :  * don't want to allocate memory.
+     737                 :            :  *
+     738                 :            :  * \param[out]    X         The result of the conversion.
+     739                 :            :  *                          Must have the same number of limbs as \p A.
+     740                 :            :  * \param[in]     A         The MPI to convert from Montgomery form.
+     741                 :            :  *                          Must have the same number of limbs as the modulus.
+     742                 :            :  * \param[in]     N         The address of the modulus, which gives the size of
+     743                 :            :  *                          the base `R` = 2^(biL*N->limbs).
+     744                 :            :  * \param[in]     AN_limbs  The number of limbs in \p X, \p A and \p N.
+     745                 :            :  * \param         mm        The Montgomery constant for \p N: -N^-1 mod 2^biL.
+     746                 :            :  *                          This can be determined by calling
+     747                 :            :  *                          `mbedtls_mpi_core_montmul_init()`.
+     748                 :            :  * \param[in,out] T         Temporary storage of size at least
+     749                 :            :  *                          `mbedtls_mpi_core_montmul_working_limbs(AN_limbs)`
+     750                 :            :  *                          limbs.
+     751                 :            :  *                          Its initial content is unused and
+     752                 :            :  *                          its final content is indeterminate.
+     753                 :            :  *                          It must not alias or otherwise overlap any of the
+     754                 :            :  *                          other parameters.
+     755                 :            :  */
+     756                 :            : void mbedtls_mpi_core_from_mont_rep(mbedtls_mpi_uint *X,
+     757                 :            :                                     const mbedtls_mpi_uint *A,
+     758                 :            :                                     const mbedtls_mpi_uint *N,
+     759                 :            :                                     size_t AN_limbs,
+     760                 :            :                                     mbedtls_mpi_uint mm,
+     761                 :            :                                     mbedtls_mpi_uint *T);
+     762                 :            : 
+     763                 :            : #endif /* MBEDTLS_BIGNUM_CORE_H */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/camellia.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/camellia.c.func-sort-c.html new file mode 100644 index 00000000000..b5944b58bae --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/camellia.c.func-sort-c.html @@ -0,0 +1,121 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/camellia.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - camellia.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:02750.0 %
Date:2024-09-22 08:21:07Functions:0100.0 %
Branches:01710.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
camellia_feistel0
mbedtls_camellia_crypt_cbc0
mbedtls_camellia_crypt_cfb1280
mbedtls_camellia_crypt_ctr0
mbedtls_camellia_crypt_ecb0
mbedtls_camellia_free0
mbedtls_camellia_init0
mbedtls_camellia_self_test0
mbedtls_camellia_setkey_dec0
mbedtls_camellia_setkey_enc0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/camellia.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/camellia.c.func.html new file mode 100644 index 00000000000..ba768bd43e0 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/camellia.c.func.html @@ -0,0 +1,121 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/camellia.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - camellia.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:02750.0 %
Date:2024-09-22 08:21:07Functions:0100.0 %
Branches:01710.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
camellia_feistel0
mbedtls_camellia_crypt_cbc0
mbedtls_camellia_crypt_cfb1280
mbedtls_camellia_crypt_ctr0
mbedtls_camellia_crypt_ecb0
mbedtls_camellia_free0
mbedtls_camellia_init0
mbedtls_camellia_self_test0
mbedtls_camellia_setkey_dec0
mbedtls_camellia_setkey_enc0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/camellia.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/camellia.c.gcov.html new file mode 100644 index 00000000000..1d56d2cda0f --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/camellia.c.gcov.html @@ -0,0 +1,1147 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/camellia.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - camellia.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:02750.0 %
Date:2024-09-22 08:21:07Functions:0100.0 %
Branches:01710.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  *  Camellia implementation
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  */
+       7                 :            : /*
+       8                 :            :  *  The Camellia block cipher was designed by NTT and Mitsubishi Electric
+       9                 :            :  *  Corporation.
+      10                 :            :  *
+      11                 :            :  *  http://info.isl.ntt.co.jp/crypt/eng/camellia/dl/01espec.pdf
+      12                 :            :  */
+      13                 :            : 
+      14                 :            : #include "common.h"
+      15                 :            : 
+      16                 :            : #if defined(MBEDTLS_CAMELLIA_C)
+      17                 :            : 
+      18                 :            : #include "mbedtls/camellia.h"
+      19                 :            : #include "mbedtls/platform_util.h"
+      20                 :            : 
+      21                 :            : #include <string.h>
+      22                 :            : 
+      23                 :            : #include "mbedtls/platform.h"
+      24                 :            : 
+      25                 :            : #if !defined(MBEDTLS_CAMELLIA_ALT)
+      26                 :            : 
+      27                 :            : static const unsigned char SIGMA_CHARS[6][8] =
+      28                 :            : {
+      29                 :            :     { 0xa0, 0x9e, 0x66, 0x7f, 0x3b, 0xcc, 0x90, 0x8b },
+      30                 :            :     { 0xb6, 0x7a, 0xe8, 0x58, 0x4c, 0xaa, 0x73, 0xb2 },
+      31                 :            :     { 0xc6, 0xef, 0x37, 0x2f, 0xe9, 0x4f, 0x82, 0xbe },
+      32                 :            :     { 0x54, 0xff, 0x53, 0xa5, 0xf1, 0xd3, 0x6f, 0x1c },
+      33                 :            :     { 0x10, 0xe5, 0x27, 0xfa, 0xde, 0x68, 0x2d, 0x1d },
+      34                 :            :     { 0xb0, 0x56, 0x88, 0xc2, 0xb3, 0xe6, 0xc1, 0xfd }
+      35                 :            : };
+      36                 :            : 
+      37                 :            : #if defined(MBEDTLS_CAMELLIA_SMALL_MEMORY)
+      38                 :            : 
+      39                 :            : static const unsigned char FSb[256] =
+      40                 :            : {
+      41                 :            :     112, 130, 44, 236, 179, 39, 192, 229, 228, 133, 87, 53, 234, 12, 174, 65,
+      42                 :            :     35, 239, 107, 147, 69, 25, 165, 33, 237, 14, 79, 78, 29, 101, 146, 189,
+      43                 :            :     134, 184, 175, 143, 124, 235, 31, 206, 62, 48, 220, 95, 94, 197, 11, 26,
+      44                 :            :     166, 225, 57, 202, 213, 71, 93, 61, 217,  1, 90, 214, 81, 86, 108, 77,
+      45                 :            :     139, 13, 154, 102, 251, 204, 176, 45, 116, 18, 43, 32, 240, 177, 132, 153,
+      46                 :            :     223, 76, 203, 194, 52, 126, 118,  5, 109, 183, 169, 49, 209, 23,  4, 215,
+      47                 :            :     20, 88, 58, 97, 222, 27, 17, 28, 50, 15, 156, 22, 83, 24, 242, 34,
+      48                 :            :     254, 68, 207, 178, 195, 181, 122, 145, 36,  8, 232, 168, 96, 252, 105, 80,
+      49                 :            :     170, 208, 160, 125, 161, 137, 98, 151, 84, 91, 30, 149, 224, 255, 100, 210,
+      50                 :            :     16, 196,  0, 72, 163, 247, 117, 219, 138,  3, 230, 218,  9, 63, 221, 148,
+      51                 :            :     135, 92, 131,  2, 205, 74, 144, 51, 115, 103, 246, 243, 157, 127, 191, 226,
+      52                 :            :     82, 155, 216, 38, 200, 55, 198, 59, 129, 150, 111, 75, 19, 190, 99, 46,
+      53                 :            :     233, 121, 167, 140, 159, 110, 188, 142, 41, 245, 249, 182, 47, 253, 180, 89,
+      54                 :            :     120, 152,  6, 106, 231, 70, 113, 186, 212, 37, 171, 66, 136, 162, 141, 250,
+      55                 :            :     114,  7, 185, 85, 248, 238, 172, 10, 54, 73, 42, 104, 60, 56, 241, 164,
+      56                 :            :     64, 40, 211, 123, 187, 201, 67, 193, 21, 227, 173, 244, 119, 199, 128, 158
+      57                 :            : };
+      58                 :            : 
+      59                 :            : #define SBOX1(n) FSb[(n)]
+      60                 :            : #define SBOX2(n) (unsigned char) ((FSb[(n)] >> 7 ^ FSb[(n)] << 1) & 0xff)
+      61                 :            : #define SBOX3(n) (unsigned char) ((FSb[(n)] >> 1 ^ FSb[(n)] << 7) & 0xff)
+      62                 :            : #define SBOX4(n) FSb[((n) << 1 ^ (n) >> 7) &0xff]
+      63                 :            : 
+      64                 :            : #else /* MBEDTLS_CAMELLIA_SMALL_MEMORY */
+      65                 :            : 
+      66                 :            : static const unsigned char FSb[256] =
+      67                 :            : {
+      68                 :            :     112, 130,  44, 236, 179,  39, 192, 229, 228, 133,  87,  53, 234,  12, 174,  65,
+      69                 :            :     35, 239, 107, 147,  69,  25, 165,  33, 237,  14,  79,  78,  29, 101, 146, 189,
+      70                 :            :     134, 184, 175, 143, 124, 235,  31, 206,  62,  48, 220,  95,  94, 197,  11,  26,
+      71                 :            :     166, 225,  57, 202, 213,  71,  93,  61, 217,   1,  90, 214,  81,  86, 108,  77,
+      72                 :            :     139,  13, 154, 102, 251, 204, 176,  45, 116,  18,  43,  32, 240, 177, 132, 153,
+      73                 :            :     223,  76, 203, 194,  52, 126, 118,   5, 109, 183, 169,  49, 209,  23,   4, 215,
+      74                 :            :     20,  88,  58,  97, 222,  27,  17,  28,  50,  15, 156,  22,  83,  24, 242,  34,
+      75                 :            :     254,  68, 207, 178, 195, 181, 122, 145,  36,   8, 232, 168,  96, 252, 105,  80,
+      76                 :            :     170, 208, 160, 125, 161, 137,  98, 151,  84,  91,  30, 149, 224, 255, 100, 210,
+      77                 :            :     16, 196,   0,  72, 163, 247, 117, 219, 138,   3, 230, 218,   9,  63, 221, 148,
+      78                 :            :     135,  92, 131,   2, 205,  74, 144,  51, 115, 103, 246, 243, 157, 127, 191, 226,
+      79                 :            :     82, 155, 216,  38, 200,  55, 198,  59, 129, 150, 111,  75,  19, 190,  99,  46,
+      80                 :            :     233, 121, 167, 140, 159, 110, 188, 142,  41, 245, 249, 182,  47, 253, 180,  89,
+      81                 :            :     120, 152,   6, 106, 231,  70, 113, 186, 212,  37, 171,  66, 136, 162, 141, 250,
+      82                 :            :     114,   7, 185,  85, 248, 238, 172,  10,  54,  73,  42, 104,  60,  56, 241, 164,
+      83                 :            :     64,  40, 211, 123, 187, 201,  67, 193,  21, 227, 173, 244, 119, 199, 128, 158
+      84                 :            : };
+      85                 :            : 
+      86                 :            : static const unsigned char FSb2[256] =
+      87                 :            : {
+      88                 :            :     224,   5,  88, 217, 103,  78, 129, 203, 201,  11, 174, 106, 213,  24,  93, 130,
+      89                 :            :     70, 223, 214,  39, 138,  50,  75,  66, 219,  28, 158, 156,  58, 202,  37, 123,
+      90                 :            :     13, 113,  95,  31, 248, 215,  62, 157, 124,  96, 185, 190, 188, 139,  22,  52,
+      91                 :            :     77, 195, 114, 149, 171, 142, 186, 122, 179,   2, 180, 173, 162, 172, 216, 154,
+      92                 :            :     23,  26,  53, 204, 247, 153,  97,  90, 232,  36,  86,  64, 225,  99,   9,  51,
+      93                 :            :     191, 152, 151, 133, 104, 252, 236,  10, 218, 111,  83,  98, 163,  46,   8, 175,
+      94                 :            :     40, 176, 116, 194, 189,  54,  34,  56, 100,  30,  57,  44, 166,  48, 229,  68,
+      95                 :            :     253, 136, 159, 101, 135, 107, 244,  35,  72,  16, 209,  81, 192, 249, 210, 160,
+      96                 :            :     85, 161,  65, 250,  67,  19, 196,  47, 168, 182,  60,  43, 193, 255, 200, 165,
+      97                 :            :     32, 137,   0, 144,  71, 239, 234, 183,  21,   6, 205, 181,  18, 126, 187,  41,
+      98                 :            :     15, 184,   7,   4, 155, 148,  33, 102, 230, 206, 237, 231,  59, 254, 127, 197,
+      99                 :            :     164,  55, 177,  76, 145, 110, 141, 118,   3,  45, 222, 150,  38, 125, 198,  92,
+     100                 :            :     211, 242,  79,  25,  63, 220, 121,  29,  82, 235, 243, 109,  94, 251, 105, 178,
+     101                 :            :     240,  49,  12, 212, 207, 140, 226, 117, 169,  74,  87, 132,  17,  69,  27, 245,
+     102                 :            :     228,  14, 115, 170, 241, 221,  89,  20, 108, 146,  84, 208, 120, 112, 227,  73,
+     103                 :            :     128,  80, 167, 246, 119, 147, 134, 131,  42, 199,  91, 233, 238, 143,   1,  61
+     104                 :            : };
+     105                 :            : 
+     106                 :            : static const unsigned char FSb3[256] =
+     107                 :            : {
+     108                 :            :     56,  65,  22, 118, 217, 147,  96, 242, 114, 194, 171, 154, 117,   6,  87, 160,
+     109                 :            :     145, 247, 181, 201, 162, 140, 210, 144, 246,   7, 167,  39, 142, 178,  73, 222,
+     110                 :            :     67,  92, 215, 199,  62, 245, 143, 103,  31,  24, 110, 175,  47, 226, 133,  13,
+     111                 :            :     83, 240, 156, 101, 234, 163, 174, 158, 236, 128,  45, 107, 168,  43,  54, 166,
+     112                 :            :     197, 134,  77,  51, 253, 102,  88, 150,  58,   9, 149,  16, 120, 216,  66, 204,
+     113                 :            :     239,  38, 229,  97,  26,  63,  59, 130, 182, 219, 212, 152, 232, 139,   2, 235,
+     114                 :            :     10,  44,  29, 176, 111, 141, 136,  14,  25, 135,  78,  11, 169,  12, 121,  17,
+     115                 :            :     127,  34, 231,  89, 225, 218,  61, 200,  18,   4, 116,  84,  48, 126, 180,  40,
+     116                 :            :     85, 104,  80, 190, 208, 196,  49, 203,  42, 173,  15, 202, 112, 255,  50, 105,
+     117                 :            :     8,  98,   0,  36, 209, 251, 186, 237,  69, 129, 115, 109, 132, 159, 238,  74,
+     118                 :            :     195,  46, 193,   1, 230,  37,  72, 153, 185, 179, 123, 249, 206, 191, 223, 113,
+     119                 :            :     41, 205, 108,  19, 100, 155,  99, 157, 192,  75, 183, 165, 137,  95, 177,  23,
+     120                 :            :     244, 188, 211,  70, 207,  55,  94,  71, 148, 250, 252,  91, 151, 254,  90, 172,
+     121                 :            :     60,  76,   3,  53, 243,  35, 184,  93, 106, 146, 213,  33,  68,  81, 198, 125,
+     122                 :            :     57, 131, 220, 170, 124, 119,  86,   5,  27, 164,  21,  52,  30,  28, 248,  82,
+     123                 :            :     32,  20, 233, 189, 221, 228, 161, 224, 138, 241, 214, 122, 187, 227,  64,  79
+     124                 :            : };
+     125                 :            : 
+     126                 :            : static const unsigned char FSb4[256] =
+     127                 :            : {
+     128                 :            :     112,  44, 179, 192, 228,  87, 234, 174,  35, 107,  69, 165, 237,  79,  29, 146,
+     129                 :            :     134, 175, 124,  31,  62, 220,  94,  11, 166,  57, 213,  93, 217,  90,  81, 108,
+     130                 :            :     139, 154, 251, 176, 116,  43, 240, 132, 223, 203,  52, 118, 109, 169, 209,   4,
+     131                 :            :     20,  58, 222,  17,  50, 156,  83, 242, 254, 207, 195, 122,  36, 232,  96, 105,
+     132                 :            :     170, 160, 161,  98,  84,  30, 224, 100,  16,   0, 163, 117, 138, 230,   9, 221,
+     133                 :            :     135, 131, 205, 144, 115, 246, 157, 191,  82, 216, 200, 198, 129, 111,  19,  99,
+     134                 :            :     233, 167, 159, 188,  41, 249,  47, 180, 120,   6, 231, 113, 212, 171, 136, 141,
+     135                 :            :     114, 185, 248, 172,  54,  42,  60, 241,  64, 211, 187,  67,  21, 173, 119, 128,
+     136                 :            :     130, 236,  39, 229, 133,  53,  12,  65, 239, 147,  25,  33,  14,  78, 101, 189,
+     137                 :            :     184, 143, 235, 206,  48,  95, 197,  26, 225, 202,  71,  61,   1, 214,  86,  77,
+     138                 :            :     13, 102, 204,  45,  18,  32, 177, 153,  76, 194, 126,   5, 183,  49,  23, 215,
+     139                 :            :     88,  97,  27,  28,  15,  22,  24,  34,  68, 178, 181, 145,   8, 168, 252,  80,
+     140                 :            :     208, 125, 137, 151,  91, 149, 255, 210, 196,  72, 247, 219,   3, 218,  63, 148,
+     141                 :            :     92,   2,  74,  51, 103, 243, 127, 226, 155,  38,  55,  59, 150,  75, 190,  46,
+     142                 :            :     121, 140, 110, 142, 245, 182, 253,  89, 152, 106,  70, 186,  37,  66, 162, 250,
+     143                 :            :     7,  85, 238,  10,  73, 104,  56, 164,  40, 123, 201, 193, 227, 244, 199, 158
+     144                 :            : };
+     145                 :            : 
+     146                 :            : #define SBOX1(n) FSb[(n)]
+     147                 :            : #define SBOX2(n) FSb2[(n)]
+     148                 :            : #define SBOX3(n) FSb3[(n)]
+     149                 :            : #define SBOX4(n) FSb4[(n)]
+     150                 :            : 
+     151                 :            : #endif /* MBEDTLS_CAMELLIA_SMALL_MEMORY */
+     152                 :            : 
+     153                 :            : static const unsigned char shifts[2][4][4] =
+     154                 :            : {
+     155                 :            :     {
+     156                 :            :         { 1, 1, 1, 1 }, /* KL */
+     157                 :            :         { 0, 0, 0, 0 }, /* KR */
+     158                 :            :         { 1, 1, 1, 1 }, /* KA */
+     159                 :            :         { 0, 0, 0, 0 }  /* KB */
+     160                 :            :     },
+     161                 :            :     {
+     162                 :            :         { 1, 0, 1, 1 }, /* KL */
+     163                 :            :         { 1, 1, 0, 1 }, /* KR */
+     164                 :            :         { 1, 1, 1, 0 }, /* KA */
+     165                 :            :         { 1, 1, 0, 1 }  /* KB */
+     166                 :            :     }
+     167                 :            : };
+     168                 :            : 
+     169                 :            : static const signed char indexes[2][4][20] =
+     170                 :            : {
+     171                 :            :     {
+     172                 :            :         {  0,  1,  2,  3,  8,  9, 10, 11, 38, 39,
+     173                 :            :            36, 37, 23, 20, 21, 22, 27, -1, -1, 26 }, /* KL -> RK */
+     174                 :            :         { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+     175                 :            :           -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, /* KR -> RK */
+     176                 :            :         {  4,  5,  6,  7, 12, 13, 14, 15, 16, 17,
+     177                 :            :            18, 19, -1, 24, 25, -1, 31, 28, 29, 30 }, /* KA -> RK */
+     178                 :            :         { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+     179                 :            :           -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }  /* KB -> RK */
+     180                 :            :     },
+     181                 :            :     {
+     182                 :            :         {  0,  1,  2,  3, 61, 62, 63, 60, -1, -1,
+     183                 :            :            -1, -1, 27, 24, 25, 26, 35, 32, 33, 34 }, /* KL -> RK */
+     184                 :            :         { -1, -1, -1, -1,  8,  9, 10, 11, 16, 17,
+     185                 :            :           18, 19, -1, -1, -1, -1, 39, 36, 37, 38 }, /* KR -> RK */
+     186                 :            :         { -1, -1, -1, -1, 12, 13, 14, 15, 58, 59,
+     187                 :            :           56, 57, 31, 28, 29, 30, -1, -1, -1, -1 }, /* KA -> RK */
+     188                 :            :         {  4,  5,  6,  7, 65, 66, 67, 64, 20, 21,
+     189                 :            :            22, 23, -1, -1, -1, -1, 43, 40, 41, 42 } /* KB -> RK */
+     190                 :            :     }
+     191                 :            : };
+     192                 :            : 
+     193                 :            : static const signed char transposes[2][20] =
+     194                 :            : {
+     195                 :            :     {
+     196                 :            :         21, 22, 23, 20,
+     197                 :            :         -1, -1, -1, -1,
+     198                 :            :         18, 19, 16, 17,
+     199                 :            :         11,  8,  9, 10,
+     200                 :            :         15, 12, 13, 14
+     201                 :            :     },
+     202                 :            :     {
+     203                 :            :         25, 26, 27, 24,
+     204                 :            :         29, 30, 31, 28,
+     205                 :            :         18, 19, 16, 17,
+     206                 :            :         -1, -1, -1, -1,
+     207                 :            :         -1, -1, -1, -1
+     208                 :            :     }
+     209                 :            : };
+     210                 :            : 
+     211                 :            : /* Shift macro for 128 bit strings with rotation smaller than 32 bits (!) */
+     212                 :            : #define ROTL(DEST, SRC, SHIFT)                                      \
+     213                 :            :     {                                                                   \
+     214                 :            :         (DEST)[0] = (SRC)[0] << (SHIFT) ^ (SRC)[1] >> (32 - (SHIFT));   \
+     215                 :            :         (DEST)[1] = (SRC)[1] << (SHIFT) ^ (SRC)[2] >> (32 - (SHIFT));   \
+     216                 :            :         (DEST)[2] = (SRC)[2] << (SHIFT) ^ (SRC)[3] >> (32 - (SHIFT));   \
+     217                 :            :         (DEST)[3] = (SRC)[3] << (SHIFT) ^ (SRC)[0] >> (32 - (SHIFT));   \
+     218                 :            :     }
+     219                 :            : 
+     220                 :            : #define FL(XL, XR, KL, KR)                                          \
+     221                 :            :     {                                                                   \
+     222                 :            :         (XR) = ((((XL) &(KL)) << 1) | (((XL) &(KL)) >> 31)) ^ (XR);   \
+     223                 :            :         (XL) = ((XR) | (KR)) ^ (XL);                                    \
+     224                 :            :     }
+     225                 :            : 
+     226                 :            : #define FLInv(YL, YR, KL, KR)                                       \
+     227                 :            :     {                                                                   \
+     228                 :            :         (YL) = ((YR) | (KR)) ^ (YL);                                    \
+     229                 :            :         (YR) = ((((YL) &(KL)) << 1) | (((YL) &(KL)) >> 31)) ^ (YR);   \
+     230                 :            :     }
+     231                 :            : 
+     232                 :            : #define SHIFT_AND_PLACE(INDEX, OFFSET)                      \
+     233                 :            :     {                                                           \
+     234                 :            :         TK[0] = KC[(OFFSET) * 4 + 0];                           \
+     235                 :            :         TK[1] = KC[(OFFSET) * 4 + 1];                           \
+     236                 :            :         TK[2] = KC[(OFFSET) * 4 + 2];                           \
+     237                 :            :         TK[3] = KC[(OFFSET) * 4 + 3];                           \
+     238                 :            :                                                             \
+     239                 :            :         for (i = 1; i <= 4; i++)                               \
+     240                 :            :         if (shifts[(INDEX)][(OFFSET)][i -1])               \
+     241                 :            :         ROTL(TK + i * 4, TK, (15 * i) % 32);          \
+     242                 :            :                                                             \
+     243                 :            :         for (i = 0; i < 20; i++)                               \
+     244                 :            :         if (indexes[(INDEX)][(OFFSET)][i] != -1) {         \
+     245                 :            :             RK[indexes[(INDEX)][(OFFSET)][i]] = TK[i];    \
+     246                 :            :         }                                                   \
+     247                 :            :     }
+     248                 :            : 
+     249                 :          0 : static void camellia_feistel(const uint32_t x[2], const uint32_t k[2],
+     250                 :            :                              uint32_t z[2])
+     251                 :            : {
+     252                 :            :     uint32_t I0, I1;
+     253                 :          0 :     I0 = x[0] ^ k[0];
+     254                 :          0 :     I1 = x[1] ^ k[1];
+     255                 :            : 
+     256                 :          0 :     I0 = ((uint32_t) SBOX1(MBEDTLS_BYTE_3(I0)) << 24) |
+     257                 :          0 :          ((uint32_t) SBOX2(MBEDTLS_BYTE_2(I0)) << 16) |
+     258                 :          0 :          ((uint32_t) SBOX3(MBEDTLS_BYTE_1(I0)) <<  8) |
+     259                 :          0 :          ((uint32_t) SBOX4(MBEDTLS_BYTE_0(I0)));
+     260                 :          0 :     I1 = ((uint32_t) SBOX2(MBEDTLS_BYTE_3(I1)) << 24) |
+     261                 :          0 :          ((uint32_t) SBOX3(MBEDTLS_BYTE_2(I1)) << 16) |
+     262                 :          0 :          ((uint32_t) SBOX4(MBEDTLS_BYTE_1(I1)) <<  8) |
+     263                 :          0 :          ((uint32_t) SBOX1(MBEDTLS_BYTE_0(I1)));
+     264                 :            : 
+     265                 :          0 :     I0 ^= (I1 << 8) | (I1 >> 24);
+     266                 :          0 :     I1 ^= (I0 << 16) | (I0 >> 16);
+     267                 :          0 :     I0 ^= (I1 >> 8) | (I1 << 24);
+     268                 :          0 :     I1 ^= (I0 >> 8) | (I0 << 24);
+     269                 :            : 
+     270                 :          0 :     z[0] ^= I1;
+     271                 :          0 :     z[1] ^= I0;
+     272                 :          0 : }
+     273                 :            : 
+     274                 :          0 : void mbedtls_camellia_init(mbedtls_camellia_context *ctx)
+     275                 :            : {
+     276                 :          0 :     memset(ctx, 0, sizeof(mbedtls_camellia_context));
+     277                 :          0 : }
+     278                 :            : 
+     279                 :          0 : void mbedtls_camellia_free(mbedtls_camellia_context *ctx)
+     280                 :            : {
+     281         [ #  # ]:          0 :     if (ctx == NULL) {
+     282                 :          0 :         return;
+     283                 :            :     }
+     284                 :            : 
+     285                 :          0 :     mbedtls_platform_zeroize(ctx, sizeof(mbedtls_camellia_context));
+     286                 :            : }
+     287                 :            : 
+     288                 :            : /*
+     289                 :            :  * Camellia key schedule (encryption)
+     290                 :            :  */
+     291                 :          0 : int mbedtls_camellia_setkey_enc(mbedtls_camellia_context *ctx,
+     292                 :            :                                 const unsigned char *key,
+     293                 :            :                                 unsigned int keybits)
+     294                 :            : {
+     295                 :            :     int idx;
+     296                 :            :     size_t i;
+     297                 :            :     uint32_t *RK;
+     298                 :            :     unsigned char t[64];
+     299                 :            :     uint32_t SIGMA[6][2];
+     300                 :            :     uint32_t KC[16];
+     301                 :            :     uint32_t TK[20];
+     302                 :            : 
+     303                 :          0 :     RK = ctx->rk;
+     304                 :            : 
+     305                 :          0 :     memset(t, 0, 64);
+     306                 :          0 :     memset(RK, 0, sizeof(ctx->rk));
+     307                 :            : 
+     308      [ #  #  # ]:          0 :     switch (keybits) {
+     309                 :          0 :         case 128: ctx->nr = 3; idx = 0; break;
+     310                 :          0 :         case 192:
+     311                 :          0 :         case 256: ctx->nr = 4; idx = 1; break;
+     312                 :          0 :         default: return MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA;
+     313                 :            :     }
+     314                 :            : 
+     315         [ #  # ]:          0 :     for (i = 0; i < keybits / 8; ++i) {
+     316                 :          0 :         t[i] = key[i];
+     317                 :            :     }
+     318                 :            : 
+     319         [ #  # ]:          0 :     if (keybits == 192) {
+     320         [ #  # ]:          0 :         for (i = 0; i < 8; i++) {
+     321                 :          0 :             t[24 + i] = ~t[16 + i];
+     322                 :            :         }
+     323                 :            :     }
+     324                 :            : 
+     325                 :            :     /*
+     326                 :            :      * Prepare SIGMA values
+     327                 :            :      */
+     328         [ #  # ]:          0 :     for (i = 0; i < 6; i++) {
+     329                 :          0 :         SIGMA[i][0] = MBEDTLS_GET_UINT32_BE(SIGMA_CHARS[i], 0);
+     330                 :          0 :         SIGMA[i][1] = MBEDTLS_GET_UINT32_BE(SIGMA_CHARS[i], 4);
+     331                 :            :     }
+     332                 :            : 
+     333                 :            :     /*
+     334                 :            :      * Key storage in KC
+     335                 :            :      * Order: KL, KR, KA, KB
+     336                 :            :      */
+     337                 :          0 :     memset(KC, 0, sizeof(KC));
+     338                 :            : 
+     339                 :            :     /* Store KL, KR */
+     340         [ #  # ]:          0 :     for (i = 0; i < 8; i++) {
+     341                 :          0 :         KC[i] = MBEDTLS_GET_UINT32_BE(t, i * 4);
+     342                 :            :     }
+     343                 :            : 
+     344                 :            :     /* Generate KA */
+     345         [ #  # ]:          0 :     for (i = 0; i < 4; ++i) {
+     346                 :          0 :         KC[8 + i] = KC[i] ^ KC[4 + i];
+     347                 :            :     }
+     348                 :            : 
+     349                 :          0 :     camellia_feistel(KC + 8, SIGMA[0], KC + 10);
+     350                 :          0 :     camellia_feistel(KC + 10, SIGMA[1], KC + 8);
+     351                 :            : 
+     352         [ #  # ]:          0 :     for (i = 0; i < 4; ++i) {
+     353                 :          0 :         KC[8 + i] ^= KC[i];
+     354                 :            :     }
+     355                 :            : 
+     356                 :          0 :     camellia_feistel(KC + 8, SIGMA[2], KC + 10);
+     357                 :          0 :     camellia_feistel(KC + 10, SIGMA[3], KC + 8);
+     358                 :            : 
+     359         [ #  # ]:          0 :     if (keybits > 128) {
+     360                 :            :         /* Generate KB */
+     361         [ #  # ]:          0 :         for (i = 0; i < 4; ++i) {
+     362                 :          0 :             KC[12 + i] = KC[4 + i] ^ KC[8 + i];
+     363                 :            :         }
+     364                 :            : 
+     365                 :          0 :         camellia_feistel(KC + 12, SIGMA[4], KC + 14);
+     366                 :          0 :         camellia_feistel(KC + 14, SIGMA[5], KC + 12);
+     367                 :            :     }
+     368                 :            : 
+     369                 :            :     /*
+     370                 :            :      * Generating subkeys
+     371                 :            :      */
+     372                 :            : 
+     373                 :            :     /* Manipulating KL */
+     374   [ #  #  #  #  :          0 :     SHIFT_AND_PLACE(idx, 0);
+             #  #  #  # ]
+     375                 :            : 
+     376                 :            :     /* Manipulating KR */
+     377         [ #  # ]:          0 :     if (keybits > 128) {
+     378   [ #  #  #  #  :          0 :         SHIFT_AND_PLACE(idx, 1);
+             #  #  #  # ]
+     379                 :            :     }
+     380                 :            : 
+     381                 :            :     /* Manipulating KA */
+     382   [ #  #  #  #  :          0 :     SHIFT_AND_PLACE(idx, 2);
+             #  #  #  # ]
+     383                 :            : 
+     384                 :            :     /* Manipulating KB */
+     385         [ #  # ]:          0 :     if (keybits > 128) {
+     386   [ #  #  #  #  :          0 :         SHIFT_AND_PLACE(idx, 3);
+             #  #  #  # ]
+     387                 :            :     }
+     388                 :            : 
+     389                 :            :     /* Do transpositions */
+     390         [ #  # ]:          0 :     for (i = 0; i < 20; i++) {
+     391         [ #  # ]:          0 :         if (transposes[idx][i] != -1) {
+     392                 :          0 :             RK[32 + 12 * idx + i] = RK[transposes[idx][i]];
+     393                 :            :         }
+     394                 :            :     }
+     395                 :            : 
+     396                 :          0 :     return 0;
+     397                 :            : }
+     398                 :            : 
+     399                 :            : /*
+     400                 :            :  * Camellia key schedule (decryption)
+     401                 :            :  */
+     402                 :            : #if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
+     403                 :          0 : int mbedtls_camellia_setkey_dec(mbedtls_camellia_context *ctx,
+     404                 :            :                                 const unsigned char *key,
+     405                 :            :                                 unsigned int keybits)
+     406                 :            : {
+     407                 :            :     int idx, ret;
+     408                 :            :     size_t i;
+     409                 :            :     mbedtls_camellia_context cty;
+     410                 :            :     uint32_t *RK;
+     411                 :            :     uint32_t *SK;
+     412                 :            : 
+     413                 :          0 :     mbedtls_camellia_init(&cty);
+     414                 :            : 
+     415                 :            :     /* Also checks keybits */
+     416         [ #  # ]:          0 :     if ((ret = mbedtls_camellia_setkey_enc(&cty, key, keybits)) != 0) {
+     417                 :          0 :         goto exit;
+     418                 :            :     }
+     419                 :            : 
+     420                 :          0 :     ctx->nr = cty.nr;
+     421                 :          0 :     idx = (ctx->nr == 4);
+     422                 :            : 
+     423                 :          0 :     RK = ctx->rk;
+     424                 :          0 :     SK = cty.rk + 24 * 2 + 8 * idx * 2;
+     425                 :            : 
+     426                 :          0 :     *RK++ = *SK++;
+     427                 :          0 :     *RK++ = *SK++;
+     428                 :          0 :     *RK++ = *SK++;
+     429                 :          0 :     *RK++ = *SK++;
+     430                 :            : 
+     431         [ #  # ]:          0 :     for (i = 22 + 8 * idx, SK -= 6; i > 0; i--, SK -= 4) {
+     432                 :          0 :         *RK++ = *SK++;
+     433                 :          0 :         *RK++ = *SK++;
+     434                 :            :     }
+     435                 :            : 
+     436                 :          0 :     SK -= 2;
+     437                 :            : 
+     438                 :          0 :     *RK++ = *SK++;
+     439                 :          0 :     *RK++ = *SK++;
+     440                 :          0 :     *RK++ = *SK++;
+     441                 :          0 :     *RK++ = *SK++;
+     442                 :            : 
+     443                 :          0 : exit:
+     444                 :          0 :     mbedtls_camellia_free(&cty);
+     445                 :            : 
+     446                 :          0 :     return ret;
+     447                 :            : }
+     448                 :            : #endif /* !MBEDTLS_BLOCK_CIPHER_NO_DECRYPT */
+     449                 :            : 
+     450                 :            : /*
+     451                 :            :  * Camellia-ECB block encryption/decryption
+     452                 :            :  */
+     453                 :          0 : int mbedtls_camellia_crypt_ecb(mbedtls_camellia_context *ctx,
+     454                 :            :                                int mode,
+     455                 :            :                                const unsigned char input[16],
+     456                 :            :                                unsigned char output[16])
+     457                 :            : {
+     458                 :            :     int NR;
+     459                 :            :     uint32_t *RK, X[4];
+     460   [ #  #  #  # ]:          0 :     if (mode != MBEDTLS_CAMELLIA_ENCRYPT && mode != MBEDTLS_CAMELLIA_DECRYPT) {
+     461                 :          0 :         return MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA;
+     462                 :            :     }
+     463                 :            : 
+     464                 :            :     ((void) mode);
+     465                 :            : 
+     466                 :          0 :     NR = ctx->nr;
+     467                 :          0 :     RK = ctx->rk;
+     468                 :            : 
+     469                 :          0 :     X[0] = MBEDTLS_GET_UINT32_BE(input,  0);
+     470                 :          0 :     X[1] = MBEDTLS_GET_UINT32_BE(input,  4);
+     471                 :          0 :     X[2] = MBEDTLS_GET_UINT32_BE(input,  8);
+     472                 :          0 :     X[3] = MBEDTLS_GET_UINT32_BE(input, 12);
+     473                 :            : 
+     474                 :          0 :     X[0] ^= *RK++;
+     475                 :          0 :     X[1] ^= *RK++;
+     476                 :          0 :     X[2] ^= *RK++;
+     477                 :          0 :     X[3] ^= *RK++;
+     478                 :            : 
+     479         [ #  # ]:          0 :     while (NR) {
+     480                 :          0 :         --NR;
+     481                 :          0 :         camellia_feistel(X, RK, X + 2);
+     482                 :          0 :         RK += 2;
+     483                 :          0 :         camellia_feistel(X + 2, RK, X);
+     484                 :          0 :         RK += 2;
+     485                 :          0 :         camellia_feistel(X, RK, X + 2);
+     486                 :          0 :         RK += 2;
+     487                 :          0 :         camellia_feistel(X + 2, RK, X);
+     488                 :          0 :         RK += 2;
+     489                 :          0 :         camellia_feistel(X, RK, X + 2);
+     490                 :          0 :         RK += 2;
+     491                 :          0 :         camellia_feistel(X + 2, RK, X);
+     492                 :          0 :         RK += 2;
+     493                 :            : 
+     494         [ #  # ]:          0 :         if (NR) {
+     495                 :          0 :             FL(X[0], X[1], RK[0], RK[1]);
+     496                 :          0 :             RK += 2;
+     497                 :          0 :             FLInv(X[2], X[3], RK[0], RK[1]);
+     498                 :          0 :             RK += 2;
+     499                 :            :         }
+     500                 :            :     }
+     501                 :            : 
+     502                 :          0 :     X[2] ^= *RK++;
+     503                 :          0 :     X[3] ^= *RK++;
+     504                 :          0 :     X[0] ^= *RK++;
+     505                 :          0 :     X[1] ^= *RK++;
+     506                 :            : 
+     507                 :          0 :     MBEDTLS_PUT_UINT32_BE(X[2], output,  0);
+     508                 :          0 :     MBEDTLS_PUT_UINT32_BE(X[3], output,  4);
+     509                 :          0 :     MBEDTLS_PUT_UINT32_BE(X[0], output,  8);
+     510                 :          0 :     MBEDTLS_PUT_UINT32_BE(X[1], output, 12);
+     511                 :            : 
+     512                 :          0 :     return 0;
+     513                 :            : }
+     514                 :            : 
+     515                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+     516                 :            : /*
+     517                 :            :  * Camellia-CBC buffer encryption/decryption
+     518                 :            :  */
+     519                 :          0 : int mbedtls_camellia_crypt_cbc(mbedtls_camellia_context *ctx,
+     520                 :            :                                int mode,
+     521                 :            :                                size_t length,
+     522                 :            :                                unsigned char iv[16],
+     523                 :            :                                const unsigned char *input,
+     524                 :            :                                unsigned char *output)
+     525                 :            : {
+     526                 :            :     unsigned char temp[16];
+     527   [ #  #  #  # ]:          0 :     if (mode != MBEDTLS_CAMELLIA_ENCRYPT && mode != MBEDTLS_CAMELLIA_DECRYPT) {
+     528                 :          0 :         return MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA;
+     529                 :            :     }
+     530                 :            : 
+     531         [ #  # ]:          0 :     if (length % 16) {
+     532                 :          0 :         return MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH;
+     533                 :            :     }
+     534                 :            : 
+     535         [ #  # ]:          0 :     if (mode == MBEDTLS_CAMELLIA_DECRYPT) {
+     536         [ #  # ]:          0 :         while (length > 0) {
+     537                 :          0 :             memcpy(temp, input, 16);
+     538                 :          0 :             mbedtls_camellia_crypt_ecb(ctx, mode, input, output);
+     539                 :            : 
+     540                 :            :             mbedtls_xor(output, output, iv, 16);
+     541                 :            : 
+     542                 :          0 :             memcpy(iv, temp, 16);
+     543                 :            : 
+     544                 :          0 :             input  += 16;
+     545                 :          0 :             output += 16;
+     546                 :          0 :             length -= 16;
+     547                 :            :         }
+     548                 :            :     } else {
+     549         [ #  # ]:          0 :         while (length > 0) {
+     550                 :            :             mbedtls_xor(output, input, iv, 16);
+     551                 :            : 
+     552                 :          0 :             mbedtls_camellia_crypt_ecb(ctx, mode, output, output);
+     553                 :          0 :             memcpy(iv, output, 16);
+     554                 :            : 
+     555                 :          0 :             input  += 16;
+     556                 :          0 :             output += 16;
+     557                 :          0 :             length -= 16;
+     558                 :            :         }
+     559                 :            :     }
+     560                 :            : 
+     561                 :          0 :     return 0;
+     562                 :            : }
+     563                 :            : #endif /* MBEDTLS_CIPHER_MODE_CBC */
+     564                 :            : 
+     565                 :            : #if defined(MBEDTLS_CIPHER_MODE_CFB)
+     566                 :            : /*
+     567                 :            :  * Camellia-CFB128 buffer encryption/decryption
+     568                 :            :  */
+     569                 :          0 : int mbedtls_camellia_crypt_cfb128(mbedtls_camellia_context *ctx,
+     570                 :            :                                   int mode,
+     571                 :            :                                   size_t length,
+     572                 :            :                                   size_t *iv_off,
+     573                 :            :                                   unsigned char iv[16],
+     574                 :            :                                   const unsigned char *input,
+     575                 :            :                                   unsigned char *output)
+     576                 :            : {
+     577                 :            :     int c;
+     578                 :            :     size_t n;
+     579   [ #  #  #  # ]:          0 :     if (mode != MBEDTLS_CAMELLIA_ENCRYPT && mode != MBEDTLS_CAMELLIA_DECRYPT) {
+     580                 :          0 :         return MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA;
+     581                 :            :     }
+     582                 :            : 
+     583                 :          0 :     n = *iv_off;
+     584         [ #  # ]:          0 :     if (n >= 16) {
+     585                 :          0 :         return MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA;
+     586                 :            :     }
+     587                 :            : 
+     588         [ #  # ]:          0 :     if (mode == MBEDTLS_CAMELLIA_DECRYPT) {
+     589         [ #  # ]:          0 :         while (length--) {
+     590         [ #  # ]:          0 :             if (n == 0) {
+     591                 :          0 :                 mbedtls_camellia_crypt_ecb(ctx, MBEDTLS_CAMELLIA_ENCRYPT, iv, iv);
+     592                 :            :             }
+     593                 :            : 
+     594                 :          0 :             c = *input++;
+     595                 :          0 :             *output++ = (unsigned char) (c ^ iv[n]);
+     596                 :          0 :             iv[n] = (unsigned char) c;
+     597                 :            : 
+     598                 :          0 :             n = (n + 1) & 0x0F;
+     599                 :            :         }
+     600                 :            :     } else {
+     601         [ #  # ]:          0 :         while (length--) {
+     602         [ #  # ]:          0 :             if (n == 0) {
+     603                 :          0 :                 mbedtls_camellia_crypt_ecb(ctx, MBEDTLS_CAMELLIA_ENCRYPT, iv, iv);
+     604                 :            :             }
+     605                 :            : 
+     606                 :          0 :             iv[n] = *output++ = (unsigned char) (iv[n] ^ *input++);
+     607                 :            : 
+     608                 :          0 :             n = (n + 1) & 0x0F;
+     609                 :            :         }
+     610                 :            :     }
+     611                 :            : 
+     612                 :          0 :     *iv_off = n;
+     613                 :            : 
+     614                 :          0 :     return 0;
+     615                 :            : }
+     616                 :            : #endif /* MBEDTLS_CIPHER_MODE_CFB */
+     617                 :            : 
+     618                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR)
+     619                 :            : /*
+     620                 :            :  * Camellia-CTR buffer encryption/decryption
+     621                 :            :  */
+     622                 :          0 : int mbedtls_camellia_crypt_ctr(mbedtls_camellia_context *ctx,
+     623                 :            :                                size_t length,
+     624                 :            :                                size_t *nc_off,
+     625                 :            :                                unsigned char nonce_counter[16],
+     626                 :            :                                unsigned char stream_block[16],
+     627                 :            :                                const unsigned char *input,
+     628                 :            :                                unsigned char *output)
+     629                 :            : {
+     630                 :            :     int c, i;
+     631                 :            :     size_t n;
+     632                 :            : 
+     633                 :          0 :     n = *nc_off;
+     634         [ #  # ]:          0 :     if (n >= 16) {
+     635                 :          0 :         return MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA;
+     636                 :            :     }
+     637                 :            : 
+     638         [ #  # ]:          0 :     while (length--) {
+     639         [ #  # ]:          0 :         if (n == 0) {
+     640                 :          0 :             mbedtls_camellia_crypt_ecb(ctx, MBEDTLS_CAMELLIA_ENCRYPT, nonce_counter,
+     641                 :            :                                        stream_block);
+     642                 :            : 
+     643         [ #  # ]:          0 :             for (i = 16; i > 0; i--) {
+     644         [ #  # ]:          0 :                 if (++nonce_counter[i - 1] != 0) {
+     645                 :          0 :                     break;
+     646                 :            :                 }
+     647                 :            :             }
+     648                 :            :         }
+     649                 :          0 :         c = *input++;
+     650                 :          0 :         *output++ = (unsigned char) (c ^ stream_block[n]);
+     651                 :            : 
+     652                 :          0 :         n = (n + 1) & 0x0F;
+     653                 :            :     }
+     654                 :            : 
+     655                 :          0 :     *nc_off = n;
+     656                 :            : 
+     657                 :          0 :     return 0;
+     658                 :            : }
+     659                 :            : #endif /* MBEDTLS_CIPHER_MODE_CTR */
+     660                 :            : #endif /* !MBEDTLS_CAMELLIA_ALT */
+     661                 :            : 
+     662                 :            : #if defined(MBEDTLS_SELF_TEST)
+     663                 :            : 
+     664                 :            : /*
+     665                 :            :  * Camellia test vectors from:
+     666                 :            :  *
+     667                 :            :  * http://info.isl.ntt.co.jp/crypt/eng/camellia/technology.html:
+     668                 :            :  *   http://info.isl.ntt.co.jp/crypt/eng/camellia/dl/cryptrec/intermediate.txt
+     669                 :            :  *   http://info.isl.ntt.co.jp/crypt/eng/camellia/dl/cryptrec/t_camellia.txt
+     670                 :            :  *                      (For each bitlength: Key 0, Nr 39)
+     671                 :            :  */
+     672                 :            : #define CAMELLIA_TESTS_ECB  2
+     673                 :            : 
+     674                 :            : static const unsigned char camellia_test_ecb_key[3][CAMELLIA_TESTS_ECB][32] =
+     675                 :            : {
+     676                 :            :     {
+     677                 :            :         { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
+     678                 :            :           0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 },
+     679                 :            :         { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+     680                 :            :           0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
+     681                 :            :     },
+     682                 :            :     {
+     683                 :            :         { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
+     684                 :            :           0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
+     685                 :            :           0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 },
+     686                 :            :         { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+     687                 :            :           0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+     688                 :            :           0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
+     689                 :            :     },
+     690                 :            :     {
+     691                 :            :         { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
+     692                 :            :           0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
+     693                 :            :           0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
+     694                 :            :           0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff },
+     695                 :            :         { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+     696                 :            :           0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+     697                 :            :           0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+     698                 :            :           0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
+     699                 :            :     },
+     700                 :            : };
+     701                 :            : 
+     702                 :            : static const unsigned char camellia_test_ecb_plain[CAMELLIA_TESTS_ECB][16] =
+     703                 :            : {
+     704                 :            :     { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
+     705                 :            :       0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 },
+     706                 :            :     { 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
+     707                 :            :       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
+     708                 :            : };
+     709                 :            : 
+     710                 :            : static const unsigned char camellia_test_ecb_cipher[3][CAMELLIA_TESTS_ECB][16] =
+     711                 :            : {
+     712                 :            :     {
+     713                 :            :         { 0x67, 0x67, 0x31, 0x38, 0x54, 0x96, 0x69, 0x73,
+     714                 :            :           0x08, 0x57, 0x06, 0x56, 0x48, 0xea, 0xbe, 0x43 },
+     715                 :            :         { 0x38, 0x3C, 0x6C, 0x2A, 0xAB, 0xEF, 0x7F, 0xDE,
+     716                 :            :           0x25, 0xCD, 0x47, 0x0B, 0xF7, 0x74, 0xA3, 0x31 }
+     717                 :            :     },
+     718                 :            :     {
+     719                 :            :         { 0xb4, 0x99, 0x34, 0x01, 0xb3, 0xe9, 0x96, 0xf8,
+     720                 :            :           0x4e, 0xe5, 0xce, 0xe7, 0xd7, 0x9b, 0x09, 0xb9 },
+     721                 :            :         { 0xD1, 0x76, 0x3F, 0xC0, 0x19, 0xD7, 0x7C, 0xC9,
+     722                 :            :           0x30, 0xBF, 0xF2, 0xA5, 0x6F, 0x7C, 0x93, 0x64 }
+     723                 :            :     },
+     724                 :            :     {
+     725                 :            :         { 0x9a, 0xcc, 0x23, 0x7d, 0xff, 0x16, 0xd7, 0x6c,
+     726                 :            :           0x20, 0xef, 0x7c, 0x91, 0x9e, 0x3a, 0x75, 0x09 },
+     727                 :            :         { 0x05, 0x03, 0xFB, 0x10, 0xAB, 0x24, 0x1E, 0x7C,
+     728                 :            :           0xF4, 0x5D, 0x8C, 0xDE, 0xEE, 0x47, 0x43, 0x35 }
+     729                 :            :     }
+     730                 :            : };
+     731                 :            : 
+     732                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+     733                 :            : #define CAMELLIA_TESTS_CBC  3
+     734                 :            : 
+     735                 :            : static const unsigned char camellia_test_cbc_key[3][32] =
+     736                 :            : {
+     737                 :            :     { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6,
+     738                 :            :       0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C }
+     739                 :            :     ,
+     740                 :            :     { 0x8E, 0x73, 0xB0, 0xF7, 0xDA, 0x0E, 0x64, 0x52,
+     741                 :            :       0xC8, 0x10, 0xF3, 0x2B, 0x80, 0x90, 0x79, 0xE5,
+     742                 :            :       0x62, 0xF8, 0xEA, 0xD2, 0x52, 0x2C, 0x6B, 0x7B }
+     743                 :            :     ,
+     744                 :            :     { 0x60, 0x3D, 0xEB, 0x10, 0x15, 0xCA, 0x71, 0xBE,
+     745                 :            :       0x2B, 0x73, 0xAE, 0xF0, 0x85, 0x7D, 0x77, 0x81,
+     746                 :            :       0x1F, 0x35, 0x2C, 0x07, 0x3B, 0x61, 0x08, 0xD7,
+     747                 :            :       0x2D, 0x98, 0x10, 0xA3, 0x09, 0x14, 0xDF, 0xF4 }
+     748                 :            : };
+     749                 :            : 
+     750                 :            : static const unsigned char camellia_test_cbc_iv[16] =
+     751                 :            : 
+     752                 :            : { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+     753                 :            :   0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F }
+     754                 :            : ;
+     755                 :            : 
+     756                 :            : static const unsigned char camellia_test_cbc_plain[CAMELLIA_TESTS_CBC][16] =
+     757                 :            : {
+     758                 :            :     { 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
+     759                 :            :       0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A },
+     760                 :            :     { 0xAE, 0x2D, 0x8A, 0x57, 0x1E, 0x03, 0xAC, 0x9C,
+     761                 :            :       0x9E, 0xB7, 0x6F, 0xAC, 0x45, 0xAF, 0x8E, 0x51 },
+     762                 :            :     { 0x30, 0xC8, 0x1C, 0x46, 0xA3, 0x5C, 0xE4, 0x11,
+     763                 :            :       0xE5, 0xFB, 0xC1, 0x19, 0x1A, 0x0A, 0x52, 0xEF }
+     764                 :            : 
+     765                 :            : };
+     766                 :            : 
+     767                 :            : static const unsigned char camellia_test_cbc_cipher[3][CAMELLIA_TESTS_CBC][16] =
+     768                 :            : {
+     769                 :            :     {
+     770                 :            :         { 0x16, 0x07, 0xCF, 0x49, 0x4B, 0x36, 0xBB, 0xF0,
+     771                 :            :           0x0D, 0xAE, 0xB0, 0xB5, 0x03, 0xC8, 0x31, 0xAB },
+     772                 :            :         { 0xA2, 0xF2, 0xCF, 0x67, 0x16, 0x29, 0xEF, 0x78,
+     773                 :            :           0x40, 0xC5, 0xA5, 0xDF, 0xB5, 0x07, 0x48, 0x87 },
+     774                 :            :         { 0x0F, 0x06, 0x16, 0x50, 0x08, 0xCF, 0x8B, 0x8B,
+     775                 :            :           0x5A, 0x63, 0x58, 0x63, 0x62, 0x54, 0x3E, 0x54 }
+     776                 :            :     },
+     777                 :            :     {
+     778                 :            :         { 0x2A, 0x48, 0x30, 0xAB, 0x5A, 0xC4, 0xA1, 0xA2,
+     779                 :            :           0x40, 0x59, 0x55, 0xFD, 0x21, 0x95, 0xCF, 0x93 },
+     780                 :            :         { 0x5D, 0x5A, 0x86, 0x9B, 0xD1, 0x4C, 0xE5, 0x42,
+     781                 :            :           0x64, 0xF8, 0x92, 0xA6, 0xDD, 0x2E, 0xC3, 0xD5 },
+     782                 :            :         { 0x37, 0xD3, 0x59, 0xC3, 0x34, 0x98, 0x36, 0xD8,
+     783                 :            :           0x84, 0xE3, 0x10, 0xAD, 0xDF, 0x68, 0xC4, 0x49 }
+     784                 :            :     },
+     785                 :            :     {
+     786                 :            :         { 0xE6, 0xCF, 0xA3, 0x5F, 0xC0, 0x2B, 0x13, 0x4A,
+     787                 :            :           0x4D, 0x2C, 0x0B, 0x67, 0x37, 0xAC, 0x3E, 0xDA },
+     788                 :            :         { 0x36, 0xCB, 0xEB, 0x73, 0xBD, 0x50, 0x4B, 0x40,
+     789                 :            :           0x70, 0xB1, 0xB7, 0xDE, 0x2B, 0x21, 0xEB, 0x50 },
+     790                 :            :         { 0xE3, 0x1A, 0x60, 0x55, 0x29, 0x7D, 0x96, 0xCA,
+     791                 :            :           0x33, 0x30, 0xCD, 0xF1, 0xB1, 0x86, 0x0A, 0x83 }
+     792                 :            :     }
+     793                 :            : };
+     794                 :            : #endif /* MBEDTLS_CIPHER_MODE_CBC */
+     795                 :            : 
+     796                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR)
+     797                 :            : /*
+     798                 :            :  * Camellia-CTR test vectors from:
+     799                 :            :  *
+     800                 :            :  * http://www.faqs.org/rfcs/rfc5528.html
+     801                 :            :  */
+     802                 :            : 
+     803                 :            : static const unsigned char camellia_test_ctr_key[3][16] =
+     804                 :            : {
+     805                 :            :     { 0xAE, 0x68, 0x52, 0xF8, 0x12, 0x10, 0x67, 0xCC,
+     806                 :            :       0x4B, 0xF7, 0xA5, 0x76, 0x55, 0x77, 0xF3, 0x9E },
+     807                 :            :     { 0x7E, 0x24, 0x06, 0x78, 0x17, 0xFA, 0xE0, 0xD7,
+     808                 :            :       0x43, 0xD6, 0xCE, 0x1F, 0x32, 0x53, 0x91, 0x63 },
+     809                 :            :     { 0x76, 0x91, 0xBE, 0x03, 0x5E, 0x50, 0x20, 0xA8,
+     810                 :            :       0xAC, 0x6E, 0x61, 0x85, 0x29, 0xF9, 0xA0, 0xDC }
+     811                 :            : };
+     812                 :            : 
+     813                 :            : static const unsigned char camellia_test_ctr_nonce_counter[3][16] =
+     814                 :            : {
+     815                 :            :     { 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00,
+     816                 :            :       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 },
+     817                 :            :     { 0x00, 0x6C, 0xB6, 0xDB, 0xC0, 0x54, 0x3B, 0x59,
+     818                 :            :       0xDA, 0x48, 0xD9, 0x0B, 0x00, 0x00, 0x00, 0x01 },
+     819                 :            :     { 0x00, 0xE0, 0x01, 0x7B, 0x27, 0x77, 0x7F, 0x3F,
+     820                 :            :       0x4A, 0x17, 0x86, 0xF0, 0x00, 0x00, 0x00, 0x01 }
+     821                 :            : };
+     822                 :            : 
+     823                 :            : static const unsigned char camellia_test_ctr_pt[3][48] =
+     824                 :            : {
+     825                 :            :     { 0x53, 0x69, 0x6E, 0x67, 0x6C, 0x65, 0x20, 0x62,
+     826                 :            :       0x6C, 0x6F, 0x63, 0x6B, 0x20, 0x6D, 0x73, 0x67 },
+     827                 :            : 
+     828                 :            :     { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+     829                 :            :       0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
+     830                 :            :       0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+     831                 :            :       0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F },
+     832                 :            : 
+     833                 :            :     { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+     834                 :            :       0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
+     835                 :            :       0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+     836                 :            :       0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
+     837                 :            :       0x20, 0x21, 0x22, 0x23 }
+     838                 :            : };
+     839                 :            : 
+     840                 :            : static const unsigned char camellia_test_ctr_ct[3][48] =
+     841                 :            : {
+     842                 :            :     { 0xD0, 0x9D, 0xC2, 0x9A, 0x82, 0x14, 0x61, 0x9A,
+     843                 :            :       0x20, 0x87, 0x7C, 0x76, 0xDB, 0x1F, 0x0B, 0x3F },
+     844                 :            :     { 0xDB, 0xF3, 0xC7, 0x8D, 0xC0, 0x83, 0x96, 0xD4,
+     845                 :            :       0xDA, 0x7C, 0x90, 0x77, 0x65, 0xBB, 0xCB, 0x44,
+     846                 :            :       0x2B, 0x8E, 0x8E, 0x0F, 0x31, 0xF0, 0xDC, 0xA7,
+     847                 :            :       0x2C, 0x74, 0x17, 0xE3, 0x53, 0x60, 0xE0, 0x48 },
+     848                 :            :     { 0xB1, 0x9D, 0x1F, 0xCD, 0xCB, 0x75, 0xEB, 0x88,
+     849                 :            :       0x2F, 0x84, 0x9C, 0xE2, 0x4D, 0x85, 0xCF, 0x73,
+     850                 :            :       0x9C, 0xE6, 0x4B, 0x2B, 0x5C, 0x9D, 0x73, 0xF1,
+     851                 :            :       0x4F, 0x2D, 0x5D, 0x9D, 0xCE, 0x98, 0x89, 0xCD,
+     852                 :            :       0xDF, 0x50, 0x86, 0x96 }
+     853                 :            : };
+     854                 :            : 
+     855                 :            : static const int camellia_test_ctr_len[3] =
+     856                 :            : { 16, 32, 36 };
+     857                 :            : #endif /* MBEDTLS_CIPHER_MODE_CTR */
+     858                 :            : 
+     859                 :            : /*
+     860                 :            :  * Checkup routine
+     861                 :            :  */
+     862                 :          0 : int mbedtls_camellia_self_test(int verbose)
+     863                 :            : {
+     864                 :            :     int i, j, u, v;
+     865                 :            :     unsigned char key[32];
+     866                 :            :     unsigned char buf[64];
+     867                 :            :     unsigned char src[16];
+     868                 :            :     unsigned char dst[16];
+     869                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+     870                 :            :     unsigned char iv[16];
+     871                 :            : #endif
+     872                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR)
+     873                 :            :     size_t offset, len;
+     874                 :            :     unsigned char nonce_counter[16];
+     875                 :            :     unsigned char stream_block[16];
+     876                 :            : #endif
+     877                 :          0 :     int ret = 1;
+     878                 :            : 
+     879                 :            :     mbedtls_camellia_context ctx;
+     880                 :            : 
+     881                 :          0 :     mbedtls_camellia_init(&ctx);
+     882                 :          0 :     memset(key, 0, 32);
+     883                 :            : 
+     884         [ #  # ]:          0 :     for (j = 0; j < 6; j++) {
+     885                 :          0 :         u = j >> 1;
+     886                 :          0 :         v = j & 1;
+     887                 :            : 
+     888         [ #  # ]:          0 :         if (verbose != 0) {
+     889         [ #  # ]:          0 :             mbedtls_printf("  CAMELLIA-ECB-%3d (%s): ", 128 + u * 64,
+     890                 :            :                            (v == MBEDTLS_CAMELLIA_DECRYPT) ? "dec" : "enc");
+     891                 :            :         }
+     892                 :            : 
+     893                 :            : #if defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
+     894                 :            :         if (v == MBEDTLS_CAMELLIA_DECRYPT) {
+     895                 :            :             if (verbose != 0) {
+     896                 :            :                 mbedtls_printf("skipped\n");
+     897                 :            :             }
+     898                 :            :             continue;
+     899                 :            :         }
+     900                 :            : #endif
+     901                 :            : 
+     902         [ #  # ]:          0 :         for (i = 0; i < CAMELLIA_TESTS_ECB; i++) {
+     903                 :          0 :             memcpy(key, camellia_test_ecb_key[u][i], 16 + 8 * u);
+     904                 :            : 
+     905                 :            : #if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
+     906         [ #  # ]:          0 :             if (v == MBEDTLS_CAMELLIA_DECRYPT) {
+     907                 :          0 :                 mbedtls_camellia_setkey_dec(&ctx, key, 128 + u * 64);
+     908                 :          0 :                 memcpy(src, camellia_test_ecb_cipher[u][i], 16);
+     909                 :          0 :                 memcpy(dst, camellia_test_ecb_plain[i], 16);
+     910                 :            :             } else
+     911                 :            : #endif
+     912                 :            :             { /* MBEDTLS_CAMELLIA_ENCRYPT */
+     913                 :          0 :                 mbedtls_camellia_setkey_enc(&ctx, key, 128 + u * 64);
+     914                 :          0 :                 memcpy(src, camellia_test_ecb_plain[i], 16);
+     915                 :          0 :                 memcpy(dst, camellia_test_ecb_cipher[u][i], 16);
+     916                 :            :             }
+     917                 :            : 
+     918                 :          0 :             mbedtls_camellia_crypt_ecb(&ctx, v, src, buf);
+     919                 :            : 
+     920         [ #  # ]:          0 :             if (memcmp(buf, dst, 16) != 0) {
+     921         [ #  # ]:          0 :                 if (verbose != 0) {
+     922                 :          0 :                     mbedtls_printf("failed\n");
+     923                 :            :                 }
+     924                 :          0 :                 goto exit;
+     925                 :            :             }
+     926                 :            :         }
+     927                 :            : 
+     928         [ #  # ]:          0 :         if (verbose != 0) {
+     929                 :          0 :             mbedtls_printf("passed\n");
+     930                 :            :         }
+     931                 :            :     }
+     932                 :            : 
+     933         [ #  # ]:          0 :     if (verbose != 0) {
+     934                 :          0 :         mbedtls_printf("\n");
+     935                 :            :     }
+     936                 :            : 
+     937                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+     938                 :            :     /*
+     939                 :            :      * CBC mode
+     940                 :            :      */
+     941         [ #  # ]:          0 :     for (j = 0; j < 6; j++) {
+     942                 :          0 :         u = j >> 1;
+     943                 :          0 :         v = j  & 1;
+     944                 :            : 
+     945         [ #  # ]:          0 :         if (verbose != 0) {
+     946         [ #  # ]:          0 :             mbedtls_printf("  CAMELLIA-CBC-%3d (%s): ", 128 + u * 64,
+     947                 :            :                            (v == MBEDTLS_CAMELLIA_DECRYPT) ? "dec" : "enc");
+     948                 :            :         }
+     949                 :            : 
+     950                 :          0 :         memcpy(src, camellia_test_cbc_iv, 16);
+     951                 :          0 :         memcpy(dst, camellia_test_cbc_iv, 16);
+     952                 :          0 :         memcpy(key, camellia_test_cbc_key[u], 16 + 8 * u);
+     953                 :            : 
+     954         [ #  # ]:          0 :         if (v == MBEDTLS_CAMELLIA_DECRYPT) {
+     955                 :          0 :             mbedtls_camellia_setkey_dec(&ctx, key, 128 + u * 64);
+     956                 :            :         } else {
+     957                 :          0 :             mbedtls_camellia_setkey_enc(&ctx, key, 128 + u * 64);
+     958                 :            :         }
+     959                 :            : 
+     960         [ #  # ]:          0 :         for (i = 0; i < CAMELLIA_TESTS_CBC; i++) {
+     961                 :            : 
+     962         [ #  # ]:          0 :             if (v == MBEDTLS_CAMELLIA_DECRYPT) {
+     963                 :          0 :                 memcpy(iv, src, 16);
+     964                 :          0 :                 memcpy(src, camellia_test_cbc_cipher[u][i], 16);
+     965                 :          0 :                 memcpy(dst, camellia_test_cbc_plain[i], 16);
+     966                 :            :             } else { /* MBEDTLS_CAMELLIA_ENCRYPT */
+     967                 :          0 :                 memcpy(iv, dst, 16);
+     968                 :          0 :                 memcpy(src, camellia_test_cbc_plain[i], 16);
+     969                 :          0 :                 memcpy(dst, camellia_test_cbc_cipher[u][i], 16);
+     970                 :            :             }
+     971                 :            : 
+     972                 :          0 :             mbedtls_camellia_crypt_cbc(&ctx, v, 16, iv, src, buf);
+     973                 :            : 
+     974         [ #  # ]:          0 :             if (memcmp(buf, dst, 16) != 0) {
+     975         [ #  # ]:          0 :                 if (verbose != 0) {
+     976                 :          0 :                     mbedtls_printf("failed\n");
+     977                 :            :                 }
+     978                 :          0 :                 goto exit;
+     979                 :            :             }
+     980                 :            :         }
+     981                 :            : 
+     982         [ #  # ]:          0 :         if (verbose != 0) {
+     983                 :          0 :             mbedtls_printf("passed\n");
+     984                 :            :         }
+     985                 :            :     }
+     986                 :            : #endif /* MBEDTLS_CIPHER_MODE_CBC */
+     987                 :            : 
+     988         [ #  # ]:          0 :     if (verbose != 0) {
+     989                 :          0 :         mbedtls_printf("\n");
+     990                 :            :     }
+     991                 :            : 
+     992                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR)
+     993                 :            :     /*
+     994                 :            :      * CTR mode
+     995                 :            :      */
+     996         [ #  # ]:          0 :     for (i = 0; i < 6; i++) {
+     997                 :          0 :         u = i >> 1;
+     998                 :          0 :         v = i  & 1;
+     999                 :            : 
+    1000         [ #  # ]:          0 :         if (verbose != 0) {
+    1001         [ #  # ]:          0 :             mbedtls_printf("  CAMELLIA-CTR-128 (%s): ",
+    1002                 :            :                            (v == MBEDTLS_CAMELLIA_DECRYPT) ? "dec" : "enc");
+    1003                 :            :         }
+    1004                 :            : 
+    1005                 :          0 :         memcpy(nonce_counter, camellia_test_ctr_nonce_counter[u], 16);
+    1006                 :          0 :         memcpy(key, camellia_test_ctr_key[u], 16);
+    1007                 :            : 
+    1008                 :          0 :         offset = 0;
+    1009                 :          0 :         mbedtls_camellia_setkey_enc(&ctx, key, 128);
+    1010                 :            : 
+    1011         [ #  # ]:          0 :         if (v == MBEDTLS_CAMELLIA_DECRYPT) {
+    1012                 :          0 :             len = camellia_test_ctr_len[u];
+    1013                 :          0 :             memcpy(buf, camellia_test_ctr_ct[u], len);
+    1014                 :            : 
+    1015                 :          0 :             mbedtls_camellia_crypt_ctr(&ctx, len, &offset, nonce_counter, stream_block,
+    1016                 :            :                                        buf, buf);
+    1017                 :            : 
+    1018         [ #  # ]:          0 :             if (memcmp(buf, camellia_test_ctr_pt[u], len) != 0) {
+    1019         [ #  # ]:          0 :                 if (verbose != 0) {
+    1020                 :          0 :                     mbedtls_printf("failed\n");
+    1021                 :            :                 }
+    1022                 :          0 :                 goto exit;
+    1023                 :            :             }
+    1024                 :            :         } else {
+    1025                 :          0 :             len = camellia_test_ctr_len[u];
+    1026                 :          0 :             memcpy(buf, camellia_test_ctr_pt[u], len);
+    1027                 :            : 
+    1028                 :          0 :             mbedtls_camellia_crypt_ctr(&ctx, len, &offset, nonce_counter, stream_block,
+    1029                 :            :                                        buf, buf);
+    1030                 :            : 
+    1031         [ #  # ]:          0 :             if (memcmp(buf, camellia_test_ctr_ct[u], len) != 0) {
+    1032         [ #  # ]:          0 :                 if (verbose != 0) {
+    1033                 :          0 :                     mbedtls_printf("failed\n");
+    1034                 :            :                 }
+    1035                 :          0 :                 goto exit;
+    1036                 :            :             }
+    1037                 :            :         }
+    1038                 :            : 
+    1039         [ #  # ]:          0 :         if (verbose != 0) {
+    1040                 :          0 :             mbedtls_printf("passed\n");
+    1041                 :            :         }
+    1042                 :            :     }
+    1043                 :            : 
+    1044         [ #  # ]:          0 :     if (verbose != 0) {
+    1045                 :          0 :         mbedtls_printf("\n");
+    1046                 :            :     }
+    1047                 :            : #endif /* MBEDTLS_CIPHER_MODE_CTR */
+    1048                 :            : 
+    1049                 :          0 :     ret = 0;
+    1050                 :            : 
+    1051                 :          0 : exit:
+    1052                 :          0 :     mbedtls_camellia_free(&ctx);
+    1053                 :          0 :     return ret;
+    1054                 :            : }
+    1055                 :            : 
+    1056                 :            : #endif /* MBEDTLS_SELF_TEST */
+    1057                 :            : 
+    1058                 :            : #endif /* MBEDTLS_CAMELLIA_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/ccm.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ccm.c.func-sort-c.html new file mode 100644 index 00000000000..1cc9ba832b8 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ccm.c.func-sort-c.html @@ -0,0 +1,157 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/ccm.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - ccm.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:02570.0 %
Date:2024-09-22 08:21:07Functions:0190.0 %
Branches:01660.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
ccm_auth_crypt0
ccm_auth_decrypt0
ccm_calculate_first_block_if_ready0
mbedtls_ccm_auth_decrypt0
mbedtls_ccm_clear_state0
mbedtls_ccm_compare_tags0
mbedtls_ccm_crypt0
mbedtls_ccm_encrypt_and_tag0
mbedtls_ccm_finish0
mbedtls_ccm_free0
mbedtls_ccm_init0
mbedtls_ccm_self_test0
mbedtls_ccm_set_lengths0
mbedtls_ccm_setkey0
mbedtls_ccm_star_auth_decrypt0
mbedtls_ccm_star_encrypt_and_tag0
mbedtls_ccm_starts0
mbedtls_ccm_update0
mbedtls_ccm_update_ad0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/ccm.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ccm.c.func.html new file mode 100644 index 00000000000..d7b813980fb --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ccm.c.func.html @@ -0,0 +1,157 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/ccm.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - ccm.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:02570.0 %
Date:2024-09-22 08:21:07Functions:0190.0 %
Branches:01660.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
ccm_auth_crypt0
ccm_auth_decrypt0
ccm_calculate_first_block_if_ready0
mbedtls_ccm_auth_decrypt0
mbedtls_ccm_clear_state0
mbedtls_ccm_compare_tags0
mbedtls_ccm_crypt0
mbedtls_ccm_encrypt_and_tag0
mbedtls_ccm_finish0
mbedtls_ccm_free0
mbedtls_ccm_init0
mbedtls_ccm_self_test0
mbedtls_ccm_set_lengths0
mbedtls_ccm_setkey0
mbedtls_ccm_star_auth_decrypt0
mbedtls_ccm_star_encrypt_and_tag0
mbedtls_ccm_starts0
mbedtls_ccm_update0
mbedtls_ccm_update_ad0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/ccm.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ccm.c.gcov.html new file mode 100644 index 00000000000..1f152bee174 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ccm.c.gcov.html @@ -0,0 +1,849 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/ccm.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - ccm.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:02570.0 %
Date:2024-09-22 08:21:07Functions:0190.0 %
Branches:01660.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  *  NIST SP800-38C compliant CCM implementation
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  */
+       7                 :            : 
+       8                 :            : /*
+       9                 :            :  * Definition of CCM:
+      10                 :            :  * http://csrc.nist.gov/publications/nistpubs/800-38C/SP800-38C_updated-July20_2007.pdf
+      11                 :            :  * RFC 3610 "Counter with CBC-MAC (CCM)"
+      12                 :            :  *
+      13                 :            :  * Related:
+      14                 :            :  * RFC 5116 "An Interface and Algorithms for Authenticated Encryption"
+      15                 :            :  */
+      16                 :            : 
+      17                 :            : #include "common.h"
+      18                 :            : 
+      19                 :            : #if defined(MBEDTLS_CCM_C)
+      20                 :            : 
+      21                 :            : #include "mbedtls/ccm.h"
+      22                 :            : #include "mbedtls/platform_util.h"
+      23                 :            : #include "mbedtls/error.h"
+      24                 :            : #include "mbedtls/constant_time.h"
+      25                 :            : 
+      26                 :            : #if defined(MBEDTLS_BLOCK_CIPHER_C)
+      27                 :            : #include "block_cipher_internal.h"
+      28                 :            : #endif
+      29                 :            : 
+      30                 :            : #include <string.h>
+      31                 :            : 
+      32                 :            : #if defined(MBEDTLS_PLATFORM_C)
+      33                 :            : #include "mbedtls/platform.h"
+      34                 :            : #else
+      35                 :            : #if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C)
+      36                 :            : #include <stdio.h>
+      37                 :            : #define mbedtls_printf printf
+      38                 :            : #endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */
+      39                 :            : #endif /* MBEDTLS_PLATFORM_C */
+      40                 :            : 
+      41                 :            : #if !defined(MBEDTLS_CCM_ALT)
+      42                 :            : 
+      43                 :            : 
+      44                 :            : /*
+      45                 :            :  * Initialize context
+      46                 :            :  */
+      47                 :          0 : void mbedtls_ccm_init(mbedtls_ccm_context *ctx)
+      48                 :            : {
+      49                 :          0 :     memset(ctx, 0, sizeof(mbedtls_ccm_context));
+      50                 :          0 : }
+      51                 :            : 
+      52                 :          0 : int mbedtls_ccm_setkey(mbedtls_ccm_context *ctx,
+      53                 :            :                        mbedtls_cipher_id_t cipher,
+      54                 :            :                        const unsigned char *key,
+      55                 :            :                        unsigned int keybits)
+      56                 :            : {
+      57                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+      58                 :            : 
+      59                 :            : #if defined(MBEDTLS_BLOCK_CIPHER_C)
+      60                 :            :     mbedtls_block_cipher_free(&ctx->block_cipher_ctx);
+      61                 :            : 
+      62                 :            :     if ((ret = mbedtls_block_cipher_setup(&ctx->block_cipher_ctx, cipher)) != 0) {
+      63                 :            :         return MBEDTLS_ERR_CCM_BAD_INPUT;
+      64                 :            :     }
+      65                 :            : 
+      66                 :            :     if ((ret = mbedtls_block_cipher_setkey(&ctx->block_cipher_ctx, key, keybits)) != 0) {
+      67                 :            :         return MBEDTLS_ERR_CCM_BAD_INPUT;
+      68                 :            :     }
+      69                 :            : #else
+      70                 :            :     const mbedtls_cipher_info_t *cipher_info;
+      71                 :            : 
+      72                 :          0 :     cipher_info = mbedtls_cipher_info_from_values(cipher, keybits,
+      73                 :            :                                                   MBEDTLS_MODE_ECB);
+      74         [ #  # ]:          0 :     if (cipher_info == NULL) {
+      75                 :          0 :         return MBEDTLS_ERR_CCM_BAD_INPUT;
+      76                 :            :     }
+      77                 :            : 
+      78         [ #  # ]:          0 :     if (mbedtls_cipher_info_get_block_size(cipher_info) != 16) {
+      79                 :          0 :         return MBEDTLS_ERR_CCM_BAD_INPUT;
+      80                 :            :     }
+      81                 :            : 
+      82                 :          0 :     mbedtls_cipher_free(&ctx->cipher_ctx);
+      83                 :            : 
+      84         [ #  # ]:          0 :     if ((ret = mbedtls_cipher_setup(&ctx->cipher_ctx, cipher_info)) != 0) {
+      85                 :          0 :         return ret;
+      86                 :            :     }
+      87                 :            : 
+      88         [ #  # ]:          0 :     if ((ret = mbedtls_cipher_setkey(&ctx->cipher_ctx, key, keybits,
+      89                 :            :                                      MBEDTLS_ENCRYPT)) != 0) {
+      90                 :          0 :         return ret;
+      91                 :            :     }
+      92                 :            : #endif
+      93                 :            : 
+      94                 :          0 :     return ret;
+      95                 :            : }
+      96                 :            : 
+      97                 :            : /*
+      98                 :            :  * Free context
+      99                 :            :  */
+     100                 :          0 : void mbedtls_ccm_free(mbedtls_ccm_context *ctx)
+     101                 :            : {
+     102         [ #  # ]:          0 :     if (ctx == NULL) {
+     103                 :          0 :         return;
+     104                 :            :     }
+     105                 :            : #if defined(MBEDTLS_BLOCK_CIPHER_C)
+     106                 :            :     mbedtls_block_cipher_free(&ctx->block_cipher_ctx);
+     107                 :            : #else
+     108                 :          0 :     mbedtls_cipher_free(&ctx->cipher_ctx);
+     109                 :            : #endif
+     110                 :          0 :     mbedtls_platform_zeroize(ctx, sizeof(mbedtls_ccm_context));
+     111                 :            : }
+     112                 :            : 
+     113                 :            : #define CCM_STATE__CLEAR                0
+     114                 :            : #define CCM_STATE__STARTED              (1 << 0)
+     115                 :            : #define CCM_STATE__LENGTHS_SET          (1 << 1)
+     116                 :            : #define CCM_STATE__AUTH_DATA_STARTED    (1 << 2)
+     117                 :            : #define CCM_STATE__AUTH_DATA_FINISHED   (1 << 3)
+     118                 :            : #define CCM_STATE__ERROR                (1 << 4)
+     119                 :            : 
+     120                 :            : /*
+     121                 :            :  * Encrypt or decrypt a partial block with CTR
+     122                 :            :  */
+     123                 :          0 : static int mbedtls_ccm_crypt(mbedtls_ccm_context *ctx,
+     124                 :            :                              size_t offset, size_t use_len,
+     125                 :            :                              const unsigned char *input,
+     126                 :            :                              unsigned char *output)
+     127                 :            : {
+     128                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     129                 :          0 :     unsigned char tmp_buf[16] = { 0 };
+     130                 :            : 
+     131                 :            : #if defined(MBEDTLS_BLOCK_CIPHER_C)
+     132                 :            :     ret = mbedtls_block_cipher_encrypt(&ctx->block_cipher_ctx, ctx->ctr, tmp_buf);
+     133                 :            : #else
+     134                 :          0 :     size_t olen = 0;
+     135                 :          0 :     ret = mbedtls_cipher_update(&ctx->cipher_ctx, ctx->ctr, 16, tmp_buf, &olen);
+     136                 :            : #endif
+     137         [ #  # ]:          0 :     if (ret != 0) {
+     138                 :          0 :         ctx->state |= CCM_STATE__ERROR;
+     139                 :          0 :         mbedtls_platform_zeroize(tmp_buf, sizeof(tmp_buf));
+     140                 :          0 :         return ret;
+     141                 :            :     }
+     142                 :            : 
+     143                 :          0 :     mbedtls_xor(output, input, tmp_buf + offset, use_len);
+     144                 :            : 
+     145                 :          0 :     mbedtls_platform_zeroize(tmp_buf, sizeof(tmp_buf));
+     146                 :          0 :     return ret;
+     147                 :            : }
+     148                 :            : 
+     149                 :          0 : static void mbedtls_ccm_clear_state(mbedtls_ccm_context *ctx)
+     150                 :            : {
+     151                 :          0 :     ctx->state = CCM_STATE__CLEAR;
+     152                 :          0 :     memset(ctx->y, 0, 16);
+     153                 :          0 :     memset(ctx->ctr, 0, 16);
+     154                 :          0 : }
+     155                 :            : 
+     156                 :          0 : static int ccm_calculate_first_block_if_ready(mbedtls_ccm_context *ctx)
+     157                 :            : {
+     158                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     159                 :            :     unsigned char i;
+     160                 :            :     size_t len_left;
+     161                 :            : #if !defined(MBEDTLS_BLOCK_CIPHER_C)
+     162                 :            :     size_t olen;
+     163                 :            : #endif
+     164                 :            : 
+     165                 :            :     /* length calculation can be done only after both
+     166                 :            :      * mbedtls_ccm_starts() and mbedtls_ccm_set_lengths() have been executed
+     167                 :            :      */
+     168   [ #  #  #  # ]:          0 :     if (!(ctx->state & CCM_STATE__STARTED) || !(ctx->state & CCM_STATE__LENGTHS_SET)) {
+     169                 :          0 :         return 0;
+     170                 :            :     }
+     171                 :            : 
+     172                 :            :     /* CCM expects non-empty tag.
+     173                 :            :      * CCM* allows empty tag. For CCM* without tag, ignore plaintext length.
+     174                 :            :      */
+     175         [ #  # ]:          0 :     if (ctx->tag_len == 0) {
+     176   [ #  #  #  # ]:          0 :         if (ctx->mode == MBEDTLS_CCM_STAR_ENCRYPT || ctx->mode == MBEDTLS_CCM_STAR_DECRYPT) {
+     177                 :          0 :             ctx->plaintext_len = 0;
+     178                 :            :         } else {
+     179                 :          0 :             return MBEDTLS_ERR_CCM_BAD_INPUT;
+     180                 :            :         }
+     181                 :            :     }
+     182                 :            : 
+     183                 :            :     /*
+     184                 :            :      * First block:
+     185                 :            :      * 0        .. 0        flags
+     186                 :            :      * 1        .. iv_len   nonce (aka iv)  - set by: mbedtls_ccm_starts()
+     187                 :            :      * iv_len+1 .. 15       length
+     188                 :            :      *
+     189                 :            :      * With flags as (bits):
+     190                 :            :      * 7        0
+     191                 :            :      * 6        add present?
+     192                 :            :      * 5 .. 3   (t - 2) / 2
+     193                 :            :      * 2 .. 0   q - 1
+     194                 :            :      */
+     195         [ #  # ]:          0 :     ctx->y[0] |= (ctx->add_len > 0) << 6;
+     196                 :          0 :     ctx->y[0] |= ((ctx->tag_len - 2) / 2) << 3;
+     197                 :          0 :     ctx->y[0] |= ctx->q - 1;
+     198                 :            : 
+     199         [ #  # ]:          0 :     for (i = 0, len_left = ctx->plaintext_len; i < ctx->q; i++, len_left >>= 8) {
+     200                 :          0 :         ctx->y[15-i] = MBEDTLS_BYTE_0(len_left);
+     201                 :            :     }
+     202                 :            : 
+     203         [ #  # ]:          0 :     if (len_left > 0) {
+     204                 :          0 :         ctx->state |= CCM_STATE__ERROR;
+     205                 :          0 :         return MBEDTLS_ERR_CCM_BAD_INPUT;
+     206                 :            :     }
+     207                 :            : 
+     208                 :            :     /* Start CBC-MAC with first block*/
+     209                 :            : #if defined(MBEDTLS_BLOCK_CIPHER_C)
+     210                 :            :     ret = mbedtls_block_cipher_encrypt(&ctx->block_cipher_ctx, ctx->y, ctx->y);
+     211                 :            : #else
+     212                 :          0 :     ret = mbedtls_cipher_update(&ctx->cipher_ctx, ctx->y, 16, ctx->y, &olen);
+     213                 :            : #endif
+     214         [ #  # ]:          0 :     if (ret != 0) {
+     215                 :          0 :         ctx->state |= CCM_STATE__ERROR;
+     216                 :          0 :         return ret;
+     217                 :            :     }
+     218                 :            : 
+     219                 :          0 :     return 0;
+     220                 :            : }
+     221                 :            : 
+     222                 :          0 : int mbedtls_ccm_starts(mbedtls_ccm_context *ctx,
+     223                 :            :                        int mode,
+     224                 :            :                        const unsigned char *iv,
+     225                 :            :                        size_t iv_len)
+     226                 :            : {
+     227                 :            :     /* Also implies q is within bounds */
+     228   [ #  #  #  # ]:          0 :     if (iv_len < 7 || iv_len > 13) {
+     229                 :          0 :         return MBEDTLS_ERR_CCM_BAD_INPUT;
+     230                 :            :     }
+     231                 :            : 
+     232                 :          0 :     ctx->mode = mode;
+     233                 :          0 :     ctx->q = 16 - 1 - (unsigned char) iv_len;
+     234                 :            : 
+     235                 :            :     /*
+     236                 :            :      * Prepare counter block for encryption:
+     237                 :            :      * 0        .. 0        flags
+     238                 :            :      * 1        .. iv_len   nonce (aka iv)
+     239                 :            :      * iv_len+1 .. 15       counter (initially 1)
+     240                 :            :      *
+     241                 :            :      * With flags as (bits):
+     242                 :            :      * 7 .. 3   0
+     243                 :            :      * 2 .. 0   q - 1
+     244                 :            :      */
+     245                 :          0 :     memset(ctx->ctr, 0, 16);
+     246                 :          0 :     ctx->ctr[0] = ctx->q - 1;
+     247                 :          0 :     memcpy(ctx->ctr + 1, iv, iv_len);
+     248                 :          0 :     memset(ctx->ctr + 1 + iv_len, 0, ctx->q);
+     249                 :          0 :     ctx->ctr[15] = 1;
+     250                 :            : 
+     251                 :            :     /*
+     252                 :            :      * See ccm_calculate_first_block_if_ready() for block layout description
+     253                 :            :      */
+     254                 :          0 :     memcpy(ctx->y + 1, iv, iv_len);
+     255                 :            : 
+     256                 :          0 :     ctx->state |= CCM_STATE__STARTED;
+     257                 :          0 :     return ccm_calculate_first_block_if_ready(ctx);
+     258                 :            : }
+     259                 :            : 
+     260                 :          0 : int mbedtls_ccm_set_lengths(mbedtls_ccm_context *ctx,
+     261                 :            :                             size_t total_ad_len,
+     262                 :            :                             size_t plaintext_len,
+     263                 :            :                             size_t tag_len)
+     264                 :            : {
+     265                 :            :     /*
+     266                 :            :      * Check length requirements: SP800-38C A.1
+     267                 :            :      * Additional requirement: a < 2^16 - 2^8 to simplify the code.
+     268                 :            :      * 'length' checked later (when writing it to the first block)
+     269                 :            :      *
+     270                 :            :      * Also, loosen the requirements to enable support for CCM* (IEEE 802.15.4).
+     271                 :            :      */
+     272   [ #  #  #  #  :          0 :     if (tag_len == 2 || tag_len > 16 || tag_len % 2 != 0) {
+                   #  # ]
+     273                 :          0 :         return MBEDTLS_ERR_CCM_BAD_INPUT;
+     274                 :            :     }
+     275                 :            : 
+     276         [ #  # ]:          0 :     if (total_ad_len >= 0xFF00) {
+     277                 :          0 :         return MBEDTLS_ERR_CCM_BAD_INPUT;
+     278                 :            :     }
+     279                 :            : 
+     280                 :          0 :     ctx->plaintext_len = plaintext_len;
+     281                 :          0 :     ctx->add_len = total_ad_len;
+     282                 :          0 :     ctx->tag_len = tag_len;
+     283                 :          0 :     ctx->processed = 0;
+     284                 :            : 
+     285                 :          0 :     ctx->state |= CCM_STATE__LENGTHS_SET;
+     286                 :          0 :     return ccm_calculate_first_block_if_ready(ctx);
+     287                 :            : }
+     288                 :            : 
+     289                 :          0 : int mbedtls_ccm_update_ad(mbedtls_ccm_context *ctx,
+     290                 :            :                           const unsigned char *add,
+     291                 :            :                           size_t add_len)
+     292                 :            : {
+     293                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     294                 :            :     size_t use_len, offset;
+     295                 :            : #if !defined(MBEDTLS_BLOCK_CIPHER_C)
+     296                 :            :     size_t olen;
+     297                 :            : #endif
+     298                 :            : 
+     299         [ #  # ]:          0 :     if (ctx->state & CCM_STATE__ERROR) {
+     300                 :          0 :         return MBEDTLS_ERR_CCM_BAD_INPUT;
+     301                 :            :     }
+     302                 :            : 
+     303         [ #  # ]:          0 :     if (add_len > 0) {
+     304         [ #  # ]:          0 :         if (ctx->state & CCM_STATE__AUTH_DATA_FINISHED) {
+     305                 :          0 :             return MBEDTLS_ERR_CCM_BAD_INPUT;
+     306                 :            :         }
+     307                 :            : 
+     308         [ #  # ]:          0 :         if (!(ctx->state & CCM_STATE__AUTH_DATA_STARTED)) {
+     309         [ #  # ]:          0 :             if (add_len > ctx->add_len) {
+     310                 :          0 :                 return MBEDTLS_ERR_CCM_BAD_INPUT;
+     311                 :            :             }
+     312                 :            : 
+     313                 :          0 :             ctx->y[0] ^= (unsigned char) ((ctx->add_len >> 8) & 0xFF);
+     314                 :          0 :             ctx->y[1] ^= (unsigned char) ((ctx->add_len) & 0xFF);
+     315                 :            : 
+     316                 :          0 :             ctx->state |= CCM_STATE__AUTH_DATA_STARTED;
+     317         [ #  # ]:          0 :         } else if (ctx->processed + add_len > ctx->add_len) {
+     318                 :          0 :             return MBEDTLS_ERR_CCM_BAD_INPUT;
+     319                 :            :         }
+     320                 :            : 
+     321         [ #  # ]:          0 :         while (add_len > 0) {
+     322                 :          0 :             offset = (ctx->processed + 2) % 16; /* account for y[0] and y[1]
+     323                 :            :                                                  * holding total auth data length */
+     324                 :          0 :             use_len = 16 - offset;
+     325                 :            : 
+     326         [ #  # ]:          0 :             if (use_len > add_len) {
+     327                 :          0 :                 use_len = add_len;
+     328                 :            :             }
+     329                 :            : 
+     330                 :          0 :             mbedtls_xor(ctx->y + offset, ctx->y + offset, add, use_len);
+     331                 :            : 
+     332                 :          0 :             ctx->processed += use_len;
+     333                 :          0 :             add_len -= use_len;
+     334                 :          0 :             add += use_len;
+     335                 :            : 
+     336   [ #  #  #  # ]:          0 :             if (use_len + offset == 16 || ctx->processed == ctx->add_len) {
+     337                 :            : #if defined(MBEDTLS_BLOCK_CIPHER_C)
+     338                 :            :                 ret = mbedtls_block_cipher_encrypt(&ctx->block_cipher_ctx, ctx->y, ctx->y);
+     339                 :            : #else
+     340                 :          0 :                 ret = mbedtls_cipher_update(&ctx->cipher_ctx, ctx->y, 16, ctx->y, &olen);
+     341                 :            : #endif
+     342         [ #  # ]:          0 :                 if (ret != 0) {
+     343                 :          0 :                     ctx->state |= CCM_STATE__ERROR;
+     344                 :          0 :                     return ret;
+     345                 :            :                 }
+     346                 :            :             }
+     347                 :            :         }
+     348                 :            : 
+     349         [ #  # ]:          0 :         if (ctx->processed == ctx->add_len) {
+     350                 :          0 :             ctx->state |= CCM_STATE__AUTH_DATA_FINISHED;
+     351                 :          0 :             ctx->processed = 0; // prepare for mbedtls_ccm_update()
+     352                 :            :         }
+     353                 :            :     }
+     354                 :            : 
+     355                 :          0 :     return 0;
+     356                 :            : }
+     357                 :            : 
+     358                 :          0 : int mbedtls_ccm_update(mbedtls_ccm_context *ctx,
+     359                 :            :                        const unsigned char *input, size_t input_len,
+     360                 :            :                        unsigned char *output, size_t output_size,
+     361                 :            :                        size_t *output_len)
+     362                 :            : {
+     363                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     364                 :            :     unsigned char i;
+     365                 :            :     size_t use_len, offset;
+     366                 :            : #if !defined(MBEDTLS_BLOCK_CIPHER_C)
+     367                 :            :     size_t olen;
+     368                 :            : #endif
+     369                 :            : 
+     370                 :            :     unsigned char local_output[16];
+     371                 :            : 
+     372         [ #  # ]:          0 :     if (ctx->state & CCM_STATE__ERROR) {
+     373                 :          0 :         return MBEDTLS_ERR_CCM_BAD_INPUT;
+     374                 :            :     }
+     375                 :            : 
+     376                 :            :     /* Check against plaintext length only if performing operation with
+     377                 :            :      * authentication
+     378                 :            :      */
+     379   [ #  #  #  # ]:          0 :     if (ctx->tag_len != 0 && ctx->processed + input_len > ctx->plaintext_len) {
+     380                 :          0 :         return MBEDTLS_ERR_CCM_BAD_INPUT;
+     381                 :            :     }
+     382                 :            : 
+     383         [ #  # ]:          0 :     if (output_size < input_len) {
+     384                 :          0 :         return MBEDTLS_ERR_CCM_BAD_INPUT;
+     385                 :            :     }
+     386                 :          0 :     *output_len = input_len;
+     387                 :            : 
+     388                 :          0 :     ret = 0;
+     389                 :            : 
+     390         [ #  # ]:          0 :     while (input_len > 0) {
+     391                 :          0 :         offset = ctx->processed % 16;
+     392                 :            : 
+     393                 :          0 :         use_len = 16 - offset;
+     394                 :            : 
+     395         [ #  # ]:          0 :         if (use_len > input_len) {
+     396                 :          0 :             use_len = input_len;
+     397                 :            :         }
+     398                 :            : 
+     399                 :          0 :         ctx->processed += use_len;
+     400                 :            : 
+     401         [ #  # ]:          0 :         if (ctx->mode == MBEDTLS_CCM_ENCRYPT || \
+     402         [ #  # ]:          0 :             ctx->mode == MBEDTLS_CCM_STAR_ENCRYPT) {
+     403                 :          0 :             mbedtls_xor(ctx->y + offset, ctx->y + offset, input, use_len);
+     404                 :            : 
+     405   [ #  #  #  # ]:          0 :             if (use_len + offset == 16 || ctx->processed == ctx->plaintext_len) {
+     406                 :            : #if defined(MBEDTLS_BLOCK_CIPHER_C)
+     407                 :            :                 ret = mbedtls_block_cipher_encrypt(&ctx->block_cipher_ctx, ctx->y, ctx->y);
+     408                 :            : #else
+     409                 :          0 :                 ret = mbedtls_cipher_update(&ctx->cipher_ctx, ctx->y, 16, ctx->y, &olen);
+     410                 :            : #endif
+     411         [ #  # ]:          0 :                 if (ret != 0) {
+     412                 :          0 :                     ctx->state |= CCM_STATE__ERROR;
+     413                 :          0 :                     goto exit;
+     414                 :            :                 }
+     415                 :            :             }
+     416                 :            : 
+     417                 :          0 :             ret = mbedtls_ccm_crypt(ctx, offset, use_len, input, output);
+     418         [ #  # ]:          0 :             if (ret != 0) {
+     419                 :          0 :                 goto exit;
+     420                 :            :             }
+     421                 :            :         }
+     422                 :            : 
+     423         [ #  # ]:          0 :         if (ctx->mode == MBEDTLS_CCM_DECRYPT || \
+     424         [ #  # ]:          0 :             ctx->mode == MBEDTLS_CCM_STAR_DECRYPT) {
+     425                 :            :             /* Since output may be in shared memory, we cannot be sure that
+     426                 :            :              * it will contain what we wrote to it. Therefore, we should avoid using
+     427                 :            :              * it as input to any operations.
+     428                 :            :              * Write decrypted data to local_output to avoid using output variable as
+     429                 :            :              * input in the XOR operation for Y.
+     430                 :            :              */
+     431                 :          0 :             ret = mbedtls_ccm_crypt(ctx, offset, use_len, input, local_output);
+     432         [ #  # ]:          0 :             if (ret != 0) {
+     433                 :          0 :                 goto exit;
+     434                 :            :             }
+     435                 :            : 
+     436                 :          0 :             mbedtls_xor(ctx->y + offset, ctx->y + offset, local_output, use_len);
+     437                 :            : 
+     438                 :          0 :             memcpy(output, local_output, use_len);
+     439                 :            : 
+     440   [ #  #  #  # ]:          0 :             if (use_len + offset == 16 || ctx->processed == ctx->plaintext_len) {
+     441                 :            : #if defined(MBEDTLS_BLOCK_CIPHER_C)
+     442                 :            :                 ret = mbedtls_block_cipher_encrypt(&ctx->block_cipher_ctx, ctx->y, ctx->y);
+     443                 :            : #else
+     444                 :          0 :                 ret = mbedtls_cipher_update(&ctx->cipher_ctx, ctx->y, 16, ctx->y, &olen);
+     445                 :            : #endif
+     446         [ #  # ]:          0 :                 if (ret != 0) {
+     447                 :          0 :                     ctx->state |= CCM_STATE__ERROR;
+     448                 :          0 :                     goto exit;
+     449                 :            :                 }
+     450                 :            :             }
+     451                 :            :         }
+     452                 :            : 
+     453   [ #  #  #  # ]:          0 :         if (use_len + offset == 16 || ctx->processed == ctx->plaintext_len) {
+     454         [ #  # ]:          0 :             for (i = 0; i < ctx->q; i++) {
+     455         [ #  # ]:          0 :                 if (++(ctx->ctr)[15-i] != 0) {
+     456                 :          0 :                     break;
+     457                 :            :                 }
+     458                 :            :             }
+     459                 :            :         }
+     460                 :            : 
+     461                 :          0 :         input_len -= use_len;
+     462                 :          0 :         input += use_len;
+     463                 :          0 :         output += use_len;
+     464                 :            :     }
+     465                 :            : 
+     466                 :          0 : exit:
+     467                 :          0 :     mbedtls_platform_zeroize(local_output, 16);
+     468                 :            : 
+     469                 :          0 :     return ret;
+     470                 :            : }
+     471                 :            : 
+     472                 :          0 : int mbedtls_ccm_finish(mbedtls_ccm_context *ctx,
+     473                 :            :                        unsigned char *tag, size_t tag_len)
+     474                 :            : {
+     475                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     476                 :            :     unsigned char i;
+     477                 :            : 
+     478         [ #  # ]:          0 :     if (ctx->state & CCM_STATE__ERROR) {
+     479                 :          0 :         return MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     480                 :            :     }
+     481                 :            : 
+     482   [ #  #  #  # ]:          0 :     if (ctx->add_len > 0 && !(ctx->state & CCM_STATE__AUTH_DATA_FINISHED)) {
+     483                 :          0 :         return MBEDTLS_ERR_CCM_BAD_INPUT;
+     484                 :            :     }
+     485                 :            : 
+     486   [ #  #  #  # ]:          0 :     if (ctx->plaintext_len > 0 && ctx->processed != ctx->plaintext_len) {
+     487                 :          0 :         return MBEDTLS_ERR_CCM_BAD_INPUT;
+     488                 :            :     }
+     489                 :            : 
+     490                 :            :     /*
+     491                 :            :      * Authentication: reset counter and crypt/mask internal tag
+     492                 :            :      */
+     493         [ #  # ]:          0 :     for (i = 0; i < ctx->q; i++) {
+     494                 :          0 :         ctx->ctr[15-i] = 0;
+     495                 :            :     }
+     496                 :            : 
+     497                 :          0 :     ret = mbedtls_ccm_crypt(ctx, 0, 16, ctx->y, ctx->y);
+     498         [ #  # ]:          0 :     if (ret != 0) {
+     499                 :          0 :         return ret;
+     500                 :            :     }
+     501         [ #  # ]:          0 :     if (tag != NULL) {
+     502                 :          0 :         memcpy(tag, ctx->y, tag_len);
+     503                 :            :     }
+     504                 :          0 :     mbedtls_ccm_clear_state(ctx);
+     505                 :            : 
+     506                 :          0 :     return 0;
+     507                 :            : }
+     508                 :            : 
+     509                 :            : /*
+     510                 :            :  * Authenticated encryption or decryption
+     511                 :            :  */
+     512                 :          0 : static int ccm_auth_crypt(mbedtls_ccm_context *ctx, int mode, size_t length,
+     513                 :            :                           const unsigned char *iv, size_t iv_len,
+     514                 :            :                           const unsigned char *add, size_t add_len,
+     515                 :            :                           const unsigned char *input, unsigned char *output,
+     516                 :            :                           unsigned char *tag, size_t tag_len)
+     517                 :            : {
+     518                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     519                 :            :     size_t olen;
+     520                 :            : 
+     521         [ #  # ]:          0 :     if ((ret = mbedtls_ccm_starts(ctx, mode, iv, iv_len)) != 0) {
+     522                 :          0 :         return ret;
+     523                 :            :     }
+     524                 :            : 
+     525         [ #  # ]:          0 :     if ((ret = mbedtls_ccm_set_lengths(ctx, add_len, length, tag_len)) != 0) {
+     526                 :          0 :         return ret;
+     527                 :            :     }
+     528                 :            : 
+     529         [ #  # ]:          0 :     if ((ret = mbedtls_ccm_update_ad(ctx, add, add_len)) != 0) {
+     530                 :          0 :         return ret;
+     531                 :            :     }
+     532                 :            : 
+     533         [ #  # ]:          0 :     if ((ret = mbedtls_ccm_update(ctx, input, length,
+     534                 :            :                                   output, length, &olen)) != 0) {
+     535                 :          0 :         return ret;
+     536                 :            :     }
+     537                 :            : 
+     538         [ #  # ]:          0 :     if ((ret = mbedtls_ccm_finish(ctx, tag, tag_len)) != 0) {
+     539                 :          0 :         return ret;
+     540                 :            :     }
+     541                 :            : 
+     542                 :          0 :     return 0;
+     543                 :            : }
+     544                 :            : 
+     545                 :            : /*
+     546                 :            :  * Authenticated encryption
+     547                 :            :  */
+     548                 :          0 : int mbedtls_ccm_star_encrypt_and_tag(mbedtls_ccm_context *ctx, size_t length,
+     549                 :            :                                      const unsigned char *iv, size_t iv_len,
+     550                 :            :                                      const unsigned char *add, size_t add_len,
+     551                 :            :                                      const unsigned char *input, unsigned char *output,
+     552                 :            :                                      unsigned char *tag, size_t tag_len)
+     553                 :            : {
+     554                 :          0 :     return ccm_auth_crypt(ctx, MBEDTLS_CCM_STAR_ENCRYPT, length, iv, iv_len,
+     555                 :            :                           add, add_len, input, output, tag, tag_len);
+     556                 :            : }
+     557                 :            : 
+     558                 :          0 : int mbedtls_ccm_encrypt_and_tag(mbedtls_ccm_context *ctx, size_t length,
+     559                 :            :                                 const unsigned char *iv, size_t iv_len,
+     560                 :            :                                 const unsigned char *add, size_t add_len,
+     561                 :            :                                 const unsigned char *input, unsigned char *output,
+     562                 :            :                                 unsigned char *tag, size_t tag_len)
+     563                 :            : {
+     564                 :          0 :     return ccm_auth_crypt(ctx, MBEDTLS_CCM_ENCRYPT, length, iv, iv_len,
+     565                 :            :                           add, add_len, input, output, tag, tag_len);
+     566                 :            : }
+     567                 :            : 
+     568                 :            : /*
+     569                 :            :  * Authenticated decryption
+     570                 :            :  */
+     571                 :          0 : static int mbedtls_ccm_compare_tags(const unsigned char *tag1,
+     572                 :            :                                     const unsigned char *tag2,
+     573                 :            :                                     size_t tag_len)
+     574                 :            : {
+     575                 :            :     /* Check tag in "constant-time" */
+     576                 :          0 :     int diff = mbedtls_ct_memcmp(tag1, tag2, tag_len);
+     577                 :            : 
+     578         [ #  # ]:          0 :     if (diff != 0) {
+     579                 :          0 :         return MBEDTLS_ERR_CCM_AUTH_FAILED;
+     580                 :            :     }
+     581                 :            : 
+     582                 :          0 :     return 0;
+     583                 :            : }
+     584                 :            : 
+     585                 :          0 : static int ccm_auth_decrypt(mbedtls_ccm_context *ctx, int mode, size_t length,
+     586                 :            :                             const unsigned char *iv, size_t iv_len,
+     587                 :            :                             const unsigned char *add, size_t add_len,
+     588                 :            :                             const unsigned char *input, unsigned char *output,
+     589                 :            :                             const unsigned char *tag, size_t tag_len)
+     590                 :            : {
+     591                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     592                 :            :     unsigned char check_tag[16];
+     593                 :            : 
+     594         [ #  # ]:          0 :     if ((ret = ccm_auth_crypt(ctx, mode, length,
+     595                 :            :                               iv, iv_len, add, add_len,
+     596                 :            :                               input, output, check_tag, tag_len)) != 0) {
+     597                 :          0 :         return ret;
+     598                 :            :     }
+     599                 :            : 
+     600         [ #  # ]:          0 :     if ((ret = mbedtls_ccm_compare_tags(tag, check_tag, tag_len)) != 0) {
+     601                 :          0 :         mbedtls_platform_zeroize(output, length);
+     602                 :          0 :         return ret;
+     603                 :            :     }
+     604                 :            : 
+     605                 :          0 :     return 0;
+     606                 :            : }
+     607                 :            : 
+     608                 :          0 : int mbedtls_ccm_star_auth_decrypt(mbedtls_ccm_context *ctx, size_t length,
+     609                 :            :                                   const unsigned char *iv, size_t iv_len,
+     610                 :            :                                   const unsigned char *add, size_t add_len,
+     611                 :            :                                   const unsigned char *input, unsigned char *output,
+     612                 :            :                                   const unsigned char *tag, size_t tag_len)
+     613                 :            : {
+     614                 :          0 :     return ccm_auth_decrypt(ctx, MBEDTLS_CCM_STAR_DECRYPT, length,
+     615                 :            :                             iv, iv_len, add, add_len,
+     616                 :            :                             input, output, tag, tag_len);
+     617                 :            : }
+     618                 :            : 
+     619                 :          0 : int mbedtls_ccm_auth_decrypt(mbedtls_ccm_context *ctx, size_t length,
+     620                 :            :                              const unsigned char *iv, size_t iv_len,
+     621                 :            :                              const unsigned char *add, size_t add_len,
+     622                 :            :                              const unsigned char *input, unsigned char *output,
+     623                 :            :                              const unsigned char *tag, size_t tag_len)
+     624                 :            : {
+     625                 :          0 :     return ccm_auth_decrypt(ctx, MBEDTLS_CCM_DECRYPT, length,
+     626                 :            :                             iv, iv_len, add, add_len,
+     627                 :            :                             input, output, tag, tag_len);
+     628                 :            : }
+     629                 :            : #endif /* !MBEDTLS_CCM_ALT */
+     630                 :            : 
+     631                 :            : #if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_CCM_GCM_CAN_AES)
+     632                 :            : /*
+     633                 :            :  * Examples 1 to 3 from SP800-38C Appendix C
+     634                 :            :  */
+     635                 :            : 
+     636                 :            : #define NB_TESTS 3
+     637                 :            : #define CCM_SELFTEST_PT_MAX_LEN 24
+     638                 :            : #define CCM_SELFTEST_CT_MAX_LEN 32
+     639                 :            : /*
+     640                 :            :  * The data is the same for all tests, only the used length changes
+     641                 :            :  */
+     642                 :            : static const unsigned char key_test_data[] = {
+     643                 :            :     0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
+     644                 :            :     0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f
+     645                 :            : };
+     646                 :            : 
+     647                 :            : static const unsigned char iv_test_data[] = {
+     648                 :            :     0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+     649                 :            :     0x18, 0x19, 0x1a, 0x1b
+     650                 :            : };
+     651                 :            : 
+     652                 :            : static const unsigned char ad_test_data[] = {
+     653                 :            :     0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+     654                 :            :     0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+     655                 :            :     0x10, 0x11, 0x12, 0x13
+     656                 :            : };
+     657                 :            : 
+     658                 :            : static const unsigned char msg_test_data[CCM_SELFTEST_PT_MAX_LEN] = {
+     659                 :            :     0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
+     660                 :            :     0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
+     661                 :            :     0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
+     662                 :            : };
+     663                 :            : 
+     664                 :            : static const size_t iv_len_test_data[NB_TESTS] = { 7, 8,  12 };
+     665                 :            : static const size_t add_len_test_data[NB_TESTS] = { 8, 16, 20 };
+     666                 :            : static const size_t msg_len_test_data[NB_TESTS] = { 4, 16, 24 };
+     667                 :            : static const size_t tag_len_test_data[NB_TESTS] = { 4, 6,  8  };
+     668                 :            : 
+     669                 :            : static const unsigned char res_test_data[NB_TESTS][CCM_SELFTEST_CT_MAX_LEN] = {
+     670                 :            :     {   0x71, 0x62, 0x01, 0x5b, 0x4d, 0xac, 0x25, 0x5d },
+     671                 :            :     {   0xd2, 0xa1, 0xf0, 0xe0, 0x51, 0xea, 0x5f, 0x62,
+     672                 :            :         0x08, 0x1a, 0x77, 0x92, 0x07, 0x3d, 0x59, 0x3d,
+     673                 :            :         0x1f, 0xc6, 0x4f, 0xbf, 0xac, 0xcd },
+     674                 :            :     {   0xe3, 0xb2, 0x01, 0xa9, 0xf5, 0xb7, 0x1a, 0x7a,
+     675                 :            :         0x9b, 0x1c, 0xea, 0xec, 0xcd, 0x97, 0xe7, 0x0b,
+     676                 :            :         0x61, 0x76, 0xaa, 0xd9, 0xa4, 0x42, 0x8a, 0xa5,
+     677                 :            :         0x48, 0x43, 0x92, 0xfb, 0xc1, 0xb0, 0x99, 0x51 }
+     678                 :            : };
+     679                 :            : 
+     680                 :          0 : int mbedtls_ccm_self_test(int verbose)
+     681                 :            : {
+     682                 :            :     mbedtls_ccm_context ctx;
+     683                 :            :     /*
+     684                 :            :      * Some hardware accelerators require the input and output buffers
+     685                 :            :      * would be in RAM, because the flash is not accessible.
+     686                 :            :      * Use buffers on the stack to hold the test vectors data.
+     687                 :            :      */
+     688                 :            :     unsigned char plaintext[CCM_SELFTEST_PT_MAX_LEN];
+     689                 :            :     unsigned char ciphertext[CCM_SELFTEST_CT_MAX_LEN];
+     690                 :            :     size_t i;
+     691                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     692                 :            : 
+     693                 :          0 :     mbedtls_ccm_init(&ctx);
+     694                 :            : 
+     695         [ #  # ]:          0 :     if (mbedtls_ccm_setkey(&ctx, MBEDTLS_CIPHER_ID_AES, key_test_data,
+     696                 :            :                            8 * sizeof(key_test_data)) != 0) {
+     697         [ #  # ]:          0 :         if (verbose != 0) {
+     698                 :          0 :             mbedtls_printf("  CCM: setup failed");
+     699                 :            :         }
+     700                 :            : 
+     701                 :          0 :         return 1;
+     702                 :            :     }
+     703                 :            : 
+     704         [ #  # ]:          0 :     for (i = 0; i < NB_TESTS; i++) {
+     705         [ #  # ]:          0 :         if (verbose != 0) {
+     706                 :          0 :             mbedtls_printf("  CCM-AES #%u: ", (unsigned int) i + 1);
+     707                 :            :         }
+     708                 :            : 
+     709                 :          0 :         memset(plaintext, 0, CCM_SELFTEST_PT_MAX_LEN);
+     710                 :          0 :         memset(ciphertext, 0, CCM_SELFTEST_CT_MAX_LEN);
+     711                 :          0 :         memcpy(plaintext, msg_test_data, msg_len_test_data[i]);
+     712                 :            : 
+     713                 :          0 :         ret = mbedtls_ccm_encrypt_and_tag(&ctx, msg_len_test_data[i],
+     714                 :          0 :                                           iv_test_data, iv_len_test_data[i],
+     715                 :          0 :                                           ad_test_data, add_len_test_data[i],
+     716                 :            :                                           plaintext, ciphertext,
+     717                 :          0 :                                           ciphertext + msg_len_test_data[i],
+     718                 :          0 :                                           tag_len_test_data[i]);
+     719                 :            : 
+     720         [ #  # ]:          0 :         if (ret != 0 ||
+     721                 :          0 :             memcmp(ciphertext, res_test_data[i],
+     722         [ #  # ]:          0 :                    msg_len_test_data[i] + tag_len_test_data[i]) != 0) {
+     723         [ #  # ]:          0 :             if (verbose != 0) {
+     724                 :          0 :                 mbedtls_printf("failed\n");
+     725                 :            :             }
+     726                 :            : 
+     727                 :          0 :             return 1;
+     728                 :            :         }
+     729                 :          0 :         memset(plaintext, 0, CCM_SELFTEST_PT_MAX_LEN);
+     730                 :            : 
+     731                 :          0 :         ret = mbedtls_ccm_auth_decrypt(&ctx, msg_len_test_data[i],
+     732                 :          0 :                                        iv_test_data, iv_len_test_data[i],
+     733                 :          0 :                                        ad_test_data, add_len_test_data[i],
+     734                 :            :                                        ciphertext, plaintext,
+     735                 :          0 :                                        ciphertext + msg_len_test_data[i],
+     736                 :          0 :                                        tag_len_test_data[i]);
+     737                 :            : 
+     738         [ #  # ]:          0 :         if (ret != 0 ||
+     739         [ #  # ]:          0 :             memcmp(plaintext, msg_test_data, msg_len_test_data[i]) != 0) {
+     740         [ #  # ]:          0 :             if (verbose != 0) {
+     741                 :          0 :                 mbedtls_printf("failed\n");
+     742                 :            :             }
+     743                 :            : 
+     744                 :          0 :             return 1;
+     745                 :            :         }
+     746                 :            : 
+     747         [ #  # ]:          0 :         if (verbose != 0) {
+     748                 :          0 :             mbedtls_printf("passed\n");
+     749                 :            :         }
+     750                 :            :     }
+     751                 :            : 
+     752                 :          0 :     mbedtls_ccm_free(&ctx);
+     753                 :            : 
+     754         [ #  # ]:          0 :     if (verbose != 0) {
+     755                 :          0 :         mbedtls_printf("\n");
+     756                 :            :     }
+     757                 :            : 
+     758                 :          0 :     return 0;
+     759                 :            : }
+     760                 :            : 
+     761                 :            : #endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */
+     762                 :            : 
+     763                 :            : #endif /* MBEDTLS_CCM_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/chacha20.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/chacha20.c.func-sort-c.html new file mode 100644 index 00000000000..be2a586126d --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/chacha20.c.func-sort-c.html @@ -0,0 +1,121 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/chacha20.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - chacha20.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:01300.0 %
Date:2024-09-22 08:21:07Functions:0100.0 %
Branches:0340.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
chacha20_block0
chacha20_inner_block0
chacha20_quarter_round0
mbedtls_chacha20_crypt0
mbedtls_chacha20_free0
mbedtls_chacha20_init0
mbedtls_chacha20_self_test0
mbedtls_chacha20_setkey0
mbedtls_chacha20_starts0
mbedtls_chacha20_update0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/chacha20.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/chacha20.c.func.html new file mode 100644 index 00000000000..efc198f6df7 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/chacha20.c.func.html @@ -0,0 +1,121 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/chacha20.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - chacha20.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:01300.0 %
Date:2024-09-22 08:21:07Functions:0100.0 %
Branches:0340.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
chacha20_block0
chacha20_inner_block0
chacha20_quarter_round0
mbedtls_chacha20_crypt0
mbedtls_chacha20_free0
mbedtls_chacha20_init0
mbedtls_chacha20_self_test0
mbedtls_chacha20_setkey0
mbedtls_chacha20_starts0
mbedtls_chacha20_update0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/chacha20.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/chacha20.c.gcov.html new file mode 100644 index 00000000000..033db112f87 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/chacha20.c.gcov.html @@ -0,0 +1,582 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/chacha20.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - chacha20.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:01300.0 %
Date:2024-09-22 08:21:07Functions:0100.0 %
Branches:0340.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  * \file chacha20.c
+       3                 :            :  *
+       4                 :            :  * \brief ChaCha20 cipher.
+       5                 :            :  *
+       6                 :            :  * \author Daniel King <damaki.gh@gmail.com>
+       7                 :            :  *
+       8                 :            :  *  Copyright The Mbed TLS Contributors
+       9                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+      10                 :            :  */
+      11                 :            : 
+      12                 :            : #include "common.h"
+      13                 :            : 
+      14                 :            : #if defined(MBEDTLS_CHACHA20_C)
+      15                 :            : 
+      16                 :            : #include "mbedtls/chacha20.h"
+      17                 :            : #include "mbedtls/platform_util.h"
+      18                 :            : #include "mbedtls/error.h"
+      19                 :            : 
+      20                 :            : #include <stddef.h>
+      21                 :            : #include <string.h>
+      22                 :            : 
+      23                 :            : #include "mbedtls/platform.h"
+      24                 :            : 
+      25                 :            : #if !defined(MBEDTLS_CHACHA20_ALT)
+      26                 :            : 
+      27                 :            : #define ROTL32(value, amount) \
+      28                 :            :     ((uint32_t) ((value) << (amount)) | ((value) >> (32 - (amount))))
+      29                 :            : 
+      30                 :            : #define CHACHA20_CTR_INDEX (12U)
+      31                 :            : 
+      32                 :            : #define CHACHA20_BLOCK_SIZE_BYTES (4U * 16U)
+      33                 :            : 
+      34                 :            : /**
+      35                 :            :  * \brief           ChaCha20 quarter round operation.
+      36                 :            :  *
+      37                 :            :  *                  The quarter round is defined as follows (from RFC 7539):
+      38                 :            :  *                      1.  a += b; d ^= a; d <<<= 16;
+      39                 :            :  *                      2.  c += d; b ^= c; b <<<= 12;
+      40                 :            :  *                      3.  a += b; d ^= a; d <<<= 8;
+      41                 :            :  *                      4.  c += d; b ^= c; b <<<= 7;
+      42                 :            :  *
+      43                 :            :  * \param state     ChaCha20 state to modify.
+      44                 :            :  * \param a         The index of 'a' in the state.
+      45                 :            :  * \param b         The index of 'b' in the state.
+      46                 :            :  * \param c         The index of 'c' in the state.
+      47                 :            :  * \param d         The index of 'd' in the state.
+      48                 :            :  */
+      49                 :          0 : static inline void chacha20_quarter_round(uint32_t state[16],
+      50                 :            :                                           size_t a,
+      51                 :            :                                           size_t b,
+      52                 :            :                                           size_t c,
+      53                 :            :                                           size_t d)
+      54                 :            : {
+      55                 :            :     /* a += b; d ^= a; d <<<= 16; */
+      56                 :          0 :     state[a] += state[b];
+      57                 :          0 :     state[d] ^= state[a];
+      58                 :          0 :     state[d] = ROTL32(state[d], 16);
+      59                 :            : 
+      60                 :            :     /* c += d; b ^= c; b <<<= 12 */
+      61                 :          0 :     state[c] += state[d];
+      62                 :          0 :     state[b] ^= state[c];
+      63                 :          0 :     state[b] = ROTL32(state[b], 12);
+      64                 :            : 
+      65                 :            :     /* a += b; d ^= a; d <<<= 8; */
+      66                 :          0 :     state[a] += state[b];
+      67                 :          0 :     state[d] ^= state[a];
+      68                 :          0 :     state[d] = ROTL32(state[d], 8);
+      69                 :            : 
+      70                 :            :     /* c += d; b ^= c; b <<<= 7; */
+      71                 :          0 :     state[c] += state[d];
+      72                 :          0 :     state[b] ^= state[c];
+      73                 :          0 :     state[b] = ROTL32(state[b], 7);
+      74                 :          0 : }
+      75                 :            : 
+      76                 :            : /**
+      77                 :            :  * \brief           Perform the ChaCha20 inner block operation.
+      78                 :            :  *
+      79                 :            :  *                  This function performs two rounds: the column round and the
+      80                 :            :  *                  diagonal round.
+      81                 :            :  *
+      82                 :            :  * \param state     The ChaCha20 state to update.
+      83                 :            :  */
+      84                 :          0 : static void chacha20_inner_block(uint32_t state[16])
+      85                 :            : {
+      86                 :          0 :     chacha20_quarter_round(state, 0, 4, 8,  12);
+      87                 :          0 :     chacha20_quarter_round(state, 1, 5, 9,  13);
+      88                 :          0 :     chacha20_quarter_round(state, 2, 6, 10, 14);
+      89                 :          0 :     chacha20_quarter_round(state, 3, 7, 11, 15);
+      90                 :            : 
+      91                 :          0 :     chacha20_quarter_round(state, 0, 5, 10, 15);
+      92                 :          0 :     chacha20_quarter_round(state, 1, 6, 11, 12);
+      93                 :          0 :     chacha20_quarter_round(state, 2, 7, 8,  13);
+      94                 :          0 :     chacha20_quarter_round(state, 3, 4, 9,  14);
+      95                 :          0 : }
+      96                 :            : 
+      97                 :            : /**
+      98                 :            :  * \brief               Generates a keystream block.
+      99                 :            :  *
+     100                 :            :  * \param initial_state The initial ChaCha20 state (key, nonce, counter).
+     101                 :            :  * \param keystream     Generated keystream bytes are written to this buffer.
+     102                 :            :  */
+     103                 :          0 : static void chacha20_block(const uint32_t initial_state[16],
+     104                 :            :                            unsigned char keystream[64])
+     105                 :            : {
+     106                 :            :     uint32_t working_state[16];
+     107                 :            :     size_t i;
+     108                 :            : 
+     109                 :          0 :     memcpy(working_state,
+     110                 :            :            initial_state,
+     111                 :            :            CHACHA20_BLOCK_SIZE_BYTES);
+     112                 :            : 
+     113         [ #  # ]:          0 :     for (i = 0U; i < 10U; i++) {
+     114                 :          0 :         chacha20_inner_block(working_state);
+     115                 :            :     }
+     116                 :            : 
+     117                 :          0 :     working_state[0] += initial_state[0];
+     118                 :          0 :     working_state[1] += initial_state[1];
+     119                 :          0 :     working_state[2] += initial_state[2];
+     120                 :          0 :     working_state[3] += initial_state[3];
+     121                 :          0 :     working_state[4] += initial_state[4];
+     122                 :          0 :     working_state[5] += initial_state[5];
+     123                 :          0 :     working_state[6] += initial_state[6];
+     124                 :          0 :     working_state[7] += initial_state[7];
+     125                 :          0 :     working_state[8] += initial_state[8];
+     126                 :          0 :     working_state[9] += initial_state[9];
+     127                 :          0 :     working_state[10] += initial_state[10];
+     128                 :          0 :     working_state[11] += initial_state[11];
+     129                 :          0 :     working_state[12] += initial_state[12];
+     130                 :          0 :     working_state[13] += initial_state[13];
+     131                 :          0 :     working_state[14] += initial_state[14];
+     132                 :          0 :     working_state[15] += initial_state[15];
+     133                 :            : 
+     134         [ #  # ]:          0 :     for (i = 0U; i < 16; i++) {
+     135                 :          0 :         size_t offset = i * 4U;
+     136                 :            : 
+     137                 :          0 :         MBEDTLS_PUT_UINT32_LE(working_state[i], keystream, offset);
+     138                 :            :     }
+     139                 :            : 
+     140                 :          0 :     mbedtls_platform_zeroize(working_state, sizeof(working_state));
+     141                 :          0 : }
+     142                 :            : 
+     143                 :          0 : void mbedtls_chacha20_init(mbedtls_chacha20_context *ctx)
+     144                 :            : {
+     145                 :          0 :     mbedtls_platform_zeroize(ctx->state, sizeof(ctx->state));
+     146                 :          0 :     mbedtls_platform_zeroize(ctx->keystream8, sizeof(ctx->keystream8));
+     147                 :            : 
+     148                 :            :     /* Initially, there's no keystream bytes available */
+     149                 :          0 :     ctx->keystream_bytes_used = CHACHA20_BLOCK_SIZE_BYTES;
+     150                 :          0 : }
+     151                 :            : 
+     152                 :          0 : void mbedtls_chacha20_free(mbedtls_chacha20_context *ctx)
+     153                 :            : {
+     154         [ #  # ]:          0 :     if (ctx != NULL) {
+     155                 :          0 :         mbedtls_platform_zeroize(ctx, sizeof(mbedtls_chacha20_context));
+     156                 :            :     }
+     157                 :          0 : }
+     158                 :            : 
+     159                 :          0 : int mbedtls_chacha20_setkey(mbedtls_chacha20_context *ctx,
+     160                 :            :                             const unsigned char key[32])
+     161                 :            : {
+     162                 :            :     /* ChaCha20 constants - the string "expand 32-byte k" */
+     163                 :          0 :     ctx->state[0] = 0x61707865;
+     164                 :          0 :     ctx->state[1] = 0x3320646e;
+     165                 :          0 :     ctx->state[2] = 0x79622d32;
+     166                 :          0 :     ctx->state[3] = 0x6b206574;
+     167                 :            : 
+     168                 :            :     /* Set key */
+     169                 :          0 :     ctx->state[4]  = MBEDTLS_GET_UINT32_LE(key, 0);
+     170                 :          0 :     ctx->state[5]  = MBEDTLS_GET_UINT32_LE(key, 4);
+     171                 :          0 :     ctx->state[6]  = MBEDTLS_GET_UINT32_LE(key, 8);
+     172                 :          0 :     ctx->state[7]  = MBEDTLS_GET_UINT32_LE(key, 12);
+     173                 :          0 :     ctx->state[8]  = MBEDTLS_GET_UINT32_LE(key, 16);
+     174                 :          0 :     ctx->state[9]  = MBEDTLS_GET_UINT32_LE(key, 20);
+     175                 :          0 :     ctx->state[10] = MBEDTLS_GET_UINT32_LE(key, 24);
+     176                 :          0 :     ctx->state[11] = MBEDTLS_GET_UINT32_LE(key, 28);
+     177                 :            : 
+     178                 :          0 :     return 0;
+     179                 :            : }
+     180                 :            : 
+     181                 :          0 : int mbedtls_chacha20_starts(mbedtls_chacha20_context *ctx,
+     182                 :            :                             const unsigned char nonce[12],
+     183                 :            :                             uint32_t counter)
+     184                 :            : {
+     185                 :            :     /* Counter */
+     186                 :          0 :     ctx->state[12] = counter;
+     187                 :            : 
+     188                 :            :     /* Nonce */
+     189                 :          0 :     ctx->state[13] = MBEDTLS_GET_UINT32_LE(nonce, 0);
+     190                 :          0 :     ctx->state[14] = MBEDTLS_GET_UINT32_LE(nonce, 4);
+     191                 :          0 :     ctx->state[15] = MBEDTLS_GET_UINT32_LE(nonce, 8);
+     192                 :            : 
+     193                 :          0 :     mbedtls_platform_zeroize(ctx->keystream8, sizeof(ctx->keystream8));
+     194                 :            : 
+     195                 :            :     /* Initially, there's no keystream bytes available */
+     196                 :          0 :     ctx->keystream_bytes_used = CHACHA20_BLOCK_SIZE_BYTES;
+     197                 :            : 
+     198                 :          0 :     return 0;
+     199                 :            : }
+     200                 :            : 
+     201                 :          0 : int mbedtls_chacha20_update(mbedtls_chacha20_context *ctx,
+     202                 :            :                             size_t size,
+     203                 :            :                             const unsigned char *input,
+     204                 :            :                             unsigned char *output)
+     205                 :            : {
+     206                 :          0 :     size_t offset = 0U;
+     207                 :            : 
+     208                 :            :     /* Use leftover keystream bytes, if available */
+     209   [ #  #  #  # ]:          0 :     while (size > 0U && ctx->keystream_bytes_used < CHACHA20_BLOCK_SIZE_BYTES) {
+     210                 :          0 :         output[offset] = input[offset]
+     211                 :          0 :                          ^ ctx->keystream8[ctx->keystream_bytes_used];
+     212                 :            : 
+     213                 :          0 :         ctx->keystream_bytes_used++;
+     214                 :          0 :         offset++;
+     215                 :          0 :         size--;
+     216                 :            :     }
+     217                 :            : 
+     218                 :            :     /* Process full blocks */
+     219         [ #  # ]:          0 :     while (size >= CHACHA20_BLOCK_SIZE_BYTES) {
+     220                 :            :         /* Generate new keystream block and increment counter */
+     221                 :          0 :         chacha20_block(ctx->state, ctx->keystream8);
+     222                 :          0 :         ctx->state[CHACHA20_CTR_INDEX]++;
+     223                 :            : 
+     224                 :          0 :         mbedtls_xor(output + offset, input + offset, ctx->keystream8, 64U);
+     225                 :            : 
+     226                 :          0 :         offset += CHACHA20_BLOCK_SIZE_BYTES;
+     227                 :          0 :         size   -= CHACHA20_BLOCK_SIZE_BYTES;
+     228                 :            :     }
+     229                 :            : 
+     230                 :            :     /* Last (partial) block */
+     231         [ #  # ]:          0 :     if (size > 0U) {
+     232                 :            :         /* Generate new keystream block and increment counter */
+     233                 :          0 :         chacha20_block(ctx->state, ctx->keystream8);
+     234                 :          0 :         ctx->state[CHACHA20_CTR_INDEX]++;
+     235                 :            : 
+     236                 :          0 :         mbedtls_xor(output + offset, input + offset, ctx->keystream8, size);
+     237                 :            : 
+     238                 :          0 :         ctx->keystream_bytes_used = size;
+     239                 :            : 
+     240                 :            :     }
+     241                 :            : 
+     242                 :          0 :     return 0;
+     243                 :            : }
+     244                 :            : 
+     245                 :          0 : int mbedtls_chacha20_crypt(const unsigned char key[32],
+     246                 :            :                            const unsigned char nonce[12],
+     247                 :            :                            uint32_t counter,
+     248                 :            :                            size_t data_len,
+     249                 :            :                            const unsigned char *input,
+     250                 :            :                            unsigned char *output)
+     251                 :            : {
+     252                 :            :     mbedtls_chacha20_context ctx;
+     253                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     254                 :            : 
+     255                 :          0 :     mbedtls_chacha20_init(&ctx);
+     256                 :            : 
+     257                 :          0 :     ret = mbedtls_chacha20_setkey(&ctx, key);
+     258         [ #  # ]:          0 :     if (ret != 0) {
+     259                 :          0 :         goto cleanup;
+     260                 :            :     }
+     261                 :            : 
+     262                 :          0 :     ret = mbedtls_chacha20_starts(&ctx, nonce, counter);
+     263         [ #  # ]:          0 :     if (ret != 0) {
+     264                 :          0 :         goto cleanup;
+     265                 :            :     }
+     266                 :            : 
+     267                 :          0 :     ret = mbedtls_chacha20_update(&ctx, data_len, input, output);
+     268                 :            : 
+     269                 :          0 : cleanup:
+     270                 :          0 :     mbedtls_chacha20_free(&ctx);
+     271                 :          0 :     return ret;
+     272                 :            : }
+     273                 :            : 
+     274                 :            : #endif /* !MBEDTLS_CHACHA20_ALT */
+     275                 :            : 
+     276                 :            : #if defined(MBEDTLS_SELF_TEST)
+     277                 :            : 
+     278                 :            : static const unsigned char test_keys[2][32] =
+     279                 :            : {
+     280                 :            :     {
+     281                 :            :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+     282                 :            :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+     283                 :            :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+     284                 :            :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+     285                 :            :     },
+     286                 :            :     {
+     287                 :            :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+     288                 :            :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+     289                 :            :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+     290                 :            :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
+     291                 :            :     }
+     292                 :            : };
+     293                 :            : 
+     294                 :            : static const unsigned char test_nonces[2][12] =
+     295                 :            : {
+     296                 :            :     {
+     297                 :            :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+     298                 :            :         0x00, 0x00, 0x00, 0x00
+     299                 :            :     },
+     300                 :            :     {
+     301                 :            :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+     302                 :            :         0x00, 0x00, 0x00, 0x02
+     303                 :            :     }
+     304                 :            : };
+     305                 :            : 
+     306                 :            : static const uint32_t test_counters[2] =
+     307                 :            : {
+     308                 :            :     0U,
+     309                 :            :     1U
+     310                 :            : };
+     311                 :            : 
+     312                 :            : static const unsigned char test_input[2][375] =
+     313                 :            : {
+     314                 :            :     {
+     315                 :            :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+     316                 :            :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+     317                 :            :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+     318                 :            :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+     319                 :            :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+     320                 :            :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+     321                 :            :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+     322                 :            :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+     323                 :            :     },
+     324                 :            :     {
+     325                 :            :         0x41, 0x6e, 0x79, 0x20, 0x73, 0x75, 0x62, 0x6d,
+     326                 :            :         0x69, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x74,
+     327                 :            :         0x6f, 0x20, 0x74, 0x68, 0x65, 0x20, 0x49, 0x45,
+     328                 :            :         0x54, 0x46, 0x20, 0x69, 0x6e, 0x74, 0x65, 0x6e,
+     329                 :            :         0x64, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, 0x74,
+     330                 :            :         0x68, 0x65, 0x20, 0x43, 0x6f, 0x6e, 0x74, 0x72,
+     331                 :            :         0x69, 0x62, 0x75, 0x74, 0x6f, 0x72, 0x20, 0x66,
+     332                 :            :         0x6f, 0x72, 0x20, 0x70, 0x75, 0x62, 0x6c, 0x69,
+     333                 :            :         0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x61,
+     334                 :            :         0x73, 0x20, 0x61, 0x6c, 0x6c, 0x20, 0x6f, 0x72,
+     335                 :            :         0x20, 0x70, 0x61, 0x72, 0x74, 0x20, 0x6f, 0x66,
+     336                 :            :         0x20, 0x61, 0x6e, 0x20, 0x49, 0x45, 0x54, 0x46,
+     337                 :            :         0x20, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65,
+     338                 :            :         0x74, 0x2d, 0x44, 0x72, 0x61, 0x66, 0x74, 0x20,
+     339                 :            :         0x6f, 0x72, 0x20, 0x52, 0x46, 0x43, 0x20, 0x61,
+     340                 :            :         0x6e, 0x64, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x73,
+     341                 :            :         0x74, 0x61, 0x74, 0x65, 0x6d, 0x65, 0x6e, 0x74,
+     342                 :            :         0x20, 0x6d, 0x61, 0x64, 0x65, 0x20, 0x77, 0x69,
+     343                 :            :         0x74, 0x68, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65,
+     344                 :            :         0x20, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74,
+     345                 :            :         0x20, 0x6f, 0x66, 0x20, 0x61, 0x6e, 0x20, 0x49,
+     346                 :            :         0x45, 0x54, 0x46, 0x20, 0x61, 0x63, 0x74, 0x69,
+     347                 :            :         0x76, 0x69, 0x74, 0x79, 0x20, 0x69, 0x73, 0x20,
+     348                 :            :         0x63, 0x6f, 0x6e, 0x73, 0x69, 0x64, 0x65, 0x72,
+     349                 :            :         0x65, 0x64, 0x20, 0x61, 0x6e, 0x20, 0x22, 0x49,
+     350                 :            :         0x45, 0x54, 0x46, 0x20, 0x43, 0x6f, 0x6e, 0x74,
+     351                 :            :         0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, 0x6e,
+     352                 :            :         0x22, 0x2e, 0x20, 0x53, 0x75, 0x63, 0x68, 0x20,
+     353                 :            :         0x73, 0x74, 0x61, 0x74, 0x65, 0x6d, 0x65, 0x6e,
+     354                 :            :         0x74, 0x73, 0x20, 0x69, 0x6e, 0x63, 0x6c, 0x75,
+     355                 :            :         0x64, 0x65, 0x20, 0x6f, 0x72, 0x61, 0x6c, 0x20,
+     356                 :            :         0x73, 0x74, 0x61, 0x74, 0x65, 0x6d, 0x65, 0x6e,
+     357                 :            :         0x74, 0x73, 0x20, 0x69, 0x6e, 0x20, 0x49, 0x45,
+     358                 :            :         0x54, 0x46, 0x20, 0x73, 0x65, 0x73, 0x73, 0x69,
+     359                 :            :         0x6f, 0x6e, 0x73, 0x2c, 0x20, 0x61, 0x73, 0x20,
+     360                 :            :         0x77, 0x65, 0x6c, 0x6c, 0x20, 0x61, 0x73, 0x20,
+     361                 :            :         0x77, 0x72, 0x69, 0x74, 0x74, 0x65, 0x6e, 0x20,
+     362                 :            :         0x61, 0x6e, 0x64, 0x20, 0x65, 0x6c, 0x65, 0x63,
+     363                 :            :         0x74, 0x72, 0x6f, 0x6e, 0x69, 0x63, 0x20, 0x63,
+     364                 :            :         0x6f, 0x6d, 0x6d, 0x75, 0x6e, 0x69, 0x63, 0x61,
+     365                 :            :         0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x6d, 0x61,
+     366                 :            :         0x64, 0x65, 0x20, 0x61, 0x74, 0x20, 0x61, 0x6e,
+     367                 :            :         0x79, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x20, 0x6f,
+     368                 :            :         0x72, 0x20, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x2c,
+     369                 :            :         0x20, 0x77, 0x68, 0x69, 0x63, 0x68, 0x20, 0x61,
+     370                 :            :         0x72, 0x65, 0x20, 0x61, 0x64, 0x64, 0x72, 0x65,
+     371                 :            :         0x73, 0x73, 0x65, 0x64, 0x20, 0x74, 0x6f
+     372                 :            :     }
+     373                 :            : };
+     374                 :            : 
+     375                 :            : static const unsigned char test_output[2][375] =
+     376                 :            : {
+     377                 :            :     {
+     378                 :            :         0x76, 0xb8, 0xe0, 0xad, 0xa0, 0xf1, 0x3d, 0x90,
+     379                 :            :         0x40, 0x5d, 0x6a, 0xe5, 0x53, 0x86, 0xbd, 0x28,
+     380                 :            :         0xbd, 0xd2, 0x19, 0xb8, 0xa0, 0x8d, 0xed, 0x1a,
+     381                 :            :         0xa8, 0x36, 0xef, 0xcc, 0x8b, 0x77, 0x0d, 0xc7,
+     382                 :            :         0xda, 0x41, 0x59, 0x7c, 0x51, 0x57, 0x48, 0x8d,
+     383                 :            :         0x77, 0x24, 0xe0, 0x3f, 0xb8, 0xd8, 0x4a, 0x37,
+     384                 :            :         0x6a, 0x43, 0xb8, 0xf4, 0x15, 0x18, 0xa1, 0x1c,
+     385                 :            :         0xc3, 0x87, 0xb6, 0x69, 0xb2, 0xee, 0x65, 0x86
+     386                 :            :     },
+     387                 :            :     {
+     388                 :            :         0xa3, 0xfb, 0xf0, 0x7d, 0xf3, 0xfa, 0x2f, 0xde,
+     389                 :            :         0x4f, 0x37, 0x6c, 0xa2, 0x3e, 0x82, 0x73, 0x70,
+     390                 :            :         0x41, 0x60, 0x5d, 0x9f, 0x4f, 0x4f, 0x57, 0xbd,
+     391                 :            :         0x8c, 0xff, 0x2c, 0x1d, 0x4b, 0x79, 0x55, 0xec,
+     392                 :            :         0x2a, 0x97, 0x94, 0x8b, 0xd3, 0x72, 0x29, 0x15,
+     393                 :            :         0xc8, 0xf3, 0xd3, 0x37, 0xf7, 0xd3, 0x70, 0x05,
+     394                 :            :         0x0e, 0x9e, 0x96, 0xd6, 0x47, 0xb7, 0xc3, 0x9f,
+     395                 :            :         0x56, 0xe0, 0x31, 0xca, 0x5e, 0xb6, 0x25, 0x0d,
+     396                 :            :         0x40, 0x42, 0xe0, 0x27, 0x85, 0xec, 0xec, 0xfa,
+     397                 :            :         0x4b, 0x4b, 0xb5, 0xe8, 0xea, 0xd0, 0x44, 0x0e,
+     398                 :            :         0x20, 0xb6, 0xe8, 0xdb, 0x09, 0xd8, 0x81, 0xa7,
+     399                 :            :         0xc6, 0x13, 0x2f, 0x42, 0x0e, 0x52, 0x79, 0x50,
+     400                 :            :         0x42, 0xbd, 0xfa, 0x77, 0x73, 0xd8, 0xa9, 0x05,
+     401                 :            :         0x14, 0x47, 0xb3, 0x29, 0x1c, 0xe1, 0x41, 0x1c,
+     402                 :            :         0x68, 0x04, 0x65, 0x55, 0x2a, 0xa6, 0xc4, 0x05,
+     403                 :            :         0xb7, 0x76, 0x4d, 0x5e, 0x87, 0xbe, 0xa8, 0x5a,
+     404                 :            :         0xd0, 0x0f, 0x84, 0x49, 0xed, 0x8f, 0x72, 0xd0,
+     405                 :            :         0xd6, 0x62, 0xab, 0x05, 0x26, 0x91, 0xca, 0x66,
+     406                 :            :         0x42, 0x4b, 0xc8, 0x6d, 0x2d, 0xf8, 0x0e, 0xa4,
+     407                 :            :         0x1f, 0x43, 0xab, 0xf9, 0x37, 0xd3, 0x25, 0x9d,
+     408                 :            :         0xc4, 0xb2, 0xd0, 0xdf, 0xb4, 0x8a, 0x6c, 0x91,
+     409                 :            :         0x39, 0xdd, 0xd7, 0xf7, 0x69, 0x66, 0xe9, 0x28,
+     410                 :            :         0xe6, 0x35, 0x55, 0x3b, 0xa7, 0x6c, 0x5c, 0x87,
+     411                 :            :         0x9d, 0x7b, 0x35, 0xd4, 0x9e, 0xb2, 0xe6, 0x2b,
+     412                 :            :         0x08, 0x71, 0xcd, 0xac, 0x63, 0x89, 0x39, 0xe2,
+     413                 :            :         0x5e, 0x8a, 0x1e, 0x0e, 0xf9, 0xd5, 0x28, 0x0f,
+     414                 :            :         0xa8, 0xca, 0x32, 0x8b, 0x35, 0x1c, 0x3c, 0x76,
+     415                 :            :         0x59, 0x89, 0xcb, 0xcf, 0x3d, 0xaa, 0x8b, 0x6c,
+     416                 :            :         0xcc, 0x3a, 0xaf, 0x9f, 0x39, 0x79, 0xc9, 0x2b,
+     417                 :            :         0x37, 0x20, 0xfc, 0x88, 0xdc, 0x95, 0xed, 0x84,
+     418                 :            :         0xa1, 0xbe, 0x05, 0x9c, 0x64, 0x99, 0xb9, 0xfd,
+     419                 :            :         0xa2, 0x36, 0xe7, 0xe8, 0x18, 0xb0, 0x4b, 0x0b,
+     420                 :            :         0xc3, 0x9c, 0x1e, 0x87, 0x6b, 0x19, 0x3b, 0xfe,
+     421                 :            :         0x55, 0x69, 0x75, 0x3f, 0x88, 0x12, 0x8c, 0xc0,
+     422                 :            :         0x8a, 0xaa, 0x9b, 0x63, 0xd1, 0xa1, 0x6f, 0x80,
+     423                 :            :         0xef, 0x25, 0x54, 0xd7, 0x18, 0x9c, 0x41, 0x1f,
+     424                 :            :         0x58, 0x69, 0xca, 0x52, 0xc5, 0xb8, 0x3f, 0xa3,
+     425                 :            :         0x6f, 0xf2, 0x16, 0xb9, 0xc1, 0xd3, 0x00, 0x62,
+     426                 :            :         0xbe, 0xbc, 0xfd, 0x2d, 0xc5, 0xbc, 0xe0, 0x91,
+     427                 :            :         0x19, 0x34, 0xfd, 0xa7, 0x9a, 0x86, 0xf6, 0xe6,
+     428                 :            :         0x98, 0xce, 0xd7, 0x59, 0xc3, 0xff, 0x9b, 0x64,
+     429                 :            :         0x77, 0x33, 0x8f, 0x3d, 0xa4, 0xf9, 0xcd, 0x85,
+     430                 :            :         0x14, 0xea, 0x99, 0x82, 0xcc, 0xaf, 0xb3, 0x41,
+     431                 :            :         0xb2, 0x38, 0x4d, 0xd9, 0x02, 0xf3, 0xd1, 0xab,
+     432                 :            :         0x7a, 0xc6, 0x1d, 0xd2, 0x9c, 0x6f, 0x21, 0xba,
+     433                 :            :         0x5b, 0x86, 0x2f, 0x37, 0x30, 0xe3, 0x7c, 0xfd,
+     434                 :            :         0xc4, 0xfd, 0x80, 0x6c, 0x22, 0xf2, 0x21
+     435                 :            :     }
+     436                 :            : };
+     437                 :            : 
+     438                 :            : static const size_t test_lengths[2] =
+     439                 :            : {
+     440                 :            :     64U,
+     441                 :            :     375U
+     442                 :            : };
+     443                 :            : 
+     444                 :            : /* Make sure no other definition is already present. */
+     445                 :            : #undef ASSERT
+     446                 :            : 
+     447                 :            : #define ASSERT(cond, args)            \
+     448                 :            :     do                                  \
+     449                 :            :     {                                   \
+     450                 :            :         if (!(cond))                \
+     451                 :            :         {                               \
+     452                 :            :             if (verbose != 0)          \
+     453                 :            :             mbedtls_printf args;    \
+     454                 :            :                                         \
+     455                 :            :             return -1;               \
+     456                 :            :         }                               \
+     457                 :            :     }                                   \
+     458                 :            :     while (0)
+     459                 :            : 
+     460                 :          0 : int mbedtls_chacha20_self_test(int verbose)
+     461                 :            : {
+     462                 :            :     unsigned char output[381];
+     463                 :            :     unsigned i;
+     464                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     465                 :            : 
+     466         [ #  # ]:          0 :     for (i = 0U; i < 2U; i++) {
+     467         [ #  # ]:          0 :         if (verbose != 0) {
+     468                 :          0 :             mbedtls_printf("  ChaCha20 test %u ", i);
+     469                 :            :         }
+     470                 :            : 
+     471                 :          0 :         ret = mbedtls_chacha20_crypt(test_keys[i],
+     472                 :          0 :                                      test_nonces[i],
+     473                 :          0 :                                      test_counters[i],
+     474                 :          0 :                                      test_lengths[i],
+     475                 :          0 :                                      test_input[i],
+     476                 :            :                                      output);
+     477                 :            : 
+     478   [ #  #  #  # ]:          0 :         ASSERT(0 == ret, ("error code: %i\n", ret));
+     479                 :            : 
+     480   [ #  #  #  # ]:          0 :         ASSERT(0 == memcmp(output, test_output[i], test_lengths[i]),
+     481                 :            :                ("failed (output)\n"));
+     482                 :            : 
+     483         [ #  # ]:          0 :         if (verbose != 0) {
+     484                 :          0 :             mbedtls_printf("passed\n");
+     485                 :            :         }
+     486                 :            :     }
+     487                 :            : 
+     488         [ #  # ]:          0 :     if (verbose != 0) {
+     489                 :          0 :         mbedtls_printf("\n");
+     490                 :            :     }
+     491                 :            : 
+     492                 :          0 :     return 0;
+     493                 :            : }
+     494                 :            : 
+     495                 :            : #endif /* MBEDTLS_SELF_TEST */
+     496                 :            : 
+     497                 :            : #endif /* !MBEDTLS_CHACHA20_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/chachapoly.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/chachapoly.c.func-sort-c.html new file mode 100644 index 00000000000..5c2a83523fc --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/chachapoly.c.func-sort-c.html @@ -0,0 +1,133 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/chachapoly.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - chachapoly.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:01510.0 %
Date:2024-09-22 08:21:07Functions:0130.0 %
Branches:0780.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
chachapoly_crypt_and_tag0
chachapoly_pad_aad0
chachapoly_pad_ciphertext0
mbedtls_chachapoly_auth_decrypt0
mbedtls_chachapoly_encrypt_and_tag0
mbedtls_chachapoly_finish0
mbedtls_chachapoly_free0
mbedtls_chachapoly_init0
mbedtls_chachapoly_self_test0
mbedtls_chachapoly_setkey0
mbedtls_chachapoly_starts0
mbedtls_chachapoly_update0
mbedtls_chachapoly_update_aad0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/chachapoly.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/chachapoly.c.func.html new file mode 100644 index 00000000000..5f92b8eeb1b --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/chachapoly.c.func.html @@ -0,0 +1,133 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/chachapoly.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - chachapoly.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:01510.0 %
Date:2024-09-22 08:21:07Functions:0130.0 %
Branches:0780.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
chachapoly_crypt_and_tag0
chachapoly_pad_aad0
chachapoly_pad_ciphertext0
mbedtls_chachapoly_auth_decrypt0
mbedtls_chachapoly_encrypt_and_tag0
mbedtls_chachapoly_finish0
mbedtls_chachapoly_free0
mbedtls_chachapoly_init0
mbedtls_chachapoly_self_test0
mbedtls_chachapoly_setkey0
mbedtls_chachapoly_starts0
mbedtls_chachapoly_update0
mbedtls_chachapoly_update_aad0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/chachapoly.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/chachapoly.c.gcov.html new file mode 100644 index 00000000000..0e179e81e86 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/chachapoly.c.gcov.html @@ -0,0 +1,563 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/chachapoly.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - chachapoly.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:01510.0 %
Date:2024-09-22 08:21:07Functions:0130.0 %
Branches:0780.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  * \file chachapoly.c
+       3                 :            :  *
+       4                 :            :  * \brief ChaCha20-Poly1305 AEAD construction based on RFC 7539.
+       5                 :            :  *
+       6                 :            :  *  Copyright The Mbed TLS Contributors
+       7                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       8                 :            :  */
+       9                 :            : #include "common.h"
+      10                 :            : 
+      11                 :            : #if defined(MBEDTLS_CHACHAPOLY_C)
+      12                 :            : 
+      13                 :            : #include "mbedtls/chachapoly.h"
+      14                 :            : #include "mbedtls/platform_util.h"
+      15                 :            : #include "mbedtls/error.h"
+      16                 :            : #include "mbedtls/constant_time.h"
+      17                 :            : 
+      18                 :            : #include <string.h>
+      19                 :            : 
+      20                 :            : #include "mbedtls/platform.h"
+      21                 :            : 
+      22                 :            : #if !defined(MBEDTLS_CHACHAPOLY_ALT)
+      23                 :            : 
+      24                 :            : #define CHACHAPOLY_STATE_INIT       (0)
+      25                 :            : #define CHACHAPOLY_STATE_AAD        (1)
+      26                 :            : #define CHACHAPOLY_STATE_CIPHERTEXT (2)   /* Encrypting or decrypting */
+      27                 :            : #define CHACHAPOLY_STATE_FINISHED   (3)
+      28                 :            : 
+      29                 :            : /**
+      30                 :            :  * \brief           Adds nul bytes to pad the AAD for Poly1305.
+      31                 :            :  *
+      32                 :            :  * \param ctx       The ChaCha20-Poly1305 context.
+      33                 :            :  */
+      34                 :          0 : static int chachapoly_pad_aad(mbedtls_chachapoly_context *ctx)
+      35                 :            : {
+      36                 :          0 :     uint32_t partial_block_len = (uint32_t) (ctx->aad_len % 16U);
+      37                 :            :     unsigned char zeroes[15];
+      38                 :            : 
+      39         [ #  # ]:          0 :     if (partial_block_len == 0U) {
+      40                 :          0 :         return 0;
+      41                 :            :     }
+      42                 :            : 
+      43                 :          0 :     memset(zeroes, 0, sizeof(zeroes));
+      44                 :            : 
+      45                 :          0 :     return mbedtls_poly1305_update(&ctx->poly1305_ctx,
+      46                 :            :                                    zeroes,
+      47                 :          0 :                                    16U - partial_block_len);
+      48                 :            : }
+      49                 :            : 
+      50                 :            : /**
+      51                 :            :  * \brief           Adds nul bytes to pad the ciphertext for Poly1305.
+      52                 :            :  *
+      53                 :            :  * \param ctx       The ChaCha20-Poly1305 context.
+      54                 :            :  */
+      55                 :          0 : static int chachapoly_pad_ciphertext(mbedtls_chachapoly_context *ctx)
+      56                 :            : {
+      57                 :          0 :     uint32_t partial_block_len = (uint32_t) (ctx->ciphertext_len % 16U);
+      58                 :            :     unsigned char zeroes[15];
+      59                 :            : 
+      60         [ #  # ]:          0 :     if (partial_block_len == 0U) {
+      61                 :          0 :         return 0;
+      62                 :            :     }
+      63                 :            : 
+      64                 :          0 :     memset(zeroes, 0, sizeof(zeroes));
+      65                 :          0 :     return mbedtls_poly1305_update(&ctx->poly1305_ctx,
+      66                 :            :                                    zeroes,
+      67                 :          0 :                                    16U - partial_block_len);
+      68                 :            : }
+      69                 :            : 
+      70                 :          0 : void mbedtls_chachapoly_init(mbedtls_chachapoly_context *ctx)
+      71                 :            : {
+      72                 :          0 :     mbedtls_chacha20_init(&ctx->chacha20_ctx);
+      73                 :          0 :     mbedtls_poly1305_init(&ctx->poly1305_ctx);
+      74                 :          0 :     ctx->aad_len        = 0U;
+      75                 :          0 :     ctx->ciphertext_len = 0U;
+      76                 :          0 :     ctx->state          = CHACHAPOLY_STATE_INIT;
+      77                 :          0 :     ctx->mode           = MBEDTLS_CHACHAPOLY_ENCRYPT;
+      78                 :          0 : }
+      79                 :            : 
+      80                 :          0 : void mbedtls_chachapoly_free(mbedtls_chachapoly_context *ctx)
+      81                 :            : {
+      82         [ #  # ]:          0 :     if (ctx == NULL) {
+      83                 :          0 :         return;
+      84                 :            :     }
+      85                 :            : 
+      86                 :          0 :     mbedtls_chacha20_free(&ctx->chacha20_ctx);
+      87                 :          0 :     mbedtls_poly1305_free(&ctx->poly1305_ctx);
+      88                 :          0 :     ctx->aad_len        = 0U;
+      89                 :          0 :     ctx->ciphertext_len = 0U;
+      90                 :          0 :     ctx->state          = CHACHAPOLY_STATE_INIT;
+      91                 :          0 :     ctx->mode           = MBEDTLS_CHACHAPOLY_ENCRYPT;
+      92                 :            : }
+      93                 :            : 
+      94                 :          0 : int mbedtls_chachapoly_setkey(mbedtls_chachapoly_context *ctx,
+      95                 :            :                               const unsigned char key[32])
+      96                 :            : {
+      97                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+      98                 :            : 
+      99                 :          0 :     ret = mbedtls_chacha20_setkey(&ctx->chacha20_ctx, key);
+     100                 :            : 
+     101                 :          0 :     return ret;
+     102                 :            : }
+     103                 :            : 
+     104                 :          0 : int mbedtls_chachapoly_starts(mbedtls_chachapoly_context *ctx,
+     105                 :            :                               const unsigned char nonce[12],
+     106                 :            :                               mbedtls_chachapoly_mode_t mode)
+     107                 :            : {
+     108                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     109                 :            :     unsigned char poly1305_key[64];
+     110                 :            : 
+     111                 :            :     /* Set counter = 0, will be update to 1 when generating Poly1305 key */
+     112                 :          0 :     ret = mbedtls_chacha20_starts(&ctx->chacha20_ctx, nonce, 0U);
+     113         [ #  # ]:          0 :     if (ret != 0) {
+     114                 :          0 :         goto cleanup;
+     115                 :            :     }
+     116                 :            : 
+     117                 :            :     /* Generate the Poly1305 key by getting the ChaCha20 keystream output with
+     118                 :            :      * counter = 0.  This is the same as encrypting a buffer of zeroes.
+     119                 :            :      * Only the first 256-bits (32 bytes) of the key is used for Poly1305.
+     120                 :            :      * The other 256 bits are discarded.
+     121                 :            :      */
+     122                 :          0 :     memset(poly1305_key, 0, sizeof(poly1305_key));
+     123                 :          0 :     ret = mbedtls_chacha20_update(&ctx->chacha20_ctx, sizeof(poly1305_key),
+     124                 :            :                                   poly1305_key, poly1305_key);
+     125         [ #  # ]:          0 :     if (ret != 0) {
+     126                 :          0 :         goto cleanup;
+     127                 :            :     }
+     128                 :            : 
+     129                 :          0 :     ret = mbedtls_poly1305_starts(&ctx->poly1305_ctx, poly1305_key);
+     130                 :            : 
+     131         [ #  # ]:          0 :     if (ret == 0) {
+     132                 :          0 :         ctx->aad_len        = 0U;
+     133                 :          0 :         ctx->ciphertext_len = 0U;
+     134                 :          0 :         ctx->state          = CHACHAPOLY_STATE_AAD;
+     135                 :          0 :         ctx->mode           = mode;
+     136                 :            :     }
+     137                 :            : 
+     138                 :          0 : cleanup:
+     139                 :          0 :     mbedtls_platform_zeroize(poly1305_key, 64U);
+     140                 :          0 :     return ret;
+     141                 :            : }
+     142                 :            : 
+     143                 :          0 : int mbedtls_chachapoly_update_aad(mbedtls_chachapoly_context *ctx,
+     144                 :            :                                   const unsigned char *aad,
+     145                 :            :                                   size_t aad_len)
+     146                 :            : {
+     147         [ #  # ]:          0 :     if (ctx->state != CHACHAPOLY_STATE_AAD) {
+     148                 :          0 :         return MBEDTLS_ERR_CHACHAPOLY_BAD_STATE;
+     149                 :            :     }
+     150                 :            : 
+     151                 :          0 :     ctx->aad_len += aad_len;
+     152                 :            : 
+     153                 :          0 :     return mbedtls_poly1305_update(&ctx->poly1305_ctx, aad, aad_len);
+     154                 :            : }
+     155                 :            : 
+     156                 :          0 : int mbedtls_chachapoly_update(mbedtls_chachapoly_context *ctx,
+     157                 :            :                               size_t len,
+     158                 :            :                               const unsigned char *input,
+     159                 :            :                               unsigned char *output)
+     160                 :            : {
+     161                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     162                 :            : 
+     163         [ #  # ]:          0 :     if ((ctx->state != CHACHAPOLY_STATE_AAD) &&
+     164         [ #  # ]:          0 :         (ctx->state != CHACHAPOLY_STATE_CIPHERTEXT)) {
+     165                 :          0 :         return MBEDTLS_ERR_CHACHAPOLY_BAD_STATE;
+     166                 :            :     }
+     167                 :            : 
+     168         [ #  # ]:          0 :     if (ctx->state == CHACHAPOLY_STATE_AAD) {
+     169                 :          0 :         ctx->state = CHACHAPOLY_STATE_CIPHERTEXT;
+     170                 :            : 
+     171                 :          0 :         ret = chachapoly_pad_aad(ctx);
+     172         [ #  # ]:          0 :         if (ret != 0) {
+     173                 :          0 :             return ret;
+     174                 :            :         }
+     175                 :            :     }
+     176                 :            : 
+     177                 :          0 :     ctx->ciphertext_len += len;
+     178                 :            : 
+     179         [ #  # ]:          0 :     if (ctx->mode == MBEDTLS_CHACHAPOLY_ENCRYPT) {
+     180                 :          0 :         ret = mbedtls_chacha20_update(&ctx->chacha20_ctx, len, input, output);
+     181         [ #  # ]:          0 :         if (ret != 0) {
+     182                 :          0 :             return ret;
+     183                 :            :         }
+     184                 :            : 
+     185                 :          0 :         ret = mbedtls_poly1305_update(&ctx->poly1305_ctx, output, len);
+     186         [ #  # ]:          0 :         if (ret != 0) {
+     187                 :          0 :             return ret;
+     188                 :            :         }
+     189                 :            :     } else { /* DECRYPT */
+     190                 :          0 :         ret = mbedtls_poly1305_update(&ctx->poly1305_ctx, input, len);
+     191         [ #  # ]:          0 :         if (ret != 0) {
+     192                 :          0 :             return ret;
+     193                 :            :         }
+     194                 :            : 
+     195                 :          0 :         ret = mbedtls_chacha20_update(&ctx->chacha20_ctx, len, input, output);
+     196         [ #  # ]:          0 :         if (ret != 0) {
+     197                 :          0 :             return ret;
+     198                 :            :         }
+     199                 :            :     }
+     200                 :            : 
+     201                 :          0 :     return 0;
+     202                 :            : }
+     203                 :            : 
+     204                 :          0 : int mbedtls_chachapoly_finish(mbedtls_chachapoly_context *ctx,
+     205                 :            :                               unsigned char mac[16])
+     206                 :            : {
+     207                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     208                 :            :     unsigned char len_block[16];
+     209                 :            : 
+     210         [ #  # ]:          0 :     if (ctx->state == CHACHAPOLY_STATE_INIT) {
+     211                 :          0 :         return MBEDTLS_ERR_CHACHAPOLY_BAD_STATE;
+     212                 :            :     }
+     213                 :            : 
+     214         [ #  # ]:          0 :     if (ctx->state == CHACHAPOLY_STATE_AAD) {
+     215                 :          0 :         ret = chachapoly_pad_aad(ctx);
+     216         [ #  # ]:          0 :         if (ret != 0) {
+     217                 :          0 :             return ret;
+     218                 :            :         }
+     219         [ #  # ]:          0 :     } else if (ctx->state == CHACHAPOLY_STATE_CIPHERTEXT) {
+     220                 :          0 :         ret = chachapoly_pad_ciphertext(ctx);
+     221         [ #  # ]:          0 :         if (ret != 0) {
+     222                 :          0 :             return ret;
+     223                 :            :         }
+     224                 :            :     }
+     225                 :            : 
+     226                 :          0 :     ctx->state = CHACHAPOLY_STATE_FINISHED;
+     227                 :            : 
+     228                 :            :     /* The lengths of the AAD and ciphertext are processed by
+     229                 :            :      * Poly1305 as the final 128-bit block, encoded as little-endian integers.
+     230                 :            :      */
+     231                 :          0 :     MBEDTLS_PUT_UINT64_LE(ctx->aad_len, len_block, 0);
+     232                 :          0 :     MBEDTLS_PUT_UINT64_LE(ctx->ciphertext_len, len_block, 8);
+     233                 :            : 
+     234                 :          0 :     ret = mbedtls_poly1305_update(&ctx->poly1305_ctx, len_block, 16U);
+     235         [ #  # ]:          0 :     if (ret != 0) {
+     236                 :          0 :         return ret;
+     237                 :            :     }
+     238                 :            : 
+     239                 :          0 :     ret = mbedtls_poly1305_finish(&ctx->poly1305_ctx, mac);
+     240                 :            : 
+     241                 :          0 :     return ret;
+     242                 :            : }
+     243                 :            : 
+     244                 :          0 : static int chachapoly_crypt_and_tag(mbedtls_chachapoly_context *ctx,
+     245                 :            :                                     mbedtls_chachapoly_mode_t mode,
+     246                 :            :                                     size_t length,
+     247                 :            :                                     const unsigned char nonce[12],
+     248                 :            :                                     const unsigned char *aad,
+     249                 :            :                                     size_t aad_len,
+     250                 :            :                                     const unsigned char *input,
+     251                 :            :                                     unsigned char *output,
+     252                 :            :                                     unsigned char tag[16])
+     253                 :            : {
+     254                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     255                 :            : 
+     256                 :          0 :     ret = mbedtls_chachapoly_starts(ctx, nonce, mode);
+     257         [ #  # ]:          0 :     if (ret != 0) {
+     258                 :          0 :         goto cleanup;
+     259                 :            :     }
+     260                 :            : 
+     261                 :          0 :     ret = mbedtls_chachapoly_update_aad(ctx, aad, aad_len);
+     262         [ #  # ]:          0 :     if (ret != 0) {
+     263                 :          0 :         goto cleanup;
+     264                 :            :     }
+     265                 :            : 
+     266                 :          0 :     ret = mbedtls_chachapoly_update(ctx, length, input, output);
+     267         [ #  # ]:          0 :     if (ret != 0) {
+     268                 :          0 :         goto cleanup;
+     269                 :            :     }
+     270                 :            : 
+     271                 :          0 :     ret = mbedtls_chachapoly_finish(ctx, tag);
+     272                 :            : 
+     273                 :          0 : cleanup:
+     274                 :          0 :     return ret;
+     275                 :            : }
+     276                 :            : 
+     277                 :          0 : int mbedtls_chachapoly_encrypt_and_tag(mbedtls_chachapoly_context *ctx,
+     278                 :            :                                        size_t length,
+     279                 :            :                                        const unsigned char nonce[12],
+     280                 :            :                                        const unsigned char *aad,
+     281                 :            :                                        size_t aad_len,
+     282                 :            :                                        const unsigned char *input,
+     283                 :            :                                        unsigned char *output,
+     284                 :            :                                        unsigned char tag[16])
+     285                 :            : {
+     286                 :          0 :     return chachapoly_crypt_and_tag(ctx, MBEDTLS_CHACHAPOLY_ENCRYPT,
+     287                 :            :                                     length, nonce, aad, aad_len,
+     288                 :            :                                     input, output, tag);
+     289                 :            : }
+     290                 :            : 
+     291                 :          0 : int mbedtls_chachapoly_auth_decrypt(mbedtls_chachapoly_context *ctx,
+     292                 :            :                                     size_t length,
+     293                 :            :                                     const unsigned char nonce[12],
+     294                 :            :                                     const unsigned char *aad,
+     295                 :            :                                     size_t aad_len,
+     296                 :            :                                     const unsigned char tag[16],
+     297                 :            :                                     const unsigned char *input,
+     298                 :            :                                     unsigned char *output)
+     299                 :            : {
+     300                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     301                 :            :     unsigned char check_tag[16];
+     302                 :            :     int diff;
+     303                 :            : 
+     304         [ #  # ]:          0 :     if ((ret = chachapoly_crypt_and_tag(ctx,
+     305                 :            :                                         MBEDTLS_CHACHAPOLY_DECRYPT, length, nonce,
+     306                 :            :                                         aad, aad_len, input, output, check_tag)) != 0) {
+     307                 :          0 :         return ret;
+     308                 :            :     }
+     309                 :            : 
+     310                 :            :     /* Check tag in "constant-time" */
+     311                 :          0 :     diff = mbedtls_ct_memcmp(tag, check_tag, sizeof(check_tag));
+     312                 :            : 
+     313         [ #  # ]:          0 :     if (diff != 0) {
+     314                 :          0 :         mbedtls_platform_zeroize(output, length);
+     315                 :          0 :         return MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED;
+     316                 :            :     }
+     317                 :            : 
+     318                 :          0 :     return 0;
+     319                 :            : }
+     320                 :            : 
+     321                 :            : #endif /* MBEDTLS_CHACHAPOLY_ALT */
+     322                 :            : 
+     323                 :            : #if defined(MBEDTLS_SELF_TEST)
+     324                 :            : 
+     325                 :            : static const unsigned char test_key[1][32] =
+     326                 :            : {
+     327                 :            :     {
+     328                 :            :         0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
+     329                 :            :         0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
+     330                 :            :         0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
+     331                 :            :         0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f
+     332                 :            :     }
+     333                 :            : };
+     334                 :            : 
+     335                 :            : static const unsigned char test_nonce[1][12] =
+     336                 :            : {
+     337                 :            :     {
+     338                 :            :         0x07, 0x00, 0x00, 0x00,                         /* 32-bit common part */
+     339                 :            :         0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47  /* 64-bit IV */
+     340                 :            :     }
+     341                 :            : };
+     342                 :            : 
+     343                 :            : static const unsigned char test_aad[1][12] =
+     344                 :            : {
+     345                 :            :     {
+     346                 :            :         0x50, 0x51, 0x52, 0x53, 0xc0, 0xc1, 0xc2, 0xc3,
+     347                 :            :         0xc4, 0xc5, 0xc6, 0xc7
+     348                 :            :     }
+     349                 :            : };
+     350                 :            : 
+     351                 :            : static const size_t test_aad_len[1] =
+     352                 :            : {
+     353                 :            :     12U
+     354                 :            : };
+     355                 :            : 
+     356                 :            : static const unsigned char test_input[1][114] =
+     357                 :            : {
+     358                 :            :     {
+     359                 :            :         0x4c, 0x61, 0x64, 0x69, 0x65, 0x73, 0x20, 0x61,
+     360                 :            :         0x6e, 0x64, 0x20, 0x47, 0x65, 0x6e, 0x74, 0x6c,
+     361                 :            :         0x65, 0x6d, 0x65, 0x6e, 0x20, 0x6f, 0x66, 0x20,
+     362                 :            :         0x74, 0x68, 0x65, 0x20, 0x63, 0x6c, 0x61, 0x73,
+     363                 :            :         0x73, 0x20, 0x6f, 0x66, 0x20, 0x27, 0x39, 0x39,
+     364                 :            :         0x3a, 0x20, 0x49, 0x66, 0x20, 0x49, 0x20, 0x63,
+     365                 :            :         0x6f, 0x75, 0x6c, 0x64, 0x20, 0x6f, 0x66, 0x66,
+     366                 :            :         0x65, 0x72, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x6f,
+     367                 :            :         0x6e, 0x6c, 0x79, 0x20, 0x6f, 0x6e, 0x65, 0x20,
+     368                 :            :         0x74, 0x69, 0x70, 0x20, 0x66, 0x6f, 0x72, 0x20,
+     369                 :            :         0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x74, 0x75,
+     370                 :            :         0x72, 0x65, 0x2c, 0x20, 0x73, 0x75, 0x6e, 0x73,
+     371                 :            :         0x63, 0x72, 0x65, 0x65, 0x6e, 0x20, 0x77, 0x6f,
+     372                 :            :         0x75, 0x6c, 0x64, 0x20, 0x62, 0x65, 0x20, 0x69,
+     373                 :            :         0x74, 0x2e
+     374                 :            :     }
+     375                 :            : };
+     376                 :            : 
+     377                 :            : static const unsigned char test_output[1][114] =
+     378                 :            : {
+     379                 :            :     {
+     380                 :            :         0xd3, 0x1a, 0x8d, 0x34, 0x64, 0x8e, 0x60, 0xdb,
+     381                 :            :         0x7b, 0x86, 0xaf, 0xbc, 0x53, 0xef, 0x7e, 0xc2,
+     382                 :            :         0xa4, 0xad, 0xed, 0x51, 0x29, 0x6e, 0x08, 0xfe,
+     383                 :            :         0xa9, 0xe2, 0xb5, 0xa7, 0x36, 0xee, 0x62, 0xd6,
+     384                 :            :         0x3d, 0xbe, 0xa4, 0x5e, 0x8c, 0xa9, 0x67, 0x12,
+     385                 :            :         0x82, 0xfa, 0xfb, 0x69, 0xda, 0x92, 0x72, 0x8b,
+     386                 :            :         0x1a, 0x71, 0xde, 0x0a, 0x9e, 0x06, 0x0b, 0x29,
+     387                 :            :         0x05, 0xd6, 0xa5, 0xb6, 0x7e, 0xcd, 0x3b, 0x36,
+     388                 :            :         0x92, 0xdd, 0xbd, 0x7f, 0x2d, 0x77, 0x8b, 0x8c,
+     389                 :            :         0x98, 0x03, 0xae, 0xe3, 0x28, 0x09, 0x1b, 0x58,
+     390                 :            :         0xfa, 0xb3, 0x24, 0xe4, 0xfa, 0xd6, 0x75, 0x94,
+     391                 :            :         0x55, 0x85, 0x80, 0x8b, 0x48, 0x31, 0xd7, 0xbc,
+     392                 :            :         0x3f, 0xf4, 0xde, 0xf0, 0x8e, 0x4b, 0x7a, 0x9d,
+     393                 :            :         0xe5, 0x76, 0xd2, 0x65, 0x86, 0xce, 0xc6, 0x4b,
+     394                 :            :         0x61, 0x16
+     395                 :            :     }
+     396                 :            : };
+     397                 :            : 
+     398                 :            : static const size_t test_input_len[1] =
+     399                 :            : {
+     400                 :            :     114U
+     401                 :            : };
+     402                 :            : 
+     403                 :            : static const unsigned char test_mac[1][16] =
+     404                 :            : {
+     405                 :            :     {
+     406                 :            :         0x1a, 0xe1, 0x0b, 0x59, 0x4f, 0x09, 0xe2, 0x6a,
+     407                 :            :         0x7e, 0x90, 0x2e, 0xcb, 0xd0, 0x60, 0x06, 0x91
+     408                 :            :     }
+     409                 :            : };
+     410                 :            : 
+     411                 :            : /* Make sure no other definition is already present. */
+     412                 :            : #undef ASSERT
+     413                 :            : 
+     414                 :            : #define ASSERT(cond, args)            \
+     415                 :            :     do                                  \
+     416                 :            :     {                                   \
+     417                 :            :         if (!(cond))                \
+     418                 :            :         {                               \
+     419                 :            :             if (verbose != 0)          \
+     420                 :            :             mbedtls_printf args;    \
+     421                 :            :                                         \
+     422                 :            :             return -1;               \
+     423                 :            :         }                               \
+     424                 :            :     }                                   \
+     425                 :            :     while (0)
+     426                 :            : 
+     427                 :          0 : int mbedtls_chachapoly_self_test(int verbose)
+     428                 :            : {
+     429                 :            :     mbedtls_chachapoly_context ctx;
+     430                 :            :     unsigned i;
+     431                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     432                 :            :     unsigned char output[200];
+     433                 :            :     unsigned char mac[16];
+     434                 :            : 
+     435         [ #  # ]:          0 :     for (i = 0U; i < 1U; i++) {
+     436         [ #  # ]:          0 :         if (verbose != 0) {
+     437                 :          0 :             mbedtls_printf("  ChaCha20-Poly1305 test %u ", i);
+     438                 :            :         }
+     439                 :            : 
+     440                 :          0 :         mbedtls_chachapoly_init(&ctx);
+     441                 :            : 
+     442                 :          0 :         ret = mbedtls_chachapoly_setkey(&ctx, test_key[i]);
+     443   [ #  #  #  # ]:          0 :         ASSERT(0 == ret, ("setkey() error code: %i\n", ret));
+     444                 :            : 
+     445                 :          0 :         ret = mbedtls_chachapoly_encrypt_and_tag(&ctx,
+     446                 :          0 :                                                  test_input_len[i],
+     447                 :          0 :                                                  test_nonce[i],
+     448                 :          0 :                                                  test_aad[i],
+     449                 :          0 :                                                  test_aad_len[i],
+     450                 :          0 :                                                  test_input[i],
+     451                 :            :                                                  output,
+     452                 :            :                                                  mac);
+     453                 :            : 
+     454   [ #  #  #  # ]:          0 :         ASSERT(0 == ret, ("crypt_and_tag() error code: %i\n", ret));
+     455                 :            : 
+     456   [ #  #  #  # ]:          0 :         ASSERT(0 == memcmp(output, test_output[i], test_input_len[i]),
+     457                 :            :                ("failure (wrong output)\n"));
+     458                 :            : 
+     459   [ #  #  #  # ]:          0 :         ASSERT(0 == memcmp(mac, test_mac[i], 16U),
+     460                 :            :                ("failure (wrong MAC)\n"));
+     461                 :            : 
+     462                 :          0 :         mbedtls_chachapoly_free(&ctx);
+     463                 :            : 
+     464         [ #  # ]:          0 :         if (verbose != 0) {
+     465                 :          0 :             mbedtls_printf("passed\n");
+     466                 :            :         }
+     467                 :            :     }
+     468                 :            : 
+     469         [ #  # ]:          0 :     if (verbose != 0) {
+     470                 :          0 :         mbedtls_printf("\n");
+     471                 :            :     }
+     472                 :            : 
+     473                 :          0 :     return 0;
+     474                 :            : }
+     475                 :            : 
+     476                 :            : #endif /* MBEDTLS_SELF_TEST */
+     477                 :            : 
+     478                 :            : #endif /* MBEDTLS_CHACHAPOLY_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/cipher.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/cipher.c.func-sort-c.html new file mode 100644 index 00000000000..2432007d04e --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/cipher.c.func-sort-c.html @@ -0,0 +1,181 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/cipher.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - cipher.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:4339910.8 %
Date:2024-09-22 08:21:07Functions:62524.0 %
Branches:223017.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
add_pkcs_padding0
get_no_padding0
get_pkcs_padding0
mbedtls_cipher_aead_decrypt0
mbedtls_cipher_aead_encrypt0
mbedtls_cipher_auth_decrypt_ext0
mbedtls_cipher_auth_encrypt_ext0
mbedtls_cipher_check_tag0
mbedtls_cipher_crypt0
mbedtls_cipher_finish0
mbedtls_cipher_info_from_string0
mbedtls_cipher_info_from_type0
mbedtls_cipher_init0
mbedtls_cipher_list0
mbedtls_cipher_reset0
mbedtls_cipher_set_iv0
mbedtls_cipher_set_padding_mode0
mbedtls_cipher_update_ad0
mbedtls_cipher_write_tag0
mbedtls_cipher_info_from_values791
mbedtls_cipher_setkey791
mbedtls_cipher_setup791
mbedtls_cipher_free1582
mbedtls_cipher_update3654
mbedtls_cipher_get_base9187
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/cipher.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/cipher.c.func.html new file mode 100644 index 00000000000..5f0229d4cf4 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/cipher.c.func.html @@ -0,0 +1,181 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/cipher.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - cipher.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:4339910.8 %
Date:2024-09-22 08:21:07Functions:62524.0 %
Branches:223017.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
add_pkcs_padding0
get_no_padding0
get_pkcs_padding0
mbedtls_cipher_aead_decrypt0
mbedtls_cipher_aead_encrypt0
mbedtls_cipher_auth_decrypt_ext0
mbedtls_cipher_auth_encrypt_ext0
mbedtls_cipher_check_tag0
mbedtls_cipher_crypt0
mbedtls_cipher_finish0
mbedtls_cipher_free1582
mbedtls_cipher_get_base9187
mbedtls_cipher_info_from_string0
mbedtls_cipher_info_from_type0
mbedtls_cipher_info_from_values791
mbedtls_cipher_init0
mbedtls_cipher_list0
mbedtls_cipher_reset0
mbedtls_cipher_set_iv0
mbedtls_cipher_set_padding_mode0
mbedtls_cipher_setkey791
mbedtls_cipher_setup791
mbedtls_cipher_update3654
mbedtls_cipher_update_ad0
mbedtls_cipher_write_tag0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/cipher.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/cipher.c.gcov.html new file mode 100644 index 00000000000..3902cd2e87e --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/cipher.c.gcov.html @@ -0,0 +1,1765 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/cipher.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - cipher.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:4339910.8 %
Date:2024-09-22 08:21:07Functions:62524.0 %
Branches:223017.3 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  * \file cipher.c
+       3                 :            :  *
+       4                 :            :  * \brief Generic cipher wrapper for Mbed TLS
+       5                 :            :  *
+       6                 :            :  * \author Adriaan de Jong <dejong@fox-it.com>
+       7                 :            :  *
+       8                 :            :  *  Copyright The Mbed TLS Contributors
+       9                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+      10                 :            :  */
+      11                 :            : 
+      12                 :            : #include "common.h"
+      13                 :            : 
+      14                 :            : #if defined(MBEDTLS_CIPHER_C)
+      15                 :            : 
+      16                 :            : #include "mbedtls/cipher.h"
+      17                 :            : #include "cipher_wrap.h"
+      18                 :            : #include "mbedtls/platform_util.h"
+      19                 :            : #include "mbedtls/error.h"
+      20                 :            : #include "mbedtls/constant_time.h"
+      21                 :            : #include "constant_time_internal.h"
+      22                 :            : 
+      23                 :            : #include <stdlib.h>
+      24                 :            : #include <string.h>
+      25                 :            : 
+      26                 :            : #if defined(MBEDTLS_CHACHAPOLY_C)
+      27                 :            : #include "mbedtls/chachapoly.h"
+      28                 :            : #endif
+      29                 :            : 
+      30                 :            : #if defined(MBEDTLS_GCM_C)
+      31                 :            : #include "mbedtls/gcm.h"
+      32                 :            : #endif
+      33                 :            : 
+      34                 :            : #if defined(MBEDTLS_CCM_C)
+      35                 :            : #include "mbedtls/ccm.h"
+      36                 :            : #endif
+      37                 :            : 
+      38                 :            : #if defined(MBEDTLS_CHACHA20_C)
+      39                 :            : #include "mbedtls/chacha20.h"
+      40                 :            : #endif
+      41                 :            : 
+      42                 :            : #if defined(MBEDTLS_CMAC_C)
+      43                 :            : #include "mbedtls/cmac.h"
+      44                 :            : #endif
+      45                 :            : 
+      46                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_DEPRECATED_REMOVED)
+      47                 :            : #include "psa/crypto.h"
+      48                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO && !MBEDTLS_DEPRECATED_REMOVED */
+      49                 :            : 
+      50                 :            : #if defined(MBEDTLS_NIST_KW_C)
+      51                 :            : #include "mbedtls/nist_kw.h"
+      52                 :            : #endif
+      53                 :            : 
+      54                 :            : #include "mbedtls/platform.h"
+      55                 :            : 
+      56                 :            : static int supported_init = 0;
+      57                 :            : 
+      58                 :       9187 : static inline const mbedtls_cipher_base_t *mbedtls_cipher_get_base(
+      59                 :            :     const mbedtls_cipher_info_t *info)
+      60                 :            : {
+      61                 :       9187 :     return mbedtls_cipher_base_lookup_table[info->base_idx];
+      62                 :            : }
+      63                 :            : 
+      64                 :          0 : const int *mbedtls_cipher_list(void)
+      65                 :            : {
+      66                 :            :     const mbedtls_cipher_definition_t *def;
+      67                 :            :     int *type;
+      68                 :            : 
+      69         [ #  # ]:          0 :     if (!supported_init) {
+      70                 :          0 :         def = mbedtls_cipher_definitions;
+      71                 :          0 :         type = mbedtls_cipher_supported;
+      72                 :            : 
+      73         [ #  # ]:          0 :         while (def->type != 0) {
+      74                 :          0 :             *type++ = (*def++).type;
+      75                 :            :         }
+      76                 :            : 
+      77                 :          0 :         *type = 0;
+      78                 :            : 
+      79                 :          0 :         supported_init = 1;
+      80                 :            :     }
+      81                 :            : 
+      82                 :          0 :     return mbedtls_cipher_supported;
+      83                 :            : }
+      84                 :            : 
+      85                 :          0 : const mbedtls_cipher_info_t *mbedtls_cipher_info_from_type(
+      86                 :            :     const mbedtls_cipher_type_t cipher_type)
+      87                 :            : {
+      88                 :            :     const mbedtls_cipher_definition_t *def;
+      89                 :            : 
+      90         [ #  # ]:          0 :     for (def = mbedtls_cipher_definitions; def->info != NULL; def++) {
+      91         [ #  # ]:          0 :         if (def->type == cipher_type) {
+      92                 :          0 :             return def->info;
+      93                 :            :         }
+      94                 :            :     }
+      95                 :            : 
+      96                 :          0 :     return NULL;
+      97                 :            : }
+      98                 :            : 
+      99                 :          0 : const mbedtls_cipher_info_t *mbedtls_cipher_info_from_string(
+     100                 :            :     const char *cipher_name)
+     101                 :            : {
+     102                 :            :     const mbedtls_cipher_definition_t *def;
+     103                 :            : 
+     104         [ #  # ]:          0 :     if (NULL == cipher_name) {
+     105                 :          0 :         return NULL;
+     106                 :            :     }
+     107                 :            : 
+     108         [ #  # ]:          0 :     for (def = mbedtls_cipher_definitions; def->info != NULL; def++) {
+     109         [ #  # ]:          0 :         if (!strcmp(def->info->name, cipher_name)) {
+     110                 :          0 :             return def->info;
+     111                 :            :         }
+     112                 :            :     }
+     113                 :            : 
+     114                 :          0 :     return NULL;
+     115                 :            : }
+     116                 :            : 
+     117                 :        791 : const mbedtls_cipher_info_t *mbedtls_cipher_info_from_values(
+     118                 :            :     const mbedtls_cipher_id_t cipher_id,
+     119                 :            :     int key_bitlen,
+     120                 :            :     const mbedtls_cipher_mode_t mode)
+     121                 :            : {
+     122                 :            :     const mbedtls_cipher_definition_t *def;
+     123                 :            : 
+     124         [ +  - ]:       2369 :     for (def = mbedtls_cipher_definitions; def->info != NULL; def++) {
+     125         [ +  - ]:       2369 :         if (mbedtls_cipher_get_base(def->info)->cipher == cipher_id &&
+     126         [ +  + ]:       2369 :             mbedtls_cipher_info_get_key_bitlen(def->info) == (unsigned) key_bitlen &&
+     127         [ +  - ]:        791 :             def->info->mode == mode) {
+     128                 :        791 :             return def->info;
+     129                 :            :         }
+     130                 :            :     }
+     131                 :            : 
+     132                 :          0 :     return NULL;
+     133                 :            : }
+     134                 :            : 
+     135                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_DEPRECATED_REMOVED)
+     136                 :            : static inline psa_key_type_t mbedtls_psa_translate_cipher_type(
+     137                 :            :     mbedtls_cipher_type_t cipher)
+     138                 :            : {
+     139                 :            :     switch (cipher) {
+     140                 :            :         case MBEDTLS_CIPHER_AES_128_CCM:
+     141                 :            :         case MBEDTLS_CIPHER_AES_192_CCM:
+     142                 :            :         case MBEDTLS_CIPHER_AES_256_CCM:
+     143                 :            :         case MBEDTLS_CIPHER_AES_128_CCM_STAR_NO_TAG:
+     144                 :            :         case MBEDTLS_CIPHER_AES_192_CCM_STAR_NO_TAG:
+     145                 :            :         case MBEDTLS_CIPHER_AES_256_CCM_STAR_NO_TAG:
+     146                 :            :         case MBEDTLS_CIPHER_AES_128_GCM:
+     147                 :            :         case MBEDTLS_CIPHER_AES_192_GCM:
+     148                 :            :         case MBEDTLS_CIPHER_AES_256_GCM:
+     149                 :            :         case MBEDTLS_CIPHER_AES_128_CBC:
+     150                 :            :         case MBEDTLS_CIPHER_AES_192_CBC:
+     151                 :            :         case MBEDTLS_CIPHER_AES_256_CBC:
+     152                 :            :         case MBEDTLS_CIPHER_AES_128_ECB:
+     153                 :            :         case MBEDTLS_CIPHER_AES_192_ECB:
+     154                 :            :         case MBEDTLS_CIPHER_AES_256_ECB:
+     155                 :            :             return PSA_KEY_TYPE_AES;
+     156                 :            : 
+     157                 :            :         /* ARIA not yet supported in PSA. */
+     158                 :            :         /* case MBEDTLS_CIPHER_ARIA_128_CCM:
+     159                 :            :            case MBEDTLS_CIPHER_ARIA_192_CCM:
+     160                 :            :            case MBEDTLS_CIPHER_ARIA_256_CCM:
+     161                 :            :            case MBEDTLS_CIPHER_ARIA_128_CCM_STAR_NO_TAG:
+     162                 :            :            case MBEDTLS_CIPHER_ARIA_192_CCM_STAR_NO_TAG:
+     163                 :            :            case MBEDTLS_CIPHER_ARIA_256_CCM_STAR_NO_TAG:
+     164                 :            :            case MBEDTLS_CIPHER_ARIA_128_GCM:
+     165                 :            :            case MBEDTLS_CIPHER_ARIA_192_GCM:
+     166                 :            :            case MBEDTLS_CIPHER_ARIA_256_GCM:
+     167                 :            :            case MBEDTLS_CIPHER_ARIA_128_CBC:
+     168                 :            :            case MBEDTLS_CIPHER_ARIA_192_CBC:
+     169                 :            :            case MBEDTLS_CIPHER_ARIA_256_CBC:
+     170                 :            :                return( PSA_KEY_TYPE_ARIA ); */
+     171                 :            : 
+     172                 :            :         default:
+     173                 :            :             return 0;
+     174                 :            :     }
+     175                 :            : }
+     176                 :            : 
+     177                 :            : static inline psa_algorithm_t mbedtls_psa_translate_cipher_mode(
+     178                 :            :     mbedtls_cipher_mode_t mode, size_t taglen)
+     179                 :            : {
+     180                 :            :     switch (mode) {
+     181                 :            :         case MBEDTLS_MODE_ECB:
+     182                 :            :             return PSA_ALG_ECB_NO_PADDING;
+     183                 :            :         case MBEDTLS_MODE_GCM:
+     184                 :            :             return PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_GCM, taglen);
+     185                 :            :         case MBEDTLS_MODE_CCM:
+     186                 :            :             return PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_CCM, taglen);
+     187                 :            :         case MBEDTLS_MODE_CCM_STAR_NO_TAG:
+     188                 :            :             return PSA_ALG_CCM_STAR_NO_TAG;
+     189                 :            :         case MBEDTLS_MODE_CBC:
+     190                 :            :             if (taglen == 0) {
+     191                 :            :                 return PSA_ALG_CBC_NO_PADDING;
+     192                 :            :             } else {
+     193                 :            :                 return 0;
+     194                 :            :             }
+     195                 :            :         default:
+     196                 :            :             return 0;
+     197                 :            :     }
+     198                 :            : }
+     199                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO && !MBEDTLS_DEPRECATED_REMOVED */
+     200                 :            : 
+     201                 :          0 : void mbedtls_cipher_init(mbedtls_cipher_context_t *ctx)
+     202                 :            : {
+     203                 :          0 :     memset(ctx, 0, sizeof(mbedtls_cipher_context_t));
+     204                 :          0 : }
+     205                 :            : 
+     206                 :       1582 : void mbedtls_cipher_free(mbedtls_cipher_context_t *ctx)
+     207                 :            : {
+     208         [ -  + ]:       1582 :     if (ctx == NULL) {
+     209                 :          0 :         return;
+     210                 :            :     }
+     211                 :            : 
+     212                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_DEPRECATED_REMOVED)
+     213                 :            :     if (ctx->psa_enabled == 1) {
+     214                 :            :         if (ctx->cipher_ctx != NULL) {
+     215                 :            :             mbedtls_cipher_context_psa * const cipher_psa =
+     216                 :            :                 (mbedtls_cipher_context_psa *) ctx->cipher_ctx;
+     217                 :            : 
+     218                 :            :             if (cipher_psa->slot_state == MBEDTLS_CIPHER_PSA_KEY_OWNED) {
+     219                 :            :                 /* xxx_free() doesn't allow to return failures. */
+     220                 :            :                 (void) psa_destroy_key(cipher_psa->slot);
+     221                 :            :             }
+     222                 :            : 
+     223                 :            :             mbedtls_zeroize_and_free(cipher_psa, sizeof(*cipher_psa));
+     224                 :            :         }
+     225                 :            : 
+     226                 :            :         mbedtls_platform_zeroize(ctx, sizeof(mbedtls_cipher_context_t));
+     227                 :            :         return;
+     228                 :            :     }
+     229                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO && !MBEDTLS_DEPRECATED_REMOVED */
+     230                 :            : 
+     231                 :            : #if defined(MBEDTLS_CMAC_C)
+     232         [ -  + ]:       1582 :     if (ctx->cmac_ctx) {
+     233                 :          0 :         mbedtls_zeroize_and_free(ctx->cmac_ctx,
+     234                 :            :                                  sizeof(mbedtls_cmac_context_t));
+     235                 :            :     }
+     236                 :            : #endif
+     237                 :            : 
+     238         [ +  + ]:       1582 :     if (ctx->cipher_ctx) {
+     239                 :        791 :         mbedtls_cipher_get_base(ctx->cipher_info)->ctx_free_func(ctx->cipher_ctx);
+     240                 :            :     }
+     241                 :            : 
+     242                 :       1582 :     mbedtls_platform_zeroize(ctx, sizeof(mbedtls_cipher_context_t));
+     243                 :            : }
+     244                 :            : 
+     245                 :        791 : int mbedtls_cipher_setup(mbedtls_cipher_context_t *ctx,
+     246                 :            :                          const mbedtls_cipher_info_t *cipher_info)
+     247                 :            : {
+     248         [ -  + ]:        791 :     if (cipher_info == NULL) {
+     249                 :          0 :         return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+     250                 :            :     }
+     251                 :            : 
+     252                 :        791 :     memset(ctx, 0, sizeof(mbedtls_cipher_context_t));
+     253                 :            : 
+     254         [ +  - ]:        791 :     if (mbedtls_cipher_get_base(cipher_info)->ctx_alloc_func != NULL) {
+     255                 :        791 :         ctx->cipher_ctx = mbedtls_cipher_get_base(cipher_info)->ctx_alloc_func();
+     256         [ -  + ]:        791 :         if (ctx->cipher_ctx == NULL) {
+     257                 :          0 :             return MBEDTLS_ERR_CIPHER_ALLOC_FAILED;
+     258                 :            :         }
+     259                 :            :     }
+     260                 :            : 
+     261                 :        791 :     ctx->cipher_info = cipher_info;
+     262                 :            : 
+     263                 :        791 :     return 0;
+     264                 :            : }
+     265                 :            : 
+     266                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_DEPRECATED_REMOVED)
+     267                 :            : int mbedtls_cipher_setup_psa(mbedtls_cipher_context_t *ctx,
+     268                 :            :                              const mbedtls_cipher_info_t *cipher_info,
+     269                 :            :                              size_t taglen)
+     270                 :            : {
+     271                 :            :     psa_algorithm_t alg;
+     272                 :            :     mbedtls_cipher_context_psa *cipher_psa;
+     273                 :            : 
+     274                 :            :     if (NULL == cipher_info || NULL == ctx) {
+     275                 :            :         return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+     276                 :            :     }
+     277                 :            : 
+     278                 :            :     /* Check that the underlying cipher mode and cipher type are
+     279                 :            :      * supported by the underlying PSA Crypto implementation. */
+     280                 :            :     alg = mbedtls_psa_translate_cipher_mode(((mbedtls_cipher_mode_t) cipher_info->mode), taglen);
+     281                 :            :     if (alg == 0) {
+     282                 :            :         return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
+     283                 :            :     }
+     284                 :            :     if (mbedtls_psa_translate_cipher_type(((mbedtls_cipher_type_t) cipher_info->type)) == 0) {
+     285                 :            :         return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
+     286                 :            :     }
+     287                 :            : 
+     288                 :            :     memset(ctx, 0, sizeof(mbedtls_cipher_context_t));
+     289                 :            : 
+     290                 :            :     cipher_psa = mbedtls_calloc(1, sizeof(mbedtls_cipher_context_psa));
+     291                 :            :     if (cipher_psa == NULL) {
+     292                 :            :         return MBEDTLS_ERR_CIPHER_ALLOC_FAILED;
+     293                 :            :     }
+     294                 :            :     cipher_psa->alg  = alg;
+     295                 :            :     ctx->cipher_ctx  = cipher_psa;
+     296                 :            :     ctx->cipher_info = cipher_info;
+     297                 :            :     ctx->psa_enabled = 1;
+     298                 :            :     return 0;
+     299                 :            : }
+     300                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO && !MBEDTLS_DEPRECATED_REMOVED */
+     301                 :            : 
+     302                 :        791 : int mbedtls_cipher_setkey(mbedtls_cipher_context_t *ctx,
+     303                 :            :                           const unsigned char *key,
+     304                 :            :                           int key_bitlen,
+     305                 :            :                           const mbedtls_operation_t operation)
+     306                 :            : {
+     307   [ -  +  -  - ]:        791 :     if (operation != MBEDTLS_ENCRYPT && operation != MBEDTLS_DECRYPT) {
+     308                 :          0 :         return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+     309                 :            :     }
+     310         [ -  + ]:        791 :     if (ctx->cipher_info == NULL) {
+     311                 :          0 :         return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+     312                 :            :     }
+     313                 :            : #if defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
+     314                 :            :     if (MBEDTLS_MODE_ECB == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode) &&
+     315                 :            :         MBEDTLS_DECRYPT == operation) {
+     316                 :            :         return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
+     317                 :            :     }
+     318                 :            : #endif
+     319                 :            : 
+     320                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_DEPRECATED_REMOVED)
+     321                 :            :     if (ctx->psa_enabled == 1) {
+     322                 :            :         mbedtls_cipher_context_psa * const cipher_psa =
+     323                 :            :             (mbedtls_cipher_context_psa *) ctx->cipher_ctx;
+     324                 :            : 
+     325                 :            :         size_t const key_bytelen = ((size_t) key_bitlen + 7) / 8;
+     326                 :            : 
+     327                 :            :         psa_status_t status;
+     328                 :            :         psa_key_type_t key_type;
+     329                 :            :         psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
+     330                 :            : 
+     331                 :            :         /* PSA Crypto API only accepts byte-aligned keys. */
+     332                 :            :         if (key_bitlen % 8 != 0) {
+     333                 :            :             return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+     334                 :            :         }
+     335                 :            : 
+     336                 :            :         /* Don't allow keys to be set multiple times. */
+     337                 :            :         if (cipher_psa->slot_state != MBEDTLS_CIPHER_PSA_KEY_UNSET) {
+     338                 :            :             return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+     339                 :            :         }
+     340                 :            : 
+     341                 :            :         key_type = mbedtls_psa_translate_cipher_type(
+     342                 :            :             ((mbedtls_cipher_type_t) ctx->cipher_info->type));
+     343                 :            :         if (key_type == 0) {
+     344                 :            :             return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
+     345                 :            :         }
+     346                 :            :         psa_set_key_type(&attributes, key_type);
+     347                 :            : 
+     348                 :            :         /* Mbed TLS' cipher layer doesn't enforce the mode of operation
+     349                 :            :          * (encrypt vs. decrypt): it is possible to setup a key for encryption
+     350                 :            :          * and use it for AEAD decryption. Until tests relying on this
+     351                 :            :          * are changed, allow any usage in PSA. */
+     352                 :            :         psa_set_key_usage_flags(&attributes,
+     353                 :            :                                 PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT);
+     354                 :            :         psa_set_key_algorithm(&attributes, cipher_psa->alg);
+     355                 :            : 
+     356                 :            :         status = psa_import_key(&attributes, key, key_bytelen,
+     357                 :            :                                 &cipher_psa->slot);
+     358                 :            :         switch (status) {
+     359                 :            :             case PSA_SUCCESS:
+     360                 :            :                 break;
+     361                 :            :             case PSA_ERROR_INSUFFICIENT_MEMORY:
+     362                 :            :                 return MBEDTLS_ERR_CIPHER_ALLOC_FAILED;
+     363                 :            :             case PSA_ERROR_NOT_SUPPORTED:
+     364                 :            :                 return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
+     365                 :            :             default:
+     366                 :            :                 return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
+     367                 :            :         }
+     368                 :            :         /* Indicate that we own the key slot and need to
+     369                 :            :          * destroy it in mbedtls_cipher_free(). */
+     370                 :            :         cipher_psa->slot_state = MBEDTLS_CIPHER_PSA_KEY_OWNED;
+     371                 :            : 
+     372                 :            :         ctx->key_bitlen = key_bitlen;
+     373                 :            :         ctx->operation = operation;
+     374                 :            :         return 0;
+     375                 :            :     }
+     376                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO && !MBEDTLS_DEPRECATED_REMOVED */
+     377                 :            : 
+     378         [ +  - ]:        791 :     if ((ctx->cipher_info->flags & MBEDTLS_CIPHER_VARIABLE_KEY_LEN) == 0 &&
+     379         [ -  + ]:        791 :         (int) mbedtls_cipher_info_get_key_bitlen(ctx->cipher_info) != key_bitlen) {
+     380                 :          0 :         return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+     381                 :            :     }
+     382                 :            : 
+     383                 :        791 :     ctx->key_bitlen = key_bitlen;
+     384                 :        791 :     ctx->operation = operation;
+     385                 :            : 
+     386                 :            : #if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
+     387                 :            :     /*
+     388                 :            :      * For OFB, CFB and CTR mode always use the encryption key schedule
+     389                 :            :      */
+     390         [ -  + ]:        791 :     if (MBEDTLS_ENCRYPT == operation ||
+     391         [ #  # ]:          0 :         MBEDTLS_MODE_CFB == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode) ||
+     392         [ #  # ]:          0 :         MBEDTLS_MODE_OFB == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode) ||
+     393         [ #  # ]:          0 :         MBEDTLS_MODE_CTR == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) {
+     394                 :       1582 :         return mbedtls_cipher_get_base(ctx->cipher_info)->setkey_enc_func(ctx->cipher_ctx, key,
+     395                 :        791 :                                                                           ctx->key_bitlen);
+     396                 :            :     }
+     397                 :            : 
+     398         [ #  # ]:          0 :     if (MBEDTLS_DECRYPT == operation) {
+     399                 :          0 :         return mbedtls_cipher_get_base(ctx->cipher_info)->setkey_dec_func(ctx->cipher_ctx, key,
+     400                 :          0 :                                                                           ctx->key_bitlen);
+     401                 :            :     }
+     402                 :            : #else
+     403                 :            :     if (operation == MBEDTLS_ENCRYPT || operation == MBEDTLS_DECRYPT) {
+     404                 :            :         return mbedtls_cipher_get_base(ctx->cipher_info)->setkey_enc_func(ctx->cipher_ctx, key,
+     405                 :            :                                                                           ctx->key_bitlen);
+     406                 :            :     }
+     407                 :            : #endif
+     408                 :            : 
+     409                 :          0 :     return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+     410                 :            : }
+     411                 :            : 
+     412                 :          0 : int mbedtls_cipher_set_iv(mbedtls_cipher_context_t *ctx,
+     413                 :            :                           const unsigned char *iv,
+     414                 :            :                           size_t iv_len)
+     415                 :            : {
+     416                 :            :     size_t actual_iv_size;
+     417                 :            : 
+     418         [ #  # ]:          0 :     if (ctx->cipher_info == NULL) {
+     419                 :          0 :         return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+     420                 :            :     }
+     421                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_DEPRECATED_REMOVED)
+     422                 :            :     if (ctx->psa_enabled == 1) {
+     423                 :            :         /* While PSA Crypto has an API for multipart
+     424                 :            :          * operations, we currently don't make it
+     425                 :            :          * accessible through the cipher layer. */
+     426                 :            :         return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
+     427                 :            :     }
+     428                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO && !MBEDTLS_DEPRECATED_REMOVED */
+     429                 :            : 
+     430                 :            :     /* avoid buffer overflow in ctx->iv */
+     431         [ #  # ]:          0 :     if (iv_len > MBEDTLS_MAX_IV_LENGTH) {
+     432                 :          0 :         return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
+     433                 :            :     }
+     434                 :            : 
+     435         [ #  # ]:          0 :     if ((ctx->cipher_info->flags & MBEDTLS_CIPHER_VARIABLE_IV_LEN) != 0) {
+     436                 :          0 :         actual_iv_size = iv_len;
+     437                 :            :     } else {
+     438                 :          0 :         actual_iv_size = mbedtls_cipher_info_get_iv_size(ctx->cipher_info);
+     439                 :            : 
+     440                 :            :         /* avoid reading past the end of input buffer */
+     441         [ #  # ]:          0 :         if (actual_iv_size > iv_len) {
+     442                 :          0 :             return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+     443                 :            :         }
+     444                 :            :     }
+     445                 :            : 
+     446                 :            : #if defined(MBEDTLS_CHACHA20_C)
+     447         [ #  # ]:          0 :     if (((mbedtls_cipher_type_t) ctx->cipher_info->type) == MBEDTLS_CIPHER_CHACHA20) {
+     448                 :            :         /* Even though the actual_iv_size is overwritten with a correct value
+     449                 :            :          * of 12 from the cipher info, return an error to indicate that
+     450                 :            :          * the input iv_len is wrong. */
+     451         [ #  # ]:          0 :         if (iv_len != 12) {
+     452                 :          0 :             return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+     453                 :            :         }
+     454                 :            : 
+     455         [ #  # ]:          0 :         if (0 != mbedtls_chacha20_starts((mbedtls_chacha20_context *) ctx->cipher_ctx,
+     456                 :            :                                          iv,
+     457                 :            :                                          0U)) {   /* Initial counter value */
+     458                 :          0 :             return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+     459                 :            :         }
+     460                 :            :     }
+     461                 :            : #if defined(MBEDTLS_CHACHAPOLY_C)
+     462   [ #  #  #  # ]:          0 :     if (((mbedtls_cipher_type_t) ctx->cipher_info->type) == MBEDTLS_CIPHER_CHACHA20_POLY1305 &&
+     463                 :            :         iv_len != 12) {
+     464                 :          0 :         return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+     465                 :            :     }
+     466                 :            : #endif
+     467                 :            : #endif
+     468                 :            : 
+     469                 :            : #if defined(MBEDTLS_GCM_C)
+     470         [ #  # ]:          0 :     if (MBEDTLS_MODE_GCM == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) {
+     471                 :          0 :         return mbedtls_gcm_starts((mbedtls_gcm_context *) ctx->cipher_ctx,
+     472                 :          0 :                                   ctx->operation,
+     473                 :            :                                   iv, iv_len);
+     474                 :            :     }
+     475                 :            : #endif
+     476                 :            : 
+     477                 :            : #if defined(MBEDTLS_CCM_C)
+     478         [ #  # ]:          0 :     if (MBEDTLS_MODE_CCM_STAR_NO_TAG == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) {
+     479                 :            :         int set_lengths_result;
+     480                 :            :         int ccm_star_mode;
+     481                 :            : 
+     482                 :          0 :         set_lengths_result = mbedtls_ccm_set_lengths(
+     483                 :          0 :             (mbedtls_ccm_context *) ctx->cipher_ctx,
+     484                 :            :             0, 0, 0);
+     485         [ #  # ]:          0 :         if (set_lengths_result != 0) {
+     486                 :          0 :             return set_lengths_result;
+     487                 :            :         }
+     488                 :            : 
+     489         [ #  # ]:          0 :         if (ctx->operation == MBEDTLS_DECRYPT) {
+     490                 :          0 :             ccm_star_mode = MBEDTLS_CCM_STAR_DECRYPT;
+     491         [ #  # ]:          0 :         } else if (ctx->operation == MBEDTLS_ENCRYPT) {
+     492                 :          0 :             ccm_star_mode = MBEDTLS_CCM_STAR_ENCRYPT;
+     493                 :            :         } else {
+     494                 :          0 :             return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+     495                 :            :         }
+     496                 :            : 
+     497                 :          0 :         return mbedtls_ccm_starts((mbedtls_ccm_context *) ctx->cipher_ctx,
+     498                 :            :                                   ccm_star_mode,
+     499                 :            :                                   iv, iv_len);
+     500                 :            :     }
+     501                 :            : #endif
+     502                 :            : 
+     503         [ #  # ]:          0 :     if (actual_iv_size != 0) {
+     504                 :          0 :         memcpy(ctx->iv, iv, actual_iv_size);
+     505                 :          0 :         ctx->iv_size = actual_iv_size;
+     506                 :            :     }
+     507                 :            : 
+     508                 :          0 :     return 0;
+     509                 :            : }
+     510                 :            : 
+     511                 :          0 : int mbedtls_cipher_reset(mbedtls_cipher_context_t *ctx)
+     512                 :            : {
+     513         [ #  # ]:          0 :     if (ctx->cipher_info == NULL) {
+     514                 :          0 :         return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+     515                 :            :     }
+     516                 :            : 
+     517                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_DEPRECATED_REMOVED)
+     518                 :            :     if (ctx->psa_enabled == 1) {
+     519                 :            :         /* We don't support resetting PSA-based
+     520                 :            :          * cipher contexts, yet. */
+     521                 :            :         return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
+     522                 :            :     }
+     523                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO && !MBEDTLS_DEPRECATED_REMOVED */
+     524                 :            : 
+     525                 :          0 :     ctx->unprocessed_len = 0;
+     526                 :            : 
+     527                 :          0 :     return 0;
+     528                 :            : }
+     529                 :            : 
+     530                 :            : #if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C)
+     531                 :          0 : int mbedtls_cipher_update_ad(mbedtls_cipher_context_t *ctx,
+     532                 :            :                              const unsigned char *ad, size_t ad_len)
+     533                 :            : {
+     534         [ #  # ]:          0 :     if (ctx->cipher_info == NULL) {
+     535                 :          0 :         return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+     536                 :            :     }
+     537                 :            : 
+     538                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_DEPRECATED_REMOVED)
+     539                 :            :     if (ctx->psa_enabled == 1) {
+     540                 :            :         /* While PSA Crypto has an API for multipart
+     541                 :            :          * operations, we currently don't make it
+     542                 :            :          * accessible through the cipher layer. */
+     543                 :            :         return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
+     544                 :            :     }
+     545                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO && !MBEDTLS_DEPRECATED_REMOVED */
+     546                 :            : 
+     547                 :            : #if defined(MBEDTLS_GCM_C)
+     548         [ #  # ]:          0 :     if (MBEDTLS_MODE_GCM == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) {
+     549                 :          0 :         return mbedtls_gcm_update_ad((mbedtls_gcm_context *) ctx->cipher_ctx,
+     550                 :            :                                      ad, ad_len);
+     551                 :            :     }
+     552                 :            : #endif
+     553                 :            : 
+     554                 :            : #if defined(MBEDTLS_CHACHAPOLY_C)
+     555         [ #  # ]:          0 :     if (MBEDTLS_CIPHER_CHACHA20_POLY1305 == ((mbedtls_cipher_type_t) ctx->cipher_info->type)) {
+     556                 :            :         int result;
+     557                 :            :         mbedtls_chachapoly_mode_t mode;
+     558                 :            : 
+     559                 :          0 :         mode = (ctx->operation == MBEDTLS_ENCRYPT)
+     560                 :            :                 ? MBEDTLS_CHACHAPOLY_ENCRYPT
+     561                 :          0 :                 : MBEDTLS_CHACHAPOLY_DECRYPT;
+     562                 :            : 
+     563                 :          0 :         result = mbedtls_chachapoly_starts((mbedtls_chachapoly_context *) ctx->cipher_ctx,
+     564                 :          0 :                                            ctx->iv,
+     565                 :            :                                            mode);
+     566         [ #  # ]:          0 :         if (result != 0) {
+     567                 :          0 :             return result;
+     568                 :            :         }
+     569                 :            : 
+     570                 :          0 :         return mbedtls_chachapoly_update_aad((mbedtls_chachapoly_context *) ctx->cipher_ctx,
+     571                 :            :                                              ad, ad_len);
+     572                 :            :     }
+     573                 :            : #endif
+     574                 :            : 
+     575                 :          0 :     return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
+     576                 :            : }
+     577                 :            : #endif /* MBEDTLS_GCM_C || MBEDTLS_CHACHAPOLY_C */
+     578                 :            : 
+     579                 :       3654 : int mbedtls_cipher_update(mbedtls_cipher_context_t *ctx, const unsigned char *input,
+     580                 :            :                           size_t ilen, unsigned char *output, size_t *olen)
+     581                 :            : {
+     582                 :       3654 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     583                 :            :     size_t block_size;
+     584                 :            : 
+     585         [ -  + ]:       3654 :     if (ctx->cipher_info == NULL) {
+     586                 :          0 :         return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+     587                 :            :     }
+     588                 :            : 
+     589                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_DEPRECATED_REMOVED)
+     590                 :            :     if (ctx->psa_enabled == 1) {
+     591                 :            :         /* While PSA Crypto has an API for multipart
+     592                 :            :          * operations, we currently don't make it
+     593                 :            :          * accessible through the cipher layer. */
+     594                 :            :         return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
+     595                 :            :     }
+     596                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO && !MBEDTLS_DEPRECATED_REMOVED */
+     597                 :            : 
+     598                 :       3654 :     *olen = 0;
+     599                 :       3654 :     block_size = mbedtls_cipher_get_block_size(ctx);
+     600         [ -  + ]:       3654 :     if (0 == block_size) {
+     601                 :          0 :         return MBEDTLS_ERR_CIPHER_INVALID_CONTEXT;
+     602                 :            :     }
+     603                 :            : 
+     604         [ +  - ]:       3654 :     if (((mbedtls_cipher_mode_t) ctx->cipher_info->mode) == MBEDTLS_MODE_ECB) {
+     605         [ -  + ]:       3654 :         if (ilen != block_size) {
+     606                 :          0 :             return MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED;
+     607                 :            :         }
+     608                 :            : 
+     609                 :       3654 :         *olen = ilen;
+     610                 :            : 
+     611         [ -  + ]:       3654 :         if (0 != (ret = mbedtls_cipher_get_base(ctx->cipher_info)->ecb_func(ctx->cipher_ctx,
+     612                 :            :                                                                             ctx->operation, input,
+     613                 :            :                                                                             output))) {
+     614                 :          0 :             return ret;
+     615                 :            :         }
+     616                 :            : 
+     617                 :       3654 :         return 0;
+     618                 :            :     }
+     619                 :            : 
+     620                 :            : #if defined(MBEDTLS_GCM_C)
+     621         [ #  # ]:          0 :     if (((mbedtls_cipher_mode_t) ctx->cipher_info->mode) == MBEDTLS_MODE_GCM) {
+     622                 :          0 :         return mbedtls_gcm_update((mbedtls_gcm_context *) ctx->cipher_ctx,
+     623                 :            :                                   input, ilen,
+     624                 :            :                                   output, ilen, olen);
+     625                 :            :     }
+     626                 :            : #endif
+     627                 :            : 
+     628                 :            : #if defined(MBEDTLS_CCM_C)
+     629         [ #  # ]:          0 :     if (((mbedtls_cipher_mode_t) ctx->cipher_info->mode) == MBEDTLS_MODE_CCM_STAR_NO_TAG) {
+     630                 :          0 :         return mbedtls_ccm_update((mbedtls_ccm_context *) ctx->cipher_ctx,
+     631                 :            :                                   input, ilen,
+     632                 :            :                                   output, ilen, olen);
+     633                 :            :     }
+     634                 :            : #endif
+     635                 :            : 
+     636                 :            : #if defined(MBEDTLS_CHACHAPOLY_C)
+     637         [ #  # ]:          0 :     if (((mbedtls_cipher_type_t) ctx->cipher_info->type) == MBEDTLS_CIPHER_CHACHA20_POLY1305) {
+     638                 :          0 :         *olen = ilen;
+     639                 :          0 :         return mbedtls_chachapoly_update((mbedtls_chachapoly_context *) ctx->cipher_ctx,
+     640                 :            :                                          ilen, input, output);
+     641                 :            :     }
+     642                 :            : #endif
+     643                 :            : 
+     644         [ #  # ]:          0 :     if (input == output &&
+     645   [ #  #  #  # ]:          0 :         (ctx->unprocessed_len != 0 || ilen % block_size)) {
+     646                 :          0 :         return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+     647                 :            :     }
+     648                 :            : 
+     649                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+     650         [ #  # ]:          0 :     if (((mbedtls_cipher_mode_t) ctx->cipher_info->mode) == MBEDTLS_MODE_CBC) {
+     651                 :          0 :         size_t copy_len = 0;
+     652                 :            : 
+     653                 :            :         /*
+     654                 :            :          * If there is not enough data for a full block, cache it.
+     655                 :            :          */
+     656   [ #  #  #  # ]:          0 :         if ((ctx->operation == MBEDTLS_DECRYPT && NULL != ctx->add_padding &&
+     657         [ #  # ]:          0 :              ilen <= block_size - ctx->unprocessed_len) ||
+     658   [ #  #  #  # ]:          0 :             (ctx->operation == MBEDTLS_DECRYPT && NULL == ctx->add_padding &&
+     659         [ #  # ]:          0 :              ilen < block_size - ctx->unprocessed_len) ||
+     660         [ #  # ]:          0 :             (ctx->operation == MBEDTLS_ENCRYPT &&
+     661         [ #  # ]:          0 :              ilen < block_size - ctx->unprocessed_len)) {
+     662                 :          0 :             memcpy(&(ctx->unprocessed_data[ctx->unprocessed_len]), input,
+     663                 :            :                    ilen);
+     664                 :            : 
+     665                 :          0 :             ctx->unprocessed_len += ilen;
+     666                 :          0 :             return 0;
+     667                 :            :         }
+     668                 :            : 
+     669                 :            :         /*
+     670                 :            :          * Process cached data first
+     671                 :            :          */
+     672         [ #  # ]:          0 :         if (0 != ctx->unprocessed_len) {
+     673                 :          0 :             copy_len = block_size - ctx->unprocessed_len;
+     674                 :            : 
+     675                 :          0 :             memcpy(&(ctx->unprocessed_data[ctx->unprocessed_len]), input,
+     676                 :            :                    copy_len);
+     677                 :            : 
+     678         [ #  # ]:          0 :             if (0 != (ret = mbedtls_cipher_get_base(ctx->cipher_info)->cbc_func(ctx->cipher_ctx,
+     679                 :            :                                                                                 ctx->operation,
+     680                 :          0 :                                                                                 block_size, ctx->iv,
+     681                 :          0 :                                                                                 ctx->
+     682                 :            :                                                                                 unprocessed_data,
+     683                 :            :                                                                                 output))) {
+     684                 :          0 :                 return ret;
+     685                 :            :             }
+     686                 :            : 
+     687                 :          0 :             *olen += block_size;
+     688                 :          0 :             output += block_size;
+     689                 :          0 :             ctx->unprocessed_len = 0;
+     690                 :            : 
+     691                 :          0 :             input += copy_len;
+     692                 :          0 :             ilen -= copy_len;
+     693                 :            :         }
+     694                 :            : 
+     695                 :            :         /*
+     696                 :            :          * Cache final, incomplete block
+     697                 :            :          */
+     698         [ #  # ]:          0 :         if (0 != ilen) {
+     699                 :            :             /* Encryption: only cache partial blocks
+     700                 :            :              * Decryption w/ padding: always keep at least one whole block
+     701                 :            :              * Decryption w/o padding: only cache partial blocks
+     702                 :            :              */
+     703                 :          0 :             copy_len = ilen % block_size;
+     704         [ #  # ]:          0 :             if (copy_len == 0 &&
+     705         [ #  # ]:          0 :                 ctx->operation == MBEDTLS_DECRYPT &&
+     706         [ #  # ]:          0 :                 NULL != ctx->add_padding) {
+     707                 :          0 :                 copy_len = block_size;
+     708                 :            :             }
+     709                 :            : 
+     710                 :          0 :             memcpy(ctx->unprocessed_data, &(input[ilen - copy_len]),
+     711                 :            :                    copy_len);
+     712                 :            : 
+     713                 :          0 :             ctx->unprocessed_len += copy_len;
+     714                 :          0 :             ilen -= copy_len;
+     715                 :            :         }
+     716                 :            : 
+     717                 :            :         /*
+     718                 :            :          * Process remaining full blocks
+     719                 :            :          */
+     720         [ #  # ]:          0 :         if (ilen) {
+     721         [ #  # ]:          0 :             if (0 != (ret = mbedtls_cipher_get_base(ctx->cipher_info)->cbc_func(ctx->cipher_ctx,
+     722                 :            :                                                                                 ctx->operation,
+     723                 :          0 :                                                                                 ilen, ctx->iv,
+     724                 :            :                                                                                 input,
+     725                 :            :                                                                                 output))) {
+     726                 :          0 :                 return ret;
+     727                 :            :             }
+     728                 :            : 
+     729                 :          0 :             *olen += ilen;
+     730                 :            :         }
+     731                 :            : 
+     732                 :          0 :         return 0;
+     733                 :            :     }
+     734                 :            : #endif /* MBEDTLS_CIPHER_MODE_CBC */
+     735                 :            : 
+     736                 :            : #if defined(MBEDTLS_CIPHER_MODE_CFB)
+     737         [ #  # ]:          0 :     if (((mbedtls_cipher_mode_t) ctx->cipher_info->mode) == MBEDTLS_MODE_CFB) {
+     738         [ #  # ]:          0 :         if (0 != (ret = mbedtls_cipher_get_base(ctx->cipher_info)->cfb_func(ctx->cipher_ctx,
+     739                 :            :                                                                             ctx->operation, ilen,
+     740                 :            :                                                                             &ctx->unprocessed_len,
+     741                 :          0 :                                                                             ctx->iv,
+     742                 :            :                                                                             input, output))) {
+     743                 :          0 :             return ret;
+     744                 :            :         }
+     745                 :            : 
+     746                 :          0 :         *olen = ilen;
+     747                 :            : 
+     748                 :          0 :         return 0;
+     749                 :            :     }
+     750                 :            : #endif /* MBEDTLS_CIPHER_MODE_CFB */
+     751                 :            : 
+     752                 :            : #if defined(MBEDTLS_CIPHER_MODE_OFB)
+     753         [ #  # ]:          0 :     if (((mbedtls_cipher_mode_t) ctx->cipher_info->mode) == MBEDTLS_MODE_OFB) {
+     754         [ #  # ]:          0 :         if (0 != (ret = mbedtls_cipher_get_base(ctx->cipher_info)->ofb_func(ctx->cipher_ctx,
+     755                 :            :                                                                             ilen,
+     756                 :            :                                                                             &ctx->unprocessed_len,
+     757                 :          0 :                                                                             ctx->iv,
+     758                 :            :                                                                             input, output))) {
+     759                 :          0 :             return ret;
+     760                 :            :         }
+     761                 :            : 
+     762                 :          0 :         *olen = ilen;
+     763                 :            : 
+     764                 :          0 :         return 0;
+     765                 :            :     }
+     766                 :            : #endif /* MBEDTLS_CIPHER_MODE_OFB */
+     767                 :            : 
+     768                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR)
+     769         [ #  # ]:          0 :     if (((mbedtls_cipher_mode_t) ctx->cipher_info->mode) == MBEDTLS_MODE_CTR) {
+     770         [ #  # ]:          0 :         if (0 != (ret = mbedtls_cipher_get_base(ctx->cipher_info)->ctr_func(ctx->cipher_ctx,
+     771                 :            :                                                                             ilen,
+     772                 :            :                                                                             &ctx->unprocessed_len,
+     773                 :          0 :                                                                             ctx->iv,
+     774                 :          0 :                                                                             ctx->unprocessed_data,
+     775                 :            :                                                                             input, output))) {
+     776                 :          0 :             return ret;
+     777                 :            :         }
+     778                 :            : 
+     779                 :          0 :         *olen = ilen;
+     780                 :            : 
+     781                 :          0 :         return 0;
+     782                 :            :     }
+     783                 :            : #endif /* MBEDTLS_CIPHER_MODE_CTR */
+     784                 :            : 
+     785                 :            : #if defined(MBEDTLS_CIPHER_MODE_XTS)
+     786                 :            :     if (((mbedtls_cipher_mode_t) ctx->cipher_info->mode) == MBEDTLS_MODE_XTS) {
+     787                 :            :         if (ctx->unprocessed_len > 0) {
+     788                 :            :             /* We can only process an entire data unit at a time. */
+     789                 :            :             return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
+     790                 :            :         }
+     791                 :            : 
+     792                 :            :         ret = mbedtls_cipher_get_base(ctx->cipher_info)->xts_func(ctx->cipher_ctx,
+     793                 :            :                                                                   ctx->operation,
+     794                 :            :                                                                   ilen,
+     795                 :            :                                                                   ctx->iv,
+     796                 :            :                                                                   input,
+     797                 :            :                                                                   output);
+     798                 :            :         if (ret != 0) {
+     799                 :            :             return ret;
+     800                 :            :         }
+     801                 :            : 
+     802                 :            :         *olen = ilen;
+     803                 :            : 
+     804                 :            :         return 0;
+     805                 :            :     }
+     806                 :            : #endif /* MBEDTLS_CIPHER_MODE_XTS */
+     807                 :            : 
+     808                 :            : #if defined(MBEDTLS_CIPHER_MODE_STREAM)
+     809         [ #  # ]:          0 :     if (((mbedtls_cipher_mode_t) ctx->cipher_info->mode) == MBEDTLS_MODE_STREAM) {
+     810         [ #  # ]:          0 :         if (0 != (ret = mbedtls_cipher_get_base(ctx->cipher_info)->stream_func(ctx->cipher_ctx,
+     811                 :            :                                                                                ilen, input,
+     812                 :            :                                                                                output))) {
+     813                 :          0 :             return ret;
+     814                 :            :         }
+     815                 :            : 
+     816                 :          0 :         *olen = ilen;
+     817                 :            : 
+     818                 :          0 :         return 0;
+     819                 :            :     }
+     820                 :            : #endif /* MBEDTLS_CIPHER_MODE_STREAM */
+     821                 :            : 
+     822                 :          0 :     return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
+     823                 :            : }
+     824                 :            : 
+     825                 :            : #if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING)
+     826                 :            : #if defined(MBEDTLS_CIPHER_PADDING_PKCS7)
+     827                 :            : /*
+     828                 :            :  * PKCS7 (and PKCS5) padding: fill with ll bytes, with ll = padding_len
+     829                 :            :  */
+     830                 :          0 : static void add_pkcs_padding(unsigned char *output, size_t output_len,
+     831                 :            :                              size_t data_len)
+     832                 :            : {
+     833                 :          0 :     size_t padding_len = output_len - data_len;
+     834                 :            :     unsigned char i;
+     835                 :            : 
+     836         [ #  # ]:          0 :     for (i = 0; i < padding_len; i++) {
+     837                 :          0 :         output[data_len + i] = (unsigned char) padding_len;
+     838                 :            :     }
+     839                 :          0 : }
+     840                 :            : 
+     841                 :          0 : static int get_pkcs_padding(unsigned char *input, size_t input_len,
+     842                 :            :                             size_t *data_len)
+     843                 :            : {
+     844                 :            :     size_t i, pad_idx;
+     845                 :            :     unsigned char padding_len;
+     846                 :            : 
+     847   [ #  #  #  # ]:          0 :     if (NULL == input || NULL == data_len) {
+     848                 :          0 :         return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+     849                 :            :     }
+     850                 :            : 
+     851                 :          0 :     padding_len = input[input_len - 1];
+     852                 :          0 :     *data_len = input_len - padding_len;
+     853                 :            : 
+     854                 :          0 :     mbedtls_ct_condition_t bad = mbedtls_ct_uint_gt(padding_len, input_len);
+     855                 :          0 :     bad = mbedtls_ct_bool_or(bad, mbedtls_ct_uint_eq(padding_len, 0));
+     856                 :            : 
+     857                 :            :     /* The number of bytes checked must be independent of padding_len,
+     858                 :            :      * so pick input_len, which is usually 8 or 16 (one block) */
+     859                 :          0 :     pad_idx = input_len - padding_len;
+     860         [ #  # ]:          0 :     for (i = 0; i < input_len; i++) {
+     861                 :          0 :         mbedtls_ct_condition_t in_padding = mbedtls_ct_uint_ge(i, pad_idx);
+     862                 :          0 :         mbedtls_ct_condition_t different  = mbedtls_ct_uint_ne(input[i], padding_len);
+     863                 :          0 :         bad = mbedtls_ct_bool_or(bad, mbedtls_ct_bool_and(in_padding, different));
+     864                 :            :     }
+     865                 :            : 
+     866                 :          0 :     return mbedtls_ct_error_if_else_0(bad, MBEDTLS_ERR_CIPHER_INVALID_PADDING);
+     867                 :            : }
+     868                 :            : #endif /* MBEDTLS_CIPHER_PADDING_PKCS7 */
+     869                 :            : 
+     870                 :            : #if defined(MBEDTLS_CIPHER_PADDING_ONE_AND_ZEROS)
+     871                 :            : /*
+     872                 :            :  * One and zeros padding: fill with 80 00 ... 00
+     873                 :            :  */
+     874                 :            : static void add_one_and_zeros_padding(unsigned char *output,
+     875                 :            :                                       size_t output_len, size_t data_len)
+     876                 :            : {
+     877                 :            :     size_t padding_len = output_len - data_len;
+     878                 :            :     unsigned char i = 0;
+     879                 :            : 
+     880                 :            :     output[data_len] = 0x80;
+     881                 :            :     for (i = 1; i < padding_len; i++) {
+     882                 :            :         output[data_len + i] = 0x00;
+     883                 :            :     }
+     884                 :            : }
+     885                 :            : 
+     886                 :            : static int get_one_and_zeros_padding(unsigned char *input, size_t input_len,
+     887                 :            :                                      size_t *data_len)
+     888                 :            : {
+     889                 :            :     if (NULL == input || NULL == data_len) {
+     890                 :            :         return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+     891                 :            :     }
+     892                 :            : 
+     893                 :            :     mbedtls_ct_condition_t in_padding = MBEDTLS_CT_TRUE;
+     894                 :            :     mbedtls_ct_condition_t bad = MBEDTLS_CT_TRUE;
+     895                 :            : 
+     896                 :            :     *data_len = 0;
+     897                 :            : 
+     898                 :            :     for (ptrdiff_t i = (ptrdiff_t) (input_len) - 1; i >= 0; i--) {
+     899                 :            :         mbedtls_ct_condition_t is_nonzero = mbedtls_ct_bool(input[i]);
+     900                 :            : 
+     901                 :            :         mbedtls_ct_condition_t hit_first_nonzero = mbedtls_ct_bool_and(is_nonzero, in_padding);
+     902                 :            : 
+     903                 :            :         *data_len = mbedtls_ct_size_if(hit_first_nonzero, i, *data_len);
+     904                 :            : 
+     905                 :            :         bad = mbedtls_ct_bool_if(hit_first_nonzero, mbedtls_ct_uint_ne(input[i], 0x80), bad);
+     906                 :            : 
+     907                 :            :         in_padding = mbedtls_ct_bool_and(in_padding, mbedtls_ct_bool_not(is_nonzero));
+     908                 :            :     }
+     909                 :            : 
+     910                 :            :     return mbedtls_ct_error_if_else_0(bad, MBEDTLS_ERR_CIPHER_INVALID_PADDING);
+     911                 :            : }
+     912                 :            : #endif /* MBEDTLS_CIPHER_PADDING_ONE_AND_ZEROS */
+     913                 :            : 
+     914                 :            : #if defined(MBEDTLS_CIPHER_PADDING_ZEROS_AND_LEN)
+     915                 :            : /*
+     916                 :            :  * Zeros and len padding: fill with 00 ... 00 ll, where ll is padding length
+     917                 :            :  */
+     918                 :            : static void add_zeros_and_len_padding(unsigned char *output,
+     919                 :            :                                       size_t output_len, size_t data_len)
+     920                 :            : {
+     921                 :            :     size_t padding_len = output_len - data_len;
+     922                 :            :     unsigned char i = 0;
+     923                 :            : 
+     924                 :            :     for (i = 1; i < padding_len; i++) {
+     925                 :            :         output[data_len + i - 1] = 0x00;
+     926                 :            :     }
+     927                 :            :     output[output_len - 1] = (unsigned char) padding_len;
+     928                 :            : }
+     929                 :            : 
+     930                 :            : static int get_zeros_and_len_padding(unsigned char *input, size_t input_len,
+     931                 :            :                                      size_t *data_len)
+     932                 :            : {
+     933                 :            :     size_t i, pad_idx;
+     934                 :            :     unsigned char padding_len;
+     935                 :            :     mbedtls_ct_condition_t bad;
+     936                 :            : 
+     937                 :            :     if (NULL == input || NULL == data_len) {
+     938                 :            :         return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+     939                 :            :     }
+     940                 :            : 
+     941                 :            :     padding_len = input[input_len - 1];
+     942                 :            :     *data_len = input_len - padding_len;
+     943                 :            : 
+     944                 :            :     /* Avoid logical || since it results in a branch */
+     945                 :            :     bad = mbedtls_ct_uint_gt(padding_len, input_len);
+     946                 :            :     bad = mbedtls_ct_bool_or(bad, mbedtls_ct_uint_eq(padding_len, 0));
+     947                 :            : 
+     948                 :            :     /* The number of bytes checked must be independent of padding_len */
+     949                 :            :     pad_idx = input_len - padding_len;
+     950                 :            :     for (i = 0; i < input_len - 1; i++) {
+     951                 :            :         mbedtls_ct_condition_t is_padding = mbedtls_ct_uint_ge(i, pad_idx);
+     952                 :            :         mbedtls_ct_condition_t nonzero_pad_byte;
+     953                 :            :         nonzero_pad_byte = mbedtls_ct_bool_if_else_0(is_padding, mbedtls_ct_bool(input[i]));
+     954                 :            :         bad = mbedtls_ct_bool_or(bad, nonzero_pad_byte);
+     955                 :            :     }
+     956                 :            : 
+     957                 :            :     return mbedtls_ct_error_if_else_0(bad, MBEDTLS_ERR_CIPHER_INVALID_PADDING);
+     958                 :            : }
+     959                 :            : #endif /* MBEDTLS_CIPHER_PADDING_ZEROS_AND_LEN */
+     960                 :            : 
+     961                 :            : #if defined(MBEDTLS_CIPHER_PADDING_ZEROS)
+     962                 :            : /*
+     963                 :            :  * Zero padding: fill with 00 ... 00
+     964                 :            :  */
+     965                 :            : static void add_zeros_padding(unsigned char *output,
+     966                 :            :                               size_t output_len, size_t data_len)
+     967                 :            : {
+     968                 :            :     memset(output + data_len, 0, output_len - data_len);
+     969                 :            : }
+     970                 :            : 
+     971                 :            : static int get_zeros_padding(unsigned char *input, size_t input_len,
+     972                 :            :                              size_t *data_len)
+     973                 :            : {
+     974                 :            :     size_t i;
+     975                 :            :     mbedtls_ct_condition_t done = MBEDTLS_CT_FALSE, prev_done;
+     976                 :            : 
+     977                 :            :     if (NULL == input || NULL == data_len) {
+     978                 :            :         return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+     979                 :            :     }
+     980                 :            : 
+     981                 :            :     *data_len = 0;
+     982                 :            :     for (i = input_len; i > 0; i--) {
+     983                 :            :         prev_done = done;
+     984                 :            :         done = mbedtls_ct_bool_or(done, mbedtls_ct_uint_ne(input[i-1], 0));
+     985                 :            :         *data_len = mbedtls_ct_size_if(mbedtls_ct_bool_ne(done, prev_done), i, *data_len);
+     986                 :            :     }
+     987                 :            : 
+     988                 :            :     return 0;
+     989                 :            : }
+     990                 :            : #endif /* MBEDTLS_CIPHER_PADDING_ZEROS */
+     991                 :            : 
+     992                 :            : /*
+     993                 :            :  * No padding: don't pad :)
+     994                 :            :  *
+     995                 :            :  * There is no add_padding function (check for NULL in mbedtls_cipher_finish)
+     996                 :            :  * but a trivial get_padding function
+     997                 :            :  */
+     998                 :          0 : static int get_no_padding(unsigned char *input, size_t input_len,
+     999                 :            :                           size_t *data_len)
+    1000                 :            : {
+    1001   [ #  #  #  # ]:          0 :     if (NULL == input || NULL == data_len) {
+    1002                 :          0 :         return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+    1003                 :            :     }
+    1004                 :            : 
+    1005                 :          0 :     *data_len = input_len;
+    1006                 :            : 
+    1007                 :          0 :     return 0;
+    1008                 :            : }
+    1009                 :            : #endif /* MBEDTLS_CIPHER_MODE_WITH_PADDING */
+    1010                 :            : 
+    1011                 :          0 : int mbedtls_cipher_finish(mbedtls_cipher_context_t *ctx,
+    1012                 :            :                           unsigned char *output, size_t *olen)
+    1013                 :            : {
+    1014         [ #  # ]:          0 :     if (ctx->cipher_info == NULL) {
+    1015                 :          0 :         return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+    1016                 :            :     }
+    1017                 :            : 
+    1018                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_DEPRECATED_REMOVED)
+    1019                 :            :     if (ctx->psa_enabled == 1) {
+    1020                 :            :         /* While PSA Crypto has an API for multipart
+    1021                 :            :          * operations, we currently don't make it
+    1022                 :            :          * accessible through the cipher layer. */
+    1023                 :            :         return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
+    1024                 :            :     }
+    1025                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO && !MBEDTLS_DEPRECATED_REMOVED */
+    1026                 :            : 
+    1027                 :          0 :     *olen = 0;
+    1028                 :            : 
+    1029                 :            : #if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING)
+    1030                 :            :     /* CBC mode requires padding so we make sure a call to
+    1031                 :            :      * mbedtls_cipher_set_padding_mode has been done successfully. */
+    1032         [ #  # ]:          0 :     if (MBEDTLS_MODE_CBC == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) {
+    1033         [ #  # ]:          0 :         if (ctx->get_padding == NULL) {
+    1034                 :          0 :             return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+    1035                 :            :         }
+    1036                 :            :     }
+    1037                 :            : #endif
+    1038                 :            : 
+    1039         [ #  # ]:          0 :     if (MBEDTLS_MODE_CFB == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode) ||
+    1040         [ #  # ]:          0 :         MBEDTLS_MODE_OFB == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode) ||
+    1041         [ #  # ]:          0 :         MBEDTLS_MODE_CTR == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode) ||
+    1042         [ #  # ]:          0 :         MBEDTLS_MODE_GCM == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode) ||
+    1043         [ #  # ]:          0 :         MBEDTLS_MODE_CCM_STAR_NO_TAG == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode) ||
+    1044         [ #  # ]:          0 :         MBEDTLS_MODE_XTS == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode) ||
+    1045         [ #  # ]:          0 :         MBEDTLS_MODE_STREAM == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) {
+    1046                 :          0 :         return 0;
+    1047                 :            :     }
+    1048                 :            : 
+    1049         [ #  # ]:          0 :     if ((MBEDTLS_CIPHER_CHACHA20          == ((mbedtls_cipher_type_t) ctx->cipher_info->type)) ||
+    1050         [ #  # ]:          0 :         (MBEDTLS_CIPHER_CHACHA20_POLY1305 == ((mbedtls_cipher_type_t) ctx->cipher_info->type))) {
+    1051                 :          0 :         return 0;
+    1052                 :            :     }
+    1053                 :            : 
+    1054         [ #  # ]:          0 :     if (MBEDTLS_MODE_ECB == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) {
+    1055         [ #  # ]:          0 :         if (ctx->unprocessed_len != 0) {
+    1056                 :          0 :             return MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED;
+    1057                 :            :         }
+    1058                 :            : 
+    1059                 :          0 :         return 0;
+    1060                 :            :     }
+    1061                 :            : 
+    1062                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+    1063         [ #  # ]:          0 :     if (MBEDTLS_MODE_CBC == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) {
+    1064                 :          0 :         int ret = 0;
+    1065                 :            : 
+    1066         [ #  # ]:          0 :         if (MBEDTLS_ENCRYPT == ctx->operation) {
+    1067                 :            :             /* check for 'no padding' mode */
+    1068         [ #  # ]:          0 :             if (NULL == ctx->add_padding) {
+    1069         [ #  # ]:          0 :                 if (0 != ctx->unprocessed_len) {
+    1070                 :          0 :                     return MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED;
+    1071                 :            :                 }
+    1072                 :            : 
+    1073                 :          0 :                 return 0;
+    1074                 :            :             }
+    1075                 :            : 
+    1076                 :          0 :             ctx->add_padding(ctx->unprocessed_data, mbedtls_cipher_get_iv_size(ctx),
+    1077                 :            :                              ctx->unprocessed_len);
+    1078         [ #  # ]:          0 :         } else if (mbedtls_cipher_get_block_size(ctx) != ctx->unprocessed_len) {
+    1079                 :            :             /*
+    1080                 :            :              * For decrypt operations, expect a full block,
+    1081                 :            :              * or an empty block if no padding
+    1082                 :            :              */
+    1083   [ #  #  #  # ]:          0 :             if (NULL == ctx->add_padding && 0 == ctx->unprocessed_len) {
+    1084                 :          0 :                 return 0;
+    1085                 :            :             }
+    1086                 :            : 
+    1087                 :          0 :             return MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED;
+    1088                 :            :         }
+    1089                 :            : 
+    1090                 :            :         /* cipher block */
+    1091         [ #  # ]:          0 :         if (0 != (ret = mbedtls_cipher_get_base(ctx->cipher_info)->cbc_func(ctx->cipher_ctx,
+    1092                 :            :                                                                             ctx->operation,
+    1093                 :          0 :                                                                             mbedtls_cipher_get_block_size(
+    1094                 :            :                                                                                 ctx),
+    1095                 :          0 :                                                                             ctx->iv,
+    1096                 :          0 :                                                                             ctx->unprocessed_data,
+    1097                 :            :                                                                             output))) {
+    1098                 :          0 :             return ret;
+    1099                 :            :         }
+    1100                 :            : 
+    1101                 :            :         /* Set output size for decryption */
+    1102         [ #  # ]:          0 :         if (MBEDTLS_DECRYPT == ctx->operation) {
+    1103                 :          0 :             return ctx->get_padding(output, mbedtls_cipher_get_block_size(ctx),
+    1104                 :            :                                     olen);
+    1105                 :            :         }
+    1106                 :            : 
+    1107                 :            :         /* Set output size for encryption */
+    1108                 :          0 :         *olen = mbedtls_cipher_get_block_size(ctx);
+    1109                 :          0 :         return 0;
+    1110                 :            :     }
+    1111                 :            : #else
+    1112                 :            :     ((void) output);
+    1113                 :            : #endif /* MBEDTLS_CIPHER_MODE_CBC */
+    1114                 :            : 
+    1115                 :          0 :     return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
+    1116                 :            : }
+    1117                 :            : 
+    1118                 :            : #if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING)
+    1119                 :          0 : int mbedtls_cipher_set_padding_mode(mbedtls_cipher_context_t *ctx,
+    1120                 :            :                                     mbedtls_cipher_padding_t mode)
+    1121                 :            : {
+    1122         [ #  # ]:          0 :     if (NULL == ctx->cipher_info ||
+    1123         [ #  # ]:          0 :         MBEDTLS_MODE_CBC != ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) {
+    1124                 :          0 :         return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+    1125                 :            :     }
+    1126                 :            : 
+    1127                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_DEPRECATED_REMOVED)
+    1128                 :            :     if (ctx->psa_enabled == 1) {
+    1129                 :            :         /* While PSA Crypto knows about CBC padding
+    1130                 :            :          * schemes, we currently don't make them
+    1131                 :            :          * accessible through the cipher layer. */
+    1132                 :            :         if (mode != MBEDTLS_PADDING_NONE) {
+    1133                 :            :             return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
+    1134                 :            :         }
+    1135                 :            : 
+    1136                 :            :         return 0;
+    1137                 :            :     }
+    1138                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO && !MBEDTLS_DEPRECATED_REMOVED */
+    1139                 :            : 
+    1140      [ #  #  # ]:          0 :     switch (mode) {
+    1141                 :            : #if defined(MBEDTLS_CIPHER_PADDING_PKCS7)
+    1142                 :          0 :         case MBEDTLS_PADDING_PKCS7:
+    1143                 :          0 :             ctx->add_padding = add_pkcs_padding;
+    1144                 :          0 :             ctx->get_padding = get_pkcs_padding;
+    1145                 :          0 :             break;
+    1146                 :            : #endif
+    1147                 :            : #if defined(MBEDTLS_CIPHER_PADDING_ONE_AND_ZEROS)
+    1148                 :            :         case MBEDTLS_PADDING_ONE_AND_ZEROS:
+    1149                 :            :             ctx->add_padding = add_one_and_zeros_padding;
+    1150                 :            :             ctx->get_padding = get_one_and_zeros_padding;
+    1151                 :            :             break;
+    1152                 :            : #endif
+    1153                 :            : #if defined(MBEDTLS_CIPHER_PADDING_ZEROS_AND_LEN)
+    1154                 :            :         case MBEDTLS_PADDING_ZEROS_AND_LEN:
+    1155                 :            :             ctx->add_padding = add_zeros_and_len_padding;
+    1156                 :            :             ctx->get_padding = get_zeros_and_len_padding;
+    1157                 :            :             break;
+    1158                 :            : #endif
+    1159                 :            : #if defined(MBEDTLS_CIPHER_PADDING_ZEROS)
+    1160                 :            :         case MBEDTLS_PADDING_ZEROS:
+    1161                 :            :             ctx->add_padding = add_zeros_padding;
+    1162                 :            :             ctx->get_padding = get_zeros_padding;
+    1163                 :            :             break;
+    1164                 :            : #endif
+    1165                 :          0 :         case MBEDTLS_PADDING_NONE:
+    1166                 :          0 :             ctx->add_padding = NULL;
+    1167                 :          0 :             ctx->get_padding = get_no_padding;
+    1168                 :          0 :             break;
+    1169                 :            : 
+    1170                 :          0 :         default:
+    1171                 :          0 :             return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
+    1172                 :            :     }
+    1173                 :            : 
+    1174                 :          0 :     return 0;
+    1175                 :            : }
+    1176                 :            : #endif /* MBEDTLS_CIPHER_MODE_WITH_PADDING */
+    1177                 :            : 
+    1178                 :            : #if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C)
+    1179                 :          0 : int mbedtls_cipher_write_tag(mbedtls_cipher_context_t *ctx,
+    1180                 :            :                              unsigned char *tag, size_t tag_len)
+    1181                 :            : {
+    1182         [ #  # ]:          0 :     if (ctx->cipher_info == NULL) {
+    1183                 :          0 :         return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+    1184                 :            :     }
+    1185                 :            : 
+    1186         [ #  # ]:          0 :     if (MBEDTLS_ENCRYPT != ctx->operation) {
+    1187                 :          0 :         return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+    1188                 :            :     }
+    1189                 :            : 
+    1190                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_DEPRECATED_REMOVED)
+    1191                 :            :     if (ctx->psa_enabled == 1) {
+    1192                 :            :         /* While PSA Crypto has an API for multipart
+    1193                 :            :          * operations, we currently don't make it
+    1194                 :            :          * accessible through the cipher layer. */
+    1195                 :            :         return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
+    1196                 :            :     }
+    1197                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO && !MBEDTLS_DEPRECATED_REMOVED */
+    1198                 :            : 
+    1199                 :            : #if defined(MBEDTLS_GCM_C)
+    1200         [ #  # ]:          0 :     if (MBEDTLS_MODE_GCM == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) {
+    1201                 :            :         size_t output_length;
+    1202                 :            :         /* The code here doesn't yet support alternative implementations
+    1203                 :            :          * that can delay up to a block of output. */
+    1204                 :          0 :         return mbedtls_gcm_finish((mbedtls_gcm_context *) ctx->cipher_ctx,
+    1205                 :            :                                   NULL, 0, &output_length,
+    1206                 :            :                                   tag, tag_len);
+    1207                 :            :     }
+    1208                 :            : #endif
+    1209                 :            : 
+    1210                 :            : #if defined(MBEDTLS_CHACHAPOLY_C)
+    1211         [ #  # ]:          0 :     if (MBEDTLS_CIPHER_CHACHA20_POLY1305 == ((mbedtls_cipher_type_t) ctx->cipher_info->type)) {
+    1212                 :            :         /* Don't allow truncated MAC for Poly1305 */
+    1213         [ #  # ]:          0 :         if (tag_len != 16U) {
+    1214                 :          0 :             return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+    1215                 :            :         }
+    1216                 :            : 
+    1217                 :          0 :         return mbedtls_chachapoly_finish(
+    1218                 :          0 :             (mbedtls_chachapoly_context *) ctx->cipher_ctx, tag);
+    1219                 :            :     }
+    1220                 :            : #endif
+    1221                 :            : 
+    1222                 :          0 :     return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
+    1223                 :            : }
+    1224                 :            : 
+    1225                 :          0 : int mbedtls_cipher_check_tag(mbedtls_cipher_context_t *ctx,
+    1226                 :            :                              const unsigned char *tag, size_t tag_len)
+    1227                 :            : {
+    1228                 :            :     unsigned char check_tag[16];
+    1229                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1230                 :            : 
+    1231         [ #  # ]:          0 :     if (ctx->cipher_info == NULL) {
+    1232                 :          0 :         return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+    1233                 :            :     }
+    1234                 :            : 
+    1235         [ #  # ]:          0 :     if (MBEDTLS_DECRYPT != ctx->operation) {
+    1236                 :          0 :         return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+    1237                 :            :     }
+    1238                 :            : 
+    1239                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_DEPRECATED_REMOVED)
+    1240                 :            :     if (ctx->psa_enabled == 1) {
+    1241                 :            :         /* While PSA Crypto has an API for multipart
+    1242                 :            :          * operations, we currently don't make it
+    1243                 :            :          * accessible through the cipher layer. */
+    1244                 :            :         return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
+    1245                 :            :     }
+    1246                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO && !MBEDTLS_DEPRECATED_REMOVED */
+    1247                 :            : 
+    1248                 :            :     /* Status to return on a non-authenticated algorithm. */
+    1249                 :          0 :     ret = MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
+    1250                 :            : 
+    1251                 :            : #if defined(MBEDTLS_GCM_C)
+    1252         [ #  # ]:          0 :     if (MBEDTLS_MODE_GCM == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) {
+    1253                 :            :         size_t output_length;
+    1254                 :            :         /* The code here doesn't yet support alternative implementations
+    1255                 :            :          * that can delay up to a block of output. */
+    1256                 :            : 
+    1257         [ #  # ]:          0 :         if (tag_len > sizeof(check_tag)) {
+    1258                 :          0 :             return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+    1259                 :            :         }
+    1260                 :            : 
+    1261         [ #  # ]:          0 :         if (0 != (ret = mbedtls_gcm_finish(
+    1262                 :          0 :                       (mbedtls_gcm_context *) ctx->cipher_ctx,
+    1263                 :            :                       NULL, 0, &output_length,
+    1264                 :            :                       check_tag, tag_len))) {
+    1265                 :          0 :             return ret;
+    1266                 :            :         }
+    1267                 :            : 
+    1268                 :            :         /* Check the tag in "constant-time" */
+    1269         [ #  # ]:          0 :         if (mbedtls_ct_memcmp(tag, check_tag, tag_len) != 0) {
+    1270                 :          0 :             ret = MBEDTLS_ERR_CIPHER_AUTH_FAILED;
+    1271                 :          0 :             goto exit;
+    1272                 :            :         }
+    1273                 :            :     }
+    1274                 :            : #endif /* MBEDTLS_GCM_C */
+    1275                 :            : 
+    1276                 :            : #if defined(MBEDTLS_CHACHAPOLY_C)
+    1277         [ #  # ]:          0 :     if (MBEDTLS_CIPHER_CHACHA20_POLY1305 == ((mbedtls_cipher_type_t) ctx->cipher_info->type)) {
+    1278                 :            :         /* Don't allow truncated MAC for Poly1305 */
+    1279         [ #  # ]:          0 :         if (tag_len != sizeof(check_tag)) {
+    1280                 :          0 :             return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+    1281                 :            :         }
+    1282                 :            : 
+    1283                 :          0 :         ret = mbedtls_chachapoly_finish(
+    1284                 :          0 :             (mbedtls_chachapoly_context *) ctx->cipher_ctx, check_tag);
+    1285         [ #  # ]:          0 :         if (ret != 0) {
+    1286                 :          0 :             return ret;
+    1287                 :            :         }
+    1288                 :            : 
+    1289                 :            :         /* Check the tag in "constant-time" */
+    1290         [ #  # ]:          0 :         if (mbedtls_ct_memcmp(tag, check_tag, tag_len) != 0) {
+    1291                 :          0 :             ret = MBEDTLS_ERR_CIPHER_AUTH_FAILED;
+    1292                 :          0 :             goto exit;
+    1293                 :            :         }
+    1294                 :            :     }
+    1295                 :            : #endif /* MBEDTLS_CHACHAPOLY_C */
+    1296                 :            : 
+    1297                 :          0 : exit:
+    1298                 :          0 :     mbedtls_platform_zeroize(check_tag, tag_len);
+    1299                 :          0 :     return ret;
+    1300                 :            : }
+    1301                 :            : #endif /* MBEDTLS_GCM_C || MBEDTLS_CHACHAPOLY_C */
+    1302                 :            : 
+    1303                 :            : /*
+    1304                 :            :  * Packet-oriented wrapper for non-AEAD modes
+    1305                 :            :  */
+    1306                 :          0 : int mbedtls_cipher_crypt(mbedtls_cipher_context_t *ctx,
+    1307                 :            :                          const unsigned char *iv, size_t iv_len,
+    1308                 :            :                          const unsigned char *input, size_t ilen,
+    1309                 :            :                          unsigned char *output, size_t *olen)
+    1310                 :            : {
+    1311                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1312                 :            :     size_t finish_olen;
+    1313                 :            : 
+    1314                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_DEPRECATED_REMOVED)
+    1315                 :            :     if (ctx->psa_enabled == 1) {
+    1316                 :            :         /* As in the non-PSA case, we don't check that
+    1317                 :            :          * a key has been set. If not, the key slot will
+    1318                 :            :          * still be in its default state of 0, which is
+    1319                 :            :          * guaranteed to be invalid, hence the PSA-call
+    1320                 :            :          * below will gracefully fail. */
+    1321                 :            :         mbedtls_cipher_context_psa * const cipher_psa =
+    1322                 :            :             (mbedtls_cipher_context_psa *) ctx->cipher_ctx;
+    1323                 :            : 
+    1324                 :            :         psa_status_t status;
+    1325                 :            :         psa_cipher_operation_t cipher_op = PSA_CIPHER_OPERATION_INIT;
+    1326                 :            :         size_t part_len;
+    1327                 :            : 
+    1328                 :            :         if (ctx->operation == MBEDTLS_DECRYPT) {
+    1329                 :            :             status = psa_cipher_decrypt_setup(&cipher_op,
+    1330                 :            :                                               cipher_psa->slot,
+    1331                 :            :                                               cipher_psa->alg);
+    1332                 :            :         } else if (ctx->operation == MBEDTLS_ENCRYPT) {
+    1333                 :            :             status = psa_cipher_encrypt_setup(&cipher_op,
+    1334                 :            :                                               cipher_psa->slot,
+    1335                 :            :                                               cipher_psa->alg);
+    1336                 :            :         } else {
+    1337                 :            :             return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+    1338                 :            :         }
+    1339                 :            : 
+    1340                 :            :         /* In the following, we can immediately return on an error,
+    1341                 :            :          * because the PSA Crypto API guarantees that cipher operations
+    1342                 :            :          * are terminated by unsuccessful calls to psa_cipher_update(),
+    1343                 :            :          * and by any call to psa_cipher_finish(). */
+    1344                 :            :         if (status != PSA_SUCCESS) {
+    1345                 :            :             return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
+    1346                 :            :         }
+    1347                 :            : 
+    1348                 :            :         if (((mbedtls_cipher_mode_t) ctx->cipher_info->mode) != MBEDTLS_MODE_ECB) {
+    1349                 :            :             status = psa_cipher_set_iv(&cipher_op, iv, iv_len);
+    1350                 :            :             if (status != PSA_SUCCESS) {
+    1351                 :            :                 return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
+    1352                 :            :             }
+    1353                 :            :         }
+    1354                 :            : 
+    1355                 :            :         status = psa_cipher_update(&cipher_op,
+    1356                 :            :                                    input, ilen,
+    1357                 :            :                                    output, ilen, olen);
+    1358                 :            :         if (status != PSA_SUCCESS) {
+    1359                 :            :             return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
+    1360                 :            :         }
+    1361                 :            : 
+    1362                 :            :         status = psa_cipher_finish(&cipher_op,
+    1363                 :            :                                    output + *olen, ilen - *olen,
+    1364                 :            :                                    &part_len);
+    1365                 :            :         if (status != PSA_SUCCESS) {
+    1366                 :            :             return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
+    1367                 :            :         }
+    1368                 :            : 
+    1369                 :            :         *olen += part_len;
+    1370                 :            :         return 0;
+    1371                 :            :     }
+    1372                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO && !MBEDTLS_DEPRECATED_REMOVED */
+    1373                 :            : 
+    1374         [ #  # ]:          0 :     if ((ret = mbedtls_cipher_set_iv(ctx, iv, iv_len)) != 0) {
+    1375                 :          0 :         return ret;
+    1376                 :            :     }
+    1377                 :            : 
+    1378         [ #  # ]:          0 :     if ((ret = mbedtls_cipher_reset(ctx)) != 0) {
+    1379                 :          0 :         return ret;
+    1380                 :            :     }
+    1381                 :            : 
+    1382         [ #  # ]:          0 :     if ((ret = mbedtls_cipher_update(ctx, input, ilen,
+    1383                 :            :                                      output, olen)) != 0) {
+    1384                 :          0 :         return ret;
+    1385                 :            :     }
+    1386                 :            : 
+    1387         [ #  # ]:          0 :     if ((ret = mbedtls_cipher_finish(ctx, output + *olen,
+    1388                 :            :                                      &finish_olen)) != 0) {
+    1389                 :          0 :         return ret;
+    1390                 :            :     }
+    1391                 :            : 
+    1392                 :          0 :     *olen += finish_olen;
+    1393                 :            : 
+    1394                 :          0 :     return 0;
+    1395                 :            : }
+    1396                 :            : 
+    1397                 :            : #if defined(MBEDTLS_CIPHER_MODE_AEAD)
+    1398                 :            : /*
+    1399                 :            :  * Packet-oriented encryption for AEAD modes: internal function used by
+    1400                 :            :  * mbedtls_cipher_auth_encrypt_ext().
+    1401                 :            :  */
+    1402                 :          0 : static int mbedtls_cipher_aead_encrypt(mbedtls_cipher_context_t *ctx,
+    1403                 :            :                                        const unsigned char *iv, size_t iv_len,
+    1404                 :            :                                        const unsigned char *ad, size_t ad_len,
+    1405                 :            :                                        const unsigned char *input, size_t ilen,
+    1406                 :            :                                        unsigned char *output, size_t *olen,
+    1407                 :            :                                        unsigned char *tag, size_t tag_len)
+    1408                 :            : {
+    1409                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_DEPRECATED_REMOVED)
+    1410                 :            :     if (ctx->psa_enabled == 1) {
+    1411                 :            :         /* As in the non-PSA case, we don't check that
+    1412                 :            :          * a key has been set. If not, the key slot will
+    1413                 :            :          * still be in its default state of 0, which is
+    1414                 :            :          * guaranteed to be invalid, hence the PSA-call
+    1415                 :            :          * below will gracefully fail. */
+    1416                 :            :         mbedtls_cipher_context_psa * const cipher_psa =
+    1417                 :            :             (mbedtls_cipher_context_psa *) ctx->cipher_ctx;
+    1418                 :            : 
+    1419                 :            :         psa_status_t status;
+    1420                 :            : 
+    1421                 :            :         /* PSA Crypto API always writes the authentication tag
+    1422                 :            :          * at the end of the encrypted message. */
+    1423                 :            :         if (output == NULL || tag != output + ilen) {
+    1424                 :            :             return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
+    1425                 :            :         }
+    1426                 :            : 
+    1427                 :            :         status = psa_aead_encrypt(cipher_psa->slot,
+    1428                 :            :                                   cipher_psa->alg,
+    1429                 :            :                                   iv, iv_len,
+    1430                 :            :                                   ad, ad_len,
+    1431                 :            :                                   input, ilen,
+    1432                 :            :                                   output, ilen + tag_len, olen);
+    1433                 :            :         if (status != PSA_SUCCESS) {
+    1434                 :            :             return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
+    1435                 :            :         }
+    1436                 :            : 
+    1437                 :            :         *olen -= tag_len;
+    1438                 :            :         return 0;
+    1439                 :            :     }
+    1440                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO && !MBEDTLS_DEPRECATED_REMOVED */
+    1441                 :            : 
+    1442                 :            : #if defined(MBEDTLS_GCM_C)
+    1443         [ #  # ]:          0 :     if (MBEDTLS_MODE_GCM == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) {
+    1444                 :          0 :         *olen = ilen;
+    1445                 :          0 :         return mbedtls_gcm_crypt_and_tag(ctx->cipher_ctx, MBEDTLS_GCM_ENCRYPT,
+    1446                 :            :                                          ilen, iv, iv_len, ad, ad_len,
+    1447                 :            :                                          input, output, tag_len, tag);
+    1448                 :            :     }
+    1449                 :            : #endif /* MBEDTLS_GCM_C */
+    1450                 :            : #if defined(MBEDTLS_CCM_C)
+    1451         [ #  # ]:          0 :     if (MBEDTLS_MODE_CCM == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) {
+    1452                 :          0 :         *olen = ilen;
+    1453                 :          0 :         return mbedtls_ccm_encrypt_and_tag(ctx->cipher_ctx, ilen,
+    1454                 :            :                                            iv, iv_len, ad, ad_len, input, output,
+    1455                 :            :                                            tag, tag_len);
+    1456                 :            :     }
+    1457                 :            : #endif /* MBEDTLS_CCM_C */
+    1458                 :            : #if defined(MBEDTLS_CHACHAPOLY_C)
+    1459         [ #  # ]:          0 :     if (MBEDTLS_CIPHER_CHACHA20_POLY1305 == ((mbedtls_cipher_type_t) ctx->cipher_info->type)) {
+    1460                 :            :         /* ChachaPoly has fixed length nonce and MAC (tag) */
+    1461   [ #  #  #  # ]:          0 :         if ((iv_len != mbedtls_cipher_info_get_iv_size(ctx->cipher_info)) ||
+    1462                 :            :             (tag_len != 16U)) {
+    1463                 :          0 :             return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+    1464                 :            :         }
+    1465                 :            : 
+    1466                 :          0 :         *olen = ilen;
+    1467                 :          0 :         return mbedtls_chachapoly_encrypt_and_tag(ctx->cipher_ctx,
+    1468                 :            :                                                   ilen, iv, ad, ad_len, input, output, tag);
+    1469                 :            :     }
+    1470                 :            : #endif /* MBEDTLS_CHACHAPOLY_C */
+    1471                 :            : 
+    1472                 :          0 :     return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
+    1473                 :            : }
+    1474                 :            : 
+    1475                 :            : /*
+    1476                 :            :  * Packet-oriented encryption for AEAD modes: internal function used by
+    1477                 :            :  * mbedtls_cipher_auth_encrypt_ext().
+    1478                 :            :  */
+    1479                 :          0 : static int mbedtls_cipher_aead_decrypt(mbedtls_cipher_context_t *ctx,
+    1480                 :            :                                        const unsigned char *iv, size_t iv_len,
+    1481                 :            :                                        const unsigned char *ad, size_t ad_len,
+    1482                 :            :                                        const unsigned char *input, size_t ilen,
+    1483                 :            :                                        unsigned char *output, size_t *olen,
+    1484                 :            :                                        const unsigned char *tag, size_t tag_len)
+    1485                 :            : {
+    1486                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_DEPRECATED_REMOVED)
+    1487                 :            :     if (ctx->psa_enabled == 1) {
+    1488                 :            :         /* As in the non-PSA case, we don't check that
+    1489                 :            :          * a key has been set. If not, the key slot will
+    1490                 :            :          * still be in its default state of 0, which is
+    1491                 :            :          * guaranteed to be invalid, hence the PSA-call
+    1492                 :            :          * below will gracefully fail. */
+    1493                 :            :         mbedtls_cipher_context_psa * const cipher_psa =
+    1494                 :            :             (mbedtls_cipher_context_psa *) ctx->cipher_ctx;
+    1495                 :            : 
+    1496                 :            :         psa_status_t status;
+    1497                 :            : 
+    1498                 :            :         /* PSA Crypto API always writes the authentication tag
+    1499                 :            :          * at the end of the encrypted message. */
+    1500                 :            :         if (input == NULL || tag != input + ilen) {
+    1501                 :            :             return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
+    1502                 :            :         }
+    1503                 :            : 
+    1504                 :            :         status = psa_aead_decrypt(cipher_psa->slot,
+    1505                 :            :                                   cipher_psa->alg,
+    1506                 :            :                                   iv, iv_len,
+    1507                 :            :                                   ad, ad_len,
+    1508                 :            :                                   input, ilen + tag_len,
+    1509                 :            :                                   output, ilen, olen);
+    1510                 :            :         if (status == PSA_ERROR_INVALID_SIGNATURE) {
+    1511                 :            :             return MBEDTLS_ERR_CIPHER_AUTH_FAILED;
+    1512                 :            :         } else if (status != PSA_SUCCESS) {
+    1513                 :            :             return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
+    1514                 :            :         }
+    1515                 :            : 
+    1516                 :            :         return 0;
+    1517                 :            :     }
+    1518                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO && !MBEDTLS_DEPRECATED_REMOVED */
+    1519                 :            : 
+    1520                 :            : #if defined(MBEDTLS_GCM_C)
+    1521         [ #  # ]:          0 :     if (MBEDTLS_MODE_GCM == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) {
+    1522                 :          0 :         int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1523                 :            : 
+    1524                 :          0 :         *olen = ilen;
+    1525                 :          0 :         ret = mbedtls_gcm_auth_decrypt(ctx->cipher_ctx, ilen,
+    1526                 :            :                                        iv, iv_len, ad, ad_len,
+    1527                 :            :                                        tag, tag_len, input, output);
+    1528                 :            : 
+    1529         [ #  # ]:          0 :         if (ret == MBEDTLS_ERR_GCM_AUTH_FAILED) {
+    1530                 :          0 :             ret = MBEDTLS_ERR_CIPHER_AUTH_FAILED;
+    1531                 :            :         }
+    1532                 :            : 
+    1533                 :          0 :         return ret;
+    1534                 :            :     }
+    1535                 :            : #endif /* MBEDTLS_GCM_C */
+    1536                 :            : #if defined(MBEDTLS_CCM_C)
+    1537         [ #  # ]:          0 :     if (MBEDTLS_MODE_CCM == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) {
+    1538                 :          0 :         int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1539                 :            : 
+    1540                 :          0 :         *olen = ilen;
+    1541                 :          0 :         ret = mbedtls_ccm_auth_decrypt(ctx->cipher_ctx, ilen,
+    1542                 :            :                                        iv, iv_len, ad, ad_len,
+    1543                 :            :                                        input, output, tag, tag_len);
+    1544                 :            : 
+    1545         [ #  # ]:          0 :         if (ret == MBEDTLS_ERR_CCM_AUTH_FAILED) {
+    1546                 :          0 :             ret = MBEDTLS_ERR_CIPHER_AUTH_FAILED;
+    1547                 :            :         }
+    1548                 :            : 
+    1549                 :          0 :         return ret;
+    1550                 :            :     }
+    1551                 :            : #endif /* MBEDTLS_CCM_C */
+    1552                 :            : #if defined(MBEDTLS_CHACHAPOLY_C)
+    1553         [ #  # ]:          0 :     if (MBEDTLS_CIPHER_CHACHA20_POLY1305 == ((mbedtls_cipher_type_t) ctx->cipher_info->type)) {
+    1554                 :          0 :         int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1555                 :            : 
+    1556                 :            :         /* ChachaPoly has fixed length nonce and MAC (tag) */
+    1557   [ #  #  #  # ]:          0 :         if ((iv_len != mbedtls_cipher_info_get_iv_size(ctx->cipher_info)) ||
+    1558                 :            :             (tag_len != 16U)) {
+    1559                 :          0 :             return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+    1560                 :            :         }
+    1561                 :            : 
+    1562                 :          0 :         *olen = ilen;
+    1563                 :          0 :         ret = mbedtls_chachapoly_auth_decrypt(ctx->cipher_ctx, ilen,
+    1564                 :            :                                               iv, ad, ad_len, tag, input, output);
+    1565                 :            : 
+    1566         [ #  # ]:          0 :         if (ret == MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED) {
+    1567                 :          0 :             ret = MBEDTLS_ERR_CIPHER_AUTH_FAILED;
+    1568                 :            :         }
+    1569                 :            : 
+    1570                 :          0 :         return ret;
+    1571                 :            :     }
+    1572                 :            : #endif /* MBEDTLS_CHACHAPOLY_C */
+    1573                 :            : 
+    1574                 :          0 :     return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
+    1575                 :            : }
+    1576                 :            : #endif /* MBEDTLS_CIPHER_MODE_AEAD */
+    1577                 :            : 
+    1578                 :            : #if defined(MBEDTLS_CIPHER_MODE_AEAD) || defined(MBEDTLS_NIST_KW_C)
+    1579                 :            : /*
+    1580                 :            :  * Packet-oriented encryption for AEAD/NIST_KW: public function.
+    1581                 :            :  */
+    1582                 :          0 : int mbedtls_cipher_auth_encrypt_ext(mbedtls_cipher_context_t *ctx,
+    1583                 :            :                                     const unsigned char *iv, size_t iv_len,
+    1584                 :            :                                     const unsigned char *ad, size_t ad_len,
+    1585                 :            :                                     const unsigned char *input, size_t ilen,
+    1586                 :            :                                     unsigned char *output, size_t output_len,
+    1587                 :            :                                     size_t *olen, size_t tag_len)
+    1588                 :            : {
+    1589                 :            : #if defined(MBEDTLS_NIST_KW_C)
+    1590                 :            :     if (
+    1591                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_DEPRECATED_REMOVED)
+    1592                 :            :         ctx->psa_enabled == 0 &&
+    1593                 :            : #endif
+    1594                 :            :         (MBEDTLS_MODE_KW == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode) ||
+    1595                 :            :          MBEDTLS_MODE_KWP == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode))) {
+    1596                 :            :         mbedtls_nist_kw_mode_t mode =
+    1597                 :            :             (MBEDTLS_MODE_KW == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) ?
+    1598                 :            :             MBEDTLS_KW_MODE_KW : MBEDTLS_KW_MODE_KWP;
+    1599                 :            : 
+    1600                 :            :         /* There is no iv, tag or ad associated with KW and KWP,
+    1601                 :            :          * so these length should be 0 as documented. */
+    1602                 :            :         if (iv_len != 0 || tag_len != 0 || ad_len != 0) {
+    1603                 :            :             return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+    1604                 :            :         }
+    1605                 :            : 
+    1606                 :            :         (void) iv;
+    1607                 :            :         (void) ad;
+    1608                 :            : 
+    1609                 :            :         return mbedtls_nist_kw_wrap(ctx->cipher_ctx, mode, input, ilen,
+    1610                 :            :                                     output, olen, output_len);
+    1611                 :            :     }
+    1612                 :            : #endif /* MBEDTLS_NIST_KW_C */
+    1613                 :            : 
+    1614                 :            : #if defined(MBEDTLS_CIPHER_MODE_AEAD)
+    1615                 :            :     /* AEAD case: check length before passing on to shared function */
+    1616         [ #  # ]:          0 :     if (output_len < ilen + tag_len) {
+    1617                 :          0 :         return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+    1618                 :            :     }
+    1619                 :            : 
+    1620                 :          0 :     int ret = mbedtls_cipher_aead_encrypt(ctx, iv, iv_len, ad, ad_len,
+    1621                 :            :                                           input, ilen, output, olen,
+    1622                 :            :                                           output + ilen, tag_len);
+    1623                 :          0 :     *olen += tag_len;
+    1624                 :          0 :     return ret;
+    1625                 :            : #else
+    1626                 :            :     return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
+    1627                 :            : #endif /* MBEDTLS_CIPHER_MODE_AEAD */
+    1628                 :            : }
+    1629                 :            : 
+    1630                 :            : /*
+    1631                 :            :  * Packet-oriented decryption for AEAD/NIST_KW: public function.
+    1632                 :            :  */
+    1633                 :          0 : int mbedtls_cipher_auth_decrypt_ext(mbedtls_cipher_context_t *ctx,
+    1634                 :            :                                     const unsigned char *iv, size_t iv_len,
+    1635                 :            :                                     const unsigned char *ad, size_t ad_len,
+    1636                 :            :                                     const unsigned char *input, size_t ilen,
+    1637                 :            :                                     unsigned char *output, size_t output_len,
+    1638                 :            :                                     size_t *olen, size_t tag_len)
+    1639                 :            : {
+    1640                 :            : #if defined(MBEDTLS_NIST_KW_C)
+    1641                 :            :     if (
+    1642                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_DEPRECATED_REMOVED)
+    1643                 :            :         ctx->psa_enabled == 0 &&
+    1644                 :            : #endif
+    1645                 :            :         (MBEDTLS_MODE_KW == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode) ||
+    1646                 :            :          MBEDTLS_MODE_KWP == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode))) {
+    1647                 :            :         mbedtls_nist_kw_mode_t mode =
+    1648                 :            :             (MBEDTLS_MODE_KW == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) ?
+    1649                 :            :             MBEDTLS_KW_MODE_KW : MBEDTLS_KW_MODE_KWP;
+    1650                 :            : 
+    1651                 :            :         /* There is no iv, tag or ad associated with KW and KWP,
+    1652                 :            :          * so these length should be 0 as documented. */
+    1653                 :            :         if (iv_len != 0 || tag_len != 0 || ad_len != 0) {
+    1654                 :            :             return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+    1655                 :            :         }
+    1656                 :            : 
+    1657                 :            :         (void) iv;
+    1658                 :            :         (void) ad;
+    1659                 :            : 
+    1660                 :            :         return mbedtls_nist_kw_unwrap(ctx->cipher_ctx, mode, input, ilen,
+    1661                 :            :                                       output, olen, output_len);
+    1662                 :            :     }
+    1663                 :            : #endif /* MBEDTLS_NIST_KW_C */
+    1664                 :            : 
+    1665                 :            : #if defined(MBEDTLS_CIPHER_MODE_AEAD)
+    1666                 :            :     /* AEAD case: check length before passing on to shared function */
+    1667   [ #  #  #  # ]:          0 :     if (ilen < tag_len || output_len < ilen - tag_len) {
+    1668                 :          0 :         return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+    1669                 :            :     }
+    1670                 :            : 
+    1671                 :          0 :     return mbedtls_cipher_aead_decrypt(ctx, iv, iv_len, ad, ad_len,
+    1672                 :            :                                        input, ilen - tag_len, output, olen,
+    1673                 :          0 :                                        input + ilen - tag_len, tag_len);
+    1674                 :            : #else
+    1675                 :            :     return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
+    1676                 :            : #endif /* MBEDTLS_CIPHER_MODE_AEAD */
+    1677                 :            : }
+    1678                 :            : #endif /* MBEDTLS_CIPHER_MODE_AEAD || MBEDTLS_NIST_KW_C */
+    1679                 :            : 
+    1680                 :            : #endif /* MBEDTLS_CIPHER_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/cipher_wrap.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/cipher_wrap.c.func-sort-c.html new file mode 100644 index 00000000000..be51181cdda --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/cipher_wrap.c.func-sort-c.html @@ -0,0 +1,305 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/cipher_wrap.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - cipher_wrap.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:131767.4 %
Date:2024-09-22 08:21:07Functions:4567.1 %
Branches:1283.6 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
aes_crypt_cbc_wrap0
aes_crypt_cfb128_wrap0
aes_crypt_ctr_wrap0
aes_crypt_ofb_wrap0
aes_setkey_dec_wrap0
aria_crypt_cbc_wrap0
aria_crypt_cfb128_wrap0
aria_crypt_ctr_wrap0
aria_crypt_ecb_wrap0
aria_ctx_alloc0
aria_ctx_free0
aria_setkey_dec_wrap0
aria_setkey_enc_wrap0
camellia_crypt_cbc_wrap0
camellia_crypt_cfb128_wrap0
camellia_crypt_ctr_wrap0
camellia_crypt_ecb_wrap0
camellia_ctx_alloc0
camellia_ctx_free0
camellia_setkey_dec_wrap0
camellia_setkey_enc_wrap0
ccm_aes_setkey_wrap0
ccm_aria_setkey_wrap0
ccm_camellia_setkey_wrap0
ccm_ctx_alloc0
ccm_ctx_free0
chacha20_ctx_alloc0
chacha20_ctx_free0
chacha20_setkey_wrap0
chacha20_stream_wrap0
chachapoly_ctx_alloc0
chachapoly_ctx_free0
chachapoly_setkey_wrap0
des3_crypt_cbc_wrap0
des3_crypt_ecb_wrap0
des3_ctx_alloc0
des3_ctx_free0
des3_set2key_dec_wrap0
des3_set2key_enc_wrap0
des3_set3key_dec_wrap0
des3_set3key_enc_wrap0
des_crypt_cbc_wrap0
des_crypt_ecb_wrap0
des_ctx_alloc0
des_ctx_free0
des_setkey_dec_wrap0
des_setkey_enc_wrap0
gcm_aes_setkey_wrap0
gcm_aria_setkey_wrap0
gcm_camellia_setkey_wrap0
gcm_ctx_alloc0
gcm_ctx_free0
aes_ctx_alloc791
aes_ctx_free791
aes_setkey_enc_wrap791
aes_crypt_ecb_wrap3654
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/cipher_wrap.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/cipher_wrap.c.func.html new file mode 100644 index 00000000000..212726fc66f --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/cipher_wrap.c.func.html @@ -0,0 +1,305 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/cipher_wrap.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - cipher_wrap.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:131767.4 %
Date:2024-09-22 08:21:07Functions:4567.1 %
Branches:1283.6 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
aes_crypt_cbc_wrap0
aes_crypt_cfb128_wrap0
aes_crypt_ctr_wrap0
aes_crypt_ecb_wrap3654
aes_crypt_ofb_wrap0
aes_ctx_alloc791
aes_ctx_free791
aes_setkey_dec_wrap0
aes_setkey_enc_wrap791
aria_crypt_cbc_wrap0
aria_crypt_cfb128_wrap0
aria_crypt_ctr_wrap0
aria_crypt_ecb_wrap0
aria_ctx_alloc0
aria_ctx_free0
aria_setkey_dec_wrap0
aria_setkey_enc_wrap0
camellia_crypt_cbc_wrap0
camellia_crypt_cfb128_wrap0
camellia_crypt_ctr_wrap0
camellia_crypt_ecb_wrap0
camellia_ctx_alloc0
camellia_ctx_free0
camellia_setkey_dec_wrap0
camellia_setkey_enc_wrap0
ccm_aes_setkey_wrap0
ccm_aria_setkey_wrap0
ccm_camellia_setkey_wrap0
ccm_ctx_alloc0
ccm_ctx_free0
chacha20_ctx_alloc0
chacha20_ctx_free0
chacha20_setkey_wrap0
chacha20_stream_wrap0
chachapoly_ctx_alloc0
chachapoly_ctx_free0
chachapoly_setkey_wrap0
des3_crypt_cbc_wrap0
des3_crypt_ecb_wrap0
des3_ctx_alloc0
des3_ctx_free0
des3_set2key_dec_wrap0
des3_set2key_enc_wrap0
des3_set3key_dec_wrap0
des3_set3key_enc_wrap0
des_crypt_cbc_wrap0
des_crypt_ecb_wrap0
des_ctx_alloc0
des_ctx_free0
des_setkey_dec_wrap0
des_setkey_enc_wrap0
gcm_aes_setkey_wrap0
gcm_aria_setkey_wrap0
gcm_camellia_setkey_wrap0
gcm_ctx_alloc0
gcm_ctx_free0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/cipher_wrap.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/cipher_wrap.c.gcov.html new file mode 100644 index 00000000000..a0ffc2bde9d --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/cipher_wrap.c.gcov.html @@ -0,0 +1,2567 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/cipher_wrap.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - cipher_wrap.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:131767.4 %
Date:2024-09-22 08:21:07Functions:4567.1 %
Branches:1283.6 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  * \file cipher_wrap.c
+       3                 :            :  *
+       4                 :            :  * \brief Generic cipher wrapper for Mbed TLS
+       5                 :            :  *
+       6                 :            :  * \author Adriaan de Jong <dejong@fox-it.com>
+       7                 :            :  *
+       8                 :            :  *  Copyright The Mbed TLS Contributors
+       9                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+      10                 :            :  */
+      11                 :            : 
+      12                 :            : #include "common.h"
+      13                 :            : 
+      14                 :            : #if defined(MBEDTLS_CIPHER_C)
+      15                 :            : 
+      16                 :            : #include "cipher_wrap.h"
+      17                 :            : #include "mbedtls/error.h"
+      18                 :            : 
+      19                 :            : #if defined(MBEDTLS_CHACHAPOLY_C)
+      20                 :            : #include "mbedtls/chachapoly.h"
+      21                 :            : #endif
+      22                 :            : 
+      23                 :            : #if defined(MBEDTLS_AES_C)
+      24                 :            : #include "mbedtls/aes.h"
+      25                 :            : #endif
+      26                 :            : 
+      27                 :            : #if defined(MBEDTLS_CAMELLIA_C)
+      28                 :            : #include "mbedtls/camellia.h"
+      29                 :            : #endif
+      30                 :            : 
+      31                 :            : #if defined(MBEDTLS_ARIA_C)
+      32                 :            : #include "mbedtls/aria.h"
+      33                 :            : #endif
+      34                 :            : 
+      35                 :            : #if defined(MBEDTLS_DES_C)
+      36                 :            : #include "mbedtls/des.h"
+      37                 :            : #endif
+      38                 :            : 
+      39                 :            : #if defined(MBEDTLS_CHACHA20_C)
+      40                 :            : #include "mbedtls/chacha20.h"
+      41                 :            : #endif
+      42                 :            : 
+      43                 :            : #if defined(MBEDTLS_GCM_C)
+      44                 :            : #include "mbedtls/gcm.h"
+      45                 :            : #endif
+      46                 :            : 
+      47                 :            : #if defined(MBEDTLS_CCM_C)
+      48                 :            : #include "mbedtls/ccm.h"
+      49                 :            : #endif
+      50                 :            : 
+      51                 :            : #if defined(MBEDTLS_NIST_KW_C)
+      52                 :            : #include "mbedtls/nist_kw.h"
+      53                 :            : #endif
+      54                 :            : 
+      55                 :            : #if defined(MBEDTLS_CIPHER_NULL_CIPHER)
+      56                 :            : #include <string.h>
+      57                 :            : #endif
+      58                 :            : 
+      59                 :            : #include "mbedtls/platform.h"
+      60                 :            : 
+      61                 :            : enum mbedtls_cipher_base_index {
+      62                 :            : #if defined(MBEDTLS_AES_C)
+      63                 :            :     MBEDTLS_CIPHER_BASE_INDEX_AES,
+      64                 :            : #endif
+      65                 :            : #if defined(MBEDTLS_ARIA_C)
+      66                 :            :     MBEDTLS_CIPHER_BASE_INDEX_ARIA,
+      67                 :            : #endif
+      68                 :            : #if defined(MBEDTLS_CAMELLIA_C)
+      69                 :            :     MBEDTLS_CIPHER_BASE_INDEX_CAMELLIA,
+      70                 :            : #endif
+      71                 :            : #if defined(MBEDTLS_CIPHER_HAVE_CCM_AES_VIA_LEGACY_OR_USE_PSA)
+      72                 :            :     MBEDTLS_CIPHER_BASE_INDEX_CCM_AES,
+      73                 :            : #endif
+      74                 :            : #if defined(MBEDTLS_CCM_C) && defined(MBEDTLS_ARIA_C)
+      75                 :            :     MBEDTLS_CIPHER_BASE_INDEX_CCM_ARIA,
+      76                 :            : #endif
+      77                 :            : #if defined(MBEDTLS_CCM_C) && defined(MBEDTLS_CAMELLIA_C)
+      78                 :            :     MBEDTLS_CIPHER_BASE_INDEX_CCM_CAMELLIA,
+      79                 :            : #endif
+      80                 :            : #if defined(MBEDTLS_CHACHA20_C)
+      81                 :            :     MBEDTLS_CIPHER_BASE_INDEX_CHACHA20_BASE,
+      82                 :            : #endif
+      83                 :            : #if defined(MBEDTLS_CHACHAPOLY_C)
+      84                 :            :     MBEDTLS_CIPHER_BASE_INDEX_CHACHAPOLY_BASE,
+      85                 :            : #endif
+      86                 :            : #if defined(MBEDTLS_DES_C)
+      87                 :            :     MBEDTLS_CIPHER_BASE_INDEX_DES_EDE3,
+      88                 :            : #endif
+      89                 :            : #if defined(MBEDTLS_DES_C)
+      90                 :            :     MBEDTLS_CIPHER_BASE_INDEX_DES_EDE,
+      91                 :            : #endif
+      92                 :            : #if defined(MBEDTLS_DES_C)
+      93                 :            :     MBEDTLS_CIPHER_BASE_INDEX_DES,
+      94                 :            : #endif
+      95                 :            : #if defined(MBEDTLS_CIPHER_HAVE_GCM_AES_VIA_LEGACY_OR_USE_PSA)
+      96                 :            :     MBEDTLS_CIPHER_BASE_INDEX_GCM_AES,
+      97                 :            : #endif
+      98                 :            : #if defined(MBEDTLS_GCM_C) && defined(MBEDTLS_ARIA_C)
+      99                 :            :     MBEDTLS_CIPHER_BASE_INDEX_GCM_ARIA,
+     100                 :            : #endif
+     101                 :            : #if defined(MBEDTLS_GCM_C) && defined(MBEDTLS_CAMELLIA_C)
+     102                 :            :     MBEDTLS_CIPHER_BASE_INDEX_GCM_CAMELLIA,
+     103                 :            : #endif
+     104                 :            : #if defined(MBEDTLS_NIST_KW_C)
+     105                 :            :     MBEDTLS_CIPHER_BASE_INDEX_KW_AES,
+     106                 :            : #endif
+     107                 :            : #if defined(MBEDTLS_CIPHER_NULL_CIPHER)
+     108                 :            :     MBEDTLS_CIPHER_BASE_INDEX_NULL_BASE,
+     109                 :            : #endif
+     110                 :            : #if defined(MBEDTLS_CIPHER_MODE_XTS) && defined(MBEDTLS_AES_C)
+     111                 :            :     MBEDTLS_CIPHER_BASE_INDEX_XTS_AES,
+     112                 :            : #endif
+     113                 :            :     /* Prevent compile failure due to empty enum */
+     114                 :            :     MBEDTLS_CIPHER_BASE_PREVENT_EMPTY_ENUM
+     115                 :            : };
+     116                 :            : 
+     117                 :            : #if defined(MBEDTLS_GCM_C) && \
+     118                 :            :     (defined(MBEDTLS_CIPHER_HAVE_GCM_AES_VIA_LEGACY_OR_USE_PSA) || \
+     119                 :            :     defined(MBEDTLS_ARIA_C) || defined(MBEDTLS_CAMELLIA_C))
+     120                 :            : /* shared by all GCM ciphers */
+     121                 :          0 : static void *gcm_ctx_alloc(void)
+     122                 :            : {
+     123                 :          0 :     void *ctx = mbedtls_calloc(1, sizeof(mbedtls_gcm_context));
+     124                 :            : 
+     125         [ #  # ]:          0 :     if (ctx != NULL) {
+     126                 :          0 :         mbedtls_gcm_init((mbedtls_gcm_context *) ctx);
+     127                 :            :     }
+     128                 :            : 
+     129                 :          0 :     return ctx;
+     130                 :            : }
+     131                 :            : 
+     132                 :          0 : static void gcm_ctx_free(void *ctx)
+     133                 :            : {
+     134                 :          0 :     mbedtls_gcm_free(ctx);
+     135                 :          0 :     mbedtls_free(ctx);
+     136                 :          0 : }
+     137                 :            : #endif /* MBEDTLS_GCM_C */
+     138                 :            : 
+     139                 :            : #if defined(MBEDTLS_CCM_C) && \
+     140                 :            :     (defined(MBEDTLS_CIPHER_HAVE_CCM_AES_VIA_LEGACY_OR_USE_PSA) || \
+     141                 :            :     defined(MBEDTLS_ARIA_C) || defined(MBEDTLS_CAMELLIA_C))
+     142                 :            : /* shared by all CCM ciphers */
+     143                 :          0 : static void *ccm_ctx_alloc(void)
+     144                 :            : {
+     145                 :          0 :     void *ctx = mbedtls_calloc(1, sizeof(mbedtls_ccm_context));
+     146                 :            : 
+     147         [ #  # ]:          0 :     if (ctx != NULL) {
+     148                 :          0 :         mbedtls_ccm_init((mbedtls_ccm_context *) ctx);
+     149                 :            :     }
+     150                 :            : 
+     151                 :          0 :     return ctx;
+     152                 :            : }
+     153                 :            : 
+     154                 :          0 : static void ccm_ctx_free(void *ctx)
+     155                 :            : {
+     156                 :          0 :     mbedtls_ccm_free(ctx);
+     157                 :          0 :     mbedtls_free(ctx);
+     158                 :          0 : }
+     159                 :            : #endif /* MBEDTLS_CCM_C */
+     160                 :            : 
+     161                 :            : #if defined(MBEDTLS_AES_C)
+     162                 :            : 
+     163                 :       3654 : static int aes_crypt_ecb_wrap(void *ctx, mbedtls_operation_t operation,
+     164                 :            :                               const unsigned char *input, unsigned char *output)
+     165                 :            : {
+     166                 :       3654 :     return mbedtls_aes_crypt_ecb((mbedtls_aes_context *) ctx, operation, input, output);
+     167                 :            : }
+     168                 :            : 
+     169                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+     170                 :          0 : static int aes_crypt_cbc_wrap(void *ctx, mbedtls_operation_t operation, size_t length,
+     171                 :            :                               unsigned char *iv, const unsigned char *input, unsigned char *output)
+     172                 :            : {
+     173                 :          0 :     return mbedtls_aes_crypt_cbc((mbedtls_aes_context *) ctx, operation, length, iv, input,
+     174                 :            :                                  output);
+     175                 :            : }
+     176                 :            : #endif /* MBEDTLS_CIPHER_MODE_CBC */
+     177                 :            : 
+     178                 :            : #if defined(MBEDTLS_CIPHER_MODE_CFB)
+     179                 :          0 : static int aes_crypt_cfb128_wrap(void *ctx, mbedtls_operation_t operation,
+     180                 :            :                                  size_t length, size_t *iv_off, unsigned char *iv,
+     181                 :            :                                  const unsigned char *input, unsigned char *output)
+     182                 :            : {
+     183                 :          0 :     return mbedtls_aes_crypt_cfb128((mbedtls_aes_context *) ctx, operation, length, iv_off, iv,
+     184                 :            :                                     input, output);
+     185                 :            : }
+     186                 :            : #endif /* MBEDTLS_CIPHER_MODE_CFB */
+     187                 :            : 
+     188                 :            : #if defined(MBEDTLS_CIPHER_MODE_OFB)
+     189                 :          0 : static int aes_crypt_ofb_wrap(void *ctx, size_t length, size_t *iv_off,
+     190                 :            :                               unsigned char *iv, const unsigned char *input, unsigned char *output)
+     191                 :            : {
+     192                 :          0 :     return mbedtls_aes_crypt_ofb((mbedtls_aes_context *) ctx, length, iv_off,
+     193                 :            :                                  iv, input, output);
+     194                 :            : }
+     195                 :            : #endif /* MBEDTLS_CIPHER_MODE_OFB */
+     196                 :            : 
+     197                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR)
+     198                 :          0 : static int aes_crypt_ctr_wrap(void *ctx, size_t length, size_t *nc_off,
+     199                 :            :                               unsigned char *nonce_counter, unsigned char *stream_block,
+     200                 :            :                               const unsigned char *input, unsigned char *output)
+     201                 :            : {
+     202                 :          0 :     return mbedtls_aes_crypt_ctr((mbedtls_aes_context *) ctx, length, nc_off, nonce_counter,
+     203                 :            :                                  stream_block, input, output);
+     204                 :            : }
+     205                 :            : #endif /* MBEDTLS_CIPHER_MODE_CTR */
+     206                 :            : 
+     207                 :            : #if defined(MBEDTLS_CIPHER_MODE_XTS)
+     208                 :            : static int aes_crypt_xts_wrap(void *ctx, mbedtls_operation_t operation,
+     209                 :            :                               size_t length,
+     210                 :            :                               const unsigned char data_unit[16],
+     211                 :            :                               const unsigned char *input,
+     212                 :            :                               unsigned char *output)
+     213                 :            : {
+     214                 :            :     mbedtls_aes_xts_context *xts_ctx = ctx;
+     215                 :            :     int mode;
+     216                 :            : 
+     217                 :            :     switch (operation) {
+     218                 :            :         case MBEDTLS_ENCRYPT:
+     219                 :            :             mode = MBEDTLS_AES_ENCRYPT;
+     220                 :            :             break;
+     221                 :            :         case MBEDTLS_DECRYPT:
+     222                 :            :             mode = MBEDTLS_AES_DECRYPT;
+     223                 :            :             break;
+     224                 :            :         default:
+     225                 :            :             return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+     226                 :            :     }
+     227                 :            : 
+     228                 :            :     return mbedtls_aes_crypt_xts(xts_ctx, mode, length,
+     229                 :            :                                  data_unit, input, output);
+     230                 :            : }
+     231                 :            : #endif /* MBEDTLS_CIPHER_MODE_XTS */
+     232                 :            : 
+     233                 :            : #if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
+     234                 :          0 : static int aes_setkey_dec_wrap(void *ctx, const unsigned char *key,
+     235                 :            :                                unsigned int key_bitlen)
+     236                 :            : {
+     237                 :          0 :     return mbedtls_aes_setkey_dec((mbedtls_aes_context *) ctx, key, key_bitlen);
+     238                 :            : }
+     239                 :            : #endif
+     240                 :            : 
+     241                 :        791 : static int aes_setkey_enc_wrap(void *ctx, const unsigned char *key,
+     242                 :            :                                unsigned int key_bitlen)
+     243                 :            : {
+     244                 :        791 :     return mbedtls_aes_setkey_enc((mbedtls_aes_context *) ctx, key, key_bitlen);
+     245                 :            : }
+     246                 :            : 
+     247                 :        791 : static void *aes_ctx_alloc(void)
+     248                 :            : {
+     249                 :        791 :     mbedtls_aes_context *aes = mbedtls_calloc(1, sizeof(mbedtls_aes_context));
+     250                 :            : 
+     251         [ -  + ]:        791 :     if (aes == NULL) {
+     252                 :          0 :         return NULL;
+     253                 :            :     }
+     254                 :            : 
+     255                 :        791 :     mbedtls_aes_init(aes);
+     256                 :            : 
+     257                 :        791 :     return aes;
+     258                 :            : }
+     259                 :            : 
+     260                 :        791 : static void aes_ctx_free(void *ctx)
+     261                 :            : {
+     262                 :        791 :     mbedtls_aes_free((mbedtls_aes_context *) ctx);
+     263                 :        791 :     mbedtls_free(ctx);
+     264                 :        791 : }
+     265                 :            : 
+     266                 :            : static const mbedtls_cipher_base_t aes_info = {
+     267                 :            :     MBEDTLS_CIPHER_ID_AES,
+     268                 :            :     aes_crypt_ecb_wrap,
+     269                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+     270                 :            :     aes_crypt_cbc_wrap,
+     271                 :            : #endif
+     272                 :            : #if defined(MBEDTLS_CIPHER_MODE_CFB)
+     273                 :            :     aes_crypt_cfb128_wrap,
+     274                 :            : #endif
+     275                 :            : #if defined(MBEDTLS_CIPHER_MODE_OFB)
+     276                 :            :     aes_crypt_ofb_wrap,
+     277                 :            : #endif
+     278                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR)
+     279                 :            :     aes_crypt_ctr_wrap,
+     280                 :            : #endif
+     281                 :            : #if defined(MBEDTLS_CIPHER_MODE_XTS)
+     282                 :            :     NULL,
+     283                 :            : #endif
+     284                 :            : #if defined(MBEDTLS_CIPHER_MODE_STREAM)
+     285                 :            :     NULL,
+     286                 :            : #endif
+     287                 :            :     aes_setkey_enc_wrap,
+     288                 :            : #if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
+     289                 :            :     aes_setkey_dec_wrap,
+     290                 :            : #endif
+     291                 :            :     aes_ctx_alloc,
+     292                 :            :     aes_ctx_free
+     293                 :            : };
+     294                 :            : 
+     295                 :            : static const mbedtls_cipher_info_t aes_128_ecb_info = {
+     296                 :            :     "AES-128-ECB",
+     297                 :            :     16,
+     298                 :            :     0 >> MBEDTLS_IV_SIZE_SHIFT,
+     299                 :            :     128 >> MBEDTLS_KEY_BITLEN_SHIFT,
+     300                 :            :     MBEDTLS_MODE_ECB,
+     301                 :            :     MBEDTLS_CIPHER_AES_128_ECB,
+     302                 :            :     0,
+     303                 :            :     MBEDTLS_CIPHER_BASE_INDEX_AES
+     304                 :            : };
+     305                 :            : 
+     306                 :            : #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
+     307                 :            : static const mbedtls_cipher_info_t aes_192_ecb_info = {
+     308                 :            :     "AES-192-ECB",
+     309                 :            :     16,
+     310                 :            :     0 >> MBEDTLS_IV_SIZE_SHIFT,
+     311                 :            :     192 >> MBEDTLS_KEY_BITLEN_SHIFT,
+     312                 :            :     MBEDTLS_MODE_ECB,
+     313                 :            :     MBEDTLS_CIPHER_AES_192_ECB,
+     314                 :            :     0,
+     315                 :            :     MBEDTLS_CIPHER_BASE_INDEX_AES
+     316                 :            : };
+     317                 :            : 
+     318                 :            : static const mbedtls_cipher_info_t aes_256_ecb_info = {
+     319                 :            :     "AES-256-ECB",
+     320                 :            :     16,
+     321                 :            :     0 >> MBEDTLS_IV_SIZE_SHIFT,
+     322                 :            :     256 >> MBEDTLS_KEY_BITLEN_SHIFT,
+     323                 :            :     MBEDTLS_MODE_ECB,
+     324                 :            :     MBEDTLS_CIPHER_AES_256_ECB,
+     325                 :            :     0,
+     326                 :            :     MBEDTLS_CIPHER_BASE_INDEX_AES
+     327                 :            : };
+     328                 :            : #endif
+     329                 :            : 
+     330                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+     331                 :            : static const mbedtls_cipher_info_t aes_128_cbc_info = {
+     332                 :            :     "AES-128-CBC",
+     333                 :            :     16,
+     334                 :            :     16 >> MBEDTLS_IV_SIZE_SHIFT,
+     335                 :            :     128 >> MBEDTLS_KEY_BITLEN_SHIFT,
+     336                 :            :     MBEDTLS_MODE_CBC,
+     337                 :            :     MBEDTLS_CIPHER_AES_128_CBC,
+     338                 :            :     0,
+     339                 :            :     MBEDTLS_CIPHER_BASE_INDEX_AES
+     340                 :            : };
+     341                 :            : 
+     342                 :            : #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
+     343                 :            : static const mbedtls_cipher_info_t aes_192_cbc_info = {
+     344                 :            :     "AES-192-CBC",
+     345                 :            :     16,
+     346                 :            :     16 >> MBEDTLS_IV_SIZE_SHIFT,
+     347                 :            :     192 >> MBEDTLS_KEY_BITLEN_SHIFT,
+     348                 :            :     MBEDTLS_MODE_CBC,
+     349                 :            :     MBEDTLS_CIPHER_AES_192_CBC,
+     350                 :            :     0,
+     351                 :            :     MBEDTLS_CIPHER_BASE_INDEX_AES
+     352                 :            : };
+     353                 :            : 
+     354                 :            : static const mbedtls_cipher_info_t aes_256_cbc_info = {
+     355                 :            :     "AES-256-CBC",
+     356                 :            :     16,
+     357                 :            :     16 >> MBEDTLS_IV_SIZE_SHIFT,
+     358                 :            :     256 >> MBEDTLS_KEY_BITLEN_SHIFT,
+     359                 :            :     MBEDTLS_MODE_CBC,
+     360                 :            :     MBEDTLS_CIPHER_AES_256_CBC,
+     361                 :            :     0,
+     362                 :            :     MBEDTLS_CIPHER_BASE_INDEX_AES
+     363                 :            : };
+     364                 :            : #endif
+     365                 :            : #endif /* MBEDTLS_CIPHER_MODE_CBC */
+     366                 :            : 
+     367                 :            : #if defined(MBEDTLS_CIPHER_MODE_CFB)
+     368                 :            : static const mbedtls_cipher_info_t aes_128_cfb128_info = {
+     369                 :            :     "AES-128-CFB128",
+     370                 :            :     16,
+     371                 :            :     16 >> MBEDTLS_IV_SIZE_SHIFT,
+     372                 :            :     128 >> MBEDTLS_KEY_BITLEN_SHIFT,
+     373                 :            :     MBEDTLS_MODE_CFB,
+     374                 :            :     MBEDTLS_CIPHER_AES_128_CFB128,
+     375                 :            :     0,
+     376                 :            :     MBEDTLS_CIPHER_BASE_INDEX_AES
+     377                 :            : };
+     378                 :            : 
+     379                 :            : #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
+     380                 :            : static const mbedtls_cipher_info_t aes_192_cfb128_info = {
+     381                 :            :     "AES-192-CFB128",
+     382                 :            :     16,
+     383                 :            :     16 >> MBEDTLS_IV_SIZE_SHIFT,
+     384                 :            :     192 >> MBEDTLS_KEY_BITLEN_SHIFT,
+     385                 :            :     MBEDTLS_MODE_CFB,
+     386                 :            :     MBEDTLS_CIPHER_AES_192_CFB128,
+     387                 :            :     0,
+     388                 :            :     MBEDTLS_CIPHER_BASE_INDEX_AES
+     389                 :            : };
+     390                 :            : 
+     391                 :            : static const mbedtls_cipher_info_t aes_256_cfb128_info = {
+     392                 :            :     "AES-256-CFB128",
+     393                 :            :     16,
+     394                 :            :     16 >> MBEDTLS_IV_SIZE_SHIFT,
+     395                 :            :     256 >> MBEDTLS_KEY_BITLEN_SHIFT,
+     396                 :            :     MBEDTLS_MODE_CFB,
+     397                 :            :     MBEDTLS_CIPHER_AES_256_CFB128,
+     398                 :            :     0,
+     399                 :            :     MBEDTLS_CIPHER_BASE_INDEX_AES
+     400                 :            : };
+     401                 :            : #endif
+     402                 :            : #endif /* MBEDTLS_CIPHER_MODE_CFB */
+     403                 :            : 
+     404                 :            : #if defined(MBEDTLS_CIPHER_MODE_OFB)
+     405                 :            : static const mbedtls_cipher_info_t aes_128_ofb_info = {
+     406                 :            :     "AES-128-OFB",
+     407                 :            :     16,
+     408                 :            :     16 >> MBEDTLS_IV_SIZE_SHIFT,
+     409                 :            :     128 >> MBEDTLS_KEY_BITLEN_SHIFT,
+     410                 :            :     MBEDTLS_MODE_OFB,
+     411                 :            :     MBEDTLS_CIPHER_AES_128_OFB,
+     412                 :            :     0,
+     413                 :            :     MBEDTLS_CIPHER_BASE_INDEX_AES
+     414                 :            : };
+     415                 :            : 
+     416                 :            : #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
+     417                 :            : static const mbedtls_cipher_info_t aes_192_ofb_info = {
+     418                 :            :     "AES-192-OFB",
+     419                 :            :     16,
+     420                 :            :     16 >> MBEDTLS_IV_SIZE_SHIFT,
+     421                 :            :     192 >> MBEDTLS_KEY_BITLEN_SHIFT,
+     422                 :            :     MBEDTLS_MODE_OFB,
+     423                 :            :     MBEDTLS_CIPHER_AES_192_OFB,
+     424                 :            :     0,
+     425                 :            :     MBEDTLS_CIPHER_BASE_INDEX_AES
+     426                 :            : };
+     427                 :            : 
+     428                 :            : static const mbedtls_cipher_info_t aes_256_ofb_info = {
+     429                 :            :     "AES-256-OFB",
+     430                 :            :     16,
+     431                 :            :     16 >> MBEDTLS_IV_SIZE_SHIFT,
+     432                 :            :     256 >> MBEDTLS_KEY_BITLEN_SHIFT,
+     433                 :            :     MBEDTLS_MODE_OFB,
+     434                 :            :     MBEDTLS_CIPHER_AES_256_OFB,
+     435                 :            :     0,
+     436                 :            :     MBEDTLS_CIPHER_BASE_INDEX_AES
+     437                 :            : };
+     438                 :            : #endif
+     439                 :            : #endif /* MBEDTLS_CIPHER_MODE_OFB */
+     440                 :            : 
+     441                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR)
+     442                 :            : static const mbedtls_cipher_info_t aes_128_ctr_info = {
+     443                 :            :     "AES-128-CTR",
+     444                 :            :     16,
+     445                 :            :     16 >> MBEDTLS_IV_SIZE_SHIFT,
+     446                 :            :     128 >> MBEDTLS_KEY_BITLEN_SHIFT,
+     447                 :            :     MBEDTLS_MODE_CTR,
+     448                 :            :     MBEDTLS_CIPHER_AES_128_CTR,
+     449                 :            :     0,
+     450                 :            :     MBEDTLS_CIPHER_BASE_INDEX_AES
+     451                 :            : };
+     452                 :            : 
+     453                 :            : #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
+     454                 :            : static const mbedtls_cipher_info_t aes_192_ctr_info = {
+     455                 :            :     "AES-192-CTR",
+     456                 :            :     16,
+     457                 :            :     16 >> MBEDTLS_IV_SIZE_SHIFT,
+     458                 :            :     192 >> MBEDTLS_KEY_BITLEN_SHIFT,
+     459                 :            :     MBEDTLS_MODE_CTR,
+     460                 :            :     MBEDTLS_CIPHER_AES_192_CTR,
+     461                 :            :     0,
+     462                 :            :     MBEDTLS_CIPHER_BASE_INDEX_AES
+     463                 :            : };
+     464                 :            : 
+     465                 :            : static const mbedtls_cipher_info_t aes_256_ctr_info = {
+     466                 :            :     "AES-256-CTR",
+     467                 :            :     16,
+     468                 :            :     16 >> MBEDTLS_IV_SIZE_SHIFT,
+     469                 :            :     256 >> MBEDTLS_KEY_BITLEN_SHIFT,
+     470                 :            :     MBEDTLS_MODE_CTR,
+     471                 :            :     MBEDTLS_CIPHER_AES_256_CTR,
+     472                 :            :     0,
+     473                 :            :     MBEDTLS_CIPHER_BASE_INDEX_AES
+     474                 :            : };
+     475                 :            : #endif
+     476                 :            : #endif /* MBEDTLS_CIPHER_MODE_CTR */
+     477                 :            : 
+     478                 :            : #if defined(MBEDTLS_CIPHER_MODE_XTS)
+     479                 :            : static int xts_aes_setkey_enc_wrap(void *ctx, const unsigned char *key,
+     480                 :            :                                    unsigned int key_bitlen)
+     481                 :            : {
+     482                 :            :     mbedtls_aes_xts_context *xts_ctx = ctx;
+     483                 :            :     return mbedtls_aes_xts_setkey_enc(xts_ctx, key, key_bitlen);
+     484                 :            : }
+     485                 :            : 
+     486                 :            : static int xts_aes_setkey_dec_wrap(void *ctx, const unsigned char *key,
+     487                 :            :                                    unsigned int key_bitlen)
+     488                 :            : {
+     489                 :            :     mbedtls_aes_xts_context *xts_ctx = ctx;
+     490                 :            :     return mbedtls_aes_xts_setkey_dec(xts_ctx, key, key_bitlen);
+     491                 :            : }
+     492                 :            : 
+     493                 :            : static void *xts_aes_ctx_alloc(void)
+     494                 :            : {
+     495                 :            :     mbedtls_aes_xts_context *xts_ctx = mbedtls_calloc(1, sizeof(*xts_ctx));
+     496                 :            : 
+     497                 :            :     if (xts_ctx != NULL) {
+     498                 :            :         mbedtls_aes_xts_init(xts_ctx);
+     499                 :            :     }
+     500                 :            : 
+     501                 :            :     return xts_ctx;
+     502                 :            : }
+     503                 :            : 
+     504                 :            : static void xts_aes_ctx_free(void *ctx)
+     505                 :            : {
+     506                 :            :     mbedtls_aes_xts_context *xts_ctx = ctx;
+     507                 :            : 
+     508                 :            :     if (xts_ctx == NULL) {
+     509                 :            :         return;
+     510                 :            :     }
+     511                 :            : 
+     512                 :            :     mbedtls_aes_xts_free(xts_ctx);
+     513                 :            :     mbedtls_free(xts_ctx);
+     514                 :            : }
+     515                 :            : 
+     516                 :            : static const mbedtls_cipher_base_t xts_aes_info = {
+     517                 :            :     MBEDTLS_CIPHER_ID_AES,
+     518                 :            :     NULL,
+     519                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+     520                 :            :     NULL,
+     521                 :            : #endif
+     522                 :            : #if defined(MBEDTLS_CIPHER_MODE_CFB)
+     523                 :            :     NULL,
+     524                 :            : #endif
+     525                 :            : #if defined(MBEDTLS_CIPHER_MODE_OFB)
+     526                 :            :     NULL,
+     527                 :            : #endif
+     528                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR)
+     529                 :            :     NULL,
+     530                 :            : #endif
+     531                 :            : #if defined(MBEDTLS_CIPHER_MODE_XTS)
+     532                 :            :     aes_crypt_xts_wrap,
+     533                 :            : #endif
+     534                 :            : #if defined(MBEDTLS_CIPHER_MODE_STREAM)
+     535                 :            :     NULL,
+     536                 :            : #endif
+     537                 :            :     xts_aes_setkey_enc_wrap,
+     538                 :            :     xts_aes_setkey_dec_wrap,
+     539                 :            :     xts_aes_ctx_alloc,
+     540                 :            :     xts_aes_ctx_free
+     541                 :            : };
+     542                 :            : 
+     543                 :            : static const mbedtls_cipher_info_t aes_128_xts_info = {
+     544                 :            :     "AES-128-XTS",
+     545                 :            :     16,
+     546                 :            :     16 >> MBEDTLS_IV_SIZE_SHIFT,
+     547                 :            :     256 >> MBEDTLS_KEY_BITLEN_SHIFT,
+     548                 :            :     MBEDTLS_MODE_XTS,
+     549                 :            :     MBEDTLS_CIPHER_AES_128_XTS,
+     550                 :            :     0,
+     551                 :            :     MBEDTLS_CIPHER_BASE_INDEX_XTS_AES
+     552                 :            : };
+     553                 :            : 
+     554                 :            : #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
+     555                 :            : static const mbedtls_cipher_info_t aes_256_xts_info = {
+     556                 :            :     "AES-256-XTS",
+     557                 :            :     16,
+     558                 :            :     16 >> MBEDTLS_IV_SIZE_SHIFT,
+     559                 :            :     512 >> MBEDTLS_KEY_BITLEN_SHIFT,
+     560                 :            :     MBEDTLS_MODE_XTS,
+     561                 :            :     MBEDTLS_CIPHER_AES_256_XTS,
+     562                 :            :     0,
+     563                 :            :     MBEDTLS_CIPHER_BASE_INDEX_XTS_AES
+     564                 :            : };
+     565                 :            : #endif
+     566                 :            : #endif /* MBEDTLS_CIPHER_MODE_XTS */
+     567                 :            : #endif /* MBEDTLS_AES_C */
+     568                 :            : 
+     569                 :            : #if defined(MBEDTLS_GCM_C) && defined(MBEDTLS_CCM_GCM_CAN_AES)
+     570                 :          0 : static int gcm_aes_setkey_wrap(void *ctx, const unsigned char *key,
+     571                 :            :                                unsigned int key_bitlen)
+     572                 :            : {
+     573                 :          0 :     return mbedtls_gcm_setkey((mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
+     574                 :            :                               key, key_bitlen);
+     575                 :            : }
+     576                 :            : #endif /* MBEDTLS_GCM_C && MBEDTLS_CCM_GCM_CAN_AES */
+     577                 :            : 
+     578                 :            : #if defined(MBEDTLS_CIPHER_HAVE_GCM_AES_VIA_LEGACY_OR_USE_PSA)
+     579                 :            : static const mbedtls_cipher_base_t gcm_aes_info = {
+     580                 :            :     MBEDTLS_CIPHER_ID_AES,
+     581                 :            :     NULL,
+     582                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+     583                 :            :     NULL,
+     584                 :            : #endif
+     585                 :            : #if defined(MBEDTLS_CIPHER_MODE_CFB)
+     586                 :            :     NULL,
+     587                 :            : #endif
+     588                 :            : #if defined(MBEDTLS_CIPHER_MODE_OFB)
+     589                 :            :     NULL,
+     590                 :            : #endif
+     591                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR)
+     592                 :            :     NULL,
+     593                 :            : #endif
+     594                 :            : #if defined(MBEDTLS_CIPHER_MODE_XTS)
+     595                 :            :     NULL,
+     596                 :            : #endif
+     597                 :            : #if defined(MBEDTLS_CIPHER_MODE_STREAM)
+     598                 :            :     NULL,
+     599                 :            : #endif
+     600                 :            : #if defined(MBEDTLS_GCM_C)
+     601                 :            :     gcm_aes_setkey_wrap,
+     602                 :            : #if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
+     603                 :            :     gcm_aes_setkey_wrap,
+     604                 :            : #endif
+     605                 :            :     gcm_ctx_alloc,
+     606                 :            :     gcm_ctx_free,
+     607                 :            : #else
+     608                 :            :     NULL,
+     609                 :            :     NULL,
+     610                 :            :     NULL,
+     611                 :            :     NULL,
+     612                 :            : #endif /* MBEDTLS_GCM_C */
+     613                 :            : };
+     614                 :            : #endif /* MBEDTLS_CIPHER_HAVE_GCM_AES_VIA_LEGACY_OR_USE_PSA */
+     615                 :            : 
+     616                 :            : #if defined(MBEDTLS_CIPHER_HAVE_GCM_AES_VIA_LEGACY_OR_USE_PSA)
+     617                 :            : static const mbedtls_cipher_info_t aes_128_gcm_info = {
+     618                 :            :     "AES-128-GCM",
+     619                 :            :     16,
+     620                 :            :     12 >> MBEDTLS_IV_SIZE_SHIFT,
+     621                 :            :     128 >> MBEDTLS_KEY_BITLEN_SHIFT,
+     622                 :            :     MBEDTLS_MODE_GCM,
+     623                 :            :     MBEDTLS_CIPHER_AES_128_GCM,
+     624                 :            :     MBEDTLS_CIPHER_VARIABLE_IV_LEN,
+     625                 :            :     MBEDTLS_CIPHER_BASE_INDEX_GCM_AES
+     626                 :            : };
+     627                 :            : 
+     628                 :            : #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
+     629                 :            : static const mbedtls_cipher_info_t aes_192_gcm_info = {
+     630                 :            :     "AES-192-GCM",
+     631                 :            :     16,
+     632                 :            :     12 >> MBEDTLS_IV_SIZE_SHIFT,
+     633                 :            :     192 >> MBEDTLS_KEY_BITLEN_SHIFT,
+     634                 :            :     MBEDTLS_MODE_GCM,
+     635                 :            :     MBEDTLS_CIPHER_AES_192_GCM,
+     636                 :            :     MBEDTLS_CIPHER_VARIABLE_IV_LEN,
+     637                 :            :     MBEDTLS_CIPHER_BASE_INDEX_GCM_AES
+     638                 :            : };
+     639                 :            : 
+     640                 :            : static const mbedtls_cipher_info_t aes_256_gcm_info = {
+     641                 :            :     "AES-256-GCM",
+     642                 :            :     16,
+     643                 :            :     12 >> MBEDTLS_IV_SIZE_SHIFT,
+     644                 :            :     256 >> MBEDTLS_KEY_BITLEN_SHIFT,
+     645                 :            :     MBEDTLS_MODE_GCM,
+     646                 :            :     MBEDTLS_CIPHER_AES_256_GCM,
+     647                 :            :     MBEDTLS_CIPHER_VARIABLE_IV_LEN,
+     648                 :            :     MBEDTLS_CIPHER_BASE_INDEX_GCM_AES
+     649                 :            : };
+     650                 :            : #endif
+     651                 :            : #endif /* MBEDTLS_CIPHER_HAVE_GCM_AES_VIA_LEGACY_OR_USE_PSA */
+     652                 :            : 
+     653                 :            : #if defined(MBEDTLS_CCM_C) && defined(MBEDTLS_CCM_GCM_CAN_AES)
+     654                 :          0 : static int ccm_aes_setkey_wrap(void *ctx, const unsigned char *key,
+     655                 :            :                                unsigned int key_bitlen)
+     656                 :            : {
+     657                 :          0 :     return mbedtls_ccm_setkey((mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
+     658                 :            :                               key, key_bitlen);
+     659                 :            : }
+     660                 :            : #endif /* MBEDTLS_CCM_C && MBEDTLS_CCM_GCM_CAN_AES */
+     661                 :            : 
+     662                 :            : #if defined(MBEDTLS_CIPHER_HAVE_CCM_AES_VIA_LEGACY_OR_USE_PSA)
+     663                 :            : static const mbedtls_cipher_base_t ccm_aes_info = {
+     664                 :            :     MBEDTLS_CIPHER_ID_AES,
+     665                 :            :     NULL,
+     666                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+     667                 :            :     NULL,
+     668                 :            : #endif
+     669                 :            : #if defined(MBEDTLS_CIPHER_MODE_CFB)
+     670                 :            :     NULL,
+     671                 :            : #endif
+     672                 :            : #if defined(MBEDTLS_CIPHER_MODE_OFB)
+     673                 :            :     NULL,
+     674                 :            : #endif
+     675                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR)
+     676                 :            :     NULL,
+     677                 :            : #endif
+     678                 :            : #if defined(MBEDTLS_CIPHER_MODE_XTS)
+     679                 :            :     NULL,
+     680                 :            : #endif
+     681                 :            : #if defined(MBEDTLS_CIPHER_MODE_STREAM)
+     682                 :            :     NULL,
+     683                 :            : #endif
+     684                 :            : #if defined(MBEDTLS_CCM_C)
+     685                 :            :     ccm_aes_setkey_wrap,
+     686                 :            : #if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
+     687                 :            :     ccm_aes_setkey_wrap,
+     688                 :            : #endif
+     689                 :            :     ccm_ctx_alloc,
+     690                 :            :     ccm_ctx_free,
+     691                 :            : #else
+     692                 :            :     NULL,
+     693                 :            :     NULL,
+     694                 :            :     NULL,
+     695                 :            :     NULL,
+     696                 :            : #endif
+     697                 :            : };
+     698                 :            : #endif /* MBEDTLS_CIPHER_HAVE_CCM_AES_VIA_LEGACY_OR_USE_PSA */
+     699                 :            : 
+     700                 :            : #if defined(MBEDTLS_CIPHER_HAVE_CCM_AES_VIA_LEGACY_OR_USE_PSA)
+     701                 :            : static const mbedtls_cipher_info_t aes_128_ccm_info = {
+     702                 :            :     "AES-128-CCM",
+     703                 :            :     16,
+     704                 :            :     12 >> MBEDTLS_IV_SIZE_SHIFT,
+     705                 :            :     128 >> MBEDTLS_KEY_BITLEN_SHIFT,
+     706                 :            :     MBEDTLS_MODE_CCM,
+     707                 :            :     MBEDTLS_CIPHER_AES_128_CCM,
+     708                 :            :     MBEDTLS_CIPHER_VARIABLE_IV_LEN,
+     709                 :            :     MBEDTLS_CIPHER_BASE_INDEX_CCM_AES
+     710                 :            : };
+     711                 :            : 
+     712                 :            : #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
+     713                 :            : static const mbedtls_cipher_info_t aes_192_ccm_info = {
+     714                 :            :     "AES-192-CCM",
+     715                 :            :     16,
+     716                 :            :     12 >> MBEDTLS_IV_SIZE_SHIFT,
+     717                 :            :     192 >> MBEDTLS_KEY_BITLEN_SHIFT,
+     718                 :            :     MBEDTLS_MODE_CCM,
+     719                 :            :     MBEDTLS_CIPHER_AES_192_CCM,
+     720                 :            :     MBEDTLS_CIPHER_VARIABLE_IV_LEN,
+     721                 :            :     MBEDTLS_CIPHER_BASE_INDEX_CCM_AES
+     722                 :            : };
+     723                 :            : 
+     724                 :            : static const mbedtls_cipher_info_t aes_256_ccm_info = {
+     725                 :            :     "AES-256-CCM",
+     726                 :            :     16,
+     727                 :            :     12 >> MBEDTLS_IV_SIZE_SHIFT,
+     728                 :            :     256 >> MBEDTLS_KEY_BITLEN_SHIFT,
+     729                 :            :     MBEDTLS_MODE_CCM,
+     730                 :            :     MBEDTLS_CIPHER_AES_256_CCM,
+     731                 :            :     MBEDTLS_CIPHER_VARIABLE_IV_LEN,
+     732                 :            :     MBEDTLS_CIPHER_BASE_INDEX_CCM_AES
+     733                 :            : };
+     734                 :            : #endif
+     735                 :            : #endif /* MBEDTLS_CIPHER_HAVE_CCM_AES_VIA_LEGACY_OR_USE_PSA */
+     736                 :            : 
+     737                 :            : #if defined(MBEDTLS_CIPHER_HAVE_CCM_STAR_NO_TAG_AES_VIA_LEGACY_OR_USE_PSA)
+     738                 :            : static const mbedtls_cipher_info_t aes_128_ccm_star_no_tag_info = {
+     739                 :            :     "AES-128-CCM*-NO-TAG",
+     740                 :            :     16,
+     741                 :            :     12 >> MBEDTLS_IV_SIZE_SHIFT,
+     742                 :            :     128 >> MBEDTLS_KEY_BITLEN_SHIFT,
+     743                 :            :     MBEDTLS_MODE_CCM_STAR_NO_TAG,
+     744                 :            :     MBEDTLS_CIPHER_AES_128_CCM_STAR_NO_TAG,
+     745                 :            :     MBEDTLS_CIPHER_VARIABLE_IV_LEN,
+     746                 :            :     MBEDTLS_CIPHER_BASE_INDEX_CCM_AES
+     747                 :            : };
+     748                 :            : 
+     749                 :            : #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
+     750                 :            : static const mbedtls_cipher_info_t aes_192_ccm_star_no_tag_info = {
+     751                 :            :     "AES-192-CCM*-NO-TAG",
+     752                 :            :     16,
+     753                 :            :     12 >> MBEDTLS_IV_SIZE_SHIFT,
+     754                 :            :     192 >> MBEDTLS_KEY_BITLEN_SHIFT,
+     755                 :            :     MBEDTLS_MODE_CCM_STAR_NO_TAG,
+     756                 :            :     MBEDTLS_CIPHER_AES_192_CCM_STAR_NO_TAG,
+     757                 :            :     MBEDTLS_CIPHER_VARIABLE_IV_LEN,
+     758                 :            :     MBEDTLS_CIPHER_BASE_INDEX_CCM_AES
+     759                 :            : };
+     760                 :            : 
+     761                 :            : static const mbedtls_cipher_info_t aes_256_ccm_star_no_tag_info = {
+     762                 :            :     "AES-256-CCM*-NO-TAG",
+     763                 :            :     16,
+     764                 :            :     12 >> MBEDTLS_IV_SIZE_SHIFT,
+     765                 :            :     256 >> MBEDTLS_KEY_BITLEN_SHIFT,
+     766                 :            :     MBEDTLS_MODE_CCM_STAR_NO_TAG,
+     767                 :            :     MBEDTLS_CIPHER_AES_256_CCM_STAR_NO_TAG,
+     768                 :            :     MBEDTLS_CIPHER_VARIABLE_IV_LEN,
+     769                 :            :     MBEDTLS_CIPHER_BASE_INDEX_CCM_AES
+     770                 :            : };
+     771                 :            : #endif
+     772                 :            : #endif /* MBEDTLS_CIPHER_HAVE_CCM_STAR_NO_TAG_AES_VIA_LEGACY_OR_USE_PSA */
+     773                 :            : 
+     774                 :            : 
+     775                 :            : #if defined(MBEDTLS_CAMELLIA_C)
+     776                 :            : 
+     777                 :          0 : static int camellia_crypt_ecb_wrap(void *ctx, mbedtls_operation_t operation,
+     778                 :            :                                    const unsigned char *input, unsigned char *output)
+     779                 :            : {
+     780                 :          0 :     return mbedtls_camellia_crypt_ecb((mbedtls_camellia_context *) ctx, operation, input,
+     781                 :            :                                       output);
+     782                 :            : }
+     783                 :            : 
+     784                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+     785                 :          0 : static int camellia_crypt_cbc_wrap(void *ctx, mbedtls_operation_t operation,
+     786                 :            :                                    size_t length, unsigned char *iv,
+     787                 :            :                                    const unsigned char *input, unsigned char *output)
+     788                 :            : {
+     789                 :          0 :     return mbedtls_camellia_crypt_cbc((mbedtls_camellia_context *) ctx, operation, length, iv,
+     790                 :            :                                       input, output);
+     791                 :            : }
+     792                 :            : #endif /* MBEDTLS_CIPHER_MODE_CBC */
+     793                 :            : 
+     794                 :            : #if defined(MBEDTLS_CIPHER_MODE_CFB)
+     795                 :          0 : static int camellia_crypt_cfb128_wrap(void *ctx, mbedtls_operation_t operation,
+     796                 :            :                                       size_t length, size_t *iv_off, unsigned char *iv,
+     797                 :            :                                       const unsigned char *input, unsigned char *output)
+     798                 :            : {
+     799                 :          0 :     return mbedtls_camellia_crypt_cfb128((mbedtls_camellia_context *) ctx, operation, length,
+     800                 :            :                                          iv_off, iv, input, output);
+     801                 :            : }
+     802                 :            : #endif /* MBEDTLS_CIPHER_MODE_CFB */
+     803                 :            : 
+     804                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR)
+     805                 :          0 : static int camellia_crypt_ctr_wrap(void *ctx, size_t length, size_t *nc_off,
+     806                 :            :                                    unsigned char *nonce_counter, unsigned char *stream_block,
+     807                 :            :                                    const unsigned char *input, unsigned char *output)
+     808                 :            : {
+     809                 :          0 :     return mbedtls_camellia_crypt_ctr((mbedtls_camellia_context *) ctx, length, nc_off,
+     810                 :            :                                       nonce_counter, stream_block, input, output);
+     811                 :            : }
+     812                 :            : #endif /* MBEDTLS_CIPHER_MODE_CTR */
+     813                 :            : 
+     814                 :            : #if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
+     815                 :          0 : static int camellia_setkey_dec_wrap(void *ctx, const unsigned char *key,
+     816                 :            :                                     unsigned int key_bitlen)
+     817                 :            : {
+     818                 :          0 :     return mbedtls_camellia_setkey_dec((mbedtls_camellia_context *) ctx, key, key_bitlen);
+     819                 :            : }
+     820                 :            : #endif
+     821                 :            : 
+     822                 :          0 : static int camellia_setkey_enc_wrap(void *ctx, const unsigned char *key,
+     823                 :            :                                     unsigned int key_bitlen)
+     824                 :            : {
+     825                 :          0 :     return mbedtls_camellia_setkey_enc((mbedtls_camellia_context *) ctx, key, key_bitlen);
+     826                 :            : }
+     827                 :            : 
+     828                 :          0 : static void *camellia_ctx_alloc(void)
+     829                 :            : {
+     830                 :            :     mbedtls_camellia_context *ctx;
+     831                 :          0 :     ctx = mbedtls_calloc(1, sizeof(mbedtls_camellia_context));
+     832                 :            : 
+     833         [ #  # ]:          0 :     if (ctx == NULL) {
+     834                 :          0 :         return NULL;
+     835                 :            :     }
+     836                 :            : 
+     837                 :          0 :     mbedtls_camellia_init(ctx);
+     838                 :            : 
+     839                 :          0 :     return ctx;
+     840                 :            : }
+     841                 :            : 
+     842                 :          0 : static void camellia_ctx_free(void *ctx)
+     843                 :            : {
+     844                 :          0 :     mbedtls_camellia_free((mbedtls_camellia_context *) ctx);
+     845                 :          0 :     mbedtls_free(ctx);
+     846                 :          0 : }
+     847                 :            : 
+     848                 :            : static const mbedtls_cipher_base_t camellia_info = {
+     849                 :            :     MBEDTLS_CIPHER_ID_CAMELLIA,
+     850                 :            :     camellia_crypt_ecb_wrap,
+     851                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+     852                 :            :     camellia_crypt_cbc_wrap,
+     853                 :            : #endif
+     854                 :            : #if defined(MBEDTLS_CIPHER_MODE_CFB)
+     855                 :            :     camellia_crypt_cfb128_wrap,
+     856                 :            : #endif
+     857                 :            : #if defined(MBEDTLS_CIPHER_MODE_OFB)
+     858                 :            :     NULL,
+     859                 :            : #endif
+     860                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR)
+     861                 :            :     camellia_crypt_ctr_wrap,
+     862                 :            : #endif
+     863                 :            : #if defined(MBEDTLS_CIPHER_MODE_XTS)
+     864                 :            :     NULL,
+     865                 :            : #endif
+     866                 :            : #if defined(MBEDTLS_CIPHER_MODE_STREAM)
+     867                 :            :     NULL,
+     868                 :            : #endif
+     869                 :            :     camellia_setkey_enc_wrap,
+     870                 :            : #if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
+     871                 :            :     camellia_setkey_dec_wrap,
+     872                 :            : #endif
+     873                 :            :     camellia_ctx_alloc,
+     874                 :            :     camellia_ctx_free
+     875                 :            : };
+     876                 :            : 
+     877                 :            : static const mbedtls_cipher_info_t camellia_128_ecb_info = {
+     878                 :            :     "CAMELLIA-128-ECB",
+     879                 :            :     16,
+     880                 :            :     0 >> MBEDTLS_IV_SIZE_SHIFT,
+     881                 :            :     128 >> MBEDTLS_KEY_BITLEN_SHIFT,
+     882                 :            :     MBEDTLS_MODE_ECB,
+     883                 :            :     MBEDTLS_CIPHER_CAMELLIA_128_ECB,
+     884                 :            :     0,
+     885                 :            :     MBEDTLS_CIPHER_BASE_INDEX_CAMELLIA
+     886                 :            : };
+     887                 :            : 
+     888                 :            : static const mbedtls_cipher_info_t camellia_192_ecb_info = {
+     889                 :            :     "CAMELLIA-192-ECB",
+     890                 :            :     16,
+     891                 :            :     0 >> MBEDTLS_IV_SIZE_SHIFT,
+     892                 :            :     192 >> MBEDTLS_KEY_BITLEN_SHIFT,
+     893                 :            :     MBEDTLS_MODE_ECB,
+     894                 :            :     MBEDTLS_CIPHER_CAMELLIA_192_ECB,
+     895                 :            :     0,
+     896                 :            :     MBEDTLS_CIPHER_BASE_INDEX_CAMELLIA
+     897                 :            : };
+     898                 :            : 
+     899                 :            : static const mbedtls_cipher_info_t camellia_256_ecb_info = {
+     900                 :            :     "CAMELLIA-256-ECB",
+     901                 :            :     16,
+     902                 :            :     0 >> MBEDTLS_IV_SIZE_SHIFT,
+     903                 :            :     256 >> MBEDTLS_KEY_BITLEN_SHIFT,
+     904                 :            :     MBEDTLS_MODE_ECB,
+     905                 :            :     MBEDTLS_CIPHER_CAMELLIA_256_ECB,
+     906                 :            :     0,
+     907                 :            :     MBEDTLS_CIPHER_BASE_INDEX_CAMELLIA
+     908                 :            : };
+     909                 :            : 
+     910                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+     911                 :            : static const mbedtls_cipher_info_t camellia_128_cbc_info = {
+     912                 :            :     "CAMELLIA-128-CBC",
+     913                 :            :     16,
+     914                 :            :     16 >> MBEDTLS_IV_SIZE_SHIFT,
+     915                 :            :     128 >> MBEDTLS_KEY_BITLEN_SHIFT,
+     916                 :            :     MBEDTLS_MODE_CBC,
+     917                 :            :     MBEDTLS_CIPHER_CAMELLIA_128_CBC,
+     918                 :            :     0,
+     919                 :            :     MBEDTLS_CIPHER_BASE_INDEX_CAMELLIA
+     920                 :            : };
+     921                 :            : 
+     922                 :            : static const mbedtls_cipher_info_t camellia_192_cbc_info = {
+     923                 :            :     "CAMELLIA-192-CBC",
+     924                 :            :     16,
+     925                 :            :     16 >> MBEDTLS_IV_SIZE_SHIFT,
+     926                 :            :     192 >> MBEDTLS_KEY_BITLEN_SHIFT,
+     927                 :            :     MBEDTLS_MODE_CBC,
+     928                 :            :     MBEDTLS_CIPHER_CAMELLIA_192_CBC,
+     929                 :            :     0,
+     930                 :            :     MBEDTLS_CIPHER_BASE_INDEX_CAMELLIA
+     931                 :            : };
+     932                 :            : 
+     933                 :            : static const mbedtls_cipher_info_t camellia_256_cbc_info = {
+     934                 :            :     "CAMELLIA-256-CBC",
+     935                 :            :     16,
+     936                 :            :     16 >> MBEDTLS_IV_SIZE_SHIFT,
+     937                 :            :     256 >> MBEDTLS_KEY_BITLEN_SHIFT,
+     938                 :            :     MBEDTLS_MODE_CBC,
+     939                 :            :     MBEDTLS_CIPHER_CAMELLIA_256_CBC,
+     940                 :            :     0,
+     941                 :            :     MBEDTLS_CIPHER_BASE_INDEX_CAMELLIA
+     942                 :            : };
+     943                 :            : #endif /* MBEDTLS_CIPHER_MODE_CBC */
+     944                 :            : 
+     945                 :            : #if defined(MBEDTLS_CIPHER_MODE_CFB)
+     946                 :            : static const mbedtls_cipher_info_t camellia_128_cfb128_info = {
+     947                 :            :     "CAMELLIA-128-CFB128",
+     948                 :            :     16,
+     949                 :            :     16 >> MBEDTLS_IV_SIZE_SHIFT,
+     950                 :            :     128 >> MBEDTLS_KEY_BITLEN_SHIFT,
+     951                 :            :     MBEDTLS_MODE_CFB,
+     952                 :            :     MBEDTLS_CIPHER_CAMELLIA_128_CFB128,
+     953                 :            :     0,
+     954                 :            :     MBEDTLS_CIPHER_BASE_INDEX_CAMELLIA
+     955                 :            : };
+     956                 :            : 
+     957                 :            : static const mbedtls_cipher_info_t camellia_192_cfb128_info = {
+     958                 :            :     "CAMELLIA-192-CFB128",
+     959                 :            :     16,
+     960                 :            :     16 >> MBEDTLS_IV_SIZE_SHIFT,
+     961                 :            :     192 >> MBEDTLS_KEY_BITLEN_SHIFT,
+     962                 :            :     MBEDTLS_MODE_CFB,
+     963                 :            :     MBEDTLS_CIPHER_CAMELLIA_192_CFB128,
+     964                 :            :     0,
+     965                 :            :     MBEDTLS_CIPHER_BASE_INDEX_CAMELLIA
+     966                 :            : };
+     967                 :            : 
+     968                 :            : static const mbedtls_cipher_info_t camellia_256_cfb128_info = {
+     969                 :            :     "CAMELLIA-256-CFB128",
+     970                 :            :     16,
+     971                 :            :     16 >> MBEDTLS_IV_SIZE_SHIFT,
+     972                 :            :     256 >> MBEDTLS_KEY_BITLEN_SHIFT,
+     973                 :            :     MBEDTLS_MODE_CFB,
+     974                 :            :     MBEDTLS_CIPHER_CAMELLIA_256_CFB128,
+     975                 :            :     0,
+     976                 :            :     MBEDTLS_CIPHER_BASE_INDEX_CAMELLIA
+     977                 :            : };
+     978                 :            : #endif /* MBEDTLS_CIPHER_MODE_CFB */
+     979                 :            : 
+     980                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR)
+     981                 :            : static const mbedtls_cipher_info_t camellia_128_ctr_info = {
+     982                 :            :     "CAMELLIA-128-CTR",
+     983                 :            :     16,
+     984                 :            :     16 >> MBEDTLS_IV_SIZE_SHIFT,
+     985                 :            :     128 >> MBEDTLS_KEY_BITLEN_SHIFT,
+     986                 :            :     MBEDTLS_MODE_CTR,
+     987                 :            :     MBEDTLS_CIPHER_CAMELLIA_128_CTR,
+     988                 :            :     0,
+     989                 :            :     MBEDTLS_CIPHER_BASE_INDEX_CAMELLIA
+     990                 :            : };
+     991                 :            : 
+     992                 :            : static const mbedtls_cipher_info_t camellia_192_ctr_info = {
+     993                 :            :     "CAMELLIA-192-CTR",
+     994                 :            :     16,
+     995                 :            :     16 >> MBEDTLS_IV_SIZE_SHIFT,
+     996                 :            :     192 >> MBEDTLS_KEY_BITLEN_SHIFT,
+     997                 :            :     MBEDTLS_MODE_CTR,
+     998                 :            :     MBEDTLS_CIPHER_CAMELLIA_192_CTR,
+     999                 :            :     0,
+    1000                 :            :     MBEDTLS_CIPHER_BASE_INDEX_CAMELLIA
+    1001                 :            : };
+    1002                 :            : 
+    1003                 :            : static const mbedtls_cipher_info_t camellia_256_ctr_info = {
+    1004                 :            :     "CAMELLIA-256-CTR",
+    1005                 :            :     16,
+    1006                 :            :     16 >> MBEDTLS_IV_SIZE_SHIFT,
+    1007                 :            :     256 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    1008                 :            :     MBEDTLS_MODE_CTR,
+    1009                 :            :     MBEDTLS_CIPHER_CAMELLIA_256_CTR,
+    1010                 :            :     0,
+    1011                 :            :     MBEDTLS_CIPHER_BASE_INDEX_CAMELLIA
+    1012                 :            : };
+    1013                 :            : #endif /* MBEDTLS_CIPHER_MODE_CTR */
+    1014                 :            : 
+    1015                 :            : #if defined(MBEDTLS_GCM_C)
+    1016                 :          0 : static int gcm_camellia_setkey_wrap(void *ctx, const unsigned char *key,
+    1017                 :            :                                     unsigned int key_bitlen)
+    1018                 :            : {
+    1019                 :          0 :     return mbedtls_gcm_setkey((mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
+    1020                 :            :                               key, key_bitlen);
+    1021                 :            : }
+    1022                 :            : 
+    1023                 :            : static const mbedtls_cipher_base_t gcm_camellia_info = {
+    1024                 :            :     MBEDTLS_CIPHER_ID_CAMELLIA,
+    1025                 :            :     NULL,
+    1026                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+    1027                 :            :     NULL,
+    1028                 :            : #endif
+    1029                 :            : #if defined(MBEDTLS_CIPHER_MODE_CFB)
+    1030                 :            :     NULL,
+    1031                 :            : #endif
+    1032                 :            : #if defined(MBEDTLS_CIPHER_MODE_OFB)
+    1033                 :            :     NULL,
+    1034                 :            : #endif
+    1035                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR)
+    1036                 :            :     NULL,
+    1037                 :            : #endif
+    1038                 :            : #if defined(MBEDTLS_CIPHER_MODE_XTS)
+    1039                 :            :     NULL,
+    1040                 :            : #endif
+    1041                 :            : #if defined(MBEDTLS_CIPHER_MODE_STREAM)
+    1042                 :            :     NULL,
+    1043                 :            : #endif
+    1044                 :            :     gcm_camellia_setkey_wrap,
+    1045                 :            : #if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
+    1046                 :            :     gcm_camellia_setkey_wrap,
+    1047                 :            : #endif
+    1048                 :            :     gcm_ctx_alloc,
+    1049                 :            :     gcm_ctx_free,
+    1050                 :            : };
+    1051                 :            : 
+    1052                 :            : static const mbedtls_cipher_info_t camellia_128_gcm_info = {
+    1053                 :            :     "CAMELLIA-128-GCM",
+    1054                 :            :     16,
+    1055                 :            :     12 >> MBEDTLS_IV_SIZE_SHIFT,
+    1056                 :            :     128 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    1057                 :            :     MBEDTLS_MODE_GCM,
+    1058                 :            :     MBEDTLS_CIPHER_CAMELLIA_128_GCM,
+    1059                 :            :     MBEDTLS_CIPHER_VARIABLE_IV_LEN,
+    1060                 :            :     MBEDTLS_CIPHER_BASE_INDEX_GCM_CAMELLIA
+    1061                 :            : };
+    1062                 :            : 
+    1063                 :            : static const mbedtls_cipher_info_t camellia_192_gcm_info = {
+    1064                 :            :     "CAMELLIA-192-GCM",
+    1065                 :            :     16,
+    1066                 :            :     12 >> MBEDTLS_IV_SIZE_SHIFT,
+    1067                 :            :     192 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    1068                 :            :     MBEDTLS_MODE_GCM,
+    1069                 :            :     MBEDTLS_CIPHER_CAMELLIA_192_GCM,
+    1070                 :            :     MBEDTLS_CIPHER_VARIABLE_IV_LEN,
+    1071                 :            :     MBEDTLS_CIPHER_BASE_INDEX_GCM_CAMELLIA
+    1072                 :            : };
+    1073                 :            : 
+    1074                 :            : static const mbedtls_cipher_info_t camellia_256_gcm_info = {
+    1075                 :            :     "CAMELLIA-256-GCM",
+    1076                 :            :     16,
+    1077                 :            :     12 >> MBEDTLS_IV_SIZE_SHIFT,
+    1078                 :            :     256 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    1079                 :            :     MBEDTLS_MODE_GCM,
+    1080                 :            :     MBEDTLS_CIPHER_CAMELLIA_256_GCM,
+    1081                 :            :     MBEDTLS_CIPHER_VARIABLE_IV_LEN,
+    1082                 :            :     MBEDTLS_CIPHER_BASE_INDEX_GCM_CAMELLIA
+    1083                 :            : };
+    1084                 :            : #endif /* MBEDTLS_GCM_C */
+    1085                 :            : 
+    1086                 :            : #if defined(MBEDTLS_CCM_C)
+    1087                 :          0 : static int ccm_camellia_setkey_wrap(void *ctx, const unsigned char *key,
+    1088                 :            :                                     unsigned int key_bitlen)
+    1089                 :            : {
+    1090                 :          0 :     return mbedtls_ccm_setkey((mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
+    1091                 :            :                               key, key_bitlen);
+    1092                 :            : }
+    1093                 :            : 
+    1094                 :            : static const mbedtls_cipher_base_t ccm_camellia_info = {
+    1095                 :            :     MBEDTLS_CIPHER_ID_CAMELLIA,
+    1096                 :            :     NULL,
+    1097                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+    1098                 :            :     NULL,
+    1099                 :            : #endif
+    1100                 :            : #if defined(MBEDTLS_CIPHER_MODE_CFB)
+    1101                 :            :     NULL,
+    1102                 :            : #endif
+    1103                 :            : #if defined(MBEDTLS_CIPHER_MODE_OFB)
+    1104                 :            :     NULL,
+    1105                 :            : #endif
+    1106                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR)
+    1107                 :            :     NULL,
+    1108                 :            : #endif
+    1109                 :            : #if defined(MBEDTLS_CIPHER_MODE_XTS)
+    1110                 :            :     NULL,
+    1111                 :            : #endif
+    1112                 :            : #if defined(MBEDTLS_CIPHER_MODE_STREAM)
+    1113                 :            :     NULL,
+    1114                 :            : #endif
+    1115                 :            :     ccm_camellia_setkey_wrap,
+    1116                 :            : #if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
+    1117                 :            :     ccm_camellia_setkey_wrap,
+    1118                 :            : #endif
+    1119                 :            :     ccm_ctx_alloc,
+    1120                 :            :     ccm_ctx_free,
+    1121                 :            : };
+    1122                 :            : 
+    1123                 :            : static const mbedtls_cipher_info_t camellia_128_ccm_info = {
+    1124                 :            :     "CAMELLIA-128-CCM",
+    1125                 :            :     16,
+    1126                 :            :     12 >> MBEDTLS_IV_SIZE_SHIFT,
+    1127                 :            :     128 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    1128                 :            :     MBEDTLS_MODE_CCM,
+    1129                 :            :     MBEDTLS_CIPHER_CAMELLIA_128_CCM,
+    1130                 :            :     MBEDTLS_CIPHER_VARIABLE_IV_LEN,
+    1131                 :            :     MBEDTLS_CIPHER_BASE_INDEX_CCM_CAMELLIA
+    1132                 :            : };
+    1133                 :            : 
+    1134                 :            : static const mbedtls_cipher_info_t camellia_192_ccm_info = {
+    1135                 :            :     "CAMELLIA-192-CCM",
+    1136                 :            :     16,
+    1137                 :            :     12 >> MBEDTLS_IV_SIZE_SHIFT,
+    1138                 :            :     192 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    1139                 :            :     MBEDTLS_MODE_CCM,
+    1140                 :            :     MBEDTLS_CIPHER_CAMELLIA_192_CCM,
+    1141                 :            :     MBEDTLS_CIPHER_VARIABLE_IV_LEN,
+    1142                 :            :     MBEDTLS_CIPHER_BASE_INDEX_CCM_CAMELLIA
+    1143                 :            : };
+    1144                 :            : 
+    1145                 :            : static const mbedtls_cipher_info_t camellia_256_ccm_info = {
+    1146                 :            :     "CAMELLIA-256-CCM",
+    1147                 :            :     16,
+    1148                 :            :     12 >> MBEDTLS_IV_SIZE_SHIFT,
+    1149                 :            :     256 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    1150                 :            :     MBEDTLS_MODE_CCM,
+    1151                 :            :     MBEDTLS_CIPHER_CAMELLIA_256_CCM,
+    1152                 :            :     MBEDTLS_CIPHER_VARIABLE_IV_LEN,
+    1153                 :            :     MBEDTLS_CIPHER_BASE_INDEX_CCM_CAMELLIA
+    1154                 :            : };
+    1155                 :            : 
+    1156                 :            : static const mbedtls_cipher_info_t camellia_128_ccm_star_no_tag_info = {
+    1157                 :            :     "CAMELLIA-128-CCM*-NO-TAG",
+    1158                 :            :     16,
+    1159                 :            :     12 >> MBEDTLS_IV_SIZE_SHIFT,
+    1160                 :            :     128 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    1161                 :            :     MBEDTLS_MODE_CCM_STAR_NO_TAG,
+    1162                 :            :     MBEDTLS_CIPHER_CAMELLIA_128_CCM_STAR_NO_TAG,
+    1163                 :            :     MBEDTLS_CIPHER_VARIABLE_IV_LEN,
+    1164                 :            :     MBEDTLS_CIPHER_BASE_INDEX_CCM_CAMELLIA
+    1165                 :            : };
+    1166                 :            : 
+    1167                 :            : static const mbedtls_cipher_info_t camellia_192_ccm_star_no_tag_info = {
+    1168                 :            :     "CAMELLIA-192-CCM*-NO-TAG",
+    1169                 :            :     16,
+    1170                 :            :     12 >> MBEDTLS_IV_SIZE_SHIFT,
+    1171                 :            :     192 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    1172                 :            :     MBEDTLS_MODE_CCM_STAR_NO_TAG,
+    1173                 :            :     MBEDTLS_CIPHER_CAMELLIA_192_CCM_STAR_NO_TAG,
+    1174                 :            :     MBEDTLS_CIPHER_VARIABLE_IV_LEN,
+    1175                 :            :     MBEDTLS_CIPHER_BASE_INDEX_CCM_CAMELLIA
+    1176                 :            : };
+    1177                 :            : 
+    1178                 :            : static const mbedtls_cipher_info_t camellia_256_ccm_star_no_tag_info = {
+    1179                 :            :     "CAMELLIA-256-CCM*-NO-TAG",
+    1180                 :            :     16,
+    1181                 :            :     12 >> MBEDTLS_IV_SIZE_SHIFT,
+    1182                 :            :     256 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    1183                 :            :     MBEDTLS_MODE_CCM_STAR_NO_TAG,
+    1184                 :            :     MBEDTLS_CIPHER_CAMELLIA_256_CCM_STAR_NO_TAG,
+    1185                 :            :     MBEDTLS_CIPHER_VARIABLE_IV_LEN,
+    1186                 :            :     MBEDTLS_CIPHER_BASE_INDEX_CCM_CAMELLIA
+    1187                 :            : };
+    1188                 :            : #endif /* MBEDTLS_CCM_C */
+    1189                 :            : 
+    1190                 :            : #endif /* MBEDTLS_CAMELLIA_C */
+    1191                 :            : 
+    1192                 :            : #if defined(MBEDTLS_ARIA_C)
+    1193                 :            : 
+    1194                 :          0 : static int aria_crypt_ecb_wrap(void *ctx, mbedtls_operation_t operation,
+    1195                 :            :                                const unsigned char *input, unsigned char *output)
+    1196                 :            : {
+    1197                 :            :     (void) operation;
+    1198                 :          0 :     return mbedtls_aria_crypt_ecb((mbedtls_aria_context *) ctx, input,
+    1199                 :            :                                   output);
+    1200                 :            : }
+    1201                 :            : 
+    1202                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+    1203                 :          0 : static int aria_crypt_cbc_wrap(void *ctx, mbedtls_operation_t operation,
+    1204                 :            :                                size_t length, unsigned char *iv,
+    1205                 :            :                                const unsigned char *input, unsigned char *output)
+    1206                 :            : {
+    1207                 :          0 :     return mbedtls_aria_crypt_cbc((mbedtls_aria_context *) ctx, operation, length, iv,
+    1208                 :            :                                   input, output);
+    1209                 :            : }
+    1210                 :            : #endif /* MBEDTLS_CIPHER_MODE_CBC */
+    1211                 :            : 
+    1212                 :            : #if defined(MBEDTLS_CIPHER_MODE_CFB)
+    1213                 :          0 : static int aria_crypt_cfb128_wrap(void *ctx, mbedtls_operation_t operation,
+    1214                 :            :                                   size_t length, size_t *iv_off, unsigned char *iv,
+    1215                 :            :                                   const unsigned char *input, unsigned char *output)
+    1216                 :            : {
+    1217                 :          0 :     return mbedtls_aria_crypt_cfb128((mbedtls_aria_context *) ctx, operation, length,
+    1218                 :            :                                      iv_off, iv, input, output);
+    1219                 :            : }
+    1220                 :            : #endif /* MBEDTLS_CIPHER_MODE_CFB */
+    1221                 :            : 
+    1222                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR)
+    1223                 :          0 : static int aria_crypt_ctr_wrap(void *ctx, size_t length, size_t *nc_off,
+    1224                 :            :                                unsigned char *nonce_counter, unsigned char *stream_block,
+    1225                 :            :                                const unsigned char *input, unsigned char *output)
+    1226                 :            : {
+    1227                 :          0 :     return mbedtls_aria_crypt_ctr((mbedtls_aria_context *) ctx, length, nc_off,
+    1228                 :            :                                   nonce_counter, stream_block, input, output);
+    1229                 :            : }
+    1230                 :            : #endif /* MBEDTLS_CIPHER_MODE_CTR */
+    1231                 :            : 
+    1232                 :            : #if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
+    1233                 :          0 : static int aria_setkey_dec_wrap(void *ctx, const unsigned char *key,
+    1234                 :            :                                 unsigned int key_bitlen)
+    1235                 :            : {
+    1236                 :          0 :     return mbedtls_aria_setkey_dec((mbedtls_aria_context *) ctx, key, key_bitlen);
+    1237                 :            : }
+    1238                 :            : #endif
+    1239                 :            : 
+    1240                 :          0 : static int aria_setkey_enc_wrap(void *ctx, const unsigned char *key,
+    1241                 :            :                                 unsigned int key_bitlen)
+    1242                 :            : {
+    1243                 :          0 :     return mbedtls_aria_setkey_enc((mbedtls_aria_context *) ctx, key, key_bitlen);
+    1244                 :            : }
+    1245                 :            : 
+    1246                 :          0 : static void *aria_ctx_alloc(void)
+    1247                 :            : {
+    1248                 :            :     mbedtls_aria_context *ctx;
+    1249                 :          0 :     ctx = mbedtls_calloc(1, sizeof(mbedtls_aria_context));
+    1250                 :            : 
+    1251         [ #  # ]:          0 :     if (ctx == NULL) {
+    1252                 :          0 :         return NULL;
+    1253                 :            :     }
+    1254                 :            : 
+    1255                 :          0 :     mbedtls_aria_init(ctx);
+    1256                 :            : 
+    1257                 :          0 :     return ctx;
+    1258                 :            : }
+    1259                 :            : 
+    1260                 :          0 : static void aria_ctx_free(void *ctx)
+    1261                 :            : {
+    1262                 :          0 :     mbedtls_aria_free((mbedtls_aria_context *) ctx);
+    1263                 :          0 :     mbedtls_free(ctx);
+    1264                 :          0 : }
+    1265                 :            : 
+    1266                 :            : static const mbedtls_cipher_base_t aria_info = {
+    1267                 :            :     MBEDTLS_CIPHER_ID_ARIA,
+    1268                 :            :     aria_crypt_ecb_wrap,
+    1269                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+    1270                 :            :     aria_crypt_cbc_wrap,
+    1271                 :            : #endif
+    1272                 :            : #if defined(MBEDTLS_CIPHER_MODE_CFB)
+    1273                 :            :     aria_crypt_cfb128_wrap,
+    1274                 :            : #endif
+    1275                 :            : #if defined(MBEDTLS_CIPHER_MODE_OFB)
+    1276                 :            :     NULL,
+    1277                 :            : #endif
+    1278                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR)
+    1279                 :            :     aria_crypt_ctr_wrap,
+    1280                 :            : #endif
+    1281                 :            : #if defined(MBEDTLS_CIPHER_MODE_XTS)
+    1282                 :            :     NULL,
+    1283                 :            : #endif
+    1284                 :            : #if defined(MBEDTLS_CIPHER_MODE_STREAM)
+    1285                 :            :     NULL,
+    1286                 :            : #endif
+    1287                 :            :     aria_setkey_enc_wrap,
+    1288                 :            : #if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
+    1289                 :            :     aria_setkey_dec_wrap,
+    1290                 :            : #endif
+    1291                 :            :     aria_ctx_alloc,
+    1292                 :            :     aria_ctx_free
+    1293                 :            : };
+    1294                 :            : 
+    1295                 :            : static const mbedtls_cipher_info_t aria_128_ecb_info = {
+    1296                 :            :     "ARIA-128-ECB",
+    1297                 :            :     16,
+    1298                 :            :     0 >> MBEDTLS_IV_SIZE_SHIFT,
+    1299                 :            :     128 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    1300                 :            :     MBEDTLS_MODE_ECB,
+    1301                 :            :     MBEDTLS_CIPHER_ARIA_128_ECB,
+    1302                 :            :     0,
+    1303                 :            :     MBEDTLS_CIPHER_BASE_INDEX_ARIA
+    1304                 :            : };
+    1305                 :            : 
+    1306                 :            : static const mbedtls_cipher_info_t aria_192_ecb_info = {
+    1307                 :            :     "ARIA-192-ECB",
+    1308                 :            :     16,
+    1309                 :            :     0 >> MBEDTLS_IV_SIZE_SHIFT,
+    1310                 :            :     192 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    1311                 :            :     MBEDTLS_MODE_ECB,
+    1312                 :            :     MBEDTLS_CIPHER_ARIA_192_ECB,
+    1313                 :            :     0,
+    1314                 :            :     MBEDTLS_CIPHER_BASE_INDEX_ARIA
+    1315                 :            : };
+    1316                 :            : 
+    1317                 :            : static const mbedtls_cipher_info_t aria_256_ecb_info = {
+    1318                 :            :     "ARIA-256-ECB",
+    1319                 :            :     16,
+    1320                 :            :     0 >> MBEDTLS_IV_SIZE_SHIFT,
+    1321                 :            :     256 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    1322                 :            :     MBEDTLS_MODE_ECB,
+    1323                 :            :     MBEDTLS_CIPHER_ARIA_256_ECB,
+    1324                 :            :     0,
+    1325                 :            :     MBEDTLS_CIPHER_BASE_INDEX_ARIA
+    1326                 :            : };
+    1327                 :            : 
+    1328                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+    1329                 :            : static const mbedtls_cipher_info_t aria_128_cbc_info = {
+    1330                 :            :     "ARIA-128-CBC",
+    1331                 :            :     16,
+    1332                 :            :     16 >> MBEDTLS_IV_SIZE_SHIFT,
+    1333                 :            :     128 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    1334                 :            :     MBEDTLS_MODE_CBC,
+    1335                 :            :     MBEDTLS_CIPHER_ARIA_128_CBC,
+    1336                 :            :     0,
+    1337                 :            :     MBEDTLS_CIPHER_BASE_INDEX_ARIA
+    1338                 :            : };
+    1339                 :            : 
+    1340                 :            : static const mbedtls_cipher_info_t aria_192_cbc_info = {
+    1341                 :            :     "ARIA-192-CBC",
+    1342                 :            :     16,
+    1343                 :            :     16 >> MBEDTLS_IV_SIZE_SHIFT,
+    1344                 :            :     192 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    1345                 :            :     MBEDTLS_MODE_CBC,
+    1346                 :            :     MBEDTLS_CIPHER_ARIA_192_CBC,
+    1347                 :            :     0,
+    1348                 :            :     MBEDTLS_CIPHER_BASE_INDEX_ARIA
+    1349                 :            : };
+    1350                 :            : 
+    1351                 :            : static const mbedtls_cipher_info_t aria_256_cbc_info = {
+    1352                 :            :     "ARIA-256-CBC",
+    1353                 :            :     16,
+    1354                 :            :     16 >> MBEDTLS_IV_SIZE_SHIFT,
+    1355                 :            :     256 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    1356                 :            :     MBEDTLS_MODE_CBC,
+    1357                 :            :     MBEDTLS_CIPHER_ARIA_256_CBC,
+    1358                 :            :     0,
+    1359                 :            :     MBEDTLS_CIPHER_BASE_INDEX_ARIA
+    1360                 :            : };
+    1361                 :            : #endif /* MBEDTLS_CIPHER_MODE_CBC */
+    1362                 :            : 
+    1363                 :            : #if defined(MBEDTLS_CIPHER_MODE_CFB)
+    1364                 :            : static const mbedtls_cipher_info_t aria_128_cfb128_info = {
+    1365                 :            :     "ARIA-128-CFB128",
+    1366                 :            :     16,
+    1367                 :            :     16 >> MBEDTLS_IV_SIZE_SHIFT,
+    1368                 :            :     128 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    1369                 :            :     MBEDTLS_MODE_CFB,
+    1370                 :            :     MBEDTLS_CIPHER_ARIA_128_CFB128,
+    1371                 :            :     0,
+    1372                 :            :     MBEDTLS_CIPHER_BASE_INDEX_ARIA
+    1373                 :            : };
+    1374                 :            : 
+    1375                 :            : static const mbedtls_cipher_info_t aria_192_cfb128_info = {
+    1376                 :            :     "ARIA-192-CFB128",
+    1377                 :            :     16,
+    1378                 :            :     16 >> MBEDTLS_IV_SIZE_SHIFT,
+    1379                 :            :     192 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    1380                 :            :     MBEDTLS_MODE_CFB,
+    1381                 :            :     MBEDTLS_CIPHER_ARIA_192_CFB128,
+    1382                 :            :     0,
+    1383                 :            :     MBEDTLS_CIPHER_BASE_INDEX_ARIA
+    1384                 :            : };
+    1385                 :            : 
+    1386                 :            : static const mbedtls_cipher_info_t aria_256_cfb128_info = {
+    1387                 :            :     "ARIA-256-CFB128",
+    1388                 :            :     16,
+    1389                 :            :     16 >> MBEDTLS_IV_SIZE_SHIFT,
+    1390                 :            :     256 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    1391                 :            :     MBEDTLS_MODE_CFB,
+    1392                 :            :     MBEDTLS_CIPHER_ARIA_256_CFB128,
+    1393                 :            :     0,
+    1394                 :            :     MBEDTLS_CIPHER_BASE_INDEX_ARIA
+    1395                 :            : };
+    1396                 :            : #endif /* MBEDTLS_CIPHER_MODE_CFB */
+    1397                 :            : 
+    1398                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR)
+    1399                 :            : static const mbedtls_cipher_info_t aria_128_ctr_info = {
+    1400                 :            :     "ARIA-128-CTR",
+    1401                 :            :     16,
+    1402                 :            :     16 >> MBEDTLS_IV_SIZE_SHIFT,
+    1403                 :            :     128 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    1404                 :            :     MBEDTLS_MODE_CTR,
+    1405                 :            :     MBEDTLS_CIPHER_ARIA_128_CTR,
+    1406                 :            :     0,
+    1407                 :            :     MBEDTLS_CIPHER_BASE_INDEX_ARIA
+    1408                 :            : };
+    1409                 :            : 
+    1410                 :            : static const mbedtls_cipher_info_t aria_192_ctr_info = {
+    1411                 :            :     "ARIA-192-CTR",
+    1412                 :            :     16,
+    1413                 :            :     16 >> MBEDTLS_IV_SIZE_SHIFT,
+    1414                 :            :     192 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    1415                 :            :     MBEDTLS_MODE_CTR,
+    1416                 :            :     MBEDTLS_CIPHER_ARIA_192_CTR,
+    1417                 :            :     0,
+    1418                 :            :     MBEDTLS_CIPHER_BASE_INDEX_ARIA
+    1419                 :            : };
+    1420                 :            : 
+    1421                 :            : static const mbedtls_cipher_info_t aria_256_ctr_info = {
+    1422                 :            :     "ARIA-256-CTR",
+    1423                 :            :     16,
+    1424                 :            :     16 >> MBEDTLS_IV_SIZE_SHIFT,
+    1425                 :            :     256 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    1426                 :            :     MBEDTLS_MODE_CTR,
+    1427                 :            :     MBEDTLS_CIPHER_ARIA_256_CTR,
+    1428                 :            :     0,
+    1429                 :            :     MBEDTLS_CIPHER_BASE_INDEX_ARIA
+    1430                 :            : };
+    1431                 :            : #endif /* MBEDTLS_CIPHER_MODE_CTR */
+    1432                 :            : 
+    1433                 :            : #if defined(MBEDTLS_GCM_C)
+    1434                 :          0 : static int gcm_aria_setkey_wrap(void *ctx, const unsigned char *key,
+    1435                 :            :                                 unsigned int key_bitlen)
+    1436                 :            : {
+    1437                 :          0 :     return mbedtls_gcm_setkey((mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
+    1438                 :            :                               key, key_bitlen);
+    1439                 :            : }
+    1440                 :            : 
+    1441                 :            : static const mbedtls_cipher_base_t gcm_aria_info = {
+    1442                 :            :     MBEDTLS_CIPHER_ID_ARIA,
+    1443                 :            :     NULL,
+    1444                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+    1445                 :            :     NULL,
+    1446                 :            : #endif
+    1447                 :            : #if defined(MBEDTLS_CIPHER_MODE_CFB)
+    1448                 :            :     NULL,
+    1449                 :            : #endif
+    1450                 :            : #if defined(MBEDTLS_CIPHER_MODE_OFB)
+    1451                 :            :     NULL,
+    1452                 :            : #endif
+    1453                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR)
+    1454                 :            :     NULL,
+    1455                 :            : #endif
+    1456                 :            : #if defined(MBEDTLS_CIPHER_MODE_XTS)
+    1457                 :            :     NULL,
+    1458                 :            : #endif
+    1459                 :            : #if defined(MBEDTLS_CIPHER_MODE_STREAM)
+    1460                 :            :     NULL,
+    1461                 :            : #endif
+    1462                 :            :     gcm_aria_setkey_wrap,
+    1463                 :            : #if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
+    1464                 :            :     gcm_aria_setkey_wrap,
+    1465                 :            : #endif
+    1466                 :            :     gcm_ctx_alloc,
+    1467                 :            :     gcm_ctx_free,
+    1468                 :            : };
+    1469                 :            : 
+    1470                 :            : static const mbedtls_cipher_info_t aria_128_gcm_info = {
+    1471                 :            :     "ARIA-128-GCM",
+    1472                 :            :     16,
+    1473                 :            :     12 >> MBEDTLS_IV_SIZE_SHIFT,
+    1474                 :            :     128 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    1475                 :            :     MBEDTLS_MODE_GCM,
+    1476                 :            :     MBEDTLS_CIPHER_ARIA_128_GCM,
+    1477                 :            :     MBEDTLS_CIPHER_VARIABLE_IV_LEN,
+    1478                 :            :     MBEDTLS_CIPHER_BASE_INDEX_GCM_ARIA
+    1479                 :            : };
+    1480                 :            : 
+    1481                 :            : static const mbedtls_cipher_info_t aria_192_gcm_info = {
+    1482                 :            :     "ARIA-192-GCM",
+    1483                 :            :     16,
+    1484                 :            :     12 >> MBEDTLS_IV_SIZE_SHIFT,
+    1485                 :            :     192 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    1486                 :            :     MBEDTLS_MODE_GCM,
+    1487                 :            :     MBEDTLS_CIPHER_ARIA_192_GCM,
+    1488                 :            :     MBEDTLS_CIPHER_VARIABLE_IV_LEN,
+    1489                 :            :     MBEDTLS_CIPHER_BASE_INDEX_GCM_ARIA
+    1490                 :            : };
+    1491                 :            : 
+    1492                 :            : static const mbedtls_cipher_info_t aria_256_gcm_info = {
+    1493                 :            :     "ARIA-256-GCM",
+    1494                 :            :     16,
+    1495                 :            :     12 >> MBEDTLS_IV_SIZE_SHIFT,
+    1496                 :            :     256 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    1497                 :            :     MBEDTLS_MODE_GCM,
+    1498                 :            :     MBEDTLS_CIPHER_ARIA_256_GCM,
+    1499                 :            :     MBEDTLS_CIPHER_VARIABLE_IV_LEN,
+    1500                 :            :     MBEDTLS_CIPHER_BASE_INDEX_GCM_ARIA
+    1501                 :            : };
+    1502                 :            : #endif /* MBEDTLS_GCM_C */
+    1503                 :            : 
+    1504                 :            : #if defined(MBEDTLS_CCM_C)
+    1505                 :          0 : static int ccm_aria_setkey_wrap(void *ctx, const unsigned char *key,
+    1506                 :            :                                 unsigned int key_bitlen)
+    1507                 :            : {
+    1508                 :          0 :     return mbedtls_ccm_setkey((mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
+    1509                 :            :                               key, key_bitlen);
+    1510                 :            : }
+    1511                 :            : 
+    1512                 :            : static const mbedtls_cipher_base_t ccm_aria_info = {
+    1513                 :            :     MBEDTLS_CIPHER_ID_ARIA,
+    1514                 :            :     NULL,
+    1515                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+    1516                 :            :     NULL,
+    1517                 :            : #endif
+    1518                 :            : #if defined(MBEDTLS_CIPHER_MODE_CFB)
+    1519                 :            :     NULL,
+    1520                 :            : #endif
+    1521                 :            : #if defined(MBEDTLS_CIPHER_MODE_OFB)
+    1522                 :            :     NULL,
+    1523                 :            : #endif
+    1524                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR)
+    1525                 :            :     NULL,
+    1526                 :            : #endif
+    1527                 :            : #if defined(MBEDTLS_CIPHER_MODE_XTS)
+    1528                 :            :     NULL,
+    1529                 :            : #endif
+    1530                 :            : #if defined(MBEDTLS_CIPHER_MODE_STREAM)
+    1531                 :            :     NULL,
+    1532                 :            : #endif
+    1533                 :            :     ccm_aria_setkey_wrap,
+    1534                 :            : #if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
+    1535                 :            :     ccm_aria_setkey_wrap,
+    1536                 :            : #endif
+    1537                 :            :     ccm_ctx_alloc,
+    1538                 :            :     ccm_ctx_free,
+    1539                 :            : };
+    1540                 :            : 
+    1541                 :            : static const mbedtls_cipher_info_t aria_128_ccm_info = {
+    1542                 :            :     "ARIA-128-CCM",
+    1543                 :            :     16,
+    1544                 :            :     12 >> MBEDTLS_IV_SIZE_SHIFT,
+    1545                 :            :     128 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    1546                 :            :     MBEDTLS_MODE_CCM,
+    1547                 :            :     MBEDTLS_CIPHER_ARIA_128_CCM,
+    1548                 :            :     MBEDTLS_CIPHER_VARIABLE_IV_LEN,
+    1549                 :            :     MBEDTLS_CIPHER_BASE_INDEX_CCM_ARIA
+    1550                 :            : };
+    1551                 :            : 
+    1552                 :            : static const mbedtls_cipher_info_t aria_192_ccm_info = {
+    1553                 :            :     "ARIA-192-CCM",
+    1554                 :            :     16,
+    1555                 :            :     12 >> MBEDTLS_IV_SIZE_SHIFT,
+    1556                 :            :     192 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    1557                 :            :     MBEDTLS_MODE_CCM,
+    1558                 :            :     MBEDTLS_CIPHER_ARIA_192_CCM,
+    1559                 :            :     MBEDTLS_CIPHER_VARIABLE_IV_LEN,
+    1560                 :            :     MBEDTLS_CIPHER_BASE_INDEX_CCM_ARIA
+    1561                 :            : };
+    1562                 :            : 
+    1563                 :            : static const mbedtls_cipher_info_t aria_256_ccm_info = {
+    1564                 :            :     "ARIA-256-CCM",
+    1565                 :            :     16,
+    1566                 :            :     12 >> MBEDTLS_IV_SIZE_SHIFT,
+    1567                 :            :     256 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    1568                 :            :     MBEDTLS_MODE_CCM,
+    1569                 :            :     MBEDTLS_CIPHER_ARIA_256_CCM,
+    1570                 :            :     MBEDTLS_CIPHER_VARIABLE_IV_LEN,
+    1571                 :            :     MBEDTLS_CIPHER_BASE_INDEX_CCM_ARIA
+    1572                 :            : };
+    1573                 :            : 
+    1574                 :            : static const mbedtls_cipher_info_t aria_128_ccm_star_no_tag_info = {
+    1575                 :            :     "ARIA-128-CCM*-NO-TAG",
+    1576                 :            :     16,
+    1577                 :            :     12 >> MBEDTLS_IV_SIZE_SHIFT,
+    1578                 :            :     128 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    1579                 :            :     MBEDTLS_MODE_CCM_STAR_NO_TAG,
+    1580                 :            :     MBEDTLS_CIPHER_ARIA_128_CCM_STAR_NO_TAG,
+    1581                 :            :     MBEDTLS_CIPHER_VARIABLE_IV_LEN,
+    1582                 :            :     MBEDTLS_CIPHER_BASE_INDEX_CCM_ARIA
+    1583                 :            : };
+    1584                 :            : 
+    1585                 :            : static const mbedtls_cipher_info_t aria_192_ccm_star_no_tag_info = {
+    1586                 :            :     "ARIA-192-CCM*-NO-TAG",
+    1587                 :            :     16,
+    1588                 :            :     12 >> MBEDTLS_IV_SIZE_SHIFT,
+    1589                 :            :     192 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    1590                 :            :     MBEDTLS_MODE_CCM_STAR_NO_TAG,
+    1591                 :            :     MBEDTLS_CIPHER_ARIA_192_CCM_STAR_NO_TAG,
+    1592                 :            :     MBEDTLS_CIPHER_VARIABLE_IV_LEN,
+    1593                 :            :     MBEDTLS_CIPHER_BASE_INDEX_CCM_ARIA
+    1594                 :            : };
+    1595                 :            : 
+    1596                 :            : static const mbedtls_cipher_info_t aria_256_ccm_star_no_tag_info = {
+    1597                 :            :     "ARIA-256-CCM*-NO-TAG",
+    1598                 :            :     16,
+    1599                 :            :     12 >> MBEDTLS_IV_SIZE_SHIFT,
+    1600                 :            :     256 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    1601                 :            :     MBEDTLS_MODE_CCM_STAR_NO_TAG,
+    1602                 :            :     MBEDTLS_CIPHER_ARIA_256_CCM_STAR_NO_TAG,
+    1603                 :            :     MBEDTLS_CIPHER_VARIABLE_IV_LEN,
+    1604                 :            :     MBEDTLS_CIPHER_BASE_INDEX_CCM_ARIA
+    1605                 :            : };
+    1606                 :            : #endif /* MBEDTLS_CCM_C */
+    1607                 :            : 
+    1608                 :            : #endif /* MBEDTLS_ARIA_C */
+    1609                 :            : 
+    1610                 :            : #if defined(MBEDTLS_DES_C)
+    1611                 :            : 
+    1612                 :          0 : static int des_crypt_ecb_wrap(void *ctx, mbedtls_operation_t operation,
+    1613                 :            :                               const unsigned char *input, unsigned char *output)
+    1614                 :            : {
+    1615                 :            :     ((void) operation);
+    1616                 :          0 :     return mbedtls_des_crypt_ecb((mbedtls_des_context *) ctx, input, output);
+    1617                 :            : }
+    1618                 :            : 
+    1619                 :          0 : static int des3_crypt_ecb_wrap(void *ctx, mbedtls_operation_t operation,
+    1620                 :            :                                const unsigned char *input, unsigned char *output)
+    1621                 :            : {
+    1622                 :            :     ((void) operation);
+    1623                 :          0 :     return mbedtls_des3_crypt_ecb((mbedtls_des3_context *) ctx, input, output);
+    1624                 :            : }
+    1625                 :            : 
+    1626                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+    1627                 :          0 : static int des_crypt_cbc_wrap(void *ctx, mbedtls_operation_t operation, size_t length,
+    1628                 :            :                               unsigned char *iv, const unsigned char *input, unsigned char *output)
+    1629                 :            : {
+    1630                 :          0 :     return mbedtls_des_crypt_cbc((mbedtls_des_context *) ctx, operation, length, iv, input,
+    1631                 :            :                                  output);
+    1632                 :            : }
+    1633                 :            : #endif /* MBEDTLS_CIPHER_MODE_CBC */
+    1634                 :            : 
+    1635                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+    1636                 :          0 : static int des3_crypt_cbc_wrap(void *ctx, mbedtls_operation_t operation, size_t length,
+    1637                 :            :                                unsigned char *iv, const unsigned char *input, unsigned char *output)
+    1638                 :            : {
+    1639                 :          0 :     return mbedtls_des3_crypt_cbc((mbedtls_des3_context *) ctx, operation, length, iv, input,
+    1640                 :            :                                   output);
+    1641                 :            : }
+    1642                 :            : #endif /* MBEDTLS_CIPHER_MODE_CBC */
+    1643                 :            : 
+    1644                 :          0 : static int des_setkey_dec_wrap(void *ctx, const unsigned char *key,
+    1645                 :            :                                unsigned int key_bitlen)
+    1646                 :            : {
+    1647                 :            :     ((void) key_bitlen);
+    1648                 :            : 
+    1649                 :          0 :     return mbedtls_des_setkey_dec((mbedtls_des_context *) ctx, key);
+    1650                 :            : }
+    1651                 :            : 
+    1652                 :          0 : static int des_setkey_enc_wrap(void *ctx, const unsigned char *key,
+    1653                 :            :                                unsigned int key_bitlen)
+    1654                 :            : {
+    1655                 :            :     ((void) key_bitlen);
+    1656                 :            : 
+    1657                 :          0 :     return mbedtls_des_setkey_enc((mbedtls_des_context *) ctx, key);
+    1658                 :            : }
+    1659                 :            : 
+    1660                 :          0 : static int des3_set2key_dec_wrap(void *ctx, const unsigned char *key,
+    1661                 :            :                                  unsigned int key_bitlen)
+    1662                 :            : {
+    1663                 :            :     ((void) key_bitlen);
+    1664                 :            : 
+    1665                 :          0 :     return mbedtls_des3_set2key_dec((mbedtls_des3_context *) ctx, key);
+    1666                 :            : }
+    1667                 :            : 
+    1668                 :          0 : static int des3_set2key_enc_wrap(void *ctx, const unsigned char *key,
+    1669                 :            :                                  unsigned int key_bitlen)
+    1670                 :            : {
+    1671                 :            :     ((void) key_bitlen);
+    1672                 :            : 
+    1673                 :          0 :     return mbedtls_des3_set2key_enc((mbedtls_des3_context *) ctx, key);
+    1674                 :            : }
+    1675                 :            : 
+    1676                 :          0 : static int des3_set3key_dec_wrap(void *ctx, const unsigned char *key,
+    1677                 :            :                                  unsigned int key_bitlen)
+    1678                 :            : {
+    1679                 :            :     ((void) key_bitlen);
+    1680                 :            : 
+    1681                 :          0 :     return mbedtls_des3_set3key_dec((mbedtls_des3_context *) ctx, key);
+    1682                 :            : }
+    1683                 :            : 
+    1684                 :          0 : static int des3_set3key_enc_wrap(void *ctx, const unsigned char *key,
+    1685                 :            :                                  unsigned int key_bitlen)
+    1686                 :            : {
+    1687                 :            :     ((void) key_bitlen);
+    1688                 :            : 
+    1689                 :          0 :     return mbedtls_des3_set3key_enc((mbedtls_des3_context *) ctx, key);
+    1690                 :            : }
+    1691                 :            : 
+    1692                 :          0 : static void *des_ctx_alloc(void)
+    1693                 :            : {
+    1694                 :          0 :     mbedtls_des_context *des = mbedtls_calloc(1, sizeof(mbedtls_des_context));
+    1695                 :            : 
+    1696         [ #  # ]:          0 :     if (des == NULL) {
+    1697                 :          0 :         return NULL;
+    1698                 :            :     }
+    1699                 :            : 
+    1700                 :          0 :     mbedtls_des_init(des);
+    1701                 :            : 
+    1702                 :          0 :     return des;
+    1703                 :            : }
+    1704                 :            : 
+    1705                 :          0 : static void des_ctx_free(void *ctx)
+    1706                 :            : {
+    1707                 :          0 :     mbedtls_des_free((mbedtls_des_context *) ctx);
+    1708                 :          0 :     mbedtls_free(ctx);
+    1709                 :          0 : }
+    1710                 :            : 
+    1711                 :          0 : static void *des3_ctx_alloc(void)
+    1712                 :            : {
+    1713                 :            :     mbedtls_des3_context *des3;
+    1714                 :          0 :     des3 = mbedtls_calloc(1, sizeof(mbedtls_des3_context));
+    1715                 :            : 
+    1716         [ #  # ]:          0 :     if (des3 == NULL) {
+    1717                 :          0 :         return NULL;
+    1718                 :            :     }
+    1719                 :            : 
+    1720                 :          0 :     mbedtls_des3_init(des3);
+    1721                 :            : 
+    1722                 :          0 :     return des3;
+    1723                 :            : }
+    1724                 :            : 
+    1725                 :          0 : static void des3_ctx_free(void *ctx)
+    1726                 :            : {
+    1727                 :          0 :     mbedtls_des3_free((mbedtls_des3_context *) ctx);
+    1728                 :          0 :     mbedtls_free(ctx);
+    1729                 :          0 : }
+    1730                 :            : 
+    1731                 :            : static const mbedtls_cipher_base_t des_info = {
+    1732                 :            :     MBEDTLS_CIPHER_ID_DES,
+    1733                 :            :     des_crypt_ecb_wrap,
+    1734                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+    1735                 :            :     des_crypt_cbc_wrap,
+    1736                 :            : #endif
+    1737                 :            : #if defined(MBEDTLS_CIPHER_MODE_CFB)
+    1738                 :            :     NULL,
+    1739                 :            : #endif
+    1740                 :            : #if defined(MBEDTLS_CIPHER_MODE_OFB)
+    1741                 :            :     NULL,
+    1742                 :            : #endif
+    1743                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR)
+    1744                 :            :     NULL,
+    1745                 :            : #endif
+    1746                 :            : #if defined(MBEDTLS_CIPHER_MODE_XTS)
+    1747                 :            :     NULL,
+    1748                 :            : #endif
+    1749                 :            : #if defined(MBEDTLS_CIPHER_MODE_STREAM)
+    1750                 :            :     NULL,
+    1751                 :            : #endif
+    1752                 :            :     des_setkey_enc_wrap,
+    1753                 :            :     des_setkey_dec_wrap,
+    1754                 :            :     des_ctx_alloc,
+    1755                 :            :     des_ctx_free
+    1756                 :            : };
+    1757                 :            : 
+    1758                 :            : static const mbedtls_cipher_info_t des_ecb_info = {
+    1759                 :            :     "DES-ECB",
+    1760                 :            :     8,
+    1761                 :            :     0 >> MBEDTLS_IV_SIZE_SHIFT,
+    1762                 :            :     MBEDTLS_KEY_LENGTH_DES >> MBEDTLS_KEY_BITLEN_SHIFT,
+    1763                 :            :     MBEDTLS_MODE_ECB,
+    1764                 :            :     MBEDTLS_CIPHER_DES_ECB,
+    1765                 :            :     0,
+    1766                 :            :     MBEDTLS_CIPHER_BASE_INDEX_DES
+    1767                 :            : };
+    1768                 :            : 
+    1769                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+    1770                 :            : static const mbedtls_cipher_info_t des_cbc_info = {
+    1771                 :            :     "DES-CBC",
+    1772                 :            :     8,
+    1773                 :            :     8 >> MBEDTLS_IV_SIZE_SHIFT,
+    1774                 :            :     MBEDTLS_KEY_LENGTH_DES >> MBEDTLS_KEY_BITLEN_SHIFT,
+    1775                 :            :     MBEDTLS_MODE_CBC,
+    1776                 :            :     MBEDTLS_CIPHER_DES_CBC,
+    1777                 :            :     0,
+    1778                 :            :     MBEDTLS_CIPHER_BASE_INDEX_DES
+    1779                 :            : };
+    1780                 :            : #endif /* MBEDTLS_CIPHER_MODE_CBC */
+    1781                 :            : 
+    1782                 :            : static const mbedtls_cipher_base_t des_ede_info = {
+    1783                 :            :     MBEDTLS_CIPHER_ID_DES,
+    1784                 :            :     des3_crypt_ecb_wrap,
+    1785                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+    1786                 :            :     des3_crypt_cbc_wrap,
+    1787                 :            : #endif
+    1788                 :            : #if defined(MBEDTLS_CIPHER_MODE_CFB)
+    1789                 :            :     NULL,
+    1790                 :            : #endif
+    1791                 :            : #if defined(MBEDTLS_CIPHER_MODE_OFB)
+    1792                 :            :     NULL,
+    1793                 :            : #endif
+    1794                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR)
+    1795                 :            :     NULL,
+    1796                 :            : #endif
+    1797                 :            : #if defined(MBEDTLS_CIPHER_MODE_XTS)
+    1798                 :            :     NULL,
+    1799                 :            : #endif
+    1800                 :            : #if defined(MBEDTLS_CIPHER_MODE_STREAM)
+    1801                 :            :     NULL,
+    1802                 :            : #endif
+    1803                 :            :     des3_set2key_enc_wrap,
+    1804                 :            :     des3_set2key_dec_wrap,
+    1805                 :            :     des3_ctx_alloc,
+    1806                 :            :     des3_ctx_free
+    1807                 :            : };
+    1808                 :            : 
+    1809                 :            : static const mbedtls_cipher_info_t des_ede_ecb_info = {
+    1810                 :            :     "DES-EDE-ECB",
+    1811                 :            :     8,
+    1812                 :            :     0 >> MBEDTLS_IV_SIZE_SHIFT,
+    1813                 :            :     MBEDTLS_KEY_LENGTH_DES_EDE >> MBEDTLS_KEY_BITLEN_SHIFT,
+    1814                 :            :     MBEDTLS_MODE_ECB,
+    1815                 :            :     MBEDTLS_CIPHER_DES_EDE_ECB,
+    1816                 :            :     0,
+    1817                 :            :     MBEDTLS_CIPHER_BASE_INDEX_DES_EDE
+    1818                 :            : };
+    1819                 :            : 
+    1820                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+    1821                 :            : static const mbedtls_cipher_info_t des_ede_cbc_info = {
+    1822                 :            :     "DES-EDE-CBC",
+    1823                 :            :     8,
+    1824                 :            :     8 >> MBEDTLS_IV_SIZE_SHIFT,
+    1825                 :            :     MBEDTLS_KEY_LENGTH_DES_EDE >> MBEDTLS_KEY_BITLEN_SHIFT,
+    1826                 :            :     MBEDTLS_MODE_CBC,
+    1827                 :            :     MBEDTLS_CIPHER_DES_EDE_CBC,
+    1828                 :            :     0,
+    1829                 :            :     MBEDTLS_CIPHER_BASE_INDEX_DES_EDE
+    1830                 :            : };
+    1831                 :            : #endif /* MBEDTLS_CIPHER_MODE_CBC */
+    1832                 :            : 
+    1833                 :            : static const mbedtls_cipher_base_t des_ede3_info = {
+    1834                 :            :     MBEDTLS_CIPHER_ID_3DES,
+    1835                 :            :     des3_crypt_ecb_wrap,
+    1836                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+    1837                 :            :     des3_crypt_cbc_wrap,
+    1838                 :            : #endif
+    1839                 :            : #if defined(MBEDTLS_CIPHER_MODE_CFB)
+    1840                 :            :     NULL,
+    1841                 :            : #endif
+    1842                 :            : #if defined(MBEDTLS_CIPHER_MODE_OFB)
+    1843                 :            :     NULL,
+    1844                 :            : #endif
+    1845                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR)
+    1846                 :            :     NULL,
+    1847                 :            : #endif
+    1848                 :            : #if defined(MBEDTLS_CIPHER_MODE_XTS)
+    1849                 :            :     NULL,
+    1850                 :            : #endif
+    1851                 :            : #if defined(MBEDTLS_CIPHER_MODE_STREAM)
+    1852                 :            :     NULL,
+    1853                 :            : #endif
+    1854                 :            :     des3_set3key_enc_wrap,
+    1855                 :            :     des3_set3key_dec_wrap,
+    1856                 :            :     des3_ctx_alloc,
+    1857                 :            :     des3_ctx_free
+    1858                 :            : };
+    1859                 :            : 
+    1860                 :            : static const mbedtls_cipher_info_t des_ede3_ecb_info = {
+    1861                 :            :     "DES-EDE3-ECB",
+    1862                 :            :     8,
+    1863                 :            :     0 >> MBEDTLS_IV_SIZE_SHIFT,
+    1864                 :            :     MBEDTLS_KEY_LENGTH_DES_EDE3 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    1865                 :            :     MBEDTLS_MODE_ECB,
+    1866                 :            :     MBEDTLS_CIPHER_DES_EDE3_ECB,
+    1867                 :            :     0,
+    1868                 :            :     MBEDTLS_CIPHER_BASE_INDEX_DES_EDE3
+    1869                 :            : };
+    1870                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+    1871                 :            : static const mbedtls_cipher_info_t des_ede3_cbc_info = {
+    1872                 :            :     "DES-EDE3-CBC",
+    1873                 :            :     8,
+    1874                 :            :     8 >> MBEDTLS_IV_SIZE_SHIFT,
+    1875                 :            :     MBEDTLS_KEY_LENGTH_DES_EDE3 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    1876                 :            :     MBEDTLS_MODE_CBC,
+    1877                 :            :     MBEDTLS_CIPHER_DES_EDE3_CBC,
+    1878                 :            :     0,
+    1879                 :            :     MBEDTLS_CIPHER_BASE_INDEX_DES_EDE3
+    1880                 :            : };
+    1881                 :            : #endif /* MBEDTLS_CIPHER_MODE_CBC */
+    1882                 :            : #endif /* MBEDTLS_DES_C */
+    1883                 :            : 
+    1884                 :            : #if defined(MBEDTLS_CHACHA20_C)
+    1885                 :            : 
+    1886                 :          0 : static int chacha20_setkey_wrap(void *ctx, const unsigned char *key,
+    1887                 :            :                                 unsigned int key_bitlen)
+    1888                 :            : {
+    1889         [ #  # ]:          0 :     if (key_bitlen != 256U) {
+    1890                 :          0 :         return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+    1891                 :            :     }
+    1892                 :            : 
+    1893         [ #  # ]:          0 :     if (0 != mbedtls_chacha20_setkey((mbedtls_chacha20_context *) ctx, key)) {
+    1894                 :          0 :         return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+    1895                 :            :     }
+    1896                 :            : 
+    1897                 :          0 :     return 0;
+    1898                 :            : }
+    1899                 :            : 
+    1900                 :          0 : static int chacha20_stream_wrap(void *ctx,  size_t length,
+    1901                 :            :                                 const unsigned char *input,
+    1902                 :            :                                 unsigned char *output)
+    1903                 :            : {
+    1904                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1905                 :            : 
+    1906                 :          0 :     ret = mbedtls_chacha20_update(ctx, length, input, output);
+    1907         [ #  # ]:          0 :     if (ret == MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA) {
+    1908                 :          0 :         return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+    1909                 :            :     }
+    1910                 :            : 
+    1911                 :          0 :     return ret;
+    1912                 :            : }
+    1913                 :            : 
+    1914                 :          0 : static void *chacha20_ctx_alloc(void)
+    1915                 :            : {
+    1916                 :            :     mbedtls_chacha20_context *ctx;
+    1917                 :          0 :     ctx = mbedtls_calloc(1, sizeof(mbedtls_chacha20_context));
+    1918                 :            : 
+    1919         [ #  # ]:          0 :     if (ctx == NULL) {
+    1920                 :          0 :         return NULL;
+    1921                 :            :     }
+    1922                 :            : 
+    1923                 :          0 :     mbedtls_chacha20_init(ctx);
+    1924                 :            : 
+    1925                 :          0 :     return ctx;
+    1926                 :            : }
+    1927                 :            : 
+    1928                 :          0 : static void chacha20_ctx_free(void *ctx)
+    1929                 :            : {
+    1930                 :          0 :     mbedtls_chacha20_free((mbedtls_chacha20_context *) ctx);
+    1931                 :          0 :     mbedtls_free(ctx);
+    1932                 :          0 : }
+    1933                 :            : 
+    1934                 :            : static const mbedtls_cipher_base_t chacha20_base_info = {
+    1935                 :            :     MBEDTLS_CIPHER_ID_CHACHA20,
+    1936                 :            :     NULL,
+    1937                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+    1938                 :            :     NULL,
+    1939                 :            : #endif
+    1940                 :            : #if defined(MBEDTLS_CIPHER_MODE_CFB)
+    1941                 :            :     NULL,
+    1942                 :            : #endif
+    1943                 :            : #if defined(MBEDTLS_CIPHER_MODE_OFB)
+    1944                 :            :     NULL,
+    1945                 :            : #endif
+    1946                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR)
+    1947                 :            :     NULL,
+    1948                 :            : #endif
+    1949                 :            : #if defined(MBEDTLS_CIPHER_MODE_XTS)
+    1950                 :            :     NULL,
+    1951                 :            : #endif
+    1952                 :            : #if defined(MBEDTLS_CIPHER_MODE_STREAM)
+    1953                 :            :     chacha20_stream_wrap,
+    1954                 :            : #endif
+    1955                 :            :     chacha20_setkey_wrap,
+    1956                 :            : #if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
+    1957                 :            :     chacha20_setkey_wrap,
+    1958                 :            : #endif
+    1959                 :            :     chacha20_ctx_alloc,
+    1960                 :            :     chacha20_ctx_free
+    1961                 :            : };
+    1962                 :            : static const mbedtls_cipher_info_t chacha20_info = {
+    1963                 :            :     "CHACHA20",
+    1964                 :            :     1,
+    1965                 :            :     12 >> MBEDTLS_IV_SIZE_SHIFT,
+    1966                 :            :     256 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    1967                 :            :     MBEDTLS_MODE_STREAM,
+    1968                 :            :     MBEDTLS_CIPHER_CHACHA20,
+    1969                 :            :     0,
+    1970                 :            :     MBEDTLS_CIPHER_BASE_INDEX_CHACHA20_BASE
+    1971                 :            : };
+    1972                 :            : #endif /* MBEDTLS_CHACHA20_C */
+    1973                 :            : 
+    1974                 :            : #if defined(MBEDTLS_CHACHAPOLY_C)
+    1975                 :            : 
+    1976                 :          0 : static int chachapoly_setkey_wrap(void *ctx,
+    1977                 :            :                                   const unsigned char *key,
+    1978                 :            :                                   unsigned int key_bitlen)
+    1979                 :            : {
+    1980         [ #  # ]:          0 :     if (key_bitlen != 256U) {
+    1981                 :          0 :         return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+    1982                 :            :     }
+    1983                 :            : 
+    1984         [ #  # ]:          0 :     if (0 != mbedtls_chachapoly_setkey((mbedtls_chachapoly_context *) ctx, key)) {
+    1985                 :          0 :         return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+    1986                 :            :     }
+    1987                 :            : 
+    1988                 :          0 :     return 0;
+    1989                 :            : }
+    1990                 :            : 
+    1991                 :          0 : static void *chachapoly_ctx_alloc(void)
+    1992                 :            : {
+    1993                 :            :     mbedtls_chachapoly_context *ctx;
+    1994                 :          0 :     ctx = mbedtls_calloc(1, sizeof(mbedtls_chachapoly_context));
+    1995                 :            : 
+    1996         [ #  # ]:          0 :     if (ctx == NULL) {
+    1997                 :          0 :         return NULL;
+    1998                 :            :     }
+    1999                 :            : 
+    2000                 :          0 :     mbedtls_chachapoly_init(ctx);
+    2001                 :            : 
+    2002                 :          0 :     return ctx;
+    2003                 :            : }
+    2004                 :            : 
+    2005                 :          0 : static void chachapoly_ctx_free(void *ctx)
+    2006                 :            : {
+    2007                 :          0 :     mbedtls_chachapoly_free((mbedtls_chachapoly_context *) ctx);
+    2008                 :          0 :     mbedtls_free(ctx);
+    2009                 :          0 : }
+    2010                 :            : 
+    2011                 :            : static const mbedtls_cipher_base_t chachapoly_base_info = {
+    2012                 :            :     MBEDTLS_CIPHER_ID_CHACHA20,
+    2013                 :            :     NULL,
+    2014                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+    2015                 :            :     NULL,
+    2016                 :            : #endif
+    2017                 :            : #if defined(MBEDTLS_CIPHER_MODE_CFB)
+    2018                 :            :     NULL,
+    2019                 :            : #endif
+    2020                 :            : #if defined(MBEDTLS_CIPHER_MODE_OFB)
+    2021                 :            :     NULL,
+    2022                 :            : #endif
+    2023                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR)
+    2024                 :            :     NULL,
+    2025                 :            : #endif
+    2026                 :            : #if defined(MBEDTLS_CIPHER_MODE_XTS)
+    2027                 :            :     NULL,
+    2028                 :            : #endif
+    2029                 :            : #if defined(MBEDTLS_CIPHER_MODE_STREAM)
+    2030                 :            :     NULL,
+    2031                 :            : #endif
+    2032                 :            :     chachapoly_setkey_wrap,
+    2033                 :            : #if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
+    2034                 :            :     chachapoly_setkey_wrap,
+    2035                 :            : #endif
+    2036                 :            :     chachapoly_ctx_alloc,
+    2037                 :            :     chachapoly_ctx_free
+    2038                 :            : };
+    2039                 :            : static const mbedtls_cipher_info_t chachapoly_info = {
+    2040                 :            :     "CHACHA20-POLY1305",
+    2041                 :            :     1,
+    2042                 :            :     12 >> MBEDTLS_IV_SIZE_SHIFT,
+    2043                 :            :     256 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    2044                 :            :     MBEDTLS_MODE_CHACHAPOLY,
+    2045                 :            :     MBEDTLS_CIPHER_CHACHA20_POLY1305,
+    2046                 :            :     0,
+    2047                 :            :     MBEDTLS_CIPHER_BASE_INDEX_CHACHAPOLY_BASE
+    2048                 :            : };
+    2049                 :            : #endif /* MBEDTLS_CHACHAPOLY_C */
+    2050                 :            : 
+    2051                 :            : #if defined(MBEDTLS_CIPHER_NULL_CIPHER)
+    2052                 :            : static int null_crypt_stream(void *ctx, size_t length,
+    2053                 :            :                              const unsigned char *input,
+    2054                 :            :                              unsigned char *output)
+    2055                 :            : {
+    2056                 :            :     ((void) ctx);
+    2057                 :            :     memmove(output, input, length);
+    2058                 :            :     return 0;
+    2059                 :            : }
+    2060                 :            : 
+    2061                 :            : static int null_setkey(void *ctx, const unsigned char *key,
+    2062                 :            :                        unsigned int key_bitlen)
+    2063                 :            : {
+    2064                 :            :     ((void) ctx);
+    2065                 :            :     ((void) key);
+    2066                 :            :     ((void) key_bitlen);
+    2067                 :            : 
+    2068                 :            :     return 0;
+    2069                 :            : }
+    2070                 :            : 
+    2071                 :            : static void *null_ctx_alloc(void)
+    2072                 :            : {
+    2073                 :            :     return (void *) 1;
+    2074                 :            : }
+    2075                 :            : 
+    2076                 :            : static void null_ctx_free(void *ctx)
+    2077                 :            : {
+    2078                 :            :     ((void) ctx);
+    2079                 :            : }
+    2080                 :            : 
+    2081                 :            : static const mbedtls_cipher_base_t null_base_info = {
+    2082                 :            :     MBEDTLS_CIPHER_ID_NULL,
+    2083                 :            :     NULL,
+    2084                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+    2085                 :            :     NULL,
+    2086                 :            : #endif
+    2087                 :            : #if defined(MBEDTLS_CIPHER_MODE_CFB)
+    2088                 :            :     NULL,
+    2089                 :            : #endif
+    2090                 :            : #if defined(MBEDTLS_CIPHER_MODE_OFB)
+    2091                 :            :     NULL,
+    2092                 :            : #endif
+    2093                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR)
+    2094                 :            :     NULL,
+    2095                 :            : #endif
+    2096                 :            : #if defined(MBEDTLS_CIPHER_MODE_XTS)
+    2097                 :            :     NULL,
+    2098                 :            : #endif
+    2099                 :            : #if defined(MBEDTLS_CIPHER_MODE_STREAM)
+    2100                 :            :     null_crypt_stream,
+    2101                 :            : #endif
+    2102                 :            :     null_setkey,
+    2103                 :            : #if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
+    2104                 :            :     null_setkey,
+    2105                 :            : #endif
+    2106                 :            :     null_ctx_alloc,
+    2107                 :            :     null_ctx_free
+    2108                 :            : };
+    2109                 :            : 
+    2110                 :            : static const mbedtls_cipher_info_t null_cipher_info = {
+    2111                 :            :     "NULL",
+    2112                 :            :     1,
+    2113                 :            :     0 >> MBEDTLS_IV_SIZE_SHIFT,
+    2114                 :            :     0 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    2115                 :            :     MBEDTLS_MODE_STREAM,
+    2116                 :            :     MBEDTLS_CIPHER_NULL,
+    2117                 :            :     0,
+    2118                 :            :     MBEDTLS_CIPHER_BASE_INDEX_NULL_BASE
+    2119                 :            : };
+    2120                 :            : #endif /* defined(MBEDTLS_CIPHER_NULL_CIPHER) */
+    2121                 :            : 
+    2122                 :            : #if defined(MBEDTLS_NIST_KW_C)
+    2123                 :            : static void *kw_ctx_alloc(void)
+    2124                 :            : {
+    2125                 :            :     void *ctx = mbedtls_calloc(1, sizeof(mbedtls_nist_kw_context));
+    2126                 :            : 
+    2127                 :            :     if (ctx != NULL) {
+    2128                 :            :         mbedtls_nist_kw_init((mbedtls_nist_kw_context *) ctx);
+    2129                 :            :     }
+    2130                 :            : 
+    2131                 :            :     return ctx;
+    2132                 :            : }
+    2133                 :            : 
+    2134                 :            : static void kw_ctx_free(void *ctx)
+    2135                 :            : {
+    2136                 :            :     mbedtls_nist_kw_free(ctx);
+    2137                 :            :     mbedtls_free(ctx);
+    2138                 :            : }
+    2139                 :            : 
+    2140                 :            : static int kw_aes_setkey_wrap(void *ctx, const unsigned char *key,
+    2141                 :            :                               unsigned int key_bitlen)
+    2142                 :            : {
+    2143                 :            :     return mbedtls_nist_kw_setkey((mbedtls_nist_kw_context *) ctx,
+    2144                 :            :                                   MBEDTLS_CIPHER_ID_AES, key, key_bitlen, 1);
+    2145                 :            : }
+    2146                 :            : 
+    2147                 :            : static int kw_aes_setkey_unwrap(void *ctx, const unsigned char *key,
+    2148                 :            :                                 unsigned int key_bitlen)
+    2149                 :            : {
+    2150                 :            :     return mbedtls_nist_kw_setkey((mbedtls_nist_kw_context *) ctx,
+    2151                 :            :                                   MBEDTLS_CIPHER_ID_AES, key, key_bitlen, 0);
+    2152                 :            : }
+    2153                 :            : 
+    2154                 :            : static const mbedtls_cipher_base_t kw_aes_info = {
+    2155                 :            :     MBEDTLS_CIPHER_ID_AES,
+    2156                 :            :     NULL,
+    2157                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+    2158                 :            :     NULL,
+    2159                 :            : #endif
+    2160                 :            : #if defined(MBEDTLS_CIPHER_MODE_CFB)
+    2161                 :            :     NULL,
+    2162                 :            : #endif
+    2163                 :            : #if defined(MBEDTLS_CIPHER_MODE_OFB)
+    2164                 :            :     NULL,
+    2165                 :            : #endif
+    2166                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR)
+    2167                 :            :     NULL,
+    2168                 :            : #endif
+    2169                 :            : #if defined(MBEDTLS_CIPHER_MODE_XTS)
+    2170                 :            :     NULL,
+    2171                 :            : #endif
+    2172                 :            : #if defined(MBEDTLS_CIPHER_MODE_STREAM)
+    2173                 :            :     NULL,
+    2174                 :            : #endif
+    2175                 :            :     kw_aes_setkey_wrap,
+    2176                 :            :     kw_aes_setkey_unwrap,
+    2177                 :            :     kw_ctx_alloc,
+    2178                 :            :     kw_ctx_free,
+    2179                 :            : };
+    2180                 :            : 
+    2181                 :            : static const mbedtls_cipher_info_t aes_128_nist_kw_info = {
+    2182                 :            :     "AES-128-KW",
+    2183                 :            :     16,
+    2184                 :            :     0 >> MBEDTLS_IV_SIZE_SHIFT,
+    2185                 :            :     128 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    2186                 :            :     MBEDTLS_MODE_KW,
+    2187                 :            :     MBEDTLS_CIPHER_AES_128_KW,
+    2188                 :            :     0,
+    2189                 :            :     MBEDTLS_CIPHER_BASE_INDEX_KW_AES
+    2190                 :            : };
+    2191                 :            : 
+    2192                 :            : #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
+    2193                 :            : static const mbedtls_cipher_info_t aes_192_nist_kw_info = {
+    2194                 :            :     "AES-192-KW",
+    2195                 :            :     16,
+    2196                 :            :     0 >> MBEDTLS_IV_SIZE_SHIFT,
+    2197                 :            :     192 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    2198                 :            :     MBEDTLS_MODE_KW,
+    2199                 :            :     MBEDTLS_CIPHER_AES_192_KW,
+    2200                 :            :     0,
+    2201                 :            :     MBEDTLS_CIPHER_BASE_INDEX_KW_AES
+    2202                 :            : };
+    2203                 :            : 
+    2204                 :            : static const mbedtls_cipher_info_t aes_256_nist_kw_info = {
+    2205                 :            :     "AES-256-KW",
+    2206                 :            :     16,
+    2207                 :            :     0 >> MBEDTLS_IV_SIZE_SHIFT,
+    2208                 :            :     256 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    2209                 :            :     MBEDTLS_MODE_KW,
+    2210                 :            :     MBEDTLS_CIPHER_AES_256_KW,
+    2211                 :            :     0,
+    2212                 :            :     MBEDTLS_CIPHER_BASE_INDEX_KW_AES
+    2213                 :            : };
+    2214                 :            : #endif
+    2215                 :            : 
+    2216                 :            : static const mbedtls_cipher_info_t aes_128_nist_kwp_info = {
+    2217                 :            :     "AES-128-KWP",
+    2218                 :            :     16,
+    2219                 :            :     0 >> MBEDTLS_IV_SIZE_SHIFT,
+    2220                 :            :     128 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    2221                 :            :     MBEDTLS_MODE_KWP,
+    2222                 :            :     MBEDTLS_CIPHER_AES_128_KWP,
+    2223                 :            :     0,
+    2224                 :            :     MBEDTLS_CIPHER_BASE_INDEX_KW_AES
+    2225                 :            : };
+    2226                 :            : 
+    2227                 :            : #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
+    2228                 :            : static const mbedtls_cipher_info_t aes_192_nist_kwp_info = {
+    2229                 :            :     "AES-192-KWP",
+    2230                 :            :     16,
+    2231                 :            :     0 >> MBEDTLS_IV_SIZE_SHIFT,
+    2232                 :            :     192 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    2233                 :            :     MBEDTLS_MODE_KWP,
+    2234                 :            :     MBEDTLS_CIPHER_AES_192_KWP,
+    2235                 :            :     0,
+    2236                 :            :     MBEDTLS_CIPHER_BASE_INDEX_KW_AES
+    2237                 :            : };
+    2238                 :            : 
+    2239                 :            : static const mbedtls_cipher_info_t aes_256_nist_kwp_info = {
+    2240                 :            :     "AES-256-KWP",
+    2241                 :            :     16,
+    2242                 :            :     0 >> MBEDTLS_IV_SIZE_SHIFT,
+    2243                 :            :     256 >> MBEDTLS_KEY_BITLEN_SHIFT,
+    2244                 :            :     MBEDTLS_MODE_KWP,
+    2245                 :            :     MBEDTLS_CIPHER_AES_256_KWP,
+    2246                 :            :     0,
+    2247                 :            :     MBEDTLS_CIPHER_BASE_INDEX_KW_AES
+    2248                 :            : };
+    2249                 :            : #endif
+    2250                 :            : #endif /* MBEDTLS_NIST_KW_C */
+    2251                 :            : 
+    2252                 :            : const mbedtls_cipher_definition_t mbedtls_cipher_definitions[] =
+    2253                 :            : {
+    2254                 :            : #if defined(MBEDTLS_AES_C)
+    2255                 :            :     { MBEDTLS_CIPHER_AES_128_ECB,          &aes_128_ecb_info },
+    2256                 :            : #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
+    2257                 :            :     { MBEDTLS_CIPHER_AES_192_ECB,          &aes_192_ecb_info },
+    2258                 :            :     { MBEDTLS_CIPHER_AES_256_ECB,          &aes_256_ecb_info },
+    2259                 :            : #endif
+    2260                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+    2261                 :            :     { MBEDTLS_CIPHER_AES_128_CBC,          &aes_128_cbc_info },
+    2262                 :            : #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
+    2263                 :            :     { MBEDTLS_CIPHER_AES_192_CBC,          &aes_192_cbc_info },
+    2264                 :            :     { MBEDTLS_CIPHER_AES_256_CBC,          &aes_256_cbc_info },
+    2265                 :            : #endif
+    2266                 :            : #endif
+    2267                 :            : #if defined(MBEDTLS_CIPHER_MODE_CFB)
+    2268                 :            :     { MBEDTLS_CIPHER_AES_128_CFB128,       &aes_128_cfb128_info },
+    2269                 :            : #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
+    2270                 :            :     { MBEDTLS_CIPHER_AES_192_CFB128,       &aes_192_cfb128_info },
+    2271                 :            :     { MBEDTLS_CIPHER_AES_256_CFB128,       &aes_256_cfb128_info },
+    2272                 :            : #endif
+    2273                 :            : #endif
+    2274                 :            : #if defined(MBEDTLS_CIPHER_MODE_OFB)
+    2275                 :            :     { MBEDTLS_CIPHER_AES_128_OFB,          &aes_128_ofb_info },
+    2276                 :            : #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
+    2277                 :            :     { MBEDTLS_CIPHER_AES_192_OFB,          &aes_192_ofb_info },
+    2278                 :            :     { MBEDTLS_CIPHER_AES_256_OFB,          &aes_256_ofb_info },
+    2279                 :            : #endif
+    2280                 :            : #endif
+    2281                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR)
+    2282                 :            :     { MBEDTLS_CIPHER_AES_128_CTR,          &aes_128_ctr_info },
+    2283                 :            : #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
+    2284                 :            :     { MBEDTLS_CIPHER_AES_192_CTR,          &aes_192_ctr_info },
+    2285                 :            :     { MBEDTLS_CIPHER_AES_256_CTR,          &aes_256_ctr_info },
+    2286                 :            : #endif
+    2287                 :            : #endif
+    2288                 :            : #if defined(MBEDTLS_CIPHER_MODE_XTS)
+    2289                 :            :     { MBEDTLS_CIPHER_AES_128_XTS,          &aes_128_xts_info },
+    2290                 :            : #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
+    2291                 :            :     { MBEDTLS_CIPHER_AES_256_XTS,          &aes_256_xts_info },
+    2292                 :            : #endif
+    2293                 :            : #endif
+    2294                 :            : #endif /* MBEDTLS_AES_C */
+    2295                 :            : #if defined(MBEDTLS_CIPHER_HAVE_GCM_AES_VIA_LEGACY_OR_USE_PSA)
+    2296                 :            :     { MBEDTLS_CIPHER_AES_128_GCM,          &aes_128_gcm_info },
+    2297                 :            : #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
+    2298                 :            :     { MBEDTLS_CIPHER_AES_192_GCM,          &aes_192_gcm_info },
+    2299                 :            :     { MBEDTLS_CIPHER_AES_256_GCM,          &aes_256_gcm_info },
+    2300                 :            : #endif
+    2301                 :            : #endif
+    2302                 :            : #if defined(MBEDTLS_CIPHER_HAVE_CCM_AES_VIA_LEGACY_OR_USE_PSA)
+    2303                 :            :     { MBEDTLS_CIPHER_AES_128_CCM,          &aes_128_ccm_info },
+    2304                 :            : #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
+    2305                 :            :     { MBEDTLS_CIPHER_AES_192_CCM,          &aes_192_ccm_info },
+    2306                 :            :     { MBEDTLS_CIPHER_AES_256_CCM,          &aes_256_ccm_info },
+    2307                 :            : #endif
+    2308                 :            : #endif
+    2309                 :            : #if defined(MBEDTLS_CIPHER_HAVE_CCM_STAR_NO_TAG_AES_VIA_LEGACY_OR_USE_PSA)
+    2310                 :            :     { MBEDTLS_CIPHER_AES_128_CCM_STAR_NO_TAG,          &aes_128_ccm_star_no_tag_info },
+    2311                 :            : #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
+    2312                 :            :     { MBEDTLS_CIPHER_AES_192_CCM_STAR_NO_TAG,          &aes_192_ccm_star_no_tag_info },
+    2313                 :            :     { MBEDTLS_CIPHER_AES_256_CCM_STAR_NO_TAG,          &aes_256_ccm_star_no_tag_info },
+    2314                 :            : #endif
+    2315                 :            : #endif
+    2316                 :            : 
+    2317                 :            : #if defined(MBEDTLS_CAMELLIA_C)
+    2318                 :            :     { MBEDTLS_CIPHER_CAMELLIA_128_ECB,     &camellia_128_ecb_info },
+    2319                 :            :     { MBEDTLS_CIPHER_CAMELLIA_192_ECB,     &camellia_192_ecb_info },
+    2320                 :            :     { MBEDTLS_CIPHER_CAMELLIA_256_ECB,     &camellia_256_ecb_info },
+    2321                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+    2322                 :            :     { MBEDTLS_CIPHER_CAMELLIA_128_CBC,     &camellia_128_cbc_info },
+    2323                 :            :     { MBEDTLS_CIPHER_CAMELLIA_192_CBC,     &camellia_192_cbc_info },
+    2324                 :            :     { MBEDTLS_CIPHER_CAMELLIA_256_CBC,     &camellia_256_cbc_info },
+    2325                 :            : #endif
+    2326                 :            : #if defined(MBEDTLS_CIPHER_MODE_CFB)
+    2327                 :            :     { MBEDTLS_CIPHER_CAMELLIA_128_CFB128,  &camellia_128_cfb128_info },
+    2328                 :            :     { MBEDTLS_CIPHER_CAMELLIA_192_CFB128,  &camellia_192_cfb128_info },
+    2329                 :            :     { MBEDTLS_CIPHER_CAMELLIA_256_CFB128,  &camellia_256_cfb128_info },
+    2330                 :            : #endif
+    2331                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR)
+    2332                 :            :     { MBEDTLS_CIPHER_CAMELLIA_128_CTR,     &camellia_128_ctr_info },
+    2333                 :            :     { MBEDTLS_CIPHER_CAMELLIA_192_CTR,     &camellia_192_ctr_info },
+    2334                 :            :     { MBEDTLS_CIPHER_CAMELLIA_256_CTR,     &camellia_256_ctr_info },
+    2335                 :            : #endif
+    2336                 :            : #if defined(MBEDTLS_GCM_C)
+    2337                 :            :     { MBEDTLS_CIPHER_CAMELLIA_128_GCM,     &camellia_128_gcm_info },
+    2338                 :            :     { MBEDTLS_CIPHER_CAMELLIA_192_GCM,     &camellia_192_gcm_info },
+    2339                 :            :     { MBEDTLS_CIPHER_CAMELLIA_256_GCM,     &camellia_256_gcm_info },
+    2340                 :            : #endif
+    2341                 :            : #if defined(MBEDTLS_CCM_C)
+    2342                 :            :     { MBEDTLS_CIPHER_CAMELLIA_128_CCM,     &camellia_128_ccm_info },
+    2343                 :            :     { MBEDTLS_CIPHER_CAMELLIA_192_CCM,     &camellia_192_ccm_info },
+    2344                 :            :     { MBEDTLS_CIPHER_CAMELLIA_256_CCM,     &camellia_256_ccm_info },
+    2345                 :            :     { MBEDTLS_CIPHER_CAMELLIA_128_CCM_STAR_NO_TAG,     &camellia_128_ccm_star_no_tag_info },
+    2346                 :            :     { MBEDTLS_CIPHER_CAMELLIA_192_CCM_STAR_NO_TAG,     &camellia_192_ccm_star_no_tag_info },
+    2347                 :            :     { MBEDTLS_CIPHER_CAMELLIA_256_CCM_STAR_NO_TAG,     &camellia_256_ccm_star_no_tag_info },
+    2348                 :            : #endif
+    2349                 :            : #endif /* MBEDTLS_CAMELLIA_C */
+    2350                 :            : 
+    2351                 :            : #if defined(MBEDTLS_ARIA_C)
+    2352                 :            :     { MBEDTLS_CIPHER_ARIA_128_ECB,     &aria_128_ecb_info },
+    2353                 :            :     { MBEDTLS_CIPHER_ARIA_192_ECB,     &aria_192_ecb_info },
+    2354                 :            :     { MBEDTLS_CIPHER_ARIA_256_ECB,     &aria_256_ecb_info },
+    2355                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+    2356                 :            :     { MBEDTLS_CIPHER_ARIA_128_CBC,     &aria_128_cbc_info },
+    2357                 :            :     { MBEDTLS_CIPHER_ARIA_192_CBC,     &aria_192_cbc_info },
+    2358                 :            :     { MBEDTLS_CIPHER_ARIA_256_CBC,     &aria_256_cbc_info },
+    2359                 :            : #endif
+    2360                 :            : #if defined(MBEDTLS_CIPHER_MODE_CFB)
+    2361                 :            :     { MBEDTLS_CIPHER_ARIA_128_CFB128,  &aria_128_cfb128_info },
+    2362                 :            :     { MBEDTLS_CIPHER_ARIA_192_CFB128,  &aria_192_cfb128_info },
+    2363                 :            :     { MBEDTLS_CIPHER_ARIA_256_CFB128,  &aria_256_cfb128_info },
+    2364                 :            : #endif
+    2365                 :            : #if defined(MBEDTLS_CIPHER_MODE_CTR)
+    2366                 :            :     { MBEDTLS_CIPHER_ARIA_128_CTR,     &aria_128_ctr_info },
+    2367                 :            :     { MBEDTLS_CIPHER_ARIA_192_CTR,     &aria_192_ctr_info },
+    2368                 :            :     { MBEDTLS_CIPHER_ARIA_256_CTR,     &aria_256_ctr_info },
+    2369                 :            : #endif
+    2370                 :            : #if defined(MBEDTLS_GCM_C)
+    2371                 :            :     { MBEDTLS_CIPHER_ARIA_128_GCM,     &aria_128_gcm_info },
+    2372                 :            :     { MBEDTLS_CIPHER_ARIA_192_GCM,     &aria_192_gcm_info },
+    2373                 :            :     { MBEDTLS_CIPHER_ARIA_256_GCM,     &aria_256_gcm_info },
+    2374                 :            : #endif
+    2375                 :            : #if defined(MBEDTLS_CCM_C)
+    2376                 :            :     { MBEDTLS_CIPHER_ARIA_128_CCM,     &aria_128_ccm_info },
+    2377                 :            :     { MBEDTLS_CIPHER_ARIA_192_CCM,     &aria_192_ccm_info },
+    2378                 :            :     { MBEDTLS_CIPHER_ARIA_256_CCM,     &aria_256_ccm_info },
+    2379                 :            :     { MBEDTLS_CIPHER_ARIA_128_CCM_STAR_NO_TAG,     &aria_128_ccm_star_no_tag_info },
+    2380                 :            :     { MBEDTLS_CIPHER_ARIA_192_CCM_STAR_NO_TAG,     &aria_192_ccm_star_no_tag_info },
+    2381                 :            :     { MBEDTLS_CIPHER_ARIA_256_CCM_STAR_NO_TAG,     &aria_256_ccm_star_no_tag_info },
+    2382                 :            : #endif
+    2383                 :            : #endif /* MBEDTLS_ARIA_C */
+    2384                 :            : 
+    2385                 :            : #if defined(MBEDTLS_DES_C)
+    2386                 :            :     { MBEDTLS_CIPHER_DES_ECB,              &des_ecb_info },
+    2387                 :            :     { MBEDTLS_CIPHER_DES_EDE_ECB,          &des_ede_ecb_info },
+    2388                 :            :     { MBEDTLS_CIPHER_DES_EDE3_ECB,         &des_ede3_ecb_info },
+    2389                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+    2390                 :            :     { MBEDTLS_CIPHER_DES_CBC,              &des_cbc_info },
+    2391                 :            :     { MBEDTLS_CIPHER_DES_EDE_CBC,          &des_ede_cbc_info },
+    2392                 :            :     { MBEDTLS_CIPHER_DES_EDE3_CBC,         &des_ede3_cbc_info },
+    2393                 :            : #endif
+    2394                 :            : #endif /* MBEDTLS_DES_C */
+    2395                 :            : 
+    2396                 :            : #if defined(MBEDTLS_CHACHA20_C)
+    2397                 :            :     { MBEDTLS_CIPHER_CHACHA20,             &chacha20_info },
+    2398                 :            : #endif
+    2399                 :            : 
+    2400                 :            : #if defined(MBEDTLS_CHACHAPOLY_C)
+    2401                 :            :     { MBEDTLS_CIPHER_CHACHA20_POLY1305,    &chachapoly_info },
+    2402                 :            : #endif
+    2403                 :            : 
+    2404                 :            : #if defined(MBEDTLS_NIST_KW_C)
+    2405                 :            :     { MBEDTLS_CIPHER_AES_128_KW,          &aes_128_nist_kw_info },
+    2406                 :            : #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
+    2407                 :            :     { MBEDTLS_CIPHER_AES_192_KW,          &aes_192_nist_kw_info },
+    2408                 :            :     { MBEDTLS_CIPHER_AES_256_KW,          &aes_256_nist_kw_info },
+    2409                 :            : #endif
+    2410                 :            :     { MBEDTLS_CIPHER_AES_128_KWP,         &aes_128_nist_kwp_info },
+    2411                 :            : #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
+    2412                 :            :     { MBEDTLS_CIPHER_AES_192_KWP,         &aes_192_nist_kwp_info },
+    2413                 :            :     { MBEDTLS_CIPHER_AES_256_KWP,         &aes_256_nist_kwp_info },
+    2414                 :            : #endif
+    2415                 :            : #endif
+    2416                 :            : 
+    2417                 :            : #if defined(MBEDTLS_CIPHER_NULL_CIPHER)
+    2418                 :            :     { MBEDTLS_CIPHER_NULL,                 &null_cipher_info },
+    2419                 :            : #endif /* MBEDTLS_CIPHER_NULL_CIPHER */
+    2420                 :            : 
+    2421                 :            :     { MBEDTLS_CIPHER_NONE, NULL }
+    2422                 :            : };
+    2423                 :            : 
+    2424                 :            : #define NUM_CIPHERS (sizeof(mbedtls_cipher_definitions) /      \
+    2425                 :            :                      sizeof(mbedtls_cipher_definitions[0]))
+    2426                 :            : int mbedtls_cipher_supported[NUM_CIPHERS];
+    2427                 :            : 
+    2428                 :            : const mbedtls_cipher_base_t *mbedtls_cipher_base_lookup_table[] = {
+    2429                 :            : #if defined(MBEDTLS_AES_C)
+    2430                 :            :     [MBEDTLS_CIPHER_BASE_INDEX_AES] = &aes_info,
+    2431                 :            : #endif
+    2432                 :            : #if defined(MBEDTLS_ARIA_C)
+    2433                 :            :     [MBEDTLS_CIPHER_BASE_INDEX_ARIA] = &aria_info,
+    2434                 :            : #endif
+    2435                 :            : #if defined(MBEDTLS_CAMELLIA_C)
+    2436                 :            :     [MBEDTLS_CIPHER_BASE_INDEX_CAMELLIA] = &camellia_info,
+    2437                 :            : #endif
+    2438                 :            : #if defined(MBEDTLS_CIPHER_HAVE_CCM_AES_VIA_LEGACY_OR_USE_PSA)
+    2439                 :            :     [MBEDTLS_CIPHER_BASE_INDEX_CCM_AES] = &ccm_aes_info,
+    2440                 :            : #endif
+    2441                 :            : #if defined(MBEDTLS_CCM_C) && defined(MBEDTLS_ARIA_C)
+    2442                 :            :     [MBEDTLS_CIPHER_BASE_INDEX_CCM_ARIA] = &ccm_aria_info,
+    2443                 :            : #endif
+    2444                 :            : #if defined(MBEDTLS_CCM_C) && defined(MBEDTLS_CAMELLIA_C)
+    2445                 :            :     [MBEDTLS_CIPHER_BASE_INDEX_CCM_CAMELLIA] = &ccm_camellia_info,
+    2446                 :            : #endif
+    2447                 :            : #if defined(MBEDTLS_CHACHA20_C)
+    2448                 :            :     [MBEDTLS_CIPHER_BASE_INDEX_CHACHA20_BASE] = &chacha20_base_info,
+    2449                 :            : #endif
+    2450                 :            : #if defined(MBEDTLS_CHACHAPOLY_C)
+    2451                 :            :     [MBEDTLS_CIPHER_BASE_INDEX_CHACHAPOLY_BASE] = &chachapoly_base_info,
+    2452                 :            : #endif
+    2453                 :            : #if defined(MBEDTLS_DES_C)
+    2454                 :            :     [MBEDTLS_CIPHER_BASE_INDEX_DES_EDE3] = &des_ede3_info,
+    2455                 :            : #endif
+    2456                 :            : #if defined(MBEDTLS_DES_C)
+    2457                 :            :     [MBEDTLS_CIPHER_BASE_INDEX_DES_EDE] = &des_ede_info,
+    2458                 :            : #endif
+    2459                 :            : #if defined(MBEDTLS_DES_C)
+    2460                 :            :     [MBEDTLS_CIPHER_BASE_INDEX_DES] = &des_info,
+    2461                 :            : #endif
+    2462                 :            : #if defined(MBEDTLS_CIPHER_HAVE_GCM_AES_VIA_LEGACY_OR_USE_PSA)
+    2463                 :            :     [MBEDTLS_CIPHER_BASE_INDEX_GCM_AES] = &gcm_aes_info,
+    2464                 :            : #endif
+    2465                 :            : #if defined(MBEDTLS_GCM_C) && defined(MBEDTLS_ARIA_C)
+    2466                 :            :     [MBEDTLS_CIPHER_BASE_INDEX_GCM_ARIA] = &gcm_aria_info,
+    2467                 :            : #endif
+    2468                 :            : #if defined(MBEDTLS_GCM_C) && defined(MBEDTLS_CAMELLIA_C)
+    2469                 :            :     [MBEDTLS_CIPHER_BASE_INDEX_GCM_CAMELLIA] = &gcm_camellia_info,
+    2470                 :            : #endif
+    2471                 :            : #if defined(MBEDTLS_NIST_KW_C)
+    2472                 :            :     [MBEDTLS_CIPHER_BASE_INDEX_KW_AES] = &kw_aes_info,
+    2473                 :            : #endif
+    2474                 :            : #if defined(MBEDTLS_CIPHER_NULL_CIPHER)
+    2475                 :            :     [MBEDTLS_CIPHER_BASE_INDEX_NULL_BASE] = &null_base_info,
+    2476                 :            : #endif
+    2477                 :            : #if defined(MBEDTLS_CIPHER_MODE_XTS) && defined(MBEDTLS_AES_C)
+    2478                 :            :     [MBEDTLS_CIPHER_BASE_INDEX_XTS_AES] = &xts_aes_info
+    2479                 :            : #endif
+    2480                 :            : };
+    2481                 :            : 
+    2482                 :            : #endif /* MBEDTLS_CIPHER_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/common.h.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/common.h.func-sort-c.html new file mode 100644 index 00000000000..f381bdb22b4 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/common.h.func-sort-c.html @@ -0,0 +1,81 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/common.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - common.h (source / functions)HitTotalCoverage
Test:coverage.infoLines:71450.0 %
Date:2024-09-22 08:21:07Functions:00-
Branches:275648.2 %
+
+ +
+ + + + + + +

Function Name Sort by function nameHit count Sort by hit count
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/common.h.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/common.h.func.html new file mode 100644 index 00000000000..8752e7835bb --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/common.h.func.html @@ -0,0 +1,81 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/common.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - common.h (source / functions)HitTotalCoverage
Test:coverage.infoLines:71450.0 %
Date:2024-09-22 08:21:07Functions:00-
Branches:275648.2 %
+
+ +
+ + + + + + +

Function Name Sort by function nameHit count Sort by hit count
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/common.h.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/common.h.gcov.html new file mode 100644 index 00000000000..2b81998ccb1 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/common.h.gcov.html @@ -0,0 +1,530 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/common.h + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - common.h (source / functions)HitTotalCoverage
Test:coverage.infoLines:71450.0 %
Date:2024-09-22 08:21:07Functions:00-
Branches:275648.2 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  * \file common.h
+       3                 :            :  *
+       4                 :            :  * \brief Utility macros for internal use in the library
+       5                 :            :  */
+       6                 :            : /*
+       7                 :            :  *  Copyright The Mbed TLS Contributors
+       8                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       9                 :            :  */
+      10                 :            : 
+      11                 :            : #ifndef MBEDTLS_LIBRARY_COMMON_H
+      12                 :            : #define MBEDTLS_LIBRARY_COMMON_H
+      13                 :            : 
+      14                 :            : #include "mbedtls/build_info.h"
+      15                 :            : #include "alignment.h"
+      16                 :            : 
+      17                 :            : #include <assert.h>
+      18                 :            : #include <stddef.h>
+      19                 :            : #include <stdint.h>
+      20                 :            : #include <stddef.h>
+      21                 :            : 
+      22                 :            : #if defined(__ARM_NEON)
+      23                 :            : #include <arm_neon.h>
+      24                 :            : #define MBEDTLS_HAVE_NEON_INTRINSICS
+      25                 :            : #elif defined(MBEDTLS_PLATFORM_IS_WINDOWS_ON_ARM64)
+      26                 :            : #include <arm64_neon.h>
+      27                 :            : #define MBEDTLS_HAVE_NEON_INTRINSICS
+      28                 :            : #endif
+      29                 :            : 
+      30                 :            : /** Helper to define a function as static except when building invasive tests.
+      31                 :            :  *
+      32                 :            :  * If a function is only used inside its own source file and should be
+      33                 :            :  * declared `static` to allow the compiler to optimize for code size,
+      34                 :            :  * but that function has unit tests, define it with
+      35                 :            :  * ```
+      36                 :            :  * MBEDTLS_STATIC_TESTABLE int mbedtls_foo(...) { ... }
+      37                 :            :  * ```
+      38                 :            :  * and declare it in a header in the `library/` directory with
+      39                 :            :  * ```
+      40                 :            :  * #if defined(MBEDTLS_TEST_HOOKS)
+      41                 :            :  * int mbedtls_foo(...);
+      42                 :            :  * #endif
+      43                 :            :  * ```
+      44                 :            :  */
+      45                 :            : #if defined(MBEDTLS_TEST_HOOKS)
+      46                 :            : #define MBEDTLS_STATIC_TESTABLE
+      47                 :            : #else
+      48                 :            : #define MBEDTLS_STATIC_TESTABLE static
+      49                 :            : #endif
+      50                 :            : 
+      51                 :            : #if defined(MBEDTLS_TEST_HOOKS)
+      52                 :            : extern void (*mbedtls_test_hook_test_fail)(const char *test, int line, const char *file);
+      53                 :            : #define MBEDTLS_TEST_HOOK_TEST_ASSERT(TEST) \
+      54                 :            :     do { \
+      55                 :            :         if ((!(TEST)) && ((*mbedtls_test_hook_test_fail) != NULL)) \
+      56                 :            :         { \
+      57                 :            :             (*mbedtls_test_hook_test_fail)( #TEST, __LINE__, __FILE__); \
+      58                 :            :         } \
+      59                 :            :     } while (0)
+      60                 :            : #else
+      61                 :            : #define MBEDTLS_TEST_HOOK_TEST_ASSERT(TEST)
+      62                 :            : #endif /* defined(MBEDTLS_TEST_HOOKS) */
+      63                 :            : 
+      64                 :            : /** \def ARRAY_LENGTH
+      65                 :            :  * Return the number of elements of a static or stack array.
+      66                 :            :  *
+      67                 :            :  * \param array         A value of array (not pointer) type.
+      68                 :            :  *
+      69                 :            :  * \return The number of elements of the array.
+      70                 :            :  */
+      71                 :            : /* A correct implementation of ARRAY_LENGTH, but which silently gives
+      72                 :            :  * a nonsensical result if called with a pointer rather than an array. */
+      73                 :            : #define ARRAY_LENGTH_UNSAFE(array)            \
+      74                 :            :     (sizeof(array) / sizeof(*(array)))
+      75                 :            : 
+      76                 :            : #if defined(__GNUC__)
+      77                 :            : /* Test if arg and &(arg)[0] have the same type. This is true if arg is
+      78                 :            :  * an array but not if it's a pointer. */
+      79                 :            : #define IS_ARRAY_NOT_POINTER(arg)                                     \
+      80                 :            :     (!__builtin_types_compatible_p(__typeof__(arg),                \
+      81                 :            :                                    __typeof__(&(arg)[0])))
+      82                 :            : /* A compile-time constant with the value 0. If `const_expr` is not a
+      83                 :            :  * compile-time constant with a nonzero value, cause a compile-time error. */
+      84                 :            : #define STATIC_ASSERT_EXPR(const_expr)                                \
+      85                 :            :     (0 && sizeof(struct { unsigned int STATIC_ASSERT : 1 - 2 * !(const_expr); }))
+      86                 :            : 
+      87                 :            : /* Return the scalar value `value` (possibly promoted). This is a compile-time
+      88                 :            :  * constant if `value` is. `condition` must be a compile-time constant.
+      89                 :            :  * If `condition` is false, arrange to cause a compile-time error. */
+      90                 :            : #define STATIC_ASSERT_THEN_RETURN(condition, value)   \
+      91                 :            :     (STATIC_ASSERT_EXPR(condition) ? 0 : (value))
+      92                 :            : 
+      93                 :            : #define ARRAY_LENGTH(array)                                           \
+      94                 :            :     (STATIC_ASSERT_THEN_RETURN(IS_ARRAY_NOT_POINTER(array),         \
+      95                 :            :                                ARRAY_LENGTH_UNSAFE(array)))
+      96                 :            : 
+      97                 :            : #else
+      98                 :            : /* If we aren't sure the compiler supports our non-standard tricks,
+      99                 :            :  * fall back to the unsafe implementation. */
+     100                 :            : #define ARRAY_LENGTH(array) ARRAY_LENGTH_UNSAFE(array)
+     101                 :            : #endif
+     102                 :            : /** Allow library to access its structs' private members.
+     103                 :            :  *
+     104                 :            :  * Although structs defined in header files are publicly available,
+     105                 :            :  * their members are private and should not be accessed by the user.
+     106                 :            :  */
+     107                 :            : #define MBEDTLS_ALLOW_PRIVATE_ACCESS
+     108                 :            : 
+     109                 :            : /**
+     110                 :            :  * \brief       Securely zeroize a buffer then free it.
+     111                 :            :  *
+     112                 :            :  *              Similar to making consecutive calls to
+     113                 :            :  *              \c mbedtls_platform_zeroize() and \c mbedtls_free(), but has
+     114                 :            :  *              code size savings, and potential for optimisation in the future.
+     115                 :            :  *
+     116                 :            :  *              Guaranteed to be a no-op if \p buf is \c NULL and \p len is 0.
+     117                 :            :  *
+     118                 :            :  * \param buf   Buffer to be zeroized then freed.
+     119                 :            :  * \param len   Length of the buffer in bytes
+     120                 :            :  */
+     121                 :            : void mbedtls_zeroize_and_free(void *buf, size_t len);
+     122                 :            : 
+     123                 :            : /** Return an offset into a buffer.
+     124                 :            :  *
+     125                 :            :  * This is just the addition of an offset to a pointer, except that this
+     126                 :            :  * function also accepts an offset of 0 into a buffer whose pointer is null.
+     127                 :            :  * (`p + n` has undefined behavior when `p` is null, even when `n == 0`.
+     128                 :            :  * A null pointer is a valid buffer pointer when the size is 0, for example
+     129                 :            :  * as the result of `malloc(0)` on some platforms.)
+     130                 :            :  *
+     131                 :            :  * \param p     Pointer to a buffer of at least n bytes.
+     132                 :            :  *              This may be \p NULL if \p n is zero.
+     133                 :            :  * \param n     An offset in bytes.
+     134                 :            :  * \return      Pointer to offset \p n in the buffer \p p.
+     135                 :            :  *              Note that this is only a valid pointer if the size of the
+     136                 :            :  *              buffer is at least \p n + 1.
+     137                 :            :  */
+     138                 :            : static inline unsigned char *mbedtls_buffer_offset(
+     139                 :            :     unsigned char *p, size_t n)
+     140                 :            : {
+     141                 :            :     return p == NULL ? NULL : p + n;
+     142                 :            : }
+     143                 :            : 
+     144                 :            : /** Return an offset into a read-only buffer.
+     145                 :            :  *
+     146                 :            :  * Similar to mbedtls_buffer_offset(), but for const pointers.
+     147                 :            :  *
+     148                 :            :  * \param p     Pointer to a buffer of at least n bytes.
+     149                 :            :  *              This may be \p NULL if \p n is zero.
+     150                 :            :  * \param n     An offset in bytes.
+     151                 :            :  * \return      Pointer to offset \p n in the buffer \p p.
+     152                 :            :  *              Note that this is only a valid pointer if the size of the
+     153                 :            :  *              buffer is at least \p n + 1.
+     154                 :            :  */
+     155                 :            : static inline const unsigned char *mbedtls_buffer_offset_const(
+     156                 :            :     const unsigned char *p, size_t n)
+     157                 :            : {
+     158                 :            :     return p == NULL ? NULL : p + n;
+     159                 :            : }
+     160                 :            : 
+     161                 :            : /* Always inline mbedtls_xor() for similar reasons as mbedtls_xor_no_simd(). */
+     162                 :            : #if defined(__IAR_SYSTEMS_ICC__)
+     163                 :            : #pragma inline = forced
+     164                 :            : #elif defined(__GNUC__)
+     165                 :            : __attribute__((always_inline))
+     166                 :            : #endif
+     167                 :            : /**
+     168                 :            :  * Perform a fast block XOR operation, such that
+     169                 :            :  * r[i] = a[i] ^ b[i] where 0 <= i < n
+     170                 :            :  *
+     171                 :            :  * \param   r Pointer to result (buffer of at least \p n bytes). \p r
+     172                 :            :  *            may be equal to either \p a or \p b, but behaviour when
+     173                 :            :  *            it overlaps in other ways is undefined.
+     174                 :            :  * \param   a Pointer to input (buffer of at least \p n bytes)
+     175                 :            :  * \param   b Pointer to input (buffer of at least \p n bytes)
+     176                 :            :  * \param   n Number of bytes to process.
+     177                 :            :  *
+     178                 :            :  * \note      Depending on the situation, it may be faster to use either mbedtls_xor() or
+     179                 :            :  *            mbedtls_xor_no_simd() (these are functionally equivalent).
+     180                 :            :  *            If the result is used immediately after the xor operation in non-SIMD code (e.g, in
+     181                 :            :  *            AES-CBC), there may be additional latency to transfer the data from SIMD to scalar
+     182                 :            :  *            registers, and in this case, mbedtls_xor_no_simd() may be faster. In other cases where
+     183                 :            :  *            the result is not used immediately (e.g., in AES-CTR), mbedtls_xor() may be faster.
+     184                 :            :  *            For targets without SIMD support, they will behave the same.
+     185                 :            :  */
+     186                 :            : static inline void mbedtls_xor(unsigned char *r,
+     187                 :            :                                const unsigned char *a,
+     188                 :            :                                const unsigned char *b,
+     189                 :            :                                size_t n)
+     190                 :            : {
+     191                 :      10111 :     size_t i = 0;
+     192                 :            : #if defined(MBEDTLS_EFFICIENT_UNALIGNED_ACCESS)
+     193                 :            : #if defined(MBEDTLS_HAVE_NEON_INTRINSICS) && \
+     194                 :            :     (!(defined(MBEDTLS_COMPILER_IS_GCC) && MBEDTLS_GCC_VERSION < 70300))
+     195                 :            :     /* Old GCC versions generate a warning here, so disable the NEON path for these compilers */
+     196                 :            :     for (; (i + 16) <= n; i += 16) {
+     197                 :            :         uint8x16_t v1 = vld1q_u8(a + i);
+     198                 :            :         uint8x16_t v2 = vld1q_u8(b + i);
+     199                 :            :         uint8x16_t x = veorq_u8(v1, v2);
+     200                 :            :         vst1q_u8(r + i, x);
+     201                 :            :     }
+     202                 :            : #if defined(__IAR_SYSTEMS_ICC__)
+     203                 :            :     /* This if statement helps some compilers (e.g., IAR) optimise out the byte-by-byte tail case
+     204                 :            :      * where n is a constant multiple of 16.
+     205                 :            :      * For other compilers (e.g. recent gcc and clang) it makes no difference if n is a compile-time
+     206                 :            :      * constant, and is a very small perf regression if n is not a compile-time constant. */
+     207                 :            :     if (n % 16 == 0) {
+     208                 :            :         return;
+     209                 :            :     }
+     210                 :            : #endif
+     211                 :            : #elif defined(MBEDTLS_ARCH_IS_X64) || defined(MBEDTLS_ARCH_IS_ARM64)
+     212                 :            :     /* This codepath probably only makes sense on architectures with 64-bit registers */
+     213   [ +  +  +  +  :      34412 :     for (; (i + 8) <= n; i += 8) {
+          +  +  +  +  +  
+          +  -  -  +  +  
+          +  +  -  -  -  
+                      - ]
+     214                 :      48602 :         uint64_t x = mbedtls_get_unaligned_uint64(a + i) ^ mbedtls_get_unaligned_uint64(b + i);
+     215                 :      24301 :         mbedtls_put_unaligned_uint64(r + i, x);
+     216                 :            :     }
+     217                 :            : #if defined(__IAR_SYSTEMS_ICC__)
+     218                 :            :     if (n % 8 == 0) {
+     219                 :            :         return;
+     220                 :            :     }
+     221                 :            : #endif
+     222                 :            : #else
+     223                 :            :     for (; (i + 4) <= n; i += 4) {
+     224                 :            :         uint32_t x = mbedtls_get_unaligned_uint32(a + i) ^ mbedtls_get_unaligned_uint32(b + i);
+     225                 :            :         mbedtls_put_unaligned_uint32(r + i, x);
+     226                 :            :     }
+     227                 :            : #if defined(__IAR_SYSTEMS_ICC__)
+     228                 :            :     if (n % 4 == 0) {
+     229                 :            :         return;
+     230                 :            :     }
+     231                 :            : #endif
+     232                 :            : #endif
+     233                 :            : #endif
+     234   [ +  +  +  +  :      15669 :     for (; i < n; i++) {
+          +  +  +  +  +  
+          +  -  -  -  +  
+          +  +  -  -  -  
+                      - ]
+     235                 :       5558 :         r[i] = a[i] ^ b[i];
+     236                 :            :     }
+     237                 :      10111 : }
+     238                 :            : 
+     239                 :            : /* Always inline mbedtls_xor_no_simd() as we see significant perf regressions when it does not get
+     240                 :            :  * inlined (e.g., observed about 3x perf difference in gcm_mult_largetable with gcc 7 - 12) */
+     241                 :            : #if defined(__IAR_SYSTEMS_ICC__)
+     242                 :            : #pragma inline = forced
+     243                 :            : #elif defined(__GNUC__)
+     244                 :            : __attribute__((always_inline))
+     245                 :            : #endif
+     246                 :            : /**
+     247                 :            :  * Perform a fast block XOR operation, such that
+     248                 :            :  * r[i] = a[i] ^ b[i] where 0 <= i < n
+     249                 :            :  *
+     250                 :            :  * In some situations, this can perform better than mbedtls_xor() (e.g., it's about 5%
+     251                 :            :  * better in AES-CBC).
+     252                 :            :  *
+     253                 :            :  * \param   r Pointer to result (buffer of at least \p n bytes). \p r
+     254                 :            :  *            may be equal to either \p a or \p b, but behaviour when
+     255                 :            :  *            it overlaps in other ways is undefined.
+     256                 :            :  * \param   a Pointer to input (buffer of at least \p n bytes)
+     257                 :            :  * \param   b Pointer to input (buffer of at least \p n bytes)
+     258                 :            :  * \param   n Number of bytes to process.
+     259                 :            :  *
+     260                 :            :  * \note      Depending on the situation, it may be faster to use either mbedtls_xor() or
+     261                 :            :  *            mbedtls_xor_no_simd() (these are functionally equivalent).
+     262                 :            :  *            If the result is used immediately after the xor operation in non-SIMD code (e.g, in
+     263                 :            :  *            AES-CBC), there may be additional latency to transfer the data from SIMD to scalar
+     264                 :            :  *            registers, and in this case, mbedtls_xor_no_simd() may be faster. In other cases where
+     265                 :            :  *            the result is not used immediately (e.g., in AES-CTR), mbedtls_xor() may be faster.
+     266                 :            :  *            For targets without SIMD support, they will behave the same.
+     267                 :            :  */
+     268                 :            : static inline void mbedtls_xor_no_simd(unsigned char *r,
+     269                 :            :                                        const unsigned char *a,
+     270                 :            :                                        const unsigned char *b,
+     271                 :            :                                        size_t n)
+     272                 :            : {
+     273                 :          0 :     size_t i = 0;
+     274                 :            : #if defined(MBEDTLS_EFFICIENT_UNALIGNED_ACCESS)
+     275                 :            : #if defined(MBEDTLS_ARCH_IS_X64) || defined(MBEDTLS_ARCH_IS_ARM64)
+     276                 :            :     /* This codepath probably only makes sense on architectures with 64-bit registers */
+     277   [ #  #  #  #  :          0 :     for (; (i + 8) <= n; i += 8) {
+             #  #  #  # ]
+     278                 :          0 :         uint64_t x = mbedtls_get_unaligned_uint64(a + i) ^ mbedtls_get_unaligned_uint64(b + i);
+     279                 :          0 :         mbedtls_put_unaligned_uint64(r + i, x);
+     280                 :            :     }
+     281                 :            : #if defined(__IAR_SYSTEMS_ICC__)
+     282                 :            :     /* This if statement helps some compilers (e.g., IAR) optimise out the byte-by-byte tail case
+     283                 :            :      * where n is a constant multiple of 8.
+     284                 :            :      * For other compilers (e.g. recent gcc and clang) it makes no difference if n is a compile-time
+     285                 :            :      * constant, and is a very small perf regression if n is not a compile-time constant. */
+     286                 :            :     if (n % 8 == 0) {
+     287                 :            :         return;
+     288                 :            :     }
+     289                 :            : #endif
+     290                 :            : #else
+     291                 :            :     for (; (i + 4) <= n; i += 4) {
+     292                 :            :         uint32_t x = mbedtls_get_unaligned_uint32(a + i) ^ mbedtls_get_unaligned_uint32(b + i);
+     293                 :            :         mbedtls_put_unaligned_uint32(r + i, x);
+     294                 :            :     }
+     295                 :            : #if defined(__IAR_SYSTEMS_ICC__)
+     296                 :            :     if (n % 4 == 0) {
+     297                 :            :         return;
+     298                 :            :     }
+     299                 :            : #endif
+     300                 :            : #endif
+     301                 :            : #endif
+     302   [ #  #  #  #  :          0 :     for (; i < n; i++) {
+             #  #  #  # ]
+     303                 :          0 :         r[i] = a[i] ^ b[i];
+     304                 :            :     }
+     305                 :          0 : }
+     306                 :            : 
+     307                 :            : /* Fix MSVC C99 compatible issue
+     308                 :            :  *      MSVC support __func__ from visual studio 2015( 1900 )
+     309                 :            :  *      Use MSVC predefine macro to avoid name check fail.
+     310                 :            :  */
+     311                 :            : #if (defined(_MSC_VER) && (_MSC_VER <= 1900))
+     312                 :            : #define /*no-check-names*/ __func__ __FUNCTION__
+     313                 :            : #endif
+     314                 :            : 
+     315                 :            : /* Define `asm` for compilers which don't define it. */
+     316                 :            : /* *INDENT-OFF* */
+     317                 :            : #ifndef asm
+     318                 :            : #if defined(__IAR_SYSTEMS_ICC__)
+     319                 :            : #define asm __asm
+     320                 :            : #else
+     321                 :            : #define asm __asm__
+     322                 :            : #endif
+     323                 :            : #endif
+     324                 :            : /* *INDENT-ON* */
+     325                 :            : 
+     326                 :            : /*
+     327                 :            :  * Define the constraint used for read-only pointer operands to aarch64 asm.
+     328                 :            :  *
+     329                 :            :  * This is normally the usual "r", but for aarch64_32 (aka ILP32,
+     330                 :            :  * as found in watchos), "p" is required to avoid warnings from clang.
+     331                 :            :  *
+     332                 :            :  * Note that clang does not recognise '+p' or '=p', and armclang
+     333                 :            :  * does not recognise 'p' at all. Therefore, to update a pointer from
+     334                 :            :  * aarch64 assembly, it is necessary to use something like:
+     335                 :            :  *
+     336                 :            :  * uintptr_t uptr = (uintptr_t) ptr;
+     337                 :            :  * asm( "ldr x4, [%x0], #8" ... : "+r" (uptr) : : )
+     338                 :            :  * ptr = (void*) uptr;
+     339                 :            :  *
+     340                 :            :  * Note that the "x" in "%x0" is neccessary; writing "%0" will cause warnings.
+     341                 :            :  */
+     342                 :            : #if defined(__aarch64__) && defined(MBEDTLS_HAVE_ASM)
+     343                 :            : #if UINTPTR_MAX == 0xfffffffful
+     344                 :            : /* ILP32: Specify the pointer operand slightly differently, as per #7787. */
+     345                 :            : #define MBEDTLS_ASM_AARCH64_PTR_CONSTRAINT "p"
+     346                 :            : #elif UINTPTR_MAX == 0xfffffffffffffffful
+     347                 :            : /* Normal case (64-bit pointers): use "r" as the constraint for pointer operands to asm */
+     348                 :            : #define MBEDTLS_ASM_AARCH64_PTR_CONSTRAINT "r"
+     349                 :            : #else
+     350                 :            : #error "Unrecognised pointer size for aarch64"
+     351                 :            : #endif
+     352                 :            : #endif
+     353                 :            : 
+     354                 :            : /* Always provide a static assert macro, so it can be used unconditionally.
+     355                 :            :  * It will expand to nothing on some systems.
+     356                 :            :  * Can be used outside functions (but don't add a trailing ';' in that case:
+     357                 :            :  * the semicolon is included here to avoid triggering -Wextra-semi when
+     358                 :            :  * MBEDTLS_STATIC_ASSERT() expands to nothing).
+     359                 :            :  * Can't use the C11-style `defined(static_assert)` on FreeBSD, since it
+     360                 :            :  * defines static_assert even with -std=c99, but then complains about it.
+     361                 :            :  */
+     362                 :            : #if defined(static_assert) && !defined(__FreeBSD__)
+     363                 :            : #define MBEDTLS_STATIC_ASSERT(expr, msg)    static_assert(expr, msg);
+     364                 :            : #else
+     365                 :            : #define MBEDTLS_STATIC_ASSERT(expr, msg)
+     366                 :            : #endif
+     367                 :            : 
+     368                 :            : #if defined(__has_builtin)
+     369                 :            : #define MBEDTLS_HAS_BUILTIN(x) __has_builtin(x)
+     370                 :            : #else
+     371                 :            : #define MBEDTLS_HAS_BUILTIN(x) 0
+     372                 :            : #endif
+     373                 :            : 
+     374                 :            : /* Define compiler branch hints */
+     375                 :            : #if MBEDTLS_HAS_BUILTIN(__builtin_expect)
+     376                 :            : #define MBEDTLS_LIKELY(x)       __builtin_expect(!!(x), 1)
+     377                 :            : #define MBEDTLS_UNLIKELY(x)     __builtin_expect(!!(x), 0)
+     378                 :            : #else
+     379                 :            : #define MBEDTLS_LIKELY(x)       x
+     380                 :            : #define MBEDTLS_UNLIKELY(x)     x
+     381                 :            : #endif
+     382                 :            : 
+     383                 :            : /* MBEDTLS_ASSUME may be used to provide additional information to the compiler
+     384                 :            :  * which can result in smaller code-size. */
+     385                 :            : #if MBEDTLS_HAS_BUILTIN(__builtin_assume)
+     386                 :            : /* clang provides __builtin_assume */
+     387                 :            : #define MBEDTLS_ASSUME(x)       __builtin_assume(x)
+     388                 :            : #elif MBEDTLS_HAS_BUILTIN(__builtin_unreachable)
+     389                 :            : /* gcc and IAR can use __builtin_unreachable */
+     390                 :            : #define MBEDTLS_ASSUME(x)       do { if (!(x)) __builtin_unreachable(); } while (0)
+     391                 :            : #elif defined(_MSC_VER)
+     392                 :            : /* Supported by MSVC since VS 2005 */
+     393                 :            : #define MBEDTLS_ASSUME(x)       __assume(x)
+     394                 :            : #else
+     395                 :            : #define MBEDTLS_ASSUME(x)       do { } while (0)
+     396                 :            : #endif
+     397                 :            : 
+     398                 :            : /* For gcc -Os, override with -O2 for a given function.
+     399                 :            :  *
+     400                 :            :  * This will not affect behaviour for other optimisation settings, e.g. -O0.
+     401                 :            :  */
+     402                 :            : #if defined(MBEDTLS_COMPILER_IS_GCC) && defined(__OPTIMIZE_SIZE__)
+     403                 :            : #define MBEDTLS_OPTIMIZE_FOR_PERFORMANCE __attribute__((optimize("-O2")))
+     404                 :            : #else
+     405                 :            : #define MBEDTLS_OPTIMIZE_FOR_PERFORMANCE
+     406                 :            : #endif
+     407                 :            : 
+     408                 :            : /* Suppress compiler warnings for unused functions and variables. */
+     409                 :            : #if !defined(MBEDTLS_MAYBE_UNUSED) && defined(__has_attribute)
+     410                 :            : #    if __has_attribute(unused)
+     411                 :            : #        define MBEDTLS_MAYBE_UNUSED __attribute__((unused))
+     412                 :            : #    endif
+     413                 :            : #endif
+     414                 :            : #if !defined(MBEDTLS_MAYBE_UNUSED) && defined(__GNUC__)
+     415                 :            : #    define MBEDTLS_MAYBE_UNUSED __attribute__((unused))
+     416                 :            : #endif
+     417                 :            : #if !defined(MBEDTLS_MAYBE_UNUSED) && defined(__IAR_SYSTEMS_ICC__) && defined(__VER__)
+     418                 :            : /* IAR does support __attribute__((unused)), but only if the -e flag (extended language support)
+     419                 :            :  * is given; the pragma always works.
+     420                 :            :  * Unfortunately the pragma affects the rest of the file where it is used, but this is harmless.
+     421                 :            :  * Check for version 5.2 or later - this pragma may be supported by earlier versions, but I wasn't
+     422                 :            :  * able to find documentation).
+     423                 :            :  */
+     424                 :            : #    if (__VER__ >= 5020000)
+     425                 :            : #        define MBEDTLS_MAYBE_UNUSED _Pragma("diag_suppress=Pe177")
+     426                 :            : #    endif
+     427                 :            : #endif
+     428                 :            : #if !defined(MBEDTLS_MAYBE_UNUSED) && defined(_MSC_VER)
+     429                 :            : #    define MBEDTLS_MAYBE_UNUSED __pragma(warning(suppress:4189))
+     430                 :            : #endif
+     431                 :            : #if !defined(MBEDTLS_MAYBE_UNUSED)
+     432                 :            : #    define MBEDTLS_MAYBE_UNUSED
+     433                 :            : #endif
+     434                 :            : 
+     435                 :            : #endif /* MBEDTLS_LIBRARY_COMMON_H */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/constant_time.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/constant_time.c.func-sort-c.html new file mode 100644 index 00000000000..210526717aa --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/constant_time.c.func-sort-c.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/constant_time.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - constant_time.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:214645.7 %
Date:2024-09-22 08:21:07Functions:2540.0 %
Branches:61833.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_ct_memcpy_offset0
mbedtls_ct_memmove_left0
mbedtls_ct_zeroize_if0
mbedtls_ct_memcmp627
mbedtls_ct_memcpy_if155964
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/constant_time.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/constant_time.c.func.html new file mode 100644 index 00000000000..601e20472ff --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/constant_time.c.func.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/constant_time.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - constant_time.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:214645.7 %
Date:2024-09-22 08:21:07Functions:2540.0 %
Branches:61833.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_ct_memcmp627
mbedtls_ct_memcpy_if155964
mbedtls_ct_memcpy_offset0
mbedtls_ct_memmove_left0
mbedtls_ct_zeroize_if0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/constant_time.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/constant_time.c.gcov.html new file mode 100644 index 00000000000..381b47ba1e4 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/constant_time.c.gcov.html @@ -0,0 +1,333 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/constant_time.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - constant_time.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:214645.7 %
Date:2024-09-22 08:21:07Functions:2540.0 %
Branches:61833.3 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Constant-time functions
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  */
+       7                 :            : 
+       8                 :            : /*
+       9                 :            :  * The following functions are implemented without using comparison operators, as those
+      10                 :            :  * might be translated to branches by some compilers on some platforms.
+      11                 :            :  */
+      12                 :            : 
+      13                 :            : #include <stdint.h>
+      14                 :            : #include <limits.h>
+      15                 :            : 
+      16                 :            : #include "common.h"
+      17                 :            : #include "constant_time_internal.h"
+      18                 :            : #include "mbedtls/constant_time.h"
+      19                 :            : #include "mbedtls/error.h"
+      20                 :            : #include "mbedtls/platform_util.h"
+      21                 :            : 
+      22                 :            : #include <string.h>
+      23                 :            : 
+      24                 :            : #if !defined(MBEDTLS_CT_ASM)
+      25                 :            : /*
+      26                 :            :  * Define an object with the value zero, such that the compiler cannot prove that it
+      27                 :            :  * has the value zero (because it is volatile, it "may be modified in ways unknown to
+      28                 :            :  * the implementation").
+      29                 :            :  */
+      30                 :            : volatile mbedtls_ct_uint_t mbedtls_ct_zero = 0;
+      31                 :            : #endif
+      32                 :            : 
+      33                 :            : /*
+      34                 :            :  * Define MBEDTLS_EFFICIENT_UNALIGNED_VOLATILE_ACCESS where assembly is present to
+      35                 :            :  * perform fast unaligned access to volatile data.
+      36                 :            :  *
+      37                 :            :  * This is needed because mbedtls_get_unaligned_uintXX etc don't support volatile
+      38                 :            :  * memory accesses.
+      39                 :            :  *
+      40                 :            :  * Some of these definitions could be moved into alignment.h but for now they are
+      41                 :            :  * only used here.
+      42                 :            :  */
+      43                 :            : #if defined(MBEDTLS_EFFICIENT_UNALIGNED_ACCESS) && \
+      44                 :            :     ((defined(MBEDTLS_CT_ARM_ASM) && (UINTPTR_MAX == 0xfffffffful)) || \
+      45                 :            :     defined(MBEDTLS_CT_AARCH64_ASM))
+      46                 :            : /* We check pointer sizes to avoid issues with them not matching register size requirements */
+      47                 :            : #define MBEDTLS_EFFICIENT_UNALIGNED_VOLATILE_ACCESS
+      48                 :            : 
+      49                 :            : static inline uint32_t mbedtls_get_unaligned_volatile_uint32(volatile const unsigned char *p)
+      50                 :            : {
+      51                 :            :     /* This is UB, even where it's safe:
+      52                 :            :      *    return *((volatile uint32_t*)p);
+      53                 :            :      * so instead the same thing is expressed in assembly below.
+      54                 :            :      */
+      55                 :            :     uint32_t r;
+      56                 :            : #if defined(MBEDTLS_CT_ARM_ASM)
+      57                 :            :     asm volatile ("ldr %0, [%1]" : "=r" (r) : "r" (p) :);
+      58                 :            : #elif defined(MBEDTLS_CT_AARCH64_ASM)
+      59                 :            :     asm volatile ("ldr %w0, [%1]" : "=r" (r) : MBEDTLS_ASM_AARCH64_PTR_CONSTRAINT(p) :);
+      60                 :            : #else
+      61                 :            : #error "No assembly defined for mbedtls_get_unaligned_volatile_uint32"
+      62                 :            : #endif
+      63                 :            :     return r;
+      64                 :            : }
+      65                 :            : #endif /* defined(MBEDTLS_EFFICIENT_UNALIGNED_ACCESS) &&
+      66                 :            :           (defined(MBEDTLS_CT_ARM_ASM) || defined(MBEDTLS_CT_AARCH64_ASM)) */
+      67                 :            : 
+      68                 :        627 : int mbedtls_ct_memcmp(const void *a,
+      69                 :            :                       const void *b,
+      70                 :            :                       size_t n)
+      71                 :            : {
+      72                 :        627 :     size_t i = 0;
+      73                 :            :     /*
+      74                 :            :      * `A` and `B` are cast to volatile to ensure that the compiler
+      75                 :            :      * generates code that always fully reads both buffers.
+      76                 :            :      * Otherwise it could generate a test to exit early if `diff` has all
+      77                 :            :      * bits set early in the loop.
+      78                 :            :      */
+      79                 :        627 :     volatile const unsigned char *A = (volatile const unsigned char *) a;
+      80                 :        627 :     volatile const unsigned char *B = (volatile const unsigned char *) b;
+      81                 :        627 :     uint32_t diff = 0;
+      82                 :            : 
+      83                 :            : #if defined(MBEDTLS_EFFICIENT_UNALIGNED_VOLATILE_ACCESS)
+      84                 :            :     for (; (i + 4) <= n; i += 4) {
+      85                 :            :         uint32_t x = mbedtls_get_unaligned_volatile_uint32(A + i);
+      86                 :            :         uint32_t y = mbedtls_get_unaligned_volatile_uint32(B + i);
+      87                 :            :         diff |= x ^ y;
+      88                 :            :     }
+      89                 :            : #endif
+      90                 :            : 
+      91         [ +  + ]:     143699 :     for (; i < n; i++) {
+      92                 :            :         /* Read volatile data in order before computing diff.
+      93                 :            :          * This avoids IAR compiler warning:
+      94                 :            :          * 'the order of volatile accesses is undefined ..' */
+      95                 :     143072 :         unsigned char x = A[i], y = B[i];
+      96                 :     143072 :         diff |= x ^ y;
+      97                 :            :     }
+      98                 :            : 
+      99                 :            : 
+     100                 :            : #if (INT_MAX < INT32_MAX)
+     101                 :            :     /* We don't support int smaller than 32-bits, but if someone tried to build
+     102                 :            :      * with this configuration, there is a risk that, for differing data, the
+     103                 :            :      * only bits set in diff are in the top 16-bits, and would be lost by a
+     104                 :            :      * simple cast from uint32 to int.
+     105                 :            :      * This would have significant security implications, so protect against it. */
+     106                 :            : #error "mbedtls_ct_memcmp() requires minimum 32-bit ints"
+     107                 :            : #else
+     108                 :            :     /* The bit-twiddling ensures that when we cast uint32_t to int, we are casting
+     109                 :            :      * a value that is in the range 0..INT_MAX - a value larger than this would
+     110                 :            :      * result in implementation defined behaviour.
+     111                 :            :      *
+     112                 :            :      * This ensures that the value returned by the function is non-zero iff
+     113                 :            :      * diff is non-zero.
+     114                 :            :      */
+     115                 :        627 :     return (int) ((diff & 0xffff) | (diff >> 16));
+     116                 :            : #endif
+     117                 :            : }
+     118                 :            : 
+     119                 :            : #if defined(MBEDTLS_NIST_KW_C)
+     120                 :            : 
+     121                 :            : int mbedtls_ct_memcmp_partial(const void *a,
+     122                 :            :                               const void *b,
+     123                 :            :                               size_t n,
+     124                 :            :                               size_t skip_head,
+     125                 :            :                               size_t skip_tail)
+     126                 :            : {
+     127                 :            :     unsigned int diff = 0;
+     128                 :            : 
+     129                 :            :     volatile const unsigned char *A = (volatile const unsigned char *) a;
+     130                 :            :     volatile const unsigned char *B = (volatile const unsigned char *) b;
+     131                 :            : 
+     132                 :            :     size_t valid_end = n - skip_tail;
+     133                 :            : 
+     134                 :            :     for (size_t i = 0; i < n; i++) {
+     135                 :            :         unsigned char x = A[i], y = B[i];
+     136                 :            :         unsigned int d = x ^ y;
+     137                 :            :         mbedtls_ct_condition_t valid = mbedtls_ct_bool_and(mbedtls_ct_uint_ge(i, skip_head),
+     138                 :            :                                                            mbedtls_ct_uint_lt(i, valid_end));
+     139                 :            :         diff |= mbedtls_ct_uint_if_else_0(valid, d);
+     140                 :            :     }
+     141                 :            : 
+     142                 :            :     /* Since we go byte-by-byte, the only bits set will be in the bottom 8 bits, so the
+     143                 :            :      * cast from uint to int is safe. */
+     144                 :            :     return (int) diff;
+     145                 :            : }
+     146                 :            : 
+     147                 :            : #endif
+     148                 :            : 
+     149                 :            : #if defined(MBEDTLS_PKCS1_V15) && defined(MBEDTLS_RSA_C) && !defined(MBEDTLS_RSA_ALT)
+     150                 :            : 
+     151                 :          0 : void mbedtls_ct_memmove_left(void *start, size_t total, size_t offset)
+     152                 :            : {
+     153                 :          0 :     volatile unsigned char *buf = start;
+     154         [ #  # ]:          0 :     for (size_t i = 0; i < total; i++) {
+     155                 :          0 :         mbedtls_ct_condition_t no_op = mbedtls_ct_uint_gt(total - offset, i);
+     156                 :            :         /* The first `total - offset` passes are a no-op. The last
+     157                 :            :          * `offset` passes shift the data one byte to the left and
+     158                 :            :          * zero out the last byte. */
+     159         [ #  # ]:          0 :         for (size_t n = 0; n < total - 1; n++) {
+     160                 :          0 :             unsigned char current = buf[n];
+     161                 :          0 :             unsigned char next    = buf[n+1];
+     162                 :          0 :             buf[n] = mbedtls_ct_uint_if(no_op, current, next);
+     163                 :            :         }
+     164                 :          0 :         buf[total-1] = mbedtls_ct_uint_if_else_0(no_op, buf[total-1]);
+     165                 :            :     }
+     166                 :          0 : }
+     167                 :            : 
+     168                 :            : #endif /* MBEDTLS_PKCS1_V15 && MBEDTLS_RSA_C && ! MBEDTLS_RSA_ALT */
+     169                 :            : 
+     170                 :     155964 : void mbedtls_ct_memcpy_if(mbedtls_ct_condition_t condition,
+     171                 :            :                           unsigned char *dest,
+     172                 :            :                           const unsigned char *src1,
+     173                 :            :                           const unsigned char *src2,
+     174                 :            :                           size_t len)
+     175                 :            : {
+     176                 :            : #if defined(MBEDTLS_CT_SIZE_64)
+     177                 :     155964 :     const uint64_t mask     = (uint64_t) condition;
+     178                 :     155964 :     const uint64_t not_mask = (uint64_t) ~mbedtls_ct_compiler_opaque(condition);
+     179                 :            : #else
+     180                 :            :     const uint32_t mask     = (uint32_t) condition;
+     181                 :            :     const uint32_t not_mask = (uint32_t) ~mbedtls_ct_compiler_opaque(condition);
+     182                 :            : #endif
+     183                 :            : 
+     184                 :            :     /* If src2 is NULL, setup src2 so that we read from the destination address.
+     185                 :            :      *
+     186                 :            :      * This means that if src2 == NULL && condition is false, the result will be a
+     187                 :            :      * no-op because we read from dest and write the same data back into dest.
+     188                 :            :      */
+     189         [ +  - ]:     155964 :     if (src2 == NULL) {
+     190                 :     155964 :         src2 = dest;
+     191                 :            :     }
+     192                 :            : 
+     193                 :            :     /* dest[i] = c1 == c2 ? src[i] : dest[i] */
+     194                 :     155964 :     size_t i = 0;
+     195                 :            : #if defined(MBEDTLS_EFFICIENT_UNALIGNED_ACCESS)
+     196                 :            : #if defined(MBEDTLS_CT_SIZE_64)
+     197         [ +  + ]:    4747843 :     for (; (i + 8) <= len; i += 8) {
+     198                 :    4591879 :         uint64_t a = mbedtls_get_unaligned_uint64(src1 + i) & mask;
+     199                 :    4591879 :         uint64_t b = mbedtls_get_unaligned_uint64(src2 + i) & not_mask;
+     200                 :    4591879 :         mbedtls_put_unaligned_uint64(dest + i, a | b);
+     201                 :            :     }
+     202                 :            : #else
+     203                 :            :     for (; (i + 4) <= len; i += 4) {
+     204                 :            :         uint32_t a = mbedtls_get_unaligned_uint32(src1 + i) & mask;
+     205                 :            :         uint32_t b = mbedtls_get_unaligned_uint32(src2 + i) & not_mask;
+     206                 :            :         mbedtls_put_unaligned_uint32(dest + i, a | b);
+     207                 :            :     }
+     208                 :            : #endif /* defined(MBEDTLS_CT_SIZE_64) */
+     209                 :            : #endif /* MBEDTLS_EFFICIENT_UNALIGNED_ACCESS */
+     210         [ -  + ]:     155964 :     for (; i < len; i++) {
+     211                 :          0 :         dest[i] = (src1[i] & mask) | (src2[i] & not_mask);
+     212                 :            :     }
+     213                 :     155964 : }
+     214                 :            : 
+     215                 :          0 : void mbedtls_ct_memcpy_offset(unsigned char *dest,
+     216                 :            :                               const unsigned char *src,
+     217                 :            :                               size_t offset,
+     218                 :            :                               size_t offset_min,
+     219                 :            :                               size_t offset_max,
+     220                 :            :                               size_t len)
+     221                 :            : {
+     222                 :            :     size_t offsetval;
+     223                 :            : 
+     224         [ #  # ]:          0 :     for (offsetval = offset_min; offsetval <= offset_max; offsetval++) {
+     225                 :          0 :         mbedtls_ct_memcpy_if(mbedtls_ct_uint_eq(offsetval, offset), dest, src + offsetval, NULL,
+     226                 :            :                              len);
+     227                 :            :     }
+     228                 :          0 : }
+     229                 :            : 
+     230                 :            : #if defined(MBEDTLS_PKCS1_V15) && defined(MBEDTLS_RSA_C) && !defined(MBEDTLS_RSA_ALT)
+     231                 :            : 
+     232                 :          0 : void mbedtls_ct_zeroize_if(mbedtls_ct_condition_t condition, void *buf, size_t len)
+     233                 :            : {
+     234                 :          0 :     uint32_t mask = (uint32_t) ~condition;
+     235                 :          0 :     uint8_t *p = (uint8_t *) buf;
+     236                 :          0 :     size_t i = 0;
+     237                 :            : #if defined(MBEDTLS_EFFICIENT_UNALIGNED_ACCESS)
+     238         [ #  # ]:          0 :     for (; (i + 4) <= len; i += 4) {
+     239                 :          0 :         mbedtls_put_unaligned_uint32((void *) (p + i),
+     240                 :          0 :                                      mbedtls_get_unaligned_uint32((void *) (p + i)) & mask);
+     241                 :            :     }
+     242                 :            : #endif
+     243         [ #  # ]:          0 :     for (; i < len; i++) {
+     244                 :          0 :         p[i] = p[i] & mask;
+     245                 :            :     }
+     246                 :          0 : }
+     247                 :            : 
+     248                 :            : #endif /* defined(MBEDTLS_PKCS1_V15) && defined(MBEDTLS_RSA_C) && !defined(MBEDTLS_RSA_ALT) */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/constant_time_impl.h.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/constant_time_impl.h.func-sort-c.html new file mode 100644 index 00000000000..5c39dd70ceb --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/constant_time_impl.h.func-sort-c.html @@ -0,0 +1,161 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/constant_time_impl.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - constant_time_impl.h (source / functions)HitTotalCoverage
Test:coverage.infoLines:375074.0 %
Date:2024-09-22 08:21:07Functions:142070.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_ct_bool_ne0
mbedtls_ct_error_if0
mbedtls_ct_error_if_else_00
mbedtls_ct_size_if_else_00
mbedtls_ct_uint_gt0
mbedtls_ct_uint_if_else_00
mbedtls_ct_uint_ge1162
mbedtls_ct_bool_and5866
mbedtls_ct_uint_lt10570
mbedtls_ct_mpi_uint_if_else_015870
mbedtls_ct_bool_or18816
mbedtls_ct_uint_eq263152
mbedtls_ct_uint_ne263152
mbedtls_ct_uchar_in_range_if962280
mbedtls_ct_compiler_opaque2614962
mbedtls_ct_uint_if4606486
mbedtls_ct_bool_not4611190
mbedtls_ct_bool5029144
mbedtls_ct_mpi_uint_if25009880
mbedtls_ct_if29616366
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/constant_time_impl.h.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/constant_time_impl.h.func.html new file mode 100644 index 00000000000..2388ee8fb6b --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/constant_time_impl.h.func.html @@ -0,0 +1,161 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/constant_time_impl.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - constant_time_impl.h (source / functions)HitTotalCoverage
Test:coverage.infoLines:375074.0 %
Date:2024-09-22 08:21:07Functions:142070.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_ct_bool5029144
mbedtls_ct_bool_and5866
mbedtls_ct_bool_ne0
mbedtls_ct_bool_not4611190
mbedtls_ct_bool_or18816
mbedtls_ct_compiler_opaque2614962
mbedtls_ct_error_if0
mbedtls_ct_error_if_else_00
mbedtls_ct_if29616366
mbedtls_ct_mpi_uint_if25009880
mbedtls_ct_mpi_uint_if_else_015870
mbedtls_ct_size_if_else_00
mbedtls_ct_uchar_in_range_if962280
mbedtls_ct_uint_eq263152
mbedtls_ct_uint_ge1162
mbedtls_ct_uint_gt0
mbedtls_ct_uint_if4606486
mbedtls_ct_uint_if_else_00
mbedtls_ct_uint_lt10570
mbedtls_ct_uint_ne263152
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/constant_time_impl.h.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/constant_time_impl.h.gcov.html new file mode 100644 index 00000000000..1df38bf8a83 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/constant_time_impl.h.gcov.html @@ -0,0 +1,641 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/constant_time_impl.h + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - constant_time_impl.h (source / functions)HitTotalCoverage
Test:coverage.infoLines:375074.0 %
Date:2024-09-22 08:21:07Functions:142070.0 %
Branches:00-
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Constant-time functions
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  */
+       7                 :            : 
+       8                 :            : #ifndef MBEDTLS_CONSTANT_TIME_IMPL_H
+       9                 :            : #define MBEDTLS_CONSTANT_TIME_IMPL_H
+      10                 :            : 
+      11                 :            : #include <stddef.h>
+      12                 :            : 
+      13                 :            : #include "common.h"
+      14                 :            : 
+      15                 :            : #if defined(MBEDTLS_BIGNUM_C)
+      16                 :            : #include "mbedtls/bignum.h"
+      17                 :            : #endif
+      18                 :            : 
+      19                 :            : /*
+      20                 :            :  * To improve readability of constant_time_internal.h, the static inline
+      21                 :            :  * definitions are here, and constant_time_internal.h has only the declarations.
+      22                 :            :  *
+      23                 :            :  * This results in duplicate declarations of the form:
+      24                 :            :  *     static inline void f();         // from constant_time_internal.h
+      25                 :            :  *     static inline void f() { ... }  // from constant_time_impl.h
+      26                 :            :  * when constant_time_internal.h is included.
+      27                 :            :  *
+      28                 :            :  * This appears to behave as if the declaration-without-definition was not present
+      29                 :            :  * (except for warnings if gcc -Wredundant-decls or similar is used).
+      30                 :            :  *
+      31                 :            :  * Disable -Wredundant-decls so that gcc does not warn about this. This is re-enabled
+      32                 :            :  * at the bottom of this file.
+      33                 :            :  */
+      34                 :            : #if defined(MBEDTLS_COMPILER_IS_GCC) && (__GNUC__ > 4)
+      35                 :            :     #pragma GCC diagnostic push
+      36                 :            :     #pragma GCC diagnostic ignored "-Wredundant-decls"
+      37                 :            : #endif
+      38                 :            : 
+      39                 :            : /* Disable asm under Memsan because it confuses Memsan and generates false errors.
+      40                 :            :  *
+      41                 :            :  * We also disable under Valgrind by default, because it's more useful
+      42                 :            :  * for Valgrind to test the plain C implementation. MBEDTLS_TEST_CONSTANT_FLOW_ASM //no-check-names
+      43                 :            :  * may be set to permit building asm under Valgrind.
+      44                 :            :  */
+      45                 :            : #if defined(MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN) || \
+      46                 :            :     (defined(MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND) && !defined(MBEDTLS_TEST_CONSTANT_FLOW_ASM)) //no-check-names
+      47                 :            : #define MBEDTLS_CT_NO_ASM
+      48                 :            : #elif defined(__has_feature)
+      49                 :            : #if __has_feature(memory_sanitizer)
+      50                 :            : #define MBEDTLS_CT_NO_ASM
+      51                 :            : #endif
+      52                 :            : #endif
+      53                 :            : 
+      54                 :            : /* armcc5 --gnu defines __GNUC__ but doesn't support GNU's extended asm */
+      55                 :            : #if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && (!defined(__ARMCC_VERSION) || \
+      56                 :            :     __ARMCC_VERSION >= 6000000) && !defined(MBEDTLS_CT_NO_ASM)
+      57                 :            : #define MBEDTLS_CT_ASM
+      58                 :            : #if (defined(__arm__) || defined(__thumb__) || defined(__thumb2__))
+      59                 :            : #define MBEDTLS_CT_ARM_ASM
+      60                 :            : #elif defined(__aarch64__)
+      61                 :            : #define MBEDTLS_CT_AARCH64_ASM
+      62                 :            : #elif defined(__amd64__) || defined(__x86_64__)
+      63                 :            : #define MBEDTLS_CT_X86_64_ASM
+      64                 :            : #elif defined(__i386__)
+      65                 :            : #define MBEDTLS_CT_X86_ASM
+      66                 :            : #endif
+      67                 :            : #endif
+      68                 :            : 
+      69                 :            : #define MBEDTLS_CT_SIZE (sizeof(mbedtls_ct_uint_t) * 8)
+      70                 :            : 
+      71                 :            : 
+      72                 :            : /* ============================================================================
+      73                 :            :  * Core const-time primitives
+      74                 :            :  */
+      75                 :            : 
+      76                 :            : /* Ensure that the compiler cannot know the value of x (i.e., cannot optimise
+      77                 :            :  * based on its value) after this function is called.
+      78                 :            :  *
+      79                 :            :  * If we are not using assembly, this will be fairly inefficient, so its use
+      80                 :            :  * should be minimised.
+      81                 :            :  */
+      82                 :            : 
+      83                 :            : #if !defined(MBEDTLS_CT_ASM)
+      84                 :            : extern volatile mbedtls_ct_uint_t mbedtls_ct_zero;
+      85                 :            : #endif
+      86                 :            : 
+      87                 :            : /**
+      88                 :            :  * \brief   Ensure that a value cannot be known at compile time.
+      89                 :            :  *
+      90                 :            :  * \param x        The value to hide from the compiler.
+      91                 :            :  * \return         The same value that was passed in, such that the compiler
+      92                 :            :  *                 cannot prove its value (even for calls of the form
+      93                 :            :  *                 x = mbedtls_ct_compiler_opaque(1), x will be unknown).
+      94                 :            :  *
+      95                 :            :  * \note           This is mainly used in constructing mbedtls_ct_condition_t
+      96                 :            :  *                 values and performing operations over them, to ensure that
+      97                 :            :  *                 there is no way for the compiler to ever know anything about
+      98                 :            :  *                 the value of an mbedtls_ct_condition_t.
+      99                 :            :  */
+     100                 :    2614962 : static inline mbedtls_ct_uint_t mbedtls_ct_compiler_opaque(mbedtls_ct_uint_t x)
+     101                 :            : {
+     102                 :            : #if defined(MBEDTLS_CT_ASM)
+     103                 :    2614962 :     asm volatile ("" : [x] "+r" (x) :);
+     104                 :    2614962 :     return x;
+     105                 :            : #else
+     106                 :            :     return x ^ mbedtls_ct_zero;
+     107                 :            : #endif
+     108                 :            : }
+     109                 :            : 
+     110                 :            : /*
+     111                 :            :  * Selecting unified syntax is needed for gcc, and harmless on clang.
+     112                 :            :  *
+     113                 :            :  * This is needed because on Thumb 1, condition flags are always set, so
+     114                 :            :  * e.g. "negs" is supported but "neg" is not (on Thumb 2, both exist).
+     115                 :            :  *
+     116                 :            :  * Under Thumb 1 unified syntax, only the "negs" form is accepted, and
+     117                 :            :  * under divided syntax, only the "neg" form is accepted. clang only
+     118                 :            :  * supports unified syntax.
+     119                 :            :  *
+     120                 :            :  * On Thumb 2 and Arm, both compilers are happy with the "s" suffix,
+     121                 :            :  * although we don't actually care about setting the flags.
+     122                 :            :  *
+     123                 :            :  * For old versions of gcc (see #8516 for details), restore divided
+     124                 :            :  * syntax afterwards - otherwise old versions of gcc seem to apply
+     125                 :            :  * unified syntax globally, which breaks other asm code.
+     126                 :            :  */
+     127                 :            : #if defined(MBEDTLS_COMPILER_IS_GCC) && defined(__thumb__) && !defined(__thumb2__) && \
+     128                 :            :     (__GNUC__ < 11) && !defined(__ARM_ARCH_2__)
+     129                 :            : #define RESTORE_ASM_SYNTAX  ".syntax divided                      \n\t"
+     130                 :            : #else
+     131                 :            : #define RESTORE_ASM_SYNTAX
+     132                 :            : #endif
+     133                 :            : 
+     134                 :            : /* Convert a number into a condition in constant time. */
+     135                 :    5029144 : static inline mbedtls_ct_condition_t mbedtls_ct_bool(mbedtls_ct_uint_t x)
+     136                 :            : {
+     137                 :            :     /*
+     138                 :            :      * Define mask-generation code that, as far as possible, will not use branches or conditional instructions.
+     139                 :            :      *
+     140                 :            :      * For some platforms / type sizes, we define assembly to assure this.
+     141                 :            :      *
+     142                 :            :      * Otherwise, we define a plain C fallback which (in May 2023) does not get optimised into
+     143                 :            :      * conditional instructions or branches by trunk clang, gcc, or MSVC v19.
+     144                 :            :      */
+     145                 :            : #if defined(MBEDTLS_CT_AARCH64_ASM) && (defined(MBEDTLS_CT_SIZE_32) || defined(MBEDTLS_CT_SIZE_64))
+     146                 :            :     mbedtls_ct_uint_t s;
+     147                 :            :     asm volatile ("neg %x[s], %x[x]                               \n\t"
+     148                 :            :                   "orr %x[x], %x[s], %x[x]                        \n\t"
+     149                 :            :                   "asr %x[x], %x[x], 63                           \n\t"
+     150                 :            :                   :
+     151                 :            :                   [s] "=&r" (s),
+     152                 :            :                   [x] "+&r" (x)
+     153                 :            :                   :
+     154                 :            :                   :
+     155                 :            :                   );
+     156                 :            :     return (mbedtls_ct_condition_t) x;
+     157                 :            : #elif defined(MBEDTLS_CT_ARM_ASM) && defined(MBEDTLS_CT_SIZE_32)
+     158                 :            :     uint32_t s;
+     159                 :            :     asm volatile (".syntax unified                                \n\t"
+     160                 :            :                   "negs %[s], %[x]                                \n\t"
+     161                 :            :                   "orrs %[x], %[x], %[s]                          \n\t"
+     162                 :            :                   "asrs %[x], %[x], #31                           \n\t"
+     163                 :            :                   RESTORE_ASM_SYNTAX
+     164                 :            :                   :
+     165                 :            :                   [s] "=&l" (s),
+     166                 :            :                   [x] "+&l" (x)
+     167                 :            :                   :
+     168                 :            :                   :
+     169                 :            :                   "cc" /* clobbers flag bits */
+     170                 :            :                   );
+     171                 :            :     return (mbedtls_ct_condition_t) x;
+     172                 :            : #elif defined(MBEDTLS_CT_X86_64_ASM) && (defined(MBEDTLS_CT_SIZE_32) || defined(MBEDTLS_CT_SIZE_64))
+     173                 :            :     uint64_t s;
+     174                 :    5029144 :     asm volatile ("mov  %[x], %[s]                                \n\t"
+     175                 :            :                   "neg  %[s]                                      \n\t"
+     176                 :            :                   "or   %[x], %[s]                                \n\t"
+     177                 :            :                   "sar  $63, %[s]                                 \n\t"
+     178                 :            :                   :
+     179                 :            :                   [s] "=&a" (s)
+     180                 :            :                   :
+     181                 :            :                   [x] "D" (x)
+     182                 :            :                   :
+     183                 :            :                   );
+     184                 :    5029144 :     return (mbedtls_ct_condition_t) s;
+     185                 :            : #elif defined(MBEDTLS_CT_X86_ASM) && defined(MBEDTLS_CT_SIZE_32)
+     186                 :            :     uint32_t s;
+     187                 :            :     asm volatile ("mov %[x], %[s]                                 \n\t"
+     188                 :            :                   "neg %[s]                                       \n\t"
+     189                 :            :                   "or %[s], %[x]                                  \n\t"
+     190                 :            :                   "sar $31, %[x]                                  \n\t"
+     191                 :            :                   :
+     192                 :            :                   [s] "=&c" (s),
+     193                 :            :                   [x] "+&a" (x)
+     194                 :            :                   :
+     195                 :            :                   :
+     196                 :            :                   );
+     197                 :            :     return (mbedtls_ct_condition_t) x;
+     198                 :            : #else
+     199                 :            :     const mbedtls_ct_uint_t xo = mbedtls_ct_compiler_opaque(x);
+     200                 :            : #if defined(_MSC_VER)
+     201                 :            :     /* MSVC has a warning about unary minus on unsigned, but this is
+     202                 :            :      * well-defined and precisely what we want to do here */
+     203                 :            : #pragma warning( push )
+     204                 :            : #pragma warning( disable : 4146 )
+     205                 :            : #endif
+     206                 :            :     // y is negative (i.e., top bit set) iff x is non-zero
+     207                 :            :     mbedtls_ct_int_t y = (-xo) | -(xo >> 1);
+     208                 :            : 
+     209                 :            :     // extract only the sign bit of y so that y == 1 (if x is non-zero) or 0 (if x is zero)
+     210                 :            :     y = (((mbedtls_ct_uint_t) y) >> (MBEDTLS_CT_SIZE - 1));
+     211                 :            : 
+     212                 :            :     // -y has all bits set (if x is non-zero), or all bits clear (if x is zero)
+     213                 :            :     return (mbedtls_ct_condition_t) (-y);
+     214                 :            : #if defined(_MSC_VER)
+     215                 :            : #pragma warning( pop )
+     216                 :            : #endif
+     217                 :            : #endif
+     218                 :            : }
+     219                 :            : 
+     220                 :   29616366 : static inline mbedtls_ct_uint_t mbedtls_ct_if(mbedtls_ct_condition_t condition,
+     221                 :            :                                               mbedtls_ct_uint_t if1,
+     222                 :            :                                               mbedtls_ct_uint_t if0)
+     223                 :            : {
+     224                 :            : #if defined(MBEDTLS_CT_AARCH64_ASM) && (defined(MBEDTLS_CT_SIZE_32) || defined(MBEDTLS_CT_SIZE_64))
+     225                 :            :     asm volatile ("and %x[if1], %x[if1], %x[condition]            \n\t"
+     226                 :            :                   "mvn %x[condition], %x[condition]               \n\t"
+     227                 :            :                   "and %x[condition], %x[condition], %x[if0]      \n\t"
+     228                 :            :                   "orr %x[condition], %x[if1], %x[condition]"
+     229                 :            :                   :
+     230                 :            :                   [condition] "+&r" (condition),
+     231                 :            :                   [if1] "+&r" (if1)
+     232                 :            :                   :
+     233                 :            :                   [if0] "r" (if0)
+     234                 :            :                   :
+     235                 :            :                   );
+     236                 :            :     return (mbedtls_ct_uint_t) condition;
+     237                 :            : #elif defined(MBEDTLS_CT_ARM_ASM) && defined(MBEDTLS_CT_SIZE_32)
+     238                 :            :     asm volatile (".syntax unified                                \n\t"
+     239                 :            :                   "ands %[if1], %[if1], %[condition]              \n\t"
+     240                 :            :                   "mvns %[condition], %[condition]                \n\t"
+     241                 :            :                   "ands %[condition], %[condition], %[if0]        \n\t"
+     242                 :            :                   "orrs %[condition], %[if1], %[condition]        \n\t"
+     243                 :            :                   RESTORE_ASM_SYNTAX
+     244                 :            :                   :
+     245                 :            :                   [condition] "+&l" (condition),
+     246                 :            :                   [if1] "+&l" (if1)
+     247                 :            :                   :
+     248                 :            :                   [if0] "l" (if0)
+     249                 :            :                   :
+     250                 :            :                   "cc"
+     251                 :            :                   );
+     252                 :            :     return (mbedtls_ct_uint_t) condition;
+     253                 :            : #elif defined(MBEDTLS_CT_X86_64_ASM) && (defined(MBEDTLS_CT_SIZE_32) || defined(MBEDTLS_CT_SIZE_64))
+     254                 :   29616366 :     asm volatile ("and  %[condition], %[if1]                      \n\t"
+     255                 :            :                   "not  %[condition]                              \n\t"
+     256                 :            :                   "and  %[condition], %[if0]                      \n\t"
+     257                 :            :                   "or   %[if1], %[if0]                            \n\t"
+     258                 :            :                   :
+     259                 :            :                   [condition] "+&D" (condition),
+     260                 :            :                   [if1] "+&S" (if1),
+     261                 :            :                   [if0] "+&a" (if0)
+     262                 :            :                   :
+     263                 :            :                   :
+     264                 :            :                   );
+     265                 :   29616366 :     return if0;
+     266                 :            : #elif defined(MBEDTLS_CT_X86_ASM) && defined(MBEDTLS_CT_SIZE_32)
+     267                 :            :     asm volatile ("and %[condition], %[if1]                       \n\t"
+     268                 :            :                   "not %[condition]                               \n\t"
+     269                 :            :                   "and %[if0], %[condition]                       \n\t"
+     270                 :            :                   "or %[condition], %[if1]                        \n\t"
+     271                 :            :                   :
+     272                 :            :                   [condition] "+&c" (condition),
+     273                 :            :                   [if1] "+&a" (if1)
+     274                 :            :                   :
+     275                 :            :                   [if0] "b" (if0)
+     276                 :            :                   :
+     277                 :            :                   );
+     278                 :            :     return if1;
+     279                 :            : #else
+     280                 :            :     mbedtls_ct_condition_t not_cond =
+     281                 :            :         (mbedtls_ct_condition_t) (~mbedtls_ct_compiler_opaque(condition));
+     282                 :            :     return (mbedtls_ct_uint_t) ((condition & if1) | (not_cond & if0));
+     283                 :            : #endif
+     284                 :            : }
+     285                 :            : 
+     286                 :      10570 : static inline mbedtls_ct_condition_t mbedtls_ct_uint_lt(mbedtls_ct_uint_t x, mbedtls_ct_uint_t y)
+     287                 :            : {
+     288                 :            : #if defined(MBEDTLS_CT_AARCH64_ASM) && (defined(MBEDTLS_CT_SIZE_32) || defined(MBEDTLS_CT_SIZE_64))
+     289                 :            :     uint64_t s1;
+     290                 :            :     asm volatile ("eor     %x[s1], %x[y], %x[x]                   \n\t"
+     291                 :            :                   "sub     %x[x], %x[x], %x[y]                    \n\t"
+     292                 :            :                   "bic     %x[x], %x[x], %x[s1]                   \n\t"
+     293                 :            :                   "and     %x[s1], %x[s1], %x[y]                  \n\t"
+     294                 :            :                   "orr     %x[s1], %x[x], %x[s1]                  \n\t"
+     295                 :            :                   "asr     %x[x], %x[s1], 63"
+     296                 :            :                   :
+     297                 :            :                   [s1] "=&r" (s1),
+     298                 :            :                   [x] "+&r" (x)
+     299                 :            :                   :
+     300                 :            :                   [y] "r" (y)
+     301                 :            :                   :
+     302                 :            :                   );
+     303                 :            :     return (mbedtls_ct_condition_t) x;
+     304                 :            : #elif defined(MBEDTLS_CT_ARM_ASM) && defined(MBEDTLS_CT_SIZE_32)
+     305                 :            :     uint32_t s1;
+     306                 :            :     asm volatile (
+     307                 :            :         ".syntax unified                                          \n\t"
+     308                 :            : #if defined(__thumb__) && !defined(__thumb2__)
+     309                 :            :         "movs     %[s1], %[x]                                     \n\t"
+     310                 :            :         "eors     %[s1], %[s1], %[y]                              \n\t"
+     311                 :            : #else
+     312                 :            :         "eors     %[s1], %[x], %[y]                               \n\t"
+     313                 :            : #endif
+     314                 :            :         "subs    %[x], %[x], %[y]                                 \n\t"
+     315                 :            :         "bics    %[x], %[x], %[s1]                                \n\t"
+     316                 :            :         "ands    %[y], %[s1], %[y]                                \n\t"
+     317                 :            :         "orrs    %[x], %[x], %[y]                                 \n\t"
+     318                 :            :         "asrs    %[x], %[x], #31                                  \n\t"
+     319                 :            :         RESTORE_ASM_SYNTAX
+     320                 :            :         :
+     321                 :            :         [s1] "=&l" (s1),
+     322                 :            :         [x] "+&l" (x),
+     323                 :            :         [y] "+&l" (y)
+     324                 :            :         :
+     325                 :            :         :
+     326                 :            :         "cc"
+     327                 :            :         );
+     328                 :            :     return (mbedtls_ct_condition_t) x;
+     329                 :            : #elif defined(MBEDTLS_CT_X86_64_ASM) && (defined(MBEDTLS_CT_SIZE_32) || defined(MBEDTLS_CT_SIZE_64))
+     330                 :            :     uint64_t s;
+     331                 :      10570 :     asm volatile ("mov %[x], %[s]                                 \n\t"
+     332                 :            :                   "xor %[y], %[s]                                 \n\t"
+     333                 :            :                   "sub %[y], %[x]                                 \n\t"
+     334                 :            :                   "and %[s], %[y]                                 \n\t"
+     335                 :            :                   "not %[s]                                       \n\t"
+     336                 :            :                   "and %[s], %[x]                                 \n\t"
+     337                 :            :                   "or %[y], %[x]                                  \n\t"
+     338                 :            :                   "sar $63, %[x]                                  \n\t"
+     339                 :            :                   :
+     340                 :            :                   [s] "=&a" (s),
+     341                 :            :                   [x] "+&D" (x),
+     342                 :            :                   [y] "+&S" (y)
+     343                 :            :                   :
+     344                 :            :                   :
+     345                 :            :                   );
+     346                 :      10570 :     return (mbedtls_ct_condition_t) x;
+     347                 :            : #elif defined(MBEDTLS_CT_X86_ASM) && defined(MBEDTLS_CT_SIZE_32)
+     348                 :            :     uint32_t s;
+     349                 :            :     asm volatile ("mov %[x], %[s]                                 \n\t"
+     350                 :            :                   "xor %[y], %[s]                                 \n\t"
+     351                 :            :                   "sub %[y], %[x]                                 \n\t"
+     352                 :            :                   "and %[s], %[y]                                 \n\t"
+     353                 :            :                   "not %[s]                                       \n\t"
+     354                 :            :                   "and %[s], %[x]                                 \n\t"
+     355                 :            :                   "or  %[y], %[x]                                 \n\t"
+     356                 :            :                   "sar $31, %[x]                                  \n\t"
+     357                 :            :                   :
+     358                 :            :                   [s] "=&b" (s),
+     359                 :            :                   [x] "+&a" (x),
+     360                 :            :                   [y] "+&c" (y)
+     361                 :            :                   :
+     362                 :            :                   :
+     363                 :            :                   );
+     364                 :            :     return (mbedtls_ct_condition_t) x;
+     365                 :            : #else
+     366                 :            :     /* Ensure that the compiler cannot optimise the following operations over x and y,
+     367                 :            :      * even if it knows the value of x and y.
+     368                 :            :      */
+     369                 :            :     const mbedtls_ct_uint_t xo = mbedtls_ct_compiler_opaque(x);
+     370                 :            :     const mbedtls_ct_uint_t yo = mbedtls_ct_compiler_opaque(y);
+     371                 :            :     /*
+     372                 :            :      * Check if the most significant bits (MSB) of the operands are different.
+     373                 :            :      * cond is true iff the MSBs differ.
+     374                 :            :      */
+     375                 :            :     mbedtls_ct_condition_t cond = mbedtls_ct_bool((xo ^ yo) >> (MBEDTLS_CT_SIZE - 1));
+     376                 :            : 
+     377                 :            :     /*
+     378                 :            :      * If the MSB are the same then the difference x-y will be negative (and
+     379                 :            :      * have its MSB set to 1 during conversion to unsigned) if and only if x<y.
+     380                 :            :      *
+     381                 :            :      * If the MSB are different, then the operand with the MSB of 1 is the
+     382                 :            :      * bigger. (That is if y has MSB of 1, then x<y is true and it is false if
+     383                 :            :      * the MSB of y is 0.)
+     384                 :            :      */
+     385                 :            : 
+     386                 :            :     // Select either y, or x - y
+     387                 :            :     mbedtls_ct_uint_t ret = mbedtls_ct_if(cond, yo, (mbedtls_ct_uint_t) (xo - yo));
+     388                 :            : 
+     389                 :            :     // Extract only the MSB of ret
+     390                 :            :     ret = ret >> (MBEDTLS_CT_SIZE - 1);
+     391                 :            : 
+     392                 :            :     // Convert to a condition (i.e., all bits set iff non-zero)
+     393                 :            :     return mbedtls_ct_bool(ret);
+     394                 :            : #endif
+     395                 :            : }
+     396                 :            : 
+     397                 :     263152 : static inline mbedtls_ct_condition_t mbedtls_ct_uint_ne(mbedtls_ct_uint_t x, mbedtls_ct_uint_t y)
+     398                 :            : {
+     399                 :            :     /* diff = 0 if x == y, non-zero otherwise */
+     400                 :     263152 :     const mbedtls_ct_uint_t diff = mbedtls_ct_compiler_opaque(x) ^ mbedtls_ct_compiler_opaque(y);
+     401                 :            : 
+     402                 :            :     /* all ones if x != y, 0 otherwise */
+     403                 :     263152 :     return mbedtls_ct_bool(diff);
+     404                 :            : }
+     405                 :            : 
+     406                 :     962280 : static inline unsigned char mbedtls_ct_uchar_in_range_if(unsigned char low,
+     407                 :            :                                                          unsigned char high,
+     408                 :            :                                                          unsigned char c,
+     409                 :            :                                                          unsigned char t)
+     410                 :            : {
+     411                 :     962280 :     const unsigned char co = (unsigned char) mbedtls_ct_compiler_opaque(c);
+     412                 :     962280 :     const unsigned char to = (unsigned char) mbedtls_ct_compiler_opaque(t);
+     413                 :            : 
+     414                 :            :     /* low_mask is: 0 if low <= c, 0x...ff if low > c */
+     415                 :     962280 :     unsigned low_mask = ((unsigned) co - low) >> 8;
+     416                 :            :     /* high_mask is: 0 if c <= high, 0x...ff if c > high */
+     417                 :     962280 :     unsigned high_mask = ((unsigned) high - co) >> 8;
+     418                 :            : 
+     419                 :     962280 :     return (unsigned char) (~(low_mask | high_mask)) & to;
+     420                 :            : }
+     421                 :            : 
+     422                 :            : /* ============================================================================
+     423                 :            :  * Everything below here is trivial wrapper functions
+     424                 :            :  */
+     425                 :            : 
+     426                 :            : static inline size_t mbedtls_ct_size_if(mbedtls_ct_condition_t condition,
+     427                 :            :                                         size_t if1,
+     428                 :            :                                         size_t if0)
+     429                 :            : {
+     430                 :            :     return (size_t) mbedtls_ct_if(condition, (mbedtls_ct_uint_t) if1, (mbedtls_ct_uint_t) if0);
+     431                 :            : }
+     432                 :            : 
+     433                 :    4606486 : static inline unsigned mbedtls_ct_uint_if(mbedtls_ct_condition_t condition,
+     434                 :            :                                           unsigned if1,
+     435                 :            :                                           unsigned if0)
+     436                 :            : {
+     437                 :    4606486 :     return (unsigned) mbedtls_ct_if(condition, (mbedtls_ct_uint_t) if1, (mbedtls_ct_uint_t) if0);
+     438                 :            : }
+     439                 :            : 
+     440                 :            : static inline mbedtls_ct_condition_t mbedtls_ct_bool_if(mbedtls_ct_condition_t condition,
+     441                 :            :                                                         mbedtls_ct_condition_t if1,
+     442                 :            :                                                         mbedtls_ct_condition_t if0)
+     443                 :            : {
+     444                 :            :     return (mbedtls_ct_condition_t) mbedtls_ct_if(condition, (mbedtls_ct_uint_t) if1,
+     445                 :            :                                                   (mbedtls_ct_uint_t) if0);
+     446                 :            : }
+     447                 :            : 
+     448                 :            : #if defined(MBEDTLS_BIGNUM_C)
+     449                 :            : 
+     450                 :   25009880 : static inline mbedtls_mpi_uint mbedtls_ct_mpi_uint_if(mbedtls_ct_condition_t condition,
+     451                 :            :                                                       mbedtls_mpi_uint if1,
+     452                 :            :                                                       mbedtls_mpi_uint if0)
+     453                 :            : {
+     454                 :   25009880 :     return (mbedtls_mpi_uint) mbedtls_ct_if(condition,
+     455                 :            :                                             (mbedtls_ct_uint_t) if1,
+     456                 :            :                                             (mbedtls_ct_uint_t) if0);
+     457                 :            : }
+     458                 :            : 
+     459                 :            : #endif
+     460                 :            : 
+     461                 :          0 : static inline size_t mbedtls_ct_size_if_else_0(mbedtls_ct_condition_t condition, size_t if1)
+     462                 :            : {
+     463                 :          0 :     return (size_t) (condition & if1);
+     464                 :            : }
+     465                 :            : 
+     466                 :          0 : static inline unsigned mbedtls_ct_uint_if_else_0(mbedtls_ct_condition_t condition, unsigned if1)
+     467                 :            : {
+     468                 :          0 :     return (unsigned) (condition & if1);
+     469                 :            : }
+     470                 :            : 
+     471                 :            : static inline mbedtls_ct_condition_t mbedtls_ct_bool_if_else_0(mbedtls_ct_condition_t condition,
+     472                 :            :                                                                mbedtls_ct_condition_t if1)
+     473                 :            : {
+     474                 :            :     return (mbedtls_ct_condition_t) (condition & if1);
+     475                 :            : }
+     476                 :            : 
+     477                 :            : #if defined(MBEDTLS_BIGNUM_C)
+     478                 :            : 
+     479                 :      15870 : static inline mbedtls_mpi_uint mbedtls_ct_mpi_uint_if_else_0(mbedtls_ct_condition_t condition,
+     480                 :            :                                                              mbedtls_mpi_uint if1)
+     481                 :            : {
+     482                 :      15870 :     return (mbedtls_mpi_uint) (condition & if1);
+     483                 :            : }
+     484                 :            : 
+     485                 :            : #endif /* MBEDTLS_BIGNUM_C */
+     486                 :            : 
+     487                 :          0 : static inline int mbedtls_ct_error_if(mbedtls_ct_condition_t condition, int if1, int if0)
+     488                 :            : {
+     489                 :            :     /* Coverting int -> uint -> int here is safe, because we require if1 and if0 to be
+     490                 :            :      * in the range -32767..0, and we require 32-bit int and uint types.
+     491                 :            :      *
+     492                 :            :      * This means that (0 <= -if0 < INT_MAX), so negating if0 is safe, and similarly for
+     493                 :            :      * converting back to int.
+     494                 :            :      */
+     495                 :          0 :     return -((int) mbedtls_ct_if(condition, (mbedtls_ct_uint_t) (-if1),
+     496                 :          0 :                                  (mbedtls_ct_uint_t) (-if0)));
+     497                 :            : }
+     498                 :            : 
+     499                 :          0 : static inline int mbedtls_ct_error_if_else_0(mbedtls_ct_condition_t condition, int if1)
+     500                 :            : {
+     501                 :          0 :     return -((int) (condition & (-if1)));
+     502                 :            : }
+     503                 :            : 
+     504                 :     263152 : static inline mbedtls_ct_condition_t mbedtls_ct_uint_eq(mbedtls_ct_uint_t x,
+     505                 :            :                                                         mbedtls_ct_uint_t y)
+     506                 :            : {
+     507                 :     263152 :     return ~mbedtls_ct_uint_ne(x, y);
+     508                 :            : }
+     509                 :            : 
+     510                 :          0 : static inline mbedtls_ct_condition_t mbedtls_ct_uint_gt(mbedtls_ct_uint_t x,
+     511                 :            :                                                         mbedtls_ct_uint_t y)
+     512                 :            : {
+     513                 :          0 :     return mbedtls_ct_uint_lt(y, x);
+     514                 :            : }
+     515                 :            : 
+     516                 :       1162 : static inline mbedtls_ct_condition_t mbedtls_ct_uint_ge(mbedtls_ct_uint_t x,
+     517                 :            :                                                         mbedtls_ct_uint_t y)
+     518                 :            : {
+     519                 :       1162 :     return ~mbedtls_ct_uint_lt(x, y);
+     520                 :            : }
+     521                 :            : 
+     522                 :            : static inline mbedtls_ct_condition_t mbedtls_ct_uint_le(mbedtls_ct_uint_t x,
+     523                 :            :                                                         mbedtls_ct_uint_t y)
+     524                 :            : {
+     525                 :            :     return ~mbedtls_ct_uint_gt(x, y);
+     526                 :            : }
+     527                 :            : 
+     528                 :          0 : static inline mbedtls_ct_condition_t mbedtls_ct_bool_ne(mbedtls_ct_condition_t x,
+     529                 :            :                                                         mbedtls_ct_condition_t y)
+     530                 :            : {
+     531                 :          0 :     return (mbedtls_ct_condition_t) (x ^ y);
+     532                 :            : }
+     533                 :            : 
+     534                 :       5866 : static inline mbedtls_ct_condition_t mbedtls_ct_bool_and(mbedtls_ct_condition_t x,
+     535                 :            :                                                          mbedtls_ct_condition_t y)
+     536                 :            : {
+     537                 :       5866 :     return (mbedtls_ct_condition_t) (x & y);
+     538                 :            : }
+     539                 :            : 
+     540                 :      18816 : static inline mbedtls_ct_condition_t mbedtls_ct_bool_or(mbedtls_ct_condition_t x,
+     541                 :            :                                                         mbedtls_ct_condition_t y)
+     542                 :            : {
+     543                 :      18816 :     return (mbedtls_ct_condition_t) (x | y);
+     544                 :            : }
+     545                 :            : 
+     546                 :    4611190 : static inline mbedtls_ct_condition_t mbedtls_ct_bool_not(mbedtls_ct_condition_t x)
+     547                 :            : {
+     548                 :    4611190 :     return (mbedtls_ct_condition_t) (~x);
+     549                 :            : }
+     550                 :            : 
+     551                 :            : #if defined(MBEDTLS_COMPILER_IS_GCC) && (__GNUC__ > 4)
+     552                 :            : /* Restore warnings for -Wredundant-decls on gcc */
+     553                 :            :     #pragma GCC diagnostic pop
+     554                 :            : #endif
+     555                 :            : 
+     556                 :            : #endif /* MBEDTLS_CONSTANT_TIME_IMPL_H */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/ctr.h.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ctr.h.func-sort-c.html new file mode 100644 index 00000000000..8825cbed7cd --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ctr.h.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/ctr.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - ctr.h (source / functions)HitTotalCoverage
Test:coverage.infoLines:070.0 %
Date:2024-09-22 08:21:07Functions:010.0 %
Branches:040.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_ctr_increment_counter0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/ctr.h.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ctr.h.func.html new file mode 100644 index 00000000000..3be8e6c9a78 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ctr.h.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/ctr.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - ctr.h (source / functions)HitTotalCoverage
Test:coverage.infoLines:070.0 %
Date:2024-09-22 08:21:07Functions:010.0 %
Branches:040.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_ctr_increment_counter0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/ctr.h.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ctr.h.gcov.html new file mode 100644 index 00000000000..01720cc72f7 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ctr.h.gcov.html @@ -0,0 +1,120 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/ctr.h + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - ctr.h (source / functions)HitTotalCoverage
Test:coverage.infoLines:070.0 %
Date:2024-09-22 08:21:07Functions:010.0 %
Branches:040.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  * \file ctr.h
+       3                 :            :  *
+       4                 :            :  * \brief    This file contains common functionality for counter algorithms.
+       5                 :            :  *
+       6                 :            :  *  Copyright The Mbed TLS Contributors
+       7                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       8                 :            :  */
+       9                 :            : 
+      10                 :            : #ifndef MBEDTLS_CTR_H
+      11                 :            : #define MBEDTLS_CTR_H
+      12                 :            : 
+      13                 :            : #include "common.h"
+      14                 :            : 
+      15                 :            : /**
+      16                 :            :  * \brief               Increment a big-endian 16-byte value.
+      17                 :            :  *                      This is quite performance-sensitive for AES-CTR and CTR-DRBG.
+      18                 :            :  *
+      19                 :            :  * \param n             A 16-byte value to be incremented.
+      20                 :            :  */
+      21                 :          0 : static inline void mbedtls_ctr_increment_counter(uint8_t n[16])
+      22                 :            : {
+      23                 :            :     // The 32-bit version seems to perform about the same as a 64-bit version
+      24                 :            :     // on 64-bit architectures, so no need to define a 64-bit version.
+      25                 :          0 :     for (int i = 3;; i--) {
+      26                 :          0 :         uint32_t x = MBEDTLS_GET_UINT32_BE(n, i << 2);
+      27                 :          0 :         x += 1;
+      28                 :          0 :         MBEDTLS_PUT_UINT32_BE(x, n, i << 2);
+      29   [ #  #  #  # ]:          0 :         if (x != 0 || i == 0) {
+      30                 :            :             break;
+      31                 :            :         }
+      32                 :            :     }
+      33                 :          0 : }
+      34                 :            : 
+      35                 :            : #endif /* MBEDTLS_CTR_H */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/des.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/des.c.func-sort-c.html new file mode 100644 index 00000000000..31ef14fdaee --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/des.c.func-sort-c.html @@ -0,0 +1,165 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/des.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - des.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:03210.0 %
Date:2024-09-22 08:21:07Functions:0210.0 %
Branches:01440.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
des3_set2key0
des3_set3key0
mbedtls_des3_crypt_cbc0
mbedtls_des3_crypt_ecb0
mbedtls_des3_free0
mbedtls_des3_init0
mbedtls_des3_set2key_dec0
mbedtls_des3_set2key_enc0
mbedtls_des3_set3key_dec0
mbedtls_des3_set3key_enc0
mbedtls_des_crypt_cbc0
mbedtls_des_crypt_ecb0
mbedtls_des_free0
mbedtls_des_init0
mbedtls_des_key_check_key_parity0
mbedtls_des_key_check_weak0
mbedtls_des_key_set_parity0
mbedtls_des_self_test0
mbedtls_des_setkey0
mbedtls_des_setkey_dec0
mbedtls_des_setkey_enc0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/des.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/des.c.func.html new file mode 100644 index 00000000000..b8e287ca106 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/des.c.func.html @@ -0,0 +1,165 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/des.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - des.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:03210.0 %
Date:2024-09-22 08:21:07Functions:0210.0 %
Branches:01440.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
des3_set2key0
des3_set3key0
mbedtls_des3_crypt_cbc0
mbedtls_des3_crypt_ecb0
mbedtls_des3_free0
mbedtls_des3_init0
mbedtls_des3_set2key_dec0
mbedtls_des3_set2key_enc0
mbedtls_des3_set3key_dec0
mbedtls_des3_set3key_enc0
mbedtls_des_crypt_cbc0
mbedtls_des_crypt_ecb0
mbedtls_des_free0
mbedtls_des_init0
mbedtls_des_key_check_key_parity0
mbedtls_des_key_check_weak0
mbedtls_des_key_set_parity0
mbedtls_des_self_test0
mbedtls_des_setkey0
mbedtls_des_setkey_dec0
mbedtls_des_setkey_enc0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/des.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/des.c.gcov.html new file mode 100644 index 00000000000..a63dbf06f16 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/des.c.gcov.html @@ -0,0 +1,1130 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/des.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - des.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:03210.0 %
Date:2024-09-22 08:21:07Functions:0210.0 %
Branches:01440.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  *  FIPS-46-3 compliant Triple-DES implementation
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  */
+       7                 :            : /*
+       8                 :            :  *  DES, on which TDES is based, was originally designed by Horst Feistel
+       9                 :            :  *  at IBM in 1974, and was adopted as a standard by NIST (formerly NBS).
+      10                 :            :  *
+      11                 :            :  *  http://csrc.nist.gov/publications/fips/fips46-3/fips46-3.pdf
+      12                 :            :  */
+      13                 :            : 
+      14                 :            : #include "common.h"
+      15                 :            : 
+      16                 :            : #if defined(MBEDTLS_DES_C)
+      17                 :            : 
+      18                 :            : #include "mbedtls/des.h"
+      19                 :            : #include "mbedtls/error.h"
+      20                 :            : #include "mbedtls/platform_util.h"
+      21                 :            : 
+      22                 :            : #include <string.h>
+      23                 :            : 
+      24                 :            : #include "mbedtls/platform.h"
+      25                 :            : 
+      26                 :            : #if !defined(MBEDTLS_DES_ALT)
+      27                 :            : 
+      28                 :            : /*
+      29                 :            :  * Expanded DES S-boxes
+      30                 :            :  */
+      31                 :            : static const uint32_t SB1[64] =
+      32                 :            : {
+      33                 :            :     0x01010400, 0x00000000, 0x00010000, 0x01010404,
+      34                 :            :     0x01010004, 0x00010404, 0x00000004, 0x00010000,
+      35                 :            :     0x00000400, 0x01010400, 0x01010404, 0x00000400,
+      36                 :            :     0x01000404, 0x01010004, 0x01000000, 0x00000004,
+      37                 :            :     0x00000404, 0x01000400, 0x01000400, 0x00010400,
+      38                 :            :     0x00010400, 0x01010000, 0x01010000, 0x01000404,
+      39                 :            :     0x00010004, 0x01000004, 0x01000004, 0x00010004,
+      40                 :            :     0x00000000, 0x00000404, 0x00010404, 0x01000000,
+      41                 :            :     0x00010000, 0x01010404, 0x00000004, 0x01010000,
+      42                 :            :     0x01010400, 0x01000000, 0x01000000, 0x00000400,
+      43                 :            :     0x01010004, 0x00010000, 0x00010400, 0x01000004,
+      44                 :            :     0x00000400, 0x00000004, 0x01000404, 0x00010404,
+      45                 :            :     0x01010404, 0x00010004, 0x01010000, 0x01000404,
+      46                 :            :     0x01000004, 0x00000404, 0x00010404, 0x01010400,
+      47                 :            :     0x00000404, 0x01000400, 0x01000400, 0x00000000,
+      48                 :            :     0x00010004, 0x00010400, 0x00000000, 0x01010004
+      49                 :            : };
+      50                 :            : 
+      51                 :            : static const uint32_t SB2[64] =
+      52                 :            : {
+      53                 :            :     0x80108020, 0x80008000, 0x00008000, 0x00108020,
+      54                 :            :     0x00100000, 0x00000020, 0x80100020, 0x80008020,
+      55                 :            :     0x80000020, 0x80108020, 0x80108000, 0x80000000,
+      56                 :            :     0x80008000, 0x00100000, 0x00000020, 0x80100020,
+      57                 :            :     0x00108000, 0x00100020, 0x80008020, 0x00000000,
+      58                 :            :     0x80000000, 0x00008000, 0x00108020, 0x80100000,
+      59                 :            :     0x00100020, 0x80000020, 0x00000000, 0x00108000,
+      60                 :            :     0x00008020, 0x80108000, 0x80100000, 0x00008020,
+      61                 :            :     0x00000000, 0x00108020, 0x80100020, 0x00100000,
+      62                 :            :     0x80008020, 0x80100000, 0x80108000, 0x00008000,
+      63                 :            :     0x80100000, 0x80008000, 0x00000020, 0x80108020,
+      64                 :            :     0x00108020, 0x00000020, 0x00008000, 0x80000000,
+      65                 :            :     0x00008020, 0x80108000, 0x00100000, 0x80000020,
+      66                 :            :     0x00100020, 0x80008020, 0x80000020, 0x00100020,
+      67                 :            :     0x00108000, 0x00000000, 0x80008000, 0x00008020,
+      68                 :            :     0x80000000, 0x80100020, 0x80108020, 0x00108000
+      69                 :            : };
+      70                 :            : 
+      71                 :            : static const uint32_t SB3[64] =
+      72                 :            : {
+      73                 :            :     0x00000208, 0x08020200, 0x00000000, 0x08020008,
+      74                 :            :     0x08000200, 0x00000000, 0x00020208, 0x08000200,
+      75                 :            :     0x00020008, 0x08000008, 0x08000008, 0x00020000,
+      76                 :            :     0x08020208, 0x00020008, 0x08020000, 0x00000208,
+      77                 :            :     0x08000000, 0x00000008, 0x08020200, 0x00000200,
+      78                 :            :     0x00020200, 0x08020000, 0x08020008, 0x00020208,
+      79                 :            :     0x08000208, 0x00020200, 0x00020000, 0x08000208,
+      80                 :            :     0x00000008, 0x08020208, 0x00000200, 0x08000000,
+      81                 :            :     0x08020200, 0x08000000, 0x00020008, 0x00000208,
+      82                 :            :     0x00020000, 0x08020200, 0x08000200, 0x00000000,
+      83                 :            :     0x00000200, 0x00020008, 0x08020208, 0x08000200,
+      84                 :            :     0x08000008, 0x00000200, 0x00000000, 0x08020008,
+      85                 :            :     0x08000208, 0x00020000, 0x08000000, 0x08020208,
+      86                 :            :     0x00000008, 0x00020208, 0x00020200, 0x08000008,
+      87                 :            :     0x08020000, 0x08000208, 0x00000208, 0x08020000,
+      88                 :            :     0x00020208, 0x00000008, 0x08020008, 0x00020200
+      89                 :            : };
+      90                 :            : 
+      91                 :            : static const uint32_t SB4[64] =
+      92                 :            : {
+      93                 :            :     0x00802001, 0x00002081, 0x00002081, 0x00000080,
+      94                 :            :     0x00802080, 0x00800081, 0x00800001, 0x00002001,
+      95                 :            :     0x00000000, 0x00802000, 0x00802000, 0x00802081,
+      96                 :            :     0x00000081, 0x00000000, 0x00800080, 0x00800001,
+      97                 :            :     0x00000001, 0x00002000, 0x00800000, 0x00802001,
+      98                 :            :     0x00000080, 0x00800000, 0x00002001, 0x00002080,
+      99                 :            :     0x00800081, 0x00000001, 0x00002080, 0x00800080,
+     100                 :            :     0x00002000, 0x00802080, 0x00802081, 0x00000081,
+     101                 :            :     0x00800080, 0x00800001, 0x00802000, 0x00802081,
+     102                 :            :     0x00000081, 0x00000000, 0x00000000, 0x00802000,
+     103                 :            :     0x00002080, 0x00800080, 0x00800081, 0x00000001,
+     104                 :            :     0x00802001, 0x00002081, 0x00002081, 0x00000080,
+     105                 :            :     0x00802081, 0x00000081, 0x00000001, 0x00002000,
+     106                 :            :     0x00800001, 0x00002001, 0x00802080, 0x00800081,
+     107                 :            :     0x00002001, 0x00002080, 0x00800000, 0x00802001,
+     108                 :            :     0x00000080, 0x00800000, 0x00002000, 0x00802080
+     109                 :            : };
+     110                 :            : 
+     111                 :            : static const uint32_t SB5[64] =
+     112                 :            : {
+     113                 :            :     0x00000100, 0x02080100, 0x02080000, 0x42000100,
+     114                 :            :     0x00080000, 0x00000100, 0x40000000, 0x02080000,
+     115                 :            :     0x40080100, 0x00080000, 0x02000100, 0x40080100,
+     116                 :            :     0x42000100, 0x42080000, 0x00080100, 0x40000000,
+     117                 :            :     0x02000000, 0x40080000, 0x40080000, 0x00000000,
+     118                 :            :     0x40000100, 0x42080100, 0x42080100, 0x02000100,
+     119                 :            :     0x42080000, 0x40000100, 0x00000000, 0x42000000,
+     120                 :            :     0x02080100, 0x02000000, 0x42000000, 0x00080100,
+     121                 :            :     0x00080000, 0x42000100, 0x00000100, 0x02000000,
+     122                 :            :     0x40000000, 0x02080000, 0x42000100, 0x40080100,
+     123                 :            :     0x02000100, 0x40000000, 0x42080000, 0x02080100,
+     124                 :            :     0x40080100, 0x00000100, 0x02000000, 0x42080000,
+     125                 :            :     0x42080100, 0x00080100, 0x42000000, 0x42080100,
+     126                 :            :     0x02080000, 0x00000000, 0x40080000, 0x42000000,
+     127                 :            :     0x00080100, 0x02000100, 0x40000100, 0x00080000,
+     128                 :            :     0x00000000, 0x40080000, 0x02080100, 0x40000100
+     129                 :            : };
+     130                 :            : 
+     131                 :            : static const uint32_t SB6[64] =
+     132                 :            : {
+     133                 :            :     0x20000010, 0x20400000, 0x00004000, 0x20404010,
+     134                 :            :     0x20400000, 0x00000010, 0x20404010, 0x00400000,
+     135                 :            :     0x20004000, 0x00404010, 0x00400000, 0x20000010,
+     136                 :            :     0x00400010, 0x20004000, 0x20000000, 0x00004010,
+     137                 :            :     0x00000000, 0x00400010, 0x20004010, 0x00004000,
+     138                 :            :     0x00404000, 0x20004010, 0x00000010, 0x20400010,
+     139                 :            :     0x20400010, 0x00000000, 0x00404010, 0x20404000,
+     140                 :            :     0x00004010, 0x00404000, 0x20404000, 0x20000000,
+     141                 :            :     0x20004000, 0x00000010, 0x20400010, 0x00404000,
+     142                 :            :     0x20404010, 0x00400000, 0x00004010, 0x20000010,
+     143                 :            :     0x00400000, 0x20004000, 0x20000000, 0x00004010,
+     144                 :            :     0x20000010, 0x20404010, 0x00404000, 0x20400000,
+     145                 :            :     0x00404010, 0x20404000, 0x00000000, 0x20400010,
+     146                 :            :     0x00000010, 0x00004000, 0x20400000, 0x00404010,
+     147                 :            :     0x00004000, 0x00400010, 0x20004010, 0x00000000,
+     148                 :            :     0x20404000, 0x20000000, 0x00400010, 0x20004010
+     149                 :            : };
+     150                 :            : 
+     151                 :            : static const uint32_t SB7[64] =
+     152                 :            : {
+     153                 :            :     0x00200000, 0x04200002, 0x04000802, 0x00000000,
+     154                 :            :     0x00000800, 0x04000802, 0x00200802, 0x04200800,
+     155                 :            :     0x04200802, 0x00200000, 0x00000000, 0x04000002,
+     156                 :            :     0x00000002, 0x04000000, 0x04200002, 0x00000802,
+     157                 :            :     0x04000800, 0x00200802, 0x00200002, 0x04000800,
+     158                 :            :     0x04000002, 0x04200000, 0x04200800, 0x00200002,
+     159                 :            :     0x04200000, 0x00000800, 0x00000802, 0x04200802,
+     160                 :            :     0x00200800, 0x00000002, 0x04000000, 0x00200800,
+     161                 :            :     0x04000000, 0x00200800, 0x00200000, 0x04000802,
+     162                 :            :     0x04000802, 0x04200002, 0x04200002, 0x00000002,
+     163                 :            :     0x00200002, 0x04000000, 0x04000800, 0x00200000,
+     164                 :            :     0x04200800, 0x00000802, 0x00200802, 0x04200800,
+     165                 :            :     0x00000802, 0x04000002, 0x04200802, 0x04200000,
+     166                 :            :     0x00200800, 0x00000000, 0x00000002, 0x04200802,
+     167                 :            :     0x00000000, 0x00200802, 0x04200000, 0x00000800,
+     168                 :            :     0x04000002, 0x04000800, 0x00000800, 0x00200002
+     169                 :            : };
+     170                 :            : 
+     171                 :            : static const uint32_t SB8[64] =
+     172                 :            : {
+     173                 :            :     0x10001040, 0x00001000, 0x00040000, 0x10041040,
+     174                 :            :     0x10000000, 0x10001040, 0x00000040, 0x10000000,
+     175                 :            :     0x00040040, 0x10040000, 0x10041040, 0x00041000,
+     176                 :            :     0x10041000, 0x00041040, 0x00001000, 0x00000040,
+     177                 :            :     0x10040000, 0x10000040, 0x10001000, 0x00001040,
+     178                 :            :     0x00041000, 0x00040040, 0x10040040, 0x10041000,
+     179                 :            :     0x00001040, 0x00000000, 0x00000000, 0x10040040,
+     180                 :            :     0x10000040, 0x10001000, 0x00041040, 0x00040000,
+     181                 :            :     0x00041040, 0x00040000, 0x10041000, 0x00001000,
+     182                 :            :     0x00000040, 0x10040040, 0x00001000, 0x00041040,
+     183                 :            :     0x10001000, 0x00000040, 0x10000040, 0x10040000,
+     184                 :            :     0x10040040, 0x10000000, 0x00040000, 0x10001040,
+     185                 :            :     0x00000000, 0x10041040, 0x00040040, 0x10000040,
+     186                 :            :     0x10040000, 0x10001000, 0x10001040, 0x00000000,
+     187                 :            :     0x10041040, 0x00041000, 0x00041000, 0x00001040,
+     188                 :            :     0x00001040, 0x00040040, 0x10000000, 0x10041000
+     189                 :            : };
+     190                 :            : 
+     191                 :            : /*
+     192                 :            :  * PC1: left and right halves bit-swap
+     193                 :            :  */
+     194                 :            : static const uint32_t LHs[16] =
+     195                 :            : {
+     196                 :            :     0x00000000, 0x00000001, 0x00000100, 0x00000101,
+     197                 :            :     0x00010000, 0x00010001, 0x00010100, 0x00010101,
+     198                 :            :     0x01000000, 0x01000001, 0x01000100, 0x01000101,
+     199                 :            :     0x01010000, 0x01010001, 0x01010100, 0x01010101
+     200                 :            : };
+     201                 :            : 
+     202                 :            : static const uint32_t RHs[16] =
+     203                 :            : {
+     204                 :            :     0x00000000, 0x01000000, 0x00010000, 0x01010000,
+     205                 :            :     0x00000100, 0x01000100, 0x00010100, 0x01010100,
+     206                 :            :     0x00000001, 0x01000001, 0x00010001, 0x01010001,
+     207                 :            :     0x00000101, 0x01000101, 0x00010101, 0x01010101,
+     208                 :            : };
+     209                 :            : 
+     210                 :            : /*
+     211                 :            :  * Initial Permutation macro
+     212                 :            :  */
+     213                 :            : #define DES_IP(X, Y)                                                       \
+     214                 :            :     do                                                                    \
+     215                 :            :     {                                                                     \
+     216                 :            :         T = (((X) >>  4) ^ (Y)) & 0x0F0F0F0F; (Y) ^= T; (X) ^= (T <<  4); \
+     217                 :            :         T = (((X) >> 16) ^ (Y)) & 0x0000FFFF; (Y) ^= T; (X) ^= (T << 16); \
+     218                 :            :         T = (((Y) >>  2) ^ (X)) & 0x33333333; (X) ^= T; (Y) ^= (T <<  2); \
+     219                 :            :         T = (((Y) >>  8) ^ (X)) & 0x00FF00FF; (X) ^= T; (Y) ^= (T <<  8); \
+     220                 :            :         (Y) = (((Y) << 1) | ((Y) >> 31)) & 0xFFFFFFFF;                    \
+     221                 :            :         T = ((X) ^ (Y)) & 0xAAAAAAAA; (Y) ^= T; (X) ^= T;                 \
+     222                 :            :         (X) = (((X) << 1) | ((X) >> 31)) & 0xFFFFFFFF;                    \
+     223                 :            :     } while (0)
+     224                 :            : 
+     225                 :            : /*
+     226                 :            :  * Final Permutation macro
+     227                 :            :  */
+     228                 :            : #define DES_FP(X, Y)                                                       \
+     229                 :            :     do                                                                    \
+     230                 :            :     {                                                                     \
+     231                 :            :         (X) = (((X) << 31) | ((X) >> 1)) & 0xFFFFFFFF;                    \
+     232                 :            :         T = ((X) ^ (Y)) & 0xAAAAAAAA; (X) ^= T; (Y) ^= T;                 \
+     233                 :            :         (Y) = (((Y) << 31) | ((Y) >> 1)) & 0xFFFFFFFF;                    \
+     234                 :            :         T = (((Y) >>  8) ^ (X)) & 0x00FF00FF; (X) ^= T; (Y) ^= (T <<  8); \
+     235                 :            :         T = (((Y) >>  2) ^ (X)) & 0x33333333; (X) ^= T; (Y) ^= (T <<  2); \
+     236                 :            :         T = (((X) >> 16) ^ (Y)) & 0x0000FFFF; (Y) ^= T; (X) ^= (T << 16); \
+     237                 :            :         T = (((X) >>  4) ^ (Y)) & 0x0F0F0F0F; (Y) ^= T; (X) ^= (T <<  4); \
+     238                 :            :     } while (0)
+     239                 :            : 
+     240                 :            : /*
+     241                 :            :  * DES round macro
+     242                 :            :  */
+     243                 :            : #define DES_ROUND(X, Y)                              \
+     244                 :            :     do                                              \
+     245                 :            :     {                                               \
+     246                 :            :         T = *SK++ ^ (X);                            \
+     247                 :            :         (Y) ^= SB8[(T) & 0x3F] ^            \
+     248                 :            :                SB6[(T >>  8) & 0x3F] ^            \
+     249                 :            :                SB4[(T >> 16) & 0x3F] ^            \
+     250                 :            :                SB2[(T >> 24) & 0x3F];             \
+     251                 :            :                                                     \
+     252                 :            :         T = *SK++ ^ (((X) << 28) | ((X) >> 4));     \
+     253                 :            :         (Y) ^= SB7[(T) & 0x3F] ^            \
+     254                 :            :                SB5[(T >>  8) & 0x3F] ^            \
+     255                 :            :                SB3[(T >> 16) & 0x3F] ^            \
+     256                 :            :                SB1[(T >> 24) & 0x3F];             \
+     257                 :            :     } while (0)
+     258                 :            : 
+     259                 :            : #define SWAP(a, b)                                       \
+     260                 :            :     do                                                  \
+     261                 :            :     {                                                   \
+     262                 :            :         uint32_t t = (a); (a) = (b); (b) = t; t = 0;    \
+     263                 :            :     } while (0)
+     264                 :            : 
+     265                 :          0 : void mbedtls_des_init(mbedtls_des_context *ctx)
+     266                 :            : {
+     267                 :          0 :     memset(ctx, 0, sizeof(mbedtls_des_context));
+     268                 :          0 : }
+     269                 :            : 
+     270                 :          0 : void mbedtls_des_free(mbedtls_des_context *ctx)
+     271                 :            : {
+     272         [ #  # ]:          0 :     if (ctx == NULL) {
+     273                 :          0 :         return;
+     274                 :            :     }
+     275                 :            : 
+     276                 :          0 :     mbedtls_platform_zeroize(ctx, sizeof(mbedtls_des_context));
+     277                 :            : }
+     278                 :            : 
+     279                 :          0 : void mbedtls_des3_init(mbedtls_des3_context *ctx)
+     280                 :            : {
+     281                 :          0 :     memset(ctx, 0, sizeof(mbedtls_des3_context));
+     282                 :          0 : }
+     283                 :            : 
+     284                 :          0 : void mbedtls_des3_free(mbedtls_des3_context *ctx)
+     285                 :            : {
+     286         [ #  # ]:          0 :     if (ctx == NULL) {
+     287                 :          0 :         return;
+     288                 :            :     }
+     289                 :            : 
+     290                 :          0 :     mbedtls_platform_zeroize(ctx, sizeof(mbedtls_des3_context));
+     291                 :            : }
+     292                 :            : 
+     293                 :            : static const unsigned char odd_parity_table[128] = { 1,  2,  4,  7,  8,
+     294                 :            :                                                      11, 13, 14, 16, 19, 21, 22, 25, 26, 28, 31, 32,
+     295                 :            :                                                      35, 37, 38, 41, 42, 44,
+     296                 :            :                                                      47, 49, 50, 52, 55, 56, 59, 61, 62, 64, 67, 69,
+     297                 :            :                                                      70, 73, 74, 76, 79, 81,
+     298                 :            :                                                      82, 84, 87, 88, 91, 93, 94, 97, 98, 100, 103,
+     299                 :            :                                                      104, 107, 109, 110, 112,
+     300                 :            :                                                      115, 117, 118, 121, 122, 124, 127, 128, 131,
+     301                 :            :                                                      133, 134, 137, 138, 140,
+     302                 :            :                                                      143, 145, 146, 148, 151, 152, 155, 157, 158,
+     303                 :            :                                                      161, 162, 164, 167, 168,
+     304                 :            :                                                      171, 173, 174, 176, 179, 181, 182, 185, 186,
+     305                 :            :                                                      188, 191, 193, 194, 196,
+     306                 :            :                                                      199, 200, 203, 205, 206, 208, 211, 213, 214,
+     307                 :            :                                                      217, 218, 220, 223, 224,
+     308                 :            :                                                      227, 229, 230, 233, 234, 236, 239, 241, 242,
+     309                 :            :                                                      244, 247, 248, 251, 253,
+     310                 :            :                                                      254 };
+     311                 :            : 
+     312                 :          0 : void mbedtls_des_key_set_parity(unsigned char key[MBEDTLS_DES_KEY_SIZE])
+     313                 :            : {
+     314                 :            :     int i;
+     315                 :            : 
+     316         [ #  # ]:          0 :     for (i = 0; i < MBEDTLS_DES_KEY_SIZE; i++) {
+     317                 :          0 :         key[i] = odd_parity_table[key[i] / 2];
+     318                 :            :     }
+     319                 :          0 : }
+     320                 :            : 
+     321                 :            : /*
+     322                 :            :  * Check the given key's parity, returns 1 on failure, 0 on SUCCESS
+     323                 :            :  */
+     324                 :          0 : int mbedtls_des_key_check_key_parity(const unsigned char key[MBEDTLS_DES_KEY_SIZE])
+     325                 :            : {
+     326                 :            :     int i;
+     327                 :            : 
+     328         [ #  # ]:          0 :     for (i = 0; i < MBEDTLS_DES_KEY_SIZE; i++) {
+     329         [ #  # ]:          0 :         if (key[i] != odd_parity_table[key[i] / 2]) {
+     330                 :          0 :             return 1;
+     331                 :            :         }
+     332                 :            :     }
+     333                 :            : 
+     334                 :          0 :     return 0;
+     335                 :            : }
+     336                 :            : 
+     337                 :            : /*
+     338                 :            :  * Table of weak and semi-weak keys
+     339                 :            :  *
+     340                 :            :  * Source: http://en.wikipedia.org/wiki/Weak_key
+     341                 :            :  *
+     342                 :            :  * Weak:
+     343                 :            :  * Alternating ones + zeros (0x0101010101010101)
+     344                 :            :  * Alternating 'F' + 'E' (0xFEFEFEFEFEFEFEFE)
+     345                 :            :  * '0xE0E0E0E0F1F1F1F1'
+     346                 :            :  * '0x1F1F1F1F0E0E0E0E'
+     347                 :            :  *
+     348                 :            :  * Semi-weak:
+     349                 :            :  * 0x011F011F010E010E and 0x1F011F010E010E01
+     350                 :            :  * 0x01E001E001F101F1 and 0xE001E001F101F101
+     351                 :            :  * 0x01FE01FE01FE01FE and 0xFE01FE01FE01FE01
+     352                 :            :  * 0x1FE01FE00EF10EF1 and 0xE01FE01FF10EF10E
+     353                 :            :  * 0x1FFE1FFE0EFE0EFE and 0xFE1FFE1FFE0EFE0E
+     354                 :            :  * 0xE0FEE0FEF1FEF1FE and 0xFEE0FEE0FEF1FEF1
+     355                 :            :  *
+     356                 :            :  */
+     357                 :            : 
+     358                 :            : #define WEAK_KEY_COUNT 16
+     359                 :            : 
+     360                 :            : static const unsigned char weak_key_table[WEAK_KEY_COUNT][MBEDTLS_DES_KEY_SIZE] =
+     361                 :            : {
+     362                 :            :     { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
+     363                 :            :     { 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE },
+     364                 :            :     { 0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E },
+     365                 :            :     { 0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1 },
+     366                 :            : 
+     367                 :            :     { 0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E },
+     368                 :            :     { 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01 },
+     369                 :            :     { 0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1 },
+     370                 :            :     { 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01 },
+     371                 :            :     { 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE },
+     372                 :            :     { 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01 },
+     373                 :            :     { 0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1 },
+     374                 :            :     { 0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E },
+     375                 :            :     { 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE },
+     376                 :            :     { 0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E },
+     377                 :            :     { 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE },
+     378                 :            :     { 0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1 }
+     379                 :            : };
+     380                 :            : 
+     381                 :          0 : int mbedtls_des_key_check_weak(const unsigned char key[MBEDTLS_DES_KEY_SIZE])
+     382                 :            : {
+     383                 :            :     int i;
+     384                 :            : 
+     385         [ #  # ]:          0 :     for (i = 0; i < WEAK_KEY_COUNT; i++) {
+     386         [ #  # ]:          0 :         if (memcmp(weak_key_table[i], key, MBEDTLS_DES_KEY_SIZE) == 0) {
+     387                 :          0 :             return 1;
+     388                 :            :         }
+     389                 :            :     }
+     390                 :            : 
+     391                 :          0 :     return 0;
+     392                 :            : }
+     393                 :            : 
+     394                 :            : #if !defined(MBEDTLS_DES_SETKEY_ALT)
+     395                 :          0 : void mbedtls_des_setkey(uint32_t SK[32], const unsigned char key[MBEDTLS_DES_KEY_SIZE])
+     396                 :            : {
+     397                 :            :     int i;
+     398                 :            :     uint32_t X, Y, T;
+     399                 :            : 
+     400                 :          0 :     X = MBEDTLS_GET_UINT32_BE(key, 0);
+     401                 :          0 :     Y = MBEDTLS_GET_UINT32_BE(key, 4);
+     402                 :            : 
+     403                 :            :     /*
+     404                 :            :      * Permuted Choice 1
+     405                 :            :      */
+     406                 :          0 :     T =  ((Y >>  4) ^ X) & 0x0F0F0F0F;  X ^= T; Y ^= (T <<  4);
+     407                 :          0 :     T =  ((Y) ^ X) & 0x10101010;  X ^= T; Y ^= (T);
+     408                 :            : 
+     409                 :          0 :     X =   (LHs[(X) & 0xF] << 3) | (LHs[(X >>  8) & 0xF] << 2)
+     410                 :          0 :         | (LHs[(X >> 16) & 0xF] << 1) | (LHs[(X >> 24) & 0xF])
+     411                 :          0 :         | (LHs[(X >>  5) & 0xF] << 7) | (LHs[(X >> 13) & 0xF] << 6)
+     412                 :          0 :         | (LHs[(X >> 21) & 0xF] << 5) | (LHs[(X >> 29) & 0xF] << 4);
+     413                 :            : 
+     414                 :          0 :     Y =   (RHs[(Y >>  1) & 0xF] << 3) | (RHs[(Y >>  9) & 0xF] << 2)
+     415                 :          0 :         | (RHs[(Y >> 17) & 0xF] << 1) | (RHs[(Y >> 25) & 0xF])
+     416                 :          0 :         | (RHs[(Y >>  4) & 0xF] << 7) | (RHs[(Y >> 12) & 0xF] << 6)
+     417                 :          0 :         | (RHs[(Y >> 20) & 0xF] << 5) | (RHs[(Y >> 28) & 0xF] << 4);
+     418                 :            : 
+     419                 :          0 :     X &= 0x0FFFFFFF;
+     420                 :          0 :     Y &= 0x0FFFFFFF;
+     421                 :            : 
+     422                 :            :     /*
+     423                 :            :      * calculate subkeys
+     424                 :            :      */
+     425         [ #  # ]:          0 :     for (i = 0; i < 16; i++) {
+     426   [ #  #  #  #  :          0 :         if (i < 2 || i == 8 || i == 15) {
+                   #  # ]
+     427                 :          0 :             X = ((X <<  1) | (X >> 27)) & 0x0FFFFFFF;
+     428                 :          0 :             Y = ((Y <<  1) | (Y >> 27)) & 0x0FFFFFFF;
+     429                 :            :         } else {
+     430                 :          0 :             X = ((X <<  2) | (X >> 26)) & 0x0FFFFFFF;
+     431                 :          0 :             Y = ((Y <<  2) | (Y >> 26)) & 0x0FFFFFFF;
+     432                 :            :         }
+     433                 :            : 
+     434                 :          0 :         *SK++ =   ((X <<  4) & 0x24000000) | ((X << 28) & 0x10000000)
+     435                 :          0 :                 | ((X << 14) & 0x08000000) | ((X << 18) & 0x02080000)
+     436                 :          0 :                 | ((X <<  6) & 0x01000000) | ((X <<  9) & 0x00200000)
+     437                 :          0 :                 | ((X >>  1) & 0x00100000) | ((X << 10) & 0x00040000)
+     438                 :          0 :                 | ((X <<  2) & 0x00020000) | ((X >> 10) & 0x00010000)
+     439                 :          0 :                 | ((Y >> 13) & 0x00002000) | ((Y >>  4) & 0x00001000)
+     440                 :          0 :                 | ((Y <<  6) & 0x00000800) | ((Y >>  1) & 0x00000400)
+     441                 :          0 :                 | ((Y >> 14) & 0x00000200) | ((Y) & 0x00000100)
+     442                 :          0 :                 | ((Y >>  5) & 0x00000020) | ((Y >> 10) & 0x00000010)
+     443                 :          0 :                 | ((Y >>  3) & 0x00000008) | ((Y >> 18) & 0x00000004)
+     444                 :          0 :                 | ((Y >> 26) & 0x00000002) | ((Y >> 24) & 0x00000001);
+     445                 :            : 
+     446                 :          0 :         *SK++ =   ((X << 15) & 0x20000000) | ((X << 17) & 0x10000000)
+     447                 :          0 :                 | ((X << 10) & 0x08000000) | ((X << 22) & 0x04000000)
+     448                 :          0 :                 | ((X >>  2) & 0x02000000) | ((X <<  1) & 0x01000000)
+     449                 :          0 :                 | ((X << 16) & 0x00200000) | ((X << 11) & 0x00100000)
+     450                 :          0 :                 | ((X <<  3) & 0x00080000) | ((X >>  6) & 0x00040000)
+     451                 :          0 :                 | ((X << 15) & 0x00020000) | ((X >>  4) & 0x00010000)
+     452                 :          0 :                 | ((Y >>  2) & 0x00002000) | ((Y <<  8) & 0x00001000)
+     453                 :          0 :                 | ((Y >> 14) & 0x00000808) | ((Y >>  9) & 0x00000400)
+     454                 :          0 :                 | ((Y) & 0x00000200) | ((Y <<  7) & 0x00000100)
+     455                 :          0 :                 | ((Y >>  7) & 0x00000020) | ((Y >>  3) & 0x00000011)
+     456                 :          0 :                 | ((Y <<  2) & 0x00000004) | ((Y >> 21) & 0x00000002);
+     457                 :            :     }
+     458                 :          0 : }
+     459                 :            : #endif /* !MBEDTLS_DES_SETKEY_ALT */
+     460                 :            : 
+     461                 :            : /*
+     462                 :            :  * DES key schedule (56-bit, encryption)
+     463                 :            :  */
+     464                 :          0 : int mbedtls_des_setkey_enc(mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE])
+     465                 :            : {
+     466                 :          0 :     mbedtls_des_setkey(ctx->sk, key);
+     467                 :            : 
+     468                 :          0 :     return 0;
+     469                 :            : }
+     470                 :            : 
+     471                 :            : /*
+     472                 :            :  * DES key schedule (56-bit, decryption)
+     473                 :            :  */
+     474                 :          0 : int mbedtls_des_setkey_dec(mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE])
+     475                 :            : {
+     476                 :            :     int i;
+     477                 :            : 
+     478                 :          0 :     mbedtls_des_setkey(ctx->sk, key);
+     479                 :            : 
+     480         [ #  # ]:          0 :     for (i = 0; i < 16; i += 2) {
+     481                 :          0 :         SWAP(ctx->sk[i], ctx->sk[30 - i]);
+     482                 :          0 :         SWAP(ctx->sk[i + 1], ctx->sk[31 - i]);
+     483                 :            :     }
+     484                 :            : 
+     485                 :          0 :     return 0;
+     486                 :            : }
+     487                 :            : 
+     488                 :          0 : static void des3_set2key(uint32_t esk[96],
+     489                 :            :                          uint32_t dsk[96],
+     490                 :            :                          const unsigned char key[MBEDTLS_DES_KEY_SIZE*2])
+     491                 :            : {
+     492                 :            :     int i;
+     493                 :            : 
+     494                 :          0 :     mbedtls_des_setkey(esk, key);
+     495                 :          0 :     mbedtls_des_setkey(dsk + 32, key + 8);
+     496                 :            : 
+     497         [ #  # ]:          0 :     for (i = 0; i < 32; i += 2) {
+     498                 :          0 :         dsk[i] = esk[30 - i];
+     499                 :          0 :         dsk[i +  1] = esk[31 - i];
+     500                 :            : 
+     501                 :          0 :         esk[i + 32] = dsk[62 - i];
+     502                 :          0 :         esk[i + 33] = dsk[63 - i];
+     503                 :            : 
+     504                 :          0 :         esk[i + 64] = esk[i];
+     505                 :          0 :         esk[i + 65] = esk[i + 1];
+     506                 :            : 
+     507                 :          0 :         dsk[i + 64] = dsk[i];
+     508                 :          0 :         dsk[i + 65] = dsk[i + 1];
+     509                 :            :     }
+     510                 :          0 : }
+     511                 :            : 
+     512                 :            : /*
+     513                 :            :  * Triple-DES key schedule (112-bit, encryption)
+     514                 :            :  */
+     515                 :          0 : int mbedtls_des3_set2key_enc(mbedtls_des3_context *ctx,
+     516                 :            :                              const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2])
+     517                 :            : {
+     518                 :            :     uint32_t sk[96];
+     519                 :            : 
+     520                 :          0 :     des3_set2key(ctx->sk, sk, key);
+     521                 :          0 :     mbedtls_platform_zeroize(sk,  sizeof(sk));
+     522                 :            : 
+     523                 :          0 :     return 0;
+     524                 :            : }
+     525                 :            : 
+     526                 :            : /*
+     527                 :            :  * Triple-DES key schedule (112-bit, decryption)
+     528                 :            :  */
+     529                 :          0 : int mbedtls_des3_set2key_dec(mbedtls_des3_context *ctx,
+     530                 :            :                              const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2])
+     531                 :            : {
+     532                 :            :     uint32_t sk[96];
+     533                 :            : 
+     534                 :          0 :     des3_set2key(sk, ctx->sk, key);
+     535                 :          0 :     mbedtls_platform_zeroize(sk,  sizeof(sk));
+     536                 :            : 
+     537                 :          0 :     return 0;
+     538                 :            : }
+     539                 :            : 
+     540                 :          0 : static void des3_set3key(uint32_t esk[96],
+     541                 :            :                          uint32_t dsk[96],
+     542                 :            :                          const unsigned char key[24])
+     543                 :            : {
+     544                 :            :     int i;
+     545                 :            : 
+     546                 :          0 :     mbedtls_des_setkey(esk, key);
+     547                 :          0 :     mbedtls_des_setkey(dsk + 32, key +  8);
+     548                 :          0 :     mbedtls_des_setkey(esk + 64, key + 16);
+     549                 :            : 
+     550         [ #  # ]:          0 :     for (i = 0; i < 32; i += 2) {
+     551                 :          0 :         dsk[i] = esk[94 - i];
+     552                 :          0 :         dsk[i +  1] = esk[95 - i];
+     553                 :            : 
+     554                 :          0 :         esk[i + 32] = dsk[62 - i];
+     555                 :          0 :         esk[i + 33] = dsk[63 - i];
+     556                 :            : 
+     557                 :          0 :         dsk[i + 64] = esk[30 - i];
+     558                 :          0 :         dsk[i + 65] = esk[31 - i];
+     559                 :            :     }
+     560                 :          0 : }
+     561                 :            : 
+     562                 :            : /*
+     563                 :            :  * Triple-DES key schedule (168-bit, encryption)
+     564                 :            :  */
+     565                 :          0 : int mbedtls_des3_set3key_enc(mbedtls_des3_context *ctx,
+     566                 :            :                              const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3])
+     567                 :            : {
+     568                 :            :     uint32_t sk[96];
+     569                 :            : 
+     570                 :          0 :     des3_set3key(ctx->sk, sk, key);
+     571                 :          0 :     mbedtls_platform_zeroize(sk,  sizeof(sk));
+     572                 :            : 
+     573                 :          0 :     return 0;
+     574                 :            : }
+     575                 :            : 
+     576                 :            : /*
+     577                 :            :  * Triple-DES key schedule (168-bit, decryption)
+     578                 :            :  */
+     579                 :          0 : int mbedtls_des3_set3key_dec(mbedtls_des3_context *ctx,
+     580                 :            :                              const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3])
+     581                 :            : {
+     582                 :            :     uint32_t sk[96];
+     583                 :            : 
+     584                 :          0 :     des3_set3key(sk, ctx->sk, key);
+     585                 :          0 :     mbedtls_platform_zeroize(sk,  sizeof(sk));
+     586                 :            : 
+     587                 :          0 :     return 0;
+     588                 :            : }
+     589                 :            : 
+     590                 :            : /*
+     591                 :            :  * DES-ECB block encryption/decryption
+     592                 :            :  */
+     593                 :            : #if !defined(MBEDTLS_DES_CRYPT_ECB_ALT)
+     594                 :          0 : int mbedtls_des_crypt_ecb(mbedtls_des_context *ctx,
+     595                 :            :                           const unsigned char input[8],
+     596                 :            :                           unsigned char output[8])
+     597                 :            : {
+     598                 :            :     int i;
+     599                 :            :     uint32_t X, Y, T, *SK;
+     600                 :            : 
+     601                 :          0 :     SK = ctx->sk;
+     602                 :            : 
+     603                 :          0 :     X = MBEDTLS_GET_UINT32_BE(input, 0);
+     604                 :          0 :     Y = MBEDTLS_GET_UINT32_BE(input, 4);
+     605                 :            : 
+     606                 :          0 :     DES_IP(X, Y);
+     607                 :            : 
+     608         [ #  # ]:          0 :     for (i = 0; i < 8; i++) {
+     609                 :          0 :         DES_ROUND(Y, X);
+     610                 :          0 :         DES_ROUND(X, Y);
+     611                 :            :     }
+     612                 :            : 
+     613                 :          0 :     DES_FP(Y, X);
+     614                 :            : 
+     615                 :          0 :     MBEDTLS_PUT_UINT32_BE(Y, output, 0);
+     616                 :          0 :     MBEDTLS_PUT_UINT32_BE(X, output, 4);
+     617                 :            : 
+     618                 :          0 :     return 0;
+     619                 :            : }
+     620                 :            : #endif /* !MBEDTLS_DES_CRYPT_ECB_ALT */
+     621                 :            : 
+     622                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+     623                 :            : /*
+     624                 :            :  * DES-CBC buffer encryption/decryption
+     625                 :            :  */
+     626                 :          0 : int mbedtls_des_crypt_cbc(mbedtls_des_context *ctx,
+     627                 :            :                           int mode,
+     628                 :            :                           size_t length,
+     629                 :            :                           unsigned char iv[8],
+     630                 :            :                           const unsigned char *input,
+     631                 :            :                           unsigned char *output)
+     632                 :            : {
+     633                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     634                 :            :     unsigned char temp[8];
+     635                 :            : 
+     636         [ #  # ]:          0 :     if (length % 8) {
+     637                 :          0 :         return MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH;
+     638                 :            :     }
+     639                 :            : 
+     640         [ #  # ]:          0 :     if (mode == MBEDTLS_DES_ENCRYPT) {
+     641         [ #  # ]:          0 :         while (length > 0) {
+     642                 :            :             mbedtls_xor(output, input, iv, 8);
+     643                 :            : 
+     644                 :          0 :             ret = mbedtls_des_crypt_ecb(ctx, output, output);
+     645         [ #  # ]:          0 :             if (ret != 0) {
+     646                 :          0 :                 goto exit;
+     647                 :            :             }
+     648                 :          0 :             memcpy(iv, output, 8);
+     649                 :            : 
+     650                 :          0 :             input  += 8;
+     651                 :          0 :             output += 8;
+     652                 :          0 :             length -= 8;
+     653                 :            :         }
+     654                 :            :     } else { /* MBEDTLS_DES_DECRYPT */
+     655         [ #  # ]:          0 :         while (length > 0) {
+     656                 :          0 :             memcpy(temp, input, 8);
+     657                 :          0 :             ret = mbedtls_des_crypt_ecb(ctx, input, output);
+     658         [ #  # ]:          0 :             if (ret != 0) {
+     659                 :          0 :                 goto exit;
+     660                 :            :             }
+     661                 :            : 
+     662                 :            :             mbedtls_xor(output, output, iv, 8);
+     663                 :            : 
+     664                 :          0 :             memcpy(iv, temp, 8);
+     665                 :            : 
+     666                 :          0 :             input  += 8;
+     667                 :          0 :             output += 8;
+     668                 :          0 :             length -= 8;
+     669                 :            :         }
+     670                 :            :     }
+     671                 :          0 :     ret = 0;
+     672                 :            : 
+     673                 :          0 : exit:
+     674                 :          0 :     return ret;
+     675                 :            : }
+     676                 :            : #endif /* MBEDTLS_CIPHER_MODE_CBC */
+     677                 :            : 
+     678                 :            : /*
+     679                 :            :  * 3DES-ECB block encryption/decryption
+     680                 :            :  */
+     681                 :            : #if !defined(MBEDTLS_DES3_CRYPT_ECB_ALT)
+     682                 :          0 : int mbedtls_des3_crypt_ecb(mbedtls_des3_context *ctx,
+     683                 :            :                            const unsigned char input[8],
+     684                 :            :                            unsigned char output[8])
+     685                 :            : {
+     686                 :            :     int i;
+     687                 :            :     uint32_t X, Y, T, *SK;
+     688                 :            : 
+     689                 :          0 :     SK = ctx->sk;
+     690                 :            : 
+     691                 :          0 :     X = MBEDTLS_GET_UINT32_BE(input, 0);
+     692                 :          0 :     Y = MBEDTLS_GET_UINT32_BE(input, 4);
+     693                 :            : 
+     694                 :          0 :     DES_IP(X, Y);
+     695                 :            : 
+     696         [ #  # ]:          0 :     for (i = 0; i < 8; i++) {
+     697                 :          0 :         DES_ROUND(Y, X);
+     698                 :          0 :         DES_ROUND(X, Y);
+     699                 :            :     }
+     700                 :            : 
+     701         [ #  # ]:          0 :     for (i = 0; i < 8; i++) {
+     702                 :          0 :         DES_ROUND(X, Y);
+     703                 :          0 :         DES_ROUND(Y, X);
+     704                 :            :     }
+     705                 :            : 
+     706         [ #  # ]:          0 :     for (i = 0; i < 8; i++) {
+     707                 :          0 :         DES_ROUND(Y, X);
+     708                 :          0 :         DES_ROUND(X, Y);
+     709                 :            :     }
+     710                 :            : 
+     711                 :          0 :     DES_FP(Y, X);
+     712                 :            : 
+     713                 :          0 :     MBEDTLS_PUT_UINT32_BE(Y, output, 0);
+     714                 :          0 :     MBEDTLS_PUT_UINT32_BE(X, output, 4);
+     715                 :            : 
+     716                 :          0 :     return 0;
+     717                 :            : }
+     718                 :            : #endif /* !MBEDTLS_DES3_CRYPT_ECB_ALT */
+     719                 :            : 
+     720                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+     721                 :            : /*
+     722                 :            :  * 3DES-CBC buffer encryption/decryption
+     723                 :            :  */
+     724                 :          0 : int mbedtls_des3_crypt_cbc(mbedtls_des3_context *ctx,
+     725                 :            :                            int mode,
+     726                 :            :                            size_t length,
+     727                 :            :                            unsigned char iv[8],
+     728                 :            :                            const unsigned char *input,
+     729                 :            :                            unsigned char *output)
+     730                 :            : {
+     731                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     732                 :            :     unsigned char temp[8];
+     733                 :            : 
+     734         [ #  # ]:          0 :     if (length % 8) {
+     735                 :          0 :         return MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH;
+     736                 :            :     }
+     737                 :            : 
+     738         [ #  # ]:          0 :     if (mode == MBEDTLS_DES_ENCRYPT) {
+     739         [ #  # ]:          0 :         while (length > 0) {
+     740                 :            :             mbedtls_xor(output, input, iv, 8);
+     741                 :            : 
+     742                 :          0 :             ret = mbedtls_des3_crypt_ecb(ctx, output, output);
+     743         [ #  # ]:          0 :             if (ret != 0) {
+     744                 :          0 :                 goto exit;
+     745                 :            :             }
+     746                 :          0 :             memcpy(iv, output, 8);
+     747                 :            : 
+     748                 :          0 :             input  += 8;
+     749                 :          0 :             output += 8;
+     750                 :          0 :             length -= 8;
+     751                 :            :         }
+     752                 :            :     } else { /* MBEDTLS_DES_DECRYPT */
+     753         [ #  # ]:          0 :         while (length > 0) {
+     754                 :          0 :             memcpy(temp, input, 8);
+     755                 :          0 :             ret = mbedtls_des3_crypt_ecb(ctx, input, output);
+     756         [ #  # ]:          0 :             if (ret != 0) {
+     757                 :          0 :                 goto exit;
+     758                 :            :             }
+     759                 :            : 
+     760                 :            :             mbedtls_xor(output, output, iv, 8);
+     761                 :            : 
+     762                 :          0 :             memcpy(iv, temp, 8);
+     763                 :            : 
+     764                 :          0 :             input  += 8;
+     765                 :          0 :             output += 8;
+     766                 :          0 :             length -= 8;
+     767                 :            :         }
+     768                 :            :     }
+     769                 :          0 :     ret = 0;
+     770                 :            : 
+     771                 :          0 : exit:
+     772                 :          0 :     return ret;
+     773                 :            : }
+     774                 :            : #endif /* MBEDTLS_CIPHER_MODE_CBC */
+     775                 :            : 
+     776                 :            : #endif /* !MBEDTLS_DES_ALT */
+     777                 :            : 
+     778                 :            : #if defined(MBEDTLS_SELF_TEST)
+     779                 :            : /*
+     780                 :            :  * DES and 3DES test vectors from:
+     781                 :            :  *
+     782                 :            :  * http://csrc.nist.gov/groups/STM/cavp/documents/des/tripledes-vectors.zip
+     783                 :            :  */
+     784                 :            : static const unsigned char des3_test_keys[24] =
+     785                 :            : {
+     786                 :            :     0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
+     787                 :            :     0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01,
+     788                 :            :     0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01, 0x23
+     789                 :            : };
+     790                 :            : 
+     791                 :            : static const unsigned char des3_test_buf[8] =
+     792                 :            : {
+     793                 :            :     0x4E, 0x6F, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74
+     794                 :            : };
+     795                 :            : 
+     796                 :            : static const unsigned char des3_test_ecb_dec[3][8] =
+     797                 :            : {
+     798                 :            :     { 0x37, 0x2B, 0x98, 0xBF, 0x52, 0x65, 0xB0, 0x59 },
+     799                 :            :     { 0xC2, 0x10, 0x19, 0x9C, 0x38, 0x5A, 0x65, 0xA1 },
+     800                 :            :     { 0xA2, 0x70, 0x56, 0x68, 0x69, 0xE5, 0x15, 0x1D }
+     801                 :            : };
+     802                 :            : 
+     803                 :            : static const unsigned char des3_test_ecb_enc[3][8] =
+     804                 :            : {
+     805                 :            :     { 0x1C, 0xD5, 0x97, 0xEA, 0x84, 0x26, 0x73, 0xFB },
+     806                 :            :     { 0xB3, 0x92, 0x4D, 0xF3, 0xC5, 0xB5, 0x42, 0x93 },
+     807                 :            :     { 0xDA, 0x37, 0x64, 0x41, 0xBA, 0x6F, 0x62, 0x6F }
+     808                 :            : };
+     809                 :            : 
+     810                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+     811                 :            : static const unsigned char des3_test_iv[8] =
+     812                 :            : {
+     813                 :            :     0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF,
+     814                 :            : };
+     815                 :            : 
+     816                 :            : static const unsigned char des3_test_cbc_dec[3][8] =
+     817                 :            : {
+     818                 :            :     { 0x58, 0xD9, 0x48, 0xEF, 0x85, 0x14, 0x65, 0x9A },
+     819                 :            :     { 0x5F, 0xC8, 0x78, 0xD4, 0xD7, 0x92, 0xD9, 0x54 },
+     820                 :            :     { 0x25, 0xF9, 0x75, 0x85, 0xA8, 0x1E, 0x48, 0xBF }
+     821                 :            : };
+     822                 :            : 
+     823                 :            : static const unsigned char des3_test_cbc_enc[3][8] =
+     824                 :            : {
+     825                 :            :     { 0x91, 0x1C, 0x6D, 0xCF, 0x48, 0xA7, 0xC3, 0x4D },
+     826                 :            :     { 0x60, 0x1A, 0x76, 0x8F, 0xA1, 0xF9, 0x66, 0xF1 },
+     827                 :            :     { 0xA1, 0x50, 0x0F, 0x99, 0xB2, 0xCD, 0x64, 0x76 }
+     828                 :            : };
+     829                 :            : #endif /* MBEDTLS_CIPHER_MODE_CBC */
+     830                 :            : 
+     831                 :            : /*
+     832                 :            :  * Checkup routine
+     833                 :            :  */
+     834                 :          0 : int mbedtls_des_self_test(int verbose)
+     835                 :            : {
+     836                 :          0 :     int i, j, u, v, ret = 0;
+     837                 :            :     mbedtls_des_context ctx;
+     838                 :            :     mbedtls_des3_context ctx3;
+     839                 :            :     unsigned char buf[8];
+     840                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+     841                 :            :     unsigned char prv[8];
+     842                 :            :     unsigned char iv[8];
+     843                 :            : #endif
+     844                 :            : 
+     845                 :          0 :     mbedtls_des_init(&ctx);
+     846                 :          0 :     mbedtls_des3_init(&ctx3);
+     847                 :            :     /*
+     848                 :            :      * ECB mode
+     849                 :            :      */
+     850         [ #  # ]:          0 :     for (i = 0; i < 6; i++) {
+     851                 :          0 :         u = i >> 1;
+     852                 :          0 :         v = i  & 1;
+     853                 :            : 
+     854         [ #  # ]:          0 :         if (verbose != 0) {
+     855         [ #  # ]:          0 :             mbedtls_printf("  DES%c-ECB-%3d (%s): ",
+     856         [ #  # ]:          0 :                            (u == 0) ? ' ' : '3', 56 + u * 56,
+     857                 :            :                            (v == MBEDTLS_DES_DECRYPT) ? "dec" : "enc");
+     858                 :            :         }
+     859                 :            : 
+     860                 :          0 :         memcpy(buf, des3_test_buf, 8);
+     861                 :            : 
+     862   [ #  #  #  #  :          0 :         switch (i) {
+                #  #  # ]
+     863                 :          0 :             case 0:
+     864                 :          0 :                 ret = mbedtls_des_setkey_dec(&ctx, des3_test_keys);
+     865                 :          0 :                 break;
+     866                 :            : 
+     867                 :          0 :             case 1:
+     868                 :          0 :                 ret = mbedtls_des_setkey_enc(&ctx, des3_test_keys);
+     869                 :          0 :                 break;
+     870                 :            : 
+     871                 :          0 :             case 2:
+     872                 :          0 :                 ret = mbedtls_des3_set2key_dec(&ctx3, des3_test_keys);
+     873                 :          0 :                 break;
+     874                 :            : 
+     875                 :          0 :             case 3:
+     876                 :          0 :                 ret = mbedtls_des3_set2key_enc(&ctx3, des3_test_keys);
+     877                 :          0 :                 break;
+     878                 :            : 
+     879                 :          0 :             case 4:
+     880                 :          0 :                 ret = mbedtls_des3_set3key_dec(&ctx3, des3_test_keys);
+     881                 :          0 :                 break;
+     882                 :            : 
+     883                 :          0 :             case 5:
+     884                 :          0 :                 ret = mbedtls_des3_set3key_enc(&ctx3, des3_test_keys);
+     885                 :          0 :                 break;
+     886                 :            : 
+     887                 :          0 :             default:
+     888                 :          0 :                 return 1;
+     889                 :            :         }
+     890         [ #  # ]:          0 :         if (ret != 0) {
+     891                 :          0 :             goto exit;
+     892                 :            :         }
+     893                 :            : 
+     894         [ #  # ]:          0 :         for (j = 0; j < 100; j++) {
+     895         [ #  # ]:          0 :             if (u == 0) {
+     896                 :          0 :                 ret = mbedtls_des_crypt_ecb(&ctx, buf, buf);
+     897                 :            :             } else {
+     898                 :          0 :                 ret = mbedtls_des3_crypt_ecb(&ctx3, buf, buf);
+     899                 :            :             }
+     900         [ #  # ]:          0 :             if (ret != 0) {
+     901                 :          0 :                 goto exit;
+     902                 :            :             }
+     903                 :            :         }
+     904                 :            : 
+     905         [ #  # ]:          0 :         if ((v == MBEDTLS_DES_DECRYPT &&
+     906   [ #  #  #  # ]:          0 :              memcmp(buf, des3_test_ecb_dec[u], 8) != 0) ||
+     907                 :          0 :             (v != MBEDTLS_DES_DECRYPT &&
+     908         [ #  # ]:          0 :              memcmp(buf, des3_test_ecb_enc[u], 8) != 0)) {
+     909         [ #  # ]:          0 :             if (verbose != 0) {
+     910                 :          0 :                 mbedtls_printf("failed\n");
+     911                 :            :             }
+     912                 :            : 
+     913                 :          0 :             ret = 1;
+     914                 :          0 :             goto exit;
+     915                 :            :         }
+     916                 :            : 
+     917         [ #  # ]:          0 :         if (verbose != 0) {
+     918                 :          0 :             mbedtls_printf("passed\n");
+     919                 :            :         }
+     920                 :            :     }
+     921                 :            : 
+     922         [ #  # ]:          0 :     if (verbose != 0) {
+     923                 :          0 :         mbedtls_printf("\n");
+     924                 :            :     }
+     925                 :            : 
+     926                 :            : #if defined(MBEDTLS_CIPHER_MODE_CBC)
+     927                 :            :     /*
+     928                 :            :      * CBC mode
+     929                 :            :      */
+     930         [ #  # ]:          0 :     for (i = 0; i < 6; i++) {
+     931                 :          0 :         u = i >> 1;
+     932                 :          0 :         v = i  & 1;
+     933                 :            : 
+     934         [ #  # ]:          0 :         if (verbose != 0) {
+     935         [ #  # ]:          0 :             mbedtls_printf("  DES%c-CBC-%3d (%s): ",
+     936         [ #  # ]:          0 :                            (u == 0) ? ' ' : '3', 56 + u * 56,
+     937                 :            :                            (v == MBEDTLS_DES_DECRYPT) ? "dec" : "enc");
+     938                 :            :         }
+     939                 :            : 
+     940                 :          0 :         memcpy(iv,  des3_test_iv,  8);
+     941                 :          0 :         memcpy(prv, des3_test_iv,  8);
+     942                 :          0 :         memcpy(buf, des3_test_buf, 8);
+     943                 :            : 
+     944   [ #  #  #  #  :          0 :         switch (i) {
+                #  #  # ]
+     945                 :          0 :             case 0:
+     946                 :          0 :                 ret = mbedtls_des_setkey_dec(&ctx, des3_test_keys);
+     947                 :          0 :                 break;
+     948                 :            : 
+     949                 :          0 :             case 1:
+     950                 :          0 :                 ret = mbedtls_des_setkey_enc(&ctx, des3_test_keys);
+     951                 :          0 :                 break;
+     952                 :            : 
+     953                 :          0 :             case 2:
+     954                 :          0 :                 ret = mbedtls_des3_set2key_dec(&ctx3, des3_test_keys);
+     955                 :          0 :                 break;
+     956                 :            : 
+     957                 :          0 :             case 3:
+     958                 :          0 :                 ret = mbedtls_des3_set2key_enc(&ctx3, des3_test_keys);
+     959                 :          0 :                 break;
+     960                 :            : 
+     961                 :          0 :             case 4:
+     962                 :          0 :                 ret = mbedtls_des3_set3key_dec(&ctx3, des3_test_keys);
+     963                 :          0 :                 break;
+     964                 :            : 
+     965                 :          0 :             case 5:
+     966                 :          0 :                 ret = mbedtls_des3_set3key_enc(&ctx3, des3_test_keys);
+     967                 :          0 :                 break;
+     968                 :            : 
+     969                 :          0 :             default:
+     970                 :          0 :                 return 1;
+     971                 :            :         }
+     972         [ #  # ]:          0 :         if (ret != 0) {
+     973                 :          0 :             goto exit;
+     974                 :            :         }
+     975                 :            : 
+     976         [ #  # ]:          0 :         if (v == MBEDTLS_DES_DECRYPT) {
+     977         [ #  # ]:          0 :             for (j = 0; j < 100; j++) {
+     978         [ #  # ]:          0 :                 if (u == 0) {
+     979                 :          0 :                     ret = mbedtls_des_crypt_cbc(&ctx, v, 8, iv, buf, buf);
+     980                 :            :                 } else {
+     981                 :          0 :                     ret = mbedtls_des3_crypt_cbc(&ctx3, v, 8, iv, buf, buf);
+     982                 :            :                 }
+     983         [ #  # ]:          0 :                 if (ret != 0) {
+     984                 :          0 :                     goto exit;
+     985                 :            :                 }
+     986                 :            :             }
+     987                 :            :         } else {
+     988         [ #  # ]:          0 :             for (j = 0; j < 100; j++) {
+     989                 :            :                 unsigned char tmp[8];
+     990                 :            : 
+     991         [ #  # ]:          0 :                 if (u == 0) {
+     992                 :          0 :                     ret = mbedtls_des_crypt_cbc(&ctx, v, 8, iv, buf, buf);
+     993                 :            :                 } else {
+     994                 :          0 :                     ret = mbedtls_des3_crypt_cbc(&ctx3, v, 8, iv, buf, buf);
+     995                 :            :                 }
+     996         [ #  # ]:          0 :                 if (ret != 0) {
+     997                 :          0 :                     goto exit;
+     998                 :            :                 }
+     999                 :            : 
+    1000                 :          0 :                 memcpy(tmp, prv, 8);
+    1001                 :          0 :                 memcpy(prv, buf, 8);
+    1002                 :          0 :                 memcpy(buf, tmp, 8);
+    1003                 :            :             }
+    1004                 :            : 
+    1005                 :          0 :             memcpy(buf, prv, 8);
+    1006                 :            :         }
+    1007                 :            : 
+    1008         [ #  # ]:          0 :         if ((v == MBEDTLS_DES_DECRYPT &&
+    1009   [ #  #  #  # ]:          0 :              memcmp(buf, des3_test_cbc_dec[u], 8) != 0) ||
+    1010                 :          0 :             (v != MBEDTLS_DES_DECRYPT &&
+    1011         [ #  # ]:          0 :              memcmp(buf, des3_test_cbc_enc[u], 8) != 0)) {
+    1012         [ #  # ]:          0 :             if (verbose != 0) {
+    1013                 :          0 :                 mbedtls_printf("failed\n");
+    1014                 :            :             }
+    1015                 :            : 
+    1016                 :          0 :             ret = 1;
+    1017                 :          0 :             goto exit;
+    1018                 :            :         }
+    1019                 :            : 
+    1020         [ #  # ]:          0 :         if (verbose != 0) {
+    1021                 :          0 :             mbedtls_printf("passed\n");
+    1022                 :            :         }
+    1023                 :            :     }
+    1024                 :            : #endif /* MBEDTLS_CIPHER_MODE_CBC */
+    1025                 :            : 
+    1026         [ #  # ]:          0 :     if (verbose != 0) {
+    1027                 :          0 :         mbedtls_printf("\n");
+    1028                 :            :     }
+    1029                 :            : 
+    1030                 :          0 : exit:
+    1031                 :          0 :     mbedtls_des_free(&ctx);
+    1032                 :          0 :     mbedtls_des3_free(&ctx3);
+    1033                 :            : 
+    1034         [ #  # ]:          0 :     if (ret != 0) {
+    1035                 :          0 :         ret = 1;
+    1036                 :            :     }
+    1037                 :          0 :     return ret;
+    1038                 :            : }
+    1039                 :            : 
+    1040                 :            : #endif /* MBEDTLS_SELF_TEST */
+    1041                 :            : 
+    1042                 :            : #endif /* MBEDTLS_DES_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/dhm.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/dhm.c.func-sort-c.html new file mode 100644 index 00000000000..6dfe9864890 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/dhm.c.func-sort-c.html @@ -0,0 +1,153 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/dhm.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - dhm.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:8323735.0 %
Date:2024-09-22 08:21:07Functions:101855.6 %
Branches:3717321.4 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
dhm_read_bignum0
mbedtls_dhm_get_bitlen0
mbedtls_dhm_get_value0
mbedtls_dhm_make_params0
mbedtls_dhm_parse_dhm0
mbedtls_dhm_read_params0
mbedtls_dhm_self_test0
mbedtls_dhm_set_group0
dhm_make_common2
dhm_random_below2
dhm_update_blinding2
mbedtls_dhm_calc_secret2
mbedtls_dhm_free2
mbedtls_dhm_init2
mbedtls_dhm_make_public2
mbedtls_dhm_read_public2
dhm_check_range4
mbedtls_dhm_get_len6
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/dhm.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/dhm.c.func.html new file mode 100644 index 00000000000..af6b933e772 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/dhm.c.func.html @@ -0,0 +1,153 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/dhm.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - dhm.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:8323735.0 %
Date:2024-09-22 08:21:07Functions:101855.6 %
Branches:3717321.4 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
dhm_check_range4
dhm_make_common2
dhm_random_below2
dhm_read_bignum0
dhm_update_blinding2
mbedtls_dhm_calc_secret2
mbedtls_dhm_free2
mbedtls_dhm_get_bitlen0
mbedtls_dhm_get_len6
mbedtls_dhm_get_value0
mbedtls_dhm_init2
mbedtls_dhm_make_params0
mbedtls_dhm_make_public2
mbedtls_dhm_parse_dhm0
mbedtls_dhm_read_params0
mbedtls_dhm_read_public2
mbedtls_dhm_self_test0
mbedtls_dhm_set_group0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/dhm.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/dhm.c.gcov.html new file mode 100644 index 00000000000..1c775651883 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/dhm.c.gcov.html @@ -0,0 +1,798 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/dhm.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - dhm.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:8323735.0 %
Date:2024-09-22 08:21:07Functions:101855.6 %
Branches:3717321.4 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  *  Diffie-Hellman-Merkle key exchange
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  */
+       7                 :            : /*
+       8                 :            :  *  The following sources were referenced in the design of this implementation
+       9                 :            :  *  of the Diffie-Hellman-Merkle algorithm:
+      10                 :            :  *
+      11                 :            :  *  [1] Handbook of Applied Cryptography - 1997, Chapter 12
+      12                 :            :  *      Menezes, van Oorschot and Vanstone
+      13                 :            :  *
+      14                 :            :  */
+      15                 :            : 
+      16                 :            : #include "common.h"
+      17                 :            : 
+      18                 :            : #if defined(MBEDTLS_DHM_C)
+      19                 :            : 
+      20                 :            : #include "mbedtls/dhm.h"
+      21                 :            : #include "mbedtls/platform_util.h"
+      22                 :            : #include "mbedtls/error.h"
+      23                 :            : 
+      24                 :            : #include <string.h>
+      25                 :            : 
+      26                 :            : #if defined(MBEDTLS_PEM_PARSE_C)
+      27                 :            : #include "mbedtls/pem.h"
+      28                 :            : #endif
+      29                 :            : 
+      30                 :            : #if defined(MBEDTLS_ASN1_PARSE_C)
+      31                 :            : #include "mbedtls/asn1.h"
+      32                 :            : #endif
+      33                 :            : 
+      34                 :            : #include "mbedtls/platform.h"
+      35                 :            : 
+      36                 :            : #if !defined(MBEDTLS_DHM_ALT)
+      37                 :            : 
+      38                 :            : /*
+      39                 :            :  * helper to validate the mbedtls_mpi size and import it
+      40                 :            :  */
+      41                 :          0 : static int dhm_read_bignum(mbedtls_mpi *X,
+      42                 :            :                            unsigned char **p,
+      43                 :            :                            const unsigned char *end)
+      44                 :            : {
+      45                 :            :     int ret, n;
+      46                 :            : 
+      47         [ #  # ]:          0 :     if (end - *p < 2) {
+      48                 :          0 :         return MBEDTLS_ERR_DHM_BAD_INPUT_DATA;
+      49                 :            :     }
+      50                 :            : 
+      51                 :          0 :     n = MBEDTLS_GET_UINT16_BE(*p, 0);
+      52                 :          0 :     (*p) += 2;
+      53                 :            : 
+      54         [ #  # ]:          0 :     if ((size_t) (end - *p) < (size_t) n) {
+      55                 :          0 :         return MBEDTLS_ERR_DHM_BAD_INPUT_DATA;
+      56                 :            :     }
+      57                 :            : 
+      58         [ #  # ]:          0 :     if ((ret = mbedtls_mpi_read_binary(X, *p, n)) != 0) {
+      59                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_DHM_READ_PARAMS_FAILED, ret);
+      60                 :            :     }
+      61                 :            : 
+      62                 :          0 :     (*p) += n;
+      63                 :            : 
+      64                 :          0 :     return 0;
+      65                 :            : }
+      66                 :            : 
+      67                 :            : /*
+      68                 :            :  * Verify sanity of parameter with regards to P
+      69                 :            :  *
+      70                 :            :  * Parameter should be: 2 <= public_param <= P - 2
+      71                 :            :  *
+      72                 :            :  * This means that we need to return an error if
+      73                 :            :  *              public_param < 2 or public_param > P-2
+      74                 :            :  *
+      75                 :            :  * For more information on the attack, see:
+      76                 :            :  *  http://www.cl.cam.ac.uk/~rja14/Papers/psandqs.pdf
+      77                 :            :  *  http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2005-2643
+      78                 :            :  */
+      79                 :          4 : static int dhm_check_range(const mbedtls_mpi *param, const mbedtls_mpi *P)
+      80                 :            : {
+      81                 :            :     mbedtls_mpi U;
+      82                 :          4 :     int ret = 0;
+      83                 :            : 
+      84                 :          4 :     mbedtls_mpi_init(&U);
+      85                 :            : 
+      86         [ -  + ]:          4 :     MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&U, P, 2));
+      87                 :            : 
+      88   [ +  -  +  - ]:          8 :     if (mbedtls_mpi_cmp_int(param, 2) < 0 ||
+      89                 :          4 :         mbedtls_mpi_cmp_mpi(param, &U) > 0) {
+      90                 :          0 :         ret = MBEDTLS_ERR_DHM_BAD_INPUT_DATA;
+      91                 :            :     }
+      92                 :            : 
+      93                 :          4 : cleanup:
+      94                 :          4 :     mbedtls_mpi_free(&U);
+      95                 :          4 :     return ret;
+      96                 :            : }
+      97                 :            : 
+      98                 :          2 : void mbedtls_dhm_init(mbedtls_dhm_context *ctx)
+      99                 :            : {
+     100                 :          2 :     memset(ctx, 0, sizeof(mbedtls_dhm_context));
+     101                 :          2 : }
+     102                 :            : 
+     103                 :          0 : size_t mbedtls_dhm_get_bitlen(const mbedtls_dhm_context *ctx)
+     104                 :            : {
+     105                 :          0 :     return mbedtls_mpi_bitlen(&ctx->P);
+     106                 :            : }
+     107                 :            : 
+     108                 :          6 : size_t mbedtls_dhm_get_len(const mbedtls_dhm_context *ctx)
+     109                 :            : {
+     110                 :          6 :     return mbedtls_mpi_size(&ctx->P);
+     111                 :            : }
+     112                 :            : 
+     113                 :          0 : int mbedtls_dhm_get_value(const mbedtls_dhm_context *ctx,
+     114                 :            :                           mbedtls_dhm_parameter param,
+     115                 :            :                           mbedtls_mpi *dest)
+     116                 :            : {
+     117                 :          0 :     const mbedtls_mpi *src = NULL;
+     118   [ #  #  #  #  :          0 :     switch (param) {
+                #  #  # ]
+     119                 :          0 :         case MBEDTLS_DHM_PARAM_P:
+     120                 :          0 :             src = &ctx->P;
+     121                 :          0 :             break;
+     122                 :          0 :         case MBEDTLS_DHM_PARAM_G:
+     123                 :          0 :             src = &ctx->G;
+     124                 :          0 :             break;
+     125                 :          0 :         case MBEDTLS_DHM_PARAM_X:
+     126                 :          0 :             src = &ctx->X;
+     127                 :          0 :             break;
+     128                 :          0 :         case MBEDTLS_DHM_PARAM_GX:
+     129                 :          0 :             src = &ctx->GX;
+     130                 :          0 :             break;
+     131                 :          0 :         case MBEDTLS_DHM_PARAM_GY:
+     132                 :          0 :             src = &ctx->GY;
+     133                 :          0 :             break;
+     134                 :          0 :         case MBEDTLS_DHM_PARAM_K:
+     135                 :          0 :             src = &ctx->K;
+     136                 :          0 :             break;
+     137                 :          0 :         default:
+     138                 :          0 :             return MBEDTLS_ERR_DHM_BAD_INPUT_DATA;
+     139                 :            :     }
+     140                 :          0 :     return mbedtls_mpi_copy(dest, src);
+     141                 :            : }
+     142                 :            : 
+     143                 :            : /*
+     144                 :            :  * Parse the ServerKeyExchange parameters
+     145                 :            :  */
+     146                 :          0 : int mbedtls_dhm_read_params(mbedtls_dhm_context *ctx,
+     147                 :            :                             unsigned char **p,
+     148                 :            :                             const unsigned char *end)
+     149                 :            : {
+     150                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     151                 :            : 
+     152   [ #  #  #  # ]:          0 :     if ((ret = dhm_read_bignum(&ctx->P,  p, end)) != 0 ||
+     153         [ #  # ]:          0 :         (ret = dhm_read_bignum(&ctx->G,  p, end)) != 0 ||
+     154                 :          0 :         (ret = dhm_read_bignum(&ctx->GY, p, end)) != 0) {
+     155                 :          0 :         return ret;
+     156                 :            :     }
+     157                 :            : 
+     158         [ #  # ]:          0 :     if ((ret = dhm_check_range(&ctx->GY, &ctx->P)) != 0) {
+     159                 :          0 :         return ret;
+     160                 :            :     }
+     161                 :            : 
+     162                 :          0 :     return 0;
+     163                 :            : }
+     164                 :            : 
+     165                 :            : /*
+     166                 :            :  * Pick a random R in the range [2, M-2] for blinding or key generation.
+     167                 :            :  */
+     168                 :          2 : static int dhm_random_below(mbedtls_mpi *R, const mbedtls_mpi *M,
+     169                 :            :                             int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
+     170                 :            : {
+     171                 :            :     int ret;
+     172                 :            : 
+     173         [ -  + ]:          2 :     MBEDTLS_MPI_CHK(mbedtls_mpi_random(R, 3, M, f_rng, p_rng));
+     174         [ +  - ]:          2 :     MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(R, R, 1));
+     175                 :            : 
+     176                 :          2 : cleanup:
+     177                 :          2 :     return ret;
+     178                 :            : }
+     179                 :            : 
+     180                 :          2 : static int dhm_make_common(mbedtls_dhm_context *ctx, int x_size,
+     181                 :            :                            int (*f_rng)(void *, unsigned char *, size_t),
+     182                 :            :                            void *p_rng)
+     183                 :            : {
+     184                 :          2 :     int ret = 0;
+     185                 :            : 
+     186         [ -  + ]:          2 :     if (mbedtls_mpi_cmp_int(&ctx->P, 0) == 0) {
+     187                 :          0 :         return MBEDTLS_ERR_DHM_BAD_INPUT_DATA;
+     188                 :            :     }
+     189         [ -  + ]:          2 :     if (x_size < 0) {
+     190                 :          0 :         return MBEDTLS_ERR_DHM_BAD_INPUT_DATA;
+     191                 :            :     }
+     192                 :            : 
+     193         [ -  + ]:          2 :     if ((unsigned) x_size < mbedtls_mpi_size(&ctx->P)) {
+     194         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_fill_random(&ctx->X, x_size, f_rng, p_rng));
+     195                 :            :     } else {
+     196                 :            :         /* Generate X as large as possible ( <= P - 2 ) */
+     197                 :          2 :         ret = dhm_random_below(&ctx->X, &ctx->P, f_rng, p_rng);
+     198         [ -  + ]:          2 :         if (ret == MBEDTLS_ERR_MPI_NOT_ACCEPTABLE) {
+     199                 :          0 :             return MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED;
+     200                 :            :         }
+     201         [ -  + ]:          2 :         if (ret != 0) {
+     202                 :          0 :             return ret;
+     203                 :            :         }
+     204                 :            :     }
+     205                 :            : 
+     206                 :            :     /*
+     207                 :            :      * Calculate GX = G^X mod P
+     208                 :            :      */
+     209         [ -  + ]:          2 :     MBEDTLS_MPI_CHK(mbedtls_mpi_exp_mod(&ctx->GX, &ctx->G, &ctx->X,
+     210                 :            :                                         &ctx->P, &ctx->RP));
+     211                 :            : 
+     212         [ -  + ]:          2 :     if ((ret = dhm_check_range(&ctx->GX, &ctx->P)) != 0) {
+     213                 :          0 :         return ret;
+     214                 :            :     }
+     215                 :            : 
+     216                 :          2 : cleanup:
+     217                 :          2 :     return ret;
+     218                 :            : }
+     219                 :            : 
+     220                 :            : /*
+     221                 :            :  * Setup and write the ServerKeyExchange parameters
+     222                 :            :  */
+     223                 :          0 : int mbedtls_dhm_make_params(mbedtls_dhm_context *ctx, int x_size,
+     224                 :            :                             unsigned char *output, size_t *olen,
+     225                 :            :                             int (*f_rng)(void *, unsigned char *, size_t),
+     226                 :            :                             void *p_rng)
+     227                 :            : {
+     228                 :            :     int ret;
+     229                 :            :     size_t n1, n2, n3;
+     230                 :            :     unsigned char *p;
+     231                 :            : 
+     232                 :          0 :     ret = dhm_make_common(ctx, x_size, f_rng, p_rng);
+     233         [ #  # ]:          0 :     if (ret != 0) {
+     234                 :          0 :         goto cleanup;
+     235                 :            :     }
+     236                 :            : 
+     237                 :            :     /*
+     238                 :            :      * Export P, G, GX. RFC 5246 §4.4 states that "leading zero octets are
+     239                 :            :      * not required". We omit leading zeros for compactness.
+     240                 :            :      */
+     241                 :            : #define DHM_MPI_EXPORT(X, n)                                          \
+     242                 :            :     do {                                                                \
+     243                 :            :         MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary((X),               \
+     244                 :            :                                                  p + 2,               \
+     245                 :            :                                                  (n)));           \
+     246                 :            :         *p++ = MBEDTLS_BYTE_1(n);                                     \
+     247                 :            :         *p++ = MBEDTLS_BYTE_0(n);                                     \
+     248                 :            :         p += (n);                                                     \
+     249                 :            :     } while (0)
+     250                 :            : 
+     251                 :          0 :     n1 = mbedtls_mpi_size(&ctx->P);
+     252                 :          0 :     n2 = mbedtls_mpi_size(&ctx->G);
+     253                 :          0 :     n3 = mbedtls_mpi_size(&ctx->GX);
+     254                 :            : 
+     255                 :          0 :     p = output;
+     256         [ #  # ]:          0 :     DHM_MPI_EXPORT(&ctx->P, n1);
+     257         [ #  # ]:          0 :     DHM_MPI_EXPORT(&ctx->G, n2);
+     258         [ #  # ]:          0 :     DHM_MPI_EXPORT(&ctx->GX, n3);
+     259                 :            : 
+     260                 :          0 :     *olen = (size_t) (p - output);
+     261                 :            : 
+     262                 :          0 : cleanup:
+     263   [ #  #  #  # ]:          0 :     if (ret != 0 && ret > -128) {
+     264                 :          0 :         ret = MBEDTLS_ERROR_ADD(MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED, ret);
+     265                 :            :     }
+     266                 :          0 :     return ret;
+     267                 :            : }
+     268                 :            : 
+     269                 :            : /*
+     270                 :            :  * Set prime modulus and generator
+     271                 :            :  */
+     272                 :          0 : int mbedtls_dhm_set_group(mbedtls_dhm_context *ctx,
+     273                 :            :                           const mbedtls_mpi *P,
+     274                 :            :                           const mbedtls_mpi *G)
+     275                 :            : {
+     276                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     277                 :            : 
+     278   [ #  #  #  # ]:          0 :     if ((ret = mbedtls_mpi_copy(&ctx->P, P)) != 0 ||
+     279                 :          0 :         (ret = mbedtls_mpi_copy(&ctx->G, G)) != 0) {
+     280                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_DHM_SET_GROUP_FAILED, ret);
+     281                 :            :     }
+     282                 :            : 
+     283                 :          0 :     return 0;
+     284                 :            : }
+     285                 :            : 
+     286                 :            : /*
+     287                 :            :  * Import the peer's public value G^Y
+     288                 :            :  */
+     289                 :          2 : int mbedtls_dhm_read_public(mbedtls_dhm_context *ctx,
+     290                 :            :                             const unsigned char *input, size_t ilen)
+     291                 :            : {
+     292                 :          2 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     293                 :            : 
+     294   [ +  -  -  + ]:          2 :     if (ilen < 1 || ilen > mbedtls_dhm_get_len(ctx)) {
+     295                 :          0 :         return MBEDTLS_ERR_DHM_BAD_INPUT_DATA;
+     296                 :            :     }
+     297                 :            : 
+     298         [ -  + ]:          2 :     if ((ret = mbedtls_mpi_read_binary(&ctx->GY, input, ilen)) != 0) {
+     299                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED, ret);
+     300                 :            :     }
+     301                 :            : 
+     302                 :          2 :     return 0;
+     303                 :            : }
+     304                 :            : 
+     305                 :            : /*
+     306                 :            :  * Create own private value X and export G^X
+     307                 :            :  */
+     308                 :          2 : int mbedtls_dhm_make_public(mbedtls_dhm_context *ctx, int x_size,
+     309                 :            :                             unsigned char *output, size_t olen,
+     310                 :            :                             int (*f_rng)(void *, unsigned char *, size_t),
+     311                 :            :                             void *p_rng)
+     312                 :            : {
+     313                 :            :     int ret;
+     314                 :            : 
+     315   [ +  -  -  + ]:          2 :     if (olen < 1 || olen > mbedtls_dhm_get_len(ctx)) {
+     316                 :          0 :         return MBEDTLS_ERR_DHM_BAD_INPUT_DATA;
+     317                 :            :     }
+     318                 :            : 
+     319                 :          2 :     ret = dhm_make_common(ctx, x_size, f_rng, p_rng);
+     320         [ -  + ]:          2 :     if (ret == MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED) {
+     321                 :          0 :         return MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED;
+     322                 :            :     }
+     323         [ -  + ]:          2 :     if (ret != 0) {
+     324                 :          0 :         goto cleanup;
+     325                 :            :     }
+     326                 :            : 
+     327         [ +  - ]:          2 :     MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(&ctx->GX, output, olen));
+     328                 :            : 
+     329                 :          2 : cleanup:
+     330   [ -  +  -  - ]:          2 :     if (ret != 0 && ret > -128) {
+     331                 :          0 :         ret = MBEDTLS_ERROR_ADD(MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED, ret);
+     332                 :            :     }
+     333                 :          2 :     return ret;
+     334                 :            : }
+     335                 :            : 
+     336                 :            : 
+     337                 :            : /*
+     338                 :            :  * Use the blinding method and optimisation suggested in section 10 of:
+     339                 :            :  *  KOCHER, Paul C. Timing attacks on implementations of Diffie-Hellman, RSA,
+     340                 :            :  *  DSS, and other systems. In : Advances in Cryptology-CRYPTO'96. Springer
+     341                 :            :  *  Berlin Heidelberg, 1996. p. 104-113.
+     342                 :            :  */
+     343                 :          2 : static int dhm_update_blinding(mbedtls_dhm_context *ctx,
+     344                 :            :                                int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
+     345                 :            : {
+     346                 :            :     int ret;
+     347                 :            :     mbedtls_mpi R;
+     348                 :            : 
+     349                 :          2 :     mbedtls_mpi_init(&R);
+     350                 :            : 
+     351                 :            :     /*
+     352                 :            :      * Don't use any blinding the first time a particular X is used,
+     353                 :            :      * but remember it to use blinding next time.
+     354                 :            :      */
+     355         [ +  - ]:          2 :     if (mbedtls_mpi_cmp_mpi(&ctx->X, &ctx->pX) != 0) {
+     356         [ -  + ]:          2 :         MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&ctx->pX, &ctx->X));
+     357         [ -  + ]:          2 :         MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&ctx->Vi, 1));
+     358         [ -  + ]:          2 :         MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&ctx->Vf, 1));
+     359                 :            : 
+     360                 :          2 :         return 0;
+     361                 :            :     }
+     362                 :            : 
+     363                 :            :     /*
+     364                 :            :      * Ok, we need blinding. Can we re-use existing values?
+     365                 :            :      * If yes, just update them by squaring them.
+     366                 :            :      */
+     367         [ #  # ]:          0 :     if (mbedtls_mpi_cmp_int(&ctx->Vi, 1) != 0) {
+     368         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&ctx->Vi, &ctx->Vi, &ctx->Vi));
+     369         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&ctx->Vi, &ctx->Vi, &ctx->P));
+     370                 :            : 
+     371         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&ctx->Vf, &ctx->Vf, &ctx->Vf));
+     372         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&ctx->Vf, &ctx->Vf, &ctx->P));
+     373                 :            : 
+     374                 :          0 :         return 0;
+     375                 :            :     }
+     376                 :            : 
+     377                 :            :     /*
+     378                 :            :      * We need to generate blinding values from scratch
+     379                 :            :      */
+     380                 :            : 
+     381                 :            :     /* Vi = random( 2, P-2 ) */
+     382         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(dhm_random_below(&ctx->Vi, &ctx->P, f_rng, p_rng));
+     383                 :            : 
+     384                 :            :     /* Vf = Vi^-X mod P
+     385                 :            :      * First compute Vi^-1 = R * (R Vi)^-1, (avoiding leaks from inv_mod),
+     386                 :            :      * then elevate to the Xth power. */
+     387         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(dhm_random_below(&R, &ctx->P, f_rng, p_rng));
+     388         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&ctx->Vf, &ctx->Vi, &R));
+     389         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&ctx->Vf, &ctx->Vf, &ctx->P));
+     390         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_inv_mod(&ctx->Vf, &ctx->Vf, &ctx->P));
+     391         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&ctx->Vf, &ctx->Vf, &R));
+     392         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&ctx->Vf, &ctx->Vf, &ctx->P));
+     393                 :            : 
+     394         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_exp_mod(&ctx->Vf, &ctx->Vf, &ctx->X, &ctx->P, &ctx->RP));
+     395                 :            : 
+     396                 :          0 : cleanup:
+     397                 :          0 :     mbedtls_mpi_free(&R);
+     398                 :            : 
+     399                 :          0 :     return ret;
+     400                 :            : }
+     401                 :            : 
+     402                 :            : /*
+     403                 :            :  * Derive and export the shared secret (G^Y)^X mod P
+     404                 :            :  */
+     405                 :          2 : int mbedtls_dhm_calc_secret(mbedtls_dhm_context *ctx,
+     406                 :            :                             unsigned char *output, size_t output_size, size_t *olen,
+     407                 :            :                             int (*f_rng)(void *, unsigned char *, size_t),
+     408                 :            :                             void *p_rng)
+     409                 :            : {
+     410                 :          2 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     411                 :            :     mbedtls_mpi GYb;
+     412                 :            : 
+     413         [ -  + ]:          2 :     if (f_rng == NULL) {
+     414                 :          0 :         return MBEDTLS_ERR_DHM_BAD_INPUT_DATA;
+     415                 :            :     }
+     416                 :            : 
+     417         [ -  + ]:          2 :     if (output_size < mbedtls_dhm_get_len(ctx)) {
+     418                 :          0 :         return MBEDTLS_ERR_DHM_BAD_INPUT_DATA;
+     419                 :            :     }
+     420                 :            : 
+     421         [ -  + ]:          2 :     if ((ret = dhm_check_range(&ctx->GY, &ctx->P)) != 0) {
+     422                 :          0 :         return ret;
+     423                 :            :     }
+     424                 :            : 
+     425                 :          2 :     mbedtls_mpi_init(&GYb);
+     426                 :            : 
+     427                 :            :     /* Blind peer's value */
+     428         [ -  + ]:          2 :     MBEDTLS_MPI_CHK(dhm_update_blinding(ctx, f_rng, p_rng));
+     429         [ -  + ]:          2 :     MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&GYb, &ctx->GY, &ctx->Vi));
+     430         [ -  + ]:          2 :     MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&GYb, &GYb, &ctx->P));
+     431                 :            : 
+     432                 :            :     /* Do modular exponentiation */
+     433         [ -  + ]:          2 :     MBEDTLS_MPI_CHK(mbedtls_mpi_exp_mod(&ctx->K, &GYb, &ctx->X,
+     434                 :            :                                         &ctx->P, &ctx->RP));
+     435                 :            : 
+     436                 :            :     /* Unblind secret value */
+     437         [ -  + ]:          2 :     MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&ctx->K, &ctx->K, &ctx->Vf));
+     438         [ -  + ]:          2 :     MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&ctx->K, &ctx->K, &ctx->P));
+     439                 :            : 
+     440                 :            :     /* Output the secret without any leading zero byte. This is mandatory
+     441                 :            :      * for TLS per RFC 5246 §8.1.2. */
+     442                 :          2 :     *olen = mbedtls_mpi_size(&ctx->K);
+     443         [ +  - ]:          2 :     MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(&ctx->K, output, *olen));
+     444                 :            : 
+     445                 :          2 : cleanup:
+     446                 :          2 :     mbedtls_mpi_free(&GYb);
+     447                 :            : 
+     448         [ -  + ]:          2 :     if (ret != 0) {
+     449                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_DHM_CALC_SECRET_FAILED, ret);
+     450                 :            :     }
+     451                 :            : 
+     452                 :          2 :     return 0;
+     453                 :            : }
+     454                 :            : 
+     455                 :            : /*
+     456                 :            :  * Free the components of a DHM key
+     457                 :            :  */
+     458                 :          2 : void mbedtls_dhm_free(mbedtls_dhm_context *ctx)
+     459                 :            : {
+     460         [ -  + ]:          2 :     if (ctx == NULL) {
+     461                 :          0 :         return;
+     462                 :            :     }
+     463                 :            : 
+     464                 :          2 :     mbedtls_mpi_free(&ctx->pX);
+     465                 :          2 :     mbedtls_mpi_free(&ctx->Vf);
+     466                 :          2 :     mbedtls_mpi_free(&ctx->Vi);
+     467                 :          2 :     mbedtls_mpi_free(&ctx->RP);
+     468                 :          2 :     mbedtls_mpi_free(&ctx->K);
+     469                 :          2 :     mbedtls_mpi_free(&ctx->GY);
+     470                 :          2 :     mbedtls_mpi_free(&ctx->GX);
+     471                 :          2 :     mbedtls_mpi_free(&ctx->X);
+     472                 :          2 :     mbedtls_mpi_free(&ctx->G);
+     473                 :          2 :     mbedtls_mpi_free(&ctx->P);
+     474                 :            : 
+     475                 :          2 :     mbedtls_platform_zeroize(ctx, sizeof(mbedtls_dhm_context));
+     476                 :            : }
+     477                 :            : 
+     478                 :            : #if defined(MBEDTLS_ASN1_PARSE_C)
+     479                 :            : /*
+     480                 :            :  * Parse DHM parameters
+     481                 :            :  */
+     482                 :          0 : int mbedtls_dhm_parse_dhm(mbedtls_dhm_context *dhm, const unsigned char *dhmin,
+     483                 :            :                           size_t dhminlen)
+     484                 :            : {
+     485                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     486                 :            :     size_t len;
+     487                 :            :     unsigned char *p, *end;
+     488                 :            : #if defined(MBEDTLS_PEM_PARSE_C)
+     489                 :            :     mbedtls_pem_context pem;
+     490                 :            : #endif /* MBEDTLS_PEM_PARSE_C */
+     491                 :            : 
+     492                 :            : #if defined(MBEDTLS_PEM_PARSE_C)
+     493                 :          0 :     mbedtls_pem_init(&pem);
+     494                 :            : 
+     495                 :            :     /* Avoid calling mbedtls_pem_read_buffer() on non-null-terminated string */
+     496   [ #  #  #  # ]:          0 :     if (dhminlen == 0 || dhmin[dhminlen - 1] != '\0') {
+     497                 :          0 :         ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT;
+     498                 :            :     } else {
+     499                 :          0 :         ret = mbedtls_pem_read_buffer(&pem,
+     500                 :            :                                       "-----BEGIN DH PARAMETERS-----",
+     501                 :            :                                       "-----END DH PARAMETERS-----",
+     502                 :            :                                       dhmin, NULL, 0, &dhminlen);
+     503                 :            :     }
+     504                 :            : 
+     505         [ #  # ]:          0 :     if (ret == 0) {
+     506                 :            :         /*
+     507                 :            :          * Was PEM encoded
+     508                 :            :          */
+     509                 :          0 :         dhminlen = pem.buflen;
+     510         [ #  # ]:          0 :     } else if (ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) {
+     511                 :          0 :         goto exit;
+     512                 :            :     }
+     513                 :            : 
+     514         [ #  # ]:          0 :     p = (ret == 0) ? pem.buf : (unsigned char *) dhmin;
+     515                 :            : #else
+     516                 :            :     p = (unsigned char *) dhmin;
+     517                 :            : #endif /* MBEDTLS_PEM_PARSE_C */
+     518                 :          0 :     end = p + dhminlen;
+     519                 :            : 
+     520                 :            :     /*
+     521                 :            :      *  DHParams ::= SEQUENCE {
+     522                 :            :      *      prime              INTEGER,  -- P
+     523                 :            :      *      generator          INTEGER,  -- g
+     524                 :            :      *      privateValueLength INTEGER OPTIONAL
+     525                 :            :      *  }
+     526                 :            :      */
+     527         [ #  # ]:          0 :     if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
+     528                 :            :                                     MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
+     529                 :          0 :         ret = MBEDTLS_ERROR_ADD(MBEDTLS_ERR_DHM_INVALID_FORMAT, ret);
+     530                 :          0 :         goto exit;
+     531                 :            :     }
+     532                 :            : 
+     533                 :          0 :     end = p + len;
+     534                 :            : 
+     535   [ #  #  #  # ]:          0 :     if ((ret = mbedtls_asn1_get_mpi(&p, end, &dhm->P)) != 0 ||
+     536                 :          0 :         (ret = mbedtls_asn1_get_mpi(&p, end, &dhm->G)) != 0) {
+     537                 :          0 :         ret = MBEDTLS_ERROR_ADD(MBEDTLS_ERR_DHM_INVALID_FORMAT, ret);
+     538                 :          0 :         goto exit;
+     539                 :            :     }
+     540                 :            : 
+     541         [ #  # ]:          0 :     if (p != end) {
+     542                 :            :         /* This might be the optional privateValueLength.
+     543                 :            :          * If so, we can cleanly discard it */
+     544                 :            :         mbedtls_mpi rec;
+     545                 :          0 :         mbedtls_mpi_init(&rec);
+     546                 :          0 :         ret = mbedtls_asn1_get_mpi(&p, end, &rec);
+     547                 :          0 :         mbedtls_mpi_free(&rec);
+     548         [ #  # ]:          0 :         if (ret != 0) {
+     549                 :          0 :             ret = MBEDTLS_ERROR_ADD(MBEDTLS_ERR_DHM_INVALID_FORMAT, ret);
+     550                 :          0 :             goto exit;
+     551                 :            :         }
+     552         [ #  # ]:          0 :         if (p != end) {
+     553                 :          0 :             ret = MBEDTLS_ERROR_ADD(MBEDTLS_ERR_DHM_INVALID_FORMAT,
+     554                 :            :                                     MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
+     555                 :          0 :             goto exit;
+     556                 :            :         }
+     557                 :            :     }
+     558                 :            : 
+     559                 :          0 :     ret = 0;
+     560                 :            : 
+     561                 :          0 : exit:
+     562                 :            : #if defined(MBEDTLS_PEM_PARSE_C)
+     563                 :          0 :     mbedtls_pem_free(&pem);
+     564                 :            : #endif
+     565         [ #  # ]:          0 :     if (ret != 0) {
+     566                 :          0 :         mbedtls_dhm_free(dhm);
+     567                 :            :     }
+     568                 :            : 
+     569                 :          0 :     return ret;
+     570                 :            : }
+     571                 :            : 
+     572                 :            : #if defined(MBEDTLS_FS_IO)
+     573                 :            : /*
+     574                 :            :  * Load all data from a file into a given buffer.
+     575                 :            :  *
+     576                 :            :  * The file is expected to contain either PEM or DER encoded data.
+     577                 :            :  * A terminating null byte is always appended. It is included in the announced
+     578                 :            :  * length only if the data looks like it is PEM encoded.
+     579                 :            :  */
+     580                 :            : static int load_file(const char *path, unsigned char **buf, size_t *n)
+     581                 :            : {
+     582                 :            :     FILE *f;
+     583                 :            :     long size;
+     584                 :            : 
+     585                 :            :     if ((f = fopen(path, "rb")) == NULL) {
+     586                 :            :         return MBEDTLS_ERR_DHM_FILE_IO_ERROR;
+     587                 :            :     }
+     588                 :            :     /* The data loaded here is public, so don't bother disabling buffering. */
+     589                 :            : 
+     590                 :            :     fseek(f, 0, SEEK_END);
+     591                 :            :     if ((size = ftell(f)) == -1) {
+     592                 :            :         fclose(f);
+     593                 :            :         return MBEDTLS_ERR_DHM_FILE_IO_ERROR;
+     594                 :            :     }
+     595                 :            :     fseek(f, 0, SEEK_SET);
+     596                 :            : 
+     597                 :            :     *n = (size_t) size;
+     598                 :            : 
+     599                 :            :     if (*n + 1 == 0 ||
+     600                 :            :         (*buf = mbedtls_calloc(1, *n + 1)) == NULL) {
+     601                 :            :         fclose(f);
+     602                 :            :         return MBEDTLS_ERR_DHM_ALLOC_FAILED;
+     603                 :            :     }
+     604                 :            : 
+     605                 :            :     if (fread(*buf, 1, *n, f) != *n) {
+     606                 :            :         fclose(f);
+     607                 :            : 
+     608                 :            :         mbedtls_zeroize_and_free(*buf, *n + 1);
+     609                 :            : 
+     610                 :            :         return MBEDTLS_ERR_DHM_FILE_IO_ERROR;
+     611                 :            :     }
+     612                 :            : 
+     613                 :            :     fclose(f);
+     614                 :            : 
+     615                 :            :     (*buf)[*n] = '\0';
+     616                 :            : 
+     617                 :            :     if (strstr((const char *) *buf, "-----BEGIN ") != NULL) {
+     618                 :            :         ++*n;
+     619                 :            :     }
+     620                 :            : 
+     621                 :            :     return 0;
+     622                 :            : }
+     623                 :            : 
+     624                 :            : /*
+     625                 :            :  * Load and parse DHM parameters
+     626                 :            :  */
+     627                 :            : int mbedtls_dhm_parse_dhmfile(mbedtls_dhm_context *dhm, const char *path)
+     628                 :            : {
+     629                 :            :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     630                 :            :     size_t n;
+     631                 :            :     unsigned char *buf;
+     632                 :            : 
+     633                 :            :     if ((ret = load_file(path, &buf, &n)) != 0) {
+     634                 :            :         return ret;
+     635                 :            :     }
+     636                 :            : 
+     637                 :            :     ret = mbedtls_dhm_parse_dhm(dhm, buf, n);
+     638                 :            : 
+     639                 :            :     mbedtls_zeroize_and_free(buf, n);
+     640                 :            : 
+     641                 :            :     return ret;
+     642                 :            : }
+     643                 :            : #endif /* MBEDTLS_FS_IO */
+     644                 :            : #endif /* MBEDTLS_ASN1_PARSE_C */
+     645                 :            : #endif /* MBEDTLS_DHM_ALT */
+     646                 :            : 
+     647                 :            : #if defined(MBEDTLS_SELF_TEST)
+     648                 :            : 
+     649                 :            : #if defined(MBEDTLS_PEM_PARSE_C)
+     650                 :            : static const char mbedtls_test_dhm_params[] =
+     651                 :            :     "-----BEGIN DH PARAMETERS-----\r\n"
+     652                 :            :     "MIGHAoGBAJ419DBEOgmQTzo5qXl5fQcN9TN455wkOL7052HzxxRVMyhYmwQcgJvh\r\n"
+     653                 :            :     "1sa18fyfR9OiVEMYglOpkqVoGLN7qd5aQNNi5W7/C+VBdHTBJcGZJyyP5B3qcz32\r\n"
+     654                 :            :     "9mLJKudlVudV0Qxk5qUJaPZ/xupz0NyoVpviuiBOI1gNi8ovSXWzAgEC\r\n"
+     655                 :            :     "-----END DH PARAMETERS-----\r\n";
+     656                 :            : #else /* MBEDTLS_PEM_PARSE_C */
+     657                 :            : static const char mbedtls_test_dhm_params[] = {
+     658                 :            :     0x30, 0x81, 0x87, 0x02, 0x81, 0x81, 0x00, 0x9e, 0x35, 0xf4, 0x30, 0x44,
+     659                 :            :     0x3a, 0x09, 0x90, 0x4f, 0x3a, 0x39, 0xa9, 0x79, 0x79, 0x7d, 0x07, 0x0d,
+     660                 :            :     0xf5, 0x33, 0x78, 0xe7, 0x9c, 0x24, 0x38, 0xbe, 0xf4, 0xe7, 0x61, 0xf3,
+     661                 :            :     0xc7, 0x14, 0x55, 0x33, 0x28, 0x58, 0x9b, 0x04, 0x1c, 0x80, 0x9b, 0xe1,
+     662                 :            :     0xd6, 0xc6, 0xb5, 0xf1, 0xfc, 0x9f, 0x47, 0xd3, 0xa2, 0x54, 0x43, 0x18,
+     663                 :            :     0x82, 0x53, 0xa9, 0x92, 0xa5, 0x68, 0x18, 0xb3, 0x7b, 0xa9, 0xde, 0x5a,
+     664                 :            :     0x40, 0xd3, 0x62, 0xe5, 0x6e, 0xff, 0x0b, 0xe5, 0x41, 0x74, 0x74, 0xc1,
+     665                 :            :     0x25, 0xc1, 0x99, 0x27, 0x2c, 0x8f, 0xe4, 0x1d, 0xea, 0x73, 0x3d, 0xf6,
+     666                 :            :     0xf6, 0x62, 0xc9, 0x2a, 0xe7, 0x65, 0x56, 0xe7, 0x55, 0xd1, 0x0c, 0x64,
+     667                 :            :     0xe6, 0xa5, 0x09, 0x68, 0xf6, 0x7f, 0xc6, 0xea, 0x73, 0xd0, 0xdc, 0xa8,
+     668                 :            :     0x56, 0x9b, 0xe2, 0xba, 0x20, 0x4e, 0x23, 0x58, 0x0d, 0x8b, 0xca, 0x2f,
+     669                 :            :     0x49, 0x75, 0xb3, 0x02, 0x01, 0x02
+     670                 :            : };
+     671                 :            : #endif /* MBEDTLS_PEM_PARSE_C */
+     672                 :            : 
+     673                 :            : static const size_t mbedtls_test_dhm_params_len = sizeof(mbedtls_test_dhm_params);
+     674                 :            : 
+     675                 :            : /*
+     676                 :            :  * Checkup routine
+     677                 :            :  */
+     678                 :          0 : int mbedtls_dhm_self_test(int verbose)
+     679                 :            : {
+     680                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     681                 :            :     mbedtls_dhm_context dhm;
+     682                 :            : 
+     683                 :          0 :     mbedtls_dhm_init(&dhm);
+     684                 :            : 
+     685         [ #  # ]:          0 :     if (verbose != 0) {
+     686                 :          0 :         mbedtls_printf("  DHM parameter load: ");
+     687                 :            :     }
+     688                 :            : 
+     689         [ #  # ]:          0 :     if ((ret = mbedtls_dhm_parse_dhm(&dhm,
+     690                 :            :                                      (const unsigned char *) mbedtls_test_dhm_params,
+     691                 :            :                                      mbedtls_test_dhm_params_len)) != 0) {
+     692         [ #  # ]:          0 :         if (verbose != 0) {
+     693                 :          0 :             mbedtls_printf("failed\n");
+     694                 :            :         }
+     695                 :            : 
+     696                 :          0 :         ret = 1;
+     697                 :          0 :         goto exit;
+     698                 :            :     }
+     699                 :            : 
+     700         [ #  # ]:          0 :     if (verbose != 0) {
+     701                 :          0 :         mbedtls_printf("passed\n\n");
+     702                 :            :     }
+     703                 :            : 
+     704                 :          0 : exit:
+     705                 :          0 :     mbedtls_dhm_free(&dhm);
+     706                 :            : 
+     707                 :          0 :     return ret;
+     708                 :            : }
+     709                 :            : 
+     710                 :            : #endif /* MBEDTLS_SELF_TEST */
+     711                 :            : 
+     712                 :            : #endif /* MBEDTLS_DHM_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/ecdh.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ecdh.c.func-sort-c.html new file mode 100644 index 00000000000..4f644b7a008 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ecdh.c.func-sort-c.html @@ -0,0 +1,185 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/ecdh.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - ecdh.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:7616745.5 %
Date:2024-09-22 08:21:07Functions:142653.8 %
Branches:167421.6 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
ecdh_calc_secret_internal0
ecdh_make_params_internal0
ecdh_make_public_internal0
ecdh_read_params_internal0
ecdh_read_public_internal0
mbedtls_ecdh_calc_secret0
mbedtls_ecdh_can_do0
mbedtls_ecdh_enable_restart0
mbedtls_ecdh_make_params0
mbedtls_ecdh_make_public0
mbedtls_ecdh_read_params0
mbedtls_ecdh_read_public0
ecdh_compute_shared_restartable74
mbedtls_ecdh_compute_shared74
ecdh_gen_public_restartable164
mbedtls_ecdh_gen_public164
mbedtls_ecdh_get_grp_id435
ecdh_free_internal975
mbedtls_ecdh_free975
ecdh_get_params_internal1001
mbedtls_ecdh_get_params1001
mbedtls_ecdh_grp_id1001
ecdh_init_internal1167
ecdh_setup_internal1167
mbedtls_ecdh_init1167
mbedtls_ecdh_setup1167
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/ecdh.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ecdh.c.func.html new file mode 100644 index 00000000000..9ff69e1dcc5 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ecdh.c.func.html @@ -0,0 +1,185 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/ecdh.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - ecdh.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:7616745.5 %
Date:2024-09-22 08:21:07Functions:142653.8 %
Branches:167421.6 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
ecdh_calc_secret_internal0
ecdh_compute_shared_restartable74
ecdh_free_internal975
ecdh_gen_public_restartable164
ecdh_get_params_internal1001
ecdh_init_internal1167
ecdh_make_params_internal0
ecdh_make_public_internal0
ecdh_read_params_internal0
ecdh_read_public_internal0
ecdh_setup_internal1167
mbedtls_ecdh_calc_secret0
mbedtls_ecdh_can_do0
mbedtls_ecdh_compute_shared74
mbedtls_ecdh_enable_restart0
mbedtls_ecdh_free975
mbedtls_ecdh_gen_public164
mbedtls_ecdh_get_grp_id435
mbedtls_ecdh_get_params1001
mbedtls_ecdh_grp_id1001
mbedtls_ecdh_init1167
mbedtls_ecdh_make_params0
mbedtls_ecdh_make_public0
mbedtls_ecdh_read_params0
mbedtls_ecdh_read_public0
mbedtls_ecdh_setup1167
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/ecdh.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ecdh.c.gcov.html new file mode 100644 index 00000000000..cf35dca0a97 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ecdh.c.gcov.html @@ -0,0 +1,779 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/ecdh.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - ecdh.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:7616745.5 %
Date:2024-09-22 08:21:07Functions:142653.8 %
Branches:167421.6 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  *  Elliptic curve Diffie-Hellman
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  */
+       7                 :            : 
+       8                 :            : /*
+       9                 :            :  * References:
+      10                 :            :  *
+      11                 :            :  * SEC1 https://www.secg.org/sec1-v2.pdf
+      12                 :            :  * RFC 4492
+      13                 :            :  */
+      14                 :            : 
+      15                 :            : #include "common.h"
+      16                 :            : 
+      17                 :            : #if defined(MBEDTLS_ECDH_C)
+      18                 :            : 
+      19                 :            : #include "mbedtls/ecdh.h"
+      20                 :            : #include "mbedtls/platform_util.h"
+      21                 :            : #include "mbedtls/error.h"
+      22                 :            : 
+      23                 :            : #include <string.h>
+      24                 :            : 
+      25                 :            : #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
+      26                 :            : typedef mbedtls_ecdh_context mbedtls_ecdh_context_mbed;
+      27                 :            : #endif
+      28                 :            : 
+      29                 :       1001 : static mbedtls_ecp_group_id mbedtls_ecdh_grp_id(
+      30                 :            :     const mbedtls_ecdh_context *ctx)
+      31                 :            : {
+      32                 :            : #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
+      33                 :       1001 :     return ctx->grp.id;
+      34                 :            : #else
+      35                 :            :     return ctx->grp_id;
+      36                 :            : #endif
+      37                 :            : }
+      38                 :            : 
+      39                 :          0 : int mbedtls_ecdh_can_do(mbedtls_ecp_group_id gid)
+      40                 :            : {
+      41                 :            :     /* At this time, all groups support ECDH. */
+      42                 :            :     (void) gid;
+      43                 :          0 :     return 1;
+      44                 :            : }
+      45                 :            : 
+      46                 :            : #if !defined(MBEDTLS_ECDH_GEN_PUBLIC_ALT)
+      47                 :            : /*
+      48                 :            :  * Generate public key (restartable version)
+      49                 :            :  *
+      50                 :            :  * Note: this internal function relies on its caller preserving the value of
+      51                 :            :  * the output parameter 'd' across continuation calls. This would not be
+      52                 :            :  * acceptable for a public function but is OK here as we control call sites.
+      53                 :            :  */
+      54                 :        164 : static int ecdh_gen_public_restartable(mbedtls_ecp_group *grp,
+      55                 :            :                                        mbedtls_mpi *d, mbedtls_ecp_point *Q,
+      56                 :            :                                        int (*f_rng)(void *, unsigned char *, size_t),
+      57                 :            :                                        void *p_rng,
+      58                 :            :                                        mbedtls_ecp_restart_ctx *rs_ctx)
+      59                 :            : {
+      60                 :        164 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+      61                 :            : 
+      62                 :        164 :     int restarting = 0;
+      63                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+      64   [ -  +  -  - ]:        164 :     restarting = (rs_ctx != NULL && rs_ctx->rsm != NULL);
+      65                 :            : #endif
+      66                 :            :     /* If multiplication is in progress, we already generated a privkey */
+      67         [ +  - ]:        164 :     if (!restarting) {
+      68         [ -  + ]:        164 :         MBEDTLS_MPI_CHK(mbedtls_ecp_gen_privkey(grp, d, f_rng, p_rng));
+      69                 :            :     }
+      70                 :            : 
+      71         [ +  - ]:        164 :     MBEDTLS_MPI_CHK(mbedtls_ecp_mul_restartable(grp, Q, d, &grp->G,
+      72                 :            :                                                 f_rng, p_rng, rs_ctx));
+      73                 :            : 
+      74                 :        164 : cleanup:
+      75                 :        164 :     return ret;
+      76                 :            : }
+      77                 :            : 
+      78                 :            : /*
+      79                 :            :  * Generate public key
+      80                 :            :  */
+      81                 :        164 : int mbedtls_ecdh_gen_public(mbedtls_ecp_group *grp, mbedtls_mpi *d, mbedtls_ecp_point *Q,
+      82                 :            :                             int (*f_rng)(void *, unsigned char *, size_t),
+      83                 :            :                             void *p_rng)
+      84                 :            : {
+      85                 :        164 :     return ecdh_gen_public_restartable(grp, d, Q, f_rng, p_rng, NULL);
+      86                 :            : }
+      87                 :            : #endif /* !MBEDTLS_ECDH_GEN_PUBLIC_ALT */
+      88                 :            : 
+      89                 :            : #if !defined(MBEDTLS_ECDH_COMPUTE_SHARED_ALT)
+      90                 :            : /*
+      91                 :            :  * Compute shared secret (SEC1 3.3.1)
+      92                 :            :  */
+      93                 :         74 : static int ecdh_compute_shared_restartable(mbedtls_ecp_group *grp,
+      94                 :            :                                            mbedtls_mpi *z,
+      95                 :            :                                            const mbedtls_ecp_point *Q, const mbedtls_mpi *d,
+      96                 :            :                                            int (*f_rng)(void *, unsigned char *, size_t),
+      97                 :            :                                            void *p_rng,
+      98                 :            :                                            mbedtls_ecp_restart_ctx *rs_ctx)
+      99                 :            : {
+     100                 :         74 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     101                 :            :     mbedtls_ecp_point P;
+     102                 :            : 
+     103                 :         74 :     mbedtls_ecp_point_init(&P);
+     104                 :            : 
+     105         [ -  + ]:         74 :     MBEDTLS_MPI_CHK(mbedtls_ecp_mul_restartable(grp, &P, d, Q,
+     106                 :            :                                                 f_rng, p_rng, rs_ctx));
+     107                 :            : 
+     108         [ -  + ]:         74 :     if (mbedtls_ecp_is_zero(&P)) {
+     109                 :          0 :         ret = MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+     110                 :          0 :         goto cleanup;
+     111                 :            :     }
+     112                 :            : 
+     113         [ +  - ]:         74 :     MBEDTLS_MPI_CHK(mbedtls_mpi_copy(z, &P.X));
+     114                 :            : 
+     115                 :         74 : cleanup:
+     116                 :         74 :     mbedtls_ecp_point_free(&P);
+     117                 :            : 
+     118                 :         74 :     return ret;
+     119                 :            : }
+     120                 :            : 
+     121                 :            : /*
+     122                 :            :  * Compute shared secret (SEC1 3.3.1)
+     123                 :            :  */
+     124                 :         74 : int mbedtls_ecdh_compute_shared(mbedtls_ecp_group *grp, mbedtls_mpi *z,
+     125                 :            :                                 const mbedtls_ecp_point *Q, const mbedtls_mpi *d,
+     126                 :            :                                 int (*f_rng)(void *, unsigned char *, size_t),
+     127                 :            :                                 void *p_rng)
+     128                 :            : {
+     129                 :         74 :     return ecdh_compute_shared_restartable(grp, z, Q, d,
+     130                 :            :                                            f_rng, p_rng, NULL);
+     131                 :            : }
+     132                 :            : #endif /* !MBEDTLS_ECDH_COMPUTE_SHARED_ALT */
+     133                 :            : 
+     134                 :       1167 : static void ecdh_init_internal(mbedtls_ecdh_context_mbed *ctx)
+     135                 :            : {
+     136                 :       1167 :     mbedtls_ecp_group_init(&ctx->grp);
+     137                 :       1167 :     mbedtls_mpi_init(&ctx->d);
+     138                 :       1167 :     mbedtls_ecp_point_init(&ctx->Q);
+     139                 :       1167 :     mbedtls_ecp_point_init(&ctx->Qp);
+     140                 :       1167 :     mbedtls_mpi_init(&ctx->z);
+     141                 :            : 
+     142                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+     143                 :       1167 :     mbedtls_ecp_restart_init(&ctx->rs);
+     144                 :            : #endif
+     145                 :       1167 : }
+     146                 :            : 
+     147                 :        435 : mbedtls_ecp_group_id mbedtls_ecdh_get_grp_id(mbedtls_ecdh_context *ctx)
+     148                 :            : {
+     149                 :            : #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
+     150                 :        435 :     return ctx->MBEDTLS_PRIVATE(grp).id;
+     151                 :            : #else
+     152                 :            :     return ctx->MBEDTLS_PRIVATE(grp_id);
+     153                 :            : #endif
+     154                 :            : }
+     155                 :            : 
+     156                 :            : /*
+     157                 :            :  * Initialize context
+     158                 :            :  */
+     159                 :       1167 : void mbedtls_ecdh_init(mbedtls_ecdh_context *ctx)
+     160                 :            : {
+     161                 :            : #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
+     162                 :       1167 :     ecdh_init_internal(ctx);
+     163                 :       1167 :     mbedtls_ecp_point_init(&ctx->Vi);
+     164                 :       1167 :     mbedtls_ecp_point_init(&ctx->Vf);
+     165                 :       1167 :     mbedtls_mpi_init(&ctx->_d);
+     166                 :            : #else
+     167                 :            :     memset(ctx, 0, sizeof(mbedtls_ecdh_context));
+     168                 :            : 
+     169                 :            :     ctx->var = MBEDTLS_ECDH_VARIANT_NONE;
+     170                 :            : #endif
+     171                 :       1167 :     ctx->point_format = MBEDTLS_ECP_PF_UNCOMPRESSED;
+     172                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+     173                 :       1167 :     ctx->restart_enabled = 0;
+     174                 :            : #endif
+     175                 :       1167 : }
+     176                 :            : 
+     177                 :       1167 : static int ecdh_setup_internal(mbedtls_ecdh_context_mbed *ctx,
+     178                 :            :                                mbedtls_ecp_group_id grp_id)
+     179                 :            : {
+     180                 :       1167 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     181                 :            : 
+     182                 :       1167 :     ret = mbedtls_ecp_group_load(&ctx->grp, grp_id);
+     183         [ -  + ]:       1167 :     if (ret != 0) {
+     184                 :          0 :         return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
+     185                 :            :     }
+     186                 :            : 
+     187                 :       1167 :     return 0;
+     188                 :            : }
+     189                 :            : 
+     190                 :            : /*
+     191                 :            :  * Setup context
+     192                 :            :  */
+     193                 :       1167 : int mbedtls_ecdh_setup(mbedtls_ecdh_context *ctx, mbedtls_ecp_group_id grp_id)
+     194                 :            : {
+     195                 :            : #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
+     196                 :       1167 :     return ecdh_setup_internal(ctx, grp_id);
+     197                 :            : #else
+     198                 :            :     switch (grp_id) {
+     199                 :            : #if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
+     200                 :            :         case MBEDTLS_ECP_DP_CURVE25519:
+     201                 :            :             ctx->point_format = MBEDTLS_ECP_PF_COMPRESSED;
+     202                 :            :             ctx->var = MBEDTLS_ECDH_VARIANT_EVEREST;
+     203                 :            :             ctx->grp_id = grp_id;
+     204                 :            :             return mbedtls_everest_setup(&ctx->ctx.everest_ecdh, grp_id);
+     205                 :            : #endif
+     206                 :            :         default:
+     207                 :            :             ctx->point_format = MBEDTLS_ECP_PF_UNCOMPRESSED;
+     208                 :            :             ctx->var = MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0;
+     209                 :            :             ctx->grp_id = grp_id;
+     210                 :            :             ecdh_init_internal(&ctx->ctx.mbed_ecdh);
+     211                 :            :             return ecdh_setup_internal(&ctx->ctx.mbed_ecdh, grp_id);
+     212                 :            :     }
+     213                 :            : #endif
+     214                 :            : }
+     215                 :            : 
+     216                 :        975 : static void ecdh_free_internal(mbedtls_ecdh_context_mbed *ctx)
+     217                 :            : {
+     218                 :        975 :     mbedtls_ecp_group_free(&ctx->grp);
+     219                 :        975 :     mbedtls_mpi_free(&ctx->d);
+     220                 :        975 :     mbedtls_ecp_point_free(&ctx->Q);
+     221                 :        975 :     mbedtls_ecp_point_free(&ctx->Qp);
+     222                 :        975 :     mbedtls_mpi_free(&ctx->z);
+     223                 :            : 
+     224                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+     225                 :        975 :     mbedtls_ecp_restart_free(&ctx->rs);
+     226                 :            : #endif
+     227                 :        975 : }
+     228                 :            : 
+     229                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+     230                 :            : /*
+     231                 :            :  * Enable restartable operations for context
+     232                 :            :  */
+     233                 :          0 : void mbedtls_ecdh_enable_restart(mbedtls_ecdh_context *ctx)
+     234                 :            : {
+     235                 :          0 :     ctx->restart_enabled = 1;
+     236                 :          0 : }
+     237                 :            : #endif
+     238                 :            : 
+     239                 :            : /*
+     240                 :            :  * Free context
+     241                 :            :  */
+     242                 :        975 : void mbedtls_ecdh_free(mbedtls_ecdh_context *ctx)
+     243                 :            : {
+     244         [ -  + ]:        975 :     if (ctx == NULL) {
+     245                 :          0 :         return;
+     246                 :            :     }
+     247                 :            : 
+     248                 :            : #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
+     249                 :        975 :     mbedtls_ecp_point_free(&ctx->Vi);
+     250                 :        975 :     mbedtls_ecp_point_free(&ctx->Vf);
+     251                 :        975 :     mbedtls_mpi_free(&ctx->_d);
+     252                 :        975 :     ecdh_free_internal(ctx);
+     253                 :            : #else
+     254                 :            :     switch (ctx->var) {
+     255                 :            : #if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
+     256                 :            :         case MBEDTLS_ECDH_VARIANT_EVEREST:
+     257                 :            :             mbedtls_everest_free(&ctx->ctx.everest_ecdh);
+     258                 :            :             break;
+     259                 :            : #endif
+     260                 :            :         case MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0:
+     261                 :            :             ecdh_free_internal(&ctx->ctx.mbed_ecdh);
+     262                 :            :             break;
+     263                 :            :         default:
+     264                 :            :             break;
+     265                 :            :     }
+     266                 :            : 
+     267                 :            :     ctx->point_format = MBEDTLS_ECP_PF_UNCOMPRESSED;
+     268                 :            :     ctx->var = MBEDTLS_ECDH_VARIANT_NONE;
+     269                 :            :     ctx->grp_id = MBEDTLS_ECP_DP_NONE;
+     270                 :            : #endif
+     271                 :            : }
+     272                 :            : 
+     273                 :          0 : static int ecdh_make_params_internal(mbedtls_ecdh_context_mbed *ctx,
+     274                 :            :                                      size_t *olen, int point_format,
+     275                 :            :                                      unsigned char *buf, size_t blen,
+     276                 :            :                                      int (*f_rng)(void *,
+     277                 :            :                                                   unsigned char *,
+     278                 :            :                                                   size_t),
+     279                 :            :                                      void *p_rng,
+     280                 :            :                                      int restart_enabled)
+     281                 :            : {
+     282                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     283                 :            :     size_t grp_len, pt_len;
+     284                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+     285                 :          0 :     mbedtls_ecp_restart_ctx *rs_ctx = NULL;
+     286                 :            : #endif
+     287                 :            : 
+     288         [ #  # ]:          0 :     if (ctx->grp.pbits == 0) {
+     289                 :          0 :         return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+     290                 :            :     }
+     291                 :            : 
+     292                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+     293         [ #  # ]:          0 :     if (restart_enabled) {
+     294                 :          0 :         rs_ctx = &ctx->rs;
+     295                 :            :     }
+     296                 :            : #else
+     297                 :            :     (void) restart_enabled;
+     298                 :            : #endif
+     299                 :            : 
+     300                 :            : 
+     301                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+     302         [ #  # ]:          0 :     if ((ret = ecdh_gen_public_restartable(&ctx->grp, &ctx->d, &ctx->Q,
+     303                 :            :                                            f_rng, p_rng, rs_ctx)) != 0) {
+     304                 :          0 :         return ret;
+     305                 :            :     }
+     306                 :            : #else
+     307                 :            :     if ((ret = mbedtls_ecdh_gen_public(&ctx->grp, &ctx->d, &ctx->Q,
+     308                 :            :                                        f_rng, p_rng)) != 0) {
+     309                 :            :         return ret;
+     310                 :            :     }
+     311                 :            : #endif /* MBEDTLS_ECP_RESTARTABLE */
+     312                 :            : 
+     313         [ #  # ]:          0 :     if ((ret = mbedtls_ecp_tls_write_group(&ctx->grp, &grp_len, buf,
+     314                 :            :                                            blen)) != 0) {
+     315                 :          0 :         return ret;
+     316                 :            :     }
+     317                 :            : 
+     318                 :          0 :     buf += grp_len;
+     319                 :          0 :     blen -= grp_len;
+     320                 :            : 
+     321         [ #  # ]:          0 :     if ((ret = mbedtls_ecp_tls_write_point(&ctx->grp, &ctx->Q, point_format,
+     322                 :            :                                            &pt_len, buf, blen)) != 0) {
+     323                 :          0 :         return ret;
+     324                 :            :     }
+     325                 :            : 
+     326                 :          0 :     *olen = grp_len + pt_len;
+     327                 :          0 :     return 0;
+     328                 :            : }
+     329                 :            : 
+     330                 :            : /*
+     331                 :            :  * Setup and write the ServerKeyExchange parameters (RFC 4492)
+     332                 :            :  *      struct {
+     333                 :            :  *          ECParameters    curve_params;
+     334                 :            :  *          ECPoint         public;
+     335                 :            :  *      } ServerECDHParams;
+     336                 :            :  */
+     337                 :          0 : int mbedtls_ecdh_make_params(mbedtls_ecdh_context *ctx, size_t *olen,
+     338                 :            :                              unsigned char *buf, size_t blen,
+     339                 :            :                              int (*f_rng)(void *, unsigned char *, size_t),
+     340                 :            :                              void *p_rng)
+     341                 :            : {
+     342                 :          0 :     int restart_enabled = 0;
+     343                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+     344                 :          0 :     restart_enabled = ctx->restart_enabled;
+     345                 :            : #else
+     346                 :            :     (void) restart_enabled;
+     347                 :            : #endif
+     348                 :            : 
+     349                 :            : #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
+     350                 :          0 :     return ecdh_make_params_internal(ctx, olen, ctx->point_format, buf, blen,
+     351                 :            :                                      f_rng, p_rng, restart_enabled);
+     352                 :            : #else
+     353                 :            :     switch (ctx->var) {
+     354                 :            : #if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
+     355                 :            :         case MBEDTLS_ECDH_VARIANT_EVEREST:
+     356                 :            :             return mbedtls_everest_make_params(&ctx->ctx.everest_ecdh, olen,
+     357                 :            :                                                buf, blen, f_rng, p_rng);
+     358                 :            : #endif
+     359                 :            :         case MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0:
+     360                 :            :             return ecdh_make_params_internal(&ctx->ctx.mbed_ecdh, olen,
+     361                 :            :                                              ctx->point_format, buf, blen,
+     362                 :            :                                              f_rng, p_rng,
+     363                 :            :                                              restart_enabled);
+     364                 :            :         default:
+     365                 :            :             return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+     366                 :            :     }
+     367                 :            : #endif
+     368                 :            : }
+     369                 :            : 
+     370                 :          0 : static int ecdh_read_params_internal(mbedtls_ecdh_context_mbed *ctx,
+     371                 :            :                                      const unsigned char **buf,
+     372                 :            :                                      const unsigned char *end)
+     373                 :            : {
+     374                 :          0 :     return mbedtls_ecp_tls_read_point(&ctx->grp, &ctx->Qp, buf,
+     375                 :          0 :                                       (size_t) (end - *buf));
+     376                 :            : }
+     377                 :            : 
+     378                 :            : /*
+     379                 :            :  * Read the ServerKeyExchange parameters (RFC 4492)
+     380                 :            :  *      struct {
+     381                 :            :  *          ECParameters    curve_params;
+     382                 :            :  *          ECPoint         public;
+     383                 :            :  *      } ServerECDHParams;
+     384                 :            :  */
+     385                 :          0 : int mbedtls_ecdh_read_params(mbedtls_ecdh_context *ctx,
+     386                 :            :                              const unsigned char **buf,
+     387                 :            :                              const unsigned char *end)
+     388                 :            : {
+     389                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     390                 :            :     mbedtls_ecp_group_id grp_id;
+     391         [ #  # ]:          0 :     if ((ret = mbedtls_ecp_tls_read_group_id(&grp_id, buf, (size_t) (end - *buf)))
+     392                 :            :         != 0) {
+     393                 :          0 :         return ret;
+     394                 :            :     }
+     395                 :            : 
+     396         [ #  # ]:          0 :     if ((ret = mbedtls_ecdh_setup(ctx, grp_id)) != 0) {
+     397                 :          0 :         return ret;
+     398                 :            :     }
+     399                 :            : 
+     400                 :            : #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
+     401                 :          0 :     return ecdh_read_params_internal(ctx, buf, end);
+     402                 :            : #else
+     403                 :            :     switch (ctx->var) {
+     404                 :            : #if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
+     405                 :            :         case MBEDTLS_ECDH_VARIANT_EVEREST:
+     406                 :            :             return mbedtls_everest_read_params(&ctx->ctx.everest_ecdh,
+     407                 :            :                                                buf, end);
+     408                 :            : #endif
+     409                 :            :         case MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0:
+     410                 :            :             return ecdh_read_params_internal(&ctx->ctx.mbed_ecdh,
+     411                 :            :                                              buf, end);
+     412                 :            :         default:
+     413                 :            :             return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+     414                 :            :     }
+     415                 :            : #endif
+     416                 :            : }
+     417                 :            : 
+     418                 :       1001 : static int ecdh_get_params_internal(mbedtls_ecdh_context_mbed *ctx,
+     419                 :            :                                     const mbedtls_ecp_keypair *key,
+     420                 :            :                                     mbedtls_ecdh_side side)
+     421                 :            : {
+     422                 :       1001 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     423                 :            : 
+     424                 :            :     /* If it's not our key, just import the public part as Qp */
+     425         [ -  + ]:       1001 :     if (side == MBEDTLS_ECDH_THEIRS) {
+     426                 :          0 :         return mbedtls_ecp_copy(&ctx->Qp, &key->Q);
+     427                 :            :     }
+     428                 :            : 
+     429                 :            :     /* Our key: import public (as Q) and private parts */
+     430         [ -  + ]:       1001 :     if (side != MBEDTLS_ECDH_OURS) {
+     431                 :          0 :         return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+     432                 :            :     }
+     433                 :            : 
+     434   [ +  -  -  + ]:       2002 :     if ((ret = mbedtls_ecp_copy(&ctx->Q, &key->Q)) != 0 ||
+     435                 :       1001 :         (ret = mbedtls_mpi_copy(&ctx->d, &key->d)) != 0) {
+     436                 :          0 :         return ret;
+     437                 :            :     }
+     438                 :            : 
+     439                 :       1001 :     return 0;
+     440                 :            : }
+     441                 :            : 
+     442                 :            : /*
+     443                 :            :  * Get parameters from a keypair
+     444                 :            :  */
+     445                 :       1001 : int mbedtls_ecdh_get_params(mbedtls_ecdh_context *ctx,
+     446                 :            :                             const mbedtls_ecp_keypair *key,
+     447                 :            :                             mbedtls_ecdh_side side)
+     448                 :            : {
+     449                 :       1001 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     450   [ -  +  -  - ]:       1001 :     if (side != MBEDTLS_ECDH_OURS && side != MBEDTLS_ECDH_THEIRS) {
+     451                 :          0 :         return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+     452                 :            :     }
+     453                 :            : 
+     454         [ +  - ]:       1001 :     if (mbedtls_ecdh_grp_id(ctx) == MBEDTLS_ECP_DP_NONE) {
+     455                 :            :         /* This is the first call to get_params(). Set up the context
+     456                 :            :          * for use with the group. */
+     457         [ -  + ]:       1001 :         if ((ret = mbedtls_ecdh_setup(ctx, key->grp.id)) != 0) {
+     458                 :          0 :             return ret;
+     459                 :            :         }
+     460                 :            :     } else {
+     461                 :            :         /* This is not the first call to get_params(). Check that the
+     462                 :            :          * current key's group is the same as the context's, which was set
+     463                 :            :          * from the first key's group. */
+     464         [ #  # ]:          0 :         if (mbedtls_ecdh_grp_id(ctx) != key->grp.id) {
+     465                 :          0 :             return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+     466                 :            :         }
+     467                 :            :     }
+     468                 :            : 
+     469                 :            : #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
+     470                 :       1001 :     return ecdh_get_params_internal(ctx, key, side);
+     471                 :            : #else
+     472                 :            :     switch (ctx->var) {
+     473                 :            : #if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
+     474                 :            :         case MBEDTLS_ECDH_VARIANT_EVEREST:
+     475                 :            :         {
+     476                 :            :             mbedtls_everest_ecdh_side s = side == MBEDTLS_ECDH_OURS ?
+     477                 :            :                                           MBEDTLS_EVEREST_ECDH_OURS :
+     478                 :            :                                           MBEDTLS_EVEREST_ECDH_THEIRS;
+     479                 :            :             return mbedtls_everest_get_params(&ctx->ctx.everest_ecdh,
+     480                 :            :                                               key, s);
+     481                 :            :         }
+     482                 :            : #endif
+     483                 :            :         case MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0:
+     484                 :            :             return ecdh_get_params_internal(&ctx->ctx.mbed_ecdh,
+     485                 :            :                                             key, side);
+     486                 :            :         default:
+     487                 :            :             return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+     488                 :            :     }
+     489                 :            : #endif
+     490                 :            : }
+     491                 :            : 
+     492                 :          0 : static int ecdh_make_public_internal(mbedtls_ecdh_context_mbed *ctx,
+     493                 :            :                                      size_t *olen, int point_format,
+     494                 :            :                                      unsigned char *buf, size_t blen,
+     495                 :            :                                      int (*f_rng)(void *,
+     496                 :            :                                                   unsigned char *,
+     497                 :            :                                                   size_t),
+     498                 :            :                                      void *p_rng,
+     499                 :            :                                      int restart_enabled)
+     500                 :            : {
+     501                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     502                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+     503                 :          0 :     mbedtls_ecp_restart_ctx *rs_ctx = NULL;
+     504                 :            : #endif
+     505                 :            : 
+     506         [ #  # ]:          0 :     if (ctx->grp.pbits == 0) {
+     507                 :          0 :         return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+     508                 :            :     }
+     509                 :            : 
+     510                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+     511         [ #  # ]:          0 :     if (restart_enabled) {
+     512                 :          0 :         rs_ctx = &ctx->rs;
+     513                 :            :     }
+     514                 :            : #else
+     515                 :            :     (void) restart_enabled;
+     516                 :            : #endif
+     517                 :            : 
+     518                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+     519         [ #  # ]:          0 :     if ((ret = ecdh_gen_public_restartable(&ctx->grp, &ctx->d, &ctx->Q,
+     520                 :            :                                            f_rng, p_rng, rs_ctx)) != 0) {
+     521                 :          0 :         return ret;
+     522                 :            :     }
+     523                 :            : #else
+     524                 :            :     if ((ret = mbedtls_ecdh_gen_public(&ctx->grp, &ctx->d, &ctx->Q,
+     525                 :            :                                        f_rng, p_rng)) != 0) {
+     526                 :            :         return ret;
+     527                 :            :     }
+     528                 :            : #endif /* MBEDTLS_ECP_RESTARTABLE */
+     529                 :            : 
+     530                 :          0 :     return mbedtls_ecp_tls_write_point(&ctx->grp, &ctx->Q, point_format, olen,
+     531                 :            :                                        buf, blen);
+     532                 :            : }
+     533                 :            : 
+     534                 :            : /*
+     535                 :            :  * Setup and export the client public value
+     536                 :            :  */
+     537                 :          0 : int mbedtls_ecdh_make_public(mbedtls_ecdh_context *ctx, size_t *olen,
+     538                 :            :                              unsigned char *buf, size_t blen,
+     539                 :            :                              int (*f_rng)(void *, unsigned char *, size_t),
+     540                 :            :                              void *p_rng)
+     541                 :            : {
+     542                 :          0 :     int restart_enabled = 0;
+     543                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+     544                 :          0 :     restart_enabled = ctx->restart_enabled;
+     545                 :            : #endif
+     546                 :            : 
+     547                 :            : #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
+     548                 :          0 :     return ecdh_make_public_internal(ctx, olen, ctx->point_format, buf, blen,
+     549                 :            :                                      f_rng, p_rng, restart_enabled);
+     550                 :            : #else
+     551                 :            :     switch (ctx->var) {
+     552                 :            : #if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
+     553                 :            :         case MBEDTLS_ECDH_VARIANT_EVEREST:
+     554                 :            :             return mbedtls_everest_make_public(&ctx->ctx.everest_ecdh, olen,
+     555                 :            :                                                buf, blen, f_rng, p_rng);
+     556                 :            : #endif
+     557                 :            :         case MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0:
+     558                 :            :             return ecdh_make_public_internal(&ctx->ctx.mbed_ecdh, olen,
+     559                 :            :                                              ctx->point_format, buf, blen,
+     560                 :            :                                              f_rng, p_rng,
+     561                 :            :                                              restart_enabled);
+     562                 :            :         default:
+     563                 :            :             return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+     564                 :            :     }
+     565                 :            : #endif
+     566                 :            : }
+     567                 :            : 
+     568                 :          0 : static int ecdh_read_public_internal(mbedtls_ecdh_context_mbed *ctx,
+     569                 :            :                                      const unsigned char *buf, size_t blen)
+     570                 :            : {
+     571                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     572                 :          0 :     const unsigned char *p = buf;
+     573                 :            : 
+     574         [ #  # ]:          0 :     if ((ret = mbedtls_ecp_tls_read_point(&ctx->grp, &ctx->Qp, &p,
+     575                 :            :                                           blen)) != 0) {
+     576                 :          0 :         return ret;
+     577                 :            :     }
+     578                 :            : 
+     579         [ #  # ]:          0 :     if ((size_t) (p - buf) != blen) {
+     580                 :          0 :         return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+     581                 :            :     }
+     582                 :            : 
+     583                 :          0 :     return 0;
+     584                 :            : }
+     585                 :            : 
+     586                 :            : /*
+     587                 :            :  * Parse and import the client's public value
+     588                 :            :  */
+     589                 :          0 : int mbedtls_ecdh_read_public(mbedtls_ecdh_context *ctx,
+     590                 :            :                              const unsigned char *buf, size_t blen)
+     591                 :            : {
+     592                 :            : #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
+     593                 :          0 :     return ecdh_read_public_internal(ctx, buf, blen);
+     594                 :            : #else
+     595                 :            :     switch (ctx->var) {
+     596                 :            : #if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
+     597                 :            :         case MBEDTLS_ECDH_VARIANT_EVEREST:
+     598                 :            :             return mbedtls_everest_read_public(&ctx->ctx.everest_ecdh,
+     599                 :            :                                                buf, blen);
+     600                 :            : #endif
+     601                 :            :         case MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0:
+     602                 :            :             return ecdh_read_public_internal(&ctx->ctx.mbed_ecdh,
+     603                 :            :                                              buf, blen);
+     604                 :            :         default:
+     605                 :            :             return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+     606                 :            :     }
+     607                 :            : #endif
+     608                 :            : }
+     609                 :            : 
+     610                 :          0 : static int ecdh_calc_secret_internal(mbedtls_ecdh_context_mbed *ctx,
+     611                 :            :                                      size_t *olen, unsigned char *buf,
+     612                 :            :                                      size_t blen,
+     613                 :            :                                      int (*f_rng)(void *,
+     614                 :            :                                                   unsigned char *,
+     615                 :            :                                                   size_t),
+     616                 :            :                                      void *p_rng,
+     617                 :            :                                      int restart_enabled)
+     618                 :            : {
+     619                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     620                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+     621                 :          0 :     mbedtls_ecp_restart_ctx *rs_ctx = NULL;
+     622                 :            : #endif
+     623                 :            : 
+     624   [ #  #  #  # ]:          0 :     if (ctx == NULL || ctx->grp.pbits == 0) {
+     625                 :          0 :         return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+     626                 :            :     }
+     627                 :            : 
+     628                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+     629         [ #  # ]:          0 :     if (restart_enabled) {
+     630                 :          0 :         rs_ctx = &ctx->rs;
+     631                 :            :     }
+     632                 :            : #else
+     633                 :            :     (void) restart_enabled;
+     634                 :            : #endif
+     635                 :            : 
+     636                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+     637         [ #  # ]:          0 :     if ((ret = ecdh_compute_shared_restartable(&ctx->grp, &ctx->z, &ctx->Qp,
+     638                 :          0 :                                                &ctx->d, f_rng, p_rng,
+     639                 :            :                                                rs_ctx)) != 0) {
+     640                 :          0 :         return ret;
+     641                 :            :     }
+     642                 :            : #else
+     643                 :            :     if ((ret = mbedtls_ecdh_compute_shared(&ctx->grp, &ctx->z, &ctx->Qp,
+     644                 :            :                                            &ctx->d, f_rng, p_rng)) != 0) {
+     645                 :            :         return ret;
+     646                 :            :     }
+     647                 :            : #endif /* MBEDTLS_ECP_RESTARTABLE */
+     648                 :            : 
+     649         [ #  # ]:          0 :     if (mbedtls_mpi_size(&ctx->z) > blen) {
+     650                 :          0 :         return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+     651                 :            :     }
+     652                 :            : 
+     653                 :          0 :     *olen = ctx->grp.pbits / 8 + ((ctx->grp.pbits % 8) != 0);
+     654                 :            : 
+     655         [ #  # ]:          0 :     if (mbedtls_ecp_get_type(&ctx->grp) == MBEDTLS_ECP_TYPE_MONTGOMERY) {
+     656                 :          0 :         return mbedtls_mpi_write_binary_le(&ctx->z, buf, *olen);
+     657                 :            :     }
+     658                 :            : 
+     659                 :          0 :     return mbedtls_mpi_write_binary(&ctx->z, buf, *olen);
+     660                 :            : }
+     661                 :            : 
+     662                 :            : /*
+     663                 :            :  * Derive and export the shared secret
+     664                 :            :  */
+     665                 :          0 : int mbedtls_ecdh_calc_secret(mbedtls_ecdh_context *ctx, size_t *olen,
+     666                 :            :                              unsigned char *buf, size_t blen,
+     667                 :            :                              int (*f_rng)(void *, unsigned char *, size_t),
+     668                 :            :                              void *p_rng)
+     669                 :            : {
+     670                 :          0 :     int restart_enabled = 0;
+     671                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+     672                 :          0 :     restart_enabled = ctx->restart_enabled;
+     673                 :            : #endif
+     674                 :            : 
+     675                 :            : #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
+     676                 :          0 :     return ecdh_calc_secret_internal(ctx, olen, buf, blen, f_rng, p_rng,
+     677                 :            :                                      restart_enabled);
+     678                 :            : #else
+     679                 :            :     switch (ctx->var) {
+     680                 :            : #if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
+     681                 :            :         case MBEDTLS_ECDH_VARIANT_EVEREST:
+     682                 :            :             return mbedtls_everest_calc_secret(&ctx->ctx.everest_ecdh, olen,
+     683                 :            :                                                buf, blen, f_rng, p_rng);
+     684                 :            : #endif
+     685                 :            :         case MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0:
+     686                 :            :             return ecdh_calc_secret_internal(&ctx->ctx.mbed_ecdh, olen, buf,
+     687                 :            :                                              blen, f_rng, p_rng,
+     688                 :            :                                              restart_enabled);
+     689                 :            :         default:
+     690                 :            :             return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+     691                 :            :     }
+     692                 :            : #endif
+     693                 :            : }
+     694                 :            : #endif /* MBEDTLS_ECDH_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/ecdsa.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ecdsa.c.func-sort-c.html new file mode 100644 index 00000000000..fe79f2c2f3b --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ecdsa.c.func-sort-c.html @@ -0,0 +1,181 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/ecdsa.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - ecdsa.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:16227259.6 %
Date:2024-09-22 08:21:07Functions:132552.0 %
Branches:9225735.8 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
ecdsa_restart_det_free0
ecdsa_restart_det_init0
ecdsa_restart_sig_free0
ecdsa_restart_sig_init0
ecdsa_restart_ver_free0
ecdsa_restart_ver_init0
mbedtls_ecdsa_free0
mbedtls_ecdsa_genkey0
mbedtls_ecdsa_init0
mbedtls_ecdsa_restart_free0
mbedtls_ecdsa_restart_init0
mbedtls_ecdsa_sign_det_ext0
ecdsa_signature_to_asn16
mbedtls_ecdsa_from_keypair6
mbedtls_ecdsa_sign_det_restartable6
mbedtls_ecdsa_write_signature6
mbedtls_ecdsa_write_signature_restartable6
mbedtls_ecdsa_verify70
mbedtls_ecdsa_sign124
mbedtls_ecdsa_sign_restartable130
mbedtls_ecdsa_read_signature1335
mbedtls_ecdsa_read_signature_restartable1335
mbedtls_ecdsa_verify_restartable1405
mbedtls_ecdsa_can_do1535
derive_mpi1539
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/ecdsa.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ecdsa.c.func.html new file mode 100644 index 00000000000..b686140cff1 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ecdsa.c.func.html @@ -0,0 +1,181 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/ecdsa.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - ecdsa.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:16227259.6 %
Date:2024-09-22 08:21:07Functions:132552.0 %
Branches:9225735.8 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
derive_mpi1539
ecdsa_restart_det_free0
ecdsa_restart_det_init0
ecdsa_restart_sig_free0
ecdsa_restart_sig_init0
ecdsa_restart_ver_free0
ecdsa_restart_ver_init0
ecdsa_signature_to_asn16
mbedtls_ecdsa_can_do1535
mbedtls_ecdsa_free0
mbedtls_ecdsa_from_keypair6
mbedtls_ecdsa_genkey0
mbedtls_ecdsa_init0
mbedtls_ecdsa_read_signature1335
mbedtls_ecdsa_read_signature_restartable1335
mbedtls_ecdsa_restart_free0
mbedtls_ecdsa_restart_init0
mbedtls_ecdsa_sign124
mbedtls_ecdsa_sign_det_ext0
mbedtls_ecdsa_sign_det_restartable6
mbedtls_ecdsa_sign_restartable130
mbedtls_ecdsa_verify70
mbedtls_ecdsa_verify_restartable1405
mbedtls_ecdsa_write_signature6
mbedtls_ecdsa_write_signature_restartable6
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/ecdsa.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ecdsa.c.gcov.html new file mode 100644 index 00000000000..30d9404571d --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ecdsa.c.gcov.html @@ -0,0 +1,962 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/ecdsa.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - ecdsa.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:16227259.6 %
Date:2024-09-22 08:21:07Functions:132552.0 %
Branches:9225735.8 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  *  Elliptic curve DSA
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  */
+       7                 :            : 
+       8                 :            : /*
+       9                 :            :  * References:
+      10                 :            :  *
+      11                 :            :  * SEC1 https://www.secg.org/sec1-v2.pdf
+      12                 :            :  */
+      13                 :            : 
+      14                 :            : #include "common.h"
+      15                 :            : 
+      16                 :            : #if defined(MBEDTLS_ECDSA_C)
+      17                 :            : 
+      18                 :            : #include "mbedtls/ecdsa.h"
+      19                 :            : #include "mbedtls/asn1write.h"
+      20                 :            : 
+      21                 :            : #include <string.h>
+      22                 :            : 
+      23                 :            : #if defined(MBEDTLS_ECDSA_DETERMINISTIC)
+      24                 :            : #include "mbedtls/hmac_drbg.h"
+      25                 :            : #endif
+      26                 :            : 
+      27                 :            : #include "mbedtls/platform.h"
+      28                 :            : 
+      29                 :            : #include "mbedtls/platform_util.h"
+      30                 :            : #include "mbedtls/error.h"
+      31                 :            : 
+      32                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+      33                 :            : 
+      34                 :            : /*
+      35                 :            :  * Sub-context for ecdsa_verify()
+      36                 :            :  */
+      37                 :            : struct mbedtls_ecdsa_restart_ver {
+      38                 :            :     mbedtls_mpi u1, u2;     /* intermediate values  */
+      39                 :            :     enum {                  /* what to do next?     */
+      40                 :            :         ecdsa_ver_init = 0, /* getting started      */
+      41                 :            :         ecdsa_ver_muladd,   /* muladd step          */
+      42                 :            :     } state;
+      43                 :            : };
+      44                 :            : 
+      45                 :            : /*
+      46                 :            :  * Init verify restart sub-context
+      47                 :            :  */
+      48                 :          0 : static void ecdsa_restart_ver_init(mbedtls_ecdsa_restart_ver_ctx *ctx)
+      49                 :            : {
+      50                 :          0 :     mbedtls_mpi_init(&ctx->u1);
+      51                 :          0 :     mbedtls_mpi_init(&ctx->u2);
+      52                 :          0 :     ctx->state = ecdsa_ver_init;
+      53                 :          0 : }
+      54                 :            : 
+      55                 :            : /*
+      56                 :            :  * Free the components of a verify restart sub-context
+      57                 :            :  */
+      58                 :          0 : static void ecdsa_restart_ver_free(mbedtls_ecdsa_restart_ver_ctx *ctx)
+      59                 :            : {
+      60         [ #  # ]:          0 :     if (ctx == NULL) {
+      61                 :          0 :         return;
+      62                 :            :     }
+      63                 :            : 
+      64                 :          0 :     mbedtls_mpi_free(&ctx->u1);
+      65                 :          0 :     mbedtls_mpi_free(&ctx->u2);
+      66                 :            : 
+      67                 :          0 :     ecdsa_restart_ver_init(ctx);
+      68                 :            : }
+      69                 :            : 
+      70                 :            : /*
+      71                 :            :  * Sub-context for ecdsa_sign()
+      72                 :            :  */
+      73                 :            : struct mbedtls_ecdsa_restart_sig {
+      74                 :            :     int sign_tries;
+      75                 :            :     int key_tries;
+      76                 :            :     mbedtls_mpi k;          /* per-signature random */
+      77                 :            :     mbedtls_mpi r;          /* r value              */
+      78                 :            :     enum {                  /* what to do next?     */
+      79                 :            :         ecdsa_sig_init = 0, /* getting started      */
+      80                 :            :         ecdsa_sig_mul,      /* doing ecp_mul()      */
+      81                 :            :         ecdsa_sig_modn,     /* mod N computations   */
+      82                 :            :     } state;
+      83                 :            : };
+      84                 :            : 
+      85                 :            : /*
+      86                 :            :  * Init verify sign sub-context
+      87                 :            :  */
+      88                 :          0 : static void ecdsa_restart_sig_init(mbedtls_ecdsa_restart_sig_ctx *ctx)
+      89                 :            : {
+      90                 :          0 :     ctx->sign_tries = 0;
+      91                 :          0 :     ctx->key_tries = 0;
+      92                 :          0 :     mbedtls_mpi_init(&ctx->k);
+      93                 :          0 :     mbedtls_mpi_init(&ctx->r);
+      94                 :          0 :     ctx->state = ecdsa_sig_init;
+      95                 :          0 : }
+      96                 :            : 
+      97                 :            : /*
+      98                 :            :  * Free the components of a sign restart sub-context
+      99                 :            :  */
+     100                 :          0 : static void ecdsa_restart_sig_free(mbedtls_ecdsa_restart_sig_ctx *ctx)
+     101                 :            : {
+     102         [ #  # ]:          0 :     if (ctx == NULL) {
+     103                 :          0 :         return;
+     104                 :            :     }
+     105                 :            : 
+     106                 :          0 :     mbedtls_mpi_free(&ctx->k);
+     107                 :          0 :     mbedtls_mpi_free(&ctx->r);
+     108                 :            : }
+     109                 :            : 
+     110                 :            : #if defined(MBEDTLS_ECDSA_DETERMINISTIC)
+     111                 :            : /*
+     112                 :            :  * Sub-context for ecdsa_sign_det()
+     113                 :            :  */
+     114                 :            : struct mbedtls_ecdsa_restart_det {
+     115                 :            :     mbedtls_hmac_drbg_context rng_ctx;  /* DRBG state   */
+     116                 :            :     enum {                      /* what to do next?     */
+     117                 :            :         ecdsa_det_init = 0,     /* getting started      */
+     118                 :            :         ecdsa_det_sign,         /* make signature       */
+     119                 :            :     } state;
+     120                 :            : };
+     121                 :            : 
+     122                 :            : /*
+     123                 :            :  * Init verify sign_det sub-context
+     124                 :            :  */
+     125                 :          0 : static void ecdsa_restart_det_init(mbedtls_ecdsa_restart_det_ctx *ctx)
+     126                 :            : {
+     127                 :          0 :     mbedtls_hmac_drbg_init(&ctx->rng_ctx);
+     128                 :          0 :     ctx->state = ecdsa_det_init;
+     129                 :          0 : }
+     130                 :            : 
+     131                 :            : /*
+     132                 :            :  * Free the components of a sign_det restart sub-context
+     133                 :            :  */
+     134                 :          0 : static void ecdsa_restart_det_free(mbedtls_ecdsa_restart_det_ctx *ctx)
+     135                 :            : {
+     136         [ #  # ]:          0 :     if (ctx == NULL) {
+     137                 :          0 :         return;
+     138                 :            :     }
+     139                 :            : 
+     140                 :          0 :     mbedtls_hmac_drbg_free(&ctx->rng_ctx);
+     141                 :            : 
+     142                 :          0 :     ecdsa_restart_det_init(ctx);
+     143                 :            : }
+     144                 :            : #endif /* MBEDTLS_ECDSA_DETERMINISTIC */
+     145                 :            : 
+     146                 :            : #define ECDSA_RS_ECP    (rs_ctx == NULL ? NULL : &rs_ctx->ecp)
+     147                 :            : 
+     148                 :            : /* Utility macro for checking and updating ops budget */
+     149                 :            : #define ECDSA_BUDGET(ops)   \
+     150                 :            :     MBEDTLS_MPI_CHK(mbedtls_ecp_check_budget(grp, ECDSA_RS_ECP, ops));
+     151                 :            : 
+     152                 :            : /* Call this when entering a function that needs its own sub-context */
+     153                 :            : #define ECDSA_RS_ENTER(SUB)   do {                                 \
+     154                 :            :         /* reset ops count for this call if top-level */                 \
+     155                 :            :         if (rs_ctx != NULL && rs_ctx->ecp.depth++ == 0)                 \
+     156                 :            :         rs_ctx->ecp.ops_done = 0;                                    \
+     157                 :            :                                                                      \
+     158                 :            :         /* set up our own sub-context if needed */                       \
+     159                 :            :         if (mbedtls_ecp_restart_is_enabled() &&                          \
+     160                 :            :             rs_ctx != NULL && rs_ctx->SUB == NULL)                      \
+     161                 :            :         {                                                                \
+     162                 :            :             rs_ctx->SUB = mbedtls_calloc(1, sizeof(*rs_ctx->SUB));   \
+     163                 :            :             if (rs_ctx->SUB == NULL)                                    \
+     164                 :            :             return MBEDTLS_ERR_ECP_ALLOC_FAILED;                  \
+     165                 :            :                                                                    \
+     166                 :            :             ecdsa_restart_## SUB ##_init(rs_ctx->SUB);                 \
+     167                 :            :         }                                                                \
+     168                 :            : } while (0)
+     169                 :            : 
+     170                 :            : /* Call this when leaving a function that needs its own sub-context */
+     171                 :            : #define ECDSA_RS_LEAVE(SUB)   do {                                 \
+     172                 :            :         /* clear our sub-context when not in progress (done or error) */ \
+     173                 :            :         if (rs_ctx != NULL && rs_ctx->SUB != NULL &&                     \
+     174                 :            :             ret != MBEDTLS_ERR_ECP_IN_PROGRESS)                         \
+     175                 :            :         {                                                                \
+     176                 :            :             ecdsa_restart_## SUB ##_free(rs_ctx->SUB);                 \
+     177                 :            :             mbedtls_free(rs_ctx->SUB);                                 \
+     178                 :            :             rs_ctx->SUB = NULL;                                          \
+     179                 :            :         }                                                                \
+     180                 :            :                                                                      \
+     181                 :            :         if (rs_ctx != NULL)                                             \
+     182                 :            :         rs_ctx->ecp.depth--;                                         \
+     183                 :            : } while (0)
+     184                 :            : 
+     185                 :            : #else /* MBEDTLS_ECP_RESTARTABLE */
+     186                 :            : 
+     187                 :            : #define ECDSA_RS_ECP    NULL
+     188                 :            : 
+     189                 :            : #define ECDSA_BUDGET(ops)     /* no-op; for compatibility */
+     190                 :            : 
+     191                 :            : #define ECDSA_RS_ENTER(SUB)   (void) rs_ctx
+     192                 :            : #define ECDSA_RS_LEAVE(SUB)   (void) rs_ctx
+     193                 :            : 
+     194                 :            : #endif /* MBEDTLS_ECP_RESTARTABLE */
+     195                 :            : 
+     196                 :            : #if defined(MBEDTLS_ECDSA_DETERMINISTIC) || \
+     197                 :            :     !defined(MBEDTLS_ECDSA_SIGN_ALT)     || \
+     198                 :            :     !defined(MBEDTLS_ECDSA_VERIFY_ALT)
+     199                 :            : /*
+     200                 :            :  * Derive a suitable integer for group grp from a buffer of length len
+     201                 :            :  * SEC1 4.1.3 step 5 aka SEC1 4.1.4 step 3
+     202                 :            :  */
+     203                 :       1539 : static int derive_mpi(const mbedtls_ecp_group *grp, mbedtls_mpi *x,
+     204                 :            :                       const unsigned char *buf, size_t blen)
+     205                 :            : {
+     206                 :       1539 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     207                 :       1539 :     size_t n_size = (grp->nbits + 7) / 8;
+     208                 :       1539 :     size_t use_size = blen > n_size ? n_size : blen;
+     209                 :            : 
+     210         [ -  + ]:       1539 :     MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(x, buf, use_size));
+     211         [ -  + ]:       1539 :     if (use_size * 8 > grp->nbits) {
+     212         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(x, use_size * 8 - grp->nbits));
+     213                 :            :     }
+     214                 :            : 
+     215                 :            :     /* While at it, reduce modulo N */
+     216         [ +  - ]:       1539 :     if (mbedtls_mpi_cmp_mpi(x, &grp->N) >= 0) {
+     217         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(x, x, &grp->N));
+     218                 :            :     }
+     219                 :            : 
+     220                 :       1539 : cleanup:
+     221                 :       1539 :     return ret;
+     222                 :            : }
+     223                 :            : #endif /* ECDSA_DETERMINISTIC || !ECDSA_SIGN_ALT || !ECDSA_VERIFY_ALT */
+     224                 :            : 
+     225                 :       1535 : int mbedtls_ecdsa_can_do(mbedtls_ecp_group_id gid)
+     226                 :            : {
+     227      [ -  -  + ]:       1535 :     switch (gid) {
+     228                 :            : #ifdef MBEDTLS_ECP_DP_CURVE25519_ENABLED
+     229                 :          0 :         case MBEDTLS_ECP_DP_CURVE25519: return 0;
+     230                 :            : #endif
+     231                 :            : #ifdef MBEDTLS_ECP_DP_CURVE448_ENABLED
+     232                 :          0 :         case MBEDTLS_ECP_DP_CURVE448: return 0;
+     233                 :            : #endif
+     234                 :       1535 :         default: return 1;
+     235                 :            :     }
+     236                 :            : }
+     237                 :            : 
+     238                 :            : #if !defined(MBEDTLS_ECDSA_SIGN_ALT)
+     239                 :            : /*
+     240                 :            :  * Compute ECDSA signature of a hashed message (SEC1 4.1.3)
+     241                 :            :  * Obviously, compared to SEC1 4.1.3, we skip step 4 (hash message)
+     242                 :            :  */
+     243                 :        130 : int mbedtls_ecdsa_sign_restartable(mbedtls_ecp_group *grp,
+     244                 :            :                                    mbedtls_mpi *r, mbedtls_mpi *s,
+     245                 :            :                                    const mbedtls_mpi *d, const unsigned char *buf, size_t blen,
+     246                 :            :                                    int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
+     247                 :            :                                    int (*f_rng_blind)(void *, unsigned char *, size_t),
+     248                 :            :                                    void *p_rng_blind,
+     249                 :            :                                    mbedtls_ecdsa_restart_ctx *rs_ctx)
+     250                 :            : {
+     251                 :            :     int ret, key_tries, sign_tries;
+     252                 :        130 :     int *p_sign_tries = &sign_tries, *p_key_tries = &key_tries;
+     253                 :            :     mbedtls_ecp_point R;
+     254                 :            :     mbedtls_mpi k, e, t;
+     255                 :        130 :     mbedtls_mpi *pk = &k, *pr = r;
+     256                 :            : 
+     257                 :            :     /* Fail cleanly on curves such as Curve25519 that can't be used for ECDSA */
+     258   [ +  -  -  + ]:        130 :     if (!mbedtls_ecdsa_can_do(grp->id) || grp->N.p == NULL) {
+     259                 :          0 :         return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+     260                 :            :     }
+     261                 :            : 
+     262                 :            :     /* Make sure d is in range 1..n-1 */
+     263   [ +  -  -  + ]:        130 :     if (mbedtls_mpi_cmp_int(d, 1) < 0 || mbedtls_mpi_cmp_mpi(d, &grp->N) >= 0) {
+     264                 :          0 :         return MBEDTLS_ERR_ECP_INVALID_KEY;
+     265                 :            :     }
+     266                 :            : 
+     267                 :        130 :     mbedtls_ecp_point_init(&R);
+     268                 :        130 :     mbedtls_mpi_init(&k); mbedtls_mpi_init(&e); mbedtls_mpi_init(&t);
+     269                 :            : 
+     270   [ -  +  -  -  :        130 :     ECDSA_RS_ENTER(sig);
+          -  +  -  -  -  
+                -  -  - ]
+     271                 :            : 
+     272                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+     273   [ -  +  -  - ]:        130 :     if (rs_ctx != NULL && rs_ctx->sig != NULL) {
+     274                 :            :         /* redirect to our context */
+     275                 :          0 :         p_sign_tries = &rs_ctx->sig->sign_tries;
+     276                 :          0 :         p_key_tries = &rs_ctx->sig->key_tries;
+     277                 :          0 :         pk = &rs_ctx->sig->k;
+     278                 :          0 :         pr = &rs_ctx->sig->r;
+     279                 :            : 
+     280                 :            :         /* jump to current step */
+     281         [ #  # ]:          0 :         if (rs_ctx->sig->state == ecdsa_sig_mul) {
+     282                 :          0 :             goto mul;
+     283                 :            :         }
+     284         [ #  # ]:          0 :         if (rs_ctx->sig->state == ecdsa_sig_modn) {
+     285                 :          0 :             goto modn;
+     286                 :            :         }
+     287                 :            :     }
+     288                 :            : #endif /* MBEDTLS_ECP_RESTARTABLE */
+     289                 :            : 
+     290                 :        130 :     *p_sign_tries = 0;
+     291                 :            :     do {
+     292         [ -  + ]:        130 :         if ((*p_sign_tries)++ > 10) {
+     293                 :          0 :             ret = MBEDTLS_ERR_ECP_RANDOM_FAILED;
+     294                 :          0 :             goto cleanup;
+     295                 :            :         }
+     296                 :            : 
+     297                 :            :         /*
+     298                 :            :          * Steps 1-3: generate a suitable ephemeral keypair
+     299                 :            :          * and set r = xR mod n
+     300                 :            :          */
+     301                 :        130 :         *p_key_tries = 0;
+     302                 :            :         do {
+     303         [ -  + ]:        130 :             if ((*p_key_tries)++ > 10) {
+     304                 :          0 :                 ret = MBEDTLS_ERR_ECP_RANDOM_FAILED;
+     305                 :          0 :                 goto cleanup;
+     306                 :            :             }
+     307                 :            : 
+     308         [ -  + ]:        130 :             MBEDTLS_MPI_CHK(mbedtls_ecp_gen_privkey(grp, pk, f_rng, p_rng));
+     309                 :            : 
+     310                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+     311   [ +  -  -  - ]:        130 :             if (rs_ctx != NULL && rs_ctx->sig != NULL) {
+     312                 :          0 :                 rs_ctx->sig->state = ecdsa_sig_mul;
+     313                 :            :             }
+     314                 :            : 
+     315                 :        130 : mul:
+     316                 :            : #endif
+     317   [ -  +  -  + ]:        130 :             MBEDTLS_MPI_CHK(mbedtls_ecp_mul_restartable(grp, &R, pk, &grp->G,
+     318                 :            :                                                         f_rng_blind,
+     319                 :            :                                                         p_rng_blind,
+     320                 :            :                                                         ECDSA_RS_ECP));
+     321         [ -  + ]:        130 :             MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(pr, &R.X, &grp->N));
+     322         [ -  + ]:        130 :         } while (mbedtls_mpi_cmp_int(pr, 0) == 0);
+     323                 :            : 
+     324                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+     325   [ +  -  -  - ]:        130 :         if (rs_ctx != NULL && rs_ctx->sig != NULL) {
+     326                 :          0 :             rs_ctx->sig->state = ecdsa_sig_modn;
+     327                 :            :         }
+     328                 :            : 
+     329                 :        130 : modn:
+     330                 :            : #endif
+     331                 :            :         /*
+     332                 :            :          * Accounting for everything up to the end of the loop
+     333                 :            :          * (step 6, but checking now avoids saving e and t)
+     334                 :            :          */
+     335   [ -  +  -  + ]:        130 :         ECDSA_BUDGET(MBEDTLS_ECP_OPS_INV + 4);
+     336                 :            : 
+     337                 :            :         /*
+     338                 :            :          * Step 5: derive MPI from hashed message
+     339                 :            :          */
+     340         [ -  + ]:        130 :         MBEDTLS_MPI_CHK(derive_mpi(grp, &e, buf, blen));
+     341                 :            : 
+     342                 :            :         /*
+     343                 :            :          * Generate a random value to blind inv_mod in next step,
+     344                 :            :          * avoiding a potential timing leak.
+     345                 :            :          */
+     346         [ -  + ]:        130 :         MBEDTLS_MPI_CHK(mbedtls_ecp_gen_privkey(grp, &t, f_rng_blind,
+     347                 :            :                                                 p_rng_blind));
+     348                 :            : 
+     349                 :            :         /*
+     350                 :            :          * Step 6: compute s = (e + r * d) / k = t (e + rd) / (kt) mod n
+     351                 :            :          */
+     352         [ -  + ]:        130 :         MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(s, pr, d));
+     353         [ -  + ]:        130 :         MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&e, &e, s));
+     354         [ -  + ]:        130 :         MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&e, &e, &t));
+     355         [ -  + ]:        130 :         MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(pk, pk, &t));
+     356         [ -  + ]:        130 :         MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(pk, pk, &grp->N));
+     357         [ -  + ]:        130 :         MBEDTLS_MPI_CHK(mbedtls_mpi_inv_mod(s, pk, &grp->N));
+     358         [ -  + ]:        130 :         MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(s, s, &e));
+     359         [ -  + ]:        130 :         MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(s, s, &grp->N));
+     360         [ -  + ]:        130 :     } while (mbedtls_mpi_cmp_int(s, 0) == 0);
+     361                 :            : 
+     362                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+     363   [ +  -  -  - ]:        130 :     if (rs_ctx != NULL && rs_ctx->sig != NULL) {
+     364         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_copy(r, pr));
+     365                 :            :     }
+     366                 :            : #endif
+     367                 :            : 
+     368                 :        130 : cleanup:
+     369                 :        130 :     mbedtls_ecp_point_free(&R);
+     370                 :        130 :     mbedtls_mpi_free(&k); mbedtls_mpi_free(&e); mbedtls_mpi_free(&t);
+     371                 :            : 
+     372   [ -  +  -  -  :        130 :     ECDSA_RS_LEAVE(sig);
+             -  -  -  + ]
+     373                 :            : 
+     374                 :        130 :     return ret;
+     375                 :            : }
+     376                 :            : 
+     377                 :            : /*
+     378                 :            :  * Compute ECDSA signature of a hashed message
+     379                 :            :  */
+     380                 :        124 : int mbedtls_ecdsa_sign(mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s,
+     381                 :            :                        const mbedtls_mpi *d, const unsigned char *buf, size_t blen,
+     382                 :            :                        int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
+     383                 :            : {
+     384                 :            :     /* Use the same RNG for both blinding and ephemeral key generation */
+     385                 :        124 :     return mbedtls_ecdsa_sign_restartable(grp, r, s, d, buf, blen,
+     386                 :            :                                           f_rng, p_rng, f_rng, p_rng, NULL);
+     387                 :            : }
+     388                 :            : #endif /* !MBEDTLS_ECDSA_SIGN_ALT */
+     389                 :            : 
+     390                 :            : #if defined(MBEDTLS_ECDSA_DETERMINISTIC)
+     391                 :            : /*
+     392                 :            :  * Deterministic signature wrapper
+     393                 :            :  *
+     394                 :            :  * note:    The f_rng_blind parameter must not be NULL.
+     395                 :            :  *
+     396                 :            :  */
+     397                 :          6 : int mbedtls_ecdsa_sign_det_restartable(mbedtls_ecp_group *grp,
+     398                 :            :                                        mbedtls_mpi *r, mbedtls_mpi *s,
+     399                 :            :                                        const mbedtls_mpi *d, const unsigned char *buf, size_t blen,
+     400                 :            :                                        mbedtls_md_type_t md_alg,
+     401                 :            :                                        int (*f_rng_blind)(void *, unsigned char *, size_t),
+     402                 :            :                                        void *p_rng_blind,
+     403                 :            :                                        mbedtls_ecdsa_restart_ctx *rs_ctx)
+     404                 :            : {
+     405                 :          6 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     406                 :            :     mbedtls_hmac_drbg_context rng_ctx;
+     407                 :          6 :     mbedtls_hmac_drbg_context *p_rng = &rng_ctx;
+     408                 :            :     unsigned char data[2 * MBEDTLS_ECP_MAX_BYTES];
+     409                 :          6 :     size_t grp_len = (grp->nbits + 7) / 8;
+     410                 :            :     const mbedtls_md_info_t *md_info;
+     411                 :            :     mbedtls_mpi h;
+     412                 :            : 
+     413         [ -  + ]:          6 :     if ((md_info = mbedtls_md_info_from_type(md_alg)) == NULL) {
+     414                 :          0 :         return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+     415                 :            :     }
+     416                 :            : 
+     417                 :          6 :     mbedtls_mpi_init(&h);
+     418                 :          6 :     mbedtls_hmac_drbg_init(&rng_ctx);
+     419                 :            : 
+     420   [ -  +  -  -  :          6 :     ECDSA_RS_ENTER(det);
+          -  +  -  -  -  
+                -  -  - ]
+     421                 :            : 
+     422                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+     423   [ -  +  -  - ]:          6 :     if (rs_ctx != NULL && rs_ctx->det != NULL) {
+     424                 :            :         /* redirect to our context */
+     425                 :          0 :         p_rng = &rs_ctx->det->rng_ctx;
+     426                 :            : 
+     427                 :            :         /* jump to current step */
+     428         [ #  # ]:          0 :         if (rs_ctx->det->state == ecdsa_det_sign) {
+     429                 :          0 :             goto sign;
+     430                 :            :         }
+     431                 :            :     }
+     432                 :            : #endif /* MBEDTLS_ECP_RESTARTABLE */
+     433                 :            : 
+     434                 :            :     /* Use private key and message hash (reduced) to initialize HMAC_DRBG */
+     435         [ -  + ]:          6 :     MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(d, data, grp_len));
+     436         [ -  + ]:          6 :     MBEDTLS_MPI_CHK(derive_mpi(grp, &h, buf, blen));
+     437         [ -  + ]:          6 :     MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(&h, data + grp_len, grp_len));
+     438         [ -  + ]:          6 :     MBEDTLS_MPI_CHK(mbedtls_hmac_drbg_seed_buf(p_rng, md_info, data, 2 * grp_len));
+     439                 :            : 
+     440                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+     441   [ +  -  -  - ]:          6 :     if (rs_ctx != NULL && rs_ctx->det != NULL) {
+     442                 :          0 :         rs_ctx->det->state = ecdsa_det_sign;
+     443                 :            :     }
+     444                 :            : 
+     445                 :          6 : sign:
+     446                 :            : #endif
+     447                 :            : #if defined(MBEDTLS_ECDSA_SIGN_ALT)
+     448                 :            :     (void) f_rng_blind;
+     449                 :            :     (void) p_rng_blind;
+     450                 :            :     ret = mbedtls_ecdsa_sign(grp, r, s, d, buf, blen,
+     451                 :            :                              mbedtls_hmac_drbg_random, p_rng);
+     452                 :            : #else
+     453                 :          6 :     ret = mbedtls_ecdsa_sign_restartable(grp, r, s, d, buf, blen,
+     454                 :            :                                          mbedtls_hmac_drbg_random, p_rng,
+     455                 :            :                                          f_rng_blind, p_rng_blind, rs_ctx);
+     456                 :            : #endif /* MBEDTLS_ECDSA_SIGN_ALT */
+     457                 :            : 
+     458                 :          6 : cleanup:
+     459                 :          6 :     mbedtls_hmac_drbg_free(&rng_ctx);
+     460                 :          6 :     mbedtls_mpi_free(&h);
+     461                 :            : 
+     462   [ -  +  -  -  :          6 :     ECDSA_RS_LEAVE(det);
+             -  -  -  + ]
+     463                 :            : 
+     464                 :          6 :     return ret;
+     465                 :            : }
+     466                 :            : 
+     467                 :            : /*
+     468                 :            :  * Deterministic signature wrapper
+     469                 :            :  */
+     470                 :          0 : int mbedtls_ecdsa_sign_det_ext(mbedtls_ecp_group *grp, mbedtls_mpi *r,
+     471                 :            :                                mbedtls_mpi *s, const mbedtls_mpi *d,
+     472                 :            :                                const unsigned char *buf, size_t blen,
+     473                 :            :                                mbedtls_md_type_t md_alg,
+     474                 :            :                                int (*f_rng_blind)(void *, unsigned char *,
+     475                 :            :                                                   size_t),
+     476                 :            :                                void *p_rng_blind)
+     477                 :            : {
+     478                 :          0 :     return mbedtls_ecdsa_sign_det_restartable(grp, r, s, d, buf, blen, md_alg,
+     479                 :            :                                               f_rng_blind, p_rng_blind, NULL);
+     480                 :            : }
+     481                 :            : #endif /* MBEDTLS_ECDSA_DETERMINISTIC */
+     482                 :            : 
+     483                 :            : #if !defined(MBEDTLS_ECDSA_VERIFY_ALT)
+     484                 :            : /*
+     485                 :            :  * Verify ECDSA signature of hashed message (SEC1 4.1.4)
+     486                 :            :  * Obviously, compared to SEC1 4.1.3, we skip step 2 (hash message)
+     487                 :            :  */
+     488                 :       1405 : int mbedtls_ecdsa_verify_restartable(mbedtls_ecp_group *grp,
+     489                 :            :                                      const unsigned char *buf, size_t blen,
+     490                 :            :                                      const mbedtls_ecp_point *Q,
+     491                 :            :                                      const mbedtls_mpi *r,
+     492                 :            :                                      const mbedtls_mpi *s,
+     493                 :            :                                      mbedtls_ecdsa_restart_ctx *rs_ctx)
+     494                 :            : {
+     495                 :       1405 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     496                 :            :     mbedtls_mpi e, s_inv, u1, u2;
+     497                 :            :     mbedtls_ecp_point R;
+     498                 :       1405 :     mbedtls_mpi *pu1 = &u1, *pu2 = &u2;
+     499                 :            : 
+     500                 :       1405 :     mbedtls_ecp_point_init(&R);
+     501                 :       1405 :     mbedtls_mpi_init(&e); mbedtls_mpi_init(&s_inv);
+     502                 :       1405 :     mbedtls_mpi_init(&u1); mbedtls_mpi_init(&u2);
+     503                 :            : 
+     504                 :            :     /* Fail cleanly on curves such as Curve25519 that can't be used for ECDSA */
+     505   [ +  -  -  + ]:       1405 :     if (!mbedtls_ecdsa_can_do(grp->id) || grp->N.p == NULL) {
+     506                 :          0 :         return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+     507                 :            :     }
+     508                 :            : 
+     509   [ -  +  -  -  :       1405 :     ECDSA_RS_ENTER(ver);
+          -  +  -  -  -  
+                -  -  - ]
+     510                 :            : 
+     511                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+     512   [ -  +  -  - ]:       1405 :     if (rs_ctx != NULL && rs_ctx->ver != NULL) {
+     513                 :            :         /* redirect to our context */
+     514                 :          0 :         pu1 = &rs_ctx->ver->u1;
+     515                 :          0 :         pu2 = &rs_ctx->ver->u2;
+     516                 :            : 
+     517                 :            :         /* jump to current step */
+     518         [ #  # ]:          0 :         if (rs_ctx->ver->state == ecdsa_ver_muladd) {
+     519                 :          0 :             goto muladd;
+     520                 :            :         }
+     521                 :            :     }
+     522                 :            : #endif /* MBEDTLS_ECP_RESTARTABLE */
+     523                 :            : 
+     524                 :            :     /*
+     525                 :            :      * Step 1: make sure r and s are in range 1..n-1
+     526                 :            :      */
+     527   [ +  +  +  -  :       2808 :     if (mbedtls_mpi_cmp_int(r, 1) < 0 || mbedtls_mpi_cmp_mpi(r, &grp->N) >= 0 ||
+                   +  - ]
+     528         [ -  + ]:       2806 :         mbedtls_mpi_cmp_int(s, 1) < 0 || mbedtls_mpi_cmp_mpi(s, &grp->N) >= 0) {
+     529                 :          2 :         ret = MBEDTLS_ERR_ECP_VERIFY_FAILED;
+     530                 :          2 :         goto cleanup;
+     531                 :            :     }
+     532                 :            : 
+     533                 :            :     /*
+     534                 :            :      * Step 3: derive MPI from hashed message
+     535                 :            :      */
+     536         [ -  + ]:       1403 :     MBEDTLS_MPI_CHK(derive_mpi(grp, &e, buf, blen));
+     537                 :            : 
+     538                 :            :     /*
+     539                 :            :      * Step 4: u1 = e / s mod n, u2 = r / s mod n
+     540                 :            :      */
+     541   [ -  +  -  + ]:       1403 :     ECDSA_BUDGET(MBEDTLS_ECP_OPS_CHK + MBEDTLS_ECP_OPS_INV + 2);
+     542                 :            : 
+     543         [ -  + ]:       1403 :     MBEDTLS_MPI_CHK(mbedtls_mpi_inv_mod(&s_inv, s, &grp->N));
+     544                 :            : 
+     545         [ -  + ]:       1403 :     MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(pu1, &e, &s_inv));
+     546         [ -  + ]:       1403 :     MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(pu1, pu1, &grp->N));
+     547                 :            : 
+     548         [ -  + ]:       1403 :     MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(pu2, r, &s_inv));
+     549         [ -  + ]:       1403 :     MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(pu2, pu2, &grp->N));
+     550                 :            : 
+     551                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+     552   [ +  -  -  - ]:       1403 :     if (rs_ctx != NULL && rs_ctx->ver != NULL) {
+     553                 :          0 :         rs_ctx->ver->state = ecdsa_ver_muladd;
+     554                 :            :     }
+     555                 :            : 
+     556                 :       1403 : muladd:
+     557                 :            : #endif
+     558                 :            :     /*
+     559                 :            :      * Step 5: R = u1 G + u2 Q
+     560                 :            :      */
+     561   [ -  +  -  + ]:       1403 :     MBEDTLS_MPI_CHK(mbedtls_ecp_muladd_restartable(grp,
+     562                 :            :                                                    &R, pu1, &grp->G, pu2, Q, ECDSA_RS_ECP));
+     563                 :            : 
+     564         [ -  + ]:       1403 :     if (mbedtls_ecp_is_zero(&R)) {
+     565                 :          0 :         ret = MBEDTLS_ERR_ECP_VERIFY_FAILED;
+     566                 :          0 :         goto cleanup;
+     567                 :            :     }
+     568                 :            : 
+     569                 :            :     /*
+     570                 :            :      * Step 6: convert xR to an integer (no-op)
+     571                 :            :      * Step 7: reduce xR mod n (gives v)
+     572                 :            :      */
+     573         [ -  + ]:       1403 :     MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&R.X, &R.X, &grp->N));
+     574                 :            : 
+     575                 :            :     /*
+     576                 :            :      * Step 8: check if v (that is, R.X) is equal to r
+     577                 :            :      */
+     578         [ +  + ]:       1403 :     if (mbedtls_mpi_cmp_mpi(&R.X, r) != 0) {
+     579                 :         15 :         ret = MBEDTLS_ERR_ECP_VERIFY_FAILED;
+     580                 :         15 :         goto cleanup;
+     581                 :            :     }
+     582                 :            : 
+     583                 :       1388 : cleanup:
+     584                 :       1405 :     mbedtls_ecp_point_free(&R);
+     585                 :       1405 :     mbedtls_mpi_free(&e); mbedtls_mpi_free(&s_inv);
+     586                 :       1405 :     mbedtls_mpi_free(&u1); mbedtls_mpi_free(&u2);
+     587                 :            : 
+     588   [ -  +  -  -  :       1405 :     ECDSA_RS_LEAVE(ver);
+             -  -  -  + ]
+     589                 :            : 
+     590                 :       1405 :     return ret;
+     591                 :            : }
+     592                 :            : 
+     593                 :            : /*
+     594                 :            :  * Verify ECDSA signature of hashed message
+     595                 :            :  */
+     596                 :         70 : int mbedtls_ecdsa_verify(mbedtls_ecp_group *grp,
+     597                 :            :                          const unsigned char *buf, size_t blen,
+     598                 :            :                          const mbedtls_ecp_point *Q,
+     599                 :            :                          const mbedtls_mpi *r,
+     600                 :            :                          const mbedtls_mpi *s)
+     601                 :            : {
+     602                 :         70 :     return mbedtls_ecdsa_verify_restartable(grp, buf, blen, Q, r, s, NULL);
+     603                 :            : }
+     604                 :            : #endif /* !MBEDTLS_ECDSA_VERIFY_ALT */
+     605                 :            : 
+     606                 :            : /*
+     607                 :            :  * Convert a signature (given by context) to ASN.1
+     608                 :            :  */
+     609                 :          6 : static int ecdsa_signature_to_asn1(const mbedtls_mpi *r, const mbedtls_mpi *s,
+     610                 :            :                                    unsigned char *sig, size_t sig_size,
+     611                 :            :                                    size_t *slen)
+     612                 :            : {
+     613                 :          6 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     614                 :          6 :     unsigned char buf[MBEDTLS_ECDSA_MAX_LEN] = { 0 };
+     615                 :          6 :     unsigned char *p = buf + sizeof(buf);
+     616                 :          6 :     size_t len = 0;
+     617                 :            : 
+     618         [ -  + ]:          6 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_mpi(&p, buf, s));
+     619         [ -  + ]:          6 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_mpi(&p, buf, r));
+     620                 :            : 
+     621         [ -  + ]:          6 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(&p, buf, len));
+     622         [ -  + ]:          6 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(&p, buf,
+     623                 :            :                                                      MBEDTLS_ASN1_CONSTRUCTED |
+     624                 :            :                                                      MBEDTLS_ASN1_SEQUENCE));
+     625                 :            : 
+     626         [ -  + ]:          6 :     if (len > sig_size) {
+     627                 :          0 :         return MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL;
+     628                 :            :     }
+     629                 :            : 
+     630                 :          6 :     memcpy(sig, p, len);
+     631                 :          6 :     *slen = len;
+     632                 :            : 
+     633                 :          6 :     return 0;
+     634                 :            : }
+     635                 :            : 
+     636                 :            : /*
+     637                 :            :  * Compute and write signature
+     638                 :            :  */
+     639                 :          6 : int mbedtls_ecdsa_write_signature_restartable(mbedtls_ecdsa_context *ctx,
+     640                 :            :                                               mbedtls_md_type_t md_alg,
+     641                 :            :                                               const unsigned char *hash, size_t hlen,
+     642                 :            :                                               unsigned char *sig, size_t sig_size, size_t *slen,
+     643                 :            :                                               int (*f_rng)(void *, unsigned char *, size_t),
+     644                 :            :                                               void *p_rng,
+     645                 :            :                                               mbedtls_ecdsa_restart_ctx *rs_ctx)
+     646                 :            : {
+     647                 :          6 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     648                 :            :     mbedtls_mpi r, s;
+     649         [ -  + ]:          6 :     if (f_rng == NULL) {
+     650                 :          0 :         return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+     651                 :            :     }
+     652                 :            : 
+     653                 :          6 :     mbedtls_mpi_init(&r);
+     654                 :          6 :     mbedtls_mpi_init(&s);
+     655                 :            : 
+     656                 :            : #if defined(MBEDTLS_ECDSA_DETERMINISTIC)
+     657         [ -  + ]:          6 :     MBEDTLS_MPI_CHK(mbedtls_ecdsa_sign_det_restartable(&ctx->grp, &r, &s, &ctx->d,
+     658                 :            :                                                        hash, hlen, md_alg, f_rng,
+     659                 :            :                                                        p_rng, rs_ctx));
+     660                 :            : #else
+     661                 :            :     (void) md_alg;
+     662                 :            : 
+     663                 :            : #if defined(MBEDTLS_ECDSA_SIGN_ALT)
+     664                 :            :     (void) rs_ctx;
+     665                 :            : 
+     666                 :            :     MBEDTLS_MPI_CHK(mbedtls_ecdsa_sign(&ctx->grp, &r, &s, &ctx->d,
+     667                 :            :                                        hash, hlen, f_rng, p_rng));
+     668                 :            : #else
+     669                 :            :     /* Use the same RNG for both blinding and ephemeral key generation */
+     670                 :            :     MBEDTLS_MPI_CHK(mbedtls_ecdsa_sign_restartable(&ctx->grp, &r, &s, &ctx->d,
+     671                 :            :                                                    hash, hlen, f_rng, p_rng, f_rng,
+     672                 :            :                                                    p_rng, rs_ctx));
+     673                 :            : #endif /* MBEDTLS_ECDSA_SIGN_ALT */
+     674                 :            : #endif /* MBEDTLS_ECDSA_DETERMINISTIC */
+     675                 :            : 
+     676         [ +  - ]:          6 :     MBEDTLS_MPI_CHK(ecdsa_signature_to_asn1(&r, &s, sig, sig_size, slen));
+     677                 :            : 
+     678                 :          6 : cleanup:
+     679                 :          6 :     mbedtls_mpi_free(&r);
+     680                 :          6 :     mbedtls_mpi_free(&s);
+     681                 :            : 
+     682                 :          6 :     return ret;
+     683                 :            : }
+     684                 :            : 
+     685                 :            : /*
+     686                 :            :  * Compute and write signature
+     687                 :            :  */
+     688                 :          6 : int mbedtls_ecdsa_write_signature(mbedtls_ecdsa_context *ctx,
+     689                 :            :                                   mbedtls_md_type_t md_alg,
+     690                 :            :                                   const unsigned char *hash, size_t hlen,
+     691                 :            :                                   unsigned char *sig, size_t sig_size, size_t *slen,
+     692                 :            :                                   int (*f_rng)(void *, unsigned char *, size_t),
+     693                 :            :                                   void *p_rng)
+     694                 :            : {
+     695                 :          6 :     return mbedtls_ecdsa_write_signature_restartable(
+     696                 :            :         ctx, md_alg, hash, hlen, sig, sig_size, slen,
+     697                 :            :         f_rng, p_rng, NULL);
+     698                 :            : }
+     699                 :            : 
+     700                 :            : /*
+     701                 :            :  * Read and check signature
+     702                 :            :  */
+     703                 :       1335 : int mbedtls_ecdsa_read_signature(mbedtls_ecdsa_context *ctx,
+     704                 :            :                                  const unsigned char *hash, size_t hlen,
+     705                 :            :                                  const unsigned char *sig, size_t slen)
+     706                 :            : {
+     707                 :       1335 :     return mbedtls_ecdsa_read_signature_restartable(
+     708                 :            :         ctx, hash, hlen, sig, slen, NULL);
+     709                 :            : }
+     710                 :            : 
+     711                 :            : /*
+     712                 :            :  * Restartable read and check signature
+     713                 :            :  */
+     714                 :       1335 : int mbedtls_ecdsa_read_signature_restartable(mbedtls_ecdsa_context *ctx,
+     715                 :            :                                              const unsigned char *hash, size_t hlen,
+     716                 :            :                                              const unsigned char *sig, size_t slen,
+     717                 :            :                                              mbedtls_ecdsa_restart_ctx *rs_ctx)
+     718                 :            : {
+     719                 :       1335 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     720                 :       1335 :     unsigned char *p = (unsigned char *) sig;
+     721                 :       1335 :     const unsigned char *end = sig + slen;
+     722                 :            :     size_t len;
+     723                 :            :     mbedtls_mpi r, s;
+     724                 :       1335 :     mbedtls_mpi_init(&r);
+     725                 :       1335 :     mbedtls_mpi_init(&s);
+     726                 :            : 
+     727         [ -  + ]:       1335 :     if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
+     728                 :            :                                     MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
+     729                 :          0 :         ret += MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+     730                 :          0 :         goto cleanup;
+     731                 :            :     }
+     732                 :            : 
+     733         [ -  + ]:       1335 :     if (p + len != end) {
+     734                 :          0 :         ret = MBEDTLS_ERROR_ADD(MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
+     735                 :            :                                 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
+     736                 :          0 :         goto cleanup;
+     737                 :            :     }
+     738                 :            : 
+     739   [ +  -  -  + ]:       2670 :     if ((ret = mbedtls_asn1_get_mpi(&p, end, &r)) != 0 ||
+     740                 :       1335 :         (ret = mbedtls_asn1_get_mpi(&p, end, &s)) != 0) {
+     741                 :          0 :         ret += MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+     742                 :          0 :         goto cleanup;
+     743                 :            :     }
+     744                 :            : #if defined(MBEDTLS_ECDSA_VERIFY_ALT)
+     745                 :            :     (void) rs_ctx;
+     746                 :            : 
+     747                 :            :     if ((ret = mbedtls_ecdsa_verify(&ctx->grp, hash, hlen,
+     748                 :            :                                     &ctx->Q, &r, &s)) != 0) {
+     749                 :            :         goto cleanup;
+     750                 :            :     }
+     751                 :            : #else
+     752         [ +  + ]:       1335 :     if ((ret = mbedtls_ecdsa_verify_restartable(&ctx->grp, hash, hlen,
+     753                 :       1335 :                                                 &ctx->Q, &r, &s, rs_ctx)) != 0) {
+     754                 :          2 :         goto cleanup;
+     755                 :            :     }
+     756                 :            : #endif /* MBEDTLS_ECDSA_VERIFY_ALT */
+     757                 :            : 
+     758                 :            :     /* At this point we know that the buffer starts with a valid signature.
+     759                 :            :      * Return 0 if the buffer just contains the signature, and a specific
+     760                 :            :      * error code if the valid signature is followed by more data. */
+     761         [ +  - ]:       1333 :     if (p != end) {
+     762                 :          0 :         ret = MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH;
+     763                 :            :     }
+     764                 :            : 
+     765                 :       1333 : cleanup:
+     766                 :       1335 :     mbedtls_mpi_free(&r);
+     767                 :       1335 :     mbedtls_mpi_free(&s);
+     768                 :            : 
+     769                 :       1335 :     return ret;
+     770                 :            : }
+     771                 :            : 
+     772                 :            : #if !defined(MBEDTLS_ECDSA_GENKEY_ALT)
+     773                 :            : /*
+     774                 :            :  * Generate key pair
+     775                 :            :  */
+     776                 :          0 : int mbedtls_ecdsa_genkey(mbedtls_ecdsa_context *ctx, mbedtls_ecp_group_id gid,
+     777                 :            :                          int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
+     778                 :            : {
+     779                 :          0 :     int ret = 0;
+     780                 :          0 :     ret = mbedtls_ecp_group_load(&ctx->grp, gid);
+     781         [ #  # ]:          0 :     if (ret != 0) {
+     782                 :          0 :         return ret;
+     783                 :            :     }
+     784                 :            : 
+     785                 :          0 :     return mbedtls_ecp_gen_keypair(&ctx->grp, &ctx->d,
+     786                 :            :                                    &ctx->Q, f_rng, p_rng);
+     787                 :            : }
+     788                 :            : #endif /* !MBEDTLS_ECDSA_GENKEY_ALT */
+     789                 :            : 
+     790                 :            : /*
+     791                 :            :  * Set context from an mbedtls_ecp_keypair
+     792                 :            :  */
+     793                 :          6 : int mbedtls_ecdsa_from_keypair(mbedtls_ecdsa_context *ctx, const mbedtls_ecp_keypair *key)
+     794                 :            : {
+     795                 :          6 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     796   [ +  -  +  - ]:         12 :     if ((ret = mbedtls_ecp_group_copy(&ctx->grp, &key->grp)) != 0 ||
+     797         [ -  + ]:         12 :         (ret = mbedtls_mpi_copy(&ctx->d, &key->d)) != 0 ||
+     798                 :          6 :         (ret = mbedtls_ecp_copy(&ctx->Q, &key->Q)) != 0) {
+     799                 :          0 :         mbedtls_ecdsa_free(ctx);
+     800                 :            :     }
+     801                 :            : 
+     802                 :          6 :     return ret;
+     803                 :            : }
+     804                 :            : 
+     805                 :            : /*
+     806                 :            :  * Initialize context
+     807                 :            :  */
+     808                 :          0 : void mbedtls_ecdsa_init(mbedtls_ecdsa_context *ctx)
+     809                 :            : {
+     810                 :          0 :     mbedtls_ecp_keypair_init(ctx);
+     811                 :          0 : }
+     812                 :            : 
+     813                 :            : /*
+     814                 :            :  * Free context
+     815                 :            :  */
+     816                 :          0 : void mbedtls_ecdsa_free(mbedtls_ecdsa_context *ctx)
+     817                 :            : {
+     818         [ #  # ]:          0 :     if (ctx == NULL) {
+     819                 :          0 :         return;
+     820                 :            :     }
+     821                 :            : 
+     822                 :          0 :     mbedtls_ecp_keypair_free(ctx);
+     823                 :            : }
+     824                 :            : 
+     825                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+     826                 :            : /*
+     827                 :            :  * Initialize a restart context
+     828                 :            :  */
+     829                 :          0 : void mbedtls_ecdsa_restart_init(mbedtls_ecdsa_restart_ctx *ctx)
+     830                 :            : {
+     831                 :          0 :     mbedtls_ecp_restart_init(&ctx->ecp);
+     832                 :            : 
+     833                 :          0 :     ctx->ver = NULL;
+     834                 :          0 :     ctx->sig = NULL;
+     835                 :            : #if defined(MBEDTLS_ECDSA_DETERMINISTIC)
+     836                 :          0 :     ctx->det = NULL;
+     837                 :            : #endif
+     838                 :          0 : }
+     839                 :            : 
+     840                 :            : /*
+     841                 :            :  * Free the components of a restart context
+     842                 :            :  */
+     843                 :          0 : void mbedtls_ecdsa_restart_free(mbedtls_ecdsa_restart_ctx *ctx)
+     844                 :            : {
+     845         [ #  # ]:          0 :     if (ctx == NULL) {
+     846                 :          0 :         return;
+     847                 :            :     }
+     848                 :            : 
+     849                 :          0 :     mbedtls_ecp_restart_free(&ctx->ecp);
+     850                 :            : 
+     851                 :          0 :     ecdsa_restart_ver_free(ctx->ver);
+     852                 :          0 :     mbedtls_free(ctx->ver);
+     853                 :          0 :     ctx->ver = NULL;
+     854                 :            : 
+     855                 :          0 :     ecdsa_restart_sig_free(ctx->sig);
+     856                 :          0 :     mbedtls_free(ctx->sig);
+     857                 :          0 :     ctx->sig = NULL;
+     858                 :            : 
+     859                 :            : #if defined(MBEDTLS_ECDSA_DETERMINISTIC)
+     860                 :          0 :     ecdsa_restart_det_free(ctx->det);
+     861                 :          0 :     mbedtls_free(ctx->det);
+     862                 :          0 :     ctx->det = NULL;
+     863                 :            : #endif
+     864                 :            : }
+     865                 :            : #endif /* MBEDTLS_ECP_RESTARTABLE */
+     866                 :            : 
+     867                 :            : #endif /* MBEDTLS_ECDSA_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/ecp.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ecp.c.func-sort-c.html new file mode 100644 index 00000000000..e60a22c7ed6 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ecp.c.func-sort-c.html @@ -0,0 +1,457 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/ecp.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - ecp.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:566116248.7 %
Date:2024-09-22 08:21:07Functions:539456.4 %
Branches:324112428.8 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
ecp_check_bad_points_mx0
ecp_check_pubkey_mx0
ecp_double_add_mxz0
ecp_mul_mxz0
ecp_normalize_mxz0
ecp_randomize_mxz0
ecp_restart_ma_init0
ecp_restart_rsm_init0
mbedtls_ecp_check_pub_priv0
mbedtls_ecp_curve_info_from_grp_id0
mbedtls_ecp_curve_info_from_name0
mbedtls_ecp_curve_info_from_tls_id0
mbedtls_ecp_curve_list0
mbedtls_ecp_export0
mbedtls_ecp_gen_key0
mbedtls_ecp_gen_keypair0
mbedtls_ecp_gen_keypair_base0
mbedtls_ecp_gen_privkey_mx0
mbedtls_ecp_grp_id_list0
mbedtls_ecp_keypair_calc_public0
mbedtls_ecp_keypair_get_group_id0
mbedtls_ecp_mul0
mbedtls_ecp_muladd0
mbedtls_ecp_point_cmp0
mbedtls_ecp_point_read_string0
mbedtls_ecp_self_test0
mbedtls_ecp_set_max_ops0
mbedtls_ecp_set_public_key0
mbedtls_ecp_set_zero0
mbedtls_ecp_sw_derive_y0
mbedtls_ecp_tls_read_group0
mbedtls_ecp_tls_read_group_id0
mbedtls_ecp_tls_read_point0
mbedtls_ecp_tls_write_group0
mbedtls_ecp_tls_write_point0
mbedtls_ecp_write_key0
mbedtls_ecp_write_key_ext0
mbedtls_ecp_write_public_key0
self_test_adjust_exponent0
self_test_point0
self_test_rng0
mbedtls_ecp_group_copy6
mbedtls_ecp_point_write_binary12
mbedtls_ecp_read_key128
mbedtls_ecp_mul_restartable368
mbedtls_ecp_gen_privkey424
mbedtls_ecp_gen_privkey_sw424
ecp_randomize_jac736
ecp_restart_ma_free975
ecp_restart_rsm_free975
mbedtls_ecp_restart_free975
mbedtls_ecp_muladd_restartable1403
ecp_precompute_comb1477
mbedtls_ecp_is_zero1477
mbedtls_ecp_restart_init2142
mbedtls_ecp_mul_shortcuts2806
ecp_normalize_jac_many2954
ecp_comb_recode_core3174
ecp_comb_recode_scalar3174
ecp_mul_comb3174
ecp_mul_comb_after_precomp3174
ecp_mul_comb_core3174
ecp_mul_restartable_internal3174
ecp_pick_window_size3174
mbedtls_ecp_check_privkey3302
ecp_normalize_jac4577
mbedtls_ecp_restart_is_enabled6118
mbedtls_ecp_copy6915
mpi_free_many9008
mpi_init_many9008
mbedtls_ecp_keypair_free11161
mbedtls_ecp_point_read_binary11161
mbedtls_ecp_keypair_init11167
ecp_check_pubkey_sw14335
ecp_sw_rhs14335
mbedtls_ecp_check_pubkey14335
mbedtls_mpi_sub_int_mod14335
mbedtls_ecp_group_free24598
mbedtls_ecp_group_init24796
ecp_group_is_static_comb_table26295
mbedtls_ecp_point_free45397
mbedtls_ecp_point_init58633
mbedtls_ecp_get_type66475
ecp_select_comb185946
ecp_safe_invert_jac189120
ecp_add_mixed194514
ecp_double_jac466356
mbedtls_mpi_mul_int_mod466356
mbedtls_mpi_add_mod480691
mbedtls_ecp_check_budget481474
mbedtls_mpi_shift_l_mod2059938
mbedtls_mpi_sub_mod3498864
ecp_modp6030023
mbedtls_mpi_mul_mod6030023
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/ecp.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ecp.c.func.html new file mode 100644 index 00000000000..9e9c910cb6a --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ecp.c.func.html @@ -0,0 +1,457 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/ecp.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - ecp.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:566116248.7 %
Date:2024-09-22 08:21:07Functions:539456.4 %
Branches:324112428.8 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
ecp_add_mixed194514
ecp_check_bad_points_mx0
ecp_check_pubkey_mx0
ecp_check_pubkey_sw14335
ecp_comb_recode_core3174
ecp_comb_recode_scalar3174
ecp_double_add_mxz0
ecp_double_jac466356
ecp_group_is_static_comb_table26295
ecp_modp6030023
ecp_mul_comb3174
ecp_mul_comb_after_precomp3174
ecp_mul_comb_core3174
ecp_mul_mxz0
ecp_mul_restartable_internal3174
ecp_normalize_jac4577
ecp_normalize_jac_many2954
ecp_normalize_mxz0
ecp_pick_window_size3174
ecp_precompute_comb1477
ecp_randomize_jac736
ecp_randomize_mxz0
ecp_restart_ma_free975
ecp_restart_ma_init0
ecp_restart_rsm_free975
ecp_restart_rsm_init0
ecp_safe_invert_jac189120
ecp_select_comb185946
ecp_sw_rhs14335
mbedtls_ecp_check_budget481474
mbedtls_ecp_check_privkey3302
mbedtls_ecp_check_pub_priv0
mbedtls_ecp_check_pubkey14335
mbedtls_ecp_copy6915
mbedtls_ecp_curve_info_from_grp_id0
mbedtls_ecp_curve_info_from_name0
mbedtls_ecp_curve_info_from_tls_id0
mbedtls_ecp_curve_list0
mbedtls_ecp_export0
mbedtls_ecp_gen_key0
mbedtls_ecp_gen_keypair0
mbedtls_ecp_gen_keypair_base0
mbedtls_ecp_gen_privkey424
mbedtls_ecp_gen_privkey_mx0
mbedtls_ecp_gen_privkey_sw424
mbedtls_ecp_get_type66475
mbedtls_ecp_group_copy6
mbedtls_ecp_group_free24598
mbedtls_ecp_group_init24796
mbedtls_ecp_grp_id_list0
mbedtls_ecp_is_zero1477
mbedtls_ecp_keypair_calc_public0
mbedtls_ecp_keypair_free11161
mbedtls_ecp_keypair_get_group_id0
mbedtls_ecp_keypair_init11167
mbedtls_ecp_mul0
mbedtls_ecp_mul_restartable368
mbedtls_ecp_mul_shortcuts2806
mbedtls_ecp_muladd0
mbedtls_ecp_muladd_restartable1403
mbedtls_ecp_point_cmp0
mbedtls_ecp_point_free45397
mbedtls_ecp_point_init58633
mbedtls_ecp_point_read_binary11161
mbedtls_ecp_point_read_string0
mbedtls_ecp_point_write_binary12
mbedtls_ecp_read_key128
mbedtls_ecp_restart_free975
mbedtls_ecp_restart_init2142
mbedtls_ecp_restart_is_enabled6118
mbedtls_ecp_self_test0
mbedtls_ecp_set_max_ops0
mbedtls_ecp_set_public_key0
mbedtls_ecp_set_zero0
mbedtls_ecp_sw_derive_y0
mbedtls_ecp_tls_read_group0
mbedtls_ecp_tls_read_group_id0
mbedtls_ecp_tls_read_point0
mbedtls_ecp_tls_write_group0
mbedtls_ecp_tls_write_point0
mbedtls_ecp_write_key0
mbedtls_ecp_write_key_ext0
mbedtls_ecp_write_public_key0
mbedtls_mpi_add_mod480691
mbedtls_mpi_mul_int_mod466356
mbedtls_mpi_mul_mod6030023
mbedtls_mpi_shift_l_mod2059938
mbedtls_mpi_sub_int_mod14335
mbedtls_mpi_sub_mod3498864
mpi_free_many9008
mpi_init_many9008
self_test_adjust_exponent0
self_test_point0
self_test_rng0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/ecp.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ecp.c.gcov.html new file mode 100644 index 00000000000..26b3e6ca14c --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ecp.c.gcov.html @@ -0,0 +1,3803 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/ecp.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - ecp.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:566116248.7 %
Date:2024-09-22 08:21:07Functions:539456.4 %
Branches:324112428.8 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  *  Elliptic curves over GF(p): generic functions
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  */
+       7                 :            : 
+       8                 :            : /*
+       9                 :            :  * References:
+      10                 :            :  *
+      11                 :            :  * SEC1 https://www.secg.org/sec1-v2.pdf
+      12                 :            :  * GECC = Guide to Elliptic Curve Cryptography - Hankerson, Menezes, Vanstone
+      13                 :            :  * FIPS 186-3 http://csrc.nist.gov/publications/fips/fips186-3/fips_186-3.pdf
+      14                 :            :  * RFC 4492 for the related TLS structures and constants
+      15                 :            :  * - https://www.rfc-editor.org/rfc/rfc4492
+      16                 :            :  * RFC 7748 for the Curve448 and Curve25519 curve definitions
+      17                 :            :  * - https://www.rfc-editor.org/rfc/rfc7748
+      18                 :            :  *
+      19                 :            :  * [Curve25519] https://cr.yp.to/ecdh/curve25519-20060209.pdf
+      20                 :            :  *
+      21                 :            :  * [2] CORON, Jean-S'ebastien. Resistance against differential power analysis
+      22                 :            :  *     for elliptic curve cryptosystems. In : Cryptographic Hardware and
+      23                 :            :  *     Embedded Systems. Springer Berlin Heidelberg, 1999. p. 292-302.
+      24                 :            :  *     <http://link.springer.com/chapter/10.1007/3-540-48059-5_25>
+      25                 :            :  *
+      26                 :            :  * [3] HEDABOU, Mustapha, PINEL, Pierre, et B'EN'ETEAU, Lucien. A comb method to
+      27                 :            :  *     render ECC resistant against Side Channel Attacks. IACR Cryptology
+      28                 :            :  *     ePrint Archive, 2004, vol. 2004, p. 342.
+      29                 :            :  *     <http://eprint.iacr.org/2004/342.pdf>
+      30                 :            :  */
+      31                 :            : 
+      32                 :            : #include "common.h"
+      33                 :            : 
+      34                 :            : /**
+      35                 :            :  * \brief Function level alternative implementation.
+      36                 :            :  *
+      37                 :            :  * The MBEDTLS_ECP_INTERNAL_ALT macro enables alternative implementations to
+      38                 :            :  * replace certain functions in this module. The alternative implementations are
+      39                 :            :  * typically hardware accelerators and need to activate the hardware before the
+      40                 :            :  * computation starts and deactivate it after it finishes. The
+      41                 :            :  * mbedtls_internal_ecp_init() and mbedtls_internal_ecp_free() functions serve
+      42                 :            :  * this purpose.
+      43                 :            :  *
+      44                 :            :  * To preserve the correct functionality the following conditions must hold:
+      45                 :            :  *
+      46                 :            :  * - The alternative implementation must be activated by
+      47                 :            :  *   mbedtls_internal_ecp_init() before any of the replaceable functions is
+      48                 :            :  *   called.
+      49                 :            :  * - mbedtls_internal_ecp_free() must \b only be called when the alternative
+      50                 :            :  *   implementation is activated.
+      51                 :            :  * - mbedtls_internal_ecp_init() must \b not be called when the alternative
+      52                 :            :  *   implementation is activated.
+      53                 :            :  * - Public functions must not return while the alternative implementation is
+      54                 :            :  *   activated.
+      55                 :            :  * - Replaceable functions are guarded by \c MBEDTLS_ECP_XXX_ALT macros and
+      56                 :            :  *   before calling them an \code if( mbedtls_internal_ecp_grp_capable( grp ) )
+      57                 :            :  *   \endcode ensures that the alternative implementation supports the current
+      58                 :            :  *   group.
+      59                 :            :  */
+      60                 :            : #if defined(MBEDTLS_ECP_INTERNAL_ALT)
+      61                 :            : #endif
+      62                 :            : 
+      63                 :            : #if defined(MBEDTLS_ECP_LIGHT)
+      64                 :            : 
+      65                 :            : #include "mbedtls/ecp.h"
+      66                 :            : #include "mbedtls/threading.h"
+      67                 :            : #include "mbedtls/platform_util.h"
+      68                 :            : #include "mbedtls/error.h"
+      69                 :            : 
+      70                 :            : #include "bn_mul.h"
+      71                 :            : #include "ecp_invasive.h"
+      72                 :            : 
+      73                 :            : #include <string.h>
+      74                 :            : 
+      75                 :            : #if !defined(MBEDTLS_ECP_ALT)
+      76                 :            : 
+      77                 :            : #include "mbedtls/platform.h"
+      78                 :            : 
+      79                 :            : #include "ecp_internal_alt.h"
+      80                 :            : 
+      81                 :            : #if defined(MBEDTLS_SELF_TEST)
+      82                 :            : /*
+      83                 :            :  * Counts of point addition and doubling, and field multiplications.
+      84                 :            :  * Used to test resistance of point multiplication to simple timing attacks.
+      85                 :            :  */
+      86                 :            : #if defined(MBEDTLS_ECP_C)
+      87                 :            : static unsigned long add_count, dbl_count;
+      88                 :            : #endif /* MBEDTLS_ECP_C */
+      89                 :            : static unsigned long mul_count;
+      90                 :            : #endif
+      91                 :            : 
+      92                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+      93                 :            : /*
+      94                 :            :  * Maximum number of "basic operations" to be done in a row.
+      95                 :            :  *
+      96                 :            :  * Default value 0 means that ECC operations will not yield.
+      97                 :            :  * Note that regardless of the value of ecp_max_ops, always at
+      98                 :            :  * least one step is performed before yielding.
+      99                 :            :  *
+     100                 :            :  * Setting ecp_max_ops=1 can be suitable for testing purposes
+     101                 :            :  * as it will interrupt computation at all possible points.
+     102                 :            :  */
+     103                 :            : static unsigned ecp_max_ops = 0;
+     104                 :            : 
+     105                 :            : /*
+     106                 :            :  * Set ecp_max_ops
+     107                 :            :  */
+     108                 :          0 : void mbedtls_ecp_set_max_ops(unsigned max_ops)
+     109                 :            : {
+     110                 :          0 :     ecp_max_ops = max_ops;
+     111                 :          0 : }
+     112                 :            : 
+     113                 :            : /*
+     114                 :            :  * Check if restart is enabled
+     115                 :            :  */
+     116                 :       6118 : int mbedtls_ecp_restart_is_enabled(void)
+     117                 :            : {
+     118                 :       6118 :     return ecp_max_ops != 0;
+     119                 :            : }
+     120                 :            : 
+     121                 :            : /*
+     122                 :            :  * Restart sub-context for ecp_mul_comb()
+     123                 :            :  */
+     124                 :            : struct mbedtls_ecp_restart_mul {
+     125                 :            :     mbedtls_ecp_point R;    /* current intermediate result                  */
+     126                 :            :     size_t i;               /* current index in various loops, 0 outside    */
+     127                 :            :     mbedtls_ecp_point *T;   /* table for precomputed points                 */
+     128                 :            :     unsigned char T_size;   /* number of points in table T                  */
+     129                 :            :     enum {                  /* what were we doing last time we returned?    */
+     130                 :            :         ecp_rsm_init = 0,       /* nothing so far, dummy initial state      */
+     131                 :            :         ecp_rsm_pre_dbl,        /* precompute 2^n multiples                 */
+     132                 :            :         ecp_rsm_pre_norm_dbl,   /* normalize precomputed 2^n multiples      */
+     133                 :            :         ecp_rsm_pre_add,        /* precompute remaining points by adding    */
+     134                 :            :         ecp_rsm_pre_norm_add,   /* normalize all precomputed points         */
+     135                 :            :         ecp_rsm_comb_core,      /* ecp_mul_comb_core()                      */
+     136                 :            :         ecp_rsm_final_norm,     /* do the final normalization               */
+     137                 :            :     } state;
+     138                 :            : };
+     139                 :            : 
+     140                 :            : /*
+     141                 :            :  * Init restart_mul sub-context
+     142                 :            :  */
+     143                 :          0 : static void ecp_restart_rsm_init(mbedtls_ecp_restart_mul_ctx *ctx)
+     144                 :            : {
+     145                 :          0 :     mbedtls_ecp_point_init(&ctx->R);
+     146                 :          0 :     ctx->i = 0;
+     147                 :          0 :     ctx->T = NULL;
+     148                 :          0 :     ctx->T_size = 0;
+     149                 :          0 :     ctx->state = ecp_rsm_init;
+     150                 :          0 : }
+     151                 :            : 
+     152                 :            : /*
+     153                 :            :  * Free the components of a restart_mul sub-context
+     154                 :            :  */
+     155                 :        975 : static void ecp_restart_rsm_free(mbedtls_ecp_restart_mul_ctx *ctx)
+     156                 :            : {
+     157                 :            :     unsigned char i;
+     158                 :            : 
+     159         [ +  - ]:        975 :     if (ctx == NULL) {
+     160                 :        975 :         return;
+     161                 :            :     }
+     162                 :            : 
+     163                 :          0 :     mbedtls_ecp_point_free(&ctx->R);
+     164                 :            : 
+     165         [ #  # ]:          0 :     if (ctx->T != NULL) {
+     166         [ #  # ]:          0 :         for (i = 0; i < ctx->T_size; i++) {
+     167                 :          0 :             mbedtls_ecp_point_free(ctx->T + i);
+     168                 :            :         }
+     169                 :          0 :         mbedtls_free(ctx->T);
+     170                 :            :     }
+     171                 :            : 
+     172                 :          0 :     ecp_restart_rsm_init(ctx);
+     173                 :            : }
+     174                 :            : 
+     175                 :            : /*
+     176                 :            :  * Restart context for ecp_muladd()
+     177                 :            :  */
+     178                 :            : struct mbedtls_ecp_restart_muladd {
+     179                 :            :     mbedtls_ecp_point mP;       /* mP value                             */
+     180                 :            :     mbedtls_ecp_point R;        /* R intermediate result                */
+     181                 :            :     enum {                      /* what should we do next?              */
+     182                 :            :         ecp_rsma_mul1 = 0,      /* first multiplication                 */
+     183                 :            :         ecp_rsma_mul2,          /* second multiplication                */
+     184                 :            :         ecp_rsma_add,           /* addition                             */
+     185                 :            :         ecp_rsma_norm,          /* normalization                        */
+     186                 :            :     } state;
+     187                 :            : };
+     188                 :            : 
+     189                 :            : /*
+     190                 :            :  * Init restart_muladd sub-context
+     191                 :            :  */
+     192                 :          0 : static void ecp_restart_ma_init(mbedtls_ecp_restart_muladd_ctx *ctx)
+     193                 :            : {
+     194                 :          0 :     mbedtls_ecp_point_init(&ctx->mP);
+     195                 :          0 :     mbedtls_ecp_point_init(&ctx->R);
+     196                 :          0 :     ctx->state = ecp_rsma_mul1;
+     197                 :          0 : }
+     198                 :            : 
+     199                 :            : /*
+     200                 :            :  * Free the components of a restart_muladd sub-context
+     201                 :            :  */
+     202                 :        975 : static void ecp_restart_ma_free(mbedtls_ecp_restart_muladd_ctx *ctx)
+     203                 :            : {
+     204         [ +  - ]:        975 :     if (ctx == NULL) {
+     205                 :        975 :         return;
+     206                 :            :     }
+     207                 :            : 
+     208                 :          0 :     mbedtls_ecp_point_free(&ctx->mP);
+     209                 :          0 :     mbedtls_ecp_point_free(&ctx->R);
+     210                 :            : 
+     211                 :          0 :     ecp_restart_ma_init(ctx);
+     212                 :            : }
+     213                 :            : 
+     214                 :            : /*
+     215                 :            :  * Initialize a restart context
+     216                 :            :  */
+     217                 :       2142 : void mbedtls_ecp_restart_init(mbedtls_ecp_restart_ctx *ctx)
+     218                 :            : {
+     219                 :       2142 :     ctx->ops_done = 0;
+     220                 :       2142 :     ctx->depth = 0;
+     221                 :       2142 :     ctx->rsm = NULL;
+     222                 :       2142 :     ctx->ma = NULL;
+     223                 :       2142 : }
+     224                 :            : 
+     225                 :            : /*
+     226                 :            :  * Free the components of a restart context
+     227                 :            :  */
+     228                 :        975 : void mbedtls_ecp_restart_free(mbedtls_ecp_restart_ctx *ctx)
+     229                 :            : {
+     230         [ -  + ]:        975 :     if (ctx == NULL) {
+     231                 :          0 :         return;
+     232                 :            :     }
+     233                 :            : 
+     234                 :        975 :     ecp_restart_rsm_free(ctx->rsm);
+     235                 :        975 :     mbedtls_free(ctx->rsm);
+     236                 :            : 
+     237                 :        975 :     ecp_restart_ma_free(ctx->ma);
+     238                 :        975 :     mbedtls_free(ctx->ma);
+     239                 :            : 
+     240                 :        975 :     mbedtls_ecp_restart_init(ctx);
+     241                 :            : }
+     242                 :            : 
+     243                 :            : /*
+     244                 :            :  * Check if we can do the next step
+     245                 :            :  */
+     246                 :     481474 : int mbedtls_ecp_check_budget(const mbedtls_ecp_group *grp,
+     247                 :            :                              mbedtls_ecp_restart_ctx *rs_ctx,
+     248                 :            :                              unsigned ops)
+     249                 :            : {
+     250   [ -  +  -  - ]:     481474 :     if (rs_ctx != NULL && ecp_max_ops != 0) {
+     251                 :            :         /* scale depending on curve size: the chosen reference is 256-bit,
+     252                 :            :          * and multiplication is quadratic. Round to the closest integer. */
+     253         [ #  # ]:          0 :         if (grp->pbits >= 512) {
+     254                 :          0 :             ops *= 4;
+     255         [ #  # ]:          0 :         } else if (grp->pbits >= 384) {
+     256                 :          0 :             ops *= 2;
+     257                 :            :         }
+     258                 :            : 
+     259                 :            :         /* Avoid infinite loops: always allow first step.
+     260                 :            :          * Because of that, however, it's not generally true
+     261                 :            :          * that ops_done <= ecp_max_ops, so the check
+     262                 :            :          * ops_done > ecp_max_ops below is mandatory. */
+     263         [ #  # ]:          0 :         if ((rs_ctx->ops_done != 0) &&
+     264         [ #  # ]:          0 :             (rs_ctx->ops_done > ecp_max_ops ||
+     265         [ #  # ]:          0 :              ops > ecp_max_ops - rs_ctx->ops_done)) {
+     266                 :          0 :             return MBEDTLS_ERR_ECP_IN_PROGRESS;
+     267                 :            :         }
+     268                 :            : 
+     269                 :            :         /* update running count */
+     270                 :          0 :         rs_ctx->ops_done += ops;
+     271                 :            :     }
+     272                 :            : 
+     273                 :     481474 :     return 0;
+     274                 :            : }
+     275                 :            : 
+     276                 :            : /* Call this when entering a function that needs its own sub-context */
+     277                 :            : #define ECP_RS_ENTER(SUB)   do {                                      \
+     278                 :            :         /* reset ops count for this call if top-level */                    \
+     279                 :            :         if (rs_ctx != NULL && rs_ctx->depth++ == 0)                        \
+     280                 :            :         rs_ctx->ops_done = 0;                                           \
+     281                 :            :                                                                         \
+     282                 :            :         /* set up our own sub-context if needed */                          \
+     283                 :            :         if (mbedtls_ecp_restart_is_enabled() &&                             \
+     284                 :            :             rs_ctx != NULL && rs_ctx->SUB == NULL)                         \
+     285                 :            :         {                                                                   \
+     286                 :            :             rs_ctx->SUB = mbedtls_calloc(1, sizeof(*rs_ctx->SUB));      \
+     287                 :            :             if (rs_ctx->SUB == NULL)                                       \
+     288                 :            :             return MBEDTLS_ERR_ECP_ALLOC_FAILED;                     \
+     289                 :            :                                                                       \
+     290                 :            :             ecp_restart_## SUB ##_init(rs_ctx->SUB);                      \
+     291                 :            :         }                                                                   \
+     292                 :            : } while (0)
+     293                 :            : 
+     294                 :            : /* Call this when leaving a function that needs its own sub-context */
+     295                 :            : #define ECP_RS_LEAVE(SUB)   do {                                      \
+     296                 :            :         /* clear our sub-context when not in progress (done or error) */    \
+     297                 :            :         if (rs_ctx != NULL && rs_ctx->SUB != NULL &&                        \
+     298                 :            :             ret != MBEDTLS_ERR_ECP_IN_PROGRESS)                            \
+     299                 :            :         {                                                                   \
+     300                 :            :             ecp_restart_## SUB ##_free(rs_ctx->SUB);                      \
+     301                 :            :             mbedtls_free(rs_ctx->SUB);                                    \
+     302                 :            :             rs_ctx->SUB = NULL;                                             \
+     303                 :            :         }                                                                   \
+     304                 :            :                                                                         \
+     305                 :            :         if (rs_ctx != NULL)                                                \
+     306                 :            :         rs_ctx->depth--;                                                \
+     307                 :            : } while (0)
+     308                 :            : 
+     309                 :            : #else /* MBEDTLS_ECP_RESTARTABLE */
+     310                 :            : 
+     311                 :            : #define ECP_RS_ENTER(sub)     (void) rs_ctx;
+     312                 :            : #define ECP_RS_LEAVE(sub)     (void) rs_ctx;
+     313                 :            : 
+     314                 :            : #endif /* MBEDTLS_ECP_RESTARTABLE */
+     315                 :            : 
+     316                 :            : #if defined(MBEDTLS_ECP_C)
+     317                 :       9008 : static void mpi_init_many(mbedtls_mpi *arr, size_t size)
+     318                 :            : {
+     319         [ +  + ]:      47994 :     while (size--) {
+     320                 :      38986 :         mbedtls_mpi_init(arr++);
+     321                 :            :     }
+     322                 :       9008 : }
+     323                 :            : 
+     324                 :       9008 : static void mpi_free_many(mbedtls_mpi *arr, size_t size)
+     325                 :            : {
+     326         [ +  + ]:      47994 :     while (size--) {
+     327                 :      38986 :         mbedtls_mpi_free(arr++);
+     328                 :            :     }
+     329                 :       9008 : }
+     330                 :            : #endif /* MBEDTLS_ECP_C */
+     331                 :            : 
+     332                 :            : /*
+     333                 :            :  * List of supported curves:
+     334                 :            :  *  - internal ID
+     335                 :            :  *  - TLS NamedCurve ID (RFC 4492 sec. 5.1.1, RFC 7071 sec. 2, RFC 8446 sec. 4.2.7)
+     336                 :            :  *  - size in bits
+     337                 :            :  *  - readable name
+     338                 :            :  *
+     339                 :            :  * Curves are listed in order: largest curves first, and for a given size,
+     340                 :            :  * fastest curves first.
+     341                 :            :  *
+     342                 :            :  * Reminder: update profiles in x509_crt.c and ssl_tls.c when adding a new curve!
+     343                 :            :  */
+     344                 :            : static const mbedtls_ecp_curve_info ecp_supported_curves[] =
+     345                 :            : {
+     346                 :            : #if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED)
+     347                 :            :     { MBEDTLS_ECP_DP_SECP521R1,    25,     521,    "secp521r1"         },
+     348                 :            : #endif
+     349                 :            : #if defined(MBEDTLS_ECP_DP_BP512R1_ENABLED)
+     350                 :            :     { MBEDTLS_ECP_DP_BP512R1,      28,     512,    "brainpoolP512r1"   },
+     351                 :            : #endif
+     352                 :            : #if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED)
+     353                 :            :     { MBEDTLS_ECP_DP_SECP384R1,    24,     384,    "secp384r1"         },
+     354                 :            : #endif
+     355                 :            : #if defined(MBEDTLS_ECP_DP_BP384R1_ENABLED)
+     356                 :            :     { MBEDTLS_ECP_DP_BP384R1,      27,     384,    "brainpoolP384r1"   },
+     357                 :            : #endif
+     358                 :            : #if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED)
+     359                 :            :     { MBEDTLS_ECP_DP_SECP256R1,    23,     256,    "secp256r1"         },
+     360                 :            : #endif
+     361                 :            : #if defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED)
+     362                 :            :     { MBEDTLS_ECP_DP_SECP256K1,    22,     256,    "secp256k1"         },
+     363                 :            : #endif
+     364                 :            : #if defined(MBEDTLS_ECP_DP_BP256R1_ENABLED)
+     365                 :            :     { MBEDTLS_ECP_DP_BP256R1,      26,     256,    "brainpoolP256r1"   },
+     366                 :            : #endif
+     367                 :            : #if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED)
+     368                 :            :     { MBEDTLS_ECP_DP_SECP224R1,    21,     224,    "secp224r1"         },
+     369                 :            : #endif
+     370                 :            : #if defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED)
+     371                 :            :     { MBEDTLS_ECP_DP_SECP224K1,    20,     224,    "secp224k1"         },
+     372                 :            : #endif
+     373                 :            : #if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED)
+     374                 :            :     { MBEDTLS_ECP_DP_SECP192R1,    19,     192,    "secp192r1"         },
+     375                 :            : #endif
+     376                 :            : #if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED)
+     377                 :            :     { MBEDTLS_ECP_DP_SECP192K1,    18,     192,    "secp192k1"         },
+     378                 :            : #endif
+     379                 :            : #if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED)
+     380                 :            :     { MBEDTLS_ECP_DP_CURVE25519,   29,     256,    "x25519"            },
+     381                 :            : #endif
+     382                 :            : #if defined(MBEDTLS_ECP_DP_CURVE448_ENABLED)
+     383                 :            :     { MBEDTLS_ECP_DP_CURVE448,     30,     448,    "x448"              },
+     384                 :            : #endif
+     385                 :            :     { MBEDTLS_ECP_DP_NONE,          0,     0,      NULL                },
+     386                 :            : };
+     387                 :            : 
+     388                 :            : #define ECP_NB_CURVES   sizeof(ecp_supported_curves) /    \
+     389                 :            :     sizeof(ecp_supported_curves[0])
+     390                 :            : 
+     391                 :            : static mbedtls_ecp_group_id ecp_supported_grp_id[ECP_NB_CURVES];
+     392                 :            : 
+     393                 :            : /*
+     394                 :            :  * List of supported curves and associated info
+     395                 :            :  */
+     396                 :          0 : const mbedtls_ecp_curve_info *mbedtls_ecp_curve_list(void)
+     397                 :            : {
+     398                 :          0 :     return ecp_supported_curves;
+     399                 :            : }
+     400                 :            : 
+     401                 :            : /*
+     402                 :            :  * List of supported curves, group ID only
+     403                 :            :  */
+     404                 :          0 : const mbedtls_ecp_group_id *mbedtls_ecp_grp_id_list(void)
+     405                 :            : {
+     406                 :            :     static int init_done = 0;
+     407                 :            : 
+     408         [ #  # ]:          0 :     if (!init_done) {
+     409                 :          0 :         size_t i = 0;
+     410                 :            :         const mbedtls_ecp_curve_info *curve_info;
+     411                 :            : 
+     412                 :          0 :         for (curve_info = mbedtls_ecp_curve_list();
+     413         [ #  # ]:          0 :              curve_info->grp_id != MBEDTLS_ECP_DP_NONE;
+     414                 :          0 :              curve_info++) {
+     415                 :          0 :             ecp_supported_grp_id[i++] = curve_info->grp_id;
+     416                 :            :         }
+     417                 :          0 :         ecp_supported_grp_id[i] = MBEDTLS_ECP_DP_NONE;
+     418                 :            : 
+     419                 :          0 :         init_done = 1;
+     420                 :            :     }
+     421                 :            : 
+     422                 :          0 :     return ecp_supported_grp_id;
+     423                 :            : }
+     424                 :            : 
+     425                 :            : /*
+     426                 :            :  * Get the curve info for the internal identifier
+     427                 :            :  */
+     428                 :          0 : const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_grp_id(mbedtls_ecp_group_id grp_id)
+     429                 :            : {
+     430                 :            :     const mbedtls_ecp_curve_info *curve_info;
+     431                 :            : 
+     432                 :          0 :     for (curve_info = mbedtls_ecp_curve_list();
+     433         [ #  # ]:          0 :          curve_info->grp_id != MBEDTLS_ECP_DP_NONE;
+     434                 :          0 :          curve_info++) {
+     435         [ #  # ]:          0 :         if (curve_info->grp_id == grp_id) {
+     436                 :          0 :             return curve_info;
+     437                 :            :         }
+     438                 :            :     }
+     439                 :            : 
+     440                 :          0 :     return NULL;
+     441                 :            : }
+     442                 :            : 
+     443                 :            : /*
+     444                 :            :  * Get the curve info from the TLS identifier
+     445                 :            :  */
+     446                 :          0 : const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_tls_id(uint16_t tls_id)
+     447                 :            : {
+     448                 :            :     const mbedtls_ecp_curve_info *curve_info;
+     449                 :            : 
+     450                 :          0 :     for (curve_info = mbedtls_ecp_curve_list();
+     451         [ #  # ]:          0 :          curve_info->grp_id != MBEDTLS_ECP_DP_NONE;
+     452                 :          0 :          curve_info++) {
+     453         [ #  # ]:          0 :         if (curve_info->tls_id == tls_id) {
+     454                 :          0 :             return curve_info;
+     455                 :            :         }
+     456                 :            :     }
+     457                 :            : 
+     458                 :          0 :     return NULL;
+     459                 :            : }
+     460                 :            : 
+     461                 :            : /*
+     462                 :            :  * Get the curve info from the name
+     463                 :            :  */
+     464                 :          0 : const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_name(const char *name)
+     465                 :            : {
+     466                 :            :     const mbedtls_ecp_curve_info *curve_info;
+     467                 :            : 
+     468         [ #  # ]:          0 :     if (name == NULL) {
+     469                 :          0 :         return NULL;
+     470                 :            :     }
+     471                 :            : 
+     472                 :          0 :     for (curve_info = mbedtls_ecp_curve_list();
+     473         [ #  # ]:          0 :          curve_info->grp_id != MBEDTLS_ECP_DP_NONE;
+     474                 :          0 :          curve_info++) {
+     475         [ #  # ]:          0 :         if (strcmp(curve_info->name, name) == 0) {
+     476                 :          0 :             return curve_info;
+     477                 :            :         }
+     478                 :            :     }
+     479                 :            : 
+     480                 :          0 :     return NULL;
+     481                 :            : }
+     482                 :            : 
+     483                 :            : /*
+     484                 :            :  * Get the type of a curve
+     485                 :            :  */
+     486                 :      66475 : mbedtls_ecp_curve_type mbedtls_ecp_get_type(const mbedtls_ecp_group *grp)
+     487                 :            : {
+     488         [ -  + ]:      66475 :     if (grp->G.X.p == NULL) {
+     489                 :          0 :         return MBEDTLS_ECP_TYPE_NONE;
+     490                 :            :     }
+     491                 :            : 
+     492         [ -  + ]:      66475 :     if (grp->G.Y.p == NULL) {
+     493                 :          0 :         return MBEDTLS_ECP_TYPE_MONTGOMERY;
+     494                 :            :     } else {
+     495                 :      66475 :         return MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS;
+     496                 :            :     }
+     497                 :            : }
+     498                 :            : 
+     499                 :            : /*
+     500                 :            :  * Initialize (the components of) a point
+     501                 :            :  */
+     502                 :      58633 : void mbedtls_ecp_point_init(mbedtls_ecp_point *pt)
+     503                 :            : {
+     504                 :      58633 :     mbedtls_mpi_init(&pt->X);
+     505                 :      58633 :     mbedtls_mpi_init(&pt->Y);
+     506                 :      58633 :     mbedtls_mpi_init(&pt->Z);
+     507                 :      58633 : }
+     508                 :            : 
+     509                 :            : /*
+     510                 :            :  * Initialize (the components of) a group
+     511                 :            :  */
+     512                 :      24796 : void mbedtls_ecp_group_init(mbedtls_ecp_group *grp)
+     513                 :            : {
+     514                 :      24796 :     grp->id = MBEDTLS_ECP_DP_NONE;
+     515                 :      24796 :     mbedtls_mpi_init(&grp->P);
+     516                 :      24796 :     mbedtls_mpi_init(&grp->A);
+     517                 :      24796 :     mbedtls_mpi_init(&grp->B);
+     518                 :      24796 :     mbedtls_ecp_point_init(&grp->G);
+     519                 :      24796 :     mbedtls_mpi_init(&grp->N);
+     520                 :      24796 :     grp->pbits = 0;
+     521                 :      24796 :     grp->nbits = 0;
+     522                 :      24796 :     grp->h = 0;
+     523                 :      24796 :     grp->modp = NULL;
+     524                 :      24796 :     grp->t_pre = NULL;
+     525                 :      24796 :     grp->t_post = NULL;
+     526                 :      24796 :     grp->t_data = NULL;
+     527                 :      24796 :     grp->T = NULL;
+     528                 :      24796 :     grp->T_size = 0;
+     529                 :      24796 : }
+     530                 :            : 
+     531                 :            : /*
+     532                 :            :  * Initialize (the components of) a key pair
+     533                 :            :  */
+     534                 :      11167 : void mbedtls_ecp_keypair_init(mbedtls_ecp_keypair *key)
+     535                 :            : {
+     536                 :      11167 :     mbedtls_ecp_group_init(&key->grp);
+     537                 :      11167 :     mbedtls_mpi_init(&key->d);
+     538                 :      11167 :     mbedtls_ecp_point_init(&key->Q);
+     539                 :      11167 : }
+     540                 :            : 
+     541                 :            : /*
+     542                 :            :  * Unallocate (the components of) a point
+     543                 :            :  */
+     544                 :      45397 : void mbedtls_ecp_point_free(mbedtls_ecp_point *pt)
+     545                 :            : {
+     546         [ -  + ]:      45397 :     if (pt == NULL) {
+     547                 :          0 :         return;
+     548                 :            :     }
+     549                 :            : 
+     550                 :      45397 :     mbedtls_mpi_free(&(pt->X));
+     551                 :      45397 :     mbedtls_mpi_free(&(pt->Y));
+     552                 :      45397 :     mbedtls_mpi_free(&(pt->Z));
+     553                 :            : }
+     554                 :            : 
+     555                 :            : /*
+     556                 :            :  * Check that the comb table (grp->T) is static initialized.
+     557                 :            :  */
+     558                 :      26295 : static int ecp_group_is_static_comb_table(const mbedtls_ecp_group *grp)
+     559                 :            : {
+     560                 :            : #if MBEDTLS_ECP_FIXED_POINT_OPTIM == 1
+     561   [ +  +  +  - ]:      26295 :     return grp->T != NULL && grp->T_size == 0;
+     562                 :            : #else
+     563                 :            :     (void) grp;
+     564                 :            :     return 0;
+     565                 :            : #endif
+     566                 :            : }
+     567                 :            : 
+     568                 :            : /*
+     569                 :            :  * Unallocate (the components of) a group
+     570                 :            :  */
+     571                 :      24598 : void mbedtls_ecp_group_free(mbedtls_ecp_group *grp)
+     572                 :            : {
+     573                 :            :     size_t i;
+     574                 :            : 
+     575         [ -  + ]:      24598 :     if (grp == NULL) {
+     576                 :          0 :         return;
+     577                 :            :     }
+     578                 :            : 
+     579         [ +  + ]:      24598 :     if (grp->h != 1) {
+     580                 :      12334 :         mbedtls_mpi_free(&grp->A);
+     581                 :      12334 :         mbedtls_mpi_free(&grp->B);
+     582                 :      12334 :         mbedtls_ecp_point_free(&grp->G);
+     583                 :            : 
+     584                 :            : #if !defined(MBEDTLS_ECP_WITH_MPI_UINT)
+     585                 :      12334 :         mbedtls_mpi_free(&grp->N);
+     586                 :      12334 :         mbedtls_mpi_free(&grp->P);
+     587                 :            : #endif
+     588                 :            :     }
+     589                 :            : 
+     590   [ +  +  -  + ]:      24598 :     if (!ecp_group_is_static_comb_table(grp) && grp->T != NULL) {
+     591         [ #  # ]:          0 :         for (i = 0; i < grp->T_size; i++) {
+     592                 :          0 :             mbedtls_ecp_point_free(&grp->T[i]);
+     593                 :            :         }
+     594                 :          0 :         mbedtls_free(grp->T);
+     595                 :            :     }
+     596                 :            : 
+     597                 :      24598 :     mbedtls_platform_zeroize(grp, sizeof(mbedtls_ecp_group));
+     598                 :            : }
+     599                 :            : 
+     600                 :            : /*
+     601                 :            :  * Unallocate (the components of) a key pair
+     602                 :            :  */
+     603                 :      11161 : void mbedtls_ecp_keypair_free(mbedtls_ecp_keypair *key)
+     604                 :            : {
+     605         [ -  + ]:      11161 :     if (key == NULL) {
+     606                 :          0 :         return;
+     607                 :            :     }
+     608                 :            : 
+     609                 :      11161 :     mbedtls_ecp_group_free(&key->grp);
+     610                 :      11161 :     mbedtls_mpi_free(&key->d);
+     611                 :      11161 :     mbedtls_ecp_point_free(&key->Q);
+     612                 :            : }
+     613                 :            : 
+     614                 :            : /*
+     615                 :            :  * Copy the contents of a point
+     616                 :            :  */
+     617                 :       6915 : int mbedtls_ecp_copy(mbedtls_ecp_point *P, const mbedtls_ecp_point *Q)
+     618                 :            : {
+     619                 :       6915 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     620         [ -  + ]:       6915 :     MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&P->X, &Q->X));
+     621         [ -  + ]:       6915 :     MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&P->Y, &Q->Y));
+     622         [ +  - ]:       6915 :     MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&P->Z, &Q->Z));
+     623                 :            : 
+     624                 :       6915 : cleanup:
+     625                 :       6915 :     return ret;
+     626                 :            : }
+     627                 :            : 
+     628                 :            : /*
+     629                 :            :  * Copy the contents of a group object
+     630                 :            :  */
+     631                 :          6 : int mbedtls_ecp_group_copy(mbedtls_ecp_group *dst, const mbedtls_ecp_group *src)
+     632                 :            : {
+     633                 :          6 :     return mbedtls_ecp_group_load(dst, src->id);
+     634                 :            : }
+     635                 :            : 
+     636                 :            : /*
+     637                 :            :  * Set point to zero
+     638                 :            :  */
+     639                 :          0 : int mbedtls_ecp_set_zero(mbedtls_ecp_point *pt)
+     640                 :            : {
+     641                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     642         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&pt->X, 1));
+     643         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&pt->Y, 1));
+     644         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&pt->Z, 0));
+     645                 :            : 
+     646                 :          0 : cleanup:
+     647                 :          0 :     return ret;
+     648                 :            : }
+     649                 :            : 
+     650                 :            : /*
+     651                 :            :  * Tell if a point is zero
+     652                 :            :  */
+     653                 :       1477 : int mbedtls_ecp_is_zero(mbedtls_ecp_point *pt)
+     654                 :            : {
+     655                 :       1477 :     return mbedtls_mpi_cmp_int(&pt->Z, 0) == 0;
+     656                 :            : }
+     657                 :            : 
+     658                 :            : /*
+     659                 :            :  * Compare two points lazily
+     660                 :            :  */
+     661                 :          0 : int mbedtls_ecp_point_cmp(const mbedtls_ecp_point *P,
+     662                 :            :                           const mbedtls_ecp_point *Q)
+     663                 :            : {
+     664   [ #  #  #  # ]:          0 :     if (mbedtls_mpi_cmp_mpi(&P->X, &Q->X) == 0 &&
+     665         [ #  # ]:          0 :         mbedtls_mpi_cmp_mpi(&P->Y, &Q->Y) == 0 &&
+     666                 :          0 :         mbedtls_mpi_cmp_mpi(&P->Z, &Q->Z) == 0) {
+     667                 :          0 :         return 0;
+     668                 :            :     }
+     669                 :            : 
+     670                 :          0 :     return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+     671                 :            : }
+     672                 :            : 
+     673                 :            : /*
+     674                 :            :  * Import a non-zero point from ASCII strings
+     675                 :            :  */
+     676                 :          0 : int mbedtls_ecp_point_read_string(mbedtls_ecp_point *P, int radix,
+     677                 :            :                                   const char *x, const char *y)
+     678                 :            : {
+     679                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     680         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_read_string(&P->X, radix, x));
+     681         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_read_string(&P->Y, radix, y));
+     682         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&P->Z, 1));
+     683                 :            : 
+     684                 :          0 : cleanup:
+     685                 :          0 :     return ret;
+     686                 :            : }
+     687                 :            : 
+     688                 :            : /*
+     689                 :            :  * Export a point into unsigned binary data (SEC1 2.3.3 and RFC7748)
+     690                 :            :  */
+     691                 :         12 : int mbedtls_ecp_point_write_binary(const mbedtls_ecp_group *grp,
+     692                 :            :                                    const mbedtls_ecp_point *P,
+     693                 :            :                                    int format, size_t *olen,
+     694                 :            :                                    unsigned char *buf, size_t buflen)
+     695                 :            : {
+     696                 :         12 :     int ret = MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
+     697                 :            :     size_t plen;
+     698   [ -  +  -  - ]:         12 :     if (format != MBEDTLS_ECP_PF_UNCOMPRESSED &&
+     699                 :            :         format != MBEDTLS_ECP_PF_COMPRESSED) {
+     700                 :          0 :         return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+     701                 :            :     }
+     702                 :            : 
+     703                 :         12 :     plen = mbedtls_mpi_size(&grp->P);
+     704                 :            : 
+     705                 :            : #if defined(MBEDTLS_ECP_MONTGOMERY_ENABLED)
+     706                 :            :     (void) format; /* Montgomery curves always use the same point format */
+     707         [ -  + ]:         12 :     if (mbedtls_ecp_get_type(grp) == MBEDTLS_ECP_TYPE_MONTGOMERY) {
+     708                 :          0 :         *olen = plen;
+     709         [ #  # ]:          0 :         if (buflen < *olen) {
+     710                 :          0 :             return MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL;
+     711                 :            :         }
+     712                 :            : 
+     713         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary_le(&P->X, buf, plen));
+     714                 :            :     }
+     715                 :            : #endif
+     716                 :            : #if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
+     717         [ -  + ]:         12 :     if (mbedtls_ecp_get_type(grp) == MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS) {
+     718                 :            :         /*
+     719                 :            :          * Common case: P == 0
+     720                 :            :          */
+     721         [ -  + ]:         12 :         if (mbedtls_mpi_cmp_int(&P->Z, 0) == 0) {
+     722         [ #  # ]:          0 :             if (buflen < 1) {
+     723                 :          0 :                 return MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL;
+     724                 :            :             }
+     725                 :            : 
+     726                 :          0 :             buf[0] = 0x00;
+     727                 :          0 :             *olen = 1;
+     728                 :            : 
+     729                 :          0 :             return 0;
+     730                 :            :         }
+     731                 :            : 
+     732         [ +  - ]:         12 :         if (format == MBEDTLS_ECP_PF_UNCOMPRESSED) {
+     733                 :         12 :             *olen = 2 * plen + 1;
+     734                 :            : 
+     735         [ -  + ]:         12 :             if (buflen < *olen) {
+     736                 :          0 :                 return MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL;
+     737                 :            :             }
+     738                 :            : 
+     739                 :         12 :             buf[0] = 0x04;
+     740         [ -  + ]:         12 :             MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(&P->X, buf + 1, plen));
+     741         [ -  + ]:         12 :             MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(&P->Y, buf + 1 + plen, plen));
+     742         [ #  # ]:          0 :         } else if (format == MBEDTLS_ECP_PF_COMPRESSED) {
+     743                 :          0 :             *olen = plen + 1;
+     744                 :            : 
+     745         [ #  # ]:          0 :             if (buflen < *olen) {
+     746                 :          0 :                 return MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL;
+     747                 :            :             }
+     748                 :            : 
+     749                 :          0 :             buf[0] = 0x02 + mbedtls_mpi_get_bit(&P->Y, 0);
+     750         [ #  # ]:          0 :             MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(&P->X, buf + 1, plen));
+     751                 :            :         }
+     752                 :            :     }
+     753                 :            : #endif
+     754                 :            : 
+     755                 :          0 : cleanup:
+     756                 :         12 :     return ret;
+     757                 :            : }
+     758                 :            : 
+     759                 :            : #if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
+     760                 :            : static int mbedtls_ecp_sw_derive_y(const mbedtls_ecp_group *grp,
+     761                 :            :                                    const mbedtls_mpi *X,
+     762                 :            :                                    mbedtls_mpi *Y,
+     763                 :            :                                    int parity_bit);
+     764                 :            : #endif /* MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED */
+     765                 :            : 
+     766                 :            : /*
+     767                 :            :  * Import a point from unsigned binary data (SEC1 2.3.4 and RFC7748)
+     768                 :            :  */
+     769                 :      11161 : int mbedtls_ecp_point_read_binary(const mbedtls_ecp_group *grp,
+     770                 :            :                                   mbedtls_ecp_point *pt,
+     771                 :            :                                   const unsigned char *buf, size_t ilen)
+     772                 :            : {
+     773                 :      11161 :     int ret = MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
+     774                 :            :     size_t plen;
+     775         [ -  + ]:      11161 :     if (ilen < 1) {
+     776                 :          0 :         return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+     777                 :            :     }
+     778                 :            : 
+     779                 :      11161 :     plen = mbedtls_mpi_size(&grp->P);
+     780                 :            : 
+     781                 :            : #if defined(MBEDTLS_ECP_MONTGOMERY_ENABLED)
+     782         [ -  + ]:      11161 :     if (mbedtls_ecp_get_type(grp) == MBEDTLS_ECP_TYPE_MONTGOMERY) {
+     783         [ #  # ]:          0 :         if (plen != ilen) {
+     784                 :          0 :             return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+     785                 :            :         }
+     786                 :            : 
+     787         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary_le(&pt->X, buf, plen));
+     788                 :          0 :         mbedtls_mpi_free(&pt->Y);
+     789                 :            : 
+     790         [ #  # ]:          0 :         if (grp->id == MBEDTLS_ECP_DP_CURVE25519) {
+     791                 :            :             /* Set most significant bit to 0 as prescribed in RFC7748 §5 */
+     792         [ #  # ]:          0 :             MBEDTLS_MPI_CHK(mbedtls_mpi_set_bit(&pt->X, plen * 8 - 1, 0));
+     793                 :            :         }
+     794                 :            : 
+     795         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&pt->Z, 1));
+     796                 :            :     }
+     797                 :            : #endif
+     798                 :            : #if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
+     799         [ +  - ]:      11161 :     if (mbedtls_ecp_get_type(grp) == MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS) {
+     800         [ -  + ]:      11161 :         if (buf[0] == 0x00) {
+     801         [ #  # ]:          0 :             if (ilen == 1) {
+     802                 :          0 :                 return mbedtls_ecp_set_zero(pt);
+     803                 :            :             } else {
+     804                 :          0 :                 return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+     805                 :            :             }
+     806                 :            :         }
+     807                 :            : 
+     808         [ -  + ]:      11161 :         if (ilen < 1 + plen) {
+     809                 :          0 :             return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+     810                 :            :         }
+     811                 :            : 
+     812         [ -  + ]:      11161 :         MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&pt->X, buf + 1, plen));
+     813         [ -  + ]:      11161 :         MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&pt->Z, 1));
+     814                 :            : 
+     815         [ +  - ]:      11161 :         if (buf[0] == 0x04) {
+     816                 :            :             /* format == MBEDTLS_ECP_PF_UNCOMPRESSED */
+     817         [ -  + ]:      11161 :             if (ilen != 1 + plen * 2) {
+     818                 :          0 :                 return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+     819                 :            :             }
+     820                 :      11161 :             return mbedtls_mpi_read_binary(&pt->Y, buf + 1 + plen, plen);
+     821   [ #  #  #  # ]:          0 :         } else if (buf[0] == 0x02 || buf[0] == 0x03) {
+     822                 :            :             /* format == MBEDTLS_ECP_PF_COMPRESSED */
+     823         [ #  # ]:          0 :             if (ilen != 1 + plen) {
+     824                 :          0 :                 return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+     825                 :            :             }
+     826                 :          0 :             return mbedtls_ecp_sw_derive_y(grp, &pt->X, &pt->Y,
+     827                 :          0 :                                            (buf[0] & 1));
+     828                 :            :         } else {
+     829                 :          0 :             return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+     830                 :            :         }
+     831                 :            :     }
+     832                 :            : #endif
+     833                 :            : 
+     834                 :          0 : cleanup:
+     835                 :          0 :     return ret;
+     836                 :            : }
+     837                 :            : 
+     838                 :            : /*
+     839                 :            :  * Import a point from a TLS ECPoint record (RFC 4492)
+     840                 :            :  *      struct {
+     841                 :            :  *          opaque point <1..2^8-1>;
+     842                 :            :  *      } ECPoint;
+     843                 :            :  */
+     844                 :          0 : int mbedtls_ecp_tls_read_point(const mbedtls_ecp_group *grp,
+     845                 :            :                                mbedtls_ecp_point *pt,
+     846                 :            :                                const unsigned char **buf, size_t buf_len)
+     847                 :            : {
+     848                 :            :     unsigned char data_len;
+     849                 :            :     const unsigned char *buf_start;
+     850                 :            :     /*
+     851                 :            :      * We must have at least two bytes (1 for length, at least one for data)
+     852                 :            :      */
+     853         [ #  # ]:          0 :     if (buf_len < 2) {
+     854                 :          0 :         return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+     855                 :            :     }
+     856                 :            : 
+     857                 :          0 :     data_len = *(*buf)++;
+     858   [ #  #  #  # ]:          0 :     if (data_len < 1 || data_len > buf_len - 1) {
+     859                 :          0 :         return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+     860                 :            :     }
+     861                 :            : 
+     862                 :            :     /*
+     863                 :            :      * Save buffer start for read_binary and update buf
+     864                 :            :      */
+     865                 :          0 :     buf_start = *buf;
+     866                 :          0 :     *buf += data_len;
+     867                 :            : 
+     868                 :          0 :     return mbedtls_ecp_point_read_binary(grp, pt, buf_start, data_len);
+     869                 :            : }
+     870                 :            : 
+     871                 :            : /*
+     872                 :            :  * Export a point as a TLS ECPoint record (RFC 4492)
+     873                 :            :  *      struct {
+     874                 :            :  *          opaque point <1..2^8-1>;
+     875                 :            :  *      } ECPoint;
+     876                 :            :  */
+     877                 :          0 : int mbedtls_ecp_tls_write_point(const mbedtls_ecp_group *grp, const mbedtls_ecp_point *pt,
+     878                 :            :                                 int format, size_t *olen,
+     879                 :            :                                 unsigned char *buf, size_t blen)
+     880                 :            : {
+     881                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     882   [ #  #  #  # ]:          0 :     if (format != MBEDTLS_ECP_PF_UNCOMPRESSED &&
+     883                 :            :         format != MBEDTLS_ECP_PF_COMPRESSED) {
+     884                 :          0 :         return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+     885                 :            :     }
+     886                 :            : 
+     887                 :            :     /*
+     888                 :            :      * buffer length must be at least one, for our length byte
+     889                 :            :      */
+     890         [ #  # ]:          0 :     if (blen < 1) {
+     891                 :          0 :         return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+     892                 :            :     }
+     893                 :            : 
+     894         [ #  # ]:          0 :     if ((ret = mbedtls_ecp_point_write_binary(grp, pt, format,
+     895                 :            :                                               olen, buf + 1, blen - 1)) != 0) {
+     896                 :          0 :         return ret;
+     897                 :            :     }
+     898                 :            : 
+     899                 :            :     /*
+     900                 :            :      * write length to the first byte and update total length
+     901                 :            :      */
+     902                 :          0 :     buf[0] = (unsigned char) *olen;
+     903                 :          0 :     ++*olen;
+     904                 :            : 
+     905                 :          0 :     return 0;
+     906                 :            : }
+     907                 :            : 
+     908                 :            : /*
+     909                 :            :  * Set a group from an ECParameters record (RFC 4492)
+     910                 :            :  */
+     911                 :          0 : int mbedtls_ecp_tls_read_group(mbedtls_ecp_group *grp,
+     912                 :            :                                const unsigned char **buf, size_t len)
+     913                 :            : {
+     914                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     915                 :            :     mbedtls_ecp_group_id grp_id;
+     916         [ #  # ]:          0 :     if ((ret = mbedtls_ecp_tls_read_group_id(&grp_id, buf, len)) != 0) {
+     917                 :          0 :         return ret;
+     918                 :            :     }
+     919                 :            : 
+     920                 :          0 :     return mbedtls_ecp_group_load(grp, grp_id);
+     921                 :            : }
+     922                 :            : 
+     923                 :            : /*
+     924                 :            :  * Read a group id from an ECParameters record (RFC 4492) and convert it to
+     925                 :            :  * mbedtls_ecp_group_id.
+     926                 :            :  */
+     927                 :          0 : int mbedtls_ecp_tls_read_group_id(mbedtls_ecp_group_id *grp,
+     928                 :            :                                   const unsigned char **buf, size_t len)
+     929                 :            : {
+     930                 :            :     uint16_t tls_id;
+     931                 :            :     const mbedtls_ecp_curve_info *curve_info;
+     932                 :            :     /*
+     933                 :            :      * We expect at least three bytes (see below)
+     934                 :            :      */
+     935         [ #  # ]:          0 :     if (len < 3) {
+     936                 :          0 :         return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+     937                 :            :     }
+     938                 :            : 
+     939                 :            :     /*
+     940                 :            :      * First byte is curve_type; only named_curve is handled
+     941                 :            :      */
+     942         [ #  # ]:          0 :     if (*(*buf)++ != MBEDTLS_ECP_TLS_NAMED_CURVE) {
+     943                 :          0 :         return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+     944                 :            :     }
+     945                 :            : 
+     946                 :            :     /*
+     947                 :            :      * Next two bytes are the namedcurve value
+     948                 :            :      */
+     949                 :          0 :     tls_id = MBEDTLS_GET_UINT16_BE(*buf, 0);
+     950                 :          0 :     *buf += 2;
+     951                 :            : 
+     952         [ #  # ]:          0 :     if ((curve_info = mbedtls_ecp_curve_info_from_tls_id(tls_id)) == NULL) {
+     953                 :          0 :         return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
+     954                 :            :     }
+     955                 :            : 
+     956                 :          0 :     *grp = curve_info->grp_id;
+     957                 :            : 
+     958                 :          0 :     return 0;
+     959                 :            : }
+     960                 :            : 
+     961                 :            : /*
+     962                 :            :  * Write the ECParameters record corresponding to a group (RFC 4492)
+     963                 :            :  */
+     964                 :          0 : int mbedtls_ecp_tls_write_group(const mbedtls_ecp_group *grp, size_t *olen,
+     965                 :            :                                 unsigned char *buf, size_t blen)
+     966                 :            : {
+     967                 :            :     const mbedtls_ecp_curve_info *curve_info;
+     968         [ #  # ]:          0 :     if ((curve_info = mbedtls_ecp_curve_info_from_grp_id(grp->id)) == NULL) {
+     969                 :          0 :         return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+     970                 :            :     }
+     971                 :            : 
+     972                 :            :     /*
+     973                 :            :      * We are going to write 3 bytes (see below)
+     974                 :            :      */
+     975                 :          0 :     *olen = 3;
+     976         [ #  # ]:          0 :     if (blen < *olen) {
+     977                 :          0 :         return MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL;
+     978                 :            :     }
+     979                 :            : 
+     980                 :            :     /*
+     981                 :            :      * First byte is curve_type, always named_curve
+     982                 :            :      */
+     983                 :          0 :     *buf++ = MBEDTLS_ECP_TLS_NAMED_CURVE;
+     984                 :            : 
+     985                 :            :     /*
+     986                 :            :      * Next two bytes are the namedcurve value
+     987                 :            :      */
+     988                 :          0 :     MBEDTLS_PUT_UINT16_BE(curve_info->tls_id, buf, 0);
+     989                 :            : 
+     990                 :          0 :     return 0;
+     991                 :            : }
+     992                 :            : 
+     993                 :            : /*
+     994                 :            :  * Wrapper around fast quasi-modp functions, with fall-back to mbedtls_mpi_mod_mpi.
+     995                 :            :  * See the documentation of struct mbedtls_ecp_group.
+     996                 :            :  *
+     997                 :            :  * This function is in the critial loop for mbedtls_ecp_mul, so pay attention to perf.
+     998                 :            :  */
+     999                 :    6030023 : static int ecp_modp(mbedtls_mpi *N, const mbedtls_ecp_group *grp)
+    1000                 :            : {
+    1001                 :    6030023 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1002                 :            : 
+    1003         [ -  + ]:    6030023 :     if (grp->modp == NULL) {
+    1004                 :          0 :         return mbedtls_mpi_mod_mpi(N, N, &grp->P);
+    1005                 :            :     }
+    1006                 :            : 
+    1007                 :            :     /* N->s < 0 is a much faster test, which fails only if N is 0 */
+    1008   [ -  +  -  - ]:    6030023 :     if ((N->s < 0 && mbedtls_mpi_cmp_int(N, 0) != 0) ||
+    1009         [ -  + ]:    6030023 :         mbedtls_mpi_bitlen(N) > 2 * grp->pbits) {
+    1010                 :          0 :         return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+    1011                 :            :     }
+    1012                 :            : 
+    1013         [ -  + ]:    6030023 :     MBEDTLS_MPI_CHK(grp->modp(N));
+    1014                 :            : 
+    1015                 :            :     /* N->s < 0 is a much faster test, which fails only if N is 0 */
+    1016   [ +  +  +  - ]:   10906439 :     while (N->s < 0 && mbedtls_mpi_cmp_int(N, 0) != 0) {
+    1017         [ -  + ]:    4876416 :         MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(N, N, &grp->P));
+    1018                 :            :     }
+    1019                 :            : 
+    1020         [ +  + ]:    7123070 :     while (mbedtls_mpi_cmp_mpi(N, &grp->P) >= 0) {
+    1021                 :            :         /* we known P, N and the result are positive */
+    1022         [ -  + ]:    1093047 :         MBEDTLS_MPI_CHK(mbedtls_mpi_sub_abs(N, N, &grp->P));
+    1023                 :            :     }
+    1024                 :            : 
+    1025                 :    6030023 : cleanup:
+    1026                 :    6030023 :     return ret;
+    1027                 :            : }
+    1028                 :            : 
+    1029                 :            : /*
+    1030                 :            :  * Fast mod-p functions expect their argument to be in the 0..p^2 range.
+    1031                 :            :  *
+    1032                 :            :  * In order to guarantee that, we need to ensure that operands of
+    1033                 :            :  * mbedtls_mpi_mul_mpi are in the 0..p range. So, after each operation we will
+    1034                 :            :  * bring the result back to this range.
+    1035                 :            :  *
+    1036                 :            :  * The following macros are shortcuts for doing that.
+    1037                 :            :  */
+    1038                 :            : 
+    1039                 :            : /*
+    1040                 :            :  * Reduce a mbedtls_mpi mod p in-place, general case, to use after mbedtls_mpi_mul_mpi
+    1041                 :            :  */
+    1042                 :            : #if defined(MBEDTLS_SELF_TEST)
+    1043                 :            : #define INC_MUL_COUNT   mul_count++;
+    1044                 :            : #else
+    1045                 :            : #define INC_MUL_COUNT
+    1046                 :            : #endif
+    1047                 :            : 
+    1048                 :            : #define MOD_MUL(N)                                                    \
+    1049                 :            :     do                                                                  \
+    1050                 :            :     {                                                                   \
+    1051                 :            :         MBEDTLS_MPI_CHK(ecp_modp(&(N), grp));                       \
+    1052                 :            :         INC_MUL_COUNT                                                   \
+    1053                 :            :     } while (0)
+    1054                 :            : 
+    1055                 :    6030023 : static inline int mbedtls_mpi_mul_mod(const mbedtls_ecp_group *grp,
+    1056                 :            :                                       mbedtls_mpi *X,
+    1057                 :            :                                       const mbedtls_mpi *A,
+    1058                 :            :                                       const mbedtls_mpi *B)
+    1059                 :            : {
+    1060                 :    6030023 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1061         [ -  + ]:    6030023 :     MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(X, A, B));
+    1062         [ -  + ]:    6030023 :     MOD_MUL(*X);
+    1063                 :    6030023 : cleanup:
+    1064                 :    6030023 :     return ret;
+    1065                 :            : }
+    1066                 :            : 
+    1067                 :            : /*
+    1068                 :            :  * Reduce a mbedtls_mpi mod p in-place, to use after mbedtls_mpi_sub_mpi
+    1069                 :            :  * N->s < 0 is a very fast test, which fails only if N is 0
+    1070                 :            :  */
+    1071                 :            : #define MOD_SUB(N)                                                          \
+    1072                 :            :     do {                                                                      \
+    1073                 :            :         while ((N)->s < 0 && mbedtls_mpi_cmp_int((N), 0) != 0)             \
+    1074                 :            :         MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi((N), (N), &grp->P));      \
+    1075                 :            :     } while (0)
+    1076                 :            : 
+    1077                 :            : MBEDTLS_MAYBE_UNUSED
+    1078                 :    3498864 : static inline int mbedtls_mpi_sub_mod(const mbedtls_ecp_group *grp,
+    1079                 :            :                                       mbedtls_mpi *X,
+    1080                 :            :                                       const mbedtls_mpi *A,
+    1081                 :            :                                       const mbedtls_mpi *B)
+    1082                 :            : {
+    1083                 :    3498864 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1084         [ -  + ]:    3498864 :     MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(X, A, B));
+    1085   [ -  +  +  +  :    5257692 :     MOD_SUB(X);
+                   +  - ]
+    1086                 :    3498864 : cleanup:
+    1087                 :    3498864 :     return ret;
+    1088                 :            : }
+    1089                 :            : 
+    1090                 :            : /*
+    1091                 :            :  * Reduce a mbedtls_mpi mod p in-place, to use after mbedtls_mpi_add_mpi and mbedtls_mpi_mul_int.
+    1092                 :            :  * We known P, N and the result are positive, so sub_abs is correct, and
+    1093                 :            :  * a bit faster.
+    1094                 :            :  */
+    1095                 :            : #define MOD_ADD(N)                                                   \
+    1096                 :            :     while (mbedtls_mpi_cmp_mpi((N), &grp->P) >= 0)                  \
+    1097                 :            :     MBEDTLS_MPI_CHK(mbedtls_mpi_sub_abs((N), (N), &grp->P))
+    1098                 :            : 
+    1099                 :     480691 : static inline int mbedtls_mpi_add_mod(const mbedtls_ecp_group *grp,
+    1100                 :            :                                       mbedtls_mpi *X,
+    1101                 :            :                                       const mbedtls_mpi *A,
+    1102                 :            :                                       const mbedtls_mpi *B)
+    1103                 :            : {
+    1104                 :     480691 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1105         [ -  + ]:     480691 :     MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(X, A, B));
+    1106   [ -  +  +  + ]:     712360 :     MOD_ADD(X);
+    1107                 :     480691 : cleanup:
+    1108                 :     480691 :     return ret;
+    1109                 :            : }
+    1110                 :            : 
+    1111                 :            : MBEDTLS_MAYBE_UNUSED
+    1112                 :     466356 : static inline int mbedtls_mpi_mul_int_mod(const mbedtls_ecp_group *grp,
+    1113                 :            :                                           mbedtls_mpi *X,
+    1114                 :            :                                           const mbedtls_mpi *A,
+    1115                 :            :                                           mbedtls_mpi_uint c)
+    1116                 :            : {
+    1117                 :     466356 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1118                 :            : 
+    1119         [ -  + ]:     466356 :     MBEDTLS_MPI_CHK(mbedtls_mpi_mul_int(X, A, c));
+    1120   [ -  +  +  + ]:     924150 :     MOD_ADD(X);
+    1121                 :     466356 : cleanup:
+    1122                 :     466356 :     return ret;
+    1123                 :            : }
+    1124                 :            : 
+    1125                 :            : MBEDTLS_MAYBE_UNUSED
+    1126                 :      14335 : static inline int mbedtls_mpi_sub_int_mod(const mbedtls_ecp_group *grp,
+    1127                 :            :                                           mbedtls_mpi *X,
+    1128                 :            :                                           const mbedtls_mpi *A,
+    1129                 :            :                                           mbedtls_mpi_uint c)
+    1130                 :            : {
+    1131                 :      14335 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1132                 :            : 
+    1133         [ -  + ]:      14335 :     MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(X, A, c));
+    1134   [ -  -  +  -  :      14335 :     MOD_SUB(X);
+                   -  - ]
+    1135                 :      14335 : cleanup:
+    1136                 :      14335 :     return ret;
+    1137                 :            : }
+    1138                 :            : 
+    1139                 :            : #define MPI_ECP_SUB_INT(X, A, c)             \
+    1140                 :            :     MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int_mod(grp, X, A, c))
+    1141                 :            : 
+    1142                 :            : MBEDTLS_MAYBE_UNUSED
+    1143                 :    2059938 : static inline int mbedtls_mpi_shift_l_mod(const mbedtls_ecp_group *grp,
+    1144                 :            :                                           mbedtls_mpi *X,
+    1145                 :            :                                           size_t count)
+    1146                 :            : {
+    1147                 :    2059938 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1148         [ -  + ]:    2059938 :     MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(X, count));
+    1149   [ -  +  +  + ]:    3069579 :     MOD_ADD(X);
+    1150                 :    2059938 : cleanup:
+    1151                 :    2059938 :     return ret;
+    1152                 :            : }
+    1153                 :            : 
+    1154                 :            : /*
+    1155                 :            :  * Macro wrappers around ECP modular arithmetic
+    1156                 :            :  *
+    1157                 :            :  * Currently, these wrappers are defined via the bignum module.
+    1158                 :            :  */
+    1159                 :            : 
+    1160                 :            : #define MPI_ECP_ADD(X, A, B)                                                  \
+    1161                 :            :     MBEDTLS_MPI_CHK(mbedtls_mpi_add_mod(grp, X, A, B))
+    1162                 :            : 
+    1163                 :            : #define MPI_ECP_SUB(X, A, B)                                                  \
+    1164                 :            :     MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mod(grp, X, A, B))
+    1165                 :            : 
+    1166                 :            : #define MPI_ECP_MUL(X, A, B)                                                  \
+    1167                 :            :     MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
+    1168                 :            : 
+    1169                 :            : #define MPI_ECP_SQR(X, A)                                                     \
+    1170                 :            :     MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, A))
+    1171                 :            : 
+    1172                 :            : #define MPI_ECP_MUL_INT(X, A, c)                                              \
+    1173                 :            :     MBEDTLS_MPI_CHK(mbedtls_mpi_mul_int_mod(grp, X, A, c))
+    1174                 :            : 
+    1175                 :            : #define MPI_ECP_INV(dst, src)                                                 \
+    1176                 :            :     MBEDTLS_MPI_CHK(mbedtls_mpi_inv_mod((dst), (src), &grp->P))
+    1177                 :            : 
+    1178                 :            : #define MPI_ECP_MOV(X, A)                                                     \
+    1179                 :            :     MBEDTLS_MPI_CHK(mbedtls_mpi_copy(X, A))
+    1180                 :            : 
+    1181                 :            : #define MPI_ECP_SHIFT_L(X, count)                                             \
+    1182                 :            :     MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l_mod(grp, X, count))
+    1183                 :            : 
+    1184                 :            : #define MPI_ECP_LSET(X, c)                                                    \
+    1185                 :            :     MBEDTLS_MPI_CHK(mbedtls_mpi_lset(X, c))
+    1186                 :            : 
+    1187                 :            : #define MPI_ECP_CMP_INT(X, c)                                                 \
+    1188                 :            :     mbedtls_mpi_cmp_int(X, c)
+    1189                 :            : 
+    1190                 :            : #define MPI_ECP_CMP(X, Y)                                                     \
+    1191                 :            :     mbedtls_mpi_cmp_mpi(X, Y)
+    1192                 :            : 
+    1193                 :            : /* Needs f_rng, p_rng to be defined. */
+    1194                 :            : #define MPI_ECP_RAND(X)                                                       \
+    1195                 :            :     MBEDTLS_MPI_CHK(mbedtls_mpi_random((X), 2, &grp->P, f_rng, p_rng))
+    1196                 :            : 
+    1197                 :            : /* Conditional negation
+    1198                 :            :  * Needs grp and a temporary MPI tmp to be defined. */
+    1199                 :            : #define MPI_ECP_COND_NEG(X, cond)                                        \
+    1200                 :            :     do                                                                     \
+    1201                 :            :     {                                                                      \
+    1202                 :            :         unsigned char nonzero = mbedtls_mpi_cmp_int((X), 0) != 0;        \
+    1203                 :            :         MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&tmp, &grp->P, (X)));      \
+    1204                 :            :         MBEDTLS_MPI_CHK(mbedtls_mpi_safe_cond_assign((X), &tmp,          \
+    1205                 :            :                                                      nonzero & cond)); \
+    1206                 :            :     } while (0)
+    1207                 :            : 
+    1208                 :            : #define MPI_ECP_NEG(X) MPI_ECP_COND_NEG((X), 1)
+    1209                 :            : 
+    1210                 :            : #define MPI_ECP_VALID(X)                      \
+    1211                 :            :     ((X)->p != NULL)
+    1212                 :            : 
+    1213                 :            : #define MPI_ECP_COND_ASSIGN(X, Y, cond)       \
+    1214                 :            :     MBEDTLS_MPI_CHK(mbedtls_mpi_safe_cond_assign((X), (Y), (cond)))
+    1215                 :            : 
+    1216                 :            : #define MPI_ECP_COND_SWAP(X, Y, cond)       \
+    1217                 :            :     MBEDTLS_MPI_CHK(mbedtls_mpi_safe_cond_swap((X), (Y), (cond)))
+    1218                 :            : 
+    1219                 :            : #if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
+    1220                 :            : 
+    1221                 :            : /*
+    1222                 :            :  * Computes the right-hand side of the Short Weierstrass equation
+    1223                 :            :  * RHS = X^3 + A X + B
+    1224                 :            :  */
+    1225                 :      14335 : static int ecp_sw_rhs(const mbedtls_ecp_group *grp,
+    1226                 :            :                       mbedtls_mpi *rhs,
+    1227                 :            :                       const mbedtls_mpi *X)
+    1228                 :            : {
+    1229                 :            :     int ret;
+    1230                 :            : 
+    1231                 :            :     /* Compute X^3 + A X + B as X (X^2 + A) + B */
+    1232         [ -  + ]:      14335 :     MPI_ECP_SQR(rhs, X);
+    1233                 :            : 
+    1234                 :            :     /* Special case for A = -3 */
+    1235         [ +  - ]:      14335 :     if (mbedtls_ecp_group_a_is_minus_3(grp)) {
+    1236         [ -  + ]:      14335 :         MPI_ECP_SUB_INT(rhs, rhs, 3);
+    1237                 :            :     } else {
+    1238         [ #  # ]:          0 :         MPI_ECP_ADD(rhs, rhs, &grp->A);
+    1239                 :            :     }
+    1240                 :            : 
+    1241         [ -  + ]:      14335 :     MPI_ECP_MUL(rhs, rhs, X);
+    1242         [ +  - ]:      14335 :     MPI_ECP_ADD(rhs, rhs, &grp->B);
+    1243                 :            : 
+    1244                 :      14335 : cleanup:
+    1245                 :      14335 :     return ret;
+    1246                 :            : }
+    1247                 :            : 
+    1248                 :            : /*
+    1249                 :            :  * Derive Y from X and a parity bit
+    1250                 :            :  */
+    1251                 :          0 : static int mbedtls_ecp_sw_derive_y(const mbedtls_ecp_group *grp,
+    1252                 :            :                                    const mbedtls_mpi *X,
+    1253                 :            :                                    mbedtls_mpi *Y,
+    1254                 :            :                                    int parity_bit)
+    1255                 :            : {
+    1256                 :            :     /* w = y^2 = x^3 + ax + b
+    1257                 :            :      * y = sqrt(w) = w^((p+1)/4) mod p   (for prime p where p = 3 mod 4)
+    1258                 :            :      *
+    1259                 :            :      * Note: this method for extracting square root does not validate that w
+    1260                 :            :      * was indeed a square so this function will return garbage in Y if X
+    1261                 :            :      * does not correspond to a point on the curve.
+    1262                 :            :      */
+    1263                 :            : 
+    1264                 :            :     /* Check prerequisite p = 3 mod 4 */
+    1265   [ #  #  #  # ]:          0 :     if (mbedtls_mpi_get_bit(&grp->P, 0) != 1 ||
+    1266                 :          0 :         mbedtls_mpi_get_bit(&grp->P, 1) != 1) {
+    1267                 :          0 :         return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
+    1268                 :            :     }
+    1269                 :            : 
+    1270                 :            :     int ret;
+    1271                 :            :     mbedtls_mpi exp;
+    1272                 :          0 :     mbedtls_mpi_init(&exp);
+    1273                 :            : 
+    1274                 :            :     /* use Y to store intermediate result, actually w above */
+    1275         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(ecp_sw_rhs(grp, Y, X));
+    1276                 :            : 
+    1277                 :            :     /* w = y^2 */ /* Y contains y^2 intermediate result */
+    1278                 :            :     /* exp = ((p+1)/4) */
+    1279         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_add_int(&exp, &grp->P, 1));
+    1280         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&exp, 2));
+    1281                 :            :     /* sqrt(w) = w^((p+1)/4) mod p   (for prime p where p = 3 mod 4) */
+    1282         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_exp_mod(Y, Y /*y^2*/, &exp, &grp->P, NULL));
+    1283                 :            : 
+    1284                 :            :     /* check parity bit match or else invert Y */
+    1285                 :            :     /* This quick inversion implementation is valid because Y != 0 for all
+    1286                 :            :      * Short Weierstrass curves supported by mbedtls, as each supported curve
+    1287                 :            :      * has an order that is a large prime, so each supported curve does not
+    1288                 :            :      * have any point of order 2, and a point with Y == 0 would be of order 2 */
+    1289         [ #  # ]:          0 :     if (mbedtls_mpi_get_bit(Y, 0) != parity_bit) {
+    1290         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(Y, &grp->P, Y));
+    1291                 :            :     }
+    1292                 :            : 
+    1293                 :          0 : cleanup:
+    1294                 :            : 
+    1295                 :          0 :     mbedtls_mpi_free(&exp);
+    1296                 :          0 :     return ret;
+    1297                 :            : }
+    1298                 :            : #endif /* MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED */
+    1299                 :            : 
+    1300                 :            : #if defined(MBEDTLS_ECP_C)
+    1301                 :            : #if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
+    1302                 :            : /*
+    1303                 :            :  * For curves in short Weierstrass form, we do all the internal operations in
+    1304                 :            :  * Jacobian coordinates.
+    1305                 :            :  *
+    1306                 :            :  * For multiplication, we'll use a comb method with countermeasures against
+    1307                 :            :  * SPA, hence timing attacks.
+    1308                 :            :  */
+    1309                 :            : 
+    1310                 :            : /*
+    1311                 :            :  * Normalize jacobian coordinates so that Z == 0 || Z == 1  (GECC 3.2.1)
+    1312                 :            :  * Cost: 1N := 1I + 3M + 1S
+    1313                 :            :  */
+    1314                 :       4577 : static int ecp_normalize_jac(const mbedtls_ecp_group *grp, mbedtls_ecp_point *pt)
+    1315                 :            : {
+    1316         [ -  + ]:       4577 :     if (MPI_ECP_CMP_INT(&pt->Z, 0) == 0) {
+    1317                 :          0 :         return 0;
+    1318                 :            :     }
+    1319                 :            : 
+    1320                 :            : #if defined(MBEDTLS_ECP_NORMALIZE_JAC_ALT)
+    1321                 :            :     if (mbedtls_internal_ecp_grp_capable(grp)) {
+    1322                 :            :         return mbedtls_internal_ecp_normalize_jac(grp, pt);
+    1323                 :            :     }
+    1324                 :            : #endif /* MBEDTLS_ECP_NORMALIZE_JAC_ALT */
+    1325                 :            : 
+    1326                 :            : #if defined(MBEDTLS_ECP_NO_FALLBACK) && defined(MBEDTLS_ECP_NORMALIZE_JAC_ALT)
+    1327                 :            :     return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
+    1328                 :            : #else
+    1329                 :       4577 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1330                 :            :     mbedtls_mpi T;
+    1331                 :       4577 :     mbedtls_mpi_init(&T);
+    1332                 :            : 
+    1333         [ -  + ]:       4577 :     MPI_ECP_INV(&T,       &pt->Z);            /* T   <-          1 / Z   */
+    1334         [ -  + ]:       4577 :     MPI_ECP_MUL(&pt->Y,   &pt->Y,     &T);    /* Y'  <- Y*T    = Y / Z   */
+    1335         [ -  + ]:       4577 :     MPI_ECP_SQR(&T,       &T);                /* T   <- T^2    = 1 / Z^2 */
+    1336         [ -  + ]:       4577 :     MPI_ECP_MUL(&pt->X,   &pt->X,     &T);    /* X   <- X  * T = X / Z^2 */
+    1337         [ -  + ]:       4577 :     MPI_ECP_MUL(&pt->Y,   &pt->Y,     &T);    /* Y'' <- Y' * T = Y / Z^3 */
+    1338                 :            : 
+    1339         [ +  - ]:       4577 :     MPI_ECP_LSET(&pt->Z, 1);
+    1340                 :            : 
+    1341                 :       4577 : cleanup:
+    1342                 :            : 
+    1343                 :       4577 :     mbedtls_mpi_free(&T);
+    1344                 :            : 
+    1345                 :       4577 :     return ret;
+    1346                 :            : #endif /* !defined(MBEDTLS_ECP_NO_FALLBACK) || !defined(MBEDTLS_ECP_NORMALIZE_JAC_ALT) */
+    1347                 :            : }
+    1348                 :            : 
+    1349                 :            : /*
+    1350                 :            :  * Normalize jacobian coordinates of an array of (pointers to) points,
+    1351                 :            :  * using Montgomery's trick to perform only one inversion mod P.
+    1352                 :            :  * (See for example Cohen's "A Course in Computational Algebraic Number
+    1353                 :            :  * Theory", Algorithm 10.3.4.)
+    1354                 :            :  *
+    1355                 :            :  * Warning: fails (returning an error) if one of the points is zero!
+    1356                 :            :  * This should never happen, see choice of w in ecp_mul_comb().
+    1357                 :            :  *
+    1358                 :            :  * Cost: 1N(t) := 1I + (6t - 3)M + 1S
+    1359                 :            :  */
+    1360                 :       2954 : static int ecp_normalize_jac_many(const mbedtls_ecp_group *grp,
+    1361                 :            :                                   mbedtls_ecp_point *T[], size_t T_size)
+    1362                 :            : {
+    1363         [ -  + ]:       2954 :     if (T_size < 2) {
+    1364                 :          0 :         return ecp_normalize_jac(grp, *T);
+    1365                 :            :     }
+    1366                 :            : 
+    1367                 :            : #if defined(MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT)
+    1368                 :            :     if (mbedtls_internal_ecp_grp_capable(grp)) {
+    1369                 :            :         return mbedtls_internal_ecp_normalize_jac_many(grp, T, T_size);
+    1370                 :            :     }
+    1371                 :            : #endif
+    1372                 :            : 
+    1373                 :            : #if defined(MBEDTLS_ECP_NO_FALLBACK) && defined(MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT)
+    1374                 :            :     return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
+    1375                 :            : #else
+    1376                 :       2954 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1377                 :            :     size_t i;
+    1378                 :            :     mbedtls_mpi *c, t;
+    1379                 :            : 
+    1380         [ -  + ]:       2954 :     if ((c = mbedtls_calloc(T_size, sizeof(mbedtls_mpi))) == NULL) {
+    1381                 :          0 :         return MBEDTLS_ERR_ECP_ALLOC_FAILED;
+    1382                 :            :     }
+    1383                 :            : 
+    1384                 :       2954 :     mbedtls_mpi_init(&t);
+    1385                 :            : 
+    1386                 :       2954 :     mpi_init_many(c, T_size);
+    1387                 :            :     /*
+    1388                 :            :      * c[i] = Z_0 * ... * Z_i,   i = 0,..,n := T_size-1
+    1389                 :            :      */
+    1390         [ -  + ]:       2954 :     MPI_ECP_MOV(&c[0], &T[0]->Z);
+    1391         [ +  + ]:      14770 :     for (i = 1; i < T_size; i++) {
+    1392         [ -  + ]:      11816 :         MPI_ECP_MUL(&c[i], &c[i-1], &T[i]->Z);
+    1393                 :            :     }
+    1394                 :            : 
+    1395                 :            :     /*
+    1396                 :            :      * c[n] = 1 / (Z_0 * ... * Z_n) mod P
+    1397                 :            :      */
+    1398         [ -  + ]:       2954 :     MPI_ECP_INV(&c[T_size-1], &c[T_size-1]);
+    1399                 :            : 
+    1400                 :      14770 :     for (i = T_size - 1;; i--) {
+    1401                 :            :         /* At the start of iteration i (note that i decrements), we have
+    1402                 :            :          * - c[j] = Z_0 * .... * Z_j        for j  < i,
+    1403                 :            :          * - c[j] = 1 / (Z_0 * .... * Z_j)  for j == i,
+    1404                 :            :          *
+    1405                 :            :          * This is maintained via
+    1406                 :            :          * - c[i-1] <- c[i] * Z_i
+    1407                 :            :          *
+    1408                 :            :          * We also derive 1/Z_i = c[i] * c[i-1] for i>0 and use that
+    1409                 :            :          * to do the actual normalization. For i==0, we already have
+    1410                 :            :          * c[0] = 1 / Z_0.
+    1411                 :            :          */
+    1412                 :            : 
+    1413         [ +  + ]:      14770 :         if (i > 0) {
+    1414                 :            :             /* Compute 1/Z_i and establish invariant for the next iteration. */
+    1415         [ -  + ]:      11816 :             MPI_ECP_MUL(&t,      &c[i], &c[i-1]);
+    1416         [ -  + ]:      11816 :             MPI_ECP_MUL(&c[i-1], &c[i], &T[i]->Z);
+    1417                 :            :         } else {
+    1418         [ -  + ]:       2954 :             MPI_ECP_MOV(&t, &c[0]);
+    1419                 :            :         }
+    1420                 :            : 
+    1421                 :            :         /* Now t holds 1 / Z_i; normalize as in ecp_normalize_jac() */
+    1422         [ -  + ]:      14770 :         MPI_ECP_MUL(&T[i]->Y, &T[i]->Y, &t);
+    1423         [ -  + ]:      14770 :         MPI_ECP_SQR(&t,       &t);
+    1424         [ -  + ]:      14770 :         MPI_ECP_MUL(&T[i]->X, &T[i]->X, &t);
+    1425         [ -  + ]:      14770 :         MPI_ECP_MUL(&T[i]->Y, &T[i]->Y, &t);
+    1426                 :            : 
+    1427                 :            :         /*
+    1428                 :            :          * Post-precessing: reclaim some memory by shrinking coordinates
+    1429                 :            :          * - not storing Z (always 1)
+    1430                 :            :          * - shrinking other coordinates, but still keeping the same number of
+    1431                 :            :          *   limbs as P, as otherwise it will too likely be regrown too fast.
+    1432                 :            :          */
+    1433         [ -  + ]:      14770 :         MBEDTLS_MPI_CHK(mbedtls_mpi_shrink(&T[i]->X, grp->P.n));
+    1434         [ -  + ]:      14770 :         MBEDTLS_MPI_CHK(mbedtls_mpi_shrink(&T[i]->Y, grp->P.n));
+    1435                 :            : 
+    1436         [ -  + ]:      14770 :         MPI_ECP_LSET(&T[i]->Z, 1);
+    1437                 :            : 
+    1438         [ +  + ]:      14770 :         if (i == 0) {
+    1439                 :       2954 :             break;
+    1440                 :            :         }
+    1441                 :            :     }
+    1442                 :            : 
+    1443                 :       2954 : cleanup:
+    1444                 :            : 
+    1445                 :       2954 :     mbedtls_mpi_free(&t);
+    1446                 :       2954 :     mpi_free_many(c, T_size);
+    1447                 :       2954 :     mbedtls_free(c);
+    1448                 :            : 
+    1449                 :       2954 :     return ret;
+    1450                 :            : #endif /* !defined(MBEDTLS_ECP_NO_FALLBACK) || !defined(MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT) */
+    1451                 :            : }
+    1452                 :            : 
+    1453                 :            : /*
+    1454                 :            :  * Conditional point inversion: Q -> -Q = (Q.X, -Q.Y, Q.Z) without leak.
+    1455                 :            :  * "inv" must be 0 (don't invert) or 1 (invert) or the result will be invalid
+    1456                 :            :  */
+    1457                 :     189120 : static int ecp_safe_invert_jac(const mbedtls_ecp_group *grp,
+    1458                 :            :                                mbedtls_ecp_point *Q,
+    1459                 :            :                                unsigned char inv)
+    1460                 :            : {
+    1461                 :     189120 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1462                 :            :     mbedtls_mpi tmp;
+    1463                 :     189120 :     mbedtls_mpi_init(&tmp);
+    1464                 :            : 
+    1465   [ -  +  +  - ]:     189120 :     MPI_ECP_COND_NEG(&Q->Y, inv);
+    1466                 :            : 
+    1467                 :     189120 : cleanup:
+    1468                 :     189120 :     mbedtls_mpi_free(&tmp);
+    1469                 :     189120 :     return ret;
+    1470                 :            : }
+    1471                 :            : 
+    1472                 :            : /*
+    1473                 :            :  * Point doubling R = 2 P, Jacobian coordinates
+    1474                 :            :  *
+    1475                 :            :  * Based on http://www.hyperelliptic.org/EFD/g1p/auto-shortw-jacobian.html#doubling-dbl-1998-cmo-2 .
+    1476                 :            :  *
+    1477                 :            :  * We follow the variable naming fairly closely. The formula variations that trade a MUL for a SQR
+    1478                 :            :  * (plus a few ADDs) aren't useful as our bignum implementation doesn't distinguish squaring.
+    1479                 :            :  *
+    1480                 :            :  * Standard optimizations are applied when curve parameter A is one of { 0, -3 }.
+    1481                 :            :  *
+    1482                 :            :  * Cost: 1D := 3M + 4S          (A ==  0)
+    1483                 :            :  *             4M + 4S          (A == -3)
+    1484                 :            :  *             3M + 6S + 1a     otherwise
+    1485                 :            :  */
+    1486                 :     466356 : static int ecp_double_jac(const mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
+    1487                 :            :                           const mbedtls_ecp_point *P,
+    1488                 :            :                           mbedtls_mpi tmp[4])
+    1489                 :            : {
+    1490                 :            : #if defined(MBEDTLS_SELF_TEST)
+    1491                 :     466356 :     dbl_count++;
+    1492                 :            : #endif
+    1493                 :            : 
+    1494                 :            : #if defined(MBEDTLS_ECP_DOUBLE_JAC_ALT)
+    1495                 :            :     if (mbedtls_internal_ecp_grp_capable(grp)) {
+    1496                 :            :         return mbedtls_internal_ecp_double_jac(grp, R, P);
+    1497                 :            :     }
+    1498                 :            : #endif /* MBEDTLS_ECP_DOUBLE_JAC_ALT */
+    1499                 :            : 
+    1500                 :            : #if defined(MBEDTLS_ECP_NO_FALLBACK) && defined(MBEDTLS_ECP_DOUBLE_JAC_ALT)
+    1501                 :            :     return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
+    1502                 :            : #else
+    1503                 :     466356 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1504                 :            : 
+    1505                 :            :     /* Special case for A = -3 */
+    1506         [ +  - ]:     466356 :     if (mbedtls_ecp_group_a_is_minus_3(grp)) {
+    1507                 :            :         /* tmp[0] <- M = 3(X + Z^2)(X - Z^2) */
+    1508         [ -  + ]:     466356 :         MPI_ECP_SQR(&tmp[1],  &P->Z);
+    1509         [ -  + ]:     466356 :         MPI_ECP_ADD(&tmp[2],  &P->X,  &tmp[1]);
+    1510         [ -  + ]:     466356 :         MPI_ECP_SUB(&tmp[3],  &P->X,  &tmp[1]);
+    1511         [ -  + ]:     466356 :         MPI_ECP_MUL(&tmp[1],  &tmp[2],     &tmp[3]);
+    1512         [ -  + ]:     466356 :         MPI_ECP_MUL_INT(&tmp[0],  &tmp[1],     3);
+    1513                 :            :     } else {
+    1514                 :            :         /* tmp[0] <- M = 3.X^2 + A.Z^4 */
+    1515         [ #  # ]:          0 :         MPI_ECP_SQR(&tmp[1],  &P->X);
+    1516         [ #  # ]:          0 :         MPI_ECP_MUL_INT(&tmp[0],  &tmp[1],  3);
+    1517                 :            : 
+    1518                 :            :         /* Optimize away for "koblitz" curves with A = 0 */
+    1519         [ #  # ]:          0 :         if (MPI_ECP_CMP_INT(&grp->A, 0) != 0) {
+    1520                 :            :             /* M += A.Z^4 */
+    1521         [ #  # ]:          0 :             MPI_ECP_SQR(&tmp[1],  &P->Z);
+    1522         [ #  # ]:          0 :             MPI_ECP_SQR(&tmp[2],  &tmp[1]);
+    1523         [ #  # ]:          0 :             MPI_ECP_MUL(&tmp[1],  &tmp[2],     &grp->A);
+    1524         [ #  # ]:          0 :             MPI_ECP_ADD(&tmp[0],  &tmp[0],     &tmp[1]);
+    1525                 :            :         }
+    1526                 :            :     }
+    1527                 :            : 
+    1528                 :            :     /* tmp[1] <- S = 4.X.Y^2 */
+    1529         [ -  + ]:     466356 :     MPI_ECP_SQR(&tmp[2],  &P->Y);
+    1530         [ -  + ]:     466356 :     MPI_ECP_SHIFT_L(&tmp[2],  1);
+    1531         [ -  + ]:     466356 :     MPI_ECP_MUL(&tmp[1],  &P->X, &tmp[2]);
+    1532         [ -  + ]:     466356 :     MPI_ECP_SHIFT_L(&tmp[1],  1);
+    1533                 :            : 
+    1534                 :            :     /* tmp[3] <- U = 8.Y^4 */
+    1535         [ -  + ]:     466356 :     MPI_ECP_SQR(&tmp[3],  &tmp[2]);
+    1536         [ -  + ]:     466356 :     MPI_ECP_SHIFT_L(&tmp[3],  1);
+    1537                 :            : 
+    1538                 :            :     /* tmp[2] <- T = M^2 - 2.S */
+    1539         [ -  + ]:     466356 :     MPI_ECP_SQR(&tmp[2],  &tmp[0]);
+    1540         [ -  + ]:     466356 :     MPI_ECP_SUB(&tmp[2],  &tmp[2], &tmp[1]);
+    1541         [ -  + ]:     466356 :     MPI_ECP_SUB(&tmp[2],  &tmp[2], &tmp[1]);
+    1542                 :            : 
+    1543                 :            :     /* tmp[1] <- S = M(S - T) - U */
+    1544         [ -  + ]:     466356 :     MPI_ECP_SUB(&tmp[1],  &tmp[1],     &tmp[2]);
+    1545         [ -  + ]:     466356 :     MPI_ECP_MUL(&tmp[1],  &tmp[1],     &tmp[0]);
+    1546         [ -  + ]:     466356 :     MPI_ECP_SUB(&tmp[1],  &tmp[1],     &tmp[3]);
+    1547                 :            : 
+    1548                 :            :     /* tmp[3] <- U = 2.Y.Z */
+    1549         [ -  + ]:     466356 :     MPI_ECP_MUL(&tmp[3],  &P->Y,  &P->Z);
+    1550         [ -  + ]:     466356 :     MPI_ECP_SHIFT_L(&tmp[3],  1);
+    1551                 :            : 
+    1552                 :            :     /* Store results */
+    1553         [ -  + ]:     466356 :     MPI_ECP_MOV(&R->X, &tmp[2]);
+    1554         [ -  + ]:     466356 :     MPI_ECP_MOV(&R->Y, &tmp[1]);
+    1555         [ +  - ]:     466356 :     MPI_ECP_MOV(&R->Z, &tmp[3]);
+    1556                 :            : 
+    1557                 :     466356 : cleanup:
+    1558                 :            : 
+    1559                 :     466356 :     return ret;
+    1560                 :            : #endif /* !defined(MBEDTLS_ECP_NO_FALLBACK) || !defined(MBEDTLS_ECP_DOUBLE_JAC_ALT) */
+    1561                 :            : }
+    1562                 :            : 
+    1563                 :            : /*
+    1564                 :            :  * Addition: R = P + Q, mixed affine-Jacobian coordinates (GECC 3.22)
+    1565                 :            :  *
+    1566                 :            :  * The coordinates of Q must be normalized (= affine),
+    1567                 :            :  * but those of P don't need to. R is not normalized.
+    1568                 :            :  *
+    1569                 :            :  * P,Q,R may alias, but only at the level of EC points: they must be either
+    1570                 :            :  * equal as pointers, or disjoint (including the coordinate data buffers).
+    1571                 :            :  * Fine-grained aliasing at the level of coordinates is not supported.
+    1572                 :            :  *
+    1573                 :            :  * Special cases: (1) P or Q is zero, (2) R is zero, (3) P == Q.
+    1574                 :            :  * None of these cases can happen as intermediate step in ecp_mul_comb():
+    1575                 :            :  * - at each step, P, Q and R are multiples of the base point, the factor
+    1576                 :            :  *   being less than its order, so none of them is zero;
+    1577                 :            :  * - Q is an odd multiple of the base point, P an even multiple,
+    1578                 :            :  *   due to the choice of precomputed points in the modified comb method.
+    1579                 :            :  * So branches for these cases do not leak secret information.
+    1580                 :            :  *
+    1581                 :            :  * Cost: 1A := 8M + 3S
+    1582                 :            :  */
+    1583                 :     194514 : static int ecp_add_mixed(const mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
+    1584                 :            :                          const mbedtls_ecp_point *P, const mbedtls_ecp_point *Q,
+    1585                 :            :                          mbedtls_mpi tmp[4])
+    1586                 :            : {
+    1587                 :            : #if defined(MBEDTLS_SELF_TEST)
+    1588                 :     194514 :     add_count++;
+    1589                 :            : #endif
+    1590                 :            : 
+    1591                 :            : #if defined(MBEDTLS_ECP_ADD_MIXED_ALT)
+    1592                 :            :     if (mbedtls_internal_ecp_grp_capable(grp)) {
+    1593                 :            :         return mbedtls_internal_ecp_add_mixed(grp, R, P, Q);
+    1594                 :            :     }
+    1595                 :            : #endif /* MBEDTLS_ECP_ADD_MIXED_ALT */
+    1596                 :            : 
+    1597                 :            : #if defined(MBEDTLS_ECP_NO_FALLBACK) && defined(MBEDTLS_ECP_ADD_MIXED_ALT)
+    1598                 :            :     return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
+    1599                 :            : #else
+    1600                 :     194514 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1601                 :            : 
+    1602                 :            :     /* NOTE: Aliasing between input and output is allowed, so one has to make
+    1603                 :            :      *       sure that at the point X,Y,Z are written, {P,Q}->{X,Y,Z} are no
+    1604                 :            :      *       longer read from. */
+    1605                 :     194514 :     mbedtls_mpi * const X = &R->X;
+    1606                 :     194514 :     mbedtls_mpi * const Y = &R->Y;
+    1607                 :     194514 :     mbedtls_mpi * const Z = &R->Z;
+    1608                 :            : 
+    1609         [ -  + ]:     194514 :     if (!MPI_ECP_VALID(&Q->Z)) {
+    1610                 :          0 :         return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+    1611                 :            :     }
+    1612                 :            : 
+    1613                 :            :     /*
+    1614                 :            :      * Trivial cases: P == 0 or Q == 0 (case 1)
+    1615                 :            :      */
+    1616         [ -  + ]:     194514 :     if (MPI_ECP_CMP_INT(&P->Z, 0) == 0) {
+    1617                 :          0 :         return mbedtls_ecp_copy(R, Q);
+    1618                 :            :     }
+    1619                 :            : 
+    1620         [ -  + ]:     194514 :     if (MPI_ECP_CMP_INT(&Q->Z, 0) == 0) {
+    1621                 :          0 :         return mbedtls_ecp_copy(R, P);
+    1622                 :            :     }
+    1623                 :            : 
+    1624                 :            :     /*
+    1625                 :            :      * Make sure Q coordinates are normalized
+    1626                 :            :      */
+    1627         [ -  + ]:     194514 :     if (MPI_ECP_CMP_INT(&Q->Z, 1) != 0) {
+    1628                 :          0 :         return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+    1629                 :            :     }
+    1630                 :            : 
+    1631         [ -  + ]:     194514 :     MPI_ECP_SQR(&tmp[0], &P->Z);
+    1632         [ -  + ]:     194514 :     MPI_ECP_MUL(&tmp[1], &tmp[0], &P->Z);
+    1633         [ -  + ]:     194514 :     MPI_ECP_MUL(&tmp[0], &tmp[0], &Q->X);
+    1634         [ -  + ]:     194514 :     MPI_ECP_MUL(&tmp[1], &tmp[1], &Q->Y);
+    1635         [ -  + ]:     194514 :     MPI_ECP_SUB(&tmp[0], &tmp[0], &P->X);
+    1636         [ -  + ]:     194514 :     MPI_ECP_SUB(&tmp[1], &tmp[1], &P->Y);
+    1637                 :            : 
+    1638                 :            :     /* Special cases (2) and (3) */
+    1639         [ -  + ]:     194514 :     if (MPI_ECP_CMP_INT(&tmp[0], 0) == 0) {
+    1640         [ #  # ]:          0 :         if (MPI_ECP_CMP_INT(&tmp[1], 0) == 0) {
+    1641                 :          0 :             ret = ecp_double_jac(grp, R, P, tmp);
+    1642                 :          0 :             goto cleanup;
+    1643                 :            :         } else {
+    1644                 :          0 :             ret = mbedtls_ecp_set_zero(R);
+    1645                 :          0 :             goto cleanup;
+    1646                 :            :         }
+    1647                 :            :     }
+    1648                 :            : 
+    1649                 :            :     /* {P,Q}->Z no longer used, so OK to write to Z even if there's aliasing. */
+    1650         [ -  + ]:     194514 :     MPI_ECP_MUL(Z,        &P->Z,    &tmp[0]);
+    1651         [ -  + ]:     194514 :     MPI_ECP_SQR(&tmp[2],  &tmp[0]);
+    1652         [ -  + ]:     194514 :     MPI_ECP_MUL(&tmp[3],  &tmp[2],  &tmp[0]);
+    1653         [ -  + ]:     194514 :     MPI_ECP_MUL(&tmp[2],  &tmp[2],  &P->X);
+    1654                 :            : 
+    1655         [ -  + ]:     194514 :     MPI_ECP_MOV(&tmp[0], &tmp[2]);
+    1656         [ -  + ]:     194514 :     MPI_ECP_SHIFT_L(&tmp[0], 1);
+    1657                 :            : 
+    1658                 :            :     /* {P,Q}->X no longer used, so OK to write to X even if there's aliasing. */
+    1659         [ -  + ]:     194514 :     MPI_ECP_SQR(X,        &tmp[1]);
+    1660         [ -  + ]:     194514 :     MPI_ECP_SUB(X,        X,        &tmp[0]);
+    1661         [ -  + ]:     194514 :     MPI_ECP_SUB(X,        X,        &tmp[3]);
+    1662         [ -  + ]:     194514 :     MPI_ECP_SUB(&tmp[2],  &tmp[2],  X);
+    1663         [ -  + ]:     194514 :     MPI_ECP_MUL(&tmp[2],  &tmp[2],  &tmp[1]);
+    1664         [ -  + ]:     194514 :     MPI_ECP_MUL(&tmp[3],  &tmp[3],  &P->Y);
+    1665                 :            :     /* {P,Q}->Y no longer used, so OK to write to Y even if there's aliasing. */
+    1666         [ +  - ]:     194514 :     MPI_ECP_SUB(Y,     &tmp[2],     &tmp[3]);
+    1667                 :            : 
+    1668                 :     194514 : cleanup:
+    1669                 :            : 
+    1670                 :     194514 :     return ret;
+    1671                 :            : #endif /* !defined(MBEDTLS_ECP_NO_FALLBACK) || !defined(MBEDTLS_ECP_ADD_MIXED_ALT) */
+    1672                 :            : }
+    1673                 :            : 
+    1674                 :            : /*
+    1675                 :            :  * Randomize jacobian coordinates:
+    1676                 :            :  * (X, Y, Z) -> (l^2 X, l^3 Y, l Z) for random l
+    1677                 :            :  * This is sort of the reverse operation of ecp_normalize_jac().
+    1678                 :            :  *
+    1679                 :            :  * This countermeasure was first suggested in [2].
+    1680                 :            :  */
+    1681                 :        736 : static int ecp_randomize_jac(const mbedtls_ecp_group *grp, mbedtls_ecp_point *pt,
+    1682                 :            :                              int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
+    1683                 :            : {
+    1684                 :            : #if defined(MBEDTLS_ECP_RANDOMIZE_JAC_ALT)
+    1685                 :            :     if (mbedtls_internal_ecp_grp_capable(grp)) {
+    1686                 :            :         return mbedtls_internal_ecp_randomize_jac(grp, pt, f_rng, p_rng);
+    1687                 :            :     }
+    1688                 :            : #endif /* MBEDTLS_ECP_RANDOMIZE_JAC_ALT */
+    1689                 :            : 
+    1690                 :            : #if defined(MBEDTLS_ECP_NO_FALLBACK) && defined(MBEDTLS_ECP_RANDOMIZE_JAC_ALT)
+    1691                 :            :     return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
+    1692                 :            : #else
+    1693                 :        736 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1694                 :            :     mbedtls_mpi l;
+    1695                 :            : 
+    1696                 :        736 :     mbedtls_mpi_init(&l);
+    1697                 :            : 
+    1698                 :            :     /* Generate l such that 1 < l < p */
+    1699         [ -  + ]:        736 :     MPI_ECP_RAND(&l);
+    1700                 :            : 
+    1701                 :            :     /* Z' = l * Z */
+    1702         [ -  + ]:        736 :     MPI_ECP_MUL(&pt->Z,   &pt->Z,     &l);
+    1703                 :            : 
+    1704                 :            :     /* Y' = l * Y */
+    1705         [ -  + ]:        736 :     MPI_ECP_MUL(&pt->Y,   &pt->Y,     &l);
+    1706                 :            : 
+    1707                 :            :     /* X' = l^2 * X */
+    1708         [ -  + ]:        736 :     MPI_ECP_SQR(&l,       &l);
+    1709         [ -  + ]:        736 :     MPI_ECP_MUL(&pt->X,   &pt->X,     &l);
+    1710                 :            : 
+    1711                 :            :     /* Y'' = l^2 * Y' = l^3 * Y */
+    1712         [ +  - ]:        736 :     MPI_ECP_MUL(&pt->Y,   &pt->Y,     &l);
+    1713                 :            : 
+    1714                 :        736 : cleanup:
+    1715                 :        736 :     mbedtls_mpi_free(&l);
+    1716                 :            : 
+    1717         [ -  + ]:        736 :     if (ret == MBEDTLS_ERR_MPI_NOT_ACCEPTABLE) {
+    1718                 :          0 :         ret = MBEDTLS_ERR_ECP_RANDOM_FAILED;
+    1719                 :            :     }
+    1720                 :        736 :     return ret;
+    1721                 :            : #endif /* !defined(MBEDTLS_ECP_NO_FALLBACK) || !defined(MBEDTLS_ECP_RANDOMIZE_JAC_ALT) */
+    1722                 :            : }
+    1723                 :            : 
+    1724                 :            : /*
+    1725                 :            :  * Check and define parameters used by the comb method (see below for details)
+    1726                 :            :  */
+    1727                 :            : #if MBEDTLS_ECP_WINDOW_SIZE < 2 || MBEDTLS_ECP_WINDOW_SIZE > 7
+    1728                 :            : #error "MBEDTLS_ECP_WINDOW_SIZE out of bounds"
+    1729                 :            : #endif
+    1730                 :            : 
+    1731                 :            : /* d = ceil( n / w ) */
+    1732                 :            : #define COMB_MAX_D      (MBEDTLS_ECP_MAX_BITS + 1) / 2
+    1733                 :            : 
+    1734                 :            : /* number of precomputed points */
+    1735                 :            : #define COMB_MAX_PRE    (1 << (MBEDTLS_ECP_WINDOW_SIZE - 1))
+    1736                 :            : 
+    1737                 :            : /*
+    1738                 :            :  * Compute the representation of m that will be used with our comb method.
+    1739                 :            :  *
+    1740                 :            :  * The basic comb method is described in GECC 3.44 for example. We use a
+    1741                 :            :  * modified version that provides resistance to SPA by avoiding zero
+    1742                 :            :  * digits in the representation as in [3]. We modify the method further by
+    1743                 :            :  * requiring that all K_i be odd, which has the small cost that our
+    1744                 :            :  * representation uses one more K_i, due to carries, but saves on the size of
+    1745                 :            :  * the precomputed table.
+    1746                 :            :  *
+    1747                 :            :  * Summary of the comb method and its modifications:
+    1748                 :            :  *
+    1749                 :            :  * - The goal is to compute m*P for some w*d-bit integer m.
+    1750                 :            :  *
+    1751                 :            :  * - The basic comb method splits m into the w-bit integers
+    1752                 :            :  *   x[0] .. x[d-1] where x[i] consists of the bits in m whose
+    1753                 :            :  *   index has residue i modulo d, and computes m * P as
+    1754                 :            :  *   S[x[0]] + 2 * S[x[1]] + .. + 2^(d-1) S[x[d-1]], where
+    1755                 :            :  *   S[i_{w-1} .. i_0] := i_{w-1} 2^{(w-1)d} P + ... + i_1 2^d P + i_0 P.
+    1756                 :            :  *
+    1757                 :            :  * - If it happens that, say, x[i+1]=0 (=> S[x[i+1]]=0), one can replace the sum by
+    1758                 :            :  *    .. + 2^{i-1} S[x[i-1]] - 2^i S[x[i]] + 2^{i+1} S[x[i]] + 2^{i+2} S[x[i+2]] ..,
+    1759                 :            :  *   thereby successively converting it into a form where all summands
+    1760                 :            :  *   are nonzero, at the cost of negative summands. This is the basic idea of [3].
+    1761                 :            :  *
+    1762                 :            :  * - More generally, even if x[i+1] != 0, we can first transform the sum as
+    1763                 :            :  *   .. - 2^i S[x[i]] + 2^{i+1} ( S[x[i]] + S[x[i+1]] ) + 2^{i+2} S[x[i+2]] ..,
+    1764                 :            :  *   and then replace S[x[i]] + S[x[i+1]] = S[x[i] ^ x[i+1]] + 2 S[x[i] & x[i+1]].
+    1765                 :            :  *   Performing and iterating this procedure for those x[i] that are even
+    1766                 :            :  *   (keeping track of carry), we can transform the original sum into one of the form
+    1767                 :            :  *   S[x'[0]] +- 2 S[x'[1]] +- .. +- 2^{d-1} S[x'[d-1]] + 2^d S[x'[d]]
+    1768                 :            :  *   with all x'[i] odd. It is therefore only necessary to know S at odd indices,
+    1769                 :            :  *   which is why we are only computing half of it in the first place in
+    1770                 :            :  *   ecp_precompute_comb and accessing it with index abs(i) / 2 in ecp_select_comb.
+    1771                 :            :  *
+    1772                 :            :  * - For the sake of compactness, only the seven low-order bits of x[i]
+    1773                 :            :  *   are used to represent its absolute value (K_i in the paper), and the msb
+    1774                 :            :  *   of x[i] encodes the sign (s_i in the paper): it is set if and only if
+    1775                 :            :  *   if s_i == -1;
+    1776                 :            :  *
+    1777                 :            :  * Calling conventions:
+    1778                 :            :  * - x is an array of size d + 1
+    1779                 :            :  * - w is the size, ie number of teeth, of the comb, and must be between
+    1780                 :            :  *   2 and 7 (in practice, between 2 and MBEDTLS_ECP_WINDOW_SIZE)
+    1781                 :            :  * - m is the MPI, expected to be odd and such that bitlength(m) <= w * d
+    1782                 :            :  *   (the result will be incorrect if these assumptions are not satisfied)
+    1783                 :            :  */
+    1784                 :       3174 : static void ecp_comb_recode_core(unsigned char x[], size_t d,
+    1785                 :            :                                  unsigned char w, const mbedtls_mpi *m)
+    1786                 :            : {
+    1787                 :            :     size_t i, j;
+    1788                 :            :     unsigned char c, cc, adjust;
+    1789                 :            : 
+    1790                 :       3174 :     memset(x, 0, d+1);
+    1791                 :            : 
+    1792                 :            :     /* First get the classical comb values (except for x_d = 0) */
+    1793         [ +  + ]:     185946 :     for (i = 0; i < d; i++) {
+    1794         [ +  + ]:    1002104 :         for (j = 0; j < w; j++) {
+    1795                 :     819332 :             x[i] |= mbedtls_mpi_get_bit(m, i + d * j) << j;
+    1796                 :            :         }
+    1797                 :            :     }
+    1798                 :            : 
+    1799                 :            :     /* Now make sure x_1 .. x_d are odd */
+    1800                 :       3174 :     c = 0;
+    1801         [ +  + ]:     185946 :     for (i = 1; i <= d; i++) {
+    1802                 :            :         /* Add carry and update it */
+    1803                 :     182772 :         cc   = x[i] & c;
+    1804                 :     182772 :         x[i] = x[i] ^ c;
+    1805                 :     182772 :         c = cc;
+    1806                 :            : 
+    1807                 :            :         /* Adjust if needed, avoiding branches */
+    1808                 :     182772 :         adjust = 1 - (x[i] & 0x01);
+    1809                 :     182772 :         c   |= x[i] & (x[i-1] * adjust);
+    1810                 :     182772 :         x[i] = x[i] ^ (x[i-1] * adjust);
+    1811                 :     182772 :         x[i-1] |= adjust << 7;
+    1812                 :            :     }
+    1813                 :       3174 : }
+    1814                 :            : 
+    1815                 :            : /*
+    1816                 :            :  * Precompute points for the adapted comb method
+    1817                 :            :  *
+    1818                 :            :  * Assumption: T must be able to hold 2^{w - 1} elements.
+    1819                 :            :  *
+    1820                 :            :  * Operation: If i = i_{w-1} ... i_1 is the binary representation of i,
+    1821                 :            :  *            sets T[i] = i_{w-1} 2^{(w-1)d} P + ... + i_1 2^d P + P.
+    1822                 :            :  *
+    1823                 :            :  * Cost: d(w-1) D + (2^{w-1} - 1) A + 1 N(w-1) + 1 N(2^{w-1} - 1)
+    1824                 :            :  *
+    1825                 :            :  * Note: Even comb values (those where P would be omitted from the
+    1826                 :            :  *       sum defining T[i] above) are not needed in our adaption
+    1827                 :            :  *       the comb method. See ecp_comb_recode_core().
+    1828                 :            :  *
+    1829                 :            :  * This function currently works in four steps:
+    1830                 :            :  * (1) [dbl]      Computation of intermediate T[i] for 2-power values of i
+    1831                 :            :  * (2) [norm_dbl] Normalization of coordinates of these T[i]
+    1832                 :            :  * (3) [add]      Computation of all T[i]
+    1833                 :            :  * (4) [norm_add] Normalization of all T[i]
+    1834                 :            :  *
+    1835                 :            :  * Step 1 can be interrupted but not the others; together with the final
+    1836                 :            :  * coordinate normalization they are the largest steps done at once, depending
+    1837                 :            :  * on the window size. Here are operation counts for P-256:
+    1838                 :            :  *
+    1839                 :            :  * step     (2)     (3)     (4)
+    1840                 :            :  * w = 5    142     165     208
+    1841                 :            :  * w = 4    136      77     160
+    1842                 :            :  * w = 3    130      33     136
+    1843                 :            :  * w = 2    124      11     124
+    1844                 :            :  *
+    1845                 :            :  * So if ECC operations are blocking for too long even with a low max_ops
+    1846                 :            :  * value, it's useful to set MBEDTLS_ECP_WINDOW_SIZE to a lower value in order
+    1847                 :            :  * to minimize maximum blocking time.
+    1848                 :            :  */
+    1849                 :       1477 : static int ecp_precompute_comb(const mbedtls_ecp_group *grp,
+    1850                 :            :                                mbedtls_ecp_point T[], const mbedtls_ecp_point *P,
+    1851                 :            :                                unsigned char w, size_t d,
+    1852                 :            :                                mbedtls_ecp_restart_ctx *rs_ctx)
+    1853                 :            : {
+    1854                 :       1477 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1855                 :            :     unsigned char i;
+    1856                 :       1477 :     size_t j = 0;
+    1857                 :       1477 :     const unsigned char T_size = 1U << (w - 1);
+    1858                 :       1477 :     mbedtls_ecp_point *cur, *TT[COMB_MAX_PRE - 1] = { NULL };
+    1859                 :            : 
+    1860                 :            :     mbedtls_mpi tmp[4];
+    1861                 :            : 
+    1862                 :       1477 :     mpi_init_many(tmp, sizeof(tmp) / sizeof(mbedtls_mpi));
+    1863                 :            : 
+    1864                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+    1865   [ -  +  -  - ]:       1477 :     if (rs_ctx != NULL && rs_ctx->rsm != NULL) {
+    1866         [ #  # ]:          0 :         if (rs_ctx->rsm->state == ecp_rsm_pre_dbl) {
+    1867                 :          0 :             goto dbl;
+    1868                 :            :         }
+    1869         [ #  # ]:          0 :         if (rs_ctx->rsm->state == ecp_rsm_pre_norm_dbl) {
+    1870                 :          0 :             goto norm_dbl;
+    1871                 :            :         }
+    1872         [ #  # ]:          0 :         if (rs_ctx->rsm->state == ecp_rsm_pre_add) {
+    1873                 :          0 :             goto add;
+    1874                 :            :         }
+    1875         [ #  # ]:          0 :         if (rs_ctx->rsm->state == ecp_rsm_pre_norm_add) {
+    1876                 :          0 :             goto norm_add;
+    1877                 :            :         }
+    1878                 :            :     }
+    1879                 :            : #else
+    1880                 :            :     (void) rs_ctx;
+    1881                 :            : #endif
+    1882                 :            : 
+    1883                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+    1884   [ +  -  -  - ]:       1477 :     if (rs_ctx != NULL && rs_ctx->rsm != NULL) {
+    1885                 :          0 :         rs_ctx->rsm->state = ecp_rsm_pre_dbl;
+    1886                 :            : 
+    1887                 :            :         /* initial state for the loop */
+    1888                 :          0 :         rs_ctx->rsm->i = 0;
+    1889                 :            :     }
+    1890                 :            : 
+    1891                 :       1477 : dbl:
+    1892                 :            : #endif
+    1893                 :            :     /*
+    1894                 :            :      * Set T[0] = P and
+    1895                 :            :      * T[2^{l-1}] = 2^{dl} P for l = 1 .. w-1 (this is not the final value)
+    1896                 :            :      */
+    1897         [ -  + ]:       1477 :     MBEDTLS_MPI_CHK(mbedtls_ecp_copy(&T[0], P));
+    1898                 :            : 
+    1899                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+    1900   [ -  +  -  -  :       1477 :     if (rs_ctx != NULL && rs_ctx->rsm != NULL && rs_ctx->rsm->i != 0) {
+                   -  - ]
+    1901                 :          0 :         j = rs_ctx->rsm->i;
+    1902                 :            :     } else
+    1903                 :            : #endif
+    1904                 :       1477 :     j = 0;
+    1905                 :            : 
+    1906         [ +  + ]:     285061 :     for (; j < d * (w - 1); j++) {
+    1907         [ -  + ]:     283584 :         MBEDTLS_ECP_BUDGET(MBEDTLS_ECP_OPS_DBL);
+    1908                 :            : 
+    1909                 :     283584 :         i = 1U << (j / d);
+    1910                 :     283584 :         cur = T + i;
+    1911                 :            : 
+    1912         [ +  + ]:     283584 :         if (j % d == 0) {
+    1913         [ -  + ]:       4431 :             MBEDTLS_MPI_CHK(mbedtls_ecp_copy(cur, T + (i >> 1)));
+    1914                 :            :         }
+    1915                 :            : 
+    1916         [ -  + ]:     283584 :         MBEDTLS_MPI_CHK(ecp_double_jac(grp, cur, cur, tmp));
+    1917                 :            :     }
+    1918                 :            : 
+    1919                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+    1920   [ +  -  -  - ]:       1477 :     if (rs_ctx != NULL && rs_ctx->rsm != NULL) {
+    1921                 :          0 :         rs_ctx->rsm->state = ecp_rsm_pre_norm_dbl;
+    1922                 :            :     }
+    1923                 :            : 
+    1924                 :       1477 : norm_dbl:
+    1925                 :            : #endif
+    1926                 :            :     /*
+    1927                 :            :      * Normalize current elements in T to allow them to be used in
+    1928                 :            :      * ecp_add_mixed() below, which requires one normalized input.
+    1929                 :            :      *
+    1930                 :            :      * As T has holes, use an auxiliary array of pointers to elements in T.
+    1931                 :            :      *
+    1932                 :            :      */
+    1933                 :       1477 :     j = 0;
+    1934         [ +  + ]:       5908 :     for (i = 1; i < T_size; i <<= 1) {
+    1935                 :       4431 :         TT[j++] = T + i;
+    1936                 :            :     }
+    1937                 :            : 
+    1938         [ -  + ]:       1477 :     MBEDTLS_ECP_BUDGET(MBEDTLS_ECP_OPS_INV + 6 * j - 2);
+    1939                 :            : 
+    1940         [ -  + ]:       1477 :     MBEDTLS_MPI_CHK(ecp_normalize_jac_many(grp, TT, j));
+    1941                 :            : 
+    1942                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+    1943   [ +  -  -  - ]:       1477 :     if (rs_ctx != NULL && rs_ctx->rsm != NULL) {
+    1944                 :          0 :         rs_ctx->rsm->state = ecp_rsm_pre_add;
+    1945                 :            :     }
+    1946                 :            : 
+    1947                 :       1477 : add:
+    1948                 :            : #endif
+    1949                 :            :     /*
+    1950                 :            :      * Compute the remaining ones using the minimal number of additions
+    1951                 :            :      * Be careful to update T[2^l] only after using it!
+    1952                 :            :      */
+    1953         [ -  + ]:       1477 :     MBEDTLS_ECP_BUDGET((T_size - 1) * MBEDTLS_ECP_OPS_ADD);
+    1954                 :            : 
+    1955         [ +  + ]:       5908 :     for (i = 1; i < T_size; i <<= 1) {
+    1956                 :       4431 :         j = i;
+    1957         [ +  + ]:      14770 :         while (j--) {
+    1958         [ -  + ]:      10339 :             MBEDTLS_MPI_CHK(ecp_add_mixed(grp, &T[i + j], &T[j], &T[i], tmp));
+    1959                 :            :         }
+    1960                 :            :     }
+    1961                 :            : 
+    1962                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+    1963   [ +  -  -  - ]:       1477 :     if (rs_ctx != NULL && rs_ctx->rsm != NULL) {
+    1964                 :          0 :         rs_ctx->rsm->state = ecp_rsm_pre_norm_add;
+    1965                 :            :     }
+    1966                 :            : 
+    1967                 :       1477 : norm_add:
+    1968                 :            : #endif
+    1969                 :            :     /*
+    1970                 :            :      * Normalize final elements in T. Even though there are no holes now, we
+    1971                 :            :      * still need the auxiliary array for homogeneity with the previous
+    1972                 :            :      * call. Also, skip T[0] which is already normalised, being a copy of P.
+    1973                 :            :      */
+    1974         [ +  + ]:      11816 :     for (j = 0; j + 1 < T_size; j++) {
+    1975                 :      10339 :         TT[j] = T + j + 1;
+    1976                 :            :     }
+    1977                 :            : 
+    1978         [ -  + ]:       1477 :     MBEDTLS_ECP_BUDGET(MBEDTLS_ECP_OPS_INV + 6 * j - 2);
+    1979                 :            : 
+    1980         [ -  + ]:       1477 :     MBEDTLS_MPI_CHK(ecp_normalize_jac_many(grp, TT, j));
+    1981                 :            : 
+    1982                 :            :     /* Free Z coordinate (=1 after normalization) to save RAM.
+    1983                 :            :      * This makes T[i] invalid as mbedtls_ecp_points, but this is OK
+    1984                 :            :      * since from this point onwards, they are only accessed indirectly
+    1985                 :            :      * via the getter function ecp_select_comb() which does set the
+    1986                 :            :      * target's Z coordinate to 1. */
+    1987         [ +  + ]:      13293 :     for (i = 0; i < T_size; i++) {
+    1988                 :      11816 :         mbedtls_mpi_free(&T[i].Z);
+    1989                 :            :     }
+    1990                 :            : 
+    1991                 :       1477 : cleanup:
+    1992                 :            : 
+    1993                 :       1477 :     mpi_free_many(tmp, sizeof(tmp) / sizeof(mbedtls_mpi));
+    1994                 :            : 
+    1995                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+    1996   [ -  +  -  -  :       1477 :     if (rs_ctx != NULL && rs_ctx->rsm != NULL &&
+                   -  - ]
+    1997                 :            :         ret == MBEDTLS_ERR_ECP_IN_PROGRESS) {
+    1998         [ #  # ]:          0 :         if (rs_ctx->rsm->state == ecp_rsm_pre_dbl) {
+    1999                 :          0 :             rs_ctx->rsm->i = j;
+    2000                 :            :         }
+    2001                 :            :     }
+    2002                 :            : #endif
+    2003                 :            : 
+    2004                 :       1477 :     return ret;
+    2005                 :            : }
+    2006                 :            : 
+    2007                 :            : /*
+    2008                 :            :  * Select precomputed point: R = sign(i) * T[ abs(i) / 2 ]
+    2009                 :            :  *
+    2010                 :            :  * See ecp_comb_recode_core() for background
+    2011                 :            :  */
+    2012                 :     185946 : static int ecp_select_comb(const mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
+    2013                 :            :                            const mbedtls_ecp_point T[], unsigned char T_size,
+    2014                 :            :                            unsigned char i)
+    2015                 :            : {
+    2016                 :     185946 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    2017                 :            :     unsigned char ii, j;
+    2018                 :            : 
+    2019                 :            :     /* Ignore the "sign" bit and scale down */
+    2020                 :     185946 :     ii =  (i & 0x7Fu) >> 1;
+    2021                 :            : 
+    2022                 :            :     /* Read the whole table to thwart cache-based timing attacks */
+    2023         [ +  + ]:    2393042 :     for (j = 0; j < T_size; j++) {
+    2024         [ -  + ]:    2207096 :         MPI_ECP_COND_ASSIGN(&R->X, &T[j].X, j == ii);
+    2025         [ -  + ]:    2207096 :         MPI_ECP_COND_ASSIGN(&R->Y, &T[j].Y, j == ii);
+    2026                 :            :     }
+    2027                 :            : 
+    2028                 :            :     /* Safely invert result if i is "negative" */
+    2029         [ -  + ]:     185946 :     MBEDTLS_MPI_CHK(ecp_safe_invert_jac(grp, R, i >> 7));
+    2030                 :            : 
+    2031         [ +  - ]:     185946 :     MPI_ECP_LSET(&R->Z, 1);
+    2032                 :            : 
+    2033                 :     185946 : cleanup:
+    2034                 :     185946 :     return ret;
+    2035                 :            : }
+    2036                 :            : 
+    2037                 :            : /*
+    2038                 :            :  * Core multiplication algorithm for the (modified) comb method.
+    2039                 :            :  * This part is actually common with the basic comb method (GECC 3.44)
+    2040                 :            :  *
+    2041                 :            :  * Cost: d A + d D + 1 R
+    2042                 :            :  */
+    2043                 :       3174 : static int ecp_mul_comb_core(const mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
+    2044                 :            :                              const mbedtls_ecp_point T[], unsigned char T_size,
+    2045                 :            :                              const unsigned char x[], size_t d,
+    2046                 :            :                              int (*f_rng)(void *, unsigned char *, size_t),
+    2047                 :            :                              void *p_rng,
+    2048                 :            :                              mbedtls_ecp_restart_ctx *rs_ctx)
+    2049                 :            : {
+    2050                 :       3174 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    2051                 :            :     mbedtls_ecp_point Txi;
+    2052                 :            :     mbedtls_mpi tmp[4];
+    2053                 :            :     size_t i;
+    2054                 :            : 
+    2055                 :       3174 :     mbedtls_ecp_point_init(&Txi);
+    2056                 :       3174 :     mpi_init_many(tmp, sizeof(tmp) / sizeof(mbedtls_mpi));
+    2057                 :            : 
+    2058                 :            : #if !defined(MBEDTLS_ECP_RESTARTABLE)
+    2059                 :            :     (void) rs_ctx;
+    2060                 :            : #endif
+    2061                 :            : 
+    2062                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+    2063   [ -  +  -  - ]:       3174 :     if (rs_ctx != NULL && rs_ctx->rsm != NULL &&
+    2064         [ #  # ]:          0 :         rs_ctx->rsm->state != ecp_rsm_comb_core) {
+    2065                 :          0 :         rs_ctx->rsm->i = 0;
+    2066                 :          0 :         rs_ctx->rsm->state = ecp_rsm_comb_core;
+    2067                 :            :     }
+    2068                 :            : 
+    2069                 :            :     /* new 'if' instead of nested for the sake of the 'else' branch */
+    2070   [ -  +  -  -  :       3174 :     if (rs_ctx != NULL && rs_ctx->rsm != NULL && rs_ctx->rsm->i != 0) {
+                   -  - ]
+    2071                 :            :         /* restore current index (R already pointing to rs_ctx->rsm->R) */
+    2072                 :          0 :         i = rs_ctx->rsm->i;
+    2073                 :            :     } else
+    2074                 :            : #endif
+    2075                 :            :     {
+    2076                 :            :         /* Start with a non-zero point and randomize its coordinates */
+    2077                 :       3174 :         i = d;
+    2078         [ -  + ]:       3174 :         MBEDTLS_MPI_CHK(ecp_select_comb(grp, R, T, T_size, x[i]));
+    2079         [ +  + ]:       3174 :         if (f_rng != 0) {
+    2080         [ -  + ]:        368 :             MBEDTLS_MPI_CHK(ecp_randomize_jac(grp, R, f_rng, p_rng));
+    2081                 :            :         }
+    2082                 :            :     }
+    2083                 :            : 
+    2084         [ +  + ]:     185946 :     while (i != 0) {
+    2085         [ -  + ]:     182772 :         MBEDTLS_ECP_BUDGET(MBEDTLS_ECP_OPS_DBL + MBEDTLS_ECP_OPS_ADD);
+    2086                 :     182772 :         --i;
+    2087                 :            : 
+    2088         [ -  + ]:     182772 :         MBEDTLS_MPI_CHK(ecp_double_jac(grp, R, R, tmp));
+    2089         [ -  + ]:     182772 :         MBEDTLS_MPI_CHK(ecp_select_comb(grp, &Txi, T, T_size, x[i]));
+    2090         [ -  + ]:     182772 :         MBEDTLS_MPI_CHK(ecp_add_mixed(grp, R, R, &Txi, tmp));
+    2091                 :            :     }
+    2092                 :            : 
+    2093                 :       3174 : cleanup:
+    2094                 :            : 
+    2095                 :       3174 :     mbedtls_ecp_point_free(&Txi);
+    2096                 :       3174 :     mpi_free_many(tmp, sizeof(tmp) / sizeof(mbedtls_mpi));
+    2097                 :            : 
+    2098                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+    2099   [ -  +  -  -  :       3174 :     if (rs_ctx != NULL && rs_ctx->rsm != NULL &&
+                   -  - ]
+    2100                 :            :         ret == MBEDTLS_ERR_ECP_IN_PROGRESS) {
+    2101                 :          0 :         rs_ctx->rsm->i = i;
+    2102                 :            :         /* no need to save R, already pointing to rs_ctx->rsm->R */
+    2103                 :            :     }
+    2104                 :            : #endif
+    2105                 :            : 
+    2106                 :       3174 :     return ret;
+    2107                 :            : }
+    2108                 :            : 
+    2109                 :            : /*
+    2110                 :            :  * Recode the scalar to get constant-time comb multiplication
+    2111                 :            :  *
+    2112                 :            :  * As the actual scalar recoding needs an odd scalar as a starting point,
+    2113                 :            :  * this wrapper ensures that by replacing m by N - m if necessary, and
+    2114                 :            :  * informs the caller that the result of multiplication will be negated.
+    2115                 :            :  *
+    2116                 :            :  * This works because we only support large prime order for Short Weierstrass
+    2117                 :            :  * curves, so N is always odd hence either m or N - m is.
+    2118                 :            :  *
+    2119                 :            :  * See ecp_comb_recode_core() for background.
+    2120                 :            :  */
+    2121                 :       3174 : static int ecp_comb_recode_scalar(const mbedtls_ecp_group *grp,
+    2122                 :            :                                   const mbedtls_mpi *m,
+    2123                 :            :                                   unsigned char k[COMB_MAX_D + 1],
+    2124                 :            :                                   size_t d,
+    2125                 :            :                                   unsigned char w,
+    2126                 :            :                                   unsigned char *parity_trick)
+    2127                 :            : {
+    2128                 :       3174 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    2129                 :            :     mbedtls_mpi M, mm;
+    2130                 :            : 
+    2131                 :       3174 :     mbedtls_mpi_init(&M);
+    2132                 :       3174 :     mbedtls_mpi_init(&mm);
+    2133                 :            : 
+    2134                 :            :     /* N is always odd (see above), just make extra sure */
+    2135         [ -  + ]:       3174 :     if (mbedtls_mpi_get_bit(&grp->N, 0) != 1) {
+    2136                 :          0 :         return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+    2137                 :            :     }
+    2138                 :            : 
+    2139                 :            :     /* do we need the parity trick? */
+    2140                 :       3174 :     *parity_trick = (mbedtls_mpi_get_bit(m, 0) == 0);
+    2141                 :            : 
+    2142                 :            :     /* execute parity fix in constant time */
+    2143         [ -  + ]:       3174 :     MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&M, m));
+    2144         [ -  + ]:       3174 :     MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&mm, &grp->N, m));
+    2145         [ -  + ]:       3174 :     MBEDTLS_MPI_CHK(mbedtls_mpi_safe_cond_assign(&M, &mm, *parity_trick));
+    2146                 :            : 
+    2147                 :            :     /* actual scalar recoding */
+    2148                 :       3174 :     ecp_comb_recode_core(k, d, w, &M);
+    2149                 :            : 
+    2150                 :       3174 : cleanup:
+    2151                 :       3174 :     mbedtls_mpi_free(&mm);
+    2152                 :       3174 :     mbedtls_mpi_free(&M);
+    2153                 :            : 
+    2154                 :       3174 :     return ret;
+    2155                 :            : }
+    2156                 :            : 
+    2157                 :            : /*
+    2158                 :            :  * Perform comb multiplication (for short Weierstrass curves)
+    2159                 :            :  * once the auxiliary table has been pre-computed.
+    2160                 :            :  *
+    2161                 :            :  * Scalar recoding may use a parity trick that makes us compute -m * P,
+    2162                 :            :  * if that is the case we'll need to recover m * P at the end.
+    2163                 :            :  */
+    2164                 :       3174 : static int ecp_mul_comb_after_precomp(const mbedtls_ecp_group *grp,
+    2165                 :            :                                       mbedtls_ecp_point *R,
+    2166                 :            :                                       const mbedtls_mpi *m,
+    2167                 :            :                                       const mbedtls_ecp_point *T,
+    2168                 :            :                                       unsigned char T_size,
+    2169                 :            :                                       unsigned char w,
+    2170                 :            :                                       size_t d,
+    2171                 :            :                                       int (*f_rng)(void *, unsigned char *, size_t),
+    2172                 :            :                                       void *p_rng,
+    2173                 :            :                                       mbedtls_ecp_restart_ctx *rs_ctx)
+    2174                 :            : {
+    2175                 :       3174 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    2176                 :            :     unsigned char parity_trick;
+    2177                 :            :     unsigned char k[COMB_MAX_D + 1];
+    2178                 :       3174 :     mbedtls_ecp_point *RR = R;
+    2179                 :            : 
+    2180                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+    2181   [ -  +  -  - ]:       3174 :     if (rs_ctx != NULL && rs_ctx->rsm != NULL) {
+    2182                 :          0 :         RR = &rs_ctx->rsm->R;
+    2183                 :            : 
+    2184         [ #  # ]:          0 :         if (rs_ctx->rsm->state == ecp_rsm_final_norm) {
+    2185                 :          0 :             goto final_norm;
+    2186                 :            :         }
+    2187                 :            :     }
+    2188                 :            : #endif
+    2189                 :            : 
+    2190         [ -  + ]:       3174 :     MBEDTLS_MPI_CHK(ecp_comb_recode_scalar(grp, m, k, d, w,
+    2191                 :            :                                            &parity_trick));
+    2192         [ -  + ]:       3174 :     MBEDTLS_MPI_CHK(ecp_mul_comb_core(grp, RR, T, T_size, k, d,
+    2193                 :            :                                       f_rng, p_rng, rs_ctx));
+    2194         [ -  + ]:       3174 :     MBEDTLS_MPI_CHK(ecp_safe_invert_jac(grp, RR, parity_trick));
+    2195                 :            : 
+    2196                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+    2197   [ +  -  -  - ]:       3174 :     if (rs_ctx != NULL && rs_ctx->rsm != NULL) {
+    2198                 :          0 :         rs_ctx->rsm->state = ecp_rsm_final_norm;
+    2199                 :            :     }
+    2200                 :            : 
+    2201                 :       3174 : final_norm:
+    2202         [ -  + ]:       3174 :     MBEDTLS_ECP_BUDGET(MBEDTLS_ECP_OPS_INV);
+    2203                 :            : #endif
+    2204                 :            :     /*
+    2205                 :            :      * Knowledge of the jacobian coordinates may leak the last few bits of the
+    2206                 :            :      * scalar [1], and since our MPI implementation isn't constant-flow,
+    2207                 :            :      * inversion (used for coordinate normalization) may leak the full value
+    2208                 :            :      * of its input via side-channels [2].
+    2209                 :            :      *
+    2210                 :            :      * [1] https://eprint.iacr.org/2003/191
+    2211                 :            :      * [2] https://eprint.iacr.org/2020/055
+    2212                 :            :      *
+    2213                 :            :      * Avoid the leak by randomizing coordinates before we normalize them.
+    2214                 :            :      */
+    2215         [ +  + ]:       3174 :     if (f_rng != 0) {
+    2216         [ -  + ]:        368 :         MBEDTLS_MPI_CHK(ecp_randomize_jac(grp, RR, f_rng, p_rng));
+    2217                 :            :     }
+    2218                 :            : 
+    2219         [ -  + ]:       3174 :     MBEDTLS_MPI_CHK(ecp_normalize_jac(grp, RR));
+    2220                 :            : 
+    2221                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+    2222   [ +  -  -  - ]:       3174 :     if (rs_ctx != NULL && rs_ctx->rsm != NULL) {
+    2223         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_ecp_copy(R, RR));
+    2224                 :            :     }
+    2225                 :            : #endif
+    2226                 :            : 
+    2227                 :       3174 : cleanup:
+    2228                 :       3174 :     return ret;
+    2229                 :            : }
+    2230                 :            : 
+    2231                 :            : /*
+    2232                 :            :  * Pick window size based on curve size and whether we optimize for base point
+    2233                 :            :  */
+    2234                 :       3174 : static unsigned char ecp_pick_window_size(const mbedtls_ecp_group *grp,
+    2235                 :            :                                           unsigned char p_eq_g)
+    2236                 :            : {
+    2237                 :            :     unsigned char w;
+    2238                 :            : 
+    2239                 :            :     /*
+    2240                 :            :      * Minimize the number of multiplications, that is minimize
+    2241                 :            :      * 10 * d * w + 18 * 2^(w-1) + 11 * d + 7 * w, with d = ceil( nbits / w )
+    2242                 :            :      * (see costs of the various parts, with 1S = 1M)
+    2243                 :            :      */
+    2244         [ -  + ]:       3174 :     w = grp->nbits >= 384 ? 5 : 4;
+    2245                 :            : 
+    2246                 :            :     /*
+    2247                 :            :      * If P == G, pre-compute a bit more, since this may be re-used later.
+    2248                 :            :      * Just adding one avoids upping the cost of the first mul too much,
+    2249                 :            :      * and the memory cost too.
+    2250                 :            :      */
+    2251         [ +  + ]:       3174 :     if (p_eq_g) {
+    2252                 :       1697 :         w++;
+    2253                 :            :     }
+    2254                 :            : 
+    2255                 :            :     /*
+    2256                 :            :      * If static comb table may not be used (!p_eq_g) or static comb table does
+    2257                 :            :      * not exists, make sure w is within bounds.
+    2258                 :            :      * (The last test is useful only for very small curves in the test suite.)
+    2259                 :            :      *
+    2260                 :            :      * The user reduces MBEDTLS_ECP_WINDOW_SIZE does not changes the size of
+    2261                 :            :      * static comb table, because the size of static comb table is fixed when
+    2262                 :            :      * it is generated.
+    2263                 :            :      */
+    2264                 :            : #if (MBEDTLS_ECP_WINDOW_SIZE < 6)
+    2265   [ +  +  -  +  :       3174 :     if ((!p_eq_g || !ecp_group_is_static_comb_table(grp)) && w > MBEDTLS_ECP_WINDOW_SIZE) {
+                   -  + ]
+    2266                 :          0 :         w = MBEDTLS_ECP_WINDOW_SIZE;
+    2267                 :            :     }
+    2268                 :            : #endif
+    2269         [ -  + ]:       3174 :     if (w >= grp->nbits) {
+    2270                 :          0 :         w = 2;
+    2271                 :            :     }
+    2272                 :            : 
+    2273                 :       3174 :     return w;
+    2274                 :            : }
+    2275                 :            : 
+    2276                 :            : /*
+    2277                 :            :  * Multiplication using the comb method - for curves in short Weierstrass form
+    2278                 :            :  *
+    2279                 :            :  * This function is mainly responsible for administrative work:
+    2280                 :            :  * - managing the restart context if enabled
+    2281                 :            :  * - managing the table of precomputed points (passed between the below two
+    2282                 :            :  *   functions): allocation, computation, ownership transfer, freeing.
+    2283                 :            :  *
+    2284                 :            :  * It delegates the actual arithmetic work to:
+    2285                 :            :  *      ecp_precompute_comb() and ecp_mul_comb_with_precomp()
+    2286                 :            :  *
+    2287                 :            :  * See comments on ecp_comb_recode_core() regarding the computation strategy.
+    2288                 :            :  */
+    2289                 :       3174 : static int ecp_mul_comb(mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
+    2290                 :            :                         const mbedtls_mpi *m, const mbedtls_ecp_point *P,
+    2291                 :            :                         int (*f_rng)(void *, unsigned char *, size_t),
+    2292                 :            :                         void *p_rng,
+    2293                 :            :                         mbedtls_ecp_restart_ctx *rs_ctx)
+    2294                 :            : {
+    2295                 :       3174 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    2296                 :            :     unsigned char w, p_eq_g, i;
+    2297                 :            :     size_t d;
+    2298                 :       3174 :     unsigned char T_size = 0, T_ok = 0;
+    2299                 :       3174 :     mbedtls_ecp_point *T = NULL;
+    2300                 :            : 
+    2301   [ -  +  -  -  :       3174 :     ECP_RS_ENTER(rsm);
+          -  +  -  -  -  
+                -  -  - ]
+    2302                 :            : 
+    2303                 :            :     /* Is P the base point ? */
+    2304                 :            : #if MBEDTLS_ECP_FIXED_POINT_OPTIM == 1
+    2305   [ +  +  +  - ]:       4871 :     p_eq_g = (MPI_ECP_CMP(&P->Y, &grp->G.Y) == 0 &&
+    2306                 :       1697 :               MPI_ECP_CMP(&P->X, &grp->G.X) == 0);
+    2307                 :            : #else
+    2308                 :            :     p_eq_g = 0;
+    2309                 :            : #endif
+    2310                 :            : 
+    2311                 :            :     /* Pick window size and deduce related sizes */
+    2312                 :       3174 :     w = ecp_pick_window_size(grp, p_eq_g);
+    2313                 :       3174 :     T_size = 1U << (w - 1);
+    2314                 :       3174 :     d = (grp->nbits + w - 1) / w;
+    2315                 :            : 
+    2316                 :            :     /* Pre-computed table: do we have it already for the base point? */
+    2317   [ +  +  +  - ]:       3174 :     if (p_eq_g && grp->T != NULL) {
+    2318                 :            :         /* second pointer to the same table, will be deleted on exit */
+    2319                 :       1697 :         T = grp->T;
+    2320                 :       1697 :         T_ok = 1;
+    2321                 :            :     } else
+    2322                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+    2323                 :            :     /* Pre-computed table: do we have one in progress? complete? */
+    2324   [ -  +  -  -  :       1477 :     if (rs_ctx != NULL && rs_ctx->rsm != NULL && rs_ctx->rsm->T != NULL) {
+                   -  - ]
+    2325                 :            :         /* transfer ownership of T from rsm to local function */
+    2326                 :          0 :         T = rs_ctx->rsm->T;
+    2327                 :          0 :         rs_ctx->rsm->T = NULL;
+    2328                 :          0 :         rs_ctx->rsm->T_size = 0;
+    2329                 :            : 
+    2330                 :            :         /* This effectively jumps to the call to mul_comb_after_precomp() */
+    2331                 :          0 :         T_ok = rs_ctx->rsm->state >= ecp_rsm_comb_core;
+    2332                 :            :     } else
+    2333                 :            : #endif
+    2334                 :            :     /* Allocate table if we didn't have any */
+    2335                 :            :     {
+    2336                 :       1477 :         T = mbedtls_calloc(T_size, sizeof(mbedtls_ecp_point));
+    2337         [ -  + ]:       1477 :         if (T == NULL) {
+    2338                 :          0 :             ret = MBEDTLS_ERR_ECP_ALLOC_FAILED;
+    2339                 :          0 :             goto cleanup;
+    2340                 :            :         }
+    2341                 :            : 
+    2342         [ +  + ]:      13293 :         for (i = 0; i < T_size; i++) {
+    2343                 :      11816 :             mbedtls_ecp_point_init(&T[i]);
+    2344                 :            :         }
+    2345                 :            : 
+    2346                 :       1477 :         T_ok = 0;
+    2347                 :            :     }
+    2348                 :            : 
+    2349                 :            :     /* Compute table (or finish computing it) if not done already */
+    2350         [ +  + ]:       3174 :     if (!T_ok) {
+    2351         [ -  + ]:       1477 :         MBEDTLS_MPI_CHK(ecp_precompute_comb(grp, T, P, w, d, rs_ctx));
+    2352                 :            : 
+    2353         [ -  + ]:       1477 :         if (p_eq_g) {
+    2354                 :            :             /* almost transfer ownership of T to the group, but keep a copy of
+    2355                 :            :              * the pointer to use for calling the next function more easily */
+    2356                 :          0 :             grp->T = T;
+    2357                 :          0 :             grp->T_size = T_size;
+    2358                 :            :         }
+    2359                 :            :     }
+    2360                 :            : 
+    2361                 :            :     /* Actual comb multiplication using precomputed points */
+    2362         [ +  - ]:       3174 :     MBEDTLS_MPI_CHK(ecp_mul_comb_after_precomp(grp, R, m,
+    2363                 :            :                                                T, T_size, w, d,
+    2364                 :            :                                                f_rng, p_rng, rs_ctx));
+    2365                 :            : 
+    2366                 :       3174 : cleanup:
+    2367                 :            : 
+    2368                 :            :     /* does T belong to the group? */
+    2369         [ +  + ]:       3174 :     if (T == grp->T) {
+    2370                 :       1697 :         T = NULL;
+    2371                 :            :     }
+    2372                 :            : 
+    2373                 :            :     /* does T belong to the restart context? */
+    2374                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+    2375   [ -  +  -  -  :       3174 :     if (rs_ctx != NULL && rs_ctx->rsm != NULL && ret == MBEDTLS_ERR_ECP_IN_PROGRESS && T != NULL) {
+             -  -  -  - ]
+    2376                 :            :         /* transfer ownership of T from local function to rsm */
+    2377                 :          0 :         rs_ctx->rsm->T_size = T_size;
+    2378                 :          0 :         rs_ctx->rsm->T = T;
+    2379                 :          0 :         T = NULL;
+    2380                 :            :     }
+    2381                 :            : #endif
+    2382                 :            : 
+    2383                 :            :     /* did T belong to us? then let's destroy it! */
+    2384         [ +  + ]:       3174 :     if (T != NULL) {
+    2385         [ +  + ]:      13293 :         for (i = 0; i < T_size; i++) {
+    2386                 :      11816 :             mbedtls_ecp_point_free(&T[i]);
+    2387                 :            :         }
+    2388                 :       1477 :         mbedtls_free(T);
+    2389                 :            :     }
+    2390                 :            : 
+    2391                 :            :     /* prevent caller from using invalid value */
+    2392                 :       3174 :     int should_free_R = (ret != 0);
+    2393                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+    2394                 :            :     /* don't free R while in progress in case R == P */
+    2395         [ -  + ]:       3174 :     if (ret == MBEDTLS_ERR_ECP_IN_PROGRESS) {
+    2396                 :          0 :         should_free_R = 0;
+    2397                 :            :     }
+    2398                 :            : #endif
+    2399         [ -  + ]:       3174 :     if (should_free_R) {
+    2400                 :          0 :         mbedtls_ecp_point_free(R);
+    2401                 :            :     }
+    2402                 :            : 
+    2403   [ -  +  -  -  :       3174 :     ECP_RS_LEAVE(rsm);
+             -  -  -  + ]
+    2404                 :            : 
+    2405                 :       3174 :     return ret;
+    2406                 :            : }
+    2407                 :            : 
+    2408                 :            : #endif /* MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED */
+    2409                 :            : 
+    2410                 :            : #if defined(MBEDTLS_ECP_MONTGOMERY_ENABLED)
+    2411                 :            : /*
+    2412                 :            :  * For Montgomery curves, we do all the internal arithmetic in projective
+    2413                 :            :  * coordinates. Import/export of points uses only the x coordinates, which is
+    2414                 :            :  * internally represented as X / Z.
+    2415                 :            :  *
+    2416                 :            :  * For scalar multiplication, we'll use a Montgomery ladder.
+    2417                 :            :  */
+    2418                 :            : 
+    2419                 :            : /*
+    2420                 :            :  * Normalize Montgomery x/z coordinates: X = X/Z, Z = 1
+    2421                 :            :  * Cost: 1M + 1I
+    2422                 :            :  */
+    2423                 :          0 : static int ecp_normalize_mxz(const mbedtls_ecp_group *grp, mbedtls_ecp_point *P)
+    2424                 :            : {
+    2425                 :            : #if defined(MBEDTLS_ECP_NORMALIZE_MXZ_ALT)
+    2426                 :            :     if (mbedtls_internal_ecp_grp_capable(grp)) {
+    2427                 :            :         return mbedtls_internal_ecp_normalize_mxz(grp, P);
+    2428                 :            :     }
+    2429                 :            : #endif /* MBEDTLS_ECP_NORMALIZE_MXZ_ALT */
+    2430                 :            : 
+    2431                 :            : #if defined(MBEDTLS_ECP_NO_FALLBACK) && defined(MBEDTLS_ECP_NORMALIZE_MXZ_ALT)
+    2432                 :            :     return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
+    2433                 :            : #else
+    2434                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    2435         [ #  # ]:          0 :     MPI_ECP_INV(&P->Z, &P->Z);
+    2436         [ #  # ]:          0 :     MPI_ECP_MUL(&P->X, &P->X, &P->Z);
+    2437         [ #  # ]:          0 :     MPI_ECP_LSET(&P->Z, 1);
+    2438                 :            : 
+    2439                 :          0 : cleanup:
+    2440                 :          0 :     return ret;
+    2441                 :            : #endif /* !defined(MBEDTLS_ECP_NO_FALLBACK) || !defined(MBEDTLS_ECP_NORMALIZE_MXZ_ALT) */
+    2442                 :            : }
+    2443                 :            : 
+    2444                 :            : /*
+    2445                 :            :  * Randomize projective x/z coordinates:
+    2446                 :            :  * (X, Z) -> (l X, l Z) for random l
+    2447                 :            :  * This is sort of the reverse operation of ecp_normalize_mxz().
+    2448                 :            :  *
+    2449                 :            :  * This countermeasure was first suggested in [2].
+    2450                 :            :  * Cost: 2M
+    2451                 :            :  */
+    2452                 :          0 : static int ecp_randomize_mxz(const mbedtls_ecp_group *grp, mbedtls_ecp_point *P,
+    2453                 :            :                              int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
+    2454                 :            : {
+    2455                 :            : #if defined(MBEDTLS_ECP_RANDOMIZE_MXZ_ALT)
+    2456                 :            :     if (mbedtls_internal_ecp_grp_capable(grp)) {
+    2457                 :            :         return mbedtls_internal_ecp_randomize_mxz(grp, P, f_rng, p_rng);
+    2458                 :            :     }
+    2459                 :            : #endif /* MBEDTLS_ECP_RANDOMIZE_MXZ_ALT */
+    2460                 :            : 
+    2461                 :            : #if defined(MBEDTLS_ECP_NO_FALLBACK) && defined(MBEDTLS_ECP_RANDOMIZE_MXZ_ALT)
+    2462                 :            :     return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
+    2463                 :            : #else
+    2464                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    2465                 :            :     mbedtls_mpi l;
+    2466                 :          0 :     mbedtls_mpi_init(&l);
+    2467                 :            : 
+    2468                 :            :     /* Generate l such that 1 < l < p */
+    2469         [ #  # ]:          0 :     MPI_ECP_RAND(&l);
+    2470                 :            : 
+    2471         [ #  # ]:          0 :     MPI_ECP_MUL(&P->X, &P->X, &l);
+    2472         [ #  # ]:          0 :     MPI_ECP_MUL(&P->Z, &P->Z, &l);
+    2473                 :            : 
+    2474                 :          0 : cleanup:
+    2475                 :          0 :     mbedtls_mpi_free(&l);
+    2476                 :            : 
+    2477         [ #  # ]:          0 :     if (ret == MBEDTLS_ERR_MPI_NOT_ACCEPTABLE) {
+    2478                 :          0 :         ret = MBEDTLS_ERR_ECP_RANDOM_FAILED;
+    2479                 :            :     }
+    2480                 :          0 :     return ret;
+    2481                 :            : #endif /* !defined(MBEDTLS_ECP_NO_FALLBACK) || !defined(MBEDTLS_ECP_RANDOMIZE_MXZ_ALT) */
+    2482                 :            : }
+    2483                 :            : 
+    2484                 :            : /*
+    2485                 :            :  * Double-and-add: R = 2P, S = P + Q, with d = X(P - Q),
+    2486                 :            :  * for Montgomery curves in x/z coordinates.
+    2487                 :            :  *
+    2488                 :            :  * http://www.hyperelliptic.org/EFD/g1p/auto-code/montgom/xz/ladder/mladd-1987-m.op3
+    2489                 :            :  * with
+    2490                 :            :  * d =  X1
+    2491                 :            :  * P = (X2, Z2)
+    2492                 :            :  * Q = (X3, Z3)
+    2493                 :            :  * R = (X4, Z4)
+    2494                 :            :  * S = (X5, Z5)
+    2495                 :            :  * and eliminating temporary variables tO, ..., t4.
+    2496                 :            :  *
+    2497                 :            :  * Cost: 5M + 4S
+    2498                 :            :  */
+    2499                 :          0 : static int ecp_double_add_mxz(const mbedtls_ecp_group *grp,
+    2500                 :            :                               mbedtls_ecp_point *R, mbedtls_ecp_point *S,
+    2501                 :            :                               const mbedtls_ecp_point *P, const mbedtls_ecp_point *Q,
+    2502                 :            :                               const mbedtls_mpi *d,
+    2503                 :            :                               mbedtls_mpi T[4])
+    2504                 :            : {
+    2505                 :            : #if defined(MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT)
+    2506                 :            :     if (mbedtls_internal_ecp_grp_capable(grp)) {
+    2507                 :            :         return mbedtls_internal_ecp_double_add_mxz(grp, R, S, P, Q, d);
+    2508                 :            :     }
+    2509                 :            : #endif /* MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT */
+    2510                 :            : 
+    2511                 :            : #if defined(MBEDTLS_ECP_NO_FALLBACK) && defined(MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT)
+    2512                 :            :     return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
+    2513                 :            : #else
+    2514                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    2515                 :            : 
+    2516         [ #  # ]:          0 :     MPI_ECP_ADD(&T[0], &P->X,   &P->Z);   /* Pp := PX + PZ                    */
+    2517         [ #  # ]:          0 :     MPI_ECP_SUB(&T[1], &P->X,   &P->Z);   /* Pm := PX - PZ                    */
+    2518         [ #  # ]:          0 :     MPI_ECP_ADD(&T[2], &Q->X,   &Q->Z);   /* Qp := QX + XZ                    */
+    2519         [ #  # ]:          0 :     MPI_ECP_SUB(&T[3], &Q->X,   &Q->Z);   /* Qm := QX - QZ                    */
+    2520         [ #  # ]:          0 :     MPI_ECP_MUL(&T[3], &T[3],   &T[0]);   /* Qm * Pp                          */
+    2521         [ #  # ]:          0 :     MPI_ECP_MUL(&T[2], &T[2],   &T[1]);   /* Qp * Pm                          */
+    2522         [ #  # ]:          0 :     MPI_ECP_SQR(&T[0], &T[0]);            /* Pp^2                             */
+    2523         [ #  # ]:          0 :     MPI_ECP_SQR(&T[1], &T[1]);            /* Pm^2                             */
+    2524         [ #  # ]:          0 :     MPI_ECP_MUL(&R->X, &T[0],   &T[1]);   /* Pp^2 * Pm^2                      */
+    2525         [ #  # ]:          0 :     MPI_ECP_SUB(&T[0], &T[0],   &T[1]);   /* Pp^2 - Pm^2                      */
+    2526         [ #  # ]:          0 :     MPI_ECP_MUL(&R->Z, &grp->A, &T[0]);   /* A * (Pp^2 - Pm^2)                */
+    2527         [ #  # ]:          0 :     MPI_ECP_ADD(&R->Z, &T[1],   &R->Z);   /* [ A * (Pp^2-Pm^2) ] + Pm^2       */
+    2528         [ #  # ]:          0 :     MPI_ECP_ADD(&S->X, &T[3],   &T[2]);   /* Qm*Pp + Qp*Pm                    */
+    2529         [ #  # ]:          0 :     MPI_ECP_SQR(&S->X, &S->X);            /* (Qm*Pp + Qp*Pm)^2                */
+    2530         [ #  # ]:          0 :     MPI_ECP_SUB(&S->Z, &T[3],   &T[2]);   /* Qm*Pp - Qp*Pm                    */
+    2531         [ #  # ]:          0 :     MPI_ECP_SQR(&S->Z, &S->Z);            /* (Qm*Pp - Qp*Pm)^2                */
+    2532         [ #  # ]:          0 :     MPI_ECP_MUL(&S->Z, d,       &S->Z);   /* d * ( Qm*Pp - Qp*Pm )^2          */
+    2533         [ #  # ]:          0 :     MPI_ECP_MUL(&R->Z, &T[0],   &R->Z);   /* [A*(Pp^2-Pm^2)+Pm^2]*(Pp^2-Pm^2) */
+    2534                 :            : 
+    2535                 :          0 : cleanup:
+    2536                 :            : 
+    2537                 :          0 :     return ret;
+    2538                 :            : #endif /* !defined(MBEDTLS_ECP_NO_FALLBACK) || !defined(MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT) */
+    2539                 :            : }
+    2540                 :            : 
+    2541                 :            : /*
+    2542                 :            :  * Multiplication with Montgomery ladder in x/z coordinates,
+    2543                 :            :  * for curves in Montgomery form
+    2544                 :            :  */
+    2545                 :          0 : static int ecp_mul_mxz(mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
+    2546                 :            :                        const mbedtls_mpi *m, const mbedtls_ecp_point *P,
+    2547                 :            :                        int (*f_rng)(void *, unsigned char *, size_t),
+    2548                 :            :                        void *p_rng)
+    2549                 :            : {
+    2550                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    2551                 :            :     size_t i;
+    2552                 :            :     unsigned char b;
+    2553                 :            :     mbedtls_ecp_point RP;
+    2554                 :            :     mbedtls_mpi PX;
+    2555                 :            :     mbedtls_mpi tmp[4];
+    2556                 :          0 :     mbedtls_ecp_point_init(&RP); mbedtls_mpi_init(&PX);
+    2557                 :            : 
+    2558                 :          0 :     mpi_init_many(tmp, sizeof(tmp) / sizeof(mbedtls_mpi));
+    2559                 :            : 
+    2560         [ #  # ]:          0 :     if (f_rng == NULL) {
+    2561                 :          0 :         return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+    2562                 :            :     }
+    2563                 :            : 
+    2564                 :            :     /* Save PX and read from P before writing to R, in case P == R */
+    2565         [ #  # ]:          0 :     MPI_ECP_MOV(&PX, &P->X);
+    2566         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_ecp_copy(&RP, P));
+    2567                 :            : 
+    2568                 :            :     /* Set R to zero in modified x/z coordinates */
+    2569         [ #  # ]:          0 :     MPI_ECP_LSET(&R->X, 1);
+    2570         [ #  # ]:          0 :     MPI_ECP_LSET(&R->Z, 0);
+    2571                 :          0 :     mbedtls_mpi_free(&R->Y);
+    2572                 :            : 
+    2573                 :            :     /* RP.X might be slightly larger than P, so reduce it */
+    2574   [ #  #  #  # ]:          0 :     MOD_ADD(&RP.X);
+    2575                 :            : 
+    2576                 :            :     /* Randomize coordinates of the starting point */
+    2577         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(ecp_randomize_mxz(grp, &RP, f_rng, p_rng));
+    2578                 :            : 
+    2579                 :            :     /* Loop invariant: R = result so far, RP = R + P */
+    2580                 :          0 :     i = grp->nbits + 1; /* one past the (zero-based) required msb for private keys */
+    2581         [ #  # ]:          0 :     while (i-- > 0) {
+    2582                 :          0 :         b = mbedtls_mpi_get_bit(m, i);
+    2583                 :            :         /*
+    2584                 :            :          *  if (b) R = 2R + P else R = 2R,
+    2585                 :            :          * which is:
+    2586                 :            :          *  if (b) double_add( RP, R, RP, R )
+    2587                 :            :          *  else   double_add( R, RP, R, RP )
+    2588                 :            :          * but using safe conditional swaps to avoid leaks
+    2589                 :            :          */
+    2590         [ #  # ]:          0 :         MPI_ECP_COND_SWAP(&R->X, &RP.X, b);
+    2591         [ #  # ]:          0 :         MPI_ECP_COND_SWAP(&R->Z, &RP.Z, b);
+    2592         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(ecp_double_add_mxz(grp, R, &RP, R, &RP, &PX, tmp));
+    2593         [ #  # ]:          0 :         MPI_ECP_COND_SWAP(&R->X, &RP.X, b);
+    2594         [ #  # ]:          0 :         MPI_ECP_COND_SWAP(&R->Z, &RP.Z, b);
+    2595                 :            :     }
+    2596                 :            : 
+    2597                 :            :     /*
+    2598                 :            :      * Knowledge of the projective coordinates may leak the last few bits of the
+    2599                 :            :      * scalar [1], and since our MPI implementation isn't constant-flow,
+    2600                 :            :      * inversion (used for coordinate normalization) may leak the full value
+    2601                 :            :      * of its input via side-channels [2].
+    2602                 :            :      *
+    2603                 :            :      * [1] https://eprint.iacr.org/2003/191
+    2604                 :            :      * [2] https://eprint.iacr.org/2020/055
+    2605                 :            :      *
+    2606                 :            :      * Avoid the leak by randomizing coordinates before we normalize them.
+    2607                 :            :      */
+    2608         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(ecp_randomize_mxz(grp, R, f_rng, p_rng));
+    2609         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(ecp_normalize_mxz(grp, R));
+    2610                 :            : 
+    2611                 :          0 : cleanup:
+    2612                 :          0 :     mbedtls_ecp_point_free(&RP); mbedtls_mpi_free(&PX);
+    2613                 :            : 
+    2614                 :          0 :     mpi_free_many(tmp, sizeof(tmp) / sizeof(mbedtls_mpi));
+    2615                 :          0 :     return ret;
+    2616                 :            : }
+    2617                 :            : 
+    2618                 :            : #endif /* MBEDTLS_ECP_MONTGOMERY_ENABLED */
+    2619                 :            : 
+    2620                 :            : /*
+    2621                 :            :  * Restartable multiplication R = m * P
+    2622                 :            :  *
+    2623                 :            :  * This internal function can be called without an RNG in case where we know
+    2624                 :            :  * the inputs are not sensitive.
+    2625                 :            :  */
+    2626                 :       3174 : static int ecp_mul_restartable_internal(mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
+    2627                 :            :                                         const mbedtls_mpi *m, const mbedtls_ecp_point *P,
+    2628                 :            :                                         int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
+    2629                 :            :                                         mbedtls_ecp_restart_ctx *rs_ctx)
+    2630                 :            : {
+    2631                 :       3174 :     int ret = MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+    2632                 :            : #if defined(MBEDTLS_ECP_INTERNAL_ALT)
+    2633                 :            :     char is_grp_capable = 0;
+    2634                 :            : #endif
+    2635                 :            : 
+    2636                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+    2637                 :            :     /* reset ops count for this call if top-level */
+    2638   [ -  +  -  - ]:       3174 :     if (rs_ctx != NULL && rs_ctx->depth++ == 0) {
+    2639                 :          0 :         rs_ctx->ops_done = 0;
+    2640                 :            :     }
+    2641                 :            : #else
+    2642                 :            :     (void) rs_ctx;
+    2643                 :            : #endif
+    2644                 :            : 
+    2645                 :            : #if defined(MBEDTLS_ECP_INTERNAL_ALT)
+    2646                 :            :     if ((is_grp_capable = mbedtls_internal_ecp_grp_capable(grp))) {
+    2647                 :            :         MBEDTLS_MPI_CHK(mbedtls_internal_ecp_init(grp));
+    2648                 :            :     }
+    2649                 :            : #endif /* MBEDTLS_ECP_INTERNAL_ALT */
+    2650                 :            : 
+    2651                 :       3174 :     int restarting = 0;
+    2652                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+    2653   [ -  +  -  - ]:       3174 :     restarting = (rs_ctx != NULL && rs_ctx->rsm != NULL);
+    2654                 :            : #endif
+    2655                 :            :     /* skip argument check when restarting */
+    2656         [ +  - ]:       3174 :     if (!restarting) {
+    2657                 :            :         /* check_privkey is free */
+    2658         [ -  + ]:       3174 :         MBEDTLS_ECP_BUDGET(MBEDTLS_ECP_OPS_CHK);
+    2659                 :            : 
+    2660                 :            :         /* Common sanity checks */
+    2661         [ -  + ]:       3174 :         MBEDTLS_MPI_CHK(mbedtls_ecp_check_privkey(grp, m));
+    2662         [ -  + ]:       3174 :         MBEDTLS_MPI_CHK(mbedtls_ecp_check_pubkey(grp, P));
+    2663                 :            :     }
+    2664                 :            : 
+    2665                 :       3174 :     ret = MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+    2666                 :            : #if defined(MBEDTLS_ECP_MONTGOMERY_ENABLED)
+    2667         [ -  + ]:       3174 :     if (mbedtls_ecp_get_type(grp) == MBEDTLS_ECP_TYPE_MONTGOMERY) {
+    2668         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(ecp_mul_mxz(grp, R, m, P, f_rng, p_rng));
+    2669                 :            :     }
+    2670                 :            : #endif
+    2671                 :            : #if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
+    2672         [ -  + ]:       3174 :     if (mbedtls_ecp_get_type(grp) == MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS) {
+    2673         [ +  - ]:       3174 :         MBEDTLS_MPI_CHK(ecp_mul_comb(grp, R, m, P, f_rng, p_rng, rs_ctx));
+    2674                 :            :     }
+    2675                 :            : #endif
+    2676                 :            : 
+    2677                 :       3174 : cleanup:
+    2678                 :            : 
+    2679                 :            : #if defined(MBEDTLS_ECP_INTERNAL_ALT)
+    2680                 :            :     if (is_grp_capable) {
+    2681                 :            :         mbedtls_internal_ecp_free(grp);
+    2682                 :            :     }
+    2683                 :            : #endif /* MBEDTLS_ECP_INTERNAL_ALT */
+    2684                 :            : 
+    2685                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+    2686         [ -  + ]:       3174 :     if (rs_ctx != NULL) {
+    2687                 :          0 :         rs_ctx->depth--;
+    2688                 :            :     }
+    2689                 :            : #endif
+    2690                 :            : 
+    2691                 :       3174 :     return ret;
+    2692                 :            : }
+    2693                 :            : 
+    2694                 :            : /*
+    2695                 :            :  * Restartable multiplication R = m * P
+    2696                 :            :  */
+    2697                 :        368 : int mbedtls_ecp_mul_restartable(mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
+    2698                 :            :                                 const mbedtls_mpi *m, const mbedtls_ecp_point *P,
+    2699                 :            :                                 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
+    2700                 :            :                                 mbedtls_ecp_restart_ctx *rs_ctx)
+    2701                 :            : {
+    2702         [ -  + ]:        368 :     if (f_rng == NULL) {
+    2703                 :          0 :         return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+    2704                 :            :     }
+    2705                 :            : 
+    2706                 :        368 :     return ecp_mul_restartable_internal(grp, R, m, P, f_rng, p_rng, rs_ctx);
+    2707                 :            : }
+    2708                 :            : 
+    2709                 :            : /*
+    2710                 :            :  * Multiplication R = m * P
+    2711                 :            :  */
+    2712                 :          0 : int mbedtls_ecp_mul(mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
+    2713                 :            :                     const mbedtls_mpi *m, const mbedtls_ecp_point *P,
+    2714                 :            :                     int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
+    2715                 :            : {
+    2716                 :          0 :     return mbedtls_ecp_mul_restartable(grp, R, m, P, f_rng, p_rng, NULL);
+    2717                 :            : }
+    2718                 :            : #endif /* MBEDTLS_ECP_C */
+    2719                 :            : 
+    2720                 :            : #if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
+    2721                 :            : /*
+    2722                 :            :  * Check that an affine point is valid as a public key,
+    2723                 :            :  * short weierstrass curves (SEC1 3.2.3.1)
+    2724                 :            :  */
+    2725                 :      14335 : static int ecp_check_pubkey_sw(const mbedtls_ecp_group *grp, const mbedtls_ecp_point *pt)
+    2726                 :            : {
+    2727                 :      14335 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    2728                 :            :     mbedtls_mpi YY, RHS;
+    2729                 :            : 
+    2730                 :            :     /* pt coordinates must be normalized for our checks */
+    2731   [ +  -  +  - ]:      28670 :     if (mbedtls_mpi_cmp_int(&pt->X, 0) < 0 ||
+    2732         [ +  - ]:      28670 :         mbedtls_mpi_cmp_int(&pt->Y, 0) < 0 ||
+    2733         [ -  + ]:      28670 :         mbedtls_mpi_cmp_mpi(&pt->X, &grp->P) >= 0 ||
+    2734                 :      14335 :         mbedtls_mpi_cmp_mpi(&pt->Y, &grp->P) >= 0) {
+    2735                 :          0 :         return MBEDTLS_ERR_ECP_INVALID_KEY;
+    2736                 :            :     }
+    2737                 :            : 
+    2738                 :      14335 :     mbedtls_mpi_init(&YY); mbedtls_mpi_init(&RHS);
+    2739                 :            : 
+    2740                 :            :     /*
+    2741                 :            :      * YY = Y^2
+    2742                 :            :      * RHS = X^3 + A X + B
+    2743                 :            :      */
+    2744         [ -  + ]:      14335 :     MPI_ECP_SQR(&YY,  &pt->Y);
+    2745         [ -  + ]:      14335 :     MBEDTLS_MPI_CHK(ecp_sw_rhs(grp, &RHS, &pt->X));
+    2746                 :            : 
+    2747         [ +  - ]:      14335 :     if (MPI_ECP_CMP(&YY, &RHS) != 0) {
+    2748                 :          0 :         ret = MBEDTLS_ERR_ECP_INVALID_KEY;
+    2749                 :            :     }
+    2750                 :            : 
+    2751                 :      14335 : cleanup:
+    2752                 :            : 
+    2753                 :      14335 :     mbedtls_mpi_free(&YY); mbedtls_mpi_free(&RHS);
+    2754                 :            : 
+    2755                 :      14335 :     return ret;
+    2756                 :            : }
+    2757                 :            : #endif /* MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED */
+    2758                 :            : 
+    2759                 :            : #if defined(MBEDTLS_ECP_C)
+    2760                 :            : #if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
+    2761                 :            : /*
+    2762                 :            :  * R = m * P with shortcuts for m == 0, m == 1 and m == -1
+    2763                 :            :  * NOT constant-time - ONLY for short Weierstrass!
+    2764                 :            :  */
+    2765                 :       2806 : static int mbedtls_ecp_mul_shortcuts(mbedtls_ecp_group *grp,
+    2766                 :            :                                      mbedtls_ecp_point *R,
+    2767                 :            :                                      const mbedtls_mpi *m,
+    2768                 :            :                                      const mbedtls_ecp_point *P,
+    2769                 :            :                                      mbedtls_ecp_restart_ctx *rs_ctx)
+    2770                 :            : {
+    2771                 :       2806 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    2772                 :            :     mbedtls_mpi tmp;
+    2773                 :       2806 :     mbedtls_mpi_init(&tmp);
+    2774                 :            : 
+    2775         [ -  + ]:       2806 :     if (mbedtls_mpi_cmp_int(m, 0) == 0) {
+    2776         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_ecp_check_pubkey(grp, P));
+    2777         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_ecp_set_zero(R));
+    2778         [ -  + ]:       2806 :     } else if (mbedtls_mpi_cmp_int(m, 1) == 0) {
+    2779         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_ecp_check_pubkey(grp, P));
+    2780         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_ecp_copy(R, P));
+    2781         [ -  + ]:       2806 :     } else if (mbedtls_mpi_cmp_int(m, -1) == 0) {
+    2782         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_ecp_check_pubkey(grp, P));
+    2783         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_ecp_copy(R, P));
+    2784   [ #  #  #  # ]:          0 :         MPI_ECP_NEG(&R->Y);
+    2785                 :            :     } else {
+    2786         [ +  - ]:       2806 :         MBEDTLS_MPI_CHK(ecp_mul_restartable_internal(grp, R, m, P,
+    2787                 :            :                                                      NULL, NULL, rs_ctx));
+    2788                 :            :     }
+    2789                 :            : 
+    2790                 :       2806 : cleanup:
+    2791                 :       2806 :     mbedtls_mpi_free(&tmp);
+    2792                 :            : 
+    2793                 :       2806 :     return ret;
+    2794                 :            : }
+    2795                 :            : 
+    2796                 :            : /*
+    2797                 :            :  * Restartable linear combination
+    2798                 :            :  * NOT constant-time
+    2799                 :            :  */
+    2800                 :       1403 : int mbedtls_ecp_muladd_restartable(
+    2801                 :            :     mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
+    2802                 :            :     const mbedtls_mpi *m, const mbedtls_ecp_point *P,
+    2803                 :            :     const mbedtls_mpi *n, const mbedtls_ecp_point *Q,
+    2804                 :            :     mbedtls_ecp_restart_ctx *rs_ctx)
+    2805                 :            : {
+    2806                 :       1403 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    2807                 :            :     mbedtls_ecp_point mP;
+    2808                 :       1403 :     mbedtls_ecp_point *pmP = &mP;
+    2809                 :       1403 :     mbedtls_ecp_point *pR = R;
+    2810                 :            :     mbedtls_mpi tmp[4];
+    2811                 :            : #if defined(MBEDTLS_ECP_INTERNAL_ALT)
+    2812                 :            :     char is_grp_capable = 0;
+    2813                 :            : #endif
+    2814         [ -  + ]:       1403 :     if (mbedtls_ecp_get_type(grp) != MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS) {
+    2815                 :          0 :         return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
+    2816                 :            :     }
+    2817                 :            : 
+    2818                 :       1403 :     mbedtls_ecp_point_init(&mP);
+    2819                 :       1403 :     mpi_init_many(tmp, sizeof(tmp) / sizeof(mbedtls_mpi));
+    2820                 :            : 
+    2821   [ -  +  -  -  :       1403 :     ECP_RS_ENTER(ma);
+          -  +  -  -  -  
+                -  -  - ]
+    2822                 :            : 
+    2823                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+    2824   [ -  +  -  - ]:       1403 :     if (rs_ctx != NULL && rs_ctx->ma != NULL) {
+    2825                 :            :         /* redirect intermediate results to restart context */
+    2826                 :          0 :         pmP = &rs_ctx->ma->mP;
+    2827                 :          0 :         pR  = &rs_ctx->ma->R;
+    2828                 :            : 
+    2829                 :            :         /* jump to next operation */
+    2830         [ #  # ]:          0 :         if (rs_ctx->ma->state == ecp_rsma_mul2) {
+    2831                 :          0 :             goto mul2;
+    2832                 :            :         }
+    2833         [ #  # ]:          0 :         if (rs_ctx->ma->state == ecp_rsma_add) {
+    2834                 :          0 :             goto add;
+    2835                 :            :         }
+    2836         [ #  # ]:          0 :         if (rs_ctx->ma->state == ecp_rsma_norm) {
+    2837                 :          0 :             goto norm;
+    2838                 :            :         }
+    2839                 :            :     }
+    2840                 :            : #endif /* MBEDTLS_ECP_RESTARTABLE */
+    2841                 :            : 
+    2842         [ -  + ]:       1403 :     MBEDTLS_MPI_CHK(mbedtls_ecp_mul_shortcuts(grp, pmP, m, P, rs_ctx));
+    2843                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+    2844   [ +  -  -  - ]:       1403 :     if (rs_ctx != NULL && rs_ctx->ma != NULL) {
+    2845                 :          0 :         rs_ctx->ma->state = ecp_rsma_mul2;
+    2846                 :            :     }
+    2847                 :            : 
+    2848                 :       1403 : mul2:
+    2849                 :            : #endif
+    2850         [ -  + ]:       1403 :     MBEDTLS_MPI_CHK(mbedtls_ecp_mul_shortcuts(grp, pR,  n, Q, rs_ctx));
+    2851                 :            : 
+    2852                 :            : #if defined(MBEDTLS_ECP_INTERNAL_ALT)
+    2853                 :            :     if ((is_grp_capable = mbedtls_internal_ecp_grp_capable(grp))) {
+    2854                 :            :         MBEDTLS_MPI_CHK(mbedtls_internal_ecp_init(grp));
+    2855                 :            :     }
+    2856                 :            : #endif /* MBEDTLS_ECP_INTERNAL_ALT */
+    2857                 :            : 
+    2858                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+    2859   [ +  -  -  - ]:       1403 :     if (rs_ctx != NULL && rs_ctx->ma != NULL) {
+    2860                 :          0 :         rs_ctx->ma->state = ecp_rsma_add;
+    2861                 :            :     }
+    2862                 :            : 
+    2863                 :       1403 : add:
+    2864                 :            : #endif
+    2865         [ -  + ]:       1403 :     MBEDTLS_ECP_BUDGET(MBEDTLS_ECP_OPS_ADD);
+    2866         [ -  + ]:       1403 :     MBEDTLS_MPI_CHK(ecp_add_mixed(grp, pR, pmP, pR, tmp));
+    2867                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+    2868   [ +  -  -  - ]:       1403 :     if (rs_ctx != NULL && rs_ctx->ma != NULL) {
+    2869                 :          0 :         rs_ctx->ma->state = ecp_rsma_norm;
+    2870                 :            :     }
+    2871                 :            : 
+    2872                 :       1403 : norm:
+    2873                 :            : #endif
+    2874         [ -  + ]:       1403 :     MBEDTLS_ECP_BUDGET(MBEDTLS_ECP_OPS_INV);
+    2875         [ -  + ]:       1403 :     MBEDTLS_MPI_CHK(ecp_normalize_jac(grp, pR));
+    2876                 :            : 
+    2877                 :            : #if defined(MBEDTLS_ECP_RESTARTABLE)
+    2878   [ +  -  -  - ]:       1403 :     if (rs_ctx != NULL && rs_ctx->ma != NULL) {
+    2879         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_ecp_copy(R, pR));
+    2880                 :            :     }
+    2881                 :            : #endif
+    2882                 :            : 
+    2883                 :       1403 : cleanup:
+    2884                 :            : 
+    2885                 :       1403 :     mpi_free_many(tmp, sizeof(tmp) / sizeof(mbedtls_mpi));
+    2886                 :            : 
+    2887                 :            : #if defined(MBEDTLS_ECP_INTERNAL_ALT)
+    2888                 :            :     if (is_grp_capable) {
+    2889                 :            :         mbedtls_internal_ecp_free(grp);
+    2890                 :            :     }
+    2891                 :            : #endif /* MBEDTLS_ECP_INTERNAL_ALT */
+    2892                 :            : 
+    2893                 :       1403 :     mbedtls_ecp_point_free(&mP);
+    2894                 :            : 
+    2895   [ -  +  -  -  :       1403 :     ECP_RS_LEAVE(ma);
+             -  -  -  + ]
+    2896                 :            : 
+    2897                 :       1403 :     return ret;
+    2898                 :            : }
+    2899                 :            : 
+    2900                 :            : /*
+    2901                 :            :  * Linear combination
+    2902                 :            :  * NOT constant-time
+    2903                 :            :  */
+    2904                 :          0 : int mbedtls_ecp_muladd(mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
+    2905                 :            :                        const mbedtls_mpi *m, const mbedtls_ecp_point *P,
+    2906                 :            :                        const mbedtls_mpi *n, const mbedtls_ecp_point *Q)
+    2907                 :            : {
+    2908                 :          0 :     return mbedtls_ecp_muladd_restartable(grp, R, m, P, n, Q, NULL);
+    2909                 :            : }
+    2910                 :            : #endif /* MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED */
+    2911                 :            : #endif /* MBEDTLS_ECP_C */
+    2912                 :            : 
+    2913                 :            : #if defined(MBEDTLS_ECP_MONTGOMERY_ENABLED)
+    2914                 :            : #if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED)
+    2915                 :            : #define ECP_MPI_INIT(_p, _n) { .p = (mbedtls_mpi_uint *) (_p), .s = 1, .n = (_n) }
+    2916                 :            : #define ECP_MPI_INIT_ARRAY(x)   \
+    2917                 :            :     ECP_MPI_INIT(x, sizeof(x) / sizeof(mbedtls_mpi_uint))
+    2918                 :            : /*
+    2919                 :            :  * Constants for the two points other than 0, 1, -1 (mod p) in
+    2920                 :            :  * https://cr.yp.to/ecdh.html#validate
+    2921                 :            :  * See ecp_check_pubkey_x25519().
+    2922                 :            :  */
+    2923                 :            : static const mbedtls_mpi_uint x25519_bad_point_1[] = {
+    2924                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xe0, 0xeb, 0x7a, 0x7c, 0x3b, 0x41, 0xb8, 0xae),
+    2925                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x16, 0x56, 0xe3, 0xfa, 0xf1, 0x9f, 0xc4, 0x6a),
+    2926                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xda, 0x09, 0x8d, 0xeb, 0x9c, 0x32, 0xb1, 0xfd),
+    2927                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x86, 0x62, 0x05, 0x16, 0x5f, 0x49, 0xb8, 0x00),
+    2928                 :            : };
+    2929                 :            : static const mbedtls_mpi_uint x25519_bad_point_2[] = {
+    2930                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5f, 0x9c, 0x95, 0xbc, 0xa3, 0x50, 0x8c, 0x24),
+    2931                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xb1, 0xd0, 0xb1, 0x55, 0x9c, 0x83, 0xef, 0x5b),
+    2932                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x04, 0x44, 0x5c, 0xc4, 0x58, 0x1c, 0x8e, 0x86),
+    2933                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xd8, 0x22, 0x4e, 0xdd, 0xd0, 0x9f, 0x11, 0x57),
+    2934                 :            : };
+    2935                 :            : static const mbedtls_mpi ecp_x25519_bad_point_1 = ECP_MPI_INIT_ARRAY(
+    2936                 :            :     x25519_bad_point_1);
+    2937                 :            : static const mbedtls_mpi ecp_x25519_bad_point_2 = ECP_MPI_INIT_ARRAY(
+    2938                 :            :     x25519_bad_point_2);
+    2939                 :            : #endif /* MBEDTLS_ECP_DP_CURVE25519_ENABLED */
+    2940                 :            : 
+    2941                 :            : /*
+    2942                 :            :  * Check that the input point is not one of the low-order points.
+    2943                 :            :  * This is recommended by the "May the Fourth" paper:
+    2944                 :            :  * https://eprint.iacr.org/2017/806.pdf
+    2945                 :            :  * Those points are never sent by an honest peer.
+    2946                 :            :  */
+    2947                 :          0 : static int ecp_check_bad_points_mx(const mbedtls_mpi *X, const mbedtls_mpi *P,
+    2948                 :            :                                    const mbedtls_ecp_group_id grp_id)
+    2949                 :            : {
+    2950                 :            :     int ret;
+    2951                 :            :     mbedtls_mpi XmP;
+    2952                 :            : 
+    2953                 :          0 :     mbedtls_mpi_init(&XmP);
+    2954                 :            : 
+    2955                 :            :     /* Reduce X mod P so that we only need to check values less than P.
+    2956                 :            :      * We know X < 2^256 so we can proceed by subtraction. */
+    2957         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&XmP, X));
+    2958         [ #  # ]:          0 :     while (mbedtls_mpi_cmp_mpi(&XmP, P) >= 0) {
+    2959         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&XmP, &XmP, P));
+    2960                 :            :     }
+    2961                 :            : 
+    2962                 :            :     /* Check against the known bad values that are less than P. For Curve448
+    2963                 :            :      * these are 0, 1 and -1. For Curve25519 we check the values less than P
+    2964                 :            :      * from the following list: https://cr.yp.to/ecdh.html#validate */
+    2965         [ #  # ]:          0 :     if (mbedtls_mpi_cmp_int(&XmP, 1) <= 0) {  /* takes care of 0 and 1 */
+    2966                 :          0 :         ret = MBEDTLS_ERR_ECP_INVALID_KEY;
+    2967                 :          0 :         goto cleanup;
+    2968                 :            :     }
+    2969                 :            : 
+    2970                 :            : #if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED)
+    2971         [ #  # ]:          0 :     if (grp_id == MBEDTLS_ECP_DP_CURVE25519) {
+    2972         [ #  # ]:          0 :         if (mbedtls_mpi_cmp_mpi(&XmP, &ecp_x25519_bad_point_1) == 0) {
+    2973                 :          0 :             ret = MBEDTLS_ERR_ECP_INVALID_KEY;
+    2974                 :          0 :             goto cleanup;
+    2975                 :            :         }
+    2976                 :            : 
+    2977         [ #  # ]:          0 :         if (mbedtls_mpi_cmp_mpi(&XmP, &ecp_x25519_bad_point_2) == 0) {
+    2978                 :          0 :             ret = MBEDTLS_ERR_ECP_INVALID_KEY;
+    2979                 :          0 :             goto cleanup;
+    2980                 :            :         }
+    2981                 :            :     }
+    2982                 :            : #else
+    2983                 :            :     (void) grp_id;
+    2984                 :            : #endif
+    2985                 :            : 
+    2986                 :            :     /* Final check: check if XmP + 1 is P (final because it changes XmP!) */
+    2987         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_add_int(&XmP, &XmP, 1));
+    2988         [ #  # ]:          0 :     if (mbedtls_mpi_cmp_mpi(&XmP, P) == 0) {
+    2989                 :          0 :         ret = MBEDTLS_ERR_ECP_INVALID_KEY;
+    2990                 :          0 :         goto cleanup;
+    2991                 :            :     }
+    2992                 :            : 
+    2993                 :          0 :     ret = 0;
+    2994                 :            : 
+    2995                 :          0 : cleanup:
+    2996                 :          0 :     mbedtls_mpi_free(&XmP);
+    2997                 :            : 
+    2998                 :          0 :     return ret;
+    2999                 :            : }
+    3000                 :            : 
+    3001                 :            : /*
+    3002                 :            :  * Check validity of a public key for Montgomery curves with x-only schemes
+    3003                 :            :  */
+    3004                 :          0 : static int ecp_check_pubkey_mx(const mbedtls_ecp_group *grp, const mbedtls_ecp_point *pt)
+    3005                 :            : {
+    3006                 :            :     /* [Curve25519 p. 5] Just check X is the correct number of bytes */
+    3007                 :            :     /* Allow any public value, if it's too big then we'll just reduce it mod p
+    3008                 :            :      * (RFC 7748 sec. 5 para. 3). */
+    3009         [ #  # ]:          0 :     if (mbedtls_mpi_size(&pt->X) > (grp->nbits + 7) / 8) {
+    3010                 :          0 :         return MBEDTLS_ERR_ECP_INVALID_KEY;
+    3011                 :            :     }
+    3012                 :            : 
+    3013                 :            :     /* Implicit in all standards (as they don't consider negative numbers):
+    3014                 :            :      * X must be non-negative. This is normally ensured by the way it's
+    3015                 :            :      * encoded for transmission, but let's be extra sure. */
+    3016         [ #  # ]:          0 :     if (mbedtls_mpi_cmp_int(&pt->X, 0) < 0) {
+    3017                 :          0 :         return MBEDTLS_ERR_ECP_INVALID_KEY;
+    3018                 :            :     }
+    3019                 :            : 
+    3020                 :          0 :     return ecp_check_bad_points_mx(&pt->X, &grp->P, grp->id);
+    3021                 :            : }
+    3022                 :            : #endif /* MBEDTLS_ECP_MONTGOMERY_ENABLED */
+    3023                 :            : 
+    3024                 :            : /*
+    3025                 :            :  * Check that a point is valid as a public key
+    3026                 :            :  */
+    3027                 :      14335 : int mbedtls_ecp_check_pubkey(const mbedtls_ecp_group *grp,
+    3028                 :            :                              const mbedtls_ecp_point *pt)
+    3029                 :            : {
+    3030                 :            :     /* Must use affine coordinates */
+    3031         [ -  + ]:      14335 :     if (mbedtls_mpi_cmp_int(&pt->Z, 1) != 0) {
+    3032                 :          0 :         return MBEDTLS_ERR_ECP_INVALID_KEY;
+    3033                 :            :     }
+    3034                 :            : 
+    3035                 :            : #if defined(MBEDTLS_ECP_MONTGOMERY_ENABLED)
+    3036         [ -  + ]:      14335 :     if (mbedtls_ecp_get_type(grp) == MBEDTLS_ECP_TYPE_MONTGOMERY) {
+    3037                 :          0 :         return ecp_check_pubkey_mx(grp, pt);
+    3038                 :            :     }
+    3039                 :            : #endif
+    3040                 :            : #if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
+    3041         [ +  - ]:      14335 :     if (mbedtls_ecp_get_type(grp) == MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS) {
+    3042                 :      14335 :         return ecp_check_pubkey_sw(grp, pt);
+    3043                 :            :     }
+    3044                 :            : #endif
+    3045                 :          0 :     return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+    3046                 :            : }
+    3047                 :            : 
+    3048                 :            : /*
+    3049                 :            :  * Check that an mbedtls_mpi is valid as a private key
+    3050                 :            :  */
+    3051                 :       3302 : int mbedtls_ecp_check_privkey(const mbedtls_ecp_group *grp,
+    3052                 :            :                               const mbedtls_mpi *d)
+    3053                 :            : {
+    3054                 :            : #if defined(MBEDTLS_ECP_MONTGOMERY_ENABLED)
+    3055         [ -  + ]:       3302 :     if (mbedtls_ecp_get_type(grp) == MBEDTLS_ECP_TYPE_MONTGOMERY) {
+    3056                 :            :         /* see RFC 7748 sec. 5 para. 5 */
+    3057   [ #  #  #  # ]:          0 :         if (mbedtls_mpi_get_bit(d, 0) != 0 ||
+    3058                 :          0 :             mbedtls_mpi_get_bit(d, 1) != 0 ||
+    3059         [ #  # ]:          0 :             mbedtls_mpi_bitlen(d) - 1 != grp->nbits) {  /* mbedtls_mpi_bitlen is one-based! */
+    3060                 :          0 :             return MBEDTLS_ERR_ECP_INVALID_KEY;
+    3061                 :            :         }
+    3062                 :            : 
+    3063                 :            :         /* see [Curve25519] page 5 */
+    3064   [ #  #  #  # ]:          0 :         if (grp->nbits == 254 && mbedtls_mpi_get_bit(d, 2) != 0) {
+    3065                 :          0 :             return MBEDTLS_ERR_ECP_INVALID_KEY;
+    3066                 :            :         }
+    3067                 :            : 
+    3068                 :          0 :         return 0;
+    3069                 :            :     }
+    3070                 :            : #endif /* MBEDTLS_ECP_MONTGOMERY_ENABLED */
+    3071                 :            : #if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
+    3072         [ +  - ]:       3302 :     if (mbedtls_ecp_get_type(grp) == MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS) {
+    3073                 :            :         /* see SEC1 3.2 */
+    3074   [ +  -  -  + ]:       6604 :         if (mbedtls_mpi_cmp_int(d, 1) < 0 ||
+    3075                 :       3302 :             mbedtls_mpi_cmp_mpi(d, &grp->N) >= 0) {
+    3076                 :          0 :             return MBEDTLS_ERR_ECP_INVALID_KEY;
+    3077                 :            :         } else {
+    3078                 :       3302 :             return 0;
+    3079                 :            :         }
+    3080                 :            :     }
+    3081                 :            : #endif /* MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED */
+    3082                 :            : 
+    3083                 :          0 :     return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+    3084                 :            : }
+    3085                 :            : 
+    3086                 :            : #if defined(MBEDTLS_ECP_MONTGOMERY_ENABLED)
+    3087                 :            : MBEDTLS_STATIC_TESTABLE
+    3088                 :          0 : int mbedtls_ecp_gen_privkey_mx(size_t high_bit,
+    3089                 :            :                                mbedtls_mpi *d,
+    3090                 :            :                                int (*f_rng)(void *, unsigned char *, size_t),
+    3091                 :            :                                void *p_rng)
+    3092                 :            : {
+    3093                 :          0 :     int ret = MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+    3094                 :          0 :     size_t n_random_bytes = high_bit / 8 + 1;
+    3095                 :            : 
+    3096                 :            :     /* [Curve25519] page 5 */
+    3097                 :            :     /* Generate a (high_bit+1)-bit random number by generating just enough
+    3098                 :            :      * random bytes, then shifting out extra bits from the top (necessary
+    3099                 :            :      * when (high_bit+1) is not a multiple of 8). */
+    3100         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_fill_random(d, n_random_bytes,
+    3101                 :            :                                             f_rng, p_rng));
+    3102         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(d, 8 * n_random_bytes - high_bit - 1));
+    3103                 :            : 
+    3104         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_set_bit(d, high_bit, 1));
+    3105                 :            : 
+    3106                 :            :     /* Make sure the last two bits are unset for Curve448, three bits for
+    3107                 :            :        Curve25519 */
+    3108         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_set_bit(d, 0, 0));
+    3109         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_set_bit(d, 1, 0));
+    3110         [ #  # ]:          0 :     if (high_bit == 254) {
+    3111         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_set_bit(d, 2, 0));
+    3112                 :            :     }
+    3113                 :            : 
+    3114                 :          0 : cleanup:
+    3115                 :          0 :     return ret;
+    3116                 :            : }
+    3117                 :            : #endif /* MBEDTLS_ECP_MONTGOMERY_ENABLED */
+    3118                 :            : 
+    3119                 :            : #if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
+    3120                 :        424 : static int mbedtls_ecp_gen_privkey_sw(
+    3121                 :            :     const mbedtls_mpi *N, mbedtls_mpi *d,
+    3122                 :            :     int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
+    3123                 :            : {
+    3124                 :        424 :     int ret = mbedtls_mpi_random(d, 1, N, f_rng, p_rng);
+    3125         [ -  + ]:        424 :     switch (ret) {
+    3126                 :          0 :         case MBEDTLS_ERR_MPI_NOT_ACCEPTABLE:
+    3127                 :          0 :             return MBEDTLS_ERR_ECP_RANDOM_FAILED;
+    3128                 :        424 :         default:
+    3129                 :        424 :             return ret;
+    3130                 :            :     }
+    3131                 :            : }
+    3132                 :            : #endif /* MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED */
+    3133                 :            : 
+    3134                 :            : /*
+    3135                 :            :  * Generate a private key
+    3136                 :            :  */
+    3137                 :        424 : int mbedtls_ecp_gen_privkey(const mbedtls_ecp_group *grp,
+    3138                 :            :                             mbedtls_mpi *d,
+    3139                 :            :                             int (*f_rng)(void *, unsigned char *, size_t),
+    3140                 :            :                             void *p_rng)
+    3141                 :            : {
+    3142                 :            : #if defined(MBEDTLS_ECP_MONTGOMERY_ENABLED)
+    3143         [ -  + ]:        424 :     if (mbedtls_ecp_get_type(grp) == MBEDTLS_ECP_TYPE_MONTGOMERY) {
+    3144                 :          0 :         return mbedtls_ecp_gen_privkey_mx(grp->nbits, d, f_rng, p_rng);
+    3145                 :            :     }
+    3146                 :            : #endif /* MBEDTLS_ECP_MONTGOMERY_ENABLED */
+    3147                 :            : 
+    3148                 :            : #if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
+    3149         [ +  - ]:        424 :     if (mbedtls_ecp_get_type(grp) == MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS) {
+    3150                 :        424 :         return mbedtls_ecp_gen_privkey_sw(&grp->N, d, f_rng, p_rng);
+    3151                 :            :     }
+    3152                 :            : #endif /* MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED */
+    3153                 :            : 
+    3154                 :          0 :     return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+    3155                 :            : }
+    3156                 :            : 
+    3157                 :            : #if defined(MBEDTLS_ECP_C)
+    3158                 :            : /*
+    3159                 :            :  * Generate a keypair with configurable base point
+    3160                 :            :  */
+    3161                 :          0 : int mbedtls_ecp_gen_keypair_base(mbedtls_ecp_group *grp,
+    3162                 :            :                                  const mbedtls_ecp_point *G,
+    3163                 :            :                                  mbedtls_mpi *d, mbedtls_ecp_point *Q,
+    3164                 :            :                                  int (*f_rng)(void *, unsigned char *, size_t),
+    3165                 :            :                                  void *p_rng)
+    3166                 :            : {
+    3167                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    3168         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_ecp_gen_privkey(grp, d, f_rng, p_rng));
+    3169         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_ecp_mul(grp, Q, d, G, f_rng, p_rng));
+    3170                 :            : 
+    3171                 :          0 : cleanup:
+    3172                 :          0 :     return ret;
+    3173                 :            : }
+    3174                 :            : 
+    3175                 :            : /*
+    3176                 :            :  * Generate key pair, wrapper for conventional base point
+    3177                 :            :  */
+    3178                 :          0 : int mbedtls_ecp_gen_keypair(mbedtls_ecp_group *grp,
+    3179                 :            :                             mbedtls_mpi *d, mbedtls_ecp_point *Q,
+    3180                 :            :                             int (*f_rng)(void *, unsigned char *, size_t),
+    3181                 :            :                             void *p_rng)
+    3182                 :            : {
+    3183                 :          0 :     return mbedtls_ecp_gen_keypair_base(grp, &grp->G, d, Q, f_rng, p_rng);
+    3184                 :            : }
+    3185                 :            : 
+    3186                 :            : /*
+    3187                 :            :  * Generate a keypair, prettier wrapper
+    3188                 :            :  */
+    3189                 :          0 : int mbedtls_ecp_gen_key(mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key,
+    3190                 :            :                         int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
+    3191                 :            : {
+    3192                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    3193         [ #  # ]:          0 :     if ((ret = mbedtls_ecp_group_load(&key->grp, grp_id)) != 0) {
+    3194                 :          0 :         return ret;
+    3195                 :            :     }
+    3196                 :            : 
+    3197                 :          0 :     return mbedtls_ecp_gen_keypair(&key->grp, &key->d, &key->Q, f_rng, p_rng);
+    3198                 :            : }
+    3199                 :            : #endif /* MBEDTLS_ECP_C */
+    3200                 :            : 
+    3201                 :          0 : int mbedtls_ecp_set_public_key(mbedtls_ecp_group_id grp_id,
+    3202                 :            :                                mbedtls_ecp_keypair *key,
+    3203                 :            :                                const mbedtls_ecp_point *Q)
+    3204                 :            : {
+    3205                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    3206                 :            : 
+    3207         [ #  # ]:          0 :     if (key->grp.id == MBEDTLS_ECP_DP_NONE) {
+    3208                 :            :         /* Group not set yet */
+    3209         [ #  # ]:          0 :         if ((ret = mbedtls_ecp_group_load(&key->grp, grp_id)) != 0) {
+    3210                 :          0 :             return ret;
+    3211                 :            :         }
+    3212         [ #  # ]:          0 :     } else if (key->grp.id != grp_id) {
+    3213                 :            :         /* Group mismatch */
+    3214                 :          0 :         return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+    3215                 :            :     }
+    3216                 :          0 :     return mbedtls_ecp_copy(&key->Q, Q);
+    3217                 :            : }
+    3218                 :            : 
+    3219                 :            : 
+    3220                 :            : #define ECP_CURVE25519_KEY_SIZE 32
+    3221                 :            : #define ECP_CURVE448_KEY_SIZE   56
+    3222                 :            : /*
+    3223                 :            :  * Read a private key.
+    3224                 :            :  */
+    3225                 :        128 : int mbedtls_ecp_read_key(mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key,
+    3226                 :            :                          const unsigned char *buf, size_t buflen)
+    3227                 :            : {
+    3228                 :        128 :     int ret = 0;
+    3229                 :            : 
+    3230         [ -  + ]:        128 :     if ((ret = mbedtls_ecp_group_load(&key->grp, grp_id)) != 0) {
+    3231                 :          0 :         return ret;
+    3232                 :            :     }
+    3233                 :            : 
+    3234                 :        128 :     ret = MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
+    3235                 :            : 
+    3236                 :            : #if defined(MBEDTLS_ECP_MONTGOMERY_ENABLED)
+    3237         [ -  + ]:        128 :     if (mbedtls_ecp_get_type(&key->grp) == MBEDTLS_ECP_TYPE_MONTGOMERY) {
+    3238                 :            :         /*
+    3239                 :            :          * Mask the key as mandated by RFC7748 for Curve25519 and Curve448.
+    3240                 :            :          */
+    3241         [ #  # ]:          0 :         if (grp_id == MBEDTLS_ECP_DP_CURVE25519) {
+    3242         [ #  # ]:          0 :             if (buflen != ECP_CURVE25519_KEY_SIZE) {
+    3243                 :          0 :                 return MBEDTLS_ERR_ECP_INVALID_KEY;
+    3244                 :            :             }
+    3245                 :            : 
+    3246         [ #  # ]:          0 :             MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary_le(&key->d, buf, buflen));
+    3247                 :            : 
+    3248                 :            :             /* Set the three least significant bits to 0 */
+    3249         [ #  # ]:          0 :             MBEDTLS_MPI_CHK(mbedtls_mpi_set_bit(&key->d, 0, 0));
+    3250         [ #  # ]:          0 :             MBEDTLS_MPI_CHK(mbedtls_mpi_set_bit(&key->d, 1, 0));
+    3251         [ #  # ]:          0 :             MBEDTLS_MPI_CHK(mbedtls_mpi_set_bit(&key->d, 2, 0));
+    3252                 :            : 
+    3253                 :            :             /* Set the most significant bit to 0 */
+    3254         [ #  # ]:          0 :             MBEDTLS_MPI_CHK(
+    3255                 :            :                 mbedtls_mpi_set_bit(&key->d,
+    3256                 :            :                                     ECP_CURVE25519_KEY_SIZE * 8 - 1, 0)
+    3257                 :            :                 );
+    3258                 :            : 
+    3259                 :            :             /* Set the second most significant bit to 1 */
+    3260         [ #  # ]:          0 :             MBEDTLS_MPI_CHK(
+    3261                 :            :                 mbedtls_mpi_set_bit(&key->d,
+    3262                 :            :                                     ECP_CURVE25519_KEY_SIZE * 8 - 2, 1)
+    3263                 :            :                 );
+    3264         [ #  # ]:          0 :         } else if (grp_id == MBEDTLS_ECP_DP_CURVE448) {
+    3265         [ #  # ]:          0 :             if (buflen != ECP_CURVE448_KEY_SIZE) {
+    3266                 :          0 :                 return MBEDTLS_ERR_ECP_INVALID_KEY;
+    3267                 :            :             }
+    3268                 :            : 
+    3269         [ #  # ]:          0 :             MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary_le(&key->d, buf, buflen));
+    3270                 :            : 
+    3271                 :            :             /* Set the two least significant bits to 0 */
+    3272         [ #  # ]:          0 :             MBEDTLS_MPI_CHK(mbedtls_mpi_set_bit(&key->d, 0, 0));
+    3273         [ #  # ]:          0 :             MBEDTLS_MPI_CHK(mbedtls_mpi_set_bit(&key->d, 1, 0));
+    3274                 :            : 
+    3275                 :            :             /* Set the most significant bit to 1 */
+    3276         [ #  # ]:          0 :             MBEDTLS_MPI_CHK(
+    3277                 :            :                 mbedtls_mpi_set_bit(&key->d,
+    3278                 :            :                                     ECP_CURVE448_KEY_SIZE * 8 - 1, 1)
+    3279                 :            :                 );
+    3280                 :            :         }
+    3281                 :            :     }
+    3282                 :            : #endif
+    3283                 :            : #if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
+    3284         [ +  - ]:        128 :     if (mbedtls_ecp_get_type(&key->grp) == MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS) {
+    3285         [ -  + ]:        128 :         MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&key->d, buf, buflen));
+    3286                 :            :     }
+    3287                 :            : #endif
+    3288                 :            : 
+    3289         [ -  + ]:        128 :     if (ret == 0) {
+    3290         [ +  - ]:        128 :         MBEDTLS_MPI_CHK(mbedtls_ecp_check_privkey(&key->grp, &key->d));
+    3291                 :            :     }
+    3292                 :            : 
+    3293                 :        128 : cleanup:
+    3294                 :            : 
+    3295         [ -  + ]:        128 :     if (ret != 0) {
+    3296                 :          0 :         mbedtls_mpi_free(&key->d);
+    3297                 :            :     }
+    3298                 :            : 
+    3299                 :        128 :     return ret;
+    3300                 :            : }
+    3301                 :            : 
+    3302                 :            : /*
+    3303                 :            :  * Write a private key.
+    3304                 :            :  */
+    3305                 :            : #if !defined MBEDTLS_DEPRECATED_REMOVED
+    3306                 :          0 : int mbedtls_ecp_write_key(mbedtls_ecp_keypair *key,
+    3307                 :            :                           unsigned char *buf, size_t buflen)
+    3308                 :            : {
+    3309                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    3310                 :            : 
+    3311                 :            : #if defined(MBEDTLS_ECP_MONTGOMERY_ENABLED)
+    3312         [ #  # ]:          0 :     if (mbedtls_ecp_get_type(&key->grp) == MBEDTLS_ECP_TYPE_MONTGOMERY) {
+    3313         [ #  # ]:          0 :         if (key->grp.id == MBEDTLS_ECP_DP_CURVE25519) {
+    3314         [ #  # ]:          0 :             if (buflen < ECP_CURVE25519_KEY_SIZE) {
+    3315                 :          0 :                 return MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL;
+    3316                 :            :             }
+    3317                 :            : 
+    3318         [ #  # ]:          0 :         } else if (key->grp.id == MBEDTLS_ECP_DP_CURVE448) {
+    3319         [ #  # ]:          0 :             if (buflen < ECP_CURVE448_KEY_SIZE) {
+    3320                 :          0 :                 return MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL;
+    3321                 :            :             }
+    3322                 :            :         }
+    3323         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary_le(&key->d, buf, buflen));
+    3324                 :            :     }
+    3325                 :            : #endif
+    3326                 :            : #if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
+    3327         [ #  # ]:          0 :     if (mbedtls_ecp_get_type(&key->grp) == MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS) {
+    3328         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(&key->d, buf, buflen));
+    3329                 :            :     }
+    3330                 :            : 
+    3331                 :            : #endif
+    3332                 :          0 : cleanup:
+    3333                 :            : 
+    3334                 :          0 :     return ret;
+    3335                 :            : }
+    3336                 :            : #endif /* MBEDTLS_DEPRECATED_REMOVED */
+    3337                 :            : 
+    3338                 :          0 : int mbedtls_ecp_write_key_ext(const mbedtls_ecp_keypair *key,
+    3339                 :            :                               size_t *olen, unsigned char *buf, size_t buflen)
+    3340                 :            : {
+    3341                 :          0 :     size_t len = (key->grp.nbits + 7) / 8;
+    3342         [ #  # ]:          0 :     if (len > buflen) {
+    3343                 :            :         /* For robustness, ensure *olen <= buflen even on error. */
+    3344                 :          0 :         *olen = 0;
+    3345                 :          0 :         return MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL;
+    3346                 :            :     }
+    3347                 :          0 :     *olen = len;
+    3348                 :            : 
+    3349                 :            :     /* Private key not set */
+    3350         [ #  # ]:          0 :     if (key->d.n == 0) {
+    3351                 :          0 :         return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+    3352                 :            :     }
+    3353                 :            : 
+    3354                 :            : #if defined(MBEDTLS_ECP_MONTGOMERY_ENABLED)
+    3355         [ #  # ]:          0 :     if (mbedtls_ecp_get_type(&key->grp) == MBEDTLS_ECP_TYPE_MONTGOMERY) {
+    3356                 :          0 :         return mbedtls_mpi_write_binary_le(&key->d, buf, len);
+    3357                 :            :     }
+    3358                 :            : #endif
+    3359                 :            : 
+    3360                 :            : #if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
+    3361         [ #  # ]:          0 :     if (mbedtls_ecp_get_type(&key->grp) == MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS) {
+    3362                 :          0 :         return mbedtls_mpi_write_binary(&key->d, buf, len);
+    3363                 :            :     }
+    3364                 :            : #endif
+    3365                 :            : 
+    3366                 :            :     /* Private key set but no recognized curve type? This shouldn't happen. */
+    3367                 :          0 :     return MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    3368                 :            : }
+    3369                 :            : 
+    3370                 :            : /*
+    3371                 :            :  * Write a public key.
+    3372                 :            :  */
+    3373                 :          0 : int mbedtls_ecp_write_public_key(const mbedtls_ecp_keypair *key,
+    3374                 :            :                                  int format, size_t *olen,
+    3375                 :            :                                  unsigned char *buf, size_t buflen)
+    3376                 :            : {
+    3377                 :          0 :     return mbedtls_ecp_point_write_binary(&key->grp, &key->Q,
+    3378                 :            :                                           format, olen, buf, buflen);
+    3379                 :            : }
+    3380                 :            : 
+    3381                 :            : 
+    3382                 :            : #if defined(MBEDTLS_ECP_C)
+    3383                 :            : /*
+    3384                 :            :  * Check a public-private key pair
+    3385                 :            :  */
+    3386                 :          0 : int mbedtls_ecp_check_pub_priv(
+    3387                 :            :     const mbedtls_ecp_keypair *pub, const mbedtls_ecp_keypair *prv,
+    3388                 :            :     int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
+    3389                 :            : {
+    3390                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    3391                 :            :     mbedtls_ecp_point Q;
+    3392                 :            :     mbedtls_ecp_group grp;
+    3393         [ #  # ]:          0 :     if (pub->grp.id == MBEDTLS_ECP_DP_NONE ||
+    3394   [ #  #  #  # ]:          0 :         pub->grp.id != prv->grp.id ||
+    3395         [ #  # ]:          0 :         mbedtls_mpi_cmp_mpi(&pub->Q.X, &prv->Q.X) ||
+    3396         [ #  # ]:          0 :         mbedtls_mpi_cmp_mpi(&pub->Q.Y, &prv->Q.Y) ||
+    3397                 :          0 :         mbedtls_mpi_cmp_mpi(&pub->Q.Z, &prv->Q.Z)) {
+    3398                 :          0 :         return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+    3399                 :            :     }
+    3400                 :            : 
+    3401                 :          0 :     mbedtls_ecp_point_init(&Q);
+    3402                 :          0 :     mbedtls_ecp_group_init(&grp);
+    3403                 :            : 
+    3404                 :            :     /* mbedtls_ecp_mul() needs a non-const group... */
+    3405                 :          0 :     mbedtls_ecp_group_copy(&grp, &prv->grp);
+    3406                 :            : 
+    3407                 :            :     /* Also checks d is valid */
+    3408         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_ecp_mul(&grp, &Q, &prv->d, &prv->grp.G, f_rng, p_rng));
+    3409                 :            : 
+    3410   [ #  #  #  # ]:          0 :     if (mbedtls_mpi_cmp_mpi(&Q.X, &prv->Q.X) ||
+    3411         [ #  # ]:          0 :         mbedtls_mpi_cmp_mpi(&Q.Y, &prv->Q.Y) ||
+    3412                 :          0 :         mbedtls_mpi_cmp_mpi(&Q.Z, &prv->Q.Z)) {
+    3413                 :          0 :         ret = MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+    3414                 :          0 :         goto cleanup;
+    3415                 :            :     }
+    3416                 :            : 
+    3417                 :          0 : cleanup:
+    3418                 :          0 :     mbedtls_ecp_point_free(&Q);
+    3419                 :          0 :     mbedtls_ecp_group_free(&grp);
+    3420                 :            : 
+    3421                 :          0 :     return ret;
+    3422                 :            : }
+    3423                 :            : 
+    3424                 :          0 : int mbedtls_ecp_keypair_calc_public(mbedtls_ecp_keypair *key,
+    3425                 :            :                                     int (*f_rng)(void *, unsigned char *, size_t),
+    3426                 :            :                                     void *p_rng)
+    3427                 :            : {
+    3428                 :          0 :     return mbedtls_ecp_mul(&key->grp, &key->Q, &key->d, &key->grp.G,
+    3429                 :            :                            f_rng, p_rng);
+    3430                 :            : }
+    3431                 :            : #endif /* MBEDTLS_ECP_C */
+    3432                 :            : 
+    3433                 :          0 : mbedtls_ecp_group_id mbedtls_ecp_keypair_get_group_id(
+    3434                 :            :     const mbedtls_ecp_keypair *key)
+    3435                 :            : {
+    3436                 :          0 :     return key->grp.id;
+    3437                 :            : }
+    3438                 :            : 
+    3439                 :            : /*
+    3440                 :            :  * Export generic key-pair parameters.
+    3441                 :            :  */
+    3442                 :          0 : int mbedtls_ecp_export(const mbedtls_ecp_keypair *key, mbedtls_ecp_group *grp,
+    3443                 :            :                        mbedtls_mpi *d, mbedtls_ecp_point *Q)
+    3444                 :            : {
+    3445                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    3446                 :            : 
+    3447   [ #  #  #  # ]:          0 :     if (grp != NULL && (ret = mbedtls_ecp_group_copy(grp, &key->grp)) != 0) {
+    3448                 :          0 :         return ret;
+    3449                 :            :     }
+    3450                 :            : 
+    3451   [ #  #  #  # ]:          0 :     if (d != NULL && (ret = mbedtls_mpi_copy(d, &key->d)) != 0) {
+    3452                 :          0 :         return ret;
+    3453                 :            :     }
+    3454                 :            : 
+    3455   [ #  #  #  # ]:          0 :     if (Q != NULL && (ret = mbedtls_ecp_copy(Q, &key->Q)) != 0) {
+    3456                 :          0 :         return ret;
+    3457                 :            :     }
+    3458                 :            : 
+    3459                 :          0 :     return 0;
+    3460                 :            : }
+    3461                 :            : 
+    3462                 :            : #if defined(MBEDTLS_SELF_TEST)
+    3463                 :            : 
+    3464                 :            : #if defined(MBEDTLS_ECP_C)
+    3465                 :            : /*
+    3466                 :            :  * PRNG for test - !!!INSECURE NEVER USE IN PRODUCTION!!!
+    3467                 :            :  *
+    3468                 :            :  * This is the linear congruential generator from numerical recipes,
+    3469                 :            :  * except we only use the low byte as the output. See
+    3470                 :            :  * https://en.wikipedia.org/wiki/Linear_congruential_generator#Parameters_in_common_use
+    3471                 :            :  */
+    3472                 :          0 : static int self_test_rng(void *ctx, unsigned char *out, size_t len)
+    3473                 :            : {
+    3474                 :            :     static uint32_t state = 42;
+    3475                 :            : 
+    3476                 :            :     (void) ctx;
+    3477                 :            : 
+    3478         [ #  # ]:          0 :     for (size_t i = 0; i < len; i++) {
+    3479                 :          0 :         state = state * 1664525u + 1013904223u;
+    3480                 :          0 :         out[i] = (unsigned char) state;
+    3481                 :            :     }
+    3482                 :            : 
+    3483                 :          0 :     return 0;
+    3484                 :            : }
+    3485                 :            : 
+    3486                 :            : /* Adjust the exponent to be a valid private point for the specified curve.
+    3487                 :            :  * This is sometimes necessary because we use a single set of exponents
+    3488                 :            :  * for all curves but the validity of values depends on the curve. */
+    3489                 :          0 : static int self_test_adjust_exponent(const mbedtls_ecp_group *grp,
+    3490                 :            :                                      mbedtls_mpi *m)
+    3491                 :            : {
+    3492                 :          0 :     int ret = 0;
+    3493                 :          0 :     switch (grp->id) {
+    3494                 :            :     /* If Curve25519 is available, then that's what we use for the
+    3495                 :            :      * Montgomery test, so we don't need the adjustment code. */
+    3496                 :            : #if !defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED)
+    3497                 :            : #if defined(MBEDTLS_ECP_DP_CURVE448_ENABLED)
+    3498                 :            :         case MBEDTLS_ECP_DP_CURVE448:
+    3499                 :            :             /* Move highest bit from 254 to N-1. Setting bit N-1 is
+    3500                 :            :              * necessary to enforce the highest-bit-set constraint. */
+    3501                 :            :             MBEDTLS_MPI_CHK(mbedtls_mpi_set_bit(m, 254, 0));
+    3502                 :            :             MBEDTLS_MPI_CHK(mbedtls_mpi_set_bit(m, grp->nbits, 1));
+    3503                 :            :             /* Copy second-highest bit from 253 to N-2. This is not
+    3504                 :            :              * necessary but improves the test variety a bit. */
+    3505                 :            :             MBEDTLS_MPI_CHK(
+    3506                 :            :                 mbedtls_mpi_set_bit(m, grp->nbits - 1,
+    3507                 :            :                                     mbedtls_mpi_get_bit(m, 253)));
+    3508                 :            :             break;
+    3509                 :            : #endif
+    3510                 :            : #endif /* ! defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED) */
+    3511                 :            :         default:
+    3512                 :            :             /* Non-Montgomery curves and Curve25519 need no adjustment. */
+    3513                 :            :             (void) grp;
+    3514                 :            :             (void) m;
+    3515                 :          0 :             goto cleanup;
+    3516                 :            :     }
+    3517                 :          0 : cleanup:
+    3518                 :          0 :     return ret;
+    3519                 :            : }
+    3520                 :            : 
+    3521                 :            : /* Calculate R = m.P for each m in exponents. Check that the number of
+    3522                 :            :  * basic operations doesn't depend on the value of m. */
+    3523                 :          0 : static int self_test_point(int verbose,
+    3524                 :            :                            mbedtls_ecp_group *grp,
+    3525                 :            :                            mbedtls_ecp_point *R,
+    3526                 :            :                            mbedtls_mpi *m,
+    3527                 :            :                            const mbedtls_ecp_point *P,
+    3528                 :            :                            const char *const *exponents,
+    3529                 :            :                            size_t n_exponents)
+    3530                 :            : {
+    3531                 :          0 :     int ret = 0;
+    3532                 :          0 :     size_t i = 0;
+    3533                 :            :     unsigned long add_c_prev, dbl_c_prev, mul_c_prev;
+    3534                 :          0 :     add_count = 0;
+    3535                 :          0 :     dbl_count = 0;
+    3536                 :          0 :     mul_count = 0;
+    3537                 :            : 
+    3538         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_read_string(m, 16, exponents[0]));
+    3539         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(self_test_adjust_exponent(grp, m));
+    3540         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_ecp_mul(grp, R, m, P, self_test_rng, NULL));
+    3541                 :            : 
+    3542         [ #  # ]:          0 :     for (i = 1; i < n_exponents; i++) {
+    3543                 :          0 :         add_c_prev = add_count;
+    3544                 :          0 :         dbl_c_prev = dbl_count;
+    3545                 :          0 :         mul_c_prev = mul_count;
+    3546                 :          0 :         add_count = 0;
+    3547                 :          0 :         dbl_count = 0;
+    3548                 :          0 :         mul_count = 0;
+    3549                 :            : 
+    3550         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_read_string(m, 16, exponents[i]));
+    3551         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(self_test_adjust_exponent(grp, m));
+    3552         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_ecp_mul(grp, R, m, P, self_test_rng, NULL));
+    3553                 :            : 
+    3554         [ #  # ]:          0 :         if (add_count != add_c_prev ||
+    3555         [ #  # ]:          0 :             dbl_count != dbl_c_prev ||
+    3556         [ #  # ]:          0 :             mul_count != mul_c_prev) {
+    3557                 :          0 :             ret = 1;
+    3558                 :          0 :             break;
+    3559                 :            :         }
+    3560                 :            :     }
+    3561                 :            : 
+    3562                 :          0 : cleanup:
+    3563         [ #  # ]:          0 :     if (verbose != 0) {
+    3564         [ #  # ]:          0 :         if (ret != 0) {
+    3565                 :          0 :             mbedtls_printf("failed (%u)\n", (unsigned int) i);
+    3566                 :            :         } else {
+    3567                 :          0 :             mbedtls_printf("passed\n");
+    3568                 :            :         }
+    3569                 :            :     }
+    3570                 :          0 :     return ret;
+    3571                 :            : }
+    3572                 :            : #endif /* MBEDTLS_ECP_C */
+    3573                 :            : 
+    3574                 :            : /*
+    3575                 :            :  * Checkup routine
+    3576                 :            :  */
+    3577                 :          0 : int mbedtls_ecp_self_test(int verbose)
+    3578                 :            : {
+    3579                 :            : #if defined(MBEDTLS_ECP_C)
+    3580                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    3581                 :            :     mbedtls_ecp_group grp;
+    3582                 :            :     mbedtls_ecp_point R, P;
+    3583                 :            :     mbedtls_mpi m;
+    3584                 :            : 
+    3585                 :            : #if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
+    3586                 :            :     /* Exponents especially adapted for secp192k1, which has the lowest
+    3587                 :            :      * order n of all supported curves (secp192r1 is in a slightly larger
+    3588                 :            :      * field but the order of its base point is slightly smaller). */
+    3589                 :          0 :     const char *sw_exponents[] =
+    3590                 :            :     {
+    3591                 :            :         "000000000000000000000000000000000000000000000001", /* one */
+    3592                 :            :         "FFFFFFFFFFFFFFFFFFFFFFFE26F2FC170F69466A74DEFD8C", /* n - 1 */
+    3593                 :            :         "5EA6F389A38B8BC81E767753B15AA5569E1782E30ABE7D25", /* random */
+    3594                 :            :         "400000000000000000000000000000000000000000000000", /* one and zeros */
+    3595                 :            :         "7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", /* all ones */
+    3596                 :            :         "555555555555555555555555555555555555555555555555", /* 101010... */
+    3597                 :            :     };
+    3598                 :            : #endif /* MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED */
+    3599                 :            : #if defined(MBEDTLS_ECP_MONTGOMERY_ENABLED)
+    3600                 :          0 :     const char *m_exponents[] =
+    3601                 :            :     {
+    3602                 :            :         /* Valid private values for Curve25519. In a build with Curve448
+    3603                 :            :          * but not Curve25519, they will be adjusted in
+    3604                 :            :          * self_test_adjust_exponent(). */
+    3605                 :            :         "4000000000000000000000000000000000000000000000000000000000000000",
+    3606                 :            :         "5C3C3C3C3C3C3C3C3C3C3C3C3C3C3C3C3C3C3C3C3C3C3C3C3C3C3C3C3C3C3C30",
+    3607                 :            :         "5715ECCE24583F7A7023C24164390586842E816D7280A49EF6DF4EAE6B280BF8",
+    3608                 :            :         "41A2B017516F6D254E1F002BCCBADD54BE30F8CEC737A0E912B4963B6BA74460",
+    3609                 :            :         "5555555555555555555555555555555555555555555555555555555555555550",
+    3610                 :            :         "7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF8",
+    3611                 :            :     };
+    3612                 :            : #endif /* MBEDTLS_ECP_MONTGOMERY_ENABLED */
+    3613                 :            : 
+    3614                 :          0 :     mbedtls_ecp_group_init(&grp);
+    3615                 :          0 :     mbedtls_ecp_point_init(&R);
+    3616                 :          0 :     mbedtls_ecp_point_init(&P);
+    3617                 :          0 :     mbedtls_mpi_init(&m);
+    3618                 :            : 
+    3619                 :            : #if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
+    3620                 :            :     /* Use secp192r1 if available, or any available curve */
+    3621                 :            : #if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED)
+    3622         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_ecp_group_load(&grp, MBEDTLS_ECP_DP_SECP192R1));
+    3623                 :            : #else
+    3624                 :            :     MBEDTLS_MPI_CHK(mbedtls_ecp_group_load(&grp, mbedtls_ecp_curve_list()->grp_id));
+    3625                 :            : #endif
+    3626                 :            : 
+    3627         [ #  # ]:          0 :     if (verbose != 0) {
+    3628                 :          0 :         mbedtls_printf("  ECP SW test #1 (constant op_count, base point G): ");
+    3629                 :            :     }
+    3630                 :            :     /* Do a dummy multiplication first to trigger precomputation */
+    3631         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&m, 2));
+    3632         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_ecp_mul(&grp, &P, &m, &grp.G, self_test_rng, NULL));
+    3633                 :          0 :     ret = self_test_point(verbose,
+    3634                 :            :                           &grp, &R, &m, &grp.G,
+    3635                 :            :                           sw_exponents,
+    3636                 :            :                           sizeof(sw_exponents) / sizeof(sw_exponents[0]));
+    3637         [ #  # ]:          0 :     if (ret != 0) {
+    3638                 :          0 :         goto cleanup;
+    3639                 :            :     }
+    3640                 :            : 
+    3641         [ #  # ]:          0 :     if (verbose != 0) {
+    3642                 :          0 :         mbedtls_printf("  ECP SW test #2 (constant op_count, other point): ");
+    3643                 :            :     }
+    3644                 :            :     /* We computed P = 2G last time, use it */
+    3645                 :          0 :     ret = self_test_point(verbose,
+    3646                 :            :                           &grp, &R, &m, &P,
+    3647                 :            :                           sw_exponents,
+    3648                 :            :                           sizeof(sw_exponents) / sizeof(sw_exponents[0]));
+    3649         [ #  # ]:          0 :     if (ret != 0) {
+    3650                 :          0 :         goto cleanup;
+    3651                 :            :     }
+    3652                 :            : 
+    3653                 :          0 :     mbedtls_ecp_group_free(&grp);
+    3654                 :          0 :     mbedtls_ecp_point_free(&R);
+    3655                 :            : #endif /* MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED */
+    3656                 :            : 
+    3657                 :            : #if defined(MBEDTLS_ECP_MONTGOMERY_ENABLED)
+    3658         [ #  # ]:          0 :     if (verbose != 0) {
+    3659                 :          0 :         mbedtls_printf("  ECP Montgomery test (constant op_count): ");
+    3660                 :            :     }
+    3661                 :            : #if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED)
+    3662         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_ecp_group_load(&grp, MBEDTLS_ECP_DP_CURVE25519));
+    3663                 :            : #elif defined(MBEDTLS_ECP_DP_CURVE448_ENABLED)
+    3664                 :            :     MBEDTLS_MPI_CHK(mbedtls_ecp_group_load(&grp, MBEDTLS_ECP_DP_CURVE448));
+    3665                 :            : #else
+    3666                 :            : #error "MBEDTLS_ECP_MONTGOMERY_ENABLED is defined, but no curve is supported for self-test"
+    3667                 :            : #endif
+    3668                 :          0 :     ret = self_test_point(verbose,
+    3669                 :            :                           &grp, &R, &m, &grp.G,
+    3670                 :            :                           m_exponents,
+    3671                 :            :                           sizeof(m_exponents) / sizeof(m_exponents[0]));
+    3672         [ #  # ]:          0 :     if (ret != 0) {
+    3673                 :          0 :         goto cleanup;
+    3674                 :            :     }
+    3675                 :            : #endif /* MBEDTLS_ECP_MONTGOMERY_ENABLED */
+    3676                 :            : 
+    3677                 :          0 : cleanup:
+    3678                 :            : 
+    3679   [ #  #  #  # ]:          0 :     if (ret < 0 && verbose != 0) {
+    3680                 :          0 :         mbedtls_printf("Unexpected error, return code = %08X\n", (unsigned int) ret);
+    3681                 :            :     }
+    3682                 :            : 
+    3683                 :          0 :     mbedtls_ecp_group_free(&grp);
+    3684                 :          0 :     mbedtls_ecp_point_free(&R);
+    3685                 :          0 :     mbedtls_ecp_point_free(&P);
+    3686                 :          0 :     mbedtls_mpi_free(&m);
+    3687                 :            : 
+    3688         [ #  # ]:          0 :     if (verbose != 0) {
+    3689                 :          0 :         mbedtls_printf("\n");
+    3690                 :            :     }
+    3691                 :            : 
+    3692                 :          0 :     return ret;
+    3693                 :            : #else /* MBEDTLS_ECP_C */
+    3694                 :            :     (void) verbose;
+    3695                 :            :     return 0;
+    3696                 :            : #endif /* MBEDTLS_ECP_C */
+    3697                 :            : }
+    3698                 :            : 
+    3699                 :            : #endif /* MBEDTLS_SELF_TEST */
+    3700                 :            : 
+    3701                 :            : #endif /* !MBEDTLS_ECP_ALT */
+    3702                 :            : 
+    3703                 :            : #endif /* MBEDTLS_ECP_LIGHT */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/ecp_curves.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ecp_curves.c.func-sort-c.html new file mode 100644 index 00000000000..18a379df692 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ecp_curves.c.func-sort-c.html @@ -0,0 +1,165 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/ecp_curves.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - ecp_curves.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:12030639.2 %
Date:2024-09-22 08:21:07Functions:102147.6 %
Branches:9432329.1 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
add640
carry640
ecp_mod_koblitz0
ecp_mod_p1920
ecp_mod_p192k10
ecp_mod_p2240
ecp_mod_p2550
ecp_mod_p256k10
ecp_mod_p4480
ecp_use_curve255190
ecp_use_curve4480
ecp_mod_p38436
ecp_mod_p52136
ecp_group_load12462
ecp_mpi_set112462
mbedtls_ecp_group_load12462
ecp_mpi_load62310
mbedtls_ecp_fix_negative3467998
ecp_mod_p2566029951
sub32156187790
add32217671944
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/ecp_curves.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ecp_curves.c.func.html new file mode 100644 index 00000000000..99500da4462 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ecp_curves.c.func.html @@ -0,0 +1,165 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/ecp_curves.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - ecp_curves.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:12030639.2 %
Date:2024-09-22 08:21:07Functions:102147.6 %
Branches:9432329.1 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
add32217671944
add640
carry640
ecp_group_load12462
ecp_mod_koblitz0
ecp_mod_p1920
ecp_mod_p192k10
ecp_mod_p2240
ecp_mod_p2550
ecp_mod_p2566029951
ecp_mod_p256k10
ecp_mod_p38436
ecp_mod_p4480
ecp_mod_p52136
ecp_mpi_load62310
ecp_mpi_set112462
ecp_use_curve255190
ecp_use_curve4480
mbedtls_ecp_fix_negative3467998
mbedtls_ecp_group_load12462
sub32156187790
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/ecp_curves.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ecp_curves.c.gcov.html new file mode 100644 index 00000000000..133e8d06776 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ecp_curves.c.gcov.html @@ -0,0 +1,5577 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/ecp_curves.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - ecp_curves.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:12030639.2 %
Date:2024-09-22 08:21:07Functions:102147.6 %
Branches:9432329.1 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  *  Elliptic curves over GF(p): curve-specific data and functions
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  */
+       7                 :            : 
+       8                 :            : #include "common.h"
+       9                 :            : 
+      10                 :            : #if !defined(MBEDTLS_ECP_WITH_MPI_UINT)
+      11                 :            : 
+      12                 :            : #if defined(MBEDTLS_ECP_LIGHT)
+      13                 :            : 
+      14                 :            : #include "mbedtls/ecp.h"
+      15                 :            : #include "mbedtls/platform_util.h"
+      16                 :            : #include "mbedtls/error.h"
+      17                 :            : 
+      18                 :            : #include "bn_mul.h"
+      19                 :            : #include "bignum_core.h"
+      20                 :            : #include "ecp_invasive.h"
+      21                 :            : 
+      22                 :            : #include <string.h>
+      23                 :            : 
+      24                 :            : #if !defined(MBEDTLS_ECP_ALT)
+      25                 :            : 
+      26                 :            : #define ECP_MPI_INIT(_p, _n) { .p = (mbedtls_mpi_uint *) (_p), .s = 1, .n = (_n) }
+      27                 :            : 
+      28                 :            : #define ECP_MPI_INIT_ARRAY(x)   \
+      29                 :            :     ECP_MPI_INIT(x, sizeof(x) / sizeof(mbedtls_mpi_uint))
+      30                 :            : 
+      31                 :            : #define ECP_POINT_INIT_XY_Z0(x, y) { \
+      32                 :            :         ECP_MPI_INIT_ARRAY(x), ECP_MPI_INIT_ARRAY(y), ECP_MPI_INIT(NULL, 0) }
+      33                 :            : #define ECP_POINT_INIT_XY_Z1(x, y) { \
+      34                 :            :         ECP_MPI_INIT_ARRAY(x), ECP_MPI_INIT_ARRAY(y), ECP_MPI_INIT(mpi_one, 1) }
+      35                 :            : 
+      36                 :            : #if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) ||   \
+      37                 :            :     defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) ||   \
+      38                 :            :     defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) ||   \
+      39                 :            :     defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED) ||   \
+      40                 :            :     defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED) ||   \
+      41                 :            :     defined(MBEDTLS_ECP_DP_BP256R1_ENABLED)   ||   \
+      42                 :            :     defined(MBEDTLS_ECP_DP_BP384R1_ENABLED)   ||   \
+      43                 :            :     defined(MBEDTLS_ECP_DP_BP512R1_ENABLED)   ||   \
+      44                 :            :     defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED) ||   \
+      45                 :            :     defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED) ||   \
+      46                 :            :     defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED)
+      47                 :            : /* For these curves, we build the group parameters dynamically. */
+      48                 :            : #define ECP_LOAD_GROUP
+      49                 :            : static const mbedtls_mpi_uint mpi_one[] = { 1 };
+      50                 :            : #endif
+      51                 :            : 
+      52                 :            : /*
+      53                 :            :  * Note: the constants are in little-endian order
+      54                 :            :  * to be directly usable in MPIs
+      55                 :            :  */
+      56                 :            : 
+      57                 :            : /*
+      58                 :            :  * Domain parameters for secp192r1
+      59                 :            :  */
+      60                 :            : #if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED)
+      61                 :            : static const mbedtls_mpi_uint secp192r1_p[] = {
+      62                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
+      63                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
+      64                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
+      65                 :            : };
+      66                 :            : static const mbedtls_mpi_uint secp192r1_b[] = {
+      67                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB1, 0xB9, 0x46, 0xC1, 0xEC, 0xDE, 0xB8, 0xFE),
+      68                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x49, 0x30, 0x24, 0x72, 0xAB, 0xE9, 0xA7, 0x0F),
+      69                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE7, 0x80, 0x9C, 0xE5, 0x19, 0x05, 0x21, 0x64),
+      70                 :            : };
+      71                 :            : static const mbedtls_mpi_uint secp192r1_gx[] = {
+      72                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x12, 0x10, 0xFF, 0x82, 0xFD, 0x0A, 0xFF, 0xF4),
+      73                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x00, 0x88, 0xA1, 0x43, 0xEB, 0x20, 0xBF, 0x7C),
+      74                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF6, 0x90, 0x30, 0xB0, 0x0E, 0xA8, 0x8D, 0x18),
+      75                 :            : };
+      76                 :            : static const mbedtls_mpi_uint secp192r1_gy[] = {
+      77                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x11, 0x48, 0x79, 0x1E, 0xA1, 0x77, 0xF9, 0x73),
+      78                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD5, 0xCD, 0x24, 0x6B, 0xED, 0x11, 0x10, 0x63),
+      79                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x78, 0xDA, 0xC8, 0xFF, 0x95, 0x2B, 0x19, 0x07),
+      80                 :            : };
+      81                 :            : static const mbedtls_mpi_uint secp192r1_n[] = {
+      82                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x31, 0x28, 0xD2, 0xB4, 0xB1, 0xC9, 0x6B, 0x14),
+      83                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x36, 0xF8, 0xDE, 0x99, 0xFF, 0xFF, 0xFF, 0xFF),
+      84                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
+      85                 :            : };
+      86                 :            : #if MBEDTLS_ECP_FIXED_POINT_OPTIM == 1
+      87                 :            : static const mbedtls_mpi_uint secp192r1_T_0_X[] = {
+      88                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x12, 0x10, 0xFF, 0x82, 0xFD, 0x0A, 0xFF, 0xF4),
+      89                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x00, 0x88, 0xA1, 0x43, 0xEB, 0x20, 0xBF, 0x7C),
+      90                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF6, 0x90, 0x30, 0xB0, 0x0E, 0xA8, 0x8D, 0x18),
+      91                 :            : };
+      92                 :            : static const mbedtls_mpi_uint secp192r1_T_0_Y[] = {
+      93                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x11, 0x48, 0x79, 0x1E, 0xA1, 0x77, 0xF9, 0x73),
+      94                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD5, 0xCD, 0x24, 0x6B, 0xED, 0x11, 0x10, 0x63),
+      95                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x78, 0xDA, 0xC8, 0xFF, 0x95, 0x2B, 0x19, 0x07),
+      96                 :            : };
+      97                 :            : static const mbedtls_mpi_uint secp192r1_T_1_X[] = {
+      98                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x97, 0x9E, 0xE3, 0x60, 0x59, 0xD1, 0xC4, 0xC2),
+      99                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x91, 0xBD, 0x22, 0xD7, 0x2D, 0x07, 0xBD, 0xB6),
+     100                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x74, 0x2A, 0xCF, 0x33, 0xF0, 0xBE, 0xD1, 0xED),
+     101                 :            : };
+     102                 :            : static const mbedtls_mpi_uint secp192r1_T_1_Y[] = {
+     103                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x88, 0x71, 0x4B, 0xA8, 0xED, 0x7E, 0xC9, 0x1A),
+     104                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8E, 0x2A, 0xF6, 0xDF, 0x0E, 0xE8, 0x4C, 0x0F),
+     105                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC5, 0x35, 0xF7, 0x8A, 0xC3, 0xEC, 0xDE, 0x1E),
+     106                 :            : };
+     107                 :            : static const mbedtls_mpi_uint secp192r1_T_2_X[] = {
+     108                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x00, 0x67, 0xC2, 0x1D, 0x32, 0x8F, 0x10, 0xFB),
+     109                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBB, 0x2D, 0x17, 0xF3, 0xE4, 0xFE, 0xD8, 0x13),
+     110                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x55, 0x45, 0x10, 0x70, 0x2C, 0x3E, 0x52, 0x3E),
+     111                 :            : };
+     112                 :            : static const mbedtls_mpi_uint secp192r1_T_2_Y[] = {
+     113                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x61, 0xF1, 0x04, 0x5D, 0xEE, 0xD4, 0x56, 0xE6),
+     114                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x78, 0xB7, 0x38, 0x27, 0x61, 0xAA, 0x81, 0x87),
+     115                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x71, 0x37, 0xD7, 0x0E, 0x29, 0x0E, 0x11, 0x14),
+     116                 :            : };
+     117                 :            : static const mbedtls_mpi_uint secp192r1_T_3_X[] = {
+     118                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1E, 0x35, 0x52, 0xC6, 0x31, 0xB7, 0x27, 0xF5),
+     119                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3D, 0xD4, 0x15, 0x98, 0x0F, 0xE7, 0xF3, 0x6A),
+     120                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD3, 0x31, 0x70, 0x35, 0x09, 0xA0, 0x2B, 0xC2),
+     121                 :            : };
+     122                 :            : static const mbedtls_mpi_uint secp192r1_T_3_Y[] = {
+     123                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x21, 0x75, 0xA7, 0x4C, 0x88, 0xCF, 0x5B, 0xE4),
+     124                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x17, 0x17, 0x48, 0x8D, 0xF2, 0xF0, 0x86, 0xED),
+     125                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x49, 0xCF, 0xFE, 0x6B, 0xB0, 0xA5, 0x06, 0xAB),
+     126                 :            : };
+     127                 :            : static const mbedtls_mpi_uint secp192r1_T_4_X[] = {
+     128                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x18, 0x6A, 0xDC, 0x9A, 0x6D, 0x7B, 0x47, 0x2E),
+     129                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x12, 0xFC, 0x51, 0x12, 0x62, 0x66, 0x0B, 0x59),
+     130                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCD, 0x40, 0x93, 0xA0, 0xB5, 0x5A, 0x58, 0xD7),
+     131                 :            : };
+     132                 :            : static const mbedtls_mpi_uint secp192r1_T_4_Y[] = {
+     133                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEF, 0xCB, 0xAF, 0xDC, 0x0B, 0xA1, 0x26, 0xFB),
+     134                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDA, 0x36, 0x9D, 0xA3, 0xD7, 0x3B, 0xAD, 0x39),
+     135                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB4, 0x3B, 0x05, 0x9A, 0xA8, 0xAA, 0x69, 0xB2),
+     136                 :            : };
+     137                 :            : static const mbedtls_mpi_uint secp192r1_T_5_X[] = {
+     138                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6D, 0xD9, 0xD1, 0x4D, 0x4A, 0x6E, 0x96, 0x1E),
+     139                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x17, 0x66, 0x32, 0x39, 0xC6, 0x57, 0x7D, 0xE6),
+     140                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x92, 0xA0, 0x36, 0xC2, 0x45, 0xF9, 0x00, 0x62),
+     141                 :            : };
+     142                 :            : static const mbedtls_mpi_uint secp192r1_T_5_Y[] = {
+     143                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB4, 0xEF, 0x59, 0x46, 0xDC, 0x60, 0xD9, 0x8F),
+     144                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x24, 0xB0, 0xE9, 0x41, 0xA4, 0x87, 0x76, 0x89),
+     145                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x13, 0xD4, 0x0E, 0xB2, 0xFA, 0x16, 0x56, 0xDC),
+     146                 :            : };
+     147                 :            : static const mbedtls_mpi_uint secp192r1_T_6_X[] = {
+     148                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0A, 0x62, 0xD2, 0xB1, 0x34, 0xB2, 0xF1, 0x06),
+     149                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB2, 0xED, 0x55, 0xC5, 0x47, 0xB5, 0x07, 0x15),
+     150                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x17, 0xF6, 0x2F, 0x94, 0xC3, 0xDD, 0x54, 0x2F),
+     151                 :            : };
+     152                 :            : static const mbedtls_mpi_uint secp192r1_T_6_Y[] = {
+     153                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFD, 0xA6, 0xD4, 0x8C, 0xA9, 0xCE, 0x4D, 0x2E),
+     154                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB9, 0x4B, 0x46, 0xCC, 0xB2, 0x55, 0xC8, 0xB2),
+     155                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3A, 0xAE, 0x31, 0xED, 0x89, 0x65, 0x59, 0x55),
+     156                 :            : };
+     157                 :            : static const mbedtls_mpi_uint secp192r1_T_7_X[] = {
+     158                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCC, 0x0A, 0xD1, 0x1A, 0xC5, 0xF6, 0xEA, 0x43),
+     159                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0C, 0xFC, 0x0C, 0x1A, 0xFB, 0xA0, 0xC8, 0x70),
+     160                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEA, 0xFD, 0x53, 0x6F, 0x6D, 0xBF, 0xBA, 0xAF),
+     161                 :            : };
+     162                 :            : static const mbedtls_mpi_uint secp192r1_T_7_Y[] = {
+     163                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2D, 0xB0, 0x7D, 0x83, 0x96, 0xE3, 0xCB, 0x9D),
+     164                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6F, 0x6E, 0x55, 0x2C, 0x20, 0x53, 0x2F, 0x46),
+     165                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA6, 0x66, 0x00, 0x17, 0x08, 0xFE, 0xAC, 0x31),
+     166                 :            : };
+     167                 :            : static const mbedtls_mpi_uint secp192r1_T_8_X[] = {
+     168                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x09, 0x12, 0x97, 0x3A, 0xC7, 0x57, 0x45, 0xCD),
+     169                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x38, 0x25, 0x99, 0x00, 0xF6, 0x97, 0xB4, 0x64),
+     170                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9B, 0x74, 0xE6, 0xE6, 0xA3, 0xDF, 0x9C, 0xCC),
+     171                 :            : };
+     172                 :            : static const mbedtls_mpi_uint secp192r1_T_8_Y[] = {
+     173                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x32, 0xF4, 0x76, 0xD5, 0x5F, 0x2A, 0xFD, 0x85),
+     174                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x62, 0x80, 0x7E, 0x3E, 0xE5, 0xE8, 0xD6, 0x63),
+     175                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE2, 0xAD, 0x1E, 0x70, 0x79, 0x3E, 0x3D, 0x83),
+     176                 :            : };
+     177                 :            : static const mbedtls_mpi_uint secp192r1_T_9_X[] = {
+     178                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8E, 0x15, 0xBB, 0xB3, 0x42, 0x6A, 0xA1, 0x7C),
+     179                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9B, 0x58, 0xCB, 0x43, 0x25, 0x00, 0x14, 0x68),
+     180                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x06, 0x4E, 0x93, 0x11, 0xE0, 0x32, 0x54, 0x98),
+     181                 :            : };
+     182                 :            : static const mbedtls_mpi_uint secp192r1_T_9_Y[] = {
+     183                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA7, 0x52, 0xA2, 0xB4, 0x57, 0x32, 0xB9, 0x11),
+     184                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7D, 0x43, 0xA1, 0xB1, 0xFB, 0x01, 0xE1, 0xE7),
+     185                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA6, 0xFB, 0x5A, 0x11, 0xB8, 0xC2, 0x03, 0xE5),
+     186                 :            : };
+     187                 :            : static const mbedtls_mpi_uint secp192r1_T_10_X[] = {
+     188                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1C, 0x2B, 0x71, 0x26, 0x4E, 0x7C, 0xC5, 0x32),
+     189                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1F, 0xF5, 0xD3, 0xA8, 0xE4, 0x95, 0x48, 0x65),
+     190                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x55, 0xAE, 0xD9, 0x5D, 0x9F, 0x6A, 0x22, 0xAD),
+     191                 :            : };
+     192                 :            : static const mbedtls_mpi_uint secp192r1_T_10_Y[] = {
+     193                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD9, 0xCC, 0xA3, 0x4D, 0xA0, 0x1C, 0x34, 0xEF),
+     194                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA3, 0x3C, 0x62, 0xF8, 0x5E, 0xA6, 0x58, 0x7D),
+     195                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6D, 0x6E, 0x66, 0x8A, 0x3D, 0x17, 0xFF, 0x0F),
+     196                 :            : };
+     197                 :            : static const mbedtls_mpi_uint secp192r1_T_11_X[] = {
+     198                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF7, 0xCD, 0xA8, 0xDD, 0xD1, 0x20, 0x5C, 0xEA),
+     199                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBF, 0xFE, 0x17, 0xE2, 0xCF, 0xEA, 0x63, 0xDE),
+     200                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x74, 0x51, 0xC9, 0x16, 0xDE, 0xB4, 0xB2, 0xDD),
+     201                 :            : };
+     202                 :            : static const mbedtls_mpi_uint secp192r1_T_11_Y[] = {
+     203                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x59, 0xBE, 0x12, 0xD7, 0xA3, 0x0A, 0x50, 0x33),
+     204                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x53, 0x87, 0xC5, 0x8A, 0x76, 0x57, 0x07, 0x60),
+     205                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE5, 0x1F, 0xC6, 0x1B, 0x66, 0xC4, 0x3D, 0x8A),
+     206                 :            : };
+     207                 :            : static const mbedtls_mpi_uint secp192r1_T_12_X[] = {
+     208                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x28, 0xA4, 0x85, 0x13, 0x8F, 0xA7, 0x35, 0x19),
+     209                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x58, 0x0D, 0xFD, 0xFF, 0x1B, 0xD1, 0xD6, 0xEF),
+     210                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBA, 0x7A, 0xD0, 0xC3, 0xB4, 0xEF, 0x39, 0x66),
+     211                 :            : };
+     212                 :            : static const mbedtls_mpi_uint secp192r1_T_12_Y[] = {
+     213                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3A, 0xFE, 0xA5, 0x9C, 0x34, 0x30, 0x49, 0x40),
+     214                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDE, 0xC5, 0x39, 0x26, 0x06, 0xE3, 0x01, 0x17),
+     215                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE2, 0x2B, 0x66, 0xFC, 0x95, 0x5F, 0x35, 0xF7),
+     216                 :            : };
+     217                 :            : static const mbedtls_mpi_uint secp192r1_T_13_X[] = {
+     218                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x58, 0xCF, 0x54, 0x63, 0x99, 0x57, 0x05, 0x45),
+     219                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x71, 0x6F, 0x00, 0x5F, 0x65, 0x08, 0x47, 0x98),
+     220                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x62, 0x2A, 0x90, 0x6D, 0x67, 0xC6, 0xBC, 0x45),
+     221                 :            : };
+     222                 :            : static const mbedtls_mpi_uint secp192r1_T_13_Y[] = {
+     223                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8A, 0x4D, 0x88, 0x0A, 0x35, 0x9E, 0x33, 0x9C),
+     224                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7C, 0x17, 0x0C, 0xF8, 0xE1, 0x7A, 0x49, 0x02),
+     225                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA4, 0x44, 0x06, 0x8F, 0x0B, 0x70, 0x2F, 0x71),
+     226                 :            : };
+     227                 :            : static const mbedtls_mpi_uint secp192r1_T_14_X[] = {
+     228                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x85, 0x4B, 0xCB, 0xF9, 0x8E, 0x6A, 0xDA, 0x1B),
+     229                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x29, 0x43, 0xA1, 0x3F, 0xCE, 0x17, 0xD2, 0x32),
+     230                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5D, 0x0D, 0xD2, 0x6C, 0x82, 0x37, 0xE5, 0xFC),
+     231                 :            : };
+     232                 :            : static const mbedtls_mpi_uint secp192r1_T_14_Y[] = {
+     233                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4A, 0x3C, 0xF4, 0x92, 0xB4, 0x8A, 0x95, 0x85),
+     234                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x85, 0x96, 0xF1, 0x0A, 0x34, 0x2F, 0x74, 0x7E),
+     235                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7B, 0xA1, 0xAA, 0xBA, 0x86, 0x77, 0x4F, 0xA2),
+     236                 :            : };
+     237                 :            : static const mbedtls_mpi_uint secp192r1_T_15_X[] = {
+     238                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE5, 0x7F, 0xEF, 0x60, 0x50, 0x80, 0xD7, 0xD4),
+     239                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x31, 0xAC, 0xC9, 0xFE, 0xEC, 0x0A, 0x1A, 0x9F),
+     240                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6B, 0x2F, 0xBE, 0x91, 0xD7, 0xB7, 0x38, 0x48),
+     241                 :            : };
+     242                 :            : static const mbedtls_mpi_uint secp192r1_T_15_Y[] = {
+     243                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB1, 0xAE, 0x85, 0x98, 0xFE, 0x05, 0x7F, 0x9F),
+     244                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x91, 0xBE, 0xFD, 0x11, 0x31, 0x3D, 0x14, 0x13),
+     245                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x59, 0x75, 0xE8, 0x30, 0x01, 0xCB, 0x9B, 0x1C),
+     246                 :            : };
+     247                 :            : static const mbedtls_ecp_point secp192r1_T[16] = {
+     248                 :            :     ECP_POINT_INIT_XY_Z1(secp192r1_T_0_X, secp192r1_T_0_Y),
+     249                 :            :     ECP_POINT_INIT_XY_Z0(secp192r1_T_1_X, secp192r1_T_1_Y),
+     250                 :            :     ECP_POINT_INIT_XY_Z0(secp192r1_T_2_X, secp192r1_T_2_Y),
+     251                 :            :     ECP_POINT_INIT_XY_Z0(secp192r1_T_3_X, secp192r1_T_3_Y),
+     252                 :            :     ECP_POINT_INIT_XY_Z0(secp192r1_T_4_X, secp192r1_T_4_Y),
+     253                 :            :     ECP_POINT_INIT_XY_Z0(secp192r1_T_5_X, secp192r1_T_5_Y),
+     254                 :            :     ECP_POINT_INIT_XY_Z0(secp192r1_T_6_X, secp192r1_T_6_Y),
+     255                 :            :     ECP_POINT_INIT_XY_Z0(secp192r1_T_7_X, secp192r1_T_7_Y),
+     256                 :            :     ECP_POINT_INIT_XY_Z0(secp192r1_T_8_X, secp192r1_T_8_Y),
+     257                 :            :     ECP_POINT_INIT_XY_Z0(secp192r1_T_9_X, secp192r1_T_9_Y),
+     258                 :            :     ECP_POINT_INIT_XY_Z0(secp192r1_T_10_X, secp192r1_T_10_Y),
+     259                 :            :     ECP_POINT_INIT_XY_Z0(secp192r1_T_11_X, secp192r1_T_11_Y),
+     260                 :            :     ECP_POINT_INIT_XY_Z0(secp192r1_T_12_X, secp192r1_T_12_Y),
+     261                 :            :     ECP_POINT_INIT_XY_Z0(secp192r1_T_13_X, secp192r1_T_13_Y),
+     262                 :            :     ECP_POINT_INIT_XY_Z0(secp192r1_T_14_X, secp192r1_T_14_Y),
+     263                 :            :     ECP_POINT_INIT_XY_Z0(secp192r1_T_15_X, secp192r1_T_15_Y),
+     264                 :            : };
+     265                 :            : #else
+     266                 :            : #define secp192r1_T NULL
+     267                 :            : #endif
+     268                 :            : #endif /* MBEDTLS_ECP_DP_SECP192R1_ENABLED */
+     269                 :            : 
+     270                 :            : /*
+     271                 :            :  * Domain parameters for secp224r1
+     272                 :            :  */
+     273                 :            : #if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED)
+     274                 :            : static const mbedtls_mpi_uint secp224r1_p[] = {
+     275                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+     276                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF),
+     277                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
+     278                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00),
+     279                 :            : };
+     280                 :            : static const mbedtls_mpi_uint secp224r1_b[] = {
+     281                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB4, 0xFF, 0x55, 0x23, 0x43, 0x39, 0x0B, 0x27),
+     282                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBA, 0xD8, 0xBF, 0xD7, 0xB7, 0xB0, 0x44, 0x50),
+     283                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x56, 0x32, 0x41, 0xF5, 0xAB, 0xB3, 0x04, 0x0C),
+     284                 :            :     MBEDTLS_BYTES_TO_T_UINT_4(0x85, 0x0A, 0x05, 0xB4),
+     285                 :            : };
+     286                 :            : static const mbedtls_mpi_uint secp224r1_gx[] = {
+     287                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x21, 0x1D, 0x5C, 0x11, 0xD6, 0x80, 0x32, 0x34),
+     288                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x22, 0x11, 0xC2, 0x56, 0xD3, 0xC1, 0x03, 0x4A),
+     289                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB9, 0x90, 0x13, 0x32, 0x7F, 0xBF, 0xB4, 0x6B),
+     290                 :            :     MBEDTLS_BYTES_TO_T_UINT_4(0xBD, 0x0C, 0x0E, 0xB7),
+     291                 :            : };
+     292                 :            : static const mbedtls_mpi_uint secp224r1_gy[] = {
+     293                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x34, 0x7E, 0x00, 0x85, 0x99, 0x81, 0xD5, 0x44),
+     294                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x64, 0x47, 0x07, 0x5A, 0xA0, 0x75, 0x43, 0xCD),
+     295                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE6, 0xDF, 0x22, 0x4C, 0xFB, 0x23, 0xF7, 0xB5),
+     296                 :            :     MBEDTLS_BYTES_TO_T_UINT_4(0x88, 0x63, 0x37, 0xBD),
+     297                 :            : };
+     298                 :            : static const mbedtls_mpi_uint secp224r1_n[] = {
+     299                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3D, 0x2A, 0x5C, 0x5C, 0x45, 0x29, 0xDD, 0x13),
+     300                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3E, 0xF0, 0xB8, 0xE0, 0xA2, 0x16, 0xFF, 0xFF),
+     301                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
+     302                 :            :     MBEDTLS_BYTES_TO_T_UINT_4(0xFF, 0xFF, 0xFF, 0xFF),
+     303                 :            : };
+     304                 :            : #if MBEDTLS_ECP_FIXED_POINT_OPTIM == 1
+     305                 :            : static const mbedtls_mpi_uint secp224r1_T_0_X[] = {
+     306                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x21, 0x1D, 0x5C, 0x11, 0xD6, 0x80, 0x32, 0x34),
+     307                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x22, 0x11, 0xC2, 0x56, 0xD3, 0xC1, 0x03, 0x4A),
+     308                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB9, 0x90, 0x13, 0x32, 0x7F, 0xBF, 0xB4, 0x6B),
+     309                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBD, 0x0C, 0x0E, 0xB7, 0x00, 0x00, 0x00, 0x00),
+     310                 :            : };
+     311                 :            : static const mbedtls_mpi_uint secp224r1_T_0_Y[] = {
+     312                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x34, 0x7E, 0x00, 0x85, 0x99, 0x81, 0xD5, 0x44),
+     313                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x64, 0x47, 0x07, 0x5A, 0xA0, 0x75, 0x43, 0xCD),
+     314                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE6, 0xDF, 0x22, 0x4C, 0xFB, 0x23, 0xF7, 0xB5),
+     315                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x88, 0x63, 0x37, 0xBD, 0x00, 0x00, 0x00, 0x00),
+     316                 :            : };
+     317                 :            : static const mbedtls_mpi_uint secp224r1_T_1_X[] = {
+     318                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE0, 0xF9, 0xB8, 0xD0, 0x3D, 0xD2, 0xD3, 0xFA),
+     319                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1E, 0xFD, 0x99, 0x26, 0x19, 0xFE, 0x13, 0x6E),
+     320                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1C, 0x0E, 0x4C, 0x48, 0x7C, 0xA2, 0x17, 0x01),
+     321                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3D, 0xA3, 0x13, 0x57, 0x00, 0x00, 0x00, 0x00),
+     322                 :            : };
+     323                 :            : static const mbedtls_mpi_uint secp224r1_T_1_Y[] = {
+     324                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9F, 0x16, 0x5C, 0x8F, 0xAA, 0xED, 0x0F, 0x58),
+     325                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBF, 0xC5, 0x43, 0x34, 0x93, 0x05, 0x2A, 0x4C),
+     326                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE4, 0xE3, 0x6C, 0xCA, 0xC6, 0x14, 0xC2, 0x25),
+     327                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD3, 0x43, 0x6C, 0xD7, 0x00, 0x00, 0x00, 0x00),
+     328                 :            : };
+     329                 :            : static const mbedtls_mpi_uint secp224r1_T_2_X[] = {
+     330                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC3, 0x5A, 0x98, 0x1E, 0xC8, 0xA5, 0x42, 0xA3),
+     331                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x98, 0x49, 0x56, 0x78, 0xF8, 0xEF, 0xED, 0x65),
+     332                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1B, 0xBB, 0x64, 0xB6, 0x4C, 0x54, 0x5F, 0xD1),
+     333                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2F, 0x0C, 0x33, 0xCC, 0x00, 0x00, 0x00, 0x00),
+     334                 :            : };
+     335                 :            : static const mbedtls_mpi_uint secp224r1_T_2_Y[] = {
+     336                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFA, 0x79, 0xCB, 0x2E, 0x08, 0xFF, 0xD8, 0xE6),
+     337                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2E, 0x1F, 0xD4, 0xD7, 0x57, 0xE9, 0x39, 0x45),
+     338                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD8, 0xD6, 0x3B, 0x0A, 0x1C, 0x87, 0xB7, 0x6A),
+     339                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEB, 0x30, 0xD8, 0x05, 0x00, 0x00, 0x00, 0x00),
+     340                 :            : };
+     341                 :            : static const mbedtls_mpi_uint secp224r1_T_3_X[] = {
+     342                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAD, 0x79, 0x74, 0x9A, 0xE6, 0xBB, 0xC2, 0xC2),
+     343                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB4, 0x5B, 0xA6, 0x67, 0xC1, 0x91, 0xE7, 0x64),
+     344                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF0, 0xDF, 0x38, 0x82, 0x19, 0x2C, 0x4C, 0xCA),
+     345                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD1, 0x2E, 0x39, 0xC5, 0x00, 0x00, 0x00, 0x00),
+     346                 :            : };
+     347                 :            : static const mbedtls_mpi_uint secp224r1_T_3_Y[] = {
+     348                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x99, 0x36, 0x78, 0x4E, 0xAE, 0x5B, 0x02, 0x76),
+     349                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x14, 0xF6, 0x8B, 0xF8, 0xF4, 0x92, 0x6B, 0x42),
+     350                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBA, 0x4D, 0x71, 0x35, 0xE7, 0x0C, 0x2C, 0x98),
+     351                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9B, 0xA5, 0x1F, 0xAE, 0x00, 0x00, 0x00, 0x00),
+     352                 :            : };
+     353                 :            : static const mbedtls_mpi_uint secp224r1_T_4_X[] = {
+     354                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAF, 0x1C, 0x4B, 0xDF, 0x5B, 0xF2, 0x51, 0xB7),
+     355                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x05, 0x74, 0xB1, 0x5A, 0xC6, 0x0F, 0x0E, 0x61),
+     356                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE8, 0x24, 0x09, 0x62, 0xAF, 0xFC, 0xDB, 0x45),
+     357                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x43, 0xE1, 0x80, 0x55, 0x00, 0x00, 0x00, 0x00),
+     358                 :            : };
+     359                 :            : static const mbedtls_mpi_uint secp224r1_T_4_Y[] = {
+     360                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3C, 0x82, 0xFE, 0xAD, 0xC3, 0xE5, 0xCF, 0xD8),
+     361                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x24, 0xA2, 0x62, 0x17, 0x76, 0xF0, 0x5A, 0xFA),
+     362                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3E, 0xB8, 0xE5, 0xAC, 0xB7, 0x66, 0x38, 0xAA),
+     363                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x97, 0xFD, 0x86, 0x05, 0x00, 0x00, 0x00, 0x00),
+     364                 :            : };
+     365                 :            : static const mbedtls_mpi_uint secp224r1_T_5_X[] = {
+     366                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x59, 0xD3, 0x0C, 0x3C, 0xD1, 0x66, 0xB0, 0xF1),
+     367                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBC, 0x59, 0xB4, 0x8D, 0x90, 0x10, 0xB7, 0xA2),
+     368                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x96, 0x47, 0x9B, 0xE6, 0x55, 0x8A, 0xE4, 0xEE),
+     369                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB1, 0x49, 0xDB, 0x78, 0x00, 0x00, 0x00, 0x00),
+     370                 :            : };
+     371                 :            : static const mbedtls_mpi_uint secp224r1_T_5_Y[] = {
+     372                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x41, 0x97, 0xED, 0xDE, 0xFF, 0xB3, 0xDF, 0x48),
+     373                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x10, 0xB9, 0x83, 0xB7, 0xEB, 0xBE, 0x40, 0x8D),
+     374                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAF, 0xD3, 0xD3, 0xCD, 0x0E, 0x82, 0x79, 0x3D),
+     375                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9B, 0x83, 0x1B, 0xF0, 0x00, 0x00, 0x00, 0x00),
+     376                 :            : };
+     377                 :            : static const mbedtls_mpi_uint secp224r1_T_6_X[] = {
+     378                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3F, 0x22, 0xBB, 0x54, 0xD3, 0x31, 0x56, 0xFC),
+     379                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x80, 0x36, 0xE5, 0xE0, 0x89, 0x96, 0x8E, 0x71),
+     380                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE1, 0xEF, 0x0A, 0xED, 0xD0, 0x11, 0x4A, 0xFF),
+     381                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x15, 0x00, 0x57, 0x27, 0x00, 0x00, 0x00, 0x00),
+     382                 :            : };
+     383                 :            : static const mbedtls_mpi_uint secp224r1_T_6_Y[] = {
+     384                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x13, 0xCA, 0x3D, 0xF7, 0x64, 0x9B, 0x6E, 0x85),
+     385                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x90, 0xE3, 0x70, 0x6B, 0x41, 0xD7, 0xED, 0x8F),
+     386                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x02, 0x44, 0x44, 0x80, 0xCE, 0x13, 0x37, 0x92),
+     387                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x94, 0x73, 0x80, 0x79, 0x00, 0x00, 0x00, 0x00),
+     388                 :            : };
+     389                 :            : static const mbedtls_mpi_uint secp224r1_T_7_X[] = {
+     390                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB7, 0x4D, 0x70, 0x7D, 0x31, 0x0F, 0x1C, 0x58),
+     391                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6D, 0x35, 0x88, 0x47, 0xC4, 0x24, 0x78, 0x3F),
+     392                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBA, 0xF0, 0xCD, 0x91, 0x81, 0xB3, 0xDE, 0xB6),
+     393                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x04, 0xCE, 0xC6, 0xF7, 0x00, 0x00, 0x00, 0x00),
+     394                 :            : };
+     395                 :            : static const mbedtls_mpi_uint secp224r1_T_7_Y[] = {
+     396                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE9, 0x9C, 0x2D, 0xE8, 0xD2, 0x00, 0x8F, 0x10),
+     397                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD5, 0x5E, 0x7C, 0x0E, 0x0C, 0x6E, 0x58, 0x02),
+     398                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAE, 0x81, 0x21, 0xCE, 0x43, 0xF4, 0x24, 0x3D),
+     399                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9E, 0xBC, 0xF0, 0xF4, 0x00, 0x00, 0x00, 0x00),
+     400                 :            : };
+     401                 :            : static const mbedtls_mpi_uint secp224r1_T_8_X[] = {
+     402                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD6, 0x10, 0xC2, 0x74, 0x4A, 0x8F, 0x8A, 0xCF),
+     403                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x89, 0x67, 0xF4, 0x2B, 0x38, 0x2B, 0x35, 0x17),
+     404                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF5, 0xE7, 0x0C, 0xA9, 0xFA, 0x77, 0x5C, 0xBD),
+     405                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE0, 0x33, 0x19, 0x2B, 0x00, 0x00, 0x00, 0x00),
+     406                 :            : };
+     407                 :            : static const mbedtls_mpi_uint secp224r1_T_8_Y[] = {
+     408                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE7, 0x3E, 0x96, 0x22, 0x53, 0xE1, 0xE9, 0xBE),
+     409                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE0, 0x13, 0xBC, 0xA1, 0x16, 0xEC, 0x01, 0x1A),
+     410                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9A, 0x00, 0xC9, 0x7A, 0xC3, 0x73, 0xA5, 0x45),
+     411                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE1, 0xF4, 0x5E, 0xC1, 0x00, 0x00, 0x00, 0x00),
+     412                 :            : };
+     413                 :            : static const mbedtls_mpi_uint secp224r1_T_9_X[] = {
+     414                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA8, 0x95, 0xD6, 0xD9, 0x32, 0x30, 0x2B, 0xD0),
+     415                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x77, 0x42, 0x09, 0x05, 0x61, 0x2A, 0x7E, 0x82),
+     416                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x73, 0x84, 0xA2, 0x05, 0x88, 0x64, 0x65, 0xF9),
+     417                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x03, 0x2D, 0x90, 0xB3, 0x00, 0x00, 0x00, 0x00),
+     418                 :            : };
+     419                 :            : static const mbedtls_mpi_uint secp224r1_T_9_Y[] = {
+     420                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0A, 0xE7, 0x2E, 0x85, 0x55, 0x80, 0x7C, 0x79),
+     421                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0F, 0xC1, 0xAC, 0x78, 0xB4, 0xAF, 0xFB, 0x6E),
+     422                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD3, 0xC3, 0x28, 0x8E, 0x79, 0x18, 0x1F, 0x58),
+     423                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x34, 0x46, 0xCF, 0x49, 0x00, 0x00, 0x00, 0x00),
+     424                 :            : };
+     425                 :            : static const mbedtls_mpi_uint secp224r1_T_10_X[] = {
+     426                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x63, 0x5F, 0xA8, 0x6C, 0x46, 0x83, 0x43, 0xFA),
+     427                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFA, 0xA9, 0x93, 0x11, 0xB6, 0x07, 0x57, 0x74),
+     428                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x77, 0x2A, 0x9D, 0x03, 0x89, 0x7E, 0xD7, 0x3C),
+     429                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7B, 0x8C, 0x62, 0xCF, 0x00, 0x00, 0x00, 0x00),
+     430                 :            : };
+     431                 :            : static const mbedtls_mpi_uint secp224r1_T_10_Y[] = {
+     432                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x44, 0x2C, 0x13, 0x59, 0xCC, 0xFA, 0x84, 0x9E),
+     433                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x51, 0xB9, 0x48, 0xBC, 0x57, 0xC7, 0xB3, 0x7C),
+     434                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFC, 0x0A, 0x38, 0x24, 0x2E, 0x3A, 0x28, 0x25),
+     435                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBC, 0x0A, 0x43, 0xB8, 0x00, 0x00, 0x00, 0x00),
+     436                 :            : };
+     437                 :            : static const mbedtls_mpi_uint secp224r1_T_11_X[] = {
+     438                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x59, 0x25, 0xAB, 0xC1, 0xEE, 0x70, 0x3C, 0xE1),
+     439                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF3, 0xDB, 0x45, 0x1D, 0x4A, 0x80, 0x75, 0x35),
+     440                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE8, 0x1F, 0x4D, 0x2D, 0x9A, 0x05, 0xF4, 0xCB),
+     441                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6B, 0x10, 0xF0, 0x5A, 0x00, 0x00, 0x00, 0x00),
+     442                 :            : };
+     443                 :            : static const mbedtls_mpi_uint secp224r1_T_11_Y[] = {
+     444                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x35, 0x95, 0xE1, 0xDC, 0x15, 0x86, 0xC3, 0x7B),
+     445                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEC, 0xDC, 0x27, 0xD1, 0x56, 0xA1, 0x14, 0x0D),
+     446                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x59, 0x0B, 0xD6, 0x77, 0x4E, 0x44, 0xA2, 0xF8),
+     447                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x94, 0x42, 0x71, 0x1F, 0x00, 0x00, 0x00, 0x00),
+     448                 :            : };
+     449                 :            : static const mbedtls_mpi_uint secp224r1_T_12_X[] = {
+     450                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x30, 0x86, 0xB2, 0xB0, 0xC8, 0x2F, 0x7B, 0xFE),
+     451                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x96, 0xEF, 0xCB, 0xDB, 0xBC, 0x9E, 0x3B, 0xC5),
+     452                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1B, 0x03, 0x86, 0xDD, 0x5B, 0xF5, 0x8D, 0x46),
+     453                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x58, 0x95, 0x79, 0xD6, 0x00, 0x00, 0x00, 0x00),
+     454                 :            : };
+     455                 :            : static const mbedtls_mpi_uint secp224r1_T_12_Y[] = {
+     456                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x84, 0x32, 0x14, 0xDA, 0x9B, 0x4F, 0x07, 0x39),
+     457                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB5, 0x3E, 0xFB, 0x06, 0xEE, 0xA7, 0x40, 0x40),
+     458                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x76, 0x1F, 0xDF, 0x71, 0x61, 0xFD, 0x8B, 0xBE),
+     459                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x80, 0x8B, 0xAB, 0x8B, 0x00, 0x00, 0x00, 0x00),
+     460                 :            : };
+     461                 :            : static const mbedtls_mpi_uint secp224r1_T_13_X[] = {
+     462                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC9, 0x34, 0xB3, 0xB4, 0xBC, 0x9F, 0xB0, 0x5E),
+     463                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE6, 0x58, 0x48, 0xA8, 0x77, 0xBB, 0x13, 0x2F),
+     464                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x41, 0xC6, 0xF7, 0x34, 0xCC, 0x89, 0x21, 0x0A),
+     465                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCA, 0x33, 0xDD, 0x1F, 0x00, 0x00, 0x00, 0x00),
+     466                 :            : };
+     467                 :            : static const mbedtls_mpi_uint secp224r1_T_13_Y[] = {
+     468                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCC, 0x81, 0xEF, 0xA4, 0xF2, 0x10, 0x0B, 0xCD),
+     469                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x83, 0xF7, 0x6E, 0x72, 0x4A, 0xDF, 0xDD, 0xE8),
+     470                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x67, 0x23, 0x0A, 0x53, 0x03, 0x16, 0x62, 0xD2),
+     471                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0B, 0x76, 0xFD, 0x3C, 0x00, 0x00, 0x00, 0x00),
+     472                 :            : };
+     473                 :            : static const mbedtls_mpi_uint secp224r1_T_14_X[] = {
+     474                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCB, 0x14, 0xA1, 0xFA, 0xA0, 0x18, 0xBE, 0x07),
+     475                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x03, 0x2A, 0xE1, 0xD7, 0xB0, 0x6C, 0xA0, 0xDE),
+     476                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD1, 0xC0, 0xB0, 0xC6, 0x63, 0x24, 0xCD, 0x4E),
+     477                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x33, 0x38, 0x2C, 0xB1, 0x00, 0x00, 0x00, 0x00),
+     478                 :            : };
+     479                 :            : static const mbedtls_mpi_uint secp224r1_T_14_Y[] = {
+     480                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEE, 0xCD, 0x7D, 0x20, 0x0C, 0xFE, 0xAC, 0xC3),
+     481                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x09, 0x97, 0x9F, 0xA2, 0xB6, 0x45, 0xF7, 0x7B),
+     482                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCA, 0x99, 0xF3, 0xD2, 0x20, 0x02, 0xEB, 0x04),
+     483                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x43, 0x18, 0x5B, 0x7B, 0x00, 0x00, 0x00, 0x00),
+     484                 :            : };
+     485                 :            : static const mbedtls_mpi_uint secp224r1_T_15_X[] = {
+     486                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2B, 0xDD, 0x77, 0x91, 0x60, 0xEA, 0xFD, 0xD3),
+     487                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7D, 0xD3, 0xB5, 0xD6, 0x90, 0x17, 0x0E, 0x1A),
+     488                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x00, 0xF4, 0x28, 0xC1, 0xF2, 0x53, 0xF6, 0x63),
+     489                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x49, 0x58, 0xDC, 0x61, 0x00, 0x00, 0x00, 0x00),
+     490                 :            : };
+     491                 :            : static const mbedtls_mpi_uint secp224r1_T_15_Y[] = {
+     492                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA8, 0x20, 0x01, 0xFB, 0xF1, 0xBD, 0x5F, 0x45),
+     493                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD0, 0x7F, 0x06, 0xDA, 0x11, 0xCB, 0xBA, 0xA6),
+     494                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA7, 0x41, 0x00, 0xA4, 0x1B, 0x30, 0x33, 0x79),
+     495                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF4, 0xFF, 0x27, 0xCA, 0x00, 0x00, 0x00, 0x00),
+     496                 :            : };
+     497                 :            : static const mbedtls_ecp_point secp224r1_T[16] = {
+     498                 :            :     ECP_POINT_INIT_XY_Z1(secp224r1_T_0_X, secp224r1_T_0_Y),
+     499                 :            :     ECP_POINT_INIT_XY_Z0(secp224r1_T_1_X, secp224r1_T_1_Y),
+     500                 :            :     ECP_POINT_INIT_XY_Z0(secp224r1_T_2_X, secp224r1_T_2_Y),
+     501                 :            :     ECP_POINT_INIT_XY_Z0(secp224r1_T_3_X, secp224r1_T_3_Y),
+     502                 :            :     ECP_POINT_INIT_XY_Z0(secp224r1_T_4_X, secp224r1_T_4_Y),
+     503                 :            :     ECP_POINT_INIT_XY_Z0(secp224r1_T_5_X, secp224r1_T_5_Y),
+     504                 :            :     ECP_POINT_INIT_XY_Z0(secp224r1_T_6_X, secp224r1_T_6_Y),
+     505                 :            :     ECP_POINT_INIT_XY_Z0(secp224r1_T_7_X, secp224r1_T_7_Y),
+     506                 :            :     ECP_POINT_INIT_XY_Z0(secp224r1_T_8_X, secp224r1_T_8_Y),
+     507                 :            :     ECP_POINT_INIT_XY_Z0(secp224r1_T_9_X, secp224r1_T_9_Y),
+     508                 :            :     ECP_POINT_INIT_XY_Z0(secp224r1_T_10_X, secp224r1_T_10_Y),
+     509                 :            :     ECP_POINT_INIT_XY_Z0(secp224r1_T_11_X, secp224r1_T_11_Y),
+     510                 :            :     ECP_POINT_INIT_XY_Z0(secp224r1_T_12_X, secp224r1_T_12_Y),
+     511                 :            :     ECP_POINT_INIT_XY_Z0(secp224r1_T_13_X, secp224r1_T_13_Y),
+     512                 :            :     ECP_POINT_INIT_XY_Z0(secp224r1_T_14_X, secp224r1_T_14_Y),
+     513                 :            :     ECP_POINT_INIT_XY_Z0(secp224r1_T_15_X, secp224r1_T_15_Y),
+     514                 :            : };
+     515                 :            : #else
+     516                 :            : #define secp224r1_T NULL
+     517                 :            : #endif
+     518                 :            : #endif /* MBEDTLS_ECP_DP_SECP224R1_ENABLED */
+     519                 :            : 
+     520                 :            : /*
+     521                 :            :  * Domain parameters for secp256r1
+     522                 :            :  */
+     523                 :            : #if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED)
+     524                 :            : static const mbedtls_mpi_uint secp256r1_p[] = {
+     525                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
+     526                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00),
+     527                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+     528                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x01, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF),
+     529                 :            : };
+     530                 :            : static const mbedtls_mpi_uint secp256r1_b[] = {
+     531                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4B, 0x60, 0xD2, 0x27, 0x3E, 0x3C, 0xCE, 0x3B),
+     532                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF6, 0xB0, 0x53, 0xCC, 0xB0, 0x06, 0x1D, 0x65),
+     533                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBC, 0x86, 0x98, 0x76, 0x55, 0xBD, 0xEB, 0xB3),
+     534                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE7, 0x93, 0x3A, 0xAA, 0xD8, 0x35, 0xC6, 0x5A),
+     535                 :            : };
+     536                 :            : static const mbedtls_mpi_uint secp256r1_gx[] = {
+     537                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x96, 0xC2, 0x98, 0xD8, 0x45, 0x39, 0xA1, 0xF4),
+     538                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA0, 0x33, 0xEB, 0x2D, 0x81, 0x7D, 0x03, 0x77),
+     539                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF2, 0x40, 0xA4, 0x63, 0xE5, 0xE6, 0xBC, 0xF8),
+     540                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x47, 0x42, 0x2C, 0xE1, 0xF2, 0xD1, 0x17, 0x6B),
+     541                 :            : };
+     542                 :            : static const mbedtls_mpi_uint secp256r1_gy[] = {
+     543                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF5, 0x51, 0xBF, 0x37, 0x68, 0x40, 0xB6, 0xCB),
+     544                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCE, 0x5E, 0x31, 0x6B, 0x57, 0x33, 0xCE, 0x2B),
+     545                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x16, 0x9E, 0x0F, 0x7C, 0x4A, 0xEB, 0xE7, 0x8E),
+     546                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9B, 0x7F, 0x1A, 0xFE, 0xE2, 0x42, 0xE3, 0x4F),
+     547                 :            : };
+     548                 :            : static const mbedtls_mpi_uint secp256r1_n[] = {
+     549                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x51, 0x25, 0x63, 0xFC, 0xC2, 0xCA, 0xB9, 0xF3),
+     550                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x84, 0x9E, 0x17, 0xA7, 0xAD, 0xFA, 0xE6, 0xBC),
+     551                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
+     552                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF),
+     553                 :            : };
+     554                 :            : #if MBEDTLS_ECP_FIXED_POINT_OPTIM == 1
+     555                 :            : static const mbedtls_mpi_uint secp256r1_T_0_X[] = {
+     556                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x96, 0xC2, 0x98, 0xD8, 0x45, 0x39, 0xA1, 0xF4),
+     557                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA0, 0x33, 0xEB, 0x2D, 0x81, 0x7D, 0x03, 0x77),
+     558                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF2, 0x40, 0xA4, 0x63, 0xE5, 0xE6, 0xBC, 0xF8),
+     559                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x47, 0x42, 0x2C, 0xE1, 0xF2, 0xD1, 0x17, 0x6B),
+     560                 :            : };
+     561                 :            : static const mbedtls_mpi_uint secp256r1_T_0_Y[] = {
+     562                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF5, 0x51, 0xBF, 0x37, 0x68, 0x40, 0xB6, 0xCB),
+     563                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCE, 0x5E, 0x31, 0x6B, 0x57, 0x33, 0xCE, 0x2B),
+     564                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x16, 0x9E, 0x0F, 0x7C, 0x4A, 0xEB, 0xE7, 0x8E),
+     565                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9B, 0x7F, 0x1A, 0xFE, 0xE2, 0x42, 0xE3, 0x4F),
+     566                 :            : };
+     567                 :            : static const mbedtls_mpi_uint secp256r1_T_1_X[] = {
+     568                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x70, 0xC8, 0xBA, 0x04, 0xB7, 0x4B, 0xD2, 0xF7),
+     569                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAB, 0xC6, 0x23, 0x3A, 0xA0, 0x09, 0x3A, 0x59),
+     570                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1D, 0x9D, 0x4C, 0xF9, 0x58, 0x23, 0xCC, 0xDF),
+     571                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x02, 0xED, 0x7B, 0x29, 0x87, 0x0F, 0xFA, 0x3C),
+     572                 :            : };
+     573                 :            : static const mbedtls_mpi_uint secp256r1_T_1_Y[] = {
+     574                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x40, 0x69, 0xF2, 0x40, 0x0B, 0xA3, 0x98, 0xCE),
+     575                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAF, 0xA8, 0x48, 0x02, 0x0D, 0x1C, 0x12, 0x62),
+     576                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9B, 0xAF, 0x09, 0x83, 0x80, 0xAA, 0x58, 0xA7),
+     577                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC6, 0x12, 0xBE, 0x70, 0x94, 0x76, 0xE3, 0xE4),
+     578                 :            : };
+     579                 :            : static const mbedtls_mpi_uint secp256r1_T_2_X[] = {
+     580                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7D, 0x7D, 0xEF, 0x86, 0xFF, 0xE3, 0x37, 0xDD),
+     581                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDB, 0x86, 0x8B, 0x08, 0x27, 0x7C, 0xD7, 0xF6),
+     582                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x91, 0x54, 0x4C, 0x25, 0x4F, 0x9A, 0xFE, 0x28),
+     583                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5E, 0xFD, 0xF0, 0x6D, 0x37, 0x03, 0x69, 0xD6),
+     584                 :            : };
+     585                 :            : static const mbedtls_mpi_uint secp256r1_T_2_Y[] = {
+     586                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x96, 0xD5, 0xDA, 0xAD, 0x92, 0x49, 0xF0, 0x9F),
+     587                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF9, 0x73, 0x43, 0x9E, 0xAF, 0xA7, 0xD1, 0xF3),
+     588                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x67, 0x41, 0x07, 0xDF, 0x78, 0x95, 0x3E, 0xA1),
+     589                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x22, 0x3D, 0xD1, 0xE6, 0x3C, 0xA5, 0xE2, 0x20),
+     590                 :            : };
+     591                 :            : static const mbedtls_mpi_uint secp256r1_T_3_X[] = {
+     592                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBF, 0x6A, 0x5D, 0x52, 0x35, 0xD7, 0xBF, 0xAE),
+     593                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5A, 0xA2, 0xBE, 0x96, 0xF4, 0xF8, 0x02, 0xC3),
+     594                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA4, 0x20, 0x49, 0x54, 0xEA, 0xB3, 0x82, 0xDB),
+     595                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2E, 0xDB, 0xEA, 0x02, 0xD1, 0x75, 0x1C, 0x62),
+     596                 :            : };
+     597                 :            : static const mbedtls_mpi_uint secp256r1_T_3_Y[] = {
+     598                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF0, 0x85, 0xF4, 0x9E, 0x4C, 0xDC, 0x39, 0x89),
+     599                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x63, 0x6D, 0xC4, 0x57, 0xD8, 0x03, 0x5D, 0x22),
+     600                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x70, 0x7F, 0x2D, 0x52, 0x6F, 0xC9, 0xDA, 0x4F),
+     601                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9D, 0x64, 0xFA, 0xB4, 0xFE, 0xA4, 0xC4, 0xD7),
+     602                 :            : };
+     603                 :            : static const mbedtls_mpi_uint secp256r1_T_4_X[] = {
+     604                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2A, 0x37, 0xB9, 0xC0, 0xAA, 0x59, 0xC6, 0x8B),
+     605                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3F, 0x58, 0xD9, 0xED, 0x58, 0x99, 0x65, 0xF7),
+     606                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x88, 0x7D, 0x26, 0x8C, 0x4A, 0xF9, 0x05, 0x9F),
+     607                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9D, 0x73, 0x9A, 0xC9, 0xE7, 0x46, 0xDC, 0x00),
+     608                 :            : };
+     609                 :            : static const mbedtls_mpi_uint secp256r1_T_4_Y[] = {
+     610                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF2, 0xD0, 0x55, 0xDF, 0x00, 0x0A, 0xF5, 0x4A),
+     611                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6A, 0xBF, 0x56, 0x81, 0x2D, 0x20, 0xEB, 0xB5),
+     612                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x11, 0xC1, 0x28, 0x52, 0xAB, 0xE3, 0xD1, 0x40),
+     613                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x24, 0x34, 0x79, 0x45, 0x57, 0xA5, 0x12, 0x03),
+     614                 :            : };
+     615                 :            : static const mbedtls_mpi_uint secp256r1_T_5_X[] = {
+     616                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEE, 0xCF, 0xB8, 0x7E, 0xF7, 0x92, 0x96, 0x8D),
+     617                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3D, 0x01, 0x8C, 0x0D, 0x23, 0xF2, 0xE3, 0x05),
+     618                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x59, 0x2E, 0xE3, 0x84, 0x52, 0x7A, 0x34, 0x76),
+     619                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE5, 0xA1, 0xB0, 0x15, 0x90, 0xE2, 0x53, 0x3C),
+     620                 :            : };
+     621                 :            : static const mbedtls_mpi_uint secp256r1_T_5_Y[] = {
+     622                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD4, 0x98, 0xE7, 0xFA, 0xA5, 0x7D, 0x8B, 0x53),
+     623                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x91, 0x35, 0xD2, 0x00, 0xD1, 0x1B, 0x9F, 0x1B),
+     624                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3F, 0x69, 0x08, 0x9A, 0x72, 0xF0, 0xA9, 0x11),
+     625                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB3, 0xFE, 0x0E, 0x14, 0xDA, 0x7C, 0x0E, 0xD3),
+     626                 :            : };
+     627                 :            : static const mbedtls_mpi_uint secp256r1_T_6_X[] = {
+     628                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x83, 0xF6, 0xE8, 0xF8, 0x87, 0xF7, 0xFC, 0x6D),
+     629                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x90, 0xBE, 0x7F, 0x3F, 0x7A, 0x2B, 0xD7, 0x13),
+     630                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCF, 0x32, 0xF2, 0x2D, 0x94, 0x6D, 0x42, 0xFD),
+     631                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAD, 0x9A, 0xE3, 0x5F, 0x42, 0xBB, 0x84, 0xED),
+     632                 :            : };
+     633                 :            : static const mbedtls_mpi_uint secp256r1_T_6_Y[] = {
+     634                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFC, 0x95, 0x29, 0x73, 0xA1, 0x67, 0x3E, 0x02),
+     635                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE3, 0x30, 0x54, 0x35, 0x8E, 0x0A, 0xDD, 0x67),
+     636                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x03, 0xD7, 0xA1, 0x97, 0x61, 0x3B, 0xF8, 0x0C),
+     637                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF2, 0x33, 0x3C, 0x58, 0x55, 0x34, 0x23, 0xA3),
+     638                 :            : };
+     639                 :            : static const mbedtls_mpi_uint secp256r1_T_7_X[] = {
+     640                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x99, 0x5D, 0x16, 0x5F, 0x7B, 0xBC, 0xBB, 0xCE),
+     641                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x61, 0xEE, 0x4E, 0x8A, 0xC1, 0x51, 0xCC, 0x50),
+     642                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1F, 0x0D, 0x4D, 0x1B, 0x53, 0x23, 0x1D, 0xB3),
+     643                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDA, 0x2A, 0x38, 0x66, 0x52, 0x84, 0xE1, 0x95),
+     644                 :            : };
+     645                 :            : static const mbedtls_mpi_uint secp256r1_T_7_Y[] = {
+     646                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5B, 0x9B, 0x83, 0x0A, 0x81, 0x4F, 0xAD, 0xAC),
+     647                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0F, 0xFF, 0x42, 0x41, 0x6E, 0xA9, 0xA2, 0xA0),
+     648                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2F, 0xA1, 0x4F, 0x1F, 0x89, 0x82, 0xAA, 0x3E),
+     649                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF3, 0xB8, 0x0F, 0x6B, 0x8F, 0x8C, 0xD6, 0x68),
+     650                 :            : };
+     651                 :            : static const mbedtls_mpi_uint secp256r1_T_8_X[] = {
+     652                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF1, 0xB3, 0xBB, 0x51, 0x69, 0xA2, 0x11, 0x93),
+     653                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x65, 0x4F, 0x0F, 0x8D, 0xBD, 0x26, 0x0F, 0xE8),
+     654                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB9, 0xCB, 0xEC, 0x6B, 0x34, 0xC3, 0x3D, 0x9D),
+     655                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE4, 0x5D, 0x1E, 0x10, 0xD5, 0x44, 0xE2, 0x54),
+     656                 :            : };
+     657                 :            : static const mbedtls_mpi_uint secp256r1_T_8_Y[] = {
+     658                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x28, 0x9E, 0xB1, 0xF1, 0x6E, 0x4C, 0xAD, 0xB3),
+     659                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB7, 0xE3, 0xC2, 0x58, 0xC0, 0xFB, 0x34, 0x43),
+     660                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x25, 0x9C, 0xDF, 0x35, 0x07, 0x41, 0xBD, 0x19),
+     661                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB6, 0x6E, 0x10, 0xEC, 0x0E, 0xEC, 0xBB, 0xD6),
+     662                 :            : };
+     663                 :            : static const mbedtls_mpi_uint secp256r1_T_9_X[] = {
+     664                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC8, 0xCF, 0xEF, 0x3F, 0x83, 0x1A, 0x88, 0xE8),
+     665                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0B, 0x29, 0xB5, 0xB9, 0xE0, 0xC9, 0xA3, 0xAE),
+     666                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x88, 0x46, 0x1E, 0x77, 0xCD, 0x7E, 0xB3, 0x10),
+     667                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB6, 0x21, 0xD0, 0xD4, 0xA3, 0x16, 0x08, 0xEE),
+     668                 :            : };
+     669                 :            : static const mbedtls_mpi_uint secp256r1_T_9_Y[] = {
+     670                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA1, 0xCA, 0xA8, 0xB3, 0xBF, 0x29, 0x99, 0x8E),
+     671                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD1, 0xF2, 0x05, 0xC1, 0xCF, 0x5D, 0x91, 0x48),
+     672                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9F, 0x01, 0x49, 0xDB, 0x82, 0xDF, 0x5F, 0x3A),
+     673                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE1, 0x06, 0x90, 0xAD, 0xE3, 0x38, 0xA4, 0xC4),
+     674                 :            : };
+     675                 :            : static const mbedtls_mpi_uint secp256r1_T_10_X[] = {
+     676                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC9, 0xD2, 0x3A, 0xE8, 0x03, 0xC5, 0x6D, 0x5D),
+     677                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBE, 0x35, 0xD0, 0xAE, 0x1D, 0x7A, 0x9F, 0xCA),
+     678                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x33, 0x1E, 0xD2, 0xCB, 0xAC, 0x88, 0x27, 0x55),
+     679                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF0, 0xB9, 0x9C, 0xE0, 0x31, 0xDD, 0x99, 0x86),
+     680                 :            : };
+     681                 :            : static const mbedtls_mpi_uint secp256r1_T_10_Y[] = {
+     682                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x61, 0xF9, 0x9B, 0x32, 0x96, 0x41, 0x58, 0x38),
+     683                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF9, 0x5A, 0x2A, 0xB8, 0x96, 0x0E, 0xB2, 0x4C),
+     684                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC1, 0x78, 0x2C, 0xC7, 0x08, 0x99, 0x19, 0x24),
+     685                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB7, 0x59, 0x28, 0xE9, 0x84, 0x54, 0xE6, 0x16),
+     686                 :            : };
+     687                 :            : static const mbedtls_mpi_uint secp256r1_T_11_X[] = {
+     688                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDD, 0x38, 0x30, 0xDB, 0x70, 0x2C, 0x0A, 0xA2),
+     689                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7C, 0x5C, 0x9D, 0xE9, 0xD5, 0x46, 0x0B, 0x5F),
+     690                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x83, 0x0B, 0x60, 0x4B, 0x37, 0x7D, 0xB9, 0xC9),
+     691                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5E, 0x24, 0xF3, 0x3D, 0x79, 0x7F, 0x6C, 0x18),
+     692                 :            : };
+     693                 :            : static const mbedtls_mpi_uint secp256r1_T_11_Y[] = {
+     694                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7F, 0xE5, 0x1C, 0x4F, 0x60, 0x24, 0xF7, 0x2A),
+     695                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xED, 0xD8, 0xE2, 0x91, 0x7F, 0x89, 0x49, 0x92),
+     696                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x97, 0xA7, 0x2E, 0x8D, 0x6A, 0xB3, 0x39, 0x81),
+     697                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x13, 0x89, 0xB5, 0x9A, 0xB8, 0x8D, 0x42, 0x9C),
+     698                 :            : };
+     699                 :            : static const mbedtls_mpi_uint secp256r1_T_12_X[] = {
+     700                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8D, 0x45, 0xE6, 0x4B, 0x3F, 0x4F, 0x1E, 0x1F),
+     701                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x47, 0x65, 0x5E, 0x59, 0x22, 0xCC, 0x72, 0x5F),
+     702                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF1, 0x93, 0x1A, 0x27, 0x1E, 0x34, 0xC5, 0x5B),
+     703                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x63, 0xF2, 0xA5, 0x58, 0x5C, 0x15, 0x2E, 0xC6),
+     704                 :            : };
+     705                 :            : static const mbedtls_mpi_uint secp256r1_T_12_Y[] = {
+     706                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF4, 0x7F, 0xBA, 0x58, 0x5A, 0x84, 0x6F, 0x5F),
+     707                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAD, 0xA6, 0x36, 0x7E, 0xDC, 0xF7, 0xE1, 0x67),
+     708                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x04, 0x4D, 0xAA, 0xEE, 0x57, 0x76, 0x3A, 0xD3),
+     709                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4E, 0x7E, 0x26, 0x18, 0x22, 0x23, 0x9F, 0xFF),
+     710                 :            : };
+     711                 :            : static const mbedtls_mpi_uint secp256r1_T_13_X[] = {
+     712                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1D, 0x4C, 0x64, 0xC7, 0x55, 0x02, 0x3F, 0xE3),
+     713                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD8, 0x02, 0x90, 0xBB, 0xC3, 0xEC, 0x30, 0x40),
+     714                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9F, 0x6F, 0x64, 0xF4, 0x16, 0x69, 0x48, 0xA4),
+     715                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFA, 0x44, 0x9C, 0x95, 0x0C, 0x7D, 0x67, 0x5E),
+     716                 :            : };
+     717                 :            : static const mbedtls_mpi_uint secp256r1_T_13_Y[] = {
+     718                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x44, 0x91, 0x8B, 0xD8, 0xD0, 0xD7, 0xE7, 0xE2),
+     719                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1F, 0xF9, 0x48, 0x62, 0x6F, 0xA8, 0x93, 0x5D),
+     720                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEA, 0x3A, 0x99, 0x02, 0xD5, 0x0B, 0x3D, 0xE3),
+     721                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1E, 0xD3, 0x00, 0x31, 0xE6, 0x0C, 0x9F, 0x44),
+     722                 :            : };
+     723                 :            : static const mbedtls_mpi_uint secp256r1_T_14_X[] = {
+     724                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x56, 0xB2, 0xAA, 0xFD, 0x88, 0x15, 0xDF, 0x52),
+     725                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4C, 0x35, 0x27, 0x31, 0x44, 0xCD, 0xC0, 0x68),
+     726                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x53, 0xF8, 0x91, 0xA5, 0x71, 0x94, 0x84, 0x2A),
+     727                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x92, 0xCB, 0xD0, 0x93, 0xE9, 0x88, 0xDA, 0xE4),
+     728                 :            : };
+     729                 :            : static const mbedtls_mpi_uint secp256r1_T_14_Y[] = {
+     730                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x24, 0xC6, 0x39, 0x16, 0x5D, 0xA3, 0x1E, 0x6D),
+     731                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBA, 0x07, 0x37, 0x26, 0x36, 0x2A, 0xFE, 0x60),
+     732                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x51, 0xBC, 0xF3, 0xD0, 0xDE, 0x50, 0xFC, 0x97),
+     733                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x80, 0x2E, 0x06, 0x10, 0x15, 0x4D, 0xFA, 0xF7),
+     734                 :            : };
+     735                 :            : static const mbedtls_mpi_uint secp256r1_T_15_X[] = {
+     736                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x27, 0x65, 0x69, 0x5B, 0x66, 0xA2, 0x75, 0x2E),
+     737                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9C, 0x16, 0x00, 0x5A, 0xB0, 0x30, 0x25, 0x1A),
+     738                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x42, 0xFB, 0x86, 0x42, 0x80, 0xC1, 0xC4, 0x76),
+     739                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5B, 0x1D, 0x83, 0x8E, 0x94, 0x01, 0x5F, 0x82),
+     740                 :            : };
+     741                 :            : static const mbedtls_mpi_uint secp256r1_T_15_Y[] = {
+     742                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x39, 0x37, 0x70, 0xEF, 0x1F, 0xA1, 0xF0, 0xDB),
+     743                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6A, 0x10, 0x5B, 0xCE, 0xC4, 0x9B, 0x6F, 0x10),
+     744                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x50, 0x11, 0x11, 0x24, 0x4F, 0x4C, 0x79, 0x61),
+     745                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x17, 0x3A, 0x72, 0xBC, 0xFE, 0x72, 0x58, 0x43),
+     746                 :            : };
+     747                 :            : static const mbedtls_ecp_point secp256r1_T[16] = {
+     748                 :            :     ECP_POINT_INIT_XY_Z1(secp256r1_T_0_X, secp256r1_T_0_Y),
+     749                 :            :     ECP_POINT_INIT_XY_Z0(secp256r1_T_1_X, secp256r1_T_1_Y),
+     750                 :            :     ECP_POINT_INIT_XY_Z0(secp256r1_T_2_X, secp256r1_T_2_Y),
+     751                 :            :     ECP_POINT_INIT_XY_Z0(secp256r1_T_3_X, secp256r1_T_3_Y),
+     752                 :            :     ECP_POINT_INIT_XY_Z0(secp256r1_T_4_X, secp256r1_T_4_Y),
+     753                 :            :     ECP_POINT_INIT_XY_Z0(secp256r1_T_5_X, secp256r1_T_5_Y),
+     754                 :            :     ECP_POINT_INIT_XY_Z0(secp256r1_T_6_X, secp256r1_T_6_Y),
+     755                 :            :     ECP_POINT_INIT_XY_Z0(secp256r1_T_7_X, secp256r1_T_7_Y),
+     756                 :            :     ECP_POINT_INIT_XY_Z0(secp256r1_T_8_X, secp256r1_T_8_Y),
+     757                 :            :     ECP_POINT_INIT_XY_Z0(secp256r1_T_9_X, secp256r1_T_9_Y),
+     758                 :            :     ECP_POINT_INIT_XY_Z0(secp256r1_T_10_X, secp256r1_T_10_Y),
+     759                 :            :     ECP_POINT_INIT_XY_Z0(secp256r1_T_11_X, secp256r1_T_11_Y),
+     760                 :            :     ECP_POINT_INIT_XY_Z0(secp256r1_T_12_X, secp256r1_T_12_Y),
+     761                 :            :     ECP_POINT_INIT_XY_Z0(secp256r1_T_13_X, secp256r1_T_13_Y),
+     762                 :            :     ECP_POINT_INIT_XY_Z0(secp256r1_T_14_X, secp256r1_T_14_Y),
+     763                 :            :     ECP_POINT_INIT_XY_Z0(secp256r1_T_15_X, secp256r1_T_15_Y),
+     764                 :            : };
+     765                 :            : #else
+     766                 :            : #define secp256r1_T NULL
+     767                 :            : #endif
+     768                 :            : 
+     769                 :            : #endif /* MBEDTLS_ECP_DP_SECP256R1_ENABLED */
+     770                 :            : 
+     771                 :            : /*
+     772                 :            :  * Domain parameters for secp384r1
+     773                 :            :  */
+     774                 :            : #if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED)
+     775                 :            : static const mbedtls_mpi_uint secp384r1_p[] = {
+     776                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00),
+     777                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF),
+     778                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
+     779                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
+     780                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
+     781                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
+     782                 :            : };
+     783                 :            : static const mbedtls_mpi_uint secp384r1_b[] = {
+     784                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEF, 0x2A, 0xEC, 0xD3, 0xED, 0xC8, 0x85, 0x2A),
+     785                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9D, 0xD1, 0x2E, 0x8A, 0x8D, 0x39, 0x56, 0xC6),
+     786                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5A, 0x87, 0x13, 0x50, 0x8F, 0x08, 0x14, 0x03),
+     787                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x12, 0x41, 0x81, 0xFE, 0x6E, 0x9C, 0x1D, 0x18),
+     788                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x19, 0x2D, 0xF8, 0xE3, 0x6B, 0x05, 0x8E, 0x98),
+     789                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE4, 0xE7, 0x3E, 0xE2, 0xA7, 0x2F, 0x31, 0xB3),
+     790                 :            : };
+     791                 :            : static const mbedtls_mpi_uint secp384r1_gx[] = {
+     792                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB7, 0x0A, 0x76, 0x72, 0x38, 0x5E, 0x54, 0x3A),
+     793                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6C, 0x29, 0x55, 0xBF, 0x5D, 0xF2, 0x02, 0x55),
+     794                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x38, 0x2A, 0x54, 0x82, 0xE0, 0x41, 0xF7, 0x59),
+     795                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x98, 0x9B, 0xA7, 0x8B, 0x62, 0x3B, 0x1D, 0x6E),
+     796                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x74, 0xAD, 0x20, 0xF3, 0x1E, 0xC7, 0xB1, 0x8E),
+     797                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x37, 0x05, 0x8B, 0xBE, 0x22, 0xCA, 0x87, 0xAA),
+     798                 :            : };
+     799                 :            : static const mbedtls_mpi_uint secp384r1_gy[] = {
+     800                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5F, 0x0E, 0xEA, 0x90, 0x7C, 0x1D, 0x43, 0x7A),
+     801                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9D, 0x81, 0x7E, 0x1D, 0xCE, 0xB1, 0x60, 0x0A),
+     802                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC0, 0xB8, 0xF0, 0xB5, 0x13, 0x31, 0xDA, 0xE9),
+     803                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7C, 0x14, 0x9A, 0x28, 0xBD, 0x1D, 0xF4, 0xF8),
+     804                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x29, 0xDC, 0x92, 0x92, 0xBF, 0x98, 0x9E, 0x5D),
+     805                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6F, 0x2C, 0x26, 0x96, 0x4A, 0xDE, 0x17, 0x36),
+     806                 :            : };
+     807                 :            : static const mbedtls_mpi_uint secp384r1_n[] = {
+     808                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x73, 0x29, 0xC5, 0xCC, 0x6A, 0x19, 0xEC, 0xEC),
+     809                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7A, 0xA7, 0xB0, 0x48, 0xB2, 0x0D, 0x1A, 0x58),
+     810                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDF, 0x2D, 0x37, 0xF4, 0x81, 0x4D, 0x63, 0xC7),
+     811                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
+     812                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
+     813                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
+     814                 :            : };
+     815                 :            : #if MBEDTLS_ECP_FIXED_POINT_OPTIM == 1
+     816                 :            : static const mbedtls_mpi_uint secp384r1_T_0_X[] = {
+     817                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB7, 0x0A, 0x76, 0x72, 0x38, 0x5E, 0x54, 0x3A),
+     818                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6C, 0x29, 0x55, 0xBF, 0x5D, 0xF2, 0x02, 0x55),
+     819                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x38, 0x2A, 0x54, 0x82, 0xE0, 0x41, 0xF7, 0x59),
+     820                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x98, 0x9B, 0xA7, 0x8B, 0x62, 0x3B, 0x1D, 0x6E),
+     821                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x74, 0xAD, 0x20, 0xF3, 0x1E, 0xC7, 0xB1, 0x8E),
+     822                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x37, 0x05, 0x8B, 0xBE, 0x22, 0xCA, 0x87, 0xAA),
+     823                 :            : };
+     824                 :            : static const mbedtls_mpi_uint secp384r1_T_0_Y[] = {
+     825                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5F, 0x0E, 0xEA, 0x90, 0x7C, 0x1D, 0x43, 0x7A),
+     826                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9D, 0x81, 0x7E, 0x1D, 0xCE, 0xB1, 0x60, 0x0A),
+     827                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC0, 0xB8, 0xF0, 0xB5, 0x13, 0x31, 0xDA, 0xE9),
+     828                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7C, 0x14, 0x9A, 0x28, 0xBD, 0x1D, 0xF4, 0xF8),
+     829                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x29, 0xDC, 0x92, 0x92, 0xBF, 0x98, 0x9E, 0x5D),
+     830                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6F, 0x2C, 0x26, 0x96, 0x4A, 0xDE, 0x17, 0x36),
+     831                 :            : };
+     832                 :            : static const mbedtls_mpi_uint secp384r1_T_1_X[] = {
+     833                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x46, 0x92, 0x00, 0x2C, 0x78, 0xDB, 0x1F, 0x37),
+     834                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x17, 0xF3, 0xEB, 0xB7, 0x06, 0xF7, 0xB6, 0xBC),
+     835                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3D, 0xBC, 0x2C, 0xCF, 0xD8, 0xED, 0x53, 0xE7),
+     836                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x52, 0x75, 0x7B, 0xA3, 0xAB, 0xC3, 0x2C, 0x85),
+     837                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE5, 0x9D, 0x78, 0x41, 0xF6, 0x76, 0x84, 0xAC),
+     838                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x54, 0x56, 0xE8, 0x52, 0xB3, 0xCB, 0xA8, 0xBD),
+     839                 :            : };
+     840                 :            : static const mbedtls_mpi_uint secp384r1_T_1_Y[] = {
+     841                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6D, 0xF2, 0xAE, 0xA4, 0xB6, 0x89, 0x1B, 0xDA),
+     842                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x01, 0x0F, 0xCE, 0x1C, 0x7C, 0xF6, 0x50, 0x4C),
+     843                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4C, 0xEB, 0x90, 0xE6, 0x4D, 0xC7, 0xD4, 0x7A),
+     844                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD1, 0x49, 0x2D, 0x8A, 0x01, 0x99, 0x60, 0x94),
+     845                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5F, 0x80, 0x9B, 0x9B, 0x6A, 0xB0, 0x07, 0xD9),
+     846                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC2, 0xA2, 0xEE, 0x59, 0xBE, 0x95, 0xBC, 0x23),
+     847                 :            : };
+     848                 :            : static const mbedtls_mpi_uint secp384r1_T_2_X[] = {
+     849                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE6, 0x9D, 0x56, 0xAE, 0x59, 0xFB, 0x1F, 0x98),
+     850                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCF, 0xAC, 0x91, 0x80, 0x87, 0xA8, 0x6E, 0x58),
+     851                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x30, 0x08, 0xA7, 0x08, 0x94, 0x32, 0xFC, 0x67),
+     852                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9F, 0x29, 0x9E, 0x84, 0xF4, 0xE5, 0x6E, 0x7E),
+     853                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x55, 0x21, 0xB9, 0x50, 0x24, 0xF8, 0x9C, 0xC7),
+     854                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x34, 0x04, 0x01, 0xC2, 0xFB, 0x77, 0x3E, 0xDE),
+     855                 :            : };
+     856                 :            : static const mbedtls_mpi_uint secp384r1_T_2_Y[] = {
+     857                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x00, 0x38, 0xEE, 0xE3, 0xC7, 0x9D, 0xEC, 0xA6),
+     858                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB6, 0x88, 0xCF, 0x43, 0xFA, 0x92, 0x5E, 0x8E),
+     859                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE9, 0xCA, 0x43, 0xF8, 0x3B, 0x49, 0x7E, 0x75),
+     860                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1C, 0xE7, 0xEB, 0x17, 0x45, 0x86, 0xC2, 0xE1),
+     861                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x92, 0x69, 0x57, 0x32, 0xE0, 0x9C, 0xD1, 0x00),
+     862                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD9, 0x10, 0xB8, 0x4D, 0xB8, 0xF4, 0x0D, 0xE3),
+     863                 :            : };
+     864                 :            : static const mbedtls_mpi_uint secp384r1_T_3_X[] = {
+     865                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x60, 0xDC, 0x9A, 0xB2, 0x79, 0x39, 0x27, 0x16),
+     866                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4F, 0x71, 0xE4, 0x3B, 0x4D, 0x60, 0x0C, 0xA3),
+     867                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x55, 0xBD, 0x19, 0x40, 0xFA, 0x19, 0x2A, 0x5A),
+     868                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4D, 0xF8, 0x1E, 0x43, 0xA1, 0x50, 0x8D, 0xEF),
+     869                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA3, 0x18, 0x7C, 0x41, 0xFA, 0x7C, 0x1B, 0x58),
+     870                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x00, 0x59, 0x24, 0xC4, 0xE9, 0xB7, 0xD3, 0xAD),
+     871                 :            : };
+     872                 :            : static const mbedtls_mpi_uint secp384r1_T_3_Y[] = {
+     873                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBB, 0x01, 0x3D, 0x63, 0x54, 0x45, 0x6F, 0xB7),
+     874                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7B, 0xB2, 0x19, 0xA3, 0x86, 0x1D, 0x42, 0x34),
+     875                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x84, 0x02, 0x87, 0x18, 0x92, 0x52, 0x1A, 0x71),
+     876                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6C, 0x18, 0xB1, 0x5D, 0x18, 0x1B, 0x37, 0xFE),
+     877                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF4, 0x74, 0x61, 0xBA, 0x18, 0xAF, 0x40, 0x30),
+     878                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDA, 0x7D, 0x3C, 0x52, 0x0F, 0x07, 0xB0, 0x6F),
+     879                 :            : };
+     880                 :            : static const mbedtls_mpi_uint secp384r1_T_4_X[] = {
+     881                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x09, 0x39, 0x13, 0xAA, 0x60, 0x15, 0x99, 0x30),
+     882                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x17, 0x00, 0xCB, 0xC6, 0xB1, 0xDB, 0x97, 0x90),
+     883                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE6, 0xFA, 0x60, 0xB8, 0x24, 0xE4, 0x7D, 0xD3),
+     884                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDD, 0x75, 0xB3, 0x70, 0xB2, 0x83, 0xB1, 0x9B),
+     885                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA3, 0xE3, 0x6C, 0xCD, 0x33, 0x62, 0x7A, 0x56),
+     886                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x88, 0x30, 0xDC, 0x0F, 0x9F, 0xBB, 0xB8, 0xAA),
+     887                 :            : };
+     888                 :            : static const mbedtls_mpi_uint secp384r1_T_4_Y[] = {
+     889                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA6, 0xD5, 0x0A, 0x60, 0x81, 0xB9, 0xC5, 0x16),
+     890                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x44, 0xAA, 0x2F, 0xD6, 0xF2, 0x73, 0xDF, 0xEB),
+     891                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF3, 0x7B, 0x74, 0xC9, 0xB3, 0x5B, 0x95, 0x6D),
+     892                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAC, 0x04, 0xEB, 0x15, 0xC8, 0x5F, 0x00, 0xF6),
+     893                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB5, 0x50, 0x20, 0x28, 0xD1, 0x01, 0xAF, 0xF0),
+     894                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x28, 0x6D, 0x4F, 0x31, 0x81, 0x2F, 0x94, 0x48),
+     895                 :            : };
+     896                 :            : static const mbedtls_mpi_uint secp384r1_T_5_X[] = {
+     897                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x46, 0x2F, 0xD8, 0xB6, 0x63, 0x7C, 0xE9, 0x50),
+     898                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD9, 0x8C, 0xB9, 0x14, 0xD9, 0x37, 0x63, 0xDE),
+     899                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x10, 0x02, 0xB8, 0x46, 0xAD, 0xCE, 0x7B, 0x38),
+     900                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x82, 0x47, 0x2D, 0x66, 0xA7, 0xE9, 0x33, 0x23),
+     901                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x92, 0xF9, 0x93, 0x94, 0xA8, 0x48, 0xB3, 0x4F),
+     902                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE9, 0x4A, 0xAC, 0x51, 0x08, 0x72, 0x2F, 0x1A),
+     903                 :            : };
+     904                 :            : static const mbedtls_mpi_uint secp384r1_T_5_Y[] = {
+     905                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDA, 0xAD, 0xA0, 0xF9, 0x81, 0xE1, 0x78, 0x97),
+     906                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3A, 0x9A, 0x63, 0xD8, 0xBA, 0x79, 0x1A, 0x17),
+     907                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x34, 0x31, 0x7B, 0x7A, 0x5A, 0x5D, 0x7D, 0x2D),
+     908                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x83, 0x96, 0x12, 0x4B, 0x19, 0x09, 0xE0, 0xB7),
+     909                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x55, 0x8A, 0x57, 0xEE, 0x4E, 0x6E, 0x7E, 0xEC),
+     910                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x11, 0x9D, 0x69, 0xDC, 0xB3, 0xDA, 0xD8, 0x08),
+     911                 :            : };
+     912                 :            : static const mbedtls_mpi_uint secp384r1_T_6_X[] = {
+     913                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x68, 0x49, 0x03, 0x03, 0x33, 0x6F, 0x28, 0x4A),
+     914                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5D, 0xDB, 0xA7, 0x05, 0x8C, 0xF3, 0x4D, 0xFB),
+     915                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8E, 0x92, 0xB1, 0xA8, 0xEC, 0x0D, 0x64, 0x3B),
+     916                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4E, 0xFC, 0xFD, 0xD0, 0x4B, 0x88, 0x1B, 0x5D),
+     917                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x83, 0x9C, 0x51, 0x69, 0xCE, 0x71, 0x73, 0xF5),
+     918                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB8, 0x5A, 0x14, 0x23, 0x1A, 0x46, 0x63, 0x5F),
+     919                 :            : };
+     920                 :            : static const mbedtls_mpi_uint secp384r1_T_6_Y[] = {
+     921                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBC, 0x4C, 0x70, 0x44, 0x18, 0xCD, 0xEF, 0xED),
+     922                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC2, 0x49, 0xDD, 0x64, 0x7E, 0x7E, 0x4D, 0x92),
+     923                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA2, 0x32, 0x7C, 0x09, 0xD0, 0x3F, 0xD6, 0x2C),
+     924                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6D, 0xE0, 0x4F, 0x65, 0x0C, 0x7A, 0x54, 0x3E),
+     925                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x16, 0xFA, 0xFB, 0x4A, 0xB4, 0x79, 0x5A, 0x8C),
+     926                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x04, 0x5D, 0x1B, 0x2B, 0xDA, 0xBC, 0x9A, 0x74),
+     927                 :            : };
+     928                 :            : static const mbedtls_mpi_uint secp384r1_T_7_X[] = {
+     929                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x51, 0xAC, 0x56, 0xF7, 0x5F, 0x51, 0x68, 0x0B),
+     930                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC6, 0xE0, 0x1D, 0xBC, 0x13, 0x4E, 0xAC, 0x03),
+     931                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB7, 0xF5, 0xC5, 0xE6, 0xD2, 0x88, 0xBA, 0xCB),
+     932                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFA, 0x0E, 0x28, 0x23, 0x58, 0x67, 0xFA, 0xEE),
+     933                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9E, 0x80, 0x4B, 0xD8, 0xC4, 0xDF, 0x15, 0xE4),
+     934                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF1, 0x0E, 0x58, 0xE6, 0x2C, 0x59, 0xC2, 0x03),
+     935                 :            : };
+     936                 :            : static const mbedtls_mpi_uint secp384r1_T_7_Y[] = {
+     937                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9B, 0x26, 0x27, 0x99, 0x16, 0x2B, 0x22, 0x0B),
+     938                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBA, 0xF3, 0x8F, 0xC3, 0x2A, 0x9B, 0xFC, 0x38),
+     939                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFC, 0x2E, 0x83, 0x3D, 0xFE, 0x9E, 0x3C, 0x1B),
+     940                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x08, 0x57, 0xCD, 0x2D, 0xC1, 0x49, 0x38, 0xB5),
+     941                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x95, 0x42, 0x8B, 0x33, 0x89, 0x1F, 0xEA, 0x01),
+     942                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAA, 0x1D, 0x13, 0xD7, 0x50, 0xBB, 0x3E, 0xEB),
+     943                 :            : };
+     944                 :            : static const mbedtls_mpi_uint secp384r1_T_8_X[] = {
+     945                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD2, 0x9A, 0x52, 0xD2, 0x54, 0x7C, 0x97, 0xF2),
+     946                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE0, 0x33, 0x6E, 0xED, 0xD9, 0x87, 0x50, 0xC5),
+     947                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5A, 0x35, 0x7E, 0x16, 0x40, 0x15, 0x83, 0xB8),
+     948                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x33, 0x2B, 0xA4, 0xAB, 0x03, 0x91, 0xEA, 0xFE),
+     949                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC1, 0x47, 0x39, 0xEF, 0x05, 0x59, 0xD0, 0x90),
+     950                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBF, 0x24, 0x0D, 0x76, 0x11, 0x53, 0x08, 0xAF),
+     951                 :            : };
+     952                 :            : static const mbedtls_mpi_uint secp384r1_T_8_Y[] = {
+     953                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1F, 0x2F, 0xDD, 0xBD, 0x50, 0x48, 0xB1, 0xE5),
+     954                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x80, 0x1C, 0x84, 0x55, 0x78, 0x14, 0xEB, 0xF6),
+     955                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD9, 0x5E, 0x3E, 0xA6, 0xAF, 0xF6, 0xC7, 0x04),
+     956                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE7, 0x11, 0xE2, 0x65, 0xCA, 0x41, 0x95, 0x3B),
+     957                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAE, 0x83, 0xD8, 0xE6, 0x4D, 0x22, 0x06, 0x2D),
+     958                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFA, 0x7F, 0x25, 0x2A, 0xAA, 0x28, 0x46, 0x97),
+     959                 :            : };
+     960                 :            : static const mbedtls_mpi_uint secp384r1_T_9_X[] = {
+     961                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x79, 0xDB, 0x15, 0x56, 0x84, 0xCB, 0xC0, 0x56),
+     962                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x56, 0xDB, 0x0E, 0x08, 0xC9, 0xF5, 0xD4, 0x9E),
+     963                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE6, 0x62, 0xD0, 0x1A, 0x7C, 0x13, 0xD5, 0x07),
+     964                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7D, 0xAD, 0x53, 0xE0, 0x32, 0x21, 0xA0, 0xC0),
+     965                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC5, 0x38, 0x81, 0x21, 0x23, 0x0E, 0xD2, 0xBB),
+     966                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1C, 0x51, 0x05, 0xD0, 0x1E, 0x82, 0xA9, 0x71),
+     967                 :            : };
+     968                 :            : static const mbedtls_mpi_uint secp384r1_T_9_Y[] = {
+     969                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA7, 0xC3, 0x27, 0xBF, 0xC6, 0xAA, 0xB7, 0xB9),
+     970                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCB, 0x65, 0x45, 0xDF, 0xB9, 0x46, 0x17, 0x46),
+     971                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF5, 0x38, 0x3F, 0xB2, 0xB1, 0x5D, 0xCA, 0x1C),
+     972                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x88, 0x29, 0x6C, 0x63, 0xE9, 0xD7, 0x48, 0xB8),
+     973                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBC, 0xF1, 0xD7, 0x99, 0x8C, 0xC2, 0x05, 0x99),
+     974                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6D, 0xE6, 0x5E, 0x82, 0x6D, 0xE5, 0x7E, 0xD5),
+     975                 :            : };
+     976                 :            : static const mbedtls_mpi_uint secp384r1_T_10_X[] = {
+     977                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7B, 0x61, 0xFA, 0x7D, 0x01, 0xDB, 0xB6, 0x63),
+     978                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x11, 0xC6, 0x58, 0x39, 0xF4, 0xC6, 0x82, 0x23),
+     979                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x47, 0x5A, 0x7A, 0x80, 0x08, 0xCD, 0xAA, 0xD8),
+     980                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDA, 0x8C, 0xC6, 0x3F, 0x3C, 0xA5, 0x68, 0xF4),
+     981                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBB, 0xF5, 0xD5, 0x17, 0xAE, 0x36, 0xD8, 0x8A),
+     982                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC7, 0xAD, 0x92, 0xC5, 0x57, 0x6C, 0xDA, 0x91),
+     983                 :            : };
+     984                 :            : static const mbedtls_mpi_uint secp384r1_T_10_Y[] = {
+     985                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE8, 0x67, 0x17, 0xC0, 0x40, 0x78, 0x8C, 0x84),
+     986                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7E, 0x9F, 0xF4, 0xAA, 0xDA, 0x5C, 0x7E, 0xB2),
+     987                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x96, 0xDB, 0x42, 0x3E, 0x72, 0x64, 0xA0, 0x67),
+     988                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x27, 0xF9, 0x41, 0x17, 0x43, 0xE3, 0xE8, 0xA8),
+     989                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x66, 0xDD, 0xCC, 0x43, 0x7E, 0x16, 0x05, 0x03),
+     990                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x36, 0x4B, 0xCF, 0x48, 0x8F, 0x41, 0x90, 0xE5),
+     991                 :            : };
+     992                 :            : static const mbedtls_mpi_uint secp384r1_T_11_X[] = {
+     993                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x98, 0x0C, 0x6B, 0x9D, 0x22, 0x04, 0xBC, 0x5C),
+     994                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x86, 0x63, 0x79, 0x2F, 0x6A, 0x0E, 0x8A, 0xDE),
+     995                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x29, 0x67, 0x3F, 0x02, 0xB8, 0x91, 0x7F, 0x74),
+     996                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFC, 0x14, 0x64, 0xA0, 0x33, 0xF4, 0x6B, 0x50),
+     997                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1C, 0x44, 0x71, 0x87, 0xB8, 0x88, 0x3F, 0x45),
+     998                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1B, 0x2B, 0x85, 0x05, 0xC5, 0x44, 0x53, 0x15),
+     999                 :            : };
+    1000                 :            : static const mbedtls_mpi_uint secp384r1_T_11_Y[] = {
+    1001                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3E, 0x2B, 0xFE, 0xD1, 0x1C, 0x73, 0xE3, 0x2E),
+    1002                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x66, 0x33, 0xA1, 0xD3, 0x69, 0x1C, 0x9D, 0xD2),
+    1003                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE0, 0x5A, 0xBA, 0xB6, 0xAE, 0x1B, 0x94, 0x04),
+    1004                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAF, 0x74, 0x90, 0x5C, 0x57, 0xB0, 0x3A, 0x45),
+    1005                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDD, 0x2F, 0x93, 0x20, 0x24, 0x54, 0x1D, 0x8D),
+    1006                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFA, 0x78, 0x9D, 0x71, 0x67, 0x5D, 0x49, 0x98),
+    1007                 :            : };
+    1008                 :            : static const mbedtls_mpi_uint secp384r1_T_12_X[] = {
+    1009                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x12, 0xC8, 0x0E, 0x11, 0x8D, 0xE0, 0x8F, 0x69),
+    1010                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x59, 0x7F, 0x79, 0x6C, 0x5F, 0xB7, 0xBC, 0xB1),
+    1011                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x88, 0xE1, 0x83, 0x3C, 0x12, 0xBB, 0xEE, 0x96),
+    1012                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2A, 0xC2, 0xC4, 0x1B, 0x41, 0x71, 0xB9, 0x17),
+    1013                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB0, 0xEE, 0xBB, 0x1D, 0x89, 0x50, 0x88, 0xF2),
+    1014                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFC, 0x1C, 0x55, 0x74, 0xEB, 0xDE, 0x92, 0x3F),
+    1015                 :            : };
+    1016                 :            : static const mbedtls_mpi_uint secp384r1_T_12_Y[] = {
+    1017                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9C, 0x38, 0x92, 0x06, 0x19, 0xD0, 0xB3, 0xB2),
+    1018                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2A, 0x99, 0x26, 0xA3, 0x5F, 0xE2, 0xC1, 0x81),
+    1019                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x75, 0xFC, 0xFD, 0xC3, 0xB6, 0x26, 0x24, 0x8F),
+    1020                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAF, 0xAD, 0xE7, 0x49, 0xB7, 0x64, 0x4B, 0x96),
+    1021                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6C, 0x4E, 0x95, 0xAD, 0x07, 0xFE, 0xB6, 0x30),
+    1022                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4F, 0x15, 0xE7, 0x2D, 0x19, 0xA9, 0x08, 0x10),
+    1023                 :            : };
+    1024                 :            : static const mbedtls_mpi_uint secp384r1_T_13_X[] = {
+    1025                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBE, 0xBD, 0xAC, 0x0A, 0x3F, 0x6B, 0xFF, 0xFA),
+    1026                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE0, 0xE4, 0x74, 0x14, 0xD9, 0x70, 0x1D, 0x71),
+    1027                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF2, 0xB0, 0x71, 0xBB, 0xD8, 0x18, 0x96, 0x2B),
+    1028                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDA, 0xB8, 0x19, 0x90, 0x80, 0xB5, 0xEE, 0x01),
+    1029                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x91, 0x21, 0x20, 0xA6, 0x17, 0x48, 0x03, 0x6F),
+    1030                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE3, 0x1D, 0xBB, 0x6D, 0x94, 0x20, 0x34, 0xF1),
+    1031                 :            : };
+    1032                 :            : static const mbedtls_mpi_uint secp384r1_T_13_Y[] = {
+    1033                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x59, 0x82, 0x67, 0x4B, 0x8E, 0x4E, 0xBE, 0xE2),
+    1034                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBE, 0xDA, 0x77, 0xF8, 0x23, 0x55, 0x2B, 0x2D),
+    1035                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5C, 0x02, 0xDE, 0x25, 0x35, 0x2D, 0x74, 0x51),
+    1036                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD0, 0x0C, 0xB8, 0x0B, 0x39, 0xBA, 0xAD, 0x04),
+    1037                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA6, 0x0E, 0x28, 0x4D, 0xE1, 0x3D, 0xE4, 0x1B),
+    1038                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5D, 0xEC, 0x0A, 0xD4, 0xB8, 0xC4, 0x8D, 0xB0),
+    1039                 :            : };
+    1040                 :            : static const mbedtls_mpi_uint secp384r1_T_14_X[] = {
+    1041                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3E, 0x68, 0xCE, 0xC2, 0x55, 0x4D, 0x0C, 0x6D),
+    1042                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9B, 0x20, 0x93, 0x32, 0x90, 0xD6, 0xAE, 0x47),
+    1043                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDD, 0x78, 0xAB, 0x43, 0x9E, 0xEB, 0x73, 0xAE),
+    1044                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xED, 0x97, 0xC3, 0x83, 0xA6, 0x3C, 0xF1, 0xBF),
+    1045                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0F, 0x25, 0x25, 0x66, 0x08, 0x26, 0xFA, 0x4B),
+    1046                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x41, 0xFB, 0x44, 0x5D, 0x82, 0xEC, 0x3B, 0xAC),
+    1047                 :            : };
+    1048                 :            : static const mbedtls_mpi_uint secp384r1_T_14_Y[] = {
+    1049                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x58, 0x90, 0xEA, 0xB5, 0x04, 0x99, 0xD0, 0x69),
+    1050                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4A, 0xF2, 0x22, 0xA0, 0xEB, 0xFD, 0x45, 0x87),
+    1051                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5D, 0xA4, 0x81, 0x32, 0xFC, 0xFA, 0xEE, 0x5B),
+    1052                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x27, 0xBB, 0xA4, 0x6A, 0x77, 0x41, 0x5C, 0x1D),
+    1053                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA1, 0x1E, 0xAA, 0x4F, 0xF0, 0x10, 0xB3, 0x50),
+    1054                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x09, 0x74, 0x13, 0x14, 0x9E, 0x90, 0xD7, 0xE6),
+    1055                 :            : };
+    1056                 :            : static const mbedtls_mpi_uint secp384r1_T_15_X[] = {
+    1057                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDB, 0xBD, 0x70, 0x4F, 0xA8, 0xD1, 0x06, 0x2C),
+    1058                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x19, 0x4E, 0x2E, 0x68, 0xFC, 0x35, 0xFA, 0x50),
+    1059                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x60, 0x53, 0x75, 0xED, 0xF2, 0x5F, 0xC2, 0xEB),
+    1060                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x39, 0x87, 0x6B, 0x9F, 0x05, 0xE2, 0x22, 0x93),
+    1061                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4F, 0x1A, 0xA8, 0xB7, 0x03, 0x9E, 0x6D, 0x7C),
+    1062                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCB, 0xD0, 0x69, 0x88, 0xA8, 0x39, 0x9E, 0x3A),
+    1063                 :            : };
+    1064                 :            : static const mbedtls_mpi_uint secp384r1_T_15_Y[] = {
+    1065                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF8, 0xEF, 0x68, 0xFE, 0xEC, 0x24, 0x08, 0x15),
+    1066                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA1, 0x06, 0x4B, 0x92, 0x0D, 0xB7, 0x34, 0x74),
+    1067                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3E, 0xF4, 0xDD, 0x1A, 0xA0, 0x4A, 0xE4, 0x45),
+    1068                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC3, 0x63, 0x4F, 0x4F, 0xCE, 0xBB, 0xD6, 0xD3),
+    1069                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCD, 0xEE, 0x8D, 0xDF, 0x3F, 0x73, 0xB7, 0xAC),
+    1070                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDF, 0x06, 0xB6, 0x80, 0x4D, 0x81, 0xD9, 0x53),
+    1071                 :            : };
+    1072                 :            : static const mbedtls_mpi_uint secp384r1_T_16_X[] = {
+    1073                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x15, 0xF5, 0x13, 0xDF, 0x13, 0x19, 0x97, 0x94),
+    1074                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x08, 0xF9, 0xB3, 0x33, 0x66, 0x82, 0x21, 0xFE),
+    1075                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF5, 0xFC, 0x39, 0x16, 0x23, 0x43, 0x76, 0x0E),
+    1076                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x09, 0x48, 0x25, 0xA1, 0x64, 0x95, 0x1C, 0x2F),
+    1077                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x43, 0xAC, 0x15, 0x57, 0xD9, 0xDE, 0xA0, 0x28),
+    1078                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x16, 0x5F, 0xB8, 0x3D, 0x48, 0x91, 0x24, 0xCC),
+    1079                 :            : };
+    1080                 :            : static const mbedtls_mpi_uint secp384r1_T_16_Y[] = {
+    1081                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2D, 0xF2, 0xC8, 0x54, 0xD1, 0x32, 0xBD, 0xC4),
+    1082                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8A, 0x3B, 0xF0, 0xAA, 0x9D, 0xD8, 0xF4, 0x20),
+    1083                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4F, 0xC3, 0xBB, 0x6C, 0x66, 0xAC, 0x25, 0x2D),
+    1084                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6F, 0x25, 0x10, 0xB2, 0xE1, 0x41, 0xDE, 0x1D),
+    1085                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3C, 0xE8, 0x30, 0xB8, 0x37, 0xBC, 0x2A, 0x98),
+    1086                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBA, 0x57, 0x01, 0x4A, 0x1E, 0x78, 0x9F, 0x85),
+    1087                 :            : };
+    1088                 :            : static const mbedtls_mpi_uint secp384r1_T_17_X[] = {
+    1089                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBD, 0x19, 0xCD, 0x12, 0x0B, 0x51, 0x4F, 0x56),
+    1090                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x30, 0x4B, 0x3D, 0x24, 0xA4, 0x16, 0x59, 0x05),
+    1091                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAC, 0xEB, 0xD3, 0x59, 0x2E, 0x75, 0x7C, 0x01),
+    1092                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8C, 0xB9, 0xB4, 0xA5, 0xD9, 0x2E, 0x29, 0x4C),
+    1093                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x86, 0x16, 0x05, 0x75, 0x02, 0xB3, 0x06, 0xEE),
+    1094                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAB, 0x7C, 0x9F, 0x79, 0x91, 0xF1, 0x4F, 0x23),
+    1095                 :            : };
+    1096                 :            : static const mbedtls_mpi_uint secp384r1_T_17_Y[] = {
+    1097                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x65, 0x98, 0x7C, 0x84, 0xE1, 0xFF, 0x30, 0x77),
+    1098                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x71, 0xE2, 0xC2, 0x5F, 0x55, 0x40, 0xBD, 0xCD),
+    1099                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x69, 0x65, 0x87, 0x3F, 0xC4, 0xC2, 0x24, 0x57),
+    1100                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0E, 0x30, 0x0A, 0x60, 0x15, 0xD1, 0x24, 0x48),
+    1101                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x57, 0x99, 0xD9, 0xB6, 0xAE, 0xB1, 0xAF, 0x1D),
+    1102                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9B, 0x80, 0xEE, 0xA2, 0x0F, 0x74, 0xB9, 0xF3),
+    1103                 :            : };
+    1104                 :            : static const mbedtls_mpi_uint secp384r1_T_18_X[] = {
+    1105                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x03, 0xE6, 0x0F, 0x37, 0xC1, 0x10, 0x99, 0x1E),
+    1106                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x61, 0xAD, 0x9D, 0x5D, 0x80, 0x01, 0xA6, 0xFE),
+    1107                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB0, 0x0F, 0x10, 0x2A, 0x9D, 0x20, 0x38, 0xEB),
+    1108                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6C, 0x60, 0xCB, 0xCE, 0x5A, 0xA0, 0xA7, 0x32),
+    1109                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBA, 0xCF, 0x14, 0xDF, 0xBF, 0xE5, 0x74, 0x2D),
+    1110                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB5, 0x12, 0x1A, 0xDD, 0x59, 0x02, 0x5D, 0xC6),
+    1111                 :            : };
+    1112                 :            : static const mbedtls_mpi_uint secp384r1_T_18_Y[] = {
+    1113                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC8, 0xC9, 0xF8, 0xF5, 0xB6, 0x13, 0x4D, 0x7B),
+    1114                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xED, 0x45, 0xB1, 0x93, 0xB3, 0xA2, 0x79, 0xDC),
+    1115                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x74, 0xF6, 0xCF, 0xF7, 0xE6, 0x29, 0x9C, 0xCC),
+    1116                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x87, 0x50, 0x65, 0x80, 0xBC, 0x59, 0x0A, 0x59),
+    1117                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0E, 0xF0, 0x24, 0x35, 0xA2, 0x46, 0xF0, 0x0C),
+    1118                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBD, 0x26, 0xC0, 0x9D, 0x61, 0x56, 0x62, 0x67),
+    1119                 :            : };
+    1120                 :            : static const mbedtls_mpi_uint secp384r1_T_19_X[] = {
+    1121                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x10, 0xBB, 0xC2, 0x24, 0x43, 0x2E, 0x37, 0x54),
+    1122                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8A, 0xF7, 0xCE, 0x35, 0xFC, 0x77, 0xF3, 0x3F),
+    1123                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x75, 0x34, 0x96, 0xD5, 0x4A, 0x76, 0x9D, 0x6B),
+    1124                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB8, 0x3B, 0x0F, 0xEA, 0xA8, 0x12, 0x0B, 0x22),
+    1125                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x66, 0x3F, 0x5D, 0x2D, 0x1C, 0xD4, 0x9E, 0xFB),
+    1126                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7D, 0x2E, 0xDD, 0xC7, 0x6E, 0xAB, 0xAF, 0xDC),
+    1127                 :            : };
+    1128                 :            : static const mbedtls_mpi_uint secp384r1_T_19_Y[] = {
+    1129                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8C, 0xB2, 0x7B, 0x0C, 0x9A, 0x83, 0x8E, 0x59),
+    1130                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x30, 0x51, 0x90, 0x92, 0x79, 0x32, 0x19, 0xC3),
+    1131                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEE, 0x89, 0xF9, 0xD0, 0xCF, 0x2C, 0xA5, 0x8F),
+    1132                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7B, 0x50, 0x21, 0xDE, 0x50, 0x41, 0x9D, 0x81),
+    1133                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE0, 0x7D, 0x2B, 0x9E, 0x9D, 0x95, 0xA8, 0xE3),
+    1134                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD8, 0xA5, 0x20, 0x87, 0x88, 0x97, 0x5F, 0xAA),
+    1135                 :            : };
+    1136                 :            : static const mbedtls_mpi_uint secp384r1_T_20_X[] = {
+    1137                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x64, 0x59, 0xB4, 0x66, 0x7E, 0xE8, 0x5A, 0x60),
+    1138                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA5, 0x5C, 0x7E, 0xB2, 0xAD, 0xD9, 0xC9, 0xDA),
+    1139                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x82, 0x97, 0x49, 0xA3, 0x13, 0x83, 0x07, 0x2E),
+    1140                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5A, 0x26, 0xC7, 0x13, 0x35, 0x0D, 0xB0, 0x6B),
+    1141                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1E, 0x60, 0xAB, 0xFA, 0x4B, 0x93, 0x18, 0x2C),
+    1142                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x54, 0x2D, 0x1C, 0x31, 0x4C, 0xE4, 0x61, 0xAE),
+    1143                 :            : };
+    1144                 :            : static const mbedtls_mpi_uint secp384r1_T_20_Y[] = {
+    1145                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDE, 0x4D, 0x1E, 0x51, 0x59, 0x6E, 0x91, 0xC5),
+    1146                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x38, 0x54, 0x4D, 0x51, 0xED, 0x36, 0xCC, 0x60),
+    1147                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x18, 0xA8, 0x56, 0xC7, 0x78, 0x27, 0x33, 0xC5),
+    1148                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x42, 0xB7, 0x95, 0xC9, 0x8B, 0xC8, 0x6A, 0xBC),
+    1149                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5E, 0xE9, 0x13, 0x96, 0xB3, 0xE1, 0xF9, 0xEE),
+    1150                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF5, 0x46, 0xB0, 0x5E, 0xC3, 0x94, 0x03, 0x05),
+    1151                 :            : };
+    1152                 :            : static const mbedtls_mpi_uint secp384r1_T_21_X[] = {
+    1153                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6D, 0x5B, 0x29, 0x30, 0x41, 0x1A, 0x9E, 0xB6),
+    1154                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x76, 0xCA, 0x83, 0x31, 0x5B, 0xA7, 0xCB, 0x42),
+    1155                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x21, 0x41, 0x50, 0x44, 0x4D, 0x64, 0x31, 0x89),
+    1156                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCF, 0x84, 0xC2, 0x5D, 0x97, 0xA5, 0x3C, 0x18),
+    1157                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF0, 0x0F, 0xA5, 0xFD, 0x8E, 0x5A, 0x47, 0x2C),
+    1158                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7C, 0x58, 0x02, 0x2D, 0x40, 0xB1, 0x0B, 0xBA),
+    1159                 :            : };
+    1160                 :            : static const mbedtls_mpi_uint secp384r1_T_21_Y[] = {
+    1161                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDA, 0x33, 0x8C, 0x67, 0xCE, 0x23, 0x43, 0x99),
+    1162                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x84, 0x53, 0x47, 0x72, 0x44, 0x1F, 0x5B, 0x2A),
+    1163                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAE, 0xC1, 0xD9, 0xA4, 0x50, 0x88, 0x63, 0x18),
+    1164                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7C, 0xF2, 0x75, 0x69, 0x73, 0x00, 0xC4, 0x31),
+    1165                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4B, 0x90, 0x1D, 0xDF, 0x1A, 0x00, 0xD8, 0x69),
+    1166                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x05, 0xB1, 0x89, 0x48, 0xA8, 0x70, 0x62, 0xEF),
+    1167                 :            : };
+    1168                 :            : static const mbedtls_mpi_uint secp384r1_T_22_X[] = {
+    1169                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7E, 0x8A, 0x55, 0x50, 0x7B, 0xEF, 0x8A, 0x3C),
+    1170                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFE, 0x1B, 0x23, 0x48, 0x23, 0x63, 0x91, 0xB6),
+    1171                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0D, 0x04, 0x54, 0x3C, 0x24, 0x9B, 0xC7, 0x9A),
+    1172                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x25, 0x38, 0xC3, 0x84, 0xFB, 0xFF, 0x9F, 0x49),
+    1173                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x66, 0x2A, 0xE0, 0x6D, 0x68, 0x8A, 0x5C, 0xCB),
+    1174                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC4, 0x93, 0x53, 0x85, 0xA1, 0x0D, 0xAF, 0x63),
+    1175                 :            : };
+    1176                 :            : static const mbedtls_mpi_uint secp384r1_T_22_Y[] = {
+    1177                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1B, 0x88, 0x95, 0x4C, 0x0B, 0xD0, 0x06, 0x51),
+    1178                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x92, 0xAF, 0x8D, 0x49, 0xA2, 0xC8, 0xB4, 0xE0),
+    1179                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x75, 0x76, 0x53, 0x09, 0x88, 0x43, 0x87, 0xCA),
+    1180                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x90, 0xA4, 0x77, 0x3F, 0x5E, 0x21, 0xB4, 0x0A),
+    1181                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x35, 0x9E, 0x86, 0x64, 0xCC, 0x91, 0xC1, 0x77),
+    1182                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC1, 0x17, 0x56, 0xCB, 0xC3, 0x7D, 0x5B, 0xB1),
+    1183                 :            : };
+    1184                 :            : static const mbedtls_mpi_uint secp384r1_T_23_X[] = {
+    1185                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x64, 0x74, 0x9F, 0xB5, 0x91, 0x21, 0xB1, 0x1C),
+    1186                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1E, 0xED, 0xE1, 0x11, 0xEF, 0x45, 0xAF, 0xC1),
+    1187                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE0, 0x31, 0xBE, 0xB2, 0xBC, 0x72, 0x65, 0x1F),
+    1188                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB1, 0x4B, 0x8C, 0x77, 0xCE, 0x1E, 0x42, 0xB5),
+    1189                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xC9, 0xAA, 0xB9, 0xD9, 0x86, 0x99, 0x55),
+    1190                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x65, 0x23, 0x80, 0xC6, 0x4E, 0x35, 0x0B, 0x6D),
+    1191                 :            : };
+    1192                 :            : static const mbedtls_mpi_uint secp384r1_T_23_Y[] = {
+    1193                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x47, 0xD8, 0xA2, 0x0A, 0x39, 0x32, 0x1D, 0x23),
+    1194                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x61, 0xC8, 0x86, 0xF1, 0x12, 0x9A, 0x4A, 0x05),
+    1195                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8D, 0xF1, 0x7C, 0xAA, 0x70, 0x8E, 0xBC, 0x01),
+    1196                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x62, 0x01, 0x47, 0x8F, 0xDD, 0x8B, 0xA5, 0xC8),
+    1197                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDB, 0x08, 0x21, 0xF4, 0xAB, 0xC7, 0xF5, 0x96),
+    1198                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0A, 0x76, 0xA5, 0x95, 0xC4, 0x0F, 0x88, 0x1D),
+    1199                 :            : };
+    1200                 :            : static const mbedtls_mpi_uint secp384r1_T_24_X[] = {
+    1201                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3F, 0x42, 0x2A, 0x52, 0xCD, 0x75, 0x51, 0x49),
+    1202                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x90, 0x36, 0xE5, 0x04, 0x2B, 0x44, 0xC6, 0xEF),
+    1203                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5C, 0xEE, 0x16, 0x13, 0x07, 0x83, 0xB5, 0x30),
+    1204                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x76, 0x59, 0xC6, 0xA2, 0x19, 0x05, 0xD3, 0xC6),
+    1205                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB6, 0x8B, 0xA8, 0x16, 0x09, 0xB7, 0xEA, 0xD6),
+    1206                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x70, 0xEE, 0x14, 0xAF, 0xB5, 0xFD, 0xD0, 0xEF),
+    1207                 :            : };
+    1208                 :            : static const mbedtls_mpi_uint secp384r1_T_24_Y[] = {
+    1209                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x18, 0x7C, 0xCA, 0x71, 0x3E, 0x6E, 0x66, 0x75),
+    1210                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBE, 0x31, 0x0E, 0x3F, 0xE5, 0x91, 0xC4, 0x7F),
+    1211                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8E, 0x3D, 0xC2, 0x3E, 0x95, 0x37, 0x58, 0x2B),
+    1212                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x01, 0x1F, 0x02, 0x03, 0xF3, 0xEF, 0xEE, 0x66),
+    1213                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x28, 0x5B, 0x1A, 0xFC, 0x38, 0xCD, 0xE8, 0x24),
+    1214                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x12, 0x57, 0x42, 0x85, 0xC6, 0x21, 0x68, 0x71),
+    1215                 :            : };
+    1216                 :            : static const mbedtls_mpi_uint secp384r1_T_25_X[] = {
+    1217                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8D, 0xA2, 0x4A, 0x66, 0xB1, 0x0A, 0xE6, 0xC0),
+    1218                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x86, 0x0C, 0x94, 0x9D, 0x5E, 0x99, 0xB2, 0xCE),
+    1219                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAD, 0x03, 0x40, 0xCA, 0xB2, 0xB3, 0x30, 0x55),
+    1220                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x74, 0x78, 0x48, 0x27, 0x34, 0x1E, 0xE2, 0x42),
+    1221                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAE, 0x72, 0x5B, 0xAC, 0xC1, 0x6D, 0xE3, 0x82),
+    1222                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x57, 0xAB, 0x46, 0xCB, 0xEA, 0x5E, 0x4B, 0x0B),
+    1223                 :            : };
+    1224                 :            : static const mbedtls_mpi_uint secp384r1_T_25_Y[] = {
+    1225                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFC, 0x08, 0xAD, 0x4E, 0x51, 0x9F, 0x2A, 0x52),
+    1226                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x68, 0x5C, 0x7D, 0x4C, 0xD6, 0xCF, 0xDD, 0x02),
+    1227                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD8, 0x76, 0x26, 0xE0, 0x8B, 0x10, 0xD9, 0x7C),
+    1228                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x30, 0xA7, 0x23, 0x4E, 0x5F, 0xD2, 0x42, 0x17),
+    1229                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD1, 0xE5, 0xA4, 0xEC, 0x77, 0x21, 0x34, 0x28),
+    1230                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5C, 0x14, 0x65, 0xEA, 0x4A, 0x85, 0xC3, 0x2F),
+    1231                 :            : };
+    1232                 :            : static const mbedtls_mpi_uint secp384r1_T_26_X[] = {
+    1233                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x19, 0xD8, 0x40, 0x27, 0x73, 0x15, 0x7E, 0x65),
+    1234                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF6, 0xBB, 0x53, 0x7E, 0x0F, 0x40, 0xC8, 0xD4),
+    1235                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEA, 0x37, 0x19, 0x73, 0xEF, 0x5A, 0x5E, 0x04),
+    1236                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9C, 0x73, 0x2B, 0x49, 0x7E, 0xAC, 0x97, 0x5C),
+    1237                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x15, 0xB2, 0xC3, 0x1E, 0x0E, 0xE7, 0xD2, 0x21),
+    1238                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8A, 0x08, 0xD6, 0xDD, 0xAC, 0x21, 0xD6, 0x3E),
+    1239                 :            : };
+    1240                 :            : static const mbedtls_mpi_uint secp384r1_T_26_Y[] = {
+    1241                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA9, 0x26, 0xBE, 0x6D, 0x6D, 0xF2, 0x38, 0x3F),
+    1242                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x08, 0x6C, 0x31, 0xA7, 0x49, 0x50, 0x3A, 0x89),
+    1243                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC3, 0x99, 0xC6, 0xF5, 0xD2, 0xC2, 0x30, 0x5A),
+    1244                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2A, 0xE4, 0xF6, 0x8B, 0x8B, 0x97, 0xE9, 0xB2),
+    1245                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDD, 0x21, 0xB7, 0x0D, 0xFC, 0x15, 0x54, 0x0B),
+    1246                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x65, 0x83, 0x1C, 0xA4, 0xCD, 0x6B, 0x9D, 0xF2),
+    1247                 :            : };
+    1248                 :            : static const mbedtls_mpi_uint secp384r1_T_27_X[] = {
+    1249                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD6, 0xE8, 0x4C, 0x48, 0xE4, 0xAA, 0x69, 0x93),
+    1250                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x27, 0x7A, 0x27, 0xFC, 0x37, 0x96, 0x1A, 0x7B),
+    1251                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6F, 0xE7, 0x30, 0xA5, 0xCF, 0x13, 0x46, 0x5C),
+    1252                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8C, 0xD8, 0xAF, 0x74, 0x23, 0x4D, 0x56, 0x84),
+    1253                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x32, 0x3D, 0x44, 0x14, 0x1B, 0x97, 0x83, 0xF0),
+    1254                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFA, 0x47, 0xD7, 0x5F, 0xFD, 0x98, 0x38, 0xF7),
+    1255                 :            : };
+    1256                 :            : static const mbedtls_mpi_uint secp384r1_T_27_Y[] = {
+    1257                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA3, 0x73, 0x64, 0x36, 0xFD, 0x7B, 0xC1, 0x15),
+    1258                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEA, 0x5D, 0x32, 0xD2, 0x47, 0x94, 0x89, 0x2D),
+    1259                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x51, 0xE9, 0x30, 0xAC, 0x06, 0xC8, 0x65, 0x04),
+    1260                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFA, 0x6C, 0xB9, 0x1B, 0xF7, 0x61, 0x49, 0x53),
+    1261                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD7, 0xFF, 0x32, 0x43, 0x80, 0xDA, 0xA6, 0xB1),
+    1262                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAC, 0xF8, 0x04, 0x01, 0x95, 0x35, 0xCE, 0x21),
+    1263                 :            : };
+    1264                 :            : static const mbedtls_mpi_uint secp384r1_T_28_X[] = {
+    1265                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6D, 0x06, 0x46, 0x0D, 0x51, 0xE2, 0xD8, 0xAC),
+    1266                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x14, 0x57, 0x1D, 0x6F, 0x79, 0xA0, 0xCD, 0xA6),
+    1267                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDF, 0xFB, 0x36, 0xCA, 0xAD, 0xF5, 0x9E, 0x41),
+    1268                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6F, 0x7A, 0x1D, 0x9E, 0x1D, 0x95, 0x48, 0xDC),
+    1269                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x81, 0x26, 0xA5, 0xB7, 0x15, 0x2C, 0xC2, 0xC6),
+    1270                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x86, 0x42, 0x72, 0xAA, 0x11, 0xDC, 0xC9, 0xB6),
+    1271                 :            : };
+    1272                 :            : static const mbedtls_mpi_uint secp384r1_T_28_Y[] = {
+    1273                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3F, 0x6C, 0x64, 0xA7, 0x62, 0x3C, 0xAB, 0xD4),
+    1274                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x48, 0x6A, 0x44, 0xD8, 0x60, 0xC0, 0xA8, 0x80),
+    1275                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x82, 0x76, 0x58, 0x12, 0x57, 0x3C, 0x89, 0x46),
+    1276                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x82, 0x4F, 0x83, 0xCE, 0xCB, 0xB8, 0xD0, 0x2C),
+    1277                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9A, 0x84, 0x04, 0xB0, 0xAD, 0xEB, 0xFA, 0xDF),
+    1278                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x34, 0xA4, 0xC3, 0x41, 0x44, 0x4E, 0x65, 0x3E),
+    1279                 :            : };
+    1280                 :            : static const mbedtls_mpi_uint secp384r1_T_29_X[] = {
+    1281                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB6, 0x16, 0xA9, 0x1C, 0xE7, 0x65, 0x20, 0xC1),
+    1282                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x58, 0x53, 0x32, 0xF8, 0xC0, 0xA6, 0xBD, 0x2C),
+    1283                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB7, 0xF0, 0xE6, 0x57, 0x31, 0xCC, 0x26, 0x6F),
+    1284                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x27, 0xE3, 0x54, 0x1C, 0x34, 0xD3, 0x17, 0xBC),
+    1285                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF5, 0xAE, 0xED, 0xFB, 0xCD, 0xE7, 0x1E, 0x9F),
+    1286                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5A, 0x16, 0x1C, 0x34, 0x40, 0x00, 0x1F, 0xB6),
+    1287                 :            : };
+    1288                 :            : static const mbedtls_mpi_uint secp384r1_T_29_Y[] = {
+    1289                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6A, 0x32, 0x00, 0xC2, 0xD4, 0x3B, 0x1A, 0x09),
+    1290                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x34, 0xE0, 0x99, 0x8F, 0x0C, 0x4A, 0x16, 0x44),
+    1291                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x83, 0x73, 0x18, 0x1B, 0xD4, 0x94, 0x29, 0x62),
+    1292                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x29, 0xA4, 0x2D, 0xB1, 0x9D, 0x74, 0x32, 0x67),
+    1293                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBF, 0xF4, 0xB1, 0x0C, 0x37, 0x62, 0x8B, 0x66),
+    1294                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC9, 0xFF, 0xDA, 0xE2, 0x35, 0xA3, 0xB6, 0x42),
+    1295                 :            : };
+    1296                 :            : static const mbedtls_mpi_uint secp384r1_T_30_X[] = {
+    1297                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x91, 0x49, 0x99, 0x65, 0xC5, 0xED, 0x16, 0xEF),
+    1298                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x79, 0x42, 0x9A, 0xF3, 0xA7, 0x4E, 0x6F, 0x2B),
+    1299                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7B, 0x0A, 0x7E, 0xC0, 0xD7, 0x4E, 0x07, 0x55),
+    1300                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD6, 0x7A, 0x31, 0x69, 0xA6, 0xB9, 0x15, 0x34),
+    1301                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA8, 0xE0, 0x72, 0xA4, 0x3F, 0xB9, 0xF8, 0x0C),
+    1302                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2B, 0x75, 0x32, 0x85, 0xA2, 0xDE, 0x37, 0x12),
+    1303                 :            : };
+    1304                 :            : static const mbedtls_mpi_uint secp384r1_T_30_Y[] = {
+    1305                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBC, 0xC0, 0x0D, 0xCF, 0x25, 0x41, 0xA4, 0xF4),
+    1306                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9B, 0xFC, 0xB2, 0x48, 0xC3, 0x85, 0x83, 0x4B),
+    1307                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2B, 0xBE, 0x0B, 0x58, 0x2D, 0x7A, 0x9A, 0x62),
+    1308                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC5, 0xF3, 0x81, 0x18, 0x1B, 0x74, 0x4F, 0x2C),
+    1309                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE2, 0x43, 0xA3, 0x0A, 0x16, 0x8B, 0xA3, 0x1E),
+    1310                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4A, 0x18, 0x81, 0x7B, 0x8D, 0xA2, 0x35, 0x77),
+    1311                 :            : };
+    1312                 :            : static const mbedtls_mpi_uint secp384r1_T_31_X[] = {
+    1313                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x86, 0xC4, 0x3F, 0x2C, 0xE7, 0x5F, 0x99, 0x03),
+    1314                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF0, 0x2B, 0xB7, 0xB6, 0xAD, 0x5A, 0x56, 0xFF),
+    1315                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x04, 0x00, 0xA4, 0x48, 0xC8, 0xE8, 0xBA, 0xBF),
+    1316                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE8, 0xA1, 0xB5, 0x13, 0x5A, 0xCD, 0x99, 0x9C),
+    1317                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB0, 0x95, 0xAD, 0xFC, 0xE2, 0x7E, 0xE7, 0xFE),
+    1318                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x96, 0x6B, 0xD1, 0x34, 0x99, 0x53, 0x63, 0x0B),
+    1319                 :            : };
+    1320                 :            : static const mbedtls_mpi_uint secp384r1_T_31_Y[] = {
+    1321                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x19, 0x8A, 0x77, 0x5D, 0x2B, 0xAB, 0x01, 0x28),
+    1322                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4E, 0x85, 0xD0, 0xD5, 0x49, 0x83, 0x4D, 0x60),
+    1323                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x81, 0xC6, 0x91, 0x30, 0x3B, 0x00, 0xAF, 0x7A),
+    1324                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3A, 0xAE, 0x61, 0x07, 0xE1, 0xB6, 0xE2, 0xC9),
+    1325                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x95, 0x43, 0x41, 0xFE, 0x9B, 0xB6, 0xF0, 0xA5),
+    1326                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB4, 0x97, 0xAE, 0xAD, 0x89, 0x88, 0x9E, 0x41),
+    1327                 :            : };
+    1328                 :            : static const mbedtls_ecp_point secp384r1_T[32] = {
+    1329                 :            :     ECP_POINT_INIT_XY_Z1(secp384r1_T_0_X, secp384r1_T_0_Y),
+    1330                 :            :     ECP_POINT_INIT_XY_Z0(secp384r1_T_1_X, secp384r1_T_1_Y),
+    1331                 :            :     ECP_POINT_INIT_XY_Z0(secp384r1_T_2_X, secp384r1_T_2_Y),
+    1332                 :            :     ECP_POINT_INIT_XY_Z0(secp384r1_T_3_X, secp384r1_T_3_Y),
+    1333                 :            :     ECP_POINT_INIT_XY_Z0(secp384r1_T_4_X, secp384r1_T_4_Y),
+    1334                 :            :     ECP_POINT_INIT_XY_Z0(secp384r1_T_5_X, secp384r1_T_5_Y),
+    1335                 :            :     ECP_POINT_INIT_XY_Z0(secp384r1_T_6_X, secp384r1_T_6_Y),
+    1336                 :            :     ECP_POINT_INIT_XY_Z0(secp384r1_T_7_X, secp384r1_T_7_Y),
+    1337                 :            :     ECP_POINT_INIT_XY_Z0(secp384r1_T_8_X, secp384r1_T_8_Y),
+    1338                 :            :     ECP_POINT_INIT_XY_Z0(secp384r1_T_9_X, secp384r1_T_9_Y),
+    1339                 :            :     ECP_POINT_INIT_XY_Z0(secp384r1_T_10_X, secp384r1_T_10_Y),
+    1340                 :            :     ECP_POINT_INIT_XY_Z0(secp384r1_T_11_X, secp384r1_T_11_Y),
+    1341                 :            :     ECP_POINT_INIT_XY_Z0(secp384r1_T_12_X, secp384r1_T_12_Y),
+    1342                 :            :     ECP_POINT_INIT_XY_Z0(secp384r1_T_13_X, secp384r1_T_13_Y),
+    1343                 :            :     ECP_POINT_INIT_XY_Z0(secp384r1_T_14_X, secp384r1_T_14_Y),
+    1344                 :            :     ECP_POINT_INIT_XY_Z0(secp384r1_T_15_X, secp384r1_T_15_Y),
+    1345                 :            :     ECP_POINT_INIT_XY_Z0(secp384r1_T_16_X, secp384r1_T_16_Y),
+    1346                 :            :     ECP_POINT_INIT_XY_Z0(secp384r1_T_17_X, secp384r1_T_17_Y),
+    1347                 :            :     ECP_POINT_INIT_XY_Z0(secp384r1_T_18_X, secp384r1_T_18_Y),
+    1348                 :            :     ECP_POINT_INIT_XY_Z0(secp384r1_T_19_X, secp384r1_T_19_Y),
+    1349                 :            :     ECP_POINT_INIT_XY_Z0(secp384r1_T_20_X, secp384r1_T_20_Y),
+    1350                 :            :     ECP_POINT_INIT_XY_Z0(secp384r1_T_21_X, secp384r1_T_21_Y),
+    1351                 :            :     ECP_POINT_INIT_XY_Z0(secp384r1_T_22_X, secp384r1_T_22_Y),
+    1352                 :            :     ECP_POINT_INIT_XY_Z0(secp384r1_T_23_X, secp384r1_T_23_Y),
+    1353                 :            :     ECP_POINT_INIT_XY_Z0(secp384r1_T_24_X, secp384r1_T_24_Y),
+    1354                 :            :     ECP_POINT_INIT_XY_Z0(secp384r1_T_25_X, secp384r1_T_25_Y),
+    1355                 :            :     ECP_POINT_INIT_XY_Z0(secp384r1_T_26_X, secp384r1_T_26_Y),
+    1356                 :            :     ECP_POINT_INIT_XY_Z0(secp384r1_T_27_X, secp384r1_T_27_Y),
+    1357                 :            :     ECP_POINT_INIT_XY_Z0(secp384r1_T_28_X, secp384r1_T_28_Y),
+    1358                 :            :     ECP_POINT_INIT_XY_Z0(secp384r1_T_29_X, secp384r1_T_29_Y),
+    1359                 :            :     ECP_POINT_INIT_XY_Z0(secp384r1_T_30_X, secp384r1_T_30_Y),
+    1360                 :            :     ECP_POINT_INIT_XY_Z0(secp384r1_T_31_X, secp384r1_T_31_Y),
+    1361                 :            : };
+    1362                 :            : #else
+    1363                 :            : #define secp384r1_T NULL
+    1364                 :            : #endif
+    1365                 :            : 
+    1366                 :            : #endif /* MBEDTLS_ECP_DP_SECP384R1_ENABLED */
+    1367                 :            : 
+    1368                 :            : /*
+    1369                 :            :  * Domain parameters for secp521r1
+    1370                 :            :  */
+    1371                 :            : #if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED)
+    1372                 :            : static const mbedtls_mpi_uint secp521r1_p[] = {
+    1373                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
+    1374                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
+    1375                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
+    1376                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
+    1377                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
+    1378                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
+    1379                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
+    1380                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
+    1381                 :            :     MBEDTLS_BYTES_TO_T_UINT_2(0xFF, 0x01),
+    1382                 :            : };
+    1383                 :            : static const mbedtls_mpi_uint secp521r1_b[] = {
+    1384                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x00, 0x3F, 0x50, 0x6B, 0xD4, 0x1F, 0x45, 0xEF),
+    1385                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF1, 0x34, 0x2C, 0x3D, 0x88, 0xDF, 0x73, 0x35),
+    1386                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x07, 0xBF, 0xB1, 0x3B, 0xBD, 0xC0, 0x52, 0x16),
+    1387                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7B, 0x93, 0x7E, 0xEC, 0x51, 0x39, 0x19, 0x56),
+    1388                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE1, 0x09, 0xF1, 0x8E, 0x91, 0x89, 0xB4, 0xB8),
+    1389                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF3, 0x15, 0xB3, 0x99, 0x5B, 0x72, 0xDA, 0xA2),
+    1390                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEE, 0x40, 0x85, 0xB6, 0xA0, 0x21, 0x9A, 0x92),
+    1391                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1F, 0x9A, 0x1C, 0x8E, 0x61, 0xB9, 0x3E, 0x95),
+    1392                 :            :     MBEDTLS_BYTES_TO_T_UINT_2(0x51, 0x00),
+    1393                 :            : };
+    1394                 :            : static const mbedtls_mpi_uint secp521r1_gx[] = {
+    1395                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x66, 0xBD, 0xE5, 0xC2, 0x31, 0x7E, 0x7E, 0xF9),
+    1396                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9B, 0x42, 0x6A, 0x85, 0xC1, 0xB3, 0x48, 0x33),
+    1397                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDE, 0xA8, 0xFF, 0xA2, 0x27, 0xC1, 0x1D, 0xFE),
+    1398                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x28, 0x59, 0xE7, 0xEF, 0x77, 0x5E, 0x4B, 0xA1),
+    1399                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBA, 0x3D, 0x4D, 0x6B, 0x60, 0xAF, 0x28, 0xF8),
+    1400                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x21, 0xB5, 0x3F, 0x05, 0x39, 0x81, 0x64, 0x9C),
+    1401                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x42, 0xB4, 0x95, 0x23, 0x66, 0xCB, 0x3E, 0x9E),
+    1402                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCD, 0xE9, 0x04, 0x04, 0xB7, 0x06, 0x8E, 0x85),
+    1403                 :            :     MBEDTLS_BYTES_TO_T_UINT_2(0xC6, 0x00),
+    1404                 :            : };
+    1405                 :            : static const mbedtls_mpi_uint secp521r1_gy[] = {
+    1406                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x50, 0x66, 0xD1, 0x9F, 0x76, 0x94, 0xBE, 0x88),
+    1407                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x40, 0xC2, 0x72, 0xA2, 0x86, 0x70, 0x3C, 0x35),
+    1408                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x61, 0x07, 0xAD, 0x3F, 0x01, 0xB9, 0x50, 0xC5),
+    1409                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x40, 0x26, 0xF4, 0x5E, 0x99, 0x72, 0xEE, 0x97),
+    1410                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2C, 0x66, 0x3E, 0x27, 0x17, 0xBD, 0xAF, 0x17),
+    1411                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x68, 0x44, 0x9B, 0x57, 0x49, 0x44, 0xF5, 0x98),
+    1412                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD9, 0x1B, 0x7D, 0x2C, 0xB4, 0x5F, 0x8A, 0x5C),
+    1413                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x04, 0xC0, 0x3B, 0x9A, 0x78, 0x6A, 0x29, 0x39),
+    1414                 :            :     MBEDTLS_BYTES_TO_T_UINT_2(0x18, 0x01),
+    1415                 :            : };
+    1416                 :            : static const mbedtls_mpi_uint secp521r1_n[] = {
+    1417                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x09, 0x64, 0x38, 0x91, 0x1E, 0xB7, 0x6F, 0xBB),
+    1418                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAE, 0x47, 0x9C, 0x89, 0xB8, 0xC9, 0xB5, 0x3B),
+    1419                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD0, 0xA5, 0x09, 0xF7, 0x48, 0x01, 0xCC, 0x7F),
+    1420                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6B, 0x96, 0x2F, 0xBF, 0x83, 0x87, 0x86, 0x51),
+    1421                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFA, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
+    1422                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
+    1423                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
+    1424                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
+    1425                 :            :     MBEDTLS_BYTES_TO_T_UINT_2(0xFF, 0x01),
+    1426                 :            : };
+    1427                 :            : #if MBEDTLS_ECP_FIXED_POINT_OPTIM == 1
+    1428                 :            : static const mbedtls_mpi_uint secp521r1_T_0_X[] = {
+    1429                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x66, 0xBD, 0xE5, 0xC2, 0x31, 0x7E, 0x7E, 0xF9),
+    1430                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9B, 0x42, 0x6A, 0x85, 0xC1, 0xB3, 0x48, 0x33),
+    1431                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDE, 0xA8, 0xFF, 0xA2, 0x27, 0xC1, 0x1D, 0xFE),
+    1432                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x28, 0x59, 0xE7, 0xEF, 0x77, 0x5E, 0x4B, 0xA1),
+    1433                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBA, 0x3D, 0x4D, 0x6B, 0x60, 0xAF, 0x28, 0xF8),
+    1434                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x21, 0xB5, 0x3F, 0x05, 0x39, 0x81, 0x64, 0x9C),
+    1435                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x42, 0xB4, 0x95, 0x23, 0x66, 0xCB, 0x3E, 0x9E),
+    1436                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCD, 0xE9, 0x04, 0x04, 0xB7, 0x06, 0x8E, 0x85),
+    1437                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1438                 :            : };
+    1439                 :            : static const mbedtls_mpi_uint secp521r1_T_0_Y[] = {
+    1440                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x50, 0x66, 0xD1, 0x9F, 0x76, 0x94, 0xBE, 0x88),
+    1441                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x40, 0xC2, 0x72, 0xA2, 0x86, 0x70, 0x3C, 0x35),
+    1442                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x61, 0x07, 0xAD, 0x3F, 0x01, 0xB9, 0x50, 0xC5),
+    1443                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x40, 0x26, 0xF4, 0x5E, 0x99, 0x72, 0xEE, 0x97),
+    1444                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2C, 0x66, 0x3E, 0x27, 0x17, 0xBD, 0xAF, 0x17),
+    1445                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x68, 0x44, 0x9B, 0x57, 0x49, 0x44, 0xF5, 0x98),
+    1446                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD9, 0x1B, 0x7D, 0x2C, 0xB4, 0x5F, 0x8A, 0x5C),
+    1447                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x04, 0xC0, 0x3B, 0x9A, 0x78, 0x6A, 0x29, 0x39),
+    1448                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x18, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1449                 :            : };
+    1450                 :            : static const mbedtls_mpi_uint secp521r1_T_1_X[] = {
+    1451                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2F, 0xB1, 0x2D, 0xEB, 0x27, 0x2F, 0xE8, 0xDA),
+    1452                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x98, 0x4B, 0x44, 0x25, 0xDB, 0x5C, 0x5F, 0x67),
+    1453                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x13, 0x85, 0x28, 0x78, 0x2E, 0x75, 0x34, 0x32),
+    1454                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x69, 0x57, 0x0F, 0x73, 0x78, 0x7A, 0xE3, 0x53),
+    1455                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8D, 0xD8, 0xEC, 0xDC, 0xDA, 0x04, 0xAD, 0xAB),
+    1456                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x34, 0x8A, 0x09, 0xF3, 0x58, 0x79, 0xD8, 0x29),
+    1457                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x63, 0x03, 0xCB, 0x50, 0x1A, 0x7F, 0x56, 0x00),
+    1458                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF6, 0xA6, 0x78, 0x38, 0x85, 0x67, 0x0B, 0x40),
+    1459                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x83, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1460                 :            : };
+    1461                 :            : static const mbedtls_mpi_uint secp521r1_T_1_Y[] = {
+    1462                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8A, 0xD5, 0xD2, 0x22, 0xC4, 0x00, 0x3B, 0xBA),
+    1463                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD5, 0x93, 0x0E, 0x7B, 0x85, 0x51, 0xC3, 0x06),
+    1464                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3D, 0xA6, 0x5F, 0x54, 0x49, 0x02, 0x81, 0x78),
+    1465                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x22, 0xE9, 0x6B, 0x3A, 0x92, 0xE7, 0x72, 0x1D),
+    1466                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6F, 0x5F, 0x28, 0x9E, 0x91, 0x27, 0x88, 0xE3),
+    1467                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEF, 0x28, 0x31, 0xB3, 0x84, 0xCA, 0x12, 0x32),
+    1468                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3D, 0xF9, 0xAC, 0x22, 0x10, 0x0A, 0x64, 0x41),
+    1469                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE9, 0xC6, 0x33, 0x1F, 0x69, 0x19, 0x18, 0xBF),
+    1470                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBE, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1471                 :            : };
+    1472                 :            : static const mbedtls_mpi_uint secp521r1_T_2_X[] = {
+    1473                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA0, 0x48, 0xB8, 0xC7, 0x37, 0x5A, 0x00, 0x36),
+    1474                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x07, 0xCC, 0x32, 0xE0, 0xEE, 0x03, 0xC2, 0xBA),
+    1475                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC4, 0x29, 0xC2, 0xE4, 0x6E, 0x24, 0x20, 0x8D),
+    1476                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x06, 0x6B, 0x7F, 0x7B, 0xF9, 0xB0, 0xB8, 0x13),
+    1477                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1D, 0x7B, 0x3C, 0xE1, 0x19, 0xA1, 0x23, 0x02),
+    1478                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2A, 0xE3, 0xC2, 0x53, 0xC0, 0x07, 0x13, 0xA9),
+    1479                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x07, 0xFE, 0x36, 0x35, 0x9F, 0x5E, 0x59, 0xCE),
+    1480                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1D, 0x55, 0x89, 0x84, 0xBC, 0xEF, 0xA2, 0xC2),
+    1481                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1482                 :            : };
+    1483                 :            : static const mbedtls_mpi_uint secp521r1_T_2_Y[] = {
+    1484                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFD, 0x1A, 0x08, 0x67, 0xB4, 0xE7, 0x22, 0xED),
+    1485                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x76, 0x26, 0xDF, 0x81, 0x3C, 0x5F, 0x1C, 0xDA),
+    1486                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE0, 0x4D, 0xD0, 0x0A, 0x48, 0x06, 0xF4, 0x48),
+    1487                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x73, 0x18, 0x39, 0xF7, 0xD1, 0x20, 0x77, 0x8D),
+    1488                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x78, 0x8F, 0x44, 0x13, 0xCB, 0x78, 0x11, 0x11),
+    1489                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x33, 0xE2, 0x49, 0xEA, 0x43, 0x79, 0x08, 0x39),
+    1490                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x01, 0xD1, 0xD8, 0x73, 0x2C, 0x71, 0x2F, 0x69),
+    1491                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x21, 0xE5, 0xE7, 0xF4, 0x46, 0xAB, 0x20, 0xCA),
+    1492                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1493                 :            : };
+    1494                 :            : static const mbedtls_mpi_uint secp521r1_T_3_X[] = {
+    1495                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8C, 0x0B, 0xB9, 0x71, 0x1A, 0x27, 0xB7, 0xA7),
+    1496                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2A, 0xA2, 0x2C, 0xD1, 0xDA, 0xBC, 0xC1, 0xBD),
+    1497                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x10, 0xA3, 0x10, 0x1F, 0x90, 0xF2, 0xA5, 0x52),
+    1498                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x28, 0xFB, 0x20, 0xF4, 0xC0, 0x70, 0xC0, 0xF5),
+    1499                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8F, 0xA7, 0x99, 0xF0, 0xA5, 0xD3, 0x09, 0xDD),
+    1500                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x26, 0xE8, 0x14, 0x39, 0xBE, 0xCB, 0x60, 0xAF),
+    1501                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9F, 0xD6, 0x14, 0xA9, 0xC9, 0x20, 0xC3, 0xEA),
+    1502                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5D, 0xA8, 0x5B, 0xFD, 0x2D, 0x96, 0xBC, 0x78),
+    1503                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1504                 :            : };
+    1505                 :            : static const mbedtls_mpi_uint secp521r1_T_3_Y[] = {
+    1506                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9D, 0x04, 0x45, 0xBE, 0xCE, 0x75, 0x95, 0xF6),
+    1507                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCC, 0xDA, 0x58, 0x49, 0x35, 0x09, 0x8D, 0x41),
+    1508                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x76, 0xF0, 0xC0, 0x36, 0xF2, 0xA6, 0x2D, 0x14),
+    1509                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE7, 0xFC, 0x3D, 0xA8, 0xFB, 0x3C, 0xD2, 0x51),
+    1510                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x01, 0x4D, 0x71, 0x09, 0x18, 0x42, 0xF0, 0x2D),
+    1511                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8D, 0xC1, 0xCE, 0x9E, 0x6A, 0x49, 0x60, 0x12),
+    1512                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAD, 0xB1, 0x00, 0xF7, 0xA1, 0x7A, 0x31, 0xB4),
+    1513                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x41, 0xC3, 0x86, 0xCD, 0x20, 0x4A, 0x17, 0x86),
+    1514                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6C, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1515                 :            : };
+    1516                 :            : static const mbedtls_mpi_uint secp521r1_T_4_X[] = {
+    1517                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x98, 0xAB, 0x8B, 0x47, 0x8D, 0xAA, 0xA6, 0x5B),
+    1518                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC4, 0x97, 0xF0, 0xBC, 0x2D, 0xDC, 0x9D, 0x84),
+    1519                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x01, 0x86, 0xB0, 0x74, 0xB2, 0xF4, 0xF6, 0x67),
+    1520                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAC, 0xBD, 0xAC, 0xE3, 0x8F, 0x43, 0x5C, 0xB1),
+    1521                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x37, 0xC3, 0xE2, 0x6E, 0x25, 0x49, 0xCD, 0x0B),
+    1522                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x64, 0x5E, 0x08, 0xB3, 0xB9, 0xAC, 0x5F, 0xD1),
+    1523                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x08, 0xB7, 0xD1, 0xF4, 0xDC, 0x19, 0xE9, 0xC8),
+    1524                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x49, 0xE4, 0xFA, 0xE1, 0x36, 0x3E, 0xED, 0x6E),
+    1525                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1526                 :            : };
+    1527                 :            : static const mbedtls_mpi_uint secp521r1_T_4_Y[] = {
+    1528                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x00, 0x67, 0x92, 0x84, 0x6E, 0x48, 0x03, 0x51),
+    1529                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9E, 0x95, 0xEF, 0x8F, 0xB2, 0x82, 0x6B, 0x1C),
+    1530                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8D, 0xFA, 0xB9, 0x55, 0x23, 0xFE, 0x09, 0xB3),
+    1531                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEF, 0x79, 0x85, 0x4B, 0x0E, 0xD4, 0x35, 0xDB),
+    1532                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9A, 0x27, 0x45, 0x81, 0xE0, 0x88, 0x52, 0xAD),
+    1533                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x17, 0x63, 0xA2, 0x4B, 0xBC, 0x5D, 0xB1, 0x92),
+    1534                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x28, 0x8C, 0x83, 0xD9, 0x3E, 0xD3, 0x42, 0xDA),
+    1535                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x99, 0x03, 0x3A, 0x31, 0xBA, 0xE9, 0x3A, 0xD1),
+    1536                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x47, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1537                 :            : };
+    1538                 :            : static const mbedtls_mpi_uint secp521r1_T_5_X[] = {
+    1539                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x35, 0x10, 0xCD, 0x2D, 0x00, 0xFE, 0x32, 0xA7),
+    1540                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE4, 0x6E, 0x1F, 0xDA, 0xF8, 0x6F, 0x4D, 0x03),
+    1541                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x09, 0x79, 0x7D, 0x09, 0xE5, 0xD3, 0x03, 0x21),
+    1542                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x58, 0xC3, 0xBE, 0xDF, 0x07, 0x65, 0x49, 0xCC),
+    1543                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x08, 0x57, 0x33, 0xEF, 0xAE, 0x4F, 0x04, 0x27),
+    1544                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9A, 0xE9, 0x9B, 0xFE, 0xBF, 0xE6, 0x85, 0xF6),
+    1545                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBD, 0xBA, 0xAA, 0x06, 0xC4, 0xC6, 0xB8, 0x57),
+    1546                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0C, 0x83, 0x01, 0xA9, 0xF6, 0x51, 0xE7, 0xB8),
+    1547                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1B, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1548                 :            : };
+    1549                 :            : static const mbedtls_mpi_uint secp521r1_T_5_Y[] = {
+    1550                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB9, 0xA6, 0x15, 0x8E, 0xAB, 0x1F, 0x10, 0x87),
+    1551                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x74, 0x08, 0x27, 0x1A, 0xA1, 0x21, 0xAD, 0xF5),
+    1552                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x02, 0x09, 0x90, 0x6E, 0x50, 0x90, 0x9A, 0x5D),
+    1553                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x86, 0x9A, 0xFE, 0xD7, 0xA1, 0xF5, 0xA2, 0x15),
+    1554                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE8, 0x7D, 0xE3, 0xDC, 0x21, 0xFB, 0xA4, 0x7B),
+    1555                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB9, 0xBF, 0x07, 0xFF, 0x45, 0xDF, 0x51, 0x77),
+    1556                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0B, 0x5C, 0x34, 0x02, 0x62, 0x9B, 0x08, 0x12),
+    1557                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x86, 0xCE, 0x9A, 0x6A, 0xEC, 0x75, 0xF6, 0x46),
+    1558                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1559                 :            : };
+    1560                 :            : static const mbedtls_mpi_uint secp521r1_T_6_X[] = {
+    1561                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE6, 0x59, 0xF4, 0x78, 0x3C, 0x60, 0xB1, 0x4A),
+    1562                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3E, 0x37, 0x84, 0x6A, 0xDC, 0xF2, 0x9A, 0x7D),
+    1563                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x40, 0x9A, 0x9A, 0x15, 0x36, 0xE0, 0x2B, 0x2D),
+    1564                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEC, 0x38, 0x9C, 0x50, 0x3D, 0x1E, 0x37, 0x82),
+    1565                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB7, 0x79, 0xF0, 0x92, 0xF2, 0x8B, 0x18, 0x82),
+    1566                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x17, 0xE0, 0x82, 0x1E, 0x80, 0x82, 0x4B, 0xD7),
+    1567                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFA, 0xBB, 0x59, 0x6B, 0x8A, 0x77, 0x41, 0x40),
+    1568                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA7, 0xF9, 0xD4, 0xB8, 0x4A, 0x82, 0xCF, 0x40),
+    1569                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1570                 :            : };
+    1571                 :            : static const mbedtls_mpi_uint secp521r1_T_6_Y[] = {
+    1572                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1E, 0x8C, 0xC8, 0x9B, 0x72, 0x9E, 0xF7, 0xF9),
+    1573                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB8, 0xCE, 0xE9, 0x77, 0x0A, 0x19, 0x59, 0x84),
+    1574                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9D, 0xA1, 0x41, 0x6A, 0x72, 0x4B, 0xB4, 0xDC),
+    1575                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0B, 0x35, 0x43, 0xE2, 0x8C, 0xBE, 0x0D, 0xE3),
+    1576                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC1, 0xEB, 0xAD, 0xF3, 0xA9, 0xA6, 0x68, 0xA1),
+    1577                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x81, 0x2F, 0xE2, 0x48, 0x0C, 0xDB, 0x1F, 0x42),
+    1578                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD1, 0x1E, 0x60, 0x9B, 0x2A, 0xD2, 0xC1, 0x3C),
+    1579                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC0, 0x64, 0xB5, 0xD2, 0xF6, 0xF6, 0x6E, 0x22),
+    1580                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x70, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1581                 :            : };
+    1582                 :            : static const mbedtls_mpi_uint secp521r1_T_7_X[] = {
+    1583                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC6, 0x3D, 0x30, 0x78, 0x10, 0x18, 0x41, 0x51),
+    1584                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x96, 0x1D, 0x1C, 0xE0, 0x6D, 0x83, 0xD1, 0x93),
+    1585                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7B, 0x03, 0x0B, 0xF5, 0x2F, 0x6C, 0x04, 0x98),
+    1586                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6C, 0x3E, 0xD5, 0xFC, 0x31, 0x5B, 0x3A, 0xEB),
+    1587                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x50, 0x82, 0x2F, 0xFB, 0xFE, 0xF8, 0x76, 0x39),
+    1588                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x85, 0x26, 0xDA, 0x9C, 0x36, 0xF5, 0x93, 0xD1),
+    1589                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4C, 0xE7, 0x6E, 0xD2, 0x7D, 0x81, 0x09, 0xC6),
+    1590                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD3, 0x03, 0xF9, 0x58, 0x48, 0x24, 0xA2, 0xEE),
+    1591                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1592                 :            : };
+    1593                 :            : static const mbedtls_mpi_uint secp521r1_T_7_Y[] = {
+    1594                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1B, 0x79, 0x0C, 0x8E, 0x6B, 0x95, 0xF3, 0xC4),
+    1595                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF4, 0x10, 0x5C, 0x87, 0x03, 0x39, 0xCF, 0x68),
+    1596                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAD, 0xF0, 0xF7, 0xC1, 0x07, 0xA4, 0xF4, 0x3F),
+    1597                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x32, 0xE8, 0x02, 0x89, 0x65, 0xC4, 0x72, 0x36),
+    1598                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB4, 0x88, 0xEA, 0x96, 0x67, 0x0B, 0x5D, 0xDF),
+    1599                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA8, 0x75, 0x60, 0xA8, 0xBD, 0x74, 0xDF, 0x68),
+    1600                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6E, 0xE5, 0x71, 0x50, 0x67, 0xD0, 0xD2, 0xE6),
+    1601                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD5, 0xFC, 0xE5, 0xC7, 0x77, 0xB0, 0x7F, 0x8C),
+    1602                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF1, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1603                 :            : };
+    1604                 :            : static const mbedtls_mpi_uint secp521r1_T_8_X[] = {
+    1605                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x97, 0x86, 0x69, 0xCD, 0x0D, 0x9A, 0xBD, 0x66),
+    1606                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x58, 0x17, 0xBC, 0xBB, 0x59, 0x85, 0x7D, 0x0E),
+    1607                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8D, 0xA8, 0x76, 0xAC, 0x80, 0xA9, 0x72, 0xE0),
+    1608                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x74, 0x78, 0xC1, 0xE2, 0x4D, 0xAF, 0xF9, 0x3C),
+    1609                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAD, 0x97, 0x8E, 0x74, 0xC4, 0x4B, 0xB2, 0x85),
+    1610                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEA, 0xD8, 0xF6, 0xF3, 0xAF, 0x2F, 0x52, 0xE5),
+    1611                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x95, 0x57, 0xF4, 0xCE, 0xEE, 0x43, 0xED, 0x60),
+    1612                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7D, 0x46, 0x38, 0xDE, 0x20, 0xFD, 0x59, 0x18),
+    1613                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD7, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1614                 :            : };
+    1615                 :            : static const mbedtls_mpi_uint secp521r1_T_8_Y[] = {
+    1616                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1C, 0x18, 0xE8, 0x58, 0xB9, 0x76, 0x2C, 0xE6),
+    1617                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xED, 0x54, 0xE4, 0xFE, 0xC7, 0xBC, 0x31, 0x37),
+    1618                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF5, 0xF8, 0x89, 0xEE, 0x70, 0xB5, 0xB0, 0x2C),
+    1619                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x83, 0x22, 0x26, 0x9A, 0x53, 0xB9, 0x38, 0x0A),
+    1620                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x74, 0xA7, 0x19, 0x8C, 0x74, 0x7E, 0x88, 0x46),
+    1621                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB4, 0xDA, 0x0A, 0xE8, 0xDA, 0xA5, 0xBE, 0x1D),
+    1622                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x90, 0x5C, 0xF7, 0xB1, 0x0C, 0x72, 0xFB, 0x09),
+    1623                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x78, 0xE2, 0x23, 0xE7, 0x46, 0xB7, 0xE0, 0x91),
+    1624                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC5, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1625                 :            : };
+    1626                 :            : static const mbedtls_mpi_uint secp521r1_T_9_X[] = {
+    1627                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3A, 0x36, 0xBC, 0xBD, 0x48, 0x11, 0x8E, 0x72),
+    1628                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAB, 0xBB, 0xA1, 0xF7, 0x0B, 0x9E, 0xBF, 0xDF),
+    1629                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x68, 0x28, 0xE1, 0xA2, 0x8F, 0xFC, 0xFC, 0xD6),
+    1630                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x81, 0xFE, 0x19, 0x0A, 0xE5, 0xE7, 0x69, 0x39),
+    1631                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5E, 0xCD, 0x12, 0xF5, 0xBE, 0xD3, 0x04, 0xF1),
+    1632                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF5, 0xA8, 0x0D, 0x81, 0x59, 0xC4, 0x79, 0x98),
+    1633                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA3, 0xF3, 0x4B, 0x92, 0x65, 0xC3, 0x31, 0xAD),
+    1634                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x75, 0xB5, 0x4F, 0x4D, 0x91, 0xD4, 0xE2, 0xB2),
+    1635                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x51, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1636                 :            : };
+    1637                 :            : static const mbedtls_mpi_uint secp521r1_T_9_Y[] = {
+    1638                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x72, 0x09, 0x41, 0x79, 0x1D, 0x4D, 0x0D, 0x33),
+    1639                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBB, 0x31, 0x18, 0xBA, 0xA0, 0xF2, 0x6E, 0x7E),
+    1640                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x93, 0x5B, 0x4D, 0x4F, 0xAF, 0xC9, 0x8C, 0xA1),
+    1641                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x48, 0x99, 0x9C, 0x06, 0x68, 0xDE, 0xD8, 0x29),
+    1642                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA0, 0x04, 0xE1, 0xB5, 0x9D, 0x00, 0xBC, 0xB8),
+    1643                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x61, 0x95, 0x92, 0x8D, 0x72, 0xD3, 0x37, 0x42),
+    1644                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAB, 0x4B, 0x27, 0xA2, 0xE8, 0xA4, 0x26, 0xA1),
+    1645                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4F, 0x45, 0x9C, 0xA9, 0xCB, 0x9F, 0xBA, 0x85),
+    1646                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCB, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1647                 :            : };
+    1648                 :            : static const mbedtls_mpi_uint secp521r1_T_10_X[] = {
+    1649                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x08, 0x7E, 0x1B, 0x64, 0xF4, 0xE8, 0xA5, 0x55),
+    1650                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF7, 0x20, 0xA9, 0xCA, 0xF3, 0x89, 0xE5, 0xE1),
+    1651                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x83, 0xED, 0xFC, 0xAB, 0xD9, 0x0A, 0xB9, 0x07),
+    1652                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x08, 0x6F, 0x46, 0x7C, 0xCD, 0x78, 0xFF, 0x05),
+    1653                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x69, 0xAB, 0x71, 0x5A, 0x94, 0xAB, 0x20, 0x20),
+    1654                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC2, 0x2E, 0xEE, 0x87, 0x57, 0x1F, 0xAD, 0xD3),
+    1655                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x91, 0x4C, 0x3D, 0xFB, 0x7E, 0xA1, 0x8B, 0x07),
+    1656                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x69, 0xCF, 0x07, 0x86, 0xBA, 0x53, 0x37, 0xCF),
+    1657                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x38, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1658                 :            : };
+    1659                 :            : static const mbedtls_mpi_uint secp521r1_T_10_Y[] = {
+    1660                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x00, 0x26, 0xB2, 0xB9, 0xE2, 0x91, 0xE3, 0xB5),
+    1661                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x79, 0xC9, 0x54, 0x84, 0x08, 0x3D, 0x0B, 0xD2),
+    1662                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5D, 0xA8, 0x77, 0x2F, 0x64, 0x45, 0x99, 0x4C),
+    1663                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x87, 0x96, 0x16, 0x1F, 0xDB, 0x96, 0x28, 0x97),
+    1664                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x83, 0x2B, 0x8D, 0xFF, 0xA2, 0x4F, 0x55, 0xD3),
+    1665                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x71, 0xE6, 0x48, 0xBD, 0x99, 0x3D, 0x12, 0x57),
+    1666                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3F, 0x84, 0x59, 0xDA, 0xB9, 0xB6, 0x66, 0x12),
+    1667                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6D, 0x78, 0x41, 0x92, 0xDF, 0xF4, 0x3F, 0x63),
+    1668                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1F, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1669                 :            : };
+    1670                 :            : static const mbedtls_mpi_uint secp521r1_T_11_X[] = {
+    1671                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7E, 0x86, 0x6F, 0x4F, 0xBF, 0x67, 0xDF, 0x2F),
+    1672                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF2, 0x2B, 0x1E, 0x5F, 0x00, 0xEA, 0xF6, 0x56),
+    1673                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x90, 0xB9, 0x6A, 0x89, 0xD8, 0xC0, 0xD7, 0xA7),
+    1674                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCB, 0x9A, 0x32, 0x23, 0xA0, 0x02, 0x91, 0x58),
+    1675                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x42, 0x7F, 0x6A, 0x15, 0x64, 0x6A, 0x8B, 0xBB),
+    1676                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8A, 0x57, 0x82, 0x58, 0xA9, 0x56, 0xB5, 0xFB),
+    1677                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDD, 0x50, 0x92, 0x60, 0xCC, 0x81, 0x24, 0xA8),
+    1678                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x36, 0x3D, 0xAD, 0xDA, 0xD9, 0x51, 0x3E, 0x57),
+    1679                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1680                 :            : };
+    1681                 :            : static const mbedtls_mpi_uint secp521r1_T_11_Y[] = {
+    1682                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEC, 0xFE, 0x8F, 0xB0, 0x0B, 0xDE, 0x2E, 0x7E),
+    1683                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x79, 0xD2, 0xBE, 0xEF, 0xAC, 0x76, 0x71, 0xA3),
+    1684                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x55, 0xE8, 0x72, 0x0B, 0xAC, 0xFE, 0xCA, 0x5A),
+    1685                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAD, 0x5B, 0xC7, 0xFC, 0xE3, 0x3C, 0x7C, 0x4C),
+    1686                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA1, 0x04, 0xA7, 0xB9, 0x9B, 0x93, 0xC0, 0x2F),
+    1687                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x41, 0x48, 0x4B, 0x8E, 0x32, 0xC5, 0xF0, 0x6B),
+    1688                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB0, 0x42, 0x07, 0xC1, 0xF2, 0xF1, 0x72, 0x5B),
+    1689                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1E, 0x37, 0x54, 0x9C, 0x88, 0xD2, 0x62, 0xAA),
+    1690                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC1, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1691                 :            : };
+    1692                 :            : static const mbedtls_mpi_uint secp521r1_T_12_X[] = {
+    1693                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC2, 0x19, 0x8A, 0x89, 0x58, 0xA2, 0x0F, 0xDB),
+    1694                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x01, 0xCC, 0x4C, 0x97, 0x30, 0x66, 0x34, 0x26),
+    1695                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x83, 0x6A, 0x1E, 0x1F, 0xDB, 0xC9, 0x5E, 0x13),
+    1696                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1B, 0x4D, 0x49, 0xFF, 0x9B, 0x9C, 0xAC, 0x9B),
+    1697                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD7, 0xE4, 0x4B, 0xF2, 0xD4, 0x1A, 0xD2, 0x78),
+    1698                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCD, 0xDA, 0xE8, 0x61, 0x9F, 0xC8, 0x49, 0x32),
+    1699                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x51, 0xCB, 0xF2, 0x2D, 0x85, 0xF6, 0x8D, 0x52),
+    1700                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB7, 0xC5, 0xCD, 0x2C, 0x79, 0xC6, 0x0E, 0x4F),
+    1701                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDB, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1702                 :            : };
+    1703                 :            : static const mbedtls_mpi_uint secp521r1_T_12_Y[] = {
+    1704                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x73, 0x1D, 0x55, 0x0F, 0xF8, 0x22, 0x9F, 0x78),
+    1705                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x76, 0x56, 0xBA, 0xE7, 0x57, 0x32, 0xEC, 0x42),
+    1706                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x65, 0x9A, 0xC6, 0x4C, 0x09, 0xC4, 0x52, 0x3F),
+    1707                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB6, 0x1E, 0x6F, 0xF4, 0x7D, 0x27, 0xDD, 0xAF),
+    1708                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x94, 0x11, 0x16, 0xEC, 0x79, 0x83, 0xAD, 0xAE),
+    1709                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x46, 0x4E, 0x92, 0x1F, 0x19, 0x7D, 0x65, 0xDC),
+    1710                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x09, 0xFF, 0x78, 0x15, 0x45, 0x63, 0x32, 0xE4),
+    1711                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBF, 0x91, 0xD0, 0x78, 0x58, 0xDA, 0x50, 0x47),
+    1712                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x73, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1713                 :            : };
+    1714                 :            : static const mbedtls_mpi_uint secp521r1_T_13_X[] = {
+    1715                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x23, 0xDE, 0x40, 0xF6, 0x41, 0xB4, 0x3B, 0x95),
+    1716                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC6, 0x8D, 0xE0, 0xE1, 0xA9, 0xF0, 0x35, 0x5D),
+    1717                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE6, 0xD4, 0xBA, 0x7B, 0xCC, 0x1B, 0x3A, 0x32),
+    1718                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD0, 0x5A, 0x2E, 0x74, 0x47, 0x14, 0xC3, 0x4D),
+    1719                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7D, 0xF0, 0x8B, 0x06, 0x15, 0x8E, 0x0E, 0xCA),
+    1720                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB5, 0xD2, 0xEB, 0x97, 0x50, 0x7D, 0x31, 0xFC),
+    1721                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x42, 0x93, 0x4C, 0xDB, 0x97, 0x79, 0x44, 0xF5),
+    1722                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9C, 0xA2, 0xA0, 0x0B, 0xC8, 0x3A, 0x8A, 0xF9),
+    1723                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1724                 :            : };
+    1725                 :            : static const mbedtls_mpi_uint secp521r1_T_13_Y[] = {
+    1726                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x79, 0x50, 0x92, 0x9E, 0x24, 0x1F, 0xCB, 0x4C),
+    1727                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD3, 0x16, 0xC9, 0xC5, 0x3D, 0x5A, 0xAF, 0x97),
+    1728                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x18, 0xE3, 0x97, 0xE4, 0xA8, 0x50, 0xF6, 0x7E),
+    1729                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x45, 0x57, 0x97, 0x42, 0x78, 0x92, 0x49, 0x0D),
+    1730                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA5, 0xEB, 0x62, 0x24, 0xFB, 0x8F, 0x32, 0xCF),
+    1731                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF3, 0x0C, 0x36, 0x6E, 0x8F, 0xE8, 0xE8, 0x8E),
+    1732                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC2, 0xD3, 0x7C, 0xC7, 0x8D, 0x3F, 0x5C, 0xE1),
+    1733                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6A, 0x64, 0x6A, 0x73, 0x10, 0x79, 0xB8, 0x5A),
+    1734                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCB, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1735                 :            : };
+    1736                 :            : static const mbedtls_mpi_uint secp521r1_T_14_X[] = {
+    1737                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x51, 0xF9, 0xEF, 0xA5, 0x20, 0x4A, 0x5C, 0xA1),
+    1738                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2F, 0xF3, 0xF4, 0x49, 0x5B, 0x73, 0xAA, 0x1B),
+    1739                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC6, 0xF2, 0xEA, 0x0F, 0x00, 0xAD, 0x53, 0xAB),
+    1740                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x03, 0xB8, 0x66, 0xED, 0xC4, 0x2B, 0x4C, 0x35),
+    1741                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3A, 0x2F, 0xC1, 0x9A, 0x37, 0xD2, 0x7F, 0x58),
+    1742                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x29, 0xA7, 0x81, 0x38, 0x64, 0xC9, 0x37, 0x38),
+    1743                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBE, 0x3B, 0x6C, 0x9F, 0x5B, 0xD9, 0x8B, 0x1D),
+    1744                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB6, 0x14, 0xD9, 0x08, 0xD8, 0xD2, 0x7E, 0x23),
+    1745                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1746                 :            : };
+    1747                 :            : static const mbedtls_mpi_uint secp521r1_T_14_Y[] = {
+    1748                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x15, 0x71, 0xE6, 0x3D, 0xD1, 0xB0, 0xE7, 0xCD),
+    1749                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5B, 0x81, 0x23, 0xEC, 0x2D, 0x42, 0x45, 0xE6),
+    1750                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x51, 0x5B, 0x44, 0x6B, 0x89, 0x03, 0x67, 0x28),
+    1751                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x84, 0x27, 0xAE, 0x80, 0x5A, 0x33, 0xBE, 0x11),
+    1752                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE3, 0xB6, 0x64, 0x1A, 0xDF, 0xD3, 0x85, 0x91),
+    1753                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x67, 0x8C, 0x22, 0xBA, 0xD0, 0xBD, 0xCC, 0xA0),
+    1754                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF7, 0x3C, 0x01, 0x3A, 0xFF, 0x9D, 0xC7, 0x6B),
+    1755                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0C, 0xC7, 0x64, 0xB4, 0x59, 0x4E, 0x9F, 0x22),
+    1756                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x85, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1757                 :            : };
+    1758                 :            : static const mbedtls_mpi_uint secp521r1_T_15_X[] = {
+    1759                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA1, 0x34, 0x0A, 0x41, 0x94, 0xA8, 0xF2, 0xB7),
+    1760                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF6, 0xD4, 0xE4, 0xF0, 0x97, 0x45, 0x6D, 0xCA),
+    1761                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8F, 0x1F, 0x4D, 0x6D, 0xFE, 0xA0, 0xC4, 0x84),
+    1762                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1D, 0x28, 0x5C, 0x40, 0xBB, 0x65, 0xD4, 0x42),
+    1763                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x98, 0xA8, 0x87, 0x35, 0x20, 0x3A, 0x89, 0x44),
+    1764                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD6, 0xFD, 0x4F, 0xAB, 0x2D, 0xD1, 0xD0, 0xC0),
+    1765                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x86, 0xE8, 0x00, 0xFC, 0x69, 0x52, 0xF8, 0xD5),
+    1766                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE1, 0x9A, 0x99, 0xE1, 0xDC, 0x9C, 0x3F, 0xD9),
+    1767                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x99, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1768                 :            : };
+    1769                 :            : static const mbedtls_mpi_uint secp521r1_T_15_Y[] = {
+    1770                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x12, 0x08, 0x98, 0xD9, 0xCA, 0x73, 0xD5, 0xA9),
+    1771                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB9, 0x2C, 0xE0, 0xA7, 0x3E, 0x91, 0xD7, 0x87),
+    1772                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x68, 0x04, 0xB0, 0x54, 0x09, 0xF4, 0x72, 0xB7),
+    1773                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC8, 0xEE, 0x28, 0xCC, 0xE8, 0x50, 0x78, 0x20),
+    1774                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0D, 0x91, 0x03, 0x76, 0xDB, 0x68, 0x24, 0x77),
+    1775                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7A, 0xE0, 0x56, 0xB2, 0x5D, 0x12, 0xD3, 0xB5),
+    1776                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0D, 0x42, 0x59, 0x8B, 0xDF, 0x67, 0xB5, 0xBE),
+    1777                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD1, 0xCC, 0xE5, 0x31, 0x53, 0x7A, 0x46, 0xB3),
+    1778                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDA, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1779                 :            : };
+    1780                 :            : static const mbedtls_mpi_uint secp521r1_T_16_X[] = {
+    1781                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCC, 0x8D, 0x59, 0xB5, 0x1B, 0x0F, 0xF4, 0xAF),
+    1782                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD9, 0x2F, 0xD1, 0x2C, 0xE0, 0xD8, 0x04, 0xEF),
+    1783                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAC, 0xF4, 0xD7, 0xBA, 0xB0, 0xA3, 0x7E, 0xC9),
+    1784                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCD, 0x08, 0x51, 0x56, 0xA6, 0x76, 0x67, 0x33),
+    1785                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8C, 0x17, 0x63, 0xFE, 0x56, 0xD0, 0xD9, 0x71),
+    1786                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAA, 0xF6, 0xC3, 0x14, 0x47, 0xC5, 0xA7, 0x31),
+    1787                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x72, 0x4C, 0x80, 0xF6, 0xA2, 0x57, 0xA7, 0x5D),
+    1788                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x11, 0xB3, 0x7B, 0xF8, 0x2F, 0xE1, 0x3E, 0x7B),
+    1789                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFA, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1790                 :            : };
+    1791                 :            : static const mbedtls_mpi_uint secp521r1_T_16_Y[] = {
+    1792                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x26, 0xF4, 0xF9, 0x6B, 0x7B, 0x90, 0xDF, 0x30),
+    1793                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1F, 0x82, 0xEF, 0x62, 0xA1, 0x4C, 0x53, 0xCA),
+    1794                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE6, 0x99, 0x76, 0x01, 0xBA, 0x8D, 0x0F, 0x54),
+    1795                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAF, 0xF4, 0x58, 0x73, 0x56, 0xFE, 0xDD, 0x7C),
+    1796                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF6, 0xCE, 0xF9, 0xE8, 0xA1, 0x34, 0xC3, 0x5B),
+    1797                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x09, 0x5F, 0xDC, 0x6A, 0x3D, 0xD8, 0x7F, 0x42),
+    1798                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC2, 0xF4, 0x51, 0xB8, 0xB8, 0xC1, 0xD7, 0x2F),
+    1799                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAE, 0x7D, 0x58, 0xD1, 0xD4, 0x1B, 0x4D, 0x23),
+    1800                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1801                 :            : };
+    1802                 :            : static const mbedtls_mpi_uint secp521r1_T_17_X[] = {
+    1803                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB9, 0x95, 0xDF, 0x00, 0xD8, 0x21, 0xDE, 0x94),
+    1804                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF7, 0x47, 0x3C, 0xC3, 0xB2, 0x01, 0x53, 0x5D),
+    1805                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1E, 0x17, 0x43, 0x23, 0xBD, 0xCA, 0x71, 0xF2),
+    1806                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x70, 0xBA, 0x0F, 0x4F, 0xDC, 0x41, 0x54, 0xBE),
+    1807                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD6, 0x39, 0x26, 0x70, 0x53, 0x32, 0x18, 0x11),
+    1808                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x32, 0x46, 0x07, 0x97, 0x3A, 0x57, 0xE0, 0x01),
+    1809                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD6, 0x92, 0x4F, 0xCE, 0xDF, 0x25, 0x80, 0x26),
+    1810                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5B, 0x6F, 0x9A, 0x03, 0x05, 0x4B, 0xD1, 0x47),
+    1811                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5D, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1812                 :            : };
+    1813                 :            : static const mbedtls_mpi_uint secp521r1_T_17_Y[] = {
+    1814                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x25, 0x01, 0x72, 0x30, 0x90, 0x17, 0x51, 0x20),
+    1815                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x74, 0xFB, 0x41, 0x65, 0x5C, 0xB4, 0x2D, 0xEE),
+    1816                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x66, 0xCD, 0xCD, 0xAA, 0x41, 0xCC, 0xBB, 0x07),
+    1817                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD4, 0xCE, 0x08, 0x0A, 0x63, 0xE9, 0xA2, 0xFF),
+    1818                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3D, 0xA8, 0x21, 0x7F, 0x7A, 0x5B, 0x9B, 0x81),
+    1819                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x10, 0x6B, 0x89, 0x44, 0x0A, 0x7F, 0x85, 0x5F),
+    1820                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7D, 0xDE, 0x7C, 0x19, 0x5C, 0x65, 0x26, 0x61),
+    1821                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD7, 0xAC, 0x62, 0x29, 0x4A, 0xF1, 0xD0, 0x81),
+    1822                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x38, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1823                 :            : };
+    1824                 :            : static const mbedtls_mpi_uint secp521r1_T_18_X[] = {
+    1825                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x32, 0x00, 0x40, 0x87, 0xEB, 0xA9, 0x58, 0x56),
+    1826                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAF, 0x51, 0x0B, 0xFF, 0x56, 0x35, 0x51, 0xB3),
+    1827                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7B, 0xAC, 0x08, 0x94, 0x71, 0xDA, 0xEC, 0x99),
+    1828                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5F, 0x4D, 0xC5, 0x7B, 0x31, 0x8B, 0x8D, 0x5E),
+    1829                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x15, 0x05, 0xF1, 0x3E, 0x9E, 0x8F, 0x17, 0x8F),
+    1830                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF0, 0x9C, 0x4B, 0x62, 0x94, 0xAD, 0x49, 0xFC),
+    1831                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0F, 0xC9, 0xC6, 0x8F, 0xFD, 0x33, 0x44, 0x34),
+    1832                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5F, 0x96, 0x17, 0x7F, 0x42, 0xBE, 0xF7, 0x0D),
+    1833                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1834                 :            : };
+    1835                 :            : static const mbedtls_mpi_uint secp521r1_T_18_Y[] = {
+    1836                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFB, 0x29, 0x39, 0x13, 0x08, 0x8D, 0x91, 0x47),
+    1837                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF6, 0x79, 0xF9, 0x2F, 0xA9, 0x0A, 0xCF, 0xD6),
+    1838                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAB, 0x87, 0x7A, 0xA3, 0x19, 0xAB, 0x55, 0xAD),
+    1839                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE8, 0x0B, 0x01, 0xC5, 0x56, 0x19, 0x9D, 0x9E),
+    1840                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x19, 0xDE, 0x82, 0x3B, 0xEA, 0xD3, 0x0B, 0x8C),
+    1841                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x65, 0x6B, 0xC7, 0xF3, 0x0F, 0x82, 0x87, 0x6C),
+    1842                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD8, 0x2E, 0x23, 0xF2, 0x39, 0x9D, 0x49, 0x70),
+    1843                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x31, 0xDE, 0xAF, 0x7A, 0xEE, 0xB0, 0xDA, 0x70),
+    1844                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x63, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1845                 :            : };
+    1846                 :            : static const mbedtls_mpi_uint secp521r1_T_19_X[] = {
+    1847                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x76, 0x4E, 0x2A, 0x50, 0xFD, 0x8E, 0xC0, 0xEB),
+    1848                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x52, 0x0F, 0x7C, 0x76, 0x63, 0xD8, 0x89, 0x45),
+    1849                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEC, 0x2D, 0xB9, 0x4E, 0xF4, 0xEE, 0x85, 0xCF),
+    1850                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC1, 0x95, 0x5C, 0x96, 0x5D, 0xAA, 0x59, 0x0B),
+    1851                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCA, 0xDB, 0xD2, 0x68, 0x8E, 0x5A, 0x94, 0x60),
+    1852                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD9, 0x02, 0xBF, 0x77, 0x9F, 0xB9, 0x4C, 0xC9),
+    1853                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2D, 0xDC, 0xC0, 0xCF, 0x81, 0x1E, 0xC4, 0x6C),
+    1854                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2B, 0xCC, 0x37, 0x86, 0xDC, 0xE2, 0x64, 0x72),
+    1855                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1856                 :            : };
+    1857                 :            : static const mbedtls_mpi_uint secp521r1_T_19_Y[] = {
+    1858                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2C, 0x30, 0xB1, 0x59, 0x20, 0x9D, 0x98, 0x28),
+    1859                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x77, 0x0C, 0x9D, 0xF8, 0x20, 0xDC, 0x90, 0xBA),
+    1860                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB1, 0xA0, 0xF4, 0xE7, 0x3E, 0x9C, 0x9E, 0xA2),
+    1861                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB5, 0x25, 0xA2, 0xB0, 0x54, 0xCD, 0x2E, 0x33),
+    1862                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEA, 0xD9, 0x42, 0xB0, 0x80, 0xB0, 0xA3, 0x38),
+    1863                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9F, 0xFE, 0x9D, 0x8D, 0x40, 0xFF, 0x27, 0x6D),
+    1864                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3A, 0x9D, 0xA6, 0x88, 0x3A, 0x8B, 0x6F, 0x14),
+    1865                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB6, 0x39, 0xEE, 0x1F, 0x3F, 0xB1, 0x4F, 0x63),
+    1866                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1867                 :            : };
+    1868                 :            : static const mbedtls_mpi_uint secp521r1_T_20_X[] = {
+    1869                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6D, 0xD7, 0x9E, 0xFF, 0xD2, 0x35, 0x67, 0x03),
+    1870                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCA, 0x4F, 0x15, 0x5D, 0xE3, 0xE8, 0x53, 0x86),
+    1871                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x92, 0xF7, 0x24, 0x98, 0xA2, 0xCB, 0x11, 0x68),
+    1872                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x06, 0x2E, 0x25, 0xE1, 0x94, 0xC5, 0xA3, 0x96),
+    1873                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE0, 0x82, 0x6E, 0xBA, 0xE7, 0x43, 0x25, 0xB0),
+    1874                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x18, 0x65, 0xB4, 0x49, 0x73, 0x18, 0x35, 0x54),
+    1875                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x59, 0x5B, 0xBC, 0x62, 0x86, 0x4C, 0xC1, 0xB7),
+    1876                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9B, 0xF2, 0x95, 0xA2, 0xBB, 0xA2, 0x35, 0x65),
+    1877                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1878                 :            : };
+    1879                 :            : static const mbedtls_mpi_uint secp521r1_T_20_Y[] = {
+    1880                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x72, 0x59, 0x62, 0xB0, 0x4B, 0x1E, 0xB4, 0xD8),
+    1881                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0D, 0x55, 0xCE, 0xB0, 0x69, 0xBA, 0x63, 0x10),
+    1882                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6E, 0x69, 0x86, 0xDB, 0x34, 0x7D, 0x68, 0x64),
+    1883                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDA, 0x06, 0xCA, 0x55, 0x44, 0x36, 0x2B, 0xBA),
+    1884                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6C, 0xD4, 0xC4, 0x3D, 0xCD, 0x9E, 0x69, 0xA4),
+    1885                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3F, 0x44, 0xE4, 0xBF, 0x31, 0xE6, 0x40, 0x9F),
+    1886                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7E, 0x4F, 0xFA, 0x75, 0xE3, 0xFB, 0x97, 0x0E),
+    1887                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x08, 0xC0, 0xBD, 0x1C, 0x48, 0xB0, 0x26, 0xD0),
+    1888                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD2, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1889                 :            : };
+    1890                 :            : static const mbedtls_mpi_uint secp521r1_T_21_X[] = {
+    1891                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1C, 0x7B, 0x32, 0xFA, 0xF2, 0x6D, 0x84, 0x8E),
+    1892                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA0, 0x21, 0x03, 0x1D, 0x0D, 0x22, 0x55, 0x67),
+    1893                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x18, 0xF9, 0x42, 0x03, 0x9C, 0xC2, 0xCB, 0xBA),
+    1894                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF8, 0xA1, 0x96, 0xD9, 0x9D, 0x11, 0x6F, 0xBE),
+    1895                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0x40, 0x57, 0xEB, 0x40, 0x2D, 0xC0, 0x11),
+    1896                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2F, 0x96, 0xBB, 0x4F, 0x2F, 0x23, 0xA8, 0x28),
+    1897                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3A, 0x29, 0x85, 0x21, 0xA5, 0x50, 0x62, 0x06),
+    1898                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC9, 0x7D, 0x92, 0xCF, 0x87, 0x0C, 0x22, 0xF9),
+    1899                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC9, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1900                 :            : };
+    1901                 :            : static const mbedtls_mpi_uint secp521r1_T_21_Y[] = {
+    1902                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5A, 0x0E, 0xA5, 0x32, 0x5B, 0xDF, 0x9C, 0xD5),
+    1903                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x27, 0x96, 0x37, 0x2C, 0x88, 0x35, 0x30, 0xA1),
+    1904                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x40, 0xB4, 0x69, 0xFF, 0xEB, 0xC6, 0x94, 0x08),
+    1905                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC9, 0x55, 0x60, 0xAD, 0xAA, 0x58, 0x14, 0x88),
+    1906                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3C, 0xFF, 0xF2, 0xB2, 0xD5, 0xA7, 0xD9, 0x27),
+    1907                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2D, 0xAE, 0x54, 0xD2, 0x60, 0x31, 0xF3, 0x15),
+    1908                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBB, 0x92, 0x83, 0xE3, 0xF1, 0x42, 0x83, 0x6E),
+    1909                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x49, 0xD2, 0xC8, 0xB7, 0x76, 0x45, 0x7F, 0x7D),
+    1910                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1911                 :            : };
+    1912                 :            : static const mbedtls_mpi_uint secp521r1_T_22_X[] = {
+    1913                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4A, 0x11, 0xA4, 0xFB, 0x7A, 0x01, 0xBC, 0xC8),
+    1914                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCD, 0x27, 0x73, 0x8D, 0x02, 0x91, 0x27, 0x8E),
+    1915                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA4, 0x62, 0xF6, 0xDD, 0x6B, 0xFA, 0x5B, 0xB9),
+    1916                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEF, 0xCA, 0xA2, 0x44, 0x2C, 0xF0, 0x28, 0xD8),
+    1917                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3C, 0xF1, 0x7A, 0xA2, 0x42, 0x4C, 0x50, 0xC6),
+    1918                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2D, 0x83, 0x3E, 0x50, 0xAB, 0x9C, 0xF7, 0x67),
+    1919                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1D, 0xED, 0x78, 0xCB, 0x76, 0x69, 0xDA, 0x42),
+    1920                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDB, 0x01, 0x1E, 0x43, 0x27, 0x47, 0x6E, 0xDA),
+    1921                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x94, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1922                 :            : };
+    1923                 :            : static const mbedtls_mpi_uint secp521r1_T_22_Y[] = {
+    1924                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD3, 0x4F, 0x54, 0xB9, 0x3E, 0xBD, 0xD5, 0x44),
+    1925                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC9, 0x35, 0x40, 0x69, 0x7F, 0x74, 0x9D, 0x32),
+    1926                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5A, 0x06, 0x6F, 0x67, 0x68, 0x2B, 0x4D, 0x10),
+    1927                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC6, 0x65, 0x41, 0xFC, 0x7C, 0x1E, 0xE8, 0xC8),
+    1928                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF2, 0x79, 0x37, 0xAF, 0xFD, 0xD2, 0xDA, 0x4C),
+    1929                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x33, 0xA8, 0x69, 0x56, 0x62, 0xA4, 0xE4, 0xA3),
+    1930                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x42, 0x71, 0x73, 0x21, 0x8A, 0x17, 0x81, 0xA2),
+    1931                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x14, 0x55, 0x8F, 0x7B, 0xB8, 0xAF, 0xF7, 0x86),
+    1932                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAA, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1933                 :            : };
+    1934                 :            : static const mbedtls_mpi_uint secp521r1_T_23_X[] = {
+    1935                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4B, 0xD1, 0xBD, 0xBE, 0x8C, 0xBC, 0x60, 0x6E),
+    1936                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x62, 0xA6, 0x57, 0x8C, 0xAE, 0x5C, 0x19, 0xFE),
+    1937                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7A, 0x43, 0xE4, 0xD9, 0xD8, 0x7B, 0xE7, 0x41),
+    1938                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xED, 0xB9, 0xE4, 0x85, 0x7C, 0x2E, 0xFC, 0x20),
+    1939                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x02, 0x2E, 0x01, 0x2A, 0x6D, 0x56, 0xBE, 0x97),
+    1940                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6A, 0x0C, 0x25, 0x9B, 0xAE, 0x86, 0x37, 0x43),
+    1941                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4A, 0x22, 0xB3, 0xCB, 0x99, 0x66, 0xB7, 0x9E),
+    1942                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x56, 0xF7, 0x90, 0xF0, 0x1B, 0x09, 0x27, 0xF7),
+    1943                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1944                 :            : };
+    1945                 :            : static const mbedtls_mpi_uint secp521r1_T_23_Y[] = {
+    1946                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1C, 0x16, 0x08, 0xEF, 0x39, 0x64, 0x49, 0x31),
+    1947                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x08, 0xA0, 0xE3, 0x97, 0xA9, 0x07, 0x54, 0x26),
+    1948                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCD, 0xFF, 0xE2, 0x00, 0x07, 0x21, 0x88, 0x20),
+    1949                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x16, 0xFD, 0x59, 0x53, 0x05, 0x6C, 0x42, 0x27),
+    1950                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8F, 0xF7, 0x39, 0x5C, 0x82, 0x36, 0xE8, 0x03),
+    1951                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2E, 0x83, 0xA8, 0xE2, 0xA8, 0x43, 0x07, 0x38),
+    1952                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE6, 0xAF, 0x2B, 0x79, 0xED, 0xD8, 0x39, 0x87),
+    1953                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x15, 0x20, 0x91, 0x7A, 0xC4, 0x07, 0xEF, 0x6C),
+    1954                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x28, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1955                 :            : };
+    1956                 :            : static const mbedtls_mpi_uint secp521r1_T_24_X[] = {
+    1957                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6A, 0x10, 0x2F, 0xAA, 0x0C, 0x94, 0x0E, 0x5A),
+    1958                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB7, 0x81, 0x87, 0x41, 0x23, 0xEB, 0x55, 0x7C),
+    1959                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB8, 0x53, 0xCC, 0x79, 0xB6, 0xEB, 0x6C, 0xCC),
+    1960                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF4, 0x77, 0x73, 0x9D, 0xFC, 0x64, 0x6F, 0x7F),
+    1961                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3C, 0x40, 0xE3, 0x6D, 0x1C, 0x16, 0x71, 0x15),
+    1962                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5A, 0xF4, 0x1B, 0xFF, 0x1C, 0x2F, 0xA5, 0xD7),
+    1963                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x06, 0x0E, 0x0B, 0x11, 0xF4, 0x8D, 0x93, 0xAF),
+    1964                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x58, 0xC5, 0x64, 0x6F, 0x24, 0x19, 0xF2, 0x9B),
+    1965                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1966                 :            : };
+    1967                 :            : static const mbedtls_mpi_uint secp521r1_T_24_Y[] = {
+    1968                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x52, 0xB3, 0xAF, 0xA5, 0x0E, 0x4F, 0x5E, 0xE1),
+    1969                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0F, 0x77, 0xCA, 0xF2, 0x6D, 0xC5, 0xF6, 0x9F),
+    1970                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x90, 0x18, 0x8E, 0x33, 0x68, 0x6C, 0xE8, 0xE0),
+    1971                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFC, 0x8B, 0x80, 0x90, 0x19, 0x7F, 0x90, 0x96),
+    1972                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5B, 0x80, 0x6B, 0x68, 0xE2, 0x7D, 0xD4, 0xD0),
+    1973                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2A, 0xC1, 0x67, 0xB3, 0x72, 0xCB, 0xBF, 0x2F),
+    1974                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4F, 0xD5, 0xD3, 0x1D, 0x14, 0x58, 0x0A, 0x80),
+    1975                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x79, 0x7A, 0x65, 0x98, 0xB3, 0x07, 0x4B, 0x2F),
+    1976                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF3, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1977                 :            : };
+    1978                 :            : static const mbedtls_mpi_uint secp521r1_T_25_X[] = {
+    1979                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2A, 0x87, 0x0F, 0x5F, 0xCF, 0xA2, 0x01, 0x08),
+    1980                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0C, 0xC9, 0xC8, 0x6E, 0x35, 0x87, 0xA5, 0x67),
+    1981                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x94, 0x3E, 0x91, 0xA0, 0xAB, 0x24, 0x1E, 0xF2),
+    1982                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB9, 0xBC, 0x02, 0x35, 0x70, 0xC1, 0x5F, 0x98),
+    1983                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x26, 0x59, 0xA0, 0x50, 0x04, 0x80, 0x52, 0x85),
+    1984                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF8, 0x56, 0x6E, 0x42, 0x8F, 0x8C, 0x91, 0x65),
+    1985                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAC, 0xA2, 0xCB, 0xA5, 0xDE, 0x14, 0x24, 0x38),
+    1986                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x00, 0xCB, 0x74, 0x28, 0xE6, 0xA7, 0xE7, 0xC3),
+    1987                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1988                 :            : };
+    1989                 :            : static const mbedtls_mpi_uint secp521r1_T_25_Y[] = {
+    1990                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x35, 0x73, 0xA8, 0x8F, 0x9E, 0x0E, 0x63, 0x96),
+    1991                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC8, 0x1B, 0x77, 0xC7, 0xC1, 0x38, 0xF9, 0xDC),
+    1992                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD8, 0x3C, 0xCF, 0xA8, 0x7A, 0xD7, 0xF3, 0xC4),
+    1993                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDD, 0x5F, 0x9A, 0xC9, 0xAD, 0xE9, 0x1A, 0x93),
+    1994                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFC, 0xCF, 0x2B, 0x5E, 0xD5, 0x81, 0x95, 0xA8),
+    1995                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x19, 0x88, 0x75, 0x29, 0x1F, 0xC7, 0xC7, 0xD0),
+    1996                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD8, 0xA9, 0x5A, 0x4D, 0x63, 0x95, 0xF9, 0x4E),
+    1997                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEB, 0xCD, 0x04, 0x8F, 0xCD, 0x91, 0xDE, 0xC6),
+    1998                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x71, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    1999                 :            : };
+    2000                 :            : static const mbedtls_mpi_uint secp521r1_T_26_X[] = {
+    2001                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x88, 0xD4, 0xFD, 0x25, 0x11, 0x99, 0x6E, 0xEA),
+    2002                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB0, 0x83, 0x01, 0x3D, 0xFB, 0x56, 0xA5, 0x4E),
+    2003                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC2, 0x3A, 0xDC, 0x74, 0xC2, 0xD7, 0xCF, 0xE8),
+    2004                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8F, 0xBD, 0xF1, 0xDD, 0xA3, 0x07, 0x03, 0xE2),
+    2005                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7B, 0xBE, 0xE9, 0x2E, 0x58, 0x84, 0x66, 0xFC),
+    2006                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x71, 0x20, 0x78, 0x37, 0x79, 0x0B, 0xA6, 0x64),
+    2007                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE3, 0xF2, 0xAC, 0x65, 0xC8, 0xC9, 0x2F, 0x61),
+    2008                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x26, 0x93, 0xE5, 0x0D, 0x0C, 0xC6, 0xB8, 0xCB),
+    2009                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    2010                 :            : };
+    2011                 :            : static const mbedtls_mpi_uint secp521r1_T_26_Y[] = {
+    2012                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x69, 0xAD, 0x5C, 0x19, 0x12, 0x61, 0x0E, 0x25),
+    2013                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x39, 0x4F, 0x0B, 0x1F, 0x49, 0x7E, 0xCD, 0x81),
+    2014                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x46, 0x2E, 0x30, 0x61, 0xDB, 0x08, 0x68, 0x9B),
+    2015                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x41, 0x78, 0xAF, 0xB3, 0x08, 0xC1, 0x69, 0xE5),
+    2016                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC4, 0x5F, 0x5D, 0xC1, 0x57, 0x6F, 0xD8, 0x34),
+    2017                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x38, 0xD3, 0x6A, 0xF7, 0xFD, 0x86, 0xE5, 0xB3),
+    2018                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA8, 0x63, 0xBD, 0x70, 0x7B, 0x47, 0xE8, 0x6D),
+    2019                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x18, 0x62, 0xC8, 0x7E, 0x9D, 0x11, 0x2B, 0xA5),
+    2020                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    2021                 :            : };
+    2022                 :            : static const mbedtls_mpi_uint secp521r1_T_27_X[] = {
+    2023                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE2, 0x84, 0xFD, 0xD5, 0x9A, 0x56, 0x7F, 0x5C),
+    2024                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7C, 0xBB, 0xA4, 0x6F, 0x12, 0x6E, 0x4D, 0xF8),
+    2025                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1D, 0x08, 0xA1, 0x82, 0x9C, 0x62, 0x74, 0x7B),
+    2026                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9E, 0x58, 0x22, 0x05, 0x1D, 0x15, 0x35, 0x79),
+    2027                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9A, 0x88, 0xCF, 0x5C, 0x05, 0x78, 0xFB, 0x94),
+    2028                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAC, 0x6B, 0x2F, 0x79, 0x09, 0x73, 0x67, 0xEC),
+    2029                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD8, 0xA0, 0x80, 0xD8, 0xE8, 0xEC, 0xFB, 0x42),
+    2030                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF5, 0xE7, 0x0B, 0xB7, 0x81, 0x48, 0x7B, 0xD9),
+    2031                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    2032                 :            : };
+    2033                 :            : static const mbedtls_mpi_uint secp521r1_T_27_Y[] = {
+    2034                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE8, 0x53, 0xA9, 0xED, 0x61, 0x92, 0xD7, 0x85),
+    2035                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x26, 0x49, 0xD9, 0x5D, 0x9B, 0x4E, 0x89, 0x35),
+    2036                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB8, 0x12, 0xEB, 0x9A, 0xC9, 0xCB, 0xC1, 0x95),
+    2037                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x35, 0xDC, 0x95, 0x16, 0xFE, 0x29, 0x70, 0x01),
+    2038                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x64, 0x33, 0xB1, 0xD6, 0x78, 0xB9, 0xE2, 0x36),
+    2039                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x34, 0xCE, 0x88, 0xC3, 0xFD, 0x7A, 0x6B, 0xB8),
+    2040                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x40, 0x1E, 0x50, 0x1E, 0xAF, 0xB1, 0x25, 0x2D),
+    2041                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC1, 0xE7, 0xD7, 0xD5, 0xBD, 0x7A, 0x12, 0xF9),
+    2042                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    2043                 :            : };
+    2044                 :            : static const mbedtls_mpi_uint secp521r1_T_28_X[] = {
+    2045                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x22, 0xAA, 0xA2, 0x80, 0x5D, 0x8F, 0xCD, 0xC8),
+    2046                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x48, 0x39, 0x79, 0x64, 0xA1, 0x67, 0x3C, 0xB7),
+    2047                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3D, 0xC7, 0x49, 0xFF, 0x7F, 0xAC, 0xAB, 0x55),
+    2048                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x81, 0x54, 0x3E, 0x83, 0xF0, 0x3D, 0xBC, 0xB5),
+    2049                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x87, 0x92, 0x4A, 0x38, 0x42, 0x8A, 0xAB, 0xF6),
+    2050                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE7, 0x0B, 0x4F, 0xEE, 0x9E, 0x92, 0xA5, 0xBE),
+    2051                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBA, 0xDD, 0x19, 0x96, 0xF2, 0xF0, 0x6B, 0x2E),
+    2052                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBE, 0xFC, 0xDD, 0xB2, 0x8A, 0xE5, 0x4C, 0x22),
+    2053                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    2054                 :            : };
+    2055                 :            : static const mbedtls_mpi_uint secp521r1_T_28_Y[] = {
+    2056                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB7, 0x06, 0x49, 0xAC, 0x99, 0x7E, 0xF8, 0x12),
+    2057                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x76, 0xC8, 0x01, 0x51, 0xEA, 0xF6, 0x52, 0xE7),
+    2058                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x43, 0x89, 0x66, 0x2B, 0x1F, 0x9B, 0x2A, 0xA3),
+    2059                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDF, 0x0F, 0x95, 0x07, 0x2B, 0x6C, 0x6E, 0x9E),
+    2060                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x24, 0xC3, 0xB4, 0xBB, 0x91, 0x1F, 0xA3, 0x72),
+    2061                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5F, 0x6E, 0x54, 0x28, 0x7B, 0x9C, 0x79, 0x2E),
+    2062                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x03, 0x45, 0xFF, 0xA6, 0xDA, 0xA2, 0x83, 0x71),
+    2063                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEB, 0xDE, 0x8F, 0x17, 0x37, 0x82, 0xCB, 0xE2),
+    2064                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    2065                 :            : };
+    2066                 :            : static const mbedtls_mpi_uint secp521r1_T_29_X[] = {
+    2067                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD8, 0x94, 0x3F, 0x26, 0xC9, 0x1D, 0xD9, 0xAE),
+    2068                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x09, 0x97, 0x28, 0x20, 0xCD, 0xC1, 0xF3, 0x40),
+    2069                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x95, 0xC9, 0xB5, 0x60, 0x9B, 0x1E, 0xDC, 0x74),
+    2070                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5B, 0xB9, 0x5B, 0x7D, 0xA0, 0xB2, 0x8C, 0xF0),
+    2071                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x33, 0xD1, 0x42, 0xE6, 0x39, 0x33, 0x6D, 0xBB),
+    2072                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5D, 0xC0, 0xFC, 0xD2, 0x14, 0x5D, 0x3E, 0x3C),
+    2073                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x78, 0x4A, 0x3E, 0x40, 0x16, 0x93, 0x15, 0xCF),
+    2074                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFA, 0x24, 0xC1, 0x27, 0x27, 0xE5, 0x4B, 0xD8),
+    2075                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    2076                 :            : };
+    2077                 :            : static const mbedtls_mpi_uint secp521r1_T_29_Y[] = {
+    2078                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1D, 0x50, 0xD8, 0xBC, 0xC1, 0x46, 0x22, 0xBB),
+    2079                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAD, 0x0E, 0x60, 0xA1, 0xB3, 0x50, 0xD4, 0x86),
+    2080                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x80, 0xB1, 0x26, 0xB6, 0x6D, 0x47, 0x5A, 0x6F),
+    2081                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x45, 0xAC, 0x11, 0x35, 0x3E, 0xB9, 0xF4, 0x01),
+    2082                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x58, 0x97, 0xFA, 0xBB, 0x6B, 0x39, 0x13, 0xD8),
+    2083                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x15, 0x7B, 0x34, 0x12, 0x75, 0x8E, 0x9B, 0xC6),
+    2084                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2C, 0x9E, 0xCD, 0x29, 0xB6, 0xEF, 0x8D, 0x10),
+    2085                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x47, 0xAC, 0xE9, 0x25, 0x27, 0xBB, 0x78, 0x47),
+    2086                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2F, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    2087                 :            : };
+    2088                 :            : static const mbedtls_mpi_uint secp521r1_T_30_X[] = {
+    2089                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x30, 0x7A, 0xA8, 0xD3, 0xE3, 0x66, 0xE5, 0x66),
+    2090                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2F, 0x4C, 0xC4, 0x2C, 0x76, 0x81, 0x50, 0x32),
+    2091                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEE, 0x71, 0x08, 0xB8, 0x52, 0x7C, 0xAF, 0xDC),
+    2092                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x45, 0x59, 0x24, 0xDD, 0xFB, 0x2F, 0xD0, 0xDA),
+    2093                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB7, 0xCD, 0x56, 0xE9, 0xAC, 0x91, 0xE6, 0xB9),
+    2094                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE5, 0x64, 0x20, 0xC6, 0x9F, 0xE4, 0xEF, 0xDF),
+    2095                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6D, 0x2C, 0x8F, 0x8C, 0x97, 0xF6, 0x22, 0xC3),
+    2096                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAC, 0xF4, 0x88, 0xAA, 0xA8, 0xD7, 0xA5, 0x68),
+    2097                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    2098                 :            : };
+    2099                 :            : static const mbedtls_mpi_uint secp521r1_T_30_Y[] = {
+    2100                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x21, 0x6C, 0xAE, 0x83, 0xB1, 0x55, 0x55, 0xEE),
+    2101                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB0, 0x67, 0x84, 0x47, 0x7C, 0x83, 0x5C, 0x89),
+    2102                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5B, 0x10, 0x4D, 0xDD, 0x30, 0x60, 0xB0, 0xE6),
+    2103                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x59, 0xA7, 0x36, 0x76, 0x24, 0x32, 0x9F, 0x9D),
+    2104                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDD, 0x42, 0x81, 0xFB, 0xA4, 0x2E, 0x13, 0x68),
+    2105                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x87, 0x94, 0x91, 0xFF, 0x99, 0xA0, 0x09, 0x61),
+    2106                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5D, 0x83, 0xA1, 0x76, 0xAF, 0x37, 0x5C, 0x77),
+    2107                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1E, 0xA8, 0x04, 0x86, 0xC4, 0xA9, 0x79, 0x42),
+    2108                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x93, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    2109                 :            : };
+    2110                 :            : static const mbedtls_mpi_uint secp521r1_T_31_X[] = {
+    2111                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB6, 0x8C, 0xC2, 0x34, 0xFB, 0x83, 0x28, 0x27),
+    2112                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA4, 0x03, 0x7D, 0x5E, 0x9E, 0x0E, 0xB0, 0x22),
+    2113                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA2, 0x02, 0x46, 0x7F, 0xB9, 0xAC, 0xBB, 0x23),
+    2114                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x06, 0xED, 0x48, 0xC2, 0x96, 0x4D, 0x56, 0x27),
+    2115                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x44, 0xB5, 0xC5, 0xD1, 0xE6, 0x1C, 0x7E, 0x9B),
+    2116                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x92, 0x2E, 0x18, 0x71, 0x2D, 0x7B, 0xD7, 0xB3),
+    2117                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAB, 0x46, 0x9D, 0xDE, 0xAA, 0x78, 0x8E, 0xB1),
+    2118                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4D, 0xD7, 0x69, 0x2E, 0xE1, 0xD9, 0x48, 0xDE),
+    2119                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFB, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    2120                 :            : };
+    2121                 :            : static const mbedtls_mpi_uint secp521r1_T_31_Y[] = {
+    2122                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAF, 0xFF, 0x9E, 0x09, 0x22, 0x22, 0xE6, 0x8D),
+    2123                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6C, 0x14, 0x28, 0x13, 0x1B, 0x62, 0x12, 0x22),
+    2124                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCC, 0x7F, 0x67, 0x03, 0xB0, 0xC0, 0xF3, 0x05),
+    2125                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC0, 0xC3, 0x0F, 0xFB, 0x25, 0x48, 0x3E, 0xF4),
+    2126                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0B, 0x6E, 0x53, 0x98, 0x36, 0xB3, 0xD3, 0x94),
+    2127                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEB, 0x81, 0x54, 0x22, 0xA4, 0xCC, 0xC1, 0x22),
+    2128                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF5, 0xBA, 0xFC, 0xA9, 0xDF, 0x68, 0x86, 0x2B),
+    2129                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x71, 0x92, 0x0E, 0xC3, 0xF2, 0x58, 0xE8, 0x51),
+    2130                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE9, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    2131                 :            : };
+    2132                 :            : static const mbedtls_ecp_point secp521r1_T[32] = {
+    2133                 :            :     ECP_POINT_INIT_XY_Z1(secp521r1_T_0_X, secp521r1_T_0_Y),
+    2134                 :            :     ECP_POINT_INIT_XY_Z0(secp521r1_T_1_X, secp521r1_T_1_Y),
+    2135                 :            :     ECP_POINT_INIT_XY_Z0(secp521r1_T_2_X, secp521r1_T_2_Y),
+    2136                 :            :     ECP_POINT_INIT_XY_Z0(secp521r1_T_3_X, secp521r1_T_3_Y),
+    2137                 :            :     ECP_POINT_INIT_XY_Z0(secp521r1_T_4_X, secp521r1_T_4_Y),
+    2138                 :            :     ECP_POINT_INIT_XY_Z0(secp521r1_T_5_X, secp521r1_T_5_Y),
+    2139                 :            :     ECP_POINT_INIT_XY_Z0(secp521r1_T_6_X, secp521r1_T_6_Y),
+    2140                 :            :     ECP_POINT_INIT_XY_Z0(secp521r1_T_7_X, secp521r1_T_7_Y),
+    2141                 :            :     ECP_POINT_INIT_XY_Z0(secp521r1_T_8_X, secp521r1_T_8_Y),
+    2142                 :            :     ECP_POINT_INIT_XY_Z0(secp521r1_T_9_X, secp521r1_T_9_Y),
+    2143                 :            :     ECP_POINT_INIT_XY_Z0(secp521r1_T_10_X, secp521r1_T_10_Y),
+    2144                 :            :     ECP_POINT_INIT_XY_Z0(secp521r1_T_11_X, secp521r1_T_11_Y),
+    2145                 :            :     ECP_POINT_INIT_XY_Z0(secp521r1_T_12_X, secp521r1_T_12_Y),
+    2146                 :            :     ECP_POINT_INIT_XY_Z0(secp521r1_T_13_X, secp521r1_T_13_Y),
+    2147                 :            :     ECP_POINT_INIT_XY_Z0(secp521r1_T_14_X, secp521r1_T_14_Y),
+    2148                 :            :     ECP_POINT_INIT_XY_Z0(secp521r1_T_15_X, secp521r1_T_15_Y),
+    2149                 :            :     ECP_POINT_INIT_XY_Z0(secp521r1_T_16_X, secp521r1_T_16_Y),
+    2150                 :            :     ECP_POINT_INIT_XY_Z0(secp521r1_T_17_X, secp521r1_T_17_Y),
+    2151                 :            :     ECP_POINT_INIT_XY_Z0(secp521r1_T_18_X, secp521r1_T_18_Y),
+    2152                 :            :     ECP_POINT_INIT_XY_Z0(secp521r1_T_19_X, secp521r1_T_19_Y),
+    2153                 :            :     ECP_POINT_INIT_XY_Z0(secp521r1_T_20_X, secp521r1_T_20_Y),
+    2154                 :            :     ECP_POINT_INIT_XY_Z0(secp521r1_T_21_X, secp521r1_T_21_Y),
+    2155                 :            :     ECP_POINT_INIT_XY_Z0(secp521r1_T_22_X, secp521r1_T_22_Y),
+    2156                 :            :     ECP_POINT_INIT_XY_Z0(secp521r1_T_23_X, secp521r1_T_23_Y),
+    2157                 :            :     ECP_POINT_INIT_XY_Z0(secp521r1_T_24_X, secp521r1_T_24_Y),
+    2158                 :            :     ECP_POINT_INIT_XY_Z0(secp521r1_T_25_X, secp521r1_T_25_Y),
+    2159                 :            :     ECP_POINT_INIT_XY_Z0(secp521r1_T_26_X, secp521r1_T_26_Y),
+    2160                 :            :     ECP_POINT_INIT_XY_Z0(secp521r1_T_27_X, secp521r1_T_27_Y),
+    2161                 :            :     ECP_POINT_INIT_XY_Z0(secp521r1_T_28_X, secp521r1_T_28_Y),
+    2162                 :            :     ECP_POINT_INIT_XY_Z0(secp521r1_T_29_X, secp521r1_T_29_Y),
+    2163                 :            :     ECP_POINT_INIT_XY_Z0(secp521r1_T_30_X, secp521r1_T_30_Y),
+    2164                 :            :     ECP_POINT_INIT_XY_Z0(secp521r1_T_31_X, secp521r1_T_31_Y),
+    2165                 :            : };
+    2166                 :            : #else
+    2167                 :            : #define secp521r1_T NULL
+    2168                 :            : #endif
+    2169                 :            : #endif /* MBEDTLS_ECP_DP_SECP521R1_ENABLED */
+    2170                 :            : 
+    2171                 :            : #if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED)
+    2172                 :            : static const mbedtls_mpi_uint secp192k1_p[] = {
+    2173                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x37, 0xEE, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF),
+    2174                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
+    2175                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
+    2176                 :            : };
+    2177                 :            : static const mbedtls_mpi_uint secp192k1_a[] = {
+    2178                 :            :     MBEDTLS_BYTES_TO_T_UINT_2(0x00, 0x00),
+    2179                 :            : };
+    2180                 :            : static const mbedtls_mpi_uint secp192k1_b[] = {
+    2181                 :            :     MBEDTLS_BYTES_TO_T_UINT_2(0x03, 0x00),
+    2182                 :            : };
+    2183                 :            : static const mbedtls_mpi_uint secp192k1_gx[] = {
+    2184                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7D, 0x6C, 0xE0, 0xEA, 0xB1, 0xD1, 0xA5, 0x1D),
+    2185                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x34, 0xF4, 0xB7, 0x80, 0x02, 0x7D, 0xB0, 0x26),
+    2186                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAE, 0xE9, 0x57, 0xC0, 0x0E, 0xF1, 0x4F, 0xDB),
+    2187                 :            : };
+    2188                 :            : static const mbedtls_mpi_uint secp192k1_gy[] = {
+    2189                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9D, 0x2F, 0x5E, 0xD9, 0x88, 0xAA, 0x82, 0x40),
+    2190                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x34, 0x86, 0xBE, 0x15, 0xD0, 0x63, 0x41, 0x84),
+    2191                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA7, 0x28, 0x56, 0x9C, 0x6D, 0x2F, 0x2F, 0x9B),
+    2192                 :            : };
+    2193                 :            : static const mbedtls_mpi_uint secp192k1_n[] = {
+    2194                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8D, 0xFD, 0xDE, 0x74, 0x6A, 0x46, 0x69, 0x0F),
+    2195                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x17, 0xFC, 0xF2, 0x26, 0xFE, 0xFF, 0xFF, 0xFF),
+    2196                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
+    2197                 :            : };
+    2198                 :            : 
+    2199                 :            : #if MBEDTLS_ECP_FIXED_POINT_OPTIM == 1
+    2200                 :            : static const mbedtls_mpi_uint secp192k1_T_0_X[] = {
+    2201                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7D, 0x6C, 0xE0, 0xEA, 0xB1, 0xD1, 0xA5, 0x1D),
+    2202                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x34, 0xF4, 0xB7, 0x80, 0x02, 0x7D, 0xB0, 0x26),
+    2203                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAE, 0xE9, 0x57, 0xC0, 0x0E, 0xF1, 0x4F, 0xDB),
+    2204                 :            : };
+    2205                 :            : static const mbedtls_mpi_uint secp192k1_T_0_Y[] = {
+    2206                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9D, 0x2F, 0x5E, 0xD9, 0x88, 0xAA, 0x82, 0x40),
+    2207                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x34, 0x86, 0xBE, 0x15, 0xD0, 0x63, 0x41, 0x84),
+    2208                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA7, 0x28, 0x56, 0x9C, 0x6D, 0x2F, 0x2F, 0x9B),
+    2209                 :            : };
+    2210                 :            : static const mbedtls_mpi_uint secp192k1_T_1_X[] = {
+    2211                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6F, 0x77, 0x3D, 0x0D, 0x85, 0x48, 0xA8, 0xA9),
+    2212                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x62, 0x07, 0xDF, 0x1D, 0xB3, 0xB3, 0x01, 0x54),
+    2213                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x05, 0x86, 0xF6, 0xAF, 0x19, 0x2A, 0x88, 0x2E),
+    2214                 :            : };
+    2215                 :            : static const mbedtls_mpi_uint secp192k1_T_1_Y[] = {
+    2216                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x33, 0x90, 0xB6, 0x2F, 0x48, 0x36, 0x4C, 0x5B),
+    2217                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDB, 0x11, 0x14, 0xA6, 0xCB, 0xBA, 0x15, 0xD9),
+    2218                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7E, 0xB0, 0xF2, 0xD4, 0xC9, 0xDA, 0xBA, 0xD7),
+    2219                 :            : };
+    2220                 :            : static const mbedtls_mpi_uint secp192k1_T_2_X[] = {
+    2221                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE4, 0xC1, 0x9C, 0xE6, 0xBB, 0xFB, 0xCF, 0x23),
+    2222                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x93, 0x19, 0xAC, 0x5A, 0xC9, 0x8A, 0x1C, 0x75),
+    2223                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC1, 0xF6, 0x76, 0x86, 0x89, 0x27, 0x8D, 0x28),
+    2224                 :            : };
+    2225                 :            : static const mbedtls_mpi_uint secp192k1_T_2_Y[] = {
+    2226                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4B, 0xE0, 0x6F, 0x34, 0xBA, 0x5E, 0xD3, 0x96),
+    2227                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6A, 0xDC, 0xA6, 0x87, 0xC9, 0x9D, 0xC0, 0x82),
+    2228                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x09, 0x11, 0x7E, 0xD6, 0xF7, 0x33, 0xFC, 0xE4),
+    2229                 :            : };
+    2230                 :            : static const mbedtls_mpi_uint secp192k1_T_3_X[] = {
+    2231                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC2, 0x37, 0x3E, 0xC0, 0x7F, 0x62, 0xE7, 0x54),
+    2232                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA5, 0x3B, 0x69, 0x9D, 0x44, 0xBC, 0x82, 0x99),
+    2233                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD4, 0x84, 0xB3, 0x5F, 0x2B, 0xA5, 0x9E, 0x2C),
+    2234                 :            : };
+    2235                 :            : static const mbedtls_mpi_uint secp192k1_T_3_Y[] = {
+    2236                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1D, 0x95, 0xEB, 0x4C, 0x04, 0xB4, 0xF4, 0x75),
+    2237                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x55, 0xAD, 0x4B, 0xD5, 0x9A, 0xEB, 0xC4, 0x4E),
+    2238                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC9, 0xB1, 0xC5, 0x59, 0xE3, 0xD5, 0x16, 0x2A),
+    2239                 :            : };
+    2240                 :            : static const mbedtls_mpi_uint secp192k1_T_4_X[] = {
+    2241                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x48, 0x2A, 0xCC, 0xAC, 0xD0, 0xEE, 0x50, 0xEC),
+    2242                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x99, 0x83, 0xE0, 0x5B, 0x14, 0x44, 0x52, 0x20),
+    2243                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD6, 0x15, 0x2D, 0x78, 0xF6, 0x51, 0x32, 0xCF),
+    2244                 :            : };
+    2245                 :            : static const mbedtls_mpi_uint secp192k1_T_4_Y[] = {
+    2246                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x86, 0x36, 0x9B, 0xDD, 0xF8, 0xDD, 0xEF, 0xB2),
+    2247                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0B, 0xB1, 0x6A, 0x2B, 0xAF, 0xEB, 0x2B, 0xB1),
+    2248                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC9, 0x87, 0x7A, 0x66, 0x5D, 0x5B, 0xDF, 0x8F),
+    2249                 :            : };
+    2250                 :            : static const mbedtls_mpi_uint secp192k1_T_5_X[] = {
+    2251                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x62, 0x45, 0xE5, 0x81, 0x9B, 0xEB, 0x37, 0x23),
+    2252                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB3, 0x29, 0xE2, 0x20, 0x64, 0x23, 0x6B, 0x6E),
+    2253                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFE, 0x1D, 0x41, 0xE1, 0x9B, 0x61, 0x7B, 0xD9),
+    2254                 :            : };
+    2255                 :            : static const mbedtls_mpi_uint secp192k1_T_5_Y[] = {
+    2256                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x75, 0x57, 0xA3, 0x0A, 0x13, 0xE4, 0x59, 0x15),
+    2257                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x79, 0x6E, 0x4A, 0x48, 0x84, 0x90, 0xAC, 0xC7),
+    2258                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9C, 0xB8, 0xF5, 0xF3, 0xDE, 0xA0, 0xA1, 0x1D),
+    2259                 :            : };
+    2260                 :            : static const mbedtls_mpi_uint secp192k1_T_6_X[] = {
+    2261                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA3, 0x32, 0x81, 0xA9, 0x91, 0x5A, 0x4E, 0x33),
+    2262                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCB, 0xA8, 0x90, 0xBE, 0x0F, 0xEC, 0xC0, 0x85),
+    2263                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x80, 0x30, 0xD7, 0x08, 0xAE, 0xC4, 0x3A, 0xA5),
+    2264                 :            : };
+    2265                 :            : static const mbedtls_mpi_uint secp192k1_T_6_Y[] = {
+    2266                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBC, 0x55, 0xE3, 0x76, 0xB3, 0x64, 0x74, 0x9F),
+    2267                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3F, 0x75, 0xD4, 0xDB, 0x98, 0xD7, 0x39, 0xAE),
+    2268                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD4, 0xEB, 0x8A, 0xAB, 0x16, 0xD9, 0xD4, 0x0B),
+    2269                 :            : };
+    2270                 :            : static const mbedtls_mpi_uint secp192k1_T_7_X[] = {
+    2271                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x41, 0xBE, 0xF9, 0xC7, 0xC7, 0xBA, 0xF3, 0xA1),
+    2272                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC2, 0x85, 0x59, 0xF3, 0x60, 0x41, 0x02, 0xD2),
+    2273                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x46, 0x1C, 0x4A, 0xA4, 0xC7, 0xED, 0x66, 0xBC),
+    2274                 :            : };
+    2275                 :            : static const mbedtls_mpi_uint secp192k1_T_7_Y[] = {
+    2276                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC3, 0x9C, 0x2E, 0x46, 0x52, 0x18, 0x87, 0x14),
+    2277                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0x35, 0x5A, 0x75, 0xAC, 0x4D, 0x75, 0x91),
+    2278                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCE, 0x2F, 0xAC, 0xFC, 0xBC, 0xE6, 0x93, 0x5E),
+    2279                 :            : };
+    2280                 :            : static const mbedtls_mpi_uint secp192k1_T_8_X[] = {
+    2281                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x87, 0x4D, 0xC9, 0x18, 0xE9, 0x00, 0xEB, 0x33),
+    2282                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1A, 0x69, 0x72, 0x07, 0x5A, 0x59, 0xA8, 0x26),
+    2283                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB6, 0x65, 0x83, 0x20, 0x10, 0xF9, 0x69, 0x82),
+    2284                 :            : };
+    2285                 :            : static const mbedtls_mpi_uint secp192k1_T_8_Y[] = {
+    2286                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8B, 0x56, 0x7F, 0x9F, 0xBF, 0x46, 0x0C, 0x7E),
+    2287                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFC, 0xCF, 0xF0, 0xDC, 0xDF, 0x2D, 0xE6, 0xE5),
+    2288                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x09, 0xF0, 0x72, 0x3A, 0x7A, 0x03, 0xE5, 0x22),
+    2289                 :            : };
+    2290                 :            : static const mbedtls_mpi_uint secp192k1_T_9_X[] = {
+    2291                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3E, 0xAA, 0x57, 0x13, 0x37, 0xA7, 0x2C, 0xD4),
+    2292                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA3, 0xAC, 0xA2, 0x23, 0xF9, 0x84, 0x60, 0xD3),
+    2293                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x32, 0xEB, 0x51, 0x70, 0x64, 0x78, 0xCA, 0x05),
+    2294                 :            : };
+    2295                 :            : static const mbedtls_mpi_uint secp192k1_T_9_Y[] = {
+    2296                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x91, 0xCC, 0x30, 0x62, 0x93, 0x46, 0x13, 0xE9),
+    2297                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x21, 0x26, 0xCC, 0x6C, 0x3D, 0x5C, 0xDA, 0x2C),
+    2298                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD5, 0xAA, 0xB8, 0x03, 0xA4, 0x1A, 0x00, 0x96),
+    2299                 :            : };
+    2300                 :            : static const mbedtls_mpi_uint secp192k1_T_10_X[] = {
+    2301                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF9, 0x9D, 0xE6, 0xCC, 0x4E, 0x2E, 0xC2, 0xD5),
+    2302                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB4, 0xC3, 0x8A, 0xAE, 0x6F, 0x40, 0x05, 0xEB),
+    2303                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9D, 0x8F, 0x4A, 0x4D, 0x35, 0xD3, 0x50, 0x9D),
+    2304                 :            : };
+    2305                 :            : static const mbedtls_mpi_uint secp192k1_T_10_Y[] = {
+    2306                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1F, 0xFD, 0x98, 0xAB, 0xC7, 0x03, 0xB4, 0x55),
+    2307                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x40, 0x40, 0xD2, 0x9F, 0xCA, 0xD0, 0x53, 0x00),
+    2308                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1A, 0x84, 0x00, 0x6F, 0xC8, 0xAD, 0xED, 0x8D),
+    2309                 :            : };
+    2310                 :            : static const mbedtls_mpi_uint secp192k1_T_11_X[] = {
+    2311                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCE, 0xD3, 0x57, 0xD7, 0xC3, 0x07, 0xBD, 0xD7),
+    2312                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x67, 0xBA, 0x47, 0x1D, 0x3D, 0xEF, 0x98, 0x6C),
+    2313                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6D, 0xC0, 0x6C, 0x7F, 0x12, 0xEE, 0x9F, 0x67),
+    2314                 :            : };
+    2315                 :            : static const mbedtls_mpi_uint secp192k1_T_11_Y[] = {
+    2316                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCA, 0x02, 0xDA, 0x79, 0xAA, 0xC9, 0x27, 0xC4),
+    2317                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x21, 0x79, 0xC7, 0x71, 0x84, 0xCB, 0xE5, 0x5A),
+    2318                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x15, 0x37, 0x06, 0xBA, 0xB5, 0xD5, 0x18, 0x4C),
+    2319                 :            : };
+    2320                 :            : static const mbedtls_mpi_uint secp192k1_T_12_X[] = {
+    2321                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA1, 0x65, 0x72, 0x6C, 0xF2, 0x63, 0x27, 0x6A),
+    2322                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x69, 0xBC, 0x71, 0xDF, 0x75, 0xF8, 0x98, 0x4D),
+    2323                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x70, 0x70, 0x9B, 0xDC, 0xE7, 0x18, 0x71, 0xFF),
+    2324                 :            : };
+    2325                 :            : static const mbedtls_mpi_uint secp192k1_T_12_Y[] = {
+    2326                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x15, 0x5B, 0x9F, 0x00, 0x5A, 0xB6, 0x80, 0x7A),
+    2327                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB7, 0xE0, 0xBB, 0xFC, 0x5E, 0x78, 0x9C, 0x89),
+    2328                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x60, 0x03, 0x68, 0x83, 0x3D, 0x2E, 0x4C, 0xDD),
+    2329                 :            : };
+    2330                 :            : static const mbedtls_mpi_uint secp192k1_T_13_X[] = {
+    2331                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3B, 0x49, 0x23, 0xA8, 0xCB, 0x3B, 0x1A, 0xF6),
+    2332                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8B, 0x3D, 0xA7, 0x46, 0xCF, 0x75, 0xB6, 0x2C),
+    2333                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x92, 0xFD, 0x30, 0x01, 0xB6, 0xEF, 0xF9, 0xE8),
+    2334                 :            : };
+    2335                 :            : static const mbedtls_mpi_uint secp192k1_T_13_Y[] = {
+    2336                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDC, 0xFA, 0xDA, 0xB8, 0x29, 0x42, 0xC9, 0xC7),
+    2337                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x06, 0xD7, 0xA0, 0xE6, 0x6B, 0x86, 0x61, 0x39),
+    2338                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDB, 0xE9, 0xD3, 0x37, 0xD8, 0xE7, 0x35, 0xA9),
+    2339                 :            : };
+    2340                 :            : static const mbedtls_mpi_uint secp192k1_T_14_X[] = {
+    2341                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFD, 0xC8, 0x8E, 0xB1, 0xCB, 0xB1, 0xB5, 0x4D),
+    2342                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x16, 0xD7, 0x46, 0x7D, 0xAF, 0xE2, 0xDC, 0xBB),
+    2343                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD0, 0x46, 0xE7, 0xD8, 0x76, 0x31, 0x90, 0x76),
+    2344                 :            : };
+    2345                 :            : static const mbedtls_mpi_uint secp192k1_T_14_Y[] = {
+    2346                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEB, 0xD3, 0xF4, 0x74, 0xE1, 0x67, 0xD8, 0x66),
+    2347                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE7, 0x70, 0x3C, 0xC8, 0xAF, 0x5F, 0xF4, 0x58),
+    2348                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x24, 0x4E, 0xED, 0x5C, 0x43, 0xB3, 0x16, 0x35),
+    2349                 :            : };
+    2350                 :            : static const mbedtls_mpi_uint secp192k1_T_15_X[] = {
+    2351                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x57, 0xAE, 0xD1, 0xDD, 0x31, 0x14, 0xD3, 0xF0),
+    2352                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE8, 0x14, 0x06, 0x13, 0x12, 0x1C, 0x81, 0xF5),
+    2353                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA6, 0xF9, 0x0C, 0x91, 0xF7, 0x67, 0x59, 0x63),
+    2354                 :            : };
+    2355                 :            : static const mbedtls_mpi_uint secp192k1_T_15_Y[] = {
+    2356                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAB, 0x91, 0xE2, 0xF4, 0x9D, 0xEB, 0x88, 0x87),
+    2357                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDB, 0x82, 0x30, 0x9C, 0xAE, 0x18, 0x4D, 0xB7),
+    2358                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3C, 0x79, 0xCF, 0x17, 0xA5, 0x1E, 0xE8, 0xC8),
+    2359                 :            : };
+    2360                 :            : static const mbedtls_ecp_point secp192k1_T[16] = {
+    2361                 :            :     ECP_POINT_INIT_XY_Z1(secp192k1_T_0_X, secp192k1_T_0_Y),
+    2362                 :            :     ECP_POINT_INIT_XY_Z0(secp192k1_T_1_X, secp192k1_T_1_Y),
+    2363                 :            :     ECP_POINT_INIT_XY_Z0(secp192k1_T_2_X, secp192k1_T_2_Y),
+    2364                 :            :     ECP_POINT_INIT_XY_Z0(secp192k1_T_3_X, secp192k1_T_3_Y),
+    2365                 :            :     ECP_POINT_INIT_XY_Z0(secp192k1_T_4_X, secp192k1_T_4_Y),
+    2366                 :            :     ECP_POINT_INIT_XY_Z0(secp192k1_T_5_X, secp192k1_T_5_Y),
+    2367                 :            :     ECP_POINT_INIT_XY_Z0(secp192k1_T_6_X, secp192k1_T_6_Y),
+    2368                 :            :     ECP_POINT_INIT_XY_Z0(secp192k1_T_7_X, secp192k1_T_7_Y),
+    2369                 :            :     ECP_POINT_INIT_XY_Z0(secp192k1_T_8_X, secp192k1_T_8_Y),
+    2370                 :            :     ECP_POINT_INIT_XY_Z0(secp192k1_T_9_X, secp192k1_T_9_Y),
+    2371                 :            :     ECP_POINT_INIT_XY_Z0(secp192k1_T_10_X, secp192k1_T_10_Y),
+    2372                 :            :     ECP_POINT_INIT_XY_Z0(secp192k1_T_11_X, secp192k1_T_11_Y),
+    2373                 :            :     ECP_POINT_INIT_XY_Z0(secp192k1_T_12_X, secp192k1_T_12_Y),
+    2374                 :            :     ECP_POINT_INIT_XY_Z0(secp192k1_T_13_X, secp192k1_T_13_Y),
+    2375                 :            :     ECP_POINT_INIT_XY_Z0(secp192k1_T_14_X, secp192k1_T_14_Y),
+    2376                 :            :     ECP_POINT_INIT_XY_Z0(secp192k1_T_15_X, secp192k1_T_15_Y),
+    2377                 :            : };
+    2378                 :            : #else
+    2379                 :            : #define secp192k1_T NULL
+    2380                 :            : #endif
+    2381                 :            : 
+    2382                 :            : #endif /* MBEDTLS_ECP_DP_SECP192K1_ENABLED */
+    2383                 :            : 
+    2384                 :            : #if defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED)
+    2385                 :            : static const mbedtls_mpi_uint secp224k1_p[] = {
+    2386                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6D, 0xE5, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF),
+    2387                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
+    2388                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
+    2389                 :            :     MBEDTLS_BYTES_TO_T_UINT_4(0xFF, 0xFF, 0xFF, 0xFF),
+    2390                 :            : };
+    2391                 :            : static const mbedtls_mpi_uint secp224k1_a[] = {
+    2392                 :            :     MBEDTLS_BYTES_TO_T_UINT_2(0x00, 0x00),
+    2393                 :            : };
+    2394                 :            : static const mbedtls_mpi_uint secp224k1_b[] = {
+    2395                 :            :     MBEDTLS_BYTES_TO_T_UINT_2(0x05, 0x00),
+    2396                 :            : };
+    2397                 :            : static const mbedtls_mpi_uint secp224k1_gx[] = {
+    2398                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5C, 0xA4, 0xB7, 0xB6, 0x0E, 0x65, 0x7E, 0x0F),
+    2399                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA9, 0x75, 0x70, 0xE4, 0xE9, 0x67, 0xA4, 0x69),
+    2400                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA1, 0x28, 0xFC, 0x30, 0xDF, 0x99, 0xF0, 0x4D),
+    2401                 :            :     MBEDTLS_BYTES_TO_T_UINT_4(0x33, 0x5B, 0x45, 0xA1),
+    2402                 :            : };
+    2403                 :            : static const mbedtls_mpi_uint secp224k1_gy[] = {
+    2404                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA5, 0x61, 0x6D, 0x55, 0xDB, 0x4B, 0xCA, 0xE2),
+    2405                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x59, 0xBD, 0xB0, 0xC0, 0xF7, 0x19, 0xE3, 0xF7),
+    2406                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD6, 0xFB, 0xCA, 0x82, 0x42, 0x34, 0xBA, 0x7F),
+    2407                 :            :     MBEDTLS_BYTES_TO_T_UINT_4(0xED, 0x9F, 0x08, 0x7E),
+    2408                 :            : };
+    2409                 :            : static const mbedtls_mpi_uint secp224k1_n[] = {
+    2410                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF7, 0xB1, 0x9F, 0x76, 0x71, 0xA9, 0xF0, 0xCA),
+    2411                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x84, 0x61, 0xEC, 0xD2, 0xE8, 0xDC, 0x01, 0x00),
+    2412                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
+    2413                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00),
+    2414                 :            : };
+    2415                 :            : 
+    2416                 :            : #if MBEDTLS_ECP_FIXED_POINT_OPTIM == 1
+    2417                 :            : static const mbedtls_mpi_uint secp224k1_T_0_X[] = {
+    2418                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5C, 0xA4, 0xB7, 0xB6, 0x0E, 0x65, 0x7E, 0x0F),
+    2419                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA9, 0x75, 0x70, 0xE4, 0xE9, 0x67, 0xA4, 0x69),
+    2420                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA1, 0x28, 0xFC, 0x30, 0xDF, 0x99, 0xF0, 0x4D),
+    2421                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x33, 0x5B, 0x45, 0xA1, 0x00, 0x00, 0x00, 0x00),
+    2422                 :            : };
+    2423                 :            : static const mbedtls_mpi_uint secp224k1_T_0_Y[] = {
+    2424                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA5, 0x61, 0x6D, 0x55, 0xDB, 0x4B, 0xCA, 0xE2),
+    2425                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x59, 0xBD, 0xB0, 0xC0, 0xF7, 0x19, 0xE3, 0xF7),
+    2426                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD6, 0xFB, 0xCA, 0x82, 0x42, 0x34, 0xBA, 0x7F),
+    2427                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xED, 0x9F, 0x08, 0x7E, 0x00, 0x00, 0x00, 0x00),
+    2428                 :            : };
+    2429                 :            : static const mbedtls_mpi_uint secp224k1_T_1_X[] = {
+    2430                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x99, 0x6C, 0x22, 0x22, 0x40, 0x89, 0xAE, 0x7A),
+    2431                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2F, 0x92, 0xE1, 0x87, 0x56, 0x35, 0xAF, 0x9B),
+    2432                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x88, 0xAF, 0x08, 0x35, 0x27, 0xEA, 0x04, 0xED),
+    2433                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF0, 0x53, 0xFD, 0xCF, 0x00, 0x00, 0x00, 0x00),
+    2434                 :            : };
+    2435                 :            : static const mbedtls_mpi_uint secp224k1_T_1_Y[] = {
+    2436                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC1, 0xD0, 0x9F, 0x8D, 0xF3, 0x63, 0x54, 0x30),
+    2437                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x39, 0xDB, 0x0F, 0x61, 0x54, 0x26, 0xD1, 0x98),
+    2438                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF5, 0x21, 0xF7, 0x1B, 0xB5, 0x1D, 0xF6, 0x7E),
+    2439                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0x05, 0xDA, 0x8F, 0x00, 0x00, 0x00, 0x00),
+    2440                 :            : };
+    2441                 :            : static const mbedtls_mpi_uint secp224k1_T_2_X[] = {
+    2442                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x10, 0x26, 0x73, 0xBC, 0xE4, 0x29, 0x62, 0x56),
+    2443                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x37, 0x95, 0x17, 0x8B, 0xC3, 0x9B, 0xAC, 0xCC),
+    2444                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB1, 0xDB, 0x77, 0xDF, 0xDD, 0x13, 0x04, 0x98),
+    2445                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x02, 0xFC, 0x22, 0x93, 0x00, 0x00, 0x00, 0x00),
+    2446                 :            : };
+    2447                 :            : static const mbedtls_mpi_uint secp224k1_T_2_Y[] = {
+    2448                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAC, 0x65, 0xF1, 0x5A, 0x37, 0xEF, 0x79, 0xAD),
+    2449                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x99, 0x01, 0x37, 0xAC, 0x9A, 0x5B, 0x51, 0x65),
+    2450                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFA, 0x75, 0x13, 0xA9, 0x4A, 0xAD, 0xFE, 0x9B),
+    2451                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x32, 0x82, 0x6F, 0x66, 0x00, 0x00, 0x00, 0x00),
+    2452                 :            : };
+    2453                 :            : static const mbedtls_mpi_uint secp224k1_T_3_X[] = {
+    2454                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4D, 0x5E, 0xF0, 0x40, 0xC3, 0xA6, 0xE2, 0x1E),
+    2455                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x34, 0x9A, 0x6F, 0xCF, 0x11, 0x26, 0x66, 0x85),
+    2456                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x79, 0x73, 0xA8, 0xCF, 0x2B, 0x12, 0x36, 0x37),
+    2457                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB9, 0xB3, 0x0A, 0x58, 0x00, 0x00, 0x00, 0x00),
+    2458                 :            : };
+    2459                 :            : static const mbedtls_mpi_uint secp224k1_T_3_Y[] = {
+    2460                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD3, 0x79, 0x00, 0x55, 0x04, 0x34, 0x90, 0x1A),
+    2461                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0A, 0x54, 0x1C, 0xC2, 0x45, 0x0C, 0x1B, 0x23),
+    2462                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x86, 0x19, 0xAB, 0xA8, 0xFC, 0x73, 0xDC, 0xEE),
+    2463                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x72, 0xFB, 0x93, 0xCE, 0x00, 0x00, 0x00, 0x00),
+    2464                 :            : };
+    2465                 :            : static const mbedtls_mpi_uint secp224k1_T_4_X[] = {
+    2466                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF8, 0x75, 0xD0, 0x66, 0x95, 0x86, 0xCA, 0x66),
+    2467                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x17, 0xEA, 0x29, 0x16, 0x6A, 0x38, 0xDF, 0x41),
+    2468                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD8, 0xA2, 0x36, 0x2F, 0xDC, 0xBB, 0x5E, 0xF7),
+    2469                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD4, 0x89, 0x59, 0x49, 0x00, 0x00, 0x00, 0x00),
+    2470                 :            : };
+    2471                 :            : static const mbedtls_mpi_uint secp224k1_T_4_Y[] = {
+    2472                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCA, 0xA3, 0x99, 0x9D, 0xB8, 0x77, 0x9D, 0x1D),
+    2473                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0A, 0x93, 0x43, 0x47, 0xC6, 0x5C, 0xF9, 0xFD),
+    2474                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAA, 0x00, 0x79, 0x42, 0x64, 0xB8, 0x25, 0x3E),
+    2475                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x29, 0x54, 0xB4, 0x33, 0x00, 0x00, 0x00, 0x00),
+    2476                 :            : };
+    2477                 :            : static const mbedtls_mpi_uint secp224k1_T_5_X[] = {
+    2478                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD9, 0x0C, 0x42, 0x90, 0x83, 0x0B, 0x31, 0x5F),
+    2479                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x54, 0x2E, 0xAE, 0xC8, 0xC7, 0x5F, 0xD2, 0x70),
+    2480                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA9, 0xBC, 0xAD, 0x41, 0xE7, 0x32, 0x3A, 0x81),
+    2481                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8A, 0x97, 0x52, 0x83, 0x00, 0x00, 0x00, 0x00),
+    2482                 :            : };
+    2483                 :            : static const mbedtls_mpi_uint secp224k1_T_5_Y[] = {
+    2484                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1A, 0x13, 0x7A, 0xBD, 0xAE, 0x94, 0x60, 0xFD),
+    2485                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x92, 0x9B, 0x95, 0xB4, 0x6E, 0x68, 0xB2, 0x1F),
+    2486                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x15, 0x49, 0xBE, 0x51, 0xFE, 0x66, 0x15, 0x74),
+    2487                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE6, 0x37, 0xE4, 0xFE, 0x00, 0x00, 0x00, 0x00),
+    2488                 :            : };
+    2489                 :            : static const mbedtls_mpi_uint secp224k1_T_6_X[] = {
+    2490                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF6, 0x9B, 0xEE, 0x64, 0xC9, 0x1B, 0xBD, 0x77),
+    2491                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDA, 0x5F, 0x34, 0xA9, 0x0B, 0xB7, 0x25, 0x52),
+    2492                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x90, 0x13, 0xB1, 0x38, 0xFB, 0x9D, 0x78, 0xED),
+    2493                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x39, 0xE7, 0x1B, 0xFA, 0x00, 0x00, 0x00, 0x00),
+    2494                 :            : };
+    2495                 :            : static const mbedtls_mpi_uint secp224k1_T_6_Y[] = {
+    2496                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFB, 0xB3, 0xB7, 0x44, 0x92, 0x6B, 0x00, 0x82),
+    2497                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x97, 0x82, 0x44, 0x3E, 0x18, 0x1A, 0x58, 0x6A),
+    2498                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x15, 0xF8, 0xC0, 0xE4, 0xEE, 0xC1, 0xBF, 0x44),
+    2499                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7E, 0x32, 0x27, 0xB2, 0x00, 0x00, 0x00, 0x00),
+    2500                 :            : };
+    2501                 :            : static const mbedtls_mpi_uint secp224k1_T_7_X[] = {
+    2502                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF4, 0x9A, 0x42, 0x62, 0x8B, 0x26, 0x54, 0x21),
+    2503                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x24, 0x85, 0x74, 0xA0, 0x79, 0xA8, 0xEE, 0xBE),
+    2504                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x80, 0x36, 0x60, 0xB3, 0x28, 0x4D, 0x55, 0xBE),
+    2505                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x32, 0x27, 0x82, 0x29, 0x00, 0x00, 0x00, 0x00),
+    2506                 :            : };
+    2507                 :            : static const mbedtls_mpi_uint secp224k1_T_7_Y[] = {
+    2508                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0D, 0xFC, 0x73, 0x77, 0xAF, 0x5C, 0xAC, 0x78),
+    2509                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCC, 0xED, 0xE5, 0xF6, 0x1D, 0xA8, 0x67, 0x43),
+    2510                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF8, 0xDE, 0x33, 0x1C, 0xF1, 0x80, 0x73, 0xF8),
+    2511                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2A, 0xE2, 0xDE, 0x3C, 0x00, 0x00, 0x00, 0x00),
+    2512                 :            : };
+    2513                 :            : static const mbedtls_mpi_uint secp224k1_T_8_X[] = {
+    2514                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x57, 0x3E, 0x6B, 0xFE, 0xF0, 0x04, 0x28, 0x01),
+    2515                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBB, 0xB2, 0x14, 0x9D, 0x18, 0x11, 0x7D, 0x9D),
+    2516                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x96, 0xC4, 0xD6, 0x2E, 0x6E, 0x57, 0x4D, 0xE1),
+    2517                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEA, 0x55, 0x1B, 0xDE, 0x00, 0x00, 0x00, 0x00),
+    2518                 :            : };
+    2519                 :            : static const mbedtls_mpi_uint secp224k1_T_8_Y[] = {
+    2520                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x07, 0xF7, 0x17, 0xBC, 0x45, 0xAB, 0x16, 0xAB),
+    2521                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCD, 0xB0, 0xEF, 0x61, 0xE3, 0x20, 0x7C, 0xF8),
+    2522                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6C, 0x85, 0x41, 0x4D, 0xF1, 0x7E, 0x4D, 0x41),
+    2523                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x99, 0xC2, 0x9B, 0x5E, 0x00, 0x00, 0x00, 0x00),
+    2524                 :            : };
+    2525                 :            : static const mbedtls_mpi_uint secp224k1_T_9_X[] = {
+    2526                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x70, 0x2E, 0x49, 0x3D, 0x3E, 0x4B, 0xD3, 0x32),
+    2527                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC8, 0x2B, 0x9D, 0xD5, 0x27, 0xFA, 0xCA, 0xE0),
+    2528                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB3, 0xB3, 0x6A, 0xE0, 0x79, 0x14, 0x28, 0x0F),
+    2529                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6C, 0x1E, 0xDC, 0xF5, 0x00, 0x00, 0x00, 0x00),
+    2530                 :            : };
+    2531                 :            : static const mbedtls_mpi_uint secp224k1_T_9_Y[] = {
+    2532                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCA, 0x44, 0x56, 0xCD, 0xFC, 0x9F, 0x09, 0xFF),
+    2533                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5C, 0x8C, 0x59, 0xA4, 0x64, 0x2A, 0x3A, 0xED),
+    2534                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x40, 0xA0, 0xB5, 0x86, 0x4E, 0x69, 0xDA, 0x06),
+    2535                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x08, 0x8B, 0x11, 0x38, 0x00, 0x00, 0x00, 0x00),
+    2536                 :            : };
+    2537                 :            : static const mbedtls_mpi_uint secp224k1_T_10_X[] = {
+    2538                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA0, 0x17, 0x16, 0x12, 0x17, 0xDC, 0x00, 0x7E),
+    2539                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE7, 0x76, 0x24, 0x6C, 0x97, 0x2C, 0xB5, 0xF9),
+    2540                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x82, 0x71, 0xE3, 0xB0, 0xBB, 0x4E, 0x50, 0x52),
+    2541                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6E, 0x48, 0x26, 0xD5, 0x00, 0x00, 0x00, 0x00),
+    2542                 :            : };
+    2543                 :            : static const mbedtls_mpi_uint secp224k1_T_10_Y[] = {
+    2544                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x06, 0x5F, 0x28, 0xF6, 0x01, 0x5A, 0x60, 0x41),
+    2545                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAE, 0x95, 0xFE, 0xD0, 0xAD, 0x15, 0xD4, 0xD9),
+    2546                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAD, 0x5B, 0x7A, 0xFD, 0x80, 0xF7, 0x9F, 0x64),
+    2547                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x32, 0xBC, 0x1B, 0xDF, 0x00, 0x00, 0x00, 0x00),
+    2548                 :            : };
+    2549                 :            : static const mbedtls_mpi_uint secp224k1_T_11_X[] = {
+    2550                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBB, 0xE6, 0xDF, 0x14, 0x29, 0xF4, 0xD4, 0x14),
+    2551                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE5, 0x12, 0xDD, 0xEC, 0x5B, 0x8A, 0x59, 0xE5),
+    2552                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x26, 0x92, 0x3E, 0x35, 0x08, 0xE9, 0xCF, 0x0E),
+    2553                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE0, 0x35, 0x29, 0x97, 0x00, 0x00, 0x00, 0x00),
+    2554                 :            : };
+    2555                 :            : static const mbedtls_mpi_uint secp224k1_T_11_Y[] = {
+    2556                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x11, 0xDB, 0xD6, 0x6A, 0xC5, 0x43, 0xA4, 0xA1),
+    2557                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x61, 0x33, 0x50, 0x61, 0x70, 0xA1, 0xE9, 0xCE),
+    2558                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x15, 0x15, 0x6E, 0x5F, 0x01, 0x0C, 0x8C, 0xFA),
+    2559                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x85, 0xA1, 0x9A, 0x9D, 0x00, 0x00, 0x00, 0x00),
+    2560                 :            : };
+    2561                 :            : static const mbedtls_mpi_uint secp224k1_T_12_X[] = {
+    2562                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6E, 0xC6, 0xF7, 0xE2, 0x4A, 0xCD, 0x9B, 0x61),
+    2563                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x34, 0x4D, 0x5A, 0xB8, 0xE2, 0x6D, 0xA6, 0x50),
+    2564                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x32, 0x3F, 0xB6, 0x17, 0xE3, 0x2C, 0x6F, 0x65),
+    2565                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1E, 0xA4, 0x59, 0x51, 0x00, 0x00, 0x00, 0x00),
+    2566                 :            : };
+    2567                 :            : static const mbedtls_mpi_uint secp224k1_T_12_Y[] = {
+    2568                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x77, 0x4F, 0x7C, 0x49, 0xCD, 0x6E, 0xEB, 0x3C),
+    2569                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x05, 0xC9, 0x1F, 0xB7, 0x4D, 0x98, 0xC7, 0x67),
+    2570                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4C, 0xFD, 0x98, 0x20, 0x95, 0xBB, 0x20, 0x3A),
+    2571                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE0, 0xF2, 0x73, 0x92, 0x00, 0x00, 0x00, 0x00),
+    2572                 :            : };
+    2573                 :            : static const mbedtls_mpi_uint secp224k1_T_13_X[] = {
+    2574                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE2, 0xEF, 0xFB, 0x30, 0xFA, 0x12, 0x1A, 0xB0),
+    2575                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7A, 0x4C, 0x24, 0xB4, 0x5B, 0xC9, 0x4C, 0x0F),
+    2576                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7A, 0xDD, 0x5E, 0x84, 0x95, 0x4D, 0x26, 0xED),
+    2577                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE3, 0xFA, 0xF9, 0x3A, 0x00, 0x00, 0x00, 0x00),
+    2578                 :            : };
+    2579                 :            : static const mbedtls_mpi_uint secp224k1_T_13_Y[] = {
+    2580                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6A, 0xA3, 0x2E, 0x7A, 0xDC, 0xA7, 0x53, 0xA9),
+    2581                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7C, 0x9F, 0x81, 0x84, 0xB2, 0x0D, 0xFE, 0x31),
+    2582                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x61, 0x89, 0x1B, 0x77, 0x0C, 0x89, 0x71, 0xEC),
+    2583                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFA, 0xFF, 0x7F, 0xB2, 0x00, 0x00, 0x00, 0x00),
+    2584                 :            : };
+    2585                 :            : static const mbedtls_mpi_uint secp224k1_T_14_X[] = {
+    2586                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x28, 0xE9, 0x2C, 0x79, 0xA6, 0x3C, 0xAD, 0x93),
+    2587                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD6, 0xE0, 0x23, 0x02, 0x86, 0x0F, 0x77, 0x2A),
+    2588                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x13, 0x93, 0x6D, 0xE9, 0xF9, 0x3C, 0xBE, 0xB9),
+    2589                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x04, 0xE7, 0x24, 0x92, 0x00, 0x00, 0x00, 0x00),
+    2590                 :            : };
+    2591                 :            : static const mbedtls_mpi_uint secp224k1_T_14_Y[] = {
+    2592                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBB, 0x3C, 0x5B, 0x4B, 0x1B, 0x25, 0x37, 0xD6),
+    2593                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC9, 0xE8, 0x38, 0x1B, 0xA1, 0x5A, 0x2E, 0x68),
+    2594                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x03, 0x19, 0xFD, 0xF4, 0x78, 0x01, 0x6B, 0x44),
+    2595                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0F, 0x69, 0x37, 0x4F, 0x00, 0x00, 0x00, 0x00),
+    2596                 :            : };
+    2597                 :            : static const mbedtls_mpi_uint secp224k1_T_15_X[] = {
+    2598                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1A, 0xE2, 0xBF, 0xD3, 0xEC, 0x95, 0x9C, 0x03),
+    2599                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC2, 0x7B, 0xFC, 0xD5, 0xD3, 0x25, 0x5E, 0x0F),
+    2600                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x39, 0x55, 0x09, 0xA2, 0x58, 0x6A, 0xC9, 0xFF),
+    2601                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x80, 0xCC, 0x3B, 0xD9, 0x00, 0x00, 0x00, 0x00),
+    2602                 :            : };
+    2603                 :            : static const mbedtls_mpi_uint secp224k1_T_15_Y[] = {
+    2604                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8F, 0x08, 0x65, 0x5E, 0xCB, 0xAB, 0x48, 0xC8),
+    2605                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEE, 0x79, 0x8B, 0xC0, 0x11, 0xC0, 0x69, 0x38),
+    2606                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE6, 0xE8, 0x8C, 0x4C, 0xC5, 0x28, 0xE4, 0xAE),
+    2607                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA5, 0x1F, 0x34, 0x5C, 0x00, 0x00, 0x00, 0x00),
+    2608                 :            : };
+    2609                 :            : static const mbedtls_ecp_point secp224k1_T[16] = {
+    2610                 :            :     ECP_POINT_INIT_XY_Z1(secp224k1_T_0_X, secp224k1_T_0_Y),
+    2611                 :            :     ECP_POINT_INIT_XY_Z0(secp224k1_T_1_X, secp224k1_T_1_Y),
+    2612                 :            :     ECP_POINT_INIT_XY_Z0(secp224k1_T_2_X, secp224k1_T_2_Y),
+    2613                 :            :     ECP_POINT_INIT_XY_Z0(secp224k1_T_3_X, secp224k1_T_3_Y),
+    2614                 :            :     ECP_POINT_INIT_XY_Z0(secp224k1_T_4_X, secp224k1_T_4_Y),
+    2615                 :            :     ECP_POINT_INIT_XY_Z0(secp224k1_T_5_X, secp224k1_T_5_Y),
+    2616                 :            :     ECP_POINT_INIT_XY_Z0(secp224k1_T_6_X, secp224k1_T_6_Y),
+    2617                 :            :     ECP_POINT_INIT_XY_Z0(secp224k1_T_7_X, secp224k1_T_7_Y),
+    2618                 :            :     ECP_POINT_INIT_XY_Z0(secp224k1_T_8_X, secp224k1_T_8_Y),
+    2619                 :            :     ECP_POINT_INIT_XY_Z0(secp224k1_T_9_X, secp224k1_T_9_Y),
+    2620                 :            :     ECP_POINT_INIT_XY_Z0(secp224k1_T_10_X, secp224k1_T_10_Y),
+    2621                 :            :     ECP_POINT_INIT_XY_Z0(secp224k1_T_11_X, secp224k1_T_11_Y),
+    2622                 :            :     ECP_POINT_INIT_XY_Z0(secp224k1_T_12_X, secp224k1_T_12_Y),
+    2623                 :            :     ECP_POINT_INIT_XY_Z0(secp224k1_T_13_X, secp224k1_T_13_Y),
+    2624                 :            :     ECP_POINT_INIT_XY_Z0(secp224k1_T_14_X, secp224k1_T_14_Y),
+    2625                 :            :     ECP_POINT_INIT_XY_Z0(secp224k1_T_15_X, secp224k1_T_15_Y),
+    2626                 :            : };
+    2627                 :            : #else
+    2628                 :            : #define secp224k1_T NULL
+    2629                 :            : #endif
+    2630                 :            : #endif /* MBEDTLS_ECP_DP_SECP224K1_ENABLED */
+    2631                 :            : 
+    2632                 :            : #if defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED)
+    2633                 :            : static const mbedtls_mpi_uint secp256k1_p[] = {
+    2634                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2F, 0xFC, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF),
+    2635                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
+    2636                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
+    2637                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
+    2638                 :            : };
+    2639                 :            : static const mbedtls_mpi_uint secp256k1_a[] = {
+    2640                 :            :     MBEDTLS_BYTES_TO_T_UINT_2(0x00, 0x00),
+    2641                 :            : };
+    2642                 :            : static const mbedtls_mpi_uint secp256k1_b[] = {
+    2643                 :            :     MBEDTLS_BYTES_TO_T_UINT_2(0x07, 0x00),
+    2644                 :            : };
+    2645                 :            : static const mbedtls_mpi_uint secp256k1_gx[] = {
+    2646                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x98, 0x17, 0xF8, 0x16, 0x5B, 0x81, 0xF2, 0x59),
+    2647                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD9, 0x28, 0xCE, 0x2D, 0xDB, 0xFC, 0x9B, 0x02),
+    2648                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x07, 0x0B, 0x87, 0xCE, 0x95, 0x62, 0xA0, 0x55),
+    2649                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAC, 0xBB, 0xDC, 0xF9, 0x7E, 0x66, 0xBE, 0x79),
+    2650                 :            : };
+    2651                 :            : static const mbedtls_mpi_uint secp256k1_gy[] = {
+    2652                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB8, 0xD4, 0x10, 0xFB, 0x8F, 0xD0, 0x47, 0x9C),
+    2653                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x19, 0x54, 0x85, 0xA6, 0x48, 0xB4, 0x17, 0xFD),
+    2654                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA8, 0x08, 0x11, 0x0E, 0xFC, 0xFB, 0xA4, 0x5D),
+    2655                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x65, 0xC4, 0xA3, 0x26, 0x77, 0xDA, 0x3A, 0x48),
+    2656                 :            : };
+    2657                 :            : static const mbedtls_mpi_uint secp256k1_n[] = {
+    2658                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x41, 0x41, 0x36, 0xD0, 0x8C, 0x5E, 0xD2, 0xBF),
+    2659                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3B, 0xA0, 0x48, 0xAF, 0xE6, 0xDC, 0xAE, 0xBA),
+    2660                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
+    2661                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
+    2662                 :            : };
+    2663                 :            : 
+    2664                 :            : #if MBEDTLS_ECP_FIXED_POINT_OPTIM == 1
+    2665                 :            : static const mbedtls_mpi_uint secp256k1_T_0_X[] = {
+    2666                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x98, 0x17, 0xF8, 0x16, 0x5B, 0x81, 0xF2, 0x59),
+    2667                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD9, 0x28, 0xCE, 0x2D, 0xDB, 0xFC, 0x9B, 0x02),
+    2668                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x07, 0x0B, 0x87, 0xCE, 0x95, 0x62, 0xA0, 0x55),
+    2669                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAC, 0xBB, 0xDC, 0xF9, 0x7E, 0x66, 0xBE, 0x79),
+    2670                 :            : };
+    2671                 :            : static const mbedtls_mpi_uint secp256k1_T_0_Y[] = {
+    2672                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB8, 0xD4, 0x10, 0xFB, 0x8F, 0xD0, 0x47, 0x9C),
+    2673                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x19, 0x54, 0x85, 0xA6, 0x48, 0xB4, 0x17, 0xFD),
+    2674                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA8, 0x08, 0x11, 0x0E, 0xFC, 0xFB, 0xA4, 0x5D),
+    2675                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x65, 0xC4, 0xA3, 0x26, 0x77, 0xDA, 0x3A, 0x48),
+    2676                 :            : };
+    2677                 :            : static const mbedtls_mpi_uint secp256k1_T_1_X[] = {
+    2678                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE7, 0xEE, 0xD7, 0x1E, 0x67, 0x86, 0x32, 0x74),
+    2679                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x23, 0x73, 0xB1, 0xA9, 0xD5, 0xCC, 0x27, 0x78),
+    2680                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1F, 0x0E, 0x11, 0x01, 0x71, 0xFE, 0x92, 0x73),
+    2681                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC6, 0x28, 0x63, 0x6D, 0x72, 0x09, 0xA6, 0xC0),
+    2682                 :            : };
+    2683                 :            : static const mbedtls_mpi_uint secp256k1_T_1_Y[] = {
+    2684                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCE, 0xE1, 0x69, 0xDC, 0x3E, 0x2C, 0x75, 0xC3),
+    2685                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE5, 0xB7, 0x3F, 0x30, 0x26, 0x3C, 0xDF, 0x8E),
+    2686                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3D, 0xBE, 0xB9, 0x5D, 0x0E, 0xE8, 0x5E, 0x14),
+    2687                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x01, 0xC3, 0x05, 0xD6, 0xB7, 0xD5, 0x24, 0xFC),
+    2688                 :            : };
+    2689                 :            : static const mbedtls_mpi_uint secp256k1_T_2_X[] = {
+    2690                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x13, 0xCF, 0x7B, 0xDC, 0xCD, 0xC3, 0x39, 0x9D),
+    2691                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x42, 0xDA, 0xB9, 0xE5, 0x64, 0xA7, 0x47, 0x91),
+    2692                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x76, 0x46, 0xA8, 0x61, 0xF6, 0x23, 0xEB, 0x58),
+    2693                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5C, 0xC1, 0xFF, 0xE4, 0x55, 0xD5, 0xC2, 0xBF),
+    2694                 :            : };
+    2695                 :            : static const mbedtls_mpi_uint secp256k1_T_2_Y[] = {
+    2696                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC9, 0xBE, 0xB9, 0x59, 0x24, 0x13, 0x4A, 0x2A),
+    2697                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x64, 0x45, 0x12, 0xDE, 0xBA, 0x4F, 0xEF, 0x56),
+    2698                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBE, 0x08, 0xBF, 0xC1, 0x66, 0xAA, 0x0A, 0xBC),
+    2699                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x36, 0xFE, 0x30, 0x55, 0x31, 0x86, 0xA7, 0xB4),
+    2700                 :            : };
+    2701                 :            : static const mbedtls_mpi_uint secp256k1_T_3_X[] = {
+    2702                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1D, 0xBF, 0x18, 0x81, 0x67, 0x27, 0x42, 0xBD),
+    2703                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x08, 0x05, 0x83, 0xA4, 0xDD, 0x57, 0xD3, 0x50),
+    2704                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x20, 0x63, 0xAB, 0xE4, 0x90, 0x70, 0xD0, 0x7C),
+    2705                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x71, 0x5D, 0xFD, 0xA0, 0xEF, 0xCF, 0x1C, 0x54),
+    2706                 :            : };
+    2707                 :            : static const mbedtls_mpi_uint secp256k1_T_3_Y[] = {
+    2708                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x13, 0x80, 0xE4, 0xF6, 0x09, 0xBC, 0x57, 0x90),
+    2709                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x21, 0x9F, 0x6E, 0x88, 0x54, 0x6E, 0x51, 0xF2),
+    2710                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF5, 0x5F, 0x85, 0xFB, 0x84, 0x3E, 0x4A, 0xAA),
+    2711                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA8, 0x19, 0xF5, 0x55, 0xC9, 0x07, 0xD8, 0xCE),
+    2712                 :            : };
+    2713                 :            : static const mbedtls_mpi_uint secp256k1_T_4_X[] = {
+    2714                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1A, 0xB4, 0xC3, 0xD9, 0x5C, 0xA0, 0xD4, 0x90),
+    2715                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0D, 0x30, 0xAF, 0x59, 0x9B, 0xF8, 0x04, 0x85),
+    2716                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4D, 0xA6, 0xFD, 0x66, 0x7B, 0xC3, 0x39, 0x85),
+    2717                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE0, 0xBF, 0xF0, 0xC2, 0xE9, 0x71, 0xA4, 0x9E),
+    2718                 :            : };
+    2719                 :            : static const mbedtls_mpi_uint secp256k1_T_4_Y[] = {
+    2720                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x14, 0x2D, 0xB9, 0x88, 0x28, 0xF1, 0xBE, 0x78),
+    2721                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x14, 0xF3, 0x1A, 0x0E, 0xB9, 0x01, 0x66, 0x34),
+    2722                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x77, 0xA7, 0xA4, 0xF4, 0x05, 0xD0, 0xAA, 0x53),
+    2723                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x00, 0x39, 0x1E, 0x47, 0xE5, 0x68, 0xC8, 0xC0),
+    2724                 :            : };
+    2725                 :            : static const mbedtls_mpi_uint secp256k1_T_5_X[] = {
+    2726                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDD, 0xB9, 0xFC, 0xE0, 0x33, 0x8A, 0x7D, 0x96),
+    2727                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4F, 0x93, 0xA5, 0x53, 0x55, 0x16, 0xB4, 0x6E),
+    2728                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE9, 0x5F, 0xEA, 0x9B, 0x29, 0x52, 0x71, 0xDA),
+    2729                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB2, 0xF0, 0x24, 0xB8, 0x7D, 0xB7, 0xA0, 0x9B),
+    2730                 :            : };
+    2731                 :            : static const mbedtls_mpi_uint secp256k1_T_5_Y[] = {
+    2732                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC2, 0x00, 0x27, 0xB2, 0xDF, 0x73, 0xA2, 0xE0),
+    2733                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1D, 0x2E, 0x4D, 0x7C, 0xDE, 0x7A, 0x23, 0x32),
+    2734                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAC, 0x65, 0x60, 0xC7, 0x97, 0x1E, 0xA4, 0x22),
+    2735                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCD, 0x13, 0x5B, 0x77, 0x59, 0xCB, 0x36, 0xE1),
+    2736                 :            : };
+    2737                 :            : static const mbedtls_mpi_uint secp256k1_T_6_X[] = {
+    2738                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x99, 0xBC, 0x9F, 0x9E, 0x2D, 0x53, 0x2A, 0xA8),
+    2739                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x87, 0x5F, 0x64, 0x9F, 0x1A, 0x19, 0xE6, 0x77),
+    2740                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9E, 0x7B, 0x39, 0xD2, 0xDB, 0x85, 0x84, 0xD5),
+    2741                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x83, 0xC7, 0x0D, 0x58, 0x6E, 0x3F, 0x52, 0x15),
+    2742                 :            : };
+    2743                 :            : static const mbedtls_mpi_uint secp256k1_T_6_Y[] = {
+    2744                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x21, 0x68, 0x19, 0x0B, 0x68, 0xC9, 0x1E, 0xFB),
+    2745                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD2, 0x4E, 0x21, 0x49, 0x3D, 0x55, 0xCC, 0x25),
+    2746                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF5, 0xF9, 0x25, 0x45, 0x54, 0x45, 0xB1, 0x0F),
+    2747                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA9, 0xB3, 0xF7, 0xCD, 0x80, 0xA4, 0x04, 0x05),
+    2748                 :            : };
+    2749                 :            : static const mbedtls_mpi_uint secp256k1_T_7_X[] = {
+    2750                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD4, 0x1E, 0x88, 0xC4, 0xAA, 0x18, 0x7E, 0x45),
+    2751                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4B, 0xAC, 0xD9, 0xB2, 0xA1, 0xC0, 0x71, 0x5D),
+    2752                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA9, 0xA2, 0xF1, 0x15, 0xA6, 0x5F, 0x6C, 0x86),
+    2753                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4F, 0x5B, 0x05, 0xBC, 0xB7, 0xC6, 0x4E, 0x72),
+    2754                 :            : };
+    2755                 :            : static const mbedtls_mpi_uint secp256k1_T_7_Y[] = {
+    2756                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1D, 0x80, 0xF8, 0x5C, 0x20, 0x2A, 0xE1, 0xE2),
+    2757                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7C, 0x48, 0x2E, 0x68, 0x82, 0x7F, 0xEB, 0x5F),
+    2758                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA2, 0x3B, 0x25, 0xDB, 0x32, 0x4D, 0x88, 0x42),
+    2759                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEE, 0x6E, 0xA6, 0xB6, 0x6D, 0x62, 0x78, 0x22),
+    2760                 :            : };
+    2761                 :            : static const mbedtls_mpi_uint secp256k1_T_8_X[] = {
+    2762                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1F, 0x4D, 0x3E, 0x86, 0x58, 0xC3, 0xEB, 0xBA),
+    2763                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1A, 0x89, 0x33, 0x18, 0x21, 0x1D, 0x9B, 0xE7),
+    2764                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0B, 0x9D, 0xFF, 0xC3, 0x79, 0xC1, 0x88, 0xF8),
+    2765                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x28, 0xD4, 0x48, 0x53, 0xE8, 0xAD, 0x21, 0x16),
+    2766                 :            : };
+    2767                 :            : static const mbedtls_mpi_uint secp256k1_T_8_Y[] = {
+    2768                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF5, 0x7B, 0xDE, 0xCB, 0xD8, 0x39, 0x17, 0x7C),
+    2769                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD3, 0xF3, 0x03, 0xF2, 0x5C, 0xBC, 0xC8, 0x8A),
+    2770                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x27, 0xAE, 0x4C, 0xB0, 0x16, 0xA4, 0x93, 0x86),
+    2771                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x71, 0x8B, 0x6B, 0xDC, 0xD7, 0x9A, 0x3E, 0x7E),
+    2772                 :            : };
+    2773                 :            : static const mbedtls_mpi_uint secp256k1_T_9_X[] = {
+    2774                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD6, 0x2D, 0x7A, 0xD2, 0x59, 0x05, 0xA2, 0x82),
+    2775                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x57, 0x56, 0x09, 0x32, 0xF1, 0xE8, 0xE3, 0x72),
+    2776                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x03, 0xCA, 0xE5, 0x2E, 0xF0, 0xFB, 0x18, 0x19),
+    2777                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBA, 0x85, 0xA9, 0x23, 0x15, 0x31, 0x1F, 0x0E),
+    2778                 :            : };
+    2779                 :            : static const mbedtls_mpi_uint secp256k1_T_9_Y[] = {
+    2780                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x76, 0xE5, 0xB1, 0x86, 0xB9, 0x6E, 0x8D, 0xD3),
+    2781                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6C, 0x77, 0xFC, 0xC9, 0xA3, 0x3F, 0x89, 0xD2),
+    2782                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDB, 0x6A, 0xDC, 0x25, 0xB0, 0xC7, 0x41, 0x54),
+    2783                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x02, 0x11, 0x6B, 0xA6, 0x11, 0x62, 0xD4, 0x2D),
+    2784                 :            : };
+    2785                 :            : static const mbedtls_mpi_uint secp256k1_T_10_X[] = {
+    2786                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x19, 0x7D, 0x34, 0xB3, 0x20, 0x7F, 0x37, 0xAA),
+    2787                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBD, 0xD4, 0x45, 0xE8, 0xC2, 0xE9, 0xC5, 0xEA),
+    2788                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5A, 0x32, 0x3B, 0x25, 0x7E, 0x79, 0xAF, 0xE7),
+    2789                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3F, 0xE4, 0x54, 0x71, 0xBE, 0x35, 0x4E, 0xD0),
+    2790                 :            : };
+    2791                 :            : static const mbedtls_mpi_uint secp256k1_T_10_Y[] = {
+    2792                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB0, 0x94, 0xDD, 0x8F, 0xB5, 0xC2, 0xDD, 0x75),
+    2793                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x07, 0x49, 0xE9, 0x1C, 0x2F, 0x08, 0x49, 0xC6),
+    2794                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x77, 0xB6, 0x03, 0x88, 0x6F, 0xB8, 0x15, 0x67),
+    2795                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA4, 0xD3, 0x1C, 0xF3, 0xA5, 0xEB, 0x79, 0x01),
+    2796                 :            : };
+    2797                 :            : static const mbedtls_mpi_uint secp256k1_T_11_X[] = {
+    2798                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x25, 0xF9, 0x43, 0x88, 0x89, 0x0D, 0x06, 0xEA),
+    2799                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x02, 0x2D, 0xF5, 0x98, 0x32, 0xF6, 0xB1, 0x05),
+    2800                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x23, 0x73, 0x8F, 0x2B, 0x50, 0x27, 0x0A, 0xE7),
+    2801                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA7, 0xE3, 0xBD, 0x16, 0x05, 0xC8, 0x93, 0x12),
+    2802                 :            : };
+    2803                 :            : static const mbedtls_mpi_uint secp256k1_T_11_Y[] = {
+    2804                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0A, 0x6A, 0xF7, 0xE3, 0x3D, 0xDE, 0x5F, 0x2F),
+    2805                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x47, 0xA3, 0x9C, 0x22, 0x3C, 0x33, 0x36, 0x5D),
+    2806                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x20, 0x24, 0x4C, 0x69, 0x45, 0x78, 0x14, 0xAE),
+    2807                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x59, 0xF8, 0xD4, 0xBF, 0xB8, 0xC0, 0xA1, 0x25),
+    2808                 :            : };
+    2809                 :            : static const mbedtls_mpi_uint secp256k1_T_12_X[] = {
+    2810                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7E, 0x88, 0xE1, 0x91, 0x03, 0xEB, 0xB3, 0x2B),
+    2811                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5C, 0x11, 0xA1, 0xEF, 0x14, 0x0D, 0xC4, 0x7D),
+    2812                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFE, 0xD4, 0x0D, 0x1D, 0x96, 0x33, 0x5C, 0x19),
+    2813                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x70, 0x45, 0x2A, 0x1A, 0xE6, 0x57, 0x04, 0x9B),
+    2814                 :            : };
+    2815                 :            : static const mbedtls_mpi_uint secp256k1_T_12_Y[] = {
+    2816                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x70, 0xB5, 0xA7, 0x80, 0xE9, 0x93, 0x97, 0x8D),
+    2817                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5D, 0xB9, 0x7C, 0xA0, 0xC9, 0x57, 0x26, 0x43),
+    2818                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9E, 0xEF, 0x56, 0xDA, 0x66, 0xF6, 0x1B, 0x9A),
+    2819                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1F, 0x89, 0x6B, 0x91, 0xE0, 0xA9, 0x65, 0x2B),
+    2820                 :            : };
+    2821                 :            : static const mbedtls_mpi_uint secp256k1_T_13_X[] = {
+    2822                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x91, 0x98, 0x96, 0x9B, 0x06, 0x7D, 0x5E, 0x5A),
+    2823                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0A, 0xFA, 0xC1, 0x5F, 0x19, 0x37, 0x94, 0x9D),
+    2824                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCF, 0xBE, 0x6B, 0x1A, 0x05, 0xE4, 0xBF, 0x9F),
+    2825                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x84, 0xCD, 0x5D, 0x35, 0xB4, 0x51, 0xF7, 0x64),
+    2826                 :            : };
+    2827                 :            : static const mbedtls_mpi_uint secp256k1_T_13_Y[] = {
+    2828                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6C, 0xEF, 0x96, 0xDB, 0xF2, 0x61, 0x63, 0x59),
+    2829                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCB, 0x04, 0x88, 0xC9, 0x9F, 0x1B, 0x94, 0xB9),
+    2830                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDB, 0x30, 0x79, 0x7E, 0x24, 0xE7, 0x5F, 0xB8),
+    2831                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3F, 0xB8, 0x90, 0xB7, 0x94, 0x25, 0xBB, 0x0F),
+    2832                 :            : };
+    2833                 :            : static const mbedtls_mpi_uint secp256k1_T_14_X[] = {
+    2834                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x62, 0x79, 0xEA, 0xAD, 0xC0, 0x6D, 0x18, 0x57),
+    2835                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE9, 0xA4, 0x58, 0x2A, 0x8D, 0x95, 0xB3, 0xE6),
+    2836                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC8, 0xC4, 0xC2, 0x12, 0x0D, 0x79, 0xE2, 0x2B),
+    2837                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x02, 0x6F, 0xBE, 0x97, 0x4D, 0xA4, 0x20, 0x07),
+    2838                 :            : };
+    2839                 :            : static const mbedtls_mpi_uint secp256k1_T_14_Y[] = {
+    2840                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCA, 0x31, 0x71, 0xC6, 0xA6, 0x91, 0xEB, 0x1F),
+    2841                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB4, 0x9B, 0xA8, 0x4A, 0xE7, 0x77, 0xE1, 0xAA),
+    2842                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA9, 0x06, 0xD3, 0x3D, 0x94, 0x30, 0xEF, 0x8C),
+    2843                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE7, 0xDF, 0xCA, 0xFA, 0xF5, 0x28, 0xF8, 0xC9),
+    2844                 :            : };
+    2845                 :            : static const mbedtls_mpi_uint secp256k1_T_15_X[] = {
+    2846                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCC, 0xE1, 0x32, 0xFD, 0x3E, 0x81, 0xF8, 0x11),
+    2847                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCD, 0xF2, 0x4B, 0x1D, 0x19, 0xC9, 0x0F, 0xCC),
+    2848                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x59, 0xB1, 0x8A, 0x22, 0x8B, 0x05, 0x6B, 0x56),
+    2849                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x35, 0x21, 0xEF, 0x30, 0xEC, 0x09, 0x2A, 0x89),
+    2850                 :            : };
+    2851                 :            : static const mbedtls_mpi_uint secp256k1_T_15_Y[] = {
+    2852                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x15, 0x84, 0x4A, 0x46, 0x07, 0x6C, 0x3C, 0x4C),
+    2853                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDD, 0x18, 0x3A, 0xF4, 0xCC, 0xF5, 0xB2, 0xF2),
+    2854                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4F, 0x8F, 0xCD, 0x0A, 0x9C, 0xF4, 0xBD, 0x95),
+    2855                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x37, 0x89, 0x7F, 0x8A, 0xB1, 0x52, 0x3A, 0xAB),
+    2856                 :            : };
+    2857                 :            : static const mbedtls_ecp_point secp256k1_T[16] = {
+    2858                 :            :     ECP_POINT_INIT_XY_Z1(secp256k1_T_0_X, secp256k1_T_0_Y),
+    2859                 :            :     ECP_POINT_INIT_XY_Z0(secp256k1_T_1_X, secp256k1_T_1_Y),
+    2860                 :            :     ECP_POINT_INIT_XY_Z0(secp256k1_T_2_X, secp256k1_T_2_Y),
+    2861                 :            :     ECP_POINT_INIT_XY_Z0(secp256k1_T_3_X, secp256k1_T_3_Y),
+    2862                 :            :     ECP_POINT_INIT_XY_Z0(secp256k1_T_4_X, secp256k1_T_4_Y),
+    2863                 :            :     ECP_POINT_INIT_XY_Z0(secp256k1_T_5_X, secp256k1_T_5_Y),
+    2864                 :            :     ECP_POINT_INIT_XY_Z0(secp256k1_T_6_X, secp256k1_T_6_Y),
+    2865                 :            :     ECP_POINT_INIT_XY_Z0(secp256k1_T_7_X, secp256k1_T_7_Y),
+    2866                 :            :     ECP_POINT_INIT_XY_Z0(secp256k1_T_8_X, secp256k1_T_8_Y),
+    2867                 :            :     ECP_POINT_INIT_XY_Z0(secp256k1_T_9_X, secp256k1_T_9_Y),
+    2868                 :            :     ECP_POINT_INIT_XY_Z0(secp256k1_T_10_X, secp256k1_T_10_Y),
+    2869                 :            :     ECP_POINT_INIT_XY_Z0(secp256k1_T_11_X, secp256k1_T_11_Y),
+    2870                 :            :     ECP_POINT_INIT_XY_Z0(secp256k1_T_12_X, secp256k1_T_12_Y),
+    2871                 :            :     ECP_POINT_INIT_XY_Z0(secp256k1_T_13_X, secp256k1_T_13_Y),
+    2872                 :            :     ECP_POINT_INIT_XY_Z0(secp256k1_T_14_X, secp256k1_T_14_Y),
+    2873                 :            :     ECP_POINT_INIT_XY_Z0(secp256k1_T_15_X, secp256k1_T_15_Y),
+    2874                 :            : };
+    2875                 :            : #else
+    2876                 :            : #define secp256k1_T NULL
+    2877                 :            : #endif
+    2878                 :            : #endif /* MBEDTLS_ECP_DP_SECP256K1_ENABLED */
+    2879                 :            : 
+    2880                 :            : /*
+    2881                 :            :  * Domain parameters for brainpoolP256r1 (RFC 5639 3.4)
+    2882                 :            :  */
+    2883                 :            : #if defined(MBEDTLS_ECP_DP_BP256R1_ENABLED)
+    2884                 :            : static const mbedtls_mpi_uint brainpoolP256r1_p[] = {
+    2885                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x77, 0x53, 0x6E, 0x1F, 0x1D, 0x48, 0x13, 0x20),
+    2886                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x28, 0x20, 0x26, 0xD5, 0x23, 0xF6, 0x3B, 0x6E),
+    2887                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x72, 0x8D, 0x83, 0x9D, 0x90, 0x0A, 0x66, 0x3E),
+    2888                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBC, 0xA9, 0xEE, 0xA1, 0xDB, 0x57, 0xFB, 0xA9),
+    2889                 :            : };
+    2890                 :            : static const mbedtls_mpi_uint brainpoolP256r1_a[] = {
+    2891                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD9, 0xB5, 0x30, 0xF3, 0x44, 0x4B, 0x4A, 0xE9),
+    2892                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6C, 0x5C, 0xDC, 0x26, 0xC1, 0x55, 0x80, 0xFB),
+    2893                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE7, 0xFF, 0x7A, 0x41, 0x30, 0x75, 0xF6, 0xEE),
+    2894                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x57, 0x30, 0x2C, 0xFC, 0x75, 0x09, 0x5A, 0x7D),
+    2895                 :            : };
+    2896                 :            : static const mbedtls_mpi_uint brainpoolP256r1_b[] = {
+    2897                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB6, 0x07, 0x8C, 0xFF, 0x18, 0xDC, 0xCC, 0x6B),
+    2898                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCE, 0xE1, 0xF7, 0x5C, 0x29, 0x16, 0x84, 0x95),
+    2899                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBF, 0x7C, 0xD7, 0xBB, 0xD9, 0xB5, 0x30, 0xF3),
+    2900                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x44, 0x4B, 0x4A, 0xE9, 0x6C, 0x5C, 0xDC, 0x26),
+    2901                 :            : };
+    2902                 :            : static const mbedtls_mpi_uint brainpoolP256r1_gx[] = {
+    2903                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x62, 0x32, 0xCE, 0x9A, 0xBD, 0x53, 0x44, 0x3A),
+    2904                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC2, 0x23, 0xBD, 0xE3, 0xE1, 0x27, 0xDE, 0xB9),
+    2905                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAF, 0xB7, 0x81, 0xFC, 0x2F, 0x48, 0x4B, 0x2C),
+    2906                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCB, 0x57, 0x7E, 0xCB, 0xB9, 0xAE, 0xD2, 0x8B),
+    2907                 :            : };
+    2908                 :            : static const mbedtls_mpi_uint brainpoolP256r1_gy[] = {
+    2909                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x97, 0x69, 0x04, 0x2F, 0xC7, 0x54, 0x1D, 0x5C),
+    2910                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x54, 0x8E, 0xED, 0x2D, 0x13, 0x45, 0x77, 0xC2),
+    2911                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC9, 0x1D, 0x61, 0x14, 0x1A, 0x46, 0xF8, 0x97),
+    2912                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFD, 0xC4, 0xDA, 0xC3, 0x35, 0xF8, 0x7E, 0x54),
+    2913                 :            : };
+    2914                 :            : static const mbedtls_mpi_uint brainpoolP256r1_n[] = {
+    2915                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA7, 0x56, 0x48, 0x97, 0x82, 0x0E, 0x1E, 0x90),
+    2916                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF7, 0xA6, 0x61, 0xB5, 0xA3, 0x7A, 0x39, 0x8C),
+    2917                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x71, 0x8D, 0x83, 0x9D, 0x90, 0x0A, 0x66, 0x3E),
+    2918                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBC, 0xA9, 0xEE, 0xA1, 0xDB, 0x57, 0xFB, 0xA9),
+    2919                 :            : };
+    2920                 :            : 
+    2921                 :            : #if MBEDTLS_ECP_FIXED_POINT_OPTIM == 1
+    2922                 :            : static const mbedtls_mpi_uint brainpoolP256r1_T_0_X[] = {
+    2923                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x62, 0x32, 0xCE, 0x9A, 0xBD, 0x53, 0x44, 0x3A),
+    2924                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC2, 0x23, 0xBD, 0xE3, 0xE1, 0x27, 0xDE, 0xB9),
+    2925                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAF, 0xB7, 0x81, 0xFC, 0x2F, 0x48, 0x4B, 0x2C),
+    2926                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCB, 0x57, 0x7E, 0xCB, 0xB9, 0xAE, 0xD2, 0x8B),
+    2927                 :            : };
+    2928                 :            : static const mbedtls_mpi_uint brainpoolP256r1_T_0_Y[] = {
+    2929                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x97, 0x69, 0x04, 0x2F, 0xC7, 0x54, 0x1D, 0x5C),
+    2930                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x54, 0x8E, 0xED, 0x2D, 0x13, 0x45, 0x77, 0xC2),
+    2931                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC9, 0x1D, 0x61, 0x14, 0x1A, 0x46, 0xF8, 0x97),
+    2932                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFD, 0xC4, 0xDA, 0xC3, 0x35, 0xF8, 0x7E, 0x54),
+    2933                 :            : };
+    2934                 :            : static const mbedtls_mpi_uint brainpoolP256r1_T_1_X[] = {
+    2935                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3C, 0xA2, 0xED, 0x52, 0xC9, 0x8C, 0xE3, 0xA5),
+    2936                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x72, 0xC9, 0xC4, 0x87, 0x3F, 0x93, 0x7A, 0xD1),
+    2937                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x96, 0x12, 0x53, 0x61, 0x3E, 0x76, 0x08, 0xCB),
+    2938                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x09, 0x8C, 0x74, 0xF4, 0x08, 0xC3, 0x76, 0x80),
+    2939                 :            : };
+    2940                 :            : static const mbedtls_mpi_uint brainpoolP256r1_T_1_Y[] = {
+    2941                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x05, 0xDD, 0x09, 0xA6, 0xED, 0xEE, 0xC4, 0x38),
+    2942                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x74, 0xD9, 0xBE, 0x4B, 0xA5, 0xB7, 0x2B, 0x6E),
+    2943                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x42, 0x20, 0x12, 0xCA, 0x0A, 0x38, 0x24, 0xAB),
+    2944                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x00, 0x72, 0x71, 0x90, 0x7A, 0x2E, 0xB7, 0x23),
+    2945                 :            : };
+    2946                 :            : static const mbedtls_mpi_uint brainpoolP256r1_T_2_X[] = {
+    2947                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2C, 0x66, 0xA1, 0x93, 0x10, 0x2A, 0x51, 0x17),
+    2948                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x88, 0x10, 0x11, 0x12, 0xBC, 0xB0, 0xB6, 0x93),
+    2949                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3C, 0x58, 0xD7, 0x0A, 0x84, 0x05, 0xA3, 0x9C),
+    2950                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF7, 0x8E, 0x95, 0x61, 0xD3, 0x0B, 0xDF, 0x36),
+    2951                 :            : };
+    2952                 :            : static const mbedtls_mpi_uint brainpoolP256r1_T_2_Y[] = {
+    2953                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF9, 0x92, 0x12, 0x0F, 0x5E, 0x87, 0x70, 0x1B),
+    2954                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x38, 0xE9, 0x9B, 0xEB, 0x3A, 0xFB, 0xCF, 0xC4),
+    2955                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDC, 0x92, 0xB9, 0xF7, 0x45, 0xD3, 0x06, 0xB6),
+    2956                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x82, 0x28, 0x65, 0xE1, 0xC5, 0x6C, 0x57, 0x18),
+    2957                 :            : };
+    2958                 :            : static const mbedtls_mpi_uint brainpoolP256r1_T_3_X[] = {
+    2959                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x28, 0x0E, 0x77, 0x01, 0x81, 0x9E, 0x38, 0x5C),
+    2960                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x71, 0xF0, 0xD5, 0xA5, 0x91, 0x2B, 0xDF, 0xC0),
+    2961                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD8, 0xEE, 0xB6, 0x25, 0xD6, 0x98, 0xDE, 0x2D),
+    2962                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7B, 0xA1, 0x55, 0x63, 0x39, 0xEB, 0xB5, 0x47),
+    2963                 :            : };
+    2964                 :            : static const mbedtls_mpi_uint brainpoolP256r1_T_3_Y[] = {
+    2965                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB6, 0xD6, 0xB8, 0xE3, 0x13, 0xED, 0x7F, 0xA3),
+    2966                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6C, 0xE8, 0xAE, 0x36, 0xB8, 0xCD, 0x19, 0x02),
+    2967                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF9, 0x82, 0x83, 0x7A, 0x7B, 0x46, 0x56, 0xE8),
+    2968                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4E, 0x60, 0x46, 0x15, 0x5A, 0xAC, 0x99, 0x30),
+    2969                 :            : };
+    2970                 :            : static const mbedtls_mpi_uint brainpoolP256r1_T_4_X[] = {
+    2971                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBF, 0x61, 0x50, 0xC6, 0xFF, 0x10, 0x7D, 0x04),
+    2972                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x92, 0x51, 0xDF, 0xA9, 0x7D, 0x78, 0x26, 0x74),
+    2973                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x56, 0x15, 0x9A, 0xF7, 0x01, 0xC1, 0xBB, 0x40),
+    2974                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x26, 0x0F, 0xE6, 0x2A, 0xBD, 0x4A, 0x9E, 0x87),
+    2975                 :            : };
+    2976                 :            : static const mbedtls_mpi_uint brainpoolP256r1_T_4_Y[] = {
+    2977                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x57, 0xF8, 0xD1, 0x77, 0xD2, 0x49, 0xB3, 0xDD),
+    2978                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x36, 0x86, 0xFB, 0x9E, 0x1F, 0x5A, 0x60, 0x47),
+    2979                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x98, 0xC4, 0x8D, 0xCD, 0x86, 0x61, 0x2F, 0xF9),
+    2980                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x41, 0xF6, 0xB9, 0xAC, 0x37, 0x9D, 0xE9, 0x28),
+    2981                 :            : };
+    2982                 :            : static const mbedtls_mpi_uint brainpoolP256r1_T_5_X[] = {
+    2983                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFA, 0x77, 0xAA, 0x97, 0x9C, 0x0B, 0x04, 0x20),
+    2984                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x80, 0xA6, 0x60, 0x81, 0xCE, 0x25, 0x13, 0x3E),
+    2985                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x24, 0x00, 0xF3, 0xBB, 0x82, 0x99, 0x95, 0xB7),
+    2986                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x47, 0x5A, 0xCE, 0x90, 0x71, 0x38, 0x2F, 0x10),
+    2987                 :            : };
+    2988                 :            : static const mbedtls_mpi_uint brainpoolP256r1_T_5_Y[] = {
+    2989                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA7, 0x1A, 0xC0, 0x84, 0x27, 0xD6, 0x9D, 0xB7),
+    2990                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x34, 0x37, 0x52, 0x16, 0x13, 0x0E, 0xCE, 0x92),
+    2991                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1E, 0xBF, 0x5A, 0xDB, 0xDB, 0x6E, 0x1E, 0x69),
+    2992                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3E, 0xB7, 0x5E, 0xF9, 0x86, 0xDD, 0x8A, 0x5C),
+    2993                 :            : };
+    2994                 :            : static const mbedtls_mpi_uint brainpoolP256r1_T_6_X[] = {
+    2995                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3D, 0xAB, 0x5C, 0x8D, 0x1D, 0xF2, 0x2D, 0x1E),
+    2996                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x65, 0xC5, 0xF8, 0xF7, 0x1D, 0x96, 0x0B, 0x4D),
+    2997                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAC, 0x4C, 0xA7, 0x45, 0x20, 0x6A, 0x1E, 0x5B),
+    2998                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x21, 0x5D, 0xEF, 0xDE, 0xEE, 0x39, 0x44, 0x19),
+    2999                 :            : };
+    3000                 :            : static const mbedtls_mpi_uint brainpoolP256r1_T_6_Y[] = {
+    3001                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4B, 0x2F, 0x6D, 0x52, 0xC9, 0x58, 0x60, 0xE8),
+    3002                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC3, 0xC9, 0x62, 0xCB, 0x38, 0x3C, 0x55, 0xCA),
+    3003                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xA5, 0x09, 0x10, 0x88, 0xDB, 0xE3, 0xBD),
+    3004                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x52, 0xE0, 0x3C, 0xCE, 0x06, 0x0B, 0x4B, 0x5D),
+    3005                 :            : };
+    3006                 :            : static const mbedtls_mpi_uint brainpoolP256r1_T_7_X[] = {
+    3007                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB1, 0x1D, 0xB4, 0x10, 0x76, 0x8F, 0xBA, 0x09),
+    3008                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x57, 0x70, 0x5A, 0x07, 0xF5, 0x1A, 0x74, 0xC7),
+    3009                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0B, 0xE9, 0x94, 0xA8, 0xC0, 0xD5, 0x4A, 0x4A),
+    3010                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3E, 0x6D, 0xD4, 0xE8, 0x9B, 0xE9, 0x6D, 0x0E),
+    3011                 :            : };
+    3012                 :            : static const mbedtls_mpi_uint brainpoolP256r1_T_7_Y[] = {
+    3013                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x65, 0x00, 0x32, 0x41, 0x57, 0x84, 0x89, 0x52),
+    3014                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEE, 0xC7, 0x14, 0xEC, 0xE9, 0x27, 0xFF, 0xF3),
+    3015                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9A, 0x67, 0x9E, 0xFB, 0xB6, 0xB8, 0x96, 0xF3),
+    3016                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE5, 0x4A, 0xE3, 0x97, 0x4B, 0x58, 0xDE, 0x30),
+    3017                 :            : };
+    3018                 :            : static const mbedtls_mpi_uint brainpoolP256r1_T_8_X[] = {
+    3019                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA6, 0x1E, 0x5C, 0xF5, 0x7F, 0xD5, 0xD4, 0xAA),
+    3020                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5D, 0x08, 0x7A, 0xF1, 0xBD, 0x89, 0xC7, 0x1E),
+    3021                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3A, 0xF9, 0x11, 0x1B, 0xF5, 0x3C, 0x6D, 0x8C),
+    3022                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x19, 0x50, 0xE5, 0x69, 0x1D, 0x59, 0xFC, 0x0C),
+    3023                 :            : };
+    3024                 :            : static const mbedtls_mpi_uint brainpoolP256r1_T_8_Y[] = {
+    3025                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF1, 0x2F, 0xF8, 0x3F, 0xEC, 0x55, 0x99, 0x57),
+    3026                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x41, 0xA7, 0x29, 0x90, 0x43, 0x81, 0x31, 0x4C),
+    3027                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC3, 0x18, 0x44, 0x50, 0x5D, 0x76, 0xCB, 0xDD),
+    3028                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF0, 0xC5, 0x5B, 0x9A, 0x03, 0xE6, 0x17, 0x39),
+    3029                 :            : };
+    3030                 :            : static const mbedtls_mpi_uint brainpoolP256r1_T_9_X[] = {
+    3031                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x21, 0x89, 0xFC, 0x55, 0x94, 0x91, 0x6A, 0xA2),
+    3032                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x74, 0x46, 0x35, 0xF2, 0x3A, 0x42, 0x08, 0x2F),
+    3033                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD3, 0xD2, 0x76, 0x49, 0x42, 0x87, 0xD3, 0x7F),
+    3034                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x90, 0xEA, 0xA0, 0x52, 0xF1, 0x6A, 0x30, 0x57),
+    3035                 :            : };
+    3036                 :            : static const mbedtls_mpi_uint brainpoolP256r1_T_9_Y[] = {
+    3037                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x00, 0xB2, 0x57, 0xA3, 0x8A, 0x4D, 0x1B, 0x3C),
+    3038                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFC, 0xA3, 0x99, 0x94, 0xB5, 0x3D, 0x64, 0x09),
+    3039                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x35, 0xC3, 0xD7, 0x53, 0xF6, 0x49, 0x1C, 0x60),
+    3040                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x27, 0x23, 0x41, 0x4D, 0xFB, 0x7A, 0x5C, 0x53),
+    3041                 :            : };
+    3042                 :            : static const mbedtls_mpi_uint brainpoolP256r1_T_10_X[] = {
+    3043                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCA, 0xB8, 0x15, 0x65, 0x5C, 0x85, 0x94, 0xD7),
+    3044                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAC, 0x37, 0xC7, 0xF8, 0x7E, 0xAE, 0x6C, 0x10),
+    3045                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x53, 0xD8, 0x11, 0x54, 0x98, 0x44, 0xE3, 0xF1),
+    3046                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE4, 0x4D, 0xA6, 0x4B, 0x28, 0xF2, 0x57, 0x9E),
+    3047                 :            : };
+    3048                 :            : static const mbedtls_mpi_uint brainpoolP256r1_T_10_Y[] = {
+    3049                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF6, 0xD0, 0xEB, 0x1E, 0xAA, 0x30, 0xD3, 0x6A),
+    3050                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x58, 0x9B, 0x4D, 0xA7, 0x73, 0x6E, 0xB6, 0x45),
+    3051                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5D, 0x47, 0xF6, 0xED, 0x37, 0xEF, 0x71, 0x4D),
+    3052                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA8, 0xB5, 0x49, 0x61, 0x5E, 0x45, 0xF6, 0x4A),
+    3053                 :            : };
+    3054                 :            : static const mbedtls_mpi_uint brainpoolP256r1_T_11_X[] = {
+    3055                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEF, 0x0E, 0xB3, 0x84, 0x3A, 0x63, 0x72, 0x84),
+    3056                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6D, 0x53, 0x5C, 0xA7, 0xC6, 0x2E, 0xAB, 0x9E),
+    3057                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEB, 0x0F, 0x8F, 0x87, 0x50, 0x28, 0xB4, 0xAE),
+    3058                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5C, 0x98, 0x4A, 0x98, 0x31, 0x86, 0xCA, 0x51),
+    3059                 :            : };
+    3060                 :            : static const mbedtls_mpi_uint brainpoolP256r1_T_11_Y[] = {
+    3061                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBE, 0xC9, 0xE2, 0xFD, 0x5D, 0x1F, 0xE8, 0xC2),
+    3062                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD5, 0x90, 0x91, 0xC4, 0x84, 0xF0, 0xBA, 0xC5),
+    3063                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6C, 0x5A, 0xB3, 0x4E, 0xFB, 0xE0, 0x57, 0xE8),
+    3064                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6B, 0x0B, 0x90, 0xA6, 0xFD, 0x9D, 0x8E, 0x02),
+    3065                 :            : };
+    3066                 :            : static const mbedtls_mpi_uint brainpoolP256r1_T_12_X[] = {
+    3067                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF8, 0x41, 0x8F, 0x31, 0xFA, 0x5A, 0xF6, 0x33),
+    3068                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAC, 0xE9, 0xE3, 0xF6, 0xE0, 0x4A, 0xE7, 0xD2),
+    3069                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x84, 0x4E, 0xCD, 0xA2, 0x22, 0x14, 0xD4, 0x12),
+    3070                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7C, 0xED, 0x21, 0xB7, 0x0F, 0x53, 0x10, 0x17),
+    3071                 :            : };
+    3072                 :            : static const mbedtls_mpi_uint brainpoolP256r1_T_12_Y[] = {
+    3073                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x05, 0x06, 0x24, 0x2C, 0x4E, 0xD1, 0x1E, 0x9F),
+    3074                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD7, 0x3F, 0xC1, 0x9F, 0xAB, 0xF0, 0x37, 0x95),
+    3075                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x03, 0x5E, 0x12, 0xCE, 0x83, 0x1B, 0x2A, 0x18),
+    3076                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x61, 0x65, 0xCF, 0xE8, 0x5C, 0xA5, 0xA2, 0x70),
+    3077                 :            : };
+    3078                 :            : static const mbedtls_mpi_uint brainpoolP256r1_T_13_X[] = {
+    3079                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB8, 0x86, 0x76, 0x3A, 0x94, 0xF6, 0x1D, 0xC1),
+    3080                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1D, 0xDA, 0xC9, 0xA6, 0x29, 0x93, 0x15, 0x10),
+    3081                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6D, 0x61, 0x6A, 0x7D, 0xC7, 0xA9, 0xF3, 0x76),
+    3082                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4A, 0x03, 0x71, 0xA2, 0x15, 0xCE, 0x50, 0x72),
+    3083                 :            : };
+    3084                 :            : static const mbedtls_mpi_uint brainpoolP256r1_T_13_Y[] = {
+    3085                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB6, 0xD0, 0xA8, 0x1E, 0x91, 0xC4, 0x4F, 0x24),
+    3086                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2D, 0x4B, 0x7E, 0xD7, 0x71, 0x58, 0x7E, 0x1E),
+    3087                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x93, 0x45, 0xAF, 0x2A, 0x18, 0x93, 0x95, 0x3B),
+    3088                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1B, 0x8F, 0xC7, 0xFA, 0x4C, 0x7A, 0x86, 0x54),
+    3089                 :            : };
+    3090                 :            : static const mbedtls_mpi_uint brainpoolP256r1_T_14_X[] = {
+    3091                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x97, 0xAF, 0x68, 0x3A, 0x23, 0xC1, 0x2E, 0xBF),
+    3092                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x89, 0x50, 0x11, 0x67, 0x39, 0xB9, 0xAF, 0x48),
+    3093                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x19, 0x86, 0xAA, 0x1E, 0x88, 0x21, 0x29, 0x8B),
+    3094                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCD, 0x28, 0xA4, 0x9D, 0x89, 0xA9, 0x9A, 0x10),
+    3095                 :            : };
+    3096                 :            : static const mbedtls_mpi_uint brainpoolP256r1_T_14_Y[] = {
+    3097                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x91, 0xBA, 0x04, 0x67, 0xB7, 0x01, 0x40, 0x38),
+    3098                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x08, 0xE9, 0x09, 0xA3, 0xCA, 0xA6, 0x37, 0xF6),
+    3099                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6C, 0x97, 0xA8, 0xB6, 0x3C, 0xEE, 0x90, 0x3D),
+    3100                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDC, 0xED, 0xC4, 0xF7, 0xC3, 0x95, 0xEC, 0x85),
+    3101                 :            : };
+    3102                 :            : static const mbedtls_mpi_uint brainpoolP256r1_T_15_X[] = {
+    3103                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF5, 0x84, 0xBD, 0xEB, 0xD5, 0x64, 0xBB, 0x9D),
+    3104                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDB, 0x9B, 0xE2, 0x28, 0x50, 0xC2, 0x72, 0x40),
+    3105                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x39, 0xF2, 0x74, 0xD1, 0x26, 0xBF, 0x32, 0x68),
+    3106                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x36, 0xCB, 0xAF, 0x72, 0xDB, 0x6D, 0x30, 0x98),
+    3107                 :            : };
+    3108                 :            : static const mbedtls_mpi_uint brainpoolP256r1_T_15_Y[] = {
+    3109                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB3, 0x50, 0x85, 0xF4, 0x2B, 0x48, 0xC1, 0xAD),
+    3110                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC0, 0x28, 0xBB, 0x11, 0xBA, 0x5B, 0x22, 0x6C),
+    3111                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAD, 0xA1, 0xE5, 0x5C, 0xC9, 0x1D, 0x44, 0x45),
+    3112                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD4, 0xE8, 0xE6, 0x6F, 0xBB, 0xC1, 0x81, 0x7F),
+    3113                 :            : };
+    3114                 :            : static const mbedtls_ecp_point brainpoolP256r1_T[16] = {
+    3115                 :            :     ECP_POINT_INIT_XY_Z1(brainpoolP256r1_T_0_X, brainpoolP256r1_T_0_Y),
+    3116                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP256r1_T_1_X, brainpoolP256r1_T_1_Y),
+    3117                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP256r1_T_2_X, brainpoolP256r1_T_2_Y),
+    3118                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP256r1_T_3_X, brainpoolP256r1_T_3_Y),
+    3119                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP256r1_T_4_X, brainpoolP256r1_T_4_Y),
+    3120                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP256r1_T_5_X, brainpoolP256r1_T_5_Y),
+    3121                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP256r1_T_6_X, brainpoolP256r1_T_6_Y),
+    3122                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP256r1_T_7_X, brainpoolP256r1_T_7_Y),
+    3123                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP256r1_T_8_X, brainpoolP256r1_T_8_Y),
+    3124                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP256r1_T_9_X, brainpoolP256r1_T_9_Y),
+    3125                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP256r1_T_10_X, brainpoolP256r1_T_10_Y),
+    3126                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP256r1_T_11_X, brainpoolP256r1_T_11_Y),
+    3127                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP256r1_T_12_X, brainpoolP256r1_T_12_Y),
+    3128                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP256r1_T_13_X, brainpoolP256r1_T_13_Y),
+    3129                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP256r1_T_14_X, brainpoolP256r1_T_14_Y),
+    3130                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP256r1_T_15_X, brainpoolP256r1_T_15_Y),
+    3131                 :            : };
+    3132                 :            : #else
+    3133                 :            : #define brainpoolP256r1_T NULL
+    3134                 :            : #endif
+    3135                 :            : 
+    3136                 :            : #endif /* MBEDTLS_ECP_DP_BP256R1_ENABLED */
+    3137                 :            : 
+    3138                 :            : /*
+    3139                 :            :  * Domain parameters for brainpoolP384r1 (RFC 5639 3.6)
+    3140                 :            :  */
+    3141                 :            : #if defined(MBEDTLS_ECP_DP_BP384R1_ENABLED)
+    3142                 :            : static const mbedtls_mpi_uint brainpoolP384r1_p[] = {
+    3143                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x53, 0xEC, 0x07, 0x31, 0x13, 0x00, 0x47, 0x87),
+    3144                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x71, 0x1A, 0x1D, 0x90, 0x29, 0xA7, 0xD3, 0xAC),
+    3145                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x23, 0x11, 0xB7, 0x7F, 0x19, 0xDA, 0xB1, 0x12),
+    3146                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB4, 0x56, 0x54, 0xED, 0x09, 0x71, 0x2F, 0x15),
+    3147                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDF, 0x41, 0xE6, 0x50, 0x7E, 0x6F, 0x5D, 0x0F),
+    3148                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x28, 0x6D, 0x38, 0xA3, 0x82, 0x1E, 0xB9, 0x8C),
+    3149                 :            : };
+    3150                 :            : static const mbedtls_mpi_uint brainpoolP384r1_a[] = {
+    3151                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x26, 0x28, 0xCE, 0x22, 0xDD, 0xC7, 0xA8, 0x04),
+    3152                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEB, 0xD4, 0x3A, 0x50, 0x4A, 0x81, 0xA5, 0x8A),
+    3153                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0F, 0xF9, 0x91, 0xBA, 0xEF, 0x65, 0x91, 0x13),
+    3154                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x87, 0x27, 0xB2, 0x4F, 0x8E, 0xA2, 0xBE, 0xC2),
+    3155                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA0, 0xAF, 0x05, 0xCE, 0x0A, 0x08, 0x72, 0x3C),
+    3156                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0C, 0x15, 0x8C, 0x3D, 0xC6, 0x82, 0xC3, 0x7B),
+    3157                 :            : };
+    3158                 :            : static const mbedtls_mpi_uint brainpoolP384r1_b[] = {
+    3159                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x11, 0x4C, 0x50, 0xFA, 0x96, 0x86, 0xB7, 0x3A),
+    3160                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x94, 0xC9, 0xDB, 0x95, 0x02, 0x39, 0xB4, 0x7C),
+    3161                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD5, 0x62, 0xEB, 0x3E, 0xA5, 0x0E, 0x88, 0x2E),
+    3162                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA6, 0xD2, 0xDC, 0x07, 0xE1, 0x7D, 0xB7, 0x2F),
+    3163                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7C, 0x44, 0xF0, 0x16, 0x54, 0xB5, 0x39, 0x8B),
+    3164                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x26, 0x28, 0xCE, 0x22, 0xDD, 0xC7, 0xA8, 0x04),
+    3165                 :            : };
+    3166                 :            : static const mbedtls_mpi_uint brainpoolP384r1_gx[] = {
+    3167                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1E, 0xAF, 0xD4, 0x47, 0xE2, 0xB2, 0x87, 0xEF),
+    3168                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAA, 0x46, 0xD6, 0x36, 0x34, 0xE0, 0x26, 0xE8),
+    3169                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE8, 0x10, 0xBD, 0x0C, 0xFE, 0xCA, 0x7F, 0xDB),
+    3170                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE3, 0x4F, 0xF1, 0x7E, 0xE7, 0xA3, 0x47, 0x88),
+    3171                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6B, 0x3F, 0xC1, 0xB7, 0x81, 0x3A, 0xA6, 0xA2),
+    3172                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0x45, 0xCF, 0x68, 0xF0, 0x64, 0x1C, 0x1D),
+    3173                 :            : };
+    3174                 :            : static const mbedtls_mpi_uint brainpoolP384r1_gy[] = {
+    3175                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x15, 0x53, 0x3C, 0x26, 0x41, 0x03, 0x82, 0x42),
+    3176                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x11, 0x81, 0x91, 0x77, 0x21, 0x46, 0x46, 0x0E),
+    3177                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x28, 0x29, 0x91, 0xF9, 0x4F, 0x05, 0x9C, 0xE1),
+    3178                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x64, 0x58, 0xEC, 0xFE, 0x29, 0x0B, 0xB7, 0x62),
+    3179                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x52, 0xD5, 0xCF, 0x95, 0x8E, 0xEB, 0xB1, 0x5C),
+    3180                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA4, 0xC2, 0xF9, 0x20, 0x75, 0x1D, 0xBE, 0x8A),
+    3181                 :            : };
+    3182                 :            : static const mbedtls_mpi_uint brainpoolP384r1_n[] = {
+    3183                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x65, 0x65, 0x04, 0xE9, 0x02, 0x32, 0x88, 0x3B),
+    3184                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x10, 0xC3, 0x7F, 0x6B, 0xAF, 0xB6, 0x3A, 0xCF),
+    3185                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA7, 0x25, 0x04, 0xAC, 0x6C, 0x6E, 0x16, 0x1F),
+    3186                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB3, 0x56, 0x54, 0xED, 0x09, 0x71, 0x2F, 0x15),
+    3187                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDF, 0x41, 0xE6, 0x50, 0x7E, 0x6F, 0x5D, 0x0F),
+    3188                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x28, 0x6D, 0x38, 0xA3, 0x82, 0x1E, 0xB9, 0x8C),
+    3189                 :            : };
+    3190                 :            : 
+    3191                 :            : #if MBEDTLS_ECP_FIXED_POINT_OPTIM == 1
+    3192                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_0_X[] = {
+    3193                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1E, 0xAF, 0xD4, 0x47, 0xE2, 0xB2, 0x87, 0xEF),
+    3194                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAA, 0x46, 0xD6, 0x36, 0x34, 0xE0, 0x26, 0xE8),
+    3195                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE8, 0x10, 0xBD, 0x0C, 0xFE, 0xCA, 0x7F, 0xDB),
+    3196                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE3, 0x4F, 0xF1, 0x7E, 0xE7, 0xA3, 0x47, 0x88),
+    3197                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6B, 0x3F, 0xC1, 0xB7, 0x81, 0x3A, 0xA6, 0xA2),
+    3198                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0x45, 0xCF, 0x68, 0xF0, 0x64, 0x1C, 0x1D),
+    3199                 :            : };
+    3200                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_0_Y[] = {
+    3201                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x15, 0x53, 0x3C, 0x26, 0x41, 0x03, 0x82, 0x42),
+    3202                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x11, 0x81, 0x91, 0x77, 0x21, 0x46, 0x46, 0x0E),
+    3203                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x28, 0x29, 0x91, 0xF9, 0x4F, 0x05, 0x9C, 0xE1),
+    3204                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x64, 0x58, 0xEC, 0xFE, 0x29, 0x0B, 0xB7, 0x62),
+    3205                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x52, 0xD5, 0xCF, 0x95, 0x8E, 0xEB, 0xB1, 0x5C),
+    3206                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA4, 0xC2, 0xF9, 0x20, 0x75, 0x1D, 0xBE, 0x8A),
+    3207                 :            : };
+    3208                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_1_X[] = {
+    3209                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x93, 0xD8, 0x8A, 0x54, 0x41, 0xD6, 0x6B, 0x1D),
+    3210                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE2, 0x3B, 0xF1, 0x22, 0xFD, 0x2D, 0x4B, 0x03),
+    3211                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x01, 0x55, 0xE3, 0x33, 0xF0, 0x73, 0x52, 0x5A),
+    3212                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC1, 0x3F, 0x30, 0x26, 0xCA, 0x7F, 0x52, 0xA3),
+    3213                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD3, 0x6E, 0x17, 0x9B, 0xD5, 0x2A, 0x4A, 0x31),
+    3214                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x86, 0xDA, 0x6B, 0xE5, 0x03, 0x07, 0x1D, 0x2E),
+    3215                 :            : };
+    3216                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_1_Y[] = {
+    3217                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x51, 0x7A, 0xAF, 0x98, 0xE3, 0xA4, 0xF6, 0x19),
+    3218                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEC, 0x7D, 0xFE, 0x51, 0x40, 0x3B, 0x47, 0xD2),
+    3219                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFC, 0x88, 0xEC, 0xC4, 0xE2, 0x8F, 0xCB, 0xA4),
+    3220                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x30, 0xE2, 0x88, 0x2D, 0x4E, 0x50, 0xEB, 0x9A),
+    3221                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x13, 0x54, 0x94, 0x5E, 0xF4, 0x7F, 0x3A, 0x04),
+    3222                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCD, 0x07, 0x1C, 0xE1, 0xBD, 0x0F, 0xF8, 0x63),
+    3223                 :            : };
+    3224                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_2_X[] = {
+    3225                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x94, 0x92, 0x28, 0x2E, 0x32, 0x04, 0xB1, 0x4D),
+    3226                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x25, 0x82, 0x44, 0x43, 0x76, 0x0D, 0x55, 0xBF),
+    3227                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5B, 0xE3, 0xFF, 0x89, 0x46, 0xDE, 0x4E, 0xFE),
+    3228                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5B, 0x22, 0xBB, 0x67, 0x1A, 0x81, 0xEE, 0x27),
+    3229                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC8, 0x54, 0xE2, 0x7A, 0xAE, 0xDA, 0x2C, 0xD0),
+    3230                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x74, 0x9A, 0x90, 0xAA, 0x6E, 0x8B, 0xCC, 0x5F),
+    3231                 :            : };
+    3232                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_2_Y[] = {
+    3233                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x16, 0x40, 0xAC, 0xED, 0x7D, 0x37, 0x87, 0xAC),
+    3234                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x98, 0xF8, 0xB1, 0x80, 0x4C, 0x8C, 0x04, 0x42),
+    3235                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC2, 0x98, 0x2C, 0xAD, 0x30, 0x69, 0x35, 0xC0),
+    3236                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x32, 0x2E, 0x00, 0x2F, 0x44, 0x8C, 0xF0, 0xC0),
+    3237                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x16, 0x58, 0x07, 0xD7, 0xCD, 0x60, 0xA1, 0x5B),
+    3238                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAF, 0xFB, 0x7B, 0x03, 0x05, 0x5E, 0x79, 0x73),
+    3239                 :            : };
+    3240                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_3_X[] = {
+    3241                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC8, 0x17, 0xCE, 0x38, 0x4B, 0x5E, 0x5B, 0xC8),
+    3242                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x60, 0x0E, 0x0A, 0x61, 0x9D, 0x7C, 0x62, 0x08),
+    3243                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x25, 0xF0, 0x98, 0x71, 0x7F, 0x17, 0x26, 0xD7),
+    3244                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x83, 0xD3, 0xFA, 0x3C, 0xF0, 0x70, 0x07, 0x82),
+    3245                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x29, 0x47, 0x5C, 0x09, 0x43, 0xB7, 0x65, 0x15),
+    3246                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0E, 0xA9, 0xA7, 0x3E, 0xFA, 0xF3, 0xEC, 0x22),
+    3247                 :            : };
+    3248                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_3_Y[] = {
+    3249                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDA, 0x78, 0x22, 0x2B, 0x58, 0x71, 0xFA, 0xAA),
+    3250                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x00, 0x30, 0xCE, 0x6A, 0xB3, 0xB0, 0x4F, 0x83),
+    3251                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCF, 0x95, 0x20, 0xA9, 0x23, 0xC2, 0x65, 0xE7),
+    3252                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x55, 0xCF, 0x03, 0x5B, 0x8A, 0x80, 0x44, 0xBB),
+    3253                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5C, 0xF8, 0x91, 0xF7, 0xD5, 0xED, 0xEA, 0x81),
+    3254                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x40, 0x5B, 0x16, 0x10, 0x25, 0xAC, 0x2A, 0x17),
+    3255                 :            : };
+    3256                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_4_X[] = {
+    3257                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF2, 0xEC, 0xDC, 0xC4, 0x7B, 0x8C, 0x6B, 0xE9),
+    3258                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2B, 0xBB, 0x1C, 0xD3, 0x5A, 0xEE, 0xD9, 0x97),
+    3259                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x64, 0x5D, 0x30, 0x5E, 0xF7, 0xB2, 0x41, 0x9D),
+    3260                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xED, 0xCE, 0x0F, 0x1A, 0xC6, 0x41, 0x64, 0x62),
+    3261                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF2, 0x18, 0xE1, 0xE3, 0x82, 0x15, 0x66, 0x4B),
+    3262                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9B, 0xE2, 0x24, 0x04, 0x72, 0x39, 0xA0, 0x7C),
+    3263                 :            : };
+    3264                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_4_Y[] = {
+    3265                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2B, 0x51, 0xA2, 0x58, 0x88, 0x62, 0xE1, 0x02),
+    3266                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x58, 0xD2, 0x65, 0x14, 0xE9, 0x4C, 0x82, 0x30),
+    3267                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDC, 0xE1, 0xAC, 0x87, 0xAE, 0x31, 0x1A, 0x7A),
+    3268                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x85, 0x4F, 0x96, 0x1E, 0x85, 0x7A, 0xC3, 0x2B),
+    3269                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF0, 0x86, 0xBB, 0xF0, 0xC0, 0x9D, 0x08, 0x7B),
+    3270                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBD, 0x53, 0x03, 0x09, 0x80, 0x91, 0xEF, 0x68),
+    3271                 :            : };
+    3272                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_5_X[] = {
+    3273                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2D, 0xD7, 0xAF, 0x6F, 0x69, 0x7B, 0x88, 0xA1),
+    3274                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAF, 0x13, 0xE4, 0x30, 0xA2, 0x47, 0xB5, 0xC1),
+    3275                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0F, 0xD2, 0xC0, 0xDD, 0x8A, 0x1C, 0x3C, 0xF2),
+    3276                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF9, 0x8C, 0xB3, 0x4C, 0xBA, 0x8B, 0x6D, 0xCF),
+    3277                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6B, 0xC7, 0xA1, 0xA8, 0x6E, 0x3C, 0x4F, 0xF1),
+    3278                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x94, 0x4A, 0x97, 0xC8, 0x03, 0x6F, 0x01, 0x82),
+    3279                 :            : };
+    3280                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_5_Y[] = {
+    3281                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x74, 0x18, 0x12, 0xA9, 0x39, 0xD5, 0x22, 0x26),
+    3282                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x47, 0xA7, 0xC0, 0xBD, 0x9D, 0x8D, 0x78, 0x38),
+    3283                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA9, 0xB3, 0xD0, 0x7F, 0xDF, 0xD0, 0x30, 0xDE),
+    3284                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x37, 0x25, 0x73, 0x96, 0xEC, 0xA8, 0x1D, 0x7C),
+    3285                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x91, 0xD1, 0x65, 0x66, 0xDC, 0xD9, 0xCF, 0xDF),
+    3286                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x95, 0xED, 0x7B, 0x37, 0xAD, 0xE2, 0xBE, 0x2D),
+    3287                 :            : };
+    3288                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_6_X[] = {
+    3289                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x50, 0x79, 0x42, 0x6A, 0x07, 0x66, 0xB1, 0xBD),
+    3290                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x45, 0x53, 0x62, 0x65, 0x92, 0x09, 0x4C, 0xA1),
+    3291                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x06, 0xAF, 0xC3, 0x03, 0xF6, 0xF4, 0x2D, 0x9B),
+    3292                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE8, 0xCA, 0x41, 0xD9, 0xA2, 0x69, 0x9B, 0xC9),
+    3293                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4B, 0xB2, 0xA6, 0x8D, 0xE1, 0xAA, 0x61, 0x76),
+    3294                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x11, 0xBA, 0x4D, 0x12, 0xB6, 0xBE, 0xF3, 0x7E),
+    3295                 :            : };
+    3296                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_6_Y[] = {
+    3297                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCA, 0xD9, 0x92, 0x22, 0x07, 0xCE, 0xC9, 0x26),
+    3298                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x62, 0xA1, 0x7C, 0x91, 0xDB, 0x32, 0xF7, 0xE5),
+    3299                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6D, 0x49, 0x4B, 0x6D, 0xFB, 0xD9, 0x70, 0x3B),
+    3300                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1C, 0xFB, 0x4E, 0x4C, 0x5E, 0x66, 0x81, 0x1D),
+    3301                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA5, 0xB3, 0xE1, 0x00, 0xB7, 0xD9, 0xCC, 0x58),
+    3302                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF3, 0x36, 0x8B, 0xC4, 0x39, 0x20, 0xFD, 0x30),
+    3303                 :            : };
+    3304                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_7_X[] = {
+    3305                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x94, 0x1F, 0x60, 0x03, 0xBB, 0xD7, 0x60, 0x57),
+    3306                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x72, 0x3C, 0x62, 0xDD, 0x71, 0x95, 0xE9, 0x61),
+    3307                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB0, 0x5B, 0x7A, 0x5F, 0x68, 0x81, 0xC5, 0x90),
+    3308                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1E, 0xAF, 0xB5, 0xB9, 0x98, 0x42, 0x28, 0xA5),
+    3309                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0C, 0x29, 0x8E, 0x11, 0x49, 0xB4, 0xD7, 0x20),
+    3310                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9B, 0x3E, 0xD2, 0x30, 0xA1, 0xBA, 0xCA, 0x03),
+    3311                 :            : };
+    3312                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_7_Y[] = {
+    3313                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x29, 0x37, 0x64, 0x44, 0x2F, 0x03, 0xE5, 0x41),
+    3314                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4A, 0x42, 0xBC, 0xFF, 0xA2, 0x1A, 0x5F, 0x06),
+    3315                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1D, 0x04, 0xAB, 0x04, 0xE0, 0x24, 0xAD, 0x2A),
+    3316                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3D, 0x45, 0x17, 0x67, 0x1F, 0x3E, 0x53, 0xF8),
+    3317                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xED, 0x0F, 0xB3, 0x1B, 0x57, 0x54, 0xC2, 0x03),
+    3318                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x59, 0xD3, 0xF8, 0xC4, 0x1B, 0x9B, 0xFA, 0x30),
+    3319                 :            : };
+    3320                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_8_X[] = {
+    3321                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x37, 0x90, 0xFD, 0xFB, 0xCA, 0x49, 0x38, 0x4E),
+    3322                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC3, 0xCF, 0xC6, 0xDD, 0xF0, 0xFF, 0x8C, 0x11),
+    3323                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD7, 0x69, 0x9D, 0xBD, 0x5F, 0x33, 0xE9, 0xB4),
+    3324                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x47, 0x19, 0x82, 0x3D, 0xAC, 0x1C, 0x40, 0x23),
+    3325                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x40, 0xC7, 0x02, 0x46, 0x14, 0x77, 0x00, 0xBE),
+    3326                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC9, 0x05, 0xF2, 0x77, 0x3A, 0x66, 0x5C, 0x39),
+    3327                 :            : };
+    3328                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_8_Y[] = {
+    3329                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1E, 0xE6, 0x17, 0xDE, 0xB2, 0xA1, 0xE5, 0xB8),
+    3330                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC7, 0x71, 0xEC, 0x9D, 0xD8, 0xF5, 0xD4, 0x66),
+    3331                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAA, 0xC6, 0x42, 0x5E, 0xE7, 0x18, 0xBA, 0xD0),
+    3332                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC5, 0x21, 0x68, 0x5A, 0x26, 0xFB, 0xD7, 0x17),
+    3333                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x26, 0x00, 0x5C, 0xBA, 0x8A, 0x34, 0xEC, 0x75),
+    3334                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC3, 0x9C, 0x3C, 0xAF, 0x53, 0xE8, 0x65, 0x35),
+    3335                 :            : };
+    3336                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_9_X[] = {
+    3337                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBE, 0xEF, 0x28, 0xDC, 0x67, 0x05, 0xC8, 0xDF),
+    3338                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0B, 0x78, 0xC3, 0x85, 0x49, 0xA0, 0xBC, 0x0F),
+    3339                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x10, 0x3E, 0x2D, 0xA0, 0xCF, 0xD4, 0x7A, 0xF5),
+    3340                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x36, 0x93, 0xFE, 0x60, 0xB3, 0x6E, 0x99, 0xE2),
+    3341                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x62, 0xAD, 0x04, 0xE7, 0x49, 0xAF, 0x5E, 0xE3),
+    3342                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x54, 0x7A, 0xED, 0xA6, 0x9E, 0x18, 0x09, 0x31),
+    3343                 :            : };
+    3344                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_9_Y[] = {
+    3345                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE8, 0x05, 0x94, 0x44, 0xDC, 0xB8, 0x85, 0x94),
+    3346                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x14, 0xB7, 0x37, 0xC2, 0x50, 0x75, 0x15, 0xDA),
+    3347                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD6, 0xC6, 0x0F, 0xB2, 0xA9, 0x91, 0x3E, 0xE8),
+    3348                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB9, 0x81, 0xAD, 0x25, 0xA1, 0x26, 0x73, 0x15),
+    3349                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFD, 0xF1, 0xD1, 0x61, 0x7C, 0x76, 0x8F, 0x13),
+    3350                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x06, 0xDB, 0x4A, 0xFF, 0x14, 0xA7, 0x48, 0x0B),
+    3351                 :            : };
+    3352                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_10_X[] = {
+    3353                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2A, 0x73, 0xC6, 0xC2, 0xCC, 0xF1, 0x57, 0x04),
+    3354                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB6, 0xED, 0x73, 0x27, 0x70, 0x82, 0xB6, 0x5E),
+    3355                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0B, 0xBA, 0xAC, 0x3A, 0xCF, 0xF4, 0xEA, 0xA6),
+    3356                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x99, 0xD6, 0xB1, 0x8F, 0x0E, 0x08, 0x2C, 0x5E),
+    3357                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x17, 0xE3, 0x8F, 0x2F, 0x0E, 0xA1, 0xF3, 0x07),
+    3358                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1A, 0xF5, 0x7C, 0x9B, 0x29, 0x0A, 0xF6, 0x28),
+    3359                 :            : };
+    3360                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_10_Y[] = {
+    3361                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBD, 0xEE, 0x17, 0x47, 0x34, 0x15, 0xA3, 0xAF),
+    3362                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFB, 0xBE, 0x88, 0x48, 0xE7, 0xA2, 0xBB, 0xDE),
+    3363                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC5, 0xAD, 0xDC, 0x65, 0x61, 0x37, 0x0F, 0xC1),
+    3364                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFA, 0x67, 0xAD, 0xA2, 0x3A, 0x1C, 0x91, 0x78),
+    3365                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x55, 0x07, 0x0C, 0x3A, 0x41, 0x6E, 0x13, 0x28),
+    3366                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x73, 0xBD, 0x7E, 0xED, 0xAA, 0x14, 0xDD, 0x61),
+    3367                 :            : };
+    3368                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_11_X[] = {
+    3369                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC3, 0xDC, 0x20, 0x01, 0x72, 0x11, 0x48, 0x55),
+    3370                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1E, 0xC4, 0x7B, 0xF8, 0x62, 0x3D, 0xF0, 0x9F),
+    3371                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE8, 0xC2, 0x3D, 0x2E, 0x52, 0xA3, 0x4A, 0x89),
+    3372                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCE, 0xE2, 0x53, 0x46, 0x5E, 0x21, 0xF8, 0xCE),
+    3373                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC2, 0xC7, 0x8F, 0xA9, 0x26, 0x42, 0x32, 0x3A),
+    3374                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFB, 0xA6, 0xA0, 0x8D, 0x4B, 0x9A, 0x19, 0x03),
+    3375                 :            : };
+    3376                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_11_Y[] = {
+    3377                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEA, 0xAB, 0x6D, 0x1E, 0xFB, 0xEE, 0x60, 0x0C),
+    3378                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB6, 0x56, 0x3C, 0xC5, 0x5D, 0x10, 0x79, 0x1C),
+    3379                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x25, 0xBC, 0x41, 0x9F, 0x71, 0xEF, 0x02, 0xF9),
+    3380                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA2, 0x36, 0xC4, 0xD0, 0x88, 0x9B, 0x32, 0xFC),
+    3381                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9C, 0xD4, 0x5D, 0x17, 0x39, 0xE6, 0x22, 0x2C),
+    3382                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7B, 0x26, 0x01, 0xCE, 0xBE, 0x4A, 0x9C, 0x27),
+    3383                 :            : };
+    3384                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_12_X[] = {
+    3385                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEF, 0x6D, 0x11, 0xCA, 0x6C, 0x5A, 0x93, 0x0C),
+    3386                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEB, 0x96, 0x26, 0xAF, 0x2F, 0xE4, 0x30, 0x98),
+    3387                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x35, 0xC1, 0x4C, 0xC6, 0x30, 0x1F, 0x5C, 0x04),
+    3388                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x59, 0xB3, 0xE8, 0xFC, 0x35, 0xEB, 0x63, 0x6C),
+    3389                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9C, 0x1D, 0xCA, 0xFC, 0x50, 0x36, 0x4B, 0x96),
+    3390                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE4, 0x0E, 0x23, 0x5B, 0xAF, 0xEB, 0x2D, 0x31),
+    3391                 :            : };
+    3392                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_12_Y[] = {
+    3393                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC6, 0x88, 0xB6, 0xD7, 0x74, 0x4A, 0x23, 0xB6),
+    3394                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEF, 0x66, 0xE2, 0xBB, 0x29, 0xA6, 0x4F, 0x55),
+    3395                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE9, 0x6F, 0x7E, 0x68, 0x6E, 0xA0, 0x14, 0x94),
+    3396                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3B, 0x73, 0xD4, 0xE8, 0xAB, 0x5B, 0xF6, 0x0D),
+    3397                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x46, 0xE0, 0x3C, 0x24, 0x00, 0x95, 0xE9, 0xAD),
+    3398                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x37, 0x0D, 0x4F, 0x81, 0xD0, 0xF2, 0x3F, 0x00),
+    3399                 :            : };
+    3400                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_13_X[] = {
+    3401                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x99, 0x1D, 0xCD, 0x78, 0x39, 0xC4, 0x6B, 0xD9),
+    3402                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x81, 0x45, 0xC7, 0xB8, 0x2F, 0xAA, 0x5D, 0xE3),
+    3403                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x33, 0x8C, 0x6E, 0xA3, 0x24, 0xB2, 0xDB, 0x4B),
+    3404                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x69, 0x2D, 0xD9, 0xF1, 0xC7, 0x9B, 0x8A, 0xAF),
+    3405                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x67, 0xE1, 0x2C, 0xB9, 0x40, 0x37, 0x91, 0x75),
+    3406                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x81, 0x2C, 0xB5, 0x23, 0x03, 0x2B, 0xAF, 0x2F),
+    3407                 :            : };
+    3408                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_13_Y[] = {
+    3409                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2F, 0x9D, 0x5A, 0x20, 0x10, 0xA9, 0x84, 0xDA),
+    3410                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x61, 0x30, 0x89, 0x20, 0x13, 0xE9, 0xB2, 0xCA),
+    3411                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB6, 0x6E, 0x52, 0xEB, 0x03, 0x18, 0x1F, 0xA6),
+    3412                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6C, 0x9E, 0x1C, 0x35, 0x87, 0x92, 0x69, 0xC7),
+    3413                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA1, 0xC9, 0x88, 0xAF, 0xC6, 0x6C, 0x83, 0x72),
+    3414                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCB, 0xD5, 0x7A, 0x54, 0x34, 0x99, 0xB6, 0x6F),
+    3415                 :            : };
+    3416                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_14_X[] = {
+    3417                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDF, 0xAD, 0x45, 0x9B, 0x4B, 0x41, 0x4D, 0x50),
+    3418                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1B, 0x5D, 0xAB, 0x7F, 0x35, 0x34, 0xE9, 0x29),
+    3419                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x73, 0xBE, 0x78, 0x34, 0x44, 0xF3, 0x4A, 0x87),
+    3420                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFB, 0xDE, 0xE3, 0xC4, 0xEE, 0x0B, 0xF9, 0xEB),
+    3421                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5E, 0x86, 0x16, 0x48, 0x32, 0xB8, 0x74, 0x41),
+    3422                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF2, 0xEE, 0x7C, 0xBA, 0xBD, 0x81, 0xE3, 0x55),
+    3423                 :            : };
+    3424                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_14_Y[] = {
+    3425                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF8, 0x6A, 0xFA, 0x84, 0xDA, 0xB8, 0xD5, 0x14),
+    3426                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB2, 0x9F, 0x8A, 0xD5, 0x1B, 0x2E, 0x1A, 0x0B),
+    3427                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5F, 0x0C, 0x61, 0xE2, 0xFF, 0x5B, 0xE6, 0xD5),
+    3428                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0E, 0x62, 0xC1, 0x87, 0x53, 0x1B, 0x92, 0xA3),
+    3429                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x54, 0x90, 0x00, 0xD1, 0x6A, 0x0C, 0x0E, 0x28),
+    3430                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8B, 0x2E, 0xB5, 0x3B, 0x44, 0xB5, 0xA0, 0x78),
+    3431                 :            : };
+    3432                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_15_X[] = {
+    3433                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB8, 0x5D, 0x02, 0x58, 0xB5, 0xBE, 0x45, 0x14),
+    3434                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAD, 0xEF, 0x8E, 0x90, 0x4D, 0x2A, 0x32, 0xAC),
+    3435                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x48, 0x99, 0x75, 0x5C, 0x0A, 0x33, 0x8F, 0x36),
+    3436                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC8, 0x6C, 0x95, 0xD4, 0x1F, 0xF3, 0xEB, 0xDA),
+    3437                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC2, 0xE4, 0x4C, 0x91, 0x20, 0xF3, 0x25, 0xEB),
+    3438                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF1, 0x95, 0xEB, 0x29, 0x6F, 0x20, 0x34, 0x81),
+    3439                 :            : };
+    3440                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_15_Y[] = {
+    3441                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2D, 0x15, 0xE5, 0x13, 0x7E, 0x64, 0x8B, 0xAD),
+    3442                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA7, 0xBC, 0x0D, 0x18, 0x7E, 0x37, 0x9E, 0xFA),
+    3443                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE8, 0x82, 0x20, 0xF7, 0x2D, 0x7A, 0x77, 0x52),
+    3444                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCB, 0x29, 0xA2, 0xDB, 0x7A, 0xE6, 0x6F, 0xA5),
+    3445                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA0, 0xC6, 0x50, 0x5C, 0xBC, 0xE6, 0x4F, 0xBD),
+    3446                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1E, 0x9F, 0xD5, 0xE8, 0xC5, 0x3D, 0xB7, 0x30),
+    3447                 :            : };
+    3448                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_16_X[] = {
+    3449                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x45, 0x03, 0x55, 0x10, 0xDB, 0xA6, 0x8B, 0x22),
+    3450                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4E, 0x17, 0xAE, 0x78, 0xC9, 0x1D, 0x43, 0xCA),
+    3451                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4E, 0x35, 0x49, 0xD4, 0x47, 0x84, 0x8D, 0x20),
+    3452                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF3, 0x95, 0x2F, 0xEA, 0xBC, 0xB4, 0x18, 0xB3),
+    3453                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD4, 0x48, 0xAE, 0x89, 0xF5, 0x65, 0x3D, 0x89),
+    3454                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x86, 0xF2, 0x2B, 0x20, 0xD1, 0x75, 0x50, 0x63),
+    3455                 :            : };
+    3456                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_16_Y[] = {
+    3457                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAD, 0xE6, 0x5C, 0x2C, 0xE0, 0x7D, 0xDF, 0x2D),
+    3458                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3E, 0x07, 0x3E, 0xCE, 0x9F, 0x18, 0xB6, 0x05),
+    3459                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9A, 0xF8, 0xF0, 0xD5, 0xFA, 0x42, 0x1D, 0x6D),
+    3460                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x41, 0x6C, 0x1D, 0x03, 0xC9, 0x0E, 0x2B, 0x2F),
+    3461                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x43, 0x18, 0x52, 0xA5, 0xB4, 0x63, 0xE1, 0x06),
+    3462                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB7, 0x0A, 0xD9, 0xC4, 0xFD, 0x16, 0x60, 0x54),
+    3463                 :            : };
+    3464                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_17_X[] = {
+    3465                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x43, 0x7D, 0xDE, 0xDF, 0x4B, 0x4A, 0xB0, 0xCB),
+    3466                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB0, 0x4E, 0x8C, 0x94, 0xC1, 0xE2, 0x85, 0xDF),
+    3467                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4F, 0xF0, 0xEA, 0xB5, 0x9B, 0x70, 0xEF, 0x10),
+    3468                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x56, 0xC2, 0x39, 0x5D, 0xF3, 0x2C, 0xD9, 0x2C),
+    3469                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0D, 0x1C, 0x2E, 0xCC, 0x2F, 0x54, 0x87, 0x80),
+    3470                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB0, 0x72, 0xC7, 0xB5, 0x50, 0xA3, 0x84, 0x77),
+    3471                 :            : };
+    3472                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_17_Y[] = {
+    3473                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB7, 0xD1, 0xAF, 0xA9, 0xB4, 0x8B, 0x5D, 0xFA),
+    3474                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC8, 0xF6, 0x52, 0x8A, 0xC3, 0x56, 0xA5, 0x5E),
+    3475                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3B, 0x52, 0xFF, 0xEA, 0x05, 0x42, 0x77, 0x83),
+    3476                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x29, 0x08, 0x90, 0x72, 0x86, 0xC4, 0xC3, 0xB8),
+    3477                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4D, 0x15, 0xF8, 0xF1, 0x16, 0x67, 0xC6, 0xD5),
+    3478                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x75, 0x87, 0xAC, 0x8F, 0x71, 0xEC, 0x83, 0x81),
+    3479                 :            : };
+    3480                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_18_X[] = {
+    3481                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x91, 0xE1, 0xE6, 0x2D, 0x0E, 0x11, 0xA1, 0x62),
+    3482                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x74, 0xE2, 0xA8, 0x32, 0xE6, 0xE3, 0x83, 0xD1),
+    3483                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x50, 0x56, 0xE5, 0xCD, 0xB7, 0x2B, 0x67, 0x6F),
+    3484                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE5, 0xED, 0xC9, 0x65, 0x6D, 0x87, 0xE1, 0x8E),
+    3485                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x50, 0x8E, 0xFD, 0x9A, 0x53, 0x0E, 0xFA, 0xA3),
+    3486                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x49, 0x4C, 0x4A, 0xE2, 0x23, 0x84, 0xFA, 0x01),
+    3487                 :            : };
+    3488                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_18_Y[] = {
+    3489                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB4, 0xFE, 0x49, 0x81, 0xD1, 0x3E, 0xF4, 0x7C),
+    3490                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x45, 0x72, 0xE0, 0xEF, 0x0D, 0xB8, 0x3E, 0x6F),
+    3491                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3C, 0x00, 0x0F, 0x5F, 0xCE, 0x60, 0x72, 0x2C),
+    3492                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB7, 0xCC, 0xD8, 0x03, 0x07, 0x6E, 0x5A, 0xCD),
+    3493                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x27, 0x3A, 0x35, 0x50, 0x4E, 0x1F, 0xCA, 0x5F),
+    3494                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x58, 0xEA, 0x88, 0x55, 0xBD, 0x6E, 0x05, 0x7F),
+    3495                 :            : };
+    3496                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_19_X[] = {
+    3497                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB1, 0x6D, 0xF1, 0x97, 0xA6, 0x69, 0x39, 0x24),
+    3498                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0B, 0x41, 0x99, 0xFF, 0x3B, 0xA1, 0x26, 0xEC),
+    3499                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x95, 0x2F, 0x95, 0x80, 0x12, 0x4A, 0x1B, 0xCB),
+    3500                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEA, 0xBF, 0x51, 0xAA, 0xAE, 0x2D, 0xDA, 0xCF),
+    3501                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0C, 0x1C, 0xB3, 0x52, 0x36, 0x49, 0xD4, 0x86),
+    3502                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x99, 0xC1, 0x1F, 0x3A, 0xD3, 0x3E, 0x5C, 0x1A),
+    3503                 :            : };
+    3504                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_19_Y[] = {
+    3505                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x73, 0x51, 0xF7, 0x2B, 0xC8, 0xA9, 0xA7, 0x15),
+    3506                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x12, 0x4E, 0x7F, 0x98, 0x41, 0x66, 0xB0, 0x03),
+    3507                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x91, 0x1D, 0xC0, 0x42, 0xCD, 0xF8, 0xC3, 0x2B),
+    3508                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCC, 0x41, 0x91, 0x7D, 0xCC, 0x8B, 0xCC, 0x41),
+    3509                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2A, 0xAE, 0x76, 0xED, 0x56, 0x18, 0xC5, 0xAB),
+    3510                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAB, 0x6A, 0x06, 0xA3, 0x7F, 0x65, 0x10, 0x1F),
+    3511                 :            : };
+    3512                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_20_X[] = {
+    3513                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0C, 0xEC, 0x3C, 0x05, 0x05, 0xCA, 0xF6, 0xED),
+    3514                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x48, 0xCD, 0x02, 0x51, 0x12, 0x16, 0x3C, 0x63),
+    3515                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA8, 0xEB, 0xB3, 0x43, 0x7B, 0xDD, 0xB2, 0x7C),
+    3516                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x00, 0x59, 0x90, 0x41, 0xDB, 0xE4, 0xF5, 0x91),
+    3517                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD0, 0x0E, 0x18, 0x2A, 0x5A, 0x83, 0x7C, 0x2F),
+    3518                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE1, 0x37, 0xA1, 0x0D, 0xF1, 0x2F, 0x63, 0x79),
+    3519                 :            : };
+    3520                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_20_Y[] = {
+    3521                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x21, 0xC0, 0xFA, 0x6F, 0x1F, 0x67, 0xCF, 0xEC),
+    3522                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x98, 0x34, 0x45, 0xBB, 0xF4, 0xF9, 0x9B, 0x89),
+    3523                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF5, 0x69, 0xFE, 0x67, 0x1D, 0x64, 0x8F, 0xB9),
+    3524                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDB, 0x39, 0xBF, 0xD8, 0xB3, 0xC7, 0xAD, 0x8A),
+    3525                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8C, 0x93, 0xFF, 0xF3, 0x28, 0xFA, 0x39, 0xF6),
+    3526                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFA, 0xF9, 0xC3, 0x85, 0x26, 0x7A, 0x88, 0x89),
+    3527                 :            : };
+    3528                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_21_X[] = {
+    3529                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4D, 0xD5, 0x79, 0xD8, 0x11, 0xDE, 0xEB, 0x4E),
+    3530                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1C, 0x46, 0xA4, 0x6A, 0xDA, 0x74, 0x34, 0xA8),
+    3531                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1E, 0xBD, 0xD3, 0xF5, 0x14, 0xEE, 0xFE, 0xAE),
+    3532                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x19, 0x4C, 0xA3, 0x71, 0x43, 0x65, 0xF8, 0x94),
+    3533                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x72, 0x6C, 0x35, 0xFA, 0x90, 0x25, 0xD8, 0xE2),
+    3534                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBB, 0x34, 0x84, 0x96, 0xA1, 0x43, 0x03, 0x4D),
+    3535                 :            : };
+    3536                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_21_Y[] = {
+    3537                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF1, 0x3B, 0x3B, 0x2F, 0xCA, 0x59, 0xF2, 0x42),
+    3538                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCD, 0x48, 0x24, 0x74, 0xD8, 0x72, 0x90, 0xA3),
+    3539                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x83, 0x42, 0x74, 0x8C, 0x6F, 0x52, 0x19, 0x3D),
+    3540                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x40, 0x9E, 0x41, 0x63, 0x68, 0x78, 0x4C, 0x2F),
+    3541                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x53, 0x94, 0xB6, 0x6B, 0x38, 0x52, 0xA8, 0x9F),
+    3542                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x81, 0x30, 0x25, 0x93, 0xA1, 0x6F, 0x6E, 0x68),
+    3543                 :            : };
+    3544                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_22_X[] = {
+    3545                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFC, 0x2F, 0x4B, 0x64, 0x79, 0x50, 0xFF, 0x01),
+    3546                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD4, 0x36, 0xED, 0x57, 0x39, 0x3B, 0xE7, 0xF3),
+    3547                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF1, 0x85, 0xEA, 0x35, 0xD6, 0xC0, 0xA0, 0x52),
+    3548                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBA, 0x89, 0x3A, 0xCC, 0x22, 0x1C, 0x46, 0x02),
+    3549                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6C, 0x7A, 0xB0, 0xA1, 0x1B, 0x69, 0x62, 0x55),
+    3550                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x57, 0xB8, 0x8A, 0x6C, 0x18, 0x85, 0x0D, 0x88),
+    3551                 :            : };
+    3552                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_22_Y[] = {
+    3553                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFD, 0xB6, 0x50, 0xE9, 0x4E, 0x7F, 0xE8, 0x07),
+    3554                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x92, 0x5B, 0x5C, 0xD1, 0x4B, 0x11, 0x9A, 0xD8),
+    3555                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x96, 0x25, 0x56, 0x74, 0x51, 0x9C, 0xEC, 0x9C),
+    3556                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x55, 0x7F, 0xB6, 0x8A, 0xCB, 0x3A, 0x10, 0x6A),
+    3557                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x60, 0x33, 0x07, 0x01, 0xE9, 0x49, 0x59, 0xE6),
+    3558                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC6, 0xA5, 0x2E, 0xF2, 0xBA, 0x32, 0x63, 0x44),
+    3559                 :            : };
+    3560                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_23_X[] = {
+    3561                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF8, 0x06, 0x0B, 0xA5, 0x44, 0x27, 0x7F, 0x22),
+    3562                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x30, 0x74, 0xAC, 0x0F, 0xCC, 0x4F, 0x13, 0x61),
+    3563                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFD, 0xB1, 0xBF, 0x97, 0x49, 0xA5, 0x1C, 0x1D),
+    3564                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8A, 0x64, 0x68, 0x7B, 0x0F, 0xCC, 0x77, 0xF8),
+    3565                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBB, 0x39, 0xF9, 0x4E, 0x84, 0x9C, 0xF6, 0x96),
+    3566                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBC, 0xCF, 0x6D, 0xE2, 0xA1, 0x2D, 0xF9, 0x2B),
+    3567                 :            : };
+    3568                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_23_Y[] = {
+    3569                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x95, 0xC4, 0x90, 0x57, 0x31, 0x01, 0x05, 0x5E),
+    3570                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCC, 0x1E, 0xBB, 0xBF, 0x98, 0xA4, 0x7C, 0xE3),
+    3571                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x89, 0xE3, 0xA0, 0xB2, 0xCD, 0x39, 0x9A, 0x3F),
+    3572                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x92, 0x34, 0x60, 0x7A, 0x89, 0x98, 0xB5, 0x52),
+    3573                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8D, 0x20, 0x3D, 0x3A, 0x04, 0x8F, 0x5A, 0xAC),
+    3574                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA3, 0x26, 0xB6, 0x49, 0x09, 0x9C, 0x0F, 0x59),
+    3575                 :            : };
+    3576                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_24_X[] = {
+    3577                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x72, 0x66, 0xD2, 0x38, 0x2A, 0x62, 0x81, 0xCA),
+    3578                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC5, 0xC8, 0x20, 0x5E, 0x28, 0xA3, 0x81, 0xA7),
+    3579                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x20, 0x31, 0xA4, 0xF1, 0xEA, 0x7D, 0x87, 0x45),
+    3580                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8F, 0x2C, 0x99, 0x09, 0x6F, 0x63, 0xEB, 0x2F),
+    3581                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x73, 0x76, 0xDA, 0x1A, 0x06, 0xBE, 0xDE, 0xA2),
+    3582                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x29, 0x09, 0x2E, 0x75, 0x39, 0x30, 0x2D, 0x42),
+    3583                 :            : };
+    3584                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_24_Y[] = {
+    3585                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x41, 0x9B, 0xC1, 0x5A, 0x17, 0xC3, 0x8C, 0x31),
+    3586                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x58, 0x8D, 0x94, 0x4D, 0x3D, 0xAB, 0x60, 0xD4),
+    3587                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xFD, 0x1E, 0x0F, 0x43, 0xAE, 0x9D, 0x62),
+    3588                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8E, 0xF2, 0xF3, 0x20, 0x1B, 0xAA, 0xB7, 0x41),
+    3589                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9D, 0x5B, 0xA4, 0xF4, 0x90, 0x3B, 0xE3, 0x71),
+    3590                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF7, 0x78, 0x72, 0xBD, 0x65, 0x09, 0x0B, 0x01),
+    3591                 :            : };
+    3592                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_25_X[] = {
+    3593                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCA, 0x37, 0x2A, 0x6C, 0x16, 0x4F, 0x64, 0x59),
+    3594                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5A, 0xCE, 0xA3, 0x90, 0xB4, 0x9A, 0xBC, 0xF7),
+    3595                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x27, 0x38, 0x55, 0x63, 0x1D, 0x3A, 0x6E, 0x18),
+    3596                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x37, 0xB4, 0xAA, 0x99, 0x22, 0x45, 0x89, 0x2C),
+    3597                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB7, 0x7C, 0x8C, 0xA6, 0x3D, 0xA7, 0x3E, 0xE8),
+    3598                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x70, 0x06, 0x42, 0xDC, 0xA6, 0xE3, 0xC6, 0x12),
+    3599                 :            : };
+    3600                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_25_Y[] = {
+    3601                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x55, 0x8C, 0x3D, 0x5D, 0x47, 0x31, 0x7C, 0xEB),
+    3602                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x46, 0x85, 0xEE, 0x46, 0x7E, 0x13, 0x04, 0x41),
+    3603                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9E, 0x3C, 0x8B, 0x43, 0x2E, 0x74, 0xF5, 0xF6),
+    3604                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBA, 0x88, 0x8E, 0x07, 0x29, 0x08, 0x03, 0x26),
+    3605                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEA, 0x9B, 0x89, 0xEB, 0x08, 0xE8, 0x43, 0xB5),
+    3606                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x17, 0x07, 0x67, 0xFD, 0xD9, 0x73, 0x6F, 0x18),
+    3607                 :            : };
+    3608                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_26_X[] = {
+    3609                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x29, 0xEB, 0x21, 0x8D, 0x98, 0x43, 0x74, 0x98),
+    3610                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x88, 0xCC, 0x14, 0xD8, 0x08, 0xBB, 0xA6, 0xE3),
+    3611                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC4, 0x98, 0xF2, 0x6A, 0x18, 0xC3, 0xDD, 0x9E),
+    3612                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC7, 0x38, 0x91, 0xA0, 0x03, 0xF2, 0x04, 0x62),
+    3613                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7A, 0xAF, 0xE8, 0xFD, 0xFB, 0x13, 0x70, 0x74),
+    3614                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD0, 0x93, 0x87, 0x98, 0x4A, 0xE0, 0x00, 0x12),
+    3615                 :            : };
+    3616                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_26_Y[] = {
+    3617                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x97, 0x2E, 0x69, 0x9C, 0xA2, 0x2D, 0x03, 0x3F),
+    3618                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x79, 0xFE, 0xF3, 0xB9, 0xC1, 0x85, 0x2A, 0xEE),
+    3619                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCE, 0xFD, 0x86, 0xB1, 0xCD, 0xBF, 0x41, 0xB7),
+    3620                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA0, 0xD8, 0x9A, 0x21, 0xF3, 0xFE, 0xCB, 0xF1),
+    3621                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x95, 0x78, 0x04, 0x60, 0xB7, 0xA9, 0xA2, 0x84),
+    3622                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE8, 0x1E, 0x66, 0x2A, 0x54, 0x51, 0xBD, 0x8B),
+    3623                 :            : };
+    3624                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_27_X[] = {
+    3625                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8E, 0x16, 0x36, 0xEF, 0x61, 0x2D, 0xEE, 0x3B),
+    3626                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x45, 0x5F, 0x88, 0xA0, 0x13, 0x12, 0xF7, 0x23),
+    3627                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA9, 0xC6, 0xAD, 0x4A, 0x4A, 0x07, 0x01, 0x5B),
+    3628                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB8, 0x74, 0xB1, 0x4F, 0xEB, 0xBD, 0xD5, 0x6B),
+    3629                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x57, 0xF9, 0x71, 0xA2, 0x06, 0x4F, 0xD7, 0xBC),
+    3630                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0x8B, 0x4D, 0x48, 0xE0, 0x98, 0xFB, 0x6A),
+    3631                 :            : };
+    3632                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_27_Y[] = {
+    3633                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC4, 0xBA, 0x10, 0xA3, 0x0D, 0x52, 0xAC, 0x3A),
+    3634                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x11, 0xD0, 0xE0, 0x36, 0xE6, 0x07, 0x3A, 0x30),
+    3635                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7E, 0x80, 0xF0, 0xAA, 0x49, 0x22, 0x4B, 0xDD),
+    3636                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xC7, 0xAB, 0x1C, 0x89, 0xCD, 0x24, 0x40),
+    3637                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x82, 0x2A, 0xFC, 0xB3, 0x6D, 0x45, 0x96, 0x49),
+    3638                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x63, 0xE4, 0xDB, 0x52, 0x3F, 0xC4, 0xB4, 0x19),
+    3639                 :            : };
+    3640                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_28_X[] = {
+    3641                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5B, 0xCC, 0xC8, 0x7F, 0xBB, 0x6B, 0x87, 0x47),
+    3642                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC0, 0x21, 0x3C, 0x69, 0x7D, 0x38, 0x57, 0x50),
+    3643                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x52, 0x4C, 0x18, 0x3C, 0x53, 0xA5, 0x48, 0x6D),
+    3644                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x21, 0xC3, 0x64, 0x45, 0xDB, 0xC4, 0x6D, 0x15),
+    3645                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x49, 0xCC, 0xD1, 0xBB, 0x17, 0xB8, 0x34, 0x2D),
+    3646                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6C, 0x69, 0x71, 0xFA, 0xA0, 0x28, 0x4A, 0x3D),
+    3647                 :            : };
+    3648                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_28_Y[] = {
+    3649                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xED, 0xE8, 0x9E, 0x39, 0xEA, 0x8D, 0x38, 0xDB),
+    3650                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCC, 0x9C, 0xBB, 0xCD, 0x80, 0x1A, 0xEE, 0xB7),
+    3651                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBC, 0xA0, 0x45, 0xBF, 0xD9, 0x22, 0x11, 0x32),
+    3652                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDA, 0x7C, 0x5C, 0xD9, 0xC0, 0x9F, 0x69, 0xF5),
+    3653                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBC, 0x8A, 0xA6, 0x79, 0x4E, 0x35, 0xB9, 0xD5),
+    3654                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCC, 0x8B, 0x9A, 0x3E, 0xA1, 0xB8, 0x28, 0x10),
+    3655                 :            : };
+    3656                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_29_X[] = {
+    3657                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x55, 0x2F, 0xEF, 0xBB, 0xA9, 0x72, 0x7F, 0xEA),
+    3658                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB5, 0x34, 0xB7, 0x12, 0xB9, 0xE7, 0xC3, 0x2A),
+    3659                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF8, 0x1D, 0xD9, 0x42, 0x77, 0x0C, 0x71, 0x6E),
+    3660                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEC, 0x01, 0x59, 0xA7, 0x56, 0x03, 0x91, 0x8D),
+    3661                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6C, 0x91, 0x99, 0x33, 0x30, 0x3E, 0xEF, 0x13),
+    3662                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x87, 0xC9, 0x5A, 0x9A, 0x54, 0x66, 0xF1, 0x70),
+    3663                 :            : };
+    3664                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_29_Y[] = {
+    3665                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x64, 0x2C, 0xB7, 0x6E, 0x71, 0x7D, 0x35, 0x30),
+    3666                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1A, 0x0D, 0xEF, 0xD1, 0x2D, 0x99, 0x63, 0x2F),
+    3667                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE4, 0x31, 0xAF, 0x2D, 0xC9, 0xC6, 0xC2, 0xAE),
+    3668                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x19, 0xC0, 0xDF, 0x80, 0x54, 0xC4, 0xAC, 0xF3),
+    3669                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE3, 0x6B, 0xA0, 0x84, 0x96, 0xF7, 0x31, 0xC8),
+    3670                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x93, 0xE2, 0x7C, 0x7A, 0x41, 0x45, 0x75, 0x6A),
+    3671                 :            : };
+    3672                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_30_X[] = {
+    3673                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAE, 0xEE, 0x58, 0x31, 0xE8, 0x68, 0xD6, 0x76),
+    3674                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD2, 0x2E, 0x48, 0xB7, 0x09, 0x9F, 0xD4, 0xCA),
+    3675                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x34, 0xA9, 0x5C, 0xE7, 0x64, 0x43, 0x5D, 0xC9),
+    3676                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9E, 0x58, 0x9F, 0x50, 0xAB, 0x68, 0xFF, 0x6D),
+    3677                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x87, 0x88, 0x2D, 0xBA, 0x12, 0xBF, 0x8D, 0x7D),
+    3678                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD4, 0xDF, 0x6F, 0xB3, 0x75, 0xA4, 0x55, 0x73),
+    3679                 :            : };
+    3680                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_30_Y[] = {
+    3681                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6D, 0x17, 0x92, 0x39, 0xB7, 0x13, 0x37, 0x6F),
+    3682                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5E, 0x43, 0x71, 0xA7, 0xCA, 0x17, 0x1B, 0x32),
+    3683                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE7, 0xB9, 0xB0, 0x78, 0xEF, 0xA0, 0xDA, 0x83),
+    3684                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9A, 0x84, 0xF2, 0x0F, 0x85, 0xA2, 0xB6, 0x1F),
+    3685                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x72, 0x65, 0x2E, 0x6E, 0x45, 0xB9, 0x4C, 0x3C),
+    3686                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFE, 0x6A, 0x8C, 0x2B, 0x77, 0x96, 0x36, 0x22),
+    3687                 :            : };
+    3688                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_31_X[] = {
+    3689                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x68, 0x7A, 0x13, 0x4A, 0x97, 0x63, 0x02, 0x10),
+    3690                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBC, 0x1E, 0x06, 0x03, 0x8F, 0xB9, 0xEE, 0x64),
+    3691                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x68, 0xEE, 0x8B, 0x89, 0xA9, 0x70, 0xDB, 0xCE),
+    3692                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x15, 0x7B, 0x81, 0xC9, 0x70, 0x8D, 0x62, 0x32),
+    3693                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x75, 0xDA, 0x46, 0xF8, 0xF9, 0x3A, 0xBE, 0x55),
+    3694                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9F, 0x9C, 0x7A, 0x97, 0x62, 0xEB, 0xFA, 0x0F),
+    3695                 :            : };
+    3696                 :            : static const mbedtls_mpi_uint brainpoolP384r1_T_31_Y[] = {
+    3697                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB2, 0x03, 0x3D, 0x3C, 0x46, 0x27, 0x9E, 0x65),
+    3698                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA4, 0x08, 0x1C, 0xD5, 0x25, 0xAF, 0xE9, 0x40),
+    3699                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFE, 0x69, 0xDC, 0x59, 0xF4, 0x8A, 0x7C, 0x1F),
+    3700                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFC, 0x9A, 0x7A, 0x99, 0x21, 0x0C, 0x4E, 0xE3),
+    3701                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF5, 0xCE, 0x85, 0x5F, 0xAC, 0xAA, 0x82, 0x10),
+    3702                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x83, 0x57, 0x69, 0x90, 0x76, 0xF3, 0x53, 0x3F),
+    3703                 :            : };
+    3704                 :            : static const mbedtls_ecp_point brainpoolP384r1_T[32] = {
+    3705                 :            :     ECP_POINT_INIT_XY_Z1(brainpoolP384r1_T_0_X, brainpoolP384r1_T_0_Y),
+    3706                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP384r1_T_1_X, brainpoolP384r1_T_1_Y),
+    3707                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP384r1_T_2_X, brainpoolP384r1_T_2_Y),
+    3708                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP384r1_T_3_X, brainpoolP384r1_T_3_Y),
+    3709                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP384r1_T_4_X, brainpoolP384r1_T_4_Y),
+    3710                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP384r1_T_5_X, brainpoolP384r1_T_5_Y),
+    3711                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP384r1_T_6_X, brainpoolP384r1_T_6_Y),
+    3712                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP384r1_T_7_X, brainpoolP384r1_T_7_Y),
+    3713                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP384r1_T_8_X, brainpoolP384r1_T_8_Y),
+    3714                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP384r1_T_9_X, brainpoolP384r1_T_9_Y),
+    3715                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP384r1_T_10_X, brainpoolP384r1_T_10_Y),
+    3716                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP384r1_T_11_X, brainpoolP384r1_T_11_Y),
+    3717                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP384r1_T_12_X, brainpoolP384r1_T_12_Y),
+    3718                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP384r1_T_13_X, brainpoolP384r1_T_13_Y),
+    3719                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP384r1_T_14_X, brainpoolP384r1_T_14_Y),
+    3720                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP384r1_T_15_X, brainpoolP384r1_T_15_Y),
+    3721                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP384r1_T_16_X, brainpoolP384r1_T_16_Y),
+    3722                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP384r1_T_17_X, brainpoolP384r1_T_17_Y),
+    3723                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP384r1_T_18_X, brainpoolP384r1_T_18_Y),
+    3724                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP384r1_T_19_X, brainpoolP384r1_T_19_Y),
+    3725                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP384r1_T_20_X, brainpoolP384r1_T_20_Y),
+    3726                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP384r1_T_21_X, brainpoolP384r1_T_21_Y),
+    3727                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP384r1_T_22_X, brainpoolP384r1_T_22_Y),
+    3728                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP384r1_T_23_X, brainpoolP384r1_T_23_Y),
+    3729                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP384r1_T_24_X, brainpoolP384r1_T_24_Y),
+    3730                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP384r1_T_25_X, brainpoolP384r1_T_25_Y),
+    3731                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP384r1_T_26_X, brainpoolP384r1_T_26_Y),
+    3732                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP384r1_T_27_X, brainpoolP384r1_T_27_Y),
+    3733                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP384r1_T_28_X, brainpoolP384r1_T_28_Y),
+    3734                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP384r1_T_29_X, brainpoolP384r1_T_29_Y),
+    3735                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP384r1_T_30_X, brainpoolP384r1_T_30_Y),
+    3736                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP384r1_T_31_X, brainpoolP384r1_T_31_Y),
+    3737                 :            : };
+    3738                 :            : #else
+    3739                 :            : #define brainpoolP384r1_T NULL
+    3740                 :            : #endif
+    3741                 :            : 
+    3742                 :            : #endif /* MBEDTLS_ECP_DP_BP384R1_ENABLED */
+    3743                 :            : 
+    3744                 :            : /*
+    3745                 :            :  * Domain parameters for brainpoolP512r1 (RFC 5639 3.7)
+    3746                 :            :  */
+    3747                 :            : #if defined(MBEDTLS_ECP_DP_BP512R1_ENABLED)
+    3748                 :            : static const mbedtls_mpi_uint brainpoolP512r1_p[] = {
+    3749                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF3, 0x48, 0x3A, 0x58, 0x56, 0x60, 0xAA, 0x28),
+    3750                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x85, 0xC6, 0x82, 0x2D, 0x2F, 0xFF, 0x81, 0x28),
+    3751                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE6, 0x80, 0xA3, 0xE6, 0x2A, 0xA1, 0xCD, 0xAE),
+    3752                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x42, 0x68, 0xC6, 0x9B, 0x00, 0x9B, 0x4D, 0x7D),
+    3753                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x71, 0x08, 0x33, 0x70, 0xCA, 0x9C, 0x63, 0xD6),
+    3754                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0E, 0xD2, 0xC9, 0xB3, 0xB3, 0x8D, 0x30, 0xCB),
+    3755                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x07, 0xFC, 0xC9, 0x33, 0xAE, 0xE6, 0xD4, 0x3F),
+    3756                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8B, 0xC4, 0xE9, 0xDB, 0xB8, 0x9D, 0xDD, 0xAA),
+    3757                 :            : };
+    3758                 :            : static const mbedtls_mpi_uint brainpoolP512r1_a[] = {
+    3759                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCA, 0x94, 0xFC, 0x77, 0x4D, 0xAC, 0xC1, 0xE7),
+    3760                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB9, 0xC7, 0xF2, 0x2B, 0xA7, 0x17, 0x11, 0x7F),
+    3761                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB5, 0xC8, 0x9A, 0x8B, 0xC9, 0xF1, 0x2E, 0x0A),
+    3762                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA1, 0x3A, 0x25, 0xA8, 0x5A, 0x5D, 0xED, 0x2D),
+    3763                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBC, 0x63, 0x98, 0xEA, 0xCA, 0x41, 0x34, 0xA8),
+    3764                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x10, 0x16, 0xF9, 0x3D, 0x8D, 0xDD, 0xCB, 0x94),
+    3765                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC5, 0x4C, 0x23, 0xAC, 0x45, 0x71, 0x32, 0xE2),
+    3766                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x89, 0x3B, 0x60, 0x8B, 0x31, 0xA3, 0x30, 0x78),
+    3767                 :            : };
+    3768                 :            : static const mbedtls_mpi_uint brainpoolP512r1_b[] = {
+    3769                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x23, 0xF7, 0x16, 0x80, 0x63, 0xBD, 0x09, 0x28),
+    3770                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDD, 0xE5, 0xBA, 0x5E, 0xB7, 0x50, 0x40, 0x98),
+    3771                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x67, 0x3E, 0x08, 0xDC, 0xCA, 0x94, 0xFC, 0x77),
+    3772                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4D, 0xAC, 0xC1, 0xE7, 0xB9, 0xC7, 0xF2, 0x2B),
+    3773                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA7, 0x17, 0x11, 0x7F, 0xB5, 0xC8, 0x9A, 0x8B),
+    3774                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC9, 0xF1, 0x2E, 0x0A, 0xA1, 0x3A, 0x25, 0xA8),
+    3775                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5A, 0x5D, 0xED, 0x2D, 0xBC, 0x63, 0x98, 0xEA),
+    3776                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCA, 0x41, 0x34, 0xA8, 0x10, 0x16, 0xF9, 0x3D),
+    3777                 :            : };
+    3778                 :            : static const mbedtls_mpi_uint brainpoolP512r1_gx[] = {
+    3779                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x22, 0xF8, 0xB9, 0xBC, 0x09, 0x22, 0x35, 0x8B),
+    3780                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x68, 0x5E, 0x6A, 0x40, 0x47, 0x50, 0x6D, 0x7C),
+    3781                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5F, 0x7D, 0xB9, 0x93, 0x7B, 0x68, 0xD1, 0x50),
+    3782                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8D, 0xD4, 0xD0, 0xE2, 0x78, 0x1F, 0x3B, 0xFF),
+    3783                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8E, 0x09, 0xD0, 0xF4, 0xEE, 0x62, 0x3B, 0xB4),
+    3784                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC1, 0x16, 0xD9, 0xB5, 0x70, 0x9F, 0xED, 0x85),
+    3785                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x93, 0x6A, 0x4C, 0x9C, 0x2E, 0x32, 0x21, 0x5A),
+    3786                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x64, 0xD9, 0x2E, 0xD8, 0xBD, 0xE4, 0xAE, 0x81),
+    3787                 :            : };
+    3788                 :            : static const mbedtls_mpi_uint brainpoolP512r1_gy[] = {
+    3789                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x92, 0x08, 0xD8, 0x3A, 0x0F, 0x1E, 0xCD, 0x78),
+    3790                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x06, 0x54, 0xF0, 0xA8, 0x2F, 0x2B, 0xCA, 0xD1),
+    3791                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAE, 0x63, 0x27, 0x8A, 0xD8, 0x4B, 0xCA, 0x5B),
+    3792                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5E, 0x48, 0x5F, 0x4A, 0x49, 0xDE, 0xDC, 0xB2),
+    3793                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x11, 0x81, 0x1F, 0x88, 0x5B, 0xC5, 0x00, 0xA0),
+    3794                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1A, 0x7B, 0xA5, 0x24, 0x00, 0xF7, 0x09, 0xF2),
+    3795                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFD, 0x22, 0x78, 0xCF, 0xA9, 0xBF, 0xEA, 0xC0),
+    3796                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEC, 0x32, 0x63, 0x56, 0x5D, 0x38, 0xDE, 0x7D),
+    3797                 :            : };
+    3798                 :            : static const mbedtls_mpi_uint brainpoolP512r1_n[] = {
+    3799                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x69, 0x00, 0xA9, 0x9C, 0x82, 0x96, 0x87, 0xB5),
+    3800                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDD, 0xDA, 0x5D, 0x08, 0x81, 0xD3, 0xB1, 0x1D),
+    3801                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x47, 0x10, 0xAC, 0x7F, 0x19, 0x61, 0x86, 0x41),
+    3802                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x19, 0x26, 0xA9, 0x4C, 0x41, 0x5C, 0x3E, 0x55),
+    3803                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x70, 0x08, 0x33, 0x70, 0xCA, 0x9C, 0x63, 0xD6),
+    3804                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0E, 0xD2, 0xC9, 0xB3, 0xB3, 0x8D, 0x30, 0xCB),
+    3805                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x07, 0xFC, 0xC9, 0x33, 0xAE, 0xE6, 0xD4, 0x3F),
+    3806                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8B, 0xC4, 0xE9, 0xDB, 0xB8, 0x9D, 0xDD, 0xAA),
+    3807                 :            : };
+    3808                 :            : 
+    3809                 :            : #if MBEDTLS_ECP_FIXED_POINT_OPTIM == 1
+    3810                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_0_X[] = {
+    3811                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x22, 0xF8, 0xB9, 0xBC, 0x09, 0x22, 0x35, 0x8B),
+    3812                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x68, 0x5E, 0x6A, 0x40, 0x47, 0x50, 0x6D, 0x7C),
+    3813                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5F, 0x7D, 0xB9, 0x93, 0x7B, 0x68, 0xD1, 0x50),
+    3814                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8D, 0xD4, 0xD0, 0xE2, 0x78, 0x1F, 0x3B, 0xFF),
+    3815                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8E, 0x09, 0xD0, 0xF4, 0xEE, 0x62, 0x3B, 0xB4),
+    3816                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC1, 0x16, 0xD9, 0xB5, 0x70, 0x9F, 0xED, 0x85),
+    3817                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x93, 0x6A, 0x4C, 0x9C, 0x2E, 0x32, 0x21, 0x5A),
+    3818                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x64, 0xD9, 0x2E, 0xD8, 0xBD, 0xE4, 0xAE, 0x81),
+    3819                 :            : };
+    3820                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_0_Y[] = {
+    3821                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x92, 0x08, 0xD8, 0x3A, 0x0F, 0x1E, 0xCD, 0x78),
+    3822                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x06, 0x54, 0xF0, 0xA8, 0x2F, 0x2B, 0xCA, 0xD1),
+    3823                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAE, 0x63, 0x27, 0x8A, 0xD8, 0x4B, 0xCA, 0x5B),
+    3824                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5E, 0x48, 0x5F, 0x4A, 0x49, 0xDE, 0xDC, 0xB2),
+    3825                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x11, 0x81, 0x1F, 0x88, 0x5B, 0xC5, 0x00, 0xA0),
+    3826                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1A, 0x7B, 0xA5, 0x24, 0x00, 0xF7, 0x09, 0xF2),
+    3827                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFD, 0x22, 0x78, 0xCF, 0xA9, 0xBF, 0xEA, 0xC0),
+    3828                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEC, 0x32, 0x63, 0x56, 0x5D, 0x38, 0xDE, 0x7D),
+    3829                 :            : };
+    3830                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_1_X[] = {
+    3831                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEA, 0xE9, 0x6B, 0x8C, 0x6F, 0x9D, 0x88, 0x43),
+    3832                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBB, 0x4F, 0x86, 0x96, 0xA7, 0x56, 0xD1, 0x37),
+    3833                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9D, 0xAB, 0xFA, 0xEE, 0xA7, 0xF5, 0x0E, 0xA6),
+    3834                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE3, 0x40, 0xEF, 0x9E, 0x6D, 0xD6, 0x32, 0x33),
+    3835                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE3, 0xED, 0x56, 0x14, 0x57, 0x1A, 0x8D, 0x69),
+    3836                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA4, 0xED, 0x4D, 0x3A, 0xFA, 0x71, 0x75, 0x6B),
+    3837                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x66, 0xC5, 0x76, 0x1C, 0x14, 0xBE, 0xB5, 0xCD),
+    3838                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE1, 0x5A, 0xCB, 0xE7, 0x36, 0x1D, 0x52, 0x1C),
+    3839                 :            : };
+    3840                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_1_Y[] = {
+    3841                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6B, 0x8D, 0x7A, 0xEB, 0xA3, 0x8B, 0xD5, 0xB0),
+    3842                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1F, 0xA3, 0x41, 0xF8, 0xAC, 0x9E, 0xAB, 0x74),
+    3843                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x12, 0xE3, 0x65, 0x0D, 0x1C, 0xFE, 0x09, 0x2B),
+    3844                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3F, 0xCA, 0x13, 0x3F, 0xC5, 0xF9, 0x7E, 0xEC),
+    3845                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2C, 0x5D, 0x63, 0x28, 0xA6, 0x89, 0xD3, 0x91),
+    3846                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC9, 0x95, 0x3F, 0x7A, 0x82, 0xD4, 0x77, 0xE3),
+    3847                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x34, 0xBB, 0x92, 0x32, 0x00, 0xF4, 0x66, 0x42),
+    3848                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBA, 0x58, 0x31, 0xD1, 0x17, 0x9F, 0x2A, 0x22),
+    3849                 :            : };
+    3850                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_2_X[] = {
+    3851                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x52, 0x36, 0xA9, 0xCD, 0x80, 0xA5, 0x2D, 0x78),
+    3852                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x91, 0x44, 0xAB, 0xCE, 0x71, 0xFF, 0x0C, 0x9B),
+    3853                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x18, 0x24, 0x58, 0x35, 0x5A, 0x21, 0x32, 0x93),
+    3854                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1B, 0xA6, 0x28, 0xF8, 0x7A, 0x97, 0xAE, 0x8B),
+    3855                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x84, 0xE7, 0x08, 0xFA, 0x47, 0xC9, 0x55, 0x09),
+    3856                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8D, 0xAC, 0x2E, 0x84, 0xA4, 0xF5, 0x52, 0xC4),
+    3857                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD9, 0x58, 0x05, 0x9D, 0xA7, 0xC8, 0x71, 0xBF),
+    3858                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB3, 0x92, 0xB4, 0x92, 0xC1, 0x92, 0xEC, 0x6B),
+    3859                 :            : };
+    3860                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_2_Y[] = {
+    3861                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4A, 0x48, 0x2D, 0x79, 0x5E, 0x58, 0xE5, 0x69),
+    3862                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB4, 0x85, 0x26, 0xEC, 0xE9, 0x6E, 0xD4, 0x06),
+    3863                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x98, 0x68, 0x26, 0x87, 0x38, 0xA2, 0xD2, 0x0B),
+    3864                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF7, 0x17, 0x60, 0xCE, 0x75, 0xF8, 0xA5, 0x6F),
+    3865                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x20, 0x51, 0xDB, 0xA9, 0xAE, 0x87, 0xF1, 0x15),
+    3866                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDD, 0x49, 0x92, 0x3B, 0x19, 0x96, 0xF5, 0xB0),
+    3867                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC4, 0xD5, 0x52, 0x52, 0x8C, 0xCE, 0xFD, 0xFA),
+    3868                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x24, 0x18, 0x0A, 0xE6, 0xF6, 0xAE, 0x08, 0x41),
+    3869                 :            : };
+    3870                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_3_X[] = {
+    3871                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7E, 0x2B, 0xD8, 0x54, 0xCE, 0xB0, 0x57, 0xFE),
+    3872                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8A, 0xB0, 0xF8, 0x9E, 0x03, 0x03, 0x3C, 0x5D),
+    3873                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x93, 0x0E, 0x29, 0x29, 0x00, 0xF3, 0x70, 0xBF),
+    3874                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x54, 0x33, 0x99, 0x0E, 0x00, 0x5D, 0xFE, 0x4B),
+    3875                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x46, 0x2D, 0xF2, 0x59, 0x32, 0xCF, 0x03, 0xF4),
+    3876                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3B, 0xC9, 0x72, 0xAE, 0x0C, 0xEF, 0xD1, 0x5B),
+    3877                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB6, 0x5A, 0x27, 0xBF, 0x2F, 0x45, 0xF9, 0x51),
+    3878                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD4, 0xBE, 0xE5, 0x2C, 0xFF, 0x5B, 0x1E, 0x88),
+    3879                 :            : };
+    3880                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_3_Y[] = {
+    3881                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAA, 0xAC, 0xBB, 0xD8, 0x83, 0xC2, 0x46, 0xF6),
+    3882                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCF, 0xDC, 0xCE, 0x15, 0xB4, 0xEF, 0xCF, 0x46),
+    3883                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x46, 0xDB, 0x5E, 0x94, 0x31, 0x0B, 0xB2, 0x7A),
+    3884                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3C, 0xB9, 0xE3, 0xE3, 0x11, 0x71, 0x41, 0x1E),
+    3885                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x36, 0xE3, 0x01, 0xB7, 0x7D, 0xBC, 0x65, 0xBE),
+    3886                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFC, 0x07, 0x65, 0x87, 0xA7, 0xE8, 0x48, 0xE3),
+    3887                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x66, 0x48, 0x8F, 0xD4, 0x30, 0x8E, 0xB4, 0x6C),
+    3888                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x86, 0xE0, 0x73, 0xBE, 0x1E, 0xBF, 0x56, 0x36),
+    3889                 :            : };
+    3890                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_4_X[] = {
+    3891                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFE, 0x0E, 0x5E, 0x87, 0xC5, 0xAB, 0x0E, 0x3C),
+    3892                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB9, 0xF9, 0x5F, 0x80, 0x24, 0x4C, 0x2A, 0xF1),
+    3893                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDE, 0x15, 0x21, 0x54, 0x92, 0x84, 0x8D, 0x6A),
+    3894                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA8, 0x8A, 0x47, 0x74, 0xDC, 0x42, 0xB1, 0xF8),
+    3895                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x81, 0xF7, 0x30, 0xFD, 0xC1, 0x9B, 0x0C, 0x5B),
+    3896                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4E, 0x6C, 0xCC, 0xDF, 0xC5, 0xE3, 0xA9, 0xD5),
+    3897                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD6, 0x67, 0x59, 0x10, 0x5C, 0x51, 0x54, 0x40),
+    3898                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA0, 0x37, 0xFB, 0x6E, 0xB0, 0x78, 0x63, 0x8E),
+    3899                 :            : };
+    3900                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_4_Y[] = {
+    3901                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA5, 0xEF, 0xC4, 0x39, 0x20, 0xF1, 0x46, 0x66),
+    3902                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE2, 0x62, 0xAE, 0xFF, 0x10, 0xE4, 0xE2, 0xE9),
+    3903                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0x5C, 0xF5, 0x2E, 0x22, 0x89, 0xE5, 0x82),
+    3904                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x89, 0x0C, 0x29, 0xA8, 0x62, 0xAE, 0xDB, 0x65),
+    3905                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD7, 0x9E, 0x0F, 0xCA, 0x87, 0x2A, 0x6F, 0x7B),
+    3906                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCE, 0xDC, 0x9B, 0x9F, 0x65, 0xD4, 0xAD, 0x27),
+    3907                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xED, 0xC3, 0x08, 0x0F, 0xCF, 0x67, 0xE9, 0xF4),
+    3908                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x92, 0x5C, 0xD7, 0xFF, 0x41, 0x9C, 0xCB, 0x26),
+    3909                 :            : };
+    3910                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_5_X[] = {
+    3911                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x37, 0x25, 0x05, 0x12, 0xAD, 0x73, 0x63, 0x90),
+    3912                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC7, 0x99, 0x07, 0x86, 0x57, 0xE7, 0x94, 0xB1),
+    3913                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x00, 0x4B, 0xA5, 0xBF, 0x18, 0xA9, 0xEF, 0x6A),
+    3914                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFA, 0x4C, 0xC4, 0x09, 0xF2, 0x2F, 0x0C, 0xAA),
+    3915                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8C, 0x3A, 0x04, 0xEA, 0x89, 0x6C, 0x91, 0xB9),
+    3916                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7D, 0x6C, 0x3A, 0xE7, 0xA3, 0xEC, 0x24, 0x7B),
+    3917                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x16, 0xA1, 0x26, 0x21, 0x04, 0xE3, 0xB9, 0x40),
+    3918                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x53, 0x71, 0x4B, 0x7B, 0xC2, 0x89, 0xCD, 0xA2),
+    3919                 :            : };
+    3920                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_5_Y[] = {
+    3921                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB7, 0xB9, 0xA8, 0x9D, 0xFD, 0x00, 0x3A, 0x1F),
+    3922                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x63, 0x41, 0x6C, 0xBB, 0x5A, 0xCA, 0x1F, 0x74),
+    3923                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2A, 0xD7, 0xE2, 0x6C, 0x6B, 0xA7, 0x48, 0xC9),
+    3924                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1E, 0x19, 0xAD, 0xA7, 0xC1, 0x7E, 0x4F, 0x6E),
+    3925                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD1, 0xF7, 0x19, 0x3C, 0x06, 0x74, 0x2C, 0x3A),
+    3926                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC5, 0x23, 0x4F, 0x0C, 0x09, 0xB0, 0x80, 0x4A),
+    3927                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4E, 0x74, 0x34, 0x08, 0x44, 0x7E, 0xA3, 0xDD),
+    3928                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFB, 0xCC, 0x8D, 0x12, 0x6E, 0xE1, 0x3D, 0x0B),
+    3929                 :            : };
+    3930                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_6_X[] = {
+    3931                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x38, 0x18, 0xB1, 0x71, 0x02, 0x93, 0xC2, 0xA4),
+    3932                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC9, 0x89, 0x40, 0xE2, 0x1F, 0xE7, 0x5E, 0x68),
+    3933                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x50, 0x8E, 0xAE, 0x89, 0x01, 0xD4, 0x0C, 0xEB),
+    3934                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAE, 0xDA, 0x58, 0x70, 0x24, 0xF2, 0xE4, 0x5F),
+    3935                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6F, 0xC7, 0x1D, 0xD6, 0x4A, 0x6F, 0x66, 0x4F),
+    3936                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x92, 0x1D, 0x7E, 0x4A, 0x2C, 0xCA, 0xEC, 0x3B),
+    3937                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA1, 0x06, 0x7F, 0xA8, 0x99, 0xE4, 0xD3, 0x4E),
+    3938                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2A, 0x1D, 0x5A, 0xDF, 0x5E, 0x58, 0x36, 0x49),
+    3939                 :            : };
+    3940                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_6_Y[] = {
+    3941                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9C, 0xB9, 0x32, 0x69, 0x1F, 0x72, 0x2A, 0xB3),
+    3942                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1C, 0x73, 0xE2, 0x03, 0x39, 0x35, 0xAA, 0xA8),
+    3943                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEB, 0x5E, 0x5D, 0x48, 0xEF, 0xAE, 0x30, 0xF5),
+    3944                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x77, 0x7F, 0x60, 0x19, 0xAF, 0xEC, 0x9D, 0xFC),
+    3945                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCA, 0xD9, 0x19, 0xE4, 0x1B, 0x56, 0x15, 0x5F),
+    3946                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBC, 0xD7, 0x33, 0x59, 0x1F, 0x43, 0x59, 0x2C),
+    3947                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC6, 0xCE, 0xEE, 0xCA, 0xA4, 0x7F, 0x63, 0xD4),
+    3948                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBD, 0x40, 0xC0, 0xF6, 0x19, 0x89, 0x43, 0x20),
+    3949                 :            : };
+    3950                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_7_X[] = {
+    3951                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEB, 0x92, 0xEA, 0x07, 0x65, 0x79, 0x86, 0xD3),
+    3952                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0xB7, 0x13, 0x75, 0xD3, 0xC5, 0x0A, 0xC9),
+    3953                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x26, 0x9E, 0xFA, 0xE1, 0x1F, 0x0C, 0xF9, 0x74),
+    3954                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB4, 0x8C, 0xED, 0x5C, 0x21, 0xE9, 0x09, 0xDD),
+    3955                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF4, 0x4D, 0xD8, 0x18, 0xC4, 0xF6, 0x36, 0x39),
+    3956                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC7, 0xC9, 0xAC, 0x5C, 0xFA, 0x69, 0xA4, 0xA0),
+    3957                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6B, 0x8C, 0x94, 0x1C, 0x7B, 0x71, 0x36, 0x58),
+    3958                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7C, 0xBD, 0x46, 0xCE, 0xB7, 0x1D, 0x9C, 0x5E),
+    3959                 :            : };
+    3960                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_7_Y[] = {
+    3961                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEA, 0xD6, 0x96, 0x4B, 0xA6, 0x47, 0xEB, 0xE5),
+    3962                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5F, 0xF1, 0x5F, 0x15, 0xDE, 0x99, 0x6F, 0x66),
+    3963                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x21, 0xBD, 0xE5, 0x04, 0xB8, 0xE6, 0xC0, 0x0B),
+    3964                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x49, 0xD3, 0xF0, 0x04, 0x00, 0xE4, 0x05, 0xDB),
+    3965                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x96, 0xF3, 0x06, 0xA3, 0x1A, 0xFF, 0xEA, 0x73),
+    3966                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x08, 0x32, 0xAA, 0x99, 0x33, 0x09, 0xB6, 0x34),
+    3967                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6E, 0xEF, 0xFC, 0x61, 0x10, 0x42, 0x31, 0x94),
+    3968                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x34, 0xF1, 0xF4, 0x33, 0xCF, 0x28, 0x90, 0x9C),
+    3969                 :            : };
+    3970                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_8_X[] = {
+    3971                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x10, 0xDE, 0xF9, 0x88, 0x87, 0x7B, 0xEB, 0xC9),
+    3972                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x66, 0xB8, 0xDA, 0xFA, 0xDA, 0x3D, 0xA6, 0x17),
+    3973                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA0, 0xF0, 0x62, 0x82, 0x53, 0x32, 0x55, 0x03),
+    3974                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2F, 0xA5, 0x32, 0x4A, 0x19, 0x11, 0x9C, 0x10),
+    3975                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x16, 0xB3, 0x27, 0xE9, 0x75, 0x90, 0x05, 0x2D),
+    3976                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x63, 0x1C, 0x90, 0x48, 0x77, 0x01, 0x85, 0x1B),
+    3977                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC7, 0xD6, 0x9B, 0x84, 0xA8, 0xD7, 0xC5, 0x28),
+    3978                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE1, 0x7A, 0xCB, 0xB3, 0x11, 0x46, 0xD7, 0x99),
+    3979                 :            : };
+    3980                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_8_Y[] = {
+    3981                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8B, 0x23, 0xBF, 0x75, 0x75, 0xA1, 0x95, 0x90),
+    3982                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4B, 0x66, 0x5D, 0x34, 0x13, 0xA9, 0x03, 0xBE),
+    3983                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x29, 0x80, 0x9D, 0x5F, 0xD2, 0x44, 0xE1, 0x62),
+    3984                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x96, 0x5D, 0xBD, 0xA8, 0xBF, 0xB4, 0x25, 0x1F),
+    3985                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6A, 0x99, 0x1F, 0x53, 0xF1, 0x57, 0xDB, 0xE7),
+    3986                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x21, 0x7C, 0xE5, 0xC5, 0x51, 0x0B, 0x4C, 0x9B),
+    3987                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6B, 0xB0, 0x1A, 0x9C, 0x16, 0xB0, 0x32, 0x1F),
+    3988                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF4, 0xE3, 0xCF, 0xDD, 0x48, 0xB4, 0x7B, 0x33),
+    3989                 :            : };
+    3990                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_9_X[] = {
+    3991                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC0, 0xDD, 0x9E, 0x3C, 0x98, 0x0E, 0x77, 0x65),
+    3992                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6C, 0xAB, 0x01, 0xD3, 0x87, 0x74, 0x25, 0x4A),
+    3993                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x87, 0xA3, 0xE3, 0x76, 0x43, 0x87, 0x12, 0xBD),
+    3994                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x54, 0xB1, 0x3B, 0x60, 0x66, 0xEB, 0x98, 0x54),
+    3995                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD2, 0x78, 0xC8, 0xD7, 0x4E, 0x75, 0xCA, 0x69),
+    3996                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x07, 0xDF, 0x71, 0x19, 0xE7, 0x07, 0x36, 0xB5),
+    3997                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6D, 0xC9, 0xA8, 0x5F, 0x91, 0xBF, 0x47, 0xB2),
+    3998                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x80, 0x96, 0x58, 0x96, 0x18, 0xB6, 0xFA, 0x01),
+    3999                 :            : };
+    4000                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_9_Y[] = {
+    4001                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD0, 0x2D, 0xA9, 0x9B, 0x86, 0xDB, 0x0C, 0x4C),
+    4002                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE4, 0x0B, 0x2D, 0x56, 0x4A, 0xD3, 0x93, 0x8A),
+    4003                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB5, 0x15, 0xE2, 0x65, 0x12, 0x86, 0x0E, 0xB2),
+    4004                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB4, 0x41, 0x4D, 0xC1, 0xCB, 0xE4, 0xC3, 0xD7),
+    4005                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6A, 0x53, 0x10, 0xCA, 0xA3, 0xAC, 0x83, 0x26),
+    4006                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3E, 0x01, 0x22, 0x96, 0x10, 0xAD, 0x69, 0xDB),
+    4007                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x42, 0x46, 0x4E, 0xD8, 0xEA, 0xD6, 0x9D, 0xF3),
+    4008                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x43, 0x2F, 0x7F, 0x62, 0x62, 0x80, 0xD0, 0x14),
+    4009                 :            : };
+    4010                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_10_X[] = {
+    4011                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB2, 0xDA, 0x00, 0x63, 0x09, 0xBD, 0x6A, 0x83),
+    4012                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0F, 0xD4, 0x6E, 0x48, 0x05, 0xB7, 0xF7, 0x17),
+    4013                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x14, 0x4D, 0xD7, 0x00, 0x4A, 0x15, 0x27, 0x7A),
+    4014                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3A, 0x15, 0xAA, 0x37, 0x27, 0x34, 0x18, 0x24),
+    4015                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3A, 0x20, 0x2C, 0x84, 0x1B, 0x88, 0xBA, 0x05),
+    4016                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAC, 0x09, 0xD6, 0x04, 0xA2, 0x60, 0x84, 0x72),
+    4017                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC8, 0x04, 0x94, 0x08, 0xD4, 0xED, 0x47, 0xDB),
+    4018                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8B, 0xF3, 0xE4, 0x3E, 0xB9, 0x5B, 0x35, 0x42),
+    4019                 :            : };
+    4020                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_10_Y[] = {
+    4021                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5F, 0xD8, 0xB6, 0x80, 0xD6, 0xF1, 0x30, 0xDD),
+    4022                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD6, 0x14, 0xA6, 0x85, 0xEE, 0xA7, 0xD8, 0x61),
+    4023                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE4, 0x49, 0x2A, 0x1E, 0x7C, 0xE9, 0x2D, 0xEC),
+    4024                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3A, 0x87, 0x56, 0x91, 0x03, 0x77, 0x4D, 0x55),
+    4025                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0E, 0x52, 0xD4, 0xAA, 0xF7, 0xFA, 0xB0, 0xC5),
+    4026                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x04, 0x5D, 0x11, 0x39, 0xB1, 0xE7, 0x76, 0xAD),
+    4027                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD6, 0x13, 0xBC, 0x37, 0x5D, 0x74, 0xCD, 0xC2),
+    4028                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC9, 0x48, 0x14, 0x23, 0x30, 0xF8, 0x46, 0x37),
+    4029                 :            : };
+    4030                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_11_X[] = {
+    4031                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAC, 0x27, 0xB0, 0xD9, 0xB2, 0x74, 0xB4, 0xC0),
+    4032                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEA, 0xA6, 0xB9, 0x6F, 0x9F, 0x64, 0x36, 0x92),
+    4033                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2E, 0x2B, 0x78, 0x40, 0x05, 0x2B, 0x7B, 0xA9),
+    4034                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB3, 0x68, 0x3A, 0xB6, 0x4A, 0xE2, 0xDB, 0xB8),
+    4035                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1E, 0x33, 0xD7, 0x34, 0x8B, 0x25, 0x45, 0xEF),
+    4036                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x89, 0xCE, 0xA8, 0xC9, 0x01, 0xFB, 0x0E, 0x7B),
+    4037                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE2, 0xF9, 0x51, 0x4C, 0x12, 0x9F, 0x60, 0xE4),
+    4038                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x67, 0x85, 0xBD, 0x30, 0x37, 0x84, 0x39, 0x44),
+    4039                 :            : };
+    4040                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_11_Y[] = {
+    4041                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x26, 0x33, 0xAF, 0x2E, 0xB8, 0x2E, 0xCC, 0x3C),
+    4042                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA4, 0xB1, 0x73, 0x59, 0x4E, 0x0C, 0x09, 0x4A),
+    4043                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8A, 0x24, 0x89, 0x81, 0x12, 0xFF, 0xBB, 0x6E),
+    4044                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x71, 0x37, 0x1A, 0x66, 0xEE, 0xED, 0xB6, 0x9B),
+    4045                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x16, 0xBD, 0x04, 0x20, 0x5D, 0xFB, 0xBF, 0x95),
+    4046                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA0, 0xF8, 0x34, 0xA3, 0xFF, 0x45, 0xDE, 0x92),
+    4047                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9B, 0x18, 0x73, 0xF1, 0x32, 0x25, 0x58, 0xEB),
+    4048                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x63, 0xC1, 0x14, 0xE3, 0x9E, 0x40, 0x0F, 0x12),
+    4049                 :            : };
+    4050                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_12_X[] = {
+    4051                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x61, 0x07, 0x9D, 0x9C, 0x00, 0xF7, 0x56, 0x19),
+    4052                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFB, 0xBA, 0x87, 0xF9, 0x15, 0x0C, 0x66, 0x5D),
+    4053                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7E, 0x1F, 0xC1, 0x28, 0xB0, 0x47, 0x0D, 0xF5),
+    4054                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x96, 0xCA, 0x27, 0xEE, 0x4B, 0x23, 0x2B, 0x89),
+    4055                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7E, 0xB5, 0x68, 0xC8, 0x17, 0x5D, 0xC3, 0xAA),
+    4056                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x17, 0x02, 0x08, 0xEE, 0x20, 0x9D, 0xEA, 0x64),
+    4057                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA7, 0x14, 0x50, 0xD4, 0x7D, 0x5F, 0xCF, 0xA0),
+    4058                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD5, 0xFA, 0xF8, 0xA7, 0xC6, 0xDC, 0x14, 0x8C),
+    4059                 :            : };
+    4060                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_12_Y[] = {
+    4061                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x76, 0xBD, 0x0A, 0x1A, 0x18, 0x98, 0xDC, 0xB0),
+    4062                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x63, 0x63, 0x02, 0xB7, 0xD5, 0x5B, 0x5A, 0xC6),
+    4063                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x51, 0xB1, 0xD7, 0x4B, 0x15, 0x39, 0x61, 0x5D),
+    4064                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5C, 0x32, 0xE1, 0x9E, 0x70, 0x1B, 0xCE, 0x51),
+    4065                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x64, 0xD8, 0x18, 0x83, 0x52, 0x9B, 0x6D, 0xA2),
+    4066                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA4, 0x55, 0x56, 0x19, 0x34, 0xA4, 0xEA, 0xFC),
+    4067                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x30, 0xA9, 0x55, 0x80, 0xE3, 0x15, 0x36, 0x8B),
+    4068                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBB, 0x06, 0xC8, 0x1D, 0x17, 0x0D, 0xAD, 0x16),
+    4069                 :            : };
+    4070                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_13_X[] = {
+    4071                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x20, 0xD6, 0xF0, 0xCC, 0xF3, 0x63, 0x53, 0xD2),
+    4072                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x27, 0x5A, 0xDC, 0x46, 0xBD, 0x0D, 0xAD, 0x96),
+    4073                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x21, 0x2F, 0x11, 0x60, 0x15, 0x51, 0x4A, 0xEA),
+    4074                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x33, 0xE3, 0x93, 0x38, 0xD5, 0x83, 0xAA, 0x0D),
+    4075                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x90, 0xA6, 0xCC, 0xB1, 0xFD, 0xBB, 0x1A, 0x0F),
+    4076                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3B, 0x54, 0xC8, 0x54, 0x6F, 0x79, 0x1A, 0x59),
+    4077                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3F, 0x4A, 0xDA, 0x28, 0x92, 0x97, 0x9D, 0x7F),
+    4078                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD6, 0x4B, 0xDB, 0xC7, 0x52, 0xC5, 0x66, 0x34),
+    4079                 :            : };
+    4080                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_13_Y[] = {
+    4081                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x05, 0x7E, 0x92, 0x53, 0x30, 0x93, 0xFD, 0xFF),
+    4082                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA0, 0x16, 0x6A, 0xB1, 0x91, 0x0A, 0xB4, 0x52),
+    4083                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6D, 0x9D, 0x40, 0x3F, 0xE3, 0xF1, 0x01, 0x46),
+    4084                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x13, 0x0E, 0xD8, 0xED, 0x11, 0x8E, 0x4C, 0xED),
+    4085                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x86, 0x4A, 0x1B, 0x88, 0xDF, 0x8D, 0x29, 0xE7),
+    4086                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x97, 0x23, 0x21, 0x11, 0xAB, 0x77, 0x81, 0x62),
+    4087                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0B, 0xAF, 0x11, 0xFA, 0xBA, 0x40, 0x63, 0xE7),
+    4088                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2B, 0x6F, 0x8D, 0x80, 0xDF, 0x67, 0xF5, 0x44),
+    4089                 :            : };
+    4090                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_14_X[] = {
+    4091                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB2, 0x8B, 0xB7, 0x08, 0xF4, 0xD7, 0x2D, 0xA8),
+    4092                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC7, 0x2B, 0x30, 0x02, 0x45, 0x71, 0x08, 0x49),
+    4093                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x97, 0x3A, 0xCA, 0x50, 0xF6, 0xC2, 0x19, 0x8C),
+    4094                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x17, 0xB9, 0x9B, 0x3E, 0x73, 0x95, 0x1D, 0x49),
+    4095                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB6, 0x60, 0x59, 0x48, 0xCB, 0xD8, 0xD6, 0xAA),
+    4096                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF0, 0xB9, 0x6C, 0x89, 0xAB, 0x99, 0xA8, 0xF8),
+    4097                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEF, 0xA1, 0x8B, 0x4E, 0x06, 0x19, 0xEC, 0x99),
+    4098                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x70, 0x95, 0x04, 0xCF, 0xD5, 0x94, 0xB3, 0x02),
+    4099                 :            : };
+    4100                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_14_Y[] = {
+    4101                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x29, 0x35, 0x93, 0x7C, 0xB3, 0xB8, 0x9E, 0x1B),
+    4102                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC4, 0x45, 0x5C, 0x7E, 0xBF, 0x75, 0x81, 0x0F),
+    4103                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDC, 0xE8, 0x24, 0xDF, 0xEC, 0x2F, 0x7D, 0xB9),
+    4104                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF2, 0x8B, 0xD5, 0x6A, 0x9B, 0xA0, 0xE0, 0x4F),
+    4105                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x32, 0xE3, 0x27, 0x82, 0xDE, 0xDD, 0xCA, 0x4B),
+    4106                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA7, 0x57, 0x56, 0x46, 0x05, 0x06, 0x01, 0x2E),
+    4107                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x74, 0x35, 0xA7, 0x47, 0xE2, 0x6B, 0x2C, 0x4F),
+    4108                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x38, 0x9D, 0x4C, 0xEC, 0x1F, 0x11, 0x75, 0x2B),
+    4109                 :            : };
+    4110                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_15_X[] = {
+    4111                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAC, 0xAA, 0x41, 0xC1, 0xE9, 0x0E, 0xE9, 0xAA),
+    4112                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0A, 0xCF, 0x9C, 0x4B, 0xE8, 0xED, 0x0A, 0x49),
+    4113                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3D, 0x73, 0xCA, 0x0C, 0x46, 0x0A, 0x9C, 0xE4),
+    4114                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x99, 0xE1, 0x9E, 0xBC, 0xFE, 0x44, 0x63, 0x6D),
+    4115                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x31, 0x43, 0x71, 0xEE, 0xF8, 0xC1, 0x8C, 0x5C),
+    4116                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6A, 0x4B, 0xF0, 0x69, 0x25, 0xBD, 0x71, 0x1A),
+    4117                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFD, 0x9A, 0xFE, 0x82, 0xE7, 0xC1, 0xC1, 0xEE),
+    4118                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFC, 0x5A, 0x6E, 0x5E, 0x97, 0x6A, 0x35, 0x8D),
+    4119                 :            : };
+    4120                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_15_Y[] = {
+    4121                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA2, 0x18, 0x6C, 0x7E, 0xB8, 0x9E, 0x57, 0x32),
+    4122                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x35, 0xB9, 0xC1, 0xD0, 0xFE, 0x78, 0xFB, 0x32),
+    4123                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7C, 0x08, 0xAE, 0x46, 0x34, 0xEA, 0x7A, 0x7F),
+    4124                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE8, 0x1C, 0x56, 0xA9, 0x18, 0x37, 0xD4, 0x9E),
+    4125                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x28, 0x63, 0xE9, 0x0A, 0xB6, 0x38, 0x3C, 0xC1),
+    4126                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3E, 0x4F, 0xA4, 0x6E, 0x85, 0x31, 0x23, 0x52),
+    4127                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0D, 0xAD, 0xC4, 0xC3, 0xB1, 0x4B, 0x1C, 0x82),
+    4128                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x30, 0x56, 0x4A, 0x38, 0xB3, 0x6B, 0x6F, 0x2C),
+    4129                 :            : };
+    4130                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_16_X[] = {
+    4131                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x67, 0xC7, 0x19, 0xDE, 0x21, 0xED, 0x89, 0xD0),
+    4132                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2F, 0xBE, 0xA6, 0xAE, 0xEB, 0x9D, 0xA7, 0x2A),
+    4133                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x04, 0x0E, 0x13, 0x1E, 0x86, 0x57, 0xC3, 0x3B),
+    4134                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1F, 0x4B, 0x30, 0x46, 0x52, 0xC1, 0xEC, 0x52),
+    4135                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6E, 0xD5, 0x44, 0x31, 0x96, 0x3B, 0x26, 0x27),
+    4136                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x77, 0x68, 0xA8, 0x67, 0x78, 0x39, 0xE8, 0x68),
+    4137                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8E, 0x78, 0xB7, 0xDD, 0xF2, 0x58, 0xB6, 0x3D),
+    4138                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x81, 0x3C, 0xB3, 0x26, 0xC4, 0x2C, 0x8C, 0xA5),
+    4139                 :            : };
+    4140                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_16_Y[] = {
+    4141                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB9, 0x24, 0xE5, 0x73, 0xEE, 0x9A, 0x02, 0xA9),
+    4142                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD9, 0x6A, 0x65, 0x60, 0xF3, 0x62, 0xE3, 0xE9),
+    4143                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFB, 0x07, 0x84, 0xE6, 0x3B, 0x46, 0x65, 0x9F),
+    4144                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE1, 0x8F, 0x0C, 0xB0, 0xE1, 0x04, 0x82, 0x9D),
+    4145                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEB, 0x13, 0xBF, 0x3D, 0xA0, 0x48, 0xA2, 0x74),
+    4146                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x08, 0x26, 0x76, 0x74, 0xAB, 0x0B, 0x29, 0xE8),
+    4147                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x30, 0x6E, 0x5F, 0x03, 0x34, 0x7C, 0x38, 0xCE),
+    4148                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4D, 0x72, 0xF9, 0x3B, 0x3C, 0xA4, 0xBC, 0x7C),
+    4149                 :            : };
+    4150                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_17_X[] = {
+    4151                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5C, 0xCE, 0x18, 0x80, 0xB8, 0x24, 0x45, 0x81),
+    4152                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF1, 0x09, 0x03, 0xB8, 0x06, 0x64, 0xF7, 0xEC),
+    4153                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF1, 0x26, 0xB1, 0x10, 0x6D, 0x71, 0x12, 0x2E),
+    4154                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAD, 0x12, 0xC6, 0x6E, 0x1E, 0x6A, 0xC3, 0x80),
+    4155                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE5, 0xD3, 0x0A, 0xDE, 0xD8, 0x6B, 0x04, 0x5C),
+    4156                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x96, 0x87, 0x5B, 0xAE, 0xDB, 0x3C, 0xC0, 0xC5),
+    4157                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8E, 0xF5, 0xF9, 0xC1, 0x9A, 0x89, 0xBB, 0x7E),
+    4158                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xED, 0x69, 0x72, 0x8B, 0xAE, 0x32, 0x13, 0x11),
+    4159                 :            : };
+    4160                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_17_Y[] = {
+    4161                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF9, 0x16, 0x07, 0x50, 0xFA, 0x4C, 0xCF, 0xE8),
+    4162                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF8, 0x50, 0x21, 0xE9, 0xDE, 0xEC, 0x7E, 0xDF),
+    4163                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7C, 0x2F, 0xE8, 0x83, 0x30, 0x0B, 0x65, 0x0E),
+    4164                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA5, 0x0B, 0x99, 0xAC, 0xC9, 0xBA, 0x6C, 0x2A),
+    4165                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA7, 0x59, 0x5A, 0x0D, 0x7B, 0x9E, 0x08, 0xAD),
+    4166                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x34, 0x91, 0xB2, 0xDC, 0x90, 0xCE, 0x67, 0xED),
+    4167                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE3, 0x93, 0x60, 0x0C, 0xD7, 0x1F, 0x2F, 0x17),
+    4168                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x19, 0x7F, 0x9D, 0x40, 0xF8, 0x78, 0x7A, 0x54),
+    4169                 :            : };
+    4170                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_18_X[] = {
+    4171                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x13, 0x22, 0x95, 0xE8, 0xEF, 0x31, 0x57, 0x35),
+    4172                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2D, 0x88, 0x53, 0xFE, 0xAF, 0x7C, 0x47, 0x14),
+    4173                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0E, 0xCE, 0xCC, 0x79, 0xE8, 0x9F, 0x8C, 0xC4),
+    4174                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDB, 0x16, 0xDD, 0x77, 0x6E, 0x8A, 0x73, 0x97),
+    4175                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC0, 0x07, 0x97, 0x21, 0x3B, 0xF8, 0x5F, 0xA8),
+    4176                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC6, 0xB5, 0xD2, 0x81, 0x84, 0xF0, 0xE7, 0x9F),
+    4177                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCB, 0x8F, 0x75, 0x09, 0x6A, 0x0E, 0x53, 0xAD),
+    4178                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE6, 0x4F, 0x70, 0x97, 0xC7, 0xAC, 0x7D, 0x3F),
+    4179                 :            : };
+    4180                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_18_Y[] = {
+    4181                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF9, 0x3C, 0x6A, 0xB4, 0x10, 0xA9, 0xC8, 0x1D),
+    4182                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEE, 0xC5, 0xD6, 0x69, 0x16, 0xB8, 0xAC, 0x25),
+    4183                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAC, 0x44, 0xDC, 0xEB, 0x48, 0x54, 0x5D, 0x5F),
+    4184                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6F, 0x48, 0x9B, 0xD7, 0x72, 0x69, 0xA4, 0x8A),
+    4185                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB4, 0x0D, 0x36, 0x9A, 0x66, 0x0B, 0xEC, 0x24),
+    4186                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBE, 0xC6, 0xD4, 0xB6, 0x60, 0xE5, 0xC3, 0x3A),
+    4187                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBA, 0x29, 0x42, 0xE0, 0x9D, 0xFD, 0x7C, 0x3E),
+    4188                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x43, 0x10, 0xBA, 0x55, 0xBC, 0x3B, 0x38, 0x5D),
+    4189                 :            : };
+    4190                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_19_X[] = {
+    4191                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x25, 0x66, 0xFA, 0x05, 0x73, 0x03, 0x1B, 0x69),
+    4192                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x11, 0xA4, 0x66, 0x12, 0x96, 0x7B, 0x02, 0x4C),
+    4193                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x44, 0xB5, 0xDE, 0x6D, 0x98, 0xD1, 0xD5, 0xA8),
+    4194                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE2, 0xF5, 0x44, 0xB8, 0x8E, 0xF6, 0x8C, 0x05),
+    4195                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x68, 0x15, 0x2B, 0x72, 0xBC, 0x49, 0xE5, 0xDF),
+    4196                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x6C, 0x44, 0xD7, 0xDF, 0x8F, 0xEB, 0x8D, 0x80),
+    4197                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x05, 0x64, 0x88, 0xAA, 0xB7, 0xE4, 0x70, 0x1D),
+    4198                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9C, 0x14, 0xBB, 0xE9, 0x9B, 0xB9, 0x65, 0x5D),
+    4199                 :            : };
+    4200                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_19_Y[] = {
+    4201                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x66, 0x8E, 0x88, 0xF5, 0xF1, 0xC1, 0x89, 0xA2),
+    4202                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x16, 0x30, 0x53, 0xE6, 0xFB, 0x2D, 0x82, 0xB4),
+    4203                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA7, 0xE4, 0xFF, 0xBA, 0x31, 0x79, 0xAB, 0xC2),
+    4204                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x45, 0x09, 0xF7, 0xB7, 0x09, 0x78, 0x4C, 0x90),
+    4205                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x10, 0xAE, 0xC2, 0x44, 0xDC, 0x17, 0x78, 0x47),
+    4206                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC7, 0xD4, 0x17, 0x43, 0x19, 0x74, 0x9E, 0x23),
+    4207                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x15, 0x64, 0x3B, 0x73, 0xA2, 0x99, 0x27, 0x76),
+    4208                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x05, 0x74, 0x36, 0x5F, 0xD3, 0x14, 0xB1, 0x31),
+    4209                 :            : };
+    4210                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_20_X[] = {
+    4211                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAC, 0x07, 0xAB, 0xFD, 0x9B, 0x03, 0xC5, 0xD5),
+    4212                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC7, 0xBE, 0xB0, 0x1D, 0xF2, 0x0C, 0x73, 0x73),
+    4213                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x99, 0xE7, 0x7B, 0x87, 0xD3, 0x34, 0xFD, 0xE2),
+    4214                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9A, 0x25, 0x3D, 0xC7, 0x36, 0x83, 0x53, 0xDC),
+    4215                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x22, 0x7C, 0xCF, 0x63, 0x55, 0x12, 0x11, 0xB0),
+    4216                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC0, 0x34, 0x4D, 0x27, 0x92, 0xAC, 0x18, 0x16),
+    4217                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x98, 0x42, 0x61, 0x9D, 0x2E, 0xFF, 0x13, 0x16),
+    4218                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF4, 0xDE, 0x92, 0x65, 0x57, 0x0D, 0xBC, 0x0A),
+    4219                 :            : };
+    4220                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_20_Y[] = {
+    4221                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEF, 0x7B, 0x6E, 0xC6, 0x2A, 0x21, 0x74, 0x0A),
+    4222                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x37, 0xA7, 0x53, 0x4D, 0x29, 0x36, 0xEF, 0xE5),
+    4223                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE1, 0xD6, 0x41, 0xC7, 0x99, 0xAD, 0x50, 0x53),
+    4224                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x99, 0xAC, 0x41, 0x9F, 0xFB, 0x4C, 0x86, 0xF1),
+    4225                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8B, 0xBB, 0xE6, 0x25, 0x28, 0xAA, 0xEB, 0x1E),
+    4226                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x92, 0x04, 0xA2, 0xC3, 0xAA, 0x08, 0x8A, 0xCC),
+    4227                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5A, 0x2B, 0x5B, 0xE2, 0x8D, 0x76, 0xEA, 0x34),
+    4228                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB3, 0x33, 0xD2, 0x21, 0x4D, 0x62, 0xE3, 0x8E),
+    4229                 :            : };
+    4230                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_21_X[] = {
+    4231                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF6, 0x06, 0x8B, 0x2B, 0xC2, 0xC4, 0xB1, 0xD2),
+    4232                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFA, 0xF5, 0xA1, 0xC0, 0x03, 0x6A, 0x29, 0x12),
+    4233                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF5, 0xA9, 0xEF, 0x55, 0xB6, 0x1A, 0x9F, 0x6B),
+    4234                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9B, 0x54, 0x32, 0xBE, 0x06, 0x43, 0xB5, 0xFD),
+    4235                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF7, 0xD6, 0xD9, 0x20, 0x89, 0xBE, 0xD4, 0x1B),
+    4236                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE8, 0x26, 0x95, 0x10, 0xCE, 0xB4, 0x88, 0x79),
+    4237                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE6, 0xA6, 0x27, 0xAC, 0x32, 0xBA, 0xBD, 0xC7),
+    4238                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA3, 0xA6, 0xAE, 0x9C, 0x7B, 0xBE, 0xA1, 0x63),
+    4239                 :            : };
+    4240                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_21_Y[] = {
+    4241                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8B, 0xCD, 0x4D, 0x3D, 0xDF, 0x96, 0xBB, 0x7D),
+    4242                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x77, 0xA7, 0x11, 0x06, 0xCC, 0x0E, 0x31, 0x81),
+    4243                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x20, 0xE4, 0xF4, 0xAD, 0x7B, 0x5F, 0xF1, 0xEF),
+    4244                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE4, 0x54, 0xBE, 0xF4, 0x8A, 0x03, 0x47, 0xDF),
+    4245                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB4, 0x53, 0x00, 0x7F, 0xB0, 0x8A, 0x68, 0xA6),
+    4246                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA0, 0x16, 0xB1, 0x73, 0x6F, 0x5B, 0x0E, 0xC3),
+    4247                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2A, 0x32, 0xE3, 0x43, 0x64, 0x75, 0xFB, 0xFB),
+    4248                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA0, 0x18, 0x55, 0x8A, 0x4E, 0x6E, 0x35, 0x54),
+    4249                 :            : };
+    4250                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_22_X[] = {
+    4251                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x80, 0x97, 0x15, 0x1E, 0xCB, 0xF2, 0x9C, 0xA5),
+    4252                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2B, 0xD1, 0xBB, 0xF3, 0x70, 0xAD, 0x13, 0xAD),
+    4253                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD8, 0x96, 0xA4, 0xC5, 0x5E, 0xDA, 0xD5, 0x57),
+    4254                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x07, 0x81, 0xE9, 0x65, 0x66, 0x76, 0x47, 0x45),
+    4255                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC9, 0x35, 0x87, 0x06, 0x73, 0xCF, 0x34, 0xD2),
+    4256                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5A, 0x81, 0x15, 0x42, 0xA2, 0x79, 0x5B, 0x42),
+    4257                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x08, 0xA2, 0x7D, 0x09, 0x14, 0x64, 0xC6, 0xAE),
+    4258                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5E, 0x6D, 0xC4, 0xED, 0xF1, 0xD6, 0xE9, 0x24),
+    4259                 :            : };
+    4260                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_22_Y[] = {
+    4261                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB4, 0xD5, 0xBB, 0x25, 0xA3, 0xDD, 0xA3, 0x88),
+    4262                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x46, 0xF2, 0x68, 0x67, 0x39, 0x8F, 0x73, 0x93),
+    4263                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF0, 0x76, 0x28, 0x89, 0xAD, 0x32, 0xE0, 0xDF),
+    4264                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF8, 0x90, 0xCC, 0x57, 0x58, 0xAA, 0xC9, 0x75),
+    4265                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5E, 0xD7, 0x43, 0xD2, 0xCE, 0x5E, 0xA0, 0x08),
+    4266                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x33, 0xB0, 0xB8, 0xA4, 0x9E, 0x96, 0x26, 0x86),
+    4267                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x94, 0x61, 0x1D, 0xF3, 0x65, 0x5E, 0x60, 0xCA),
+    4268                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC7, 0x1E, 0x65, 0xED, 0xCF, 0x07, 0x60, 0x20),
+    4269                 :            : };
+    4270                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_23_X[] = {
+    4271                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA4, 0x30, 0x17, 0x8A, 0x91, 0x88, 0x0A, 0xA4),
+    4272                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x05, 0x7D, 0x18, 0xA4, 0xAC, 0x59, 0xFC, 0x5F),
+    4273                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA4, 0x31, 0x8B, 0x25, 0x65, 0x39, 0x9A, 0xDC),
+    4274                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x15, 0x16, 0x4B, 0x68, 0xBA, 0x59, 0x13, 0x2F),
+    4275                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8D, 0xFD, 0xD3, 0xC5, 0x56, 0xC9, 0x8C, 0x5E),
+    4276                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBC, 0xC6, 0x9F, 0xF4, 0xE6, 0xF7, 0xB4, 0x01),
+    4277                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2D, 0x7C, 0x03, 0x00, 0x26, 0x9F, 0xD8, 0x7B),
+    4278                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x24, 0x1D, 0x6E, 0x00, 0xB9, 0x00, 0x6E, 0x93),
+    4279                 :            : };
+    4280                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_23_Y[] = {
+    4281                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x75, 0x63, 0xDA, 0x03, 0x2B, 0xD5, 0x0B, 0xFE),
+    4282                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x46, 0xFC, 0xE2, 0xC8, 0x47, 0xF0, 0xAE, 0xF2),
+    4283                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x51, 0x4C, 0xF7, 0x50, 0x0C, 0x48, 0x06, 0x2A),
+    4284                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDF, 0x2B, 0x32, 0x98, 0x0E, 0x7E, 0x61, 0x41),
+    4285                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5D, 0x02, 0x27, 0xFE, 0x75, 0x86, 0xDF, 0x24),
+    4286                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2B, 0x30, 0xB1, 0x22, 0x32, 0x1B, 0xFE, 0x24),
+    4287                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC2, 0x27, 0xF7, 0x78, 0x6F, 0xD7, 0xFD, 0xE4),
+    4288                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA0, 0x78, 0xCC, 0xEA, 0xC0, 0x50, 0x24, 0x44),
+    4289                 :            : };
+    4290                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_24_X[] = {
+    4291                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x37, 0x2B, 0x4F, 0x7F, 0x58, 0xE6, 0xC2, 0x70),
+    4292                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x37, 0x43, 0xD5, 0xA7, 0x35, 0x3C, 0x80, 0xB8),
+    4293                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1A, 0x6D, 0x4B, 0x12, 0x00, 0x7B, 0xE6, 0xA6),
+    4294                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x37, 0x15, 0xBD, 0xD0, 0x9B, 0xCA, 0xAA, 0x81),
+    4295                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xCF, 0xCE, 0x9C, 0xE3, 0x8B, 0x60, 0x7A, 0x53),
+    4296                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0C, 0xDA, 0x4B, 0x03, 0xA7, 0x8D, 0x43, 0x22),
+    4297                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x57, 0xAF, 0x00, 0x2B, 0x32, 0xF0, 0x22, 0x68),
+    4298                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDC, 0xD9, 0x99, 0x99, 0xBE, 0x43, 0x99, 0x3E),
+    4299                 :            : };
+    4300                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_24_Y[] = {
+    4301                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1F, 0x71, 0x41, 0xF4, 0xB5, 0xFD, 0xDD, 0x36),
+    4302                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9D, 0xE2, 0x20, 0x4C, 0xD1, 0x2E, 0x1F, 0x06),
+    4303                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x96, 0x43, 0x48, 0x76, 0x8A, 0x49, 0xAC, 0x87),
+    4304                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0C, 0x1A, 0x55, 0xA8, 0xA3, 0xD4, 0x57, 0x75),
+    4305                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7C, 0xA6, 0x84, 0x39, 0xC9, 0x13, 0xBB, 0x60),
+    4306                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD9, 0xFA, 0xA9, 0x70, 0xDE, 0x83, 0xDD, 0xC9),
+    4307                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEC, 0xC9, 0xD9, 0x3E, 0x44, 0x91, 0x68, 0x7B),
+    4308                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB6, 0x9F, 0x85, 0x6D, 0xF7, 0x54, 0x36, 0x82),
+    4309                 :            : };
+    4310                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_25_X[] = {
+    4311                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x68, 0x6B, 0xA6, 0xA3, 0xE5, 0xD4, 0x46, 0xDB),
+    4312                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x23, 0x3E, 0xDC, 0x84, 0x7C, 0x7B, 0x24, 0x34),
+    4313                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x14, 0xED, 0x7F, 0x86, 0x07, 0x6C, 0x57, 0xCA),
+    4314                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x95, 0x06, 0xFE, 0x52, 0x12, 0x79, 0x69, 0x56),
+    4315                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x84, 0xD1, 0x44, 0x5F, 0x21, 0x3A, 0xC3, 0x84),
+    4316                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5E, 0xD9, 0x4A, 0xC0, 0x75, 0xAB, 0x17, 0xAC),
+    4317                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xFF, 0x81, 0x94, 0xB6, 0x80, 0x6B, 0x6F, 0xC3),
+    4318                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x07, 0xBE, 0x8E, 0xA5, 0xAA, 0xBC, 0x1E, 0x3E),
+    4319                 :            : };
+    4320                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_25_Y[] = {
+    4321                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x89, 0xC7, 0x85, 0xA6, 0x59, 0x9B, 0xB1, 0x52),
+    4322                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1C, 0xCE, 0x40, 0xD1, 0xFB, 0xDF, 0x94, 0xF7),
+    4323                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x18, 0xB8, 0x5E, 0xBF, 0x45, 0xA8, 0x2D, 0x2D),
+    4324                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x98, 0x9C, 0x06, 0x1B, 0xA9, 0x57, 0xB9, 0x79),
+    4325                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x53, 0xE9, 0xCE, 0xA2, 0xD3, 0x74, 0xA1, 0x3C),
+    4326                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAA, 0x5F, 0x34, 0x78, 0xDB, 0xAE, 0x3A, 0x14),
+    4327                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7D, 0x32, 0x84, 0x3E, 0x68, 0x6A, 0x43, 0x0F),
+    4328                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8C, 0xBC, 0x39, 0x36, 0xA4, 0xC5, 0xBB, 0x11),
+    4329                 :            : };
+    4330                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_26_X[] = {
+    4331                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8C, 0x07, 0xA2, 0xB5, 0xC9, 0x0F, 0x4D, 0x0F),
+    4332                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE3, 0x1D, 0x67, 0xE6, 0xF1, 0x46, 0xEB, 0x71),
+    4333                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD7, 0x41, 0x23, 0x95, 0xE7, 0xE0, 0x10, 0xDD),
+    4334                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBE, 0x69, 0xFE, 0x68, 0x8C, 0xC6, 0x5F, 0xB6),
+    4335                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE3, 0xB9, 0x2B, 0x3D, 0xD2, 0x4F, 0xD8, 0x1A),
+    4336                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA3, 0x09, 0xF5, 0x5F, 0xCF, 0xF6, 0x91, 0x57),
+    4337                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x65, 0x15, 0x42, 0x6B, 0x6D, 0xB5, 0xF3, 0xB6),
+    4338                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBF, 0x56, 0x9D, 0xC5, 0xFF, 0xCA, 0x13, 0x9B),
+    4339                 :            : };
+    4340                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_26_Y[] = {
+    4341                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x4D, 0x38, 0xE6, 0x23, 0x63, 0x48, 0x3C, 0xCA),
+    4342                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD2, 0x68, 0x3C, 0xD1, 0x3B, 0xE9, 0x3B, 0x82),
+    4343                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB5, 0x08, 0x54, 0x49, 0xD1, 0x46, 0x45, 0x13),
+    4344                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x07, 0x70, 0x52, 0x6E, 0x79, 0xC4, 0x5E, 0x95),
+    4345                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x36, 0xDF, 0xE8, 0x5A, 0x32, 0x81, 0xDA, 0xD3),
+    4346                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3C, 0x2D, 0x94, 0x5B, 0xB5, 0x35, 0x9F, 0x0A),
+    4347                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2A, 0x12, 0x8D, 0xC3, 0x36, 0x36, 0xB2, 0x2A),
+    4348                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x39, 0x2F, 0x22, 0x38, 0x5B, 0x18, 0x4C, 0x35),
+    4349                 :            : };
+    4350                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_27_X[] = {
+    4351                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x10, 0xC1, 0x22, 0x0E, 0xF0, 0x73, 0x11, 0x05),
+    4352                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB2, 0xAE, 0xA4, 0x56, 0x18, 0x61, 0x66, 0x12),
+    4353                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x79, 0xFB, 0x72, 0x08, 0x84, 0x38, 0x51, 0xB0),
+    4354                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDA, 0x86, 0xA8, 0xB9, 0x31, 0x99, 0x29, 0xC3),
+    4355                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x8A, 0xFB, 0xC3, 0x42, 0xB3, 0xC7, 0x6F, 0x3A),
+    4356                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD8, 0xF8, 0xE1, 0x09, 0xBE, 0x75, 0xB0, 0x22),
+    4357                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5A, 0x7D, 0xFF, 0xF4, 0x99, 0xFC, 0x13, 0xAB),
+    4358                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE6, 0x1B, 0x84, 0x81, 0x42, 0x22, 0xC6, 0x3D),
+    4359                 :            : };
+    4360                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_27_Y[] = {
+    4361                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x21, 0xE0, 0x37, 0xA4, 0xA0, 0x2F, 0x38, 0x7F),
+    4362                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD0, 0x3D, 0xB7, 0x40, 0x2F, 0x39, 0x3C, 0x7A),
+    4363                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7A, 0x3B, 0x8A, 0x51, 0xAE, 0x40, 0x49, 0x7A),
+    4364                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x36, 0x20, 0x9F, 0xDD, 0xA9, 0xD0, 0x77, 0xC7),
+    4365                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x78, 0x1D, 0x64, 0xDA, 0xA0, 0x53, 0xC7, 0x7D),
+    4366                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x37, 0x7B, 0x66, 0x55, 0x94, 0xD1, 0x51, 0x44),
+    4367                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0E, 0xA9, 0xB5, 0x5B, 0x38, 0x35, 0x40, 0xC0),
+    4368                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC8, 0xC9, 0x0F, 0xF0, 0x73, 0x79, 0x43, 0x61),
+    4369                 :            : };
+    4370                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_28_X[] = {
+    4371                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x10, 0x47, 0x45, 0x69, 0x80, 0x72, 0x72, 0x42),
+    4372                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x70, 0x11, 0x99, 0x59, 0xDB, 0x48, 0x80, 0x39),
+    4373                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x75, 0x6E, 0x3D, 0xFC, 0x37, 0x15, 0xF4, 0xBF),
+    4374                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x17, 0xBB, 0x5B, 0xA6, 0x35, 0x8D, 0x28, 0x20),
+    4375                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAB, 0x1A, 0x3B, 0x2C, 0x8F, 0xD3, 0xAA, 0x2D),
+    4376                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x55, 0x1C, 0x1A, 0xF8, 0x02, 0xD9, 0x7B, 0x41),
+    4377                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAF, 0x69, 0xAC, 0xF8, 0x54, 0x31, 0x14, 0xA1),
+    4378                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x41, 0x8A, 0xE6, 0xDE, 0x58, 0xB9, 0xC4, 0x7A),
+    4379                 :            : };
+    4380                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_28_Y[] = {
+    4381                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x57, 0x83, 0x52, 0xFE, 0xF9, 0x7B, 0xE9, 0x1F),
+    4382                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x07, 0xA2, 0x55, 0x46, 0x15, 0x49, 0xC1, 0x3A),
+    4383                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1D, 0xBC, 0x5C, 0x91, 0xBD, 0xB9, 0x9C, 0xF4),
+    4384                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBB, 0xFD, 0xB1, 0x4E, 0x5F, 0x74, 0xEE, 0x53),
+    4385                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xB1, 0x8B, 0xD8, 0x8B, 0x17, 0x73, 0x1B, 0x96),
+    4386                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x22, 0x92, 0xD7, 0x67, 0x06, 0xAD, 0x25, 0xCD),
+    4387                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x01, 0x0F, 0x80, 0x24, 0xE2, 0x27, 0x5F, 0x8B),
+    4388                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x61, 0x1C, 0xCE, 0xD0, 0x67, 0xCA, 0xD4, 0x0B),
+    4389                 :            : };
+    4390                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_29_X[] = {
+    4391                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x87, 0xF1, 0xDD, 0x33, 0x66, 0xF9, 0x05, 0xD6),
+    4392                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1D, 0xE5, 0x6B, 0x79, 0xBD, 0x48, 0x42, 0xAA),
+    4393                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD1, 0x14, 0x52, 0xE3, 0x53, 0xB4, 0x50, 0xD4),
+    4394                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x32, 0x84, 0x6C, 0xCF, 0xDA, 0xB2, 0x20, 0x0A),
+    4395                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x70, 0xD6, 0x1A, 0xE5, 0xE2, 0x29, 0x70, 0xCE),
+    4396                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD5, 0x61, 0xFE, 0xBB, 0x21, 0x82, 0xD1, 0xFE),
+    4397                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x2C, 0xF0, 0x9C, 0x8B, 0x1A, 0x42, 0x30, 0x06),
+    4398                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x43, 0xD6, 0x49, 0x81, 0x92, 0xF1, 0xD0, 0x90),
+    4399                 :            : };
+    4400                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_29_Y[] = {
+    4401                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC9, 0x91, 0x93, 0x6A, 0xA6, 0x22, 0xE9, 0xD6),
+    4402                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x09, 0xDC, 0xC3, 0x69, 0x11, 0x95, 0x7D, 0xEC),
+    4403                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x1C, 0xA3, 0x9D, 0x87, 0x5E, 0x64, 0x41, 0xA2),
+    4404                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xBE, 0x87, 0x5A, 0x15, 0xBD, 0x6E, 0x3C, 0x8D),
+    4405                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD0, 0x8D, 0x50, 0xCC, 0xCF, 0xB7, 0x8F, 0x0B),
+    4406                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x38, 0x65, 0xCD, 0x31, 0x30, 0xF1, 0x68, 0x13),
+    4407                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x10, 0x5C, 0x66, 0x67, 0x92, 0x30, 0x57, 0x95),
+    4408                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x23, 0x9B, 0x01, 0x3D, 0x20, 0x8B, 0xD1, 0x0D),
+    4409                 :            : };
+    4410                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_30_X[] = {
+    4411                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAB, 0xC0, 0xE6, 0x4F, 0xDE, 0x62, 0xAB, 0xB3),
+    4412                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA4, 0x48, 0xB3, 0x1C, 0x0F, 0x16, 0x93, 0x45),
+    4413                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x77, 0x63, 0xBD, 0x1F, 0x16, 0x50, 0x56, 0x98),
+    4414                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x5D, 0x06, 0xBC, 0xE9, 0x27, 0x1C, 0x9A, 0x7B),
+    4415                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF8, 0xFE, 0x21, 0xC5, 0x39, 0x55, 0xE1, 0xFD),
+    4416                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF6, 0xA8, 0xD0, 0x96, 0x0E, 0xB5, 0xB2, 0x84),
+    4417                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3D, 0xE7, 0x4B, 0xF3, 0x11, 0x0C, 0xC9, 0x5B),
+    4418                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x43, 0x3A, 0xC4, 0x87, 0x71, 0xEE, 0xFA, 0x18),
+    4419                 :            : };
+    4420                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_30_Y[] = {
+    4421                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA7, 0x77, 0xEE, 0x81, 0x5E, 0x96, 0xEA, 0x4B),
+    4422                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xEE, 0xDF, 0xA9, 0xF4, 0x4F, 0x7C, 0xB2, 0x43),
+    4423                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x9F, 0xD4, 0xDF, 0x35, 0x63, 0x47, 0x25, 0x8A),
+    4424                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xA5, 0x3D, 0xFF, 0xA4, 0x02, 0xC3, 0x95, 0x11),
+    4425                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xD5, 0x10, 0x78, 0xD1, 0x2B, 0xB7, 0xBE, 0x0E),
+    4426                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x0A, 0xE9, 0x57, 0xF9, 0xE0, 0xD8, 0xFC, 0xBC),
+    4427                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF3, 0xC4, 0x01, 0xD6, 0xB4, 0xE7, 0x78, 0xE2),
+    4428                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x02, 0x6C, 0xB9, 0x13, 0xA4, 0xE8, 0x6D, 0x6F),
+    4429                 :            : };
+    4430                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_31_X[] = {
+    4431                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE8, 0xB0, 0xC9, 0xCD, 0xBF, 0xA2, 0x1E, 0x63),
+    4432                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xDD, 0x4F, 0x86, 0x22, 0x9B, 0xEA, 0xE8, 0xBB),
+    4433                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x50, 0x46, 0xDF, 0x43, 0xB9, 0x82, 0x2D, 0x0A),
+    4434                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x07, 0x32, 0xF1, 0x4E, 0x95, 0x41, 0xAE, 0x8E),
+    4435                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x52, 0x93, 0x26, 0xFC, 0xD3, 0x90, 0xDC, 0xEB),
+    4436                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x04, 0x05, 0x45, 0xCA, 0xF9, 0x5A, 0x89, 0x93),
+    4437                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xC5, 0x82, 0x63, 0x4E, 0x55, 0x1D, 0x3A, 0x08),
+    4438                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x7C, 0x69, 0x52, 0x49, 0xE9, 0xED, 0x57, 0x34),
+    4439                 :            : };
+    4440                 :            : static const mbedtls_mpi_uint brainpoolP512r1_T_31_Y[] = {
+    4441                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x70, 0x64, 0xE9, 0xAC, 0x4C, 0x4A, 0xEA, 0x25),
+    4442                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xE9, 0xE9, 0x0B, 0x99, 0xE7, 0xF9, 0xA9, 0x2C),
+    4443                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x24, 0x0C, 0xC1, 0xF4, 0x8D, 0x07, 0xB6, 0xB1),
+    4444                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xAD, 0x68, 0xFA, 0x35, 0xE4, 0x9E, 0xAE, 0xD9),
+    4445                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0xF0, 0x2D, 0x1A, 0x13, 0x8E, 0x02, 0xE2, 0x63),
+    4446                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x27, 0x38, 0x28, 0x86, 0x46, 0x7B, 0x3A, 0xE1),
+    4447                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x3F, 0x4C, 0x64, 0x59, 0x0A, 0xF9, 0x02, 0xC4),
+    4448                 :            :     MBEDTLS_BYTES_TO_T_UINT_8(0x41, 0x4F, 0x23, 0xA2, 0xC3, 0xD5, 0xEF, 0x42),
+    4449                 :            : };
+    4450                 :            : static const mbedtls_ecp_point brainpoolP512r1_T[32] = {
+    4451                 :            :     ECP_POINT_INIT_XY_Z1(brainpoolP512r1_T_0_X, brainpoolP512r1_T_0_Y),
+    4452                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP512r1_T_1_X, brainpoolP512r1_T_1_Y),
+    4453                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP512r1_T_2_X, brainpoolP512r1_T_2_Y),
+    4454                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP512r1_T_3_X, brainpoolP512r1_T_3_Y),
+    4455                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP512r1_T_4_X, brainpoolP512r1_T_4_Y),
+    4456                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP512r1_T_5_X, brainpoolP512r1_T_5_Y),
+    4457                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP512r1_T_6_X, brainpoolP512r1_T_6_Y),
+    4458                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP512r1_T_7_X, brainpoolP512r1_T_7_Y),
+    4459                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP512r1_T_8_X, brainpoolP512r1_T_8_Y),
+    4460                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP512r1_T_9_X, brainpoolP512r1_T_9_Y),
+    4461                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP512r1_T_10_X, brainpoolP512r1_T_10_Y),
+    4462                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP512r1_T_11_X, brainpoolP512r1_T_11_Y),
+    4463                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP512r1_T_12_X, brainpoolP512r1_T_12_Y),
+    4464                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP512r1_T_13_X, brainpoolP512r1_T_13_Y),
+    4465                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP512r1_T_14_X, brainpoolP512r1_T_14_Y),
+    4466                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP512r1_T_15_X, brainpoolP512r1_T_15_Y),
+    4467                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP512r1_T_16_X, brainpoolP512r1_T_16_Y),
+    4468                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP512r1_T_17_X, brainpoolP512r1_T_17_Y),
+    4469                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP512r1_T_18_X, brainpoolP512r1_T_18_Y),
+    4470                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP512r1_T_19_X, brainpoolP512r1_T_19_Y),
+    4471                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP512r1_T_20_X, brainpoolP512r1_T_20_Y),
+    4472                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP512r1_T_21_X, brainpoolP512r1_T_21_Y),
+    4473                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP512r1_T_22_X, brainpoolP512r1_T_22_Y),
+    4474                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP512r1_T_23_X, brainpoolP512r1_T_23_Y),
+    4475                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP512r1_T_24_X, brainpoolP512r1_T_24_Y),
+    4476                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP512r1_T_25_X, brainpoolP512r1_T_25_Y),
+    4477                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP512r1_T_26_X, brainpoolP512r1_T_26_Y),
+    4478                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP512r1_T_27_X, brainpoolP512r1_T_27_Y),
+    4479                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP512r1_T_28_X, brainpoolP512r1_T_28_Y),
+    4480                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP512r1_T_29_X, brainpoolP512r1_T_29_Y),
+    4481                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP512r1_T_30_X, brainpoolP512r1_T_30_Y),
+    4482                 :            :     ECP_POINT_INIT_XY_Z0(brainpoolP512r1_T_31_X, brainpoolP512r1_T_31_Y),
+    4483                 :            : };
+    4484                 :            : #else
+    4485                 :            : #define brainpoolP512r1_T NULL
+    4486                 :            : #endif
+    4487                 :            : #endif /* MBEDTLS_ECP_DP_BP512R1_ENABLED */
+    4488                 :            : 
+    4489                 :            : #if defined(ECP_LOAD_GROUP)
+    4490                 :            : /*
+    4491                 :            :  * Create an MPI from embedded constants
+    4492                 :            :  * (assumes len is an exact multiple of sizeof(mbedtls_mpi_uint))
+    4493                 :            :  */
+    4494                 :      62310 : static inline void ecp_mpi_load(mbedtls_mpi *X, const mbedtls_mpi_uint *p, size_t len)
+    4495                 :            : {
+    4496                 :      62310 :     X->s = 1;
+    4497                 :      62310 :     X->n = (unsigned short) (len / sizeof(mbedtls_mpi_uint));
+    4498                 :      62310 :     X->p = (mbedtls_mpi_uint *) p;
+    4499                 :      62310 : }
+    4500                 :            : 
+    4501                 :            : /*
+    4502                 :            :  * Set an MPI to static value 1
+    4503                 :            :  */
+    4504                 :      12462 : static inline void ecp_mpi_set1(mbedtls_mpi *X)
+    4505                 :            : {
+    4506                 :      12462 :     X->s = 1;
+    4507                 :      12462 :     X->n = 1;
+    4508                 :      12462 :     X->p = (mbedtls_mpi_uint *) mpi_one; /* X->p will not be modified so the cast is safe */
+    4509                 :      12462 : }
+    4510                 :            : 
+    4511                 :            : /*
+    4512                 :            :  * Make group available from embedded constants
+    4513                 :            :  */
+    4514                 :      12462 : static int ecp_group_load(mbedtls_ecp_group *grp,
+    4515                 :            :                           const mbedtls_mpi_uint *p,  size_t plen,
+    4516                 :            :                           const mbedtls_mpi_uint *a,  size_t alen,
+    4517                 :            :                           const mbedtls_mpi_uint *b,  size_t blen,
+    4518                 :            :                           const mbedtls_mpi_uint *gx, size_t gxlen,
+    4519                 :            :                           const mbedtls_mpi_uint *gy, size_t gylen,
+    4520                 :            :                           const mbedtls_mpi_uint *n,  size_t nlen,
+    4521                 :            :                           const mbedtls_ecp_point *T)
+    4522                 :            : {
+    4523                 :      12462 :     ecp_mpi_load(&grp->P, p, plen);
+    4524         [ -  + ]:      12462 :     if (a != NULL) {
+    4525                 :          0 :         ecp_mpi_load(&grp->A, a, alen);
+    4526                 :            :     }
+    4527                 :      12462 :     ecp_mpi_load(&grp->B, b, blen);
+    4528                 :      12462 :     ecp_mpi_load(&grp->N, n, nlen);
+    4529                 :            : 
+    4530                 :      12462 :     ecp_mpi_load(&grp->G.X, gx, gxlen);
+    4531                 :      12462 :     ecp_mpi_load(&grp->G.Y, gy, gylen);
+    4532                 :      12462 :     ecp_mpi_set1(&grp->G.Z);
+    4533                 :            : 
+    4534                 :      12462 :     grp->pbits = mbedtls_mpi_bitlen(&grp->P);
+    4535                 :      12462 :     grp->nbits = mbedtls_mpi_bitlen(&grp->N);
+    4536                 :            : 
+    4537                 :      12462 :     grp->h = 1;
+    4538                 :            : 
+    4539                 :      12462 :     grp->T = (mbedtls_ecp_point *) T;
+    4540                 :            :     /*
+    4541                 :            :      * Set T_size to 0 to prevent T free by mbedtls_ecp_group_free.
+    4542                 :            :      */
+    4543                 :      12462 :     grp->T_size = 0;
+    4544                 :            : 
+    4545                 :      12462 :     return 0;
+    4546                 :            : }
+    4547                 :            : #endif /* ECP_LOAD_GROUP */
+    4548                 :            : 
+    4549                 :            : #if defined(MBEDTLS_ECP_NIST_OPTIM)
+    4550                 :            : /* Forward declarations */
+    4551                 :            : #if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED)
+    4552                 :            : static int ecp_mod_p192(mbedtls_mpi *);
+    4553                 :            : #endif
+    4554                 :            : #if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED)
+    4555                 :            : static int ecp_mod_p224(mbedtls_mpi *);
+    4556                 :            : #endif
+    4557                 :            : #if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED)
+    4558                 :            : static int ecp_mod_p256(mbedtls_mpi *);
+    4559                 :            : #endif
+    4560                 :            : #if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED)
+    4561                 :            : static int ecp_mod_p384(mbedtls_mpi *);
+    4562                 :            : #endif
+    4563                 :            : #if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED)
+    4564                 :            : static int ecp_mod_p521(mbedtls_mpi *);
+    4565                 :            : #endif
+    4566                 :            : 
+    4567                 :            : #define NIST_MODP(P)      grp->modp = ecp_mod_ ## P;
+    4568                 :            : #else
+    4569                 :            : #define NIST_MODP(P)
+    4570                 :            : #endif /* MBEDTLS_ECP_NIST_OPTIM */
+    4571                 :            : 
+    4572                 :            : /* Additional forward declarations */
+    4573                 :            : #if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED)
+    4574                 :            : static int ecp_mod_p255(mbedtls_mpi *);
+    4575                 :            : #endif
+    4576                 :            : #if defined(MBEDTLS_ECP_DP_CURVE448_ENABLED)
+    4577                 :            : static int ecp_mod_p448(mbedtls_mpi *);
+    4578                 :            : #endif
+    4579                 :            : #if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED)
+    4580                 :            : static int ecp_mod_p192k1(mbedtls_mpi *);
+    4581                 :            : #endif
+    4582                 :            : #if defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED)
+    4583                 :            : static int ecp_mod_p224k1(mbedtls_mpi *);
+    4584                 :            : #endif
+    4585                 :            : #if defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED)
+    4586                 :            : static int ecp_mod_p256k1(mbedtls_mpi *);
+    4587                 :            : #endif
+    4588                 :            : 
+    4589                 :            : #if defined(ECP_LOAD_GROUP)
+    4590                 :            : #define LOAD_GROUP_A(G)   ecp_group_load(grp,            \
+    4591                 :            :                                          G ## _p,  sizeof(G ## _p),   \
+    4592                 :            :                                          G ## _a,  sizeof(G ## _a),   \
+    4593                 :            :                                          G ## _b,  sizeof(G ## _b),   \
+    4594                 :            :                                          G ## _gx, sizeof(G ## _gx),   \
+    4595                 :            :                                          G ## _gy, sizeof(G ## _gy),   \
+    4596                 :            :                                          G ## _n,  sizeof(G ## _n),   \
+    4597                 :            :                                          G ## _T                         \
+    4598                 :            :                                          )
+    4599                 :            : 
+    4600                 :            : #define LOAD_GROUP(G)     ecp_group_load(grp,            \
+    4601                 :            :                                          G ## _p,  sizeof(G ## _p),   \
+    4602                 :            :                                          NULL,     0,                    \
+    4603                 :            :                                          G ## _b,  sizeof(G ## _b),   \
+    4604                 :            :                                          G ## _gx, sizeof(G ## _gx),   \
+    4605                 :            :                                          G ## _gy, sizeof(G ## _gy),   \
+    4606                 :            :                                          G ## _n,  sizeof(G ## _n),   \
+    4607                 :            :                                          G ## _T                         \
+    4608                 :            :                                          )
+    4609                 :            : #endif /* ECP_LOAD_GROUP */
+    4610                 :            : 
+    4611                 :            : #if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED)
+    4612                 :            : /* Constants used by ecp_use_curve25519() */
+    4613                 :            : static const mbedtls_mpi_sint curve25519_a24 = 0x01DB42;
+    4614                 :            : static const unsigned char curve25519_part_of_n[] = {
+    4615                 :            :     0x14, 0xDE, 0xF9, 0xDE, 0xA2, 0xF7, 0x9C, 0xD6,
+    4616                 :            :     0x58, 0x12, 0x63, 0x1A, 0x5C, 0xF5, 0xD3, 0xED,
+    4617                 :            : };
+    4618                 :            : 
+    4619                 :            : /*
+    4620                 :            :  * Specialized function for creating the Curve25519 group
+    4621                 :            :  */
+    4622                 :          0 : static int ecp_use_curve25519(mbedtls_ecp_group *grp)
+    4623                 :            : {
+    4624                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    4625                 :            : 
+    4626                 :            :     /* Actually ( A + 2 ) / 4 */
+    4627         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&grp->A, curve25519_a24));
+    4628                 :            : 
+    4629                 :            :     /* P = 2^255 - 19 */
+    4630         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&grp->P, 1));
+    4631         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(&grp->P, 255));
+    4632         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&grp->P, &grp->P, 19));
+    4633                 :          0 :     grp->pbits = mbedtls_mpi_bitlen(&grp->P);
+    4634                 :            : 
+    4635                 :            :     /* N = 2^252 + 27742317777372353535851937790883648493 */
+    4636         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&grp->N,
+    4637                 :            :                                             curve25519_part_of_n, sizeof(curve25519_part_of_n)));
+    4638         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_set_bit(&grp->N, 252, 1));
+    4639                 :            : 
+    4640                 :            :     /* Y intentionally not set, since we use x/z coordinates.
+    4641                 :            :      * This is used as a marker to identify Montgomery curves! */
+    4642         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&grp->G.X, 9));
+    4643         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&grp->G.Z, 1));
+    4644                 :          0 :     mbedtls_mpi_free(&grp->G.Y);
+    4645                 :            : 
+    4646                 :            :     /* Actually, the required msb for private keys */
+    4647                 :          0 :     grp->nbits = 254;
+    4648                 :            : 
+    4649                 :          0 : cleanup:
+    4650         [ #  # ]:          0 :     if (ret != 0) {
+    4651                 :          0 :         mbedtls_ecp_group_free(grp);
+    4652                 :            :     }
+    4653                 :            : 
+    4654                 :          0 :     return ret;
+    4655                 :            : }
+    4656                 :            : #endif /* MBEDTLS_ECP_DP_CURVE25519_ENABLED */
+    4657                 :            : 
+    4658                 :            : #if defined(MBEDTLS_ECP_DP_CURVE448_ENABLED)
+    4659                 :            : /* Constants used by ecp_use_curve448() */
+    4660                 :            : static const mbedtls_mpi_sint curve448_a24 = 0x98AA;
+    4661                 :            : static const unsigned char curve448_part_of_n[] = {
+    4662                 :            :     0x83, 0x35, 0xDC, 0x16, 0x3B, 0xB1, 0x24,
+    4663                 :            :     0xB6, 0x51, 0x29, 0xC9, 0x6F, 0xDE, 0x93,
+    4664                 :            :     0x3D, 0x8D, 0x72, 0x3A, 0x70, 0xAA, 0xDC,
+    4665                 :            :     0x87, 0x3D, 0x6D, 0x54, 0xA7, 0xBB, 0x0D,
+    4666                 :            : };
+    4667                 :            : 
+    4668                 :            : /*
+    4669                 :            :  * Specialized function for creating the Curve448 group
+    4670                 :            :  */
+    4671                 :          0 : static int ecp_use_curve448(mbedtls_ecp_group *grp)
+    4672                 :            : {
+    4673                 :            :     mbedtls_mpi Ns;
+    4674                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    4675                 :            : 
+    4676                 :          0 :     mbedtls_mpi_init(&Ns);
+    4677                 :            : 
+    4678                 :            :     /* Actually ( A + 2 ) / 4 */
+    4679         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&grp->A, curve448_a24));
+    4680                 :            : 
+    4681                 :            :     /* P = 2^448 - 2^224 - 1 */
+    4682         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&grp->P, 1));
+    4683         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(&grp->P, 224));
+    4684         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&grp->P, &grp->P, 1));
+    4685         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(&grp->P, 224));
+    4686         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&grp->P, &grp->P, 1));
+    4687                 :          0 :     grp->pbits = mbedtls_mpi_bitlen(&grp->P);
+    4688                 :            : 
+    4689                 :            :     /* Y intentionally not set, since we use x/z coordinates.
+    4690                 :            :      * This is used as a marker to identify Montgomery curves! */
+    4691         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&grp->G.X, 5));
+    4692         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&grp->G.Z, 1));
+    4693                 :          0 :     mbedtls_mpi_free(&grp->G.Y);
+    4694                 :            : 
+    4695                 :            :     /* N = 2^446 - 13818066809895115352007386748515426880336692474882178609894547503885 */
+    4696         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_set_bit(&grp->N, 446, 1));
+    4697         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&Ns,
+    4698                 :            :                                             curve448_part_of_n, sizeof(curve448_part_of_n)));
+    4699         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&grp->N, &grp->N, &Ns));
+    4700                 :            : 
+    4701                 :            :     /* Actually, the required msb for private keys */
+    4702                 :          0 :     grp->nbits = 447;
+    4703                 :            : 
+    4704                 :          0 : cleanup:
+    4705                 :          0 :     mbedtls_mpi_free(&Ns);
+    4706         [ #  # ]:          0 :     if (ret != 0) {
+    4707                 :          0 :         mbedtls_ecp_group_free(grp);
+    4708                 :            :     }
+    4709                 :            : 
+    4710                 :          0 :     return ret;
+    4711                 :            : }
+    4712                 :            : #endif /* MBEDTLS_ECP_DP_CURVE448_ENABLED */
+    4713                 :            : 
+    4714                 :            : /*
+    4715                 :            :  * Set a group using well-known domain parameters
+    4716                 :            :  */
+    4717                 :      12462 : int mbedtls_ecp_group_load(mbedtls_ecp_group *grp, mbedtls_ecp_group_id id)
+    4718                 :            : {
+    4719                 :      12462 :     mbedtls_ecp_group_free(grp);
+    4720                 :            : 
+    4721                 :      12462 :     mbedtls_ecp_group_init(grp);
+    4722                 :            : 
+    4723                 :      12462 :     grp->id = id;
+    4724                 :            : 
+    4725   [ -  -  +  +  :      12462 :     switch (id) {
+          +  -  -  -  -  
+             -  -  -  - ]
+    4726                 :            : #if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED)
+    4727                 :          0 :         case MBEDTLS_ECP_DP_SECP192R1:
+    4728                 :          0 :             NIST_MODP(p192);
+    4729                 :          0 :             return LOAD_GROUP(secp192r1);
+    4730                 :            : #endif /* MBEDTLS_ECP_DP_SECP192R1_ENABLED */
+    4731                 :            : 
+    4732                 :            : #if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED)
+    4733                 :          0 :         case MBEDTLS_ECP_DP_SECP224R1:
+    4734                 :          0 :             NIST_MODP(p224);
+    4735                 :          0 :             return LOAD_GROUP(secp224r1);
+    4736                 :            : #endif /* MBEDTLS_ECP_DP_SECP224R1_ENABLED */
+    4737                 :            : 
+    4738                 :            : #if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED)
+    4739                 :      12436 :         case MBEDTLS_ECP_DP_SECP256R1:
+    4740                 :      12436 :             NIST_MODP(p256);
+    4741                 :      12436 :             return LOAD_GROUP(secp256r1);
+    4742                 :            : #endif /* MBEDTLS_ECP_DP_SECP256R1_ENABLED */
+    4743                 :            : 
+    4744                 :            : #if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED)
+    4745                 :         13 :         case MBEDTLS_ECP_DP_SECP384R1:
+    4746                 :         13 :             NIST_MODP(p384);
+    4747                 :         13 :             return LOAD_GROUP(secp384r1);
+    4748                 :            : #endif /* MBEDTLS_ECP_DP_SECP384R1_ENABLED */
+    4749                 :            : 
+    4750                 :            : #if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED)
+    4751                 :         13 :         case MBEDTLS_ECP_DP_SECP521R1:
+    4752                 :         13 :             NIST_MODP(p521);
+    4753                 :         13 :             return LOAD_GROUP(secp521r1);
+    4754                 :            : #endif /* MBEDTLS_ECP_DP_SECP521R1_ENABLED */
+    4755                 :            : 
+    4756                 :            : #if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED)
+    4757                 :          0 :         case MBEDTLS_ECP_DP_SECP192K1:
+    4758                 :          0 :             grp->modp = ecp_mod_p192k1;
+    4759                 :          0 :             return LOAD_GROUP_A(secp192k1);
+    4760                 :            : #endif /* MBEDTLS_ECP_DP_SECP192K1_ENABLED */
+    4761                 :            : 
+    4762                 :            : #if defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED)
+    4763                 :            :         case MBEDTLS_ECP_DP_SECP224K1:
+    4764                 :            :             grp->modp = ecp_mod_p224k1;
+    4765                 :            :             return LOAD_GROUP_A(secp224k1);
+    4766                 :            : #endif /* MBEDTLS_ECP_DP_SECP224K1_ENABLED */
+    4767                 :            : 
+    4768                 :            : #if defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED)
+    4769                 :          0 :         case MBEDTLS_ECP_DP_SECP256K1:
+    4770                 :          0 :             grp->modp = ecp_mod_p256k1;
+    4771                 :          0 :             return LOAD_GROUP_A(secp256k1);
+    4772                 :            : #endif /* MBEDTLS_ECP_DP_SECP256K1_ENABLED */
+    4773                 :            : 
+    4774                 :            : #if defined(MBEDTLS_ECP_DP_BP256R1_ENABLED)
+    4775                 :          0 :         case MBEDTLS_ECP_DP_BP256R1:
+    4776                 :          0 :             return LOAD_GROUP_A(brainpoolP256r1);
+    4777                 :            : #endif /* MBEDTLS_ECP_DP_BP256R1_ENABLED */
+    4778                 :            : 
+    4779                 :            : #if defined(MBEDTLS_ECP_DP_BP384R1_ENABLED)
+    4780                 :          0 :         case MBEDTLS_ECP_DP_BP384R1:
+    4781                 :          0 :             return LOAD_GROUP_A(brainpoolP384r1);
+    4782                 :            : #endif /* MBEDTLS_ECP_DP_BP384R1_ENABLED */
+    4783                 :            : 
+    4784                 :            : #if defined(MBEDTLS_ECP_DP_BP512R1_ENABLED)
+    4785                 :          0 :         case MBEDTLS_ECP_DP_BP512R1:
+    4786                 :          0 :             return LOAD_GROUP_A(brainpoolP512r1);
+    4787                 :            : #endif /* MBEDTLS_ECP_DP_BP512R1_ENABLED */
+    4788                 :            : 
+    4789                 :            : #if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED)
+    4790                 :          0 :         case MBEDTLS_ECP_DP_CURVE25519:
+    4791                 :          0 :             grp->modp = ecp_mod_p255;
+    4792                 :          0 :             return ecp_use_curve25519(grp);
+    4793                 :            : #endif /* MBEDTLS_ECP_DP_CURVE25519_ENABLED */
+    4794                 :            : 
+    4795                 :            : #if defined(MBEDTLS_ECP_DP_CURVE448_ENABLED)
+    4796                 :          0 :         case MBEDTLS_ECP_DP_CURVE448:
+    4797                 :          0 :             grp->modp = ecp_mod_p448;
+    4798                 :          0 :             return ecp_use_curve448(grp);
+    4799                 :            : #endif /* MBEDTLS_ECP_DP_CURVE448_ENABLED */
+    4800                 :            : 
+    4801                 :          0 :         default:
+    4802                 :          0 :             grp->id = MBEDTLS_ECP_DP_NONE;
+    4803                 :          0 :             return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
+    4804                 :            :     }
+    4805                 :            : }
+    4806                 :            : 
+    4807                 :            : #if defined(MBEDTLS_ECP_NIST_OPTIM)
+    4808                 :            : /*
+    4809                 :            :  * Fast reduction modulo the primes used by the NIST curves.
+    4810                 :            :  *
+    4811                 :            :  * These functions are critical for speed, but not needed for correct
+    4812                 :            :  * operations. So, we make the choice to heavily rely on the internals of our
+    4813                 :            :  * bignum library, which creates a tight coupling between these functions and
+    4814                 :            :  * our MPI implementation.  However, the coupling between the ECP module and
+    4815                 :            :  * MPI remains loose, since these functions can be deactivated at will.
+    4816                 :            :  */
+    4817                 :            : 
+    4818                 :            : #if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED)
+    4819                 :            : /*
+    4820                 :            :  * Compared to the way things are presented in FIPS 186-3 D.2,
+    4821                 :            :  * we proceed in columns, from right (least significant chunk) to left,
+    4822                 :            :  * adding chunks to N in place, and keeping a carry for the next chunk.
+    4823                 :            :  * This avoids moving things around in memory, and uselessly adding zeros,
+    4824                 :            :  * compared to the more straightforward, line-oriented approach.
+    4825                 :            :  *
+    4826                 :            :  * For this prime we need to handle data in chunks of 64 bits.
+    4827                 :            :  * Since this is always a multiple of our basic mbedtls_mpi_uint, we can
+    4828                 :            :  * use a mbedtls_mpi_uint * to designate such a chunk, and small loops to handle it.
+    4829                 :            :  */
+    4830                 :            : 
+    4831                 :            : /* Add 64-bit chunks (dst += src) and update carry */
+    4832                 :          0 : static inline void add64(mbedtls_mpi_uint *dst, mbedtls_mpi_uint *src, mbedtls_mpi_uint *carry)
+    4833                 :            : {
+    4834                 :            :     unsigned char i;
+    4835                 :          0 :     mbedtls_mpi_uint c = 0;
+    4836         [ #  # ]:          0 :     for (i = 0; i < 8 / sizeof(mbedtls_mpi_uint); i++, dst++, src++) {
+    4837                 :          0 :         *dst += c;      c  = (*dst < c);
+    4838                 :          0 :         *dst += *src;   c += (*dst < *src);
+    4839                 :            :     }
+    4840                 :          0 :     *carry += c;
+    4841                 :          0 : }
+    4842                 :            : 
+    4843                 :            : /* Add carry to a 64-bit chunk and update carry */
+    4844                 :          0 : static inline void carry64(mbedtls_mpi_uint *dst, mbedtls_mpi_uint *carry)
+    4845                 :            : {
+    4846                 :            :     unsigned char i;
+    4847         [ #  # ]:          0 :     for (i = 0; i < 8 / sizeof(mbedtls_mpi_uint); i++, dst++) {
+    4848                 :          0 :         *dst += *carry;
+    4849                 :          0 :         *carry  = (*dst < *carry);
+    4850                 :            :     }
+    4851                 :          0 : }
+    4852                 :            : 
+    4853                 :            : #define WIDTH       8 / sizeof(mbedtls_mpi_uint)
+    4854                 :            : #define A(i)      N->p + (i) * WIDTH
+    4855                 :            : #define ADD(i)    add64(p, A(i), &c)
+    4856                 :            : #define NEXT        p += WIDTH; carry64(p, &c)
+    4857                 :            : #define LAST        p += WIDTH; *p = c; while (++p < end) *p = 0
+    4858                 :            : 
+    4859                 :            : /*
+    4860                 :            :  * Fast quasi-reduction modulo p192 (FIPS 186-3 D.2.1)
+    4861                 :            :  */
+    4862                 :          0 : static int ecp_mod_p192(mbedtls_mpi *N)
+    4863                 :            : {
+    4864                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    4865                 :          0 :     mbedtls_mpi_uint c = 0;
+    4866                 :            :     mbedtls_mpi_uint *p, *end;
+    4867                 :            : 
+    4868                 :            :     /* Make sure we have enough blocks so that A(5) is legal */
+    4869         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_grow(N, 6 * WIDTH));
+    4870                 :            : 
+    4871                 :          0 :     p = N->p;
+    4872                 :          0 :     end = p + N->n;
+    4873                 :            : 
+    4874                 :          0 :     ADD(3); ADD(5);             NEXT;     // A0 += A3 + A5
+    4875                 :          0 :     ADD(3); ADD(4); ADD(5);   NEXT;       // A1 += A3 + A4 + A5
+    4876         [ #  # ]:          0 :     ADD(4); ADD(5);             LAST;     // A2 += A4 + A5
+    4877                 :            : 
+    4878                 :          0 : cleanup:
+    4879                 :          0 :     return ret;
+    4880                 :            : }
+    4881                 :            : 
+    4882                 :            : #undef WIDTH
+    4883                 :            : #undef A
+    4884                 :            : #undef ADD
+    4885                 :            : #undef NEXT
+    4886                 :            : #undef LAST
+    4887                 :            : #endif /* MBEDTLS_ECP_DP_SECP192R1_ENABLED */
+    4888                 :            : 
+    4889                 :            : #if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) ||   \
+    4890                 :            :     defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) ||   \
+    4891                 :            :     defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED)
+    4892                 :            : /*
+    4893                 :            :  * The reader is advised to first understand ecp_mod_p192() since the same
+    4894                 :            :  * general structure is used here, but with additional complications:
+    4895                 :            :  * (1) chunks of 32 bits, and (2) subtractions.
+    4896                 :            :  */
+    4897                 :            : 
+    4898                 :            : /*
+    4899                 :            :  * For these primes, we need to handle data in chunks of 32 bits.
+    4900                 :            :  * This makes it more complicated if we use 64 bits limbs in MPI,
+    4901                 :            :  * which prevents us from using a uniform access method as for p192.
+    4902                 :            :  *
+    4903                 :            :  * So, we define a mini abstraction layer to access 32 bit chunks,
+    4904                 :            :  * load them in 'cur' for work, and store them back from 'cur' when done.
+    4905                 :            :  *
+    4906                 :            :  * While at it, also define the size of N in terms of 32-bit chunks.
+    4907                 :            :  */
+    4908                 :            : #define LOAD32      cur = A(i);
+    4909                 :            : 
+    4910                 :            : #if defined(MBEDTLS_HAVE_INT32)  /* 32 bit */
+    4911                 :            : 
+    4912                 :            : #define MAX32       N->n
+    4913                 :            : #define A(j)      N->p[j]
+    4914                 :            : #define STORE32     N->p[i] = cur;
+    4915                 :            : 
+    4916                 :            : #else                               /* 64-bit */
+    4917                 :            : 
+    4918                 :            : #define MAX32       N->n * 2
+    4919                 :            : #define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
+    4920                 :            :     (uint32_t) (N->p[(j)/2])
+    4921                 :            : #define STORE32                                   \
+    4922                 :            :     if (i % 2) {                                 \
+    4923                 :            :         N->p[i/2] &= 0x00000000FFFFFFFF;          \
+    4924                 :            :         N->p[i/2] |= ((mbedtls_mpi_uint) cur) << 32;        \
+    4925                 :            :     } else {                                      \
+    4926                 :            :         N->p[i/2] &= 0xFFFFFFFF00000000;          \
+    4927                 :            :         N->p[i/2] |= (mbedtls_mpi_uint) cur;                \
+    4928                 :            :     }
+    4929                 :            : 
+    4930                 :            : #endif /* sizeof( mbedtls_mpi_uint ) */
+    4931                 :            : 
+    4932                 :            : /*
+    4933                 :            :  * Helpers for addition and subtraction of chunks, with signed carry.
+    4934                 :            :  */
+    4935                 :  217671944 : static inline void add32(uint32_t *dst, uint32_t src, signed char *carry)
+    4936                 :            : {
+    4937                 :  217671944 :     *dst += src;
+    4938                 :  217671944 :     *carry += (*dst < src);
+    4939                 :  217671944 : }
+    4940                 :            : 
+    4941                 :  156187790 : static inline void sub32(uint32_t *dst, uint32_t src, signed char *carry)
+    4942                 :            : {
+    4943                 :  156187790 :     *carry -= (*dst < src);
+    4944                 :  156187790 :     *dst -= src;
+    4945                 :  156187790 : }
+    4946                 :            : 
+    4947                 :            : #define ADD(j)    add32(&cur, A(j), &c);
+    4948                 :            : #define SUB(j)    sub32(&cur, A(j), &c);
+    4949                 :            : 
+    4950                 :            : /*
+    4951                 :            :  * Helpers for the main 'loop'
+    4952                 :            :  */
+    4953                 :            : #define INIT(b)                                                       \
+    4954                 :            :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;                    \
+    4955                 :            :     signed char c = 0, cc;                                              \
+    4956                 :            :     uint32_t cur;                                                       \
+    4957                 :            :     size_t i = 0, bits = (b);                                           \
+    4958                 :            :     /* N is the size of the product of two b-bit numbers, plus one */   \
+    4959                 :            :     /* limb for fix_negative */                                         \
+    4960                 :            :     MBEDTLS_MPI_CHK(mbedtls_mpi_grow(N, (b) * 2 / biL + 1));      \
+    4961                 :            :     LOAD32;
+    4962                 :            : 
+    4963                 :            : #define NEXT                    \
+    4964                 :            :     STORE32; i++; LOAD32;       \
+    4965                 :            :     cc = c; c = 0;              \
+    4966                 :            :     if (cc < 0)                \
+    4967                 :            :     sub32(&cur, -cc, &c); \
+    4968                 :            :     else                        \
+    4969                 :            :     add32(&cur, cc, &c);  \
+    4970                 :            : 
+    4971                 :            : #define LAST                                    \
+    4972                 :            :     STORE32; i++;                               \
+    4973                 :            :     cur = c > 0 ? c : 0; STORE32;               \
+    4974                 :            :     cur = 0; while (++i < MAX32) { STORE32; }  \
+    4975                 :            :     if (c < 0) mbedtls_ecp_fix_negative(N, c, bits);
+    4976                 :            : 
+    4977                 :            : /*
+    4978                 :            :  * If the result is negative, we get it in the form
+    4979                 :            :  * c * 2^bits + N, with c negative and N positive shorter than 'bits'
+    4980                 :            :  */
+    4981                 :    3467998 : static void mbedtls_ecp_fix_negative(mbedtls_mpi *N, signed char c, size_t bits)
+    4982                 :            : {
+    4983                 :            :     size_t i;
+    4984                 :            : 
+    4985                 :            :     /* Set N := 2^bits - 1 - N. We know that 0 <= N < 2^bits, so
+    4986                 :            :      * set the absolute value to 0xfff...fff - N. There is no carry
+    4987                 :            :      * since we're subtracting from all-bits-one.  */
+    4988         [ +  + ]:   20807988 :     for (i = 0; i <= bits / 8 / sizeof(mbedtls_mpi_uint); i++) {
+    4989                 :   17339990 :         N->p[i] = ~(mbedtls_mpi_uint) 0 - N->p[i];
+    4990                 :            :     }
+    4991                 :            :     /* Add 1, taking care of the carry. */
+    4992                 :    3467998 :     i = 0;
+    4993                 :            :     do {
+    4994                 :    3467998 :         ++N->p[i];
+    4995   [ -  +  -  - ]:    3467998 :     } while (N->p[i++] == 0 && i <= bits / 8 / sizeof(mbedtls_mpi_uint));
+    4996                 :            :     /* Invert the sign.
+    4997                 :            :      * Now N = N0 - 2^bits where N0 is the initial value of N. */
+    4998                 :    3467998 :     N->s = -1;
+    4999                 :            : 
+    5000                 :            :     /* Add |c| * 2^bits to the absolute value. Since c and N are
+    5001                 :            :      * negative, this adds c * 2^bits. */
+    5002                 :    3467998 :     mbedtls_mpi_uint msw = (mbedtls_mpi_uint) -c;
+    5003                 :            : #if defined(MBEDTLS_HAVE_INT64)
+    5004         [ -  + ]:    3467998 :     if (bits == 224) {
+    5005                 :          0 :         msw <<= 32;
+    5006                 :            :     }
+    5007                 :            : #endif
+    5008                 :    3467998 :     N->p[bits / 8 / sizeof(mbedtls_mpi_uint)] += msw;
+    5009                 :    3467998 : }
+    5010                 :            : 
+    5011                 :            : #if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED)
+    5012                 :            : /*
+    5013                 :            :  * Fast quasi-reduction modulo p224 (FIPS 186-3 D.2.2)
+    5014                 :            :  */
+    5015                 :          0 : static int ecp_mod_p224(mbedtls_mpi *N)
+    5016                 :            : {
+    5017   [ #  #  #  # ]:          0 :     INIT(224);
+    5018                 :            : 
+    5019   [ #  #  #  #  :          0 :     SUB(7); SUB(11);               NEXT;      // A0 += -A7 - A11
+                   #  # ]
+    5020   [ #  #  #  #  :          0 :     SUB(8); SUB(12);               NEXT;      // A1 += -A8 - A12
+                   #  # ]
+    5021   [ #  #  #  #  :          0 :     SUB(9); SUB(13);               NEXT;      // A2 += -A9 - A13
+                   #  # ]
+    5022   [ #  #  #  #  :          0 :     SUB(10); ADD(7); ADD(11);    NEXT;        // A3 += -A10 + A7 + A11
+                   #  # ]
+    5023   [ #  #  #  #  :          0 :     SUB(11); ADD(8); ADD(12);    NEXT;        // A4 += -A11 + A8 + A12
+                   #  # ]
+    5024   [ #  #  #  #  :          0 :     SUB(12); ADD(9); ADD(13);    NEXT;        // A5 += -A12 + A9 + A13
+                   #  # ]
+    5025   [ #  #  #  #  :          0 :     SUB(13); ADD(10);               LAST;     // A6 += -A13 + A10
+          #  #  #  #  #  
+                      # ]
+    5026                 :            : 
+    5027                 :          0 : cleanup:
+    5028                 :          0 :     return ret;
+    5029                 :            : }
+    5030                 :            : #endif /* MBEDTLS_ECP_DP_SECP224R1_ENABLED */
+    5031                 :            : 
+    5032                 :            : #if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED)
+    5033                 :            : /*
+    5034                 :            :  * Fast quasi-reduction modulo p256 (FIPS 186-3 D.2.3)
+    5035                 :            :  */
+    5036                 :    6029951 : static int ecp_mod_p256(mbedtls_mpi *N)
+    5037                 :            : {
+    5038   [ -  +  -  + ]:    6029951 :     INIT(256);
+    5039                 :            : 
+    5040                 :    6029951 :     ADD(8); ADD(9);
+    5041   [ -  +  +  -  :    6029951 :     SUB(11); SUB(12); SUB(13); SUB(14);             NEXT;         // A0
+                   +  + ]
+    5042                 :            : 
+    5043                 :    6029951 :     ADD(9); ADD(10);
+    5044   [ +  -  -  +  :    6029951 :     SUB(12); SUB(13); SUB(14); SUB(15);             NEXT;         // A1
+                   +  + ]
+    5045                 :            : 
+    5046                 :    6029951 :     ADD(10); ADD(11);
+    5047   [ -  +  +  -  :    6029951 :     SUB(13); SUB(14); SUB(15);                        NEXT;       // A2
+                   +  + ]
+    5048                 :            : 
+    5049                 :    6029951 :     ADD(11); ADD(11); ADD(12); ADD(12); ADD(13);
+    5050   [ +  -  -  +  :    6029951 :     SUB(15); SUB(8); SUB(9);                        NEXT;         // A3
+                   +  + ]
+    5051                 :            : 
+    5052                 :    6029951 :     ADD(12); ADD(12); ADD(13); ADD(13); ADD(14);
+    5053   [ -  +  +  -  :    6029951 :     SUB(9); SUB(10);                                   NEXT;      // A4
+                   +  + ]
+    5054                 :            : 
+    5055                 :    6029951 :     ADD(13); ADD(13); ADD(14); ADD(14); ADD(15);
+    5056   [ +  -  -  +  :    6029951 :     SUB(10); SUB(11);                                   NEXT;     // A5
+                   +  + ]
+    5057                 :            : 
+    5058                 :    6029951 :     ADD(14); ADD(14); ADD(15); ADD(15); ADD(14); ADD(13);
+    5059   [ -  +  +  -  :    6029951 :     SUB(8); SUB(9);                                   NEXT;       // A6
+                   +  + ]
+    5060                 :            : 
+    5061                 :    6029951 :     ADD(15); ADD(15); ADD(15); ADD(8);
+    5062   [ +  -  -  +  :   60299510 :     SUB(10); SUB(11); SUB(12); SUB(13);             LAST;         // A7
+          +  +  +  +  +  
+                      + ]
+    5063                 :            : 
+    5064                 :    2561953 : cleanup:
+    5065                 :    6029951 :     return ret;
+    5066                 :            : }
+    5067                 :            : #endif /* MBEDTLS_ECP_DP_SECP256R1_ENABLED */
+    5068                 :            : 
+    5069                 :            : #if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED)
+    5070                 :            : /*
+    5071                 :            :  * Fast quasi-reduction modulo p384 (FIPS 186-3 D.2.4)
+    5072                 :            :  */
+    5073                 :         36 : static int ecp_mod_p384(mbedtls_mpi *N)
+    5074                 :            : {
+    5075   [ -  +  -  + ]:         36 :     INIT(384);
+    5076                 :            : 
+    5077                 :         36 :     ADD(12); ADD(21); ADD(20);
+    5078   [ -  +  +  -  :         36 :     SUB(23);                                              NEXT;   // A0
+                   -  + ]
+    5079                 :            : 
+    5080                 :         36 :     ADD(13); ADD(22); ADD(23);
+    5081   [ +  -  -  +  :         36 :     SUB(12); SUB(20);                                   NEXT;     // A2
+                   -  + ]
+    5082                 :            : 
+    5083                 :         36 :     ADD(14); ADD(23);
+    5084   [ -  +  +  -  :         36 :     SUB(13); SUB(21);                                   NEXT;     // A2
+                   +  - ]
+    5085                 :            : 
+    5086                 :         36 :     ADD(15); ADD(12); ADD(20); ADD(21);
+    5087   [ +  -  -  +  :         36 :     SUB(14); SUB(22); SUB(23);                        NEXT;       // A3
+                   -  + ]
+    5088                 :            : 
+    5089                 :         36 :     ADD(21); ADD(21); ADD(16); ADD(13); ADD(12); ADD(20); ADD(22);
+    5090   [ -  +  +  -  :         36 :     SUB(15); SUB(23); SUB(23);                        NEXT;       // A4
+                   -  + ]
+    5091                 :            : 
+    5092                 :         36 :     ADD(22); ADD(22); ADD(17); ADD(14); ADD(13); ADD(21); ADD(23);
+    5093   [ +  -  -  +  :         36 :     SUB(16);                                              NEXT;   // A5
+                   -  + ]
+    5094                 :            : 
+    5095                 :         36 :     ADD(23); ADD(23); ADD(18); ADD(15); ADD(14); ADD(22);
+    5096   [ -  +  +  -  :         36 :     SUB(17);                                              NEXT;   // A6
+                   -  + ]
+    5097                 :            : 
+    5098                 :         36 :     ADD(19); ADD(16); ADD(15); ADD(23);
+    5099   [ +  -  -  +  :         36 :     SUB(18);                                              NEXT;   // A7
+                   -  + ]
+    5100                 :            : 
+    5101                 :         36 :     ADD(20); ADD(17); ADD(16);
+    5102   [ -  +  +  -  :         36 :     SUB(19);                                              NEXT;   // A8
+                   -  + ]
+    5103                 :            : 
+    5104                 :         36 :     ADD(21); ADD(18); ADD(17);
+    5105   [ +  -  -  +  :         36 :     SUB(20);                                              NEXT;   // A9
+                   -  + ]
+    5106                 :            : 
+    5107                 :         36 :     ADD(22); ADD(19); ADD(18);
+    5108   [ -  +  +  -  :         36 :     SUB(21);                                              NEXT;   // A10
+                   -  + ]
+    5109                 :            : 
+    5110                 :         36 :     ADD(23); ADD(20); ADD(19);
+    5111   [ +  -  -  +  :        504 :     SUB(22);                                              LAST;   // A11
+          +  +  +  +  +  
+                      - ]
+    5112                 :            : 
+    5113                 :         36 : cleanup:
+    5114                 :         36 :     return ret;
+    5115                 :            : }
+    5116                 :            : #endif /* MBEDTLS_ECP_DP_SECP384R1_ENABLED */
+    5117                 :            : 
+    5118                 :            : #undef A
+    5119                 :            : #undef LOAD32
+    5120                 :            : #undef STORE32
+    5121                 :            : #undef MAX32
+    5122                 :            : #undef INIT
+    5123                 :            : #undef NEXT
+    5124                 :            : #undef LAST
+    5125                 :            : 
+    5126                 :            : #endif /* MBEDTLS_ECP_DP_SECP224R1_ENABLED ||
+    5127                 :            :           MBEDTLS_ECP_DP_SECP256R1_ENABLED ||
+    5128                 :            :           MBEDTLS_ECP_DP_SECP384R1_ENABLED */
+    5129                 :            : 
+    5130                 :            : #if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED)
+    5131                 :            : /*
+    5132                 :            :  * Here we have an actual Mersenne prime, so things are more straightforward.
+    5133                 :            :  * However, chunks are aligned on a 'weird' boundary (521 bits).
+    5134                 :            :  */
+    5135                 :            : 
+    5136                 :            : /* Size of p521 in terms of mbedtls_mpi_uint */
+    5137                 :            : #define P521_WIDTH      (521 / 8 / sizeof(mbedtls_mpi_uint) + 1)
+    5138                 :            : 
+    5139                 :            : /* Bits to keep in the most significant mbedtls_mpi_uint */
+    5140                 :            : #define P521_MASK       0x01FF
+    5141                 :            : 
+    5142                 :            : /*
+    5143                 :            :  * Fast quasi-reduction modulo p521 (FIPS 186-3 D.2.5)
+    5144                 :            :  * Write N as A1 + 2^521 A0, return A0 + A1
+    5145                 :            :  */
+    5146                 :         36 : static int ecp_mod_p521(mbedtls_mpi *N)
+    5147                 :            : {
+    5148                 :         36 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    5149                 :            :     size_t i;
+    5150                 :            :     mbedtls_mpi M;
+    5151                 :            :     mbedtls_mpi_uint Mp[P521_WIDTH + 1];
+    5152                 :            :     /* Worst case for the size of M is when mbedtls_mpi_uint is 16 bits:
+    5153                 :            :      * we need to hold bits 513 to 1056, which is 34 limbs, that is
+    5154                 :            :      * P521_WIDTH + 1. Otherwise P521_WIDTH is enough. */
+    5155                 :            : 
+    5156         [ -  + ]:         36 :     if (N->n < P521_WIDTH) {
+    5157                 :          0 :         return 0;
+    5158                 :            :     }
+    5159                 :            : 
+    5160                 :            :     /* M = A1 */
+    5161                 :         36 :     M.s = 1;
+    5162                 :         36 :     M.n = N->n - (P521_WIDTH - 1);
+    5163         [ -  + ]:         36 :     if (M.n > P521_WIDTH + 1) {
+    5164                 :          0 :         M.n = P521_WIDTH + 1;
+    5165                 :            :     }
+    5166                 :         36 :     M.p = Mp;
+    5167                 :         36 :     memcpy(Mp, N->p + P521_WIDTH - 1, M.n * sizeof(mbedtls_mpi_uint));
+    5168         [ -  + ]:         36 :     MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&M, 521 % (8 * sizeof(mbedtls_mpi_uint))));
+    5169                 :            : 
+    5170                 :            :     /* N = A0 */
+    5171                 :         36 :     N->p[P521_WIDTH - 1] &= P521_MASK;
+    5172         [ +  + ]:        360 :     for (i = P521_WIDTH; i < N->n; i++) {
+    5173                 :        324 :         N->p[i] = 0;
+    5174                 :            :     }
+    5175                 :            : 
+    5176                 :            :     /* N = A0 + A1 */
+    5177         [ +  - ]:         36 :     MBEDTLS_MPI_CHK(mbedtls_mpi_add_abs(N, N, &M));
+    5178                 :            : 
+    5179                 :         36 : cleanup:
+    5180                 :         36 :     return ret;
+    5181                 :            : }
+    5182                 :            : 
+    5183                 :            : #undef P521_WIDTH
+    5184                 :            : #undef P521_MASK
+    5185                 :            : #endif /* MBEDTLS_ECP_DP_SECP521R1_ENABLED */
+    5186                 :            : 
+    5187                 :            : #endif /* MBEDTLS_ECP_NIST_OPTIM */
+    5188                 :            : 
+    5189                 :            : #if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED)
+    5190                 :            : 
+    5191                 :            : /* Size of p255 in terms of mbedtls_mpi_uint */
+    5192                 :            : #define P255_WIDTH      (255 / 8 / sizeof(mbedtls_mpi_uint) + 1)
+    5193                 :            : 
+    5194                 :            : /*
+    5195                 :            :  * Fast quasi-reduction modulo p255 = 2^255 - 19
+    5196                 :            :  * Write N as A0 + 2^256 A1, return A0 + 38 * A1
+    5197                 :            :  */
+    5198                 :          0 : static int ecp_mod_p255(mbedtls_mpi *N)
+    5199                 :            : {
+    5200                 :            :     mbedtls_mpi_uint Mp[P255_WIDTH];
+    5201                 :            : 
+    5202                 :            :     /* Helper references for top part of N */
+    5203                 :          0 :     mbedtls_mpi_uint * const NT_p = N->p + P255_WIDTH;
+    5204                 :          0 :     const size_t NT_n = N->n - P255_WIDTH;
+    5205         [ #  # ]:          0 :     if (N->n <= P255_WIDTH) {
+    5206                 :          0 :         return 0;
+    5207                 :            :     }
+    5208         [ #  # ]:          0 :     if (NT_n > P255_WIDTH) {
+    5209                 :          0 :         return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+    5210                 :            :     }
+    5211                 :            : 
+    5212                 :            :     /* Split N as N + 2^256 M */
+    5213                 :          0 :     memcpy(Mp,   NT_p, sizeof(mbedtls_mpi_uint) * NT_n);
+    5214                 :          0 :     memset(NT_p, 0,    sizeof(mbedtls_mpi_uint) * NT_n);
+    5215                 :            : 
+    5216                 :            :     /* N = A0 + 38 * A1 */
+    5217                 :          0 :     mbedtls_mpi_core_mla(N->p, P255_WIDTH + 1,
+    5218                 :            :                          Mp, NT_n,
+    5219                 :            :                          38);
+    5220                 :            : 
+    5221                 :          0 :     return 0;
+    5222                 :            : }
+    5223                 :            : #endif /* MBEDTLS_ECP_DP_CURVE25519_ENABLED */
+    5224                 :            : 
+    5225                 :            : #if defined(MBEDTLS_ECP_DP_CURVE448_ENABLED)
+    5226                 :            : 
+    5227                 :            : /* Size of p448 in terms of mbedtls_mpi_uint */
+    5228                 :            : #define P448_WIDTH      (448 / 8 / sizeof(mbedtls_mpi_uint))
+    5229                 :            : 
+    5230                 :            : /* Number of limbs fully occupied by 2^224 (max), and limbs used by it (min) */
+    5231                 :            : #define DIV_ROUND_UP(X, Y) (((X) + (Y) -1) / (Y))
+    5232                 :            : #define P224_SIZE        (224 / 8)
+    5233                 :            : #define P224_WIDTH_MIN   (P224_SIZE / sizeof(mbedtls_mpi_uint))
+    5234                 :            : #define P224_WIDTH_MAX   DIV_ROUND_UP(P224_SIZE, sizeof(mbedtls_mpi_uint))
+    5235                 :            : #define P224_UNUSED_BITS ((P224_WIDTH_MAX * sizeof(mbedtls_mpi_uint) * 8) - 224)
+    5236                 :            : 
+    5237                 :            : /*
+    5238                 :            :  * Fast quasi-reduction modulo p448 = 2^448 - 2^224 - 1
+    5239                 :            :  * Write N as A0 + 2^448 A1 and A1 as B0 + 2^224 B1, and return
+    5240                 :            :  * A0 + A1 + B1 + (B0 + B1) * 2^224.  This is different to the reference
+    5241                 :            :  * implementation of Curve448, which uses its own special 56-bit limbs rather
+    5242                 :            :  * than a generic bignum library.  We could squeeze some extra speed out on
+    5243                 :            :  * 32-bit machines by splitting N up into 32-bit limbs and doing the
+    5244                 :            :  * arithmetic using the limbs directly as we do for the NIST primes above,
+    5245                 :            :  * but for 64-bit targets it should use half the number of operations if we do
+    5246                 :            :  * the reduction with 224-bit limbs, since mpi_add_mpi will then use 64-bit adds.
+    5247                 :            :  */
+    5248                 :          0 : static int ecp_mod_p448(mbedtls_mpi *N)
+    5249                 :            : {
+    5250                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    5251                 :            :     size_t i;
+    5252                 :            :     mbedtls_mpi M, Q;
+    5253                 :            :     mbedtls_mpi_uint Mp[P448_WIDTH + 1], Qp[P448_WIDTH];
+    5254                 :            : 
+    5255         [ #  # ]:          0 :     if (N->n <= P448_WIDTH) {
+    5256                 :          0 :         return 0;
+    5257                 :            :     }
+    5258                 :            : 
+    5259                 :            :     /* M = A1 */
+    5260                 :          0 :     M.s = 1;
+    5261                 :          0 :     M.n = N->n - (P448_WIDTH);
+    5262         [ #  # ]:          0 :     if (M.n > P448_WIDTH) {
+    5263                 :            :         /* Shouldn't be called with N larger than 2^896! */
+    5264                 :          0 :         return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+    5265                 :            :     }
+    5266                 :          0 :     M.p = Mp;
+    5267                 :          0 :     memset(Mp, 0, sizeof(Mp));
+    5268                 :          0 :     memcpy(Mp, N->p + P448_WIDTH, M.n * sizeof(mbedtls_mpi_uint));
+    5269                 :            : 
+    5270                 :            :     /* N = A0 */
+    5271         [ #  # ]:          0 :     for (i = P448_WIDTH; i < N->n; i++) {
+    5272                 :          0 :         N->p[i] = 0;
+    5273                 :            :     }
+    5274                 :            : 
+    5275                 :            :     /* N += A1 */
+    5276         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(N, N, &M));
+    5277                 :            : 
+    5278                 :            :     /* Q = B1, N += B1 */
+    5279                 :          0 :     Q = M;
+    5280                 :          0 :     Q.p = Qp;
+    5281                 :          0 :     memcpy(Qp, Mp, sizeof(Qp));
+    5282         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&Q, 224));
+    5283         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(N, N, &Q));
+    5284                 :            : 
+    5285                 :            :     /* M = (B0 + B1) * 2^224, N += M */
+    5286                 :            :     if (sizeof(mbedtls_mpi_uint) > 4) {
+    5287                 :          0 :         Mp[P224_WIDTH_MIN] &= ((mbedtls_mpi_uint)-1) >> (P224_UNUSED_BITS);
+    5288                 :            :     }
+    5289         [ #  # ]:          0 :     for (i = P224_WIDTH_MAX; i < M.n; ++i) {
+    5290                 :          0 :         Mp[i] = 0;
+    5291                 :            :     }
+    5292         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&M, &M, &Q));
+    5293                 :          0 :     M.n = P448_WIDTH + 1; /* Make room for shifted carry bit from the addition */
+    5294         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(&M, 224));
+    5295         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(N, N, &M));
+    5296                 :            : 
+    5297                 :          0 : cleanup:
+    5298                 :          0 :     return ret;
+    5299                 :            : }
+    5300                 :            : #endif /* MBEDTLS_ECP_DP_CURVE448_ENABLED */
+    5301                 :            : 
+    5302                 :            : #if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED) ||   \
+    5303                 :            :     defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED) ||   \
+    5304                 :            :     defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED)
+    5305                 :            : /*
+    5306                 :            :  * Fast quasi-reduction modulo P = 2^s - R,
+    5307                 :            :  * with R about 33 bits, used by the Koblitz curves.
+    5308                 :            :  *
+    5309                 :            :  * Write N as A0 + 2^224 A1, return A0 + R * A1.
+    5310                 :            :  * Actually do two passes, since R is big.
+    5311                 :            :  */
+    5312                 :            : #define P_KOBLITZ_MAX   (256 / 8 / sizeof(mbedtls_mpi_uint))      // Max limbs in P
+    5313                 :            : #define P_KOBLITZ_R     (8 / sizeof(mbedtls_mpi_uint))            // Limbs in R
+    5314                 :          0 : static inline int ecp_mod_koblitz(mbedtls_mpi *N, const mbedtls_mpi_uint *Rp, size_t p_limbs,
+    5315                 :            :                                   size_t adjust, size_t shift, mbedtls_mpi_uint mask)
+    5316                 :            : {
+    5317                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    5318                 :            :     size_t i;
+    5319                 :            :     mbedtls_mpi M, R;
+    5320                 :            :     mbedtls_mpi_uint Mp[P_KOBLITZ_MAX + P_KOBLITZ_R + 1];
+    5321                 :            : 
+    5322         [ #  # ]:          0 :     if (N->n < p_limbs) {
+    5323                 :          0 :         return 0;
+    5324                 :            :     }
+    5325                 :            : 
+    5326                 :            :     /* Init R */
+    5327                 :          0 :     R.s = 1;
+    5328                 :          0 :     R.p = (mbedtls_mpi_uint *) Rp; /* R.p will not be modified so the cast is safe */
+    5329                 :          0 :     R.n = P_KOBLITZ_R;
+    5330                 :            : 
+    5331                 :            :     /* Common setup for M */
+    5332                 :          0 :     M.s = 1;
+    5333                 :          0 :     M.p = Mp;
+    5334                 :            : 
+    5335                 :            :     /* M = A1 */
+    5336                 :          0 :     M.n = (unsigned short) (N->n - (p_limbs - adjust));
+    5337         [ #  # ]:          0 :     if (M.n > p_limbs + adjust) {
+    5338                 :          0 :         M.n = (unsigned short) (p_limbs + adjust);
+    5339                 :            :     }
+    5340                 :          0 :     memset(Mp, 0, sizeof(Mp));
+    5341                 :          0 :     memcpy(Mp, N->p + p_limbs - adjust, M.n * sizeof(mbedtls_mpi_uint));
+    5342         [ #  # ]:          0 :     if (shift != 0) {
+    5343         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&M, shift));
+    5344                 :            :     }
+    5345                 :          0 :     M.n += R.n; /* Make room for multiplication by R */
+    5346                 :            : 
+    5347                 :            :     /* N = A0 */
+    5348         [ #  # ]:          0 :     if (mask != 0) {
+    5349                 :          0 :         N->p[p_limbs - 1] &= mask;
+    5350                 :            :     }
+    5351         [ #  # ]:          0 :     for (i = p_limbs; i < N->n; i++) {
+    5352                 :          0 :         N->p[i] = 0;
+    5353                 :            :     }
+    5354                 :            : 
+    5355                 :            :     /* N = A0 + R * A1 */
+    5356         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&M, &M, &R));
+    5357         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_add_abs(N, N, &M));
+    5358                 :            : 
+    5359                 :            :     /* Second pass */
+    5360                 :            : 
+    5361                 :            :     /* M = A1 */
+    5362                 :          0 :     M.n = (unsigned short) (N->n - (p_limbs - adjust));
+    5363         [ #  # ]:          0 :     if (M.n > p_limbs + adjust) {
+    5364                 :          0 :         M.n = (unsigned short) (p_limbs + adjust);
+    5365                 :            :     }
+    5366                 :          0 :     memset(Mp, 0, sizeof(Mp));
+    5367                 :          0 :     memcpy(Mp, N->p + p_limbs - adjust, M.n * sizeof(mbedtls_mpi_uint));
+    5368         [ #  # ]:          0 :     if (shift != 0) {
+    5369         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&M, shift));
+    5370                 :            :     }
+    5371                 :          0 :     M.n += R.n; /* Make room for multiplication by R */
+    5372                 :            : 
+    5373                 :            :     /* N = A0 */
+    5374         [ #  # ]:          0 :     if (mask != 0) {
+    5375                 :          0 :         N->p[p_limbs - 1] &= mask;
+    5376                 :            :     }
+    5377         [ #  # ]:          0 :     for (i = p_limbs; i < N->n; i++) {
+    5378                 :          0 :         N->p[i] = 0;
+    5379                 :            :     }
+    5380                 :            : 
+    5381                 :            :     /* N = A0 + R * A1 */
+    5382         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&M, &M, &R));
+    5383         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_add_abs(N, N, &M));
+    5384                 :            : 
+    5385                 :          0 : cleanup:
+    5386                 :          0 :     return ret;
+    5387                 :            : }
+    5388                 :            : #endif /* MBEDTLS_ECP_DP_SECP192K1_ENABLED) ||
+    5389                 :            :           MBEDTLS_ECP_DP_SECP224K1_ENABLED) ||
+    5390                 :            :           MBEDTLS_ECP_DP_SECP256K1_ENABLED) */
+    5391                 :            : 
+    5392                 :            : #if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED)
+    5393                 :            : /*
+    5394                 :            :  * Fast quasi-reduction modulo p192k1 = 2^192 - R,
+    5395                 :            :  * with R = 2^32 + 2^12 + 2^8 + 2^7 + 2^6 + 2^3 + 1 = 0x01000011C9
+    5396                 :            :  */
+    5397                 :          0 : static int ecp_mod_p192k1(mbedtls_mpi *N)
+    5398                 :            : {
+    5399                 :            :     static const mbedtls_mpi_uint Rp[] = {
+    5400                 :            :         MBEDTLS_BYTES_TO_T_UINT_8(0xC9, 0x11, 0x00, 0x00, 0x01, 0x00, 0x00,
+    5401                 :            :                                   0x00)
+    5402                 :            :     };
+    5403                 :            : 
+    5404                 :          0 :     return ecp_mod_koblitz(N, Rp, 192 / 8 / sizeof(mbedtls_mpi_uint), 0, 0,
+    5405                 :            :                            0);
+    5406                 :            : }
+    5407                 :            : #endif /* MBEDTLS_ECP_DP_SECP192K1_ENABLED */
+    5408                 :            : 
+    5409                 :            : #if defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED)
+    5410                 :            : /*
+    5411                 :            :  * Fast quasi-reduction modulo p224k1 = 2^224 - R,
+    5412                 :            :  * with R = 2^32 + 2^12 + 2^11 + 2^9 + 2^7 + 2^4 + 2 + 1 = 0x0100001A93
+    5413                 :            :  */
+    5414                 :            : static int ecp_mod_p224k1(mbedtls_mpi *N)
+    5415                 :            : {
+    5416                 :            :     static const mbedtls_mpi_uint Rp[] = {
+    5417                 :            :         MBEDTLS_BYTES_TO_T_UINT_8(0x93, 0x1A, 0x00, 0x00, 0x01, 0x00, 0x00,
+    5418                 :            :                                   0x00)
+    5419                 :            :     };
+    5420                 :            : 
+    5421                 :            : #if defined(MBEDTLS_HAVE_INT64)
+    5422                 :            :     return ecp_mod_koblitz(N, Rp, 4, 1, 32, 0xFFFFFFFF);
+    5423                 :            : #else
+    5424                 :            :     return ecp_mod_koblitz(N, Rp, 224 / 8 / sizeof(mbedtls_mpi_uint), 0, 0,
+    5425                 :            :                            0);
+    5426                 :            : #endif
+    5427                 :            : }
+    5428                 :            : 
+    5429                 :            : #endif /* MBEDTLS_ECP_DP_SECP224K1_ENABLED */
+    5430                 :            : 
+    5431                 :            : #if defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED)
+    5432                 :            : /*
+    5433                 :            :  * Fast quasi-reduction modulo p256k1 = 2^256 - R,
+    5434                 :            :  * with R = 2^32 + 2^9 + 2^8 + 2^7 + 2^6 + 2^4 + 1 = 0x01000003D1
+    5435                 :            :  */
+    5436                 :          0 : static int ecp_mod_p256k1(mbedtls_mpi *N)
+    5437                 :            : {
+    5438                 :            :     static const mbedtls_mpi_uint Rp[] = {
+    5439                 :            :         MBEDTLS_BYTES_TO_T_UINT_8(0xD1, 0x03, 0x00, 0x00, 0x01, 0x00, 0x00,
+    5440                 :            :                                   0x00)
+    5441                 :            :     };
+    5442                 :          0 :     return ecp_mod_koblitz(N, Rp, 256 / 8 / sizeof(mbedtls_mpi_uint), 0, 0,
+    5443                 :            :                            0);
+    5444                 :            : }
+    5445                 :            : #endif /* MBEDTLS_ECP_DP_SECP256K1_ENABLED */
+    5446                 :            : 
+    5447                 :            : #if defined(MBEDTLS_TEST_HOOKS)
+    5448                 :            : 
+    5449                 :            : MBEDTLS_STATIC_TESTABLE
+    5450                 :            : mbedtls_ecp_variant mbedtls_ecp_get_variant(void)
+    5451                 :            : {
+    5452                 :            :     return MBEDTLS_ECP_VARIANT_WITH_MPI_STRUCT;
+    5453                 :            : }
+    5454                 :            : 
+    5455                 :            : #endif /* MBEDTLS_TEST_HOOKS */
+    5456                 :            : 
+    5457                 :            : #endif /* !MBEDTLS_ECP_ALT */
+    5458                 :            : 
+    5459                 :            : #endif /* MBEDTLS_ECP_LIGHT */
+    5460                 :            : #endif /* MBEDTLS_ECP_WITH_MPI_UINT */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/gcm.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/gcm.c.func-sort-c.html new file mode 100644 index 00000000000..a97290c6b2c --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/gcm.c.func-sort-c.html @@ -0,0 +1,149 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/gcm.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - gcm.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:14942734.9 %
Date:2024-09-22 08:21:07Functions:141782.4 %
Branches:5822925.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
gcm_gen_table_rightshift0
gcm_mult_smalltable0
mbedtls_gcm_self_test0
mbedtls_gcm_auth_decrypt326
gcm_gen_table791
gcm_set_acceleration791
mbedtls_gcm_crypt_and_tag791
mbedtls_gcm_finish791
mbedtls_gcm_free791
mbedtls_gcm_init791
mbedtls_gcm_setkey791
mbedtls_gcm_starts791
mbedtls_gcm_update791
mbedtls_gcm_update_ad791
gcm_incr2072
gcm_mask2072
gcm_mult3658
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/gcm.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/gcm.c.func.html new file mode 100644 index 00000000000..a873e1bc40b --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/gcm.c.func.html @@ -0,0 +1,149 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/gcm.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - gcm.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:14942734.9 %
Date:2024-09-22 08:21:07Functions:141782.4 %
Branches:5822925.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
gcm_gen_table791
gcm_gen_table_rightshift0
gcm_incr2072
gcm_mask2072
gcm_mult3658
gcm_mult_smalltable0
gcm_set_acceleration791
mbedtls_gcm_auth_decrypt326
mbedtls_gcm_crypt_and_tag791
mbedtls_gcm_finish791
mbedtls_gcm_free791
mbedtls_gcm_init791
mbedtls_gcm_self_test0
mbedtls_gcm_setkey791
mbedtls_gcm_starts791
mbedtls_gcm_update791
mbedtls_gcm_update_ad791
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/gcm.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/gcm.c.gcov.html new file mode 100644 index 00000000000..4afba794ec4 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/gcm.c.gcov.html @@ -0,0 +1,1416 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/gcm.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - gcm.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:14942734.9 %
Date:2024-09-22 08:21:07Functions:141782.4 %
Branches:5822925.3 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  *  NIST SP800-38D compliant GCM implementation
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  */
+       7                 :            : 
+       8                 :            : /*
+       9                 :            :  * http://csrc.nist.gov/publications/nistpubs/800-38D/SP-800-38D.pdf
+      10                 :            :  *
+      11                 :            :  * See also:
+      12                 :            :  * [MGV] http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/gcm/gcm-revised-spec.pdf
+      13                 :            :  *
+      14                 :            :  * We use the algorithm described as Shoup's method with 4-bit tables in
+      15                 :            :  * [MGV] 4.1, pp. 12-13, to enhance speed without using too much memory.
+      16                 :            :  */
+      17                 :            : 
+      18                 :            : #include "common.h"
+      19                 :            : 
+      20                 :            : #if defined(MBEDTLS_GCM_C)
+      21                 :            : 
+      22                 :            : #include "mbedtls/gcm.h"
+      23                 :            : #include "mbedtls/platform.h"
+      24                 :            : #include "mbedtls/platform_util.h"
+      25                 :            : #include "mbedtls/error.h"
+      26                 :            : #include "mbedtls/constant_time.h"
+      27                 :            : 
+      28                 :            : #if defined(MBEDTLS_BLOCK_CIPHER_C)
+      29                 :            : #include "block_cipher_internal.h"
+      30                 :            : #endif
+      31                 :            : 
+      32                 :            : #include <string.h>
+      33                 :            : 
+      34                 :            : #if defined(MBEDTLS_AESNI_C)
+      35                 :            : #include "aesni.h"
+      36                 :            : #endif
+      37                 :            : 
+      38                 :            : #if defined(MBEDTLS_AESCE_C)
+      39                 :            : #include "aesce.h"
+      40                 :            : #endif
+      41                 :            : 
+      42                 :            : #if !defined(MBEDTLS_GCM_ALT)
+      43                 :            : 
+      44                 :            : /* Used to select the acceleration mechanism */
+      45                 :            : #define MBEDTLS_GCM_ACC_SMALLTABLE  0
+      46                 :            : #define MBEDTLS_GCM_ACC_LARGETABLE  1
+      47                 :            : #define MBEDTLS_GCM_ACC_AESNI       2
+      48                 :            : #define MBEDTLS_GCM_ACC_AESCE       3
+      49                 :            : 
+      50                 :            : /*
+      51                 :            :  * Initialize a context
+      52                 :            :  */
+      53                 :        791 : void mbedtls_gcm_init(mbedtls_gcm_context *ctx)
+      54                 :            : {
+      55                 :        791 :     memset(ctx, 0, sizeof(mbedtls_gcm_context));
+      56                 :        791 : }
+      57                 :            : 
+      58                 :        791 : static inline void gcm_set_acceleration(mbedtls_gcm_context *ctx)
+      59                 :            : {
+      60                 :            : #if defined(MBEDTLS_GCM_LARGE_TABLE)
+      61                 :            :     ctx->acceleration = MBEDTLS_GCM_ACC_LARGETABLE;
+      62                 :            : #else
+      63                 :        791 :     ctx->acceleration = MBEDTLS_GCM_ACC_SMALLTABLE;
+      64                 :            : #endif
+      65                 :            : 
+      66                 :            : #if defined(MBEDTLS_AESNI_HAVE_CODE)
+      67                 :            :     /* With CLMUL support, we need only h, not the rest of the table */
+      68         [ +  - ]:        791 :     if (mbedtls_aesni_has_support(MBEDTLS_AESNI_CLMUL)) {
+      69                 :        791 :         ctx->acceleration = MBEDTLS_GCM_ACC_AESNI;
+      70                 :            :     }
+      71                 :            : #endif
+      72                 :            : 
+      73                 :            : #if defined(MBEDTLS_AESCE_HAVE_CODE)
+      74                 :            :     if (MBEDTLS_AESCE_HAS_SUPPORT()) {
+      75                 :            :         ctx->acceleration = MBEDTLS_GCM_ACC_AESCE;
+      76                 :            :     }
+      77                 :            : #endif
+      78                 :        791 : }
+      79                 :            : 
+      80                 :          0 : static inline void gcm_gen_table_rightshift(uint64_t dst[2], const uint64_t src[2])
+      81                 :            : {
+      82                 :          0 :     uint8_t *u8Dst = (uint8_t *) dst;
+      83                 :          0 :     uint8_t *u8Src = (uint8_t *) src;
+      84                 :            : 
+      85                 :          0 :     MBEDTLS_PUT_UINT64_BE(MBEDTLS_GET_UINT64_BE(&src[1], 0) >> 1, &dst[1], 0);
+      86                 :          0 :     u8Dst[8] |= (u8Src[7] & 0x01) << 7;
+      87                 :          0 :     MBEDTLS_PUT_UINT64_BE(MBEDTLS_GET_UINT64_BE(&src[0], 0) >> 1, &dst[0], 0);
+      88         [ #  # ]:          0 :     u8Dst[0] ^= (u8Src[15] & 0x01) ? 0xE1 : 0;
+      89                 :          0 : }
+      90                 :            : 
+      91                 :            : /*
+      92                 :            :  * Precompute small multiples of H, that is set
+      93                 :            :  *      HH[i] || HL[i] = H times i,
+      94                 :            :  * where i is seen as a field element as in [MGV], ie high-order bits
+      95                 :            :  * correspond to low powers of P. The result is stored in the same way, that
+      96                 :            :  * is the high-order bit of HH corresponds to P^0 and the low-order bit of HL
+      97                 :            :  * corresponds to P^127.
+      98                 :            :  */
+      99                 :        791 : static int gcm_gen_table(mbedtls_gcm_context *ctx)
+     100                 :            : {
+     101                 :            :     int ret, i, j;
+     102                 :        791 :     uint64_t u64h[2] = { 0 };
+     103                 :        791 :     uint8_t *h = (uint8_t *) u64h;
+     104                 :            : 
+     105                 :            : #if defined(MBEDTLS_BLOCK_CIPHER_C)
+     106                 :            :     ret = mbedtls_block_cipher_encrypt(&ctx->block_cipher_ctx, h, h);
+     107                 :            : #else
+     108                 :        791 :     size_t olen = 0;
+     109                 :        791 :     ret = mbedtls_cipher_update(&ctx->cipher_ctx, h, 16, h, &olen);
+     110                 :            : #endif
+     111         [ -  + ]:        791 :     if (ret != 0) {
+     112                 :          0 :         return ret;
+     113                 :            :     }
+     114                 :            : 
+     115                 :        791 :     gcm_set_acceleration(ctx);
+     116                 :            : 
+     117                 :            :     /* MBEDTLS_GCM_HTABLE_SIZE/2 = 1000 corresponds to 1 in GF(2^128) */
+     118                 :        791 :     ctx->H[MBEDTLS_GCM_HTABLE_SIZE/2][0] = u64h[0];
+     119                 :        791 :     ctx->H[MBEDTLS_GCM_HTABLE_SIZE/2][1] = u64h[1];
+     120                 :            : 
+     121         [ +  - ]:        791 :     switch (ctx->acceleration) {
+     122                 :            : #if defined(MBEDTLS_AESNI_HAVE_CODE)
+     123                 :        791 :         case MBEDTLS_GCM_ACC_AESNI:
+     124                 :        791 :             return 0;
+     125                 :            : #endif
+     126                 :            : 
+     127                 :            : #if defined(MBEDTLS_AESCE_HAVE_CODE)
+     128                 :            :         case MBEDTLS_GCM_ACC_AESCE:
+     129                 :            :             return 0;
+     130                 :            : #endif
+     131                 :            : 
+     132                 :          0 :         default:
+     133                 :            :             /* 0 corresponds to 0 in GF(2^128) */
+     134                 :          0 :             ctx->H[0][0] = 0;
+     135                 :          0 :             ctx->H[0][1] = 0;
+     136                 :            : 
+     137         [ #  # ]:          0 :             for (i = MBEDTLS_GCM_HTABLE_SIZE/4; i > 0; i >>= 1) {
+     138                 :          0 :                 gcm_gen_table_rightshift(ctx->H[i], ctx->H[i*2]);
+     139                 :            :             }
+     140                 :            : 
+     141                 :            : #if !defined(MBEDTLS_GCM_LARGE_TABLE)
+     142                 :            :             /* pack elements of H as 64-bits ints, big-endian */
+     143         [ #  # ]:          0 :             for (i = MBEDTLS_GCM_HTABLE_SIZE/2; i > 0; i >>= 1) {
+     144                 :          0 :                 MBEDTLS_PUT_UINT64_BE(ctx->H[i][0], &ctx->H[i][0], 0);
+     145                 :          0 :                 MBEDTLS_PUT_UINT64_BE(ctx->H[i][1], &ctx->H[i][1], 0);
+     146                 :            :             }
+     147                 :            : #endif
+     148                 :            : 
+     149         [ #  # ]:          0 :             for (i = 2; i < MBEDTLS_GCM_HTABLE_SIZE; i <<= 1) {
+     150         [ #  # ]:          0 :                 for (j = 1; j < i; j++) {
+     151                 :          0 :                     mbedtls_xor_no_simd((unsigned char *) ctx->H[i+j],
+     152                 :          0 :                                         (unsigned char *) ctx->H[i],
+     153                 :          0 :                                         (unsigned char *) ctx->H[j],
+     154                 :            :                                         16);
+     155                 :            :                 }
+     156                 :            :             }
+     157                 :            :     }
+     158                 :            : 
+     159                 :          0 :     return 0;
+     160                 :            : }
+     161                 :            : 
+     162                 :        791 : int mbedtls_gcm_setkey(mbedtls_gcm_context *ctx,
+     163                 :            :                        mbedtls_cipher_id_t cipher,
+     164                 :            :                        const unsigned char *key,
+     165                 :            :                        unsigned int keybits)
+     166                 :            : {
+     167                 :        791 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     168                 :            : 
+     169   [ +  +  +  -  :        791 :     if (keybits != 128 && keybits != 192 && keybits != 256) {
+                   -  + ]
+     170                 :          0 :         return MBEDTLS_ERR_GCM_BAD_INPUT;
+     171                 :            :     }
+     172                 :            : 
+     173                 :            : #if defined(MBEDTLS_BLOCK_CIPHER_C)
+     174                 :            :     mbedtls_block_cipher_free(&ctx->block_cipher_ctx);
+     175                 :            : 
+     176                 :            :     if ((ret = mbedtls_block_cipher_setup(&ctx->block_cipher_ctx, cipher)) != 0) {
+     177                 :            :         return ret;
+     178                 :            :     }
+     179                 :            : 
+     180                 :            :     if ((ret = mbedtls_block_cipher_setkey(&ctx->block_cipher_ctx, key, keybits)) != 0) {
+     181                 :            :         return ret;
+     182                 :            :     }
+     183                 :            : #else
+     184                 :            :     const mbedtls_cipher_info_t *cipher_info;
+     185                 :            : 
+     186                 :        791 :     cipher_info = mbedtls_cipher_info_from_values(cipher, keybits,
+     187                 :            :                                                   MBEDTLS_MODE_ECB);
+     188         [ -  + ]:        791 :     if (cipher_info == NULL) {
+     189                 :          0 :         return MBEDTLS_ERR_GCM_BAD_INPUT;
+     190                 :            :     }
+     191                 :            : 
+     192         [ -  + ]:        791 :     if (mbedtls_cipher_info_get_block_size(cipher_info) != 16) {
+     193                 :          0 :         return MBEDTLS_ERR_GCM_BAD_INPUT;
+     194                 :            :     }
+     195                 :            : 
+     196                 :        791 :     mbedtls_cipher_free(&ctx->cipher_ctx);
+     197                 :            : 
+     198         [ -  + ]:        791 :     if ((ret = mbedtls_cipher_setup(&ctx->cipher_ctx, cipher_info)) != 0) {
+     199                 :          0 :         return ret;
+     200                 :            :     }
+     201                 :            : 
+     202         [ -  + ]:        791 :     if ((ret = mbedtls_cipher_setkey(&ctx->cipher_ctx, key, keybits,
+     203                 :            :                                      MBEDTLS_ENCRYPT)) != 0) {
+     204                 :          0 :         return ret;
+     205                 :            :     }
+     206                 :            : #endif
+     207                 :            : 
+     208         [ -  + ]:        791 :     if ((ret = gcm_gen_table(ctx)) != 0) {
+     209                 :          0 :         return ret;
+     210                 :            :     }
+     211                 :            : 
+     212                 :        791 :     return 0;
+     213                 :            : }
+     214                 :            : 
+     215                 :            : #if defined(MBEDTLS_GCM_LARGE_TABLE)
+     216                 :            : static const uint16_t last8[256] = {
+     217                 :            :     0x0000, 0xc201, 0x8403, 0x4602, 0x0807, 0xca06, 0x8c04, 0x4e05,
+     218                 :            :     0x100e, 0xd20f, 0x940d, 0x560c, 0x1809, 0xda08, 0x9c0a, 0x5e0b,
+     219                 :            :     0x201c, 0xe21d, 0xa41f, 0x661e, 0x281b, 0xea1a, 0xac18, 0x6e19,
+     220                 :            :     0x3012, 0xf213, 0xb411, 0x7610, 0x3815, 0xfa14, 0xbc16, 0x7e17,
+     221                 :            :     0x4038, 0x8239, 0xc43b, 0x063a, 0x483f, 0x8a3e, 0xcc3c, 0x0e3d,
+     222                 :            :     0x5036, 0x9237, 0xd435, 0x1634, 0x5831, 0x9a30, 0xdc32, 0x1e33,
+     223                 :            :     0x6024, 0xa225, 0xe427, 0x2626, 0x6823, 0xaa22, 0xec20, 0x2e21,
+     224                 :            :     0x702a, 0xb22b, 0xf429, 0x3628, 0x782d, 0xba2c, 0xfc2e, 0x3e2f,
+     225                 :            :     0x8070, 0x4271, 0x0473, 0xc672, 0x8877, 0x4a76, 0x0c74, 0xce75,
+     226                 :            :     0x907e, 0x527f, 0x147d, 0xd67c, 0x9879, 0x5a78, 0x1c7a, 0xde7b,
+     227                 :            :     0xa06c, 0x626d, 0x246f, 0xe66e, 0xa86b, 0x6a6a, 0x2c68, 0xee69,
+     228                 :            :     0xb062, 0x7263, 0x3461, 0xf660, 0xb865, 0x7a64, 0x3c66, 0xfe67,
+     229                 :            :     0xc048, 0x0249, 0x444b, 0x864a, 0xc84f, 0x0a4e, 0x4c4c, 0x8e4d,
+     230                 :            :     0xd046, 0x1247, 0x5445, 0x9644, 0xd841, 0x1a40, 0x5c42, 0x9e43,
+     231                 :            :     0xe054, 0x2255, 0x6457, 0xa656, 0xe853, 0x2a52, 0x6c50, 0xae51,
+     232                 :            :     0xf05a, 0x325b, 0x7459, 0xb658, 0xf85d, 0x3a5c, 0x7c5e, 0xbe5f,
+     233                 :            :     0x00e1, 0xc2e0, 0x84e2, 0x46e3, 0x08e6, 0xcae7, 0x8ce5, 0x4ee4,
+     234                 :            :     0x10ef, 0xd2ee, 0x94ec, 0x56ed, 0x18e8, 0xdae9, 0x9ceb, 0x5eea,
+     235                 :            :     0x20fd, 0xe2fc, 0xa4fe, 0x66ff, 0x28fa, 0xeafb, 0xacf9, 0x6ef8,
+     236                 :            :     0x30f3, 0xf2f2, 0xb4f0, 0x76f1, 0x38f4, 0xfaf5, 0xbcf7, 0x7ef6,
+     237                 :            :     0x40d9, 0x82d8, 0xc4da, 0x06db, 0x48de, 0x8adf, 0xccdd, 0x0edc,
+     238                 :            :     0x50d7, 0x92d6, 0xd4d4, 0x16d5, 0x58d0, 0x9ad1, 0xdcd3, 0x1ed2,
+     239                 :            :     0x60c5, 0xa2c4, 0xe4c6, 0x26c7, 0x68c2, 0xaac3, 0xecc1, 0x2ec0,
+     240                 :            :     0x70cb, 0xb2ca, 0xf4c8, 0x36c9, 0x78cc, 0xbacd, 0xfccf, 0x3ece,
+     241                 :            :     0x8091, 0x4290, 0x0492, 0xc693, 0x8896, 0x4a97, 0x0c95, 0xce94,
+     242                 :            :     0x909f, 0x529e, 0x149c, 0xd69d, 0x9898, 0x5a99, 0x1c9b, 0xde9a,
+     243                 :            :     0xa08d, 0x628c, 0x248e, 0xe68f, 0xa88a, 0x6a8b, 0x2c89, 0xee88,
+     244                 :            :     0xb083, 0x7282, 0x3480, 0xf681, 0xb884, 0x7a85, 0x3c87, 0xfe86,
+     245                 :            :     0xc0a9, 0x02a8, 0x44aa, 0x86ab, 0xc8ae, 0x0aaf, 0x4cad, 0x8eac,
+     246                 :            :     0xd0a7, 0x12a6, 0x54a4, 0x96a5, 0xd8a0, 0x1aa1, 0x5ca3, 0x9ea2,
+     247                 :            :     0xe0b5, 0x22b4, 0x64b6, 0xa6b7, 0xe8b2, 0x2ab3, 0x6cb1, 0xaeb0,
+     248                 :            :     0xf0bb, 0x32ba, 0x74b8, 0xb6b9, 0xf8bc, 0x3abd, 0x7cbf, 0xbebe
+     249                 :            : };
+     250                 :            : 
+     251                 :            : static void gcm_mult_largetable(uint8_t *output, const uint8_t *x, uint64_t H[256][2])
+     252                 :            : {
+     253                 :            :     int i;
+     254                 :            :     uint64_t u64z[2];
+     255                 :            :     uint16_t *u16z = (uint16_t *) u64z;
+     256                 :            :     uint8_t *u8z = (uint8_t *) u64z;
+     257                 :            :     uint8_t rem;
+     258                 :            : 
+     259                 :            :     u64z[0] = 0;
+     260                 :            :     u64z[1] = 0;
+     261                 :            : 
+     262                 :            :     if (MBEDTLS_IS_BIG_ENDIAN) {
+     263                 :            :         for (i = 15; i > 0; i--) {
+     264                 :            :             mbedtls_xor_no_simd(u8z, u8z, (uint8_t *) H[x[i]], 16);
+     265                 :            :             rem = u8z[15];
+     266                 :            : 
+     267                 :            :             u64z[1] >>= 8;
+     268                 :            :             u8z[8] = u8z[7];
+     269                 :            :             u64z[0] >>= 8;
+     270                 :            : 
+     271                 :            :             u16z[0] ^= MBEDTLS_GET_UINT16_LE(&last8[rem], 0);
+     272                 :            :         }
+     273                 :            :     } else {
+     274                 :            :         for (i = 15; i > 0; i--) {
+     275                 :            :             mbedtls_xor_no_simd(u8z, u8z, (uint8_t *) H[x[i]], 16);
+     276                 :            :             rem = u8z[15];
+     277                 :            : 
+     278                 :            :             u64z[1] <<= 8;
+     279                 :            :             u8z[8] = u8z[7];
+     280                 :            :             u64z[0] <<= 8;
+     281                 :            : 
+     282                 :            :             u16z[0] ^= last8[rem];
+     283                 :            :         }
+     284                 :            :     }
+     285                 :            : 
+     286                 :            :     mbedtls_xor_no_simd(output, u8z, (uint8_t *) H[x[0]], 16);
+     287                 :            : }
+     288                 :            : #else
+     289                 :            : /*
+     290                 :            :  * Shoup's method for multiplication use this table with
+     291                 :            :  *      last4[x] = x times P^128
+     292                 :            :  * where x and last4[x] are seen as elements of GF(2^128) as in [MGV]
+     293                 :            :  */
+     294                 :            : static const uint16_t last4[16] =
+     295                 :            : {
+     296                 :            :     0x0000, 0x1c20, 0x3840, 0x2460,
+     297                 :            :     0x7080, 0x6ca0, 0x48c0, 0x54e0,
+     298                 :            :     0xe100, 0xfd20, 0xd940, 0xc560,
+     299                 :            :     0x9180, 0x8da0, 0xa9c0, 0xb5e0
+     300                 :            : };
+     301                 :            : 
+     302                 :          0 : static void gcm_mult_smalltable(uint8_t *output, const uint8_t *x, uint64_t H[16][2])
+     303                 :            : {
+     304                 :          0 :     int i = 0;
+     305                 :            :     unsigned char lo, hi, rem;
+     306                 :            :     uint64_t u64z[2];
+     307                 :          0 :     const uint64_t *pu64z = NULL;
+     308                 :          0 :     uint8_t *u8z = (uint8_t *) u64z;
+     309                 :            : 
+     310                 :          0 :     lo = x[15] & 0xf;
+     311                 :          0 :     hi = (x[15] >> 4) & 0xf;
+     312                 :            : 
+     313                 :          0 :     pu64z = H[lo];
+     314                 :            : 
+     315                 :          0 :     rem = (unsigned char) pu64z[1] & 0xf;
+     316                 :          0 :     u64z[1] = (pu64z[0] << 60) | (pu64z[1] >> 4);
+     317                 :          0 :     u64z[0] = (pu64z[0] >> 4);
+     318                 :          0 :     u64z[0] ^= (uint64_t) last4[rem] << 48;
+     319                 :          0 :     mbedtls_xor_no_simd(u8z, u8z, (uint8_t *) H[hi], 16);
+     320                 :            : 
+     321         [ #  # ]:          0 :     for (i = 14; i >= 0; i--) {
+     322                 :          0 :         lo = x[i] & 0xf;
+     323                 :          0 :         hi = (x[i] >> 4) & 0xf;
+     324                 :            : 
+     325                 :          0 :         rem = (unsigned char) u64z[1] & 0xf;
+     326                 :          0 :         u64z[1] = (u64z[0] << 60) | (u64z[1] >> 4);
+     327                 :          0 :         u64z[0] = (u64z[0] >> 4);
+     328                 :          0 :         u64z[0] ^= (uint64_t) last4[rem] << 48;
+     329                 :          0 :         mbedtls_xor_no_simd(u8z, u8z, (uint8_t *) H[lo], 16);
+     330                 :            : 
+     331                 :          0 :         rem = (unsigned char) u64z[1] & 0xf;
+     332                 :          0 :         u64z[1] = (u64z[0] << 60) | (u64z[1] >> 4);
+     333                 :          0 :         u64z[0] = (u64z[0] >> 4);
+     334                 :          0 :         u64z[0] ^= (uint64_t) last4[rem] << 48;
+     335                 :          0 :         mbedtls_xor_no_simd(u8z, u8z, (uint8_t *) H[hi], 16);
+     336                 :            :     }
+     337                 :            : 
+     338                 :          0 :     MBEDTLS_PUT_UINT64_BE(u64z[0], output, 0);
+     339                 :          0 :     MBEDTLS_PUT_UINT64_BE(u64z[1], output, 8);
+     340                 :          0 : }
+     341                 :            : #endif
+     342                 :            : 
+     343                 :            : /*
+     344                 :            :  * Sets output to x times H using the precomputed tables.
+     345                 :            :  * x and output are seen as elements of GF(2^128) as in [MGV].
+     346                 :            :  */
+     347                 :       3658 : static void gcm_mult(mbedtls_gcm_context *ctx, const unsigned char x[16],
+     348                 :            :                      unsigned char output[16])
+     349                 :            : {
+     350      [ +  -  - ]:       3658 :     switch (ctx->acceleration) {
+     351                 :            : #if defined(MBEDTLS_AESNI_HAVE_CODE)
+     352                 :       3658 :         case MBEDTLS_GCM_ACC_AESNI:
+     353                 :       3658 :             mbedtls_aesni_gcm_mult(output, x, (uint8_t *) ctx->H[MBEDTLS_GCM_HTABLE_SIZE/2]);
+     354                 :       3658 :             break;
+     355                 :            : #endif
+     356                 :            : 
+     357                 :            : #if defined(MBEDTLS_AESCE_HAVE_CODE)
+     358                 :            :         case MBEDTLS_GCM_ACC_AESCE:
+     359                 :            :             mbedtls_aesce_gcm_mult(output, x, (uint8_t *) ctx->H[MBEDTLS_GCM_HTABLE_SIZE/2]);
+     360                 :            :             break;
+     361                 :            : #endif
+     362                 :            : 
+     363                 :            : #if defined(MBEDTLS_GCM_LARGE_TABLE)
+     364                 :            :         case MBEDTLS_GCM_ACC_LARGETABLE:
+     365                 :            :             gcm_mult_largetable(output, x, ctx->H);
+     366                 :            :             break;
+     367                 :            : #else
+     368                 :          0 :         case MBEDTLS_GCM_ACC_SMALLTABLE:
+     369                 :          0 :             gcm_mult_smalltable(output, x, ctx->H);
+     370                 :          0 :             break;
+     371                 :            : #endif
+     372                 :            :     }
+     373                 :            : 
+     374                 :       3658 :     return;
+     375                 :            : }
+     376                 :            : 
+     377                 :        791 : int mbedtls_gcm_starts(mbedtls_gcm_context *ctx,
+     378                 :            :                        int mode,
+     379                 :            :                        const unsigned char *iv, size_t iv_len)
+     380                 :            : {
+     381                 :        791 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     382                 :            :     unsigned char work_buf[16];
+     383                 :            :     const unsigned char *p;
+     384                 :            :     size_t use_len;
+     385                 :            :     uint64_t iv_bits;
+     386                 :            : #if !defined(MBEDTLS_BLOCK_CIPHER_C)
+     387                 :        791 :     size_t olen = 0;
+     388                 :            : #endif
+     389                 :            : 
+     390                 :            :     /* IV is limited to 2^64 bits, so 2^61 bytes */
+     391                 :            :     /* IV is not allowed to be zero length */
+     392   [ +  -  -  + ]:        791 :     if (iv_len == 0 || (uint64_t) iv_len >> 61 != 0) {
+     393                 :          0 :         return MBEDTLS_ERR_GCM_BAD_INPUT;
+     394                 :            :     }
+     395                 :            : 
+     396                 :        791 :     memset(ctx->y, 0x00, sizeof(ctx->y));
+     397                 :        791 :     memset(ctx->buf, 0x00, sizeof(ctx->buf));
+     398                 :            : 
+     399                 :        791 :     ctx->mode = mode;
+     400                 :        791 :     ctx->len = 0;
+     401                 :        791 :     ctx->add_len = 0;
+     402                 :            : 
+     403         [ +  - ]:        791 :     if (iv_len == 12) {
+     404                 :        791 :         memcpy(ctx->y, iv, iv_len);
+     405                 :        791 :         ctx->y[15] = 1;
+     406                 :            :     } else {
+     407                 :          0 :         memset(work_buf, 0x00, 16);
+     408                 :          0 :         iv_bits = (uint64_t) iv_len * 8;
+     409                 :          0 :         MBEDTLS_PUT_UINT64_BE(iv_bits, work_buf, 8);
+     410                 :            : 
+     411                 :          0 :         p = iv;
+     412         [ #  # ]:          0 :         while (iv_len > 0) {
+     413                 :          0 :             use_len = (iv_len < 16) ? iv_len : 16;
+     414                 :            : 
+     415                 :            : #if defined(MBEDTLS_COMPILER_IS_GCC) && (MBEDTLS_GCC_VERSION >= 70110)
+     416                 :            : #pragma GCC diagnostic push
+     417                 :            : #pragma GCC diagnostic warning "-Wstringop-overflow=0"
+     418                 :            : #endif
+     419                 :            : 
+     420                 :          0 :             mbedtls_xor(ctx->y, ctx->y, p, use_len);
+     421                 :            : 
+     422                 :            : #if defined(MBEDTLS_COMPILER_IS_GCC) && (MBEDTLS_GCC_VERSION >= 70110)
+     423                 :            : #pragma GCC diagnostic pop
+     424                 :            : #endif
+     425                 :            : 
+     426                 :          0 :             gcm_mult(ctx, ctx->y, ctx->y);
+     427                 :            : 
+     428                 :          0 :             iv_len -= use_len;
+     429                 :          0 :             p += use_len;
+     430                 :            :         }
+     431                 :            : 
+     432                 :          0 :         mbedtls_xor(ctx->y, ctx->y, work_buf, 16);
+     433                 :            : 
+     434                 :          0 :         gcm_mult(ctx, ctx->y, ctx->y);
+     435                 :            :     }
+     436                 :            : 
+     437                 :            : 
+     438                 :            : #if defined(MBEDTLS_BLOCK_CIPHER_C)
+     439                 :            :     ret = mbedtls_block_cipher_encrypt(&ctx->block_cipher_ctx, ctx->y, ctx->base_ectr);
+     440                 :            : #else
+     441                 :        791 :     ret = mbedtls_cipher_update(&ctx->cipher_ctx, ctx->y, 16, ctx->base_ectr, &olen);
+     442                 :            : #endif
+     443         [ -  + ]:        791 :     if (ret != 0) {
+     444                 :          0 :         return ret;
+     445                 :            :     }
+     446                 :            : 
+     447                 :        791 :     return 0;
+     448                 :            : }
+     449                 :            : 
+     450                 :            : /**
+     451                 :            :  * mbedtls_gcm_context::buf contains the partial state of the computation of
+     452                 :            :  * the authentication tag.
+     453                 :            :  * mbedtls_gcm_context::add_len and mbedtls_gcm_context::len indicate
+     454                 :            :  * different stages of the computation:
+     455                 :            :  *     * len == 0 && add_len == 0:      initial state
+     456                 :            :  *     * len == 0 && add_len % 16 != 0: the first `add_len % 16` bytes have
+     457                 :            :  *                                      a partial block of AD that has been
+     458                 :            :  *                                      xored in but not yet multiplied in.
+     459                 :            :  *     * len == 0 && add_len % 16 == 0: the authentication tag is correct if
+     460                 :            :  *                                      the data ends now.
+     461                 :            :  *     * len % 16 != 0:                 the first `len % 16` bytes have
+     462                 :            :  *                                      a partial block of ciphertext that has
+     463                 :            :  *                                      been xored in but not yet multiplied in.
+     464                 :            :  *     * len > 0 && len % 16 == 0:      the authentication tag is correct if
+     465                 :            :  *                                      the data ends now.
+     466                 :            :  */
+     467                 :        791 : int mbedtls_gcm_update_ad(mbedtls_gcm_context *ctx,
+     468                 :            :                           const unsigned char *add, size_t add_len)
+     469                 :            : {
+     470                 :            :     const unsigned char *p;
+     471                 :            :     size_t use_len, offset;
+     472                 :            :     uint64_t new_add_len;
+     473                 :            : 
+     474                 :            :     /* AD is limited to 2^64 bits, ie 2^61 bytes
+     475                 :            :      * Also check for possible overflow */
+     476                 :            : #if SIZE_MAX > 0xFFFFFFFFFFFFFFFFULL
+     477                 :            :     if (add_len > 0xFFFFFFFFFFFFFFFFULL) {
+     478                 :            :         return MBEDTLS_ERR_GCM_BAD_INPUT;
+     479                 :            :     }
+     480                 :            : #endif
+     481                 :        791 :     new_add_len = ctx->add_len + (uint64_t) add_len;
+     482   [ +  -  -  + ]:        791 :     if (new_add_len < ctx->add_len || new_add_len >> 61 != 0) {
+     483                 :          0 :         return MBEDTLS_ERR_GCM_BAD_INPUT;
+     484                 :            :     }
+     485                 :            : 
+     486                 :        791 :     offset = ctx->add_len % 16;
+     487                 :        791 :     p = add;
+     488                 :            : 
+     489         [ -  + ]:        791 :     if (offset != 0) {
+     490                 :          0 :         use_len = 16 - offset;
+     491         [ #  # ]:          0 :         if (use_len > add_len) {
+     492                 :          0 :             use_len = add_len;
+     493                 :            :         }
+     494                 :            : 
+     495                 :          0 :         mbedtls_xor(ctx->buf + offset, ctx->buf + offset, p, use_len);
+     496                 :            : 
+     497         [ #  # ]:          0 :         if (offset + use_len == 16) {
+     498                 :          0 :             gcm_mult(ctx, ctx->buf, ctx->buf);
+     499                 :            :         }
+     500                 :            : 
+     501                 :          0 :         ctx->add_len += use_len;
+     502                 :          0 :         add_len -= use_len;
+     503                 :          0 :         p += use_len;
+     504                 :            :     }
+     505                 :            : 
+     506                 :        791 :     ctx->add_len += add_len;
+     507                 :            : 
+     508         [ +  + ]:        795 :     while (add_len >= 16) {
+     509                 :          4 :         mbedtls_xor(ctx->buf, ctx->buf, p, 16);
+     510                 :            : 
+     511                 :          4 :         gcm_mult(ctx, ctx->buf, ctx->buf);
+     512                 :            : 
+     513                 :          4 :         add_len -= 16;
+     514                 :          4 :         p += 16;
+     515                 :            :     }
+     516                 :            : 
+     517         [ +  - ]:        791 :     if (add_len > 0) {
+     518                 :        791 :         mbedtls_xor(ctx->buf, ctx->buf, p, add_len);
+     519                 :            :     }
+     520                 :            : 
+     521                 :        791 :     return 0;
+     522                 :            : }
+     523                 :            : 
+     524                 :            : /* Increment the counter. */
+     525                 :       2072 : static void gcm_incr(unsigned char y[16])
+     526                 :            : {
+     527                 :       2072 :     uint32_t x = MBEDTLS_GET_UINT32_BE(y, 12);
+     528                 :       2072 :     x++;
+     529                 :       2072 :     MBEDTLS_PUT_UINT32_BE(x, y, 12);
+     530                 :       2072 : }
+     531                 :            : 
+     532                 :            : /* Calculate and apply the encryption mask. Process use_len bytes of data,
+     533                 :            :  * starting at position offset in the mask block. */
+     534                 :       2072 : static int gcm_mask(mbedtls_gcm_context *ctx,
+     535                 :            :                     unsigned char ectr[16],
+     536                 :            :                     size_t offset, size_t use_len,
+     537                 :            :                     const unsigned char *input,
+     538                 :            :                     unsigned char *output)
+     539                 :            : {
+     540                 :       2072 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     541                 :            : 
+     542                 :            : #if defined(MBEDTLS_BLOCK_CIPHER_C)
+     543                 :            :     ret = mbedtls_block_cipher_encrypt(&ctx->block_cipher_ctx, ctx->y, ectr);
+     544                 :            : #else
+     545                 :       2072 :     size_t olen = 0;
+     546                 :       2072 :     ret = mbedtls_cipher_update(&ctx->cipher_ctx, ctx->y, 16, ectr, &olen);
+     547                 :            : #endif
+     548         [ -  + ]:       2072 :     if (ret != 0) {
+     549                 :          0 :         mbedtls_platform_zeroize(ectr, 16);
+     550                 :          0 :         return ret;
+     551                 :            :     }
+     552                 :            : 
+     553         [ +  + ]:       2072 :     if (ctx->mode == MBEDTLS_GCM_DECRYPT) {
+     554                 :        871 :         mbedtls_xor(ctx->buf + offset, ctx->buf + offset, input, use_len);
+     555                 :            :     }
+     556                 :       2072 :     mbedtls_xor(output, ectr + offset, input, use_len);
+     557         [ +  + ]:       2072 :     if (ctx->mode == MBEDTLS_GCM_ENCRYPT) {
+     558                 :       1201 :         mbedtls_xor(ctx->buf + offset, ctx->buf + offset, output, use_len);
+     559                 :            :     }
+     560                 :            : 
+     561                 :       2072 :     return 0;
+     562                 :            : }
+     563                 :            : 
+     564                 :        791 : int mbedtls_gcm_update(mbedtls_gcm_context *ctx,
+     565                 :            :                        const unsigned char *input, size_t input_length,
+     566                 :            :                        unsigned char *output, size_t output_size,
+     567                 :            :                        size_t *output_length)
+     568                 :            : {
+     569                 :        791 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     570                 :        791 :     const unsigned char *p = input;
+     571                 :        791 :     unsigned char *out_p = output;
+     572                 :            :     size_t offset;
+     573                 :        791 :     unsigned char ectr[16] = { 0 };
+     574                 :            : 
+     575         [ -  + ]:        791 :     if (output_size < input_length) {
+     576                 :          0 :         return MBEDTLS_ERR_GCM_BUFFER_TOO_SMALL;
+     577                 :            :     }
+     578                 :        791 :     *output_length = input_length;
+     579                 :            : 
+     580                 :            :     /* Exit early if input_length==0 so that we don't do any pointer arithmetic
+     581                 :            :      * on a potentially null pointer.
+     582                 :            :      * Returning early also means that the last partial block of AD remains
+     583                 :            :      * untouched for mbedtls_gcm_finish */
+     584         [ -  + ]:        791 :     if (input_length == 0) {
+     585                 :          0 :         return 0;
+     586                 :            :     }
+     587                 :            : 
+     588   [ +  +  -  + ]:        791 :     if (output > input && (size_t) (output - input) < input_length) {
+     589                 :          0 :         return MBEDTLS_ERR_GCM_BAD_INPUT;
+     590                 :            :     }
+     591                 :            : 
+     592                 :            :     /* Total length is restricted to 2^39 - 256 bits, ie 2^36 - 2^5 bytes
+     593                 :            :      * Also check for possible overflow */
+     594         [ +  - ]:        791 :     if (ctx->len + input_length < ctx->len ||
+     595         [ -  + ]:        791 :         (uint64_t) ctx->len + input_length > 0xFFFFFFFE0ull) {
+     596                 :          0 :         return MBEDTLS_ERR_GCM_BAD_INPUT;
+     597                 :            :     }
+     598                 :            : 
+     599   [ +  -  +  - ]:        791 :     if (ctx->len == 0 && ctx->add_len % 16 != 0) {
+     600                 :        791 :         gcm_mult(ctx, ctx->buf, ctx->buf);
+     601                 :            :     }
+     602                 :            : 
+     603                 :        791 :     offset = ctx->len % 16;
+     604         [ -  + ]:        791 :     if (offset != 0) {
+     605                 :          0 :         size_t use_len = 16 - offset;
+     606         [ #  # ]:          0 :         if (use_len > input_length) {
+     607                 :          0 :             use_len = input_length;
+     608                 :            :         }
+     609                 :            : 
+     610         [ #  # ]:          0 :         if ((ret = gcm_mask(ctx, ectr, offset, use_len, p, out_p)) != 0) {
+     611                 :          0 :             return ret;
+     612                 :            :         }
+     613                 :            : 
+     614         [ #  # ]:          0 :         if (offset + use_len == 16) {
+     615                 :          0 :             gcm_mult(ctx, ctx->buf, ctx->buf);
+     616                 :            :         }
+     617                 :            : 
+     618                 :          0 :         ctx->len += use_len;
+     619                 :          0 :         input_length -= use_len;
+     620                 :          0 :         p += use_len;
+     621                 :          0 :         out_p += use_len;
+     622                 :            :     }
+     623                 :            : 
+     624                 :        791 :     ctx->len += input_length;
+     625                 :            : 
+     626         [ +  + ]:       2113 :     while (input_length >= 16) {
+     627                 :       1322 :         gcm_incr(ctx->y);
+     628         [ -  + ]:       1322 :         if ((ret = gcm_mask(ctx, ectr, 0, 16, p, out_p)) != 0) {
+     629                 :          0 :             return ret;
+     630                 :            :         }
+     631                 :            : 
+     632                 :       1322 :         gcm_mult(ctx, ctx->buf, ctx->buf);
+     633                 :            : 
+     634                 :       1322 :         input_length -= 16;
+     635                 :       1322 :         p += 16;
+     636                 :       1322 :         out_p += 16;
+     637                 :            :     }
+     638                 :            : 
+     639         [ +  + ]:        791 :     if (input_length > 0) {
+     640                 :        750 :         gcm_incr(ctx->y);
+     641         [ -  + ]:        750 :         if ((ret = gcm_mask(ctx, ectr, 0, input_length, p, out_p)) != 0) {
+     642                 :          0 :             return ret;
+     643                 :            :         }
+     644                 :            :     }
+     645                 :            : 
+     646                 :        791 :     mbedtls_platform_zeroize(ectr, sizeof(ectr));
+     647                 :        791 :     return 0;
+     648                 :            : }
+     649                 :            : 
+     650                 :        791 : int mbedtls_gcm_finish(mbedtls_gcm_context *ctx,
+     651                 :            :                        unsigned char *output, size_t output_size,
+     652                 :            :                        size_t *output_length,
+     653                 :            :                        unsigned char *tag, size_t tag_len)
+     654                 :            : {
+     655                 :            :     unsigned char work_buf[16];
+     656                 :            :     uint64_t orig_len;
+     657                 :            :     uint64_t orig_add_len;
+     658                 :            : 
+     659                 :            :     /* We never pass any output in finish(). The output parameter exists only
+     660                 :            :      * for the sake of alternative implementations. */
+     661                 :            :     (void) output;
+     662                 :            :     (void) output_size;
+     663                 :        791 :     *output_length = 0;
+     664                 :            : 
+     665                 :            :     /* Total length is restricted to 2^39 - 256 bits, ie 2^36 - 2^5 bytes
+     666                 :            :      * and AD length is restricted to 2^64 bits, ie 2^61 bytes so neither of
+     667                 :            :      * the two multiplications would overflow. */
+     668                 :        791 :     orig_len = ctx->len * 8;
+     669                 :        791 :     orig_add_len = ctx->add_len * 8;
+     670                 :            : 
+     671   [ -  +  -  - ]:        791 :     if (ctx->len == 0 && ctx->add_len % 16 != 0) {
+     672                 :          0 :         gcm_mult(ctx, ctx->buf, ctx->buf);
+     673                 :            :     }
+     674                 :            : 
+     675   [ +  -  -  + ]:        791 :     if (tag_len > 16 || tag_len < 4) {
+     676                 :          0 :         return MBEDTLS_ERR_GCM_BAD_INPUT;
+     677                 :            :     }
+     678                 :            : 
+     679         [ +  + ]:        791 :     if (ctx->len % 16 != 0) {
+     680                 :        750 :         gcm_mult(ctx, ctx->buf, ctx->buf);
+     681                 :            :     }
+     682                 :            : 
+     683                 :        791 :     memcpy(tag, ctx->base_ectr, tag_len);
+     684                 :            : 
+     685   [ -  +  -  - ]:        791 :     if (orig_len || orig_add_len) {
+     686                 :        791 :         memset(work_buf, 0x00, 16);
+     687                 :            : 
+     688                 :        791 :         MBEDTLS_PUT_UINT32_BE((orig_add_len >> 32), work_buf, 0);
+     689                 :        791 :         MBEDTLS_PUT_UINT32_BE((orig_add_len), work_buf, 4);
+     690                 :        791 :         MBEDTLS_PUT_UINT32_BE((orig_len     >> 32), work_buf, 8);
+     691                 :        791 :         MBEDTLS_PUT_UINT32_BE((orig_len), work_buf, 12);
+     692                 :            : 
+     693                 :        791 :         mbedtls_xor(ctx->buf, ctx->buf, work_buf, 16);
+     694                 :            : 
+     695                 :        791 :         gcm_mult(ctx, ctx->buf, ctx->buf);
+     696                 :            : 
+     697                 :        791 :         mbedtls_xor(tag, tag, ctx->buf, tag_len);
+     698                 :            :     }
+     699                 :            : 
+     700                 :        791 :     return 0;
+     701                 :            : }
+     702                 :            : 
+     703                 :        791 : int mbedtls_gcm_crypt_and_tag(mbedtls_gcm_context *ctx,
+     704                 :            :                               int mode,
+     705                 :            :                               size_t length,
+     706                 :            :                               const unsigned char *iv,
+     707                 :            :                               size_t iv_len,
+     708                 :            :                               const unsigned char *add,
+     709                 :            :                               size_t add_len,
+     710                 :            :                               const unsigned char *input,
+     711                 :            :                               unsigned char *output,
+     712                 :            :                               size_t tag_len,
+     713                 :            :                               unsigned char *tag)
+     714                 :            : {
+     715                 :        791 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     716                 :            :     size_t olen;
+     717                 :            : 
+     718         [ -  + ]:        791 :     if ((ret = mbedtls_gcm_starts(ctx, mode, iv, iv_len)) != 0) {
+     719                 :          0 :         return ret;
+     720                 :            :     }
+     721                 :            : 
+     722         [ -  + ]:        791 :     if ((ret = mbedtls_gcm_update_ad(ctx, add, add_len)) != 0) {
+     723                 :          0 :         return ret;
+     724                 :            :     }
+     725                 :            : 
+     726         [ -  + ]:        791 :     if ((ret = mbedtls_gcm_update(ctx, input, length,
+     727                 :            :                                   output, length, &olen)) != 0) {
+     728                 :          0 :         return ret;
+     729                 :            :     }
+     730                 :            : 
+     731         [ -  + ]:        791 :     if ((ret = mbedtls_gcm_finish(ctx, NULL, 0, &olen, tag, tag_len)) != 0) {
+     732                 :          0 :         return ret;
+     733                 :            :     }
+     734                 :            : 
+     735                 :        791 :     return 0;
+     736                 :            : }
+     737                 :            : 
+     738                 :        326 : int mbedtls_gcm_auth_decrypt(mbedtls_gcm_context *ctx,
+     739                 :            :                              size_t length,
+     740                 :            :                              const unsigned char *iv,
+     741                 :            :                              size_t iv_len,
+     742                 :            :                              const unsigned char *add,
+     743                 :            :                              size_t add_len,
+     744                 :            :                              const unsigned char *tag,
+     745                 :            :                              size_t tag_len,
+     746                 :            :                              const unsigned char *input,
+     747                 :            :                              unsigned char *output)
+     748                 :            : {
+     749                 :        326 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     750                 :            :     unsigned char check_tag[16];
+     751                 :            :     int diff;
+     752                 :            : 
+     753         [ -  + ]:        326 :     if ((ret = mbedtls_gcm_crypt_and_tag(ctx, MBEDTLS_GCM_DECRYPT, length,
+     754                 :            :                                          iv, iv_len, add, add_len,
+     755                 :            :                                          input, output, tag_len, check_tag)) != 0) {
+     756                 :          0 :         return ret;
+     757                 :            :     }
+     758                 :            : 
+     759                 :            :     /* Check tag in "constant-time" */
+     760                 :        326 :     diff = mbedtls_ct_memcmp(tag, check_tag, tag_len);
+     761                 :            : 
+     762         [ +  + ]:        326 :     if (diff != 0) {
+     763                 :         27 :         mbedtls_platform_zeroize(output, length);
+     764                 :         27 :         return MBEDTLS_ERR_GCM_AUTH_FAILED;
+     765                 :            :     }
+     766                 :            : 
+     767                 :        299 :     return 0;
+     768                 :            : }
+     769                 :            : 
+     770                 :        791 : void mbedtls_gcm_free(mbedtls_gcm_context *ctx)
+     771                 :            : {
+     772         [ -  + ]:        791 :     if (ctx == NULL) {
+     773                 :          0 :         return;
+     774                 :            :     }
+     775                 :            : #if defined(MBEDTLS_BLOCK_CIPHER_C)
+     776                 :            :     mbedtls_block_cipher_free(&ctx->block_cipher_ctx);
+     777                 :            : #else
+     778                 :        791 :     mbedtls_cipher_free(&ctx->cipher_ctx);
+     779                 :            : #endif
+     780                 :        791 :     mbedtls_platform_zeroize(ctx, sizeof(mbedtls_gcm_context));
+     781                 :            : }
+     782                 :            : 
+     783                 :            : #endif /* !MBEDTLS_GCM_ALT */
+     784                 :            : 
+     785                 :            : #if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_CCM_GCM_CAN_AES)
+     786                 :            : /*
+     787                 :            :  * AES-GCM test vectors from:
+     788                 :            :  *
+     789                 :            :  * http://csrc.nist.gov/groups/STM/cavp/documents/mac/gcmtestvectors.zip
+     790                 :            :  */
+     791                 :            : #define MAX_TESTS   6
+     792                 :            : 
+     793                 :            : static const int key_index_test_data[MAX_TESTS] =
+     794                 :            : { 0, 0, 1, 1, 1, 1 };
+     795                 :            : 
+     796                 :            : static const unsigned char key_test_data[][32] =
+     797                 :            : {
+     798                 :            :     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+     799                 :            :       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+     800                 :            :       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+     801                 :            :       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+     802                 :            :     { 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
+     803                 :            :       0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
+     804                 :            :       0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
+     805                 :            :       0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08 },
+     806                 :            : };
+     807                 :            : 
+     808                 :            : static const size_t iv_len_test_data[MAX_TESTS] =
+     809                 :            : { 12, 12, 12, 12, 8, 60 };
+     810                 :            : 
+     811                 :            : static const int iv_index_test_data[MAX_TESTS] =
+     812                 :            : { 0, 0, 1, 1, 1, 2 };
+     813                 :            : 
+     814                 :            : static const unsigned char iv_test_data[][64] =
+     815                 :            : {
+     816                 :            :     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+     817                 :            :       0x00, 0x00, 0x00, 0x00 },
+     818                 :            :     { 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
+     819                 :            :       0xde, 0xca, 0xf8, 0x88 },
+     820                 :            :     { 0x93, 0x13, 0x22, 0x5d, 0xf8, 0x84, 0x06, 0xe5,
+     821                 :            :       0x55, 0x90, 0x9c, 0x5a, 0xff, 0x52, 0x69, 0xaa,
+     822                 :            :       0x6a, 0x7a, 0x95, 0x38, 0x53, 0x4f, 0x7d, 0xa1,
+     823                 :            :       0xe4, 0xc3, 0x03, 0xd2, 0xa3, 0x18, 0xa7, 0x28,
+     824                 :            :       0xc3, 0xc0, 0xc9, 0x51, 0x56, 0x80, 0x95, 0x39,
+     825                 :            :       0xfc, 0xf0, 0xe2, 0x42, 0x9a, 0x6b, 0x52, 0x54,
+     826                 :            :       0x16, 0xae, 0xdb, 0xf5, 0xa0, 0xde, 0x6a, 0x57,
+     827                 :            :       0xa6, 0x37, 0xb3, 0x9b },
+     828                 :            : };
+     829                 :            : 
+     830                 :            : static const size_t add_len_test_data[MAX_TESTS] =
+     831                 :            : { 0, 0, 0, 20, 20, 20 };
+     832                 :            : 
+     833                 :            : static const int add_index_test_data[MAX_TESTS] =
+     834                 :            : { 0, 0, 0, 1, 1, 1 };
+     835                 :            : 
+     836                 :            : static const unsigned char additional_test_data[][64] =
+     837                 :            : {
+     838                 :            :     { 0x00 },
+     839                 :            :     { 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
+     840                 :            :       0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
+     841                 :            :       0xab, 0xad, 0xda, 0xd2 },
+     842                 :            : };
+     843                 :            : 
+     844                 :            : static const size_t pt_len_test_data[MAX_TESTS] =
+     845                 :            : { 0, 16, 64, 60, 60, 60 };
+     846                 :            : 
+     847                 :            : static const int pt_index_test_data[MAX_TESTS] =
+     848                 :            : { 0, 0, 1, 1, 1, 1 };
+     849                 :            : 
+     850                 :            : static const unsigned char pt_test_data[][64] =
+     851                 :            : {
+     852                 :            :     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+     853                 :            :       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+     854                 :            :     { 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
+     855                 :            :       0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
+     856                 :            :       0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
+     857                 :            :       0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
+     858                 :            :       0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
+     859                 :            :       0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
+     860                 :            :       0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
+     861                 :            :       0xba, 0x63, 0x7b, 0x39, 0x1a, 0xaf, 0xd2, 0x55 },
+     862                 :            : };
+     863                 :            : 
+     864                 :            : static const unsigned char ct_test_data[][64] =
+     865                 :            : {
+     866                 :            :     { 0x00 },
+     867                 :            :     { 0x03, 0x88, 0xda, 0xce, 0x60, 0xb6, 0xa3, 0x92,
+     868                 :            :       0xf3, 0x28, 0xc2, 0xb9, 0x71, 0xb2, 0xfe, 0x78 },
+     869                 :            :     { 0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24,
+     870                 :            :       0x4b, 0x72, 0x21, 0xb7, 0x84, 0xd0, 0xd4, 0x9c,
+     871                 :            :       0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, 0xa4, 0xe0,
+     872                 :            :       0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e,
+     873                 :            :       0x21, 0xd5, 0x14, 0xb2, 0x54, 0x66, 0x93, 0x1c,
+     874                 :            :       0x7d, 0x8f, 0x6a, 0x5a, 0xac, 0x84, 0xaa, 0x05,
+     875                 :            :       0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, 0x97,
+     876                 :            :       0x3d, 0x58, 0xe0, 0x91, 0x47, 0x3f, 0x59, 0x85 },
+     877                 :            :     { 0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24,
+     878                 :            :       0x4b, 0x72, 0x21, 0xb7, 0x84, 0xd0, 0xd4, 0x9c,
+     879                 :            :       0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, 0xa4, 0xe0,
+     880                 :            :       0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e,
+     881                 :            :       0x21, 0xd5, 0x14, 0xb2, 0x54, 0x66, 0x93, 0x1c,
+     882                 :            :       0x7d, 0x8f, 0x6a, 0x5a, 0xac, 0x84, 0xaa, 0x05,
+     883                 :            :       0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, 0x97,
+     884                 :            :       0x3d, 0x58, 0xe0, 0x91 },
+     885                 :            :     { 0x61, 0x35, 0x3b, 0x4c, 0x28, 0x06, 0x93, 0x4a,
+     886                 :            :       0x77, 0x7f, 0xf5, 0x1f, 0xa2, 0x2a, 0x47, 0x55,
+     887                 :            :       0x69, 0x9b, 0x2a, 0x71, 0x4f, 0xcd, 0xc6, 0xf8,
+     888                 :            :       0x37, 0x66, 0xe5, 0xf9, 0x7b, 0x6c, 0x74, 0x23,
+     889                 :            :       0x73, 0x80, 0x69, 0x00, 0xe4, 0x9f, 0x24, 0xb2,
+     890                 :            :       0x2b, 0x09, 0x75, 0x44, 0xd4, 0x89, 0x6b, 0x42,
+     891                 :            :       0x49, 0x89, 0xb5, 0xe1, 0xeb, 0xac, 0x0f, 0x07,
+     892                 :            :       0xc2, 0x3f, 0x45, 0x98 },
+     893                 :            :     { 0x8c, 0xe2, 0x49, 0x98, 0x62, 0x56, 0x15, 0xb6,
+     894                 :            :       0x03, 0xa0, 0x33, 0xac, 0xa1, 0x3f, 0xb8, 0x94,
+     895                 :            :       0xbe, 0x91, 0x12, 0xa5, 0xc3, 0xa2, 0x11, 0xa8,
+     896                 :            :       0xba, 0x26, 0x2a, 0x3c, 0xca, 0x7e, 0x2c, 0xa7,
+     897                 :            :       0x01, 0xe4, 0xa9, 0xa4, 0xfb, 0xa4, 0x3c, 0x90,
+     898                 :            :       0xcc, 0xdc, 0xb2, 0x81, 0xd4, 0x8c, 0x7c, 0x6f,
+     899                 :            :       0xd6, 0x28, 0x75, 0xd2, 0xac, 0xa4, 0x17, 0x03,
+     900                 :            :       0x4c, 0x34, 0xae, 0xe5 },
+     901                 :            : #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
+     902                 :            :     { 0x00 },
+     903                 :            :     { 0x98, 0xe7, 0x24, 0x7c, 0x07, 0xf0, 0xfe, 0x41,
+     904                 :            :       0x1c, 0x26, 0x7e, 0x43, 0x84, 0xb0, 0xf6, 0x00 },
+     905                 :            :     { 0x39, 0x80, 0xca, 0x0b, 0x3c, 0x00, 0xe8, 0x41,
+     906                 :            :       0xeb, 0x06, 0xfa, 0xc4, 0x87, 0x2a, 0x27, 0x57,
+     907                 :            :       0x85, 0x9e, 0x1c, 0xea, 0xa6, 0xef, 0xd9, 0x84,
+     908                 :            :       0x62, 0x85, 0x93, 0xb4, 0x0c, 0xa1, 0xe1, 0x9c,
+     909                 :            :       0x7d, 0x77, 0x3d, 0x00, 0xc1, 0x44, 0xc5, 0x25,
+     910                 :            :       0xac, 0x61, 0x9d, 0x18, 0xc8, 0x4a, 0x3f, 0x47,
+     911                 :            :       0x18, 0xe2, 0x44, 0x8b, 0x2f, 0xe3, 0x24, 0xd9,
+     912                 :            :       0xcc, 0xda, 0x27, 0x10, 0xac, 0xad, 0xe2, 0x56 },
+     913                 :            :     { 0x39, 0x80, 0xca, 0x0b, 0x3c, 0x00, 0xe8, 0x41,
+     914                 :            :       0xeb, 0x06, 0xfa, 0xc4, 0x87, 0x2a, 0x27, 0x57,
+     915                 :            :       0x85, 0x9e, 0x1c, 0xea, 0xa6, 0xef, 0xd9, 0x84,
+     916                 :            :       0x62, 0x85, 0x93, 0xb4, 0x0c, 0xa1, 0xe1, 0x9c,
+     917                 :            :       0x7d, 0x77, 0x3d, 0x00, 0xc1, 0x44, 0xc5, 0x25,
+     918                 :            :       0xac, 0x61, 0x9d, 0x18, 0xc8, 0x4a, 0x3f, 0x47,
+     919                 :            :       0x18, 0xe2, 0x44, 0x8b, 0x2f, 0xe3, 0x24, 0xd9,
+     920                 :            :       0xcc, 0xda, 0x27, 0x10 },
+     921                 :            :     { 0x0f, 0x10, 0xf5, 0x99, 0xae, 0x14, 0xa1, 0x54,
+     922                 :            :       0xed, 0x24, 0xb3, 0x6e, 0x25, 0x32, 0x4d, 0xb8,
+     923                 :            :       0xc5, 0x66, 0x63, 0x2e, 0xf2, 0xbb, 0xb3, 0x4f,
+     924                 :            :       0x83, 0x47, 0x28, 0x0f, 0xc4, 0x50, 0x70, 0x57,
+     925                 :            :       0xfd, 0xdc, 0x29, 0xdf, 0x9a, 0x47, 0x1f, 0x75,
+     926                 :            :       0xc6, 0x65, 0x41, 0xd4, 0xd4, 0xda, 0xd1, 0xc9,
+     927                 :            :       0xe9, 0x3a, 0x19, 0xa5, 0x8e, 0x8b, 0x47, 0x3f,
+     928                 :            :       0xa0, 0xf0, 0x62, 0xf7 },
+     929                 :            :     { 0xd2, 0x7e, 0x88, 0x68, 0x1c, 0xe3, 0x24, 0x3c,
+     930                 :            :       0x48, 0x30, 0x16, 0x5a, 0x8f, 0xdc, 0xf9, 0xff,
+     931                 :            :       0x1d, 0xe9, 0xa1, 0xd8, 0xe6, 0xb4, 0x47, 0xef,
+     932                 :            :       0x6e, 0xf7, 0xb7, 0x98, 0x28, 0x66, 0x6e, 0x45,
+     933                 :            :       0x81, 0xe7, 0x90, 0x12, 0xaf, 0x34, 0xdd, 0xd9,
+     934                 :            :       0xe2, 0xf0, 0x37, 0x58, 0x9b, 0x29, 0x2d, 0xb3,
+     935                 :            :       0xe6, 0x7c, 0x03, 0x67, 0x45, 0xfa, 0x22, 0xe7,
+     936                 :            :       0xe9, 0xb7, 0x37, 0x3b },
+     937                 :            :     { 0x00 },
+     938                 :            :     { 0xce, 0xa7, 0x40, 0x3d, 0x4d, 0x60, 0x6b, 0x6e,
+     939                 :            :       0x07, 0x4e, 0xc5, 0xd3, 0xba, 0xf3, 0x9d, 0x18 },
+     940                 :            :     { 0x52, 0x2d, 0xc1, 0xf0, 0x99, 0x56, 0x7d, 0x07,
+     941                 :            :       0xf4, 0x7f, 0x37, 0xa3, 0x2a, 0x84, 0x42, 0x7d,
+     942                 :            :       0x64, 0x3a, 0x8c, 0xdc, 0xbf, 0xe5, 0xc0, 0xc9,
+     943                 :            :       0x75, 0x98, 0xa2, 0xbd, 0x25, 0x55, 0xd1, 0xaa,
+     944                 :            :       0x8c, 0xb0, 0x8e, 0x48, 0x59, 0x0d, 0xbb, 0x3d,
+     945                 :            :       0xa7, 0xb0, 0x8b, 0x10, 0x56, 0x82, 0x88, 0x38,
+     946                 :            :       0xc5, 0xf6, 0x1e, 0x63, 0x93, 0xba, 0x7a, 0x0a,
+     947                 :            :       0xbc, 0xc9, 0xf6, 0x62, 0x89, 0x80, 0x15, 0xad },
+     948                 :            :     { 0x52, 0x2d, 0xc1, 0xf0, 0x99, 0x56, 0x7d, 0x07,
+     949                 :            :       0xf4, 0x7f, 0x37, 0xa3, 0x2a, 0x84, 0x42, 0x7d,
+     950                 :            :       0x64, 0x3a, 0x8c, 0xdc, 0xbf, 0xe5, 0xc0, 0xc9,
+     951                 :            :       0x75, 0x98, 0xa2, 0xbd, 0x25, 0x55, 0xd1, 0xaa,
+     952                 :            :       0x8c, 0xb0, 0x8e, 0x48, 0x59, 0x0d, 0xbb, 0x3d,
+     953                 :            :       0xa7, 0xb0, 0x8b, 0x10, 0x56, 0x82, 0x88, 0x38,
+     954                 :            :       0xc5, 0xf6, 0x1e, 0x63, 0x93, 0xba, 0x7a, 0x0a,
+     955                 :            :       0xbc, 0xc9, 0xf6, 0x62 },
+     956                 :            :     { 0xc3, 0x76, 0x2d, 0xf1, 0xca, 0x78, 0x7d, 0x32,
+     957                 :            :       0xae, 0x47, 0xc1, 0x3b, 0xf1, 0x98, 0x44, 0xcb,
+     958                 :            :       0xaf, 0x1a, 0xe1, 0x4d, 0x0b, 0x97, 0x6a, 0xfa,
+     959                 :            :       0xc5, 0x2f, 0xf7, 0xd7, 0x9b, 0xba, 0x9d, 0xe0,
+     960                 :            :       0xfe, 0xb5, 0x82, 0xd3, 0x39, 0x34, 0xa4, 0xf0,
+     961                 :            :       0x95, 0x4c, 0xc2, 0x36, 0x3b, 0xc7, 0x3f, 0x78,
+     962                 :            :       0x62, 0xac, 0x43, 0x0e, 0x64, 0xab, 0xe4, 0x99,
+     963                 :            :       0xf4, 0x7c, 0x9b, 0x1f },
+     964                 :            :     { 0x5a, 0x8d, 0xef, 0x2f, 0x0c, 0x9e, 0x53, 0xf1,
+     965                 :            :       0xf7, 0x5d, 0x78, 0x53, 0x65, 0x9e, 0x2a, 0x20,
+     966                 :            :       0xee, 0xb2, 0xb2, 0x2a, 0xaf, 0xde, 0x64, 0x19,
+     967                 :            :       0xa0, 0x58, 0xab, 0x4f, 0x6f, 0x74, 0x6b, 0xf4,
+     968                 :            :       0x0f, 0xc0, 0xc3, 0xb7, 0x80, 0xf2, 0x44, 0x45,
+     969                 :            :       0x2d, 0xa3, 0xeb, 0xf1, 0xc5, 0xd8, 0x2c, 0xde,
+     970                 :            :       0xa2, 0x41, 0x89, 0x97, 0x20, 0x0e, 0xf8, 0x2e,
+     971                 :            :       0x44, 0xae, 0x7e, 0x3f },
+     972                 :            : #endif /* !MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
+     973                 :            : };
+     974                 :            : 
+     975                 :            : static const unsigned char tag_test_data[][16] =
+     976                 :            : {
+     977                 :            :     { 0x58, 0xe2, 0xfc, 0xce, 0xfa, 0x7e, 0x30, 0x61,
+     978                 :            :       0x36, 0x7f, 0x1d, 0x57, 0xa4, 0xe7, 0x45, 0x5a },
+     979                 :            :     { 0xab, 0x6e, 0x47, 0xd4, 0x2c, 0xec, 0x13, 0xbd,
+     980                 :            :       0xf5, 0x3a, 0x67, 0xb2, 0x12, 0x57, 0xbd, 0xdf },
+     981                 :            :     { 0x4d, 0x5c, 0x2a, 0xf3, 0x27, 0xcd, 0x64, 0xa6,
+     982                 :            :       0x2c, 0xf3, 0x5a, 0xbd, 0x2b, 0xa6, 0xfa, 0xb4 },
+     983                 :            :     { 0x5b, 0xc9, 0x4f, 0xbc, 0x32, 0x21, 0xa5, 0xdb,
+     984                 :            :       0x94, 0xfa, 0xe9, 0x5a, 0xe7, 0x12, 0x1a, 0x47 },
+     985                 :            :     { 0x36, 0x12, 0xd2, 0xe7, 0x9e, 0x3b, 0x07, 0x85,
+     986                 :            :       0x56, 0x1b, 0xe1, 0x4a, 0xac, 0xa2, 0xfc, 0xcb },
+     987                 :            :     { 0x61, 0x9c, 0xc5, 0xae, 0xff, 0xfe, 0x0b, 0xfa,
+     988                 :            :       0x46, 0x2a, 0xf4, 0x3c, 0x16, 0x99, 0xd0, 0x50 },
+     989                 :            : #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
+     990                 :            :     { 0xcd, 0x33, 0xb2, 0x8a, 0xc7, 0x73, 0xf7, 0x4b,
+     991                 :            :       0xa0, 0x0e, 0xd1, 0xf3, 0x12, 0x57, 0x24, 0x35 },
+     992                 :            :     { 0x2f, 0xf5, 0x8d, 0x80, 0x03, 0x39, 0x27, 0xab,
+     993                 :            :       0x8e, 0xf4, 0xd4, 0x58, 0x75, 0x14, 0xf0, 0xfb },
+     994                 :            :     { 0x99, 0x24, 0xa7, 0xc8, 0x58, 0x73, 0x36, 0xbf,
+     995                 :            :       0xb1, 0x18, 0x02, 0x4d, 0xb8, 0x67, 0x4a, 0x14 },
+     996                 :            :     { 0x25, 0x19, 0x49, 0x8e, 0x80, 0xf1, 0x47, 0x8f,
+     997                 :            :       0x37, 0xba, 0x55, 0xbd, 0x6d, 0x27, 0x61, 0x8c },
+     998                 :            :     { 0x65, 0xdc, 0xc5, 0x7f, 0xcf, 0x62, 0x3a, 0x24,
+     999                 :            :       0x09, 0x4f, 0xcc, 0xa4, 0x0d, 0x35, 0x33, 0xf8 },
+    1000                 :            :     { 0xdc, 0xf5, 0x66, 0xff, 0x29, 0x1c, 0x25, 0xbb,
+    1001                 :            :       0xb8, 0x56, 0x8f, 0xc3, 0xd3, 0x76, 0xa6, 0xd9 },
+    1002                 :            :     { 0x53, 0x0f, 0x8a, 0xfb, 0xc7, 0x45, 0x36, 0xb9,
+    1003                 :            :       0xa9, 0x63, 0xb4, 0xf1, 0xc4, 0xcb, 0x73, 0x8b },
+    1004                 :            :     { 0xd0, 0xd1, 0xc8, 0xa7, 0x99, 0x99, 0x6b, 0xf0,
+    1005                 :            :       0x26, 0x5b, 0x98, 0xb5, 0xd4, 0x8a, 0xb9, 0x19 },
+    1006                 :            :     { 0xb0, 0x94, 0xda, 0xc5, 0xd9, 0x34, 0x71, 0xbd,
+    1007                 :            :       0xec, 0x1a, 0x50, 0x22, 0x70, 0xe3, 0xcc, 0x6c },
+    1008                 :            :     { 0x76, 0xfc, 0x6e, 0xce, 0x0f, 0x4e, 0x17, 0x68,
+    1009                 :            :       0xcd, 0xdf, 0x88, 0x53, 0xbb, 0x2d, 0x55, 0x1b },
+    1010                 :            :     { 0x3a, 0x33, 0x7d, 0xbf, 0x46, 0xa7, 0x92, 0xc4,
+    1011                 :            :       0x5e, 0x45, 0x49, 0x13, 0xfe, 0x2e, 0xa8, 0xf2 },
+    1012                 :            :     { 0xa4, 0x4a, 0x82, 0x66, 0xee, 0x1c, 0x8e, 0xb0,
+    1013                 :            :       0xc8, 0xb5, 0xd4, 0xcf, 0x5a, 0xe9, 0xf1, 0x9a },
+    1014                 :            : #endif /* !MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
+    1015                 :            : };
+    1016                 :            : 
+    1017                 :          0 : int mbedtls_gcm_self_test(int verbose)
+    1018                 :            : {
+    1019                 :            :     mbedtls_gcm_context ctx;
+    1020                 :            :     unsigned char buf[64];
+    1021                 :            :     unsigned char tag_buf[16];
+    1022                 :            :     int i, j, ret;
+    1023                 :          0 :     mbedtls_cipher_id_t cipher = MBEDTLS_CIPHER_ID_AES;
+    1024                 :            :     size_t olen;
+    1025                 :            : 
+    1026         [ #  # ]:          0 :     if (verbose != 0) {
+    1027                 :            : #if defined(MBEDTLS_GCM_ALT)
+    1028                 :            :         mbedtls_printf("  GCM note: alternative implementation.\n");
+    1029                 :            : #else /* MBEDTLS_GCM_ALT */
+    1030                 :            : #if defined(MBEDTLS_AESNI_HAVE_CODE)
+    1031         [ #  # ]:          0 :         if (mbedtls_aesni_has_support(MBEDTLS_AESNI_CLMUL)) {
+    1032                 :          0 :             mbedtls_printf("  GCM note: using AESNI.\n");
+    1033                 :            :         } else
+    1034                 :            : #endif
+    1035                 :            : 
+    1036                 :            : #if defined(MBEDTLS_AESCE_HAVE_CODE)
+    1037                 :            :         if (MBEDTLS_AESCE_HAS_SUPPORT()) {
+    1038                 :            :             mbedtls_printf("  GCM note: using AESCE.\n");
+    1039                 :            :         } else
+    1040                 :            : #endif
+    1041                 :            : 
+    1042                 :          0 :         mbedtls_printf("  GCM note: built-in implementation.\n");
+    1043                 :            : #endif /* MBEDTLS_GCM_ALT */
+    1044                 :            :     }
+    1045                 :            : 
+    1046                 :            :     static const int loop_limit =
+    1047                 :            :         (sizeof(ct_test_data) / sizeof(*ct_test_data)) / MAX_TESTS;
+    1048                 :            : 
+    1049         [ #  # ]:          0 :     for (j = 0; j < loop_limit; j++) {
+    1050                 :          0 :         int key_len = 128 + 64 * j;
+    1051                 :            : 
+    1052         [ #  # ]:          0 :         for (i = 0; i < MAX_TESTS; i++) {
+    1053         [ #  # ]:          0 :             if (verbose != 0) {
+    1054                 :          0 :                 mbedtls_printf("  AES-GCM-%3d #%d (%s): ",
+    1055                 :            :                                key_len, i, "enc");
+    1056                 :            :             }
+    1057                 :            : 
+    1058                 :          0 :             mbedtls_gcm_init(&ctx);
+    1059                 :            : 
+    1060                 :          0 :             ret = mbedtls_gcm_setkey(&ctx, cipher,
+    1061                 :          0 :                                      key_test_data[key_index_test_data[i]],
+    1062                 :            :                                      key_len);
+    1063                 :            :             /*
+    1064                 :            :              * AES-192 is an optional feature that may be unavailable when
+    1065                 :            :              * there is an alternative underlying implementation i.e. when
+    1066                 :            :              * MBEDTLS_AES_ALT is defined.
+    1067                 :            :              */
+    1068   [ #  #  #  # ]:          0 :             if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED && key_len == 192) {
+    1069                 :          0 :                 mbedtls_printf("skipped\n");
+    1070                 :          0 :                 break;
+    1071         [ #  # ]:          0 :             } else if (ret != 0) {
+    1072                 :          0 :                 goto exit;
+    1073                 :            :             }
+    1074                 :            : 
+    1075                 :          0 :             ret = mbedtls_gcm_crypt_and_tag(&ctx, MBEDTLS_GCM_ENCRYPT,
+    1076                 :          0 :                                             pt_len_test_data[i],
+    1077                 :          0 :                                             iv_test_data[iv_index_test_data[i]],
+    1078                 :          0 :                                             iv_len_test_data[i],
+    1079                 :          0 :                                             additional_test_data[add_index_test_data[i]],
+    1080                 :          0 :                                             add_len_test_data[i],
+    1081                 :          0 :                                             pt_test_data[pt_index_test_data[i]],
+    1082                 :            :                                             buf, 16, tag_buf);
+    1083                 :            : #if defined(MBEDTLS_GCM_ALT)
+    1084                 :            :             /* Allow alternative implementations to only support 12-byte nonces. */
+    1085                 :            :             if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED &&
+    1086                 :            :                 iv_len_test_data[i] != 12) {
+    1087                 :            :                 mbedtls_printf("skipped\n");
+    1088                 :            :                 break;
+    1089                 :            :             }
+    1090                 :            : #endif /* defined(MBEDTLS_GCM_ALT) */
+    1091         [ #  # ]:          0 :             if (ret != 0) {
+    1092                 :          0 :                 goto exit;
+    1093                 :            :             }
+    1094                 :            : 
+    1095                 :          0 :             if (memcmp(buf, ct_test_data[j * 6 + i],
+    1096         [ #  # ]:          0 :                        pt_len_test_data[i]) != 0 ||
+    1097         [ #  # ]:          0 :                 memcmp(tag_buf, tag_test_data[j * 6 + i], 16) != 0) {
+    1098                 :          0 :                 ret = 1;
+    1099                 :          0 :                 goto exit;
+    1100                 :            :             }
+    1101                 :            : 
+    1102                 :          0 :             mbedtls_gcm_free(&ctx);
+    1103                 :            : 
+    1104         [ #  # ]:          0 :             if (verbose != 0) {
+    1105                 :          0 :                 mbedtls_printf("passed\n");
+    1106                 :            :             }
+    1107                 :            : 
+    1108                 :          0 :             mbedtls_gcm_init(&ctx);
+    1109                 :            : 
+    1110         [ #  # ]:          0 :             if (verbose != 0) {
+    1111                 :          0 :                 mbedtls_printf("  AES-GCM-%3d #%d (%s): ",
+    1112                 :            :                                key_len, i, "dec");
+    1113                 :            :             }
+    1114                 :            : 
+    1115                 :          0 :             ret = mbedtls_gcm_setkey(&ctx, cipher,
+    1116                 :          0 :                                      key_test_data[key_index_test_data[i]],
+    1117                 :            :                                      key_len);
+    1118         [ #  # ]:          0 :             if (ret != 0) {
+    1119                 :          0 :                 goto exit;
+    1120                 :            :             }
+    1121                 :            : 
+    1122                 :          0 :             ret = mbedtls_gcm_crypt_and_tag(&ctx, MBEDTLS_GCM_DECRYPT,
+    1123                 :          0 :                                             pt_len_test_data[i],
+    1124                 :          0 :                                             iv_test_data[iv_index_test_data[i]],
+    1125                 :          0 :                                             iv_len_test_data[i],
+    1126                 :          0 :                                             additional_test_data[add_index_test_data[i]],
+    1127                 :          0 :                                             add_len_test_data[i],
+    1128                 :          0 :                                             ct_test_data[j * 6 + i], buf, 16, tag_buf);
+    1129                 :            : 
+    1130         [ #  # ]:          0 :             if (ret != 0) {
+    1131                 :          0 :                 goto exit;
+    1132                 :            :             }
+    1133                 :            : 
+    1134                 :          0 :             if (memcmp(buf, pt_test_data[pt_index_test_data[i]],
+    1135         [ #  # ]:          0 :                        pt_len_test_data[i]) != 0 ||
+    1136         [ #  # ]:          0 :                 memcmp(tag_buf, tag_test_data[j * 6 + i], 16) != 0) {
+    1137                 :          0 :                 ret = 1;
+    1138                 :          0 :                 goto exit;
+    1139                 :            :             }
+    1140                 :            : 
+    1141                 :          0 :             mbedtls_gcm_free(&ctx);
+    1142                 :            : 
+    1143         [ #  # ]:          0 :             if (verbose != 0) {
+    1144                 :          0 :                 mbedtls_printf("passed\n");
+    1145                 :            :             }
+    1146                 :            : 
+    1147                 :          0 :             mbedtls_gcm_init(&ctx);
+    1148                 :            : 
+    1149         [ #  # ]:          0 :             if (verbose != 0) {
+    1150                 :          0 :                 mbedtls_printf("  AES-GCM-%3d #%d split (%s): ",
+    1151                 :            :                                key_len, i, "enc");
+    1152                 :            :             }
+    1153                 :            : 
+    1154                 :          0 :             ret = mbedtls_gcm_setkey(&ctx, cipher,
+    1155                 :          0 :                                      key_test_data[key_index_test_data[i]],
+    1156                 :            :                                      key_len);
+    1157         [ #  # ]:          0 :             if (ret != 0) {
+    1158                 :          0 :                 goto exit;
+    1159                 :            :             }
+    1160                 :            : 
+    1161                 :          0 :             ret = mbedtls_gcm_starts(&ctx, MBEDTLS_GCM_ENCRYPT,
+    1162                 :          0 :                                      iv_test_data[iv_index_test_data[i]],
+    1163                 :          0 :                                      iv_len_test_data[i]);
+    1164         [ #  # ]:          0 :             if (ret != 0) {
+    1165                 :          0 :                 goto exit;
+    1166                 :            :             }
+    1167                 :            : 
+    1168                 :          0 :             ret = mbedtls_gcm_update_ad(&ctx,
+    1169                 :          0 :                                         additional_test_data[add_index_test_data[i]],
+    1170                 :          0 :                                         add_len_test_data[i]);
+    1171         [ #  # ]:          0 :             if (ret != 0) {
+    1172                 :          0 :                 goto exit;
+    1173                 :            :             }
+    1174                 :            : 
+    1175         [ #  # ]:          0 :             if (pt_len_test_data[i] > 32) {
+    1176                 :          0 :                 size_t rest_len = pt_len_test_data[i] - 32;
+    1177                 :          0 :                 ret = mbedtls_gcm_update(&ctx,
+    1178                 :          0 :                                          pt_test_data[pt_index_test_data[i]],
+    1179                 :            :                                          32,
+    1180                 :            :                                          buf, sizeof(buf), &olen);
+    1181         [ #  # ]:          0 :                 if (ret != 0) {
+    1182                 :          0 :                     goto exit;
+    1183                 :            :                 }
+    1184         [ #  # ]:          0 :                 if (olen != 32) {
+    1185                 :          0 :                     goto exit;
+    1186                 :            :                 }
+    1187                 :            : 
+    1188                 :          0 :                 ret = mbedtls_gcm_update(&ctx,
+    1189                 :          0 :                                          pt_test_data[pt_index_test_data[i]] + 32,
+    1190                 :            :                                          rest_len,
+    1191                 :            :                                          buf + 32, sizeof(buf) - 32, &olen);
+    1192         [ #  # ]:          0 :                 if (ret != 0) {
+    1193                 :          0 :                     goto exit;
+    1194                 :            :                 }
+    1195         [ #  # ]:          0 :                 if (olen != rest_len) {
+    1196                 :          0 :                     goto exit;
+    1197                 :            :                 }
+    1198                 :            :             } else {
+    1199                 :          0 :                 ret = mbedtls_gcm_update(&ctx,
+    1200                 :          0 :                                          pt_test_data[pt_index_test_data[i]],
+    1201                 :          0 :                                          pt_len_test_data[i],
+    1202                 :            :                                          buf, sizeof(buf), &olen);
+    1203         [ #  # ]:          0 :                 if (ret != 0) {
+    1204                 :          0 :                     goto exit;
+    1205                 :            :                 }
+    1206         [ #  # ]:          0 :                 if (olen != pt_len_test_data[i]) {
+    1207                 :          0 :                     goto exit;
+    1208                 :            :                 }
+    1209                 :            :             }
+    1210                 :            : 
+    1211                 :          0 :             ret = mbedtls_gcm_finish(&ctx, NULL, 0, &olen, tag_buf, 16);
+    1212         [ #  # ]:          0 :             if (ret != 0) {
+    1213                 :          0 :                 goto exit;
+    1214                 :            :             }
+    1215                 :            : 
+    1216                 :          0 :             if (memcmp(buf, ct_test_data[j * 6 + i],
+    1217         [ #  # ]:          0 :                        pt_len_test_data[i]) != 0 ||
+    1218         [ #  # ]:          0 :                 memcmp(tag_buf, tag_test_data[j * 6 + i], 16) != 0) {
+    1219                 :          0 :                 ret = 1;
+    1220                 :          0 :                 goto exit;
+    1221                 :            :             }
+    1222                 :            : 
+    1223                 :          0 :             mbedtls_gcm_free(&ctx);
+    1224                 :            : 
+    1225         [ #  # ]:          0 :             if (verbose != 0) {
+    1226                 :          0 :                 mbedtls_printf("passed\n");
+    1227                 :            :             }
+    1228                 :            : 
+    1229                 :          0 :             mbedtls_gcm_init(&ctx);
+    1230                 :            : 
+    1231         [ #  # ]:          0 :             if (verbose != 0) {
+    1232                 :          0 :                 mbedtls_printf("  AES-GCM-%3d #%d split (%s): ",
+    1233                 :            :                                key_len, i, "dec");
+    1234                 :            :             }
+    1235                 :            : 
+    1236                 :          0 :             ret = mbedtls_gcm_setkey(&ctx, cipher,
+    1237                 :          0 :                                      key_test_data[key_index_test_data[i]],
+    1238                 :            :                                      key_len);
+    1239         [ #  # ]:          0 :             if (ret != 0) {
+    1240                 :          0 :                 goto exit;
+    1241                 :            :             }
+    1242                 :            : 
+    1243                 :          0 :             ret = mbedtls_gcm_starts(&ctx, MBEDTLS_GCM_DECRYPT,
+    1244                 :          0 :                                      iv_test_data[iv_index_test_data[i]],
+    1245                 :          0 :                                      iv_len_test_data[i]);
+    1246         [ #  # ]:          0 :             if (ret != 0) {
+    1247                 :          0 :                 goto exit;
+    1248                 :            :             }
+    1249                 :          0 :             ret = mbedtls_gcm_update_ad(&ctx,
+    1250                 :          0 :                                         additional_test_data[add_index_test_data[i]],
+    1251                 :          0 :                                         add_len_test_data[i]);
+    1252         [ #  # ]:          0 :             if (ret != 0) {
+    1253                 :          0 :                 goto exit;
+    1254                 :            :             }
+    1255                 :            : 
+    1256         [ #  # ]:          0 :             if (pt_len_test_data[i] > 32) {
+    1257                 :          0 :                 size_t rest_len = pt_len_test_data[i] - 32;
+    1258                 :          0 :                 ret = mbedtls_gcm_update(&ctx,
+    1259                 :          0 :                                          ct_test_data[j * 6 + i], 32,
+    1260                 :            :                                          buf, sizeof(buf), &olen);
+    1261         [ #  # ]:          0 :                 if (ret != 0) {
+    1262                 :          0 :                     goto exit;
+    1263                 :            :                 }
+    1264         [ #  # ]:          0 :                 if (olen != 32) {
+    1265                 :          0 :                     goto exit;
+    1266                 :            :                 }
+    1267                 :            : 
+    1268                 :          0 :                 ret = mbedtls_gcm_update(&ctx,
+    1269                 :          0 :                                          ct_test_data[j * 6 + i] + 32,
+    1270                 :            :                                          rest_len,
+    1271                 :            :                                          buf + 32, sizeof(buf) - 32, &olen);
+    1272         [ #  # ]:          0 :                 if (ret != 0) {
+    1273                 :          0 :                     goto exit;
+    1274                 :            :                 }
+    1275         [ #  # ]:          0 :                 if (olen != rest_len) {
+    1276                 :          0 :                     goto exit;
+    1277                 :            :                 }
+    1278                 :            :             } else {
+    1279                 :          0 :                 ret = mbedtls_gcm_update(&ctx,
+    1280                 :          0 :                                          ct_test_data[j * 6 + i],
+    1281                 :          0 :                                          pt_len_test_data[i],
+    1282                 :            :                                          buf, sizeof(buf), &olen);
+    1283         [ #  # ]:          0 :                 if (ret != 0) {
+    1284                 :          0 :                     goto exit;
+    1285                 :            :                 }
+    1286         [ #  # ]:          0 :                 if (olen != pt_len_test_data[i]) {
+    1287                 :          0 :                     goto exit;
+    1288                 :            :                 }
+    1289                 :            :             }
+    1290                 :            : 
+    1291                 :          0 :             ret = mbedtls_gcm_finish(&ctx, NULL, 0, &olen, tag_buf, 16);
+    1292         [ #  # ]:          0 :             if (ret != 0) {
+    1293                 :          0 :                 goto exit;
+    1294                 :            :             }
+    1295                 :            : 
+    1296                 :          0 :             if (memcmp(buf, pt_test_data[pt_index_test_data[i]],
+    1297         [ #  # ]:          0 :                        pt_len_test_data[i]) != 0 ||
+    1298         [ #  # ]:          0 :                 memcmp(tag_buf, tag_test_data[j * 6 + i], 16) != 0) {
+    1299                 :          0 :                 ret = 1;
+    1300                 :          0 :                 goto exit;
+    1301                 :            :             }
+    1302                 :            : 
+    1303                 :          0 :             mbedtls_gcm_free(&ctx);
+    1304                 :            : 
+    1305         [ #  # ]:          0 :             if (verbose != 0) {
+    1306                 :          0 :                 mbedtls_printf("passed\n");
+    1307                 :            :             }
+    1308                 :            :         }
+    1309                 :            :     }
+    1310                 :            : 
+    1311         [ #  # ]:          0 :     if (verbose != 0) {
+    1312                 :          0 :         mbedtls_printf("\n");
+    1313                 :            :     }
+    1314                 :            : 
+    1315                 :          0 :     ret = 0;
+    1316                 :            : 
+    1317                 :          0 : exit:
+    1318         [ #  # ]:          0 :     if (ret != 0) {
+    1319         [ #  # ]:          0 :         if (verbose != 0) {
+    1320                 :          0 :             mbedtls_printf("failed\n");
+    1321                 :            :         }
+    1322                 :          0 :         mbedtls_gcm_free(&ctx);
+    1323                 :            :     }
+    1324                 :            : 
+    1325                 :          0 :     return ret;
+    1326                 :            : }
+    1327                 :            : 
+    1328                 :            : #endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */
+    1329                 :            : 
+    1330                 :            : #endif /* MBEDTLS_GCM_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/hkdf.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/hkdf.c.func-sort-c.html new file mode 100644 index 00000000000..b1970fe2c4e --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/hkdf.c.func-sort-c.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/hkdf.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - hkdf.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:396460.9 %
Date:2024-09-22 08:21:07Functions:2366.7 %
Branches:183650.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_hkdf0
mbedtls_hkdf_extract189
mbedtls_hkdf_expand1227
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/hkdf.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/hkdf.c.func.html new file mode 100644 index 00000000000..2932283a285 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/hkdf.c.func.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/hkdf.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - hkdf.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:396460.9 %
Date:2024-09-22 08:21:07Functions:2366.7 %
Branches:183650.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_hkdf0
mbedtls_hkdf_expand1227
mbedtls_hkdf_extract189
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/hkdf.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/hkdf.c.gcov.html new file mode 100644 index 00000000000..f02c1bdb020 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/hkdf.c.gcov.html @@ -0,0 +1,246 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/hkdf.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - hkdf.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:396460.9 %
Date:2024-09-22 08:21:07Functions:2366.7 %
Branches:183650.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  *  HKDF implementation -- RFC 5869
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  */
+       7                 :            : #include "common.h"
+       8                 :            : 
+       9                 :            : #if defined(MBEDTLS_HKDF_C)
+      10                 :            : 
+      11                 :            : #include <string.h>
+      12                 :            : #include "mbedtls/hkdf.h"
+      13                 :            : #include "mbedtls/platform_util.h"
+      14                 :            : #include "mbedtls/error.h"
+      15                 :            : 
+      16                 :          0 : int mbedtls_hkdf(const mbedtls_md_info_t *md, const unsigned char *salt,
+      17                 :            :                  size_t salt_len, const unsigned char *ikm, size_t ikm_len,
+      18                 :            :                  const unsigned char *info, size_t info_len,
+      19                 :            :                  unsigned char *okm, size_t okm_len)
+      20                 :            : {
+      21                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+      22                 :            :     unsigned char prk[MBEDTLS_MD_MAX_SIZE];
+      23                 :            : 
+      24                 :          0 :     ret = mbedtls_hkdf_extract(md, salt, salt_len, ikm, ikm_len, prk);
+      25                 :            : 
+      26         [ #  # ]:          0 :     if (ret == 0) {
+      27                 :          0 :         ret = mbedtls_hkdf_expand(md, prk, mbedtls_md_get_size(md),
+      28                 :            :                                   info, info_len, okm, okm_len);
+      29                 :            :     }
+      30                 :            : 
+      31                 :          0 :     mbedtls_platform_zeroize(prk, sizeof(prk));
+      32                 :            : 
+      33                 :          0 :     return ret;
+      34                 :            : }
+      35                 :            : 
+      36                 :        189 : int mbedtls_hkdf_extract(const mbedtls_md_info_t *md,
+      37                 :            :                          const unsigned char *salt, size_t salt_len,
+      38                 :            :                          const unsigned char *ikm, size_t ikm_len,
+      39                 :            :                          unsigned char *prk)
+      40                 :            : {
+      41                 :        189 :     unsigned char null_salt[MBEDTLS_MD_MAX_SIZE] = { '\0' };
+      42                 :            : 
+      43         [ -  + ]:        189 :     if (salt == NULL) {
+      44                 :            :         size_t hash_len;
+      45                 :            : 
+      46         [ #  # ]:          0 :         if (salt_len != 0) {
+      47                 :          0 :             return MBEDTLS_ERR_HKDF_BAD_INPUT_DATA;
+      48                 :            :         }
+      49                 :            : 
+      50                 :          0 :         hash_len = mbedtls_md_get_size(md);
+      51                 :            : 
+      52         [ #  # ]:          0 :         if (hash_len == 0) {
+      53                 :          0 :             return MBEDTLS_ERR_HKDF_BAD_INPUT_DATA;
+      54                 :            :         }
+      55                 :            : 
+      56                 :          0 :         salt = null_salt;
+      57                 :          0 :         salt_len = hash_len;
+      58                 :            :     }
+      59                 :            : 
+      60                 :        189 :     return mbedtls_md_hmac(md, salt, salt_len, ikm, ikm_len, prk);
+      61                 :            : }
+      62                 :            : 
+      63                 :       1227 : int mbedtls_hkdf_expand(const mbedtls_md_info_t *md, const unsigned char *prk,
+      64                 :            :                         size_t prk_len, const unsigned char *info,
+      65                 :            :                         size_t info_len, unsigned char *okm, size_t okm_len)
+      66                 :            : {
+      67                 :            :     size_t hash_len;
+      68                 :       1227 :     size_t where = 0;
+      69                 :            :     size_t n;
+      70                 :       1227 :     size_t t_len = 0;
+      71                 :            :     size_t i;
+      72                 :       1227 :     int ret = 0;
+      73                 :            :     mbedtls_md_context_t ctx;
+      74                 :            :     unsigned char t[MBEDTLS_MD_MAX_SIZE];
+      75                 :            : 
+      76         [ -  + ]:       1227 :     if (okm == NULL) {
+      77                 :          0 :         return MBEDTLS_ERR_HKDF_BAD_INPUT_DATA;
+      78                 :            :     }
+      79                 :            : 
+      80                 :       1227 :     hash_len = mbedtls_md_get_size(md);
+      81                 :            : 
+      82   [ +  -  -  + ]:       1227 :     if (prk_len < hash_len || hash_len == 0) {
+      83                 :          0 :         return MBEDTLS_ERR_HKDF_BAD_INPUT_DATA;
+      84                 :            :     }
+      85                 :            : 
+      86         [ -  + ]:       1227 :     if (info == NULL) {
+      87                 :          0 :         info = (const unsigned char *) "";
+      88                 :          0 :         info_len = 0;
+      89                 :            :     }
+      90                 :            : 
+      91                 :       1227 :     n = okm_len / hash_len;
+      92                 :            : 
+      93         [ +  + ]:       1227 :     if (okm_len % hash_len != 0) {
+      94                 :        279 :         n++;
+      95                 :            :     }
+      96                 :            : 
+      97                 :            :     /*
+      98                 :            :      * Per RFC 5869 Section 2.3, okm_len must not exceed
+      99                 :            :      * 255 times the hash length
+     100                 :            :      */
+     101         [ -  + ]:       1227 :     if (n > 255) {
+     102                 :          0 :         return MBEDTLS_ERR_HKDF_BAD_INPUT_DATA;
+     103                 :            :     }
+     104                 :            : 
+     105                 :       1227 :     mbedtls_md_init(&ctx);
+     106                 :            : 
+     107         [ -  + ]:       1227 :     if ((ret = mbedtls_md_setup(&ctx, md, 1)) != 0) {
+     108                 :          0 :         goto exit;
+     109                 :            :     }
+     110                 :            : 
+     111                 :       1227 :     memset(t, 0, hash_len);
+     112                 :            : 
+     113                 :            :     /*
+     114                 :            :      * Compute T = T(1) | T(2) | T(3) | ... | T(N)
+     115                 :            :      * Where T(N) is defined in RFC 5869 Section 2.3
+     116                 :            :      */
+     117         [ +  + ]:       2490 :     for (i = 1; i <= n; i++) {
+     118                 :            :         size_t num_to_copy;
+     119                 :       1263 :         unsigned char c = i & 0xff;
+     120                 :            : 
+     121                 :       1263 :         ret = mbedtls_md_hmac_starts(&ctx, prk, prk_len);
+     122         [ -  + ]:       1263 :         if (ret != 0) {
+     123                 :          0 :             goto exit;
+     124                 :            :         }
+     125                 :            : 
+     126                 :       1263 :         ret = mbedtls_md_hmac_update(&ctx, t, t_len);
+     127         [ -  + ]:       1263 :         if (ret != 0) {
+     128                 :          0 :             goto exit;
+     129                 :            :         }
+     130                 :            : 
+     131                 :       1263 :         ret = mbedtls_md_hmac_update(&ctx, info, info_len);
+     132         [ -  + ]:       1263 :         if (ret != 0) {
+     133                 :          0 :             goto exit;
+     134                 :            :         }
+     135                 :            : 
+     136                 :            :         /* The constant concatenated to the end of each T(n) is a single octet.
+     137                 :            :          * */
+     138                 :       1263 :         ret = mbedtls_md_hmac_update(&ctx, &c, 1);
+     139         [ -  + ]:       1263 :         if (ret != 0) {
+     140                 :          0 :             goto exit;
+     141                 :            :         }
+     142                 :            : 
+     143                 :       1263 :         ret = mbedtls_md_hmac_finish(&ctx, t);
+     144         [ -  + ]:       1263 :         if (ret != 0) {
+     145                 :          0 :             goto exit;
+     146                 :            :         }
+     147                 :            : 
+     148         [ +  + ]:       1263 :         num_to_copy = i != n ? hash_len : okm_len - where;
+     149                 :       1263 :         memcpy(okm + where, t, num_to_copy);
+     150                 :       1263 :         where += hash_len;
+     151                 :       1263 :         t_len = hash_len;
+     152                 :            :     }
+     153                 :            : 
+     154                 :       1227 : exit:
+     155                 :       1227 :     mbedtls_md_free(&ctx);
+     156                 :       1227 :     mbedtls_platform_zeroize(t, sizeof(t));
+     157                 :            : 
+     158                 :       1227 :     return ret;
+     159                 :            : }
+     160                 :            : 
+     161                 :            : #endif /* MBEDTLS_HKDF_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/hmac_drbg.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/hmac_drbg.c.func-sort-c.html new file mode 100644 index 00000000000..dea6196ae0e --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/hmac_drbg.c.func-sort-c.html @@ -0,0 +1,137 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/hmac_drbg.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - hmac_drbg.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:6417836.0 %
Date:2024-09-22 08:21:07Functions:61442.9 %
Branches:2913621.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
hmac_drbg_reseed_core0
hmac_drbg_self_test_entropy0
mbedtls_hmac_drbg_reseed0
mbedtls_hmac_drbg_seed0
mbedtls_hmac_drbg_self_test0
mbedtls_hmac_drbg_set_entropy_len0
mbedtls_hmac_drbg_set_prediction_resistance0
mbedtls_hmac_drbg_set_reseed_interval0
mbedtls_hmac_drbg_free6
mbedtls_hmac_drbg_init6
mbedtls_hmac_drbg_random6
mbedtls_hmac_drbg_random_with_add6
mbedtls_hmac_drbg_seed_buf6
mbedtls_hmac_drbg_update12
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/hmac_drbg.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/hmac_drbg.c.func.html new file mode 100644 index 00000000000..d5f17d03281 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/hmac_drbg.c.func.html @@ -0,0 +1,137 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/hmac_drbg.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - hmac_drbg.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:6417836.0 %
Date:2024-09-22 08:21:07Functions:61442.9 %
Branches:2913621.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
hmac_drbg_reseed_core0
hmac_drbg_self_test_entropy0
mbedtls_hmac_drbg_free6
mbedtls_hmac_drbg_init6
mbedtls_hmac_drbg_random6
mbedtls_hmac_drbg_random_with_add6
mbedtls_hmac_drbg_reseed0
mbedtls_hmac_drbg_seed0
mbedtls_hmac_drbg_seed_buf6
mbedtls_hmac_drbg_self_test0
mbedtls_hmac_drbg_set_entropy_len0
mbedtls_hmac_drbg_set_prediction_resistance0
mbedtls_hmac_drbg_set_reseed_interval0
mbedtls_hmac_drbg_update12
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/hmac_drbg.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/hmac_drbg.c.gcov.html new file mode 100644 index 00000000000..c5fafa516ad --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/hmac_drbg.c.gcov.html @@ -0,0 +1,718 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/hmac_drbg.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - hmac_drbg.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:6417836.0 %
Date:2024-09-22 08:21:07Functions:61442.9 %
Branches:2913621.3 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  *  HMAC_DRBG implementation (NIST SP 800-90)
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  */
+       7                 :            : 
+       8                 :            : /*
+       9                 :            :  *  The NIST SP 800-90A DRBGs are described in the following publication.
+      10                 :            :  *  http://csrc.nist.gov/publications/nistpubs/800-90A/SP800-90A.pdf
+      11                 :            :  *  References below are based on rev. 1 (January 2012).
+      12                 :            :  */
+      13                 :            : 
+      14                 :            : #include "common.h"
+      15                 :            : 
+      16                 :            : #if defined(MBEDTLS_HMAC_DRBG_C)
+      17                 :            : 
+      18                 :            : #include "mbedtls/hmac_drbg.h"
+      19                 :            : #include "mbedtls/platform_util.h"
+      20                 :            : #include "mbedtls/error.h"
+      21                 :            : 
+      22                 :            : #include <string.h>
+      23                 :            : 
+      24                 :            : #if defined(MBEDTLS_FS_IO)
+      25                 :            : #include <stdio.h>
+      26                 :            : #endif
+      27                 :            : 
+      28                 :            : #include "mbedtls/platform.h"
+      29                 :            : 
+      30                 :            : /*
+      31                 :            :  * HMAC_DRBG context initialization
+      32                 :            :  */
+      33                 :          6 : void mbedtls_hmac_drbg_init(mbedtls_hmac_drbg_context *ctx)
+      34                 :            : {
+      35                 :          6 :     memset(ctx, 0, sizeof(mbedtls_hmac_drbg_context));
+      36                 :            : 
+      37                 :          6 :     ctx->reseed_interval = MBEDTLS_HMAC_DRBG_RESEED_INTERVAL;
+      38                 :          6 : }
+      39                 :            : 
+      40                 :            : /*
+      41                 :            :  * HMAC_DRBG update, using optional additional data (10.1.2.2)
+      42                 :            :  */
+      43                 :         12 : int mbedtls_hmac_drbg_update(mbedtls_hmac_drbg_context *ctx,
+      44                 :            :                              const unsigned char *additional,
+      45                 :            :                              size_t add_len)
+      46                 :            : {
+      47                 :         12 :     size_t md_len = mbedtls_md_get_size(ctx->md_ctx.md_info);
+      48   [ +  +  +  - ]:         12 :     unsigned char rounds = (additional != NULL && add_len != 0) ? 2 : 1;
+      49                 :            :     unsigned char sep[1];
+      50                 :            :     unsigned char K[MBEDTLS_MD_MAX_SIZE];
+      51                 :         12 :     int ret = MBEDTLS_ERR_MD_BAD_INPUT_DATA;
+      52                 :            : 
+      53         [ +  + ]:         30 :     for (sep[0] = 0; sep[0] < rounds; sep[0]++) {
+      54                 :            :         /* Step 1 or 4 */
+      55         [ -  + ]:         18 :         if ((ret = mbedtls_md_hmac_reset(&ctx->md_ctx)) != 0) {
+      56                 :          0 :             goto exit;
+      57                 :            :         }
+      58         [ -  + ]:         18 :         if ((ret = mbedtls_md_hmac_update(&ctx->md_ctx,
+      59                 :         18 :                                           ctx->V, md_len)) != 0) {
+      60                 :          0 :             goto exit;
+      61                 :            :         }
+      62         [ -  + ]:         18 :         if ((ret = mbedtls_md_hmac_update(&ctx->md_ctx,
+      63                 :            :                                           sep, 1)) != 0) {
+      64                 :          0 :             goto exit;
+      65                 :            :         }
+      66         [ +  + ]:         18 :         if (rounds == 2) {
+      67         [ -  + ]:         12 :             if ((ret = mbedtls_md_hmac_update(&ctx->md_ctx,
+      68                 :            :                                               additional, add_len)) != 0) {
+      69                 :          0 :                 goto exit;
+      70                 :            :             }
+      71                 :            :         }
+      72         [ -  + ]:         18 :         if ((ret = mbedtls_md_hmac_finish(&ctx->md_ctx, K)) != 0) {
+      73                 :          0 :             goto exit;
+      74                 :            :         }
+      75                 :            : 
+      76                 :            :         /* Step 2 or 5 */
+      77         [ -  + ]:         18 :         if ((ret = mbedtls_md_hmac_starts(&ctx->md_ctx, K, md_len)) != 0) {
+      78                 :          0 :             goto exit;
+      79                 :            :         }
+      80         [ -  + ]:         18 :         if ((ret = mbedtls_md_hmac_update(&ctx->md_ctx,
+      81                 :         18 :                                           ctx->V, md_len)) != 0) {
+      82                 :          0 :             goto exit;
+      83                 :            :         }
+      84         [ -  + ]:         18 :         if ((ret = mbedtls_md_hmac_finish(&ctx->md_ctx, ctx->V)) != 0) {
+      85                 :          0 :             goto exit;
+      86                 :            :         }
+      87                 :            :     }
+      88                 :            : 
+      89                 :         12 : exit:
+      90                 :         12 :     mbedtls_platform_zeroize(K, sizeof(K));
+      91                 :         12 :     return ret;
+      92                 :            : }
+      93                 :            : 
+      94                 :            : /*
+      95                 :            :  * Simplified HMAC_DRBG initialisation (for use with deterministic ECDSA)
+      96                 :            :  */
+      97                 :          6 : int mbedtls_hmac_drbg_seed_buf(mbedtls_hmac_drbg_context *ctx,
+      98                 :            :                                const mbedtls_md_info_t *md_info,
+      99                 :            :                                const unsigned char *data, size_t data_len)
+     100                 :            : {
+     101                 :          6 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     102                 :            : 
+     103         [ -  + ]:          6 :     if ((ret = mbedtls_md_setup(&ctx->md_ctx, md_info, 1)) != 0) {
+     104                 :          0 :         return ret;
+     105                 :            :     }
+     106                 :            : 
+     107                 :            : #if defined(MBEDTLS_THREADING_C)
+     108                 :            :     mbedtls_mutex_init(&ctx->mutex);
+     109                 :            : #endif
+     110                 :            : 
+     111                 :            :     /*
+     112                 :            :      * Set initial working state.
+     113                 :            :      * Use the V memory location, which is currently all 0, to initialize the
+     114                 :            :      * MD context with an all-zero key. Then set V to its initial value.
+     115                 :            :      */
+     116         [ -  + ]:          6 :     if ((ret = mbedtls_md_hmac_starts(&ctx->md_ctx, ctx->V,
+     117                 :          6 :                                       mbedtls_md_get_size(md_info))) != 0) {
+     118                 :          0 :         return ret;
+     119                 :            :     }
+     120                 :          6 :     memset(ctx->V, 0x01, mbedtls_md_get_size(md_info));
+     121                 :            : 
+     122         [ -  + ]:          6 :     if ((ret = mbedtls_hmac_drbg_update(ctx, data, data_len)) != 0) {
+     123                 :          0 :         return ret;
+     124                 :            :     }
+     125                 :            : 
+     126                 :          6 :     return 0;
+     127                 :            : }
+     128                 :            : 
+     129                 :            : /*
+     130                 :            :  * Internal function used both for seeding and reseeding the DRBG.
+     131                 :            :  * Comments starting with arabic numbers refer to section 10.1.2.4
+     132                 :            :  * of SP800-90A, while roman numbers refer to section 9.2.
+     133                 :            :  */
+     134                 :          0 : static int hmac_drbg_reseed_core(mbedtls_hmac_drbg_context *ctx,
+     135                 :            :                                  const unsigned char *additional, size_t len,
+     136                 :            :                                  int use_nonce)
+     137                 :            : {
+     138                 :            :     unsigned char seed[MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT];
+     139                 :          0 :     size_t seedlen = 0;
+     140                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     141                 :            : 
+     142                 :            :     {
+     143                 :            :         size_t total_entropy_len;
+     144                 :            : 
+     145         [ #  # ]:          0 :         if (use_nonce == 0) {
+     146                 :          0 :             total_entropy_len = ctx->entropy_len;
+     147                 :            :         } else {
+     148                 :          0 :             total_entropy_len = ctx->entropy_len * 3 / 2;
+     149                 :            :         }
+     150                 :            : 
+     151                 :            :         /* III. Check input length */
+     152         [ #  # ]:          0 :         if (len > MBEDTLS_HMAC_DRBG_MAX_INPUT ||
+     153         [ #  # ]:          0 :             total_entropy_len + len > MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT) {
+     154                 :          0 :             return MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG;
+     155                 :            :         }
+     156                 :            :     }
+     157                 :            : 
+     158                 :          0 :     memset(seed, 0, MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT);
+     159                 :            : 
+     160                 :            :     /* IV. Gather entropy_len bytes of entropy for the seed */
+     161         [ #  # ]:          0 :     if ((ret = ctx->f_entropy(ctx->p_entropy,
+     162                 :            :                               seed, ctx->entropy_len)) != 0) {
+     163                 :          0 :         return MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED;
+     164                 :            :     }
+     165                 :          0 :     seedlen += ctx->entropy_len;
+     166                 :            : 
+     167                 :            :     /* For initial seeding, allow adding of nonce generated
+     168                 :            :      * from the entropy source. See Sect 8.6.7 in SP800-90A. */
+     169         [ #  # ]:          0 :     if (use_nonce) {
+     170                 :            :         /* Note: We don't merge the two calls to f_entropy() in order
+     171                 :            :          *       to avoid requesting too much entropy from f_entropy()
+     172                 :            :          *       at once. Specifically, if the underlying digest is not
+     173                 :            :          *       SHA-1, 3 / 2 * entropy_len is at least 36 Bytes, which
+     174                 :            :          *       is larger than the maximum of 32 Bytes that our own
+     175                 :            :          *       entropy source implementation can emit in a single
+     176                 :            :          *       call in configurations disabling SHA-512. */
+     177         [ #  # ]:          0 :         if ((ret = ctx->f_entropy(ctx->p_entropy,
+     178                 :            :                                   seed + seedlen,
+     179                 :          0 :                                   ctx->entropy_len / 2)) != 0) {
+     180                 :          0 :             return MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED;
+     181                 :            :         }
+     182                 :            : 
+     183                 :          0 :         seedlen += ctx->entropy_len / 2;
+     184                 :            :     }
+     185                 :            : 
+     186                 :            : 
+     187                 :            :     /* 1. Concatenate entropy and additional data if any */
+     188   [ #  #  #  # ]:          0 :     if (additional != NULL && len != 0) {
+     189                 :          0 :         memcpy(seed + seedlen, additional, len);
+     190                 :          0 :         seedlen += len;
+     191                 :            :     }
+     192                 :            : 
+     193                 :            :     /* 2. Update state */
+     194         [ #  # ]:          0 :     if ((ret = mbedtls_hmac_drbg_update(ctx, seed, seedlen)) != 0) {
+     195                 :          0 :         goto exit;
+     196                 :            :     }
+     197                 :            : 
+     198                 :            :     /* 3. Reset reseed_counter */
+     199                 :          0 :     ctx->reseed_counter = 1;
+     200                 :            : 
+     201                 :          0 : exit:
+     202                 :            :     /* 4. Done */
+     203                 :          0 :     mbedtls_platform_zeroize(seed, seedlen);
+     204                 :          0 :     return ret;
+     205                 :            : }
+     206                 :            : 
+     207                 :            : /*
+     208                 :            :  * HMAC_DRBG reseeding: 10.1.2.4 + 9.2
+     209                 :            :  */
+     210                 :          0 : int mbedtls_hmac_drbg_reseed(mbedtls_hmac_drbg_context *ctx,
+     211                 :            :                              const unsigned char *additional, size_t len)
+     212                 :            : {
+     213                 :          0 :     return hmac_drbg_reseed_core(ctx, additional, len, 0);
+     214                 :            : }
+     215                 :            : 
+     216                 :            : /*
+     217                 :            :  * HMAC_DRBG initialisation (10.1.2.3 + 9.1)
+     218                 :            :  *
+     219                 :            :  * The nonce is not passed as a separate parameter but extracted
+     220                 :            :  * from the entropy source as suggested in 8.6.7.
+     221                 :            :  */
+     222                 :          0 : int mbedtls_hmac_drbg_seed(mbedtls_hmac_drbg_context *ctx,
+     223                 :            :                            const mbedtls_md_info_t *md_info,
+     224                 :            :                            int (*f_entropy)(void *, unsigned char *, size_t),
+     225                 :            :                            void *p_entropy,
+     226                 :            :                            const unsigned char *custom,
+     227                 :            :                            size_t len)
+     228                 :            : {
+     229                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     230                 :            :     size_t md_size;
+     231                 :            : 
+     232         [ #  # ]:          0 :     if ((ret = mbedtls_md_setup(&ctx->md_ctx, md_info, 1)) != 0) {
+     233                 :          0 :         return ret;
+     234                 :            :     }
+     235                 :            : 
+     236                 :            :     /* The mutex is initialized iff the md context is set up. */
+     237                 :            : #if defined(MBEDTLS_THREADING_C)
+     238                 :            :     mbedtls_mutex_init(&ctx->mutex);
+     239                 :            : #endif
+     240                 :            : 
+     241                 :          0 :     md_size = mbedtls_md_get_size(md_info);
+     242                 :            : 
+     243                 :            :     /*
+     244                 :            :      * Set initial working state.
+     245                 :            :      * Use the V memory location, which is currently all 0, to initialize the
+     246                 :            :      * MD context with an all-zero key. Then set V to its initial value.
+     247                 :            :      */
+     248         [ #  # ]:          0 :     if ((ret = mbedtls_md_hmac_starts(&ctx->md_ctx, ctx->V, md_size)) != 0) {
+     249                 :          0 :         return ret;
+     250                 :            :     }
+     251                 :          0 :     memset(ctx->V, 0x01, md_size);
+     252                 :            : 
+     253                 :          0 :     ctx->f_entropy = f_entropy;
+     254                 :          0 :     ctx->p_entropy = p_entropy;
+     255                 :            : 
+     256         [ #  # ]:          0 :     if (ctx->entropy_len == 0) {
+     257                 :            :         /*
+     258                 :            :          * See SP800-57 5.6.1 (p. 65-66) for the security strength provided by
+     259                 :            :          * each hash function, then according to SP800-90A rev1 10.1 table 2,
+     260                 :            :          * min_entropy_len (in bits) is security_strength.
+     261                 :            :          *
+     262                 :            :          * (This also matches the sizes used in the NIST test vectors.)
+     263                 :            :          */
+     264   [ #  #  #  # ]:          0 :         ctx->entropy_len = md_size <= 20 ? 16 : /* 160-bits hash -> 128 bits */
+     265                 :            :                            md_size <= 28 ? 24 : /* 224-bits hash -> 192 bits */
+     266                 :            :                            32;  /* better (256+) -> 256 bits */
+     267                 :            :     }
+     268                 :            : 
+     269         [ #  # ]:          0 :     if ((ret = hmac_drbg_reseed_core(ctx, custom, len,
+     270                 :            :                                      1 /* add nonce */)) != 0) {
+     271                 :          0 :         return ret;
+     272                 :            :     }
+     273                 :            : 
+     274                 :          0 :     return 0;
+     275                 :            : }
+     276                 :            : 
+     277                 :            : /*
+     278                 :            :  * Set prediction resistance
+     279                 :            :  */
+     280                 :          0 : void mbedtls_hmac_drbg_set_prediction_resistance(mbedtls_hmac_drbg_context *ctx,
+     281                 :            :                                                  int resistance)
+     282                 :            : {
+     283                 :          0 :     ctx->prediction_resistance = resistance;
+     284                 :          0 : }
+     285                 :            : 
+     286                 :            : /*
+     287                 :            :  * Set entropy length grabbed for seeding
+     288                 :            :  */
+     289                 :          0 : void mbedtls_hmac_drbg_set_entropy_len(mbedtls_hmac_drbg_context *ctx, size_t len)
+     290                 :            : {
+     291                 :          0 :     ctx->entropy_len = len;
+     292                 :          0 : }
+     293                 :            : 
+     294                 :            : /*
+     295                 :            :  * Set reseed interval
+     296                 :            :  */
+     297                 :          0 : void mbedtls_hmac_drbg_set_reseed_interval(mbedtls_hmac_drbg_context *ctx, int interval)
+     298                 :            : {
+     299                 :          0 :     ctx->reseed_interval = interval;
+     300                 :          0 : }
+     301                 :            : 
+     302                 :            : /*
+     303                 :            :  * HMAC_DRBG random function with optional additional data:
+     304                 :            :  * 10.1.2.5 (arabic) + 9.3 (Roman)
+     305                 :            :  */
+     306                 :          6 : int mbedtls_hmac_drbg_random_with_add(void *p_rng,
+     307                 :            :                                       unsigned char *output, size_t out_len,
+     308                 :            :                                       const unsigned char *additional, size_t add_len)
+     309                 :            : {
+     310                 :          6 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     311                 :          6 :     mbedtls_hmac_drbg_context *ctx = (mbedtls_hmac_drbg_context *) p_rng;
+     312                 :          6 :     size_t md_len = mbedtls_md_get_size(ctx->md_ctx.md_info);
+     313                 :          6 :     size_t left = out_len;
+     314                 :          6 :     unsigned char *out = output;
+     315                 :            : 
+     316                 :            :     /* II. Check request length */
+     317         [ -  + ]:          6 :     if (out_len > MBEDTLS_HMAC_DRBG_MAX_REQUEST) {
+     318                 :          0 :         return MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG;
+     319                 :            :     }
+     320                 :            : 
+     321                 :            :     /* III. Check input length */
+     322         [ -  + ]:          6 :     if (add_len > MBEDTLS_HMAC_DRBG_MAX_INPUT) {
+     323                 :          0 :         return MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG;
+     324                 :            :     }
+     325                 :            : 
+     326                 :            :     /* 1. (aka VII and IX) Check reseed counter and PR */
+     327         [ -  + ]:          6 :     if (ctx->f_entropy != NULL && /* For no-reseeding instances */
+     328         [ #  # ]:          0 :         (ctx->prediction_resistance == MBEDTLS_HMAC_DRBG_PR_ON ||
+     329         [ #  # ]:          0 :          ctx->reseed_counter > ctx->reseed_interval)) {
+     330         [ #  # ]:          0 :         if ((ret = mbedtls_hmac_drbg_reseed(ctx, additional, add_len)) != 0) {
+     331                 :          0 :             return ret;
+     332                 :            :         }
+     333                 :            : 
+     334                 :          0 :         add_len = 0; /* VII.4 */
+     335                 :            :     }
+     336                 :            : 
+     337                 :            :     /* 2. Use additional data if any */
+     338   [ -  +  -  - ]:          6 :     if (additional != NULL && add_len != 0) {
+     339         [ #  # ]:          0 :         if ((ret = mbedtls_hmac_drbg_update(ctx,
+     340                 :            :                                             additional, add_len)) != 0) {
+     341                 :          0 :             goto exit;
+     342                 :            :         }
+     343                 :            :     }
+     344                 :            : 
+     345                 :            :     /* 3, 4, 5. Generate bytes */
+     346         [ +  + ]:         12 :     while (left != 0) {
+     347                 :          6 :         size_t use_len = left > md_len ? md_len : left;
+     348                 :            : 
+     349         [ -  + ]:          6 :         if ((ret = mbedtls_md_hmac_reset(&ctx->md_ctx)) != 0) {
+     350                 :          0 :             goto exit;
+     351                 :            :         }
+     352         [ -  + ]:          6 :         if ((ret = mbedtls_md_hmac_update(&ctx->md_ctx,
+     353                 :          6 :                                           ctx->V, md_len)) != 0) {
+     354                 :          0 :             goto exit;
+     355                 :            :         }
+     356         [ -  + ]:          6 :         if ((ret = mbedtls_md_hmac_finish(&ctx->md_ctx, ctx->V)) != 0) {
+     357                 :          0 :             goto exit;
+     358                 :            :         }
+     359                 :            : 
+     360                 :          6 :         memcpy(out, ctx->V, use_len);
+     361                 :          6 :         out += use_len;
+     362                 :          6 :         left -= use_len;
+     363                 :            :     }
+     364                 :            : 
+     365                 :            :     /* 6. Update */
+     366         [ -  + ]:          6 :     if ((ret = mbedtls_hmac_drbg_update(ctx,
+     367                 :            :                                         additional, add_len)) != 0) {
+     368                 :          0 :         goto exit;
+     369                 :            :     }
+     370                 :            : 
+     371                 :            :     /* 7. Update reseed counter */
+     372                 :          6 :     ctx->reseed_counter++;
+     373                 :            : 
+     374                 :          6 : exit:
+     375                 :            :     /* 8. Done */
+     376                 :          6 :     return ret;
+     377                 :            : }
+     378                 :            : 
+     379                 :            : /*
+     380                 :            :  * HMAC_DRBG random function
+     381                 :            :  */
+     382                 :          6 : int mbedtls_hmac_drbg_random(void *p_rng, unsigned char *output, size_t out_len)
+     383                 :            : {
+     384                 :          6 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     385                 :          6 :     mbedtls_hmac_drbg_context *ctx = (mbedtls_hmac_drbg_context *) p_rng;
+     386                 :            : 
+     387                 :            : #if defined(MBEDTLS_THREADING_C)
+     388                 :            :     if ((ret = mbedtls_mutex_lock(&ctx->mutex)) != 0) {
+     389                 :            :         return ret;
+     390                 :            :     }
+     391                 :            : #endif
+     392                 :            : 
+     393                 :          6 :     ret = mbedtls_hmac_drbg_random_with_add(ctx, output, out_len, NULL, 0);
+     394                 :            : 
+     395                 :            : #if defined(MBEDTLS_THREADING_C)
+     396                 :            :     if (mbedtls_mutex_unlock(&ctx->mutex) != 0) {
+     397                 :            :         return MBEDTLS_ERR_THREADING_MUTEX_ERROR;
+     398                 :            :     }
+     399                 :            : #endif
+     400                 :            : 
+     401                 :          6 :     return ret;
+     402                 :            : }
+     403                 :            : 
+     404                 :            : /*
+     405                 :            :  *  This function resets HMAC_DRBG context to the state immediately
+     406                 :            :  *  after initial call of mbedtls_hmac_drbg_init().
+     407                 :            :  */
+     408                 :          6 : void mbedtls_hmac_drbg_free(mbedtls_hmac_drbg_context *ctx)
+     409                 :            : {
+     410         [ -  + ]:          6 :     if (ctx == NULL) {
+     411                 :          0 :         return;
+     412                 :            :     }
+     413                 :            : 
+     414                 :            : #if defined(MBEDTLS_THREADING_C)
+     415                 :            :     /* The mutex is initialized iff the md context is set up. */
+     416                 :            :     if (ctx->md_ctx.md_info != NULL) {
+     417                 :            :         mbedtls_mutex_free(&ctx->mutex);
+     418                 :            :     }
+     419                 :            : #endif
+     420                 :          6 :     mbedtls_md_free(&ctx->md_ctx);
+     421                 :          6 :     mbedtls_platform_zeroize(ctx, sizeof(mbedtls_hmac_drbg_context));
+     422                 :          6 :     ctx->reseed_interval = MBEDTLS_HMAC_DRBG_RESEED_INTERVAL;
+     423                 :            : }
+     424                 :            : 
+     425                 :            : #if defined(MBEDTLS_FS_IO)
+     426                 :            : int mbedtls_hmac_drbg_write_seed_file(mbedtls_hmac_drbg_context *ctx, const char *path)
+     427                 :            : {
+     428                 :            :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     429                 :            :     FILE *f;
+     430                 :            :     unsigned char buf[MBEDTLS_HMAC_DRBG_MAX_INPUT];
+     431                 :            : 
+     432                 :            :     if ((f = fopen(path, "wb")) == NULL) {
+     433                 :            :         return MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR;
+     434                 :            :     }
+     435                 :            : 
+     436                 :            :     /* Ensure no stdio buffering of secrets, as such buffers cannot be wiped. */
+     437                 :            :     mbedtls_setbuf(f, NULL);
+     438                 :            : 
+     439                 :            :     if ((ret = mbedtls_hmac_drbg_random(ctx, buf, sizeof(buf))) != 0) {
+     440                 :            :         goto exit;
+     441                 :            :     }
+     442                 :            : 
+     443                 :            :     if (fwrite(buf, 1, sizeof(buf), f) != sizeof(buf)) {
+     444                 :            :         ret = MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR;
+     445                 :            :         goto exit;
+     446                 :            :     }
+     447                 :            : 
+     448                 :            :     ret = 0;
+     449                 :            : 
+     450                 :            : exit:
+     451                 :            :     fclose(f);
+     452                 :            :     mbedtls_platform_zeroize(buf, sizeof(buf));
+     453                 :            : 
+     454                 :            :     return ret;
+     455                 :            : }
+     456                 :            : 
+     457                 :            : int mbedtls_hmac_drbg_update_seed_file(mbedtls_hmac_drbg_context *ctx, const char *path)
+     458                 :            : {
+     459                 :            :     int ret = 0;
+     460                 :            :     FILE *f = NULL;
+     461                 :            :     size_t n;
+     462                 :            :     unsigned char buf[MBEDTLS_HMAC_DRBG_MAX_INPUT];
+     463                 :            :     unsigned char c;
+     464                 :            : 
+     465                 :            :     if ((f = fopen(path, "rb")) == NULL) {
+     466                 :            :         return MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR;
+     467                 :            :     }
+     468                 :            : 
+     469                 :            :     /* Ensure no stdio buffering of secrets, as such buffers cannot be wiped. */
+     470                 :            :     mbedtls_setbuf(f, NULL);
+     471                 :            : 
+     472                 :            :     n = fread(buf, 1, sizeof(buf), f);
+     473                 :            :     if (fread(&c, 1, 1, f) != 0) {
+     474                 :            :         ret = MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG;
+     475                 :            :         goto exit;
+     476                 :            :     }
+     477                 :            :     if (n == 0 || ferror(f)) {
+     478                 :            :         ret = MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR;
+     479                 :            :         goto exit;
+     480                 :            :     }
+     481                 :            :     fclose(f);
+     482                 :            :     f = NULL;
+     483                 :            : 
+     484                 :            :     ret = mbedtls_hmac_drbg_update(ctx, buf, n);
+     485                 :            : 
+     486                 :            : exit:
+     487                 :            :     mbedtls_platform_zeroize(buf, sizeof(buf));
+     488                 :            :     if (f != NULL) {
+     489                 :            :         fclose(f);
+     490                 :            :     }
+     491                 :            :     if (ret != 0) {
+     492                 :            :         return ret;
+     493                 :            :     }
+     494                 :            :     return mbedtls_hmac_drbg_write_seed_file(ctx, path);
+     495                 :            : }
+     496                 :            : #endif /* MBEDTLS_FS_IO */
+     497                 :            : 
+     498                 :            : 
+     499                 :            : #if defined(MBEDTLS_SELF_TEST)
+     500                 :            : 
+     501                 :            : #if !defined(MBEDTLS_MD_CAN_SHA1)
+     502                 :            : /* Dummy checkup routine */
+     503                 :            : int mbedtls_hmac_drbg_self_test(int verbose)
+     504                 :            : {
+     505                 :            :     (void) verbose;
+     506                 :            :     return 0;
+     507                 :            : }
+     508                 :            : #else
+     509                 :            : 
+     510                 :            : #define OUTPUT_LEN  80
+     511                 :            : 
+     512                 :            : /* From a NIST PR=true test vector */
+     513                 :            : static const unsigned char entropy_pr[] = {
+     514                 :            :     0xa0, 0xc9, 0xab, 0x58, 0xf1, 0xe2, 0xe5, 0xa4, 0xde, 0x3e, 0xbd, 0x4f,
+     515                 :            :     0xf7, 0x3e, 0x9c, 0x5b, 0x64, 0xef, 0xd8, 0xca, 0x02, 0x8c, 0xf8, 0x11,
+     516                 :            :     0x48, 0xa5, 0x84, 0xfe, 0x69, 0xab, 0x5a, 0xee, 0x42, 0xaa, 0x4d, 0x42,
+     517                 :            :     0x17, 0x60, 0x99, 0xd4, 0x5e, 0x13, 0x97, 0xdc, 0x40, 0x4d, 0x86, 0xa3,
+     518                 :            :     0x7b, 0xf5, 0x59, 0x54, 0x75, 0x69, 0x51, 0xe4
+     519                 :            : };
+     520                 :            : static const unsigned char result_pr[OUTPUT_LEN] = {
+     521                 :            :     0x9a, 0x00, 0xa2, 0xd0, 0x0e, 0xd5, 0x9b, 0xfe, 0x31, 0xec, 0xb1, 0x39,
+     522                 :            :     0x9b, 0x60, 0x81, 0x48, 0xd1, 0x96, 0x9d, 0x25, 0x0d, 0x3c, 0x1e, 0x94,
+     523                 :            :     0x10, 0x10, 0x98, 0x12, 0x93, 0x25, 0xca, 0xb8, 0xfc, 0xcc, 0x2d, 0x54,
+     524                 :            :     0x73, 0x19, 0x70, 0xc0, 0x10, 0x7a, 0xa4, 0x89, 0x25, 0x19, 0x95, 0x5e,
+     525                 :            :     0x4b, 0xc6, 0x00, 0x1d, 0x7f, 0x4e, 0x6a, 0x2b, 0xf8, 0xa3, 0x01, 0xab,
+     526                 :            :     0x46, 0x05, 0x5c, 0x09, 0xa6, 0x71, 0x88, 0xf1, 0xa7, 0x40, 0xee, 0xf3,
+     527                 :            :     0xe1, 0x5c, 0x02, 0x9b, 0x44, 0xaf, 0x03, 0x44
+     528                 :            : };
+     529                 :            : 
+     530                 :            : /* From a NIST PR=false test vector */
+     531                 :            : static const unsigned char entropy_nopr[] = {
+     532                 :            :     0x79, 0x34, 0x9b, 0xbf, 0x7c, 0xdd, 0xa5, 0x79, 0x95, 0x57, 0x86, 0x66,
+     533                 :            :     0x21, 0xc9, 0x13, 0x83, 0x11, 0x46, 0x73, 0x3a, 0xbf, 0x8c, 0x35, 0xc8,
+     534                 :            :     0xc7, 0x21, 0x5b, 0x5b, 0x96, 0xc4, 0x8e, 0x9b, 0x33, 0x8c, 0x74, 0xe3,
+     535                 :            :     0xe9, 0x9d, 0xfe, 0xdf
+     536                 :            : };
+     537                 :            : static const unsigned char result_nopr[OUTPUT_LEN] = {
+     538                 :            :     0xc6, 0xa1, 0x6a, 0xb8, 0xd4, 0x20, 0x70, 0x6f, 0x0f, 0x34, 0xab, 0x7f,
+     539                 :            :     0xec, 0x5a, 0xdc, 0xa9, 0xd8, 0xca, 0x3a, 0x13, 0x3e, 0x15, 0x9c, 0xa6,
+     540                 :            :     0xac, 0x43, 0xc6, 0xf8, 0xa2, 0xbe, 0x22, 0x83, 0x4a, 0x4c, 0x0a, 0x0a,
+     541                 :            :     0xff, 0xb1, 0x0d, 0x71, 0x94, 0xf1, 0xc1, 0xa5, 0xcf, 0x73, 0x22, 0xec,
+     542                 :            :     0x1a, 0xe0, 0x96, 0x4e, 0xd4, 0xbf, 0x12, 0x27, 0x46, 0xe0, 0x87, 0xfd,
+     543                 :            :     0xb5, 0xb3, 0xe9, 0x1b, 0x34, 0x93, 0xd5, 0xbb, 0x98, 0xfa, 0xed, 0x49,
+     544                 :            :     0xe8, 0x5f, 0x13, 0x0f, 0xc8, 0xa4, 0x59, 0xb7
+     545                 :            : };
+     546                 :            : 
+     547                 :            : /* "Entropy" from buffer */
+     548                 :            : static size_t test_offset;
+     549                 :          0 : static int hmac_drbg_self_test_entropy(void *data,
+     550                 :            :                                        unsigned char *buf, size_t len)
+     551                 :            : {
+     552                 :          0 :     const unsigned char *p = data;
+     553                 :          0 :     memcpy(buf, p + test_offset, len);
+     554                 :          0 :     test_offset += len;
+     555                 :          0 :     return 0;
+     556                 :            : }
+     557                 :            : 
+     558                 :            : #define CHK(c)    if ((c) != 0)                          \
+     559                 :            :     {                                       \
+     560                 :            :         if (verbose != 0)                  \
+     561                 :            :         mbedtls_printf("failed\n");  \
+     562                 :            :         return 1;                        \
+     563                 :            :     }
+     564                 :            : 
+     565                 :            : /*
+     566                 :            :  * Checkup routine for HMAC_DRBG with SHA-1
+     567                 :            :  */
+     568                 :          0 : int mbedtls_hmac_drbg_self_test(int verbose)
+     569                 :            : {
+     570                 :            :     mbedtls_hmac_drbg_context ctx;
+     571                 :            :     unsigned char buf[OUTPUT_LEN];
+     572                 :          0 :     const mbedtls_md_info_t *md_info = mbedtls_md_info_from_type(MBEDTLS_MD_SHA1);
+     573                 :            : 
+     574                 :          0 :     mbedtls_hmac_drbg_init(&ctx);
+     575                 :            : 
+     576                 :            :     /*
+     577                 :            :      * PR = True
+     578                 :            :      */
+     579         [ #  # ]:          0 :     if (verbose != 0) {
+     580                 :          0 :         mbedtls_printf("  HMAC_DRBG (PR = True) : ");
+     581                 :            :     }
+     582                 :            : 
+     583                 :          0 :     test_offset = 0;
+     584   [ #  #  #  # ]:          0 :     CHK(mbedtls_hmac_drbg_seed(&ctx, md_info,
+     585                 :            :                                hmac_drbg_self_test_entropy, (void *) entropy_pr,
+     586                 :            :                                NULL, 0));
+     587                 :          0 :     mbedtls_hmac_drbg_set_prediction_resistance(&ctx, MBEDTLS_HMAC_DRBG_PR_ON);
+     588   [ #  #  #  # ]:          0 :     CHK(mbedtls_hmac_drbg_random(&ctx, buf, OUTPUT_LEN));
+     589   [ #  #  #  # ]:          0 :     CHK(mbedtls_hmac_drbg_random(&ctx, buf, OUTPUT_LEN));
+     590   [ #  #  #  # ]:          0 :     CHK(memcmp(buf, result_pr, OUTPUT_LEN));
+     591                 :          0 :     mbedtls_hmac_drbg_free(&ctx);
+     592                 :            : 
+     593                 :          0 :     mbedtls_hmac_drbg_free(&ctx);
+     594                 :            : 
+     595         [ #  # ]:          0 :     if (verbose != 0) {
+     596                 :          0 :         mbedtls_printf("passed\n");
+     597                 :            :     }
+     598                 :            : 
+     599                 :            :     /*
+     600                 :            :      * PR = False
+     601                 :            :      */
+     602         [ #  # ]:          0 :     if (verbose != 0) {
+     603                 :          0 :         mbedtls_printf("  HMAC_DRBG (PR = False) : ");
+     604                 :            :     }
+     605                 :            : 
+     606                 :          0 :     mbedtls_hmac_drbg_init(&ctx);
+     607                 :            : 
+     608                 :          0 :     test_offset = 0;
+     609   [ #  #  #  # ]:          0 :     CHK(mbedtls_hmac_drbg_seed(&ctx, md_info,
+     610                 :            :                                hmac_drbg_self_test_entropy, (void *) entropy_nopr,
+     611                 :            :                                NULL, 0));
+     612   [ #  #  #  # ]:          0 :     CHK(mbedtls_hmac_drbg_reseed(&ctx, NULL, 0));
+     613   [ #  #  #  # ]:          0 :     CHK(mbedtls_hmac_drbg_random(&ctx, buf, OUTPUT_LEN));
+     614   [ #  #  #  # ]:          0 :     CHK(mbedtls_hmac_drbg_random(&ctx, buf, OUTPUT_LEN));
+     615   [ #  #  #  # ]:          0 :     CHK(memcmp(buf, result_nopr, OUTPUT_LEN));
+     616                 :          0 :     mbedtls_hmac_drbg_free(&ctx);
+     617                 :            : 
+     618                 :          0 :     mbedtls_hmac_drbg_free(&ctx);
+     619                 :            : 
+     620         [ #  # ]:          0 :     if (verbose != 0) {
+     621                 :          0 :         mbedtls_printf("passed\n");
+     622                 :            :     }
+     623                 :            : 
+     624         [ #  # ]:          0 :     if (verbose != 0) {
+     625                 :          0 :         mbedtls_printf("\n");
+     626                 :            :     }
+     627                 :            : 
+     628                 :          0 :     return 0;
+     629                 :            : }
+     630                 :            : #endif /* MBEDTLS_MD_CAN_SHA1 */
+     631                 :            : #endif /* MBEDTLS_SELF_TEST */
+     632                 :            : 
+     633                 :            : #endif /* MBEDTLS_HMAC_DRBG_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/index-sort-b.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/index-sort-b.html new file mode 100644 index 00000000000..e9de8297a5e --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/index-sort-b.html @@ -0,0 +1,731 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/libraryHitTotalCoverage
Test:coverage.infoLines:45991359033.8 %
Date:2024-09-22 08:21:07Functions:44496246.2 %
Branches:2400954725.1 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
ctr.h +
0.0%
+
0.0 %0 / 70.0 %0 / 10.0 %0 / 4
chacha20.c +
0.0%
+
0.0 %0 / 1300.0 %0 / 100.0 %0 / 34
poly1305.c +
0.0%
+
0.0 %0 / 1940.0 %0 / 100.0 %0 / 36
md5.c +
0.0%
+
0.0 %0 / 1910.0 %0 / 90.0 %0 / 44
ripemd160.c +
0.0%
+
0.0 %0 / 2120.0 %0 / 90.0 %0 / 44
x509write.c +
0.0%
+
0.0 %0 / 590.0 %0 / 10.0 %0 / 48
sha1.c +
0.0%
+
0.0 %0 / 2250.0 %0 / 90.0 %0 / 54
chachapoly.c +
0.0%
+
0.0 %0 / 1510.0 %0 / 130.0 %0 / 78
sha3.c +
0.0%
+
0.0 %0 / 2470.0 %0 / 110.0 %0 / 107
des.c +
0.0%
+
0.0 %0 / 3210.0 %0 / 210.0 %0 / 144
aria.c +
0.0%
+
0.0 %0 / 2910.0 %0 / 140.0 %0 / 150
ccm.c +
0.0%
+
0.0 %0 / 2570.0 %0 / 190.0 %0 / 166
camellia.c +
0.0%
+
0.0 %0 / 2750.0 %0 / 100.0 %0 / 171
cipher_wrap.c +
7.4%7.4%
+
7.4 %13 / 1767.1 %4 / 563.6 %1 / 28
cipher.c +
10.8%10.8%
+
10.8 %43 / 39924.0 %6 / 257.3 %22 / 301
aes.c +
12.3%12.3%
+
12.3 %62 / 50337.5 %6 / 1611.8 %30 / 254
pem.c +
17.8%17.8%
+
17.8 %43 / 24230.0 %3 / 1012.8 %21 / 164
x509.c +
27.0%27.0%
+
27.0 %198 / 73454.3 %19 / 3513.2 %81 / 614
rsa_alt_helpers.c +
28.3%28.3%
+
28.3 %49 / 17340.0 %2 / 515.7 %34 / 216
pkwrite.c +
29.8%29.8%
+
29.8 %50 / 16841.7 %5 / 1218.6 %22 / 118
pk_wrap.c +
28.4%28.4%
+
28.4 %42 / 14835.7 %10 / 2818.8 %12 / 64
oid.c +
7.2%7.2%
+
7.2 %12 / 16636.4 %12 / 3319.6 %47 / 240
hmac_drbg.c +
36.0%36.0%
+
36.0 %64 / 17842.9 %6 / 1421.3 %29 / 136
dhm.c +
35.0%35.0%
+
35.0 %83 / 23755.6 %10 / 1821.4 %37 / 173
pk.c +
31.1%31.1%
+
31.1 %60 / 19359.1 %13 / 2221.6 %36 / 167
ecdh.c +
45.5%45.5%
+
45.5 %76 / 16753.8 %14 / 2621.6 %16 / 74
platform_util.c +
53.8%53.8%
+
53.8 %7 / 1366.7 %2 / 325.0 %1 / 4
pk_internal.h +
61.1%61.1%
+
61.1 %11 / 1875.0 %3 / 425.0 %2 / 8
gcm.c +
34.9%34.9%
+
34.9 %149 / 42782.4 %14 / 1725.3 %58 / 229
ecp.c +
48.7%48.7%
+
48.7 %566 / 116256.4 %53 / 9428.8 %324 / 1124
ecp_curves.c +
39.2%39.2%
+
39.2 %120 / 30647.6 %10 / 2129.1 %94 / 323
x509_crt.c +
44.6%44.6%
+
44.6 %448 / 100458.2 %32 / 5530.0 %240 / 801
rsa.c +
44.8%44.8%
+
44.8 %485 / 108255.8 %29 / 5230.5 %294 / 965
md.c +
39.3%39.3%
+
39.3 %133 / 33870.0 %14 / 2031.8 %67 / 211
constant_time.c +
45.7%45.7%
+
45.7 %21 / 4640.0 %2 / 533.3 %6 / 18
pkparse.c +
45.5%45.5%
+
45.5 %137 / 30158.3 %7 / 1235.3 %82 / 232
ecdsa.c +
59.6%59.6%
+
59.6 %162 / 27252.0 %13 / 2535.8 %92 / 257
bignum.c +
52.4%52.4%
+
52.4 %469 / 89569.1 %38 / 5537.4 %301 / 804
pk_ecc.c +
66.7%66.7%
+
66.7 %14 / 2175.0 %3 / 437.5 %3 / 8
x509write_csr.c +
62.1%62.1%
+
62.1 %64 / 10366.7 %8 / 1237.9 %25 / 66
base64.c +
39.2%39.2%
+
39.2 %49 / 12540.0 %2 / 539.3 %33 / 84
x509_create.c +
61.0%61.0%
+
61.0 %122 / 20075.0 %9 / 1239.6 %65 / 164
asn1write.c +
52.0%52.0%
+
52.0 %90 / 17352.4 %11 / 2141.7 %40 / 96
sha512.c +
63.5%63.5%
+
63.5 %120 / 18966.7 %8 / 1243.0 %37 / 86
sha256.c +
65.2%65.2%
+
65.2 %122 / 18775.0 %9 / 1244.2 %38 / 86
common.h +
50.0%50.0%
+
50.0 %7 / 14-0 / 048.2 %27 / 56
hkdf.c +
60.9%60.9%
+
60.9 %39 / 6466.7 %2 / 350.0 %18 / 36
asn1parse.c +
75.9%75.9%
+
75.9 %145 / 19184.2 %16 / 1959.1 %65 / 110
aesni.c +
68.3%68.3%
+
68.3 %28 / 4175.0 %6 / 866.7 %8 / 12
bignum_core.c +
80.3%80.3%
+
80.3 %249 / 31084.8 %28 / 3366.7 %92 / 138
alignment.h +
66.7%66.7%
+
66.7 %8 / 12-0 / 0-0 / 0
bignum_core.h +
100.0%
+
100.0 %2 / 2100.0 %1 / 1-0 / 0
constant_time_impl.h +
74.0%74.0%
+
74.0 %37 / 5070.0 %14 / 20-0 / 0
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/index-sort-f.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/index-sort-f.html new file mode 100644 index 00000000000..77caf29cef4 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/index-sort-f.html @@ -0,0 +1,731 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/libraryHitTotalCoverage
Test:coverage.infoLines:45991359033.8 %
Date:2024-09-22 08:21:07Functions:44496246.2 %
Branches:2400954725.1 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
x509write.c +
0.0%
+
0.0 %0 / 590.0 %0 / 10.0 %0 / 48
ctr.h +
0.0%
+
0.0 %0 / 70.0 %0 / 10.0 %0 / 4
md5.c +
0.0%
+
0.0 %0 / 1910.0 %0 / 90.0 %0 / 44
sha1.c +
0.0%
+
0.0 %0 / 2250.0 %0 / 90.0 %0 / 54
ripemd160.c +
0.0%
+
0.0 %0 / 2120.0 %0 / 90.0 %0 / 44
poly1305.c +
0.0%
+
0.0 %0 / 1940.0 %0 / 100.0 %0 / 36
chacha20.c +
0.0%
+
0.0 %0 / 1300.0 %0 / 100.0 %0 / 34
camellia.c +
0.0%
+
0.0 %0 / 2750.0 %0 / 100.0 %0 / 171
sha3.c +
0.0%
+
0.0 %0 / 2470.0 %0 / 110.0 %0 / 107
chachapoly.c +
0.0%
+
0.0 %0 / 1510.0 %0 / 130.0 %0 / 78
aria.c +
0.0%
+
0.0 %0 / 2910.0 %0 / 140.0 %0 / 150
ccm.c +
0.0%
+
0.0 %0 / 2570.0 %0 / 190.0 %0 / 166
des.c +
0.0%
+
0.0 %0 / 3210.0 %0 / 210.0 %0 / 144
cipher_wrap.c +
7.4%7.4%
+
7.4 %13 / 1767.1 %4 / 563.6 %1 / 28
cipher.c +
10.8%10.8%
+
10.8 %43 / 39924.0 %6 / 257.3 %22 / 301
pem.c +
17.8%17.8%
+
17.8 %43 / 24230.0 %3 / 1012.8 %21 / 164
pk_wrap.c +
28.4%28.4%
+
28.4 %42 / 14835.7 %10 / 2818.8 %12 / 64
oid.c +
7.2%7.2%
+
7.2 %12 / 16636.4 %12 / 3319.6 %47 / 240
aes.c +
12.3%12.3%
+
12.3 %62 / 50337.5 %6 / 1611.8 %30 / 254
base64.c +
39.2%39.2%
+
39.2 %49 / 12540.0 %2 / 539.3 %33 / 84
constant_time.c +
45.7%45.7%
+
45.7 %21 / 4640.0 %2 / 533.3 %6 / 18
rsa_alt_helpers.c +
28.3%28.3%
+
28.3 %49 / 17340.0 %2 / 515.7 %34 / 216
pkwrite.c +
29.8%29.8%
+
29.8 %50 / 16841.7 %5 / 1218.6 %22 / 118
hmac_drbg.c +
36.0%36.0%
+
36.0 %64 / 17842.9 %6 / 1421.3 %29 / 136
ecp_curves.c +
39.2%39.2%
+
39.2 %120 / 30647.6 %10 / 2129.1 %94 / 323
ecdsa.c +
59.6%59.6%
+
59.6 %162 / 27252.0 %13 / 2535.8 %92 / 257
asn1write.c +
52.0%52.0%
+
52.0 %90 / 17352.4 %11 / 2141.7 %40 / 96
ecdh.c +
45.5%45.5%
+
45.5 %76 / 16753.8 %14 / 2621.6 %16 / 74
x509.c +
27.0%27.0%
+
27.0 %198 / 73454.3 %19 / 3513.2 %81 / 614
dhm.c +
35.0%35.0%
+
35.0 %83 / 23755.6 %10 / 1821.4 %37 / 173
rsa.c +
44.8%44.8%
+
44.8 %485 / 108255.8 %29 / 5230.5 %294 / 965
ecp.c +
48.7%48.7%
+
48.7 %566 / 116256.4 %53 / 9428.8 %324 / 1124
x509_crt.c +
44.6%44.6%
+
44.6 %448 / 100458.2 %32 / 5530.0 %240 / 801
pkparse.c +
45.5%45.5%
+
45.5 %137 / 30158.3 %7 / 1235.3 %82 / 232
pk.c +
31.1%31.1%
+
31.1 %60 / 19359.1 %13 / 2221.6 %36 / 167
hkdf.c +
60.9%60.9%
+
60.9 %39 / 6466.7 %2 / 350.0 %18 / 36
platform_util.c +
53.8%53.8%
+
53.8 %7 / 1366.7 %2 / 325.0 %1 / 4
x509write_csr.c +
62.1%62.1%
+
62.1 %64 / 10366.7 %8 / 1237.9 %25 / 66
sha512.c +
63.5%63.5%
+
63.5 %120 / 18966.7 %8 / 1243.0 %37 / 86
bignum.c +
52.4%52.4%
+
52.4 %469 / 89569.1 %38 / 5537.4 %301 / 804
constant_time_impl.h +
74.0%74.0%
+
74.0 %37 / 5070.0 %14 / 20-0 / 0
md.c +
39.3%39.3%
+
39.3 %133 / 33870.0 %14 / 2031.8 %67 / 211
pk_internal.h +
61.1%61.1%
+
61.1 %11 / 1875.0 %3 / 425.0 %2 / 8
pk_ecc.c +
66.7%66.7%
+
66.7 %14 / 2175.0 %3 / 437.5 %3 / 8
aesni.c +
68.3%68.3%
+
68.3 %28 / 4175.0 %6 / 866.7 %8 / 12
x509_create.c +
61.0%61.0%
+
61.0 %122 / 20075.0 %9 / 1239.6 %65 / 164
sha256.c +
65.2%65.2%
+
65.2 %122 / 18775.0 %9 / 1244.2 %38 / 86
gcm.c +
34.9%34.9%
+
34.9 %149 / 42782.4 %14 / 1725.3 %58 / 229
asn1parse.c +
75.9%75.9%
+
75.9 %145 / 19184.2 %16 / 1959.1 %65 / 110
bignum_core.c +
80.3%80.3%
+
80.3 %249 / 31084.8 %28 / 3366.7 %92 / 138
alignment.h +
66.7%66.7%
+
66.7 %8 / 12-0 / 0-0 / 0
common.h +
50.0%50.0%
+
50.0 %7 / 14-0 / 048.2 %27 / 56
bignum_core.h +
100.0%
+
100.0 %2 / 2100.0 %1 / 1-0 / 0
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/index-sort-l.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/index-sort-l.html new file mode 100644 index 00000000000..fcdb907545b --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/index-sort-l.html @@ -0,0 +1,731 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/libraryHitTotalCoverage
Test:coverage.infoLines:45991359033.8 %
Date:2024-09-22 08:21:07Functions:44496246.2 %
Branches:2400954725.1 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
ctr.h +
0.0%
+
0.0 %0 / 70.0 %0 / 10.0 %0 / 4
x509write.c +
0.0%
+
0.0 %0 / 590.0 %0 / 10.0 %0 / 48
chacha20.c +
0.0%
+
0.0 %0 / 1300.0 %0 / 100.0 %0 / 34
chachapoly.c +
0.0%
+
0.0 %0 / 1510.0 %0 / 130.0 %0 / 78
md5.c +
0.0%
+
0.0 %0 / 1910.0 %0 / 90.0 %0 / 44
poly1305.c +
0.0%
+
0.0 %0 / 1940.0 %0 / 100.0 %0 / 36
ripemd160.c +
0.0%
+
0.0 %0 / 2120.0 %0 / 90.0 %0 / 44
sha1.c +
0.0%
+
0.0 %0 / 2250.0 %0 / 90.0 %0 / 54
sha3.c +
0.0%
+
0.0 %0 / 2470.0 %0 / 110.0 %0 / 107
ccm.c +
0.0%
+
0.0 %0 / 2570.0 %0 / 190.0 %0 / 166
camellia.c +
0.0%
+
0.0 %0 / 2750.0 %0 / 100.0 %0 / 171
aria.c +
0.0%
+
0.0 %0 / 2910.0 %0 / 140.0 %0 / 150
des.c +
0.0%
+
0.0 %0 / 3210.0 %0 / 210.0 %0 / 144
oid.c +
7.2%7.2%
+
7.2 %12 / 16636.4 %12 / 3319.6 %47 / 240
cipher_wrap.c +
7.4%7.4%
+
7.4 %13 / 1767.1 %4 / 563.6 %1 / 28
cipher.c +
10.8%10.8%
+
10.8 %43 / 39924.0 %6 / 257.3 %22 / 301
aes.c +
12.3%12.3%
+
12.3 %62 / 50337.5 %6 / 1611.8 %30 / 254
pem.c +
17.8%17.8%
+
17.8 %43 / 24230.0 %3 / 1012.8 %21 / 164
x509.c +
27.0%27.0%
+
27.0 %198 / 73454.3 %19 / 3513.2 %81 / 614
pk_wrap.c +
28.4%28.4%
+
28.4 %42 / 14835.7 %10 / 2818.8 %12 / 64
rsa_alt_helpers.c +
28.3%28.3%
+
28.3 %49 / 17340.0 %2 / 515.7 %34 / 216
pkwrite.c +
29.8%29.8%
+
29.8 %50 / 16841.7 %5 / 1218.6 %22 / 118
pk.c +
31.1%31.1%
+
31.1 %60 / 19359.1 %13 / 2221.6 %36 / 167
gcm.c +
34.9%34.9%
+
34.9 %149 / 42782.4 %14 / 1725.3 %58 / 229
dhm.c +
35.0%35.0%
+
35.0 %83 / 23755.6 %10 / 1821.4 %37 / 173
hmac_drbg.c +
36.0%36.0%
+
36.0 %64 / 17842.9 %6 / 1421.3 %29 / 136
base64.c +
39.2%39.2%
+
39.2 %49 / 12540.0 %2 / 539.3 %33 / 84
ecp_curves.c +
39.2%39.2%
+
39.2 %120 / 30647.6 %10 / 2129.1 %94 / 323
md.c +
39.3%39.3%
+
39.3 %133 / 33870.0 %14 / 2031.8 %67 / 211
x509_crt.c +
44.6%44.6%
+
44.6 %448 / 100458.2 %32 / 5530.0 %240 / 801
rsa.c +
44.8%44.8%
+
44.8 %485 / 108255.8 %29 / 5230.5 %294 / 965
ecdh.c +
45.5%45.5%
+
45.5 %76 / 16753.8 %14 / 2621.6 %16 / 74
pkparse.c +
45.5%45.5%
+
45.5 %137 / 30158.3 %7 / 1235.3 %82 / 232
constant_time.c +
45.7%45.7%
+
45.7 %21 / 4640.0 %2 / 533.3 %6 / 18
ecp.c +
48.7%48.7%
+
48.7 %566 / 116256.4 %53 / 9428.8 %324 / 1124
common.h +
50.0%50.0%
+
50.0 %7 / 14-0 / 048.2 %27 / 56
asn1write.c +
52.0%52.0%
+
52.0 %90 / 17352.4 %11 / 2141.7 %40 / 96
bignum.c +
52.4%52.4%
+
52.4 %469 / 89569.1 %38 / 5537.4 %301 / 804
platform_util.c +
53.8%53.8%
+
53.8 %7 / 1366.7 %2 / 325.0 %1 / 4
ecdsa.c +
59.6%59.6%
+
59.6 %162 / 27252.0 %13 / 2535.8 %92 / 257
hkdf.c +
60.9%60.9%
+
60.9 %39 / 6466.7 %2 / 350.0 %18 / 36
x509_create.c +
61.0%61.0%
+
61.0 %122 / 20075.0 %9 / 1239.6 %65 / 164
pk_internal.h +
61.1%61.1%
+
61.1 %11 / 1875.0 %3 / 425.0 %2 / 8
x509write_csr.c +
62.1%62.1%
+
62.1 %64 / 10366.7 %8 / 1237.9 %25 / 66
sha512.c +
63.5%63.5%
+
63.5 %120 / 18966.7 %8 / 1243.0 %37 / 86
sha256.c +
65.2%65.2%
+
65.2 %122 / 18775.0 %9 / 1244.2 %38 / 86
alignment.h +
66.7%66.7%
+
66.7 %8 / 12-0 / 0-0 / 0
pk_ecc.c +
66.7%66.7%
+
66.7 %14 / 2175.0 %3 / 437.5 %3 / 8
aesni.c +
68.3%68.3%
+
68.3 %28 / 4175.0 %6 / 866.7 %8 / 12
constant_time_impl.h +
74.0%74.0%
+
74.0 %37 / 5070.0 %14 / 20-0 / 0
asn1parse.c +
75.9%75.9%
+
75.9 %145 / 19184.2 %16 / 1959.1 %65 / 110
bignum_core.c +
80.3%80.3%
+
80.3 %249 / 31084.8 %28 / 3366.7 %92 / 138
bignum_core.h +
100.0%
+
100.0 %2 / 2100.0 %1 / 1-0 / 0
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/index.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/index.html new file mode 100644 index 00000000000..509677bb1df --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/index.html @@ -0,0 +1,731 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/libraryHitTotalCoverage
Test:coverage.infoLines:45991359033.8 %
Date:2024-09-22 08:21:07Functions:44496246.2 %
Branches:2400954725.1 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
aes.c +
12.3%12.3%
+
12.3 %62 / 50337.5 %6 / 1611.8 %30 / 254
aesni.c +
68.3%68.3%
+
68.3 %28 / 4175.0 %6 / 866.7 %8 / 12
alignment.h +
66.7%66.7%
+
66.7 %8 / 12-0 / 0-0 / 0
aria.c +
0.0%
+
0.0 %0 / 2910.0 %0 / 140.0 %0 / 150
asn1parse.c +
75.9%75.9%
+
75.9 %145 / 19184.2 %16 / 1959.1 %65 / 110
asn1write.c +
52.0%52.0%
+
52.0 %90 / 17352.4 %11 / 2141.7 %40 / 96
base64.c +
39.2%39.2%
+
39.2 %49 / 12540.0 %2 / 539.3 %33 / 84
bignum.c +
52.4%52.4%
+
52.4 %469 / 89569.1 %38 / 5537.4 %301 / 804
bignum_core.c +
80.3%80.3%
+
80.3 %249 / 31084.8 %28 / 3366.7 %92 / 138
bignum_core.h +
100.0%
+
100.0 %2 / 2100.0 %1 / 1-0 / 0
camellia.c +
0.0%
+
0.0 %0 / 2750.0 %0 / 100.0 %0 / 171
ccm.c +
0.0%
+
0.0 %0 / 2570.0 %0 / 190.0 %0 / 166
chacha20.c +
0.0%
+
0.0 %0 / 1300.0 %0 / 100.0 %0 / 34
chachapoly.c +
0.0%
+
0.0 %0 / 1510.0 %0 / 130.0 %0 / 78
cipher.c +
10.8%10.8%
+
10.8 %43 / 39924.0 %6 / 257.3 %22 / 301
cipher_wrap.c +
7.4%7.4%
+
7.4 %13 / 1767.1 %4 / 563.6 %1 / 28
common.h +
50.0%50.0%
+
50.0 %7 / 14-0 / 048.2 %27 / 56
constant_time.c +
45.7%45.7%
+
45.7 %21 / 4640.0 %2 / 533.3 %6 / 18
constant_time_impl.h +
74.0%74.0%
+
74.0 %37 / 5070.0 %14 / 20-0 / 0
ctr.h +
0.0%
+
0.0 %0 / 70.0 %0 / 10.0 %0 / 4
des.c +
0.0%
+
0.0 %0 / 3210.0 %0 / 210.0 %0 / 144
dhm.c +
35.0%35.0%
+
35.0 %83 / 23755.6 %10 / 1821.4 %37 / 173
ecdh.c +
45.5%45.5%
+
45.5 %76 / 16753.8 %14 / 2621.6 %16 / 74
ecdsa.c +
59.6%59.6%
+
59.6 %162 / 27252.0 %13 / 2535.8 %92 / 257
ecp.c +
48.7%48.7%
+
48.7 %566 / 116256.4 %53 / 9428.8 %324 / 1124
ecp_curves.c +
39.2%39.2%
+
39.2 %120 / 30647.6 %10 / 2129.1 %94 / 323
gcm.c +
34.9%34.9%
+
34.9 %149 / 42782.4 %14 / 1725.3 %58 / 229
hkdf.c +
60.9%60.9%
+
60.9 %39 / 6466.7 %2 / 350.0 %18 / 36
hmac_drbg.c +
36.0%36.0%
+
36.0 %64 / 17842.9 %6 / 1421.3 %29 / 136
md.c +
39.3%39.3%
+
39.3 %133 / 33870.0 %14 / 2031.8 %67 / 211
md5.c +
0.0%
+
0.0 %0 / 1910.0 %0 / 90.0 %0 / 44
oid.c +
7.2%7.2%
+
7.2 %12 / 16636.4 %12 / 3319.6 %47 / 240
pem.c +
17.8%17.8%
+
17.8 %43 / 24230.0 %3 / 1012.8 %21 / 164
pk.c +
31.1%31.1%
+
31.1 %60 / 19359.1 %13 / 2221.6 %36 / 167
pk_ecc.c +
66.7%66.7%
+
66.7 %14 / 2175.0 %3 / 437.5 %3 / 8
pk_internal.h +
61.1%61.1%
+
61.1 %11 / 1875.0 %3 / 425.0 %2 / 8
pk_wrap.c +
28.4%28.4%
+
28.4 %42 / 14835.7 %10 / 2818.8 %12 / 64
pkparse.c +
45.5%45.5%
+
45.5 %137 / 30158.3 %7 / 1235.3 %82 / 232
pkwrite.c +
29.8%29.8%
+
29.8 %50 / 16841.7 %5 / 1218.6 %22 / 118
platform_util.c +
53.8%53.8%
+
53.8 %7 / 1366.7 %2 / 325.0 %1 / 4
poly1305.c +
0.0%
+
0.0 %0 / 1940.0 %0 / 100.0 %0 / 36
ripemd160.c +
0.0%
+
0.0 %0 / 2120.0 %0 / 90.0 %0 / 44
rsa.c +
44.8%44.8%
+
44.8 %485 / 108255.8 %29 / 5230.5 %294 / 965
rsa_alt_helpers.c +
28.3%28.3%
+
28.3 %49 / 17340.0 %2 / 515.7 %34 / 216
sha1.c +
0.0%
+
0.0 %0 / 2250.0 %0 / 90.0 %0 / 54
sha256.c +
65.2%65.2%
+
65.2 %122 / 18775.0 %9 / 1244.2 %38 / 86
sha3.c +
0.0%
+
0.0 %0 / 2470.0 %0 / 110.0 %0 / 107
sha512.c +
63.5%63.5%
+
63.5 %120 / 18966.7 %8 / 1243.0 %37 / 86
x509.c +
27.0%27.0%
+
27.0 %198 / 73454.3 %19 / 3513.2 %81 / 614
x509_create.c +
61.0%61.0%
+
61.0 %122 / 20075.0 %9 / 1239.6 %65 / 164
x509_crt.c +
44.6%44.6%
+
44.6 %448 / 100458.2 %32 / 5530.0 %240 / 801
x509write.c +
0.0%
+
0.0 %0 / 590.0 %0 / 10.0 %0 / 48
x509write_csr.c +
62.1%62.1%
+
62.1 %64 / 10366.7 %8 / 1237.9 %25 / 66
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/md.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/md.c.func-sort-c.html new file mode 100644 index 00000000000..0d9c69d1d01 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/md.c.func-sort-c.html @@ -0,0 +1,161 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/md.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - md.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:13333839.3 %
Date:2024-09-22 08:21:07Functions:142070.0 %
Branches:6721131.8 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_md_clone0
mbedtls_md_get_name0
mbedtls_md_get_type0
mbedtls_md_info_from_ctx0
mbedtls_md_info_from_string0
mbedtls_md_list0
mbedtls_md_hmac_reset24
mbedtls_md_hmac508
mbedtls_md1594
mbedtls_md_init1741
mbedtls_md_free1745
mbedtls_md_setup1745
mbedtls_md_hmac_starts1795
mbedtls_md_hmac_finish1813
mbedtls_md_get_size3158
mbedtls_md_finish3642
mbedtls_md_starts3648
mbedtls_md_info_from_type3652
mbedtls_md_hmac_update4369
mbedtls_md_update9848
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/md.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/md.c.func.html new file mode 100644 index 00000000000..5f80003ccb6 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/md.c.func.html @@ -0,0 +1,161 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/md.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - md.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:13333839.3 %
Date:2024-09-22 08:21:07Functions:142070.0 %
Branches:6721131.8 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_md1594
mbedtls_md_clone0
mbedtls_md_finish3642
mbedtls_md_free1745
mbedtls_md_get_name0
mbedtls_md_get_size3158
mbedtls_md_get_type0
mbedtls_md_hmac508
mbedtls_md_hmac_finish1813
mbedtls_md_hmac_reset24
mbedtls_md_hmac_starts1795
mbedtls_md_hmac_update4369
mbedtls_md_info_from_ctx0
mbedtls_md_info_from_string0
mbedtls_md_info_from_type3652
mbedtls_md_init1741
mbedtls_md_list0
mbedtls_md_setup1745
mbedtls_md_starts3648
mbedtls_md_update9848
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/md.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/md.c.gcov.html new file mode 100644 index 00000000000..46211416452 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/md.c.gcov.html @@ -0,0 +1,1214 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/md.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - md.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:13333839.3 %
Date:2024-09-22 08:21:07Functions:142070.0 %
Branches:6721131.8 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  * \file md.c
+       3                 :            :  *
+       4                 :            :  * \brief Generic message digest wrapper for Mbed TLS
+       5                 :            :  *
+       6                 :            :  * \author Adriaan de Jong <dejong@fox-it.com>
+       7                 :            :  *
+       8                 :            :  *  Copyright The Mbed TLS Contributors
+       9                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+      10                 :            :  */
+      11                 :            : 
+      12                 :            : #include "common.h"
+      13                 :            : 
+      14                 :            : /*
+      15                 :            :  * Availability of functions in this module is controlled by two
+      16                 :            :  * feature macros:
+      17                 :            :  * - MBEDTLS_MD_C enables the whole module;
+      18                 :            :  * - MBEDTLS_MD_LIGHT enables only functions for hashing and accessing
+      19                 :            :  * most hash metadata (everything except string names); is it
+      20                 :            :  * automatically set whenever MBEDTLS_MD_C is defined.
+      21                 :            :  *
+      22                 :            :  * In this file, functions from MD_LIGHT are at the top, MD_C at the end.
+      23                 :            :  *
+      24                 :            :  * In the future we may want to change the contract of some functions
+      25                 :            :  * (behaviour with NULL arguments) depending on whether MD_C is defined or
+      26                 :            :  * only MD_LIGHT. Also, the exact scope of MD_LIGHT might vary.
+      27                 :            :  *
+      28                 :            :  * For these reasons, we're keeping MD_LIGHT internal for now.
+      29                 :            :  */
+      30                 :            : #if defined(MBEDTLS_MD_LIGHT)
+      31                 :            : 
+      32                 :            : #include "mbedtls/md.h"
+      33                 :            : #include "md_wrap.h"
+      34                 :            : #include "mbedtls/platform_util.h"
+      35                 :            : #include "mbedtls/error.h"
+      36                 :            : 
+      37                 :            : #include "mbedtls/md5.h"
+      38                 :            : #include "mbedtls/ripemd160.h"
+      39                 :            : #include "mbedtls/sha1.h"
+      40                 :            : #include "mbedtls/sha256.h"
+      41                 :            : #include "mbedtls/sha512.h"
+      42                 :            : #include "mbedtls/sha3.h"
+      43                 :            : 
+      44                 :            : #if defined(MBEDTLS_PSA_CRYPTO_C)
+      45                 :            : #include <psa/crypto.h>
+      46                 :            : #include "md_psa.h"
+      47                 :            : #include "psa_util_internal.h"
+      48                 :            : #endif
+      49                 :            : 
+      50                 :            : #if defined(MBEDTLS_MD_SOME_PSA)
+      51                 :            : #include "psa_crypto_core.h"
+      52                 :            : #endif
+      53                 :            : 
+      54                 :            : #include "mbedtls/platform.h"
+      55                 :            : 
+      56                 :            : #include <string.h>
+      57                 :            : 
+      58                 :            : #if defined(MBEDTLS_FS_IO)
+      59                 :            : #include <stdio.h>
+      60                 :            : #endif
+      61                 :            : 
+      62                 :            : /* See comment above MBEDTLS_MD_MAX_SIZE in md.h */
+      63                 :            : #if defined(MBEDTLS_PSA_CRYPTO_C) && MBEDTLS_MD_MAX_SIZE < PSA_HASH_MAX_SIZE
+      64                 :            : #error "Internal error: MBEDTLS_MD_MAX_SIZE < PSA_HASH_MAX_SIZE"
+      65                 :            : #endif
+      66                 :            : 
+      67                 :            : #if defined(MBEDTLS_MD_C)
+      68                 :            : #define MD_INFO(type, out_size, block_size) type, out_size, block_size,
+      69                 :            : #else
+      70                 :            : #define MD_INFO(type, out_size, block_size) type, out_size,
+      71                 :            : #endif
+      72                 :            : 
+      73                 :            : #if defined(MBEDTLS_MD_CAN_MD5)
+      74                 :            : static const mbedtls_md_info_t mbedtls_md5_info = {
+      75                 :            :     MD_INFO(MBEDTLS_MD_MD5, 16, 64)
+      76                 :            : };
+      77                 :            : #endif
+      78                 :            : 
+      79                 :            : #if defined(MBEDTLS_MD_CAN_RIPEMD160)
+      80                 :            : static const mbedtls_md_info_t mbedtls_ripemd160_info = {
+      81                 :            :     MD_INFO(MBEDTLS_MD_RIPEMD160, 20, 64)
+      82                 :            : };
+      83                 :            : #endif
+      84                 :            : 
+      85                 :            : #if defined(MBEDTLS_MD_CAN_SHA1)
+      86                 :            : static const mbedtls_md_info_t mbedtls_sha1_info = {
+      87                 :            :     MD_INFO(MBEDTLS_MD_SHA1, 20, 64)
+      88                 :            : };
+      89                 :            : #endif
+      90                 :            : 
+      91                 :            : #if defined(MBEDTLS_MD_CAN_SHA224)
+      92                 :            : static const mbedtls_md_info_t mbedtls_sha224_info = {
+      93                 :            :     MD_INFO(MBEDTLS_MD_SHA224, 28, 64)
+      94                 :            : };
+      95                 :            : #endif
+      96                 :            : 
+      97                 :            : #if defined(MBEDTLS_MD_CAN_SHA256)
+      98                 :            : static const mbedtls_md_info_t mbedtls_sha256_info = {
+      99                 :            :     MD_INFO(MBEDTLS_MD_SHA256, 32, 64)
+     100                 :            : };
+     101                 :            : #endif
+     102                 :            : 
+     103                 :            : #if defined(MBEDTLS_MD_CAN_SHA384)
+     104                 :            : static const mbedtls_md_info_t mbedtls_sha384_info = {
+     105                 :            :     MD_INFO(MBEDTLS_MD_SHA384, 48, 128)
+     106                 :            : };
+     107                 :            : #endif
+     108                 :            : 
+     109                 :            : #if defined(MBEDTLS_MD_CAN_SHA512)
+     110                 :            : static const mbedtls_md_info_t mbedtls_sha512_info = {
+     111                 :            :     MD_INFO(MBEDTLS_MD_SHA512, 64, 128)
+     112                 :            : };
+     113                 :            : #endif
+     114                 :            : 
+     115                 :            : #if defined(MBEDTLS_MD_CAN_SHA3_224)
+     116                 :            : static const mbedtls_md_info_t mbedtls_sha3_224_info = {
+     117                 :            :     MD_INFO(MBEDTLS_MD_SHA3_224, 28, 144)
+     118                 :            : };
+     119                 :            : #endif
+     120                 :            : 
+     121                 :            : #if defined(MBEDTLS_MD_CAN_SHA3_256)
+     122                 :            : static const mbedtls_md_info_t mbedtls_sha3_256_info = {
+     123                 :            :     MD_INFO(MBEDTLS_MD_SHA3_256, 32, 136)
+     124                 :            : };
+     125                 :            : #endif
+     126                 :            : 
+     127                 :            : #if defined(MBEDTLS_MD_CAN_SHA3_384)
+     128                 :            : static const mbedtls_md_info_t mbedtls_sha3_384_info = {
+     129                 :            :     MD_INFO(MBEDTLS_MD_SHA3_384, 48, 104)
+     130                 :            : };
+     131                 :            : #endif
+     132                 :            : 
+     133                 :            : #if defined(MBEDTLS_MD_CAN_SHA3_512)
+     134                 :            : static const mbedtls_md_info_t mbedtls_sha3_512_info = {
+     135                 :            :     MD_INFO(MBEDTLS_MD_SHA3_512, 64, 72)
+     136                 :            : };
+     137                 :            : #endif
+     138                 :            : 
+     139                 :       3652 : const mbedtls_md_info_t *mbedtls_md_info_from_type(mbedtls_md_type_t md_type)
+     140                 :            : {
+     141   [ -  -  -  -  :       3652 :     switch (md_type) {
+          +  +  +  -  -  
+                -  -  - ]
+     142                 :            : #if defined(MBEDTLS_MD_CAN_MD5)
+     143                 :          0 :         case MBEDTLS_MD_MD5:
+     144                 :          0 :             return &mbedtls_md5_info;
+     145                 :            : #endif
+     146                 :            : #if defined(MBEDTLS_MD_CAN_RIPEMD160)
+     147                 :          0 :         case MBEDTLS_MD_RIPEMD160:
+     148                 :          0 :             return &mbedtls_ripemd160_info;
+     149                 :            : #endif
+     150                 :            : #if defined(MBEDTLS_MD_CAN_SHA1)
+     151                 :          0 :         case MBEDTLS_MD_SHA1:
+     152                 :          0 :             return &mbedtls_sha1_info;
+     153                 :            : #endif
+     154                 :            : #if defined(MBEDTLS_MD_CAN_SHA224)
+     155                 :          0 :         case MBEDTLS_MD_SHA224:
+     156                 :          0 :             return &mbedtls_sha224_info;
+     157                 :            : #endif
+     158                 :            : #if defined(MBEDTLS_MD_CAN_SHA256)
+     159                 :       3560 :         case MBEDTLS_MD_SHA256:
+     160                 :       3560 :             return &mbedtls_sha256_info;
+     161                 :            : #endif
+     162                 :            : #if defined(MBEDTLS_MD_CAN_SHA384)
+     163                 :          3 :         case MBEDTLS_MD_SHA384:
+     164                 :          3 :             return &mbedtls_sha384_info;
+     165                 :            : #endif
+     166                 :            : #if defined(MBEDTLS_MD_CAN_SHA512)
+     167                 :         89 :         case MBEDTLS_MD_SHA512:
+     168                 :         89 :             return &mbedtls_sha512_info;
+     169                 :            : #endif
+     170                 :            : #if defined(MBEDTLS_MD_CAN_SHA3_224)
+     171                 :          0 :         case MBEDTLS_MD_SHA3_224:
+     172                 :          0 :             return &mbedtls_sha3_224_info;
+     173                 :            : #endif
+     174                 :            : #if defined(MBEDTLS_MD_CAN_SHA3_256)
+     175                 :          0 :         case MBEDTLS_MD_SHA3_256:
+     176                 :          0 :             return &mbedtls_sha3_256_info;
+     177                 :            : #endif
+     178                 :            : #if defined(MBEDTLS_MD_CAN_SHA3_384)
+     179                 :          0 :         case MBEDTLS_MD_SHA3_384:
+     180                 :          0 :             return &mbedtls_sha3_384_info;
+     181                 :            : #endif
+     182                 :            : #if defined(MBEDTLS_MD_CAN_SHA3_512)
+     183                 :          0 :         case MBEDTLS_MD_SHA3_512:
+     184                 :          0 :             return &mbedtls_sha3_512_info;
+     185                 :            : #endif
+     186                 :          0 :         default:
+     187                 :          0 :             return NULL;
+     188                 :            :     }
+     189                 :            : }
+     190                 :            : 
+     191                 :            : #if defined(MBEDTLS_MD_SOME_PSA)
+     192                 :            : static psa_algorithm_t psa_alg_of_md(const mbedtls_md_info_t *info)
+     193                 :            : {
+     194                 :            :     switch (info->type) {
+     195                 :            : #if defined(MBEDTLS_MD_MD5_VIA_PSA)
+     196                 :            :         case MBEDTLS_MD_MD5:
+     197                 :            :             return PSA_ALG_MD5;
+     198                 :            : #endif
+     199                 :            : #if defined(MBEDTLS_MD_RIPEMD160_VIA_PSA)
+     200                 :            :         case MBEDTLS_MD_RIPEMD160:
+     201                 :            :             return PSA_ALG_RIPEMD160;
+     202                 :            : #endif
+     203                 :            : #if defined(MBEDTLS_MD_SHA1_VIA_PSA)
+     204                 :            :         case MBEDTLS_MD_SHA1:
+     205                 :            :             return PSA_ALG_SHA_1;
+     206                 :            : #endif
+     207                 :            : #if defined(MBEDTLS_MD_SHA224_VIA_PSA)
+     208                 :            :         case MBEDTLS_MD_SHA224:
+     209                 :            :             return PSA_ALG_SHA_224;
+     210                 :            : #endif
+     211                 :            : #if defined(MBEDTLS_MD_SHA256_VIA_PSA)
+     212                 :            :         case MBEDTLS_MD_SHA256:
+     213                 :            :             return PSA_ALG_SHA_256;
+     214                 :            : #endif
+     215                 :            : #if defined(MBEDTLS_MD_SHA384_VIA_PSA)
+     216                 :            :         case MBEDTLS_MD_SHA384:
+     217                 :            :             return PSA_ALG_SHA_384;
+     218                 :            : #endif
+     219                 :            : #if defined(MBEDTLS_MD_SHA512_VIA_PSA)
+     220                 :            :         case MBEDTLS_MD_SHA512:
+     221                 :            :             return PSA_ALG_SHA_512;
+     222                 :            : #endif
+     223                 :            : #if defined(MBEDTLS_MD_SHA3_224_VIA_PSA)
+     224                 :            :         case MBEDTLS_MD_SHA3_224:
+     225                 :            :             return PSA_ALG_SHA3_224;
+     226                 :            : #endif
+     227                 :            : #if defined(MBEDTLS_MD_SHA3_256_VIA_PSA)
+     228                 :            :         case MBEDTLS_MD_SHA3_256:
+     229                 :            :             return PSA_ALG_SHA3_256;
+     230                 :            : #endif
+     231                 :            : #if defined(MBEDTLS_MD_SHA3_384_VIA_PSA)
+     232                 :            :         case MBEDTLS_MD_SHA3_384:
+     233                 :            :             return PSA_ALG_SHA3_384;
+     234                 :            : #endif
+     235                 :            : #if defined(MBEDTLS_MD_SHA3_512_VIA_PSA)
+     236                 :            :         case MBEDTLS_MD_SHA3_512:
+     237                 :            :             return PSA_ALG_SHA3_512;
+     238                 :            : #endif
+     239                 :            :         default:
+     240                 :            :             return PSA_ALG_NONE;
+     241                 :            :     }
+     242                 :            : }
+     243                 :            : 
+     244                 :            : static int md_can_use_psa(const mbedtls_md_info_t *info)
+     245                 :            : {
+     246                 :            :     psa_algorithm_t alg = psa_alg_of_md(info);
+     247                 :            :     if (alg == PSA_ALG_NONE) {
+     248                 :            :         return 0;
+     249                 :            :     }
+     250                 :            : 
+     251                 :            :     return psa_can_do_hash(alg);
+     252                 :            : }
+     253                 :            : #endif /* MBEDTLS_MD_SOME_PSA */
+     254                 :            : 
+     255                 :       1741 : void mbedtls_md_init(mbedtls_md_context_t *ctx)
+     256                 :            : {
+     257                 :            :     /* Note: this sets engine (if present) to MBEDTLS_MD_ENGINE_LEGACY */
+     258                 :       1741 :     memset(ctx, 0, sizeof(mbedtls_md_context_t));
+     259                 :       1741 : }
+     260                 :            : 
+     261                 :       1745 : void mbedtls_md_free(mbedtls_md_context_t *ctx)
+     262                 :            : {
+     263   [ +  -  -  + ]:       1745 :     if (ctx == NULL || ctx->md_info == NULL) {
+     264                 :          0 :         return;
+     265                 :            :     }
+     266                 :            : 
+     267         [ +  - ]:       1745 :     if (ctx->md_ctx != NULL) {
+     268                 :            : #if defined(MBEDTLS_MD_SOME_PSA)
+     269                 :            :         if (ctx->engine == MBEDTLS_MD_ENGINE_PSA) {
+     270                 :            :             psa_hash_abort(ctx->md_ctx);
+     271                 :            :         } else
+     272                 :            : #endif
+     273   [ -  -  -  -  :       1745 :         switch (ctx->md_info->type) {
+             +  +  +  -  
+                      - ]
+     274                 :            : #if defined(MBEDTLS_MD5_C)
+     275                 :          0 :             case MBEDTLS_MD_MD5:
+     276                 :          0 :                 mbedtls_md5_free(ctx->md_ctx);
+     277                 :          0 :                 break;
+     278                 :            : #endif
+     279                 :            : #if defined(MBEDTLS_RIPEMD160_C)
+     280                 :          0 :             case MBEDTLS_MD_RIPEMD160:
+     281                 :          0 :                 mbedtls_ripemd160_free(ctx->md_ctx);
+     282                 :          0 :                 break;
+     283                 :            : #endif
+     284                 :            : #if defined(MBEDTLS_SHA1_C)
+     285                 :          0 :             case MBEDTLS_MD_SHA1:
+     286                 :          0 :                 mbedtls_sha1_free(ctx->md_ctx);
+     287                 :          0 :                 break;
+     288                 :            : #endif
+     289                 :            : #if defined(MBEDTLS_SHA224_C)
+     290                 :          0 :             case MBEDTLS_MD_SHA224:
+     291                 :          0 :                 mbedtls_sha256_free(ctx->md_ctx);
+     292                 :          0 :                 break;
+     293                 :            : #endif
+     294                 :            : #if defined(MBEDTLS_SHA256_C)
+     295                 :       1743 :             case MBEDTLS_MD_SHA256:
+     296                 :       1743 :                 mbedtls_sha256_free(ctx->md_ctx);
+     297                 :       1743 :                 break;
+     298                 :            : #endif
+     299                 :            : #if defined(MBEDTLS_SHA384_C)
+     300                 :          1 :             case MBEDTLS_MD_SHA384:
+     301                 :          1 :                 mbedtls_sha512_free(ctx->md_ctx);
+     302                 :          1 :                 break;
+     303                 :            : #endif
+     304                 :            : #if defined(MBEDTLS_SHA512_C)
+     305                 :          1 :             case MBEDTLS_MD_SHA512:
+     306                 :          1 :                 mbedtls_sha512_free(ctx->md_ctx);
+     307                 :          1 :                 break;
+     308                 :            : #endif
+     309                 :            : #if defined(MBEDTLS_SHA3_C)
+     310                 :          0 :             case MBEDTLS_MD_SHA3_224:
+     311                 :            :             case MBEDTLS_MD_SHA3_256:
+     312                 :            :             case MBEDTLS_MD_SHA3_384:
+     313                 :            :             case MBEDTLS_MD_SHA3_512:
+     314                 :          0 :                 mbedtls_sha3_free(ctx->md_ctx);
+     315                 :          0 :                 break;
+     316                 :            : #endif
+     317                 :          0 :             default:
+     318                 :            :                 /* Shouldn't happen */
+     319                 :          0 :                 break;
+     320                 :            :         }
+     321                 :       1745 :         mbedtls_free(ctx->md_ctx);
+     322                 :            :     }
+     323                 :            : 
+     324                 :            : #if defined(MBEDTLS_MD_C)
+     325         [ +  + ]:       1745 :     if (ctx->hmac_ctx != NULL) {
+     326                 :       1741 :         mbedtls_zeroize_and_free(ctx->hmac_ctx,
+     327                 :       1741 :                                  2 * ctx->md_info->block_size);
+     328                 :            :     }
+     329                 :            : #endif
+     330                 :            : 
+     331                 :       1745 :     mbedtls_platform_zeroize(ctx, sizeof(mbedtls_md_context_t));
+     332                 :            : }
+     333                 :            : 
+     334                 :          0 : int mbedtls_md_clone(mbedtls_md_context_t *dst,
+     335                 :            :                      const mbedtls_md_context_t *src)
+     336                 :            : {
+     337   [ #  #  #  #  :          0 :     if (dst == NULL || dst->md_info == NULL ||
+                   #  # ]
+     338         [ #  # ]:          0 :         src == NULL || src->md_info == NULL ||
+     339         [ #  # ]:          0 :         dst->md_info != src->md_info) {
+     340                 :          0 :         return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
+     341                 :            :     }
+     342                 :            : 
+     343                 :            : #if defined(MBEDTLS_MD_SOME_PSA)
+     344                 :            :     if (src->engine != dst->engine) {
+     345                 :            :         /* This can happen with src set to legacy because PSA wasn't ready
+     346                 :            :          * yet, and dst to PSA because it became ready in the meantime.
+     347                 :            :          * We currently don't support that case (we'd need to re-allocate
+     348                 :            :          * md_ctx to the size of the appropriate MD context). */
+     349                 :            :         return MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE;
+     350                 :            :     }
+     351                 :            : 
+     352                 :            :     if (src->engine == MBEDTLS_MD_ENGINE_PSA) {
+     353                 :            :         psa_status_t status = psa_hash_clone(src->md_ctx, dst->md_ctx);
+     354                 :            :         return mbedtls_md_error_from_psa(status);
+     355                 :            :     }
+     356                 :            : #endif
+     357                 :            : 
+     358   [ #  #  #  #  :          0 :     switch (src->md_info->type) {
+             #  #  #  #  
+                      # ]
+     359                 :            : #if defined(MBEDTLS_MD5_C)
+     360                 :          0 :         case MBEDTLS_MD_MD5:
+     361                 :          0 :             mbedtls_md5_clone(dst->md_ctx, src->md_ctx);
+     362                 :          0 :             break;
+     363                 :            : #endif
+     364                 :            : #if defined(MBEDTLS_RIPEMD160_C)
+     365                 :          0 :         case MBEDTLS_MD_RIPEMD160:
+     366                 :          0 :             mbedtls_ripemd160_clone(dst->md_ctx, src->md_ctx);
+     367                 :          0 :             break;
+     368                 :            : #endif
+     369                 :            : #if defined(MBEDTLS_SHA1_C)
+     370                 :          0 :         case MBEDTLS_MD_SHA1:
+     371                 :          0 :             mbedtls_sha1_clone(dst->md_ctx, src->md_ctx);
+     372                 :          0 :             break;
+     373                 :            : #endif
+     374                 :            : #if defined(MBEDTLS_SHA224_C)
+     375                 :          0 :         case MBEDTLS_MD_SHA224:
+     376                 :          0 :             mbedtls_sha256_clone(dst->md_ctx, src->md_ctx);
+     377                 :          0 :             break;
+     378                 :            : #endif
+     379                 :            : #if defined(MBEDTLS_SHA256_C)
+     380                 :          0 :         case MBEDTLS_MD_SHA256:
+     381                 :          0 :             mbedtls_sha256_clone(dst->md_ctx, src->md_ctx);
+     382                 :          0 :             break;
+     383                 :            : #endif
+     384                 :            : #if defined(MBEDTLS_SHA384_C)
+     385                 :          0 :         case MBEDTLS_MD_SHA384:
+     386                 :          0 :             mbedtls_sha512_clone(dst->md_ctx, src->md_ctx);
+     387                 :          0 :             break;
+     388                 :            : #endif
+     389                 :            : #if defined(MBEDTLS_SHA512_C)
+     390                 :          0 :         case MBEDTLS_MD_SHA512:
+     391                 :          0 :             mbedtls_sha512_clone(dst->md_ctx, src->md_ctx);
+     392                 :          0 :             break;
+     393                 :            : #endif
+     394                 :            : #if defined(MBEDTLS_SHA3_C)
+     395                 :          0 :         case MBEDTLS_MD_SHA3_224:
+     396                 :            :         case MBEDTLS_MD_SHA3_256:
+     397                 :            :         case MBEDTLS_MD_SHA3_384:
+     398                 :            :         case MBEDTLS_MD_SHA3_512:
+     399                 :          0 :             mbedtls_sha3_clone(dst->md_ctx, src->md_ctx);
+     400                 :          0 :             break;
+     401                 :            : #endif
+     402                 :          0 :         default:
+     403                 :          0 :             return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
+     404                 :            :     }
+     405                 :            : 
+     406                 :          0 :     return 0;
+     407                 :            : }
+     408                 :            : 
+     409                 :            : #define ALLOC(type)                                                   \
+     410                 :            :     do {                                                                \
+     411                 :            :         ctx->md_ctx = mbedtls_calloc(1, sizeof(mbedtls_##type##_context)); \
+     412                 :            :         if (ctx->md_ctx == NULL)                                       \
+     413                 :            :         return MBEDTLS_ERR_MD_ALLOC_FAILED;                      \
+     414                 :            :         mbedtls_##type##_init(ctx->md_ctx);                           \
+     415                 :            :     }                                                                   \
+     416                 :            :     while (0)
+     417                 :            : 
+     418                 :       1745 : int mbedtls_md_setup(mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac)
+     419                 :            : {
+     420                 :            : #if defined(MBEDTLS_MD_C)
+     421         [ -  + ]:       1745 :     if (ctx == NULL) {
+     422                 :          0 :         return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
+     423                 :            :     }
+     424                 :            : #endif
+     425         [ -  + ]:       1745 :     if (md_info == NULL) {
+     426                 :          0 :         return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
+     427                 :            :     }
+     428                 :            : 
+     429                 :       1745 :     ctx->md_info = md_info;
+     430                 :       1745 :     ctx->md_ctx = NULL;
+     431                 :            : #if defined(MBEDTLS_MD_C)
+     432                 :       1745 :     ctx->hmac_ctx = NULL;
+     433                 :            : #else
+     434                 :            :     if (hmac != 0) {
+     435                 :            :         return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
+     436                 :            :     }
+     437                 :            : #endif
+     438                 :            : 
+     439                 :            : #if defined(MBEDTLS_MD_SOME_PSA)
+     440                 :            :     if (md_can_use_psa(ctx->md_info)) {
+     441                 :            :         ctx->md_ctx = mbedtls_calloc(1, sizeof(psa_hash_operation_t));
+     442                 :            :         if (ctx->md_ctx == NULL) {
+     443                 :            :             return MBEDTLS_ERR_MD_ALLOC_FAILED;
+     444                 :            :         }
+     445                 :            :         ctx->engine = MBEDTLS_MD_ENGINE_PSA;
+     446                 :            :     } else
+     447                 :            : #endif
+     448   [ -  -  -  -  :       1745 :     switch (md_info->type) {
+             +  +  +  -  
+                      - ]
+     449                 :            : #if defined(MBEDTLS_MD5_C)
+     450                 :          0 :         case MBEDTLS_MD_MD5:
+     451         [ #  # ]:          0 :             ALLOC(md5);
+     452                 :          0 :             break;
+     453                 :            : #endif
+     454                 :            : #if defined(MBEDTLS_RIPEMD160_C)
+     455                 :          0 :         case MBEDTLS_MD_RIPEMD160:
+     456         [ #  # ]:          0 :             ALLOC(ripemd160);
+     457                 :          0 :             break;
+     458                 :            : #endif
+     459                 :            : #if defined(MBEDTLS_SHA1_C)
+     460                 :          0 :         case MBEDTLS_MD_SHA1:
+     461         [ #  # ]:          0 :             ALLOC(sha1);
+     462                 :          0 :             break;
+     463                 :            : #endif
+     464                 :            : #if defined(MBEDTLS_SHA224_C)
+     465                 :          0 :         case MBEDTLS_MD_SHA224:
+     466         [ #  # ]:          0 :             ALLOC(sha256);
+     467                 :          0 :             break;
+     468                 :            : #endif
+     469                 :            : #if defined(MBEDTLS_SHA256_C)
+     470                 :       1743 :         case MBEDTLS_MD_SHA256:
+     471         [ -  + ]:       1743 :             ALLOC(sha256);
+     472                 :       1743 :             break;
+     473                 :            : #endif
+     474                 :            : #if defined(MBEDTLS_SHA384_C)
+     475                 :          1 :         case MBEDTLS_MD_SHA384:
+     476         [ -  + ]:          1 :             ALLOC(sha512);
+     477                 :          1 :             break;
+     478                 :            : #endif
+     479                 :            : #if defined(MBEDTLS_SHA512_C)
+     480                 :          1 :         case MBEDTLS_MD_SHA512:
+     481         [ -  + ]:          1 :             ALLOC(sha512);
+     482                 :          1 :             break;
+     483                 :            : #endif
+     484                 :            : #if defined(MBEDTLS_SHA3_C)
+     485                 :          0 :         case MBEDTLS_MD_SHA3_224:
+     486                 :            :         case MBEDTLS_MD_SHA3_256:
+     487                 :            :         case MBEDTLS_MD_SHA3_384:
+     488                 :            :         case MBEDTLS_MD_SHA3_512:
+     489         [ #  # ]:          0 :             ALLOC(sha3);
+     490                 :          0 :             break;
+     491                 :            : #endif
+     492                 :          0 :         default:
+     493                 :          0 :             return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
+     494                 :            :     }
+     495                 :            : 
+     496                 :            : #if defined(MBEDTLS_MD_C)
+     497         [ +  + ]:       1745 :     if (hmac != 0) {
+     498                 :       1741 :         ctx->hmac_ctx = mbedtls_calloc(2, md_info->block_size);
+     499         [ -  + ]:       1741 :         if (ctx->hmac_ctx == NULL) {
+     500                 :          0 :             mbedtls_md_free(ctx);
+     501                 :          0 :             return MBEDTLS_ERR_MD_ALLOC_FAILED;
+     502                 :            :         }
+     503                 :            :     }
+     504                 :            : #endif
+     505                 :            : 
+     506                 :       1745 :     return 0;
+     507                 :            : }
+     508                 :            : #undef ALLOC
+     509                 :            : 
+     510                 :       3648 : int mbedtls_md_starts(mbedtls_md_context_t *ctx)
+     511                 :            : {
+     512                 :            : #if defined(MBEDTLS_MD_C)
+     513   [ +  -  -  + ]:       3648 :     if (ctx == NULL || ctx->md_info == NULL) {
+     514                 :          0 :         return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
+     515                 :            :     }
+     516                 :            : #endif
+     517                 :            : 
+     518                 :            : #if defined(MBEDTLS_MD_SOME_PSA)
+     519                 :            :     if (ctx->engine == MBEDTLS_MD_ENGINE_PSA) {
+     520                 :            :         psa_algorithm_t alg = psa_alg_of_md(ctx->md_info);
+     521                 :            :         psa_hash_abort(ctx->md_ctx);
+     522                 :            :         psa_status_t status = psa_hash_setup(ctx->md_ctx, alg);
+     523                 :            :         return mbedtls_md_error_from_psa(status);
+     524                 :            :     }
+     525                 :            : #endif
+     526                 :            : 
+     527   [ -  -  -  -  :       3648 :     switch (ctx->md_info->type) {
+          +  +  +  -  -  
+                -  -  - ]
+     528                 :            : #if defined(MBEDTLS_MD5_C)
+     529                 :          0 :         case MBEDTLS_MD_MD5:
+     530                 :          0 :             return mbedtls_md5_starts(ctx->md_ctx);
+     531                 :            : #endif
+     532                 :            : #if defined(MBEDTLS_RIPEMD160_C)
+     533                 :          0 :         case MBEDTLS_MD_RIPEMD160:
+     534                 :          0 :             return mbedtls_ripemd160_starts(ctx->md_ctx);
+     535                 :            : #endif
+     536                 :            : #if defined(MBEDTLS_SHA1_C)
+     537                 :          0 :         case MBEDTLS_MD_SHA1:
+     538                 :          0 :             return mbedtls_sha1_starts(ctx->md_ctx);
+     539                 :            : #endif
+     540                 :            : #if defined(MBEDTLS_SHA224_C)
+     541                 :          0 :         case MBEDTLS_MD_SHA224:
+     542                 :          0 :             return mbedtls_sha256_starts(ctx->md_ctx, 1);
+     543                 :            : #endif
+     544                 :            : #if defined(MBEDTLS_SHA256_C)
+     545                 :       3644 :         case MBEDTLS_MD_SHA256:
+     546                 :       3644 :             return mbedtls_sha256_starts(ctx->md_ctx, 0);
+     547                 :            : #endif
+     548                 :            : #if defined(MBEDTLS_SHA384_C)
+     549                 :          2 :         case MBEDTLS_MD_SHA384:
+     550                 :          2 :             return mbedtls_sha512_starts(ctx->md_ctx, 1);
+     551                 :            : #endif
+     552                 :            : #if defined(MBEDTLS_SHA512_C)
+     553                 :          2 :         case MBEDTLS_MD_SHA512:
+     554                 :          2 :             return mbedtls_sha512_starts(ctx->md_ctx, 0);
+     555                 :            : #endif
+     556                 :            : #if defined(MBEDTLS_SHA3_C)
+     557                 :          0 :         case MBEDTLS_MD_SHA3_224:
+     558                 :          0 :             return mbedtls_sha3_starts(ctx->md_ctx, MBEDTLS_SHA3_224);
+     559                 :          0 :         case MBEDTLS_MD_SHA3_256:
+     560                 :          0 :             return mbedtls_sha3_starts(ctx->md_ctx, MBEDTLS_SHA3_256);
+     561                 :          0 :         case MBEDTLS_MD_SHA3_384:
+     562                 :          0 :             return mbedtls_sha3_starts(ctx->md_ctx, MBEDTLS_SHA3_384);
+     563                 :          0 :         case MBEDTLS_MD_SHA3_512:
+     564                 :          0 :             return mbedtls_sha3_starts(ctx->md_ctx, MBEDTLS_SHA3_512);
+     565                 :            : #endif
+     566                 :          0 :         default:
+     567                 :          0 :             return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
+     568                 :            :     }
+     569                 :            : }
+     570                 :            : 
+     571                 :       9848 : int mbedtls_md_update(mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen)
+     572                 :            : {
+     573                 :            : #if defined(MBEDTLS_MD_C)
+     574   [ +  -  -  + ]:       9848 :     if (ctx == NULL || ctx->md_info == NULL) {
+     575                 :          0 :         return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
+     576                 :            :     }
+     577                 :            : #endif
+     578                 :            : 
+     579                 :            : #if defined(MBEDTLS_MD_SOME_PSA)
+     580                 :            :     if (ctx->engine == MBEDTLS_MD_ENGINE_PSA) {
+     581                 :            :         psa_status_t status = psa_hash_update(ctx->md_ctx, input, ilen);
+     582                 :            :         return mbedtls_md_error_from_psa(status);
+     583                 :            :     }
+     584                 :            : #endif
+     585                 :            : 
+     586   [ -  -  -  -  :       9848 :     switch (ctx->md_info->type) {
+             +  +  +  -  
+                      - ]
+     587                 :            : #if defined(MBEDTLS_MD5_C)
+     588                 :          0 :         case MBEDTLS_MD_MD5:
+     589                 :          0 :             return mbedtls_md5_update(ctx->md_ctx, input, ilen);
+     590                 :            : #endif
+     591                 :            : #if defined(MBEDTLS_RIPEMD160_C)
+     592                 :          0 :         case MBEDTLS_MD_RIPEMD160:
+     593                 :          0 :             return mbedtls_ripemd160_update(ctx->md_ctx, input, ilen);
+     594                 :            : #endif
+     595                 :            : #if defined(MBEDTLS_SHA1_C)
+     596                 :          0 :         case MBEDTLS_MD_SHA1:
+     597                 :          0 :             return mbedtls_sha1_update(ctx->md_ctx, input, ilen);
+     598                 :            : #endif
+     599                 :            : #if defined(MBEDTLS_SHA224_C)
+     600                 :          0 :         case MBEDTLS_MD_SHA224:
+     601                 :          0 :             return mbedtls_sha256_update(ctx->md_ctx, input, ilen);
+     602                 :            : #endif
+     603                 :            : #if defined(MBEDTLS_SHA256_C)
+     604                 :       9840 :         case MBEDTLS_MD_SHA256:
+     605                 :       9840 :             return mbedtls_sha256_update(ctx->md_ctx, input, ilen);
+     606                 :            : #endif
+     607                 :            : #if defined(MBEDTLS_SHA384_C)
+     608                 :          4 :         case MBEDTLS_MD_SHA384:
+     609                 :          4 :             return mbedtls_sha512_update(ctx->md_ctx, input, ilen);
+     610                 :            : #endif
+     611                 :            : #if defined(MBEDTLS_SHA512_C)
+     612                 :          4 :         case MBEDTLS_MD_SHA512:
+     613                 :          4 :             return mbedtls_sha512_update(ctx->md_ctx, input, ilen);
+     614                 :            : #endif
+     615                 :            : #if defined(MBEDTLS_SHA3_C)
+     616                 :          0 :         case MBEDTLS_MD_SHA3_224:
+     617                 :            :         case MBEDTLS_MD_SHA3_256:
+     618                 :            :         case MBEDTLS_MD_SHA3_384:
+     619                 :            :         case MBEDTLS_MD_SHA3_512:
+     620                 :          0 :             return mbedtls_sha3_update(ctx->md_ctx, input, ilen);
+     621                 :            : #endif
+     622                 :          0 :         default:
+     623                 :          0 :             return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
+     624                 :            :     }
+     625                 :            : }
+     626                 :            : 
+     627                 :       3642 : int mbedtls_md_finish(mbedtls_md_context_t *ctx, unsigned char *output)
+     628                 :            : {
+     629                 :            : #if defined(MBEDTLS_MD_C)
+     630   [ +  -  -  + ]:       3642 :     if (ctx == NULL || ctx->md_info == NULL) {
+     631                 :          0 :         return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
+     632                 :            :     }
+     633                 :            : #endif
+     634                 :            : 
+     635                 :            : #if defined(MBEDTLS_MD_SOME_PSA)
+     636                 :            :     if (ctx->engine == MBEDTLS_MD_ENGINE_PSA) {
+     637                 :            :         size_t size = ctx->md_info->size;
+     638                 :            :         psa_status_t status = psa_hash_finish(ctx->md_ctx,
+     639                 :            :                                               output, size, &size);
+     640                 :            :         return mbedtls_md_error_from_psa(status);
+     641                 :            :     }
+     642                 :            : #endif
+     643                 :            : 
+     644   [ -  -  -  -  :       3642 :     switch (ctx->md_info->type) {
+             +  +  +  -  
+                      - ]
+     645                 :            : #if defined(MBEDTLS_MD5_C)
+     646                 :          0 :         case MBEDTLS_MD_MD5:
+     647                 :          0 :             return mbedtls_md5_finish(ctx->md_ctx, output);
+     648                 :            : #endif
+     649                 :            : #if defined(MBEDTLS_RIPEMD160_C)
+     650                 :          0 :         case MBEDTLS_MD_RIPEMD160:
+     651                 :          0 :             return mbedtls_ripemd160_finish(ctx->md_ctx, output);
+     652                 :            : #endif
+     653                 :            : #if defined(MBEDTLS_SHA1_C)
+     654                 :          0 :         case MBEDTLS_MD_SHA1:
+     655                 :          0 :             return mbedtls_sha1_finish(ctx->md_ctx, output);
+     656                 :            : #endif
+     657                 :            : #if defined(MBEDTLS_SHA224_C)
+     658                 :          0 :         case MBEDTLS_MD_SHA224:
+     659                 :          0 :             return mbedtls_sha256_finish(ctx->md_ctx, output);
+     660                 :            : #endif
+     661                 :            : #if defined(MBEDTLS_SHA256_C)
+     662                 :       3638 :         case MBEDTLS_MD_SHA256:
+     663                 :       3638 :             return mbedtls_sha256_finish(ctx->md_ctx, output);
+     664                 :            : #endif
+     665                 :            : #if defined(MBEDTLS_SHA384_C)
+     666                 :          2 :         case MBEDTLS_MD_SHA384:
+     667                 :          2 :             return mbedtls_sha512_finish(ctx->md_ctx, output);
+     668                 :            : #endif
+     669                 :            : #if defined(MBEDTLS_SHA512_C)
+     670                 :          2 :         case MBEDTLS_MD_SHA512:
+     671                 :          2 :             return mbedtls_sha512_finish(ctx->md_ctx, output);
+     672                 :            : #endif
+     673                 :            : #if defined(MBEDTLS_SHA3_C)
+     674                 :          0 :         case MBEDTLS_MD_SHA3_224:
+     675                 :            :         case MBEDTLS_MD_SHA3_256:
+     676                 :            :         case MBEDTLS_MD_SHA3_384:
+     677                 :            :         case MBEDTLS_MD_SHA3_512:
+     678                 :          0 :             return mbedtls_sha3_finish(ctx->md_ctx, output, ctx->md_info->size);
+     679                 :            : #endif
+     680                 :          0 :         default:
+     681                 :          0 :             return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
+     682                 :            :     }
+     683                 :            : }
+     684                 :            : 
+     685                 :       1594 : int mbedtls_md(const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen,
+     686                 :            :                unsigned char *output)
+     687                 :            : {
+     688         [ -  + ]:       1594 :     if (md_info == NULL) {
+     689                 :          0 :         return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
+     690                 :            :     }
+     691                 :            : 
+     692                 :            : #if defined(MBEDTLS_MD_SOME_PSA)
+     693                 :            :     if (md_can_use_psa(md_info)) {
+     694                 :            :         size_t size = md_info->size;
+     695                 :            :         psa_status_t status = psa_hash_compute(psa_alg_of_md(md_info),
+     696                 :            :                                                input, ilen,
+     697                 :            :                                                output, size, &size);
+     698                 :            :         return mbedtls_md_error_from_psa(status);
+     699                 :            :     }
+     700                 :            : #endif
+     701                 :            : 
+     702   [ -  -  -  -  :       1594 :     switch (md_info->type) {
+          +  +  +  -  -  
+                -  -  - ]
+     703                 :            : #if defined(MBEDTLS_MD5_C)
+     704                 :          0 :         case MBEDTLS_MD_MD5:
+     705                 :          0 :             return mbedtls_md5(input, ilen, output);
+     706                 :            : #endif
+     707                 :            : #if defined(MBEDTLS_RIPEMD160_C)
+     708                 :          0 :         case MBEDTLS_MD_RIPEMD160:
+     709                 :          0 :             return mbedtls_ripemd160(input, ilen, output);
+     710                 :            : #endif
+     711                 :            : #if defined(MBEDTLS_SHA1_C)
+     712                 :          0 :         case MBEDTLS_MD_SHA1:
+     713                 :          0 :             return mbedtls_sha1(input, ilen, output);
+     714                 :            : #endif
+     715                 :            : #if defined(MBEDTLS_SHA224_C)
+     716                 :          0 :         case MBEDTLS_MD_SHA224:
+     717                 :          0 :             return mbedtls_sha256(input, ilen, output, 1);
+     718                 :            : #endif
+     719                 :            : #if defined(MBEDTLS_SHA256_C)
+     720                 :       1549 :         case MBEDTLS_MD_SHA256:
+     721                 :       1549 :             return mbedtls_sha256(input, ilen, output, 0);
+     722                 :            : #endif
+     723                 :            : #if defined(MBEDTLS_SHA384_C)
+     724                 :          1 :         case MBEDTLS_MD_SHA384:
+     725                 :          1 :             return mbedtls_sha512(input, ilen, output, 1);
+     726                 :            : #endif
+     727                 :            : #if defined(MBEDTLS_SHA512_C)
+     728                 :         44 :         case MBEDTLS_MD_SHA512:
+     729                 :         44 :             return mbedtls_sha512(input, ilen, output, 0);
+     730                 :            : #endif
+     731                 :            : #if defined(MBEDTLS_SHA3_C)
+     732                 :          0 :         case MBEDTLS_MD_SHA3_224:
+     733                 :          0 :             return mbedtls_sha3(MBEDTLS_SHA3_224, input, ilen, output, md_info->size);
+     734                 :          0 :         case MBEDTLS_MD_SHA3_256:
+     735                 :          0 :             return mbedtls_sha3(MBEDTLS_SHA3_256, input, ilen, output, md_info->size);
+     736                 :          0 :         case MBEDTLS_MD_SHA3_384:
+     737                 :          0 :             return mbedtls_sha3(MBEDTLS_SHA3_384, input, ilen, output, md_info->size);
+     738                 :          0 :         case MBEDTLS_MD_SHA3_512:
+     739                 :          0 :             return mbedtls_sha3(MBEDTLS_SHA3_512, input, ilen, output, md_info->size);
+     740                 :            : #endif
+     741                 :          0 :         default:
+     742                 :          0 :             return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
+     743                 :            :     }
+     744                 :            : }
+     745                 :            : 
+     746                 :       3158 : unsigned char mbedtls_md_get_size(const mbedtls_md_info_t *md_info)
+     747                 :            : {
+     748         [ -  + ]:       3158 :     if (md_info == NULL) {
+     749                 :          0 :         return 0;
+     750                 :            :     }
+     751                 :            : 
+     752                 :       3158 :     return md_info->size;
+     753                 :            : }
+     754                 :            : 
+     755                 :          0 : mbedtls_md_type_t mbedtls_md_get_type(const mbedtls_md_info_t *md_info)
+     756                 :            : {
+     757         [ #  # ]:          0 :     if (md_info == NULL) {
+     758                 :          0 :         return MBEDTLS_MD_NONE;
+     759                 :            :     }
+     760                 :            : 
+     761                 :          0 :     return md_info->type;
+     762                 :            : }
+     763                 :            : 
+     764                 :            : #if defined(MBEDTLS_PSA_CRYPTO_C)
+     765                 :            : int mbedtls_md_error_from_psa(psa_status_t status)
+     766                 :            : {
+     767                 :            :     return PSA_TO_MBEDTLS_ERR_LIST(status, psa_to_md_errors,
+     768                 :            :                                    psa_generic_status_to_mbedtls);
+     769                 :            : }
+     770                 :            : #endif /* MBEDTLS_PSA_CRYPTO_C */
+     771                 :            : 
+     772                 :            : 
+     773                 :            : /************************************************************************
+     774                 :            :  * Functions above this separator are part of MBEDTLS_MD_LIGHT,         *
+     775                 :            :  * functions below are only available when MBEDTLS_MD_C is set.         *
+     776                 :            :  ************************************************************************/
+     777                 :            : #if defined(MBEDTLS_MD_C)
+     778                 :            : 
+     779                 :            : /*
+     780                 :            :  * Reminder: update profiles in x509_crt.c when adding a new hash!
+     781                 :            :  */
+     782                 :            : static const int supported_digests[] = {
+     783                 :            : 
+     784                 :            : #if defined(MBEDTLS_MD_CAN_SHA512)
+     785                 :            :     MBEDTLS_MD_SHA512,
+     786                 :            : #endif
+     787                 :            : 
+     788                 :            : #if defined(MBEDTLS_MD_CAN_SHA384)
+     789                 :            :     MBEDTLS_MD_SHA384,
+     790                 :            : #endif
+     791                 :            : 
+     792                 :            : #if defined(MBEDTLS_MD_CAN_SHA256)
+     793                 :            :     MBEDTLS_MD_SHA256,
+     794                 :            : #endif
+     795                 :            : #if defined(MBEDTLS_MD_CAN_SHA224)
+     796                 :            :     MBEDTLS_MD_SHA224,
+     797                 :            : #endif
+     798                 :            : 
+     799                 :            : #if defined(MBEDTLS_MD_CAN_SHA1)
+     800                 :            :     MBEDTLS_MD_SHA1,
+     801                 :            : #endif
+     802                 :            : 
+     803                 :            : #if defined(MBEDTLS_MD_CAN_RIPEMD160)
+     804                 :            :     MBEDTLS_MD_RIPEMD160,
+     805                 :            : #endif
+     806                 :            : 
+     807                 :            : #if defined(MBEDTLS_MD_CAN_MD5)
+     808                 :            :     MBEDTLS_MD_MD5,
+     809                 :            : #endif
+     810                 :            : 
+     811                 :            : #if defined(MBEDTLS_MD_CAN_SHA3_224)
+     812                 :            :     MBEDTLS_MD_SHA3_224,
+     813                 :            : #endif
+     814                 :            : 
+     815                 :            : #if defined(MBEDTLS_MD_CAN_SHA3_256)
+     816                 :            :     MBEDTLS_MD_SHA3_256,
+     817                 :            : #endif
+     818                 :            : 
+     819                 :            : #if defined(MBEDTLS_MD_CAN_SHA3_384)
+     820                 :            :     MBEDTLS_MD_SHA3_384,
+     821                 :            : #endif
+     822                 :            : 
+     823                 :            : #if defined(MBEDTLS_MD_CAN_SHA3_512)
+     824                 :            :     MBEDTLS_MD_SHA3_512,
+     825                 :            : #endif
+     826                 :            : 
+     827                 :            :     MBEDTLS_MD_NONE
+     828                 :            : };
+     829                 :            : 
+     830                 :          0 : const int *mbedtls_md_list(void)
+     831                 :            : {
+     832                 :          0 :     return supported_digests;
+     833                 :            : }
+     834                 :            : 
+     835                 :            : typedef struct {
+     836                 :            :     const char *md_name;
+     837                 :            :     mbedtls_md_type_t md_type;
+     838                 :            : } md_name_entry;
+     839                 :            : 
+     840                 :            : static const md_name_entry md_names[] = {
+     841                 :            : #if defined(MBEDTLS_MD_CAN_MD5)
+     842                 :            :     { "MD5", MBEDTLS_MD_MD5 },
+     843                 :            : #endif
+     844                 :            : #if defined(MBEDTLS_MD_CAN_RIPEMD160)
+     845                 :            :     { "RIPEMD160", MBEDTLS_MD_RIPEMD160 },
+     846                 :            : #endif
+     847                 :            : #if defined(MBEDTLS_MD_CAN_SHA1)
+     848                 :            :     { "SHA1", MBEDTLS_MD_SHA1 },
+     849                 :            :     { "SHA", MBEDTLS_MD_SHA1 }, // compatibility fallback
+     850                 :            : #endif
+     851                 :            : #if defined(MBEDTLS_MD_CAN_SHA224)
+     852                 :            :     { "SHA224", MBEDTLS_MD_SHA224 },
+     853                 :            : #endif
+     854                 :            : #if defined(MBEDTLS_MD_CAN_SHA256)
+     855                 :            :     { "SHA256", MBEDTLS_MD_SHA256 },
+     856                 :            : #endif
+     857                 :            : #if defined(MBEDTLS_MD_CAN_SHA384)
+     858                 :            :     { "SHA384", MBEDTLS_MD_SHA384 },
+     859                 :            : #endif
+     860                 :            : #if defined(MBEDTLS_MD_CAN_SHA512)
+     861                 :            :     { "SHA512", MBEDTLS_MD_SHA512 },
+     862                 :            : #endif
+     863                 :            : #if defined(MBEDTLS_MD_CAN_SHA3_224)
+     864                 :            :     { "SHA3-224", MBEDTLS_MD_SHA3_224 },
+     865                 :            : #endif
+     866                 :            : #if defined(MBEDTLS_MD_CAN_SHA3_256)
+     867                 :            :     { "SHA3-256", MBEDTLS_MD_SHA3_256 },
+     868                 :            : #endif
+     869                 :            : #if defined(MBEDTLS_MD_CAN_SHA3_384)
+     870                 :            :     { "SHA3-384", MBEDTLS_MD_SHA3_384 },
+     871                 :            : #endif
+     872                 :            : #if defined(MBEDTLS_MD_CAN_SHA3_512)
+     873                 :            :     { "SHA3-512", MBEDTLS_MD_SHA3_512 },
+     874                 :            : #endif
+     875                 :            :     { NULL, MBEDTLS_MD_NONE },
+     876                 :            : };
+     877                 :            : 
+     878                 :          0 : const mbedtls_md_info_t *mbedtls_md_info_from_string(const char *md_name)
+     879                 :            : {
+     880         [ #  # ]:          0 :     if (NULL == md_name) {
+     881                 :          0 :         return NULL;
+     882                 :            :     }
+     883                 :            : 
+     884                 :          0 :     const md_name_entry *entry = md_names;
+     885         [ #  # ]:          0 :     while (entry->md_name != NULL &&
+     886         [ #  # ]:          0 :            strcmp(entry->md_name, md_name) != 0) {
+     887                 :          0 :         ++entry;
+     888                 :            :     }
+     889                 :            : 
+     890                 :          0 :     return mbedtls_md_info_from_type(entry->md_type);
+     891                 :            : }
+     892                 :            : 
+     893                 :          0 : const char *mbedtls_md_get_name(const mbedtls_md_info_t *md_info)
+     894                 :            : {
+     895         [ #  # ]:          0 :     if (md_info == NULL) {
+     896                 :          0 :         return NULL;
+     897                 :            :     }
+     898                 :            : 
+     899                 :          0 :     const md_name_entry *entry = md_names;
+     900         [ #  # ]:          0 :     while (entry->md_type != MBEDTLS_MD_NONE &&
+     901         [ #  # ]:          0 :            entry->md_type != md_info->type) {
+     902                 :          0 :         ++entry;
+     903                 :            :     }
+     904                 :            : 
+     905                 :          0 :     return entry->md_name;
+     906                 :            : }
+     907                 :            : 
+     908                 :          0 : const mbedtls_md_info_t *mbedtls_md_info_from_ctx(
+     909                 :            :     const mbedtls_md_context_t *ctx)
+     910                 :            : {
+     911         [ #  # ]:          0 :     if (ctx == NULL) {
+     912                 :          0 :         return NULL;
+     913                 :            :     }
+     914                 :            : 
+     915                 :          0 :     return ctx->MBEDTLS_PRIVATE(md_info);
+     916                 :            : }
+     917                 :            : 
+     918                 :            : #if defined(MBEDTLS_FS_IO)
+     919                 :            : int mbedtls_md_file(const mbedtls_md_info_t *md_info, const char *path, unsigned char *output)
+     920                 :            : {
+     921                 :            :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     922                 :            :     FILE *f;
+     923                 :            :     size_t n;
+     924                 :            :     mbedtls_md_context_t ctx;
+     925                 :            :     unsigned char buf[1024];
+     926                 :            : 
+     927                 :            :     if (md_info == NULL) {
+     928                 :            :         return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
+     929                 :            :     }
+     930                 :            : 
+     931                 :            :     if ((f = fopen(path, "rb")) == NULL) {
+     932                 :            :         return MBEDTLS_ERR_MD_FILE_IO_ERROR;
+     933                 :            :     }
+     934                 :            : 
+     935                 :            :     /* Ensure no stdio buffering of secrets, as such buffers cannot be wiped. */
+     936                 :            :     mbedtls_setbuf(f, NULL);
+     937                 :            : 
+     938                 :            :     mbedtls_md_init(&ctx);
+     939                 :            : 
+     940                 :            :     if ((ret = mbedtls_md_setup(&ctx, md_info, 0)) != 0) {
+     941                 :            :         goto cleanup;
+     942                 :            :     }
+     943                 :            : 
+     944                 :            :     if ((ret = mbedtls_md_starts(&ctx)) != 0) {
+     945                 :            :         goto cleanup;
+     946                 :            :     }
+     947                 :            : 
+     948                 :            :     while ((n = fread(buf, 1, sizeof(buf), f)) > 0) {
+     949                 :            :         if ((ret = mbedtls_md_update(&ctx, buf, n)) != 0) {
+     950                 :            :             goto cleanup;
+     951                 :            :         }
+     952                 :            :     }
+     953                 :            : 
+     954                 :            :     if (ferror(f) != 0) {
+     955                 :            :         ret = MBEDTLS_ERR_MD_FILE_IO_ERROR;
+     956                 :            :     } else {
+     957                 :            :         ret = mbedtls_md_finish(&ctx, output);
+     958                 :            :     }
+     959                 :            : 
+     960                 :            : cleanup:
+     961                 :            :     mbedtls_platform_zeroize(buf, sizeof(buf));
+     962                 :            :     fclose(f);
+     963                 :            :     mbedtls_md_free(&ctx);
+     964                 :            : 
+     965                 :            :     return ret;
+     966                 :            : }
+     967                 :            : #endif /* MBEDTLS_FS_IO */
+     968                 :            : 
+     969                 :       1795 : int mbedtls_md_hmac_starts(mbedtls_md_context_t *ctx, const unsigned char *key, size_t keylen)
+     970                 :            : {
+     971                 :       1795 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     972                 :            :     unsigned char sum[MBEDTLS_MD_MAX_SIZE];
+     973                 :            :     unsigned char *ipad, *opad;
+     974                 :            : 
+     975   [ +  -  +  -  :       1795 :     if (ctx == NULL || ctx->md_info == NULL || ctx->hmac_ctx == NULL) {
+                   -  + ]
+     976                 :          0 :         return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
+     977                 :            :     }
+     978                 :            : 
+     979         [ -  + ]:       1795 :     if (keylen > (size_t) ctx->md_info->block_size) {
+     980         [ #  # ]:          0 :         if ((ret = mbedtls_md_starts(ctx)) != 0) {
+     981                 :          0 :             goto cleanup;
+     982                 :            :         }
+     983         [ #  # ]:          0 :         if ((ret = mbedtls_md_update(ctx, key, keylen)) != 0) {
+     984                 :          0 :             goto cleanup;
+     985                 :            :         }
+     986         [ #  # ]:          0 :         if ((ret = mbedtls_md_finish(ctx, sum)) != 0) {
+     987                 :          0 :             goto cleanup;
+     988                 :            :         }
+     989                 :            : 
+     990                 :          0 :         keylen = ctx->md_info->size;
+     991                 :          0 :         key = sum;
+     992                 :            :     }
+     993                 :            : 
+     994                 :       1795 :     ipad = (unsigned char *) ctx->hmac_ctx;
+     995                 :       1795 :     opad = (unsigned char *) ctx->hmac_ctx + ctx->md_info->block_size;
+     996                 :            : 
+     997                 :       1795 :     memset(ipad, 0x36, ctx->md_info->block_size);
+     998                 :       1795 :     memset(opad, 0x5C, ctx->md_info->block_size);
+     999                 :            : 
+    1000                 :            :     mbedtls_xor(ipad, ipad, key, keylen);
+    1001                 :            :     mbedtls_xor(opad, opad, key, keylen);
+    1002                 :            : 
+    1003         [ -  + ]:       1795 :     if ((ret = mbedtls_md_starts(ctx)) != 0) {
+    1004                 :          0 :         goto cleanup;
+    1005                 :            :     }
+    1006         [ +  - ]:       1795 :     if ((ret = mbedtls_md_update(ctx, ipad,
+    1007                 :       1795 :                                  ctx->md_info->block_size)) != 0) {
+    1008                 :          0 :         goto cleanup;
+    1009                 :            :     }
+    1010                 :            : 
+    1011                 :       1795 : cleanup:
+    1012                 :       1795 :     mbedtls_platform_zeroize(sum, sizeof(sum));
+    1013                 :            : 
+    1014                 :       1795 :     return ret;
+    1015                 :            : }
+    1016                 :            : 
+    1017                 :       4369 : int mbedtls_md_hmac_update(mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen)
+    1018                 :            : {
+    1019   [ +  -  +  -  :       4369 :     if (ctx == NULL || ctx->md_info == NULL || ctx->hmac_ctx == NULL) {
+                   -  + ]
+    1020                 :          0 :         return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
+    1021                 :            :     }
+    1022                 :            : 
+    1023                 :       4369 :     return mbedtls_md_update(ctx, input, ilen);
+    1024                 :            : }
+    1025                 :            : 
+    1026                 :       1813 : int mbedtls_md_hmac_finish(mbedtls_md_context_t *ctx, unsigned char *output)
+    1027                 :            : {
+    1028                 :       1813 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1029                 :            :     unsigned char tmp[MBEDTLS_MD_MAX_SIZE];
+    1030                 :            :     unsigned char *opad;
+    1031                 :            : 
+    1032   [ +  -  +  -  :       1813 :     if (ctx == NULL || ctx->md_info == NULL || ctx->hmac_ctx == NULL) {
+                   -  + ]
+    1033                 :          0 :         return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
+    1034                 :            :     }
+    1035                 :            : 
+    1036                 :       1813 :     opad = (unsigned char *) ctx->hmac_ctx + ctx->md_info->block_size;
+    1037                 :            : 
+    1038         [ -  + ]:       1813 :     if ((ret = mbedtls_md_finish(ctx, tmp)) != 0) {
+    1039                 :          0 :         return ret;
+    1040                 :            :     }
+    1041         [ -  + ]:       1813 :     if ((ret = mbedtls_md_starts(ctx)) != 0) {
+    1042                 :          0 :         return ret;
+    1043                 :            :     }
+    1044         [ -  + ]:       1813 :     if ((ret = mbedtls_md_update(ctx, opad,
+    1045                 :       1813 :                                  ctx->md_info->block_size)) != 0) {
+    1046                 :          0 :         return ret;
+    1047                 :            :     }
+    1048         [ -  + ]:       1813 :     if ((ret = mbedtls_md_update(ctx, tmp,
+    1049                 :       1813 :                                  ctx->md_info->size)) != 0) {
+    1050                 :          0 :         return ret;
+    1051                 :            :     }
+    1052                 :       1813 :     return mbedtls_md_finish(ctx, output);
+    1053                 :            : }
+    1054                 :            : 
+    1055                 :         24 : int mbedtls_md_hmac_reset(mbedtls_md_context_t *ctx)
+    1056                 :            : {
+    1057                 :         24 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1058                 :            :     unsigned char *ipad;
+    1059                 :            : 
+    1060   [ +  -  +  -  :         24 :     if (ctx == NULL || ctx->md_info == NULL || ctx->hmac_ctx == NULL) {
+                   -  + ]
+    1061                 :          0 :         return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
+    1062                 :            :     }
+    1063                 :            : 
+    1064                 :         24 :     ipad = (unsigned char *) ctx->hmac_ctx;
+    1065                 :            : 
+    1066         [ -  + ]:         24 :     if ((ret = mbedtls_md_starts(ctx)) != 0) {
+    1067                 :          0 :         return ret;
+    1068                 :            :     }
+    1069                 :         24 :     return mbedtls_md_update(ctx, ipad, ctx->md_info->block_size);
+    1070                 :            : }
+    1071                 :            : 
+    1072                 :        508 : int mbedtls_md_hmac(const mbedtls_md_info_t *md_info,
+    1073                 :            :                     const unsigned char *key, size_t keylen,
+    1074                 :            :                     const unsigned char *input, size_t ilen,
+    1075                 :            :                     unsigned char *output)
+    1076                 :            : {
+    1077                 :            :     mbedtls_md_context_t ctx;
+    1078                 :        508 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1079                 :            : 
+    1080         [ -  + ]:        508 :     if (md_info == NULL) {
+    1081                 :          0 :         return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
+    1082                 :            :     }
+    1083                 :            : 
+    1084                 :        508 :     mbedtls_md_init(&ctx);
+    1085                 :            : 
+    1086         [ -  + ]:        508 :     if ((ret = mbedtls_md_setup(&ctx, md_info, 1)) != 0) {
+    1087                 :          0 :         goto cleanup;
+    1088                 :            :     }
+    1089                 :            : 
+    1090         [ -  + ]:        508 :     if ((ret = mbedtls_md_hmac_starts(&ctx, key, keylen)) != 0) {
+    1091                 :          0 :         goto cleanup;
+    1092                 :            :     }
+    1093         [ -  + ]:        508 :     if ((ret = mbedtls_md_hmac_update(&ctx, input, ilen)) != 0) {
+    1094                 :          0 :         goto cleanup;
+    1095                 :            :     }
+    1096         [ +  - ]:        508 :     if ((ret = mbedtls_md_hmac_finish(&ctx, output)) != 0) {
+    1097                 :          0 :         goto cleanup;
+    1098                 :            :     }
+    1099                 :            : 
+    1100                 :        508 : cleanup:
+    1101                 :        508 :     mbedtls_md_free(&ctx);
+    1102                 :            : 
+    1103                 :        508 :     return ret;
+    1104                 :            : }
+    1105                 :            : 
+    1106                 :            : #endif /* MBEDTLS_MD_C */
+    1107                 :            : 
+    1108                 :            : #endif /* MBEDTLS_MD_LIGHT */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/md5.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/md5.c.func-sort-c.html new file mode 100644 index 00000000000..96dfc955f54 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/md5.c.func-sort-c.html @@ -0,0 +1,117 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/md5.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - md5.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:01910.0 %
Date:2024-09-22 08:21:07Functions:090.0 %
Branches:0440.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_internal_md5_process0
mbedtls_md50
mbedtls_md5_clone0
mbedtls_md5_finish0
mbedtls_md5_free0
mbedtls_md5_init0
mbedtls_md5_self_test0
mbedtls_md5_starts0
mbedtls_md5_update0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/md5.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/md5.c.func.html new file mode 100644 index 00000000000..64b713a3d9c --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/md5.c.func.html @@ -0,0 +1,117 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/md5.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - md5.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:01910.0 %
Date:2024-09-22 08:21:07Functions:090.0 %
Branches:0440.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_internal_md5_process0
mbedtls_md50
mbedtls_md5_clone0
mbedtls_md5_finish0
mbedtls_md5_free0
mbedtls_md5_init0
mbedtls_md5_self_test0
mbedtls_md5_starts0
mbedtls_md5_update0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/md5.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/md5.c.gcov.html new file mode 100644 index 00000000000..92df1fe93ad --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/md5.c.gcov.html @@ -0,0 +1,511 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/md5.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - md5.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:01910.0 %
Date:2024-09-22 08:21:07Functions:090.0 %
Branches:0440.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  *  RFC 1321 compliant MD5 implementation
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  */
+       7                 :            : /*
+       8                 :            :  *  The MD5 algorithm was designed by Ron Rivest in 1991.
+       9                 :            :  *
+      10                 :            :  *  http://www.ietf.org/rfc/rfc1321.txt
+      11                 :            :  */
+      12                 :            : 
+      13                 :            : #include "common.h"
+      14                 :            : 
+      15                 :            : #if defined(MBEDTLS_MD5_C)
+      16                 :            : 
+      17                 :            : #include "mbedtls/md5.h"
+      18                 :            : #include "mbedtls/platform_util.h"
+      19                 :            : #include "mbedtls/error.h"
+      20                 :            : 
+      21                 :            : #include <string.h>
+      22                 :            : 
+      23                 :            : #include "mbedtls/platform.h"
+      24                 :            : 
+      25                 :            : #if !defined(MBEDTLS_MD5_ALT)
+      26                 :            : 
+      27                 :          0 : void mbedtls_md5_init(mbedtls_md5_context *ctx)
+      28                 :            : {
+      29                 :          0 :     memset(ctx, 0, sizeof(mbedtls_md5_context));
+      30                 :          0 : }
+      31                 :            : 
+      32                 :          0 : void mbedtls_md5_free(mbedtls_md5_context *ctx)
+      33                 :            : {
+      34         [ #  # ]:          0 :     if (ctx == NULL) {
+      35                 :          0 :         return;
+      36                 :            :     }
+      37                 :            : 
+      38                 :          0 :     mbedtls_platform_zeroize(ctx, sizeof(mbedtls_md5_context));
+      39                 :            : }
+      40                 :            : 
+      41                 :          0 : void mbedtls_md5_clone(mbedtls_md5_context *dst,
+      42                 :            :                        const mbedtls_md5_context *src)
+      43                 :            : {
+      44                 :          0 :     *dst = *src;
+      45                 :          0 : }
+      46                 :            : 
+      47                 :            : /*
+      48                 :            :  * MD5 context setup
+      49                 :            :  */
+      50                 :          0 : int mbedtls_md5_starts(mbedtls_md5_context *ctx)
+      51                 :            : {
+      52                 :          0 :     ctx->total[0] = 0;
+      53                 :          0 :     ctx->total[1] = 0;
+      54                 :            : 
+      55                 :          0 :     ctx->state[0] = 0x67452301;
+      56                 :          0 :     ctx->state[1] = 0xEFCDAB89;
+      57                 :          0 :     ctx->state[2] = 0x98BADCFE;
+      58                 :          0 :     ctx->state[3] = 0x10325476;
+      59                 :            : 
+      60                 :          0 :     return 0;
+      61                 :            : }
+      62                 :            : 
+      63                 :            : #if !defined(MBEDTLS_MD5_PROCESS_ALT)
+      64                 :          0 : int mbedtls_internal_md5_process(mbedtls_md5_context *ctx,
+      65                 :            :                                  const unsigned char data[64])
+      66                 :            : {
+      67                 :            :     struct {
+      68                 :            :         uint32_t X[16], A, B, C, D;
+      69                 :            :     } local;
+      70                 :            : 
+      71                 :          0 :     local.X[0] = MBEDTLS_GET_UINT32_LE(data,  0);
+      72                 :          0 :     local.X[1] = MBEDTLS_GET_UINT32_LE(data,  4);
+      73                 :          0 :     local.X[2] = MBEDTLS_GET_UINT32_LE(data,  8);
+      74                 :          0 :     local.X[3] = MBEDTLS_GET_UINT32_LE(data, 12);
+      75                 :          0 :     local.X[4] = MBEDTLS_GET_UINT32_LE(data, 16);
+      76                 :          0 :     local.X[5] = MBEDTLS_GET_UINT32_LE(data, 20);
+      77                 :          0 :     local.X[6] = MBEDTLS_GET_UINT32_LE(data, 24);
+      78                 :          0 :     local.X[7] = MBEDTLS_GET_UINT32_LE(data, 28);
+      79                 :          0 :     local.X[8] = MBEDTLS_GET_UINT32_LE(data, 32);
+      80                 :          0 :     local.X[9] = MBEDTLS_GET_UINT32_LE(data, 36);
+      81                 :          0 :     local.X[10] = MBEDTLS_GET_UINT32_LE(data, 40);
+      82                 :          0 :     local.X[11] = MBEDTLS_GET_UINT32_LE(data, 44);
+      83                 :          0 :     local.X[12] = MBEDTLS_GET_UINT32_LE(data, 48);
+      84                 :          0 :     local.X[13] = MBEDTLS_GET_UINT32_LE(data, 52);
+      85                 :          0 :     local.X[14] = MBEDTLS_GET_UINT32_LE(data, 56);
+      86                 :          0 :     local.X[15] = MBEDTLS_GET_UINT32_LE(data, 60);
+      87                 :            : 
+      88                 :            : #define S(x, n)                                                          \
+      89                 :            :     (((x) << (n)) | (((x) & 0xFFFFFFFF) >> (32 - (n))))
+      90                 :            : 
+      91                 :            : #define P(a, b, c, d, k, s, t)                                                \
+      92                 :            :     do                                                                  \
+      93                 :            :     {                                                                   \
+      94                 :            :         (a) += F((b), (c), (d)) + local.X[(k)] + (t);                     \
+      95                 :            :         (a) = S((a), (s)) + (b);                                         \
+      96                 :            :     } while (0)
+      97                 :            : 
+      98                 :          0 :     local.A = ctx->state[0];
+      99                 :          0 :     local.B = ctx->state[1];
+     100                 :          0 :     local.C = ctx->state[2];
+     101                 :          0 :     local.D = ctx->state[3];
+     102                 :            : 
+     103                 :            : #define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
+     104                 :            : 
+     105                 :          0 :     P(local.A, local.B, local.C, local.D,  0,  7, 0xD76AA478);
+     106                 :          0 :     P(local.D, local.A, local.B, local.C,  1, 12, 0xE8C7B756);
+     107                 :          0 :     P(local.C, local.D, local.A, local.B,  2, 17, 0x242070DB);
+     108                 :          0 :     P(local.B, local.C, local.D, local.A,  3, 22, 0xC1BDCEEE);
+     109                 :          0 :     P(local.A, local.B, local.C, local.D,  4,  7, 0xF57C0FAF);
+     110                 :          0 :     P(local.D, local.A, local.B, local.C,  5, 12, 0x4787C62A);
+     111                 :          0 :     P(local.C, local.D, local.A, local.B,  6, 17, 0xA8304613);
+     112                 :          0 :     P(local.B, local.C, local.D, local.A,  7, 22, 0xFD469501);
+     113                 :          0 :     P(local.A, local.B, local.C, local.D,  8,  7, 0x698098D8);
+     114                 :          0 :     P(local.D, local.A, local.B, local.C,  9, 12, 0x8B44F7AF);
+     115                 :          0 :     P(local.C, local.D, local.A, local.B, 10, 17, 0xFFFF5BB1);
+     116                 :          0 :     P(local.B, local.C, local.D, local.A, 11, 22, 0x895CD7BE);
+     117                 :          0 :     P(local.A, local.B, local.C, local.D, 12,  7, 0x6B901122);
+     118                 :          0 :     P(local.D, local.A, local.B, local.C, 13, 12, 0xFD987193);
+     119                 :          0 :     P(local.C, local.D, local.A, local.B, 14, 17, 0xA679438E);
+     120                 :          0 :     P(local.B, local.C, local.D, local.A, 15, 22, 0x49B40821);
+     121                 :            : 
+     122                 :            : #undef F
+     123                 :            : 
+     124                 :            : #define F(x, y, z) ((y) ^ ((z) & ((x) ^ (y))))
+     125                 :            : 
+     126                 :          0 :     P(local.A, local.B, local.C, local.D,  1,  5, 0xF61E2562);
+     127                 :          0 :     P(local.D, local.A, local.B, local.C,  6,  9, 0xC040B340);
+     128                 :          0 :     P(local.C, local.D, local.A, local.B, 11, 14, 0x265E5A51);
+     129                 :          0 :     P(local.B, local.C, local.D, local.A,  0, 20, 0xE9B6C7AA);
+     130                 :          0 :     P(local.A, local.B, local.C, local.D,  5,  5, 0xD62F105D);
+     131                 :          0 :     P(local.D, local.A, local.B, local.C, 10,  9, 0x02441453);
+     132                 :          0 :     P(local.C, local.D, local.A, local.B, 15, 14, 0xD8A1E681);
+     133                 :          0 :     P(local.B, local.C, local.D, local.A,  4, 20, 0xE7D3FBC8);
+     134                 :          0 :     P(local.A, local.B, local.C, local.D,  9,  5, 0x21E1CDE6);
+     135                 :          0 :     P(local.D, local.A, local.B, local.C, 14,  9, 0xC33707D6);
+     136                 :          0 :     P(local.C, local.D, local.A, local.B,  3, 14, 0xF4D50D87);
+     137                 :          0 :     P(local.B, local.C, local.D, local.A,  8, 20, 0x455A14ED);
+     138                 :          0 :     P(local.A, local.B, local.C, local.D, 13,  5, 0xA9E3E905);
+     139                 :          0 :     P(local.D, local.A, local.B, local.C,  2,  9, 0xFCEFA3F8);
+     140                 :          0 :     P(local.C, local.D, local.A, local.B,  7, 14, 0x676F02D9);
+     141                 :          0 :     P(local.B, local.C, local.D, local.A, 12, 20, 0x8D2A4C8A);
+     142                 :            : 
+     143                 :            : #undef F
+     144                 :            : 
+     145                 :            : #define F(x, y, z) ((x) ^ (y) ^ (z))
+     146                 :            : 
+     147                 :          0 :     P(local.A, local.B, local.C, local.D,  5,  4, 0xFFFA3942);
+     148                 :          0 :     P(local.D, local.A, local.B, local.C,  8, 11, 0x8771F681);
+     149                 :          0 :     P(local.C, local.D, local.A, local.B, 11, 16, 0x6D9D6122);
+     150                 :          0 :     P(local.B, local.C, local.D, local.A, 14, 23, 0xFDE5380C);
+     151                 :          0 :     P(local.A, local.B, local.C, local.D,  1,  4, 0xA4BEEA44);
+     152                 :          0 :     P(local.D, local.A, local.B, local.C,  4, 11, 0x4BDECFA9);
+     153                 :          0 :     P(local.C, local.D, local.A, local.B,  7, 16, 0xF6BB4B60);
+     154                 :          0 :     P(local.B, local.C, local.D, local.A, 10, 23, 0xBEBFBC70);
+     155                 :          0 :     P(local.A, local.B, local.C, local.D, 13,  4, 0x289B7EC6);
+     156                 :          0 :     P(local.D, local.A, local.B, local.C,  0, 11, 0xEAA127FA);
+     157                 :          0 :     P(local.C, local.D, local.A, local.B,  3, 16, 0xD4EF3085);
+     158                 :          0 :     P(local.B, local.C, local.D, local.A,  6, 23, 0x04881D05);
+     159                 :          0 :     P(local.A, local.B, local.C, local.D,  9,  4, 0xD9D4D039);
+     160                 :          0 :     P(local.D, local.A, local.B, local.C, 12, 11, 0xE6DB99E5);
+     161                 :          0 :     P(local.C, local.D, local.A, local.B, 15, 16, 0x1FA27CF8);
+     162                 :          0 :     P(local.B, local.C, local.D, local.A,  2, 23, 0xC4AC5665);
+     163                 :            : 
+     164                 :            : #undef F
+     165                 :            : 
+     166                 :            : #define F(x, y, z) ((y) ^ ((x) | ~(z)))
+     167                 :            : 
+     168                 :          0 :     P(local.A, local.B, local.C, local.D,  0,  6, 0xF4292244);
+     169                 :          0 :     P(local.D, local.A, local.B, local.C,  7, 10, 0x432AFF97);
+     170                 :          0 :     P(local.C, local.D, local.A, local.B, 14, 15, 0xAB9423A7);
+     171                 :          0 :     P(local.B, local.C, local.D, local.A,  5, 21, 0xFC93A039);
+     172                 :          0 :     P(local.A, local.B, local.C, local.D, 12,  6, 0x655B59C3);
+     173                 :          0 :     P(local.D, local.A, local.B, local.C,  3, 10, 0x8F0CCC92);
+     174                 :          0 :     P(local.C, local.D, local.A, local.B, 10, 15, 0xFFEFF47D);
+     175                 :          0 :     P(local.B, local.C, local.D, local.A,  1, 21, 0x85845DD1);
+     176                 :          0 :     P(local.A, local.B, local.C, local.D,  8,  6, 0x6FA87E4F);
+     177                 :          0 :     P(local.D, local.A, local.B, local.C, 15, 10, 0xFE2CE6E0);
+     178                 :          0 :     P(local.C, local.D, local.A, local.B,  6, 15, 0xA3014314);
+     179                 :          0 :     P(local.B, local.C, local.D, local.A, 13, 21, 0x4E0811A1);
+     180                 :          0 :     P(local.A, local.B, local.C, local.D,  4,  6, 0xF7537E82);
+     181                 :          0 :     P(local.D, local.A, local.B, local.C, 11, 10, 0xBD3AF235);
+     182                 :          0 :     P(local.C, local.D, local.A, local.B,  2, 15, 0x2AD7D2BB);
+     183                 :          0 :     P(local.B, local.C, local.D, local.A,  9, 21, 0xEB86D391);
+     184                 :            : 
+     185                 :            : #undef F
+     186                 :            : 
+     187                 :          0 :     ctx->state[0] += local.A;
+     188                 :          0 :     ctx->state[1] += local.B;
+     189                 :          0 :     ctx->state[2] += local.C;
+     190                 :          0 :     ctx->state[3] += local.D;
+     191                 :            : 
+     192                 :            :     /* Zeroise variables to clear sensitive data from memory. */
+     193                 :          0 :     mbedtls_platform_zeroize(&local, sizeof(local));
+     194                 :            : 
+     195                 :          0 :     return 0;
+     196                 :            : }
+     197                 :            : 
+     198                 :            : #endif /* !MBEDTLS_MD5_PROCESS_ALT */
+     199                 :            : 
+     200                 :            : /*
+     201                 :            :  * MD5 process buffer
+     202                 :            :  */
+     203                 :          0 : int mbedtls_md5_update(mbedtls_md5_context *ctx,
+     204                 :            :                        const unsigned char *input,
+     205                 :            :                        size_t ilen)
+     206                 :            : {
+     207                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     208                 :            :     size_t fill;
+     209                 :            :     uint32_t left;
+     210                 :            : 
+     211         [ #  # ]:          0 :     if (ilen == 0) {
+     212                 :          0 :         return 0;
+     213                 :            :     }
+     214                 :            : 
+     215                 :          0 :     left = ctx->total[0] & 0x3F;
+     216                 :          0 :     fill = 64 - left;
+     217                 :            : 
+     218                 :          0 :     ctx->total[0] += (uint32_t) ilen;
+     219                 :          0 :     ctx->total[0] &= 0xFFFFFFFF;
+     220                 :            : 
+     221         [ #  # ]:          0 :     if (ctx->total[0] < (uint32_t) ilen) {
+     222                 :          0 :         ctx->total[1]++;
+     223                 :            :     }
+     224                 :            : 
+     225   [ #  #  #  # ]:          0 :     if (left && ilen >= fill) {
+     226                 :          0 :         memcpy((void *) (ctx->buffer + left), input, fill);
+     227         [ #  # ]:          0 :         if ((ret = mbedtls_internal_md5_process(ctx, ctx->buffer)) != 0) {
+     228                 :          0 :             return ret;
+     229                 :            :         }
+     230                 :            : 
+     231                 :          0 :         input += fill;
+     232                 :          0 :         ilen  -= fill;
+     233                 :          0 :         left = 0;
+     234                 :            :     }
+     235                 :            : 
+     236         [ #  # ]:          0 :     while (ilen >= 64) {
+     237         [ #  # ]:          0 :         if ((ret = mbedtls_internal_md5_process(ctx, input)) != 0) {
+     238                 :          0 :             return ret;
+     239                 :            :         }
+     240                 :            : 
+     241                 :          0 :         input += 64;
+     242                 :          0 :         ilen  -= 64;
+     243                 :            :     }
+     244                 :            : 
+     245         [ #  # ]:          0 :     if (ilen > 0) {
+     246                 :          0 :         memcpy((void *) (ctx->buffer + left), input, ilen);
+     247                 :            :     }
+     248                 :            : 
+     249                 :          0 :     return 0;
+     250                 :            : }
+     251                 :            : 
+     252                 :            : /*
+     253                 :            :  * MD5 final digest
+     254                 :            :  */
+     255                 :          0 : int mbedtls_md5_finish(mbedtls_md5_context *ctx,
+     256                 :            :                        unsigned char output[16])
+     257                 :            : {
+     258                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     259                 :            :     uint32_t used;
+     260                 :            :     uint32_t high, low;
+     261                 :            : 
+     262                 :            :     /*
+     263                 :            :      * Add padding: 0x80 then 0x00 until 8 bytes remain for the length
+     264                 :            :      */
+     265                 :          0 :     used = ctx->total[0] & 0x3F;
+     266                 :            : 
+     267                 :          0 :     ctx->buffer[used++] = 0x80;
+     268                 :            : 
+     269         [ #  # ]:          0 :     if (used <= 56) {
+     270                 :            :         /* Enough room for padding + length in current block */
+     271                 :          0 :         memset(ctx->buffer + used, 0, 56 - used);
+     272                 :            :     } else {
+     273                 :            :         /* We'll need an extra block */
+     274                 :          0 :         memset(ctx->buffer + used, 0, 64 - used);
+     275                 :            : 
+     276         [ #  # ]:          0 :         if ((ret = mbedtls_internal_md5_process(ctx, ctx->buffer)) != 0) {
+     277                 :          0 :             goto exit;
+     278                 :            :         }
+     279                 :            : 
+     280                 :          0 :         memset(ctx->buffer, 0, 56);
+     281                 :            :     }
+     282                 :            : 
+     283                 :            :     /*
+     284                 :            :      * Add message length
+     285                 :            :      */
+     286                 :          0 :     high = (ctx->total[0] >> 29)
+     287                 :          0 :            | (ctx->total[1] <<  3);
+     288                 :          0 :     low  = (ctx->total[0] <<  3);
+     289                 :            : 
+     290                 :          0 :     MBEDTLS_PUT_UINT32_LE(low,  ctx->buffer, 56);
+     291                 :          0 :     MBEDTLS_PUT_UINT32_LE(high, ctx->buffer, 60);
+     292                 :            : 
+     293         [ #  # ]:          0 :     if ((ret = mbedtls_internal_md5_process(ctx, ctx->buffer)) != 0) {
+     294                 :          0 :         goto exit;
+     295                 :            :     }
+     296                 :            : 
+     297                 :            :     /*
+     298                 :            :      * Output final state
+     299                 :            :      */
+     300                 :          0 :     MBEDTLS_PUT_UINT32_LE(ctx->state[0], output,  0);
+     301                 :          0 :     MBEDTLS_PUT_UINT32_LE(ctx->state[1], output,  4);
+     302                 :          0 :     MBEDTLS_PUT_UINT32_LE(ctx->state[2], output,  8);
+     303                 :          0 :     MBEDTLS_PUT_UINT32_LE(ctx->state[3], output, 12);
+     304                 :            : 
+     305                 :          0 :     ret = 0;
+     306                 :            : 
+     307                 :          0 : exit:
+     308                 :          0 :     mbedtls_md5_free(ctx);
+     309                 :          0 :     return ret;
+     310                 :            : }
+     311                 :            : 
+     312                 :            : #endif /* !MBEDTLS_MD5_ALT */
+     313                 :            : 
+     314                 :            : /*
+     315                 :            :  * output = MD5( input buffer )
+     316                 :            :  */
+     317                 :          0 : int mbedtls_md5(const unsigned char *input,
+     318                 :            :                 size_t ilen,
+     319                 :            :                 unsigned char output[16])
+     320                 :            : {
+     321                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     322                 :            :     mbedtls_md5_context ctx;
+     323                 :            : 
+     324                 :          0 :     mbedtls_md5_init(&ctx);
+     325                 :            : 
+     326         [ #  # ]:          0 :     if ((ret = mbedtls_md5_starts(&ctx)) != 0) {
+     327                 :          0 :         goto exit;
+     328                 :            :     }
+     329                 :            : 
+     330         [ #  # ]:          0 :     if ((ret = mbedtls_md5_update(&ctx, input, ilen)) != 0) {
+     331                 :          0 :         goto exit;
+     332                 :            :     }
+     333                 :            : 
+     334         [ #  # ]:          0 :     if ((ret = mbedtls_md5_finish(&ctx, output)) != 0) {
+     335                 :          0 :         goto exit;
+     336                 :            :     }
+     337                 :            : 
+     338                 :          0 : exit:
+     339                 :          0 :     mbedtls_md5_free(&ctx);
+     340                 :            : 
+     341                 :          0 :     return ret;
+     342                 :            : }
+     343                 :            : 
+     344                 :            : #if defined(MBEDTLS_SELF_TEST)
+     345                 :            : /*
+     346                 :            :  * RFC 1321 test vectors
+     347                 :            :  */
+     348                 :            : static const unsigned char md5_test_buf[7][81] =
+     349                 :            : {
+     350                 :            :     { "" },
+     351                 :            :     { "a" },
+     352                 :            :     { "abc" },
+     353                 :            :     { "message digest" },
+     354                 :            :     { "abcdefghijklmnopqrstuvwxyz" },
+     355                 :            :     { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" },
+     356                 :            :     { "12345678901234567890123456789012345678901234567890123456789012345678901234567890" }
+     357                 :            : };
+     358                 :            : 
+     359                 :            : static const size_t md5_test_buflen[7] =
+     360                 :            : {
+     361                 :            :     0, 1, 3, 14, 26, 62, 80
+     362                 :            : };
+     363                 :            : 
+     364                 :            : static const unsigned char md5_test_sum[7][16] =
+     365                 :            : {
+     366                 :            :     { 0xD4, 0x1D, 0x8C, 0xD9, 0x8F, 0x00, 0xB2, 0x04,
+     367                 :            :       0xE9, 0x80, 0x09, 0x98, 0xEC, 0xF8, 0x42, 0x7E },
+     368                 :            :     { 0x0C, 0xC1, 0x75, 0xB9, 0xC0, 0xF1, 0xB6, 0xA8,
+     369                 :            :       0x31, 0xC3, 0x99, 0xE2, 0x69, 0x77, 0x26, 0x61 },
+     370                 :            :     { 0x90, 0x01, 0x50, 0x98, 0x3C, 0xD2, 0x4F, 0xB0,
+     371                 :            :       0xD6, 0x96, 0x3F, 0x7D, 0x28, 0xE1, 0x7F, 0x72 },
+     372                 :            :     { 0xF9, 0x6B, 0x69, 0x7D, 0x7C, 0xB7, 0x93, 0x8D,
+     373                 :            :       0x52, 0x5A, 0x2F, 0x31, 0xAA, 0xF1, 0x61, 0xD0 },
+     374                 :            :     { 0xC3, 0xFC, 0xD3, 0xD7, 0x61, 0x92, 0xE4, 0x00,
+     375                 :            :       0x7D, 0xFB, 0x49, 0x6C, 0xCA, 0x67, 0xE1, 0x3B },
+     376                 :            :     { 0xD1, 0x74, 0xAB, 0x98, 0xD2, 0x77, 0xD9, 0xF5,
+     377                 :            :       0xA5, 0x61, 0x1C, 0x2C, 0x9F, 0x41, 0x9D, 0x9F },
+     378                 :            :     { 0x57, 0xED, 0xF4, 0xA2, 0x2B, 0xE3, 0xC9, 0x55,
+     379                 :            :       0xAC, 0x49, 0xDA, 0x2E, 0x21, 0x07, 0xB6, 0x7A }
+     380                 :            : };
+     381                 :            : 
+     382                 :            : /*
+     383                 :            :  * Checkup routine
+     384                 :            :  */
+     385                 :          0 : int mbedtls_md5_self_test(int verbose)
+     386                 :            : {
+     387                 :          0 :     int i, ret = 0;
+     388                 :            :     unsigned char md5sum[16];
+     389                 :            : 
+     390         [ #  # ]:          0 :     for (i = 0; i < 7; i++) {
+     391         [ #  # ]:          0 :         if (verbose != 0) {
+     392                 :          0 :             mbedtls_printf("  MD5 test #%d: ", i + 1);
+     393                 :            :         }
+     394                 :            : 
+     395                 :          0 :         ret = mbedtls_md5(md5_test_buf[i], md5_test_buflen[i], md5sum);
+     396         [ #  # ]:          0 :         if (ret != 0) {
+     397                 :          0 :             goto fail;
+     398                 :            :         }
+     399                 :            : 
+     400         [ #  # ]:          0 :         if (memcmp(md5sum, md5_test_sum[i], 16) != 0) {
+     401                 :          0 :             ret = 1;
+     402                 :          0 :             goto fail;
+     403                 :            :         }
+     404                 :            : 
+     405         [ #  # ]:          0 :         if (verbose != 0) {
+     406                 :          0 :             mbedtls_printf("passed\n");
+     407                 :            :         }
+     408                 :            :     }
+     409                 :            : 
+     410         [ #  # ]:          0 :     if (verbose != 0) {
+     411                 :          0 :         mbedtls_printf("\n");
+     412                 :            :     }
+     413                 :            : 
+     414                 :          0 :     return 0;
+     415                 :            : 
+     416                 :          0 : fail:
+     417         [ #  # ]:          0 :     if (verbose != 0) {
+     418                 :          0 :         mbedtls_printf("failed\n");
+     419                 :            :     }
+     420                 :            : 
+     421                 :          0 :     return ret;
+     422                 :            : }
+     423                 :            : 
+     424                 :            : #endif /* MBEDTLS_SELF_TEST */
+     425                 :            : 
+     426                 :            : #endif /* MBEDTLS_MD5_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/oid.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/oid.c.func-sort-c.html new file mode 100644 index 00000000000..be29caaf937 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/oid.c.func-sort-c.html @@ -0,0 +1,213 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/oid.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - oid.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:121667.2 %
Date:2024-09-22 08:21:07Functions:123336.4 %
Branches:4724019.6 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_oid_from_numeric_string0
mbedtls_oid_get_attr_short_name0
mbedtls_oid_get_certificate_policies0
mbedtls_oid_get_cipher_alg0
mbedtls_oid_get_ec_grp_algid0
mbedtls_oid_get_extended_key_usage0
mbedtls_oid_get_md_alg0
mbedtls_oid_get_md_hmac0
mbedtls_oid_get_numeric_string0
mbedtls_oid_get_oid_by_ec_grp_algid0
mbedtls_oid_get_sig_alg_desc0
oid_certificate_policies_from_asn10
oid_cipher_alg_from_asn10
oid_ext_key_usage_from_asn10
oid_grp_id_algid_from_asn10
oid_md_alg_from_asn10
oid_md_hmac_from_asn10
oid_parse_number0
oid_subidentifier_encode_into0
oid_subidentifier_num_bytes0
oid_x520_attr_from_asn10
mbedtls_oid_get_oid_by_sig_alg6
mbedtls_oid_get_oid_by_ec_grp12
mbedtls_oid_get_oid_by_pk_alg12
mbedtls_oid_get_oid_by_md301
mbedtls_oid_get_ec_grp11161
oid_grp_id_from_asn111161
mbedtls_oid_get_sig_alg12125
oid_sig_alg_from_asn112125
mbedtls_oid_get_pk_alg12283
oid_pk_alg_from_asn112283
mbedtls_oid_get_x509_ext_type62692
oid_x509_ext_from_asn162692
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/oid.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/oid.c.func.html new file mode 100644 index 00000000000..71a88249bed --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/oid.c.func.html @@ -0,0 +1,213 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/oid.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - oid.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:121667.2 %
Date:2024-09-22 08:21:07Functions:123336.4 %
Branches:4724019.6 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_oid_from_numeric_string0
mbedtls_oid_get_attr_short_name0
mbedtls_oid_get_certificate_policies0
mbedtls_oid_get_cipher_alg0
mbedtls_oid_get_ec_grp11161
mbedtls_oid_get_ec_grp_algid0
mbedtls_oid_get_extended_key_usage0
mbedtls_oid_get_md_alg0
mbedtls_oid_get_md_hmac0
mbedtls_oid_get_numeric_string0
mbedtls_oid_get_oid_by_ec_grp12
mbedtls_oid_get_oid_by_ec_grp_algid0
mbedtls_oid_get_oid_by_md301
mbedtls_oid_get_oid_by_pk_alg12
mbedtls_oid_get_oid_by_sig_alg6
mbedtls_oid_get_pk_alg12283
mbedtls_oid_get_sig_alg12125
mbedtls_oid_get_sig_alg_desc0
mbedtls_oid_get_x509_ext_type62692
oid_certificate_policies_from_asn10
oid_cipher_alg_from_asn10
oid_ext_key_usage_from_asn10
oid_grp_id_algid_from_asn10
oid_grp_id_from_asn111161
oid_md_alg_from_asn10
oid_md_hmac_from_asn10
oid_parse_number0
oid_pk_alg_from_asn112283
oid_sig_alg_from_asn112125
oid_subidentifier_encode_into0
oid_subidentifier_num_bytes0
oid_x509_ext_from_asn162692
oid_x520_attr_from_asn10
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/oid.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/oid.c.gcov.html new file mode 100644 index 00000000000..0263c772bf8 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/oid.c.gcov.html @@ -0,0 +1,1275 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/oid.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - oid.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:121667.2 %
Date:2024-09-22 08:21:07Functions:123336.4 %
Branches:4724019.6 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  * \file oid.c
+       3                 :            :  *
+       4                 :            :  * \brief Object Identifier (OID) database
+       5                 :            :  *
+       6                 :            :  *  Copyright The Mbed TLS Contributors
+       7                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       8                 :            :  */
+       9                 :            : 
+      10                 :            : #include "common.h"
+      11                 :            : 
+      12                 :            : #if defined(MBEDTLS_OID_C)
+      13                 :            : 
+      14                 :            : #include "mbedtls/oid.h"
+      15                 :            : #include "mbedtls/rsa.h"
+      16                 :            : #include "mbedtls/error.h"
+      17                 :            : #include "mbedtls/pk.h"
+      18                 :            : 
+      19                 :            : #include <stdio.h>
+      20                 :            : #include <string.h>
+      21                 :            : 
+      22                 :            : #include "mbedtls/platform.h"
+      23                 :            : 
+      24                 :            : /*
+      25                 :            :  * Macro to automatically add the size of #define'd OIDs
+      26                 :            :  */
+      27                 :            : #define ADD_LEN(s)      s, MBEDTLS_OID_SIZE(s)
+      28                 :            : 
+      29                 :            : /*
+      30                 :            :  * Macro to generate mbedtls_oid_descriptor_t
+      31                 :            :  */
+      32                 :            : #if !defined(MBEDTLS_X509_REMOVE_INFO)
+      33                 :            : #define OID_DESCRIPTOR(s, name, description)  { ADD_LEN(s), name, description }
+      34                 :            : #define NULL_OID_DESCRIPTOR                   { NULL, 0, NULL, NULL }
+      35                 :            : #else
+      36                 :            : #define OID_DESCRIPTOR(s, name, description)  { ADD_LEN(s) }
+      37                 :            : #define NULL_OID_DESCRIPTOR                   { NULL, 0 }
+      38                 :            : #endif
+      39                 :            : 
+      40                 :            : /*
+      41                 :            :  * Macro to generate an internal function for oid_XXX_from_asn1() (used by
+      42                 :            :  * the other functions)
+      43                 :            :  */
+      44                 :            : #define FN_OID_TYPED_FROM_ASN1(TYPE_T, NAME, LIST)                    \
+      45                 :            :     static const TYPE_T *oid_ ## NAME ## _from_asn1(                   \
+      46                 :            :         const mbedtls_asn1_buf *oid)     \
+      47                 :            :     {                                                                   \
+      48                 :            :         const TYPE_T *p = (LIST);                                       \
+      49                 :            :         const mbedtls_oid_descriptor_t *cur =                           \
+      50                 :            :             (const mbedtls_oid_descriptor_t *) p;                       \
+      51                 :            :         if (p == NULL || oid == NULL) return NULL;                  \
+      52                 :            :         while (cur->asn1 != NULL) {                                    \
+      53                 :            :             if (cur->asn1_len == oid->len &&                            \
+      54                 :            :                 memcmp(cur->asn1, oid->p, oid->len) == 0) {          \
+      55                 :            :                 return p;                                            \
+      56                 :            :             }                                                           \
+      57                 :            :             p++;                                                        \
+      58                 :            :             cur = (const mbedtls_oid_descriptor_t *) p;                 \
+      59                 :            :         }                                                               \
+      60                 :            :         return NULL;                                                 \
+      61                 :            :     }
+      62                 :            : 
+      63                 :            : #if !defined(MBEDTLS_X509_REMOVE_INFO)
+      64                 :            : /*
+      65                 :            :  * Macro to generate a function for retrieving a single attribute from the
+      66                 :            :  * descriptor of an mbedtls_oid_descriptor_t wrapper.
+      67                 :            :  */
+      68                 :            : #define FN_OID_GET_DESCRIPTOR_ATTR1(FN_NAME, TYPE_T, TYPE_NAME, ATTR1_TYPE, ATTR1) \
+      69                 :            :     int FN_NAME(const mbedtls_asn1_buf *oid, ATTR1_TYPE * ATTR1)                  \
+      70                 :            :     {                                                                       \
+      71                 :            :         const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1(oid);        \
+      72                 :            :         if (data == NULL) return MBEDTLS_ERR_OID_NOT_FOUND;            \
+      73                 :            :         *ATTR1 = data->descriptor.ATTR1;                                    \
+      74                 :            :         return 0;                                                        \
+      75                 :            :     }
+      76                 :            : #endif /* MBEDTLS_X509_REMOVE_INFO */
+      77                 :            : 
+      78                 :            : /*
+      79                 :            :  * Macro to generate a function for retrieving a single attribute from an
+      80                 :            :  * mbedtls_oid_descriptor_t wrapper.
+      81                 :            :  */
+      82                 :            : #define FN_OID_GET_ATTR1(FN_NAME, TYPE_T, TYPE_NAME, ATTR1_TYPE, ATTR1) \
+      83                 :            :     int FN_NAME(const mbedtls_asn1_buf *oid, ATTR1_TYPE * ATTR1)                  \
+      84                 :            :     {                                                                       \
+      85                 :            :         const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1(oid);        \
+      86                 :            :         if (data == NULL) return MBEDTLS_ERR_OID_NOT_FOUND;            \
+      87                 :            :         *ATTR1 = data->ATTR1;                                               \
+      88                 :            :         return 0;                                                        \
+      89                 :            :     }
+      90                 :            : 
+      91                 :            : /*
+      92                 :            :  * Macro to generate a function for retrieving two attributes from an
+      93                 :            :  * mbedtls_oid_descriptor_t wrapper.
+      94                 :            :  */
+      95                 :            : #define FN_OID_GET_ATTR2(FN_NAME, TYPE_T, TYPE_NAME, ATTR1_TYPE, ATTR1,     \
+      96                 :            :                          ATTR2_TYPE, ATTR2)                                 \
+      97                 :            :     int FN_NAME(const mbedtls_asn1_buf *oid, ATTR1_TYPE * ATTR1,               \
+      98                 :            :                 ATTR2_TYPE * ATTR2)              \
+      99                 :            :     {                                                                           \
+     100                 :            :         const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1(oid);            \
+     101                 :            :         if (data == NULL) return MBEDTLS_ERR_OID_NOT_FOUND;                 \
+     102                 :            :         *(ATTR1) = data->ATTR1;                                                 \
+     103                 :            :         *(ATTR2) = data->ATTR2;                                                 \
+     104                 :            :         return 0;                                                            \
+     105                 :            :     }
+     106                 :            : 
+     107                 :            : /*
+     108                 :            :  * Macro to generate a function for retrieving the OID based on a single
+     109                 :            :  * attribute from a mbedtls_oid_descriptor_t wrapper.
+     110                 :            :  */
+     111                 :            : #define FN_OID_GET_OID_BY_ATTR1(FN_NAME, TYPE_T, LIST, ATTR1_TYPE, ATTR1)   \
+     112                 :            :     int FN_NAME(ATTR1_TYPE ATTR1, const char **oid, size_t *olen)             \
+     113                 :            :     {                                                                           \
+     114                 :            :         const TYPE_T *cur = (LIST);                                             \
+     115                 :            :         while (cur->descriptor.asn1 != NULL) {                                 \
+     116                 :            :             if (cur->ATTR1 == (ATTR1)) {                                       \
+     117                 :            :                 *oid = cur->descriptor.asn1;                                    \
+     118                 :            :                 *olen = cur->descriptor.asn1_len;                               \
+     119                 :            :                 return 0;                                                    \
+     120                 :            :             }                                                                   \
+     121                 :            :             cur++;                                                              \
+     122                 :            :         }                                                                       \
+     123                 :            :         return MBEDTLS_ERR_OID_NOT_FOUND;                                    \
+     124                 :            :     }
+     125                 :            : 
+     126                 :            : /*
+     127                 :            :  * Macro to generate a function for retrieving the OID based on two
+     128                 :            :  * attributes from a mbedtls_oid_descriptor_t wrapper.
+     129                 :            :  */
+     130                 :            : #define FN_OID_GET_OID_BY_ATTR2(FN_NAME, TYPE_T, LIST, ATTR1_TYPE, ATTR1,   \
+     131                 :            :                                 ATTR2_TYPE, ATTR2)                          \
+     132                 :            :     int FN_NAME(ATTR1_TYPE ATTR1, ATTR2_TYPE ATTR2, const char **oid,         \
+     133                 :            :                 size_t *olen)                                                 \
+     134                 :            :     {                                                                           \
+     135                 :            :         const TYPE_T *cur = (LIST);                                             \
+     136                 :            :         while (cur->descriptor.asn1 != NULL) {                                 \
+     137                 :            :             if (cur->ATTR1 == (ATTR1) && cur->ATTR2 == (ATTR2)) {              \
+     138                 :            :                 *oid = cur->descriptor.asn1;                                    \
+     139                 :            :                 *olen = cur->descriptor.asn1_len;                               \
+     140                 :            :                 return 0;                                                    \
+     141                 :            :             }                                                                   \
+     142                 :            :             cur++;                                                              \
+     143                 :            :         }                                                                       \
+     144                 :            :         return MBEDTLS_ERR_OID_NOT_FOUND;                                   \
+     145                 :            :     }
+     146                 :            : 
+     147                 :            : /*
+     148                 :            :  * For X520 attribute types
+     149                 :            :  */
+     150                 :            : typedef struct {
+     151                 :            :     mbedtls_oid_descriptor_t    descriptor;
+     152                 :            :     const char          *short_name;
+     153                 :            : } oid_x520_attr_t;
+     154                 :            : 
+     155                 :            : static const oid_x520_attr_t oid_x520_attr_type[] =
+     156                 :            : {
+     157                 :            :     {
+     158                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_AT_CN,          "id-at-commonName",               "Common Name"),
+     159                 :            :         "CN",
+     160                 :            :     },
+     161                 :            :     {
+     162                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_AT_COUNTRY,     "id-at-countryName",              "Country"),
+     163                 :            :         "C",
+     164                 :            :     },
+     165                 :            :     {
+     166                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_AT_LOCALITY,    "id-at-locality",                 "Locality"),
+     167                 :            :         "L",
+     168                 :            :     },
+     169                 :            :     {
+     170                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_AT_STATE,       "id-at-state",                    "State"),
+     171                 :            :         "ST",
+     172                 :            :     },
+     173                 :            :     {
+     174                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_AT_ORGANIZATION, "id-at-organizationName",
+     175                 :            :                        "Organization"),
+     176                 :            :         "O",
+     177                 :            :     },
+     178                 :            :     {
+     179                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_AT_ORG_UNIT,    "id-at-organizationalUnitName",   "Org Unit"),
+     180                 :            :         "OU",
+     181                 :            :     },
+     182                 :            :     {
+     183                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_PKCS9_EMAIL,
+     184                 :            :                        "emailAddress",
+     185                 :            :                        "E-mail address"),
+     186                 :            :         "emailAddress",
+     187                 :            :     },
+     188                 :            :     {
+     189                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_AT_SERIAL_NUMBER,
+     190                 :            :                        "id-at-serialNumber",
+     191                 :            :                        "Serial number"),
+     192                 :            :         "serialNumber",
+     193                 :            :     },
+     194                 :            :     {
+     195                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_AT_POSTAL_ADDRESS,
+     196                 :            :                        "id-at-postalAddress",
+     197                 :            :                        "Postal address"),
+     198                 :            :         "postalAddress",
+     199                 :            :     },
+     200                 :            :     {
+     201                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_AT_POSTAL_CODE, "id-at-postalCode",               "Postal code"),
+     202                 :            :         "postalCode",
+     203                 :            :     },
+     204                 :            :     {
+     205                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_AT_SUR_NAME,    "id-at-surName",                  "Surname"),
+     206                 :            :         "SN",
+     207                 :            :     },
+     208                 :            :     {
+     209                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_AT_GIVEN_NAME,  "id-at-givenName",                "Given name"),
+     210                 :            :         "GN",
+     211                 :            :     },
+     212                 :            :     {
+     213                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_AT_INITIALS,    "id-at-initials",                 "Initials"),
+     214                 :            :         "initials",
+     215                 :            :     },
+     216                 :            :     {
+     217                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_AT_GENERATION_QUALIFIER,
+     218                 :            :                        "id-at-generationQualifier",
+     219                 :            :                        "Generation qualifier"),
+     220                 :            :         "generationQualifier",
+     221                 :            :     },
+     222                 :            :     {
+     223                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_AT_TITLE,       "id-at-title",                    "Title"),
+     224                 :            :         "title",
+     225                 :            :     },
+     226                 :            :     {
+     227                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_AT_DN_QUALIFIER,
+     228                 :            :                        "id-at-dnQualifier",
+     229                 :            :                        "Distinguished Name qualifier"),
+     230                 :            :         "dnQualifier",
+     231                 :            :     },
+     232                 :            :     {
+     233                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_AT_PSEUDONYM,   "id-at-pseudonym",                "Pseudonym"),
+     234                 :            :         "pseudonym",
+     235                 :            :     },
+     236                 :            :     {
+     237                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_UID,            "id-uid",                         "User Id"),
+     238                 :            :         "uid",
+     239                 :            :     },
+     240                 :            :     {
+     241                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_DOMAIN_COMPONENT,
+     242                 :            :                        "id-domainComponent",
+     243                 :            :                        "Domain component"),
+     244                 :            :         "DC",
+     245                 :            :     },
+     246                 :            :     {
+     247                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_AT_UNIQUE_IDENTIFIER,
+     248                 :            :                        "id-at-uniqueIdentifier",
+     249                 :            :                        "Unique Identifier"),
+     250                 :            :         "uniqueIdentifier",
+     251                 :            :     },
+     252                 :            :     {
+     253                 :            :         NULL_OID_DESCRIPTOR,
+     254                 :            :         NULL,
+     255                 :            :     }
+     256                 :            : };
+     257                 :            : 
+     258   [ #  #  #  #  :          0 : FN_OID_TYPED_FROM_ASN1(oid_x520_attr_t, x520_attr, oid_x520_attr_type)
+          #  #  #  #  #  
+                      # ]
+     259         [ #  # ]:          0 : FN_OID_GET_ATTR1(mbedtls_oid_get_attr_short_name,
+     260                 :            :                  oid_x520_attr_t,
+     261                 :            :                  x520_attr,
+     262                 :            :                  const char *,
+     263                 :            :                  short_name)
+     264                 :            : 
+     265                 :            : /*
+     266                 :            :  * For X509 extensions
+     267                 :            :  */
+     268                 :            : typedef struct {
+     269                 :            :     mbedtls_oid_descriptor_t    descriptor;
+     270                 :            :     int                 ext_type;
+     271                 :            : } oid_x509_ext_t;
+     272                 :            : 
+     273                 :            : static const oid_x509_ext_t oid_x509_ext[] =
+     274                 :            : {
+     275                 :            :     {
+     276                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_BASIC_CONSTRAINTS,
+     277                 :            :                        "id-ce-basicConstraints",
+     278                 :            :                        "Basic Constraints"),
+     279                 :            :         MBEDTLS_OID_X509_EXT_BASIC_CONSTRAINTS,
+     280                 :            :     },
+     281                 :            :     {
+     282                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_KEY_USAGE,            "id-ce-keyUsage",            "Key Usage"),
+     283                 :            :         MBEDTLS_OID_X509_EXT_KEY_USAGE,
+     284                 :            :     },
+     285                 :            :     {
+     286                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_EXTENDED_KEY_USAGE,
+     287                 :            :                        "id-ce-extKeyUsage",
+     288                 :            :                        "Extended Key Usage"),
+     289                 :            :         MBEDTLS_OID_X509_EXT_EXTENDED_KEY_USAGE,
+     290                 :            :     },
+     291                 :            :     {
+     292                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_SUBJECT_ALT_NAME,
+     293                 :            :                        "id-ce-subjectAltName",
+     294                 :            :                        "Subject Alt Name"),
+     295                 :            :         MBEDTLS_OID_X509_EXT_SUBJECT_ALT_NAME,
+     296                 :            :     },
+     297                 :            :     {
+     298                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_NS_CERT_TYPE,
+     299                 :            :                        "id-netscape-certtype",
+     300                 :            :                        "Netscape Certificate Type"),
+     301                 :            :         MBEDTLS_OID_X509_EXT_NS_CERT_TYPE,
+     302                 :            :     },
+     303                 :            :     {
+     304                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_CERTIFICATE_POLICIES,
+     305                 :            :                        "id-ce-certificatePolicies",
+     306                 :            :                        "Certificate Policies"),
+     307                 :            :         MBEDTLS_OID_X509_EXT_CERTIFICATE_POLICIES,
+     308                 :            :     },
+     309                 :            :     {
+     310                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_SUBJECT_KEY_IDENTIFIER,
+     311                 :            :                        "id-ce-subjectKeyIdentifier",
+     312                 :            :                        "Subject Key Identifier"),
+     313                 :            :         MBEDTLS_OID_X509_EXT_SUBJECT_KEY_IDENTIFIER,
+     314                 :            :     },
+     315                 :            :     {
+     316                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_AUTHORITY_KEY_IDENTIFIER,
+     317                 :            :                        "id-ce-authorityKeyIdentifier",
+     318                 :            :                        "Authority Key Identifier"),
+     319                 :            :         MBEDTLS_OID_X509_EXT_AUTHORITY_KEY_IDENTIFIER,
+     320                 :            :     },
+     321                 :            :     {
+     322                 :            :         NULL_OID_DESCRIPTOR,
+     323                 :            :         0,
+     324                 :            :     },
+     325                 :            : };
+     326                 :            : 
+     327   [ +  -  -  +  :     270388 : FN_OID_TYPED_FROM_ASN1(oid_x509_ext_t, x509_ext, oid_x509_ext)
+          +  +  +  +  +  
+                      + ]
+     328         [ +  + ]:      62692 : FN_OID_GET_ATTR1(mbedtls_oid_get_x509_ext_type, oid_x509_ext_t, x509_ext, int, ext_type)
+     329                 :            : 
+     330                 :            : #if !defined(MBEDTLS_X509_REMOVE_INFO)
+     331                 :            : static const mbedtls_oid_descriptor_t oid_ext_key_usage[] =
+     332                 :            : {
+     333                 :            :     OID_DESCRIPTOR(MBEDTLS_OID_SERVER_AUTH,
+     334                 :            :                    "id-kp-serverAuth",
+     335                 :            :                    "TLS Web Server Authentication"),
+     336                 :            :     OID_DESCRIPTOR(MBEDTLS_OID_CLIENT_AUTH,
+     337                 :            :                    "id-kp-clientAuth",
+     338                 :            :                    "TLS Web Client Authentication"),
+     339                 :            :     OID_DESCRIPTOR(MBEDTLS_OID_CODE_SIGNING,     "id-kp-codeSigning",     "Code Signing"),
+     340                 :            :     OID_DESCRIPTOR(MBEDTLS_OID_EMAIL_PROTECTION, "id-kp-emailProtection", "E-mail Protection"),
+     341                 :            :     OID_DESCRIPTOR(MBEDTLS_OID_TIME_STAMPING,    "id-kp-timeStamping",    "Time Stamping"),
+     342                 :            :     OID_DESCRIPTOR(MBEDTLS_OID_OCSP_SIGNING,     "id-kp-OCSPSigning",     "OCSP Signing"),
+     343                 :            :     OID_DESCRIPTOR(MBEDTLS_OID_WISUN_FAN,
+     344                 :            :                    "id-kp-wisun-fan-device",
+     345                 :            :                    "Wi-SUN Alliance Field Area Network (FAN)"),
+     346                 :            :     NULL_OID_DESCRIPTOR,
+     347                 :            : };
+     348                 :            : 
+     349   [ #  #  #  #  :          0 : FN_OID_TYPED_FROM_ASN1(mbedtls_oid_descriptor_t, ext_key_usage, oid_ext_key_usage)
+          #  #  #  #  #  
+                      # ]
+     350         [ #  # ]:          0 : FN_OID_GET_ATTR1(mbedtls_oid_get_extended_key_usage,
+     351                 :            :                  mbedtls_oid_descriptor_t,
+     352                 :            :                  ext_key_usage,
+     353                 :            :                  const char *,
+     354                 :            :                  description)
+     355                 :            : 
+     356                 :            : static const mbedtls_oid_descriptor_t oid_certificate_policies[] =
+     357                 :            : {
+     358                 :            :     OID_DESCRIPTOR(MBEDTLS_OID_ANY_POLICY,      "anyPolicy",       "Any Policy"),
+     359                 :            :     NULL_OID_DESCRIPTOR,
+     360                 :            : };
+     361                 :            : 
+     362   [ #  #  #  #  :          0 : FN_OID_TYPED_FROM_ASN1(mbedtls_oid_descriptor_t, certificate_policies, oid_certificate_policies)
+          #  #  #  #  #  
+                      # ]
+     363         [ #  # ]:          0 : FN_OID_GET_ATTR1(mbedtls_oid_get_certificate_policies,
+     364                 :            :                  mbedtls_oid_descriptor_t,
+     365                 :            :                  certificate_policies,
+     366                 :            :                  const char *,
+     367                 :            :                  description)
+     368                 :            : #endif /* MBEDTLS_X509_REMOVE_INFO */
+     369                 :            : 
+     370                 :            : /*
+     371                 :            :  * For SignatureAlgorithmIdentifier
+     372                 :            :  */
+     373                 :            : typedef struct {
+     374                 :            :     mbedtls_oid_descriptor_t    descriptor;
+     375                 :            :     mbedtls_md_type_t           md_alg;
+     376                 :            :     mbedtls_pk_type_t           pk_alg;
+     377                 :            : } oid_sig_alg_t;
+     378                 :            : 
+     379                 :            : static const oid_sig_alg_t oid_sig_alg[] =
+     380                 :            : {
+     381                 :            : #if defined(MBEDTLS_RSA_C)
+     382                 :            : #if defined(MBEDTLS_MD_CAN_MD5)
+     383                 :            :     {
+     384                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_PKCS1_MD5,        "md5WithRSAEncryption",     "RSA with MD5"),
+     385                 :            :         MBEDTLS_MD_MD5,      MBEDTLS_PK_RSA,
+     386                 :            :     },
+     387                 :            : #endif /* MBEDTLS_MD_CAN_MD5 */
+     388                 :            : #if defined(MBEDTLS_MD_CAN_SHA1)
+     389                 :            :     {
+     390                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_PKCS1_SHA1,       "sha-1WithRSAEncryption",   "RSA with SHA1"),
+     391                 :            :         MBEDTLS_MD_SHA1,     MBEDTLS_PK_RSA,
+     392                 :            :     },
+     393                 :            : #endif /* MBEDTLS_MD_CAN_SHA1 */
+     394                 :            : #if defined(MBEDTLS_MD_CAN_SHA224)
+     395                 :            :     {
+     396                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_PKCS1_SHA224,     "sha224WithRSAEncryption",
+     397                 :            :                        "RSA with SHA-224"),
+     398                 :            :         MBEDTLS_MD_SHA224,   MBEDTLS_PK_RSA,
+     399                 :            :     },
+     400                 :            : #endif /* MBEDTLS_MD_CAN_SHA224 */
+     401                 :            : #if defined(MBEDTLS_MD_CAN_SHA256)
+     402                 :            :     {
+     403                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_PKCS1_SHA256,     "sha256WithRSAEncryption",
+     404                 :            :                        "RSA with SHA-256"),
+     405                 :            :         MBEDTLS_MD_SHA256,   MBEDTLS_PK_RSA,
+     406                 :            :     },
+     407                 :            : #endif /* MBEDTLS_MD_CAN_SHA256 */
+     408                 :            : #if defined(MBEDTLS_MD_CAN_SHA384)
+     409                 :            :     {
+     410                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_PKCS1_SHA384,     "sha384WithRSAEncryption",
+     411                 :            :                        "RSA with SHA-384"),
+     412                 :            :         MBEDTLS_MD_SHA384,   MBEDTLS_PK_RSA,
+     413                 :            :     },
+     414                 :            : #endif /* MBEDTLS_MD_CAN_SHA384 */
+     415                 :            : #if defined(MBEDTLS_MD_CAN_SHA512)
+     416                 :            :     {
+     417                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_PKCS1_SHA512,     "sha512WithRSAEncryption",
+     418                 :            :                        "RSA with SHA-512"),
+     419                 :            :         MBEDTLS_MD_SHA512,   MBEDTLS_PK_RSA,
+     420                 :            :     },
+     421                 :            : #endif /* MBEDTLS_MD_CAN_SHA512 */
+     422                 :            : #if defined(MBEDTLS_MD_CAN_SHA1)
+     423                 :            :     {
+     424                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_RSA_SHA_OBS,      "sha-1WithRSAEncryption",   "RSA with SHA1"),
+     425                 :            :         MBEDTLS_MD_SHA1,     MBEDTLS_PK_RSA,
+     426                 :            :     },
+     427                 :            : #endif /* MBEDTLS_MD_CAN_SHA1 */
+     428                 :            : #endif /* MBEDTLS_RSA_C */
+     429                 :            : #if defined(MBEDTLS_PK_CAN_ECDSA_SOME)
+     430                 :            : #if defined(MBEDTLS_MD_CAN_SHA1)
+     431                 :            :     {
+     432                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_ECDSA_SHA1,       "ecdsa-with-SHA1",      "ECDSA with SHA1"),
+     433                 :            :         MBEDTLS_MD_SHA1,     MBEDTLS_PK_ECDSA,
+     434                 :            :     },
+     435                 :            : #endif /* MBEDTLS_MD_CAN_SHA1 */
+     436                 :            : #if defined(MBEDTLS_MD_CAN_SHA224)
+     437                 :            :     {
+     438                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_ECDSA_SHA224,     "ecdsa-with-SHA224",    "ECDSA with SHA224"),
+     439                 :            :         MBEDTLS_MD_SHA224,   MBEDTLS_PK_ECDSA,
+     440                 :            :     },
+     441                 :            : #endif
+     442                 :            : #if defined(MBEDTLS_MD_CAN_SHA256)
+     443                 :            :     {
+     444                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_ECDSA_SHA256,     "ecdsa-with-SHA256",    "ECDSA with SHA256"),
+     445                 :            :         MBEDTLS_MD_SHA256,   MBEDTLS_PK_ECDSA,
+     446                 :            :     },
+     447                 :            : #endif /* MBEDTLS_MD_CAN_SHA256 */
+     448                 :            : #if defined(MBEDTLS_MD_CAN_SHA384)
+     449                 :            :     {
+     450                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_ECDSA_SHA384,     "ecdsa-with-SHA384",    "ECDSA with SHA384"),
+     451                 :            :         MBEDTLS_MD_SHA384,   MBEDTLS_PK_ECDSA,
+     452                 :            :     },
+     453                 :            : #endif /* MBEDTLS_MD_CAN_SHA384 */
+     454                 :            : #if defined(MBEDTLS_MD_CAN_SHA512)
+     455                 :            :     {
+     456                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_ECDSA_SHA512,     "ecdsa-with-SHA512",    "ECDSA with SHA512"),
+     457                 :            :         MBEDTLS_MD_SHA512,   MBEDTLS_PK_ECDSA,
+     458                 :            :     },
+     459                 :            : #endif /* MBEDTLS_MD_CAN_SHA512 */
+     460                 :            : #endif /* MBEDTLS_PK_CAN_ECDSA_SOME */
+     461                 :            : #if defined(MBEDTLS_RSA_C)
+     462                 :            :     {
+     463                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_RSASSA_PSS,        "RSASSA-PSS",           "RSASSA-PSS"),
+     464                 :            :         MBEDTLS_MD_NONE,     MBEDTLS_PK_RSASSA_PSS,
+     465                 :            :     },
+     466                 :            : #endif /* MBEDTLS_RSA_C */
+     467                 :            :     {
+     468                 :            :         NULL_OID_DESCRIPTOR,
+     469                 :            :         MBEDTLS_MD_NONE, MBEDTLS_PK_NONE,
+     470                 :            :     },
+     471                 :            : };
+     472                 :            : 
+     473   [ +  -  -  +  :     114894 : FN_OID_TYPED_FROM_ASN1(oid_sig_alg_t, sig_alg, oid_sig_alg)
+          +  +  +  +  +  
+                      - ]
+     474                 :            : 
+     475                 :            : #if !defined(MBEDTLS_X509_REMOVE_INFO)
+     476         [ #  # ]:          0 : FN_OID_GET_DESCRIPTOR_ATTR1(mbedtls_oid_get_sig_alg_desc,
+     477                 :            :                             oid_sig_alg_t,
+     478                 :            :                             sig_alg,
+     479                 :            :                             const char *,
+     480                 :            :                             description)
+     481                 :            : #endif
+     482                 :            : 
+     483         [ -  + ]:      12125 : FN_OID_GET_ATTR2(mbedtls_oid_get_sig_alg,
+     484                 :            :                  oid_sig_alg_t,
+     485                 :            :                  sig_alg,
+     486                 :            :                  mbedtls_md_type_t,
+     487                 :            :                  md_alg,
+     488                 :            :                  mbedtls_pk_type_t,
+     489                 :            :                  pk_alg)
+     490   [ +  +  +  +  :         60 : FN_OID_GET_OID_BY_ATTR2(mbedtls_oid_get_oid_by_sig_alg,
+                   +  - ]
+     491                 :            :                         oid_sig_alg_t,
+     492                 :            :                         oid_sig_alg,
+     493                 :            :                         mbedtls_pk_type_t,
+     494                 :            :                         pk_alg,
+     495                 :            :                         mbedtls_md_type_t,
+     496                 :            :                         md_alg)
+     497                 :            : 
+     498                 :            : /*
+     499                 :            :  * For PublicKeyInfo (PKCS1, RFC 5480)
+     500                 :            :  */
+     501                 :            : typedef struct {
+     502                 :            :     mbedtls_oid_descriptor_t    descriptor;
+     503                 :            :     mbedtls_pk_type_t           pk_alg;
+     504                 :            : } oid_pk_alg_t;
+     505                 :            : 
+     506                 :            : static const oid_pk_alg_t oid_pk_alg[] =
+     507                 :            : {
+     508                 :            :     {
+     509                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_PKCS1_RSA,           "rsaEncryption",    "RSA"),
+     510                 :            :         MBEDTLS_PK_RSA,
+     511                 :            :     },
+     512                 :            :     {
+     513                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_EC_ALG_UNRESTRICTED, "id-ecPublicKey",   "Generic EC key"),
+     514                 :            :         MBEDTLS_PK_ECKEY,
+     515                 :            :     },
+     516                 :            :     {
+     517                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_EC_ALG_ECDH,         "id-ecDH",          "EC key for ECDH"),
+     518                 :            :         MBEDTLS_PK_ECKEY_DH,
+     519                 :            :     },
+     520                 :            :     {
+     521                 :            :         NULL_OID_DESCRIPTOR,
+     522                 :            :         MBEDTLS_PK_NONE,
+     523                 :            :     },
+     524                 :            : };
+     525                 :            : 
+     526   [ +  -  -  +  :      23444 : FN_OID_TYPED_FROM_ASN1(oid_pk_alg_t, pk_alg, oid_pk_alg)
+          +  +  +  -  +  
+                      - ]
+     527         [ -  + ]:      12283 : FN_OID_GET_ATTR1(mbedtls_oid_get_pk_alg, oid_pk_alg_t, pk_alg, mbedtls_pk_type_t, pk_alg)
+     528   [ +  +  +  - ]:         24 : FN_OID_GET_OID_BY_ATTR1(mbedtls_oid_get_oid_by_pk_alg,
+     529                 :            :                         oid_pk_alg_t,
+     530                 :            :                         oid_pk_alg,
+     531                 :            :                         mbedtls_pk_type_t,
+     532                 :            :                         pk_alg)
+     533                 :            : 
+     534                 :            : #if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
+     535                 :            : /*
+     536                 :            :  * For elliptic curves that use namedCurve inside ECParams (RFC 5480)
+     537                 :            :  */
+     538                 :            : typedef struct {
+     539                 :            :     mbedtls_oid_descriptor_t    descriptor;
+     540                 :            :     mbedtls_ecp_group_id        grp_id;
+     541                 :            : } oid_ecp_grp_t;
+     542                 :            : 
+     543                 :            : static const oid_ecp_grp_t oid_ecp_grp[] =
+     544                 :            : {
+     545                 :            : #if defined(MBEDTLS_ECP_HAVE_SECP192R1)
+     546                 :            :     {
+     547                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_EC_GRP_SECP192R1, "secp192r1",    "secp192r1"),
+     548                 :            :         MBEDTLS_ECP_DP_SECP192R1,
+     549                 :            :     },
+     550                 :            : #endif /* MBEDTLS_ECP_HAVE_SECP192R1 */
+     551                 :            : #if defined(MBEDTLS_ECP_HAVE_SECP224R1)
+     552                 :            :     {
+     553                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_EC_GRP_SECP224R1, "secp224r1",    "secp224r1"),
+     554                 :            :         MBEDTLS_ECP_DP_SECP224R1,
+     555                 :            :     },
+     556                 :            : #endif /* MBEDTLS_ECP_HAVE_SECP224R1 */
+     557                 :            : #if defined(MBEDTLS_ECP_HAVE_SECP256R1)
+     558                 :            :     {
+     559                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_EC_GRP_SECP256R1, "secp256r1",    "secp256r1"),
+     560                 :            :         MBEDTLS_ECP_DP_SECP256R1,
+     561                 :            :     },
+     562                 :            : #endif /* MBEDTLS_ECP_HAVE_SECP256R1 */
+     563                 :            : #if defined(MBEDTLS_ECP_HAVE_SECP384R1)
+     564                 :            :     {
+     565                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_EC_GRP_SECP384R1, "secp384r1",    "secp384r1"),
+     566                 :            :         MBEDTLS_ECP_DP_SECP384R1,
+     567                 :            :     },
+     568                 :            : #endif /* MBEDTLS_ECP_HAVE_SECP384R1 */
+     569                 :            : #if defined(MBEDTLS_ECP_HAVE_SECP521R1)
+     570                 :            :     {
+     571                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_EC_GRP_SECP521R1, "secp521r1",    "secp521r1"),
+     572                 :            :         MBEDTLS_ECP_DP_SECP521R1,
+     573                 :            :     },
+     574                 :            : #endif /* MBEDTLS_ECP_HAVE_SECP521R1 */
+     575                 :            : #if defined(MBEDTLS_ECP_HAVE_SECP192K1)
+     576                 :            :     {
+     577                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_EC_GRP_SECP192K1, "secp192k1",    "secp192k1"),
+     578                 :            :         MBEDTLS_ECP_DP_SECP192K1,
+     579                 :            :     },
+     580                 :            : #endif /* MBEDTLS_ECP_HAVE_SECP192K1 */
+     581                 :            : #if defined(MBEDTLS_ECP_HAVE_SECP224K1)
+     582                 :            :     {
+     583                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_EC_GRP_SECP224K1, "secp224k1",    "secp224k1"),
+     584                 :            :         MBEDTLS_ECP_DP_SECP224K1,
+     585                 :            :     },
+     586                 :            : #endif /* MBEDTLS_ECP_HAVE_SECP224K1 */
+     587                 :            : #if defined(MBEDTLS_ECP_HAVE_SECP256K1)
+     588                 :            :     {
+     589                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_EC_GRP_SECP256K1, "secp256k1",    "secp256k1"),
+     590                 :            :         MBEDTLS_ECP_DP_SECP256K1,
+     591                 :            :     },
+     592                 :            : #endif /* MBEDTLS_ECP_HAVE_SECP256K1 */
+     593                 :            : #if defined(MBEDTLS_ECP_HAVE_BP256R1)
+     594                 :            :     {
+     595                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_EC_GRP_BP256R1,   "brainpoolP256r1", "brainpool256r1"),
+     596                 :            :         MBEDTLS_ECP_DP_BP256R1,
+     597                 :            :     },
+     598                 :            : #endif /* MBEDTLS_ECP_HAVE_BP256R1 */
+     599                 :            : #if defined(MBEDTLS_ECP_HAVE_BP384R1)
+     600                 :            :     {
+     601                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_EC_GRP_BP384R1,   "brainpoolP384r1", "brainpool384r1"),
+     602                 :            :         MBEDTLS_ECP_DP_BP384R1,
+     603                 :            :     },
+     604                 :            : #endif /* MBEDTLS_ECP_HAVE_BP384R1 */
+     605                 :            : #if defined(MBEDTLS_ECP_HAVE_BP512R1)
+     606                 :            :     {
+     607                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_EC_GRP_BP512R1,   "brainpoolP512r1", "brainpool512r1"),
+     608                 :            :         MBEDTLS_ECP_DP_BP512R1,
+     609                 :            :     },
+     610                 :            : #endif /* MBEDTLS_ECP_HAVE_BP512R1 */
+     611                 :            :     {
+     612                 :            :         NULL_OID_DESCRIPTOR,
+     613                 :            :         MBEDTLS_ECP_DP_NONE,
+     614                 :            :     },
+     615                 :            : };
+     616                 :            : 
+     617   [ +  -  -  +  :      33519 : FN_OID_TYPED_FROM_ASN1(oid_ecp_grp_t, grp_id, oid_ecp_grp)
+          +  +  +  +  +  
+                      - ]
+     618         [ -  + ]:      11161 : FN_OID_GET_ATTR1(mbedtls_oid_get_ec_grp, oid_ecp_grp_t, grp_id, mbedtls_ecp_group_id, grp_id)
+     619   [ +  +  +  - ]:         36 : FN_OID_GET_OID_BY_ATTR1(mbedtls_oid_get_oid_by_ec_grp,
+     620                 :            :                         oid_ecp_grp_t,
+     621                 :            :                         oid_ecp_grp,
+     622                 :            :                         mbedtls_ecp_group_id,
+     623                 :            :                         grp_id)
+     624                 :            : 
+     625                 :            : /*
+     626                 :            :  * For Elliptic Curve algorithms that are directly
+     627                 :            :  * encoded in the AlgorithmIdentifier (RFC 8410)
+     628                 :            :  */
+     629                 :            : typedef struct {
+     630                 :            :     mbedtls_oid_descriptor_t    descriptor;
+     631                 :            :     mbedtls_ecp_group_id        grp_id;
+     632                 :            : } oid_ecp_grp_algid_t;
+     633                 :            : 
+     634                 :            : static const oid_ecp_grp_algid_t oid_ecp_grp_algid[] =
+     635                 :            : {
+     636                 :            : #if defined(MBEDTLS_ECP_HAVE_CURVE25519)
+     637                 :            :     {
+     638                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_X25519,               "X25519",       "X25519"),
+     639                 :            :         MBEDTLS_ECP_DP_CURVE25519,
+     640                 :            :     },
+     641                 :            : #endif /* MBEDTLS_ECP_HAVE_CURVE25519 */
+     642                 :            : #if defined(MBEDTLS_ECP_HAVE_CURVE448)
+     643                 :            :     {
+     644                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_X448,                 "X448",         "X448"),
+     645                 :            :         MBEDTLS_ECP_DP_CURVE448,
+     646                 :            :     },
+     647                 :            : #endif /* MBEDTLS_ECP_HAVE_CURVE448 */
+     648                 :            :     {
+     649                 :            :         NULL_OID_DESCRIPTOR,
+     650                 :            :         MBEDTLS_ECP_DP_NONE,
+     651                 :            :     },
+     652                 :            : };
+     653                 :            : 
+     654   [ #  #  #  #  :          0 : FN_OID_TYPED_FROM_ASN1(oid_ecp_grp_algid_t, grp_id_algid, oid_ecp_grp_algid)
+          #  #  #  #  #  
+                      # ]
+     655         [ #  # ]:          0 : FN_OID_GET_ATTR1(mbedtls_oid_get_ec_grp_algid,
+     656                 :            :                  oid_ecp_grp_algid_t,
+     657                 :            :                  grp_id_algid,
+     658                 :            :                  mbedtls_ecp_group_id,
+     659                 :            :                  grp_id)
+     660   [ #  #  #  # ]:          0 : FN_OID_GET_OID_BY_ATTR1(mbedtls_oid_get_oid_by_ec_grp_algid,
+     661                 :            :                         oid_ecp_grp_algid_t,
+     662                 :            :                         oid_ecp_grp_algid,
+     663                 :            :                         mbedtls_ecp_group_id,
+     664                 :            :                         grp_id)
+     665                 :            : #endif /* MBEDTLS_PK_HAVE_ECC_KEYS */
+     666                 :            : 
+     667                 :            : #if defined(MBEDTLS_CIPHER_C)
+     668                 :            : /*
+     669                 :            :  * For PKCS#5 PBES2 encryption algorithm
+     670                 :            :  */
+     671                 :            : typedef struct {
+     672                 :            :     mbedtls_oid_descriptor_t    descriptor;
+     673                 :            :     mbedtls_cipher_type_t       cipher_alg;
+     674                 :            : } oid_cipher_alg_t;
+     675                 :            : 
+     676                 :            : static const oid_cipher_alg_t oid_cipher_alg[] =
+     677                 :            : {
+     678                 :            :     {
+     679                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_DES_CBC,              "desCBC",       "DES-CBC"),
+     680                 :            :         MBEDTLS_CIPHER_DES_CBC,
+     681                 :            :     },
+     682                 :            :     {
+     683                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_DES_EDE3_CBC,         "des-ede3-cbc", "DES-EDE3-CBC"),
+     684                 :            :         MBEDTLS_CIPHER_DES_EDE3_CBC,
+     685                 :            :     },
+     686                 :            :     {
+     687                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_AES_128_CBC,          "aes128-cbc", "AES128-CBC"),
+     688                 :            :         MBEDTLS_CIPHER_AES_128_CBC,
+     689                 :            :     },
+     690                 :            :     {
+     691                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_AES_192_CBC,          "aes192-cbc", "AES192-CBC"),
+     692                 :            :         MBEDTLS_CIPHER_AES_192_CBC,
+     693                 :            :     },
+     694                 :            :     {
+     695                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_AES_256_CBC,          "aes256-cbc", "AES256-CBC"),
+     696                 :            :         MBEDTLS_CIPHER_AES_256_CBC,
+     697                 :            :     },
+     698                 :            :     {
+     699                 :            :         NULL_OID_DESCRIPTOR,
+     700                 :            :         MBEDTLS_CIPHER_NONE,
+     701                 :            :     },
+     702                 :            : };
+     703                 :            : 
+     704   [ #  #  #  #  :          0 : FN_OID_TYPED_FROM_ASN1(oid_cipher_alg_t, cipher_alg, oid_cipher_alg)
+          #  #  #  #  #  
+                      # ]
+     705         [ #  # ]:          0 : FN_OID_GET_ATTR1(mbedtls_oid_get_cipher_alg,
+     706                 :            :                  oid_cipher_alg_t,
+     707                 :            :                  cipher_alg,
+     708                 :            :                  mbedtls_cipher_type_t,
+     709                 :            :                  cipher_alg)
+     710                 :            : #endif /* MBEDTLS_CIPHER_C */
+     711                 :            : 
+     712                 :            : /*
+     713                 :            :  * For digestAlgorithm
+     714                 :            :  */
+     715                 :            : typedef struct {
+     716                 :            :     mbedtls_oid_descriptor_t    descriptor;
+     717                 :            :     mbedtls_md_type_t           md_alg;
+     718                 :            : } oid_md_alg_t;
+     719                 :            : 
+     720                 :            : static const oid_md_alg_t oid_md_alg[] =
+     721                 :            : {
+     722                 :            : #if defined(MBEDTLS_MD_CAN_MD5)
+     723                 :            :     {
+     724                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_DIGEST_ALG_MD5,       "id-md5",       "MD5"),
+     725                 :            :         MBEDTLS_MD_MD5,
+     726                 :            :     },
+     727                 :            : #endif
+     728                 :            : #if defined(MBEDTLS_MD_CAN_SHA1)
+     729                 :            :     {
+     730                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_DIGEST_ALG_SHA1,      "id-sha1",      "SHA-1"),
+     731                 :            :         MBEDTLS_MD_SHA1,
+     732                 :            :     },
+     733                 :            : #endif
+     734                 :            : #if defined(MBEDTLS_MD_CAN_SHA224)
+     735                 :            :     {
+     736                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_DIGEST_ALG_SHA224,    "id-sha224",    "SHA-224"),
+     737                 :            :         MBEDTLS_MD_SHA224,
+     738                 :            :     },
+     739                 :            : #endif
+     740                 :            : #if defined(MBEDTLS_MD_CAN_SHA256)
+     741                 :            :     {
+     742                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_DIGEST_ALG_SHA256,    "id-sha256",    "SHA-256"),
+     743                 :            :         MBEDTLS_MD_SHA256,
+     744                 :            :     },
+     745                 :            : #endif
+     746                 :            : #if defined(MBEDTLS_MD_CAN_SHA384)
+     747                 :            :     {
+     748                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_DIGEST_ALG_SHA384,    "id-sha384",    "SHA-384"),
+     749                 :            :         MBEDTLS_MD_SHA384,
+     750                 :            :     },
+     751                 :            : #endif
+     752                 :            : #if defined(MBEDTLS_MD_CAN_SHA512)
+     753                 :            :     {
+     754                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_DIGEST_ALG_SHA512,    "id-sha512",    "SHA-512"),
+     755                 :            :         MBEDTLS_MD_SHA512,
+     756                 :            :     },
+     757                 :            : #endif
+     758                 :            : #if defined(MBEDTLS_MD_CAN_RIPEMD160)
+     759                 :            :     {
+     760                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_DIGEST_ALG_RIPEMD160, "id-ripemd160", "RIPEMD-160"),
+     761                 :            :         MBEDTLS_MD_RIPEMD160,
+     762                 :            :     },
+     763                 :            : #endif
+     764                 :            : #if defined(MBEDTLS_MD_CAN_SHA3_224)
+     765                 :            :     {
+     766                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_DIGEST_ALG_SHA3_224,    "id-sha3-224",    "SHA-3-224"),
+     767                 :            :         MBEDTLS_MD_SHA3_224,
+     768                 :            :     },
+     769                 :            : #endif
+     770                 :            : #if defined(MBEDTLS_MD_CAN_SHA3_256)
+     771                 :            :     {
+     772                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_DIGEST_ALG_SHA3_256,    "id-sha3-256",    "SHA-3-256"),
+     773                 :            :         MBEDTLS_MD_SHA3_256,
+     774                 :            :     },
+     775                 :            : #endif
+     776                 :            : #if defined(MBEDTLS_MD_CAN_SHA3_384)
+     777                 :            :     {
+     778                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_DIGEST_ALG_SHA3_384,    "id-sha3-384",    "SHA-3-384"),
+     779                 :            :         MBEDTLS_MD_SHA3_384,
+     780                 :            :     },
+     781                 :            : #endif
+     782                 :            : #if defined(MBEDTLS_MD_CAN_SHA3_512)
+     783                 :            :     {
+     784                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_DIGEST_ALG_SHA3_512,    "id-sha3-512",    "SHA-3-512"),
+     785                 :            :         MBEDTLS_MD_SHA3_512,
+     786                 :            :     },
+     787                 :            : #endif
+     788                 :            :     {
+     789                 :            :         NULL_OID_DESCRIPTOR,
+     790                 :            :         MBEDTLS_MD_NONE,
+     791                 :            :     },
+     792                 :            : };
+     793                 :            : 
+     794   [ #  #  #  #  :          0 : FN_OID_TYPED_FROM_ASN1(oid_md_alg_t, md_alg, oid_md_alg)
+          #  #  #  #  #  
+                      # ]
+     795         [ #  # ]:          0 : FN_OID_GET_ATTR1(mbedtls_oid_get_md_alg, oid_md_alg_t, md_alg, mbedtls_md_type_t, md_alg)
+     796   [ +  +  +  - ]:       1293 : FN_OID_GET_OID_BY_ATTR1(mbedtls_oid_get_oid_by_md,
+     797                 :            :                         oid_md_alg_t,
+     798                 :            :                         oid_md_alg,
+     799                 :            :                         mbedtls_md_type_t,
+     800                 :            :                         md_alg)
+     801                 :            : 
+     802                 :            : /*
+     803                 :            :  * For HMAC digestAlgorithm
+     804                 :            :  */
+     805                 :            : typedef struct {
+     806                 :            :     mbedtls_oid_descriptor_t    descriptor;
+     807                 :            :     mbedtls_md_type_t           md_hmac;
+     808                 :            : } oid_md_hmac_t;
+     809                 :            : 
+     810                 :            : static const oid_md_hmac_t oid_md_hmac[] =
+     811                 :            : {
+     812                 :            : #if defined(MBEDTLS_MD_CAN_SHA1)
+     813                 :            :     {
+     814                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_HMAC_SHA1,      "hmacSHA1",      "HMAC-SHA-1"),
+     815                 :            :         MBEDTLS_MD_SHA1,
+     816                 :            :     },
+     817                 :            : #endif /* MBEDTLS_MD_CAN_SHA1 */
+     818                 :            : #if defined(MBEDTLS_MD_CAN_SHA224)
+     819                 :            :     {
+     820                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_HMAC_SHA224,    "hmacSHA224",    "HMAC-SHA-224"),
+     821                 :            :         MBEDTLS_MD_SHA224,
+     822                 :            :     },
+     823                 :            : #endif /* MBEDTLS_MD_CAN_SHA224 */
+     824                 :            : #if defined(MBEDTLS_MD_CAN_SHA256)
+     825                 :            :     {
+     826                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_HMAC_SHA256,    "hmacSHA256",    "HMAC-SHA-256"),
+     827                 :            :         MBEDTLS_MD_SHA256,
+     828                 :            :     },
+     829                 :            : #endif /* MBEDTLS_MD_CAN_SHA256 */
+     830                 :            : #if defined(MBEDTLS_MD_CAN_SHA384)
+     831                 :            :     {
+     832                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_HMAC_SHA384,    "hmacSHA384",    "HMAC-SHA-384"),
+     833                 :            :         MBEDTLS_MD_SHA384,
+     834                 :            :     },
+     835                 :            : #endif /* MBEDTLS_MD_CAN_SHA384 */
+     836                 :            : #if defined(MBEDTLS_MD_CAN_SHA512)
+     837                 :            :     {
+     838                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_HMAC_SHA512,    "hmacSHA512",    "HMAC-SHA-512"),
+     839                 :            :         MBEDTLS_MD_SHA512,
+     840                 :            :     },
+     841                 :            : #endif /* MBEDTLS_MD_CAN_SHA512 */
+     842                 :            : #if defined(MBEDTLS_MD_CAN_SHA3_224)
+     843                 :            :     {
+     844                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_HMAC_SHA3_224,    "hmacSHA3-224",    "HMAC-SHA3-224"),
+     845                 :            :         MBEDTLS_MD_SHA3_224,
+     846                 :            :     },
+     847                 :            : #endif /* MBEDTLS_MD_CAN_SHA3_224 */
+     848                 :            : #if defined(MBEDTLS_MD_CAN_SHA3_256)
+     849                 :            :     {
+     850                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_HMAC_SHA3_256,    "hmacSHA3-256",    "HMAC-SHA3-256"),
+     851                 :            :         MBEDTLS_MD_SHA3_256,
+     852                 :            :     },
+     853                 :            : #endif /* MBEDTLS_MD_CAN_SHA3_256 */
+     854                 :            : #if defined(MBEDTLS_MD_CAN_SHA3_384)
+     855                 :            :     {
+     856                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_HMAC_SHA3_384,    "hmacSHA3-384",    "HMAC-SHA3-384"),
+     857                 :            :         MBEDTLS_MD_SHA3_384,
+     858                 :            :     },
+     859                 :            : #endif /* MBEDTLS_MD_CAN_SHA3_384 */
+     860                 :            : #if defined(MBEDTLS_MD_CAN_SHA3_512)
+     861                 :            :     {
+     862                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_HMAC_SHA3_512,    "hmacSHA3-512",    "HMAC-SHA3-512"),
+     863                 :            :         MBEDTLS_MD_SHA3_512,
+     864                 :            :     },
+     865                 :            : #endif /* MBEDTLS_MD_CAN_SHA3_512 */
+     866                 :            : #if defined(MBEDTLS_MD_CAN_RIPEMD160)
+     867                 :            :     {
+     868                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_HMAC_RIPEMD160,    "hmacRIPEMD160",    "HMAC-RIPEMD160"),
+     869                 :            :         MBEDTLS_MD_RIPEMD160,
+     870                 :            :     },
+     871                 :            : #endif /* MBEDTLS_MD_CAN_RIPEMD160 */
+     872                 :            :     {
+     873                 :            :         NULL_OID_DESCRIPTOR,
+     874                 :            :         MBEDTLS_MD_NONE,
+     875                 :            :     },
+     876                 :            : };
+     877                 :            : 
+     878   [ #  #  #  #  :          0 : FN_OID_TYPED_FROM_ASN1(oid_md_hmac_t, md_hmac, oid_md_hmac)
+          #  #  #  #  #  
+                      # ]
+     879         [ #  # ]:          0 : FN_OID_GET_ATTR1(mbedtls_oid_get_md_hmac, oid_md_hmac_t, md_hmac, mbedtls_md_type_t, md_hmac)
+     880                 :            : 
+     881                 :            : #if defined(MBEDTLS_PKCS12_C) && defined(MBEDTLS_CIPHER_C)
+     882                 :            : /*
+     883                 :            :  * For PKCS#12 PBEs
+     884                 :            :  */
+     885                 :            : typedef struct {
+     886                 :            :     mbedtls_oid_descriptor_t    descriptor;
+     887                 :            :     mbedtls_md_type_t           md_alg;
+     888                 :            :     mbedtls_cipher_type_t       cipher_alg;
+     889                 :            : } oid_pkcs12_pbe_alg_t;
+     890                 :            : 
+     891                 :            : static const oid_pkcs12_pbe_alg_t oid_pkcs12_pbe_alg[] =
+     892                 :            : {
+     893                 :            :     {
+     894                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_PKCS12_PBE_SHA1_DES3_EDE_CBC,
+     895                 :            :                        "pbeWithSHAAnd3-KeyTripleDES-CBC",
+     896                 :            :                        "PBE with SHA1 and 3-Key 3DES"),
+     897                 :            :         MBEDTLS_MD_SHA1,      MBEDTLS_CIPHER_DES_EDE3_CBC,
+     898                 :            :     },
+     899                 :            :     {
+     900                 :            :         OID_DESCRIPTOR(MBEDTLS_OID_PKCS12_PBE_SHA1_DES2_EDE_CBC,
+     901                 :            :                        "pbeWithSHAAnd2-KeyTripleDES-CBC",
+     902                 :            :                        "PBE with SHA1 and 2-Key 3DES"),
+     903                 :            :         MBEDTLS_MD_SHA1,      MBEDTLS_CIPHER_DES_EDE_CBC,
+     904                 :            :     },
+     905                 :            :     {
+     906                 :            :         NULL_OID_DESCRIPTOR,
+     907                 :            :         MBEDTLS_MD_NONE, MBEDTLS_CIPHER_NONE,
+     908                 :            :     },
+     909                 :            : };
+     910                 :            : 
+     911                 :            : FN_OID_TYPED_FROM_ASN1(oid_pkcs12_pbe_alg_t, pkcs12_pbe_alg, oid_pkcs12_pbe_alg)
+     912                 :            : FN_OID_GET_ATTR2(mbedtls_oid_get_pkcs12_pbe_alg,
+     913                 :            :                  oid_pkcs12_pbe_alg_t,
+     914                 :            :                  pkcs12_pbe_alg,
+     915                 :            :                  mbedtls_md_type_t,
+     916                 :            :                  md_alg,
+     917                 :            :                  mbedtls_cipher_type_t,
+     918                 :            :                  cipher_alg)
+     919                 :            : #endif /* MBEDTLS_PKCS12_C && MBEDTLS_CIPHER_C */
+     920                 :            : 
+     921                 :            : /* Return the x.y.z.... style numeric string for the given OID */
+     922                 :          0 : int mbedtls_oid_get_numeric_string(char *buf, size_t size,
+     923                 :            :                                    const mbedtls_asn1_buf *oid)
+     924                 :            : {
+     925                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     926                 :          0 :     char *p = buf;
+     927                 :          0 :     size_t n = size;
+     928                 :          0 :     unsigned int value = 0;
+     929                 :            : 
+     930         [ #  # ]:          0 :     if (size > INT_MAX) {
+     931                 :            :         /* Avoid overflow computing return value */
+     932                 :          0 :         return MBEDTLS_ERR_ASN1_INVALID_LENGTH;
+     933                 :            :     }
+     934                 :            : 
+     935         [ #  # ]:          0 :     if (oid->len <= 0) {
+     936                 :            :         /* OID must not be empty */
+     937                 :          0 :         return MBEDTLS_ERR_ASN1_OUT_OF_DATA;
+     938                 :            :     }
+     939                 :            : 
+     940         [ #  # ]:          0 :     for (size_t i = 0; i < oid->len; i++) {
+     941                 :            :         /* Prevent overflow in value. */
+     942         [ #  # ]:          0 :         if (value > (UINT_MAX >> 7)) {
+     943                 :          0 :             return MBEDTLS_ERR_ASN1_INVALID_DATA;
+     944                 :            :         }
+     945   [ #  #  #  # ]:          0 :         if ((value == 0) && ((oid->p[i]) == 0x80)) {
+     946                 :            :             /* Overlong encoding is not allowed */
+     947                 :          0 :             return MBEDTLS_ERR_ASN1_INVALID_DATA;
+     948                 :            :         }
+     949                 :            : 
+     950                 :          0 :         value <<= 7;
+     951                 :          0 :         value |= oid->p[i] & 0x7F;
+     952                 :            : 
+     953         [ #  # ]:          0 :         if (!(oid->p[i] & 0x80)) {
+     954                 :            :             /* Last byte */
+     955         [ #  # ]:          0 :             if (n == size) {
+     956                 :            :                 int component1;
+     957                 :            :                 unsigned int component2;
+     958                 :            :                 /* First subidentifier contains first two OID components */
+     959         [ #  # ]:          0 :                 if (value >= 80) {
+     960                 :          0 :                     component1 = '2';
+     961                 :          0 :                     component2 = value - 80;
+     962         [ #  # ]:          0 :                 } else if (value >= 40) {
+     963                 :          0 :                     component1 = '1';
+     964                 :          0 :                     component2 = value - 40;
+     965                 :            :                 } else {
+     966                 :          0 :                     component1 = '0';
+     967                 :          0 :                     component2 = value;
+     968                 :            :                 }
+     969                 :          0 :                 ret = mbedtls_snprintf(p, n, "%c.%u", component1, component2);
+     970                 :            :             } else {
+     971                 :          0 :                 ret = mbedtls_snprintf(p, n, ".%u", value);
+     972                 :            :             }
+     973   [ #  #  #  # ]:          0 :             if (ret < 2 || (size_t) ret >= n) {
+     974                 :          0 :                 return MBEDTLS_ERR_OID_BUF_TOO_SMALL;
+     975                 :            :             }
+     976                 :          0 :             n -= (size_t) ret;
+     977                 :          0 :             p += ret;
+     978                 :          0 :             value = 0;
+     979                 :            :         }
+     980                 :            :     }
+     981                 :            : 
+     982         [ #  # ]:          0 :     if (value != 0) {
+     983                 :            :         /* Unterminated subidentifier */
+     984                 :          0 :         return MBEDTLS_ERR_ASN1_OUT_OF_DATA;
+     985                 :            :     }
+     986                 :            : 
+     987                 :          0 :     return (int) (size - n);
+     988                 :            : }
+     989                 :            : 
+     990                 :          0 : static int oid_parse_number(unsigned int *num, const char **p, const char *bound)
+     991                 :            : {
+     992                 :          0 :     int ret = MBEDTLS_ERR_ASN1_INVALID_DATA;
+     993                 :            : 
+     994                 :          0 :     *num = 0;
+     995                 :            : 
+     996   [ #  #  #  #  :          0 :     while (*p < bound && **p >= '0' && **p <= '9') {
+                   #  # ]
+     997                 :          0 :         ret = 0;
+     998         [ #  # ]:          0 :         if (*num > (UINT_MAX / 10)) {
+     999                 :          0 :             return MBEDTLS_ERR_ASN1_INVALID_DATA;
+    1000                 :            :         }
+    1001                 :          0 :         *num *= 10;
+    1002                 :          0 :         *num += **p - '0';
+    1003                 :          0 :         (*p)++;
+    1004                 :            :     }
+    1005                 :          0 :     return ret;
+    1006                 :            : }
+    1007                 :            : 
+    1008                 :          0 : static size_t oid_subidentifier_num_bytes(unsigned int value)
+    1009                 :            : {
+    1010                 :          0 :     size_t num_bytes = 0;
+    1011                 :            : 
+    1012                 :            :     do {
+    1013                 :          0 :         value >>= 7;
+    1014                 :          0 :         num_bytes++;
+    1015         [ #  # ]:          0 :     } while (value != 0);
+    1016                 :            : 
+    1017                 :          0 :     return num_bytes;
+    1018                 :            : }
+    1019                 :            : 
+    1020                 :          0 : static int oid_subidentifier_encode_into(unsigned char **p,
+    1021                 :            :                                          unsigned char *bound,
+    1022                 :            :                                          unsigned int value)
+    1023                 :            : {
+    1024                 :          0 :     size_t num_bytes = oid_subidentifier_num_bytes(value);
+    1025                 :            : 
+    1026         [ #  # ]:          0 :     if ((size_t) (bound - *p) < num_bytes) {
+    1027                 :          0 :         return MBEDTLS_ERR_OID_BUF_TOO_SMALL;
+    1028                 :            :     }
+    1029                 :          0 :     (*p)[num_bytes - 1] = (unsigned char) (value & 0x7f);
+    1030                 :          0 :     value >>= 7;
+    1031                 :            : 
+    1032         [ #  # ]:          0 :     for (size_t i = 2; i <= num_bytes; i++) {
+    1033                 :          0 :         (*p)[num_bytes - i] = 0x80 | (unsigned char) (value & 0x7f);
+    1034                 :          0 :         value >>= 7;
+    1035                 :            :     }
+    1036                 :          0 :     *p += num_bytes;
+    1037                 :            : 
+    1038                 :          0 :     return 0;
+    1039                 :            : }
+    1040                 :            : 
+    1041                 :            : /* Return the OID for the given x.y.z.... style numeric string  */
+    1042                 :          0 : int mbedtls_oid_from_numeric_string(mbedtls_asn1_buf *oid,
+    1043                 :            :                                     const char *oid_str, size_t size)
+    1044                 :            : {
+    1045                 :          0 :     int ret = MBEDTLS_ERR_ASN1_INVALID_DATA;
+    1046                 :          0 :     const char *str_ptr = oid_str;
+    1047                 :          0 :     const char *str_bound = oid_str + size;
+    1048                 :          0 :     unsigned int val = 0;
+    1049                 :            :     unsigned int component1, component2;
+    1050                 :            :     size_t encoded_len;
+    1051                 :            :     unsigned char *resized_mem;
+    1052                 :            : 
+    1053                 :            :     /* Count the number of dots to get a worst-case allocation size. */
+    1054                 :          0 :     size_t num_dots = 0;
+    1055         [ #  # ]:          0 :     for (size_t i = 0; i < size; i++) {
+    1056         [ #  # ]:          0 :         if (oid_str[i] == '.') {
+    1057                 :          0 :             num_dots++;
+    1058                 :            :         }
+    1059                 :            :     }
+    1060                 :            :     /* Allocate maximum possible required memory:
+    1061                 :            :      * There are (num_dots + 1) integer components, but the first 2 share the
+    1062                 :            :      * same subidentifier, so we only need num_dots subidentifiers maximum. */
+    1063   [ #  #  #  # ]:          0 :     if (num_dots == 0 || (num_dots > MBEDTLS_OID_MAX_COMPONENTS - 1)) {
+    1064                 :          0 :         return MBEDTLS_ERR_ASN1_INVALID_DATA;
+    1065                 :            :     }
+    1066                 :            :     /* Each byte can store 7 bits, calculate number of bytes for a
+    1067                 :            :      * subidentifier:
+    1068                 :            :      *
+    1069                 :            :      * bytes = ceil(subidentifer_size * 8 / 7)
+    1070                 :            :      */
+    1071                 :          0 :     size_t bytes_per_subidentifier = (((sizeof(unsigned int) * 8) - 1) / 7)
+    1072                 :            :                                      + 1;
+    1073                 :          0 :     size_t max_possible_bytes = num_dots * bytes_per_subidentifier;
+    1074                 :          0 :     oid->p = mbedtls_calloc(max_possible_bytes, 1);
+    1075         [ #  # ]:          0 :     if (oid->p == NULL) {
+    1076                 :          0 :         return MBEDTLS_ERR_ASN1_ALLOC_FAILED;
+    1077                 :            :     }
+    1078                 :          0 :     unsigned char *out_ptr = oid->p;
+    1079                 :          0 :     unsigned char *out_bound = oid->p + max_possible_bytes;
+    1080                 :            : 
+    1081                 :          0 :     ret = oid_parse_number(&component1, &str_ptr, str_bound);
+    1082         [ #  # ]:          0 :     if (ret != 0) {
+    1083                 :          0 :         goto error;
+    1084                 :            :     }
+    1085         [ #  # ]:          0 :     if (component1 > 2) {
+    1086                 :            :         /* First component can't be > 2 */
+    1087                 :          0 :         ret = MBEDTLS_ERR_ASN1_INVALID_DATA;
+    1088                 :          0 :         goto error;
+    1089                 :            :     }
+    1090   [ #  #  #  # ]:          0 :     if (str_ptr >= str_bound || *str_ptr != '.') {
+    1091                 :          0 :         ret = MBEDTLS_ERR_ASN1_INVALID_DATA;
+    1092                 :          0 :         goto error;
+    1093                 :            :     }
+    1094                 :          0 :     str_ptr++;
+    1095                 :            : 
+    1096                 :          0 :     ret = oid_parse_number(&component2, &str_ptr, str_bound);
+    1097         [ #  # ]:          0 :     if (ret != 0) {
+    1098                 :          0 :         goto error;
+    1099                 :            :     }
+    1100   [ #  #  #  # ]:          0 :     if ((component1 < 2) && (component2 > 39)) {
+    1101                 :            :         /* Root nodes 0 and 1 may have up to 40 children, numbered 0-39 */
+    1102                 :          0 :         ret = MBEDTLS_ERR_ASN1_INVALID_DATA;
+    1103                 :          0 :         goto error;
+    1104                 :            :     }
+    1105         [ #  # ]:          0 :     if (str_ptr < str_bound) {
+    1106         [ #  # ]:          0 :         if (*str_ptr == '.') {
+    1107                 :          0 :             str_ptr++;
+    1108                 :            :         } else {
+    1109                 :          0 :             ret = MBEDTLS_ERR_ASN1_INVALID_DATA;
+    1110                 :          0 :             goto error;
+    1111                 :            :         }
+    1112                 :            :     }
+    1113                 :            : 
+    1114         [ #  # ]:          0 :     if (component2 > (UINT_MAX - (component1 * 40))) {
+    1115                 :          0 :         ret = MBEDTLS_ERR_ASN1_INVALID_DATA;
+    1116                 :          0 :         goto error;
+    1117                 :            :     }
+    1118                 :          0 :     ret = oid_subidentifier_encode_into(&out_ptr, out_bound,
+    1119                 :          0 :                                         (component1 * 40) + component2);
+    1120         [ #  # ]:          0 :     if (ret != 0) {
+    1121                 :          0 :         goto error;
+    1122                 :            :     }
+    1123                 :            : 
+    1124         [ #  # ]:          0 :     while (str_ptr < str_bound) {
+    1125                 :          0 :         ret = oid_parse_number(&val, &str_ptr, str_bound);
+    1126         [ #  # ]:          0 :         if (ret != 0) {
+    1127                 :          0 :             goto error;
+    1128                 :            :         }
+    1129         [ #  # ]:          0 :         if (str_ptr < str_bound) {
+    1130         [ #  # ]:          0 :             if (*str_ptr == '.') {
+    1131                 :          0 :                 str_ptr++;
+    1132                 :            :             } else {
+    1133                 :          0 :                 ret = MBEDTLS_ERR_ASN1_INVALID_DATA;
+    1134                 :          0 :                 goto error;
+    1135                 :            :             }
+    1136                 :            :         }
+    1137                 :            : 
+    1138                 :          0 :         ret = oid_subidentifier_encode_into(&out_ptr, out_bound, val);
+    1139         [ #  # ]:          0 :         if (ret != 0) {
+    1140                 :          0 :             goto error;
+    1141                 :            :         }
+    1142                 :            :     }
+    1143                 :            : 
+    1144                 :          0 :     encoded_len = (size_t) (out_ptr - oid->p);
+    1145                 :          0 :     resized_mem = mbedtls_calloc(encoded_len, 1);
+    1146         [ #  # ]:          0 :     if (resized_mem == NULL) {
+    1147                 :          0 :         ret = MBEDTLS_ERR_ASN1_ALLOC_FAILED;
+    1148                 :          0 :         goto error;
+    1149                 :            :     }
+    1150                 :          0 :     memcpy(resized_mem, oid->p, encoded_len);
+    1151                 :          0 :     mbedtls_free(oid->p);
+    1152                 :          0 :     oid->p = resized_mem;
+    1153                 :          0 :     oid->len = encoded_len;
+    1154                 :            : 
+    1155                 :          0 :     oid->tag = MBEDTLS_ASN1_OID;
+    1156                 :            : 
+    1157                 :          0 :     return 0;
+    1158                 :            : 
+    1159                 :          0 : error:
+    1160                 :          0 :     mbedtls_free(oid->p);
+    1161                 :          0 :     oid->p = NULL;
+    1162                 :          0 :     oid->len = 0;
+    1163                 :          0 :     return ret;
+    1164                 :            : }
+    1165                 :            : 
+    1166                 :            : #endif /* MBEDTLS_OID_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/pem.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pem.c.func-sort-c.html new file mode 100644 index 00000000000..79a33905283 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pem.c.func-sort-c.html @@ -0,0 +1,121 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/pem.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - pem.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:4324217.8 %
Date:2024-09-22 08:21:07Functions:31030.0 %
Branches:2116412.8 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_pem_write_buffer0
pem_aes_decrypt0
pem_check_pkcs_padding0
pem_des3_decrypt0
pem_des_decrypt0
pem_get_iv0
pem_pbkdf10
mbedtls_pem_free158
mbedtls_pem_init158
mbedtls_pem_read_buffer459
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/pem.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pem.c.func.html new file mode 100644 index 00000000000..e17d32e387a --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pem.c.func.html @@ -0,0 +1,121 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/pem.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - pem.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:4324217.8 %
Date:2024-09-22 08:21:07Functions:31030.0 %
Branches:2116412.8 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_pem_free158
mbedtls_pem_init158
mbedtls_pem_read_buffer459
mbedtls_pem_write_buffer0
pem_aes_decrypt0
pem_check_pkcs_padding0
pem_des3_decrypt0
pem_des_decrypt0
pem_get_iv0
pem_pbkdf10
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/pem.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pem.c.gcov.html new file mode 100644 index 00000000000..68f5be68a25 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pem.c.gcov.html @@ -0,0 +1,632 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/pem.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - pem.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:4324217.8 %
Date:2024-09-22 08:21:07Functions:31030.0 %
Branches:2116412.8 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  *  Privacy Enhanced Mail (PEM) decoding
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  */
+       7                 :            : 
+       8                 :            : #include "common.h"
+       9                 :            : 
+      10                 :            : #if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
+      11                 :            : 
+      12                 :            : #include "mbedtls/pem.h"
+      13                 :            : #include "mbedtls/base64.h"
+      14                 :            : #include "mbedtls/des.h"
+      15                 :            : #include "mbedtls/aes.h"
+      16                 :            : #include "mbedtls/md.h"
+      17                 :            : #include "mbedtls/cipher.h"
+      18                 :            : #include "mbedtls/platform_util.h"
+      19                 :            : #include "mbedtls/error.h"
+      20                 :            : 
+      21                 :            : #include <string.h>
+      22                 :            : 
+      23                 :            : #include "mbedtls/platform.h"
+      24                 :            : 
+      25                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+      26                 :            : #include "psa/crypto.h"
+      27                 :            : #endif
+      28                 :            : 
+      29                 :            : #if defined(MBEDTLS_MD_CAN_MD5) &&  \
+      30                 :            :     defined(MBEDTLS_CIPHER_MODE_CBC) &&                             \
+      31                 :            :     (defined(MBEDTLS_DES_C) || defined(MBEDTLS_AES_C))
+      32                 :            : #define PEM_RFC1421
+      33                 :            : #endif /* MBEDTLS_MD_CAN_MD5 &&
+      34                 :            :           MBEDTLS_CIPHER_MODE_CBC &&
+      35                 :            :           ( MBEDTLS_AES_C || MBEDTLS_DES_C ) */
+      36                 :            : 
+      37                 :            : #if defined(MBEDTLS_PEM_PARSE_C)
+      38                 :        158 : void mbedtls_pem_init(mbedtls_pem_context *ctx)
+      39                 :            : {
+      40                 :        158 :     memset(ctx, 0, sizeof(mbedtls_pem_context));
+      41                 :        158 : }
+      42                 :            : 
+      43                 :            : #if defined(PEM_RFC1421)
+      44                 :            : /*
+      45                 :            :  * Read a 16-byte hex string and convert it to binary
+      46                 :            :  */
+      47                 :          0 : static int pem_get_iv(const unsigned char *s, unsigned char *iv,
+      48                 :            :                       size_t iv_len)
+      49                 :            : {
+      50                 :            :     size_t i, j, k;
+      51                 :            : 
+      52                 :          0 :     memset(iv, 0, iv_len);
+      53                 :            : 
+      54         [ #  # ]:          0 :     for (i = 0; i < iv_len * 2; i++, s++) {
+      55   [ #  #  #  # ]:          0 :         if (*s >= '0' && *s <= '9') {
+      56                 :          0 :             j = *s - '0';
+      57                 :            :         } else
+      58   [ #  #  #  # ]:          0 :         if (*s >= 'A' && *s <= 'F') {
+      59                 :          0 :             j = *s - '7';
+      60                 :            :         } else
+      61   [ #  #  #  # ]:          0 :         if (*s >= 'a' && *s <= 'f') {
+      62                 :          0 :             j = *s - 'W';
+      63                 :            :         } else {
+      64                 :          0 :             return MBEDTLS_ERR_PEM_INVALID_ENC_IV;
+      65                 :            :         }
+      66                 :            : 
+      67         [ #  # ]:          0 :         k = ((i & 1) != 0) ? j : j << 4;
+      68                 :            : 
+      69                 :          0 :         iv[i >> 1] = (unsigned char) (iv[i >> 1] | k);
+      70                 :            :     }
+      71                 :            : 
+      72                 :          0 :     return 0;
+      73                 :            : }
+      74                 :            : 
+      75                 :          0 : static int pem_pbkdf1(unsigned char *key, size_t keylen,
+      76                 :            :                       unsigned char *iv,
+      77                 :            :                       const unsigned char *pwd, size_t pwdlen)
+      78                 :            : {
+      79                 :            :     mbedtls_md_context_t md5_ctx;
+      80                 :            :     const mbedtls_md_info_t *md5_info;
+      81                 :            :     unsigned char md5sum[16];
+      82                 :            :     size_t use_len;
+      83                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+      84                 :            : 
+      85                 :          0 :     mbedtls_md_init(&md5_ctx);
+      86                 :            : 
+      87                 :            :     /* Prepare the context. (setup() errors gracefully on NULL info.) */
+      88                 :          0 :     md5_info = mbedtls_md_info_from_type(MBEDTLS_MD_MD5);
+      89         [ #  # ]:          0 :     if ((ret = mbedtls_md_setup(&md5_ctx, md5_info, 0)) != 0) {
+      90                 :          0 :         goto exit;
+      91                 :            :     }
+      92                 :            : 
+      93                 :            :     /*
+      94                 :            :      * key[ 0..15] = MD5(pwd || IV)
+      95                 :            :      */
+      96         [ #  # ]:          0 :     if ((ret = mbedtls_md_starts(&md5_ctx)) != 0) {
+      97                 :          0 :         goto exit;
+      98                 :            :     }
+      99         [ #  # ]:          0 :     if ((ret = mbedtls_md_update(&md5_ctx, pwd, pwdlen)) != 0) {
+     100                 :          0 :         goto exit;
+     101                 :            :     }
+     102         [ #  # ]:          0 :     if ((ret = mbedtls_md_update(&md5_ctx, iv,  8)) != 0) {
+     103                 :          0 :         goto exit;
+     104                 :            :     }
+     105         [ #  # ]:          0 :     if ((ret = mbedtls_md_finish(&md5_ctx, md5sum)) != 0) {
+     106                 :          0 :         goto exit;
+     107                 :            :     }
+     108                 :            : 
+     109         [ #  # ]:          0 :     if (keylen <= 16) {
+     110                 :          0 :         memcpy(key, md5sum, keylen);
+     111                 :          0 :         goto exit;
+     112                 :            :     }
+     113                 :            : 
+     114                 :          0 :     memcpy(key, md5sum, 16);
+     115                 :            : 
+     116                 :            :     /*
+     117                 :            :      * key[16..23] = MD5(key[ 0..15] || pwd || IV])
+     118                 :            :      */
+     119         [ #  # ]:          0 :     if ((ret = mbedtls_md_starts(&md5_ctx)) != 0) {
+     120                 :          0 :         goto exit;
+     121                 :            :     }
+     122         [ #  # ]:          0 :     if ((ret = mbedtls_md_update(&md5_ctx, md5sum, 16)) != 0) {
+     123                 :          0 :         goto exit;
+     124                 :            :     }
+     125         [ #  # ]:          0 :     if ((ret = mbedtls_md_update(&md5_ctx, pwd, pwdlen)) != 0) {
+     126                 :          0 :         goto exit;
+     127                 :            :     }
+     128         [ #  # ]:          0 :     if ((ret = mbedtls_md_update(&md5_ctx, iv, 8)) != 0) {
+     129                 :          0 :         goto exit;
+     130                 :            :     }
+     131         [ #  # ]:          0 :     if ((ret = mbedtls_md_finish(&md5_ctx, md5sum)) != 0) {
+     132                 :          0 :         goto exit;
+     133                 :            :     }
+     134                 :            : 
+     135                 :          0 :     use_len = 16;
+     136         [ #  # ]:          0 :     if (keylen < 32) {
+     137                 :          0 :         use_len = keylen - 16;
+     138                 :            :     }
+     139                 :            : 
+     140                 :          0 :     memcpy(key + 16, md5sum, use_len);
+     141                 :            : 
+     142                 :          0 : exit:
+     143                 :          0 :     mbedtls_md_free(&md5_ctx);
+     144                 :          0 :     mbedtls_platform_zeroize(md5sum, 16);
+     145                 :            : 
+     146                 :          0 :     return ret;
+     147                 :            : }
+     148                 :            : 
+     149                 :            : #if defined(MBEDTLS_DES_C)
+     150                 :            : /*
+     151                 :            :  * Decrypt with DES-CBC, using PBKDF1 for key derivation
+     152                 :            :  */
+     153                 :          0 : static int pem_des_decrypt(unsigned char des_iv[8],
+     154                 :            :                            unsigned char *buf, size_t buflen,
+     155                 :            :                            const unsigned char *pwd, size_t pwdlen)
+     156                 :            : {
+     157                 :            :     mbedtls_des_context des_ctx;
+     158                 :            :     unsigned char des_key[8];
+     159                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     160                 :            : 
+     161                 :          0 :     mbedtls_des_init(&des_ctx);
+     162                 :            : 
+     163         [ #  # ]:          0 :     if ((ret = pem_pbkdf1(des_key, 8, des_iv, pwd, pwdlen)) != 0) {
+     164                 :          0 :         goto exit;
+     165                 :            :     }
+     166                 :            : 
+     167         [ #  # ]:          0 :     if ((ret = mbedtls_des_setkey_dec(&des_ctx, des_key)) != 0) {
+     168                 :          0 :         goto exit;
+     169                 :            :     }
+     170                 :          0 :     ret = mbedtls_des_crypt_cbc(&des_ctx, MBEDTLS_DES_DECRYPT, buflen,
+     171                 :            :                                 des_iv, buf, buf);
+     172                 :            : 
+     173                 :          0 : exit:
+     174                 :          0 :     mbedtls_des_free(&des_ctx);
+     175                 :          0 :     mbedtls_platform_zeroize(des_key, 8);
+     176                 :            : 
+     177                 :          0 :     return ret;
+     178                 :            : }
+     179                 :            : 
+     180                 :            : /*
+     181                 :            :  * Decrypt with 3DES-CBC, using PBKDF1 for key derivation
+     182                 :            :  */
+     183                 :          0 : static int pem_des3_decrypt(unsigned char des3_iv[8],
+     184                 :            :                             unsigned char *buf, size_t buflen,
+     185                 :            :                             const unsigned char *pwd, size_t pwdlen)
+     186                 :            : {
+     187                 :            :     mbedtls_des3_context des3_ctx;
+     188                 :            :     unsigned char des3_key[24];
+     189                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     190                 :            : 
+     191                 :          0 :     mbedtls_des3_init(&des3_ctx);
+     192                 :            : 
+     193         [ #  # ]:          0 :     if ((ret = pem_pbkdf1(des3_key, 24, des3_iv, pwd, pwdlen)) != 0) {
+     194                 :          0 :         goto exit;
+     195                 :            :     }
+     196                 :            : 
+     197         [ #  # ]:          0 :     if ((ret = mbedtls_des3_set3key_dec(&des3_ctx, des3_key)) != 0) {
+     198                 :          0 :         goto exit;
+     199                 :            :     }
+     200                 :          0 :     ret = mbedtls_des3_crypt_cbc(&des3_ctx, MBEDTLS_DES_DECRYPT, buflen,
+     201                 :            :                                  des3_iv, buf, buf);
+     202                 :            : 
+     203                 :          0 : exit:
+     204                 :          0 :     mbedtls_des3_free(&des3_ctx);
+     205                 :          0 :     mbedtls_platform_zeroize(des3_key, 24);
+     206                 :            : 
+     207                 :          0 :     return ret;
+     208                 :            : }
+     209                 :            : #endif /* MBEDTLS_DES_C */
+     210                 :            : 
+     211                 :            : #if defined(MBEDTLS_AES_C)
+     212                 :            : /*
+     213                 :            :  * Decrypt with AES-XXX-CBC, using PBKDF1 for key derivation
+     214                 :            :  */
+     215                 :          0 : static int pem_aes_decrypt(unsigned char aes_iv[16], unsigned int keylen,
+     216                 :            :                            unsigned char *buf, size_t buflen,
+     217                 :            :                            const unsigned char *pwd, size_t pwdlen)
+     218                 :            : {
+     219                 :            :     mbedtls_aes_context aes_ctx;
+     220                 :            :     unsigned char aes_key[32];
+     221                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     222                 :            : 
+     223                 :          0 :     mbedtls_aes_init(&aes_ctx);
+     224                 :            : 
+     225         [ #  # ]:          0 :     if ((ret = pem_pbkdf1(aes_key, keylen, aes_iv, pwd, pwdlen)) != 0) {
+     226                 :          0 :         goto exit;
+     227                 :            :     }
+     228                 :            : 
+     229         [ #  # ]:          0 :     if ((ret = mbedtls_aes_setkey_dec(&aes_ctx, aes_key, keylen * 8)) != 0) {
+     230                 :          0 :         goto exit;
+     231                 :            :     }
+     232                 :          0 :     ret = mbedtls_aes_crypt_cbc(&aes_ctx, MBEDTLS_AES_DECRYPT, buflen,
+     233                 :            :                                 aes_iv, buf, buf);
+     234                 :            : 
+     235                 :          0 : exit:
+     236                 :          0 :     mbedtls_aes_free(&aes_ctx);
+     237                 :          0 :     mbedtls_platform_zeroize(aes_key, keylen);
+     238                 :            : 
+     239                 :          0 :     return ret;
+     240                 :            : }
+     241                 :            : #endif /* MBEDTLS_AES_C */
+     242                 :            : 
+     243                 :            : #if defined(MBEDTLS_DES_C) || defined(MBEDTLS_AES_C)
+     244                 :          0 : static int pem_check_pkcs_padding(unsigned char *input, size_t input_len, size_t *data_len)
+     245                 :            : {
+     246                 :            :     /* input_len > 0 is guaranteed by mbedtls_pem_read_buffer(). */
+     247                 :          0 :     size_t pad_len = input[input_len - 1];
+     248                 :            :     size_t i;
+     249                 :            : 
+     250         [ #  # ]:          0 :     if (pad_len > input_len) {
+     251                 :          0 :         return MBEDTLS_ERR_PEM_PASSWORD_MISMATCH;
+     252                 :            :     }
+     253                 :            : 
+     254                 :          0 :     *data_len = input_len - pad_len;
+     255                 :            : 
+     256         [ #  # ]:          0 :     for (i = *data_len; i < input_len; i++) {
+     257         [ #  # ]:          0 :         if (input[i] != pad_len) {
+     258                 :          0 :             return MBEDTLS_ERR_PEM_PASSWORD_MISMATCH;
+     259                 :            :         }
+     260                 :            :     }
+     261                 :            : 
+     262                 :          0 :     return 0;
+     263                 :            : }
+     264                 :            : #endif /* MBEDTLS_DES_C || MBEDTLS_AES_C */
+     265                 :            : 
+     266                 :            : #endif /* PEM_RFC1421 */
+     267                 :            : 
+     268                 :        459 : int mbedtls_pem_read_buffer(mbedtls_pem_context *ctx, const char *header, const char *footer,
+     269                 :            :                             const unsigned char *data, const unsigned char *pwd,
+     270                 :            :                             size_t pwdlen, size_t *use_len)
+     271                 :            : {
+     272                 :            :     int ret, enc;
+     273                 :            :     size_t len;
+     274                 :            :     unsigned char *buf;
+     275                 :            :     const unsigned char *s1, *s2, *end;
+     276                 :            : #if defined(PEM_RFC1421)
+     277                 :            :     unsigned char pem_iv[16];
+     278                 :        459 :     mbedtls_cipher_type_t enc_alg = MBEDTLS_CIPHER_NONE;
+     279                 :            : #else
+     280                 :            :     ((void) pwd);
+     281                 :            :     ((void) pwdlen);
+     282                 :            : #endif /* PEM_RFC1421 */
+     283                 :            : 
+     284         [ -  + ]:        459 :     if (ctx == NULL) {
+     285                 :          0 :         return MBEDTLS_ERR_PEM_BAD_INPUT_DATA;
+     286                 :            :     }
+     287                 :            : 
+     288                 :        459 :     s1 = (unsigned char *) strstr((const char *) data, header);
+     289                 :            : 
+     290         [ +  + ]:        459 :     if (s1 == NULL) {
+     291                 :        306 :         return MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT;
+     292                 :            :     }
+     293                 :            : 
+     294                 :        153 :     s2 = (unsigned char *) strstr((const char *) data, footer);
+     295                 :            : 
+     296   [ +  -  -  + ]:        153 :     if (s2 == NULL || s2 <= s1) {
+     297                 :          0 :         return MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT;
+     298                 :            :     }
+     299                 :            : 
+     300                 :        153 :     s1 += strlen(header);
+     301         [ -  + ]:        153 :     if (*s1 == ' ') {
+     302                 :          0 :         s1++;
+     303                 :            :     }
+     304         [ +  - ]:        153 :     if (*s1 == '\r') {
+     305                 :        153 :         s1++;
+     306                 :            :     }
+     307         [ +  - ]:        153 :     if (*s1 == '\n') {
+     308                 :        153 :         s1++;
+     309                 :            :     } else {
+     310                 :          0 :         return MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT;
+     311                 :            :     }
+     312                 :            : 
+     313                 :        153 :     end = s2;
+     314                 :        153 :     end += strlen(footer);
+     315         [ -  + ]:        153 :     if (*end == ' ') {
+     316                 :          0 :         end++;
+     317                 :            :     }
+     318         [ +  - ]:        153 :     if (*end == '\r') {
+     319                 :        153 :         end++;
+     320                 :            :     }
+     321         [ +  - ]:        153 :     if (*end == '\n') {
+     322                 :        153 :         end++;
+     323                 :            :     }
+     324                 :        153 :     *use_len = (size_t) (end - data);
+     325                 :            : 
+     326                 :        153 :     enc = 0;
+     327                 :            : 
+     328   [ +  -  -  + ]:        153 :     if (s2 - s1 >= 22 && memcmp(s1, "Proc-Type: 4,ENCRYPTED", 22) == 0) {
+     329                 :            : #if defined(PEM_RFC1421)
+     330                 :          0 :         enc++;
+     331                 :            : 
+     332                 :          0 :         s1 += 22;
+     333         [ #  # ]:          0 :         if (*s1 == '\r') {
+     334                 :          0 :             s1++;
+     335                 :            :         }
+     336         [ #  # ]:          0 :         if (*s1 == '\n') {
+     337                 :          0 :             s1++;
+     338                 :            :         } else {
+     339                 :          0 :             return MBEDTLS_ERR_PEM_INVALID_DATA;
+     340                 :            :         }
+     341                 :            : 
+     342                 :            : 
+     343                 :            : #if defined(MBEDTLS_DES_C)
+     344   [ #  #  #  # ]:          0 :         if (s2 - s1 >= 23 && memcmp(s1, "DEK-Info: DES-EDE3-CBC,", 23) == 0) {
+     345                 :          0 :             enc_alg = MBEDTLS_CIPHER_DES_EDE3_CBC;
+     346                 :            : 
+     347                 :          0 :             s1 += 23;
+     348   [ #  #  #  # ]:          0 :             if (s2 - s1 < 16 || pem_get_iv(s1, pem_iv, 8) != 0) {
+     349                 :          0 :                 return MBEDTLS_ERR_PEM_INVALID_ENC_IV;
+     350                 :            :             }
+     351                 :            : 
+     352                 :          0 :             s1 += 16;
+     353   [ #  #  #  # ]:          0 :         } else if (s2 - s1 >= 18 && memcmp(s1, "DEK-Info: DES-CBC,", 18) == 0) {
+     354                 :          0 :             enc_alg = MBEDTLS_CIPHER_DES_CBC;
+     355                 :            : 
+     356                 :          0 :             s1 += 18;
+     357   [ #  #  #  # ]:          0 :             if (s2 - s1 < 16 || pem_get_iv(s1, pem_iv, 8) != 0) {
+     358                 :          0 :                 return MBEDTLS_ERR_PEM_INVALID_ENC_IV;
+     359                 :            :             }
+     360                 :            : 
+     361                 :          0 :             s1 += 16;
+     362                 :            :         }
+     363                 :            : #endif /* MBEDTLS_DES_C */
+     364                 :            : 
+     365                 :            : #if defined(MBEDTLS_AES_C)
+     366   [ #  #  #  # ]:          0 :         if (s2 - s1 >= 14 && memcmp(s1, "DEK-Info: AES-", 14) == 0) {
+     367         [ #  # ]:          0 :             if (s2 - s1 < 22) {
+     368                 :          0 :                 return MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG;
+     369         [ #  # ]:          0 :             } else if (memcmp(s1, "DEK-Info: AES-128-CBC,", 22) == 0) {
+     370                 :          0 :                 enc_alg = MBEDTLS_CIPHER_AES_128_CBC;
+     371         [ #  # ]:          0 :             } else if (memcmp(s1, "DEK-Info: AES-192-CBC,", 22) == 0) {
+     372                 :          0 :                 enc_alg = MBEDTLS_CIPHER_AES_192_CBC;
+     373         [ #  # ]:          0 :             } else if (memcmp(s1, "DEK-Info: AES-256-CBC,", 22) == 0) {
+     374                 :          0 :                 enc_alg = MBEDTLS_CIPHER_AES_256_CBC;
+     375                 :            :             } else {
+     376                 :          0 :                 return MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG;
+     377                 :            :             }
+     378                 :            : 
+     379                 :          0 :             s1 += 22;
+     380   [ #  #  #  # ]:          0 :             if (s2 - s1 < 32 || pem_get_iv(s1, pem_iv, 16) != 0) {
+     381                 :          0 :                 return MBEDTLS_ERR_PEM_INVALID_ENC_IV;
+     382                 :            :             }
+     383                 :            : 
+     384                 :          0 :             s1 += 32;
+     385                 :            :         }
+     386                 :            : #endif /* MBEDTLS_AES_C */
+     387                 :            : 
+     388         [ #  # ]:          0 :         if (enc_alg == MBEDTLS_CIPHER_NONE) {
+     389                 :          0 :             return MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG;
+     390                 :            :         }
+     391                 :            : 
+     392         [ #  # ]:          0 :         if (*s1 == '\r') {
+     393                 :          0 :             s1++;
+     394                 :            :         }
+     395         [ #  # ]:          0 :         if (*s1 == '\n') {
+     396                 :          0 :             s1++;
+     397                 :            :         } else {
+     398                 :          0 :             return MBEDTLS_ERR_PEM_INVALID_DATA;
+     399                 :            :         }
+     400                 :            : #else
+     401                 :            :         return MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE;
+     402                 :            : #endif /* PEM_RFC1421 */
+     403                 :            :     }
+     404                 :            : 
+     405         [ -  + ]:        153 :     if (s1 >= s2) {
+     406                 :          0 :         return MBEDTLS_ERR_PEM_INVALID_DATA;
+     407                 :            :     }
+     408                 :            : 
+     409                 :        153 :     ret = mbedtls_base64_decode(NULL, 0, &len, s1, (size_t) (s2 - s1));
+     410                 :            : 
+     411         [ -  + ]:        153 :     if (ret == MBEDTLS_ERR_BASE64_INVALID_CHARACTER) {
+     412                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PEM_INVALID_DATA, ret);
+     413                 :            :     }
+     414                 :            : 
+     415         [ -  + ]:        153 :     if (len == 0) {
+     416                 :          0 :         return MBEDTLS_ERR_PEM_BAD_INPUT_DATA;
+     417                 :            :     }
+     418                 :            : 
+     419         [ -  + ]:        153 :     if ((buf = mbedtls_calloc(1, len)) == NULL) {
+     420                 :          0 :         return MBEDTLS_ERR_PEM_ALLOC_FAILED;
+     421                 :            :     }
+     422                 :            : 
+     423         [ -  + ]:        153 :     if ((ret = mbedtls_base64_decode(buf, len, &len, s1, (size_t) (s2 - s1))) != 0) {
+     424                 :          0 :         mbedtls_zeroize_and_free(buf, len);
+     425                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PEM_INVALID_DATA, ret);
+     426                 :            :     }
+     427                 :            : 
+     428         [ -  + ]:        153 :     if (enc != 0) {
+     429                 :            : #if defined(PEM_RFC1421)
+     430         [ #  # ]:          0 :         if (pwd == NULL) {
+     431                 :          0 :             mbedtls_zeroize_and_free(buf, len);
+     432                 :          0 :             return MBEDTLS_ERR_PEM_PASSWORD_REQUIRED;
+     433                 :            :         }
+     434                 :            : 
+     435                 :          0 :         ret = 0;
+     436                 :            : 
+     437                 :            : #if defined(MBEDTLS_DES_C)
+     438         [ #  # ]:          0 :         if (enc_alg == MBEDTLS_CIPHER_DES_EDE3_CBC) {
+     439                 :          0 :             ret = pem_des3_decrypt(pem_iv, buf, len, pwd, pwdlen);
+     440         [ #  # ]:          0 :         } else if (enc_alg == MBEDTLS_CIPHER_DES_CBC) {
+     441                 :          0 :             ret = pem_des_decrypt(pem_iv, buf, len, pwd, pwdlen);
+     442                 :            :         }
+     443                 :            : #endif /* MBEDTLS_DES_C */
+     444                 :            : 
+     445                 :            : #if defined(MBEDTLS_AES_C)
+     446         [ #  # ]:          0 :         if (enc_alg == MBEDTLS_CIPHER_AES_128_CBC) {
+     447                 :          0 :             ret = pem_aes_decrypt(pem_iv, 16, buf, len, pwd, pwdlen);
+     448         [ #  # ]:          0 :         } else if (enc_alg == MBEDTLS_CIPHER_AES_192_CBC) {
+     449                 :          0 :             ret = pem_aes_decrypt(pem_iv, 24, buf, len, pwd, pwdlen);
+     450         [ #  # ]:          0 :         } else if (enc_alg == MBEDTLS_CIPHER_AES_256_CBC) {
+     451                 :          0 :             ret = pem_aes_decrypt(pem_iv, 32, buf, len, pwd, pwdlen);
+     452                 :            :         }
+     453                 :            : #endif /* MBEDTLS_AES_C */
+     454                 :            : 
+     455         [ #  # ]:          0 :         if (ret != 0) {
+     456                 :          0 :             mbedtls_zeroize_and_free(buf, len);
+     457                 :          0 :             return ret;
+     458                 :            :         }
+     459                 :            : 
+     460                 :            :         /* Check PKCS padding and update data length based on padding info.
+     461                 :            :          * This can be used to detect invalid padding data and password
+     462                 :            :          * mismatches. */
+     463                 :            :         size_t unpadded_len;
+     464                 :          0 :         ret = pem_check_pkcs_padding(buf, len, &unpadded_len);
+     465         [ #  # ]:          0 :         if (ret != 0) {
+     466                 :          0 :             mbedtls_zeroize_and_free(buf, len);
+     467                 :          0 :             return ret;
+     468                 :            :         }
+     469                 :          0 :         len = unpadded_len;
+     470                 :            : #else
+     471                 :            :         mbedtls_zeroize_and_free(buf, len);
+     472                 :            :         return MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE;
+     473                 :            : #endif /* PEM_RFC1421 */
+     474                 :            :     }
+     475                 :            : 
+     476                 :        153 :     ctx->buf = buf;
+     477                 :        153 :     ctx->buflen = len;
+     478                 :            : 
+     479                 :        153 :     return 0;
+     480                 :            : }
+     481                 :            : 
+     482                 :        158 : void mbedtls_pem_free(mbedtls_pem_context *ctx)
+     483                 :            : {
+     484         [ +  + ]:        158 :     if (ctx->buf != NULL) {
+     485                 :        153 :         mbedtls_zeroize_and_free(ctx->buf, ctx->buflen);
+     486                 :            :     }
+     487                 :        158 :     mbedtls_free(ctx->info);
+     488                 :            : 
+     489                 :        158 :     mbedtls_platform_zeroize(ctx, sizeof(mbedtls_pem_context));
+     490                 :        158 : }
+     491                 :            : #endif /* MBEDTLS_PEM_PARSE_C */
+     492                 :            : 
+     493                 :            : #if defined(MBEDTLS_PEM_WRITE_C)
+     494                 :          0 : int mbedtls_pem_write_buffer(const char *header, const char *footer,
+     495                 :            :                              const unsigned char *der_data, size_t der_len,
+     496                 :            :                              unsigned char *buf, size_t buf_len, size_t *olen)
+     497                 :            : {
+     498                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     499                 :          0 :     unsigned char *encode_buf = NULL, *c, *p = buf;
+     500                 :          0 :     size_t len = 0, use_len, add_len = 0;
+     501                 :            : 
+     502                 :          0 :     mbedtls_base64_encode(NULL, 0, &use_len, der_data, der_len);
+     503                 :          0 :     add_len = strlen(header) + strlen(footer) + (((use_len > 2) ? (use_len - 2) : 0) / 64) + 1;
+     504                 :            : 
+     505         [ #  # ]:          0 :     if (use_len + add_len > buf_len) {
+     506                 :          0 :         *olen = use_len + add_len;
+     507                 :          0 :         return MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL;
+     508                 :            :     }
+     509                 :            : 
+     510   [ #  #  #  # ]:          0 :     if (use_len != 0 &&
+     511                 :          0 :         ((encode_buf = mbedtls_calloc(1, use_len)) == NULL)) {
+     512                 :          0 :         return MBEDTLS_ERR_PEM_ALLOC_FAILED;
+     513                 :            :     }
+     514                 :            : 
+     515         [ #  # ]:          0 :     if ((ret = mbedtls_base64_encode(encode_buf, use_len, &use_len, der_data,
+     516                 :            :                                      der_len)) != 0) {
+     517                 :          0 :         mbedtls_free(encode_buf);
+     518                 :          0 :         return ret;
+     519                 :            :     }
+     520                 :            : 
+     521                 :          0 :     memcpy(p, header, strlen(header));
+     522                 :          0 :     p += strlen(header);
+     523                 :          0 :     c = encode_buf;
+     524                 :            : 
+     525         [ #  # ]:          0 :     while (use_len) {
+     526                 :          0 :         len = (use_len > 64) ? 64 : use_len;
+     527                 :          0 :         memcpy(p, c, len);
+     528                 :          0 :         use_len -= len;
+     529                 :          0 :         p += len;
+     530                 :          0 :         c += len;
+     531                 :          0 :         *p++ = '\n';
+     532                 :            :     }
+     533                 :            : 
+     534                 :          0 :     memcpy(p, footer, strlen(footer));
+     535                 :          0 :     p += strlen(footer);
+     536                 :            : 
+     537                 :          0 :     *p++ = '\0';
+     538                 :          0 :     *olen = (size_t) (p - buf);
+     539                 :            : 
+     540                 :            :     /* Clean any remaining data previously written to the buffer */
+     541                 :          0 :     memset(buf + *olen, 0, buf_len - *olen);
+     542                 :            : 
+     543                 :          0 :     mbedtls_free(encode_buf);
+     544                 :          0 :     return 0;
+     545                 :            : }
+     546                 :            : #endif /* MBEDTLS_PEM_WRITE_C */
+     547                 :            : #endif /* MBEDTLS_PEM_PARSE_C || MBEDTLS_PEM_WRITE_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/pk.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pk.c.func-sort-c.html new file mode 100644 index 00000000000..33c814d82b2 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pk.c.func-sort-c.html @@ -0,0 +1,169 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/pk.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - pk.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:6019331.1 %
Date:2024-09-22 08:21:07Functions:132259.1 %
Branches:3616721.6 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_pk_check_pair0
mbedtls_pk_debug0
mbedtls_pk_decrypt0
mbedtls_pk_encrypt0
mbedtls_pk_get_name0
mbedtls_pk_restart_free0
mbedtls_pk_restart_init0
mbedtls_pk_sign_ext0
pk_restart_setup0
mbedtls_pk_sign6
mbedtls_pk_sign_restartable6
mbedtls_pk_init164
mbedtls_pk_get_bitlen540
mbedtls_pk_verify1588
mbedtls_pk_verify_ext1588
mbedtls_pk_verify_restartable1588
pk_hashlen_helper1594
mbedtls_pk_can_do3188
mbedtls_pk_free12288
mbedtls_pk_info_from_type12294
mbedtls_pk_setup12294
mbedtls_pk_get_type35237
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/pk.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pk.c.func.html new file mode 100644 index 00000000000..f77a77f0c3f --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pk.c.func.html @@ -0,0 +1,169 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/pk.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - pk.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:6019331.1 %
Date:2024-09-22 08:21:07Functions:132259.1 %
Branches:3616721.6 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_pk_can_do3188
mbedtls_pk_check_pair0
mbedtls_pk_debug0
mbedtls_pk_decrypt0
mbedtls_pk_encrypt0
mbedtls_pk_free12288
mbedtls_pk_get_bitlen540
mbedtls_pk_get_name0
mbedtls_pk_get_type35237
mbedtls_pk_info_from_type12294
mbedtls_pk_init164
mbedtls_pk_restart_free0
mbedtls_pk_restart_init0
mbedtls_pk_setup12294
mbedtls_pk_sign6
mbedtls_pk_sign_ext0
mbedtls_pk_sign_restartable6
mbedtls_pk_verify1588
mbedtls_pk_verify_ext1588
mbedtls_pk_verify_restartable1588
pk_hashlen_helper1594
pk_restart_setup0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/pk.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pk.c.gcov.html new file mode 100644 index 00000000000..cfcecf57d51 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pk.c.gcov.html @@ -0,0 +1,1620 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/pk.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - pk.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:6019331.1 %
Date:2024-09-22 08:21:07Functions:132259.1 %
Branches:3616721.6 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  *  Public Key abstraction layer
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  */
+       7                 :            : 
+       8                 :            : #include "common.h"
+       9                 :            : 
+      10                 :            : #if defined(MBEDTLS_PK_C)
+      11                 :            : #include "mbedtls/pk.h"
+      12                 :            : #include "pk_wrap.h"
+      13                 :            : #include "pkwrite.h"
+      14                 :            : #include "pk_internal.h"
+      15                 :            : 
+      16                 :            : #include "mbedtls/platform_util.h"
+      17                 :            : #include "mbedtls/error.h"
+      18                 :            : 
+      19                 :            : #if defined(MBEDTLS_RSA_C)
+      20                 :            : #include "mbedtls/rsa.h"
+      21                 :            : #include "rsa_internal.h"
+      22                 :            : #endif
+      23                 :            : #if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
+      24                 :            : #include "mbedtls/ecp.h"
+      25                 :            : #endif
+      26                 :            : #if defined(MBEDTLS_ECDSA_C)
+      27                 :            : #include "mbedtls/ecdsa.h"
+      28                 :            : #endif
+      29                 :            : 
+      30                 :            : #if defined(MBEDTLS_PSA_CRYPTO_CLIENT)
+      31                 :            : #include "psa_util_internal.h"
+      32                 :            : #include "mbedtls/psa_util.h"
+      33                 :            : #endif
+      34                 :            : 
+      35                 :            : #include <limits.h>
+      36                 :            : #include <stdint.h>
+      37                 :            : 
+      38                 :            : #define PSA_EXPORT_KEY_PAIR_OR_PUBLIC_MAX_SIZE \
+      39                 :            :     (PSA_EXPORT_KEY_PAIR_MAX_SIZE > PSA_EXPORT_PUBLIC_KEY_MAX_SIZE) ? \
+      40                 :            :     PSA_EXPORT_KEY_PAIR_MAX_SIZE : PSA_EXPORT_PUBLIC_KEY_MAX_SIZE
+      41                 :            : 
+      42                 :            : /*
+      43                 :            :  * Initialise a mbedtls_pk_context
+      44                 :            :  */
+      45                 :        164 : void mbedtls_pk_init(mbedtls_pk_context *ctx)
+      46                 :            : {
+      47                 :        164 :     ctx->pk_info = NULL;
+      48                 :        164 :     ctx->pk_ctx = NULL;
+      49                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+      50                 :            :     ctx->priv_id = MBEDTLS_SVC_KEY_ID_INIT;
+      51                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO */
+      52                 :            : #if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
+      53                 :            :     memset(ctx->pub_raw, 0, sizeof(ctx->pub_raw));
+      54                 :            :     ctx->pub_raw_len = 0;
+      55                 :            :     ctx->ec_family = 0;
+      56                 :            :     ctx->ec_bits = 0;
+      57                 :            : #endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
+      58                 :        164 : }
+      59                 :            : 
+      60                 :            : /*
+      61                 :            :  * Free (the components of) a mbedtls_pk_context
+      62                 :            :  */
+      63                 :      12288 : void mbedtls_pk_free(mbedtls_pk_context *ctx)
+      64                 :            : {
+      65         [ -  + ]:      12288 :     if (ctx == NULL) {
+      66                 :          0 :         return;
+      67                 :            :     }
+      68                 :            : 
+      69   [ +  -  +  - ]:      12288 :     if ((ctx->pk_info != NULL) && (ctx->pk_info->ctx_free_func != NULL)) {
+      70                 :      12288 :         ctx->pk_info->ctx_free_func(ctx->pk_ctx);
+      71                 :            :     }
+      72                 :            : 
+      73                 :            : #if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
+      74                 :            :     /* The ownership of the priv_id key for opaque keys is external of the PK
+      75                 :            :      * module. It's the user responsibility to clear it after use. */
+      76                 :            :     if ((ctx->pk_info != NULL) && (ctx->pk_info->type != MBEDTLS_PK_OPAQUE)) {
+      77                 :            :         psa_destroy_key(ctx->priv_id);
+      78                 :            :     }
+      79                 :            : #endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
+      80                 :            : 
+      81                 :      12288 :     mbedtls_platform_zeroize(ctx, sizeof(mbedtls_pk_context));
+      82                 :            : }
+      83                 :            : 
+      84                 :            : #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
+      85                 :            : /*
+      86                 :            :  * Initialize a restart context
+      87                 :            :  */
+      88                 :          0 : void mbedtls_pk_restart_init(mbedtls_pk_restart_ctx *ctx)
+      89                 :            : {
+      90                 :          0 :     ctx->pk_info = NULL;
+      91                 :          0 :     ctx->rs_ctx = NULL;
+      92                 :          0 : }
+      93                 :            : 
+      94                 :            : /*
+      95                 :            :  * Free the components of a restart context
+      96                 :            :  */
+      97                 :          0 : void mbedtls_pk_restart_free(mbedtls_pk_restart_ctx *ctx)
+      98                 :            : {
+      99   [ #  #  #  # ]:          0 :     if (ctx == NULL || ctx->pk_info == NULL ||
+     100         [ #  # ]:          0 :         ctx->pk_info->rs_free_func == NULL) {
+     101                 :          0 :         return;
+     102                 :            :     }
+     103                 :            : 
+     104                 :          0 :     ctx->pk_info->rs_free_func(ctx->rs_ctx);
+     105                 :            : 
+     106                 :          0 :     ctx->pk_info = NULL;
+     107                 :          0 :     ctx->rs_ctx = NULL;
+     108                 :            : }
+     109                 :            : #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
+     110                 :            : 
+     111                 :            : /*
+     112                 :            :  * Get pk_info structure from type
+     113                 :            :  */
+     114                 :      12294 : const mbedtls_pk_info_t *mbedtls_pk_info_from_type(mbedtls_pk_type_t pk_type)
+     115                 :            : {
+     116   [ +  +  -  -  :      12294 :     switch (pk_type) {
+                      - ]
+     117                 :            : #if defined(MBEDTLS_RSA_C)
+     118                 :       1127 :         case MBEDTLS_PK_RSA:
+     119                 :       1127 :             return &mbedtls_rsa_info;
+     120                 :            : #endif /* MBEDTLS_RSA_C */
+     121                 :            : #if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
+     122                 :      11167 :         case MBEDTLS_PK_ECKEY:
+     123                 :      11167 :             return &mbedtls_eckey_info;
+     124                 :          0 :         case MBEDTLS_PK_ECKEY_DH:
+     125                 :          0 :             return &mbedtls_eckeydh_info;
+     126                 :            : #endif /* MBEDTLS_PK_HAVE_ECC_KEYS */
+     127                 :            : #if defined(MBEDTLS_PK_CAN_ECDSA_SOME)
+     128                 :          0 :         case MBEDTLS_PK_ECDSA:
+     129                 :          0 :             return &mbedtls_ecdsa_info;
+     130                 :            : #endif /* MBEDTLS_PK_CAN_ECDSA_SOME */
+     131                 :            :         /* MBEDTLS_PK_RSA_ALT omitted on purpose */
+     132                 :          0 :         default:
+     133                 :          0 :             return NULL;
+     134                 :            :     }
+     135                 :            : }
+     136                 :            : 
+     137                 :            : /*
+     138                 :            :  * Initialise context
+     139                 :            :  */
+     140                 :      12294 : int mbedtls_pk_setup(mbedtls_pk_context *ctx, const mbedtls_pk_info_t *info)
+     141                 :            : {
+     142   [ +  -  -  + ]:      12294 :     if (info == NULL || ctx->pk_info != NULL) {
+     143                 :          0 :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+     144                 :            :     }
+     145                 :            : 
+     146         [ +  - ]:      12294 :     if ((info->ctx_alloc_func != NULL) &&
+     147         [ -  + ]:      12294 :         ((ctx->pk_ctx = info->ctx_alloc_func()) == NULL)) {
+     148                 :          0 :         return MBEDTLS_ERR_PK_ALLOC_FAILED;
+     149                 :            :     }
+     150                 :            : 
+     151                 :      12294 :     ctx->pk_info = info;
+     152                 :            : 
+     153                 :      12294 :     return 0;
+     154                 :            : }
+     155                 :            : 
+     156                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+     157                 :            : /*
+     158                 :            :  * Initialise a PSA-wrapping context
+     159                 :            :  */
+     160                 :            : int mbedtls_pk_setup_opaque(mbedtls_pk_context *ctx,
+     161                 :            :                             const mbedtls_svc_key_id_t key)
+     162                 :            : {
+     163                 :            :     const mbedtls_pk_info_t *info = NULL;
+     164                 :            :     psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
+     165                 :            :     psa_key_type_t type;
+     166                 :            : 
+     167                 :            :     if (ctx == NULL || ctx->pk_info != NULL) {
+     168                 :            :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+     169                 :            :     }
+     170                 :            : 
+     171                 :            :     if (PSA_SUCCESS != psa_get_key_attributes(key, &attributes)) {
+     172                 :            :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+     173                 :            :     }
+     174                 :            :     type = psa_get_key_type(&attributes);
+     175                 :            :     psa_reset_key_attributes(&attributes);
+     176                 :            : 
+     177                 :            : #if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
+     178                 :            :     if (PSA_KEY_TYPE_IS_ECC_KEY_PAIR(type)) {
+     179                 :            :         info = &mbedtls_ecdsa_opaque_info;
+     180                 :            :     } else
+     181                 :            : #endif /* MBEDTLS_PK_HAVE_ECC_KEYS */
+     182                 :            :     if (type == PSA_KEY_TYPE_RSA_KEY_PAIR) {
+     183                 :            :         info = &mbedtls_rsa_opaque_info;
+     184                 :            :     } else {
+     185                 :            :         return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE;
+     186                 :            :     }
+     187                 :            : 
+     188                 :            :     ctx->pk_info = info;
+     189                 :            :     ctx->priv_id = key;
+     190                 :            : 
+     191                 :            :     return 0;
+     192                 :            : }
+     193                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO */
+     194                 :            : 
+     195                 :            : #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
+     196                 :            : /*
+     197                 :            :  * Initialize an RSA-alt context
+     198                 :            :  */
+     199                 :            : int mbedtls_pk_setup_rsa_alt(mbedtls_pk_context *ctx, void *key,
+     200                 :            :                              mbedtls_pk_rsa_alt_decrypt_func decrypt_func,
+     201                 :            :                              mbedtls_pk_rsa_alt_sign_func sign_func,
+     202                 :            :                              mbedtls_pk_rsa_alt_key_len_func key_len_func)
+     203                 :            : {
+     204                 :            :     mbedtls_rsa_alt_context *rsa_alt;
+     205                 :            :     const mbedtls_pk_info_t *info = &mbedtls_rsa_alt_info;
+     206                 :            : 
+     207                 :            :     if (ctx->pk_info != NULL) {
+     208                 :            :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+     209                 :            :     }
+     210                 :            : 
+     211                 :            :     if ((ctx->pk_ctx = info->ctx_alloc_func()) == NULL) {
+     212                 :            :         return MBEDTLS_ERR_PK_ALLOC_FAILED;
+     213                 :            :     }
+     214                 :            : 
+     215                 :            :     ctx->pk_info = info;
+     216                 :            : 
+     217                 :            :     rsa_alt = (mbedtls_rsa_alt_context *) ctx->pk_ctx;
+     218                 :            : 
+     219                 :            :     rsa_alt->key = key;
+     220                 :            :     rsa_alt->decrypt_func = decrypt_func;
+     221                 :            :     rsa_alt->sign_func = sign_func;
+     222                 :            :     rsa_alt->key_len_func = key_len_func;
+     223                 :            : 
+     224                 :            :     return 0;
+     225                 :            : }
+     226                 :            : #endif /* MBEDTLS_PK_RSA_ALT_SUPPORT */
+     227                 :            : 
+     228                 :            : /*
+     229                 :            :  * Tell if a PK can do the operations of the given type
+     230                 :            :  */
+     231                 :       3188 : int mbedtls_pk_can_do(const mbedtls_pk_context *ctx, mbedtls_pk_type_t type)
+     232                 :            : {
+     233                 :            :     /* A context with null pk_info is not set up yet and can't do anything.
+     234                 :            :      * For backward compatibility, also accept NULL instead of a context
+     235                 :            :      * pointer. */
+     236   [ +  -  -  + ]:       3188 :     if (ctx == NULL || ctx->pk_info == NULL) {
+     237                 :          0 :         return 0;
+     238                 :            :     }
+     239                 :            : 
+     240                 :       3188 :     return ctx->pk_info->can_do(type);
+     241                 :            : }
+     242                 :            : 
+     243                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+     244                 :            : /*
+     245                 :            :  * Tell if a PK can do the operations of the given PSA algorithm
+     246                 :            :  */
+     247                 :            : int mbedtls_pk_can_do_ext(const mbedtls_pk_context *ctx, psa_algorithm_t alg,
+     248                 :            :                           psa_key_usage_t usage)
+     249                 :            : {
+     250                 :            :     psa_key_usage_t key_usage;
+     251                 :            : 
+     252                 :            :     /* A context with null pk_info is not set up yet and can't do anything.
+     253                 :            :      * For backward compatibility, also accept NULL instead of a context
+     254                 :            :      * pointer. */
+     255                 :            :     if (ctx == NULL || ctx->pk_info == NULL) {
+     256                 :            :         return 0;
+     257                 :            :     }
+     258                 :            : 
+     259                 :            :     /* Filter out non allowed algorithms */
+     260                 :            :     if (PSA_ALG_IS_ECDSA(alg) == 0 &&
+     261                 :            :         PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg) == 0 &&
+     262                 :            :         PSA_ALG_IS_RSA_PSS(alg) == 0 &&
+     263                 :            :         alg != PSA_ALG_RSA_PKCS1V15_CRYPT &&
+     264                 :            :         PSA_ALG_IS_ECDH(alg) == 0) {
+     265                 :            :         return 0;
+     266                 :            :     }
+     267                 :            : 
+     268                 :            :     /* Filter out non allowed usage flags */
+     269                 :            :     if (usage == 0 ||
+     270                 :            :         (usage & ~(PSA_KEY_USAGE_SIGN_HASH |
+     271                 :            :                    PSA_KEY_USAGE_DECRYPT |
+     272                 :            :                    PSA_KEY_USAGE_DERIVE)) != 0) {
+     273                 :            :         return 0;
+     274                 :            :     }
+     275                 :            : 
+     276                 :            :     /* Wildcard hash is not allowed */
+     277                 :            :     if (PSA_ALG_IS_SIGN_HASH(alg) &&
+     278                 :            :         PSA_ALG_SIGN_GET_HASH(alg) == PSA_ALG_ANY_HASH) {
+     279                 :            :         return 0;
+     280                 :            :     }
+     281                 :            : 
+     282                 :            :     if (mbedtls_pk_get_type(ctx) != MBEDTLS_PK_OPAQUE) {
+     283                 :            :         mbedtls_pk_type_t type;
+     284                 :            : 
+     285                 :            :         if (PSA_ALG_IS_ECDSA(alg) || PSA_ALG_IS_ECDH(alg)) {
+     286                 :            :             type = MBEDTLS_PK_ECKEY;
+     287                 :            :         } else if (PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg) ||
+     288                 :            :                    alg == PSA_ALG_RSA_PKCS1V15_CRYPT) {
+     289                 :            :             type = MBEDTLS_PK_RSA;
+     290                 :            :         } else if (PSA_ALG_IS_RSA_PSS(alg)) {
+     291                 :            :             type = MBEDTLS_PK_RSASSA_PSS;
+     292                 :            :         } else {
+     293                 :            :             return 0;
+     294                 :            :         }
+     295                 :            : 
+     296                 :            :         if (ctx->pk_info->can_do(type) == 0) {
+     297                 :            :             return 0;
+     298                 :            :         }
+     299                 :            : 
+     300                 :            :         switch (type) {
+     301                 :            :             case MBEDTLS_PK_ECKEY:
+     302                 :            :                 key_usage = PSA_KEY_USAGE_SIGN_HASH | PSA_KEY_USAGE_DERIVE;
+     303                 :            :                 break;
+     304                 :            :             case MBEDTLS_PK_RSA:
+     305                 :            :             case MBEDTLS_PK_RSASSA_PSS:
+     306                 :            :                 key_usage = PSA_KEY_USAGE_SIGN_HASH |
+     307                 :            :                             PSA_KEY_USAGE_SIGN_MESSAGE |
+     308                 :            :                             PSA_KEY_USAGE_DECRYPT;
+     309                 :            :                 break;
+     310                 :            :             default:
+     311                 :            :                 /* Should never happen */
+     312                 :            :                 return 0;
+     313                 :            :         }
+     314                 :            : 
+     315                 :            :         return (key_usage & usage) == usage;
+     316                 :            :     }
+     317                 :            : 
+     318                 :            :     psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
+     319                 :            :     psa_status_t status;
+     320                 :            : 
+     321                 :            :     status = psa_get_key_attributes(ctx->priv_id, &attributes);
+     322                 :            :     if (status != PSA_SUCCESS) {
+     323                 :            :         return 0;
+     324                 :            :     }
+     325                 :            : 
+     326                 :            :     psa_algorithm_t key_alg = psa_get_key_algorithm(&attributes);
+     327                 :            :     /* Key's enrollment is available only when an Mbed TLS implementation of PSA
+     328                 :            :      * Crypto is being used, i.e. when MBEDTLS_PSA_CRYPTO_C is defined.
+     329                 :            :      * Even though we don't officially support using other implementations of PSA
+     330                 :            :      * Crypto with TLS and X.509 (yet), we try to keep vendor's customizations
+     331                 :            :      * separated. */
+     332                 :            : #if defined(MBEDTLS_PSA_CRYPTO_C)
+     333                 :            :     psa_algorithm_t key_alg2 = psa_get_key_enrollment_algorithm(&attributes);
+     334                 :            : #endif /* MBEDTLS_PSA_CRYPTO_C */
+     335                 :            :     key_usage = psa_get_key_usage_flags(&attributes);
+     336                 :            :     psa_reset_key_attributes(&attributes);
+     337                 :            : 
+     338                 :            :     if ((key_usage & usage) != usage) {
+     339                 :            :         return 0;
+     340                 :            :     }
+     341                 :            : 
+     342                 :            :     /*
+     343                 :            :      * Common case: the key alg [or alg2] only allows alg.
+     344                 :            :      * This will match PSA_ALG_RSA_PKCS1V15_CRYPT & PSA_ALG_IS_ECDH
+     345                 :            :      * directly.
+     346                 :            :      * This would also match ECDSA/RSA_PKCS1V15_SIGN/RSA_PSS with
+     347                 :            :      * a fixed hash on key_alg [or key_alg2].
+     348                 :            :      */
+     349                 :            :     if (alg == key_alg) {
+     350                 :            :         return 1;
+     351                 :            :     }
+     352                 :            : #if defined(MBEDTLS_PSA_CRYPTO_C)
+     353                 :            :     if (alg == key_alg2) {
+     354                 :            :         return 1;
+     355                 :            :     }
+     356                 :            : #endif /* MBEDTLS_PSA_CRYPTO_C */
+     357                 :            : 
+     358                 :            :     /*
+     359                 :            :      * If key_alg [or key_alg2] is a hash-and-sign with a wildcard for the hash,
+     360                 :            :      * and alg is the same hash-and-sign family with any hash,
+     361                 :            :      * then alg is compliant with this key alg
+     362                 :            :      */
+     363                 :            :     if (PSA_ALG_IS_SIGN_HASH(alg)) {
+     364                 :            :         if (PSA_ALG_IS_SIGN_HASH(key_alg) &&
+     365                 :            :             PSA_ALG_SIGN_GET_HASH(key_alg) == PSA_ALG_ANY_HASH &&
+     366                 :            :             (alg & ~PSA_ALG_HASH_MASK) == (key_alg & ~PSA_ALG_HASH_MASK)) {
+     367                 :            :             return 1;
+     368                 :            :         }
+     369                 :            : #if defined(MBEDTLS_PSA_CRYPTO_C)
+     370                 :            :         if (PSA_ALG_IS_SIGN_HASH(key_alg2) &&
+     371                 :            :             PSA_ALG_SIGN_GET_HASH(key_alg2) == PSA_ALG_ANY_HASH &&
+     372                 :            :             (alg & ~PSA_ALG_HASH_MASK) == (key_alg2 & ~PSA_ALG_HASH_MASK)) {
+     373                 :            :             return 1;
+     374                 :            :         }
+     375                 :            : #endif /* MBEDTLS_PSA_CRYPTO_C */
+     376                 :            :     }
+     377                 :            : 
+     378                 :            :     return 0;
+     379                 :            : }
+     380                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO */
+     381                 :            : 
+     382                 :            : #if defined(MBEDTLS_PSA_CRYPTO_CLIENT)
+     383                 :            : #if defined(MBEDTLS_RSA_C)
+     384                 :            : static psa_algorithm_t psa_algorithm_for_rsa(const mbedtls_rsa_context *rsa,
+     385                 :            :                                              int want_crypt)
+     386                 :            : {
+     387                 :            :     if (mbedtls_rsa_get_padding_mode(rsa) == MBEDTLS_RSA_PKCS_V21) {
+     388                 :            :         if (want_crypt) {
+     389                 :            :             mbedtls_md_type_t md_type = (mbedtls_md_type_t) mbedtls_rsa_get_md_alg(rsa);
+     390                 :            :             return PSA_ALG_RSA_OAEP(mbedtls_md_psa_alg_from_type(md_type));
+     391                 :            :         } else {
+     392                 :            :             return PSA_ALG_RSA_PSS_ANY_SALT(PSA_ALG_ANY_HASH);
+     393                 :            :         }
+     394                 :            :     } else {
+     395                 :            :         if (want_crypt) {
+     396                 :            :             return PSA_ALG_RSA_PKCS1V15_CRYPT;
+     397                 :            :         } else {
+     398                 :            :             return PSA_ALG_RSA_PKCS1V15_SIGN(PSA_ALG_ANY_HASH);
+     399                 :            :         }
+     400                 :            :     }
+     401                 :            : }
+     402                 :            : #endif /* MBEDTLS_RSA_C */
+     403                 :            : 
+     404                 :            : int mbedtls_pk_get_psa_attributes(const mbedtls_pk_context *pk,
+     405                 :            :                                   psa_key_usage_t usage,
+     406                 :            :                                   psa_key_attributes_t *attributes)
+     407                 :            : {
+     408                 :            :     mbedtls_pk_type_t pk_type = mbedtls_pk_get_type(pk);
+     409                 :            : 
+     410                 :            :     psa_key_usage_t more_usage = usage;
+     411                 :            :     if (usage == PSA_KEY_USAGE_SIGN_MESSAGE) {
+     412                 :            :         more_usage |= PSA_KEY_USAGE_VERIFY_MESSAGE;
+     413                 :            :     } else if (usage == PSA_KEY_USAGE_SIGN_HASH) {
+     414                 :            :         more_usage |= PSA_KEY_USAGE_VERIFY_HASH;
+     415                 :            :     } else if (usage == PSA_KEY_USAGE_DECRYPT) {
+     416                 :            :         more_usage |= PSA_KEY_USAGE_ENCRYPT;
+     417                 :            :     }
+     418                 :            :     more_usage |= PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_COPY;
+     419                 :            : 
+     420                 :            :     int want_private = !(usage == PSA_KEY_USAGE_VERIFY_MESSAGE ||
+     421                 :            :                          usage == PSA_KEY_USAGE_VERIFY_HASH ||
+     422                 :            :                          usage == PSA_KEY_USAGE_ENCRYPT);
+     423                 :            : 
+     424                 :            :     switch (pk_type) {
+     425                 :            : #if defined(MBEDTLS_RSA_C)
+     426                 :            :         case MBEDTLS_PK_RSA:
+     427                 :            :         {
+     428                 :            :             int want_crypt = 0; /* 0: sign/verify; 1: encrypt/decrypt */
+     429                 :            :             switch (usage) {
+     430                 :            :                 case PSA_KEY_USAGE_SIGN_MESSAGE:
+     431                 :            :                 case PSA_KEY_USAGE_SIGN_HASH:
+     432                 :            :                 case PSA_KEY_USAGE_VERIFY_MESSAGE:
+     433                 :            :                 case PSA_KEY_USAGE_VERIFY_HASH:
+     434                 :            :                     /* Nothing to do. */
+     435                 :            :                     break;
+     436                 :            :                 case PSA_KEY_USAGE_DECRYPT:
+     437                 :            :                 case PSA_KEY_USAGE_ENCRYPT:
+     438                 :            :                     want_crypt = 1;
+     439                 :            :                     break;
+     440                 :            :                 default:
+     441                 :            :                     return MBEDTLS_ERR_PK_TYPE_MISMATCH;
+     442                 :            :             }
+     443                 :            :             /* Detect the presence of a private key in a way that works both
+     444                 :            :              * in CRT and non-CRT configurations. */
+     445                 :            :             mbedtls_rsa_context *rsa = mbedtls_pk_rsa(*pk);
+     446                 :            :             int has_private = (mbedtls_rsa_check_privkey(rsa) == 0);
+     447                 :            :             if (want_private && !has_private) {
+     448                 :            :                 return MBEDTLS_ERR_PK_TYPE_MISMATCH;
+     449                 :            :             }
+     450                 :            :             psa_set_key_type(attributes, (want_private ?
+     451                 :            :                                           PSA_KEY_TYPE_RSA_KEY_PAIR :
+     452                 :            :                                           PSA_KEY_TYPE_RSA_PUBLIC_KEY));
+     453                 :            :             psa_set_key_bits(attributes, mbedtls_pk_get_bitlen(pk));
+     454                 :            :             psa_set_key_algorithm(attributes,
+     455                 :            :                                   psa_algorithm_for_rsa(rsa, want_crypt));
+     456                 :            :             break;
+     457                 :            :         }
+     458                 :            : #endif /* MBEDTLS_RSA_C */
+     459                 :            : 
+     460                 :            : #if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
+     461                 :            :         case MBEDTLS_PK_ECKEY:
+     462                 :            :         case MBEDTLS_PK_ECKEY_DH:
+     463                 :            :         case MBEDTLS_PK_ECDSA:
+     464                 :            :         {
+     465                 :            :             int sign_ok = (pk_type != MBEDTLS_PK_ECKEY_DH);
+     466                 :            :             int derive_ok = (pk_type != MBEDTLS_PK_ECDSA);
+     467                 :            : #if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
+     468                 :            :             psa_ecc_family_t family = pk->ec_family;
+     469                 :            :             size_t bits = pk->ec_bits;
+     470                 :            :             int has_private = 0;
+     471                 :            :             if (pk->priv_id != MBEDTLS_SVC_KEY_ID_INIT) {
+     472                 :            :                 has_private = 1;
+     473                 :            :             }
+     474                 :            : #else
+     475                 :            :             const mbedtls_ecp_keypair *ec = mbedtls_pk_ec_ro(*pk);
+     476                 :            :             int has_private = (ec->d.n != 0);
+     477                 :            :             size_t bits = 0;
+     478                 :            :             psa_ecc_family_t family =
+     479                 :            :                 mbedtls_ecc_group_to_psa(ec->grp.id, &bits);
+     480                 :            : #endif
+     481                 :            :             psa_algorithm_t alg = 0;
+     482                 :            :             switch (usage) {
+     483                 :            :                 case PSA_KEY_USAGE_SIGN_MESSAGE:
+     484                 :            :                 case PSA_KEY_USAGE_SIGN_HASH:
+     485                 :            :                 case PSA_KEY_USAGE_VERIFY_MESSAGE:
+     486                 :            :                 case PSA_KEY_USAGE_VERIFY_HASH:
+     487                 :            :                     if (!sign_ok) {
+     488                 :            :                         return MBEDTLS_ERR_PK_TYPE_MISMATCH;
+     489                 :            :                     }
+     490                 :            : #if defined(MBEDTLS_ECDSA_DETERMINISTIC)
+     491                 :            :                     alg = PSA_ALG_DETERMINISTIC_ECDSA(PSA_ALG_ANY_HASH);
+     492                 :            : #else
+     493                 :            :                     alg = PSA_ALG_ECDSA(PSA_ALG_ANY_HASH);
+     494                 :            : #endif
+     495                 :            :                     break;
+     496                 :            :                 case PSA_KEY_USAGE_DERIVE:
+     497                 :            :                     alg = PSA_ALG_ECDH;
+     498                 :            :                     if (!derive_ok) {
+     499                 :            :                         return MBEDTLS_ERR_PK_TYPE_MISMATCH;
+     500                 :            :                     }
+     501                 :            :                     break;
+     502                 :            :                 default:
+     503                 :            :                     return MBEDTLS_ERR_PK_TYPE_MISMATCH;
+     504                 :            :             }
+     505                 :            :             if (want_private && !has_private) {
+     506                 :            :                 return MBEDTLS_ERR_PK_TYPE_MISMATCH;
+     507                 :            :             }
+     508                 :            :             psa_set_key_type(attributes, (want_private ?
+     509                 :            :                                           PSA_KEY_TYPE_ECC_KEY_PAIR(family) :
+     510                 :            :                                           PSA_KEY_TYPE_ECC_PUBLIC_KEY(family)));
+     511                 :            :             psa_set_key_bits(attributes, bits);
+     512                 :            :             psa_set_key_algorithm(attributes, alg);
+     513                 :            :             break;
+     514                 :            :         }
+     515                 :            : #endif /* MBEDTLS_PK_HAVE_ECC_KEYS */
+     516                 :            : 
+     517                 :            : #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
+     518                 :            :         case MBEDTLS_PK_RSA_ALT:
+     519                 :            :             return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE;
+     520                 :            : #endif /* MBEDTLS_PK_RSA_ALT_SUPPORT */
+     521                 :            : 
+     522                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+     523                 :            :         case MBEDTLS_PK_OPAQUE:
+     524                 :            :         {
+     525                 :            :             psa_key_attributes_t old_attributes = PSA_KEY_ATTRIBUTES_INIT;
+     526                 :            :             psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
+     527                 :            :             status = psa_get_key_attributes(pk->priv_id, &old_attributes);
+     528                 :            :             if (status != PSA_SUCCESS) {
+     529                 :            :                 return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+     530                 :            :             }
+     531                 :            :             psa_key_type_t old_type = psa_get_key_type(&old_attributes);
+     532                 :            :             switch (usage) {
+     533                 :            :                 case PSA_KEY_USAGE_SIGN_MESSAGE:
+     534                 :            :                 case PSA_KEY_USAGE_SIGN_HASH:
+     535                 :            :                 case PSA_KEY_USAGE_VERIFY_MESSAGE:
+     536                 :            :                 case PSA_KEY_USAGE_VERIFY_HASH:
+     537                 :            :                     if (!(PSA_KEY_TYPE_IS_ECC_KEY_PAIR(old_type) ||
+     538                 :            :                           old_type == PSA_KEY_TYPE_RSA_KEY_PAIR)) {
+     539                 :            :                         return MBEDTLS_ERR_PK_TYPE_MISMATCH;
+     540                 :            :                     }
+     541                 :            :                     break;
+     542                 :            :                 case PSA_KEY_USAGE_DECRYPT:
+     543                 :            :                 case PSA_KEY_USAGE_ENCRYPT:
+     544                 :            :                     if (old_type != PSA_KEY_TYPE_RSA_KEY_PAIR) {
+     545                 :            :                         return MBEDTLS_ERR_PK_TYPE_MISMATCH;
+     546                 :            :                     }
+     547                 :            :                     break;
+     548                 :            :                 case PSA_KEY_USAGE_DERIVE:
+     549                 :            :                     if (!(PSA_KEY_TYPE_IS_ECC_KEY_PAIR(old_type))) {
+     550                 :            :                         return MBEDTLS_ERR_PK_TYPE_MISMATCH;
+     551                 :            :                     }
+     552                 :            :                     break;
+     553                 :            :                 default:
+     554                 :            :                     return MBEDTLS_ERR_PK_TYPE_MISMATCH;
+     555                 :            :             }
+     556                 :            :             psa_key_type_t new_type = old_type;
+     557                 :            :             /* Opaque keys are always key pairs, so we don't need a check
+     558                 :            :              * on the input if the required usage is private. We just need
+     559                 :            :              * to adjust the type correctly if the required usage is public. */
+     560                 :            :             if (!want_private) {
+     561                 :            :                 new_type = PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(new_type);
+     562                 :            :             }
+     563                 :            :             more_usage = psa_get_key_usage_flags(&old_attributes);
+     564                 :            :             if ((usage & more_usage) == 0) {
+     565                 :            :                 return MBEDTLS_ERR_PK_TYPE_MISMATCH;
+     566                 :            :             }
+     567                 :            :             psa_set_key_type(attributes, new_type);
+     568                 :            :             psa_set_key_bits(attributes, psa_get_key_bits(&old_attributes));
+     569                 :            :             psa_set_key_algorithm(attributes, psa_get_key_algorithm(&old_attributes));
+     570                 :            :             break;
+     571                 :            :         }
+     572                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO */
+     573                 :            : 
+     574                 :            :         default:
+     575                 :            :             return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+     576                 :            :     }
+     577                 :            : 
+     578                 :            :     psa_set_key_usage_flags(attributes, more_usage);
+     579                 :            :     /* Key's enrollment is available only when an Mbed TLS implementation of PSA
+     580                 :            :      * Crypto is being used, i.e. when MBEDTLS_PSA_CRYPTO_C is defined.
+     581                 :            :      * Even though we don't officially support using other implementations of PSA
+     582                 :            :      * Crypto with TLS and X.509 (yet), we try to keep vendor's customizations
+     583                 :            :      * separated. */
+     584                 :            : #if defined(MBEDTLS_PSA_CRYPTO_C)
+     585                 :            :     psa_set_key_enrollment_algorithm(attributes, PSA_ALG_NONE);
+     586                 :            : #endif
+     587                 :            : 
+     588                 :            :     return 0;
+     589                 :            : }
+     590                 :            : 
+     591                 :            : #if defined(MBEDTLS_PK_USE_PSA_EC_DATA) || defined(MBEDTLS_USE_PSA_CRYPTO)
+     592                 :            : static psa_status_t export_import_into_psa(mbedtls_svc_key_id_t old_key_id,
+     593                 :            :                                            const psa_key_attributes_t *attributes,
+     594                 :            :                                            mbedtls_svc_key_id_t *new_key_id)
+     595                 :            : {
+     596                 :            :     unsigned char key_buffer[PSA_EXPORT_KEY_PAIR_MAX_SIZE];
+     597                 :            :     size_t key_length = 0;
+     598                 :            :     psa_status_t status = psa_export_key(old_key_id,
+     599                 :            :                                          key_buffer, sizeof(key_buffer),
+     600                 :            :                                          &key_length);
+     601                 :            :     if (status != PSA_SUCCESS) {
+     602                 :            :         return status;
+     603                 :            :     }
+     604                 :            :     status = psa_import_key(attributes, key_buffer, key_length, new_key_id);
+     605                 :            :     mbedtls_platform_zeroize(key_buffer, key_length);
+     606                 :            :     return status;
+     607                 :            : }
+     608                 :            : 
+     609                 :            : static int copy_into_psa(mbedtls_svc_key_id_t old_key_id,
+     610                 :            :                          const psa_key_attributes_t *attributes,
+     611                 :            :                          mbedtls_svc_key_id_t *new_key_id)
+     612                 :            : {
+     613                 :            :     /* Normally, we prefer copying: it's more efficient and works even
+     614                 :            :      * for non-exportable keys. */
+     615                 :            :     psa_status_t status = psa_copy_key(old_key_id, attributes, new_key_id);
+     616                 :            :     if (status == PSA_ERROR_NOT_PERMITTED /*missing COPY usage*/ ||
+     617                 :            :         status == PSA_ERROR_INVALID_ARGUMENT /*incompatible policy*/) {
+     618                 :            :         /* There are edge cases where copying won't work, but export+import
+     619                 :            :          * might:
+     620                 :            :          * - If the old key does not allow PSA_KEY_USAGE_COPY.
+     621                 :            :          * - If the old key's usage does not allow what attributes wants.
+     622                 :            :          *   Because the key was intended for use in the pk module, and may
+     623                 :            :          *   have had a policy chosen solely for what pk needs rather than
+     624                 :            :          *   based on a detailed understanding of PSA policies, we are a bit
+     625                 :            :          *   more liberal than psa_copy_key() here.
+     626                 :            :          */
+     627                 :            :         /* Here we need to check that the types match, otherwise we risk
+     628                 :            :          * importing nonsensical data. */
+     629                 :            :         psa_key_attributes_t old_attributes = PSA_KEY_ATTRIBUTES_INIT;
+     630                 :            :         status = psa_get_key_attributes(old_key_id, &old_attributes);
+     631                 :            :         if (status != PSA_SUCCESS) {
+     632                 :            :             return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+     633                 :            :         }
+     634                 :            :         psa_key_type_t old_type = psa_get_key_type(&old_attributes);
+     635                 :            :         psa_reset_key_attributes(&old_attributes);
+     636                 :            :         if (old_type != psa_get_key_type(attributes)) {
+     637                 :            :             return MBEDTLS_ERR_PK_TYPE_MISMATCH;
+     638                 :            :         }
+     639                 :            :         status = export_import_into_psa(old_key_id, attributes, new_key_id);
+     640                 :            :     }
+     641                 :            :     return PSA_PK_TO_MBEDTLS_ERR(status);
+     642                 :            : }
+     643                 :            : #endif /* MBEDTLS_PK_USE_PSA_EC_DATA || MBEDTLS_USE_PSA_CRYPTO */
+     644                 :            : 
+     645                 :            : static int import_pair_into_psa(const mbedtls_pk_context *pk,
+     646                 :            :                                 const psa_key_attributes_t *attributes,
+     647                 :            :                                 mbedtls_svc_key_id_t *key_id)
+     648                 :            : {
+     649                 :            :     switch (mbedtls_pk_get_type(pk)) {
+     650                 :            : #if defined(MBEDTLS_RSA_C)
+     651                 :            :         case MBEDTLS_PK_RSA:
+     652                 :            :         {
+     653                 :            :             if (psa_get_key_type(attributes) != PSA_KEY_TYPE_RSA_KEY_PAIR) {
+     654                 :            :                 return MBEDTLS_ERR_PK_TYPE_MISMATCH;
+     655                 :            :             }
+     656                 :            :             unsigned char key_buffer[
+     657                 :            :                 PSA_KEY_EXPORT_RSA_KEY_PAIR_MAX_SIZE(PSA_VENDOR_RSA_MAX_KEY_BITS)];
+     658                 :            :             unsigned char *const key_end = key_buffer + sizeof(key_buffer);
+     659                 :            :             unsigned char *key_data = key_end;
+     660                 :            :             int ret = mbedtls_rsa_write_key(mbedtls_pk_rsa(*pk),
+     661                 :            :                                             key_buffer, &key_data);
+     662                 :            :             if (ret < 0) {
+     663                 :            :                 return ret;
+     664                 :            :             }
+     665                 :            :             size_t key_length = key_end - key_data;
+     666                 :            :             ret = PSA_PK_TO_MBEDTLS_ERR(psa_import_key(attributes,
+     667                 :            :                                                        key_data, key_length,
+     668                 :            :                                                        key_id));
+     669                 :            :             mbedtls_platform_zeroize(key_data, key_length);
+     670                 :            :             return ret;
+     671                 :            :         }
+     672                 :            : #endif /* MBEDTLS_RSA_C */
+     673                 :            : 
+     674                 :            : #if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
+     675                 :            :         case MBEDTLS_PK_ECKEY:
+     676                 :            :         case MBEDTLS_PK_ECKEY_DH:
+     677                 :            :         case MBEDTLS_PK_ECDSA:
+     678                 :            :         {
+     679                 :            :             /* We need to check the curve family, otherwise the import could
+     680                 :            :              * succeed with nonsensical data.
+     681                 :            :              * We don't check the bit-size: it's optional in attributes,
+     682                 :            :              * and if it's specified, psa_import_key() will know from the key
+     683                 :            :              * data length and will check that the bit-size matches. */
+     684                 :            :             psa_key_type_t to_type = psa_get_key_type(attributes);
+     685                 :            : #if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
+     686                 :            :             psa_ecc_family_t from_family = pk->ec_family;
+     687                 :            : #else /* MBEDTLS_PK_USE_PSA_EC_DATA */
+     688                 :            :             const mbedtls_ecp_keypair *ec = mbedtls_pk_ec_ro(*pk);
+     689                 :            :             size_t from_bits = 0;
+     690                 :            :             psa_ecc_family_t from_family = mbedtls_ecc_group_to_psa(ec->grp.id,
+     691                 :            :                                                                     &from_bits);
+     692                 :            : #endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
+     693                 :            :             if (to_type != PSA_KEY_TYPE_ECC_KEY_PAIR(from_family)) {
+     694                 :            :                 return MBEDTLS_ERR_PK_TYPE_MISMATCH;
+     695                 :            :             }
+     696                 :            : 
+     697                 :            : #if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
+     698                 :            :             if (mbedtls_svc_key_id_is_null(pk->priv_id)) {
+     699                 :            :                 /* We have a public key and want a key pair. */
+     700                 :            :                 return MBEDTLS_ERR_PK_TYPE_MISMATCH;
+     701                 :            :             }
+     702                 :            :             return copy_into_psa(pk->priv_id, attributes, key_id);
+     703                 :            : #else /* MBEDTLS_PK_USE_PSA_EC_DATA */
+     704                 :            :             if (ec->d.n == 0) {
+     705                 :            :                 /* Private key not set. Assume the input is a public key only.
+     706                 :            :                  * (The other possibility is that it's an incomplete object
+     707                 :            :                  * where the group is set but neither the public key nor
+     708                 :            :                  * the private key. This is not possible through ecp.h
+     709                 :            :                  * functions, so we don't bother reporting a more suitable
+     710                 :            :                  * error in that case.) */
+     711                 :            :                 return MBEDTLS_ERR_PK_TYPE_MISMATCH;
+     712                 :            :             }
+     713                 :            :             unsigned char key_buffer[PSA_BITS_TO_BYTES(PSA_VENDOR_ECC_MAX_CURVE_BITS)];
+     714                 :            :             size_t key_length = 0;
+     715                 :            :             int ret = mbedtls_ecp_write_key_ext(ec, &key_length,
+     716                 :            :                                                 key_buffer, sizeof(key_buffer));
+     717                 :            :             if (ret < 0) {
+     718                 :            :                 return ret;
+     719                 :            :             }
+     720                 :            :             ret = PSA_PK_TO_MBEDTLS_ERR(psa_import_key(attributes,
+     721                 :            :                                                        key_buffer, key_length,
+     722                 :            :                                                        key_id));
+     723                 :            :             mbedtls_platform_zeroize(key_buffer, key_length);
+     724                 :            :             return ret;
+     725                 :            : #endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
+     726                 :            :         }
+     727                 :            : #endif /* MBEDTLS_PK_HAVE_ECC_KEYS */
+     728                 :            : 
+     729                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+     730                 :            :         case MBEDTLS_PK_OPAQUE:
+     731                 :            :             return copy_into_psa(pk->priv_id, attributes, key_id);
+     732                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO */
+     733                 :            : 
+     734                 :            :         default:
+     735                 :            :             return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+     736                 :            :     }
+     737                 :            : }
+     738                 :            : 
+     739                 :            : static int import_public_into_psa(const mbedtls_pk_context *pk,
+     740                 :            :                                   const psa_key_attributes_t *attributes,
+     741                 :            :                                   mbedtls_svc_key_id_t *key_id)
+     742                 :            : {
+     743                 :            :     psa_key_type_t psa_type = psa_get_key_type(attributes);
+     744                 :            : 
+     745                 :            : #if defined(MBEDTLS_RSA_C) ||                                           \
+     746                 :            :     (defined(MBEDTLS_PK_HAVE_ECC_KEYS) && !defined(MBEDTLS_PK_USE_PSA_EC_DATA)) || \
+     747                 :            :     defined(MBEDTLS_USE_PSA_CRYPTO)
+     748                 :            :     unsigned char key_buffer[PSA_EXPORT_PUBLIC_KEY_MAX_SIZE];
+     749                 :            : #endif
+     750                 :            :     unsigned char *key_data = NULL;
+     751                 :            :     size_t key_length = 0;
+     752                 :            : 
+     753                 :            :     switch (mbedtls_pk_get_type(pk)) {
+     754                 :            : #if defined(MBEDTLS_RSA_C)
+     755                 :            :         case MBEDTLS_PK_RSA:
+     756                 :            :         {
+     757                 :            :             if (psa_type != PSA_KEY_TYPE_RSA_PUBLIC_KEY) {
+     758                 :            :                 return MBEDTLS_ERR_PK_TYPE_MISMATCH;
+     759                 :            :             }
+     760                 :            :             unsigned char *const key_end = key_buffer + sizeof(key_buffer);
+     761                 :            :             key_data = key_end;
+     762                 :            :             int ret = mbedtls_rsa_write_pubkey(mbedtls_pk_rsa(*pk),
+     763                 :            :                                                key_buffer, &key_data);
+     764                 :            :             if (ret < 0) {
+     765                 :            :                 return ret;
+     766                 :            :             }
+     767                 :            :             key_length = (size_t) ret;
+     768                 :            :             break;
+     769                 :            :         }
+     770                 :            : #endif /*MBEDTLS_RSA_C */
+     771                 :            : 
+     772                 :            : #if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
+     773                 :            :         case MBEDTLS_PK_ECKEY:
+     774                 :            :         case MBEDTLS_PK_ECKEY_DH:
+     775                 :            :         case MBEDTLS_PK_ECDSA:
+     776                 :            :         {
+     777                 :            :             /* We need to check the curve family, otherwise the import could
+     778                 :            :              * succeed with nonsensical data.
+     779                 :            :              * We don't check the bit-size: it's optional in attributes,
+     780                 :            :              * and if it's specified, psa_import_key() will know from the key
+     781                 :            :              * data length and will check that the bit-size matches. */
+     782                 :            : #if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
+     783                 :            :             if (psa_type != PSA_KEY_TYPE_ECC_PUBLIC_KEY(pk->ec_family)) {
+     784                 :            :                 return MBEDTLS_ERR_PK_TYPE_MISMATCH;
+     785                 :            :             }
+     786                 :            :             key_data = (unsigned char *) pk->pub_raw;
+     787                 :            :             key_length = pk->pub_raw_len;
+     788                 :            : #else /* MBEDTLS_PK_USE_PSA_EC_DATA */
+     789                 :            :             const mbedtls_ecp_keypair *ec = mbedtls_pk_ec_ro(*pk);
+     790                 :            :             size_t from_bits = 0;
+     791                 :            :             psa_ecc_family_t from_family = mbedtls_ecc_group_to_psa(ec->grp.id,
+     792                 :            :                                                                     &from_bits);
+     793                 :            :             if (psa_type != PSA_KEY_TYPE_ECC_PUBLIC_KEY(from_family)) {
+     794                 :            :                 return MBEDTLS_ERR_PK_TYPE_MISMATCH;
+     795                 :            :             }
+     796                 :            :             int ret = mbedtls_ecp_write_public_key(
+     797                 :            :                 ec, MBEDTLS_ECP_PF_UNCOMPRESSED,
+     798                 :            :                 &key_length, key_buffer, sizeof(key_buffer));
+     799                 :            :             if (ret < 0) {
+     800                 :            :                 return ret;
+     801                 :            :             }
+     802                 :            :             key_data = key_buffer;
+     803                 :            : #endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
+     804                 :            :             break;
+     805                 :            :         }
+     806                 :            : #endif /* MBEDTLS_PK_HAVE_ECC_KEYS */
+     807                 :            : 
+     808                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+     809                 :            :         case MBEDTLS_PK_OPAQUE:
+     810                 :            :         {
+     811                 :            :             psa_key_attributes_t old_attributes = PSA_KEY_ATTRIBUTES_INIT;
+     812                 :            :             psa_status_t status =
+     813                 :            :                 psa_get_key_attributes(pk->priv_id, &old_attributes);
+     814                 :            :             if (status != PSA_SUCCESS) {
+     815                 :            :                 return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+     816                 :            :             }
+     817                 :            :             psa_key_type_t old_type = psa_get_key_type(&old_attributes);
+     818                 :            :             psa_reset_key_attributes(&old_attributes);
+     819                 :            :             if (psa_type != PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(old_type)) {
+     820                 :            :                 return MBEDTLS_ERR_PK_TYPE_MISMATCH;
+     821                 :            :             }
+     822                 :            :             status = psa_export_public_key(pk->priv_id,
+     823                 :            :                                            key_buffer, sizeof(key_buffer),
+     824                 :            :                                            &key_length);
+     825                 :            :             if (status != PSA_SUCCESS) {
+     826                 :            :                 return PSA_PK_TO_MBEDTLS_ERR(status);
+     827                 :            :             }
+     828                 :            :             key_data = key_buffer;
+     829                 :            :             break;
+     830                 :            :         }
+     831                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO */
+     832                 :            : 
+     833                 :            :         default:
+     834                 :            :             return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+     835                 :            :     }
+     836                 :            : 
+     837                 :            :     return PSA_PK_TO_MBEDTLS_ERR(psa_import_key(attributes,
+     838                 :            :                                                 key_data, key_length,
+     839                 :            :                                                 key_id));
+     840                 :            : }
+     841                 :            : 
+     842                 :            : int mbedtls_pk_import_into_psa(const mbedtls_pk_context *pk,
+     843                 :            :                                const psa_key_attributes_t *attributes,
+     844                 :            :                                mbedtls_svc_key_id_t *key_id)
+     845                 :            : {
+     846                 :            :     /* Set the output immediately so that it won't contain garbage even
+     847                 :            :      * if we error out before calling psa_import_key(). */
+     848                 :            :     *key_id = MBEDTLS_SVC_KEY_ID_INIT;
+     849                 :            : 
+     850                 :            : #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
+     851                 :            :     if (mbedtls_pk_get_type(pk) == MBEDTLS_PK_RSA_ALT) {
+     852                 :            :         return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE;
+     853                 :            :     }
+     854                 :            : #endif /* MBEDTLS_PK_RSA_ALT_SUPPORT */
+     855                 :            : 
+     856                 :            :     int want_public = PSA_KEY_TYPE_IS_PUBLIC_KEY(psa_get_key_type(attributes));
+     857                 :            :     if (want_public) {
+     858                 :            :         return import_public_into_psa(pk, attributes, key_id);
+     859                 :            :     } else {
+     860                 :            :         return import_pair_into_psa(pk, attributes, key_id);
+     861                 :            :     }
+     862                 :            : }
+     863                 :            : 
+     864                 :            : static int copy_from_psa(mbedtls_svc_key_id_t key_id,
+     865                 :            :                          mbedtls_pk_context *pk,
+     866                 :            :                          int public_only)
+     867                 :            : {
+     868                 :            :     psa_status_t status;
+     869                 :            :     psa_key_attributes_t key_attr = PSA_KEY_ATTRIBUTES_INIT;
+     870                 :            :     psa_key_type_t key_type;
+     871                 :            :     psa_algorithm_t alg_type;
+     872                 :            :     size_t key_bits;
+     873                 :            :     /* Use a buffer size large enough to contain either a key pair or public key. */
+     874                 :            :     unsigned char exp_key[PSA_EXPORT_KEY_PAIR_OR_PUBLIC_MAX_SIZE];
+     875                 :            :     size_t exp_key_len;
+     876                 :            :     int ret = MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+     877                 :            : 
+     878                 :            :     if (pk == NULL) {
+     879                 :            :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+     880                 :            :     }
+     881                 :            : 
+     882                 :            :     status = psa_get_key_attributes(key_id, &key_attr);
+     883                 :            :     if (status != PSA_SUCCESS) {
+     884                 :            :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+     885                 :            :     }
+     886                 :            : 
+     887                 :            :     if (public_only) {
+     888                 :            :         status = psa_export_public_key(key_id, exp_key, sizeof(exp_key), &exp_key_len);
+     889                 :            :     } else {
+     890                 :            :         status = psa_export_key(key_id, exp_key, sizeof(exp_key), &exp_key_len);
+     891                 :            :     }
+     892                 :            :     if (status != PSA_SUCCESS) {
+     893                 :            :         ret = PSA_PK_TO_MBEDTLS_ERR(status);
+     894                 :            :         goto exit;
+     895                 :            :     }
+     896                 :            : 
+     897                 :            :     key_type = psa_get_key_type(&key_attr);
+     898                 :            :     if (public_only) {
+     899                 :            :         key_type = PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(key_type);
+     900                 :            :     }
+     901                 :            :     key_bits = psa_get_key_bits(&key_attr);
+     902                 :            :     alg_type = psa_get_key_algorithm(&key_attr);
+     903                 :            : 
+     904                 :            : #if defined(MBEDTLS_RSA_C)
+     905                 :            :     if ((key_type == PSA_KEY_TYPE_RSA_KEY_PAIR) ||
+     906                 :            :         (key_type == PSA_KEY_TYPE_RSA_PUBLIC_KEY)) {
+     907                 :            : 
+     908                 :            :         ret = mbedtls_pk_setup(pk, mbedtls_pk_info_from_type(MBEDTLS_PK_RSA));
+     909                 :            :         if (ret != 0) {
+     910                 :            :             goto exit;
+     911                 :            :         }
+     912                 :            : 
+     913                 :            :         if (key_type == PSA_KEY_TYPE_RSA_KEY_PAIR) {
+     914                 :            :             ret = mbedtls_rsa_parse_key(mbedtls_pk_rsa(*pk), exp_key, exp_key_len);
+     915                 :            :         } else {
+     916                 :            :             ret = mbedtls_rsa_parse_pubkey(mbedtls_pk_rsa(*pk), exp_key, exp_key_len);
+     917                 :            :         }
+     918                 :            :         if (ret != 0) {
+     919                 :            :             goto exit;
+     920                 :            :         }
+     921                 :            : 
+     922                 :            :         mbedtls_md_type_t md_type = MBEDTLS_MD_NONE;
+     923                 :            :         if (PSA_ALG_GET_HASH(alg_type) != PSA_ALG_ANY_HASH) {
+     924                 :            :             md_type = mbedtls_md_type_from_psa_alg(alg_type);
+     925                 :            :         }
+     926                 :            : 
+     927                 :            :         if (PSA_ALG_IS_RSA_OAEP(alg_type) || PSA_ALG_IS_RSA_PSS(alg_type)) {
+     928                 :            :             ret = mbedtls_rsa_set_padding(mbedtls_pk_rsa(*pk), MBEDTLS_RSA_PKCS_V21, md_type);
+     929                 :            :         } else if (PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg_type) ||
+     930                 :            :                    alg_type == PSA_ALG_RSA_PKCS1V15_CRYPT) {
+     931                 :            :             ret = mbedtls_rsa_set_padding(mbedtls_pk_rsa(*pk), MBEDTLS_RSA_PKCS_V15, md_type);
+     932                 :            :         }
+     933                 :            :         if (ret != 0) {
+     934                 :            :             goto exit;
+     935                 :            :         }
+     936                 :            :     } else
+     937                 :            : #endif /* MBEDTLS_RSA_C */
+     938                 :            : #if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
+     939                 :            :     if (PSA_KEY_TYPE_IS_ECC_KEY_PAIR(key_type) ||
+     940                 :            :         PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY(key_type)) {
+     941                 :            :         mbedtls_ecp_group_id grp_id;
+     942                 :            : 
+     943                 :            :         ret = mbedtls_pk_setup(pk, mbedtls_pk_info_from_type(MBEDTLS_PK_ECKEY));
+     944                 :            :         if (ret != 0) {
+     945                 :            :             goto exit;
+     946                 :            :         }
+     947                 :            : 
+     948                 :            :         grp_id = mbedtls_ecc_group_from_psa(PSA_KEY_TYPE_ECC_GET_FAMILY(key_type), key_bits);
+     949                 :            :         ret = mbedtls_pk_ecc_set_group(pk, grp_id);
+     950                 :            :         if (ret != 0) {
+     951                 :            :             goto exit;
+     952                 :            :         }
+     953                 :            : 
+     954                 :            :         if (PSA_KEY_TYPE_IS_ECC_KEY_PAIR(key_type)) {
+     955                 :            :             ret = mbedtls_pk_ecc_set_key(pk, exp_key, exp_key_len);
+     956                 :            :             if (ret != 0) {
+     957                 :            :                 goto exit;
+     958                 :            :             }
+     959                 :            :             ret = mbedtls_pk_ecc_set_pubkey_from_prv(pk, exp_key, exp_key_len,
+     960                 :            :                                                      mbedtls_psa_get_random,
+     961                 :            :                                                      MBEDTLS_PSA_RANDOM_STATE);
+     962                 :            :         } else {
+     963                 :            :             ret = mbedtls_pk_ecc_set_pubkey(pk, exp_key, exp_key_len);
+     964                 :            :         }
+     965                 :            :         if (ret != 0) {
+     966                 :            :             goto exit;
+     967                 :            :         }
+     968                 :            :     } else
+     969                 :            : #endif /* MBEDTLS_PK_HAVE_ECC_KEYS */
+     970                 :            :     {
+     971                 :            :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+     972                 :            :     }
+     973                 :            : 
+     974                 :            : exit:
+     975                 :            :     psa_reset_key_attributes(&key_attr);
+     976                 :            :     mbedtls_platform_zeroize(exp_key, sizeof(exp_key));
+     977                 :            : 
+     978                 :            :     return ret;
+     979                 :            : }
+     980                 :            : 
+     981                 :            : int mbedtls_pk_copy_from_psa(mbedtls_svc_key_id_t key_id,
+     982                 :            :                              mbedtls_pk_context *pk)
+     983                 :            : {
+     984                 :            :     return copy_from_psa(key_id, pk, 0);
+     985                 :            : }
+     986                 :            : 
+     987                 :            : int mbedtls_pk_copy_public_from_psa(mbedtls_svc_key_id_t key_id,
+     988                 :            :                                     mbedtls_pk_context *pk)
+     989                 :            : {
+     990                 :            :     return copy_from_psa(key_id, pk, 1);
+     991                 :            : }
+     992                 :            : #endif /* MBEDTLS_PSA_CRYPTO_CLIENT */
+     993                 :            : 
+     994                 :            : /*
+     995                 :            :  * Helper for mbedtls_pk_sign and mbedtls_pk_verify
+     996                 :            :  */
+     997                 :       1594 : static inline int pk_hashlen_helper(mbedtls_md_type_t md_alg, size_t *hash_len)
+     998                 :            : {
+     999         [ +  + ]:       1594 :     if (*hash_len != 0) {
+    1000                 :       1588 :         return 0;
+    1001                 :            :     }
+    1002                 :            : 
+    1003                 :          6 :     *hash_len = mbedtls_md_get_size_from_type(md_alg);
+    1004                 :            : 
+    1005         [ -  + ]:          6 :     if (*hash_len == 0) {
+    1006                 :          0 :         return -1;
+    1007                 :            :     }
+    1008                 :            : 
+    1009                 :          6 :     return 0;
+    1010                 :            : }
+    1011                 :            : 
+    1012                 :            : #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
+    1013                 :            : /*
+    1014                 :            :  * Helper to set up a restart context if needed
+    1015                 :            :  */
+    1016                 :          0 : static int pk_restart_setup(mbedtls_pk_restart_ctx *ctx,
+    1017                 :            :                             const mbedtls_pk_info_t *info)
+    1018                 :            : {
+    1019                 :            :     /* Don't do anything if already set up or invalid */
+    1020   [ #  #  #  # ]:          0 :     if (ctx == NULL || ctx->pk_info != NULL) {
+    1021                 :          0 :         return 0;
+    1022                 :            :     }
+    1023                 :            : 
+    1024                 :            :     /* Should never happen when we're called */
+    1025   [ #  #  #  # ]:          0 :     if (info->rs_alloc_func == NULL || info->rs_free_func == NULL) {
+    1026                 :          0 :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+    1027                 :            :     }
+    1028                 :            : 
+    1029         [ #  # ]:          0 :     if ((ctx->rs_ctx = info->rs_alloc_func()) == NULL) {
+    1030                 :          0 :         return MBEDTLS_ERR_PK_ALLOC_FAILED;
+    1031                 :            :     }
+    1032                 :            : 
+    1033                 :          0 :     ctx->pk_info = info;
+    1034                 :            : 
+    1035                 :          0 :     return 0;
+    1036                 :            : }
+    1037                 :            : #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
+    1038                 :            : 
+    1039                 :            : /*
+    1040                 :            :  * Verify a signature (restartable)
+    1041                 :            :  */
+    1042                 :       1588 : int mbedtls_pk_verify_restartable(mbedtls_pk_context *ctx,
+    1043                 :            :                                   mbedtls_md_type_t md_alg,
+    1044                 :            :                                   const unsigned char *hash, size_t hash_len,
+    1045                 :            :                                   const unsigned char *sig, size_t sig_len,
+    1046                 :            :                                   mbedtls_pk_restart_ctx *rs_ctx)
+    1047                 :            : {
+    1048   [ -  +  -  -  :       1588 :     if ((md_alg != MBEDTLS_MD_NONE || hash_len != 0) && hash == NULL) {
+                   -  + ]
+    1049                 :          0 :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+    1050                 :            :     }
+    1051                 :            : 
+    1052   [ +  -  -  + ]:       3176 :     if (ctx->pk_info == NULL ||
+    1053                 :       1588 :         pk_hashlen_helper(md_alg, &hash_len) != 0) {
+    1054                 :          0 :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+    1055                 :            :     }
+    1056                 :            : 
+    1057                 :            : #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
+    1058                 :            :     /* optimization: use non-restartable version if restart disabled */
+    1059   [ -  +  -  - ]:       1588 :     if (rs_ctx != NULL &&
+    1060                 :          0 :         mbedtls_ecp_restart_is_enabled() &&
+    1061         [ #  # ]:          0 :         ctx->pk_info->verify_rs_func != NULL) {
+    1062                 :          0 :         int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1063                 :            : 
+    1064         [ #  # ]:          0 :         if ((ret = pk_restart_setup(rs_ctx, ctx->pk_info)) != 0) {
+    1065                 :          0 :             return ret;
+    1066                 :            :         }
+    1067                 :            : 
+    1068                 :          0 :         ret = ctx->pk_info->verify_rs_func(ctx,
+    1069                 :            :                                            md_alg, hash, hash_len, sig, sig_len, rs_ctx->rs_ctx);
+    1070                 :            : 
+    1071         [ #  # ]:          0 :         if (ret != MBEDTLS_ERR_ECP_IN_PROGRESS) {
+    1072                 :          0 :             mbedtls_pk_restart_free(rs_ctx);
+    1073                 :            :         }
+    1074                 :            : 
+    1075                 :          0 :         return ret;
+    1076                 :            :     }
+    1077                 :            : #else /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
+    1078                 :            :     (void) rs_ctx;
+    1079                 :            : #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
+    1080                 :            : 
+    1081         [ -  + ]:       1588 :     if (ctx->pk_info->verify_func == NULL) {
+    1082                 :          0 :         return MBEDTLS_ERR_PK_TYPE_MISMATCH;
+    1083                 :            :     }
+    1084                 :            : 
+    1085                 :       1588 :     return ctx->pk_info->verify_func(ctx, md_alg, hash, hash_len,
+    1086                 :            :                                      sig, sig_len);
+    1087                 :            : }
+    1088                 :            : 
+    1089                 :            : /*
+    1090                 :            :  * Verify a signature
+    1091                 :            :  */
+    1092                 :       1588 : int mbedtls_pk_verify(mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg,
+    1093                 :            :                       const unsigned char *hash, size_t hash_len,
+    1094                 :            :                       const unsigned char *sig, size_t sig_len)
+    1095                 :            : {
+    1096                 :       1588 :     return mbedtls_pk_verify_restartable(ctx, md_alg, hash, hash_len,
+    1097                 :            :                                          sig, sig_len, NULL);
+    1098                 :            : }
+    1099                 :            : 
+    1100                 :            : /*
+    1101                 :            :  * Verify a signature with options
+    1102                 :            :  */
+    1103                 :       1588 : int mbedtls_pk_verify_ext(mbedtls_pk_type_t type, const void *options,
+    1104                 :            :                           mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg,
+    1105                 :            :                           const unsigned char *hash, size_t hash_len,
+    1106                 :            :                           const unsigned char *sig, size_t sig_len)
+    1107                 :            : {
+    1108   [ -  +  -  -  :       1588 :     if ((md_alg != MBEDTLS_MD_NONE || hash_len != 0) && hash == NULL) {
+                   -  + ]
+    1109                 :          0 :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+    1110                 :            :     }
+    1111                 :            : 
+    1112         [ -  + ]:       1588 :     if (ctx->pk_info == NULL) {
+    1113                 :          0 :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+    1114                 :            :     }
+    1115                 :            : 
+    1116         [ -  + ]:       1588 :     if (!mbedtls_pk_can_do(ctx, type)) {
+    1117                 :          0 :         return MBEDTLS_ERR_PK_TYPE_MISMATCH;
+    1118                 :            :     }
+    1119                 :            : 
+    1120         [ +  - ]:       1588 :     if (type != MBEDTLS_PK_RSASSA_PSS) {
+    1121                 :            :         /* General case: no options */
+    1122         [ -  + ]:       1588 :         if (options != NULL) {
+    1123                 :          0 :             return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+    1124                 :            :         }
+    1125                 :            : 
+    1126                 :       1588 :         return mbedtls_pk_verify(ctx, md_alg, hash, hash_len, sig, sig_len);
+    1127                 :            :     }
+    1128                 :            : 
+    1129                 :            :     /* Ensure the PK context is of the right type otherwise mbedtls_pk_rsa()
+    1130                 :            :      * below would return a NULL pointer. */
+    1131         [ #  # ]:          0 :     if (mbedtls_pk_get_type(ctx) != MBEDTLS_PK_RSA) {
+    1132                 :          0 :         return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE;
+    1133                 :            :     }
+    1134                 :            : 
+    1135                 :            : #if defined(MBEDTLS_RSA_C) && defined(MBEDTLS_PKCS1_V21)
+    1136                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1137                 :            :     const mbedtls_pk_rsassa_pss_options *pss_opts;
+    1138                 :            : 
+    1139                 :            : #if SIZE_MAX > UINT_MAX
+    1140   [ #  #  #  # ]:          0 :     if (md_alg == MBEDTLS_MD_NONE && UINT_MAX < hash_len) {
+    1141                 :          0 :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+    1142                 :            :     }
+    1143                 :            : #endif
+    1144                 :            : 
+    1145         [ #  # ]:          0 :     if (options == NULL) {
+    1146                 :          0 :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+    1147                 :            :     }
+    1148                 :            : 
+    1149                 :          0 :     pss_opts = (const mbedtls_pk_rsassa_pss_options *) options;
+    1150                 :            : 
+    1151                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+    1152                 :            :     if (pss_opts->mgf1_hash_id == md_alg) {
+    1153                 :            :         unsigned char buf[MBEDTLS_PK_RSA_PUB_DER_MAX_BYTES];
+    1154                 :            :         unsigned char *p;
+    1155                 :            :         int key_len;
+    1156                 :            :         size_t signature_length;
+    1157                 :            :         psa_status_t status = PSA_ERROR_DATA_CORRUPT;
+    1158                 :            :         psa_status_t destruction_status = PSA_ERROR_DATA_CORRUPT;
+    1159                 :            : 
+    1160                 :            :         psa_algorithm_t psa_md_alg = mbedtls_md_psa_alg_from_type(md_alg);
+    1161                 :            :         mbedtls_svc_key_id_t key_id = MBEDTLS_SVC_KEY_ID_INIT;
+    1162                 :            :         psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
+    1163                 :            :         psa_algorithm_t psa_sig_alg = PSA_ALG_RSA_PSS_ANY_SALT(psa_md_alg);
+    1164                 :            :         p = buf + sizeof(buf);
+    1165                 :            :         key_len = mbedtls_rsa_write_pubkey(mbedtls_pk_rsa(*ctx), buf, &p);
+    1166                 :            : 
+    1167                 :            :         if (key_len < 0) {
+    1168                 :            :             return key_len;
+    1169                 :            :         }
+    1170                 :            : 
+    1171                 :            :         psa_set_key_type(&attributes, PSA_KEY_TYPE_RSA_PUBLIC_KEY);
+    1172                 :            :         psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_VERIFY_HASH);
+    1173                 :            :         psa_set_key_algorithm(&attributes, psa_sig_alg);
+    1174                 :            : 
+    1175                 :            :         status = psa_import_key(&attributes,
+    1176                 :            :                                 buf + sizeof(buf) - key_len, key_len,
+    1177                 :            :                                 &key_id);
+    1178                 :            :         if (status != PSA_SUCCESS) {
+    1179                 :            :             psa_destroy_key(key_id);
+    1180                 :            :             return PSA_PK_TO_MBEDTLS_ERR(status);
+    1181                 :            :         }
+    1182                 :            : 
+    1183                 :            :         /* This function requires returning MBEDTLS_ERR_PK_SIG_LEN_MISMATCH
+    1184                 :            :          * on a valid signature with trailing data in a buffer, but
+    1185                 :            :          * mbedtls_psa_rsa_verify_hash requires the sig_len to be exact,
+    1186                 :            :          * so for this reason the passed sig_len is overwritten. Smaller
+    1187                 :            :          * signature lengths should not be accepted for verification. */
+    1188                 :            :         signature_length = sig_len > mbedtls_pk_get_len(ctx) ?
+    1189                 :            :                            mbedtls_pk_get_len(ctx) : sig_len;
+    1190                 :            :         status = psa_verify_hash(key_id, psa_sig_alg, hash,
+    1191                 :            :                                  hash_len, sig, signature_length);
+    1192                 :            :         destruction_status = psa_destroy_key(key_id);
+    1193                 :            : 
+    1194                 :            :         if (status == PSA_SUCCESS && sig_len > mbedtls_pk_get_len(ctx)) {
+    1195                 :            :             return MBEDTLS_ERR_PK_SIG_LEN_MISMATCH;
+    1196                 :            :         }
+    1197                 :            : 
+    1198                 :            :         if (status == PSA_SUCCESS) {
+    1199                 :            :             status = destruction_status;
+    1200                 :            :         }
+    1201                 :            : 
+    1202                 :            :         return PSA_PK_RSA_TO_MBEDTLS_ERR(status);
+    1203                 :            :     } else
+    1204                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO */
+    1205                 :            :     {
+    1206         [ #  # ]:          0 :         if (sig_len < mbedtls_pk_get_len(ctx)) {
+    1207                 :          0 :             return MBEDTLS_ERR_RSA_VERIFY_FAILED;
+    1208                 :            :         }
+    1209                 :            : 
+    1210                 :          0 :         ret = mbedtls_rsa_rsassa_pss_verify_ext(mbedtls_pk_rsa(*ctx),
+    1211                 :            :                                                 md_alg, (unsigned int) hash_len, hash,
+    1212                 :          0 :                                                 pss_opts->mgf1_hash_id,
+    1213                 :          0 :                                                 pss_opts->expected_salt_len,
+    1214                 :            :                                                 sig);
+    1215         [ #  # ]:          0 :         if (ret != 0) {
+    1216                 :          0 :             return ret;
+    1217                 :            :         }
+    1218                 :            : 
+    1219         [ #  # ]:          0 :         if (sig_len > mbedtls_pk_get_len(ctx)) {
+    1220                 :          0 :             return MBEDTLS_ERR_PK_SIG_LEN_MISMATCH;
+    1221                 :            :         }
+    1222                 :            : 
+    1223                 :          0 :         return 0;
+    1224                 :            :     }
+    1225                 :            : #else
+    1226                 :            :     return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE;
+    1227                 :            : #endif /* MBEDTLS_RSA_C && MBEDTLS_PKCS1_V21 */
+    1228                 :            : }
+    1229                 :            : 
+    1230                 :            : /*
+    1231                 :            :  * Make a signature (restartable)
+    1232                 :            :  */
+    1233                 :          6 : int mbedtls_pk_sign_restartable(mbedtls_pk_context *ctx,
+    1234                 :            :                                 mbedtls_md_type_t md_alg,
+    1235                 :            :                                 const unsigned char *hash, size_t hash_len,
+    1236                 :            :                                 unsigned char *sig, size_t sig_size, size_t *sig_len,
+    1237                 :            :                                 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
+    1238                 :            :                                 mbedtls_pk_restart_ctx *rs_ctx)
+    1239                 :            : {
+    1240   [ -  +  -  -  :          6 :     if ((md_alg != MBEDTLS_MD_NONE || hash_len != 0) && hash == NULL) {
+                   -  + ]
+    1241                 :          0 :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+    1242                 :            :     }
+    1243                 :            : 
+    1244   [ +  -  -  + ]:          6 :     if (ctx->pk_info == NULL || pk_hashlen_helper(md_alg, &hash_len) != 0) {
+    1245                 :          0 :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+    1246                 :            :     }
+    1247                 :            : 
+    1248                 :            : #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
+    1249                 :            :     /* optimization: use non-restartable version if restart disabled */
+    1250   [ -  +  -  - ]:          6 :     if (rs_ctx != NULL &&
+    1251                 :          0 :         mbedtls_ecp_restart_is_enabled() &&
+    1252         [ #  # ]:          0 :         ctx->pk_info->sign_rs_func != NULL) {
+    1253                 :          0 :         int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1254                 :            : 
+    1255         [ #  # ]:          0 :         if ((ret = pk_restart_setup(rs_ctx, ctx->pk_info)) != 0) {
+    1256                 :          0 :             return ret;
+    1257                 :            :         }
+    1258                 :            : 
+    1259                 :          0 :         ret = ctx->pk_info->sign_rs_func(ctx, md_alg,
+    1260                 :            :                                          hash, hash_len,
+    1261                 :            :                                          sig, sig_size, sig_len,
+    1262                 :            :                                          f_rng, p_rng, rs_ctx->rs_ctx);
+    1263                 :            : 
+    1264         [ #  # ]:          0 :         if (ret != MBEDTLS_ERR_ECP_IN_PROGRESS) {
+    1265                 :          0 :             mbedtls_pk_restart_free(rs_ctx);
+    1266                 :            :         }
+    1267                 :            : 
+    1268                 :          0 :         return ret;
+    1269                 :            :     }
+    1270                 :            : #else /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
+    1271                 :            :     (void) rs_ctx;
+    1272                 :            : #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
+    1273                 :            : 
+    1274         [ -  + ]:          6 :     if (ctx->pk_info->sign_func == NULL) {
+    1275                 :          0 :         return MBEDTLS_ERR_PK_TYPE_MISMATCH;
+    1276                 :            :     }
+    1277                 :            : 
+    1278                 :          6 :     return ctx->pk_info->sign_func(ctx, md_alg,
+    1279                 :            :                                    hash, hash_len,
+    1280                 :            :                                    sig, sig_size, sig_len,
+    1281                 :            :                                    f_rng, p_rng);
+    1282                 :            : }
+    1283                 :            : 
+    1284                 :            : /*
+    1285                 :            :  * Make a signature
+    1286                 :            :  */
+    1287                 :          6 : int mbedtls_pk_sign(mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg,
+    1288                 :            :                     const unsigned char *hash, size_t hash_len,
+    1289                 :            :                     unsigned char *sig, size_t sig_size, size_t *sig_len,
+    1290                 :            :                     int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
+    1291                 :            : {
+    1292                 :          6 :     return mbedtls_pk_sign_restartable(ctx, md_alg, hash, hash_len,
+    1293                 :            :                                        sig, sig_size, sig_len,
+    1294                 :            :                                        f_rng, p_rng, NULL);
+    1295                 :            : }
+    1296                 :            : 
+    1297                 :            : /*
+    1298                 :            :  * Make a signature given a signature type.
+    1299                 :            :  */
+    1300                 :          0 : int mbedtls_pk_sign_ext(mbedtls_pk_type_t pk_type,
+    1301                 :            :                         mbedtls_pk_context *ctx,
+    1302                 :            :                         mbedtls_md_type_t md_alg,
+    1303                 :            :                         const unsigned char *hash, size_t hash_len,
+    1304                 :            :                         unsigned char *sig, size_t sig_size, size_t *sig_len,
+    1305                 :            :                         int (*f_rng)(void *, unsigned char *, size_t),
+    1306                 :            :                         void *p_rng)
+    1307                 :            : {
+    1308         [ #  # ]:          0 :     if (ctx->pk_info == NULL) {
+    1309                 :          0 :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+    1310                 :            :     }
+    1311                 :            : 
+    1312         [ #  # ]:          0 :     if (!mbedtls_pk_can_do(ctx, pk_type)) {
+    1313                 :          0 :         return MBEDTLS_ERR_PK_TYPE_MISMATCH;
+    1314                 :            :     }
+    1315                 :            : 
+    1316         [ #  # ]:          0 :     if (pk_type != MBEDTLS_PK_RSASSA_PSS) {
+    1317                 :          0 :         return mbedtls_pk_sign(ctx, md_alg, hash, hash_len,
+    1318                 :            :                                sig, sig_size, sig_len, f_rng, p_rng);
+    1319                 :            :     }
+    1320                 :            : 
+    1321                 :            : #if defined(MBEDTLS_RSA_C) && defined(MBEDTLS_PKCS1_V21)
+    1322                 :            : 
+    1323                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+    1324                 :            :     const psa_algorithm_t psa_md_alg = mbedtls_md_psa_alg_from_type(md_alg);
+    1325                 :            :     if (psa_md_alg == 0) {
+    1326                 :            :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+    1327                 :            :     }
+    1328                 :            : 
+    1329                 :            :     if (mbedtls_pk_get_type(ctx) == MBEDTLS_PK_OPAQUE) {
+    1330                 :            :         psa_key_attributes_t key_attr = PSA_KEY_ATTRIBUTES_INIT;
+    1331                 :            :         psa_algorithm_t psa_alg, sign_alg;
+    1332                 :            : #if defined(MBEDTLS_PSA_CRYPTO_C)
+    1333                 :            :         psa_algorithm_t psa_enrollment_alg;
+    1334                 :            : #endif /* MBEDTLS_PSA_CRYPTO_C */
+    1335                 :            :         psa_status_t status;
+    1336                 :            : 
+    1337                 :            :         status = psa_get_key_attributes(ctx->priv_id, &key_attr);
+    1338                 :            :         if (status != PSA_SUCCESS) {
+    1339                 :            :             return PSA_PK_RSA_TO_MBEDTLS_ERR(status);
+    1340                 :            :         }
+    1341                 :            :         psa_alg = psa_get_key_algorithm(&key_attr);
+    1342                 :            : #if defined(MBEDTLS_PSA_CRYPTO_C)
+    1343                 :            :         psa_enrollment_alg = psa_get_key_enrollment_algorithm(&key_attr);
+    1344                 :            : #endif /* MBEDTLS_PSA_CRYPTO_C */
+    1345                 :            :         psa_reset_key_attributes(&key_attr);
+    1346                 :            : 
+    1347                 :            :         /* Since we're PK type is MBEDTLS_PK_RSASSA_PSS at least one between
+    1348                 :            :          * alg and enrollment alg should be of type RSA_PSS. */
+    1349                 :            :         if (PSA_ALG_IS_RSA_PSS(psa_alg)) {
+    1350                 :            :             sign_alg = psa_alg;
+    1351                 :            :         }
+    1352                 :            : #if defined(MBEDTLS_PSA_CRYPTO_C)
+    1353                 :            :         else if (PSA_ALG_IS_RSA_PSS(psa_enrollment_alg)) {
+    1354                 :            :             sign_alg = psa_enrollment_alg;
+    1355                 :            :         }
+    1356                 :            : #endif /* MBEDTLS_PSA_CRYPTO_C */
+    1357                 :            :         else {
+    1358                 :            :             /* The opaque key has no RSA PSS algorithm associated. */
+    1359                 :            :             return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+    1360                 :            :         }
+    1361                 :            :         /* Adjust the hashing algorithm. */
+    1362                 :            :         sign_alg = (sign_alg & ~PSA_ALG_HASH_MASK) | PSA_ALG_GET_HASH(psa_md_alg);
+    1363                 :            : 
+    1364                 :            :         status = psa_sign_hash(ctx->priv_id, sign_alg,
+    1365                 :            :                                hash, hash_len,
+    1366                 :            :                                sig, sig_size, sig_len);
+    1367                 :            :         return PSA_PK_RSA_TO_MBEDTLS_ERR(status);
+    1368                 :            :     }
+    1369                 :            : 
+    1370                 :            :     return mbedtls_pk_psa_rsa_sign_ext(PSA_ALG_RSA_PSS(psa_md_alg),
+    1371                 :            :                                        ctx->pk_ctx, hash, hash_len,
+    1372                 :            :                                        sig, sig_size, sig_len);
+    1373                 :            : #else /* MBEDTLS_USE_PSA_CRYPTO */
+    1374                 :            : 
+    1375         [ #  # ]:          0 :     if (sig_size < mbedtls_pk_get_len(ctx)) {
+    1376                 :          0 :         return MBEDTLS_ERR_PK_BUFFER_TOO_SMALL;
+    1377                 :            :     }
+    1378                 :            : 
+    1379         [ #  # ]:          0 :     if (pk_hashlen_helper(md_alg, &hash_len) != 0) {
+    1380                 :          0 :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+    1381                 :            :     }
+    1382                 :            : 
+    1383                 :          0 :     mbedtls_rsa_context *const rsa_ctx = mbedtls_pk_rsa(*ctx);
+    1384                 :            : 
+    1385                 :          0 :     const int ret = mbedtls_rsa_rsassa_pss_sign_no_mode_check(rsa_ctx, f_rng, p_rng, md_alg,
+    1386                 :            :                                                               (unsigned int) hash_len, hash, sig);
+    1387         [ #  # ]:          0 :     if (ret == 0) {
+    1388                 :          0 :         *sig_len = rsa_ctx->len;
+    1389                 :            :     }
+    1390                 :          0 :     return ret;
+    1391                 :            : 
+    1392                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO */
+    1393                 :            : 
+    1394                 :            : #else
+    1395                 :            :     return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE;
+    1396                 :            : #endif /* MBEDTLS_RSA_C && MBEDTLS_PKCS1_V21 */
+    1397                 :            : }
+    1398                 :            : 
+    1399                 :            : /*
+    1400                 :            :  * Decrypt message
+    1401                 :            :  */
+    1402                 :          0 : int mbedtls_pk_decrypt(mbedtls_pk_context *ctx,
+    1403                 :            :                        const unsigned char *input, size_t ilen,
+    1404                 :            :                        unsigned char *output, size_t *olen, size_t osize,
+    1405                 :            :                        int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
+    1406                 :            : {
+    1407         [ #  # ]:          0 :     if (ctx->pk_info == NULL) {
+    1408                 :          0 :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+    1409                 :            :     }
+    1410                 :            : 
+    1411         [ #  # ]:          0 :     if (ctx->pk_info->decrypt_func == NULL) {
+    1412                 :          0 :         return MBEDTLS_ERR_PK_TYPE_MISMATCH;
+    1413                 :            :     }
+    1414                 :            : 
+    1415                 :          0 :     return ctx->pk_info->decrypt_func(ctx, input, ilen,
+    1416                 :            :                                       output, olen, osize, f_rng, p_rng);
+    1417                 :            : }
+    1418                 :            : 
+    1419                 :            : /*
+    1420                 :            :  * Encrypt message
+    1421                 :            :  */
+    1422                 :          0 : int mbedtls_pk_encrypt(mbedtls_pk_context *ctx,
+    1423                 :            :                        const unsigned char *input, size_t ilen,
+    1424                 :            :                        unsigned char *output, size_t *olen, size_t osize,
+    1425                 :            :                        int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
+    1426                 :            : {
+    1427         [ #  # ]:          0 :     if (ctx->pk_info == NULL) {
+    1428                 :          0 :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+    1429                 :            :     }
+    1430                 :            : 
+    1431         [ #  # ]:          0 :     if (ctx->pk_info->encrypt_func == NULL) {
+    1432                 :          0 :         return MBEDTLS_ERR_PK_TYPE_MISMATCH;
+    1433                 :            :     }
+    1434                 :            : 
+    1435                 :          0 :     return ctx->pk_info->encrypt_func(ctx, input, ilen,
+    1436                 :            :                                       output, olen, osize, f_rng, p_rng);
+    1437                 :            : }
+    1438                 :            : 
+    1439                 :            : /*
+    1440                 :            :  * Check public-private key pair
+    1441                 :            :  */
+    1442                 :          0 : int mbedtls_pk_check_pair(const mbedtls_pk_context *pub,
+    1443                 :            :                           const mbedtls_pk_context *prv,
+    1444                 :            :                           int (*f_rng)(void *, unsigned char *, size_t),
+    1445                 :            :                           void *p_rng)
+    1446                 :            : {
+    1447         [ #  # ]:          0 :     if (pub->pk_info == NULL ||
+    1448         [ #  # ]:          0 :         prv->pk_info == NULL) {
+    1449                 :          0 :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+    1450                 :            :     }
+    1451                 :            : 
+    1452         [ #  # ]:          0 :     if (f_rng == NULL) {
+    1453                 :          0 :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+    1454                 :            :     }
+    1455                 :            : 
+    1456         [ #  # ]:          0 :     if (prv->pk_info->check_pair_func == NULL) {
+    1457                 :          0 :         return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE;
+    1458                 :            :     }
+    1459                 :            : 
+    1460         [ #  # ]:          0 :     if (prv->pk_info->type == MBEDTLS_PK_RSA_ALT) {
+    1461         [ #  # ]:          0 :         if (pub->pk_info->type != MBEDTLS_PK_RSA) {
+    1462                 :          0 :             return MBEDTLS_ERR_PK_TYPE_MISMATCH;
+    1463                 :            :         }
+    1464                 :            :     } else {
+    1465         [ #  # ]:          0 :         if ((prv->pk_info->type != MBEDTLS_PK_OPAQUE) &&
+    1466         [ #  # ]:          0 :             (pub->pk_info != prv->pk_info)) {
+    1467                 :          0 :             return MBEDTLS_ERR_PK_TYPE_MISMATCH;
+    1468                 :            :         }
+    1469                 :            :     }
+    1470                 :            : 
+    1471                 :          0 :     return prv->pk_info->check_pair_func((mbedtls_pk_context *) pub,
+    1472                 :            :                                          (mbedtls_pk_context *) prv,
+    1473                 :            :                                          f_rng, p_rng);
+    1474                 :            : }
+    1475                 :            : 
+    1476                 :            : /*
+    1477                 :            :  * Get key size in bits
+    1478                 :            :  */
+    1479                 :        540 : size_t mbedtls_pk_get_bitlen(const mbedtls_pk_context *ctx)
+    1480                 :            : {
+    1481                 :            :     /* For backward compatibility, accept NULL or a context that
+    1482                 :            :      * isn't set up yet, and return a fake value that should be safe. */
+    1483   [ +  -  -  + ]:        540 :     if (ctx == NULL || ctx->pk_info == NULL) {
+    1484                 :          0 :         return 0;
+    1485                 :            :     }
+    1486                 :            : 
+    1487                 :        540 :     return ctx->pk_info->get_bitlen((mbedtls_pk_context *) ctx);
+    1488                 :            : }
+    1489                 :            : 
+    1490                 :            : /*
+    1491                 :            :  * Export debug information
+    1492                 :            :  */
+    1493                 :          0 : int mbedtls_pk_debug(const mbedtls_pk_context *ctx, mbedtls_pk_debug_item *items)
+    1494                 :            : {
+    1495         [ #  # ]:          0 :     if (ctx->pk_info == NULL) {
+    1496                 :          0 :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+    1497                 :            :     }
+    1498                 :            : 
+    1499         [ #  # ]:          0 :     if (ctx->pk_info->debug_func == NULL) {
+    1500                 :          0 :         return MBEDTLS_ERR_PK_TYPE_MISMATCH;
+    1501                 :            :     }
+    1502                 :            : 
+    1503                 :          0 :     ctx->pk_info->debug_func((mbedtls_pk_context *) ctx, items);
+    1504                 :          0 :     return 0;
+    1505                 :            : }
+    1506                 :            : 
+    1507                 :            : /*
+    1508                 :            :  * Access the PK type name
+    1509                 :            :  */
+    1510                 :          0 : const char *mbedtls_pk_get_name(const mbedtls_pk_context *ctx)
+    1511                 :            : {
+    1512   [ #  #  #  # ]:          0 :     if (ctx == NULL || ctx->pk_info == NULL) {
+    1513                 :          0 :         return "invalid PK";
+    1514                 :            :     }
+    1515                 :            : 
+    1516                 :          0 :     return ctx->pk_info->name;
+    1517                 :            : }
+    1518                 :            : 
+    1519                 :            : /*
+    1520                 :            :  * Access the PK type
+    1521                 :            :  */
+    1522                 :      35237 : mbedtls_pk_type_t mbedtls_pk_get_type(const mbedtls_pk_context *ctx)
+    1523                 :            : {
+    1524   [ +  -  -  + ]:      35237 :     if (ctx == NULL || ctx->pk_info == NULL) {
+    1525                 :          0 :         return MBEDTLS_PK_NONE;
+    1526                 :            :     }
+    1527                 :            : 
+    1528                 :      35237 :     return ctx->pk_info->type;
+    1529                 :            : }
+    1530                 :            : 
+    1531                 :            : #endif /* MBEDTLS_PK_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/pk_ecc.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pk_ecc.c.func-sort-c.html new file mode 100644 index 00000000000..c572ea74330 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pk_ecc.c.func-sort-c.html @@ -0,0 +1,97 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/pk_ecc.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - pk_ecc.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:142166.7 %
Date:2024-09-22 08:21:07Functions:3475.0 %
Branches:3837.5 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_pk_ecc_set_pubkey_from_prv0
mbedtls_pk_ecc_set_key128
mbedtls_pk_ecc_set_group11161
mbedtls_pk_ecc_set_pubkey11161
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/pk_ecc.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pk_ecc.c.func.html new file mode 100644 index 00000000000..bd60fce4f00 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pk_ecc.c.func.html @@ -0,0 +1,97 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/pk_ecc.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - pk_ecc.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:142166.7 %
Date:2024-09-22 08:21:07Functions:3475.0 %
Branches:3837.5 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_pk_ecc_set_group11161
mbedtls_pk_ecc_set_key128
mbedtls_pk_ecc_set_pubkey11161
mbedtls_pk_ecc_set_pubkey_from_prv0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/pk_ecc.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pk_ecc.c.gcov.html new file mode 100644 index 00000000000..b6ddd303dbc --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pk_ecc.c.gcov.html @@ -0,0 +1,340 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/pk_ecc.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - pk_ecc.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:142166.7 %
Date:2024-09-22 08:21:07Functions:3475.0 %
Branches:3837.5 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  *  ECC setters for PK.
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  */
+       7                 :            : 
+       8                 :            : #include "common.h"
+       9                 :            : 
+      10                 :            : #include "mbedtls/pk.h"
+      11                 :            : #include "mbedtls/error.h"
+      12                 :            : #include "mbedtls/ecp.h"
+      13                 :            : #include "pk_internal.h"
+      14                 :            : 
+      15                 :            : #if defined(MBEDTLS_PK_C) && defined(MBEDTLS_PK_HAVE_ECC_KEYS)
+      16                 :            : 
+      17                 :      11161 : int mbedtls_pk_ecc_set_group(mbedtls_pk_context *pk, mbedtls_ecp_group_id grp_id)
+      18                 :            : {
+      19                 :            : #if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
+      20                 :            :     size_t ec_bits;
+      21                 :            :     psa_ecc_family_t ec_family = mbedtls_ecc_group_to_psa(grp_id, &ec_bits);
+      22                 :            : 
+      23                 :            :     /* group may already be initialized; if so, make sure IDs match */
+      24                 :            :     if ((pk->ec_family != 0 && pk->ec_family != ec_family) ||
+      25                 :            :         (pk->ec_bits != 0 && pk->ec_bits != ec_bits)) {
+      26                 :            :         return MBEDTLS_ERR_PK_KEY_INVALID_FORMAT;
+      27                 :            :     }
+      28                 :            : 
+      29                 :            :     /* set group */
+      30                 :            :     pk->ec_family = ec_family;
+      31                 :            :     pk->ec_bits = ec_bits;
+      32                 :            : 
+      33                 :            :     return 0;
+      34                 :            : #else /* MBEDTLS_PK_USE_PSA_EC_DATA */
+      35                 :      11161 :     mbedtls_ecp_keypair *ecp = mbedtls_pk_ec_rw(*pk);
+      36                 :            : 
+      37                 :            :     /* grp may already be initialized; if so, make sure IDs match */
+      38         [ -  + ]:      11161 :     if (mbedtls_pk_ec_ro(*pk)->grp.id != MBEDTLS_ECP_DP_NONE &&
+      39         [ #  # ]:          0 :         mbedtls_pk_ec_ro(*pk)->grp.id != grp_id) {
+      40                 :          0 :         return MBEDTLS_ERR_PK_KEY_INVALID_FORMAT;
+      41                 :            :     }
+      42                 :            : 
+      43                 :            :     /* set group */
+      44                 :      11161 :     return mbedtls_ecp_group_load(&(ecp->grp), grp_id);
+      45                 :            : #endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
+      46                 :            : }
+      47                 :            : 
+      48                 :        128 : int mbedtls_pk_ecc_set_key(mbedtls_pk_context *pk, unsigned char *key, size_t key_len)
+      49                 :            : {
+      50                 :            : #if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
+      51                 :            :     psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
+      52                 :            :     psa_key_usage_t flags;
+      53                 :            :     psa_status_t status;
+      54                 :            : 
+      55                 :            :     psa_set_key_type(&attributes, PSA_KEY_TYPE_ECC_KEY_PAIR(pk->ec_family));
+      56                 :            :     if (pk->ec_family == PSA_ECC_FAMILY_MONTGOMERY) {
+      57                 :            :         /* Do not set algorithm here because Montgomery keys cannot do ECDSA and
+      58                 :            :          * the PK module cannot do ECDH. When the key will be used in TLS for
+      59                 :            :          * ECDH, it will be exported and then re-imported with proper flags
+      60                 :            :          * and algorithm. */
+      61                 :            :         flags = PSA_KEY_USAGE_EXPORT;
+      62                 :            :     } else {
+      63                 :            :         psa_set_key_algorithm(&attributes,
+      64                 :            :                               MBEDTLS_PK_PSA_ALG_ECDSA_MAYBE_DET(PSA_ALG_ANY_HASH));
+      65                 :            :         flags = PSA_KEY_USAGE_SIGN_HASH | PSA_KEY_USAGE_SIGN_MESSAGE |
+      66                 :            :                 PSA_KEY_USAGE_EXPORT;
+      67                 :            :     }
+      68                 :            :     psa_set_key_usage_flags(&attributes, flags);
+      69                 :            : 
+      70                 :            :     status = psa_import_key(&attributes, key, key_len, &pk->priv_id);
+      71                 :            :     return psa_pk_status_to_mbedtls(status);
+      72                 :            : 
+      73                 :            : #else /* MBEDTLS_PK_USE_PSA_EC_DATA */
+      74                 :            : 
+      75                 :        128 :     mbedtls_ecp_keypair *eck = mbedtls_pk_ec_rw(*pk);
+      76                 :        128 :     int ret = mbedtls_ecp_read_key(eck->grp.id, eck, key, key_len);
+      77         [ -  + ]:        128 :     if (ret != 0) {
+      78                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret);
+      79                 :            :     }
+      80                 :        128 :     return 0;
+      81                 :            : #endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
+      82                 :            : }
+      83                 :            : 
+      84                 :          0 : int mbedtls_pk_ecc_set_pubkey_from_prv(mbedtls_pk_context *pk,
+      85                 :            :                                        const unsigned char *prv, size_t prv_len,
+      86                 :            :                                        int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
+      87                 :            : {
+      88                 :            : #if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
+      89                 :            : 
+      90                 :            :     (void) f_rng;
+      91                 :            :     (void) p_rng;
+      92                 :            :     (void) prv;
+      93                 :            :     (void) prv_len;
+      94                 :            :     psa_status_t status;
+      95                 :            : 
+      96                 :            :     status = psa_export_public_key(pk->priv_id, pk->pub_raw, sizeof(pk->pub_raw),
+      97                 :            :                                    &pk->pub_raw_len);
+      98                 :            :     return psa_pk_status_to_mbedtls(status);
+      99                 :            : 
+     100                 :            : #elif defined(MBEDTLS_USE_PSA_CRYPTO) /* && !MBEDTLS_PK_USE_PSA_EC_DATA */
+     101                 :            : 
+     102                 :            :     (void) f_rng;
+     103                 :            :     (void) p_rng;
+     104                 :            :     psa_status_t status;
+     105                 :            : 
+     106                 :            :     mbedtls_ecp_keypair *eck = (mbedtls_ecp_keypair *) pk->pk_ctx;
+     107                 :            :     size_t curve_bits;
+     108                 :            :     psa_ecc_family_t curve = mbedtls_ecc_group_to_psa(eck->grp.id, &curve_bits);
+     109                 :            : 
+     110                 :            :     /* Import private key into PSA, from serialized input */
+     111                 :            :     mbedtls_svc_key_id_t key_id = MBEDTLS_SVC_KEY_ID_INIT;
+     112                 :            :     psa_key_attributes_t key_attr = PSA_KEY_ATTRIBUTES_INIT;
+     113                 :            :     psa_set_key_type(&key_attr, PSA_KEY_TYPE_ECC_KEY_PAIR(curve));
+     114                 :            :     psa_set_key_usage_flags(&key_attr, PSA_KEY_USAGE_EXPORT);
+     115                 :            :     status = psa_import_key(&key_attr, prv, prv_len, &key_id);
+     116                 :            :     if (status != PSA_SUCCESS) {
+     117                 :            :         return psa_pk_status_to_mbedtls(status);
+     118                 :            :     }
+     119                 :            : 
+     120                 :            :     /* Export public key from PSA */
+     121                 :            :     unsigned char pub[MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH];
+     122                 :            :     size_t pub_len;
+     123                 :            :     status = psa_export_public_key(key_id, pub, sizeof(pub), &pub_len);
+     124                 :            :     psa_status_t destruction_status = psa_destroy_key(key_id);
+     125                 :            :     if (status != PSA_SUCCESS) {
+     126                 :            :         return psa_pk_status_to_mbedtls(status);
+     127                 :            :     } else if (destruction_status != PSA_SUCCESS) {
+     128                 :            :         return psa_pk_status_to_mbedtls(destruction_status);
+     129                 :            :     }
+     130                 :            : 
+     131                 :            :     /* Load serialized public key into ecp_keypair structure */
+     132                 :            :     return mbedtls_ecp_point_read_binary(&eck->grp, &eck->Q, pub, pub_len);
+     133                 :            : 
+     134                 :            : #else /* MBEDTLS_USE_PSA_CRYPTO */
+     135                 :            : 
+     136                 :            :     (void) prv;
+     137                 :            :     (void) prv_len;
+     138                 :            : 
+     139                 :          0 :     mbedtls_ecp_keypair *eck = (mbedtls_ecp_keypair *) pk->pk_ctx;
+     140                 :          0 :     return mbedtls_ecp_mul(&eck->grp, &eck->Q, &eck->d, &eck->grp.G, f_rng, p_rng);
+     141                 :            : 
+     142                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO */
+     143                 :            : }
+     144                 :            : 
+     145                 :            : #if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
+     146                 :            : /*
+     147                 :            :  * Set the public key: fallback using ECP_LIGHT in the USE_PSA_EC_DATA case.
+     148                 :            :  *
+     149                 :            :  * Normally, when MBEDTLS_PK_USE_PSA_EC_DATA is enabled, we only use PSA
+     150                 :            :  * functions to handle keys. However, currently psa_import_key() does not
+     151                 :            :  * support compressed points. In case that support was explicitly requested,
+     152                 :            :  * this fallback uses ECP functions to get the job done. This is the reason
+     153                 :            :  * why MBEDTLS_PK_PARSE_EC_COMPRESSED auto-enables MBEDTLS_ECP_LIGHT.
+     154                 :            :  *
+     155                 :            :  * [in/out] pk: in: must have the group set, see mbedtls_pk_ecc_set_group().
+     156                 :            :  *              out: will have the public key set.
+     157                 :            :  * [in] pub, pub_len: the public key as an ECPoint,
+     158                 :            :  *                    in any format supported by ECP.
+     159                 :            :  *
+     160                 :            :  * Return:
+     161                 :            :  * - 0 on success;
+     162                 :            :  * - MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the format is potentially valid
+     163                 :            :  *   but not supported;
+     164                 :            :  * - another error code otherwise.
+     165                 :            :  */
+     166                 :            : static int pk_ecc_set_pubkey_psa_ecp_fallback(mbedtls_pk_context *pk,
+     167                 :            :                                               const unsigned char *pub,
+     168                 :            :                                               size_t pub_len)
+     169                 :            : {
+     170                 :            : #if !defined(MBEDTLS_PK_PARSE_EC_COMPRESSED)
+     171                 :            :     (void) pk;
+     172                 :            :     (void) pub;
+     173                 :            :     (void) pub_len;
+     174                 :            :     return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
+     175                 :            : #else /* MBEDTLS_PK_PARSE_EC_COMPRESSED */
+     176                 :            :     mbedtls_ecp_keypair ecp_key;
+     177                 :            :     mbedtls_ecp_group_id ecp_group_id;
+     178                 :            :     int ret;
+     179                 :            : 
+     180                 :            :     ecp_group_id = mbedtls_ecc_group_from_psa(pk->ec_family, pk->ec_bits);
+     181                 :            : 
+     182                 :            :     mbedtls_ecp_keypair_init(&ecp_key);
+     183                 :            :     ret = mbedtls_ecp_group_load(&(ecp_key.grp), ecp_group_id);
+     184                 :            :     if (ret != 0) {
+     185                 :            :         goto exit;
+     186                 :            :     }
+     187                 :            :     ret = mbedtls_ecp_point_read_binary(&(ecp_key.grp), &ecp_key.Q,
+     188                 :            :                                         pub, pub_len);
+     189                 :            :     if (ret != 0) {
+     190                 :            :         goto exit;
+     191                 :            :     }
+     192                 :            :     ret = mbedtls_ecp_point_write_binary(&(ecp_key.grp), &ecp_key.Q,
+     193                 :            :                                          MBEDTLS_ECP_PF_UNCOMPRESSED,
+     194                 :            :                                          &pk->pub_raw_len, pk->pub_raw,
+     195                 :            :                                          sizeof(pk->pub_raw));
+     196                 :            : 
+     197                 :            : exit:
+     198                 :            :     mbedtls_ecp_keypair_free(&ecp_key);
+     199                 :            :     return ret;
+     200                 :            : #endif /* MBEDTLS_PK_PARSE_EC_COMPRESSED */
+     201                 :            : }
+     202                 :            : #endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
+     203                 :            : 
+     204                 :      11161 : int mbedtls_pk_ecc_set_pubkey(mbedtls_pk_context *pk, const unsigned char *pub, size_t pub_len)
+     205                 :            : {
+     206                 :            : #if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
+     207                 :            : 
+     208                 :            :     /* Load the key */
+     209                 :            :     if (!PSA_ECC_FAMILY_IS_WEIERSTRASS(pk->ec_family) || *pub == 0x04) {
+     210                 :            :         /* Format directly supported by PSA:
+     211                 :            :          * - non-Weierstrass curves that only have one format;
+     212                 :            :          * - uncompressed format for Weierstrass curves. */
+     213                 :            :         if (pub_len > sizeof(pk->pub_raw)) {
+     214                 :            :             return MBEDTLS_ERR_PK_BUFFER_TOO_SMALL;
+     215                 :            :         }
+     216                 :            :         memcpy(pk->pub_raw, pub, pub_len);
+     217                 :            :         pk->pub_raw_len = pub_len;
+     218                 :            :     } else {
+     219                 :            :         /* Other format, try the fallback */
+     220                 :            :         int ret = pk_ecc_set_pubkey_psa_ecp_fallback(pk, pub, pub_len);
+     221                 :            :         if (ret != 0) {
+     222                 :            :             return ret;
+     223                 :            :         }
+     224                 :            :     }
+     225                 :            : 
+     226                 :            :     /* Validate the key by trying to import it */
+     227                 :            :     mbedtls_svc_key_id_t key_id = MBEDTLS_SVC_KEY_ID_INIT;
+     228                 :            :     psa_key_attributes_t key_attrs = PSA_KEY_ATTRIBUTES_INIT;
+     229                 :            : 
+     230                 :            :     psa_set_key_usage_flags(&key_attrs, 0);
+     231                 :            :     psa_set_key_type(&key_attrs, PSA_KEY_TYPE_ECC_PUBLIC_KEY(pk->ec_family));
+     232                 :            :     psa_set_key_bits(&key_attrs, pk->ec_bits);
+     233                 :            : 
+     234                 :            :     if ((psa_import_key(&key_attrs, pk->pub_raw, pk->pub_raw_len,
+     235                 :            :                         &key_id) != PSA_SUCCESS) ||
+     236                 :            :         (psa_destroy_key(key_id) != PSA_SUCCESS)) {
+     237                 :            :         return MBEDTLS_ERR_PK_INVALID_PUBKEY;
+     238                 :            :     }
+     239                 :            : 
+     240                 :            :     return 0;
+     241                 :            : 
+     242                 :            : #else /* MBEDTLS_PK_USE_PSA_EC_DATA */
+     243                 :            : 
+     244                 :            :     int ret;
+     245                 :      11161 :     mbedtls_ecp_keypair *ec_key = (mbedtls_ecp_keypair *) pk->pk_ctx;
+     246                 :      11161 :     ret = mbedtls_ecp_point_read_binary(&ec_key->grp, &ec_key->Q, pub, pub_len);
+     247         [ -  + ]:      11161 :     if (ret != 0) {
+     248                 :          0 :         return ret;
+     249                 :            :     }
+     250                 :      11161 :     return mbedtls_ecp_check_pubkey(&ec_key->grp, &ec_key->Q);
+     251                 :            : 
+     252                 :            : #endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
+     253                 :            : }
+     254                 :            : 
+     255                 :            : #endif /* MBEDTLS_PK_C && MBEDTLS_PK_HAVE_ECC_KEYS */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/pk_internal.h.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pk_internal.h.func-sort-c.html new file mode 100644 index 00000000000..b3377c9fef1 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pk_internal.h.func-sort-c.html @@ -0,0 +1,97 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/pk_internal.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - pk_internal.h (source / functions)HitTotalCoverage
Test:coverage.infoLines:111861.1 %
Date:2024-09-22 08:21:07Functions:3475.0 %
Branches:2825.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_pk_is_rfc84100
mbedtls_pk_get_ec_group_id3313
mbedtls_pk_ec_rw11289
mbedtls_pk_ec_ro14474
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/pk_internal.h.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pk_internal.h.func.html new file mode 100644 index 00000000000..73387fd836b --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pk_internal.h.func.html @@ -0,0 +1,97 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/pk_internal.h - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - pk_internal.h (source / functions)HitTotalCoverage
Test:coverage.infoLines:111861.1 %
Date:2024-09-22 08:21:07Functions:3475.0 %
Branches:2825.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_pk_ec_ro14474
mbedtls_pk_ec_rw11289
mbedtls_pk_get_ec_group_id3313
mbedtls_pk_is_rfc84100
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/pk_internal.h.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pk_internal.h.gcov.html new file mode 100644 index 00000000000..e7932e9cbc1 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pk_internal.h.gcov.html @@ -0,0 +1,292 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/pk_internal.h + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - pk_internal.h (source / functions)HitTotalCoverage
Test:coverage.infoLines:111861.1 %
Date:2024-09-22 08:21:07Functions:3475.0 %
Branches:2825.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  * \file pk_internal.h
+       3                 :            :  *
+       4                 :            :  * \brief Public Key abstraction layer: internal (i.e. library only) functions
+       5                 :            :  *        and definitions.
+       6                 :            :  */
+       7                 :            : /*
+       8                 :            :  *  Copyright The Mbed TLS Contributors
+       9                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+      10                 :            :  */
+      11                 :            : #ifndef MBEDTLS_PK_INTERNAL_H
+      12                 :            : #define MBEDTLS_PK_INTERNAL_H
+      13                 :            : 
+      14                 :            : #include "mbedtls/pk.h"
+      15                 :            : 
+      16                 :            : #if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
+      17                 :            : #include "mbedtls/ecp.h"
+      18                 :            : #endif
+      19                 :            : 
+      20                 :            : #if defined(MBEDTLS_PSA_CRYPTO_CLIENT)
+      21                 :            : #include "psa/crypto.h"
+      22                 :            : 
+      23                 :            : #include "psa_util_internal.h"
+      24                 :            : #define PSA_PK_TO_MBEDTLS_ERR(status) psa_pk_status_to_mbedtls(status)
+      25                 :            : #define PSA_PK_RSA_TO_MBEDTLS_ERR(status) PSA_TO_MBEDTLS_ERR_LIST(status,     \
+      26                 :            :                                                                   psa_to_pk_rsa_errors,            \
+      27                 :            :                                                                   psa_pk_status_to_mbedtls)
+      28                 :            : #define PSA_PK_ECDSA_TO_MBEDTLS_ERR(status) PSA_TO_MBEDTLS_ERR_LIST(status,   \
+      29                 :            :                                                                     psa_to_pk_ecdsa_errors,        \
+      30                 :            :                                                                     psa_pk_status_to_mbedtls)
+      31                 :            : #endif /* MBEDTLS_PSA_CRYPTO_CLIENT */
+      32                 :            : 
+      33                 :            : /* Headers/footers for PEM files */
+      34                 :            : #define PEM_BEGIN_PUBLIC_KEY    "-----BEGIN PUBLIC KEY-----"
+      35                 :            : #define PEM_END_PUBLIC_KEY      "-----END PUBLIC KEY-----"
+      36                 :            : #define PEM_BEGIN_PRIVATE_KEY_RSA   "-----BEGIN RSA PRIVATE KEY-----"
+      37                 :            : #define PEM_END_PRIVATE_KEY_RSA     "-----END RSA PRIVATE KEY-----"
+      38                 :            : #define PEM_BEGIN_PUBLIC_KEY_RSA     "-----BEGIN RSA PUBLIC KEY-----"
+      39                 :            : #define PEM_END_PUBLIC_KEY_RSA     "-----END RSA PUBLIC KEY-----"
+      40                 :            : #define PEM_BEGIN_PRIVATE_KEY_EC    "-----BEGIN EC PRIVATE KEY-----"
+      41                 :            : #define PEM_END_PRIVATE_KEY_EC      "-----END EC PRIVATE KEY-----"
+      42                 :            : #define PEM_BEGIN_PRIVATE_KEY_PKCS8 "-----BEGIN PRIVATE KEY-----"
+      43                 :            : #define PEM_END_PRIVATE_KEY_PKCS8   "-----END PRIVATE KEY-----"
+      44                 :            : #define PEM_BEGIN_ENCRYPTED_PRIVATE_KEY_PKCS8 "-----BEGIN ENCRYPTED PRIVATE KEY-----"
+      45                 :            : #define PEM_END_ENCRYPTED_PRIVATE_KEY_PKCS8   "-----END ENCRYPTED PRIVATE KEY-----"
+      46                 :            : 
+      47                 :            : #if defined(MBEDTLS_PK_HAVE_ECC_KEYS) && !defined(MBEDTLS_PK_USE_PSA_EC_DATA)
+      48                 :            : /**
+      49                 :            :  * Public function mbedtls_pk_ec() can be used to get direct access to the
+      50                 :            :  * wrapped ecp_keypair structure pointed to the pk_ctx. However this is not
+      51                 :            :  * ideal because it bypasses the PK module on the control of its internal
+      52                 :            :  * structure (pk_context) fields.
+      53                 :            :  * For backward compatibility we keep mbedtls_pk_ec() when ECP_C is defined, but
+      54                 :            :  * we provide 2 very similar functions when only ECP_LIGHT is enabled and not
+      55                 :            :  * ECP_C.
+      56                 :            :  * These variants embed the "ro" or "rw" keywords in their name to make the
+      57                 :            :  * usage of the returned pointer explicit. Of course the returned value is
+      58                 :            :  * const or non-const accordingly.
+      59                 :            :  */
+      60                 :      14474 : static inline const mbedtls_ecp_keypair *mbedtls_pk_ec_ro(const mbedtls_pk_context pk)
+      61                 :            : {
+      62         [ +  - ]:      14474 :     switch (mbedtls_pk_get_type(&pk)) {
+      63                 :      14474 :         case MBEDTLS_PK_ECKEY:
+      64                 :            :         case MBEDTLS_PK_ECKEY_DH:
+      65                 :            :         case MBEDTLS_PK_ECDSA:
+      66                 :      14474 :             return (const mbedtls_ecp_keypair *) (pk).MBEDTLS_PRIVATE(pk_ctx);
+      67                 :          0 :         default:
+      68                 :          0 :             return NULL;
+      69                 :            :     }
+      70                 :            : }
+      71                 :            : 
+      72                 :      11289 : static inline mbedtls_ecp_keypair *mbedtls_pk_ec_rw(const mbedtls_pk_context pk)
+      73                 :            : {
+      74         [ +  - ]:      11289 :     switch (mbedtls_pk_get_type(&pk)) {
+      75                 :      11289 :         case MBEDTLS_PK_ECKEY:
+      76                 :            :         case MBEDTLS_PK_ECKEY_DH:
+      77                 :            :         case MBEDTLS_PK_ECDSA:
+      78                 :      11289 :             return (mbedtls_ecp_keypair *) (pk).MBEDTLS_PRIVATE(pk_ctx);
+      79                 :          0 :         default:
+      80                 :          0 :             return NULL;
+      81                 :            :     }
+      82                 :            : }
+      83                 :            : #endif /* MBEDTLS_PK_HAVE_ECC_KEYS && !MBEDTLS_PK_USE_PSA_EC_DATA */
+      84                 :            : 
+      85                 :            : #if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
+      86                 :       3313 : static inline mbedtls_ecp_group_id mbedtls_pk_get_ec_group_id(const mbedtls_pk_context *pk)
+      87                 :            : {
+      88                 :            :     mbedtls_ecp_group_id id;
+      89                 :            : 
+      90                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+      91                 :            :     if (mbedtls_pk_get_type(pk) == MBEDTLS_PK_OPAQUE) {
+      92                 :            :         psa_key_attributes_t opaque_attrs = PSA_KEY_ATTRIBUTES_INIT;
+      93                 :            :         psa_key_type_t opaque_key_type;
+      94                 :            :         psa_ecc_family_t curve;
+      95                 :            : 
+      96                 :            :         if (psa_get_key_attributes(pk->priv_id, &opaque_attrs) != PSA_SUCCESS) {
+      97                 :            :             return MBEDTLS_ECP_DP_NONE;
+      98                 :            :         }
+      99                 :            :         opaque_key_type = psa_get_key_type(&opaque_attrs);
+     100                 :            :         curve = PSA_KEY_TYPE_ECC_GET_FAMILY(opaque_key_type);
+     101                 :            :         id = mbedtls_ecc_group_from_psa(curve, psa_get_key_bits(&opaque_attrs));
+     102                 :            :         psa_reset_key_attributes(&opaque_attrs);
+     103                 :            :     } else
+     104                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO */
+     105                 :            :     {
+     106                 :            : #if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
+     107                 :            :         id = mbedtls_ecc_group_from_psa(pk->ec_family, pk->ec_bits);
+     108                 :            : #else /* MBEDTLS_PK_USE_PSA_EC_DATA */
+     109                 :       3313 :         id = mbedtls_pk_ec_ro(*pk)->grp.id;
+     110                 :            : #endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
+     111                 :            :     }
+     112                 :            : 
+     113                 :       3313 :     return id;
+     114                 :            : }
+     115                 :            : 
+     116                 :            : /* Helper for Montgomery curves */
+     117                 :            : #if defined(MBEDTLS_ECP_HAVE_CURVE25519) || defined(MBEDTLS_ECP_HAVE_CURVE448)
+     118                 :            : #define MBEDTLS_PK_HAVE_RFC8410_CURVES
+     119                 :            : #endif /* MBEDTLS_ECP_HAVE_CURVE25519 || MBEDTLS_ECP_DP_CURVE448 */
+     120                 :            : 
+     121                 :            : #define MBEDTLS_PK_IS_RFC8410_GROUP_ID(id)  \
+     122                 :            :     ((id == MBEDTLS_ECP_DP_CURVE25519) || (id == MBEDTLS_ECP_DP_CURVE448))
+     123                 :            : 
+     124                 :          0 : static inline int mbedtls_pk_is_rfc8410(const mbedtls_pk_context *pk)
+     125                 :            : {
+     126                 :          0 :     mbedtls_ecp_group_id id = mbedtls_pk_get_ec_group_id(pk);
+     127                 :            : 
+     128   [ #  #  #  # ]:          0 :     return MBEDTLS_PK_IS_RFC8410_GROUP_ID(id);
+     129                 :            : }
+     130                 :            : 
+     131                 :            : /*
+     132                 :            :  * Set the group used by this key.
+     133                 :            :  *
+     134                 :            :  * [in/out] pk: in: must have been pk_setup() to an ECC type
+     135                 :            :  *              out: will have group (curve) information set
+     136                 :            :  * [in] grp_in: a supported group ID (not NONE)
+     137                 :            :  */
+     138                 :            : int mbedtls_pk_ecc_set_group(mbedtls_pk_context *pk, mbedtls_ecp_group_id grp_id);
+     139                 :            : 
+     140                 :            : /*
+     141                 :            :  * Set the private key material
+     142                 :            :  *
+     143                 :            :  * [in/out] pk: in: must have the group set already, see mbedtls_pk_ecc_set_group().
+     144                 :            :  *              out: will have the private key set.
+     145                 :            :  * [in] key, key_len: the raw private key (no ASN.1 wrapping).
+     146                 :            :  */
+     147                 :            : int mbedtls_pk_ecc_set_key(mbedtls_pk_context *pk, unsigned char *key, size_t key_len);
+     148                 :            : 
+     149                 :            : /*
+     150                 :            :  * Set the public key.
+     151                 :            :  *
+     152                 :            :  * [in/out] pk: in: must have its group set, see mbedtls_pk_ecc_set_group().
+     153                 :            :  *              out: will have the public key set.
+     154                 :            :  * [in] pub, pub_len: the raw public key (an ECPoint).
+     155                 :            :  *
+     156                 :            :  * Return:
+     157                 :            :  * - 0 on success;
+     158                 :            :  * - MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the format is potentially valid
+     159                 :            :  *   but not supported;
+     160                 :            :  * - another error code otherwise.
+     161                 :            :  */
+     162                 :            : int mbedtls_pk_ecc_set_pubkey(mbedtls_pk_context *pk, const unsigned char *pub, size_t pub_len);
+     163                 :            : 
+     164                 :            : /*
+     165                 :            :  * Derive a public key from its private counterpart.
+     166                 :            :  * Computationally intensive, only use when public key is not available.
+     167                 :            :  *
+     168                 :            :  * [in/out] pk: in: must have the private key set, see mbedtls_pk_ecc_set_key().
+     169                 :            :  *              out: will have the public key set.
+     170                 :            :  * [in] prv, prv_len: the raw private key (see note below).
+     171                 :            :  * [in] f_rng, p_rng: RNG function and context.
+     172                 :            :  *
+     173                 :            :  * Note: the private key information is always available from pk,
+     174                 :            :  * however for convenience the serialized version is also passed,
+     175                 :            :  * as it's available at each calling site, and useful in some configs
+     176                 :            :  * (as otherwise we would have to re-serialize it from the pk context).
+     177                 :            :  *
+     178                 :            :  * There are three implementations of this function:
+     179                 :            :  * 1. MBEDTLS_PK_USE_PSA_EC_DATA,
+     180                 :            :  * 2. MBEDTLS_USE_PSA_CRYPTO but not MBEDTLS_PK_USE_PSA_EC_DATA,
+     181                 :            :  * 3. not MBEDTLS_USE_PSA_CRYPTO.
+     182                 :            :  */
+     183                 :            : int mbedtls_pk_ecc_set_pubkey_from_prv(mbedtls_pk_context *pk,
+     184                 :            :                                        const unsigned char *prv, size_t prv_len,
+     185                 :            :                                        int (*f_rng)(void *, unsigned char *, size_t), void *p_rng);
+     186                 :            : #endif /* MBEDTLS_PK_HAVE_ECC_KEYS */
+     187                 :            : 
+     188                 :            : /* Helper for (deterministic) ECDSA */
+     189                 :            : #if defined(MBEDTLS_ECDSA_DETERMINISTIC)
+     190                 :            : #define MBEDTLS_PK_PSA_ALG_ECDSA_MAYBE_DET  PSA_ALG_DETERMINISTIC_ECDSA
+     191                 :            : #else
+     192                 :            : #define MBEDTLS_PK_PSA_ALG_ECDSA_MAYBE_DET  PSA_ALG_ECDSA
+     193                 :            : #endif
+     194                 :            : 
+     195                 :            : #if defined(MBEDTLS_TEST_HOOKS)
+     196                 :            : MBEDTLS_STATIC_TESTABLE int mbedtls_pk_parse_key_pkcs8_encrypted_der(
+     197                 :            :     mbedtls_pk_context *pk,
+     198                 :            :     unsigned char *key, size_t keylen,
+     199                 :            :     const unsigned char *pwd, size_t pwdlen,
+     200                 :            :     int (*f_rng)(void *, unsigned char *, size_t), void *p_rng);
+     201                 :            : #endif
+     202                 :            : 
+     203                 :            : #if defined(MBEDTLS_FS_IO)
+     204                 :            : int mbedtls_pk_load_file(const char *path, unsigned char **buf, size_t *n);
+     205                 :            : #endif
+     206                 :            : 
+     207                 :            : #endif /* MBEDTLS_PK_INTERNAL_H */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/pk_wrap.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pk_wrap.c.func-sort-c.html new file mode 100644 index 00000000000..68d7f2cb2e9 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pk_wrap.c.func-sort-c.html @@ -0,0 +1,193 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/pk_wrap.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - pk_wrap.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:4214828.4 %
Date:2024-09-22 08:21:07Functions:102835.7 %
Branches:126418.8 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
ecdsa_can_do0
ecdsa_rs_alloc0
ecdsa_rs_free0
ecdsa_sign_rs_wrap0
ecdsa_verify_rs_wrap0
eckey_check_pair_wrap0
eckey_debug0
eckey_get_bitlen0
eckey_rs_alloc0
eckey_rs_free0
eckey_sign_rs_wrap0
eckey_verify_rs_wrap0
eckeydh_can_do0
rsa_check_pair_wrap0
rsa_debug0
rsa_decrypt_wrap0
rsa_encrypt_wrap0
rsa_sign_wrap0
ecdsa_sign_wrap6
rsa_verify_wrap253
rsa_can_do506
rsa_get_bitlen540
rsa_alloc_wrap1127
rsa_free_wrap1127
ecdsa_verify_wrap1335
eckey_can_do2682
eckey_free_wrap11161
eckey_alloc_wrap11167
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/pk_wrap.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pk_wrap.c.func.html new file mode 100644 index 00000000000..b952833b6af --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pk_wrap.c.func.html @@ -0,0 +1,193 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/pk_wrap.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - pk_wrap.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:4214828.4 %
Date:2024-09-22 08:21:07Functions:102835.7 %
Branches:126418.8 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
ecdsa_can_do0
ecdsa_rs_alloc0
ecdsa_rs_free0
ecdsa_sign_rs_wrap0
ecdsa_sign_wrap6
ecdsa_verify_rs_wrap0
ecdsa_verify_wrap1335
eckey_alloc_wrap11167
eckey_can_do2682
eckey_check_pair_wrap0
eckey_debug0
eckey_free_wrap11161
eckey_get_bitlen0
eckey_rs_alloc0
eckey_rs_free0
eckey_sign_rs_wrap0
eckey_verify_rs_wrap0
eckeydh_can_do0
rsa_alloc_wrap1127
rsa_can_do506
rsa_check_pair_wrap0
rsa_debug0
rsa_decrypt_wrap0
rsa_encrypt_wrap0
rsa_free_wrap1127
rsa_get_bitlen540
rsa_sign_wrap0
rsa_verify_wrap253
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/pk_wrap.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pk_wrap.c.gcov.html new file mode 100644 index 00000000000..bf152c00604 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pk_wrap.c.gcov.html @@ -0,0 +1,1669 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/pk_wrap.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - pk_wrap.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:4214828.4 %
Date:2024-09-22 08:21:07Functions:102835.7 %
Branches:126418.8 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  *  Public Key abstraction layer: wrapper functions
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  */
+       7                 :            : 
+       8                 :            : #include "common.h"
+       9                 :            : 
+      10                 :            : #include "mbedtls/platform_util.h"
+      11                 :            : 
+      12                 :            : #if defined(MBEDTLS_PK_C)
+      13                 :            : #include "pk_wrap.h"
+      14                 :            : #include "pk_internal.h"
+      15                 :            : #include "mbedtls/error.h"
+      16                 :            : #include "mbedtls/psa_util.h"
+      17                 :            : 
+      18                 :            : /* Even if RSA not activated, for the sake of RSA-alt */
+      19                 :            : #include "mbedtls/rsa.h"
+      20                 :            : 
+      21                 :            : #if defined(MBEDTLS_ECP_C)
+      22                 :            : #include "mbedtls/ecp.h"
+      23                 :            : #endif
+      24                 :            : 
+      25                 :            : #if defined(MBEDTLS_ECDSA_C)
+      26                 :            : #include "mbedtls/ecdsa.h"
+      27                 :            : #endif
+      28                 :            : 
+      29                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+      30                 :            : #include "psa_util_internal.h"
+      31                 :            : #include "psa/crypto.h"
+      32                 :            : #include "mbedtls/psa_util.h"
+      33                 :            : 
+      34                 :            : #if defined(MBEDTLS_RSA_C)
+      35                 :            : #include "pkwrite.h"
+      36                 :            : #include "rsa_internal.h"
+      37                 :            : #endif
+      38                 :            : 
+      39                 :            : #if defined(MBEDTLS_PK_CAN_ECDSA_SOME)
+      40                 :            : #include "mbedtls/asn1write.h"
+      41                 :            : #include "mbedtls/asn1.h"
+      42                 :            : #endif
+      43                 :            : #endif  /* MBEDTLS_USE_PSA_CRYPTO */
+      44                 :            : 
+      45                 :            : #include "mbedtls/platform.h"
+      46                 :            : 
+      47                 :            : #include <limits.h>
+      48                 :            : #include <stdint.h>
+      49                 :            : #include <string.h>
+      50                 :            : 
+      51                 :            : #if defined(MBEDTLS_RSA_C)
+      52                 :        506 : static int rsa_can_do(mbedtls_pk_type_t type)
+      53                 :            : {
+      54   [ -  +  -  - ]:        506 :     return type == MBEDTLS_PK_RSA ||
+      55                 :            :            type == MBEDTLS_PK_RSASSA_PSS;
+      56                 :            : }
+      57                 :            : 
+      58                 :        540 : static size_t rsa_get_bitlen(mbedtls_pk_context *pk)
+      59                 :            : {
+      60                 :        540 :     const mbedtls_rsa_context *rsa = (const mbedtls_rsa_context *) pk->pk_ctx;
+      61                 :        540 :     return mbedtls_rsa_get_bitlen(rsa);
+      62                 :            : }
+      63                 :            : 
+      64                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+      65                 :            : static int rsa_verify_wrap(mbedtls_pk_context *pk, mbedtls_md_type_t md_alg,
+      66                 :            :                            const unsigned char *hash, size_t hash_len,
+      67                 :            :                            const unsigned char *sig, size_t sig_len)
+      68                 :            : {
+      69                 :            :     mbedtls_rsa_context *rsa = (mbedtls_rsa_context *) pk->pk_ctx;
+      70                 :            :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+      71                 :            :     psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
+      72                 :            :     mbedtls_svc_key_id_t key_id = MBEDTLS_SVC_KEY_ID_INIT;
+      73                 :            :     psa_status_t status;
+      74                 :            :     int key_len;
+      75                 :            :     unsigned char buf[MBEDTLS_PK_RSA_PUB_DER_MAX_BYTES];
+      76                 :            :     unsigned char *p = buf + sizeof(buf);
+      77                 :            :     psa_algorithm_t psa_alg_md;
+      78                 :            :     size_t rsa_len = mbedtls_rsa_get_len(rsa);
+      79                 :            : 
+      80                 :            : #if SIZE_MAX > UINT_MAX
+      81                 :            :     if (md_alg == MBEDTLS_MD_NONE && UINT_MAX < hash_len) {
+      82                 :            :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+      83                 :            :     }
+      84                 :            : #endif
+      85                 :            : 
+      86                 :            :     if (mbedtls_rsa_get_padding_mode(rsa) == MBEDTLS_RSA_PKCS_V21) {
+      87                 :            :         psa_alg_md = PSA_ALG_RSA_PSS(mbedtls_md_psa_alg_from_type(md_alg));
+      88                 :            :     } else {
+      89                 :            :         psa_alg_md = PSA_ALG_RSA_PKCS1V15_SIGN(mbedtls_md_psa_alg_from_type(md_alg));
+      90                 :            :     }
+      91                 :            : 
+      92                 :            :     if (sig_len < rsa_len) {
+      93                 :            :         return MBEDTLS_ERR_RSA_VERIFY_FAILED;
+      94                 :            :     }
+      95                 :            : 
+      96                 :            :     key_len = mbedtls_rsa_write_pubkey(rsa, buf, &p);
+      97                 :            :     if (key_len <= 0) {
+      98                 :            :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+      99                 :            :     }
+     100                 :            : 
+     101                 :            :     psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_VERIFY_HASH);
+     102                 :            :     psa_set_key_algorithm(&attributes, psa_alg_md);
+     103                 :            :     psa_set_key_type(&attributes, PSA_KEY_TYPE_RSA_PUBLIC_KEY);
+     104                 :            : 
+     105                 :            :     status = psa_import_key(&attributes,
+     106                 :            :                             buf + sizeof(buf) - key_len, key_len,
+     107                 :            :                             &key_id);
+     108                 :            :     if (status != PSA_SUCCESS) {
+     109                 :            :         ret = PSA_PK_TO_MBEDTLS_ERR(status);
+     110                 :            :         goto cleanup;
+     111                 :            :     }
+     112                 :            : 
+     113                 :            :     status = psa_verify_hash(key_id, psa_alg_md, hash, hash_len,
+     114                 :            :                              sig, sig_len);
+     115                 :            :     if (status != PSA_SUCCESS) {
+     116                 :            :         ret = PSA_PK_RSA_TO_MBEDTLS_ERR(status);
+     117                 :            :         goto cleanup;
+     118                 :            :     }
+     119                 :            :     ret = 0;
+     120                 :            : 
+     121                 :            : cleanup:
+     122                 :            :     status = psa_destroy_key(key_id);
+     123                 :            :     if (ret == 0 && status != PSA_SUCCESS) {
+     124                 :            :         ret = PSA_PK_TO_MBEDTLS_ERR(status);
+     125                 :            :     }
+     126                 :            : 
+     127                 :            :     return ret;
+     128                 :            : }
+     129                 :            : #else /* MBEDTLS_USE_PSA_CRYPTO */
+     130                 :        253 : static int rsa_verify_wrap(mbedtls_pk_context *pk, mbedtls_md_type_t md_alg,
+     131                 :            :                            const unsigned char *hash, size_t hash_len,
+     132                 :            :                            const unsigned char *sig, size_t sig_len)
+     133                 :            : {
+     134                 :        253 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     135                 :        253 :     mbedtls_rsa_context *rsa = (mbedtls_rsa_context *) pk->pk_ctx;
+     136                 :        253 :     size_t rsa_len = mbedtls_rsa_get_len(rsa);
+     137                 :            : 
+     138                 :            : #if SIZE_MAX > UINT_MAX
+     139   [ -  +  -  - ]:        253 :     if (md_alg == MBEDTLS_MD_NONE && UINT_MAX < hash_len) {
+     140                 :          0 :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+     141                 :            :     }
+     142                 :            : #endif
+     143                 :            : 
+     144         [ -  + ]:        253 :     if (sig_len < rsa_len) {
+     145                 :          0 :         return MBEDTLS_ERR_RSA_VERIFY_FAILED;
+     146                 :            :     }
+     147                 :            : 
+     148         [ -  + ]:        253 :     if ((ret = mbedtls_rsa_pkcs1_verify(rsa, md_alg,
+     149                 :            :                                         (unsigned int) hash_len,
+     150                 :            :                                         hash, sig)) != 0) {
+     151                 :          0 :         return ret;
+     152                 :            :     }
+     153                 :            : 
+     154                 :            :     /* The buffer contains a valid signature followed by extra data.
+     155                 :            :      * We have a special error code for that so that so that callers can
+     156                 :            :      * use mbedtls_pk_verify() to check "Does the buffer start with a
+     157                 :            :      * valid signature?" and not just "Does the buffer contain a valid
+     158                 :            :      * signature?". */
+     159         [ -  + ]:        253 :     if (sig_len > rsa_len) {
+     160                 :          0 :         return MBEDTLS_ERR_PK_SIG_LEN_MISMATCH;
+     161                 :            :     }
+     162                 :            : 
+     163                 :        253 :     return 0;
+     164                 :            : }
+     165                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO */
+     166                 :            : 
+     167                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+     168                 :            : int  mbedtls_pk_psa_rsa_sign_ext(psa_algorithm_t alg,
+     169                 :            :                                  mbedtls_rsa_context *rsa_ctx,
+     170                 :            :                                  const unsigned char *hash, size_t hash_len,
+     171                 :            :                                  unsigned char *sig, size_t sig_size,
+     172                 :            :                                  size_t *sig_len)
+     173                 :            : {
+     174                 :            :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     175                 :            :     psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
+     176                 :            :     mbedtls_svc_key_id_t key_id = MBEDTLS_SVC_KEY_ID_INIT;
+     177                 :            :     psa_status_t status;
+     178                 :            :     int key_len;
+     179                 :            :     unsigned char *buf = NULL;
+     180                 :            :     unsigned char *p;
+     181                 :            : 
+     182                 :            :     buf = mbedtls_calloc(1, MBEDTLS_PK_RSA_PRV_DER_MAX_BYTES);
+     183                 :            :     if (buf == NULL) {
+     184                 :            :         return MBEDTLS_ERR_PK_ALLOC_FAILED;
+     185                 :            :     }
+     186                 :            :     p = buf + MBEDTLS_PK_RSA_PRV_DER_MAX_BYTES;
+     187                 :            : 
+     188                 :            :     *sig_len = mbedtls_rsa_get_len(rsa_ctx);
+     189                 :            :     if (sig_size < *sig_len) {
+     190                 :            :         mbedtls_free(buf);
+     191                 :            :         return MBEDTLS_ERR_PK_BUFFER_TOO_SMALL;
+     192                 :            :     }
+     193                 :            : 
+     194                 :            :     key_len = mbedtls_rsa_write_key(rsa_ctx, buf, &p);
+     195                 :            :     if (key_len <= 0) {
+     196                 :            :         mbedtls_free(buf);
+     197                 :            :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+     198                 :            :     }
+     199                 :            :     psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_SIGN_HASH);
+     200                 :            :     psa_set_key_algorithm(&attributes, alg);
+     201                 :            :     psa_set_key_type(&attributes, PSA_KEY_TYPE_RSA_KEY_PAIR);
+     202                 :            : 
+     203                 :            :     status = psa_import_key(&attributes,
+     204                 :            :                             buf + MBEDTLS_PK_RSA_PRV_DER_MAX_BYTES - key_len, key_len,
+     205                 :            :                             &key_id);
+     206                 :            :     if (status != PSA_SUCCESS) {
+     207                 :            :         ret = PSA_PK_TO_MBEDTLS_ERR(status);
+     208                 :            :         goto cleanup;
+     209                 :            :     }
+     210                 :            :     status = psa_sign_hash(key_id, alg, hash, hash_len,
+     211                 :            :                            sig, sig_size, sig_len);
+     212                 :            :     if (status != PSA_SUCCESS) {
+     213                 :            :         ret = PSA_PK_RSA_TO_MBEDTLS_ERR(status);
+     214                 :            :         goto cleanup;
+     215                 :            :     }
+     216                 :            : 
+     217                 :            :     ret = 0;
+     218                 :            : 
+     219                 :            : cleanup:
+     220                 :            :     mbedtls_free(buf);
+     221                 :            :     status = psa_destroy_key(key_id);
+     222                 :            :     if (ret == 0 && status != PSA_SUCCESS) {
+     223                 :            :         ret = PSA_PK_TO_MBEDTLS_ERR(status);
+     224                 :            :     }
+     225                 :            :     return ret;
+     226                 :            : }
+     227                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO */
+     228                 :            : 
+     229                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+     230                 :            : static int rsa_sign_wrap(mbedtls_pk_context *pk, mbedtls_md_type_t md_alg,
+     231                 :            :                          const unsigned char *hash, size_t hash_len,
+     232                 :            :                          unsigned char *sig, size_t sig_size, size_t *sig_len,
+     233                 :            :                          int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
+     234                 :            : {
+     235                 :            :     ((void) f_rng);
+     236                 :            :     ((void) p_rng);
+     237                 :            : 
+     238                 :            :     psa_algorithm_t psa_md_alg;
+     239                 :            :     psa_md_alg = mbedtls_md_psa_alg_from_type(md_alg);
+     240                 :            :     if (psa_md_alg == 0) {
+     241                 :            :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+     242                 :            :     }
+     243                 :            :     psa_algorithm_t psa_alg;
+     244                 :            :     if (mbedtls_rsa_get_padding_mode(mbedtls_pk_rsa(*pk)) == MBEDTLS_RSA_PKCS_V21) {
+     245                 :            :         psa_alg = PSA_ALG_RSA_PSS(psa_md_alg);
+     246                 :            :     } else {
+     247                 :            :         psa_alg = PSA_ALG_RSA_PKCS1V15_SIGN(psa_md_alg);
+     248                 :            :     }
+     249                 :            : 
+     250                 :            :     return mbedtls_pk_psa_rsa_sign_ext(psa_alg, pk->pk_ctx, hash, hash_len,
+     251                 :            :                                        sig, sig_size, sig_len);
+     252                 :            : }
+     253                 :            : #else /* MBEDTLS_USE_PSA_CRYPTO */
+     254                 :          0 : static int rsa_sign_wrap(mbedtls_pk_context *pk, mbedtls_md_type_t md_alg,
+     255                 :            :                          const unsigned char *hash, size_t hash_len,
+     256                 :            :                          unsigned char *sig, size_t sig_size, size_t *sig_len,
+     257                 :            :                          int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
+     258                 :            : {
+     259                 :          0 :     mbedtls_rsa_context *rsa = (mbedtls_rsa_context *) pk->pk_ctx;
+     260                 :            : 
+     261                 :            : #if SIZE_MAX > UINT_MAX
+     262   [ #  #  #  # ]:          0 :     if (md_alg == MBEDTLS_MD_NONE && UINT_MAX < hash_len) {
+     263                 :          0 :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+     264                 :            :     }
+     265                 :            : #endif
+     266                 :            : 
+     267                 :          0 :     *sig_len = mbedtls_rsa_get_len(rsa);
+     268         [ #  # ]:          0 :     if (sig_size < *sig_len) {
+     269                 :          0 :         return MBEDTLS_ERR_PK_BUFFER_TOO_SMALL;
+     270                 :            :     }
+     271                 :            : 
+     272                 :          0 :     return mbedtls_rsa_pkcs1_sign(rsa, f_rng, p_rng,
+     273                 :            :                                   md_alg, (unsigned int) hash_len,
+     274                 :            :                                   hash, sig);
+     275                 :            : }
+     276                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO */
+     277                 :            : 
+     278                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+     279                 :            : static int rsa_decrypt_wrap(mbedtls_pk_context *pk,
+     280                 :            :                             const unsigned char *input, size_t ilen,
+     281                 :            :                             unsigned char *output, size_t *olen, size_t osize,
+     282                 :            :                             int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
+     283                 :            : {
+     284                 :            :     mbedtls_rsa_context *rsa = (mbedtls_rsa_context *) pk->pk_ctx;
+     285                 :            :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     286                 :            :     psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
+     287                 :            :     mbedtls_svc_key_id_t key_id = MBEDTLS_SVC_KEY_ID_INIT;
+     288                 :            :     psa_algorithm_t psa_md_alg, decrypt_alg;
+     289                 :            :     psa_status_t status;
+     290                 :            :     int key_len;
+     291                 :            :     unsigned char buf[MBEDTLS_PK_RSA_PRV_DER_MAX_BYTES];
+     292                 :            :     unsigned char *p = buf + sizeof(buf);
+     293                 :            : 
+     294                 :            :     ((void) f_rng);
+     295                 :            :     ((void) p_rng);
+     296                 :            : 
+     297                 :            :     if (ilen != mbedtls_rsa_get_len(rsa)) {
+     298                 :            :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+     299                 :            :     }
+     300                 :            : 
+     301                 :            :     key_len = mbedtls_rsa_write_key(rsa, buf, &p);
+     302                 :            :     if (key_len <= 0) {
+     303                 :            :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+     304                 :            :     }
+     305                 :            : 
+     306                 :            :     psa_set_key_type(&attributes, PSA_KEY_TYPE_RSA_KEY_PAIR);
+     307                 :            :     psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DECRYPT);
+     308                 :            :     if (mbedtls_rsa_get_padding_mode(rsa) == MBEDTLS_RSA_PKCS_V21) {
+     309                 :            :         psa_md_alg = mbedtls_md_psa_alg_from_type((mbedtls_md_type_t) mbedtls_rsa_get_md_alg(rsa));
+     310                 :            :         decrypt_alg = PSA_ALG_RSA_OAEP(psa_md_alg);
+     311                 :            :     } else {
+     312                 :            :         decrypt_alg = PSA_ALG_RSA_PKCS1V15_CRYPT;
+     313                 :            :     }
+     314                 :            :     psa_set_key_algorithm(&attributes, decrypt_alg);
+     315                 :            : 
+     316                 :            :     status = psa_import_key(&attributes,
+     317                 :            :                             buf + sizeof(buf) - key_len, key_len,
+     318                 :            :                             &key_id);
+     319                 :            :     if (status != PSA_SUCCESS) {
+     320                 :            :         ret = PSA_PK_TO_MBEDTLS_ERR(status);
+     321                 :            :         goto cleanup;
+     322                 :            :     }
+     323                 :            : 
+     324                 :            :     status = psa_asymmetric_decrypt(key_id, decrypt_alg,
+     325                 :            :                                     input, ilen,
+     326                 :            :                                     NULL, 0,
+     327                 :            :                                     output, osize, olen);
+     328                 :            :     if (status != PSA_SUCCESS) {
+     329                 :            :         ret = PSA_PK_RSA_TO_MBEDTLS_ERR(status);
+     330                 :            :         goto cleanup;
+     331                 :            :     }
+     332                 :            : 
+     333                 :            :     ret = 0;
+     334                 :            : 
+     335                 :            : cleanup:
+     336                 :            :     mbedtls_platform_zeroize(buf, sizeof(buf));
+     337                 :            :     status = psa_destroy_key(key_id);
+     338                 :            :     if (ret == 0 && status != PSA_SUCCESS) {
+     339                 :            :         ret = PSA_PK_TO_MBEDTLS_ERR(status);
+     340                 :            :     }
+     341                 :            : 
+     342                 :            :     return ret;
+     343                 :            : }
+     344                 :            : #else /* MBEDTLS_USE_PSA_CRYPTO */
+     345                 :          0 : static int rsa_decrypt_wrap(mbedtls_pk_context *pk,
+     346                 :            :                             const unsigned char *input, size_t ilen,
+     347                 :            :                             unsigned char *output, size_t *olen, size_t osize,
+     348                 :            :                             int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
+     349                 :            : {
+     350                 :          0 :     mbedtls_rsa_context *rsa = (mbedtls_rsa_context *) pk->pk_ctx;
+     351                 :            : 
+     352         [ #  # ]:          0 :     if (ilen != mbedtls_rsa_get_len(rsa)) {
+     353                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+     354                 :            :     }
+     355                 :            : 
+     356                 :          0 :     return mbedtls_rsa_pkcs1_decrypt(rsa, f_rng, p_rng,
+     357                 :            :                                      olen, input, output, osize);
+     358                 :            : }
+     359                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO */
+     360                 :            : 
+     361                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+     362                 :            : static int rsa_encrypt_wrap(mbedtls_pk_context *pk,
+     363                 :            :                             const unsigned char *input, size_t ilen,
+     364                 :            :                             unsigned char *output, size_t *olen, size_t osize,
+     365                 :            :                             int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
+     366                 :            : {
+     367                 :            :     mbedtls_rsa_context *rsa = (mbedtls_rsa_context *) pk->pk_ctx;
+     368                 :            :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     369                 :            :     psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
+     370                 :            :     mbedtls_svc_key_id_t key_id = MBEDTLS_SVC_KEY_ID_INIT;
+     371                 :            :     psa_algorithm_t psa_md_alg, psa_encrypt_alg;
+     372                 :            :     psa_status_t status;
+     373                 :            :     int key_len;
+     374                 :            :     unsigned char buf[MBEDTLS_PK_RSA_PUB_DER_MAX_BYTES];
+     375                 :            :     unsigned char *p = buf + sizeof(buf);
+     376                 :            : 
+     377                 :            :     ((void) f_rng);
+     378                 :            :     ((void) p_rng);
+     379                 :            : 
+     380                 :            :     if (mbedtls_rsa_get_len(rsa) > osize) {
+     381                 :            :         return MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE;
+     382                 :            :     }
+     383                 :            : 
+     384                 :            :     key_len = mbedtls_rsa_write_pubkey(rsa, buf, &p);
+     385                 :            :     if (key_len <= 0) {
+     386                 :            :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+     387                 :            :     }
+     388                 :            : 
+     389                 :            :     psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_ENCRYPT);
+     390                 :            :     if (mbedtls_rsa_get_padding_mode(rsa) == MBEDTLS_RSA_PKCS_V21) {
+     391                 :            :         psa_md_alg = mbedtls_md_psa_alg_from_type((mbedtls_md_type_t) mbedtls_rsa_get_md_alg(rsa));
+     392                 :            :         psa_encrypt_alg = PSA_ALG_RSA_OAEP(psa_md_alg);
+     393                 :            :     } else {
+     394                 :            :         psa_encrypt_alg = PSA_ALG_RSA_PKCS1V15_CRYPT;
+     395                 :            :     }
+     396                 :            :     psa_set_key_algorithm(&attributes, psa_encrypt_alg);
+     397                 :            :     psa_set_key_type(&attributes, PSA_KEY_TYPE_RSA_PUBLIC_KEY);
+     398                 :            : 
+     399                 :            :     status = psa_import_key(&attributes,
+     400                 :            :                             buf + sizeof(buf) - key_len, key_len,
+     401                 :            :                             &key_id);
+     402                 :            :     if (status != PSA_SUCCESS) {
+     403                 :            :         ret = PSA_PK_TO_MBEDTLS_ERR(status);
+     404                 :            :         goto cleanup;
+     405                 :            :     }
+     406                 :            : 
+     407                 :            :     status = psa_asymmetric_encrypt(key_id, psa_encrypt_alg,
+     408                 :            :                                     input, ilen,
+     409                 :            :                                     NULL, 0,
+     410                 :            :                                     output, osize, olen);
+     411                 :            :     if (status != PSA_SUCCESS) {
+     412                 :            :         ret = PSA_PK_RSA_TO_MBEDTLS_ERR(status);
+     413                 :            :         goto cleanup;
+     414                 :            :     }
+     415                 :            : 
+     416                 :            :     ret = 0;
+     417                 :            : 
+     418                 :            : cleanup:
+     419                 :            :     status = psa_destroy_key(key_id);
+     420                 :            :     if (ret == 0 && status != PSA_SUCCESS) {
+     421                 :            :         ret = PSA_PK_TO_MBEDTLS_ERR(status);
+     422                 :            :     }
+     423                 :            : 
+     424                 :            :     return ret;
+     425                 :            : }
+     426                 :            : #else /* MBEDTLS_USE_PSA_CRYPTO */
+     427                 :          0 : static int rsa_encrypt_wrap(mbedtls_pk_context *pk,
+     428                 :            :                             const unsigned char *input, size_t ilen,
+     429                 :            :                             unsigned char *output, size_t *olen, size_t osize,
+     430                 :            :                             int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
+     431                 :            : {
+     432                 :          0 :     mbedtls_rsa_context *rsa = (mbedtls_rsa_context *) pk->pk_ctx;
+     433                 :          0 :     *olen = mbedtls_rsa_get_len(rsa);
+     434                 :            : 
+     435         [ #  # ]:          0 :     if (*olen > osize) {
+     436                 :          0 :         return MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE;
+     437                 :            :     }
+     438                 :            : 
+     439                 :          0 :     return mbedtls_rsa_pkcs1_encrypt(rsa, f_rng, p_rng,
+     440                 :            :                                      ilen, input, output);
+     441                 :            : }
+     442                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO */
+     443                 :            : 
+     444                 :          0 : static int rsa_check_pair_wrap(mbedtls_pk_context *pub, mbedtls_pk_context *prv,
+     445                 :            :                                int (*f_rng)(void *, unsigned char *, size_t),
+     446                 :            :                                void *p_rng)
+     447                 :            : {
+     448                 :            :     (void) f_rng;
+     449                 :            :     (void) p_rng;
+     450                 :          0 :     return mbedtls_rsa_check_pub_priv((const mbedtls_rsa_context *) pub->pk_ctx,
+     451                 :          0 :                                       (const mbedtls_rsa_context *) prv->pk_ctx);
+     452                 :            : }
+     453                 :            : 
+     454                 :       1127 : static void *rsa_alloc_wrap(void)
+     455                 :            : {
+     456                 :       1127 :     void *ctx = mbedtls_calloc(1, sizeof(mbedtls_rsa_context));
+     457                 :            : 
+     458         [ +  - ]:       1127 :     if (ctx != NULL) {
+     459                 :       1127 :         mbedtls_rsa_init((mbedtls_rsa_context *) ctx);
+     460                 :            :     }
+     461                 :            : 
+     462                 :       1127 :     return ctx;
+     463                 :            : }
+     464                 :            : 
+     465                 :       1127 : static void rsa_free_wrap(void *ctx)
+     466                 :            : {
+     467                 :       1127 :     mbedtls_rsa_free((mbedtls_rsa_context *) ctx);
+     468                 :       1127 :     mbedtls_free(ctx);
+     469                 :       1127 : }
+     470                 :            : 
+     471                 :          0 : static void rsa_debug(mbedtls_pk_context *pk, mbedtls_pk_debug_item *items)
+     472                 :            : {
+     473                 :            : #if defined(MBEDTLS_RSA_ALT)
+     474                 :            :     /* Not supported */
+     475                 :            :     (void) pk;
+     476                 :            :     (void) items;
+     477                 :            : #else
+     478                 :          0 :     mbedtls_rsa_context *rsa = (mbedtls_rsa_context *) pk->pk_ctx;
+     479                 :            : 
+     480                 :          0 :     items->type = MBEDTLS_PK_DEBUG_MPI;
+     481                 :          0 :     items->name = "rsa.N";
+     482                 :          0 :     items->value = &(rsa->N);
+     483                 :            : 
+     484                 :          0 :     items++;
+     485                 :            : 
+     486                 :          0 :     items->type = MBEDTLS_PK_DEBUG_MPI;
+     487                 :          0 :     items->name = "rsa.E";
+     488                 :          0 :     items->value = &(rsa->E);
+     489                 :            : #endif
+     490                 :          0 : }
+     491                 :            : 
+     492                 :            : const mbedtls_pk_info_t mbedtls_rsa_info = {
+     493                 :            :     .type = MBEDTLS_PK_RSA,
+     494                 :            :     .name = "RSA",
+     495                 :            :     .get_bitlen = rsa_get_bitlen,
+     496                 :            :     .can_do = rsa_can_do,
+     497                 :            :     .verify_func = rsa_verify_wrap,
+     498                 :            :     .sign_func = rsa_sign_wrap,
+     499                 :            : #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
+     500                 :            :     .verify_rs_func = NULL,
+     501                 :            :     .sign_rs_func = NULL,
+     502                 :            :     .rs_alloc_func = NULL,
+     503                 :            :     .rs_free_func = NULL,
+     504                 :            : #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
+     505                 :            :     .decrypt_func = rsa_decrypt_wrap,
+     506                 :            :     .encrypt_func = rsa_encrypt_wrap,
+     507                 :            :     .check_pair_func = rsa_check_pair_wrap,
+     508                 :            :     .ctx_alloc_func = rsa_alloc_wrap,
+     509                 :            :     .ctx_free_func = rsa_free_wrap,
+     510                 :            :     .debug_func = rsa_debug,
+     511                 :            : };
+     512                 :            : #endif /* MBEDTLS_RSA_C */
+     513                 :            : 
+     514                 :            : #if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
+     515                 :            : /*
+     516                 :            :  * Generic EC key
+     517                 :            :  */
+     518                 :       2682 : static int eckey_can_do(mbedtls_pk_type_t type)
+     519                 :            : {
+     520         [ +  - ]:       2682 :     return type == MBEDTLS_PK_ECKEY ||
+     521   [ +  -  +  + ]:       5364 :            type == MBEDTLS_PK_ECKEY_DH ||
+     522                 :            :            type == MBEDTLS_PK_ECDSA;
+     523                 :            : }
+     524                 :            : 
+     525                 :          0 : static size_t eckey_get_bitlen(mbedtls_pk_context *pk)
+     526                 :            : {
+     527                 :            : #if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
+     528                 :            :     return pk->ec_bits;
+     529                 :            : #else /* MBEDTLS_PK_USE_PSA_EC_DATA */
+     530                 :          0 :     mbedtls_ecp_keypair *ecp = (mbedtls_ecp_keypair *) pk->pk_ctx;
+     531                 :          0 :     return ecp->grp.pbits;
+     532                 :            : #endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
+     533                 :            : }
+     534                 :            : 
+     535                 :            : #if defined(MBEDTLS_PK_CAN_ECDSA_VERIFY)
+     536                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+     537                 :            : /* Common helper for ECDSA verify using PSA functions. */
+     538                 :            : static int ecdsa_verify_psa(unsigned char *key, size_t key_len,
+     539                 :            :                             psa_ecc_family_t curve, size_t curve_bits,
+     540                 :            :                             const unsigned char *hash, size_t hash_len,
+     541                 :            :                             const unsigned char *sig, size_t sig_len)
+     542                 :            : {
+     543                 :            :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     544                 :            :     psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
+     545                 :            :     mbedtls_svc_key_id_t key_id = MBEDTLS_SVC_KEY_ID_INIT;
+     546                 :            :     psa_algorithm_t psa_sig_md = PSA_ALG_ECDSA_ANY;
+     547                 :            :     size_t signature_len = PSA_ECDSA_SIGNATURE_SIZE(curve_bits);
+     548                 :            :     size_t converted_sig_len;
+     549                 :            :     unsigned char extracted_sig[PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE];
+     550                 :            :     unsigned char *p;
+     551                 :            :     psa_status_t status;
+     552                 :            : 
+     553                 :            :     if (curve == 0) {
+     554                 :            :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+     555                 :            :     }
+     556                 :            : 
+     557                 :            :     psa_set_key_type(&attributes, PSA_KEY_TYPE_ECC_PUBLIC_KEY(curve));
+     558                 :            :     psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_VERIFY_HASH);
+     559                 :            :     psa_set_key_algorithm(&attributes, psa_sig_md);
+     560                 :            : 
+     561                 :            :     status = psa_import_key(&attributes, key, key_len, &key_id);
+     562                 :            :     if (status != PSA_SUCCESS) {
+     563                 :            :         ret = PSA_PK_TO_MBEDTLS_ERR(status);
+     564                 :            :         goto cleanup;
+     565                 :            :     }
+     566                 :            : 
+     567                 :            :     if (signature_len > sizeof(extracted_sig)) {
+     568                 :            :         ret = MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+     569                 :            :         goto cleanup;
+     570                 :            :     }
+     571                 :            : 
+     572                 :            :     p = (unsigned char *) sig;
+     573                 :            :     ret = mbedtls_ecdsa_der_to_raw(curve_bits, p, sig_len, extracted_sig,
+     574                 :            :                                    sizeof(extracted_sig), &converted_sig_len);
+     575                 :            :     if (ret != 0) {
+     576                 :            :         goto cleanup;
+     577                 :            :     }
+     578                 :            : 
+     579                 :            :     if (converted_sig_len != signature_len) {
+     580                 :            :         ret = MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+     581                 :            :         goto cleanup;
+     582                 :            :     }
+     583                 :            : 
+     584                 :            :     status = psa_verify_hash(key_id, psa_sig_md, hash, hash_len,
+     585                 :            :                              extracted_sig, signature_len);
+     586                 :            :     if (status != PSA_SUCCESS) {
+     587                 :            :         ret = PSA_PK_ECDSA_TO_MBEDTLS_ERR(status);
+     588                 :            :         goto cleanup;
+     589                 :            :     }
+     590                 :            : 
+     591                 :            :     ret = 0;
+     592                 :            : 
+     593                 :            : cleanup:
+     594                 :            :     status = psa_destroy_key(key_id);
+     595                 :            :     if (ret == 0 && status != PSA_SUCCESS) {
+     596                 :            :         ret = PSA_PK_TO_MBEDTLS_ERR(status);
+     597                 :            :     }
+     598                 :            : 
+     599                 :            :     return ret;
+     600                 :            : }
+     601                 :            : 
+     602                 :            : static int ecdsa_opaque_verify_wrap(mbedtls_pk_context *pk,
+     603                 :            :                                     mbedtls_md_type_t md_alg,
+     604                 :            :                                     const unsigned char *hash, size_t hash_len,
+     605                 :            :                                     const unsigned char *sig, size_t sig_len)
+     606                 :            : {
+     607                 :            :     (void) md_alg;
+     608                 :            :     unsigned char key[MBEDTLS_PK_MAX_EC_PUBKEY_RAW_LEN];
+     609                 :            :     size_t key_len;
+     610                 :            :     psa_key_attributes_t key_attr = PSA_KEY_ATTRIBUTES_INIT;
+     611                 :            :     psa_ecc_family_t curve;
+     612                 :            :     size_t curve_bits;
+     613                 :            :     psa_status_t status;
+     614                 :            : 
+     615                 :            :     status = psa_get_key_attributes(pk->priv_id, &key_attr);
+     616                 :            :     if (status != PSA_SUCCESS) {
+     617                 :            :         return PSA_PK_ECDSA_TO_MBEDTLS_ERR(status);
+     618                 :            :     }
+     619                 :            :     curve = PSA_KEY_TYPE_ECC_GET_FAMILY(psa_get_key_type(&key_attr));
+     620                 :            :     curve_bits = psa_get_key_bits(&key_attr);
+     621                 :            :     psa_reset_key_attributes(&key_attr);
+     622                 :            : 
+     623                 :            :     status = psa_export_public_key(pk->priv_id, key, sizeof(key), &key_len);
+     624                 :            :     if (status != PSA_SUCCESS) {
+     625                 :            :         return PSA_PK_ECDSA_TO_MBEDTLS_ERR(status);
+     626                 :            :     }
+     627                 :            : 
+     628                 :            :     return ecdsa_verify_psa(key, key_len, curve, curve_bits,
+     629                 :            :                             hash, hash_len, sig, sig_len);
+     630                 :            : }
+     631                 :            : 
+     632                 :            : #if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
+     633                 :            : static int ecdsa_verify_wrap(mbedtls_pk_context *pk,
+     634                 :            :                              mbedtls_md_type_t md_alg,
+     635                 :            :                              const unsigned char *hash, size_t hash_len,
+     636                 :            :                              const unsigned char *sig, size_t sig_len)
+     637                 :            : {
+     638                 :            :     (void) md_alg;
+     639                 :            :     psa_ecc_family_t curve = pk->ec_family;
+     640                 :            :     size_t curve_bits = pk->ec_bits;
+     641                 :            : 
+     642                 :            :     return ecdsa_verify_psa(pk->pub_raw, pk->pub_raw_len, curve, curve_bits,
+     643                 :            :                             hash, hash_len, sig, sig_len);
+     644                 :            : }
+     645                 :            : #else /* MBEDTLS_PK_USE_PSA_EC_DATA */
+     646                 :            : static int ecdsa_verify_wrap(mbedtls_pk_context *pk,
+     647                 :            :                              mbedtls_md_type_t md_alg,
+     648                 :            :                              const unsigned char *hash, size_t hash_len,
+     649                 :            :                              const unsigned char *sig, size_t sig_len)
+     650                 :            : {
+     651                 :            :     (void) md_alg;
+     652                 :            :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     653                 :            :     mbedtls_ecp_keypair *ctx = pk->pk_ctx;
+     654                 :            :     unsigned char key[MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH];
+     655                 :            :     size_t key_len;
+     656                 :            :     size_t curve_bits;
+     657                 :            :     psa_ecc_family_t curve = mbedtls_ecc_group_to_psa(ctx->grp.id, &curve_bits);
+     658                 :            : 
+     659                 :            :     ret = mbedtls_ecp_point_write_binary(&ctx->grp, &ctx->Q,
+     660                 :            :                                          MBEDTLS_ECP_PF_UNCOMPRESSED,
+     661                 :            :                                          &key_len, key, sizeof(key));
+     662                 :            :     if (ret != 0) {
+     663                 :            :         return ret;
+     664                 :            :     }
+     665                 :            : 
+     666                 :            :     return ecdsa_verify_psa(key, key_len, curve, curve_bits,
+     667                 :            :                             hash, hash_len, sig, sig_len);
+     668                 :            : }
+     669                 :            : #endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
+     670                 :            : #else /* MBEDTLS_USE_PSA_CRYPTO */
+     671                 :       1335 : static int ecdsa_verify_wrap(mbedtls_pk_context *pk, mbedtls_md_type_t md_alg,
+     672                 :            :                              const unsigned char *hash, size_t hash_len,
+     673                 :            :                              const unsigned char *sig, size_t sig_len)
+     674                 :            : {
+     675                 :       1335 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     676                 :            :     ((void) md_alg);
+     677                 :            : 
+     678                 :       1335 :     ret = mbedtls_ecdsa_read_signature((mbedtls_ecdsa_context *) pk->pk_ctx,
+     679                 :            :                                        hash, hash_len, sig, sig_len);
+     680                 :            : 
+     681         [ -  + ]:       1335 :     if (ret == MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH) {
+     682                 :          0 :         return MBEDTLS_ERR_PK_SIG_LEN_MISMATCH;
+     683                 :            :     }
+     684                 :            : 
+     685                 :       1335 :     return ret;
+     686                 :            : }
+     687                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO */
+     688                 :            : #endif /* MBEDTLS_PK_CAN_ECDSA_VERIFY */
+     689                 :            : 
+     690                 :            : #if defined(MBEDTLS_PK_CAN_ECDSA_SIGN)
+     691                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+     692                 :            : /* Common helper for ECDSA sign using PSA functions.
+     693                 :            :  * Instead of extracting key's properties in order to check which kind of ECDSA
+     694                 :            :  * signature it supports, we try both deterministic and non-deterministic.
+     695                 :            :  */
+     696                 :            : static int ecdsa_sign_psa(mbedtls_svc_key_id_t key_id, mbedtls_md_type_t md_alg,
+     697                 :            :                           const unsigned char *hash, size_t hash_len,
+     698                 :            :                           unsigned char *sig, size_t sig_size, size_t *sig_len)
+     699                 :            : {
+     700                 :            :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     701                 :            :     psa_status_t status;
+     702                 :            :     psa_key_attributes_t key_attr = PSA_KEY_ATTRIBUTES_INIT;
+     703                 :            :     size_t key_bits = 0;
+     704                 :            : 
+     705                 :            :     status = psa_get_key_attributes(key_id, &key_attr);
+     706                 :            :     if (status != PSA_SUCCESS) {
+     707                 :            :         return PSA_PK_ECDSA_TO_MBEDTLS_ERR(status);
+     708                 :            :     }
+     709                 :            :     key_bits = psa_get_key_bits(&key_attr);
+     710                 :            :     psa_reset_key_attributes(&key_attr);
+     711                 :            : 
+     712                 :            :     status = psa_sign_hash(key_id,
+     713                 :            :                            PSA_ALG_DETERMINISTIC_ECDSA(mbedtls_md_psa_alg_from_type(md_alg)),
+     714                 :            :                            hash, hash_len, sig, sig_size, sig_len);
+     715                 :            :     if (status == PSA_SUCCESS) {
+     716                 :            :         goto done;
+     717                 :            :     } else if (status != PSA_ERROR_NOT_PERMITTED) {
+     718                 :            :         return PSA_PK_ECDSA_TO_MBEDTLS_ERR(status);
+     719                 :            :     }
+     720                 :            : 
+     721                 :            :     status = psa_sign_hash(key_id,
+     722                 :            :                            PSA_ALG_ECDSA(mbedtls_md_psa_alg_from_type(md_alg)),
+     723                 :            :                            hash, hash_len, sig, sig_size, sig_len);
+     724                 :            :     if (status != PSA_SUCCESS) {
+     725                 :            :         return PSA_PK_ECDSA_TO_MBEDTLS_ERR(status);
+     726                 :            :     }
+     727                 :            : 
+     728                 :            : done:
+     729                 :            :     ret = mbedtls_ecdsa_raw_to_der(key_bits, sig, *sig_len, sig, sig_size, sig_len);
+     730                 :            : 
+     731                 :            :     return ret;
+     732                 :            : }
+     733                 :            : 
+     734                 :            : static int ecdsa_opaque_sign_wrap(mbedtls_pk_context *pk,
+     735                 :            :                                   mbedtls_md_type_t md_alg,
+     736                 :            :                                   const unsigned char *hash, size_t hash_len,
+     737                 :            :                                   unsigned char *sig, size_t sig_size,
+     738                 :            :                                   size_t *sig_len,
+     739                 :            :                                   int (*f_rng)(void *, unsigned char *, size_t),
+     740                 :            :                                   void *p_rng)
+     741                 :            : {
+     742                 :            :     ((void) f_rng);
+     743                 :            :     ((void) p_rng);
+     744                 :            : 
+     745                 :            :     return ecdsa_sign_psa(pk->priv_id, md_alg, hash, hash_len, sig, sig_size,
+     746                 :            :                           sig_len);
+     747                 :            : }
+     748                 :            : 
+     749                 :            : #if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
+     750                 :            : /* When PK_USE_PSA_EC_DATA is defined opaque and non-opaque keys end up
+     751                 :            :  * using the same function. */
+     752                 :            : #define ecdsa_sign_wrap     ecdsa_opaque_sign_wrap
+     753                 :            : #else /* MBEDTLS_PK_USE_PSA_EC_DATA */
+     754                 :            : static int ecdsa_sign_wrap(mbedtls_pk_context *pk, mbedtls_md_type_t md_alg,
+     755                 :            :                            const unsigned char *hash, size_t hash_len,
+     756                 :            :                            unsigned char *sig, size_t sig_size, size_t *sig_len,
+     757                 :            :                            int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
+     758                 :            : {
+     759                 :            :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     760                 :            :     mbedtls_svc_key_id_t key_id = MBEDTLS_SVC_KEY_ID_INIT;
+     761                 :            :     psa_status_t status;
+     762                 :            :     mbedtls_ecp_keypair *ctx = pk->pk_ctx;
+     763                 :            :     psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
+     764                 :            :     unsigned char buf[MBEDTLS_PSA_MAX_EC_KEY_PAIR_LENGTH];
+     765                 :            :     size_t curve_bits;
+     766                 :            :     psa_ecc_family_t curve =
+     767                 :            :         mbedtls_ecc_group_to_psa(ctx->grp.id, &curve_bits);
+     768                 :            :     size_t key_len = PSA_BITS_TO_BYTES(curve_bits);
+     769                 :            :     psa_algorithm_t psa_hash = mbedtls_md_psa_alg_from_type(md_alg);
+     770                 :            :     psa_algorithm_t psa_sig_md = MBEDTLS_PK_PSA_ALG_ECDSA_MAYBE_DET(psa_hash);
+     771                 :            :     ((void) f_rng);
+     772                 :            :     ((void) p_rng);
+     773                 :            : 
+     774                 :            :     if (curve == 0) {
+     775                 :            :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+     776                 :            :     }
+     777                 :            : 
+     778                 :            :     if (key_len > sizeof(buf)) {
+     779                 :            :         return MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     780                 :            :     }
+     781                 :            :     ret = mbedtls_mpi_write_binary(&ctx->d, buf, key_len);
+     782                 :            :     if (ret != 0) {
+     783                 :            :         goto cleanup;
+     784                 :            :     }
+     785                 :            : 
+     786                 :            :     psa_set_key_type(&attributes, PSA_KEY_TYPE_ECC_KEY_PAIR(curve));
+     787                 :            :     psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_SIGN_HASH);
+     788                 :            :     psa_set_key_algorithm(&attributes, psa_sig_md);
+     789                 :            : 
+     790                 :            :     status = psa_import_key(&attributes, buf, key_len, &key_id);
+     791                 :            :     if (status != PSA_SUCCESS) {
+     792                 :            :         ret = PSA_PK_TO_MBEDTLS_ERR(status);
+     793                 :            :         goto cleanup;
+     794                 :            :     }
+     795                 :            : 
+     796                 :            :     ret = ecdsa_sign_psa(key_id, md_alg, hash, hash_len, sig, sig_size, sig_len);
+     797                 :            : 
+     798                 :            : cleanup:
+     799                 :            :     mbedtls_platform_zeroize(buf, sizeof(buf));
+     800                 :            :     status = psa_destroy_key(key_id);
+     801                 :            :     if (ret == 0 && status != PSA_SUCCESS) {
+     802                 :            :         ret = PSA_PK_TO_MBEDTLS_ERR(status);
+     803                 :            :     }
+     804                 :            : 
+     805                 :            :     return ret;
+     806                 :            : }
+     807                 :            : #endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
+     808                 :            : #else /* MBEDTLS_USE_PSA_CRYPTO */
+     809                 :          6 : static int ecdsa_sign_wrap(mbedtls_pk_context *pk, mbedtls_md_type_t md_alg,
+     810                 :            :                            const unsigned char *hash, size_t hash_len,
+     811                 :            :                            unsigned char *sig, size_t sig_size, size_t *sig_len,
+     812                 :            :                            int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
+     813                 :            : {
+     814                 :          6 :     return mbedtls_ecdsa_write_signature((mbedtls_ecdsa_context *) pk->pk_ctx,
+     815                 :            :                                          md_alg, hash, hash_len,
+     816                 :            :                                          sig, sig_size, sig_len,
+     817                 :            :                                          f_rng, p_rng);
+     818                 :            : }
+     819                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO */
+     820                 :            : #endif /* MBEDTLS_PK_CAN_ECDSA_SIGN */
+     821                 :            : 
+     822                 :            : #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
+     823                 :            : /* Forward declarations */
+     824                 :            : static int ecdsa_verify_rs_wrap(mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg,
+     825                 :            :                                 const unsigned char *hash, size_t hash_len,
+     826                 :            :                                 const unsigned char *sig, size_t sig_len,
+     827                 :            :                                 void *rs_ctx);
+     828                 :            : 
+     829                 :            : static int ecdsa_sign_rs_wrap(mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg,
+     830                 :            :                               const unsigned char *hash, size_t hash_len,
+     831                 :            :                               unsigned char *sig, size_t sig_size, size_t *sig_len,
+     832                 :            :                               int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
+     833                 :            :                               void *rs_ctx);
+     834                 :            : 
+     835                 :            : /*
+     836                 :            :  * Restart context for ECDSA operations with ECKEY context
+     837                 :            :  *
+     838                 :            :  * We need to store an actual ECDSA context, as we need to pass the same to
+     839                 :            :  * the underlying ecdsa function, so we can't create it on the fly every time.
+     840                 :            :  */
+     841                 :            : typedef struct {
+     842                 :            :     mbedtls_ecdsa_restart_ctx ecdsa_rs;
+     843                 :            :     mbedtls_ecdsa_context ecdsa_ctx;
+     844                 :            : } eckey_restart_ctx;
+     845                 :            : 
+     846                 :          0 : static void *eckey_rs_alloc(void)
+     847                 :            : {
+     848                 :            :     eckey_restart_ctx *rs_ctx;
+     849                 :            : 
+     850                 :          0 :     void *ctx = mbedtls_calloc(1, sizeof(eckey_restart_ctx));
+     851                 :            : 
+     852         [ #  # ]:          0 :     if (ctx != NULL) {
+     853                 :          0 :         rs_ctx = ctx;
+     854                 :          0 :         mbedtls_ecdsa_restart_init(&rs_ctx->ecdsa_rs);
+     855                 :          0 :         mbedtls_ecdsa_init(&rs_ctx->ecdsa_ctx);
+     856                 :            :     }
+     857                 :            : 
+     858                 :          0 :     return ctx;
+     859                 :            : }
+     860                 :            : 
+     861                 :          0 : static void eckey_rs_free(void *ctx)
+     862                 :            : {
+     863                 :            :     eckey_restart_ctx *rs_ctx;
+     864                 :            : 
+     865         [ #  # ]:          0 :     if (ctx == NULL) {
+     866                 :          0 :         return;
+     867                 :            :     }
+     868                 :            : 
+     869                 :          0 :     rs_ctx = ctx;
+     870                 :          0 :     mbedtls_ecdsa_restart_free(&rs_ctx->ecdsa_rs);
+     871                 :          0 :     mbedtls_ecdsa_free(&rs_ctx->ecdsa_ctx);
+     872                 :            : 
+     873                 :          0 :     mbedtls_free(ctx);
+     874                 :            : }
+     875                 :            : 
+     876                 :          0 : static int eckey_verify_rs_wrap(mbedtls_pk_context *pk, mbedtls_md_type_t md_alg,
+     877                 :            :                                 const unsigned char *hash, size_t hash_len,
+     878                 :            :                                 const unsigned char *sig, size_t sig_len,
+     879                 :            :                                 void *rs_ctx)
+     880                 :            : {
+     881                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     882                 :          0 :     eckey_restart_ctx *rs = rs_ctx;
+     883                 :            : 
+     884                 :            :     /* Should never happen */
+     885         [ #  # ]:          0 :     if (rs == NULL) {
+     886                 :          0 :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+     887                 :            :     }
+     888                 :            : 
+     889                 :            :     /* set up our own sub-context if needed (that is, on first run) */
+     890         [ #  # ]:          0 :     if (rs->ecdsa_ctx.grp.pbits == 0) {
+     891         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_ecdsa_from_keypair(&rs->ecdsa_ctx, pk->pk_ctx));
+     892                 :            :     }
+     893                 :            : 
+     894         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(ecdsa_verify_rs_wrap(pk,
+     895                 :            :                                          md_alg, hash, hash_len,
+     896                 :            :                                          sig, sig_len, &rs->ecdsa_rs));
+     897                 :            : 
+     898                 :          0 : cleanup:
+     899                 :          0 :     return ret;
+     900                 :            : }
+     901                 :            : 
+     902                 :          0 : static int eckey_sign_rs_wrap(mbedtls_pk_context *pk, mbedtls_md_type_t md_alg,
+     903                 :            :                               const unsigned char *hash, size_t hash_len,
+     904                 :            :                               unsigned char *sig, size_t sig_size, size_t *sig_len,
+     905                 :            :                               int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
+     906                 :            :                               void *rs_ctx)
+     907                 :            : {
+     908                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     909                 :          0 :     eckey_restart_ctx *rs = rs_ctx;
+     910                 :            : 
+     911                 :            :     /* Should never happen */
+     912         [ #  # ]:          0 :     if (rs == NULL) {
+     913                 :          0 :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+     914                 :            :     }
+     915                 :            : 
+     916                 :            :     /* set up our own sub-context if needed (that is, on first run) */
+     917         [ #  # ]:          0 :     if (rs->ecdsa_ctx.grp.pbits == 0) {
+     918         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_ecdsa_from_keypair(&rs->ecdsa_ctx, pk->pk_ctx));
+     919                 :            :     }
+     920                 :            : 
+     921         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(ecdsa_sign_rs_wrap(pk, md_alg,
+     922                 :            :                                        hash, hash_len, sig, sig_size, sig_len,
+     923                 :            :                                        f_rng, p_rng, &rs->ecdsa_rs));
+     924                 :            : 
+     925                 :          0 : cleanup:
+     926                 :          0 :     return ret;
+     927                 :            : }
+     928                 :            : #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
+     929                 :            : 
+     930                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+     931                 :            : #if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
+     932                 :            : static int eckey_check_pair_psa(mbedtls_pk_context *pub, mbedtls_pk_context *prv)
+     933                 :            : {
+     934                 :            :     psa_status_t status;
+     935                 :            :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     936                 :            :     uint8_t prv_key_buf[MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH];
+     937                 :            :     size_t prv_key_len;
+     938                 :            :     mbedtls_svc_key_id_t key_id = prv->priv_id;
+     939                 :            : 
+     940                 :            :     status = psa_export_public_key(key_id, prv_key_buf, sizeof(prv_key_buf),
+     941                 :            :                                    &prv_key_len);
+     942                 :            :     ret = PSA_PK_TO_MBEDTLS_ERR(status);
+     943                 :            :     if (ret != 0) {
+     944                 :            :         return ret;
+     945                 :            :     }
+     946                 :            : 
+     947                 :            :     if (memcmp(prv_key_buf, pub->pub_raw, pub->pub_raw_len) != 0) {
+     948                 :            :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+     949                 :            :     }
+     950                 :            : 
+     951                 :            :     return 0;
+     952                 :            : }
+     953                 :            : #else /* MBEDTLS_PK_USE_PSA_EC_DATA */
+     954                 :            : static int eckey_check_pair_psa(mbedtls_pk_context *pub, mbedtls_pk_context *prv)
+     955                 :            : {
+     956                 :            :     psa_status_t status;
+     957                 :            :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     958                 :            :     uint8_t prv_key_buf[MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH];
+     959                 :            :     size_t prv_key_len;
+     960                 :            :     psa_status_t destruction_status;
+     961                 :            :     mbedtls_svc_key_id_t key_id = MBEDTLS_SVC_KEY_ID_INIT;
+     962                 :            :     psa_key_attributes_t key_attr = PSA_KEY_ATTRIBUTES_INIT;
+     963                 :            :     uint8_t pub_key_buf[MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH];
+     964                 :            :     size_t pub_key_len;
+     965                 :            :     size_t curve_bits;
+     966                 :            :     const psa_ecc_family_t curve =
+     967                 :            :         mbedtls_ecc_group_to_psa(mbedtls_pk_ec_ro(*prv)->grp.id, &curve_bits);
+     968                 :            :     const size_t curve_bytes = PSA_BITS_TO_BYTES(curve_bits);
+     969                 :            : 
+     970                 :            :     if (curve == 0) {
+     971                 :            :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+     972                 :            :     }
+     973                 :            : 
+     974                 :            :     psa_set_key_type(&key_attr, PSA_KEY_TYPE_ECC_KEY_PAIR(curve));
+     975                 :            :     psa_set_key_usage_flags(&key_attr, PSA_KEY_USAGE_EXPORT);
+     976                 :            : 
+     977                 :            :     ret = mbedtls_mpi_write_binary(&mbedtls_pk_ec_ro(*prv)->d,
+     978                 :            :                                    prv_key_buf, curve_bytes);
+     979                 :            :     if (ret != 0) {
+     980                 :            :         mbedtls_platform_zeroize(prv_key_buf, sizeof(prv_key_buf));
+     981                 :            :         return ret;
+     982                 :            :     }
+     983                 :            : 
+     984                 :            :     status = psa_import_key(&key_attr, prv_key_buf, curve_bytes, &key_id);
+     985                 :            :     mbedtls_platform_zeroize(prv_key_buf, sizeof(prv_key_buf));
+     986                 :            :     ret = PSA_PK_TO_MBEDTLS_ERR(status);
+     987                 :            :     if (ret != 0) {
+     988                 :            :         return ret;
+     989                 :            :     }
+     990                 :            : 
+     991                 :            :     // From now on prv_key_buf is used to store the public key of prv.
+     992                 :            :     status = psa_export_public_key(key_id, prv_key_buf, sizeof(prv_key_buf),
+     993                 :            :                                    &prv_key_len);
+     994                 :            :     ret = PSA_PK_TO_MBEDTLS_ERR(status);
+     995                 :            :     destruction_status = psa_destroy_key(key_id);
+     996                 :            :     if (ret != 0) {
+     997                 :            :         return ret;
+     998                 :            :     } else if (destruction_status != PSA_SUCCESS) {
+     999                 :            :         return PSA_PK_TO_MBEDTLS_ERR(destruction_status);
+    1000                 :            :     }
+    1001                 :            : 
+    1002                 :            :     ret = mbedtls_ecp_point_write_binary(&mbedtls_pk_ec_rw(*pub)->grp,
+    1003                 :            :                                          &mbedtls_pk_ec_rw(*pub)->Q,
+    1004                 :            :                                          MBEDTLS_ECP_PF_UNCOMPRESSED,
+    1005                 :            :                                          &pub_key_len, pub_key_buf,
+    1006                 :            :                                          sizeof(pub_key_buf));
+    1007                 :            :     if (ret != 0) {
+    1008                 :            :         return ret;
+    1009                 :            :     }
+    1010                 :            : 
+    1011                 :            :     if (memcmp(prv_key_buf, pub_key_buf, curve_bytes) != 0) {
+    1012                 :            :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+    1013                 :            :     }
+    1014                 :            : 
+    1015                 :            :     return 0;
+    1016                 :            : }
+    1017                 :            : #endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
+    1018                 :            : 
+    1019                 :            : static int eckey_check_pair_wrap(mbedtls_pk_context *pub, mbedtls_pk_context *prv,
+    1020                 :            :                                  int (*f_rng)(void *, unsigned char *, size_t),
+    1021                 :            :                                  void *p_rng)
+    1022                 :            : {
+    1023                 :            :     (void) f_rng;
+    1024                 :            :     (void) p_rng;
+    1025                 :            :     return eckey_check_pair_psa(pub, prv);
+    1026                 :            : }
+    1027                 :            : #else /* MBEDTLS_USE_PSA_CRYPTO */
+    1028                 :          0 : static int eckey_check_pair_wrap(mbedtls_pk_context *pub, mbedtls_pk_context *prv,
+    1029                 :            :                                  int (*f_rng)(void *, unsigned char *, size_t),
+    1030                 :            :                                  void *p_rng)
+    1031                 :            : {
+    1032                 :          0 :     return mbedtls_ecp_check_pub_priv((const mbedtls_ecp_keypair *) pub->pk_ctx,
+    1033                 :          0 :                                       (const mbedtls_ecp_keypair *) prv->pk_ctx,
+    1034                 :            :                                       f_rng, p_rng);
+    1035                 :            : }
+    1036                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO */
+    1037                 :            : 
+    1038                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+    1039                 :            : #if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
+    1040                 :            : /* When PK_USE_PSA_EC_DATA is defined opaque and non-opaque keys end up
+    1041                 :            :  * using the same function. */
+    1042                 :            : #define ecdsa_opaque_check_pair_wrap    eckey_check_pair_wrap
+    1043                 :            : #else /* MBEDTLS_PK_USE_PSA_EC_DATA */
+    1044                 :            : static int ecdsa_opaque_check_pair_wrap(mbedtls_pk_context *pub,
+    1045                 :            :                                         mbedtls_pk_context *prv,
+    1046                 :            :                                         int (*f_rng)(void *, unsigned char *, size_t),
+    1047                 :            :                                         void *p_rng)
+    1048                 :            : {
+    1049                 :            :     psa_status_t status;
+    1050                 :            :     uint8_t exp_pub_key[MBEDTLS_PK_MAX_EC_PUBKEY_RAW_LEN];
+    1051                 :            :     size_t exp_pub_key_len = 0;
+    1052                 :            :     uint8_t pub_key[MBEDTLS_PK_MAX_EC_PUBKEY_RAW_LEN];
+    1053                 :            :     size_t pub_key_len = 0;
+    1054                 :            :     int ret;
+    1055                 :            :     (void) f_rng;
+    1056                 :            :     (void) p_rng;
+    1057                 :            : 
+    1058                 :            :     status = psa_export_public_key(prv->priv_id, exp_pub_key, sizeof(exp_pub_key),
+    1059                 :            :                                    &exp_pub_key_len);
+    1060                 :            :     if (status != PSA_SUCCESS) {
+    1061                 :            :         ret = psa_pk_status_to_mbedtls(status);
+    1062                 :            :         return ret;
+    1063                 :            :     }
+    1064                 :            :     ret = mbedtls_ecp_point_write_binary(&(mbedtls_pk_ec_ro(*pub)->grp),
+    1065                 :            :                                          &(mbedtls_pk_ec_ro(*pub)->Q),
+    1066                 :            :                                          MBEDTLS_ECP_PF_UNCOMPRESSED,
+    1067                 :            :                                          &pub_key_len, pub_key, sizeof(pub_key));
+    1068                 :            :     if (ret != 0) {
+    1069                 :            :         return ret;
+    1070                 :            :     }
+    1071                 :            :     if ((exp_pub_key_len != pub_key_len) ||
+    1072                 :            :         memcmp(exp_pub_key, pub_key, exp_pub_key_len)) {
+    1073                 :            :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+    1074                 :            :     }
+    1075                 :            :     return 0;
+    1076                 :            : }
+    1077                 :            : #endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
+    1078                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO */
+    1079                 :            : 
+    1080                 :            : #if !defined(MBEDTLS_PK_USE_PSA_EC_DATA)
+    1081                 :      11167 : static void *eckey_alloc_wrap(void)
+    1082                 :            : {
+    1083                 :      11167 :     void *ctx = mbedtls_calloc(1, sizeof(mbedtls_ecp_keypair));
+    1084                 :            : 
+    1085         [ +  - ]:      11167 :     if (ctx != NULL) {
+    1086                 :      11167 :         mbedtls_ecp_keypair_init(ctx);
+    1087                 :            :     }
+    1088                 :            : 
+    1089                 :      11167 :     return ctx;
+    1090                 :            : }
+    1091                 :            : 
+    1092                 :      11161 : static void eckey_free_wrap(void *ctx)
+    1093                 :            : {
+    1094                 :      11161 :     mbedtls_ecp_keypair_free((mbedtls_ecp_keypair *) ctx);
+    1095                 :      11161 :     mbedtls_free(ctx);
+    1096                 :      11161 : }
+    1097                 :            : #endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
+    1098                 :            : 
+    1099                 :          0 : static void eckey_debug(mbedtls_pk_context *pk, mbedtls_pk_debug_item *items)
+    1100                 :            : {
+    1101                 :            : #if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
+    1102                 :            :     items->type = MBEDTLS_PK_DEBUG_PSA_EC;
+    1103                 :            :     items->name = "eckey.Q";
+    1104                 :            :     items->value = pk;
+    1105                 :            : #else /* MBEDTLS_PK_USE_PSA_EC_DATA */
+    1106                 :          0 :     mbedtls_ecp_keypair *ecp = (mbedtls_ecp_keypair *) pk->pk_ctx;
+    1107                 :          0 :     items->type = MBEDTLS_PK_DEBUG_ECP;
+    1108                 :          0 :     items->name = "eckey.Q";
+    1109                 :          0 :     items->value = &(ecp->Q);
+    1110                 :            : #endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
+    1111                 :          0 : }
+    1112                 :            : 
+    1113                 :            : const mbedtls_pk_info_t mbedtls_eckey_info = {
+    1114                 :            :     .type = MBEDTLS_PK_ECKEY,
+    1115                 :            :     .name = "EC",
+    1116                 :            :     .get_bitlen = eckey_get_bitlen,
+    1117                 :            :     .can_do = eckey_can_do,
+    1118                 :            : #if defined(MBEDTLS_PK_CAN_ECDSA_VERIFY)
+    1119                 :            :     .verify_func = ecdsa_verify_wrap,   /* Compatible key structures */
+    1120                 :            : #else /* MBEDTLS_PK_CAN_ECDSA_VERIFY */
+    1121                 :            :     .verify_func = NULL,
+    1122                 :            : #endif /* MBEDTLS_PK_CAN_ECDSA_VERIFY */
+    1123                 :            : #if defined(MBEDTLS_PK_CAN_ECDSA_SIGN)
+    1124                 :            :     .sign_func = ecdsa_sign_wrap,   /* Compatible key structures */
+    1125                 :            : #else /* MBEDTLS_PK_CAN_ECDSA_VERIFY */
+    1126                 :            :     .sign_func = NULL,
+    1127                 :            : #endif /* MBEDTLS_PK_CAN_ECDSA_VERIFY */
+    1128                 :            : #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
+    1129                 :            :     .verify_rs_func = eckey_verify_rs_wrap,
+    1130                 :            :     .sign_rs_func = eckey_sign_rs_wrap,
+    1131                 :            :     .rs_alloc_func = eckey_rs_alloc,
+    1132                 :            :     .rs_free_func = eckey_rs_free,
+    1133                 :            : #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
+    1134                 :            :     .decrypt_func = NULL,
+    1135                 :            :     .encrypt_func = NULL,
+    1136                 :            :     .check_pair_func = eckey_check_pair_wrap,
+    1137                 :            : #if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
+    1138                 :            :     .ctx_alloc_func = NULL,
+    1139                 :            :     .ctx_free_func = NULL,
+    1140                 :            : #else /* MBEDTLS_PK_USE_PSA_EC_DATA */
+    1141                 :            :     .ctx_alloc_func = eckey_alloc_wrap,
+    1142                 :            :     .ctx_free_func = eckey_free_wrap,
+    1143                 :            : #endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
+    1144                 :            :     .debug_func = eckey_debug,
+    1145                 :            : };
+    1146                 :            : 
+    1147                 :            : /*
+    1148                 :            :  * EC key restricted to ECDH
+    1149                 :            :  */
+    1150                 :          0 : static int eckeydh_can_do(mbedtls_pk_type_t type)
+    1151                 :            : {
+    1152   [ #  #  #  # ]:          0 :     return type == MBEDTLS_PK_ECKEY ||
+    1153                 :            :            type == MBEDTLS_PK_ECKEY_DH;
+    1154                 :            : }
+    1155                 :            : 
+    1156                 :            : const mbedtls_pk_info_t mbedtls_eckeydh_info = {
+    1157                 :            :     .type = MBEDTLS_PK_ECKEY_DH,
+    1158                 :            :     .name = "EC_DH",
+    1159                 :            :     .get_bitlen = eckey_get_bitlen,         /* Same underlying key structure */
+    1160                 :            :     .can_do = eckeydh_can_do,
+    1161                 :            :     .verify_func = NULL,
+    1162                 :            :     .sign_func = NULL,
+    1163                 :            : #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
+    1164                 :            :     .verify_rs_func = NULL,
+    1165                 :            :     .sign_rs_func = NULL,
+    1166                 :            : #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
+    1167                 :            :     .decrypt_func = NULL,
+    1168                 :            :     .encrypt_func = NULL,
+    1169                 :            :     .check_pair_func = eckey_check_pair_wrap,
+    1170                 :            : #if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
+    1171                 :            :     .ctx_alloc_func = NULL,
+    1172                 :            :     .ctx_free_func = NULL,
+    1173                 :            : #else /* MBEDTLS_PK_USE_PSA_EC_DATA */
+    1174                 :            :     .ctx_alloc_func = eckey_alloc_wrap,   /* Same underlying key structure */
+    1175                 :            :     .ctx_free_func = eckey_free_wrap,    /* Same underlying key structure */
+    1176                 :            : #endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
+    1177                 :            :     .debug_func = eckey_debug,            /* Same underlying key structure */
+    1178                 :            : };
+    1179                 :            : 
+    1180                 :            : #if defined(MBEDTLS_PK_CAN_ECDSA_SOME)
+    1181                 :          0 : static int ecdsa_can_do(mbedtls_pk_type_t type)
+    1182                 :            : {
+    1183                 :          0 :     return type == MBEDTLS_PK_ECDSA;
+    1184                 :            : }
+    1185                 :            : 
+    1186                 :            : #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
+    1187                 :          0 : static int ecdsa_verify_rs_wrap(mbedtls_pk_context *pk, mbedtls_md_type_t md_alg,
+    1188                 :            :                                 const unsigned char *hash, size_t hash_len,
+    1189                 :            :                                 const unsigned char *sig, size_t sig_len,
+    1190                 :            :                                 void *rs_ctx)
+    1191                 :            : {
+    1192                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1193                 :            :     ((void) md_alg);
+    1194                 :            : 
+    1195                 :          0 :     ret = mbedtls_ecdsa_read_signature_restartable(
+    1196                 :          0 :         (mbedtls_ecdsa_context *) pk->pk_ctx,
+    1197                 :            :         hash, hash_len, sig, sig_len,
+    1198                 :            :         (mbedtls_ecdsa_restart_ctx *) rs_ctx);
+    1199                 :            : 
+    1200         [ #  # ]:          0 :     if (ret == MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH) {
+    1201                 :          0 :         return MBEDTLS_ERR_PK_SIG_LEN_MISMATCH;
+    1202                 :            :     }
+    1203                 :            : 
+    1204                 :          0 :     return ret;
+    1205                 :            : }
+    1206                 :            : 
+    1207                 :          0 : static int ecdsa_sign_rs_wrap(mbedtls_pk_context *pk, mbedtls_md_type_t md_alg,
+    1208                 :            :                               const unsigned char *hash, size_t hash_len,
+    1209                 :            :                               unsigned char *sig, size_t sig_size, size_t *sig_len,
+    1210                 :            :                               int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
+    1211                 :            :                               void *rs_ctx)
+    1212                 :            : {
+    1213                 :          0 :     return mbedtls_ecdsa_write_signature_restartable(
+    1214                 :          0 :         (mbedtls_ecdsa_context *) pk->pk_ctx,
+    1215                 :            :         md_alg, hash, hash_len, sig, sig_size, sig_len, f_rng, p_rng,
+    1216                 :            :         (mbedtls_ecdsa_restart_ctx *) rs_ctx);
+    1217                 :            : 
+    1218                 :            : }
+    1219                 :            : 
+    1220                 :          0 : static void *ecdsa_rs_alloc(void)
+    1221                 :            : {
+    1222                 :          0 :     void *ctx = mbedtls_calloc(1, sizeof(mbedtls_ecdsa_restart_ctx));
+    1223                 :            : 
+    1224         [ #  # ]:          0 :     if (ctx != NULL) {
+    1225                 :          0 :         mbedtls_ecdsa_restart_init(ctx);
+    1226                 :            :     }
+    1227                 :            : 
+    1228                 :          0 :     return ctx;
+    1229                 :            : }
+    1230                 :            : 
+    1231                 :          0 : static void ecdsa_rs_free(void *ctx)
+    1232                 :            : {
+    1233                 :          0 :     mbedtls_ecdsa_restart_free(ctx);
+    1234                 :          0 :     mbedtls_free(ctx);
+    1235                 :          0 : }
+    1236                 :            : #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
+    1237                 :            : 
+    1238                 :            : const mbedtls_pk_info_t mbedtls_ecdsa_info = {
+    1239                 :            :     .type = MBEDTLS_PK_ECDSA,
+    1240                 :            :     .name = "ECDSA",
+    1241                 :            :     .get_bitlen = eckey_get_bitlen,     /* Compatible key structures */
+    1242                 :            :     .can_do = ecdsa_can_do,
+    1243                 :            : #if defined(MBEDTLS_PK_CAN_ECDSA_VERIFY)
+    1244                 :            :     .verify_func = ecdsa_verify_wrap,   /* Compatible key structures */
+    1245                 :            : #else /* MBEDTLS_PK_CAN_ECDSA_VERIFY */
+    1246                 :            :     .verify_func = NULL,
+    1247                 :            : #endif /* MBEDTLS_PK_CAN_ECDSA_VERIFY */
+    1248                 :            : #if defined(MBEDTLS_PK_CAN_ECDSA_SIGN)
+    1249                 :            :     .sign_func = ecdsa_sign_wrap,   /* Compatible key structures */
+    1250                 :            : #else /* MBEDTLS_PK_CAN_ECDSA_SIGN */
+    1251                 :            :     .sign_func = NULL,
+    1252                 :            : #endif /* MBEDTLS_PK_CAN_ECDSA_SIGN */
+    1253                 :            : #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
+    1254                 :            :     .verify_rs_func = ecdsa_verify_rs_wrap,
+    1255                 :            :     .sign_rs_func = ecdsa_sign_rs_wrap,
+    1256                 :            :     .rs_alloc_func = ecdsa_rs_alloc,
+    1257                 :            :     .rs_free_func = ecdsa_rs_free,
+    1258                 :            : #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
+    1259                 :            :     .decrypt_func = NULL,
+    1260                 :            :     .encrypt_func = NULL,
+    1261                 :            :     .check_pair_func = eckey_check_pair_wrap,   /* Compatible key structures */
+    1262                 :            : #if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
+    1263                 :            :     .ctx_alloc_func = NULL,
+    1264                 :            :     .ctx_free_func = NULL,
+    1265                 :            : #else /* MBEDTLS_PK_USE_PSA_EC_DATA */
+    1266                 :            :     .ctx_alloc_func = eckey_alloc_wrap,   /* Compatible key structures */
+    1267                 :            :     .ctx_free_func = eckey_free_wrap,   /* Compatible key structures */
+    1268                 :            : #endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
+    1269                 :            :     .debug_func = eckey_debug,        /* Compatible key structures */
+    1270                 :            : };
+    1271                 :            : #endif /* MBEDTLS_PK_CAN_ECDSA_SOME */
+    1272                 :            : #endif /* MBEDTLS_PK_HAVE_ECC_KEYS */
+    1273                 :            : 
+    1274                 :            : #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
+    1275                 :            : /*
+    1276                 :            :  * Support for alternative RSA-private implementations
+    1277                 :            :  */
+    1278                 :            : 
+    1279                 :            : static int rsa_alt_can_do(mbedtls_pk_type_t type)
+    1280                 :            : {
+    1281                 :            :     return type == MBEDTLS_PK_RSA;
+    1282                 :            : }
+    1283                 :            : 
+    1284                 :            : static size_t rsa_alt_get_bitlen(mbedtls_pk_context *pk)
+    1285                 :            : {
+    1286                 :            :     const mbedtls_rsa_alt_context *rsa_alt = pk->pk_ctx;
+    1287                 :            : 
+    1288                 :            :     return 8 * rsa_alt->key_len_func(rsa_alt->key);
+    1289                 :            : }
+    1290                 :            : 
+    1291                 :            : static int rsa_alt_sign_wrap(mbedtls_pk_context *pk, mbedtls_md_type_t md_alg,
+    1292                 :            :                              const unsigned char *hash, size_t hash_len,
+    1293                 :            :                              unsigned char *sig, size_t sig_size, size_t *sig_len,
+    1294                 :            :                              int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
+    1295                 :            : {
+    1296                 :            :     mbedtls_rsa_alt_context *rsa_alt = pk->pk_ctx;
+    1297                 :            : 
+    1298                 :            : #if SIZE_MAX > UINT_MAX
+    1299                 :            :     if (UINT_MAX < hash_len) {
+    1300                 :            :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+    1301                 :            :     }
+    1302                 :            : #endif
+    1303                 :            : 
+    1304                 :            :     *sig_len = rsa_alt->key_len_func(rsa_alt->key);
+    1305                 :            :     if (*sig_len > MBEDTLS_PK_SIGNATURE_MAX_SIZE) {
+    1306                 :            :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+    1307                 :            :     }
+    1308                 :            :     if (*sig_len > sig_size) {
+    1309                 :            :         return MBEDTLS_ERR_PK_BUFFER_TOO_SMALL;
+    1310                 :            :     }
+    1311                 :            : 
+    1312                 :            :     return rsa_alt->sign_func(rsa_alt->key, f_rng, p_rng,
+    1313                 :            :                               md_alg, (unsigned int) hash_len, hash, sig);
+    1314                 :            : }
+    1315                 :            : 
+    1316                 :            : static int rsa_alt_decrypt_wrap(mbedtls_pk_context *pk,
+    1317                 :            :                                 const unsigned char *input, size_t ilen,
+    1318                 :            :                                 unsigned char *output, size_t *olen, size_t osize,
+    1319                 :            :                                 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
+    1320                 :            : {
+    1321                 :            :     mbedtls_rsa_alt_context *rsa_alt = pk->pk_ctx;
+    1322                 :            : 
+    1323                 :            :     ((void) f_rng);
+    1324                 :            :     ((void) p_rng);
+    1325                 :            : 
+    1326                 :            :     if (ilen != rsa_alt->key_len_func(rsa_alt->key)) {
+    1327                 :            :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    1328                 :            :     }
+    1329                 :            : 
+    1330                 :            :     return rsa_alt->decrypt_func(rsa_alt->key,
+    1331                 :            :                                  olen, input, output, osize);
+    1332                 :            : }
+    1333                 :            : 
+    1334                 :            : #if defined(MBEDTLS_RSA_C)
+    1335                 :            : static int rsa_alt_check_pair(mbedtls_pk_context *pub, mbedtls_pk_context *prv,
+    1336                 :            :                               int (*f_rng)(void *, unsigned char *, size_t),
+    1337                 :            :                               void *p_rng)
+    1338                 :            : {
+    1339                 :            :     unsigned char sig[MBEDTLS_MPI_MAX_SIZE];
+    1340                 :            :     unsigned char hash[32];
+    1341                 :            :     size_t sig_len = 0;
+    1342                 :            :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1343                 :            : 
+    1344                 :            :     if (rsa_alt_get_bitlen(prv) != rsa_get_bitlen(pub)) {
+    1345                 :            :         return MBEDTLS_ERR_RSA_KEY_CHECK_FAILED;
+    1346                 :            :     }
+    1347                 :            : 
+    1348                 :            :     memset(hash, 0x2a, sizeof(hash));
+    1349                 :            : 
+    1350                 :            :     if ((ret = rsa_alt_sign_wrap(prv, MBEDTLS_MD_NONE,
+    1351                 :            :                                  hash, sizeof(hash),
+    1352                 :            :                                  sig, sizeof(sig), &sig_len,
+    1353                 :            :                                  f_rng, p_rng)) != 0) {
+    1354                 :            :         return ret;
+    1355                 :            :     }
+    1356                 :            : 
+    1357                 :            :     if (rsa_verify_wrap(pub, MBEDTLS_MD_NONE,
+    1358                 :            :                         hash, sizeof(hash), sig, sig_len) != 0) {
+    1359                 :            :         return MBEDTLS_ERR_RSA_KEY_CHECK_FAILED;
+    1360                 :            :     }
+    1361                 :            : 
+    1362                 :            :     return 0;
+    1363                 :            : }
+    1364                 :            : #endif /* MBEDTLS_RSA_C */
+    1365                 :            : 
+    1366                 :            : static void *rsa_alt_alloc_wrap(void)
+    1367                 :            : {
+    1368                 :            :     void *ctx = mbedtls_calloc(1, sizeof(mbedtls_rsa_alt_context));
+    1369                 :            : 
+    1370                 :            :     if (ctx != NULL) {
+    1371                 :            :         memset(ctx, 0, sizeof(mbedtls_rsa_alt_context));
+    1372                 :            :     }
+    1373                 :            : 
+    1374                 :            :     return ctx;
+    1375                 :            : }
+    1376                 :            : 
+    1377                 :            : static void rsa_alt_free_wrap(void *ctx)
+    1378                 :            : {
+    1379                 :            :     mbedtls_zeroize_and_free(ctx, sizeof(mbedtls_rsa_alt_context));
+    1380                 :            : }
+    1381                 :            : 
+    1382                 :            : const mbedtls_pk_info_t mbedtls_rsa_alt_info = {
+    1383                 :            :     .type = MBEDTLS_PK_RSA_ALT,
+    1384                 :            :     .name = "RSA-alt",
+    1385                 :            :     .get_bitlen = rsa_alt_get_bitlen,
+    1386                 :            :     .can_do = rsa_alt_can_do,
+    1387                 :            :     .verify_func = NULL,
+    1388                 :            :     .sign_func = rsa_alt_sign_wrap,
+    1389                 :            : #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
+    1390                 :            :     .verify_rs_func = NULL,
+    1391                 :            :     .sign_rs_func = NULL,
+    1392                 :            :     .rs_alloc_func = NULL,
+    1393                 :            :     .rs_free_func = NULL,
+    1394                 :            : #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
+    1395                 :            :     .decrypt_func = rsa_alt_decrypt_wrap,
+    1396                 :            :     .encrypt_func = NULL,
+    1397                 :            : #if defined(MBEDTLS_RSA_C)
+    1398                 :            :     .check_pair_func = rsa_alt_check_pair,
+    1399                 :            : #else
+    1400                 :            :     .check_pair_func = NULL,
+    1401                 :            : #endif
+    1402                 :            :     .ctx_alloc_func = rsa_alt_alloc_wrap,
+    1403                 :            :     .ctx_free_func = rsa_alt_free_wrap,
+    1404                 :            :     .debug_func = NULL,
+    1405                 :            : };
+    1406                 :            : #endif /* MBEDTLS_PK_RSA_ALT_SUPPORT */
+    1407                 :            : 
+    1408                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+    1409                 :            : static size_t opaque_get_bitlen(mbedtls_pk_context *pk)
+    1410                 :            : {
+    1411                 :            :     size_t bits;
+    1412                 :            :     psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
+    1413                 :            : 
+    1414                 :            :     if (PSA_SUCCESS != psa_get_key_attributes(pk->priv_id, &attributes)) {
+    1415                 :            :         return 0;
+    1416                 :            :     }
+    1417                 :            : 
+    1418                 :            :     bits = psa_get_key_bits(&attributes);
+    1419                 :            :     psa_reset_key_attributes(&attributes);
+    1420                 :            :     return bits;
+    1421                 :            : }
+    1422                 :            : 
+    1423                 :            : #if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
+    1424                 :            : static int ecdsa_opaque_can_do(mbedtls_pk_type_t type)
+    1425                 :            : {
+    1426                 :            :     return type == MBEDTLS_PK_ECKEY ||
+    1427                 :            :            type == MBEDTLS_PK_ECDSA;
+    1428                 :            : }
+    1429                 :            : 
+    1430                 :            : const mbedtls_pk_info_t mbedtls_ecdsa_opaque_info = {
+    1431                 :            :     .type = MBEDTLS_PK_OPAQUE,
+    1432                 :            :     .name = "Opaque",
+    1433                 :            :     .get_bitlen = opaque_get_bitlen,
+    1434                 :            :     .can_do = ecdsa_opaque_can_do,
+    1435                 :            : #if defined(MBEDTLS_PK_CAN_ECDSA_VERIFY)
+    1436                 :            :     .verify_func = ecdsa_opaque_verify_wrap,
+    1437                 :            : #else /* MBEDTLS_PK_CAN_ECDSA_VERIFY */
+    1438                 :            :     .verify_func = NULL,
+    1439                 :            : #endif /* MBEDTLS_PK_CAN_ECDSA_VERIFY */
+    1440                 :            : #if defined(MBEDTLS_PK_CAN_ECDSA_SIGN)
+    1441                 :            :     .sign_func = ecdsa_opaque_sign_wrap,
+    1442                 :            : #else /* MBEDTLS_PK_CAN_ECDSA_SIGN */
+    1443                 :            :     .sign_func = NULL,
+    1444                 :            : #endif /* MBEDTLS_PK_CAN_ECDSA_SIGN */
+    1445                 :            : #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
+    1446                 :            :     .verify_rs_func = NULL,
+    1447                 :            :     .sign_rs_func = NULL,
+    1448                 :            :     .rs_alloc_func = NULL,
+    1449                 :            :     .rs_free_func = NULL,
+    1450                 :            : #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
+    1451                 :            :     .decrypt_func = NULL,
+    1452                 :            :     .encrypt_func = NULL,
+    1453                 :            :     .check_pair_func = ecdsa_opaque_check_pair_wrap,
+    1454                 :            :     .ctx_alloc_func = NULL,
+    1455                 :            :     .ctx_free_func = NULL,
+    1456                 :            :     .debug_func = NULL,
+    1457                 :            : };
+    1458                 :            : #endif /* MBEDTLS_PK_HAVE_ECC_KEYS */
+    1459                 :            : 
+    1460                 :            : static int rsa_opaque_can_do(mbedtls_pk_type_t type)
+    1461                 :            : {
+    1462                 :            :     return type == MBEDTLS_PK_RSA ||
+    1463                 :            :            type == MBEDTLS_PK_RSASSA_PSS;
+    1464                 :            : }
+    1465                 :            : 
+    1466                 :            : #if defined(PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC)
+    1467                 :            : static int rsa_opaque_decrypt(mbedtls_pk_context *pk,
+    1468                 :            :                               const unsigned char *input, size_t ilen,
+    1469                 :            :                               unsigned char *output, size_t *olen, size_t osize,
+    1470                 :            :                               int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
+    1471                 :            : {
+    1472                 :            :     psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
+    1473                 :            :     psa_algorithm_t alg;
+    1474                 :            :     psa_key_type_t type;
+    1475                 :            :     psa_status_t status;
+    1476                 :            : 
+    1477                 :            :     /* PSA has its own RNG */
+    1478                 :            :     (void) f_rng;
+    1479                 :            :     (void) p_rng;
+    1480                 :            : 
+    1481                 :            :     status = psa_get_key_attributes(pk->priv_id, &attributes);
+    1482                 :            :     if (status != PSA_SUCCESS) {
+    1483                 :            :         return PSA_PK_TO_MBEDTLS_ERR(status);
+    1484                 :            :     }
+    1485                 :            : 
+    1486                 :            :     type = psa_get_key_type(&attributes);
+    1487                 :            :     alg = psa_get_key_algorithm(&attributes);
+    1488                 :            :     psa_reset_key_attributes(&attributes);
+    1489                 :            : 
+    1490                 :            :     if (!PSA_KEY_TYPE_IS_RSA(type)) {
+    1491                 :            :         return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE;
+    1492                 :            :     }
+    1493                 :            : 
+    1494                 :            :     status = psa_asymmetric_decrypt(pk->priv_id, alg, input, ilen, NULL, 0, output, osize, olen);
+    1495                 :            :     if (status != PSA_SUCCESS) {
+    1496                 :            :         return PSA_PK_RSA_TO_MBEDTLS_ERR(status);
+    1497                 :            :     }
+    1498                 :            : 
+    1499                 :            :     return 0;
+    1500                 :            : }
+    1501                 :            : #endif /* PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC */
+    1502                 :            : 
+    1503                 :            : static int rsa_opaque_sign_wrap(mbedtls_pk_context *pk, mbedtls_md_type_t md_alg,
+    1504                 :            :                                 const unsigned char *hash, size_t hash_len,
+    1505                 :            :                                 unsigned char *sig, size_t sig_size, size_t *sig_len,
+    1506                 :            :                                 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
+    1507                 :            : {
+    1508                 :            : #if defined(MBEDTLS_RSA_C)
+    1509                 :            :     psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
+    1510                 :            :     psa_algorithm_t alg;
+    1511                 :            :     psa_key_type_t type;
+    1512                 :            :     psa_status_t status;
+    1513                 :            : 
+    1514                 :            :     /* PSA has its own RNG */
+    1515                 :            :     (void) f_rng;
+    1516                 :            :     (void) p_rng;
+    1517                 :            : 
+    1518                 :            :     status = psa_get_key_attributes(pk->priv_id, &attributes);
+    1519                 :            :     if (status != PSA_SUCCESS) {
+    1520                 :            :         return PSA_PK_TO_MBEDTLS_ERR(status);
+    1521                 :            :     }
+    1522                 :            : 
+    1523                 :            :     type = psa_get_key_type(&attributes);
+    1524                 :            :     alg = psa_get_key_algorithm(&attributes);
+    1525                 :            :     psa_reset_key_attributes(&attributes);
+    1526                 :            : 
+    1527                 :            :     if (PSA_KEY_TYPE_IS_RSA(type)) {
+    1528                 :            :         alg = (alg & ~PSA_ALG_HASH_MASK) | mbedtls_md_psa_alg_from_type(md_alg);
+    1529                 :            :     } else {
+    1530                 :            :         return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE;
+    1531                 :            :     }
+    1532                 :            : 
+    1533                 :            :     status = psa_sign_hash(pk->priv_id, alg, hash, hash_len, sig, sig_size, sig_len);
+    1534                 :            :     if (status != PSA_SUCCESS) {
+    1535                 :            :         if (PSA_KEY_TYPE_IS_RSA(type)) {
+    1536                 :            :             return PSA_PK_RSA_TO_MBEDTLS_ERR(status);
+    1537                 :            :         } else {
+    1538                 :            :             return PSA_PK_TO_MBEDTLS_ERR(status);
+    1539                 :            :         }
+    1540                 :            :     }
+    1541                 :            : 
+    1542                 :            :     return 0;
+    1543                 :            : #else /* !MBEDTLS_RSA_C */
+    1544                 :            :     ((void) pk);
+    1545                 :            :     ((void) md_alg);
+    1546                 :            :     ((void) hash);
+    1547                 :            :     ((void) hash_len);
+    1548                 :            :     ((void) sig);
+    1549                 :            :     ((void) sig_size);
+    1550                 :            :     ((void) sig_len);
+    1551                 :            :     ((void) f_rng);
+    1552                 :            :     ((void) p_rng);
+    1553                 :            :     return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE;
+    1554                 :            : #endif /* !MBEDTLS_RSA_C */
+    1555                 :            : }
+    1556                 :            : 
+    1557                 :            : const mbedtls_pk_info_t mbedtls_rsa_opaque_info = {
+    1558                 :            :     .type = MBEDTLS_PK_OPAQUE,
+    1559                 :            :     .name = "Opaque",
+    1560                 :            :     .get_bitlen = opaque_get_bitlen,
+    1561                 :            :     .can_do = rsa_opaque_can_do,
+    1562                 :            :     .verify_func = NULL,
+    1563                 :            :     .sign_func = rsa_opaque_sign_wrap,
+    1564                 :            : #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
+    1565                 :            :     .verify_rs_func = NULL,
+    1566                 :            :     .sign_rs_func = NULL,
+    1567                 :            :     .rs_alloc_func = NULL,
+    1568                 :            :     .rs_free_func = NULL,
+    1569                 :            : #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
+    1570                 :            : #if defined(PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC)
+    1571                 :            :     .decrypt_func = rsa_opaque_decrypt,
+    1572                 :            : #else /* PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC */
+    1573                 :            :     .decrypt_func = NULL,
+    1574                 :            : #endif /* PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC */
+    1575                 :            :     .encrypt_func = NULL,
+    1576                 :            :     .check_pair_func = NULL,
+    1577                 :            :     .ctx_alloc_func = NULL,
+    1578                 :            :     .ctx_free_func = NULL,
+    1579                 :            :     .debug_func = NULL,
+    1580                 :            : };
+    1581                 :            : 
+    1582                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO */
+    1583                 :            : 
+    1584                 :            : #endif /* MBEDTLS_PK_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/pkparse.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pkparse.c.func-sort-c.html new file mode 100644 index 00000000000..b397077468f --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pkparse.c.func-sort-c.html @@ -0,0 +1,129 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/pkparse.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - pkparse.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:13730145.5 %
Date:2024-09-22 08:21:07Functions:71258.3 %
Branches:8223235.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
pk_ecc_group_id_from_specified0
pk_ecc_tag_is_specified_ec_domain0
pk_get_ecparams0
pk_parse_key_rfc8410_der0
pk_use_ecparams_rfc84100
mbedtls_pk_parse_public_key5
pk_parse_key_sec1_der128
mbedtls_pk_parse_key153
pk_parse_key_pkcs8_unencrypted_der153
pk_use_ecparams11161
mbedtls_pk_parse_subpubkey12130
pk_get_pk_alg12283
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/pkparse.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pkparse.c.func.html new file mode 100644 index 00000000000..b05ab358aba --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pkparse.c.func.html @@ -0,0 +1,129 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/pkparse.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - pkparse.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:13730145.5 %
Date:2024-09-22 08:21:07Functions:71258.3 %
Branches:8223235.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_pk_parse_key153
mbedtls_pk_parse_public_key5
mbedtls_pk_parse_subpubkey12130
pk_ecc_group_id_from_specified0
pk_ecc_tag_is_specified_ec_domain0
pk_get_ecparams0
pk_get_pk_alg12283
pk_parse_key_pkcs8_unencrypted_der153
pk_parse_key_rfc8410_der0
pk_parse_key_sec1_der128
pk_use_ecparams11161
pk_use_ecparams_rfc84100
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/pkparse.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pkparse.c.gcov.html new file mode 100644 index 00000000000..76cf8d5a88e --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pkparse.c.gcov.html @@ -0,0 +1,1477 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/pkparse.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - pkparse.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:13730145.5 %
Date:2024-09-22 08:21:07Functions:71258.3 %
Branches:8223235.3 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  *  Public Key layer for parsing key files and structures
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  */
+       7                 :            : 
+       8                 :            : #include "common.h"
+       9                 :            : 
+      10                 :            : #if defined(MBEDTLS_PK_PARSE_C)
+      11                 :            : 
+      12                 :            : #include "mbedtls/pk.h"
+      13                 :            : #include "mbedtls/asn1.h"
+      14                 :            : #include "mbedtls/oid.h"
+      15                 :            : #include "mbedtls/platform_util.h"
+      16                 :            : #include "mbedtls/platform.h"
+      17                 :            : #include "mbedtls/error.h"
+      18                 :            : #include "mbedtls/ecp.h"
+      19                 :            : #include "pk_internal.h"
+      20                 :            : 
+      21                 :            : #include <string.h>
+      22                 :            : 
+      23                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+      24                 :            : #include "mbedtls/psa_util.h"
+      25                 :            : #include "psa/crypto.h"
+      26                 :            : #endif
+      27                 :            : 
+      28                 :            : /* Key types */
+      29                 :            : #if defined(MBEDTLS_RSA_C)
+      30                 :            : #include "mbedtls/rsa.h"
+      31                 :            : #include "rsa_internal.h"
+      32                 :            : #endif
+      33                 :            : 
+      34                 :            : /* Extended formats */
+      35                 :            : #if defined(MBEDTLS_PEM_PARSE_C)
+      36                 :            : #include "mbedtls/pem.h"
+      37                 :            : #endif
+      38                 :            : #if defined(MBEDTLS_PKCS5_C)
+      39                 :            : #include "mbedtls/pkcs5.h"
+      40                 :            : #endif
+      41                 :            : #if defined(MBEDTLS_PKCS12_C)
+      42                 :            : #include "mbedtls/pkcs12.h"
+      43                 :            : #endif
+      44                 :            : 
+      45                 :            : #if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
+      46                 :            : 
+      47                 :            : /***********************************************************************
+      48                 :            :  *
+      49                 :            :  *      Low-level ECC parsing: optional support for SpecifiedECDomain
+      50                 :            :  *
+      51                 :            :  * There are two functions here that are used by the rest of the code:
+      52                 :            :  * - pk_ecc_tag_is_speficied_ec_domain()
+      53                 :            :  * - pk_ecc_group_id_from_specified()
+      54                 :            :  *
+      55                 :            :  * All the other functions are internal to this section.
+      56                 :            :  *
+      57                 :            :  * The two "public" functions have a dummy variant provided
+      58                 :            :  * in configs without MBEDTLS_PK_PARSE_EC_EXTENDED. This acts as an
+      59                 :            :  * abstraction layer for this macro, which should not appear outside
+      60                 :            :  * this section.
+      61                 :            :  *
+      62                 :            :  **********************************************************************/
+      63                 :            : 
+      64                 :            : #if !defined(MBEDTLS_PK_PARSE_EC_EXTENDED)
+      65                 :            : /* See the "real" version for documentation */
+      66                 :          0 : static int pk_ecc_tag_is_specified_ec_domain(int tag)
+      67                 :            : {
+      68                 :            :     (void) tag;
+      69                 :          0 :     return 0;
+      70                 :            : }
+      71                 :            : 
+      72                 :            : /* See the "real" version for documentation */
+      73                 :          0 : static int pk_ecc_group_id_from_specified(const mbedtls_asn1_buf *params,
+      74                 :            :                                           mbedtls_ecp_group_id *grp_id)
+      75                 :            : {
+      76                 :            :     (void) params;
+      77                 :            :     (void) grp_id;
+      78                 :          0 :     return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
+      79                 :            : }
+      80                 :            : #else /* MBEDTLS_PK_PARSE_EC_EXTENDED */
+      81                 :            : /*
+      82                 :            :  * Tell if the passed tag might be the start of SpecifiedECDomain
+      83                 :            :  * (that is, a sequence).
+      84                 :            :  */
+      85                 :            : static int pk_ecc_tag_is_specified_ec_domain(int tag)
+      86                 :            : {
+      87                 :            :     return tag == (MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE);
+      88                 :            : }
+      89                 :            : 
+      90                 :            : /*
+      91                 :            :  * Parse a SpecifiedECDomain (SEC 1 C.2) and (mostly) fill the group with it.
+      92                 :            :  * WARNING: the resulting group should only be used with
+      93                 :            :  * pk_ecc_group_id_from_specified(), since its base point may not be set correctly
+      94                 :            :  * if it was encoded compressed.
+      95                 :            :  *
+      96                 :            :  *  SpecifiedECDomain ::= SEQUENCE {
+      97                 :            :  *      version SpecifiedECDomainVersion(ecdpVer1 | ecdpVer2 | ecdpVer3, ...),
+      98                 :            :  *      fieldID FieldID {{FieldTypes}},
+      99                 :            :  *      curve Curve,
+     100                 :            :  *      base ECPoint,
+     101                 :            :  *      order INTEGER,
+     102                 :            :  *      cofactor INTEGER OPTIONAL,
+     103                 :            :  *      hash HashAlgorithm OPTIONAL,
+     104                 :            :  *      ...
+     105                 :            :  *  }
+     106                 :            :  *
+     107                 :            :  * We only support prime-field as field type, and ignore hash and cofactor.
+     108                 :            :  */
+     109                 :            : static int pk_group_from_specified(const mbedtls_asn1_buf *params, mbedtls_ecp_group *grp)
+     110                 :            : {
+     111                 :            :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     112                 :            :     unsigned char *p = params->p;
+     113                 :            :     const unsigned char *const end = params->p + params->len;
+     114                 :            :     const unsigned char *end_field, *end_curve;
+     115                 :            :     size_t len;
+     116                 :            :     int ver;
+     117                 :            : 
+     118                 :            :     /* SpecifiedECDomainVersion ::= INTEGER { 1, 2, 3 } */
+     119                 :            :     if ((ret = mbedtls_asn1_get_int(&p, end, &ver)) != 0) {
+     120                 :            :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret);
+     121                 :            :     }
+     122                 :            : 
+     123                 :            :     if (ver < 1 || ver > 3) {
+     124                 :            :         return MBEDTLS_ERR_PK_KEY_INVALID_FORMAT;
+     125                 :            :     }
+     126                 :            : 
+     127                 :            :     /*
+     128                 :            :      * FieldID { FIELD-ID:IOSet } ::= SEQUENCE { -- Finite field
+     129                 :            :      *       fieldType FIELD-ID.&id({IOSet}),
+     130                 :            :      *       parameters FIELD-ID.&Type({IOSet}{@fieldType})
+     131                 :            :      * }
+     132                 :            :      */
+     133                 :            :     if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
+     134                 :            :                                     MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
+     135                 :            :         return ret;
+     136                 :            :     }
+     137                 :            : 
+     138                 :            :     end_field = p + len;
+     139                 :            : 
+     140                 :            :     /*
+     141                 :            :      * FIELD-ID ::= TYPE-IDENTIFIER
+     142                 :            :      * FieldTypes FIELD-ID ::= {
+     143                 :            :      *       { Prime-p IDENTIFIED BY prime-field } |
+     144                 :            :      *       { Characteristic-two IDENTIFIED BY characteristic-two-field }
+     145                 :            :      * }
+     146                 :            :      * prime-field OBJECT IDENTIFIER ::= { id-fieldType 1 }
+     147                 :            :      */
+     148                 :            :     if ((ret = mbedtls_asn1_get_tag(&p, end_field, &len, MBEDTLS_ASN1_OID)) != 0) {
+     149                 :            :         return ret;
+     150                 :            :     }
+     151                 :            : 
+     152                 :            :     if (len != MBEDTLS_OID_SIZE(MBEDTLS_OID_ANSI_X9_62_PRIME_FIELD) ||
+     153                 :            :         memcmp(p, MBEDTLS_OID_ANSI_X9_62_PRIME_FIELD, len) != 0) {
+     154                 :            :         return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE;
+     155                 :            :     }
+     156                 :            : 
+     157                 :            :     p += len;
+     158                 :            : 
+     159                 :            :     /* Prime-p ::= INTEGER -- Field of size p. */
+     160                 :            :     if ((ret = mbedtls_asn1_get_mpi(&p, end_field, &grp->P)) != 0) {
+     161                 :            :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret);
+     162                 :            :     }
+     163                 :            : 
+     164                 :            :     grp->pbits = mbedtls_mpi_bitlen(&grp->P);
+     165                 :            : 
+     166                 :            :     if (p != end_field) {
+     167                 :            :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT,
+     168                 :            :                                  MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
+     169                 :            :     }
+     170                 :            : 
+     171                 :            :     /*
+     172                 :            :      * Curve ::= SEQUENCE {
+     173                 :            :      *       a FieldElement,
+     174                 :            :      *       b FieldElement,
+     175                 :            :      *       seed BIT STRING OPTIONAL
+     176                 :            :      *       -- Shall be present if used in SpecifiedECDomain
+     177                 :            :      *       -- with version equal to ecdpVer2 or ecdpVer3
+     178                 :            :      * }
+     179                 :            :      */
+     180                 :            :     if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
+     181                 :            :                                     MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
+     182                 :            :         return ret;
+     183                 :            :     }
+     184                 :            : 
+     185                 :            :     end_curve = p + len;
+     186                 :            : 
+     187                 :            :     /*
+     188                 :            :      * FieldElement ::= OCTET STRING
+     189                 :            :      * containing an integer in the case of a prime field
+     190                 :            :      */
+     191                 :            :     if ((ret = mbedtls_asn1_get_tag(&p, end_curve, &len, MBEDTLS_ASN1_OCTET_STRING)) != 0 ||
+     192                 :            :         (ret = mbedtls_mpi_read_binary(&grp->A, p, len)) != 0) {
+     193                 :            :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret);
+     194                 :            :     }
+     195                 :            : 
+     196                 :            :     p += len;
+     197                 :            : 
+     198                 :            :     if ((ret = mbedtls_asn1_get_tag(&p, end_curve, &len, MBEDTLS_ASN1_OCTET_STRING)) != 0 ||
+     199                 :            :         (ret = mbedtls_mpi_read_binary(&grp->B, p, len)) != 0) {
+     200                 :            :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret);
+     201                 :            :     }
+     202                 :            : 
+     203                 :            :     p += len;
+     204                 :            : 
+     205                 :            :     /* Ignore seed BIT STRING OPTIONAL */
+     206                 :            :     if ((ret = mbedtls_asn1_get_tag(&p, end_curve, &len, MBEDTLS_ASN1_BIT_STRING)) == 0) {
+     207                 :            :         p += len;
+     208                 :            :     }
+     209                 :            : 
+     210                 :            :     if (p != end_curve) {
+     211                 :            :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT,
+     212                 :            :                                  MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
+     213                 :            :     }
+     214                 :            : 
+     215                 :            :     /*
+     216                 :            :      * ECPoint ::= OCTET STRING
+     217                 :            :      */
+     218                 :            :     if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_OCTET_STRING)) != 0) {
+     219                 :            :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret);
+     220                 :            :     }
+     221                 :            : 
+     222                 :            :     if ((ret = mbedtls_ecp_point_read_binary(grp, &grp->G,
+     223                 :            :                                              (const unsigned char *) p, len)) != 0) {
+     224                 :            :         /*
+     225                 :            :          * If we can't read the point because it's compressed, cheat by
+     226                 :            :          * reading only the X coordinate and the parity bit of Y.
+     227                 :            :          */
+     228                 :            :         if (ret != MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE ||
+     229                 :            :             (p[0] != 0x02 && p[0] != 0x03) ||
+     230                 :            :             len != mbedtls_mpi_size(&grp->P) + 1 ||
+     231                 :            :             mbedtls_mpi_read_binary(&grp->G.X, p + 1, len - 1) != 0 ||
+     232                 :            :             mbedtls_mpi_lset(&grp->G.Y, p[0] - 2) != 0 ||
+     233                 :            :             mbedtls_mpi_lset(&grp->G.Z, 1) != 0) {
+     234                 :            :             return MBEDTLS_ERR_PK_KEY_INVALID_FORMAT;
+     235                 :            :         }
+     236                 :            :     }
+     237                 :            : 
+     238                 :            :     p += len;
+     239                 :            : 
+     240                 :            :     /*
+     241                 :            :      * order INTEGER
+     242                 :            :      */
+     243                 :            :     if ((ret = mbedtls_asn1_get_mpi(&p, end, &grp->N)) != 0) {
+     244                 :            :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret);
+     245                 :            :     }
+     246                 :            : 
+     247                 :            :     grp->nbits = mbedtls_mpi_bitlen(&grp->N);
+     248                 :            : 
+     249                 :            :     /*
+     250                 :            :      * Allow optional elements by purposefully not enforcing p == end here.
+     251                 :            :      */
+     252                 :            : 
+     253                 :            :     return 0;
+     254                 :            : }
+     255                 :            : 
+     256                 :            : /*
+     257                 :            :  * Find the group id associated with an (almost filled) group as generated by
+     258                 :            :  * pk_group_from_specified(), or return an error if unknown.
+     259                 :            :  */
+     260                 :            : static int pk_group_id_from_group(const mbedtls_ecp_group *grp, mbedtls_ecp_group_id *grp_id)
+     261                 :            : {
+     262                 :            :     int ret = 0;
+     263                 :            :     mbedtls_ecp_group ref;
+     264                 :            :     const mbedtls_ecp_group_id *id;
+     265                 :            : 
+     266                 :            :     mbedtls_ecp_group_init(&ref);
+     267                 :            : 
+     268                 :            :     for (id = mbedtls_ecp_grp_id_list(); *id != MBEDTLS_ECP_DP_NONE; id++) {
+     269                 :            :         /* Load the group associated to that id */
+     270                 :            :         mbedtls_ecp_group_free(&ref);
+     271                 :            :         MBEDTLS_MPI_CHK(mbedtls_ecp_group_load(&ref, *id));
+     272                 :            : 
+     273                 :            :         /* Compare to the group we were given, starting with easy tests */
+     274                 :            :         if (grp->pbits == ref.pbits && grp->nbits == ref.nbits &&
+     275                 :            :             mbedtls_mpi_cmp_mpi(&grp->P, &ref.P) == 0 &&
+     276                 :            :             mbedtls_mpi_cmp_mpi(&grp->A, &ref.A) == 0 &&
+     277                 :            :             mbedtls_mpi_cmp_mpi(&grp->B, &ref.B) == 0 &&
+     278                 :            :             mbedtls_mpi_cmp_mpi(&grp->N, &ref.N) == 0 &&
+     279                 :            :             mbedtls_mpi_cmp_mpi(&grp->G.X, &ref.G.X) == 0 &&
+     280                 :            :             mbedtls_mpi_cmp_mpi(&grp->G.Z, &ref.G.Z) == 0 &&
+     281                 :            :             /* For Y we may only know the parity bit, so compare only that */
+     282                 :            :             mbedtls_mpi_get_bit(&grp->G.Y, 0) == mbedtls_mpi_get_bit(&ref.G.Y, 0)) {
+     283                 :            :             break;
+     284                 :            :         }
+     285                 :            :     }
+     286                 :            : 
+     287                 :            : cleanup:
+     288                 :            :     mbedtls_ecp_group_free(&ref);
+     289                 :            : 
+     290                 :            :     *grp_id = *id;
+     291                 :            : 
+     292                 :            :     if (ret == 0 && *id == MBEDTLS_ECP_DP_NONE) {
+     293                 :            :         ret = MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
+     294                 :            :     }
+     295                 :            : 
+     296                 :            :     return ret;
+     297                 :            : }
+     298                 :            : 
+     299                 :            : /*
+     300                 :            :  * Parse a SpecifiedECDomain (SEC 1 C.2) and find the associated group ID
+     301                 :            :  */
+     302                 :            : static int pk_ecc_group_id_from_specified(const mbedtls_asn1_buf *params,
+     303                 :            :                                           mbedtls_ecp_group_id *grp_id)
+     304                 :            : {
+     305                 :            :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     306                 :            :     mbedtls_ecp_group grp;
+     307                 :            : 
+     308                 :            :     mbedtls_ecp_group_init(&grp);
+     309                 :            : 
+     310                 :            :     if ((ret = pk_group_from_specified(params, &grp)) != 0) {
+     311                 :            :         goto cleanup;
+     312                 :            :     }
+     313                 :            : 
+     314                 :            :     ret = pk_group_id_from_group(&grp, grp_id);
+     315                 :            : 
+     316                 :            : cleanup:
+     317                 :            :     /* The API respecting lifecycle for mbedtls_ecp_group struct is
+     318                 :            :      * _init(), _load() and _free(). In pk_ecc_group_id_from_specified() the
+     319                 :            :      * temporary grp breaks that flow and it's members are populated
+     320                 :            :      * by pk_group_id_from_group(). As such mbedtls_ecp_group_free()
+     321                 :            :      * which is assuming a group populated by _setup() may not clean-up
+     322                 :            :      * properly -> Manually free it's members.
+     323                 :            :      */
+     324                 :            :     mbedtls_mpi_free(&grp.N);
+     325                 :            :     mbedtls_mpi_free(&grp.P);
+     326                 :            :     mbedtls_mpi_free(&grp.A);
+     327                 :            :     mbedtls_mpi_free(&grp.B);
+     328                 :            :     mbedtls_ecp_point_free(&grp.G);
+     329                 :            : 
+     330                 :            :     return ret;
+     331                 :            : }
+     332                 :            : #endif /* MBEDTLS_PK_PARSE_EC_EXTENDED */
+     333                 :            : 
+     334                 :            : /***********************************************************************
+     335                 :            :  *
+     336                 :            :  * Unsorted (yet!) from this point on until the next section header
+     337                 :            :  *
+     338                 :            :  **********************************************************************/
+     339                 :            : 
+     340                 :            : /* Minimally parse an ECParameters buffer to and mbedtls_asn1_buf
+     341                 :            :  *
+     342                 :            :  * ECParameters ::= CHOICE {
+     343                 :            :  *   namedCurve         OBJECT IDENTIFIER
+     344                 :            :  *   specifiedCurve     SpecifiedECDomain -- = SEQUENCE { ... }
+     345                 :            :  *   -- implicitCurve   NULL
+     346                 :            :  * }
+     347                 :            :  */
+     348                 :          0 : static int pk_get_ecparams(unsigned char **p, const unsigned char *end,
+     349                 :            :                            mbedtls_asn1_buf *params)
+     350                 :            : {
+     351                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     352                 :            : 
+     353         [ #  # ]:          0 :     if (end - *p < 1) {
+     354                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT,
+     355                 :            :                                  MBEDTLS_ERR_ASN1_OUT_OF_DATA);
+     356                 :            :     }
+     357                 :            : 
+     358                 :            :     /* Acceptable tags: OID for namedCurve, or specifiedECDomain */
+     359                 :          0 :     params->tag = **p;
+     360   [ #  #  #  # ]:          0 :     if (params->tag != MBEDTLS_ASN1_OID &&
+     361                 :          0 :         !pk_ecc_tag_is_specified_ec_domain(params->tag)) {
+     362                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT,
+     363                 :            :                                  MBEDTLS_ERR_ASN1_UNEXPECTED_TAG);
+     364                 :            :     }
+     365                 :            : 
+     366         [ #  # ]:          0 :     if ((ret = mbedtls_asn1_get_tag(p, end, &params->len, params->tag)) != 0) {
+     367                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret);
+     368                 :            :     }
+     369                 :            : 
+     370                 :          0 :     params->p = *p;
+     371                 :          0 :     *p += params->len;
+     372                 :            : 
+     373         [ #  # ]:          0 :     if (*p != end) {
+     374                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT,
+     375                 :            :                                  MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
+     376                 :            :     }
+     377                 :            : 
+     378                 :          0 :     return 0;
+     379                 :            : }
+     380                 :            : 
+     381                 :            : /*
+     382                 :            :  * Use EC parameters to initialise an EC group
+     383                 :            :  *
+     384                 :            :  * ECParameters ::= CHOICE {
+     385                 :            :  *   namedCurve         OBJECT IDENTIFIER
+     386                 :            :  *   specifiedCurve     SpecifiedECDomain -- = SEQUENCE { ... }
+     387                 :            :  *   -- implicitCurve   NULL
+     388                 :            :  */
+     389                 :      11161 : static int pk_use_ecparams(const mbedtls_asn1_buf *params, mbedtls_pk_context *pk)
+     390                 :            : {
+     391                 :      11161 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     392                 :            :     mbedtls_ecp_group_id grp_id;
+     393                 :            : 
+     394         [ +  - ]:      11161 :     if (params->tag == MBEDTLS_ASN1_OID) {
+     395         [ -  + ]:      11161 :         if (mbedtls_oid_get_ec_grp(params, &grp_id) != 0) {
+     396                 :          0 :             return MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE;
+     397                 :            :         }
+     398                 :            :     } else {
+     399                 :          0 :         ret = pk_ecc_group_id_from_specified(params, &grp_id);
+     400         [ #  # ]:          0 :         if (ret != 0) {
+     401                 :          0 :             return ret;
+     402                 :            :         }
+     403                 :            :     }
+     404                 :            : 
+     405                 :      11161 :     return mbedtls_pk_ecc_set_group(pk, grp_id);
+     406                 :            : }
+     407                 :            : 
+     408                 :            : #if defined(MBEDTLS_PK_HAVE_RFC8410_CURVES)
+     409                 :            : 
+     410                 :            : /*
+     411                 :            :  * Load an RFC8410 EC key, which doesn't have any parameters
+     412                 :            :  */
+     413                 :          0 : static int pk_use_ecparams_rfc8410(const mbedtls_asn1_buf *params,
+     414                 :            :                                    mbedtls_ecp_group_id grp_id,
+     415                 :            :                                    mbedtls_pk_context *pk)
+     416                 :            : {
+     417   [ #  #  #  # ]:          0 :     if (params->tag != 0 || params->len != 0) {
+     418                 :          0 :         return MBEDTLS_ERR_PK_KEY_INVALID_FORMAT;
+     419                 :            :     }
+     420                 :            : 
+     421                 :          0 :     return mbedtls_pk_ecc_set_group(pk, grp_id);
+     422                 :            : }
+     423                 :            : 
+     424                 :            : /*
+     425                 :            :  * Parse an RFC 8410 encoded private EC key
+     426                 :            :  *
+     427                 :            :  * CurvePrivateKey ::= OCTET STRING
+     428                 :            :  */
+     429                 :          0 : static int pk_parse_key_rfc8410_der(mbedtls_pk_context *pk,
+     430                 :            :                                     unsigned char *key, size_t keylen, const unsigned char *end,
+     431                 :            :                                     int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
+     432                 :            : {
+     433                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     434                 :            :     size_t len;
+     435                 :            : 
+     436         [ #  # ]:          0 :     if ((ret = mbedtls_asn1_get_tag(&key, (key + keylen), &len, MBEDTLS_ASN1_OCTET_STRING)) != 0) {
+     437                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret);
+     438                 :            :     }
+     439                 :            : 
+     440         [ #  # ]:          0 :     if (key + len != end) {
+     441                 :          0 :         return MBEDTLS_ERR_PK_KEY_INVALID_FORMAT;
+     442                 :            :     }
+     443                 :            : 
+     444                 :            :     /*
+     445                 :            :      * Load the private key
+     446                 :            :      */
+     447                 :          0 :     ret = mbedtls_pk_ecc_set_key(pk, key, len);
+     448         [ #  # ]:          0 :     if (ret != 0) {
+     449                 :          0 :         return ret;
+     450                 :            :     }
+     451                 :            : 
+     452                 :            :     /* pk_parse_key_pkcs8_unencrypted_der() only supports version 1 PKCS8 keys,
+     453                 :            :      * which never contain a public key. As such, derive the public key
+     454                 :            :      * unconditionally. */
+     455         [ #  # ]:          0 :     if ((ret = mbedtls_pk_ecc_set_pubkey_from_prv(pk, key, len, f_rng, p_rng)) != 0) {
+     456                 :          0 :         return ret;
+     457                 :            :     }
+     458                 :            : 
+     459                 :          0 :     return 0;
+     460                 :            : }
+     461                 :            : #endif /* MBEDTLS_PK_HAVE_RFC8410_CURVES */
+     462                 :            : 
+     463                 :            : #endif /* MBEDTLS_PK_HAVE_ECC_KEYS */
+     464                 :            : 
+     465                 :            : /* Get a PK algorithm identifier
+     466                 :            :  *
+     467                 :            :  *  AlgorithmIdentifier  ::=  SEQUENCE  {
+     468                 :            :  *       algorithm               OBJECT IDENTIFIER,
+     469                 :            :  *       parameters              ANY DEFINED BY algorithm OPTIONAL  }
+     470                 :            :  */
+     471                 :      12283 : static int pk_get_pk_alg(unsigned char **p,
+     472                 :            :                          const unsigned char *end,
+     473                 :            :                          mbedtls_pk_type_t *pk_alg, mbedtls_asn1_buf *params,
+     474                 :            :                          mbedtls_ecp_group_id *ec_grp_id)
+     475                 :            : {
+     476                 :      12283 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     477                 :            :     mbedtls_asn1_buf alg_oid;
+     478                 :            : 
+     479                 :      12283 :     memset(params, 0, sizeof(mbedtls_asn1_buf));
+     480                 :            : 
+     481         [ -  + ]:      12283 :     if ((ret = mbedtls_asn1_get_alg(p, end, &alg_oid, params)) != 0) {
+     482                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_INVALID_ALG, ret);
+     483                 :            :     }
+     484                 :            : 
+     485                 :      12283 :     ret = mbedtls_oid_get_pk_alg(&alg_oid, pk_alg);
+     486                 :            : #if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
+     487         [ -  + ]:      12283 :     if (ret == MBEDTLS_ERR_OID_NOT_FOUND) {
+     488                 :          0 :         ret = mbedtls_oid_get_ec_grp_algid(&alg_oid, ec_grp_id);
+     489         [ #  # ]:          0 :         if (ret == 0) {
+     490                 :          0 :             *pk_alg = MBEDTLS_PK_ECKEY;
+     491                 :            :         }
+     492                 :            :     }
+     493                 :            : #else
+     494                 :            :     (void) ec_grp_id;
+     495                 :            : #endif
+     496         [ -  + ]:      12283 :     if (ret != 0) {
+     497                 :          0 :         return MBEDTLS_ERR_PK_UNKNOWN_PK_ALG;
+     498                 :            :     }
+     499                 :            : 
+     500                 :            :     /*
+     501                 :            :      * No parameters with RSA (only for EC)
+     502                 :            :      */
+     503         [ +  + ]:      12283 :     if (*pk_alg == MBEDTLS_PK_RSA &&
+     504   [ -  +  -  - ]:       1122 :         ((params->tag != MBEDTLS_ASN1_NULL && params->tag != 0) ||
+     505         [ -  + ]:       1122 :          params->len != 0)) {
+     506                 :          0 :         return MBEDTLS_ERR_PK_INVALID_ALG;
+     507                 :            :     }
+     508                 :            : 
+     509                 :      12283 :     return 0;
+     510                 :            : }
+     511                 :            : 
+     512                 :            : /*
+     513                 :            :  *  SubjectPublicKeyInfo  ::=  SEQUENCE  {
+     514                 :            :  *       algorithm            AlgorithmIdentifier,
+     515                 :            :  *       subjectPublicKey     BIT STRING }
+     516                 :            :  */
+     517                 :      12130 : int mbedtls_pk_parse_subpubkey(unsigned char **p, const unsigned char *end,
+     518                 :            :                                mbedtls_pk_context *pk)
+     519                 :            : {
+     520                 :      12130 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     521                 :            :     size_t len;
+     522                 :            :     mbedtls_asn1_buf alg_params;
+     523                 :      12130 :     mbedtls_pk_type_t pk_alg = MBEDTLS_PK_NONE;
+     524                 :      12130 :     mbedtls_ecp_group_id ec_grp_id = MBEDTLS_ECP_DP_NONE;
+     525                 :            :     const mbedtls_pk_info_t *pk_info;
+     526                 :            : 
+     527         [ -  + ]:      12130 :     if ((ret = mbedtls_asn1_get_tag(p, end, &len,
+     528                 :            :                                     MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
+     529                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret);
+     530                 :            :     }
+     531                 :            : 
+     532                 :      12130 :     end = *p + len;
+     533                 :            : 
+     534         [ -  + ]:      12130 :     if ((ret = pk_get_pk_alg(p, end, &pk_alg, &alg_params, &ec_grp_id)) != 0) {
+     535                 :          0 :         return ret;
+     536                 :            :     }
+     537                 :            : 
+     538         [ -  + ]:      12130 :     if ((ret = mbedtls_asn1_get_bitstring_null(p, end, &len)) != 0) {
+     539                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_INVALID_PUBKEY, ret);
+     540                 :            :     }
+     541                 :            : 
+     542         [ -  + ]:      12130 :     if (*p + len != end) {
+     543                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_INVALID_PUBKEY,
+     544                 :            :                                  MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
+     545                 :            :     }
+     546                 :            : 
+     547         [ -  + ]:      12130 :     if ((pk_info = mbedtls_pk_info_from_type(pk_alg)) == NULL) {
+     548                 :          0 :         return MBEDTLS_ERR_PK_UNKNOWN_PK_ALG;
+     549                 :            :     }
+     550                 :            : 
+     551         [ -  + ]:      12130 :     if ((ret = mbedtls_pk_setup(pk, pk_info)) != 0) {
+     552                 :          0 :         return ret;
+     553                 :            :     }
+     554                 :            : 
+     555                 :            : #if defined(MBEDTLS_RSA_C)
+     556         [ +  + ]:      12130 :     if (pk_alg == MBEDTLS_PK_RSA) {
+     557                 :       1097 :         ret = mbedtls_rsa_parse_pubkey(mbedtls_pk_rsa(*pk), *p, (size_t) (end - *p));
+     558         [ +  - ]:       1097 :         if (ret == 0) {
+     559                 :            :             /* On success all the input has been consumed by the parsing function. */
+     560                 :       1097 :             *p += end - *p;
+     561   [ #  #  #  # ]:          0 :         } else if ((ret <= MBEDTLS_ERR_ASN1_OUT_OF_DATA) &&
+     562                 :            :                    (ret >= MBEDTLS_ERR_ASN1_BUF_TOO_SMALL)) {
+     563                 :            :             /* In case of ASN1 error codes add MBEDTLS_ERR_PK_INVALID_PUBKEY. */
+     564                 :          0 :             ret = MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_INVALID_PUBKEY, ret);
+     565                 :            :         } else {
+     566                 :          0 :             ret = MBEDTLS_ERR_PK_INVALID_PUBKEY;
+     567                 :            :         }
+     568                 :            :     } else
+     569                 :            : #endif /* MBEDTLS_RSA_C */
+     570                 :            : #if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
+     571   [ +  -  +  - ]:      11033 :     if (pk_alg == MBEDTLS_PK_ECKEY_DH || pk_alg == MBEDTLS_PK_ECKEY) {
+     572                 :            : #if defined(MBEDTLS_PK_HAVE_RFC8410_CURVES)
+     573   [ +  -  -  + ]:      11033 :         if (MBEDTLS_PK_IS_RFC8410_GROUP_ID(ec_grp_id)) {
+     574                 :          0 :             ret = pk_use_ecparams_rfc8410(&alg_params, ec_grp_id, pk);
+     575                 :            :         } else
+     576                 :            : #endif
+     577                 :            :         {
+     578                 :      11033 :             ret = pk_use_ecparams(&alg_params, pk);
+     579                 :            :         }
+     580         [ +  - ]:      11033 :         if (ret == 0) {
+     581                 :      11033 :             ret = mbedtls_pk_ecc_set_pubkey(pk, *p, (size_t) (end - *p));
+     582                 :      11033 :             *p += end - *p;
+     583                 :            :         }
+     584                 :            :     } else
+     585                 :            : #endif /* MBEDTLS_PK_HAVE_ECC_KEYS */
+     586                 :          0 :     ret = MBEDTLS_ERR_PK_UNKNOWN_PK_ALG;
+     587                 :            : 
+     588   [ +  -  -  + ]:      12130 :     if (ret == 0 && *p != end) {
+     589                 :          0 :         ret = MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_INVALID_PUBKEY,
+     590                 :            :                                 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
+     591                 :            :     }
+     592                 :            : 
+     593         [ -  + ]:      12130 :     if (ret != 0) {
+     594                 :          0 :         mbedtls_pk_free(pk);
+     595                 :            :     }
+     596                 :            : 
+     597                 :      12130 :     return ret;
+     598                 :            : }
+     599                 :            : 
+     600                 :            : #if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
+     601                 :            : /*
+     602                 :            :  * Parse a SEC1 encoded private EC key
+     603                 :            :  */
+     604                 :        128 : static int pk_parse_key_sec1_der(mbedtls_pk_context *pk,
+     605                 :            :                                  const unsigned char *key, size_t keylen,
+     606                 :            :                                  int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
+     607                 :            : {
+     608                 :        128 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     609                 :            :     int version, pubkey_done;
+     610                 :            :     size_t len, d_len;
+     611                 :        128 :     mbedtls_asn1_buf params = { 0, 0, NULL };
+     612                 :        128 :     unsigned char *p = (unsigned char *) key;
+     613                 :            :     unsigned char *d;
+     614                 :        128 :     unsigned char *end = p + keylen;
+     615                 :            :     unsigned char *end2;
+     616                 :            : 
+     617                 :            :     /*
+     618                 :            :      * RFC 5915, or SEC1 Appendix C.4
+     619                 :            :      *
+     620                 :            :      * ECPrivateKey ::= SEQUENCE {
+     621                 :            :      *      version        INTEGER { ecPrivkeyVer1(1) } (ecPrivkeyVer1),
+     622                 :            :      *      privateKey     OCTET STRING,
+     623                 :            :      *      parameters [0] ECParameters {{ NamedCurve }} OPTIONAL,
+     624                 :            :      *      publicKey  [1] BIT STRING OPTIONAL
+     625                 :            :      *    }
+     626                 :            :      */
+     627         [ -  + ]:        128 :     if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
+     628                 :            :                                     MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
+     629                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret);
+     630                 :            :     }
+     631                 :            : 
+     632                 :        128 :     end = p + len;
+     633                 :            : 
+     634         [ -  + ]:        128 :     if ((ret = mbedtls_asn1_get_int(&p, end, &version)) != 0) {
+     635                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret);
+     636                 :            :     }
+     637                 :            : 
+     638         [ -  + ]:        128 :     if (version != 1) {
+     639                 :          0 :         return MBEDTLS_ERR_PK_KEY_INVALID_VERSION;
+     640                 :            :     }
+     641                 :            : 
+     642         [ -  + ]:        128 :     if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_OCTET_STRING)) != 0) {
+     643                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret);
+     644                 :            :     }
+     645                 :            : 
+     646                 :            :     /* Keep a reference to the position fo the private key. It will be used
+     647                 :            :      * later in this function. */
+     648                 :        128 :     d = p;
+     649                 :        128 :     d_len = len;
+     650                 :            : 
+     651                 :        128 :     p += len;
+     652                 :            : 
+     653                 :        128 :     pubkey_done = 0;
+     654         [ +  - ]:        128 :     if (p != end) {
+     655                 :            :         /*
+     656                 :            :          * Is 'parameters' present?
+     657                 :            :          */
+     658         [ -  + ]:        128 :         if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
+     659                 :            :                                         MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED |
+     660                 :            :                                         0)) == 0) {
+     661   [ #  #  #  # ]:          0 :             if ((ret = pk_get_ecparams(&p, p + len, &params)) != 0 ||
+     662                 :          0 :                 (ret = pk_use_ecparams(&params, pk)) != 0) {
+     663                 :          0 :                 return ret;
+     664                 :            :             }
+     665         [ -  + ]:        128 :         } else if (ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) {
+     666                 :          0 :             return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret);
+     667                 :            :         }
+     668                 :            :     }
+     669                 :            : 
+     670                 :            :     /*
+     671                 :            :      * Load the private key
+     672                 :            :      */
+     673                 :        128 :     ret = mbedtls_pk_ecc_set_key(pk, d, d_len);
+     674         [ -  + ]:        128 :     if (ret != 0) {
+     675                 :          0 :         return ret;
+     676                 :            :     }
+     677                 :            : 
+     678         [ +  - ]:        128 :     if (p != end) {
+     679                 :            :         /*
+     680                 :            :          * Is 'publickey' present? If not, or if we can't read it (eg because it
+     681                 :            :          * is compressed), create it from the private key.
+     682                 :            :          */
+     683         [ +  - ]:        128 :         if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
+     684                 :            :                                         MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED |
+     685                 :            :                                         1)) == 0) {
+     686                 :        128 :             end2 = p + len;
+     687                 :            : 
+     688         [ -  + ]:        128 :             if ((ret = mbedtls_asn1_get_bitstring_null(&p, end2, &len)) != 0) {
+     689                 :          0 :                 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret);
+     690                 :            :             }
+     691                 :            : 
+     692         [ -  + ]:        128 :             if (p + len != end2) {
+     693                 :          0 :                 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT,
+     694                 :            :                                          MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
+     695                 :            :             }
+     696                 :            : 
+     697         [ +  - ]:        128 :             if ((ret = mbedtls_pk_ecc_set_pubkey(pk, p, (size_t) (end2 - p))) == 0) {
+     698                 :        128 :                 pubkey_done = 1;
+     699                 :            :             } else {
+     700                 :            :                 /*
+     701                 :            :                  * The only acceptable failure mode of mbedtls_pk_ecc_set_pubkey() above
+     702                 :            :                  * is if the point format is not recognized.
+     703                 :            :                  */
+     704         [ #  # ]:          0 :                 if (ret != MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE) {
+     705                 :          0 :                     return MBEDTLS_ERR_PK_KEY_INVALID_FORMAT;
+     706                 :            :                 }
+     707                 :            :             }
+     708         [ #  # ]:          0 :         } else if (ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) {
+     709                 :          0 :             return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret);
+     710                 :            :         }
+     711                 :            :     }
+     712                 :            : 
+     713         [ -  + ]:        128 :     if (!pubkey_done) {
+     714         [ #  # ]:          0 :         if ((ret = mbedtls_pk_ecc_set_pubkey_from_prv(pk, d, d_len, f_rng, p_rng)) != 0) {
+     715                 :          0 :             return ret;
+     716                 :            :         }
+     717                 :            :     }
+     718                 :            : 
+     719                 :        128 :     return 0;
+     720                 :            : }
+     721                 :            : #endif /* MBEDTLS_PK_HAVE_ECC_KEYS */
+     722                 :            : 
+     723                 :            : /***********************************************************************
+     724                 :            :  *
+     725                 :            :  *      PKCS#8 parsing functions
+     726                 :            :  *
+     727                 :            :  **********************************************************************/
+     728                 :            : 
+     729                 :            : /*
+     730                 :            :  * Parse an unencrypted PKCS#8 encoded private key
+     731                 :            :  *
+     732                 :            :  * Notes:
+     733                 :            :  *
+     734                 :            :  * - This function does not own the key buffer. It is the
+     735                 :            :  *   responsibility of the caller to take care of zeroizing
+     736                 :            :  *   and freeing it after use.
+     737                 :            :  *
+     738                 :            :  * - The function is responsible for freeing the provided
+     739                 :            :  *   PK context on failure.
+     740                 :            :  *
+     741                 :            :  */
+     742                 :        153 : static int pk_parse_key_pkcs8_unencrypted_der(
+     743                 :            :     mbedtls_pk_context *pk,
+     744                 :            :     const unsigned char *key, size_t keylen,
+     745                 :            :     int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
+     746                 :            : {
+     747                 :            :     int ret, version;
+     748                 :            :     size_t len;
+     749                 :            :     mbedtls_asn1_buf params;
+     750                 :        153 :     unsigned char *p = (unsigned char *) key;
+     751                 :        153 :     unsigned char *end = p + keylen;
+     752                 :        153 :     mbedtls_pk_type_t pk_alg = MBEDTLS_PK_NONE;
+     753                 :        153 :     mbedtls_ecp_group_id ec_grp_id = MBEDTLS_ECP_DP_NONE;
+     754                 :            :     const mbedtls_pk_info_t *pk_info;
+     755                 :            : 
+     756                 :            : #if !defined(MBEDTLS_PK_HAVE_ECC_KEYS)
+     757                 :            :     (void) f_rng;
+     758                 :            :     (void) p_rng;
+     759                 :            : #endif
+     760                 :            : 
+     761                 :            :     /*
+     762                 :            :      * This function parses the PrivateKeyInfo object (PKCS#8 v1.2 = RFC 5208)
+     763                 :            :      *
+     764                 :            :      *    PrivateKeyInfo ::= SEQUENCE {
+     765                 :            :      *      version                   Version,
+     766                 :            :      *      privateKeyAlgorithm       PrivateKeyAlgorithmIdentifier,
+     767                 :            :      *      privateKey                PrivateKey,
+     768                 :            :      *      attributes           [0]  IMPLICIT Attributes OPTIONAL }
+     769                 :            :      *
+     770                 :            :      *    Version ::= INTEGER
+     771                 :            :      *    PrivateKeyAlgorithmIdentifier ::= AlgorithmIdentifier
+     772                 :            :      *    PrivateKey ::= OCTET STRING
+     773                 :            :      *
+     774                 :            :      *  The PrivateKey OCTET STRING is a SEC1 ECPrivateKey
+     775                 :            :      */
+     776                 :            : 
+     777         [ -  + ]:        153 :     if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
+     778                 :            :                                     MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
+     779                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret);
+     780                 :            :     }
+     781                 :            : 
+     782                 :        153 :     end = p + len;
+     783                 :            : 
+     784         [ -  + ]:        153 :     if ((ret = mbedtls_asn1_get_int(&p, end, &version)) != 0) {
+     785                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret);
+     786                 :            :     }
+     787                 :            : 
+     788         [ -  + ]:        153 :     if (version != 0) {
+     789                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_VERSION, ret);
+     790                 :            :     }
+     791                 :            : 
+     792         [ -  + ]:        153 :     if ((ret = pk_get_pk_alg(&p, end, &pk_alg, &params, &ec_grp_id)) != 0) {
+     793                 :          0 :         return ret;
+     794                 :            :     }
+     795                 :            : 
+     796         [ -  + ]:        153 :     if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_OCTET_STRING)) != 0) {
+     797                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret);
+     798                 :            :     }
+     799                 :            : 
+     800         [ -  + ]:        153 :     if (len < 1) {
+     801                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT,
+     802                 :            :                                  MBEDTLS_ERR_ASN1_OUT_OF_DATA);
+     803                 :            :     }
+     804                 :            : 
+     805         [ -  + ]:        153 :     if ((pk_info = mbedtls_pk_info_from_type(pk_alg)) == NULL) {
+     806                 :          0 :         return MBEDTLS_ERR_PK_UNKNOWN_PK_ALG;
+     807                 :            :     }
+     808                 :            : 
+     809         [ -  + ]:        153 :     if ((ret = mbedtls_pk_setup(pk, pk_info)) != 0) {
+     810                 :          0 :         return ret;
+     811                 :            :     }
+     812                 :            : 
+     813                 :            : #if defined(MBEDTLS_RSA_C)
+     814         [ +  + ]:        153 :     if (pk_alg == MBEDTLS_PK_RSA) {
+     815         [ -  + ]:         25 :         if ((ret = mbedtls_rsa_parse_key(mbedtls_pk_rsa(*pk), p, len)) != 0) {
+     816                 :          0 :             mbedtls_pk_free(pk);
+     817                 :          0 :             return ret;
+     818                 :            :         }
+     819                 :            :     } else
+     820                 :            : #endif /* MBEDTLS_RSA_C */
+     821                 :            : #if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
+     822   [ -  +  -  - ]:        128 :     if (pk_alg == MBEDTLS_PK_ECKEY || pk_alg == MBEDTLS_PK_ECKEY_DH) {
+     823                 :            : #if defined(MBEDTLS_PK_HAVE_RFC8410_CURVES)
+     824   [ +  -  -  + ]:        128 :         if (MBEDTLS_PK_IS_RFC8410_GROUP_ID(ec_grp_id)) {
+     825         [ #  # ]:          0 :             if ((ret =
+     826         [ #  # ]:          0 :                      pk_use_ecparams_rfc8410(&params, ec_grp_id, pk)) != 0 ||
+     827                 :            :                 (ret =
+     828                 :          0 :                      pk_parse_key_rfc8410_der(pk, p, len, end, f_rng,
+     829                 :            :                                               p_rng)) != 0) {
+     830                 :          0 :                 mbedtls_pk_free(pk);
+     831                 :          0 :                 return ret;
+     832                 :            :             }
+     833                 :            :         } else
+     834                 :            : #endif
+     835                 :            :         {
+     836   [ +  -  -  + ]:        256 :             if ((ret = pk_use_ecparams(&params, pk)) != 0 ||
+     837                 :        128 :                 (ret = pk_parse_key_sec1_der(pk, p, len, f_rng, p_rng)) != 0) {
+     838                 :          0 :                 mbedtls_pk_free(pk);
+     839                 :          0 :                 return ret;
+     840                 :            :             }
+     841                 :            :         }
+     842                 :            :     } else
+     843                 :            : #endif /* MBEDTLS_PK_HAVE_ECC_KEYS */
+     844                 :          0 :     return MBEDTLS_ERR_PK_UNKNOWN_PK_ALG;
+     845                 :            : 
+     846                 :        153 :     end = p + len;
+     847         [ -  + ]:        153 :     if (end != (key + keylen)) {
+     848                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT,
+     849                 :            :                                  MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
+     850                 :            :     }
+     851                 :            : 
+     852                 :        153 :     return 0;
+     853                 :            : }
+     854                 :            : 
+     855                 :            : /*
+     856                 :            :  * Parse an encrypted PKCS#8 encoded private key
+     857                 :            :  *
+     858                 :            :  * To save space, the decryption happens in-place on the given key buffer.
+     859                 :            :  * Also, while this function may modify the keybuffer, it doesn't own it,
+     860                 :            :  * and instead it is the responsibility of the caller to zeroize and properly
+     861                 :            :  * free it after use.
+     862                 :            :  *
+     863                 :            :  */
+     864                 :            : #if defined(MBEDTLS_PKCS12_C) || defined(MBEDTLS_PKCS5_C)
+     865                 :            : MBEDTLS_STATIC_TESTABLE int mbedtls_pk_parse_key_pkcs8_encrypted_der(
+     866                 :            :     mbedtls_pk_context *pk,
+     867                 :            :     unsigned char *key, size_t keylen,
+     868                 :            :     const unsigned char *pwd, size_t pwdlen,
+     869                 :            :     int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
+     870                 :            : {
+     871                 :            :     int ret, decrypted = 0;
+     872                 :            :     size_t len;
+     873                 :            :     unsigned char *buf;
+     874                 :            :     unsigned char *p, *end;
+     875                 :            :     mbedtls_asn1_buf pbe_alg_oid, pbe_params;
+     876                 :            : #if defined(MBEDTLS_PKCS12_C) && defined(MBEDTLS_CIPHER_PADDING_PKCS7) && defined(MBEDTLS_CIPHER_C)
+     877                 :            :     mbedtls_cipher_type_t cipher_alg;
+     878                 :            :     mbedtls_md_type_t md_alg;
+     879                 :            : #endif
+     880                 :            :     size_t outlen = 0;
+     881                 :            : 
+     882                 :            :     p = key;
+     883                 :            :     end = p + keylen;
+     884                 :            : 
+     885                 :            :     if (pwdlen == 0) {
+     886                 :            :         return MBEDTLS_ERR_PK_PASSWORD_REQUIRED;
+     887                 :            :     }
+     888                 :            : 
+     889                 :            :     /*
+     890                 :            :      * This function parses the EncryptedPrivateKeyInfo object (PKCS#8)
+     891                 :            :      *
+     892                 :            :      *  EncryptedPrivateKeyInfo ::= SEQUENCE {
+     893                 :            :      *    encryptionAlgorithm  EncryptionAlgorithmIdentifier,
+     894                 :            :      *    encryptedData        EncryptedData
+     895                 :            :      *  }
+     896                 :            :      *
+     897                 :            :      *  EncryptionAlgorithmIdentifier ::= AlgorithmIdentifier
+     898                 :            :      *
+     899                 :            :      *  EncryptedData ::= OCTET STRING
+     900                 :            :      *
+     901                 :            :      *  The EncryptedData OCTET STRING is a PKCS#8 PrivateKeyInfo
+     902                 :            :      *
+     903                 :            :      */
+     904                 :            :     if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
+     905                 :            :                                     MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
+     906                 :            :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret);
+     907                 :            :     }
+     908                 :            : 
+     909                 :            :     end = p + len;
+     910                 :            : 
+     911                 :            :     if ((ret = mbedtls_asn1_get_alg(&p, end, &pbe_alg_oid, &pbe_params)) != 0) {
+     912                 :            :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret);
+     913                 :            :     }
+     914                 :            : 
+     915                 :            :     if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_OCTET_STRING)) != 0) {
+     916                 :            :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret);
+     917                 :            :     }
+     918                 :            : 
+     919                 :            :     buf = p;
+     920                 :            : 
+     921                 :            :     /*
+     922                 :            :      * Decrypt EncryptedData with appropriate PBE
+     923                 :            :      */
+     924                 :            : #if defined(MBEDTLS_PKCS12_C) && defined(MBEDTLS_CIPHER_PADDING_PKCS7) && defined(MBEDTLS_CIPHER_C)
+     925                 :            :     if (mbedtls_oid_get_pkcs12_pbe_alg(&pbe_alg_oid, &md_alg, &cipher_alg) == 0) {
+     926                 :            :         if ((ret = mbedtls_pkcs12_pbe_ext(&pbe_params, MBEDTLS_PKCS12_PBE_DECRYPT,
+     927                 :            :                                           cipher_alg, md_alg,
+     928                 :            :                                           pwd, pwdlen, p, len, buf, len, &outlen)) != 0) {
+     929                 :            :             if (ret == MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH) {
+     930                 :            :                 return MBEDTLS_ERR_PK_PASSWORD_MISMATCH;
+     931                 :            :             }
+     932                 :            : 
+     933                 :            :             return ret;
+     934                 :            :         }
+     935                 :            : 
+     936                 :            :         decrypted = 1;
+     937                 :            :     } else
+     938                 :            : #endif /* MBEDTLS_PKCS12_C && MBEDTLS_CIPHER_PADDING_PKCS7 && MBEDTLS_CIPHER_C */
+     939                 :            : #if defined(MBEDTLS_PKCS5_C) && defined(MBEDTLS_CIPHER_PADDING_PKCS7) && defined(MBEDTLS_CIPHER_C)
+     940                 :            :     if (MBEDTLS_OID_CMP(MBEDTLS_OID_PKCS5_PBES2, &pbe_alg_oid) == 0) {
+     941                 :            :         if ((ret = mbedtls_pkcs5_pbes2_ext(&pbe_params, MBEDTLS_PKCS5_DECRYPT, pwd, pwdlen,
+     942                 :            :                                            p, len, buf, len, &outlen)) != 0) {
+     943                 :            :             if (ret == MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH) {
+     944                 :            :                 return MBEDTLS_ERR_PK_PASSWORD_MISMATCH;
+     945                 :            :             }
+     946                 :            : 
+     947                 :            :             return ret;
+     948                 :            :         }
+     949                 :            : 
+     950                 :            :         decrypted = 1;
+     951                 :            :     } else
+     952                 :            : #endif /* MBEDTLS_PKCS5_C && MBEDTLS_CIPHER_PADDING_PKCS7 && MBEDTLS_CIPHER_C */
+     953                 :            :     {
+     954                 :            :         ((void) pwd);
+     955                 :            :     }
+     956                 :            : 
+     957                 :            :     if (decrypted == 0) {
+     958                 :            :         return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE;
+     959                 :            :     }
+     960                 :            :     return pk_parse_key_pkcs8_unencrypted_der(pk, buf, outlen, f_rng, p_rng);
+     961                 :            : }
+     962                 :            : #endif /* MBEDTLS_PKCS12_C || MBEDTLS_PKCS5_C */
+     963                 :            : 
+     964                 :            : /***********************************************************************
+     965                 :            :  *
+     966                 :            :  *      Top-level functions, with format auto-discovery
+     967                 :            :  *
+     968                 :            :  **********************************************************************/
+     969                 :            : 
+     970                 :            : /*
+     971                 :            :  * Parse a private key
+     972                 :            :  */
+     973                 :        153 : int mbedtls_pk_parse_key(mbedtls_pk_context *pk,
+     974                 :            :                          const unsigned char *key, size_t keylen,
+     975                 :            :                          const unsigned char *pwd, size_t pwdlen,
+     976                 :            :                          int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
+     977                 :            : {
+     978                 :        153 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     979                 :            :     const mbedtls_pk_info_t *pk_info;
+     980                 :            : #if defined(MBEDTLS_PEM_PARSE_C)
+     981                 :            :     size_t len;
+     982                 :            :     mbedtls_pem_context pem;
+     983                 :            : #endif
+     984                 :            : 
+     985         [ -  + ]:        153 :     if (keylen == 0) {
+     986                 :          0 :         return MBEDTLS_ERR_PK_KEY_INVALID_FORMAT;
+     987                 :            :     }
+     988                 :            : 
+     989                 :            : #if defined(MBEDTLS_PEM_PARSE_C)
+     990                 :        153 :     mbedtls_pem_init(&pem);
+     991                 :            : 
+     992                 :            : #if defined(MBEDTLS_RSA_C)
+     993                 :            :     /* Avoid calling mbedtls_pem_read_buffer() on non-null-terminated string */
+     994         [ -  + ]:        153 :     if (key[keylen - 1] != '\0') {
+     995                 :          0 :         ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT;
+     996                 :            :     } else {
+     997                 :        153 :         ret = mbedtls_pem_read_buffer(&pem,
+     998                 :            :                                       PEM_BEGIN_PRIVATE_KEY_RSA, PEM_END_PRIVATE_KEY_RSA,
+     999                 :            :                                       key, pwd, pwdlen, &len);
+    1000                 :            :     }
+    1001                 :            : 
+    1002         [ -  + ]:        153 :     if (ret == 0) {
+    1003                 :          0 :         pk_info = mbedtls_pk_info_from_type(MBEDTLS_PK_RSA);
+    1004   [ #  #  #  # ]:          0 :         if ((ret = mbedtls_pk_setup(pk, pk_info)) != 0 ||
+    1005                 :          0 :             (ret = mbedtls_rsa_parse_key(mbedtls_pk_rsa(*pk),
+    1006                 :          0 :                                          pem.buf, pem.buflen)) != 0) {
+    1007                 :          0 :             mbedtls_pk_free(pk);
+    1008                 :            :         }
+    1009                 :            : 
+    1010                 :          0 :         mbedtls_pem_free(&pem);
+    1011                 :          0 :         return ret;
+    1012         [ -  + ]:        153 :     } else if (ret == MBEDTLS_ERR_PEM_PASSWORD_MISMATCH) {
+    1013                 :          0 :         return MBEDTLS_ERR_PK_PASSWORD_MISMATCH;
+    1014         [ -  + ]:        153 :     } else if (ret == MBEDTLS_ERR_PEM_PASSWORD_REQUIRED) {
+    1015                 :          0 :         return MBEDTLS_ERR_PK_PASSWORD_REQUIRED;
+    1016         [ -  + ]:        153 :     } else if (ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) {
+    1017                 :          0 :         return ret;
+    1018                 :            :     }
+    1019                 :            : #endif /* MBEDTLS_RSA_C */
+    1020                 :            : 
+    1021                 :            : #if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
+    1022                 :            :     /* Avoid calling mbedtls_pem_read_buffer() on non-null-terminated string */
+    1023         [ -  + ]:        153 :     if (key[keylen - 1] != '\0') {
+    1024                 :          0 :         ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT;
+    1025                 :            :     } else {
+    1026                 :        153 :         ret = mbedtls_pem_read_buffer(&pem,
+    1027                 :            :                                       PEM_BEGIN_PRIVATE_KEY_EC,
+    1028                 :            :                                       PEM_END_PRIVATE_KEY_EC,
+    1029                 :            :                                       key, pwd, pwdlen, &len);
+    1030                 :            :     }
+    1031         [ -  + ]:        153 :     if (ret == 0) {
+    1032                 :          0 :         pk_info = mbedtls_pk_info_from_type(MBEDTLS_PK_ECKEY);
+    1033                 :            : 
+    1034   [ #  #  #  # ]:          0 :         if ((ret = mbedtls_pk_setup(pk, pk_info)) != 0 ||
+    1035                 :          0 :             (ret = pk_parse_key_sec1_der(pk,
+    1036                 :          0 :                                          pem.buf, pem.buflen,
+    1037                 :            :                                          f_rng, p_rng)) != 0) {
+    1038                 :          0 :             mbedtls_pk_free(pk);
+    1039                 :            :         }
+    1040                 :            : 
+    1041                 :          0 :         mbedtls_pem_free(&pem);
+    1042                 :          0 :         return ret;
+    1043         [ -  + ]:        153 :     } else if (ret == MBEDTLS_ERR_PEM_PASSWORD_MISMATCH) {
+    1044                 :          0 :         return MBEDTLS_ERR_PK_PASSWORD_MISMATCH;
+    1045         [ -  + ]:        153 :     } else if (ret == MBEDTLS_ERR_PEM_PASSWORD_REQUIRED) {
+    1046                 :          0 :         return MBEDTLS_ERR_PK_PASSWORD_REQUIRED;
+    1047         [ -  + ]:        153 :     } else if (ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) {
+    1048                 :          0 :         return ret;
+    1049                 :            :     }
+    1050                 :            : #endif /* MBEDTLS_PK_HAVE_ECC_KEYS */
+    1051                 :            : 
+    1052                 :            :     /* Avoid calling mbedtls_pem_read_buffer() on non-null-terminated string */
+    1053         [ -  + ]:        153 :     if (key[keylen - 1] != '\0') {
+    1054                 :          0 :         ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT;
+    1055                 :            :     } else {
+    1056                 :        153 :         ret = mbedtls_pem_read_buffer(&pem,
+    1057                 :            :                                       PEM_BEGIN_PRIVATE_KEY_PKCS8, PEM_END_PRIVATE_KEY_PKCS8,
+    1058                 :            :                                       key, NULL, 0, &len);
+    1059                 :            :     }
+    1060         [ +  - ]:        153 :     if (ret == 0) {
+    1061         [ -  + ]:        153 :         if ((ret = pk_parse_key_pkcs8_unencrypted_der(pk,
+    1062                 :        153 :                                                       pem.buf, pem.buflen, f_rng, p_rng)) != 0) {
+    1063                 :          0 :             mbedtls_pk_free(pk);
+    1064                 :            :         }
+    1065                 :            : 
+    1066                 :        153 :         mbedtls_pem_free(&pem);
+    1067                 :        153 :         return ret;
+    1068         [ #  # ]:          0 :     } else if (ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) {
+    1069                 :          0 :         return ret;
+    1070                 :            :     }
+    1071                 :            : 
+    1072                 :            : #if defined(MBEDTLS_PKCS12_C) || defined(MBEDTLS_PKCS5_C)
+    1073                 :            :     /* Avoid calling mbedtls_pem_read_buffer() on non-null-terminated string */
+    1074                 :            :     if (key[keylen - 1] != '\0') {
+    1075                 :            :         ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT;
+    1076                 :            :     } else {
+    1077                 :            :         ret = mbedtls_pem_read_buffer(&pem,
+    1078                 :            :                                       PEM_BEGIN_ENCRYPTED_PRIVATE_KEY_PKCS8,
+    1079                 :            :                                       PEM_END_ENCRYPTED_PRIVATE_KEY_PKCS8,
+    1080                 :            :                                       key, NULL, 0, &len);
+    1081                 :            :     }
+    1082                 :            :     if (ret == 0) {
+    1083                 :            :         if ((ret = mbedtls_pk_parse_key_pkcs8_encrypted_der(pk, pem.buf, pem.buflen,
+    1084                 :            :                                                             pwd, pwdlen, f_rng, p_rng)) != 0) {
+    1085                 :            :             mbedtls_pk_free(pk);
+    1086                 :            :         }
+    1087                 :            : 
+    1088                 :            :         mbedtls_pem_free(&pem);
+    1089                 :            :         return ret;
+    1090                 :            :     } else if (ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) {
+    1091                 :            :         return ret;
+    1092                 :            :     }
+    1093                 :            : #endif /* MBEDTLS_PKCS12_C || MBEDTLS_PKCS5_C */
+    1094                 :            : #else
+    1095                 :            :     ((void) pwd);
+    1096                 :            :     ((void) pwdlen);
+    1097                 :            : #endif /* MBEDTLS_PEM_PARSE_C */
+    1098                 :            : 
+    1099                 :            :     /*
+    1100                 :            :      * At this point we only know it's not a PEM formatted key. Could be any
+    1101                 :            :      * of the known DER encoded private key formats
+    1102                 :            :      *
+    1103                 :            :      * We try the different DER format parsers to see if one passes without
+    1104                 :            :      * error
+    1105                 :            :      */
+    1106                 :            : #if defined(MBEDTLS_PKCS12_C) || defined(MBEDTLS_PKCS5_C)
+    1107                 :            :     if (pwdlen != 0) {
+    1108                 :            :         unsigned char *key_copy;
+    1109                 :            : 
+    1110                 :            :         if ((key_copy = mbedtls_calloc(1, keylen)) == NULL) {
+    1111                 :            :             return MBEDTLS_ERR_PK_ALLOC_FAILED;
+    1112                 :            :         }
+    1113                 :            : 
+    1114                 :            :         memcpy(key_copy, key, keylen);
+    1115                 :            : 
+    1116                 :            :         ret = mbedtls_pk_parse_key_pkcs8_encrypted_der(pk, key_copy, keylen,
+    1117                 :            :                                                        pwd, pwdlen, f_rng, p_rng);
+    1118                 :            : 
+    1119                 :            :         mbedtls_zeroize_and_free(key_copy, keylen);
+    1120                 :            :     }
+    1121                 :            : 
+    1122                 :            :     if (ret == 0) {
+    1123                 :            :         return 0;
+    1124                 :            :     }
+    1125                 :            : 
+    1126                 :            :     mbedtls_pk_free(pk);
+    1127                 :            :     mbedtls_pk_init(pk);
+    1128                 :            : 
+    1129                 :            :     if (ret == MBEDTLS_ERR_PK_PASSWORD_MISMATCH) {
+    1130                 :            :         return ret;
+    1131                 :            :     }
+    1132                 :            : #endif /* MBEDTLS_PKCS12_C || MBEDTLS_PKCS5_C */
+    1133                 :            : 
+    1134                 :          0 :     ret = pk_parse_key_pkcs8_unencrypted_der(pk, key, keylen, f_rng, p_rng);
+    1135         [ #  # ]:          0 :     if (ret == 0) {
+    1136                 :          0 :         return 0;
+    1137                 :            :     }
+    1138                 :            : 
+    1139                 :          0 :     mbedtls_pk_free(pk);
+    1140                 :          0 :     mbedtls_pk_init(pk);
+    1141                 :            : 
+    1142                 :            : #if defined(MBEDTLS_RSA_C)
+    1143                 :            : 
+    1144                 :          0 :     pk_info = mbedtls_pk_info_from_type(MBEDTLS_PK_RSA);
+    1145   [ #  #  #  # ]:          0 :     if (mbedtls_pk_setup(pk, pk_info) == 0 &&
+    1146                 :          0 :         mbedtls_rsa_parse_key(mbedtls_pk_rsa(*pk), key, keylen) == 0) {
+    1147                 :          0 :         return 0;
+    1148                 :            :     }
+    1149                 :            : 
+    1150                 :          0 :     mbedtls_pk_free(pk);
+    1151                 :          0 :     mbedtls_pk_init(pk);
+    1152                 :            : #endif /* MBEDTLS_RSA_C */
+    1153                 :            : 
+    1154                 :            : #if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
+    1155                 :          0 :     pk_info = mbedtls_pk_info_from_type(MBEDTLS_PK_ECKEY);
+    1156   [ #  #  #  # ]:          0 :     if (mbedtls_pk_setup(pk, pk_info) == 0 &&
+    1157                 :          0 :         pk_parse_key_sec1_der(pk,
+    1158                 :            :                               key, keylen, f_rng, p_rng) == 0) {
+    1159                 :          0 :         return 0;
+    1160                 :            :     }
+    1161                 :          0 :     mbedtls_pk_free(pk);
+    1162                 :            : #endif /* MBEDTLS_PK_HAVE_ECC_KEYS */
+    1163                 :            : 
+    1164                 :            :     /* If MBEDTLS_RSA_C is defined but MBEDTLS_PK_HAVE_ECC_KEYS isn't,
+    1165                 :            :      * it is ok to leave the PK context initialized but not
+    1166                 :            :      * freed: It is the caller's responsibility to call pk_init()
+    1167                 :            :      * before calling this function, and to call pk_free()
+    1168                 :            :      * when it fails. If MBEDTLS_PK_HAVE_ECC_KEYS is defined but MBEDTLS_RSA_C
+    1169                 :            :      * isn't, this leads to mbedtls_pk_free() being called
+    1170                 :            :      * twice, once here and once by the caller, but this is
+    1171                 :            :      * also ok and in line with the mbedtls_pk_free() calls
+    1172                 :            :      * on failed PEM parsing attempts. */
+    1173                 :            : 
+    1174                 :          0 :     return MBEDTLS_ERR_PK_KEY_INVALID_FORMAT;
+    1175                 :            : }
+    1176                 :            : 
+    1177                 :            : /*
+    1178                 :            :  * Parse a public key
+    1179                 :            :  */
+    1180                 :          5 : int mbedtls_pk_parse_public_key(mbedtls_pk_context *ctx,
+    1181                 :            :                                 const unsigned char *key, size_t keylen)
+    1182                 :            : {
+    1183                 :          5 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1184                 :            :     unsigned char *p;
+    1185                 :            : #if defined(MBEDTLS_RSA_C)
+    1186                 :            :     const mbedtls_pk_info_t *pk_info;
+    1187                 :            : #endif
+    1188                 :            : #if defined(MBEDTLS_PEM_PARSE_C)
+    1189                 :            :     size_t len;
+    1190                 :            :     mbedtls_pem_context pem;
+    1191                 :            : #endif
+    1192                 :            : 
+    1193         [ -  + ]:          5 :     if (keylen == 0) {
+    1194                 :          0 :         return MBEDTLS_ERR_PK_KEY_INVALID_FORMAT;
+    1195                 :            :     }
+    1196                 :            : 
+    1197                 :            : #if defined(MBEDTLS_PEM_PARSE_C)
+    1198                 :          5 :     mbedtls_pem_init(&pem);
+    1199                 :            : #if defined(MBEDTLS_RSA_C)
+    1200                 :            :     /* Avoid calling mbedtls_pem_read_buffer() on non-null-terminated string */
+    1201         [ +  - ]:          5 :     if (key[keylen - 1] != '\0') {
+    1202                 :          5 :         ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT;
+    1203                 :            :     } else {
+    1204                 :          0 :         ret = mbedtls_pem_read_buffer(&pem,
+    1205                 :            :                                       PEM_BEGIN_PUBLIC_KEY_RSA, PEM_END_PUBLIC_KEY_RSA,
+    1206                 :            :                                       key, NULL, 0, &len);
+    1207                 :            :     }
+    1208                 :            : 
+    1209         [ -  + ]:          5 :     if (ret == 0) {
+    1210                 :          0 :         p = pem.buf;
+    1211         [ #  # ]:          0 :         if ((pk_info = mbedtls_pk_info_from_type(MBEDTLS_PK_RSA)) == NULL) {
+    1212                 :          0 :             mbedtls_pem_free(&pem);
+    1213                 :          0 :             return MBEDTLS_ERR_PK_UNKNOWN_PK_ALG;
+    1214                 :            :         }
+    1215                 :            : 
+    1216         [ #  # ]:          0 :         if ((ret = mbedtls_pk_setup(ctx, pk_info)) != 0) {
+    1217                 :          0 :             mbedtls_pem_free(&pem);
+    1218                 :          0 :             return ret;
+    1219                 :            :         }
+    1220                 :            : 
+    1221         [ #  # ]:          0 :         if ((ret = mbedtls_rsa_parse_pubkey(mbedtls_pk_rsa(*ctx), p, pem.buflen)) != 0) {
+    1222                 :          0 :             mbedtls_pk_free(ctx);
+    1223                 :            :         }
+    1224                 :            : 
+    1225                 :          0 :         mbedtls_pem_free(&pem);
+    1226                 :          0 :         return ret;
+    1227         [ -  + ]:          5 :     } else if (ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) {
+    1228                 :          0 :         mbedtls_pem_free(&pem);
+    1229                 :          0 :         return ret;
+    1230                 :            :     }
+    1231                 :            : #endif /* MBEDTLS_RSA_C */
+    1232                 :            : 
+    1233                 :            :     /* Avoid calling mbedtls_pem_read_buffer() on non-null-terminated string */
+    1234         [ +  - ]:          5 :     if (key[keylen - 1] != '\0') {
+    1235                 :          5 :         ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT;
+    1236                 :            :     } else {
+    1237                 :          0 :         ret = mbedtls_pem_read_buffer(&pem,
+    1238                 :            :                                       PEM_BEGIN_PUBLIC_KEY, PEM_END_PUBLIC_KEY,
+    1239                 :            :                                       key, NULL, 0, &len);
+    1240                 :            :     }
+    1241                 :            : 
+    1242         [ -  + ]:          5 :     if (ret == 0) {
+    1243                 :            :         /*
+    1244                 :            :          * Was PEM encoded
+    1245                 :            :          */
+    1246                 :          0 :         p = pem.buf;
+    1247                 :            : 
+    1248                 :          0 :         ret = mbedtls_pk_parse_subpubkey(&p, p + pem.buflen, ctx);
+    1249                 :          0 :         mbedtls_pem_free(&pem);
+    1250                 :          0 :         return ret;
+    1251         [ -  + ]:          5 :     } else if (ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) {
+    1252                 :          0 :         mbedtls_pem_free(&pem);
+    1253                 :          0 :         return ret;
+    1254                 :            :     }
+    1255                 :          5 :     mbedtls_pem_free(&pem);
+    1256                 :            : #endif /* MBEDTLS_PEM_PARSE_C */
+    1257                 :            : 
+    1258                 :            : #if defined(MBEDTLS_RSA_C)
+    1259         [ -  + ]:          5 :     if ((pk_info = mbedtls_pk_info_from_type(MBEDTLS_PK_RSA)) == NULL) {
+    1260                 :          0 :         return MBEDTLS_ERR_PK_UNKNOWN_PK_ALG;
+    1261                 :            :     }
+    1262                 :            : 
+    1263         [ -  + ]:          5 :     if ((ret = mbedtls_pk_setup(ctx, pk_info)) != 0) {
+    1264                 :          0 :         return ret;
+    1265                 :            :     }
+    1266                 :            : 
+    1267                 :          5 :     p = (unsigned char *) key;
+    1268                 :          5 :     ret = mbedtls_rsa_parse_pubkey(mbedtls_pk_rsa(*ctx), p, keylen);
+    1269         [ -  + ]:          5 :     if (ret == 0) {
+    1270                 :          0 :         return ret;
+    1271                 :            :     }
+    1272                 :          5 :     mbedtls_pk_free(ctx);
+    1273         [ -  + ]:          5 :     if (ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) {
+    1274                 :          0 :         return ret;
+    1275                 :            :     }
+    1276                 :            : #endif /* MBEDTLS_RSA_C */
+    1277                 :          5 :     p = (unsigned char *) key;
+    1278                 :            : 
+    1279                 :          5 :     ret = mbedtls_pk_parse_subpubkey(&p, p + keylen, ctx);
+    1280                 :            : 
+    1281                 :          5 :     return ret;
+    1282                 :            : }
+    1283                 :            : 
+    1284                 :            : /***********************************************************************
+    1285                 :            :  *
+    1286                 :            :  *      Top-level functions, with filesystem support
+    1287                 :            :  *
+    1288                 :            :  **********************************************************************/
+    1289                 :            : 
+    1290                 :            : #if defined(MBEDTLS_FS_IO)
+    1291                 :            : /*
+    1292                 :            :  * Load all data from a file into a given buffer.
+    1293                 :            :  *
+    1294                 :            :  * The file is expected to contain either PEM or DER encoded data.
+    1295                 :            :  * A terminating null byte is always appended. It is included in the announced
+    1296                 :            :  * length only if the data looks like it is PEM encoded.
+    1297                 :            :  */
+    1298                 :            : int mbedtls_pk_load_file(const char *path, unsigned char **buf, size_t *n)
+    1299                 :            : {
+    1300                 :            :     FILE *f;
+    1301                 :            :     long size;
+    1302                 :            : 
+    1303                 :            :     if ((f = fopen(path, "rb")) == NULL) {
+    1304                 :            :         return MBEDTLS_ERR_PK_FILE_IO_ERROR;
+    1305                 :            :     }
+    1306                 :            : 
+    1307                 :            :     /* Ensure no stdio buffering of secrets, as such buffers cannot be wiped. */
+    1308                 :            :     mbedtls_setbuf(f, NULL);
+    1309                 :            : 
+    1310                 :            :     fseek(f, 0, SEEK_END);
+    1311                 :            :     if ((size = ftell(f)) == -1) {
+    1312                 :            :         fclose(f);
+    1313                 :            :         return MBEDTLS_ERR_PK_FILE_IO_ERROR;
+    1314                 :            :     }
+    1315                 :            :     fseek(f, 0, SEEK_SET);
+    1316                 :            : 
+    1317                 :            :     *n = (size_t) size;
+    1318                 :            : 
+    1319                 :            :     if (*n + 1 == 0 ||
+    1320                 :            :         (*buf = mbedtls_calloc(1, *n + 1)) == NULL) {
+    1321                 :            :         fclose(f);
+    1322                 :            :         return MBEDTLS_ERR_PK_ALLOC_FAILED;
+    1323                 :            :     }
+    1324                 :            : 
+    1325                 :            :     if (fread(*buf, 1, *n, f) != *n) {
+    1326                 :            :         fclose(f);
+    1327                 :            : 
+    1328                 :            :         mbedtls_zeroize_and_free(*buf, *n);
+    1329                 :            : 
+    1330                 :            :         return MBEDTLS_ERR_PK_FILE_IO_ERROR;
+    1331                 :            :     }
+    1332                 :            : 
+    1333                 :            :     fclose(f);
+    1334                 :            : 
+    1335                 :            :     (*buf)[*n] = '\0';
+    1336                 :            : 
+    1337                 :            :     if (strstr((const char *) *buf, "-----BEGIN ") != NULL) {
+    1338                 :            :         ++*n;
+    1339                 :            :     }
+    1340                 :            : 
+    1341                 :            :     return 0;
+    1342                 :            : }
+    1343                 :            : 
+    1344                 :            : /*
+    1345                 :            :  * Load and parse a private key
+    1346                 :            :  */
+    1347                 :            : int mbedtls_pk_parse_keyfile(mbedtls_pk_context *ctx,
+    1348                 :            :                              const char *path, const char *pwd,
+    1349                 :            :                              int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
+    1350                 :            : {
+    1351                 :            :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1352                 :            :     size_t n;
+    1353                 :            :     unsigned char *buf;
+    1354                 :            : 
+    1355                 :            :     if ((ret = mbedtls_pk_load_file(path, &buf, &n)) != 0) {
+    1356                 :            :         return ret;
+    1357                 :            :     }
+    1358                 :            : 
+    1359                 :            :     if (pwd == NULL) {
+    1360                 :            :         ret = mbedtls_pk_parse_key(ctx, buf, n, NULL, 0, f_rng, p_rng);
+    1361                 :            :     } else {
+    1362                 :            :         ret = mbedtls_pk_parse_key(ctx, buf, n,
+    1363                 :            :                                    (const unsigned char *) pwd, strlen(pwd), f_rng, p_rng);
+    1364                 :            :     }
+    1365                 :            : 
+    1366                 :            :     mbedtls_zeroize_and_free(buf, n);
+    1367                 :            : 
+    1368                 :            :     return ret;
+    1369                 :            : }
+    1370                 :            : 
+    1371                 :            : /*
+    1372                 :            :  * Load and parse a public key
+    1373                 :            :  */
+    1374                 :            : int mbedtls_pk_parse_public_keyfile(mbedtls_pk_context *ctx, const char *path)
+    1375                 :            : {
+    1376                 :            :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1377                 :            :     size_t n;
+    1378                 :            :     unsigned char *buf;
+    1379                 :            : 
+    1380                 :            :     if ((ret = mbedtls_pk_load_file(path, &buf, &n)) != 0) {
+    1381                 :            :         return ret;
+    1382                 :            :     }
+    1383                 :            : 
+    1384                 :            :     ret = mbedtls_pk_parse_public_key(ctx, buf, n);
+    1385                 :            : 
+    1386                 :            :     mbedtls_zeroize_and_free(buf, n);
+    1387                 :            : 
+    1388                 :            :     return ret;
+    1389                 :            : }
+    1390                 :            : #endif /* MBEDTLS_FS_IO */
+    1391                 :            : 
+    1392                 :            : #endif /* MBEDTLS_PK_PARSE_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/pkwrite.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pkwrite.c.func-sort-c.html new file mode 100644 index 00000000000..6fc542c53b0 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pkwrite.c.func-sort-c.html @@ -0,0 +1,129 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/pkwrite.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - pkwrite.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:5016829.8 %
Date:2024-09-22 08:21:07Functions:51241.7 %
Branches:2211818.6 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_pk_write_key_der0
mbedtls_pk_write_key_pem0
mbedtls_pk_write_pubkey_pem0
pk_write_ec_der0
pk_write_ec_private0
pk_write_ec_rfc8410_der0
pk_write_rsa_der0
mbedtls_pk_write_pubkey12
mbedtls_pk_write_pubkey_der12
pk_write_ec_param12
pk_write_ec_pubkey12
pk_get_type_ext24
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/pkwrite.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pkwrite.c.func.html new file mode 100644 index 00000000000..30f4557d459 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pkwrite.c.func.html @@ -0,0 +1,129 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/pkwrite.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - pkwrite.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:5016829.8 %
Date:2024-09-22 08:21:07Functions:51241.7 %
Branches:2211818.6 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_pk_write_key_der0
mbedtls_pk_write_key_pem0
mbedtls_pk_write_pubkey12
mbedtls_pk_write_pubkey_der12
mbedtls_pk_write_pubkey_pem0
pk_get_type_ext24
pk_write_ec_der0
pk_write_ec_param12
pk_write_ec_private0
pk_write_ec_pubkey12
pk_write_ec_rfc8410_der0
pk_write_rsa_der0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/pkwrite.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pkwrite.c.gcov.html new file mode 100644 index 00000000000..9da58e3c519 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/pkwrite.c.gcov.html @@ -0,0 +1,706 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/pkwrite.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - pkwrite.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:5016829.8 %
Date:2024-09-22 08:21:07Functions:51241.7 %
Branches:2211818.6 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  *  Public Key layer for writing key files and structures
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  */
+       7                 :            : 
+       8                 :            : #include "common.h"
+       9                 :            : 
+      10                 :            : #if defined(MBEDTLS_PK_WRITE_C)
+      11                 :            : 
+      12                 :            : #include "mbedtls/pk.h"
+      13                 :            : #include "mbedtls/asn1write.h"
+      14                 :            : #include "mbedtls/oid.h"
+      15                 :            : #include "mbedtls/platform_util.h"
+      16                 :            : #include "mbedtls/error.h"
+      17                 :            : #include "pk_internal.h"
+      18                 :            : 
+      19                 :            : #include <string.h>
+      20                 :            : 
+      21                 :            : #if defined(MBEDTLS_ECP_C)
+      22                 :            : #include "mbedtls/bignum.h"
+      23                 :            : #include "mbedtls/ecp.h"
+      24                 :            : #include "mbedtls/platform_util.h"
+      25                 :            : #endif
+      26                 :            : #if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
+      27                 :            : #include "pk_internal.h"
+      28                 :            : #endif
+      29                 :            : #if defined(MBEDTLS_RSA_C) || defined(MBEDTLS_PK_HAVE_ECC_KEYS)
+      30                 :            : #include "pkwrite.h"
+      31                 :            : #endif
+      32                 :            : #if defined(MBEDTLS_PEM_WRITE_C)
+      33                 :            : #include "mbedtls/pem.h"
+      34                 :            : #endif
+      35                 :            : #if defined(MBEDTLS_RSA_C)
+      36                 :            : #include "rsa_internal.h"
+      37                 :            : #endif
+      38                 :            : 
+      39                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+      40                 :            : #include "psa/crypto.h"
+      41                 :            : #include "psa_util_internal.h"
+      42                 :            : #endif
+      43                 :            : #include "mbedtls/platform.h"
+      44                 :            : 
+      45                 :            : /* Helpers for properly sizing buffers aimed at holding public keys or
+      46                 :            :  * key-pairs based on build symbols. */
+      47                 :            : #if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
+      48                 :            : #define PK_MAX_EC_PUBLIC_KEY_SIZE       PSA_EXPORT_PUBLIC_KEY_MAX_SIZE
+      49                 :            : #define PK_MAX_EC_KEY_PAIR_SIZE         MBEDTLS_PSA_MAX_EC_KEY_PAIR_LENGTH
+      50                 :            : #elif defined(MBEDTLS_USE_PSA_CRYPTO)
+      51                 :            : #define PK_MAX_EC_PUBLIC_KEY_SIZE       PSA_EXPORT_PUBLIC_KEY_MAX_SIZE
+      52                 :            : #define PK_MAX_EC_KEY_PAIR_SIZE         MBEDTLS_PSA_MAX_EC_KEY_PAIR_LENGTH
+      53                 :            : #else
+      54                 :            : #define PK_MAX_EC_PUBLIC_KEY_SIZE       MBEDTLS_ECP_MAX_PT_LEN
+      55                 :            : #define PK_MAX_EC_KEY_PAIR_SIZE         MBEDTLS_ECP_MAX_BYTES
+      56                 :            : #endif
+      57                 :            : 
+      58                 :            : /******************************************************************************
+      59                 :            :  * Internal functions for RSA keys.
+      60                 :            :  ******************************************************************************/
+      61                 :            : #if defined(MBEDTLS_RSA_C)
+      62                 :          0 : static int pk_write_rsa_der(unsigned char **p, unsigned char *buf,
+      63                 :            :                             const mbedtls_pk_context *pk)
+      64                 :            : {
+      65                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+      66                 :            :     if (mbedtls_pk_get_type(pk) == MBEDTLS_PK_OPAQUE) {
+      67                 :            :         uint8_t tmp[PSA_EXPORT_KEY_PAIR_MAX_SIZE];
+      68                 :            :         size_t len = 0, tmp_len = 0;
+      69                 :            : 
+      70                 :            :         if (psa_export_key(pk->priv_id, tmp, sizeof(tmp), &tmp_len) != PSA_SUCCESS) {
+      71                 :            :             return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+      72                 :            :         }
+      73                 :            :         *p -= tmp_len;
+      74                 :            :         memcpy(*p, tmp, tmp_len);
+      75                 :            :         len += tmp_len;
+      76                 :            :         mbedtls_platform_zeroize(tmp, sizeof(tmp));
+      77                 :            : 
+      78                 :            :         return (int) len;
+      79                 :            :     }
+      80                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO */
+      81                 :          0 :     return mbedtls_rsa_write_key(mbedtls_pk_rsa(*pk), buf, p);
+      82                 :            : }
+      83                 :            : #endif /* MBEDTLS_RSA_C */
+      84                 :            : 
+      85                 :            : /******************************************************************************
+      86                 :            :  * Internal functions for EC keys.
+      87                 :            :  ******************************************************************************/
+      88                 :            : #if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
+      89                 :            : #if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
+      90                 :            : static int pk_write_ec_pubkey(unsigned char **p, unsigned char *start,
+      91                 :            :                               const mbedtls_pk_context *pk)
+      92                 :            : {
+      93                 :            :     size_t len = 0;
+      94                 :            :     uint8_t buf[PK_MAX_EC_PUBLIC_KEY_SIZE];
+      95                 :            : 
+      96                 :            :     if (mbedtls_pk_get_type(pk) == MBEDTLS_PK_OPAQUE) {
+      97                 :            :         if (psa_export_public_key(pk->priv_id, buf, sizeof(buf), &len) != PSA_SUCCESS) {
+      98                 :            :             return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+      99                 :            :         }
+     100                 :            :     } else {
+     101                 :            :         len = pk->pub_raw_len;
+     102                 :            :         memcpy(buf, pk->pub_raw, len);
+     103                 :            :     }
+     104                 :            : 
+     105                 :            :     if (*p < start || (size_t) (*p - start) < len) {
+     106                 :            :         return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL;
+     107                 :            :     }
+     108                 :            : 
+     109                 :            :     *p -= len;
+     110                 :            :     memcpy(*p, buf, len);
+     111                 :            : 
+     112                 :            :     return (int) len;
+     113                 :            : }
+     114                 :            : #else /* MBEDTLS_PK_USE_PSA_EC_DATA */
+     115                 :         12 : static int pk_write_ec_pubkey(unsigned char **p, unsigned char *start,
+     116                 :            :                               const mbedtls_pk_context *pk)
+     117                 :            : {
+     118                 :         12 :     size_t len = 0;
+     119                 :            :     unsigned char buf[PK_MAX_EC_PUBLIC_KEY_SIZE];
+     120                 :         12 :     mbedtls_ecp_keypair *ec = mbedtls_pk_ec(*pk);
+     121                 :         12 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     122                 :            : 
+     123                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+     124                 :            :     if (mbedtls_pk_get_type(pk) == MBEDTLS_PK_OPAQUE) {
+     125                 :            :         if (psa_export_public_key(pk->priv_id, buf, sizeof(buf), &len) != PSA_SUCCESS) {
+     126                 :            :             return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+     127                 :            :         }
+     128                 :            :         *p -= len;
+     129                 :            :         memcpy(*p, buf, len);
+     130                 :            :         return (int) len;
+     131                 :            :     } else
+     132                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO */
+     133                 :            :     {
+     134         [ -  + ]:         12 :         if ((ret = mbedtls_ecp_point_write_binary(&ec->grp, &ec->Q,
+     135                 :            :                                                   MBEDTLS_ECP_PF_UNCOMPRESSED,
+     136                 :            :                                                   &len, buf, sizeof(buf))) != 0) {
+     137                 :          0 :             return ret;
+     138                 :            :         }
+     139                 :            :     }
+     140                 :            : 
+     141   [ +  -  -  + ]:         12 :     if (*p < start || (size_t) (*p - start) < len) {
+     142                 :          0 :         return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL;
+     143                 :            :     }
+     144                 :            : 
+     145                 :         12 :     *p -= len;
+     146                 :         12 :     memcpy(*p, buf, len);
+     147                 :            : 
+     148                 :         12 :     return (int) len;
+     149                 :            : }
+     150                 :            : #endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
+     151                 :            : 
+     152                 :            : /*
+     153                 :            :  * privateKey  OCTET STRING -- always of length ceil(log2(n)/8)
+     154                 :            :  */
+     155                 :            : #if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
+     156                 :            : static int pk_write_ec_private(unsigned char **p, unsigned char *start,
+     157                 :            :                                const mbedtls_pk_context *pk)
+     158                 :            : {
+     159                 :            :     size_t byte_length;
+     160                 :            :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     161                 :            :     unsigned char tmp[PK_MAX_EC_KEY_PAIR_SIZE];
+     162                 :            :     psa_status_t status;
+     163                 :            : 
+     164                 :            :     if (mbedtls_pk_get_type(pk) == MBEDTLS_PK_OPAQUE) {
+     165                 :            :         status = psa_export_key(pk->priv_id, tmp, sizeof(tmp), &byte_length);
+     166                 :            :         if (status != PSA_SUCCESS) {
+     167                 :            :             ret = PSA_PK_ECDSA_TO_MBEDTLS_ERR(status);
+     168                 :            :             return ret;
+     169                 :            :         }
+     170                 :            :     } else {
+     171                 :            :         status = psa_export_key(pk->priv_id, tmp, sizeof(tmp), &byte_length);
+     172                 :            :         if (status != PSA_SUCCESS) {
+     173                 :            :             ret = PSA_PK_ECDSA_TO_MBEDTLS_ERR(status);
+     174                 :            :             goto exit;
+     175                 :            :         }
+     176                 :            :     }
+     177                 :            : 
+     178                 :            :     ret = mbedtls_asn1_write_octet_string(p, start, tmp, byte_length);
+     179                 :            : exit:
+     180                 :            :     mbedtls_platform_zeroize(tmp, sizeof(tmp));
+     181                 :            :     return ret;
+     182                 :            : }
+     183                 :            : #else /* MBEDTLS_PK_USE_PSA_EC_DATA */
+     184                 :          0 : static int pk_write_ec_private(unsigned char **p, unsigned char *start,
+     185                 :            :                                const mbedtls_pk_context *pk)
+     186                 :            : {
+     187                 :            :     size_t byte_length;
+     188                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     189                 :            :     unsigned char tmp[PK_MAX_EC_KEY_PAIR_SIZE];
+     190                 :            : 
+     191                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+     192                 :            :     psa_status_t status;
+     193                 :            :     if (mbedtls_pk_get_type(pk) == MBEDTLS_PK_OPAQUE) {
+     194                 :            :         status = psa_export_key(pk->priv_id, tmp, sizeof(tmp), &byte_length);
+     195                 :            :         if (status != PSA_SUCCESS) {
+     196                 :            :             ret = PSA_PK_ECDSA_TO_MBEDTLS_ERR(status);
+     197                 :            :             return ret;
+     198                 :            :         }
+     199                 :            :     } else
+     200                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO */
+     201                 :            :     {
+     202                 :          0 :         mbedtls_ecp_keypair *ec = mbedtls_pk_ec_rw(*pk);
+     203                 :          0 :         byte_length = (ec->grp.pbits + 7) / 8;
+     204                 :            : 
+     205                 :          0 :         ret = mbedtls_ecp_write_key_ext(ec, &byte_length, tmp, sizeof(tmp));
+     206         [ #  # ]:          0 :         if (ret != 0) {
+     207                 :          0 :             goto exit;
+     208                 :            :         }
+     209                 :            :     }
+     210                 :          0 :     ret = mbedtls_asn1_write_octet_string(p, start, tmp, byte_length);
+     211                 :          0 : exit:
+     212                 :          0 :     mbedtls_platform_zeroize(tmp, sizeof(tmp));
+     213                 :          0 :     return ret;
+     214                 :            : }
+     215                 :            : #endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
+     216                 :            : 
+     217                 :            : /*
+     218                 :            :  * ECParameters ::= CHOICE {
+     219                 :            :  *   namedCurve         OBJECT IDENTIFIER
+     220                 :            :  * }
+     221                 :            :  */
+     222                 :         12 : static int pk_write_ec_param(unsigned char **p, unsigned char *start,
+     223                 :            :                              mbedtls_ecp_group_id grp_id)
+     224                 :            : {
+     225                 :         12 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     226                 :         12 :     size_t len = 0;
+     227                 :            :     const char *oid;
+     228                 :            :     size_t oid_len;
+     229                 :            : 
+     230         [ -  + ]:         12 :     if ((ret = mbedtls_oid_get_oid_by_ec_grp(grp_id, &oid, &oid_len)) != 0) {
+     231                 :          0 :         return ret;
+     232                 :            :     }
+     233                 :            : 
+     234         [ -  + ]:         12 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_oid(p, start, oid, oid_len));
+     235                 :            : 
+     236                 :         12 :     return (int) len;
+     237                 :            : }
+     238                 :            : 
+     239                 :            : #if defined(MBEDTLS_PK_HAVE_RFC8410_CURVES)
+     240                 :            : /*
+     241                 :            :  * RFC8410 section 7
+     242                 :            :  *
+     243                 :            :  * OneAsymmetricKey ::= SEQUENCE {
+     244                 :            :  *    version Version,
+     245                 :            :  *    privateKeyAlgorithm PrivateKeyAlgorithmIdentifier,
+     246                 :            :  *    privateKey PrivateKey,
+     247                 :            :  *    attributes [0] IMPLICIT Attributes OPTIONAL,
+     248                 :            :  *    ...,
+     249                 :            :  *    [[2: publicKey [1] IMPLICIT PublicKey OPTIONAL ]],
+     250                 :            :  *    ...
+     251                 :            :  * }
+     252                 :            :  * ...
+     253                 :            :  * CurvePrivateKey ::= OCTET STRING
+     254                 :            :  */
+     255                 :          0 : static int pk_write_ec_rfc8410_der(unsigned char **p, unsigned char *buf,
+     256                 :            :                                    const mbedtls_pk_context *pk)
+     257                 :            : {
+     258                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     259                 :          0 :     size_t len = 0;
+     260                 :          0 :     size_t oid_len = 0;
+     261                 :            :     const char *oid;
+     262                 :            :     mbedtls_ecp_group_id grp_id;
+     263                 :            : 
+     264                 :            :     /* privateKey */
+     265         [ #  # ]:          0 :     MBEDTLS_ASN1_CHK_ADD(len, pk_write_ec_private(p, buf, pk));
+     266         [ #  # ]:          0 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(p, buf, len));
+     267         [ #  # ]:          0 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(p, buf, MBEDTLS_ASN1_OCTET_STRING));
+     268                 :            : 
+     269                 :          0 :     grp_id = mbedtls_pk_get_ec_group_id(pk);
+     270                 :            :     /* privateKeyAlgorithm */
+     271         [ #  # ]:          0 :     if ((ret = mbedtls_oid_get_oid_by_ec_grp_algid(grp_id, &oid, &oid_len)) != 0) {
+     272                 :          0 :         return ret;
+     273                 :            :     }
+     274         [ #  # ]:          0 :     MBEDTLS_ASN1_CHK_ADD(len,
+     275                 :            :                          mbedtls_asn1_write_algorithm_identifier_ext(p, buf, oid, oid_len, 0, 0));
+     276                 :            : 
+     277                 :            :     /* version */
+     278         [ #  # ]:          0 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_int(p, buf, 0));
+     279                 :            : 
+     280         [ #  # ]:          0 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(p, buf, len));
+     281         [ #  # ]:          0 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(p, buf, MBEDTLS_ASN1_CONSTRUCTED |
+     282                 :            :                                                      MBEDTLS_ASN1_SEQUENCE));
+     283                 :            : 
+     284                 :          0 :     return (int) len;
+     285                 :            : }
+     286                 :            : #endif /* MBEDTLS_PK_HAVE_RFC8410_CURVES */
+     287                 :            : 
+     288                 :            : /*
+     289                 :            :  * RFC 5915, or SEC1 Appendix C.4
+     290                 :            :  *
+     291                 :            :  * ECPrivateKey ::= SEQUENCE {
+     292                 :            :  *      version        INTEGER { ecPrivkeyVer1(1) } (ecPrivkeyVer1),
+     293                 :            :  *      privateKey     OCTET STRING,
+     294                 :            :  *      parameters [0] ECParameters {{ NamedCurve }} OPTIONAL,
+     295                 :            :  *      publicKey  [1] BIT STRING OPTIONAL
+     296                 :            :  *    }
+     297                 :            :  */
+     298                 :          0 : static int pk_write_ec_der(unsigned char **p, unsigned char *buf,
+     299                 :            :                            const mbedtls_pk_context *pk)
+     300                 :            : {
+     301                 :          0 :     size_t len = 0;
+     302                 :            :     int ret;
+     303                 :          0 :     size_t pub_len = 0, par_len = 0;
+     304                 :            :     mbedtls_ecp_group_id grp_id;
+     305                 :            : 
+     306                 :            :     /* publicKey */
+     307         [ #  # ]:          0 :     MBEDTLS_ASN1_CHK_ADD(pub_len, pk_write_ec_pubkey(p, buf, pk));
+     308                 :            : 
+     309         [ #  # ]:          0 :     if (*p - buf < 1) {
+     310                 :          0 :         return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL;
+     311                 :            :     }
+     312                 :          0 :     (*p)--;
+     313                 :          0 :     **p = 0;
+     314                 :          0 :     pub_len += 1;
+     315                 :            : 
+     316         [ #  # ]:          0 :     MBEDTLS_ASN1_CHK_ADD(pub_len, mbedtls_asn1_write_len(p, buf, pub_len));
+     317         [ #  # ]:          0 :     MBEDTLS_ASN1_CHK_ADD(pub_len, mbedtls_asn1_write_tag(p, buf, MBEDTLS_ASN1_BIT_STRING));
+     318                 :            : 
+     319         [ #  # ]:          0 :     MBEDTLS_ASN1_CHK_ADD(pub_len, mbedtls_asn1_write_len(p, buf, pub_len));
+     320         [ #  # ]:          0 :     MBEDTLS_ASN1_CHK_ADD(pub_len, mbedtls_asn1_write_tag(p, buf,
+     321                 :            :                                                          MBEDTLS_ASN1_CONTEXT_SPECIFIC |
+     322                 :            :                                                          MBEDTLS_ASN1_CONSTRUCTED | 1));
+     323                 :          0 :     len += pub_len;
+     324                 :            : 
+     325                 :            :     /* parameters */
+     326                 :          0 :     grp_id = mbedtls_pk_get_ec_group_id(pk);
+     327         [ #  # ]:          0 :     MBEDTLS_ASN1_CHK_ADD(par_len, pk_write_ec_param(p, buf, grp_id));
+     328         [ #  # ]:          0 :     MBEDTLS_ASN1_CHK_ADD(par_len, mbedtls_asn1_write_len(p, buf, par_len));
+     329         [ #  # ]:          0 :     MBEDTLS_ASN1_CHK_ADD(par_len, mbedtls_asn1_write_tag(p, buf,
+     330                 :            :                                                          MBEDTLS_ASN1_CONTEXT_SPECIFIC |
+     331                 :            :                                                          MBEDTLS_ASN1_CONSTRUCTED | 0));
+     332                 :          0 :     len += par_len;
+     333                 :            : 
+     334                 :            :     /* privateKey */
+     335         [ #  # ]:          0 :     MBEDTLS_ASN1_CHK_ADD(len, pk_write_ec_private(p, buf, pk));
+     336                 :            : 
+     337                 :            :     /* version */
+     338         [ #  # ]:          0 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_int(p, buf, 1));
+     339                 :            : 
+     340         [ #  # ]:          0 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(p, buf, len));
+     341         [ #  # ]:          0 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(p, buf, MBEDTLS_ASN1_CONSTRUCTED |
+     342                 :            :                                                      MBEDTLS_ASN1_SEQUENCE));
+     343                 :            : 
+     344                 :          0 :     return (int) len;
+     345                 :            : }
+     346                 :            : #endif /* MBEDTLS_PK_HAVE_ECC_KEYS */
+     347                 :            : 
+     348                 :            : /******************************************************************************
+     349                 :            :  * Internal functions for Opaque keys.
+     350                 :            :  ******************************************************************************/
+     351                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+     352                 :            : static int pk_write_opaque_pubkey(unsigned char **p, unsigned char *start,
+     353                 :            :                                   const mbedtls_pk_context *pk)
+     354                 :            : {
+     355                 :            :     size_t buffer_size;
+     356                 :            :     size_t len = 0;
+     357                 :            : 
+     358                 :            :     if (*p < start) {
+     359                 :            :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+     360                 :            :     }
+     361                 :            : 
+     362                 :            :     buffer_size = (size_t) (*p - start);
+     363                 :            :     if (psa_export_public_key(pk->priv_id, start, buffer_size,
+     364                 :            :                               &len) != PSA_SUCCESS) {
+     365                 :            :         return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
+     366                 :            :     }
+     367                 :            : 
+     368                 :            :     *p -= len;
+     369                 :            :     memmove(*p, start, len);
+     370                 :            : 
+     371                 :            :     return (int) len;
+     372                 :            : }
+     373                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO */
+     374                 :            : 
+     375                 :            : /******************************************************************************
+     376                 :            :  * Generic helpers
+     377                 :            :  ******************************************************************************/
+     378                 :            : 
+     379                 :            : /* Extend the public mbedtls_pk_get_type() by getting key type also in case of
+     380                 :            :  * opaque keys. */
+     381                 :         24 : static mbedtls_pk_type_t pk_get_type_ext(const mbedtls_pk_context *pk)
+     382                 :            : {
+     383                 :         24 :     mbedtls_pk_type_t pk_type = mbedtls_pk_get_type(pk);
+     384                 :            : 
+     385                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+     386                 :            :     if (pk_type == MBEDTLS_PK_OPAQUE) {
+     387                 :            :         psa_key_attributes_t opaque_attrs = PSA_KEY_ATTRIBUTES_INIT;
+     388                 :            :         psa_key_type_t opaque_key_type;
+     389                 :            : 
+     390                 :            :         if (psa_get_key_attributes(pk->priv_id, &opaque_attrs) != PSA_SUCCESS) {
+     391                 :            :             return MBEDTLS_PK_NONE;
+     392                 :            :         }
+     393                 :            :         opaque_key_type = psa_get_key_type(&opaque_attrs);
+     394                 :            :         psa_reset_key_attributes(&opaque_attrs);
+     395                 :            : 
+     396                 :            :         if (PSA_KEY_TYPE_IS_ECC(opaque_key_type)) {
+     397                 :            :             return MBEDTLS_PK_ECKEY;
+     398                 :            :         } else if (PSA_KEY_TYPE_IS_RSA(opaque_key_type)) {
+     399                 :            :             return MBEDTLS_PK_RSA;
+     400                 :            :         } else {
+     401                 :            :             return MBEDTLS_PK_NONE;
+     402                 :            :         }
+     403                 :            :     } else
+     404                 :            : #endif
+     405                 :         24 :     return pk_type;
+     406                 :            : }
+     407                 :            : 
+     408                 :            : /******************************************************************************
+     409                 :            :  * Public functions for writing private/public DER keys.
+     410                 :            :  ******************************************************************************/
+     411                 :         12 : int mbedtls_pk_write_pubkey(unsigned char **p, unsigned char *start,
+     412                 :            :                             const mbedtls_pk_context *key)
+     413                 :            : {
+     414                 :         12 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     415                 :         12 :     size_t len = 0;
+     416                 :            : 
+     417                 :            : #if defined(MBEDTLS_RSA_C)
+     418         [ -  + ]:         12 :     if (mbedtls_pk_get_type(key) == MBEDTLS_PK_RSA) {
+     419         [ #  # ]:          0 :         MBEDTLS_ASN1_CHK_ADD(len, mbedtls_rsa_write_pubkey(mbedtls_pk_rsa(*key), start, p));
+     420                 :            :     } else
+     421                 :            : #endif
+     422                 :            : #if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
+     423         [ +  - ]:         12 :     if (mbedtls_pk_get_type(key) == MBEDTLS_PK_ECKEY) {
+     424         [ -  + ]:         12 :         MBEDTLS_ASN1_CHK_ADD(len, pk_write_ec_pubkey(p, start, key));
+     425                 :            :     } else
+     426                 :            : #endif
+     427                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+     428                 :            :     if (mbedtls_pk_get_type(key) == MBEDTLS_PK_OPAQUE) {
+     429                 :            :         MBEDTLS_ASN1_CHK_ADD(len, pk_write_opaque_pubkey(p, start, key));
+     430                 :            :     } else
+     431                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO */
+     432                 :          0 :     return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE;
+     433                 :            : 
+     434                 :         12 :     return (int) len;
+     435                 :            : }
+     436                 :            : 
+     437                 :         12 : int mbedtls_pk_write_pubkey_der(const mbedtls_pk_context *key, unsigned char *buf, size_t size)
+     438                 :            : {
+     439                 :         12 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     440                 :            :     unsigned char *c;
+     441                 :         12 :     int has_par = 1;
+     442                 :         12 :     size_t len = 0, par_len = 0, oid_len = 0;
+     443                 :            :     mbedtls_pk_type_t pk_type;
+     444                 :         12 :     const char *oid = NULL;
+     445                 :            : 
+     446         [ -  + ]:         12 :     if (size == 0) {
+     447                 :          0 :         return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL;
+     448                 :            :     }
+     449                 :            : 
+     450                 :         12 :     c = buf + size;
+     451                 :            : 
+     452         [ -  + ]:         12 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_pk_write_pubkey(&c, buf, key));
+     453                 :            : 
+     454         [ -  + ]:         12 :     if (c - buf < 1) {
+     455                 :          0 :         return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL;
+     456                 :            :     }
+     457                 :            : 
+     458                 :            :     /*
+     459                 :            :      *  SubjectPublicKeyInfo  ::=  SEQUENCE  {
+     460                 :            :      *       algorithm            AlgorithmIdentifier,
+     461                 :            :      *       subjectPublicKey     BIT STRING }
+     462                 :            :      */
+     463                 :         12 :     *--c = 0;
+     464                 :         12 :     len += 1;
+     465                 :            : 
+     466         [ -  + ]:         12 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(&c, buf, len));
+     467         [ -  + ]:         12 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(&c, buf, MBEDTLS_ASN1_BIT_STRING));
+     468                 :            : 
+     469                 :         12 :     pk_type = pk_get_type_ext(key);
+     470                 :            : 
+     471                 :            : #if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
+     472         [ +  - ]:         12 :     if (pk_get_type_ext(key) == MBEDTLS_PK_ECKEY) {
+     473                 :         12 :         mbedtls_ecp_group_id ec_grp_id = mbedtls_pk_get_ec_group_id(key);
+     474   [ +  -  -  + ]:         12 :         if (MBEDTLS_PK_IS_RFC8410_GROUP_ID(ec_grp_id)) {
+     475                 :          0 :             ret = mbedtls_oid_get_oid_by_ec_grp_algid(ec_grp_id, &oid, &oid_len);
+     476         [ #  # ]:          0 :             if (ret != 0) {
+     477                 :          0 :                 return ret;
+     478                 :            :             }
+     479                 :          0 :             has_par = 0;
+     480                 :            :         } else {
+     481         [ -  + ]:         12 :             MBEDTLS_ASN1_CHK_ADD(par_len, pk_write_ec_param(&c, buf, ec_grp_id));
+     482                 :            :         }
+     483                 :            :     }
+     484                 :            : #endif /* MBEDTLS_PK_HAVE_ECC_KEYS */
+     485                 :            : 
+     486                 :            :     /* At this point oid_len is not null only for EC Montgomery keys. */
+     487         [ +  - ]:         12 :     if (oid_len == 0) {
+     488                 :         12 :         ret = mbedtls_oid_get_oid_by_pk_alg(pk_type, &oid, &oid_len);
+     489         [ -  + ]:         12 :         if (ret != 0) {
+     490                 :          0 :             return ret;
+     491                 :            :         }
+     492                 :            :     }
+     493                 :            : 
+     494         [ -  + ]:         12 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_algorithm_identifier_ext(&c, buf, oid, oid_len,
+     495                 :            :                                                                           par_len, has_par));
+     496                 :            : 
+     497         [ -  + ]:         12 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(&c, buf, len));
+     498         [ -  + ]:         12 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(&c, buf, MBEDTLS_ASN1_CONSTRUCTED |
+     499                 :            :                                                      MBEDTLS_ASN1_SEQUENCE));
+     500                 :            : 
+     501                 :         12 :     return (int) len;
+     502                 :            : }
+     503                 :            : 
+     504                 :          0 : int mbedtls_pk_write_key_der(const mbedtls_pk_context *key, unsigned char *buf, size_t size)
+     505                 :            : {
+     506                 :            :     unsigned char *c;
+     507                 :            : 
+     508         [ #  # ]:          0 :     if (size == 0) {
+     509                 :          0 :         return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL;
+     510                 :            :     }
+     511                 :            : 
+     512                 :          0 :     c = buf + size;
+     513                 :            : 
+     514                 :            : #if defined(MBEDTLS_RSA_C)
+     515         [ #  # ]:          0 :     if (pk_get_type_ext(key) == MBEDTLS_PK_RSA) {
+     516                 :          0 :         return pk_write_rsa_der(&c, buf, key);
+     517                 :            :     } else
+     518                 :            : #endif /* MBEDTLS_RSA_C */
+     519                 :            : #if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
+     520         [ #  # ]:          0 :     if (pk_get_type_ext(key) == MBEDTLS_PK_ECKEY) {
+     521                 :            : #if defined(MBEDTLS_PK_HAVE_RFC8410_CURVES)
+     522         [ #  # ]:          0 :         if (mbedtls_pk_is_rfc8410(key)) {
+     523                 :          0 :             return pk_write_ec_rfc8410_der(&c, buf, key);
+     524                 :            :         }
+     525                 :            : #endif /* MBEDTLS_PK_HAVE_RFC8410_CURVES */
+     526                 :          0 :         return pk_write_ec_der(&c, buf, key);
+     527                 :            :     } else
+     528                 :            : #endif /* MBEDTLS_PK_HAVE_ECC_KEYS */
+     529                 :          0 :     return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE;
+     530                 :            : }
+     531                 :            : 
+     532                 :            : /******************************************************************************
+     533                 :            :  * Public functions for wrinting private/public PEM keys.
+     534                 :            :  ******************************************************************************/
+     535                 :            : #if defined(MBEDTLS_PEM_WRITE_C)
+     536                 :            : 
+     537                 :            : #define PUB_DER_MAX_BYTES                                                   \
+     538                 :            :     (MBEDTLS_PK_RSA_PUB_DER_MAX_BYTES > MBEDTLS_PK_ECP_PUB_DER_MAX_BYTES ? \
+     539                 :            :      MBEDTLS_PK_RSA_PUB_DER_MAX_BYTES : MBEDTLS_PK_ECP_PUB_DER_MAX_BYTES)
+     540                 :            : #define PRV_DER_MAX_BYTES                                                   \
+     541                 :            :     (MBEDTLS_PK_RSA_PRV_DER_MAX_BYTES > MBEDTLS_PK_ECP_PRV_DER_MAX_BYTES ? \
+     542                 :            :      MBEDTLS_PK_RSA_PRV_DER_MAX_BYTES : MBEDTLS_PK_ECP_PRV_DER_MAX_BYTES)
+     543                 :            : 
+     544                 :          0 : int mbedtls_pk_write_pubkey_pem(const mbedtls_pk_context *key, unsigned char *buf, size_t size)
+     545                 :            : {
+     546                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     547                 :          0 :     unsigned char *output_buf = NULL;
+     548                 :          0 :     output_buf = mbedtls_calloc(1, PUB_DER_MAX_BYTES);
+     549         [ #  # ]:          0 :     if (output_buf == NULL) {
+     550                 :          0 :         return MBEDTLS_ERR_PK_ALLOC_FAILED;
+     551                 :            :     }
+     552                 :          0 :     size_t olen = 0;
+     553                 :            : 
+     554         [ #  # ]:          0 :     if ((ret = mbedtls_pk_write_pubkey_der(key, output_buf,
+     555                 :            :                                            PUB_DER_MAX_BYTES)) < 0) {
+     556                 :          0 :         goto cleanup;
+     557                 :            :     }
+     558                 :            : 
+     559         [ #  # ]:          0 :     if ((ret = mbedtls_pem_write_buffer(PEM_BEGIN_PUBLIC_KEY "\n", PEM_END_PUBLIC_KEY "\n",
+     560                 :          0 :                                         output_buf + PUB_DER_MAX_BYTES - ret,
+     561                 :            :                                         ret, buf, size, &olen)) != 0) {
+     562                 :          0 :         goto cleanup;
+     563                 :            :     }
+     564                 :            : 
+     565                 :          0 :     ret = 0;
+     566                 :          0 : cleanup:
+     567                 :          0 :     mbedtls_free(output_buf);
+     568                 :          0 :     return ret;
+     569                 :            : }
+     570                 :            : 
+     571                 :          0 : int mbedtls_pk_write_key_pem(const mbedtls_pk_context *key, unsigned char *buf, size_t size)
+     572                 :            : {
+     573                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     574                 :          0 :     unsigned char *output_buf = NULL;
+     575                 :          0 :     output_buf = mbedtls_calloc(1, PRV_DER_MAX_BYTES);
+     576         [ #  # ]:          0 :     if (output_buf == NULL) {
+     577                 :          0 :         return MBEDTLS_ERR_PK_ALLOC_FAILED;
+     578                 :            :     }
+     579                 :            :     const char *begin, *end;
+     580                 :          0 :     size_t olen = 0;
+     581                 :            : 
+     582         [ #  # ]:          0 :     if ((ret = mbedtls_pk_write_key_der(key, output_buf, PRV_DER_MAX_BYTES)) < 0) {
+     583                 :          0 :         goto cleanup;
+     584                 :            :     }
+     585                 :            : 
+     586                 :            : #if defined(MBEDTLS_RSA_C)
+     587         [ #  # ]:          0 :     if (pk_get_type_ext(key) == MBEDTLS_PK_RSA) {
+     588                 :          0 :         begin = PEM_BEGIN_PRIVATE_KEY_RSA "\n";
+     589                 :          0 :         end = PEM_END_PRIVATE_KEY_RSA "\n";
+     590                 :            :     } else
+     591                 :            : #endif
+     592                 :            : #if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
+     593         [ #  # ]:          0 :     if (pk_get_type_ext(key) == MBEDTLS_PK_ECKEY) {
+     594         [ #  # ]:          0 :         if (mbedtls_pk_is_rfc8410(key)) {
+     595                 :          0 :             begin = PEM_BEGIN_PRIVATE_KEY_PKCS8 "\n";
+     596                 :          0 :             end = PEM_END_PRIVATE_KEY_PKCS8 "\n";
+     597                 :            :         } else {
+     598                 :          0 :             begin = PEM_BEGIN_PRIVATE_KEY_EC "\n";
+     599                 :          0 :             end = PEM_END_PRIVATE_KEY_EC "\n";
+     600                 :            :         }
+     601                 :            :     } else
+     602                 :            : #endif /* MBEDTLS_PK_HAVE_ECC_KEYS */
+     603                 :            :     {
+     604                 :          0 :         ret = MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE;
+     605                 :          0 :         goto cleanup;
+     606                 :            :     }
+     607                 :            : 
+     608         [ #  # ]:          0 :     if ((ret = mbedtls_pem_write_buffer(begin, end,
+     609                 :          0 :                                         output_buf + PRV_DER_MAX_BYTES - ret,
+     610                 :            :                                         ret, buf, size, &olen)) != 0) {
+     611                 :          0 :         goto cleanup;
+     612                 :            :     }
+     613                 :            : 
+     614                 :          0 :     ret = 0;
+     615                 :          0 : cleanup:
+     616                 :          0 :     mbedtls_zeroize_and_free(output_buf, PRV_DER_MAX_BYTES);
+     617                 :          0 :     return ret;
+     618                 :            : }
+     619                 :            : #endif /* MBEDTLS_PEM_WRITE_C */
+     620                 :            : 
+     621                 :            : #endif /* MBEDTLS_PK_WRITE_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/platform_util.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/platform_util.c.func-sort-c.html new file mode 100644 index 00000000000..146882b1c38 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/platform_util.c.func-sort-c.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/platform_util.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - platform_util.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:71353.8 %
Date:2024-09-22 08:21:07Functions:2366.7 %
Branches:1425.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_ms_time0
mbedtls_platform_gmtime_r2255
mbedtls_zeroize_and_free2517173
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/platform_util.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/platform_util.c.func.html new file mode 100644 index 00000000000..ac87c758277 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/platform_util.c.func.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/platform_util.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - platform_util.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:71353.8 %
Date:2024-09-22 08:21:07Functions:2366.7 %
Branches:1425.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_ms_time0
mbedtls_platform_gmtime_r2255
mbedtls_zeroize_and_free2517173
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/platform_util.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/platform_util.c.gcov.html new file mode 100644 index 00000000000..a6dd2f0c80a --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/platform_util.c.gcov.html @@ -0,0 +1,348 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/platform_util.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - platform_util.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:71353.8 %
Date:2024-09-22 08:21:07Functions:2366.7 %
Branches:1425.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  * Common and shared functions used by multiple modules in the Mbed TLS
+       3                 :            :  * library.
+       4                 :            :  *
+       5                 :            :  *  Copyright The Mbed TLS Contributors
+       6                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       7                 :            :  */
+       8                 :            : 
+       9                 :            : /*
+      10                 :            :  * Ensure gmtime_r is available even with -std=c99; must be defined before
+      11                 :            :  * mbedtls_config.h, which pulls in glibc's features.h. Harmless on other platforms
+      12                 :            :  * except OpenBSD, where it stops us accessing explicit_bzero.
+      13                 :            :  */
+      14                 :            : #if !defined(_POSIX_C_SOURCE) && !defined(__OpenBSD__)
+      15                 :            : #define _POSIX_C_SOURCE 200112L
+      16                 :            : #endif
+      17                 :            : 
+      18                 :            : #if !defined(_GNU_SOURCE)
+      19                 :            : /* Clang requires this to get support for explicit_bzero */
+      20                 :            : #define _GNU_SOURCE
+      21                 :            : #endif
+      22                 :            : 
+      23                 :            : #include "common.h"
+      24                 :            : 
+      25                 :            : #include "mbedtls/platform_util.h"
+      26                 :            : #include "mbedtls/platform.h"
+      27                 :            : #include "mbedtls/threading.h"
+      28                 :            : 
+      29                 :            : #include <stddef.h>
+      30                 :            : 
+      31                 :            : #ifndef __STDC_WANT_LIB_EXT1__
+      32                 :            : #define __STDC_WANT_LIB_EXT1__ 1 /* Ask for the C11 gmtime_s() and memset_s() if available */
+      33                 :            : #endif
+      34                 :            : #include <string.h>
+      35                 :            : 
+      36                 :            : #if defined(_WIN32)
+      37                 :            : #include <windows.h>
+      38                 :            : #endif
+      39                 :            : 
+      40                 :            : // Detect platforms known to support explicit_bzero()
+      41                 :            : #if defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 25)
+      42                 :            : #define MBEDTLS_PLATFORM_HAS_EXPLICIT_BZERO 1
+      43                 :            : #elif (defined(__FreeBSD__) && (__FreeBSD_version >= 1100037)) || defined(__OpenBSD__)
+      44                 :            : #define MBEDTLS_PLATFORM_HAS_EXPLICIT_BZERO 1
+      45                 :            : #endif
+      46                 :            : 
+      47                 :            : #if !defined(MBEDTLS_PLATFORM_ZEROIZE_ALT)
+      48                 :            : 
+      49                 :            : #undef HAVE_MEMORY_SANITIZER
+      50                 :            : #if defined(__has_feature)
+      51                 :            : #if __has_feature(memory_sanitizer)
+      52                 :            : #include <sanitizer/msan_interface.h>
+      53                 :            : #define HAVE_MEMORY_SANITIZER
+      54                 :            : #endif
+      55                 :            : #endif
+      56                 :            : 
+      57                 :            : /*
+      58                 :            :  * Where possible, we try to detect the presence of a platform-provided
+      59                 :            :  * secure memset, such as explicit_bzero(), that is safe against being optimized
+      60                 :            :  * out, and use that.
+      61                 :            :  *
+      62                 :            :  * For other platforms, we provide an implementation that aims not to be
+      63                 :            :  * optimized out by the compiler.
+      64                 :            :  *
+      65                 :            :  * This implementation for mbedtls_platform_zeroize() was inspired from Colin
+      66                 :            :  * Percival's blog article at:
+      67                 :            :  *
+      68                 :            :  * http://www.daemonology.net/blog/2014-09-04-how-to-zero-a-buffer.html
+      69                 :            :  *
+      70                 :            :  * It uses a volatile function pointer to the standard memset(). Because the
+      71                 :            :  * pointer is volatile the compiler expects it to change at
+      72                 :            :  * any time and will not optimize out the call that could potentially perform
+      73                 :            :  * other operations on the input buffer instead of just setting it to 0.
+      74                 :            :  * Nevertheless, as pointed out by davidtgoldblatt on Hacker News
+      75                 :            :  * (refer to http://www.daemonology.net/blog/2014-09-05-erratum.html for
+      76                 :            :  * details), optimizations of the following form are still possible:
+      77                 :            :  *
+      78                 :            :  * if (memset_func != memset)
+      79                 :            :  *     memset_func(buf, 0, len);
+      80                 :            :  *
+      81                 :            :  * Note that it is extremely difficult to guarantee that
+      82                 :            :  * the memset() call will not be optimized out by aggressive compilers
+      83                 :            :  * in a portable way. For this reason, Mbed TLS also provides the configuration
+      84                 :            :  * option MBEDTLS_PLATFORM_ZEROIZE_ALT, which allows users to configure
+      85                 :            :  * mbedtls_platform_zeroize() to use a suitable implementation for their
+      86                 :            :  * platform and needs.
+      87                 :            :  */
+      88                 :            : #if !defined(MBEDTLS_PLATFORM_HAS_EXPLICIT_BZERO) && !(defined(__STDC_LIB_EXT1__) && \
+      89                 :            :     !defined(__IAR_SYSTEMS_ICC__)) \
+      90                 :            :     && !defined(_WIN32)
+      91                 :            : static void *(*const volatile memset_func)(void *, int, size_t) = memset;
+      92                 :            : #endif
+      93                 :            : 
+      94                 :            : void mbedtls_platform_zeroize(void *buf, size_t len)
+      95                 :            : {
+      96                 :            :     if (len > 0) {
+      97                 :            : #if defined(MBEDTLS_PLATFORM_HAS_EXPLICIT_BZERO)
+      98                 :            :         explicit_bzero(buf, len);
+      99                 :            : #if defined(HAVE_MEMORY_SANITIZER)
+     100                 :            :         /* You'd think that Msan would recognize explicit_bzero() as
+     101                 :            :          * equivalent to bzero(), but it actually doesn't on several
+     102                 :            :          * platforms, including Linux (Ubuntu 20.04).
+     103                 :            :          * https://github.com/google/sanitizers/issues/1507
+     104                 :            :          * https://github.com/openssh/openssh-portable/commit/74433a19bb6f4cef607680fa4d1d7d81ca3826aa
+     105                 :            :          */
+     106                 :            :         __msan_unpoison(buf, len);
+     107                 :            : #endif
+     108                 :            : #elif defined(__STDC_LIB_EXT1__) && !defined(__IAR_SYSTEMS_ICC__)
+     109                 :            :         memset_s(buf, len, 0, len);
+     110                 :            : #elif defined(_WIN32)
+     111                 :            :         SecureZeroMemory(buf, len);
+     112                 :            : #else
+     113                 :            :         memset_func(buf, 0, len);
+     114                 :            : #endif
+     115                 :            : 
+     116                 :            : #if defined(__GNUC__)
+     117                 :            :         /* For clang and recent gcc, pretend that we have some assembly that reads the
+     118                 :            :          * zero'd memory as an additional protection against being optimised away. */
+     119                 :            : #if defined(__clang__) || (__GNUC__ >= 10)
+     120                 :            : #if defined(__clang__)
+     121                 :            : #pragma clang diagnostic push
+     122                 :            : #pragma clang diagnostic ignored "-Wvla"
+     123                 :            : #elif defined(MBEDTLS_COMPILER_IS_GCC)
+     124                 :            : #pragma GCC diagnostic push
+     125                 :            : #pragma GCC diagnostic ignored "-Wvla"
+     126                 :            : #endif
+     127                 :            :         asm volatile ("" : : "m" (*(char (*)[len]) buf) :);
+     128                 :            : #if defined(__clang__)
+     129                 :            : #pragma clang diagnostic pop
+     130                 :            : #elif defined(MBEDTLS_COMPILER_IS_GCC)
+     131                 :            : #pragma GCC diagnostic pop
+     132                 :            : #endif
+     133                 :            : #endif
+     134                 :            : #endif
+     135                 :            :     }
+     136                 :            : }
+     137                 :            : #endif /* MBEDTLS_PLATFORM_ZEROIZE_ALT */
+     138                 :            : 
+     139                 :    2517173 : void mbedtls_zeroize_and_free(void *buf, size_t len)
+     140                 :            : {
+     141         [ +  - ]:    2517173 :     if (buf != NULL) {
+     142                 :    2517173 :         mbedtls_platform_zeroize(buf, len);
+     143                 :            :     }
+     144                 :            : 
+     145                 :    2517173 :     mbedtls_free(buf);
+     146                 :    2517173 : }
+     147                 :            : 
+     148                 :            : #if defined(MBEDTLS_HAVE_TIME_DATE) && !defined(MBEDTLS_PLATFORM_GMTIME_R_ALT)
+     149                 :            : #include <time.h>
+     150                 :            : #if !defined(_WIN32) && (defined(unix) || \
+     151                 :            :     defined(__unix) || defined(__unix__) || (defined(__APPLE__) && \
+     152                 :            :     defined(__MACH__)) || defined__midipix__)
+     153                 :            : #include <unistd.h>
+     154                 :            : #endif /* !_WIN32 && (unix || __unix || __unix__ ||
+     155                 :            :         * (__APPLE__ && __MACH__) || __midipix__) */
+     156                 :            : 
+     157                 :            : #if !((defined(_POSIX_VERSION) && _POSIX_VERSION >= 200809L) ||     \
+     158                 :            :     (defined(_POSIX_THREAD_SAFE_FUNCTIONS) &&                     \
+     159                 :            :     _POSIX_THREAD_SAFE_FUNCTIONS >= 200112L))
+     160                 :            : /*
+     161                 :            :  * This is a convenience shorthand macro to avoid checking the long
+     162                 :            :  * preprocessor conditions above. Ideally, we could expose this macro in
+     163                 :            :  * platform_util.h and simply use it in platform_util.c, threading.c and
+     164                 :            :  * threading.h. However, this macro is not part of the Mbed TLS public API, so
+     165                 :            :  * we keep it private by only defining it in this file
+     166                 :            :  */
+     167                 :            : #if !(defined(_WIN32) && !defined(EFIX64) && !defined(EFI32)) || \
+     168                 :            :     (defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR))
+     169                 :            : #define PLATFORM_UTIL_USE_GMTIME
+     170                 :            : #endif
+     171                 :            : 
+     172                 :            : #endif /* !( ( defined(_POSIX_VERSION) && _POSIX_VERSION >= 200809L ) || \
+     173                 :            :              ( defined(_POSIX_THREAD_SAFE_FUNCTIONS ) && \
+     174                 :            :                 _POSIX_THREAD_SAFE_FUNCTIONS >= 200112L ) ) */
+     175                 :            : 
+     176                 :       2255 : struct tm *mbedtls_platform_gmtime_r(const mbedtls_time_t *tt,
+     177                 :            :                                      struct tm *tm_buf)
+     178                 :            : {
+     179                 :            : #if defined(_WIN32) && !defined(PLATFORM_UTIL_USE_GMTIME)
+     180                 :            : #if defined(__STDC_LIB_EXT1__)
+     181                 :            :     return (gmtime_s(tt, tm_buf) == 0) ? NULL : tm_buf;
+     182                 :            : #else
+     183                 :            :     /* MSVC and mingw64 argument order and return value are inconsistent with the C11 standard */
+     184                 :            :     return (gmtime_s(tm_buf, tt) == 0) ? tm_buf : NULL;
+     185                 :            : #endif
+     186                 :            : #elif !defined(PLATFORM_UTIL_USE_GMTIME)
+     187                 :       2255 :     return gmtime_r(tt, tm_buf);
+     188                 :            : #else
+     189                 :            :     struct tm *lt;
+     190                 :            : 
+     191                 :            : #if defined(MBEDTLS_THREADING_C)
+     192                 :            :     if (mbedtls_mutex_lock(&mbedtls_threading_gmtime_mutex) != 0) {
+     193                 :            :         return NULL;
+     194                 :            :     }
+     195                 :            : #endif /* MBEDTLS_THREADING_C */
+     196                 :            : 
+     197                 :            :     lt = gmtime(tt);
+     198                 :            : 
+     199                 :            :     if (lt != NULL) {
+     200                 :            :         memcpy(tm_buf, lt, sizeof(struct tm));
+     201                 :            :     }
+     202                 :            : 
+     203                 :            : #if defined(MBEDTLS_THREADING_C)
+     204                 :            :     if (mbedtls_mutex_unlock(&mbedtls_threading_gmtime_mutex) != 0) {
+     205                 :            :         return NULL;
+     206                 :            :     }
+     207                 :            : #endif /* MBEDTLS_THREADING_C */
+     208                 :            : 
+     209                 :            :     return (lt == NULL) ? NULL : tm_buf;
+     210                 :            : #endif /* _WIN32 && !EFIX64 && !EFI32 */
+     211                 :            : }
+     212                 :            : #endif /* MBEDTLS_HAVE_TIME_DATE && MBEDTLS_PLATFORM_GMTIME_R_ALT */
+     213                 :            : 
+     214                 :            : #if defined(MBEDTLS_TEST_HOOKS)
+     215                 :            : void (*mbedtls_test_hook_test_fail)(const char *, int, const char *);
+     216                 :            : #endif /* MBEDTLS_TEST_HOOKS */
+     217                 :            : 
+     218                 :            : #if defined(MBEDTLS_HAVE_TIME) && !defined(MBEDTLS_PLATFORM_MS_TIME_ALT)
+     219                 :            : 
+     220                 :            : #include <time.h>
+     221                 :            : #if !defined(_WIN32) && \
+     222                 :            :     (defined(unix) || defined(__unix) || defined(__unix__) || \
+     223                 :            :     (defined(__APPLE__) && defined(__MACH__)) || defined(__HAIKU__) || defined(__midipix__))
+     224                 :            : #include <unistd.h>
+     225                 :            : #endif \
+     226                 :            :     /* !_WIN32 && (unix || __unix || __unix__ || (__APPLE__ && __MACH__) || __HAIKU__ || __midipix__) */
+     227                 :            : #if (defined(_POSIX_VERSION) && _POSIX_VERSION >= 199309L) || defined(__HAIKU__)
+     228                 :          0 : mbedtls_ms_time_t mbedtls_ms_time(void)
+     229                 :            : {
+     230                 :            :     int ret;
+     231                 :            :     struct timespec tv;
+     232                 :            :     mbedtls_ms_time_t current_ms;
+     233                 :            : 
+     234                 :            : #if defined(__linux__) && defined(CLOCK_BOOTTIME) || defined(__midipix__)
+     235                 :          0 :     ret = clock_gettime(CLOCK_BOOTTIME, &tv);
+     236                 :            : #else
+     237                 :            :     ret = clock_gettime(CLOCK_MONOTONIC, &tv);
+     238                 :            : #endif
+     239         [ #  # ]:          0 :     if (ret) {
+     240                 :          0 :         return time(NULL) * 1000;
+     241                 :            :     }
+     242                 :            : 
+     243                 :          0 :     current_ms = tv.tv_sec;
+     244                 :            : 
+     245                 :          0 :     return current_ms*1000 + tv.tv_nsec / 1000000;
+     246                 :            : }
+     247                 :            : #elif defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) || \
+     248                 :            :     defined(__MINGW32__) || defined(_WIN64)
+     249                 :            : #include <windows.h>
+     250                 :            : mbedtls_ms_time_t mbedtls_ms_time(void)
+     251                 :            : {
+     252                 :            :     FILETIME ct;
+     253                 :            :     mbedtls_ms_time_t current_ms;
+     254                 :            : 
+     255                 :            :     GetSystemTimeAsFileTime(&ct);
+     256                 :            :     current_ms = ((mbedtls_ms_time_t) ct.dwLowDateTime +
+     257                 :            :                   ((mbedtls_ms_time_t) (ct.dwHighDateTime) << 32LL))/10000;
+     258                 :            :     return current_ms;
+     259                 :            : }
+     260                 :            : #else
+     261                 :            : #error "No mbedtls_ms_time available"
+     262                 :            : #endif
+     263                 :            : #endif /* MBEDTLS_HAVE_TIME && !MBEDTLS_PLATFORM_MS_TIME_ALT */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/poly1305.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/poly1305.c.func-sort-c.html new file mode 100644 index 00000000000..68cc468eb7b --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/poly1305.c.func-sort-c.html @@ -0,0 +1,121 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/poly1305.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - poly1305.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:01940.0 %
Date:2024-09-22 08:21:07Functions:0100.0 %
Branches:0360.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_poly1305_finish0
mbedtls_poly1305_free0
mbedtls_poly1305_init0
mbedtls_poly1305_mac0
mbedtls_poly1305_self_test0
mbedtls_poly1305_starts0
mbedtls_poly1305_update0
mul640
poly1305_compute_mac0
poly1305_process0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/poly1305.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/poly1305.c.func.html new file mode 100644 index 00000000000..3316b79d587 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/poly1305.c.func.html @@ -0,0 +1,121 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/poly1305.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - poly1305.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:01940.0 %
Date:2024-09-22 08:21:07Functions:0100.0 %
Branches:0360.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_poly1305_finish0
mbedtls_poly1305_free0
mbedtls_poly1305_init0
mbedtls_poly1305_mac0
mbedtls_poly1305_self_test0
mbedtls_poly1305_starts0
mbedtls_poly1305_update0
mul640
poly1305_compute_mac0
poly1305_process0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/poly1305.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/poly1305.c.gcov.html new file mode 100644 index 00000000000..53593be761c --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/poly1305.c.gcov.html @@ -0,0 +1,577 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/poly1305.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - poly1305.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:01940.0 %
Date:2024-09-22 08:21:07Functions:0100.0 %
Branches:0360.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  * \file poly1305.c
+       3                 :            :  *
+       4                 :            :  * \brief Poly1305 authentication algorithm.
+       5                 :            :  *
+       6                 :            :  *  Copyright The Mbed TLS Contributors
+       7                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       8                 :            :  */
+       9                 :            : #include "common.h"
+      10                 :            : 
+      11                 :            : #if defined(MBEDTLS_POLY1305_C)
+      12                 :            : 
+      13                 :            : #include "mbedtls/poly1305.h"
+      14                 :            : #include "mbedtls/platform_util.h"
+      15                 :            : #include "mbedtls/error.h"
+      16                 :            : 
+      17                 :            : #include <string.h>
+      18                 :            : 
+      19                 :            : #include "mbedtls/platform.h"
+      20                 :            : 
+      21                 :            : #if !defined(MBEDTLS_POLY1305_ALT)
+      22                 :            : 
+      23                 :            : #define POLY1305_BLOCK_SIZE_BYTES (16U)
+      24                 :            : 
+      25                 :            : /*
+      26                 :            :  * Our implementation is tuned for 32-bit platforms with a 64-bit multiplier.
+      27                 :            :  * However we provided an alternative for platforms without such a multiplier.
+      28                 :            :  */
+      29                 :            : #if defined(MBEDTLS_NO_64BIT_MULTIPLICATION)
+      30                 :            : static uint64_t mul64(uint32_t a, uint32_t b)
+      31                 :            : {
+      32                 :            :     /* a = al + 2**16 ah, b = bl + 2**16 bh */
+      33                 :            :     const uint16_t al = (uint16_t) a;
+      34                 :            :     const uint16_t bl = (uint16_t) b;
+      35                 :            :     const uint16_t ah = a >> 16;
+      36                 :            :     const uint16_t bh = b >> 16;
+      37                 :            : 
+      38                 :            :     /* ab = al*bl + 2**16 (ah*bl + bl*bh) + 2**32 ah*bh */
+      39                 :            :     const uint32_t lo = (uint32_t) al * bl;
+      40                 :            :     const uint64_t me = (uint64_t) ((uint32_t) ah * bl) + (uint32_t) al * bh;
+      41                 :            :     const uint32_t hi = (uint32_t) ah * bh;
+      42                 :            : 
+      43                 :            :     return lo + (me << 16) + ((uint64_t) hi << 32);
+      44                 :            : }
+      45                 :            : #else
+      46                 :          0 : static inline uint64_t mul64(uint32_t a, uint32_t b)
+      47                 :            : {
+      48                 :          0 :     return (uint64_t) a * b;
+      49                 :            : }
+      50                 :            : #endif
+      51                 :            : 
+      52                 :            : 
+      53                 :            : /**
+      54                 :            :  * \brief                   Process blocks with Poly1305.
+      55                 :            :  *
+      56                 :            :  * \param ctx               The Poly1305 context.
+      57                 :            :  * \param nblocks           Number of blocks to process. Note that this
+      58                 :            :  *                          function only processes full blocks.
+      59                 :            :  * \param input             Buffer containing the input block(s).
+      60                 :            :  * \param needs_padding     Set to 0 if the padding bit has already been
+      61                 :            :  *                          applied to the input data before calling this
+      62                 :            :  *                          function.  Otherwise, set this parameter to 1.
+      63                 :            :  */
+      64                 :          0 : static void poly1305_process(mbedtls_poly1305_context *ctx,
+      65                 :            :                              size_t nblocks,
+      66                 :            :                              const unsigned char *input,
+      67                 :            :                              uint32_t needs_padding)
+      68                 :            : {
+      69                 :            :     uint64_t d0, d1, d2, d3;
+      70                 :            :     uint32_t acc0, acc1, acc2, acc3, acc4;
+      71                 :            :     uint32_t r0, r1, r2, r3;
+      72                 :            :     uint32_t rs1, rs2, rs3;
+      73                 :          0 :     size_t offset  = 0U;
+      74                 :            :     size_t i;
+      75                 :            : 
+      76                 :          0 :     r0 = ctx->r[0];
+      77                 :          0 :     r1 = ctx->r[1];
+      78                 :          0 :     r2 = ctx->r[2];
+      79                 :          0 :     r3 = ctx->r[3];
+      80                 :            : 
+      81                 :          0 :     rs1 = r1 + (r1 >> 2U);
+      82                 :          0 :     rs2 = r2 + (r2 >> 2U);
+      83                 :          0 :     rs3 = r3 + (r3 >> 2U);
+      84                 :            : 
+      85                 :          0 :     acc0 = ctx->acc[0];
+      86                 :          0 :     acc1 = ctx->acc[1];
+      87                 :          0 :     acc2 = ctx->acc[2];
+      88                 :          0 :     acc3 = ctx->acc[3];
+      89                 :          0 :     acc4 = ctx->acc[4];
+      90                 :            : 
+      91                 :            :     /* Process full blocks */
+      92         [ #  # ]:          0 :     for (i = 0U; i < nblocks; i++) {
+      93                 :            :         /* The input block is treated as a 128-bit little-endian integer */
+      94                 :          0 :         d0   = MBEDTLS_GET_UINT32_LE(input, offset + 0);
+      95                 :          0 :         d1   = MBEDTLS_GET_UINT32_LE(input, offset + 4);
+      96                 :          0 :         d2   = MBEDTLS_GET_UINT32_LE(input, offset + 8);
+      97                 :          0 :         d3   = MBEDTLS_GET_UINT32_LE(input, offset + 12);
+      98                 :            : 
+      99                 :            :         /* Compute: acc += (padded) block as a 130-bit integer */
+     100                 :          0 :         d0  += (uint64_t) acc0;
+     101                 :          0 :         d1  += (uint64_t) acc1 + (d0 >> 32U);
+     102                 :          0 :         d2  += (uint64_t) acc2 + (d1 >> 32U);
+     103                 :          0 :         d3  += (uint64_t) acc3 + (d2 >> 32U);
+     104                 :          0 :         acc0 = (uint32_t) d0;
+     105                 :          0 :         acc1 = (uint32_t) d1;
+     106                 :          0 :         acc2 = (uint32_t) d2;
+     107                 :          0 :         acc3 = (uint32_t) d3;
+     108                 :          0 :         acc4 += (uint32_t) (d3 >> 32U) + needs_padding;
+     109                 :            : 
+     110                 :            :         /* Compute: acc *= r */
+     111                 :          0 :         d0 = mul64(acc0, r0) +
+     112                 :          0 :              mul64(acc1, rs3) +
+     113                 :          0 :              mul64(acc2, rs2) +
+     114                 :          0 :              mul64(acc3, rs1);
+     115                 :          0 :         d1 = mul64(acc0, r1) +
+     116                 :          0 :              mul64(acc1, r0) +
+     117                 :          0 :              mul64(acc2, rs3) +
+     118                 :          0 :              mul64(acc3, rs2) +
+     119                 :          0 :              mul64(acc4, rs1);
+     120                 :          0 :         d2 = mul64(acc0, r2) +
+     121                 :          0 :              mul64(acc1, r1) +
+     122                 :          0 :              mul64(acc2, r0) +
+     123                 :          0 :              mul64(acc3, rs3) +
+     124                 :          0 :              mul64(acc4, rs2);
+     125                 :          0 :         d3 = mul64(acc0, r3) +
+     126                 :          0 :              mul64(acc1, r2) +
+     127                 :          0 :              mul64(acc2, r1) +
+     128                 :          0 :              mul64(acc3, r0) +
+     129                 :          0 :              mul64(acc4, rs3);
+     130                 :          0 :         acc4 *= r0;
+     131                 :            : 
+     132                 :            :         /* Compute: acc %= (2^130 - 5) (partial remainder) */
+     133                 :          0 :         d1 += (d0 >> 32);
+     134                 :          0 :         d2 += (d1 >> 32);
+     135                 :          0 :         d3 += (d2 >> 32);
+     136                 :          0 :         acc0 = (uint32_t) d0;
+     137                 :          0 :         acc1 = (uint32_t) d1;
+     138                 :          0 :         acc2 = (uint32_t) d2;
+     139                 :          0 :         acc3 = (uint32_t) d3;
+     140                 :          0 :         acc4 = (uint32_t) (d3 >> 32) + acc4;
+     141                 :            : 
+     142                 :          0 :         d0 = (uint64_t) acc0 + (acc4 >> 2) + (acc4 & 0xFFFFFFFCU);
+     143                 :          0 :         acc4 &= 3U;
+     144                 :          0 :         acc0 = (uint32_t) d0;
+     145                 :          0 :         d0 = (uint64_t) acc1 + (d0 >> 32U);
+     146                 :          0 :         acc1 = (uint32_t) d0;
+     147                 :          0 :         d0 = (uint64_t) acc2 + (d0 >> 32U);
+     148                 :          0 :         acc2 = (uint32_t) d0;
+     149                 :          0 :         d0 = (uint64_t) acc3 + (d0 >> 32U);
+     150                 :          0 :         acc3 = (uint32_t) d0;
+     151                 :          0 :         d0 = (uint64_t) acc4 + (d0 >> 32U);
+     152                 :          0 :         acc4 = (uint32_t) d0;
+     153                 :            : 
+     154                 :          0 :         offset    += POLY1305_BLOCK_SIZE_BYTES;
+     155                 :            :     }
+     156                 :            : 
+     157                 :          0 :     ctx->acc[0] = acc0;
+     158                 :          0 :     ctx->acc[1] = acc1;
+     159                 :          0 :     ctx->acc[2] = acc2;
+     160                 :          0 :     ctx->acc[3] = acc3;
+     161                 :          0 :     ctx->acc[4] = acc4;
+     162                 :          0 : }
+     163                 :            : 
+     164                 :            : /**
+     165                 :            :  * \brief                   Compute the Poly1305 MAC
+     166                 :            :  *
+     167                 :            :  * \param ctx               The Poly1305 context.
+     168                 :            :  * \param mac               The buffer to where the MAC is written. Must be
+     169                 :            :  *                          big enough to contain the 16-byte MAC.
+     170                 :            :  */
+     171                 :          0 : static void poly1305_compute_mac(const mbedtls_poly1305_context *ctx,
+     172                 :            :                                  unsigned char mac[16])
+     173                 :            : {
+     174                 :            :     uint64_t d;
+     175                 :            :     uint32_t g0, g1, g2, g3, g4;
+     176                 :            :     uint32_t acc0, acc1, acc2, acc3, acc4;
+     177                 :            :     uint32_t mask;
+     178                 :            :     uint32_t mask_inv;
+     179                 :            : 
+     180                 :          0 :     acc0 = ctx->acc[0];
+     181                 :          0 :     acc1 = ctx->acc[1];
+     182                 :          0 :     acc2 = ctx->acc[2];
+     183                 :          0 :     acc3 = ctx->acc[3];
+     184                 :          0 :     acc4 = ctx->acc[4];
+     185                 :            : 
+     186                 :            :     /* Before adding 's' we ensure that the accumulator is mod 2^130 - 5.
+     187                 :            :      * We do this by calculating acc - (2^130 - 5), then checking if
+     188                 :            :      * the 131st bit is set. If it is, then reduce: acc -= (2^130 - 5)
+     189                 :            :      */
+     190                 :            : 
+     191                 :            :     /* Calculate acc + -(2^130 - 5) */
+     192                 :          0 :     d  = ((uint64_t) acc0 + 5U);
+     193                 :          0 :     g0 = (uint32_t) d;
+     194                 :          0 :     d  = ((uint64_t) acc1 + (d >> 32));
+     195                 :          0 :     g1 = (uint32_t) d;
+     196                 :          0 :     d  = ((uint64_t) acc2 + (d >> 32));
+     197                 :          0 :     g2 = (uint32_t) d;
+     198                 :          0 :     d  = ((uint64_t) acc3 + (d >> 32));
+     199                 :          0 :     g3 = (uint32_t) d;
+     200                 :          0 :     g4 = acc4 + (uint32_t) (d >> 32U);
+     201                 :            : 
+     202                 :            :     /* mask == 0xFFFFFFFF if 131st bit is set, otherwise mask == 0 */
+     203                 :          0 :     mask = (uint32_t) 0U - (g4 >> 2U);
+     204                 :          0 :     mask_inv = ~mask;
+     205                 :            : 
+     206                 :            :     /* If 131st bit is set then acc=g, otherwise, acc is unmodified */
+     207                 :          0 :     acc0 = (acc0 & mask_inv) | (g0 & mask);
+     208                 :          0 :     acc1 = (acc1 & mask_inv) | (g1 & mask);
+     209                 :          0 :     acc2 = (acc2 & mask_inv) | (g2 & mask);
+     210                 :          0 :     acc3 = (acc3 & mask_inv) | (g3 & mask);
+     211                 :            : 
+     212                 :            :     /* Add 's' */
+     213                 :          0 :     d = (uint64_t) acc0 + ctx->s[0];
+     214                 :          0 :     acc0 = (uint32_t) d;
+     215                 :          0 :     d = (uint64_t) acc1 + ctx->s[1] + (d >> 32U);
+     216                 :          0 :     acc1 = (uint32_t) d;
+     217                 :          0 :     d = (uint64_t) acc2 + ctx->s[2] + (d >> 32U);
+     218                 :          0 :     acc2 = (uint32_t) d;
+     219                 :          0 :     acc3 += ctx->s[3] + (uint32_t) (d >> 32U);
+     220                 :            : 
+     221                 :            :     /* Compute MAC (128 least significant bits of the accumulator) */
+     222                 :          0 :     MBEDTLS_PUT_UINT32_LE(acc0, mac,  0);
+     223                 :          0 :     MBEDTLS_PUT_UINT32_LE(acc1, mac,  4);
+     224                 :          0 :     MBEDTLS_PUT_UINT32_LE(acc2, mac,  8);
+     225                 :          0 :     MBEDTLS_PUT_UINT32_LE(acc3, mac, 12);
+     226                 :          0 : }
+     227                 :            : 
+     228                 :          0 : void mbedtls_poly1305_init(mbedtls_poly1305_context *ctx)
+     229                 :            : {
+     230                 :          0 :     mbedtls_platform_zeroize(ctx, sizeof(mbedtls_poly1305_context));
+     231                 :          0 : }
+     232                 :            : 
+     233                 :          0 : void mbedtls_poly1305_free(mbedtls_poly1305_context *ctx)
+     234                 :            : {
+     235         [ #  # ]:          0 :     if (ctx == NULL) {
+     236                 :          0 :         return;
+     237                 :            :     }
+     238                 :            : 
+     239                 :          0 :     mbedtls_platform_zeroize(ctx, sizeof(mbedtls_poly1305_context));
+     240                 :            : }
+     241                 :            : 
+     242                 :          0 : int mbedtls_poly1305_starts(mbedtls_poly1305_context *ctx,
+     243                 :            :                             const unsigned char key[32])
+     244                 :            : {
+     245                 :            :     /* r &= 0x0ffffffc0ffffffc0ffffffc0fffffff */
+     246                 :          0 :     ctx->r[0] = MBEDTLS_GET_UINT32_LE(key, 0)  & 0x0FFFFFFFU;
+     247                 :          0 :     ctx->r[1] = MBEDTLS_GET_UINT32_LE(key, 4)  & 0x0FFFFFFCU;
+     248                 :          0 :     ctx->r[2] = MBEDTLS_GET_UINT32_LE(key, 8)  & 0x0FFFFFFCU;
+     249                 :          0 :     ctx->r[3] = MBEDTLS_GET_UINT32_LE(key, 12) & 0x0FFFFFFCU;
+     250                 :            : 
+     251                 :          0 :     ctx->s[0] = MBEDTLS_GET_UINT32_LE(key, 16);
+     252                 :          0 :     ctx->s[1] = MBEDTLS_GET_UINT32_LE(key, 20);
+     253                 :          0 :     ctx->s[2] = MBEDTLS_GET_UINT32_LE(key, 24);
+     254                 :          0 :     ctx->s[3] = MBEDTLS_GET_UINT32_LE(key, 28);
+     255                 :            : 
+     256                 :            :     /* Initial accumulator state */
+     257                 :          0 :     ctx->acc[0] = 0U;
+     258                 :          0 :     ctx->acc[1] = 0U;
+     259                 :          0 :     ctx->acc[2] = 0U;
+     260                 :          0 :     ctx->acc[3] = 0U;
+     261                 :          0 :     ctx->acc[4] = 0U;
+     262                 :            : 
+     263                 :            :     /* Queue initially empty */
+     264                 :          0 :     mbedtls_platform_zeroize(ctx->queue, sizeof(ctx->queue));
+     265                 :          0 :     ctx->queue_len = 0U;
+     266                 :            : 
+     267                 :          0 :     return 0;
+     268                 :            : }
+     269                 :            : 
+     270                 :          0 : int mbedtls_poly1305_update(mbedtls_poly1305_context *ctx,
+     271                 :            :                             const unsigned char *input,
+     272                 :            :                             size_t ilen)
+     273                 :            : {
+     274                 :          0 :     size_t offset    = 0U;
+     275                 :          0 :     size_t remaining = ilen;
+     276                 :            :     size_t queue_free_len;
+     277                 :            :     size_t nblocks;
+     278                 :            : 
+     279   [ #  #  #  # ]:          0 :     if ((remaining > 0U) && (ctx->queue_len > 0U)) {
+     280                 :          0 :         queue_free_len = (POLY1305_BLOCK_SIZE_BYTES - ctx->queue_len);
+     281                 :            : 
+     282         [ #  # ]:          0 :         if (ilen < queue_free_len) {
+     283                 :            :             /* Not enough data to complete the block.
+     284                 :            :              * Store this data with the other leftovers.
+     285                 :            :              */
+     286                 :          0 :             memcpy(&ctx->queue[ctx->queue_len],
+     287                 :            :                    input,
+     288                 :            :                    ilen);
+     289                 :            : 
+     290                 :          0 :             ctx->queue_len += ilen;
+     291                 :            : 
+     292                 :          0 :             remaining = 0U;
+     293                 :            :         } else {
+     294                 :            :             /* Enough data to produce a complete block */
+     295                 :          0 :             memcpy(&ctx->queue[ctx->queue_len],
+     296                 :            :                    input,
+     297                 :            :                    queue_free_len);
+     298                 :            : 
+     299                 :          0 :             ctx->queue_len = 0U;
+     300                 :            : 
+     301                 :          0 :             poly1305_process(ctx, 1U, ctx->queue, 1U);   /* add padding bit */
+     302                 :            : 
+     303                 :          0 :             offset    += queue_free_len;
+     304                 :          0 :             remaining -= queue_free_len;
+     305                 :            :         }
+     306                 :            :     }
+     307                 :            : 
+     308         [ #  # ]:          0 :     if (remaining >= POLY1305_BLOCK_SIZE_BYTES) {
+     309                 :          0 :         nblocks = remaining / POLY1305_BLOCK_SIZE_BYTES;
+     310                 :            : 
+     311                 :          0 :         poly1305_process(ctx, nblocks, &input[offset], 1U);
+     312                 :            : 
+     313                 :          0 :         offset += nblocks * POLY1305_BLOCK_SIZE_BYTES;
+     314                 :          0 :         remaining %= POLY1305_BLOCK_SIZE_BYTES;
+     315                 :            :     }
+     316                 :            : 
+     317         [ #  # ]:          0 :     if (remaining > 0U) {
+     318                 :            :         /* Store partial block */
+     319                 :          0 :         ctx->queue_len = remaining;
+     320                 :          0 :         memcpy(ctx->queue, &input[offset], remaining);
+     321                 :            :     }
+     322                 :            : 
+     323                 :          0 :     return 0;
+     324                 :            : }
+     325                 :            : 
+     326                 :          0 : int mbedtls_poly1305_finish(mbedtls_poly1305_context *ctx,
+     327                 :            :                             unsigned char mac[16])
+     328                 :            : {
+     329                 :            :     /* Process any leftover data */
+     330         [ #  # ]:          0 :     if (ctx->queue_len > 0U) {
+     331                 :            :         /* Add padding bit */
+     332                 :          0 :         ctx->queue[ctx->queue_len] = 1U;
+     333                 :          0 :         ctx->queue_len++;
+     334                 :            : 
+     335                 :            :         /* Pad with zeroes */
+     336                 :          0 :         memset(&ctx->queue[ctx->queue_len],
+     337                 :            :                0,
+     338                 :          0 :                POLY1305_BLOCK_SIZE_BYTES - ctx->queue_len);
+     339                 :            : 
+     340                 :          0 :         poly1305_process(ctx, 1U,           /* Process 1 block */
+     341                 :          0 :                          ctx->queue, 0U);   /* Already padded above */
+     342                 :            :     }
+     343                 :            : 
+     344                 :          0 :     poly1305_compute_mac(ctx, mac);
+     345                 :            : 
+     346                 :          0 :     return 0;
+     347                 :            : }
+     348                 :            : 
+     349                 :          0 : int mbedtls_poly1305_mac(const unsigned char key[32],
+     350                 :            :                          const unsigned char *input,
+     351                 :            :                          size_t ilen,
+     352                 :            :                          unsigned char mac[16])
+     353                 :            : {
+     354                 :            :     mbedtls_poly1305_context ctx;
+     355                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     356                 :            : 
+     357                 :          0 :     mbedtls_poly1305_init(&ctx);
+     358                 :            : 
+     359                 :          0 :     ret = mbedtls_poly1305_starts(&ctx, key);
+     360         [ #  # ]:          0 :     if (ret != 0) {
+     361                 :          0 :         goto cleanup;
+     362                 :            :     }
+     363                 :            : 
+     364                 :          0 :     ret = mbedtls_poly1305_update(&ctx, input, ilen);
+     365         [ #  # ]:          0 :     if (ret != 0) {
+     366                 :          0 :         goto cleanup;
+     367                 :            :     }
+     368                 :            : 
+     369                 :          0 :     ret = mbedtls_poly1305_finish(&ctx, mac);
+     370                 :            : 
+     371                 :          0 : cleanup:
+     372                 :          0 :     mbedtls_poly1305_free(&ctx);
+     373                 :          0 :     return ret;
+     374                 :            : }
+     375                 :            : 
+     376                 :            : #endif /* MBEDTLS_POLY1305_ALT */
+     377                 :            : 
+     378                 :            : #if defined(MBEDTLS_SELF_TEST)
+     379                 :            : 
+     380                 :            : static const unsigned char test_keys[2][32] =
+     381                 :            : {
+     382                 :            :     {
+     383                 :            :         0x85, 0xd6, 0xbe, 0x78, 0x57, 0x55, 0x6d, 0x33,
+     384                 :            :         0x7f, 0x44, 0x52, 0xfe, 0x42, 0xd5, 0x06, 0xa8,
+     385                 :            :         0x01, 0x03, 0x80, 0x8a, 0xfb, 0x0d, 0xb2, 0xfd,
+     386                 :            :         0x4a, 0xbf, 0xf6, 0xaf, 0x41, 0x49, 0xf5, 0x1b
+     387                 :            :     },
+     388                 :            :     {
+     389                 :            :         0x1c, 0x92, 0x40, 0xa5, 0xeb, 0x55, 0xd3, 0x8a,
+     390                 :            :         0xf3, 0x33, 0x88, 0x86, 0x04, 0xf6, 0xb5, 0xf0,
+     391                 :            :         0x47, 0x39, 0x17, 0xc1, 0x40, 0x2b, 0x80, 0x09,
+     392                 :            :         0x9d, 0xca, 0x5c, 0xbc, 0x20, 0x70, 0x75, 0xc0
+     393                 :            :     }
+     394                 :            : };
+     395                 :            : 
+     396                 :            : static const unsigned char test_data[2][127] =
+     397                 :            : {
+     398                 :            :     {
+     399                 :            :         0x43, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x67, 0x72,
+     400                 :            :         0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x46, 0x6f,
+     401                 :            :         0x72, 0x75, 0x6d, 0x20, 0x52, 0x65, 0x73, 0x65,
+     402                 :            :         0x61, 0x72, 0x63, 0x68, 0x20, 0x47, 0x72, 0x6f,
+     403                 :            :         0x75, 0x70
+     404                 :            :     },
+     405                 :            :     {
+     406                 :            :         0x27, 0x54, 0x77, 0x61, 0x73, 0x20, 0x62, 0x72,
+     407                 :            :         0x69, 0x6c, 0x6c, 0x69, 0x67, 0x2c, 0x20, 0x61,
+     408                 :            :         0x6e, 0x64, 0x20, 0x74, 0x68, 0x65, 0x20, 0x73,
+     409                 :            :         0x6c, 0x69, 0x74, 0x68, 0x79, 0x20, 0x74, 0x6f,
+     410                 :            :         0x76, 0x65, 0x73, 0x0a, 0x44, 0x69, 0x64, 0x20,
+     411                 :            :         0x67, 0x79, 0x72, 0x65, 0x20, 0x61, 0x6e, 0x64,
+     412                 :            :         0x20, 0x67, 0x69, 0x6d, 0x62, 0x6c, 0x65, 0x20,
+     413                 :            :         0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x77,
+     414                 :            :         0x61, 0x62, 0x65, 0x3a, 0x0a, 0x41, 0x6c, 0x6c,
+     415                 :            :         0x20, 0x6d, 0x69, 0x6d, 0x73, 0x79, 0x20, 0x77,
+     416                 :            :         0x65, 0x72, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20,
+     417                 :            :         0x62, 0x6f, 0x72, 0x6f, 0x67, 0x6f, 0x76, 0x65,
+     418                 :            :         0x73, 0x2c, 0x0a, 0x41, 0x6e, 0x64, 0x20, 0x74,
+     419                 :            :         0x68, 0x65, 0x20, 0x6d, 0x6f, 0x6d, 0x65, 0x20,
+     420                 :            :         0x72, 0x61, 0x74, 0x68, 0x73, 0x20, 0x6f, 0x75,
+     421                 :            :         0x74, 0x67, 0x72, 0x61, 0x62, 0x65, 0x2e
+     422                 :            :     }
+     423                 :            : };
+     424                 :            : 
+     425                 :            : static const size_t test_data_len[2] =
+     426                 :            : {
+     427                 :            :     34U,
+     428                 :            :     127U
+     429                 :            : };
+     430                 :            : 
+     431                 :            : static const unsigned char test_mac[2][16] =
+     432                 :            : {
+     433                 :            :     {
+     434                 :            :         0xa8, 0x06, 0x1d, 0xc1, 0x30, 0x51, 0x36, 0xc6,
+     435                 :            :         0xc2, 0x2b, 0x8b, 0xaf, 0x0c, 0x01, 0x27, 0xa9
+     436                 :            :     },
+     437                 :            :     {
+     438                 :            :         0x45, 0x41, 0x66, 0x9a, 0x7e, 0xaa, 0xee, 0x61,
+     439                 :            :         0xe7, 0x08, 0xdc, 0x7c, 0xbc, 0xc5, 0xeb, 0x62
+     440                 :            :     }
+     441                 :            : };
+     442                 :            : 
+     443                 :            : /* Make sure no other definition is already present. */
+     444                 :            : #undef ASSERT
+     445                 :            : 
+     446                 :            : #define ASSERT(cond, args)            \
+     447                 :            :     do                                  \
+     448                 :            :     {                                   \
+     449                 :            :         if (!(cond))                \
+     450                 :            :         {                               \
+     451                 :            :             if (verbose != 0)          \
+     452                 :            :             mbedtls_printf args;    \
+     453                 :            :                                         \
+     454                 :            :             return -1;               \
+     455                 :            :         }                               \
+     456                 :            :     }                                   \
+     457                 :            :     while (0)
+     458                 :            : 
+     459                 :          0 : int mbedtls_poly1305_self_test(int verbose)
+     460                 :            : {
+     461                 :            :     unsigned char mac[16];
+     462                 :            :     unsigned i;
+     463                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     464                 :            : 
+     465         [ #  # ]:          0 :     for (i = 0U; i < 2U; i++) {
+     466         [ #  # ]:          0 :         if (verbose != 0) {
+     467                 :          0 :             mbedtls_printf("  Poly1305 test %u ", i);
+     468                 :            :         }
+     469                 :            : 
+     470                 :          0 :         ret = mbedtls_poly1305_mac(test_keys[i],
+     471                 :          0 :                                    test_data[i],
+     472                 :          0 :                                    test_data_len[i],
+     473                 :            :                                    mac);
+     474   [ #  #  #  # ]:          0 :         ASSERT(0 == ret, ("error code: %i\n", ret));
+     475                 :            : 
+     476   [ #  #  #  # ]:          0 :         ASSERT(0 == memcmp(mac, test_mac[i], 16U), ("failed (mac)\n"));
+     477                 :            : 
+     478         [ #  # ]:          0 :         if (verbose != 0) {
+     479                 :          0 :             mbedtls_printf("passed\n");
+     480                 :            :         }
+     481                 :            :     }
+     482                 :            : 
+     483         [ #  # ]:          0 :     if (verbose != 0) {
+     484                 :          0 :         mbedtls_printf("\n");
+     485                 :            :     }
+     486                 :            : 
+     487                 :          0 :     return 0;
+     488                 :            : }
+     489                 :            : 
+     490                 :            : #endif /* MBEDTLS_SELF_TEST */
+     491                 :            : 
+     492                 :            : #endif /* MBEDTLS_POLY1305_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/ripemd160.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ripemd160.c.func-sort-c.html new file mode 100644 index 00000000000..cd1fdf37680 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ripemd160.c.func-sort-c.html @@ -0,0 +1,117 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/ripemd160.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - ripemd160.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:02120.0 %
Date:2024-09-22 08:21:07Functions:090.0 %
Branches:0440.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_internal_ripemd160_process0
mbedtls_ripemd1600
mbedtls_ripemd160_clone0
mbedtls_ripemd160_finish0
mbedtls_ripemd160_free0
mbedtls_ripemd160_init0
mbedtls_ripemd160_self_test0
mbedtls_ripemd160_starts0
mbedtls_ripemd160_update0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/ripemd160.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ripemd160.c.func.html new file mode 100644 index 00000000000..a7ed53d1203 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ripemd160.c.func.html @@ -0,0 +1,117 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/ripemd160.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - ripemd160.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:02120.0 %
Date:2024-09-22 08:21:07Functions:090.0 %
Branches:0440.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_internal_ripemd160_process0
mbedtls_ripemd1600
mbedtls_ripemd160_clone0
mbedtls_ripemd160_finish0
mbedtls_ripemd160_free0
mbedtls_ripemd160_init0
mbedtls_ripemd160_self_test0
mbedtls_ripemd160_starts0
mbedtls_ripemd160_update0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/ripemd160.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ripemd160.c.gcov.html new file mode 100644 index 00000000000..c06f0098d86 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/ripemd160.c.gcov.html @@ -0,0 +1,575 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/ripemd160.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - ripemd160.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:02120.0 %
Date:2024-09-22 08:21:07Functions:090.0 %
Branches:0440.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  *  RIPE MD-160 implementation
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  */
+       7                 :            : 
+       8                 :            : /*
+       9                 :            :  *  The RIPEMD-160 algorithm was designed by RIPE in 1996
+      10                 :            :  *  http://homes.esat.kuleuven.be/~bosselae/mbedtls_ripemd160.html
+      11                 :            :  *  http://ehash.iaik.tugraz.at/wiki/RIPEMD-160
+      12                 :            :  */
+      13                 :            : 
+      14                 :            : #include "common.h"
+      15                 :            : 
+      16                 :            : #if defined(MBEDTLS_RIPEMD160_C)
+      17                 :            : 
+      18                 :            : #include "mbedtls/ripemd160.h"
+      19                 :            : #include "mbedtls/platform_util.h"
+      20                 :            : #include "mbedtls/error.h"
+      21                 :            : 
+      22                 :            : #include <string.h>
+      23                 :            : 
+      24                 :            : #include "mbedtls/platform.h"
+      25                 :            : 
+      26                 :            : #if !defined(MBEDTLS_RIPEMD160_ALT)
+      27                 :            : 
+      28                 :          0 : void mbedtls_ripemd160_init(mbedtls_ripemd160_context *ctx)
+      29                 :            : {
+      30                 :          0 :     memset(ctx, 0, sizeof(mbedtls_ripemd160_context));
+      31                 :          0 : }
+      32                 :            : 
+      33                 :          0 : void mbedtls_ripemd160_free(mbedtls_ripemd160_context *ctx)
+      34                 :            : {
+      35         [ #  # ]:          0 :     if (ctx == NULL) {
+      36                 :          0 :         return;
+      37                 :            :     }
+      38                 :            : 
+      39                 :          0 :     mbedtls_platform_zeroize(ctx, sizeof(mbedtls_ripemd160_context));
+      40                 :            : }
+      41                 :            : 
+      42                 :          0 : void mbedtls_ripemd160_clone(mbedtls_ripemd160_context *dst,
+      43                 :            :                              const mbedtls_ripemd160_context *src)
+      44                 :            : {
+      45                 :          0 :     *dst = *src;
+      46                 :          0 : }
+      47                 :            : 
+      48                 :            : /*
+      49                 :            :  * RIPEMD-160 context setup
+      50                 :            :  */
+      51                 :          0 : int mbedtls_ripemd160_starts(mbedtls_ripemd160_context *ctx)
+      52                 :            : {
+      53                 :          0 :     ctx->total[0] = 0;
+      54                 :          0 :     ctx->total[1] = 0;
+      55                 :            : 
+      56                 :          0 :     ctx->state[0] = 0x67452301;
+      57                 :          0 :     ctx->state[1] = 0xEFCDAB89;
+      58                 :          0 :     ctx->state[2] = 0x98BADCFE;
+      59                 :          0 :     ctx->state[3] = 0x10325476;
+      60                 :          0 :     ctx->state[4] = 0xC3D2E1F0;
+      61                 :            : 
+      62                 :          0 :     return 0;
+      63                 :            : }
+      64                 :            : 
+      65                 :            : #if !defined(MBEDTLS_RIPEMD160_PROCESS_ALT)
+      66                 :            : /*
+      67                 :            :  * Process one block
+      68                 :            :  */
+      69                 :          0 : int mbedtls_internal_ripemd160_process(mbedtls_ripemd160_context *ctx,
+      70                 :            :                                        const unsigned char data[64])
+      71                 :            : {
+      72                 :            :     struct {
+      73                 :            :         uint32_t A, B, C, D, E, Ap, Bp, Cp, Dp, Ep, X[16];
+      74                 :            :     } local;
+      75                 :            : 
+      76                 :          0 :     local.X[0] = MBEDTLS_GET_UINT32_LE(data,  0);
+      77                 :          0 :     local.X[1] = MBEDTLS_GET_UINT32_LE(data,  4);
+      78                 :          0 :     local.X[2] = MBEDTLS_GET_UINT32_LE(data,  8);
+      79                 :          0 :     local.X[3] = MBEDTLS_GET_UINT32_LE(data, 12);
+      80                 :          0 :     local.X[4] = MBEDTLS_GET_UINT32_LE(data, 16);
+      81                 :          0 :     local.X[5] = MBEDTLS_GET_UINT32_LE(data, 20);
+      82                 :          0 :     local.X[6] = MBEDTLS_GET_UINT32_LE(data, 24);
+      83                 :          0 :     local.X[7] = MBEDTLS_GET_UINT32_LE(data, 28);
+      84                 :          0 :     local.X[8] = MBEDTLS_GET_UINT32_LE(data, 32);
+      85                 :          0 :     local.X[9] = MBEDTLS_GET_UINT32_LE(data, 36);
+      86                 :          0 :     local.X[10] = MBEDTLS_GET_UINT32_LE(data, 40);
+      87                 :          0 :     local.X[11] = MBEDTLS_GET_UINT32_LE(data, 44);
+      88                 :          0 :     local.X[12] = MBEDTLS_GET_UINT32_LE(data, 48);
+      89                 :          0 :     local.X[13] = MBEDTLS_GET_UINT32_LE(data, 52);
+      90                 :          0 :     local.X[14] = MBEDTLS_GET_UINT32_LE(data, 56);
+      91                 :          0 :     local.X[15] = MBEDTLS_GET_UINT32_LE(data, 60);
+      92                 :            : 
+      93                 :          0 :     local.A = local.Ap = ctx->state[0];
+      94                 :          0 :     local.B = local.Bp = ctx->state[1];
+      95                 :          0 :     local.C = local.Cp = ctx->state[2];
+      96                 :          0 :     local.D = local.Dp = ctx->state[3];
+      97                 :          0 :     local.E = local.Ep = ctx->state[4];
+      98                 :            : 
+      99                 :            : #define F1(x, y, z)   ((x) ^ (y) ^ (z))
+     100                 :            : #define F2(x, y, z)   (((x) & (y)) | (~(x) & (z)))
+     101                 :            : #define F3(x, y, z)   (((x) | ~(y)) ^ (z))
+     102                 :            : #define F4(x, y, z)   (((x) & (z)) | ((y) & ~(z)))
+     103                 :            : #define F5(x, y, z)   ((x) ^ ((y) | ~(z)))
+     104                 :            : 
+     105                 :            : #define S(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
+     106                 :            : 
+     107                 :            : #define P(a, b, c, d, e, r, s, f, k)                      \
+     108                 :            :     do                                                      \
+     109                 :            :     {                                                       \
+     110                 :            :         (a) += f((b), (c), (d)) + local.X[r] + (k);       \
+     111                 :            :         (a) = S((a), (s)) + (e);                          \
+     112                 :            :         (c) = S((c), 10);                                 \
+     113                 :            :     } while (0)
+     114                 :            : 
+     115                 :            : #define P2(a, b, c, d, e, r, s, rp, sp)                               \
+     116                 :            :     do                                                                  \
+     117                 :            :     {                                                                   \
+     118                 :            :         P((a), (b), (c), (d), (e), (r), (s), F, K);                   \
+     119                 :            :         P(a ## p, b ## p, c ## p, d ## p, e ## p,                      \
+     120                 :            :           (rp), (sp), Fp, Kp);                                        \
+     121                 :            :     } while (0)
+     122                 :            : 
+     123                 :            : #define F   F1
+     124                 :            : #define K   0x00000000
+     125                 :            : #define Fp  F5
+     126                 :            : #define Kp  0x50A28BE6
+     127                 :          0 :     P2(local.A, local.B, local.C, local.D, local.E,  0, 11,  5,  8);
+     128                 :          0 :     P2(local.E, local.A, local.B, local.C, local.D,  1, 14, 14,  9);
+     129                 :          0 :     P2(local.D, local.E, local.A, local.B, local.C,  2, 15,  7,  9);
+     130                 :          0 :     P2(local.C, local.D, local.E, local.A, local.B,  3, 12,  0, 11);
+     131                 :          0 :     P2(local.B, local.C, local.D, local.E, local.A,  4,  5,  9, 13);
+     132                 :          0 :     P2(local.A, local.B, local.C, local.D, local.E,  5,  8,  2, 15);
+     133                 :          0 :     P2(local.E, local.A, local.B, local.C, local.D,  6,  7, 11, 15);
+     134                 :          0 :     P2(local.D, local.E, local.A, local.B, local.C,  7,  9,  4,  5);
+     135                 :          0 :     P2(local.C, local.D, local.E, local.A, local.B,  8, 11, 13,  7);
+     136                 :          0 :     P2(local.B, local.C, local.D, local.E, local.A,  9, 13,  6,  7);
+     137                 :          0 :     P2(local.A, local.B, local.C, local.D, local.E, 10, 14, 15,  8);
+     138                 :          0 :     P2(local.E, local.A, local.B, local.C, local.D, 11, 15,  8, 11);
+     139                 :          0 :     P2(local.D, local.E, local.A, local.B, local.C, 12,  6,  1, 14);
+     140                 :          0 :     P2(local.C, local.D, local.E, local.A, local.B, 13,  7, 10, 14);
+     141                 :          0 :     P2(local.B, local.C, local.D, local.E, local.A, 14,  9,  3, 12);
+     142                 :          0 :     P2(local.A, local.B, local.C, local.D, local.E, 15,  8, 12,  6);
+     143                 :            : #undef F
+     144                 :            : #undef K
+     145                 :            : #undef Fp
+     146                 :            : #undef Kp
+     147                 :            : 
+     148                 :            : #define F   F2
+     149                 :            : #define K   0x5A827999
+     150                 :            : #define Fp  F4
+     151                 :            : #define Kp  0x5C4DD124
+     152                 :          0 :     P2(local.E, local.A, local.B, local.C, local.D,  7,  7,  6,  9);
+     153                 :          0 :     P2(local.D, local.E, local.A, local.B, local.C,  4,  6, 11, 13);
+     154                 :          0 :     P2(local.C, local.D, local.E, local.A, local.B, 13,  8,  3, 15);
+     155                 :          0 :     P2(local.B, local.C, local.D, local.E, local.A,  1, 13,  7,  7);
+     156                 :          0 :     P2(local.A, local.B, local.C, local.D, local.E, 10, 11,  0, 12);
+     157                 :          0 :     P2(local.E, local.A, local.B, local.C, local.D,  6,  9, 13,  8);
+     158                 :          0 :     P2(local.D, local.E, local.A, local.B, local.C, 15,  7,  5,  9);
+     159                 :          0 :     P2(local.C, local.D, local.E, local.A, local.B,  3, 15, 10, 11);
+     160                 :          0 :     P2(local.B, local.C, local.D, local.E, local.A, 12,  7, 14,  7);
+     161                 :          0 :     P2(local.A, local.B, local.C, local.D, local.E,  0, 12, 15,  7);
+     162                 :          0 :     P2(local.E, local.A, local.B, local.C, local.D,  9, 15,  8, 12);
+     163                 :          0 :     P2(local.D, local.E, local.A, local.B, local.C,  5,  9, 12,  7);
+     164                 :          0 :     P2(local.C, local.D, local.E, local.A, local.B,  2, 11,  4,  6);
+     165                 :          0 :     P2(local.B, local.C, local.D, local.E, local.A, 14,  7,  9, 15);
+     166                 :          0 :     P2(local.A, local.B, local.C, local.D, local.E, 11, 13,  1, 13);
+     167                 :          0 :     P2(local.E, local.A, local.B, local.C, local.D,  8, 12,  2, 11);
+     168                 :            : #undef F
+     169                 :            : #undef K
+     170                 :            : #undef Fp
+     171                 :            : #undef Kp
+     172                 :            : 
+     173                 :            : #define F   F3
+     174                 :            : #define K   0x6ED9EBA1
+     175                 :            : #define Fp  F3
+     176                 :            : #define Kp  0x6D703EF3
+     177                 :          0 :     P2(local.D, local.E, local.A, local.B, local.C,  3, 11, 15,  9);
+     178                 :          0 :     P2(local.C, local.D, local.E, local.A, local.B, 10, 13,  5,  7);
+     179                 :          0 :     P2(local.B, local.C, local.D, local.E, local.A, 14,  6,  1, 15);
+     180                 :          0 :     P2(local.A, local.B, local.C, local.D, local.E,  4,  7,  3, 11);
+     181                 :          0 :     P2(local.E, local.A, local.B, local.C, local.D,  9, 14,  7,  8);
+     182                 :          0 :     P2(local.D, local.E, local.A, local.B, local.C, 15,  9, 14,  6);
+     183                 :          0 :     P2(local.C, local.D, local.E, local.A, local.B,  8, 13,  6,  6);
+     184                 :          0 :     P2(local.B, local.C, local.D, local.E, local.A,  1, 15,  9, 14);
+     185                 :          0 :     P2(local.A, local.B, local.C, local.D, local.E,  2, 14, 11, 12);
+     186                 :          0 :     P2(local.E, local.A, local.B, local.C, local.D,  7,  8,  8, 13);
+     187                 :          0 :     P2(local.D, local.E, local.A, local.B, local.C,  0, 13, 12,  5);
+     188                 :          0 :     P2(local.C, local.D, local.E, local.A, local.B,  6,  6,  2, 14);
+     189                 :          0 :     P2(local.B, local.C, local.D, local.E, local.A, 13,  5, 10, 13);
+     190                 :          0 :     P2(local.A, local.B, local.C, local.D, local.E, 11, 12,  0, 13);
+     191                 :          0 :     P2(local.E, local.A, local.B, local.C, local.D,  5,  7,  4,  7);
+     192                 :          0 :     P2(local.D, local.E, local.A, local.B, local.C, 12,  5, 13,  5);
+     193                 :            : #undef F
+     194                 :            : #undef K
+     195                 :            : #undef Fp
+     196                 :            : #undef Kp
+     197                 :            : 
+     198                 :            : #define F   F4
+     199                 :            : #define K   0x8F1BBCDC
+     200                 :            : #define Fp  F2
+     201                 :            : #define Kp  0x7A6D76E9
+     202                 :          0 :     P2(local.C, local.D, local.E, local.A, local.B,  1, 11,  8, 15);
+     203                 :          0 :     P2(local.B, local.C, local.D, local.E, local.A,  9, 12,  6,  5);
+     204                 :          0 :     P2(local.A, local.B, local.C, local.D, local.E, 11, 14,  4,  8);
+     205                 :          0 :     P2(local.E, local.A, local.B, local.C, local.D, 10, 15,  1, 11);
+     206                 :          0 :     P2(local.D, local.E, local.A, local.B, local.C,  0, 14,  3, 14);
+     207                 :          0 :     P2(local.C, local.D, local.E, local.A, local.B,  8, 15, 11, 14);
+     208                 :          0 :     P2(local.B, local.C, local.D, local.E, local.A, 12,  9, 15,  6);
+     209                 :          0 :     P2(local.A, local.B, local.C, local.D, local.E,  4,  8,  0, 14);
+     210                 :          0 :     P2(local.E, local.A, local.B, local.C, local.D, 13,  9,  5,  6);
+     211                 :          0 :     P2(local.D, local.E, local.A, local.B, local.C,  3, 14, 12,  9);
+     212                 :          0 :     P2(local.C, local.D, local.E, local.A, local.B,  7,  5,  2, 12);
+     213                 :          0 :     P2(local.B, local.C, local.D, local.E, local.A, 15,  6, 13,  9);
+     214                 :          0 :     P2(local.A, local.B, local.C, local.D, local.E, 14,  8,  9, 12);
+     215                 :          0 :     P2(local.E, local.A, local.B, local.C, local.D,  5,  6,  7,  5);
+     216                 :          0 :     P2(local.D, local.E, local.A, local.B, local.C,  6,  5, 10, 15);
+     217                 :          0 :     P2(local.C, local.D, local.E, local.A, local.B,  2, 12, 14,  8);
+     218                 :            : #undef F
+     219                 :            : #undef K
+     220                 :            : #undef Fp
+     221                 :            : #undef Kp
+     222                 :            : 
+     223                 :            : #define F   F5
+     224                 :            : #define K   0xA953FD4E
+     225                 :            : #define Fp  F1
+     226                 :            : #define Kp  0x00000000
+     227                 :          0 :     P2(local.B, local.C, local.D, local.E, local.A,  4,  9, 12,  8);
+     228                 :          0 :     P2(local.A, local.B, local.C, local.D, local.E,  0, 15, 15,  5);
+     229                 :          0 :     P2(local.E, local.A, local.B, local.C, local.D,  5,  5, 10, 12);
+     230                 :          0 :     P2(local.D, local.E, local.A, local.B, local.C,  9, 11,  4,  9);
+     231                 :          0 :     P2(local.C, local.D, local.E, local.A, local.B,  7,  6,  1, 12);
+     232                 :          0 :     P2(local.B, local.C, local.D, local.E, local.A, 12,  8,  5,  5);
+     233                 :          0 :     P2(local.A, local.B, local.C, local.D, local.E,  2, 13,  8, 14);
+     234                 :          0 :     P2(local.E, local.A, local.B, local.C, local.D, 10, 12,  7,  6);
+     235                 :          0 :     P2(local.D, local.E, local.A, local.B, local.C, 14,  5,  6,  8);
+     236                 :          0 :     P2(local.C, local.D, local.E, local.A, local.B,  1, 12,  2, 13);
+     237                 :          0 :     P2(local.B, local.C, local.D, local.E, local.A,  3, 13, 13,  6);
+     238                 :          0 :     P2(local.A, local.B, local.C, local.D, local.E,  8, 14, 14,  5);
+     239                 :          0 :     P2(local.E, local.A, local.B, local.C, local.D, 11, 11,  0, 15);
+     240                 :          0 :     P2(local.D, local.E, local.A, local.B, local.C,  6,  8,  3, 13);
+     241                 :          0 :     P2(local.C, local.D, local.E, local.A, local.B, 15,  5,  9, 11);
+     242                 :          0 :     P2(local.B, local.C, local.D, local.E, local.A, 13,  6, 11, 11);
+     243                 :            : #undef F
+     244                 :            : #undef K
+     245                 :            : #undef Fp
+     246                 :            : #undef Kp
+     247                 :            : 
+     248                 :          0 :     local.C       = ctx->state[1] + local.C + local.Dp;
+     249                 :          0 :     ctx->state[1] = ctx->state[2] + local.D + local.Ep;
+     250                 :          0 :     ctx->state[2] = ctx->state[3] + local.E + local.Ap;
+     251                 :          0 :     ctx->state[3] = ctx->state[4] + local.A + local.Bp;
+     252                 :          0 :     ctx->state[4] = ctx->state[0] + local.B + local.Cp;
+     253                 :          0 :     ctx->state[0] = local.C;
+     254                 :            : 
+     255                 :            :     /* Zeroise variables to clear sensitive data from memory. */
+     256                 :          0 :     mbedtls_platform_zeroize(&local, sizeof(local));
+     257                 :            : 
+     258                 :          0 :     return 0;
+     259                 :            : }
+     260                 :            : 
+     261                 :            : #endif /* !MBEDTLS_RIPEMD160_PROCESS_ALT */
+     262                 :            : 
+     263                 :            : /*
+     264                 :            :  * RIPEMD-160 process buffer
+     265                 :            :  */
+     266                 :          0 : int mbedtls_ripemd160_update(mbedtls_ripemd160_context *ctx,
+     267                 :            :                              const unsigned char *input,
+     268                 :            :                              size_t ilen)
+     269                 :            : {
+     270                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     271                 :            :     size_t fill;
+     272                 :            :     uint32_t left;
+     273                 :            : 
+     274         [ #  # ]:          0 :     if (ilen == 0) {
+     275                 :          0 :         return 0;
+     276                 :            :     }
+     277                 :            : 
+     278                 :          0 :     left = ctx->total[0] & 0x3F;
+     279                 :          0 :     fill = 64 - left;
+     280                 :            : 
+     281                 :          0 :     ctx->total[0] += (uint32_t) ilen;
+     282                 :          0 :     ctx->total[0] &= 0xFFFFFFFF;
+     283                 :            : 
+     284         [ #  # ]:          0 :     if (ctx->total[0] < (uint32_t) ilen) {
+     285                 :          0 :         ctx->total[1]++;
+     286                 :            :     }
+     287                 :            : 
+     288   [ #  #  #  # ]:          0 :     if (left && ilen >= fill) {
+     289                 :          0 :         memcpy((void *) (ctx->buffer + left), input, fill);
+     290                 :            : 
+     291         [ #  # ]:          0 :         if ((ret = mbedtls_internal_ripemd160_process(ctx, ctx->buffer)) != 0) {
+     292                 :          0 :             return ret;
+     293                 :            :         }
+     294                 :            : 
+     295                 :          0 :         input += fill;
+     296                 :          0 :         ilen  -= fill;
+     297                 :          0 :         left = 0;
+     298                 :            :     }
+     299                 :            : 
+     300         [ #  # ]:          0 :     while (ilen >= 64) {
+     301         [ #  # ]:          0 :         if ((ret = mbedtls_internal_ripemd160_process(ctx, input)) != 0) {
+     302                 :          0 :             return ret;
+     303                 :            :         }
+     304                 :            : 
+     305                 :          0 :         input += 64;
+     306                 :          0 :         ilen  -= 64;
+     307                 :            :     }
+     308                 :            : 
+     309         [ #  # ]:          0 :     if (ilen > 0) {
+     310                 :          0 :         memcpy((void *) (ctx->buffer + left), input, ilen);
+     311                 :            :     }
+     312                 :            : 
+     313                 :          0 :     return 0;
+     314                 :            : }
+     315                 :            : 
+     316                 :            : static const unsigned char ripemd160_padding[64] =
+     317                 :            : {
+     318                 :            :     0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+     319                 :            :     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+     320                 :            :     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+     321                 :            :     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+     322                 :            : };
+     323                 :            : 
+     324                 :            : /*
+     325                 :            :  * RIPEMD-160 final digest
+     326                 :            :  */
+     327                 :          0 : int mbedtls_ripemd160_finish(mbedtls_ripemd160_context *ctx,
+     328                 :            :                              unsigned char output[20])
+     329                 :            : {
+     330                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     331                 :            :     uint32_t last, padn;
+     332                 :            :     uint32_t high, low;
+     333                 :            :     unsigned char msglen[8];
+     334                 :            : 
+     335                 :          0 :     high = (ctx->total[0] >> 29)
+     336                 :          0 :            | (ctx->total[1] <<  3);
+     337                 :          0 :     low  = (ctx->total[0] <<  3);
+     338                 :            : 
+     339                 :          0 :     MBEDTLS_PUT_UINT32_LE(low,  msglen, 0);
+     340                 :          0 :     MBEDTLS_PUT_UINT32_LE(high, msglen, 4);
+     341                 :            : 
+     342                 :          0 :     last = ctx->total[0] & 0x3F;
+     343         [ #  # ]:          0 :     padn = (last < 56) ? (56 - last) : (120 - last);
+     344                 :            : 
+     345                 :          0 :     ret = mbedtls_ripemd160_update(ctx, ripemd160_padding, padn);
+     346         [ #  # ]:          0 :     if (ret != 0) {
+     347                 :          0 :         goto exit;
+     348                 :            :     }
+     349                 :            : 
+     350                 :          0 :     ret = mbedtls_ripemd160_update(ctx, msglen, 8);
+     351         [ #  # ]:          0 :     if (ret != 0) {
+     352                 :          0 :         goto exit;
+     353                 :            :     }
+     354                 :            : 
+     355                 :          0 :     MBEDTLS_PUT_UINT32_LE(ctx->state[0], output,  0);
+     356                 :          0 :     MBEDTLS_PUT_UINT32_LE(ctx->state[1], output,  4);
+     357                 :          0 :     MBEDTLS_PUT_UINT32_LE(ctx->state[2], output,  8);
+     358                 :          0 :     MBEDTLS_PUT_UINT32_LE(ctx->state[3], output, 12);
+     359                 :          0 :     MBEDTLS_PUT_UINT32_LE(ctx->state[4], output, 16);
+     360                 :            : 
+     361                 :          0 :     ret = 0;
+     362                 :            : 
+     363                 :          0 : exit:
+     364                 :          0 :     mbedtls_ripemd160_free(ctx);
+     365                 :          0 :     return ret;
+     366                 :            : }
+     367                 :            : 
+     368                 :            : #endif /* ! MBEDTLS_RIPEMD160_ALT */
+     369                 :            : 
+     370                 :            : /*
+     371                 :            :  * output = RIPEMD-160( input buffer )
+     372                 :            :  */
+     373                 :          0 : int mbedtls_ripemd160(const unsigned char *input,
+     374                 :            :                       size_t ilen,
+     375                 :            :                       unsigned char output[20])
+     376                 :            : {
+     377                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     378                 :            :     mbedtls_ripemd160_context ctx;
+     379                 :            : 
+     380                 :          0 :     mbedtls_ripemd160_init(&ctx);
+     381                 :            : 
+     382         [ #  # ]:          0 :     if ((ret = mbedtls_ripemd160_starts(&ctx)) != 0) {
+     383                 :          0 :         goto exit;
+     384                 :            :     }
+     385                 :            : 
+     386         [ #  # ]:          0 :     if ((ret = mbedtls_ripemd160_update(&ctx, input, ilen)) != 0) {
+     387                 :          0 :         goto exit;
+     388                 :            :     }
+     389                 :            : 
+     390         [ #  # ]:          0 :     if ((ret = mbedtls_ripemd160_finish(&ctx, output)) != 0) {
+     391                 :          0 :         goto exit;
+     392                 :            :     }
+     393                 :            : 
+     394                 :          0 : exit:
+     395                 :          0 :     mbedtls_ripemd160_free(&ctx);
+     396                 :            : 
+     397                 :          0 :     return ret;
+     398                 :            : }
+     399                 :            : 
+     400                 :            : #if defined(MBEDTLS_SELF_TEST)
+     401                 :            : /*
+     402                 :            :  * Test vectors from the RIPEMD-160 paper and
+     403                 :            :  * http://homes.esat.kuleuven.be/~bosselae/mbedtls_ripemd160.html#HMAC
+     404                 :            :  */
+     405                 :            : #define TESTS   8
+     406                 :            : static const unsigned char ripemd160_test_str[TESTS][81] =
+     407                 :            : {
+     408                 :            :     { "" },
+     409                 :            :     { "a" },
+     410                 :            :     { "abc" },
+     411                 :            :     { "message digest" },
+     412                 :            :     { "abcdefghijklmnopqrstuvwxyz" },
+     413                 :            :     { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" },
+     414                 :            :     { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" },
+     415                 :            :     { "12345678901234567890123456789012345678901234567890123456789012345678901234567890" },
+     416                 :            : };
+     417                 :            : 
+     418                 :            : static const size_t ripemd160_test_strlen[TESTS] =
+     419                 :            : {
+     420                 :            :     0, 1, 3, 14, 26, 56, 62, 80
+     421                 :            : };
+     422                 :            : 
+     423                 :            : static const unsigned char ripemd160_test_md[TESTS][20] =
+     424                 :            : {
+     425                 :            :     { 0x9c, 0x11, 0x85, 0xa5, 0xc5, 0xe9, 0xfc, 0x54, 0x61, 0x28,
+     426                 :            :       0x08, 0x97, 0x7e, 0xe8, 0xf5, 0x48, 0xb2, 0x25, 0x8d, 0x31 },
+     427                 :            :     { 0x0b, 0xdc, 0x9d, 0x2d, 0x25, 0x6b, 0x3e, 0xe9, 0xda, 0xae,
+     428                 :            :       0x34, 0x7b, 0xe6, 0xf4, 0xdc, 0x83, 0x5a, 0x46, 0x7f, 0xfe },
+     429                 :            :     { 0x8e, 0xb2, 0x08, 0xf7, 0xe0, 0x5d, 0x98, 0x7a, 0x9b, 0x04,
+     430                 :            :       0x4a, 0x8e, 0x98, 0xc6, 0xb0, 0x87, 0xf1, 0x5a, 0x0b, 0xfc },
+     431                 :            :     { 0x5d, 0x06, 0x89, 0xef, 0x49, 0xd2, 0xfa, 0xe5, 0x72, 0xb8,
+     432                 :            :       0x81, 0xb1, 0x23, 0xa8, 0x5f, 0xfa, 0x21, 0x59, 0x5f, 0x36 },
+     433                 :            :     { 0xf7, 0x1c, 0x27, 0x10, 0x9c, 0x69, 0x2c, 0x1b, 0x56, 0xbb,
+     434                 :            :       0xdc, 0xeb, 0x5b, 0x9d, 0x28, 0x65, 0xb3, 0x70, 0x8d, 0xbc },
+     435                 :            :     { 0x12, 0xa0, 0x53, 0x38, 0x4a, 0x9c, 0x0c, 0x88, 0xe4, 0x05,
+     436                 :            :       0xa0, 0x6c, 0x27, 0xdc, 0xf4, 0x9a, 0xda, 0x62, 0xeb, 0x2b },
+     437                 :            :     { 0xb0, 0xe2, 0x0b, 0x6e, 0x31, 0x16, 0x64, 0x02, 0x86, 0xed,
+     438                 :            :       0x3a, 0x87, 0xa5, 0x71, 0x30, 0x79, 0xb2, 0x1f, 0x51, 0x89 },
+     439                 :            :     { 0x9b, 0x75, 0x2e, 0x45, 0x57, 0x3d, 0x4b, 0x39, 0xf4, 0xdb,
+     440                 :            :       0xd3, 0x32, 0x3c, 0xab, 0x82, 0xbf, 0x63, 0x32, 0x6b, 0xfb },
+     441                 :            : };
+     442                 :            : 
+     443                 :            : /*
+     444                 :            :  * Checkup routine
+     445                 :            :  */
+     446                 :          0 : int mbedtls_ripemd160_self_test(int verbose)
+     447                 :            : {
+     448                 :          0 :     int i, ret = 0;
+     449                 :            :     unsigned char output[20];
+     450                 :            : 
+     451                 :          0 :     memset(output, 0, sizeof(output));
+     452                 :            : 
+     453         [ #  # ]:          0 :     for (i = 0; i < TESTS; i++) {
+     454         [ #  # ]:          0 :         if (verbose != 0) {
+     455                 :          0 :             mbedtls_printf("  RIPEMD-160 test #%d: ", i + 1);
+     456                 :            :         }
+     457                 :            : 
+     458                 :          0 :         ret = mbedtls_ripemd160(ripemd160_test_str[i],
+     459                 :          0 :                                 ripemd160_test_strlen[i], output);
+     460         [ #  # ]:          0 :         if (ret != 0) {
+     461                 :          0 :             goto fail;
+     462                 :            :         }
+     463                 :            : 
+     464         [ #  # ]:          0 :         if (memcmp(output, ripemd160_test_md[i], 20) != 0) {
+     465                 :          0 :             ret = 1;
+     466                 :          0 :             goto fail;
+     467                 :            :         }
+     468                 :            : 
+     469         [ #  # ]:          0 :         if (verbose != 0) {
+     470                 :          0 :             mbedtls_printf("passed\n");
+     471                 :            :         }
+     472                 :            :     }
+     473                 :            : 
+     474         [ #  # ]:          0 :     if (verbose != 0) {
+     475                 :          0 :         mbedtls_printf("\n");
+     476                 :            :     }
+     477                 :            : 
+     478                 :          0 :     return 0;
+     479                 :            : 
+     480                 :          0 : fail:
+     481         [ #  # ]:          0 :     if (verbose != 0) {
+     482                 :          0 :         mbedtls_printf("failed\n");
+     483                 :            :     }
+     484                 :            : 
+     485                 :          0 :     return ret;
+     486                 :            : }
+     487                 :            : 
+     488                 :            : #endif /* MBEDTLS_SELF_TEST */
+     489                 :            : 
+     490                 :            : #endif /* MBEDTLS_RIPEMD160_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/rsa.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/rsa.c.func-sort-c.html new file mode 100644 index 00000000000..1a73744ea79 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/rsa.c.func-sort-c.html @@ -0,0 +1,289 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/rsa.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - rsa.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:485108244.8 %
Date:2024-09-22 08:21:07Functions:295255.8 %
Branches:29496530.5 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
compute_hash0
mbedtls_ct_rsaes_pkcs1_v15_unpadding0
mbedtls_rsa_check_privkey0
mbedtls_rsa_check_pub_priv0
mbedtls_rsa_export0
mbedtls_rsa_export_crt0
mbedtls_rsa_export_raw0
mbedtls_rsa_gen_key0
mbedtls_rsa_get_md_alg0
mbedtls_rsa_get_padding_mode0
mbedtls_rsa_pkcs1_decrypt0
mbedtls_rsa_pkcs1_encrypt0
mbedtls_rsa_rsaes_oaep_decrypt0
mbedtls_rsa_rsaes_oaep_encrypt0
mbedtls_rsa_rsaes_pkcs1_v15_decrypt0
mbedtls_rsa_rsaes_pkcs1_v15_encrypt0
mbedtls_rsa_rsassa_pss_sign0
mbedtls_rsa_rsassa_pss_sign_no_mode_check0
mbedtls_rsa_rsassa_pss_verify0
mbedtls_rsa_self_test0
mbedtls_rsa_write_key0
mbedtls_rsa_write_pubkey0
myrand0
mbedtls_rsa_rsassa_pss_sign_ext1
mbedtls_rsa_rsassa_pss_verify_ext1
rsa_rsassa_pss_sign1
rsa_rsassa_pss_sign_no_mode_check1
hash_mprime2
mgf_mask2
mbedtls_rsa_parse_key25
mbedtls_rsa_pkcs1_sign26
mbedtls_rsa_rsassa_pkcs1_v15_sign26
mbedtls_rsa_private27
rsa_prepare_blinding27
rsa_unblind27
mbedtls_rsa_set_padding50
mbedtls_rsa_copy89
mbedtls_rsa_import131
asn1_get_nonzero_mpi200
mbedtls_rsa_pkcs1_verify275
mbedtls_rsa_rsassa_pkcs1_v15_verify275
rsa_rsassa_pkcs1_v15_encode301
mbedtls_rsa_public302
mbedtls_rsa_get_len329
mbedtls_rsa_get_bitlen540
mbedtls_rsa_parse_pubkey1102
mbedtls_rsa_check_pubkey1122
mbedtls_rsa_complete1172
mbedtls_rsa_free1205
mbedtls_rsa_init1218
mbedtls_rsa_import_raw2194
rsa_check_context2623
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/rsa.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/rsa.c.func.html new file mode 100644 index 00000000000..84aa79865e4 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/rsa.c.func.html @@ -0,0 +1,289 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/rsa.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - rsa.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:485108244.8 %
Date:2024-09-22 08:21:07Functions:295255.8 %
Branches:29496530.5 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
asn1_get_nonzero_mpi200
compute_hash0
hash_mprime2
mbedtls_ct_rsaes_pkcs1_v15_unpadding0
mbedtls_rsa_check_privkey0
mbedtls_rsa_check_pub_priv0
mbedtls_rsa_check_pubkey1122
mbedtls_rsa_complete1172
mbedtls_rsa_copy89
mbedtls_rsa_export0
mbedtls_rsa_export_crt0
mbedtls_rsa_export_raw0
mbedtls_rsa_free1205
mbedtls_rsa_gen_key0
mbedtls_rsa_get_bitlen540
mbedtls_rsa_get_len329
mbedtls_rsa_get_md_alg0
mbedtls_rsa_get_padding_mode0
mbedtls_rsa_import131
mbedtls_rsa_import_raw2194
mbedtls_rsa_init1218
mbedtls_rsa_parse_key25
mbedtls_rsa_parse_pubkey1102
mbedtls_rsa_pkcs1_decrypt0
mbedtls_rsa_pkcs1_encrypt0
mbedtls_rsa_pkcs1_sign26
mbedtls_rsa_pkcs1_verify275
mbedtls_rsa_private27
mbedtls_rsa_public302
mbedtls_rsa_rsaes_oaep_decrypt0
mbedtls_rsa_rsaes_oaep_encrypt0
mbedtls_rsa_rsaes_pkcs1_v15_decrypt0
mbedtls_rsa_rsaes_pkcs1_v15_encrypt0
mbedtls_rsa_rsassa_pkcs1_v15_sign26
mbedtls_rsa_rsassa_pkcs1_v15_verify275
mbedtls_rsa_rsassa_pss_sign0
mbedtls_rsa_rsassa_pss_sign_ext1
mbedtls_rsa_rsassa_pss_sign_no_mode_check0
mbedtls_rsa_rsassa_pss_verify0
mbedtls_rsa_rsassa_pss_verify_ext1
mbedtls_rsa_self_test0
mbedtls_rsa_set_padding50
mbedtls_rsa_write_key0
mbedtls_rsa_write_pubkey0
mgf_mask2
myrand0
rsa_check_context2623
rsa_prepare_blinding27
rsa_rsassa_pkcs1_v15_encode301
rsa_rsassa_pss_sign1
rsa_rsassa_pss_sign_no_mode_check1
rsa_unblind27
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/rsa.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/rsa.c.gcov.html new file mode 100644 index 00000000000..8b07e678412 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/rsa.c.gcov.html @@ -0,0 +1,3172 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/rsa.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - rsa.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:485108244.8 %
Date:2024-09-22 08:21:07Functions:295255.8 %
Branches:29496530.5 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  *  The RSA public-key cryptosystem
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  */
+       7                 :            : 
+       8                 :            : /*
+       9                 :            :  *  The following sources were referenced in the design of this implementation
+      10                 :            :  *  of the RSA algorithm:
+      11                 :            :  *
+      12                 :            :  *  [1] A method for obtaining digital signatures and public-key cryptosystems
+      13                 :            :  *      R Rivest, A Shamir, and L Adleman
+      14                 :            :  *      http://people.csail.mit.edu/rivest/pubs.html#RSA78
+      15                 :            :  *
+      16                 :            :  *  [2] Handbook of Applied Cryptography - 1997, Chapter 8
+      17                 :            :  *      Menezes, van Oorschot and Vanstone
+      18                 :            :  *
+      19                 :            :  *  [3] Malware Guard Extension: Using SGX to Conceal Cache Attacks
+      20                 :            :  *      Michael Schwarz, Samuel Weiser, Daniel Gruss, Clémentine Maurice and
+      21                 :            :  *      Stefan Mangard
+      22                 :            :  *      https://arxiv.org/abs/1702.08719v2
+      23                 :            :  *
+      24                 :            :  */
+      25                 :            : 
+      26                 :            : #include "common.h"
+      27                 :            : 
+      28                 :            : #if defined(MBEDTLS_RSA_C)
+      29                 :            : 
+      30                 :            : #include "mbedtls/rsa.h"
+      31                 :            : #include "bignum_core.h"
+      32                 :            : #include "rsa_alt_helpers.h"
+      33                 :            : #include "rsa_internal.h"
+      34                 :            : #include "mbedtls/oid.h"
+      35                 :            : #include "mbedtls/asn1write.h"
+      36                 :            : #include "mbedtls/platform_util.h"
+      37                 :            : #include "mbedtls/error.h"
+      38                 :            : #include "constant_time_internal.h"
+      39                 :            : #include "mbedtls/constant_time.h"
+      40                 :            : #include "md_psa.h"
+      41                 :            : 
+      42                 :            : #include <string.h>
+      43                 :            : 
+      44                 :            : #if defined(MBEDTLS_PKCS1_V15) && !defined(__OpenBSD__) && !defined(__NetBSD__)
+      45                 :            : #include <stdlib.h>
+      46                 :            : #endif
+      47                 :            : 
+      48                 :            : #include "mbedtls/platform.h"
+      49                 :            : 
+      50                 :            : /*
+      51                 :            :  * Wrapper around mbedtls_asn1_get_mpi() that rejects zero.
+      52                 :            :  *
+      53                 :            :  * The value zero is:
+      54                 :            :  * - never a valid value for an RSA parameter
+      55                 :            :  * - interpreted as "omitted, please reconstruct" by mbedtls_rsa_complete().
+      56                 :            :  *
+      57                 :            :  * Since values can't be omitted in PKCS#1, passing a zero value to
+      58                 :            :  * rsa_complete() would be incorrect, so reject zero values early.
+      59                 :            :  */
+      60                 :        200 : static int asn1_get_nonzero_mpi(unsigned char **p,
+      61                 :            :                                 const unsigned char *end,
+      62                 :            :                                 mbedtls_mpi *X)
+      63                 :            : {
+      64                 :            :     int ret;
+      65                 :            : 
+      66                 :        200 :     ret = mbedtls_asn1_get_mpi(p, end, X);
+      67         [ -  + ]:        200 :     if (ret != 0) {
+      68                 :          0 :         return ret;
+      69                 :            :     }
+      70                 :            : 
+      71         [ -  + ]:        200 :     if (mbedtls_mpi_cmp_int(X, 0) == 0) {
+      72                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+      73                 :            :     }
+      74                 :            : 
+      75                 :        200 :     return 0;
+      76                 :            : }
+      77                 :            : 
+      78                 :         25 : int mbedtls_rsa_parse_key(mbedtls_rsa_context *rsa, const unsigned char *key, size_t keylen)
+      79                 :            : {
+      80                 :            :     int ret, version;
+      81                 :            :     size_t len;
+      82                 :            :     unsigned char *p, *end;
+      83                 :            : 
+      84                 :            :     mbedtls_mpi T;
+      85                 :         25 :     mbedtls_mpi_init(&T);
+      86                 :            : 
+      87                 :         25 :     p = (unsigned char *) key;
+      88                 :         25 :     end = p + keylen;
+      89                 :            : 
+      90                 :            :     /*
+      91                 :            :      * This function parses the RSAPrivateKey (PKCS#1)
+      92                 :            :      *
+      93                 :            :      *  RSAPrivateKey ::= SEQUENCE {
+      94                 :            :      *      version           Version,
+      95                 :            :      *      modulus           INTEGER,  -- n
+      96                 :            :      *      publicExponent    INTEGER,  -- e
+      97                 :            :      *      privateExponent   INTEGER,  -- d
+      98                 :            :      *      prime1            INTEGER,  -- p
+      99                 :            :      *      prime2            INTEGER,  -- q
+     100                 :            :      *      exponent1         INTEGER,  -- d mod (p-1)
+     101                 :            :      *      exponent2         INTEGER,  -- d mod (q-1)
+     102                 :            :      *      coefficient       INTEGER,  -- (inverse of q) mod p
+     103                 :            :      *      otherPrimeInfos   OtherPrimeInfos OPTIONAL
+     104                 :            :      *  }
+     105                 :            :      */
+     106         [ -  + ]:         25 :     if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
+     107                 :            :                                     MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
+     108                 :          0 :         return ret;
+     109                 :            :     }
+     110                 :            : 
+     111         [ -  + ]:         25 :     if (end != p + len) {
+     112                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+     113                 :            :     }
+     114                 :            : 
+     115         [ -  + ]:         25 :     if ((ret = mbedtls_asn1_get_int(&p, end, &version)) != 0) {
+     116                 :          0 :         return ret;
+     117                 :            :     }
+     118                 :            : 
+     119         [ -  + ]:         25 :     if (version != 0) {
+     120                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+     121                 :            :     }
+     122                 :            : 
+     123                 :            :     /* Import N */
+     124   [ +  -  -  + ]:         50 :     if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 ||
+     125                 :         25 :         (ret = mbedtls_rsa_import(rsa, &T, NULL, NULL,
+     126                 :            :                                   NULL, NULL)) != 0) {
+     127                 :          0 :         goto cleanup;
+     128                 :            :     }
+     129                 :            : 
+     130                 :            :     /* Import E */
+     131   [ +  -  -  + ]:         50 :     if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 ||
+     132                 :         25 :         (ret = mbedtls_rsa_import(rsa, NULL, NULL, NULL,
+     133                 :            :                                   NULL, &T)) != 0) {
+     134                 :          0 :         goto cleanup;
+     135                 :            :     }
+     136                 :            : 
+     137                 :            :     /* Import D */
+     138   [ +  -  -  + ]:         50 :     if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 ||
+     139                 :         25 :         (ret = mbedtls_rsa_import(rsa, NULL, NULL, NULL,
+     140                 :            :                                   &T, NULL)) != 0) {
+     141                 :          0 :         goto cleanup;
+     142                 :            :     }
+     143                 :            : 
+     144                 :            :     /* Import P */
+     145   [ +  -  -  + ]:         50 :     if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 ||
+     146                 :         25 :         (ret = mbedtls_rsa_import(rsa, NULL, &T, NULL,
+     147                 :            :                                   NULL, NULL)) != 0) {
+     148                 :          0 :         goto cleanup;
+     149                 :            :     }
+     150                 :            : 
+     151                 :            :     /* Import Q */
+     152   [ +  -  -  + ]:         50 :     if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 ||
+     153                 :         25 :         (ret = mbedtls_rsa_import(rsa, NULL, NULL, &T,
+     154                 :            :                                   NULL, NULL)) != 0) {
+     155                 :          0 :         goto cleanup;
+     156                 :            :     }
+     157                 :            : 
+     158                 :            : #if !defined(MBEDTLS_RSA_NO_CRT) && !defined(MBEDTLS_RSA_ALT)
+     159                 :            :     /*
+     160                 :            :      * The RSA CRT parameters DP, DQ and QP are nominally redundant, in
+     161                 :            :      * that they can be easily recomputed from D, P and Q. However by
+     162                 :            :      * parsing them from the PKCS1 structure it is possible to avoid
+     163                 :            :      * recalculating them which both reduces the overhead of loading
+     164                 :            :      * RSA private keys into memory and also avoids side channels which
+     165                 :            :      * can arise when computing those values, since all of D, P, and Q
+     166                 :            :      * are secret. See https://eprint.iacr.org/2020/055 for a
+     167                 :            :      * description of one such attack.
+     168                 :            :      */
+     169                 :            : 
+     170                 :            :     /* Import DP */
+     171   [ +  -  -  + ]:         50 :     if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 ||
+     172                 :         25 :         (ret = mbedtls_mpi_copy(&rsa->DP, &T)) != 0) {
+     173                 :          0 :         goto cleanup;
+     174                 :            :     }
+     175                 :            : 
+     176                 :            :     /* Import DQ */
+     177   [ +  -  -  + ]:         50 :     if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 ||
+     178                 :         25 :         (ret = mbedtls_mpi_copy(&rsa->DQ, &T)) != 0) {
+     179                 :          0 :         goto cleanup;
+     180                 :            :     }
+     181                 :            : 
+     182                 :            :     /* Import QP */
+     183   [ +  -  -  + ]:         50 :     if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 ||
+     184                 :         25 :         (ret = mbedtls_mpi_copy(&rsa->QP, &T)) != 0) {
+     185                 :          0 :         goto cleanup;
+     186                 :            :     }
+     187                 :            : 
+     188                 :            : #else
+     189                 :            :     /* Verify existence of the CRT params */
+     190                 :            :     if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 ||
+     191                 :            :         (ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 ||
+     192                 :            :         (ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0) {
+     193                 :            :         goto cleanup;
+     194                 :            :     }
+     195                 :            : #endif
+     196                 :            : 
+     197                 :            :     /* rsa_complete() doesn't complete anything with the default
+     198                 :            :      * implementation but is still called:
+     199                 :            :      * - for the benefit of alternative implementation that may want to
+     200                 :            :      *   pre-compute stuff beyond what's provided (eg Montgomery factors)
+     201                 :            :      * - as is also sanity-checks the key
+     202                 :            :      *
+     203                 :            :      * Furthermore, we also check the public part for consistency with
+     204                 :            :      * mbedtls_pk_parse_pubkey(), as it includes size minima for example.
+     205                 :            :      */
+     206   [ +  -  -  + ]:         50 :     if ((ret = mbedtls_rsa_complete(rsa)) != 0 ||
+     207                 :         25 :         (ret = mbedtls_rsa_check_pubkey(rsa)) != 0) {
+     208                 :          0 :         goto cleanup;
+     209                 :            :     }
+     210                 :            : 
+     211         [ +  - ]:         25 :     if (p != end) {
+     212                 :          0 :         ret = MBEDTLS_ERR_ASN1_LENGTH_MISMATCH;
+     213                 :            :     }
+     214                 :            : 
+     215                 :         25 : cleanup:
+     216                 :            : 
+     217                 :         25 :     mbedtls_mpi_free(&T);
+     218                 :            : 
+     219         [ -  + ]:         25 :     if (ret != 0) {
+     220                 :          0 :         mbedtls_rsa_free(rsa);
+     221                 :            :     }
+     222                 :            : 
+     223                 :         25 :     return ret;
+     224                 :            : }
+     225                 :            : 
+     226                 :       1102 : int mbedtls_rsa_parse_pubkey(mbedtls_rsa_context *rsa, const unsigned char *key, size_t keylen)
+     227                 :            : {
+     228                 :       1102 :     unsigned char *p = (unsigned char *) key;
+     229                 :       1102 :     unsigned char *end = (unsigned char *) (key + keylen);
+     230                 :       1102 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     231                 :            :     size_t len;
+     232                 :            : 
+     233                 :            :     /*
+     234                 :            :      *  RSAPublicKey ::= SEQUENCE {
+     235                 :            :      *      modulus           INTEGER,  -- n
+     236                 :            :      *      publicExponent    INTEGER   -- e
+     237                 :            :      *  }
+     238                 :            :      */
+     239                 :            : 
+     240         [ -  + ]:       1102 :     if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
+     241                 :            :                                     MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
+     242                 :          0 :         return ret;
+     243                 :            :     }
+     244                 :            : 
+     245         [ -  + ]:       1102 :     if (end != p + len) {
+     246                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+     247                 :            :     }
+     248                 :            : 
+     249                 :            :     /* Import N */
+     250         [ +  + ]:       1102 :     if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_INTEGER)) != 0) {
+     251                 :          5 :         return ret;
+     252                 :            :     }
+     253                 :            : 
+     254         [ -  + ]:       1097 :     if ((ret = mbedtls_rsa_import_raw(rsa, p, len, NULL, 0, NULL, 0,
+     255                 :            :                                       NULL, 0, NULL, 0)) != 0) {
+     256                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+     257                 :            :     }
+     258                 :            : 
+     259                 :       1097 :     p += len;
+     260                 :            : 
+     261                 :            :     /* Import E */
+     262         [ -  + ]:       1097 :     if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_INTEGER)) != 0) {
+     263                 :          0 :         return ret;
+     264                 :            :     }
+     265                 :            : 
+     266         [ -  + ]:       1097 :     if ((ret = mbedtls_rsa_import_raw(rsa, NULL, 0, NULL, 0, NULL, 0,
+     267                 :            :                                       NULL, 0, p, len)) != 0) {
+     268                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+     269                 :            :     }
+     270                 :            : 
+     271                 :       1097 :     p += len;
+     272                 :            : 
+     273   [ +  -  -  + ]:       2194 :     if (mbedtls_rsa_complete(rsa) != 0 ||
+     274                 :       1097 :         mbedtls_rsa_check_pubkey(rsa) != 0) {
+     275                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+     276                 :            :     }
+     277                 :            : 
+     278         [ -  + ]:       1097 :     if (p != end) {
+     279                 :          0 :         return MBEDTLS_ERR_ASN1_LENGTH_MISMATCH;
+     280                 :            :     }
+     281                 :            : 
+     282                 :       1097 :     return 0;
+     283                 :            : }
+     284                 :            : 
+     285                 :          0 : int mbedtls_rsa_write_key(const mbedtls_rsa_context *rsa, unsigned char *start,
+     286                 :            :                           unsigned char **p)
+     287                 :            : {
+     288                 :          0 :     size_t len = 0;
+     289                 :            :     int ret;
+     290                 :            : 
+     291                 :            :     mbedtls_mpi T; /* Temporary holding the exported parameters */
+     292                 :            : 
+     293                 :            :     /*
+     294                 :            :      * Export the parameters one after another to avoid simultaneous copies.
+     295                 :            :      */
+     296                 :            : 
+     297                 :          0 :     mbedtls_mpi_init(&T);
+     298                 :            : 
+     299                 :            :     /* Export QP */
+     300   [ #  #  #  # ]:          0 :     if ((ret = mbedtls_rsa_export_crt(rsa, NULL, NULL, &T)) != 0 ||
+     301                 :          0 :         (ret = mbedtls_asn1_write_mpi(p, start, &T)) < 0) {
+     302                 :          0 :         goto end_of_export;
+     303                 :            :     }
+     304                 :          0 :     len += ret;
+     305                 :            : 
+     306                 :            :     /* Export DQ */
+     307   [ #  #  #  # ]:          0 :     if ((ret = mbedtls_rsa_export_crt(rsa, NULL, &T, NULL)) != 0 ||
+     308                 :          0 :         (ret = mbedtls_asn1_write_mpi(p, start, &T)) < 0) {
+     309                 :          0 :         goto end_of_export;
+     310                 :            :     }
+     311                 :          0 :     len += ret;
+     312                 :            : 
+     313                 :            :     /* Export DP */
+     314   [ #  #  #  # ]:          0 :     if ((ret = mbedtls_rsa_export_crt(rsa, &T, NULL, NULL)) != 0 ||
+     315                 :          0 :         (ret = mbedtls_asn1_write_mpi(p, start, &T)) < 0) {
+     316                 :          0 :         goto end_of_export;
+     317                 :            :     }
+     318                 :          0 :     len += ret;
+     319                 :            : 
+     320                 :            :     /* Export Q */
+     321   [ #  #  #  # ]:          0 :     if ((ret = mbedtls_rsa_export(rsa, NULL, NULL, &T, NULL, NULL)) != 0 ||
+     322                 :          0 :         (ret = mbedtls_asn1_write_mpi(p, start, &T)) < 0) {
+     323                 :          0 :         goto end_of_export;
+     324                 :            :     }
+     325                 :          0 :     len += ret;
+     326                 :            : 
+     327                 :            :     /* Export P */
+     328   [ #  #  #  # ]:          0 :     if ((ret = mbedtls_rsa_export(rsa, NULL, &T, NULL, NULL, NULL)) != 0 ||
+     329                 :          0 :         (ret = mbedtls_asn1_write_mpi(p, start, &T)) < 0) {
+     330                 :          0 :         goto end_of_export;
+     331                 :            :     }
+     332                 :          0 :     len += ret;
+     333                 :            : 
+     334                 :            :     /* Export D */
+     335   [ #  #  #  # ]:          0 :     if ((ret = mbedtls_rsa_export(rsa, NULL, NULL, NULL, &T, NULL)) != 0 ||
+     336                 :          0 :         (ret = mbedtls_asn1_write_mpi(p, start, &T)) < 0) {
+     337                 :          0 :         goto end_of_export;
+     338                 :            :     }
+     339                 :          0 :     len += ret;
+     340                 :            : 
+     341                 :            :     /* Export E */
+     342   [ #  #  #  # ]:          0 :     if ((ret = mbedtls_rsa_export(rsa, NULL, NULL, NULL, NULL, &T)) != 0 ||
+     343                 :          0 :         (ret = mbedtls_asn1_write_mpi(p, start, &T)) < 0) {
+     344                 :          0 :         goto end_of_export;
+     345                 :            :     }
+     346                 :          0 :     len += ret;
+     347                 :            : 
+     348                 :            :     /* Export N */
+     349   [ #  #  #  # ]:          0 :     if ((ret = mbedtls_rsa_export(rsa, &T, NULL, NULL, NULL, NULL)) != 0 ||
+     350                 :          0 :         (ret = mbedtls_asn1_write_mpi(p, start, &T)) < 0) {
+     351                 :          0 :         goto end_of_export;
+     352                 :            :     }
+     353                 :          0 :     len += ret;
+     354                 :            : 
+     355                 :          0 : end_of_export:
+     356                 :            : 
+     357                 :          0 :     mbedtls_mpi_free(&T);
+     358         [ #  # ]:          0 :     if (ret < 0) {
+     359                 :          0 :         return ret;
+     360                 :            :     }
+     361                 :            : 
+     362         [ #  # ]:          0 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_int(p, start, 0));
+     363         [ #  # ]:          0 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(p, start, len));
+     364         [ #  # ]:          0 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(p, start,
+     365                 :            :                                                      MBEDTLS_ASN1_CONSTRUCTED |
+     366                 :            :                                                      MBEDTLS_ASN1_SEQUENCE));
+     367                 :            : 
+     368                 :          0 :     return (int) len;
+     369                 :            : }
+     370                 :            : 
+     371                 :            : /*
+     372                 :            :  *  RSAPublicKey ::= SEQUENCE {
+     373                 :            :  *      modulus           INTEGER,  -- n
+     374                 :            :  *      publicExponent    INTEGER   -- e
+     375                 :            :  *  }
+     376                 :            :  */
+     377                 :          0 : int mbedtls_rsa_write_pubkey(const mbedtls_rsa_context *rsa, unsigned char *start,
+     378                 :            :                              unsigned char **p)
+     379                 :            : {
+     380                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     381                 :          0 :     size_t len = 0;
+     382                 :            :     mbedtls_mpi T;
+     383                 :            : 
+     384                 :          0 :     mbedtls_mpi_init(&T);
+     385                 :            : 
+     386                 :            :     /* Export E */
+     387   [ #  #  #  # ]:          0 :     if ((ret = mbedtls_rsa_export(rsa, NULL, NULL, NULL, NULL, &T)) != 0 ||
+     388                 :          0 :         (ret = mbedtls_asn1_write_mpi(p, start, &T)) < 0) {
+     389                 :          0 :         goto end_of_export;
+     390                 :            :     }
+     391                 :          0 :     len += ret;
+     392                 :            : 
+     393                 :            :     /* Export N */
+     394   [ #  #  #  # ]:          0 :     if ((ret = mbedtls_rsa_export(rsa, &T, NULL, NULL, NULL, NULL)) != 0 ||
+     395                 :          0 :         (ret = mbedtls_asn1_write_mpi(p, start, &T)) < 0) {
+     396                 :          0 :         goto end_of_export;
+     397                 :            :     }
+     398                 :          0 :     len += ret;
+     399                 :            : 
+     400                 :          0 : end_of_export:
+     401                 :            : 
+     402                 :          0 :     mbedtls_mpi_free(&T);
+     403         [ #  # ]:          0 :     if (ret < 0) {
+     404                 :          0 :         return ret;
+     405                 :            :     }
+     406                 :            : 
+     407         [ #  # ]:          0 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(p, start, len));
+     408         [ #  # ]:          0 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(p, start, MBEDTLS_ASN1_CONSTRUCTED |
+     409                 :            :                                                      MBEDTLS_ASN1_SEQUENCE));
+     410                 :            : 
+     411                 :          0 :     return (int) len;
+     412                 :            : }
+     413                 :            : 
+     414                 :            : #if defined(MBEDTLS_PKCS1_V15) && defined(MBEDTLS_RSA_C) && !defined(MBEDTLS_RSA_ALT)
+     415                 :            : 
+     416                 :            : /** This function performs the unpadding part of a PKCS#1 v1.5 decryption
+     417                 :            :  *  operation (EME-PKCS1-v1_5 decoding).
+     418                 :            :  *
+     419                 :            :  * \note The return value from this function is a sensitive value
+     420                 :            :  *       (this is unusual). #MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE shouldn't happen
+     421                 :            :  *       in a well-written application, but 0 vs #MBEDTLS_ERR_RSA_INVALID_PADDING
+     422                 :            :  *       is often a situation that an attacker can provoke and leaking which
+     423                 :            :  *       one is the result is precisely the information the attacker wants.
+     424                 :            :  *
+     425                 :            :  * \param input          The input buffer which is the payload inside PKCS#1v1.5
+     426                 :            :  *                       encryption padding, called the "encoded message EM"
+     427                 :            :  *                       by the terminology.
+     428                 :            :  * \param ilen           The length of the payload in the \p input buffer.
+     429                 :            :  * \param output         The buffer for the payload, called "message M" by the
+     430                 :            :  *                       PKCS#1 terminology. This must be a writable buffer of
+     431                 :            :  *                       length \p output_max_len bytes.
+     432                 :            :  * \param olen           The address at which to store the length of
+     433                 :            :  *                       the payload. This must not be \c NULL.
+     434                 :            :  * \param output_max_len The length in bytes of the output buffer \p output.
+     435                 :            :  *
+     436                 :            :  * \return      \c 0 on success.
+     437                 :            :  * \return      #MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE
+     438                 :            :  *              The output buffer is too small for the unpadded payload.
+     439                 :            :  * \return      #MBEDTLS_ERR_RSA_INVALID_PADDING
+     440                 :            :  *              The input doesn't contain properly formatted padding.
+     441                 :            :  */
+     442                 :          0 : static int mbedtls_ct_rsaes_pkcs1_v15_unpadding(unsigned char *input,
+     443                 :            :                                                 size_t ilen,
+     444                 :            :                                                 unsigned char *output,
+     445                 :            :                                                 size_t output_max_len,
+     446                 :            :                                                 size_t *olen)
+     447                 :            : {
+     448                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     449                 :            :     size_t i, plaintext_max_size;
+     450                 :            : 
+     451                 :            :     /* The following variables take sensitive values: their value must
+     452                 :            :      * not leak into the observable behavior of the function other than
+     453                 :            :      * the designated outputs (output, olen, return value). Otherwise
+     454                 :            :      * this would open the execution of the function to
+     455                 :            :      * side-channel-based variants of the Bleichenbacher padding oracle
+     456                 :            :      * attack. Potential side channels include overall timing, memory
+     457                 :            :      * access patterns (especially visible to an adversary who has access
+     458                 :            :      * to a shared memory cache), and branches (especially visible to
+     459                 :            :      * an adversary who has access to a shared code cache or to a shared
+     460                 :            :      * branch predictor). */
+     461                 :          0 :     size_t pad_count = 0;
+     462                 :            :     mbedtls_ct_condition_t bad;
+     463                 :            :     mbedtls_ct_condition_t pad_done;
+     464                 :          0 :     size_t plaintext_size = 0;
+     465                 :            :     mbedtls_ct_condition_t output_too_large;
+     466                 :            : 
+     467                 :          0 :     plaintext_max_size = (output_max_len > ilen - 11) ? ilen - 11
+     468                 :            :                                                         : output_max_len;
+     469                 :            : 
+     470                 :            :     /* Check and get padding length in constant time and constant
+     471                 :            :      * memory trace. The first byte must be 0. */
+     472                 :          0 :     bad = mbedtls_ct_bool(input[0]);
+     473                 :            : 
+     474                 :            : 
+     475                 :            :     /* Decode EME-PKCS1-v1_5 padding: 0x00 || 0x02 || PS || 0x00
+     476                 :            :      * where PS must be at least 8 nonzero bytes. */
+     477                 :          0 :     bad = mbedtls_ct_bool_or(bad, mbedtls_ct_uint_ne(input[1], MBEDTLS_RSA_CRYPT));
+     478                 :            : 
+     479                 :            :     /* Read the whole buffer. Set pad_done to nonzero if we find
+     480                 :            :      * the 0x00 byte and remember the padding length in pad_count. */
+     481                 :          0 :     pad_done = MBEDTLS_CT_FALSE;
+     482         [ #  # ]:          0 :     for (i = 2; i < ilen; i++) {
+     483                 :          0 :         mbedtls_ct_condition_t found = mbedtls_ct_uint_eq(input[i], 0);
+     484                 :          0 :         pad_done   = mbedtls_ct_bool_or(pad_done, found);
+     485                 :          0 :         pad_count += mbedtls_ct_uint_if_else_0(mbedtls_ct_bool_not(pad_done), 1);
+     486                 :            :     }
+     487                 :            : 
+     488                 :            :     /* If pad_done is still zero, there's no data, only unfinished padding. */
+     489                 :          0 :     bad = mbedtls_ct_bool_or(bad, mbedtls_ct_bool_not(pad_done));
+     490                 :            : 
+     491                 :            :     /* There must be at least 8 bytes of padding. */
+     492                 :          0 :     bad = mbedtls_ct_bool_or(bad, mbedtls_ct_uint_gt(8, pad_count));
+     493                 :            : 
+     494                 :            :     /* If the padding is valid, set plaintext_size to the number of
+     495                 :            :      * remaining bytes after stripping the padding. If the padding
+     496                 :            :      * is invalid, avoid leaking this fact through the size of the
+     497                 :            :      * output: use the maximum message size that fits in the output
+     498                 :            :      * buffer. Do it without branches to avoid leaking the padding
+     499                 :            :      * validity through timing. RSA keys are small enough that all the
+     500                 :            :      * size_t values involved fit in unsigned int. */
+     501                 :          0 :     plaintext_size = mbedtls_ct_uint_if(
+     502                 :            :         bad, (unsigned) plaintext_max_size,
+     503                 :          0 :         (unsigned) (ilen - pad_count - 3));
+     504                 :            : 
+     505                 :            :     /* Set output_too_large to 0 if the plaintext fits in the output
+     506                 :            :      * buffer and to 1 otherwise. */
+     507                 :          0 :     output_too_large = mbedtls_ct_uint_gt(plaintext_size,
+     508                 :            :                                           plaintext_max_size);
+     509                 :            : 
+     510                 :            :     /* Set ret without branches to avoid timing attacks. Return:
+     511                 :            :      * - INVALID_PADDING if the padding is bad (bad != 0).
+     512                 :            :      * - OUTPUT_TOO_LARGE if the padding is good but the decrypted
+     513                 :            :      *   plaintext does not fit in the output buffer.
+     514                 :            :      * - 0 if the padding is correct. */
+     515                 :          0 :     ret = mbedtls_ct_error_if(
+     516                 :            :         bad,
+     517                 :            :         MBEDTLS_ERR_RSA_INVALID_PADDING,
+     518                 :            :         mbedtls_ct_error_if_else_0(output_too_large, MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE)
+     519                 :            :         );
+     520                 :            : 
+     521                 :            :     /* If the padding is bad or the plaintext is too large, zero the
+     522                 :            :      * data that we're about to copy to the output buffer.
+     523                 :            :      * We need to copy the same amount of data
+     524                 :            :      * from the same buffer whether the padding is good or not to
+     525                 :            :      * avoid leaking the padding validity through overall timing or
+     526                 :            :      * through memory or cache access patterns. */
+     527                 :          0 :     mbedtls_ct_zeroize_if(mbedtls_ct_bool_or(bad, output_too_large), input + 11, ilen - 11);
+     528                 :            : 
+     529                 :            :     /* If the plaintext is too large, truncate it to the buffer size.
+     530                 :            :      * Copy anyway to avoid revealing the length through timing, because
+     531                 :            :      * revealing the length is as bad as revealing the padding validity
+     532                 :            :      * for a Bleichenbacher attack. */
+     533                 :          0 :     plaintext_size = mbedtls_ct_uint_if(output_too_large,
+     534                 :            :                                         (unsigned) plaintext_max_size,
+     535                 :            :                                         (unsigned) plaintext_size);
+     536                 :            : 
+     537                 :            :     /* Move the plaintext to the leftmost position where it can start in
+     538                 :            :      * the working buffer, i.e. make it start plaintext_max_size from
+     539                 :            :      * the end of the buffer. Do this with a memory access trace that
+     540                 :            :      * does not depend on the plaintext size. After this move, the
+     541                 :            :      * starting location of the plaintext is no longer sensitive
+     542                 :            :      * information. */
+     543                 :          0 :     mbedtls_ct_memmove_left(input + ilen - plaintext_max_size,
+     544                 :            :                             plaintext_max_size,
+     545                 :            :                             plaintext_max_size - plaintext_size);
+     546                 :            : 
+     547                 :            :     /* Finally copy the decrypted plaintext plus trailing zeros into the output
+     548                 :            :      * buffer. If output_max_len is 0, then output may be an invalid pointer
+     549                 :            :      * and the result of memcpy() would be undefined; prevent undefined
+     550                 :            :      * behavior making sure to depend only on output_max_len (the size of the
+     551                 :            :      * user-provided output buffer), which is independent from plaintext
+     552                 :            :      * length, validity of padding, success of the decryption, and other
+     553                 :            :      * secrets. */
+     554         [ #  # ]:          0 :     if (output_max_len != 0) {
+     555                 :          0 :         memcpy(output, input + ilen - plaintext_max_size, plaintext_max_size);
+     556                 :            :     }
+     557                 :            : 
+     558                 :            :     /* Report the amount of data we copied to the output buffer. In case
+     559                 :            :      * of errors (bad padding or output too large), the value of *olen
+     560                 :            :      * when this function returns is not specified. Making it equivalent
+     561                 :            :      * to the good case limits the risks of leaking the padding validity. */
+     562                 :          0 :     *olen = plaintext_size;
+     563                 :            : 
+     564                 :          0 :     return ret;
+     565                 :            : }
+     566                 :            : 
+     567                 :            : #endif /* MBEDTLS_PKCS1_V15 && MBEDTLS_RSA_C && ! MBEDTLS_RSA_ALT */
+     568                 :            : 
+     569                 :            : #if !defined(MBEDTLS_RSA_ALT)
+     570                 :            : 
+     571                 :        131 : int mbedtls_rsa_import(mbedtls_rsa_context *ctx,
+     572                 :            :                        const mbedtls_mpi *N,
+     573                 :            :                        const mbedtls_mpi *P, const mbedtls_mpi *Q,
+     574                 :            :                        const mbedtls_mpi *D, const mbedtls_mpi *E)
+     575                 :            : {
+     576                 :        131 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     577                 :            : 
+     578   [ +  +  +  -  :        131 :     if ((N != NULL && (ret = mbedtls_mpi_copy(&ctx->N, N)) != 0) ||
+                   +  + ]
+     579   [ +  -  +  + ]:        131 :         (P != NULL && (ret = mbedtls_mpi_copy(&ctx->P, P)) != 0) ||
+     580   [ +  -  +  + ]:        131 :         (Q != NULL && (ret = mbedtls_mpi_copy(&ctx->Q, Q)) != 0) ||
+     581   [ +  -  +  + ]:        131 :         (D != NULL && (ret = mbedtls_mpi_copy(&ctx->D, D)) != 0) ||
+     582         [ -  + ]:         27 :         (E != NULL && (ret = mbedtls_mpi_copy(&ctx->E, E)) != 0)) {
+     583                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret);
+     584                 :            :     }
+     585                 :            : 
+     586         [ +  + ]:        131 :     if (N != NULL) {
+     587                 :         27 :         ctx->len = mbedtls_mpi_size(&ctx->N);
+     588                 :            :     }
+     589                 :            : 
+     590                 :        131 :     return 0;
+     591                 :            : }
+     592                 :            : 
+     593                 :       2194 : int mbedtls_rsa_import_raw(mbedtls_rsa_context *ctx,
+     594                 :            :                            unsigned char const *N, size_t N_len,
+     595                 :            :                            unsigned char const *P, size_t P_len,
+     596                 :            :                            unsigned char const *Q, size_t Q_len,
+     597                 :            :                            unsigned char const *D, size_t D_len,
+     598                 :            :                            unsigned char const *E, size_t E_len)
+     599                 :            : {
+     600                 :       2194 :     int ret = 0;
+     601                 :            : 
+     602         [ +  + ]:       2194 :     if (N != NULL) {
+     603         [ -  + ]:       1097 :         MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&ctx->N, N, N_len));
+     604                 :       1097 :         ctx->len = mbedtls_mpi_size(&ctx->N);
+     605                 :            :     }
+     606                 :            : 
+     607         [ -  + ]:       2194 :     if (P != NULL) {
+     608         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&ctx->P, P, P_len));
+     609                 :            :     }
+     610                 :            : 
+     611         [ -  + ]:       2194 :     if (Q != NULL) {
+     612         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&ctx->Q, Q, Q_len));
+     613                 :            :     }
+     614                 :            : 
+     615         [ -  + ]:       2194 :     if (D != NULL) {
+     616         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&ctx->D, D, D_len));
+     617                 :            :     }
+     618                 :            : 
+     619         [ +  + ]:       2194 :     if (E != NULL) {
+     620         [ +  - ]:       1097 :         MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&ctx->E, E, E_len));
+     621                 :            :     }
+     622                 :            : 
+     623                 :       2194 : cleanup:
+     624                 :            : 
+     625         [ -  + ]:       2194 :     if (ret != 0) {
+     626                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret);
+     627                 :            :     }
+     628                 :            : 
+     629                 :       2194 :     return 0;
+     630                 :            : }
+     631                 :            : 
+     632                 :            : /*
+     633                 :            :  * Checks whether the context fields are set in such a way
+     634                 :            :  * that the RSA primitives will be able to execute without error.
+     635                 :            :  * It does *not* make guarantees for consistency of the parameters.
+     636                 :            :  */
+     637                 :       2623 : static int rsa_check_context(mbedtls_rsa_context const *ctx, int is_priv,
+     638                 :            :                              int blinding_needed)
+     639                 :            : {
+     640                 :            : #if !defined(MBEDTLS_RSA_NO_CRT)
+     641                 :            :     /* blinding_needed is only used for NO_CRT to decide whether
+     642                 :            :      * P,Q need to be present or not. */
+     643                 :            :     ((void) blinding_needed);
+     644                 :            : #endif
+     645                 :            : 
+     646         [ +  - ]:       2623 :     if (ctx->len != mbedtls_mpi_size(&ctx->N) ||
+     647         [ -  + ]:       2623 :         ctx->len > MBEDTLS_MPI_MAX_SIZE) {
+     648                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+     649                 :            :     }
+     650                 :            : 
+     651                 :            :     /*
+     652                 :            :      * 1. Modular exponentiation needs positive, odd moduli.
+     653                 :            :      */
+     654                 :            : 
+     655                 :            :     /* Modular exponentiation wrt. N is always used for
+     656                 :            :      * RSA public key operations. */
+     657   [ +  -  -  + ]:       5246 :     if (mbedtls_mpi_cmp_int(&ctx->N, 0) <= 0 ||
+     658                 :       2623 :         mbedtls_mpi_get_bit(&ctx->N, 0) == 0) {
+     659                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+     660                 :            :     }
+     661                 :            : 
+     662                 :            : #if !defined(MBEDTLS_RSA_NO_CRT)
+     663                 :            :     /* Modular exponentiation for P and Q is only
+     664                 :            :      * used for private key operations and if CRT
+     665                 :            :      * is used. */
+     666   [ +  +  +  - ]:       2711 :     if (is_priv &&
+     667         [ +  - ]:        176 :         (mbedtls_mpi_cmp_int(&ctx->P, 0) <= 0 ||
+     668         [ +  - ]:        176 :          mbedtls_mpi_get_bit(&ctx->P, 0) == 0 ||
+     669         [ -  + ]:        176 :          mbedtls_mpi_cmp_int(&ctx->Q, 0) <= 0 ||
+     670                 :         88 :          mbedtls_mpi_get_bit(&ctx->Q, 0) == 0)) {
+     671                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+     672                 :            :     }
+     673                 :            : #endif /* !MBEDTLS_RSA_NO_CRT */
+     674                 :            : 
+     675                 :            :     /*
+     676                 :            :      * 2. Exponents must be positive
+     677                 :            :      */
+     678                 :            : 
+     679                 :            :     /* Always need E for public key operations */
+     680         [ -  + ]:       2623 :     if (mbedtls_mpi_cmp_int(&ctx->E, 0) <= 0) {
+     681                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+     682                 :            :     }
+     683                 :            : 
+     684                 :            : #if defined(MBEDTLS_RSA_NO_CRT)
+     685                 :            :     /* For private key operations, use D or DP & DQ
+     686                 :            :      * as (unblinded) exponents. */
+     687                 :            :     if (is_priv && mbedtls_mpi_cmp_int(&ctx->D, 0) <= 0) {
+     688                 :            :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+     689                 :            :     }
+     690                 :            : #else
+     691   [ +  +  +  - ]:       2711 :     if (is_priv &&
+     692         [ -  + ]:        176 :         (mbedtls_mpi_cmp_int(&ctx->DP, 0) <= 0 ||
+     693                 :         88 :          mbedtls_mpi_cmp_int(&ctx->DQ, 0) <= 0)) {
+     694                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+     695                 :            :     }
+     696                 :            : #endif /* MBEDTLS_RSA_NO_CRT */
+     697                 :            : 
+     698                 :            :     /* Blinding shouldn't make exponents negative either,
+     699                 :            :      * so check that P, Q >= 1 if that hasn't yet been
+     700                 :            :      * done as part of 1. */
+     701                 :            : #if defined(MBEDTLS_RSA_NO_CRT)
+     702                 :            :     if (is_priv && blinding_needed &&
+     703                 :            :         (mbedtls_mpi_cmp_int(&ctx->P, 0) <= 0 ||
+     704                 :            :          mbedtls_mpi_cmp_int(&ctx->Q, 0) <= 0)) {
+     705                 :            :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+     706                 :            :     }
+     707                 :            : #endif
+     708                 :            : 
+     709                 :            :     /* It wouldn't lead to an error if it wasn't satisfied,
+     710                 :            :      * but check for QP >= 1 nonetheless. */
+     711                 :            : #if !defined(MBEDTLS_RSA_NO_CRT)
+     712   [ +  +  -  + ]:       2711 :     if (is_priv &&
+     713                 :         88 :         mbedtls_mpi_cmp_int(&ctx->QP, 0) <= 0) {
+     714                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+     715                 :            :     }
+     716                 :            : #endif
+     717                 :            : 
+     718                 :       2623 :     return 0;
+     719                 :            : }
+     720                 :            : 
+     721                 :       1172 : int mbedtls_rsa_complete(mbedtls_rsa_context *ctx)
+     722                 :            : {
+     723                 :       1172 :     int ret = 0;
+     724                 :            :     int have_N, have_P, have_Q, have_D, have_E;
+     725                 :            : #if !defined(MBEDTLS_RSA_NO_CRT)
+     726                 :            :     int have_DP, have_DQ, have_QP;
+     727                 :            : #endif
+     728                 :            :     int n_missing, pq_missing, d_missing, is_pub, is_priv;
+     729                 :            : 
+     730                 :       1172 :     have_N = (mbedtls_mpi_cmp_int(&ctx->N, 0) != 0);
+     731                 :       1172 :     have_P = (mbedtls_mpi_cmp_int(&ctx->P, 0) != 0);
+     732                 :       1172 :     have_Q = (mbedtls_mpi_cmp_int(&ctx->Q, 0) != 0);
+     733                 :       1172 :     have_D = (mbedtls_mpi_cmp_int(&ctx->D, 0) != 0);
+     734                 :       1172 :     have_E = (mbedtls_mpi_cmp_int(&ctx->E, 0) != 0);
+     735                 :            : 
+     736                 :            : #if !defined(MBEDTLS_RSA_NO_CRT)
+     737                 :       1172 :     have_DP = (mbedtls_mpi_cmp_int(&ctx->DP, 0) != 0);
+     738                 :       1172 :     have_DQ = (mbedtls_mpi_cmp_int(&ctx->DQ, 0) != 0);
+     739                 :       1172 :     have_QP = (mbedtls_mpi_cmp_int(&ctx->QP, 0) != 0);
+     740                 :            : #endif
+     741                 :            : 
+     742                 :            :     /*
+     743                 :            :      * Check whether provided parameters are enough
+     744                 :            :      * to deduce all others. The following incomplete
+     745                 :            :      * parameter sets for private keys are supported:
+     746                 :            :      *
+     747                 :            :      * (1) P, Q missing.
+     748                 :            :      * (2) D and potentially N missing.
+     749                 :            :      *
+     750                 :            :      */
+     751                 :            : 
+     752   [ +  +  +  -  :       1172 :     n_missing  =              have_P &&  have_Q &&  have_D && have_E;
+             +  -  +  - ]
+     753   [ +  -  +  +  :       1172 :     pq_missing =   have_N && !have_P && !have_Q &&  have_D && have_E;
+          +  -  +  +  +  
+                      - ]
+     754   [ +  +  +  -  :       1172 :     d_missing  =              have_P &&  have_Q && !have_D && have_E;
+             -  +  -  - ]
+     755   [ +  -  +  +  :       1172 :     is_pub     =   have_N && !have_P && !have_Q && !have_D && have_E;
+          +  -  +  +  +  
+                      - ]
+     756                 :            : 
+     757                 :            :     /* These three alternatives are mutually exclusive */
+     758   [ +  +  +  +  :       1172 :     is_priv = n_missing || pq_missing || d_missing;
+                   -  + ]
+     759                 :            : 
+     760   [ +  +  -  + ]:       1172 :     if (!is_priv && !is_pub) {
+     761                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+     762                 :            :     }
+     763                 :            : 
+     764                 :            :     /*
+     765                 :            :      * Step 1: Deduce N if P, Q are provided.
+     766                 :            :      */
+     767                 :            : 
+     768   [ -  +  -  -  :       1172 :     if (!have_N && have_P && have_Q) {
+                   -  - ]
+     769         [ #  # ]:          0 :         if ((ret = mbedtls_mpi_mul_mpi(&ctx->N, &ctx->P,
+     770                 :          0 :                                        &ctx->Q)) != 0) {
+     771                 :          0 :             return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret);
+     772                 :            :         }
+     773                 :            : 
+     774                 :          0 :         ctx->len = mbedtls_mpi_size(&ctx->N);
+     775                 :            :     }
+     776                 :            : 
+     777                 :            :     /*
+     778                 :            :      * Step 2: Deduce and verify all remaining core parameters.
+     779                 :            :      */
+     780                 :            : 
+     781         [ +  + ]:       1172 :     if (pq_missing) {
+     782                 :          2 :         ret = mbedtls_rsa_deduce_primes(&ctx->N, &ctx->E, &ctx->D,
+     783                 :            :                                         &ctx->P, &ctx->Q);
+     784         [ -  + ]:          2 :         if (ret != 0) {
+     785                 :          0 :             return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret);
+     786                 :            :         }
+     787                 :            : 
+     788         [ -  + ]:       1170 :     } else if (d_missing) {
+     789         [ #  # ]:          0 :         if ((ret = mbedtls_rsa_deduce_private_exponent(&ctx->P,
+     790                 :          0 :                                                        &ctx->Q,
+     791                 :          0 :                                                        &ctx->E,
+     792                 :            :                                                        &ctx->D)) != 0) {
+     793                 :          0 :             return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret);
+     794                 :            :         }
+     795                 :            :     }
+     796                 :            : 
+     797                 :            :     /*
+     798                 :            :      * Step 3: Deduce all additional parameters specific
+     799                 :            :      *         to our current RSA implementation.
+     800                 :            :      */
+     801                 :            : 
+     802                 :            : #if !defined(MBEDTLS_RSA_NO_CRT)
+     803   [ +  +  +  +  :       1172 :     if (is_priv && !(have_DP && have_DQ && have_QP)) {
+             +  -  -  + ]
+     804                 :          2 :         ret = mbedtls_rsa_deduce_crt(&ctx->P,  &ctx->Q,  &ctx->D,
+     805                 :            :                                      &ctx->DP, &ctx->DQ, &ctx->QP);
+     806         [ -  + ]:          2 :         if (ret != 0) {
+     807                 :          0 :             return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret);
+     808                 :            :         }
+     809                 :            :     }
+     810                 :            : #endif /* MBEDTLS_RSA_NO_CRT */
+     811                 :            : 
+     812                 :            :     /*
+     813                 :            :      * Step 3: Basic sanity checks
+     814                 :            :      */
+     815                 :            : 
+     816                 :       1172 :     return rsa_check_context(ctx, is_priv, 1);
+     817                 :            : }
+     818                 :            : 
+     819                 :          0 : int mbedtls_rsa_export_raw(const mbedtls_rsa_context *ctx,
+     820                 :            :                            unsigned char *N, size_t N_len,
+     821                 :            :                            unsigned char *P, size_t P_len,
+     822                 :            :                            unsigned char *Q, size_t Q_len,
+     823                 :            :                            unsigned char *D, size_t D_len,
+     824                 :            :                            unsigned char *E, size_t E_len)
+     825                 :            : {
+     826                 :          0 :     int ret = 0;
+     827                 :            :     int is_priv;
+     828                 :            : 
+     829                 :            :     /* Check if key is private or public */
+     830                 :          0 :     is_priv =
+     831         [ #  # ]:          0 :         mbedtls_mpi_cmp_int(&ctx->N, 0) != 0 &&
+     832         [ #  # ]:          0 :         mbedtls_mpi_cmp_int(&ctx->P, 0) != 0 &&
+     833         [ #  # ]:          0 :         mbedtls_mpi_cmp_int(&ctx->Q, 0) != 0 &&
+     834   [ #  #  #  # ]:          0 :         mbedtls_mpi_cmp_int(&ctx->D, 0) != 0 &&
+     835                 :          0 :         mbedtls_mpi_cmp_int(&ctx->E, 0) != 0;
+     836                 :            : 
+     837         [ #  # ]:          0 :     if (!is_priv) {
+     838                 :            :         /* If we're trying to export private parameters for a public key,
+     839                 :            :          * something must be wrong. */
+     840   [ #  #  #  #  :          0 :         if (P != NULL || Q != NULL || D != NULL) {
+                   #  # ]
+     841                 :          0 :             return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+     842                 :            :         }
+     843                 :            : 
+     844                 :            :     }
+     845                 :            : 
+     846         [ #  # ]:          0 :     if (N != NULL) {
+     847         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(&ctx->N, N, N_len));
+     848                 :            :     }
+     849                 :            : 
+     850         [ #  # ]:          0 :     if (P != NULL) {
+     851         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(&ctx->P, P, P_len));
+     852                 :            :     }
+     853                 :            : 
+     854         [ #  # ]:          0 :     if (Q != NULL) {
+     855         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(&ctx->Q, Q, Q_len));
+     856                 :            :     }
+     857                 :            : 
+     858         [ #  # ]:          0 :     if (D != NULL) {
+     859         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(&ctx->D, D, D_len));
+     860                 :            :     }
+     861                 :            : 
+     862         [ #  # ]:          0 :     if (E != NULL) {
+     863         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(&ctx->E, E, E_len));
+     864                 :            :     }
+     865                 :            : 
+     866                 :          0 : cleanup:
+     867                 :            : 
+     868                 :          0 :     return ret;
+     869                 :            : }
+     870                 :            : 
+     871                 :          0 : int mbedtls_rsa_export(const mbedtls_rsa_context *ctx,
+     872                 :            :                        mbedtls_mpi *N, mbedtls_mpi *P, mbedtls_mpi *Q,
+     873                 :            :                        mbedtls_mpi *D, mbedtls_mpi *E)
+     874                 :            : {
+     875                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     876                 :            :     int is_priv;
+     877                 :            : 
+     878                 :            :     /* Check if key is private or public */
+     879                 :          0 :     is_priv =
+     880         [ #  # ]:          0 :         mbedtls_mpi_cmp_int(&ctx->N, 0) != 0 &&
+     881         [ #  # ]:          0 :         mbedtls_mpi_cmp_int(&ctx->P, 0) != 0 &&
+     882         [ #  # ]:          0 :         mbedtls_mpi_cmp_int(&ctx->Q, 0) != 0 &&
+     883   [ #  #  #  # ]:          0 :         mbedtls_mpi_cmp_int(&ctx->D, 0) != 0 &&
+     884                 :          0 :         mbedtls_mpi_cmp_int(&ctx->E, 0) != 0;
+     885                 :            : 
+     886         [ #  # ]:          0 :     if (!is_priv) {
+     887                 :            :         /* If we're trying to export private parameters for a public key,
+     888                 :            :          * something must be wrong. */
+     889   [ #  #  #  #  :          0 :         if (P != NULL || Q != NULL || D != NULL) {
+                   #  # ]
+     890                 :          0 :             return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+     891                 :            :         }
+     892                 :            : 
+     893                 :            :     }
+     894                 :            : 
+     895                 :            :     /* Export all requested core parameters. */
+     896                 :            : 
+     897   [ #  #  #  #  :          0 :     if ((N != NULL && (ret = mbedtls_mpi_copy(N, &ctx->N)) != 0) ||
+                   #  # ]
+     898   [ #  #  #  # ]:          0 :         (P != NULL && (ret = mbedtls_mpi_copy(P, &ctx->P)) != 0) ||
+     899   [ #  #  #  # ]:          0 :         (Q != NULL && (ret = mbedtls_mpi_copy(Q, &ctx->Q)) != 0) ||
+     900   [ #  #  #  # ]:          0 :         (D != NULL && (ret = mbedtls_mpi_copy(D, &ctx->D)) != 0) ||
+     901         [ #  # ]:          0 :         (E != NULL && (ret = mbedtls_mpi_copy(E, &ctx->E)) != 0)) {
+     902                 :          0 :         return ret;
+     903                 :            :     }
+     904                 :            : 
+     905                 :          0 :     return 0;
+     906                 :            : }
+     907                 :            : 
+     908                 :            : /*
+     909                 :            :  * Export CRT parameters
+     910                 :            :  * This must also be implemented if CRT is not used, for being able to
+     911                 :            :  * write DER encoded RSA keys. The helper function mbedtls_rsa_deduce_crt
+     912                 :            :  * can be used in this case.
+     913                 :            :  */
+     914                 :          0 : int mbedtls_rsa_export_crt(const mbedtls_rsa_context *ctx,
+     915                 :            :                            mbedtls_mpi *DP, mbedtls_mpi *DQ, mbedtls_mpi *QP)
+     916                 :            : {
+     917                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     918                 :            :     int is_priv;
+     919                 :            : 
+     920                 :            :     /* Check if key is private or public */
+     921                 :          0 :     is_priv =
+     922         [ #  # ]:          0 :         mbedtls_mpi_cmp_int(&ctx->N, 0) != 0 &&
+     923         [ #  # ]:          0 :         mbedtls_mpi_cmp_int(&ctx->P, 0) != 0 &&
+     924         [ #  # ]:          0 :         mbedtls_mpi_cmp_int(&ctx->Q, 0) != 0 &&
+     925   [ #  #  #  # ]:          0 :         mbedtls_mpi_cmp_int(&ctx->D, 0) != 0 &&
+     926                 :          0 :         mbedtls_mpi_cmp_int(&ctx->E, 0) != 0;
+     927                 :            : 
+     928         [ #  # ]:          0 :     if (!is_priv) {
+     929                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+     930                 :            :     }
+     931                 :            : 
+     932                 :            : #if !defined(MBEDTLS_RSA_NO_CRT)
+     933                 :            :     /* Export all requested blinding parameters. */
+     934   [ #  #  #  #  :          0 :     if ((DP != NULL && (ret = mbedtls_mpi_copy(DP, &ctx->DP)) != 0) ||
+                   #  # ]
+     935   [ #  #  #  # ]:          0 :         (DQ != NULL && (ret = mbedtls_mpi_copy(DQ, &ctx->DQ)) != 0) ||
+     936         [ #  # ]:          0 :         (QP != NULL && (ret = mbedtls_mpi_copy(QP, &ctx->QP)) != 0)) {
+     937                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret);
+     938                 :            :     }
+     939                 :            : #else
+     940                 :            :     if ((ret = mbedtls_rsa_deduce_crt(&ctx->P, &ctx->Q, &ctx->D,
+     941                 :            :                                       DP, DQ, QP)) != 0) {
+     942                 :            :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret);
+     943                 :            :     }
+     944                 :            : #endif
+     945                 :            : 
+     946                 :          0 :     return 0;
+     947                 :            : }
+     948                 :            : 
+     949                 :            : /*
+     950                 :            :  * Initialize an RSA context
+     951                 :            :  */
+     952                 :       1218 : void mbedtls_rsa_init(mbedtls_rsa_context *ctx)
+     953                 :            : {
+     954                 :       1218 :     memset(ctx, 0, sizeof(mbedtls_rsa_context));
+     955                 :            : 
+     956                 :       1218 :     ctx->padding = MBEDTLS_RSA_PKCS_V15;
+     957                 :       1218 :     ctx->hash_id = MBEDTLS_MD_NONE;
+     958                 :            : 
+     959                 :            : #if defined(MBEDTLS_THREADING_C)
+     960                 :            :     /* Set ctx->ver to nonzero to indicate that the mutex has been
+     961                 :            :      * initialized and will need to be freed. */
+     962                 :            :     ctx->ver = 1;
+     963                 :            :     mbedtls_mutex_init(&ctx->mutex);
+     964                 :            : #endif
+     965                 :       1218 : }
+     966                 :            : 
+     967                 :            : /*
+     968                 :            :  * Set padding for an existing RSA context
+     969                 :            :  */
+     970                 :         50 : int mbedtls_rsa_set_padding(mbedtls_rsa_context *ctx, int padding,
+     971                 :            :                             mbedtls_md_type_t hash_id)
+     972                 :            : {
+     973      [ +  +  - ]:         50 :     switch (padding) {
+     974                 :            : #if defined(MBEDTLS_PKCS1_V15)
+     975                 :         48 :         case MBEDTLS_RSA_PKCS_V15:
+     976                 :         48 :             break;
+     977                 :            : #endif
+     978                 :            : 
+     979                 :            : #if defined(MBEDTLS_PKCS1_V21)
+     980                 :          2 :         case MBEDTLS_RSA_PKCS_V21:
+     981                 :          2 :             break;
+     982                 :            : #endif
+     983                 :          0 :         default:
+     984                 :          0 :             return MBEDTLS_ERR_RSA_INVALID_PADDING;
+     985                 :            :     }
+     986                 :            : 
+     987                 :            : #if defined(MBEDTLS_PKCS1_V21)
+     988   [ +  +  +  - ]:         50 :     if ((padding == MBEDTLS_RSA_PKCS_V21) &&
+     989                 :            :         (hash_id != MBEDTLS_MD_NONE)) {
+     990                 :            :         /* Just make sure this hash is supported in this build. */
+     991         [ -  + ]:          2 :         if (mbedtls_md_info_from_type(hash_id) == NULL) {
+     992                 :          0 :             return MBEDTLS_ERR_RSA_INVALID_PADDING;
+     993                 :            :         }
+     994                 :            :     }
+     995                 :            : #endif /* MBEDTLS_PKCS1_V21 */
+     996                 :            : 
+     997                 :         50 :     ctx->padding = padding;
+     998                 :         50 :     ctx->hash_id = hash_id;
+     999                 :            : 
+    1000                 :         50 :     return 0;
+    1001                 :            : }
+    1002                 :            : 
+    1003                 :            : /*
+    1004                 :            :  * Get padding mode of initialized RSA context
+    1005                 :            :  */
+    1006                 :          0 : int mbedtls_rsa_get_padding_mode(const mbedtls_rsa_context *ctx)
+    1007                 :            : {
+    1008                 :          0 :     return ctx->padding;
+    1009                 :            : }
+    1010                 :            : 
+    1011                 :            : /*
+    1012                 :            :  * Get hash identifier of mbedtls_md_type_t type
+    1013                 :            :  */
+    1014                 :          0 : int mbedtls_rsa_get_md_alg(const mbedtls_rsa_context *ctx)
+    1015                 :            : {
+    1016                 :          0 :     return ctx->hash_id;
+    1017                 :            : }
+    1018                 :            : 
+    1019                 :            : /*
+    1020                 :            :  * Get length in bits of RSA modulus
+    1021                 :            :  */
+    1022                 :        540 : size_t mbedtls_rsa_get_bitlen(const mbedtls_rsa_context *ctx)
+    1023                 :            : {
+    1024                 :        540 :     return mbedtls_mpi_bitlen(&ctx->N);
+    1025                 :            : }
+    1026                 :            : 
+    1027                 :            : /*
+    1028                 :            :  * Get length in bytes of RSA modulus
+    1029                 :            :  */
+    1030                 :        329 : size_t mbedtls_rsa_get_len(const mbedtls_rsa_context *ctx)
+    1031                 :            : {
+    1032                 :        329 :     return ctx->len;
+    1033                 :            : }
+    1034                 :            : 
+    1035                 :            : #if defined(MBEDTLS_GENPRIME)
+    1036                 :            : 
+    1037                 :            : /*
+    1038                 :            :  * Generate an RSA keypair
+    1039                 :            :  *
+    1040                 :            :  * This generation method follows the RSA key pair generation procedure of
+    1041                 :            :  * FIPS 186-4 if 2^16 < exponent < 2^256 and nbits = 2048 or nbits = 3072.
+    1042                 :            :  */
+    1043                 :          0 : int mbedtls_rsa_gen_key(mbedtls_rsa_context *ctx,
+    1044                 :            :                         int (*f_rng)(void *, unsigned char *, size_t),
+    1045                 :            :                         void *p_rng,
+    1046                 :            :                         unsigned int nbits, int exponent)
+    1047                 :            : {
+    1048                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1049                 :            :     mbedtls_mpi H, G, L;
+    1050                 :          0 :     int prime_quality = 0;
+    1051                 :            : 
+    1052                 :            :     /*
+    1053                 :            :      * If the modulus is 1024 bit long or shorter, then the security strength of
+    1054                 :            :      * the RSA algorithm is less than or equal to 80 bits and therefore an error
+    1055                 :            :      * rate of 2^-80 is sufficient.
+    1056                 :            :      */
+    1057         [ #  # ]:          0 :     if (nbits > 1024) {
+    1058                 :          0 :         prime_quality = MBEDTLS_MPI_GEN_PRIME_FLAG_LOW_ERR;
+    1059                 :            :     }
+    1060                 :            : 
+    1061                 :          0 :     mbedtls_mpi_init(&H);
+    1062                 :          0 :     mbedtls_mpi_init(&G);
+    1063                 :          0 :     mbedtls_mpi_init(&L);
+    1064                 :            : 
+    1065   [ #  #  #  # ]:          0 :     if (exponent < 3 || nbits % 2 != 0) {
+    1066                 :          0 :         ret = MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    1067                 :          0 :         goto cleanup;
+    1068                 :            :     }
+    1069                 :            : 
+    1070         [ #  # ]:          0 :     if (nbits < MBEDTLS_RSA_GEN_KEY_MIN_BITS) {
+    1071                 :          0 :         ret = MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    1072                 :          0 :         goto cleanup;
+    1073                 :            :     }
+    1074                 :            : 
+    1075                 :            :     /*
+    1076                 :            :      * find primes P and Q with Q < P so that:
+    1077                 :            :      * 1.  |P-Q| > 2^( nbits / 2 - 100 )
+    1078                 :            :      * 2.  GCD( E, (P-1)*(Q-1) ) == 1
+    1079                 :            :      * 3.  E^-1 mod LCM(P-1, Q-1) > 2^( nbits / 2 )
+    1080                 :            :      */
+    1081         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&ctx->E, exponent));
+    1082                 :            : 
+    1083                 :            :     do {
+    1084         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_gen_prime(&ctx->P, nbits >> 1,
+    1085                 :            :                                               prime_quality, f_rng, p_rng));
+    1086                 :            : 
+    1087         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_gen_prime(&ctx->Q, nbits >> 1,
+    1088                 :            :                                               prime_quality, f_rng, p_rng));
+    1089                 :            : 
+    1090                 :            :         /* make sure the difference between p and q is not too small (FIPS 186-4 §B.3.3 step 5.4) */
+    1091         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&H, &ctx->P, &ctx->Q));
+    1092   [ #  #  #  # ]:          0 :         if (mbedtls_mpi_bitlen(&H) <= ((nbits >= 200) ? ((nbits >> 1) - 99) : 0)) {
+    1093                 :          0 :             continue;
+    1094                 :            :         }
+    1095                 :            : 
+    1096                 :            :         /* not required by any standards, but some users rely on the fact that P > Q */
+    1097         [ #  # ]:          0 :         if (H.s < 0) {
+    1098                 :          0 :             mbedtls_mpi_swap(&ctx->P, &ctx->Q);
+    1099                 :            :         }
+    1100                 :            : 
+    1101                 :            :         /* Temporarily replace P,Q by P-1, Q-1 */
+    1102         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&ctx->P, &ctx->P, 1));
+    1103         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&ctx->Q, &ctx->Q, 1));
+    1104         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&H, &ctx->P, &ctx->Q));
+    1105                 :            : 
+    1106                 :            :         /* check GCD( E, (P-1)*(Q-1) ) == 1 (FIPS 186-4 §B.3.1 criterion 2(a)) */
+    1107         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_gcd(&G, &ctx->E, &H));
+    1108         [ #  # ]:          0 :         if (mbedtls_mpi_cmp_int(&G, 1) != 0) {
+    1109                 :          0 :             continue;
+    1110                 :            :         }
+    1111                 :            : 
+    1112                 :            :         /* compute smallest possible D = E^-1 mod LCM(P-1, Q-1) (FIPS 186-4 §B.3.1 criterion 3(b)) */
+    1113         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_gcd(&G, &ctx->P, &ctx->Q));
+    1114         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_div_mpi(&L, NULL, &H, &G));
+    1115         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_inv_mod(&ctx->D, &ctx->E, &L));
+    1116                 :            : 
+    1117         [ #  # ]:          0 :         if (mbedtls_mpi_bitlen(&ctx->D) <= ((nbits + 1) / 2)) {      // (FIPS 186-4 §B.3.1 criterion 3(a))
+    1118                 :          0 :             continue;
+    1119                 :            :         }
+    1120                 :            : 
+    1121                 :          0 :         break;
+    1122                 :            :     } while (1);
+    1123                 :            : 
+    1124                 :            :     /* Restore P,Q */
+    1125         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_add_int(&ctx->P,  &ctx->P, 1));
+    1126         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_add_int(&ctx->Q,  &ctx->Q, 1));
+    1127                 :            : 
+    1128         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&ctx->N, &ctx->P, &ctx->Q));
+    1129                 :            : 
+    1130                 :          0 :     ctx->len = mbedtls_mpi_size(&ctx->N);
+    1131                 :            : 
+    1132                 :            : #if !defined(MBEDTLS_RSA_NO_CRT)
+    1133                 :            :     /*
+    1134                 :            :      * DP = D mod (P - 1)
+    1135                 :            :      * DQ = D mod (Q - 1)
+    1136                 :            :      * QP = Q^-1 mod P
+    1137                 :            :      */
+    1138         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_rsa_deduce_crt(&ctx->P, &ctx->Q, &ctx->D,
+    1139                 :            :                                            &ctx->DP, &ctx->DQ, &ctx->QP));
+    1140                 :            : #endif /* MBEDTLS_RSA_NO_CRT */
+    1141                 :            : 
+    1142                 :            :     /* Double-check */
+    1143         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_rsa_check_privkey(ctx));
+    1144                 :            : 
+    1145                 :          0 : cleanup:
+    1146                 :            : 
+    1147                 :          0 :     mbedtls_mpi_free(&H);
+    1148                 :          0 :     mbedtls_mpi_free(&G);
+    1149                 :          0 :     mbedtls_mpi_free(&L);
+    1150                 :            : 
+    1151         [ #  # ]:          0 :     if (ret != 0) {
+    1152                 :          0 :         mbedtls_rsa_free(ctx);
+    1153                 :            : 
+    1154         [ #  # ]:          0 :         if ((-ret & ~0x7f) == 0) {
+    1155                 :          0 :             ret = MBEDTLS_ERROR_ADD(MBEDTLS_ERR_RSA_KEY_GEN_FAILED, ret);
+    1156                 :            :         }
+    1157                 :          0 :         return ret;
+    1158                 :            :     }
+    1159                 :            : 
+    1160                 :          0 :     return 0;
+    1161                 :            : }
+    1162                 :            : 
+    1163                 :            : #endif /* MBEDTLS_GENPRIME */
+    1164                 :            : 
+    1165                 :            : /*
+    1166                 :            :  * Check a public RSA key
+    1167                 :            :  */
+    1168                 :       1122 : int mbedtls_rsa_check_pubkey(const mbedtls_rsa_context *ctx)
+    1169                 :            : {
+    1170         [ -  + ]:       1122 :     if (rsa_check_context(ctx, 0 /* public */, 0 /* no blinding */) != 0) {
+    1171                 :          0 :         return MBEDTLS_ERR_RSA_KEY_CHECK_FAILED;
+    1172                 :            :     }
+    1173                 :            : 
+    1174         [ -  + ]:       1122 :     if (mbedtls_mpi_bitlen(&ctx->N) < 128) {
+    1175                 :          0 :         return MBEDTLS_ERR_RSA_KEY_CHECK_FAILED;
+    1176                 :            :     }
+    1177                 :            : 
+    1178   [ +  -  +  - ]:       2244 :     if (mbedtls_mpi_get_bit(&ctx->E, 0) == 0 ||
+    1179         [ -  + ]:       2244 :         mbedtls_mpi_bitlen(&ctx->E)     < 2  ||
+    1180                 :       1122 :         mbedtls_mpi_cmp_mpi(&ctx->E, &ctx->N) >= 0) {
+    1181                 :          0 :         return MBEDTLS_ERR_RSA_KEY_CHECK_FAILED;
+    1182                 :            :     }
+    1183                 :            : 
+    1184                 :       1122 :     return 0;
+    1185                 :            : }
+    1186                 :            : 
+    1187                 :            : /*
+    1188                 :            :  * Check for the consistency of all fields in an RSA private key context
+    1189                 :            :  */
+    1190                 :          0 : int mbedtls_rsa_check_privkey(const mbedtls_rsa_context *ctx)
+    1191                 :            : {
+    1192   [ #  #  #  # ]:          0 :     if (mbedtls_rsa_check_pubkey(ctx) != 0 ||
+    1193                 :          0 :         rsa_check_context(ctx, 1 /* private */, 1 /* blinding */) != 0) {
+    1194                 :          0 :         return MBEDTLS_ERR_RSA_KEY_CHECK_FAILED;
+    1195                 :            :     }
+    1196                 :            : 
+    1197         [ #  # ]:          0 :     if (mbedtls_rsa_validate_params(&ctx->N, &ctx->P, &ctx->Q,
+    1198                 :            :                                     &ctx->D, &ctx->E, NULL, NULL) != 0) {
+    1199                 :          0 :         return MBEDTLS_ERR_RSA_KEY_CHECK_FAILED;
+    1200                 :            :     }
+    1201                 :            : 
+    1202                 :            : #if !defined(MBEDTLS_RSA_NO_CRT)
+    1203         [ #  # ]:          0 :     else if (mbedtls_rsa_validate_crt(&ctx->P, &ctx->Q, &ctx->D,
+    1204                 :            :                                       &ctx->DP, &ctx->DQ, &ctx->QP) != 0) {
+    1205                 :          0 :         return MBEDTLS_ERR_RSA_KEY_CHECK_FAILED;
+    1206                 :            :     }
+    1207                 :            : #endif
+    1208                 :            : 
+    1209                 :          0 :     return 0;
+    1210                 :            : }
+    1211                 :            : 
+    1212                 :            : /*
+    1213                 :            :  * Check if contexts holding a public and private key match
+    1214                 :            :  */
+    1215                 :          0 : int mbedtls_rsa_check_pub_priv(const mbedtls_rsa_context *pub,
+    1216                 :            :                                const mbedtls_rsa_context *prv)
+    1217                 :            : {
+    1218   [ #  #  #  # ]:          0 :     if (mbedtls_rsa_check_pubkey(pub)  != 0 ||
+    1219                 :          0 :         mbedtls_rsa_check_privkey(prv) != 0) {
+    1220                 :          0 :         return MBEDTLS_ERR_RSA_KEY_CHECK_FAILED;
+    1221                 :            :     }
+    1222                 :            : 
+    1223   [ #  #  #  # ]:          0 :     if (mbedtls_mpi_cmp_mpi(&pub->N, &prv->N) != 0 ||
+    1224                 :          0 :         mbedtls_mpi_cmp_mpi(&pub->E, &prv->E) != 0) {
+    1225                 :          0 :         return MBEDTLS_ERR_RSA_KEY_CHECK_FAILED;
+    1226                 :            :     }
+    1227                 :            : 
+    1228                 :          0 :     return 0;
+    1229                 :            : }
+    1230                 :            : 
+    1231                 :            : /*
+    1232                 :            :  * Do an RSA public key operation
+    1233                 :            :  */
+    1234                 :        302 : int mbedtls_rsa_public(mbedtls_rsa_context *ctx,
+    1235                 :            :                        const unsigned char *input,
+    1236                 :            :                        unsigned char *output)
+    1237                 :            : {
+    1238                 :        302 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1239                 :            :     size_t olen;
+    1240                 :            :     mbedtls_mpi T;
+    1241                 :            : 
+    1242         [ -  + ]:        302 :     if (rsa_check_context(ctx, 0 /* public */, 0 /* no blinding */)) {
+    1243                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    1244                 :            :     }
+    1245                 :            : 
+    1246                 :        302 :     mbedtls_mpi_init(&T);
+    1247                 :            : 
+    1248                 :            : #if defined(MBEDTLS_THREADING_C)
+    1249                 :            :     if ((ret = mbedtls_mutex_lock(&ctx->mutex)) != 0) {
+    1250                 :            :         return ret;
+    1251                 :            :     }
+    1252                 :            : #endif
+    1253                 :            : 
+    1254         [ -  + ]:        302 :     MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&T, input, ctx->len));
+    1255                 :            : 
+    1256         [ -  + ]:        302 :     if (mbedtls_mpi_cmp_mpi(&T, &ctx->N) >= 0) {
+    1257                 :          0 :         ret = MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
+    1258                 :          0 :         goto cleanup;
+    1259                 :            :     }
+    1260                 :            : 
+    1261                 :        302 :     olen = ctx->len;
+    1262         [ -  + ]:        302 :     MBEDTLS_MPI_CHK(mbedtls_mpi_exp_mod(&T, &T, &ctx->E, &ctx->N, &ctx->RN));
+    1263         [ +  - ]:        302 :     MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(&T, output, olen));
+    1264                 :            : 
+    1265                 :        302 : cleanup:
+    1266                 :            : #if defined(MBEDTLS_THREADING_C)
+    1267                 :            :     if (mbedtls_mutex_unlock(&ctx->mutex) != 0) {
+    1268                 :            :         return MBEDTLS_ERR_THREADING_MUTEX_ERROR;
+    1269                 :            :     }
+    1270                 :            : #endif
+    1271                 :            : 
+    1272                 :        302 :     mbedtls_mpi_free(&T);
+    1273                 :            : 
+    1274         [ -  + ]:        302 :     if (ret != 0) {
+    1275                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_RSA_PUBLIC_FAILED, ret);
+    1276                 :            :     }
+    1277                 :            : 
+    1278                 :        302 :     return 0;
+    1279                 :            : }
+    1280                 :            : 
+    1281                 :            : /*
+    1282                 :            :  * Generate or update blinding values, see section 10 of:
+    1283                 :            :  *  KOCHER, Paul C. Timing attacks on implementations of Diffie-Hellman, RSA,
+    1284                 :            :  *  DSS, and other systems. In : Advances in Cryptology-CRYPTO'96. Springer
+    1285                 :            :  *  Berlin Heidelberg, 1996. p. 104-113.
+    1286                 :            :  */
+    1287                 :         27 : static int rsa_prepare_blinding(mbedtls_rsa_context *ctx,
+    1288                 :            :                                 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
+    1289                 :            : {
+    1290                 :         27 :     int ret, count = 0;
+    1291                 :            :     mbedtls_mpi R;
+    1292                 :            : 
+    1293                 :         27 :     mbedtls_mpi_init(&R);
+    1294                 :            : 
+    1295         [ -  + ]:         27 :     if (ctx->Vf.p != NULL) {
+    1296                 :            :         /* We already have blinding values, just update them by squaring */
+    1297         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&ctx->Vi, &ctx->Vi, &ctx->Vi));
+    1298         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&ctx->Vi, &ctx->Vi, &ctx->N));
+    1299         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&ctx->Vf, &ctx->Vf, &ctx->Vf));
+    1300         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&ctx->Vf, &ctx->Vf, &ctx->N));
+    1301                 :            : 
+    1302                 :          0 :         goto cleanup;
+    1303                 :            :     }
+    1304                 :            : 
+    1305                 :            :     /* Unblinding value: Vf = random number, invertible mod N */
+    1306                 :            :     do {
+    1307         [ -  + ]:         27 :         if (count++ > 10) {
+    1308                 :          0 :             ret = MBEDTLS_ERR_RSA_RNG_FAILED;
+    1309                 :          0 :             goto cleanup;
+    1310                 :            :         }
+    1311                 :            : 
+    1312         [ -  + ]:         27 :         MBEDTLS_MPI_CHK(mbedtls_mpi_fill_random(&ctx->Vf, ctx->len - 1, f_rng, p_rng));
+    1313                 :            : 
+    1314                 :            :         /* Compute Vf^-1 as R * (R Vf)^-1 to avoid leaks from inv_mod. */
+    1315         [ -  + ]:         27 :         MBEDTLS_MPI_CHK(mbedtls_mpi_fill_random(&R, ctx->len - 1, f_rng, p_rng));
+    1316         [ -  + ]:         27 :         MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&ctx->Vi, &ctx->Vf, &R));
+    1317         [ -  + ]:         27 :         MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&ctx->Vi, &ctx->Vi, &ctx->N));
+    1318                 :            : 
+    1319                 :            :         /* At this point, Vi is invertible mod N if and only if both Vf and R
+    1320                 :            :          * are invertible mod N. If one of them isn't, we don't need to know
+    1321                 :            :          * which one, we just loop and choose new values for both of them.
+    1322                 :            :          * (Each iteration succeeds with overwhelming probability.) */
+    1323                 :         27 :         ret = mbedtls_mpi_inv_mod(&ctx->Vi, &ctx->Vi, &ctx->N);
+    1324   [ -  +  -  - ]:         27 :         if (ret != 0 && ret != MBEDTLS_ERR_MPI_NOT_ACCEPTABLE) {
+    1325                 :          0 :             goto cleanup;
+    1326                 :            :         }
+    1327                 :            : 
+    1328         [ -  + ]:         27 :     } while (ret == MBEDTLS_ERR_MPI_NOT_ACCEPTABLE);
+    1329                 :            : 
+    1330                 :            :     /* Finish the computation of Vf^-1 = R * (R Vf)^-1 */
+    1331         [ -  + ]:         27 :     MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&ctx->Vi, &ctx->Vi, &R));
+    1332         [ -  + ]:         27 :     MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&ctx->Vi, &ctx->Vi, &ctx->N));
+    1333                 :            : 
+    1334                 :            :     /* Blinding value: Vi = Vf^(-e) mod N
+    1335                 :            :      * (Vi already contains Vf^-1 at this point) */
+    1336         [ +  - ]:         27 :     MBEDTLS_MPI_CHK(mbedtls_mpi_exp_mod(&ctx->Vi, &ctx->Vi, &ctx->E, &ctx->N, &ctx->RN));
+    1337                 :            : 
+    1338                 :            : 
+    1339                 :         27 : cleanup:
+    1340                 :         27 :     mbedtls_mpi_free(&R);
+    1341                 :            : 
+    1342                 :         27 :     return ret;
+    1343                 :            : }
+    1344                 :            : 
+    1345                 :            : /*
+    1346                 :            :  * Unblind
+    1347                 :            :  * T = T * Vf mod N
+    1348                 :            :  */
+    1349                 :         27 : static int rsa_unblind(mbedtls_mpi *T, mbedtls_mpi *Vf, const mbedtls_mpi *N)
+    1350                 :            : {
+    1351                 :         27 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1352                 :         27 :     const mbedtls_mpi_uint mm = mbedtls_mpi_core_montmul_init(N->p);
+    1353                 :         27 :     const size_t nlimbs = N->n;
+    1354                 :         27 :     const size_t tlimbs = mbedtls_mpi_core_montmul_working_limbs(nlimbs);
+    1355                 :            :     mbedtls_mpi RR, M_T;
+    1356                 :            : 
+    1357                 :         27 :     mbedtls_mpi_init(&RR);
+    1358                 :         27 :     mbedtls_mpi_init(&M_T);
+    1359                 :            : 
+    1360         [ -  + ]:         27 :     MBEDTLS_MPI_CHK(mbedtls_mpi_core_get_mont_r2_unsafe(&RR, N));
+    1361         [ -  + ]:         27 :     MBEDTLS_MPI_CHK(mbedtls_mpi_grow(&M_T, tlimbs));
+    1362                 :            : 
+    1363         [ -  + ]:         27 :     MBEDTLS_MPI_CHK(mbedtls_mpi_grow(T, nlimbs));
+    1364         [ -  + ]:         27 :     MBEDTLS_MPI_CHK(mbedtls_mpi_grow(Vf, nlimbs));
+    1365                 :            : 
+    1366                 :            :     /* T = T * Vf mod N
+    1367                 :            :      * Reminder: montmul(A, B, N) = A * B * R^-1 mod N
+    1368                 :            :      * Usually both operands are multiplied by R mod N beforehand (by calling
+    1369                 :            :      * `to_mont_rep()` on them), yielding a result that's also * R mod N (aka
+    1370                 :            :      * "in the Montgomery domain"). Here we only multiply one operand by R mod
+    1371                 :            :      * N, so the result is directly what we want - no need to call
+    1372                 :            :      * `from_mont_rep()` on it. */
+    1373                 :         27 :     mbedtls_mpi_core_to_mont_rep(T->p, T->p, N->p, nlimbs, mm, RR.p, M_T.p);
+    1374                 :         27 :     mbedtls_mpi_core_montmul(T->p, T->p, Vf->p, nlimbs, N->p, nlimbs, mm, M_T.p);
+    1375                 :            : 
+    1376                 :         27 : cleanup:
+    1377                 :            : 
+    1378                 :         27 :     mbedtls_mpi_free(&RR);
+    1379                 :         27 :     mbedtls_mpi_free(&M_T);
+    1380                 :            : 
+    1381                 :         27 :     return ret;
+    1382                 :            : }
+    1383                 :            : 
+    1384                 :            : /*
+    1385                 :            :  * Exponent blinding supposed to prevent side-channel attacks using multiple
+    1386                 :            :  * traces of measurements to recover the RSA key. The more collisions are there,
+    1387                 :            :  * the more bits of the key can be recovered. See [3].
+    1388                 :            :  *
+    1389                 :            :  * Collecting n collisions with m bit long blinding value requires 2^(m-m/n)
+    1390                 :            :  * observations on average.
+    1391                 :            :  *
+    1392                 :            :  * For example with 28 byte blinding to achieve 2 collisions the adversary has
+    1393                 :            :  * to make 2^112 observations on average.
+    1394                 :            :  *
+    1395                 :            :  * (With the currently (as of 2017 April) known best algorithms breaking 2048
+    1396                 :            :  * bit RSA requires approximately as much time as trying out 2^112 random keys.
+    1397                 :            :  * Thus in this sense with 28 byte blinding the security is not reduced by
+    1398                 :            :  * side-channel attacks like the one in [3])
+    1399                 :            :  *
+    1400                 :            :  * This countermeasure does not help if the key recovery is possible with a
+    1401                 :            :  * single trace.
+    1402                 :            :  */
+    1403                 :            : #define RSA_EXPONENT_BLINDING 28
+    1404                 :            : 
+    1405                 :            : /*
+    1406                 :            :  * Do an RSA private key operation
+    1407                 :            :  */
+    1408                 :         27 : int mbedtls_rsa_private(mbedtls_rsa_context *ctx,
+    1409                 :            :                         int (*f_rng)(void *, unsigned char *, size_t),
+    1410                 :            :                         void *p_rng,
+    1411                 :            :                         const unsigned char *input,
+    1412                 :            :                         unsigned char *output)
+    1413                 :            : {
+    1414                 :         27 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1415                 :            :     size_t olen;
+    1416                 :            : 
+    1417                 :            :     /* Temporary holding the result */
+    1418                 :            :     mbedtls_mpi T;
+    1419                 :            : 
+    1420                 :            :     /* Temporaries holding P-1, Q-1 and the
+    1421                 :            :      * exponent blinding factor, respectively. */
+    1422                 :            :     mbedtls_mpi P1, Q1, R;
+    1423                 :            : 
+    1424                 :            : #if !defined(MBEDTLS_RSA_NO_CRT)
+    1425                 :            :     /* Temporaries holding the results mod p resp. mod q. */
+    1426                 :            :     mbedtls_mpi TP, TQ;
+    1427                 :            : 
+    1428                 :            :     /* Temporaries holding the blinded exponents for
+    1429                 :            :      * the mod p resp. mod q computation (if used). */
+    1430                 :            :     mbedtls_mpi DP_blind, DQ_blind;
+    1431                 :            : #else
+    1432                 :            :     /* Temporary holding the blinded exponent (if used). */
+    1433                 :            :     mbedtls_mpi D_blind;
+    1434                 :            : #endif /* MBEDTLS_RSA_NO_CRT */
+    1435                 :            : 
+    1436                 :            :     /* Temporaries holding the initial input and the double
+    1437                 :            :      * checked result; should be the same in the end. */
+    1438                 :            :     mbedtls_mpi input_blinded, check_result_blinded;
+    1439                 :            : 
+    1440         [ -  + ]:         27 :     if (f_rng == NULL) {
+    1441                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    1442                 :            :     }
+    1443                 :            : 
+    1444         [ -  + ]:         27 :     if (rsa_check_context(ctx, 1 /* private key checks */,
+    1445                 :            :                           1 /* blinding on        */) != 0) {
+    1446                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    1447                 :            :     }
+    1448                 :            : 
+    1449                 :            : #if defined(MBEDTLS_THREADING_C)
+    1450                 :            :     if ((ret = mbedtls_mutex_lock(&ctx->mutex)) != 0) {
+    1451                 :            :         return ret;
+    1452                 :            :     }
+    1453                 :            : #endif
+    1454                 :            : 
+    1455                 :            :     /* MPI Initialization */
+    1456                 :         27 :     mbedtls_mpi_init(&T);
+    1457                 :            : 
+    1458                 :         27 :     mbedtls_mpi_init(&P1);
+    1459                 :         27 :     mbedtls_mpi_init(&Q1);
+    1460                 :         27 :     mbedtls_mpi_init(&R);
+    1461                 :            : 
+    1462                 :            : #if defined(MBEDTLS_RSA_NO_CRT)
+    1463                 :            :     mbedtls_mpi_init(&D_blind);
+    1464                 :            : #else
+    1465                 :         27 :     mbedtls_mpi_init(&DP_blind);
+    1466                 :         27 :     mbedtls_mpi_init(&DQ_blind);
+    1467                 :            : #endif
+    1468                 :            : 
+    1469                 :            : #if !defined(MBEDTLS_RSA_NO_CRT)
+    1470                 :         27 :     mbedtls_mpi_init(&TP); mbedtls_mpi_init(&TQ);
+    1471                 :            : #endif
+    1472                 :            : 
+    1473                 :         27 :     mbedtls_mpi_init(&input_blinded);
+    1474                 :         27 :     mbedtls_mpi_init(&check_result_blinded);
+    1475                 :            : 
+    1476                 :            :     /* End of MPI initialization */
+    1477                 :            : 
+    1478         [ -  + ]:         27 :     MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&T, input, ctx->len));
+    1479         [ -  + ]:         27 :     if (mbedtls_mpi_cmp_mpi(&T, &ctx->N) >= 0) {
+    1480                 :          0 :         ret = MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
+    1481                 :          0 :         goto cleanup;
+    1482                 :            :     }
+    1483                 :            : 
+    1484                 :            :     /*
+    1485                 :            :      * Blinding
+    1486                 :            :      * T = T * Vi mod N
+    1487                 :            :      */
+    1488         [ -  + ]:         27 :     MBEDTLS_MPI_CHK(rsa_prepare_blinding(ctx, f_rng, p_rng));
+    1489         [ -  + ]:         27 :     MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&T, &T, &ctx->Vi));
+    1490         [ -  + ]:         27 :     MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&T, &T, &ctx->N));
+    1491                 :            : 
+    1492         [ -  + ]:         27 :     MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&input_blinded, &T));
+    1493                 :            : 
+    1494                 :            :     /*
+    1495                 :            :      * Exponent blinding
+    1496                 :            :      */
+    1497         [ -  + ]:         27 :     MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&P1, &ctx->P, 1));
+    1498         [ -  + ]:         27 :     MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&Q1, &ctx->Q, 1));
+    1499                 :            : 
+    1500                 :            : #if defined(MBEDTLS_RSA_NO_CRT)
+    1501                 :            :     /*
+    1502                 :            :      * D_blind = ( P - 1 ) * ( Q - 1 ) * R + D
+    1503                 :            :      */
+    1504                 :            :     MBEDTLS_MPI_CHK(mbedtls_mpi_fill_random(&R, RSA_EXPONENT_BLINDING,
+    1505                 :            :                                             f_rng, p_rng));
+    1506                 :            :     MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&D_blind, &P1, &Q1));
+    1507                 :            :     MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&D_blind, &D_blind, &R));
+    1508                 :            :     MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&D_blind, &D_blind, &ctx->D));
+    1509                 :            : #else
+    1510                 :            :     /*
+    1511                 :            :      * DP_blind = ( P - 1 ) * R + DP
+    1512                 :            :      */
+    1513         [ -  + ]:         27 :     MBEDTLS_MPI_CHK(mbedtls_mpi_fill_random(&R, RSA_EXPONENT_BLINDING,
+    1514                 :            :                                             f_rng, p_rng));
+    1515         [ -  + ]:         27 :     MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&DP_blind, &P1, &R));
+    1516         [ -  + ]:         27 :     MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&DP_blind, &DP_blind,
+    1517                 :            :                                         &ctx->DP));
+    1518                 :            : 
+    1519                 :            :     /*
+    1520                 :            :      * DQ_blind = ( Q - 1 ) * R + DQ
+    1521                 :            :      */
+    1522         [ -  + ]:         27 :     MBEDTLS_MPI_CHK(mbedtls_mpi_fill_random(&R, RSA_EXPONENT_BLINDING,
+    1523                 :            :                                             f_rng, p_rng));
+    1524         [ -  + ]:         27 :     MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&DQ_blind, &Q1, &R));
+    1525         [ -  + ]:         27 :     MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&DQ_blind, &DQ_blind,
+    1526                 :            :                                         &ctx->DQ));
+    1527                 :            : #endif /* MBEDTLS_RSA_NO_CRT */
+    1528                 :            : 
+    1529                 :            : #if defined(MBEDTLS_RSA_NO_CRT)
+    1530                 :            :     MBEDTLS_MPI_CHK(mbedtls_mpi_exp_mod(&T, &T, &D_blind, &ctx->N, &ctx->RN));
+    1531                 :            : #else
+    1532                 :            :     /*
+    1533                 :            :      * Faster decryption using the CRT
+    1534                 :            :      *
+    1535                 :            :      * TP = input ^ dP mod P
+    1536                 :            :      * TQ = input ^ dQ mod Q
+    1537                 :            :      */
+    1538                 :            : 
+    1539         [ -  + ]:         27 :     MBEDTLS_MPI_CHK(mbedtls_mpi_exp_mod(&TP, &T, &DP_blind, &ctx->P, &ctx->RP));
+    1540         [ -  + ]:         27 :     MBEDTLS_MPI_CHK(mbedtls_mpi_exp_mod(&TQ, &T, &DQ_blind, &ctx->Q, &ctx->RQ));
+    1541                 :            : 
+    1542                 :            :     /*
+    1543                 :            :      * T = (TP - TQ) * (Q^-1 mod P) mod P
+    1544                 :            :      */
+    1545         [ -  + ]:         27 :     MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&T, &TP, &TQ));
+    1546         [ -  + ]:         27 :     MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&TP, &T, &ctx->QP));
+    1547         [ -  + ]:         27 :     MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&T, &TP, &ctx->P));
+    1548                 :            : 
+    1549                 :            :     /*
+    1550                 :            :      * T = TQ + T * Q
+    1551                 :            :      */
+    1552         [ -  + ]:         27 :     MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&TP, &T, &ctx->Q));
+    1553         [ -  + ]:         27 :     MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&T, &TQ, &TP));
+    1554                 :            : #endif /* MBEDTLS_RSA_NO_CRT */
+    1555                 :            : 
+    1556                 :            :     /* Verify the result to prevent glitching attacks. */
+    1557         [ -  + ]:         27 :     MBEDTLS_MPI_CHK(mbedtls_mpi_exp_mod(&check_result_blinded, &T, &ctx->E,
+    1558                 :            :                                         &ctx->N, &ctx->RN));
+    1559         [ -  + ]:         27 :     if (mbedtls_mpi_cmp_mpi(&check_result_blinded, &input_blinded) != 0) {
+    1560                 :          0 :         ret = MBEDTLS_ERR_RSA_VERIFY_FAILED;
+    1561                 :          0 :         goto cleanup;
+    1562                 :            :     }
+    1563                 :            : 
+    1564                 :            :     /*
+    1565                 :            :      * Unblind
+    1566                 :            :      * T = T * Vf mod N
+    1567                 :            :      */
+    1568         [ -  + ]:         27 :     MBEDTLS_MPI_CHK(rsa_unblind(&T, &ctx->Vf, &ctx->N));
+    1569                 :            : 
+    1570                 :         27 :     olen = ctx->len;
+    1571         [ +  - ]:         27 :     MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(&T, output, olen));
+    1572                 :            : 
+    1573                 :         27 : cleanup:
+    1574                 :            : #if defined(MBEDTLS_THREADING_C)
+    1575                 :            :     if (mbedtls_mutex_unlock(&ctx->mutex) != 0) {
+    1576                 :            :         return MBEDTLS_ERR_THREADING_MUTEX_ERROR;
+    1577                 :            :     }
+    1578                 :            : #endif
+    1579                 :            : 
+    1580                 :         27 :     mbedtls_mpi_free(&P1);
+    1581                 :         27 :     mbedtls_mpi_free(&Q1);
+    1582                 :         27 :     mbedtls_mpi_free(&R);
+    1583                 :            : 
+    1584                 :            : #if defined(MBEDTLS_RSA_NO_CRT)
+    1585                 :            :     mbedtls_mpi_free(&D_blind);
+    1586                 :            : #else
+    1587                 :         27 :     mbedtls_mpi_free(&DP_blind);
+    1588                 :         27 :     mbedtls_mpi_free(&DQ_blind);
+    1589                 :            : #endif
+    1590                 :            : 
+    1591                 :         27 :     mbedtls_mpi_free(&T);
+    1592                 :            : 
+    1593                 :            : #if !defined(MBEDTLS_RSA_NO_CRT)
+    1594                 :         27 :     mbedtls_mpi_free(&TP); mbedtls_mpi_free(&TQ);
+    1595                 :            : #endif
+    1596                 :            : 
+    1597                 :         27 :     mbedtls_mpi_free(&check_result_blinded);
+    1598                 :         27 :     mbedtls_mpi_free(&input_blinded);
+    1599                 :            : 
+    1600   [ -  +  -  - ]:         27 :     if (ret != 0 && ret >= -0x007f) {
+    1601                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_RSA_PRIVATE_FAILED, ret);
+    1602                 :            :     }
+    1603                 :            : 
+    1604                 :         27 :     return ret;
+    1605                 :            : }
+    1606                 :            : 
+    1607                 :            : #if defined(MBEDTLS_PKCS1_V21)
+    1608                 :            : /**
+    1609                 :            :  * Generate and apply the MGF1 operation (from PKCS#1 v2.1) to a buffer.
+    1610                 :            :  *
+    1611                 :            :  * \param dst       buffer to mask
+    1612                 :            :  * \param dlen      length of destination buffer
+    1613                 :            :  * \param src       source of the mask generation
+    1614                 :            :  * \param slen      length of the source buffer
+    1615                 :            :  * \param md_alg    message digest to use
+    1616                 :            :  */
+    1617                 :          2 : static int mgf_mask(unsigned char *dst, size_t dlen, unsigned char *src,
+    1618                 :            :                     size_t slen, mbedtls_md_type_t md_alg)
+    1619                 :            : {
+    1620                 :            :     unsigned char counter[4];
+    1621                 :            :     unsigned char *p;
+    1622                 :            :     unsigned int hlen;
+    1623                 :            :     size_t i, use_len;
+    1624                 :            :     unsigned char mask[MBEDTLS_MD_MAX_SIZE];
+    1625                 :          2 :     int ret = 0;
+    1626                 :            :     const mbedtls_md_info_t *md_info;
+    1627                 :            :     mbedtls_md_context_t md_ctx;
+    1628                 :            : 
+    1629                 :          2 :     mbedtls_md_init(&md_ctx);
+    1630                 :          2 :     md_info = mbedtls_md_info_from_type(md_alg);
+    1631         [ -  + ]:          2 :     if (md_info == NULL) {
+    1632                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    1633                 :            :     }
+    1634                 :            : 
+    1635                 :          2 :     mbedtls_md_init(&md_ctx);
+    1636         [ -  + ]:          2 :     if ((ret = mbedtls_md_setup(&md_ctx, md_info, 0)) != 0) {
+    1637                 :          0 :         goto exit;
+    1638                 :            :     }
+    1639                 :            : 
+    1640                 :          2 :     hlen = mbedtls_md_get_size(md_info);
+    1641                 :            : 
+    1642                 :          2 :     memset(mask, 0, sizeof(mask));
+    1643                 :          2 :     memset(counter, 0, 4);
+    1644                 :            : 
+    1645                 :            :     /* Generate and apply dbMask */
+    1646                 :          2 :     p = dst;
+    1647                 :            : 
+    1648         [ +  + ]:         16 :     while (dlen > 0) {
+    1649                 :         14 :         use_len = hlen;
+    1650         [ +  + ]:         14 :         if (dlen < hlen) {
+    1651                 :          2 :             use_len = dlen;
+    1652                 :            :         }
+    1653                 :            : 
+    1654         [ -  + ]:         14 :         if ((ret = mbedtls_md_starts(&md_ctx)) != 0) {
+    1655                 :          0 :             goto exit;
+    1656                 :            :         }
+    1657         [ -  + ]:         14 :         if ((ret = mbedtls_md_update(&md_ctx, src, slen)) != 0) {
+    1658                 :          0 :             goto exit;
+    1659                 :            :         }
+    1660         [ -  + ]:         14 :         if ((ret = mbedtls_md_update(&md_ctx, counter, 4)) != 0) {
+    1661                 :          0 :             goto exit;
+    1662                 :            :         }
+    1663         [ -  + ]:         14 :         if ((ret = mbedtls_md_finish(&md_ctx, mask)) != 0) {
+    1664                 :          0 :             goto exit;
+    1665                 :            :         }
+    1666                 :            : 
+    1667         [ +  + ]:        460 :         for (i = 0; i < use_len; ++i) {
+    1668                 :        446 :             *p++ ^= mask[i];
+    1669                 :            :         }
+    1670                 :            : 
+    1671                 :         14 :         counter[3]++;
+    1672                 :            : 
+    1673                 :         14 :         dlen -= use_len;
+    1674                 :            :     }
+    1675                 :            : 
+    1676                 :          2 : exit:
+    1677                 :          2 :     mbedtls_platform_zeroize(mask, sizeof(mask));
+    1678                 :          2 :     mbedtls_md_free(&md_ctx);
+    1679                 :            : 
+    1680                 :          2 :     return ret;
+    1681                 :            : }
+    1682                 :            : 
+    1683                 :            : /**
+    1684                 :            :  * Generate Hash(M') as in RFC 8017 page 43 points 5 and 6.
+    1685                 :            :  *
+    1686                 :            :  * \param hash      the input hash
+    1687                 :            :  * \param hlen      length of the input hash
+    1688                 :            :  * \param salt      the input salt
+    1689                 :            :  * \param slen      length of the input salt
+    1690                 :            :  * \param out       the output buffer - must be large enough for \p md_alg
+    1691                 :            :  * \param md_alg    message digest to use
+    1692                 :            :  */
+    1693                 :          2 : static int hash_mprime(const unsigned char *hash, size_t hlen,
+    1694                 :            :                        const unsigned char *salt, size_t slen,
+    1695                 :            :                        unsigned char *out, mbedtls_md_type_t md_alg)
+    1696                 :            : {
+    1697                 :          2 :     const unsigned char zeros[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
+    1698                 :            : 
+    1699                 :            :     mbedtls_md_context_t md_ctx;
+    1700                 :          2 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1701                 :            : 
+    1702                 :          2 :     const mbedtls_md_info_t *md_info = mbedtls_md_info_from_type(md_alg);
+    1703         [ -  + ]:          2 :     if (md_info == NULL) {
+    1704                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    1705                 :            :     }
+    1706                 :            : 
+    1707                 :          2 :     mbedtls_md_init(&md_ctx);
+    1708         [ -  + ]:          2 :     if ((ret = mbedtls_md_setup(&md_ctx, md_info, 0)) != 0) {
+    1709                 :          0 :         goto exit;
+    1710                 :            :     }
+    1711         [ -  + ]:          2 :     if ((ret = mbedtls_md_starts(&md_ctx)) != 0) {
+    1712                 :          0 :         goto exit;
+    1713                 :            :     }
+    1714         [ -  + ]:          2 :     if ((ret = mbedtls_md_update(&md_ctx, zeros, sizeof(zeros))) != 0) {
+    1715                 :          0 :         goto exit;
+    1716                 :            :     }
+    1717         [ -  + ]:          2 :     if ((ret = mbedtls_md_update(&md_ctx, hash, hlen)) != 0) {
+    1718                 :          0 :         goto exit;
+    1719                 :            :     }
+    1720         [ -  + ]:          2 :     if ((ret = mbedtls_md_update(&md_ctx, salt, slen)) != 0) {
+    1721                 :          0 :         goto exit;
+    1722                 :            :     }
+    1723         [ +  - ]:          2 :     if ((ret = mbedtls_md_finish(&md_ctx, out)) != 0) {
+    1724                 :          0 :         goto exit;
+    1725                 :            :     }
+    1726                 :            : 
+    1727                 :          2 : exit:
+    1728                 :          2 :     mbedtls_md_free(&md_ctx);
+    1729                 :            : 
+    1730                 :          2 :     return ret;
+    1731                 :            : }
+    1732                 :            : 
+    1733                 :            : /**
+    1734                 :            :  * Compute a hash.
+    1735                 :            :  *
+    1736                 :            :  * \param md_alg    algorithm to use
+    1737                 :            :  * \param input     input message to hash
+    1738                 :            :  * \param ilen      input length
+    1739                 :            :  * \param output    the output buffer - must be large enough for \p md_alg
+    1740                 :            :  */
+    1741                 :          0 : static int compute_hash(mbedtls_md_type_t md_alg,
+    1742                 :            :                         const unsigned char *input, size_t ilen,
+    1743                 :            :                         unsigned char *output)
+    1744                 :            : {
+    1745                 :            :     const mbedtls_md_info_t *md_info;
+    1746                 :            : 
+    1747                 :          0 :     md_info = mbedtls_md_info_from_type(md_alg);
+    1748         [ #  # ]:          0 :     if (md_info == NULL) {
+    1749                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    1750                 :            :     }
+    1751                 :            : 
+    1752                 :          0 :     return mbedtls_md(md_info, input, ilen, output);
+    1753                 :            : }
+    1754                 :            : #endif /* MBEDTLS_PKCS1_V21 */
+    1755                 :            : 
+    1756                 :            : #if defined(MBEDTLS_PKCS1_V21)
+    1757                 :            : /*
+    1758                 :            :  * Implementation of the PKCS#1 v2.1 RSAES-OAEP-ENCRYPT function
+    1759                 :            :  */
+    1760                 :          0 : int mbedtls_rsa_rsaes_oaep_encrypt(mbedtls_rsa_context *ctx,
+    1761                 :            :                                    int (*f_rng)(void *, unsigned char *, size_t),
+    1762                 :            :                                    void *p_rng,
+    1763                 :            :                                    const unsigned char *label, size_t label_len,
+    1764                 :            :                                    size_t ilen,
+    1765                 :            :                                    const unsigned char *input,
+    1766                 :            :                                    unsigned char *output)
+    1767                 :            : {
+    1768                 :            :     size_t olen;
+    1769                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1770                 :          0 :     unsigned char *p = output;
+    1771                 :            :     unsigned int hlen;
+    1772                 :            : 
+    1773         [ #  # ]:          0 :     if (f_rng == NULL) {
+    1774                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    1775                 :            :     }
+    1776                 :            : 
+    1777                 :          0 :     hlen = mbedtls_md_get_size_from_type((mbedtls_md_type_t) ctx->hash_id);
+    1778         [ #  # ]:          0 :     if (hlen == 0) {
+    1779                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    1780                 :            :     }
+    1781                 :            : 
+    1782                 :          0 :     olen = ctx->len;
+    1783                 :            : 
+    1784                 :            :     /* first comparison checks for overflow */
+    1785   [ #  #  #  # ]:          0 :     if (ilen + 2 * hlen + 2 < ilen || olen < ilen + 2 * hlen + 2) {
+    1786                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    1787                 :            :     }
+    1788                 :            : 
+    1789                 :          0 :     memset(output, 0, olen);
+    1790                 :            : 
+    1791                 :          0 :     *p++ = 0;
+    1792                 :            : 
+    1793                 :            :     /* Generate a random octet string seed */
+    1794         [ #  # ]:          0 :     if ((ret = f_rng(p_rng, p, hlen)) != 0) {
+    1795                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_RSA_RNG_FAILED, ret);
+    1796                 :            :     }
+    1797                 :            : 
+    1798                 :          0 :     p += hlen;
+    1799                 :            : 
+    1800                 :            :     /* Construct DB */
+    1801                 :          0 :     ret = compute_hash((mbedtls_md_type_t) ctx->hash_id, label, label_len, p);
+    1802         [ #  # ]:          0 :     if (ret != 0) {
+    1803                 :          0 :         return ret;
+    1804                 :            :     }
+    1805                 :          0 :     p += hlen;
+    1806                 :          0 :     p += olen - 2 * hlen - 2 - ilen;
+    1807                 :          0 :     *p++ = 1;
+    1808         [ #  # ]:          0 :     if (ilen != 0) {
+    1809                 :          0 :         memcpy(p, input, ilen);
+    1810                 :            :     }
+    1811                 :            : 
+    1812                 :            :     /* maskedDB: Apply dbMask to DB */
+    1813         [ #  # ]:          0 :     if ((ret = mgf_mask(output + hlen + 1, olen - hlen - 1, output + 1, hlen,
+    1814                 :          0 :                         (mbedtls_md_type_t) ctx->hash_id)) != 0) {
+    1815                 :          0 :         return ret;
+    1816                 :            :     }
+    1817                 :            : 
+    1818                 :            :     /* maskedSeed: Apply seedMask to seed */
+    1819         [ #  # ]:          0 :     if ((ret = mgf_mask(output + 1, hlen, output + hlen + 1, olen - hlen - 1,
+    1820                 :          0 :                         (mbedtls_md_type_t) ctx->hash_id)) != 0) {
+    1821                 :          0 :         return ret;
+    1822                 :            :     }
+    1823                 :            : 
+    1824                 :          0 :     return mbedtls_rsa_public(ctx, output, output);
+    1825                 :            : }
+    1826                 :            : #endif /* MBEDTLS_PKCS1_V21 */
+    1827                 :            : 
+    1828                 :            : #if defined(MBEDTLS_PKCS1_V15)
+    1829                 :            : /*
+    1830                 :            :  * Implementation of the PKCS#1 v2.1 RSAES-PKCS1-V1_5-ENCRYPT function
+    1831                 :            :  */
+    1832                 :          0 : int mbedtls_rsa_rsaes_pkcs1_v15_encrypt(mbedtls_rsa_context *ctx,
+    1833                 :            :                                         int (*f_rng)(void *, unsigned char *, size_t),
+    1834                 :            :                                         void *p_rng, size_t ilen,
+    1835                 :            :                                         const unsigned char *input,
+    1836                 :            :                                         unsigned char *output)
+    1837                 :            : {
+    1838                 :            :     size_t nb_pad, olen;
+    1839                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1840                 :          0 :     unsigned char *p = output;
+    1841                 :            : 
+    1842                 :          0 :     olen = ctx->len;
+    1843                 :            : 
+    1844                 :            :     /* first comparison checks for overflow */
+    1845   [ #  #  #  # ]:          0 :     if (ilen + 11 < ilen || olen < ilen + 11) {
+    1846                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    1847                 :            :     }
+    1848                 :            : 
+    1849                 :          0 :     nb_pad = olen - 3 - ilen;
+    1850                 :            : 
+    1851                 :          0 :     *p++ = 0;
+    1852                 :            : 
+    1853         [ #  # ]:          0 :     if (f_rng == NULL) {
+    1854                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    1855                 :            :     }
+    1856                 :            : 
+    1857                 :          0 :     *p++ = MBEDTLS_RSA_CRYPT;
+    1858                 :            : 
+    1859         [ #  # ]:          0 :     while (nb_pad-- > 0) {
+    1860                 :          0 :         int rng_dl = 100;
+    1861                 :            : 
+    1862                 :            :         do {
+    1863                 :          0 :             ret = f_rng(p_rng, p, 1);
+    1864   [ #  #  #  #  :          0 :         } while (*p == 0 && --rng_dl && ret == 0);
+                   #  # ]
+    1865                 :            : 
+    1866                 :            :         /* Check if RNG failed to generate data */
+    1867   [ #  #  #  # ]:          0 :         if (rng_dl == 0 || ret != 0) {
+    1868                 :          0 :             return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_RSA_RNG_FAILED, ret);
+    1869                 :            :         }
+    1870                 :            : 
+    1871                 :          0 :         p++;
+    1872                 :            :     }
+    1873                 :            : 
+    1874                 :          0 :     *p++ = 0;
+    1875         [ #  # ]:          0 :     if (ilen != 0) {
+    1876                 :          0 :         memcpy(p, input, ilen);
+    1877                 :            :     }
+    1878                 :            : 
+    1879                 :          0 :     return mbedtls_rsa_public(ctx, output, output);
+    1880                 :            : }
+    1881                 :            : #endif /* MBEDTLS_PKCS1_V15 */
+    1882                 :            : 
+    1883                 :            : /*
+    1884                 :            :  * Add the message padding, then do an RSA operation
+    1885                 :            :  */
+    1886                 :          0 : int mbedtls_rsa_pkcs1_encrypt(mbedtls_rsa_context *ctx,
+    1887                 :            :                               int (*f_rng)(void *, unsigned char *, size_t),
+    1888                 :            :                               void *p_rng,
+    1889                 :            :                               size_t ilen,
+    1890                 :            :                               const unsigned char *input,
+    1891                 :            :                               unsigned char *output)
+    1892                 :            : {
+    1893      [ #  #  # ]:          0 :     switch (ctx->padding) {
+    1894                 :            : #if defined(MBEDTLS_PKCS1_V15)
+    1895                 :          0 :         case MBEDTLS_RSA_PKCS_V15:
+    1896                 :          0 :             return mbedtls_rsa_rsaes_pkcs1_v15_encrypt(ctx, f_rng, p_rng,
+    1897                 :            :                                                        ilen, input, output);
+    1898                 :            : #endif
+    1899                 :            : 
+    1900                 :            : #if defined(MBEDTLS_PKCS1_V21)
+    1901                 :          0 :         case MBEDTLS_RSA_PKCS_V21:
+    1902                 :          0 :             return mbedtls_rsa_rsaes_oaep_encrypt(ctx, f_rng, p_rng, NULL, 0,
+    1903                 :            :                                                   ilen, input, output);
+    1904                 :            : #endif
+    1905                 :            : 
+    1906                 :          0 :         default:
+    1907                 :          0 :             return MBEDTLS_ERR_RSA_INVALID_PADDING;
+    1908                 :            :     }
+    1909                 :            : }
+    1910                 :            : 
+    1911                 :            : #if defined(MBEDTLS_PKCS1_V21)
+    1912                 :            : /*
+    1913                 :            :  * Implementation of the PKCS#1 v2.1 RSAES-OAEP-DECRYPT function
+    1914                 :            :  */
+    1915                 :          0 : int mbedtls_rsa_rsaes_oaep_decrypt(mbedtls_rsa_context *ctx,
+    1916                 :            :                                    int (*f_rng)(void *, unsigned char *, size_t),
+    1917                 :            :                                    void *p_rng,
+    1918                 :            :                                    const unsigned char *label, size_t label_len,
+    1919                 :            :                                    size_t *olen,
+    1920                 :            :                                    const unsigned char *input,
+    1921                 :            :                                    unsigned char *output,
+    1922                 :            :                                    size_t output_max_len)
+    1923                 :            : {
+    1924                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1925                 :            :     size_t ilen, i, pad_len;
+    1926                 :            :     unsigned char *p;
+    1927                 :            :     mbedtls_ct_condition_t bad, in_padding;
+    1928                 :            :     unsigned char buf[MBEDTLS_MPI_MAX_SIZE];
+    1929                 :            :     unsigned char lhash[MBEDTLS_MD_MAX_SIZE];
+    1930                 :            :     unsigned int hlen;
+    1931                 :            : 
+    1932                 :            :     /*
+    1933                 :            :      * Parameters sanity checks
+    1934                 :            :      */
+    1935         [ #  # ]:          0 :     if (ctx->padding != MBEDTLS_RSA_PKCS_V21) {
+    1936                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    1937                 :            :     }
+    1938                 :            : 
+    1939                 :          0 :     ilen = ctx->len;
+    1940                 :            : 
+    1941   [ #  #  #  # ]:          0 :     if (ilen < 16 || ilen > sizeof(buf)) {
+    1942                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    1943                 :            :     }
+    1944                 :            : 
+    1945                 :          0 :     hlen = mbedtls_md_get_size_from_type((mbedtls_md_type_t) ctx->hash_id);
+    1946         [ #  # ]:          0 :     if (hlen == 0) {
+    1947                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    1948                 :            :     }
+    1949                 :            : 
+    1950                 :            :     // checking for integer underflow
+    1951         [ #  # ]:          0 :     if (2 * hlen + 2 > ilen) {
+    1952                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    1953                 :            :     }
+    1954                 :            : 
+    1955                 :            :     /*
+    1956                 :            :      * RSA operation
+    1957                 :            :      */
+    1958                 :          0 :     ret = mbedtls_rsa_private(ctx, f_rng, p_rng, input, buf);
+    1959                 :            : 
+    1960         [ #  # ]:          0 :     if (ret != 0) {
+    1961                 :          0 :         goto cleanup;
+    1962                 :            :     }
+    1963                 :            : 
+    1964                 :            :     /*
+    1965                 :            :      * Unmask data and generate lHash
+    1966                 :            :      */
+    1967                 :            :     /* seed: Apply seedMask to maskedSeed */
+    1968         [ #  # ]:          0 :     if ((ret = mgf_mask(buf + 1, hlen, buf + hlen + 1, ilen - hlen - 1,
+    1969         [ #  # ]:          0 :                         (mbedtls_md_type_t) ctx->hash_id)) != 0 ||
+    1970                 :            :         /* DB: Apply dbMask to maskedDB */
+    1971                 :          0 :         (ret = mgf_mask(buf + hlen + 1, ilen - hlen - 1, buf + 1, hlen,
+    1972                 :          0 :                         (mbedtls_md_type_t) ctx->hash_id)) != 0) {
+    1973                 :          0 :         goto cleanup;
+    1974                 :            :     }
+    1975                 :            : 
+    1976                 :            :     /* Generate lHash */
+    1977                 :          0 :     ret = compute_hash((mbedtls_md_type_t) ctx->hash_id,
+    1978                 :            :                        label, label_len, lhash);
+    1979         [ #  # ]:          0 :     if (ret != 0) {
+    1980                 :          0 :         goto cleanup;
+    1981                 :            :     }
+    1982                 :            : 
+    1983                 :            :     /*
+    1984                 :            :      * Check contents, in "constant-time"
+    1985                 :            :      */
+    1986                 :          0 :     p = buf;
+    1987                 :            : 
+    1988                 :          0 :     bad = mbedtls_ct_bool(*p++); /* First byte must be 0 */
+    1989                 :            : 
+    1990                 :          0 :     p += hlen; /* Skip seed */
+    1991                 :            : 
+    1992                 :            :     /* Check lHash */
+    1993                 :          0 :     bad = mbedtls_ct_bool_or(bad, mbedtls_ct_bool(mbedtls_ct_memcmp(lhash, p, hlen)));
+    1994                 :          0 :     p += hlen;
+    1995                 :            : 
+    1996                 :            :     /* Get zero-padding len, but always read till end of buffer
+    1997                 :            :      * (minus one, for the 01 byte) */
+    1998                 :          0 :     pad_len = 0;
+    1999                 :          0 :     in_padding = MBEDTLS_CT_TRUE;
+    2000         [ #  # ]:          0 :     for (i = 0; i < ilen - 2 * hlen - 2; i++) {
+    2001                 :          0 :         in_padding = mbedtls_ct_bool_and(in_padding, mbedtls_ct_uint_eq(p[i], 0));
+    2002                 :          0 :         pad_len += mbedtls_ct_uint_if_else_0(in_padding, 1);
+    2003                 :            :     }
+    2004                 :            : 
+    2005                 :          0 :     p += pad_len;
+    2006                 :          0 :     bad = mbedtls_ct_bool_or(bad, mbedtls_ct_uint_ne(*p++, 0x01));
+    2007                 :            : 
+    2008                 :            :     /*
+    2009                 :            :      * The only information "leaked" is whether the padding was correct or not
+    2010                 :            :      * (eg, no data is copied if it was not correct). This meets the
+    2011                 :            :      * recommendations in PKCS#1 v2.2: an opponent cannot distinguish between
+    2012                 :            :      * the different error conditions.
+    2013                 :            :      */
+    2014         [ #  # ]:          0 :     if (bad != MBEDTLS_CT_FALSE) {
+    2015                 :          0 :         ret = MBEDTLS_ERR_RSA_INVALID_PADDING;
+    2016                 :          0 :         goto cleanup;
+    2017                 :            :     }
+    2018                 :            : 
+    2019         [ #  # ]:          0 :     if (ilen - ((size_t) (p - buf)) > output_max_len) {
+    2020                 :          0 :         ret = MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE;
+    2021                 :          0 :         goto cleanup;
+    2022                 :            :     }
+    2023                 :            : 
+    2024                 :          0 :     *olen = ilen - ((size_t) (p - buf));
+    2025         [ #  # ]:          0 :     if (*olen != 0) {
+    2026                 :          0 :         memcpy(output, p, *olen);
+    2027                 :            :     }
+    2028                 :          0 :     ret = 0;
+    2029                 :            : 
+    2030                 :          0 : cleanup:
+    2031                 :          0 :     mbedtls_platform_zeroize(buf, sizeof(buf));
+    2032                 :          0 :     mbedtls_platform_zeroize(lhash, sizeof(lhash));
+    2033                 :            : 
+    2034                 :          0 :     return ret;
+    2035                 :            : }
+    2036                 :            : #endif /* MBEDTLS_PKCS1_V21 */
+    2037                 :            : 
+    2038                 :            : #if defined(MBEDTLS_PKCS1_V15)
+    2039                 :            : /*
+    2040                 :            :  * Implementation of the PKCS#1 v2.1 RSAES-PKCS1-V1_5-DECRYPT function
+    2041                 :            :  */
+    2042                 :          0 : int mbedtls_rsa_rsaes_pkcs1_v15_decrypt(mbedtls_rsa_context *ctx,
+    2043                 :            :                                         int (*f_rng)(void *, unsigned char *, size_t),
+    2044                 :            :                                         void *p_rng,
+    2045                 :            :                                         size_t *olen,
+    2046                 :            :                                         const unsigned char *input,
+    2047                 :            :                                         unsigned char *output,
+    2048                 :            :                                         size_t output_max_len)
+    2049                 :            : {
+    2050                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    2051                 :            :     size_t ilen;
+    2052                 :            :     unsigned char buf[MBEDTLS_MPI_MAX_SIZE];
+    2053                 :            : 
+    2054                 :          0 :     ilen = ctx->len;
+    2055                 :            : 
+    2056         [ #  # ]:          0 :     if (ctx->padding != MBEDTLS_RSA_PKCS_V15) {
+    2057                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    2058                 :            :     }
+    2059                 :            : 
+    2060   [ #  #  #  # ]:          0 :     if (ilen < 16 || ilen > sizeof(buf)) {
+    2061                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    2062                 :            :     }
+    2063                 :            : 
+    2064                 :          0 :     ret = mbedtls_rsa_private(ctx, f_rng, p_rng, input, buf);
+    2065                 :            : 
+    2066         [ #  # ]:          0 :     if (ret != 0) {
+    2067                 :          0 :         goto cleanup;
+    2068                 :            :     }
+    2069                 :            : 
+    2070                 :          0 :     ret = mbedtls_ct_rsaes_pkcs1_v15_unpadding(buf, ilen,
+    2071                 :            :                                                output, output_max_len, olen);
+    2072                 :            : 
+    2073                 :          0 : cleanup:
+    2074                 :          0 :     mbedtls_platform_zeroize(buf, sizeof(buf));
+    2075                 :            : 
+    2076                 :          0 :     return ret;
+    2077                 :            : }
+    2078                 :            : #endif /* MBEDTLS_PKCS1_V15 */
+    2079                 :            : 
+    2080                 :            : /*
+    2081                 :            :  * Do an RSA operation, then remove the message padding
+    2082                 :            :  */
+    2083                 :          0 : int mbedtls_rsa_pkcs1_decrypt(mbedtls_rsa_context *ctx,
+    2084                 :            :                               int (*f_rng)(void *, unsigned char *, size_t),
+    2085                 :            :                               void *p_rng,
+    2086                 :            :                               size_t *olen,
+    2087                 :            :                               const unsigned char *input,
+    2088                 :            :                               unsigned char *output,
+    2089                 :            :                               size_t output_max_len)
+    2090                 :            : {
+    2091      [ #  #  # ]:          0 :     switch (ctx->padding) {
+    2092                 :            : #if defined(MBEDTLS_PKCS1_V15)
+    2093                 :          0 :         case MBEDTLS_RSA_PKCS_V15:
+    2094                 :          0 :             return mbedtls_rsa_rsaes_pkcs1_v15_decrypt(ctx, f_rng, p_rng, olen,
+    2095                 :            :                                                        input, output, output_max_len);
+    2096                 :            : #endif
+    2097                 :            : 
+    2098                 :            : #if defined(MBEDTLS_PKCS1_V21)
+    2099                 :          0 :         case MBEDTLS_RSA_PKCS_V21:
+    2100                 :          0 :             return mbedtls_rsa_rsaes_oaep_decrypt(ctx, f_rng, p_rng, NULL, 0,
+    2101                 :            :                                                   olen, input, output,
+    2102                 :            :                                                   output_max_len);
+    2103                 :            : #endif
+    2104                 :            : 
+    2105                 :          0 :         default:
+    2106                 :          0 :             return MBEDTLS_ERR_RSA_INVALID_PADDING;
+    2107                 :            :     }
+    2108                 :            : }
+    2109                 :            : 
+    2110                 :            : #if defined(MBEDTLS_PKCS1_V21)
+    2111                 :          1 : static int rsa_rsassa_pss_sign_no_mode_check(mbedtls_rsa_context *ctx,
+    2112                 :            :                                              int (*f_rng)(void *, unsigned char *, size_t),
+    2113                 :            :                                              void *p_rng,
+    2114                 :            :                                              mbedtls_md_type_t md_alg,
+    2115                 :            :                                              unsigned int hashlen,
+    2116                 :            :                                              const unsigned char *hash,
+    2117                 :            :                                              int saltlen,
+    2118                 :            :                                              unsigned char *sig)
+    2119                 :            : {
+    2120                 :            :     size_t olen;
+    2121                 :          1 :     unsigned char *p = sig;
+    2122                 :          1 :     unsigned char *salt = NULL;
+    2123                 :          1 :     size_t slen, min_slen, hlen, offset = 0;
+    2124                 :          1 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    2125                 :            :     size_t msb;
+    2126                 :            :     mbedtls_md_type_t hash_id;
+    2127                 :            : 
+    2128   [ -  +  -  -  :          1 :     if ((md_alg != MBEDTLS_MD_NONE || hashlen != 0) && hash == NULL) {
+                   -  + ]
+    2129                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    2130                 :            :     }
+    2131                 :            : 
+    2132         [ -  + ]:          1 :     if (f_rng == NULL) {
+    2133                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    2134                 :            :     }
+    2135                 :            : 
+    2136                 :          1 :     olen = ctx->len;
+    2137                 :            : 
+    2138         [ +  - ]:          1 :     if (md_alg != MBEDTLS_MD_NONE) {
+    2139                 :            :         /* Gather length of hash to sign */
+    2140                 :          1 :         size_t exp_hashlen = mbedtls_md_get_size_from_type(md_alg);
+    2141         [ -  + ]:          1 :         if (exp_hashlen == 0) {
+    2142                 :          0 :             return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    2143                 :            :         }
+    2144                 :            : 
+    2145         [ -  + ]:          1 :         if (hashlen != exp_hashlen) {
+    2146                 :          0 :             return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    2147                 :            :         }
+    2148                 :            :     }
+    2149                 :            : 
+    2150                 :          1 :     hash_id = (mbedtls_md_type_t) ctx->hash_id;
+    2151         [ -  + ]:          1 :     if (hash_id == MBEDTLS_MD_NONE) {
+    2152                 :          0 :         hash_id = md_alg;
+    2153                 :            :     }
+    2154                 :          1 :     hlen = mbedtls_md_get_size_from_type(hash_id);
+    2155         [ -  + ]:          1 :     if (hlen == 0) {
+    2156                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    2157                 :            :     }
+    2158                 :            : 
+    2159         [ -  + ]:          1 :     if (saltlen == MBEDTLS_RSA_SALT_LEN_ANY) {
+    2160                 :            :         /* Calculate the largest possible salt length, up to the hash size.
+    2161                 :            :          * Normally this is the hash length, which is the maximum salt length
+    2162                 :            :          * according to FIPS 185-4 §5.5 (e) and common practice. If there is not
+    2163                 :            :          * enough room, use the maximum salt length that fits. The constraint is
+    2164                 :            :          * that the hash length plus the salt length plus 2 bytes must be at most
+    2165                 :            :          * the key length. This complies with FIPS 186-4 §5.5 (e) and RFC 8017
+    2166                 :            :          * (PKCS#1 v2.2) §9.1.1 step 3. */
+    2167                 :          0 :         min_slen = hlen - 2;
+    2168         [ #  # ]:          0 :         if (olen < hlen + min_slen + 2) {
+    2169                 :          0 :             return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    2170         [ #  # ]:          0 :         } else if (olen >= hlen + hlen + 2) {
+    2171                 :          0 :             slen = hlen;
+    2172                 :            :         } else {
+    2173                 :          0 :             slen = olen - hlen - 2;
+    2174                 :            :         }
+    2175   [ +  -  -  + ]:          1 :     } else if ((saltlen < 0) || (saltlen + hlen + 2 > olen)) {
+    2176                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    2177                 :            :     } else {
+    2178                 :          1 :         slen = (size_t) saltlen;
+    2179                 :            :     }
+    2180                 :            : 
+    2181                 :          1 :     memset(sig, 0, olen);
+    2182                 :            : 
+    2183                 :            :     /* Note: EMSA-PSS encoding is over the length of N - 1 bits */
+    2184                 :          1 :     msb = mbedtls_mpi_bitlen(&ctx->N) - 1;
+    2185                 :          1 :     p += olen - hlen - slen - 2;
+    2186                 :          1 :     *p++ = 0x01;
+    2187                 :            : 
+    2188                 :            :     /* Generate salt of length slen in place in the encoded message */
+    2189                 :          1 :     salt = p;
+    2190         [ -  + ]:          1 :     if ((ret = f_rng(p_rng, salt, slen)) != 0) {
+    2191                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_RSA_RNG_FAILED, ret);
+    2192                 :            :     }
+    2193                 :            : 
+    2194                 :          1 :     p += slen;
+    2195                 :            : 
+    2196                 :            :     /* Generate H = Hash( M' ) */
+    2197                 :          1 :     ret = hash_mprime(hash, hashlen, salt, slen, p, hash_id);
+    2198         [ -  + ]:          1 :     if (ret != 0) {
+    2199                 :          0 :         return ret;
+    2200                 :            :     }
+    2201                 :            : 
+    2202                 :            :     /* Compensate for boundary condition when applying mask */
+    2203         [ -  + ]:          1 :     if (msb % 8 == 0) {
+    2204                 :          0 :         offset = 1;
+    2205                 :            :     }
+    2206                 :            : 
+    2207                 :            :     /* maskedDB: Apply dbMask to DB */
+    2208                 :          1 :     ret = mgf_mask(sig + offset, olen - hlen - 1 - offset, p, hlen, hash_id);
+    2209         [ -  + ]:          1 :     if (ret != 0) {
+    2210                 :          0 :         return ret;
+    2211                 :            :     }
+    2212                 :            : 
+    2213                 :          1 :     msb = mbedtls_mpi_bitlen(&ctx->N) - 1;
+    2214                 :          1 :     sig[0] &= 0xFF >> (olen * 8 - msb);
+    2215                 :            : 
+    2216                 :          1 :     p += hlen;
+    2217                 :          1 :     *p++ = 0xBC;
+    2218                 :            : 
+    2219                 :          1 :     return mbedtls_rsa_private(ctx, f_rng, p_rng, sig, sig);
+    2220                 :            : }
+    2221                 :            : 
+    2222                 :          1 : static int rsa_rsassa_pss_sign(mbedtls_rsa_context *ctx,
+    2223                 :            :                                int (*f_rng)(void *, unsigned char *, size_t),
+    2224                 :            :                                void *p_rng,
+    2225                 :            :                                mbedtls_md_type_t md_alg,
+    2226                 :            :                                unsigned int hashlen,
+    2227                 :            :                                const unsigned char *hash,
+    2228                 :            :                                int saltlen,
+    2229                 :            :                                unsigned char *sig)
+    2230                 :            : {
+    2231         [ -  + ]:          1 :     if (ctx->padding != MBEDTLS_RSA_PKCS_V21) {
+    2232                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    2233                 :            :     }
+    2234   [ -  +  -  - ]:          1 :     if ((ctx->hash_id == MBEDTLS_MD_NONE) && (md_alg == MBEDTLS_MD_NONE)) {
+    2235                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    2236                 :            :     }
+    2237                 :          1 :     return rsa_rsassa_pss_sign_no_mode_check(ctx, f_rng, p_rng, md_alg, hashlen, hash, saltlen,
+    2238                 :            :                                              sig);
+    2239                 :            : }
+    2240                 :            : 
+    2241                 :          0 : int mbedtls_rsa_rsassa_pss_sign_no_mode_check(mbedtls_rsa_context *ctx,
+    2242                 :            :                                               int (*f_rng)(void *, unsigned char *, size_t),
+    2243                 :            :                                               void *p_rng,
+    2244                 :            :                                               mbedtls_md_type_t md_alg,
+    2245                 :            :                                               unsigned int hashlen,
+    2246                 :            :                                               const unsigned char *hash,
+    2247                 :            :                                               unsigned char *sig)
+    2248                 :            : {
+    2249                 :          0 :     return rsa_rsassa_pss_sign_no_mode_check(ctx, f_rng, p_rng, md_alg,
+    2250                 :            :                                              hashlen, hash, MBEDTLS_RSA_SALT_LEN_ANY, sig);
+    2251                 :            : }
+    2252                 :            : 
+    2253                 :            : /*
+    2254                 :            :  * Implementation of the PKCS#1 v2.1 RSASSA-PSS-SIGN function with
+    2255                 :            :  * the option to pass in the salt length.
+    2256                 :            :  */
+    2257                 :          1 : int mbedtls_rsa_rsassa_pss_sign_ext(mbedtls_rsa_context *ctx,
+    2258                 :            :                                     int (*f_rng)(void *, unsigned char *, size_t),
+    2259                 :            :                                     void *p_rng,
+    2260                 :            :                                     mbedtls_md_type_t md_alg,
+    2261                 :            :                                     unsigned int hashlen,
+    2262                 :            :                                     const unsigned char *hash,
+    2263                 :            :                                     int saltlen,
+    2264                 :            :                                     unsigned char *sig)
+    2265                 :            : {
+    2266                 :          1 :     return rsa_rsassa_pss_sign(ctx, f_rng, p_rng, md_alg,
+    2267                 :            :                                hashlen, hash, saltlen, sig);
+    2268                 :            : }
+    2269                 :            : 
+    2270                 :            : /*
+    2271                 :            :  * Implementation of the PKCS#1 v2.1 RSASSA-PSS-SIGN function
+    2272                 :            :  */
+    2273                 :          0 : int mbedtls_rsa_rsassa_pss_sign(mbedtls_rsa_context *ctx,
+    2274                 :            :                                 int (*f_rng)(void *, unsigned char *, size_t),
+    2275                 :            :                                 void *p_rng,
+    2276                 :            :                                 mbedtls_md_type_t md_alg,
+    2277                 :            :                                 unsigned int hashlen,
+    2278                 :            :                                 const unsigned char *hash,
+    2279                 :            :                                 unsigned char *sig)
+    2280                 :            : {
+    2281                 :          0 :     return rsa_rsassa_pss_sign(ctx, f_rng, p_rng, md_alg,
+    2282                 :            :                                hashlen, hash, MBEDTLS_RSA_SALT_LEN_ANY, sig);
+    2283                 :            : }
+    2284                 :            : #endif /* MBEDTLS_PKCS1_V21 */
+    2285                 :            : 
+    2286                 :            : #if defined(MBEDTLS_PKCS1_V15)
+    2287                 :            : /*
+    2288                 :            :  * Implementation of the PKCS#1 v2.1 RSASSA-PKCS1-V1_5-SIGN function
+    2289                 :            :  */
+    2290                 :            : 
+    2291                 :            : /* Construct a PKCS v1.5 encoding of a hashed message
+    2292                 :            :  *
+    2293                 :            :  * This is used both for signature generation and verification.
+    2294                 :            :  *
+    2295                 :            :  * Parameters:
+    2296                 :            :  * - md_alg:  Identifies the hash algorithm used to generate the given hash;
+    2297                 :            :  *            MBEDTLS_MD_NONE if raw data is signed.
+    2298                 :            :  * - hashlen: Length of hash. Must match md_alg if that's not NONE.
+    2299                 :            :  * - hash:    Buffer containing the hashed message or the raw data.
+    2300                 :            :  * - dst_len: Length of the encoded message.
+    2301                 :            :  * - dst:     Buffer to hold the encoded message.
+    2302                 :            :  *
+    2303                 :            :  * Assumptions:
+    2304                 :            :  * - hash has size hashlen.
+    2305                 :            :  * - dst points to a buffer of size at least dst_len.
+    2306                 :            :  *
+    2307                 :            :  */
+    2308                 :        301 : static int rsa_rsassa_pkcs1_v15_encode(mbedtls_md_type_t md_alg,
+    2309                 :            :                                        unsigned int hashlen,
+    2310                 :            :                                        const unsigned char *hash,
+    2311                 :            :                                        size_t dst_len,
+    2312                 :            :                                        unsigned char *dst)
+    2313                 :            : {
+    2314                 :        301 :     size_t oid_size  = 0;
+    2315                 :        301 :     size_t nb_pad    = dst_len;
+    2316                 :        301 :     unsigned char *p = dst;
+    2317                 :        301 :     const char *oid  = NULL;
+    2318                 :            : 
+    2319                 :            :     /* Are we signing hashed or raw data? */
+    2320         [ +  - ]:        301 :     if (md_alg != MBEDTLS_MD_NONE) {
+    2321                 :        301 :         unsigned char md_size = mbedtls_md_get_size_from_type(md_alg);
+    2322         [ -  + ]:        301 :         if (md_size == 0) {
+    2323                 :          0 :             return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    2324                 :            :         }
+    2325                 :            : 
+    2326         [ -  + ]:        301 :         if (mbedtls_oid_get_oid_by_md(md_alg, &oid, &oid_size) != 0) {
+    2327                 :          0 :             return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    2328                 :            :         }
+    2329                 :            : 
+    2330         [ -  + ]:        301 :         if (hashlen != md_size) {
+    2331                 :          0 :             return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    2332                 :            :         }
+    2333                 :            : 
+    2334                 :            :         /* Double-check that 8 + hashlen + oid_size can be used as a
+    2335                 :            :          * 1-byte ASN.1 length encoding and that there's no overflow. */
+    2336   [ +  -  +  - ]:        301 :         if (8 + hashlen + oid_size  >= 0x80         ||
+    2337                 :        301 :             10 + hashlen            <  hashlen      ||
+    2338         [ -  + ]:        301 :             10 + hashlen + oid_size <  10 + hashlen) {
+    2339                 :          0 :             return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    2340                 :            :         }
+    2341                 :            : 
+    2342                 :            :         /*
+    2343                 :            :          * Static bounds check:
+    2344                 :            :          * - Need 10 bytes for five tag-length pairs.
+    2345                 :            :          *   (Insist on 1-byte length encodings to protect against variants of
+    2346                 :            :          *    Bleichenbacher's forgery attack against lax PKCS#1v1.5 verification)
+    2347                 :            :          * - Need hashlen bytes for hash
+    2348                 :            :          * - Need oid_size bytes for hash alg OID.
+    2349                 :            :          */
+    2350         [ -  + ]:        301 :         if (nb_pad < 10 + hashlen + oid_size) {
+    2351                 :          0 :             return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    2352                 :            :         }
+    2353                 :        301 :         nb_pad -= 10 + hashlen + oid_size;
+    2354                 :            :     } else {
+    2355         [ #  # ]:          0 :         if (nb_pad < hashlen) {
+    2356                 :          0 :             return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    2357                 :            :         }
+    2358                 :            : 
+    2359                 :          0 :         nb_pad -= hashlen;
+    2360                 :            :     }
+    2361                 :            : 
+    2362                 :            :     /* Need space for signature header and padding delimiter (3 bytes),
+    2363                 :            :      * and 8 bytes for the minimal padding */
+    2364         [ -  + ]:        301 :     if (nb_pad < 3 + 8) {
+    2365                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    2366                 :            :     }
+    2367                 :        301 :     nb_pad -= 3;
+    2368                 :            : 
+    2369                 :            :     /* Now nb_pad is the amount of memory to be filled
+    2370                 :            :      * with padding, and at least 8 bytes long. */
+    2371                 :            : 
+    2372                 :            :     /* Write signature header and padding */
+    2373                 :        301 :     *p++ = 0;
+    2374                 :        301 :     *p++ = MBEDTLS_RSA_SIGN;
+    2375                 :        301 :     memset(p, 0xFF, nb_pad);
+    2376                 :        301 :     p += nb_pad;
+    2377                 :        301 :     *p++ = 0;
+    2378                 :            : 
+    2379                 :            :     /* Are we signing raw data? */
+    2380         [ -  + ]:        301 :     if (md_alg == MBEDTLS_MD_NONE) {
+    2381                 :          0 :         memcpy(p, hash, hashlen);
+    2382                 :          0 :         return 0;
+    2383                 :            :     }
+    2384                 :            : 
+    2385                 :            :     /* Signing hashed data, add corresponding ASN.1 structure
+    2386                 :            :      *
+    2387                 :            :      * DigestInfo ::= SEQUENCE {
+    2388                 :            :      *   digestAlgorithm DigestAlgorithmIdentifier,
+    2389                 :            :      *   digest Digest }
+    2390                 :            :      * DigestAlgorithmIdentifier ::= AlgorithmIdentifier
+    2391                 :            :      * Digest ::= OCTET STRING
+    2392                 :            :      *
+    2393                 :            :      * Schematic:
+    2394                 :            :      * TAG-SEQ + LEN [ TAG-SEQ + LEN [ TAG-OID  + LEN [ OID  ]
+    2395                 :            :      *                                 TAG-NULL + LEN [ NULL ] ]
+    2396                 :            :      *                 TAG-OCTET + LEN [ HASH ] ]
+    2397                 :            :      */
+    2398                 :        301 :     *p++ = MBEDTLS_ASN1_SEQUENCE | MBEDTLS_ASN1_CONSTRUCTED;
+    2399                 :        301 :     *p++ = (unsigned char) (0x08 + oid_size + hashlen);
+    2400                 :        301 :     *p++ = MBEDTLS_ASN1_SEQUENCE | MBEDTLS_ASN1_CONSTRUCTED;
+    2401                 :        301 :     *p++ = (unsigned char) (0x04 + oid_size);
+    2402                 :        301 :     *p++ = MBEDTLS_ASN1_OID;
+    2403                 :        301 :     *p++ = (unsigned char) oid_size;
+    2404                 :        301 :     memcpy(p, oid, oid_size);
+    2405                 :        301 :     p += oid_size;
+    2406                 :        301 :     *p++ = MBEDTLS_ASN1_NULL;
+    2407                 :        301 :     *p++ = 0x00;
+    2408                 :        301 :     *p++ = MBEDTLS_ASN1_OCTET_STRING;
+    2409                 :        301 :     *p++ = (unsigned char) hashlen;
+    2410                 :        301 :     memcpy(p, hash, hashlen);
+    2411                 :        301 :     p += hashlen;
+    2412                 :            : 
+    2413                 :            :     /* Just a sanity-check, should be automatic
+    2414                 :            :      * after the initial bounds check. */
+    2415         [ -  + ]:        301 :     if (p != dst + dst_len) {
+    2416                 :          0 :         mbedtls_platform_zeroize(dst, dst_len);
+    2417                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    2418                 :            :     }
+    2419                 :            : 
+    2420                 :        301 :     return 0;
+    2421                 :            : }
+    2422                 :            : 
+    2423                 :            : /*
+    2424                 :            :  * Do an RSA operation to sign the message digest
+    2425                 :            :  */
+    2426                 :         26 : int mbedtls_rsa_rsassa_pkcs1_v15_sign(mbedtls_rsa_context *ctx,
+    2427                 :            :                                       int (*f_rng)(void *, unsigned char *, size_t),
+    2428                 :            :                                       void *p_rng,
+    2429                 :            :                                       mbedtls_md_type_t md_alg,
+    2430                 :            :                                       unsigned int hashlen,
+    2431                 :            :                                       const unsigned char *hash,
+    2432                 :            :                                       unsigned char *sig)
+    2433                 :            : {
+    2434                 :         26 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    2435                 :         26 :     unsigned char *sig_try = NULL, *verif = NULL;
+    2436                 :            : 
+    2437   [ -  +  -  -  :         26 :     if ((md_alg != MBEDTLS_MD_NONE || hashlen != 0) && hash == NULL) {
+                   -  + ]
+    2438                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    2439                 :            :     }
+    2440                 :            : 
+    2441         [ -  + ]:         26 :     if (ctx->padding != MBEDTLS_RSA_PKCS_V15) {
+    2442                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    2443                 :            :     }
+    2444                 :            : 
+    2445                 :            :     /*
+    2446                 :            :      * Prepare PKCS1-v1.5 encoding (padding and hash identifier)
+    2447                 :            :      */
+    2448                 :            : 
+    2449         [ -  + ]:         26 :     if ((ret = rsa_rsassa_pkcs1_v15_encode(md_alg, hashlen, hash,
+    2450                 :            :                                            ctx->len, sig)) != 0) {
+    2451                 :          0 :         return ret;
+    2452                 :            :     }
+    2453                 :            : 
+    2454                 :            :     /* Private key operation
+    2455                 :            :      *
+    2456                 :            :      * In order to prevent Lenstra's attack, make the signature in a
+    2457                 :            :      * temporary buffer and check it before returning it.
+    2458                 :            :      */
+    2459                 :            : 
+    2460                 :         26 :     sig_try = mbedtls_calloc(1, ctx->len);
+    2461         [ -  + ]:         26 :     if (sig_try == NULL) {
+    2462                 :          0 :         return MBEDTLS_ERR_MPI_ALLOC_FAILED;
+    2463                 :            :     }
+    2464                 :            : 
+    2465                 :         26 :     verif = mbedtls_calloc(1, ctx->len);
+    2466         [ -  + ]:         26 :     if (verif == NULL) {
+    2467                 :          0 :         mbedtls_free(sig_try);
+    2468                 :          0 :         return MBEDTLS_ERR_MPI_ALLOC_FAILED;
+    2469                 :            :     }
+    2470                 :            : 
+    2471         [ -  + ]:         26 :     MBEDTLS_MPI_CHK(mbedtls_rsa_private(ctx, f_rng, p_rng, sig, sig_try));
+    2472         [ -  + ]:         26 :     MBEDTLS_MPI_CHK(mbedtls_rsa_public(ctx, sig_try, verif));
+    2473                 :            : 
+    2474         [ -  + ]:         26 :     if (mbedtls_ct_memcmp(verif, sig, ctx->len) != 0) {
+    2475                 :          0 :         ret = MBEDTLS_ERR_RSA_PRIVATE_FAILED;
+    2476                 :          0 :         goto cleanup;
+    2477                 :            :     }
+    2478                 :            : 
+    2479                 :         26 :     memcpy(sig, sig_try, ctx->len);
+    2480                 :            : 
+    2481                 :         26 : cleanup:
+    2482                 :         26 :     mbedtls_zeroize_and_free(sig_try, ctx->len);
+    2483                 :         26 :     mbedtls_zeroize_and_free(verif, ctx->len);
+    2484                 :            : 
+    2485         [ -  + ]:         26 :     if (ret != 0) {
+    2486                 :          0 :         memset(sig, '!', ctx->len);
+    2487                 :            :     }
+    2488                 :         26 :     return ret;
+    2489                 :            : }
+    2490                 :            : #endif /* MBEDTLS_PKCS1_V15 */
+    2491                 :            : 
+    2492                 :            : /*
+    2493                 :            :  * Do an RSA operation to sign the message digest
+    2494                 :            :  */
+    2495                 :         26 : int mbedtls_rsa_pkcs1_sign(mbedtls_rsa_context *ctx,
+    2496                 :            :                            int (*f_rng)(void *, unsigned char *, size_t),
+    2497                 :            :                            void *p_rng,
+    2498                 :            :                            mbedtls_md_type_t md_alg,
+    2499                 :            :                            unsigned int hashlen,
+    2500                 :            :                            const unsigned char *hash,
+    2501                 :            :                            unsigned char *sig)
+    2502                 :            : {
+    2503   [ -  +  -  -  :         26 :     if ((md_alg != MBEDTLS_MD_NONE || hashlen != 0) && hash == NULL) {
+                   -  + ]
+    2504                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    2505                 :            :     }
+    2506                 :            : 
+    2507      [ +  -  - ]:         26 :     switch (ctx->padding) {
+    2508                 :            : #if defined(MBEDTLS_PKCS1_V15)
+    2509                 :         26 :         case MBEDTLS_RSA_PKCS_V15:
+    2510                 :         26 :             return mbedtls_rsa_rsassa_pkcs1_v15_sign(ctx, f_rng, p_rng,
+    2511                 :            :                                                      md_alg, hashlen, hash, sig);
+    2512                 :            : #endif
+    2513                 :            : 
+    2514                 :            : #if defined(MBEDTLS_PKCS1_V21)
+    2515                 :          0 :         case MBEDTLS_RSA_PKCS_V21:
+    2516                 :          0 :             return mbedtls_rsa_rsassa_pss_sign(ctx, f_rng, p_rng, md_alg,
+    2517                 :            :                                                hashlen, hash, sig);
+    2518                 :            : #endif
+    2519                 :            : 
+    2520                 :          0 :         default:
+    2521                 :          0 :             return MBEDTLS_ERR_RSA_INVALID_PADDING;
+    2522                 :            :     }
+    2523                 :            : }
+    2524                 :            : 
+    2525                 :            : #if defined(MBEDTLS_PKCS1_V21)
+    2526                 :            : /*
+    2527                 :            :  * Implementation of the PKCS#1 v2.1 RSASSA-PSS-VERIFY function
+    2528                 :            :  */
+    2529                 :          1 : int mbedtls_rsa_rsassa_pss_verify_ext(mbedtls_rsa_context *ctx,
+    2530                 :            :                                       mbedtls_md_type_t md_alg,
+    2531                 :            :                                       unsigned int hashlen,
+    2532                 :            :                                       const unsigned char *hash,
+    2533                 :            :                                       mbedtls_md_type_t mgf1_hash_id,
+    2534                 :            :                                       int expected_salt_len,
+    2535                 :            :                                       const unsigned char *sig)
+    2536                 :            : {
+    2537                 :          1 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    2538                 :            :     size_t siglen;
+    2539                 :            :     unsigned char *p;
+    2540                 :            :     unsigned char *hash_start;
+    2541                 :            :     unsigned char result[MBEDTLS_MD_MAX_SIZE];
+    2542                 :            :     unsigned int hlen;
+    2543                 :            :     size_t observed_salt_len, msb;
+    2544                 :          1 :     unsigned char buf[MBEDTLS_MPI_MAX_SIZE] = { 0 };
+    2545                 :            : 
+    2546   [ -  +  -  -  :          1 :     if ((md_alg != MBEDTLS_MD_NONE || hashlen != 0) && hash == NULL) {
+                   -  + ]
+    2547                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    2548                 :            :     }
+    2549                 :            : 
+    2550                 :          1 :     siglen = ctx->len;
+    2551                 :            : 
+    2552   [ +  -  -  + ]:          1 :     if (siglen < 16 || siglen > sizeof(buf)) {
+    2553                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    2554                 :            :     }
+    2555                 :            : 
+    2556                 :          1 :     ret = mbedtls_rsa_public(ctx, sig, buf);
+    2557                 :            : 
+    2558         [ -  + ]:          1 :     if (ret != 0) {
+    2559                 :          0 :         return ret;
+    2560                 :            :     }
+    2561                 :            : 
+    2562                 :          1 :     p = buf;
+    2563                 :            : 
+    2564         [ -  + ]:          1 :     if (buf[siglen - 1] != 0xBC) {
+    2565                 :          0 :         return MBEDTLS_ERR_RSA_INVALID_PADDING;
+    2566                 :            :     }
+    2567                 :            : 
+    2568         [ +  - ]:          1 :     if (md_alg != MBEDTLS_MD_NONE) {
+    2569                 :            :         /* Gather length of hash to sign */
+    2570                 :          1 :         size_t exp_hashlen = mbedtls_md_get_size_from_type(md_alg);
+    2571         [ -  + ]:          1 :         if (exp_hashlen == 0) {
+    2572                 :          0 :             return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    2573                 :            :         }
+    2574                 :            : 
+    2575         [ -  + ]:          1 :         if (hashlen != exp_hashlen) {
+    2576                 :          0 :             return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    2577                 :            :         }
+    2578                 :            :     }
+    2579                 :            : 
+    2580                 :          1 :     hlen = mbedtls_md_get_size_from_type(mgf1_hash_id);
+    2581         [ -  + ]:          1 :     if (hlen == 0) {
+    2582                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    2583                 :            :     }
+    2584                 :            : 
+    2585                 :            :     /*
+    2586                 :            :      * Note: EMSA-PSS verification is over the length of N - 1 bits
+    2587                 :            :      */
+    2588                 :          1 :     msb = mbedtls_mpi_bitlen(&ctx->N) - 1;
+    2589                 :            : 
+    2590         [ -  + ]:          1 :     if (buf[0] >> (8 - siglen * 8 + msb)) {
+    2591                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    2592                 :            :     }
+    2593                 :            : 
+    2594                 :            :     /* Compensate for boundary condition when applying mask */
+    2595         [ -  + ]:          1 :     if (msb % 8 == 0) {
+    2596                 :          0 :         p++;
+    2597                 :          0 :         siglen -= 1;
+    2598                 :            :     }
+    2599                 :            : 
+    2600         [ -  + ]:          1 :     if (siglen < hlen + 2) {
+    2601                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    2602                 :            :     }
+    2603                 :          1 :     hash_start = p + siglen - hlen - 1;
+    2604                 :            : 
+    2605                 :          1 :     ret = mgf_mask(p, siglen - hlen - 1, hash_start, hlen, mgf1_hash_id);
+    2606         [ -  + ]:          1 :     if (ret != 0) {
+    2607                 :          0 :         return ret;
+    2608                 :            :     }
+    2609                 :            : 
+    2610                 :          1 :     buf[0] &= 0xFF >> (siglen * 8 - msb);
+    2611                 :            : 
+    2612   [ +  +  +  - ]:        223 :     while (p < hash_start - 1 && *p == 0) {
+    2613                 :        222 :         p++;
+    2614                 :            :     }
+    2615                 :            : 
+    2616         [ -  + ]:          1 :     if (*p++ != 0x01) {
+    2617                 :          0 :         return MBEDTLS_ERR_RSA_INVALID_PADDING;
+    2618                 :            :     }
+    2619                 :            : 
+    2620                 :          1 :     observed_salt_len = (size_t) (hash_start - p);
+    2621                 :            : 
+    2622         [ +  - ]:          1 :     if (expected_salt_len != MBEDTLS_RSA_SALT_LEN_ANY &&
+    2623         [ -  + ]:          1 :         observed_salt_len != (size_t) expected_salt_len) {
+    2624                 :          0 :         return MBEDTLS_ERR_RSA_INVALID_PADDING;
+    2625                 :            :     }
+    2626                 :            : 
+    2627                 :            :     /*
+    2628                 :            :      * Generate H = Hash( M' )
+    2629                 :            :      */
+    2630                 :          1 :     ret = hash_mprime(hash, hashlen, p, observed_salt_len,
+    2631                 :            :                       result, mgf1_hash_id);
+    2632         [ -  + ]:          1 :     if (ret != 0) {
+    2633                 :          0 :         return ret;
+    2634                 :            :     }
+    2635                 :            : 
+    2636         [ -  + ]:          1 :     if (memcmp(hash_start, result, hlen) != 0) {
+    2637                 :          0 :         return MBEDTLS_ERR_RSA_VERIFY_FAILED;
+    2638                 :            :     }
+    2639                 :            : 
+    2640                 :          1 :     return 0;
+    2641                 :            : }
+    2642                 :            : 
+    2643                 :            : /*
+    2644                 :            :  * Simplified PKCS#1 v2.1 RSASSA-PSS-VERIFY function
+    2645                 :            :  */
+    2646                 :          0 : int mbedtls_rsa_rsassa_pss_verify(mbedtls_rsa_context *ctx,
+    2647                 :            :                                   mbedtls_md_type_t md_alg,
+    2648                 :            :                                   unsigned int hashlen,
+    2649                 :            :                                   const unsigned char *hash,
+    2650                 :            :                                   const unsigned char *sig)
+    2651                 :            : {
+    2652                 :            :     mbedtls_md_type_t mgf1_hash_id;
+    2653   [ #  #  #  #  :          0 :     if ((md_alg != MBEDTLS_MD_NONE || hashlen != 0) && hash == NULL) {
+                   #  # ]
+    2654                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    2655                 :            :     }
+    2656                 :            : 
+    2657                 :          0 :     mgf1_hash_id = (ctx->hash_id != MBEDTLS_MD_NONE)
+    2658                 :          0 :                              ? (mbedtls_md_type_t) ctx->hash_id
+    2659         [ #  # ]:          0 :                              : md_alg;
+    2660                 :            : 
+    2661                 :          0 :     return mbedtls_rsa_rsassa_pss_verify_ext(ctx,
+    2662                 :            :                                              md_alg, hashlen, hash,
+    2663                 :            :                                              mgf1_hash_id,
+    2664                 :            :                                              MBEDTLS_RSA_SALT_LEN_ANY,
+    2665                 :            :                                              sig);
+    2666                 :            : 
+    2667                 :            : }
+    2668                 :            : #endif /* MBEDTLS_PKCS1_V21 */
+    2669                 :            : 
+    2670                 :            : #if defined(MBEDTLS_PKCS1_V15)
+    2671                 :            : /*
+    2672                 :            :  * Implementation of the PKCS#1 v2.1 RSASSA-PKCS1-v1_5-VERIFY function
+    2673                 :            :  */
+    2674                 :        275 : int mbedtls_rsa_rsassa_pkcs1_v15_verify(mbedtls_rsa_context *ctx,
+    2675                 :            :                                         mbedtls_md_type_t md_alg,
+    2676                 :            :                                         unsigned int hashlen,
+    2677                 :            :                                         const unsigned char *hash,
+    2678                 :            :                                         const unsigned char *sig)
+    2679                 :            : {
+    2680                 :        275 :     int ret = 0;
+    2681                 :            :     size_t sig_len;
+    2682                 :        275 :     unsigned char *encoded = NULL, *encoded_expected = NULL;
+    2683                 :            : 
+    2684   [ -  +  -  -  :        275 :     if ((md_alg != MBEDTLS_MD_NONE || hashlen != 0) && hash == NULL) {
+                   -  + ]
+    2685                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    2686                 :            :     }
+    2687                 :            : 
+    2688                 :        275 :     sig_len = ctx->len;
+    2689                 :            : 
+    2690                 :            :     /*
+    2691                 :            :      * Prepare expected PKCS1 v1.5 encoding of hash.
+    2692                 :            :      */
+    2693                 :            : 
+    2694   [ +  -  -  + ]:        550 :     if ((encoded          = mbedtls_calloc(1, sig_len)) == NULL ||
+    2695                 :        275 :         (encoded_expected = mbedtls_calloc(1, sig_len)) == NULL) {
+    2696                 :          0 :         ret = MBEDTLS_ERR_MPI_ALLOC_FAILED;
+    2697                 :          0 :         goto cleanup;
+    2698                 :            :     }
+    2699                 :            : 
+    2700         [ -  + ]:        275 :     if ((ret = rsa_rsassa_pkcs1_v15_encode(md_alg, hashlen, hash, sig_len,
+    2701                 :            :                                            encoded_expected)) != 0) {
+    2702                 :          0 :         goto cleanup;
+    2703                 :            :     }
+    2704                 :            : 
+    2705                 :            :     /*
+    2706                 :            :      * Apply RSA primitive to get what should be PKCS1 encoded hash.
+    2707                 :            :      */
+    2708                 :            : 
+    2709                 :        275 :     ret = mbedtls_rsa_public(ctx, sig, encoded);
+    2710         [ -  + ]:        275 :     if (ret != 0) {
+    2711                 :          0 :         goto cleanup;
+    2712                 :            :     }
+    2713                 :            : 
+    2714                 :            :     /*
+    2715                 :            :      * Compare
+    2716                 :            :      */
+    2717                 :            : 
+    2718         [ +  + ]:        275 :     if ((ret = mbedtls_ct_memcmp(encoded, encoded_expected,
+    2719                 :            :                                  sig_len)) != 0) {
+    2720                 :          7 :         ret = MBEDTLS_ERR_RSA_VERIFY_FAILED;
+    2721                 :          7 :         goto cleanup;
+    2722                 :            :     }
+    2723                 :            : 
+    2724                 :        268 : cleanup:
+    2725                 :            : 
+    2726         [ +  - ]:        275 :     if (encoded != NULL) {
+    2727                 :        275 :         mbedtls_zeroize_and_free(encoded, sig_len);
+    2728                 :            :     }
+    2729                 :            : 
+    2730         [ +  - ]:        275 :     if (encoded_expected != NULL) {
+    2731                 :        275 :         mbedtls_zeroize_and_free(encoded_expected, sig_len);
+    2732                 :            :     }
+    2733                 :            : 
+    2734                 :        275 :     return ret;
+    2735                 :            : }
+    2736                 :            : #endif /* MBEDTLS_PKCS1_V15 */
+    2737                 :            : 
+    2738                 :            : /*
+    2739                 :            :  * Do an RSA operation and check the message digest
+    2740                 :            :  */
+    2741                 :        275 : int mbedtls_rsa_pkcs1_verify(mbedtls_rsa_context *ctx,
+    2742                 :            :                              mbedtls_md_type_t md_alg,
+    2743                 :            :                              unsigned int hashlen,
+    2744                 :            :                              const unsigned char *hash,
+    2745                 :            :                              const unsigned char *sig)
+    2746                 :            : {
+    2747   [ -  +  -  -  :        275 :     if ((md_alg != MBEDTLS_MD_NONE || hashlen != 0) && hash == NULL) {
+                   -  + ]
+    2748                 :          0 :         return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+    2749                 :            :     }
+    2750                 :            : 
+    2751      [ +  -  - ]:        275 :     switch (ctx->padding) {
+    2752                 :            : #if defined(MBEDTLS_PKCS1_V15)
+    2753                 :        275 :         case MBEDTLS_RSA_PKCS_V15:
+    2754                 :        275 :             return mbedtls_rsa_rsassa_pkcs1_v15_verify(ctx, md_alg,
+    2755                 :            :                                                        hashlen, hash, sig);
+    2756                 :            : #endif
+    2757                 :            : 
+    2758                 :            : #if defined(MBEDTLS_PKCS1_V21)
+    2759                 :          0 :         case MBEDTLS_RSA_PKCS_V21:
+    2760                 :          0 :             return mbedtls_rsa_rsassa_pss_verify(ctx, md_alg,
+    2761                 :            :                                                  hashlen, hash, sig);
+    2762                 :            : #endif
+    2763                 :            : 
+    2764                 :          0 :         default:
+    2765                 :          0 :             return MBEDTLS_ERR_RSA_INVALID_PADDING;
+    2766                 :            :     }
+    2767                 :            : }
+    2768                 :            : 
+    2769                 :            : /*
+    2770                 :            :  * Copy the components of an RSA key
+    2771                 :            :  */
+    2772                 :         89 : int mbedtls_rsa_copy(mbedtls_rsa_context *dst, const mbedtls_rsa_context *src)
+    2773                 :            : {
+    2774                 :         89 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    2775                 :            : 
+    2776                 :         89 :     dst->len = src->len;
+    2777                 :            : 
+    2778         [ -  + ]:         89 :     MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&dst->N, &src->N));
+    2779         [ -  + ]:         89 :     MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&dst->E, &src->E));
+    2780                 :            : 
+    2781         [ -  + ]:         89 :     MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&dst->D, &src->D));
+    2782         [ -  + ]:         89 :     MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&dst->P, &src->P));
+    2783         [ -  + ]:         89 :     MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&dst->Q, &src->Q));
+    2784                 :            : 
+    2785                 :            : #if !defined(MBEDTLS_RSA_NO_CRT)
+    2786         [ -  + ]:         89 :     MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&dst->DP, &src->DP));
+    2787         [ -  + ]:         89 :     MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&dst->DQ, &src->DQ));
+    2788         [ -  + ]:         89 :     MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&dst->QP, &src->QP));
+    2789         [ -  + ]:         89 :     MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&dst->RP, &src->RP));
+    2790         [ -  + ]:         89 :     MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&dst->RQ, &src->RQ));
+    2791                 :            : #endif
+    2792                 :            : 
+    2793         [ -  + ]:         89 :     MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&dst->RN, &src->RN));
+    2794                 :            : 
+    2795         [ -  + ]:         89 :     MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&dst->Vi, &src->Vi));
+    2796         [ -  + ]:         89 :     MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&dst->Vf, &src->Vf));
+    2797                 :            : 
+    2798                 :         89 :     dst->padding = src->padding;
+    2799                 :         89 :     dst->hash_id = src->hash_id;
+    2800                 :            : 
+    2801                 :         89 : cleanup:
+    2802         [ -  + ]:         89 :     if (ret != 0) {
+    2803                 :          0 :         mbedtls_rsa_free(dst);
+    2804                 :            :     }
+    2805                 :            : 
+    2806                 :         89 :     return ret;
+    2807                 :            : }
+    2808                 :            : 
+    2809                 :            : /*
+    2810                 :            :  * Free the components of an RSA key
+    2811                 :            :  */
+    2812                 :       1205 : void mbedtls_rsa_free(mbedtls_rsa_context *ctx)
+    2813                 :            : {
+    2814         [ -  + ]:       1205 :     if (ctx == NULL) {
+    2815                 :          0 :         return;
+    2816                 :            :     }
+    2817                 :            : 
+    2818                 :       1205 :     mbedtls_mpi_free(&ctx->Vi);
+    2819                 :       1205 :     mbedtls_mpi_free(&ctx->Vf);
+    2820                 :       1205 :     mbedtls_mpi_free(&ctx->RN);
+    2821                 :       1205 :     mbedtls_mpi_free(&ctx->D);
+    2822                 :       1205 :     mbedtls_mpi_free(&ctx->Q);
+    2823                 :       1205 :     mbedtls_mpi_free(&ctx->P);
+    2824                 :       1205 :     mbedtls_mpi_free(&ctx->E);
+    2825                 :       1205 :     mbedtls_mpi_free(&ctx->N);
+    2826                 :            : 
+    2827                 :            : #if !defined(MBEDTLS_RSA_NO_CRT)
+    2828                 :       1205 :     mbedtls_mpi_free(&ctx->RQ);
+    2829                 :       1205 :     mbedtls_mpi_free(&ctx->RP);
+    2830                 :       1205 :     mbedtls_mpi_free(&ctx->QP);
+    2831                 :       1205 :     mbedtls_mpi_free(&ctx->DQ);
+    2832                 :       1205 :     mbedtls_mpi_free(&ctx->DP);
+    2833                 :            : #endif /* MBEDTLS_RSA_NO_CRT */
+    2834                 :            : 
+    2835                 :            : #if defined(MBEDTLS_THREADING_C)
+    2836                 :            :     /* Free the mutex, but only if it hasn't been freed already. */
+    2837                 :            :     if (ctx->ver != 0) {
+    2838                 :            :         mbedtls_mutex_free(&ctx->mutex);
+    2839                 :            :         ctx->ver = 0;
+    2840                 :            :     }
+    2841                 :            : #endif
+    2842                 :            : }
+    2843                 :            : 
+    2844                 :            : #endif /* !MBEDTLS_RSA_ALT */
+    2845                 :            : 
+    2846                 :            : #if defined(MBEDTLS_SELF_TEST)
+    2847                 :            : 
+    2848                 :            : 
+    2849                 :            : /*
+    2850                 :            :  * Example RSA-1024 keypair, for test purposes
+    2851                 :            :  */
+    2852                 :            : #define KEY_LEN 128
+    2853                 :            : 
+    2854                 :            : #define RSA_N   "9292758453063D803DD603D5E777D788" \
+    2855                 :            :                 "8ED1D5BF35786190FA2F23EBC0848AEA" \
+    2856                 :            :                 "DDA92CA6C3D80B32C4D109BE0F36D6AE" \
+    2857                 :            :                 "7130B9CED7ACDF54CFC7555AC14EEBAB" \
+    2858                 :            :                 "93A89813FBF3C4F8066D2D800F7C38A8" \
+    2859                 :            :                 "1AE31942917403FF4946B0A83D3D3E05" \
+    2860                 :            :                 "EE57C6F5F5606FB5D4BC6CD34EE0801A" \
+    2861                 :            :                 "5E94BB77B07507233A0BC7BAC8F90F79"
+    2862                 :            : 
+    2863                 :            : #define RSA_E   "10001"
+    2864                 :            : 
+    2865                 :            : #define RSA_D   "24BF6185468786FDD303083D25E64EFC" \
+    2866                 :            :                 "66CA472BC44D253102F8B4A9D3BFA750" \
+    2867                 :            :                 "91386C0077937FE33FA3252D28855837" \
+    2868                 :            :                 "AE1B484A8A9A45F7EE8C0C634F99E8CD" \
+    2869                 :            :                 "DF79C5CE07EE72C7F123142198164234" \
+    2870                 :            :                 "CABB724CF78B8173B9F880FC86322407" \
+    2871                 :            :                 "AF1FEDFDDE2BEB674CA15F3E81A1521E" \
+    2872                 :            :                 "071513A1E85B5DFA031F21ECAE91A34D"
+    2873                 :            : 
+    2874                 :            : #define RSA_P   "C36D0EB7FCD285223CFB5AABA5BDA3D8" \
+    2875                 :            :                 "2C01CAD19EA484A87EA4377637E75500" \
+    2876                 :            :                 "FCB2005C5C7DD6EC4AC023CDA285D796" \
+    2877                 :            :                 "C3D9E75E1EFC42488BB4F1D13AC30A57"
+    2878                 :            : 
+    2879                 :            : #define RSA_Q   "C000DF51A7C77AE8D7C7370C1FF55B69" \
+    2880                 :            :                 "E211C2B9E5DB1ED0BF61D0D9899620F4" \
+    2881                 :            :                 "910E4168387E3C30AA1E00C339A79508" \
+    2882                 :            :                 "8452DD96A9A5EA5D9DCA68DA636032AF"
+    2883                 :            : 
+    2884                 :            : #define PT_LEN  24
+    2885                 :            : #define RSA_PT  "\xAA\xBB\xCC\x03\x02\x01\x00\xFF\xFF\xFF\xFF\xFF" \
+    2886                 :            :                 "\x11\x22\x33\x0A\x0B\x0C\xCC\xDD\xDD\xDD\xDD\xDD"
+    2887                 :            : 
+    2888                 :            : #if defined(MBEDTLS_PKCS1_V15)
+    2889                 :          0 : static int myrand(void *rng_state, unsigned char *output, size_t len)
+    2890                 :            : {
+    2891                 :            : #if !defined(__OpenBSD__) && !defined(__NetBSD__)
+    2892                 :            :     size_t i;
+    2893                 :            : 
+    2894         [ #  # ]:          0 :     if (rng_state != NULL) {
+    2895                 :          0 :         rng_state  = NULL;
+    2896                 :            :     }
+    2897                 :            : 
+    2898         [ #  # ]:          0 :     for (i = 0; i < len; ++i) {
+    2899                 :          0 :         output[i] = rand();
+    2900                 :            :     }
+    2901                 :            : #else
+    2902                 :            :     if (rng_state != NULL) {
+    2903                 :            :         rng_state = NULL;
+    2904                 :            :     }
+    2905                 :            : 
+    2906                 :            :     arc4random_buf(output, len);
+    2907                 :            : #endif /* !OpenBSD && !NetBSD */
+    2908                 :            : 
+    2909                 :          0 :     return 0;
+    2910                 :            : }
+    2911                 :            : #endif /* MBEDTLS_PKCS1_V15 */
+    2912                 :            : 
+    2913                 :            : /*
+    2914                 :            :  * Checkup routine
+    2915                 :            :  */
+    2916                 :          0 : int mbedtls_rsa_self_test(int verbose)
+    2917                 :            : {
+    2918                 :          0 :     int ret = 0;
+    2919                 :            : #if defined(MBEDTLS_PKCS1_V15)
+    2920                 :            :     size_t len;
+    2921                 :            :     mbedtls_rsa_context rsa;
+    2922                 :            :     unsigned char rsa_plaintext[PT_LEN];
+    2923                 :            :     unsigned char rsa_decrypted[PT_LEN];
+    2924                 :            :     unsigned char rsa_ciphertext[KEY_LEN];
+    2925                 :            : #if defined(MBEDTLS_MD_CAN_SHA1)
+    2926                 :            :     unsigned char sha1sum[20];
+    2927                 :            : #endif
+    2928                 :            : 
+    2929                 :            :     mbedtls_mpi K;
+    2930                 :            : 
+    2931                 :          0 :     mbedtls_mpi_init(&K);
+    2932                 :          0 :     mbedtls_rsa_init(&rsa);
+    2933                 :            : 
+    2934         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_read_string(&K, 16, RSA_N));
+    2935         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_rsa_import(&rsa, &K, NULL, NULL, NULL, NULL));
+    2936         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_read_string(&K, 16, RSA_P));
+    2937         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_rsa_import(&rsa, NULL, &K, NULL, NULL, NULL));
+    2938         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_read_string(&K, 16, RSA_Q));
+    2939         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_rsa_import(&rsa, NULL, NULL, &K, NULL, NULL));
+    2940         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_read_string(&K, 16, RSA_D));
+    2941         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_rsa_import(&rsa, NULL, NULL, NULL, &K, NULL));
+    2942         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_read_string(&K, 16, RSA_E));
+    2943         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_rsa_import(&rsa, NULL, NULL, NULL, NULL, &K));
+    2944                 :            : 
+    2945         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_rsa_complete(&rsa));
+    2946                 :            : 
+    2947         [ #  # ]:          0 :     if (verbose != 0) {
+    2948                 :          0 :         mbedtls_printf("  RSA key validation: ");
+    2949                 :            :     }
+    2950                 :            : 
+    2951   [ #  #  #  # ]:          0 :     if (mbedtls_rsa_check_pubkey(&rsa) != 0 ||
+    2952                 :          0 :         mbedtls_rsa_check_privkey(&rsa) != 0) {
+    2953         [ #  # ]:          0 :         if (verbose != 0) {
+    2954                 :          0 :             mbedtls_printf("failed\n");
+    2955                 :            :         }
+    2956                 :            : 
+    2957                 :          0 :         ret = 1;
+    2958                 :          0 :         goto cleanup;
+    2959                 :            :     }
+    2960                 :            : 
+    2961         [ #  # ]:          0 :     if (verbose != 0) {
+    2962                 :          0 :         mbedtls_printf("passed\n  PKCS#1 encryption : ");
+    2963                 :            :     }
+    2964                 :            : 
+    2965                 :          0 :     memcpy(rsa_plaintext, RSA_PT, PT_LEN);
+    2966                 :            : 
+    2967         [ #  # ]:          0 :     if (mbedtls_rsa_pkcs1_encrypt(&rsa, myrand, NULL,
+    2968                 :            :                                   PT_LEN, rsa_plaintext,
+    2969                 :            :                                   rsa_ciphertext) != 0) {
+    2970         [ #  # ]:          0 :         if (verbose != 0) {
+    2971                 :          0 :             mbedtls_printf("failed\n");
+    2972                 :            :         }
+    2973                 :            : 
+    2974                 :          0 :         ret = 1;
+    2975                 :          0 :         goto cleanup;
+    2976                 :            :     }
+    2977                 :            : 
+    2978         [ #  # ]:          0 :     if (verbose != 0) {
+    2979                 :          0 :         mbedtls_printf("passed\n  PKCS#1 decryption : ");
+    2980                 :            :     }
+    2981                 :            : 
+    2982         [ #  # ]:          0 :     if (mbedtls_rsa_pkcs1_decrypt(&rsa, myrand, NULL,
+    2983                 :            :                                   &len, rsa_ciphertext, rsa_decrypted,
+    2984                 :            :                                   sizeof(rsa_decrypted)) != 0) {
+    2985         [ #  # ]:          0 :         if (verbose != 0) {
+    2986                 :          0 :             mbedtls_printf("failed\n");
+    2987                 :            :         }
+    2988                 :            : 
+    2989                 :          0 :         ret = 1;
+    2990                 :          0 :         goto cleanup;
+    2991                 :            :     }
+    2992                 :            : 
+    2993         [ #  # ]:          0 :     if (memcmp(rsa_decrypted, rsa_plaintext, len) != 0) {
+    2994         [ #  # ]:          0 :         if (verbose != 0) {
+    2995                 :          0 :             mbedtls_printf("failed\n");
+    2996                 :            :         }
+    2997                 :            : 
+    2998                 :          0 :         ret = 1;
+    2999                 :          0 :         goto cleanup;
+    3000                 :            :     }
+    3001                 :            : 
+    3002         [ #  # ]:          0 :     if (verbose != 0) {
+    3003                 :          0 :         mbedtls_printf("passed\n");
+    3004                 :            :     }
+    3005                 :            : 
+    3006                 :            : #if defined(MBEDTLS_MD_CAN_SHA1)
+    3007         [ #  # ]:          0 :     if (verbose != 0) {
+    3008                 :          0 :         mbedtls_printf("  PKCS#1 data sign  : ");
+    3009                 :            :     }
+    3010                 :            : 
+    3011         [ #  # ]:          0 :     if (mbedtls_md(mbedtls_md_info_from_type(MBEDTLS_MD_SHA1),
+    3012                 :            :                    rsa_plaintext, PT_LEN, sha1sum) != 0) {
+    3013         [ #  # ]:          0 :         if (verbose != 0) {
+    3014                 :          0 :             mbedtls_printf("failed\n");
+    3015                 :            :         }
+    3016                 :            : 
+    3017                 :          0 :         return 1;
+    3018                 :            :     }
+    3019                 :            : 
+    3020         [ #  # ]:          0 :     if (mbedtls_rsa_pkcs1_sign(&rsa, myrand, NULL,
+    3021                 :            :                                MBEDTLS_MD_SHA1, 20,
+    3022                 :            :                                sha1sum, rsa_ciphertext) != 0) {
+    3023         [ #  # ]:          0 :         if (verbose != 0) {
+    3024                 :          0 :             mbedtls_printf("failed\n");
+    3025                 :            :         }
+    3026                 :            : 
+    3027                 :          0 :         ret = 1;
+    3028                 :          0 :         goto cleanup;
+    3029                 :            :     }
+    3030                 :            : 
+    3031         [ #  # ]:          0 :     if (verbose != 0) {
+    3032                 :          0 :         mbedtls_printf("passed\n  PKCS#1 sig. verify: ");
+    3033                 :            :     }
+    3034                 :            : 
+    3035         [ #  # ]:          0 :     if (mbedtls_rsa_pkcs1_verify(&rsa, MBEDTLS_MD_SHA1, 20,
+    3036                 :            :                                  sha1sum, rsa_ciphertext) != 0) {
+    3037         [ #  # ]:          0 :         if (verbose != 0) {
+    3038                 :          0 :             mbedtls_printf("failed\n");
+    3039                 :            :         }
+    3040                 :            : 
+    3041                 :          0 :         ret = 1;
+    3042                 :          0 :         goto cleanup;
+    3043                 :            :     }
+    3044                 :            : 
+    3045         [ #  # ]:          0 :     if (verbose != 0) {
+    3046                 :          0 :         mbedtls_printf("passed\n");
+    3047                 :            :     }
+    3048                 :            : #endif /* MBEDTLS_MD_CAN_SHA1 */
+    3049                 :            : 
+    3050         [ #  # ]:          0 :     if (verbose != 0) {
+    3051                 :          0 :         mbedtls_printf("\n");
+    3052                 :            :     }
+    3053                 :            : 
+    3054                 :          0 : cleanup:
+    3055                 :          0 :     mbedtls_mpi_free(&K);
+    3056                 :          0 :     mbedtls_rsa_free(&rsa);
+    3057                 :            : #else /* MBEDTLS_PKCS1_V15 */
+    3058                 :            :     ((void) verbose);
+    3059                 :            : #endif /* MBEDTLS_PKCS1_V15 */
+    3060                 :          0 :     return ret;
+    3061                 :            : }
+    3062                 :            : 
+    3063                 :            : #endif /* MBEDTLS_SELF_TEST */
+    3064                 :            : 
+    3065                 :            : #endif /* MBEDTLS_RSA_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/rsa_alt_helpers.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/rsa_alt_helpers.c.func-sort-c.html new file mode 100644 index 00000000000..63d6974677e --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/rsa_alt_helpers.c.func-sort-c.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/rsa_alt_helpers.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - rsa_alt_helpers.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:4917328.3 %
Date:2024-09-22 08:21:07Functions:2540.0 %
Branches:3421615.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_rsa_deduce_private_exponent0
mbedtls_rsa_validate_crt0
mbedtls_rsa_validate_params0
mbedtls_rsa_deduce_crt2
mbedtls_rsa_deduce_primes2
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/rsa_alt_helpers.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/rsa_alt_helpers.c.func.html new file mode 100644 index 00000000000..c2399e05189 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/rsa_alt_helpers.c.func.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/rsa_alt_helpers.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - rsa_alt_helpers.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:4917328.3 %
Date:2024-09-22 08:21:07Functions:2540.0 %
Branches:3421615.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_rsa_deduce_crt2
mbedtls_rsa_deduce_primes2
mbedtls_rsa_deduce_private_exponent0
mbedtls_rsa_validate_crt0
mbedtls_rsa_validate_params0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/rsa_alt_helpers.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/rsa_alt_helpers.c.gcov.html new file mode 100644 index 00000000000..12aade0bb31 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/rsa_alt_helpers.c.gcov.html @@ -0,0 +1,538 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/rsa_alt_helpers.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - rsa_alt_helpers.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:4917328.3 %
Date:2024-09-22 08:21:07Functions:2540.0 %
Branches:3421615.7 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  *  Helper functions for the RSA module
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  *
+       7                 :            :  */
+       8                 :            : 
+       9                 :            : #include "common.h"
+      10                 :            : 
+      11                 :            : #if defined(MBEDTLS_RSA_C)
+      12                 :            : 
+      13                 :            : #include "mbedtls/rsa.h"
+      14                 :            : #include "mbedtls/bignum.h"
+      15                 :            : #include "rsa_alt_helpers.h"
+      16                 :            : 
+      17                 :            : /*
+      18                 :            :  * Compute RSA prime factors from public and private exponents
+      19                 :            :  *
+      20                 :            :  * Summary of algorithm:
+      21                 :            :  * Setting F := lcm(P-1,Q-1), the idea is as follows:
+      22                 :            :  *
+      23                 :            :  * (a) For any 1 <= X < N with gcd(X,N)=1, we have X^F = 1 modulo N, so X^(F/2)
+      24                 :            :  *     is a square root of 1 in Z/NZ. Since Z/NZ ~= Z/PZ x Z/QZ by CRT and the
+      25                 :            :  *     square roots of 1 in Z/PZ and Z/QZ are +1 and -1, this leaves the four
+      26                 :            :  *     possibilities X^(F/2) = (+-1, +-1). If it happens that X^(F/2) = (-1,+1)
+      27                 :            :  *     or (+1,-1), then gcd(X^(F/2) + 1, N) will be equal to one of the prime
+      28                 :            :  *     factors of N.
+      29                 :            :  *
+      30                 :            :  * (b) If we don't know F/2 but (F/2) * K for some odd (!) K, then the same
+      31                 :            :  *     construction still applies since (-)^K is the identity on the set of
+      32                 :            :  *     roots of 1 in Z/NZ.
+      33                 :            :  *
+      34                 :            :  * The public and private key primitives (-)^E and (-)^D are mutually inverse
+      35                 :            :  * bijections on Z/NZ if and only if (-)^(DE) is the identity on Z/NZ, i.e.
+      36                 :            :  * if and only if DE - 1 is a multiple of F, say DE - 1 = F * L.
+      37                 :            :  * Splitting L = 2^t * K with K odd, we have
+      38                 :            :  *
+      39                 :            :  *   DE - 1 = FL = (F/2) * (2^(t+1)) * K,
+      40                 :            :  *
+      41                 :            :  * so (F / 2) * K is among the numbers
+      42                 :            :  *
+      43                 :            :  *   (DE - 1) >> 1, (DE - 1) >> 2, ..., (DE - 1) >> ord
+      44                 :            :  *
+      45                 :            :  * where ord is the order of 2 in (DE - 1).
+      46                 :            :  * We can therefore iterate through these numbers apply the construction
+      47                 :            :  * of (a) and (b) above to attempt to factor N.
+      48                 :            :  *
+      49                 :            :  */
+      50                 :          2 : int mbedtls_rsa_deduce_primes(mbedtls_mpi const *N,
+      51                 :            :                               mbedtls_mpi const *E, mbedtls_mpi const *D,
+      52                 :            :                               mbedtls_mpi *P, mbedtls_mpi *Q)
+      53                 :            : {
+      54                 :          2 :     int ret = 0;
+      55                 :            : 
+      56                 :            :     uint16_t attempt;  /* Number of current attempt  */
+      57                 :            :     uint16_t iter;     /* Number of squares computed in the current attempt */
+      58                 :            : 
+      59                 :            :     uint16_t order;    /* Order of 2 in DE - 1 */
+      60                 :            : 
+      61                 :            :     mbedtls_mpi T;  /* Holds largest odd divisor of DE - 1     */
+      62                 :            :     mbedtls_mpi K;  /* Temporary holding the current candidate */
+      63                 :            : 
+      64                 :          2 :     const unsigned char primes[] = { 2,
+      65                 :            :                                      3,    5,    7,   11,   13,   17,   19,   23,
+      66                 :            :                                      29,   31,   37,   41,   43,   47,   53,   59,
+      67                 :            :                                      61,   67,   71,   73,   79,   83,   89,   97,
+      68                 :            :                                      101,  103,  107,  109,  113,  127,  131,  137,
+      69                 :            :                                      139,  149,  151,  157,  163,  167,  173,  179,
+      70                 :            :                                      181,  191,  193,  197,  199,  211,  223,  227,
+      71                 :            :                                      229,  233,  239,  241,  251 };
+      72                 :            : 
+      73                 :          2 :     const size_t num_primes = sizeof(primes) / sizeof(*primes);
+      74                 :            : 
+      75   [ +  -  +  -  :          2 :     if (P == NULL || Q == NULL || P->p != NULL || Q->p != NULL) {
+             +  -  -  + ]
+      76                 :          0 :         return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
+      77                 :            :     }
+      78                 :            : 
+      79   [ +  -  +  - ]:          4 :     if (mbedtls_mpi_cmp_int(N, 0) <= 0 ||
+      80         [ +  - ]:          4 :         mbedtls_mpi_cmp_int(D, 1) <= 0 ||
+      81         [ +  - ]:          4 :         mbedtls_mpi_cmp_mpi(D, N) >= 0 ||
+      82         [ -  + ]:          4 :         mbedtls_mpi_cmp_int(E, 1) <= 0 ||
+      83                 :          2 :         mbedtls_mpi_cmp_mpi(E, N) >= 0) {
+      84                 :          0 :         return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
+      85                 :            :     }
+      86                 :            : 
+      87                 :            :     /*
+      88                 :            :      * Initializations and temporary changes
+      89                 :            :      */
+      90                 :            : 
+      91                 :          2 :     mbedtls_mpi_init(&K);
+      92                 :          2 :     mbedtls_mpi_init(&T);
+      93                 :            : 
+      94                 :            :     /* T := DE - 1 */
+      95         [ -  + ]:          2 :     MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&T, D,  E));
+      96         [ -  + ]:          2 :     MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&T, &T, 1));
+      97                 :            : 
+      98         [ -  + ]:          2 :     if ((order = (uint16_t) mbedtls_mpi_lsb(&T)) == 0) {
+      99                 :          0 :         ret = MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
+     100                 :          0 :         goto cleanup;
+     101                 :            :     }
+     102                 :            : 
+     103                 :            :     /* After this operation, T holds the largest odd divisor of DE - 1. */
+     104         [ -  + ]:          2 :     MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&T, order));
+     105                 :            : 
+     106                 :            :     /*
+     107                 :            :      * Actual work
+     108                 :            :      */
+     109                 :            : 
+     110                 :            :     /* Skip trying 2 if N == 1 mod 8 */
+     111                 :          2 :     attempt = 0;
+     112         [ -  + ]:          2 :     if (N->p[0] % 8 == 1) {
+     113                 :          0 :         attempt = 1;
+     114                 :            :     }
+     115                 :            : 
+     116         [ +  - ]:          2 :     for (; attempt < num_primes; ++attempt) {
+     117         [ -  + ]:          2 :         MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&K, primes[attempt]));
+     118                 :            : 
+     119                 :            :         /* Check if gcd(K,N) = 1 */
+     120         [ -  + ]:          2 :         MBEDTLS_MPI_CHK(mbedtls_mpi_gcd(P, &K, N));
+     121         [ -  + ]:          2 :         if (mbedtls_mpi_cmp_int(P, 1) != 0) {
+     122                 :          0 :             continue;
+     123                 :            :         }
+     124                 :            : 
+     125                 :            :         /* Go through K^T + 1, K^(2T) + 1, K^(4T) + 1, ...
+     126                 :            :          * and check whether they have nontrivial GCD with N. */
+     127         [ -  + ]:          2 :         MBEDTLS_MPI_CHK(mbedtls_mpi_exp_mod(&K, &K, &T, N,
+     128                 :            :                                             Q /* temporarily use Q for storing Montgomery
+     129                 :            :                                                * multiplication helper values */));
+     130                 :            : 
+     131         [ +  - ]:          2 :         for (iter = 1; iter <= order; ++iter) {
+     132                 :            :             /* If we reach 1 prematurely, there's no point
+     133                 :            :              * in continuing to square K */
+     134         [ -  + ]:          2 :             if (mbedtls_mpi_cmp_int(&K, 1) == 0) {
+     135                 :          0 :                 break;
+     136                 :            :             }
+     137                 :            : 
+     138         [ -  + ]:          2 :             MBEDTLS_MPI_CHK(mbedtls_mpi_add_int(&K, &K, 1));
+     139         [ -  + ]:          2 :             MBEDTLS_MPI_CHK(mbedtls_mpi_gcd(P, &K, N));
+     140                 :            : 
+     141   [ +  -  +  - ]:          4 :             if (mbedtls_mpi_cmp_int(P, 1) ==  1 &&
+     142                 :          2 :                 mbedtls_mpi_cmp_mpi(P, N) == -1) {
+     143                 :            :                 /*
+     144                 :            :                  * Have found a nontrivial divisor P of N.
+     145                 :            :                  * Set Q := N / P.
+     146                 :            :                  */
+     147                 :            : 
+     148         [ -  + ]:          2 :                 MBEDTLS_MPI_CHK(mbedtls_mpi_div_mpi(Q, NULL, N, P));
+     149                 :          2 :                 goto cleanup;
+     150                 :            :             }
+     151                 :            : 
+     152         [ #  # ]:          0 :             MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&K, &K, 1));
+     153         [ #  # ]:          0 :             MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&K, &K, &K));
+     154         [ #  # ]:          0 :             MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&K, &K, N));
+     155                 :            :         }
+     156                 :            : 
+     157                 :            :         /*
+     158                 :            :          * If we get here, then either we prematurely aborted the loop because
+     159                 :            :          * we reached 1, or K holds primes[attempt]^(DE - 1) mod N, which must
+     160                 :            :          * be 1 if D,E,N were consistent.
+     161                 :            :          * Check if that's the case and abort if not, to avoid very long,
+     162                 :            :          * yet eventually failing, computations if N,D,E were not sane.
+     163                 :            :          */
+     164         [ #  # ]:          0 :         if (mbedtls_mpi_cmp_int(&K, 1) != 0) {
+     165                 :          0 :             break;
+     166                 :            :         }
+     167                 :            :     }
+     168                 :            : 
+     169                 :          0 :     ret = MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
+     170                 :            : 
+     171                 :          2 : cleanup:
+     172                 :            : 
+     173                 :          2 :     mbedtls_mpi_free(&K);
+     174                 :          2 :     mbedtls_mpi_free(&T);
+     175                 :          2 :     return ret;
+     176                 :            : }
+     177                 :            : 
+     178                 :            : /*
+     179                 :            :  * Given P, Q and the public exponent E, deduce D.
+     180                 :            :  * This is essentially a modular inversion.
+     181                 :            :  */
+     182                 :          0 : int mbedtls_rsa_deduce_private_exponent(mbedtls_mpi const *P,
+     183                 :            :                                         mbedtls_mpi const *Q,
+     184                 :            :                                         mbedtls_mpi const *E,
+     185                 :            :                                         mbedtls_mpi *D)
+     186                 :            : {
+     187                 :          0 :     int ret = 0;
+     188                 :            :     mbedtls_mpi K, L;
+     189                 :            : 
+     190   [ #  #  #  # ]:          0 :     if (D == NULL || mbedtls_mpi_cmp_int(D, 0) != 0) {
+     191                 :          0 :         return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
+     192                 :            :     }
+     193                 :            : 
+     194   [ #  #  #  # ]:          0 :     if (mbedtls_mpi_cmp_int(P, 1) <= 0 ||
+     195         [ #  # ]:          0 :         mbedtls_mpi_cmp_int(Q, 1) <= 0 ||
+     196                 :          0 :         mbedtls_mpi_cmp_int(E, 0) == 0) {
+     197                 :          0 :         return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
+     198                 :            :     }
+     199                 :            : 
+     200                 :          0 :     mbedtls_mpi_init(&K);
+     201                 :          0 :     mbedtls_mpi_init(&L);
+     202                 :            : 
+     203                 :            :     /* Temporarily put K := P-1 and L := Q-1 */
+     204         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&K, P, 1));
+     205         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&L, Q, 1));
+     206                 :            : 
+     207                 :            :     /* Temporarily put D := gcd(P-1, Q-1) */
+     208         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_gcd(D, &K, &L));
+     209                 :            : 
+     210                 :            :     /* K := LCM(P-1, Q-1) */
+     211         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&K, &K, &L));
+     212         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_div_mpi(&K, NULL, &K, D));
+     213                 :            : 
+     214                 :            :     /* Compute modular inverse of E in LCM(P-1, Q-1) */
+     215         [ #  # ]:          0 :     MBEDTLS_MPI_CHK(mbedtls_mpi_inv_mod(D, E, &K));
+     216                 :            : 
+     217                 :          0 : cleanup:
+     218                 :            : 
+     219                 :          0 :     mbedtls_mpi_free(&K);
+     220                 :          0 :     mbedtls_mpi_free(&L);
+     221                 :            : 
+     222                 :          0 :     return ret;
+     223                 :            : }
+     224                 :            : 
+     225                 :          2 : int mbedtls_rsa_deduce_crt(const mbedtls_mpi *P, const mbedtls_mpi *Q,
+     226                 :            :                            const mbedtls_mpi *D, mbedtls_mpi *DP,
+     227                 :            :                            mbedtls_mpi *DQ, mbedtls_mpi *QP)
+     228                 :            : {
+     229                 :          2 :     int ret = 0;
+     230                 :            :     mbedtls_mpi K;
+     231                 :          2 :     mbedtls_mpi_init(&K);
+     232                 :            : 
+     233                 :            :     /* DP = D mod P-1 */
+     234         [ +  - ]:          2 :     if (DP != NULL) {
+     235         [ -  + ]:          2 :         MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&K, P, 1));
+     236         [ -  + ]:          2 :         MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(DP, D, &K));
+     237                 :            :     }
+     238                 :            : 
+     239                 :            :     /* DQ = D mod Q-1 */
+     240         [ +  - ]:          2 :     if (DQ != NULL) {
+     241         [ -  + ]:          2 :         MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&K, Q, 1));
+     242         [ -  + ]:          2 :         MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(DQ, D, &K));
+     243                 :            :     }
+     244                 :            : 
+     245                 :            :     /* QP = Q^{-1} mod P */
+     246         [ -  + ]:          2 :     if (QP != NULL) {
+     247         [ +  - ]:          2 :         MBEDTLS_MPI_CHK(mbedtls_mpi_inv_mod(QP, Q, P));
+     248                 :            :     }
+     249                 :            : 
+     250                 :          2 : cleanup:
+     251                 :          2 :     mbedtls_mpi_free(&K);
+     252                 :            : 
+     253                 :          2 :     return ret;
+     254                 :            : }
+     255                 :            : 
+     256                 :            : /*
+     257                 :            :  * Check that core RSA parameters are sane.
+     258                 :            :  */
+     259                 :          0 : int mbedtls_rsa_validate_params(const mbedtls_mpi *N, const mbedtls_mpi *P,
+     260                 :            :                                 const mbedtls_mpi *Q, const mbedtls_mpi *D,
+     261                 :            :                                 const mbedtls_mpi *E,
+     262                 :            :                                 int (*f_rng)(void *, unsigned char *, size_t),
+     263                 :            :                                 void *p_rng)
+     264                 :            : {
+     265                 :          0 :     int ret = 0;
+     266                 :            :     mbedtls_mpi K, L;
+     267                 :            : 
+     268                 :          0 :     mbedtls_mpi_init(&K);
+     269                 :          0 :     mbedtls_mpi_init(&L);
+     270                 :            : 
+     271                 :            :     /*
+     272                 :            :      * Step 1: If PRNG provided, check that P and Q are prime
+     273                 :            :      */
+     274                 :            : 
+     275                 :            : #if defined(MBEDTLS_GENPRIME)
+     276                 :            :     /*
+     277                 :            :      * When generating keys, the strongest security we support aims for an error
+     278                 :            :      * rate of at most 2^-100 and we are aiming for the same certainty here as
+     279                 :            :      * well.
+     280                 :            :      */
+     281   [ #  #  #  #  :          0 :     if (f_rng != NULL && P != NULL &&
+                   #  # ]
+     282                 :          0 :         (ret = mbedtls_mpi_is_prime_ext(P, 50, f_rng, p_rng)) != 0) {
+     283                 :          0 :         ret = MBEDTLS_ERR_RSA_KEY_CHECK_FAILED;
+     284                 :          0 :         goto cleanup;
+     285                 :            :     }
+     286                 :            : 
+     287   [ #  #  #  #  :          0 :     if (f_rng != NULL && Q != NULL &&
+                   #  # ]
+     288                 :          0 :         (ret = mbedtls_mpi_is_prime_ext(Q, 50, f_rng, p_rng)) != 0) {
+     289                 :          0 :         ret = MBEDTLS_ERR_RSA_KEY_CHECK_FAILED;
+     290                 :          0 :         goto cleanup;
+     291                 :            :     }
+     292                 :            : #else
+     293                 :            :     ((void) f_rng);
+     294                 :            :     ((void) p_rng);
+     295                 :            : #endif /* MBEDTLS_GENPRIME */
+     296                 :            : 
+     297                 :            :     /*
+     298                 :            :      * Step 2: Check that 1 < N = P * Q
+     299                 :            :      */
+     300                 :            : 
+     301   [ #  #  #  #  :          0 :     if (P != NULL && Q != NULL && N != NULL) {
+                   #  # ]
+     302         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&K, P, Q));
+     303   [ #  #  #  # ]:          0 :         if (mbedtls_mpi_cmp_int(N, 1)  <= 0 ||
+     304                 :          0 :             mbedtls_mpi_cmp_mpi(&K, N) != 0) {
+     305                 :          0 :             ret = MBEDTLS_ERR_RSA_KEY_CHECK_FAILED;
+     306                 :          0 :             goto cleanup;
+     307                 :            :         }
+     308                 :            :     }
+     309                 :            : 
+     310                 :            :     /*
+     311                 :            :      * Step 3: Check and 1 < D, E < N if present.
+     312                 :            :      */
+     313                 :            : 
+     314   [ #  #  #  #  :          0 :     if (N != NULL && D != NULL && E != NULL) {
+                   #  # ]
+     315   [ #  #  #  # ]:          0 :         if (mbedtls_mpi_cmp_int(D, 1) <= 0 ||
+     316         [ #  # ]:          0 :             mbedtls_mpi_cmp_int(E, 1) <= 0 ||
+     317         [ #  # ]:          0 :             mbedtls_mpi_cmp_mpi(D, N) >= 0 ||
+     318                 :          0 :             mbedtls_mpi_cmp_mpi(E, N) >= 0) {
+     319                 :          0 :             ret = MBEDTLS_ERR_RSA_KEY_CHECK_FAILED;
+     320                 :          0 :             goto cleanup;
+     321                 :            :         }
+     322                 :            :     }
+     323                 :            : 
+     324                 :            :     /*
+     325                 :            :      * Step 4: Check that D, E are inverse modulo P-1 and Q-1
+     326                 :            :      */
+     327                 :            : 
+     328   [ #  #  #  #  :          0 :     if (P != NULL && Q != NULL && D != NULL && E != NULL) {
+             #  #  #  # ]
+     329   [ #  #  #  # ]:          0 :         if (mbedtls_mpi_cmp_int(P, 1) <= 0 ||
+     330                 :          0 :             mbedtls_mpi_cmp_int(Q, 1) <= 0) {
+     331                 :          0 :             ret = MBEDTLS_ERR_RSA_KEY_CHECK_FAILED;
+     332                 :          0 :             goto cleanup;
+     333                 :            :         }
+     334                 :            : 
+     335                 :            :         /* Compute DE-1 mod P-1 */
+     336         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&K, D, E));
+     337         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&K, &K, 1));
+     338         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&L, P, 1));
+     339         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&K, &K, &L));
+     340         [ #  # ]:          0 :         if (mbedtls_mpi_cmp_int(&K, 0) != 0) {
+     341                 :          0 :             ret = MBEDTLS_ERR_RSA_KEY_CHECK_FAILED;
+     342                 :          0 :             goto cleanup;
+     343                 :            :         }
+     344                 :            : 
+     345                 :            :         /* Compute DE-1 mod Q-1 */
+     346         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&K, D, E));
+     347         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&K, &K, 1));
+     348         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&L, Q, 1));
+     349         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&K, &K, &L));
+     350         [ #  # ]:          0 :         if (mbedtls_mpi_cmp_int(&K, 0) != 0) {
+     351                 :          0 :             ret = MBEDTLS_ERR_RSA_KEY_CHECK_FAILED;
+     352                 :          0 :             goto cleanup;
+     353                 :            :         }
+     354                 :            :     }
+     355                 :            : 
+     356                 :          0 : cleanup:
+     357                 :            : 
+     358                 :          0 :     mbedtls_mpi_free(&K);
+     359                 :          0 :     mbedtls_mpi_free(&L);
+     360                 :            : 
+     361                 :            :     /* Wrap MPI error codes by RSA check failure error code */
+     362   [ #  #  #  # ]:          0 :     if (ret != 0 && ret != MBEDTLS_ERR_RSA_KEY_CHECK_FAILED) {
+     363                 :          0 :         ret += MBEDTLS_ERR_RSA_KEY_CHECK_FAILED;
+     364                 :            :     }
+     365                 :            : 
+     366                 :          0 :     return ret;
+     367                 :            : }
+     368                 :            : 
+     369                 :            : /*
+     370                 :            :  * Check that RSA CRT parameters are in accordance with core parameters.
+     371                 :            :  */
+     372                 :          0 : int mbedtls_rsa_validate_crt(const mbedtls_mpi *P,  const mbedtls_mpi *Q,
+     373                 :            :                              const mbedtls_mpi *D,  const mbedtls_mpi *DP,
+     374                 :            :                              const mbedtls_mpi *DQ, const mbedtls_mpi *QP)
+     375                 :            : {
+     376                 :          0 :     int ret = 0;
+     377                 :            : 
+     378                 :            :     mbedtls_mpi K, L;
+     379                 :          0 :     mbedtls_mpi_init(&K);
+     380                 :          0 :     mbedtls_mpi_init(&L);
+     381                 :            : 
+     382                 :            :     /* Check that DP - D == 0 mod P - 1 */
+     383         [ #  # ]:          0 :     if (DP != NULL) {
+     384         [ #  # ]:          0 :         if (P == NULL) {
+     385                 :          0 :             ret = MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+     386                 :          0 :             goto cleanup;
+     387                 :            :         }
+     388                 :            : 
+     389         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&K, P, 1));
+     390         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&L, DP, D));
+     391         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&L, &L, &K));
+     392                 :            : 
+     393         [ #  # ]:          0 :         if (mbedtls_mpi_cmp_int(&L, 0) != 0) {
+     394                 :          0 :             ret = MBEDTLS_ERR_RSA_KEY_CHECK_FAILED;
+     395                 :          0 :             goto cleanup;
+     396                 :            :         }
+     397                 :            :     }
+     398                 :            : 
+     399                 :            :     /* Check that DQ - D == 0 mod Q - 1 */
+     400         [ #  # ]:          0 :     if (DQ != NULL) {
+     401         [ #  # ]:          0 :         if (Q == NULL) {
+     402                 :          0 :             ret = MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+     403                 :          0 :             goto cleanup;
+     404                 :            :         }
+     405                 :            : 
+     406         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&K, Q, 1));
+     407         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&L, DQ, D));
+     408         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&L, &L, &K));
+     409                 :            : 
+     410         [ #  # ]:          0 :         if (mbedtls_mpi_cmp_int(&L, 0) != 0) {
+     411                 :          0 :             ret = MBEDTLS_ERR_RSA_KEY_CHECK_FAILED;
+     412                 :          0 :             goto cleanup;
+     413                 :            :         }
+     414                 :            :     }
+     415                 :            : 
+     416                 :            :     /* Check that QP * Q - 1 == 0 mod P */
+     417         [ #  # ]:          0 :     if (QP != NULL) {
+     418   [ #  #  #  # ]:          0 :         if (P == NULL || Q == NULL) {
+     419                 :          0 :             ret = MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
+     420                 :          0 :             goto cleanup;
+     421                 :            :         }
+     422                 :            : 
+     423         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&K, QP, Q));
+     424         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&K, &K, 1));
+     425         [ #  # ]:          0 :         MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&K, &K, P));
+     426         [ #  # ]:          0 :         if (mbedtls_mpi_cmp_int(&K, 0) != 0) {
+     427                 :          0 :             ret = MBEDTLS_ERR_RSA_KEY_CHECK_FAILED;
+     428                 :          0 :             goto cleanup;
+     429                 :            :         }
+     430                 :            :     }
+     431                 :            : 
+     432                 :          0 : cleanup:
+     433                 :            : 
+     434                 :            :     /* Wrap MPI error codes by RSA check failure error code */
+     435   [ #  #  #  # ]:          0 :     if (ret != 0 &&
+     436         [ #  # ]:          0 :         ret != MBEDTLS_ERR_RSA_KEY_CHECK_FAILED &&
+     437                 :            :         ret != MBEDTLS_ERR_RSA_BAD_INPUT_DATA) {
+     438                 :          0 :         ret += MBEDTLS_ERR_RSA_KEY_CHECK_FAILED;
+     439                 :            :     }
+     440                 :            : 
+     441                 :          0 :     mbedtls_mpi_free(&K);
+     442                 :          0 :     mbedtls_mpi_free(&L);
+     443                 :            : 
+     444                 :          0 :     return ret;
+     445                 :            : }
+     446                 :            : 
+     447                 :            : #endif /* MBEDTLS_RSA_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/sha1.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/sha1.c.func-sort-c.html new file mode 100644 index 00000000000..b6daba61d52 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/sha1.c.func-sort-c.html @@ -0,0 +1,117 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/sha1.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - sha1.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:02250.0 %
Date:2024-09-22 08:21:07Functions:090.0 %
Branches:0540.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_internal_sha1_process0
mbedtls_sha10
mbedtls_sha1_clone0
mbedtls_sha1_finish0
mbedtls_sha1_free0
mbedtls_sha1_init0
mbedtls_sha1_self_test0
mbedtls_sha1_starts0
mbedtls_sha1_update0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/sha1.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/sha1.c.func.html new file mode 100644 index 00000000000..87d81ba3ea8 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/sha1.c.func.html @@ -0,0 +1,117 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/sha1.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - sha1.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:02250.0 %
Date:2024-09-22 08:21:07Functions:090.0 %
Branches:0540.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_internal_sha1_process0
mbedtls_sha10
mbedtls_sha1_clone0
mbedtls_sha1_finish0
mbedtls_sha1_free0
mbedtls_sha1_init0
mbedtls_sha1_self_test0
mbedtls_sha1_starts0
mbedtls_sha1_update0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/sha1.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/sha1.c.gcov.html new file mode 100644 index 00000000000..b6b017f873e --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/sha1.c.gcov.html @@ -0,0 +1,565 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/sha1.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - sha1.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:02250.0 %
Date:2024-09-22 08:21:07Functions:090.0 %
Branches:0540.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  *  FIPS-180-1 compliant SHA-1 implementation
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  */
+       7                 :            : /*
+       8                 :            :  *  The SHA-1 standard was published by NIST in 1993.
+       9                 :            :  *
+      10                 :            :  *  http://www.itl.nist.gov/fipspubs/fip180-1.htm
+      11                 :            :  */
+      12                 :            : 
+      13                 :            : #include "common.h"
+      14                 :            : 
+      15                 :            : #if defined(MBEDTLS_SHA1_C)
+      16                 :            : 
+      17                 :            : #include "mbedtls/sha1.h"
+      18                 :            : #include "mbedtls/platform_util.h"
+      19                 :            : #include "mbedtls/error.h"
+      20                 :            : 
+      21                 :            : #include <string.h>
+      22                 :            : 
+      23                 :            : #include "mbedtls/platform.h"
+      24                 :            : 
+      25                 :            : #if !defined(MBEDTLS_SHA1_ALT)
+      26                 :            : 
+      27                 :          0 : void mbedtls_sha1_init(mbedtls_sha1_context *ctx)
+      28                 :            : {
+      29                 :          0 :     memset(ctx, 0, sizeof(mbedtls_sha1_context));
+      30                 :          0 : }
+      31                 :            : 
+      32                 :          0 : void mbedtls_sha1_free(mbedtls_sha1_context *ctx)
+      33                 :            : {
+      34         [ #  # ]:          0 :     if (ctx == NULL) {
+      35                 :          0 :         return;
+      36                 :            :     }
+      37                 :            : 
+      38                 :          0 :     mbedtls_platform_zeroize(ctx, sizeof(mbedtls_sha1_context));
+      39                 :            : }
+      40                 :            : 
+      41                 :          0 : void mbedtls_sha1_clone(mbedtls_sha1_context *dst,
+      42                 :            :                         const mbedtls_sha1_context *src)
+      43                 :            : {
+      44                 :          0 :     *dst = *src;
+      45                 :          0 : }
+      46                 :            : 
+      47                 :            : /*
+      48                 :            :  * SHA-1 context setup
+      49                 :            :  */
+      50                 :          0 : int mbedtls_sha1_starts(mbedtls_sha1_context *ctx)
+      51                 :            : {
+      52                 :          0 :     ctx->total[0] = 0;
+      53                 :          0 :     ctx->total[1] = 0;
+      54                 :            : 
+      55                 :          0 :     ctx->state[0] = 0x67452301;
+      56                 :          0 :     ctx->state[1] = 0xEFCDAB89;
+      57                 :          0 :     ctx->state[2] = 0x98BADCFE;
+      58                 :          0 :     ctx->state[3] = 0x10325476;
+      59                 :          0 :     ctx->state[4] = 0xC3D2E1F0;
+      60                 :            : 
+      61                 :          0 :     return 0;
+      62                 :            : }
+      63                 :            : 
+      64                 :            : #if !defined(MBEDTLS_SHA1_PROCESS_ALT)
+      65                 :          0 : int mbedtls_internal_sha1_process(mbedtls_sha1_context *ctx,
+      66                 :            :                                   const unsigned char data[64])
+      67                 :            : {
+      68                 :            :     struct {
+      69                 :            :         uint32_t temp, W[16], A, B, C, D, E;
+      70                 :            :     } local;
+      71                 :            : 
+      72                 :          0 :     local.W[0] = MBEDTLS_GET_UINT32_BE(data,  0);
+      73                 :          0 :     local.W[1] = MBEDTLS_GET_UINT32_BE(data,  4);
+      74                 :          0 :     local.W[2] = MBEDTLS_GET_UINT32_BE(data,  8);
+      75                 :          0 :     local.W[3] = MBEDTLS_GET_UINT32_BE(data, 12);
+      76                 :          0 :     local.W[4] = MBEDTLS_GET_UINT32_BE(data, 16);
+      77                 :          0 :     local.W[5] = MBEDTLS_GET_UINT32_BE(data, 20);
+      78                 :          0 :     local.W[6] = MBEDTLS_GET_UINT32_BE(data, 24);
+      79                 :          0 :     local.W[7] = MBEDTLS_GET_UINT32_BE(data, 28);
+      80                 :          0 :     local.W[8] = MBEDTLS_GET_UINT32_BE(data, 32);
+      81                 :          0 :     local.W[9] = MBEDTLS_GET_UINT32_BE(data, 36);
+      82                 :          0 :     local.W[10] = MBEDTLS_GET_UINT32_BE(data, 40);
+      83                 :          0 :     local.W[11] = MBEDTLS_GET_UINT32_BE(data, 44);
+      84                 :          0 :     local.W[12] = MBEDTLS_GET_UINT32_BE(data, 48);
+      85                 :          0 :     local.W[13] = MBEDTLS_GET_UINT32_BE(data, 52);
+      86                 :          0 :     local.W[14] = MBEDTLS_GET_UINT32_BE(data, 56);
+      87                 :          0 :     local.W[15] = MBEDTLS_GET_UINT32_BE(data, 60);
+      88                 :            : 
+      89                 :            : #define S(x, n) (((x) << (n)) | (((x) & 0xFFFFFFFF) >> (32 - (n))))
+      90                 :            : 
+      91                 :            : #define R(t)                                                    \
+      92                 :            :     (                                                           \
+      93                 :            :         local.temp = local.W[((t) -  3) & 0x0F] ^             \
+      94                 :            :                      local.W[((t) -  8) & 0x0F] ^             \
+      95                 :            :                      local.W[((t) - 14) & 0x0F] ^             \
+      96                 :            :                      local.W[(t)        & 0x0F],              \
+      97                 :            :         (local.W[(t) & 0x0F] = S(local.temp, 1))               \
+      98                 :            :     )
+      99                 :            : 
+     100                 :            : #define P(a, b, c, d, e, x)                                          \
+     101                 :            :     do                                                          \
+     102                 :            :     {                                                           \
+     103                 :            :         (e) += S((a), 5) + F((b), (c), (d)) + K + (x);             \
+     104                 :            :         (b) = S((b), 30);                                        \
+     105                 :            :     } while (0)
+     106                 :            : 
+     107                 :          0 :     local.A = ctx->state[0];
+     108                 :          0 :     local.B = ctx->state[1];
+     109                 :          0 :     local.C = ctx->state[2];
+     110                 :          0 :     local.D = ctx->state[3];
+     111                 :          0 :     local.E = ctx->state[4];
+     112                 :            : 
+     113                 :            : #define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
+     114                 :            : #define K 0x5A827999
+     115                 :            : 
+     116                 :          0 :     P(local.A, local.B, local.C, local.D, local.E, local.W[0]);
+     117                 :          0 :     P(local.E, local.A, local.B, local.C, local.D, local.W[1]);
+     118                 :          0 :     P(local.D, local.E, local.A, local.B, local.C, local.W[2]);
+     119                 :          0 :     P(local.C, local.D, local.E, local.A, local.B, local.W[3]);
+     120                 :          0 :     P(local.B, local.C, local.D, local.E, local.A, local.W[4]);
+     121                 :          0 :     P(local.A, local.B, local.C, local.D, local.E, local.W[5]);
+     122                 :          0 :     P(local.E, local.A, local.B, local.C, local.D, local.W[6]);
+     123                 :          0 :     P(local.D, local.E, local.A, local.B, local.C, local.W[7]);
+     124                 :          0 :     P(local.C, local.D, local.E, local.A, local.B, local.W[8]);
+     125                 :          0 :     P(local.B, local.C, local.D, local.E, local.A, local.W[9]);
+     126                 :          0 :     P(local.A, local.B, local.C, local.D, local.E, local.W[10]);
+     127                 :          0 :     P(local.E, local.A, local.B, local.C, local.D, local.W[11]);
+     128                 :          0 :     P(local.D, local.E, local.A, local.B, local.C, local.W[12]);
+     129                 :          0 :     P(local.C, local.D, local.E, local.A, local.B, local.W[13]);
+     130                 :          0 :     P(local.B, local.C, local.D, local.E, local.A, local.W[14]);
+     131                 :          0 :     P(local.A, local.B, local.C, local.D, local.E, local.W[15]);
+     132                 :          0 :     P(local.E, local.A, local.B, local.C, local.D, R(16));
+     133                 :          0 :     P(local.D, local.E, local.A, local.B, local.C, R(17));
+     134                 :          0 :     P(local.C, local.D, local.E, local.A, local.B, R(18));
+     135                 :          0 :     P(local.B, local.C, local.D, local.E, local.A, R(19));
+     136                 :            : 
+     137                 :            : #undef K
+     138                 :            : #undef F
+     139                 :            : 
+     140                 :            : #define F(x, y, z) ((x) ^ (y) ^ (z))
+     141                 :            : #define K 0x6ED9EBA1
+     142                 :            : 
+     143                 :          0 :     P(local.A, local.B, local.C, local.D, local.E, R(20));
+     144                 :          0 :     P(local.E, local.A, local.B, local.C, local.D, R(21));
+     145                 :          0 :     P(local.D, local.E, local.A, local.B, local.C, R(22));
+     146                 :          0 :     P(local.C, local.D, local.E, local.A, local.B, R(23));
+     147                 :          0 :     P(local.B, local.C, local.D, local.E, local.A, R(24));
+     148                 :          0 :     P(local.A, local.B, local.C, local.D, local.E, R(25));
+     149                 :          0 :     P(local.E, local.A, local.B, local.C, local.D, R(26));
+     150                 :          0 :     P(local.D, local.E, local.A, local.B, local.C, R(27));
+     151                 :          0 :     P(local.C, local.D, local.E, local.A, local.B, R(28));
+     152                 :          0 :     P(local.B, local.C, local.D, local.E, local.A, R(29));
+     153                 :          0 :     P(local.A, local.B, local.C, local.D, local.E, R(30));
+     154                 :          0 :     P(local.E, local.A, local.B, local.C, local.D, R(31));
+     155                 :          0 :     P(local.D, local.E, local.A, local.B, local.C, R(32));
+     156                 :          0 :     P(local.C, local.D, local.E, local.A, local.B, R(33));
+     157                 :          0 :     P(local.B, local.C, local.D, local.E, local.A, R(34));
+     158                 :          0 :     P(local.A, local.B, local.C, local.D, local.E, R(35));
+     159                 :          0 :     P(local.E, local.A, local.B, local.C, local.D, R(36));
+     160                 :          0 :     P(local.D, local.E, local.A, local.B, local.C, R(37));
+     161                 :          0 :     P(local.C, local.D, local.E, local.A, local.B, R(38));
+     162                 :          0 :     P(local.B, local.C, local.D, local.E, local.A, R(39));
+     163                 :            : 
+     164                 :            : #undef K
+     165                 :            : #undef F
+     166                 :            : 
+     167                 :            : #define F(x, y, z) (((x) & (y)) | ((z) & ((x) | (y))))
+     168                 :            : #define K 0x8F1BBCDC
+     169                 :            : 
+     170                 :          0 :     P(local.A, local.B, local.C, local.D, local.E, R(40));
+     171                 :          0 :     P(local.E, local.A, local.B, local.C, local.D, R(41));
+     172                 :          0 :     P(local.D, local.E, local.A, local.B, local.C, R(42));
+     173                 :          0 :     P(local.C, local.D, local.E, local.A, local.B, R(43));
+     174                 :          0 :     P(local.B, local.C, local.D, local.E, local.A, R(44));
+     175                 :          0 :     P(local.A, local.B, local.C, local.D, local.E, R(45));
+     176                 :          0 :     P(local.E, local.A, local.B, local.C, local.D, R(46));
+     177                 :          0 :     P(local.D, local.E, local.A, local.B, local.C, R(47));
+     178                 :          0 :     P(local.C, local.D, local.E, local.A, local.B, R(48));
+     179                 :          0 :     P(local.B, local.C, local.D, local.E, local.A, R(49));
+     180                 :          0 :     P(local.A, local.B, local.C, local.D, local.E, R(50));
+     181                 :          0 :     P(local.E, local.A, local.B, local.C, local.D, R(51));
+     182                 :          0 :     P(local.D, local.E, local.A, local.B, local.C, R(52));
+     183                 :          0 :     P(local.C, local.D, local.E, local.A, local.B, R(53));
+     184                 :          0 :     P(local.B, local.C, local.D, local.E, local.A, R(54));
+     185                 :          0 :     P(local.A, local.B, local.C, local.D, local.E, R(55));
+     186                 :          0 :     P(local.E, local.A, local.B, local.C, local.D, R(56));
+     187                 :          0 :     P(local.D, local.E, local.A, local.B, local.C, R(57));
+     188                 :          0 :     P(local.C, local.D, local.E, local.A, local.B, R(58));
+     189                 :          0 :     P(local.B, local.C, local.D, local.E, local.A, R(59));
+     190                 :            : 
+     191                 :            : #undef K
+     192                 :            : #undef F
+     193                 :            : 
+     194                 :            : #define F(x, y, z) ((x) ^ (y) ^ (z))
+     195                 :            : #define K 0xCA62C1D6
+     196                 :            : 
+     197                 :          0 :     P(local.A, local.B, local.C, local.D, local.E, R(60));
+     198                 :          0 :     P(local.E, local.A, local.B, local.C, local.D, R(61));
+     199                 :          0 :     P(local.D, local.E, local.A, local.B, local.C, R(62));
+     200                 :          0 :     P(local.C, local.D, local.E, local.A, local.B, R(63));
+     201                 :          0 :     P(local.B, local.C, local.D, local.E, local.A, R(64));
+     202                 :          0 :     P(local.A, local.B, local.C, local.D, local.E, R(65));
+     203                 :          0 :     P(local.E, local.A, local.B, local.C, local.D, R(66));
+     204                 :          0 :     P(local.D, local.E, local.A, local.B, local.C, R(67));
+     205                 :          0 :     P(local.C, local.D, local.E, local.A, local.B, R(68));
+     206                 :          0 :     P(local.B, local.C, local.D, local.E, local.A, R(69));
+     207                 :          0 :     P(local.A, local.B, local.C, local.D, local.E, R(70));
+     208                 :          0 :     P(local.E, local.A, local.B, local.C, local.D, R(71));
+     209                 :          0 :     P(local.D, local.E, local.A, local.B, local.C, R(72));
+     210                 :          0 :     P(local.C, local.D, local.E, local.A, local.B, R(73));
+     211                 :          0 :     P(local.B, local.C, local.D, local.E, local.A, R(74));
+     212                 :          0 :     P(local.A, local.B, local.C, local.D, local.E, R(75));
+     213                 :          0 :     P(local.E, local.A, local.B, local.C, local.D, R(76));
+     214                 :          0 :     P(local.D, local.E, local.A, local.B, local.C, R(77));
+     215                 :          0 :     P(local.C, local.D, local.E, local.A, local.B, R(78));
+     216                 :          0 :     P(local.B, local.C, local.D, local.E, local.A, R(79));
+     217                 :            : 
+     218                 :            : #undef K
+     219                 :            : #undef F
+     220                 :            : 
+     221                 :          0 :     ctx->state[0] += local.A;
+     222                 :          0 :     ctx->state[1] += local.B;
+     223                 :          0 :     ctx->state[2] += local.C;
+     224                 :          0 :     ctx->state[3] += local.D;
+     225                 :          0 :     ctx->state[4] += local.E;
+     226                 :            : 
+     227                 :            :     /* Zeroise buffers and variables to clear sensitive data from memory. */
+     228                 :          0 :     mbedtls_platform_zeroize(&local, sizeof(local));
+     229                 :            : 
+     230                 :          0 :     return 0;
+     231                 :            : }
+     232                 :            : 
+     233                 :            : #endif /* !MBEDTLS_SHA1_PROCESS_ALT */
+     234                 :            : 
+     235                 :            : /*
+     236                 :            :  * SHA-1 process buffer
+     237                 :            :  */
+     238                 :          0 : int mbedtls_sha1_update(mbedtls_sha1_context *ctx,
+     239                 :            :                         const unsigned char *input,
+     240                 :            :                         size_t ilen)
+     241                 :            : {
+     242                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     243                 :            :     size_t fill;
+     244                 :            :     uint32_t left;
+     245                 :            : 
+     246         [ #  # ]:          0 :     if (ilen == 0) {
+     247                 :          0 :         return 0;
+     248                 :            :     }
+     249                 :            : 
+     250                 :          0 :     left = ctx->total[0] & 0x3F;
+     251                 :          0 :     fill = 64 - left;
+     252                 :            : 
+     253                 :          0 :     ctx->total[0] += (uint32_t) ilen;
+     254                 :          0 :     ctx->total[0] &= 0xFFFFFFFF;
+     255                 :            : 
+     256         [ #  # ]:          0 :     if (ctx->total[0] < (uint32_t) ilen) {
+     257                 :          0 :         ctx->total[1]++;
+     258                 :            :     }
+     259                 :            : 
+     260   [ #  #  #  # ]:          0 :     if (left && ilen >= fill) {
+     261                 :          0 :         memcpy((void *) (ctx->buffer + left), input, fill);
+     262                 :            : 
+     263         [ #  # ]:          0 :         if ((ret = mbedtls_internal_sha1_process(ctx, ctx->buffer)) != 0) {
+     264                 :          0 :             return ret;
+     265                 :            :         }
+     266                 :            : 
+     267                 :          0 :         input += fill;
+     268                 :          0 :         ilen  -= fill;
+     269                 :          0 :         left = 0;
+     270                 :            :     }
+     271                 :            : 
+     272         [ #  # ]:          0 :     while (ilen >= 64) {
+     273         [ #  # ]:          0 :         if ((ret = mbedtls_internal_sha1_process(ctx, input)) != 0) {
+     274                 :          0 :             return ret;
+     275                 :            :         }
+     276                 :            : 
+     277                 :          0 :         input += 64;
+     278                 :          0 :         ilen  -= 64;
+     279                 :            :     }
+     280                 :            : 
+     281         [ #  # ]:          0 :     if (ilen > 0) {
+     282                 :          0 :         memcpy((void *) (ctx->buffer + left), input, ilen);
+     283                 :            :     }
+     284                 :            : 
+     285                 :          0 :     return 0;
+     286                 :            : }
+     287                 :            : 
+     288                 :            : /*
+     289                 :            :  * SHA-1 final digest
+     290                 :            :  */
+     291                 :          0 : int mbedtls_sha1_finish(mbedtls_sha1_context *ctx,
+     292                 :            :                         unsigned char output[20])
+     293                 :            : {
+     294                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     295                 :            :     uint32_t used;
+     296                 :            :     uint32_t high, low;
+     297                 :            : 
+     298                 :            :     /*
+     299                 :            :      * Add padding: 0x80 then 0x00 until 8 bytes remain for the length
+     300                 :            :      */
+     301                 :          0 :     used = ctx->total[0] & 0x3F;
+     302                 :            : 
+     303                 :          0 :     ctx->buffer[used++] = 0x80;
+     304                 :            : 
+     305         [ #  # ]:          0 :     if (used <= 56) {
+     306                 :            :         /* Enough room for padding + length in current block */
+     307                 :          0 :         memset(ctx->buffer + used, 0, 56 - used);
+     308                 :            :     } else {
+     309                 :            :         /* We'll need an extra block */
+     310                 :          0 :         memset(ctx->buffer + used, 0, 64 - used);
+     311                 :            : 
+     312         [ #  # ]:          0 :         if ((ret = mbedtls_internal_sha1_process(ctx, ctx->buffer)) != 0) {
+     313                 :          0 :             goto exit;
+     314                 :            :         }
+     315                 :            : 
+     316                 :          0 :         memset(ctx->buffer, 0, 56);
+     317                 :            :     }
+     318                 :            : 
+     319                 :            :     /*
+     320                 :            :      * Add message length
+     321                 :            :      */
+     322                 :          0 :     high = (ctx->total[0] >> 29)
+     323                 :          0 :            | (ctx->total[1] <<  3);
+     324                 :          0 :     low  = (ctx->total[0] <<  3);
+     325                 :            : 
+     326                 :          0 :     MBEDTLS_PUT_UINT32_BE(high, ctx->buffer, 56);
+     327                 :          0 :     MBEDTLS_PUT_UINT32_BE(low,  ctx->buffer, 60);
+     328                 :            : 
+     329         [ #  # ]:          0 :     if ((ret = mbedtls_internal_sha1_process(ctx, ctx->buffer)) != 0) {
+     330                 :          0 :         goto exit;
+     331                 :            :     }
+     332                 :            : 
+     333                 :            :     /*
+     334                 :            :      * Output final state
+     335                 :            :      */
+     336                 :          0 :     MBEDTLS_PUT_UINT32_BE(ctx->state[0], output,  0);
+     337                 :          0 :     MBEDTLS_PUT_UINT32_BE(ctx->state[1], output,  4);
+     338                 :          0 :     MBEDTLS_PUT_UINT32_BE(ctx->state[2], output,  8);
+     339                 :          0 :     MBEDTLS_PUT_UINT32_BE(ctx->state[3], output, 12);
+     340                 :          0 :     MBEDTLS_PUT_UINT32_BE(ctx->state[4], output, 16);
+     341                 :            : 
+     342                 :          0 :     ret = 0;
+     343                 :            : 
+     344                 :          0 : exit:
+     345                 :          0 :     mbedtls_sha1_free(ctx);
+     346                 :          0 :     return ret;
+     347                 :            : }
+     348                 :            : 
+     349                 :            : #endif /* !MBEDTLS_SHA1_ALT */
+     350                 :            : 
+     351                 :            : /*
+     352                 :            :  * output = SHA-1( input buffer )
+     353                 :            :  */
+     354                 :          0 : int mbedtls_sha1(const unsigned char *input,
+     355                 :            :                  size_t ilen,
+     356                 :            :                  unsigned char output[20])
+     357                 :            : {
+     358                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     359                 :            :     mbedtls_sha1_context ctx;
+     360                 :            : 
+     361                 :          0 :     mbedtls_sha1_init(&ctx);
+     362                 :            : 
+     363         [ #  # ]:          0 :     if ((ret = mbedtls_sha1_starts(&ctx)) != 0) {
+     364                 :          0 :         goto exit;
+     365                 :            :     }
+     366                 :            : 
+     367         [ #  # ]:          0 :     if ((ret = mbedtls_sha1_update(&ctx, input, ilen)) != 0) {
+     368                 :          0 :         goto exit;
+     369                 :            :     }
+     370                 :            : 
+     371         [ #  # ]:          0 :     if ((ret = mbedtls_sha1_finish(&ctx, output)) != 0) {
+     372                 :          0 :         goto exit;
+     373                 :            :     }
+     374                 :            : 
+     375                 :          0 : exit:
+     376                 :          0 :     mbedtls_sha1_free(&ctx);
+     377                 :          0 :     return ret;
+     378                 :            : }
+     379                 :            : 
+     380                 :            : #if defined(MBEDTLS_SELF_TEST)
+     381                 :            : /*
+     382                 :            :  * FIPS-180-1 test vectors
+     383                 :            :  */
+     384                 :            : static const unsigned char sha1_test_buf[3][57] =
+     385                 :            : {
+     386                 :            :     { "abc" },
+     387                 :            :     { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" },
+     388                 :            :     { "" }
+     389                 :            : };
+     390                 :            : 
+     391                 :            : static const size_t sha1_test_buflen[3] =
+     392                 :            : {
+     393                 :            :     3, 56, 1000
+     394                 :            : };
+     395                 :            : 
+     396                 :            : static const unsigned char sha1_test_sum[3][20] =
+     397                 :            : {
+     398                 :            :     { 0xA9, 0x99, 0x3E, 0x36, 0x47, 0x06, 0x81, 0x6A, 0xBA, 0x3E,
+     399                 :            :       0x25, 0x71, 0x78, 0x50, 0xC2, 0x6C, 0x9C, 0xD0, 0xD8, 0x9D },
+     400                 :            :     { 0x84, 0x98, 0x3E, 0x44, 0x1C, 0x3B, 0xD2, 0x6E, 0xBA, 0xAE,
+     401                 :            :       0x4A, 0xA1, 0xF9, 0x51, 0x29, 0xE5, 0xE5, 0x46, 0x70, 0xF1 },
+     402                 :            :     { 0x34, 0xAA, 0x97, 0x3C, 0xD4, 0xC4, 0xDA, 0xA4, 0xF6, 0x1E,
+     403                 :            :       0xEB, 0x2B, 0xDB, 0xAD, 0x27, 0x31, 0x65, 0x34, 0x01, 0x6F }
+     404                 :            : };
+     405                 :            : 
+     406                 :            : /*
+     407                 :            :  * Checkup routine
+     408                 :            :  */
+     409                 :          0 : int mbedtls_sha1_self_test(int verbose)
+     410                 :            : {
+     411                 :          0 :     int i, j, buflen, ret = 0;
+     412                 :            :     unsigned char buf[1024];
+     413                 :            :     unsigned char sha1sum[20];
+     414                 :            :     mbedtls_sha1_context ctx;
+     415                 :            : 
+     416                 :          0 :     mbedtls_sha1_init(&ctx);
+     417                 :            : 
+     418                 :            :     /*
+     419                 :            :      * SHA-1
+     420                 :            :      */
+     421         [ #  # ]:          0 :     for (i = 0; i < 3; i++) {
+     422         [ #  # ]:          0 :         if (verbose != 0) {
+     423                 :          0 :             mbedtls_printf("  SHA-1 test #%d: ", i + 1);
+     424                 :            :         }
+     425                 :            : 
+     426         [ #  # ]:          0 :         if ((ret = mbedtls_sha1_starts(&ctx)) != 0) {
+     427                 :          0 :             goto fail;
+     428                 :            :         }
+     429                 :            : 
+     430         [ #  # ]:          0 :         if (i == 2) {
+     431                 :          0 :             memset(buf, 'a', buflen = 1000);
+     432                 :            : 
+     433         [ #  # ]:          0 :             for (j = 0; j < 1000; j++) {
+     434                 :          0 :                 ret = mbedtls_sha1_update(&ctx, buf, buflen);
+     435         [ #  # ]:          0 :                 if (ret != 0) {
+     436                 :          0 :                     goto fail;
+     437                 :            :                 }
+     438                 :            :             }
+     439                 :            :         } else {
+     440                 :          0 :             ret = mbedtls_sha1_update(&ctx, sha1_test_buf[i],
+     441                 :          0 :                                       sha1_test_buflen[i]);
+     442         [ #  # ]:          0 :             if (ret != 0) {
+     443                 :          0 :                 goto fail;
+     444                 :            :             }
+     445                 :            :         }
+     446                 :            : 
+     447         [ #  # ]:          0 :         if ((ret = mbedtls_sha1_finish(&ctx, sha1sum)) != 0) {
+     448                 :          0 :             goto fail;
+     449                 :            :         }
+     450                 :            : 
+     451         [ #  # ]:          0 :         if (memcmp(sha1sum, sha1_test_sum[i], 20) != 0) {
+     452                 :          0 :             ret = 1;
+     453                 :          0 :             goto fail;
+     454                 :            :         }
+     455                 :            : 
+     456         [ #  # ]:          0 :         if (verbose != 0) {
+     457                 :          0 :             mbedtls_printf("passed\n");
+     458                 :            :         }
+     459                 :            :     }
+     460                 :            : 
+     461         [ #  # ]:          0 :     if (verbose != 0) {
+     462                 :          0 :         mbedtls_printf("\n");
+     463                 :            :     }
+     464                 :            : 
+     465                 :          0 :     goto exit;
+     466                 :            : 
+     467                 :          0 : fail:
+     468         [ #  # ]:          0 :     if (verbose != 0) {
+     469                 :          0 :         mbedtls_printf("failed\n");
+     470                 :            :     }
+     471                 :            : 
+     472                 :          0 : exit:
+     473                 :          0 :     mbedtls_sha1_free(&ctx);
+     474                 :            : 
+     475                 :          0 :     return ret;
+     476                 :            : }
+     477                 :            : 
+     478                 :            : #endif /* MBEDTLS_SELF_TEST */
+     479                 :            : 
+     480                 :            : #endif /* MBEDTLS_SHA1_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/sha256.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/sha256.c.func-sort-c.html new file mode 100644 index 00000000000..bf7dbfdfc3c --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/sha256.c.func-sort-c.html @@ -0,0 +1,129 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/sha256.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - sha256.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:12218765.2 %
Date:2024-09-22 08:21:07Functions:91275.0 %
Branches:388644.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_sha224_self_test0
mbedtls_sha256_common_self_test0
mbedtls_sha256_self_test0
mbedtls_sha256_clone390
mbedtls_sha2563187
mbedtls_sha256_init5354
mbedtls_sha256_finish7193
mbedtls_internal_sha256_process_many7240
mbedtls_sha256_starts7255
mbedtls_sha256_free13262
mbedtls_sha256_update23563
mbedtls_internal_sha256_process44956
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/sha256.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/sha256.c.func.html new file mode 100644 index 00000000000..7e6ce30880f --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/sha256.c.func.html @@ -0,0 +1,129 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/sha256.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - sha256.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:12218765.2 %
Date:2024-09-22 08:21:07Functions:91275.0 %
Branches:388644.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_internal_sha256_process44956
mbedtls_internal_sha256_process_many7240
mbedtls_sha224_self_test0
mbedtls_sha2563187
mbedtls_sha256_clone390
mbedtls_sha256_common_self_test0
mbedtls_sha256_finish7193
mbedtls_sha256_free13262
mbedtls_sha256_init5354
mbedtls_sha256_self_test0
mbedtls_sha256_starts7255
mbedtls_sha256_update23563
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/sha256.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/sha256.c.gcov.html new file mode 100644 index 00000000000..28a8b7fe04d --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/sha256.c.gcov.html @@ -0,0 +1,1061 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/sha256.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - sha256.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:12218765.2 %
Date:2024-09-22 08:21:07Functions:91275.0 %
Branches:388644.2 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  *  FIPS-180-2 compliant SHA-256 implementation
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  */
+       7                 :            : /*
+       8                 :            :  *  The SHA-256 Secure Hash Standard was published by NIST in 2002.
+       9                 :            :  *
+      10                 :            :  *  http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf
+      11                 :            :  */
+      12                 :            : 
+      13                 :            : #if defined(__clang__) &&  (__clang_major__ >= 4)
+      14                 :            : 
+      15                 :            : /* Ideally, we would simply use MBEDTLS_ARCH_IS_ARMV8_A in the following #if,
+      16                 :            :  * but that is defined by build_info.h, and we need this block to happen first. */
+      17                 :            : #if defined(__ARM_ARCH) && (__ARM_ARCH_PROFILE == 'A')
+      18                 :            : #if __ARM_ARCH >= 8
+      19                 :            : #define MBEDTLS_SHA256_ARCH_IS_ARMV8_A
+      20                 :            : #endif
+      21                 :            : #endif
+      22                 :            : 
+      23                 :            : #if defined(MBEDTLS_SHA256_ARCH_IS_ARMV8_A) && !defined(__ARM_FEATURE_CRYPTO)
+      24                 :            : /* TODO: Re-consider above after https://reviews.llvm.org/D131064 merged.
+      25                 :            :  *
+      26                 :            :  * The intrinsic declaration are guarded by predefined ACLE macros in clang:
+      27                 :            :  * these are normally only enabled by the -march option on the command line.
+      28                 :            :  * By defining the macros ourselves we gain access to those declarations without
+      29                 :            :  * requiring -march on the command line.
+      30                 :            :  *
+      31                 :            :  * `arm_neon.h` is included by common.h, so we put these defines
+      32                 :            :  * at the top of this file, before any includes.
+      33                 :            :  */
+      34                 :            : #define __ARM_FEATURE_CRYPTO 1
+      35                 :            : /* See: https://arm-software.github.io/acle/main/acle.html#cryptographic-extensions
+      36                 :            :  *
+      37                 :            :  * `__ARM_FEATURE_CRYPTO` is deprecated, but we need to continue to specify it
+      38                 :            :  * for older compilers.
+      39                 :            :  */
+      40                 :            : #define __ARM_FEATURE_SHA2   1
+      41                 :            : #define MBEDTLS_ENABLE_ARM_CRYPTO_EXTENSIONS_COMPILER_FLAG
+      42                 :            : #endif
+      43                 :            : 
+      44                 :            : #endif /* defined(__clang__) &&  (__clang_major__ >= 4) */
+      45                 :            : 
+      46                 :            : /* Ensure that SIG_SETMASK is defined when -std=c99 is used. */
+      47                 :            : #define _GNU_SOURCE
+      48                 :            : 
+      49                 :            : #include "common.h"
+      50                 :            : 
+      51                 :            : #if defined(MBEDTLS_SHA256_C) || defined(MBEDTLS_SHA224_C)
+      52                 :            : 
+      53                 :            : #include "mbedtls/sha256.h"
+      54                 :            : #include "mbedtls/platform_util.h"
+      55                 :            : #include "mbedtls/error.h"
+      56                 :            : 
+      57                 :            : #include <string.h>
+      58                 :            : 
+      59                 :            : #include "mbedtls/platform.h"
+      60                 :            : 
+      61                 :            : #if defined(MBEDTLS_ARCH_IS_ARMV8_A)
+      62                 :            : 
+      63                 :            : #  if defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT) || \
+      64                 :            :     defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY)
+      65                 :            : #       if !defined(MBEDTLS_HAVE_NEON_INTRINSICS)
+      66                 :            : #           if defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT)
+      67                 :            : #               warning "Target does not support NEON instructions"
+      68                 :            : #               undef MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
+      69                 :            : #           else
+      70                 :            : #               error "Target does not support NEON instructions"
+      71                 :            : #           endif
+      72                 :            : #       endif
+      73                 :            : #   endif
+      74                 :            : 
+      75                 :            : #  if defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT) || \
+      76                 :            :     defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY)
+      77                 :            : /* *INDENT-OFF* */
+      78                 :            : 
+      79                 :            : #   if !defined(__ARM_FEATURE_CRYPTO) || defined(MBEDTLS_ENABLE_ARM_CRYPTO_EXTENSIONS_COMPILER_FLAG)
+      80                 :            : #      if defined(__ARMCOMPILER_VERSION)
+      81                 :            : #        if __ARMCOMPILER_VERSION <= 6090000
+      82                 :            : #          error "Must use minimum -march=armv8-a+crypto for MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_*"
+      83                 :            : #        endif
+      84                 :            : #          pragma clang attribute push (__attribute__((target("sha2"))), apply_to=function)
+      85                 :            : #          define MBEDTLS_POP_TARGET_PRAGMA
+      86                 :            : #      elif defined(__clang__)
+      87                 :            : #        if __clang_major__ < 4
+      88                 :            : #          error "A more recent Clang is required for MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_*"
+      89                 :            : #        endif
+      90                 :            : #        pragma clang attribute push (__attribute__((target("crypto"))), apply_to=function)
+      91                 :            : #        define MBEDTLS_POP_TARGET_PRAGMA
+      92                 :            : #      elif defined(__GNUC__)
+      93                 :            :          /* FIXME: GCC 5 claims to support Armv8 Crypto Extensions, but some
+      94                 :            :           *        intrinsics are missing. Missing intrinsics could be worked around.
+      95                 :            :           */
+      96                 :            : #        if __GNUC__ < 6
+      97                 :            : #          error "A more recent GCC is required for MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_*"
+      98                 :            : #        else
+      99                 :            : #          pragma GCC push_options
+     100                 :            : #          pragma GCC target ("arch=armv8-a+crypto")
+     101                 :            : #          define MBEDTLS_POP_TARGET_PRAGMA
+     102                 :            : #        endif
+     103                 :            : #      else
+     104                 :            : #        error "Only GCC and Clang supported for MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_*"
+     105                 :            : #      endif
+     106                 :            : #    endif
+     107                 :            : /* *INDENT-ON* */
+     108                 :            : 
+     109                 :            : #  endif
+     110                 :            : #  if defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT)
+     111                 :            : #    if defined(__unix__)
+     112                 :            : #      if defined(__linux__)
+     113                 :            : /* Our preferred method of detection is getauxval() */
+     114                 :            : #        include <sys/auxv.h>
+     115                 :            : /* These are not always defined via sys/auxv.h */
+     116                 :            : #        if !defined(HWCAP_SHA2)
+     117                 :            : #          define HWCAP_SHA2  (1 << 6)
+     118                 :            : #        endif
+     119                 :            : #        if !defined(HWCAP2_SHA2)
+     120                 :            : #          define HWCAP2_SHA2 (1 << 3)
+     121                 :            : #        endif
+     122                 :            : #      endif
+     123                 :            : /* Use SIGILL on Unix, and fall back to it on Linux */
+     124                 :            : #      include <signal.h>
+     125                 :            : #    endif
+     126                 :            : #  endif
+     127                 :            : #elif !defined(MBEDTLS_PLATFORM_IS_WINDOWS_ON_ARM64)
+     128                 :            : #  undef MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY
+     129                 :            : #  undef MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
+     130                 :            : #endif
+     131                 :            : 
+     132                 :            : #if defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT)
+     133                 :            : /*
+     134                 :            :  * Capability detection code comes early, so we can disable
+     135                 :            :  * MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT if no detection mechanism found
+     136                 :            :  */
+     137                 :            : #if defined(MBEDTLS_ARCH_IS_ARM64) && defined(HWCAP_SHA2)
+     138                 :            : static int mbedtls_a64_crypto_sha256_determine_support(void)
+     139                 :            : {
+     140                 :            :     return (getauxval(AT_HWCAP) & HWCAP_SHA2) ? 1 : 0;
+     141                 :            : }
+     142                 :            : #elif defined(MBEDTLS_ARCH_IS_ARM32) && defined(HWCAP2_SHA2)
+     143                 :            : static int mbedtls_a64_crypto_sha256_determine_support(void)
+     144                 :            : {
+     145                 :            :     return (getauxval(AT_HWCAP2) & HWCAP2_SHA2) ? 1 : 0;
+     146                 :            : }
+     147                 :            : #elif defined(__APPLE__)
+     148                 :            : static int mbedtls_a64_crypto_sha256_determine_support(void)
+     149                 :            : {
+     150                 :            :     return 1;
+     151                 :            : }
+     152                 :            : #elif defined(MBEDTLS_PLATFORM_IS_WINDOWS_ON_ARM64)
+     153                 :            : #define WIN32_LEAN_AND_MEAN
+     154                 :            : #include <Windows.h>
+     155                 :            : #include <processthreadsapi.h>
+     156                 :            : 
+     157                 :            : static int mbedtls_a64_crypto_sha256_determine_support(void)
+     158                 :            : {
+     159                 :            :     return IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE) ?
+     160                 :            :            1 : 0;
+     161                 :            : }
+     162                 :            : #elif defined(__unix__) && defined(SIG_SETMASK)
+     163                 :            : /* Detection with SIGILL, setjmp() and longjmp() */
+     164                 :            : #include <signal.h>
+     165                 :            : #include <setjmp.h>
+     166                 :            : 
+     167                 :            : static jmp_buf return_from_sigill;
+     168                 :            : 
+     169                 :            : /*
+     170                 :            :  * Armv8-A SHA256 support detection via SIGILL
+     171                 :            :  */
+     172                 :            : static void sigill_handler(int signal)
+     173                 :            : {
+     174                 :            :     (void) signal;
+     175                 :            :     longjmp(return_from_sigill, 1);
+     176                 :            : }
+     177                 :            : 
+     178                 :            : static int mbedtls_a64_crypto_sha256_determine_support(void)
+     179                 :            : {
+     180                 :            :     struct sigaction old_action, new_action;
+     181                 :            : 
+     182                 :            :     sigset_t old_mask;
+     183                 :            :     if (sigprocmask(0, NULL, &old_mask)) {
+     184                 :            :         return 0;
+     185                 :            :     }
+     186                 :            : 
+     187                 :            :     sigemptyset(&new_action.sa_mask);
+     188                 :            :     new_action.sa_flags = 0;
+     189                 :            :     new_action.sa_handler = sigill_handler;
+     190                 :            : 
+     191                 :            :     sigaction(SIGILL, &new_action, &old_action);
+     192                 :            : 
+     193                 :            :     static int ret = 0;
+     194                 :            : 
+     195                 :            :     if (setjmp(return_from_sigill) == 0) {         /* First return only */
+     196                 :            :         /* If this traps, we will return a second time from setjmp() with 1 */
+     197                 :            : #if defined(MBEDTLS_ARCH_IS_ARM64)
+     198                 :            :         asm volatile ("sha256h q0, q0, v0.4s" : : : "v0");
+     199                 :            : #else
+     200                 :            :         asm volatile ("sha256h.32 q0, q0, q0" : : : "q0");
+     201                 :            : #endif
+     202                 :            :         ret = 1;
+     203                 :            :     }
+     204                 :            : 
+     205                 :            :     sigaction(SIGILL, &old_action, NULL);
+     206                 :            :     sigprocmask(SIG_SETMASK, &old_mask, NULL);
+     207                 :            : 
+     208                 :            :     return ret;
+     209                 :            : }
+     210                 :            : #else
+     211                 :            : #warning "No mechanism to detect ARMV8_CRYPTO found, using C code only"
+     212                 :            : #undef MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
+     213                 :            : #endif  /* HWCAP_SHA2, __APPLE__, __unix__ && SIG_SETMASK */
+     214                 :            : 
+     215                 :            : #endif  /* MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT */
+     216                 :            : 
+     217                 :            : #if !defined(MBEDTLS_SHA256_ALT)
+     218                 :            : 
+     219                 :            : #define SHA256_BLOCK_SIZE 64
+     220                 :            : 
+     221                 :       5354 : void mbedtls_sha256_init(mbedtls_sha256_context *ctx)
+     222                 :            : {
+     223                 :       5354 :     memset(ctx, 0, sizeof(mbedtls_sha256_context));
+     224                 :       5354 : }
+     225                 :            : 
+     226                 :      13262 : void mbedtls_sha256_free(mbedtls_sha256_context *ctx)
+     227                 :            : {
+     228         [ -  + ]:      13262 :     if (ctx == NULL) {
+     229                 :          0 :         return;
+     230                 :            :     }
+     231                 :            : 
+     232                 :      13262 :     mbedtls_platform_zeroize(ctx, sizeof(mbedtls_sha256_context));
+     233                 :            : }
+     234                 :            : 
+     235                 :        390 : void mbedtls_sha256_clone(mbedtls_sha256_context *dst,
+     236                 :            :                           const mbedtls_sha256_context *src)
+     237                 :            : {
+     238                 :        390 :     *dst = *src;
+     239                 :        390 : }
+     240                 :            : 
+     241                 :            : /*
+     242                 :            :  * SHA-256 context setup
+     243                 :            :  */
+     244                 :       7255 : int mbedtls_sha256_starts(mbedtls_sha256_context *ctx, int is224)
+     245                 :            : {
+     246                 :            : #if defined(MBEDTLS_SHA224_C) && defined(MBEDTLS_SHA256_C)
+     247   [ -  +  -  - ]:       7255 :     if (is224 != 0 && is224 != 1) {
+     248                 :          0 :         return MBEDTLS_ERR_SHA256_BAD_INPUT_DATA;
+     249                 :            :     }
+     250                 :            : #elif defined(MBEDTLS_SHA256_C)
+     251                 :            :     if (is224 != 0) {
+     252                 :            :         return MBEDTLS_ERR_SHA256_BAD_INPUT_DATA;
+     253                 :            :     }
+     254                 :            : #else /* defined MBEDTLS_SHA224_C only */
+     255                 :            :     if (is224 == 0) {
+     256                 :            :         return MBEDTLS_ERR_SHA256_BAD_INPUT_DATA;
+     257                 :            :     }
+     258                 :            : #endif
+     259                 :            : 
+     260                 :       7255 :     ctx->total[0] = 0;
+     261                 :       7255 :     ctx->total[1] = 0;
+     262                 :            : 
+     263         [ +  - ]:       7255 :     if (is224 == 0) {
+     264                 :            : #if defined(MBEDTLS_SHA256_C)
+     265                 :       7255 :         ctx->state[0] = 0x6A09E667;
+     266                 :       7255 :         ctx->state[1] = 0xBB67AE85;
+     267                 :       7255 :         ctx->state[2] = 0x3C6EF372;
+     268                 :       7255 :         ctx->state[3] = 0xA54FF53A;
+     269                 :       7255 :         ctx->state[4] = 0x510E527F;
+     270                 :       7255 :         ctx->state[5] = 0x9B05688C;
+     271                 :       7255 :         ctx->state[6] = 0x1F83D9AB;
+     272                 :       7255 :         ctx->state[7] = 0x5BE0CD19;
+     273                 :            : #endif
+     274                 :            :     } else {
+     275                 :            : #if defined(MBEDTLS_SHA224_C)
+     276                 :          0 :         ctx->state[0] = 0xC1059ED8;
+     277                 :          0 :         ctx->state[1] = 0x367CD507;
+     278                 :          0 :         ctx->state[2] = 0x3070DD17;
+     279                 :          0 :         ctx->state[3] = 0xF70E5939;
+     280                 :          0 :         ctx->state[4] = 0xFFC00B31;
+     281                 :          0 :         ctx->state[5] = 0x68581511;
+     282                 :          0 :         ctx->state[6] = 0x64F98FA7;
+     283                 :          0 :         ctx->state[7] = 0xBEFA4FA4;
+     284                 :            : #endif
+     285                 :            :     }
+     286                 :            : 
+     287                 :            : #if defined(MBEDTLS_SHA224_C)
+     288                 :       7255 :     ctx->is224 = is224;
+     289                 :            : #endif
+     290                 :            : 
+     291                 :       7255 :     return 0;
+     292                 :            : }
+     293                 :            : 
+     294                 :            : #if !defined(MBEDTLS_SHA256_PROCESS_ALT)
+     295                 :            : static const uint32_t K[] =
+     296                 :            : {
+     297                 :            :     0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5,
+     298                 :            :     0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5,
+     299                 :            :     0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3,
+     300                 :            :     0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174,
+     301                 :            :     0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC,
+     302                 :            :     0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA,
+     303                 :            :     0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7,
+     304                 :            :     0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967,
+     305                 :            :     0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13,
+     306                 :            :     0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85,
+     307                 :            :     0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3,
+     308                 :            :     0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070,
+     309                 :            :     0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5,
+     310                 :            :     0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3,
+     311                 :            :     0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208,
+     312                 :            :     0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2,
+     313                 :            : };
+     314                 :            : 
+     315                 :            : #endif
+     316                 :            : 
+     317                 :            : #if defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT) || \
+     318                 :            :     defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY)
+     319                 :            : 
+     320                 :            : #if defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY)
+     321                 :            : #  define mbedtls_internal_sha256_process_many_a64_crypto mbedtls_internal_sha256_process_many
+     322                 :            : #  define mbedtls_internal_sha256_process_a64_crypto      mbedtls_internal_sha256_process
+     323                 :            : #endif
+     324                 :            : 
+     325                 :            : static size_t mbedtls_internal_sha256_process_many_a64_crypto(
+     326                 :            :     mbedtls_sha256_context *ctx, const uint8_t *msg, size_t len)
+     327                 :            : {
+     328                 :            :     uint32x4_t abcd = vld1q_u32(&ctx->state[0]);
+     329                 :            :     uint32x4_t efgh = vld1q_u32(&ctx->state[4]);
+     330                 :            : 
+     331                 :            :     size_t processed = 0;
+     332                 :            : 
+     333                 :            :     for (;
+     334                 :            :          len >= SHA256_BLOCK_SIZE;
+     335                 :            :          processed += SHA256_BLOCK_SIZE,
+     336                 :            :          msg += SHA256_BLOCK_SIZE,
+     337                 :            :          len -= SHA256_BLOCK_SIZE) {
+     338                 :            :         uint32x4_t tmp, abcd_prev;
+     339                 :            : 
+     340                 :            :         uint32x4_t abcd_orig = abcd;
+     341                 :            :         uint32x4_t efgh_orig = efgh;
+     342                 :            : 
+     343                 :            :         uint32x4_t sched0 = vreinterpretq_u32_u8(vld1q_u8(msg + 16 * 0));
+     344                 :            :         uint32x4_t sched1 = vreinterpretq_u32_u8(vld1q_u8(msg + 16 * 1));
+     345                 :            :         uint32x4_t sched2 = vreinterpretq_u32_u8(vld1q_u8(msg + 16 * 2));
+     346                 :            :         uint32x4_t sched3 = vreinterpretq_u32_u8(vld1q_u8(msg + 16 * 3));
+     347                 :            : 
+     348                 :            : #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__  /* Will be true if not defined */
+     349                 :            :                                                /* Untested on BE */
+     350                 :            :         sched0 = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(sched0)));
+     351                 :            :         sched1 = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(sched1)));
+     352                 :            :         sched2 = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(sched2)));
+     353                 :            :         sched3 = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(sched3)));
+     354                 :            : #endif
+     355                 :            : 
+     356                 :            :         /* Rounds 0 to 3 */
+     357                 :            :         tmp = vaddq_u32(sched0, vld1q_u32(&K[0]));
+     358                 :            :         abcd_prev = abcd;
+     359                 :            :         abcd = vsha256hq_u32(abcd_prev, efgh, tmp);
+     360                 :            :         efgh = vsha256h2q_u32(efgh, abcd_prev, tmp);
+     361                 :            : 
+     362                 :            :         /* Rounds 4 to 7 */
+     363                 :            :         tmp = vaddq_u32(sched1, vld1q_u32(&K[4]));
+     364                 :            :         abcd_prev = abcd;
+     365                 :            :         abcd = vsha256hq_u32(abcd_prev, efgh, tmp);
+     366                 :            :         efgh = vsha256h2q_u32(efgh, abcd_prev, tmp);
+     367                 :            : 
+     368                 :            :         /* Rounds 8 to 11 */
+     369                 :            :         tmp = vaddq_u32(sched2, vld1q_u32(&K[8]));
+     370                 :            :         abcd_prev = abcd;
+     371                 :            :         abcd = vsha256hq_u32(abcd_prev, efgh, tmp);
+     372                 :            :         efgh = vsha256h2q_u32(efgh, abcd_prev, tmp);
+     373                 :            : 
+     374                 :            :         /* Rounds 12 to 15 */
+     375                 :            :         tmp = vaddq_u32(sched3, vld1q_u32(&K[12]));
+     376                 :            :         abcd_prev = abcd;
+     377                 :            :         abcd = vsha256hq_u32(abcd_prev, efgh, tmp);
+     378                 :            :         efgh = vsha256h2q_u32(efgh, abcd_prev, tmp);
+     379                 :            : 
+     380                 :            :         for (int t = 16; t < 64; t += 16) {
+     381                 :            :             /* Rounds t to t + 3 */
+     382                 :            :             sched0 = vsha256su1q_u32(vsha256su0q_u32(sched0, sched1), sched2, sched3);
+     383                 :            :             tmp = vaddq_u32(sched0, vld1q_u32(&K[t]));
+     384                 :            :             abcd_prev = abcd;
+     385                 :            :             abcd = vsha256hq_u32(abcd_prev, efgh, tmp);
+     386                 :            :             efgh = vsha256h2q_u32(efgh, abcd_prev, tmp);
+     387                 :            : 
+     388                 :            :             /* Rounds t + 4 to t + 7 */
+     389                 :            :             sched1 = vsha256su1q_u32(vsha256su0q_u32(sched1, sched2), sched3, sched0);
+     390                 :            :             tmp = vaddq_u32(sched1, vld1q_u32(&K[t + 4]));
+     391                 :            :             abcd_prev = abcd;
+     392                 :            :             abcd = vsha256hq_u32(abcd_prev, efgh, tmp);
+     393                 :            :             efgh = vsha256h2q_u32(efgh, abcd_prev, tmp);
+     394                 :            : 
+     395                 :            :             /* Rounds t + 8 to t + 11 */
+     396                 :            :             sched2 = vsha256su1q_u32(vsha256su0q_u32(sched2, sched3), sched0, sched1);
+     397                 :            :             tmp = vaddq_u32(sched2, vld1q_u32(&K[t + 8]));
+     398                 :            :             abcd_prev = abcd;
+     399                 :            :             abcd = vsha256hq_u32(abcd_prev, efgh, tmp);
+     400                 :            :             efgh = vsha256h2q_u32(efgh, abcd_prev, tmp);
+     401                 :            : 
+     402                 :            :             /* Rounds t + 12 to t + 15 */
+     403                 :            :             sched3 = vsha256su1q_u32(vsha256su0q_u32(sched3, sched0), sched1, sched2);
+     404                 :            :             tmp = vaddq_u32(sched3, vld1q_u32(&K[t + 12]));
+     405                 :            :             abcd_prev = abcd;
+     406                 :            :             abcd = vsha256hq_u32(abcd_prev, efgh, tmp);
+     407                 :            :             efgh = vsha256h2q_u32(efgh, abcd_prev, tmp);
+     408                 :            :         }
+     409                 :            : 
+     410                 :            :         abcd = vaddq_u32(abcd, abcd_orig);
+     411                 :            :         efgh = vaddq_u32(efgh, efgh_orig);
+     412                 :            :     }
+     413                 :            : 
+     414                 :            :     vst1q_u32(&ctx->state[0], abcd);
+     415                 :            :     vst1q_u32(&ctx->state[4], efgh);
+     416                 :            : 
+     417                 :            :     return processed;
+     418                 :            : }
+     419                 :            : 
+     420                 :            : #if defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT)
+     421                 :            : /*
+     422                 :            :  * This function is for internal use only if we are building both C and Armv8-A
+     423                 :            :  * versions, otherwise it is renamed to be the public mbedtls_internal_sha256_process()
+     424                 :            :  */
+     425                 :            : static
+     426                 :            : #endif
+     427                 :            : int mbedtls_internal_sha256_process_a64_crypto(mbedtls_sha256_context *ctx,
+     428                 :            :                                                const unsigned char data[SHA256_BLOCK_SIZE])
+     429                 :            : {
+     430                 :            :     return (mbedtls_internal_sha256_process_many_a64_crypto(ctx, data,
+     431                 :            :                                                             SHA256_BLOCK_SIZE) ==
+     432                 :            :             SHA256_BLOCK_SIZE) ? 0 : -1;
+     433                 :            : }
+     434                 :            : 
+     435                 :            : #endif /* MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT || MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY */
+     436                 :            : 
+     437                 :            : #if defined(MBEDTLS_POP_TARGET_PRAGMA)
+     438                 :            : #if defined(__clang__)
+     439                 :            : #pragma clang attribute pop
+     440                 :            : #elif defined(__GNUC__)
+     441                 :            : #pragma GCC pop_options
+     442                 :            : #endif
+     443                 :            : #undef MBEDTLS_POP_TARGET_PRAGMA
+     444                 :            : #endif
+     445                 :            : 
+     446                 :            : #if !defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT)
+     447                 :            : #define mbedtls_internal_sha256_process_many_c mbedtls_internal_sha256_process_many
+     448                 :            : #define mbedtls_internal_sha256_process_c      mbedtls_internal_sha256_process
+     449                 :            : #endif
+     450                 :            : 
+     451                 :            : 
+     452                 :            : #if !defined(MBEDTLS_SHA256_PROCESS_ALT) && \
+     453                 :            :     !defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY)
+     454                 :            : 
+     455                 :            : #define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
+     456                 :            : #define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
+     457                 :            : 
+     458                 :            : #define S0(x) (ROTR(x, 7) ^ ROTR(x, 18) ^  SHR(x, 3))
+     459                 :            : #define S1(x) (ROTR(x, 17) ^ ROTR(x, 19) ^  SHR(x, 10))
+     460                 :            : 
+     461                 :            : #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
+     462                 :            : #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
+     463                 :            : 
+     464                 :            : #define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y))))
+     465                 :            : #define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
+     466                 :            : 
+     467                 :            : #define R(t)                                                        \
+     468                 :            :     (                                                               \
+     469                 :            :         local.W[t] = S1(local.W[(t) -  2]) + local.W[(t) -  7] +    \
+     470                 :            :                      S0(local.W[(t) - 15]) + local.W[(t) - 16]      \
+     471                 :            :     )
+     472                 :            : 
+     473                 :            : #define P(a, b, c, d, e, f, g, h, x, K)                                      \
+     474                 :            :     do                                                              \
+     475                 :            :     {                                                               \
+     476                 :            :         local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
+     477                 :            :         local.temp2 = S2(a) + F0((a), (b), (c));                      \
+     478                 :            :         (d) += local.temp1; (h) = local.temp1 + local.temp2;        \
+     479                 :            :     } while (0)
+     480                 :            : 
+     481                 :            : #if defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT)
+     482                 :            : /*
+     483                 :            :  * This function is for internal use only if we are building both C and Armv8
+     484                 :            :  * versions, otherwise it is renamed to be the public mbedtls_internal_sha256_process()
+     485                 :            :  */
+     486                 :            : static
+     487                 :            : #endif
+     488                 :      44956 : int mbedtls_internal_sha256_process_c(mbedtls_sha256_context *ctx,
+     489                 :            :                                       const unsigned char data[SHA256_BLOCK_SIZE])
+     490                 :            : {
+     491                 :            :     struct {
+     492                 :            :         uint32_t temp1, temp2, W[64];
+     493                 :            :         uint32_t A[8];
+     494                 :            :     } local;
+     495                 :            : 
+     496                 :            :     unsigned int i;
+     497                 :            : 
+     498         [ +  + ]:     404604 :     for (i = 0; i < 8; i++) {
+     499                 :     359648 :         local.A[i] = ctx->state[i];
+     500                 :            :     }
+     501                 :            : 
+     502                 :            : #if defined(MBEDTLS_SHA256_SMALLER)
+     503                 :            :     for (i = 0; i < 64; i++) {
+     504                 :            :         if (i < 16) {
+     505                 :            :             local.W[i] = MBEDTLS_GET_UINT32_BE(data, 4 * i);
+     506                 :            :         } else {
+     507                 :            :             R(i);
+     508                 :            :         }
+     509                 :            : 
+     510                 :            :         P(local.A[0], local.A[1], local.A[2], local.A[3], local.A[4],
+     511                 :            :           local.A[5], local.A[6], local.A[7], local.W[i], K[i]);
+     512                 :            : 
+     513                 :            :         local.temp1 = local.A[7]; local.A[7] = local.A[6];
+     514                 :            :         local.A[6] = local.A[5]; local.A[5] = local.A[4];
+     515                 :            :         local.A[4] = local.A[3]; local.A[3] = local.A[2];
+     516                 :            :         local.A[2] = local.A[1]; local.A[1] = local.A[0];
+     517                 :            :         local.A[0] = local.temp1;
+     518                 :            :     }
+     519                 :            : #else /* MBEDTLS_SHA256_SMALLER */
+     520         [ +  + ]:     764252 :     for (i = 0; i < 16; i++) {
+     521                 :    1438592 :         local.W[i] = MBEDTLS_GET_UINT32_BE(data, 4 * i);
+     522                 :            :     }
+     523                 :            : 
+     524         [ +  + ]:     134868 :     for (i = 0; i < 16; i += 8) {
+     525                 :      89912 :         P(local.A[0], local.A[1], local.A[2], local.A[3], local.A[4],
+     526                 :            :           local.A[5], local.A[6], local.A[7], local.W[i+0], K[i+0]);
+     527                 :      89912 :         P(local.A[7], local.A[0], local.A[1], local.A[2], local.A[3],
+     528                 :            :           local.A[4], local.A[5], local.A[6], local.W[i+1], K[i+1]);
+     529                 :      89912 :         P(local.A[6], local.A[7], local.A[0], local.A[1], local.A[2],
+     530                 :            :           local.A[3], local.A[4], local.A[5], local.W[i+2], K[i+2]);
+     531                 :      89912 :         P(local.A[5], local.A[6], local.A[7], local.A[0], local.A[1],
+     532                 :            :           local.A[2], local.A[3], local.A[4], local.W[i+3], K[i+3]);
+     533                 :      89912 :         P(local.A[4], local.A[5], local.A[6], local.A[7], local.A[0],
+     534                 :            :           local.A[1], local.A[2], local.A[3], local.W[i+4], K[i+4]);
+     535                 :      89912 :         P(local.A[3], local.A[4], local.A[5], local.A[6], local.A[7],
+     536                 :            :           local.A[0], local.A[1], local.A[2], local.W[i+5], K[i+5]);
+     537                 :      89912 :         P(local.A[2], local.A[3], local.A[4], local.A[5], local.A[6],
+     538                 :            :           local.A[7], local.A[0], local.A[1], local.W[i+6], K[i+6]);
+     539                 :      89912 :         P(local.A[1], local.A[2], local.A[3], local.A[4], local.A[5],
+     540                 :            :           local.A[6], local.A[7], local.A[0], local.W[i+7], K[i+7]);
+     541                 :            :     }
+     542                 :            : 
+     543         [ +  + ]:     314692 :     for (i = 16; i < 64; i += 8) {
+     544                 :     269736 :         P(local.A[0], local.A[1], local.A[2], local.A[3], local.A[4],
+     545                 :            :           local.A[5], local.A[6], local.A[7], R(i+0), K[i+0]);
+     546                 :     269736 :         P(local.A[7], local.A[0], local.A[1], local.A[2], local.A[3],
+     547                 :            :           local.A[4], local.A[5], local.A[6], R(i+1), K[i+1]);
+     548                 :     269736 :         P(local.A[6], local.A[7], local.A[0], local.A[1], local.A[2],
+     549                 :            :           local.A[3], local.A[4], local.A[5], R(i+2), K[i+2]);
+     550                 :     269736 :         P(local.A[5], local.A[6], local.A[7], local.A[0], local.A[1],
+     551                 :            :           local.A[2], local.A[3], local.A[4], R(i+3), K[i+3]);
+     552                 :     269736 :         P(local.A[4], local.A[5], local.A[6], local.A[7], local.A[0],
+     553                 :            :           local.A[1], local.A[2], local.A[3], R(i+4), K[i+4]);
+     554                 :     269736 :         P(local.A[3], local.A[4], local.A[5], local.A[6], local.A[7],
+     555                 :            :           local.A[0], local.A[1], local.A[2], R(i+5), K[i+5]);
+     556                 :     269736 :         P(local.A[2], local.A[3], local.A[4], local.A[5], local.A[6],
+     557                 :            :           local.A[7], local.A[0], local.A[1], R(i+6), K[i+6]);
+     558                 :     269736 :         P(local.A[1], local.A[2], local.A[3], local.A[4], local.A[5],
+     559                 :            :           local.A[6], local.A[7], local.A[0], R(i+7), K[i+7]);
+     560                 :            :     }
+     561                 :            : #endif /* MBEDTLS_SHA256_SMALLER */
+     562                 :            : 
+     563         [ +  + ]:     404604 :     for (i = 0; i < 8; i++) {
+     564                 :     359648 :         ctx->state[i] += local.A[i];
+     565                 :            :     }
+     566                 :            : 
+     567                 :            :     /* Zeroise buffers and variables to clear sensitive data from memory. */
+     568                 :      44956 :     mbedtls_platform_zeroize(&local, sizeof(local));
+     569                 :            : 
+     570                 :      44956 :     return 0;
+     571                 :            : }
+     572                 :            : 
+     573                 :            : #endif /* !MBEDTLS_SHA256_PROCESS_ALT && !MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY */
+     574                 :            : 
+     575                 :            : 
+     576                 :            : #if !defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY)
+     577                 :            : 
+     578                 :       7240 : static size_t mbedtls_internal_sha256_process_many_c(
+     579                 :            :     mbedtls_sha256_context *ctx, const uint8_t *data, size_t len)
+     580                 :            : {
+     581                 :       7240 :     size_t processed = 0;
+     582                 :            : 
+     583         [ +  + ]:      43024 :     while (len >= SHA256_BLOCK_SIZE) {
+     584         [ -  + ]:      35784 :         if (mbedtls_internal_sha256_process_c(ctx, data) != 0) {
+     585                 :          0 :             return 0;
+     586                 :            :         }
+     587                 :            : 
+     588                 :      35784 :         data += SHA256_BLOCK_SIZE;
+     589                 :      35784 :         len  -= SHA256_BLOCK_SIZE;
+     590                 :            : 
+     591                 :      35784 :         processed += SHA256_BLOCK_SIZE;
+     592                 :            :     }
+     593                 :            : 
+     594                 :       7240 :     return processed;
+     595                 :            : }
+     596                 :            : 
+     597                 :            : #endif /* !MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY */
+     598                 :            : 
+     599                 :            : 
+     600                 :            : #if defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT)
+     601                 :            : 
+     602                 :            : static int mbedtls_a64_crypto_sha256_has_support(void)
+     603                 :            : {
+     604                 :            :     static int done = 0;
+     605                 :            :     static int supported = 0;
+     606                 :            : 
+     607                 :            :     if (!done) {
+     608                 :            :         supported = mbedtls_a64_crypto_sha256_determine_support();
+     609                 :            :         done = 1;
+     610                 :            :     }
+     611                 :            : 
+     612                 :            :     return supported;
+     613                 :            : }
+     614                 :            : 
+     615                 :            : static size_t mbedtls_internal_sha256_process_many(mbedtls_sha256_context *ctx,
+     616                 :            :                                                    const uint8_t *msg, size_t len)
+     617                 :            : {
+     618                 :            :     if (mbedtls_a64_crypto_sha256_has_support()) {
+     619                 :            :         return mbedtls_internal_sha256_process_many_a64_crypto(ctx, msg, len);
+     620                 :            :     } else {
+     621                 :            :         return mbedtls_internal_sha256_process_many_c(ctx, msg, len);
+     622                 :            :     }
+     623                 :            : }
+     624                 :            : 
+     625                 :            : int mbedtls_internal_sha256_process(mbedtls_sha256_context *ctx,
+     626                 :            :                                     const unsigned char data[SHA256_BLOCK_SIZE])
+     627                 :            : {
+     628                 :            :     if (mbedtls_a64_crypto_sha256_has_support()) {
+     629                 :            :         return mbedtls_internal_sha256_process_a64_crypto(ctx, data);
+     630                 :            :     } else {
+     631                 :            :         return mbedtls_internal_sha256_process_c(ctx, data);
+     632                 :            :     }
+     633                 :            : }
+     634                 :            : 
+     635                 :            : #endif /* MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT */
+     636                 :            : 
+     637                 :            : 
+     638                 :            : /*
+     639                 :            :  * SHA-256 process buffer
+     640                 :            :  */
+     641                 :      23563 : int mbedtls_sha256_update(mbedtls_sha256_context *ctx,
+     642                 :            :                           const unsigned char *input,
+     643                 :            :                           size_t ilen)
+     644                 :            : {
+     645                 :      23563 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     646                 :            :     size_t fill;
+     647                 :            :     uint32_t left;
+     648                 :            : 
+     649         [ +  + ]:      23563 :     if (ilen == 0) {
+     650                 :       1675 :         return 0;
+     651                 :            :     }
+     652                 :            : 
+     653                 :      21888 :     left = ctx->total[0] & 0x3F;
+     654                 :      21888 :     fill = SHA256_BLOCK_SIZE - left;
+     655                 :            : 
+     656                 :      21888 :     ctx->total[0] += (uint32_t) ilen;
+     657                 :      21888 :     ctx->total[0] &= 0xFFFFFFFF;
+     658                 :            : 
+     659         [ -  + ]:      21888 :     if (ctx->total[0] < (uint32_t) ilen) {
+     660                 :          0 :         ctx->total[1]++;
+     661                 :            :     }
+     662                 :            : 
+     663   [ +  +  +  + ]:      21888 :     if (left && ilen >= fill) {
+     664                 :       1880 :         memcpy((void *) (ctx->buffer + left), input, fill);
+     665                 :            : 
+     666         [ -  + ]:       1880 :         if ((ret = mbedtls_internal_sha256_process(ctx, ctx->buffer)) != 0) {
+     667                 :          0 :             return ret;
+     668                 :            :         }
+     669                 :            : 
+     670                 :       1880 :         input += fill;
+     671                 :       1880 :         ilen  -= fill;
+     672                 :       1880 :         left = 0;
+     673                 :            :     }
+     674                 :            : 
+     675         [ +  + ]:      29128 :     while (ilen >= SHA256_BLOCK_SIZE) {
+     676                 :            :         size_t processed =
+     677                 :       7240 :             mbedtls_internal_sha256_process_many(ctx, input, ilen);
+     678         [ -  + ]:       7240 :         if (processed < SHA256_BLOCK_SIZE) {
+     679                 :          0 :             return MBEDTLS_ERR_ERROR_GENERIC_ERROR;
+     680                 :            :         }
+     681                 :            : 
+     682                 :       7240 :         input += processed;
+     683                 :       7240 :         ilen  -= processed;
+     684                 :            :     }
+     685                 :            : 
+     686         [ +  + ]:      21888 :     if (ilen > 0) {
+     687                 :      17995 :         memcpy((void *) (ctx->buffer + left), input, ilen);
+     688                 :            :     }
+     689                 :            : 
+     690                 :      21888 :     return 0;
+     691                 :            : }
+     692                 :            : 
+     693                 :            : /*
+     694                 :            :  * SHA-256 final digest
+     695                 :            :  */
+     696                 :       7193 : int mbedtls_sha256_finish(mbedtls_sha256_context *ctx,
+     697                 :            :                           unsigned char *output)
+     698                 :            : {
+     699                 :       7193 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     700                 :            :     uint32_t used;
+     701                 :            :     uint32_t high, low;
+     702                 :       7193 :     int truncated = 0;
+     703                 :            : 
+     704                 :            :     /*
+     705                 :            :      * Add padding: 0x80 then 0x00 until 8 bytes remain for the length
+     706                 :            :      */
+     707                 :       7193 :     used = ctx->total[0] & 0x3F;
+     708                 :            : 
+     709                 :       7193 :     ctx->buffer[used++] = 0x80;
+     710                 :            : 
+     711         [ +  + ]:       7193 :     if (used <= 56) {
+     712                 :            :         /* Enough room for padding + length in current block */
+     713                 :       7094 :         memset(ctx->buffer + used, 0, 56 - used);
+     714                 :            :     } else {
+     715                 :            :         /* We'll need an extra block */
+     716                 :         99 :         memset(ctx->buffer + used, 0, SHA256_BLOCK_SIZE - used);
+     717                 :            : 
+     718         [ -  + ]:         99 :         if ((ret = mbedtls_internal_sha256_process(ctx, ctx->buffer)) != 0) {
+     719                 :          0 :             goto exit;
+     720                 :            :         }
+     721                 :            : 
+     722                 :         99 :         memset(ctx->buffer, 0, 56);
+     723                 :            :     }
+     724                 :            : 
+     725                 :            :     /*
+     726                 :            :      * Add message length
+     727                 :            :      */
+     728                 :       7193 :     high = (ctx->total[0] >> 29)
+     729                 :       7193 :            | (ctx->total[1] <<  3);
+     730                 :       7193 :     low  = (ctx->total[0] <<  3);
+     731                 :            : 
+     732                 :       7193 :     MBEDTLS_PUT_UINT32_BE(high, ctx->buffer, 56);
+     733                 :       7193 :     MBEDTLS_PUT_UINT32_BE(low,  ctx->buffer, 60);
+     734                 :            : 
+     735         [ -  + ]:       7193 :     if ((ret = mbedtls_internal_sha256_process(ctx, ctx->buffer)) != 0) {
+     736                 :          0 :         goto exit;
+     737                 :            :     }
+     738                 :            : 
+     739                 :            :     /*
+     740                 :            :      * Output final state
+     741                 :            :      */
+     742                 :       7193 :     MBEDTLS_PUT_UINT32_BE(ctx->state[0], output,  0);
+     743                 :       7193 :     MBEDTLS_PUT_UINT32_BE(ctx->state[1], output,  4);
+     744                 :       7193 :     MBEDTLS_PUT_UINT32_BE(ctx->state[2], output,  8);
+     745                 :       7193 :     MBEDTLS_PUT_UINT32_BE(ctx->state[3], output, 12);
+     746                 :       7193 :     MBEDTLS_PUT_UINT32_BE(ctx->state[4], output, 16);
+     747                 :       7193 :     MBEDTLS_PUT_UINT32_BE(ctx->state[5], output, 20);
+     748                 :       7193 :     MBEDTLS_PUT_UINT32_BE(ctx->state[6], output, 24);
+     749                 :            : 
+     750                 :            : #if defined(MBEDTLS_SHA224_C)
+     751                 :       7193 :     truncated = ctx->is224;
+     752                 :            : #endif
+     753         [ +  - ]:       7193 :     if (!truncated) {
+     754                 :       7193 :         MBEDTLS_PUT_UINT32_BE(ctx->state[7], output, 28);
+     755                 :            :     }
+     756                 :            : 
+     757                 :       7193 :     ret = 0;
+     758                 :            : 
+     759                 :       7193 : exit:
+     760                 :       7193 :     mbedtls_sha256_free(ctx);
+     761                 :       7193 :     return ret;
+     762                 :            : }
+     763                 :            : 
+     764                 :            : #endif /* !MBEDTLS_SHA256_ALT */
+     765                 :            : 
+     766                 :            : /*
+     767                 :            :  * output = SHA-256( input buffer )
+     768                 :            :  */
+     769                 :       3187 : int mbedtls_sha256(const unsigned char *input,
+     770                 :            :                    size_t ilen,
+     771                 :            :                    unsigned char *output,
+     772                 :            :                    int is224)
+     773                 :            : {
+     774                 :       3187 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     775                 :            :     mbedtls_sha256_context ctx;
+     776                 :            : 
+     777                 :            : #if defined(MBEDTLS_SHA224_C) && defined(MBEDTLS_SHA256_C)
+     778   [ -  +  -  - ]:       3187 :     if (is224 != 0 && is224 != 1) {
+     779                 :          0 :         return MBEDTLS_ERR_SHA256_BAD_INPUT_DATA;
+     780                 :            :     }
+     781                 :            : #elif defined(MBEDTLS_SHA256_C)
+     782                 :            :     if (is224 != 0) {
+     783                 :            :         return MBEDTLS_ERR_SHA256_BAD_INPUT_DATA;
+     784                 :            :     }
+     785                 :            : #else /* defined MBEDTLS_SHA224_C only */
+     786                 :            :     if (is224 == 0) {
+     787                 :            :         return MBEDTLS_ERR_SHA256_BAD_INPUT_DATA;
+     788                 :            :     }
+     789                 :            : #endif
+     790                 :            : 
+     791                 :       3187 :     mbedtls_sha256_init(&ctx);
+     792                 :            : 
+     793         [ -  + ]:       3187 :     if ((ret = mbedtls_sha256_starts(&ctx, is224)) != 0) {
+     794                 :          0 :         goto exit;
+     795                 :            :     }
+     796                 :            : 
+     797         [ -  + ]:       3187 :     if ((ret = mbedtls_sha256_update(&ctx, input, ilen)) != 0) {
+     798                 :          0 :         goto exit;
+     799                 :            :     }
+     800                 :            : 
+     801         [ +  - ]:       3187 :     if ((ret = mbedtls_sha256_finish(&ctx, output)) != 0) {
+     802                 :          0 :         goto exit;
+     803                 :            :     }
+     804                 :            : 
+     805                 :       3187 : exit:
+     806                 :       3187 :     mbedtls_sha256_free(&ctx);
+     807                 :            : 
+     808                 :       3187 :     return ret;
+     809                 :            : }
+     810                 :            : 
+     811                 :            : #if defined(MBEDTLS_SELF_TEST)
+     812                 :            : /*
+     813                 :            :  * FIPS-180-2 test vectors
+     814                 :            :  */
+     815                 :            : static const unsigned char sha_test_buf[3][57] =
+     816                 :            : {
+     817                 :            :     { "abc" },
+     818                 :            :     { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" },
+     819                 :            :     { "" }
+     820                 :            : };
+     821                 :            : 
+     822                 :            : static const size_t sha_test_buflen[3] =
+     823                 :            : {
+     824                 :            :     3, 56, 1000
+     825                 :            : };
+     826                 :            : 
+     827                 :            : typedef const unsigned char (sha_test_sum_t)[32];
+     828                 :            : 
+     829                 :            : /*
+     830                 :            :  * SHA-224 test vectors
+     831                 :            :  */
+     832                 :            : #if defined(MBEDTLS_SHA224_C)
+     833                 :            : static sha_test_sum_t sha224_test_sum[] =
+     834                 :            : {
+     835                 :            :     { 0x23, 0x09, 0x7D, 0x22, 0x34, 0x05, 0xD8, 0x22,
+     836                 :            :       0x86, 0x42, 0xA4, 0x77, 0xBD, 0xA2, 0x55, 0xB3,
+     837                 :            :       0x2A, 0xAD, 0xBC, 0xE4, 0xBD, 0xA0, 0xB3, 0xF7,
+     838                 :            :       0xE3, 0x6C, 0x9D, 0xA7 },
+     839                 :            :     { 0x75, 0x38, 0x8B, 0x16, 0x51, 0x27, 0x76, 0xCC,
+     840                 :            :       0x5D, 0xBA, 0x5D, 0xA1, 0xFD, 0x89, 0x01, 0x50,
+     841                 :            :       0xB0, 0xC6, 0x45, 0x5C, 0xB4, 0xF5, 0x8B, 0x19,
+     842                 :            :       0x52, 0x52, 0x25, 0x25 },
+     843                 :            :     { 0x20, 0x79, 0x46, 0x55, 0x98, 0x0C, 0x91, 0xD8,
+     844                 :            :       0xBB, 0xB4, 0xC1, 0xEA, 0x97, 0x61, 0x8A, 0x4B,
+     845                 :            :       0xF0, 0x3F, 0x42, 0x58, 0x19, 0x48, 0xB2, 0xEE,
+     846                 :            :       0x4E, 0xE7, 0xAD, 0x67 }
+     847                 :            : };
+     848                 :            : #endif
+     849                 :            : 
+     850                 :            : /*
+     851                 :            :  * SHA-256 test vectors
+     852                 :            :  */
+     853                 :            : #if defined(MBEDTLS_SHA256_C)
+     854                 :            : static sha_test_sum_t sha256_test_sum[] =
+     855                 :            : {
+     856                 :            :     { 0xBA, 0x78, 0x16, 0xBF, 0x8F, 0x01, 0xCF, 0xEA,
+     857                 :            :       0x41, 0x41, 0x40, 0xDE, 0x5D, 0xAE, 0x22, 0x23,
+     858                 :            :       0xB0, 0x03, 0x61, 0xA3, 0x96, 0x17, 0x7A, 0x9C,
+     859                 :            :       0xB4, 0x10, 0xFF, 0x61, 0xF2, 0x00, 0x15, 0xAD },
+     860                 :            :     { 0x24, 0x8D, 0x6A, 0x61, 0xD2, 0x06, 0x38, 0xB8,
+     861                 :            :       0xE5, 0xC0, 0x26, 0x93, 0x0C, 0x3E, 0x60, 0x39,
+     862                 :            :       0xA3, 0x3C, 0xE4, 0x59, 0x64, 0xFF, 0x21, 0x67,
+     863                 :            :       0xF6, 0xEC, 0xED, 0xD4, 0x19, 0xDB, 0x06, 0xC1 },
+     864                 :            :     { 0xCD, 0xC7, 0x6E, 0x5C, 0x99, 0x14, 0xFB, 0x92,
+     865                 :            :       0x81, 0xA1, 0xC7, 0xE2, 0x84, 0xD7, 0x3E, 0x67,
+     866                 :            :       0xF1, 0x80, 0x9A, 0x48, 0xA4, 0x97, 0x20, 0x0E,
+     867                 :            :       0x04, 0x6D, 0x39, 0xCC, 0xC7, 0x11, 0x2C, 0xD0 }
+     868                 :            : };
+     869                 :            : #endif
+     870                 :            : 
+     871                 :            : /*
+     872                 :            :  * Checkup routine
+     873                 :            :  */
+     874                 :          0 : static int mbedtls_sha256_common_self_test(int verbose, int is224)
+     875                 :            : {
+     876                 :          0 :     int i, buflen, ret = 0;
+     877                 :            :     unsigned char *buf;
+     878                 :            :     unsigned char sha256sum[32];
+     879                 :            :     mbedtls_sha256_context ctx;
+     880                 :            : 
+     881                 :            : #if defined(MBEDTLS_SHA224_C) && defined(MBEDTLS_SHA256_C)
+     882         [ #  # ]:          0 :     sha_test_sum_t *sha_test_sum = (is224) ? sha224_test_sum : sha256_test_sum;
+     883                 :            : #elif defined(MBEDTLS_SHA256_C)
+     884                 :            :     sha_test_sum_t *sha_test_sum = sha256_test_sum;
+     885                 :            : #else
+     886                 :            :     sha_test_sum_t *sha_test_sum = sha224_test_sum;
+     887                 :            : #endif
+     888                 :            : 
+     889                 :          0 :     buf = mbedtls_calloc(1024, sizeof(unsigned char));
+     890         [ #  # ]:          0 :     if (NULL == buf) {
+     891         [ #  # ]:          0 :         if (verbose != 0) {
+     892                 :          0 :             mbedtls_printf("Buffer allocation failed\n");
+     893                 :            :         }
+     894                 :            : 
+     895                 :          0 :         return 1;
+     896                 :            :     }
+     897                 :            : 
+     898                 :          0 :     mbedtls_sha256_init(&ctx);
+     899                 :            : 
+     900         [ #  # ]:          0 :     for (i = 0; i < 3; i++) {
+     901         [ #  # ]:          0 :         if (verbose != 0) {
+     902                 :          0 :             mbedtls_printf("  SHA-%d test #%d: ", 256 - is224 * 32, i + 1);
+     903                 :            :         }
+     904                 :            : 
+     905         [ #  # ]:          0 :         if ((ret = mbedtls_sha256_starts(&ctx, is224)) != 0) {
+     906                 :          0 :             goto fail;
+     907                 :            :         }
+     908                 :            : 
+     909         [ #  # ]:          0 :         if (i == 2) {
+     910                 :          0 :             memset(buf, 'a', buflen = 1000);
+     911                 :            : 
+     912         [ #  # ]:          0 :             for (int j = 0; j < 1000; j++) {
+     913                 :          0 :                 ret = mbedtls_sha256_update(&ctx, buf, buflen);
+     914         [ #  # ]:          0 :                 if (ret != 0) {
+     915                 :          0 :                     goto fail;
+     916                 :            :                 }
+     917                 :            :             }
+     918                 :            : 
+     919                 :            :         } else {
+     920                 :          0 :             ret = mbedtls_sha256_update(&ctx, sha_test_buf[i],
+     921                 :          0 :                                         sha_test_buflen[i]);
+     922         [ #  # ]:          0 :             if (ret != 0) {
+     923                 :          0 :                 goto fail;
+     924                 :            :             }
+     925                 :            :         }
+     926                 :            : 
+     927         [ #  # ]:          0 :         if ((ret = mbedtls_sha256_finish(&ctx, sha256sum)) != 0) {
+     928                 :          0 :             goto fail;
+     929                 :            :         }
+     930                 :            : 
+     931                 :            : 
+     932         [ #  # ]:          0 :         if (memcmp(sha256sum, sha_test_sum[i], 32 - is224 * 4) != 0) {
+     933                 :          0 :             ret = 1;
+     934                 :          0 :             goto fail;
+     935                 :            :         }
+     936                 :            : 
+     937         [ #  # ]:          0 :         if (verbose != 0) {
+     938                 :          0 :             mbedtls_printf("passed\n");
+     939                 :            :         }
+     940                 :            :     }
+     941                 :            : 
+     942         [ #  # ]:          0 :     if (verbose != 0) {
+     943                 :          0 :         mbedtls_printf("\n");
+     944                 :            :     }
+     945                 :            : 
+     946                 :          0 :     goto exit;
+     947                 :            : 
+     948                 :          0 : fail:
+     949         [ #  # ]:          0 :     if (verbose != 0) {
+     950                 :          0 :         mbedtls_printf("failed\n");
+     951                 :            :     }
+     952                 :            : 
+     953                 :          0 : exit:
+     954                 :          0 :     mbedtls_sha256_free(&ctx);
+     955                 :          0 :     mbedtls_free(buf);
+     956                 :            : 
+     957                 :          0 :     return ret;
+     958                 :            : }
+     959                 :            : 
+     960                 :            : #if defined(MBEDTLS_SHA256_C)
+     961                 :          0 : int mbedtls_sha256_self_test(int verbose)
+     962                 :            : {
+     963                 :          0 :     return mbedtls_sha256_common_self_test(verbose, 0);
+     964                 :            : }
+     965                 :            : #endif /* MBEDTLS_SHA256_C */
+     966                 :            : 
+     967                 :            : #if defined(MBEDTLS_SHA224_C)
+     968                 :          0 : int mbedtls_sha224_self_test(int verbose)
+     969                 :            : {
+     970                 :          0 :     return mbedtls_sha256_common_self_test(verbose, 1);
+     971                 :            : }
+     972                 :            : #endif /* MBEDTLS_SHA224_C */
+     973                 :            : 
+     974                 :            : #endif /* MBEDTLS_SELF_TEST */
+     975                 :            : 
+     976                 :            : #endif /* MBEDTLS_SHA256_C || MBEDTLS_SHA224_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/sha3.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/sha3.c.func-sort-c.html new file mode 100644 index 00000000000..c4461fbd61d --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/sha3.c.func-sort-c.html @@ -0,0 +1,125 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/sha3.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - sha3.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:02470.0 %
Date:2024-09-22 08:21:07Functions:0110.0 %
Branches:01070.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
keccak_f16000
mbedtls_sha30
mbedtls_sha3_clone0
mbedtls_sha3_finish0
mbedtls_sha3_free0
mbedtls_sha3_init0
mbedtls_sha3_kat_test0
mbedtls_sha3_long_kat_test0
mbedtls_sha3_self_test0
mbedtls_sha3_starts0
mbedtls_sha3_update0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/sha3.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/sha3.c.func.html new file mode 100644 index 00000000000..bea01e93ae8 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/sha3.c.func.html @@ -0,0 +1,125 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/sha3.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - sha3.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:02470.0 %
Date:2024-09-22 08:21:07Functions:0110.0 %
Branches:01070.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
keccak_f16000
mbedtls_sha30
mbedtls_sha3_clone0
mbedtls_sha3_finish0
mbedtls_sha3_free0
mbedtls_sha3_init0
mbedtls_sha3_kat_test0
mbedtls_sha3_long_kat_test0
mbedtls_sha3_self_test0
mbedtls_sha3_starts0
mbedtls_sha3_update0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/sha3.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/sha3.c.gcov.html new file mode 100644 index 00000000000..9de1d6b47bf --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/sha3.c.gcov.html @@ -0,0 +1,809 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/sha3.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - sha3.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:02470.0 %
Date:2024-09-22 08:21:07Functions:0110.0 %
Branches:01070.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  *  FIPS-202 compliant SHA3 implementation
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  */
+       7                 :            : /*
+       8                 :            :  *  The SHA-3 Secure Hash Standard was published by NIST in 2015.
+       9                 :            :  *
+      10                 :            :  *  https://nvlpubs.nist.gov/nistpubs/fips/nist.fips.202.pdf
+      11                 :            :  */
+      12                 :            : 
+      13                 :            : #include "common.h"
+      14                 :            : 
+      15                 :            : #if defined(MBEDTLS_SHA3_C)
+      16                 :            : 
+      17                 :            : /*
+      18                 :            :  * These macros select manually unrolled implementations of parts of the main permutation function.
+      19                 :            :  *
+      20                 :            :  * Unrolling has a major impact on both performance and code size. gcc performance benefits a lot
+      21                 :            :  * from manually unrolling at higher optimisation levels.
+      22                 :            :  *
+      23                 :            :  * Depending on your size/perf priorities, compiler and target, it may be beneficial to adjust
+      24                 :            :  * these; the defaults here should give sensible trade-offs for gcc and clang on aarch64 and
+      25                 :            :  * x86-64.
+      26                 :            :  */
+      27                 :            : #if !defined(MBEDTLS_SHA3_THETA_UNROLL)
+      28                 :            :     #define MBEDTLS_SHA3_THETA_UNROLL 0 //no-check-names
+      29                 :            : #endif
+      30                 :            : #if !defined(MBEDTLS_SHA3_CHI_UNROLL)
+      31                 :            :     #if defined(__OPTIMIZE_SIZE__)
+      32                 :            :         #define MBEDTLS_SHA3_CHI_UNROLL 0 //no-check-names
+      33                 :            :     #else
+      34                 :            :         #define MBEDTLS_SHA3_CHI_UNROLL 1 //no-check-names
+      35                 :            :     #endif
+      36                 :            : #endif
+      37                 :            : #if !defined(MBEDTLS_SHA3_PI_UNROLL)
+      38                 :            :     #define MBEDTLS_SHA3_PI_UNROLL 1 //no-check-names
+      39                 :            : #endif
+      40                 :            : #if !defined(MBEDTLS_SHA3_RHO_UNROLL)
+      41                 :            :     #define MBEDTLS_SHA3_RHO_UNROLL 1 //no-check-names
+      42                 :            : #endif
+      43                 :            : 
+      44                 :            : #include "mbedtls/sha3.h"
+      45                 :            : #include "mbedtls/platform_util.h"
+      46                 :            : #include "mbedtls/error.h"
+      47                 :            : 
+      48                 :            : #include <string.h>
+      49                 :            : 
+      50                 :            : #if defined(MBEDTLS_SELF_TEST)
+      51                 :            : #include "mbedtls/platform.h"
+      52                 :            : #endif /* MBEDTLS_SELF_TEST */
+      53                 :            : 
+      54                 :            : #define XOR_BYTE 0x6
+      55                 :            : 
+      56                 :            : /* Precomputed masks for the iota transform.
+      57                 :            :  *
+      58                 :            :  * Each round uses a 64-bit mask value. In each mask values, only
+      59                 :            :  * bits whose position is of the form 2^k-1 can be set, thus only
+      60                 :            :  * 7 of 64 bits of the mask need to be known for each mask value.
+      61                 :            :  *
+      62                 :            :  * We use a compressed encoding of the mask where bits 63, 31 and 15
+      63                 :            :  * are moved to bits 4-6. This allows us to make each mask value
+      64                 :            :  * 1 byte rather than 8 bytes, saving 7*24 = 168 bytes of data (with
+      65                 :            :  * perhaps a little variation due to alignment). Decompressing this
+      66                 :            :  * requires a little code, but much less than the savings on the table.
+      67                 :            :  *
+      68                 :            :  * The impact on performance depends on the platform and compiler.
+      69                 :            :  * There's a bit more computation, but less memory bandwidth. A quick
+      70                 :            :  * benchmark on x86_64 shows a 7% speed improvement with GCC and a
+      71                 :            :  * 5% speed penalty with Clang, compared to the naive uint64_t[24] table.
+      72                 :            :  * YMMV.
+      73                 :            :  */
+      74                 :            : /* Helper macro to set the values of the higher bits in unused low positions */
+      75                 :            : #define H(b63, b31, b15) (b63 << 6 | b31 << 5 | b15 << 4)
+      76                 :            : static const uint8_t iota_r_packed[24] = {
+      77                 :            :     H(0, 0, 0) | 0x01, H(0, 0, 1) | 0x82, H(1, 0, 1) | 0x8a, H(1, 1, 1) | 0x00,
+      78                 :            :     H(0, 0, 1) | 0x8b, H(0, 1, 0) | 0x01, H(1, 1, 1) | 0x81, H(1, 0, 1) | 0x09,
+      79                 :            :     H(0, 0, 0) | 0x8a, H(0, 0, 0) | 0x88, H(0, 1, 1) | 0x09, H(0, 1, 0) | 0x0a,
+      80                 :            :     H(0, 1, 1) | 0x8b, H(1, 0, 0) | 0x8b, H(1, 0, 1) | 0x89, H(1, 0, 1) | 0x03,
+      81                 :            :     H(1, 0, 1) | 0x02, H(1, 0, 0) | 0x80, H(0, 0, 1) | 0x0a, H(1, 1, 0) | 0x0a,
+      82                 :            :     H(1, 1, 1) | 0x81, H(1, 0, 1) | 0x80, H(0, 1, 0) | 0x01, H(1, 1, 1) | 0x08,
+      83                 :            : };
+      84                 :            : #undef H
+      85                 :            : 
+      86                 :            : static const uint32_t rho[6] = {
+      87                 :            :     0x3f022425, 0x1c143a09, 0x2c3d3615, 0x27191713, 0x312b382e, 0x3e030832
+      88                 :            : };
+      89                 :            : 
+      90                 :            : static const uint32_t pi[6] = {
+      91                 :            :     0x110b070a, 0x10050312, 0x04181508, 0x0d13170f, 0x0e14020c, 0x01060916
+      92                 :            : };
+      93                 :            : 
+      94                 :            : #define ROTR64(x, y) (((x) << (64U - (y))) | ((x) >> (y))) // 64-bit rotate right
+      95                 :            : #define ABSORB(ctx, idx, v) do { ctx->state[(idx) >> 3] ^= ((uint64_t) (v)) << (((idx) & 0x7) << 3); \
+      96                 :            : } while (0)
+      97                 :            : #define SQUEEZE(ctx, idx) ((uint8_t) (ctx->state[(idx) >> 3] >> (((idx) & 0x7) << 3)))
+      98                 :            : #define SWAP(x, y) do { uint64_t tmp = (x); (x) = (y); (y) = tmp; } while (0)
+      99                 :            : 
+     100                 :            : /* The permutation function.  */
+     101                 :          0 : static void keccak_f1600(mbedtls_sha3_context *ctx)
+     102                 :            : {
+     103                 :            :     uint64_t lane[5];
+     104                 :          0 :     uint64_t *s = ctx->state;
+     105                 :            :     int i;
+     106                 :            : 
+     107         [ #  # ]:          0 :     for (int round = 0; round < 24; round++) {
+     108                 :            :         uint64_t t;
+     109                 :            : 
+     110                 :            :         /* Theta */
+     111                 :            : #if MBEDTLS_SHA3_THETA_UNROLL == 0 //no-check-names
+     112         [ #  # ]:          0 :         for (i = 0; i < 5; i++) {
+     113                 :          0 :             lane[i] = s[i] ^ s[i + 5] ^ s[i + 10] ^ s[i + 15] ^ s[i + 20];
+     114                 :            :         }
+     115         [ #  # ]:          0 :         for (i = 0; i < 5; i++) {
+     116                 :          0 :             t = lane[(i + 4) % 5] ^ ROTR64(lane[(i + 1) % 5], 63);
+     117                 :          0 :             s[i] ^= t; s[i + 5] ^= t; s[i + 10] ^= t; s[i + 15] ^= t; s[i + 20] ^= t;
+     118                 :            :         }
+     119                 :            : #else
+     120                 :            :         lane[0] = s[0] ^ s[5] ^ s[10] ^ s[15] ^ s[20];
+     121                 :            :         lane[1] = s[1] ^ s[6] ^ s[11] ^ s[16] ^ s[21];
+     122                 :            :         lane[2] = s[2] ^ s[7] ^ s[12] ^ s[17] ^ s[22];
+     123                 :            :         lane[3] = s[3] ^ s[8] ^ s[13] ^ s[18] ^ s[23];
+     124                 :            :         lane[4] = s[4] ^ s[9] ^ s[14] ^ s[19] ^ s[24];
+     125                 :            : 
+     126                 :            :         t = lane[4] ^ ROTR64(lane[1], 63);
+     127                 :            :         s[0] ^= t; s[5] ^= t; s[10] ^= t; s[15] ^= t; s[20] ^= t;
+     128                 :            : 
+     129                 :            :         t = lane[0] ^ ROTR64(lane[2], 63);
+     130                 :            :         s[1] ^= t; s[6] ^= t; s[11] ^= t; s[16] ^= t; s[21] ^= t;
+     131                 :            : 
+     132                 :            :         t = lane[1] ^ ROTR64(lane[3], 63);
+     133                 :            :         s[2] ^= t; s[7] ^= t; s[12] ^= t; s[17] ^= t; s[22] ^= t;
+     134                 :            : 
+     135                 :            :         t = lane[2] ^ ROTR64(lane[4], 63);
+     136                 :            :         s[3] ^= t; s[8] ^= t; s[13] ^= t; s[18] ^= t; s[23] ^= t;
+     137                 :            : 
+     138                 :            :         t = lane[3] ^ ROTR64(lane[0], 63);
+     139                 :            :         s[4] ^= t; s[9] ^= t; s[14] ^= t; s[19] ^= t; s[24] ^= t;
+     140                 :            : #endif
+     141                 :            : 
+     142                 :            :         /* Rho */
+     143         [ #  # ]:          0 :         for (i = 1; i < 25; i += 4) {
+     144                 :          0 :             uint32_t r = rho[(i - 1) >> 2];
+     145                 :            : #if MBEDTLS_SHA3_RHO_UNROLL == 0
+     146                 :            :             for (int j = i; j < i + 4; j++) {
+     147                 :            :                 uint8_t r8 = (uint8_t) (r >> 24);
+     148                 :            :                 r <<= 8;
+     149                 :            :                 s[j] = ROTR64(s[j], r8);
+     150                 :            :             }
+     151                 :            : #else
+     152                 :          0 :             s[i + 0] = ROTR64(s[i + 0], MBEDTLS_BYTE_3(r));
+     153                 :          0 :             s[i + 1] = ROTR64(s[i + 1], MBEDTLS_BYTE_2(r));
+     154                 :          0 :             s[i + 2] = ROTR64(s[i + 2], MBEDTLS_BYTE_1(r));
+     155                 :          0 :             s[i + 3] = ROTR64(s[i + 3], MBEDTLS_BYTE_0(r));
+     156                 :            : #endif
+     157                 :            :         }
+     158                 :            : 
+     159                 :            :         /* Pi */
+     160                 :          0 :         t = s[1];
+     161                 :            : #if MBEDTLS_SHA3_PI_UNROLL == 0
+     162                 :            :         for (i = 0; i < 24; i += 4) {
+     163                 :            :             uint32_t p = pi[i >> 2];
+     164                 :            :             for (unsigned j = 0; j < 4; j++) {
+     165                 :            :                 SWAP(s[p & 0xff], t);
+     166                 :            :                 p >>= 8;
+     167                 :            :             }
+     168                 :            :         }
+     169                 :            : #else
+     170                 :          0 :         uint32_t p = pi[0];
+     171                 :          0 :         SWAP(s[MBEDTLS_BYTE_0(p)], t); SWAP(s[MBEDTLS_BYTE_1(p)], t);
+     172                 :          0 :         SWAP(s[MBEDTLS_BYTE_2(p)], t); SWAP(s[MBEDTLS_BYTE_3(p)], t);
+     173                 :          0 :         p = pi[1];
+     174                 :          0 :         SWAP(s[MBEDTLS_BYTE_0(p)], t); SWAP(s[MBEDTLS_BYTE_1(p)], t);
+     175                 :          0 :         SWAP(s[MBEDTLS_BYTE_2(p)], t); SWAP(s[MBEDTLS_BYTE_3(p)], t);
+     176                 :          0 :         p = pi[2];
+     177                 :          0 :         SWAP(s[MBEDTLS_BYTE_0(p)], t); SWAP(s[MBEDTLS_BYTE_1(p)], t);
+     178                 :          0 :         SWAP(s[MBEDTLS_BYTE_2(p)], t); SWAP(s[MBEDTLS_BYTE_3(p)], t);
+     179                 :          0 :         p = pi[3];
+     180                 :          0 :         SWAP(s[MBEDTLS_BYTE_0(p)], t); SWAP(s[MBEDTLS_BYTE_1(p)], t);
+     181                 :          0 :         SWAP(s[MBEDTLS_BYTE_2(p)], t); SWAP(s[MBEDTLS_BYTE_3(p)], t);
+     182                 :          0 :         p = pi[4];
+     183                 :          0 :         SWAP(s[MBEDTLS_BYTE_0(p)], t); SWAP(s[MBEDTLS_BYTE_1(p)], t);
+     184                 :          0 :         SWAP(s[MBEDTLS_BYTE_2(p)], t); SWAP(s[MBEDTLS_BYTE_3(p)], t);
+     185                 :          0 :         p = pi[5];
+     186                 :          0 :         SWAP(s[MBEDTLS_BYTE_0(p)], t); SWAP(s[MBEDTLS_BYTE_1(p)], t);
+     187                 :          0 :         SWAP(s[MBEDTLS_BYTE_2(p)], t); SWAP(s[MBEDTLS_BYTE_3(p)], t);
+     188                 :            : #endif
+     189                 :            : 
+     190                 :            :         /* Chi */
+     191                 :            : #if MBEDTLS_SHA3_CHI_UNROLL == 0 //no-check-names
+     192                 :            :         for (i = 0; i <= 20; i += 5) {
+     193                 :            :             lane[0] = s[i]; lane[1] = s[i + 1]; lane[2] = s[i + 2];
+     194                 :            :             lane[3] = s[i + 3]; lane[4] = s[i + 4];
+     195                 :            :             s[i + 0] ^= (~lane[1]) & lane[2];
+     196                 :            :             s[i + 1] ^= (~lane[2]) & lane[3];
+     197                 :            :             s[i + 2] ^= (~lane[3]) & lane[4];
+     198                 :            :             s[i + 3] ^= (~lane[4]) & lane[0];
+     199                 :            :             s[i + 4] ^= (~lane[0]) & lane[1];
+     200                 :            :         }
+     201                 :            : #else
+     202                 :          0 :         lane[0] = s[0]; lane[1] = s[1]; lane[2] = s[2]; lane[3] = s[3]; lane[4] = s[4];
+     203                 :          0 :         s[0] ^= (~lane[1]) & lane[2];
+     204                 :          0 :         s[1] ^= (~lane[2]) & lane[3];
+     205                 :          0 :         s[2] ^= (~lane[3]) & lane[4];
+     206                 :          0 :         s[3] ^= (~lane[4]) & lane[0];
+     207                 :          0 :         s[4] ^= (~lane[0]) & lane[1];
+     208                 :            : 
+     209                 :          0 :         lane[0] = s[5]; lane[1] = s[6]; lane[2] = s[7]; lane[3] = s[8]; lane[4] = s[9];
+     210                 :          0 :         s[5] ^= (~lane[1]) & lane[2];
+     211                 :          0 :         s[6] ^= (~lane[2]) & lane[3];
+     212                 :          0 :         s[7] ^= (~lane[3]) & lane[4];
+     213                 :          0 :         s[8] ^= (~lane[4]) & lane[0];
+     214                 :          0 :         s[9] ^= (~lane[0]) & lane[1];
+     215                 :            : 
+     216                 :          0 :         lane[0] = s[10]; lane[1] = s[11]; lane[2] = s[12]; lane[3] = s[13]; lane[4] = s[14];
+     217                 :          0 :         s[10] ^= (~lane[1]) & lane[2];
+     218                 :          0 :         s[11] ^= (~lane[2]) & lane[3];
+     219                 :          0 :         s[12] ^= (~lane[3]) & lane[4];
+     220                 :          0 :         s[13] ^= (~lane[4]) & lane[0];
+     221                 :          0 :         s[14] ^= (~lane[0]) & lane[1];
+     222                 :            : 
+     223                 :          0 :         lane[0] = s[15]; lane[1] = s[16]; lane[2] = s[17]; lane[3] = s[18]; lane[4] = s[19];
+     224                 :          0 :         s[15] ^= (~lane[1]) & lane[2];
+     225                 :          0 :         s[16] ^= (~lane[2]) & lane[3];
+     226                 :          0 :         s[17] ^= (~lane[3]) & lane[4];
+     227                 :          0 :         s[18] ^= (~lane[4]) & lane[0];
+     228                 :          0 :         s[19] ^= (~lane[0]) & lane[1];
+     229                 :            : 
+     230                 :          0 :         lane[0] = s[20]; lane[1] = s[21]; lane[2] = s[22]; lane[3] = s[23]; lane[4] = s[24];
+     231                 :          0 :         s[20] ^= (~lane[1]) & lane[2];
+     232                 :          0 :         s[21] ^= (~lane[2]) & lane[3];
+     233                 :          0 :         s[22] ^= (~lane[3]) & lane[4];
+     234                 :          0 :         s[23] ^= (~lane[4]) & lane[0];
+     235                 :          0 :         s[24] ^= (~lane[0]) & lane[1];
+     236                 :            : #endif
+     237                 :            : 
+     238                 :            :         /* Iota */
+     239                 :            :         /* Decompress the round masks (see definition of rc) */
+     240                 :          0 :         s[0] ^= ((iota_r_packed[round] & 0x40ull) << 57 |
+     241                 :          0 :                  (iota_r_packed[round] & 0x20ull) << 26 |
+     242                 :          0 :                  (iota_r_packed[round] & 0x10ull) << 11 |
+     243                 :          0 :                  (iota_r_packed[round] & 0x8f));
+     244                 :            :     }
+     245                 :          0 : }
+     246                 :            : 
+     247                 :          0 : void mbedtls_sha3_init(mbedtls_sha3_context *ctx)
+     248                 :            : {
+     249                 :          0 :     memset(ctx, 0, sizeof(mbedtls_sha3_context));
+     250                 :          0 : }
+     251                 :            : 
+     252                 :          0 : void mbedtls_sha3_free(mbedtls_sha3_context *ctx)
+     253                 :            : {
+     254         [ #  # ]:          0 :     if (ctx == NULL) {
+     255                 :          0 :         return;
+     256                 :            :     }
+     257                 :            : 
+     258                 :          0 :     mbedtls_platform_zeroize(ctx, sizeof(mbedtls_sha3_context));
+     259                 :            : }
+     260                 :            : 
+     261                 :          0 : void mbedtls_sha3_clone(mbedtls_sha3_context *dst,
+     262                 :            :                         const mbedtls_sha3_context *src)
+     263                 :            : {
+     264                 :          0 :     *dst = *src;
+     265                 :          0 : }
+     266                 :            : 
+     267                 :            : /*
+     268                 :            :  * SHA-3 context setup
+     269                 :            :  */
+     270                 :          0 : int mbedtls_sha3_starts(mbedtls_sha3_context *ctx, mbedtls_sha3_id id)
+     271                 :            : {
+     272   [ #  #  #  #  :          0 :     switch (id) {
+                      # ]
+     273                 :          0 :         case MBEDTLS_SHA3_224:
+     274                 :          0 :             ctx->olen = 224 / 8;
+     275                 :          0 :             ctx->max_block_size = 1152 / 8;
+     276                 :          0 :             break;
+     277                 :          0 :         case MBEDTLS_SHA3_256:
+     278                 :          0 :             ctx->olen = 256 / 8;
+     279                 :          0 :             ctx->max_block_size = 1088 / 8;
+     280                 :          0 :             break;
+     281                 :          0 :         case MBEDTLS_SHA3_384:
+     282                 :          0 :             ctx->olen = 384 / 8;
+     283                 :          0 :             ctx->max_block_size = 832 / 8;
+     284                 :          0 :             break;
+     285                 :          0 :         case MBEDTLS_SHA3_512:
+     286                 :          0 :             ctx->olen = 512 / 8;
+     287                 :          0 :             ctx->max_block_size = 576 / 8;
+     288                 :          0 :             break;
+     289                 :          0 :         default:
+     290                 :          0 :             return MBEDTLS_ERR_SHA3_BAD_INPUT_DATA;
+     291                 :            :     }
+     292                 :            : 
+     293                 :          0 :     memset(ctx->state, 0, sizeof(ctx->state));
+     294                 :          0 :     ctx->index = 0;
+     295                 :            : 
+     296                 :          0 :     return 0;
+     297                 :            : }
+     298                 :            : 
+     299                 :            : /*
+     300                 :            :  * SHA-3 process buffer
+     301                 :            :  */
+     302                 :          0 : int mbedtls_sha3_update(mbedtls_sha3_context *ctx,
+     303                 :            :                         const uint8_t *input,
+     304                 :            :                         size_t ilen)
+     305                 :            : {
+     306         [ #  # ]:          0 :     if (ilen >= 8) {
+     307                 :            :         // 8-byte align index
+     308                 :          0 :         int align_bytes = 8 - (ctx->index % 8);
+     309         [ #  # ]:          0 :         if (align_bytes) {
+     310         [ #  # ]:          0 :             for (; align_bytes > 0; align_bytes--) {
+     311                 :          0 :                 ABSORB(ctx, ctx->index, *input++);
+     312                 :          0 :                 ilen--;
+     313                 :          0 :                 ctx->index++;
+     314                 :            :             }
+     315         [ #  # ]:          0 :             if ((ctx->index = ctx->index % ctx->max_block_size) == 0) {
+     316                 :          0 :                 keccak_f1600(ctx);
+     317                 :            :             }
+     318                 :            :         }
+     319                 :            : 
+     320                 :            :         // process input in 8-byte chunks
+     321         [ #  # ]:          0 :         while (ilen >= 8) {
+     322                 :          0 :             ABSORB(ctx, ctx->index, MBEDTLS_GET_UINT64_LE(input, 0));
+     323                 :          0 :             input += 8;
+     324                 :          0 :             ilen -= 8;
+     325         [ #  # ]:          0 :             if ((ctx->index = (ctx->index + 8) % ctx->max_block_size) == 0) {
+     326                 :          0 :                 keccak_f1600(ctx);
+     327                 :            :             }
+     328                 :            :         }
+     329                 :            :     }
+     330                 :            : 
+     331                 :            :     // handle remaining bytes
+     332         [ #  # ]:          0 :     while (ilen-- > 0) {
+     333                 :          0 :         ABSORB(ctx, ctx->index, *input++);
+     334         [ #  # ]:          0 :         if ((ctx->index = (ctx->index + 1) % ctx->max_block_size) == 0) {
+     335                 :          0 :             keccak_f1600(ctx);
+     336                 :            :         }
+     337                 :            :     }
+     338                 :            : 
+     339                 :          0 :     return 0;
+     340                 :            : }
+     341                 :            : 
+     342                 :          0 : int mbedtls_sha3_finish(mbedtls_sha3_context *ctx,
+     343                 :            :                         uint8_t *output, size_t olen)
+     344                 :            : {
+     345                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     346                 :            : 
+     347                 :            :     /* Catch SHA-3 families, with fixed output length */
+     348         [ #  # ]:          0 :     if (ctx->olen > 0) {
+     349         [ #  # ]:          0 :         if (ctx->olen > olen) {
+     350                 :          0 :             ret = MBEDTLS_ERR_SHA3_BAD_INPUT_DATA;
+     351                 :          0 :             goto exit;
+     352                 :            :         }
+     353                 :          0 :         olen = ctx->olen;
+     354                 :            :     }
+     355                 :            : 
+     356                 :          0 :     ABSORB(ctx, ctx->index, XOR_BYTE);
+     357                 :          0 :     ABSORB(ctx, ctx->max_block_size - 1, 0x80);
+     358                 :          0 :     keccak_f1600(ctx);
+     359                 :          0 :     ctx->index = 0;
+     360                 :            : 
+     361         [ #  # ]:          0 :     while (olen-- > 0) {
+     362                 :          0 :         *output++ = SQUEEZE(ctx, ctx->index);
+     363                 :            : 
+     364         [ #  # ]:          0 :         if ((ctx->index = (ctx->index + 1) % ctx->max_block_size) == 0) {
+     365                 :          0 :             keccak_f1600(ctx);
+     366                 :            :         }
+     367                 :            :     }
+     368                 :            : 
+     369                 :          0 :     ret = 0;
+     370                 :            : 
+     371                 :          0 : exit:
+     372                 :          0 :     mbedtls_sha3_free(ctx);
+     373                 :          0 :     return ret;
+     374                 :            : }
+     375                 :            : 
+     376                 :            : /*
+     377                 :            :  * output = SHA-3( input buffer )
+     378                 :            :  */
+     379                 :          0 : int mbedtls_sha3(mbedtls_sha3_id id, const uint8_t *input,
+     380                 :            :                  size_t ilen, uint8_t *output, size_t olen)
+     381                 :            : {
+     382                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     383                 :            :     mbedtls_sha3_context ctx;
+     384                 :            : 
+     385                 :          0 :     mbedtls_sha3_init(&ctx);
+     386                 :            : 
+     387                 :            :     /* Sanity checks are performed in every mbedtls_sha3_xxx() */
+     388         [ #  # ]:          0 :     if ((ret = mbedtls_sha3_starts(&ctx, id)) != 0) {
+     389                 :          0 :         goto exit;
+     390                 :            :     }
+     391                 :            : 
+     392         [ #  # ]:          0 :     if ((ret = mbedtls_sha3_update(&ctx, input, ilen)) != 0) {
+     393                 :          0 :         goto exit;
+     394                 :            :     }
+     395                 :            : 
+     396         [ #  # ]:          0 :     if ((ret = mbedtls_sha3_finish(&ctx, output, olen)) != 0) {
+     397                 :          0 :         goto exit;
+     398                 :            :     }
+     399                 :            : 
+     400                 :          0 : exit:
+     401                 :          0 :     mbedtls_sha3_free(&ctx);
+     402                 :            : 
+     403                 :          0 :     return ret;
+     404                 :            : }
+     405                 :            : 
+     406                 :            : /**************** Self-tests ****************/
+     407                 :            : 
+     408                 :            : #if defined(MBEDTLS_SELF_TEST)
+     409                 :            : 
+     410                 :            : static const unsigned char test_data[2][4] =
+     411                 :            : {
+     412                 :            :     "",
+     413                 :            :     "abc",
+     414                 :            : };
+     415                 :            : 
+     416                 :            : static const size_t test_data_len[2] =
+     417                 :            : {
+     418                 :            :     0, /* "" */
+     419                 :            :     3  /* "abc" */
+     420                 :            : };
+     421                 :            : 
+     422                 :            : static const unsigned char test_hash_sha3_224[2][28] =
+     423                 :            : {
+     424                 :            :     { /* "" */
+     425                 :            :         0x6B, 0x4E, 0x03, 0x42, 0x36, 0x67, 0xDB, 0xB7,
+     426                 :            :         0x3B, 0x6E, 0x15, 0x45, 0x4F, 0x0E, 0xB1, 0xAB,
+     427                 :            :         0xD4, 0x59, 0x7F, 0x9A, 0x1B, 0x07, 0x8E, 0x3F,
+     428                 :            :         0x5B, 0x5A, 0x6B, 0xC7
+     429                 :            :     },
+     430                 :            :     { /* "abc" */
+     431                 :            :         0xE6, 0x42, 0x82, 0x4C, 0x3F, 0x8C, 0xF2, 0x4A,
+     432                 :            :         0xD0, 0x92, 0x34, 0xEE, 0x7D, 0x3C, 0x76, 0x6F,
+     433                 :            :         0xC9, 0xA3, 0xA5, 0x16, 0x8D, 0x0C, 0x94, 0xAD,
+     434                 :            :         0x73, 0xB4, 0x6F, 0xDF
+     435                 :            :     }
+     436                 :            : };
+     437                 :            : 
+     438                 :            : static const unsigned char test_hash_sha3_256[2][32] =
+     439                 :            : {
+     440                 :            :     { /* "" */
+     441                 :            :         0xA7, 0xFF, 0xC6, 0xF8, 0xBF, 0x1E, 0xD7, 0x66,
+     442                 :            :         0x51, 0xC1, 0x47, 0x56, 0xA0, 0x61, 0xD6, 0x62,
+     443                 :            :         0xF5, 0x80, 0xFF, 0x4D, 0xE4, 0x3B, 0x49, 0xFA,
+     444                 :            :         0x82, 0xD8, 0x0A, 0x4B, 0x80, 0xF8, 0x43, 0x4A
+     445                 :            :     },
+     446                 :            :     { /* "abc" */
+     447                 :            :         0x3A, 0x98, 0x5D, 0xA7, 0x4F, 0xE2, 0x25, 0xB2,
+     448                 :            :         0x04, 0x5C, 0x17, 0x2D, 0x6B, 0xD3, 0x90, 0xBD,
+     449                 :            :         0x85, 0x5F, 0x08, 0x6E, 0x3E, 0x9D, 0x52, 0x5B,
+     450                 :            :         0x46, 0xBF, 0xE2, 0x45, 0x11, 0x43, 0x15, 0x32
+     451                 :            :     }
+     452                 :            : };
+     453                 :            : 
+     454                 :            : static const unsigned char test_hash_sha3_384[2][48] =
+     455                 :            : {
+     456                 :            :     { /* "" */
+     457                 :            :         0x0C, 0x63, 0xA7, 0x5B, 0x84, 0x5E, 0x4F, 0x7D,
+     458                 :            :         0x01, 0x10, 0x7D, 0x85, 0x2E, 0x4C, 0x24, 0x85,
+     459                 :            :         0xC5, 0x1A, 0x50, 0xAA, 0xAA, 0x94, 0xFC, 0x61,
+     460                 :            :         0x99, 0x5E, 0x71, 0xBB, 0xEE, 0x98, 0x3A, 0x2A,
+     461                 :            :         0xC3, 0x71, 0x38, 0x31, 0x26, 0x4A, 0xDB, 0x47,
+     462                 :            :         0xFB, 0x6B, 0xD1, 0xE0, 0x58, 0xD5, 0xF0, 0x04
+     463                 :            :     },
+     464                 :            :     { /* "abc" */
+     465                 :            :         0xEC, 0x01, 0x49, 0x82, 0x88, 0x51, 0x6F, 0xC9,
+     466                 :            :         0x26, 0x45, 0x9F, 0x58, 0xE2, 0xC6, 0xAD, 0x8D,
+     467                 :            :         0xF9, 0xB4, 0x73, 0xCB, 0x0F, 0xC0, 0x8C, 0x25,
+     468                 :            :         0x96, 0xDA, 0x7C, 0xF0, 0xE4, 0x9B, 0xE4, 0xB2,
+     469                 :            :         0x98, 0xD8, 0x8C, 0xEA, 0x92, 0x7A, 0xC7, 0xF5,
+     470                 :            :         0x39, 0xF1, 0xED, 0xF2, 0x28, 0x37, 0x6D, 0x25
+     471                 :            :     }
+     472                 :            : };
+     473                 :            : 
+     474                 :            : static const unsigned char test_hash_sha3_512[2][64] =
+     475                 :            : {
+     476                 :            :     { /* "" */
+     477                 :            :         0xA6, 0x9F, 0x73, 0xCC, 0xA2, 0x3A, 0x9A, 0xC5,
+     478                 :            :         0xC8, 0xB5, 0x67, 0xDC, 0x18, 0x5A, 0x75, 0x6E,
+     479                 :            :         0x97, 0xC9, 0x82, 0x16, 0x4F, 0xE2, 0x58, 0x59,
+     480                 :            :         0xE0, 0xD1, 0xDC, 0xC1, 0x47, 0x5C, 0x80, 0xA6,
+     481                 :            :         0x15, 0xB2, 0x12, 0x3A, 0xF1, 0xF5, 0xF9, 0x4C,
+     482                 :            :         0x11, 0xE3, 0xE9, 0x40, 0x2C, 0x3A, 0xC5, 0x58,
+     483                 :            :         0xF5, 0x00, 0x19, 0x9D, 0x95, 0xB6, 0xD3, 0xE3,
+     484                 :            :         0x01, 0x75, 0x85, 0x86, 0x28, 0x1D, 0xCD, 0x26
+     485                 :            :     },
+     486                 :            :     { /* "abc" */
+     487                 :            :         0xB7, 0x51, 0x85, 0x0B, 0x1A, 0x57, 0x16, 0x8A,
+     488                 :            :         0x56, 0x93, 0xCD, 0x92, 0x4B, 0x6B, 0x09, 0x6E,
+     489                 :            :         0x08, 0xF6, 0x21, 0x82, 0x74, 0x44, 0xF7, 0x0D,
+     490                 :            :         0x88, 0x4F, 0x5D, 0x02, 0x40, 0xD2, 0x71, 0x2E,
+     491                 :            :         0x10, 0xE1, 0x16, 0xE9, 0x19, 0x2A, 0xF3, 0xC9,
+     492                 :            :         0x1A, 0x7E, 0xC5, 0x76, 0x47, 0xE3, 0x93, 0x40,
+     493                 :            :         0x57, 0x34, 0x0B, 0x4C, 0xF4, 0x08, 0xD5, 0xA5,
+     494                 :            :         0x65, 0x92, 0xF8, 0x27, 0x4E, 0xEC, 0x53, 0xF0
+     495                 :            :     }
+     496                 :            : };
+     497                 :            : 
+     498                 :            : static const unsigned char long_kat_hash_sha3_224[28] =
+     499                 :            : {
+     500                 :            :     0xD6, 0x93, 0x35, 0xB9, 0x33, 0x25, 0x19, 0x2E,
+     501                 :            :     0x51, 0x6A, 0x91, 0x2E, 0x6D, 0x19, 0xA1, 0x5C,
+     502                 :            :     0xB5, 0x1C, 0x6E, 0xD5, 0xC1, 0x52, 0x43, 0xE7,
+     503                 :            :     0xA7, 0xFD, 0x65, 0x3C
+     504                 :            : };
+     505                 :            : 
+     506                 :            : static const unsigned char long_kat_hash_sha3_256[32] =
+     507                 :            : {
+     508                 :            :     0x5C, 0x88, 0x75, 0xAE, 0x47, 0x4A, 0x36, 0x34,
+     509                 :            :     0xBA, 0x4F, 0xD5, 0x5E, 0xC8, 0x5B, 0xFF, 0xD6,
+     510                 :            :     0x61, 0xF3, 0x2A, 0xCA, 0x75, 0xC6, 0xD6, 0x99,
+     511                 :            :     0xD0, 0xCD, 0xCB, 0x6C, 0x11, 0x58, 0x91, 0xC1
+     512                 :            : };
+     513                 :            : 
+     514                 :            : static const unsigned char long_kat_hash_sha3_384[48] =
+     515                 :            : {
+     516                 :            :     0xEE, 0xE9, 0xE2, 0x4D, 0x78, 0xC1, 0x85, 0x53,
+     517                 :            :     0x37, 0x98, 0x34, 0x51, 0xDF, 0x97, 0xC8, 0xAD,
+     518                 :            :     0x9E, 0xED, 0xF2, 0x56, 0xC6, 0x33, 0x4F, 0x8E,
+     519                 :            :     0x94, 0x8D, 0x25, 0x2D, 0x5E, 0x0E, 0x76, 0x84,
+     520                 :            :     0x7A, 0xA0, 0x77, 0x4D, 0xDB, 0x90, 0xA8, 0x42,
+     521                 :            :     0x19, 0x0D, 0x2C, 0x55, 0x8B, 0x4B, 0x83, 0x40
+     522                 :            : };
+     523                 :            : 
+     524                 :            : static const unsigned char long_kat_hash_sha3_512[64] =
+     525                 :            : {
+     526                 :            :     0x3C, 0x3A, 0x87, 0x6D, 0xA1, 0x40, 0x34, 0xAB,
+     527                 :            :     0x60, 0x62, 0x7C, 0x07, 0x7B, 0xB9, 0x8F, 0x7E,
+     528                 :            :     0x12, 0x0A, 0x2A, 0x53, 0x70, 0x21, 0x2D, 0xFF,
+     529                 :            :     0xB3, 0x38, 0x5A, 0x18, 0xD4, 0xF3, 0x88, 0x59,
+     530                 :            :     0xED, 0x31, 0x1D, 0x0A, 0x9D, 0x51, 0x41, 0xCE,
+     531                 :            :     0x9C, 0xC5, 0xC6, 0x6E, 0xE6, 0x89, 0xB2, 0x66,
+     532                 :            :     0xA8, 0xAA, 0x18, 0xAC, 0xE8, 0x28, 0x2A, 0x0E,
+     533                 :            :     0x0D, 0xB5, 0x96, 0xC9, 0x0B, 0x0A, 0x7B, 0x87
+     534                 :            : };
+     535                 :            : 
+     536                 :          0 : static int mbedtls_sha3_kat_test(int verbose,
+     537                 :            :                                  const char *type_name,
+     538                 :            :                                  mbedtls_sha3_id id,
+     539                 :            :                                  int test_num)
+     540                 :            : {
+     541                 :            :     uint8_t hash[64];
+     542                 :            :     int result;
+     543                 :            : 
+     544                 :          0 :     result = mbedtls_sha3(id,
+     545                 :          0 :                           test_data[test_num], test_data_len[test_num],
+     546                 :            :                           hash, sizeof(hash));
+     547         [ #  # ]:          0 :     if (result != 0) {
+     548         [ #  # ]:          0 :         if (verbose != 0) {
+     549                 :          0 :             mbedtls_printf("  %s test %d error code: %d\n",
+     550                 :            :                            type_name, test_num, result);
+     551                 :            :         }
+     552                 :            : 
+     553                 :          0 :         return result;
+     554                 :            :     }
+     555                 :            : 
+     556   [ #  #  #  #  :          0 :     switch (id) {
+                      # ]
+     557                 :          0 :         case MBEDTLS_SHA3_224:
+     558                 :          0 :             result = memcmp(hash, test_hash_sha3_224[test_num], 28);
+     559                 :          0 :             break;
+     560                 :          0 :         case MBEDTLS_SHA3_256:
+     561                 :          0 :             result = memcmp(hash, test_hash_sha3_256[test_num], 32);
+     562                 :          0 :             break;
+     563                 :          0 :         case MBEDTLS_SHA3_384:
+     564                 :          0 :             result = memcmp(hash, test_hash_sha3_384[test_num], 48);
+     565                 :          0 :             break;
+     566                 :          0 :         case MBEDTLS_SHA3_512:
+     567                 :          0 :             result = memcmp(hash, test_hash_sha3_512[test_num], 64);
+     568                 :          0 :             break;
+     569                 :          0 :         default:
+     570                 :          0 :             break;
+     571                 :            :     }
+     572                 :            : 
+     573         [ #  # ]:          0 :     if (0 != result) {
+     574         [ #  # ]:          0 :         if (verbose != 0) {
+     575                 :          0 :             mbedtls_printf("  %s test %d failed\n", type_name, test_num);
+     576                 :            :         }
+     577                 :            : 
+     578                 :          0 :         return -1;
+     579                 :            :     }
+     580                 :            : 
+     581         [ #  # ]:          0 :     if (verbose != 0) {
+     582                 :          0 :         mbedtls_printf("  %s test %d passed\n", type_name, test_num);
+     583                 :            :     }
+     584                 :            : 
+     585                 :          0 :     return 0;
+     586                 :            : }
+     587                 :            : 
+     588                 :          0 : static int mbedtls_sha3_long_kat_test(int verbose,
+     589                 :            :                                       const char *type_name,
+     590                 :            :                                       mbedtls_sha3_id id)
+     591                 :            : {
+     592                 :            :     mbedtls_sha3_context ctx;
+     593                 :            :     unsigned char buffer[1000];
+     594                 :            :     unsigned char hash[64];
+     595                 :          0 :     int result = 0;
+     596                 :            : 
+     597                 :          0 :     memset(buffer, 'a', 1000);
+     598                 :            : 
+     599         [ #  # ]:          0 :     if (verbose != 0) {
+     600                 :          0 :         mbedtls_printf("  %s long KAT test ", type_name);
+     601                 :            :     }
+     602                 :            : 
+     603                 :          0 :     mbedtls_sha3_init(&ctx);
+     604                 :            : 
+     605                 :          0 :     result = mbedtls_sha3_starts(&ctx, id);
+     606         [ #  # ]:          0 :     if (result != 0) {
+     607         [ #  # ]:          0 :         if (verbose != 0) {
+     608                 :          0 :             mbedtls_printf("setup failed\n ");
+     609                 :            :         }
+     610                 :            :     }
+     611                 :            : 
+     612                 :            :     /* Process 1,000,000 (one million) 'a' characters */
+     613         [ #  # ]:          0 :     for (int i = 0; i < 1000; i++) {
+     614                 :          0 :         result = mbedtls_sha3_update(&ctx, buffer, 1000);
+     615         [ #  # ]:          0 :         if (result != 0) {
+     616         [ #  # ]:          0 :             if (verbose != 0) {
+     617                 :          0 :                 mbedtls_printf("update error code: %i\n", result);
+     618                 :            :             }
+     619                 :            : 
+     620                 :          0 :             goto cleanup;
+     621                 :            :         }
+     622                 :            :     }
+     623                 :            : 
+     624                 :          0 :     result = mbedtls_sha3_finish(&ctx, hash, sizeof(hash));
+     625         [ #  # ]:          0 :     if (result != 0) {
+     626         [ #  # ]:          0 :         if (verbose != 0) {
+     627                 :          0 :             mbedtls_printf("finish error code: %d\n", result);
+     628                 :            :         }
+     629                 :            : 
+     630                 :          0 :         goto cleanup;
+     631                 :            :     }
+     632                 :            : 
+     633   [ #  #  #  #  :          0 :     switch (id) {
+                      # ]
+     634                 :          0 :         case MBEDTLS_SHA3_224:
+     635                 :          0 :             result = memcmp(hash, long_kat_hash_sha3_224, 28);
+     636                 :          0 :             break;
+     637                 :          0 :         case MBEDTLS_SHA3_256:
+     638                 :          0 :             result = memcmp(hash, long_kat_hash_sha3_256, 32);
+     639                 :          0 :             break;
+     640                 :          0 :         case MBEDTLS_SHA3_384:
+     641                 :          0 :             result = memcmp(hash, long_kat_hash_sha3_384, 48);
+     642                 :          0 :             break;
+     643                 :          0 :         case MBEDTLS_SHA3_512:
+     644                 :          0 :             result = memcmp(hash, long_kat_hash_sha3_512, 64);
+     645                 :          0 :             break;
+     646                 :          0 :         default:
+     647                 :          0 :             break;
+     648                 :            :     }
+     649                 :            : 
+     650         [ #  # ]:          0 :     if (result != 0) {
+     651         [ #  # ]:          0 :         if (verbose != 0) {
+     652                 :          0 :             mbedtls_printf("failed\n");
+     653                 :            :         }
+     654                 :            :     }
+     655                 :            : 
+     656         [ #  # ]:          0 :     if (verbose != 0) {
+     657                 :          0 :         mbedtls_printf("passed\n");
+     658                 :            :     }
+     659                 :            : 
+     660                 :          0 : cleanup:
+     661                 :          0 :     mbedtls_sha3_free(&ctx);
+     662                 :          0 :     return result;
+     663                 :            : }
+     664                 :            : 
+     665                 :          0 : int mbedtls_sha3_self_test(int verbose)
+     666                 :            : {
+     667                 :            :     int i;
+     668                 :            : 
+     669                 :            :     /* SHA-3 Known Answer Tests (KAT) */
+     670         [ #  # ]:          0 :     for (i = 0; i < 2; i++) {
+     671         [ #  # ]:          0 :         if (0 != mbedtls_sha3_kat_test(verbose,
+     672                 :            :                                        "SHA3-224", MBEDTLS_SHA3_224, i)) {
+     673                 :          0 :             return 1;
+     674                 :            :         }
+     675                 :            : 
+     676         [ #  # ]:          0 :         if (0 != mbedtls_sha3_kat_test(verbose,
+     677                 :            :                                        "SHA3-256", MBEDTLS_SHA3_256, i)) {
+     678                 :          0 :             return 1;
+     679                 :            :         }
+     680                 :            : 
+     681         [ #  # ]:          0 :         if (0 != mbedtls_sha3_kat_test(verbose,
+     682                 :            :                                        "SHA3-384", MBEDTLS_SHA3_384, i)) {
+     683                 :          0 :             return 1;
+     684                 :            :         }
+     685                 :            : 
+     686         [ #  # ]:          0 :         if (0 != mbedtls_sha3_kat_test(verbose,
+     687                 :            :                                        "SHA3-512", MBEDTLS_SHA3_512, i)) {
+     688                 :          0 :             return 1;
+     689                 :            :         }
+     690                 :            :     }
+     691                 :            : 
+     692                 :            :     /* SHA-3 long KAT tests */
+     693         [ #  # ]:          0 :     if (0 != mbedtls_sha3_long_kat_test(verbose,
+     694                 :            :                                         "SHA3-224", MBEDTLS_SHA3_224)) {
+     695                 :          0 :         return 1;
+     696                 :            :     }
+     697                 :            : 
+     698         [ #  # ]:          0 :     if (0 != mbedtls_sha3_long_kat_test(verbose,
+     699                 :            :                                         "SHA3-256", MBEDTLS_SHA3_256)) {
+     700                 :          0 :         return 1;
+     701                 :            :     }
+     702                 :            : 
+     703         [ #  # ]:          0 :     if (0 != mbedtls_sha3_long_kat_test(verbose,
+     704                 :            :                                         "SHA3-384", MBEDTLS_SHA3_384)) {
+     705                 :          0 :         return 1;
+     706                 :            :     }
+     707                 :            : 
+     708         [ #  # ]:          0 :     if (0 != mbedtls_sha3_long_kat_test(verbose,
+     709                 :            :                                         "SHA3-512", MBEDTLS_SHA3_512)) {
+     710                 :          0 :         return 1;
+     711                 :            :     }
+     712                 :            : 
+     713         [ #  # ]:          0 :     if (verbose != 0) {
+     714                 :          0 :         mbedtls_printf("\n");
+     715                 :            :     }
+     716                 :            : 
+     717                 :          0 :     return 0;
+     718                 :            : }
+     719                 :            : #endif /* MBEDTLS_SELF_TEST */
+     720                 :            : 
+     721                 :            : #endif /* MBEDTLS_SHA3_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/sha512.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/sha512.c.func-sort-c.html new file mode 100644 index 00000000000..b404ba44624 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/sha512.c.func-sort-c.html @@ -0,0 +1,129 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/sha512.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - sha512.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:12018963.5 %
Date:2024-09-22 08:21:07Functions:81266.7 %
Branches:378643.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_sha384_self_test0
mbedtls_sha512_clone0
mbedtls_sha512_common_self_test0
mbedtls_sha512_self_test0
mbedtls_internal_sha512_process_many49
mbedtls_sha512259
mbedtls_sha512_init261
mbedtls_sha512_finish263
mbedtls_sha512_starts263
mbedtls_sha512_update267
mbedtls_sha512_free524
mbedtls_internal_sha512_process536
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/sha512.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/sha512.c.func.html new file mode 100644 index 00000000000..edfd5edc444 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/sha512.c.func.html @@ -0,0 +1,129 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/sha512.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - sha512.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:12018963.5 %
Date:2024-09-22 08:21:07Functions:81266.7 %
Branches:378643.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_internal_sha512_process536
mbedtls_internal_sha512_process_many49
mbedtls_sha384_self_test0
mbedtls_sha512259
mbedtls_sha512_clone0
mbedtls_sha512_common_self_test0
mbedtls_sha512_finish263
mbedtls_sha512_free524
mbedtls_sha512_init261
mbedtls_sha512_self_test0
mbedtls_sha512_starts263
mbedtls_sha512_update267
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/sha512.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/sha512.c.gcov.html new file mode 100644 index 00000000000..fcb3c3319ed --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/sha512.c.gcov.html @@ -0,0 +1,1197 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/sha512.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - sha512.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:12018963.5 %
Date:2024-09-22 08:21:07Functions:81266.7 %
Branches:378643.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  *  FIPS-180-2 compliant SHA-384/512 implementation
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  */
+       7                 :            : /*
+       8                 :            :  *  The SHA-512 Secure Hash Standard was published by NIST in 2002.
+       9                 :            :  *
+      10                 :            :  *  http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf
+      11                 :            :  */
+      12                 :            : 
+      13                 :            : #if defined(__aarch64__) && !defined(__ARM_FEATURE_SHA512) && \
+      14                 :            :     defined(__clang__) && __clang_major__ >= 7
+      15                 :            : /* TODO: Re-consider above after https://reviews.llvm.org/D131064 merged.
+      16                 :            :  *
+      17                 :            :  * The intrinsic declaration are guarded by predefined ACLE macros in clang:
+      18                 :            :  * these are normally only enabled by the -march option on the command line.
+      19                 :            :  * By defining the macros ourselves we gain access to those declarations without
+      20                 :            :  * requiring -march on the command line.
+      21                 :            :  *
+      22                 :            :  * `arm_neon.h` is included by common.h, so we put these defines
+      23                 :            :  * at the top of this file, before any includes.
+      24                 :            :  */
+      25                 :            : #define __ARM_FEATURE_SHA512 1
+      26                 :            : #define MBEDTLS_ENABLE_ARM_SHA3_EXTENSIONS_COMPILER_FLAG
+      27                 :            : #endif
+      28                 :            : 
+      29                 :            : #include "common.h"
+      30                 :            : 
+      31                 :            : #if defined(MBEDTLS_SHA512_C) || defined(MBEDTLS_SHA384_C)
+      32                 :            : 
+      33                 :            : #include "mbedtls/sha512.h"
+      34                 :            : #include "mbedtls/platform_util.h"
+      35                 :            : #include "mbedtls/error.h"
+      36                 :            : 
+      37                 :            : #if defined(_MSC_VER) || defined(__WATCOMC__)
+      38                 :            :   #define UL64(x) x##ui64
+      39                 :            : #else
+      40                 :            :   #define UL64(x) x##ULL
+      41                 :            : #endif
+      42                 :            : 
+      43                 :            : #include <string.h>
+      44                 :            : 
+      45                 :            : #include "mbedtls/platform.h"
+      46                 :            : 
+      47                 :            : #if defined(__aarch64__)
+      48                 :            : #  if defined(MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT) || \
+      49                 :            :     defined(MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY)
+      50                 :            : /* *INDENT-OFF* */
+      51                 :            : #   if !defined(MBEDTLS_HAVE_NEON_INTRINSICS)
+      52                 :            : #       error "Target does not support NEON instructions"
+      53                 :            : #   endif
+      54                 :            : /*
+      55                 :            :  * Best performance comes from most recent compilers, with intrinsics and -O3.
+      56                 :            :  * Must compile with -march=armv8.2-a+sha3, but we can't detect armv8.2-a, and
+      57                 :            :  * can't always detect __ARM_FEATURE_SHA512 (notably clang 7-12).
+      58                 :            :  *
+      59                 :            :  * GCC < 8 won't work at all (lacks the sha512 instructions)
+      60                 :            :  * GCC >= 8 uses intrinsics, sets __ARM_FEATURE_SHA512
+      61                 :            :  *
+      62                 :            :  * Clang < 7 won't work at all (lacks the sha512 instructions)
+      63                 :            :  * Clang 7-12 don't have intrinsics (but we work around that with inline
+      64                 :            :  *            assembler) or __ARM_FEATURE_SHA512
+      65                 :            :  * Clang == 13.0.0 same as clang 12 (only seen on macOS)
+      66                 :            :  * Clang >= 13.0.1 has __ARM_FEATURE_SHA512 and intrinsics
+      67                 :            :  */
+      68                 :            : #    if !defined(__ARM_FEATURE_SHA512) || defined(MBEDTLS_ENABLE_ARM_SHA3_EXTENSIONS_COMPILER_FLAG)
+      69                 :            :        /* Test Clang first, as it defines __GNUC__ */
+      70                 :            : #      if defined(__ARMCOMPILER_VERSION)
+      71                 :            : #        if __ARMCOMPILER_VERSION < 6090000
+      72                 :            : #          error "A more recent armclang is required for MBEDTLS_SHA512_USE_A64_CRYPTO_*"
+      73                 :            : #        elif __ARMCOMPILER_VERSION == 6090000
+      74                 :            : #          error "Must use minimum -march=armv8.2-a+sha3 for MBEDTLS_SHA512_USE_A64_CRYPTO_*"
+      75                 :            : #        else
+      76                 :            : #          pragma clang attribute push (__attribute__((target("sha3"))), apply_to=function)
+      77                 :            : #          define MBEDTLS_POP_TARGET_PRAGMA
+      78                 :            : #        endif
+      79                 :            : #      elif defined(__clang__)
+      80                 :            : #        if __clang_major__ < 7
+      81                 :            : #          error "A more recent Clang is required for MBEDTLS_SHA512_USE_A64_CRYPTO_*"
+      82                 :            : #        else
+      83                 :            : #          pragma clang attribute push (__attribute__((target("sha3"))), apply_to=function)
+      84                 :            : #          define MBEDTLS_POP_TARGET_PRAGMA
+      85                 :            : #        endif
+      86                 :            : #      elif defined(__GNUC__)
+      87                 :            : #        if __GNUC__ < 8
+      88                 :            : #          error "A more recent GCC is required for MBEDTLS_SHA512_USE_A64_CRYPTO_*"
+      89                 :            : #        else
+      90                 :            : #          pragma GCC push_options
+      91                 :            : #          pragma GCC target ("arch=armv8.2-a+sha3")
+      92                 :            : #          define MBEDTLS_POP_TARGET_PRAGMA
+      93                 :            : #        endif
+      94                 :            : #      else
+      95                 :            : #        error "Only GCC and Clang supported for MBEDTLS_SHA512_USE_A64_CRYPTO_*"
+      96                 :            : #      endif
+      97                 :            : #    endif
+      98                 :            : /* *INDENT-ON* */
+      99                 :            : #  endif
+     100                 :            : #  if defined(MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT)
+     101                 :            : #    if defined(__unix__)
+     102                 :            : #      if defined(__linux__)
+     103                 :            : /* Our preferred method of detection is getauxval() */
+     104                 :            : #        include <sys/auxv.h>
+     105                 :            : #        if !defined(HWCAP_SHA512)
+     106                 :            : /* The same header that declares getauxval() should provide the HWCAP_xxx
+     107                 :            :  * constants to analyze its return value. However, the libc may be too
+     108                 :            :  * old to have the constant that we need. So if it's missing, assume that
+     109                 :            :  * the value is the same one used by the Linux kernel ABI.
+     110                 :            :  */
+     111                 :            : #          define HWCAP_SHA512 (1 << 21)
+     112                 :            : #        endif
+     113                 :            : #      endif
+     114                 :            : /* Use SIGILL on Unix, and fall back to it on Linux */
+     115                 :            : #      include <signal.h>
+     116                 :            : #    endif
+     117                 :            : #  endif
+     118                 :            : #elif !defined(MBEDTLS_PLATFORM_IS_WINDOWS_ON_ARM64)
+     119                 :            : #  undef MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY
+     120                 :            : #  undef MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
+     121                 :            : #endif
+     122                 :            : 
+     123                 :            : #if defined(MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT)
+     124                 :            : /*
+     125                 :            :  * Capability detection code comes early, so we can disable
+     126                 :            :  * MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT if no detection mechanism found
+     127                 :            :  */
+     128                 :            : #if defined(HWCAP_SHA512)
+     129                 :            : static int mbedtls_a64_crypto_sha512_determine_support(void)
+     130                 :            : {
+     131                 :            :     return (getauxval(AT_HWCAP) & HWCAP_SHA512) ? 1 : 0;
+     132                 :            : }
+     133                 :            : #elif defined(__APPLE__)
+     134                 :            : #include <sys/types.h>
+     135                 :            : #include <sys/sysctl.h>
+     136                 :            : 
+     137                 :            : static int mbedtls_a64_crypto_sha512_determine_support(void)
+     138                 :            : {
+     139                 :            :     int value = 0;
+     140                 :            :     size_t value_len = sizeof(value);
+     141                 :            : 
+     142                 :            :     int ret = sysctlbyname("hw.optional.armv8_2_sha512", &value, &value_len,
+     143                 :            :                            NULL, 0);
+     144                 :            :     return ret == 0 && value != 0;
+     145                 :            : }
+     146                 :            : #elif defined(MBEDTLS_PLATFORM_IS_WINDOWS_ON_ARM64)
+     147                 :            : /*
+     148                 :            :  * As of March 2022, there don't appear to be any PF_ARM_V8_* flags
+     149                 :            :  * available to pass to IsProcessorFeaturePresent() to check for
+     150                 :            :  * SHA-512 support. So we fall back to the C code only.
+     151                 :            :  */
+     152                 :            : #if defined(_MSC_VER)
+     153                 :            : #pragma message "No mechanism to detect A64_CRYPTO found, using C code only"
+     154                 :            : #else
+     155                 :            : #warning "No mechanism to detect A64_CRYPTO found, using C code only"
+     156                 :            : #endif
+     157                 :            : #elif defined(__unix__) && defined(SIG_SETMASK)
+     158                 :            : /* Detection with SIGILL, setjmp() and longjmp() */
+     159                 :            : #include <signal.h>
+     160                 :            : #include <setjmp.h>
+     161                 :            : 
+     162                 :            : static jmp_buf return_from_sigill;
+     163                 :            : 
+     164                 :            : /*
+     165                 :            :  * A64 SHA512 support detection via SIGILL
+     166                 :            :  */
+     167                 :            : static void sigill_handler(int signal)
+     168                 :            : {
+     169                 :            :     (void) signal;
+     170                 :            :     longjmp(return_from_sigill, 1);
+     171                 :            : }
+     172                 :            : 
+     173                 :            : static int mbedtls_a64_crypto_sha512_determine_support(void)
+     174                 :            : {
+     175                 :            :     struct sigaction old_action, new_action;
+     176                 :            : 
+     177                 :            :     sigset_t old_mask;
+     178                 :            :     if (sigprocmask(0, NULL, &old_mask)) {
+     179                 :            :         return 0;
+     180                 :            :     }
+     181                 :            : 
+     182                 :            :     sigemptyset(&new_action.sa_mask);
+     183                 :            :     new_action.sa_flags = 0;
+     184                 :            :     new_action.sa_handler = sigill_handler;
+     185                 :            : 
+     186                 :            :     sigaction(SIGILL, &new_action, &old_action);
+     187                 :            : 
+     188                 :            :     static int ret = 0;
+     189                 :            : 
+     190                 :            :     if (setjmp(return_from_sigill) == 0) {         /* First return only */
+     191                 :            :         /* If this traps, we will return a second time from setjmp() with 1 */
+     192                 :            :         asm ("sha512h q0, q0, v0.2d" : : : "v0");
+     193                 :            :         ret = 1;
+     194                 :            :     }
+     195                 :            : 
+     196                 :            :     sigaction(SIGILL, &old_action, NULL);
+     197                 :            :     sigprocmask(SIG_SETMASK, &old_mask, NULL);
+     198                 :            : 
+     199                 :            :     return ret;
+     200                 :            : }
+     201                 :            : #else
+     202                 :            : #warning "No mechanism to detect A64_CRYPTO found, using C code only"
+     203                 :            : #undef MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
+     204                 :            : #endif  /* HWCAP_SHA512, __APPLE__, __unix__ && SIG_SETMASK */
+     205                 :            : 
+     206                 :            : #endif  /* MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT */
+     207                 :            : 
+     208                 :            : #if !defined(MBEDTLS_SHA512_ALT)
+     209                 :            : 
+     210                 :            : #define SHA512_BLOCK_SIZE 128
+     211                 :            : 
+     212                 :            : #if defined(MBEDTLS_SHA512_SMALLER)
+     213                 :            : static void sha512_put_uint64_be(uint64_t n, unsigned char *b, uint8_t i)
+     214                 :            : {
+     215                 :            :     MBEDTLS_PUT_UINT64_BE(n, b, i);
+     216                 :            : }
+     217                 :            : #else
+     218                 :            : #define sha512_put_uint64_be    MBEDTLS_PUT_UINT64_BE
+     219                 :            : #endif /* MBEDTLS_SHA512_SMALLER */
+     220                 :            : 
+     221                 :        261 : void mbedtls_sha512_init(mbedtls_sha512_context *ctx)
+     222                 :            : {
+     223                 :        261 :     memset(ctx, 0, sizeof(mbedtls_sha512_context));
+     224                 :        261 : }
+     225                 :            : 
+     226                 :        524 : void mbedtls_sha512_free(mbedtls_sha512_context *ctx)
+     227                 :            : {
+     228         [ -  + ]:        524 :     if (ctx == NULL) {
+     229                 :          0 :         return;
+     230                 :            :     }
+     231                 :            : 
+     232                 :        524 :     mbedtls_platform_zeroize(ctx, sizeof(mbedtls_sha512_context));
+     233                 :            : }
+     234                 :            : 
+     235                 :          0 : void mbedtls_sha512_clone(mbedtls_sha512_context *dst,
+     236                 :            :                           const mbedtls_sha512_context *src)
+     237                 :            : {
+     238                 :          0 :     *dst = *src;
+     239                 :          0 : }
+     240                 :            : 
+     241                 :            : /*
+     242                 :            :  * SHA-512 context setup
+     243                 :            :  */
+     244                 :        263 : int mbedtls_sha512_starts(mbedtls_sha512_context *ctx, int is384)
+     245                 :            : {
+     246                 :            : #if defined(MBEDTLS_SHA384_C) && defined(MBEDTLS_SHA512_C)
+     247   [ +  +  -  + ]:        263 :     if (is384 != 0 && is384 != 1) {
+     248                 :          0 :         return MBEDTLS_ERR_SHA512_BAD_INPUT_DATA;
+     249                 :            :     }
+     250                 :            : #elif defined(MBEDTLS_SHA512_C)
+     251                 :            :     if (is384 != 0) {
+     252                 :            :         return MBEDTLS_ERR_SHA512_BAD_INPUT_DATA;
+     253                 :            :     }
+     254                 :            : #else /* defined MBEDTLS_SHA384_C only */
+     255                 :            :     if (is384 == 0) {
+     256                 :            :         return MBEDTLS_ERR_SHA512_BAD_INPUT_DATA;
+     257                 :            :     }
+     258                 :            : #endif
+     259                 :            : 
+     260                 :        263 :     ctx->total[0] = 0;
+     261                 :        263 :     ctx->total[1] = 0;
+     262                 :            : 
+     263         [ +  + ]:        263 :     if (is384 == 0) {
+     264                 :            : #if defined(MBEDTLS_SHA512_C)
+     265                 :         46 :         ctx->state[0] = UL64(0x6A09E667F3BCC908);
+     266                 :         46 :         ctx->state[1] = UL64(0xBB67AE8584CAA73B);
+     267                 :         46 :         ctx->state[2] = UL64(0x3C6EF372FE94F82B);
+     268                 :         46 :         ctx->state[3] = UL64(0xA54FF53A5F1D36F1);
+     269                 :         46 :         ctx->state[4] = UL64(0x510E527FADE682D1);
+     270                 :         46 :         ctx->state[5] = UL64(0x9B05688C2B3E6C1F);
+     271                 :         46 :         ctx->state[6] = UL64(0x1F83D9ABFB41BD6B);
+     272                 :         46 :         ctx->state[7] = UL64(0x5BE0CD19137E2179);
+     273                 :            : #endif /* MBEDTLS_SHA512_C */
+     274                 :            :     } else {
+     275                 :            : #if defined(MBEDTLS_SHA384_C)
+     276                 :        217 :         ctx->state[0] = UL64(0xCBBB9D5DC1059ED8);
+     277                 :        217 :         ctx->state[1] = UL64(0x629A292A367CD507);
+     278                 :        217 :         ctx->state[2] = UL64(0x9159015A3070DD17);
+     279                 :        217 :         ctx->state[3] = UL64(0x152FECD8F70E5939);
+     280                 :        217 :         ctx->state[4] = UL64(0x67332667FFC00B31);
+     281                 :        217 :         ctx->state[5] = UL64(0x8EB44A8768581511);
+     282                 :        217 :         ctx->state[6] = UL64(0xDB0C2E0D64F98FA7);
+     283                 :        217 :         ctx->state[7] = UL64(0x47B5481DBEFA4FA4);
+     284                 :            : #endif /* MBEDTLS_SHA384_C */
+     285                 :            :     }
+     286                 :            : 
+     287                 :            : #if defined(MBEDTLS_SHA384_C)
+     288                 :        263 :     ctx->is384 = is384;
+     289                 :            : #endif
+     290                 :            : 
+     291                 :        263 :     return 0;
+     292                 :            : }
+     293                 :            : 
+     294                 :            : #if !defined(MBEDTLS_SHA512_PROCESS_ALT)
+     295                 :            : 
+     296                 :            : /*
+     297                 :            :  * Round constants
+     298                 :            :  */
+     299                 :            : static const uint64_t K[80] =
+     300                 :            : {
+     301                 :            :     UL64(0x428A2F98D728AE22),  UL64(0x7137449123EF65CD),
+     302                 :            :     UL64(0xB5C0FBCFEC4D3B2F),  UL64(0xE9B5DBA58189DBBC),
+     303                 :            :     UL64(0x3956C25BF348B538),  UL64(0x59F111F1B605D019),
+     304                 :            :     UL64(0x923F82A4AF194F9B),  UL64(0xAB1C5ED5DA6D8118),
+     305                 :            :     UL64(0xD807AA98A3030242),  UL64(0x12835B0145706FBE),
+     306                 :            :     UL64(0x243185BE4EE4B28C),  UL64(0x550C7DC3D5FFB4E2),
+     307                 :            :     UL64(0x72BE5D74F27B896F),  UL64(0x80DEB1FE3B1696B1),
+     308                 :            :     UL64(0x9BDC06A725C71235),  UL64(0xC19BF174CF692694),
+     309                 :            :     UL64(0xE49B69C19EF14AD2),  UL64(0xEFBE4786384F25E3),
+     310                 :            :     UL64(0x0FC19DC68B8CD5B5),  UL64(0x240CA1CC77AC9C65),
+     311                 :            :     UL64(0x2DE92C6F592B0275),  UL64(0x4A7484AA6EA6E483),
+     312                 :            :     UL64(0x5CB0A9DCBD41FBD4),  UL64(0x76F988DA831153B5),
+     313                 :            :     UL64(0x983E5152EE66DFAB),  UL64(0xA831C66D2DB43210),
+     314                 :            :     UL64(0xB00327C898FB213F),  UL64(0xBF597FC7BEEF0EE4),
+     315                 :            :     UL64(0xC6E00BF33DA88FC2),  UL64(0xD5A79147930AA725),
+     316                 :            :     UL64(0x06CA6351E003826F),  UL64(0x142929670A0E6E70),
+     317                 :            :     UL64(0x27B70A8546D22FFC),  UL64(0x2E1B21385C26C926),
+     318                 :            :     UL64(0x4D2C6DFC5AC42AED),  UL64(0x53380D139D95B3DF),
+     319                 :            :     UL64(0x650A73548BAF63DE),  UL64(0x766A0ABB3C77B2A8),
+     320                 :            :     UL64(0x81C2C92E47EDAEE6),  UL64(0x92722C851482353B),
+     321                 :            :     UL64(0xA2BFE8A14CF10364),  UL64(0xA81A664BBC423001),
+     322                 :            :     UL64(0xC24B8B70D0F89791),  UL64(0xC76C51A30654BE30),
+     323                 :            :     UL64(0xD192E819D6EF5218),  UL64(0xD69906245565A910),
+     324                 :            :     UL64(0xF40E35855771202A),  UL64(0x106AA07032BBD1B8),
+     325                 :            :     UL64(0x19A4C116B8D2D0C8),  UL64(0x1E376C085141AB53),
+     326                 :            :     UL64(0x2748774CDF8EEB99),  UL64(0x34B0BCB5E19B48A8),
+     327                 :            :     UL64(0x391C0CB3C5C95A63),  UL64(0x4ED8AA4AE3418ACB),
+     328                 :            :     UL64(0x5B9CCA4F7763E373),  UL64(0x682E6FF3D6B2B8A3),
+     329                 :            :     UL64(0x748F82EE5DEFB2FC),  UL64(0x78A5636F43172F60),
+     330                 :            :     UL64(0x84C87814A1F0AB72),  UL64(0x8CC702081A6439EC),
+     331                 :            :     UL64(0x90BEFFFA23631E28),  UL64(0xA4506CEBDE82BDE9),
+     332                 :            :     UL64(0xBEF9A3F7B2C67915),  UL64(0xC67178F2E372532B),
+     333                 :            :     UL64(0xCA273ECEEA26619C),  UL64(0xD186B8C721C0C207),
+     334                 :            :     UL64(0xEADA7DD6CDE0EB1E),  UL64(0xF57D4F7FEE6ED178),
+     335                 :            :     UL64(0x06F067AA72176FBA),  UL64(0x0A637DC5A2C898A6),
+     336                 :            :     UL64(0x113F9804BEF90DAE),  UL64(0x1B710B35131C471B),
+     337                 :            :     UL64(0x28DB77F523047D84),  UL64(0x32CAAB7B40C72493),
+     338                 :            :     UL64(0x3C9EBE0A15C9BEBC),  UL64(0x431D67C49C100D4C),
+     339                 :            :     UL64(0x4CC5D4BECB3E42B6),  UL64(0x597F299CFC657E2A),
+     340                 :            :     UL64(0x5FCB6FAB3AD6FAEC),  UL64(0x6C44198C4A475817)
+     341                 :            : };
+     342                 :            : #endif
+     343                 :            : 
+     344                 :            : #if defined(MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT) || \
+     345                 :            :     defined(MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY)
+     346                 :            : 
+     347                 :            : #if defined(MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY)
+     348                 :            : #  define mbedtls_internal_sha512_process_many_a64_crypto mbedtls_internal_sha512_process_many
+     349                 :            : #  define mbedtls_internal_sha512_process_a64_crypto      mbedtls_internal_sha512_process
+     350                 :            : #endif
+     351                 :            : 
+     352                 :            : /* Accelerated SHA-512 implementation originally written by Simon Tatham for PuTTY,
+     353                 :            :  * under the MIT licence; dual-licensed as Apache 2 with his kind permission.
+     354                 :            :  */
+     355                 :            : 
+     356                 :            : #if defined(__clang__) && \
+     357                 :            :     (__clang_major__ < 13 || \
+     358                 :            :      (__clang_major__ == 13 && __clang_minor__ == 0 && __clang_patchlevel__ == 0))
+     359                 :            : static inline uint64x2_t vsha512su0q_u64(uint64x2_t x, uint64x2_t y)
+     360                 :            : {
+     361                 :            :     asm ("sha512su0 %0.2D,%1.2D" : "+w" (x) : "w" (y));
+     362                 :            :     return x;
+     363                 :            : }
+     364                 :            : static inline uint64x2_t vsha512su1q_u64(uint64x2_t x, uint64x2_t y, uint64x2_t z)
+     365                 :            : {
+     366                 :            :     asm ("sha512su1 %0.2D,%1.2D,%2.2D" : "+w" (x) : "w" (y), "w" (z));
+     367                 :            :     return x;
+     368                 :            : }
+     369                 :            : static inline uint64x2_t vsha512hq_u64(uint64x2_t x, uint64x2_t y, uint64x2_t z)
+     370                 :            : {
+     371                 :            :     asm ("sha512h %0,%1,%2.2D" : "+w" (x) : "w" (y), "w" (z));
+     372                 :            :     return x;
+     373                 :            : }
+     374                 :            : static inline uint64x2_t vsha512h2q_u64(uint64x2_t x, uint64x2_t y, uint64x2_t z)
+     375                 :            : {
+     376                 :            :     asm ("sha512h2 %0,%1,%2.2D" : "+w" (x) : "w" (y), "w" (z));
+     377                 :            :     return x;
+     378                 :            : }
+     379                 :            : #endif  /* __clang__ etc */
+     380                 :            : 
+     381                 :            : static size_t mbedtls_internal_sha512_process_many_a64_crypto(
+     382                 :            :     mbedtls_sha512_context *ctx, const uint8_t *msg, size_t len)
+     383                 :            : {
+     384                 :            :     uint64x2_t ab = vld1q_u64(&ctx->state[0]);
+     385                 :            :     uint64x2_t cd = vld1q_u64(&ctx->state[2]);
+     386                 :            :     uint64x2_t ef = vld1q_u64(&ctx->state[4]);
+     387                 :            :     uint64x2_t gh = vld1q_u64(&ctx->state[6]);
+     388                 :            : 
+     389                 :            :     size_t processed = 0;
+     390                 :            : 
+     391                 :            :     for (;
+     392                 :            :          len >= SHA512_BLOCK_SIZE;
+     393                 :            :          processed += SHA512_BLOCK_SIZE,
+     394                 :            :          msg += SHA512_BLOCK_SIZE,
+     395                 :            :          len -= SHA512_BLOCK_SIZE) {
+     396                 :            :         uint64x2_t initial_sum, sum, intermed;
+     397                 :            : 
+     398                 :            :         uint64x2_t ab_orig = ab;
+     399                 :            :         uint64x2_t cd_orig = cd;
+     400                 :            :         uint64x2_t ef_orig = ef;
+     401                 :            :         uint64x2_t gh_orig = gh;
+     402                 :            : 
+     403                 :            :         uint64x2_t s0 = (uint64x2_t) vld1q_u8(msg + 16 * 0);
+     404                 :            :         uint64x2_t s1 = (uint64x2_t) vld1q_u8(msg + 16 * 1);
+     405                 :            :         uint64x2_t s2 = (uint64x2_t) vld1q_u8(msg + 16 * 2);
+     406                 :            :         uint64x2_t s3 = (uint64x2_t) vld1q_u8(msg + 16 * 3);
+     407                 :            :         uint64x2_t s4 = (uint64x2_t) vld1q_u8(msg + 16 * 4);
+     408                 :            :         uint64x2_t s5 = (uint64x2_t) vld1q_u8(msg + 16 * 5);
+     409                 :            :         uint64x2_t s6 = (uint64x2_t) vld1q_u8(msg + 16 * 6);
+     410                 :            :         uint64x2_t s7 = (uint64x2_t) vld1q_u8(msg + 16 * 7);
+     411                 :            : 
+     412                 :            : #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__  /* assume LE if these not defined; untested on BE */
+     413                 :            :         s0 = vreinterpretq_u64_u8(vrev64q_u8(vreinterpretq_u8_u64(s0)));
+     414                 :            :         s1 = vreinterpretq_u64_u8(vrev64q_u8(vreinterpretq_u8_u64(s1)));
+     415                 :            :         s2 = vreinterpretq_u64_u8(vrev64q_u8(vreinterpretq_u8_u64(s2)));
+     416                 :            :         s3 = vreinterpretq_u64_u8(vrev64q_u8(vreinterpretq_u8_u64(s3)));
+     417                 :            :         s4 = vreinterpretq_u64_u8(vrev64q_u8(vreinterpretq_u8_u64(s4)));
+     418                 :            :         s5 = vreinterpretq_u64_u8(vrev64q_u8(vreinterpretq_u8_u64(s5)));
+     419                 :            :         s6 = vreinterpretq_u64_u8(vrev64q_u8(vreinterpretq_u8_u64(s6)));
+     420                 :            :         s7 = vreinterpretq_u64_u8(vrev64q_u8(vreinterpretq_u8_u64(s7)));
+     421                 :            : #endif
+     422                 :            : 
+     423                 :            :         /* Rounds 0 and 1 */
+     424                 :            :         initial_sum = vaddq_u64(s0, vld1q_u64(&K[0]));
+     425                 :            :         sum = vaddq_u64(vextq_u64(initial_sum, initial_sum, 1), gh);
+     426                 :            :         intermed = vsha512hq_u64(sum, vextq_u64(ef, gh, 1), vextq_u64(cd, ef, 1));
+     427                 :            :         gh = vsha512h2q_u64(intermed, cd, ab);
+     428                 :            :         cd = vaddq_u64(cd, intermed);
+     429                 :            : 
+     430                 :            :         /* Rounds 2 and 3 */
+     431                 :            :         initial_sum = vaddq_u64(s1, vld1q_u64(&K[2]));
+     432                 :            :         sum = vaddq_u64(vextq_u64(initial_sum, initial_sum, 1), ef);
+     433                 :            :         intermed = vsha512hq_u64(sum, vextq_u64(cd, ef, 1), vextq_u64(ab, cd, 1));
+     434                 :            :         ef = vsha512h2q_u64(intermed, ab, gh);
+     435                 :            :         ab = vaddq_u64(ab, intermed);
+     436                 :            : 
+     437                 :            :         /* Rounds 4 and 5 */
+     438                 :            :         initial_sum = vaddq_u64(s2, vld1q_u64(&K[4]));
+     439                 :            :         sum = vaddq_u64(vextq_u64(initial_sum, initial_sum, 1), cd);
+     440                 :            :         intermed = vsha512hq_u64(sum, vextq_u64(ab, cd, 1), vextq_u64(gh, ab, 1));
+     441                 :            :         cd = vsha512h2q_u64(intermed, gh, ef);
+     442                 :            :         gh = vaddq_u64(gh, intermed);
+     443                 :            : 
+     444                 :            :         /* Rounds 6 and 7 */
+     445                 :            :         initial_sum = vaddq_u64(s3, vld1q_u64(&K[6]));
+     446                 :            :         sum = vaddq_u64(vextq_u64(initial_sum, initial_sum, 1), ab);
+     447                 :            :         intermed = vsha512hq_u64(sum, vextq_u64(gh, ab, 1), vextq_u64(ef, gh, 1));
+     448                 :            :         ab = vsha512h2q_u64(intermed, ef, cd);
+     449                 :            :         ef = vaddq_u64(ef, intermed);
+     450                 :            : 
+     451                 :            :         /* Rounds 8 and 9 */
+     452                 :            :         initial_sum = vaddq_u64(s4, vld1q_u64(&K[8]));
+     453                 :            :         sum = vaddq_u64(vextq_u64(initial_sum, initial_sum, 1), gh);
+     454                 :            :         intermed = vsha512hq_u64(sum, vextq_u64(ef, gh, 1), vextq_u64(cd, ef, 1));
+     455                 :            :         gh = vsha512h2q_u64(intermed, cd, ab);
+     456                 :            :         cd = vaddq_u64(cd, intermed);
+     457                 :            : 
+     458                 :            :         /* Rounds 10 and 11 */
+     459                 :            :         initial_sum = vaddq_u64(s5, vld1q_u64(&K[10]));
+     460                 :            :         sum = vaddq_u64(vextq_u64(initial_sum, initial_sum, 1), ef);
+     461                 :            :         intermed = vsha512hq_u64(sum, vextq_u64(cd, ef, 1), vextq_u64(ab, cd, 1));
+     462                 :            :         ef = vsha512h2q_u64(intermed, ab, gh);
+     463                 :            :         ab = vaddq_u64(ab, intermed);
+     464                 :            : 
+     465                 :            :         /* Rounds 12 and 13 */
+     466                 :            :         initial_sum = vaddq_u64(s6, vld1q_u64(&K[12]));
+     467                 :            :         sum = vaddq_u64(vextq_u64(initial_sum, initial_sum, 1), cd);
+     468                 :            :         intermed = vsha512hq_u64(sum, vextq_u64(ab, cd, 1), vextq_u64(gh, ab, 1));
+     469                 :            :         cd = vsha512h2q_u64(intermed, gh, ef);
+     470                 :            :         gh = vaddq_u64(gh, intermed);
+     471                 :            : 
+     472                 :            :         /* Rounds 14 and 15 */
+     473                 :            :         initial_sum = vaddq_u64(s7, vld1q_u64(&K[14]));
+     474                 :            :         sum = vaddq_u64(vextq_u64(initial_sum, initial_sum, 1), ab);
+     475                 :            :         intermed = vsha512hq_u64(sum, vextq_u64(gh, ab, 1), vextq_u64(ef, gh, 1));
+     476                 :            :         ab = vsha512h2q_u64(intermed, ef, cd);
+     477                 :            :         ef = vaddq_u64(ef, intermed);
+     478                 :            : 
+     479                 :            :         for (unsigned int t = 16; t < 80; t += 16) {
+     480                 :            :             /* Rounds t and t + 1 */
+     481                 :            :             s0 = vsha512su1q_u64(vsha512su0q_u64(s0, s1), s7, vextq_u64(s4, s5, 1));
+     482                 :            :             initial_sum = vaddq_u64(s0, vld1q_u64(&K[t]));
+     483                 :            :             sum = vaddq_u64(vextq_u64(initial_sum, initial_sum, 1), gh);
+     484                 :            :             intermed = vsha512hq_u64(sum, vextq_u64(ef, gh, 1), vextq_u64(cd, ef, 1));
+     485                 :            :             gh = vsha512h2q_u64(intermed, cd, ab);
+     486                 :            :             cd = vaddq_u64(cd, intermed);
+     487                 :            : 
+     488                 :            :             /* Rounds t + 2 and t + 3 */
+     489                 :            :             s1 = vsha512su1q_u64(vsha512su0q_u64(s1, s2), s0, vextq_u64(s5, s6, 1));
+     490                 :            :             initial_sum = vaddq_u64(s1, vld1q_u64(&K[t + 2]));
+     491                 :            :             sum = vaddq_u64(vextq_u64(initial_sum, initial_sum, 1), ef);
+     492                 :            :             intermed = vsha512hq_u64(sum, vextq_u64(cd, ef, 1), vextq_u64(ab, cd, 1));
+     493                 :            :             ef = vsha512h2q_u64(intermed, ab, gh);
+     494                 :            :             ab = vaddq_u64(ab, intermed);
+     495                 :            : 
+     496                 :            :             /* Rounds t + 4 and t + 5 */
+     497                 :            :             s2 = vsha512su1q_u64(vsha512su0q_u64(s2, s3), s1, vextq_u64(s6, s7, 1));
+     498                 :            :             initial_sum = vaddq_u64(s2, vld1q_u64(&K[t + 4]));
+     499                 :            :             sum = vaddq_u64(vextq_u64(initial_sum, initial_sum, 1), cd);
+     500                 :            :             intermed = vsha512hq_u64(sum, vextq_u64(ab, cd, 1), vextq_u64(gh, ab, 1));
+     501                 :            :             cd = vsha512h2q_u64(intermed, gh, ef);
+     502                 :            :             gh = vaddq_u64(gh, intermed);
+     503                 :            : 
+     504                 :            :             /* Rounds t + 6 and t + 7 */
+     505                 :            :             s3 = vsha512su1q_u64(vsha512su0q_u64(s3, s4), s2, vextq_u64(s7, s0, 1));
+     506                 :            :             initial_sum = vaddq_u64(s3, vld1q_u64(&K[t + 6]));
+     507                 :            :             sum = vaddq_u64(vextq_u64(initial_sum, initial_sum, 1), ab);
+     508                 :            :             intermed = vsha512hq_u64(sum, vextq_u64(gh, ab, 1), vextq_u64(ef, gh, 1));
+     509                 :            :             ab = vsha512h2q_u64(intermed, ef, cd);
+     510                 :            :             ef = vaddq_u64(ef, intermed);
+     511                 :            : 
+     512                 :            :             /* Rounds t + 8 and t + 9 */
+     513                 :            :             s4 = vsha512su1q_u64(vsha512su0q_u64(s4, s5), s3, vextq_u64(s0, s1, 1));
+     514                 :            :             initial_sum = vaddq_u64(s4, vld1q_u64(&K[t + 8]));
+     515                 :            :             sum = vaddq_u64(vextq_u64(initial_sum, initial_sum, 1), gh);
+     516                 :            :             intermed = vsha512hq_u64(sum, vextq_u64(ef, gh, 1), vextq_u64(cd, ef, 1));
+     517                 :            :             gh = vsha512h2q_u64(intermed, cd, ab);
+     518                 :            :             cd = vaddq_u64(cd, intermed);
+     519                 :            : 
+     520                 :            :             /* Rounds t + 10 and t + 11 */
+     521                 :            :             s5 = vsha512su1q_u64(vsha512su0q_u64(s5, s6), s4, vextq_u64(s1, s2, 1));
+     522                 :            :             initial_sum = vaddq_u64(s5, vld1q_u64(&K[t + 10]));
+     523                 :            :             sum = vaddq_u64(vextq_u64(initial_sum, initial_sum, 1), ef);
+     524                 :            :             intermed = vsha512hq_u64(sum, vextq_u64(cd, ef, 1), vextq_u64(ab, cd, 1));
+     525                 :            :             ef = vsha512h2q_u64(intermed, ab, gh);
+     526                 :            :             ab = vaddq_u64(ab, intermed);
+     527                 :            : 
+     528                 :            :             /* Rounds t + 12 and t + 13 */
+     529                 :            :             s6 = vsha512su1q_u64(vsha512su0q_u64(s6, s7), s5, vextq_u64(s2, s3, 1));
+     530                 :            :             initial_sum = vaddq_u64(s6, vld1q_u64(&K[t + 12]));
+     531                 :            :             sum = vaddq_u64(vextq_u64(initial_sum, initial_sum, 1), cd);
+     532                 :            :             intermed = vsha512hq_u64(sum, vextq_u64(ab, cd, 1), vextq_u64(gh, ab, 1));
+     533                 :            :             cd = vsha512h2q_u64(intermed, gh, ef);
+     534                 :            :             gh = vaddq_u64(gh, intermed);
+     535                 :            : 
+     536                 :            :             /* Rounds t + 14 and t + 15 */
+     537                 :            :             s7 = vsha512su1q_u64(vsha512su0q_u64(s7, s0), s6, vextq_u64(s3, s4, 1));
+     538                 :            :             initial_sum = vaddq_u64(s7, vld1q_u64(&K[t + 14]));
+     539                 :            :             sum = vaddq_u64(vextq_u64(initial_sum, initial_sum, 1), ab);
+     540                 :            :             intermed = vsha512hq_u64(sum, vextq_u64(gh, ab, 1), vextq_u64(ef, gh, 1));
+     541                 :            :             ab = vsha512h2q_u64(intermed, ef, cd);
+     542                 :            :             ef = vaddq_u64(ef, intermed);
+     543                 :            :         }
+     544                 :            : 
+     545                 :            :         ab = vaddq_u64(ab, ab_orig);
+     546                 :            :         cd = vaddq_u64(cd, cd_orig);
+     547                 :            :         ef = vaddq_u64(ef, ef_orig);
+     548                 :            :         gh = vaddq_u64(gh, gh_orig);
+     549                 :            :     }
+     550                 :            : 
+     551                 :            :     vst1q_u64(&ctx->state[0], ab);
+     552                 :            :     vst1q_u64(&ctx->state[2], cd);
+     553                 :            :     vst1q_u64(&ctx->state[4], ef);
+     554                 :            :     vst1q_u64(&ctx->state[6], gh);
+     555                 :            : 
+     556                 :            :     return processed;
+     557                 :            : }
+     558                 :            : 
+     559                 :            : #if defined(MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT)
+     560                 :            : /*
+     561                 :            :  * This function is for internal use only if we are building both C and A64
+     562                 :            :  * versions, otherwise it is renamed to be the public mbedtls_internal_sha512_process()
+     563                 :            :  */
+     564                 :            : static
+     565                 :            : #endif
+     566                 :            : int mbedtls_internal_sha512_process_a64_crypto(mbedtls_sha512_context *ctx,
+     567                 :            :                                                const unsigned char data[SHA512_BLOCK_SIZE])
+     568                 :            : {
+     569                 :            :     return (mbedtls_internal_sha512_process_many_a64_crypto(ctx, data,
+     570                 :            :                                                             SHA512_BLOCK_SIZE) ==
+     571                 :            :             SHA512_BLOCK_SIZE) ? 0 : -1;
+     572                 :            : }
+     573                 :            : 
+     574                 :            : #endif /* MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT || MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY */
+     575                 :            : 
+     576                 :            : #if defined(MBEDTLS_POP_TARGET_PRAGMA)
+     577                 :            : #if defined(__clang__)
+     578                 :            : #pragma clang attribute pop
+     579                 :            : #elif defined(__GNUC__)
+     580                 :            : #pragma GCC pop_options
+     581                 :            : #endif
+     582                 :            : #undef MBEDTLS_POP_TARGET_PRAGMA
+     583                 :            : #endif
+     584                 :            : 
+     585                 :            : 
+     586                 :            : #if !defined(MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT)
+     587                 :            : #define mbedtls_internal_sha512_process_many_c mbedtls_internal_sha512_process_many
+     588                 :            : #define mbedtls_internal_sha512_process_c      mbedtls_internal_sha512_process
+     589                 :            : #endif
+     590                 :            : 
+     591                 :            : 
+     592                 :            : #if !defined(MBEDTLS_SHA512_PROCESS_ALT) && !defined(MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY)
+     593                 :            : 
+     594                 :            : #if defined(MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT)
+     595                 :            : /*
+     596                 :            :  * This function is for internal use only if we are building both C and A64
+     597                 :            :  * versions, otherwise it is renamed to be the public mbedtls_internal_sha512_process()
+     598                 :            :  */
+     599                 :            : static
+     600                 :            : #endif
+     601                 :        536 : int mbedtls_internal_sha512_process_c(mbedtls_sha512_context *ctx,
+     602                 :            :                                       const unsigned char data[SHA512_BLOCK_SIZE])
+     603                 :            : {
+     604                 :            :     int i;
+     605                 :            :     struct {
+     606                 :            :         uint64_t temp1, temp2, W[80];
+     607                 :            :         uint64_t A[8];
+     608                 :            :     } local;
+     609                 :            : 
+     610                 :            : #define  SHR(x, n) ((x) >> (n))
+     611                 :            : #define ROTR(x, n) (SHR((x), (n)) | ((x) << (64 - (n))))
+     612                 :            : 
+     613                 :            : #define S0(x) (ROTR(x, 1) ^ ROTR(x, 8) ^  SHR(x, 7))
+     614                 :            : #define S1(x) (ROTR(x, 19) ^ ROTR(x, 61) ^  SHR(x, 6))
+     615                 :            : 
+     616                 :            : #define S2(x) (ROTR(x, 28) ^ ROTR(x, 34) ^ ROTR(x, 39))
+     617                 :            : #define S3(x) (ROTR(x, 14) ^ ROTR(x, 18) ^ ROTR(x, 41))
+     618                 :            : 
+     619                 :            : #define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y))))
+     620                 :            : #define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
+     621                 :            : 
+     622                 :            : #define P(a, b, c, d, e, f, g, h, x, K)                                      \
+     623                 :            :     do                                                              \
+     624                 :            :     {                                                               \
+     625                 :            :         local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
+     626                 :            :         local.temp2 = S2(a) + F0((a), (b), (c));                      \
+     627                 :            :         (d) += local.temp1; (h) = local.temp1 + local.temp2;        \
+     628                 :            :     } while (0)
+     629                 :            : 
+     630         [ +  + ]:       4824 :     for (i = 0; i < 8; i++) {
+     631                 :       4288 :         local.A[i] = ctx->state[i];
+     632                 :            :     }
+     633                 :            : 
+     634                 :            : #if defined(MBEDTLS_SHA512_SMALLER)
+     635                 :            :     for (i = 0; i < 80; i++) {
+     636                 :            :         if (i < 16) {
+     637                 :            :             local.W[i] = MBEDTLS_GET_UINT64_BE(data, i << 3);
+     638                 :            :         } else {
+     639                 :            :             local.W[i] = S1(local.W[i -  2]) + local.W[i -  7] +
+     640                 :            :                          S0(local.W[i - 15]) + local.W[i - 16];
+     641                 :            :         }
+     642                 :            : 
+     643                 :            :         P(local.A[0], local.A[1], local.A[2], local.A[3], local.A[4],
+     644                 :            :           local.A[5], local.A[6], local.A[7], local.W[i], K[i]);
+     645                 :            : 
+     646                 :            :         local.temp1 = local.A[7]; local.A[7] = local.A[6];
+     647                 :            :         local.A[6] = local.A[5]; local.A[5] = local.A[4];
+     648                 :            :         local.A[4] = local.A[3]; local.A[3] = local.A[2];
+     649                 :            :         local.A[2] = local.A[1]; local.A[1] = local.A[0];
+     650                 :            :         local.A[0] = local.temp1;
+     651                 :            :     }
+     652                 :            : #else /* MBEDTLS_SHA512_SMALLER */
+     653         [ +  + ]:       9112 :     for (i = 0; i < 16; i++) {
+     654                 :      17152 :         local.W[i] = MBEDTLS_GET_UINT64_BE(data, i << 3);
+     655                 :            :     }
+     656                 :            : 
+     657         [ +  + ]:      34840 :     for (; i < 80; i++) {
+     658                 :      34304 :         local.W[i] = S1(local.W[i -  2]) + local.W[i -  7] +
+     659                 :      34304 :                      S0(local.W[i - 15]) + local.W[i - 16];
+     660                 :            :     }
+     661                 :            : 
+     662                 :        536 :     i = 0;
+     663                 :            :     do {
+     664                 :       5360 :         P(local.A[0], local.A[1], local.A[2], local.A[3], local.A[4],
+     665                 :       5360 :           local.A[5], local.A[6], local.A[7], local.W[i], K[i]); i++;
+     666                 :       5360 :         P(local.A[7], local.A[0], local.A[1], local.A[2], local.A[3],
+     667                 :       5360 :           local.A[4], local.A[5], local.A[6], local.W[i], K[i]); i++;
+     668                 :       5360 :         P(local.A[6], local.A[7], local.A[0], local.A[1], local.A[2],
+     669                 :       5360 :           local.A[3], local.A[4], local.A[5], local.W[i], K[i]); i++;
+     670                 :       5360 :         P(local.A[5], local.A[6], local.A[7], local.A[0], local.A[1],
+     671                 :       5360 :           local.A[2], local.A[3], local.A[4], local.W[i], K[i]); i++;
+     672                 :       5360 :         P(local.A[4], local.A[5], local.A[6], local.A[7], local.A[0],
+     673                 :       5360 :           local.A[1], local.A[2], local.A[3], local.W[i], K[i]); i++;
+     674                 :       5360 :         P(local.A[3], local.A[4], local.A[5], local.A[6], local.A[7],
+     675                 :       5360 :           local.A[0], local.A[1], local.A[2], local.W[i], K[i]); i++;
+     676                 :       5360 :         P(local.A[2], local.A[3], local.A[4], local.A[5], local.A[6],
+     677                 :       5360 :           local.A[7], local.A[0], local.A[1], local.W[i], K[i]); i++;
+     678                 :       5360 :         P(local.A[1], local.A[2], local.A[3], local.A[4], local.A[5],
+     679                 :       5360 :           local.A[6], local.A[7], local.A[0], local.W[i], K[i]); i++;
+     680         [ +  + ]:       5360 :     } while (i < 80);
+     681                 :            : #endif /* MBEDTLS_SHA512_SMALLER */
+     682                 :            : 
+     683         [ +  + ]:       4824 :     for (i = 0; i < 8; i++) {
+     684                 :       4288 :         ctx->state[i] += local.A[i];
+     685                 :            :     }
+     686                 :            : 
+     687                 :            :     /* Zeroise buffers and variables to clear sensitive data from memory. */
+     688                 :        536 :     mbedtls_platform_zeroize(&local, sizeof(local));
+     689                 :            : 
+     690                 :        536 :     return 0;
+     691                 :            : }
+     692                 :            : 
+     693                 :            : #endif /* !MBEDTLS_SHA512_PROCESS_ALT && !MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY */
+     694                 :            : 
+     695                 :            : 
+     696                 :            : #if !defined(MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY)
+     697                 :            : 
+     698                 :         49 : static size_t mbedtls_internal_sha512_process_many_c(
+     699                 :            :     mbedtls_sha512_context *ctx, const uint8_t *data, size_t len)
+     700                 :            : {
+     701                 :         49 :     size_t processed = 0;
+     702                 :            : 
+     703         [ +  + ]:        322 :     while (len >= SHA512_BLOCK_SIZE) {
+     704         [ -  + ]:        273 :         if (mbedtls_internal_sha512_process_c(ctx, data) != 0) {
+     705                 :          0 :             return 0;
+     706                 :            :         }
+     707                 :            : 
+     708                 :        273 :         data += SHA512_BLOCK_SIZE;
+     709                 :        273 :         len  -= SHA512_BLOCK_SIZE;
+     710                 :            : 
+     711                 :        273 :         processed += SHA512_BLOCK_SIZE;
+     712                 :            :     }
+     713                 :            : 
+     714                 :         49 :     return processed;
+     715                 :            : }
+     716                 :            : 
+     717                 :            : #endif /* !MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY */
+     718                 :            : 
+     719                 :            : 
+     720                 :            : #if defined(MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT)
+     721                 :            : 
+     722                 :            : static int mbedtls_a64_crypto_sha512_has_support(void)
+     723                 :            : {
+     724                 :            :     static int done = 0;
+     725                 :            :     static int supported = 0;
+     726                 :            : 
+     727                 :            :     if (!done) {
+     728                 :            :         supported = mbedtls_a64_crypto_sha512_determine_support();
+     729                 :            :         done = 1;
+     730                 :            :     }
+     731                 :            : 
+     732                 :            :     return supported;
+     733                 :            : }
+     734                 :            : 
+     735                 :            : static size_t mbedtls_internal_sha512_process_many(mbedtls_sha512_context *ctx,
+     736                 :            :                                                    const uint8_t *msg, size_t len)
+     737                 :            : {
+     738                 :            :     if (mbedtls_a64_crypto_sha512_has_support()) {
+     739                 :            :         return mbedtls_internal_sha512_process_many_a64_crypto(ctx, msg, len);
+     740                 :            :     } else {
+     741                 :            :         return mbedtls_internal_sha512_process_many_c(ctx, msg, len);
+     742                 :            :     }
+     743                 :            : }
+     744                 :            : 
+     745                 :            : int mbedtls_internal_sha512_process(mbedtls_sha512_context *ctx,
+     746                 :            :                                     const unsigned char data[SHA512_BLOCK_SIZE])
+     747                 :            : {
+     748                 :            :     if (mbedtls_a64_crypto_sha512_has_support()) {
+     749                 :            :         return mbedtls_internal_sha512_process_a64_crypto(ctx, data);
+     750                 :            :     } else {
+     751                 :            :         return mbedtls_internal_sha512_process_c(ctx, data);
+     752                 :            :     }
+     753                 :            : }
+     754                 :            : 
+     755                 :            : #endif /* MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT */
+     756                 :            : 
+     757                 :            : /*
+     758                 :            :  * SHA-512 process buffer
+     759                 :            :  */
+     760                 :        267 : int mbedtls_sha512_update(mbedtls_sha512_context *ctx,
+     761                 :            :                           const unsigned char *input,
+     762                 :            :                           size_t ilen)
+     763                 :            : {
+     764                 :        267 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     765                 :            :     size_t fill;
+     766                 :            :     unsigned int left;
+     767                 :            : 
+     768         [ -  + ]:        267 :     if (ilen == 0) {
+     769                 :          0 :         return 0;
+     770                 :            :     }
+     771                 :            : 
+     772                 :        267 :     left = (unsigned int) (ctx->total[0] & 0x7F);
+     773                 :        267 :     fill = SHA512_BLOCK_SIZE - left;
+     774                 :            : 
+     775                 :        267 :     ctx->total[0] += (uint64_t) ilen;
+     776                 :            : 
+     777         [ -  + ]:        267 :     if (ctx->total[0] < (uint64_t) ilen) {
+     778                 :          0 :         ctx->total[1]++;
+     779                 :            :     }
+     780                 :            : 
+     781   [ -  +  -  - ]:        267 :     if (left && ilen >= fill) {
+     782                 :          0 :         memcpy((void *) (ctx->buffer + left), input, fill);
+     783                 :            : 
+     784         [ #  # ]:          0 :         if ((ret = mbedtls_internal_sha512_process(ctx, ctx->buffer)) != 0) {
+     785                 :          0 :             return ret;
+     786                 :            :         }
+     787                 :            : 
+     788                 :          0 :         input += fill;
+     789                 :          0 :         ilen  -= fill;
+     790                 :          0 :         left = 0;
+     791                 :            :     }
+     792                 :            : 
+     793         [ +  + ]:        316 :     while (ilen >= SHA512_BLOCK_SIZE) {
+     794                 :            :         size_t processed =
+     795                 :         49 :             mbedtls_internal_sha512_process_many(ctx, input, ilen);
+     796         [ -  + ]:         49 :         if (processed < SHA512_BLOCK_SIZE) {
+     797                 :          0 :             return MBEDTLS_ERR_ERROR_GENERIC_ERROR;
+     798                 :            :         }
+     799                 :            : 
+     800                 :         49 :         input += processed;
+     801                 :         49 :         ilen  -= processed;
+     802                 :            :     }
+     803                 :            : 
+     804         [ +  + ]:        267 :     if (ilen > 0) {
+     805                 :        263 :         memcpy((void *) (ctx->buffer + left), input, ilen);
+     806                 :            :     }
+     807                 :            : 
+     808                 :        267 :     return 0;
+     809                 :            : }
+     810                 :            : 
+     811                 :            : /*
+     812                 :            :  * SHA-512 final digest
+     813                 :            :  */
+     814                 :        263 : int mbedtls_sha512_finish(mbedtls_sha512_context *ctx,
+     815                 :            :                           unsigned char *output)
+     816                 :            : {
+     817                 :        263 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     818                 :            :     unsigned used;
+     819                 :            :     uint64_t high, low;
+     820                 :        263 :     int truncated = 0;
+     821                 :            : 
+     822                 :            :     /*
+     823                 :            :      * Add padding: 0x80 then 0x00 until 16 bytes remain for the length
+     824                 :            :      */
+     825                 :        263 :     used = ctx->total[0] & 0x7F;
+     826                 :            : 
+     827                 :        263 :     ctx->buffer[used++] = 0x80;
+     828                 :            : 
+     829         [ +  - ]:        263 :     if (used <= 112) {
+     830                 :            :         /* Enough room for padding + length in current block */
+     831                 :        263 :         memset(ctx->buffer + used, 0, 112 - used);
+     832                 :            :     } else {
+     833                 :            :         /* We'll need an extra block */
+     834                 :          0 :         memset(ctx->buffer + used, 0, SHA512_BLOCK_SIZE - used);
+     835                 :            : 
+     836         [ #  # ]:          0 :         if ((ret = mbedtls_internal_sha512_process(ctx, ctx->buffer)) != 0) {
+     837                 :          0 :             goto exit;
+     838                 :            :         }
+     839                 :            : 
+     840                 :          0 :         memset(ctx->buffer, 0, 112);
+     841                 :            :     }
+     842                 :            : 
+     843                 :            :     /*
+     844                 :            :      * Add message length
+     845                 :            :      */
+     846                 :        263 :     high = (ctx->total[0] >> 61)
+     847                 :        263 :            | (ctx->total[1] <<  3);
+     848                 :        263 :     low  = (ctx->total[0] <<  3);
+     849                 :            : 
+     850                 :        263 :     sha512_put_uint64_be(high, ctx->buffer, 112);
+     851                 :        263 :     sha512_put_uint64_be(low,  ctx->buffer, 120);
+     852                 :            : 
+     853         [ -  + ]:        263 :     if ((ret = mbedtls_internal_sha512_process(ctx, ctx->buffer)) != 0) {
+     854                 :          0 :         goto exit;
+     855                 :            :     }
+     856                 :            : 
+     857                 :            :     /*
+     858                 :            :      * Output final state
+     859                 :            :      */
+     860                 :        263 :     sha512_put_uint64_be(ctx->state[0], output,  0);
+     861                 :        263 :     sha512_put_uint64_be(ctx->state[1], output,  8);
+     862                 :        263 :     sha512_put_uint64_be(ctx->state[2], output, 16);
+     863                 :        263 :     sha512_put_uint64_be(ctx->state[3], output, 24);
+     864                 :        263 :     sha512_put_uint64_be(ctx->state[4], output, 32);
+     865                 :        263 :     sha512_put_uint64_be(ctx->state[5], output, 40);
+     866                 :            : 
+     867                 :            : #if defined(MBEDTLS_SHA384_C)
+     868                 :        263 :     truncated = ctx->is384;
+     869                 :            : #endif
+     870         [ +  + ]:        263 :     if (!truncated) {
+     871                 :         46 :         sha512_put_uint64_be(ctx->state[6], output, 48);
+     872                 :         46 :         sha512_put_uint64_be(ctx->state[7], output, 56);
+     873                 :            :     }
+     874                 :            : 
+     875                 :        263 :     ret = 0;
+     876                 :            : 
+     877                 :        263 : exit:
+     878                 :        263 :     mbedtls_sha512_free(ctx);
+     879                 :        263 :     return ret;
+     880                 :            : }
+     881                 :            : 
+     882                 :            : #endif /* !MBEDTLS_SHA512_ALT */
+     883                 :            : 
+     884                 :            : /*
+     885                 :            :  * output = SHA-512( input buffer )
+     886                 :            :  */
+     887                 :        259 : int mbedtls_sha512(const unsigned char *input,
+     888                 :            :                    size_t ilen,
+     889                 :            :                    unsigned char *output,
+     890                 :            :                    int is384)
+     891                 :            : {
+     892                 :        259 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     893                 :            :     mbedtls_sha512_context ctx;
+     894                 :            : 
+     895                 :            : #if defined(MBEDTLS_SHA384_C) && defined(MBEDTLS_SHA512_C)
+     896   [ +  +  -  + ]:        259 :     if (is384 != 0 && is384 != 1) {
+     897                 :          0 :         return MBEDTLS_ERR_SHA512_BAD_INPUT_DATA;
+     898                 :            :     }
+     899                 :            : #elif defined(MBEDTLS_SHA512_C)
+     900                 :            :     if (is384 != 0) {
+     901                 :            :         return MBEDTLS_ERR_SHA512_BAD_INPUT_DATA;
+     902                 :            :     }
+     903                 :            : #else /* defined MBEDTLS_SHA384_C only */
+     904                 :            :     if (is384 == 0) {
+     905                 :            :         return MBEDTLS_ERR_SHA512_BAD_INPUT_DATA;
+     906                 :            :     }
+     907                 :            : #endif
+     908                 :            : 
+     909                 :        259 :     mbedtls_sha512_init(&ctx);
+     910                 :            : 
+     911         [ -  + ]:        259 :     if ((ret = mbedtls_sha512_starts(&ctx, is384)) != 0) {
+     912                 :          0 :         goto exit;
+     913                 :            :     }
+     914                 :            : 
+     915         [ -  + ]:        259 :     if ((ret = mbedtls_sha512_update(&ctx, input, ilen)) != 0) {
+     916                 :          0 :         goto exit;
+     917                 :            :     }
+     918                 :            : 
+     919         [ +  - ]:        259 :     if ((ret = mbedtls_sha512_finish(&ctx, output)) != 0) {
+     920                 :          0 :         goto exit;
+     921                 :            :     }
+     922                 :            : 
+     923                 :        259 : exit:
+     924                 :        259 :     mbedtls_sha512_free(&ctx);
+     925                 :            : 
+     926                 :        259 :     return ret;
+     927                 :            : }
+     928                 :            : 
+     929                 :            : #if defined(MBEDTLS_SELF_TEST)
+     930                 :            : 
+     931                 :            : /*
+     932                 :            :  * FIPS-180-2 test vectors
+     933                 :            :  */
+     934                 :            : static const unsigned char sha_test_buf[3][113] =
+     935                 :            : {
+     936                 :            :     { "abc" },
+     937                 :            :     {
+     938                 :            :         "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
+     939                 :            :     },
+     940                 :            :     { "" }
+     941                 :            : };
+     942                 :            : 
+     943                 :            : static const size_t sha_test_buflen[3] =
+     944                 :            : {
+     945                 :            :     3, 112, 1000
+     946                 :            : };
+     947                 :            : 
+     948                 :            : typedef const unsigned char (sha_test_sum_t)[64];
+     949                 :            : 
+     950                 :            : /*
+     951                 :            :  * SHA-384 test vectors
+     952                 :            :  */
+     953                 :            : #if defined(MBEDTLS_SHA384_C)
+     954                 :            : static sha_test_sum_t sha384_test_sum[] =
+     955                 :            : {
+     956                 :            :     { 0xCB, 0x00, 0x75, 0x3F, 0x45, 0xA3, 0x5E, 0x8B,
+     957                 :            :       0xB5, 0xA0, 0x3D, 0x69, 0x9A, 0xC6, 0x50, 0x07,
+     958                 :            :       0x27, 0x2C, 0x32, 0xAB, 0x0E, 0xDE, 0xD1, 0x63,
+     959                 :            :       0x1A, 0x8B, 0x60, 0x5A, 0x43, 0xFF, 0x5B, 0xED,
+     960                 :            :       0x80, 0x86, 0x07, 0x2B, 0xA1, 0xE7, 0xCC, 0x23,
+     961                 :            :       0x58, 0xBA, 0xEC, 0xA1, 0x34, 0xC8, 0x25, 0xA7 },
+     962                 :            :     { 0x09, 0x33, 0x0C, 0x33, 0xF7, 0x11, 0x47, 0xE8,
+     963                 :            :       0x3D, 0x19, 0x2F, 0xC7, 0x82, 0xCD, 0x1B, 0x47,
+     964                 :            :       0x53, 0x11, 0x1B, 0x17, 0x3B, 0x3B, 0x05, 0xD2,
+     965                 :            :       0x2F, 0xA0, 0x80, 0x86, 0xE3, 0xB0, 0xF7, 0x12,
+     966                 :            :       0xFC, 0xC7, 0xC7, 0x1A, 0x55, 0x7E, 0x2D, 0xB9,
+     967                 :            :       0x66, 0xC3, 0xE9, 0xFA, 0x91, 0x74, 0x60, 0x39 },
+     968                 :            :     { 0x9D, 0x0E, 0x18, 0x09, 0x71, 0x64, 0x74, 0xCB,
+     969                 :            :       0x08, 0x6E, 0x83, 0x4E, 0x31, 0x0A, 0x4A, 0x1C,
+     970                 :            :       0xED, 0x14, 0x9E, 0x9C, 0x00, 0xF2, 0x48, 0x52,
+     971                 :            :       0x79, 0x72, 0xCE, 0xC5, 0x70, 0x4C, 0x2A, 0x5B,
+     972                 :            :       0x07, 0xB8, 0xB3, 0xDC, 0x38, 0xEC, 0xC4, 0xEB,
+     973                 :            :       0xAE, 0x97, 0xDD, 0xD8, 0x7F, 0x3D, 0x89, 0x85 }
+     974                 :            : };
+     975                 :            : #endif /* MBEDTLS_SHA384_C */
+     976                 :            : 
+     977                 :            : /*
+     978                 :            :  * SHA-512 test vectors
+     979                 :            :  */
+     980                 :            : #if defined(MBEDTLS_SHA512_C)
+     981                 :            : static sha_test_sum_t sha512_test_sum[] =
+     982                 :            : {
+     983                 :            :     { 0xDD, 0xAF, 0x35, 0xA1, 0x93, 0x61, 0x7A, 0xBA,
+     984                 :            :       0xCC, 0x41, 0x73, 0x49, 0xAE, 0x20, 0x41, 0x31,
+     985                 :            :       0x12, 0xE6, 0xFA, 0x4E, 0x89, 0xA9, 0x7E, 0xA2,
+     986                 :            :       0x0A, 0x9E, 0xEE, 0xE6, 0x4B, 0x55, 0xD3, 0x9A,
+     987                 :            :       0x21, 0x92, 0x99, 0x2A, 0x27, 0x4F, 0xC1, 0xA8,
+     988                 :            :       0x36, 0xBA, 0x3C, 0x23, 0xA3, 0xFE, 0xEB, 0xBD,
+     989                 :            :       0x45, 0x4D, 0x44, 0x23, 0x64, 0x3C, 0xE8, 0x0E,
+     990                 :            :       0x2A, 0x9A, 0xC9, 0x4F, 0xA5, 0x4C, 0xA4, 0x9F },
+     991                 :            :     { 0x8E, 0x95, 0x9B, 0x75, 0xDA, 0xE3, 0x13, 0xDA,
+     992                 :            :       0x8C, 0xF4, 0xF7, 0x28, 0x14, 0xFC, 0x14, 0x3F,
+     993                 :            :       0x8F, 0x77, 0x79, 0xC6, 0xEB, 0x9F, 0x7F, 0xA1,
+     994                 :            :       0x72, 0x99, 0xAE, 0xAD, 0xB6, 0x88, 0x90, 0x18,
+     995                 :            :       0x50, 0x1D, 0x28, 0x9E, 0x49, 0x00, 0xF7, 0xE4,
+     996                 :            :       0x33, 0x1B, 0x99, 0xDE, 0xC4, 0xB5, 0x43, 0x3A,
+     997                 :            :       0xC7, 0xD3, 0x29, 0xEE, 0xB6, 0xDD, 0x26, 0x54,
+     998                 :            :       0x5E, 0x96, 0xE5, 0x5B, 0x87, 0x4B, 0xE9, 0x09 },
+     999                 :            :     { 0xE7, 0x18, 0x48, 0x3D, 0x0C, 0xE7, 0x69, 0x64,
+    1000                 :            :       0x4E, 0x2E, 0x42, 0xC7, 0xBC, 0x15, 0xB4, 0x63,
+    1001                 :            :       0x8E, 0x1F, 0x98, 0xB1, 0x3B, 0x20, 0x44, 0x28,
+    1002                 :            :       0x56, 0x32, 0xA8, 0x03, 0xAF, 0xA9, 0x73, 0xEB,
+    1003                 :            :       0xDE, 0x0F, 0xF2, 0x44, 0x87, 0x7E, 0xA6, 0x0A,
+    1004                 :            :       0x4C, 0xB0, 0x43, 0x2C, 0xE5, 0x77, 0xC3, 0x1B,
+    1005                 :            :       0xEB, 0x00, 0x9C, 0x5C, 0x2C, 0x49, 0xAA, 0x2E,
+    1006                 :            :       0x4E, 0xAD, 0xB2, 0x17, 0xAD, 0x8C, 0xC0, 0x9B }
+    1007                 :            : };
+    1008                 :            : #endif /* MBEDTLS_SHA512_C */
+    1009                 :            : 
+    1010                 :          0 : static int mbedtls_sha512_common_self_test(int verbose, int is384)
+    1011                 :            : {
+    1012                 :          0 :     int i, buflen, ret = 0;
+    1013                 :            :     unsigned char *buf;
+    1014                 :            :     unsigned char sha512sum[64];
+    1015                 :            :     mbedtls_sha512_context ctx;
+    1016                 :            : 
+    1017                 :            : #if defined(MBEDTLS_SHA384_C) && defined(MBEDTLS_SHA512_C)
+    1018         [ #  # ]:          0 :     sha_test_sum_t *sha_test_sum = (is384) ? sha384_test_sum : sha512_test_sum;
+    1019                 :            : #elif defined(MBEDTLS_SHA512_C)
+    1020                 :            :     sha_test_sum_t *sha_test_sum = sha512_test_sum;
+    1021                 :            : #else
+    1022                 :            :     sha_test_sum_t *sha_test_sum = sha384_test_sum;
+    1023                 :            : #endif
+    1024                 :            : 
+    1025                 :          0 :     buf = mbedtls_calloc(1024, sizeof(unsigned char));
+    1026         [ #  # ]:          0 :     if (NULL == buf) {
+    1027         [ #  # ]:          0 :         if (verbose != 0) {
+    1028                 :          0 :             mbedtls_printf("Buffer allocation failed\n");
+    1029                 :            :         }
+    1030                 :            : 
+    1031                 :          0 :         return 1;
+    1032                 :            :     }
+    1033                 :            : 
+    1034                 :          0 :     mbedtls_sha512_init(&ctx);
+    1035                 :            : 
+    1036         [ #  # ]:          0 :     for (i = 0; i < 3; i++) {
+    1037         [ #  # ]:          0 :         if (verbose != 0) {
+    1038                 :          0 :             mbedtls_printf("  SHA-%d test #%d: ", 512 - is384 * 128, i + 1);
+    1039                 :            :         }
+    1040                 :            : 
+    1041         [ #  # ]:          0 :         if ((ret = mbedtls_sha512_starts(&ctx, is384)) != 0) {
+    1042                 :          0 :             goto fail;
+    1043                 :            :         }
+    1044                 :            : 
+    1045         [ #  # ]:          0 :         if (i == 2) {
+    1046                 :          0 :             memset(buf, 'a', buflen = 1000);
+    1047                 :            : 
+    1048         [ #  # ]:          0 :             for (int j = 0; j < 1000; j++) {
+    1049                 :          0 :                 ret = mbedtls_sha512_update(&ctx, buf, buflen);
+    1050         [ #  # ]:          0 :                 if (ret != 0) {
+    1051                 :          0 :                     goto fail;
+    1052                 :            :                 }
+    1053                 :            :             }
+    1054                 :            :         } else {
+    1055                 :          0 :             ret = mbedtls_sha512_update(&ctx, sha_test_buf[i],
+    1056                 :          0 :                                         sha_test_buflen[i]);
+    1057         [ #  # ]:          0 :             if (ret != 0) {
+    1058                 :          0 :                 goto fail;
+    1059                 :            :             }
+    1060                 :            :         }
+    1061                 :            : 
+    1062         [ #  # ]:          0 :         if ((ret = mbedtls_sha512_finish(&ctx, sha512sum)) != 0) {
+    1063                 :          0 :             goto fail;
+    1064                 :            :         }
+    1065                 :            : 
+    1066         [ #  # ]:          0 :         if (memcmp(sha512sum, sha_test_sum[i], 64 - is384 * 16) != 0) {
+    1067                 :          0 :             ret = 1;
+    1068                 :          0 :             goto fail;
+    1069                 :            :         }
+    1070                 :            : 
+    1071         [ #  # ]:          0 :         if (verbose != 0) {
+    1072                 :          0 :             mbedtls_printf("passed\n");
+    1073                 :            :         }
+    1074                 :            :     }
+    1075                 :            : 
+    1076         [ #  # ]:          0 :     if (verbose != 0) {
+    1077                 :          0 :         mbedtls_printf("\n");
+    1078                 :            :     }
+    1079                 :            : 
+    1080                 :          0 :     goto exit;
+    1081                 :            : 
+    1082                 :          0 : fail:
+    1083         [ #  # ]:          0 :     if (verbose != 0) {
+    1084                 :          0 :         mbedtls_printf("failed\n");
+    1085                 :            :     }
+    1086                 :            : 
+    1087                 :          0 : exit:
+    1088                 :          0 :     mbedtls_sha512_free(&ctx);
+    1089                 :          0 :     mbedtls_free(buf);
+    1090                 :            : 
+    1091                 :          0 :     return ret;
+    1092                 :            : }
+    1093                 :            : 
+    1094                 :            : #if defined(MBEDTLS_SHA512_C)
+    1095                 :          0 : int mbedtls_sha512_self_test(int verbose)
+    1096                 :            : {
+    1097                 :          0 :     return mbedtls_sha512_common_self_test(verbose, 0);
+    1098                 :            : }
+    1099                 :            : #endif /* MBEDTLS_SHA512_C */
+    1100                 :            : 
+    1101                 :            : #if defined(MBEDTLS_SHA384_C)
+    1102                 :          0 : int mbedtls_sha384_self_test(int verbose)
+    1103                 :            : {
+    1104                 :          0 :     return mbedtls_sha512_common_self_test(verbose, 1);
+    1105                 :            : }
+    1106                 :            : #endif /* MBEDTLS_SHA384_C */
+    1107                 :            : 
+    1108                 :            : #undef ARRAY_LENGTH
+    1109                 :            : 
+    1110                 :            : #endif /* MBEDTLS_SELF_TEST */
+    1111                 :            : 
+    1112                 :            : #endif /* MBEDTLS_SHA512_C || MBEDTLS_SHA384_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509.c.func-sort-c.html new file mode 100644 index 00000000000..a4fd8201384 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509.c.func-sort-c.html @@ -0,0 +1,221 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/x509.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - x509.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:19873427.0 %
Date:2024-09-22 08:21:07Functions:193554.3 %
Branches:8161413.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_x509_dn_gets0
mbedtls_x509_get_alg_null0
mbedtls_x509_get_ns_cert_type0
mbedtls_x509_get_rsassa_pss_params0
mbedtls_x509_info_cert_type0
mbedtls_x509_info_key_usage0
mbedtls_x509_info_subject_alt_name0
mbedtls_x509_key_size_helper0
mbedtls_x509_serial_gets0
mbedtls_x509_sig_alg_gets0
mbedtls_x509_time_is_future0
mbedtls_x509_time_is_past0
md_type_to_string0
nibble_to_hex_digit0
x509_get_current_time0
x509_get_hash_alg0
mbedtls_x509_time_gmtime2255
x509_get_other_name8113
mbedtls_x509_get_subject_alt_name8153
mbedtls_x509_get_subject_alt_name_ext8153
mbedtls_x509_free_subject_alt_name9653
mbedtls_x509_parse_subject_alt_name9653
mbedtls_x509_get_key_usage9975
mbedtls_x509_time_cmp10853
mbedtls_x509_get_ext12125
mbedtls_x509_get_serial12125
mbedtls_x509_get_sig12125
mbedtls_x509_get_sig_alg12125
mbedtls_x509_get_alg24250
mbedtls_x509_get_name24250
mbedtls_x509_get_time24250
x509_date_is_valid24250
x509_parse_time24250
x509_get_attr_type_value24370
x509_parse2_int145500
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509.c.func.html new file mode 100644 index 00000000000..ae8870a3c04 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509.c.func.html @@ -0,0 +1,221 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/x509.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - x509.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:19873427.0 %
Date:2024-09-22 08:21:07Functions:193554.3 %
Branches:8161413.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_x509_dn_gets0
mbedtls_x509_free_subject_alt_name9653
mbedtls_x509_get_alg24250
mbedtls_x509_get_alg_null0
mbedtls_x509_get_ext12125
mbedtls_x509_get_key_usage9975
mbedtls_x509_get_name24250
mbedtls_x509_get_ns_cert_type0
mbedtls_x509_get_rsassa_pss_params0
mbedtls_x509_get_serial12125
mbedtls_x509_get_sig12125
mbedtls_x509_get_sig_alg12125
mbedtls_x509_get_subject_alt_name8153
mbedtls_x509_get_subject_alt_name_ext8153
mbedtls_x509_get_time24250
mbedtls_x509_info_cert_type0
mbedtls_x509_info_key_usage0
mbedtls_x509_info_subject_alt_name0
mbedtls_x509_key_size_helper0
mbedtls_x509_parse_subject_alt_name9653
mbedtls_x509_serial_gets0
mbedtls_x509_sig_alg_gets0
mbedtls_x509_time_cmp10853
mbedtls_x509_time_gmtime2255
mbedtls_x509_time_is_future0
mbedtls_x509_time_is_past0
md_type_to_string0
nibble_to_hex_digit0
x509_date_is_valid24250
x509_get_attr_type_value24370
x509_get_current_time0
x509_get_hash_alg0
x509_get_other_name8113
x509_parse2_int145500
x509_parse_time24250
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509.c.gcov.html new file mode 100644 index 00000000000..6724e84749f --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509.c.gcov.html @@ -0,0 +1,1886 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/x509.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - x509.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:19873427.0 %
Date:2024-09-22 08:21:07Functions:193554.3 %
Branches:8161413.2 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  *  X.509 common functions for parsing and verification
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  */
+       7                 :            : /*
+       8                 :            :  *  The ITU-T X.509 standard defines a certificate format for PKI.
+       9                 :            :  *
+      10                 :            :  *  http://www.ietf.org/rfc/rfc5280.txt (Certificates and CRLs)
+      11                 :            :  *  http://www.ietf.org/rfc/rfc3279.txt (Alg IDs for CRLs)
+      12                 :            :  *  http://www.ietf.org/rfc/rfc2986.txt (CSRs, aka PKCS#10)
+      13                 :            :  *
+      14                 :            :  *  http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf
+      15                 :            :  *  http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf
+      16                 :            :  */
+      17                 :            : 
+      18                 :            : #include "common.h"
+      19                 :            : 
+      20                 :            : #if defined(MBEDTLS_X509_USE_C)
+      21                 :            : 
+      22                 :            : #include "x509_internal.h"
+      23                 :            : #include "mbedtls/asn1.h"
+      24                 :            : #include "mbedtls/error.h"
+      25                 :            : #include "mbedtls/oid.h"
+      26                 :            : 
+      27                 :            : #include <stdio.h>
+      28                 :            : #include <string.h>
+      29                 :            : 
+      30                 :            : #if defined(MBEDTLS_PEM_PARSE_C)
+      31                 :            : #include "mbedtls/pem.h"
+      32                 :            : #endif
+      33                 :            : 
+      34                 :            : #include "mbedtls/asn1write.h"
+      35                 :            : 
+      36                 :            : #include "mbedtls/platform.h"
+      37                 :            : 
+      38                 :            : #if defined(MBEDTLS_HAVE_TIME)
+      39                 :            : #include "mbedtls/platform_time.h"
+      40                 :            : #endif
+      41                 :            : #if defined(MBEDTLS_HAVE_TIME_DATE)
+      42                 :            : #include "mbedtls/platform_util.h"
+      43                 :            : #include <time.h>
+      44                 :            : #endif
+      45                 :            : 
+      46                 :            : #define CHECK(code)                                     \
+      47                 :            :     do {                                                \
+      48                 :            :         if ((ret = (code)) != 0) {                      \
+      49                 :            :             return ret;                                 \
+      50                 :            :         }                                               \
+      51                 :            :     } while (0)
+      52                 :            : 
+      53                 :            : #define CHECK_RANGE(min, max, val)                      \
+      54                 :            :     do {                                                \
+      55                 :            :         if ((val) < (min) || (val) > (max)) {           \
+      56                 :            :             return ret;                                 \
+      57                 :            :         }                                               \
+      58                 :            :     } while (0)
+      59                 :            : 
+      60                 :            : /*
+      61                 :            :  *  CertificateSerialNumber  ::=  INTEGER
+      62                 :            :  */
+      63                 :      12125 : int mbedtls_x509_get_serial(unsigned char **p, const unsigned char *end,
+      64                 :            :                             mbedtls_x509_buf *serial)
+      65                 :            : {
+      66                 :      12125 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+      67                 :            : 
+      68         [ -  + ]:      12125 :     if ((end - *p) < 1) {
+      69                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_SERIAL,
+      70                 :            :                                  MBEDTLS_ERR_ASN1_OUT_OF_DATA);
+      71                 :            :     }
+      72                 :            : 
+      73         [ +  - ]:      12125 :     if (**p != (MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_PRIMITIVE | 2) &&
+      74         [ -  + ]:      12125 :         **p !=   MBEDTLS_ASN1_INTEGER) {
+      75                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_SERIAL,
+      76                 :            :                                  MBEDTLS_ERR_ASN1_UNEXPECTED_TAG);
+      77                 :            :     }
+      78                 :            : 
+      79                 :      12125 :     serial->tag = *(*p)++;
+      80                 :            : 
+      81         [ -  + ]:      12125 :     if ((ret = mbedtls_asn1_get_len(p, end, &serial->len)) != 0) {
+      82                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_SERIAL, ret);
+      83                 :            :     }
+      84                 :            : 
+      85                 :      12125 :     serial->p = *p;
+      86                 :      12125 :     *p += serial->len;
+      87                 :            : 
+      88                 :      12125 :     return 0;
+      89                 :            : }
+      90                 :            : 
+      91                 :            : /* Get an algorithm identifier without parameters (eg for signatures)
+      92                 :            :  *
+      93                 :            :  *  AlgorithmIdentifier  ::=  SEQUENCE  {
+      94                 :            :  *       algorithm               OBJECT IDENTIFIER,
+      95                 :            :  *       parameters              ANY DEFINED BY algorithm OPTIONAL  }
+      96                 :            :  */
+      97                 :          0 : int mbedtls_x509_get_alg_null(unsigned char **p, const unsigned char *end,
+      98                 :            :                               mbedtls_x509_buf *alg)
+      99                 :            : {
+     100                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     101                 :            : 
+     102         [ #  # ]:          0 :     if ((ret = mbedtls_asn1_get_alg_null(p, end, alg)) != 0) {
+     103                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_ALG, ret);
+     104                 :            :     }
+     105                 :            : 
+     106                 :          0 :     return 0;
+     107                 :            : }
+     108                 :            : 
+     109                 :            : /*
+     110                 :            :  * Parse an algorithm identifier with (optional) parameters
+     111                 :            :  */
+     112                 :      24250 : int mbedtls_x509_get_alg(unsigned char **p, const unsigned char *end,
+     113                 :            :                          mbedtls_x509_buf *alg, mbedtls_x509_buf *params)
+     114                 :            : {
+     115                 :      24250 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     116                 :            : 
+     117         [ -  + ]:      24250 :     if ((ret = mbedtls_asn1_get_alg(p, end, alg, params)) != 0) {
+     118                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_ALG, ret);
+     119                 :            :     }
+     120                 :            : 
+     121                 :      24250 :     return 0;
+     122                 :            : }
+     123                 :            : 
+     124                 :            : /*
+     125                 :            :  * Convert md type to string
+     126                 :            :  */
+     127                 :            : #if !defined(MBEDTLS_X509_REMOVE_INFO) && defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
+     128                 :            : 
+     129                 :          0 : static inline const char *md_type_to_string(mbedtls_md_type_t md_alg)
+     130                 :            : {
+     131   [ #  #  #  #  :          0 :     switch (md_alg) {
+             #  #  #  #  
+                      # ]
+     132                 :            : #if defined(MBEDTLS_MD_CAN_MD5)
+     133                 :          0 :         case MBEDTLS_MD_MD5:
+     134                 :          0 :             return "MD5";
+     135                 :            : #endif
+     136                 :            : #if defined(MBEDTLS_MD_CAN_SHA1)
+     137                 :          0 :         case MBEDTLS_MD_SHA1:
+     138                 :          0 :             return "SHA1";
+     139                 :            : #endif
+     140                 :            : #if defined(MBEDTLS_MD_CAN_SHA224)
+     141                 :          0 :         case MBEDTLS_MD_SHA224:
+     142                 :          0 :             return "SHA224";
+     143                 :            : #endif
+     144                 :            : #if defined(MBEDTLS_MD_CAN_SHA256)
+     145                 :          0 :         case MBEDTLS_MD_SHA256:
+     146                 :          0 :             return "SHA256";
+     147                 :            : #endif
+     148                 :            : #if defined(MBEDTLS_MD_CAN_SHA384)
+     149                 :          0 :         case MBEDTLS_MD_SHA384:
+     150                 :          0 :             return "SHA384";
+     151                 :            : #endif
+     152                 :            : #if defined(MBEDTLS_MD_CAN_SHA512)
+     153                 :          0 :         case MBEDTLS_MD_SHA512:
+     154                 :          0 :             return "SHA512";
+     155                 :            : #endif
+     156                 :            : #if defined(MBEDTLS_MD_CAN_RIPEMD160)
+     157                 :          0 :         case MBEDTLS_MD_RIPEMD160:
+     158                 :          0 :             return "RIPEMD160";
+     159                 :            : #endif
+     160                 :          0 :         case MBEDTLS_MD_NONE:
+     161                 :          0 :             return NULL;
+     162                 :          0 :         default:
+     163                 :          0 :             return NULL;
+     164                 :            :     }
+     165                 :            : }
+     166                 :            : 
+     167                 :            : #endif /* !defined(MBEDTLS_X509_REMOVE_INFO) && defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT) */
+     168                 :            : 
+     169                 :            : #if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
+     170                 :            : /*
+     171                 :            :  * HashAlgorithm ::= AlgorithmIdentifier
+     172                 :            :  *
+     173                 :            :  * AlgorithmIdentifier  ::=  SEQUENCE  {
+     174                 :            :  *      algorithm               OBJECT IDENTIFIER,
+     175                 :            :  *      parameters              ANY DEFINED BY algorithm OPTIONAL  }
+     176                 :            :  *
+     177                 :            :  * For HashAlgorithm, parameters MUST be NULL or absent.
+     178                 :            :  */
+     179                 :          0 : static int x509_get_hash_alg(const mbedtls_x509_buf *alg, mbedtls_md_type_t *md_alg)
+     180                 :            : {
+     181                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     182                 :            :     unsigned char *p;
+     183                 :            :     const unsigned char *end;
+     184                 :            :     mbedtls_x509_buf md_oid;
+     185                 :            :     size_t len;
+     186                 :            : 
+     187                 :            :     /* Make sure we got a SEQUENCE and setup bounds */
+     188         [ #  # ]:          0 :     if (alg->tag != (MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) {
+     189                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_ALG,
+     190                 :            :                                  MBEDTLS_ERR_ASN1_UNEXPECTED_TAG);
+     191                 :            :     }
+     192                 :            : 
+     193                 :          0 :     p = alg->p;
+     194                 :          0 :     end = p + alg->len;
+     195                 :            : 
+     196         [ #  # ]:          0 :     if (p >= end) {
+     197                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_ALG,
+     198                 :            :                                  MBEDTLS_ERR_ASN1_OUT_OF_DATA);
+     199                 :            :     }
+     200                 :            : 
+     201                 :            :     /* Parse md_oid */
+     202                 :          0 :     md_oid.tag = *p;
+     203                 :            : 
+     204         [ #  # ]:          0 :     if ((ret = mbedtls_asn1_get_tag(&p, end, &md_oid.len, MBEDTLS_ASN1_OID)) != 0) {
+     205                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_ALG, ret);
+     206                 :            :     }
+     207                 :            : 
+     208                 :          0 :     md_oid.p = p;
+     209                 :          0 :     p += md_oid.len;
+     210                 :            : 
+     211                 :            :     /* Get md_alg from md_oid */
+     212         [ #  # ]:          0 :     if ((ret = mbedtls_oid_get_md_alg(&md_oid, md_alg)) != 0) {
+     213                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_ALG, ret);
+     214                 :            :     }
+     215                 :            : 
+     216                 :            :     /* Make sure params is absent of NULL */
+     217         [ #  # ]:          0 :     if (p == end) {
+     218                 :          0 :         return 0;
+     219                 :            :     }
+     220                 :            : 
+     221   [ #  #  #  # ]:          0 :     if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_NULL)) != 0 || len != 0) {
+     222                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_ALG, ret);
+     223                 :            :     }
+     224                 :            : 
+     225         [ #  # ]:          0 :     if (p != end) {
+     226                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_ALG,
+     227                 :            :                                  MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
+     228                 :            :     }
+     229                 :            : 
+     230                 :          0 :     return 0;
+     231                 :            : }
+     232                 :            : 
+     233                 :            : /*
+     234                 :            :  *    RSASSA-PSS-params  ::=  SEQUENCE  {
+     235                 :            :  *       hashAlgorithm     [0] HashAlgorithm DEFAULT sha1Identifier,
+     236                 :            :  *       maskGenAlgorithm  [1] MaskGenAlgorithm DEFAULT mgf1SHA1Identifier,
+     237                 :            :  *       saltLength        [2] INTEGER DEFAULT 20,
+     238                 :            :  *       trailerField      [3] INTEGER DEFAULT 1  }
+     239                 :            :  *    -- Note that the tags in this Sequence are explicit.
+     240                 :            :  *
+     241                 :            :  * RFC 4055 (which defines use of RSASSA-PSS in PKIX) states that the value
+     242                 :            :  * of trailerField MUST be 1, and PKCS#1 v2.2 doesn't even define any other
+     243                 :            :  * option. Enforce this at parsing time.
+     244                 :            :  */
+     245                 :          0 : int mbedtls_x509_get_rsassa_pss_params(const mbedtls_x509_buf *params,
+     246                 :            :                                        mbedtls_md_type_t *md_alg, mbedtls_md_type_t *mgf_md,
+     247                 :            :                                        int *salt_len)
+     248                 :            : {
+     249                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     250                 :            :     unsigned char *p;
+     251                 :            :     const unsigned char *end, *end2;
+     252                 :            :     size_t len;
+     253                 :            :     mbedtls_x509_buf alg_id, alg_params;
+     254                 :            : 
+     255                 :            :     /* First set everything to defaults */
+     256                 :          0 :     *md_alg = MBEDTLS_MD_SHA1;
+     257                 :          0 :     *mgf_md = MBEDTLS_MD_SHA1;
+     258                 :          0 :     *salt_len = 20;
+     259                 :            : 
+     260                 :            :     /* Make sure params is a SEQUENCE and setup bounds */
+     261         [ #  # ]:          0 :     if (params->tag != (MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) {
+     262                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_ALG,
+     263                 :            :                                  MBEDTLS_ERR_ASN1_UNEXPECTED_TAG);
+     264                 :            :     }
+     265                 :            : 
+     266                 :          0 :     p = (unsigned char *) params->p;
+     267                 :          0 :     end = p + params->len;
+     268                 :            : 
+     269         [ #  # ]:          0 :     if (p == end) {
+     270                 :          0 :         return 0;
+     271                 :            :     }
+     272                 :            : 
+     273                 :            :     /*
+     274                 :            :      * HashAlgorithm
+     275                 :            :      */
+     276         [ #  # ]:          0 :     if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
+     277                 :            :                                     MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED |
+     278                 :            :                                     0)) == 0) {
+     279                 :          0 :         end2 = p + len;
+     280                 :            : 
+     281                 :            :         /* HashAlgorithm ::= AlgorithmIdentifier (without parameters) */
+     282         [ #  # ]:          0 :         if ((ret = mbedtls_x509_get_alg_null(&p, end2, &alg_id)) != 0) {
+     283                 :          0 :             return ret;
+     284                 :            :         }
+     285                 :            : 
+     286         [ #  # ]:          0 :         if ((ret = mbedtls_oid_get_md_alg(&alg_id, md_alg)) != 0) {
+     287                 :          0 :             return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_ALG, ret);
+     288                 :            :         }
+     289                 :            : 
+     290         [ #  # ]:          0 :         if (p != end2) {
+     291                 :          0 :             return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_ALG,
+     292                 :            :                                      MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
+     293                 :            :         }
+     294         [ #  # ]:          0 :     } else if (ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) {
+     295                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_ALG, ret);
+     296                 :            :     }
+     297                 :            : 
+     298         [ #  # ]:          0 :     if (p == end) {
+     299                 :          0 :         return 0;
+     300                 :            :     }
+     301                 :            : 
+     302                 :            :     /*
+     303                 :            :      * MaskGenAlgorithm
+     304                 :            :      */
+     305         [ #  # ]:          0 :     if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
+     306                 :            :                                     MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED |
+     307                 :            :                                     1)) == 0) {
+     308                 :          0 :         end2 = p + len;
+     309                 :            : 
+     310                 :            :         /* MaskGenAlgorithm ::= AlgorithmIdentifier (params = HashAlgorithm) */
+     311         [ #  # ]:          0 :         if ((ret = mbedtls_x509_get_alg(&p, end2, &alg_id, &alg_params)) != 0) {
+     312                 :          0 :             return ret;
+     313                 :            :         }
+     314                 :            : 
+     315                 :            :         /* Only MFG1 is recognised for now */
+     316   [ #  #  #  #  :          0 :         if (MBEDTLS_OID_CMP(MBEDTLS_OID_MGF1, &alg_id) != 0) {
+                   #  # ]
+     317                 :          0 :             return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE,
+     318                 :            :                                      MBEDTLS_ERR_OID_NOT_FOUND);
+     319                 :            :         }
+     320                 :            : 
+     321                 :            :         /* Parse HashAlgorithm */
+     322         [ #  # ]:          0 :         if ((ret = x509_get_hash_alg(&alg_params, mgf_md)) != 0) {
+     323                 :          0 :             return ret;
+     324                 :            :         }
+     325                 :            : 
+     326         [ #  # ]:          0 :         if (p != end2) {
+     327                 :          0 :             return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_ALG,
+     328                 :            :                                      MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
+     329                 :            :         }
+     330         [ #  # ]:          0 :     } else if (ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) {
+     331                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_ALG, ret);
+     332                 :            :     }
+     333                 :            : 
+     334         [ #  # ]:          0 :     if (p == end) {
+     335                 :          0 :         return 0;
+     336                 :            :     }
+     337                 :            : 
+     338                 :            :     /*
+     339                 :            :      * salt_len
+     340                 :            :      */
+     341         [ #  # ]:          0 :     if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
+     342                 :            :                                     MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED |
+     343                 :            :                                     2)) == 0) {
+     344                 :          0 :         end2 = p + len;
+     345                 :            : 
+     346         [ #  # ]:          0 :         if ((ret = mbedtls_asn1_get_int(&p, end2, salt_len)) != 0) {
+     347                 :          0 :             return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_ALG, ret);
+     348                 :            :         }
+     349                 :            : 
+     350         [ #  # ]:          0 :         if (p != end2) {
+     351                 :          0 :             return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_ALG,
+     352                 :            :                                      MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
+     353                 :            :         }
+     354         [ #  # ]:          0 :     } else if (ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) {
+     355                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_ALG, ret);
+     356                 :            :     }
+     357                 :            : 
+     358         [ #  # ]:          0 :     if (p == end) {
+     359                 :          0 :         return 0;
+     360                 :            :     }
+     361                 :            : 
+     362                 :            :     /*
+     363                 :            :      * trailer_field (if present, must be 1)
+     364                 :            :      */
+     365         [ #  # ]:          0 :     if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
+     366                 :            :                                     MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED |
+     367                 :            :                                     3)) == 0) {
+     368                 :            :         int trailer_field;
+     369                 :            : 
+     370                 :          0 :         end2 = p + len;
+     371                 :            : 
+     372         [ #  # ]:          0 :         if ((ret = mbedtls_asn1_get_int(&p, end2, &trailer_field)) != 0) {
+     373                 :          0 :             return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_ALG, ret);
+     374                 :            :         }
+     375                 :            : 
+     376         [ #  # ]:          0 :         if (p != end2) {
+     377                 :          0 :             return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_ALG,
+     378                 :            :                                      MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
+     379                 :            :         }
+     380                 :            : 
+     381         [ #  # ]:          0 :         if (trailer_field != 1) {
+     382                 :          0 :             return MBEDTLS_ERR_X509_INVALID_ALG;
+     383                 :            :         }
+     384         [ #  # ]:          0 :     } else if (ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) {
+     385                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_ALG, ret);
+     386                 :            :     }
+     387                 :            : 
+     388         [ #  # ]:          0 :     if (p != end) {
+     389                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_ALG,
+     390                 :            :                                  MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
+     391                 :            :     }
+     392                 :            : 
+     393                 :          0 :     return 0;
+     394                 :            : }
+     395                 :            : #endif /* MBEDTLS_X509_RSASSA_PSS_SUPPORT */
+     396                 :            : 
+     397                 :            : /*
+     398                 :            :  *  AttributeTypeAndValue ::= SEQUENCE {
+     399                 :            :  *    type     AttributeType,
+     400                 :            :  *    value    AttributeValue }
+     401                 :            :  *
+     402                 :            :  *  AttributeType ::= OBJECT IDENTIFIER
+     403                 :            :  *
+     404                 :            :  *  AttributeValue ::= ANY DEFINED BY AttributeType
+     405                 :            :  */
+     406                 :      24370 : static int x509_get_attr_type_value(unsigned char **p,
+     407                 :            :                                     const unsigned char *end,
+     408                 :            :                                     mbedtls_x509_name *cur)
+     409                 :            : {
+     410                 :      24370 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     411                 :            :     size_t len;
+     412                 :            :     mbedtls_x509_buf *oid;
+     413                 :            :     mbedtls_x509_buf *val;
+     414                 :            : 
+     415         [ -  + ]:      24370 :     if ((ret = mbedtls_asn1_get_tag(p, end, &len,
+     416                 :            :                                     MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
+     417                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_NAME, ret);
+     418                 :            :     }
+     419                 :            : 
+     420                 :      24370 :     end = *p + len;
+     421                 :            : 
+     422         [ -  + ]:      24370 :     if ((end - *p) < 1) {
+     423                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_NAME,
+     424                 :            :                                  MBEDTLS_ERR_ASN1_OUT_OF_DATA);
+     425                 :            :     }
+     426                 :            : 
+     427                 :      24370 :     oid = &cur->oid;
+     428                 :      24370 :     oid->tag = **p;
+     429                 :            : 
+     430         [ -  + ]:      24370 :     if ((ret = mbedtls_asn1_get_tag(p, end, &oid->len, MBEDTLS_ASN1_OID)) != 0) {
+     431                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_NAME, ret);
+     432                 :            :     }
+     433                 :            : 
+     434                 :      24370 :     oid->p = *p;
+     435                 :      24370 :     *p += oid->len;
+     436                 :            : 
+     437         [ -  + ]:      24370 :     if ((end - *p) < 1) {
+     438                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_NAME,
+     439                 :            :                                  MBEDTLS_ERR_ASN1_OUT_OF_DATA);
+     440                 :            :     }
+     441                 :            : 
+     442   [ +  -  +  + ]:      24370 :     if (**p != MBEDTLS_ASN1_BMP_STRING && **p != MBEDTLS_ASN1_UTF8_STRING      &&
+     443   [ +  -  -  + ]:        190 :         **p != MBEDTLS_ASN1_T61_STRING && **p != MBEDTLS_ASN1_PRINTABLE_STRING &&
+     444   [ #  #  #  # ]:          0 :         **p != MBEDTLS_ASN1_IA5_STRING && **p != MBEDTLS_ASN1_UNIVERSAL_STRING &&
+     445         [ #  # ]:          0 :         **p != MBEDTLS_ASN1_BIT_STRING) {
+     446                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_NAME,
+     447                 :            :                                  MBEDTLS_ERR_ASN1_UNEXPECTED_TAG);
+     448                 :            :     }
+     449                 :            : 
+     450                 :      24370 :     val = &cur->val;
+     451                 :      24370 :     val->tag = *(*p)++;
+     452                 :            : 
+     453         [ -  + ]:      24370 :     if ((ret = mbedtls_asn1_get_len(p, end, &val->len)) != 0) {
+     454                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_NAME, ret);
+     455                 :            :     }
+     456                 :            : 
+     457                 :      24370 :     val->p = *p;
+     458                 :      24370 :     *p += val->len;
+     459                 :            : 
+     460         [ -  + ]:      24370 :     if (*p != end) {
+     461                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_NAME,
+     462                 :            :                                  MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
+     463                 :            :     }
+     464                 :            : 
+     465                 :      24370 :     cur->next = NULL;
+     466                 :            : 
+     467                 :      24370 :     return 0;
+     468                 :            : }
+     469                 :            : 
+     470                 :            : /*
+     471                 :            :  *  Name ::= CHOICE { -- only one possibility for now --
+     472                 :            :  *       rdnSequence  RDNSequence }
+     473                 :            :  *
+     474                 :            :  *  RDNSequence ::= SEQUENCE OF RelativeDistinguishedName
+     475                 :            :  *
+     476                 :            :  *  RelativeDistinguishedName ::=
+     477                 :            :  *    SET OF AttributeTypeAndValue
+     478                 :            :  *
+     479                 :            :  *  AttributeTypeAndValue ::= SEQUENCE {
+     480                 :            :  *    type     AttributeType,
+     481                 :            :  *    value    AttributeValue }
+     482                 :            :  *
+     483                 :            :  *  AttributeType ::= OBJECT IDENTIFIER
+     484                 :            :  *
+     485                 :            :  *  AttributeValue ::= ANY DEFINED BY AttributeType
+     486                 :            :  *
+     487                 :            :  * The data structure is optimized for the common case where each RDN has only
+     488                 :            :  * one element, which is represented as a list of AttributeTypeAndValue.
+     489                 :            :  * For the general case we still use a flat list, but we mark elements of the
+     490                 :            :  * same set so that they are "merged" together in the functions that consume
+     491                 :            :  * this list, eg mbedtls_x509_dn_gets().
+     492                 :            :  *
+     493                 :            :  * On success, this function may allocate a linked list starting at cur->next
+     494                 :            :  * that must later be free'd by the caller using mbedtls_free(). In error
+     495                 :            :  * cases, this function frees all allocated memory internally and the caller
+     496                 :            :  * has no freeing responsibilities.
+     497                 :            :  */
+     498                 :      24250 : int mbedtls_x509_get_name(unsigned char **p, const unsigned char *end,
+     499                 :            :                           mbedtls_x509_name *cur)
+     500                 :            : {
+     501                 :      24250 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     502                 :            :     size_t set_len;
+     503                 :            :     const unsigned char *end_set;
+     504                 :      24250 :     mbedtls_x509_name *head = cur;
+     505                 :            : 
+     506                 :            :     /* don't use recursion, we'd risk stack overflow if not optimized */
+     507                 :            :     while (1) {
+     508                 :            :         /*
+     509                 :            :          * parse SET
+     510                 :            :          */
+     511         [ -  + ]:      24370 :         if ((ret = mbedtls_asn1_get_tag(p, end, &set_len,
+     512                 :            :                                         MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SET)) != 0) {
+     513                 :          0 :             ret = MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_NAME, ret);
+     514                 :          0 :             goto error;
+     515                 :            :         }
+     516                 :            : 
+     517                 :      24370 :         end_set  = *p + set_len;
+     518                 :            : 
+     519                 :            :         while (1) {
+     520         [ -  + ]:      24370 :             if ((ret = x509_get_attr_type_value(p, end_set, cur)) != 0) {
+     521                 :          0 :                 goto error;
+     522                 :            :             }
+     523                 :            : 
+     524         [ +  - ]:      24370 :             if (*p == end_set) {
+     525                 :      24370 :                 break;
+     526                 :            :             }
+     527                 :            : 
+     528                 :            :             /* Mark this item as being no the only one in a set */
+     529                 :          0 :             cur->next_merged = 1;
+     530                 :            : 
+     531                 :          0 :             cur->next = mbedtls_calloc(1, sizeof(mbedtls_x509_name));
+     532                 :            : 
+     533         [ #  # ]:          0 :             if (cur->next == NULL) {
+     534                 :          0 :                 ret = MBEDTLS_ERR_X509_ALLOC_FAILED;
+     535                 :          0 :                 goto error;
+     536                 :            :             }
+     537                 :            : 
+     538                 :          0 :             cur = cur->next;
+     539                 :            :         }
+     540                 :            : 
+     541                 :            :         /*
+     542                 :            :          * continue until end of SEQUENCE is reached
+     543                 :            :          */
+     544         [ +  + ]:      24370 :         if (*p == end) {
+     545                 :      24250 :             return 0;
+     546                 :            :         }
+     547                 :            : 
+     548                 :        120 :         cur->next = mbedtls_calloc(1, sizeof(mbedtls_x509_name));
+     549                 :            : 
+     550         [ -  + ]:        120 :         if (cur->next == NULL) {
+     551                 :          0 :             ret = MBEDTLS_ERR_X509_ALLOC_FAILED;
+     552                 :          0 :             goto error;
+     553                 :            :         }
+     554                 :            : 
+     555                 :        120 :         cur = cur->next;
+     556                 :            :     }
+     557                 :            : 
+     558                 :          0 : error:
+     559                 :            :     /* Skip the first element as we did not allocate it */
+     560                 :          0 :     mbedtls_asn1_free_named_data_list_shallow(head->next);
+     561                 :          0 :     head->next = NULL;
+     562                 :            : 
+     563                 :          0 :     return ret;
+     564                 :            : }
+     565                 :            : 
+     566                 :      24250 : static int x509_date_is_valid(const mbedtls_x509_time *t)
+     567                 :            : {
+     568                 :            :     unsigned int month_days;
+     569                 :            :     unsigned int year;
+     570   [ +  +  -  - ]:      24250 :     switch (t->mon) {
+     571                 :       3971 :         case 1: case 3: case 5: case 7: case 8: case 10: case 12:
+     572                 :       3971 :             month_days = 31;
+     573                 :       3971 :             break;
+     574                 :      20279 :         case 4: case 6: case 9: case 11:
+     575                 :      20279 :             month_days = 30;
+     576                 :      20279 :             break;
+     577                 :          0 :         case 2:
+     578                 :          0 :             year = (unsigned int) t->year;
+     579         [ #  # ]:          0 :             month_days = ((year & 3) || (!(year % 100)
+     580         [ #  # ]:          0 :                                          && (year % 400)))
+     581         [ #  # ]:          0 :                           ? 28 : 29;
+     582                 :          0 :             break;
+     583                 :          0 :         default:
+     584                 :          0 :             return MBEDTLS_ERR_X509_INVALID_DATE;
+     585                 :            :     }
+     586                 :            : 
+     587         [ +  - ]:      24250 :     if ((unsigned int) (t->day - 1) >= month_days ||      /* (1 - days in month) */
+     588                 :            :         /* (unsigned int) (t->mon - 1) >= 12 || */  /* (1 - 12) checked above */
+     589         [ +  - ]:      24250 :         (unsigned int) t->year > 9999 ||         /* (0 - 9999) */
+     590         [ +  - ]:      24250 :         (unsigned int) t->hour > 23 ||           /* (0 - 23) */
+     591         [ +  - ]:      24250 :         (unsigned int) t->min  > 59 ||           /* (0 - 59) */
+     592         [ -  + ]:      24250 :         (unsigned int) t->sec  > 59) {           /* (0 - 59) */
+     593                 :          0 :         return MBEDTLS_ERR_X509_INVALID_DATE;
+     594                 :            :     }
+     595                 :            : 
+     596                 :      24250 :     return 0;
+     597                 :            : }
+     598                 :            : 
+     599                 :     145500 : static int x509_parse2_int(const unsigned char *p)
+     600                 :            : {
+     601                 :     145500 :     uint32_t d1 = p[0] - '0';
+     602                 :     145500 :     uint32_t d2 = p[1] - '0';
+     603   [ +  -  +  - ]:     145500 :     return (d1 < 10 && d2 < 10) ? (int) (d1 * 10 + d2) : -1;
+     604                 :            : }
+     605                 :            : 
+     606                 :            : /*
+     607                 :            :  * Parse an ASN1_UTC_TIME (yearlen=2) or ASN1_GENERALIZED_TIME (yearlen=4)
+     608                 :            :  * field.
+     609                 :            :  */
+     610                 :      24250 : static int x509_parse_time(const unsigned char *p, mbedtls_x509_time *tm,
+     611                 :            :                            size_t yearlen)
+     612                 :            : {
+     613                 :            :     int x;
+     614                 :            : 
+     615                 :            :     /*
+     616                 :            :      * Parse year, month, day, hour, minute, second
+     617                 :            :      */
+     618                 :      24250 :     tm->year = x509_parse2_int(p);
+     619         [ -  + ]:      24250 :     if (tm->year < 0) {
+     620                 :          0 :         return MBEDTLS_ERR_X509_INVALID_DATE;
+     621                 :            :     }
+     622                 :            : 
+     623         [ -  + ]:      24250 :     if (4 == yearlen) {
+     624                 :          0 :         x = tm->year * 100;
+     625                 :          0 :         p += 2;
+     626                 :          0 :         tm->year = x509_parse2_int(p);
+     627         [ #  # ]:          0 :         if (tm->year < 0) {
+     628                 :          0 :             return MBEDTLS_ERR_X509_INVALID_DATE;
+     629                 :            :         }
+     630                 :            :     } else {
+     631         [ +  - ]:      24250 :         x = (tm->year < 50) ? 2000 : 1900;
+     632                 :            :     }
+     633                 :      24250 :     tm->year += x;
+     634                 :            : 
+     635                 :      24250 :     tm->mon  = x509_parse2_int(p + 2);
+     636                 :      24250 :     tm->day  = x509_parse2_int(p + 4);
+     637                 :      24250 :     tm->hour = x509_parse2_int(p + 6);
+     638                 :      24250 :     tm->min  = x509_parse2_int(p + 8);
+     639                 :      24250 :     tm->sec  = x509_parse2_int(p + 10);
+     640                 :            : 
+     641                 :      24250 :     return x509_date_is_valid(tm);
+     642                 :            : }
+     643                 :            : 
+     644                 :            : /*
+     645                 :            :  *  Time ::= CHOICE {
+     646                 :            :  *       utcTime        UTCTime,
+     647                 :            :  *       generalTime    GeneralizedTime }
+     648                 :            :  */
+     649                 :      24250 : int mbedtls_x509_get_time(unsigned char **p, const unsigned char *end,
+     650                 :            :                           mbedtls_x509_time *tm)
+     651                 :            : {
+     652                 :      24250 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     653                 :            :     size_t len, year_len;
+     654                 :            :     unsigned char tag;
+     655                 :            : 
+     656         [ -  + ]:      24250 :     if ((end - *p) < 1) {
+     657                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_DATE,
+     658                 :            :                                  MBEDTLS_ERR_ASN1_OUT_OF_DATA);
+     659                 :            :     }
+     660                 :            : 
+     661                 :      24250 :     tag = **p;
+     662                 :            : 
+     663         [ +  - ]:      24250 :     if (tag == MBEDTLS_ASN1_UTC_TIME) {
+     664                 :      24250 :         year_len = 2;
+     665         [ #  # ]:          0 :     } else if (tag == MBEDTLS_ASN1_GENERALIZED_TIME) {
+     666                 :          0 :         year_len = 4;
+     667                 :            :     } else {
+     668                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_DATE,
+     669                 :            :                                  MBEDTLS_ERR_ASN1_UNEXPECTED_TAG);
+     670                 :            :     }
+     671                 :            : 
+     672                 :      24250 :     (*p)++;
+     673                 :      24250 :     ret = mbedtls_asn1_get_len(p, end, &len);
+     674                 :            : 
+     675         [ -  + ]:      24250 :     if (ret != 0) {
+     676                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_DATE, ret);
+     677                 :            :     }
+     678                 :            : 
+     679                 :            :     /* len is 12 or 14 depending on year_len, plus optional trailing 'Z' */
+     680         [ +  - ]:      24250 :     if (len != year_len + 10 &&
+     681   [ +  -  -  + ]:      24250 :         !(len == year_len + 11 && (*p)[(len - 1)] == 'Z')) {
+     682                 :          0 :         return MBEDTLS_ERR_X509_INVALID_DATE;
+     683                 :            :     }
+     684                 :            : 
+     685                 :      24250 :     (*p) += len;
+     686                 :      24250 :     return x509_parse_time(*p - len, tm, year_len);
+     687                 :            : }
+     688                 :            : 
+     689                 :      12125 : int mbedtls_x509_get_sig(unsigned char **p, const unsigned char *end, mbedtls_x509_buf *sig)
+     690                 :            : {
+     691                 :      12125 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     692                 :            :     size_t len;
+     693                 :            :     int tag_type;
+     694                 :            : 
+     695         [ -  + ]:      12125 :     if ((end - *p) < 1) {
+     696                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_SIGNATURE,
+     697                 :            :                                  MBEDTLS_ERR_ASN1_OUT_OF_DATA);
+     698                 :            :     }
+     699                 :            : 
+     700                 :      12125 :     tag_type = **p;
+     701                 :            : 
+     702         [ -  + ]:      12125 :     if ((ret = mbedtls_asn1_get_bitstring_null(p, end, &len)) != 0) {
+     703                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_SIGNATURE, ret);
+     704                 :            :     }
+     705                 :            : 
+     706                 :      12125 :     sig->tag = tag_type;
+     707                 :      12125 :     sig->len = len;
+     708                 :      12125 :     sig->p = *p;
+     709                 :            : 
+     710                 :      12125 :     *p += len;
+     711                 :            : 
+     712                 :      12125 :     return 0;
+     713                 :            : }
+     714                 :            : 
+     715                 :            : /*
+     716                 :            :  * Get signature algorithm from alg OID and optional parameters
+     717                 :            :  */
+     718                 :      12125 : int mbedtls_x509_get_sig_alg(const mbedtls_x509_buf *sig_oid, const mbedtls_x509_buf *sig_params,
+     719                 :            :                              mbedtls_md_type_t *md_alg, mbedtls_pk_type_t *pk_alg,
+     720                 :            :                              void **sig_opts)
+     721                 :            : {
+     722                 :      12125 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     723                 :            : 
+     724         [ -  + ]:      12125 :     if (*sig_opts != NULL) {
+     725                 :          0 :         return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
+     726                 :            :     }
+     727                 :            : 
+     728         [ -  + ]:      12125 :     if ((ret = mbedtls_oid_get_sig_alg(sig_oid, md_alg, pk_alg)) != 0) {
+     729                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG, ret);
+     730                 :            :     }
+     731                 :            : 
+     732                 :            : #if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
+     733         [ -  + ]:      12125 :     if (*pk_alg == MBEDTLS_PK_RSASSA_PSS) {
+     734                 :            :         mbedtls_pk_rsassa_pss_options *pss_opts;
+     735                 :            : 
+     736                 :          0 :         pss_opts = mbedtls_calloc(1, sizeof(mbedtls_pk_rsassa_pss_options));
+     737         [ #  # ]:          0 :         if (pss_opts == NULL) {
+     738                 :          0 :             return MBEDTLS_ERR_X509_ALLOC_FAILED;
+     739                 :            :         }
+     740                 :            : 
+     741                 :          0 :         ret = mbedtls_x509_get_rsassa_pss_params(sig_params,
+     742                 :            :                                                  md_alg,
+     743                 :            :                                                  &pss_opts->mgf1_hash_id,
+     744                 :            :                                                  &pss_opts->expected_salt_len);
+     745         [ #  # ]:          0 :         if (ret != 0) {
+     746                 :          0 :             mbedtls_free(pss_opts);
+     747                 :          0 :             return ret;
+     748                 :            :         }
+     749                 :            : 
+     750                 :          0 :         *sig_opts = (void *) pss_opts;
+     751                 :            :     } else
+     752                 :            : #endif /* MBEDTLS_X509_RSASSA_PSS_SUPPORT */
+     753                 :            :     {
+     754                 :            :         /* Make sure parameters are absent or NULL */
+     755   [ +  +  +  - ]:      12125 :         if ((sig_params->tag != MBEDTLS_ASN1_NULL && sig_params->tag != 0) ||
+     756         [ -  + ]:      12125 :             sig_params->len != 0) {
+     757                 :          0 :             return MBEDTLS_ERR_X509_INVALID_ALG;
+     758                 :            :         }
+     759                 :            :     }
+     760                 :            : 
+     761                 :      12125 :     return 0;
+     762                 :            : }
+     763                 :            : 
+     764                 :            : /*
+     765                 :            :  * X.509 Extensions (No parsing of extensions, pointer should
+     766                 :            :  * be either manually updated or extensions should be parsed!)
+     767                 :            :  */
+     768                 :      12125 : int mbedtls_x509_get_ext(unsigned char **p, const unsigned char *end,
+     769                 :            :                          mbedtls_x509_buf *ext, int tag)
+     770                 :            : {
+     771                 :      12125 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     772                 :            :     size_t len;
+     773                 :            : 
+     774                 :            :     /* Extension structure use EXPLICIT tagging. That is, the actual
+     775                 :            :      * `Extensions` structure is wrapped by a tag-length pair using
+     776                 :            :      * the respective context-specific tag. */
+     777                 :      12125 :     ret = mbedtls_asn1_get_tag(p, end, &ext->len,
+     778                 :            :                                MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | tag);
+     779         [ -  + ]:      12125 :     if (ret != 0) {
+     780                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
+     781                 :            :     }
+     782                 :            : 
+     783                 :      12125 :     ext->tag = MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | tag;
+     784                 :      12125 :     ext->p   = *p;
+     785                 :      12125 :     end      = *p + ext->len;
+     786                 :            : 
+     787                 :            :     /*
+     788                 :            :      * Extensions  ::=  SEQUENCE SIZE (1..MAX) OF Extension
+     789                 :            :      */
+     790         [ -  + ]:      12125 :     if ((ret = mbedtls_asn1_get_tag(p, end, &len,
+     791                 :            :                                     MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
+     792                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
+     793                 :            :     }
+     794                 :            : 
+     795         [ -  + ]:      12125 :     if (end != *p + len) {
+     796                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
+     797                 :            :                                  MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
+     798                 :            :     }
+     799                 :            : 
+     800                 :      12125 :     return 0;
+     801                 :            : }
+     802                 :            : 
+     803                 :          0 : static char nibble_to_hex_digit(int i)
+     804                 :            : {
+     805         [ #  # ]:          0 :     return (i < 10) ? (i + '0') : (i - 10 + 'A');
+     806                 :            : }
+     807                 :            : 
+     808                 :            : /*
+     809                 :            :  * Store the name in printable form into buf; no more
+     810                 :            :  * than size characters will be written
+     811                 :            :  */
+     812                 :          0 : int mbedtls_x509_dn_gets(char *buf, size_t size, const mbedtls_x509_name *dn)
+     813                 :            : {
+     814                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     815                 :            :     size_t i, j, n, asn1_len_size, asn1_tag_size, asn1_tag_len_buf_start;
+     816                 :            :     /* 6 is enough as our asn1 write functions only write one byte for the tag and at most five bytes for the length*/
+     817                 :            :     unsigned char asn1_tag_len_buf[6];
+     818                 :            :     unsigned char *asn1_len_p;
+     819                 :          0 :     unsigned char c, merge = 0;
+     820                 :            :     const mbedtls_x509_name *name;
+     821                 :          0 :     const char *short_name = NULL;
+     822                 :            :     char lowbits, highbits;
+     823                 :            :     char s[MBEDTLS_X509_MAX_DN_NAME_SIZE], *p;
+     824                 :            :     int print_hexstring;
+     825                 :            : 
+     826                 :          0 :     memset(s, 0, sizeof(s));
+     827                 :            : 
+     828                 :          0 :     name = dn;
+     829                 :          0 :     p = buf;
+     830                 :          0 :     n = size;
+     831                 :            : 
+     832         [ #  # ]:          0 :     while (name != NULL) {
+     833         [ #  # ]:          0 :         if (!name->oid.p) {
+     834                 :          0 :             name = name->next;
+     835                 :          0 :             continue;
+     836                 :            :         }
+     837                 :            : 
+     838         [ #  # ]:          0 :         if (name != dn) {
+     839         [ #  # ]:          0 :             ret = mbedtls_snprintf(p, n, merge ? " + " : ", ");
+     840   [ #  #  #  # ]:          0 :             MBEDTLS_X509_SAFE_SNPRINTF;
+     841                 :            :         }
+     842                 :            : 
+     843                 :          0 :         print_hexstring = (name->val.tag != MBEDTLS_ASN1_UTF8_STRING) &&
+     844   [ #  #  #  # ]:          0 :                           (name->val.tag != MBEDTLS_ASN1_PRINTABLE_STRING) &&
+     845         [ #  # ]:          0 :                           (name->val.tag != MBEDTLS_ASN1_IA5_STRING);
+     846                 :            : 
+     847         [ #  # ]:          0 :         if ((ret = mbedtls_oid_get_attr_short_name(&name->oid, &short_name)) == 0) {
+     848                 :          0 :             ret = mbedtls_snprintf(p, n, "%s=", short_name);
+     849                 :            :         } else {
+     850         [ #  # ]:          0 :             if ((ret = mbedtls_oid_get_numeric_string(p, n, &name->oid)) > 0) {
+     851                 :          0 :                 n -= ret;
+     852                 :          0 :                 p += ret;
+     853                 :          0 :                 ret = mbedtls_snprintf(p, n, "=");
+     854                 :          0 :                 print_hexstring = 1;
+     855         [ #  # ]:          0 :             } else if (ret == MBEDTLS_ERR_OID_BUF_TOO_SMALL) {
+     856                 :          0 :                 return MBEDTLS_ERR_X509_BUFFER_TOO_SMALL;
+     857                 :            :             } else {
+     858                 :          0 :                 ret = mbedtls_snprintf(p, n, "\?\?=");
+     859                 :            :             }
+     860                 :            :         }
+     861   [ #  #  #  # ]:          0 :         MBEDTLS_X509_SAFE_SNPRINTF;
+     862                 :            : 
+     863         [ #  # ]:          0 :         if (print_hexstring) {
+     864                 :          0 :             s[0] = '#';
+     865                 :            : 
+     866                 :          0 :             asn1_len_p = asn1_tag_len_buf + sizeof(asn1_tag_len_buf);
+     867         [ #  # ]:          0 :             if ((ret = mbedtls_asn1_write_len(&asn1_len_p, asn1_tag_len_buf, name->val.len)) < 0) {
+     868                 :          0 :                 return MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     869                 :            :             }
+     870                 :          0 :             asn1_len_size = ret;
+     871         [ #  # ]:          0 :             if ((ret = mbedtls_asn1_write_tag(&asn1_len_p, asn1_tag_len_buf, name->val.tag)) < 0) {
+     872                 :          0 :                 return MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     873                 :            :             }
+     874                 :          0 :             asn1_tag_size = ret;
+     875                 :          0 :             asn1_tag_len_buf_start = sizeof(asn1_tag_len_buf) - asn1_len_size - asn1_tag_size;
+     876         [ #  # ]:          0 :             for (i = 0, j = 1; i < asn1_len_size + asn1_tag_size; i++) {
+     877         [ #  # ]:          0 :                 if (j + 1 >= sizeof(s) - 1) {
+     878                 :          0 :                     return MBEDTLS_ERR_X509_BUFFER_TOO_SMALL;
+     879                 :            :                 }
+     880                 :          0 :                 c = asn1_tag_len_buf[asn1_tag_len_buf_start+i];
+     881                 :          0 :                 lowbits = (c & 0x0F);
+     882                 :          0 :                 highbits = c >> 4;
+     883                 :          0 :                 s[j++] = nibble_to_hex_digit(highbits);
+     884                 :          0 :                 s[j++] = nibble_to_hex_digit(lowbits);
+     885                 :            :             }
+     886         [ #  # ]:          0 :             for (i = 0; i < name->val.len; i++) {
+     887         [ #  # ]:          0 :                 if (j + 1 >= sizeof(s) - 1) {
+     888                 :          0 :                     return MBEDTLS_ERR_X509_BUFFER_TOO_SMALL;
+     889                 :            :                 }
+     890                 :          0 :                 c = name->val.p[i];
+     891                 :          0 :                 lowbits = (c & 0x0F);
+     892                 :          0 :                 highbits = c >> 4;
+     893                 :          0 :                 s[j++] = nibble_to_hex_digit(highbits);
+     894                 :          0 :                 s[j++] = nibble_to_hex_digit(lowbits);
+     895                 :            :             }
+     896                 :            :         } else {
+     897         [ #  # ]:          0 :             for (i = 0, j = 0; i < name->val.len; i++, j++) {
+     898         [ #  # ]:          0 :                 if (j >= sizeof(s) - 1) {
+     899                 :          0 :                     return MBEDTLS_ERR_X509_BUFFER_TOO_SMALL;
+     900                 :            :                 }
+     901                 :            : 
+     902                 :          0 :                 c = name->val.p[i];
+     903                 :            :                 // Special characters requiring escaping, RFC 4514 Section 2.4
+     904         [ #  # ]:          0 :                 if (c == '\0') {
+     905                 :          0 :                     return MBEDTLS_ERR_X509_INVALID_NAME;
+     906                 :            :                 } else {
+     907   [ #  #  #  # ]:          0 :                     if (strchr(",=+<>;\"\\", c) ||
+     908         [ #  # ]:          0 :                         ((i == 0) && strchr("# ", c)) ||
+     909   [ #  #  #  # ]:          0 :                         ((i == name->val.len-1) && (c == ' '))) {
+     910         [ #  # ]:          0 :                         if (j + 1 >= sizeof(s) - 1) {
+     911                 :          0 :                             return MBEDTLS_ERR_X509_BUFFER_TOO_SMALL;
+     912                 :            :                         }
+     913                 :          0 :                         s[j++] = '\\';
+     914                 :            :                     }
+     915                 :            :                 }
+     916   [ #  #  #  # ]:          0 :                 if (c < 32 || c >= 127) {
+     917         [ #  # ]:          0 :                     if (j + 3 >= sizeof(s) - 1) {
+     918                 :          0 :                         return MBEDTLS_ERR_X509_BUFFER_TOO_SMALL;
+     919                 :            :                     }
+     920                 :          0 :                     s[j++] = '\\';
+     921                 :          0 :                     lowbits = (c & 0x0F);
+     922                 :          0 :                     highbits = c >> 4;
+     923                 :          0 :                     s[j++] = nibble_to_hex_digit(highbits);
+     924                 :          0 :                     s[j] = nibble_to_hex_digit(lowbits);
+     925                 :            :                 } else {
+     926                 :          0 :                     s[j] = c;
+     927                 :            :                 }
+     928                 :            :             }
+     929                 :            :         }
+     930                 :          0 :         s[j] = '\0';
+     931                 :          0 :         ret = mbedtls_snprintf(p, n, "%s", s);
+     932   [ #  #  #  # ]:          0 :         MBEDTLS_X509_SAFE_SNPRINTF;
+     933                 :            : 
+     934                 :          0 :         merge = name->next_merged;
+     935                 :          0 :         name = name->next;
+     936                 :            :     }
+     937                 :            : 
+     938                 :          0 :     return (int) (size - n);
+     939                 :            : }
+     940                 :            : 
+     941                 :            : /*
+     942                 :            :  * Store the serial in printable form into buf; no more
+     943                 :            :  * than size characters will be written
+     944                 :            :  */
+     945                 :          0 : int mbedtls_x509_serial_gets(char *buf, size_t size, const mbedtls_x509_buf *serial)
+     946                 :            : {
+     947                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     948                 :            :     size_t i, n, nr;
+     949                 :            :     char *p;
+     950                 :            : 
+     951                 :          0 :     p = buf;
+     952                 :          0 :     n = size;
+     953                 :            : 
+     954                 :          0 :     nr = (serial->len <= 32)
+     955         [ #  # ]:          0 :         ? serial->len  : 28;
+     956                 :            : 
+     957         [ #  # ]:          0 :     for (i = 0; i < nr; i++) {
+     958   [ #  #  #  #  :          0 :         if (i == 0 && nr > 1 && serial->p[i] == 0x0) {
+                   #  # ]
+     959                 :          0 :             continue;
+     960                 :            :         }
+     961                 :            : 
+     962                 :          0 :         ret = mbedtls_snprintf(p, n, "%02X%s",
+     963         [ #  # ]:          0 :                                serial->p[i], (i < nr - 1) ? ":" : "");
+     964   [ #  #  #  # ]:          0 :         MBEDTLS_X509_SAFE_SNPRINTF;
+     965                 :            :     }
+     966                 :            : 
+     967         [ #  # ]:          0 :     if (nr != serial->len) {
+     968                 :          0 :         ret = mbedtls_snprintf(p, n, "....");
+     969   [ #  #  #  # ]:          0 :         MBEDTLS_X509_SAFE_SNPRINTF;
+     970                 :            :     }
+     971                 :            : 
+     972                 :          0 :     return (int) (size - n);
+     973                 :            : }
+     974                 :            : 
+     975                 :            : #if !defined(MBEDTLS_X509_REMOVE_INFO)
+     976                 :            : /*
+     977                 :            :  * Helper for writing signature algorithms
+     978                 :            :  */
+     979                 :          0 : int mbedtls_x509_sig_alg_gets(char *buf, size_t size, const mbedtls_x509_buf *sig_oid,
+     980                 :            :                               mbedtls_pk_type_t pk_alg, mbedtls_md_type_t md_alg,
+     981                 :            :                               const void *sig_opts)
+     982                 :            : {
+     983                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     984                 :          0 :     char *p = buf;
+     985                 :          0 :     size_t n = size;
+     986                 :          0 :     const char *desc = NULL;
+     987                 :            : 
+     988                 :          0 :     ret = mbedtls_oid_get_sig_alg_desc(sig_oid, &desc);
+     989         [ #  # ]:          0 :     if (ret != 0) {
+     990                 :          0 :         ret = mbedtls_snprintf(p, n, "???");
+     991                 :            :     } else {
+     992                 :          0 :         ret = mbedtls_snprintf(p, n, "%s", desc);
+     993                 :            :     }
+     994   [ #  #  #  # ]:          0 :     MBEDTLS_X509_SAFE_SNPRINTF;
+     995                 :            : 
+     996                 :            : #if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
+     997         [ #  # ]:          0 :     if (pk_alg == MBEDTLS_PK_RSASSA_PSS) {
+     998                 :            :         const mbedtls_pk_rsassa_pss_options *pss_opts;
+     999                 :            : 
+    1000                 :          0 :         pss_opts = (const mbedtls_pk_rsassa_pss_options *) sig_opts;
+    1001                 :            : 
+    1002                 :          0 :         const char *name = md_type_to_string(md_alg);
+    1003                 :          0 :         const char *mgf_name = md_type_to_string(pss_opts->mgf1_hash_id);
+    1004                 :            : 
+    1005         [ #  # ]:          0 :         ret = mbedtls_snprintf(p, n, " (%s, MGF1-%s, 0x%02X)",
+    1006                 :            :                                name ? name : "???",
+    1007                 :            :                                mgf_name ? mgf_name : "???",
+    1008         [ #  # ]:          0 :                                (unsigned int) pss_opts->expected_salt_len);
+    1009   [ #  #  #  # ]:          0 :         MBEDTLS_X509_SAFE_SNPRINTF;
+    1010                 :            :     }
+    1011                 :            : #else
+    1012                 :            :     ((void) pk_alg);
+    1013                 :            :     ((void) md_alg);
+    1014                 :            :     ((void) sig_opts);
+    1015                 :            : #endif /* MBEDTLS_X509_RSASSA_PSS_SUPPORT */
+    1016                 :            : 
+    1017                 :          0 :     return (int) (size - n);
+    1018                 :            : }
+    1019                 :            : #endif /* MBEDTLS_X509_REMOVE_INFO */
+    1020                 :            : 
+    1021                 :            : /*
+    1022                 :            :  * Helper for writing "RSA key size", "EC key size", etc
+    1023                 :            :  */
+    1024                 :          0 : int mbedtls_x509_key_size_helper(char *buf, size_t buf_size, const char *name)
+    1025                 :            : {
+    1026                 :          0 :     char *p = buf;
+    1027                 :          0 :     size_t n = buf_size;
+    1028                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1029                 :            : 
+    1030                 :          0 :     ret = mbedtls_snprintf(p, n, "%s key size", name);
+    1031   [ #  #  #  # ]:          0 :     MBEDTLS_X509_SAFE_SNPRINTF;
+    1032                 :            : 
+    1033                 :          0 :     return 0;
+    1034                 :            : }
+    1035                 :            : 
+    1036                 :      10853 : int mbedtls_x509_time_cmp(const mbedtls_x509_time *t1,
+    1037                 :            :                           const mbedtls_x509_time *t2)
+    1038                 :            : {
+    1039                 :            :     int x;
+    1040                 :            : 
+    1041                 :      10853 :     x = (((t1->year << 9) | (t1->mon << 5) | (t1->day)) -
+    1042                 :      10853 :          ((t2->year << 9) | (t2->mon << 5) | (t2->day)));
+    1043         [ +  - ]:      10853 :     if (x != 0) {
+    1044                 :      10853 :         return x;
+    1045                 :            :     }
+    1046                 :            : 
+    1047                 :          0 :     x = (((t1->hour << 12) | (t1->min << 6) | (t1->sec)) -
+    1048                 :          0 :          ((t2->hour << 12) | (t2->min << 6) | (t2->sec)));
+    1049                 :          0 :     return x;
+    1050                 :            : }
+    1051                 :            : 
+    1052                 :            : #if defined(MBEDTLS_HAVE_TIME_DATE)
+    1053                 :       2255 : int mbedtls_x509_time_gmtime(mbedtls_time_t tt, mbedtls_x509_time *now)
+    1054                 :            : {
+    1055                 :            :     struct tm tm;
+    1056                 :            : 
+    1057         [ -  + ]:       2255 :     if (mbedtls_platform_gmtime_r(&tt, &tm) == NULL) {
+    1058                 :          0 :         return -1;
+    1059                 :            :     }
+    1060                 :            : 
+    1061                 :       2255 :     now->year = tm.tm_year + 1900;
+    1062                 :       2255 :     now->mon  = tm.tm_mon  + 1;
+    1063                 :       2255 :     now->day  = tm.tm_mday;
+    1064                 :       2255 :     now->hour = tm.tm_hour;
+    1065                 :       2255 :     now->min  = tm.tm_min;
+    1066                 :       2255 :     now->sec  = tm.tm_sec;
+    1067                 :       2255 :     return 0;
+    1068                 :            : }
+    1069                 :            : 
+    1070                 :          0 : static int x509_get_current_time(mbedtls_x509_time *now)
+    1071                 :            : {
+    1072                 :          0 :     return mbedtls_x509_time_gmtime(mbedtls_time(NULL), now);
+    1073                 :            : }
+    1074                 :            : 
+    1075                 :          0 : int mbedtls_x509_time_is_past(const mbedtls_x509_time *to)
+    1076                 :            : {
+    1077                 :            :     mbedtls_x509_time now;
+    1078                 :            : 
+    1079         [ #  # ]:          0 :     if (x509_get_current_time(&now) != 0) {
+    1080                 :          0 :         return 1;
+    1081                 :            :     }
+    1082                 :            : 
+    1083                 :          0 :     return mbedtls_x509_time_cmp(to, &now) < 0;
+    1084                 :            : }
+    1085                 :            : 
+    1086                 :          0 : int mbedtls_x509_time_is_future(const mbedtls_x509_time *from)
+    1087                 :            : {
+    1088                 :            :     mbedtls_x509_time now;
+    1089                 :            : 
+    1090         [ #  # ]:          0 :     if (x509_get_current_time(&now) != 0) {
+    1091                 :          0 :         return 1;
+    1092                 :            :     }
+    1093                 :            : 
+    1094                 :          0 :     return mbedtls_x509_time_cmp(from, &now) > 0;
+    1095                 :            : }
+    1096                 :            : 
+    1097                 :            : #else  /* MBEDTLS_HAVE_TIME_DATE */
+    1098                 :            : 
+    1099                 :            : int mbedtls_x509_time_is_past(const mbedtls_x509_time *to)
+    1100                 :            : {
+    1101                 :            :     ((void) to);
+    1102                 :            :     return 0;
+    1103                 :            : }
+    1104                 :            : 
+    1105                 :            : int mbedtls_x509_time_is_future(const mbedtls_x509_time *from)
+    1106                 :            : {
+    1107                 :            :     ((void) from);
+    1108                 :            :     return 0;
+    1109                 :            : }
+    1110                 :            : #endif /* MBEDTLS_HAVE_TIME_DATE */
+    1111                 :            : 
+    1112                 :            : /* Common functions for parsing CRT and CSR. */
+    1113                 :            : #if defined(MBEDTLS_X509_CRT_PARSE_C) || defined(MBEDTLS_X509_CSR_PARSE_C)
+    1114                 :            : /*
+    1115                 :            :  * OtherName ::= SEQUENCE {
+    1116                 :            :  *      type-id    OBJECT IDENTIFIER,
+    1117                 :            :  *      value      [0] EXPLICIT ANY DEFINED BY type-id }
+    1118                 :            :  *
+    1119                 :            :  * HardwareModuleName ::= SEQUENCE {
+    1120                 :            :  *                           hwType OBJECT IDENTIFIER,
+    1121                 :            :  *                           hwSerialNum OCTET STRING }
+    1122                 :            :  *
+    1123                 :            :  * NOTE: we currently only parse and use otherName of type HwModuleName,
+    1124                 :            :  * as defined in RFC 4108.
+    1125                 :            :  */
+    1126                 :       8113 : static int x509_get_other_name(const mbedtls_x509_buf *subject_alt_name,
+    1127                 :            :                                mbedtls_x509_san_other_name *other_name)
+    1128                 :            : {
+    1129                 :       8113 :     int ret = 0;
+    1130                 :            :     size_t len;
+    1131                 :       8113 :     unsigned char *p = subject_alt_name->p;
+    1132                 :       8113 :     const unsigned char *end = p + subject_alt_name->len;
+    1133                 :            :     mbedtls_x509_buf cur_oid;
+    1134                 :            : 
+    1135         [ -  + ]:       8113 :     if ((subject_alt_name->tag &
+    1136                 :            :          (MBEDTLS_ASN1_TAG_CLASS_MASK | MBEDTLS_ASN1_TAG_VALUE_MASK)) !=
+    1137                 :            :         (MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_X509_SAN_OTHER_NAME)) {
+    1138                 :            :         /*
+    1139                 :            :          * The given subject alternative name is not of type "othername".
+    1140                 :            :          */
+    1141                 :          0 :         return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
+    1142                 :            :     }
+    1143                 :            : 
+    1144         [ -  + ]:       8113 :     if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
+    1145                 :            :                                     MBEDTLS_ASN1_OID)) != 0) {
+    1146                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
+    1147                 :            :     }
+    1148                 :            : 
+    1149                 :       8113 :     cur_oid.tag = MBEDTLS_ASN1_OID;
+    1150                 :       8113 :     cur_oid.p = p;
+    1151                 :       8113 :     cur_oid.len = len;
+    1152                 :            : 
+    1153                 :            :     /*
+    1154                 :            :      * Only HwModuleName is currently supported.
+    1155                 :            :      */
+    1156   [ -  +  -  -  :       8113 :     if (MBEDTLS_OID_CMP(MBEDTLS_OID_ON_HW_MODULE_NAME, &cur_oid) != 0) {
+                   +  - ]
+    1157                 :       8113 :         return MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE;
+    1158                 :            :     }
+    1159                 :          0 :     other_name->type_id = cur_oid;
+    1160                 :            : 
+    1161                 :          0 :     p += len;
+    1162         [ #  # ]:          0 :     if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
+    1163                 :            :                                     MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_CONTEXT_SPECIFIC)) !=
+    1164                 :            :         0) {
+    1165                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
+    1166                 :            :     }
+    1167                 :            : 
+    1168         [ #  # ]:          0 :     if (end != p + len) {
+    1169                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
+    1170                 :            :                                  MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
+    1171                 :            :     }
+    1172                 :            : 
+    1173         [ #  # ]:          0 :     if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
+    1174                 :            :                                     MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
+    1175                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
+    1176                 :            :     }
+    1177                 :            : 
+    1178         [ #  # ]:          0 :     if (end != p + len) {
+    1179                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
+    1180                 :            :                                  MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
+    1181                 :            :     }
+    1182                 :            : 
+    1183         [ #  # ]:          0 :     if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_OID)) != 0) {
+    1184                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
+    1185                 :            :     }
+    1186                 :            : 
+    1187                 :          0 :     other_name->value.hardware_module_name.oid.tag = MBEDTLS_ASN1_OID;
+    1188                 :          0 :     other_name->value.hardware_module_name.oid.p = p;
+    1189                 :          0 :     other_name->value.hardware_module_name.oid.len = len;
+    1190                 :            : 
+    1191                 :          0 :     p += len;
+    1192         [ #  # ]:          0 :     if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
+    1193                 :            :                                     MBEDTLS_ASN1_OCTET_STRING)) != 0) {
+    1194                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
+    1195                 :            :     }
+    1196                 :            : 
+    1197                 :          0 :     other_name->value.hardware_module_name.val.tag = MBEDTLS_ASN1_OCTET_STRING;
+    1198                 :          0 :     other_name->value.hardware_module_name.val.p = p;
+    1199                 :          0 :     other_name->value.hardware_module_name.val.len = len;
+    1200                 :          0 :     p += len;
+    1201         [ #  # ]:          0 :     if (p != end) {
+    1202                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
+    1203                 :            :                                  MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
+    1204                 :            :     }
+    1205                 :          0 :     return 0;
+    1206                 :            : }
+    1207                 :            : 
+    1208                 :            : /* Check mbedtls_x509_get_subject_alt_name for detailed description.
+    1209                 :            :  *
+    1210                 :            :  * In some cases while parsing subject alternative names the sequence tag is optional
+    1211                 :            :  * (e.g. CertSerialNumber). This function is designed to handle such case.
+    1212                 :            :  */
+    1213                 :       8153 : int mbedtls_x509_get_subject_alt_name_ext(unsigned char **p,
+    1214                 :            :                                           const unsigned char *end,
+    1215                 :            :                                           mbedtls_x509_sequence *subject_alt_name)
+    1216                 :            : {
+    1217                 :       8153 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1218                 :            :     size_t tag_len;
+    1219                 :       8153 :     mbedtls_asn1_sequence *cur = subject_alt_name;
+    1220                 :            : 
+    1221         [ +  + ]:      17806 :     while (*p < end) {
+    1222                 :            :         mbedtls_x509_subject_alternative_name tmp_san_name;
+    1223                 :            :         mbedtls_x509_buf tmp_san_buf;
+    1224                 :       9653 :         memset(&tmp_san_name, 0, sizeof(tmp_san_name));
+    1225                 :            : 
+    1226                 :       9653 :         tmp_san_buf.tag = **p;
+    1227                 :       9653 :         (*p)++;
+    1228                 :            : 
+    1229         [ -  + ]:       9653 :         if ((ret = mbedtls_asn1_get_len(p, end, &tag_len)) != 0) {
+    1230                 :          0 :             return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
+    1231                 :            :         }
+    1232                 :            : 
+    1233                 :       9653 :         tmp_san_buf.p = *p;
+    1234                 :       9653 :         tmp_san_buf.len = tag_len;
+    1235                 :            : 
+    1236         [ -  + ]:       9653 :         if ((tmp_san_buf.tag & MBEDTLS_ASN1_TAG_CLASS_MASK) !=
+    1237                 :            :             MBEDTLS_ASN1_CONTEXT_SPECIFIC) {
+    1238                 :          0 :             return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
+    1239                 :            :                                      MBEDTLS_ERR_ASN1_UNEXPECTED_TAG);
+    1240                 :            :         }
+    1241                 :            : 
+    1242                 :            :         /*
+    1243                 :            :          * Check that the SAN is structured correctly by parsing it.
+    1244                 :            :          * The SAN structure is discarded afterwards.
+    1245                 :            :          */
+    1246                 :       9653 :         ret = mbedtls_x509_parse_subject_alt_name(&tmp_san_buf, &tmp_san_name);
+    1247                 :            :         /*
+    1248                 :            :          * In case the extension is malformed, return an error,
+    1249                 :            :          * and clear the allocated sequences.
+    1250                 :            :          */
+    1251   [ +  +  -  + ]:       9653 :         if (ret != 0 && ret != MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE) {
+    1252                 :          0 :             mbedtls_asn1_sequence_free(subject_alt_name->next);
+    1253                 :          0 :             subject_alt_name->next = NULL;
+    1254                 :          0 :             return ret;
+    1255                 :            :         }
+    1256                 :            : 
+    1257                 :       9653 :         mbedtls_x509_free_subject_alt_name(&tmp_san_name);
+    1258                 :            :         /* Allocate and assign next pointer */
+    1259         [ +  + ]:       9653 :         if (cur->buf.p != NULL) {
+    1260         [ -  + ]:       1500 :             if (cur->next != NULL) {
+    1261                 :          0 :                 return MBEDTLS_ERR_X509_INVALID_EXTENSIONS;
+    1262                 :            :             }
+    1263                 :            : 
+    1264                 :       1500 :             cur->next = mbedtls_calloc(1, sizeof(mbedtls_asn1_sequence));
+    1265                 :            : 
+    1266         [ -  + ]:       1500 :             if (cur->next == NULL) {
+    1267                 :          0 :                 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
+    1268                 :            :                                          MBEDTLS_ERR_ASN1_ALLOC_FAILED);
+    1269                 :            :             }
+    1270                 :            : 
+    1271                 :       1500 :             cur = cur->next;
+    1272                 :            :         }
+    1273                 :            : 
+    1274                 :       9653 :         cur->buf = tmp_san_buf;
+    1275                 :       9653 :         *p += tmp_san_buf.len;
+    1276                 :            :     }
+    1277                 :            : 
+    1278                 :            :     /* Set final sequence entry's next pointer to NULL */
+    1279                 :       8153 :     cur->next = NULL;
+    1280                 :            : 
+    1281         [ -  + ]:       8153 :     if (*p != end) {
+    1282                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
+    1283                 :            :                                  MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
+    1284                 :            :     }
+    1285                 :            : 
+    1286                 :       8153 :     return 0;
+    1287                 :            : }
+    1288                 :            : 
+    1289                 :            : /*
+    1290                 :            :  * SubjectAltName ::= GeneralNames
+    1291                 :            :  *
+    1292                 :            :  * GeneralNames ::= SEQUENCE SIZE (1..MAX) OF GeneralName
+    1293                 :            :  *
+    1294                 :            :  * GeneralName ::= CHOICE {
+    1295                 :            :  *      otherName                       [0]     OtherName,
+    1296                 :            :  *      rfc822Name                      [1]     IA5String,
+    1297                 :            :  *      dNSName                         [2]     IA5String,
+    1298                 :            :  *      x400Address                     [3]     ORAddress,
+    1299                 :            :  *      directoryName                   [4]     Name,
+    1300                 :            :  *      ediPartyName                    [5]     EDIPartyName,
+    1301                 :            :  *      uniformResourceIdentifier       [6]     IA5String,
+    1302                 :            :  *      iPAddress                       [7]     OCTET STRING,
+    1303                 :            :  *      registeredID                    [8]     OBJECT IDENTIFIER }
+    1304                 :            :  *
+    1305                 :            :  * OtherName ::= SEQUENCE {
+    1306                 :            :  *      type-id    OBJECT IDENTIFIER,
+    1307                 :            :  *      value      [0] EXPLICIT ANY DEFINED BY type-id }
+    1308                 :            :  *
+    1309                 :            :  * EDIPartyName ::= SEQUENCE {
+    1310                 :            :  *      nameAssigner            [0]     DirectoryString OPTIONAL,
+    1311                 :            :  *      partyName               [1]     DirectoryString }
+    1312                 :            :  *
+    1313                 :            :  * We list all types, but use the following GeneralName types from RFC 5280:
+    1314                 :            :  * "dnsName", "uniformResourceIdentifier" and "hardware_module_name"
+    1315                 :            :  * of type "otherName", as defined in RFC 4108.
+    1316                 :            :  */
+    1317                 :       8153 : int mbedtls_x509_get_subject_alt_name(unsigned char **p,
+    1318                 :            :                                       const unsigned char *end,
+    1319                 :            :                                       mbedtls_x509_sequence *subject_alt_name)
+    1320                 :            : {
+    1321                 :       8153 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1322                 :            :     size_t len;
+    1323                 :            : 
+    1324                 :            :     /* Get main sequence tag */
+    1325         [ -  + ]:       8153 :     if ((ret = mbedtls_asn1_get_tag(p, end, &len,
+    1326                 :            :                                     MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
+    1327                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
+    1328                 :            :     }
+    1329                 :            : 
+    1330         [ -  + ]:       8153 :     if (*p + len != end) {
+    1331                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
+    1332                 :            :                                  MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
+    1333                 :            :     }
+    1334                 :            : 
+    1335                 :       8153 :     return mbedtls_x509_get_subject_alt_name_ext(p, end, subject_alt_name);
+    1336                 :            : }
+    1337                 :            : 
+    1338                 :          0 : int mbedtls_x509_get_ns_cert_type(unsigned char **p,
+    1339                 :            :                                   const unsigned char *end,
+    1340                 :            :                                   unsigned char *ns_cert_type)
+    1341                 :            : {
+    1342                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1343                 :          0 :     mbedtls_x509_bitstring bs = { 0, 0, NULL };
+    1344                 :            : 
+    1345         [ #  # ]:          0 :     if ((ret = mbedtls_asn1_get_bitstring(p, end, &bs)) != 0) {
+    1346                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
+    1347                 :            :     }
+    1348                 :            : 
+    1349                 :            :     /* A bitstring with no flags set is still technically valid, as it will mean
+    1350                 :            :        that the certificate has no designated purpose at the time of creation. */
+    1351         [ #  # ]:          0 :     if (bs.len == 0) {
+    1352                 :          0 :         *ns_cert_type = 0;
+    1353                 :          0 :         return 0;
+    1354                 :            :     }
+    1355                 :            : 
+    1356         [ #  # ]:          0 :     if (bs.len != 1) {
+    1357                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
+    1358                 :            :                                  MBEDTLS_ERR_ASN1_INVALID_LENGTH);
+    1359                 :            :     }
+    1360                 :            : 
+    1361                 :            :     /* Get actual bitstring */
+    1362                 :          0 :     *ns_cert_type = *bs.p;
+    1363                 :          0 :     return 0;
+    1364                 :            : }
+    1365                 :            : 
+    1366                 :       9975 : int mbedtls_x509_get_key_usage(unsigned char **p,
+    1367                 :            :                                const unsigned char *end,
+    1368                 :            :                                unsigned int *key_usage)
+    1369                 :            : {
+    1370                 :       9975 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1371                 :            :     size_t i;
+    1372                 :       9975 :     mbedtls_x509_bitstring bs = { 0, 0, NULL };
+    1373                 :            : 
+    1374         [ -  + ]:       9975 :     if ((ret = mbedtls_asn1_get_bitstring(p, end, &bs)) != 0) {
+    1375                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
+    1376                 :            :     }
+    1377                 :            : 
+    1378                 :            :     /* A bitstring with no flags set is still technically valid, as it will mean
+    1379                 :            :        that the certificate has no designated purpose at the time of creation. */
+    1380         [ -  + ]:       9975 :     if (bs.len == 0) {
+    1381                 :          0 :         *key_usage = 0;
+    1382                 :          0 :         return 0;
+    1383                 :            :     }
+    1384                 :            : 
+    1385                 :            :     /* Get actual bitstring */
+    1386                 :       9975 :     *key_usage = 0;
+    1387   [ +  +  +  - ]:      19950 :     for (i = 0; i < bs.len && i < sizeof(unsigned int); i++) {
+    1388                 :       9975 :         *key_usage |= (unsigned int) bs.p[i] << (8*i);
+    1389                 :            :     }
+    1390                 :            : 
+    1391                 :       9975 :     return 0;
+    1392                 :            : }
+    1393                 :            : 
+    1394                 :       9653 : int mbedtls_x509_parse_subject_alt_name(const mbedtls_x509_buf *san_buf,
+    1395                 :            :                                         mbedtls_x509_subject_alternative_name *san)
+    1396                 :            : {
+    1397                 :       9653 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1398   [ +  -  +  -  :       9653 :     switch (san_buf->tag &
+                -  -  - ]
+    1399                 :            :             (MBEDTLS_ASN1_TAG_CLASS_MASK |
+    1400                 :            :              MBEDTLS_ASN1_TAG_VALUE_MASK)) {
+    1401                 :            :         /*
+    1402                 :            :          * otherName
+    1403                 :            :          */
+    1404                 :       8113 :         case (MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_X509_SAN_OTHER_NAME):
+    1405                 :            :         {
+    1406                 :            :             mbedtls_x509_san_other_name other_name;
+    1407                 :            : 
+    1408                 :       8113 :             ret = x509_get_other_name(san_buf, &other_name);
+    1409         [ +  - ]:       8113 :             if (ret != 0) {
+    1410                 :       8113 :                 return ret;
+    1411                 :            :             }
+    1412                 :            : 
+    1413                 :          0 :             memset(san, 0, sizeof(mbedtls_x509_subject_alternative_name));
+    1414                 :          0 :             san->type = MBEDTLS_X509_SAN_OTHER_NAME;
+    1415                 :          0 :             memcpy(&san->san.other_name,
+    1416                 :            :                    &other_name, sizeof(other_name));
+    1417                 :            : 
+    1418                 :            :         }
+    1419                 :          0 :         break;
+    1420                 :            :         /*
+    1421                 :            :          * uniformResourceIdentifier
+    1422                 :            :          */
+    1423                 :          0 :         case (MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_X509_SAN_UNIFORM_RESOURCE_IDENTIFIER):
+    1424                 :            :         {
+    1425                 :          0 :             memset(san, 0, sizeof(mbedtls_x509_subject_alternative_name));
+    1426                 :          0 :             san->type = MBEDTLS_X509_SAN_UNIFORM_RESOURCE_IDENTIFIER;
+    1427                 :            : 
+    1428                 :          0 :             memcpy(&san->san.unstructured_name,
+    1429                 :            :                    san_buf, sizeof(*san_buf));
+    1430                 :            : 
+    1431                 :            :         }
+    1432                 :          0 :         break;
+    1433                 :            :         /*
+    1434                 :            :          * dNSName
+    1435                 :            :          */
+    1436                 :       1540 :         case (MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_X509_SAN_DNS_NAME):
+    1437                 :            :         {
+    1438                 :       1540 :             memset(san, 0, sizeof(mbedtls_x509_subject_alternative_name));
+    1439                 :       1540 :             san->type = MBEDTLS_X509_SAN_DNS_NAME;
+    1440                 :            : 
+    1441                 :       1540 :             memcpy(&san->san.unstructured_name,
+    1442                 :            :                    san_buf, sizeof(*san_buf));
+    1443                 :            :         }
+    1444                 :       1540 :         break;
+    1445                 :            :         /*
+    1446                 :            :          * IP address
+    1447                 :            :          */
+    1448                 :          0 :         case (MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_X509_SAN_IP_ADDRESS):
+    1449                 :            :         {
+    1450                 :          0 :             memset(san, 0, sizeof(mbedtls_x509_subject_alternative_name));
+    1451                 :          0 :             san->type = MBEDTLS_X509_SAN_IP_ADDRESS;
+    1452                 :            :             // Only IPv6 (16 bytes) and IPv4 (4 bytes) types are supported
+    1453   [ #  #  #  # ]:          0 :             if (san_buf->len == 4 || san_buf->len == 16) {
+    1454                 :          0 :                 memcpy(&san->san.unstructured_name,
+    1455                 :            :                        san_buf, sizeof(*san_buf));
+    1456                 :            :             } else {
+    1457                 :          0 :                 return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
+    1458                 :            :             }
+    1459                 :            :         }
+    1460                 :          0 :         break;
+    1461                 :            :         /*
+    1462                 :            :          * rfc822Name
+    1463                 :            :          */
+    1464                 :          0 :         case (MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_X509_SAN_RFC822_NAME):
+    1465                 :            :         {
+    1466                 :          0 :             memset(san, 0, sizeof(mbedtls_x509_subject_alternative_name));
+    1467                 :          0 :             san->type = MBEDTLS_X509_SAN_RFC822_NAME;
+    1468                 :          0 :             memcpy(&san->san.unstructured_name, san_buf, sizeof(*san_buf));
+    1469                 :            :         }
+    1470                 :          0 :         break;
+    1471                 :            :         /*
+    1472                 :            :          * directoryName
+    1473                 :            :          */
+    1474                 :          0 :         case (MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_X509_SAN_DIRECTORY_NAME):
+    1475                 :            :         {
+    1476                 :            :             size_t name_len;
+    1477                 :          0 :             unsigned char *p = san_buf->p;
+    1478                 :          0 :             memset(san, 0, sizeof(mbedtls_x509_subject_alternative_name));
+    1479                 :          0 :             san->type = MBEDTLS_X509_SAN_DIRECTORY_NAME;
+    1480                 :            : 
+    1481                 :          0 :             ret = mbedtls_asn1_get_tag(&p, p + san_buf->len, &name_len,
+    1482                 :            :                                        MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE);
+    1483                 :            : 
+    1484         [ #  # ]:          0 :             if (ret != 0) {
+    1485                 :          0 :                 return ret;
+    1486                 :            :             }
+    1487                 :            : 
+    1488         [ #  # ]:          0 :             if ((ret = mbedtls_x509_get_name(&p, p + name_len,
+    1489                 :            :                                              &san->san.directory_name)) != 0) {
+    1490                 :          0 :                 return ret;
+    1491                 :            :             }
+    1492                 :            :         }
+    1493                 :          0 :         break;
+    1494                 :            :         /*
+    1495                 :            :          * Type not supported
+    1496                 :            :          */
+    1497                 :          0 :         default:
+    1498                 :          0 :             return MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE;
+    1499                 :            :     }
+    1500                 :       1540 :     return 0;
+    1501                 :            : }
+    1502                 :            : 
+    1503                 :       9653 : void mbedtls_x509_free_subject_alt_name(mbedtls_x509_subject_alternative_name *san)
+    1504                 :            : {
+    1505         [ -  + ]:       9653 :     if (san->type == MBEDTLS_X509_SAN_DIRECTORY_NAME) {
+    1506                 :          0 :         mbedtls_asn1_free_named_data_list_shallow(san->san.directory_name.next);
+    1507                 :            :     }
+    1508                 :       9653 : }
+    1509                 :            : 
+    1510                 :            : #if !defined(MBEDTLS_X509_REMOVE_INFO)
+    1511                 :          0 : int mbedtls_x509_info_subject_alt_name(char **buf, size_t *size,
+    1512                 :            :                                        const mbedtls_x509_sequence
+    1513                 :            :                                        *subject_alt_name,
+    1514                 :            :                                        const char *prefix)
+    1515                 :            : {
+    1516                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1517                 :            :     size_t i;
+    1518                 :          0 :     size_t n = *size;
+    1519                 :          0 :     char *p = *buf;
+    1520                 :          0 :     const mbedtls_x509_sequence *cur = subject_alt_name;
+    1521                 :            :     mbedtls_x509_subject_alternative_name san;
+    1522                 :            :     int parse_ret;
+    1523                 :            : 
+    1524         [ #  # ]:          0 :     while (cur != NULL) {
+    1525                 :          0 :         memset(&san, 0, sizeof(san));
+    1526                 :          0 :         parse_ret = mbedtls_x509_parse_subject_alt_name(&cur->buf, &san);
+    1527         [ #  # ]:          0 :         if (parse_ret != 0) {
+    1528         [ #  # ]:          0 :             if (parse_ret == MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE) {
+    1529                 :          0 :                 ret = mbedtls_snprintf(p, n, "\n%s    <unsupported>", prefix);
+    1530   [ #  #  #  # ]:          0 :                 MBEDTLS_X509_SAFE_SNPRINTF;
+    1531                 :            :             } else {
+    1532                 :          0 :                 ret = mbedtls_snprintf(p, n, "\n%s    <malformed>", prefix);
+    1533   [ #  #  #  # ]:          0 :                 MBEDTLS_X509_SAFE_SNPRINTF;
+    1534                 :            :             }
+    1535                 :          0 :             cur = cur->next;
+    1536                 :          0 :             continue;
+    1537                 :            :         }
+    1538                 :            : 
+    1539   [ #  #  #  #  :          0 :         switch (san.type) {
+                   #  # ]
+    1540                 :            :             /*
+    1541                 :            :              * otherName
+    1542                 :            :              */
+    1543                 :          0 :             case MBEDTLS_X509_SAN_OTHER_NAME:
+    1544                 :            :             {
+    1545                 :          0 :                 mbedtls_x509_san_other_name *other_name = &san.san.other_name;
+    1546                 :            : 
+    1547                 :          0 :                 ret = mbedtls_snprintf(p, n, "\n%s    otherName :", prefix);
+    1548   [ #  #  #  # ]:          0 :                 MBEDTLS_X509_SAFE_SNPRINTF;
+    1549                 :            : 
+    1550   [ #  #  #  #  :          0 :                 if (MBEDTLS_OID_CMP(MBEDTLS_OID_ON_HW_MODULE_NAME,
+                   #  # ]
+    1551                 :            :                                     &other_name->type_id) == 0) {
+    1552                 :          0 :                     ret = mbedtls_snprintf(p, n, "\n%s        hardware module name :", prefix);
+    1553   [ #  #  #  # ]:          0 :                     MBEDTLS_X509_SAFE_SNPRINTF;
+    1554                 :            :                     ret =
+    1555                 :          0 :                         mbedtls_snprintf(p, n, "\n%s            hardware type          : ", prefix);
+    1556   [ #  #  #  # ]:          0 :                     MBEDTLS_X509_SAFE_SNPRINTF;
+    1557                 :            : 
+    1558                 :          0 :                     ret = mbedtls_oid_get_numeric_string(p,
+    1559                 :            :                                                          n,
+    1560                 :          0 :                                                          &other_name->value.hardware_module_name.oid);
+    1561   [ #  #  #  # ]:          0 :                     MBEDTLS_X509_SAFE_SNPRINTF;
+    1562                 :            : 
+    1563                 :            :                     ret =
+    1564                 :          0 :                         mbedtls_snprintf(p, n, "\n%s            hardware serial number : ", prefix);
+    1565   [ #  #  #  # ]:          0 :                     MBEDTLS_X509_SAFE_SNPRINTF;
+    1566                 :            : 
+    1567         [ #  # ]:          0 :                     for (i = 0; i < other_name->value.hardware_module_name.val.len; i++) {
+    1568                 :          0 :                         ret = mbedtls_snprintf(p,
+    1569                 :            :                                                n,
+    1570                 :            :                                                "%02X",
+    1571                 :          0 :                                                other_name->value.hardware_module_name.val.p[i]);
+    1572   [ #  #  #  # ]:          0 :                         MBEDTLS_X509_SAFE_SNPRINTF;
+    1573                 :            :                     }
+    1574                 :            :                 }/* MBEDTLS_OID_ON_HW_MODULE_NAME */
+    1575                 :            :             }
+    1576                 :          0 :             break;
+    1577                 :            :             /*
+    1578                 :            :              * uniformResourceIdentifier
+    1579                 :            :              */
+    1580                 :          0 :             case MBEDTLS_X509_SAN_UNIFORM_RESOURCE_IDENTIFIER:
+    1581                 :            :             {
+    1582                 :          0 :                 ret = mbedtls_snprintf(p, n, "\n%s    uniformResourceIdentifier : ", prefix);
+    1583   [ #  #  #  # ]:          0 :                 MBEDTLS_X509_SAFE_SNPRINTF;
+    1584         [ #  # ]:          0 :                 if (san.san.unstructured_name.len >= n) {
+    1585         [ #  # ]:          0 :                     if (n > 0) {
+    1586                 :          0 :                         *p = '\0';
+    1587                 :            :                     }
+    1588                 :          0 :                     return MBEDTLS_ERR_X509_BUFFER_TOO_SMALL;
+    1589                 :            :                 }
+    1590                 :            : 
+    1591                 :          0 :                 memcpy(p, san.san.unstructured_name.p, san.san.unstructured_name.len);
+    1592                 :          0 :                 p += san.san.unstructured_name.len;
+    1593                 :          0 :                 n -= san.san.unstructured_name.len;
+    1594                 :            :             }
+    1595                 :          0 :             break;
+    1596                 :            :             /*
+    1597                 :            :              * dNSName
+    1598                 :            :              * RFC822 Name
+    1599                 :            :              */
+    1600                 :          0 :             case MBEDTLS_X509_SAN_DNS_NAME:
+    1601                 :            :             case MBEDTLS_X509_SAN_RFC822_NAME:
+    1602                 :            :             {
+    1603                 :          0 :                 const char *dns_name = "dNSName";
+    1604                 :          0 :                 const char *rfc822_name = "rfc822Name";
+    1605                 :            : 
+    1606                 :          0 :                 ret = mbedtls_snprintf(p, n,
+    1607                 :            :                                        "\n%s    %s : ",
+    1608                 :            :                                        prefix,
+    1609         [ #  # ]:          0 :                                        san.type ==
+    1610                 :            :                                        MBEDTLS_X509_SAN_DNS_NAME ? dns_name : rfc822_name);
+    1611   [ #  #  #  # ]:          0 :                 MBEDTLS_X509_SAFE_SNPRINTF;
+    1612         [ #  # ]:          0 :                 if (san.san.unstructured_name.len >= n) {
+    1613         [ #  # ]:          0 :                     if (n > 0) {
+    1614                 :          0 :                         *p = '\0';
+    1615                 :            :                     }
+    1616                 :          0 :                     return MBEDTLS_ERR_X509_BUFFER_TOO_SMALL;
+    1617                 :            :                 }
+    1618                 :            : 
+    1619                 :          0 :                 memcpy(p, san.san.unstructured_name.p, san.san.unstructured_name.len);
+    1620                 :          0 :                 p += san.san.unstructured_name.len;
+    1621                 :          0 :                 n -= san.san.unstructured_name.len;
+    1622                 :            :             }
+    1623                 :          0 :             break;
+    1624                 :            :             /*
+    1625                 :            :              * iPAddress
+    1626                 :            :              */
+    1627                 :          0 :             case MBEDTLS_X509_SAN_IP_ADDRESS:
+    1628                 :            :             {
+    1629                 :          0 :                 ret = mbedtls_snprintf(p, n, "\n%s    %s : ",
+    1630                 :            :                                        prefix, "iPAddress");
+    1631   [ #  #  #  # ]:          0 :                 MBEDTLS_X509_SAFE_SNPRINTF;
+    1632         [ #  # ]:          0 :                 if (san.san.unstructured_name.len >= n) {
+    1633         [ #  # ]:          0 :                     if (n > 0) {
+    1634                 :          0 :                         *p = '\0';
+    1635                 :            :                     }
+    1636                 :          0 :                     return MBEDTLS_ERR_X509_BUFFER_TOO_SMALL;
+    1637                 :            :                 }
+    1638                 :            : 
+    1639                 :          0 :                 unsigned char *ip = san.san.unstructured_name.p;
+    1640                 :            :                 // Only IPv6 (16 bytes) and IPv4 (4 bytes) types are supported
+    1641         [ #  # ]:          0 :                 if (san.san.unstructured_name.len == 4) {
+    1642                 :          0 :                     ret = mbedtls_snprintf(p, n, "%u.%u.%u.%u", ip[0], ip[1], ip[2], ip[3]);
+    1643   [ #  #  #  # ]:          0 :                     MBEDTLS_X509_SAFE_SNPRINTF;
+    1644         [ #  # ]:          0 :                 } else if (san.san.unstructured_name.len == 16) {
+    1645                 :          0 :                     ret = mbedtls_snprintf(p, n,
+    1646                 :            :                                            "%X%X:%X%X:%X%X:%X%X:%X%X:%X%X:%X%X:%X%X",
+    1647                 :          0 :                                            ip[0], ip[1], ip[2], ip[3], ip[4], ip[5], ip[6],
+    1648                 :          0 :                                            ip[7], ip[8], ip[9], ip[10], ip[11], ip[12], ip[13],
+    1649                 :          0 :                                            ip[14], ip[15]);
+    1650   [ #  #  #  # ]:          0 :                     MBEDTLS_X509_SAFE_SNPRINTF;
+    1651                 :            :                 } else {
+    1652         [ #  # ]:          0 :                     if (n > 0) {
+    1653                 :          0 :                         *p = '\0';
+    1654                 :            :                     }
+    1655                 :          0 :                     return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
+    1656                 :            :                 }
+    1657                 :            :             }
+    1658                 :          0 :             break;
+    1659                 :            :             /*
+    1660                 :            :              * directoryName
+    1661                 :            :              */
+    1662                 :          0 :             case MBEDTLS_X509_SAN_DIRECTORY_NAME:
+    1663                 :            :             {
+    1664                 :          0 :                 ret = mbedtls_snprintf(p, n, "\n%s    directoryName : ", prefix);
+    1665   [ #  #  #  # ]:          0 :                 if (ret < 0 || (size_t) ret >= n) {
+    1666                 :          0 :                     mbedtls_x509_free_subject_alt_name(&san);
+    1667                 :            :                 }
+    1668                 :            : 
+    1669   [ #  #  #  # ]:          0 :                 MBEDTLS_X509_SAFE_SNPRINTF;
+    1670                 :          0 :                 ret = mbedtls_x509_dn_gets(p, n, &san.san.directory_name);
+    1671                 :            : 
+    1672         [ #  # ]:          0 :                 if (ret < 0) {
+    1673                 :          0 :                     mbedtls_x509_free_subject_alt_name(&san);
+    1674         [ #  # ]:          0 :                     if (n > 0) {
+    1675                 :          0 :                         *p = '\0';
+    1676                 :            :                     }
+    1677                 :          0 :                     return ret;
+    1678                 :            :                 }
+    1679                 :            : 
+    1680                 :          0 :                 p += ret;
+    1681                 :          0 :                 n -= ret;
+    1682                 :            :             }
+    1683                 :          0 :             break;
+    1684                 :            :             /*
+    1685                 :            :              * Type not supported, skip item.
+    1686                 :            :              */
+    1687                 :          0 :             default:
+    1688                 :          0 :                 ret = mbedtls_snprintf(p, n, "\n%s    <unsupported>", prefix);
+    1689   [ #  #  #  # ]:          0 :                 MBEDTLS_X509_SAFE_SNPRINTF;
+    1690                 :          0 :                 break;
+    1691                 :            :         }
+    1692                 :            : 
+    1693                 :            :         /* So far memory is freed only in the case of directoryName
+    1694                 :            :          * parsing succeeding, as mbedtls_x509_get_name allocates memory. */
+    1695                 :          0 :         mbedtls_x509_free_subject_alt_name(&san);
+    1696                 :          0 :         cur = cur->next;
+    1697                 :            :     }
+    1698                 :            : 
+    1699                 :          0 :     *p = '\0';
+    1700                 :            : 
+    1701                 :          0 :     *size = n;
+    1702                 :          0 :     *buf = p;
+    1703                 :            : 
+    1704                 :          0 :     return 0;
+    1705                 :            : }
+    1706                 :            : 
+    1707                 :            : #define PRINT_ITEM(i)                                   \
+    1708                 :            :     do {                                                \
+    1709                 :            :         ret = mbedtls_snprintf(p, n, "%s" i, sep);      \
+    1710                 :            :         MBEDTLS_X509_SAFE_SNPRINTF;                     \
+    1711                 :            :         sep = ", ";                                     \
+    1712                 :            :     } while (0)
+    1713                 :            : 
+    1714                 :            : #define CERT_TYPE(type, name)                           \
+    1715                 :            :     do {                                                \
+    1716                 :            :         if (ns_cert_type & (type)) {                    \
+    1717                 :            :             PRINT_ITEM(name);                           \
+    1718                 :            :         }                                               \
+    1719                 :            :     } while (0)
+    1720                 :            : 
+    1721                 :          0 : int mbedtls_x509_info_cert_type(char **buf, size_t *size,
+    1722                 :            :                                 unsigned char ns_cert_type)
+    1723                 :            : {
+    1724                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1725                 :          0 :     size_t n = *size;
+    1726                 :          0 :     char *p = *buf;
+    1727                 :          0 :     const char *sep = "";
+    1728                 :            : 
+    1729   [ #  #  #  #  :          0 :     CERT_TYPE(MBEDTLS_X509_NS_CERT_TYPE_SSL_CLIENT,         "SSL Client");
+                   #  # ]
+    1730   [ #  #  #  #  :          0 :     CERT_TYPE(MBEDTLS_X509_NS_CERT_TYPE_SSL_SERVER,         "SSL Server");
+                   #  # ]
+    1731   [ #  #  #  #  :          0 :     CERT_TYPE(MBEDTLS_X509_NS_CERT_TYPE_EMAIL,              "Email");
+                   #  # ]
+    1732   [ #  #  #  #  :          0 :     CERT_TYPE(MBEDTLS_X509_NS_CERT_TYPE_OBJECT_SIGNING,     "Object Signing");
+                   #  # ]
+    1733   [ #  #  #  #  :          0 :     CERT_TYPE(MBEDTLS_X509_NS_CERT_TYPE_RESERVED,           "Reserved");
+                   #  # ]
+    1734   [ #  #  #  #  :          0 :     CERT_TYPE(MBEDTLS_X509_NS_CERT_TYPE_SSL_CA,             "SSL CA");
+                   #  # ]
+    1735   [ #  #  #  #  :          0 :     CERT_TYPE(MBEDTLS_X509_NS_CERT_TYPE_EMAIL_CA,           "Email CA");
+                   #  # ]
+    1736   [ #  #  #  #  :          0 :     CERT_TYPE(MBEDTLS_X509_NS_CERT_TYPE_OBJECT_SIGNING_CA,  "Object Signing CA");
+                   #  # ]
+    1737                 :            : 
+    1738                 :          0 :     *size = n;
+    1739                 :          0 :     *buf = p;
+    1740                 :            : 
+    1741                 :          0 :     return 0;
+    1742                 :            : }
+    1743                 :            : 
+    1744                 :            : #define KEY_USAGE(code, name)       \
+    1745                 :            :     do {                            \
+    1746                 :            :         if ((key_usage) & (code)) { \
+    1747                 :            :             PRINT_ITEM(name);       \
+    1748                 :            :         }                           \
+    1749                 :            :     } while (0)
+    1750                 :            : 
+    1751                 :          0 : int mbedtls_x509_info_key_usage(char **buf, size_t *size,
+    1752                 :            :                                 unsigned int key_usage)
+    1753                 :            : {
+    1754                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1755                 :          0 :     size_t n = *size;
+    1756                 :          0 :     char *p = *buf;
+    1757                 :          0 :     const char *sep = "";
+    1758                 :            : 
+    1759   [ #  #  #  #  :          0 :     KEY_USAGE(MBEDTLS_X509_KU_DIGITAL_SIGNATURE,    "Digital Signature");
+                   #  # ]
+    1760   [ #  #  #  #  :          0 :     KEY_USAGE(MBEDTLS_X509_KU_NON_REPUDIATION,      "Non Repudiation");
+                   #  # ]
+    1761   [ #  #  #  #  :          0 :     KEY_USAGE(MBEDTLS_X509_KU_KEY_ENCIPHERMENT,     "Key Encipherment");
+                   #  # ]
+    1762   [ #  #  #  #  :          0 :     KEY_USAGE(MBEDTLS_X509_KU_DATA_ENCIPHERMENT,    "Data Encipherment");
+                   #  # ]
+    1763   [ #  #  #  #  :          0 :     KEY_USAGE(MBEDTLS_X509_KU_KEY_AGREEMENT,        "Key Agreement");
+                   #  # ]
+    1764   [ #  #  #  #  :          0 :     KEY_USAGE(MBEDTLS_X509_KU_KEY_CERT_SIGN,        "Key Cert Sign");
+                   #  # ]
+    1765   [ #  #  #  #  :          0 :     KEY_USAGE(MBEDTLS_X509_KU_CRL_SIGN,             "CRL Sign");
+                   #  # ]
+    1766   [ #  #  #  #  :          0 :     KEY_USAGE(MBEDTLS_X509_KU_ENCIPHER_ONLY,        "Encipher Only");
+                   #  # ]
+    1767   [ #  #  #  #  :          0 :     KEY_USAGE(MBEDTLS_X509_KU_DECIPHER_ONLY,        "Decipher Only");
+                   #  # ]
+    1768                 :            : 
+    1769                 :          0 :     *size = n;
+    1770                 :          0 :     *buf = p;
+    1771                 :            : 
+    1772                 :          0 :     return 0;
+    1773                 :            : }
+    1774                 :            : #endif /* MBEDTLS_X509_REMOVE_INFO */
+    1775                 :            : #endif /* MBEDTLS_X509_CRT_PARSE_C || MBEDTLS_X509_CSR_PARSE_C */
+    1776                 :            : #endif /* MBEDTLS_X509_USE_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509_create.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509_create.c.func-sort-c.html new file mode 100644 index 00000000000..806a3e9933b --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509_create.c.func-sort-c.html @@ -0,0 +1,129 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/x509_create.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - x509_create.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:12220061.0 %
Date:2024-09-22 08:21:07Functions:91275.0 %
Branches:6516439.6 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
hex_to_int0
hexpair_to_int0
parse_attribute_value_hex_der_encoded0
mbedtls_x509_write_extensions6
mbedtls_x509_write_names6
mbedtls_x509_write_sig6
mbedtls_x509_string_to_names8
x509_write_name18
parse_attribute_value_string24
x509_attr_descr_from_name24
mbedtls_x509_set_extension38
x509_write_extension38
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509_create.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509_create.c.func.html new file mode 100644 index 00000000000..c0239007d85 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509_create.c.func.html @@ -0,0 +1,129 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/x509_create.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - x509_create.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:12220061.0 %
Date:2024-09-22 08:21:07Functions:91275.0 %
Branches:6516439.6 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
hex_to_int0
hexpair_to_int0
mbedtls_x509_set_extension38
mbedtls_x509_string_to_names8
mbedtls_x509_write_extensions6
mbedtls_x509_write_names6
mbedtls_x509_write_sig6
parse_attribute_value_hex_der_encoded0
parse_attribute_value_string24
x509_attr_descr_from_name24
x509_write_extension38
x509_write_name18
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509_create.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509_create.c.gcov.html new file mode 100644 index 00000000000..922601d3953 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509_create.c.gcov.html @@ -0,0 +1,649 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/x509_create.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - x509_create.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:12220061.0 %
Date:2024-09-22 08:21:07Functions:91275.0 %
Branches:6516439.6 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  *  X.509 base functions for creating certificates / CSRs
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  */
+       7                 :            : 
+       8                 :            : #include "common.h"
+       9                 :            : 
+      10                 :            : #if defined(MBEDTLS_X509_CREATE_C)
+      11                 :            : 
+      12                 :            : #include "x509_internal.h"
+      13                 :            : #include "mbedtls/asn1write.h"
+      14                 :            : #include "mbedtls/error.h"
+      15                 :            : #include "mbedtls/oid.h"
+      16                 :            : 
+      17                 :            : #include <string.h>
+      18                 :            : 
+      19                 :            : #include "mbedtls/platform.h"
+      20                 :            : 
+      21                 :            : #include "mbedtls/asn1.h"
+      22                 :            : 
+      23                 :            : /* Structure linking OIDs for X.509 DN AttributeTypes to their
+      24                 :            :  * string representations and default string encodings used by Mbed TLS. */
+      25                 :            : typedef struct {
+      26                 :            :     const char *name; /* String representation of AttributeType, e.g.
+      27                 :            :                        * "CN" or "emailAddress". */
+      28                 :            :     size_t name_len; /* Length of 'name', without trailing 0 byte. */
+      29                 :            :     const char *oid; /* String representation of OID of AttributeType,
+      30                 :            :                       * as per RFC 5280, Appendix A.1. encoded as per
+      31                 :            :                       * X.690 */
+      32                 :            :     int default_tag; /* The default character encoding used for the
+      33                 :            :                       * given attribute type, e.g.
+      34                 :            :                       * MBEDTLS_ASN1_UTF8_STRING for UTF-8. */
+      35                 :            : } x509_attr_descriptor_t;
+      36                 :            : 
+      37                 :            : #define ADD_STRLEN(s)     s, sizeof(s) - 1
+      38                 :            : 
+      39                 :            : /* X.509 DN attributes from RFC 5280, Appendix A.1. */
+      40                 :            : static const x509_attr_descriptor_t x509_attrs[] =
+      41                 :            : {
+      42                 :            :     { ADD_STRLEN("CN"),
+      43                 :            :       MBEDTLS_OID_AT_CN, MBEDTLS_ASN1_UTF8_STRING },
+      44                 :            :     { ADD_STRLEN("commonName"),
+      45                 :            :       MBEDTLS_OID_AT_CN, MBEDTLS_ASN1_UTF8_STRING },
+      46                 :            :     { ADD_STRLEN("C"),
+      47                 :            :       MBEDTLS_OID_AT_COUNTRY, MBEDTLS_ASN1_PRINTABLE_STRING },
+      48                 :            :     { ADD_STRLEN("countryName"),
+      49                 :            :       MBEDTLS_OID_AT_COUNTRY, MBEDTLS_ASN1_PRINTABLE_STRING },
+      50                 :            :     { ADD_STRLEN("O"),
+      51                 :            :       MBEDTLS_OID_AT_ORGANIZATION, MBEDTLS_ASN1_UTF8_STRING },
+      52                 :            :     { ADD_STRLEN("organizationName"),
+      53                 :            :       MBEDTLS_OID_AT_ORGANIZATION, MBEDTLS_ASN1_UTF8_STRING },
+      54                 :            :     { ADD_STRLEN("L"),
+      55                 :            :       MBEDTLS_OID_AT_LOCALITY, MBEDTLS_ASN1_UTF8_STRING },
+      56                 :            :     { ADD_STRLEN("locality"),
+      57                 :            :       MBEDTLS_OID_AT_LOCALITY, MBEDTLS_ASN1_UTF8_STRING },
+      58                 :            :     { ADD_STRLEN("R"),
+      59                 :            :       MBEDTLS_OID_PKCS9_EMAIL, MBEDTLS_ASN1_IA5_STRING },
+      60                 :            :     { ADD_STRLEN("OU"),
+      61                 :            :       MBEDTLS_OID_AT_ORG_UNIT, MBEDTLS_ASN1_UTF8_STRING },
+      62                 :            :     { ADD_STRLEN("organizationalUnitName"),
+      63                 :            :       MBEDTLS_OID_AT_ORG_UNIT, MBEDTLS_ASN1_UTF8_STRING },
+      64                 :            :     { ADD_STRLEN("ST"),
+      65                 :            :       MBEDTLS_OID_AT_STATE, MBEDTLS_ASN1_UTF8_STRING },
+      66                 :            :     { ADD_STRLEN("stateOrProvinceName"),
+      67                 :            :       MBEDTLS_OID_AT_STATE, MBEDTLS_ASN1_UTF8_STRING },
+      68                 :            :     { ADD_STRLEN("emailAddress"),
+      69                 :            :       MBEDTLS_OID_PKCS9_EMAIL, MBEDTLS_ASN1_IA5_STRING },
+      70                 :            :     { ADD_STRLEN("serialNumber"),
+      71                 :            :       MBEDTLS_OID_AT_SERIAL_NUMBER, MBEDTLS_ASN1_PRINTABLE_STRING },
+      72                 :            :     { ADD_STRLEN("postalAddress"),
+      73                 :            :       MBEDTLS_OID_AT_POSTAL_ADDRESS, MBEDTLS_ASN1_PRINTABLE_STRING },
+      74                 :            :     { ADD_STRLEN("postalCode"),
+      75                 :            :       MBEDTLS_OID_AT_POSTAL_CODE, MBEDTLS_ASN1_PRINTABLE_STRING },
+      76                 :            :     { ADD_STRLEN("dnQualifier"),
+      77                 :            :       MBEDTLS_OID_AT_DN_QUALIFIER, MBEDTLS_ASN1_PRINTABLE_STRING },
+      78                 :            :     { ADD_STRLEN("title"),
+      79                 :            :       MBEDTLS_OID_AT_TITLE, MBEDTLS_ASN1_UTF8_STRING },
+      80                 :            :     { ADD_STRLEN("surName"),
+      81                 :            :       MBEDTLS_OID_AT_SUR_NAME, MBEDTLS_ASN1_UTF8_STRING },
+      82                 :            :     { ADD_STRLEN("SN"),
+      83                 :            :       MBEDTLS_OID_AT_SUR_NAME, MBEDTLS_ASN1_UTF8_STRING },
+      84                 :            :     { ADD_STRLEN("givenName"),
+      85                 :            :       MBEDTLS_OID_AT_GIVEN_NAME, MBEDTLS_ASN1_UTF8_STRING },
+      86                 :            :     { ADD_STRLEN("GN"),
+      87                 :            :       MBEDTLS_OID_AT_GIVEN_NAME, MBEDTLS_ASN1_UTF8_STRING },
+      88                 :            :     { ADD_STRLEN("initials"),
+      89                 :            :       MBEDTLS_OID_AT_INITIALS, MBEDTLS_ASN1_UTF8_STRING },
+      90                 :            :     { ADD_STRLEN("pseudonym"),
+      91                 :            :       MBEDTLS_OID_AT_PSEUDONYM, MBEDTLS_ASN1_UTF8_STRING },
+      92                 :            :     { ADD_STRLEN("generationQualifier"),
+      93                 :            :       MBEDTLS_OID_AT_GENERATION_QUALIFIER, MBEDTLS_ASN1_UTF8_STRING },
+      94                 :            :     { ADD_STRLEN("domainComponent"),
+      95                 :            :       MBEDTLS_OID_DOMAIN_COMPONENT, MBEDTLS_ASN1_IA5_STRING },
+      96                 :            :     { ADD_STRLEN("DC"),
+      97                 :            :       MBEDTLS_OID_DOMAIN_COMPONENT,   MBEDTLS_ASN1_IA5_STRING },
+      98                 :            :     { NULL, 0, NULL, MBEDTLS_ASN1_NULL }
+      99                 :            : };
+     100                 :            : 
+     101                 :         24 : static const x509_attr_descriptor_t *x509_attr_descr_from_name(const char *name, size_t name_len)
+     102                 :            : {
+     103                 :            :     const x509_attr_descriptor_t *cur;
+     104                 :            : 
+     105         [ +  - ]:         94 :     for (cur = x509_attrs; cur->name != NULL; cur++) {
+     106         [ +  + ]:         94 :         if (cur->name_len == name_len &&
+     107         [ +  + ]:         36 :             strncmp(cur->name, name, name_len) == 0) {
+     108                 :         24 :             break;
+     109                 :            :         }
+     110                 :            :     }
+     111                 :            : 
+     112         [ -  + ]:         24 :     if (cur->name == NULL) {
+     113                 :          0 :         return NULL;
+     114                 :            :     }
+     115                 :            : 
+     116                 :         24 :     return cur;
+     117                 :            : }
+     118                 :            : 
+     119                 :          0 : static int hex_to_int(char c)
+     120                 :            : {
+     121   [ #  #  #  # ]:          0 :     return ('0' <= c && c <= '9') ? (c - '0') :
+     122   [ #  #  #  # ]:          0 :            ('a' <= c && c <= 'f') ? (c - 'a' + 10) :
+     123   [ #  #  #  # ]:          0 :            ('A' <= c && c <= 'F') ? (c - 'A' + 10) : -1;
+     124                 :            : }
+     125                 :            : 
+     126                 :          0 : static int hexpair_to_int(const char *hexpair)
+     127                 :            : {
+     128                 :          0 :     int n1 = hex_to_int(*hexpair);
+     129                 :          0 :     int n2 = hex_to_int(*(hexpair + 1));
+     130                 :            : 
+     131   [ #  #  #  # ]:          0 :     if (n1 != -1 && n2 != -1) {
+     132                 :          0 :         return (n1 << 4) | n2;
+     133                 :            :     } else {
+     134                 :          0 :         return -1;
+     135                 :            :     }
+     136                 :            : }
+     137                 :            : 
+     138                 :         24 : static int parse_attribute_value_string(const char *s,
+     139                 :            :                                         int len,
+     140                 :            :                                         unsigned char *data,
+     141                 :            :                                         size_t *data_len)
+     142                 :            : {
+     143                 :            :     const char *c;
+     144                 :         24 :     const char *end = s + len;
+     145                 :         24 :     unsigned char *d = data;
+     146                 :            :     int n;
+     147                 :            : 
+     148         [ +  + ]:        258 :     for (c = s; c < end; c++) {
+     149         [ -  + ]:        234 :         if (*c == '\\') {
+     150                 :          0 :             c++;
+     151                 :            : 
+     152                 :            :             /* Check for valid escaped characters as per RFC 4514 Section 3 */
+     153   [ #  #  #  # ]:          0 :             if (c + 1 < end && (n = hexpair_to_int(c)) != -1) {
+     154         [ #  # ]:          0 :                 if (n == 0) {
+     155                 :          0 :                     return MBEDTLS_ERR_X509_INVALID_NAME;
+     156                 :            :                 }
+     157                 :          0 :                 *(d++) = n;
+     158                 :          0 :                 c++;
+     159   [ #  #  #  # ]:          0 :             } else if (c < end && strchr(" ,=+<>#;\"\\", *c)) {
+     160                 :          0 :                 *(d++) = *c;
+     161                 :            :             } else {
+     162                 :          0 :                 return MBEDTLS_ERR_X509_INVALID_NAME;
+     163                 :            :             }
+     164                 :            :         } else {
+     165                 :        234 :             *(d++) = *c;
+     166                 :            :         }
+     167                 :            : 
+     168         [ -  + ]:        234 :         if (d - data == MBEDTLS_X509_MAX_DN_NAME_SIZE) {
+     169                 :          0 :             return MBEDTLS_ERR_X509_INVALID_NAME;
+     170                 :            :         }
+     171                 :            :     }
+     172                 :         24 :     *data_len = (size_t) (d - data);
+     173                 :         24 :     return 0;
+     174                 :            : }
+     175                 :            : 
+     176                 :            : /** Parse a hexstring containing a DER-encoded string.
+     177                 :            :  *
+     178                 :            :  * \param s         A string of \p len bytes hexadecimal digits.
+     179                 :            :  * \param len       Number of bytes to read from \p s.
+     180                 :            :  * \param data      Output buffer of size \p data_size.
+     181                 :            :  *                  On success, it contains the payload that's DER-encoded
+     182                 :            :  *                  in the input (content without the tag and length).
+     183                 :            :  *                  If the DER tag is a string tag, the payload is guaranteed
+     184                 :            :  *                  not to contain null bytes.
+     185                 :            :  * \param data_size Length of the \p data buffer.
+     186                 :            :  * \param data_len  On success, the length of the parsed string.
+     187                 :            :  *                  It is guaranteed to be less than
+     188                 :            :  *                  #MBEDTLS_X509_MAX_DN_NAME_SIZE.
+     189                 :            :  * \param tag       The ASN.1 tag that the payload in \p data is encoded in.
+     190                 :            :  *
+     191                 :            :  * \retval          0 on success.
+     192                 :            :  * \retval          #MBEDTLS_ERR_X509_INVALID_NAME if \p s does not contain
+     193                 :            :  *                  a valid hexstring,
+     194                 :            :  *                  or if the decoded hexstring is not valid DER,
+     195                 :            :  *                  or if the payload does not fit in \p data,
+     196                 :            :  *                  or if the payload is more than
+     197                 :            :  *                  #MBEDTLS_X509_MAX_DN_NAME_SIZE bytes,
+     198                 :            :  *                  of if \p *tag is an ASN.1 string tag and the payload
+     199                 :            :  *                  contains a null byte.
+     200                 :            :  * \retval          #MBEDTLS_ERR_X509_ALLOC_FAILED on low memory.
+     201                 :            :  */
+     202                 :          0 : static int parse_attribute_value_hex_der_encoded(const char *s,
+     203                 :            :                                                  size_t len,
+     204                 :            :                                                  unsigned char *data,
+     205                 :            :                                                  size_t data_size,
+     206                 :            :                                                  size_t *data_len,
+     207                 :            :                                                  int *tag)
+     208                 :            : {
+     209                 :            :     /* Step 1: preliminary length checks. */
+     210                 :            :     /* Each byte is encoded by exactly two hexadecimal digits. */
+     211         [ #  # ]:          0 :     if (len % 2 != 0) {
+     212                 :            :         /* Odd number of hex digits */
+     213                 :          0 :         return MBEDTLS_ERR_X509_INVALID_NAME;
+     214                 :            :     }
+     215                 :          0 :     size_t const der_length = len / 2;
+     216         [ #  # ]:          0 :     if (der_length > MBEDTLS_X509_MAX_DN_NAME_SIZE + 4) {
+     217                 :            :         /* The payload would be more than MBEDTLS_X509_MAX_DN_NAME_SIZE
+     218                 :            :          * (after subtracting the ASN.1 tag and length). Reject this early
+     219                 :            :          * to avoid allocating a large intermediate buffer. */
+     220                 :          0 :         return MBEDTLS_ERR_X509_INVALID_NAME;
+     221                 :            :     }
+     222         [ #  # ]:          0 :     if (der_length < 1) {
+     223                 :            :         /* Avoid empty-buffer shenanigans. A valid DER encoding is never
+     224                 :            :          * empty. */
+     225                 :          0 :         return MBEDTLS_ERR_X509_INVALID_NAME;
+     226                 :            :     }
+     227                 :            : 
+     228                 :            :     /* Step 2: Decode the hex string into an intermediate buffer. */
+     229                 :          0 :     unsigned char *der = mbedtls_calloc(1, der_length);
+     230         [ #  # ]:          0 :     if (der == NULL) {
+     231                 :          0 :         return MBEDTLS_ERR_X509_ALLOC_FAILED;
+     232                 :            :     }
+     233                 :            :     /* Beyond this point, der needs to be freed on exit. */
+     234         [ #  # ]:          0 :     for (size_t i = 0; i < der_length; i++) {
+     235                 :          0 :         int c = hexpair_to_int(s + 2 * i);
+     236         [ #  # ]:          0 :         if (c < 0) {
+     237                 :          0 :             goto error;
+     238                 :            :         }
+     239                 :          0 :         der[i] = c;
+     240                 :            :     }
+     241                 :            : 
+     242                 :            :     /* Step 3: decode the DER. */
+     243                 :            :     /* We've checked that der_length >= 1 above. */
+     244                 :          0 :     *tag = der[0];
+     245                 :            :     {
+     246                 :          0 :         unsigned char *p = der + 1;
+     247         [ #  # ]:          0 :         if (mbedtls_asn1_get_len(&p, der + der_length, data_len) != 0) {
+     248                 :          0 :             goto error;
+     249                 :            :         }
+     250                 :            :         /* Now p points to the first byte of the payload inside der,
+     251                 :            :          * and *data_len is the length of the payload. */
+     252                 :            : 
+     253                 :            :         /* Step 4: payload validation */
+     254         [ #  # ]:          0 :         if (*data_len > MBEDTLS_X509_MAX_DN_NAME_SIZE) {
+     255                 :          0 :             goto error;
+     256                 :            :         }
+     257                 :            :         /* Strings must not contain null bytes. */
+     258   [ #  #  #  # ]:          0 :         if (MBEDTLS_ASN1_IS_STRING_TAG(*tag)) {
+     259         [ #  # ]:          0 :             for (size_t i = 0; i < *data_len; i++) {
+     260         [ #  # ]:          0 :                 if (p[i] == 0) {
+     261                 :          0 :                     goto error;
+     262                 :            :                 }
+     263                 :            :             }
+     264                 :            :         }
+     265                 :            : 
+     266                 :            :         /* Step 5: output the payload. */
+     267         [ #  # ]:          0 :         if (*data_len > data_size) {
+     268                 :          0 :             goto error;
+     269                 :            :         }
+     270                 :          0 :         memcpy(data, p, *data_len);
+     271                 :            :     }
+     272                 :          0 :     mbedtls_free(der);
+     273                 :            : 
+     274                 :          0 :     return 0;
+     275                 :            : 
+     276                 :          0 : error:
+     277                 :          0 :     mbedtls_free(der);
+     278                 :          0 :     return MBEDTLS_ERR_X509_INVALID_NAME;
+     279                 :            : }
+     280                 :            : 
+     281                 :          8 : int mbedtls_x509_string_to_names(mbedtls_asn1_named_data **head, const char *name)
+     282                 :            : {
+     283                 :          8 :     int ret = MBEDTLS_ERR_X509_INVALID_NAME;
+     284                 :          8 :     int parse_ret = 0;
+     285                 :          8 :     const char *s = name, *c = s;
+     286                 :          8 :     const char *end = s + strlen(s);
+     287                 :          8 :     mbedtls_asn1_buf oid = { .p = NULL, .len = 0, .tag = MBEDTLS_ASN1_NULL };
+     288                 :          8 :     const x509_attr_descriptor_t *attr_descr = NULL;
+     289                 :          8 :     int in_attr_type = 1;
+     290                 :            :     int tag;
+     291                 :          8 :     int numericoid = 0;
+     292                 :            :     unsigned char data[MBEDTLS_X509_MAX_DN_NAME_SIZE];
+     293                 :          8 :     size_t data_len = 0;
+     294                 :            : 
+     295                 :            :     /* Clear existing chain if present */
+     296                 :          8 :     mbedtls_asn1_free_named_data_list(head);
+     297                 :            : 
+     298         [ +  + ]:        324 :     while (c <= end) {
+     299   [ +  +  +  + ]:        316 :         if (in_attr_type && *c == '=') {
+     300         [ -  + ]:         24 :             if ((attr_descr = x509_attr_descr_from_name(s, (size_t) (c - s))) == NULL) {
+     301         [ #  # ]:          0 :                 if ((mbedtls_oid_from_numeric_string(&oid, s, (size_t) (c - s))) != 0) {
+     302                 :          0 :                     return MBEDTLS_ERR_X509_INVALID_NAME;
+     303                 :            :                 } else {
+     304                 :          0 :                     numericoid = 1;
+     305                 :            :                 }
+     306                 :            :             } else {
+     307                 :         24 :                 oid.len = strlen(attr_descr->oid);
+     308                 :         24 :                 oid.p = mbedtls_calloc(1, oid.len);
+     309                 :         24 :                 memcpy(oid.p, attr_descr->oid, oid.len);
+     310                 :         24 :                 numericoid = 0;
+     311                 :            :             }
+     312                 :            : 
+     313                 :         24 :             s = c + 1;
+     314                 :         24 :             in_attr_type = 0;
+     315                 :            :         }
+     316                 :            : 
+     317   [ +  +  +  +  :        316 :         if (!in_attr_type && ((*c == ',' && *(c-1) != '\\') || c == end)) {
+             -  +  +  + ]
+     318         [ -  + ]:         24 :             if (s == c) {
+     319                 :          0 :                 mbedtls_free(oid.p);
+     320                 :          0 :                 return MBEDTLS_ERR_X509_INVALID_NAME;
+     321         [ -  + ]:         24 :             } else if (*s == '#') {
+     322                 :            :                 /* We know that c >= s (loop invariant) and c != s (in this
+     323                 :            :                  * else branch), hence c - s - 1 >= 0. */
+     324                 :          0 :                 parse_ret = parse_attribute_value_hex_der_encoded(
+     325                 :          0 :                     s + 1, (size_t) (c - s) - 1,
+     326                 :            :                     data, sizeof(data), &data_len, &tag);
+     327         [ #  # ]:          0 :                 if (parse_ret != 0) {
+     328                 :          0 :                     mbedtls_free(oid.p);
+     329                 :          0 :                     return parse_ret;
+     330                 :            :                 }
+     331                 :            :             } else {
+     332         [ -  + ]:         24 :                 if (numericoid) {
+     333                 :          0 :                     mbedtls_free(oid.p);
+     334                 :          0 :                     return MBEDTLS_ERR_X509_INVALID_NAME;
+     335                 :            :                 } else {
+     336         [ -  + ]:         24 :                     if ((parse_ret =
+     337                 :         24 :                              parse_attribute_value_string(s, (int) (c - s), data,
+     338                 :            :                                                           &data_len)) != 0) {
+     339                 :          0 :                         mbedtls_free(oid.p);
+     340                 :          0 :                         return parse_ret;
+     341                 :            :                     }
+     342                 :         24 :                     tag = attr_descr->default_tag;
+     343                 :            :                 }
+     344                 :            :             }
+     345                 :            : 
+     346                 :            :             mbedtls_asn1_named_data *cur =
+     347                 :         24 :                 mbedtls_asn1_store_named_data(head, (char *) oid.p, oid.len,
+     348                 :            :                                               (unsigned char *) data,
+     349                 :            :                                               data_len);
+     350                 :         24 :             mbedtls_free(oid.p);
+     351                 :         24 :             oid.p = NULL;
+     352         [ -  + ]:         24 :             if (cur == NULL) {
+     353                 :          0 :                 return MBEDTLS_ERR_X509_ALLOC_FAILED;
+     354                 :            :             }
+     355                 :            : 
+     356                 :            :             // set tagType
+     357                 :         24 :             cur->val.tag = tag;
+     358                 :            : 
+     359   [ +  +  -  + ]:         24 :             while (c < end && *(c + 1) == ' ') {
+     360                 :          0 :                 c++;
+     361                 :            :             }
+     362                 :            : 
+     363                 :         24 :             s = c + 1;
+     364                 :         24 :             in_attr_type = 1;
+     365                 :            : 
+     366                 :            :             /* Successfully parsed one name, update ret to success */
+     367                 :         24 :             ret = 0;
+     368                 :            :         }
+     369                 :        316 :         c++;
+     370                 :            :     }
+     371         [ -  + ]:          8 :     if (oid.p != NULL) {
+     372                 :          0 :         mbedtls_free(oid.p);
+     373                 :            :     }
+     374                 :          8 :     return ret;
+     375                 :            : }
+     376                 :            : 
+     377                 :            : /* The first byte of the value in the mbedtls_asn1_named_data structure is reserved
+     378                 :            :  * to store the critical boolean for us
+     379                 :            :  */
+     380                 :         38 : int mbedtls_x509_set_extension(mbedtls_asn1_named_data **head, const char *oid, size_t oid_len,
+     381                 :            :                                int critical, const unsigned char *val, size_t val_len)
+     382                 :            : {
+     383                 :            :     mbedtls_asn1_named_data *cur;
+     384                 :            : 
+     385         [ -  + ]:         38 :     if (val_len > (SIZE_MAX  - 1)) {
+     386                 :          0 :         return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
+     387                 :            :     }
+     388                 :            : 
+     389         [ -  + ]:         38 :     if ((cur = mbedtls_asn1_store_named_data(head, oid, oid_len,
+     390                 :            :                                              NULL, val_len + 1)) == NULL) {
+     391                 :          0 :         return MBEDTLS_ERR_X509_ALLOC_FAILED;
+     392                 :            :     }
+     393                 :            : 
+     394                 :         38 :     cur->val.p[0] = critical;
+     395                 :         38 :     memcpy(cur->val.p + 1, val, val_len);
+     396                 :            : 
+     397                 :         38 :     return 0;
+     398                 :            : }
+     399                 :            : 
+     400                 :            : /*
+     401                 :            :  *  RelativeDistinguishedName ::=
+     402                 :            :  *    SET OF AttributeTypeAndValue
+     403                 :            :  *
+     404                 :            :  *  AttributeTypeAndValue ::= SEQUENCE {
+     405                 :            :  *    type     AttributeType,
+     406                 :            :  *    value    AttributeValue }
+     407                 :            :  *
+     408                 :            :  *  AttributeType ::= OBJECT IDENTIFIER
+     409                 :            :  *
+     410                 :            :  *  AttributeValue ::= ANY DEFINED BY AttributeType
+     411                 :            :  */
+     412                 :         18 : static int x509_write_name(unsigned char **p,
+     413                 :            :                            unsigned char *start,
+     414                 :            :                            mbedtls_asn1_named_data *cur_name)
+     415                 :            : {
+     416                 :         18 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     417                 :         18 :     size_t len = 0;
+     418                 :         18 :     const char *oid             = (const char *) cur_name->oid.p;
+     419                 :         18 :     size_t oid_len              = cur_name->oid.len;
+     420                 :         18 :     const unsigned char *name   = cur_name->val.p;
+     421                 :         18 :     size_t name_len             = cur_name->val.len;
+     422                 :            : 
+     423                 :            :     // Write correct string tag and value
+     424         [ -  + ]:         18 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tagged_string(p, start,
+     425                 :            :                                                                cur_name->val.tag,
+     426                 :            :                                                                (const char *) name,
+     427                 :            :                                                                name_len));
+     428                 :            :     // Write OID
+     429                 :            :     //
+     430         [ -  + ]:         18 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_oid(p, start, oid,
+     431                 :            :                                                      oid_len));
+     432                 :            : 
+     433         [ -  + ]:         18 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(p, start, len));
+     434         [ -  + ]:         18 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(p, start,
+     435                 :            :                                                      MBEDTLS_ASN1_CONSTRUCTED |
+     436                 :            :                                                      MBEDTLS_ASN1_SEQUENCE));
+     437                 :            : 
+     438         [ -  + ]:         18 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(p, start, len));
+     439         [ -  + ]:         18 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(p, start,
+     440                 :            :                                                      MBEDTLS_ASN1_CONSTRUCTED |
+     441                 :            :                                                      MBEDTLS_ASN1_SET));
+     442                 :            : 
+     443                 :         18 :     return (int) len;
+     444                 :            : }
+     445                 :            : 
+     446                 :          6 : int mbedtls_x509_write_names(unsigned char **p, unsigned char *start,
+     447                 :            :                              mbedtls_asn1_named_data *first)
+     448                 :            : {
+     449                 :          6 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     450                 :          6 :     size_t len = 0;
+     451                 :          6 :     mbedtls_asn1_named_data *cur = first;
+     452                 :            : 
+     453         [ +  + ]:         24 :     while (cur != NULL) {
+     454         [ -  + ]:         18 :         MBEDTLS_ASN1_CHK_ADD(len, x509_write_name(p, start, cur));
+     455                 :         18 :         cur = cur->next;
+     456                 :            :     }
+     457                 :            : 
+     458         [ -  + ]:          6 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(p, start, len));
+     459         [ -  + ]:          6 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(p, start, MBEDTLS_ASN1_CONSTRUCTED |
+     460                 :            :                                                      MBEDTLS_ASN1_SEQUENCE));
+     461                 :            : 
+     462                 :          6 :     return (int) len;
+     463                 :            : }
+     464                 :            : 
+     465                 :          6 : int mbedtls_x509_write_sig(unsigned char **p, unsigned char *start,
+     466                 :            :                            const char *oid, size_t oid_len,
+     467                 :            :                            unsigned char *sig, size_t size,
+     468                 :            :                            mbedtls_pk_type_t pk_alg)
+     469                 :            : {
+     470                 :          6 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     471                 :            :     int write_null_par;
+     472                 :          6 :     size_t len = 0;
+     473                 :            : 
+     474   [ +  -  -  + ]:          6 :     if (*p < start || (size_t) (*p - start) < size) {
+     475                 :          0 :         return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL;
+     476                 :            :     }
+     477                 :            : 
+     478                 :          6 :     len = size;
+     479                 :          6 :     (*p) -= len;
+     480                 :          6 :     memcpy(*p, sig, len);
+     481                 :            : 
+     482         [ -  + ]:          6 :     if (*p - start < 1) {
+     483                 :          0 :         return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL;
+     484                 :            :     }
+     485                 :            : 
+     486                 :          6 :     *--(*p) = 0;
+     487                 :          6 :     len += 1;
+     488                 :            : 
+     489         [ -  + ]:          6 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(p, start, len));
+     490         [ -  + ]:          6 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(p, start, MBEDTLS_ASN1_BIT_STRING));
+     491                 :            : 
+     492                 :            :     // Write OID
+     493                 :            :     //
+     494         [ +  - ]:          6 :     if (pk_alg == MBEDTLS_PK_ECDSA) {
+     495                 :            :         /*
+     496                 :            :          * The AlgorithmIdentifier's parameters field must be absent for DSA/ECDSA signature
+     497                 :            :          * algorithms, see https://www.rfc-editor.org/rfc/rfc5480#page-17 and
+     498                 :            :          * https://www.rfc-editor.org/rfc/rfc5758#section-3.
+     499                 :            :          */
+     500                 :          6 :         write_null_par = 0;
+     501                 :            :     } else {
+     502                 :          0 :         write_null_par = 1;
+     503                 :            :     }
+     504         [ -  + ]:          6 :     MBEDTLS_ASN1_CHK_ADD(len,
+     505                 :            :                          mbedtls_asn1_write_algorithm_identifier_ext(p, start, oid, oid_len,
+     506                 :            :                                                                      0, write_null_par));
+     507                 :            : 
+     508                 :          6 :     return (int) len;
+     509                 :            : }
+     510                 :            : 
+     511                 :         38 : static int x509_write_extension(unsigned char **p, unsigned char *start,
+     512                 :            :                                 mbedtls_asn1_named_data *ext)
+     513                 :            : {
+     514                 :         38 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     515                 :         38 :     size_t len = 0;
+     516                 :            : 
+     517         [ -  + ]:         38 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_raw_buffer(p, start, ext->val.p + 1,
+     518                 :            :                                                             ext->val.len - 1));
+     519         [ -  + ]:         38 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(p, start, ext->val.len - 1));
+     520         [ -  + ]:         38 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(p, start, MBEDTLS_ASN1_OCTET_STRING));
+     521                 :            : 
+     522         [ -  + ]:         38 :     if (ext->val.p[0] != 0) {
+     523         [ #  # ]:          0 :         MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_bool(p, start, 1));
+     524                 :            :     }
+     525                 :            : 
+     526         [ -  + ]:         38 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_raw_buffer(p, start, ext->oid.p,
+     527                 :            :                                                             ext->oid.len));
+     528         [ -  + ]:         38 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(p, start, ext->oid.len));
+     529         [ -  + ]:         38 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(p, start, MBEDTLS_ASN1_OID));
+     530                 :            : 
+     531         [ -  + ]:         38 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(p, start, len));
+     532         [ -  + ]:         38 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(p, start, MBEDTLS_ASN1_CONSTRUCTED |
+     533                 :            :                                                      MBEDTLS_ASN1_SEQUENCE));
+     534                 :            : 
+     535                 :         38 :     return (int) len;
+     536                 :            : }
+     537                 :            : 
+     538                 :            : /*
+     539                 :            :  * Extension  ::=  SEQUENCE  {
+     540                 :            :  *     extnID      OBJECT IDENTIFIER,
+     541                 :            :  *     critical    BOOLEAN DEFAULT FALSE,
+     542                 :            :  *     extnValue   OCTET STRING
+     543                 :            :  *                 -- contains the DER encoding of an ASN.1 value
+     544                 :            :  *                 -- corresponding to the extension type identified
+     545                 :            :  *                 -- by extnID
+     546                 :            :  *     }
+     547                 :            :  */
+     548                 :          6 : int mbedtls_x509_write_extensions(unsigned char **p, unsigned char *start,
+     549                 :            :                                   mbedtls_asn1_named_data *first)
+     550                 :            : {
+     551                 :          6 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     552                 :          6 :     size_t len = 0;
+     553                 :          6 :     mbedtls_asn1_named_data *cur_ext = first;
+     554                 :            : 
+     555         [ +  + ]:         44 :     while (cur_ext != NULL) {
+     556         [ -  + ]:         38 :         MBEDTLS_ASN1_CHK_ADD(len, x509_write_extension(p, start, cur_ext));
+     557                 :         38 :         cur_ext = cur_ext->next;
+     558                 :            :     }
+     559                 :            : 
+     560                 :          6 :     return (int) len;
+     561                 :            : }
+     562                 :            : 
+     563                 :            : #endif /* MBEDTLS_X509_CREATE_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509_crt.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509_crt.c.func-sort-c.html new file mode 100644 index 00000000000..eaa3674ea20 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509_crt.c.func-sort-c.html @@ -0,0 +1,301 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/x509_crt.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - x509_crt.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:448100444.6 %
Date:2024-09-22 08:21:07Functions:325558.2 %
Branches:24080130.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_x509_crt_check_extended_key_usage0
mbedtls_x509_crt_get_ca_istrue0
mbedtls_x509_crt_info0
mbedtls_x509_crt_is_revoked0
mbedtls_x509_crt_parse0
mbedtls_x509_crt_parse_cn_inet_pton0
mbedtls_x509_crt_parse_der_nocopy0
mbedtls_x509_crt_parse_der_with_ext_cb0
mbedtls_x509_crt_restart_free0
mbedtls_x509_crt_restart_init0
mbedtls_x509_crt_verify0
mbedtls_x509_crt_verify_info0
mbedtls_x509_crt_verify_restartable0
x509_check_wildcard0
x509_crt_check_cn0
x509_crt_check_san0
x509_crt_check_san_ip0
x509_crt_check_san_uri0
x509_crt_verify_name0
x509_inet_pton_ipv40
x509_inet_pton_ipv60
x509_info_cert_policies0
x509_info_ext_key_usage0
x509_get_certificate_policies40
x509_memcasecmp175
x509_crt_verifycrl1586
mbedtls_x509_crt_check_key_usage1588
x509_crt_check_parent1588
x509_crt_check_signature1588
x509_crt_find_parent1588
x509_crt_find_parent_in1590
x509_get_authority_key_id2190
mbedtls_x509_crt_verify_with_profile2255
x509_crt_check_ee_locally_trusted2255
x509_crt_merge_flags_with_cb2255
x509_crt_verify_chain2255
x509_crt_verify_chain_reset2255
x509_crt_verify_restartable_ca_cb2255
x509_profile_check_md_alg2255
x509_profile_check_key3841
x509_name_cmp3843
x509_string_cmp3843
x509_profile_check_pk_alg4510
x509_get_ext_key_usage9975
x509_get_basic_constraints12105
mbedtls_x509_crt_free12119
mbedtls_x509_crt_init12125
mbedtls_x509_crt_parse_der12125
mbedtls_x509_crt_parse_der_internal12125
x509_crt_parse_der_core12125
x509_get_crt_ext12125
x509_get_dates12125
x509_get_subject_key_id12125
x509_get_version12125
x509_get_uid24250
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509_crt.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509_crt.c.func.html new file mode 100644 index 00000000000..ee3ca83cbb6 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509_crt.c.func.html @@ -0,0 +1,301 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/x509_crt.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - x509_crt.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:448100444.6 %
Date:2024-09-22 08:21:07Functions:325558.2 %
Branches:24080130.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_x509_crt_check_extended_key_usage0
mbedtls_x509_crt_check_key_usage1588
mbedtls_x509_crt_free12119
mbedtls_x509_crt_get_ca_istrue0
mbedtls_x509_crt_info0
mbedtls_x509_crt_init12125
mbedtls_x509_crt_is_revoked0
mbedtls_x509_crt_parse0
mbedtls_x509_crt_parse_cn_inet_pton0
mbedtls_x509_crt_parse_der12125
mbedtls_x509_crt_parse_der_internal12125
mbedtls_x509_crt_parse_der_nocopy0
mbedtls_x509_crt_parse_der_with_ext_cb0
mbedtls_x509_crt_restart_free0
mbedtls_x509_crt_restart_init0
mbedtls_x509_crt_verify0
mbedtls_x509_crt_verify_info0
mbedtls_x509_crt_verify_restartable0
mbedtls_x509_crt_verify_with_profile2255
x509_check_wildcard0
x509_crt_check_cn0
x509_crt_check_ee_locally_trusted2255
x509_crt_check_parent1588
x509_crt_check_san0
x509_crt_check_san_ip0
x509_crt_check_san_uri0
x509_crt_check_signature1588
x509_crt_find_parent1588
x509_crt_find_parent_in1590
x509_crt_merge_flags_with_cb2255
x509_crt_parse_der_core12125
x509_crt_verify_chain2255
x509_crt_verify_chain_reset2255
x509_crt_verify_name0
x509_crt_verify_restartable_ca_cb2255
x509_crt_verifycrl1586
x509_get_authority_key_id2190
x509_get_basic_constraints12105
x509_get_certificate_policies40
x509_get_crt_ext12125
x509_get_dates12125
x509_get_ext_key_usage9975
x509_get_subject_key_id12125
x509_get_uid24250
x509_get_version12125
x509_inet_pton_ipv40
x509_inet_pton_ipv60
x509_info_cert_policies0
x509_info_ext_key_usage0
x509_memcasecmp175
x509_name_cmp3843
x509_profile_check_key3841
x509_profile_check_md_alg2255
x509_profile_check_pk_alg4510
x509_string_cmp3843
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509_crt.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509_crt.c.gcov.html new file mode 100644 index 00000000000..d9bc26a4da6 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509_crt.c.gcov.html @@ -0,0 +1,3394 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/x509_crt.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - x509_crt.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:448100444.6 %
Date:2024-09-22 08:21:07Functions:325558.2 %
Branches:24080130.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  *  X.509 certificate parsing and verification
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  */
+       7                 :            : /*
+       8                 :            :  *  The ITU-T X.509 standard defines a certificate format for PKI.
+       9                 :            :  *
+      10                 :            :  *  http://www.ietf.org/rfc/rfc5280.txt (Certificates and CRLs)
+      11                 :            :  *  http://www.ietf.org/rfc/rfc3279.txt (Alg IDs for CRLs)
+      12                 :            :  *  http://www.ietf.org/rfc/rfc2986.txt (CSRs, aka PKCS#10)
+      13                 :            :  *
+      14                 :            :  *  http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf
+      15                 :            :  *  http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf
+      16                 :            :  *
+      17                 :            :  *  [SIRO] https://cabforum.org/wp-content/uploads/Chunghwatelecom201503cabforumV4.pdf
+      18                 :            :  */
+      19                 :            : 
+      20                 :            : #include "common.h"
+      21                 :            : 
+      22                 :            : #if defined(MBEDTLS_X509_CRT_PARSE_C)
+      23                 :            : 
+      24                 :            : #include "mbedtls/x509_crt.h"
+      25                 :            : #include "x509_internal.h"
+      26                 :            : #include "mbedtls/error.h"
+      27                 :            : #include "mbedtls/oid.h"
+      28                 :            : #include "mbedtls/platform_util.h"
+      29                 :            : 
+      30                 :            : #include <string.h>
+      31                 :            : 
+      32                 :            : #if defined(MBEDTLS_PEM_PARSE_C)
+      33                 :            : #include "mbedtls/pem.h"
+      34                 :            : #endif
+      35                 :            : 
+      36                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+      37                 :            : #include "psa/crypto.h"
+      38                 :            : #include "psa_util_internal.h"
+      39                 :            : #include "mbedtls/psa_util.h"
+      40                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO */
+      41                 :            : #include "pk_internal.h"
+      42                 :            : 
+      43                 :            : #include "mbedtls/platform.h"
+      44                 :            : 
+      45                 :            : #if defined(MBEDTLS_THREADING_C)
+      46                 :            : #include "mbedtls/threading.h"
+      47                 :            : #endif
+      48                 :            : 
+      49                 :            : #if defined(MBEDTLS_HAVE_TIME)
+      50                 :            : #if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32)
+      51                 :            : #define WIN32_LEAN_AND_MEAN
+      52                 :            : #include <windows.h>
+      53                 :            : #else
+      54                 :            : #include <time.h>
+      55                 :            : #endif
+      56                 :            : #endif
+      57                 :            : 
+      58                 :            : #if defined(MBEDTLS_FS_IO)
+      59                 :            : #include <stdio.h>
+      60                 :            : #if !defined(_WIN32) || defined(EFIX64) || defined(EFI32)
+      61                 :            : #include <sys/types.h>
+      62                 :            : #include <sys/stat.h>
+      63                 :            : #if defined(__MBED__)
+      64                 :            : #include <platform/mbed_retarget.h>
+      65                 :            : #else
+      66                 :            : #include <dirent.h>
+      67                 :            : #endif /* __MBED__ */
+      68                 :            : #include <errno.h>
+      69                 :            : #endif /* !_WIN32 || EFIX64 || EFI32 */
+      70                 :            : #endif
+      71                 :            : 
+      72                 :            : /*
+      73                 :            :  * Item in a verification chain: cert and flags for it
+      74                 :            :  */
+      75                 :            : typedef struct {
+      76                 :            :     mbedtls_x509_crt *crt;
+      77                 :            :     uint32_t flags;
+      78                 :            : } x509_crt_verify_chain_item;
+      79                 :            : 
+      80                 :            : /*
+      81                 :            :  * Max size of verification chain: end-entity + intermediates + trusted root
+      82                 :            :  */
+      83                 :            : #define X509_MAX_VERIFY_CHAIN_SIZE    (MBEDTLS_X509_MAX_INTERMEDIATE_CA + 2)
+      84                 :            : 
+      85                 :            : /* Default profile. Do not remove items unless there are serious security
+      86                 :            :  * concerns. */
+      87                 :            : const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_default =
+      88                 :            : {
+      89                 :            :     /* Hashes from SHA-256 and above. Note that this selection
+      90                 :            :      * should be aligned with ssl_preset_default_hashes in ssl_tls.c. */
+      91                 :            :     MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA256) |
+      92                 :            :     MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA384) |
+      93                 :            :     MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA512),
+      94                 :            :     0xFFFFFFF, /* Any PK alg    */
+      95                 :            : #if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
+      96                 :            :     /* Curves at or above 128-bit security level. Note that this selection
+      97                 :            :      * should be aligned with ssl_preset_default_curves in ssl_tls.c. */
+      98                 :            :     MBEDTLS_X509_ID_FLAG(MBEDTLS_ECP_DP_SECP256R1) |
+      99                 :            :     MBEDTLS_X509_ID_FLAG(MBEDTLS_ECP_DP_SECP384R1) |
+     100                 :            :     MBEDTLS_X509_ID_FLAG(MBEDTLS_ECP_DP_SECP521R1) |
+     101                 :            :     MBEDTLS_X509_ID_FLAG(MBEDTLS_ECP_DP_BP256R1) |
+     102                 :            :     MBEDTLS_X509_ID_FLAG(MBEDTLS_ECP_DP_BP384R1) |
+     103                 :            :     MBEDTLS_X509_ID_FLAG(MBEDTLS_ECP_DP_BP512R1) |
+     104                 :            :     0,
+     105                 :            : #else /* MBEDTLS_PK_HAVE_ECC_KEYS */
+     106                 :            :     0,
+     107                 :            : #endif /* MBEDTLS_PK_HAVE_ECC_KEYS */
+     108                 :            :     2048,
+     109                 :            : };
+     110                 :            : 
+     111                 :            : /* Next-generation profile. Currently identical to the default, but may
+     112                 :            :  * be tightened at any time. */
+     113                 :            : const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_next =
+     114                 :            : {
+     115                 :            :     /* Hashes from SHA-256 and above. */
+     116                 :            :     MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA256) |
+     117                 :            :     MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA384) |
+     118                 :            :     MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA512),
+     119                 :            :     0xFFFFFFF, /* Any PK alg    */
+     120                 :            : #if defined(MBEDTLS_ECP_C)
+     121                 :            :     /* Curves at or above 128-bit security level. */
+     122                 :            :     MBEDTLS_X509_ID_FLAG(MBEDTLS_ECP_DP_SECP256R1) |
+     123                 :            :     MBEDTLS_X509_ID_FLAG(MBEDTLS_ECP_DP_SECP384R1) |
+     124                 :            :     MBEDTLS_X509_ID_FLAG(MBEDTLS_ECP_DP_SECP521R1) |
+     125                 :            :     MBEDTLS_X509_ID_FLAG(MBEDTLS_ECP_DP_BP256R1) |
+     126                 :            :     MBEDTLS_X509_ID_FLAG(MBEDTLS_ECP_DP_BP384R1) |
+     127                 :            :     MBEDTLS_X509_ID_FLAG(MBEDTLS_ECP_DP_BP512R1) |
+     128                 :            :     MBEDTLS_X509_ID_FLAG(MBEDTLS_ECP_DP_SECP256K1),
+     129                 :            : #else
+     130                 :            :     0,
+     131                 :            : #endif
+     132                 :            :     2048,
+     133                 :            : };
+     134                 :            : 
+     135                 :            : /*
+     136                 :            :  * NSA Suite B Profile
+     137                 :            :  */
+     138                 :            : const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_suiteb =
+     139                 :            : {
+     140                 :            :     /* Only SHA-256 and 384 */
+     141                 :            :     MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA256) |
+     142                 :            :     MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA384),
+     143                 :            :     /* Only ECDSA */
+     144                 :            :     MBEDTLS_X509_ID_FLAG(MBEDTLS_PK_ECDSA) |
+     145                 :            :     MBEDTLS_X509_ID_FLAG(MBEDTLS_PK_ECKEY),
+     146                 :            : #if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
+     147                 :            :     /* Only NIST P-256 and P-384 */
+     148                 :            :     MBEDTLS_X509_ID_FLAG(MBEDTLS_ECP_DP_SECP256R1) |
+     149                 :            :     MBEDTLS_X509_ID_FLAG(MBEDTLS_ECP_DP_SECP384R1),
+     150                 :            : #else /* MBEDTLS_PK_HAVE_ECC_KEYS */
+     151                 :            :     0,
+     152                 :            : #endif /* MBEDTLS_PK_HAVE_ECC_KEYS */
+     153                 :            :     0,
+     154                 :            : };
+     155                 :            : 
+     156                 :            : /*
+     157                 :            :  * Empty / all-forbidden profile
+     158                 :            :  */
+     159                 :            : const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_none =
+     160                 :            : {
+     161                 :            :     0,
+     162                 :            :     0,
+     163                 :            :     0,
+     164                 :            :     (uint32_t) -1,
+     165                 :            : };
+     166                 :            : 
+     167                 :            : /*
+     168                 :            :  * Check md_alg against profile
+     169                 :            :  * Return 0 if md_alg is acceptable for this profile, -1 otherwise
+     170                 :            :  */
+     171                 :       2255 : static int x509_profile_check_md_alg(const mbedtls_x509_crt_profile *profile,
+     172                 :            :                                      mbedtls_md_type_t md_alg)
+     173                 :            : {
+     174         [ -  + ]:       2255 :     if (md_alg == MBEDTLS_MD_NONE) {
+     175                 :          0 :         return -1;
+     176                 :            :     }
+     177                 :            : 
+     178         [ +  - ]:       2255 :     if ((profile->allowed_mds & MBEDTLS_X509_ID_FLAG(md_alg)) != 0) {
+     179                 :       2255 :         return 0;
+     180                 :            :     }
+     181                 :            : 
+     182                 :          0 :     return -1;
+     183                 :            : }
+     184                 :            : 
+     185                 :            : /*
+     186                 :            :  * Check pk_alg against profile
+     187                 :            :  * Return 0 if pk_alg is acceptable for this profile, -1 otherwise
+     188                 :            :  */
+     189                 :       4510 : static int x509_profile_check_pk_alg(const mbedtls_x509_crt_profile *profile,
+     190                 :            :                                      mbedtls_pk_type_t pk_alg)
+     191                 :            : {
+     192         [ -  + ]:       4510 :     if (pk_alg == MBEDTLS_PK_NONE) {
+     193                 :          0 :         return -1;
+     194                 :            :     }
+     195                 :            : 
+     196         [ +  - ]:       4510 :     if ((profile->allowed_pks & MBEDTLS_X509_ID_FLAG(pk_alg)) != 0) {
+     197                 :       4510 :         return 0;
+     198                 :            :     }
+     199                 :            : 
+     200                 :          0 :     return -1;
+     201                 :            : }
+     202                 :            : 
+     203                 :            : /*
+     204                 :            :  * Check key against profile
+     205                 :            :  * Return 0 if pk is acceptable for this profile, -1 otherwise
+     206                 :            :  */
+     207                 :       3841 : static int x509_profile_check_key(const mbedtls_x509_crt_profile *profile,
+     208                 :            :                                   const mbedtls_pk_context *pk)
+     209                 :            : {
+     210                 :       3841 :     const mbedtls_pk_type_t pk_alg = mbedtls_pk_get_type(pk);
+     211                 :            : 
+     212                 :            : #if defined(MBEDTLS_RSA_C)
+     213   [ +  +  -  + ]:       3841 :     if (pk_alg == MBEDTLS_PK_RSA || pk_alg == MBEDTLS_PK_RSASSA_PSS) {
+     214         [ +  - ]:        540 :         if (mbedtls_pk_get_bitlen(pk) >= profile->rsa_min_bitlen) {
+     215                 :        540 :             return 0;
+     216                 :            :         }
+     217                 :            : 
+     218                 :          0 :         return -1;
+     219                 :            :     }
+     220                 :            : #endif /* MBEDTLS_RSA_C */
+     221                 :            : 
+     222                 :            : #if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
+     223   [ +  -  -  + ]:       3301 :     if (pk_alg == MBEDTLS_PK_ECDSA ||
+     224         [ #  # ]:          0 :         pk_alg == MBEDTLS_PK_ECKEY ||
+     225                 :            :         pk_alg == MBEDTLS_PK_ECKEY_DH) {
+     226                 :       3301 :         const mbedtls_ecp_group_id gid = mbedtls_pk_get_ec_group_id(pk);
+     227                 :            : 
+     228         [ -  + ]:       3301 :         if (gid == MBEDTLS_ECP_DP_NONE) {
+     229                 :          0 :             return -1;
+     230                 :            :         }
+     231                 :            : 
+     232         [ +  - ]:       3301 :         if ((profile->allowed_curves & MBEDTLS_X509_ID_FLAG(gid)) != 0) {
+     233                 :       3301 :             return 0;
+     234                 :            :         }
+     235                 :            : 
+     236                 :          0 :         return -1;
+     237                 :            :     }
+     238                 :            : #endif /* MBEDTLS_PK_HAVE_ECC_KEYS */
+     239                 :            : 
+     240                 :          0 :     return -1;
+     241                 :            : }
+     242                 :            : 
+     243                 :            : /*
+     244                 :            :  * Like memcmp, but case-insensitive and always returns -1 if different
+     245                 :            :  */
+     246                 :        175 : static int x509_memcasecmp(const void *s1, const void *s2, size_t len)
+     247                 :            : {
+     248                 :            :     size_t i;
+     249                 :            :     unsigned char diff;
+     250                 :        175 :     const unsigned char *n1 = s1, *n2 = s2;
+     251                 :            : 
+     252         [ +  - ]:       5374 :     for (i = 0; i < len; i++) {
+     253                 :       5374 :         diff = n1[i] ^ n2[i];
+     254                 :            : 
+     255         [ +  + ]:       5374 :         if (diff == 0) {
+     256                 :       5199 :             continue;
+     257                 :            :         }
+     258                 :            : 
+     259         [ -  + ]:        175 :         if (diff == 32 &&
+     260   [ #  #  #  # ]:          0 :             ((n1[i] >= 'a' && n1[i] <= 'z') ||
+     261   [ #  #  #  # ]:          0 :              (n1[i] >= 'A' && n1[i] <= 'Z'))) {
+     262                 :          0 :             continue;
+     263                 :            :         }
+     264                 :            : 
+     265                 :        175 :         return -1;
+     266                 :            :     }
+     267                 :            : 
+     268                 :          0 :     return 0;
+     269                 :            : }
+     270                 :            : 
+     271                 :            : /*
+     272                 :            :  * Return 0 if name matches wildcard, -1 otherwise
+     273                 :            :  */
+     274                 :          0 : static int x509_check_wildcard(const char *cn, const mbedtls_x509_buf *name)
+     275                 :            : {
+     276                 :            :     size_t i;
+     277                 :          0 :     size_t cn_idx = 0, cn_len = strlen(cn);
+     278                 :            : 
+     279                 :            :     /* We can't have a match if there is no wildcard to match */
+     280   [ #  #  #  #  :          0 :     if (name->len < 3 || name->p[0] != '*' || name->p[1] != '.') {
+                   #  # ]
+     281                 :          0 :         return -1;
+     282                 :            :     }
+     283                 :            : 
+     284         [ #  # ]:          0 :     for (i = 0; i < cn_len; ++i) {
+     285         [ #  # ]:          0 :         if (cn[i] == '.') {
+     286                 :          0 :             cn_idx = i;
+     287                 :          0 :             break;
+     288                 :            :         }
+     289                 :            :     }
+     290                 :            : 
+     291         [ #  # ]:          0 :     if (cn_idx == 0) {
+     292                 :          0 :         return -1;
+     293                 :            :     }
+     294                 :            : 
+     295   [ #  #  #  # ]:          0 :     if (cn_len - cn_idx == name->len - 1 &&
+     296                 :          0 :         x509_memcasecmp(name->p + 1, cn + cn_idx, name->len - 1) == 0) {
+     297                 :          0 :         return 0;
+     298                 :            :     }
+     299                 :            : 
+     300                 :          0 :     return -1;
+     301                 :            : }
+     302                 :            : 
+     303                 :            : /*
+     304                 :            :  * Compare two X.509 strings, case-insensitive, and allowing for some encoding
+     305                 :            :  * variations (but not all).
+     306                 :            :  *
+     307                 :            :  * Return 0 if equal, -1 otherwise.
+     308                 :            :  */
+     309                 :       3843 : static int x509_string_cmp(const mbedtls_x509_buf *a, const mbedtls_x509_buf *b)
+     310                 :            : {
+     311         [ +  - ]:       3843 :     if (a->tag == b->tag &&
+     312         [ +  + ]:       3843 :         a->len == b->len &&
+     313         [ +  + ]:       2430 :         memcmp(a->p, b->p, b->len) == 0) {
+     314                 :       2255 :         return 0;
+     315                 :            :     }
+     316                 :            : 
+     317   [ -  +  -  - ]:       1588 :     if ((a->tag == MBEDTLS_ASN1_UTF8_STRING || a->tag == MBEDTLS_ASN1_PRINTABLE_STRING) &&
+     318   [ -  +  -  - ]:       1588 :         (b->tag == MBEDTLS_ASN1_UTF8_STRING || b->tag == MBEDTLS_ASN1_PRINTABLE_STRING) &&
+     319   [ +  +  -  + ]:       1763 :         a->len == b->len &&
+     320                 :        175 :         x509_memcasecmp(a->p, b->p, b->len) == 0) {
+     321                 :          0 :         return 0;
+     322                 :            :     }
+     323                 :            : 
+     324                 :       1588 :     return -1;
+     325                 :            : }
+     326                 :            : 
+     327                 :            : /*
+     328                 :            :  * Compare two X.509 Names (aka rdnSequence).
+     329                 :            :  *
+     330                 :            :  * See RFC 5280 section 7.1, though we don't implement the whole algorithm:
+     331                 :            :  * we sometimes return unequal when the full algorithm would return equal,
+     332                 :            :  * but never the other way. (In particular, we don't do Unicode normalisation
+     333                 :            :  * or space folding.)
+     334                 :            :  *
+     335                 :            :  * Return 0 if equal, -1 otherwise.
+     336                 :            :  */
+     337                 :       3843 : static int x509_name_cmp(const mbedtls_x509_name *a, const mbedtls_x509_name *b)
+     338                 :            : {
+     339                 :            :     /* Avoid recursion, it might not be optimised by the compiler */
+     340   [ +  +  -  + ]:       6098 :     while (a != NULL || b != NULL) {
+     341   [ +  -  -  + ]:       3843 :         if (a == NULL || b == NULL) {
+     342                 :          0 :             return -1;
+     343                 :            :         }
+     344                 :            : 
+     345                 :            :         /* type */
+     346         [ +  - ]:       3843 :         if (a->oid.tag != b->oid.tag ||
+     347         [ +  - ]:       3843 :             a->oid.len != b->oid.len ||
+     348         [ -  + ]:       3843 :             memcmp(a->oid.p, b->oid.p, b->oid.len) != 0) {
+     349                 :          0 :             return -1;
+     350                 :            :         }
+     351                 :            : 
+     352                 :            :         /* value */
+     353         [ +  + ]:       3843 :         if (x509_string_cmp(&a->val, &b->val) != 0) {
+     354                 :       1588 :             return -1;
+     355                 :            :         }
+     356                 :            : 
+     357                 :            :         /* structure of the list of sets */
+     358         [ -  + ]:       2255 :         if (a->next_merged != b->next_merged) {
+     359                 :          0 :             return -1;
+     360                 :            :         }
+     361                 :            : 
+     362                 :       2255 :         a = a->next;
+     363                 :       2255 :         b = b->next;
+     364                 :            :     }
+     365                 :            : 
+     366                 :            :     /* a == NULL == b */
+     367                 :       2255 :     return 0;
+     368                 :            : }
+     369                 :            : 
+     370                 :            : /*
+     371                 :            :  * Reset (init or clear) a verify_chain
+     372                 :            :  */
+     373                 :       2255 : static void x509_crt_verify_chain_reset(
+     374                 :            :     mbedtls_x509_crt_verify_chain *ver_chain)
+     375                 :            : {
+     376                 :            :     size_t i;
+     377                 :            : 
+     378         [ +  + ]:      24805 :     for (i = 0; i < MBEDTLS_X509_MAX_VERIFY_CHAIN_SIZE; i++) {
+     379                 :      22550 :         ver_chain->items[i].crt = NULL;
+     380                 :      22550 :         ver_chain->items[i].flags = (uint32_t) -1;
+     381                 :            :     }
+     382                 :            : 
+     383                 :       2255 :     ver_chain->len = 0;
+     384                 :            : 
+     385                 :            : #if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
+     386                 :            :     ver_chain->trust_ca_cb_result = NULL;
+     387                 :            : #endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
+     388                 :       2255 : }
+     389                 :            : 
+     390                 :            : /*
+     391                 :            :  *  Version  ::=  INTEGER  {  v1(0), v2(1), v3(2)  }
+     392                 :            :  */
+     393                 :      12125 : static int x509_get_version(unsigned char **p,
+     394                 :            :                             const unsigned char *end,
+     395                 :            :                             int *ver)
+     396                 :            : {
+     397                 :      12125 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     398                 :            :     size_t len;
+     399                 :            : 
+     400         [ -  + ]:      12125 :     if ((ret = mbedtls_asn1_get_tag(p, end, &len,
+     401                 :            :                                     MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED |
+     402                 :            :                                     0)) != 0) {
+     403         [ #  # ]:          0 :         if (ret == MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) {
+     404                 :          0 :             *ver = 0;
+     405                 :          0 :             return 0;
+     406                 :            :         }
+     407                 :            : 
+     408                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_FORMAT, ret);
+     409                 :            :     }
+     410                 :            : 
+     411                 :      12125 :     end = *p + len;
+     412                 :            : 
+     413         [ -  + ]:      12125 :     if ((ret = mbedtls_asn1_get_int(p, end, ver)) != 0) {
+     414                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_VERSION, ret);
+     415                 :            :     }
+     416                 :            : 
+     417         [ -  + ]:      12125 :     if (*p != end) {
+     418                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_VERSION,
+     419                 :            :                                  MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
+     420                 :            :     }
+     421                 :            : 
+     422                 :      12125 :     return 0;
+     423                 :            : }
+     424                 :            : 
+     425                 :            : /*
+     426                 :            :  *  Validity ::= SEQUENCE {
+     427                 :            :  *       notBefore      Time,
+     428                 :            :  *       notAfter       Time }
+     429                 :            :  */
+     430                 :      12125 : static int x509_get_dates(unsigned char **p,
+     431                 :            :                           const unsigned char *end,
+     432                 :            :                           mbedtls_x509_time *from,
+     433                 :            :                           mbedtls_x509_time *to)
+     434                 :            : {
+     435                 :      12125 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     436                 :            :     size_t len;
+     437                 :            : 
+     438         [ -  + ]:      12125 :     if ((ret = mbedtls_asn1_get_tag(p, end, &len,
+     439                 :            :                                     MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
+     440                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_DATE, ret);
+     441                 :            :     }
+     442                 :            : 
+     443                 :      12125 :     end = *p + len;
+     444                 :            : 
+     445         [ -  + ]:      12125 :     if ((ret = mbedtls_x509_get_time(p, end, from)) != 0) {
+     446                 :          0 :         return ret;
+     447                 :            :     }
+     448                 :            : 
+     449         [ -  + ]:      12125 :     if ((ret = mbedtls_x509_get_time(p, end, to)) != 0) {
+     450                 :          0 :         return ret;
+     451                 :            :     }
+     452                 :            : 
+     453         [ -  + ]:      12125 :     if (*p != end) {
+     454                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_DATE,
+     455                 :            :                                  MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
+     456                 :            :     }
+     457                 :            : 
+     458                 :      12125 :     return 0;
+     459                 :            : }
+     460                 :            : 
+     461                 :            : /*
+     462                 :            :  * X.509 v2/v3 unique identifier (not parsed)
+     463                 :            :  */
+     464                 :      24250 : static int x509_get_uid(unsigned char **p,
+     465                 :            :                         const unsigned char *end,
+     466                 :            :                         mbedtls_x509_buf *uid, int n)
+     467                 :            : {
+     468                 :      24250 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     469                 :            : 
+     470         [ -  + ]:      24250 :     if (*p == end) {
+     471                 :          0 :         return 0;
+     472                 :            :     }
+     473                 :            : 
+     474                 :      24250 :     uid->tag = **p;
+     475                 :            : 
+     476         [ +  - ]:      24250 :     if ((ret = mbedtls_asn1_get_tag(p, end, &uid->len,
+     477                 :            :                                     MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED |
+     478                 :            :                                     n)) != 0) {
+     479         [ +  - ]:      24250 :         if (ret == MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) {
+     480                 :      24250 :             return 0;
+     481                 :            :         }
+     482                 :            : 
+     483                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_FORMAT, ret);
+     484                 :            :     }
+     485                 :            : 
+     486                 :          0 :     uid->p = *p;
+     487                 :          0 :     *p += uid->len;
+     488                 :            : 
+     489                 :          0 :     return 0;
+     490                 :            : }
+     491                 :            : 
+     492                 :      12105 : static int x509_get_basic_constraints(unsigned char **p,
+     493                 :            :                                       const unsigned char *end,
+     494                 :            :                                       int *ca_istrue,
+     495                 :            :                                       int *max_pathlen)
+     496                 :            : {
+     497                 :      12105 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     498                 :            :     size_t len;
+     499                 :            : 
+     500                 :            :     /*
+     501                 :            :      * BasicConstraints ::= SEQUENCE {
+     502                 :            :      *      cA                      BOOLEAN DEFAULT FALSE,
+     503                 :            :      *      pathLenConstraint       INTEGER (0..MAX) OPTIONAL }
+     504                 :            :      */
+     505                 :      12105 :     *ca_istrue = 0; /* DEFAULT FALSE */
+     506                 :      12105 :     *max_pathlen = 0; /* endless */
+     507                 :            : 
+     508         [ -  + ]:      12105 :     if ((ret = mbedtls_asn1_get_tag(p, end, &len,
+     509                 :            :                                     MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
+     510                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
+     511                 :            :     }
+     512                 :            : 
+     513         [ +  + ]:      12105 :     if (*p == end) {
+     514                 :       8121 :         return 0;
+     515                 :            :     }
+     516                 :            : 
+     517         [ -  + ]:       3984 :     if ((ret = mbedtls_asn1_get_bool(p, end, ca_istrue)) != 0) {
+     518         [ #  # ]:          0 :         if (ret == MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) {
+     519                 :          0 :             ret = mbedtls_asn1_get_int(p, end, ca_istrue);
+     520                 :            :         }
+     521                 :            : 
+     522         [ #  # ]:          0 :         if (ret != 0) {
+     523                 :          0 :             return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
+     524                 :            :         }
+     525                 :            : 
+     526         [ #  # ]:          0 :         if (*ca_istrue != 0) {
+     527                 :          0 :             *ca_istrue = 1;
+     528                 :            :         }
+     529                 :            :     }
+     530                 :            : 
+     531         [ +  - ]:       3984 :     if (*p == end) {
+     532                 :       3984 :         return 0;
+     533                 :            :     }
+     534                 :            : 
+     535         [ #  # ]:          0 :     if ((ret = mbedtls_asn1_get_int(p, end, max_pathlen)) != 0) {
+     536                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
+     537                 :            :     }
+     538                 :            : 
+     539         [ #  # ]:          0 :     if (*p != end) {
+     540                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
+     541                 :            :                                  MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
+     542                 :            :     }
+     543                 :            : 
+     544                 :            :     /* Do not accept max_pathlen equal to INT_MAX to avoid a signed integer
+     545                 :            :      * overflow, which is an undefined behavior. */
+     546         [ #  # ]:          0 :     if (*max_pathlen == INT_MAX) {
+     547                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
+     548                 :            :                                  MBEDTLS_ERR_ASN1_INVALID_LENGTH);
+     549                 :            :     }
+     550                 :            : 
+     551                 :          0 :     (*max_pathlen)++;
+     552                 :            : 
+     553                 :          0 :     return 0;
+     554                 :            : }
+     555                 :            : 
+     556                 :            : /*
+     557                 :            :  * ExtKeyUsageSyntax ::= SEQUENCE SIZE (1..MAX) OF KeyPurposeId
+     558                 :            :  *
+     559                 :            :  * KeyPurposeId ::= OBJECT IDENTIFIER
+     560                 :            :  */
+     561                 :       9975 : static int x509_get_ext_key_usage(unsigned char **p,
+     562                 :            :                                   const unsigned char *end,
+     563                 :            :                                   mbedtls_x509_sequence *ext_key_usage)
+     564                 :            : {
+     565                 :       9975 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     566                 :            : 
+     567         [ -  + ]:       9975 :     if ((ret = mbedtls_asn1_get_sequence_of(p, end, ext_key_usage, MBEDTLS_ASN1_OID)) != 0) {
+     568                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
+     569                 :            :     }
+     570                 :            : 
+     571                 :            :     /* Sequence length must be >= 1 */
+     572         [ -  + ]:       9975 :     if (ext_key_usage->buf.p == NULL) {
+     573                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
+     574                 :            :                                  MBEDTLS_ERR_ASN1_INVALID_LENGTH);
+     575                 :            :     }
+     576                 :            : 
+     577                 :       9975 :     return 0;
+     578                 :            : }
+     579                 :            : 
+     580                 :            : /*
+     581                 :            :  * SubjectKeyIdentifier ::= KeyIdentifier
+     582                 :            :  *
+     583                 :            :  * KeyIdentifier ::= OCTET STRING
+     584                 :            :  */
+     585                 :      12125 : static int x509_get_subject_key_id(unsigned char **p,
+     586                 :            :                                    const unsigned char *end,
+     587                 :            :                                    mbedtls_x509_buf *subject_key_id)
+     588                 :            : {
+     589                 :      12125 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     590                 :      12125 :     size_t len = 0u;
+     591                 :            : 
+     592         [ -  + ]:      12125 :     if ((ret = mbedtls_asn1_get_tag(p, end, &len,
+     593                 :            :                                     MBEDTLS_ASN1_OCTET_STRING)) != 0) {
+     594                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
+     595                 :            :     }
+     596                 :            : 
+     597                 :      12125 :     subject_key_id->len = len;
+     598                 :      12125 :     subject_key_id->tag = MBEDTLS_ASN1_OCTET_STRING;
+     599                 :      12125 :     subject_key_id->p = *p;
+     600                 :      12125 :     *p += len;
+     601                 :            : 
+     602         [ -  + ]:      12125 :     if (*p != end) {
+     603                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
+     604                 :            :                                  MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
+     605                 :            :     }
+     606                 :            : 
+     607                 :      12125 :     return 0;
+     608                 :            : }
+     609                 :            : 
+     610                 :            : /*
+     611                 :            :  * AuthorityKeyIdentifier ::= SEQUENCE {
+     612                 :            :  *        keyIdentifier [0] KeyIdentifier OPTIONAL,
+     613                 :            :  *        authorityCertIssuer [1] GeneralNames OPTIONAL,
+     614                 :            :  *        authorityCertSerialNumber [2] CertificateSerialNumber OPTIONAL }
+     615                 :            :  *
+     616                 :            :  *    KeyIdentifier ::= OCTET STRING
+     617                 :            :  */
+     618                 :       2190 : static int x509_get_authority_key_id(unsigned char **p,
+     619                 :            :                                      unsigned char *end,
+     620                 :            :                                      mbedtls_x509_authority *authority_key_id)
+     621                 :            : {
+     622                 :       2190 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     623                 :       2190 :     size_t len = 0u;
+     624                 :            : 
+     625         [ -  + ]:       2190 :     if ((ret = mbedtls_asn1_get_tag(p, end, &len,
+     626                 :            :                                     MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
+     627                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
+     628                 :            :     }
+     629                 :            : 
+     630         [ -  + ]:       2190 :     if (*p + len != end) {
+     631                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
+     632                 :            :                                  MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
+     633                 :            :     }
+     634                 :            : 
+     635                 :       2190 :     ret = mbedtls_asn1_get_tag(p, end, &len,
+     636                 :            :                                MBEDTLS_ASN1_CONTEXT_SPECIFIC);
+     637                 :            : 
+     638                 :            :     /* KeyIdentifier is an OPTIONAL field */
+     639         [ +  - ]:       2190 :     if (ret == 0) {
+     640                 :       2190 :         authority_key_id->keyIdentifier.len = len;
+     641                 :       2190 :         authority_key_id->keyIdentifier.p = *p;
+     642                 :            :         /* Setting tag of the keyIdentfier intentionally to 0x04.
+     643                 :            :          * Although the .keyIdentfier field is CONTEXT_SPECIFIC ([0] OPTIONAL),
+     644                 :            :          * its tag with the content is the payload of on OCTET STRING primitive */
+     645                 :       2190 :         authority_key_id->keyIdentifier.tag = MBEDTLS_ASN1_OCTET_STRING;
+     646                 :            : 
+     647                 :       2190 :         *p += len;
+     648         [ #  # ]:          0 :     } else if (ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) {
+     649                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
+     650                 :            :     }
+     651                 :            : 
+     652         [ -  + ]:       2190 :     if (*p < end) {
+     653                 :            :         /* Getting authorityCertIssuer using the required specific class tag [1] */
+     654         [ #  # ]:          0 :         if ((ret = mbedtls_asn1_get_tag(p, end, &len,
+     655                 :            :                                         MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED |
+     656                 :            :                                         1)) != 0) {
+     657                 :            :             /* authorityCertIssuer and authorityCertSerialNumber MUST both
+     658                 :            :                be present or both be absent. At this point we expect to have both. */
+     659                 :          0 :             return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
+     660                 :            :         }
+     661                 :            :         /* "end" also includes the CertSerialNumber field so "len" shall be used */
+     662                 :          0 :         ret = mbedtls_x509_get_subject_alt_name_ext(p,
+     663                 :          0 :                                                     (*p+len),
+     664                 :            :                                                     &authority_key_id->authorityCertIssuer);
+     665         [ #  # ]:          0 :         if (ret != 0) {
+     666                 :          0 :             return ret;
+     667                 :            :         }
+     668                 :            : 
+     669                 :            :         /* Getting authorityCertSerialNumber using the required specific class tag [2] */
+     670         [ #  # ]:          0 :         if ((ret = mbedtls_asn1_get_tag(p, end, &len,
+     671                 :            :                                         MBEDTLS_ASN1_CONTEXT_SPECIFIC | 2)) != 0) {
+     672                 :          0 :             return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
+     673                 :            :         }
+     674                 :          0 :         authority_key_id->authorityCertSerialNumber.len = len;
+     675                 :          0 :         authority_key_id->authorityCertSerialNumber.p = *p;
+     676                 :          0 :         authority_key_id->authorityCertSerialNumber.tag = MBEDTLS_ASN1_INTEGER;
+     677                 :          0 :         *p += len;
+     678                 :            :     }
+     679                 :            : 
+     680         [ -  + ]:       2190 :     if (*p != end) {
+     681                 :          0 :         return MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
+     682                 :            :                MBEDTLS_ERR_ASN1_LENGTH_MISMATCH;
+     683                 :            :     }
+     684                 :            : 
+     685                 :       2190 :     return 0;
+     686                 :            : }
+     687                 :            : 
+     688                 :            : /*
+     689                 :            :  * id-ce-certificatePolicies OBJECT IDENTIFIER ::=  { id-ce 32 }
+     690                 :            :  *
+     691                 :            :  * anyPolicy OBJECT IDENTIFIER ::= { id-ce-certificatePolicies 0 }
+     692                 :            :  *
+     693                 :            :  * certificatePolicies ::= SEQUENCE SIZE (1..MAX) OF PolicyInformation
+     694                 :            :  *
+     695                 :            :  * PolicyInformation ::= SEQUENCE {
+     696                 :            :  *     policyIdentifier   CertPolicyId,
+     697                 :            :  *     policyQualifiers   SEQUENCE SIZE (1..MAX) OF
+     698                 :            :  *                             PolicyQualifierInfo OPTIONAL }
+     699                 :            :  *
+     700                 :            :  * CertPolicyId ::= OBJECT IDENTIFIER
+     701                 :            :  *
+     702                 :            :  * PolicyQualifierInfo ::= SEQUENCE {
+     703                 :            :  *      policyQualifierId  PolicyQualifierId,
+     704                 :            :  *      qualifier          ANY DEFINED BY policyQualifierId }
+     705                 :            :  *
+     706                 :            :  * -- policyQualifierIds for Internet policy qualifiers
+     707                 :            :  *
+     708                 :            :  * id-qt          OBJECT IDENTIFIER ::=  { id-pkix 2 }
+     709                 :            :  * id-qt-cps      OBJECT IDENTIFIER ::=  { id-qt 1 }
+     710                 :            :  * id-qt-unotice  OBJECT IDENTIFIER ::=  { id-qt 2 }
+     711                 :            :  *
+     712                 :            :  * PolicyQualifierId ::= OBJECT IDENTIFIER ( id-qt-cps | id-qt-unotice )
+     713                 :            :  *
+     714                 :            :  * Qualifier ::= CHOICE {
+     715                 :            :  *      cPSuri           CPSuri,
+     716                 :            :  *      userNotice       UserNotice }
+     717                 :            :  *
+     718                 :            :  * CPSuri ::= IA5String
+     719                 :            :  *
+     720                 :            :  * UserNotice ::= SEQUENCE {
+     721                 :            :  *      noticeRef        NoticeReference OPTIONAL,
+     722                 :            :  *      explicitText     DisplayText OPTIONAL }
+     723                 :            :  *
+     724                 :            :  * NoticeReference ::= SEQUENCE {
+     725                 :            :  *      organization     DisplayText,
+     726                 :            :  *      noticeNumbers    SEQUENCE OF INTEGER }
+     727                 :            :  *
+     728                 :            :  * DisplayText ::= CHOICE {
+     729                 :            :  *      ia5String        IA5String      (SIZE (1..200)),
+     730                 :            :  *      visibleString    VisibleString  (SIZE (1..200)),
+     731                 :            :  *      bmpString        BMPString      (SIZE (1..200)),
+     732                 :            :  *      utf8String       UTF8String     (SIZE (1..200)) }
+     733                 :            :  *
+     734                 :            :  * NOTE: we only parse and use anyPolicy without qualifiers at this point
+     735                 :            :  * as defined in RFC 5280.
+     736                 :            :  */
+     737                 :         40 : static int x509_get_certificate_policies(unsigned char **p,
+     738                 :            :                                          const unsigned char *end,
+     739                 :            :                                          mbedtls_x509_sequence *certificate_policies)
+     740                 :            : {
+     741                 :         40 :     int ret, parse_ret = 0;
+     742                 :            :     size_t len;
+     743                 :            :     mbedtls_asn1_buf *buf;
+     744                 :         40 :     mbedtls_asn1_sequence *cur = certificate_policies;
+     745                 :            : 
+     746                 :            :     /* Get main sequence tag */
+     747                 :         40 :     ret = mbedtls_asn1_get_tag(p, end, &len,
+     748                 :            :                                MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE);
+     749         [ -  + ]:         40 :     if (ret != 0) {
+     750                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
+     751                 :            :     }
+     752                 :            : 
+     753         [ -  + ]:         40 :     if (*p + len != end) {
+     754                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
+     755                 :            :                                  MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
+     756                 :            :     }
+     757                 :            : 
+     758                 :            :     /*
+     759                 :            :      * Cannot be an empty sequence.
+     760                 :            :      */
+     761         [ -  + ]:         40 :     if (len == 0) {
+     762                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
+     763                 :            :                                  MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
+     764                 :            :     }
+     765                 :            : 
+     766         [ +  + ]:        100 :     while (*p < end) {
+     767                 :            :         mbedtls_x509_buf policy_oid;
+     768                 :            :         const unsigned char *policy_end;
+     769                 :            : 
+     770                 :            :         /*
+     771                 :            :          * Get the policy sequence
+     772                 :            :          */
+     773         [ -  + ]:         60 :         if ((ret = mbedtls_asn1_get_tag(p, end, &len,
+     774                 :            :                                         MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
+     775                 :          0 :             return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
+     776                 :            :         }
+     777                 :            : 
+     778                 :         60 :         policy_end = *p + len;
+     779                 :            : 
+     780         [ -  + ]:         60 :         if ((ret = mbedtls_asn1_get_tag(p, policy_end, &len,
+     781                 :            :                                         MBEDTLS_ASN1_OID)) != 0) {
+     782                 :          0 :             return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
+     783                 :            :         }
+     784                 :            : 
+     785                 :         60 :         policy_oid.tag = MBEDTLS_ASN1_OID;
+     786                 :         60 :         policy_oid.len = len;
+     787                 :         60 :         policy_oid.p = *p;
+     788                 :            : 
+     789                 :            :         /*
+     790                 :            :          * Only AnyPolicy is currently supported when enforcing policy.
+     791                 :            :          */
+     792   [ -  +  -  -  :         60 :         if (MBEDTLS_OID_CMP(MBEDTLS_OID_ANY_POLICY, &policy_oid) != 0) {
+                   +  - ]
+     793                 :            :             /*
+     794                 :            :              * Set the parsing return code but continue parsing, in case this
+     795                 :            :              * extension is critical.
+     796                 :            :              */
+     797                 :         60 :             parse_ret = MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE;
+     798                 :            :         }
+     799                 :            : 
+     800                 :            :         /* Allocate and assign next pointer */
+     801         [ +  + ]:         60 :         if (cur->buf.p != NULL) {
+     802         [ -  + ]:         20 :             if (cur->next != NULL) {
+     803                 :          0 :                 return MBEDTLS_ERR_X509_INVALID_EXTENSIONS;
+     804                 :            :             }
+     805                 :            : 
+     806                 :         20 :             cur->next = mbedtls_calloc(1, sizeof(mbedtls_asn1_sequence));
+     807                 :            : 
+     808         [ -  + ]:         20 :             if (cur->next == NULL) {
+     809                 :          0 :                 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
+     810                 :            :                                          MBEDTLS_ERR_ASN1_ALLOC_FAILED);
+     811                 :            :             }
+     812                 :            : 
+     813                 :         20 :             cur = cur->next;
+     814                 :            :         }
+     815                 :            : 
+     816                 :         60 :         buf = &(cur->buf);
+     817                 :         60 :         buf->tag = policy_oid.tag;
+     818                 :         60 :         buf->p = policy_oid.p;
+     819                 :         60 :         buf->len = policy_oid.len;
+     820                 :            : 
+     821                 :         60 :         *p += len;
+     822                 :            : 
+     823                 :            :         /*
+     824                 :            :          * If there is an optional qualifier, then *p < policy_end
+     825                 :            :          * Check the Qualifier len to verify it doesn't exceed policy_end.
+     826                 :            :          */
+     827         [ +  + ]:         60 :         if (*p < policy_end) {
+     828         [ -  + ]:         30 :             if ((ret = mbedtls_asn1_get_tag(p, policy_end, &len,
+     829                 :            :                                             MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) !=
+     830                 :            :                 0) {
+     831                 :          0 :                 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
+     832                 :            :             }
+     833                 :            :             /*
+     834                 :            :              * Skip the optional policy qualifiers.
+     835                 :            :              */
+     836                 :         30 :             *p += len;
+     837                 :            :         }
+     838                 :            : 
+     839         [ -  + ]:         60 :         if (*p != policy_end) {
+     840                 :          0 :             return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
+     841                 :            :                                      MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
+     842                 :            :         }
+     843                 :            :     }
+     844                 :            : 
+     845                 :            :     /* Set final sequence entry's next pointer to NULL */
+     846                 :         40 :     cur->next = NULL;
+     847                 :            : 
+     848         [ -  + ]:         40 :     if (*p != end) {
+     849                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
+     850                 :            :                                  MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
+     851                 :            :     }
+     852                 :            : 
+     853                 :         40 :     return parse_ret;
+     854                 :            : }
+     855                 :            : 
+     856                 :            : /*
+     857                 :            :  * X.509 v3 extensions
+     858                 :            :  *
+     859                 :            :  */
+     860                 :      12125 : static int x509_get_crt_ext(unsigned char **p,
+     861                 :            :                             const unsigned char *end,
+     862                 :            :                             mbedtls_x509_crt *crt,
+     863                 :            :                             mbedtls_x509_crt_ext_cb_t cb,
+     864                 :            :                             void *p_ctx)
+     865                 :            : {
+     866                 :      12125 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     867                 :            :     size_t len;
+     868                 :            :     unsigned char *end_ext_data, *start_ext_octet, *end_ext_octet;
+     869                 :            : 
+     870         [ -  + ]:      12125 :     if (*p == end) {
+     871                 :          0 :         return 0;
+     872                 :            :     }
+     873                 :            : 
+     874         [ -  + ]:      12125 :     if ((ret = mbedtls_x509_get_ext(p, end, &crt->v3_ext, 3)) != 0) {
+     875                 :          0 :         return ret;
+     876                 :            :     }
+     877                 :            : 
+     878                 :      12125 :     end = crt->v3_ext.p + crt->v3_ext.len;
+     879         [ +  + ]:      74817 :     while (*p < end) {
+     880                 :            :         /*
+     881                 :            :          * Extension  ::=  SEQUENCE  {
+     882                 :            :          *      extnID      OBJECT IDENTIFIER,
+     883                 :            :          *      critical    BOOLEAN DEFAULT FALSE,
+     884                 :            :          *      extnValue   OCTET STRING  }
+     885                 :            :          */
+     886                 :      62692 :         mbedtls_x509_buf extn_oid = { 0, 0, NULL };
+     887                 :      62692 :         int is_critical = 0; /* DEFAULT FALSE */
+     888                 :      62692 :         int ext_type = 0;
+     889                 :            : 
+     890         [ -  + ]:      62692 :         if ((ret = mbedtls_asn1_get_tag(p, end, &len,
+     891                 :            :                                         MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
+     892                 :          0 :             return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
+     893                 :            :         }
+     894                 :            : 
+     895                 :      62692 :         end_ext_data = *p + len;
+     896                 :            : 
+     897                 :            :         /* Get extension ID */
+     898         [ -  + ]:      62692 :         if ((ret = mbedtls_asn1_get_tag(p, end_ext_data, &extn_oid.len,
+     899                 :            :                                         MBEDTLS_ASN1_OID)) != 0) {
+     900                 :          0 :             return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
+     901                 :            :         }
+     902                 :            : 
+     903                 :      62692 :         extn_oid.tag = MBEDTLS_ASN1_OID;
+     904                 :      62692 :         extn_oid.p = *p;
+     905                 :      62692 :         *p += extn_oid.len;
+     906                 :            : 
+     907                 :            :         /* Get optional critical */
+     908   [ +  +  -  + ]:      62692 :         if ((ret = mbedtls_asn1_get_bool(p, end_ext_data, &is_critical)) != 0 &&
+     909                 :            :             (ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG)) {
+     910                 :          0 :             return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
+     911                 :            :         }
+     912                 :            : 
+     913                 :            :         /* Data should be octet string type */
+     914         [ -  + ]:      62692 :         if ((ret = mbedtls_asn1_get_tag(p, end_ext_data, &len,
+     915                 :            :                                         MBEDTLS_ASN1_OCTET_STRING)) != 0) {
+     916                 :          0 :             return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
+     917                 :            :         }
+     918                 :            : 
+     919                 :      62692 :         start_ext_octet = *p;
+     920                 :      62692 :         end_ext_octet = *p + len;
+     921                 :            : 
+     922         [ -  + ]:      62692 :         if (end_ext_octet != end_ext_data) {
+     923                 :          0 :             return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
+     924                 :            :                                      MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
+     925                 :            :         }
+     926                 :            : 
+     927                 :            :         /*
+     928                 :            :          * Detect supported extensions
+     929                 :            :          */
+     930                 :      62692 :         ret = mbedtls_oid_get_x509_ext_type(&extn_oid, &ext_type);
+     931                 :            : 
+     932         [ +  + ]:      62692 :         if (ret != 0) {
+     933                 :            :             /* Give the callback (if any) a chance to handle the extension */
+     934         [ -  + ]:       8129 :             if (cb != NULL) {
+     935                 :          0 :                 ret = cb(p_ctx, crt, &extn_oid, is_critical, *p, end_ext_octet);
+     936   [ #  #  #  # ]:          0 :                 if (ret != 0 && is_critical) {
+     937                 :          0 :                     return ret;
+     938                 :            :                 }
+     939                 :          0 :                 *p = end_ext_octet;
+     940                 :       8129 :                 continue;
+     941                 :            :             }
+     942                 :            : 
+     943                 :            :             /* No parser found, skip extension */
+     944                 :       8129 :             *p = end_ext_octet;
+     945                 :            : 
+     946         [ -  + ]:       8129 :             if (is_critical) {
+     947                 :            :                 /* Data is marked as critical: fail */
+     948                 :          0 :                 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
+     949                 :            :                                          MBEDTLS_ERR_ASN1_UNEXPECTED_TAG);
+     950                 :            :             }
+     951                 :       8129 :             continue;
+     952                 :            :         }
+     953                 :            : 
+     954                 :            :         /* Forbid repeated extensions */
+     955         [ -  + ]:      54563 :         if ((crt->ext_types & ext_type) != 0) {
+     956                 :          0 :             return MBEDTLS_ERR_X509_INVALID_EXTENSIONS;
+     957                 :            :         }
+     958                 :            : 
+     959                 :      54563 :         crt->ext_types |= ext_type;
+     960                 :            : 
+     961   [ +  +  +  +  :      54563 :         switch (ext_type) {
+             +  +  -  +  
+                      - ]
+     962                 :      12105 :             case MBEDTLS_X509_EXT_BASIC_CONSTRAINTS:
+     963                 :            :                 /* Parse basic constraints */
+     964         [ -  + ]:      12105 :                 if ((ret = x509_get_basic_constraints(p, end_ext_octet,
+     965                 :            :                                                       &crt->ca_istrue, &crt->max_pathlen)) != 0) {
+     966                 :          0 :                     return ret;
+     967                 :            :                 }
+     968                 :      12105 :                 break;
+     969                 :            : 
+     970                 :       9975 :             case MBEDTLS_X509_EXT_KEY_USAGE:
+     971                 :            :                 /* Parse key usage */
+     972         [ -  + ]:       9975 :                 if ((ret = mbedtls_x509_get_key_usage(p, end_ext_octet,
+     973                 :            :                                                       &crt->key_usage)) != 0) {
+     974                 :          0 :                     return ret;
+     975                 :            :                 }
+     976                 :       9975 :                 break;
+     977                 :            : 
+     978                 :       9975 :             case MBEDTLS_X509_EXT_EXTENDED_KEY_USAGE:
+     979                 :            :                 /* Parse extended key usage */
+     980         [ -  + ]:       9975 :                 if ((ret = x509_get_ext_key_usage(p, end_ext_octet,
+     981                 :            :                                                   &crt->ext_key_usage)) != 0) {
+     982                 :          0 :                     return ret;
+     983                 :            :                 }
+     984                 :       9975 :                 break;
+     985                 :            : 
+     986                 :      12125 :             case MBEDTLS_X509_EXT_SUBJECT_KEY_IDENTIFIER:
+     987                 :            :                 /* Parse subject key identifier */
+     988         [ -  + ]:      12125 :                 if ((ret = x509_get_subject_key_id(p, end_ext_data,
+     989                 :            :                                                    &crt->subject_key_id)) != 0) {
+     990                 :          0 :                     return ret;
+     991                 :            :                 }
+     992                 :      12125 :                 break;
+     993                 :            : 
+     994                 :       2190 :             case MBEDTLS_X509_EXT_AUTHORITY_KEY_IDENTIFIER:
+     995                 :            :                 /* Parse authority key identifier */
+     996         [ -  + ]:       2190 :                 if ((ret = x509_get_authority_key_id(p, end_ext_octet,
+     997                 :            :                                                      &crt->authority_key_id)) != 0) {
+     998                 :          0 :                     return ret;
+     999                 :            :                 }
+    1000                 :       2190 :                 break;
+    1001                 :       8153 :             case MBEDTLS_X509_EXT_SUBJECT_ALT_NAME:
+    1002                 :            :                 /* Parse subject alt name
+    1003                 :            :                  * SubjectAltName ::= GeneralNames
+    1004                 :            :                  */
+    1005         [ -  + ]:       8153 :                 if ((ret = mbedtls_x509_get_subject_alt_name(p, end_ext_octet,
+    1006                 :            :                                                              &crt->subject_alt_names)) != 0) {
+    1007                 :          0 :                     return ret;
+    1008                 :            :                 }
+    1009                 :       8153 :                 break;
+    1010                 :            : 
+    1011                 :          0 :             case MBEDTLS_X509_EXT_NS_CERT_TYPE:
+    1012                 :            :                 /* Parse netscape certificate type */
+    1013         [ #  # ]:          0 :                 if ((ret = mbedtls_x509_get_ns_cert_type(p, end_ext_octet,
+    1014                 :            :                                                          &crt->ns_cert_type)) != 0) {
+    1015                 :          0 :                     return ret;
+    1016                 :            :                 }
+    1017                 :          0 :                 break;
+    1018                 :            : 
+    1019                 :         40 :             case MBEDTLS_OID_X509_EXT_CERTIFICATE_POLICIES:
+    1020                 :            :                 /* Parse certificate policies type */
+    1021         [ +  - ]:         40 :                 if ((ret = x509_get_certificate_policies(p, end_ext_octet,
+    1022                 :            :                                                          &crt->certificate_policies)) != 0) {
+    1023                 :            :                     /* Give the callback (if any) a chance to handle the extension
+    1024                 :            :                      * if it contains unsupported policies */
+    1025   [ +  -  -  +  :         40 :                     if (ret == MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE && cb != NULL &&
+                   -  - ]
+    1026                 :          0 :                         cb(p_ctx, crt, &extn_oid, is_critical,
+    1027                 :            :                            start_ext_octet, end_ext_octet) == 0) {
+    1028                 :          0 :                         break;
+    1029                 :            :                     }
+    1030                 :            : 
+    1031         [ -  + ]:         40 :                     if (is_critical) {
+    1032                 :          0 :                         return ret;
+    1033                 :            :                     } else
+    1034                 :            :                     /*
+    1035                 :            :                      * If MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE is returned, then we
+    1036                 :            :                      * cannot interpret or enforce the policy. However, it is up to
+    1037                 :            :                      * the user to choose how to enforce the policies,
+    1038                 :            :                      * unless the extension is critical.
+    1039                 :            :                      */
+    1040         [ -  + ]:         40 :                     if (ret != MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE) {
+    1041                 :          0 :                         return ret;
+    1042                 :            :                     }
+    1043                 :            :                 }
+    1044                 :         40 :                 break;
+    1045                 :            : 
+    1046                 :          0 :             default:
+    1047                 :            :                 /*
+    1048                 :            :                  * If this is a non-critical extension, which the oid layer
+    1049                 :            :                  * supports, but there isn't an x509 parser for it,
+    1050                 :            :                  * skip the extension.
+    1051                 :            :                  */
+    1052         [ #  # ]:          0 :                 if (is_critical) {
+    1053                 :          0 :                     return MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE;
+    1054                 :            :                 } else {
+    1055                 :          0 :                     *p = end_ext_octet;
+    1056                 :            :                 }
+    1057                 :            :         }
+    1058                 :            :     }
+    1059                 :            : 
+    1060         [ -  + ]:      12125 :     if (*p != end) {
+    1061                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
+    1062                 :            :                                  MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
+    1063                 :            :     }
+    1064                 :            : 
+    1065                 :      12125 :     return 0;
+    1066                 :            : }
+    1067                 :            : 
+    1068                 :            : /*
+    1069                 :            :  * Parse and fill a single X.509 certificate in DER format
+    1070                 :            :  */
+    1071                 :      12125 : static int x509_crt_parse_der_core(mbedtls_x509_crt *crt,
+    1072                 :            :                                    const unsigned char *buf,
+    1073                 :            :                                    size_t buflen,
+    1074                 :            :                                    int make_copy,
+    1075                 :            :                                    mbedtls_x509_crt_ext_cb_t cb,
+    1076                 :            :                                    void *p_ctx)
+    1077                 :            : {
+    1078                 :      12125 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1079                 :            :     size_t len;
+    1080                 :            :     unsigned char *p, *end, *crt_end;
+    1081                 :            :     mbedtls_x509_buf sig_params1, sig_params2, sig_oid2;
+    1082                 :            : 
+    1083                 :      12125 :     memset(&sig_params1, 0, sizeof(mbedtls_x509_buf));
+    1084                 :      12125 :     memset(&sig_params2, 0, sizeof(mbedtls_x509_buf));
+    1085                 :      12125 :     memset(&sig_oid2, 0, sizeof(mbedtls_x509_buf));
+    1086                 :            : 
+    1087                 :            :     /*
+    1088                 :            :      * Check for valid input
+    1089                 :            :      */
+    1090   [ +  -  -  + ]:      12125 :     if (crt == NULL || buf == NULL) {
+    1091                 :          0 :         return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
+    1092                 :            :     }
+    1093                 :            : 
+    1094                 :            :     /* Use the original buffer until we figure out actual length. */
+    1095                 :      12125 :     p = (unsigned char *) buf;
+    1096                 :      12125 :     len = buflen;
+    1097                 :      12125 :     end = p + len;
+    1098                 :            : 
+    1099                 :            :     /*
+    1100                 :            :      * Certificate  ::=  SEQUENCE  {
+    1101                 :            :      *      tbsCertificate       TBSCertificate,
+    1102                 :            :      *      signatureAlgorithm   AlgorithmIdentifier,
+    1103                 :            :      *      signatureValue       BIT STRING  }
+    1104                 :            :      */
+    1105         [ -  + ]:      12125 :     if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
+    1106                 :            :                                     MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
+    1107                 :          0 :         mbedtls_x509_crt_free(crt);
+    1108                 :          0 :         return MBEDTLS_ERR_X509_INVALID_FORMAT;
+    1109                 :            :     }
+    1110                 :            : 
+    1111                 :      12125 :     end = crt_end = p + len;
+    1112                 :      12125 :     crt->raw.len = (size_t) (crt_end - buf);
+    1113         [ +  - ]:      12125 :     if (make_copy != 0) {
+    1114                 :            :         /* Create and populate a new buffer for the raw field. */
+    1115                 :      12125 :         crt->raw.p = p = mbedtls_calloc(1, crt->raw.len);
+    1116         [ -  + ]:      12125 :         if (crt->raw.p == NULL) {
+    1117                 :          0 :             return MBEDTLS_ERR_X509_ALLOC_FAILED;
+    1118                 :            :         }
+    1119                 :            : 
+    1120                 :      12125 :         memcpy(crt->raw.p, buf, crt->raw.len);
+    1121                 :      12125 :         crt->own_buffer = 1;
+    1122                 :            : 
+    1123                 :      12125 :         p += crt->raw.len - len;
+    1124                 :      12125 :         end = crt_end = p + len;
+    1125                 :            :     } else {
+    1126                 :          0 :         crt->raw.p = (unsigned char *) buf;
+    1127                 :          0 :         crt->own_buffer = 0;
+    1128                 :            :     }
+    1129                 :            : 
+    1130                 :            :     /*
+    1131                 :            :      * TBSCertificate  ::=  SEQUENCE  {
+    1132                 :            :      */
+    1133                 :      12125 :     crt->tbs.p = p;
+    1134                 :            : 
+    1135         [ -  + ]:      12125 :     if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
+    1136                 :            :                                     MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
+    1137                 :          0 :         mbedtls_x509_crt_free(crt);
+    1138                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_FORMAT, ret);
+    1139                 :            :     }
+    1140                 :            : 
+    1141                 :      12125 :     end = p + len;
+    1142                 :      12125 :     crt->tbs.len = (size_t) (end - crt->tbs.p);
+    1143                 :            : 
+    1144                 :            :     /*
+    1145                 :            :      * Version  ::=  INTEGER  {  v1(0), v2(1), v3(2)  }
+    1146                 :            :      *
+    1147                 :            :      * CertificateSerialNumber  ::=  INTEGER
+    1148                 :            :      *
+    1149                 :            :      * signature            AlgorithmIdentifier
+    1150                 :            :      */
+    1151   [ +  -  +  - ]:      24250 :     if ((ret = x509_get_version(&p, end, &crt->version)) != 0 ||
+    1152         [ -  + ]:      24250 :         (ret = mbedtls_x509_get_serial(&p, end, &crt->serial)) != 0 ||
+    1153                 :      12125 :         (ret = mbedtls_x509_get_alg(&p, end, &crt->sig_oid,
+    1154                 :            :                                     &sig_params1)) != 0) {
+    1155                 :          0 :         mbedtls_x509_crt_free(crt);
+    1156                 :          0 :         return ret;
+    1157                 :            :     }
+    1158                 :            : 
+    1159   [ +  -  -  + ]:      12125 :     if (crt->version < 0 || crt->version > 2) {
+    1160                 :          0 :         mbedtls_x509_crt_free(crt);
+    1161                 :          0 :         return MBEDTLS_ERR_X509_UNKNOWN_VERSION;
+    1162                 :            :     }
+    1163                 :            : 
+    1164                 :      12125 :     crt->version++;
+    1165                 :            : 
+    1166         [ -  + ]:      12125 :     if ((ret = mbedtls_x509_get_sig_alg(&crt->sig_oid, &sig_params1,
+    1167                 :            :                                         &crt->sig_md, &crt->sig_pk,
+    1168                 :            :                                         &crt->sig_opts)) != 0) {
+    1169                 :          0 :         mbedtls_x509_crt_free(crt);
+    1170                 :          0 :         return ret;
+    1171                 :            :     }
+    1172                 :            : 
+    1173                 :            :     /*
+    1174                 :            :      * issuer               Name
+    1175                 :            :      */
+    1176                 :      12125 :     crt->issuer_raw.p = p;
+    1177                 :            : 
+    1178         [ -  + ]:      12125 :     if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
+    1179                 :            :                                     MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
+    1180                 :          0 :         mbedtls_x509_crt_free(crt);
+    1181                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_FORMAT, ret);
+    1182                 :            :     }
+    1183                 :            : 
+    1184         [ -  + ]:      12125 :     if ((ret = mbedtls_x509_get_name(&p, p + len, &crt->issuer)) != 0) {
+    1185                 :          0 :         mbedtls_x509_crt_free(crt);
+    1186                 :          0 :         return ret;
+    1187                 :            :     }
+    1188                 :            : 
+    1189                 :      12125 :     crt->issuer_raw.len = (size_t) (p - crt->issuer_raw.p);
+    1190                 :            : 
+    1191                 :            :     /*
+    1192                 :            :      * Validity ::= SEQUENCE {
+    1193                 :            :      *      notBefore      Time,
+    1194                 :            :      *      notAfter       Time }
+    1195                 :            :      *
+    1196                 :            :      */
+    1197         [ -  + ]:      12125 :     if ((ret = x509_get_dates(&p, end, &crt->valid_from,
+    1198                 :            :                               &crt->valid_to)) != 0) {
+    1199                 :          0 :         mbedtls_x509_crt_free(crt);
+    1200                 :          0 :         return ret;
+    1201                 :            :     }
+    1202                 :            : 
+    1203                 :            :     /*
+    1204                 :            :      * subject              Name
+    1205                 :            :      */
+    1206                 :      12125 :     crt->subject_raw.p = p;
+    1207                 :            : 
+    1208         [ -  + ]:      12125 :     if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
+    1209                 :            :                                     MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
+    1210                 :          0 :         mbedtls_x509_crt_free(crt);
+    1211                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_FORMAT, ret);
+    1212                 :            :     }
+    1213                 :            : 
+    1214   [ +  -  -  + ]:      12125 :     if (len && (ret = mbedtls_x509_get_name(&p, p + len, &crt->subject)) != 0) {
+    1215                 :          0 :         mbedtls_x509_crt_free(crt);
+    1216                 :          0 :         return ret;
+    1217                 :            :     }
+    1218                 :            : 
+    1219                 :      12125 :     crt->subject_raw.len = (size_t) (p - crt->subject_raw.p);
+    1220                 :            : 
+    1221                 :            :     /*
+    1222                 :            :      * SubjectPublicKeyInfo
+    1223                 :            :      */
+    1224                 :      12125 :     crt->pk_raw.p = p;
+    1225         [ -  + ]:      12125 :     if ((ret = mbedtls_pk_parse_subpubkey(&p, end, &crt->pk)) != 0) {
+    1226                 :          0 :         mbedtls_x509_crt_free(crt);
+    1227                 :          0 :         return ret;
+    1228                 :            :     }
+    1229                 :      12125 :     crt->pk_raw.len = (size_t) (p - crt->pk_raw.p);
+    1230                 :            : 
+    1231                 :            :     /*
+    1232                 :            :      *  issuerUniqueID  [1]  IMPLICIT UniqueIdentifier OPTIONAL,
+    1233                 :            :      *                       -- If present, version shall be v2 or v3
+    1234                 :            :      *  subjectUniqueID [2]  IMPLICIT UniqueIdentifier OPTIONAL,
+    1235                 :            :      *                       -- If present, version shall be v2 or v3
+    1236                 :            :      *  extensions      [3]  EXPLICIT Extensions OPTIONAL
+    1237                 :            :      *                       -- If present, version shall be v3
+    1238                 :            :      */
+    1239   [ +  -  +  - ]:      12125 :     if (crt->version == 2 || crt->version == 3) {
+    1240                 :      12125 :         ret = x509_get_uid(&p, end, &crt->issuer_id,  1);
+    1241         [ -  + ]:      12125 :         if (ret != 0) {
+    1242                 :          0 :             mbedtls_x509_crt_free(crt);
+    1243                 :          0 :             return ret;
+    1244                 :            :         }
+    1245                 :            :     }
+    1246                 :            : 
+    1247   [ +  -  +  - ]:      12125 :     if (crt->version == 2 || crt->version == 3) {
+    1248                 :      12125 :         ret = x509_get_uid(&p, end, &crt->subject_id,  2);
+    1249         [ -  + ]:      12125 :         if (ret != 0) {
+    1250                 :          0 :             mbedtls_x509_crt_free(crt);
+    1251                 :          0 :             return ret;
+    1252                 :            :         }
+    1253                 :            :     }
+    1254                 :            : 
+    1255         [ +  - ]:      12125 :     if (crt->version == 3) {
+    1256                 :      12125 :         ret = x509_get_crt_ext(&p, end, crt, cb, p_ctx);
+    1257         [ -  + ]:      12125 :         if (ret != 0) {
+    1258                 :          0 :             mbedtls_x509_crt_free(crt);
+    1259                 :          0 :             return ret;
+    1260                 :            :         }
+    1261                 :            :     }
+    1262                 :            : 
+    1263         [ -  + ]:      12125 :     if (p != end) {
+    1264                 :          0 :         mbedtls_x509_crt_free(crt);
+    1265                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_FORMAT,
+    1266                 :            :                                  MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
+    1267                 :            :     }
+    1268                 :            : 
+    1269                 :      12125 :     end = crt_end;
+    1270                 :            : 
+    1271                 :            :     /*
+    1272                 :            :      *  }
+    1273                 :            :      *  -- end of TBSCertificate
+    1274                 :            :      *
+    1275                 :            :      *  signatureAlgorithm   AlgorithmIdentifier,
+    1276                 :            :      *  signatureValue       BIT STRING
+    1277                 :            :      */
+    1278         [ -  + ]:      12125 :     if ((ret = mbedtls_x509_get_alg(&p, end, &sig_oid2, &sig_params2)) != 0) {
+    1279                 :          0 :         mbedtls_x509_crt_free(crt);
+    1280                 :          0 :         return ret;
+    1281                 :            :     }
+    1282                 :            : 
+    1283         [ +  - ]:      12125 :     if (crt->sig_oid.len != sig_oid2.len ||
+    1284         [ +  - ]:      12125 :         memcmp(crt->sig_oid.p, sig_oid2.p, crt->sig_oid.len) != 0 ||
+    1285         [ +  - ]:      12125 :         sig_params1.tag != sig_params2.tag ||
+    1286         [ +  - ]:      12125 :         sig_params1.len != sig_params2.len ||
+    1287         [ -  + ]:      12125 :         (sig_params1.len != 0 &&
+    1288         [ #  # ]:          0 :          memcmp(sig_params1.p, sig_params2.p, sig_params1.len) != 0)) {
+    1289                 :          0 :         mbedtls_x509_crt_free(crt);
+    1290                 :          0 :         return MBEDTLS_ERR_X509_SIG_MISMATCH;
+    1291                 :            :     }
+    1292                 :            : 
+    1293         [ -  + ]:      12125 :     if ((ret = mbedtls_x509_get_sig(&p, end, &crt->sig)) != 0) {
+    1294                 :          0 :         mbedtls_x509_crt_free(crt);
+    1295                 :          0 :         return ret;
+    1296                 :            :     }
+    1297                 :            : 
+    1298         [ -  + ]:      12125 :     if (p != end) {
+    1299                 :          0 :         mbedtls_x509_crt_free(crt);
+    1300                 :          0 :         return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_FORMAT,
+    1301                 :            :                                  MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
+    1302                 :            :     }
+    1303                 :            : 
+    1304                 :      12125 :     return 0;
+    1305                 :            : }
+    1306                 :            : 
+    1307                 :            : /*
+    1308                 :            :  * Parse one X.509 certificate in DER format from a buffer and add them to a
+    1309                 :            :  * chained list
+    1310                 :            :  */
+    1311                 :      12125 : static int mbedtls_x509_crt_parse_der_internal(mbedtls_x509_crt *chain,
+    1312                 :            :                                                const unsigned char *buf,
+    1313                 :            :                                                size_t buflen,
+    1314                 :            :                                                int make_copy,
+    1315                 :            :                                                mbedtls_x509_crt_ext_cb_t cb,
+    1316                 :            :                                                void *p_ctx)
+    1317                 :            : {
+    1318                 :      12125 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1319                 :      12125 :     mbedtls_x509_crt *crt = chain, *prev = NULL;
+    1320                 :            : 
+    1321                 :            :     /*
+    1322                 :            :      * Check for valid input
+    1323                 :            :      */
+    1324   [ +  -  -  + ]:      12125 :     if (crt == NULL || buf == NULL) {
+    1325                 :          0 :         return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
+    1326                 :            :     }
+    1327                 :            : 
+    1328   [ -  +  -  - ]:      12125 :     while (crt->version != 0 && crt->next != NULL) {
+    1329                 :          0 :         prev = crt;
+    1330                 :          0 :         crt = crt->next;
+    1331                 :            :     }
+    1332                 :            : 
+    1333                 :            :     /*
+    1334                 :            :      * Add new certificate on the end of the chain if needed.
+    1335                 :            :      */
+    1336   [ -  +  -  - ]:      12125 :     if (crt->version != 0 && crt->next == NULL) {
+    1337                 :          0 :         crt->next = mbedtls_calloc(1, sizeof(mbedtls_x509_crt));
+    1338                 :            : 
+    1339         [ #  # ]:          0 :         if (crt->next == NULL) {
+    1340                 :          0 :             return MBEDTLS_ERR_X509_ALLOC_FAILED;
+    1341                 :            :         }
+    1342                 :            : 
+    1343                 :          0 :         prev = crt;
+    1344                 :          0 :         mbedtls_x509_crt_init(crt->next);
+    1345                 :          0 :         crt = crt->next;
+    1346                 :            :     }
+    1347                 :            : 
+    1348                 :      12125 :     ret = x509_crt_parse_der_core(crt, buf, buflen, make_copy, cb, p_ctx);
+    1349         [ -  + ]:      12125 :     if (ret != 0) {
+    1350         [ #  # ]:          0 :         if (prev) {
+    1351                 :          0 :             prev->next = NULL;
+    1352                 :            :         }
+    1353                 :            : 
+    1354         [ #  # ]:          0 :         if (crt != chain) {
+    1355                 :          0 :             mbedtls_free(crt);
+    1356                 :            :         }
+    1357                 :            : 
+    1358                 :          0 :         return ret;
+    1359                 :            :     }
+    1360                 :            : 
+    1361                 :      12125 :     return 0;
+    1362                 :            : }
+    1363                 :            : 
+    1364                 :          0 : int mbedtls_x509_crt_parse_der_nocopy(mbedtls_x509_crt *chain,
+    1365                 :            :                                       const unsigned char *buf,
+    1366                 :            :                                       size_t buflen)
+    1367                 :            : {
+    1368                 :          0 :     return mbedtls_x509_crt_parse_der_internal(chain, buf, buflen, 0, NULL, NULL);
+    1369                 :            : }
+    1370                 :            : 
+    1371                 :          0 : int mbedtls_x509_crt_parse_der_with_ext_cb(mbedtls_x509_crt *chain,
+    1372                 :            :                                            const unsigned char *buf,
+    1373                 :            :                                            size_t buflen,
+    1374                 :            :                                            int make_copy,
+    1375                 :            :                                            mbedtls_x509_crt_ext_cb_t cb,
+    1376                 :            :                                            void *p_ctx)
+    1377                 :            : {
+    1378                 :          0 :     return mbedtls_x509_crt_parse_der_internal(chain, buf, buflen, make_copy, cb, p_ctx);
+    1379                 :            : }
+    1380                 :            : 
+    1381                 :      12125 : int mbedtls_x509_crt_parse_der(mbedtls_x509_crt *chain,
+    1382                 :            :                                const unsigned char *buf,
+    1383                 :            :                                size_t buflen)
+    1384                 :            : {
+    1385                 :      12125 :     return mbedtls_x509_crt_parse_der_internal(chain, buf, buflen, 1, NULL, NULL);
+    1386                 :            : }
+    1387                 :            : 
+    1388                 :            : /*
+    1389                 :            :  * Parse one or more PEM certificates from a buffer and add them to the chained
+    1390                 :            :  * list
+    1391                 :            :  */
+    1392                 :          0 : int mbedtls_x509_crt_parse(mbedtls_x509_crt *chain,
+    1393                 :            :                            const unsigned char *buf,
+    1394                 :            :                            size_t buflen)
+    1395                 :            : {
+    1396                 :            : #if defined(MBEDTLS_PEM_PARSE_C)
+    1397                 :          0 :     int success = 0, first_error = 0, total_failed = 0;
+    1398                 :          0 :     int buf_format = MBEDTLS_X509_FORMAT_DER;
+    1399                 :            : #endif
+    1400                 :            : 
+    1401                 :            :     /*
+    1402                 :            :      * Check for valid input
+    1403                 :            :      */
+    1404   [ #  #  #  # ]:          0 :     if (chain == NULL || buf == NULL) {
+    1405                 :          0 :         return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
+    1406                 :            :     }
+    1407                 :            : 
+    1408                 :            :     /*
+    1409                 :            :      * Determine buffer content. Buffer contains either one DER certificate or
+    1410                 :            :      * one or more PEM certificates.
+    1411                 :            :      */
+    1412                 :            : #if defined(MBEDTLS_PEM_PARSE_C)
+    1413   [ #  #  #  # ]:          0 :     if (buflen != 0 && buf[buflen - 1] == '\0' &&
+    1414         [ #  # ]:          0 :         strstr((const char *) buf, "-----BEGIN CERTIFICATE-----") != NULL) {
+    1415                 :          0 :         buf_format = MBEDTLS_X509_FORMAT_PEM;
+    1416                 :            :     }
+    1417                 :            : 
+    1418         [ #  # ]:          0 :     if (buf_format == MBEDTLS_X509_FORMAT_DER) {
+    1419                 :          0 :         return mbedtls_x509_crt_parse_der(chain, buf, buflen);
+    1420                 :            :     }
+    1421                 :            : #else
+    1422                 :            :     return mbedtls_x509_crt_parse_der(chain, buf, buflen);
+    1423                 :            : #endif
+    1424                 :            : 
+    1425                 :            : #if defined(MBEDTLS_PEM_PARSE_C)
+    1426         [ #  # ]:          0 :     if (buf_format == MBEDTLS_X509_FORMAT_PEM) {
+    1427                 :          0 :         int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1428                 :            :         mbedtls_pem_context pem;
+    1429                 :            : 
+    1430                 :            :         /* 1 rather than 0 since the terminating NULL byte is counted in */
+    1431         [ #  # ]:          0 :         while (buflen > 1) {
+    1432                 :            :             size_t use_len;
+    1433                 :          0 :             mbedtls_pem_init(&pem);
+    1434                 :            : 
+    1435                 :            :             /* If we get there, we know the string is null-terminated */
+    1436                 :          0 :             ret = mbedtls_pem_read_buffer(&pem,
+    1437                 :            :                                           "-----BEGIN CERTIFICATE-----",
+    1438                 :            :                                           "-----END CERTIFICATE-----",
+    1439                 :            :                                           buf, NULL, 0, &use_len);
+    1440                 :            : 
+    1441         [ #  # ]:          0 :             if (ret == 0) {
+    1442                 :            :                 /*
+    1443                 :            :                  * Was PEM encoded
+    1444                 :            :                  */
+    1445                 :          0 :                 buflen -= use_len;
+    1446                 :          0 :                 buf += use_len;
+    1447         [ #  # ]:          0 :             } else if (ret == MBEDTLS_ERR_PEM_BAD_INPUT_DATA) {
+    1448                 :          0 :                 return ret;
+    1449         [ #  # ]:          0 :             } else if (ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) {
+    1450                 :          0 :                 mbedtls_pem_free(&pem);
+    1451                 :            : 
+    1452                 :            :                 /*
+    1453                 :            :                  * PEM header and footer were found
+    1454                 :            :                  */
+    1455                 :          0 :                 buflen -= use_len;
+    1456                 :          0 :                 buf += use_len;
+    1457                 :            : 
+    1458         [ #  # ]:          0 :                 if (first_error == 0) {
+    1459                 :          0 :                     first_error = ret;
+    1460                 :            :                 }
+    1461                 :            : 
+    1462                 :          0 :                 total_failed++;
+    1463                 :          0 :                 continue;
+    1464                 :            :             } else {
+    1465                 :          0 :                 break;
+    1466                 :            :             }
+    1467                 :            : 
+    1468                 :          0 :             ret = mbedtls_x509_crt_parse_der(chain, pem.buf, pem.buflen);
+    1469                 :            : 
+    1470                 :          0 :             mbedtls_pem_free(&pem);
+    1471                 :            : 
+    1472         [ #  # ]:          0 :             if (ret != 0) {
+    1473                 :            :                 /*
+    1474                 :            :                  * Quit parsing on a memory error
+    1475                 :            :                  */
+    1476         [ #  # ]:          0 :                 if (ret == MBEDTLS_ERR_X509_ALLOC_FAILED) {
+    1477                 :          0 :                     return ret;
+    1478                 :            :                 }
+    1479                 :            : 
+    1480         [ #  # ]:          0 :                 if (first_error == 0) {
+    1481                 :          0 :                     first_error = ret;
+    1482                 :            :                 }
+    1483                 :            : 
+    1484                 :          0 :                 total_failed++;
+    1485                 :          0 :                 continue;
+    1486                 :            :             }
+    1487                 :            : 
+    1488                 :          0 :             success = 1;
+    1489                 :            :         }
+    1490                 :            :     }
+    1491                 :            : 
+    1492         [ #  # ]:          0 :     if (success) {
+    1493                 :          0 :         return total_failed;
+    1494         [ #  # ]:          0 :     } else if (first_error) {
+    1495                 :          0 :         return first_error;
+    1496                 :            :     } else {
+    1497                 :          0 :         return MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT;
+    1498                 :            :     }
+    1499                 :            : #endif /* MBEDTLS_PEM_PARSE_C */
+    1500                 :            : }
+    1501                 :            : 
+    1502                 :            : #if defined(MBEDTLS_FS_IO)
+    1503                 :            : /*
+    1504                 :            :  * Load one or more certificates and add them to the chained list
+    1505                 :            :  */
+    1506                 :            : int mbedtls_x509_crt_parse_file(mbedtls_x509_crt *chain, const char *path)
+    1507                 :            : {
+    1508                 :            :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1509                 :            :     size_t n;
+    1510                 :            :     unsigned char *buf;
+    1511                 :            : 
+    1512                 :            :     if ((ret = mbedtls_pk_load_file(path, &buf, &n)) != 0) {
+    1513                 :            :         return ret;
+    1514                 :            :     }
+    1515                 :            : 
+    1516                 :            :     ret = mbedtls_x509_crt_parse(chain, buf, n);
+    1517                 :            : 
+    1518                 :            :     mbedtls_zeroize_and_free(buf, n);
+    1519                 :            : 
+    1520                 :            :     return ret;
+    1521                 :            : }
+    1522                 :            : 
+    1523                 :            : int mbedtls_x509_crt_parse_path(mbedtls_x509_crt *chain, const char *path)
+    1524                 :            : {
+    1525                 :            :     int ret = 0;
+    1526                 :            : #if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32)
+    1527                 :            :     int w_ret;
+    1528                 :            :     WCHAR szDir[MAX_PATH];
+    1529                 :            :     char filename[MAX_PATH];
+    1530                 :            :     char *p;
+    1531                 :            :     size_t len = strlen(path);
+    1532                 :            : 
+    1533                 :            :     WIN32_FIND_DATAW file_data;
+    1534                 :            :     HANDLE hFind;
+    1535                 :            : 
+    1536                 :            :     if (len > MAX_PATH - 3) {
+    1537                 :            :         return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
+    1538                 :            :     }
+    1539                 :            : 
+    1540                 :            :     memset(szDir, 0, sizeof(szDir));
+    1541                 :            :     memset(filename, 0, MAX_PATH);
+    1542                 :            :     memcpy(filename, path, len);
+    1543                 :            :     filename[len++] = '\\';
+    1544                 :            :     p = filename + len;
+    1545                 :            :     filename[len++] = '*';
+    1546                 :            : 
+    1547                 :            :     /*
+    1548                 :            :      * Note this function uses the code page CP_ACP which is the system default
+    1549                 :            :      * ANSI codepage. The input string is always described in BYTES and the
+    1550                 :            :      * output length is described in WCHARs.
+    1551                 :            :      */
+    1552                 :            :     w_ret = MultiByteToWideChar(CP_ACP, 0, filename, (int) len, szDir,
+    1553                 :            :                                 MAX_PATH - 3);
+    1554                 :            :     if (w_ret == 0) {
+    1555                 :            :         return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
+    1556                 :            :     }
+    1557                 :            : 
+    1558                 :            :     hFind = FindFirstFileW(szDir, &file_data);
+    1559                 :            :     if (hFind == INVALID_HANDLE_VALUE) {
+    1560                 :            :         return MBEDTLS_ERR_X509_FILE_IO_ERROR;
+    1561                 :            :     }
+    1562                 :            : 
+    1563                 :            :     len = MAX_PATH - len;
+    1564                 :            :     do {
+    1565                 :            :         memset(p, 0, len);
+    1566                 :            : 
+    1567                 :            :         if (file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
+    1568                 :            :             continue;
+    1569                 :            :         }
+    1570                 :            :         w_ret = WideCharToMultiByte(CP_ACP, 0, file_data.cFileName,
+    1571                 :            :                                     -1, p, (int) len, NULL, NULL);
+    1572                 :            :         if (w_ret == 0) {
+    1573                 :            :             ret = MBEDTLS_ERR_X509_FILE_IO_ERROR;
+    1574                 :            :             goto cleanup;
+    1575                 :            :         }
+    1576                 :            : 
+    1577                 :            :         w_ret = mbedtls_x509_crt_parse_file(chain, filename);
+    1578                 :            :         if (w_ret < 0) {
+    1579                 :            :             ret++;
+    1580                 :            :         } else {
+    1581                 :            :             ret += w_ret;
+    1582                 :            :         }
+    1583                 :            :     } while (FindNextFileW(hFind, &file_data) != 0);
+    1584                 :            : 
+    1585                 :            :     if (GetLastError() != ERROR_NO_MORE_FILES) {
+    1586                 :            :         ret = MBEDTLS_ERR_X509_FILE_IO_ERROR;
+    1587                 :            :     }
+    1588                 :            : 
+    1589                 :            : cleanup:
+    1590                 :            :     FindClose(hFind);
+    1591                 :            : #else /* _WIN32 */
+    1592                 :            :     int t_ret;
+    1593                 :            :     int snp_ret;
+    1594                 :            :     struct stat sb;
+    1595                 :            :     struct dirent *entry;
+    1596                 :            :     char entry_name[MBEDTLS_X509_MAX_FILE_PATH_LEN];
+    1597                 :            :     DIR *dir = opendir(path);
+    1598                 :            : 
+    1599                 :            :     if (dir == NULL) {
+    1600                 :            :         return MBEDTLS_ERR_X509_FILE_IO_ERROR;
+    1601                 :            :     }
+    1602                 :            : 
+    1603                 :            : #if defined(MBEDTLS_THREADING_C)
+    1604                 :            :     if ((ret = mbedtls_mutex_lock(&mbedtls_threading_readdir_mutex)) != 0) {
+    1605                 :            :         closedir(dir);
+    1606                 :            :         return ret;
+    1607                 :            :     }
+    1608                 :            : #endif /* MBEDTLS_THREADING_C */
+    1609                 :            : 
+    1610                 :            :     memset(&sb, 0, sizeof(sb));
+    1611                 :            : 
+    1612                 :            :     while ((entry = readdir(dir)) != NULL) {
+    1613                 :            :         snp_ret = mbedtls_snprintf(entry_name, sizeof(entry_name),
+    1614                 :            :                                    "%s/%s", path, entry->d_name);
+    1615                 :            : 
+    1616                 :            :         if (snp_ret < 0 || (size_t) snp_ret >= sizeof(entry_name)) {
+    1617                 :            :             ret = MBEDTLS_ERR_X509_BUFFER_TOO_SMALL;
+    1618                 :            :             goto cleanup;
+    1619                 :            :         } else if (stat(entry_name, &sb) == -1) {
+    1620                 :            :             if (errno == ENOENT) {
+    1621                 :            :                 /* Broken symbolic link - ignore this entry.
+    1622                 :            :                     stat(2) will return this error for either (a) a dangling
+    1623                 :            :                     symlink or (b) a missing file.
+    1624                 :            :                     Given that we have just obtained the filename from readdir,
+    1625                 :            :                     assume that it does exist and therefore treat this as a
+    1626                 :            :                     dangling symlink. */
+    1627                 :            :                 continue;
+    1628                 :            :             } else {
+    1629                 :            :                 /* Some other file error; report the error. */
+    1630                 :            :                 ret = MBEDTLS_ERR_X509_FILE_IO_ERROR;
+    1631                 :            :                 goto cleanup;
+    1632                 :            :             }
+    1633                 :            :         }
+    1634                 :            : 
+    1635                 :            :         if (!S_ISREG(sb.st_mode)) {
+    1636                 :            :             continue;
+    1637                 :            :         }
+    1638                 :            : 
+    1639                 :            :         // Ignore parse errors
+    1640                 :            :         //
+    1641                 :            :         t_ret = mbedtls_x509_crt_parse_file(chain, entry_name);
+    1642                 :            :         if (t_ret < 0) {
+    1643                 :            :             ret++;
+    1644                 :            :         } else {
+    1645                 :            :             ret += t_ret;
+    1646                 :            :         }
+    1647                 :            :     }
+    1648                 :            : 
+    1649                 :            : cleanup:
+    1650                 :            :     closedir(dir);
+    1651                 :            : 
+    1652                 :            : #if defined(MBEDTLS_THREADING_C)
+    1653                 :            :     if (mbedtls_mutex_unlock(&mbedtls_threading_readdir_mutex) != 0) {
+    1654                 :            :         ret = MBEDTLS_ERR_THREADING_MUTEX_ERROR;
+    1655                 :            :     }
+    1656                 :            : #endif /* MBEDTLS_THREADING_C */
+    1657                 :            : 
+    1658                 :            : #endif /* _WIN32 */
+    1659                 :            : 
+    1660                 :            :     return ret;
+    1661                 :            : }
+    1662                 :            : #endif /* MBEDTLS_FS_IO */
+    1663                 :            : 
+    1664                 :            : #if !defined(MBEDTLS_X509_REMOVE_INFO)
+    1665                 :            : #define PRINT_ITEM(i)                               \
+    1666                 :            :     do {                                            \
+    1667                 :            :         ret = mbedtls_snprintf(p, n, "%s" i, sep);  \
+    1668                 :            :         MBEDTLS_X509_SAFE_SNPRINTF;                 \
+    1669                 :            :         sep = ", ";                                 \
+    1670                 :            :     } while (0)
+    1671                 :            : 
+    1672                 :            : #define CERT_TYPE(type, name)          \
+    1673                 :            :     do {                               \
+    1674                 :            :         if (ns_cert_type & (type)) {   \
+    1675                 :            :             PRINT_ITEM(name);          \
+    1676                 :            :         }                              \
+    1677                 :            :     } while (0)
+    1678                 :            : 
+    1679                 :            : #define KEY_USAGE(code, name)      \
+    1680                 :            :     do {                           \
+    1681                 :            :         if (key_usage & (code)) {  \
+    1682                 :            :             PRINT_ITEM(name);      \
+    1683                 :            :         }                          \
+    1684                 :            :     } while (0)
+    1685                 :            : 
+    1686                 :          0 : static int x509_info_ext_key_usage(char **buf, size_t *size,
+    1687                 :            :                                    const mbedtls_x509_sequence *extended_key_usage)
+    1688                 :            : {
+    1689                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1690                 :            :     const char *desc;
+    1691                 :          0 :     size_t n = *size;
+    1692                 :          0 :     char *p = *buf;
+    1693                 :          0 :     const mbedtls_x509_sequence *cur = extended_key_usage;
+    1694                 :          0 :     const char *sep = "";
+    1695                 :            : 
+    1696         [ #  # ]:          0 :     while (cur != NULL) {
+    1697         [ #  # ]:          0 :         if (mbedtls_oid_get_extended_key_usage(&cur->buf, &desc) != 0) {
+    1698                 :          0 :             desc = "???";
+    1699                 :            :         }
+    1700                 :            : 
+    1701                 :          0 :         ret = mbedtls_snprintf(p, n, "%s%s", sep, desc);
+    1702   [ #  #  #  # ]:          0 :         MBEDTLS_X509_SAFE_SNPRINTF;
+    1703                 :            : 
+    1704                 :          0 :         sep = ", ";
+    1705                 :            : 
+    1706                 :          0 :         cur = cur->next;
+    1707                 :            :     }
+    1708                 :            : 
+    1709                 :          0 :     *size = n;
+    1710                 :          0 :     *buf = p;
+    1711                 :            : 
+    1712                 :          0 :     return 0;
+    1713                 :            : }
+    1714                 :            : 
+    1715                 :          0 : static int x509_info_cert_policies(char **buf, size_t *size,
+    1716                 :            :                                    const mbedtls_x509_sequence *certificate_policies)
+    1717                 :            : {
+    1718                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1719                 :            :     const char *desc;
+    1720                 :          0 :     size_t n = *size;
+    1721                 :          0 :     char *p = *buf;
+    1722                 :          0 :     const mbedtls_x509_sequence *cur = certificate_policies;
+    1723                 :          0 :     const char *sep = "";
+    1724                 :            : 
+    1725         [ #  # ]:          0 :     while (cur != NULL) {
+    1726         [ #  # ]:          0 :         if (mbedtls_oid_get_certificate_policies(&cur->buf, &desc) != 0) {
+    1727                 :          0 :             desc = "???";
+    1728                 :            :         }
+    1729                 :            : 
+    1730                 :          0 :         ret = mbedtls_snprintf(p, n, "%s%s", sep, desc);
+    1731   [ #  #  #  # ]:          0 :         MBEDTLS_X509_SAFE_SNPRINTF;
+    1732                 :            : 
+    1733                 :          0 :         sep = ", ";
+    1734                 :            : 
+    1735                 :          0 :         cur = cur->next;
+    1736                 :            :     }
+    1737                 :            : 
+    1738                 :          0 :     *size = n;
+    1739                 :          0 :     *buf = p;
+    1740                 :            : 
+    1741                 :          0 :     return 0;
+    1742                 :            : }
+    1743                 :            : 
+    1744                 :            : /*
+    1745                 :            :  * Return an informational string about the certificate.
+    1746                 :            :  */
+    1747                 :            : #define BEFORE_COLON    18
+    1748                 :            : #define BC              "18"
+    1749                 :          0 : int mbedtls_x509_crt_info(char *buf, size_t size, const char *prefix,
+    1750                 :            :                           const mbedtls_x509_crt *crt)
+    1751                 :            : {
+    1752                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1753                 :            :     size_t n;
+    1754                 :            :     char *p;
+    1755                 :            :     char key_size_str[BEFORE_COLON];
+    1756                 :            : 
+    1757                 :          0 :     p = buf;
+    1758                 :          0 :     n = size;
+    1759                 :            : 
+    1760         [ #  # ]:          0 :     if (NULL == crt) {
+    1761                 :          0 :         ret = mbedtls_snprintf(p, n, "\nCertificate is uninitialised!\n");
+    1762   [ #  #  #  # ]:          0 :         MBEDTLS_X509_SAFE_SNPRINTF;
+    1763                 :            : 
+    1764                 :          0 :         return (int) (size - n);
+    1765                 :            :     }
+    1766                 :            : 
+    1767                 :          0 :     ret = mbedtls_snprintf(p, n, "%scert. version     : %d\n",
+    1768                 :          0 :                            prefix, crt->version);
+    1769   [ #  #  #  # ]:          0 :     MBEDTLS_X509_SAFE_SNPRINTF;
+    1770                 :          0 :     ret = mbedtls_snprintf(p, n, "%sserial number     : ",
+    1771                 :            :                            prefix);
+    1772   [ #  #  #  # ]:          0 :     MBEDTLS_X509_SAFE_SNPRINTF;
+    1773                 :            : 
+    1774                 :          0 :     ret = mbedtls_x509_serial_gets(p, n, &crt->serial);
+    1775   [ #  #  #  # ]:          0 :     MBEDTLS_X509_SAFE_SNPRINTF;
+    1776                 :            : 
+    1777                 :          0 :     ret = mbedtls_snprintf(p, n, "\n%sissuer name       : ", prefix);
+    1778   [ #  #  #  # ]:          0 :     MBEDTLS_X509_SAFE_SNPRINTF;
+    1779                 :          0 :     ret = mbedtls_x509_dn_gets(p, n, &crt->issuer);
+    1780   [ #  #  #  # ]:          0 :     MBEDTLS_X509_SAFE_SNPRINTF;
+    1781                 :            : 
+    1782                 :          0 :     ret = mbedtls_snprintf(p, n, "\n%ssubject name      : ", prefix);
+    1783   [ #  #  #  # ]:          0 :     MBEDTLS_X509_SAFE_SNPRINTF;
+    1784                 :          0 :     ret = mbedtls_x509_dn_gets(p, n, &crt->subject);
+    1785   [ #  #  #  # ]:          0 :     MBEDTLS_X509_SAFE_SNPRINTF;
+    1786                 :            : 
+    1787                 :          0 :     ret = mbedtls_snprintf(p, n, "\n%sissued  on        : " \
+    1788                 :            :                                  "%04d-%02d-%02d %02d:%02d:%02d", prefix,
+    1789                 :          0 :                            crt->valid_from.year, crt->valid_from.mon,
+    1790                 :          0 :                            crt->valid_from.day,  crt->valid_from.hour,
+    1791                 :          0 :                            crt->valid_from.min,  crt->valid_from.sec);
+    1792   [ #  #  #  # ]:          0 :     MBEDTLS_X509_SAFE_SNPRINTF;
+    1793                 :            : 
+    1794                 :          0 :     ret = mbedtls_snprintf(p, n, "\n%sexpires on        : " \
+    1795                 :            :                                  "%04d-%02d-%02d %02d:%02d:%02d", prefix,
+    1796                 :          0 :                            crt->valid_to.year, crt->valid_to.mon,
+    1797                 :          0 :                            crt->valid_to.day,  crt->valid_to.hour,
+    1798                 :          0 :                            crt->valid_to.min,  crt->valid_to.sec);
+    1799   [ #  #  #  # ]:          0 :     MBEDTLS_X509_SAFE_SNPRINTF;
+    1800                 :            : 
+    1801                 :          0 :     ret = mbedtls_snprintf(p, n, "\n%ssigned using      : ", prefix);
+    1802   [ #  #  #  # ]:          0 :     MBEDTLS_X509_SAFE_SNPRINTF;
+    1803                 :            : 
+    1804                 :          0 :     ret = mbedtls_x509_sig_alg_gets(p, n, &crt->sig_oid, crt->sig_pk,
+    1805                 :          0 :                                     crt->sig_md, crt->sig_opts);
+    1806   [ #  #  #  # ]:          0 :     MBEDTLS_X509_SAFE_SNPRINTF;
+    1807                 :            : 
+    1808                 :            :     /* Key size */
+    1809         [ #  # ]:          0 :     if ((ret = mbedtls_x509_key_size_helper(key_size_str, BEFORE_COLON,
+    1810                 :            :                                             mbedtls_pk_get_name(&crt->pk))) != 0) {
+    1811                 :          0 :         return ret;
+    1812                 :            :     }
+    1813                 :            : 
+    1814                 :          0 :     ret = mbedtls_snprintf(p, n, "\n%s%-" BC "s: %d bits", prefix, key_size_str,
+    1815                 :          0 :                            (int) mbedtls_pk_get_bitlen(&crt->pk));
+    1816   [ #  #  #  # ]:          0 :     MBEDTLS_X509_SAFE_SNPRINTF;
+    1817                 :            : 
+    1818                 :            :     /*
+    1819                 :            :      * Optional extensions
+    1820                 :            :      */
+    1821                 :            : 
+    1822         [ #  # ]:          0 :     if (crt->ext_types & MBEDTLS_X509_EXT_BASIC_CONSTRAINTS) {
+    1823                 :          0 :         ret = mbedtls_snprintf(p, n, "\n%sbasic constraints : CA=%s", prefix,
+    1824         [ #  # ]:          0 :                                crt->ca_istrue ? "true" : "false");
+    1825   [ #  #  #  # ]:          0 :         MBEDTLS_X509_SAFE_SNPRINTF;
+    1826                 :            : 
+    1827         [ #  # ]:          0 :         if (crt->max_pathlen > 0) {
+    1828                 :          0 :             ret = mbedtls_snprintf(p, n, ", max_pathlen=%d", crt->max_pathlen - 1);
+    1829   [ #  #  #  # ]:          0 :             MBEDTLS_X509_SAFE_SNPRINTF;
+    1830                 :            :         }
+    1831                 :            :     }
+    1832                 :            : 
+    1833         [ #  # ]:          0 :     if (crt->ext_types & MBEDTLS_X509_EXT_SUBJECT_ALT_NAME) {
+    1834                 :          0 :         ret = mbedtls_snprintf(p, n, "\n%ssubject alt name  :", prefix);
+    1835   [ #  #  #  # ]:          0 :         MBEDTLS_X509_SAFE_SNPRINTF;
+    1836                 :            : 
+    1837         [ #  # ]:          0 :         if ((ret = mbedtls_x509_info_subject_alt_name(&p, &n,
+    1838                 :            :                                                       &crt->subject_alt_names,
+    1839                 :            :                                                       prefix)) != 0) {
+    1840                 :          0 :             return ret;
+    1841                 :            :         }
+    1842                 :            :     }
+    1843                 :            : 
+    1844         [ #  # ]:          0 :     if (crt->ext_types & MBEDTLS_X509_EXT_NS_CERT_TYPE) {
+    1845                 :          0 :         ret = mbedtls_snprintf(p, n, "\n%scert. type        : ", prefix);
+    1846   [ #  #  #  # ]:          0 :         MBEDTLS_X509_SAFE_SNPRINTF;
+    1847                 :            : 
+    1848         [ #  # ]:          0 :         if ((ret = mbedtls_x509_info_cert_type(&p, &n, crt->ns_cert_type)) != 0) {
+    1849                 :          0 :             return ret;
+    1850                 :            :         }
+    1851                 :            :     }
+    1852                 :            : 
+    1853         [ #  # ]:          0 :     if (crt->ext_types & MBEDTLS_X509_EXT_KEY_USAGE) {
+    1854                 :          0 :         ret = mbedtls_snprintf(p, n, "\n%skey usage         : ", prefix);
+    1855   [ #  #  #  # ]:          0 :         MBEDTLS_X509_SAFE_SNPRINTF;
+    1856                 :            : 
+    1857         [ #  # ]:          0 :         if ((ret = mbedtls_x509_info_key_usage(&p, &n, crt->key_usage)) != 0) {
+    1858                 :          0 :             return ret;
+    1859                 :            :         }
+    1860                 :            :     }
+    1861                 :            : 
+    1862         [ #  # ]:          0 :     if (crt->ext_types & MBEDTLS_X509_EXT_EXTENDED_KEY_USAGE) {
+    1863                 :          0 :         ret = mbedtls_snprintf(p, n, "\n%sext key usage     : ", prefix);
+    1864   [ #  #  #  # ]:          0 :         MBEDTLS_X509_SAFE_SNPRINTF;
+    1865                 :            : 
+    1866         [ #  # ]:          0 :         if ((ret = x509_info_ext_key_usage(&p, &n,
+    1867                 :            :                                            &crt->ext_key_usage)) != 0) {
+    1868                 :          0 :             return ret;
+    1869                 :            :         }
+    1870                 :            :     }
+    1871                 :            : 
+    1872         [ #  # ]:          0 :     if (crt->ext_types & MBEDTLS_OID_X509_EXT_CERTIFICATE_POLICIES) {
+    1873                 :          0 :         ret = mbedtls_snprintf(p, n, "\n%scertificate policies : ", prefix);
+    1874   [ #  #  #  # ]:          0 :         MBEDTLS_X509_SAFE_SNPRINTF;
+    1875                 :            : 
+    1876         [ #  # ]:          0 :         if ((ret = x509_info_cert_policies(&p, &n,
+    1877                 :            :                                            &crt->certificate_policies)) != 0) {
+    1878                 :          0 :             return ret;
+    1879                 :            :         }
+    1880                 :            :     }
+    1881                 :            : 
+    1882                 :          0 :     ret = mbedtls_snprintf(p, n, "\n");
+    1883   [ #  #  #  # ]:          0 :     MBEDTLS_X509_SAFE_SNPRINTF;
+    1884                 :            : 
+    1885                 :          0 :     return (int) (size - n);
+    1886                 :            : }
+    1887                 :            : 
+    1888                 :            : struct x509_crt_verify_string {
+    1889                 :            :     int code;
+    1890                 :            :     const char *string;
+    1891                 :            : };
+    1892                 :            : 
+    1893                 :            : #define X509_CRT_ERROR_INFO(err, err_str, info) { err, info },
+    1894                 :            : static const struct x509_crt_verify_string x509_crt_verify_strings[] = {
+    1895                 :            :     MBEDTLS_X509_CRT_ERROR_INFO_LIST
+    1896                 :            :     { 0, NULL }
+    1897                 :            : };
+    1898                 :            : #undef X509_CRT_ERROR_INFO
+    1899                 :            : 
+    1900                 :          0 : int mbedtls_x509_crt_verify_info(char *buf, size_t size, const char *prefix,
+    1901                 :            :                                  uint32_t flags)
+    1902                 :            : {
+    1903                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    1904                 :            :     const struct x509_crt_verify_string *cur;
+    1905                 :          0 :     char *p = buf;
+    1906                 :          0 :     size_t n = size;
+    1907                 :            : 
+    1908         [ #  # ]:          0 :     for (cur = x509_crt_verify_strings; cur->string != NULL; cur++) {
+    1909         [ #  # ]:          0 :         if ((flags & cur->code) == 0) {
+    1910                 :          0 :             continue;
+    1911                 :            :         }
+    1912                 :            : 
+    1913                 :          0 :         ret = mbedtls_snprintf(p, n, "%s%s\n", prefix, cur->string);
+    1914   [ #  #  #  # ]:          0 :         MBEDTLS_X509_SAFE_SNPRINTF;
+    1915                 :          0 :         flags ^= cur->code;
+    1916                 :            :     }
+    1917                 :            : 
+    1918         [ #  # ]:          0 :     if (flags != 0) {
+    1919                 :          0 :         ret = mbedtls_snprintf(p, n, "%sUnknown reason "
+    1920                 :            :                                      "(this should not happen)\n", prefix);
+    1921   [ #  #  #  # ]:          0 :         MBEDTLS_X509_SAFE_SNPRINTF;
+    1922                 :            :     }
+    1923                 :            : 
+    1924                 :          0 :     return (int) (size - n);
+    1925                 :            : }
+    1926                 :            : #endif /* MBEDTLS_X509_REMOVE_INFO */
+    1927                 :            : 
+    1928                 :       1588 : int mbedtls_x509_crt_check_key_usage(const mbedtls_x509_crt *crt,
+    1929                 :            :                                      unsigned int usage)
+    1930                 :            : {
+    1931                 :            :     unsigned int usage_must, usage_may;
+    1932                 :       1588 :     unsigned int may_mask = MBEDTLS_X509_KU_ENCIPHER_ONLY
+    1933                 :            :                             | MBEDTLS_X509_KU_DECIPHER_ONLY;
+    1934                 :            : 
+    1935         [ +  + ]:       1588 :     if ((crt->ext_types & MBEDTLS_X509_EXT_KEY_USAGE) == 0) {
+    1936                 :        704 :         return 0;
+    1937                 :            :     }
+    1938                 :            : 
+    1939                 :        884 :     usage_must = usage & ~may_mask;
+    1940                 :            : 
+    1941         [ -  + ]:        884 :     if (((crt->key_usage & ~may_mask) & usage_must) != usage_must) {
+    1942                 :          0 :         return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
+    1943                 :            :     }
+    1944                 :            : 
+    1945                 :        884 :     usage_may = usage & may_mask;
+    1946                 :            : 
+    1947         [ -  + ]:        884 :     if (((crt->key_usage & may_mask) | usage_may) != usage_may) {
+    1948                 :          0 :         return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
+    1949                 :            :     }
+    1950                 :            : 
+    1951                 :        884 :     return 0;
+    1952                 :            : }
+    1953                 :            : 
+    1954                 :          0 : int mbedtls_x509_crt_check_extended_key_usage(const mbedtls_x509_crt *crt,
+    1955                 :            :                                               const char *usage_oid,
+    1956                 :            :                                               size_t usage_len)
+    1957                 :            : {
+    1958                 :            :     const mbedtls_x509_sequence *cur;
+    1959                 :            : 
+    1960                 :            :     /* Extension is not mandatory, absent means no restriction */
+    1961         [ #  # ]:          0 :     if ((crt->ext_types & MBEDTLS_X509_EXT_EXTENDED_KEY_USAGE) == 0) {
+    1962                 :          0 :         return 0;
+    1963                 :            :     }
+    1964                 :            : 
+    1965                 :            :     /*
+    1966                 :            :      * Look for the requested usage (or wildcard ANY) in our list
+    1967                 :            :      */
+    1968         [ #  # ]:          0 :     for (cur = &crt->ext_key_usage; cur != NULL; cur = cur->next) {
+    1969                 :          0 :         const mbedtls_x509_buf *cur_oid = &cur->buf;
+    1970                 :            : 
+    1971         [ #  # ]:          0 :         if (cur_oid->len == usage_len &&
+    1972         [ #  # ]:          0 :             memcmp(cur_oid->p, usage_oid, usage_len) == 0) {
+    1973                 :          0 :             return 0;
+    1974                 :            :         }
+    1975                 :            : 
+    1976   [ #  #  #  #  :          0 :         if (MBEDTLS_OID_CMP(MBEDTLS_OID_ANY_EXTENDED_KEY_USAGE, cur_oid) == 0) {
+                   #  # ]
+    1977                 :          0 :             return 0;
+    1978                 :            :         }
+    1979                 :            :     }
+    1980                 :            : 
+    1981                 :          0 :     return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
+    1982                 :            : }
+    1983                 :            : 
+    1984                 :            : #if defined(MBEDTLS_X509_CRL_PARSE_C)
+    1985                 :            : /*
+    1986                 :            :  * Return 1 if the certificate is revoked, or 0 otherwise.
+    1987                 :            :  */
+    1988                 :          0 : int mbedtls_x509_crt_is_revoked(const mbedtls_x509_crt *crt, const mbedtls_x509_crl *crl)
+    1989                 :            : {
+    1990                 :          0 :     const mbedtls_x509_crl_entry *cur = &crl->entry;
+    1991                 :            : 
+    1992   [ #  #  #  # ]:          0 :     while (cur != NULL && cur->serial.len != 0) {
+    1993         [ #  # ]:          0 :         if (crt->serial.len == cur->serial.len &&
+    1994         [ #  # ]:          0 :             memcmp(crt->serial.p, cur->serial.p, crt->serial.len) == 0) {
+    1995                 :          0 :             return 1;
+    1996                 :            :         }
+    1997                 :            : 
+    1998                 :          0 :         cur = cur->next;
+    1999                 :            :     }
+    2000                 :            : 
+    2001                 :          0 :     return 0;
+    2002                 :            : }
+    2003                 :            : 
+    2004                 :            : /*
+    2005                 :            :  * Check that the given certificate is not revoked according to the CRL.
+    2006                 :            :  * Skip validation if no CRL for the given CA is present.
+    2007                 :            :  */
+    2008                 :       1586 : static int x509_crt_verifycrl(mbedtls_x509_crt *crt, mbedtls_x509_crt *ca,
+    2009                 :            :                               mbedtls_x509_crl *crl_list,
+    2010                 :            :                               const mbedtls_x509_crt_profile *profile,
+    2011                 :            :                               const mbedtls_x509_time *now)
+    2012                 :            : {
+    2013                 :       1586 :     int flags = 0;
+    2014                 :            :     unsigned char hash[MBEDTLS_MD_MAX_SIZE];
+    2015                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+    2016                 :            :     psa_algorithm_t psa_algorithm;
+    2017                 :            : #else
+    2018                 :            :     const mbedtls_md_info_t *md_info;
+    2019                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO */
+    2020                 :            :     size_t hash_length;
+    2021                 :            : 
+    2022         [ -  + ]:       1586 :     if (ca == NULL) {
+    2023                 :          0 :         return flags;
+    2024                 :            :     }
+    2025                 :            : 
+    2026         [ -  + ]:       1586 :     while (crl_list != NULL) {
+    2027   [ #  #  #  # ]:          0 :         if (crl_list->version == 0 ||
+    2028                 :          0 :             x509_name_cmp(&crl_list->issuer, &ca->subject) != 0) {
+    2029                 :          0 :             crl_list = crl_list->next;
+    2030                 :          0 :             continue;
+    2031                 :            :         }
+    2032                 :            : 
+    2033                 :            :         /*
+    2034                 :            :          * Check if the CA is configured to sign CRLs
+    2035                 :            :          */
+    2036         [ #  # ]:          0 :         if (mbedtls_x509_crt_check_key_usage(ca,
+    2037                 :            :                                              MBEDTLS_X509_KU_CRL_SIGN) != 0) {
+    2038                 :          0 :             flags |= MBEDTLS_X509_BADCRL_NOT_TRUSTED;
+    2039                 :          0 :             break;
+    2040                 :            :         }
+    2041                 :            : 
+    2042                 :            :         /*
+    2043                 :            :          * Check if CRL is correctly signed by the trusted CA
+    2044                 :            :          */
+    2045         [ #  # ]:          0 :         if (x509_profile_check_md_alg(profile, crl_list->sig_md) != 0) {
+    2046                 :          0 :             flags |= MBEDTLS_X509_BADCRL_BAD_MD;
+    2047                 :            :         }
+    2048                 :            : 
+    2049         [ #  # ]:          0 :         if (x509_profile_check_pk_alg(profile, crl_list->sig_pk) != 0) {
+    2050                 :          0 :             flags |= MBEDTLS_X509_BADCRL_BAD_PK;
+    2051                 :            :         }
+    2052                 :            : 
+    2053                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+    2054                 :            :         psa_algorithm = mbedtls_md_psa_alg_from_type(crl_list->sig_md);
+    2055                 :            :         if (psa_hash_compute(psa_algorithm,
+    2056                 :            :                              crl_list->tbs.p,
+    2057                 :            :                              crl_list->tbs.len,
+    2058                 :            :                              hash,
+    2059                 :            :                              sizeof(hash),
+    2060                 :            :                              &hash_length) != PSA_SUCCESS) {
+    2061                 :            :             /* Note: this can't happen except after an internal error */
+    2062                 :            :             flags |= MBEDTLS_X509_BADCRL_NOT_TRUSTED;
+    2063                 :            :             break;
+    2064                 :            :         }
+    2065                 :            : #else
+    2066                 :          0 :         md_info = mbedtls_md_info_from_type(crl_list->sig_md);
+    2067                 :          0 :         hash_length = mbedtls_md_get_size(md_info);
+    2068         [ #  # ]:          0 :         if (mbedtls_md(md_info,
+    2069                 :          0 :                        crl_list->tbs.p,
+    2070                 :            :                        crl_list->tbs.len,
+    2071                 :            :                        hash) != 0) {
+    2072                 :            :             /* Note: this can't happen except after an internal error */
+    2073                 :          0 :             flags |= MBEDTLS_X509_BADCRL_NOT_TRUSTED;
+    2074                 :          0 :             break;
+    2075                 :            :         }
+    2076                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO */
+    2077                 :            : 
+    2078         [ #  # ]:          0 :         if (x509_profile_check_key(profile, &ca->pk) != 0) {
+    2079                 :          0 :             flags |= MBEDTLS_X509_BADCERT_BAD_KEY;
+    2080                 :            :         }
+    2081                 :            : 
+    2082         [ #  # ]:          0 :         if (mbedtls_pk_verify_ext(crl_list->sig_pk, crl_list->sig_opts, &ca->pk,
+    2083                 :            :                                   crl_list->sig_md, hash, hash_length,
+    2084                 :          0 :                                   crl_list->sig.p, crl_list->sig.len) != 0) {
+    2085                 :          0 :             flags |= MBEDTLS_X509_BADCRL_NOT_TRUSTED;
+    2086                 :          0 :             break;
+    2087                 :            :         }
+    2088                 :            : 
+    2089                 :            : #if defined(MBEDTLS_HAVE_TIME_DATE)
+    2090                 :            :         /*
+    2091                 :            :          * Check for validity of CRL (Do not drop out)
+    2092                 :            :          */
+    2093         [ #  # ]:          0 :         if (mbedtls_x509_time_cmp(&crl_list->next_update, now) < 0) {
+    2094                 :          0 :             flags |= MBEDTLS_X509_BADCRL_EXPIRED;
+    2095                 :            :         }
+    2096                 :            : 
+    2097         [ #  # ]:          0 :         if (mbedtls_x509_time_cmp(&crl_list->this_update, now) > 0) {
+    2098                 :          0 :             flags |= MBEDTLS_X509_BADCRL_FUTURE;
+    2099                 :            :         }
+    2100                 :            : #else
+    2101                 :            :         ((void) now);
+    2102                 :            : #endif
+    2103                 :            : 
+    2104                 :            :         /*
+    2105                 :            :          * Check if certificate is revoked
+    2106                 :            :          */
+    2107         [ #  # ]:          0 :         if (mbedtls_x509_crt_is_revoked(crt, crl_list)) {
+    2108                 :          0 :             flags |= MBEDTLS_X509_BADCERT_REVOKED;
+    2109                 :          0 :             break;
+    2110                 :            :         }
+    2111                 :            : 
+    2112                 :          0 :         crl_list = crl_list->next;
+    2113                 :            :     }
+    2114                 :            : 
+    2115                 :       1586 :     return flags;
+    2116                 :            : }
+    2117                 :            : #endif /* MBEDTLS_X509_CRL_PARSE_C */
+    2118                 :            : 
+    2119                 :            : /*
+    2120                 :            :  * Check the signature of a certificate by its parent
+    2121                 :            :  */
+    2122                 :       1588 : static int x509_crt_check_signature(const mbedtls_x509_crt *child,
+    2123                 :            :                                     mbedtls_x509_crt *parent,
+    2124                 :            :                                     mbedtls_x509_crt_restart_ctx *rs_ctx)
+    2125                 :            : {
+    2126                 :            :     size_t hash_len;
+    2127                 :            :     unsigned char hash[MBEDTLS_MD_MAX_SIZE];
+    2128                 :            : #if !defined(MBEDTLS_USE_PSA_CRYPTO)
+    2129                 :            :     const mbedtls_md_info_t *md_info;
+    2130                 :       1588 :     md_info = mbedtls_md_info_from_type(child->sig_md);
+    2131                 :       1588 :     hash_len = mbedtls_md_get_size(md_info);
+    2132                 :            : 
+    2133                 :            :     /* Note: hash errors can happen only after an internal error */
+    2134         [ -  + ]:       1588 :     if (mbedtls_md(md_info, child->tbs.p, child->tbs.len, hash) != 0) {
+    2135                 :          0 :         return -1;
+    2136                 :            :     }
+    2137                 :            : #else
+    2138                 :            :     psa_algorithm_t hash_alg = mbedtls_md_psa_alg_from_type(child->sig_md);
+    2139                 :            :     psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
+    2140                 :            : 
+    2141                 :            :     status = psa_hash_compute(hash_alg,
+    2142                 :            :                               child->tbs.p,
+    2143                 :            :                               child->tbs.len,
+    2144                 :            :                               hash,
+    2145                 :            :                               sizeof(hash),
+    2146                 :            :                               &hash_len);
+    2147                 :            :     if (status != PSA_SUCCESS) {
+    2148                 :            :         return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
+    2149                 :            :     }
+    2150                 :            : 
+    2151                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO */
+    2152                 :            :     /* Skip expensive computation on obvious mismatch */
+    2153         [ -  + ]:       1588 :     if (!mbedtls_pk_can_do(&parent->pk, child->sig_pk)) {
+    2154                 :          0 :         return -1;
+    2155                 :            :     }
+    2156                 :            : 
+    2157                 :            : #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
+    2158   [ -  +  -  - ]:       1588 :     if (rs_ctx != NULL && child->sig_pk == MBEDTLS_PK_ECDSA) {
+    2159                 :          0 :         return mbedtls_pk_verify_restartable(&parent->pk,
+    2160                 :          0 :                                              child->sig_md, hash, hash_len,
+    2161                 :          0 :                                              child->sig.p, child->sig.len, &rs_ctx->pk);
+    2162                 :            :     }
+    2163                 :            : #else
+    2164                 :            :     (void) rs_ctx;
+    2165                 :            : #endif
+    2166                 :            : 
+    2167                 :       1588 :     return mbedtls_pk_verify_ext(child->sig_pk, child->sig_opts, &parent->pk,
+    2168                 :       1588 :                                  child->sig_md, hash, hash_len,
+    2169                 :       1588 :                                  child->sig.p, child->sig.len);
+    2170                 :            : }
+    2171                 :            : 
+    2172                 :            : /*
+    2173                 :            :  * Check if 'parent' is a suitable parent (signing CA) for 'child'.
+    2174                 :            :  * Return 0 if yes, -1 if not.
+    2175                 :            :  *
+    2176                 :            :  * top means parent is a locally-trusted certificate
+    2177                 :            :  */
+    2178                 :       1588 : static int x509_crt_check_parent(const mbedtls_x509_crt *child,
+    2179                 :            :                                  const mbedtls_x509_crt *parent,
+    2180                 :            :                                  int top)
+    2181                 :            : {
+    2182                 :            :     int need_ca_bit;
+    2183                 :            : 
+    2184                 :            :     /* Parent must be the issuer */
+    2185         [ -  + ]:       1588 :     if (x509_name_cmp(&child->issuer, &parent->subject) != 0) {
+    2186                 :          0 :         return -1;
+    2187                 :            :     }
+    2188                 :            : 
+    2189                 :            :     /* Parent must have the basicConstraints CA bit set as a general rule */
+    2190                 :       1588 :     need_ca_bit = 1;
+    2191                 :            : 
+    2192                 :            :     /* Exception: v1/v2 certificates that are locally trusted. */
+    2193   [ +  -  -  + ]:       1588 :     if (top && parent->version < 3) {
+    2194                 :          0 :         need_ca_bit = 0;
+    2195                 :            :     }
+    2196                 :            : 
+    2197   [ +  -  -  + ]:       1588 :     if (need_ca_bit && !parent->ca_istrue) {
+    2198                 :          0 :         return -1;
+    2199                 :            :     }
+    2200                 :            : 
+    2201   [ +  -  -  + ]:       3176 :     if (need_ca_bit &&
+    2202                 :       1588 :         mbedtls_x509_crt_check_key_usage(parent, MBEDTLS_X509_KU_KEY_CERT_SIGN) != 0) {
+    2203                 :          0 :         return -1;
+    2204                 :            :     }
+    2205                 :            : 
+    2206                 :       1588 :     return 0;
+    2207                 :            : }
+    2208                 :            : 
+    2209                 :            : /*
+    2210                 :            :  * Find a suitable parent for child in candidates, or return NULL.
+    2211                 :            :  *
+    2212                 :            :  * Here suitable is defined as:
+    2213                 :            :  *  1. subject name matches child's issuer
+    2214                 :            :  *  2. if necessary, the CA bit is set and key usage allows signing certs
+    2215                 :            :  *  3. for trusted roots, the signature is correct
+    2216                 :            :  *     (for intermediates, the signature is checked and the result reported)
+    2217                 :            :  *  4. pathlen constraints are satisfied
+    2218                 :            :  *
+    2219                 :            :  * If there's a suitable candidate which is also time-valid, return the first
+    2220                 :            :  * such. Otherwise, return the first suitable candidate (or NULL if there is
+    2221                 :            :  * none).
+    2222                 :            :  *
+    2223                 :            :  * The rationale for this rule is that someone could have a list of trusted
+    2224                 :            :  * roots with two versions on the same root with different validity periods.
+    2225                 :            :  * (At least one user reported having such a list and wanted it to just work.)
+    2226                 :            :  * The reason we don't just require time-validity is that generally there is
+    2227                 :            :  * only one version, and if it's expired we want the flags to state that
+    2228                 :            :  * rather than NOT_TRUSTED, as would be the case if we required it here.
+    2229                 :            :  *
+    2230                 :            :  * The rationale for rule 3 (signature for trusted roots) is that users might
+    2231                 :            :  * have two versions of the same CA with different keys in their list, and the
+    2232                 :            :  * way we select the correct one is by checking the signature (as we don't
+    2233                 :            :  * rely on key identifier extensions). (This is one way users might choose to
+    2234                 :            :  * handle key rollover, another relies on self-issued certs, see [SIRO].)
+    2235                 :            :  *
+    2236                 :            :  * Arguments:
+    2237                 :            :  *  - [in] child: certificate for which we're looking for a parent
+    2238                 :            :  *  - [in] candidates: chained list of potential parents
+    2239                 :            :  *  - [out] r_parent: parent found (or NULL)
+    2240                 :            :  *  - [out] r_signature_is_good: 1 if child signature by parent is valid, or 0
+    2241                 :            :  *  - [in] top: 1 if candidates consists of trusted roots, ie we're at the top
+    2242                 :            :  *         of the chain, 0 otherwise
+    2243                 :            :  *  - [in] path_cnt: number of intermediates seen so far
+    2244                 :            :  *  - [in] self_cnt: number of self-signed intermediates seen so far
+    2245                 :            :  *         (will never be greater than path_cnt)
+    2246                 :            :  *  - [in-out] rs_ctx: context for restarting operations
+    2247                 :            :  *
+    2248                 :            :  * Return value:
+    2249                 :            :  *  - 0 on success
+    2250                 :            :  *  - MBEDTLS_ERR_ECP_IN_PROGRESS otherwise
+    2251                 :            :  */
+    2252                 :       1590 : static int x509_crt_find_parent_in(
+    2253                 :            :     mbedtls_x509_crt *child,
+    2254                 :            :     mbedtls_x509_crt *candidates,
+    2255                 :            :     mbedtls_x509_crt **r_parent,
+    2256                 :            :     int *r_signature_is_good,
+    2257                 :            :     int top,
+    2258                 :            :     unsigned path_cnt,
+    2259                 :            :     unsigned self_cnt,
+    2260                 :            :     mbedtls_x509_crt_restart_ctx *rs_ctx,
+    2261                 :            :     const mbedtls_x509_time *now)
+    2262                 :            : {
+    2263                 :       1590 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    2264                 :            :     mbedtls_x509_crt *parent, *fallback_parent;
+    2265                 :       1590 :     int signature_is_good = 0, fallback_signature_is_good;
+    2266                 :            : 
+    2267                 :            : #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
+    2268                 :            :     /* did we have something in progress? */
+    2269   [ -  +  -  - ]:       1590 :     if (rs_ctx != NULL && rs_ctx->parent != NULL) {
+    2270                 :            :         /* restore saved state */
+    2271                 :          0 :         parent = rs_ctx->parent;
+    2272                 :          0 :         fallback_parent = rs_ctx->fallback_parent;
+    2273                 :          0 :         fallback_signature_is_good = rs_ctx->fallback_signature_is_good;
+    2274                 :            : 
+    2275                 :            :         /* clear saved state */
+    2276                 :          0 :         rs_ctx->parent = NULL;
+    2277                 :          0 :         rs_ctx->fallback_parent = NULL;
+    2278                 :          0 :         rs_ctx->fallback_signature_is_good = 0;
+    2279                 :            : 
+    2280                 :            :         /* resume where we left */
+    2281                 :          0 :         goto check_signature;
+    2282                 :            :     }
+    2283                 :            : #endif
+    2284                 :            : 
+    2285                 :       1590 :     fallback_parent = NULL;
+    2286                 :       1590 :     fallback_signature_is_good = 0;
+    2287                 :            : 
+    2288         [ +  + ]:       1593 :     for (parent = candidates; parent != NULL; parent = parent->next) {
+    2289                 :            :         /* basic parenting skills (name, CA bit, key usage) */
+    2290         [ -  + ]:       1588 :         if (x509_crt_check_parent(child, parent, top) != 0) {
+    2291                 :          0 :             continue;
+    2292                 :            :         }
+    2293                 :            : 
+    2294                 :            :         /* +1 because stored max_pathlen is 1 higher that the actual value */
+    2295         [ -  + ]:       1588 :         if (parent->max_pathlen > 0 &&
+    2296         [ #  # ]:          0 :             (size_t) parent->max_pathlen < 1 + path_cnt - self_cnt) {
+    2297                 :          0 :             continue;
+    2298                 :            :         }
+    2299                 :            : 
+    2300                 :            :         /* Signature */
+    2301                 :            : #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
+    2302                 :       1588 : check_signature:
+    2303                 :            : #endif
+    2304                 :       1588 :         ret = x509_crt_check_signature(child, parent, rs_ctx);
+    2305                 :            : 
+    2306                 :            : #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
+    2307   [ -  +  -  - ]:       1588 :         if (rs_ctx != NULL && ret == MBEDTLS_ERR_ECP_IN_PROGRESS) {
+    2308                 :            :             /* save state */
+    2309                 :          0 :             rs_ctx->parent = parent;
+    2310                 :          0 :             rs_ctx->fallback_parent = fallback_parent;
+    2311                 :          0 :             rs_ctx->fallback_signature_is_good = fallback_signature_is_good;
+    2312                 :            : 
+    2313                 :          0 :             return ret;
+    2314                 :            :         }
+    2315                 :            : #else
+    2316                 :            :         (void) ret;
+    2317                 :            : #endif
+    2318                 :            : 
+    2319                 :       1588 :         signature_is_good = ret == 0;
+    2320   [ +  -  +  + ]:       1588 :         if (top && !signature_is_good) {
+    2321                 :          2 :             continue;
+    2322                 :            :         }
+    2323                 :            : 
+    2324                 :            : #if defined(MBEDTLS_HAVE_TIME_DATE)
+    2325                 :            :         /* optional time check */
+    2326   [ +  +  -  + ]:       3171 :         if (mbedtls_x509_time_cmp(&parent->valid_to, now) < 0 ||    /* past */
+    2327                 :       1585 :             mbedtls_x509_time_cmp(&parent->valid_from, now) > 0) {  /* future */
+    2328         [ +  - ]:          1 :             if (fallback_parent == NULL) {
+    2329                 :          1 :                 fallback_parent = parent;
+    2330                 :          1 :                 fallback_signature_is_good = signature_is_good;
+    2331                 :            :             }
+    2332                 :            : 
+    2333                 :          1 :             continue;
+    2334                 :            :         }
+    2335                 :            : #else
+    2336                 :            :         ((void) now);
+    2337                 :            : #endif
+    2338                 :            : 
+    2339                 :       1585 :         *r_parent = parent;
+    2340                 :       1585 :         *r_signature_is_good = signature_is_good;
+    2341                 :            : 
+    2342                 :       1585 :         break;
+    2343                 :            :     }
+    2344                 :            : 
+    2345         [ +  + ]:       1590 :     if (parent == NULL) {
+    2346                 :          5 :         *r_parent = fallback_parent;
+    2347                 :          5 :         *r_signature_is_good = fallback_signature_is_good;
+    2348                 :            :     }
+    2349                 :            : 
+    2350                 :       1590 :     return 0;
+    2351                 :            : }
+    2352                 :            : 
+    2353                 :            : /*
+    2354                 :            :  * Find a parent in trusted CAs or the provided chain, or return NULL.
+    2355                 :            :  *
+    2356                 :            :  * Searches in trusted CAs first, and return the first suitable parent found
+    2357                 :            :  * (see find_parent_in() for definition of suitable).
+    2358                 :            :  *
+    2359                 :            :  * Arguments:
+    2360                 :            :  *  - [in] child: certificate for which we're looking for a parent, followed
+    2361                 :            :  *         by a chain of possible intermediates
+    2362                 :            :  *  - [in] trust_ca: list of locally trusted certificates
+    2363                 :            :  *  - [out] parent: parent found (or NULL)
+    2364                 :            :  *  - [out] parent_is_trusted: 1 if returned `parent` is trusted, or 0
+    2365                 :            :  *  - [out] signature_is_good: 1 if child signature by parent is valid, or 0
+    2366                 :            :  *  - [in] path_cnt: number of links in the chain so far (EE -> ... -> child)
+    2367                 :            :  *  - [in] self_cnt: number of self-signed certs in the chain so far
+    2368                 :            :  *         (will always be no greater than path_cnt)
+    2369                 :            :  *  - [in-out] rs_ctx: context for restarting operations
+    2370                 :            :  *
+    2371                 :            :  * Return value:
+    2372                 :            :  *  - 0 on success
+    2373                 :            :  *  - MBEDTLS_ERR_ECP_IN_PROGRESS otherwise
+    2374                 :            :  */
+    2375                 :       1588 : static int x509_crt_find_parent(
+    2376                 :            :     mbedtls_x509_crt *child,
+    2377                 :            :     mbedtls_x509_crt *trust_ca,
+    2378                 :            :     mbedtls_x509_crt **parent,
+    2379                 :            :     int *parent_is_trusted,
+    2380                 :            :     int *signature_is_good,
+    2381                 :            :     unsigned path_cnt,
+    2382                 :            :     unsigned self_cnt,
+    2383                 :            :     mbedtls_x509_crt_restart_ctx *rs_ctx,
+    2384                 :            :     const mbedtls_x509_time *now)
+    2385                 :            : {
+    2386                 :       1588 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    2387                 :            :     mbedtls_x509_crt *search_list;
+    2388                 :            : 
+    2389                 :       1588 :     *parent_is_trusted = 1;
+    2390                 :            : 
+    2391                 :            : #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
+    2392                 :            :     /* restore then clear saved state if we have some stored */
+    2393   [ -  +  -  - ]:       1588 :     if (rs_ctx != NULL && rs_ctx->parent_is_trusted != -1) {
+    2394                 :          0 :         *parent_is_trusted = rs_ctx->parent_is_trusted;
+    2395                 :          0 :         rs_ctx->parent_is_trusted = -1;
+    2396                 :            :     }
+    2397                 :            : #endif
+    2398                 :            : 
+    2399                 :            :     while (1) {
+    2400         [ +  + ]:       1590 :         search_list = *parent_is_trusted ? trust_ca : child->next;
+    2401                 :            : 
+    2402                 :       1590 :         ret = x509_crt_find_parent_in(child, search_list,
+    2403                 :            :                                       parent, signature_is_good,
+    2404                 :            :                                       *parent_is_trusted,
+    2405                 :            :                                       path_cnt, self_cnt, rs_ctx, now);
+    2406                 :            : 
+    2407                 :            : #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
+    2408   [ -  +  -  - ]:       1590 :         if (rs_ctx != NULL && ret == MBEDTLS_ERR_ECP_IN_PROGRESS) {
+    2409                 :            :             /* save state */
+    2410                 :          0 :             rs_ctx->parent_is_trusted = *parent_is_trusted;
+    2411                 :          0 :             return ret;
+    2412                 :            :         }
+    2413                 :            : #else
+    2414                 :            :         (void) ret;
+    2415                 :            : #endif
+    2416                 :            : 
+    2417                 :            :         /* stop here if found or already in second iteration */
+    2418   [ +  +  +  + ]:       1590 :         if (*parent != NULL || *parent_is_trusted == 0) {
+    2419                 :            :             break;
+    2420                 :            :         }
+    2421                 :            : 
+    2422                 :            :         /* prepare second iteration */
+    2423                 :          2 :         *parent_is_trusted = 0;
+    2424                 :            :     }
+    2425                 :            : 
+    2426                 :            :     /* extra precaution against mistakes in the caller */
+    2427         [ +  + ]:       1588 :     if (*parent == NULL) {
+    2428                 :          2 :         *parent_is_trusted = 0;
+    2429                 :          2 :         *signature_is_good = 0;
+    2430                 :            :     }
+    2431                 :            : 
+    2432                 :       1588 :     return 0;
+    2433                 :            : }
+    2434                 :            : 
+    2435                 :            : /*
+    2436                 :            :  * Check if an end-entity certificate is locally trusted
+    2437                 :            :  *
+    2438                 :            :  * Currently we require such certificates to be self-signed (actually only
+    2439                 :            :  * check for self-issued as self-signatures are not checked)
+    2440                 :            :  */
+    2441                 :       2255 : static int x509_crt_check_ee_locally_trusted(
+    2442                 :            :     mbedtls_x509_crt *crt,
+    2443                 :            :     mbedtls_x509_crt *trust_ca)
+    2444                 :            : {
+    2445                 :            :     mbedtls_x509_crt *cur;
+    2446                 :            : 
+    2447                 :            :     /* must be self-issued */
+    2448         [ +  + ]:       2255 :     if (x509_name_cmp(&crt->issuer, &crt->subject) != 0) {
+    2449                 :       1588 :         return -1;
+    2450                 :            :     }
+    2451                 :            : 
+    2452                 :            :     /* look for an exact match with trusted cert */
+    2453         [ +  - ]:        667 :     for (cur = trust_ca; cur != NULL; cur = cur->next) {
+    2454         [ +  - ]:        667 :         if (crt->raw.len == cur->raw.len &&
+    2455         [ +  - ]:        667 :             memcmp(crt->raw.p, cur->raw.p, crt->raw.len) == 0) {
+    2456                 :        667 :             return 0;
+    2457                 :            :         }
+    2458                 :            :     }
+    2459                 :            : 
+    2460                 :            :     /* too bad */
+    2461                 :          0 :     return -1;
+    2462                 :            : }
+    2463                 :            : 
+    2464                 :            : /*
+    2465                 :            :  * Build and verify a certificate chain
+    2466                 :            :  *
+    2467                 :            :  * Given a peer-provided list of certificates EE, C1, ..., Cn and
+    2468                 :            :  * a list of trusted certs R1, ... Rp, try to build and verify a chain
+    2469                 :            :  *      EE, Ci1, ... Ciq [, Rj]
+    2470                 :            :  * such that every cert in the chain is a child of the next one,
+    2471                 :            :  * jumping to a trusted root as early as possible.
+    2472                 :            :  *
+    2473                 :            :  * Verify that chain and return it with flags for all issues found.
+    2474                 :            :  *
+    2475                 :            :  * Special cases:
+    2476                 :            :  * - EE == Rj -> return a one-element list containing it
+    2477                 :            :  * - EE, Ci1, ..., Ciq cannot be continued with a trusted root
+    2478                 :            :  *   -> return that chain with NOT_TRUSTED set on Ciq
+    2479                 :            :  *
+    2480                 :            :  * Tests for (aspects of) this function should include at least:
+    2481                 :            :  * - trusted EE
+    2482                 :            :  * - EE -> trusted root
+    2483                 :            :  * - EE -> intermediate CA -> trusted root
+    2484                 :            :  * - if relevant: EE untrusted
+    2485                 :            :  * - if relevant: EE -> intermediate, untrusted
+    2486                 :            :  * with the aspect under test checked at each relevant level (EE, int, root).
+    2487                 :            :  * For some aspects longer chains are required, but usually length 2 is
+    2488                 :            :  * enough (but length 1 is not in general).
+    2489                 :            :  *
+    2490                 :            :  * Arguments:
+    2491                 :            :  *  - [in] crt: the cert list EE, C1, ..., Cn
+    2492                 :            :  *  - [in] trust_ca: the trusted list R1, ..., Rp
+    2493                 :            :  *  - [in] ca_crl, profile: as in verify_with_profile()
+    2494                 :            :  *  - [out] ver_chain: the built and verified chain
+    2495                 :            :  *      Only valid when return value is 0, may contain garbage otherwise!
+    2496                 :            :  *      Restart note: need not be the same when calling again to resume.
+    2497                 :            :  *  - [in-out] rs_ctx: context for restarting operations
+    2498                 :            :  *
+    2499                 :            :  * Return value:
+    2500                 :            :  *  - non-zero if the chain could not be fully built and examined
+    2501                 :            :  *  - 0 is the chain was successfully built and examined,
+    2502                 :            :  *      even if it was found to be invalid
+    2503                 :            :  */
+    2504                 :       2255 : static int x509_crt_verify_chain(
+    2505                 :            :     mbedtls_x509_crt *crt,
+    2506                 :            :     mbedtls_x509_crt *trust_ca,
+    2507                 :            :     mbedtls_x509_crl *ca_crl,
+    2508                 :            :     mbedtls_x509_crt_ca_cb_t f_ca_cb,
+    2509                 :            :     void *p_ca_cb,
+    2510                 :            :     const mbedtls_x509_crt_profile *profile,
+    2511                 :            :     mbedtls_x509_crt_verify_chain *ver_chain,
+    2512                 :            :     mbedtls_x509_crt_restart_ctx *rs_ctx)
+    2513                 :            : {
+    2514                 :            :     /* Don't initialize any of those variables here, so that the compiler can
+    2515                 :            :      * catch potential issues with jumping ahead when restarting */
+    2516                 :       2255 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    2517                 :            :     uint32_t *flags;
+    2518                 :            :     mbedtls_x509_crt_verify_chain_item *cur;
+    2519                 :            :     mbedtls_x509_crt *child;
+    2520                 :            :     mbedtls_x509_crt *parent;
+    2521                 :            :     int parent_is_trusted;
+    2522                 :            :     int child_is_trusted;
+    2523                 :            :     int signature_is_good;
+    2524                 :            :     unsigned self_cnt;
+    2525                 :       2255 :     mbedtls_x509_crt *cur_trust_ca = NULL;
+    2526                 :            :     mbedtls_x509_time now;
+    2527                 :            : 
+    2528                 :            : #if defined(MBEDTLS_HAVE_TIME_DATE)
+    2529         [ -  + ]:       2255 :     if (mbedtls_x509_time_gmtime(mbedtls_time(NULL), &now) != 0) {
+    2530                 :          0 :         return MBEDTLS_ERR_X509_FATAL_ERROR;
+    2531                 :            :     }
+    2532                 :            : #endif
+    2533                 :            : 
+    2534                 :            : #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
+    2535                 :            :     /* resume if we had an operation in progress */
+    2536   [ -  +  -  - ]:       2255 :     if (rs_ctx != NULL && rs_ctx->in_progress == x509_crt_rs_find_parent) {
+    2537                 :            :         /* restore saved state */
+    2538                 :          0 :         *ver_chain = rs_ctx->ver_chain; /* struct copy */
+    2539                 :          0 :         self_cnt = rs_ctx->self_cnt;
+    2540                 :            : 
+    2541                 :            :         /* restore derived state */
+    2542                 :          0 :         cur = &ver_chain->items[ver_chain->len - 1];
+    2543                 :          0 :         child = cur->crt;
+    2544                 :          0 :         flags = &cur->flags;
+    2545                 :            : 
+    2546                 :          0 :         goto find_parent;
+    2547                 :            :     }
+    2548                 :            : #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
+    2549                 :            : 
+    2550                 :       2255 :     child = crt;
+    2551                 :       2255 :     self_cnt = 0;
+    2552                 :       2255 :     parent_is_trusted = 0;
+    2553                 :       2255 :     child_is_trusted = 0;
+    2554                 :            : 
+    2555                 :            :     while (1) {
+    2556                 :            :         /* Add certificate to the verification chain */
+    2557                 :       3841 :         cur = &ver_chain->items[ver_chain->len];
+    2558                 :       3841 :         cur->crt = child;
+    2559                 :       3841 :         cur->flags = 0;
+    2560                 :       3841 :         ver_chain->len++;
+    2561                 :       3841 :         flags = &cur->flags;
+    2562                 :            : 
+    2563                 :            : #if defined(MBEDTLS_HAVE_TIME_DATE)
+    2564                 :            :         /* Check time-validity (all certificates) */
+    2565         [ +  + ]:       3841 :         if (mbedtls_x509_time_cmp(&child->valid_to, &now) < 0) {
+    2566                 :          2 :             *flags |= MBEDTLS_X509_BADCERT_EXPIRED;
+    2567                 :            :         }
+    2568                 :            : 
+    2569         [ -  + ]:       3841 :         if (mbedtls_x509_time_cmp(&child->valid_from, &now) > 0) {
+    2570                 :          0 :             *flags |= MBEDTLS_X509_BADCERT_FUTURE;
+    2571                 :            :         }
+    2572                 :            : #endif
+    2573                 :            : 
+    2574                 :            :         /* Stop here for trusted roots (but not for trusted EE certs) */
+    2575         [ +  + ]:       3841 :         if (child_is_trusted) {
+    2576                 :       1586 :             return 0;
+    2577                 :            :         }
+    2578                 :            : 
+    2579                 :            :         /* Check signature algorithm: MD & PK algs */
+    2580         [ -  + ]:       2255 :         if (x509_profile_check_md_alg(profile, child->sig_md) != 0) {
+    2581                 :          0 :             *flags |= MBEDTLS_X509_BADCERT_BAD_MD;
+    2582                 :            :         }
+    2583                 :            : 
+    2584         [ -  + ]:       2255 :         if (x509_profile_check_pk_alg(profile, child->sig_pk) != 0) {
+    2585                 :          0 :             *flags |= MBEDTLS_X509_BADCERT_BAD_PK;
+    2586                 :            :         }
+    2587                 :            : 
+    2588                 :            :         /* Special case: EE certs that are locally trusted */
+    2589   [ +  -  +  + ]:       4510 :         if (ver_chain->len == 1 &&
+    2590                 :       2255 :             x509_crt_check_ee_locally_trusted(child, trust_ca) == 0) {
+    2591                 :        667 :             return 0;
+    2592                 :            :         }
+    2593                 :            : 
+    2594                 :            : #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
+    2595                 :       1588 : find_parent:
+    2596                 :            : #endif
+    2597                 :            : 
+    2598                 :            :         /* Obtain list of potential trusted signers from CA callback,
+    2599                 :            :          * or use statically provided list. */
+    2600                 :            : #if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
+    2601                 :            :         if (f_ca_cb != NULL) {
+    2602                 :            :             mbedtls_x509_crt_free(ver_chain->trust_ca_cb_result);
+    2603                 :            :             mbedtls_free(ver_chain->trust_ca_cb_result);
+    2604                 :            :             ver_chain->trust_ca_cb_result = NULL;
+    2605                 :            : 
+    2606                 :            :             ret = f_ca_cb(p_ca_cb, child, &ver_chain->trust_ca_cb_result);
+    2607                 :            :             if (ret != 0) {
+    2608                 :            :                 return MBEDTLS_ERR_X509_FATAL_ERROR;
+    2609                 :            :             }
+    2610                 :            : 
+    2611                 :            :             cur_trust_ca = ver_chain->trust_ca_cb_result;
+    2612                 :            :         } else
+    2613                 :            : #endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
+    2614                 :            :         {
+    2615                 :            :             ((void) f_ca_cb);
+    2616                 :            :             ((void) p_ca_cb);
+    2617                 :       1588 :             cur_trust_ca = trust_ca;
+    2618                 :            :         }
+    2619                 :            : 
+    2620                 :            :         /* Look for a parent in trusted CAs or up the chain */
+    2621                 :       1588 :         ret = x509_crt_find_parent(child, cur_trust_ca, &parent,
+    2622                 :            :                                    &parent_is_trusted, &signature_is_good,
+    2623                 :       1588 :                                    ver_chain->len - 1, self_cnt, rs_ctx,
+    2624                 :            :                                    &now);
+    2625                 :            : 
+    2626                 :            : #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
+    2627   [ -  +  -  - ]:       1588 :         if (rs_ctx != NULL && ret == MBEDTLS_ERR_ECP_IN_PROGRESS) {
+    2628                 :            :             /* save state */
+    2629                 :          0 :             rs_ctx->in_progress = x509_crt_rs_find_parent;
+    2630                 :          0 :             rs_ctx->self_cnt = self_cnt;
+    2631                 :          0 :             rs_ctx->ver_chain = *ver_chain; /* struct copy */
+    2632                 :            : 
+    2633                 :          0 :             return ret;
+    2634                 :            :         }
+    2635                 :            : #else
+    2636                 :            :         (void) ret;
+    2637                 :            : #endif
+    2638                 :            : 
+    2639                 :            :         /* No parent? We're done here */
+    2640         [ +  + ]:       1588 :         if (parent == NULL) {
+    2641                 :          2 :             *flags |= MBEDTLS_X509_BADCERT_NOT_TRUSTED;
+    2642                 :          2 :             return 0;
+    2643                 :            :         }
+    2644                 :            : 
+    2645                 :            :         /* Count intermediate self-issued (not necessarily self-signed) certs.
+    2646                 :            :          * These can occur with some strategies for key rollover, see [SIRO],
+    2647                 :            :          * and should be excluded from max_pathlen checks. */
+    2648   [ -  +  -  - ]:       1586 :         if (ver_chain->len != 1 &&
+    2649                 :          0 :             x509_name_cmp(&child->issuer, &child->subject) == 0) {
+    2650                 :          0 :             self_cnt++;
+    2651                 :            :         }
+    2652                 :            : 
+    2653                 :            :         /* path_cnt is 0 for the first intermediate CA,
+    2654                 :            :          * and if parent is trusted it's not an intermediate CA */
+    2655         [ -  + ]:       1586 :         if (!parent_is_trusted &&
+    2656         [ #  # ]:          0 :             ver_chain->len > MBEDTLS_X509_MAX_INTERMEDIATE_CA) {
+    2657                 :            :             /* return immediately to avoid overflow the chain array */
+    2658                 :          0 :             return MBEDTLS_ERR_X509_FATAL_ERROR;
+    2659                 :            :         }
+    2660                 :            : 
+    2661                 :            :         /* signature was checked while searching parent */
+    2662         [ -  + ]:       1586 :         if (!signature_is_good) {
+    2663                 :          0 :             *flags |= MBEDTLS_X509_BADCERT_NOT_TRUSTED;
+    2664                 :            :         }
+    2665                 :            : 
+    2666                 :            :         /* check size of signing key */
+    2667         [ -  + ]:       1586 :         if (x509_profile_check_key(profile, &parent->pk) != 0) {
+    2668                 :          0 :             *flags |= MBEDTLS_X509_BADCERT_BAD_KEY;
+    2669                 :            :         }
+    2670                 :            : 
+    2671                 :            : #if defined(MBEDTLS_X509_CRL_PARSE_C)
+    2672                 :            :         /* Check trusted CA's CRL for the given crt */
+    2673                 :       1586 :         *flags |= x509_crt_verifycrl(child, parent, ca_crl, profile, &now);
+    2674                 :            : #else
+    2675                 :            :         (void) ca_crl;
+    2676                 :            : #endif
+    2677                 :            : 
+    2678                 :            :         /* prepare for next iteration */
+    2679                 :       1586 :         child = parent;
+    2680                 :       1586 :         parent = NULL;
+    2681                 :       1586 :         child_is_trusted = parent_is_trusted;
+    2682                 :       1586 :         signature_is_good = 0;
+    2683                 :            :     }
+    2684                 :            : }
+    2685                 :            : 
+    2686                 :            : #ifdef _WIN32
+    2687                 :            : #ifdef _MSC_VER
+    2688                 :            : #pragma comment(lib, "ws2_32.lib")
+    2689                 :            : #include <winsock2.h>
+    2690                 :            : #include <ws2tcpip.h>
+    2691                 :            : #elif (defined(__MINGW32__) || defined(__MINGW64__)) && _WIN32_WINNT >= 0x0600
+    2692                 :            : #include <winsock2.h>
+    2693                 :            : #include <ws2tcpip.h>
+    2694                 :            : #else
+    2695                 :            : /* inet_pton() is not supported, fallback to software version */
+    2696                 :            : #define MBEDTLS_TEST_SW_INET_PTON
+    2697                 :            : #endif
+    2698                 :            : #elif defined(__sun)
+    2699                 :            : /* Solaris requires -lsocket -lnsl for inet_pton() */
+    2700                 :            : #elif defined(__has_include)
+    2701                 :            : #if __has_include(<sys/socket.h>)
+    2702                 :            : #include <sys/socket.h>
+    2703                 :            : #endif
+    2704                 :            : #if __has_include(<arpa/inet.h>)
+    2705                 :            : #include <arpa/inet.h>
+    2706                 :            : #endif
+    2707                 :            : #endif
+    2708                 :            : 
+    2709                 :            : /* Use whether or not AF_INET6 is defined to indicate whether or not to use
+    2710                 :            :  * the platform inet_pton() or a local implementation (below).  The local
+    2711                 :            :  * implementation may be used even in cases where the platform provides
+    2712                 :            :  * inet_pton(), e.g. when there are different includes required and/or the
+    2713                 :            :  * platform implementation requires dependencies on additional libraries.
+    2714                 :            :  * Specifically, Windows requires custom includes and additional link
+    2715                 :            :  * dependencies, and Solaris requires additional link dependencies.
+    2716                 :            :  * Also, as a coarse heuristic, use the local implementation if the compiler
+    2717                 :            :  * does not support __has_include(), or if the definition of AF_INET6 is not
+    2718                 :            :  * provided by headers included (or not) via __has_include() above.
+    2719                 :            :  * MBEDTLS_TEST_SW_INET_PTON is a bypass define to force testing of this code //no-check-names
+    2720                 :            :  * despite having a platform that has inet_pton. */
+    2721                 :            : #if !defined(AF_INET6) || defined(MBEDTLS_TEST_SW_INET_PTON) //no-check-names
+    2722                 :            : /* Definition located further below to possibly reduce compiler inlining */
+    2723                 :            : static int x509_inet_pton_ipv4(const char *src, void *dst);
+    2724                 :            : 
+    2725                 :            : #define li_cton(c, n) \
+    2726                 :            :     (((n) = (c) - '0') <= 9 || (((n) = ((c)&0xdf) - 'A') <= 5 ? ((n) += 10) : 0))
+    2727                 :            : 
+    2728                 :            : static int x509_inet_pton_ipv6(const char *src, void *dst)
+    2729                 :            : {
+    2730                 :            :     const unsigned char *p = (const unsigned char *) src;
+    2731                 :            :     int nonzero_groups = 0, num_digits, zero_group_start = -1;
+    2732                 :            :     uint16_t addr[8];
+    2733                 :            :     do {
+    2734                 :            :         /* note: allows excess leading 0's, e.g. 1:0002:3:... */
+    2735                 :            :         uint16_t group = num_digits = 0;
+    2736                 :            :         for (uint8_t digit; num_digits < 4; num_digits++) {
+    2737                 :            :             if (li_cton(*p, digit) == 0) {
+    2738                 :            :                 break;
+    2739                 :            :             }
+    2740                 :            :             group = (group << 4) | digit;
+    2741                 :            :             p++;
+    2742                 :            :         }
+    2743                 :            :         if (num_digits != 0) {
+    2744                 :            :             MBEDTLS_PUT_UINT16_BE(group, addr, nonzero_groups);
+    2745                 :            :             nonzero_groups++;
+    2746                 :            :             if (*p == '\0') {
+    2747                 :            :                 break;
+    2748                 :            :             } else if (*p == '.') {
+    2749                 :            :                 /* Don't accept IPv4 too early or late */
+    2750                 :            :                 if ((nonzero_groups == 0 && zero_group_start == -1) ||
+    2751                 :            :                     nonzero_groups >= 7) {
+    2752                 :            :                     break;
+    2753                 :            :                 }
+    2754                 :            : 
+    2755                 :            :                 /* Walk back to prior ':', then parse as IPv4-mapped */
+    2756                 :            :                 int steps = 4;
+    2757                 :            :                 do {
+    2758                 :            :                     p--;
+    2759                 :            :                     steps--;
+    2760                 :            :                 } while (*p != ':' && steps > 0);
+    2761                 :            : 
+    2762                 :            :                 if (*p != ':') {
+    2763                 :            :                     break;
+    2764                 :            :                 }
+    2765                 :            :                 p++;
+    2766                 :            :                 nonzero_groups--;
+    2767                 :            :                 if (x509_inet_pton_ipv4((const char *) p,
+    2768                 :            :                                         addr + nonzero_groups) != 0) {
+    2769                 :            :                     break;
+    2770                 :            :                 }
+    2771                 :            : 
+    2772                 :            :                 nonzero_groups += 2;
+    2773                 :            :                 p = (const unsigned char *) "";
+    2774                 :            :                 break;
+    2775                 :            :             } else if (*p != ':') {
+    2776                 :            :                 return -1;
+    2777                 :            :             }
+    2778                 :            :         } else {
+    2779                 :            :             /* Don't accept a second zero group or an invalid delimiter */
+    2780                 :            :             if (zero_group_start != -1 || *p != ':') {
+    2781                 :            :                 return -1;
+    2782                 :            :             }
+    2783                 :            :             zero_group_start = nonzero_groups;
+    2784                 :            : 
+    2785                 :            :             /* Accept a zero group at start, but it has to be a double colon */
+    2786                 :            :             if (zero_group_start == 0 && *++p != ':') {
+    2787                 :            :                 return -1;
+    2788                 :            :             }
+    2789                 :            : 
+    2790                 :            :             if (p[1] == '\0') {
+    2791                 :            :                 ++p;
+    2792                 :            :                 break;
+    2793                 :            :             }
+    2794                 :            :         }
+    2795                 :            :         ++p;
+    2796                 :            :     } while (nonzero_groups < 8);
+    2797                 :            : 
+    2798                 :            :     if (*p != '\0') {
+    2799                 :            :         return -1;
+    2800                 :            :     }
+    2801                 :            : 
+    2802                 :            :     if (zero_group_start != -1) {
+    2803                 :            :         if (nonzero_groups > 6) {
+    2804                 :            :             return -1;
+    2805                 :            :         }
+    2806                 :            :         int zero_groups = 8 - nonzero_groups;
+    2807                 :            :         int groups_after_zero = nonzero_groups - zero_group_start;
+    2808                 :            : 
+    2809                 :            :         /* Move the non-zero part to after the zeroes */
+    2810                 :            :         if (groups_after_zero) {
+    2811                 :            :             memmove(addr + zero_group_start + zero_groups,
+    2812                 :            :                     addr + zero_group_start,
+    2813                 :            :                     groups_after_zero * sizeof(*addr));
+    2814                 :            :         }
+    2815                 :            :         memset(addr + zero_group_start, 0, zero_groups * sizeof(*addr));
+    2816                 :            :     } else {
+    2817                 :            :         if (nonzero_groups != 8) {
+    2818                 :            :             return -1;
+    2819                 :            :         }
+    2820                 :            :     }
+    2821                 :            :     memcpy(dst, addr, sizeof(addr));
+    2822                 :            :     return 0;
+    2823                 :            : }
+    2824                 :            : 
+    2825                 :            : static int x509_inet_pton_ipv4(const char *src, void *dst)
+    2826                 :            : {
+    2827                 :            :     const unsigned char *p = (const unsigned char *) src;
+    2828                 :            :     uint8_t *res = (uint8_t *) dst;
+    2829                 :            :     uint8_t digit, num_digits = 0;
+    2830                 :            :     uint8_t num_octets = 0;
+    2831                 :            :     uint16_t octet;
+    2832                 :            : 
+    2833                 :            :     do {
+    2834                 :            :         octet = num_digits = 0;
+    2835                 :            :         do {
+    2836                 :            :             digit = *p - '0';
+    2837                 :            :             if (digit > 9) {
+    2838                 :            :                 break;
+    2839                 :            :             }
+    2840                 :            : 
+    2841                 :            :             /* Don't allow leading zeroes. These might mean octal format,
+    2842                 :            :              * which this implementation does not support. */
+    2843                 :            :             if (octet == 0 && num_digits > 0) {
+    2844                 :            :                 return -1;
+    2845                 :            :             }
+    2846                 :            : 
+    2847                 :            :             octet = octet * 10 + digit;
+    2848                 :            :             num_digits++;
+    2849                 :            :             p++;
+    2850                 :            :         } while (num_digits < 3);
+    2851                 :            : 
+    2852                 :            :         if (octet >= 256 || num_digits > 3 || num_digits == 0) {
+    2853                 :            :             return -1;
+    2854                 :            :         }
+    2855                 :            :         *res++ = (uint8_t) octet;
+    2856                 :            :         num_octets++;
+    2857                 :            :     } while (num_octets < 4 && *p++ == '.');
+    2858                 :            :     return num_octets == 4 && *p == '\0' ? 0 : -1;
+    2859                 :            : }
+    2860                 :            : 
+    2861                 :            : #else
+    2862                 :            : 
+    2863                 :          0 : static int x509_inet_pton_ipv6(const char *src, void *dst)
+    2864                 :            : {
+    2865         [ #  # ]:          0 :     return inet_pton(AF_INET6, src, dst) == 1 ? 0 : -1;
+    2866                 :            : }
+    2867                 :            : 
+    2868                 :          0 : static int x509_inet_pton_ipv4(const char *src, void *dst)
+    2869                 :            : {
+    2870         [ #  # ]:          0 :     return inet_pton(AF_INET, src, dst) == 1 ? 0 : -1;
+    2871                 :            : }
+    2872                 :            : 
+    2873                 :            : #endif /* !AF_INET6 || MBEDTLS_TEST_SW_INET_PTON */ //no-check-names
+    2874                 :            : 
+    2875                 :          0 : size_t mbedtls_x509_crt_parse_cn_inet_pton(const char *cn, void *dst)
+    2876                 :            : {
+    2877                 :          0 :     return strchr(cn, ':') == NULL
+    2878                 :          0 :             ? x509_inet_pton_ipv4(cn, dst) == 0 ? 4 : 0
+    2879   [ #  #  #  #  :          0 :             : x509_inet_pton_ipv6(cn, dst) == 0 ? 16 : 0;
+                   #  # ]
+    2880                 :            : }
+    2881                 :            : 
+    2882                 :            : /*
+    2883                 :            :  * Check for CN match
+    2884                 :            :  */
+    2885                 :          0 : static int x509_crt_check_cn(const mbedtls_x509_buf *name,
+    2886                 :            :                              const char *cn, size_t cn_len)
+    2887                 :            : {
+    2888                 :            :     /* try exact match */
+    2889   [ #  #  #  # ]:          0 :     if (name->len == cn_len &&
+    2890                 :          0 :         x509_memcasecmp(cn, name->p, cn_len) == 0) {
+    2891                 :          0 :         return 0;
+    2892                 :            :     }
+    2893                 :            : 
+    2894                 :            :     /* try wildcard match */
+    2895         [ #  # ]:          0 :     if (x509_check_wildcard(cn, name) == 0) {
+    2896                 :          0 :         return 0;
+    2897                 :            :     }
+    2898                 :            : 
+    2899                 :          0 :     return -1;
+    2900                 :            : }
+    2901                 :            : 
+    2902                 :          0 : static int x509_crt_check_san_ip(const mbedtls_x509_sequence *san,
+    2903                 :            :                                  const char *cn, size_t cn_len)
+    2904                 :            : {
+    2905                 :            :     uint32_t ip[4];
+    2906                 :          0 :     cn_len = mbedtls_x509_crt_parse_cn_inet_pton(cn, ip);
+    2907         [ #  # ]:          0 :     if (cn_len == 0) {
+    2908                 :          0 :         return -1;
+    2909                 :            :     }
+    2910                 :            : 
+    2911         [ #  # ]:          0 :     for (const mbedtls_x509_sequence *cur = san; cur != NULL; cur = cur->next) {
+    2912                 :          0 :         const unsigned char san_type = (unsigned char) cur->buf.tag &
+    2913                 :            :                                        MBEDTLS_ASN1_TAG_VALUE_MASK;
+    2914         [ #  # ]:          0 :         if (san_type == MBEDTLS_X509_SAN_IP_ADDRESS &&
+    2915   [ #  #  #  # ]:          0 :             cur->buf.len == cn_len && memcmp(cur->buf.p, ip, cn_len) == 0) {
+    2916                 :          0 :             return 0;
+    2917                 :            :         }
+    2918                 :            :     }
+    2919                 :            : 
+    2920                 :          0 :     return -1;
+    2921                 :            : }
+    2922                 :            : 
+    2923                 :          0 : static int x509_crt_check_san_uri(const mbedtls_x509_sequence *san,
+    2924                 :            :                                   const char *cn, size_t cn_len)
+    2925                 :            : {
+    2926         [ #  # ]:          0 :     for (const mbedtls_x509_sequence *cur = san; cur != NULL; cur = cur->next) {
+    2927                 :          0 :         const unsigned char san_type = (unsigned char) cur->buf.tag &
+    2928                 :            :                                        MBEDTLS_ASN1_TAG_VALUE_MASK;
+    2929         [ #  # ]:          0 :         if (san_type == MBEDTLS_X509_SAN_UNIFORM_RESOURCE_IDENTIFIER &&
+    2930   [ #  #  #  # ]:          0 :             cur->buf.len == cn_len && memcmp(cur->buf.p, cn, cn_len) == 0) {
+    2931                 :          0 :             return 0;
+    2932                 :            :         }
+    2933                 :            :     }
+    2934                 :            : 
+    2935                 :          0 :     return -1;
+    2936                 :            : }
+    2937                 :            : 
+    2938                 :            : /*
+    2939                 :            :  * Check for SAN match, see RFC 5280 Section 4.2.1.6
+    2940                 :            :  */
+    2941                 :          0 : static int x509_crt_check_san(const mbedtls_x509_sequence *san,
+    2942                 :            :                               const char *cn, size_t cn_len)
+    2943                 :            : {
+    2944                 :          0 :     int san_ip = 0;
+    2945                 :          0 :     int san_uri = 0;
+    2946                 :            :     /* Prioritize DNS name over other subtypes due to popularity */
+    2947         [ #  # ]:          0 :     for (const mbedtls_x509_sequence *cur = san; cur != NULL; cur = cur->next) {
+    2948   [ #  #  #  # ]:          0 :         switch ((unsigned char) cur->buf.tag & MBEDTLS_ASN1_TAG_VALUE_MASK) {
+    2949                 :          0 :             case MBEDTLS_X509_SAN_DNS_NAME:
+    2950         [ #  # ]:          0 :                 if (x509_crt_check_cn(&cur->buf, cn, cn_len) == 0) {
+    2951                 :          0 :                     return 0;
+    2952                 :            :                 }
+    2953                 :          0 :                 break;
+    2954                 :          0 :             case MBEDTLS_X509_SAN_IP_ADDRESS:
+    2955                 :          0 :                 san_ip = 1;
+    2956                 :          0 :                 break;
+    2957                 :          0 :             case MBEDTLS_X509_SAN_UNIFORM_RESOURCE_IDENTIFIER:
+    2958                 :          0 :                 san_uri = 1;
+    2959                 :          0 :                 break;
+    2960                 :            :             /* (We may handle other types here later.) */
+    2961                 :          0 :             default: /* Unrecognized type */
+    2962                 :          0 :                 break;
+    2963                 :            :         }
+    2964                 :            :     }
+    2965         [ #  # ]:          0 :     if (san_ip) {
+    2966         [ #  # ]:          0 :         if (x509_crt_check_san_ip(san, cn, cn_len) == 0) {
+    2967                 :          0 :             return 0;
+    2968                 :            :         }
+    2969                 :            :     }
+    2970         [ #  # ]:          0 :     if (san_uri) {
+    2971         [ #  # ]:          0 :         if (x509_crt_check_san_uri(san, cn, cn_len) == 0) {
+    2972                 :          0 :             return 0;
+    2973                 :            :         }
+    2974                 :            :     }
+    2975                 :            : 
+    2976                 :          0 :     return -1;
+    2977                 :            : }
+    2978                 :            : 
+    2979                 :            : /*
+    2980                 :            :  * Verify the requested CN - only call this if cn is not NULL!
+    2981                 :            :  */
+    2982                 :          0 : static void x509_crt_verify_name(const mbedtls_x509_crt *crt,
+    2983                 :            :                                  const char *cn,
+    2984                 :            :                                  uint32_t *flags)
+    2985                 :            : {
+    2986                 :            :     const mbedtls_x509_name *name;
+    2987                 :          0 :     size_t cn_len = strlen(cn);
+    2988                 :            : 
+    2989         [ #  # ]:          0 :     if (crt->ext_types & MBEDTLS_X509_EXT_SUBJECT_ALT_NAME) {
+    2990         [ #  # ]:          0 :         if (x509_crt_check_san(&crt->subject_alt_names, cn, cn_len) == 0) {
+    2991                 :          0 :             return;
+    2992                 :            :         }
+    2993                 :            :     } else {
+    2994         [ #  # ]:          0 :         for (name = &crt->subject; name != NULL; name = name->next) {
+    2995   [ #  #  #  #  :          0 :             if (MBEDTLS_OID_CMP(MBEDTLS_OID_AT_CN, &name->oid) == 0 &&
+             #  #  #  # ]
+    2996                 :          0 :                 x509_crt_check_cn(&name->val, cn, cn_len) == 0) {
+    2997                 :          0 :                 return;
+    2998                 :            :             }
+    2999                 :            :         }
+    3000                 :            : 
+    3001                 :            :     }
+    3002                 :            : 
+    3003                 :          0 :     *flags |= MBEDTLS_X509_BADCERT_CN_MISMATCH;
+    3004                 :            : }
+    3005                 :            : 
+    3006                 :            : /*
+    3007                 :            :  * Merge the flags for all certs in the chain, after calling callback
+    3008                 :            :  */
+    3009                 :       2255 : static int x509_crt_merge_flags_with_cb(
+    3010                 :            :     uint32_t *flags,
+    3011                 :            :     const mbedtls_x509_crt_verify_chain *ver_chain,
+    3012                 :            :     int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
+    3013                 :            :     void *p_vrfy)
+    3014                 :            : {
+    3015                 :       2255 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    3016                 :            :     unsigned i;
+    3017                 :            :     uint32_t cur_flags;
+    3018                 :            :     const mbedtls_x509_crt_verify_chain_item *cur;
+    3019                 :            : 
+    3020         [ +  + ]:       6096 :     for (i = ver_chain->len; i != 0; --i) {
+    3021                 :       3841 :         cur = &ver_chain->items[i-1];
+    3022                 :       3841 :         cur_flags = cur->flags;
+    3023                 :            : 
+    3024         [ -  + ]:       3841 :         if (NULL != f_vrfy) {
+    3025         [ #  # ]:          0 :             if ((ret = f_vrfy(p_vrfy, cur->crt, (int) i-1, &cur_flags)) != 0) {
+    3026                 :          0 :                 return ret;
+    3027                 :            :             }
+    3028                 :            :         }
+    3029                 :            : 
+    3030                 :       3841 :         *flags |= cur_flags;
+    3031                 :            :     }
+    3032                 :            : 
+    3033                 :       2255 :     return 0;
+    3034                 :            : }
+    3035                 :            : 
+    3036                 :            : /*
+    3037                 :            :  * Verify the certificate validity, with profile, restartable version
+    3038                 :            :  *
+    3039                 :            :  * This function:
+    3040                 :            :  *  - checks the requested CN (if any)
+    3041                 :            :  *  - checks the type and size of the EE cert's key,
+    3042                 :            :  *    as that isn't done as part of chain building/verification currently
+    3043                 :            :  *  - builds and verifies the chain
+    3044                 :            :  *  - then calls the callback and merges the flags
+    3045                 :            :  *
+    3046                 :            :  * The parameters pairs `trust_ca`, `ca_crl` and `f_ca_cb`, `p_ca_cb`
+    3047                 :            :  * are mutually exclusive: If `f_ca_cb != NULL`, it will be used by the
+    3048                 :            :  * verification routine to search for trusted signers, and CRLs will
+    3049                 :            :  * be disabled. Otherwise, `trust_ca` will be used as the static list
+    3050                 :            :  * of trusted signers, and `ca_crl` will be use as the static list
+    3051                 :            :  * of CRLs.
+    3052                 :            :  */
+    3053                 :       2255 : static int x509_crt_verify_restartable_ca_cb(mbedtls_x509_crt *crt,
+    3054                 :            :                                              mbedtls_x509_crt *trust_ca,
+    3055                 :            :                                              mbedtls_x509_crl *ca_crl,
+    3056                 :            :                                              mbedtls_x509_crt_ca_cb_t f_ca_cb,
+    3057                 :            :                                              void *p_ca_cb,
+    3058                 :            :                                              const mbedtls_x509_crt_profile *profile,
+    3059                 :            :                                              const char *cn, uint32_t *flags,
+    3060                 :            :                                              int (*f_vrfy)(void *,
+    3061                 :            :                                                            mbedtls_x509_crt *,
+    3062                 :            :                                                            int,
+    3063                 :            :                                                            uint32_t *),
+    3064                 :            :                                              void *p_vrfy,
+    3065                 :            :                                              mbedtls_x509_crt_restart_ctx *rs_ctx)
+    3066                 :            : {
+    3067                 :       2255 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+    3068                 :            :     mbedtls_pk_type_t pk_type;
+    3069                 :            :     mbedtls_x509_crt_verify_chain ver_chain;
+    3070                 :            :     uint32_t ee_flags;
+    3071                 :            : 
+    3072                 :       2255 :     *flags = 0;
+    3073                 :       2255 :     ee_flags = 0;
+    3074                 :       2255 :     x509_crt_verify_chain_reset(&ver_chain);
+    3075                 :            : 
+    3076         [ -  + ]:       2255 :     if (profile == NULL) {
+    3077                 :          0 :         ret = MBEDTLS_ERR_X509_BAD_INPUT_DATA;
+    3078                 :          0 :         goto exit;
+    3079                 :            :     }
+    3080                 :            : 
+    3081                 :            :     /* check name if requested */
+    3082         [ -  + ]:       2255 :     if (cn != NULL) {
+    3083                 :          0 :         x509_crt_verify_name(crt, cn, &ee_flags);
+    3084                 :            :     }
+    3085                 :            : 
+    3086                 :            :     /* Check the type and size of the key */
+    3087                 :       2255 :     pk_type = mbedtls_pk_get_type(&crt->pk);
+    3088                 :            : 
+    3089         [ -  + ]:       2255 :     if (x509_profile_check_pk_alg(profile, pk_type) != 0) {
+    3090                 :          0 :         ee_flags |= MBEDTLS_X509_BADCERT_BAD_PK;
+    3091                 :            :     }
+    3092                 :            : 
+    3093         [ -  + ]:       2255 :     if (x509_profile_check_key(profile, &crt->pk) != 0) {
+    3094                 :          0 :         ee_flags |= MBEDTLS_X509_BADCERT_BAD_KEY;
+    3095                 :            :     }
+    3096                 :            : 
+    3097                 :            :     /* Check the chain */
+    3098                 :       2255 :     ret = x509_crt_verify_chain(crt, trust_ca, ca_crl,
+    3099                 :            :                                 f_ca_cb, p_ca_cb, profile,
+    3100                 :            :                                 &ver_chain, rs_ctx);
+    3101                 :            : 
+    3102         [ -  + ]:       2255 :     if (ret != 0) {
+    3103                 :          0 :         goto exit;
+    3104                 :            :     }
+    3105                 :            : 
+    3106                 :            :     /* Merge end-entity flags */
+    3107                 :       2255 :     ver_chain.items[0].flags |= ee_flags;
+    3108                 :            : 
+    3109                 :            :     /* Build final flags, calling callback on the way if any */
+    3110                 :       2255 :     ret = x509_crt_merge_flags_with_cb(flags, &ver_chain, f_vrfy, p_vrfy);
+    3111                 :            : 
+    3112                 :       2255 : exit:
+    3113                 :            : 
+    3114                 :            : #if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
+    3115                 :            :     mbedtls_x509_crt_free(ver_chain.trust_ca_cb_result);
+    3116                 :            :     mbedtls_free(ver_chain.trust_ca_cb_result);
+    3117                 :            :     ver_chain.trust_ca_cb_result = NULL;
+    3118                 :            : #endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
+    3119                 :            : 
+    3120                 :            : #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
+    3121   [ -  +  -  - ]:       2255 :     if (rs_ctx != NULL && ret != MBEDTLS_ERR_ECP_IN_PROGRESS) {
+    3122                 :          0 :         mbedtls_x509_crt_restart_free(rs_ctx);
+    3123                 :            :     }
+    3124                 :            : #endif
+    3125                 :            : 
+    3126                 :            :     /* prevent misuse of the vrfy callback - VERIFY_FAILED would be ignored by
+    3127                 :            :      * the SSL module for authmode optional, but non-zero return from the
+    3128                 :            :      * callback means a fatal error so it shouldn't be ignored */
+    3129         [ -  + ]:       2255 :     if (ret == MBEDTLS_ERR_X509_CERT_VERIFY_FAILED) {
+    3130                 :          0 :         ret = MBEDTLS_ERR_X509_FATAL_ERROR;
+    3131                 :            :     }
+    3132                 :            : 
+    3133         [ -  + ]:       2255 :     if (ret != 0) {
+    3134                 :          0 :         *flags = (uint32_t) -1;
+    3135                 :          0 :         return ret;
+    3136                 :            :     }
+    3137                 :            : 
+    3138         [ +  + ]:       2255 :     if (*flags != 0) {
+    3139                 :          3 :         return MBEDTLS_ERR_X509_CERT_VERIFY_FAILED;
+    3140                 :            :     }
+    3141                 :            : 
+    3142                 :       2252 :     return 0;
+    3143                 :            : }
+    3144                 :            : 
+    3145                 :            : 
+    3146                 :            : /*
+    3147                 :            :  * Verify the certificate validity (default profile, not restartable)
+    3148                 :            :  */
+    3149                 :          0 : int mbedtls_x509_crt_verify(mbedtls_x509_crt *crt,
+    3150                 :            :                             mbedtls_x509_crt *trust_ca,
+    3151                 :            :                             mbedtls_x509_crl *ca_crl,
+    3152                 :            :                             const char *cn, uint32_t *flags,
+    3153                 :            :                             int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
+    3154                 :            :                             void *p_vrfy)
+    3155                 :            : {
+    3156                 :          0 :     return x509_crt_verify_restartable_ca_cb(crt, trust_ca, ca_crl,
+    3157                 :            :                                              NULL, NULL,
+    3158                 :            :                                              &mbedtls_x509_crt_profile_default,
+    3159                 :            :                                              cn, flags,
+    3160                 :            :                                              f_vrfy, p_vrfy, NULL);
+    3161                 :            : }
+    3162                 :            : 
+    3163                 :            : /*
+    3164                 :            :  * Verify the certificate validity (user-chosen profile, not restartable)
+    3165                 :            :  */
+    3166                 :       2255 : int mbedtls_x509_crt_verify_with_profile(mbedtls_x509_crt *crt,
+    3167                 :            :                                          mbedtls_x509_crt *trust_ca,
+    3168                 :            :                                          mbedtls_x509_crl *ca_crl,
+    3169                 :            :                                          const mbedtls_x509_crt_profile *profile,
+    3170                 :            :                                          const char *cn, uint32_t *flags,
+    3171                 :            :                                          int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
+    3172                 :            :                                          void *p_vrfy)
+    3173                 :            : {
+    3174                 :       2255 :     return x509_crt_verify_restartable_ca_cb(crt, trust_ca, ca_crl,
+    3175                 :            :                                              NULL, NULL,
+    3176                 :            :                                              profile, cn, flags,
+    3177                 :            :                                              f_vrfy, p_vrfy, NULL);
+    3178                 :            : }
+    3179                 :            : 
+    3180                 :            : #if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
+    3181                 :            : /*
+    3182                 :            :  * Verify the certificate validity (user-chosen profile, CA callback,
+    3183                 :            :  *                                  not restartable).
+    3184                 :            :  */
+    3185                 :            : int mbedtls_x509_crt_verify_with_ca_cb(mbedtls_x509_crt *crt,
+    3186                 :            :                                        mbedtls_x509_crt_ca_cb_t f_ca_cb,
+    3187                 :            :                                        void *p_ca_cb,
+    3188                 :            :                                        const mbedtls_x509_crt_profile *profile,
+    3189                 :            :                                        const char *cn, uint32_t *flags,
+    3190                 :            :                                        int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
+    3191                 :            :                                        void *p_vrfy)
+    3192                 :            : {
+    3193                 :            :     return x509_crt_verify_restartable_ca_cb(crt, NULL, NULL,
+    3194                 :            :                                              f_ca_cb, p_ca_cb,
+    3195                 :            :                                              profile, cn, flags,
+    3196                 :            :                                              f_vrfy, p_vrfy, NULL);
+    3197                 :            : }
+    3198                 :            : #endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
+    3199                 :            : 
+    3200                 :          0 : int mbedtls_x509_crt_verify_restartable(mbedtls_x509_crt *crt,
+    3201                 :            :                                         mbedtls_x509_crt *trust_ca,
+    3202                 :            :                                         mbedtls_x509_crl *ca_crl,
+    3203                 :            :                                         const mbedtls_x509_crt_profile *profile,
+    3204                 :            :                                         const char *cn, uint32_t *flags,
+    3205                 :            :                                         int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
+    3206                 :            :                                         void *p_vrfy,
+    3207                 :            :                                         mbedtls_x509_crt_restart_ctx *rs_ctx)
+    3208                 :            : {
+    3209                 :          0 :     return x509_crt_verify_restartable_ca_cb(crt, trust_ca, ca_crl,
+    3210                 :            :                                              NULL, NULL,
+    3211                 :            :                                              profile, cn, flags,
+    3212                 :            :                                              f_vrfy, p_vrfy, rs_ctx);
+    3213                 :            : }
+    3214                 :            : 
+    3215                 :            : 
+    3216                 :            : /*
+    3217                 :            :  * Initialize a certificate chain
+    3218                 :            :  */
+    3219                 :      12125 : void mbedtls_x509_crt_init(mbedtls_x509_crt *crt)
+    3220                 :            : {
+    3221                 :      12125 :     memset(crt, 0, sizeof(mbedtls_x509_crt));
+    3222                 :      12125 : }
+    3223                 :            : 
+    3224                 :            : /*
+    3225                 :            :  * Unallocate all certificate data
+    3226                 :            :  */
+    3227                 :      12119 : void mbedtls_x509_crt_free(mbedtls_x509_crt *crt)
+    3228                 :            : {
+    3229                 :      12119 :     mbedtls_x509_crt *cert_cur = crt;
+    3230                 :            :     mbedtls_x509_crt *cert_prv;
+    3231                 :            : 
+    3232         [ +  + ]:      24238 :     while (cert_cur != NULL) {
+    3233                 :      12119 :         mbedtls_pk_free(&cert_cur->pk);
+    3234                 :            : 
+    3235                 :            : #if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
+    3236                 :      12119 :         mbedtls_free(cert_cur->sig_opts);
+    3237                 :            : #endif
+    3238                 :            : 
+    3239                 :      12119 :         mbedtls_asn1_free_named_data_list_shallow(cert_cur->issuer.next);
+    3240                 :      12119 :         mbedtls_asn1_free_named_data_list_shallow(cert_cur->subject.next);
+    3241                 :      12119 :         mbedtls_asn1_sequence_free(cert_cur->ext_key_usage.next);
+    3242                 :      12119 :         mbedtls_asn1_sequence_free(cert_cur->subject_alt_names.next);
+    3243                 :      12119 :         mbedtls_asn1_sequence_free(cert_cur->certificate_policies.next);
+    3244                 :      12119 :         mbedtls_asn1_sequence_free(cert_cur->authority_key_id.authorityCertIssuer.next);
+    3245                 :            : 
+    3246   [ +  -  +  - ]:      12119 :         if (cert_cur->raw.p != NULL && cert_cur->own_buffer) {
+    3247                 :      12119 :             mbedtls_zeroize_and_free(cert_cur->raw.p, cert_cur->raw.len);
+    3248                 :            :         }
+    3249                 :            : 
+    3250                 :      12119 :         cert_prv = cert_cur;
+    3251                 :      12119 :         cert_cur = cert_cur->next;
+    3252                 :            : 
+    3253                 :      12119 :         mbedtls_platform_zeroize(cert_prv, sizeof(mbedtls_x509_crt));
+    3254         [ -  + ]:      12119 :         if (cert_prv != crt) {
+    3255                 :          0 :             mbedtls_free(cert_prv);
+    3256                 :            :         }
+    3257                 :            :     }
+    3258                 :      12119 : }
+    3259                 :            : 
+    3260                 :            : #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
+    3261                 :            : /*
+    3262                 :            :  * Initialize a restart context
+    3263                 :            :  */
+    3264                 :          0 : void mbedtls_x509_crt_restart_init(mbedtls_x509_crt_restart_ctx *ctx)
+    3265                 :            : {
+    3266                 :          0 :     mbedtls_pk_restart_init(&ctx->pk);
+    3267                 :            : 
+    3268                 :          0 :     ctx->parent = NULL;
+    3269                 :          0 :     ctx->fallback_parent = NULL;
+    3270                 :          0 :     ctx->fallback_signature_is_good = 0;
+    3271                 :            : 
+    3272                 :          0 :     ctx->parent_is_trusted = -1;
+    3273                 :            : 
+    3274                 :          0 :     ctx->in_progress = x509_crt_rs_none;
+    3275                 :          0 :     ctx->self_cnt = 0;
+    3276                 :          0 :     x509_crt_verify_chain_reset(&ctx->ver_chain);
+    3277                 :          0 : }
+    3278                 :            : 
+    3279                 :            : /*
+    3280                 :            :  * Free the components of a restart context
+    3281                 :            :  */
+    3282                 :          0 : void mbedtls_x509_crt_restart_free(mbedtls_x509_crt_restart_ctx *ctx)
+    3283                 :            : {
+    3284         [ #  # ]:          0 :     if (ctx == NULL) {
+    3285                 :          0 :         return;
+    3286                 :            :     }
+    3287                 :            : 
+    3288                 :          0 :     mbedtls_pk_restart_free(&ctx->pk);
+    3289                 :          0 :     mbedtls_x509_crt_restart_init(ctx);
+    3290                 :            : }
+    3291                 :            : #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
+    3292                 :            : 
+    3293                 :          0 : int mbedtls_x509_crt_get_ca_istrue(const mbedtls_x509_crt *crt)
+    3294                 :            : {
+    3295         [ #  # ]:          0 :     if ((crt->ext_types & MBEDTLS_X509_EXT_BASIC_CONSTRAINTS) != 0) {
+    3296                 :          0 :         return crt->MBEDTLS_PRIVATE(ca_istrue);
+    3297                 :            :     }
+    3298                 :          0 :     return MBEDTLS_ERR_X509_INVALID_EXTENSIONS;
+    3299                 :            : }
+    3300                 :            : 
+    3301                 :            : #endif /* MBEDTLS_X509_CRT_PARSE_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509write.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509write.c.func-sort-c.html new file mode 100644 index 00000000000..b3733bef1ce --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509write.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/x509write.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - x509write.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:0590.0 %
Date:2024-09-22 08:21:07Functions:010.0 %
Branches:0480.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_x509_write_set_san_common0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509write.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509write.c.func.html new file mode 100644 index 00000000000..60c88ff9628 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509write.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/x509write.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - x509write.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:0590.0 %
Date:2024-09-22 08:21:07Functions:010.0 %
Branches:0480.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_x509_write_set_san_common0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509write.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509write.c.gcov.html new file mode 100644 index 00000000000..3869f5c19ff --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509write.c.gcov.html @@ -0,0 +1,259 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/x509write.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - x509write.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:0590.0 %
Date:2024-09-22 08:21:07Functions:010.0 %
Branches:0480.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  *  X.509 internal, common functions for writing
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  */
+       7                 :            : #include "common.h"
+       8                 :            : #if defined(MBEDTLS_X509_CSR_WRITE_C) || defined(MBEDTLS_X509_CRT_WRITE_C)
+       9                 :            : 
+      10                 :            : #include "mbedtls/x509_crt.h"
+      11                 :            : #include "x509_internal.h"
+      12                 :            : #include "mbedtls/asn1write.h"
+      13                 :            : #include "mbedtls/error.h"
+      14                 :            : #include "mbedtls/oid.h"
+      15                 :            : #include "mbedtls/platform.h"
+      16                 :            : #include "mbedtls/platform_util.h"
+      17                 :            : 
+      18                 :            : #include <string.h>
+      19                 :            : #include <stdint.h>
+      20                 :            : 
+      21                 :            : #if defined(MBEDTLS_PEM_WRITE_C)
+      22                 :            : #include "mbedtls/pem.h"
+      23                 :            : #endif /* MBEDTLS_PEM_WRITE_C */
+      24                 :            : 
+      25                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+      26                 :            : #include "psa/crypto.h"
+      27                 :            : #include "mbedtls/psa_util.h"
+      28                 :            : #include "md_psa.h"
+      29                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO */
+      30                 :            : 
+      31                 :            : #define CHECK_OVERFLOW_ADD(a, b) \
+      32                 :            :     do                         \
+      33                 :            :     {                           \
+      34                 :            :         if (a > SIZE_MAX - (b)) \
+      35                 :            :         { \
+      36                 :            :             return MBEDTLS_ERR_X509_BAD_INPUT_DATA; \
+      37                 :            :         }                            \
+      38                 :            :         a += b; \
+      39                 :            :     } while (0)
+      40                 :            : 
+      41                 :          0 : int mbedtls_x509_write_set_san_common(mbedtls_asn1_named_data **extensions,
+      42                 :            :                                       const mbedtls_x509_san_list *san_list)
+      43                 :            : {
+      44                 :          0 :     int ret = 0;
+      45                 :            :     const mbedtls_x509_san_list *cur;
+      46                 :            :     unsigned char *buf;
+      47                 :            :     unsigned char *p;
+      48                 :            :     size_t len;
+      49                 :          0 :     size_t buflen = 0;
+      50                 :            : 
+      51                 :            :     /* Determine the maximum size of the SubjectAltName list */
+      52         [ #  # ]:          0 :     for (cur = san_list; cur != NULL; cur = cur->next) {
+      53                 :            :         /* Calculate size of the required buffer */
+      54      [ #  #  # ]:          0 :         switch (cur->node.type) {
+      55                 :          0 :             case MBEDTLS_X509_SAN_DNS_NAME:
+      56                 :            :             case MBEDTLS_X509_SAN_UNIFORM_RESOURCE_IDENTIFIER:
+      57                 :            :             case MBEDTLS_X509_SAN_IP_ADDRESS:
+      58                 :            :             case MBEDTLS_X509_SAN_RFC822_NAME:
+      59                 :            :                 /* length of value for each name entry,
+      60                 :            :                  * maximum 4 bytes for the length field,
+      61                 :            :                  * 1 byte for the tag/type.
+      62                 :            :                  */
+      63         [ #  # ]:          0 :                 CHECK_OVERFLOW_ADD(buflen, cur->node.san.unstructured_name.len);
+      64         [ #  # ]:          0 :                 CHECK_OVERFLOW_ADD(buflen, 4 + 1);
+      65                 :          0 :                 break;
+      66                 :          0 :             case MBEDTLS_X509_SAN_DIRECTORY_NAME:
+      67                 :            :             {
+      68                 :          0 :                 const mbedtls_asn1_named_data *chunk = &cur->node.san.directory_name;
+      69         [ #  # ]:          0 :                 while (chunk != NULL) {
+      70                 :            :                     // Max 4 bytes for length, +1 for tag,
+      71                 :            :                     // additional 4 max for length, +1 for tag.
+      72                 :            :                     // See x509_write_name for more information.
+      73         [ #  # ]:          0 :                     CHECK_OVERFLOW_ADD(buflen, 4 + 1 + 4 + 1);
+      74         [ #  # ]:          0 :                     CHECK_OVERFLOW_ADD(buflen, chunk->oid.len);
+      75         [ #  # ]:          0 :                     CHECK_OVERFLOW_ADD(buflen, chunk->val.len);
+      76                 :          0 :                     chunk = chunk->next;
+      77                 :            :                 }
+      78         [ #  # ]:          0 :                 CHECK_OVERFLOW_ADD(buflen, 4 + 1);
+      79                 :          0 :                 break;
+      80                 :            :             }
+      81                 :          0 :             default:
+      82                 :            :                 /* Not supported - return. */
+      83                 :          0 :                 return MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE;
+      84                 :            :         }
+      85                 :            :     }
+      86                 :            : 
+      87                 :            :     /* Add the extra length field and tag */
+      88         [ #  # ]:          0 :     CHECK_OVERFLOW_ADD(buflen, 4 + 1);
+      89                 :            : 
+      90                 :            :     /* Allocate buffer */
+      91                 :          0 :     buf = mbedtls_calloc(1, buflen);
+      92         [ #  # ]:          0 :     if (buf == NULL) {
+      93                 :          0 :         return MBEDTLS_ERR_ASN1_ALLOC_FAILED;
+      94                 :            :     }
+      95                 :          0 :     p = buf + buflen;
+      96                 :            : 
+      97                 :            :     /* Write ASN.1-based structure */
+      98                 :          0 :     cur = san_list;
+      99                 :          0 :     len = 0;
+     100         [ #  # ]:          0 :     while (cur != NULL) {
+     101                 :          0 :         size_t single_san_len = 0;
+     102      [ #  #  # ]:          0 :         switch (cur->node.type) {
+     103                 :          0 :             case MBEDTLS_X509_SAN_DNS_NAME:
+     104                 :            :             case MBEDTLS_X509_SAN_RFC822_NAME:
+     105                 :            :             case MBEDTLS_X509_SAN_UNIFORM_RESOURCE_IDENTIFIER:
+     106                 :            :             case MBEDTLS_X509_SAN_IP_ADDRESS:
+     107                 :            :             {
+     108                 :          0 :                 const unsigned char *unstructured_name =
+     109                 :            :                     (const unsigned char *) cur->node.san.unstructured_name.p;
+     110                 :          0 :                 size_t unstructured_name_len = cur->node.san.unstructured_name.len;
+     111                 :            : 
+     112         [ #  # ]:          0 :                 MBEDTLS_ASN1_CHK_CLEANUP_ADD(single_san_len,
+     113                 :            :                                              mbedtls_asn1_write_raw_buffer(
+     114                 :            :                                                  &p, buf,
+     115                 :            :                                                  unstructured_name, unstructured_name_len));
+     116         [ #  # ]:          0 :                 MBEDTLS_ASN1_CHK_CLEANUP_ADD(single_san_len, mbedtls_asn1_write_len(
+     117                 :            :                                                  &p, buf, unstructured_name_len));
+     118         [ #  # ]:          0 :                 MBEDTLS_ASN1_CHK_CLEANUP_ADD(single_san_len,
+     119                 :            :                                              mbedtls_asn1_write_tag(
+     120                 :            :                                                  &p, buf,
+     121                 :            :                                                  MBEDTLS_ASN1_CONTEXT_SPECIFIC | cur->node.type));
+     122                 :            :             }
+     123                 :          0 :             break;
+     124                 :          0 :             case MBEDTLS_X509_SAN_DIRECTORY_NAME:
+     125         [ #  # ]:          0 :                 MBEDTLS_ASN1_CHK_CLEANUP_ADD(single_san_len,
+     126                 :            :                                              mbedtls_x509_write_names(&p, buf,
+     127                 :            :                                                                       (mbedtls_asn1_named_data *) &
+     128                 :            :                                                                       cur->node
+     129                 :            :                                                                       .san.directory_name));
+     130         [ #  # ]:          0 :                 MBEDTLS_ASN1_CHK_CLEANUP_ADD(single_san_len,
+     131                 :            :                                              mbedtls_asn1_write_len(&p, buf, single_san_len));
+     132         [ #  # ]:          0 :                 MBEDTLS_ASN1_CHK_CLEANUP_ADD(single_san_len,
+     133                 :            :                                              mbedtls_asn1_write_tag(&p, buf,
+     134                 :            :                                                                     MBEDTLS_ASN1_CONTEXT_SPECIFIC |
+     135                 :            :                                                                     MBEDTLS_ASN1_CONSTRUCTED |
+     136                 :            :                                                                     MBEDTLS_X509_SAN_DIRECTORY_NAME));
+     137                 :          0 :                 break;
+     138                 :          0 :             default:
+     139                 :            :                 /* Error out on an unsupported SAN */
+     140                 :          0 :                 ret = MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE;
+     141                 :          0 :                 goto cleanup;
+     142                 :            :         }
+     143                 :          0 :         cur = cur->next;
+     144                 :            :         /* check for overflow */
+     145         [ #  # ]:          0 :         if (len > SIZE_MAX - single_san_len) {
+     146                 :          0 :             ret = MBEDTLS_ERR_X509_BAD_INPUT_DATA;
+     147                 :          0 :             goto cleanup;
+     148                 :            :         }
+     149                 :          0 :         len += single_san_len;
+     150                 :            :     }
+     151                 :            : 
+     152         [ #  # ]:          0 :     MBEDTLS_ASN1_CHK_CLEANUP_ADD(len, mbedtls_asn1_write_len(&p, buf, len));
+     153         [ #  # ]:          0 :     MBEDTLS_ASN1_CHK_CLEANUP_ADD(len,
+     154                 :            :                                  mbedtls_asn1_write_tag(&p, buf,
+     155                 :            :                                                         MBEDTLS_ASN1_CONSTRUCTED |
+     156                 :            :                                                         MBEDTLS_ASN1_SEQUENCE));
+     157                 :            : 
+     158                 :          0 :     ret = mbedtls_x509_set_extension(extensions,
+     159                 :            :                                      MBEDTLS_OID_SUBJECT_ALT_NAME,
+     160                 :            :                                      MBEDTLS_OID_SIZE(MBEDTLS_OID_SUBJECT_ALT_NAME),
+     161                 :            :                                      0,
+     162                 :          0 :                                      buf + buflen - len, len);
+     163                 :            : 
+     164                 :            :     /* If we exceeded the allocated buffer it means that maximum size of the SubjectAltName list
+     165                 :            :      * was incorrectly calculated and memory is corrupted. */
+     166         [ #  # ]:          0 :     if (p < buf) {
+     167                 :          0 :         ret = MBEDTLS_ERR_ASN1_LENGTH_MISMATCH;
+     168                 :            :     }
+     169                 :          0 : cleanup:
+     170                 :          0 :     mbedtls_free(buf);
+     171                 :          0 :     return ret;
+     172                 :            : }
+     173                 :            : 
+     174                 :            : #endif /* MBEDTLS_X509_CSR_WRITE_C || MBEDTLS_X509_CRT_WRITE_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509write_csr.c.func-sort-c.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509write_csr.c.func-sort-c.html new file mode 100644 index 00000000000..60bd83e3fd3 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509write_csr.c.func-sort-c.html @@ -0,0 +1,129 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/x509write_csr.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - x509write_csr.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:6410362.1 %
Date:2024-09-22 08:21:07Functions:81266.7 %
Branches:256637.9 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_x509write_csr_pem0
mbedtls_x509write_csr_set_key_usage0
mbedtls_x509write_csr_set_ns_cert_type0
mbedtls_x509write_csr_set_subject_alternative_name0
mbedtls_x509write_csr_der6
mbedtls_x509write_csr_free6
mbedtls_x509write_csr_init6
mbedtls_x509write_csr_set_key6
mbedtls_x509write_csr_set_md_alg6
x509write_csr_der_internal6
mbedtls_x509write_csr_set_subject_name8
mbedtls_x509write_csr_set_extension38
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509write_csr.c.func.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509write_csr.c.func.html new file mode 100644 index 00000000000..3084d8a9712 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509write_csr.c.func.html @@ -0,0 +1,129 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/x509write_csr.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - x509write_csr.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:6410362.1 %
Date:2024-09-22 08:21:07Functions:81266.7 %
Branches:256637.9 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
mbedtls_x509write_csr_der6
mbedtls_x509write_csr_free6
mbedtls_x509write_csr_init6
mbedtls_x509write_csr_pem0
mbedtls_x509write_csr_set_extension38
mbedtls_x509write_csr_set_key6
mbedtls_x509write_csr_set_key_usage0
mbedtls_x509write_csr_set_md_alg6
mbedtls_x509write_csr_set_ns_cert_type0
mbedtls_x509write_csr_set_subject_alternative_name0
mbedtls_x509write_csr_set_subject_name8
x509write_csr_der_internal6
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509write_csr.c.gcov.html b/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509write_csr.c.gcov.html new file mode 100644 index 00000000000..d1227c0df45 --- /dev/null +++ b/coverage_log/os_stub/mbedtlslib/mbedtls/library/x509write_csr.c.gcov.html @@ -0,0 +1,416 @@ + + + + + + + LCOV - coverage.info - os_stub/mbedtlslib/mbedtls/library/x509write_csr.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/mbedtlslib/mbedtls/library - x509write_csr.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:6410362.1 %
Date:2024-09-22 08:21:07Functions:81266.7 %
Branches:256637.9 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  *  X.509 Certificate Signing Request writing
+       3                 :            :  *
+       4                 :            :  *  Copyright The Mbed TLS Contributors
+       5                 :            :  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+       6                 :            :  */
+       7                 :            : /*
+       8                 :            :  * References:
+       9                 :            :  * - CSRs: PKCS#10 v1.7 aka RFC 2986
+      10                 :            :  * - attributes: PKCS#9 v2.0 aka RFC 2985
+      11                 :            :  */
+      12                 :            : 
+      13                 :            : #include "common.h"
+      14                 :            : 
+      15                 :            : #if defined(MBEDTLS_X509_CSR_WRITE_C)
+      16                 :            : 
+      17                 :            : #include "x509_internal.h"
+      18                 :            : #include "mbedtls/x509_csr.h"
+      19                 :            : #include "mbedtls/asn1write.h"
+      20                 :            : #include "mbedtls/error.h"
+      21                 :            : #include "mbedtls/oid.h"
+      22                 :            : #include "mbedtls/platform_util.h"
+      23                 :            : 
+      24                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+      25                 :            : #include "psa/crypto.h"
+      26                 :            : #include "psa_util_internal.h"
+      27                 :            : #include "mbedtls/psa_util.h"
+      28                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO */
+      29                 :            : 
+      30                 :            : #include <string.h>
+      31                 :            : #include <stdlib.h>
+      32                 :            : 
+      33                 :            : #if defined(MBEDTLS_PEM_WRITE_C)
+      34                 :            : #include "mbedtls/pem.h"
+      35                 :            : #endif
+      36                 :            : 
+      37                 :            : #include "mbedtls/platform.h"
+      38                 :            : 
+      39                 :          6 : void mbedtls_x509write_csr_init(mbedtls_x509write_csr *ctx)
+      40                 :            : {
+      41                 :          6 :     memset(ctx, 0, sizeof(mbedtls_x509write_csr));
+      42                 :          6 : }
+      43                 :            : 
+      44                 :          6 : void mbedtls_x509write_csr_free(mbedtls_x509write_csr *ctx)
+      45                 :            : {
+      46                 :          6 :     mbedtls_asn1_free_named_data_list(&ctx->subject);
+      47                 :          6 :     mbedtls_asn1_free_named_data_list(&ctx->extensions);
+      48                 :            : 
+      49                 :          6 :     mbedtls_platform_zeroize(ctx, sizeof(mbedtls_x509write_csr));
+      50                 :          6 : }
+      51                 :            : 
+      52                 :          6 : void mbedtls_x509write_csr_set_md_alg(mbedtls_x509write_csr *ctx, mbedtls_md_type_t md_alg)
+      53                 :            : {
+      54                 :          6 :     ctx->md_alg = md_alg;
+      55                 :          6 : }
+      56                 :            : 
+      57                 :          6 : void mbedtls_x509write_csr_set_key(mbedtls_x509write_csr *ctx, mbedtls_pk_context *key)
+      58                 :            : {
+      59                 :          6 :     ctx->key = key;
+      60                 :          6 : }
+      61                 :            : 
+      62                 :          8 : int mbedtls_x509write_csr_set_subject_name(mbedtls_x509write_csr *ctx,
+      63                 :            :                                            const char *subject_name)
+      64                 :            : {
+      65                 :          8 :     return mbedtls_x509_string_to_names(&ctx->subject, subject_name);
+      66                 :            : }
+      67                 :            : 
+      68                 :         38 : int mbedtls_x509write_csr_set_extension(mbedtls_x509write_csr *ctx,
+      69                 :            :                                         const char *oid, size_t oid_len,
+      70                 :            :                                         int critical,
+      71                 :            :                                         const unsigned char *val, size_t val_len)
+      72                 :            : {
+      73                 :         38 :     return mbedtls_x509_set_extension(&ctx->extensions, oid, oid_len,
+      74                 :            :                                       critical, val, val_len);
+      75                 :            : }
+      76                 :            : 
+      77                 :          0 : int mbedtls_x509write_csr_set_subject_alternative_name(mbedtls_x509write_csr *ctx,
+      78                 :            :                                                        const mbedtls_x509_san_list *san_list)
+      79                 :            : {
+      80                 :          0 :     return mbedtls_x509_write_set_san_common(&ctx->extensions, san_list);
+      81                 :            : }
+      82                 :            : 
+      83                 :          0 : int mbedtls_x509write_csr_set_key_usage(mbedtls_x509write_csr *ctx, unsigned char key_usage)
+      84                 :            : {
+      85                 :          0 :     unsigned char buf[4] = { 0 };
+      86                 :            :     unsigned char *c;
+      87                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+      88                 :            : 
+      89                 :          0 :     c = buf + 4;
+      90                 :            : 
+      91                 :          0 :     ret = mbedtls_asn1_write_named_bitstring(&c, buf, &key_usage, 8);
+      92   [ #  #  #  # ]:          0 :     if (ret < 3 || ret > 4) {
+      93                 :          0 :         return ret;
+      94                 :            :     }
+      95                 :            : 
+      96                 :          0 :     ret = mbedtls_x509write_csr_set_extension(ctx, MBEDTLS_OID_KEY_USAGE,
+      97                 :            :                                               MBEDTLS_OID_SIZE(MBEDTLS_OID_KEY_USAGE),
+      98                 :            :                                               0, c, (size_t) ret);
+      99         [ #  # ]:          0 :     if (ret != 0) {
+     100                 :          0 :         return ret;
+     101                 :            :     }
+     102                 :            : 
+     103                 :          0 :     return 0;
+     104                 :            : }
+     105                 :            : 
+     106                 :          0 : int mbedtls_x509write_csr_set_ns_cert_type(mbedtls_x509write_csr *ctx,
+     107                 :            :                                            unsigned char ns_cert_type)
+     108                 :            : {
+     109                 :          0 :     unsigned char buf[4] = { 0 };
+     110                 :            :     unsigned char *c;
+     111                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     112                 :            : 
+     113                 :          0 :     c = buf + 4;
+     114                 :            : 
+     115                 :          0 :     ret = mbedtls_asn1_write_named_bitstring(&c, buf, &ns_cert_type, 8);
+     116   [ #  #  #  # ]:          0 :     if (ret < 3 || ret > 4) {
+     117                 :          0 :         return ret;
+     118                 :            :     }
+     119                 :            : 
+     120                 :          0 :     ret = mbedtls_x509write_csr_set_extension(ctx, MBEDTLS_OID_NS_CERT_TYPE,
+     121                 :            :                                               MBEDTLS_OID_SIZE(MBEDTLS_OID_NS_CERT_TYPE),
+     122                 :            :                                               0, c, (size_t) ret);
+     123         [ #  # ]:          0 :     if (ret != 0) {
+     124                 :          0 :         return ret;
+     125                 :            :     }
+     126                 :            : 
+     127                 :          0 :     return 0;
+     128                 :            : }
+     129                 :            : 
+     130                 :          6 : static int x509write_csr_der_internal(mbedtls_x509write_csr *ctx,
+     131                 :            :                                       unsigned char *buf,
+     132                 :            :                                       size_t size,
+     133                 :            :                                       unsigned char *sig, size_t sig_size,
+     134                 :            :                                       int (*f_rng)(void *, unsigned char *, size_t),
+     135                 :            :                                       void *p_rng)
+     136                 :            : {
+     137                 :          6 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     138                 :            :     const char *sig_oid;
+     139                 :          6 :     size_t sig_oid_len = 0;
+     140                 :            :     unsigned char *c, *c2;
+     141                 :            :     unsigned char hash[MBEDTLS_MD_MAX_SIZE];
+     142                 :          6 :     size_t pub_len = 0, sig_and_oid_len = 0, sig_len;
+     143                 :          6 :     size_t len = 0;
+     144                 :            :     mbedtls_pk_type_t pk_alg;
+     145                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+     146                 :            :     size_t hash_len;
+     147                 :            :     psa_algorithm_t hash_alg = mbedtls_md_psa_alg_from_type(ctx->md_alg);
+     148                 :            : #endif /* MBEDTLS_USE_PSA_CRYPTO */
+     149                 :            : 
+     150                 :            :     /* Write the CSR backwards starting from the end of buf */
+     151                 :          6 :     c = buf + size;
+     152                 :            : 
+     153         [ -  + ]:          6 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_x509_write_extensions(&c, buf,
+     154                 :            :                                                             ctx->extensions));
+     155                 :            : 
+     156         [ +  - ]:          6 :     if (len) {
+     157         [ -  + ]:          6 :         MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(&c, buf, len));
+     158         [ -  + ]:          6 :         MBEDTLS_ASN1_CHK_ADD(len,
+     159                 :            :                              mbedtls_asn1_write_tag(
+     160                 :            :                                  &c, buf,
+     161                 :            :                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE));
+     162                 :            : 
+     163         [ -  + ]:          6 :         MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(&c, buf, len));
+     164         [ -  + ]:          6 :         MBEDTLS_ASN1_CHK_ADD(len,
+     165                 :            :                              mbedtls_asn1_write_tag(
+     166                 :            :                                  &c, buf,
+     167                 :            :                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SET));
+     168                 :            : 
+     169         [ -  + ]:          6 :         MBEDTLS_ASN1_CHK_ADD(len,
+     170                 :            :                              mbedtls_asn1_write_oid(
+     171                 :            :                                  &c, buf, MBEDTLS_OID_PKCS9_CSR_EXT_REQ,
+     172                 :            :                                  MBEDTLS_OID_SIZE(MBEDTLS_OID_PKCS9_CSR_EXT_REQ)));
+     173                 :            : 
+     174         [ -  + ]:          6 :         MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(&c, buf, len));
+     175         [ -  + ]:          6 :         MBEDTLS_ASN1_CHK_ADD(len,
+     176                 :            :                              mbedtls_asn1_write_tag(
+     177                 :            :                                  &c, buf,
+     178                 :            :                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE));
+     179                 :            :     }
+     180                 :            : 
+     181         [ -  + ]:          6 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(&c, buf, len));
+     182         [ -  + ]:          6 :     MBEDTLS_ASN1_CHK_ADD(len,
+     183                 :            :                          mbedtls_asn1_write_tag(
+     184                 :            :                              &c, buf,
+     185                 :            :                              MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_CONTEXT_SPECIFIC));
+     186                 :            : 
+     187         [ -  + ]:          6 :     MBEDTLS_ASN1_CHK_ADD(pub_len, mbedtls_pk_write_pubkey_der(ctx->key,
+     188                 :            :                                                               buf, (size_t) (c - buf)));
+     189                 :          6 :     c -= pub_len;
+     190                 :          6 :     len += pub_len;
+     191                 :            : 
+     192                 :            :     /*
+     193                 :            :      *  Subject  ::=  Name
+     194                 :            :      */
+     195         [ -  + ]:          6 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_x509_write_names(&c, buf,
+     196                 :            :                                                        ctx->subject));
+     197                 :            : 
+     198                 :            :     /*
+     199                 :            :      *  Version  ::=  INTEGER  {  v1(0), v2(1), v3(2)  }
+     200                 :            :      */
+     201         [ -  + ]:          6 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_int(&c, buf, 0));
+     202                 :            : 
+     203         [ -  + ]:          6 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(&c, buf, len));
+     204         [ -  + ]:          6 :     MBEDTLS_ASN1_CHK_ADD(len,
+     205                 :            :                          mbedtls_asn1_write_tag(
+     206                 :            :                              &c, buf,
+     207                 :            :                              MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE));
+     208                 :            : 
+     209                 :            :     /*
+     210                 :            :      * Sign the written CSR data into the sig buffer
+     211                 :            :      * Note: hash errors can happen only after an internal error
+     212                 :            :      */
+     213                 :            : #if defined(MBEDTLS_USE_PSA_CRYPTO)
+     214                 :            :     if (psa_hash_compute(hash_alg,
+     215                 :            :                          c,
+     216                 :            :                          len,
+     217                 :            :                          hash,
+     218                 :            :                          sizeof(hash),
+     219                 :            :                          &hash_len) != PSA_SUCCESS) {
+     220                 :            :         return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
+     221                 :            :     }
+     222                 :            : #else /* MBEDTLS_USE_PSA_CRYPTO */
+     223                 :          6 :     ret = mbedtls_md(mbedtls_md_info_from_type(ctx->md_alg), c, len, hash);
+     224         [ -  + ]:          6 :     if (ret != 0) {
+     225                 :          0 :         return ret;
+     226                 :            :     }
+     227                 :            : #endif
+     228         [ -  + ]:          6 :     if ((ret = mbedtls_pk_sign(ctx->key, ctx->md_alg, hash, 0,
+     229                 :            :                                sig, sig_size, &sig_len,
+     230                 :            :                                f_rng, p_rng)) != 0) {
+     231                 :          0 :         return ret;
+     232                 :            :     }
+     233                 :            : 
+     234         [ -  + ]:          6 :     if (mbedtls_pk_can_do(ctx->key, MBEDTLS_PK_RSA)) {
+     235                 :          0 :         pk_alg = MBEDTLS_PK_RSA;
+     236         [ +  - ]:          6 :     } else if (mbedtls_pk_can_do(ctx->key, MBEDTLS_PK_ECDSA)) {
+     237                 :          6 :         pk_alg = MBEDTLS_PK_ECDSA;
+     238                 :            :     } else {
+     239                 :          0 :         return MBEDTLS_ERR_X509_INVALID_ALG;
+     240                 :            :     }
+     241                 :            : 
+     242         [ -  + ]:          6 :     if ((ret = mbedtls_oid_get_oid_by_sig_alg(pk_alg, ctx->md_alg,
+     243                 :            :                                               &sig_oid, &sig_oid_len)) != 0) {
+     244                 :          0 :         return ret;
+     245                 :            :     }
+     246                 :            : 
+     247                 :            :     /*
+     248                 :            :      * Move the written CSR data to the start of buf to create space for
+     249                 :            :      * writing the signature into buf.
+     250                 :            :      */
+     251                 :          6 :     memmove(buf, c, len);
+     252                 :            : 
+     253                 :            :     /*
+     254                 :            :      * Write sig and its OID into buf backwards from the end of buf.
+     255                 :            :      * Note: mbedtls_x509_write_sig will check for c2 - ( buf + len ) < sig_len
+     256                 :            :      * and return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL if needed.
+     257                 :            :      */
+     258                 :          6 :     c2 = buf + size;
+     259         [ -  + ]:          6 :     MBEDTLS_ASN1_CHK_ADD(sig_and_oid_len,
+     260                 :            :                          mbedtls_x509_write_sig(&c2, buf + len, sig_oid, sig_oid_len,
+     261                 :            :                                                 sig, sig_len, pk_alg));
+     262                 :            : 
+     263                 :            :     /*
+     264                 :            :      * Compact the space between the CSR data and signature by moving the
+     265                 :            :      * CSR data to the start of the signature.
+     266                 :            :      */
+     267                 :          6 :     c2 -= len;
+     268                 :          6 :     memmove(c2, buf, len);
+     269                 :            : 
+     270                 :            :     /* ASN encode the total size and tag the CSR data with it. */
+     271                 :          6 :     len += sig_and_oid_len;
+     272         [ -  + ]:          6 :     MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(&c2, buf, len));
+     273         [ -  + ]:          6 :     MBEDTLS_ASN1_CHK_ADD(len,
+     274                 :            :                          mbedtls_asn1_write_tag(
+     275                 :            :                              &c2, buf,
+     276                 :            :                              MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE));
+     277                 :            : 
+     278                 :            :     /* Zero the unused bytes at the start of buf */
+     279                 :          6 :     memset(buf, 0, (size_t) (c2 - buf));
+     280                 :            : 
+     281                 :          6 :     return (int) len;
+     282                 :            : }
+     283                 :            : 
+     284                 :          6 : int mbedtls_x509write_csr_der(mbedtls_x509write_csr *ctx, unsigned char *buf,
+     285                 :            :                               size_t size,
+     286                 :            :                               int (*f_rng)(void *, unsigned char *, size_t),
+     287                 :            :                               void *p_rng)
+     288                 :            : {
+     289                 :            :     int ret;
+     290                 :            :     unsigned char *sig;
+     291                 :            : 
+     292         [ -  + ]:          6 :     if ((sig = mbedtls_calloc(1, MBEDTLS_PK_SIGNATURE_MAX_SIZE)) == NULL) {
+     293                 :          0 :         return MBEDTLS_ERR_X509_ALLOC_FAILED;
+     294                 :            :     }
+     295                 :            : 
+     296                 :          6 :     ret = x509write_csr_der_internal(ctx, buf, size,
+     297                 :            :                                      sig, MBEDTLS_PK_SIGNATURE_MAX_SIZE,
+     298                 :            :                                      f_rng, p_rng);
+     299                 :            : 
+     300                 :          6 :     mbedtls_free(sig);
+     301                 :            : 
+     302                 :          6 :     return ret;
+     303                 :            : }
+     304                 :            : 
+     305                 :            : #define PEM_BEGIN_CSR           "-----BEGIN CERTIFICATE REQUEST-----\n"
+     306                 :            : #define PEM_END_CSR             "-----END CERTIFICATE REQUEST-----\n"
+     307                 :            : 
+     308                 :            : #if defined(MBEDTLS_PEM_WRITE_C)
+     309                 :          0 : int mbedtls_x509write_csr_pem(mbedtls_x509write_csr *ctx, unsigned char *buf, size_t size,
+     310                 :            :                               int (*f_rng)(void *, unsigned char *, size_t),
+     311                 :            :                               void *p_rng)
+     312                 :            : {
+     313                 :          0 :     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+     314                 :          0 :     size_t olen = 0;
+     315                 :            : 
+     316         [ #  # ]:          0 :     if ((ret = mbedtls_x509write_csr_der(ctx, buf, size,
+     317                 :            :                                          f_rng, p_rng)) < 0) {
+     318                 :          0 :         return ret;
+     319                 :            :     }
+     320                 :            : 
+     321         [ #  # ]:          0 :     if ((ret = mbedtls_pem_write_buffer(PEM_BEGIN_CSR, PEM_END_CSR,
+     322                 :          0 :                                         buf + size - ret,
+     323                 :            :                                         ret, buf, size, &olen)) != 0) {
+     324                 :          0 :         return ret;
+     325                 :            :     }
+     326                 :            : 
+     327                 :          0 :     return 0;
+     328                 :            : }
+     329                 :            : #endif /* MBEDTLS_PEM_WRITE_C */
+     330                 :            : 
+     331                 :            : #endif /* MBEDTLS_X509_CSR_WRITE_C */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/memlib/compare_mem.c.func-sort-c.html b/coverage_log/os_stub/memlib/compare_mem.c.func-sort-c.html new file mode 100644 index 00000000000..c85271d018d --- /dev/null +++ b/coverage_log/os_stub/memlib/compare_mem.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - os_stub/memlib/compare_mem.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/memlib - compare_mem.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:77100.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:22100.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_consttime_is_mem_equal13780
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/memlib/compare_mem.c.func.html b/coverage_log/os_stub/memlib/compare_mem.c.func.html new file mode 100644 index 00000000000..b3ddbaa70de --- /dev/null +++ b/coverage_log/os_stub/memlib/compare_mem.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - os_stub/memlib/compare_mem.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/memlib - compare_mem.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:77100.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:22100.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_consttime_is_mem_equal13780
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/memlib/compare_mem.c.gcov.html b/coverage_log/os_stub/memlib/compare_mem.c.gcov.html new file mode 100644 index 00000000000..1f1b156147f --- /dev/null +++ b/coverage_log/os_stub/memlib/compare_mem.c.gcov.html @@ -0,0 +1,109 @@ + + + + + + + LCOV - coverage.info - os_stub/memlib/compare_mem.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/memlib - compare_mem.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:77100.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:22100.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 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 "base.h"
+       8                 :            : 
+       9                 :      13780 : bool libspdm_consttime_is_mem_equal(const void *destination_buffer,
+      10                 :            :                                     const void *source_buffer, size_t length)
+      11                 :            : {
+      12                 :            :     const volatile uint8_t *pointer_dst;
+      13                 :            :     const volatile uint8_t *pointer_src;
+      14                 :            :     uint8_t delta;
+      15                 :            : 
+      16                 :      13780 :     pointer_dst = (const uint8_t *)destination_buffer;
+      17                 :      13780 :     pointer_src = (const uint8_t *)source_buffer;
+      18                 :      13780 :     delta = 0;
+      19         [ +  + ]:     156719 :     while ((length-- != 0)) {
+      20                 :     142939 :         delta |= *(pointer_dst++) ^ *(pointer_src++);
+      21                 :            :     }
+      22                 :            : 
+      23                 :      13780 :     return ((delta == 0) ? true : false);
+      24                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/memlib/copy_mem.c.func-sort-c.html b/coverage_log/os_stub/memlib/copy_mem.c.func-sort-c.html new file mode 100644 index 00000000000..d2ae103fae9 --- /dev/null +++ b/coverage_log/os_stub/memlib/copy_mem.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - os_stub/memlib/copy_mem.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/memlib - copy_mem.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:91275.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:111668.8 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_copy_mem46854
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/memlib/copy_mem.c.func.html b/coverage_log/os_stub/memlib/copy_mem.c.func.html new file mode 100644 index 00000000000..bdba5a7814f --- /dev/null +++ b/coverage_log/os_stub/memlib/copy_mem.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - os_stub/memlib/copy_mem.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/memlib - copy_mem.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:91275.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:111668.8 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_copy_mem46854
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/memlib/copy_mem.c.gcov.html b/coverage_log/os_stub/memlib/copy_mem.c.gcov.html new file mode 100644 index 00000000000..f2118659f1e --- /dev/null +++ b/coverage_log/os_stub/memlib/copy_mem.c.gcov.html @@ -0,0 +1,118 @@ + + + + + + + LCOV - coverage.info - os_stub/memlib/copy_mem.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/memlib - copy_mem.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:91275.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:111668.8 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 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 "library/debuglib.h"
+       8                 :            : #include "hal/library/memlib.h"
+       9                 :            : 
+      10                 :      46854 : void libspdm_copy_mem(void *dst_buf, size_t dst_len,
+      11                 :            :                       const void *src_buf, size_t src_len)
+      12                 :            : {
+      13                 :            :     volatile uint8_t* dst;
+      14                 :            :     const volatile uint8_t* src;
+      15                 :            : 
+      16                 :      46854 :     dst = (volatile uint8_t*) dst_buf;
+      17                 :      46854 :     src = (const volatile uint8_t*) src_buf;
+      18                 :            : 
+      19   [ +  -  -  + ]:      46854 :     if ((dst == NULL) || (src == NULL)) {
+      20                 :          0 :         LIBSPDM_ASSERT(0);
+      21                 :            :     }
+      22   [ +  +  +  -  :      46854 :     if (((src < dst) && ((src + src_len) > dst)) || ((dst < src) && ((dst + src_len) > src))) {
+             +  +  -  + ]
+      23                 :          0 :         LIBSPDM_ASSERT(0);
+      24                 :            :     }
+      25         [ -  + ]:      46854 :     if (src_len > dst_len) {
+      26                 :          0 :         LIBSPDM_ASSERT(0);
+      27                 :            :     }
+      28                 :            : 
+      29         [ +  + ]:    2116410 :     while (src_len-- != 0) {
+      30                 :    2069556 :         *(dst++) = *(src++);
+      31                 :            :     }
+      32                 :      46854 : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/memlib/index-sort-b.html b/coverage_log/os_stub/memlib/index-sort-b.html new file mode 100644 index 00000000000..cd176682317 --- /dev/null +++ b/coverage_log/os_stub/memlib/index-sort-b.html @@ -0,0 +1,143 @@ + + + + + + + LCOV - coverage.info - os_stub/memlib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/memlibHitTotalCoverage
Test:coverage.infoLines:273090.0 %
Date:2024-09-22 08:21:07Functions:44100.0 %
Branches:172277.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
copy_mem.c +
75.0%75.0%
+
75.0 %9 / 12100.0 %1 / 168.8 %11 / 16
set_mem.c +
100.0%
+
100.0 %5 / 5100.0 %1 / 1100.0 %2 / 2
zero_mem.c +
100.0%
+
100.0 %6 / 6100.0 %1 / 1100.0 %2 / 2
compare_mem.c +
100.0%
+
100.0 %7 / 7100.0 %1 / 1100.0 %2 / 2
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/memlib/index-sort-f.html b/coverage_log/os_stub/memlib/index-sort-f.html new file mode 100644 index 00000000000..4a77a28ad54 --- /dev/null +++ b/coverage_log/os_stub/memlib/index-sort-f.html @@ -0,0 +1,143 @@ + + + + + + + LCOV - coverage.info - os_stub/memlib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/memlibHitTotalCoverage
Test:coverage.infoLines:273090.0 %
Date:2024-09-22 08:21:07Functions:44100.0 %
Branches:172277.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
set_mem.c +
100.0%
+
100.0 %5 / 5100.0 %1 / 1100.0 %2 / 2
copy_mem.c +
75.0%75.0%
+
75.0 %9 / 12100.0 %1 / 168.8 %11 / 16
zero_mem.c +
100.0%
+
100.0 %6 / 6100.0 %1 / 1100.0 %2 / 2
compare_mem.c +
100.0%
+
100.0 %7 / 7100.0 %1 / 1100.0 %2 / 2
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/memlib/index-sort-l.html b/coverage_log/os_stub/memlib/index-sort-l.html new file mode 100644 index 00000000000..e6939cddd71 --- /dev/null +++ b/coverage_log/os_stub/memlib/index-sort-l.html @@ -0,0 +1,143 @@ + + + + + + + LCOV - coverage.info - os_stub/memlib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/memlibHitTotalCoverage
Test:coverage.infoLines:273090.0 %
Date:2024-09-22 08:21:07Functions:44100.0 %
Branches:172277.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
copy_mem.c +
75.0%75.0%
+
75.0 %9 / 12100.0 %1 / 168.8 %11 / 16
set_mem.c +
100.0%
+
100.0 %5 / 5100.0 %1 / 1100.0 %2 / 2
zero_mem.c +
100.0%
+
100.0 %6 / 6100.0 %1 / 1100.0 %2 / 2
compare_mem.c +
100.0%
+
100.0 %7 / 7100.0 %1 / 1100.0 %2 / 2
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/memlib/index.html b/coverage_log/os_stub/memlib/index.html new file mode 100644 index 00000000000..a294ce16bc2 --- /dev/null +++ b/coverage_log/os_stub/memlib/index.html @@ -0,0 +1,143 @@ + + + + + + + LCOV - coverage.info - os_stub/memlib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/memlibHitTotalCoverage
Test:coverage.infoLines:273090.0 %
Date:2024-09-22 08:21:07Functions:44100.0 %
Branches:172277.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
compare_mem.c +
100.0%
+
100.0 %7 / 7100.0 %1 / 1100.0 %2 / 2
copy_mem.c +
75.0%75.0%
+
75.0 %9 / 12100.0 %1 / 168.8 %11 / 16
set_mem.c +
100.0%
+
100.0 %5 / 5100.0 %1 / 1100.0 %2 / 2
zero_mem.c +
100.0%
+
100.0 %6 / 6100.0 %1 / 1100.0 %2 / 2
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/memlib/set_mem.c.func-sort-c.html b/coverage_log/os_stub/memlib/set_mem.c.func-sort-c.html new file mode 100644 index 00000000000..b947a7cf74e --- /dev/null +++ b/coverage_log/os_stub/memlib/set_mem.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - os_stub/memlib/set_mem.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/memlib - set_mem.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:55100.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:22100.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_set_mem1620
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/memlib/set_mem.c.func.html b/coverage_log/os_stub/memlib/set_mem.c.func.html new file mode 100644 index 00000000000..41e396c26c0 --- /dev/null +++ b/coverage_log/os_stub/memlib/set_mem.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - os_stub/memlib/set_mem.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/memlib - set_mem.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:55100.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:22100.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_set_mem1620
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/memlib/set_mem.c.gcov.html b/coverage_log/os_stub/memlib/set_mem.c.gcov.html new file mode 100644 index 00000000000..1f5dae11d12 --- /dev/null +++ b/coverage_log/os_stub/memlib/set_mem.c.gcov.html @@ -0,0 +1,102 @@ + + + + + + + LCOV - coverage.info - os_stub/memlib/set_mem.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/memlib - set_mem.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:55100.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:22100.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 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 "hal/library/memlib.h"
+       8                 :            : 
+       9                 :       1620 : void libspdm_set_mem(void *buffer, size_t length, uint8_t value)
+      10                 :            : {
+      11                 :            :     volatile uint8_t *pointer;
+      12                 :            : 
+      13                 :       1620 :     pointer = (uint8_t *)buffer;
+      14         [ +  + ]:     366400 :     while (length-- != 0) {
+      15                 :     364780 :         *(pointer++) = value;
+      16                 :            :     }
+      17                 :       1620 : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/memlib/zero_mem.c.func-sort-c.html b/coverage_log/os_stub/memlib/zero_mem.c.func-sort-c.html new file mode 100644 index 00000000000..883d3f1b5b0 --- /dev/null +++ b/coverage_log/os_stub/memlib/zero_mem.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - os_stub/memlib/zero_mem.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/memlib - zero_mem.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:66100.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:22100.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_zero_mem2683184
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/memlib/zero_mem.c.func.html b/coverage_log/os_stub/memlib/zero_mem.c.func.html new file mode 100644 index 00000000000..89c2499af6a --- /dev/null +++ b/coverage_log/os_stub/memlib/zero_mem.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - os_stub/memlib/zero_mem.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/memlib - zero_mem.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:66100.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:22100.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_zero_mem2683184
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/memlib/zero_mem.c.gcov.html b/coverage_log/os_stub/memlib/zero_mem.c.gcov.html new file mode 100644 index 00000000000..f62124b33a7 --- /dev/null +++ b/coverage_log/os_stub/memlib/zero_mem.c.gcov.html @@ -0,0 +1,125 @@ + + + + + + + LCOV - coverage.info - os_stub/memlib/zero_mem.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/memlib - zero_mem.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:66100.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:22100.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 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 "hal/library/memlib.h"
+       8                 :            : 
+       9                 :            : #ifdef _WIN32
+      10                 :            : #include <windows.h>
+      11                 :            : #elif defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+      12                 :            : #include <strings.h>
+      13                 :            : #include <string.h>
+      14                 :            : #endif
+      15                 :            : 
+      16                 :    2683184 : void libspdm_zero_mem(void *buffer, size_t length)
+      17                 :            : {
+      18                 :            : 
+      19                 :            : #if defined(__STDC_LIB_EXT1__)
+      20                 :            :     memset_s(buffer, length, 0, length);
+      21                 :            : #elif defined(_WIN32)
+      22                 :            :     SecureZeroMemory(buffer, length);
+      23                 :            : #elif defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+      24                 :            :     explicit_bzero(buffer, length);
+      25                 :            : #else
+      26                 :            :     volatile uint8_t *pointer;
+      27                 :            : 
+      28                 :    2683184 :     pointer = (uint8_t *)buffer;
+      29         [ +  + ]:  165476063 :     while (length-- != 0) {
+      30                 :  162792879 :         *(pointer++) = 0;
+      31                 :            :     }
+      32                 :            : 
+      33                 :            : #if defined(_MSC_VER) && (_MSC_VER > 1200) && !defined(__clang__)
+      34                 :            :     _ReadWriteBarrier();
+      35                 :            : #elif defined(__GNUC__)
+      36                 :    2683184 :     __asm__ __volatile__ ("" : : : "memory");
+      37                 :            : #endif
+      38                 :            : 
+      39                 :            : #endif
+      40                 :    2683184 : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/platform_lib/index-sort-b.html b/coverage_log/os_stub/platform_lib/index-sort-b.html new file mode 100644 index 00000000000..f2df709f628 --- /dev/null +++ b/coverage_log/os_stub/platform_lib/index-sort-b.html @@ -0,0 +1,119 @@ + + + + + + + LCOV - coverage.info - os_stub/platform_lib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/platform_libHitTotalCoverage
Test:coverage.infoLines:61250.0 %
Date:2024-09-22 08:21:07Functions:1425.0 %
Branches:1425.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
time_linux.c +
100.0%
+
100.0 %6 / 6100.0 %1 / 125.0 %1 / 4
watchdog.c +
0.0%
+
0.0 %0 / 60.0 %0 / 3-0 / 0
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/platform_lib/index-sort-f.html b/coverage_log/os_stub/platform_lib/index-sort-f.html new file mode 100644 index 00000000000..ff90ee32d7b --- /dev/null +++ b/coverage_log/os_stub/platform_lib/index-sort-f.html @@ -0,0 +1,119 @@ + + + + + + + LCOV - coverage.info - os_stub/platform_lib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/platform_libHitTotalCoverage
Test:coverage.infoLines:61250.0 %
Date:2024-09-22 08:21:07Functions:1425.0 %
Branches:1425.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
watchdog.c +
0.0%
+
0.0 %0 / 60.0 %0 / 3-0 / 0
time_linux.c +
100.0%
+
100.0 %6 / 6100.0 %1 / 125.0 %1 / 4
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/platform_lib/index-sort-l.html b/coverage_log/os_stub/platform_lib/index-sort-l.html new file mode 100644 index 00000000000..72966e1edbe --- /dev/null +++ b/coverage_log/os_stub/platform_lib/index-sort-l.html @@ -0,0 +1,119 @@ + + + + + + + LCOV - coverage.info - os_stub/platform_lib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/platform_libHitTotalCoverage
Test:coverage.infoLines:61250.0 %
Date:2024-09-22 08:21:07Functions:1425.0 %
Branches:1425.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
watchdog.c +
0.0%
+
0.0 %0 / 60.0 %0 / 3-0 / 0
time_linux.c +
100.0%
+
100.0 %6 / 6100.0 %1 / 125.0 %1 / 4
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/platform_lib/index.html b/coverage_log/os_stub/platform_lib/index.html new file mode 100644 index 00000000000..3062a34bc0f --- /dev/null +++ b/coverage_log/os_stub/platform_lib/index.html @@ -0,0 +1,119 @@ + + + + + + + LCOV - coverage.info - os_stub/platform_lib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/platform_libHitTotalCoverage
Test:coverage.infoLines:61250.0 %
Date:2024-09-22 08:21:07Functions:1425.0 %
Branches:1425.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
time_linux.c +
100.0%
+
100.0 %6 / 6100.0 %1 / 125.0 %1 / 4
watchdog.c +
0.0%
+
0.0 %0 / 60.0 %0 / 3-0 / 0
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/platform_lib/time_linux.c.func-sort-c.html b/coverage_log/os_stub/platform_lib/time_linux.c.func-sort-c.html new file mode 100644 index 00000000000..d033e54a3dc --- /dev/null +++ b/coverage_log/os_stub/platform_lib/time_linux.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - os_stub/platform_lib/time_linux.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/platform_lib - time_linux.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:66100.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:1425.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_sleep66
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/platform_lib/time_linux.c.func.html b/coverage_log/os_stub/platform_lib/time_linux.c.func.html new file mode 100644 index 00000000000..95dfd752d15 --- /dev/null +++ b/coverage_log/os_stub/platform_lib/time_linux.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - os_stub/platform_lib/time_linux.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/platform_lib - time_linux.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:66100.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:1425.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_sleep66
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/platform_lib/time_linux.c.gcov.html b/coverage_log/os_stub/platform_lib/time_linux.c.gcov.html new file mode 100644 index 00000000000..c93c2dcafd9 --- /dev/null +++ b/coverage_log/os_stub/platform_lib/time_linux.c.gcov.html @@ -0,0 +1,114 @@ + + + + + + + LCOV - coverage.info - os_stub/platform_lib/time_linux.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/platform_lib - time_linux.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:66100.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:1425.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  * Copyright Notice:
+       3                 :            :  * Copyright 2022 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 <base.h>
+       8                 :            : #include <stdlib.h>
+       9                 :            : #include <sys/time.h>
+      10                 :            : #include <errno.h>
+      11                 :            : 
+      12                 :            : /**
+      13                 :            :  * Suspends the execution of the current thread until the time-out interval elapses.
+      14                 :            :  *
+      15                 :            :  * @param microseconds     The time interval for which execution is to be suspended, in microseconds.
+      16                 :            :  *
+      17                 :            :  **/
+      18                 :         66 : void libspdm_sleep(uint64_t microseconds)
+      19                 :            : {
+      20                 :            :     struct timeval tv;
+      21                 :            :     int err;
+      22                 :            : 
+      23                 :         66 :     tv.tv_sec = microseconds / 1000000;
+      24                 :         66 :     tv.tv_usec = (microseconds % 1000000);
+      25                 :            : 
+      26                 :            :     do {
+      27                 :         66 :         err=select(0, NULL, NULL, NULL, &tv);
+      28   [ -  +  -  - ]:         66 :     } while(err<0 && errno==EINTR);
+      29                 :         66 : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/platform_lib/watchdog.c.func-sort-c.html b/coverage_log/os_stub/platform_lib/watchdog.c.func-sort-c.html new file mode 100644 index 00000000000..751666d987b --- /dev/null +++ b/coverage_log/os_stub/platform_lib/watchdog.c.func-sort-c.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - os_stub/platform_lib/watchdog.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/platform_lib - watchdog.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:060.0 %
Date:2024-09-22 08:21:07Functions:030.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_reset_watchdog0
libspdm_start_watchdog0
libspdm_stop_watchdog0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/platform_lib/watchdog.c.func.html b/coverage_log/os_stub/platform_lib/watchdog.c.func.html new file mode 100644 index 00000000000..1efbc972903 --- /dev/null +++ b/coverage_log/os_stub/platform_lib/watchdog.c.func.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - os_stub/platform_lib/watchdog.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/platform_lib - watchdog.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:060.0 %
Date:2024-09-22 08:21:07Functions:030.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_reset_watchdog0
libspdm_start_watchdog0
libspdm_stop_watchdog0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/platform_lib/watchdog.c.gcov.html b/coverage_log/os_stub/platform_lib/watchdog.c.gcov.html new file mode 100644 index 00000000000..63593036106 --- /dev/null +++ b/coverage_log/os_stub/platform_lib/watchdog.c.gcov.html @@ -0,0 +1,130 @@ + + + + + + + LCOV - coverage.info - os_stub/platform_lib/watchdog.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/platform_lib - watchdog.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:060.0 %
Date:2024-09-22 08:21:07Functions:030.0 %
Branches:00-
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2022 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 "base.h"
+       8                 :            : #include "internal/libspdm_lib_config.h"
+       9                 :            : 
+      10                 :            : #if LIBSPDM_ENABLE_CAPABILITY_HBEAT_CAP
+      11                 :            : /**
+      12                 :            :  * If no heartbeat arrives in seconds, the watchdog timeout event
+      13                 :            :  * should terminate the session.
+      14                 :            :  *
+      15                 :            :  * @param  session_id     Indicate the SPDM session ID.
+      16                 :            :  * @param  seconds        heartbeat period, in seconds.
+      17                 :            :  *
+      18                 :            :  **/
+      19                 :          0 : bool libspdm_start_watchdog(uint32_t session_id, uint16_t seconds)
+      20                 :            : {
+      21                 :          0 :     return true;
+      22                 :            : }
+      23                 :            : 
+      24                 :            : /**
+      25                 :            :  * stop watchdog.
+      26                 :            :  *
+      27                 :            :  * @param  session_id     Indicate the SPDM session ID.
+      28                 :            :  *
+      29                 :            :  **/
+      30                 :          0 : bool libspdm_stop_watchdog(uint32_t session_id)
+      31                 :            : {
+      32                 :          0 :     return true;
+      33                 :            : }
+      34                 :            : 
+      35                 :            : /**
+      36                 :            :  * Reset the watchdog in heartbeat response.
+      37                 :            :  *
+      38                 :            :  * @param  session_id     Indicate the SPDM session ID.
+      39                 :            :  *
+      40                 :            :  **/
+      41                 :          0 : bool libspdm_reset_watchdog(uint32_t session_id)
+      42                 :            : {
+      43                 :          0 :     return true;
+      44                 :            : }
+      45                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_HBEAT_CAP */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/platform_lib_null/index-sort-b.html b/coverage_log/os_stub/platform_lib_null/index-sort-b.html new file mode 100644 index 00000000000..82586aa7e4f --- /dev/null +++ b/coverage_log/os_stub/platform_lib_null/index-sort-b.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/platform_lib_null + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/platform_lib_nullHitTotalCoverage
Test:coverage.infoLines:060.0 %
Date:2024-09-22 08:21:07Functions:030.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
watchdog.c +
0.0%
+
0.0 %0 / 60.0 %0 / 3-0 / 0
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/platform_lib_null/index-sort-f.html b/coverage_log/os_stub/platform_lib_null/index-sort-f.html new file mode 100644 index 00000000000..d18f463ca43 --- /dev/null +++ b/coverage_log/os_stub/platform_lib_null/index-sort-f.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/platform_lib_null + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/platform_lib_nullHitTotalCoverage
Test:coverage.infoLines:060.0 %
Date:2024-09-22 08:21:07Functions:030.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
watchdog.c +
0.0%
+
0.0 %0 / 60.0 %0 / 3-0 / 0
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/platform_lib_null/index-sort-l.html b/coverage_log/os_stub/platform_lib_null/index-sort-l.html new file mode 100644 index 00000000000..3ad4097bbe5 --- /dev/null +++ b/coverage_log/os_stub/platform_lib_null/index-sort-l.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/platform_lib_null + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/platform_lib_nullHitTotalCoverage
Test:coverage.infoLines:060.0 %
Date:2024-09-22 08:21:07Functions:030.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
watchdog.c +
0.0%
+
0.0 %0 / 60.0 %0 / 3-0 / 0
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/platform_lib_null/index.html b/coverage_log/os_stub/platform_lib_null/index.html new file mode 100644 index 00000000000..ffb80049e6b --- /dev/null +++ b/coverage_log/os_stub/platform_lib_null/index.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/platform_lib_null + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/platform_lib_nullHitTotalCoverage
Test:coverage.infoLines:060.0 %
Date:2024-09-22 08:21:07Functions:030.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
watchdog.c +
0.0%
+
0.0 %0 / 60.0 %0 / 3-0 / 0
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/platform_lib_null/watchdog.c.func-sort-c.html b/coverage_log/os_stub/platform_lib_null/watchdog.c.func-sort-c.html new file mode 100644 index 00000000000..b6560d72b49 --- /dev/null +++ b/coverage_log/os_stub/platform_lib_null/watchdog.c.func-sort-c.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - os_stub/platform_lib_null/watchdog.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/platform_lib_null - watchdog.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:060.0 %
Date:2024-09-22 08:21:07Functions:030.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_reset_watchdog0
libspdm_start_watchdog0
libspdm_stop_watchdog0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/platform_lib_null/watchdog.c.func.html b/coverage_log/os_stub/platform_lib_null/watchdog.c.func.html new file mode 100644 index 00000000000..83645d3b469 --- /dev/null +++ b/coverage_log/os_stub/platform_lib_null/watchdog.c.func.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - os_stub/platform_lib_null/watchdog.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/platform_lib_null - watchdog.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:060.0 %
Date:2024-09-22 08:21:07Functions:030.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_reset_watchdog0
libspdm_start_watchdog0
libspdm_stop_watchdog0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/platform_lib_null/watchdog.c.gcov.html b/coverage_log/os_stub/platform_lib_null/watchdog.c.gcov.html new file mode 100644 index 00000000000..a9a8f5d1ba9 --- /dev/null +++ b/coverage_log/os_stub/platform_lib_null/watchdog.c.gcov.html @@ -0,0 +1,130 @@ + + + + + + + LCOV - coverage.info - os_stub/platform_lib_null/watchdog.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/platform_lib_null - watchdog.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:060.0 %
Date:2024-09-22 08:21:07Functions:030.0 %
Branches:00-
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2022 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 "base.h"
+       8                 :            : #include "internal/libspdm_lib_config.h"
+       9                 :            : 
+      10                 :            : #if LIBSPDM_ENABLE_CAPABILITY_HBEAT_CAP
+      11                 :            : /**
+      12                 :            :  * If no heartbeat arrives in seconds, the watchdog timeout event
+      13                 :            :  * should terminate the session.
+      14                 :            :  *
+      15                 :            :  * @param  session_id     Indicate the SPDM session ID.
+      16                 :            :  * @param  seconds        heartbeat period, in seconds.
+      17                 :            :  *
+      18                 :            :  **/
+      19                 :          0 : bool libspdm_start_watchdog(uint32_t session_id, uint16_t seconds)
+      20                 :            : {
+      21                 :          0 :     return true;
+      22                 :            : }
+      23                 :            : 
+      24                 :            : /**
+      25                 :            :  * stop watchdog.
+      26                 :            :  *
+      27                 :            :  * @param  session_id     Indicate the SPDM session ID.
+      28                 :            :  *
+      29                 :            :  **/
+      30                 :          0 : bool libspdm_stop_watchdog(uint32_t session_id)
+      31                 :            : {
+      32                 :          0 :     return true;
+      33                 :            : }
+      34                 :            : 
+      35                 :            : /**
+      36                 :            :  * Reset the watchdog in heartbeat response.
+      37                 :            :  *
+      38                 :            :  * @param  session_id     Indicate the SPDM session ID.
+      39                 :            :  *
+      40                 :            :  **/
+      41                 :          0 : bool libspdm_reset_watchdog(uint32_t session_id)
+      42                 :            : {
+      43                 :          0 :     return true;
+      44                 :            : }
+      45                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_HBEAT_CAP */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/rnglib/index-sort-b.html b/coverage_log/os_stub/rnglib/index-sort-b.html new file mode 100644 index 00000000000..7c6927e9671 --- /dev/null +++ b/coverage_log/os_stub/rnglib/index-sort-b.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/rnglib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/rnglibHitTotalCoverage
Test:coverage.infoLines:71258.3 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:3650.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
rng_linux.c +
58.3%58.3%
+
58.3 %7 / 12100.0 %1 / 150.0 %3 / 6
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/rnglib/index-sort-f.html b/coverage_log/os_stub/rnglib/index-sort-f.html new file mode 100644 index 00000000000..0251ccc6872 --- /dev/null +++ b/coverage_log/os_stub/rnglib/index-sort-f.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/rnglib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/rnglibHitTotalCoverage
Test:coverage.infoLines:71258.3 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:3650.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
rng_linux.c +
58.3%58.3%
+
58.3 %7 / 12100.0 %1 / 150.0 %3 / 6
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/rnglib/index-sort-l.html b/coverage_log/os_stub/rnglib/index-sort-l.html new file mode 100644 index 00000000000..363199e3e0e --- /dev/null +++ b/coverage_log/os_stub/rnglib/index-sort-l.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/rnglib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/rnglibHitTotalCoverage
Test:coverage.infoLines:71258.3 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:3650.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
rng_linux.c +
58.3%58.3%
+
58.3 %7 / 12100.0 %1 / 150.0 %3 / 6
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/rnglib/index.html b/coverage_log/os_stub/rnglib/index.html new file mode 100644 index 00000000000..51942f26a7d --- /dev/null +++ b/coverage_log/os_stub/rnglib/index.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/rnglib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/rnglibHitTotalCoverage
Test:coverage.infoLines:71258.3 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:3650.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
rng_linux.c +
58.3%58.3%
+
58.3 %7 / 12100.0 %1 / 150.0 %3 / 6
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/rnglib/rng_linux.c.func-sort-c.html b/coverage_log/os_stub/rnglib/rng_linux.c.func-sort-c.html new file mode 100644 index 00000000000..aab28db552a --- /dev/null +++ b/coverage_log/os_stub/rnglib/rng_linux.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - os_stub/rnglib/rng_linux.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/rnglib - rng_linux.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:71258.3 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:3650.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_random_number_6412437
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/rnglib/rng_linux.c.func.html b/coverage_log/os_stub/rnglib/rng_linux.c.func.html new file mode 100644 index 00000000000..25d3de8e95d --- /dev/null +++ b/coverage_log/os_stub/rnglib/rng_linux.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - os_stub/rnglib/rng_linux.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/rnglib - rng_linux.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:71258.3 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:3650.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_random_number_6412437
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/rnglib/rng_linux.c.gcov.html b/coverage_log/os_stub/rnglib/rng_linux.c.gcov.html new file mode 100644 index 00000000000..e41d86b85e3 --- /dev/null +++ b/coverage_log/os_stub/rnglib/rng_linux.c.gcov.html @@ -0,0 +1,129 @@ + + + + + + + LCOV - coverage.info - os_stub/rnglib/rng_linux.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/rnglib - rng_linux.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:71258.3 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:3650.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 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 <base.h>
+       8                 :            : #include <stdlib.h>
+       9                 :            : #include "stdio.h"
+      10                 :            : #include <unistd.h>
+      11                 :            : #include <fcntl.h>
+      12                 :            : #include <assert.h>
+      13                 :            : 
+      14                 :            : /**
+      15                 :            :  * Generates a 64-bit random number.
+      16                 :            :  *
+      17                 :            :  * if rand is NULL, then LIBSPDM_ASSERT().
+      18                 :            :  *
+      19                 :            :  * @param[out] rand_data     buffer pointer to store the 64-bit random value.
+      20                 :            :  *
+      21                 :            :  * @retval true         Random number generated successfully.
+      22                 :            :  * @retval false        Failed to generate the random number.
+      23                 :            :  *
+      24                 :            :  **/
+      25                 :      12437 : bool libspdm_get_random_number_64(uint64_t *rand_data)
+      26                 :            : {
+      27                 :            :     int fd;
+      28                 :            : 
+      29         [ -  + ]:      12437 :     assert(rand_data != NULL);
+      30                 :            : 
+      31                 :      12437 :     fd = open("/dev/urandom", O_RDONLY);
+      32         [ -  + ]:      12437 :     if (fd < 0) {
+      33                 :          0 :         printf("cannot open /dev/urandom\n");
+      34                 :          0 :         return false;
+      35                 :            :     }
+      36         [ -  + ]:      12437 :     if (read(fd, rand_data, sizeof(*rand_data)) != sizeof(*rand_data)) {
+      37                 :          0 :         printf("Cannot read /dev/urandom\n");
+      38                 :          0 :         close(fd);
+      39                 :          0 :         return false;
+      40                 :            :     }
+      41                 :      12437 :     close(fd);
+      42                 :            : 
+      43                 :      12437 :     return true;
+      44                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/spdm_crypt_ext_lib/index-sort-b.html b/coverage_log/os_stub/spdm_crypt_ext_lib/index-sort-b.html new file mode 100644 index 00000000000..1e159690621 --- /dev/null +++ b/coverage_log/os_stub/spdm_crypt_ext_lib/index-sort-b.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/spdm_crypt_ext_lib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/spdm_crypt_ext_libHitTotalCoverage
Test:coverage.infoLines:288532.9 %
Date:2024-09-22 08:21:07Functions:77100.0 %
Branches:73221.9 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
spdm_crypt_ext.c +
32.9%32.9%
+
32.9 %28 / 85100.0 %7 / 721.9 %7 / 32
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/spdm_crypt_ext_lib/index-sort-f.html b/coverage_log/os_stub/spdm_crypt_ext_lib/index-sort-f.html new file mode 100644 index 00000000000..2fa921a554f --- /dev/null +++ b/coverage_log/os_stub/spdm_crypt_ext_lib/index-sort-f.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/spdm_crypt_ext_lib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/spdm_crypt_ext_libHitTotalCoverage
Test:coverage.infoLines:288532.9 %
Date:2024-09-22 08:21:07Functions:77100.0 %
Branches:73221.9 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
spdm_crypt_ext.c +
32.9%32.9%
+
32.9 %28 / 85100.0 %7 / 721.9 %7 / 32
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/spdm_crypt_ext_lib/index-sort-l.html b/coverage_log/os_stub/spdm_crypt_ext_lib/index-sort-l.html new file mode 100644 index 00000000000..0c7dbb237b1 --- /dev/null +++ b/coverage_log/os_stub/spdm_crypt_ext_lib/index-sort-l.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/spdm_crypt_ext_lib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/spdm_crypt_ext_libHitTotalCoverage
Test:coverage.infoLines:288532.9 %
Date:2024-09-22 08:21:07Functions:77100.0 %
Branches:73221.9 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
spdm_crypt_ext.c +
32.9%32.9%
+
32.9 %28 / 85100.0 %7 / 721.9 %7 / 32
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/spdm_crypt_ext_lib/index.html b/coverage_log/os_stub/spdm_crypt_ext_lib/index.html new file mode 100644 index 00000000000..294e679d265 --- /dev/null +++ b/coverage_log/os_stub/spdm_crypt_ext_lib/index.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - os_stub/spdm_crypt_ext_lib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/spdm_crypt_ext_libHitTotalCoverage
Test:coverage.infoLines:288532.9 %
Date:2024-09-22 08:21:07Functions:77100.0 %
Branches:73221.9 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
spdm_crypt_ext.c +
32.9%32.9%
+
32.9 %28 / 85100.0 %7 / 721.9 %7 / 32
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/spdm_crypt_ext_lib/spdm_crypt_ext.c.func-sort-c.html b/coverage_log/os_stub/spdm_crypt_ext_lib/spdm_crypt_ext.c.func-sort-c.html new file mode 100644 index 00000000000..55b5bf85e40 --- /dev/null +++ b/coverage_log/os_stub/spdm_crypt_ext_lib/spdm_crypt_ext.c.func-sort-c.html @@ -0,0 +1,109 @@ + + + + + + + LCOV - coverage.info - os_stub/spdm_crypt_ext_lib/spdm_crypt_ext.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/spdm_crypt_ext_lib - spdm_crypt_ext.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:288532.9 %
Date:2024-09-22 08:21:07Functions:77100.0 %
Branches:73221.9 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_aysm_nid6
libspdm_get_req_asym_get_private_key_from_pem25
libspdm_req_asym_get_private_key_from_pem25
libspdm_asym_get_private_key_from_pem128
libspdm_get_asym_get_private_key_from_pem153
libspdm_measurement_hash_all214
libspdm_spdm_measurement_hash_func214
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/spdm_crypt_ext_lib/spdm_crypt_ext.c.func.html b/coverage_log/os_stub/spdm_crypt_ext_lib/spdm_crypt_ext.c.func.html new file mode 100644 index 00000000000..1995ee9aef1 --- /dev/null +++ b/coverage_log/os_stub/spdm_crypt_ext_lib/spdm_crypt_ext.c.func.html @@ -0,0 +1,109 @@ + + + + + + + LCOV - coverage.info - os_stub/spdm_crypt_ext_lib/spdm_crypt_ext.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/spdm_crypt_ext_lib - spdm_crypt_ext.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:288532.9 %
Date:2024-09-22 08:21:07Functions:77100.0 %
Branches:73221.9 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_asym_get_private_key_from_pem128
libspdm_get_asym_get_private_key_from_pem153
libspdm_get_aysm_nid6
libspdm_get_req_asym_get_private_key_from_pem25
libspdm_measurement_hash_all214
libspdm_req_asym_get_private_key_from_pem25
libspdm_spdm_measurement_hash_func214
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/spdm_crypt_ext_lib/spdm_crypt_ext.c.gcov.html b/coverage_log/os_stub/spdm_crypt_ext_lib/spdm_crypt_ext.c.gcov.html new file mode 100644 index 00000000000..9278f204402 --- /dev/null +++ b/coverage_log/os_stub/spdm_crypt_ext_lib/spdm_crypt_ext.c.gcov.html @@ -0,0 +1,351 @@ + + + + + + + LCOV - coverage.info - os_stub/spdm_crypt_ext_lib/spdm_crypt_ext.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/spdm_crypt_ext_lib - spdm_crypt_ext.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:288532.9 %
Date:2024-09-22 08:21:07Functions:77100.0 %
Branches:73221.9 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 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_lib_config.h"
+       8                 :            : #include "spdm_crypt_ext_lib/spdm_crypt_ext_lib.h"
+       9                 :            : #include "hal/library/cryptlib.h"
+      10                 :            : #include "spdm_crypt_ext_lib/cryptlib_ext.h"
+      11                 :            : #include "industry_standard/spdm.h"
+      12                 :            : #include "hal/library/debuglib.h"
+      13                 :            : 
+      14                 :            : /**
+      15                 :            :  * Return asymmetric GET_PRIVATE_KEY_FROM_PEM function, based upon the asymmetric algorithm.
+      16                 :            :  *
+      17                 :            :  * @param  base_asym_algo                 SPDM base_asym_algo
+      18                 :            :  *
+      19                 :            :  * @return asymmetric GET_PRIVATE_KEY_FROM_PEM function
+      20                 :            :  **/
+      21                 :            : libspdm_asym_get_private_key_from_pem_func
+      22                 :        153 : libspdm_get_asym_get_private_key_from_pem(uint32_t base_asym_algo)
+      23                 :            : {
+      24   [ +  +  -  -  :        153 :     switch (base_asym_algo) {
+                      - ]
+      25                 :         25 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
+      26                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
+      27                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
+      28                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048:
+      29                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072:
+      30                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096:
+      31                 :            : #if (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT)
+      32                 :         25 :         return libspdm_rsa_get_private_key_from_pem;
+      33                 :            : #else
+      34                 :            :         LIBSPDM_ASSERT(false);
+      35                 :            :         break;
+      36                 :            : #endif
+      37                 :        128 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
+      38                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
+      39                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
+      40                 :            : #if LIBSPDM_ECDSA_SUPPORT
+      41                 :        128 :         return libspdm_ec_get_private_key_from_pem;
+      42                 :            : #else
+      43                 :            :         LIBSPDM_ASSERT(false);
+      44                 :            :         break;
+      45                 :            : #endif
+      46                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
+      47                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
+      48                 :            : #if (LIBSPDM_EDDSA_ED25519_SUPPORT) || (LIBSPDM_EDDSA_ED448_SUPPORT)
+      49                 :            :         return libspdm_ecd_get_private_key_from_pem;
+      50                 :            : #else
+      51                 :          0 :         LIBSPDM_ASSERT(false);
+      52                 :          0 :         break;
+      53                 :            : #endif
+      54                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256:
+      55                 :            : #if LIBSPDM_SM2_DSA_SUPPORT
+      56                 :            :         return libspdm_sm2_get_private_key_from_pem;
+      57                 :            : #else
+      58                 :          0 :         LIBSPDM_ASSERT(false);
+      59                 :          0 :         break;
+      60                 :            : #endif
+      61                 :          0 :     default:
+      62                 :          0 :         LIBSPDM_ASSERT(false);
+      63                 :          0 :         break;
+      64                 :            :     }
+      65                 :            : 
+      66                 :          0 :     return NULL;
+      67                 :            : }
+      68                 :            : 
+      69                 :            : /**
+      70                 :            :  * Retrieve the Private key from the password-protected PEM key data.
+      71                 :            :  *
+      72                 :            :  * @param  base_asym_algo                 SPDM base_asym_algo
+      73                 :            :  * @param  pem_data                      Pointer to the PEM-encoded key data to be retrieved.
+      74                 :            :  * @param  pem_size                      size of the PEM key data in bytes.
+      75                 :            :  * @param  password                     NULL-terminated passphrase used for encrypted PEM key data.
+      76                 :            :  * @param  context                      Pointer to newly generated asymmetric context which contain the retrieved private key component.
+      77                 :            :  *                                     Use libspdm_asym_free() function to free the resource.
+      78                 :            :  *
+      79                 :            :  * @retval  true   Private key was retrieved successfully.
+      80                 :            :  * @retval  false  Invalid PEM key data or incorrect password.
+      81                 :            :  **/
+      82                 :        128 : bool libspdm_asym_get_private_key_from_pem(uint32_t base_asym_algo,
+      83                 :            :                                            const uint8_t *pem_data,
+      84                 :            :                                            size_t pem_size,
+      85                 :            :                                            const char *password,
+      86                 :            :                                            void **context)
+      87                 :            : {
+      88                 :            :     libspdm_asym_get_private_key_from_pem_func asym_get_private_key_from_pem;
+      89                 :        128 :     asym_get_private_key_from_pem = libspdm_get_asym_get_private_key_from_pem(base_asym_algo);
+      90         [ -  + ]:        128 :     if (asym_get_private_key_from_pem == NULL) {
+      91                 :          0 :         return false;
+      92                 :            :     }
+      93                 :        128 :     return asym_get_private_key_from_pem(pem_data, pem_size, password, context);
+      94                 :            : }
+      95                 :            : 
+      96                 :            : /**
+      97                 :            :  * Return asymmetric GET_PRIVATE_KEY_FROM_PEM function, based upon the asymmetric algorithm.
+      98                 :            :  *
+      99                 :            :  * @param  req_base_asym_alg               SPDM req_base_asym_alg
+     100                 :            :  *
+     101                 :            :  * @return asymmetric GET_PRIVATE_KEY_FROM_PEM function
+     102                 :            :  **/
+     103                 :            : static libspdm_asym_get_private_key_from_pem_func
+     104                 :         25 : libspdm_get_req_asym_get_private_key_from_pem(uint16_t req_base_asym_alg)
+     105                 :            : {
+     106                 :         25 :     return libspdm_get_asym_get_private_key_from_pem(req_base_asym_alg);
+     107                 :            : }
+     108                 :            : 
+     109                 :            : /**
+     110                 :            :  * Retrieve the Private key from the password-protected PEM key data.
+     111                 :            :  *
+     112                 :            :  * @param  req_base_asym_alg               SPDM req_base_asym_alg
+     113                 :            :  * @param  pem_data                      Pointer to the PEM-encoded key data to be retrieved.
+     114                 :            :  * @param  pem_size                      size of the PEM key data in bytes.
+     115                 :            :  * @param  password                     NULL-terminated passphrase used for encrypted PEM key data.
+     116                 :            :  * @param  context                      Pointer to newly generated asymmetric context which contain the retrieved private key component.
+     117                 :            :  *                                     Use libspdm_asym_free() function to free the resource.
+     118                 :            :  *
+     119                 :            :  * @retval  true   Private key was retrieved successfully.
+     120                 :            :  * @retval  false  Invalid PEM key data or incorrect password.
+     121                 :            :  **/
+     122                 :         25 : bool libspdm_req_asym_get_private_key_from_pem(uint16_t req_base_asym_alg,
+     123                 :            :                                                const uint8_t *pem_data,
+     124                 :            :                                                size_t pem_size,
+     125                 :            :                                                const char *password,
+     126                 :            :                                                void **context)
+     127                 :            : {
+     128                 :            :     libspdm_asym_get_private_key_from_pem_func asym_get_private_key_from_pem;
+     129                 :            :     asym_get_private_key_from_pem =
+     130                 :         25 :         libspdm_get_req_asym_get_private_key_from_pem(req_base_asym_alg);
+     131         [ -  + ]:         25 :     if (asym_get_private_key_from_pem == NULL) {
+     132                 :          0 :         return false;
+     133                 :            :     }
+     134                 :         25 :     return asym_get_private_key_from_pem(pem_data, pem_size, password,
+     135                 :            :                                          context);
+     136                 :            : }
+     137                 :            : 
+     138                 :            : /**
+     139                 :            :  * Computes the hash of a input data buffer.
+     140                 :            :  *
+     141                 :            :  * This function performs the hash of a given data buffer, and return the hash value.
+     142                 :            :  *
+     143                 :            :  * @param  data        Pointer to the buffer containing the data to be hashed.
+     144                 :            :  * @param  data_size   Size of data buffer in bytes.
+     145                 :            :  * @param  hash_value  Pointer to a buffer that receives the hash value.
+     146                 :            :  *
+     147                 :            :  * @retval true   hash computation succeeded.
+     148                 :            :  * @retval false  hash computation failed.
+     149                 :            :  **/
+     150                 :            : typedef bool (*libspdm_hash_all_func)(const void *data, size_t data_size, uint8_t *hash_value);
+     151                 :            : 
+     152                 :            : /**
+     153                 :            :  * Return hash function, based upon the negotiated measurement hash algorithm.
+     154                 :            :  *
+     155                 :            :  * @param  measurement_hash_algo          SPDM measurement_hash_algo
+     156                 :            :  *
+     157                 :            :  * @return hash function
+     158                 :            :  **/
+     159                 :        214 : static libspdm_hash_all_func libspdm_spdm_measurement_hash_func(uint32_t measurement_hash_algo)
+     160                 :            : {
+     161   [ -  +  -  -  :        214 :     switch (measurement_hash_algo) {
+             -  -  -  - ]
+     162                 :          0 :     case SPDM_ALGORITHMS_MEASUREMENT_HASH_ALGO_TPM_ALG_SHA_256:
+     163                 :            : #if LIBSPDM_SHA256_SUPPORT
+     164                 :          0 :         return libspdm_sha256_hash_all;
+     165                 :            : #else
+     166                 :            :         LIBSPDM_ASSERT(false);
+     167                 :            :         break;
+     168                 :            : #endif
+     169                 :        214 :     case SPDM_ALGORITHMS_MEASUREMENT_HASH_ALGO_TPM_ALG_SHA_384:
+     170                 :            : #if LIBSPDM_SHA384_SUPPORT
+     171                 :        214 :         return libspdm_sha384_hash_all;
+     172                 :            : #else
+     173                 :            :         LIBSPDM_ASSERT(false);
+     174                 :            :         break;
+     175                 :            : #endif
+     176                 :          0 :     case SPDM_ALGORITHMS_MEASUREMENT_HASH_ALGO_TPM_ALG_SHA_512:
+     177                 :            : #if LIBSPDM_SHA512_SUPPORT
+     178                 :          0 :         return libspdm_sha512_hash_all;
+     179                 :            : #else
+     180                 :            :         LIBSPDM_ASSERT(false);
+     181                 :            :         break;
+     182                 :            : #endif
+     183                 :          0 :     case SPDM_ALGORITHMS_MEASUREMENT_HASH_ALGO_TPM_ALG_SHA3_256:
+     184                 :            : #if LIBSPDM_SHA3_256_SUPPORT
+     185                 :            :         return libspdm_sha3_256_hash_all;
+     186                 :            : #else
+     187                 :          0 :         LIBSPDM_ASSERT(false);
+     188                 :          0 :         break;
+     189                 :            : #endif
+     190                 :          0 :     case SPDM_ALGORITHMS_MEASUREMENT_HASH_ALGO_TPM_ALG_SHA3_384:
+     191                 :            : #if LIBSPDM_SHA3_384_SUPPORT
+     192                 :            :         return libspdm_sha3_384_hash_all;
+     193                 :            : #else
+     194                 :          0 :         LIBSPDM_ASSERT(false);
+     195                 :          0 :         break;
+     196                 :            : #endif
+     197                 :          0 :     case SPDM_ALGORITHMS_MEASUREMENT_HASH_ALGO_TPM_ALG_SHA3_512:
+     198                 :            : #if LIBSPDM_SHA3_512_SUPPORT
+     199                 :            :         return libspdm_sha3_512_hash_all;
+     200                 :            : #else
+     201                 :          0 :         LIBSPDM_ASSERT(false);
+     202                 :          0 :         break;
+     203                 :            : #endif
+     204                 :          0 :     case SPDM_ALGORITHMS_MEASUREMENT_HASH_ALGO_TPM_ALG_SM3_256:
+     205                 :            : #if LIBSPDM_SM3_256_SUPPORT
+     206                 :            :         return libspdm_sm3_256_hash_all;
+     207                 :            : #else
+     208                 :          0 :         LIBSPDM_ASSERT(false);
+     209                 :          0 :         break;
+     210                 :            : #endif
+     211                 :          0 :     default:
+     212                 :          0 :         LIBSPDM_ASSERT(false);
+     213                 :          0 :         break;
+     214                 :            :     }
+     215                 :            : 
+     216                 :          0 :     return NULL;
+     217                 :            : }
+     218                 :            : 
+     219                 :        214 : bool libspdm_measurement_hash_all(uint32_t measurement_hash_algo,
+     220                 :            :                                   const void *data, size_t data_size,
+     221                 :            :                                   uint8_t *hash_value)
+     222                 :            : {
+     223                 :            :     libspdm_hash_all_func hash_function;
+     224                 :        214 :     hash_function = libspdm_spdm_measurement_hash_func(measurement_hash_algo);
+     225         [ -  + ]:        214 :     if (hash_function == NULL) {
+     226                 :          0 :         return false;
+     227                 :            :     }
+     228                 :        214 :     return hash_function(data, data_size, hash_value);
+     229                 :            : }
+     230                 :            : 
+     231                 :          6 : size_t libspdm_get_aysm_nid(uint32_t base_asym_algo)
+     232                 :            : {
+     233   [ -  -  -  -  :          6 :     switch (base_asym_algo)
+          -  -  +  -  -  
+             -  -  -  - ]
+     234                 :            :     {
+     235                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
+     236                 :          0 :         return LIBSPDM_CRYPTO_NID_RSASSA2048;
+     237                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
+     238                 :          0 :         return LIBSPDM_CRYPTO_NID_RSASSA3072;
+     239                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
+     240                 :          0 :         return LIBSPDM_CRYPTO_NID_RSASSA4096;
+     241                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048:
+     242                 :          0 :         return LIBSPDM_CRYPTO_NID_RSAPSS2048;
+     243                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072:
+     244                 :          0 :         return LIBSPDM_CRYPTO_NID_RSAPSS3072;
+     245                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096:
+     246                 :          0 :         return LIBSPDM_CRYPTO_NID_RSAPSS4096;
+     247                 :          6 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
+     248                 :          6 :         return LIBSPDM_CRYPTO_NID_ECDSA_NIST_P256;
+     249                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
+     250                 :          0 :         return LIBSPDM_CRYPTO_NID_ECDSA_NIST_P384;
+     251                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
+     252                 :          0 :         return LIBSPDM_CRYPTO_NID_ECDSA_NIST_P521;
+     253                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
+     254                 :          0 :         return LIBSPDM_CRYPTO_NID_EDDSA_ED25519;
+     255                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
+     256                 :          0 :         return LIBSPDM_CRYPTO_NID_EDDSA_ED448;
+     257                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256:
+     258                 :          0 :         return LIBSPDM_CRYPTO_NID_SM2_DSA_P256;
+     259                 :          0 :     default:
+     260                 :          0 :         return LIBSPDM_CRYPTO_NID_NULL;
+     261                 :            :     }
+     262                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/spdm_device_secret_lib_sample/cert.c.func-sort-c.html b/coverage_log/os_stub/spdm_device_secret_lib_sample/cert.c.func-sort-c.html new file mode 100644 index 00000000000..73efd324f0e --- /dev/null +++ b/coverage_log/os_stub/spdm_device_secret_lib_sample/cert.c.func-sort-c.html @@ -0,0 +1,121 @@ + + + + + + + LCOV - coverage.info - os_stub/spdm_device_secret_lib_sample/cert.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/spdm_device_secret_lib_sample - cert.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:27679234.8 %
Date:2024-09-22 08:21:07Functions:71070.0 %
Branches:10230233.8 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_read_requester_root_public_certificate0
libspdm_read_responder_root_public_certificate_by_size0
libspdm_read_responder_root_public_certificate_slot0
libspdm_read_responder_public_certificate_chain_alias_cert_till_dev_cert_ca2
libspdm_read_responder_root_public_certificate2
libspdm_read_responder_public_certificate_chain_alias_cert3
libspdm_read_responder_public_certificate_chain_per_slot6
libspdm_read_responder_public_certificate_chain_by_size8
libspdm_read_requester_public_certificate_chain22
libspdm_read_responder_public_certificate_chain613
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/spdm_device_secret_lib_sample/cert.c.func.html b/coverage_log/os_stub/spdm_device_secret_lib_sample/cert.c.func.html new file mode 100644 index 00000000000..d78a4435d38 --- /dev/null +++ b/coverage_log/os_stub/spdm_device_secret_lib_sample/cert.c.func.html @@ -0,0 +1,121 @@ + + + + + + + LCOV - coverage.info - os_stub/spdm_device_secret_lib_sample/cert.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/spdm_device_secret_lib_sample - cert.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:27679234.8 %
Date:2024-09-22 08:21:07Functions:71070.0 %
Branches:10230233.8 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_read_requester_public_certificate_chain22
libspdm_read_requester_root_public_certificate0
libspdm_read_responder_public_certificate_chain613
libspdm_read_responder_public_certificate_chain_alias_cert3
libspdm_read_responder_public_certificate_chain_alias_cert_till_dev_cert_ca2
libspdm_read_responder_public_certificate_chain_by_size8
libspdm_read_responder_public_certificate_chain_per_slot6
libspdm_read_responder_root_public_certificate2
libspdm_read_responder_root_public_certificate_by_size0
libspdm_read_responder_root_public_certificate_slot0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/spdm_device_secret_lib_sample/cert.c.gcov.html b/coverage_log/os_stub/spdm_device_secret_lib_sample/cert.c.gcov.html new file mode 100644 index 00000000000..6dfeb73b001 --- /dev/null +++ b/coverage_log/os_stub/spdm_device_secret_lib_sample/cert.c.gcov.html @@ -0,0 +1,1380 @@ + + + + + + + LCOV - coverage.info - os_stub/spdm_device_secret_lib_sample/cert.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/spdm_device_secret_lib_sample - cert.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:27679234.8 %
Date:2024-09-22 08:21:07Functions:71070.0 %
Branches:10230233.8 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 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                 :            : /** @file
+       8                 :            :  * SPDM common library.
+       9                 :            :  * It follows the SPDM Specification.
+      10                 :            :  **/
+      11                 :            : 
+      12                 :            : #include <stdarg.h>
+      13                 :            : #include <stddef.h>
+      14                 :            : #include <setjmp.h>
+      15                 :            : #include <stdint.h>
+      16                 :            : #include <stdlib.h>
+      17                 :            : #include <stdio.h>
+      18                 :            : #include <assert.h>
+      19                 :            : #include <string.h>
+      20                 :            : 
+      21                 :            : #include <base.h>
+      22                 :            : #include "library/memlib.h"
+      23                 :            : #include "spdm_device_secret_lib_internal.h"
+      24                 :            : 
+      25                 :          2 : bool libspdm_read_responder_root_public_certificate(uint32_t base_hash_algo,
+      26                 :            :                                                     uint32_t base_asym_algo,
+      27                 :            :                                                     void **data, size_t *size,
+      28                 :            :                                                     void **hash,
+      29                 :            :                                                     size_t *hash_size)
+      30                 :            : {
+      31                 :            :     bool res;
+      32                 :            :     void *file_data;
+      33                 :            :     size_t file_size;
+      34                 :            :     spdm_cert_chain_t *cert_chain;
+      35                 :            :     size_t cert_chain_size;
+      36                 :            :     char *file;
+      37                 :            :     size_t digest_size;
+      38                 :            : 
+      39                 :          2 :     *data = NULL;
+      40                 :          2 :     *size = 0;
+      41         [ -  + ]:          2 :     if (hash != NULL) {
+      42                 :          0 :         *hash = NULL;
+      43                 :            :     }
+      44         [ -  + ]:          2 :     if (hash_size != NULL) {
+      45                 :          0 :         *hash_size = 0;
+      46                 :            :     }
+      47                 :            : 
+      48         [ -  + ]:          2 :     if (base_asym_algo == 0) {
+      49                 :          0 :         return false;
+      50                 :            :     }
+      51                 :            : 
+      52   [ -  -  -  +  :          2 :     switch (base_asym_algo) {
+          -  -  -  -  -  
+                      - ]
+      53                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
+      54                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048:
+      55                 :          0 :         file = "rsa2048/ca.cert.der";
+      56                 :          0 :         break;
+      57                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
+      58                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072:
+      59                 :          0 :         file = "rsa3072/ca.cert.der";
+      60                 :          0 :         break;
+      61                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
+      62                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096:
+      63                 :          0 :         file = "rsa4096/ca.cert.der";
+      64                 :          0 :         break;
+      65                 :          2 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
+      66                 :          2 :         file = "ecp256/ca.cert.der";
+      67                 :          2 :         break;
+      68                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
+      69                 :          0 :         file = "ecp384/ca.cert.der";
+      70                 :          0 :         break;
+      71                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
+      72                 :          0 :         file = "ecp521/ca.cert.der";
+      73                 :          0 :         break;
+      74                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256:
+      75                 :          0 :         file = "sm2/ca.cert.der";
+      76                 :          0 :         break;
+      77                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
+      78                 :          0 :         file = "ed25519/ca.cert.der";
+      79                 :          0 :         break;
+      80                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
+      81                 :          0 :         file = "ed448/ca.cert.der";
+      82                 :          0 :         break;
+      83                 :          0 :     default:
+      84                 :          0 :         LIBSPDM_ASSERT(false);
+      85                 :          0 :         return false;
+      86                 :            :     }
+      87                 :          2 :     res = libspdm_read_input_file(file, &file_data, &file_size);
+      88         [ -  + ]:          2 :     if (!res) {
+      89                 :          0 :         return res;
+      90                 :            :     }
+      91                 :            : 
+      92                 :          2 :     digest_size = libspdm_get_hash_size(base_hash_algo);
+      93                 :            : 
+      94                 :          2 :     cert_chain_size = sizeof(spdm_cert_chain_t) + digest_size + file_size;
+      95                 :          2 :     cert_chain = (void *)malloc(cert_chain_size);
+      96         [ -  + ]:          2 :     if (cert_chain == NULL) {
+      97                 :          0 :         free(file_data);
+      98                 :          0 :         return false;
+      99                 :            :     }
+     100                 :          2 :     cert_chain->length = (uint16_t)cert_chain_size;
+     101                 :          2 :     cert_chain->reserved = 0;
+     102                 :            : 
+     103                 :          2 :     res = libspdm_hash_all(base_hash_algo, file_data, file_size,
+     104                 :          2 :                            (uint8_t *)(cert_chain + 1));
+     105         [ -  + ]:          2 :     if (!res) {
+     106                 :          0 :         free(file_data);
+     107                 :          0 :         free(cert_chain);
+     108                 :          0 :         return res;
+     109                 :            :     }
+     110                 :          2 :     libspdm_copy_mem((uint8_t *)cert_chain + sizeof(spdm_cert_chain_t) + digest_size,
+     111                 :          2 :                      cert_chain_size - (sizeof(spdm_cert_chain_t) + digest_size),
+     112                 :            :                      file_data, file_size);
+     113                 :            : 
+     114                 :          2 :     *data = cert_chain;
+     115                 :          2 :     *size = cert_chain_size;
+     116         [ -  + ]:          2 :     if (hash != NULL) {
+     117                 :          0 :         *hash = (cert_chain + 1);
+     118                 :            :     }
+     119         [ -  + ]:          2 :     if (hash_size != NULL) {
+     120                 :          0 :         *hash_size = digest_size;
+     121                 :            :     }
+     122                 :            : 
+     123                 :          2 :     free(file_data);
+     124                 :          2 :     return true;
+     125                 :            : }
+     126                 :            : 
+     127                 :          0 : bool libspdm_read_responder_root_public_certificate_slot(uint8_t slot_id,
+     128                 :            :                                                          uint32_t base_hash_algo,
+     129                 :            :                                                          uint32_t base_asym_algo,
+     130                 :            :                                                          void **data, size_t *size,
+     131                 :            :                                                          void **hash,
+     132                 :            :                                                          size_t *hash_size)
+     133                 :            : {
+     134                 :            :     bool res;
+     135                 :            :     void *file_data;
+     136                 :            :     size_t file_size;
+     137                 :            :     spdm_cert_chain_t *cert_chain;
+     138                 :            :     size_t cert_chain_size;
+     139                 :            :     char *file;
+     140                 :            :     size_t digest_size;
+     141                 :            : 
+     142                 :          0 :     *data = NULL;
+     143                 :          0 :     *size = 0;
+     144         [ #  # ]:          0 :     if (hash != NULL) {
+     145                 :          0 :         *hash = NULL;
+     146                 :            :     }
+     147         [ #  # ]:          0 :     if (hash_size != NULL) {
+     148                 :          0 :         *hash_size = 0;
+     149                 :            :     }
+     150                 :            : 
+     151         [ #  # ]:          0 :     if (base_asym_algo == 0) {
+     152                 :          0 :         return false;
+     153                 :            :     }
+     154                 :            : 
+     155         [ #  # ]:          0 :     if (slot_id == 0) {
+     156   [ #  #  #  #  :          0 :         switch (base_asym_algo) {
+          #  #  #  #  #  
+                      # ]
+     157                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
+     158                 :            :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048:
+     159                 :          0 :             file = "rsa2048/ca.cert.der";
+     160                 :          0 :             break;
+     161                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
+     162                 :            :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072:
+     163                 :          0 :             file = "rsa3072/ca.cert.der";
+     164                 :          0 :             break;
+     165                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
+     166                 :            :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096:
+     167                 :          0 :             file = "rsa4096/ca.cert.der";
+     168                 :          0 :             break;
+     169                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
+     170                 :          0 :             file = "ecp256/ca.cert.der";
+     171                 :          0 :             break;
+     172                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
+     173                 :          0 :             file = "ecp384/ca.cert.der";
+     174                 :          0 :             break;
+     175                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
+     176                 :          0 :             file = "ecp521/ca.cert.der";
+     177                 :          0 :             break;
+     178                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256:
+     179                 :          0 :             file = "sm2/ca.cert.der";
+     180                 :          0 :             break;
+     181                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
+     182                 :          0 :             file = "ed25519/ca.cert.der";
+     183                 :          0 :             break;
+     184                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
+     185                 :          0 :             file = "ed448/ca.cert.der";
+     186                 :          0 :             break;
+     187                 :          0 :         default:
+     188                 :          0 :             LIBSPDM_ASSERT(false);
+     189                 :          0 :             return false;
+     190                 :            :         }
+     191                 :            :     } else {
+     192   [ #  #  #  #  :          0 :         switch (base_asym_algo) {
+          #  #  #  #  #  
+                      # ]
+     193                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
+     194                 :            :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048:
+     195                 :          0 :             file = "rsa2048/ca1.cert.der";
+     196                 :          0 :             break;
+     197                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
+     198                 :            :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072:
+     199                 :          0 :             file = "rsa3072/ca1.cert.der";
+     200                 :          0 :             break;
+     201                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
+     202                 :            :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096:
+     203                 :          0 :             file = "rsa4096/ca1.cert.der";
+     204                 :          0 :             break;
+     205                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
+     206                 :          0 :             file = "ecp256/ca1.cert.der";
+     207                 :          0 :             break;
+     208                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
+     209                 :          0 :             file = "ecp384/ca1.cert.der";
+     210                 :          0 :             break;
+     211                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
+     212                 :          0 :             file = "ecp521/ca1.cert.der";
+     213                 :          0 :             break;
+     214                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256:
+     215                 :          0 :             file = "sm2/ca1.cert.der";
+     216                 :          0 :             break;
+     217                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
+     218                 :          0 :             file = "ed25519/ca1.cert.der";
+     219                 :          0 :             break;
+     220                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
+     221                 :          0 :             file = "ed448/ca1.cert.der";
+     222                 :          0 :             break;
+     223                 :          0 :         default:
+     224                 :          0 :             LIBSPDM_ASSERT(false);
+     225                 :          0 :             return false;
+     226                 :            :         }
+     227                 :            :     }
+     228                 :          0 :     res = libspdm_read_input_file(file, &file_data, &file_size);
+     229         [ #  # ]:          0 :     if (!res) {
+     230                 :          0 :         return res;
+     231                 :            :     }
+     232                 :            : 
+     233                 :          0 :     digest_size = libspdm_get_hash_size(base_hash_algo);
+     234                 :            : 
+     235                 :          0 :     cert_chain_size = sizeof(spdm_cert_chain_t) + digest_size + file_size;
+     236                 :          0 :     cert_chain = (void *)malloc(cert_chain_size);
+     237         [ #  # ]:          0 :     if (cert_chain == NULL) {
+     238                 :          0 :         free(file_data);
+     239                 :          0 :         return false;
+     240                 :            :     }
+     241                 :          0 :     cert_chain->length = (uint16_t)cert_chain_size;
+     242                 :          0 :     cert_chain->reserved = 0;
+     243                 :            : 
+     244                 :          0 :     res = libspdm_hash_all(base_hash_algo, file_data, file_size,
+     245                 :          0 :                            (uint8_t *)(cert_chain + 1));
+     246         [ #  # ]:          0 :     if (!res) {
+     247                 :          0 :         free(file_data);
+     248                 :          0 :         free(cert_chain);
+     249                 :          0 :         return res;
+     250                 :            :     }
+     251                 :          0 :     libspdm_copy_mem((uint8_t *)cert_chain + sizeof(spdm_cert_chain_t) + digest_size,
+     252                 :          0 :                      cert_chain_size - (sizeof(spdm_cert_chain_t) + digest_size),
+     253                 :            :                      file_data, file_size);
+     254                 :            : 
+     255                 :          0 :     *data = cert_chain;
+     256                 :          0 :     *size = cert_chain_size;
+     257         [ #  # ]:          0 :     if (hash != NULL) {
+     258                 :          0 :         *hash = (cert_chain + 1);
+     259                 :            :     }
+     260         [ #  # ]:          0 :     if (hash_size != NULL) {
+     261                 :          0 :         *hash_size = digest_size;
+     262                 :            :     }
+     263                 :            : 
+     264                 :          0 :     free(file_data);
+     265                 :          0 :     return true;
+     266                 :            : }
+     267                 :            : 
+     268                 :          0 : bool libspdm_read_requester_root_public_certificate(uint32_t base_hash_algo,
+     269                 :            :                                                     uint16_t req_base_asym_alg,
+     270                 :            :                                                     void **data, size_t *size,
+     271                 :            :                                                     void **hash,
+     272                 :            :                                                     size_t *hash_size)
+     273                 :            : {
+     274                 :            :     bool res;
+     275                 :            :     void *file_data;
+     276                 :            :     size_t file_size;
+     277                 :            :     spdm_cert_chain_t *cert_chain;
+     278                 :            :     size_t cert_chain_size;
+     279                 :            :     char *file;
+     280                 :            :     size_t digest_size;
+     281                 :            : 
+     282                 :          0 :     *data = NULL;
+     283                 :          0 :     *size = 0;
+     284         [ #  # ]:          0 :     if (hash != NULL) {
+     285                 :          0 :         *hash = NULL;
+     286                 :            :     }
+     287         [ #  # ]:          0 :     if (hash_size != NULL) {
+     288                 :          0 :         *hash_size = 0;
+     289                 :            :     }
+     290                 :            : 
+     291         [ #  # ]:          0 :     if (req_base_asym_alg == 0) {
+     292                 :          0 :         return false;
+     293                 :            :     }
+     294                 :            : 
+     295   [ #  #  #  #  :          0 :     switch (req_base_asym_alg) {
+          #  #  #  #  #  
+                      # ]
+     296                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
+     297                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048:
+     298                 :          0 :         file = "rsa2048/ca.cert.der";
+     299                 :          0 :         break;
+     300                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
+     301                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072:
+     302                 :          0 :         file = "rsa3072/ca.cert.der";
+     303                 :          0 :         break;
+     304                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
+     305                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096:
+     306                 :          0 :         file = "rsa4096/ca.cert.der";
+     307                 :          0 :         break;
+     308                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
+     309                 :          0 :         file = "ecp256/ca.cert.der";
+     310                 :          0 :         break;
+     311                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
+     312                 :          0 :         file = "ecp384/ca.cert.der";
+     313                 :          0 :         break;
+     314                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
+     315                 :          0 :         file = "ecp521/ca.cert.der";
+     316                 :          0 :         break;
+     317                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256:
+     318                 :          0 :         file = "sm2/ca.cert.der";
+     319                 :          0 :         break;
+     320                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
+     321                 :          0 :         file = "ed25519/ca.cert.der";
+     322                 :          0 :         break;
+     323                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
+     324                 :          0 :         file = "ed448/ca.cert.der";
+     325                 :          0 :         break;
+     326                 :          0 :     default:
+     327                 :          0 :         LIBSPDM_ASSERT(false);
+     328                 :          0 :         return false;
+     329                 :            :     }
+     330                 :            : 
+     331                 :          0 :     digest_size = libspdm_get_hash_size(base_hash_algo);
+     332                 :            : 
+     333                 :          0 :     res = libspdm_read_input_file(file, &file_data, &file_size);
+     334         [ #  # ]:          0 :     if (!res) {
+     335                 :          0 :         return res;
+     336                 :            :     }
+     337                 :            : 
+     338                 :          0 :     cert_chain_size = sizeof(spdm_cert_chain_t) + digest_size + file_size;
+     339                 :          0 :     cert_chain = (void *)malloc(cert_chain_size);
+     340         [ #  # ]:          0 :     if (cert_chain == NULL) {
+     341                 :          0 :         free(file_data);
+     342                 :          0 :         return false;
+     343                 :            :     }
+     344                 :          0 :     cert_chain->length = (uint16_t)cert_chain_size;
+     345                 :          0 :     cert_chain->reserved = 0;
+     346                 :          0 :     res = libspdm_hash_all(base_hash_algo, file_data, file_size,
+     347                 :          0 :                            (uint8_t *)(cert_chain + 1));
+     348         [ #  # ]:          0 :     if (!res) {
+     349                 :          0 :         free(file_data);
+     350                 :          0 :         free(cert_chain);
+     351                 :          0 :         return res;
+     352                 :            :     }
+     353                 :          0 :     libspdm_copy_mem((uint8_t *)cert_chain + sizeof(spdm_cert_chain_t) + digest_size,
+     354                 :          0 :                      cert_chain_size - (sizeof(spdm_cert_chain_t) + digest_size),
+     355                 :            :                      file_data, file_size);
+     356                 :            : 
+     357                 :          0 :     *data = cert_chain;
+     358                 :          0 :     *size = cert_chain_size;
+     359         [ #  # ]:          0 :     if (hash != NULL) {
+     360                 :          0 :         *hash = (cert_chain + 1);
+     361                 :            :     }
+     362         [ #  # ]:          0 :     if (hash_size != NULL) {
+     363                 :          0 :         *hash_size = digest_size;
+     364                 :            :     }
+     365                 :            : 
+     366                 :          0 :     free(file_data);
+     367                 :          0 :     return true;
+     368                 :            : }
+     369                 :            : 
+     370                 :        613 : bool libspdm_read_responder_public_certificate_chain(
+     371                 :            :     uint32_t base_hash_algo, uint32_t base_asym_algo, void **data,
+     372                 :            :     size_t *size, void **hash, size_t *hash_size)
+     373                 :            : {
+     374                 :            :     bool res;
+     375                 :            :     void *file_data;
+     376                 :            :     size_t file_size;
+     377                 :            :     spdm_cert_chain_t *cert_chain;
+     378                 :            :     size_t cert_chain_size;
+     379                 :            :     char *file;
+     380                 :            :     const uint8_t *root_cert;
+     381                 :            :     size_t root_cert_len;
+     382                 :            :     size_t digest_size;
+     383                 :            :     bool is_requester_cert;
+     384                 :            :     bool is_device_cert_model;
+     385                 :            : 
+     386                 :        613 :     is_requester_cert = false;
+     387                 :            : 
+     388                 :            :     /*default is true*/
+     389                 :        613 :     is_device_cert_model = true;
+     390                 :            : 
+     391                 :        613 :     *data = NULL;
+     392                 :        613 :     *size = 0;
+     393         [ +  + ]:        613 :     if (hash != NULL) {
+     394                 :        324 :         *hash = NULL;
+     395                 :            :     }
+     396         [ +  + ]:        613 :     if (hash_size != NULL) {
+     397                 :        324 :         *hash_size = 0;
+     398                 :            :     }
+     399                 :            : 
+     400         [ -  + ]:        613 :     if (base_asym_algo == 0) {
+     401                 :          0 :         return false;
+     402                 :            :     }
+     403                 :            : 
+     404   [ +  -  -  +  :        613 :     switch (base_asym_algo) {
+          -  -  -  -  -  
+                      - ]
+     405                 :          4 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
+     406                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048:
+     407                 :          4 :         file = "rsa2048/bundle_responder.certchain.der";
+     408                 :          4 :         break;
+     409                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
+     410                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072:
+     411                 :          0 :         file = "rsa3072/bundle_responder.certchain.der";
+     412                 :          0 :         break;
+     413                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
+     414                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096:
+     415                 :          0 :         file = "rsa4096/bundle_responder.certchain.der";
+     416                 :          0 :         break;
+     417                 :        609 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
+     418                 :        609 :         file = "ecp256/bundle_responder.certchain.der";
+     419                 :        609 :         break;
+     420                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
+     421                 :          0 :         file = "ecp384/bundle_responder.certchain.der";
+     422                 :          0 :         break;
+     423                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
+     424                 :          0 :         file = "ecp521/bundle_responder.certchain.der";
+     425                 :          0 :         break;
+     426                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256:
+     427                 :          0 :         file = "sm2/bundle_responder.certchain.der";
+     428                 :          0 :         break;
+     429                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
+     430                 :          0 :         file = "ed25519/bundle_responder.certchain.der";
+     431                 :          0 :         break;
+     432                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
+     433                 :          0 :         file = "ed448/bundle_responder.certchain.der";
+     434                 :          0 :         break;
+     435                 :          0 :     default:
+     436                 :          0 :         LIBSPDM_ASSERT(false);
+     437                 :          0 :         return false;
+     438                 :            :     }
+     439                 :        613 :     res = libspdm_read_input_file(file, &file_data, &file_size);
+     440         [ -  + ]:        613 :     if (!res) {
+     441                 :          0 :         return res;
+     442                 :            :     }
+     443                 :            : 
+     444                 :        613 :     digest_size = libspdm_get_hash_size(base_hash_algo);
+     445                 :            : 
+     446                 :        613 :     cert_chain_size = sizeof(spdm_cert_chain_t) + digest_size + file_size;
+     447                 :        613 :     cert_chain = (void *)malloc(cert_chain_size);
+     448         [ -  + ]:        613 :     if (cert_chain == NULL) {
+     449                 :          0 :         free(file_data);
+     450                 :          0 :         return false;
+     451                 :            :     }
+     452                 :        613 :     cert_chain->length = (uint16_t)cert_chain_size;
+     453                 :        613 :     cert_chain->reserved = 0;
+     454                 :            : 
+     455                 :        613 :     res = libspdm_verify_cert_chain_data(file_data, file_size,
+     456                 :            :                                          base_asym_algo, base_hash_algo,
+     457                 :            :                                          is_requester_cert, is_device_cert_model);
+     458         [ -  + ]:        613 :     if (!res) {
+     459                 :          0 :         free(file_data);
+     460                 :          0 :         free(cert_chain);
+     461                 :          0 :         return res;
+     462                 :            :     }
+     463                 :            : 
+     464                 :            : 
+     465                 :            :     /* Get Root Certificate and calculate hash value*/
+     466                 :            : 
+     467                 :        613 :     res = libspdm_x509_get_cert_from_cert_chain(file_data, file_size, 0, &root_cert,
+     468                 :            :                                                 &root_cert_len);
+     469         [ -  + ]:        613 :     if (!res) {
+     470                 :          0 :         free(file_data);
+     471                 :          0 :         free(cert_chain);
+     472                 :          0 :         return res;
+     473                 :            :     }
+     474                 :            : 
+     475                 :        613 :     res = libspdm_hash_all(base_hash_algo, root_cert, root_cert_len,
+     476                 :        613 :                            (uint8_t *)(cert_chain + 1));
+     477         [ -  + ]:        613 :     if (!res) {
+     478                 :          0 :         free(file_data);
+     479                 :          0 :         free(cert_chain);
+     480                 :          0 :         return res;
+     481                 :            :     }
+     482                 :        613 :     libspdm_copy_mem((uint8_t *)cert_chain + sizeof(spdm_cert_chain_t) + digest_size,
+     483                 :        613 :                      cert_chain_size - (sizeof(spdm_cert_chain_t) + digest_size),
+     484                 :            :                      file_data, file_size);
+     485                 :            : 
+     486                 :        613 :     *data = cert_chain;
+     487                 :        613 :     *size = cert_chain_size;
+     488         [ +  + ]:        613 :     if (hash != NULL) {
+     489                 :        324 :         *hash = (cert_chain + 1);
+     490                 :            :     }
+     491         [ +  + ]:        613 :     if (hash_size != NULL) {
+     492                 :        324 :         *hash_size = digest_size;
+     493                 :            :     }
+     494                 :            : 
+     495                 :        613 :     free(file_data);
+     496                 :        613 :     return true;
+     497                 :            : }
+     498                 :            : 
+     499                 :            : /*This alias cert chain is partial, from root CA to device certificate CA.*/
+     500                 :          2 : bool libspdm_read_responder_public_certificate_chain_alias_cert_till_dev_cert_ca(
+     501                 :            :     uint32_t base_hash_algo, uint32_t base_asym_algo, void **data,
+     502                 :            :     size_t *size, void **hash, size_t *hash_size)
+     503                 :            : {
+     504                 :            :     bool res;
+     505                 :            :     void *file_data;
+     506                 :            :     size_t file_size;
+     507                 :            :     spdm_cert_chain_t *cert_chain;
+     508                 :            :     size_t cert_chain_size;
+     509                 :            :     char *file;
+     510                 :            :     const uint8_t *root_cert;
+     511                 :            :     size_t root_cert_len;
+     512                 :            :     const uint8_t *leaf_cert;
+     513                 :            :     size_t leaf_cert_len;
+     514                 :            :     size_t digest_size;
+     515                 :            :     bool is_requester_cert;
+     516                 :            :     bool is_device_cert_model;
+     517                 :            : 
+     518                 :          2 :     is_requester_cert = false;
+     519                 :            : 
+     520                 :            :     /*default is false*/
+     521                 :          2 :     is_device_cert_model = false;
+     522                 :            : 
+     523                 :          2 :     *data = NULL;
+     524                 :          2 :     *size = 0;
+     525         [ -  + ]:          2 :     if (hash != NULL) {
+     526                 :          0 :         *hash = NULL;
+     527                 :            :     }
+     528         [ -  + ]:          2 :     if (hash_size != NULL) {
+     529                 :          0 :         *hash_size = 0;
+     530                 :            :     }
+     531                 :            : 
+     532         [ -  + ]:          2 :     if (base_asym_algo == 0) {
+     533                 :          0 :         return false;
+     534                 :            :     }
+     535                 :            : 
+     536   [ -  -  -  +  :          2 :     switch (base_asym_algo) {
+          -  -  -  -  -  
+                      - ]
+     537                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
+     538                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048:
+     539                 :          0 :         file = "rsa2048/bundle_responder.certchain_alias_cert_partial_set.der";
+     540                 :          0 :         break;
+     541                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
+     542                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072:
+     543                 :          0 :         file = "rsa3072/bundle_responder.certchain_alias_cert_partial_set.der";
+     544                 :          0 :         break;
+     545                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
+     546                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096:
+     547                 :          0 :         file = "rsa4096/bundle_responder.certchain_alias_cert_partial_set.der";
+     548                 :          0 :         break;
+     549                 :          2 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
+     550                 :          2 :         file = "ecp256/bundle_responder.certchain_alias_cert_partial_set.der";
+     551                 :          2 :         break;
+     552                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
+     553                 :          0 :         file = "ecp384/bundle_responder.certchain_alias_cert_partial_set.der";
+     554                 :          0 :         break;
+     555                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
+     556                 :          0 :         file = "ecp521/bundle_responder.certchain_alias_cert_partial_set.der";
+     557                 :          0 :         break;
+     558                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256:
+     559                 :          0 :         file = "sm2/bundle_responder.certchain_alias_cert_partial_set.der";
+     560                 :          0 :         break;
+     561                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
+     562                 :          0 :         file = "ed25519/bundle_responder.certchain_alias_cert_partial_set.der";
+     563                 :          0 :         break;
+     564                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
+     565                 :          0 :         file = "ed448/bundle_responder.certchain_alias_cert_partial_set.der";
+     566                 :          0 :         break;
+     567                 :          0 :     default:
+     568                 :          0 :         LIBSPDM_ASSERT(false);
+     569                 :          0 :         return false;
+     570                 :            :     }
+     571                 :          2 :     res = libspdm_read_input_file(file, &file_data, &file_size);
+     572         [ -  + ]:          2 :     if (!res) {
+     573                 :          0 :         return res;
+     574                 :            :     }
+     575                 :            : 
+     576                 :          2 :     digest_size = libspdm_get_hash_size(base_hash_algo);
+     577                 :            : 
+     578                 :          2 :     cert_chain_size = sizeof(spdm_cert_chain_t) + digest_size + file_size;
+     579                 :          2 :     cert_chain = (void *)malloc(cert_chain_size);
+     580         [ -  + ]:          2 :     if (cert_chain == NULL) {
+     581                 :          0 :         free(file_data);
+     582                 :          0 :         return false;
+     583                 :            :     }
+     584                 :          2 :     cert_chain->length = (uint16_t)cert_chain_size;
+     585                 :          2 :     cert_chain->reserved = 0;
+     586                 :            : 
+     587                 :            :     /* Get leaf Certificate*/
+     588                 :          2 :     res = libspdm_x509_get_cert_from_cert_chain(file_data, file_size, -1, &leaf_cert,
+     589                 :            :                                                 &leaf_cert_len);
+     590         [ -  + ]:          2 :     if (!res) {
+     591                 :          0 :         free(file_data);
+     592                 :          0 :         free(cert_chain);
+     593                 :          0 :         return res;
+     594                 :            :     }
+     595                 :          2 :     res = libspdm_x509_set_cert_certificate_check(leaf_cert, leaf_cert_len,
+     596                 :            :                                                   base_asym_algo, base_hash_algo,
+     597                 :            :                                                   is_requester_cert, is_device_cert_model);
+     598         [ -  + ]:          2 :     if (!res) {
+     599                 :          0 :         free(file_data);
+     600                 :          0 :         free(cert_chain);
+     601                 :          0 :         return res;
+     602                 :            :     }
+     603                 :            : 
+     604                 :            :     /* Get Root Certificate*/
+     605                 :          2 :     res = libspdm_x509_get_cert_from_cert_chain(file_data, file_size, 0, &root_cert,
+     606                 :            :                                                 &root_cert_len);
+     607         [ -  + ]:          2 :     if (!res) {
+     608                 :          0 :         free(file_data);
+     609                 :          0 :         free(cert_chain);
+     610                 :          0 :         return res;
+     611                 :            :     }
+     612                 :            : 
+     613                 :            :     /*verify cert_chain*/
+     614                 :          2 :     res = libspdm_x509_verify_cert_chain(root_cert, root_cert_len, file_data, file_size);
+     615         [ -  + ]:          2 :     if (!res) {
+     616                 :          0 :         free(file_data);
+     617                 :          0 :         free(cert_chain);
+     618                 :          0 :         return res;
+     619                 :            :     }
+     620                 :            : 
+     621                 :            :     /*calculate hash value*/
+     622                 :          2 :     res = libspdm_hash_all(base_hash_algo, root_cert, root_cert_len,
+     623                 :          2 :                            (uint8_t *)(cert_chain + 1));
+     624         [ -  + ]:          2 :     if (!res) {
+     625                 :          0 :         free(file_data);
+     626                 :          0 :         free(cert_chain);
+     627                 :          0 :         return res;
+     628                 :            :     }
+     629                 :          2 :     libspdm_copy_mem((uint8_t *)cert_chain + sizeof(spdm_cert_chain_t) + digest_size,
+     630                 :          2 :                      cert_chain_size - (sizeof(spdm_cert_chain_t) + digest_size),
+     631                 :            :                      file_data, file_size);
+     632                 :            : 
+     633                 :          2 :     *data = cert_chain;
+     634                 :          2 :     *size = cert_chain_size;
+     635         [ -  + ]:          2 :     if (hash != NULL) {
+     636                 :          0 :         *hash = (cert_chain + 1);
+     637                 :            :     }
+     638         [ -  + ]:          2 :     if (hash_size != NULL) {
+     639                 :          0 :         *hash_size = digest_size;
+     640                 :            :     }
+     641                 :            : 
+     642                 :          2 :     free(file_data);
+     643                 :          2 :     return true;
+     644                 :            : }
+     645                 :            : 
+     646                 :            : /*This alias cert chain is entire, from root CA to leaf certificate.*/
+     647                 :          3 : bool libspdm_read_responder_public_certificate_chain_alias_cert(
+     648                 :            :     uint32_t base_hash_algo, uint32_t base_asym_algo, void **data,
+     649                 :            :     size_t *size, void **hash, size_t *hash_size)
+     650                 :            : {
+     651                 :            :     bool res;
+     652                 :            :     void *file_data;
+     653                 :            :     size_t file_size;
+     654                 :            :     spdm_cert_chain_t *cert_chain;
+     655                 :            :     size_t cert_chain_size;
+     656                 :            :     char *file;
+     657                 :            :     const uint8_t *root_cert;
+     658                 :            :     size_t root_cert_len;
+     659                 :            :     const uint8_t *leaf_cert;
+     660                 :            :     size_t leaf_cert_len;
+     661                 :            :     size_t digest_size;
+     662                 :            :     bool is_requester_cert;
+     663                 :            :     bool is_device_cert_model;
+     664                 :            : 
+     665                 :          3 :     is_requester_cert = false;
+     666                 :            : 
+     667                 :            :     /*default is false*/
+     668                 :          3 :     is_device_cert_model = false;
+     669                 :            : 
+     670                 :          3 :     *data = NULL;
+     671                 :          3 :     *size = 0;
+     672         [ +  + ]:          3 :     if (hash != NULL) {
+     673                 :          2 :         *hash = NULL;
+     674                 :            :     }
+     675         [ +  + ]:          3 :     if (hash_size != NULL) {
+     676                 :          2 :         *hash_size = 0;
+     677                 :            :     }
+     678                 :            : 
+     679         [ -  + ]:          3 :     if (base_asym_algo == 0) {
+     680                 :          0 :         return false;
+     681                 :            :     }
+     682                 :            : 
+     683   [ -  -  -  +  :          3 :     switch (base_asym_algo) {
+          -  -  -  -  -  
+                      - ]
+     684                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
+     685                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048:
+     686                 :          0 :         file = "rsa2048/bundle_responder.certchain_alias.der";
+     687                 :          0 :         break;
+     688                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
+     689                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072:
+     690                 :          0 :         file = "rsa3072/bundle_responder.certchain_alias.der";
+     691                 :          0 :         break;
+     692                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
+     693                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096:
+     694                 :          0 :         file = "rsa4096/bundle_responder.certchain_alias.der";
+     695                 :          0 :         break;
+     696                 :          3 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
+     697                 :          3 :         file = "ecp256/bundle_responder.certchain_alias.der";
+     698                 :          3 :         break;
+     699                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
+     700                 :          0 :         file = "ecp384/bundle_responder.certchain_alias.der";
+     701                 :          0 :         break;
+     702                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
+     703                 :          0 :         file = "ecp521/bundle_responder.certchain_alias.der";
+     704                 :          0 :         break;
+     705                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256:
+     706                 :          0 :         file = "sm2/bundle_responder.certchain_alias.der";
+     707                 :          0 :         break;
+     708                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
+     709                 :          0 :         file = "ed25519/bundle_responder.certchain_alias.der";
+     710                 :          0 :         break;
+     711                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
+     712                 :          0 :         file = "ed448/bundle_responder.certchain_alias.der";
+     713                 :          0 :         break;
+     714                 :          0 :     default:
+     715                 :          0 :         LIBSPDM_ASSERT(false);
+     716                 :          0 :         return false;
+     717                 :            :     }
+     718                 :          3 :     res = libspdm_read_input_file(file, &file_data, &file_size);
+     719         [ -  + ]:          3 :     if (!res) {
+     720                 :          0 :         return res;
+     721                 :            :     }
+     722                 :            : 
+     723                 :          3 :     digest_size = libspdm_get_hash_size(base_hash_algo);
+     724                 :            : 
+     725                 :          3 :     cert_chain_size = sizeof(spdm_cert_chain_t) + digest_size + file_size;
+     726                 :          3 :     cert_chain = (void *)malloc(cert_chain_size);
+     727         [ -  + ]:          3 :     if (cert_chain == NULL) {
+     728                 :          0 :         free(file_data);
+     729                 :          0 :         return false;
+     730                 :            :     }
+     731                 :          3 :     cert_chain->length = (uint16_t)cert_chain_size;
+     732                 :          3 :     cert_chain->reserved = 0;
+     733                 :            : 
+     734                 :            :     /* Get leaf Certificate*/
+     735                 :          3 :     res = libspdm_x509_get_cert_from_cert_chain(file_data, file_size, -1, &leaf_cert,
+     736                 :            :                                                 &leaf_cert_len);
+     737         [ -  + ]:          3 :     if (!res) {
+     738                 :          0 :         free(file_data);
+     739                 :          0 :         free(cert_chain);
+     740                 :          0 :         return res;
+     741                 :            :     }
+     742                 :          3 :     res = libspdm_x509_certificate_check(leaf_cert, leaf_cert_len,
+     743                 :            :                                          base_asym_algo, base_hash_algo,
+     744                 :            :                                          is_requester_cert, is_device_cert_model);
+     745         [ -  + ]:          3 :     if (!res) {
+     746                 :          0 :         free(file_data);
+     747                 :          0 :         free(cert_chain);
+     748                 :          0 :         return res;
+     749                 :            :     }
+     750                 :            : 
+     751                 :            :     /* Get Root Certificate*/
+     752                 :          3 :     res = libspdm_x509_get_cert_from_cert_chain(file_data, file_size, 0, &root_cert,
+     753                 :            :                                                 &root_cert_len);
+     754         [ -  + ]:          3 :     if (!res) {
+     755                 :          0 :         free(file_data);
+     756                 :          0 :         free(cert_chain);
+     757                 :          0 :         return res;
+     758                 :            :     }
+     759                 :            : 
+     760                 :            :     /*verify cert_chain*/
+     761                 :          3 :     res = libspdm_x509_verify_cert_chain(root_cert, root_cert_len, file_data, file_size);
+     762         [ -  + ]:          3 :     if (!res) {
+     763                 :          0 :         free(file_data);
+     764                 :          0 :         free(cert_chain);
+     765                 :          0 :         return res;
+     766                 :            :     }
+     767                 :            : 
+     768                 :            :     /*calculate hash value*/
+     769                 :          3 :     res = libspdm_hash_all(base_hash_algo, root_cert, root_cert_len,
+     770                 :          3 :                            (uint8_t *)(cert_chain + 1));
+     771         [ -  + ]:          3 :     if (!res) {
+     772                 :          0 :         free(file_data);
+     773                 :          0 :         free(cert_chain);
+     774                 :          0 :         return res;
+     775                 :            :     }
+     776                 :          3 :     libspdm_copy_mem((uint8_t *)cert_chain + sizeof(spdm_cert_chain_t) + digest_size,
+     777                 :          3 :                      cert_chain_size - (sizeof(spdm_cert_chain_t) + digest_size),
+     778                 :            :                      file_data, file_size);
+     779                 :            : 
+     780                 :          3 :     *data = cert_chain;
+     781                 :          3 :     *size = cert_chain_size;
+     782         [ +  + ]:          3 :     if (hash != NULL) {
+     783                 :          2 :         *hash = (cert_chain + 1);
+     784                 :            :     }
+     785         [ +  + ]:          3 :     if (hash_size != NULL) {
+     786                 :          2 :         *hash_size = digest_size;
+     787                 :            :     }
+     788                 :            : 
+     789                 :          3 :     free(file_data);
+     790                 :          3 :     return true;
+     791                 :            : }
+     792                 :            : 
+     793                 :          6 : bool libspdm_read_responder_public_certificate_chain_per_slot(
+     794                 :            :     uint8_t slot_id, uint32_t base_hash_algo, uint32_t base_asym_algo,
+     795                 :            :     void **data, size_t *size, void **hash, size_t *hash_size)
+     796                 :            : {
+     797                 :            :     bool res;
+     798                 :            :     void *file_data;
+     799                 :            :     size_t file_size;
+     800                 :            :     spdm_cert_chain_t *cert_chain;
+     801                 :            :     size_t cert_chain_size;
+     802                 :            :     char *file;
+     803                 :            :     const uint8_t *root_cert;
+     804                 :            :     size_t root_cert_len;
+     805                 :            :     size_t digest_size;
+     806                 :            :     bool is_requester_cert;
+     807                 :            :     bool is_device_cert_model;
+     808                 :            : 
+     809                 :          6 :     is_requester_cert = false;
+     810                 :            : 
+     811                 :            :     /*default is true*/
+     812                 :          6 :     is_device_cert_model = true;
+     813                 :            : 
+     814                 :          6 :     *data = NULL;
+     815                 :          6 :     *size = 0;
+     816         [ +  + ]:          6 :     if (hash != NULL) {
+     817                 :          2 :         *hash = NULL;
+     818                 :            :     }
+     819         [ +  + ]:          6 :     if (hash_size != NULL) {
+     820                 :          2 :         *hash_size = 0;
+     821                 :            :     }
+     822                 :            : 
+     823         [ -  + ]:          6 :     if (base_asym_algo == 0) {
+     824                 :          0 :         return false;
+     825                 :            :     }
+     826                 :            : 
+     827         [ -  + ]:          6 :     if (slot_id == 0) {
+     828   [ #  #  #  #  :          0 :         switch (base_asym_algo) {
+          #  #  #  #  #  
+                      # ]
+     829                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
+     830                 :            :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048:
+     831                 :          0 :             file = "rsa2048/bundle_responder.certchain.der";
+     832                 :          0 :             break;
+     833                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
+     834                 :            :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072:
+     835                 :          0 :             file = "rsa3072/bundle_responder.certchain.der";
+     836                 :          0 :             break;
+     837                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
+     838                 :            :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096:
+     839                 :          0 :             file = "rsa4096/bundle_responder.certchain.der";
+     840                 :          0 :             break;
+     841                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
+     842                 :          0 :             file = "ecp256/bundle_responder.certchain.der";
+     843                 :          0 :             break;
+     844                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
+     845                 :          0 :             file = "ecp384/bundle_responder.certchain.der";
+     846                 :          0 :             break;
+     847                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
+     848                 :          0 :             file = "ecp521/bundle_responder.certchain.der";
+     849                 :          0 :             break;
+     850                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256:
+     851                 :          0 :             file = "sm2/bundle_responder.certchain.der";
+     852                 :          0 :             break;
+     853                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
+     854                 :          0 :             file = "ed25519/bundle_responder.certchain.der";
+     855                 :          0 :             break;
+     856                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
+     857                 :          0 :             file = "ed448/bundle_responder.certchain.der";
+     858                 :          0 :             break;
+     859                 :          0 :         default:
+     860                 :          0 :             LIBSPDM_ASSERT(false);
+     861                 :          0 :             return false;
+     862                 :            :         }
+     863                 :            :     } else {
+     864   [ -  -  -  +  :          6 :         switch (base_asym_algo) {
+          -  -  -  -  -  
+                      - ]
+     865                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
+     866                 :            :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048:
+     867                 :          0 :             file = "rsa2048/bundle_responder.certchain1.der";
+     868                 :          0 :             break;
+     869                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
+     870                 :            :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072:
+     871                 :          0 :             file = "rsa3072/bundle_responder.certchain1.der";
+     872                 :          0 :             break;
+     873                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
+     874                 :            :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096:
+     875                 :          0 :             file = "rsa4096/bundle_responder.certchain1.der";
+     876                 :          0 :             break;
+     877                 :          6 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
+     878                 :          6 :             file = "ecp256/bundle_responder.certchain1.der";
+     879                 :          6 :             break;
+     880                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
+     881                 :          0 :             file = "ecp384/bundle_responder.certchain1.der";
+     882                 :          0 :             break;
+     883                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
+     884                 :          0 :             file = "ecp521/bundle_responder.certchain1.der";
+     885                 :          0 :             break;
+     886                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256:
+     887                 :          0 :             file = "sm2/bundle_responder.certchain1.der";
+     888                 :          0 :             break;
+     889                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
+     890                 :          0 :             file = "ed25519/bundle_responder.certchain1.der";
+     891                 :          0 :             break;
+     892                 :          0 :         case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
+     893                 :          0 :             file = "ed448/bundle_responder.certchain1.der";
+     894                 :          0 :             break;
+     895                 :          0 :         default:
+     896                 :          0 :             LIBSPDM_ASSERT(false);
+     897                 :          0 :             return false;
+     898                 :            :         }
+     899                 :            :     }
+     900                 :          6 :     res = libspdm_read_input_file(file, &file_data, &file_size);
+     901         [ -  + ]:          6 :     if (!res) {
+     902                 :          0 :         return res;
+     903                 :            :     }
+     904                 :            : 
+     905                 :          6 :     digest_size = libspdm_get_hash_size(base_hash_algo);
+     906                 :            : 
+     907                 :          6 :     cert_chain_size = sizeof(spdm_cert_chain_t) + digest_size + file_size;
+     908                 :          6 :     cert_chain = (void *)malloc(cert_chain_size);
+     909         [ -  + ]:          6 :     if (cert_chain == NULL) {
+     910                 :          0 :         free(file_data);
+     911                 :          0 :         return false;
+     912                 :            :     }
+     913                 :          6 :     cert_chain->length = (uint16_t)cert_chain_size;
+     914                 :          6 :     cert_chain->reserved = 0;
+     915                 :            : 
+     916                 :          6 :     res = libspdm_verify_cert_chain_data(file_data, file_size,
+     917                 :            :                                          base_asym_algo, base_hash_algo,
+     918                 :            :                                          is_requester_cert, is_device_cert_model);
+     919         [ -  + ]:          6 :     if (!res) {
+     920                 :          0 :         free(file_data);
+     921                 :          0 :         free(cert_chain);
+     922                 :          0 :         return res;
+     923                 :            :     }
+     924                 :            : 
+     925                 :            : 
+     926                 :            :     /* Get Root Certificate and calculate hash value*/
+     927                 :            : 
+     928                 :          6 :     res = libspdm_x509_get_cert_from_cert_chain(file_data, file_size, 0, &root_cert,
+     929                 :            :                                                 &root_cert_len);
+     930         [ -  + ]:          6 :     if (!res) {
+     931                 :          0 :         free(file_data);
+     932                 :          0 :         free(cert_chain);
+     933                 :          0 :         return res;
+     934                 :            :     }
+     935                 :            : 
+     936                 :          6 :     res = libspdm_hash_all(base_hash_algo, root_cert, root_cert_len,
+     937                 :          6 :                            (uint8_t *)(cert_chain + 1));
+     938         [ -  + ]:          6 :     if (!res) {
+     939                 :          0 :         free(file_data);
+     940                 :          0 :         free(cert_chain);
+     941                 :          0 :         return res;
+     942                 :            :     }
+     943                 :          6 :     libspdm_copy_mem((uint8_t *)cert_chain + sizeof(spdm_cert_chain_t) + digest_size,
+     944                 :          6 :                      cert_chain_size - (sizeof(spdm_cert_chain_t) + digest_size),
+     945                 :            :                      file_data, file_size);
+     946                 :            : 
+     947                 :          6 :     *data = cert_chain;
+     948                 :          6 :     *size = cert_chain_size;
+     949         [ +  + ]:          6 :     if (hash != NULL) {
+     950                 :          2 :         *hash = (cert_chain + 1);
+     951                 :            :     }
+     952         [ +  + ]:          6 :     if (hash_size != NULL) {
+     953                 :          2 :         *hash_size = digest_size;
+     954                 :            :     }
+     955                 :            : 
+     956                 :          6 :     free(file_data);
+     957                 :          6 :     return true;
+     958                 :            : }
+     959                 :            : 
+     960                 :            : 
+     961                 :         22 : bool libspdm_read_requester_public_certificate_chain(
+     962                 :            :     uint32_t base_hash_algo, uint16_t req_base_asym_alg, void **data,
+     963                 :            :     size_t *size, void **hash, size_t *hash_size)
+     964                 :            : {
+     965                 :            :     bool res;
+     966                 :            :     void *file_data;
+     967                 :            :     size_t file_size;
+     968                 :            :     spdm_cert_chain_t *cert_chain;
+     969                 :            :     size_t cert_chain_size;
+     970                 :            :     char *file;
+     971                 :            :     const uint8_t *root_cert;
+     972                 :            :     size_t root_cert_len;
+     973                 :            :     size_t digest_size;
+     974                 :            :     bool is_requester_cert;
+     975                 :            :     bool is_device_cert_model;
+     976                 :            : 
+     977                 :         22 :     is_requester_cert = false;
+     978                 :            : 
+     979                 :            :     /*default is true*/
+     980                 :         22 :     is_device_cert_model = true;
+     981                 :            : 
+     982                 :         22 :     *data = NULL;
+     983                 :         22 :     *size = 0;
+     984         [ +  + ]:         22 :     if (hash != NULL) {
+     985                 :          5 :         *hash = NULL;
+     986                 :            :     }
+     987         [ +  + ]:         22 :     if (hash_size != NULL) {
+     988                 :          5 :         *hash_size = 0;
+     989                 :            :     }
+     990                 :            : 
+     991         [ -  + ]:         22 :     if (req_base_asym_alg == 0) {
+     992                 :          0 :         return false;
+     993                 :            :     }
+     994                 :            : 
+     995   [ +  -  -  -  :         22 :     switch (req_base_asym_alg) {
+          -  -  -  -  -  
+                      - ]
+     996                 :         22 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
+     997                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048:
+     998                 :         22 :         file = "rsa2048/bundle_requester.certchain.der";
+     999                 :         22 :         break;
+    1000                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
+    1001                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072:
+    1002                 :          0 :         file = "rsa3072/bundle_requester.certchain.der";
+    1003                 :          0 :         break;
+    1004                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
+    1005                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096:
+    1006                 :          0 :         file = "rsa4096/bundle_requester.certchain.der";
+    1007                 :          0 :         break;
+    1008                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
+    1009                 :          0 :         file = "ecp256/bundle_requester.certchain.der";
+    1010                 :          0 :         break;
+    1011                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
+    1012                 :          0 :         file = "ecp384/bundle_requester.certchain.der";
+    1013                 :          0 :         break;
+    1014                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
+    1015                 :          0 :         file = "ecp521/bundle_requester.certchain.der";
+    1016                 :          0 :         break;
+    1017                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256:
+    1018                 :          0 :         file = "sm2/bundle_requester.certchain.der";
+    1019                 :          0 :         break;
+    1020                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
+    1021                 :          0 :         file = "ed25519/bundle_requester.certchain.der";
+    1022                 :          0 :         break;
+    1023                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
+    1024                 :          0 :         file = "ed448/bundle_requester.certchain.der";
+    1025                 :          0 :         break;
+    1026                 :          0 :     default:
+    1027                 :          0 :         LIBSPDM_ASSERT(false);
+    1028                 :          0 :         return false;
+    1029                 :            :     }
+    1030                 :         22 :     res = libspdm_read_input_file(file, &file_data, &file_size);
+    1031         [ -  + ]:         22 :     if (!res) {
+    1032                 :          0 :         return res;
+    1033                 :            :     }
+    1034                 :            : 
+    1035                 :         22 :     digest_size = libspdm_get_hash_size(base_hash_algo);
+    1036                 :            : 
+    1037                 :         22 :     cert_chain_size = sizeof(spdm_cert_chain_t) + digest_size + file_size;
+    1038                 :         22 :     cert_chain = (void *)malloc(cert_chain_size);
+    1039         [ -  + ]:         22 :     if (cert_chain == NULL) {
+    1040                 :          0 :         free(file_data);
+    1041                 :          0 :         return false;
+    1042                 :            :     }
+    1043                 :         22 :     cert_chain->length = (uint16_t)cert_chain_size;
+    1044                 :         22 :     cert_chain->reserved = 0;
+    1045                 :            : 
+    1046                 :         22 :     res = libspdm_verify_cert_chain_data(file_data, file_size,
+    1047                 :            :                                          req_base_asym_alg, base_hash_algo,
+    1048                 :            :                                          is_requester_cert, is_device_cert_model);
+    1049         [ -  + ]:         22 :     if (!res) {
+    1050                 :          0 :         free(file_data);
+    1051                 :          0 :         free(cert_chain);
+    1052                 :          0 :         return res;
+    1053                 :            :     }
+    1054                 :            : 
+    1055                 :            : 
+    1056                 :            :     /* Get Root Certificate and calculate hash value*/
+    1057                 :            : 
+    1058                 :         22 :     res = libspdm_x509_get_cert_from_cert_chain(file_data, file_size, 0, &root_cert,
+    1059                 :            :                                                 &root_cert_len);
+    1060         [ -  + ]:         22 :     if (!res) {
+    1061                 :          0 :         free(file_data);
+    1062                 :          0 :         free(cert_chain);
+    1063                 :          0 :         return res;
+    1064                 :            :     }
+    1065                 :            : 
+    1066                 :         22 :     res = libspdm_hash_all(base_hash_algo, root_cert, root_cert_len,
+    1067                 :         22 :                            (uint8_t *)(cert_chain + 1));
+    1068         [ -  + ]:         22 :     if (!res) {
+    1069                 :          0 :         free(file_data);
+    1070                 :          0 :         free(cert_chain);
+    1071                 :          0 :         return res;
+    1072                 :            :     }
+    1073                 :         22 :     libspdm_copy_mem((uint8_t *)cert_chain + sizeof(spdm_cert_chain_t) + digest_size,
+    1074                 :         22 :                      cert_chain_size - (sizeof(spdm_cert_chain_t) + digest_size),
+    1075                 :            :                      file_data, file_size);
+    1076                 :            : 
+    1077                 :         22 :     *data = cert_chain;
+    1078                 :         22 :     *size = cert_chain_size;
+    1079         [ +  + ]:         22 :     if (hash != NULL) {
+    1080                 :          5 :         *hash = (cert_chain + 1);
+    1081                 :            :     }
+    1082         [ +  + ]:         22 :     if (hash_size != NULL) {
+    1083                 :          5 :         *hash_size = digest_size;
+    1084                 :            :     }
+    1085                 :            : 
+    1086                 :         22 :     free(file_data);
+    1087                 :         22 :     return true;
+    1088                 :            : }
+    1089                 :            : 
+    1090                 :          0 : bool libspdm_read_responder_root_public_certificate_by_size(
+    1091                 :            :     uint32_t base_hash_algo, uint32_t base_asym_algo, uint16_t chain_id,
+    1092                 :            :     void **data, size_t *size, void **hash, size_t *hash_size)
+    1093                 :            : {
+    1094                 :            :     bool res;
+    1095                 :            :     void *file_data;
+    1096                 :            :     size_t file_size;
+    1097                 :            :     spdm_cert_chain_t *cert_chain;
+    1098                 :            :     size_t cert_chain_size;
+    1099                 :            :     char *file;
+    1100                 :            :     size_t digest_size;
+    1101                 :            : 
+    1102                 :          0 :     *data = NULL;
+    1103                 :          0 :     *size = 0;
+    1104         [ #  # ]:          0 :     if (hash != NULL) {
+    1105                 :          0 :         *hash = NULL;
+    1106                 :            :     }
+    1107         [ #  # ]:          0 :     if (hash_size != NULL) {
+    1108                 :          0 :         *hash_size = 0;
+    1109                 :            :     }
+    1110                 :            : 
+    1111   [ #  #  #  #  :          0 :     switch (chain_id) {
+                      # ]
+    1112                 :          0 :     case LIBSPDM_TEST_CERT_SMALL:
+    1113                 :          0 :         file = "long_chains/Shorter1024B_ca.cert.der";
+    1114                 :          0 :         break;
+    1115                 :          0 :     case LIBSPDM_TEST_CERT_MAXINT16: /* data_size slightly smaller than 0x7FFF*/
+    1116                 :          0 :         file = "long_chains/ShorterMAXINT16_ca.cert.der";
+    1117                 :          0 :         break;
+    1118                 :          0 :     case LIBSPDM_TEST_CERT_MAXUINT16: /* data_size slightly smaller than 0xFFFF*/
+    1119                 :          0 :         file = "long_chains/ShorterMAXUINT16_ca.cert.der";
+    1120                 :          0 :         break;
+    1121                 :          0 :     case LIBSPDM_LIBSPDM_TEST_CERT_MAXUINT16_LARGER: /* data_size larger than 0xFFFF*/
+    1122                 :          0 :         file = "long_chains/LongerMAXUINT16_ca.cert.der";
+    1123                 :          0 :         break;
+    1124                 :          0 :     default:
+    1125                 :          0 :         LIBSPDM_ASSERT(false);
+    1126                 :          0 :         return false;
+    1127                 :            :     }
+    1128                 :          0 :     res = libspdm_read_input_file(file, &file_data, &file_size);
+    1129         [ #  # ]:          0 :     if (!res) {
+    1130                 :          0 :         return res;
+    1131                 :            :     }
+    1132                 :            : 
+    1133                 :          0 :     digest_size = libspdm_get_hash_size(base_hash_algo);
+    1134                 :            : 
+    1135                 :          0 :     cert_chain_size = sizeof(spdm_cert_chain_t) + digest_size + file_size;
+    1136                 :          0 :     cert_chain = (void *)malloc(cert_chain_size);
+    1137         [ #  # ]:          0 :     if (cert_chain == NULL) {
+    1138                 :          0 :         free(file_data);
+    1139                 :          0 :         return false;
+    1140                 :            :     }
+    1141                 :          0 :     cert_chain->length = (uint16_t)cert_chain_size;
+    1142                 :          0 :     cert_chain->reserved = 0;
+    1143                 :            : 
+    1144                 :          0 :     res = libspdm_hash_all(base_hash_algo, file_data, file_size,
+    1145                 :          0 :                            (uint8_t *)(cert_chain + 1));
+    1146         [ #  # ]:          0 :     if (!res) {
+    1147                 :          0 :         free(file_data);
+    1148                 :          0 :         free(cert_chain);
+    1149                 :          0 :         return res;
+    1150                 :            :     }
+    1151                 :          0 :     libspdm_copy_mem((uint8_t *)cert_chain + sizeof(spdm_cert_chain_t) + digest_size,
+    1152                 :          0 :                      cert_chain_size - (sizeof(spdm_cert_chain_t) + digest_size),
+    1153                 :            :                      file_data, file_size);
+    1154                 :            : 
+    1155                 :          0 :     *data = cert_chain;
+    1156                 :          0 :     *size = cert_chain_size;
+    1157         [ #  # ]:          0 :     if (hash != NULL) {
+    1158                 :          0 :         *hash = (cert_chain + 1);
+    1159                 :            :     }
+    1160         [ #  # ]:          0 :     if (hash_size != NULL) {
+    1161                 :          0 :         *hash_size = digest_size;
+    1162                 :            :     }
+    1163                 :            : 
+    1164                 :          0 :     free(file_data);
+    1165                 :          0 :     return true;
+    1166                 :            : }
+    1167                 :            : 
+    1168                 :          8 : bool libspdm_read_responder_public_certificate_chain_by_size(
+    1169                 :            :     uint32_t base_hash_algo, uint32_t base_asym_algo, uint16_t chain_id,
+    1170                 :            :     void **data, size_t *size, void **hash, size_t *hash_size)
+    1171                 :            : {
+    1172                 :            :     bool res;
+    1173                 :            :     void *file_data;
+    1174                 :            :     size_t file_size;
+    1175                 :            :     spdm_cert_chain_t *cert_chain;
+    1176                 :            :     size_t cert_chain_size;
+    1177                 :            :     char *file;
+    1178                 :            :     const uint8_t *root_cert;
+    1179                 :            :     size_t root_cert_len;
+    1180                 :            :     size_t digest_size;
+    1181                 :            :     bool is_requester_cert;
+    1182                 :            :     bool is_device_cert_model;
+    1183                 :            : 
+    1184                 :          8 :     is_requester_cert = false;
+    1185                 :            : 
+    1186                 :            :     /*defalut is true*/
+    1187                 :          8 :     is_device_cert_model = true;
+    1188                 :            : 
+    1189                 :          8 :     *data = NULL;
+    1190                 :          8 :     *size = 0;
+    1191         [ +  + ]:          8 :     if (hash != NULL) {
+    1192                 :          2 :         *hash = NULL;
+    1193                 :            :     }
+    1194         [ +  + ]:          8 :     if (hash_size != NULL) {
+    1195                 :          2 :         *hash_size = 0;
+    1196                 :            :     }
+    1197                 :            : 
+    1198   [ +  +  +  -  :          8 :     switch (chain_id) {
+                      - ]
+    1199                 :          3 :     case LIBSPDM_TEST_CERT_SMALL: /* data_size smaller than 1024 Bytes*/
+    1200                 :          3 :         file = "long_chains/Shorter1024B_bundle_responder.certchain.der";
+    1201                 :          3 :         break;
+    1202                 :          2 :     case LIBSPDM_TEST_CERT_MAXINT16: /* data_size slightly smaller than 0x7FFF*/
+    1203                 :          2 :         file = "long_chains/ShorterMAXINT16_bundle_responder.certchain.der";
+    1204                 :          2 :         break;
+    1205                 :          3 :     case LIBSPDM_TEST_CERT_MAXUINT16: /* data_size slightly smaller than 0xFFFF*/
+    1206                 :          3 :         file = "long_chains/ShorterMAXUINT16_bundle_responder.certchain.der";
+    1207                 :          3 :         break;
+    1208                 :          0 :     case LIBSPDM_LIBSPDM_TEST_CERT_MAXUINT16_LARGER: /* data_size larger than 0xFFFF*/
+    1209                 :          0 :         file = "long_chains/LongerMAXUINT16_bundle_responder.certchain.der";
+    1210                 :          0 :         break;
+    1211                 :          0 :     default:
+    1212                 :          0 :         LIBSPDM_ASSERT(false);
+    1213                 :          0 :         return false;
+    1214                 :            :     }
+    1215                 :          8 :     res = libspdm_read_input_file(file, &file_data, &file_size);
+    1216         [ -  + ]:          8 :     if (!res) {
+    1217                 :          0 :         return res;
+    1218                 :            :     }
+    1219                 :            : 
+    1220                 :          8 :     digest_size = libspdm_get_hash_size(base_hash_algo);
+    1221                 :            : 
+    1222                 :          8 :     cert_chain_size = sizeof(spdm_cert_chain_t) + digest_size + file_size;
+    1223                 :          8 :     cert_chain = (void *)malloc(cert_chain_size);
+    1224         [ -  + ]:          8 :     if (cert_chain == NULL) {
+    1225                 :          0 :         free(file_data);
+    1226                 :          0 :         return false;
+    1227                 :            :     }
+    1228                 :          8 :     cert_chain->length = (uint16_t)cert_chain_size;
+    1229                 :          8 :     cert_chain->reserved = 0;
+    1230                 :            : 
+    1231                 :          8 :     res = libspdm_verify_cert_chain_data(file_data, file_size,
+    1232                 :            :                                          base_asym_algo, base_hash_algo,
+    1233                 :            :                                          is_requester_cert, is_device_cert_model);
+    1234         [ -  + ]:          8 :     if (!res) {
+    1235                 :          0 :         free(file_data);
+    1236                 :          0 :         free(cert_chain);
+    1237                 :          0 :         return res;
+    1238                 :            :     }
+    1239                 :            : 
+    1240                 :            : 
+    1241                 :            :     /* Get Root Certificate and calculate hash value*/
+    1242                 :            : 
+    1243                 :          8 :     res = libspdm_x509_get_cert_from_cert_chain(file_data, file_size, 0, &root_cert,
+    1244                 :            :                                                 &root_cert_len);
+    1245         [ -  + ]:          8 :     if (!res) {
+    1246                 :          0 :         free(file_data);
+    1247                 :          0 :         free(cert_chain);
+    1248                 :          0 :         return res;
+    1249                 :            :     }
+    1250                 :            : 
+    1251                 :          8 :     res = libspdm_hash_all(base_hash_algo, root_cert, root_cert_len,
+    1252                 :          8 :                            (uint8_t *)(cert_chain + 1));
+    1253         [ -  + ]:          8 :     if (!res) {
+    1254                 :          0 :         free(file_data);
+    1255                 :          0 :         free(cert_chain);
+    1256                 :          0 :         return res;
+    1257                 :            :     }
+    1258                 :          8 :     libspdm_copy_mem((uint8_t *)cert_chain + sizeof(spdm_cert_chain_t) + digest_size,
+    1259                 :          8 :                      cert_chain_size - (sizeof(spdm_cert_chain_t) + digest_size),
+    1260                 :            :                      file_data, file_size);
+    1261                 :            : 
+    1262                 :          8 :     *data = cert_chain;
+    1263                 :          8 :     *size = cert_chain_size;
+    1264         [ +  + ]:          8 :     if (hash != NULL) {
+    1265                 :          2 :         *hash = (cert_chain + 1);
+    1266                 :            :     }
+    1267         [ +  + ]:          8 :     if (hash_size != NULL) {
+    1268                 :          2 :         *hash_size = digest_size;
+    1269                 :            :     }
+    1270                 :            : 
+    1271                 :          8 :     free(file_data);
+    1272                 :          8 :     return true;
+    1273                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/spdm_device_secret_lib_sample/index-sort-b.html b/coverage_log/os_stub/spdm_device_secret_lib_sample/index-sort-b.html new file mode 100644 index 00000000000..da5c5540796 --- /dev/null +++ b/coverage_log/os_stub/spdm_device_secret_lib_sample/index-sort-b.html @@ -0,0 +1,119 @@ + + + + + + + LCOV - coverage.info - os_stub/spdm_device_secret_lib_sample + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/spdm_device_secret_lib_sampleHitTotalCoverage
Test:coverage.infoLines:952192949.4 %
Date:2024-09-22 08:21:07Functions:444989.8 %
Branches:31674342.5 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
cert.c +
34.8%34.8%
+
34.8 %276 / 79270.0 %7 / 1033.8 %102 / 302
lib.c +
59.5%59.5%
+
59.5 %676 / 113794.9 %37 / 3948.5 %214 / 441
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/spdm_device_secret_lib_sample/index-sort-f.html b/coverage_log/os_stub/spdm_device_secret_lib_sample/index-sort-f.html new file mode 100644 index 00000000000..714946c9de1 --- /dev/null +++ b/coverage_log/os_stub/spdm_device_secret_lib_sample/index-sort-f.html @@ -0,0 +1,119 @@ + + + + + + + LCOV - coverage.info - os_stub/spdm_device_secret_lib_sample + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/spdm_device_secret_lib_sampleHitTotalCoverage
Test:coverage.infoLines:952192949.4 %
Date:2024-09-22 08:21:07Functions:444989.8 %
Branches:31674342.5 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
cert.c +
34.8%34.8%
+
34.8 %276 / 79270.0 %7 / 1033.8 %102 / 302
lib.c +
59.5%59.5%
+
59.5 %676 / 113794.9 %37 / 3948.5 %214 / 441
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/spdm_device_secret_lib_sample/index-sort-l.html b/coverage_log/os_stub/spdm_device_secret_lib_sample/index-sort-l.html new file mode 100644 index 00000000000..57098472ee0 --- /dev/null +++ b/coverage_log/os_stub/spdm_device_secret_lib_sample/index-sort-l.html @@ -0,0 +1,119 @@ + + + + + + + LCOV - coverage.info - os_stub/spdm_device_secret_lib_sample + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/spdm_device_secret_lib_sampleHitTotalCoverage
Test:coverage.infoLines:952192949.4 %
Date:2024-09-22 08:21:07Functions:444989.8 %
Branches:31674342.5 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
cert.c +
34.8%34.8%
+
34.8 %276 / 79270.0 %7 / 1033.8 %102 / 302
lib.c +
59.5%59.5%
+
59.5 %676 / 113794.9 %37 / 3948.5 %214 / 441
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/spdm_device_secret_lib_sample/index.html b/coverage_log/os_stub/spdm_device_secret_lib_sample/index.html new file mode 100644 index 00000000000..0ebbe8fc06b --- /dev/null +++ b/coverage_log/os_stub/spdm_device_secret_lib_sample/index.html @@ -0,0 +1,119 @@ + + + + + + + LCOV - coverage.info - os_stub/spdm_device_secret_lib_sample + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/spdm_device_secret_lib_sampleHitTotalCoverage
Test:coverage.infoLines:952192949.4 %
Date:2024-09-22 08:21:07Functions:444989.8 %
Branches:31674342.5 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
cert.c +
34.8%34.8%
+
34.8 %276 / 79270.0 %7 / 1033.8 %102 / 302
lib.c +
59.5%59.5%
+
59.5 %676 / 113794.9 %37 / 3948.5 %214 / 441
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/spdm_device_secret_lib_sample/lib.c.func-sort-c.html b/coverage_log/os_stub/spdm_device_secret_lib_sample/lib.c.func-sort-c.html new file mode 100644 index 00000000000..7d50bd9532e --- /dev/null +++ b/coverage_log/os_stub/spdm_device_secret_lib_sample/lib.c.func-sort-c.html @@ -0,0 +1,237 @@ + + + + + + + LCOV - coverage.info - os_stub/spdm_device_secret_lib_sample/lib.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/spdm_device_secret_lib_sample - lib.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:676113759.5 %
Date:2024-09-22 08:21:07Functions:373994.9 %
Branches:21444148.5 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_get_requester_private_key_from_raw_data0
libspdm_get_responder_private_key_from_raw_data0
libspdm_discard_all_cached_last_request1
libspdm_event_get_types1
libspdm_init_key_pair_info1
libspdm_event_subscribe2
libspdm_encap_challenge_opaque_data3
libspdm_cache_last_set_key_pair_info_request4
libspdm_read_cached_csr4
libspdm_read_requester_public_key4
libspdm_gen_csr_without_reset6
libspdm_read_responder_certificate6
libspdm_read_cached_last_set_key_pair_info_request7
libspdm_challenge_opaque_data8
libspdm_write_certificate_to_nvm8
libspdm_gen_csr10
libspdm_generate_measurement_summary_hash10
libspdm_write_key_pair_info10
libspdm_is_in_trusted_environment11
libspdm_measurement_extension_log_collection11
libspdm_cache_last_csr_request13
libspdm_read_responder_public_key13
libspdm_read_key_pair_info14
libspdm_fill_measurement_device_mode_block15
libspdm_fill_measurement_hem_block15
libspdm_fill_measurement_manifest_block15
libspdm_fill_measurement_svn_block15
libspdm_gen_csr_ex15
libspdm_read_cached_last_csr_request19
libspdm_read_requester_private_key24
libspdm_requester_data_sign24
libspdm_generate_mel26
libspdm_psk_master_secret_hkdf_expand33
libspdm_psk_handshake_secret_hkdf_expand71
libspdm_responder_data_sign121
libspdm_measurement_opaque_data122
libspdm_read_responder_private_key127
libspdm_measurement_collection137
libspdm_fill_measurement_image_hash_block170
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/spdm_device_secret_lib_sample/lib.c.func.html b/coverage_log/os_stub/spdm_device_secret_lib_sample/lib.c.func.html new file mode 100644 index 00000000000..cd7169329e7 --- /dev/null +++ b/coverage_log/os_stub/spdm_device_secret_lib_sample/lib.c.func.html @@ -0,0 +1,237 @@ + + + + + + + LCOV - coverage.info - os_stub/spdm_device_secret_lib_sample/lib.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/spdm_device_secret_lib_sample - lib.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:676113759.5 %
Date:2024-09-22 08:21:07Functions:373994.9 %
Branches:21444148.5 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_cache_last_csr_request13
libspdm_cache_last_set_key_pair_info_request4
libspdm_challenge_opaque_data8
libspdm_discard_all_cached_last_request1
libspdm_encap_challenge_opaque_data3
libspdm_event_get_types1
libspdm_event_subscribe2
libspdm_fill_measurement_device_mode_block15
libspdm_fill_measurement_hem_block15
libspdm_fill_measurement_image_hash_block170
libspdm_fill_measurement_manifest_block15
libspdm_fill_measurement_svn_block15
libspdm_gen_csr10
libspdm_gen_csr_ex15
libspdm_gen_csr_without_reset6
libspdm_generate_measurement_summary_hash10
libspdm_generate_mel26
libspdm_get_requester_private_key_from_raw_data0
libspdm_get_responder_private_key_from_raw_data0
libspdm_init_key_pair_info1
libspdm_is_in_trusted_environment11
libspdm_measurement_collection137
libspdm_measurement_extension_log_collection11
libspdm_measurement_opaque_data122
libspdm_psk_handshake_secret_hkdf_expand71
libspdm_psk_master_secret_hkdf_expand33
libspdm_read_cached_csr4
libspdm_read_cached_last_csr_request19
libspdm_read_cached_last_set_key_pair_info_request7
libspdm_read_key_pair_info14
libspdm_read_requester_private_key24
libspdm_read_requester_public_key4
libspdm_read_responder_certificate6
libspdm_read_responder_private_key127
libspdm_read_responder_public_key13
libspdm_requester_data_sign24
libspdm_responder_data_sign121
libspdm_write_certificate_to_nvm8
libspdm_write_key_pair_info10
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/os_stub/spdm_device_secret_lib_sample/lib.c.gcov.html b/coverage_log/os_stub/spdm_device_secret_lib_sample/lib.c.gcov.html new file mode 100644 index 00000000000..8a816a7afff --- /dev/null +++ b/coverage_log/os_stub/spdm_device_secret_lib_sample/lib.c.gcov.html @@ -0,0 +1,2735 @@ + + + + + + + LCOV - coverage.info - os_stub/spdm_device_secret_lib_sample/lib.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - os_stub/spdm_device_secret_lib_sample - lib.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:676113759.5 %
Date:2024-09-22 08:21:07Functions:373994.9 %
Branches:21444148.5 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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                 :            : /** @file
+       8                 :            :  * SPDM common library.
+       9                 :            :  * It follows the SPDM Specification.
+      10                 :            :  **/
+      11                 :            : #include <base.h>
+      12                 :            : #if defined(_WIN32) || (defined(__clang__) && (defined (LIBSPDM_CPU_AARCH64) || \
+      13                 :            :     defined(LIBSPDM_CPU_ARM)))
+      14                 :            : #else
+      15                 :            :     #include <fcntl.h>
+      16                 :            :     #include <unistd.h>
+      17                 :            :     #include <sys/stat.h>
+      18                 :            : #endif
+      19                 :            : #include <stdarg.h>
+      20                 :            : #include <stddef.h>
+      21                 :            : #include <setjmp.h>
+      22                 :            : #include <stdint.h>
+      23                 :            : #include <stdlib.h>
+      24                 :            : #include <stdio.h>
+      25                 :            : #include <assert.h>
+      26                 :            : #include <string.h>
+      27                 :            : 
+      28                 :            : #include "library/memlib.h"
+      29                 :            : #include "spdm_device_secret_lib_internal.h"
+      30                 :            : #include "raw_data_key.h"
+      31                 :            : #include "internal/libspdm_common_lib.h"
+      32                 :            : 
+      33                 :            : bool g_in_trusted_environment = false;
+      34                 :            : uint32_t g_supported_event_groups_list_len = 8;
+      35                 :            : uint8_t g_event_group_count = 1;
+      36                 :            : 
+      37                 :            : #if LIBSPDM_ENABLE_CAPABILITY_GET_KEY_PAIR_INFO_CAP
+      38                 :            : typedef struct {
+      39                 :            :     uint16_t capabilities;
+      40                 :            :     uint16_t key_usage_capabilities;
+      41                 :            :     uint16_t current_key_usage;
+      42                 :            :     uint32_t asym_algo_capabilities;
+      43                 :            :     uint32_t current_asym_algo;
+      44                 :            :     uint16_t public_key_info_len;
+      45                 :            :     uint8_t assoc_cert_slot_mask;
+      46                 :            :     uint8_t public_key_info[SPDM_MAX_PUBLIC_KEY_INFO_LEN];
+      47                 :            : } libspdm_key_pair_info_t;
+      48                 :            : 
+      49                 :            : #ifndef LIBSPDM_MAX_KEY_PAIR_COUNT
+      50                 :            : #define LIBSPDM_MAX_KEY_PAIR_COUNT 16
+      51                 :            : #endif
+      52                 :            : 
+      53                 :            : libspdm_key_pair_info_t m_key_pair_info[LIBSPDM_MAX_KEY_PAIR_COUNT];
+      54                 :            : 
+      55                 :            : bool g_need_init_key_pair_info = true;
+      56                 :            : #endif /*LIBSPDM_ENABLE_CAPABILITY_GET_KEY_PAIR_INFO_CAP*/
+      57                 :            : 
+      58                 :            : /* "LIBSPDM_PRIVATE_KEY_MODE_RAW_KEY_ONLY = 1" means use the RAW private key only
+      59                 :            :  * "LIBSPDM_PRIVATE_KEY_MODE_RAW_KEY_ONLY = 0" means controlled by g_private_key_mode
+      60                 :            :  **/
+      61                 :            : #define LIBSPDM_PRIVATE_KEY_MODE_RAW_KEY_ONLY 0
+      62                 :            : /* "g_private_key_mode = 1" means use the PEM mode
+      63                 :            :  * "g_private_key_mode = 0" means use the RAW mode
+      64                 :            :  **/
+      65                 :            : #if !LIBSPDM_PRIVATE_KEY_MODE_RAW_KEY_ONLY
+      66                 :            : bool g_private_key_mode = 1;
+      67                 :            : #endif
+      68                 :            : 
+      69                 :            : #if LIBSPDM_ECDSA_SUPPORT
+      70                 :            : uint8_t m_libspdm_ec256_responder_private_key[] = LIBSPDM_EC256_RESPONDER_PRIVATE_KEY;
+      71                 :            : uint8_t m_libspdm_ec256_responder_public_key[] = LIBSPDM_EC256_RESPONDER_PUBLIC_KEY;
+      72                 :            : 
+      73                 :            : uint8_t m_libspdm_ec384_responder_private_key[] = LIBSPDM_EC384_RESPONDER_PRIVATE_KEY;
+      74                 :            : uint8_t m_libspdm_ec384_responder_public_key[] = LIBSPDM_EC384_RESPONDER_PUBLIC_KEY;
+      75                 :            : 
+      76                 :            : uint8_t m_libspdm_ec521_responder_private_key[] = LIBSPDM_EC521_RESPONDER_PRIVATE_KEY;
+      77                 :            : uint8_t m_libspdm_ec521_responder_public_key[] = LIBSPDM_EC521_RESPONDER_PUBLIC_KEY;
+      78                 :            : 
+      79                 :            : uint8_t m_libspdm_ec256_requester_private_key[] = LIBSPDM_EC256_REQUESTER_PRIVATE_KEY;
+      80                 :            : uint8_t m_libspdm_ec256_requester_public_key[] = LIBSPDM_EC256_REQUESTER_PUBLIC_KEY;
+      81                 :            : 
+      82                 :            : uint8_t m_libspdm_ec384_requester_private_key[] = LIBSPDM_EC384_REQUESTER_PRIVATE_KEY;
+      83                 :            : uint8_t m_libspdm_ec384_requester_public_key[] = LIBSPDM_EC384_REQUESTER_PUBLIC_KEY;
+      84                 :            : 
+      85                 :            : uint8_t m_libspdm_ec521_requester_private_key[] = LIBSPDM_EC521_REQUESTER_PRIVATE_KEY;
+      86                 :            : uint8_t m_libspdm_ec521_requester_public_key[] = LIBSPDM_EC521_REQUESTER_PUBLIC_KEY;
+      87                 :            : #endif /*LIBSPDM_ECDSA_SUPPORT*/
+      88                 :            : 
+      89                 :            : #if (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT)
+      90                 :            : uint8_t m_libspdm_rsa2048_res_n[] = LIBSPDM_RSA2048_RES_N;
+      91                 :            : uint8_t m_libspdm_rsa2048_res_e[] = LIBSPDM_RSA2048_RES_E;
+      92                 :            : uint8_t m_libspdm_rsa2048_res_d[] = LIBSPDM_RSA2048_RES_D;
+      93                 :            : uint8_t m_libspdm_rsa3072_res_n[] = LIBSPDM_RSA3072_RES_N;
+      94                 :            : uint8_t m_libspdm_rsa3072_res_e[] = LIBSPDM_RSA3072_RES_E;
+      95                 :            : uint8_t m_libspdm_rsa3072_res_d[] = LIBSPDM_RSA3072_RES_D;
+      96                 :            : uint8_t m_libspdm_rsa4096_res_n[] = LIBSPDM_RSA4096_RES_N;
+      97                 :            : uint8_t m_libspdm_rsa4096_res_e[] = LIBSPDM_RSA4096_RES_E;
+      98                 :            : uint8_t m_libspdm_rsa4096_res_d[] = LIBSPDM_RSA4096_RES_D;
+      99                 :            : uint8_t m_libspdm_rsa2048_req_n[] = LIBSPDM_RSA2048_REQ_N;
+     100                 :            : uint8_t m_libspdm_rsa2048_req_e[] = LIBSPDM_RSA2048_REQ_E;
+     101                 :            : uint8_t m_libspdm_rsa2048_req_d[] = LIBSPDM_RSA2048_REQ_D;
+     102                 :            : uint8_t m_libspdm_rsa3072_req_n[] = LIBSPDM_RSA3072_REQ_N;
+     103                 :            : uint8_t m_libspdm_rsa3072_req_e[] = LIBSPDM_RSA3072_REQ_E;
+     104                 :            : uint8_t m_libspdm_rsa3072_req_d[] = LIBSPDM_RSA3072_REQ_D;
+     105                 :            : uint8_t m_libspdm_rsa4096_req_n[] = LIBSPDM_RSA4096_REQ_N;
+     106                 :            : uint8_t m_libspdm_rsa4096_req_e[] = LIBSPDM_RSA4096_REQ_E;
+     107                 :            : uint8_t m_libspdm_rsa4096_req_d[] = LIBSPDM_RSA4096_REQ_D;
+     108                 :            : #endif /* (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT) */
+     109                 :            : 
+     110                 :            : #if (LIBSPDM_ENABLE_CAPABILITY_MEL_CAP) || (LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP)
+     111                 :            : 
+     112                 :            : #define LIBSPDM_MAX_MEASUREMENT_EXTENSION_LOG_SIZE 0x1000
+     113                 :            : uint8_t m_libspdm_mel[LIBSPDM_MAX_MEASUREMENT_EXTENSION_LOG_SIZE];
+     114                 :            : 
+     115                 :            : #endif /* (LIBSPDM_ENABLE_CAPABILITY_MEL_CAP) || (LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP) */
+     116                 :            : 
+     117                 :          0 : bool libspdm_get_responder_private_key_from_raw_data(uint32_t base_asym_algo, void **context)
+     118                 :            : {
+     119                 :            : #if (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT) || (LIBSPDM_ECDSA_SUPPORT)
+     120                 :            :     bool result;
+     121                 :            : 
+     122                 :            : #if (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT)
+     123                 :            :     void *rsa_context;
+     124                 :            :     uint8_t *rsa_n;
+     125                 :            :     uint8_t *rsa_e;
+     126                 :            :     uint8_t *rsa_d;
+     127                 :            :     size_t rsa_n_size;
+     128                 :            :     size_t rsa_e_size;
+     129                 :            :     size_t rsa_d_size;
+     130                 :            : #endif /* (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT) */
+     131                 :            : 
+     132                 :            : #if LIBSPDM_ECDSA_SUPPORT
+     133                 :            :     void *ec_context;
+     134                 :            :     size_t ec_nid;
+     135                 :            :     uint8_t *ec_public;
+     136                 :            :     uint8_t *ec_private;
+     137                 :            :     size_t ec_public_size;
+     138                 :            :     size_t ec_private_size;
+     139                 :            : #endif /*LIBSPDM_ECDSA_SUPPORT*/
+     140                 :            : 
+     141   [ #  #  #  #  :          0 :     switch (base_asym_algo) {
+                #  #  # ]
+     142                 :            : #if (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT)
+     143                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
+     144                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048:
+     145                 :          0 :         rsa_n = m_libspdm_rsa2048_res_n;
+     146                 :          0 :         rsa_e = m_libspdm_rsa2048_res_e;
+     147                 :          0 :         rsa_d = m_libspdm_rsa2048_res_d;
+     148                 :          0 :         rsa_n_size = sizeof(m_libspdm_rsa2048_res_n);
+     149                 :          0 :         rsa_e_size = sizeof(m_libspdm_rsa2048_res_e);
+     150                 :          0 :         rsa_d_size = sizeof(m_libspdm_rsa2048_res_d);
+     151                 :          0 :         break;
+     152                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
+     153                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072:
+     154                 :          0 :         rsa_n = m_libspdm_rsa3072_res_n;
+     155                 :          0 :         rsa_e = m_libspdm_rsa3072_res_e;
+     156                 :          0 :         rsa_d = m_libspdm_rsa3072_res_d;
+     157                 :          0 :         rsa_n_size = sizeof(m_libspdm_rsa3072_res_n);
+     158                 :          0 :         rsa_e_size = sizeof(m_libspdm_rsa3072_res_e);
+     159                 :          0 :         rsa_d_size = sizeof(m_libspdm_rsa3072_res_d);
+     160                 :          0 :         break;
+     161                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
+     162                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096:
+     163                 :          0 :         rsa_n = m_libspdm_rsa4096_res_n;
+     164                 :          0 :         rsa_e = m_libspdm_rsa4096_res_e;
+     165                 :          0 :         rsa_d = m_libspdm_rsa4096_res_d;
+     166                 :          0 :         rsa_n_size = sizeof(m_libspdm_rsa4096_res_n);
+     167                 :          0 :         rsa_e_size = sizeof(m_libspdm_rsa4096_res_e);
+     168                 :          0 :         rsa_d_size = sizeof(m_libspdm_rsa4096_res_d);
+     169                 :          0 :         break;
+     170                 :            : #endif /* (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT) */
+     171                 :            : 
+     172                 :            : #if LIBSPDM_ECDSA_SUPPORT
+     173                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
+     174                 :          0 :         ec_nid = LIBSPDM_CRYPTO_NID_ECDSA_NIST_P256;
+     175                 :          0 :         ec_public = m_libspdm_ec256_responder_public_key;
+     176                 :          0 :         ec_private = m_libspdm_ec256_responder_private_key;
+     177                 :          0 :         ec_public_size = sizeof(m_libspdm_ec256_responder_public_key);
+     178                 :          0 :         ec_private_size = sizeof(m_libspdm_ec256_responder_private_key);
+     179                 :          0 :         break;
+     180                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
+     181                 :          0 :         ec_nid = LIBSPDM_CRYPTO_NID_ECDSA_NIST_P384;
+     182                 :          0 :         ec_public = m_libspdm_ec384_responder_public_key;
+     183                 :          0 :         ec_private = m_libspdm_ec384_responder_private_key;
+     184                 :          0 :         ec_public_size = sizeof(m_libspdm_ec384_responder_public_key);
+     185                 :          0 :         ec_private_size = sizeof(m_libspdm_ec384_responder_private_key);
+     186                 :          0 :         break;
+     187                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
+     188                 :          0 :         ec_nid = LIBSPDM_CRYPTO_NID_ECDSA_NIST_P521;
+     189                 :          0 :         ec_public = m_libspdm_ec521_responder_public_key;
+     190                 :          0 :         ec_private = m_libspdm_ec521_responder_private_key;
+     191                 :          0 :         ec_public_size = sizeof(m_libspdm_ec521_responder_public_key);
+     192                 :          0 :         ec_private_size = sizeof(m_libspdm_ec521_responder_private_key);
+     193                 :          0 :         break;
+     194                 :            : #endif /*LIBSPDM_ECDSA_SUPPORT*/
+     195                 :          0 :     default:
+     196                 :          0 :         LIBSPDM_ASSERT(false);
+     197                 :          0 :         return false;
+     198                 :            :     }
+     199                 :            : 
+     200      [ #  #  # ]:          0 :     switch (base_asym_algo) {
+     201                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
+     202                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048:
+     203                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
+     204                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072:
+     205                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
+     206                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096:
+     207                 :            : #if (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT)
+     208                 :          0 :         rsa_context = libspdm_rsa_new();
+     209         [ #  # ]:          0 :         if (rsa_context == NULL) {
+     210                 :          0 :             return false;
+     211                 :            :         }
+     212                 :          0 :         result = libspdm_rsa_set_key(rsa_context, LIBSPDM_RSA_KEY_N, rsa_n, rsa_n_size);
+     213         [ #  # ]:          0 :         if (!result) {
+     214                 :          0 :             libspdm_rsa_free(rsa_context);
+     215                 :          0 :             return false;
+     216                 :            :         }
+     217                 :          0 :         result = libspdm_rsa_set_key(rsa_context, LIBSPDM_RSA_KEY_E, rsa_e, rsa_e_size);
+     218         [ #  # ]:          0 :         if (!result) {
+     219                 :          0 :             libspdm_rsa_free(rsa_context);
+     220                 :          0 :             return false;
+     221                 :            :         }
+     222                 :          0 :         result = libspdm_rsa_set_key(rsa_context, LIBSPDM_RSA_KEY_D, rsa_d, rsa_d_size);
+     223         [ #  # ]:          0 :         if (!result) {
+     224                 :          0 :             libspdm_rsa_free(rsa_context);
+     225                 :          0 :             return false;
+     226                 :            :         }
+     227                 :          0 :         *context = rsa_context;
+     228                 :          0 :         return true;
+     229                 :            : #else
+     230                 :            :         LIBSPDM_ASSERT(false);
+     231                 :            :         return false;
+     232                 :            : #endif /* (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT) */
+     233                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
+     234                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
+     235                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
+     236                 :            : #if LIBSPDM_ECDSA_SUPPORT
+     237                 :          0 :         ec_context = libspdm_ec_new_by_nid(ec_nid);
+     238         [ #  # ]:          0 :         if (ec_context == NULL) {
+     239                 :          0 :             return false;
+     240                 :            :         }
+     241                 :          0 :         result = libspdm_ec_set_pub_key(ec_context, ec_public, ec_public_size);
+     242         [ #  # ]:          0 :         if (!result) {
+     243                 :          0 :             libspdm_ec_free(ec_context);
+     244                 :          0 :             return false;
+     245                 :            :         }
+     246                 :          0 :         result = libspdm_ec_set_priv_key(ec_context, ec_private, ec_private_size);
+     247         [ #  # ]:          0 :         if (!result) {
+     248                 :          0 :             libspdm_ec_free(ec_context);
+     249                 :          0 :             return false;
+     250                 :            :         }
+     251                 :          0 :         *context = ec_context;
+     252                 :          0 :         return true;
+     253                 :            : #else
+     254                 :            :         LIBSPDM_ASSERT(false);
+     255                 :            :         return false;
+     256                 :            : #endif /*#LIBSPDM_ECDSA_SUPPORT*/
+     257                 :            :     }
+     258                 :            : 
+     259                 :            : #endif /* (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT) || (LIBSPDM_ECDSA_SUPPORT) */
+     260                 :          0 :     return false;
+     261                 :            : }
+     262                 :            : 
+     263                 :          0 : bool libspdm_get_requester_private_key_from_raw_data(uint32_t base_asym_algo, void **context)
+     264                 :            : {
+     265                 :            : #if (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT) || (LIBSPDM_ECDSA_SUPPORT)
+     266                 :            :     bool result;
+     267                 :            : 
+     268                 :            : #if (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT)
+     269                 :            :     void *rsa_context;
+     270                 :            :     uint8_t *rsa_n;
+     271                 :            :     uint8_t *rsa_e;
+     272                 :            :     uint8_t *rsa_d;
+     273                 :            :     size_t rsa_n_size;
+     274                 :            :     size_t rsa_e_size;
+     275                 :            :     size_t rsa_d_size;
+     276                 :            : #endif /* (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT) */
+     277                 :            : 
+     278                 :            : #if LIBSPDM_ECDSA_SUPPORT
+     279                 :            :     void *ec_context;
+     280                 :            :     size_t ec_nid;
+     281                 :            :     uint8_t *ec_public;
+     282                 :            :     uint8_t *ec_private;
+     283                 :            :     size_t ec_public_size;
+     284                 :            :     size_t ec_private_size;
+     285                 :            : #endif /*LIBSPDM_ECDSA_SUPPORT*/
+     286                 :            : 
+     287   [ #  #  #  #  :          0 :     switch (base_asym_algo) {
+                #  #  # ]
+     288                 :            : #if (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT)
+     289                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
+     290                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048:
+     291                 :          0 :         rsa_n = m_libspdm_rsa2048_req_n;
+     292                 :          0 :         rsa_e = m_libspdm_rsa2048_req_e;
+     293                 :          0 :         rsa_d = m_libspdm_rsa2048_req_d;
+     294                 :          0 :         rsa_n_size = sizeof(m_libspdm_rsa2048_req_n);
+     295                 :          0 :         rsa_e_size = sizeof(m_libspdm_rsa2048_req_e);
+     296                 :          0 :         rsa_d_size = sizeof(m_libspdm_rsa2048_req_d);
+     297                 :          0 :         break;
+     298                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
+     299                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072:
+     300                 :          0 :         rsa_n = m_libspdm_rsa3072_req_n;
+     301                 :          0 :         rsa_e = m_libspdm_rsa3072_req_e;
+     302                 :          0 :         rsa_d = m_libspdm_rsa3072_req_d;
+     303                 :          0 :         rsa_n_size = sizeof(m_libspdm_rsa3072_req_n);
+     304                 :          0 :         rsa_e_size = sizeof(m_libspdm_rsa3072_req_e);
+     305                 :          0 :         rsa_d_size = sizeof(m_libspdm_rsa3072_req_d);
+     306                 :          0 :         break;
+     307                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
+     308                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096:
+     309                 :          0 :         rsa_n = m_libspdm_rsa4096_req_n;
+     310                 :          0 :         rsa_e = m_libspdm_rsa4096_req_e;
+     311                 :          0 :         rsa_d = m_libspdm_rsa4096_req_d;
+     312                 :          0 :         rsa_n_size = sizeof(m_libspdm_rsa4096_req_n);
+     313                 :          0 :         rsa_e_size = sizeof(m_libspdm_rsa4096_req_e);
+     314                 :          0 :         rsa_d_size = sizeof(m_libspdm_rsa4096_req_d);
+     315                 :          0 :         break;
+     316                 :            : #endif /* (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT) */
+     317                 :            : 
+     318                 :            : #if LIBSPDM_ECDSA_SUPPORT
+     319                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
+     320                 :          0 :         ec_nid = LIBSPDM_CRYPTO_NID_ECDSA_NIST_P256;
+     321                 :          0 :         ec_public = m_libspdm_ec256_requester_public_key;
+     322                 :          0 :         ec_private = m_libspdm_ec256_requester_private_key;
+     323                 :          0 :         ec_public_size = sizeof(m_libspdm_ec256_requester_public_key);
+     324                 :          0 :         ec_private_size = sizeof(m_libspdm_ec256_requester_private_key);
+     325                 :          0 :         break;
+     326                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
+     327                 :          0 :         ec_nid = LIBSPDM_CRYPTO_NID_ECDSA_NIST_P384;
+     328                 :          0 :         ec_public = m_libspdm_ec384_requester_public_key;
+     329                 :          0 :         ec_private = m_libspdm_ec384_requester_private_key;
+     330                 :          0 :         ec_public_size = sizeof(m_libspdm_ec384_requester_public_key);
+     331                 :          0 :         ec_private_size = sizeof(m_libspdm_ec384_requester_private_key);
+     332                 :          0 :         break;
+     333                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
+     334                 :          0 :         ec_nid = LIBSPDM_CRYPTO_NID_ECDSA_NIST_P521;
+     335                 :          0 :         ec_public = m_libspdm_ec521_requester_public_key;
+     336                 :          0 :         ec_private = m_libspdm_ec521_requester_private_key;
+     337                 :          0 :         ec_public_size = sizeof(m_libspdm_ec521_requester_public_key);
+     338                 :          0 :         ec_private_size = sizeof(m_libspdm_ec521_requester_private_key);
+     339                 :          0 :         break;
+     340                 :            : #endif /*LIBSPDM_ECDSA_SUPPORT*/
+     341                 :          0 :     default:
+     342                 :          0 :         LIBSPDM_ASSERT(false);
+     343                 :          0 :         return false;
+     344                 :            :     }
+     345                 :            : 
+     346      [ #  #  # ]:          0 :     switch (base_asym_algo) {
+     347                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
+     348                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048:
+     349                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
+     350                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072:
+     351                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
+     352                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096:
+     353                 :            : #if (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT)
+     354                 :          0 :         rsa_context = libspdm_rsa_new();
+     355         [ #  # ]:          0 :         if (rsa_context == NULL) {
+     356                 :          0 :             return false;
+     357                 :            :         }
+     358                 :          0 :         result = libspdm_rsa_set_key(rsa_context, LIBSPDM_RSA_KEY_N, rsa_n, rsa_n_size);
+     359         [ #  # ]:          0 :         if (!result) {
+     360                 :          0 :             libspdm_rsa_free(rsa_context);
+     361                 :          0 :             return false;
+     362                 :            :         }
+     363                 :          0 :         result = libspdm_rsa_set_key(rsa_context, LIBSPDM_RSA_KEY_E, rsa_e, rsa_e_size);
+     364         [ #  # ]:          0 :         if (!result) {
+     365                 :          0 :             libspdm_rsa_free(rsa_context);
+     366                 :          0 :             return false;
+     367                 :            :         }
+     368                 :          0 :         result = libspdm_rsa_set_key(rsa_context, LIBSPDM_RSA_KEY_D, rsa_d, rsa_d_size);
+     369         [ #  # ]:          0 :         if (!result) {
+     370                 :          0 :             libspdm_rsa_free(rsa_context);
+     371                 :          0 :             return false;
+     372                 :            :         }
+     373                 :          0 :         *context = rsa_context;
+     374                 :          0 :         return true;
+     375                 :            : #else
+     376                 :            :         LIBSPDM_ASSERT(false);
+     377                 :            :         return false;
+     378                 :            : #endif /* (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT) */
+     379                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
+     380                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
+     381                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
+     382                 :            : #if LIBSPDM_ECDSA_SUPPORT
+     383                 :          0 :         ec_context = libspdm_ec_new_by_nid(ec_nid);
+     384         [ #  # ]:          0 :         if (ec_context == NULL) {
+     385                 :          0 :             return false;
+     386                 :            :         }
+     387                 :          0 :         result = libspdm_ec_set_pub_key(ec_context, ec_public, ec_public_size);
+     388         [ #  # ]:          0 :         if (!result) {
+     389                 :          0 :             libspdm_ec_free(ec_context);
+     390                 :          0 :             return false;
+     391                 :            :         }
+     392                 :          0 :         result = libspdm_ec_set_priv_key(ec_context, ec_private, ec_private_size);
+     393         [ #  # ]:          0 :         if (!result) {
+     394                 :          0 :             libspdm_ec_free(ec_context);
+     395                 :          0 :             return false;
+     396                 :            :         }
+     397                 :          0 :         *context = ec_context;
+     398                 :          0 :         return true;
+     399                 :            : #else
+     400                 :            :         LIBSPDM_ASSERT(false);
+     401                 :            :         return false;
+     402                 :            : #endif /*#LIBSPDM_ECDSA_SUPPORT*/
+     403                 :            :     }
+     404                 :            : 
+     405                 :            : #endif /* (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT) || (LIBSPDM_ECDSA_SUPPORT) */
+     406                 :          0 :     return false;
+     407                 :            : }
+     408                 :            : 
+     409                 :            : #if !LIBSPDM_PRIVATE_KEY_MODE_RAW_KEY_ONLY
+     410                 :        127 : bool libspdm_read_responder_private_key(uint32_t base_asym_algo,
+     411                 :            :                                         void **data, size_t *size)
+     412                 :            : {
+     413                 :            :     bool res;
+     414                 :            :     char *file;
+     415                 :            : 
+     416   [ -  -  -  +  :        127 :     switch (base_asym_algo) {
+          -  -  -  -  -  
+                      - ]
+     417                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
+     418                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048:
+     419                 :          0 :         file = "rsa2048/end_responder.key";
+     420                 :          0 :         break;
+     421                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
+     422                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072:
+     423                 :          0 :         file = "rsa3072/end_responder.key";
+     424                 :          0 :         break;
+     425                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
+     426                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096:
+     427                 :          0 :         file = "rsa4096/end_responder.key";
+     428                 :          0 :         break;
+     429                 :        127 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
+     430                 :        127 :         file = "ecp256/end_responder.key";
+     431                 :        127 :         break;
+     432                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
+     433                 :          0 :         file = "ecp384/end_responder.key";
+     434                 :          0 :         break;
+     435                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
+     436                 :          0 :         file = "ecp521/end_responder.key";
+     437                 :          0 :         break;
+     438                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256:
+     439                 :          0 :         file = "sm2/end_responder.key";
+     440                 :          0 :         break;
+     441                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
+     442                 :          0 :         file = "ed25519/end_responder.key";
+     443                 :          0 :         break;
+     444                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
+     445                 :          0 :         file = "ed448/end_responder.key";
+     446                 :          0 :         break;
+     447                 :          0 :     default:
+     448                 :          0 :         LIBSPDM_ASSERT(false);
+     449                 :          0 :         return false;
+     450                 :            :     }
+     451                 :        127 :     res = libspdm_read_input_file(file, data, size);
+     452                 :        127 :     return res;
+     453                 :            : }
+     454                 :            : #endif
+     455                 :            : 
+     456                 :          6 : bool libspdm_read_responder_certificate(uint32_t base_asym_algo,
+     457                 :            :                                         void **data, size_t *size)
+     458                 :            : {
+     459                 :            :     bool res;
+     460                 :            :     char *file;
+     461                 :            : 
+     462   [ -  -  -  +  :          6 :     switch (base_asym_algo) {
+          -  -  -  -  -  
+                      - ]
+     463                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
+     464                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048:
+     465                 :          0 :         file = "rsa2048/end_responder.cert.der";
+     466                 :          0 :         break;
+     467                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
+     468                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072:
+     469                 :          0 :         file = "rsa3072/end_responder.cert.der";
+     470                 :          0 :         break;
+     471                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
+     472                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096:
+     473                 :          0 :         file = "rsa4096/end_responder.cert.der";
+     474                 :          0 :         break;
+     475                 :          6 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
+     476                 :          6 :         file = "ecp256/end_responder.cert.der";
+     477                 :          6 :         break;
+     478                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
+     479                 :          0 :         file = "ecp384/end_responder.cert.der";
+     480                 :          0 :         break;
+     481                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
+     482                 :          0 :         file = "ecp521/end_responder.cert.der";
+     483                 :          0 :         break;
+     484                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256:
+     485                 :          0 :         file = "sm2/end_responder.cert.der";
+     486                 :          0 :         break;
+     487                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
+     488                 :          0 :         file = "ed25519/end_responder.cert.der";
+     489                 :          0 :         break;
+     490                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
+     491                 :          0 :         file = "ed448/end_responder.cert.der";
+     492                 :          0 :         break;
+     493                 :          0 :     default:
+     494                 :          0 :         LIBSPDM_ASSERT(false);
+     495                 :          0 :         return false;
+     496                 :            :     }
+     497                 :          6 :     res = libspdm_read_input_file(file, data, size);
+     498                 :          6 :     return res;
+     499                 :            : }
+     500                 :            : 
+     501                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP
+     502                 :         24 : bool libspdm_read_requester_private_key(uint16_t req_base_asym_alg,
+     503                 :            :                                         void **data, size_t *size)
+     504                 :            : {
+     505                 :            :     bool res;
+     506                 :            :     char *file;
+     507                 :            : 
+     508   [ +  -  -  -  :         24 :     switch (req_base_asym_alg) {
+          -  -  -  -  -  
+                      - ]
+     509                 :         24 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
+     510                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048:
+     511                 :         24 :         file = "rsa2048/end_requester.key";
+     512                 :         24 :         break;
+     513                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
+     514                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072:
+     515                 :          0 :         file = "rsa3072/end_requester.key";
+     516                 :          0 :         break;
+     517                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
+     518                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096:
+     519                 :          0 :         file = "rsa4096/end_requester.key";
+     520                 :          0 :         break;
+     521                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
+     522                 :          0 :         file = "ecp256/end_requester.key";
+     523                 :          0 :         break;
+     524                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
+     525                 :          0 :         file = "ecp384/end_requester.key";
+     526                 :          0 :         break;
+     527                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
+     528                 :          0 :         file = "ecp521/end_requester.key";
+     529                 :          0 :         break;
+     530                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256:
+     531                 :          0 :         file = "sm2/end_requester.key";
+     532                 :          0 :         break;
+     533                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
+     534                 :          0 :         file = "ed25519/end_requester.key";
+     535                 :          0 :         break;
+     536                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
+     537                 :          0 :         file = "ed448/end_requester.key";
+     538                 :          0 :         break;
+     539                 :          0 :     default:
+     540                 :          0 :         LIBSPDM_ASSERT(false);
+     541                 :          0 :         return false;
+     542                 :            :     }
+     543                 :         24 :     res = libspdm_read_input_file(file, data, size);
+     544                 :         24 :     return res;
+     545                 :            : }
+     546                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP */
+     547                 :            : 
+     548                 :         13 : bool libspdm_read_responder_public_key(uint32_t base_asym_algo,
+     549                 :            :                                        void **data, size_t *size)
+     550                 :            : {
+     551                 :            :     bool res;
+     552                 :            :     char *file;
+     553                 :            : 
+     554   [ -  -  -  +  :         13 :     switch (base_asym_algo) {
+          -  -  -  -  -  
+                      - ]
+     555                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
+     556                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048:
+     557                 :          0 :         file = "rsa2048/end_responder.key.pub.der";
+     558                 :          0 :         break;
+     559                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
+     560                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072:
+     561                 :          0 :         file = "rsa3072/end_responder.key.pub.der";
+     562                 :          0 :         break;
+     563                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
+     564                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096:
+     565                 :          0 :         file = "rsa4096/end_responder.key.pub.der";
+     566                 :          0 :         break;
+     567                 :         13 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
+     568                 :         13 :         file = "ecp256/end_responder.key.pub.der";
+     569                 :         13 :         break;
+     570                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
+     571                 :          0 :         file = "ecp384/end_responder.key.pub.der";
+     572                 :          0 :         break;
+     573                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
+     574                 :          0 :         file = "ecp521/end_responder.key.pub.der";
+     575                 :          0 :         break;
+     576                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256:
+     577                 :          0 :         file = "sm2/end_responder.key.pub.der";
+     578                 :          0 :         break;
+     579                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
+     580                 :          0 :         file = "ed25519/end_responder.key.pub.der";
+     581                 :          0 :         break;
+     582                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
+     583                 :          0 :         file = "ed448/end_responder.key.pub.der";
+     584                 :          0 :         break;
+     585                 :          0 :     default:
+     586                 :          0 :         LIBSPDM_ASSERT(false);
+     587                 :          0 :         return false;
+     588                 :            :     }
+     589                 :         13 :     res = libspdm_read_input_file(file, data, size);
+     590                 :         13 :     return res;
+     591                 :            : }
+     592                 :            : 
+     593                 :          4 : bool libspdm_read_requester_public_key(uint16_t req_base_asym_alg,
+     594                 :            :                                        void **data, size_t *size)
+     595                 :            : {
+     596                 :            :     bool res;
+     597                 :            :     char *file;
+     598                 :            : 
+     599   [ +  -  -  -  :          4 :     switch (req_base_asym_alg) {
+          -  -  -  -  -  
+                      - ]
+     600                 :          4 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
+     601                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048:
+     602                 :          4 :         file = "rsa2048/end_requester.key.pub.der";
+     603                 :          4 :         break;
+     604                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
+     605                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072:
+     606                 :          0 :         file = "rsa3072/end_requester.key.pub.der";
+     607                 :          0 :         break;
+     608                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
+     609                 :            :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096:
+     610                 :          0 :         file = "rsa4096/end_requester.key.pub.der";
+     611                 :          0 :         break;
+     612                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
+     613                 :          0 :         file = "ecp256/end_requester.key.pub.der";
+     614                 :          0 :         break;
+     615                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
+     616                 :          0 :         file = "ecp384/end_requester.key.pub.der";
+     617                 :          0 :         break;
+     618                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
+     619                 :          0 :         file = "ecp521/end_requester.key.pub.der";
+     620                 :          0 :         break;
+     621                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256:
+     622                 :          0 :         file = "sm2/end_requester.key.pub.der";
+     623                 :          0 :         break;
+     624                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
+     625                 :          0 :         file = "ed25519/end_requester.key.pub.der";
+     626                 :          0 :         break;
+     627                 :          0 :     case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
+     628                 :          0 :         file = "ed448/end_requester.key.pub.der";
+     629                 :          0 :         break;
+     630                 :          0 :     default:
+     631                 :          0 :         LIBSPDM_ASSERT(false);
+     632                 :          0 :         return false;
+     633                 :            :     }
+     634                 :          4 :     res = libspdm_read_input_file(file, data, size);
+     635                 :          4 :     return res;
+     636                 :            : }
+     637                 :            : 
+     638                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CSR_CAP
+     639                 :         19 : bool libspdm_read_cached_last_csr_request(uint8_t **last_csr_request,
+     640                 :            :                                           size_t *last_csr_request_len,
+     641                 :            :                                           uint8_t req_csr_tracking_tag,
+     642                 :            :                                           uint8_t *available_rsp_csr_tracking_tag)
+     643                 :            : {
+     644                 :            :     bool res;
+     645                 :            :     uint8_t index;
+     646                 :            :     size_t file_size;
+     647                 :            :     uint8_t *file_data;
+     648                 :            : 
+     649                 :         19 :     file_data = NULL;
+     650                 :         19 :     *available_rsp_csr_tracking_tag = 0;
+     651                 :         19 :     char file[] = "cached_last_csr_x_request";
+     652                 :            :     /*change the file name, for example: cached_last_csr_1_request*/
+     653                 :         19 :     file[16] = (char)(req_csr_tracking_tag + '0');
+     654                 :         19 :     res = libspdm_read_input_file(file, (void **)last_csr_request, last_csr_request_len);
+     655                 :            : 
+     656         [ +  + ]:        152 :     for (index = 1; index <= SPDM_MAX_CSR_TRACKING_TAG; index++) {
+     657                 :        133 :         file[16] = (char)(index + '0');
+     658                 :        133 :         libspdm_read_input_file(file, (void **)(&file_data), &file_size);
+     659         [ +  + ]:        133 :         if (file_size == 0) {
+     660                 :         85 :             *available_rsp_csr_tracking_tag |=  (1 << index);
+     661                 :            :         } else {
+     662         [ +  + ]:         48 :             if (file_data != NULL) {
+     663                 :         35 :                 free(file_data);
+     664                 :            :             }
+     665                 :            :         }
+     666                 :            :     }
+     667                 :            : 
+     668                 :         19 :     return res;
+     669                 :            : }
+     670                 :            : 
+     671                 :         13 : bool libspdm_cache_last_csr_request(const uint8_t *last_csr_request,
+     672                 :            :                                     size_t last_csr_request_len,
+     673                 :            :                                     uint8_t req_csr_tracking_tag)
+     674                 :            : {
+     675                 :            :     bool res;
+     676                 :            : 
+     677                 :         13 :     char file[] = "cached_last_csr_x_request";
+     678                 :            :     /*change the file name, for example: cached_last_csr_1_request*/
+     679                 :         13 :     file[16] = (char)(req_csr_tracking_tag + '0');
+     680                 :         13 :     res = libspdm_write_output_file(file, last_csr_request, last_csr_request_len);
+     681                 :            : 
+     682                 :         13 :     return res;
+     683                 :            : }
+     684                 :            : 
+     685                 :            : /*clean the cached last SPDM csr request*/
+     686                 :          1 : bool libspdm_discard_all_cached_last_request()
+     687                 :            : {
+     688                 :            :     uint8_t index;
+     689                 :            : 
+     690                 :          1 :     char file[] = "cached_last_csr_x_request";
+     691                 :            : 
+     692         [ +  + ]:          8 :     for (index = 1; index <= SPDM_MAX_CSR_TRACKING_TAG; index++) {
+     693                 :          7 :         file[16] = (char)(index + '0');
+     694         [ -  + ]:          7 :         if (!libspdm_write_output_file(file, NULL, 0)) {
+     695                 :          0 :             return false;
+     696                 :            :         }
+     697                 :            :     }
+     698                 :            : 
+     699                 :          1 :     return true;
+     700                 :            : }
+     701                 :            : 
+     702                 :            : /*
+     703                 :            :  * return true represent that: the device complete the csr by reset successfully
+     704                 :            :  * return false represent that: the device complete the csr need reset
+     705                 :            :  **/
+     706                 :          4 : bool libspdm_read_cached_csr(uint8_t **csr_pointer, size_t *csr_len)
+     707                 :            : {
+     708                 :            :     bool res;
+     709                 :            :     char *file;
+     710                 :            : 
+     711                 :          4 :     file = "test_csr/cached.csr";
+     712                 :            : 
+     713                 :          4 :     res = libspdm_read_input_file(file, (void **)csr_pointer, csr_len);
+     714                 :          4 :     return res;
+     715                 :            : }
+     716                 :            : 
+     717                 :          6 : bool libspdm_gen_csr_without_reset(uint32_t base_hash_algo, uint32_t base_asym_algo,
+     718                 :            :                                    uint8_t *requester_info, size_t requester_info_length,
+     719                 :            :                                    uint8_t *opaque_data, uint16_t opaque_data_length,
+     720                 :            :                                    size_t *csr_len, uint8_t *csr_pointer,
+     721                 :            :                                    bool is_device_cert_model)
+     722                 :            : {
+     723                 :            :     bool result;
+     724                 :            :     size_t hash_nid;
+     725                 :            :     size_t asym_nid;
+     726                 :            :     void *context;
+     727                 :            :     size_t csr_buffer_size;
+     728                 :            : 
+     729                 :          6 :     csr_buffer_size = *csr_len;
+     730                 :            : 
+     731                 :            : #if !LIBSPDM_PRIVATE_KEY_MODE_RAW_KEY_ONLY
+     732         [ +  - ]:          6 :     if (g_private_key_mode) {
+     733                 :            :         void *x509_ca_cert;
+     734                 :            :         void *prikey, *cert;
+     735                 :            :         size_t prikey_size, cert_size;
+     736                 :            : 
+     737                 :          6 :         result = libspdm_read_responder_private_key(
+     738                 :            :             base_asym_algo, &prikey, &prikey_size);
+     739         [ -  + ]:          6 :         if (!result) {
+     740                 :          0 :             return false;
+     741                 :            :         }
+     742                 :            : 
+     743                 :          6 :         result = libspdm_read_responder_certificate(
+     744                 :            :             base_asym_algo, &cert, &cert_size);
+     745         [ -  + ]:          6 :         if (!result) {
+     746                 :          0 :             return false;
+     747                 :            :         }
+     748                 :            : 
+     749                 :          6 :         result = libspdm_x509_construct_certificate(cert, cert_size,
+     750                 :            :                                                     (uint8_t **)&x509_ca_cert);
+     751   [ +  -  -  + ]:          6 :         if ((x509_ca_cert == NULL) || (!result)) {
+     752                 :          0 :             return false;
+     753                 :            :         }
+     754                 :            : 
+     755                 :          6 :         result = libspdm_asym_get_private_key_from_pem(
+     756                 :            :             base_asym_algo, prikey, prikey_size, NULL, &context);
+     757         [ -  + ]:          6 :         if (!result) {
+     758                 :          0 :             libspdm_zero_mem(prikey, prikey_size);
+     759                 :          0 :             free(prikey);
+     760                 :          0 :             return false;
+     761                 :            :         }
+     762                 :          6 :         hash_nid = libspdm_get_hash_nid(base_hash_algo);
+     763                 :          6 :         asym_nid = libspdm_get_aysm_nid(base_asym_algo);
+     764                 :            : 
+     765                 :          6 :         char *subject_name = "C=NL,O=PolarSSL,CN=PolarSSL Server 1";
+     766                 :            : 
+     767                 :          6 :         result = libspdm_gen_x509_csr(hash_nid, asym_nid,
+     768                 :            :                                       requester_info, requester_info_length,
+     769                 :          6 :                                       !is_device_cert_model,
+     770                 :            :                                       context, subject_name,
+     771                 :            :                                       csr_len, csr_pointer,
+     772                 :          6 :                                       x509_ca_cert);
+     773                 :          6 :         libspdm_asym_free(base_asym_algo, context);
+     774                 :          6 :         libspdm_zero_mem(prikey, prikey_size);
+     775                 :          6 :         free(prikey);
+     776                 :          6 :         free(cert);
+     777                 :            :     } else {
+     778                 :            : #endif
+     779                 :            :     void *x509_ca_cert;
+     780                 :            :     void *cert;
+     781                 :            :     size_t cert_size;
+     782                 :            : 
+     783                 :          0 :     result = libspdm_get_responder_private_key_from_raw_data(base_asym_algo, &context);
+     784         [ #  # ]:          0 :     if (!result) {
+     785                 :          0 :         return false;
+     786                 :            :     }
+     787                 :            : 
+     788                 :          0 :     result = libspdm_read_responder_certificate(
+     789                 :            :         base_asym_algo, &cert, &cert_size);
+     790         [ #  # ]:          0 :     if (!result) {
+     791                 :          0 :         return false;
+     792                 :            :     }
+     793                 :            : 
+     794                 :          0 :     result = libspdm_x509_construct_certificate(cert, cert_size,
+     795                 :            :                                                 (uint8_t **)&x509_ca_cert);
+     796   [ #  #  #  # ]:          0 :     if ((x509_ca_cert == NULL) || (!result)) {
+     797                 :          0 :         return false;
+     798                 :            :     }
+     799                 :            : 
+     800                 :          0 :     hash_nid = libspdm_get_hash_nid(base_hash_algo);
+     801                 :          0 :     asym_nid = libspdm_get_aysm_nid(base_asym_algo);
+     802                 :            : 
+     803                 :          0 :     char *subject_name = "C=NL,O=PolarSSL,CN=PolarSSL Server 1";
+     804                 :            : 
+     805                 :          0 :     result = libspdm_gen_x509_csr(hash_nid, asym_nid,
+     806                 :            :                                   requester_info, requester_info_length,
+     807                 :          0 :                                   !is_device_cert_model,
+     808                 :            :                                   context, subject_name,
+     809                 :            :                                   csr_len, csr_pointer,
+     810                 :          0 :                                   x509_ca_cert);
+     811                 :          0 :     libspdm_asym_free(base_asym_algo, context);
+     812                 :          0 :     free(cert);
+     813                 :            : #if !LIBSPDM_PRIVATE_KEY_MODE_RAW_KEY_ONLY
+     814                 :            : }
+     815                 :            : #endif
+     816                 :            : 
+     817         [ -  + ]:          6 :     if (csr_buffer_size < *csr_len) {
+     818                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,"csr buffer is too small to store generated csr! \n"));
+     819                 :          0 :         result = false;
+     820                 :            :     }
+     821                 :          6 :     return result;
+     822                 :            : }
+     823                 :            : 
+     824                 :         10 : bool libspdm_gen_csr(
+     825                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+     826                 :            :     void *spdm_context,
+     827                 :            : #endif
+     828                 :            :     uint32_t base_hash_algo, uint32_t base_asym_algo, bool *need_reset,
+     829                 :            :     const void *request, size_t request_size,
+     830                 :            :     uint8_t *requester_info, size_t requester_info_length,
+     831                 :            :     uint8_t *opaque_data, uint16_t opaque_data_length,
+     832                 :            :     size_t *csr_len, uint8_t *csr_pointer,
+     833                 :            :     bool is_device_cert_model)
+     834                 :            : {
+     835                 :            :     bool result;
+     836                 :            :     uint8_t *cached_last_csr_request;
+     837                 :            :     size_t cached_last_request_len;
+     838                 :            :     uint8_t *cached_csr;
+     839                 :            :     size_t csr_buffer_size;
+     840                 :            :     uint8_t rsp_csr_tracking_tag;
+     841                 :            : 
+     842                 :         10 :     csr_buffer_size = *csr_len;
+     843                 :            : 
+     844                 :            :     /*device gen csr need reset*/
+     845         [ +  + ]:         10 :     if (*need_reset) {
+     846                 :          4 :         result = libspdm_read_cached_last_csr_request(&cached_last_csr_request,
+     847                 :            :                                                       &cached_last_request_len,
+     848                 :            :                                                       1, &rsp_csr_tracking_tag);
+     849                 :            : 
+     850                 :            :         /*get the cached last csr request and csr*/
+     851         [ +  + ]:          4 :         if ((result) &&
+     852   [ +  +  +  - ]:          5 :             (cached_last_request_len == request_size) &&
+     853                 :          2 :             (libspdm_consttime_is_mem_equal(cached_last_csr_request, request,
+     854         [ +  + ]:          2 :                                             request_size)) &&
+     855                 :          2 :             (libspdm_read_cached_csr(&cached_csr, csr_len)) &&
+     856         [ +  - ]:          1 :             (*csr_len != 0)) {
+     857                 :            : 
+     858                 :            :             /*get and save cached csr*/
+     859         [ -  + ]:          1 :             if (csr_buffer_size < *csr_len) {
+     860                 :          0 :                 free(cached_csr);
+     861                 :          0 :                 free(cached_last_csr_request);
+     862                 :          0 :                 LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+     863                 :            :                                "csr buffer is too small to store cached csr! \n"));
+     864                 :          0 :                 return false;
+     865                 :            :             } else {
+     866                 :          1 :                 libspdm_copy_mem(csr_pointer, csr_buffer_size, cached_csr, *csr_len);
+     867                 :            :             }
+     868                 :            : 
+     869                 :            :             /*device don't need reset this time*/
+     870                 :          1 :             *need_reset = false;
+     871                 :            : 
+     872                 :          1 :             free(cached_csr);
+     873                 :          1 :             free(cached_last_csr_request);
+     874                 :          1 :             return true;
+     875                 :            :         } else {
+     876         [ +  + ]:          3 :             if (cached_last_csr_request != NULL) {
+     877                 :          2 :                 free(cached_last_csr_request);
+     878                 :            :             }
+     879                 :            : 
+     880                 :            :             /*device need reset this time: cache the last_csr_request */
+     881                 :          3 :             result = libspdm_cache_last_csr_request(request, request_size, 1);
+     882         [ -  + ]:          3 :             if (!result) {
+     883                 :          0 :                 return result;
+     884                 :            :             }
+     885                 :            : 
+     886                 :            :             /*device need reset this time*/
+     887                 :          3 :             *need_reset = true;
+     888                 :          3 :             return true;
+     889                 :            :         }
+     890                 :            :     } else {
+     891                 :          6 :         result = libspdm_gen_csr_without_reset(base_hash_algo, base_asym_algo,
+     892                 :            :                                                requester_info, requester_info_length,
+     893                 :            :                                                opaque_data, opaque_data_length,
+     894                 :            :                                                csr_len, csr_pointer, is_device_cert_model);
+     895                 :          6 :         return result;
+     896                 :            :     }
+     897                 :            : 
+     898                 :            : }
+     899                 :            : 
+     900                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CSR_CAP_EX
+     901                 :         15 : bool libspdm_gen_csr_ex(
+     902                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+     903                 :            :     void *spdm_context,
+     904                 :            : #endif
+     905                 :            :     uint32_t base_hash_algo, uint32_t base_asym_algo, bool *need_reset,
+     906                 :            :     const void *request, size_t request_size,
+     907                 :            :     uint8_t *requester_info, size_t requester_info_length,
+     908                 :            :     uint8_t *opaque_data, uint16_t opaque_data_length,
+     909                 :            :     size_t *csr_len, uint8_t *csr_pointer,
+     910                 :            :     uint8_t req_cert_model,
+     911                 :            :     uint8_t *req_csr_tracking_tag,
+     912                 :            :     uint8_t req_key_pair_id,
+     913                 :            :     bool overwrite)
+     914                 :            : {
+     915                 :            :     bool result;
+     916                 :            :     uint8_t *cached_last_csr_request;
+     917                 :            :     size_t cached_last_request_len;
+     918                 :            :     uint8_t *cached_csr;
+     919                 :            :     size_t csr_buffer_size;
+     920                 :            :     uint8_t rsp_csr_tracking_tag;
+     921                 :            :     uint8_t available_csr_tracking_tag;
+     922                 :            :     uint8_t *request_change;
+     923                 :            :     uint8_t index;
+     924                 :            :     bool flag;
+     925                 :            :     bool is_device_cert_model;
+     926                 :            : 
+     927                 :         15 :     available_csr_tracking_tag = 0;
+     928                 :         15 :     csr_buffer_size = *csr_len;
+     929                 :            : 
+     930                 :            :     /*device gen csr need reset*/
+     931         [ +  - ]:         15 :     if (*need_reset) {
+     932                 :         15 :         result = libspdm_read_cached_last_csr_request(&cached_last_csr_request,
+     933                 :            :                                                       &cached_last_request_len,
+     934                 :         15 :                                                       *req_csr_tracking_tag,
+     935                 :            :                                                       &rsp_csr_tracking_tag);
+     936                 :            : 
+     937         [ +  + ]:         48 :         for (index = 1; index <= SPDM_MAX_CSR_TRACKING_TAG; index++) {
+     938         [ +  + ]:         47 :             if (((rsp_csr_tracking_tag >> index) & 0x01) == 0x01) {
+     939                 :         14 :                 available_csr_tracking_tag = index;
+     940                 :         14 :                 break;
+     941                 :            :             }
+     942                 :            :         }
+     943                 :            : 
+     944         [ +  + ]:         15 :         if (*req_csr_tracking_tag == 0) {
+     945         [ +  + ]:         11 :             if (available_csr_tracking_tag == 0) {
+     946                 :            :                 /*no available tracking tag*/
+     947                 :          1 :                 *req_csr_tracking_tag = 0xFF;
+     948                 :          1 :                 return false;
+     949                 :            :             } else {
+     950                 :         10 :                 flag = false;
+     951                 :            :             }
+     952                 :            :         } else {
+     953                 :            :             /*matched csr_tracking_tag*/
+     954         [ +  + ]:          4 :             if (((rsp_csr_tracking_tag >> *req_csr_tracking_tag) & 0x01) == 0) {
+     955                 :          2 :                 flag = true;
+     956                 :            :             } else {
+     957                 :            :                 /*unexpected*/
+     958                 :          2 :                 return false;
+     959                 :            :             }
+     960                 :            :         }
+     961                 :            : 
+     962                 :            :         /*get the cached last csr request and csr*/
+     963         [ +  + ]:         12 :         if ((result) &&
+     964   [ +  -  +  - ]:          4 :             (cached_last_request_len == request_size) &&
+     965                 :          2 :             (libspdm_consttime_is_mem_equal(cached_last_csr_request, request,
+     966         [ +  + ]:          2 :                                             request_size)) &&
+     967                 :          2 :             (libspdm_read_cached_csr(&cached_csr, csr_len)) &&
+     968   [ +  -  +  - ]:          1 :             (*csr_len != 0) &&
+     969                 :            :             (flag)) {
+     970                 :            : 
+     971                 :            :             /*get and save cached csr*/
+     972         [ -  + ]:          1 :             if (csr_buffer_size < *csr_len) {
+     973                 :          0 :                 free(cached_csr);
+     974                 :          0 :                 free(cached_last_csr_request);
+     975                 :          0 :                 LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+     976                 :            :                                "csr buffer is too small to store cached csr! \n"));
+     977                 :          0 :                 return false;
+     978                 :            :             } else {
+     979                 :          1 :                 libspdm_copy_mem(csr_pointer, csr_buffer_size, cached_csr, *csr_len);
+     980                 :            :             }
+     981                 :            : 
+     982                 :            :             /*device don't need reset this time*/
+     983                 :          1 :             *need_reset = false;
+     984                 :            : 
+     985                 :          1 :             free(cached_csr);
+     986                 :          1 :             free(cached_last_csr_request);
+     987                 :          1 :             return true;
+     988                 :            :         } else {
+     989         [ +  + ]:         11 :             if (cached_last_csr_request != NULL) {
+     990                 :          1 :                 free(cached_last_csr_request);
+     991                 :            :             }
+     992                 :            : 
+     993   [ +  +  +  - ]:         11 :             if ((*req_csr_tracking_tag == 0) && (available_csr_tracking_tag != 0)) {
+     994                 :         10 :                 request_change = malloc(request_size);
+     995                 :         10 :                 libspdm_copy_mem(request_change, request_size, request,request_size);
+     996                 :            : 
+     997         [ +  + ]:         10 :                 if (overwrite) {
+     998                 :          1 :                     available_csr_tracking_tag = 1;
+     999                 :            :                     /*discard all previously generated CSRTrackingTags. */
+    1000                 :          1 :                     result = libspdm_discard_all_cached_last_request();
+    1001         [ -  + ]:          1 :                     if (!result) {
+    1002                 :          0 :                         free(request_change);
+    1003                 :          0 :                         return result;
+    1004                 :            :                     }
+    1005                 :            :                 }
+    1006                 :            : 
+    1007                 :         10 :                 request_change[3] |=
+    1008                 :         10 :                     (available_csr_tracking_tag <<
+    1009                 :            :                         SPDM_GET_CSR_REQUEST_ATTRIBUTES_CSR_TRACKING_TAG_OFFSET);
+    1010                 :            : 
+    1011                 :            :                 /*device need reset this time: cache the last_csr_request */
+    1012                 :         10 :                 result = libspdm_cache_last_csr_request(request_change,
+    1013                 :            :                                                         request_size, available_csr_tracking_tag);
+    1014         [ -  + ]:         10 :                 if (!result) {
+    1015                 :          0 :                     free(request_change);
+    1016                 :          0 :                     return result;
+    1017                 :            :                 }
+    1018                 :            : 
+    1019                 :            :                 /*device need reset this time*/
+    1020                 :         10 :                 *need_reset = true;
+    1021                 :         10 :                 *req_csr_tracking_tag = available_csr_tracking_tag;
+    1022                 :         10 :                 free(request_change);
+    1023                 :         10 :                 return true;
+    1024                 :            :             } else {
+    1025                 :            :                 /*the device is busy*/
+    1026                 :          1 :                 *req_csr_tracking_tag = 0xFF;
+    1027                 :          1 :                 return false;
+    1028                 :            :             }
+    1029                 :            :         }
+    1030                 :            :     } else {
+    1031         [ #  # ]:          0 :         if (req_cert_model == SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT) {
+    1032                 :          0 :             is_device_cert_model = true;
+    1033                 :            :         } else {
+    1034                 :          0 :             is_device_cert_model = false;
+    1035                 :            :         }
+    1036                 :          0 :         result = libspdm_gen_csr_without_reset(base_hash_algo, base_asym_algo,
+    1037                 :            :                                                requester_info, requester_info_length,
+    1038                 :            :                                                opaque_data, opaque_data_length,
+    1039                 :            :                                                csr_len, csr_pointer, is_device_cert_model);
+    1040                 :          0 :         return result;
+    1041                 :            :     }
+    1042                 :            : }
+    1043                 :            : #endif /*LIBSPDM_ENABLE_CAPABILITY_CSR_CAP_EX*/
+    1044                 :            : 
+    1045                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CSR_CAP */
+    1046                 :            : 
+    1047                 :            : #if (LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP) || (LIBSPDM_ENABLE_CAPABILITY_MEL_CAP)
+    1048                 :         26 : void libspdm_generate_mel(uint32_t measurement_hash_algo)
+    1049                 :            : {
+    1050                 :            :     spdm_measurement_extension_log_dmtf_t *measurement_extension_log;
+    1051                 :            :     spdm_mel_entry_dmtf_t *mel_entry1;
+    1052                 :            :     spdm_mel_entry_dmtf_t *mel_entry2;
+    1053                 :            :     spdm_mel_entry_dmtf_t *mel_entry3;
+    1054                 :            : 
+    1055                 :         26 :     uint8_t rom_informational[] = "ROM";
+    1056                 :         26 :     uint8_t bootfv_informational[] = "Boot FW";
+    1057                 :         26 :     uint32_t version = 0x0100030A;
+    1058                 :            : 
+    1059                 :            :     /*generate MEL*/
+    1060                 :         26 :     measurement_extension_log = (spdm_measurement_extension_log_dmtf_t *)m_libspdm_mel;
+    1061                 :            : 
+    1062                 :         26 :     measurement_extension_log->number_of_entries = 3;
+    1063                 :         26 :     measurement_extension_log->mel_entries_len =
+    1064                 :         26 :         measurement_extension_log->number_of_entries * sizeof(spdm_mel_entry_dmtf_t) +
+    1065                 :         26 :         sizeof(rom_informational) - 1 + sizeof(bootfv_informational) - 1 + sizeof(version);
+    1066                 :         26 :     measurement_extension_log->reserved = 0;
+    1067                 :            : 
+    1068                 :            :     /*MEL Entry 1: informational ROM */
+    1069                 :         26 :     mel_entry1 = (spdm_mel_entry_dmtf_t *)((uint8_t *)measurement_extension_log +
+    1070                 :            :                                            sizeof(spdm_measurement_extension_log_dmtf_t));
+    1071                 :         26 :     mel_entry1->mel_index = 1;
+    1072                 :         26 :     mel_entry1->meas_index = LIBSPDM_MEASUREMENT_INDEX_HEM;
+    1073                 :         26 :     libspdm_write_uint24(mel_entry1->reserved, 0);
+    1074                 :         26 :     mel_entry1->measurement_block_dmtf_header.dmtf_spec_measurement_value_type =
+    1075                 :            :         SPDM_MEASUREMENT_BLOCK_MEASUREMENT_TYPE_INFORMATIONAL |
+    1076                 :            :         SPDM_MEASUREMENT_BLOCK_MEASUREMENT_TYPE_RAW_BIT_STREAM;
+    1077                 :         26 :     mel_entry1->measurement_block_dmtf_header.dmtf_spec_measurement_value_size =
+    1078                 :            :         sizeof(rom_informational) - 1;
+    1079                 :         26 :     libspdm_copy_mem((void *)(mel_entry1 + 1), sizeof(rom_informational) - 1,
+    1080                 :            :                      rom_informational, sizeof(rom_informational) - 1);
+    1081                 :            : 
+    1082                 :            :     /*MEL Entry 2: informational Boot FW */
+    1083                 :         26 :     mel_entry2 = (spdm_mel_entry_dmtf_t *)((uint8_t *)(mel_entry1 + 1) +
+    1084                 :            :                                            sizeof(rom_informational) - 1);
+    1085                 :         26 :     mel_entry2->mel_index = 2;
+    1086                 :         26 :     mel_entry2->meas_index = LIBSPDM_MEASUREMENT_INDEX_HEM;
+    1087                 :         26 :     libspdm_write_uint24(mel_entry2->reserved, 0);
+    1088                 :         26 :     mel_entry2->measurement_block_dmtf_header.dmtf_spec_measurement_value_type =
+    1089                 :            :         SPDM_MEASUREMENT_BLOCK_MEASUREMENT_TYPE_INFORMATIONAL |
+    1090                 :            :         SPDM_MEASUREMENT_BLOCK_MEASUREMENT_TYPE_RAW_BIT_STREAM;
+    1091                 :         26 :     mel_entry2->measurement_block_dmtf_header.dmtf_spec_measurement_value_size =
+    1092                 :            :         sizeof(bootfv_informational) - 1;
+    1093                 :         26 :     libspdm_copy_mem((void *)(mel_entry2 + 1), sizeof(bootfv_informational) - 1,
+    1094                 :            :                      bootfv_informational, sizeof(bootfv_informational) - 1);
+    1095                 :            : 
+    1096                 :            :     /*MEL Entry 3: version 0x0100030A */
+    1097                 :         26 :     mel_entry3 = (spdm_mel_entry_dmtf_t *)((uint8_t *)(mel_entry2 + 1) +
+    1098                 :            :                                            sizeof(bootfv_informational) - 1);
+    1099                 :         26 :     mel_entry3->mel_index = 3;
+    1100                 :         26 :     mel_entry3->meas_index = LIBSPDM_MEASUREMENT_INDEX_HEM;
+    1101                 :         26 :     libspdm_write_uint24(mel_entry3->reserved, 0);
+    1102                 :         26 :     mel_entry3->measurement_block_dmtf_header.dmtf_spec_measurement_value_type =
+    1103                 :            :         SPDM_MEASUREMENT_BLOCK_MEASUREMENT_TYPE_VERSION |
+    1104                 :            :         SPDM_MEASUREMENT_BLOCK_MEASUREMENT_TYPE_RAW_BIT_STREAM;
+    1105                 :         26 :     mel_entry3->measurement_block_dmtf_header.dmtf_spec_measurement_value_size = sizeof(version);
+    1106                 :         26 :     libspdm_copy_mem((void *)(mel_entry3 + 1), sizeof(version), &version, sizeof(version));
+    1107                 :         26 : }
+    1108                 :            : #endif /*(LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP) || (LIBSPDM_ENABLE_CAPABILITY_MEL_CAP)*/
+    1109                 :            : 
+    1110                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
+    1111                 :            : /**
+    1112                 :            :  * Fill image hash measurement block.
+    1113                 :            :  *
+    1114                 :            :  * @return measurement block size.
+    1115                 :            :  **/
+    1116                 :        170 : size_t libspdm_fill_measurement_image_hash_block (
+    1117                 :            :     bool use_bit_stream,
+    1118                 :            :     uint32_t measurement_hash_algo,
+    1119                 :            :     uint8_t measurements_index,
+    1120                 :            :     spdm_measurement_block_dmtf_t *measurement_block
+    1121                 :            :     )
+    1122                 :            : {
+    1123                 :            :     size_t hash_size;
+    1124                 :            :     uint8_t data[LIBSPDM_MEASUREMENT_RAW_DATA_SIZE];
+    1125                 :            :     bool result;
+    1126                 :            : 
+    1127                 :        170 :     hash_size = libspdm_get_measurement_hash_size(measurement_hash_algo);
+    1128                 :            : 
+    1129                 :            :     measurement_block->measurement_block_common_header
+    1130                 :        170 :     .index = measurements_index;
+    1131                 :            :     measurement_block->measurement_block_common_header
+    1132                 :        170 :     .measurement_specification =
+    1133                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1134                 :            : 
+    1135                 :        170 :     libspdm_set_mem(data, sizeof(data), (uint8_t)(measurements_index));
+    1136                 :            : 
+    1137         [ +  + ]:        170 :     if (!use_bit_stream) {
+    1138                 :            :         measurement_block->measurement_block_dmtf_header
+    1139                 :        169 :         .dmtf_spec_measurement_value_type =
+    1140                 :        169 :             (measurements_index - 1);
+    1141                 :            :         measurement_block->measurement_block_dmtf_header
+    1142                 :        169 :         .dmtf_spec_measurement_value_size =
+    1143                 :        169 :             (uint16_t)hash_size;
+    1144                 :            : 
+    1145                 :            :         measurement_block->measurement_block_common_header
+    1146                 :        169 :         .measurement_size =
+    1147                 :        169 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
+    1148                 :        169 :                        (uint16_t)hash_size);
+    1149                 :            : 
+    1150                 :        169 :         result = libspdm_measurement_hash_all(
+    1151                 :            :             measurement_hash_algo, data,
+    1152                 :            :             sizeof(data),
+    1153                 :        169 :             (void *)(measurement_block + 1));
+    1154         [ -  + ]:        169 :         if (!result) {
+    1155                 :          0 :             return 0;
+    1156                 :            :         }
+    1157                 :            : 
+    1158                 :        169 :         return sizeof(spdm_measurement_block_dmtf_t) + hash_size;
+    1159                 :            : 
+    1160                 :            :     } else {
+    1161                 :            :         measurement_block->measurement_block_dmtf_header
+    1162                 :          1 :         .dmtf_spec_measurement_value_type =
+    1163                 :          1 :             (measurements_index - 1) |
+    1164                 :            :             SPDM_MEASUREMENT_BLOCK_MEASUREMENT_TYPE_RAW_BIT_STREAM;
+    1165                 :            :         measurement_block->measurement_block_dmtf_header
+    1166                 :          1 :         .dmtf_spec_measurement_value_size =
+    1167                 :            :             (uint16_t)sizeof(data);
+    1168                 :            : 
+    1169                 :            :         measurement_block->measurement_block_common_header
+    1170                 :          1 :         .measurement_size =
+    1171                 :            :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
+    1172                 :            :                        (uint16_t)sizeof(data));
+    1173                 :            : 
+    1174                 :          1 :         libspdm_copy_mem((void *)(measurement_block + 1), sizeof(data), data, sizeof(data));
+    1175                 :            : 
+    1176                 :          1 :         return sizeof(spdm_measurement_block_dmtf_t) + sizeof(data);
+    1177                 :            :     }
+    1178                 :            : }
+    1179                 :            : 
+    1180                 :            : /**
+    1181                 :            :  * Fill svn measurement block.
+    1182                 :            :  *
+    1183                 :            :  * @return measurement block size.
+    1184                 :            :  **/
+    1185                 :         15 : size_t libspdm_fill_measurement_svn_block (
+    1186                 :            :     spdm_measurement_block_dmtf_t *measurement_block
+    1187                 :            :     )
+    1188                 :            : {
+    1189                 :            :     spdm_measurements_secure_version_number_t svn;
+    1190                 :            : 
+    1191                 :            :     measurement_block->measurement_block_common_header
+    1192                 :         15 :     .index = LIBSPDM_MEASUREMENT_INDEX_SVN;
+    1193                 :            :     measurement_block->measurement_block_common_header
+    1194                 :         15 :     .measurement_specification =
+    1195                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1196                 :            : 
+    1197                 :         15 :     svn = 0x7;
+    1198                 :            : 
+    1199                 :            :     measurement_block->measurement_block_dmtf_header
+    1200                 :         15 :     .dmtf_spec_measurement_value_type =
+    1201                 :            :         SPDM_MEASUREMENT_BLOCK_MEASUREMENT_TYPE_SECURE_VERSION_NUMBER |
+    1202                 :            :         SPDM_MEASUREMENT_BLOCK_MEASUREMENT_TYPE_RAW_BIT_STREAM;
+    1203                 :            :     measurement_block->measurement_block_dmtf_header
+    1204                 :         15 :     .dmtf_spec_measurement_value_size =
+    1205                 :            :         (uint16_t)sizeof(svn);
+    1206                 :            : 
+    1207                 :            :     measurement_block->measurement_block_common_header
+    1208                 :         15 :     .measurement_size =
+    1209                 :            :         (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
+    1210                 :            :                    (uint16_t)sizeof(svn));
+    1211                 :            : 
+    1212                 :         15 :     libspdm_copy_mem((void *)(measurement_block + 1), sizeof(svn), (void *)&svn, sizeof(svn));
+    1213                 :            : 
+    1214                 :         15 :     return sizeof(spdm_measurement_block_dmtf_t) + sizeof(svn);
+    1215                 :            : }
+    1216                 :            : 
+    1217                 :            : /**
+    1218                 :            :  * Fill HEM measurement block.
+    1219                 :            :  *
+    1220                 :            :  * @param  measurement_block          A pointer to store measurement block.
+    1221                 :            :  * @param  measurement_hash_algo      Indicates the measurement hash algorithm.
+    1222                 :            :  *                                    It must align with measurement_hash_alg
+    1223                 :            :  *                                    (SPDM_ALGORITHMS_MEASUREMENT_HASH_ALGO_*)
+    1224                 :            :  *
+    1225                 :            :  * @return measurement block size.
+    1226                 :            :  **/
+    1227                 :         15 : size_t libspdm_fill_measurement_hem_block (
+    1228                 :            :     spdm_measurement_block_dmtf_t *measurement_block, uint32_t measurement_hash_algo
+    1229                 :            :     )
+    1230                 :            : {
+    1231                 :            :     size_t hash_size;
+    1232                 :            :     spdm_measurement_extension_log_dmtf_t *measurement_extension_log;
+    1233                 :            :     spdm_mel_entry_dmtf_t *mel_entry;
+    1234                 :            :     uint32_t index;
+    1235                 :            :     uint8_t *verify_hem;
+    1236                 :            : 
+    1237         [ -  + ]:         15 :     if (measurement_hash_algo == SPDM_ALGORITHMS_MEASUREMENT_HASH_ALGO_RAW_BIT_STREAM_ONLY) {
+    1238                 :          0 :         return 0;
+    1239                 :            :     }
+    1240                 :            : 
+    1241                 :         15 :     libspdm_generate_mel(measurement_hash_algo);
+    1242                 :            : 
+    1243                 :         15 :     hash_size = libspdm_get_measurement_hash_size(measurement_hash_algo);
+    1244         [ -  + ]:         15 :     if (measurement_block == NULL) {
+    1245                 :          0 :         return sizeof(spdm_measurement_block_dmtf_t) + hash_size;
+    1246                 :            :     }
+    1247                 :            : 
+    1248                 :            :     /*MEL*/
+    1249                 :         15 :     measurement_extension_log = (spdm_measurement_extension_log_dmtf_t *)m_libspdm_mel;
+    1250                 :            : 
+    1251                 :            :     /*generate measurement block*/
+    1252                 :            :     measurement_block->measurement_block_common_header
+    1253                 :         15 :     .index = LIBSPDM_MEASUREMENT_INDEX_HEM;
+    1254                 :            :     measurement_block->measurement_block_common_header
+    1255                 :         15 :     .measurement_specification =
+    1256                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1257                 :            : 
+    1258                 :            :     measurement_block->measurement_block_dmtf_header
+    1259                 :         15 :     .dmtf_spec_measurement_value_type =
+    1260                 :            :         SPDM_MEASUREMENT_BLOCK_MEASUREMENT_TYPE_HASH_EXTEND_MEASUREMENT;
+    1261                 :            :     measurement_block->measurement_block_dmtf_header
+    1262                 :         15 :     .dmtf_spec_measurement_value_size =
+    1263                 :         15 :         (uint16_t)hash_size;
+    1264                 :            : 
+    1265                 :            :     measurement_block->measurement_block_common_header
+    1266                 :         15 :     .measurement_size =
+    1267                 :         15 :         (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
+    1268                 :         15 :                    (uint16_t)hash_size);
+    1269                 :            : 
+    1270                 :         15 :     verify_hem = malloc(measurement_extension_log->mel_entries_len + hash_size);
+    1271         [ -  + ]:         15 :     if (verify_hem == NULL) {
+    1272                 :          0 :         return 0;
+    1273                 :            :     }
+    1274                 :            : 
+    1275                 :         15 :     libspdm_zero_mem(verify_hem, measurement_extension_log->mel_entries_len + hash_size);
+    1276                 :         15 :     mel_entry = (spdm_mel_entry_dmtf_t *)((uint8_t *)measurement_extension_log +
+    1277                 :            :                                           sizeof(spdm_measurement_extension_log_dmtf_t));
+    1278         [ +  + ]:         60 :     for (index = 0; index < measurement_extension_log->number_of_entries; index++) {
+    1279                 :         45 :         libspdm_copy_mem(
+    1280                 :         45 :             verify_hem + hash_size,
+    1281                 :         45 :             measurement_extension_log->mel_entries_len,
+    1282                 :            :             mel_entry,
+    1283                 :            :             sizeof(spdm_mel_entry_dmtf_t) +
+    1284                 :         45 :             mel_entry->measurement_block_dmtf_header.dmtf_spec_measurement_value_size);
+    1285                 :            : 
+    1286         [ -  + ]:         45 :         if (!libspdm_measurement_hash_all(
+    1287                 :            :                 measurement_hash_algo,
+    1288                 :            :                 verify_hem,
+    1289                 :         45 :                 hash_size + sizeof(spdm_mel_entry_dmtf_t) +
+    1290                 :         45 :                 mel_entry->measurement_block_dmtf_header.dmtf_spec_measurement_value_size,
+    1291                 :            :                 verify_hem
+    1292                 :            :                 )) {
+    1293                 :          0 :             free(verify_hem);
+    1294                 :          0 :             return 0;
+    1295                 :            :         }
+    1296                 :         45 :         mel_entry = (spdm_mel_entry_dmtf_t *)
+    1297                 :         45 :                     ((uint8_t *)mel_entry + sizeof(spdm_mel_entry_dmtf_t)+
+    1298                 :         45 :                      mel_entry->measurement_block_dmtf_header.dmtf_spec_measurement_value_size);
+    1299                 :            :     }
+    1300                 :            : 
+    1301                 :         15 :     libspdm_copy_mem((void *)(measurement_block + 1), hash_size, verify_hem, hash_size);
+    1302                 :         15 :     free(verify_hem);
+    1303                 :         15 :     return sizeof(spdm_measurement_block_dmtf_t) + hash_size;
+    1304                 :            : }
+    1305                 :            : 
+    1306                 :            : /**
+    1307                 :            :  * Fill manifest measurement block.
+    1308                 :            :  *
+    1309                 :            :  * @return measurement block size.
+    1310                 :            :  **/
+    1311                 :         15 : size_t libspdm_fill_measurement_manifest_block (
+    1312                 :            :     spdm_measurement_block_dmtf_t *measurement_block
+    1313                 :            :     )
+    1314                 :            : {
+    1315                 :            :     uint8_t data[LIBSPDM_MEASUREMENT_MANIFEST_SIZE];
+    1316                 :            : 
+    1317                 :            :     measurement_block->measurement_block_common_header
+    1318                 :         15 :     .index = SPDM_MEASUREMENT_BLOCK_MEASUREMENT_INDEX_MEASUREMENT_MANIFEST;
+    1319                 :            :     measurement_block->measurement_block_common_header
+    1320                 :         15 :     .measurement_specification =
+    1321                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1322                 :            : 
+    1323                 :         15 :     libspdm_set_mem(data, sizeof(data),
+    1324                 :            :                     (uint8_t)SPDM_MEASUREMENT_BLOCK_MEASUREMENT_INDEX_MEASUREMENT_MANIFEST);
+    1325                 :            : 
+    1326                 :            :     measurement_block->measurement_block_dmtf_header
+    1327                 :         15 :     .dmtf_spec_measurement_value_type =
+    1328                 :            :         SPDM_MEASUREMENT_BLOCK_MEASUREMENT_TYPE_MEASUREMENT_MANIFEST |
+    1329                 :            :         SPDM_MEASUREMENT_BLOCK_MEASUREMENT_TYPE_RAW_BIT_STREAM;
+    1330                 :            :     measurement_block->measurement_block_dmtf_header
+    1331                 :         15 :     .dmtf_spec_measurement_value_size =
+    1332                 :            :         (uint16_t)sizeof(data);
+    1333                 :            : 
+    1334                 :            :     measurement_block->measurement_block_common_header
+    1335                 :         15 :     .measurement_size =
+    1336                 :            :         (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
+    1337                 :            :                    (uint16_t)sizeof(data));
+    1338                 :            : 
+    1339                 :         15 :     libspdm_copy_mem((void *)(measurement_block + 1), sizeof(data), data, sizeof(data));
+    1340                 :            : 
+    1341                 :         15 :     return sizeof(spdm_measurement_block_dmtf_t) + sizeof(data);
+    1342                 :            : }
+    1343                 :            : 
+    1344                 :            : /**
+    1345                 :            :  * Fill device mode measurement block.
+    1346                 :            :  *
+    1347                 :            :  * @return measurement block size.
+    1348                 :            :  **/
+    1349                 :         15 : size_t libspdm_fill_measurement_device_mode_block (
+    1350                 :            :     spdm_measurement_block_dmtf_t *measurement_block
+    1351                 :            :     )
+    1352                 :            : {
+    1353                 :            :     spdm_measurements_device_mode_t device_mode;
+    1354                 :            : 
+    1355                 :            :     measurement_block->measurement_block_common_header
+    1356                 :         15 :     .index = SPDM_MEASUREMENT_BLOCK_MEASUREMENT_INDEX_DEVICE_MODE;
+    1357                 :            :     measurement_block->measurement_block_common_header
+    1358                 :         15 :     .measurement_specification =
+    1359                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1360                 :            : 
+    1361                 :         15 :     device_mode.operational_mode_capabilities =
+    1362                 :            :         SPDM_MEASUREMENT_DEVICE_OPERATION_MODE_MANUFACTURING_MODE |
+    1363                 :            :         SPDM_MEASUREMENT_DEVICE_OPERATION_MODE_VALIDATION_MODE |
+    1364                 :            :         SPDM_MEASUREMENT_DEVICE_OPERATION_MODE_NORMAL_MODE |
+    1365                 :            :         SPDM_MEASUREMENT_DEVICE_OPERATION_MODE_RECOVERY_MODE |
+    1366                 :            :         SPDM_MEASUREMENT_DEVICE_OPERATION_MODE_RMA_MODE |
+    1367                 :            :         SPDM_MEASUREMENT_DEVICE_OPERATION_MODE_DECOMMISSIONED_MODE;
+    1368                 :         15 :     device_mode.operational_mode_state =
+    1369                 :            :         SPDM_MEASUREMENT_DEVICE_OPERATION_MODE_NORMAL_MODE;
+    1370                 :         15 :     device_mode.device_mode_capabilities =
+    1371                 :            :         SPDM_MEASUREMENT_DEVICE_MODE_NON_INVASIVE_DEBUG_MODE_IS_ACTIVE |
+    1372                 :            :         SPDM_MEASUREMENT_DEVICE_MODE_INVASIVE_DEBUG_MODE_IS_ACTIVE |
+    1373                 :            :         SPDM_MEASUREMENT_DEVICE_MODE_NON_INVASIVE_DEBUG_MODE_HAS_BEEN_ACTIVE |
+    1374                 :            :         SPDM_MEASUREMENT_DEVICE_MODE_INVASIVE_DEBUG_MODE_HAS_BEEN_ACTIVE |
+    1375                 :            :         SPDM_MEASUREMENT_DEVICE_MODE_INVASIVE_DEBUG_MODE_HAS_BEEN_ACTIVE_AFTER_MFG;
+    1376                 :         15 :     device_mode.device_mode_state =
+    1377                 :            :         SPDM_MEASUREMENT_DEVICE_MODE_NON_INVASIVE_DEBUG_MODE_IS_ACTIVE |
+    1378                 :            :         SPDM_MEASUREMENT_DEVICE_MODE_INVASIVE_DEBUG_MODE_HAS_BEEN_ACTIVE_AFTER_MFG;
+    1379                 :            : 
+    1380                 :            :     measurement_block->measurement_block_dmtf_header
+    1381                 :         15 :     .dmtf_spec_measurement_value_type =
+    1382                 :            :         SPDM_MEASUREMENT_BLOCK_MEASUREMENT_TYPE_DEVICE_MODE |
+    1383                 :            :         SPDM_MEASUREMENT_BLOCK_MEASUREMENT_TYPE_RAW_BIT_STREAM;
+    1384                 :            :     measurement_block->measurement_block_dmtf_header
+    1385                 :         15 :     .dmtf_spec_measurement_value_size =
+    1386                 :            :         (uint16_t)sizeof(device_mode);
+    1387                 :            : 
+    1388                 :            :     measurement_block->measurement_block_common_header
+    1389                 :         15 :     .measurement_size =
+    1390                 :            :         (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
+    1391                 :            :                    (uint16_t)sizeof(device_mode));
+    1392                 :            : 
+    1393                 :         15 :     libspdm_copy_mem((void *)(measurement_block + 1), sizeof(device_mode),
+    1394                 :            :                      (void *)&device_mode, sizeof(device_mode));
+    1395                 :            : 
+    1396                 :         15 :     return sizeof(spdm_measurement_block_dmtf_t) + sizeof(device_mode);
+    1397                 :            : }
+    1398                 :            : 
+    1399                 :        137 : libspdm_return_t libspdm_measurement_collection(
+    1400                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    1401                 :            :     void *spdm_context,
+    1402                 :            : #endif
+    1403                 :            :     spdm_version_number_t spdm_version,
+    1404                 :            :     uint8_t measurement_specification,
+    1405                 :            :     uint32_t measurement_hash_algo,
+    1406                 :            :     uint8_t measurements_index,
+    1407                 :            :     uint8_t request_attribute,
+    1408                 :            :     uint8_t *content_changed,
+    1409                 :            :     uint8_t *measurements_count,
+    1410                 :            :     void *measurements,
+    1411                 :            :     size_t *measurements_size)
+    1412                 :            : {
+    1413                 :            :     spdm_measurement_block_dmtf_t *measurement_block;
+    1414                 :            :     size_t hash_size;
+    1415                 :            :     uint8_t index;
+    1416                 :            :     size_t total_size_needed;
+    1417                 :            :     bool use_bit_stream;
+    1418                 :            :     size_t measurement_block_size;
+    1419                 :            : 
+    1420         [ +  - ]:        137 :     if ((measurement_specification !=
+    1421         [ -  + ]:        137 :          SPDM_MEASUREMENT_SPECIFICATION_DMTF) ||
+    1422                 :            :         (measurement_hash_algo == 0)) {
+    1423                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+    1424                 :            :     }
+    1425                 :            : 
+    1426                 :        137 :     hash_size = libspdm_get_measurement_hash_size(measurement_hash_algo);
+    1427         [ -  + ]:        137 :     LIBSPDM_ASSERT(hash_size != 0);
+    1428                 :            : 
+    1429                 :        137 :     use_bit_stream = false;
+    1430         [ +  - ]:        137 :     if ((measurement_hash_algo == SPDM_ALGORITHMS_MEASUREMENT_HASH_ALGO_RAW_BIT_STREAM_ONLY) ||
+    1431         [ +  + ]:        137 :         ((request_attribute & SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_RAW_BIT_STREAM_REQUESTED) !=
+    1432                 :            :          0)) {
+    1433                 :          1 :         use_bit_stream = true;
+    1434                 :            :     }
+    1435                 :            : 
+    1436         [ +  + ]:        137 :     if (measurements_index ==
+    1437                 :            :         SPDM_GET_MEASUREMENTS_REQUEST_MEASUREMENT_OPERATION_TOTAL_NUMBER_OF_MEASUREMENTS) {
+    1438                 :         11 :         *measurements_count = LIBSPDM_MEASUREMENT_BLOCK_NUMBER;
+    1439                 :         11 :         goto successful_return;
+    1440         [ +  + ]:        126 :     } else if (measurements_index ==
+    1441                 :            :                SPDM_GET_MEASUREMENTS_REQUEST_MEASUREMENT_OPERATION_ALL_MEASUREMENTS) {
+    1442                 :            : 
+    1443                 :            :         /* Calculate total_size_needed based on hash algo selected.
+    1444                 :            :          * If we have an hash algo, then the first HASH_NUMBER elements will be
+    1445                 :            :          * hash values, otherwise HASH_NUMBER raw bitstream values.*/
+    1446         [ +  - ]:         15 :         if (!use_bit_stream) {
+    1447                 :         15 :             total_size_needed =
+    1448                 :            :                 LIBSPDM_MEASUREMENT_BLOCK_HASH_NUMBER *
+    1449                 :         15 :                 (sizeof(spdm_measurement_block_dmtf_t) + hash_size);
+    1450                 :            :         } else {
+    1451                 :          0 :             total_size_needed =
+    1452                 :            :                 LIBSPDM_MEASUREMENT_BLOCK_HASH_NUMBER *
+    1453                 :            :                 (sizeof(spdm_measurement_block_dmtf_t) + LIBSPDM_MEASUREMENT_RAW_DATA_SIZE);
+    1454                 :            :         }
+    1455                 :            :         /* Next one - SVN is always raw bitstream data.*/
+    1456                 :         15 :         total_size_needed +=
+    1457                 :            :             (sizeof(spdm_measurement_block_dmtf_t) +
+    1458                 :            :              sizeof(spdm_measurements_secure_version_number_t));
+    1459                 :            :         /* Next one - HEM is always digest data.*/
+    1460                 :         15 :         total_size_needed +=
+    1461                 :            :             (sizeof(spdm_measurement_block_dmtf_t) + hash_size);
+    1462                 :            :         /* Next one - manifest is always raw bitstream data.*/
+    1463                 :         15 :         total_size_needed +=
+    1464                 :            :             (sizeof(spdm_measurement_block_dmtf_t) + LIBSPDM_MEASUREMENT_MANIFEST_SIZE);
+    1465                 :            :         /* Next one - device_mode is always raw bitstream data.*/
+    1466                 :         15 :         total_size_needed +=
+    1467                 :            :             (sizeof(spdm_measurement_block_dmtf_t) + sizeof(spdm_measurements_device_mode_t));
+    1468                 :            : 
+    1469         [ -  + ]:         15 :         LIBSPDM_ASSERT(total_size_needed <= *measurements_size);
+    1470         [ -  + ]:         15 :         if (total_size_needed > *measurements_size) {
+    1471                 :          0 :             return LIBSPDM_STATUS_BUFFER_TOO_SMALL;
+    1472                 :            :         }
+    1473                 :            : 
+    1474                 :         15 :         *measurements_size = total_size_needed;
+    1475                 :         15 :         *measurements_count = LIBSPDM_MEASUREMENT_BLOCK_NUMBER;
+    1476                 :         15 :         measurement_block = measurements;
+    1477                 :            : 
+    1478                 :            :         /* The first HASH_NUMBER blocks may be hash values or raw bitstream*/
+    1479         [ +  + ]:         75 :         for (index = 1; index <= LIBSPDM_MEASUREMENT_BLOCK_HASH_NUMBER; index++) {
+    1480                 :         60 :             measurement_block_size = libspdm_fill_measurement_image_hash_block (use_bit_stream,
+    1481                 :            :                                                                                 measurement_hash_algo,
+    1482                 :            :                                                                                 index,
+    1483                 :            :                                                                                 measurement_block);
+    1484         [ -  + ]:         60 :             if (measurement_block_size == 0) {
+    1485                 :          0 :                 return LIBSPDM_STATUS_MEAS_INTERNAL_ERROR;
+    1486                 :            :             }
+    1487                 :         60 :             measurement_block = (void *)((uint8_t *)measurement_block + measurement_block_size);
+    1488                 :            :         }
+    1489                 :            :         /* Next one - SVN is always raw bitstream data.*/
+    1490                 :            :         {
+    1491                 :         15 :             measurement_block_size = libspdm_fill_measurement_svn_block (measurement_block);
+    1492                 :         15 :             measurement_block = (void *)((uint8_t *)measurement_block + measurement_block_size);
+    1493                 :            :         }
+    1494                 :            :         /* Next one - HEM is always digest data.*/
+    1495                 :            :         {
+    1496                 :         15 :             measurement_block_size = libspdm_fill_measurement_hem_block (measurement_block,
+    1497                 :            :                                                                          measurement_hash_algo);
+    1498                 :         15 :             measurement_block = (void *)((uint8_t *)measurement_block + measurement_block_size);
+    1499                 :            :         }
+    1500                 :            :         /* Next one - manifest is always raw bitstream data.*/
+    1501                 :            :         {
+    1502                 :         15 :             measurement_block_size = libspdm_fill_measurement_manifest_block (measurement_block);
+    1503                 :         15 :             measurement_block = (void *)((uint8_t *)measurement_block + measurement_block_size);
+    1504                 :            :         }
+    1505                 :            :         /* Next one - device_mode is always raw bitstream data.*/
+    1506                 :            :         {
+    1507                 :         15 :             measurement_block_size = libspdm_fill_measurement_device_mode_block (measurement_block);
+    1508                 :         15 :             measurement_block = (void *)((uint8_t *)measurement_block + measurement_block_size);
+    1509                 :            :         }
+    1510                 :            : 
+    1511                 :         15 :         goto successful_return;
+    1512                 :            :     } else {
+    1513                 :            :         /* One Index */
+    1514         [ +  + ]:        111 :         if (measurements_index <= LIBSPDM_MEASUREMENT_BLOCK_HASH_NUMBER) {
+    1515         [ +  + ]:        110 :             if (!use_bit_stream) {
+    1516                 :        109 :                 total_size_needed =
+    1517                 :            :                     sizeof(spdm_measurement_block_dmtf_t) +
+    1518                 :            :                     hash_size;
+    1519                 :            :             } else {
+    1520                 :          1 :                 total_size_needed =
+    1521                 :            :                     sizeof(spdm_measurement_block_dmtf_t) +
+    1522                 :            :                     LIBSPDM_MEASUREMENT_RAW_DATA_SIZE;
+    1523                 :            :             }
+    1524         [ -  + ]:        110 :             LIBSPDM_ASSERT(total_size_needed <= *measurements_size);
+    1525         [ -  + ]:        110 :             if (total_size_needed > *measurements_size) {
+    1526                 :          0 :                 return LIBSPDM_STATUS_BUFFER_TOO_SMALL;
+    1527                 :            :             }
+    1528                 :            : 
+    1529                 :        110 :             *measurements_count = 1;
+    1530                 :        110 :             *measurements_size = total_size_needed;
+    1531                 :            : 
+    1532                 :        110 :             measurement_block = measurements;
+    1533                 :        110 :             measurement_block_size = libspdm_fill_measurement_image_hash_block (use_bit_stream,
+    1534                 :            :                                                                                 measurement_hash_algo,
+    1535                 :            :                                                                                 measurements_index,
+    1536                 :            :                                                                                 measurement_block);
+    1537         [ -  + ]:        110 :             if (measurement_block_size == 0) {
+    1538                 :          0 :                 return LIBSPDM_STATUS_MEAS_INTERNAL_ERROR;
+    1539                 :            :             }
+    1540         [ -  + ]:          1 :         } else if (measurements_index == LIBSPDM_MEASUREMENT_INDEX_SVN) {
+    1541                 :          0 :             total_size_needed =
+    1542                 :            :                 sizeof(spdm_measurement_block_dmtf_t) +
+    1543                 :            :                 sizeof(spdm_measurements_secure_version_number_t);
+    1544         [ #  # ]:          0 :             LIBSPDM_ASSERT(total_size_needed <= *measurements_size);
+    1545         [ #  # ]:          0 :             if (total_size_needed > *measurements_size) {
+    1546                 :          0 :                 return LIBSPDM_STATUS_BUFFER_TOO_SMALL;
+    1547                 :            :             }
+    1548                 :            : 
+    1549                 :          0 :             *measurements_count = 1;
+    1550                 :          0 :             *measurements_size = total_size_needed;
+    1551                 :            : 
+    1552                 :          0 :             measurement_block = measurements;
+    1553                 :          0 :             measurement_block_size = libspdm_fill_measurement_svn_block (measurement_block);
+    1554         [ #  # ]:          0 :             if (measurement_block_size == 0) {
+    1555                 :          0 :                 return LIBSPDM_STATUS_MEAS_INTERNAL_ERROR;
+    1556                 :            :             }
+    1557         [ -  + ]:          1 :         } else if (measurements_index == LIBSPDM_MEASUREMENT_INDEX_HEM) {
+    1558                 :          0 :             total_size_needed =
+    1559                 :            :                 sizeof(spdm_measurement_block_dmtf_t) + hash_size;
+    1560         [ #  # ]:          0 :             LIBSPDM_ASSERT(total_size_needed <= *measurements_size);
+    1561         [ #  # ]:          0 :             if (total_size_needed > *measurements_size) {
+    1562                 :          0 :                 return LIBSPDM_STATUS_BUFFER_TOO_SMALL;
+    1563                 :            :             }
+    1564                 :            : 
+    1565                 :          0 :             *measurements_count = 1;
+    1566                 :          0 :             *measurements_size = total_size_needed;
+    1567                 :            : 
+    1568                 :          0 :             measurement_block = measurements;
+    1569                 :          0 :             measurement_block_size = libspdm_fill_measurement_hem_block (measurement_block,
+    1570                 :            :                                                                          measurement_hash_algo);
+    1571         [ #  # ]:          0 :             if (measurement_block_size == 0) {
+    1572                 :          0 :                 return LIBSPDM_STATUS_MEAS_INTERNAL_ERROR;
+    1573                 :            :             }
+    1574         [ -  + ]:          1 :         } else if (measurements_index ==
+    1575                 :            :                    SPDM_MEASUREMENT_BLOCK_MEASUREMENT_INDEX_MEASUREMENT_MANIFEST) {
+    1576                 :          0 :             total_size_needed =
+    1577                 :            :                 sizeof(spdm_measurement_block_dmtf_t) +
+    1578                 :            :                 LIBSPDM_MEASUREMENT_MANIFEST_SIZE;
+    1579         [ #  # ]:          0 :             LIBSPDM_ASSERT(total_size_needed <= *measurements_size);
+    1580         [ #  # ]:          0 :             if (total_size_needed > *measurements_size) {
+    1581                 :          0 :                 return LIBSPDM_STATUS_BUFFER_TOO_SMALL;
+    1582                 :            :             }
+    1583                 :            : 
+    1584                 :          0 :             *measurements_count = 1;
+    1585                 :          0 :             *measurements_size = total_size_needed;
+    1586                 :            : 
+    1587                 :          0 :             measurement_block = measurements;
+    1588                 :          0 :             measurement_block_size = libspdm_fill_measurement_manifest_block (measurement_block);
+    1589         [ #  # ]:          0 :             if (measurement_block_size == 0) {
+    1590                 :          0 :                 return LIBSPDM_STATUS_MEAS_INTERNAL_ERROR;
+    1591                 :            :             }
+    1592         [ -  + ]:          1 :         } else if (measurements_index == SPDM_MEASUREMENT_BLOCK_MEASUREMENT_INDEX_DEVICE_MODE) {
+    1593                 :          0 :             total_size_needed =
+    1594                 :            :                 sizeof(spdm_measurement_block_dmtf_t) +
+    1595                 :            :                 sizeof(spdm_measurements_device_mode_t);
+    1596         [ #  # ]:          0 :             LIBSPDM_ASSERT(total_size_needed <= *measurements_size);
+    1597         [ #  # ]:          0 :             if (total_size_needed > *measurements_size) {
+    1598                 :          0 :                 return LIBSPDM_STATUS_BUFFER_TOO_SMALL;
+    1599                 :            :             }
+    1600                 :            : 
+    1601                 :          0 :             *measurements_count = 1;
+    1602                 :          0 :             *measurements_size = total_size_needed;
+    1603                 :            : 
+    1604                 :          0 :             measurement_block = measurements;
+    1605                 :          0 :             measurement_block_size = libspdm_fill_measurement_device_mode_block (measurement_block);
+    1606         [ #  # ]:          0 :             if (measurement_block_size == 0) {
+    1607                 :          0 :                 return LIBSPDM_STATUS_MEAS_INTERNAL_ERROR;
+    1608                 :            :             }
+    1609                 :            :         } else {
+    1610                 :          1 :             *measurements_count = 0;
+    1611                 :          1 :             return LIBSPDM_STATUS_MEAS_INVALID_INDEX;
+    1612                 :            :         }
+    1613                 :            :     }
+    1614                 :            : 
+    1615                 :        136 : successful_return:
+    1616         [ +  + ]:        136 :     if ((content_changed != NULL) &&
+    1617         [ +  + ]:        126 :         ((spdm_version >> SPDM_VERSION_NUMBER_SHIFT_BIT) >= SPDM_MESSAGE_VERSION_12)) {
+    1618                 :            :         /* return content change*/
+    1619         [ +  + ]:          9 :         if ((request_attribute & SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE) !=
+    1620                 :            :             0) {
+    1621                 :          7 :             *content_changed = SPDM_MEASUREMENTS_RESPONSE_CONTENT_NO_CHANGE_DETECTED;
+    1622                 :            :         } else {
+    1623                 :          2 :             *content_changed = SPDM_MEASUREMENTS_RESPONSE_CONTENT_CHANGE_NO_DETECTION;
+    1624                 :            :         }
+    1625                 :            :     }
+    1626                 :            : 
+    1627                 :        136 :     return LIBSPDM_STATUS_SUCCESS;
+    1628                 :            : }
+    1629                 :            : 
+    1630                 :            : size_t libspdm_secret_lib_meas_opaque_data_size;
+    1631                 :            : 
+    1632                 :        122 : bool libspdm_measurement_opaque_data(
+    1633                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    1634                 :            :     void *spdm_context,
+    1635                 :            : #endif
+    1636                 :            :     spdm_version_number_t spdm_version,
+    1637                 :            :     uint8_t measurement_specification,
+    1638                 :            :     uint32_t measurement_hash_algo,
+    1639                 :            :     uint8_t measurement_index,
+    1640                 :            :     uint8_t request_attribute,
+    1641                 :            :     void *opaque_data,
+    1642                 :            :     size_t *opaque_data_size)
+    1643                 :            : {
+    1644                 :            :     size_t index;
+    1645                 :            : 
+    1646         [ -  + ]:        122 :     LIBSPDM_ASSERT(libspdm_secret_lib_meas_opaque_data_size <= *opaque_data_size);
+    1647                 :            : 
+    1648                 :        122 :     *opaque_data_size = libspdm_secret_lib_meas_opaque_data_size;
+    1649                 :            : 
+    1650         [ +  + ]:        218 :     for (index = 0; index < *opaque_data_size; index++)
+    1651                 :            :     {
+    1652                 :         96 :         ((uint8_t *)opaque_data)[index] = (uint8_t)index;
+    1653                 :            :     }
+    1654                 :            : 
+    1655                 :        122 :     return true;
+    1656                 :            : }
+    1657                 :            : 
+    1658                 :         10 : bool libspdm_generate_measurement_summary_hash(
+    1659                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    1660                 :            :     void *spdm_context,
+    1661                 :            : #endif
+    1662                 :            :     spdm_version_number_t spdm_version, uint32_t base_hash_algo,
+    1663                 :            :     uint8_t measurement_specification, uint32_t measurement_hash_algo,
+    1664                 :            :     uint8_t measurement_summary_hash_type,
+    1665                 :            :     uint8_t *measurement_summary_hash,
+    1666                 :            :     uint32_t measurement_summary_hash_size)
+    1667                 :            : {
+    1668                 :            :     uint8_t measurement_data[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
+    1669                 :            :     size_t index;
+    1670                 :            :     spdm_measurement_block_dmtf_t *cached_measurement_block;
+    1671                 :            :     size_t measurement_data_size;
+    1672                 :            :     size_t measurement_block_size;
+    1673                 :            :     uint8_t device_measurement[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
+    1674                 :            :     uint8_t device_measurement_count;
+    1675                 :            :     size_t device_measurement_size;
+    1676                 :            :     libspdm_return_t status;
+    1677                 :            :     bool result;
+    1678                 :            : 
+    1679      [ -  +  - ]:         10 :     switch (measurement_summary_hash_type) {
+    1680                 :          0 :     case SPDM_REQUEST_NO_MEASUREMENT_SUMMARY_HASH:
+    1681                 :          0 :         break;
+    1682                 :            : 
+    1683                 :         10 :     case SPDM_REQUEST_TCB_COMPONENT_MEASUREMENT_HASH:
+    1684                 :            :     case SPDM_REQUEST_ALL_MEASUREMENTS_HASH:
+    1685         [ -  + ]:         10 :         if (measurement_summary_hash_size != libspdm_get_hash_size(base_hash_algo)) {
+    1686                 :          0 :             return false;
+    1687                 :            :         }
+    1688                 :            : 
+    1689                 :            :         /* get all measurement data*/
+    1690                 :         10 :         device_measurement_size = sizeof(device_measurement);
+    1691                 :         10 :         status = libspdm_measurement_collection(
+    1692                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    1693                 :            :             spdm_context,
+    1694                 :            : #endif
+    1695                 :            :             spdm_version, measurement_specification,
+    1696                 :            :             measurement_hash_algo,
+    1697                 :            :             0xFF, /* Get all measurements*/
+    1698                 :            :             0,
+    1699                 :            :             NULL,
+    1700                 :            :             &device_measurement_count, device_measurement,
+    1701                 :            :             &device_measurement_size);
+    1702         [ -  + ]:         10 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+    1703                 :          0 :             return false;
+    1704                 :            :         }
+    1705                 :            : 
+    1706                 :            :         /* double confirm that MeasurementData internal size is correct*/
+    1707                 :         10 :         measurement_data_size = 0;
+    1708                 :         10 :         cached_measurement_block = (void *)device_measurement;
+    1709         [ +  + ]:         90 :         for (index = 0; index < device_measurement_count; index++) {
+    1710                 :         80 :             measurement_block_size =
+    1711                 :            :                 sizeof(spdm_measurement_block_common_header_t) +
+    1712                 :            :                 cached_measurement_block
+    1713                 :            :                 ->measurement_block_common_header
+    1714                 :         80 :                 .measurement_size;
+    1715         [ -  + ]:         80 :             LIBSPDM_ASSERT(cached_measurement_block
+    1716                 :            :                            ->measurement_block_common_header
+    1717                 :            :                            .measurement_size ==
+    1718                 :            :                            sizeof(spdm_measurement_block_dmtf_header_t) +
+    1719                 :            :                            cached_measurement_block
+    1720                 :            :                            ->measurement_block_dmtf_header
+    1721                 :            :                            .dmtf_spec_measurement_value_size);
+    1722                 :         80 :             measurement_data_size +=
+    1723                 :            :                 cached_measurement_block
+    1724                 :            :                 ->measurement_block_common_header
+    1725                 :         80 :                 .measurement_size;
+    1726                 :         80 :             cached_measurement_block =
+    1727                 :         80 :                 (void *)((size_t)cached_measurement_block +
+    1728                 :            :                          measurement_block_size);
+    1729                 :            :         }
+    1730                 :            : 
+    1731         [ -  + ]:         10 :         LIBSPDM_ASSERT(measurement_data_size <=
+    1732                 :            :                        LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE);
+    1733                 :            : 
+    1734                 :            :         /* get required data and hash them*/
+    1735                 :         10 :         cached_measurement_block = (void *)device_measurement;
+    1736                 :         10 :         measurement_data_size = 0;
+    1737         [ +  + ]:         90 :         for (index = 0; index < device_measurement_count; index++) {
+    1738                 :         80 :             measurement_block_size =
+    1739                 :            :                 sizeof(spdm_measurement_block_common_header_t) +
+    1740                 :            :                 cached_measurement_block
+    1741                 :            :                 ->measurement_block_common_header
+    1742                 :         80 :                 .measurement_size;
+    1743                 :            :             /* filter unneeded data*/
+    1744         [ +  + ]:         80 :             if ((measurement_summary_hash_type ==
+    1745                 :         40 :                  SPDM_REQUEST_ALL_MEASUREMENTS_HASH) ||
+    1746                 :            :                 ((cached_measurement_block
+    1747                 :            :                   ->measurement_block_dmtf_header
+    1748         [ +  + ]:         40 :                   .dmtf_spec_measurement_value_type &
+    1749                 :            :                   SPDM_MEASUREMENT_BLOCK_MEASUREMENT_TYPE_MASK) ==
+    1750                 :            :                  SPDM_MEASUREMENT_BLOCK_MEASUREMENT_TYPE_IMMUTABLE_ROM)) {
+    1751                 :         50 :                 libspdm_copy_mem(&measurement_data[measurement_data_size],
+    1752                 :            :                                  sizeof(measurement_data)
+    1753                 :         50 :                                  - (&measurement_data[measurement_data_size] - measurement_data),
+    1754                 :            :                                  cached_measurement_block,
+    1755                 :            :                                  sizeof(cached_measurement_block->
+    1756                 :            :                                         measurement_block_common_header) +
+    1757                 :            :                                  cached_measurement_block->measurement_block_common_header
+    1758                 :         50 :                                  .measurement_size);
+    1759                 :         50 :                 measurement_data_size +=
+    1760                 :            :                     sizeof(cached_measurement_block->measurement_block_common_header) +
+    1761                 :            :                     cached_measurement_block
+    1762                 :            :                     ->measurement_block_common_header
+    1763                 :         50 :                     .measurement_size;
+    1764                 :            :             }
+    1765                 :         80 :             cached_measurement_block =
+    1766                 :         80 :                 (void *)((size_t)cached_measurement_block +
+    1767                 :            :                          measurement_block_size);
+    1768                 :            :         }
+    1769                 :            : 
+    1770                 :         10 :         result = libspdm_hash_all(base_hash_algo, measurement_data,
+    1771                 :            :                                   measurement_data_size, measurement_summary_hash);
+    1772         [ -  + ]:         10 :         if (!result) {
+    1773                 :          0 :             return false;
+    1774                 :            :         }
+    1775                 :         10 :         break;
+    1776                 :          0 :     default:
+    1777                 :          0 :         return false;
+    1778                 :            :         break;
+    1779                 :            :     }
+    1780                 :         10 :     return true;
+    1781                 :            : }
+    1782                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP */
+    1783                 :            : 
+    1784                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP
+    1785                 :            : size_t libspdm_secret_lib_challenge_opaque_data_size;
+    1786                 :            : 
+    1787                 :          8 : bool libspdm_challenge_opaque_data(
+    1788                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    1789                 :            :     void *spdm_context,
+    1790                 :            : #endif
+    1791                 :            :     spdm_version_number_t spdm_version,
+    1792                 :            :     uint8_t slot_id,
+    1793                 :            :     uint8_t *measurement_summary_hash,
+    1794                 :            :     size_t measurement_summary_hash_size,
+    1795                 :            :     void *opaque_data,
+    1796                 :            :     size_t *opaque_data_size)
+    1797                 :            : {
+    1798                 :            :     size_t index;
+    1799                 :            : 
+    1800         [ -  + ]:          8 :     LIBSPDM_ASSERT(libspdm_secret_lib_challenge_opaque_data_size <= *opaque_data_size);
+    1801                 :            : 
+    1802                 :          8 :     *opaque_data_size = libspdm_secret_lib_challenge_opaque_data_size;
+    1803                 :            : 
+    1804         [ +  + ]:         16 :     for (index = 0; index < *opaque_data_size; index++)
+    1805                 :            :     {
+    1806                 :          8 :         ((uint8_t *)opaque_data)[index] = (uint8_t)index;
+    1807                 :            :     }
+    1808                 :            : 
+    1809                 :          8 :     return true;
+    1810                 :            : }
+    1811                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP */
+    1812                 :            : 
+    1813                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP
+    1814                 :          3 : bool libspdm_encap_challenge_opaque_data(
+    1815                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    1816                 :            :     void *spdm_context,
+    1817                 :            : #endif
+    1818                 :            :     spdm_version_number_t spdm_version,
+    1819                 :            :     uint8_t slot_id,
+    1820                 :            :     uint8_t *measurement_summary_hash,
+    1821                 :            :     size_t measurement_summary_hash_size,
+    1822                 :            :     void *opaque_data,
+    1823                 :            :     size_t *opaque_data_size)
+    1824                 :            : {
+    1825                 :            :     size_t index;
+    1826                 :            : 
+    1827         [ -  + ]:          3 :     LIBSPDM_ASSERT(libspdm_secret_lib_challenge_opaque_data_size <= *opaque_data_size);
+    1828                 :            : 
+    1829                 :          3 :     *opaque_data_size = libspdm_secret_lib_challenge_opaque_data_size;
+    1830                 :            : 
+    1831         [ -  + ]:          3 :     for (index = 0; index < *opaque_data_size; index++)
+    1832                 :            :     {
+    1833                 :          0 :         ((uint8_t *)opaque_data)[index] = (uint8_t)index;
+    1834                 :            :     }
+    1835                 :            : 
+    1836                 :          3 :     return true;
+    1837                 :            : }
+    1838                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP */
+    1839                 :            : 
+    1840                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MEL_CAP
+    1841                 :            : /*Collect the measurement extension log.*/
+    1842                 :         11 : bool libspdm_measurement_extension_log_collection(
+    1843                 :            :     void *spdm_context,
+    1844                 :            :     uint8_t mel_specification,
+    1845                 :            :     uint8_t measurement_specification,
+    1846                 :            :     uint32_t measurement_hash_algo,
+    1847                 :            :     void **spdm_mel,
+    1848                 :            :     size_t *spdm_mel_size)
+    1849                 :            : {
+    1850                 :            :     spdm_measurement_extension_log_dmtf_t *measurement_extension_log;
+    1851                 :            : 
+    1852         [ +  - ]:         11 :     if ((measurement_specification !=
+    1853         [ +  - ]:         11 :          SPDM_MEASUREMENT_SPECIFICATION_DMTF) ||
+    1854         [ -  + ]:         11 :         (mel_specification != SPDM_MEL_SPECIFICATION_DMTF) ||
+    1855                 :            :         (measurement_hash_algo == 0)) {
+    1856                 :          0 :         return false;
+    1857                 :            :     }
+    1858                 :            : 
+    1859                 :         11 :     libspdm_generate_mel(measurement_hash_algo);
+    1860                 :            : 
+    1861                 :         11 :     measurement_extension_log = (spdm_measurement_extension_log_dmtf_t *)m_libspdm_mel;
+    1862                 :         11 :     *spdm_mel = (spdm_measurement_extension_log_dmtf_t *)m_libspdm_mel;
+    1863                 :         11 :     *spdm_mel_size = (size_t)(measurement_extension_log->mel_entries_len) +
+    1864                 :            :                      sizeof(spdm_measurement_extension_log_dmtf_t);
+    1865                 :         11 :     return true;
+    1866                 :            : }
+    1867                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEL_CAP */
+    1868                 :            : 
+    1869                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP
+    1870                 :         24 : bool libspdm_requester_data_sign(
+    1871                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    1872                 :            :     void *spdm_context,
+    1873                 :            : #endif
+    1874                 :            :     spdm_version_number_t spdm_version, uint8_t op_code,
+    1875                 :            :     uint16_t req_base_asym_alg,
+    1876                 :            :     uint32_t base_hash_algo, bool is_data_hash,
+    1877                 :            :     const uint8_t *message, size_t message_size,
+    1878                 :            :     uint8_t *signature, size_t *sig_size)
+    1879                 :            : {
+    1880                 :            :     void *context;
+    1881                 :            :     bool result;
+    1882                 :            : 
+    1883                 :            : #if !LIBSPDM_PRIVATE_KEY_MODE_RAW_KEY_ONLY
+    1884         [ +  - ]:         24 :     if (g_private_key_mode) {
+    1885                 :            :         void *private_pem;
+    1886                 :            :         size_t private_pem_size;
+    1887                 :            : 
+    1888                 :         24 :         result = libspdm_read_requester_private_key(
+    1889                 :            :             req_base_asym_alg, &private_pem, &private_pem_size);
+    1890         [ -  + ]:         24 :         if (!result) {
+    1891                 :          0 :             return false;
+    1892                 :            :         }
+    1893                 :            : 
+    1894                 :         24 :         result = libspdm_req_asym_get_private_key_from_pem(req_base_asym_alg,
+    1895                 :            :                                                            private_pem,
+    1896                 :            :                                                            private_pem_size, NULL,
+    1897                 :            :                                                            &context);
+    1898         [ -  + ]:         24 :         if (!result) {
+    1899                 :          0 :             libspdm_zero_mem(private_pem, private_pem_size);
+    1900                 :          0 :             free(private_pem);
+    1901                 :          0 :             return false;
+    1902                 :            :         }
+    1903                 :            : 
+    1904         [ +  + ]:         24 :         if (is_data_hash) {
+    1905                 :          8 :             result = libspdm_req_asym_sign_hash(spdm_version, op_code, req_base_asym_alg,
+    1906                 :            :                                                 base_hash_algo, context,
+    1907                 :            :                                                 message, message_size, signature, sig_size);
+    1908                 :            :         } else {
+    1909                 :         16 :             result = libspdm_req_asym_sign(spdm_version, op_code, req_base_asym_alg,
+    1910                 :            :                                            base_hash_algo, context,
+    1911                 :            :                                            message, message_size,
+    1912                 :            :                                            signature, sig_size);
+    1913                 :            :         }
+    1914                 :         24 :         libspdm_req_asym_free(req_base_asym_alg, context);
+    1915                 :         24 :         libspdm_zero_mem(private_pem, private_pem_size);
+    1916                 :         24 :         free(private_pem);
+    1917                 :            :     } else {
+    1918                 :            : #endif
+    1919                 :          0 :     result = libspdm_get_requester_private_key_from_raw_data(req_base_asym_alg, &context);
+    1920         [ #  # ]:          0 :     if (!result) {
+    1921                 :          0 :         return false;
+    1922                 :            :     }
+    1923                 :            : 
+    1924         [ #  # ]:          0 :     if (is_data_hash) {
+    1925                 :          0 :         result = libspdm_req_asym_sign_hash(spdm_version, op_code, req_base_asym_alg,
+    1926                 :            :                                             base_hash_algo, context,
+    1927                 :            :                                             message, message_size, signature, sig_size);
+    1928                 :            :     } else {
+    1929                 :          0 :         result = libspdm_req_asym_sign(spdm_version, op_code, req_base_asym_alg,
+    1930                 :            :                                        base_hash_algo, context,
+    1931                 :            :                                        message, message_size,
+    1932                 :            :                                        signature, sig_size);
+    1933                 :            :     }
+    1934                 :          0 :     libspdm_req_asym_free(req_base_asym_alg, context);
+    1935                 :            : #if !LIBSPDM_PRIVATE_KEY_MODE_RAW_KEY_ONLY
+    1936                 :            : }
+    1937                 :            : #endif
+    1938                 :            : 
+    1939                 :            : #if LIBSPDM_SECRET_LIB_SIGN_LITTLE_ENDIAN
+    1940                 :            :     if ((spdm_version >> SPDM_VERSION_NUMBER_SHIFT_BIT) <= SPDM_MESSAGE_VERSION_11) {
+    1941                 :            :         if (result) {
+    1942                 :            :             libspdm_copy_signature_swap_endian(
+    1943                 :            :                 req_base_asym_alg, signature, *sig_size, signature, *sig_size);
+    1944                 :            :         }
+    1945                 :            :     }
+    1946                 :            : #endif
+    1947                 :            : 
+    1948                 :         24 :     return result;
+    1949                 :            : }
+    1950                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP */
+    1951                 :            : 
+    1952                 :        121 : bool libspdm_responder_data_sign(
+    1953                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    1954                 :            :     void *spdm_context,
+    1955                 :            : #endif
+    1956                 :            :     spdm_version_number_t spdm_version, uint8_t op_code,
+    1957                 :            :     uint32_t base_asym_algo,
+    1958                 :            :     uint32_t base_hash_algo, bool is_data_hash,
+    1959                 :            :     const uint8_t *message, size_t message_size,
+    1960                 :            :     uint8_t *signature, size_t *sig_size)
+    1961                 :            : {
+    1962                 :            :     void *context;
+    1963                 :            :     bool result;
+    1964                 :            : #if !LIBSPDM_PRIVATE_KEY_MODE_RAW_KEY_ONLY
+    1965         [ +  - ]:        121 :     if (g_private_key_mode) {
+    1966                 :            :         void *private_pem;
+    1967                 :            :         size_t private_pem_size;
+    1968                 :            : 
+    1969                 :        121 :         result = libspdm_read_responder_private_key(
+    1970                 :            :             base_asym_algo, &private_pem, &private_pem_size);
+    1971         [ -  + ]:        121 :         if (!result) {
+    1972                 :          0 :             return false;
+    1973                 :            :         }
+    1974                 :            : 
+    1975                 :        121 :         result = libspdm_asym_get_private_key_from_pem(
+    1976                 :            :             base_asym_algo, private_pem, private_pem_size, NULL, &context);
+    1977         [ -  + ]:        121 :         if (!result) {
+    1978                 :          0 :             libspdm_zero_mem(private_pem, private_pem_size);
+    1979                 :          0 :             free(private_pem);
+    1980                 :          0 :             return false;
+    1981                 :            :         }
+    1982                 :            : 
+    1983         [ +  + ]:        121 :         if (is_data_hash) {
+    1984                 :         35 :             result = libspdm_asym_sign_hash(spdm_version, op_code, base_asym_algo, base_hash_algo,
+    1985                 :            :                                             context,
+    1986                 :            :                                             message, message_size, signature, sig_size);
+    1987                 :            :         } else {
+    1988                 :         86 :             result = libspdm_asym_sign(spdm_version, op_code, base_asym_algo,
+    1989                 :            :                                        base_hash_algo, context,
+    1990                 :            :                                        message, message_size,
+    1991                 :            :                                        signature, sig_size);
+    1992                 :            :         }
+    1993                 :        121 :         libspdm_asym_free(base_asym_algo, context);
+    1994                 :        121 :         libspdm_zero_mem(private_pem, private_pem_size);
+    1995                 :        121 :         free(private_pem);
+    1996                 :            :     } else {
+    1997                 :            : #endif
+    1998                 :          0 :     result = libspdm_get_responder_private_key_from_raw_data(base_asym_algo, &context);
+    1999         [ #  # ]:          0 :     if (!result) {
+    2000                 :          0 :         return false;
+    2001                 :            :     }
+    2002                 :            : 
+    2003         [ #  # ]:          0 :     if (is_data_hash) {
+    2004                 :          0 :         result = libspdm_asym_sign_hash(spdm_version, op_code, base_asym_algo, base_hash_algo,
+    2005                 :            :                                         context,
+    2006                 :            :                                         message, message_size, signature, sig_size);
+    2007                 :            :     } else {
+    2008                 :          0 :         result = libspdm_asym_sign(spdm_version, op_code, base_asym_algo,
+    2009                 :            :                                    base_hash_algo, context,
+    2010                 :            :                                    message, message_size,
+    2011                 :            :                                    signature, sig_size);
+    2012                 :            :     }
+    2013                 :          0 :     libspdm_asym_free(base_asym_algo, context);
+    2014                 :            : #if !LIBSPDM_PRIVATE_KEY_MODE_RAW_KEY_ONLY
+    2015                 :            : }
+    2016                 :            : #endif
+    2017                 :            : 
+    2018                 :            : #if LIBSPDM_SECRET_LIB_SIGN_LITTLE_ENDIAN
+    2019                 :            :     if ((spdm_version >> SPDM_VERSION_NUMBER_SHIFT_BIT) <= SPDM_MESSAGE_VERSION_11) {
+    2020                 :            :         if (result) {
+    2021                 :            :             libspdm_copy_signature_swap_endian(
+    2022                 :            :                 base_asym_algo, signature, *sig_size, signature, *sig_size);
+    2023                 :            :         }
+    2024                 :            :     }
+    2025                 :            : #endif
+    2026                 :            : 
+    2027                 :        121 :     return result;
+    2028                 :            : }
+    2029                 :            : 
+    2030                 :            : #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
+    2031                 :            : 
+    2032                 :            : uint8_t m_libspdm_my_zero_filled_buffer[LIBSPDM_MAX_HASH_SIZE];
+    2033                 :            : uint8_t m_libspdm_my_salt0[LIBSPDM_MAX_HASH_SIZE];
+    2034                 :            : uint8_t m_libspdm_bin_str0[0x11] = {
+    2035                 :            :     0x00, 0x00, /* length - to be filled*/
+    2036                 :            :     /* SPDM_VERSION_1_1_BIN_CONCAT_LABEL */
+    2037                 :            :     0x73, 0x70, 0x64, 0x6d, 0x31, 0x2e, 0x31, 0x20,
+    2038                 :            :     /* SPDM_BIN_STR_0_LABEL */
+    2039                 :            :     0x64, 0x65, 0x72, 0x69, 0x76, 0x65, 0x64,
+    2040                 :            : };
+    2041                 :            : 
+    2042                 :         71 : bool libspdm_psk_handshake_secret_hkdf_expand(
+    2043                 :            :     spdm_version_number_t spdm_version,
+    2044                 :            :     uint32_t base_hash_algo,
+    2045                 :            :     const uint8_t *psk_hint,
+    2046                 :            :     size_t psk_hint_size,
+    2047                 :            :     const uint8_t *info,
+    2048                 :            :     size_t info_size,
+    2049                 :            :     uint8_t *out, size_t out_size)
+    2050                 :            : {
+    2051                 :            :     void *psk;
+    2052                 :            :     size_t psk_size;
+    2053                 :            :     size_t hash_size;
+    2054                 :            :     bool result;
+    2055                 :            :     uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    2056                 :            : 
+    2057         [ -  + ]:         71 :     if ((spdm_version >> SPDM_VERSION_NUMBER_SHIFT_BIT) >= SPDM_MESSAGE_VERSION_13) {
+    2058                 :          0 :         libspdm_set_mem(m_libspdm_my_salt0, sizeof(m_libspdm_my_salt0), 0xff);
+    2059                 :            :     }
+    2060                 :            : 
+    2061         [ +  + ]:         71 :     if (psk_hint_size == 0) {
+    2062                 :          4 :         psk = LIBSPDM_TEST_PSK_DATA_STRING;
+    2063                 :          4 :         psk_size = sizeof(LIBSPDM_TEST_PSK_DATA_STRING);
+    2064         [ +  - ]:         67 :     } else if ((strcmp((const char *)psk_hint, LIBSPDM_TEST_PSK_HINT_STRING) ==
+    2065         [ +  - ]:         67 :                 0) &&
+    2066                 :            :                (psk_hint_size == sizeof(LIBSPDM_TEST_PSK_HINT_STRING))) {
+    2067                 :         67 :         psk = LIBSPDM_TEST_PSK_DATA_STRING;
+    2068                 :         67 :         psk_size = sizeof(LIBSPDM_TEST_PSK_DATA_STRING);
+    2069                 :            :     } else {
+    2070                 :          0 :         return false;
+    2071                 :            :     }
+    2072                 :         71 :     printf("[PSK]: ");
+    2073                 :         71 :     libspdm_dump_hex_str(psk, psk_size);
+    2074                 :         71 :     printf("\n");
+    2075                 :            : 
+    2076                 :         71 :     hash_size = libspdm_get_hash_size(base_hash_algo);
+    2077                 :            : 
+    2078                 :         71 :     result = libspdm_hkdf_extract(base_hash_algo, psk, psk_size, m_libspdm_my_salt0,
+    2079                 :            :                                   hash_size, handshake_secret, hash_size);
+    2080         [ -  + ]:         71 :     if (!result) {
+    2081                 :          0 :         return result;
+    2082                 :            :     }
+    2083                 :            : 
+    2084                 :         71 :     result = libspdm_hkdf_expand(base_hash_algo, handshake_secret, hash_size,
+    2085                 :            :                                  info, info_size, out, out_size);
+    2086                 :         71 :     libspdm_zero_mem(handshake_secret, hash_size);
+    2087                 :            : 
+    2088                 :         71 :     return result;
+    2089                 :            : }
+    2090                 :            : 
+    2091                 :         33 : bool libspdm_psk_master_secret_hkdf_expand(
+    2092                 :            :     spdm_version_number_t spdm_version,
+    2093                 :            :     uint32_t base_hash_algo,
+    2094                 :            :     const uint8_t *psk_hint,
+    2095                 :            :     size_t psk_hint_size,
+    2096                 :            :     const uint8_t *info,
+    2097                 :            :     size_t info_size, uint8_t *out,
+    2098                 :            :     size_t out_size)
+    2099                 :            : {
+    2100                 :            :     void *psk;
+    2101                 :            :     size_t psk_size;
+    2102                 :            :     size_t hash_size;
+    2103                 :            :     bool result;
+    2104                 :            :     uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    2105                 :            :     uint8_t salt1[LIBSPDM_MAX_HASH_SIZE];
+    2106                 :            :     uint8_t master_secret[LIBSPDM_MAX_HASH_SIZE];
+    2107                 :            : 
+    2108         [ -  + ]:         33 :     if (psk_hint_size == 0) {
+    2109                 :          0 :         psk = LIBSPDM_TEST_PSK_DATA_STRING;
+    2110                 :          0 :         psk_size = sizeof(LIBSPDM_TEST_PSK_DATA_STRING);
+    2111         [ +  - ]:         33 :     } else if ((strcmp((const char *)psk_hint, LIBSPDM_TEST_PSK_HINT_STRING) ==
+    2112         [ +  - ]:         33 :                 0) &&
+    2113                 :            :                (psk_hint_size == sizeof(LIBSPDM_TEST_PSK_HINT_STRING))) {
+    2114                 :         33 :         psk = LIBSPDM_TEST_PSK_DATA_STRING;
+    2115                 :         33 :         psk_size = sizeof(LIBSPDM_TEST_PSK_DATA_STRING);
+    2116                 :            :     } else {
+    2117                 :          0 :         return false;
+    2118                 :            :     }
+    2119                 :            : 
+    2120                 :         33 :     hash_size = libspdm_get_hash_size(base_hash_algo);
+    2121                 :            : 
+    2122                 :         33 :     result = libspdm_hkdf_extract(base_hash_algo, psk, psk_size, m_libspdm_my_salt0,
+    2123                 :            :                                   hash_size, handshake_secret, hash_size);
+    2124         [ -  + ]:         33 :     if (!result) {
+    2125                 :          0 :         return result;
+    2126                 :            :     }
+    2127                 :            : 
+    2128                 :         33 :     *(uint16_t *)m_libspdm_bin_str0 = (uint16_t)hash_size;
+    2129                 :            :     /* patch the version*/
+    2130                 :         33 :     m_libspdm_bin_str0[6] = (char)('0' + ((spdm_version >> 12) & 0xF));
+    2131                 :         33 :     m_libspdm_bin_str0[8] = (char)('0' + ((spdm_version >> 8) & 0xF));
+    2132                 :         33 :     result = libspdm_hkdf_expand(base_hash_algo, handshake_secret, hash_size,
+    2133                 :            :                                  m_libspdm_bin_str0, sizeof(m_libspdm_bin_str0), salt1,
+    2134                 :            :                                  hash_size);
+    2135                 :         33 :     libspdm_zero_mem(handshake_secret, hash_size);
+    2136         [ -  + ]:         33 :     if (!result) {
+    2137                 :          0 :         return result;
+    2138                 :            :     }
+    2139                 :            : 
+    2140                 :         33 :     result = libspdm_hkdf_extract(base_hash_algo, m_libspdm_my_zero_filled_buffer,
+    2141                 :            :                                   hash_size, salt1, hash_size, master_secret, hash_size);
+    2142                 :         33 :     libspdm_zero_mem(salt1, hash_size);
+    2143         [ -  + ]:         33 :     if (!result) {
+    2144                 :          0 :         return result;
+    2145                 :            :     }
+    2146                 :            : 
+    2147                 :         33 :     result = libspdm_hkdf_expand(base_hash_algo, master_secret, hash_size,
+    2148                 :            :                                  info, info_size, out, out_size);
+    2149                 :         33 :     libspdm_zero_mem(master_secret, hash_size);
+    2150                 :            : 
+    2151                 :         33 :     return result;
+    2152                 :            : }
+    2153                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP */
+    2154                 :            : 
+    2155                 :            : #if LIBSPDM_ENABLE_CAPABILITY_SET_CERT_CAP
+    2156                 :         11 : bool libspdm_is_in_trusted_environment(
+    2157                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    2158                 :            :     void *spdm_context
+    2159                 :            : #endif
+    2160                 :            :     )
+    2161                 :            : {
+    2162                 :         11 :     return g_in_trusted_environment;
+    2163                 :            : }
+    2164                 :            : 
+    2165                 :          8 : bool libspdm_write_certificate_to_nvm(
+    2166                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    2167                 :            :     void *spdm_context,
+    2168                 :            : #endif
+    2169                 :            :     uint8_t slot_id, const void * cert_chain,
+    2170                 :            :     size_t cert_chain_size,
+    2171                 :            :     uint32_t base_hash_algo, uint32_t base_asym_algo)
+    2172                 :            : {
+    2173                 :            : #if defined(_WIN32) || (defined(__clang__) && (defined (LIBSPDM_CPU_AARCH64) || \
+    2174                 :            :     defined(LIBSPDM_CPU_ARM)))
+    2175                 :            :     FILE *fp_out;
+    2176                 :            : #else
+    2177                 :            :     int64_t fp_out;
+    2178                 :            : #endif
+    2179                 :            : 
+    2180                 :          8 :     char file_name[] = "slot_id_0_cert_chain.der";
+    2181                 :            :     /*change the file name, for example: slot_id_1_cert_chain.der*/
+    2182                 :          8 :     file_name[8] = (char)(slot_id+'0');
+    2183                 :            : 
+    2184                 :            :     /*check the input parameter*/
+    2185         [ -  + ]:          8 :     if ((cert_chain == NULL) ^ (cert_chain_size == 0) ) {
+    2186                 :          0 :         return false;
+    2187                 :            :     }
+    2188                 :            : 
+    2189                 :            : #if defined(_WIN32) || (defined(__clang__) && (defined (LIBSPDM_CPU_AARCH64) || \
+    2190                 :            :     defined(LIBSPDM_CPU_ARM)))
+    2191                 :            :     if ((fp_out = fopen(file_name, "w+b")) == NULL) {
+    2192                 :            :         printf("Unable to open file %s\n", file_name);
+    2193                 :            :         return false;
+    2194                 :            :     }
+    2195                 :            : 
+    2196                 :            :     if (cert_chain != NULL) {
+    2197                 :            :         if ((fwrite(cert_chain, 1, cert_chain_size, fp_out)) != cert_chain_size) {
+    2198                 :            :             printf("Write output file error %s\n", file_name);
+    2199                 :            :             fclose(fp_out);
+    2200                 :            :             return false;
+    2201                 :            :         }
+    2202                 :            :     }
+    2203                 :            : 
+    2204                 :            :     fclose(fp_out);
+    2205                 :            : #else
+    2206         [ +  + ]:          8 :     if (cert_chain != NULL) {
+    2207         [ -  + ]:          7 :         if ((fp_out = open(file_name, O_WRONLY | O_CREAT, S_IRWXU)) == -1) {
+    2208                 :          0 :             printf("Unable to open file %s\n", file_name);
+    2209                 :          0 :             return false;
+    2210                 :            :         }
+    2211                 :            : 
+    2212         [ -  + ]:          7 :         if ((write(fp_out, cert_chain, cert_chain_size)) != cert_chain_size) {
+    2213                 :          0 :             printf("Write output file error %s\n", file_name);
+    2214                 :          0 :             close(fp_out);
+    2215                 :          0 :             return false;
+    2216                 :            :         }
+    2217                 :            :     } else {
+    2218         [ -  + ]:          1 :         if ((fp_out = open(file_name, O_WRONLY | O_TRUNC)) == -1) {
+    2219                 :          0 :             printf("Unable to open file %s\n", file_name);
+    2220                 :          0 :             return false;
+    2221                 :            :         }
+    2222                 :            : 
+    2223                 :          1 :         close(fp_out);
+    2224                 :            :     }
+    2225                 :            : 
+    2226                 :          8 :     close(fp_out);
+    2227                 :            : #endif
+    2228                 :            : 
+    2229                 :          8 :     return true;
+    2230                 :            : }
+    2231                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_SET_CERT_CAP */
+    2232                 :            : 
+    2233                 :            : #if LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP
+    2234                 :          1 : bool libspdm_event_get_types(
+    2235                 :            :     void *spdm_context,
+    2236                 :            :     spdm_version_number_t spdm_version,
+    2237                 :            :     void *supported_event_groups_list,
+    2238                 :            :     uint32_t *supported_event_groups_list_len,
+    2239                 :            :     uint8_t *event_group_count)
+    2240                 :            : {
+    2241                 :          1 :     *supported_event_groups_list_len = g_supported_event_groups_list_len;
+    2242                 :            : 
+    2243         [ +  + ]:          9 :     for (uint32_t index = 0; index < *supported_event_groups_list_len; index++)
+    2244                 :            :     {
+    2245                 :          8 :         ((char *)supported_event_groups_list)[index] = (char)index;
+    2246                 :            :     }
+    2247                 :            : 
+    2248                 :          1 :     *event_group_count = g_event_group_count;
+    2249                 :            : 
+    2250                 :          1 :     return true;
+    2251                 :            : }
+    2252                 :            : 
+    2253                 :          2 : bool libspdm_event_subscribe(
+    2254                 :            :     void *spdm_context,
+    2255                 :            :     spdm_version_number_t spdm_version,
+    2256                 :            :     uint8_t subscribe_event_group_count,
+    2257                 :            :     uint32_t subscribe_list_len,
+    2258                 :            :     const void *subscribe_list)
+    2259                 :            : {
+    2260         [ +  + ]:          2 :     if (subscribe_event_group_count == 0) {
+    2261   [ +  -  -  + ]:          1 :         if ((subscribe_list_len != 0) || (subscribe_list != NULL)) {
+    2262                 :          0 :             return false;
+    2263                 :            :         }
+    2264                 :            :     } else {
+    2265   [ +  -  -  + ]:          1 :         if ((subscribe_list_len == 0) || (subscribe_list == NULL)) {
+    2266                 :          0 :             return false;
+    2267                 :            :         }
+    2268                 :            :     }
+    2269                 :            : 
+    2270                 :          2 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+    2271                 :            :                    "subscribe_event_group_count == %d, subscribe_list_len = %d\n",
+    2272                 :            :                    subscribe_event_group_count, subscribe_list_len));
+    2273                 :            : 
+    2274         [ +  + ]:         20 :     for (uint32_t index = 0; index < subscribe_list_len; index++) {
+    2275                 :         18 :         printf("%02x ", ((const char *)subscribe_list)[index]);
+    2276                 :            :     }
+    2277                 :          2 :     printf("\n");
+    2278                 :            : 
+    2279                 :          2 :     return true;
+    2280                 :            : }
+    2281                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP */
+    2282                 :            : 
+    2283                 :            : #if LIBSPDM_ENABLE_CAPABILITY_GET_KEY_PAIR_INFO_CAP
+    2284                 :            : 
+    2285                 :          1 : void libspdm_init_key_pair_info(uint8_t total_key_pairs) {
+    2286                 :          1 :     uint8_t public_key_info_rsa[] = {0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7,
+    2287                 :            :                                      0x0D, 0x01, 0x01, 0x01, 0x05, 0x00};
+    2288                 :          1 :     uint8_t public_key_info_ecp256[] = {0x30, 0x13, 0x06, 0x07, 0x2A, 0x86, 0x48, 0xCE, 0x3D,
+    2289                 :            :                                         0x02, 0x01, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D,
+    2290                 :            :                                         0x03, 0x01, 0x07};
+    2291                 :          1 :     uint8_t public_key_info_ecp384[] = {0x30, 0x10, 0x06, 0x07, 0x2A, 0x86, 0x48, 0xCE, 0x3D,
+    2292                 :            :                                         0x02, 0x01, 0x06, 0x05, 0x2B, 0x81, 0x04, 0x00, 0x22};
+    2293                 :          1 :     uint8_t public_key_info_ecp521[] = {0x30, 0x10, 0x06, 0x07, 0x2A, 0x86, 0x48, 0xCE, 0x3D,
+    2294                 :            :                                         0x02, 0x01, 0x06, 0x05, 0x2B, 0x81, 0x04, 0x00, 0x23};
+    2295                 :          1 :     uint8_t public_key_info_sm2[] = {0x30, 0x13, 0x06, 0x07, 0x2A, 0x86, 0x48, 0xCE, 0x3D,
+    2296                 :            :                                      0x02, 0x01, 0x06, 0x08, 0x2A, 0x81, 0x1C, 0xCF, 0x55,
+    2297                 :            :                                      0x01, 0x82, 0x2D};
+    2298                 :          1 :     uint8_t public_key_info_ed25519[] = {0x30, 0x05, 0x06, 0x03, 0x2B, 0x65, 0x70};
+    2299                 :          1 :     uint8_t public_key_info_ed448[] = {0x30, 0x05, 0x06, 0x03, 0x2B, 0x65, 0x71};
+    2300                 :            :     uint8_t index;
+    2301                 :            :     /*provisioned key pair info*/
+    2302                 :            : 
+    2303                 :            :     /*key_pair_id 1*/
+    2304                 :          1 :     m_key_pair_info[0].capabilities = SPDM_KEY_PAIR_CAP_MASK;
+    2305                 :          1 :     m_key_pair_info[0].key_usage_capabilities = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+    2306                 :          1 :     m_key_pair_info[0].current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+    2307                 :          1 :     m_key_pair_info[0].asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_MASK;
+    2308                 :          1 :     m_key_pair_info[0].assoc_cert_slot_mask = 0x01;
+    2309                 :          1 :     m_key_pair_info[0].current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
+    2310                 :          1 :     m_key_pair_info[0].public_key_info_len = (uint16_t)sizeof(public_key_info_rsa);
+    2311                 :          1 :     libspdm_copy_mem(m_key_pair_info[0].public_key_info, m_key_pair_info[0].public_key_info_len,
+    2312                 :          1 :                      public_key_info_rsa, m_key_pair_info[0].public_key_info_len);
+    2313                 :            : 
+    2314                 :            :     /*key_pair_id 2*/
+    2315                 :          1 :     m_key_pair_info[1].capabilities = SPDM_KEY_PAIR_CAP_MASK;
+    2316                 :          1 :     m_key_pair_info[1].key_usage_capabilities = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+    2317                 :          1 :     m_key_pair_info[1].current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+    2318                 :          1 :     m_key_pair_info[1].asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_MASK;
+    2319                 :          1 :     m_key_pair_info[1].assoc_cert_slot_mask = 0x02;
+    2320                 :          1 :     m_key_pair_info[1].current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA3072;
+    2321                 :          1 :     m_key_pair_info[1].public_key_info_len = (uint16_t)sizeof(public_key_info_rsa);
+    2322                 :          1 :     libspdm_copy_mem(m_key_pair_info[1].public_key_info, m_key_pair_info[1].public_key_info_len,
+    2323                 :          1 :                      public_key_info_rsa, m_key_pair_info[1].public_key_info_len);
+    2324                 :            : 
+    2325                 :            :     /*key_pair_id 3*/
+    2326                 :          1 :     m_key_pair_info[2].capabilities = SPDM_KEY_PAIR_CAP_MASK;
+    2327                 :          1 :     m_key_pair_info[2].key_usage_capabilities = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+    2328                 :          1 :     m_key_pair_info[2].current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+    2329                 :          1 :     m_key_pair_info[2].asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_MASK;
+    2330                 :          1 :     m_key_pair_info[2].assoc_cert_slot_mask = 0x04;
+    2331                 :          1 :     m_key_pair_info[2].current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA4096;
+    2332                 :          1 :     m_key_pair_info[2].public_key_info_len = (uint16_t)sizeof(public_key_info_rsa);
+    2333                 :          1 :     libspdm_copy_mem(m_key_pair_info[2].public_key_info, m_key_pair_info[2].public_key_info_len,
+    2334                 :          1 :                      public_key_info_rsa, m_key_pair_info[2].public_key_info_len);
+    2335                 :            : 
+    2336                 :            :     /*key_pair_id 4*/
+    2337                 :          1 :     m_key_pair_info[3].capabilities = SPDM_KEY_PAIR_CAP_MASK;
+    2338                 :          1 :     m_key_pair_info[3].key_usage_capabilities = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+    2339                 :          1 :     m_key_pair_info[3].current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+    2340                 :          1 :     m_key_pair_info[3].asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_MASK;
+    2341                 :          1 :     m_key_pair_info[3].assoc_cert_slot_mask = 0x08;
+    2342                 :          1 :     m_key_pair_info[3].current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_ECC256;
+    2343                 :          1 :     m_key_pair_info[3].public_key_info_len = (uint16_t)sizeof(public_key_info_ecp256);
+    2344                 :          1 :     libspdm_copy_mem(m_key_pair_info[3].public_key_info, m_key_pair_info[3].public_key_info_len,
+    2345                 :          1 :                      public_key_info_ecp256, m_key_pair_info[3].public_key_info_len);
+    2346                 :            : 
+    2347                 :            :     /*key_pair_id 5*/
+    2348                 :          1 :     m_key_pair_info[4].capabilities = SPDM_KEY_PAIR_CAP_MASK;
+    2349                 :          1 :     m_key_pair_info[4].key_usage_capabilities = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+    2350                 :          1 :     m_key_pair_info[4].current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+    2351                 :          1 :     m_key_pair_info[4].asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_MASK;
+    2352                 :          1 :     m_key_pair_info[4].assoc_cert_slot_mask = 0x10;
+    2353                 :          1 :     m_key_pair_info[4].current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_ECC384;
+    2354                 :          1 :     m_key_pair_info[4].public_key_info_len = (uint16_t)sizeof(public_key_info_ecp384);
+    2355                 :          1 :     libspdm_copy_mem(m_key_pair_info[4].public_key_info, m_key_pair_info[4].public_key_info_len,
+    2356                 :          1 :                      public_key_info_ecp384, m_key_pair_info[4].public_key_info_len);
+    2357                 :            : 
+    2358                 :            :     /*key_pair_id 6*/
+    2359                 :          1 :     m_key_pair_info[5].capabilities = SPDM_KEY_PAIR_CAP_MASK;
+    2360                 :          1 :     m_key_pair_info[5].key_usage_capabilities = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+    2361                 :          1 :     m_key_pair_info[5].current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+    2362                 :          1 :     m_key_pair_info[5].asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_MASK;
+    2363                 :          1 :     m_key_pair_info[5].assoc_cert_slot_mask = 0x20;
+    2364                 :          1 :     m_key_pair_info[5].current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_ECC521;
+    2365                 :          1 :     m_key_pair_info[5].public_key_info_len = (uint16_t)sizeof(public_key_info_ecp521);
+    2366                 :          1 :     libspdm_copy_mem(m_key_pair_info[5].public_key_info, m_key_pair_info[5].public_key_info_len,
+    2367                 :          1 :                      public_key_info_ecp521, m_key_pair_info[5].public_key_info_len);
+    2368                 :            : 
+    2369                 :            :     /*key_pair_id 7*/
+    2370                 :          1 :     m_key_pair_info[6].capabilities = SPDM_KEY_PAIR_CAP_MASK;
+    2371                 :          1 :     m_key_pair_info[6].key_usage_capabilities = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+    2372                 :          1 :     m_key_pair_info[6].current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+    2373                 :          1 :     m_key_pair_info[6].asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_MASK;
+    2374                 :          1 :     m_key_pair_info[6].assoc_cert_slot_mask = 0x40;
+    2375                 :          1 :     m_key_pair_info[6].current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_SM2;
+    2376                 :          1 :     m_key_pair_info[6].public_key_info_len = (uint16_t)sizeof(public_key_info_sm2);
+    2377                 :          1 :     libspdm_copy_mem(m_key_pair_info[6].public_key_info, m_key_pair_info[6].public_key_info_len,
+    2378                 :          1 :                      public_key_info_sm2, m_key_pair_info[6].public_key_info_len);
+    2379                 :            : 
+    2380                 :            :     /*key_pair_id 8*/
+    2381                 :          1 :     m_key_pair_info[7].capabilities = SPDM_KEY_PAIR_CAP_MASK;
+    2382                 :          1 :     m_key_pair_info[7].key_usage_capabilities = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+    2383                 :          1 :     m_key_pair_info[7].current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+    2384                 :          1 :     m_key_pair_info[7].asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_MASK;
+    2385                 :          1 :     m_key_pair_info[7].assoc_cert_slot_mask = 0x80;
+    2386                 :          1 :     m_key_pair_info[7].current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_ED25519;
+    2387                 :          1 :     m_key_pair_info[7].public_key_info_len = (uint16_t)sizeof(public_key_info_ed25519);
+    2388                 :          1 :     libspdm_copy_mem(m_key_pair_info[7].public_key_info, m_key_pair_info[7].public_key_info_len,
+    2389                 :          1 :                      public_key_info_ed25519, m_key_pair_info[7].public_key_info_len);
+    2390                 :            : 
+    2391                 :            :     /*key_pair_id 9*/
+    2392                 :          1 :     m_key_pair_info[8].capabilities = SPDM_KEY_PAIR_CAP_MASK;
+    2393                 :          1 :     m_key_pair_info[8].key_usage_capabilities = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+    2394                 :          1 :     m_key_pair_info[8].current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+    2395                 :          1 :     m_key_pair_info[8].asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_MASK;
+    2396                 :          1 :     m_key_pair_info[8].assoc_cert_slot_mask = 0x00;
+    2397                 :          1 :     m_key_pair_info[8].current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_ED448;
+    2398                 :          1 :     m_key_pair_info[8].public_key_info_len = (uint16_t)sizeof(public_key_info_ed448);
+    2399                 :          1 :     libspdm_copy_mem(m_key_pair_info[8].public_key_info, m_key_pair_info[8].public_key_info_len,
+    2400                 :          1 :                      public_key_info_ed448, m_key_pair_info[8].public_key_info_len);
+    2401                 :            : 
+    2402                 :            :     /*provisioned more key pair info*/
+    2403         [ +  + ]:          8 :     for (index = 10; index <= total_key_pairs; index++) {
+    2404                 :          7 :         m_key_pair_info[index - 1].capabilities = SPDM_KEY_PAIR_CAP_MASK;
+    2405                 :          7 :         m_key_pair_info[index - 1].key_usage_capabilities = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+    2406                 :          7 :         m_key_pair_info[index - 1].current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+    2407                 :          7 :         m_key_pair_info[index - 1].asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_MASK;
+    2408                 :          7 :         m_key_pair_info[index - 1].assoc_cert_slot_mask = 0x00;
+    2409                 :          7 :         m_key_pair_info[index - 1].current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_ED448;
+    2410                 :          7 :         m_key_pair_info[index - 1].public_key_info_len = (uint16_t)sizeof(public_key_info_ed448);
+    2411                 :          7 :         libspdm_copy_mem(m_key_pair_info[index - 1].public_key_info,
+    2412                 :          7 :                          m_key_pair_info[index - 1].public_key_info_len,
+    2413                 :          7 :                          public_key_info_ed448, m_key_pair_info[index - 1].public_key_info_len);
+    2414                 :            :     }
+    2415                 :          1 : }
+    2416                 :            : 
+    2417                 :            : /**
+    2418                 :            :  * read the key pair info of the key_pair_id.
+    2419                 :            :  *
+    2420                 :            :  * @param  spdm_context               A pointer to the SPDM context.
+    2421                 :            :  * @param  key_pair_id                Indicate which key pair ID's information to retrieve.
+    2422                 :            :  *
+    2423                 :            :  * @param  capabilities               Indicate the capabilities of the requested key pairs.
+    2424                 :            :  * @param  key_usage_capabilities     Indicate the key usages the responder allows.
+    2425                 :            :  * @param  current_key_usage          Indicate the currently configured key usage for the requested key pairs ID.
+    2426                 :            :  * @param  asym_algo_capabilities     Indicate the asymmetric algorithms the Responder supports for this key pair ID.
+    2427                 :            :  * @param  current_asym_algo          Indicate the currently configured asymmetric algorithm for this key pair ID.
+    2428                 :            :  * @param  assoc_cert_slot_mask       This field is a bit mask representing the currently associated certificate slots.
+    2429                 :            :  * @param  public_key_info_len        On input, indicate the size in bytes of the destination buffer to store.
+    2430                 :            :  *                                    On output, indicate the size in bytes of the public_key_info.
+    2431                 :            :  *                                    It can be NULL, if public_key_info is not required.
+    2432                 :            :  * @param  public_key_info            A pointer to a destination buffer to store the public_key_info.
+    2433                 :            :  *                                    It can be NULL, if public_key_info is not required.
+    2434                 :            :  *
+    2435                 :            :  * @retval true  get key pair info successfully.
+    2436                 :            :  * @retval false get key pair info failed.
+    2437                 :            :  **/
+    2438                 :         14 : bool libspdm_read_key_pair_info(
+    2439                 :            :     void *spdm_context,
+    2440                 :            :     uint8_t key_pair_id,
+    2441                 :            :     uint16_t *capabilities,
+    2442                 :            :     uint16_t *key_usage_capabilities,
+    2443                 :            :     uint16_t *current_key_usage,
+    2444                 :            :     uint32_t *asym_algo_capabilities,
+    2445                 :            :     uint32_t *current_asym_algo,
+    2446                 :            :     uint8_t *assoc_cert_slot_mask,
+    2447                 :            :     uint16_t *public_key_info_len,
+    2448                 :            :     uint8_t *public_key_info)
+    2449                 :            : {
+    2450                 :            :     uint8_t total_key_pairs;
+    2451                 :            :     libspdm_data_parameter_t parameter;
+    2452                 :            :     size_t data_return_size;
+    2453                 :            :     libspdm_return_t status;
+    2454                 :            : 
+    2455                 :         14 :     parameter.location = LIBSPDM_DATA_LOCATION_LOCAL;
+    2456                 :         14 :     data_return_size = sizeof(uint8_t);
+    2457                 :         14 :     status = libspdm_get_data(spdm_context, LIBSPDM_DATA_TOTAL_KEY_PAIRS,
+    2458                 :            :                               &parameter, &total_key_pairs, &data_return_size);
+    2459         [ -  + ]:         14 :     if (status != LIBSPDM_STATUS_SUCCESS) {
+    2460                 :          0 :         return false;
+    2461                 :            :     }
+    2462                 :            : 
+    2463         [ -  + ]:         14 :     LIBSPDM_ASSERT(total_key_pairs <= LIBSPDM_MAX_KEY_PAIR_COUNT);
+    2464                 :            : 
+    2465         [ +  + ]:         14 :     if (g_need_init_key_pair_info) {
+    2466                 :          1 :         libspdm_init_key_pair_info(total_key_pairs);
+    2467                 :          1 :         g_need_init_key_pair_info = false;
+    2468                 :            :     }
+    2469                 :            : 
+    2470                 :            :     /*check*/
+    2471         [ -  + ]:         14 :     if (key_pair_id > total_key_pairs) {
+    2472                 :          0 :         return false;
+    2473                 :            :     }
+    2474                 :            : 
+    2475         [ +  + ]:         14 :     if (public_key_info_len != NULL) {
+    2476         [ -  + ]:          1 :         if (*public_key_info_len < m_key_pair_info[key_pair_id - 1].public_key_info_len) {
+    2477                 :          0 :             return false;
+    2478                 :            :         }
+    2479                 :            :     }
+    2480                 :            : 
+    2481                 :            :     /*output*/
+    2482                 :         14 :     *capabilities = m_key_pair_info[key_pair_id - 1].capabilities;
+    2483                 :         14 :     *key_usage_capabilities = m_key_pair_info[key_pair_id - 1].key_usage_capabilities;
+    2484                 :         14 :     *current_key_usage = m_key_pair_info[key_pair_id - 1].current_key_usage;
+    2485                 :         14 :     *asym_algo_capabilities = m_key_pair_info[key_pair_id - 1].asym_algo_capabilities;
+    2486                 :         14 :     *current_asym_algo = m_key_pair_info[key_pair_id - 1].current_asym_algo;
+    2487                 :         14 :     *assoc_cert_slot_mask = m_key_pair_info[key_pair_id - 1].assoc_cert_slot_mask;
+    2488                 :            : 
+    2489         [ +  + ]:         14 :     if (public_key_info_len != NULL) {
+    2490                 :          1 :         *public_key_info_len = m_key_pair_info[key_pair_id - 1].public_key_info_len;
+    2491                 :            :     }
+    2492         [ +  + ]:         14 :     if (public_key_info != NULL) {
+    2493                 :          1 :         libspdm_copy_mem(public_key_info, *public_key_info_len,
+    2494                 :          1 :                          m_key_pair_info[key_pair_id - 1].public_key_info, *public_key_info_len);
+    2495                 :            : 
+    2496                 :            :     }
+    2497                 :            : 
+    2498                 :         14 :     return true;
+    2499                 :            : }
+    2500                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_GET_KEY_PAIR_INFO_CAP */
+    2501                 :            : 
+    2502                 :            : #if LIBSPDM_ENABLE_CAPABILITY_SET_KEY_PAIR_INFO_CAP
+    2503                 :            : 
+    2504                 :            : typedef struct
+    2505                 :            : {
+    2506                 :            :     uint8_t key_pair_id;
+    2507                 :            :     uint8_t operation;
+    2508                 :            :     uint16_t desired_key_usage;
+    2509                 :            :     uint32_t desired_asym_algo;
+    2510                 :            :     uint8_t desired_assoc_cert_slot_mask;
+    2511                 :            : } libspdm_cached_key_pair_info_data_t;
+    2512                 :            : 
+    2513                 :            : 
+    2514                 :          7 : bool libspdm_read_cached_last_set_key_pair_info_request(uint8_t **last_set_key_pair_info_request,
+    2515                 :            :                                                         size_t *last_set_key_pair_info_request_len)
+    2516                 :            : {
+    2517                 :            :     bool res;
+    2518                 :          7 :     char file[] = "cached_last_set_key_pair_info_request";
+    2519                 :            : 
+    2520                 :          7 :     res = libspdm_read_input_file(file, (void **)last_set_key_pair_info_request,
+    2521                 :            :                                   last_set_key_pair_info_request_len);
+    2522                 :            : 
+    2523                 :          7 :     return res;
+    2524                 :            : }
+    2525                 :            : 
+    2526                 :          4 : bool libspdm_cache_last_set_key_pair_info_request(const uint8_t *last_set_key_pair_info_request,
+    2527                 :            :                                                   size_t last_set_key_pair_info_request_len)
+    2528                 :            : {
+    2529                 :            :     bool res;
+    2530                 :          4 :     char file[] = "cached_last_set_key_pair_info_request";
+    2531                 :            : 
+    2532                 :          4 :     res = libspdm_write_output_file(file, last_set_key_pair_info_request,
+    2533                 :            :                                     last_set_key_pair_info_request_len);
+    2534                 :            : 
+    2535                 :          4 :     return res;
+    2536                 :            : }
+    2537                 :            : 
+    2538                 :         10 : bool libspdm_write_key_pair_info(
+    2539                 :            :     void *spdm_context,
+    2540                 :            :     uint8_t key_pair_id,
+    2541                 :            :     uint8_t operation,
+    2542                 :            :     uint16_t desired_key_usage,
+    2543                 :            :     uint32_t desired_asym_algo,
+    2544                 :            :     uint8_t desired_assoc_cert_slot_mask,
+    2545                 :            :     bool *need_reset)
+    2546                 :            : {
+    2547                 :            :     bool result;
+    2548                 :            :     libspdm_cached_key_pair_info_data_t *cached_key_pair_info;
+    2549                 :            :     libspdm_cached_key_pair_info_data_t current_key_pair_info;
+    2550                 :            :     size_t cached_key_pair_info_len;
+    2551                 :            : 
+    2552                 :            : 
+    2553                 :         10 :     cached_key_pair_info_len = 0;
+    2554         [ +  + ]:         10 :     if (*need_reset) {
+    2555                 :          7 :         result = libspdm_read_cached_last_set_key_pair_info_request(
+    2556                 :            :             (uint8_t **)&cached_key_pair_info,
+    2557                 :            :             &cached_key_pair_info_len);
+    2558                 :            : 
+    2559         [ +  + ]:          7 :         if ((result) &&
+    2560         [ +  - ]:          6 :             (cached_key_pair_info_len == sizeof(libspdm_cached_key_pair_info_data_t)) &&
+    2561         [ +  + ]:          6 :             (cached_key_pair_info->operation == operation) &&
+    2562         [ +  - ]:          4 :             (cached_key_pair_info->key_pair_id == key_pair_id) &&
+    2563         [ +  + ]:          4 :             (cached_key_pair_info->desired_key_usage == desired_key_usage) &&
+    2564         [ +  - ]:          3 :             (cached_key_pair_info->desired_asym_algo == desired_asym_algo) &&
+    2565         [ +  - ]:          3 :             (cached_key_pair_info->desired_assoc_cert_slot_mask == desired_assoc_cert_slot_mask)) {
+    2566         [ +  + ]:          3 :             if (operation == SPDM_SET_KEY_PAIR_INFO_ERASE_OPERATION) {
+    2567                 :          1 :                 m_key_pair_info[key_pair_id - 1].current_key_usage = 0;
+    2568                 :          1 :                 m_key_pair_info[key_pair_id - 1].current_asym_algo = 0;
+    2569                 :          1 :                 m_key_pair_info[key_pair_id - 1].assoc_cert_slot_mask = 0;
+    2570         [ -  + ]:          2 :             } else if (operation == SPDM_SET_KEY_PAIR_INFO_GENERATE_OPERATION) {
+    2571                 :          0 :                 m_key_pair_info[key_pair_id - 1].current_key_usage = desired_key_usage;
+    2572                 :          0 :                 m_key_pair_info[key_pair_id - 1].current_asym_algo = desired_asym_algo;
+    2573                 :          0 :                 m_key_pair_info[key_pair_id - 1].assoc_cert_slot_mask =
+    2574                 :            :                     desired_assoc_cert_slot_mask;
+    2575         [ +  - ]:          2 :             } else if (operation == SPDM_SET_KEY_PAIR_INFO_CHANGE_OPERATION) {
+    2576         [ +  + ]:          2 :                 if (desired_key_usage != 0) {
+    2577                 :          1 :                     m_key_pair_info[key_pair_id - 1].current_key_usage = desired_key_usage;
+    2578                 :            :                 }
+    2579         [ +  + ]:          2 :                 if (desired_asym_algo != 0) {
+    2580                 :          1 :                     m_key_pair_info[key_pair_id - 1].current_asym_algo = desired_asym_algo;
+    2581                 :            :                 }
+    2582                 :          2 :                 m_key_pair_info[key_pair_id - 1].assoc_cert_slot_mask =
+    2583                 :            :                     desired_assoc_cert_slot_mask;
+    2584                 :            :             } else {
+    2585                 :          0 :                 return false;
+    2586                 :            :             }
+    2587                 :            : 
+    2588                 :            :             /*device don't need reset this time*/
+    2589                 :          3 :             *need_reset = false;
+    2590                 :          3 :             free(cached_key_pair_info);
+    2591                 :          3 :             return true;
+    2592                 :            :         } else {
+    2593         [ +  + ]:          4 :             if (cached_key_pair_info != NULL) {
+    2594                 :          3 :                 free(cached_key_pair_info);
+    2595                 :            :             }
+    2596                 :            : 
+    2597                 :          4 :             current_key_pair_info.operation = operation;
+    2598                 :          4 :             current_key_pair_info.key_pair_id = key_pair_id;
+    2599                 :          4 :             current_key_pair_info.desired_key_usage = desired_key_usage;
+    2600                 :          4 :             current_key_pair_info.desired_asym_algo = desired_asym_algo;
+    2601                 :          4 :             current_key_pair_info.desired_assoc_cert_slot_mask = desired_assoc_cert_slot_mask;
+    2602                 :            :             /*device need reset this time: cache the last_set_key_pair_info_request */
+    2603                 :          4 :             result = libspdm_cache_last_set_key_pair_info_request(
+    2604                 :            :                 (const uint8_t *)&current_key_pair_info,
+    2605                 :            :                 sizeof(libspdm_cached_key_pair_info_data_t));
+    2606         [ -  + ]:          4 :             if (!result) {
+    2607                 :          0 :                 return result;
+    2608                 :            :             }
+    2609                 :            : 
+    2610                 :            :             /*device need reset this time*/
+    2611                 :          4 :             *need_reset = true;
+    2612                 :          4 :             return true;
+    2613                 :            :         }
+    2614                 :            :     } else {
+    2615         [ +  + ]:          3 :         if (operation == SPDM_SET_KEY_PAIR_INFO_ERASE_OPERATION) {
+    2616                 :          1 :             m_key_pair_info[key_pair_id - 1].current_key_usage = 0;
+    2617                 :          1 :             m_key_pair_info[key_pair_id - 1].current_asym_algo = 0;
+    2618                 :          1 :             m_key_pair_info[key_pair_id - 1].assoc_cert_slot_mask = 0;
+    2619         [ -  + ]:          2 :         } else if (operation == SPDM_SET_KEY_PAIR_INFO_GENERATE_OPERATION) {
+    2620                 :          0 :             m_key_pair_info[key_pair_id - 1].current_key_usage = desired_key_usage;
+    2621                 :          0 :             m_key_pair_info[key_pair_id - 1].current_asym_algo = desired_asym_algo;
+    2622                 :          0 :             m_key_pair_info[key_pair_id - 1].assoc_cert_slot_mask = desired_assoc_cert_slot_mask;
+    2623         [ +  - ]:          2 :         } else if (operation == SPDM_SET_KEY_PAIR_INFO_CHANGE_OPERATION) {
+    2624         [ +  + ]:          2 :             if (desired_key_usage != 0) {
+    2625                 :          1 :                 m_key_pair_info[key_pair_id - 1].current_key_usage = desired_key_usage;
+    2626                 :            :             }
+    2627         [ +  + ]:          2 :             if (desired_asym_algo != 0) {
+    2628                 :          1 :                 m_key_pair_info[key_pair_id - 1].current_asym_algo = desired_asym_algo;
+    2629                 :            :             }
+    2630                 :          2 :             m_key_pair_info[key_pair_id - 1].assoc_cert_slot_mask = desired_assoc_cert_slot_mask;
+    2631                 :            :         } else {
+    2632                 :          0 :             return false;
+    2633                 :            :         }
+    2634                 :            : 
+    2635                 :          3 :         return true;
+    2636                 :            :     }
+    2637                 :            : }
+    2638                 :            : #endif /* #if LIBSPDM_ENABLE_CAPABILITY_SET_KEY_PAIR_INFO_CAP */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/ruby.png b/coverage_log/ruby.png new file mode 100644 index 0000000000000000000000000000000000000000..991b6d4ec9e78be165e3ef757eed1aada287364d GIT binary patch literal 141 zcmeAS@N?(olHy`uVBq!ia0vp^j3CU&3?x-=hn)ga>?NMQuI!iC1^FceV#7`HfI^%F z9+AZi4BSE>%y{W;-5;PJOS+@4BLl<6e(pbstUx|nfKQ0)e^Y%R^MdiLxj>4`)5S5Q b;#P73kj=!v_*DHKNFRfztDnm{r-UW|iOwIS literal 0 HcmV?d00001 diff --git a/coverage_log/snow.png b/coverage_log/snow.png new file mode 100644 index 0000000000000000000000000000000000000000..2cdae107fceec6e7f02ac7acb4a34a82a540caa5 GIT binary patch literal 141 zcmeAS@N?(olHy`uVBq!ia0vp^j3CU&3?x-=hn)ga>?NMQuI!iC1^MM!lvI6;R0X`wF|Ns97GD8ntt^-nBo-U3d c6}OTTfNUlP#;5A{K>8RwUHx3vIVCg!071?oo&W#< literal 0 HcmV?d00001 diff --git a/coverage_log/unit_test/cmockalib/cmocka/src/cmocka.c.func-sort-c.html b/coverage_log/unit_test/cmockalib/cmocka/src/cmocka.c.func-sort-c.html new file mode 100644 index 00000000000..6c13f491c83 --- /dev/null +++ b/coverage_log/unit_test/cmockalib/cmocka/src/cmocka.c.func-sort-c.html @@ -0,0 +1,617 @@ + + + + + + + LCOV - coverage.info - unit_test/cmockalib/cmocka/src/cmocka.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/cmockalib/cmocka/src - cmocka.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:308146121.1 %
Date:2024-09-22 08:21:07Functions:4413432.8 %
Branches:8559814.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
_assert_double_equal0
_assert_double_not_equal0
_assert_float_equal0
_assert_float_not_equal0
_assert_in_range0
_assert_in_set0
_assert_not_in_range0
_assert_not_in_set0
_assert_return_code0
_assert_string_not_equal0
_check_expected0
_expect_any0
_expect_check0
_expect_function_call0
_expect_in_range0
_expect_in_set0
_expect_memory0
_expect_not_in_range0
_expect_not_in_set0
_expect_not_memory0
_expect_not_string0
_expect_not_value0
_expect_string0
_expect_value0
_fail0
_function_called0
_mock0
_run_group_tests0
_run_test0
_run_tests0
_skip0
_test_calloc0
_test_free0
_test_malloc0
_test_realloc0
_will_return0
add_symbol_value0
c_strmatch0
c_strreplace0
check_any0
check_in_range0
check_in_set0
check_memory0
check_not_in_range0
check_not_in_set0
check_not_memory0
check_not_string0
check_not_value0
check_string0
check_value0
cm_print_error0
cmocka_set_message_output0
cmocka_set_skip_filter0
cmocka_set_test_filter0
cmprintf_group_finish_tap0
cmprintf_group_finish_xml0
cmprintf_group_start_tap0
cmprintf_subunit0
cmprintf_tap0
double_compare0
double_values_equal_display_error0
double_values_not_equal_display_error0
exception_handler0
exit_test0
expect_memory_setup0
expect_range0
expect_set0
float_compare0
float_values_equal_display_error0
float_values_not_equal_display_error0
free_allocated_blocks0
free_symbol_map_value0
free_value0
get_symbol_value0
integer_in_range_display_error0
integer_not_in_range_display_error0
libc_realloc0
list_add0
list_add_value0
list_find0
list_first0
list_remove0
list_remove_free0
mock_assert0
set_source_location0
source_location_is_set0
string_not_equal_display_error0
symbol_names_match0
value_in_set_display_error0
vcm_print_error0
_assert_memory_not_equal6
memory_not_equal_display_error6
_assert_string_equal9
string_equal_display_error9
_assert_int_not_equal67
values_not_equal_display_error67
_cmocka_run_group_tests78
cmprintf_group_finish78
cmprintf_group_finish_standard78
cmprintf_group_start78
cmprintf_group_start_standard78
libc_calloc78
print_error78
vprint_error78
cmocka_run_group_fixture156
_assert_memory_equal384
memory_equal_display_error384
cmocka_run_one_tests1070
vcm_free_error1070
libc_free1148
check_point_allocated_blocks1161
display_allocated_blocks1226
fail_if_blocks_allocated1226
check_for_leftover_values_list1239
cmocka_run_one_test_or_fixture1239
fail_if_leftover_values1239
initialize_testing1239
remove_always_return_values_from_list1239
teardown_testing1239
cmprintf2140
cmprintf_standard2140
cm_get_output2296
print_message2296
vprint_message2296
get_allocated_blocks_list2387
check_for_leftover_values2478
remove_always_return_values2478
list_free3717
list_initialize3722
list_empty4956
initialize_source_location7434
_assert_int_equal24938
values_equal_display_error24938
_assert_true29996
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/cmockalib/cmocka/src/cmocka.c.func.html b/coverage_log/unit_test/cmockalib/cmocka/src/cmocka.c.func.html new file mode 100644 index 00000000000..00020e4b3db --- /dev/null +++ b/coverage_log/unit_test/cmockalib/cmocka/src/cmocka.c.func.html @@ -0,0 +1,617 @@ + + + + + + + LCOV - coverage.info - unit_test/cmockalib/cmocka/src/cmocka.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/cmockalib/cmocka/src - cmocka.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:308146121.1 %
Date:2024-09-22 08:21:07Functions:4413432.8 %
Branches:8559814.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
_assert_double_equal0
_assert_double_not_equal0
_assert_float_equal0
_assert_float_not_equal0
_assert_in_range0
_assert_in_set0
_assert_int_equal24938
_assert_int_not_equal67
_assert_memory_equal384
_assert_memory_not_equal6
_assert_not_in_range0
_assert_not_in_set0
_assert_return_code0
_assert_string_equal9
_assert_string_not_equal0
_assert_true29996
_check_expected0
_cmocka_run_group_tests78
_expect_any0
_expect_check0
_expect_function_call0
_expect_in_range0
_expect_in_set0
_expect_memory0
_expect_not_in_range0
_expect_not_in_set0
_expect_not_memory0
_expect_not_string0
_expect_not_value0
_expect_string0
_expect_value0
_fail0
_function_called0
_mock0
_run_group_tests0
_run_test0
_run_tests0
_skip0
_test_calloc0
_test_free0
_test_malloc0
_test_realloc0
_will_return0
add_symbol_value0
c_strmatch0
c_strreplace0
check_any0
check_for_leftover_values2478
check_for_leftover_values_list1239
check_in_range0
check_in_set0
check_memory0
check_not_in_range0
check_not_in_set0
check_not_memory0
check_not_string0
check_not_value0
check_point_allocated_blocks1161
check_string0
check_value0
cm_get_output2296
cm_print_error0
cmocka_run_group_fixture156
cmocka_run_one_test_or_fixture1239
cmocka_run_one_tests1070
cmocka_set_message_output0
cmocka_set_skip_filter0
cmocka_set_test_filter0
cmprintf2140
cmprintf_group_finish78
cmprintf_group_finish_standard78
cmprintf_group_finish_tap0
cmprintf_group_finish_xml0
cmprintf_group_start78
cmprintf_group_start_standard78
cmprintf_group_start_tap0
cmprintf_standard2140
cmprintf_subunit0
cmprintf_tap0
display_allocated_blocks1226
double_compare0
double_values_equal_display_error0
double_values_not_equal_display_error0
exception_handler0
exit_test0
expect_memory_setup0
expect_range0
expect_set0
fail_if_blocks_allocated1226
fail_if_leftover_values1239
float_compare0
float_values_equal_display_error0
float_values_not_equal_display_error0
free_allocated_blocks0
free_symbol_map_value0
free_value0
get_allocated_blocks_list2387
get_symbol_value0
initialize_source_location7434
initialize_testing1239
integer_in_range_display_error0
integer_not_in_range_display_error0
libc_calloc78
libc_free1148
libc_realloc0
list_add0
list_add_value0
list_empty4956
list_find0
list_first0
list_free3717
list_initialize3722
list_remove0
list_remove_free0
memory_equal_display_error384
memory_not_equal_display_error6
mock_assert0
print_error78
print_message2296
remove_always_return_values2478
remove_always_return_values_from_list1239
set_source_location0
source_location_is_set0
string_equal_display_error9
string_not_equal_display_error0
symbol_names_match0
teardown_testing1239
value_in_set_display_error0
values_equal_display_error24938
values_not_equal_display_error67
vcm_free_error1070
vcm_print_error0
vprint_error78
vprint_message2296
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/cmockalib/cmocka/src/cmocka.c.gcov.html b/coverage_log/unit_test/cmockalib/cmocka/src/cmocka.c.gcov.html new file mode 100644 index 00000000000..c08d2dd2f6b --- /dev/null +++ b/coverage_log/unit_test/cmockalib/cmocka/src/cmocka.c.gcov.html @@ -0,0 +1,3724 @@ + + + + + + + LCOV - coverage.info - unit_test/cmockalib/cmocka/src/cmocka.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/cmockalib/cmocka/src - cmocka.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:308146121.1 %
Date:2024-09-22 08:21:07Functions:4413432.8 %
Branches:8559814.2 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /*
+       2                 :            :  * Copyright 2008 Google Inc.
+       3                 :            :  * Copyright 2014-2018 Andreas Schneider <asn@cryptomilk.org>
+       4                 :            :  * Copyright 2015      Jakub Hrozek <jakub.hrozek@posteo.se>
+       5                 :            :  *
+       6                 :            :  * Licensed under the Apache License, Version 2.0 (the "License");
+       7                 :            :  * you may not use this file except in compliance with the License.
+       8                 :            :  * You may obtain a copy of the License at
+       9                 :            :  *
+      10                 :            :  * http://www.apache.org/licenses/LICENSE-2.0
+      11                 :            :  *
+      12                 :            :  * Unless required by applicable law or agreed to in writing, software
+      13                 :            :  * distributed under the License is distributed on an "AS IS" BASIS,
+      14                 :            :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+      15                 :            :  * See the License for the specific language governing permissions and
+      16                 :            :  * limitations under the License.
+      17                 :            :  */
+      18                 :            : #ifdef HAVE_CONFIG_H
+      19                 :            : #include "config.h"
+      20                 :            : #endif
+      21                 :            : 
+      22                 :            : #ifdef HAVE_MALLOC_H
+      23                 :            : #include <malloc.h>
+      24                 :            : #endif
+      25                 :            : 
+      26                 :            : #ifdef HAVE_INTTYPES_H
+      27                 :            : #include <inttypes.h>
+      28                 :            : #endif
+      29                 :            : 
+      30                 :            : #ifdef HAVE_SIGNAL_H
+      31                 :            : #include <signal.h>
+      32                 :            : #endif
+      33                 :            : 
+      34                 :            : #ifdef HAVE_STRINGS_H
+      35                 :            : #include <strings.h>
+      36                 :            : #endif
+      37                 :            : 
+      38                 :            : #include <stdint.h>
+      39                 :            : #include <setjmp.h>
+      40                 :            : #include <stdarg.h>
+      41                 :            : #include <stddef.h>
+      42                 :            : #include <stdio.h>
+      43                 :            : #include <stdlib.h>
+      44                 :            : #include <string.h>
+      45                 :            : #include <stdbool.h>
+      46                 :            : #include <time.h>
+      47                 :            : #include <float.h>
+      48                 :            : 
+      49                 :            : /*
+      50                 :            :  * This allows to add a platform specific header file. Some embedded platforms
+      51                 :            :  * sometimes miss certain types and definitions.
+      52                 :            :  *
+      53                 :            :  * Example:
+      54                 :            :  *
+      55                 :            :  * typedef unsigned long int uintptr_t
+      56                 :            :  * #define _UINTPTR_T 1
+      57                 :            :  * #define _UINTPTR_T_DEFINED 1
+      58                 :            :  */
+      59                 :            : #ifdef CMOCKA_PLATFORM_INCLUDE
+      60                 :            : # include "cmocka_platform.h"
+      61                 :            : #endif /* CMOCKA_PLATFORM_INCLUDE */
+      62                 :            : 
+      63                 :            : #include <cmocka.h>
+      64                 :            : #include <cmocka_private.h>
+      65                 :            : 
+      66                 :            : /* Size of guard bytes around dynamically allocated blocks. */
+      67                 :            : #define MALLOC_GUARD_SIZE 16
+      68                 :            : /* Pattern used to initialize guard blocks. */
+      69                 :            : #define MALLOC_GUARD_PATTERN 0xEF
+      70                 :            : /* Pattern used to initialize memory allocated with test_malloc(). */
+      71                 :            : #define MALLOC_ALLOC_PATTERN 0xBA
+      72                 :            : #define MALLOC_FREE_PATTERN 0xCD
+      73                 :            : /* Alignment of allocated blocks.  NOTE: This must be base2. */
+      74                 :            : #ifndef MALLOC_ALIGNMENT
+      75                 :            : #define MALLOC_ALIGNMENT sizeof(size_t)
+      76                 :            : #endif
+      77                 :            : 
+      78                 :            : /* Printf formatting for source code locations. */
+      79                 :            : #define SOURCE_LOCATION_FORMAT "%s:%u"
+      80                 :            : 
+      81                 :            : #if defined(HAVE_GCC_THREAD_LOCAL_STORAGE)
+      82                 :            : # define CMOCKA_THREAD __thread
+      83                 :            : #elif defined(HAVE_MSVC_THREAD_LOCAL_STORAGE)
+      84                 :            : # define CMOCKA_THREAD __declspec(thread)
+      85                 :            : #else
+      86                 :            : # define CMOCKA_THREAD
+      87                 :            : #endif
+      88                 :            : 
+      89                 :            : #ifdef HAVE_CLOCK_REALTIME
+      90                 :            : #define CMOCKA_CLOCK_GETTIME(clock_id, ts) clock_gettime((clock_id), (ts))
+      91                 :            : #else
+      92                 :            : #define CMOCKA_CLOCK_GETTIME(clock_id, ts)
+      93                 :            : #endif
+      94                 :            : 
+      95                 :            : #ifndef MAX
+      96                 :            : #define MAX(a,b) ((a) < (b) ? (b) : (a))
+      97                 :            : #endif
+      98                 :            : 
+      99                 :            : /**
+     100                 :            :  * POSIX has sigsetjmp/siglongjmp, while Windows only has setjmp/longjmp.
+     101                 :            :  */
+     102                 :            : #ifdef HAVE_SIGLONGJMP
+     103                 :            : # define cm_jmp_buf             sigjmp_buf
+     104                 :            : # define cm_setjmp(env)         sigsetjmp(env, 1)
+     105                 :            : # define cm_longjmp(env, val)   siglongjmp(env, val)
+     106                 :            : #else
+     107                 :            : # define cm_jmp_buf             jmp_buf
+     108                 :            : # define cm_setjmp(env)         setjmp(env)
+     109                 :            : # define cm_longjmp(env, val)   longjmp(env, val)
+     110                 :            : #endif
+     111                 :            : 
+     112                 :            : 
+     113                 :            : /*
+     114                 :            :  * Declare and initialize a LargestIntegralType variable name
+     115                 :            :  * with value the conversion of ptr.
+     116                 :            :  */
+     117                 :            : #define declare_initialize_value_pointer_pointer(name, ptr) \
+     118                 :            :     LargestIntegralType name ; \
+     119                 :            :     name = (LargestIntegralType) (uintptr_t) ptr
+     120                 :            : 
+     121                 :            : /* Cast a LargestIntegralType to pointer_type. */
+     122                 :            : #define cast_largest_integral_type_to_pointer( \
+     123                 :            :     pointer_type, largest_integral_type) \
+     124                 :            :     ((pointer_type)(uintptr_t)(largest_integral_type))
+     125                 :            : 
+     126                 :            : /* Doubly linked list node. */
+     127                 :            : typedef struct ListNode {
+     128                 :            :     const void *value;
+     129                 :            :     int refcount;
+     130                 :            :     struct ListNode *next;
+     131                 :            :     struct ListNode *prev;
+     132                 :            : } ListNode;
+     133                 :            : 
+     134                 :            : /* Debug information for malloc(). */
+     135                 :            : struct MallocBlockInfoData {
+     136                 :            :     void* block;              /* Address of the block returned by malloc(). */
+     137                 :            :     size_t allocated_size;    /* Total size of the allocated block. */
+     138                 :            :     size_t size;              /* Request block size. */
+     139                 :            :     SourceLocation location;  /* Where the block was allocated. */
+     140                 :            :     ListNode node;            /* Node within list of all allocated blocks. */
+     141                 :            : };
+     142                 :            : 
+     143                 :            : typedef union {
+     144                 :            :     struct MallocBlockInfoData *data;
+     145                 :            :     char *ptr;
+     146                 :            : } MallocBlockInfo;
+     147                 :            : 
+     148                 :            : /* State of each test. */
+     149                 :            : typedef struct TestState {
+     150                 :            :     const ListNode *check_point; /* Check point of the test if there's a */
+     151                 :            :                                  /* setup function. */
+     152                 :            :     void *state;                 /* State associated with the test. */
+     153                 :            : } TestState;
+     154                 :            : 
+     155                 :            : /* Determines whether two values are the same. */
+     156                 :            : typedef int (*EqualityFunction)(const void *left, const void *right);
+     157                 :            : 
+     158                 :            : /* Value of a symbol and the place it was declared. */
+     159                 :            : typedef struct SymbolValue {
+     160                 :            :     SourceLocation location;
+     161                 :            :     LargestIntegralType value;
+     162                 :            : } SymbolValue;
+     163                 :            : 
+     164                 :            : /*
+     165                 :            :  * Contains a list of values for a symbol.
+     166                 :            :  * NOTE: Each structure referenced by symbol_values_list_head must have a
+     167                 :            :  * SourceLocation as its' first member.
+     168                 :            :  */
+     169                 :            : typedef struct SymbolMapValue {
+     170                 :            :     const char *symbol_name;
+     171                 :            :     ListNode symbol_values_list_head;
+     172                 :            : } SymbolMapValue;
+     173                 :            : 
+     174                 :            : /* Where a particular ordering was located and its symbol name */
+     175                 :            : typedef struct FuncOrderingValue {
+     176                 :            :     SourceLocation location;
+     177                 :            :     const char * function;
+     178                 :            : } FuncOrderingValue;
+     179                 :            : 
+     180                 :            : /* Used by list_free() to deallocate values referenced by list nodes. */
+     181                 :            : typedef void (*CleanupListValue)(const void *value, void *cleanup_value_data);
+     182                 :            : 
+     183                 :            : /* Structure used to check the range of integer types.a */
+     184                 :            : typedef struct CheckIntegerRange {
+     185                 :            :     CheckParameterEvent event;
+     186                 :            :     LargestIntegralType minimum;
+     187                 :            :     LargestIntegralType maximum;
+     188                 :            : } CheckIntegerRange;
+     189                 :            : 
+     190                 :            : /* Structure used to check whether an integer value is in a set. */
+     191                 :            : typedef struct CheckIntegerSet {
+     192                 :            :     CheckParameterEvent event;
+     193                 :            :     const LargestIntegralType *set;
+     194                 :            :     size_t size_of_set;
+     195                 :            : } CheckIntegerSet;
+     196                 :            : 
+     197                 :            : /* Used to check whether a parameter matches the area of memory referenced by
+     198                 :            :  * this structure.  */
+     199                 :            : typedef struct CheckMemoryData {
+     200                 :            :     CheckParameterEvent event;
+     201                 :            :     const void *memory;
+     202                 :            :     size_t size;
+     203                 :            : } CheckMemoryData;
+     204                 :            : 
+     205                 :            : static ListNode* list_initialize(ListNode * const node);
+     206                 :            : static ListNode* list_add(ListNode * const head, ListNode *new_node);
+     207                 :            : static ListNode* list_add_value(ListNode * const head, const void *value,
+     208                 :            :                                      const int count);
+     209                 :            : static ListNode* list_remove(
+     210                 :            :     ListNode * const node, const CleanupListValue cleanup_value,
+     211                 :            :     void * const cleanup_value_data);
+     212                 :            : static void list_remove_free(
+     213                 :            :     ListNode * const node, const CleanupListValue cleanup_value,
+     214                 :            :     void * const cleanup_value_data);
+     215                 :            : static int list_empty(const ListNode * const head);
+     216                 :            : static int list_find(
+     217                 :            :     ListNode * const head, const void *value,
+     218                 :            :     const EqualityFunction equal_func, ListNode **output);
+     219                 :            : static int list_first(ListNode * const head, ListNode **output);
+     220                 :            : static ListNode* list_free(
+     221                 :            :     ListNode * const head, const CleanupListValue cleanup_value,
+     222                 :            :     void * const cleanup_value_data);
+     223                 :            : 
+     224                 :            : static void add_symbol_value(
+     225                 :            :     ListNode * const symbol_map_head, const char * const symbol_names[],
+     226                 :            :     const size_t number_of_symbol_names, const void* value, const int count);
+     227                 :            : static int get_symbol_value(
+     228                 :            :     ListNode * const symbol_map_head, const char * const symbol_names[],
+     229                 :            :     const size_t number_of_symbol_names, void **output);
+     230                 :            : static void free_value(const void *value, void *cleanup_value_data);
+     231                 :            : static void free_symbol_map_value(
+     232                 :            :     const void *value, void *cleanup_value_data);
+     233                 :            : static void remove_always_return_values(ListNode * const map_head,
+     234                 :            :                                         const size_t number_of_symbol_names);
+     235                 :            : 
+     236                 :            : static size_t check_for_leftover_values_list(const ListNode * head,
+     237                 :            :                                              const char * const error_message);
+     238                 :            : 
+     239                 :            : static size_t check_for_leftover_values(
+     240                 :            :     const ListNode * const map_head, const char * const error_message,
+     241                 :            :     const size_t number_of_symbol_names);
+     242                 :            : 
+     243                 :            : static void remove_always_return_values_from_list(ListNode * const map_head);
+     244                 :            : 
+     245                 :            : /*
+     246                 :            :  * This must be called at the beginning of a test to initialize some data
+     247                 :            :  * structures.
+     248                 :            :  */
+     249                 :            : static void initialize_testing(const char *test_name);
+     250                 :            : 
+     251                 :            : /* This must be called at the end of a test to free() allocated structures. */
+     252                 :            : static void teardown_testing(const char *test_name);
+     253                 :            : 
+     254                 :            : static enum cm_message_output cm_get_output(void);
+     255                 :            : 
+     256                 :            : static int cm_error_message_enabled = 1;
+     257                 :            : static CMOCKA_THREAD char *cm_error_message;
+     258                 :            : 
+     259                 :            : /*
+     260                 :            :  * Keeps track of the calling context returned by setenv() so that the fail()
+     261                 :            :  * method can jump out of a test.
+     262                 :            :  */
+     263                 :            : static CMOCKA_THREAD cm_jmp_buf global_run_test_env;
+     264                 :            : static CMOCKA_THREAD int global_running_test = 0;
+     265                 :            : 
+     266                 :            : /* Keeps track of the calling context returned by setenv() so that */
+     267                 :            : /* mock_assert() can optionally jump back to expect_assert_failure(). */
+     268                 :            : jmp_buf global_expect_assert_env;
+     269                 :            : int global_expecting_assert = 0;
+     270                 :            : const char *global_last_failed_assert = NULL;
+     271                 :            : static int global_skip_test;
+     272                 :            : 
+     273                 :            : /* Keeps a map of the values that functions will have to return to provide */
+     274                 :            : /* mocked interfaces. */
+     275                 :            : static CMOCKA_THREAD ListNode global_function_result_map_head;
+     276                 :            : /* Location of the last mock value returned was declared. */
+     277                 :            : static CMOCKA_THREAD SourceLocation global_last_mock_value_location;
+     278                 :            : 
+     279                 :            : /* Keeps a map of the values that functions expect as parameters to their
+     280                 :            :  * mocked interfaces. */
+     281                 :            : static CMOCKA_THREAD ListNode global_function_parameter_map_head;
+     282                 :            : /* Location of last parameter value checked was declared. */
+     283                 :            : static CMOCKA_THREAD SourceLocation global_last_parameter_location;
+     284                 :            : 
+     285                 :            : /* List (acting as FIFO) of call ordering. */
+     286                 :            : static CMOCKA_THREAD ListNode global_call_ordering_head;
+     287                 :            : /* Location of last call ordering that was declared. */
+     288                 :            : static CMOCKA_THREAD SourceLocation global_last_call_ordering_location;
+     289                 :            : 
+     290                 :            : /* List of all currently allocated blocks. */
+     291                 :            : static CMOCKA_THREAD ListNode global_allocated_blocks;
+     292                 :            : 
+     293                 :            : static enum cm_message_output global_msg_output = CM_OUTPUT_STDOUT;
+     294                 :            : 
+     295                 :            : static const char *global_test_filter_pattern;
+     296                 :            : 
+     297                 :            : static const char *global_skip_filter_pattern;
+     298                 :            : 
+     299                 :            : #ifndef _WIN32
+     300                 :            : /* Signals caught by exception_handler(). */
+     301                 :            : static const int exception_signals[] = {
+     302                 :            :     SIGFPE,
+     303                 :            :     SIGILL,
+     304                 :            :     SIGSEGV,
+     305                 :            : #ifdef SIGBUS
+     306                 :            :     SIGBUS,
+     307                 :            : #endif
+     308                 :            : #ifdef SIGSYS
+     309                 :            :     SIGSYS,
+     310                 :            : #endif
+     311                 :            : };
+     312                 :            : 
+     313                 :            : /* Default signal functions that should be restored after a test is complete. */
+     314                 :            : typedef void (*SignalFunction)(int signal);
+     315                 :            : static SignalFunction default_signal_functions[
+     316                 :            :     ARRAY_SIZE(exception_signals)];
+     317                 :            : 
+     318                 :            : #else /* _WIN32 */
+     319                 :            : 
+     320                 :            : /* The default exception filter. */
+     321                 :            : static LPTOP_LEVEL_EXCEPTION_FILTER previous_exception_filter;
+     322                 :            : 
+     323                 :            : /* Fatal exceptions. */
+     324                 :            : typedef struct ExceptionCodeInfo {
+     325                 :            :     DWORD code;
+     326                 :            :     const char* description;
+     327                 :            : } ExceptionCodeInfo;
+     328                 :            : 
+     329                 :            : #define EXCEPTION_CODE_INFO(exception_code) {exception_code, #exception_code}
+     330                 :            : 
+     331                 :            : static const ExceptionCodeInfo exception_codes[] = {
+     332                 :            :     EXCEPTION_CODE_INFO(EXCEPTION_ACCESS_VIOLATION),
+     333                 :            :     EXCEPTION_CODE_INFO(EXCEPTION_ARRAY_BOUNDS_EXCEEDED),
+     334                 :            :     EXCEPTION_CODE_INFO(EXCEPTION_DATATYPE_MISALIGNMENT),
+     335                 :            :     EXCEPTION_CODE_INFO(EXCEPTION_FLT_DENORMAL_OPERAND),
+     336                 :            :     EXCEPTION_CODE_INFO(EXCEPTION_FLT_DIVIDE_BY_ZERO),
+     337                 :            :     EXCEPTION_CODE_INFO(EXCEPTION_FLT_INEXACT_RESULT),
+     338                 :            :     EXCEPTION_CODE_INFO(EXCEPTION_FLT_INVALID_OPERATION),
+     339                 :            :     EXCEPTION_CODE_INFO(EXCEPTION_FLT_OVERFLOW),
+     340                 :            :     EXCEPTION_CODE_INFO(EXCEPTION_FLT_STACK_CHECK),
+     341                 :            :     EXCEPTION_CODE_INFO(EXCEPTION_FLT_UNDERFLOW),
+     342                 :            :     EXCEPTION_CODE_INFO(EXCEPTION_GUARD_PAGE),
+     343                 :            :     EXCEPTION_CODE_INFO(EXCEPTION_ILLEGAL_INSTRUCTION),
+     344                 :            :     EXCEPTION_CODE_INFO(EXCEPTION_INT_DIVIDE_BY_ZERO),
+     345                 :            :     EXCEPTION_CODE_INFO(EXCEPTION_INT_OVERFLOW),
+     346                 :            :     EXCEPTION_CODE_INFO(EXCEPTION_INVALID_DISPOSITION),
+     347                 :            :     EXCEPTION_CODE_INFO(EXCEPTION_INVALID_HANDLE),
+     348                 :            :     EXCEPTION_CODE_INFO(EXCEPTION_IN_PAGE_ERROR),
+     349                 :            :     EXCEPTION_CODE_INFO(EXCEPTION_NONCONTINUABLE_EXCEPTION),
+     350                 :            :     EXCEPTION_CODE_INFO(EXCEPTION_PRIV_INSTRUCTION),
+     351                 :            :     EXCEPTION_CODE_INFO(EXCEPTION_STACK_OVERFLOW),
+     352                 :            : };
+     353                 :            : #endif /* !_WIN32 */
+     354                 :            : 
+     355                 :            : enum CMUnitTestStatus {
+     356                 :            :     CM_TEST_NOT_STARTED,
+     357                 :            :     CM_TEST_PASSED,
+     358                 :            :     CM_TEST_FAILED,
+     359                 :            :     CM_TEST_ERROR,
+     360                 :            :     CM_TEST_SKIPPED,
+     361                 :            : };
+     362                 :            : 
+     363                 :            : struct CMUnitTestState {
+     364                 :            :     const ListNode *check_point; /* Check point of the test if there's a setup function. */
+     365                 :            :     const struct CMUnitTest *test; /* Point to array element in the tests we get passed */
+     366                 :            :     void *state; /* State associated with the test */
+     367                 :            :     const char *error_message; /* The error messages by the test */
+     368                 :            :     enum CMUnitTestStatus status; /* PASSED, FAILED, ABORT ... */
+     369                 :            :     double runtime; /* Time calculations */
+     370                 :            : };
+     371                 :            : 
+     372                 :            : /* Exit the currently executing test. */
+     373                 :          0 : static void exit_test(const int quit_application)
+     374                 :            : {
+     375                 :          0 :     const char *env = getenv("CMOCKA_TEST_ABORT");
+     376                 :          0 :     int abort_test = 0;
+     377                 :            : 
+     378   [ #  #  #  # ]:          0 :     if (env != NULL && strlen(env) == 1) {
+     379                 :          0 :         abort_test = (env[0] == '1');
+     380                 :            :     }
+     381                 :            : 
+     382   [ #  #  #  # ]:          0 :     if (global_skip_test == 0 &&
+     383                 :            :         abort_test == 1) {
+     384                 :          0 :         print_error("%s", cm_error_message);
+     385                 :          0 :         abort();
+     386         [ #  # ]:          0 :     } else if (global_running_test) {
+     387                 :          0 :         cm_longjmp(global_run_test_env, 1);
+     388         [ #  # ]:          0 :     } else if (quit_application) {
+     389                 :          0 :         exit(-1);
+     390                 :            :     }
+     391                 :          0 : }
+     392                 :            : 
+     393                 :          0 : void _skip(const char * const file, const int line)
+     394                 :            : {
+     395                 :          0 :     cm_print_error(SOURCE_LOCATION_FORMAT ": Skipped!\n", file, line);
+     396                 :          0 :     global_skip_test = 1;
+     397                 :          0 :     exit_test(1);
+     398                 :            : 
+     399                 :            :     /* Unreachable */
+     400                 :          0 :     exit(-1);
+     401                 :            : }
+     402                 :            : 
+     403                 :            : /* Initialize a SourceLocation structure. */
+     404                 :       7434 : static void initialize_source_location(SourceLocation * const location) {
+     405                 :       7434 :     assert_non_null(location);
+     406                 :       7434 :     location->file = NULL;
+     407                 :       7434 :     location->line = 0;
+     408                 :       7434 : }
+     409                 :            : 
+     410                 :            : 
+     411                 :            : /* Determine whether a source location is currently set. */
+     412                 :          0 : static int source_location_is_set(const SourceLocation * const location) {
+     413                 :          0 :     assert_non_null(location);
+     414   [ #  #  #  # ]:          0 :     return location->file && location->line;
+     415                 :            : }
+     416                 :            : 
+     417                 :            : 
+     418                 :            : /* Set a source location. */
+     419                 :          0 : static void set_source_location(
+     420                 :            :     SourceLocation * const location, const char * const file,
+     421                 :            :     const int line) {
+     422                 :          0 :     assert_non_null(location);
+     423                 :          0 :     location->file = file;
+     424                 :          0 :     location->line = line;
+     425                 :          0 : }
+     426                 :            : 
+     427                 :            : 
+     428                 :          0 : static int c_strreplace(char *src,
+     429                 :            :                         size_t src_len,
+     430                 :            :                         const char *pattern,
+     431                 :            :                         const char *repl,
+     432                 :            :                         int *str_replaced)
+     433                 :            : {
+     434                 :          0 :     char *p = NULL;
+     435                 :            : 
+     436                 :          0 :     p = strstr(src, pattern);
+     437         [ #  # ]:          0 :     if (p == NULL) {
+     438                 :          0 :         return -1;
+     439                 :            :     }
+     440                 :            : 
+     441                 :            :     do {
+     442                 :          0 :         size_t of = p - src;
+     443                 :          0 :         size_t l  = strlen(src);
+     444                 :          0 :         size_t pl = strlen(pattern);
+     445                 :          0 :         size_t rl = strlen(repl);
+     446                 :            : 
+     447                 :            :         /* overflow check */
+     448         [ #  # ]:          0 :         if (src_len <= l + MAX(pl, rl) + 1) {
+     449                 :          0 :             return -1;
+     450                 :            :         }
+     451                 :            : 
+     452         [ #  # ]:          0 :         if (rl != pl) {
+     453                 :          0 :             memmove(src + of + rl, src + of + pl, l - of - pl + 1);
+     454                 :            :         }
+     455                 :            : 
+     456                 :          0 :         memcpy(src + of, repl, rl);
+     457                 :            : 
+     458         [ #  # ]:          0 :         if (str_replaced != NULL) {
+     459                 :          0 :             *str_replaced = 1;
+     460                 :            :         }
+     461                 :          0 :         p = strstr(src, pattern);
+     462         [ #  # ]:          0 :     } while (p != NULL);
+     463                 :            : 
+     464                 :          0 :     return 0;
+     465                 :            : }
+     466                 :            : 
+     467                 :          0 : static int c_strmatch(const char *str, const char *pattern)
+     468                 :            : {
+     469                 :            :     int ok;
+     470                 :            : 
+     471   [ #  #  #  # ]:          0 :     if (str == NULL || pattern == NULL) {
+     472                 :          0 :         return 0;
+     473                 :            :     }
+     474                 :            : 
+     475                 :            :     for (;;) {
+     476                 :            :         /* Check if pattern is done */
+     477         [ #  # ]:          0 :         if (*pattern == '\0') {
+     478                 :            :             /* If string is at the end, we're good */
+     479         [ #  # ]:          0 :             if (*str == '\0') {
+     480                 :          0 :                 return 1;
+     481                 :            :             }
+     482                 :            : 
+     483                 :          0 :             return 0;
+     484                 :            :         }
+     485                 :            : 
+     486         [ #  # ]:          0 :         if (*pattern == '*') {
+     487                 :            :             /* Move on */
+     488                 :          0 :             pattern++;
+     489                 :            : 
+     490                 :            :             /* If we are at the end, everything is fine */
+     491         [ #  # ]:          0 :             if (*pattern == '\0') {
+     492                 :          0 :                 return 1;
+     493                 :            :             }
+     494                 :            : 
+     495                 :            :             /* Try to match each position */
+     496         [ #  # ]:          0 :             for (; *str != '\0'; str++) {
+     497                 :          0 :                 ok = c_strmatch(str, pattern);
+     498         [ #  # ]:          0 :                 if (ok) {
+     499                 :          0 :                     return 1;
+     500                 :            :                 }
+     501                 :            :             }
+     502                 :            : 
+     503                 :            :             /* No match */
+     504                 :          0 :             return 0;
+     505                 :            :         }
+     506                 :            : 
+     507                 :            :         /* If we are at the end, leave */
+     508         [ #  # ]:          0 :         if (*str == '\0') {
+     509                 :          0 :             return 0;
+     510                 :            :         }
+     511                 :            : 
+     512                 :            :         /* Check if we have a single wildcard or matching char */
+     513   [ #  #  #  # ]:          0 :         if (*pattern != '?' && *str != *pattern) {
+     514                 :          0 :             return 0;
+     515                 :            :         }
+     516                 :            : 
+     517                 :            :         /* Move string and pattern */
+     518                 :          0 :         str++;
+     519                 :          0 :         pattern++;
+     520                 :            :     }
+     521                 :            : 
+     522                 :            :     return 0;
+     523                 :            : }
+     524                 :            : 
+     525                 :            : /* Create function results and expected parameter lists. */
+     526                 :       1239 : void initialize_testing(const char *test_name) {
+     527                 :            :     (void)test_name;
+     528                 :       1239 :     list_initialize(&global_function_result_map_head);
+     529                 :       1239 :     initialize_source_location(&global_last_mock_value_location);
+     530                 :       1239 :     list_initialize(&global_function_parameter_map_head);
+     531                 :       1239 :     initialize_source_location(&global_last_parameter_location);
+     532                 :       1239 :     list_initialize(&global_call_ordering_head);
+     533                 :       1239 :     initialize_source_location(&global_last_parameter_location);
+     534                 :       1239 : }
+     535                 :            : 
+     536                 :            : 
+     537                 :       1239 : static void fail_if_leftover_values(const char *test_name) {
+     538                 :       1239 :     int error_occurred = 0;
+     539                 :            :     (void)test_name;
+     540                 :       1239 :     remove_always_return_values(&global_function_result_map_head, 1);
+     541         [ -  + ]:       1239 :     if (check_for_leftover_values(
+     542                 :            :             &global_function_result_map_head,
+     543                 :            :             "%s() has remaining non-returned values.\n", 1)) {
+     544                 :          0 :         error_occurred = 1;
+     545                 :            :     }
+     546                 :            : 
+     547                 :       1239 :     remove_always_return_values(&global_function_parameter_map_head, 2);
+     548         [ -  + ]:       1239 :     if (check_for_leftover_values(
+     549                 :            :             &global_function_parameter_map_head,
+     550                 :            :             "'%s' parameter still has values that haven't been checked.\n",
+     551                 :            :             2)) {
+     552                 :          0 :         error_occurred = 1;
+     553                 :            :     }
+     554                 :            : 
+     555                 :       1239 :     remove_always_return_values_from_list(&global_call_ordering_head);
+     556         [ -  + ]:       1239 :     if (check_for_leftover_values_list(&global_call_ordering_head,
+     557                 :            :         "%s function was expected to be called but was not.\n")) {
+     558                 :          0 :         error_occurred = 1;
+     559                 :            :     }
+     560         [ -  + ]:       1239 :     if (error_occurred) {
+     561                 :          0 :         exit_test(1);
+     562                 :            :     }
+     563                 :       1239 : }
+     564                 :            : 
+     565                 :            : 
+     566                 :       1239 : static void teardown_testing(const char *test_name) {
+     567                 :            :     (void)test_name;
+     568                 :       1239 :     list_free(&global_function_result_map_head, free_symbol_map_value,
+     569                 :            :               (void*)0);
+     570                 :       1239 :     initialize_source_location(&global_last_mock_value_location);
+     571                 :       1239 :     list_free(&global_function_parameter_map_head, free_symbol_map_value,
+     572                 :            :               (void*)1);
+     573                 :       1239 :     initialize_source_location(&global_last_parameter_location);
+     574                 :       1239 :     list_free(&global_call_ordering_head, free_value,
+     575                 :            :               (void*)0);
+     576                 :       1239 :     initialize_source_location(&global_last_call_ordering_location);
+     577                 :       1239 : }
+     578                 :            : 
+     579                 :            : /* Initialize a list node. */
+     580                 :       3722 : static ListNode* list_initialize(ListNode * const node) {
+     581                 :       3722 :     node->value = NULL;
+     582                 :       3722 :     node->next = node;
+     583                 :       3722 :     node->prev = node;
+     584                 :       3722 :     node->refcount = 1;
+     585                 :       3722 :     return node;
+     586                 :            : }
+     587                 :            : 
+     588                 :            : 
+     589                 :            : /*
+     590                 :            :  * Adds a value at the tail of a given list.
+     591                 :            :  * The node referencing the value is allocated from the heap.
+     592                 :            :  */
+     593                 :          0 : static ListNode* list_add_value(ListNode * const head, const void *value,
+     594                 :            :                                      const int refcount) {
+     595                 :          0 :     ListNode * const new_node = (ListNode*)malloc(sizeof(ListNode));
+     596                 :          0 :     assert_non_null(head);
+     597                 :          0 :     assert_non_null(value);
+     598                 :          0 :     new_node->value = value;
+     599                 :          0 :     new_node->refcount = refcount;
+     600                 :          0 :     return list_add(head, new_node);
+     601                 :            : }
+     602                 :            : 
+     603                 :            : 
+     604                 :            : /* Add new_node to the end of the list. */
+     605                 :          0 : static ListNode* list_add(ListNode * const head, ListNode *new_node) {
+     606                 :          0 :     assert_non_null(head);
+     607                 :          0 :     assert_non_null(new_node);
+     608                 :          0 :     new_node->next = head;
+     609                 :          0 :     new_node->prev = head->prev;
+     610                 :          0 :     head->prev->next = new_node;
+     611                 :          0 :     head->prev = new_node;
+     612                 :          0 :     return new_node;
+     613                 :            : }
+     614                 :            : 
+     615                 :            : 
+     616                 :            : /* Remove a node from a list. */
+     617                 :          0 : static ListNode* list_remove(
+     618                 :            :         ListNode * const node, const CleanupListValue cleanup_value,
+     619                 :            :         void * const cleanup_value_data) {
+     620                 :          0 :     assert_non_null(node);
+     621                 :          0 :     node->prev->next = node->next;
+     622                 :          0 :     node->next->prev = node->prev;
+     623         [ #  # ]:          0 :     if (cleanup_value) {
+     624                 :          0 :         cleanup_value(node->value, cleanup_value_data);
+     625                 :            :     }
+     626                 :          0 :     return node;
+     627                 :            : }
+     628                 :            : 
+     629                 :            : 
+     630                 :            : /* Remove a list node from a list and free the node. */
+     631                 :          0 : static void list_remove_free(
+     632                 :            :         ListNode * const node, const CleanupListValue cleanup_value,
+     633                 :            :         void * const cleanup_value_data) {
+     634                 :          0 :     assert_non_null(node);
+     635                 :          0 :     free(list_remove(node, cleanup_value, cleanup_value_data));
+     636                 :          0 : }
+     637                 :            : 
+     638                 :            : 
+     639                 :            : /*
+     640                 :            :  * Frees memory kept by a linked list The cleanup_value function is called for
+     641                 :            :  * every "value" field of nodes in the list, except for the head.  In addition
+     642                 :            :  * to each list value, cleanup_value_data is passed to each call to
+     643                 :            :  * cleanup_value.  The head of the list is not deallocated.
+     644                 :            :  */
+     645                 :       3717 : static ListNode* list_free(
+     646                 :            :         ListNode * const head, const CleanupListValue cleanup_value,
+     647                 :            :         void * const cleanup_value_data) {
+     648                 :       3717 :     assert_non_null(head);
+     649         [ -  + ]:       3717 :     while (!list_empty(head)) {
+     650                 :          0 :         list_remove_free(head->next, cleanup_value, cleanup_value_data);
+     651                 :            :     }
+     652                 :       3717 :     return head;
+     653                 :            : }
+     654                 :            : 
+     655                 :            : 
+     656                 :            : /* Determine whether a list is empty. */
+     657                 :       4956 : static int list_empty(const ListNode * const head) {
+     658                 :       4956 :     assert_non_null(head);
+     659                 :       4956 :     return head->next == head;
+     660                 :            : }
+     661                 :            : 
+     662                 :            : 
+     663                 :            : /*
+     664                 :            :  * Find a value in the list using the equal_func to compare each node with the
+     665                 :            :  * value.
+     666                 :            :  */
+     667                 :          0 : static int list_find(ListNode * const head, const void *value,
+     668                 :            :                      const EqualityFunction equal_func, ListNode **output) {
+     669                 :            :     ListNode *current;
+     670                 :          0 :     assert_non_null(head);
+     671         [ #  # ]:          0 :     for (current = head->next; current != head; current = current->next) {
+     672         [ #  # ]:          0 :         if (equal_func(current->value, value)) {
+     673                 :          0 :             *output = current;
+     674                 :          0 :             return 1;
+     675                 :            :         }
+     676                 :            :     }
+     677                 :          0 :     return 0;
+     678                 :            : }
+     679                 :            : 
+     680                 :            : /* Returns the first node of a list */
+     681                 :          0 : static int list_first(ListNode * const head, ListNode **output) {
+     682                 :          0 :     ListNode *target_node = NULL;
+     683                 :          0 :     assert_non_null(head);
+     684         [ #  # ]:          0 :     if (list_empty(head)) {
+     685                 :          0 :         return 0;
+     686                 :            :     }
+     687                 :          0 :     target_node = head->next;
+     688                 :          0 :     *output = target_node;
+     689                 :          0 :     return 1;
+     690                 :            : }
+     691                 :            : 
+     692                 :            : 
+     693                 :            : /* Deallocate a value referenced by a list. */
+     694                 :          0 : static void free_value(const void *value, void *cleanup_value_data) {
+     695                 :            :     (void)cleanup_value_data;
+     696                 :          0 :     assert_non_null(value);
+     697                 :          0 :     free((void*)value);
+     698                 :          0 : }
+     699                 :            : 
+     700                 :            : 
+     701                 :            : /* Releases memory associated to a symbol_map_value. */
+     702                 :          0 : static void free_symbol_map_value(const void *value,
+     703                 :            :                                   void *cleanup_value_data) {
+     704                 :          0 :     SymbolMapValue * const map_value = (SymbolMapValue*)value;
+     705                 :          0 :     const LargestIntegralType children = cast_ptr_to_largest_integral_type(cleanup_value_data);
+     706                 :          0 :     assert_non_null(value);
+     707         [ #  # ]:          0 :     if (children == 0) {
+     708                 :          0 :         list_free(&map_value->symbol_values_list_head,
+     709                 :            :                   free_value,
+     710                 :            :                   NULL);
+     711                 :            :     } else {
+     712                 :          0 :         list_free(&map_value->symbol_values_list_head,
+     713                 :            :                   free_symbol_map_value,
+     714                 :          0 :                   (void *)((uintptr_t)children - 1));
+     715                 :            :     }
+     716                 :            : 
+     717                 :          0 :     free(map_value);
+     718                 :          0 : }
+     719                 :            : 
+     720                 :            : 
+     721                 :            : /*
+     722                 :            :  * Determine whether a symbol name referenced by a symbol_map_value matches the
+     723                 :            :  * specified function name.
+     724                 :            :  */
+     725                 :          0 : static int symbol_names_match(const void *map_value, const void *symbol) {
+     726                 :          0 :     return !strcmp(((SymbolMapValue*)map_value)->symbol_name,
+     727                 :            :                    (const char*)symbol);
+     728                 :            : }
+     729                 :            : 
+     730                 :            : /*
+     731                 :            :  * Adds a value to the queue of values associated with the given hierarchy of
+     732                 :            :  * symbols.  It's assumed value is allocated from the heap.
+     733                 :            :  */
+     734                 :          0 : static void add_symbol_value(ListNode * const symbol_map_head,
+     735                 :            :                              const char * const symbol_names[],
+     736                 :            :                              const size_t number_of_symbol_names,
+     737                 :            :                              const void* value, const int refcount) {
+     738                 :            :     const char* symbol_name;
+     739                 :            :     ListNode *target_node;
+     740                 :            :     SymbolMapValue *target_map_value;
+     741                 :          0 :     assert_non_null(symbol_map_head);
+     742                 :          0 :     assert_non_null(symbol_names);
+     743                 :          0 :     assert_true(number_of_symbol_names);
+     744                 :          0 :     symbol_name = symbol_names[0];
+     745                 :            : 
+     746         [ #  # ]:          0 :     if (!list_find(symbol_map_head, symbol_name, symbol_names_match,
+     747                 :            :                    &target_node)) {
+     748                 :            :         SymbolMapValue * const new_symbol_map_value =
+     749                 :          0 :             (SymbolMapValue*)malloc(sizeof(*new_symbol_map_value));
+     750                 :          0 :         new_symbol_map_value->symbol_name = symbol_name;
+     751                 :          0 :         list_initialize(&new_symbol_map_value->symbol_values_list_head);
+     752                 :          0 :         target_node = list_add_value(symbol_map_head, new_symbol_map_value,
+     753                 :            :                                           1);
+     754                 :            :     }
+     755                 :            : 
+     756                 :          0 :     target_map_value = (SymbolMapValue*)target_node->value;
+     757         [ #  # ]:          0 :     if (number_of_symbol_names == 1) {
+     758                 :          0 :             list_add_value(&target_map_value->symbol_values_list_head,
+     759                 :            :                                 value, refcount);
+     760                 :            :     } else {
+     761                 :          0 :         add_symbol_value(&target_map_value->symbol_values_list_head,
+     762                 :            :                          &symbol_names[1], number_of_symbol_names - 1, value,
+     763                 :            :                          refcount);
+     764                 :            :     }
+     765                 :          0 : }
+     766                 :            : 
+     767                 :            : 
+     768                 :            : /*
+     769                 :            :  * Gets the next value associated with the given hierarchy of symbols.
+     770                 :            :  * The value is returned as an output parameter with the function returning the
+     771                 :            :  * node's old refcount value if a value is found, 0 otherwise.  This means that
+     772                 :            :  * a return value of 1 indicates the node was just removed from the list.
+     773                 :            :  */
+     774                 :          0 : static int get_symbol_value(
+     775                 :            :         ListNode * const head, const char * const symbol_names[],
+     776                 :            :         const size_t number_of_symbol_names, void **output) {
+     777                 :          0 :     const char* symbol_name = NULL;
+     778                 :          0 :     ListNode *target_node = NULL;
+     779                 :          0 :     assert_non_null(head);
+     780                 :          0 :     assert_non_null(symbol_names);
+     781                 :          0 :     assert_true(number_of_symbol_names);
+     782                 :          0 :     assert_non_null(output);
+     783                 :          0 :     symbol_name = symbol_names[0];
+     784                 :            : 
+     785         [ #  # ]:          0 :     if (list_find(head, symbol_name, symbol_names_match, &target_node)) {
+     786                 :          0 :         SymbolMapValue *map_value = NULL;
+     787                 :          0 :         ListNode *child_list = NULL;
+     788                 :          0 :         int return_value = 0;
+     789                 :          0 :         assert_non_null(target_node);
+     790                 :          0 :         assert_non_null(target_node->value);
+     791                 :            : 
+     792                 :          0 :         map_value = (SymbolMapValue*)target_node->value;
+     793                 :          0 :         child_list = &map_value->symbol_values_list_head;
+     794                 :            : 
+     795         [ #  # ]:          0 :         if (number_of_symbol_names == 1) {
+     796                 :          0 :             ListNode *value_node = NULL;
+     797                 :          0 :             return_value = list_first(child_list, &value_node);
+     798                 :          0 :             assert_true(return_value);
+     799                 :            :             /* Add a check to silence clang analyzer */
+     800         [ #  # ]:          0 :             if (return_value == 0) {
+     801                 :          0 :                 goto out;
+     802                 :            :             }
+     803                 :          0 :             *output = (void*) value_node->value;
+     804                 :          0 :             return_value = value_node->refcount;
+     805         [ #  # ]:          0 :             if (value_node->refcount - 1 == 0) {
+     806                 :          0 :                 list_remove_free(value_node, NULL, NULL);
+     807         [ #  # ]:          0 :             } else if (value_node->refcount > WILL_RETURN_ONCE) {
+     808                 :          0 :                 --value_node->refcount;
+     809                 :            :             }
+     810                 :            :         } else {
+     811                 :          0 :             return_value = get_symbol_value(
+     812                 :            :                 child_list, &symbol_names[1], number_of_symbol_names - 1,
+     813                 :            :                 output);
+     814                 :            :         }
+     815         [ #  # ]:          0 :         if (list_empty(child_list)) {
+     816                 :          0 :             list_remove_free(target_node, free_symbol_map_value, (void*)0);
+     817                 :            :         }
+     818                 :          0 :         return return_value;
+     819                 :            :     }
+     820                 :          0 : out:
+     821                 :          0 :     cm_print_error("No entries for symbol %s.\n", symbol_name);
+     822                 :          0 :     return 0;
+     823                 :            : }
+     824                 :            : 
+     825                 :            : /**
+     826                 :            :  * Taverse a list of nodes and remove first symbol value in list that has a
+     827                 :            :  * refcount < -1 (i.e. should always be returned and has been returned at
+     828                 :            :  * least once).
+     829                 :            :  */
+     830                 :            : 
+     831                 :       1239 : static void remove_always_return_values_from_list(ListNode * const map_head)
+     832                 :            : {
+     833                 :       1239 :     ListNode * current = NULL;
+     834                 :       1239 :     ListNode * next = NULL;
+     835                 :       1239 :     assert_non_null(map_head);
+     836                 :            : 
+     837                 :       1239 :     for (current = map_head->next, next = current->next;
+     838         [ -  + ]:       1239 :             current != map_head;
+     839                 :          0 :             current = next, next = current->next) {
+     840         [ #  # ]:          0 :         if (current->refcount < -1) {
+     841                 :          0 :             list_remove_free(current, free_value, NULL);
+     842                 :            :         }
+     843                 :            :     }
+     844                 :       1239 : }
+     845                 :            : 
+     846                 :            : /*
+     847                 :            :  * Traverse down a tree of symbol values and remove the first symbol value
+     848                 :            :  * in each branch that has a refcount < -1 (i.e should always be returned
+     849                 :            :  * and has been returned at least once).
+     850                 :            :  */
+     851                 :       2478 : static void remove_always_return_values(ListNode * const map_head,
+     852                 :            :                                         const size_t number_of_symbol_names) {
+     853                 :            :     ListNode *current;
+     854                 :       2478 :     assert_non_null(map_head);
+     855                 :       2478 :     assert_true(number_of_symbol_names);
+     856                 :       2478 :     current = map_head->next;
+     857         [ -  + ]:       2478 :     while (current != map_head) {
+     858                 :          0 :         SymbolMapValue * const value = (SymbolMapValue*)current->value;
+     859                 :          0 :         ListNode * const next = current->next;
+     860                 :            :         ListNode *child_list;
+     861                 :          0 :         assert_non_null(value);
+     862                 :          0 :         child_list = &value->symbol_values_list_head;
+     863                 :            : 
+     864         [ #  # ]:          0 :         if (!list_empty(child_list)) {
+     865         [ #  # ]:          0 :             if (number_of_symbol_names == 1) {
+     866                 :          0 :                 ListNode * const child_node = child_list->next;
+     867                 :            :                 /* If this item has been returned more than once, free it. */
+     868         [ #  # ]:          0 :                 if (child_node->refcount < -1) {
+     869                 :          0 :                     list_remove_free(child_node, free_value, NULL);
+     870                 :            :                 }
+     871                 :            :             } else {
+     872                 :          0 :                 remove_always_return_values(child_list,
+     873                 :            :                                             number_of_symbol_names - 1);
+     874                 :            :             }
+     875                 :            :         }
+     876                 :            : 
+     877         [ #  # ]:          0 :         if (list_empty(child_list)) {
+     878                 :          0 :             list_remove_free(current, free_value, NULL);
+     879                 :            :         }
+     880                 :          0 :         current = next;
+     881                 :            :     }
+     882                 :       2478 : }
+     883                 :            : 
+     884                 :       1239 : static size_t check_for_leftover_values_list(const ListNode * head,
+     885                 :            :                                              const char * const error_message)
+     886                 :            : {
+     887                 :            :     ListNode *child_node;
+     888                 :       1239 :     size_t leftover_count = 0;
+     889         [ -  + ]:       1239 :     if (!list_empty(head))
+     890                 :            :     {
+     891         [ #  # ]:          0 :         for (child_node = head->next; child_node != head;
+     892                 :          0 :                  child_node = child_node->next, ++leftover_count) {
+     893                 :          0 :             const FuncOrderingValue *const o =
+     894                 :            :                     (const FuncOrderingValue*) child_node->value;
+     895                 :          0 :             cm_print_error("%s: %s", error_message, o->function);
+     896                 :          0 :             cm_print_error(SOURCE_LOCATION_FORMAT
+     897                 :            :                     ": note: remaining item was declared here\n",
+     898                 :          0 :                     o->location.file, o->location.line);
+     899                 :            :         }
+     900                 :            :     }
+     901                 :       1239 :     return leftover_count;
+     902                 :            : }
+     903                 :            : 
+     904                 :            : /*
+     905                 :            :  * Checks if there are any leftover values set up by the test that were never
+     906                 :            :  * retrieved through execution, and fail the test if that is the case.
+     907                 :            :  */
+     908                 :       2478 : static size_t check_for_leftover_values(
+     909                 :            :         const ListNode * const map_head, const char * const error_message,
+     910                 :            :         const size_t number_of_symbol_names) {
+     911                 :            :     const ListNode *current;
+     912                 :       2478 :     size_t symbols_with_leftover_values = 0;
+     913                 :       2478 :     assert_non_null(map_head);
+     914                 :       2478 :     assert_true(number_of_symbol_names);
+     915                 :            : 
+     916         [ -  + ]:       2478 :     for (current = map_head->next; current != map_head;
+     917                 :          0 :          current = current->next) {
+     918                 :          0 :         const SymbolMapValue * const value =
+     919                 :            :             (SymbolMapValue*)current->value;
+     920                 :            :         const ListNode *child_list;
+     921                 :          0 :         assert_non_null(value);
+     922                 :          0 :         child_list = &value->symbol_values_list_head;
+     923                 :            : 
+     924         [ #  # ]:          0 :         if (!list_empty(child_list)) {
+     925         [ #  # ]:          0 :             if (number_of_symbol_names == 1) {
+     926                 :            :                 const ListNode *child_node;
+     927                 :          0 :                 cm_print_error("%s: %s", error_message, value->symbol_name);
+     928                 :            : 
+     929         [ #  # ]:          0 :                 for (child_node = child_list->next; child_node != child_list;
+     930                 :          0 :                      child_node = child_node->next) {
+     931                 :          0 :                     const SourceLocation * const location =
+     932                 :            :                         (const SourceLocation*)child_node->value;
+     933                 :          0 :                     cm_print_error(SOURCE_LOCATION_FORMAT
+     934                 :            :                                    ": note: remaining item was declared here\n",
+     935                 :          0 :                                    location->file, location->line);
+     936                 :            :                 }
+     937                 :            :             } else {
+     938                 :          0 :                 cm_print_error("%s: ", value->symbol_name);
+     939                 :          0 :                 check_for_leftover_values(child_list, error_message,
+     940                 :            :                                           number_of_symbol_names - 1);
+     941                 :            :             }
+     942                 :          0 :             symbols_with_leftover_values ++;
+     943                 :            :         }
+     944                 :            :     }
+     945                 :       2478 :     return symbols_with_leftover_values;
+     946                 :            : }
+     947                 :            : 
+     948                 :            : 
+     949                 :            : /* Get the next return value for the specified mock function. */
+     950                 :          0 : LargestIntegralType _mock(const char * const function, const char* const file,
+     951                 :            :                           const int line) {
+     952                 :            :     void *result;
+     953                 :          0 :     const int rc = get_symbol_value(&global_function_result_map_head,
+     954                 :            :                                     &function, 1, &result);
+     955         [ #  # ]:          0 :     if (rc) {
+     956                 :          0 :         SymbolValue * const symbol = (SymbolValue*)result;
+     957                 :          0 :         const LargestIntegralType value = symbol->value;
+     958                 :          0 :         global_last_mock_value_location = symbol->location;
+     959         [ #  # ]:          0 :         if (rc == 1) {
+     960                 :          0 :             free(symbol);
+     961                 :            :         }
+     962                 :          0 :         return value;
+     963                 :            :     } else {
+     964                 :          0 :         cm_print_error(SOURCE_LOCATION_FORMAT ": error: Could not get value "
+     965                 :            :                        "to mock function %s\n", file, line, function);
+     966         [ #  # ]:          0 :         if (source_location_is_set(&global_last_mock_value_location)) {
+     967                 :          0 :             cm_print_error(SOURCE_LOCATION_FORMAT
+     968                 :            :                            ": note: Previously returned mock value was declared here\n",
+     969                 :            :                            global_last_mock_value_location.file,
+     970                 :            :                            global_last_mock_value_location.line);
+     971                 :            :         } else {
+     972                 :          0 :             cm_print_error("There were no previously returned mock values for "
+     973                 :            :                            "this test.\n");
+     974                 :            :         }
+     975                 :          0 :         exit_test(1);
+     976                 :            :     }
+     977                 :          0 :     return 0;
+     978                 :            : }
+     979                 :            : 
+     980                 :            : /* Ensure that function is being called in proper order */
+     981                 :          0 : void _function_called(const char *const function,
+     982                 :            :                       const char *const file,
+     983                 :            :                       const int line)
+     984                 :            : {
+     985                 :          0 :     ListNode *first_value_node = NULL;
+     986                 :          0 :     ListNode *value_node = NULL;
+     987                 :            :     int rc;
+     988                 :            : 
+     989                 :          0 :     rc = list_first(&global_call_ordering_head, &value_node);
+     990                 :          0 :     first_value_node = value_node;
+     991         [ #  # ]:          0 :     if (rc) {
+     992                 :            :         FuncOrderingValue *expected_call;
+     993                 :            :         int cmp;
+     994                 :            : 
+     995                 :          0 :         expected_call = (FuncOrderingValue *)value_node->value;
+     996                 :            : 
+     997                 :          0 :         cmp = strcmp(expected_call->function, function);
+     998         [ #  # ]:          0 :         if (value_node->refcount < -1) {
+     999                 :            :             /*
+    1000                 :            :              * Search through value nodes until either function is found or
+    1001                 :            :              * encounter a non-zero refcount greater than -2
+    1002                 :            :              */
+    1003         [ #  # ]:          0 :             if (cmp != 0) {
+    1004                 :          0 :                 value_node = value_node->next;
+    1005                 :          0 :                 expected_call = (FuncOrderingValue *)value_node->value;
+    1006                 :            : 
+    1007                 :          0 :                 cmp = strcmp(expected_call->function, function);
+    1008         [ #  # ]:          0 :                 while (value_node->refcount < -1 &&
+    1009         [ #  # ]:          0 :                        cmp != 0 &&
+    1010         [ #  # ]:          0 :                        value_node != first_value_node->prev) {
+    1011                 :          0 :                     value_node = value_node->next;
+    1012         [ #  # ]:          0 :                     if (value_node == NULL) {
+    1013                 :          0 :                         break;
+    1014                 :            :                     }
+    1015                 :          0 :                     expected_call = (FuncOrderingValue *)value_node->value;
+    1016         [ #  # ]:          0 :                     if (expected_call == NULL) {
+    1017                 :          0 :                         continue;
+    1018                 :            :                     }
+    1019                 :          0 :                     cmp = strcmp(expected_call->function, function);
+    1020                 :            :                 }
+    1021                 :            : 
+    1022   [ #  #  #  # ]:          0 :                 if (expected_call == NULL || value_node == first_value_node->prev) {
+    1023                 :          0 :                     cm_print_error(SOURCE_LOCATION_FORMAT
+    1024                 :            :                                    ": error: No expected mock calls matching "
+    1025                 :            :                                    "called() invocation in %s",
+    1026                 :            :                                    file, line,
+    1027                 :            :                                    function);
+    1028                 :          0 :                     exit_test(1);
+    1029                 :            :                 }
+    1030                 :            :             }
+    1031                 :            :         }
+    1032                 :            : 
+    1033         [ #  # ]:          0 :         if (cmp == 0) {
+    1034   [ #  #  #  # ]:          0 :             if (value_node->refcount > -2 && --value_node->refcount == 0) {
+    1035                 :          0 :                 list_remove_free(value_node, free_value, NULL);
+    1036                 :            :             }
+    1037                 :            :         } else {
+    1038                 :          0 :             cm_print_error(SOURCE_LOCATION_FORMAT
+    1039                 :            :                            ": error: Expected call to %s but received called() "
+    1040                 :            :                            "in %s\n",
+    1041                 :            :                            file, line,
+    1042                 :            :                            expected_call->function,
+    1043                 :            :                            function);
+    1044                 :          0 :             exit_test(1);
+    1045                 :            :         }
+    1046                 :            :     } else {
+    1047                 :          0 :         cm_print_error(SOURCE_LOCATION_FORMAT
+    1048                 :            :                        ": error: No mock calls expected but called() was "
+    1049                 :            :                        "invoked in %s\n",
+    1050                 :            :                        file, line,
+    1051                 :            :                        function);
+    1052                 :          0 :         exit_test(1);
+    1053                 :            :     }
+    1054                 :          0 : }
+    1055                 :            : 
+    1056                 :            : /* Add a return value for the specified mock function name. */
+    1057                 :          0 : void _will_return(const char * const function_name, const char * const file,
+    1058                 :            :                   const int line, const LargestIntegralType value,
+    1059                 :            :                   const int count) {
+    1060                 :            :     SymbolValue * const return_value =
+    1061                 :          0 :         (SymbolValue*)malloc(sizeof(*return_value));
+    1062                 :          0 :     assert_true(count != 0);
+    1063                 :          0 :     return_value->value = value;
+    1064                 :          0 :     set_source_location(&return_value->location, file, line);
+    1065                 :          0 :     add_symbol_value(&global_function_result_map_head, &function_name, 1,
+    1066                 :            :                      return_value, count);
+    1067                 :          0 : }
+    1068                 :            : 
+    1069                 :            : 
+    1070                 :            : /*
+    1071                 :            :  * Add a custom parameter checking function.  If the event parameter is NULL
+    1072                 :            :  * the event structure is allocated internally by this function.  If event
+    1073                 :            :  * parameter is provided it must be allocated on the heap and doesn't need to
+    1074                 :            :  * be deallocated by the caller.
+    1075                 :            :  */
+    1076                 :          0 : void _expect_check(
+    1077                 :            :         const char* const function, const char* const parameter,
+    1078                 :            :         const char* const file, const int line,
+    1079                 :            :         const CheckParameterValue check_function,
+    1080                 :            :         const LargestIntegralType check_data,
+    1081                 :            :         CheckParameterEvent * const event, const int count) {
+    1082                 :          0 :     CheckParameterEvent * const check =
+    1083         [ #  # ]:          0 :         event ? event : (CheckParameterEvent*)malloc(sizeof(*check));
+    1084                 :          0 :     const char* symbols[] = {function, parameter};
+    1085                 :          0 :     check->parameter_name = parameter;
+    1086                 :          0 :     check->check_value = check_function;
+    1087                 :          0 :     check->check_value_data = check_data;
+    1088                 :          0 :     set_source_location(&check->location, file, line);
+    1089                 :          0 :     add_symbol_value(&global_function_parameter_map_head, symbols, 2, check,
+    1090                 :            :                      count);
+    1091                 :          0 : }
+    1092                 :            : 
+    1093                 :            : /*
+    1094                 :            :  * Add an call expectations that a particular function is called correctly.
+    1095                 :            :  * This is used for code under test that makes calls to several functions
+    1096                 :            :  * in depended upon components (mocks).
+    1097                 :            :  */
+    1098                 :            : 
+    1099                 :          0 : void _expect_function_call(
+    1100                 :            :     const char * const function_name,
+    1101                 :            :     const char * const file,
+    1102                 :            :     const int line,
+    1103                 :            :     const int count)
+    1104                 :            : {
+    1105                 :            :     FuncOrderingValue *ordering;
+    1106                 :            : 
+    1107                 :          0 :     assert_non_null(function_name);
+    1108                 :          0 :     assert_non_null(file);
+    1109                 :          0 :     assert_true(count != 0);
+    1110                 :            : 
+    1111                 :          0 :     ordering = (FuncOrderingValue *)malloc(sizeof(*ordering));
+    1112                 :            : 
+    1113                 :          0 :     set_source_location(&ordering->location, file, line);
+    1114                 :          0 :     ordering->function = function_name;
+    1115                 :            : 
+    1116                 :          0 :     list_add_value(&global_call_ordering_head, ordering, count);
+    1117                 :          0 : }
+    1118                 :            : 
+    1119                 :            : /* Returns 1 if the specified float values are equal, else returns 0. */
+    1120                 :          0 : static int float_compare(const float left,
+    1121                 :            :                          const float right,
+    1122                 :            :                          const float epsilon) {
+    1123                 :            :     float absLeft;
+    1124                 :            :     float absRight;
+    1125                 :            :     float largest;
+    1126                 :            :     float relDiff;
+    1127                 :            : 
+    1128                 :          0 :     float diff = left - right;
+    1129         [ #  # ]:          0 :     diff = (diff >= 0.f) ? diff : -diff;
+    1130                 :            : 
+    1131                 :            :     // Check if the numbers are really close -- needed
+    1132                 :            :         // when comparing numbers near zero.
+    1133         [ #  # ]:          0 :         if (diff <= epsilon) {
+    1134                 :          0 :             return 1;
+    1135                 :            :     }
+    1136                 :            : 
+    1137         [ #  # ]:          0 :     absLeft = (left >= 0.f) ? left : -left;
+    1138         [ #  # ]:          0 :     absRight = (right >= 0.f) ? right : -right;
+    1139                 :            : 
+    1140         [ #  # ]:          0 :     largest = (absRight > absLeft) ? absRight : absLeft;
+    1141                 :          0 :     relDiff = largest * FLT_EPSILON;
+    1142                 :            : 
+    1143         [ #  # ]:          0 :     if (diff > relDiff) {
+    1144                 :          0 :         return 0;
+    1145                 :            :     }
+    1146                 :          0 :     return 1;
+    1147                 :            : }
+    1148                 :            : 
+    1149                 :            : /* Returns 1 if the specified float values are equal. If the values are not equal
+    1150                 :            :  * an error is displayed and 0 is returned. */
+    1151                 :          0 : static int float_values_equal_display_error(const float left,
+    1152                 :            :                                             const float right,
+    1153                 :            :                                             const float epsilon) {
+    1154                 :          0 :     const int equal = float_compare(left, right, epsilon);
+    1155         [ #  # ]:          0 :     if (!equal) {
+    1156                 :          0 :         cm_print_error(FloatPrintfFormat " != "
+    1157                 :            :                    FloatPrintfFormat "\n", left, right);
+    1158                 :            :     }
+    1159                 :          0 :     return equal;
+    1160                 :            : }
+    1161                 :            : 
+    1162                 :            : /* Returns 1 if the specified float values are different. If the values are equal
+    1163                 :            :  * an error is displayed and 0 is returned. */
+    1164                 :          0 : static int float_values_not_equal_display_error(const float left,
+    1165                 :            :                                                 const float right,
+    1166                 :            :                                                 const float epsilon) {
+    1167                 :          0 :     const int not_equal = (float_compare(left, right, epsilon) == 0);
+    1168         [ #  # ]:          0 :     if (!not_equal) {
+    1169                 :          0 :         cm_print_error(FloatPrintfFormat " == "
+    1170                 :            :                    FloatPrintfFormat "\n", left, right);
+    1171                 :            :     }
+    1172                 :          0 :     return not_equal;
+    1173                 :            : }
+    1174                 :            : 
+    1175                 :            : /* Returns 1 if the specified double values are equal, else returns 0. */
+    1176                 :          0 : static int double_compare(const double left,
+    1177                 :            :                           const double right,
+    1178                 :            :                           const double epsilon) {
+    1179                 :            :     double absLeft;
+    1180                 :            :     double absRight;
+    1181                 :            :     double largest;
+    1182                 :            :     double relDiff;
+    1183                 :            : 
+    1184                 :          0 :     double diff = left - right;
+    1185         [ #  # ]:          0 :     diff = (diff >= 0.f) ? diff : -diff;
+    1186                 :            : 
+    1187                 :            :     /*
+    1188                 :            :      * Check if the numbers are really close -- needed
+    1189                 :            :      * when comparing numbers near zero.
+    1190                 :            :      */
+    1191         [ #  # ]:          0 :     if (diff <= epsilon) {
+    1192                 :          0 :         return 1;
+    1193                 :            :     }
+    1194                 :            : 
+    1195         [ #  # ]:          0 :     absLeft = (left >= 0.f) ? left : -left;
+    1196         [ #  # ]:          0 :     absRight = (right >= 0.f) ? right : -right;
+    1197                 :            : 
+    1198         [ #  # ]:          0 :     largest = (absRight > absLeft) ? absRight : absLeft;
+    1199                 :          0 :     relDiff = largest * FLT_EPSILON;
+    1200                 :            : 
+    1201         [ #  # ]:          0 :     if (diff > relDiff) {
+    1202                 :          0 :         return 0;
+    1203                 :            :     }
+    1204                 :            : 
+    1205                 :          0 :     return 1;
+    1206                 :            : }
+    1207                 :            : 
+    1208                 :            : /*
+    1209                 :            :  * Returns 1 if the specified double values are equal. If the values are not
+    1210                 :            :  * equal an error is displayed and 0 is returned.
+    1211                 :            :  */
+    1212                 :          0 : static int double_values_equal_display_error(const double left,
+    1213                 :            :                                              const double right,
+    1214                 :            :                                              const double epsilon) {
+    1215                 :          0 :     const int equal = double_compare(left, right, epsilon);
+    1216                 :            : 
+    1217         [ #  # ]:          0 :     if (!equal) {
+    1218                 :          0 :         cm_print_error(DoublePrintfFormat " != "
+    1219                 :            :                    DoublePrintfFormat "\n", left, right);
+    1220                 :            :     }
+    1221                 :            : 
+    1222                 :          0 :     return equal;
+    1223                 :            : }
+    1224                 :            : 
+    1225                 :            : /*
+    1226                 :            :  * Returns 1 if the specified double values are different. If the values are
+    1227                 :            :  * equal an error is displayed and 0 is returned.
+    1228                 :            :  */
+    1229                 :          0 : static int double_values_not_equal_display_error(const double left,
+    1230                 :            :                                                  const double right,
+    1231                 :            :                                                  const double epsilon) {
+    1232                 :          0 :     const int not_equal = (double_compare(left, right, epsilon) == 0);
+    1233                 :            : 
+    1234         [ #  # ]:          0 :     if (!not_equal) {
+    1235                 :          0 :         cm_print_error(DoublePrintfFormat " == "
+    1236                 :            :                    DoublePrintfFormat "\n", left, right);
+    1237                 :            :     }
+    1238                 :            : 
+    1239                 :          0 :     return not_equal;
+    1240                 :            : }
+    1241                 :            : 
+    1242                 :            : /* Returns 1 if the specified values are equal.  If the values are not equal
+    1243                 :            :  * an error is displayed and 0 is returned. */
+    1244                 :      24938 : static int values_equal_display_error(const LargestIntegralType left,
+    1245                 :            :                                       const LargestIntegralType right) {
+    1246                 :      24938 :     const int equal = left == right;
+    1247         [ -  + ]:      24938 :     if (!equal) {
+    1248                 :          0 :         cm_print_error(LargestIntegralTypePrintfFormat " != "
+    1249                 :            :                        LargestIntegralTypePrintfFormat "\n", left, right);
+    1250                 :            :     }
+    1251                 :      24938 :     return equal;
+    1252                 :            : }
+    1253                 :            : 
+    1254                 :            : /*
+    1255                 :            :  * Returns 1 if the specified values are not equal.  If the values are equal
+    1256                 :            :  * an error is displayed and 0 is returned. */
+    1257                 :         67 : static int values_not_equal_display_error(const LargestIntegralType left,
+    1258                 :            :                                           const LargestIntegralType right) {
+    1259                 :         67 :     const int not_equal = left != right;
+    1260         [ -  + ]:         67 :     if (!not_equal) {
+    1261                 :          0 :         cm_print_error(LargestIntegralTypePrintfFormat " == "
+    1262                 :            :                        LargestIntegralTypePrintfFormat "\n", left, right);
+    1263                 :            :     }
+    1264                 :         67 :     return not_equal;
+    1265                 :            : }
+    1266                 :            : 
+    1267                 :            : 
+    1268                 :            : /*
+    1269                 :            :  * Determine whether value is contained within check_integer_set.
+    1270                 :            :  * If invert is 0 and the value is in the set 1 is returned, otherwise 0 is
+    1271                 :            :  * returned and an error is displayed.  If invert is 1 and the value is not
+    1272                 :            :  * in the set 1 is returned, otherwise 0 is returned and an error is
+    1273                 :            :  * displayed.
+    1274                 :            :  */
+    1275                 :          0 : static int value_in_set_display_error(
+    1276                 :            :         const LargestIntegralType value,
+    1277                 :            :         const CheckIntegerSet * const check_integer_set, const int invert) {
+    1278                 :          0 :     int succeeded = invert;
+    1279                 :          0 :     assert_non_null(check_integer_set);
+    1280                 :            :     {
+    1281                 :          0 :         const LargestIntegralType * const set = check_integer_set->set;
+    1282                 :          0 :         const size_t size_of_set = check_integer_set->size_of_set;
+    1283                 :            :         size_t i;
+    1284         [ #  # ]:          0 :         for (i = 0; i < size_of_set; i++) {
+    1285         [ #  # ]:          0 :             if (set[i] == value) {
+    1286                 :            :                 /* If invert = 0 and item is found, succeeded = 1. */
+    1287                 :            :                 /* If invert = 1 and item is found, succeeded = 0. */
+    1288                 :          0 :                 succeeded = !succeeded;
+    1289                 :          0 :                 break;
+    1290                 :            :             }
+    1291                 :            :         }
+    1292         [ #  # ]:          0 :         if (succeeded) {
+    1293                 :          0 :             return 1;
+    1294                 :            :         }
+    1295         [ #  # ]:          0 :         cm_print_error(LargestIntegralTypePrintfFormatDecimal
+    1296                 :            :                        " is %sin the set (",
+    1297                 :            :                        value, invert ? "" : "not ");
+    1298         [ #  # ]:          0 :         for (i = 0; i < size_of_set; i++) {
+    1299                 :          0 :             cm_print_error(LargestIntegralTypePrintfFormat ", ", set[i]);
+    1300                 :            :         }
+    1301                 :          0 :         cm_print_error(")\n");
+    1302                 :            :     }
+    1303                 :          0 :     return 0;
+    1304                 :            : }
+    1305                 :            : 
+    1306                 :            : 
+    1307                 :            : /*
+    1308                 :            :  * Determine whether a value is within the specified range.  If the value is
+    1309                 :            :  * within the specified range 1 is returned.  If the value isn't within the
+    1310                 :            :  * specified range an error is displayed and 0 is returned.
+    1311                 :            :  */
+    1312                 :          0 : static int integer_in_range_display_error(
+    1313                 :            :         const LargestIntegralType value, const LargestIntegralType range_min,
+    1314                 :            :         const LargestIntegralType range_max) {
+    1315   [ #  #  #  # ]:          0 :     if (value >= range_min && value <= range_max) {
+    1316                 :          0 :         return 1;
+    1317                 :            :     }
+    1318                 :          0 :     cm_print_error(LargestIntegralTypePrintfFormatDecimal
+    1319                 :            :                    " is not within the range "
+    1320                 :            :                    LargestIntegralTypePrintfFormatDecimal "-"
+    1321                 :            :                    LargestIntegralTypePrintfFormatDecimal "\n",
+    1322                 :            :                    value, range_min, range_max);
+    1323                 :          0 :     return 0;
+    1324                 :            : }
+    1325                 :            : 
+    1326                 :            : 
+    1327                 :            : /*
+    1328                 :            :  * Determine whether a value is within the specified range.  If the value
+    1329                 :            :  * is not within the range 1 is returned.  If the value is within the
+    1330                 :            :  * specified range an error is displayed and zero is returned.
+    1331                 :            :  */
+    1332                 :          0 : static int integer_not_in_range_display_error(
+    1333                 :            :         const LargestIntegralType value, const LargestIntegralType range_min,
+    1334                 :            :         const LargestIntegralType range_max) {
+    1335   [ #  #  #  # ]:          0 :     if (value < range_min || value > range_max) {
+    1336                 :          0 :         return 1;
+    1337                 :            :     }
+    1338                 :          0 :     cm_print_error(LargestIntegralTypePrintfFormatDecimal
+    1339                 :            :                    " is within the range "
+    1340                 :            :                    LargestIntegralTypePrintfFormatDecimal "-"
+    1341                 :            :                    LargestIntegralTypePrintfFormatDecimal "\n",
+    1342                 :            :                    value, range_min, range_max);
+    1343                 :          0 :     return 0;
+    1344                 :            : }
+    1345                 :            : 
+    1346                 :            : 
+    1347                 :            : /*
+    1348                 :            :  * Determine whether the specified strings are equal.  If the strings are equal
+    1349                 :            :  * 1 is returned.  If they're not equal an error is displayed and 0 is
+    1350                 :            :  * returned.
+    1351                 :            :  */
+    1352                 :          9 : static int string_equal_display_error(
+    1353                 :            :         const char * const left, const char * const right) {
+    1354         [ +  - ]:          9 :     if (strcmp(left, right) == 0) {
+    1355                 :          9 :         return 1;
+    1356                 :            :     }
+    1357                 :          0 :     cm_print_error("\"%s\" != \"%s\"\n", left, right);
+    1358                 :          0 :     return 0;
+    1359                 :            : }
+    1360                 :            : 
+    1361                 :            : 
+    1362                 :            : /*
+    1363                 :            :  * Determine whether the specified strings are equal.  If the strings are not
+    1364                 :            :  * equal 1 is returned.  If they're not equal an error is displayed and 0 is
+    1365                 :            :  * returned
+    1366                 :            :  */
+    1367                 :          0 : static int string_not_equal_display_error(
+    1368                 :            :         const char * const left, const char * const right) {
+    1369         [ #  # ]:          0 :     if (strcmp(left, right) != 0) {
+    1370                 :          0 :         return 1;
+    1371                 :            :     }
+    1372                 :          0 :     cm_print_error("\"%s\" == \"%s\"\n", left, right);
+    1373                 :          0 :     return 0;
+    1374                 :            : }
+    1375                 :            : 
+    1376                 :            : 
+    1377                 :            : /*
+    1378                 :            :  * Determine whether the specified areas of memory are equal.  If they're equal
+    1379                 :            :  * 1 is returned otherwise an error is displayed and 0 is returned.
+    1380                 :            :  */
+    1381                 :        384 : static int memory_equal_display_error(const char* const a, const char* const b,
+    1382                 :            :                                       const size_t size) {
+    1383                 :        384 :     size_t differences = 0;
+    1384                 :            :     size_t i;
+    1385         [ +  + ]:      32295 :     for (i = 0; i < size; i++) {
+    1386                 :      31911 :         const char l = a[i];
+    1387                 :      31911 :         const char r = b[i];
+    1388         [ -  + ]:      31911 :         if (l != r) {
+    1389         [ #  # ]:          0 :             if (differences < 16) {
+    1390                 :          0 :                 cm_print_error("difference at offset %" PRIdS " 0x%02x 0x%02x\n",
+    1391                 :            :                                i, l, r);
+    1392                 :            :             }
+    1393                 :          0 :             differences ++;
+    1394                 :            :         }
+    1395                 :            :     }
+    1396         [ -  + ]:        384 :     if (differences > 0) {
+    1397         [ #  # ]:          0 :         if (differences >= 16) {
+    1398                 :          0 :             cm_print_error("...\n");
+    1399                 :            :         }
+    1400                 :          0 :         cm_print_error("%"PRIdS " bytes of %p and %p differ\n",
+    1401                 :            :                        differences, (void *)a, (void *)b);
+    1402                 :          0 :         return 0;
+    1403                 :            :     }
+    1404                 :        384 :     return 1;
+    1405                 :            : }
+    1406                 :            : 
+    1407                 :            : 
+    1408                 :            : /*
+    1409                 :            :  * Determine whether the specified areas of memory are not equal.  If they're
+    1410                 :            :  * not equal 1 is returned otherwise an error is displayed and 0 is
+    1411                 :            :  * returned.
+    1412                 :            :  */
+    1413                 :          6 : static int memory_not_equal_display_error(
+    1414                 :            :         const char* const a, const char* const b, const size_t size) {
+    1415                 :          6 :     size_t same = 0;
+    1416                 :            :     size_t i;
+    1417         [ +  + ]:       2919 :     for (i = 0; i < size; i++) {
+    1418                 :       2913 :         const char l = a[i];
+    1419                 :       2913 :         const char r = b[i];
+    1420         [ +  + ]:       2913 :         if (l == r) {
+    1421                 :         30 :             same ++;
+    1422                 :            :         }
+    1423                 :            :     }
+    1424         [ -  + ]:          6 :     if (same == size) {
+    1425                 :          0 :         cm_print_error("%"PRIdS "bytes of %p and %p the same\n",
+    1426                 :            :                        same, (void *)a, (void *)b);
+    1427                 :          0 :         return 0;
+    1428                 :            :     }
+    1429                 :          6 :     return 1;
+    1430                 :            : }
+    1431                 :            : 
+    1432                 :            : 
+    1433                 :            : /* CheckParameterValue callback to check whether a value is within a set. */
+    1434                 :          0 : static int check_in_set(const LargestIntegralType value,
+    1435                 :            :                         const LargestIntegralType check_value_data) {
+    1436                 :          0 :     return value_in_set_display_error(value,
+    1437                 :            :         cast_largest_integral_type_to_pointer(CheckIntegerSet*,
+    1438                 :            :                                               check_value_data), 0);
+    1439                 :            : }
+    1440                 :            : 
+    1441                 :            : 
+    1442                 :            : /* CheckParameterValue callback to check whether a value isn't within a set. */
+    1443                 :          0 : static int check_not_in_set(const LargestIntegralType value,
+    1444                 :            :                             const LargestIntegralType check_value_data) {
+    1445                 :          0 :     return value_in_set_display_error(value,
+    1446                 :            :         cast_largest_integral_type_to_pointer(CheckIntegerSet*,
+    1447                 :            :                                               check_value_data), 1);
+    1448                 :            : }
+    1449                 :            : 
+    1450                 :            : 
+    1451                 :            : /* Create the callback data for check_in_set() or check_not_in_set() and
+    1452                 :            :  * register a check event. */
+    1453                 :          0 : static void expect_set(
+    1454                 :            :         const char* const function, const char* const parameter,
+    1455                 :            :         const char* const file, const int line,
+    1456                 :            :         const LargestIntegralType values[], const size_t number_of_values,
+    1457                 :            :         const CheckParameterValue check_function, const int count) {
+    1458                 :            :     CheckIntegerSet * const check_integer_set =
+    1459                 :          0 :         (CheckIntegerSet*)malloc(sizeof(*check_integer_set) +
+    1460                 :            :                (sizeof(values[0]) * number_of_values));
+    1461                 :          0 :     LargestIntegralType * const set = (LargestIntegralType*)(
+    1462                 :            :         check_integer_set + 1);
+    1463                 :          0 :     declare_initialize_value_pointer_pointer(check_data, check_integer_set);
+    1464                 :          0 :     assert_non_null(values);
+    1465                 :          0 :     assert_true(number_of_values);
+    1466                 :          0 :     memcpy(set, values, number_of_values * sizeof(values[0]));
+    1467                 :          0 :     check_integer_set->set = set;
+    1468                 :          0 :     check_integer_set->size_of_set = number_of_values;
+    1469                 :          0 :     _expect_check(
+    1470                 :            :         function, parameter, file, line, check_function,
+    1471                 :            :         check_data, &check_integer_set->event, count);
+    1472                 :          0 : }
+    1473                 :            : 
+    1474                 :            : 
+    1475                 :            : /* Add an event to check whether a value is in a set. */
+    1476                 :          0 : void _expect_in_set(
+    1477                 :            :         const char* const function, const char* const parameter,
+    1478                 :            :         const char* const file, const int line,
+    1479                 :            :         const LargestIntegralType values[], const size_t number_of_values,
+    1480                 :            :         const int count) {
+    1481                 :          0 :     expect_set(function, parameter, file, line, values, number_of_values,
+    1482                 :            :                check_in_set, count);
+    1483                 :          0 : }
+    1484                 :            : 
+    1485                 :            : 
+    1486                 :            : /* Add an event to check whether a value isn't in a set. */
+    1487                 :          0 : void _expect_not_in_set(
+    1488                 :            :         const char* const function, const char* const parameter,
+    1489                 :            :         const char* const file, const int line,
+    1490                 :            :         const LargestIntegralType values[], const size_t number_of_values,
+    1491                 :            :         const int count) {
+    1492                 :          0 :     expect_set(function, parameter, file, line, values, number_of_values,
+    1493                 :            :                check_not_in_set, count);
+    1494                 :          0 : }
+    1495                 :            : 
+    1496                 :            : 
+    1497                 :            : /* CheckParameterValue callback to check whether a value is within a range. */
+    1498                 :          0 : static int check_in_range(const LargestIntegralType value,
+    1499                 :            :                           const LargestIntegralType check_value_data) {
+    1500                 :          0 :     CheckIntegerRange * const check_integer_range =
+    1501                 :            :         cast_largest_integral_type_to_pointer(CheckIntegerRange*,
+    1502                 :            :                                               check_value_data);
+    1503                 :          0 :     assert_non_null(check_integer_range);
+    1504                 :          0 :     return integer_in_range_display_error(value, check_integer_range->minimum,
+    1505                 :            :                                           check_integer_range->maximum);
+    1506                 :            : }
+    1507                 :            : 
+    1508                 :            : 
+    1509                 :            : /* CheckParameterValue callback to check whether a value is not within a range. */
+    1510                 :          0 : static int check_not_in_range(const LargestIntegralType value,
+    1511                 :            :                               const LargestIntegralType check_value_data) {
+    1512                 :          0 :     CheckIntegerRange * const check_integer_range =
+    1513                 :            :         cast_largest_integral_type_to_pointer(CheckIntegerRange*,
+    1514                 :            :                                               check_value_data);
+    1515                 :          0 :     assert_non_null(check_integer_range);
+    1516                 :          0 :     return integer_not_in_range_display_error(
+    1517                 :            :         value, check_integer_range->minimum, check_integer_range->maximum);
+    1518                 :            : }
+    1519                 :            : 
+    1520                 :            : 
+    1521                 :            : /* Create the callback data for check_in_range() or check_not_in_range() and
+    1522                 :            :  * register a check event. */
+    1523                 :          0 : static void expect_range(
+    1524                 :            :         const char* const function, const char* const parameter,
+    1525                 :            :         const char* const file, const int line,
+    1526                 :            :         const LargestIntegralType minimum, const LargestIntegralType maximum,
+    1527                 :            :         const CheckParameterValue check_function, const int count) {
+    1528                 :            :     CheckIntegerRange * const check_integer_range =
+    1529                 :          0 :         (CheckIntegerRange*)malloc(sizeof(*check_integer_range));
+    1530                 :          0 :     declare_initialize_value_pointer_pointer(check_data, check_integer_range);
+    1531                 :          0 :     check_integer_range->minimum = minimum;
+    1532                 :          0 :     check_integer_range->maximum = maximum;
+    1533                 :          0 :     _expect_check(function, parameter, file, line, check_function,
+    1534                 :            :                   check_data, &check_integer_range->event, count);
+    1535                 :          0 : }
+    1536                 :            : 
+    1537                 :            : 
+    1538                 :            : /* Add an event to determine whether a parameter is within a range. */
+    1539                 :          0 : void _expect_in_range(
+    1540                 :            :         const char* const function, const char* const parameter,
+    1541                 :            :         const char* const file, const int line,
+    1542                 :            :         const LargestIntegralType minimum, const LargestIntegralType maximum,
+    1543                 :            :         const int count) {
+    1544                 :          0 :     expect_range(function, parameter, file, line, minimum, maximum,
+    1545                 :            :                  check_in_range, count);
+    1546                 :          0 : }
+    1547                 :            : 
+    1548                 :            : 
+    1549                 :            : /* Add an event to determine whether a parameter is not within a range. */
+    1550                 :          0 : void _expect_not_in_range(
+    1551                 :            :         const char* const function, const char* const parameter,
+    1552                 :            :         const char* const file, const int line,
+    1553                 :            :         const LargestIntegralType minimum, const LargestIntegralType maximum,
+    1554                 :            :         const int count) {
+    1555                 :          0 :     expect_range(function, parameter, file, line, minimum, maximum,
+    1556                 :            :                  check_not_in_range, count);
+    1557                 :          0 : }
+    1558                 :            : 
+    1559                 :            : 
+    1560                 :            : /* CheckParameterValue callback to check whether a value is equal to an
+    1561                 :            :  * expected value. */
+    1562                 :          0 : static int check_value(const LargestIntegralType value,
+    1563                 :            :                        const LargestIntegralType check_value_data) {
+    1564                 :          0 :     return values_equal_display_error(value, check_value_data);
+    1565                 :            : }
+    1566                 :            : 
+    1567                 :            : 
+    1568                 :            : /* Add an event to check a parameter equals an expected value. */
+    1569                 :          0 : void _expect_value(
+    1570                 :            :         const char* const function, const char* const parameter,
+    1571                 :            :         const char* const file, const int line,
+    1572                 :            :         const LargestIntegralType value, const int count) {
+    1573                 :          0 :     _expect_check(function, parameter, file, line, check_value, value, NULL,
+    1574                 :            :                   count);
+    1575                 :          0 : }
+    1576                 :            : 
+    1577                 :            : 
+    1578                 :            : /* CheckParameterValue callback to check whether a value is not equal to an
+    1579                 :            :  * expected value. */
+    1580                 :          0 : static int check_not_value(const LargestIntegralType value,
+    1581                 :            :                            const LargestIntegralType check_value_data) {
+    1582                 :          0 :     return values_not_equal_display_error(value, check_value_data);
+    1583                 :            : }
+    1584                 :            : 
+    1585                 :            : 
+    1586                 :            : /* Add an event to check a parameter is not equal to an expected value. */
+    1587                 :          0 : void _expect_not_value(
+    1588                 :            :         const char* const function, const char* const parameter,
+    1589                 :            :         const char* const file, const int line,
+    1590                 :            :         const LargestIntegralType value, const int count) {
+    1591                 :          0 :     _expect_check(function, parameter, file, line, check_not_value, value,
+    1592                 :            :                   NULL, count);
+    1593                 :          0 : }
+    1594                 :            : 
+    1595                 :            : 
+    1596                 :            : /* CheckParameterValue callback to check whether a parameter equals a string. */
+    1597                 :          0 : static int check_string(const LargestIntegralType value,
+    1598                 :            :                         const LargestIntegralType check_value_data) {
+    1599                 :          0 :     return string_equal_display_error(
+    1600                 :            :         cast_largest_integral_type_to_pointer(char*, value),
+    1601                 :            :         cast_largest_integral_type_to_pointer(char*, check_value_data));
+    1602                 :            : }
+    1603                 :            : 
+    1604                 :            : 
+    1605                 :            : /* Add an event to check whether a parameter is equal to a string. */
+    1606                 :          0 : void _expect_string(
+    1607                 :            :         const char* const function, const char* const parameter,
+    1608                 :            :         const char* const file, const int line, const char* string,
+    1609                 :            :         const int count) {
+    1610                 :          0 :     declare_initialize_value_pointer_pointer(string_pointer,
+    1611                 :            :                                              discard_const(string));
+    1612                 :          0 :     _expect_check(function, parameter, file, line, check_string,
+    1613                 :            :                   string_pointer, NULL, count);
+    1614                 :          0 : }
+    1615                 :            : 
+    1616                 :            : 
+    1617                 :            : /* CheckParameterValue callback to check whether a parameter is not equals to
+    1618                 :            :  * a string. */
+    1619                 :          0 : static int check_not_string(const LargestIntegralType value,
+    1620                 :            :                             const LargestIntegralType check_value_data) {
+    1621                 :          0 :     return string_not_equal_display_error(
+    1622                 :            :         cast_largest_integral_type_to_pointer(char*, value),
+    1623                 :            :         cast_largest_integral_type_to_pointer(char*, check_value_data));
+    1624                 :            : }
+    1625                 :            : 
+    1626                 :            : 
+    1627                 :            : /* Add an event to check whether a parameter is not equal to a string. */
+    1628                 :          0 : void _expect_not_string(
+    1629                 :            :         const char* const function, const char* const parameter,
+    1630                 :            :         const char* const file, const int line, const char* string,
+    1631                 :            :         const int count) {
+    1632                 :          0 :     declare_initialize_value_pointer_pointer(string_pointer,
+    1633                 :            :                                              discard_const(string));
+    1634                 :          0 :     _expect_check(function, parameter, file, line, check_not_string,
+    1635                 :            :                   string_pointer, NULL, count);
+    1636                 :          0 : }
+    1637                 :            : 
+    1638                 :            : /* CheckParameterValue callback to check whether a parameter equals an area of
+    1639                 :            :  * memory. */
+    1640                 :          0 : static int check_memory(const LargestIntegralType value,
+    1641                 :            :                         const LargestIntegralType check_value_data) {
+    1642                 :          0 :     CheckMemoryData * const check = cast_largest_integral_type_to_pointer(
+    1643                 :            :         CheckMemoryData*, check_value_data);
+    1644                 :          0 :     assert_non_null(check);
+    1645                 :          0 :     return memory_equal_display_error(
+    1646                 :            :         cast_largest_integral_type_to_pointer(const char*, value),
+    1647                 :          0 :         (const char*)check->memory, check->size);
+    1648                 :            : }
+    1649                 :            : 
+    1650                 :            : 
+    1651                 :            : /* Create the callback data for check_memory() or check_not_memory() and
+    1652                 :            :  * register a check event. */
+    1653                 :          0 : static void expect_memory_setup(
+    1654                 :            :         const char* const function, const char* const parameter,
+    1655                 :            :         const char* const file, const int line,
+    1656                 :            :         const void * const memory, const size_t size,
+    1657                 :            :         const CheckParameterValue check_function, const int count) {
+    1658                 :            :     CheckMemoryData * const check_data =
+    1659                 :          0 :         (CheckMemoryData*)malloc(sizeof(*check_data) + size);
+    1660                 :          0 :     void * const mem = (void*)(check_data + 1);
+    1661                 :          0 :     declare_initialize_value_pointer_pointer(check_data_pointer, check_data);
+    1662                 :          0 :     assert_non_null(memory);
+    1663                 :          0 :     assert_true(size);
+    1664                 :          0 :     memcpy(mem, memory, size);
+    1665                 :          0 :     check_data->memory = mem;
+    1666                 :          0 :     check_data->size = size;
+    1667                 :          0 :     _expect_check(function, parameter, file, line, check_function,
+    1668                 :            :                   check_data_pointer, &check_data->event, count);
+    1669                 :          0 : }
+    1670                 :            : 
+    1671                 :            : 
+    1672                 :            : /* Add an event to check whether a parameter matches an area of memory. */
+    1673                 :          0 : void _expect_memory(
+    1674                 :            :         const char* const function, const char* const parameter,
+    1675                 :            :         const char* const file, const int line, const void* const memory,
+    1676                 :            :         const size_t size, const int count) {
+    1677                 :          0 :     expect_memory_setup(function, parameter, file, line, memory, size,
+    1678                 :            :                         check_memory, count);
+    1679                 :          0 : }
+    1680                 :            : 
+    1681                 :            : 
+    1682                 :            : /* CheckParameterValue callback to check whether a parameter is not equal to
+    1683                 :            :  * an area of memory. */
+    1684                 :          0 : static int check_not_memory(const LargestIntegralType value,
+    1685                 :            :                             const LargestIntegralType check_value_data) {
+    1686                 :          0 :     CheckMemoryData * const check = cast_largest_integral_type_to_pointer(
+    1687                 :            :         CheckMemoryData*, check_value_data);
+    1688                 :          0 :     assert_non_null(check);
+    1689                 :          0 :     return memory_not_equal_display_error(
+    1690                 :            :         cast_largest_integral_type_to_pointer(const char*, value),
+    1691                 :          0 :         (const char*)check->memory,
+    1692                 :            :         check->size);
+    1693                 :            : }
+    1694                 :            : 
+    1695                 :            : 
+    1696                 :            : /* Add an event to check whether a parameter doesn't match an area of memory. */
+    1697                 :          0 : void _expect_not_memory(
+    1698                 :            :         const char* const function, const char* const parameter,
+    1699                 :            :         const char* const file, const int line, const void* const memory,
+    1700                 :            :         const size_t size, const int count) {
+    1701                 :          0 :     expect_memory_setup(function, parameter, file, line, memory, size,
+    1702                 :            :                         check_not_memory, count);
+    1703                 :          0 : }
+    1704                 :            : 
+    1705                 :            : 
+    1706                 :            : /* CheckParameterValue callback that always returns 1. */
+    1707                 :          0 : static int check_any(const LargestIntegralType value,
+    1708                 :            :                      const LargestIntegralType check_value_data) {
+    1709                 :            :     (void)value;
+    1710                 :            :     (void)check_value_data;
+    1711                 :          0 :     return 1;
+    1712                 :            : }
+    1713                 :            : 
+    1714                 :            : 
+    1715                 :            : /* Add an event to allow any value for a parameter. */
+    1716                 :          0 : void _expect_any(
+    1717                 :            :         const char* const function, const char* const parameter,
+    1718                 :            :         const char* const file, const int line, const int count) {
+    1719                 :          0 :     _expect_check(function, parameter, file, line, check_any, 0, NULL,
+    1720                 :            :                   count);
+    1721                 :          0 : }
+    1722                 :            : 
+    1723                 :            : 
+    1724                 :          0 : void _check_expected(
+    1725                 :            :         const char * const function_name, const char * const parameter_name,
+    1726                 :            :         const char* file, const int line, const LargestIntegralType value) {
+    1727                 :          0 :     void *result = NULL;
+    1728                 :          0 :     const char* symbols[] = {function_name, parameter_name};
+    1729                 :          0 :     const int rc = get_symbol_value(&global_function_parameter_map_head,
+    1730                 :            :                                     symbols, 2, &result);
+    1731         [ #  # ]:          0 :     if (rc) {
+    1732                 :          0 :         CheckParameterEvent * const check = (CheckParameterEvent*)result;
+    1733                 :            :         int check_succeeded;
+    1734                 :          0 :         global_last_parameter_location = check->location;
+    1735                 :          0 :         check_succeeded = check->check_value(value, check->check_value_data);
+    1736         [ #  # ]:          0 :         if (rc == 1) {
+    1737                 :          0 :             free(check);
+    1738                 :            :         }
+    1739         [ #  # ]:          0 :         if (!check_succeeded) {
+    1740                 :          0 :             cm_print_error(SOURCE_LOCATION_FORMAT
+    1741                 :            :                            ": error: Check of parameter %s, function %s failed\n"
+    1742                 :            :                            SOURCE_LOCATION_FORMAT
+    1743                 :            :                            ": note: Expected parameter declared here\n",
+    1744                 :            :                            file, line,
+    1745                 :            :                            parameter_name, function_name,
+    1746                 :            :                            global_last_parameter_location.file,
+    1747                 :            :                            global_last_parameter_location.line);
+    1748                 :          0 :             _fail(file, line);
+    1749                 :            :         }
+    1750                 :            :     } else {
+    1751                 :          0 :         cm_print_error(SOURCE_LOCATION_FORMAT ": error: Could not get value "
+    1752                 :            :                     "to check parameter %s of function %s\n", file, line,
+    1753                 :            :                     parameter_name, function_name);
+    1754         [ #  # ]:          0 :         if (source_location_is_set(&global_last_parameter_location)) {
+    1755                 :          0 :             cm_print_error(SOURCE_LOCATION_FORMAT
+    1756                 :            :                         ": note: Previously declared parameter value was declared here\n",
+    1757                 :            :                         global_last_parameter_location.file,
+    1758                 :            :                         global_last_parameter_location.line);
+    1759                 :            :         } else {
+    1760                 :          0 :             cm_print_error("There were no previously declared parameter values "
+    1761                 :            :                         "for this test.\n");
+    1762                 :            :         }
+    1763                 :          0 :         exit_test(1);
+    1764                 :            :     }
+    1765                 :          0 : }
+    1766                 :            : 
+    1767                 :            : 
+    1768                 :            : /* Replacement for assert. */
+    1769                 :          0 : void mock_assert(const int result, const char* const expression,
+    1770                 :            :                  const char* const file, const int line) {
+    1771         [ #  # ]:          0 :     if (!result) {
+    1772         [ #  # ]:          0 :         if (global_expecting_assert) {
+    1773                 :          0 :             global_last_failed_assert = expression;
+    1774                 :          0 :             longjmp(global_expect_assert_env, result);
+    1775                 :            :         } else {
+    1776                 :          0 :             cm_print_error("ASSERT: %s\n", expression);
+    1777                 :          0 :             _fail(file, line);
+    1778                 :            :         }
+    1779                 :            :     }
+    1780                 :          0 : }
+    1781                 :            : 
+    1782                 :            : 
+    1783                 :      29996 : void _assert_true(const LargestIntegralType result,
+    1784                 :            :                   const char * const expression,
+    1785                 :            :                   const char * const file, const int line) {
+    1786         [ -  + ]:      29996 :     if (!result) {
+    1787                 :          0 :         cm_print_error("%s\n", expression);
+    1788                 :          0 :         _fail(file, line);
+    1789                 :            :     }
+    1790                 :      29996 : }
+    1791                 :            : 
+    1792                 :          0 : void _assert_return_code(const LargestIntegralType result,
+    1793                 :            :                          size_t rlen,
+    1794                 :            :                          const LargestIntegralType error,
+    1795                 :            :                          const char * const expression,
+    1796                 :            :                          const char * const file,
+    1797                 :            :                          const int line)
+    1798                 :            : {
+    1799                 :            :     LargestIntegralType valmax;
+    1800                 :            : 
+    1801                 :            : 
+    1802   [ #  #  #  # ]:          0 :     switch (rlen) {
+    1803                 :          0 :     case 1:
+    1804                 :          0 :         valmax = 255;
+    1805                 :          0 :         break;
+    1806                 :          0 :     case 2:
+    1807                 :          0 :         valmax = 32767;
+    1808                 :          0 :         break;
+    1809                 :          0 :     case 4:
+    1810                 :          0 :         valmax = 2147483647;
+    1811                 :          0 :         break;
+    1812                 :          0 :     case 8:
+    1813                 :            :     default:
+    1814         [ #  # ]:          0 :         if (rlen > sizeof(valmax)) {
+    1815                 :          0 :             valmax = 2147483647;
+    1816                 :            :         } else {
+    1817                 :          0 :             valmax = 9223372036854775807L;
+    1818                 :            :         }
+    1819                 :          0 :         break;
+    1820                 :            :     }
+    1821                 :            : 
+    1822         [ #  # ]:          0 :     if (result > valmax - 1) {
+    1823         [ #  # ]:          0 :         if (error > 0) {
+    1824                 :          0 :             cm_print_error("%s < 0, errno("
+    1825                 :            :                            LargestIntegralTypePrintfFormatDecimal "): %s\n",
+    1826                 :            :                            expression, error, strerror((int)error));
+    1827                 :            :         } else {
+    1828                 :          0 :             cm_print_error("%s < 0\n", expression);
+    1829                 :            :         }
+    1830                 :          0 :         _fail(file, line);
+    1831                 :            :     }
+    1832                 :          0 : }
+    1833                 :            : 
+    1834                 :          0 : void _assert_float_equal(const float a,
+    1835                 :            :                          const float b,
+    1836                 :            :                          const float epsilon,
+    1837                 :            :                          const char * const file,
+    1838                 :            :                          const int line) {
+    1839         [ #  # ]:          0 :     if (!float_values_equal_display_error(a, b, epsilon)) {
+    1840                 :          0 :         _fail(file, line);
+    1841                 :            :     }
+    1842                 :          0 : }
+    1843                 :            : 
+    1844                 :          0 : void _assert_float_not_equal(const float a,
+    1845                 :            :                              const float b,
+    1846                 :            :                              const float epsilon,
+    1847                 :            :                              const char * const file,
+    1848                 :            :                              const int line) {
+    1849         [ #  # ]:          0 :     if (!float_values_not_equal_display_error(a, b, epsilon)) {
+    1850                 :          0 :         _fail(file, line);
+    1851                 :            :     }
+    1852                 :          0 : }
+    1853                 :            : 
+    1854                 :          0 : void _assert_double_equal(const double a,
+    1855                 :            :                           const double b,
+    1856                 :            :                           const double epsilon,
+    1857                 :            :                           const char * const file,
+    1858                 :            :                           const int line) {
+    1859         [ #  # ]:          0 :     if (!double_values_equal_display_error(a, b, epsilon)) {
+    1860                 :          0 :         _fail(file, line);
+    1861                 :            :     }
+    1862                 :          0 : }
+    1863                 :            : 
+    1864                 :          0 : void _assert_double_not_equal(const double a,
+    1865                 :            :                               const double b,
+    1866                 :            :                               const double epsilon,
+    1867                 :            :                               const char * const file,
+    1868                 :            :                               const int line) {
+    1869         [ #  # ]:          0 :     if (!double_values_not_equal_display_error(a, b, epsilon)) {
+    1870                 :          0 :         _fail(file, line);
+    1871                 :            :     }
+    1872                 :          0 : }
+    1873                 :            : 
+    1874                 :      24938 : void _assert_int_equal(
+    1875                 :            :         const LargestIntegralType a, const LargestIntegralType b,
+    1876                 :            :         const char * const file, const int line) {
+    1877         [ -  + ]:      24938 :     if (!values_equal_display_error(a, b)) {
+    1878                 :          0 :         _fail(file, line);
+    1879                 :            :     }
+    1880                 :      24938 : }
+    1881                 :            : 
+    1882                 :            : 
+    1883                 :         67 : void _assert_int_not_equal(
+    1884                 :            :         const LargestIntegralType a, const LargestIntegralType b,
+    1885                 :            :         const char * const file, const int line) {
+    1886         [ -  + ]:         67 :     if (!values_not_equal_display_error(a, b)) {
+    1887                 :          0 :         _fail(file, line);
+    1888                 :            :     }
+    1889                 :         67 : }
+    1890                 :            : 
+    1891                 :            : 
+    1892                 :          9 : void _assert_string_equal(const char * const a, const char * const b,
+    1893                 :            :                           const char * const file, const int line) {
+    1894         [ -  + ]:          9 :     if (!string_equal_display_error(a, b)) {
+    1895                 :          0 :         _fail(file, line);
+    1896                 :            :     }
+    1897                 :          9 : }
+    1898                 :            : 
+    1899                 :            : 
+    1900                 :          0 : void _assert_string_not_equal(const char * const a, const char * const b,
+    1901                 :            :                               const char *file, const int line) {
+    1902         [ #  # ]:          0 :     if (!string_not_equal_display_error(a, b)) {
+    1903                 :          0 :         _fail(file, line);
+    1904                 :            :     }
+    1905                 :          0 : }
+    1906                 :            : 
+    1907                 :            : 
+    1908                 :        384 : void _assert_memory_equal(const void * const a, const void * const b,
+    1909                 :            :                           const size_t size, const char* const file,
+    1910                 :            :                           const int line) {
+    1911         [ -  + ]:        384 :     if (!memory_equal_display_error((const char*)a, (const char*)b, size)) {
+    1912                 :          0 :         _fail(file, line);
+    1913                 :            :     }
+    1914                 :        384 : }
+    1915                 :            : 
+    1916                 :            : 
+    1917                 :          6 : void _assert_memory_not_equal(const void * const a, const void * const b,
+    1918                 :            :                               const size_t size, const char* const file,
+    1919                 :            :                               const int line) {
+    1920         [ -  + ]:          6 :     if (!memory_not_equal_display_error((const char*)a, (const char*)b,
+    1921                 :            :                                         size)) {
+    1922                 :          0 :         _fail(file, line);
+    1923                 :            :     }
+    1924                 :          6 : }
+    1925                 :            : 
+    1926                 :            : 
+    1927                 :          0 : void _assert_in_range(
+    1928                 :            :         const LargestIntegralType value, const LargestIntegralType minimum,
+    1929                 :            :         const LargestIntegralType maximum, const char* const file,
+    1930                 :            :         const int line) {
+    1931         [ #  # ]:          0 :     if (!integer_in_range_display_error(value, minimum, maximum)) {
+    1932                 :          0 :         _fail(file, line);
+    1933                 :            :     }
+    1934                 :          0 : }
+    1935                 :            : 
+    1936                 :          0 : void _assert_not_in_range(
+    1937                 :            :         const LargestIntegralType value, const LargestIntegralType minimum,
+    1938                 :            :         const LargestIntegralType maximum, const char* const file,
+    1939                 :            :         const int line) {
+    1940         [ #  # ]:          0 :     if (!integer_not_in_range_display_error(value, minimum, maximum)) {
+    1941                 :          0 :         _fail(file, line);
+    1942                 :            :     }
+    1943                 :          0 : }
+    1944                 :            : 
+    1945                 :          0 : void _assert_in_set(const LargestIntegralType value,
+    1946                 :            :                     const LargestIntegralType values[],
+    1947                 :            :                     const size_t number_of_values, const char* const file,
+    1948                 :            :                     const int line) {
+    1949                 :            :     CheckIntegerSet check_integer_set;
+    1950                 :          0 :     check_integer_set.set = values;
+    1951                 :          0 :     check_integer_set.size_of_set = number_of_values;
+    1952         [ #  # ]:          0 :     if (!value_in_set_display_error(value, &check_integer_set, 0)) {
+    1953                 :          0 :         _fail(file, line);
+    1954                 :            :     }
+    1955                 :          0 : }
+    1956                 :            : 
+    1957                 :          0 : void _assert_not_in_set(const LargestIntegralType value,
+    1958                 :            :                         const LargestIntegralType values[],
+    1959                 :            :                         const size_t number_of_values, const char* const file,
+    1960                 :            :                         const int line) {
+    1961                 :            :     CheckIntegerSet check_integer_set;
+    1962                 :          0 :     check_integer_set.set = values;
+    1963                 :          0 :     check_integer_set.size_of_set = number_of_values;
+    1964         [ #  # ]:          0 :     if (!value_in_set_display_error(value, &check_integer_set, 1)) {
+    1965                 :          0 :         _fail(file, line);
+    1966                 :            :     }
+    1967                 :          0 : }
+    1968                 :            : 
+    1969                 :            : 
+    1970                 :            : /* Get the list of allocated blocks. */
+    1971                 :       2387 : static ListNode* get_allocated_blocks_list(void) {
+    1972                 :            :     /* If it initialized, initialize the list of allocated blocks. */
+    1973         [ +  + ]:       2387 :     if (!global_allocated_blocks.value) {
+    1974                 :          5 :         list_initialize(&global_allocated_blocks);
+    1975                 :          5 :         global_allocated_blocks.value = (void*)1;
+    1976                 :            :     }
+    1977                 :       2387 :     return &global_allocated_blocks;
+    1978                 :            : }
+    1979                 :            : 
+    1980                 :         78 : static void *libc_calloc(size_t nmemb, size_t size)
+    1981                 :            : {
+    1982                 :            : #undef calloc
+    1983                 :         78 :     return calloc(nmemb, size);
+    1984                 :            : #define calloc test_calloc
+    1985                 :            : }
+    1986                 :            : 
+    1987                 :       1148 : static void libc_free(void *ptr)
+    1988                 :            : {
+    1989                 :            : #undef free
+    1990                 :       1148 :     free(ptr);
+    1991                 :            : #define free test_free
+    1992                 :       1148 : }
+    1993                 :            : 
+    1994                 :          0 : static void *libc_realloc(void *ptr, size_t size)
+    1995                 :            : {
+    1996                 :            : #undef realloc
+    1997                 :          0 :     return realloc(ptr, size);
+    1998                 :            : #define realloc test_realloc
+    1999                 :            : }
+    2000                 :            : 
+    2001                 :            : static void vcm_print_error(const char* const format,
+    2002                 :            :                             va_list args) CMOCKA_PRINTF_ATTRIBUTE(1, 0);
+    2003                 :            : 
+    2004                 :            : /* It's important to use the libc malloc and free here otherwise
+    2005                 :            :  * the automatic free of leaked blocks can reap the error messages
+    2006                 :            :  */
+    2007                 :          0 : static void vcm_print_error(const char* const format, va_list args)
+    2008                 :            : {
+    2009                 :            :     char buffer[1024];
+    2010                 :          0 :     size_t msg_len = 0;
+    2011                 :            :     va_list ap;
+    2012                 :            :     int len;
+    2013                 :          0 :     va_copy(ap, args);
+    2014                 :            : 
+    2015                 :          0 :     len = vsnprintf(buffer, sizeof(buffer), format, args);
+    2016         [ #  # ]:          0 :     if (len < 0) {
+    2017                 :            :         /* TODO */
+    2018                 :          0 :         goto end;
+    2019                 :            :     }
+    2020                 :            : 
+    2021         [ #  # ]:          0 :     if (cm_error_message == NULL) {
+    2022                 :            :         /* CREATE MESSAGE */
+    2023                 :            : 
+    2024                 :          0 :         cm_error_message = libc_calloc(1, len + 1);
+    2025         [ #  # ]:          0 :         if (cm_error_message == NULL) {
+    2026                 :            :             /* TODO */
+    2027                 :          0 :             goto end;
+    2028                 :            :         }
+    2029                 :            :     } else {
+    2030                 :            :         /* APPEND MESSAGE */
+    2031                 :            :         char *tmp;
+    2032                 :            : 
+    2033                 :          0 :         msg_len = strlen(cm_error_message);
+    2034                 :          0 :         tmp = libc_realloc(cm_error_message, msg_len + len + 1);
+    2035         [ #  # ]:          0 :         if (tmp == NULL) {
+    2036                 :          0 :             goto end;
+    2037                 :            :         }
+    2038                 :          0 :         cm_error_message = tmp;
+    2039                 :            :     }
+    2040                 :            : 
+    2041         [ #  # ]:          0 :     if (((size_t)len) < sizeof(buffer)) {
+    2042                 :            :         /* Use len + 1 to also copy '\0' */
+    2043                 :          0 :         memcpy(cm_error_message + msg_len, buffer, len + 1);
+    2044                 :            :     } else {
+    2045                 :          0 :         vsnprintf(cm_error_message + msg_len, len, format, ap);
+    2046                 :            :     }
+    2047                 :          0 : end:
+    2048                 :          0 :     va_end(ap);
+    2049                 :            : 
+    2050                 :          0 : }
+    2051                 :            : 
+    2052                 :       1070 : static void vcm_free_error(char *err_msg)
+    2053                 :            : {
+    2054                 :       1070 :     libc_free(err_msg);
+    2055                 :       1070 : }
+    2056                 :            : 
+    2057                 :            : /* Use the real malloc in this function. */
+    2058                 :            : #undef malloc
+    2059                 :          0 : void* _test_malloc(const size_t size, const char* file, const int line) {
+    2060                 :          0 :     char *ptr = NULL;
+    2061                 :            :     MallocBlockInfo block_info;
+    2062                 :          0 :     ListNode * const block_list = get_allocated_blocks_list();
+    2063                 :            :     size_t allocate_size;
+    2064                 :          0 :     char *block = NULL;
+    2065                 :            : 
+    2066                 :          0 :     allocate_size = size + (MALLOC_GUARD_SIZE * 2) +
+    2067                 :            :                     sizeof(struct MallocBlockInfoData) + MALLOC_ALIGNMENT;
+    2068                 :          0 :     assert_true(allocate_size > size);
+    2069                 :            : 
+    2070                 :          0 :     block = (char *)malloc(allocate_size);
+    2071                 :          0 :     assert_non_null(block);
+    2072                 :            : 
+    2073                 :            :     /* Calculate the returned address. */
+    2074                 :          0 :     ptr = (char*)(((size_t)block + MALLOC_GUARD_SIZE +
+    2075                 :          0 :                   sizeof(struct MallocBlockInfoData) +
+    2076                 :          0 :                   MALLOC_ALIGNMENT) & ~(MALLOC_ALIGNMENT - 1));
+    2077                 :            : 
+    2078                 :            :     /* Initialize the guard blocks. */
+    2079                 :          0 :     memset(ptr - MALLOC_GUARD_SIZE, MALLOC_GUARD_PATTERN, MALLOC_GUARD_SIZE);
+    2080                 :          0 :     memset(ptr + size, MALLOC_GUARD_PATTERN, MALLOC_GUARD_SIZE);
+    2081                 :          0 :     memset(ptr, MALLOC_ALLOC_PATTERN, size);
+    2082                 :            : 
+    2083                 :          0 :     block_info.ptr = ptr - (MALLOC_GUARD_SIZE +
+    2084                 :            :                             sizeof(struct MallocBlockInfoData));
+    2085                 :          0 :     set_source_location(&block_info.data->location, file, line);
+    2086                 :          0 :     block_info.data->allocated_size = allocate_size;
+    2087                 :          0 :     block_info.data->size = size;
+    2088                 :          0 :     block_info.data->block = block;
+    2089                 :          0 :     block_info.data->node.value = block_info.ptr;
+    2090                 :          0 :     list_add(block_list, &block_info.data->node);
+    2091                 :          0 :     return ptr;
+    2092                 :            : }
+    2093                 :            : #define malloc test_malloc
+    2094                 :            : 
+    2095                 :            : 
+    2096                 :          0 : void* _test_calloc(const size_t number_of_elements, const size_t size,
+    2097                 :            :                    const char* file, const int line) {
+    2098                 :          0 :     void* const ptr = _test_malloc(number_of_elements * size, file, line);
+    2099         [ #  # ]:          0 :     if (ptr) {
+    2100                 :          0 :         memset(ptr, 0, number_of_elements * size);
+    2101                 :            :     }
+    2102                 :          0 :     return ptr;
+    2103                 :            : }
+    2104                 :            : #define calloc test_calloc
+    2105                 :            : 
+    2106                 :            : 
+    2107                 :            : /* Use the real free in this function. */
+    2108                 :            : #undef free
+    2109                 :          0 : void _test_free(void* const ptr, const char* file, const int line) {
+    2110                 :            :     unsigned int i;
+    2111                 :          0 :     char *block = discard_const_p(char, ptr);
+    2112                 :            :     MallocBlockInfo block_info;
+    2113                 :            : 
+    2114         [ #  # ]:          0 :     if (ptr == NULL) {
+    2115                 :          0 :         return;
+    2116                 :            :     }
+    2117                 :            : 
+    2118                 :          0 :     _assert_true(cast_ptr_to_largest_integral_type(ptr), "ptr", file, line);
+    2119                 :          0 :     block_info.ptr = block - (MALLOC_GUARD_SIZE +
+    2120                 :            :                               sizeof(struct MallocBlockInfoData));
+    2121                 :            :     /* Check the guard blocks. */
+    2122                 :            :     {
+    2123                 :          0 :         char *guards[2] = {block - MALLOC_GUARD_SIZE,
+    2124                 :          0 :                            block + block_info.data->size};
+    2125         [ #  # ]:          0 :         for (i = 0; i < ARRAY_SIZE(guards); i++) {
+    2126                 :            :             unsigned int j;
+    2127                 :          0 :             char * const guard = guards[i];
+    2128         [ #  # ]:          0 :             for (j = 0; j < MALLOC_GUARD_SIZE; j++) {
+    2129                 :          0 :                 const char diff = guard[j] - MALLOC_GUARD_PATTERN;
+    2130         [ #  # ]:          0 :                 if (diff) {
+    2131                 :          0 :                     cm_print_error(SOURCE_LOCATION_FORMAT
+    2132                 :            :                                    ": error: Guard block of %p size=%lu is corrupt\n"
+    2133                 :            :                                    SOURCE_LOCATION_FORMAT ": note: allocated here at %p\n",
+    2134                 :            :                                    file,
+    2135                 :            :                                    line,
+    2136                 :            :                                    ptr,
+    2137                 :          0 :                                    (unsigned long)block_info.data->size,
+    2138                 :          0 :                                    block_info.data->location.file,
+    2139                 :          0 :                                    block_info.data->location.line,
+    2140                 :          0 :                                    (void *)&guard[j]);
+    2141                 :          0 :                     _fail(file, line);
+    2142                 :            :                 }
+    2143                 :            :             }
+    2144                 :            :         }
+    2145                 :            :     }
+    2146                 :          0 :     list_remove(&block_info.data->node, NULL, NULL);
+    2147                 :            : 
+    2148                 :          0 :     block = discard_const_p(char, block_info.data->block);
+    2149                 :          0 :     memset(block, MALLOC_FREE_PATTERN, block_info.data->allocated_size);
+    2150                 :          0 :     free(block);
+    2151                 :            : }
+    2152                 :            : #define free test_free
+    2153                 :            : 
+    2154                 :            : #undef realloc
+    2155                 :          0 : void *_test_realloc(void *ptr,
+    2156                 :            :                    const size_t size,
+    2157                 :            :                    const char *file,
+    2158                 :            :                    const int line)
+    2159                 :            : {
+    2160                 :            :     MallocBlockInfo block_info;
+    2161                 :          0 :     char *block = ptr;
+    2162                 :          0 :     size_t block_size = size;
+    2163                 :            :     void *new_block;
+    2164                 :            : 
+    2165         [ #  # ]:          0 :     if (ptr == NULL) {
+    2166                 :          0 :         return _test_malloc(size, file, line);
+    2167                 :            :     }
+    2168                 :            : 
+    2169         [ #  # ]:          0 :     if (size == 0) {
+    2170                 :          0 :         _test_free(ptr, file, line);
+    2171                 :          0 :         return NULL;
+    2172                 :            :     }
+    2173                 :            : 
+    2174                 :          0 :     block_info.ptr = block - (MALLOC_GUARD_SIZE +
+    2175                 :            :                               sizeof(struct MallocBlockInfoData));
+    2176                 :            : 
+    2177                 :          0 :     new_block = _test_malloc(size, file, line);
+    2178         [ #  # ]:          0 :     if (new_block == NULL) {
+    2179                 :          0 :         return NULL;
+    2180                 :            :     }
+    2181                 :            : 
+    2182         [ #  # ]:          0 :     if (block_info.data->size < size) {
+    2183                 :          0 :         block_size = block_info.data->size;
+    2184                 :            :     }
+    2185                 :            : 
+    2186                 :          0 :     memcpy(new_block, ptr, block_size);
+    2187                 :            : 
+    2188                 :            :     /* Free previous memory */
+    2189                 :          0 :     _test_free(ptr, file, line);
+    2190                 :            : 
+    2191                 :          0 :     return new_block;
+    2192                 :            : }
+    2193                 :            : #define realloc test_realloc
+    2194                 :            : 
+    2195                 :            : /* Crudely checkpoint the current heap state. */
+    2196                 :       1161 : static const ListNode* check_point_allocated_blocks(void) {
+    2197                 :       1161 :     return get_allocated_blocks_list()->prev;
+    2198                 :            : }
+    2199                 :            : 
+    2200                 :            : 
+    2201                 :            : /* Display the blocks allocated after the specified check point.  This
+    2202                 :            :  * function returns the number of blocks displayed. */
+    2203                 :       1226 : static size_t display_allocated_blocks(const ListNode * const check_point) {
+    2204                 :       1226 :     const ListNode * const head = get_allocated_blocks_list();
+    2205                 :            :     const ListNode *node;
+    2206                 :       1226 :     size_t allocated_blocks = 0;
+    2207                 :       1226 :     assert_non_null(check_point);
+    2208                 :       1226 :     assert_non_null(check_point->next);
+    2209                 :            : 
+    2210         [ -  + ]:       1226 :     for (node = check_point->next; node != head; node = node->next) {
+    2211                 :          0 :         const MallocBlockInfo block_info = {
+    2212                 :          0 :             .ptr = discard_const(node->value),
+    2213                 :            :         };
+    2214                 :          0 :         assert_non_null(block_info.ptr);
+    2215                 :            : 
+    2216         [ #  # ]:          0 :         if (allocated_blocks == 0) {
+    2217                 :          0 :             cm_print_error("Blocks allocated...\n");
+    2218                 :            :         }
+    2219                 :          0 :         cm_print_error(SOURCE_LOCATION_FORMAT ": note: block %p allocated here\n",
+    2220                 :          0 :                        block_info.data->location.file,
+    2221                 :          0 :                        block_info.data->location.line,
+    2222                 :          0 :                        block_info.data->block);
+    2223                 :          0 :         allocated_blocks++;
+    2224                 :            :     }
+    2225                 :       1226 :     return allocated_blocks;
+    2226                 :            : }
+    2227                 :            : 
+    2228                 :            : 
+    2229                 :            : /* Free all blocks allocated after the specified check point. */
+    2230                 :          0 : static void free_allocated_blocks(const ListNode * const check_point) {
+    2231                 :          0 :     const ListNode * const head = get_allocated_blocks_list();
+    2232                 :            :     const ListNode *node;
+    2233                 :          0 :     assert_non_null(check_point);
+    2234                 :            : 
+    2235                 :          0 :     node = check_point->next;
+    2236                 :          0 :     assert_non_null(node);
+    2237                 :            : 
+    2238         [ #  # ]:          0 :     while (node != head) {
+    2239                 :          0 :         const MallocBlockInfo block_info = {
+    2240                 :          0 :             .ptr = discard_const(node->value),
+    2241                 :            :         };
+    2242                 :          0 :         node = node->next;
+    2243                 :          0 :         free(discard_const_p(char, block_info.data) +
+    2244                 :            :              sizeof(struct MallocBlockInfoData) +
+    2245                 :            :              MALLOC_GUARD_SIZE);
+    2246                 :            :     }
+    2247                 :          0 : }
+    2248                 :            : 
+    2249                 :            : 
+    2250                 :            : /* Fail if any any blocks are allocated after the specified check point. */
+    2251                 :       1226 : static void fail_if_blocks_allocated(const ListNode * const check_point,
+    2252                 :            :                                      const char * const test_name) {
+    2253                 :       1226 :     const size_t allocated_blocks = display_allocated_blocks(check_point);
+    2254         [ -  + ]:       1226 :     if (allocated_blocks > 0) {
+    2255                 :          0 :         free_allocated_blocks(check_point);
+    2256                 :          0 :         cm_print_error("ERROR: %s leaked %zu block(s)\n", test_name,
+    2257                 :            :                        allocated_blocks);
+    2258                 :          0 :         exit_test(1);
+    2259                 :            :     }
+    2260                 :       1226 : }
+    2261                 :            : 
+    2262                 :            : 
+    2263                 :          0 : void _fail(const char * const file, const int line) {
+    2264                 :          0 :     enum cm_message_output output = cm_get_output();
+    2265                 :            : 
+    2266         [ #  # ]:          0 :     switch(output) {
+    2267                 :          0 :         case CM_OUTPUT_STDOUT:
+    2268                 :          0 :             cm_print_error("[   LINE   ] --- " SOURCE_LOCATION_FORMAT ": error: Failure!", file, line);
+    2269                 :          0 :             break;
+    2270                 :          0 :         default:
+    2271                 :          0 :             cm_print_error(SOURCE_LOCATION_FORMAT ": error: Failure!", file, line);
+    2272                 :          0 :             break;
+    2273                 :            :     }
+    2274                 :          0 :     exit_test(1);
+    2275                 :            : 
+    2276                 :            :     /* Unreachable */
+    2277                 :          0 :     exit(-1);
+    2278                 :            : }
+    2279                 :            : 
+    2280                 :            : 
+    2281                 :            : #ifndef _WIN32
+    2282                 :          0 : CMOCKA_NORETURN static void exception_handler(int sig) {
+    2283                 :          0 :     const char *sig_strerror = "";
+    2284                 :            : 
+    2285                 :            : #ifdef HAVE_STRSIGNAL
+    2286                 :            :     sig_strerror = strsignal(sig);
+    2287                 :            : #endif
+    2288                 :            : 
+    2289                 :          0 :     cm_print_error("Test failed with exception: %s(%d)",
+    2290                 :            :                    sig_strerror, sig);
+    2291                 :          0 :     exit_test(1);
+    2292                 :            : 
+    2293                 :            :     /* Unreachable */
+    2294                 :          0 :     exit(-1);
+    2295                 :            : }
+    2296                 :            : 
+    2297                 :            : #else /* _WIN32 */
+    2298                 :            : 
+    2299                 :            : static LONG WINAPI exception_filter(EXCEPTION_POINTERS *exception_pointers) {
+    2300                 :            :     EXCEPTION_RECORD * const exception_record =
+    2301                 :            :         exception_pointers->ExceptionRecord;
+    2302                 :            :     const DWORD code = exception_record->ExceptionCode;
+    2303                 :            :     unsigned int i;
+    2304                 :            :     for (i = 0; i < ARRAY_SIZE(exception_codes); i++) {
+    2305                 :            :         const ExceptionCodeInfo * const code_info = &exception_codes[i];
+    2306                 :            :         if (code == code_info->code) {
+    2307                 :            :             static int shown_debug_message = 0;
+    2308                 :            :             fflush(stdout);
+    2309                 :            :             cm_print_error("%s occurred at %p.\n", code_info->description,
+    2310                 :            :                         exception_record->ExceptionAddress);
+    2311                 :            :             if (!shown_debug_message) {
+    2312                 :            :                 cm_print_error(
+    2313                 :            :                     "\n"
+    2314                 :            :                     "To debug in Visual Studio...\n"
+    2315                 :            :                     "1. Select menu item File->Open Project\n"
+    2316                 :            :                     "2. Change 'Files of type' to 'Executable Files'\n"
+    2317                 :            :                     "3. Open this executable.\n"
+    2318                 :            :                     "4. Select menu item Debug->Start\n"
+    2319                 :            :                     "\n"
+    2320                 :            :                     "Alternatively, set the environment variable \n"
+    2321                 :            :                     "UNIT_TESTING_DEBUG to 1 and rebuild this executable, \n"
+    2322                 :            :                     "then click 'Debug' in the popup dialog box.\n"
+    2323                 :            :                     "\n");
+    2324                 :            :                 shown_debug_message = 1;
+    2325                 :            :             }
+    2326                 :            :             exit_test(0);
+    2327                 :            :             return EXCEPTION_EXECUTE_HANDLER;
+    2328                 :            :         }
+    2329                 :            :     }
+    2330                 :            :     return EXCEPTION_CONTINUE_SEARCH;
+    2331                 :            : }
+    2332                 :            : #endif /* !_WIN32 */
+    2333                 :            : 
+    2334                 :          0 : void cm_print_error(const char * const format, ...)
+    2335                 :            : {
+    2336                 :            :     va_list args;
+    2337                 :          0 :     va_start(args, format);
+    2338         [ #  # ]:          0 :     if (cm_error_message_enabled) {
+    2339                 :          0 :         vcm_print_error(format, args);
+    2340                 :            :     } else {
+    2341                 :          0 :         vprint_error(format, args);
+    2342                 :            :     }
+    2343                 :          0 :     va_end(args);
+    2344                 :          0 : }
+    2345                 :            : 
+    2346                 :            : /* Standard output and error print methods. */
+    2347                 :       2296 : void vprint_message(const char* const format, va_list args)
+    2348                 :            : {
+    2349                 :            :     char buffer[4096];
+    2350                 :            : 
+    2351                 :       2296 :     vsnprintf(buffer, sizeof(buffer), format, args);
+    2352                 :       2296 :     printf("%s", buffer);
+    2353                 :       2296 :     fflush(stdout);
+    2354                 :            : #ifdef _WIN32
+    2355                 :            :     OutputDebugString(buffer);
+    2356                 :            : #endif /* _WIN32 */
+    2357                 :       2296 : }
+    2358                 :            : 
+    2359                 :            : 
+    2360                 :         78 : void vprint_error(const char* const format, va_list args)
+    2361                 :            : {
+    2362                 :            :     char buffer[4096];
+    2363                 :            : 
+    2364                 :         78 :     vsnprintf(buffer, sizeof(buffer), format, args);
+    2365                 :         78 :     fprintf(stderr, "%s", buffer);
+    2366                 :         78 :     fflush(stderr);
+    2367                 :            : #ifdef _WIN32
+    2368                 :            :     OutputDebugString(buffer);
+    2369                 :            : #endif /* _WIN32 */
+    2370                 :         78 : }
+    2371                 :            : 
+    2372                 :            : 
+    2373                 :       2296 : void print_message(const char* const format, ...) {
+    2374                 :            :     va_list args;
+    2375                 :       2296 :     va_start(args, format);
+    2376                 :       2296 :     vprint_message(format, args);
+    2377                 :       2296 :     va_end(args);
+    2378                 :       2296 : }
+    2379                 :            : 
+    2380                 :            : 
+    2381                 :         78 : void print_error(const char* const format, ...) {
+    2382                 :            :     va_list args;
+    2383                 :         78 :     va_start(args, format);
+    2384                 :         78 :     vprint_error(format, args);
+    2385                 :         78 :     va_end(args);
+    2386                 :         78 : }
+    2387                 :            : 
+    2388                 :            : /* New formatter */
+    2389                 :       2296 : static enum cm_message_output cm_get_output(void)
+    2390                 :            : {
+    2391                 :       2296 :     enum cm_message_output output = global_msg_output;
+    2392                 :            :     char *env;
+    2393                 :            : 
+    2394                 :       2296 :     env = getenv("CMOCKA_MESSAGE_OUTPUT");
+    2395         [ -  + ]:       2296 :     if (env != NULL) {
+    2396         [ #  # ]:          0 :         if (strcasecmp(env, "STDOUT") == 0) {
+    2397                 :          0 :             output = CM_OUTPUT_STDOUT;
+    2398         [ #  # ]:          0 :         } else if (strcasecmp(env, "SUBUNIT") == 0) {
+    2399                 :          0 :             output = CM_OUTPUT_SUBUNIT;
+    2400         [ #  # ]:          0 :         } else if (strcasecmp(env, "TAP") == 0) {
+    2401                 :          0 :             output = CM_OUTPUT_TAP;
+    2402         [ #  # ]:          0 :         } else if (strcasecmp(env, "XML") == 0) {
+    2403                 :          0 :             output = CM_OUTPUT_XML;
+    2404                 :            :         }
+    2405                 :            :     }
+    2406                 :            : 
+    2407                 :       2296 :     return output;
+    2408                 :            : }
+    2409                 :            : 
+    2410                 :            : enum cm_printf_type {
+    2411                 :            :     PRINTF_TEST_START,
+    2412                 :            :     PRINTF_TEST_SUCCESS,
+    2413                 :            :     PRINTF_TEST_FAILURE,
+    2414                 :            :     PRINTF_TEST_ERROR,
+    2415                 :            :     PRINTF_TEST_SKIPPED,
+    2416                 :            : };
+    2417                 :            : 
+    2418                 :            : static int xml_printed;
+    2419                 :            : static int file_append;
+    2420                 :            : 
+    2421                 :          0 : static void cmprintf_group_finish_xml(const char *group_name,
+    2422                 :            :                                       size_t total_executed,
+    2423                 :            :                                       size_t total_failed,
+    2424                 :            :                                       size_t total_errors,
+    2425                 :            :                                       size_t total_skipped,
+    2426                 :            :                                       double total_runtime,
+    2427                 :            :                                       struct CMUnitTestState *cm_tests)
+    2428                 :            : {
+    2429                 :          0 :     FILE *fp = stdout;
+    2430                 :          0 :     int file_opened = 0;
+    2431                 :          0 :     int multiple_files = 0;
+    2432                 :            :     char *env;
+    2433                 :            :     size_t i;
+    2434                 :            : 
+    2435                 :          0 :     env = getenv("CMOCKA_XML_FILE");
+    2436         [ #  # ]:          0 :     if (env != NULL) {
+    2437                 :            :         char buf[1024];
+    2438                 :            :         int rc;
+    2439                 :            : 
+    2440                 :          0 :         snprintf(buf, sizeof(buf), "%s", env);
+    2441                 :            : 
+    2442                 :          0 :         rc = c_strreplace(buf, sizeof(buf), "%g", group_name, &multiple_files);
+    2443         [ #  # ]:          0 :         if (rc < 0) {
+    2444                 :          0 :             snprintf(buf, sizeof(buf), "%s", env);
+    2445                 :            :         }
+    2446                 :            : 
+    2447                 :          0 :         fp = fopen(buf, "r");
+    2448         [ #  # ]:          0 :         if (fp == NULL) {
+    2449                 :          0 :             fp = fopen(buf, "w");
+    2450         [ #  # ]:          0 :             if (fp != NULL) {
+    2451                 :          0 :                 file_append = 1;
+    2452                 :          0 :                 file_opened = 1;
+    2453                 :            :             } else {
+    2454                 :          0 :                 fp = stderr;
+    2455                 :            :             }
+    2456                 :            :         } else {
+    2457                 :          0 :             fclose(fp);
+    2458         [ #  # ]:          0 :             if (file_append) {
+    2459                 :          0 :                 fp = fopen(buf, "a");
+    2460         [ #  # ]:          0 :                 if (fp != NULL) {
+    2461                 :          0 :                     file_opened = 1;
+    2462                 :          0 :                     xml_printed = 1;
+    2463                 :            :                 } else {
+    2464                 :          0 :                     fp = stderr;
+    2465                 :            :                 }
+    2466                 :            :             } else {
+    2467                 :          0 :                 fp = stderr;
+    2468                 :            :             }
+    2469                 :            :         }
+    2470                 :            :     }
+    2471                 :            : 
+    2472   [ #  #  #  #  :          0 :     if (!xml_printed || (file_opened && !file_append)) {
+                   #  # ]
+    2473                 :          0 :         fprintf(fp, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
+    2474         [ #  # ]:          0 :         if (!file_opened) {
+    2475                 :          0 :             xml_printed = 1;
+    2476                 :            :         }
+    2477                 :            :     }
+    2478                 :            : 
+    2479                 :          0 :     fprintf(fp, "<testsuites>\n");
+    2480                 :          0 :     fprintf(fp, "  <testsuite name=\"%s\" time=\"%.3f\" "
+    2481                 :            :                 "tests=\"%u\" failures=\"%u\" errors=\"%u\" skipped=\"%u\" >\n",
+    2482                 :            :                 group_name,
+    2483                 :            :                 total_runtime, /* seconds */
+    2484                 :            :                 (unsigned)total_executed,
+    2485                 :            :                 (unsigned)total_failed,
+    2486                 :            :                 (unsigned)total_errors,
+    2487                 :            :                 (unsigned)total_skipped);
+    2488                 :            : 
+    2489         [ #  # ]:          0 :     for (i = 0; i < total_executed; i++) {
+    2490                 :          0 :         struct CMUnitTestState *cmtest = &cm_tests[i];
+    2491                 :            : 
+    2492                 :          0 :         fprintf(fp, "    <testcase name=\"%s\" time=\"%.3f\" >\n",
+    2493                 :          0 :                 cmtest->test->name, cmtest->runtime);
+    2494                 :            : 
+    2495   [ #  #  #  # ]:          0 :         switch (cmtest->status) {
+    2496                 :          0 :         case CM_TEST_ERROR:
+    2497                 :            :         case CM_TEST_FAILED:
+    2498         [ #  # ]:          0 :             if (cmtest->error_message != NULL) {
+    2499                 :          0 :                 fprintf(fp, "      <failure><![CDATA[%s]]></failure>\n",
+    2500                 :            :                         cmtest->error_message);
+    2501                 :            :             } else {
+    2502                 :          0 :                 fprintf(fp, "      <failure message=\"Unknown error\" />\n");
+    2503                 :            :             }
+    2504                 :          0 :             break;
+    2505                 :          0 :         case CM_TEST_SKIPPED:
+    2506                 :          0 :             fprintf(fp, "      <skipped/>\n");
+    2507                 :          0 :             break;
+    2508                 :            : 
+    2509                 :          0 :         case CM_TEST_PASSED:
+    2510                 :            :         case CM_TEST_NOT_STARTED:
+    2511                 :          0 :             break;
+    2512                 :            :         }
+    2513                 :            : 
+    2514                 :          0 :         fprintf(fp, "    </testcase>\n");
+    2515                 :            :     }
+    2516                 :            : 
+    2517                 :          0 :     fprintf(fp, "  </testsuite>\n");
+    2518                 :          0 :     fprintf(fp, "</testsuites>\n");
+    2519                 :            : 
+    2520         [ #  # ]:          0 :     if (file_opened) {
+    2521                 :          0 :         fclose(fp);
+    2522                 :            :     }
+    2523                 :          0 : }
+    2524                 :            : 
+    2525                 :         78 : static void cmprintf_group_start_standard(const char *group_name,
+    2526                 :            :                                           const size_t num_tests)
+    2527                 :            : {
+    2528                 :         78 :     print_message("[==========] %s: Running %zu test(s).\n",
+    2529                 :            :                   group_name,
+    2530                 :            :                   num_tests);
+    2531                 :         78 : }
+    2532                 :            : 
+    2533                 :         78 : static void cmprintf_group_finish_standard(const char *group_name,
+    2534                 :            :                                            size_t total_executed,
+    2535                 :            :                                            size_t total_passed,
+    2536                 :            :                                            size_t total_failed,
+    2537                 :            :                                            size_t total_errors,
+    2538                 :            :                                            size_t total_skipped,
+    2539                 :            :                                            struct CMUnitTestState *cm_tests)
+    2540                 :            : {
+    2541                 :            :     size_t i;
+    2542                 :            : 
+    2543                 :         78 :     print_message("[==========] %s: %zu test(s) run.\n",
+    2544                 :            :                   group_name,
+    2545                 :            :                   total_executed);
+    2546                 :         78 :     print_error("[  PASSED  ] %u test(s).\n",
+    2547                 :            :                 (unsigned)(total_passed));
+    2548                 :            : 
+    2549         [ -  + ]:         78 :     if (total_skipped) {
+    2550                 :          0 :         print_error("[  SKIPPED ] %s: %zu test(s), listed below:\n",
+    2551                 :            :                     group_name,
+    2552                 :            :                     total_skipped);
+    2553         [ #  # ]:          0 :         for (i = 0; i < total_executed; i++) {
+    2554                 :          0 :             struct CMUnitTestState *cmtest = &cm_tests[i];
+    2555                 :            : 
+    2556         [ #  # ]:          0 :             if (cmtest->status == CM_TEST_SKIPPED) {
+    2557                 :          0 :                 print_error("[  SKIPPED ] %s\n", cmtest->test->name);
+    2558                 :            :             }
+    2559                 :            :         }
+    2560                 :          0 :         print_error("\n %zu SKIPPED TEST(S)\n", total_skipped);
+    2561                 :            :     }
+    2562                 :            : 
+    2563         [ -  + ]:         78 :     if (total_failed) {
+    2564                 :          0 :         print_error("[  FAILED  ] %s: %zu test(s), listed below:\n",
+    2565                 :            :                     group_name,
+    2566                 :            :                     total_failed);
+    2567         [ #  # ]:          0 :         for (i = 0; i < total_executed; i++) {
+    2568                 :          0 :             struct CMUnitTestState *cmtest = &cm_tests[i];
+    2569                 :            : 
+    2570         [ #  # ]:          0 :             if (cmtest->status == CM_TEST_FAILED) {
+    2571                 :          0 :                 print_error("[  FAILED  ] %s\n", cmtest->test->name);
+    2572                 :            :             }
+    2573                 :            :         }
+    2574                 :          0 :         print_error("\n %zu FAILED TEST(S)\n",
+    2575                 :            :                     (total_failed + total_errors));
+    2576                 :            :     }
+    2577                 :         78 : }
+    2578                 :            : 
+    2579                 :       2140 : static void cmprintf_standard(enum cm_printf_type type,
+    2580                 :            :                               const char *test_name,
+    2581                 :            :                               const char *error_message)
+    2582                 :            : {
+    2583   [ +  +  -  -  :       2140 :     switch (type) {
+                   -  - ]
+    2584                 :       1070 :     case PRINTF_TEST_START:
+    2585                 :       1070 :         print_message("[ RUN      ] %s\n", test_name);
+    2586                 :       1070 :         break;
+    2587                 :       1070 :     case PRINTF_TEST_SUCCESS:
+    2588                 :       1070 :         print_message("[       OK ] %s\n", test_name);
+    2589                 :       1070 :         break;
+    2590                 :          0 :     case PRINTF_TEST_FAILURE:
+    2591         [ #  # ]:          0 :         if (error_message != NULL) {
+    2592                 :          0 :             print_error("[  ERROR   ] --- %s\n", error_message);
+    2593                 :            :         }
+    2594                 :          0 :         print_message("[  FAILED  ] %s\n", test_name);
+    2595                 :          0 :         break;
+    2596                 :          0 :     case PRINTF_TEST_SKIPPED:
+    2597                 :          0 :         print_message("[  SKIPPED ] %s\n", test_name);
+    2598                 :          0 :         break;
+    2599                 :          0 :     case PRINTF_TEST_ERROR:
+    2600         [ #  # ]:          0 :         if (error_message != NULL) {
+    2601                 :          0 :             print_error("%s\n", error_message);
+    2602                 :            :         }
+    2603                 :          0 :         print_error("[  ERROR   ] %s\n", test_name);
+    2604                 :          0 :         break;
+    2605                 :            :     }
+    2606                 :       2140 : }
+    2607                 :            : 
+    2608                 :          0 : static void cmprintf_group_start_tap(const size_t num_tests)
+    2609                 :            : {
+    2610                 :            :     static bool version_printed = false;
+    2611         [ #  # ]:          0 :     if (!version_printed) {
+    2612                 :          0 :         print_message("TAP version 13\n");
+    2613                 :          0 :         version_printed = true;
+    2614                 :            :     }
+    2615                 :            : 
+    2616                 :          0 :     print_message("1..%u\n", (unsigned)num_tests);
+    2617                 :          0 : }
+    2618                 :            : 
+    2619                 :          0 : static void cmprintf_group_finish_tap(const char *group_name,
+    2620                 :            :                                       size_t total_executed,
+    2621                 :            :                                       size_t total_passed,
+    2622                 :            :                                       size_t total_skipped)
+    2623                 :            : {
+    2624                 :          0 :     const char *status = "not ok";
+    2625         [ #  # ]:          0 :     if (total_passed + total_skipped == total_executed) {
+    2626                 :          0 :         status = "ok";
+    2627                 :            :     }
+    2628                 :          0 :     print_message("# %s - %s\n", status, group_name);
+    2629                 :          0 : }
+    2630                 :            : 
+    2631                 :          0 : static void cmprintf_tap(enum cm_printf_type type,
+    2632                 :            :                          size_t test_number,
+    2633                 :            :                          const char *test_name,
+    2634                 :            :                          const char *error_message)
+    2635                 :            : {
+    2636   [ #  #  #  #  :          0 :     switch (type) {
+                   #  # ]
+    2637                 :          0 :     case PRINTF_TEST_START:
+    2638                 :          0 :         break;
+    2639                 :          0 :     case PRINTF_TEST_SUCCESS:
+    2640                 :          0 :         print_message("ok %u - %s\n", (unsigned)test_number, test_name);
+    2641                 :          0 :         break;
+    2642                 :          0 :     case PRINTF_TEST_FAILURE:
+    2643                 :          0 :         print_message("not ok %u - %s\n", (unsigned)test_number, test_name);
+    2644         [ #  # ]:          0 :         if (error_message != NULL) {
+    2645                 :            :             char *msg;
+    2646                 :            :             char *p;
+    2647                 :            : 
+    2648                 :          0 :             msg = strdup(error_message);
+    2649         [ #  # ]:          0 :             if (msg == NULL) {
+    2650                 :          0 :                 return;
+    2651                 :            :             }
+    2652                 :          0 :             p = msg;
+    2653                 :            : 
+    2654         [ #  # ]:          0 :             while (p[0] != '\0') {
+    2655                 :          0 :                 char *q = p;
+    2656                 :            : 
+    2657                 :          0 :                 p = strchr(q, '\n');
+    2658         [ #  # ]:          0 :                 if (p != NULL) {
+    2659                 :          0 :                     p[0] = '\0';
+    2660                 :            :                 }
+    2661                 :            : 
+    2662                 :          0 :                 print_message("# %s\n", q);
+    2663                 :            : 
+    2664         [ #  # ]:          0 :                 if (p == NULL) {
+    2665                 :          0 :                     break;
+    2666                 :            :                 }
+    2667                 :          0 :                 p++;
+    2668                 :            :             }
+    2669                 :          0 :             libc_free(msg);
+    2670                 :            :         }
+    2671                 :          0 :         break;
+    2672                 :          0 :     case PRINTF_TEST_SKIPPED:
+    2673                 :          0 :         print_message("ok %u # SKIP %s\n", (unsigned)test_number, test_name);
+    2674                 :          0 :         break;
+    2675                 :          0 :     case PRINTF_TEST_ERROR:
+    2676                 :          0 :         print_message("not ok %u - %s %s\n",
+    2677                 :            :                       (unsigned)test_number, test_name, error_message);
+    2678                 :          0 :         break;
+    2679                 :            :     }
+    2680                 :            : }
+    2681                 :            : 
+    2682                 :          0 : static void cmprintf_subunit(enum cm_printf_type type,
+    2683                 :            :                              const char *test_name,
+    2684                 :            :                              const char *error_message)
+    2685                 :            : {
+    2686   [ #  #  #  #  :          0 :     switch (type) {
+                   #  # ]
+    2687                 :          0 :     case PRINTF_TEST_START:
+    2688                 :          0 :         print_message("test: %s\n", test_name);
+    2689                 :          0 :         break;
+    2690                 :          0 :     case PRINTF_TEST_SUCCESS:
+    2691                 :          0 :         print_message("success: %s\n", test_name);
+    2692                 :          0 :         break;
+    2693                 :          0 :     case PRINTF_TEST_FAILURE:
+    2694                 :          0 :         print_message("failure: %s", test_name);
+    2695         [ #  # ]:          0 :         if (error_message != NULL) {
+    2696                 :          0 :             print_message(" [\n%s\n]\n", error_message);
+    2697                 :            :         }
+    2698                 :          0 :         break;
+    2699                 :          0 :     case PRINTF_TEST_SKIPPED:
+    2700                 :          0 :         print_message("skip: %s\n", test_name);
+    2701                 :          0 :         break;
+    2702                 :          0 :     case PRINTF_TEST_ERROR:
+    2703                 :          0 :         print_message("error: %s [ %s ]\n", test_name, error_message);
+    2704                 :          0 :         break;
+    2705                 :            :     }
+    2706                 :          0 : }
+    2707                 :            : 
+    2708                 :         78 : static void cmprintf_group_start(const char *group_name,
+    2709                 :            :                                  const size_t num_tests)
+    2710                 :            : {
+    2711                 :            :     enum cm_message_output output;
+    2712                 :            : 
+    2713                 :         78 :     output = cm_get_output();
+    2714                 :            : 
+    2715   [ +  -  -  -  :         78 :     switch (output) {
+                      - ]
+    2716                 :         78 :     case CM_OUTPUT_STDOUT:
+    2717                 :         78 :         cmprintf_group_start_standard(group_name, num_tests);
+    2718                 :         78 :         break;
+    2719                 :          0 :     case CM_OUTPUT_SUBUNIT:
+    2720                 :          0 :         break;
+    2721                 :          0 :     case CM_OUTPUT_TAP:
+    2722                 :          0 :         cmprintf_group_start_tap(num_tests);
+    2723                 :          0 :         break;
+    2724                 :          0 :     case CM_OUTPUT_XML:
+    2725                 :          0 :         break;
+    2726                 :            :     }
+    2727                 :         78 : }
+    2728                 :            : 
+    2729                 :         78 : static void cmprintf_group_finish(const char *group_name,
+    2730                 :            :                                   size_t total_executed,
+    2731                 :            :                                   size_t total_passed,
+    2732                 :            :                                   size_t total_failed,
+    2733                 :            :                                   size_t total_errors,
+    2734                 :            :                                   size_t total_skipped,
+    2735                 :            :                                   double total_runtime,
+    2736                 :            :                                   struct CMUnitTestState *cm_tests)
+    2737                 :            : {
+    2738                 :            :     enum cm_message_output output;
+    2739                 :            : 
+    2740                 :         78 :     output = cm_get_output();
+    2741                 :            : 
+    2742   [ +  -  -  -  :         78 :     switch (output) {
+                      - ]
+    2743                 :         78 :     case CM_OUTPUT_STDOUT:
+    2744                 :         78 :         cmprintf_group_finish_standard(group_name,
+    2745                 :            :                                        total_executed,
+    2746                 :            :                                        total_passed,
+    2747                 :            :                                        total_failed,
+    2748                 :            :                                        total_errors,
+    2749                 :            :                                        total_skipped,
+    2750                 :            :                                        cm_tests);
+    2751                 :         78 :         break;
+    2752                 :          0 :     case CM_OUTPUT_SUBUNIT:
+    2753                 :          0 :         break;
+    2754                 :          0 :     case CM_OUTPUT_TAP:
+    2755                 :          0 :         cmprintf_group_finish_tap(group_name,
+    2756                 :            :                                   total_executed,
+    2757                 :            :                                   total_passed,
+    2758                 :            :                                   total_skipped);
+    2759                 :          0 :         break;
+    2760                 :          0 :     case CM_OUTPUT_XML:
+    2761                 :          0 :         cmprintf_group_finish_xml(group_name,
+    2762                 :            :                                   total_executed,
+    2763                 :            :                                   total_failed,
+    2764                 :            :                                   total_errors,
+    2765                 :            :                                   total_skipped,
+    2766                 :            :                                   total_runtime,
+    2767                 :            :                                   cm_tests);
+    2768                 :          0 :         break;
+    2769                 :            :     }
+    2770                 :         78 : }
+    2771                 :            : 
+    2772                 :       2140 : static void cmprintf(enum cm_printf_type type,
+    2773                 :            :                      size_t test_number,
+    2774                 :            :                      const char *test_name,
+    2775                 :            :                      const char *error_message)
+    2776                 :            : {
+    2777                 :            :     enum cm_message_output output;
+    2778                 :            : 
+    2779                 :       2140 :     output = cm_get_output();
+    2780                 :            : 
+    2781   [ +  -  -  -  :       2140 :     switch (output) {
+                      - ]
+    2782                 :       2140 :     case CM_OUTPUT_STDOUT:
+    2783                 :       2140 :         cmprintf_standard(type, test_name, error_message);
+    2784                 :       2140 :         break;
+    2785                 :          0 :     case CM_OUTPUT_SUBUNIT:
+    2786                 :          0 :         cmprintf_subunit(type, test_name, error_message);
+    2787                 :          0 :         break;
+    2788                 :          0 :     case CM_OUTPUT_TAP:
+    2789                 :          0 :         cmprintf_tap(type, test_number, test_name, error_message);
+    2790                 :          0 :         break;
+    2791                 :          0 :     case CM_OUTPUT_XML:
+    2792                 :          0 :         break;
+    2793                 :            :     }
+    2794                 :       2140 : }
+    2795                 :            : 
+    2796                 :          0 : void cmocka_set_message_output(enum cm_message_output output)
+    2797                 :            : {
+    2798                 :          0 :     global_msg_output = output;
+    2799                 :          0 : }
+    2800                 :            : 
+    2801                 :          0 : void cmocka_set_test_filter(const char *pattern)
+    2802                 :            : {
+    2803                 :          0 :     global_test_filter_pattern = pattern;
+    2804                 :          0 : }
+    2805                 :            : 
+    2806                 :          0 : void cmocka_set_skip_filter(const char *pattern)
+    2807                 :            : {
+    2808                 :          0 :     global_skip_filter_pattern = pattern;
+    2809                 :          0 : }
+    2810                 :            : 
+    2811                 :            : /****************************************************************************
+    2812                 :            :  * TIME CALCULATIONS
+    2813                 :            :  ****************************************************************************/
+    2814                 :            : 
+    2815                 :            : #ifdef HAVE_STRUCT_TIMESPEC
+    2816                 :            : static struct timespec cm_tspecdiff(struct timespec time1,
+    2817                 :            :                                     struct timespec time0)
+    2818                 :            : {
+    2819                 :            :     struct timespec ret;
+    2820                 :            :     int xsec = 0;
+    2821                 :            :     int sign = 1;
+    2822                 :            : 
+    2823                 :            :     if (time0.tv_nsec > time1.tv_nsec) {
+    2824                 :            :         xsec = (int) ((time0.tv_nsec - time1.tv_nsec) / (1E9 + 1));
+    2825                 :            :         time0.tv_nsec -= (long int) (1E9 * xsec);
+    2826                 :            :         time0.tv_sec += xsec;
+    2827                 :            :     }
+    2828                 :            : 
+    2829                 :            :     if ((time1.tv_nsec - time0.tv_nsec) > 1E9) {
+    2830                 :            :         xsec = (int) ((time1.tv_nsec - time0.tv_nsec) / 1E9);
+    2831                 :            :         time0.tv_nsec += (long int) (1E9 * xsec);
+    2832                 :            :         time0.tv_sec -= xsec;
+    2833                 :            :     }
+    2834                 :            : 
+    2835                 :            :     ret.tv_sec = time1.tv_sec - time0.tv_sec;
+    2836                 :            :     ret.tv_nsec = time1.tv_nsec - time0.tv_nsec;
+    2837                 :            : 
+    2838                 :            :     if (time1.tv_sec < time0.tv_sec) {
+    2839                 :            :         sign = -1;
+    2840                 :            :     }
+    2841                 :            : 
+    2842                 :            :     ret.tv_sec = ret.tv_sec * sign;
+    2843                 :            : 
+    2844                 :            :     return ret;
+    2845                 :            : }
+    2846                 :            : 
+    2847                 :            : static double cm_secdiff(struct timespec clock1, struct timespec clock0)
+    2848                 :            : {
+    2849                 :            :     double ret;
+    2850                 :            :     struct timespec diff;
+    2851                 :            : 
+    2852                 :            :     diff = cm_tspecdiff(clock1, clock0);
+    2853                 :            : 
+    2854                 :            :     ret = (double) diff.tv_sec;
+    2855                 :            :     ret += (double) diff.tv_nsec / (double) 1E9;
+    2856                 :            : 
+    2857                 :            :     return ret;
+    2858                 :            : }
+    2859                 :            : #endif /* HAVE_STRUCT_TIMESPEC */
+    2860                 :            : 
+    2861                 :            : /****************************************************************************
+    2862                 :            :  * CMOCKA TEST RUNNER
+    2863                 :            :  ****************************************************************************/
+    2864                 :       1239 : static int cmocka_run_one_test_or_fixture(const char *function_name,
+    2865                 :            :                                           CMUnitTestFunction test_func,
+    2866                 :            :                                           CMFixtureFunction setup_func,
+    2867                 :            :                                           CMFixtureFunction teardown_func,
+    2868                 :            :                                           void ** const volatile state,
+    2869                 :            :                                           const void *const heap_check_point)
+    2870                 :            : {
+    2871         [ +  + ]:       1239 :     const ListNode * const volatile check_point = (const ListNode*)
+    2872                 :            :         (heap_check_point != NULL ?
+    2873                 :       1070 :          heap_check_point : check_point_allocated_blocks());
+    2874                 :       1239 :     int handle_exceptions = 1;
+    2875                 :       1239 :     void *current_state = NULL;
+    2876                 :       1239 :     int rc = 0;
+    2877                 :            : 
+    2878                 :            :     /* FIXME check only one test or fixture is set */
+    2879                 :            : 
+    2880                 :            :     /* Detect if we should handle exceptions */
+    2881                 :            : #ifdef _WIN32
+    2882                 :            :     handle_exceptions = !IsDebuggerPresent();
+    2883                 :            : #endif /* _WIN32 */
+    2884                 :            : #ifdef UNIT_TESTING_DEBUG
+    2885                 :            :     handle_exceptions = 0;
+    2886                 :            : #endif /* UNIT_TESTING_DEBUG */
+    2887                 :            : 
+    2888                 :            : 
+    2889         [ +  - ]:       1239 :     if (handle_exceptions) {
+    2890                 :            : #ifndef _WIN32
+    2891                 :            :         unsigned int i;
+    2892         [ +  + ]:       7434 :         for (i = 0; i < ARRAY_SIZE(exception_signals); i++) {
+    2893                 :       6195 :             default_signal_functions[i] = signal(
+    2894                 :       6195 :                     exception_signals[i], exception_handler);
+    2895                 :            :         }
+    2896                 :            : #else /* _WIN32 */
+    2897                 :            :         previous_exception_filter = SetUnhandledExceptionFilter(
+    2898                 :            :                 exception_filter);
+    2899                 :            : #endif /* !_WIN32 */
+    2900                 :            :     }
+    2901                 :            : 
+    2902                 :            :     /* Init the test structure */
+    2903                 :       1239 :     initialize_testing(function_name);
+    2904                 :            : 
+    2905                 :       1239 :     global_running_test = 1;
+    2906                 :            : 
+    2907         [ +  - ]:       1239 :     if (cm_setjmp(global_run_test_env) == 0) {
+    2908         [ +  + ]:       1239 :         if (test_func != NULL) {
+    2909         [ -  + ]:       1070 :             test_func(state != NULL ? state : &current_state);
+    2910                 :            : 
+    2911                 :       1070 :             fail_if_blocks_allocated(check_point, function_name);
+    2912                 :       1070 :             rc = 0;
+    2913         [ +  + ]:        169 :         } else if (setup_func != NULL) {
+    2914         [ -  + ]:         91 :             rc = setup_func(state != NULL ? state : &current_state);
+    2915                 :            : 
+    2916                 :            :             /*
+    2917                 :            :              * For setup we can ignore any allocated blocks. We just need to
+    2918                 :            :              * ensure they're deallocated on tear down.
+    2919                 :            :              */
+    2920         [ +  - ]:         78 :         } else if (teardown_func != NULL) {
+    2921         [ -  + ]:         78 :             rc = teardown_func(state != NULL ? state : &current_state);
+    2922                 :            : 
+    2923                 :         78 :             fail_if_blocks_allocated(check_point, function_name);
+    2924                 :            :         } else {
+    2925                 :            :             /* ERROR */
+    2926                 :            :         }
+    2927                 :       1239 :         fail_if_leftover_values(function_name);
+    2928                 :       1239 :         global_running_test = 0;
+    2929                 :            :     } else {
+    2930                 :            :         /* TEST FAILED */
+    2931                 :          0 :         global_running_test = 0;
+    2932                 :          0 :         rc = -1;
+    2933                 :            :     }
+    2934                 :       1239 :     teardown_testing(function_name);
+    2935                 :            : 
+    2936         [ +  - ]:       1239 :     if (handle_exceptions) {
+    2937                 :            : #ifndef _WIN32
+    2938                 :            :         unsigned int i;
+    2939         [ +  + ]:       7434 :         for (i = 0; i < ARRAY_SIZE(exception_signals); i++) {
+    2940                 :       6195 :             signal(exception_signals[i], default_signal_functions[i]);
+    2941                 :            :         }
+    2942                 :            : #else /* _WIN32 */
+    2943                 :            :         if (previous_exception_filter) {
+    2944                 :            :             SetUnhandledExceptionFilter(previous_exception_filter);
+    2945                 :            :             previous_exception_filter = NULL;
+    2946                 :            :         }
+    2947                 :            : #endif /* !_WIN32 */
+    2948                 :            :     }
+    2949                 :            : 
+    2950                 :       1239 :     return rc;
+    2951                 :            : }
+    2952                 :            : 
+    2953                 :        156 : static int cmocka_run_group_fixture(const char *function_name,
+    2954                 :            :                                     CMFixtureFunction setup_func,
+    2955                 :            :                                     CMFixtureFunction teardown_func,
+    2956                 :            :                                     void **state,
+    2957                 :            :                                     const void *const heap_check_point)
+    2958                 :            : {
+    2959                 :            :     int rc;
+    2960                 :            : 
+    2961         [ +  + ]:        156 :     if (setup_func != NULL) {
+    2962                 :         78 :         rc = cmocka_run_one_test_or_fixture(function_name,
+    2963                 :            :                                         NULL,
+    2964                 :            :                                         setup_func,
+    2965                 :            :                                         NULL,
+    2966                 :            :                                         state,
+    2967                 :            :                                         heap_check_point);
+    2968                 :            :     } else {
+    2969                 :         78 :         rc = cmocka_run_one_test_or_fixture(function_name,
+    2970                 :            :                                         NULL,
+    2971                 :            :                                         NULL,
+    2972                 :            :                                         teardown_func,
+    2973                 :            :                                         state,
+    2974                 :            :                                         heap_check_point);
+    2975                 :            :     }
+    2976                 :            : 
+    2977                 :        156 :     return rc;
+    2978                 :            : }
+    2979                 :            : 
+    2980                 :       1070 : static int cmocka_run_one_tests(struct CMUnitTestState *test_state)
+    2981                 :            : {
+    2982                 :            : #ifdef HAVE_STRUCT_TIMESPEC
+    2983                 :            :     struct timespec start = {
+    2984                 :            :         .tv_sec = 0,
+    2985                 :            :         .tv_nsec = 0,
+    2986                 :            :     };
+    2987                 :            :     struct timespec finish = {
+    2988                 :            :         .tv_sec = 0,
+    2989                 :            :         .tv_nsec = 0,
+    2990                 :            :     };
+    2991                 :            : #endif
+    2992                 :       1070 :     int rc = 0;
+    2993                 :            : 
+    2994                 :            :     /* Run setup */
+    2995         [ +  + ]:       1070 :     if (test_state->test->setup_func != NULL) {
+    2996                 :            :         /* Setup the memory check point, it will be evaluated on teardown */
+    2997                 :         13 :         test_state->check_point = check_point_allocated_blocks();
+    2998                 :            : 
+    2999                 :         13 :         rc = cmocka_run_one_test_or_fixture(test_state->test->name,
+    3000                 :            :                                             NULL,
+    3001                 :         13 :                                             test_state->test->setup_func,
+    3002                 :            :                                             NULL,
+    3003                 :            :                                             &test_state->state,
+    3004                 :         13 :                                             test_state->check_point);
+    3005         [ -  + ]:         13 :         if (rc != 0) {
+    3006                 :          0 :             test_state->status = CM_TEST_ERROR;
+    3007                 :          0 :             cm_print_error("Test setup failed");
+    3008                 :            :         }
+    3009                 :            :     }
+    3010                 :            : 
+    3011                 :            :     /* Run test */
+    3012                 :            : #ifdef HAVE_STRUCT_TIMESPEC
+    3013                 :            :     CMOCKA_CLOCK_GETTIME(CLOCK_REALTIME, &start);
+    3014                 :            : #endif
+    3015                 :            : 
+    3016         [ +  - ]:       1070 :     if (rc == 0) {
+    3017                 :       1070 :         rc = cmocka_run_one_test_or_fixture(test_state->test->name,
+    3018                 :       1070 :                                             test_state->test->test_func,
+    3019                 :            :                                             NULL,
+    3020                 :            :                                             NULL,
+    3021                 :            :                                             &test_state->state,
+    3022                 :            :                                             NULL);
+    3023         [ +  - ]:       1070 :         if (rc == 0) {
+    3024                 :       1070 :             test_state->status = CM_TEST_PASSED;
+    3025                 :            :         } else {
+    3026         [ #  # ]:          0 :             if (global_skip_test) {
+    3027                 :          0 :                 test_state->status = CM_TEST_SKIPPED;
+    3028                 :          0 :                 global_skip_test = 0; /* Do not skip the next test */
+    3029                 :            :             } else {
+    3030                 :          0 :                 test_state->status = CM_TEST_FAILED;
+    3031                 :            :             }
+    3032                 :            :         }
+    3033                 :       1070 :         rc = 0;
+    3034                 :            :     }
+    3035                 :            : 
+    3036                 :       1070 :     test_state->runtime = 0.0;
+    3037                 :            : 
+    3038                 :            : #ifdef HAVE_STRUCT_TIMESPEC
+    3039                 :            :     CMOCKA_CLOCK_GETTIME(CLOCK_REALTIME, &finish);
+    3040                 :            :     test_state->runtime = cm_secdiff(finish, start);
+    3041                 :            : #endif
+    3042                 :            : 
+    3043                 :            :     /* Run teardown */
+    3044   [ +  -  -  + ]:       1070 :     if (rc == 0 && test_state->test->teardown_func != NULL) {
+    3045                 :          0 :         rc = cmocka_run_one_test_or_fixture(test_state->test->name,
+    3046                 :            :                                             NULL,
+    3047                 :            :                                             NULL,
+    3048                 :          0 :                                             test_state->test->teardown_func,
+    3049                 :            :                                             &test_state->state,
+    3050                 :          0 :                                             test_state->check_point);
+    3051         [ #  # ]:          0 :         if (rc != 0) {
+    3052                 :          0 :             test_state->status = CM_TEST_ERROR;
+    3053                 :          0 :             cm_print_error("Test teardown failed");
+    3054                 :            :         }
+    3055                 :            :     }
+    3056                 :            : 
+    3057                 :       1070 :     test_state->error_message = cm_error_message;
+    3058                 :       1070 :     cm_error_message = NULL;
+    3059                 :            : 
+    3060                 :       1070 :     return rc;
+    3061                 :            : }
+    3062                 :            : 
+    3063                 :         78 : int _cmocka_run_group_tests(const char *group_name,
+    3064                 :            :                             const struct CMUnitTest * const tests,
+    3065                 :            :                             const size_t num_tests,
+    3066                 :            :                             CMFixtureFunction group_setup,
+    3067                 :            :                             CMFixtureFunction group_teardown)
+    3068                 :            : {
+    3069                 :            :     struct CMUnitTestState *cm_tests;
+    3070                 :         78 :     const ListNode *group_check_point = check_point_allocated_blocks();
+    3071                 :         78 :     void *group_state = NULL;
+    3072                 :         78 :     size_t total_tests = 0;
+    3073                 :         78 :     size_t total_failed = 0;
+    3074                 :         78 :     size_t total_passed = 0;
+    3075                 :         78 :     size_t total_executed = 0;
+    3076                 :         78 :     size_t total_errors = 0;
+    3077                 :         78 :     size_t total_skipped = 0;
+    3078                 :         78 :     double total_runtime = 0;
+    3079                 :            :     size_t i;
+    3080                 :            :     int rc;
+    3081                 :            : 
+    3082                 :            :     /* Make sure LargestIntegralType is at least the size of a pointer. */
+    3083                 :         78 :     assert_true(sizeof(LargestIntegralType) >= sizeof(void*));
+    3084                 :            : 
+    3085                 :         78 :     cm_tests = libc_calloc(1, sizeof(struct CMUnitTestState) * num_tests);
+    3086         [ -  + ]:         78 :     if (cm_tests == NULL) {
+    3087                 :          0 :         return -1;
+    3088                 :            :     }
+    3089                 :            : 
+    3090                 :            :     /* Setup cmocka test array */
+    3091         [ +  + ]:       1148 :     for (i = 0; i < num_tests; i++) {
+    3092         [ +  - ]:       1070 :         if (tests[i].name != NULL &&
+    3093         [ -  + ]:       1070 :             (tests[i].test_func != NULL
+    3094         [ #  # ]:          0 :              || tests[i].setup_func != NULL
+    3095         [ #  # ]:          0 :              || tests[i].teardown_func != NULL)) {
+    3096         [ -  + ]:       1070 :             if (global_test_filter_pattern != NULL) {
+    3097                 :            :                 int match;
+    3098                 :            : 
+    3099                 :          0 :                 match = c_strmatch(tests[i].name, global_test_filter_pattern);
+    3100         [ #  # ]:          0 :                 if (!match) {
+    3101                 :          0 :                     continue;
+    3102                 :            :                 }
+    3103                 :            :             }
+    3104         [ -  + ]:       1070 :             if (global_skip_filter_pattern != NULL) {
+    3105                 :            :                 int match;
+    3106                 :            : 
+    3107                 :          0 :                 match = c_strmatch(tests[i].name, global_skip_filter_pattern);
+    3108         [ #  # ]:          0 :                 if (match) {
+    3109                 :          0 :                     continue;
+    3110                 :            :                 }
+    3111                 :            :             }
+    3112                 :       1070 :             cm_tests[total_tests] = (struct CMUnitTestState) {
+    3113                 :       1070 :                 .test = &tests[i],
+    3114                 :            :                 .status = CM_TEST_NOT_STARTED,
+    3115                 :            :                 .state = NULL,
+    3116                 :            :             };
+    3117                 :       1070 :             total_tests++;
+    3118                 :            :         }
+    3119                 :            :     }
+    3120                 :            : 
+    3121                 :         78 :     cmprintf_group_start(group_name, total_tests);
+    3122                 :            : 
+    3123                 :         78 :     rc = 0;
+    3124                 :            : 
+    3125                 :            :     /* Run group setup */
+    3126         [ +  - ]:         78 :     if (group_setup != NULL) {
+    3127                 :         78 :         rc = cmocka_run_group_fixture("cmocka_group_setup",
+    3128                 :            :                                       group_setup,
+    3129                 :            :                                       NULL,
+    3130                 :            :                                       &group_state,
+    3131                 :            :                                       group_check_point);
+    3132                 :            :     }
+    3133                 :            : 
+    3134         [ +  - ]:         78 :     if (rc == 0) {
+    3135                 :            :         /* Execute tests */
+    3136         [ +  + ]:       1148 :         for (i = 0; i < total_tests; i++) {
+    3137                 :       1070 :             struct CMUnitTestState *cmtest = &cm_tests[i];
+    3138                 :       1070 :             size_t test_number = i + 1;
+    3139                 :            : 
+    3140                 :       1070 :             cmprintf(PRINTF_TEST_START, test_number, cmtest->test->name, NULL);
+    3141                 :            : 
+    3142         [ +  + ]:       1070 :             if (group_state != NULL) {
+    3143                 :       1057 :                 cmtest->state = group_state;
+    3144         [ -  + ]:         13 :             } else if (cmtest->test->initial_state  != NULL) {
+    3145                 :          0 :                 cmtest->state = cmtest->test->initial_state;
+    3146                 :            :             }
+    3147                 :            : 
+    3148                 :       1070 :             rc = cmocka_run_one_tests(cmtest);
+    3149                 :       1070 :             total_executed++;
+    3150                 :       1070 :             total_runtime += cmtest->runtime;
+    3151         [ +  - ]:       1070 :             if (rc == 0) {
+    3152   [ +  -  -  - ]:       1070 :                 switch (cmtest->status) {
+    3153                 :       1070 :                     case CM_TEST_PASSED:
+    3154                 :       1070 :                         cmprintf(PRINTF_TEST_SUCCESS,
+    3155                 :            :                                  test_number,
+    3156                 :       1070 :                                  cmtest->test->name,
+    3157                 :            :                                  cmtest->error_message);
+    3158                 :       1070 :                         total_passed++;
+    3159                 :       1070 :                         break;
+    3160                 :          0 :                     case CM_TEST_SKIPPED:
+    3161                 :          0 :                         cmprintf(PRINTF_TEST_SKIPPED,
+    3162                 :            :                                  test_number,
+    3163                 :          0 :                                  cmtest->test->name,
+    3164                 :            :                                  cmtest->error_message);
+    3165                 :          0 :                         total_skipped++;
+    3166                 :          0 :                         break;
+    3167                 :          0 :                     case CM_TEST_FAILED:
+    3168                 :          0 :                         cmprintf(PRINTF_TEST_FAILURE,
+    3169                 :            :                                  test_number,
+    3170                 :          0 :                                  cmtest->test->name,
+    3171                 :            :                                  cmtest->error_message);
+    3172                 :          0 :                         total_failed++;
+    3173                 :          0 :                         break;
+    3174                 :          0 :                     default:
+    3175                 :          0 :                         cmprintf(PRINTF_TEST_ERROR,
+    3176                 :            :                                  test_number,
+    3177                 :          0 :                                  cmtest->test->name,
+    3178                 :            :                                  "Internal cmocka error");
+    3179                 :          0 :                         total_errors++;
+    3180                 :          0 :                         break;
+    3181                 :            :                 }
+    3182                 :            :             } else {
+    3183                 :          0 :                 char err_msg[2048] = {0};
+    3184                 :            : 
+    3185                 :          0 :                 snprintf(err_msg, sizeof(err_msg),
+    3186                 :            :                          "Could not run test: %s",
+    3187                 :            :                          cmtest->error_message);
+    3188                 :            : 
+    3189                 :          0 :                 cmprintf(PRINTF_TEST_ERROR,
+    3190                 :            :                          test_number,
+    3191                 :          0 :                          cmtest->test->name,
+    3192                 :            :                          err_msg);
+    3193                 :          0 :                 total_errors++;
+    3194                 :            :             }
+    3195                 :            :         }
+    3196                 :            :     } else {
+    3197         [ #  # ]:          0 :         if (cm_error_message != NULL) {
+    3198                 :          0 :             print_error("[  ERROR   ] --- %s\n", cm_error_message);
+    3199                 :          0 :             vcm_free_error(cm_error_message);
+    3200                 :          0 :             cm_error_message = NULL;
+    3201                 :            :         }
+    3202                 :          0 :         cmprintf(PRINTF_TEST_ERROR, 0,
+    3203                 :            :                  group_name, "[  FAILED  ] GROUP SETUP");
+    3204                 :          0 :         total_errors++;
+    3205                 :            :     }
+    3206                 :            : 
+    3207                 :            :     /* Run group teardown */
+    3208         [ +  - ]:         78 :     if (group_teardown != NULL) {
+    3209                 :         78 :         rc = cmocka_run_group_fixture("cmocka_group_teardown",
+    3210                 :            :                                       NULL,
+    3211                 :            :                                       group_teardown,
+    3212                 :            :                                       &group_state,
+    3213                 :            :                                       group_check_point);
+    3214         [ -  + ]:         78 :         if (rc != 0) {
+    3215         [ #  # ]:          0 :             if (cm_error_message != NULL) {
+    3216                 :          0 :                 print_error("[  ERROR   ] --- %s\n", cm_error_message);
+    3217                 :          0 :                 vcm_free_error(cm_error_message);
+    3218                 :          0 :                 cm_error_message = NULL;
+    3219                 :            :             }
+    3220                 :          0 :             cmprintf(PRINTF_TEST_ERROR, 0,
+    3221                 :            :                      group_name, "[  FAILED  ] GROUP TEARDOWN");
+    3222                 :            :         }
+    3223                 :            :     }
+    3224                 :            : 
+    3225                 :         78 :     cmprintf_group_finish(group_name,
+    3226                 :            :                           total_executed,
+    3227                 :            :                           total_passed,
+    3228                 :            :                           total_failed,
+    3229                 :            :                           total_errors,
+    3230                 :            :                           total_skipped,
+    3231                 :            :                           total_runtime,
+    3232                 :            :                           cm_tests);
+    3233                 :            : 
+    3234         [ +  + ]:       1148 :     for (i = 0; i < total_tests; i++) {
+    3235                 :       1070 :         vcm_free_error(discard_const_p(char, cm_tests[i].error_message));
+    3236                 :            :     }
+    3237                 :         78 :     libc_free(cm_tests);
+    3238                 :         78 :     fail_if_blocks_allocated(group_check_point, "cmocka_group_tests");
+    3239                 :            : 
+    3240                 :         78 :     return (int)(total_failed + total_errors);
+    3241                 :            : }
+    3242                 :            : 
+    3243                 :            : /****************************************************************************
+    3244                 :            :  * DEPRECATED TEST RUNNER
+    3245                 :            :  ****************************************************************************/
+    3246                 :            : 
+    3247                 :          0 : int _run_test(
+    3248                 :            :         const char * const function_name,  const UnitTestFunction Function,
+    3249                 :            :         void ** const volatile state, const UnitTestFunctionType function_type,
+    3250                 :            :         const void* const heap_check_point) {
+    3251         [ #  # ]:          0 :     const ListNode * const volatile check_point = (const ListNode*)
+    3252                 :            :         (heap_check_point ?
+    3253                 :          0 :          heap_check_point : check_point_allocated_blocks());
+    3254                 :          0 :     void *current_state = NULL;
+    3255                 :          0 :     volatile int rc = 1;
+    3256                 :          0 :     int handle_exceptions = 1;
+    3257                 :            : #ifdef _WIN32
+    3258                 :            :     handle_exceptions = !IsDebuggerPresent();
+    3259                 :            : #endif /* _WIN32 */
+    3260                 :            : #ifdef UNIT_TESTING_DEBUG
+    3261                 :            :     handle_exceptions = 0;
+    3262                 :            : #endif /* UNIT_TESTING_DEBUG */
+    3263                 :            : 
+    3264                 :          0 :     cm_error_message_enabled = 0;
+    3265                 :            : 
+    3266         [ #  # ]:          0 :     if (handle_exceptions) {
+    3267                 :            : #ifndef _WIN32
+    3268                 :            :         unsigned int i;
+    3269         [ #  # ]:          0 :         for (i = 0; i < ARRAY_SIZE(exception_signals); i++) {
+    3270                 :          0 :             default_signal_functions[i] = signal(
+    3271                 :          0 :                 exception_signals[i], exception_handler);
+    3272                 :            :         }
+    3273                 :            : #else /* _WIN32 */
+    3274                 :            :         previous_exception_filter = SetUnhandledExceptionFilter(
+    3275                 :            :             exception_filter);
+    3276                 :            : #endif /* !_WIN32 */
+    3277                 :            :     }
+    3278                 :            : 
+    3279         [ #  # ]:          0 :     if (function_type == UNIT_TEST_FUNCTION_TYPE_TEST) {
+    3280                 :          0 :         print_message("[ RUN      ] %s\n", function_name);
+    3281                 :            :     }
+    3282                 :          0 :     initialize_testing(function_name);
+    3283                 :          0 :     global_running_test = 1;
+    3284         [ #  # ]:          0 :     if (cm_setjmp(global_run_test_env) == 0) {
+    3285         [ #  # ]:          0 :         Function(state ? state : &current_state);
+    3286                 :          0 :         fail_if_leftover_values(function_name);
+    3287                 :            : 
+    3288                 :            :         /* If this is a setup function then ignore any allocated blocks
+    3289                 :            :          * only ensure they're deallocated on tear down. */
+    3290         [ #  # ]:          0 :         if (function_type != UNIT_TEST_FUNCTION_TYPE_SETUP) {
+    3291                 :          0 :             fail_if_blocks_allocated(check_point, function_name);
+    3292                 :            :         }
+    3293                 :            : 
+    3294                 :          0 :         global_running_test = 0;
+    3295                 :            : 
+    3296         [ #  # ]:          0 :         if (function_type == UNIT_TEST_FUNCTION_TYPE_TEST) {
+    3297                 :          0 :             print_message("[       OK ] %s\n", function_name);
+    3298                 :            :         }
+    3299                 :          0 :         rc = 0;
+    3300                 :            :     } else {
+    3301                 :          0 :         global_running_test = 0;
+    3302                 :          0 :         print_message("[  FAILED  ] %s\n", function_name);
+    3303                 :            :     }
+    3304                 :          0 :     teardown_testing(function_name);
+    3305                 :            : 
+    3306         [ #  # ]:          0 :     if (handle_exceptions) {
+    3307                 :            : #ifndef _WIN32
+    3308                 :            :         unsigned int i;
+    3309         [ #  # ]:          0 :         for (i = 0; i < ARRAY_SIZE(exception_signals); i++) {
+    3310                 :          0 :             signal(exception_signals[i], default_signal_functions[i]);
+    3311                 :            :         }
+    3312                 :            : #else /* _WIN32 */
+    3313                 :            :         if (previous_exception_filter) {
+    3314                 :            :             SetUnhandledExceptionFilter(previous_exception_filter);
+    3315                 :            :             previous_exception_filter = NULL;
+    3316                 :            :         }
+    3317                 :            : #endif /* !_WIN32 */
+    3318                 :            :     }
+    3319                 :            : 
+    3320                 :          0 :     return rc;
+    3321                 :            : }
+    3322                 :            : 
+    3323                 :            : 
+    3324                 :          0 : int _run_tests(const UnitTest * const tests, const size_t number_of_tests) {
+    3325                 :            :     /* Whether to execute the next test. */
+    3326                 :          0 :     int run_next_test = 1;
+    3327                 :            :     /* Whether the previous test failed. */
+    3328                 :          0 :     int previous_test_failed = 0;
+    3329                 :            :     /* Whether the previous setup failed. */
+    3330                 :          0 :     int previous_setup_failed = 0;
+    3331                 :            :     /* Check point of the heap state. */
+    3332                 :          0 :     const ListNode * const check_point = check_point_allocated_blocks();
+    3333                 :            :     /* Current test being executed. */
+    3334                 :          0 :     size_t current_test = 0;
+    3335                 :            :     /* Number of tests executed. */
+    3336                 :          0 :     size_t tests_executed = 0;
+    3337                 :            :     /* Number of failed tests. */
+    3338                 :          0 :     size_t total_failed = 0;
+    3339                 :            :     /* Number of setup functions. */
+    3340                 :          0 :     size_t setups = 0;
+    3341                 :            :     /* Number of teardown functions. */
+    3342                 :          0 :     size_t teardowns = 0;
+    3343                 :            :     size_t i;
+    3344                 :            :     /*
+    3345                 :            :      * A stack of test states.  A state is pushed on the stack
+    3346                 :            :      * when a test setup occurs and popped on tear down.
+    3347                 :            :      */
+    3348                 :            :     TestState* test_states =
+    3349                 :          0 :        (TestState*)malloc(number_of_tests * sizeof(*test_states));
+    3350                 :            :     /* The number of test states which should be 0 at the end */
+    3351                 :          0 :     long number_of_test_states = 0;
+    3352                 :            :     /* Names of the tests that failed. */
+    3353                 :          0 :     const char** failed_names = (const char**)malloc(number_of_tests *
+    3354                 :            :                                        sizeof(*failed_names));
+    3355                 :          0 :     void **current_state = NULL;
+    3356                 :            : 
+    3357                 :            :     /* Count setup and teardown functions */
+    3358         [ #  # ]:          0 :     for (i = 0; i < number_of_tests; i++) {
+    3359                 :          0 :         const UnitTest * const test = &tests[i];
+    3360                 :            : 
+    3361         [ #  # ]:          0 :         if (test->function_type == UNIT_TEST_FUNCTION_TYPE_SETUP) {
+    3362                 :          0 :             setups++;
+    3363                 :            :         }
+    3364                 :            : 
+    3365         [ #  # ]:          0 :         if (test->function_type == UNIT_TEST_FUNCTION_TYPE_TEARDOWN) {
+    3366                 :          0 :             teardowns++;
+    3367                 :            :         }
+    3368                 :            :     }
+    3369                 :            : 
+    3370                 :          0 :     print_message("[==========] Running %"PRIdS " test(s).\n",
+    3371                 :          0 :                   number_of_tests - setups - teardowns);
+    3372                 :            : 
+    3373                 :            :     /* Make sure LargestIntegralType is at least the size of a pointer. */
+    3374                 :          0 :     assert_true(sizeof(LargestIntegralType) >= sizeof(void*));
+    3375                 :            : 
+    3376         [ #  # ]:          0 :     while (current_test < number_of_tests) {
+    3377                 :          0 :         const ListNode *test_check_point = NULL;
+    3378                 :            :         TestState *current_TestState;
+    3379                 :          0 :         const UnitTest * const test = &tests[current_test++];
+    3380         [ #  # ]:          0 :         if (!test->function) {
+    3381                 :          0 :             continue;
+    3382                 :            :         }
+    3383                 :            : 
+    3384   [ #  #  #  # ]:          0 :         switch (test->function_type) {
+    3385                 :          0 :         case UNIT_TEST_FUNCTION_TYPE_TEST:
+    3386         [ #  # ]:          0 :             if (! previous_setup_failed) {
+    3387                 :          0 :                 run_next_test = 1;
+    3388                 :            :             }
+    3389                 :          0 :             break;
+    3390                 :          0 :         case UNIT_TEST_FUNCTION_TYPE_SETUP: {
+    3391                 :            :             /* Checkpoint the heap before the setup. */
+    3392                 :          0 :             current_TestState = &test_states[number_of_test_states++];
+    3393                 :          0 :             current_TestState->check_point = check_point_allocated_blocks();
+    3394                 :          0 :             test_check_point = current_TestState->check_point;
+    3395                 :          0 :             current_state = &current_TestState->state;
+    3396                 :          0 :             *current_state = NULL;
+    3397                 :          0 :             run_next_test = 1;
+    3398                 :          0 :             break;
+    3399                 :            :         }
+    3400                 :          0 :         case UNIT_TEST_FUNCTION_TYPE_TEARDOWN:
+    3401                 :            :             /* Check the heap based on the last setup checkpoint. */
+    3402                 :          0 :             assert_true(number_of_test_states);
+    3403                 :          0 :             current_TestState = &test_states[--number_of_test_states];
+    3404                 :          0 :             test_check_point = current_TestState->check_point;
+    3405                 :          0 :             current_state = &current_TestState->state;
+    3406                 :          0 :             break;
+    3407                 :          0 :         default:
+    3408                 :          0 :             print_error("Invalid unit test function type %d\n",
+    3409                 :          0 :                         test->function_type);
+    3410                 :          0 :             exit_test(1);
+    3411                 :          0 :             break;
+    3412                 :            :         }
+    3413                 :            : 
+    3414         [ #  # ]:          0 :         if (run_next_test) {
+    3415                 :          0 :             int failed = _run_test(test->name, test->function, current_state,
+    3416                 :          0 :                                    test->function_type, test_check_point);
+    3417         [ #  # ]:          0 :             if (failed) {
+    3418                 :          0 :                 failed_names[total_failed] = test->name;
+    3419                 :            :             }
+    3420                 :            : 
+    3421   [ #  #  #  # ]:          0 :             switch (test->function_type) {
+    3422                 :          0 :             case UNIT_TEST_FUNCTION_TYPE_TEST:
+    3423                 :          0 :                 previous_test_failed = failed;
+    3424                 :          0 :                 total_failed += failed;
+    3425                 :          0 :                 tests_executed ++;
+    3426                 :          0 :                 break;
+    3427                 :            : 
+    3428                 :          0 :             case UNIT_TEST_FUNCTION_TYPE_SETUP:
+    3429         [ #  # ]:          0 :                 if (failed) {
+    3430                 :          0 :                     total_failed ++;
+    3431                 :          0 :                     tests_executed ++;
+    3432                 :            :                     /* Skip forward until the next test or setup function. */
+    3433                 :          0 :                     run_next_test = 0;
+    3434                 :          0 :                     previous_setup_failed = 1;
+    3435                 :            :                 }
+    3436                 :          0 :                 previous_test_failed = 0;
+    3437                 :          0 :                 break;
+    3438                 :            : 
+    3439                 :          0 :             case UNIT_TEST_FUNCTION_TYPE_TEARDOWN:
+    3440                 :            :                 /* If this test failed. */
+    3441   [ #  #  #  # ]:          0 :                 if (failed && !previous_test_failed) {
+    3442                 :          0 :                     total_failed ++;
+    3443                 :            :                 }
+    3444                 :          0 :                 break;
+    3445                 :          0 :             default:
+    3446                 :            : #ifndef _HPUX
+    3447                 :          0 :                 assert_null("BUG: shouldn't be here!");
+    3448                 :            : #endif
+    3449                 :          0 :                 break;
+    3450                 :            :             }
+    3451                 :            :         }
+    3452                 :            :     }
+    3453                 :            : 
+    3454                 :          0 :     print_message("[==========] %"PRIdS " test(s) run.\n", tests_executed);
+    3455                 :          0 :     print_error("[  PASSED  ] %"PRIdS " test(s).\n", tests_executed - total_failed);
+    3456                 :            : 
+    3457         [ #  # ]:          0 :     if (total_failed > 0) {
+    3458                 :          0 :         print_error("[  FAILED  ] %"PRIdS " test(s), listed below:\n", total_failed);
+    3459         [ #  # ]:          0 :         for (i = 0; i < total_failed; i++) {
+    3460                 :          0 :             print_error("[  FAILED  ] %s\n", failed_names[i]);
+    3461                 :            :         }
+    3462                 :            :     } else {
+    3463                 :          0 :         print_error("\n %"PRIdS " FAILED TEST(S)\n", total_failed);
+    3464                 :            :     }
+    3465                 :            : 
+    3466         [ #  # ]:          0 :     if (number_of_test_states != 0) {
+    3467                 :          0 :         print_error("[  ERROR   ] Mismatched number of setup %"PRIdS " and "
+    3468                 :            :                     "teardown %"PRIdS " functions\n", setups, teardowns);
+    3469                 :          0 :         total_failed = (size_t)-1;
+    3470                 :            :     }
+    3471                 :            : 
+    3472                 :          0 :     free(test_states);
+    3473                 :          0 :     free((void*)failed_names);
+    3474                 :            : 
+    3475                 :          0 :     fail_if_blocks_allocated(check_point, "run_tests");
+    3476                 :          0 :     return (int)total_failed;
+    3477                 :            : }
+    3478                 :            : 
+    3479                 :          0 : int _run_group_tests(const UnitTest * const tests, const size_t number_of_tests)
+    3480                 :            : {
+    3481                 :          0 :     UnitTestFunction setup = NULL;
+    3482                 :          0 :     const char *setup_name = NULL;
+    3483                 :          0 :     size_t num_setups = 0;
+    3484                 :          0 :     UnitTestFunction teardown = NULL;
+    3485                 :          0 :     const char *teardown_name = NULL;
+    3486                 :          0 :     size_t num_teardowns = 0;
+    3487                 :          0 :     size_t current_test = 0;
+    3488                 :            :     size_t i;
+    3489                 :            : 
+    3490                 :            :     /* Number of tests executed. */
+    3491                 :          0 :     size_t tests_executed = 0;
+    3492                 :            :     /* Number of failed tests. */
+    3493                 :          0 :     size_t total_failed = 0;
+    3494                 :            :     /* Check point of the heap state. */
+    3495                 :          0 :     const ListNode * const check_point = check_point_allocated_blocks();
+    3496                 :          0 :     const char **failed_names = NULL;
+    3497                 :          0 :     void **current_state = NULL;
+    3498                 :          0 :     TestState group_state = {
+    3499                 :            :         .check_point = NULL,
+    3500                 :            :     };
+    3501                 :            : 
+    3502         [ #  # ]:          0 :     if (number_of_tests == 0) {
+    3503                 :          0 :         return -1;
+    3504                 :            :     }
+    3505                 :            : 
+    3506                 :          0 :     failed_names = (const char **)malloc(number_of_tests *
+    3507                 :            :                                          sizeof(*failed_names));
+    3508         [ #  # ]:          0 :     if (failed_names == NULL) {
+    3509                 :          0 :         return -2;
+    3510                 :            :     }
+    3511                 :            : 
+    3512                 :            :     /* Find setup and teardown function */
+    3513         [ #  # ]:          0 :     for (i = 0; i < number_of_tests; i++) {
+    3514                 :          0 :         const UnitTest * const test = &tests[i];
+    3515                 :            : 
+    3516         [ #  # ]:          0 :         if (test->function_type == UNIT_TEST_FUNCTION_TYPE_GROUP_SETUP) {
+    3517         [ #  # ]:          0 :             if (setup == NULL) {
+    3518                 :          0 :                 setup = test->function;
+    3519                 :          0 :                 setup_name = test->name;
+    3520                 :          0 :                 num_setups = 1;
+    3521                 :            :             } else {
+    3522                 :          0 :                 print_error("[  ERROR   ] More than one group setup function detected\n");
+    3523                 :          0 :                 exit_test(1);
+    3524                 :            :             }
+    3525                 :            :         }
+    3526                 :            : 
+    3527         [ #  # ]:          0 :         if (test->function_type == UNIT_TEST_FUNCTION_TYPE_GROUP_TEARDOWN) {
+    3528         [ #  # ]:          0 :             if (teardown == NULL) {
+    3529                 :          0 :                 teardown = test->function;
+    3530                 :          0 :                 teardown_name = test->name;
+    3531                 :          0 :                 num_teardowns = 1;
+    3532                 :            :             } else {
+    3533                 :          0 :                 print_error("[  ERROR   ] More than one group teardown function detected\n");
+    3534                 :          0 :                 exit_test(1);
+    3535                 :            :             }
+    3536                 :            :         }
+    3537                 :            :     }
+    3538                 :            : 
+    3539                 :          0 :     print_message("[==========] Running %"PRIdS " test(s).\n",
+    3540                 :          0 :                   number_of_tests - num_setups - num_teardowns);
+    3541                 :            : 
+    3542         [ #  # ]:          0 :     if (setup != NULL) {
+    3543                 :            :         int failed;
+    3544                 :            : 
+    3545                 :          0 :         group_state.check_point = check_point_allocated_blocks();
+    3546                 :          0 :         current_state = &group_state.state;
+    3547                 :          0 :         *current_state = NULL;
+    3548                 :          0 :         failed = _run_test(setup_name,
+    3549                 :            :                            setup,
+    3550                 :            :                            current_state,
+    3551                 :            :                            UNIT_TEST_FUNCTION_TYPE_SETUP,
+    3552                 :          0 :                            group_state.check_point);
+    3553         [ #  # ]:          0 :         if (failed) {
+    3554                 :          0 :             failed_names[total_failed] = setup_name;
+    3555                 :            :         }
+    3556                 :            : 
+    3557                 :          0 :         total_failed += failed;
+    3558                 :          0 :         tests_executed++;
+    3559                 :            :     }
+    3560                 :            : 
+    3561         [ #  # ]:          0 :     while (current_test < number_of_tests) {
+    3562                 :          0 :         int run_test = 0;
+    3563                 :          0 :         const UnitTest * const test = &tests[current_test++];
+    3564         [ #  # ]:          0 :         if (test->function == NULL) {
+    3565                 :          0 :             continue;
+    3566                 :            :         }
+    3567                 :            : 
+    3568      [ #  #  # ]:          0 :         switch (test->function_type) {
+    3569                 :          0 :         case UNIT_TEST_FUNCTION_TYPE_TEST:
+    3570                 :          0 :             run_test = 1;
+    3571                 :          0 :             break;
+    3572                 :          0 :         case UNIT_TEST_FUNCTION_TYPE_SETUP:
+    3573                 :            :         case UNIT_TEST_FUNCTION_TYPE_TEARDOWN:
+    3574                 :            :         case UNIT_TEST_FUNCTION_TYPE_GROUP_SETUP:
+    3575                 :            :         case UNIT_TEST_FUNCTION_TYPE_GROUP_TEARDOWN:
+    3576                 :          0 :             break;
+    3577                 :          0 :         default:
+    3578                 :          0 :             print_error("Invalid unit test function type %d\n",
+    3579                 :          0 :                         test->function_type);
+    3580                 :          0 :             break;
+    3581                 :            :         }
+    3582                 :            : 
+    3583         [ #  # ]:          0 :         if (run_test) {
+    3584                 :            :             int failed;
+    3585                 :            : 
+    3586                 :          0 :             failed = _run_test(test->name,
+    3587                 :          0 :                                test->function,
+    3588                 :            :                                current_state,
+    3589                 :          0 :                                test->function_type,
+    3590                 :            :                                NULL);
+    3591         [ #  # ]:          0 :             if (failed) {
+    3592                 :          0 :                 failed_names[total_failed] = test->name;
+    3593                 :            :             }
+    3594                 :            : 
+    3595                 :          0 :             total_failed += failed;
+    3596                 :          0 :             tests_executed++;
+    3597                 :            :         }
+    3598                 :            :     }
+    3599                 :            : 
+    3600         [ #  # ]:          0 :     if (teardown != NULL) {
+    3601                 :            :         int failed;
+    3602                 :            : 
+    3603                 :          0 :         failed = _run_test(teardown_name,
+    3604                 :            :                            teardown,
+    3605                 :            :                            current_state,
+    3606                 :            :                            UNIT_TEST_FUNCTION_TYPE_GROUP_TEARDOWN,
+    3607                 :          0 :                            group_state.check_point);
+    3608         [ #  # ]:          0 :         if (failed) {
+    3609                 :          0 :             failed_names[total_failed] = teardown_name;
+    3610                 :            :         }
+    3611                 :            : 
+    3612                 :          0 :         total_failed += failed;
+    3613                 :          0 :         tests_executed++;
+    3614                 :            :     }
+    3615                 :            : 
+    3616                 :          0 :     print_message("[==========] %"PRIdS " test(s) run.\n", tests_executed);
+    3617                 :          0 :     print_error("[  PASSED  ] %"PRIdS " test(s).\n", tests_executed - total_failed);
+    3618                 :            : 
+    3619         [ #  # ]:          0 :     if (total_failed) {
+    3620                 :          0 :         print_error("[  FAILED  ] %"PRIdS " test(s), listed below:\n", total_failed);
+    3621         [ #  # ]:          0 :         for (i = 0; i < total_failed; i++) {
+    3622                 :          0 :             print_error("[  FAILED  ] %s\n", failed_names[i]);
+    3623                 :            :         }
+    3624                 :            :     } else {
+    3625                 :          0 :         print_error("\n %"PRIdS " FAILED TEST(S)\n", total_failed);
+    3626                 :            :     }
+    3627                 :            : 
+    3628                 :          0 :     free((void*)failed_names);
+    3629                 :          0 :     fail_if_blocks_allocated(check_point, "run_group_tests");
+    3630                 :            : 
+    3631                 :          0 :     return (int)total_failed;
+    3632                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/cmockalib/cmocka/src/index-sort-b.html b/coverage_log/unit_test/cmockalib/cmocka/src/index-sort-b.html new file mode 100644 index 00000000000..98f465961f6 --- /dev/null +++ b/coverage_log/unit_test/cmockalib/cmocka/src/index-sort-b.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - unit_test/cmockalib/cmocka/src + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/cmockalib/cmocka/srcHitTotalCoverage
Test:coverage.infoLines:308146121.1 %
Date:2024-09-22 08:21:07Functions:4413432.8 %
Branches:8559814.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
cmocka.c +
21.1%21.1%
+
21.1 %308 / 146132.8 %44 / 13414.2 %85 / 598
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/cmockalib/cmocka/src/index-sort-f.html b/coverage_log/unit_test/cmockalib/cmocka/src/index-sort-f.html new file mode 100644 index 00000000000..a30781e4ec0 --- /dev/null +++ b/coverage_log/unit_test/cmockalib/cmocka/src/index-sort-f.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - unit_test/cmockalib/cmocka/src + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/cmockalib/cmocka/srcHitTotalCoverage
Test:coverage.infoLines:308146121.1 %
Date:2024-09-22 08:21:07Functions:4413432.8 %
Branches:8559814.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
cmocka.c +
21.1%21.1%
+
21.1 %308 / 146132.8 %44 / 13414.2 %85 / 598
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/cmockalib/cmocka/src/index-sort-l.html b/coverage_log/unit_test/cmockalib/cmocka/src/index-sort-l.html new file mode 100644 index 00000000000..6151f89b0f4 --- /dev/null +++ b/coverage_log/unit_test/cmockalib/cmocka/src/index-sort-l.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - unit_test/cmockalib/cmocka/src + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/cmockalib/cmocka/srcHitTotalCoverage
Test:coverage.infoLines:308146121.1 %
Date:2024-09-22 08:21:07Functions:4413432.8 %
Branches:8559814.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
cmocka.c +
21.1%21.1%
+
21.1 %308 / 146132.8 %44 / 13414.2 %85 / 598
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/cmockalib/cmocka/src/index.html b/coverage_log/unit_test/cmockalib/cmocka/src/index.html new file mode 100644 index 00000000000..aaf75acbe81 --- /dev/null +++ b/coverage_log/unit_test/cmockalib/cmocka/src/index.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - unit_test/cmockalib/cmocka/src + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/cmockalib/cmocka/srcHitTotalCoverage
Test:coverage.infoLines:308146121.1 %
Date:2024-09-22 08:21:07Functions:4413432.8 %
Branches:8559814.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
cmocka.c +
21.1%21.1%
+
21.1 %308 / 146132.8 %44 / 13414.2 %85 / 598
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/spdm_transport_test_lib/common.c.func-sort-c.html b/coverage_log/unit_test/spdm_transport_test_lib/common.c.func-sort-c.html new file mode 100644 index 00000000000..29e2852d69e --- /dev/null +++ b/coverage_log/unit_test/spdm_transport_test_lib/common.c.func-sort-c.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - unit_test/spdm_transport_test_lib/common.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/spdm_transport_test_lib - common.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:598668.6 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:213855.3 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_transport_test_decode_message2647
libspdm_transport_test_encode_message5130
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/spdm_transport_test_lib/common.c.func.html b/coverage_log/unit_test/spdm_transport_test_lib/common.c.func.html new file mode 100644 index 00000000000..995dc9f783a --- /dev/null +++ b/coverage_log/unit_test/spdm_transport_test_lib/common.c.func.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - unit_test/spdm_transport_test_lib/common.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/spdm_transport_test_lib - common.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:598668.6 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:213855.3 %
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_transport_test_decode_message2647
libspdm_transport_test_encode_message5130
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/spdm_transport_test_lib/common.c.gcov.html b/coverage_log/unit_test/spdm_transport_test_lib/common.c.gcov.html new file mode 100644 index 00000000000..605745dbf63 --- /dev/null +++ b/coverage_log/unit_test/spdm_transport_test_lib/common.c.gcov.html @@ -0,0 +1,401 @@ + + + + + + + LCOV - coverage.info - unit_test/spdm_transport_test_lib/common.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/spdm_transport_test_lib - common.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:598668.6 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:213855.3 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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 "library/spdm_transport_test_lib.h"
+       8                 :            : #include "library/spdm_secured_message_lib.h"
+       9                 :            : 
+      10                 :            : /**
+      11                 :            :  * Encode a normal message or secured message to a transport message.
+      12                 :            :  *
+      13                 :            :  * @param  session_id                    Indicates if it is a secured message protected via SPDM session.
+      14                 :            :  *                                     If session_id is NULL, it is a normal message.
+      15                 :            :  *                                     If session_id is NOT NULL, it is a secured message.
+      16                 :            :  * @param  message_size                  size in bytes of the message data buffer.
+      17                 :            :  * @param  message                      A pointer to a source buffer to store the message.
+      18                 :            :  * @param  transport_message_size         size in bytes of the transport message data buffer.
+      19                 :            :  * @param  transport_message             A pointer to a destination buffer to store the transport message.
+      20                 :            :  *
+      21                 :            :  * @retval RETURN_SUCCESS               The message is encoded successfully.
+      22                 :            :  * @retval RETURN_INVALID_PARAMETER     The message is NULL or the message_size is zero.
+      23                 :            :  **/
+      24                 :            : libspdm_return_t libspdm_test_encode_message(const uint32_t *session_id,
+      25                 :            :                                              bool need_alignment,
+      26                 :            :                                              size_t message_size,
+      27                 :            :                                              const void *message,
+      28                 :            :                                              size_t *transport_message_size,
+      29                 :            :                                              void **transport_message);
+      30                 :            : 
+      31                 :            : /**
+      32                 :            :  * Decode a transport message to a normal message or secured message.
+      33                 :            :  *
+      34                 :            :  * @param  session_id                    Indicates if it is a secured message protected via SPDM session.
+      35                 :            :  *                                     If *session_id is NULL, it is a normal message.
+      36                 :            :  *                                     If *session_id is NOT NULL, it is a secured message.
+      37                 :            :  * @param  transport_message_size         size in bytes of the transport message data buffer.
+      38                 :            :  * @param  transport_message             A pointer to a source buffer to store the transport message.
+      39                 :            :  * @param  message_size                  size in bytes of the message data buffer.
+      40                 :            :  * @param  message                      A pointer to a destination buffer to store the message.
+      41                 :            :  *
+      42                 :            :  * @retval RETURN_SUCCESS               The message is encoded successfully.
+      43                 :            :  * @retval RETURN_INVALID_PARAMETER     The message is NULL or the message_size is zero.
+      44                 :            :  **/
+      45                 :            : libspdm_return_t libspdm_test_decode_message(uint32_t **session_id,
+      46                 :            :                                              bool need_alignment,
+      47                 :            :                                              size_t transport_message_size,
+      48                 :            :                                              const void *transport_message,
+      49                 :            :                                              size_t *message_size,
+      50                 :            :                                              void **message);
+      51                 :            : 
+      52                 :            : /**
+      53                 :            :  * Encode an SPDM or APP message to a transport layer message.
+      54                 :            :  *
+      55                 :            :  * For normal SPDM message, it adds the transport layer wrapper.
+      56                 :            :  * For secured SPDM message, it encrypts a secured message then adds the transport layer wrapper.
+      57                 :            :  * For secured APP message, it encrypts a secured message then adds the transport layer wrapper.
+      58                 :            :  *
+      59                 :            :  * The APP message is encoded to a secured message directly in SPDM session.
+      60                 :            :  * The APP message format is defined by the transport layer.
+      61                 :            :  * Take MCTP as example: APP message == MCTP header (MCTP_MESSAGE_TYPE_SPDM) + SPDM message
+      62                 :            :  *
+      63                 :            :  * @param  spdm_context            A pointer to the SPDM context.
+      64                 :            :  * @param  session_id              Indicates if it is a secured message protected via SPDM session.
+      65                 :            :  *                                 If session_id is NULL, it is a normal message.
+      66                 :            :  *                                 If session_id is not NULL, it is a secured message.
+      67                 :            :  * @param  is_app_message          Indicates if it is an APP message or SPDM message.
+      68                 :            :  * @param  is_request_message      Indicates if it is a request message.
+      69                 :            :  * @param  message_size            Size in bytes of the message data buffer.
+      70                 :            :  * @param  message                 A pointer to a source buffer to store the message.
+      71                 :            :  *                                 For normal message, it shall point to the acquired sender buffer.
+      72                 :            :  *                                 For secured message, it shall point to the scratch buffer in spdm_context.
+      73                 :            :  * @param  transport_message_size  Size in bytes of the transport message data buffer.
+      74                 :            :  * @param  transport_message       A pointer to a destination buffer to store the transport message.
+      75                 :            :  *                                 On input, it shall be msg_buf_ptr from sender buffer.
+      76                 :            :  *                                 On output, it will point to acquired sender buffer.
+      77                 :            :  *
+      78                 :            :  * @retval RETURN_SUCCESS               The message is encoded successfully.
+      79                 :            :  * @retval RETURN_INVALID_PARAMETER     The message is NULL or the message_size is zero.
+      80                 :            :  **/
+      81                 :       5130 : libspdm_return_t libspdm_transport_test_encode_message(
+      82                 :            :     void *spdm_context, const uint32_t *session_id, bool is_app_message,
+      83                 :            :     bool is_request_message, size_t message_size, void *message,
+      84                 :            :     size_t *transport_message_size, void **transport_message)
+      85                 :            : {
+      86                 :            :     libspdm_return_t status;
+      87                 :            :     void *app_message;
+      88                 :            :     size_t app_message_size;
+      89                 :            :     uint8_t *secured_message;
+      90                 :            :     size_t secured_message_size;
+      91                 :            :     libspdm_secured_message_callbacks_t spdm_secured_message_callbacks;
+      92                 :            :     void *secured_message_context;
+      93                 :            :     size_t transport_header_size;
+      94                 :            : 
+      95                 :       5130 :     spdm_secured_message_callbacks.version =
+      96                 :            :         LIBSPDM_SECURED_MESSAGE_CALLBACKS_VERSION;
+      97                 :       5130 :     spdm_secured_message_callbacks.get_sequence_number =
+      98                 :            :         libspdm_test_get_sequence_number;
+      99                 :       5130 :     spdm_secured_message_callbacks.get_max_random_number_count =
+     100                 :            :         libspdm_test_get_max_random_number_count;
+     101                 :       5130 :     spdm_secured_message_callbacks.get_secured_spdm_version =
+     102                 :            :         libspdm_test_get_secured_spdm_version;
+     103                 :            : 
+     104   [ -  +  -  - ]:       5130 :     if (is_app_message && (session_id == NULL)) {
+     105                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     106                 :            :     }
+     107                 :            : 
+     108         [ +  + ]:       5130 :     if (session_id != NULL) {
+     109                 :            :         secured_message_context =
+     110                 :        464 :             libspdm_get_secured_message_context_via_session_id(
+     111                 :            :                 spdm_context, *session_id);
+     112         [ -  + ]:        464 :         if (secured_message_context == NULL) {
+     113                 :          0 :             return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     114                 :            :         }
+     115                 :            : 
+     116                 :        464 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     117                 :            : 
+     118         [ +  - ]:        464 :         if (!is_app_message) {
+     119                 :            :             /* SPDM message to APP message*/
+     120                 :        464 :             app_message = NULL;
+     121                 :        464 :             app_message_size = transport_header_size + message_size + (LIBSPDM_TEST_ALIGNMENT - 1);
+     122                 :        464 :             status = libspdm_test_encode_message(NULL, false, message_size,
+     123                 :            :                                                  message,
+     124                 :            :                                                  &app_message_size,
+     125                 :            :                                                  &app_message);
+     126         [ -  + ]:        464 :             if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     127                 :          0 :                 LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR,
+     128                 :            :                                "transport_encode_message - %xu\n",
+     129                 :            :                                status));
+     130                 :          0 :                 return status;
+     131                 :            :             }
+     132                 :            :         } else {
+     133                 :          0 :             app_message = (void *)message;
+     134                 :          0 :             app_message_size = message_size;
+     135                 :            :         }
+     136                 :            :         /* APP message to secured message*/
+     137                 :        464 :         secured_message = (uint8_t *)*transport_message + transport_header_size;
+     138                 :        464 :         secured_message_size = *transport_message_size - transport_header_size;
+     139                 :        464 :         status = libspdm_encode_secured_message(
+     140                 :            :             secured_message_context, *session_id, is_request_message,
+     141                 :            :             app_message_size, app_message, &secured_message_size,
+     142                 :            :             secured_message, &spdm_secured_message_callbacks);
+     143         [ -  + ]:        464 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     144                 :          0 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR,
+     145                 :            :                            "libspdm_encode_secured_message - %xu\n", status));
+     146                 :          0 :             return status;
+     147                 :            :         }
+     148                 :            : 
+     149                 :            :         /* secured message to secured Test message*/
+     150                 :        464 :         status = libspdm_test_encode_message(
+     151                 :            :             session_id, true, secured_message_size, secured_message,
+     152                 :            :             transport_message_size, transport_message);
+     153         [ -  + ]:        464 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     154                 :          0 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR, "transport_encode_message - %xu\n",
+     155                 :            :                            status));
+     156                 :          0 :             return status;
+     157                 :            :         }
+     158                 :            :     } else {
+     159                 :            :         /* SPDM message to normal Test message*/
+     160                 :       4666 :         status = libspdm_test_encode_message(NULL, true, message_size, message,
+     161                 :            :                                              transport_message_size,
+     162                 :            :                                              transport_message);
+     163         [ -  + ]:       4666 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     164                 :          0 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR, "transport_encode_message - %xu\n",
+     165                 :            :                            status));
+     166                 :          0 :             return status;
+     167                 :            :         }
+     168                 :            :     }
+     169                 :            : 
+     170                 :       5130 :     return LIBSPDM_STATUS_SUCCESS;
+     171                 :            : }
+     172                 :            : 
+     173                 :            : /**
+     174                 :            :  * Decode an SPDM or APP message from a transport layer message.
+     175                 :            :  *
+     176                 :            :  * For normal SPDM message, it removes the transport layer wrapper,
+     177                 :            :  * For secured SPDM message, it removes the transport layer wrapper, then decrypts and verifies a secured message.
+     178                 :            :  * For secured APP message, it removes the transport layer wrapper, then decrypts and verifies a secured message.
+     179                 :            :  *
+     180                 :            :  * The APP message is decoded from a secured message directly in SPDM session.
+     181                 :            :  * The APP message format is defined by the transport layer.
+     182                 :            :  * Take MCTP as example: APP message == MCTP header (MCTP_MESSAGE_TYPE_SPDM) + SPDM message
+     183                 :            :  *
+     184                 :            :  * @param  spdm_context            A pointer to the SPDM context.
+     185                 :            :  * @param  session_id              Indicates if it is a secured message protected via SPDM session.
+     186                 :            :  *                                 If session_id is NULL, it is a normal message.
+     187                 :            :  *                                 If session_id is not NULL, it is a secured message.
+     188                 :            :  * @param  is_app_message          Indicates if it is an APP message or SPDM message.
+     189                 :            :  * @param  is_request_message      Indicates if it is a request message.
+     190                 :            :  * @param  transport_message_size  Size in bytes of the transport message data buffer.
+     191                 :            :  * @param  transport_message       A pointer to a source buffer to store the transport message.
+     192                 :            :  *                                 For normal message or secured message, it shall point to acquired receiver buffer.
+     193                 :            :  * @param  message_size            Size in bytes of the message data buffer.
+     194                 :            :  * @param  message                 A pointer to a destination buffer to store the message.
+     195                 :            :  *                                 On input, it shall point to the scratch buffer in spdm_context.
+     196                 :            :  *                                 On output, for normal message, it will point to the original receiver buffer.
+     197                 :            :  *                                 On output, for secured message, it will point to the scratch buffer in spdm_context.
+     198                 :            :  *
+     199                 :            :  * @retval RETURN_SUCCESS               The message is decoded successfully.
+     200                 :            :  * @retval RETURN_INVALID_PARAMETER     The message is NULL or the message_size is zero.
+     201                 :            :  * @retval RETURN_UNSUPPORTED           The transport_message is unsupported.
+     202                 :            :  **/
+     203                 :       2647 : libspdm_return_t libspdm_transport_test_decode_message(
+     204                 :            :     void *spdm_context, uint32_t **session_id,
+     205                 :            :     bool *is_app_message, bool is_request_message,
+     206                 :            :     size_t transport_message_size, void *transport_message,
+     207                 :            :     size_t *message_size, void **message)
+     208                 :            : {
+     209                 :            :     libspdm_return_t status;
+     210                 :            :     uint32_t *secured_message_session_id;
+     211                 :            :     uint8_t *secured_message;
+     212                 :            :     size_t secured_message_size;
+     213                 :            :     uint8_t *app_message;
+     214                 :            :     size_t app_message_size;
+     215                 :            :     libspdm_secured_message_callbacks_t spdm_secured_message_callbacks;
+     216                 :            :     void *secured_message_context;
+     217                 :            :     libspdm_error_struct_t spdm_error;
+     218                 :            : 
+     219                 :       2647 :     spdm_error.error_code = 0;
+     220                 :       2647 :     spdm_error.session_id = 0;
+     221                 :       2647 :     libspdm_set_last_spdm_error_struct(spdm_context, &spdm_error);
+     222                 :            : 
+     223                 :       2647 :     spdm_secured_message_callbacks.version =
+     224                 :            :         LIBSPDM_SECURED_MESSAGE_CALLBACKS_VERSION;
+     225                 :       2647 :     spdm_secured_message_callbacks.get_sequence_number =
+     226                 :            :         libspdm_test_get_sequence_number;
+     227                 :       2647 :     spdm_secured_message_callbacks.get_max_random_number_count =
+     228                 :            :         libspdm_test_get_max_random_number_count;
+     229                 :       2647 :     spdm_secured_message_callbacks.get_secured_spdm_version =
+     230                 :            :         libspdm_test_get_secured_spdm_version;
+     231                 :            : 
+     232   [ +  -  -  + ]:       2647 :     if ((session_id == NULL) || (is_app_message == NULL)) {
+     233                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     234                 :            :     }
+     235                 :            : 
+     236                 :       2647 :     secured_message_session_id = NULL;
+     237                 :            :     /* Detect received message*/
+     238                 :       2647 :     status = libspdm_test_decode_message(
+     239                 :            :         &secured_message_session_id, true, transport_message_size,
+     240                 :            :         transport_message, &secured_message_size, (void **)&secured_message);
+     241         [ -  + ]:       2647 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     242                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR, "transport_decode_message - %xu\n", status));
+     243                 :          0 :         return status;
+     244                 :            :     }
+     245                 :            : 
+     246         [ +  + ]:       2647 :     if (secured_message_session_id != NULL) {
+     247                 :        326 :         *session_id = secured_message_session_id;
+     248                 :            : 
+     249                 :            :         secured_message_context =
+     250                 :        326 :             libspdm_get_secured_message_context_via_session_id(
+     251                 :            :                 spdm_context, *secured_message_session_id);
+     252         [ -  + ]:        326 :         if (secured_message_context == NULL) {
+     253                 :          0 :             spdm_error.error_code = SPDM_ERROR_CODE_INVALID_SESSION;
+     254                 :          0 :             spdm_error.session_id = *secured_message_session_id;
+     255                 :          0 :             libspdm_set_last_spdm_error_struct(spdm_context,
+     256                 :            :                                                &spdm_error);
+     257                 :          0 :             return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     258                 :            :         }
+     259                 :            : 
+     260                 :            :         /* Secured message to APP message*/
+     261                 :        326 :         app_message = *message;
+     262                 :        326 :         app_message_size = *message_size;
+     263                 :        326 :         status = libspdm_decode_secured_message(
+     264                 :            :             secured_message_context, *secured_message_session_id,
+     265                 :            :             is_request_message, secured_message_size, secured_message,
+     266                 :            :             &app_message_size, (void **)&app_message,
+     267                 :            :             &spdm_secured_message_callbacks);
+     268         [ +  + ]:        326 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     269                 :         28 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR,
+     270                 :            :                            "libspdm_decode_secured_message - %xu\n", status));
+     271                 :         28 :             libspdm_secured_message_get_last_spdm_error_struct(
+     272                 :            :                 secured_message_context, &spdm_error);
+     273                 :         28 :             libspdm_set_last_spdm_error_struct(spdm_context,
+     274                 :            :                                                &spdm_error);
+     275                 :         28 :             return status;
+     276                 :            :         }
+     277                 :            : 
+     278                 :            :         /* APP message to SPDM message.*/
+     279                 :        298 :         status = libspdm_test_decode_message(&secured_message_session_id, false,
+     280                 :            :                                              app_message_size, app_message,
+     281                 :            :                                              message_size, message);
+     282         [ -  + ]:        298 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     283                 :          0 :             *is_app_message = true;
+     284                 :            :             /* just return APP message.*/
+     285                 :          0 :             *message = app_message;
+     286                 :          0 :             *message_size = app_message_size;
+     287                 :          0 :             return LIBSPDM_STATUS_SUCCESS;
+     288                 :            :         } else {
+     289                 :        298 :             *is_app_message = false;
+     290         [ +  - ]:        298 :             if (secured_message_session_id == NULL) {
+     291                 :        298 :                 return LIBSPDM_STATUS_SUCCESS;
+     292                 :            :             } else {
+     293                 :            :                 /* get encapsulated secured message - cannot handle it.*/
+     294                 :          0 :                 LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR,
+     295                 :            :                                "transport_decode_message - expect encapsulated normal but got session (%08x)\n",
+     296                 :            :                                *secured_message_session_id));
+     297                 :          0 :                 return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     298                 :            :             }
+     299                 :            :         }
+     300                 :            :     } else {
+     301                 :            :         /* get non-secured message*/
+     302                 :       2321 :         status = libspdm_test_decode_message(&secured_message_session_id, true,
+     303                 :            :                                              transport_message_size,
+     304                 :            :                                              transport_message,
+     305                 :            :                                              message_size, message);
+     306         [ -  + ]:       2321 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     307                 :          0 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR, "transport_decode_message - %xu\n",
+     308                 :            :                            status));
+     309                 :          0 :             return status;
+     310                 :            :         }
+     311         [ -  + ]:       2321 :         LIBSPDM_ASSERT(secured_message_session_id == NULL);
+     312                 :       2321 :         *session_id = NULL;
+     313                 :       2321 :         *is_app_message = false;
+     314                 :       2321 :         return LIBSPDM_STATUS_SUCCESS;
+     315                 :            :     }
+     316                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/spdm_transport_test_lib/index-sort-b.html b/coverage_log/unit_test/spdm_transport_test_lib/index-sort-b.html new file mode 100644 index 00000000000..8c44f0a1a45 --- /dev/null +++ b/coverage_log/unit_test/spdm_transport_test_lib/index-sort-b.html @@ -0,0 +1,119 @@ + + + + + + + LCOV - coverage.info - unit_test/spdm_transport_test_lib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/spdm_transport_test_libHitTotalCoverage
Test:coverage.infoLines:10714275.4 %
Date:2024-09-22 08:21:07Functions:77100.0 %
Branches:406958.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
common.c +
68.6%68.6%
+
68.6 %59 / 86100.0 %2 / 255.3 %21 / 38
test.c +
85.7%85.7%
+
85.7 %48 / 56100.0 %5 / 561.3 %19 / 31
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/spdm_transport_test_lib/index-sort-f.html b/coverage_log/unit_test/spdm_transport_test_lib/index-sort-f.html new file mode 100644 index 00000000000..97d3a5b41f0 --- /dev/null +++ b/coverage_log/unit_test/spdm_transport_test_lib/index-sort-f.html @@ -0,0 +1,119 @@ + + + + + + + LCOV - coverage.info - unit_test/spdm_transport_test_lib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/spdm_transport_test_libHitTotalCoverage
Test:coverage.infoLines:10714275.4 %
Date:2024-09-22 08:21:07Functions:77100.0 %
Branches:406958.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
common.c +
68.6%68.6%
+
68.6 %59 / 86100.0 %2 / 255.3 %21 / 38
test.c +
85.7%85.7%
+
85.7 %48 / 56100.0 %5 / 561.3 %19 / 31
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/spdm_transport_test_lib/index-sort-l.html b/coverage_log/unit_test/spdm_transport_test_lib/index-sort-l.html new file mode 100644 index 00000000000..4e871c0b4a2 --- /dev/null +++ b/coverage_log/unit_test/spdm_transport_test_lib/index-sort-l.html @@ -0,0 +1,119 @@ + + + + + + + LCOV - coverage.info - unit_test/spdm_transport_test_lib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/spdm_transport_test_libHitTotalCoverage
Test:coverage.infoLines:10714275.4 %
Date:2024-09-22 08:21:07Functions:77100.0 %
Branches:406958.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
common.c +
68.6%68.6%
+
68.6 %59 / 86100.0 %2 / 255.3 %21 / 38
test.c +
85.7%85.7%
+
85.7 %48 / 56100.0 %5 / 561.3 %19 / 31
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/spdm_transport_test_lib/index.html b/coverage_log/unit_test/spdm_transport_test_lib/index.html new file mode 100644 index 00000000000..94dac9e11b6 --- /dev/null +++ b/coverage_log/unit_test/spdm_transport_test_lib/index.html @@ -0,0 +1,119 @@ + + + + + + + LCOV - coverage.info - unit_test/spdm_transport_test_lib + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/spdm_transport_test_libHitTotalCoverage
Test:coverage.infoLines:10714275.4 %
Date:2024-09-22 08:21:07Functions:77100.0 %
Branches:406958.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
common.c +
68.6%68.6%
+
68.6 %59 / 86100.0 %2 / 255.3 %21 / 38
test.c +
85.7%85.7%
+
85.7 %48 / 56100.0 %5 / 561.3 %19 / 31
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/spdm_transport_test_lib/test.c.func-sort-c.html b/coverage_log/unit_test/spdm_transport_test_lib/test.c.func-sort-c.html new file mode 100644 index 00000000000..3aec47ee6d8 --- /dev/null +++ b/coverage_log/unit_test/spdm_transport_test_lib/test.c.func-sort-c.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - unit_test/spdm_transport_test_lib/test.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/spdm_transport_test_lib - test.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:485685.7 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:193161.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_test_get_max_random_number_count464
libspdm_test_get_secured_spdm_version790
libspdm_test_get_sequence_number790
libspdm_test_decode_message5266
libspdm_test_encode_message5594
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/spdm_transport_test_lib/test.c.func.html b/coverage_log/unit_test/spdm_transport_test_lib/test.c.func.html new file mode 100644 index 00000000000..77c45d6e9ae --- /dev/null +++ b/coverage_log/unit_test/spdm_transport_test_lib/test.c.func.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - unit_test/spdm_transport_test_lib/test.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/spdm_transport_test_lib - test.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:485685.7 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:193161.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_test_decode_message5266
libspdm_test_encode_message5594
libspdm_test_get_max_random_number_count464
libspdm_test_get_secured_spdm_version790
libspdm_test_get_sequence_number790
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/spdm_transport_test_lib/test.c.gcov.html b/coverage_log/unit_test/spdm_transport_test_lib/test.c.gcov.html new file mode 100644 index 00000000000..845f3d132a0 --- /dev/null +++ b/coverage_log/unit_test/spdm_transport_test_lib/test.c.gcov.html @@ -0,0 +1,266 @@ + + + + + + + LCOV - coverage.info - unit_test/spdm_transport_test_lib/test.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/spdm_transport_test_lib - test.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:485685.7 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:193161.3 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 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 "library/spdm_transport_test_lib.h"
+       8                 :            : #include "internal/libspdm_common_lib.h"
+       9                 :            : 
+      10                 :            : /**
+      11                 :            :  * Get sequence number in an SPDM secure message.
+      12                 :            :  *
+      13                 :            :  * This value is transport layer specific.
+      14                 :            :  *
+      15                 :            :  * @param sequence_number        The current sequence number used to encode or decode message.
+      16                 :            :  * @param sequence_number_buffer  A buffer to hold the sequence number output used in the secured message.
+      17                 :            :  *                             The size in byte of the output buffer shall be 8.
+      18                 :            :  *
+      19                 :            :  * @return size in byte of the sequence_number_buffer.
+      20                 :            :  *        It shall be no greater than 8.
+      21                 :            :  *        0 means no sequence number is required.
+      22                 :            :  **/
+      23                 :        790 : uint8_t libspdm_test_get_sequence_number(uint64_t sequence_number,
+      24                 :            :                                          uint8_t *sequence_number_buffer)
+      25                 :            : {
+      26                 :        790 :     libspdm_copy_mem(sequence_number_buffer, LIBSPDM_TEST_SEQUENCE_NUMBER_COUNT,
+      27                 :            :                      &sequence_number, LIBSPDM_TEST_SEQUENCE_NUMBER_COUNT);
+      28                 :        790 :     return LIBSPDM_TEST_SEQUENCE_NUMBER_COUNT;
+      29                 :            : }
+      30                 :            : 
+      31                 :            : /**
+      32                 :            :  * Return max random number count in an SPDM secure message.
+      33                 :            :  *
+      34                 :            :  * This value is transport layer specific.
+      35                 :            :  *
+      36                 :            :  * @return Max random number count in an SPDM secured message.
+      37                 :            :  *        0 means no random number is required.
+      38                 :            :  **/
+      39                 :        464 : uint32_t libspdm_test_get_max_random_number_count(void)
+      40                 :            : {
+      41                 :        464 :     return LIBSPDM_TEST_MAX_RANDOM_NUMBER_COUNT;
+      42                 :            : }
+      43                 :            : 
+      44                 :            : /**
+      45                 :            :  * This function translates the negotiated secured_message_version to a DSP0277 version.
+      46                 :            :  *
+      47                 :            :  * @param  secured_message_version  The version specified in binding specification and
+      48                 :            :  *                                  negotiated in KEY_EXCHANGE/KEY_EXCHANGE_RSP.
+      49                 :            :  *
+      50                 :            :  * @return The DSP0277 version specified in binding specification,
+      51                 :            :  *         which is bound to secured_message_version.
+      52                 :            :  */
+      53                 :        790 : spdm_version_number_t libspdm_test_get_secured_spdm_version(
+      54                 :            :     spdm_version_number_t secured_message_version)
+      55                 :            : {
+      56                 :        790 :     return secured_message_version;
+      57                 :            : }
+      58                 :            : 
+      59                 :            : /**
+      60                 :            :  * Encode a normal message or secured message to a transport message.
+      61                 :            :  *
+      62                 :            :  * @param  session_id                    Indicates if it is a secured message protected via SPDM session.
+      63                 :            :  *                                     If session_id is NULL, it is a normal message.
+      64                 :            :  *                                     If session_id is NOT NULL, it is a secured message.
+      65                 :            :  * @param  message_size                  size in bytes of the message data buffer.
+      66                 :            :  * @param  message                      A pointer to a source buffer to store the message.
+      67                 :            :  * @param  transport_message_size         size in bytes of the transport message data buffer.
+      68                 :            :  * @param  transport_message             A pointer to a destination buffer to store the transport message.
+      69                 :            :  *
+      70                 :            :  * @retval RETURN_SUCCESS               The message is encoded successfully.
+      71                 :            :  * @retval RETURN_INVALID_PARAMETER     The message is NULL or the message_size is zero.
+      72                 :            :  **/
+      73                 :       5594 : libspdm_return_t libspdm_test_encode_message(const uint32_t *session_id,
+      74                 :            :                                              bool need_alignment,
+      75                 :            :                                              size_t message_size,
+      76                 :            :                                              void *message,
+      77                 :            :                                              size_t *transport_message_size,
+      78                 :            :                                              void **transport_message)
+      79                 :            : {
+      80                 :            :     size_t aligned_message_size;
+      81                 :            :     size_t alignment;
+      82                 :            :     uint32_t data32;
+      83                 :            :     libspdm_test_message_header_t *test_message_header;
+      84                 :            : 
+      85         [ +  + ]:       5594 :     if (need_alignment) {
+      86                 :       5130 :         alignment = LIBSPDM_TEST_ALIGNMENT;
+      87                 :            :     } else {
+      88                 :        464 :         alignment = 1;
+      89                 :            :     }
+      90                 :       5594 :     aligned_message_size =
+      91                 :       5594 :         (message_size + (alignment - 1)) & ~(alignment - 1);
+      92                 :            : 
+      93         [ -  + ]:       5594 :     LIBSPDM_ASSERT(*transport_message_size >=
+      94                 :            :                    aligned_message_size + sizeof(libspdm_test_message_header_t));
+      95                 :       5594 :     if (*transport_message_size <
+      96         [ -  + ]:       5594 :         aligned_message_size + sizeof(libspdm_test_message_header_t)) {
+      97                 :          0 :         *transport_message_size = aligned_message_size +
+      98                 :            :                                   sizeof(libspdm_test_message_header_t);
+      99                 :          0 :         return LIBSPDM_STATUS_BUFFER_TOO_SMALL;
+     100                 :            :     }
+     101                 :            : 
+     102                 :       5594 :     *transport_message_size =
+     103                 :       5594 :         aligned_message_size + sizeof(libspdm_test_message_header_t);
+     104                 :       5594 :     *transport_message = (uint8_t *)message - sizeof(libspdm_test_message_header_t);
+     105                 :       5594 :     test_message_header = *transport_message;
+     106         [ +  + ]:       5594 :     if (session_id != NULL) {
+     107                 :        464 :         test_message_header->message_type =
+     108                 :            :             LIBSPDM_TEST_MESSAGE_TYPE_SECURED_TEST;
+     109                 :        464 :         data32 = libspdm_read_uint32((const uint8_t *)message);
+     110         [ -  + ]:        464 :         LIBSPDM_ASSERT(*session_id == data32);
+     111         [ -  + ]:        464 :         if (*session_id != data32) {
+     112                 :          0 :             return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     113                 :            :         }
+     114                 :            :     } else {
+     115                 :       5130 :         test_message_header->message_type = LIBSPDM_TEST_MESSAGE_TYPE_SPDM;
+     116                 :            :     }
+     117                 :       5594 :     libspdm_zero_mem((uint8_t *)message + message_size,
+     118                 :            :                      aligned_message_size - message_size);
+     119                 :       5594 :     return LIBSPDM_STATUS_SUCCESS;
+     120                 :            : }
+     121                 :            : 
+     122                 :            : /**
+     123                 :            :  * Decode a transport message to a normal message or secured message.
+     124                 :            :  *
+     125                 :            :  * @param  session_id                    Indicates if it is a secured message protected via SPDM session.
+     126                 :            :  *                                     If *session_id is NULL, it is a normal message.
+     127                 :            :  *                                     If *session_id is NOT NULL, it is a secured message.
+     128                 :            :  * @param  transport_message_size         size in bytes of the transport message data buffer.
+     129                 :            :  * @param  transport_message             A pointer to a source buffer to store the transport message.
+     130                 :            :  * @param  message_size                  size in bytes of the message data buffer.
+     131                 :            :  * @param  message                      A pointer to a destination buffer to store the message.
+     132                 :            :  *
+     133                 :            :  * @retval RETURN_SUCCESS               The message is encoded successfully.
+     134                 :            :  * @retval RETURN_INVALID_PARAMETER     The message is NULL or the message_size is zero.
+     135                 :            :  **/
+     136                 :       5266 : libspdm_return_t libspdm_test_decode_message(uint32_t **session_id,
+     137                 :            :                                              bool need_alignment,
+     138                 :            :                                              size_t transport_message_size,
+     139                 :            :                                              void *transport_message,
+     140                 :            :                                              size_t *message_size, void **message)
+     141                 :            : {
+     142                 :            :     const libspdm_test_message_header_t *test_message_header;
+     143                 :            : 
+     144         [ -  + ]:       5266 :     LIBSPDM_ASSERT(transport_message_size > sizeof(libspdm_test_message_header_t));
+     145         [ -  + ]:       5266 :     if (transport_message_size <= sizeof(libspdm_test_message_header_t)) {
+     146                 :          0 :         return LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     147                 :            :     }
+     148                 :            : 
+     149                 :       5266 :     test_message_header = transport_message;
+     150                 :            : 
+     151      [ +  +  - ]:       5266 :     switch (test_message_header->message_type) {
+     152                 :        326 :     case LIBSPDM_TEST_MESSAGE_TYPE_SECURED_TEST:
+     153         [ -  + ]:        326 :         LIBSPDM_ASSERT(session_id != NULL);
+     154         [ -  + ]:        326 :         if (session_id == NULL) {
+     155                 :          0 :             return LIBSPDM_STATUS_INVALID_MSG_FIELD;
+     156                 :            :         }
+     157         [ -  + ]:        326 :         if (transport_message_size <=
+     158                 :            :             sizeof(libspdm_test_message_header_t) + sizeof(uint32_t)) {
+     159                 :          0 :             return LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     160                 :            :         }
+     161                 :        326 :         *session_id = (uint32_t *)((uint8_t *)transport_message +
+     162                 :            :                                    sizeof(libspdm_test_message_header_t));
+     163                 :        326 :         break;
+     164                 :       4940 :     case LIBSPDM_TEST_MESSAGE_TYPE_SPDM:
+     165         [ +  - ]:       4940 :         if (session_id != NULL) {
+     166                 :       4940 :             *session_id = NULL;
+     167                 :            :         }
+     168                 :       4940 :         break;
+     169                 :          0 :     default:
+     170                 :          0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
+     171                 :            :     }
+     172                 :            : 
+     173         [ +  + ]:       5266 :     if (need_alignment) {
+     174         [ -  + ]:       4968 :         LIBSPDM_ASSERT(((transport_message_size - sizeof(libspdm_test_message_header_t)) &
+     175                 :            :                         (LIBSPDM_TEST_ALIGNMENT - 1)) == 0);
+     176                 :            :     }
+     177                 :            : 
+     178                 :       5266 :     *message_size = transport_message_size - sizeof(libspdm_test_message_header_t);
+     179                 :       5266 :     *message = (uint8_t *)transport_message + sizeof(libspdm_test_message_header_t);
+     180                 :       5266 :     return LIBSPDM_STATUS_SUCCESS;
+     181                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/spdm_unit_test_common/common.c.func-sort-c.html b/coverage_log/unit_test/spdm_unit_test_common/common.c.func-sort-c.html new file mode 100644 index 00000000000..f12483f6da6 --- /dev/null +++ b/coverage_log/unit_test/spdm_unit_test_common/common.c.func-sort-c.html @@ -0,0 +1,121 @@ + + + + + + + LCOV - coverage.info - unit_test/spdm_unit_test_common/common.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/spdm_unit_test_common - common.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:767798.7 %
Date:2024-09-22 08:21:07Functions:1010100.0 %
Branches:213658.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_force_error12
libspdm_release_error12
libspdm_setup_test_context75
libspdm_unit_test_group_teardown76
libspdm_unit_test_group_setup89
spdm_device_release_receiver_buffer2475
spdm_device_acquire_receiver_buffer2481
spdm_device_release_sender_buffer2516
spdm_device_acquire_sender_buffer2522
libspdm_get_test_context5125
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/spdm_unit_test_common/common.c.func.html b/coverage_log/unit_test/spdm_unit_test_common/common.c.func.html new file mode 100644 index 00000000000..de034a8b9fa --- /dev/null +++ b/coverage_log/unit_test/spdm_unit_test_common/common.c.func.html @@ -0,0 +1,121 @@ + + + + + + + LCOV - coverage.info - unit_test/spdm_unit_test_common/common.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/spdm_unit_test_common - common.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:767798.7 %
Date:2024-09-22 08:21:07Functions:1010100.0 %
Branches:213658.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_force_error12
libspdm_get_test_context5125
libspdm_release_error12
libspdm_setup_test_context75
libspdm_unit_test_group_setup89
libspdm_unit_test_group_teardown76
spdm_device_acquire_receiver_buffer2481
spdm_device_acquire_sender_buffer2522
spdm_device_release_receiver_buffer2475
spdm_device_release_sender_buffer2516
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/spdm_unit_test_common/common.c.gcov.html b/coverage_log/unit_test/spdm_unit_test_common/common.c.gcov.html new file mode 100644 index 00000000000..9b293e60e2a --- /dev/null +++ b/coverage_log/unit_test/spdm_unit_test_common/common.c.gcov.html @@ -0,0 +1,256 @@ + + + + + + + LCOV - coverage.info - unit_test/spdm_unit_test_common/common.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/spdm_unit_test_common - common.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:767798.7 %
Date:2024-09-22 08:21:07Functions:1010100.0 %
Branches:213658.3 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : 
+       9                 :            : static libspdm_test_context_t *m_spdm_test_context;
+      10                 :            : 
+      11                 :            : static uint8_t m_send_receive_buffer[LIBSPDM_MAX_SENDER_RECEIVER_BUFFER_SIZE];
+      12                 :            : 
+      13                 :            : static bool m_sender_buffer_acquired = false;
+      14                 :            : static bool m_receiver_buffer_acquired = false;
+      15                 :            : 
+      16                 :            : static bool m_error_acquire_sender_buffer = false;
+      17                 :            : static bool m_error_acquire_receiver_buffer = false;
+      18                 :            : 
+      19                 :            : #if (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP) && \
+      20                 :            :     (LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT)
+      21                 :            : static uint8_t m_cert_chain_buffer[SPDM_MAX_CERTIFICATE_CHAIN_SIZE];
+      22                 :            : #endif
+      23                 :            : 
+      24                 :       2522 : libspdm_return_t spdm_device_acquire_sender_buffer (
+      25                 :            :     void *context, void **msg_buf_ptr)
+      26                 :            : {
+      27   [ +  -  -  + ]:       2522 :     LIBSPDM_ASSERT (!m_sender_buffer_acquired && !m_receiver_buffer_acquired);
+      28         [ +  + ]:       2522 :     if (m_error_acquire_sender_buffer) {
+      29                 :          6 :         return LIBSPDM_STATUS_ACQUIRE_FAIL;
+      30                 :            :     } else {
+      31                 :       2516 :         *msg_buf_ptr = m_send_receive_buffer;
+      32                 :       2516 :         libspdm_zero_mem (m_send_receive_buffer, sizeof(m_send_receive_buffer));
+      33                 :       2516 :         m_sender_buffer_acquired = true;
+      34                 :            : 
+      35                 :       2516 :         return LIBSPDM_STATUS_SUCCESS;
+      36                 :            :     }
+      37                 :            : }
+      38                 :            : 
+      39                 :       2516 : void spdm_device_release_sender_buffer (void *context, const void *msg_buf_ptr)
+      40                 :            : {
+      41   [ +  -  -  + ]:       2516 :     LIBSPDM_ASSERT (m_sender_buffer_acquired && !m_receiver_buffer_acquired);
+      42         [ -  + ]:       2516 :     LIBSPDM_ASSERT (msg_buf_ptr == m_send_receive_buffer);
+      43                 :            : 
+      44                 :       2516 :     m_sender_buffer_acquired = false;
+      45                 :       2516 : }
+      46                 :            : 
+      47                 :       2481 : libspdm_return_t spdm_device_acquire_receiver_buffer (
+      48                 :            :     void *context, void **msg_buf_ptr)
+      49                 :            : {
+      50   [ +  -  -  + ]:       2481 :     LIBSPDM_ASSERT (!m_sender_buffer_acquired && !m_receiver_buffer_acquired);
+      51                 :            : 
+      52         [ +  + ]:       2481 :     if (m_error_acquire_receiver_buffer) {
+      53                 :          6 :         return LIBSPDM_STATUS_ACQUIRE_FAIL;
+      54                 :            :     } else {
+      55                 :       2475 :         *msg_buf_ptr = m_send_receive_buffer;
+      56                 :       2475 :         libspdm_zero_mem (m_send_receive_buffer, sizeof(m_send_receive_buffer));
+      57                 :       2475 :         m_receiver_buffer_acquired = true;
+      58                 :            : 
+      59                 :       2475 :         return LIBSPDM_STATUS_SUCCESS;
+      60                 :            :     }
+      61                 :            : }
+      62                 :            : 
+      63                 :       2475 : void spdm_device_release_receiver_buffer (void *context, const void *msg_buf_ptr)
+      64                 :            : {
+      65   [ +  -  -  + ]:       2475 :     LIBSPDM_ASSERT (!m_sender_buffer_acquired && m_receiver_buffer_acquired);
+      66         [ -  + ]:       2475 :     LIBSPDM_ASSERT (msg_buf_ptr == m_send_receive_buffer);
+      67                 :            : 
+      68                 :       2475 :     m_receiver_buffer_acquired = false;
+      69                 :       2475 : }
+      70                 :            : 
+      71                 :       5125 : libspdm_test_context_t *libspdm_get_test_context(void)
+      72                 :            : {
+      73                 :       5125 :     return m_spdm_test_context;
+      74                 :            : }
+      75                 :            : 
+      76                 :         75 : void libspdm_setup_test_context(libspdm_test_context_t *spdm_test_context)
+      77                 :            : {
+      78                 :         75 :     m_spdm_test_context = spdm_test_context;
+      79                 :         75 : }
+      80                 :            : 
+      81                 :         89 : int libspdm_unit_test_group_setup(void **state)
+      82                 :            : {
+      83                 :            :     libspdm_test_context_t *spdm_test_context;
+      84                 :            :     void *spdm_context;
+      85                 :            : 
+      86                 :         89 :     spdm_test_context = m_spdm_test_context;
+      87                 :         89 :     spdm_test_context->spdm_context = (void *)malloc(libspdm_get_context_size());
+      88         [ -  + ]:         89 :     if (spdm_test_context->spdm_context == NULL) {
+      89                 :          0 :         return -1;
+      90                 :            :     }
+      91                 :         89 :     spdm_context = spdm_test_context->spdm_context;
+      92                 :         89 :     spdm_test_context->case_id = 0xFFFFFFFF;
+      93                 :            : 
+      94                 :         89 :     libspdm_init_context(spdm_context);
+      95                 :            : 
+      96                 :         89 :     libspdm_register_device_io_func(spdm_context,
+      97                 :            :                                     spdm_test_context->send_message,
+      98                 :            :                                     spdm_test_context->receive_message);
+      99                 :         89 :     libspdm_register_transport_layer_func(spdm_context,
+     100                 :            :                                           LIBSPDM_MAX_SPDM_MSG_SIZE,
+     101                 :            :                                           LIBSPDM_TEST_TRANSPORT_HEADER_SIZE,
+     102                 :            :                                           LIBSPDM_TEST_TRANSPORT_TAIL_SIZE,
+     103                 :            :                                           libspdm_transport_test_encode_message,
+     104                 :            :                                           libspdm_transport_test_decode_message);
+     105                 :         89 :     libspdm_register_device_buffer_func(spdm_context,
+     106                 :            :                                         LIBSPDM_MAX_SENDER_RECEIVER_BUFFER_SIZE,
+     107                 :            :                                         LIBSPDM_MAX_SENDER_RECEIVER_BUFFER_SIZE,
+     108                 :            :                                         spdm_device_acquire_sender_buffer,
+     109                 :            :                                         spdm_device_release_sender_buffer,
+     110                 :            :                                         spdm_device_acquire_receiver_buffer,
+     111                 :            :                                         spdm_device_release_receiver_buffer);
+     112                 :            : 
+     113                 :         89 :     spdm_test_context->scratch_buffer_size =
+     114                 :         89 :         libspdm_get_sizeof_required_scratch_buffer(spdm_context);
+     115                 :         89 :     spdm_test_context->scratch_buffer = (void *)malloc(spdm_test_context->scratch_buffer_size);
+     116                 :         89 :     libspdm_set_scratch_buffer (spdm_context,
+     117                 :            :                                 spdm_test_context->scratch_buffer,
+     118                 :            :                                 spdm_test_context->scratch_buffer_size);
+     119                 :            : 
+     120                 :         89 :     m_error_acquire_sender_buffer = false;
+     121                 :         89 :     m_error_acquire_receiver_buffer = false;
+     122                 :            : 
+     123                 :            :     #if (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP) && \
+     124                 :            :     (LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT)
+     125                 :         89 :     libspdm_register_cert_chain_buffer(
+     126                 :            :         spdm_context, m_cert_chain_buffer, sizeof(m_cert_chain_buffer));
+     127                 :            :     #endif /* (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (...) */
+     128                 :            : 
+     129                 :         89 :     *state = spdm_test_context;
+     130                 :            : 
+     131                 :         89 :     return 0;
+     132                 :            : }
+     133                 :            : 
+     134                 :         76 : int libspdm_unit_test_group_teardown(void **state)
+     135                 :            : {
+     136                 :            :     libspdm_test_context_t *spdm_test_context;
+     137                 :            : 
+     138   [ +  -  -  + ]:         76 :     LIBSPDM_ASSERT (!m_sender_buffer_acquired && !m_receiver_buffer_acquired);
+     139                 :            : 
+     140                 :         76 :     spdm_test_context = *state;
+     141                 :         76 :     free(spdm_test_context->spdm_context);
+     142                 :         76 :     free(spdm_test_context->scratch_buffer);
+     143                 :         76 :     spdm_test_context->spdm_context = NULL;
+     144                 :         76 :     spdm_test_context->case_id = 0xFFFFFFFF;
+     145                 :            : 
+     146                 :         76 :     return 0;
+     147                 :            : }
+     148                 :            : 
+     149                 :         12 : void libspdm_force_error (libspdm_error_target_t target)
+     150                 :            : {
+     151      [ +  +  - ]:         12 :     switch (target) {
+     152                 :          6 :     case LIBSPDM_ERR_ACQUIRE_SENDER_BUFFER:
+     153                 :          6 :         m_error_acquire_sender_buffer = true;
+     154                 :          6 :         break;
+     155                 :          6 :     case LIBSPDM_ERR_ACQUIRE_RECEIVER_BUFFER:
+     156                 :          6 :         m_error_acquire_receiver_buffer = true;
+     157                 :          6 :         break;
+     158                 :            :     }
+     159                 :         12 : }
+     160                 :            : 
+     161                 :         12 : void libspdm_release_error (libspdm_error_target_t target)
+     162                 :            : {
+     163      [ +  +  - ]:         12 :     switch (target) {
+     164                 :          6 :     case LIBSPDM_ERR_ACQUIRE_SENDER_BUFFER:
+     165                 :          6 :         m_error_acquire_sender_buffer = false;
+     166                 :          6 :         break;
+     167                 :          6 :     case LIBSPDM_ERR_ACQUIRE_RECEIVER_BUFFER:
+     168                 :          6 :         m_error_acquire_receiver_buffer = false;
+     169                 :          6 :         break;
+     170                 :            :     }
+     171                 :         12 : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/spdm_unit_test_common/event_support.c.func-sort-c.html b/coverage_log/unit_test/spdm_unit_test_common/event_support.c.func-sort-c.html new file mode 100644 index 00000000000..5855688c7b1 --- /dev/null +++ b/coverage_log/unit_test/spdm_unit_test_common/event_support.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - unit_test/spdm_unit_test_common/event_support.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/spdm_unit_test_common - event_support.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:4242100.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:222684.6 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
generate_dmtf_event_group5
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/spdm_unit_test_common/event_support.c.func.html b/coverage_log/unit_test/spdm_unit_test_common/event_support.c.func.html new file mode 100644 index 00000000000..524f4bdba9f --- /dev/null +++ b/coverage_log/unit_test/spdm_unit_test_common/event_support.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - unit_test/spdm_unit_test_common/event_support.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/spdm_unit_test_common - event_support.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:4242100.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:222684.6 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
generate_dmtf_event_group5
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/spdm_unit_test_common/event_support.c.gcov.html b/coverage_log/unit_test/spdm_unit_test_common/event_support.c.gcov.html new file mode 100644 index 00000000000..5a34d7b36d0 --- /dev/null +++ b/coverage_log/unit_test/spdm_unit_test_common/event_support.c.gcov.html @@ -0,0 +1,186 @@ + + + + + + + LCOV - coverage.info - unit_test/spdm_unit_test_common/event_support.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/spdm_unit_test_common - event_support.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:4242100.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:222684.6 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : 
+       9                 :            : #pragma pack(1)
+      10                 :            : typedef struct {
+      11                 :            :     uint8_t id;
+      12                 :            :     uint8_t vendor_id_len;
+      13                 :            : } event_group_id_0byte_t;
+      14                 :            : 
+      15                 :            : typedef struct {
+      16                 :            :     uint8_t id;
+      17                 :            :     uint8_t vendor_id_len;
+      18                 :            :     uint16_t vendor_id;
+      19                 :            : } event_group_id_2byte_t;
+      20                 :            : 
+      21                 :            : typedef struct {
+      22                 :            :     uint16_t event_type_count;
+      23                 :            :     uint16_t event_group_ver;
+      24                 :            :     uint32_t attributes;
+      25                 :            :     /* uint8_t event_type_list[] */
+      26                 :            : } event_group_t;
+      27                 :            : 
+      28                 :            : typedef struct {
+      29                 :            :     uint16_t event_type_id;
+      30                 :            :     uint16_t reserved;
+      31                 :            : } event_type_t;
+      32                 :            : #pragma pack()
+      33                 :            : 
+      34                 :          5 : void generate_dmtf_event_group(void *buffer, uint8_t *total_bytes, uint32_t attributes,
+      35                 :            :                                bool inc_event_lost, bool inc_meas_changed,
+      36                 :            :                                bool inc_meas_pre_update, bool inc_cert_changed)
+      37                 :            : {
+      38                 :            :     uint8_t *ptr;
+      39                 :            :     uint16_t event_type_count;
+      40                 :            : 
+      41   [ +  +  +  -  :          5 :     LIBSPDM_ASSERT(!(attributes & SPDM_SUBSCRIBE_EVENT_TYPES_REQUEST_ATTRIBUTE_ALL) ||
+          +  -  +  -  -  
+                      + ]
+      42                 :            :                    (!inc_event_lost && !inc_meas_changed &&
+      43                 :            :                     !inc_meas_pre_update && !inc_cert_changed));
+      44                 :            : 
+      45                 :          5 :     event_type_count = 0;
+      46                 :            : 
+      47         [ +  + ]:          5 :     if (inc_event_lost) {
+      48                 :          4 :         event_type_count++;
+      49                 :            :     }
+      50         [ +  + ]:          5 :     if (inc_meas_changed) {
+      51                 :          4 :         event_type_count++;
+      52                 :            :     }
+      53         [ +  + ]:          5 :     if (inc_meas_pre_update) {
+      54                 :          2 :         event_type_count++;
+      55                 :            :     }
+      56         [ +  + ]:          5 :     if (inc_cert_changed) {
+      57                 :          2 :         event_type_count++;
+      58                 :            :     }
+      59                 :            : 
+      60                 :          5 :     ptr = buffer;
+      61                 :          5 :     *total_bytes = 0;
+      62                 :            : 
+      63                 :          5 :     ((event_group_id_0byte_t *)ptr)->id = SPDM_REGISTRY_ID_DMTF;
+      64                 :          5 :     ((event_group_id_0byte_t *)ptr)->vendor_id_len = 0;
+      65                 :            : 
+      66                 :          5 :     ptr += sizeof(event_group_id_0byte_t);
+      67                 :          5 :     *total_bytes += (uint8_t)sizeof(event_group_id_0byte_t);
+      68                 :            : 
+      69                 :          5 :     ((event_group_t *)ptr)->event_type_count = event_type_count;
+      70                 :          5 :     ((event_group_t *)ptr)->event_group_ver = 1;
+      71                 :          5 :     ((event_group_t *)ptr)->attributes = attributes;
+      72                 :            : 
+      73                 :          5 :     ptr += sizeof(event_group_t);
+      74                 :          5 :     *total_bytes += (uint8_t)sizeof(event_group_t);
+      75                 :            : 
+      76         [ +  + ]:          5 :     if (inc_event_lost) {
+      77                 :          4 :         ((event_type_t *)ptr)->event_type_id = SPDM_DMTF_EVENT_TYPE_EVENT_LOST;
+      78                 :          4 :         ((event_type_t *)ptr)->reserved = 0;
+      79                 :          4 :         ptr += sizeof(event_type_t);
+      80                 :          4 :         *total_bytes += (uint8_t)sizeof(event_type_t);
+      81                 :            :     }
+      82         [ +  + ]:          5 :     if (inc_meas_changed) {
+      83                 :          4 :         ((event_type_t *)ptr)->event_type_id = SPDM_DMTF_EVENT_TYPE_MEASUREMENT_CHANGED;
+      84                 :          4 :         ((event_type_t *)ptr)->reserved = 0;
+      85                 :          4 :         ptr += sizeof(event_type_t);
+      86                 :          4 :         *total_bytes += (uint8_t)sizeof(event_type_t);
+      87                 :            :     }
+      88         [ +  + ]:          5 :     if (inc_meas_pre_update) {
+      89                 :          2 :         ((event_type_t *)ptr)->event_type_id = SPDM_DMTF_EVENT_TYPE_MEASUREMENT_PRE_UPDATE;
+      90                 :          2 :         ((event_type_t *)ptr)->reserved = 0;
+      91                 :          2 :         ptr += sizeof(event_type_t);
+      92                 :          2 :         *total_bytes += (uint8_t)sizeof(event_type_t);
+      93                 :            :     }
+      94         [ +  + ]:          5 :     if (inc_cert_changed) {
+      95                 :          2 :         ((event_type_t *)ptr)->event_type_id = SPDM_DMTF_EVENT_TYPE_CERTIFICATE_CHANGED;
+      96                 :          2 :         ((event_type_t *)ptr)->reserved = 0;
+      97                 :          2 :         *total_bytes += (uint8_t)sizeof(event_type_t);
+      98                 :            :     }
+      99                 :          5 : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/spdm_unit_test_common/index-sort-b.html b/coverage_log/unit_test/spdm_unit_test_common/index-sort-b.html new file mode 100644 index 00000000000..4d12a8bd72d --- /dev/null +++ b/coverage_log/unit_test/spdm_unit_test_common/index-sort-b.html @@ -0,0 +1,131 @@ + + + + + + + LCOV - coverage.info - unit_test/spdm_unit_test_common + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/spdm_unit_test_commonHitTotalCoverage
Test:coverage.infoLines:15917789.8 %
Date:2024-09-22 08:21:07Functions:1616100.0 %
Branches:598470.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
common.c +
98.7%98.7%
+
98.7 %76 / 77100.0 %10 / 1058.3 %21 / 36
support.c +
70.7%70.7%
+
70.7 %41 / 58100.0 %5 / 572.7 %16 / 22
event_support.c +
100.0%
+
100.0 %42 / 42100.0 %1 / 184.6 %22 / 26
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/spdm_unit_test_common/index-sort-f.html b/coverage_log/unit_test/spdm_unit_test_common/index-sort-f.html new file mode 100644 index 00000000000..b8150f54fdb --- /dev/null +++ b/coverage_log/unit_test/spdm_unit_test_common/index-sort-f.html @@ -0,0 +1,131 @@ + + + + + + + LCOV - coverage.info - unit_test/spdm_unit_test_common + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/spdm_unit_test_commonHitTotalCoverage
Test:coverage.infoLines:15917789.8 %
Date:2024-09-22 08:21:07Functions:1616100.0 %
Branches:598470.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
event_support.c +
100.0%
+
100.0 %42 / 42100.0 %1 / 184.6 %22 / 26
support.c +
70.7%70.7%
+
70.7 %41 / 58100.0 %5 / 572.7 %16 / 22
common.c +
98.7%98.7%
+
98.7 %76 / 77100.0 %10 / 1058.3 %21 / 36
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/spdm_unit_test_common/index-sort-l.html b/coverage_log/unit_test/spdm_unit_test_common/index-sort-l.html new file mode 100644 index 00000000000..fa68d41134a --- /dev/null +++ b/coverage_log/unit_test/spdm_unit_test_common/index-sort-l.html @@ -0,0 +1,131 @@ + + + + + + + LCOV - coverage.info - unit_test/spdm_unit_test_common + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/spdm_unit_test_commonHitTotalCoverage
Test:coverage.infoLines:15917789.8 %
Date:2024-09-22 08:21:07Functions:1616100.0 %
Branches:598470.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
support.c +
70.7%70.7%
+
70.7 %41 / 58100.0 %5 / 572.7 %16 / 22
common.c +
98.7%98.7%
+
98.7 %76 / 77100.0 %10 / 1058.3 %21 / 36
event_support.c +
100.0%
+
100.0 %42 / 42100.0 %1 / 184.6 %22 / 26
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/spdm_unit_test_common/index.html b/coverage_log/unit_test/spdm_unit_test_common/index.html new file mode 100644 index 00000000000..c22bca3cd52 --- /dev/null +++ b/coverage_log/unit_test/spdm_unit_test_common/index.html @@ -0,0 +1,131 @@ + + + + + + + LCOV - coverage.info - unit_test/spdm_unit_test_common + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/spdm_unit_test_commonHitTotalCoverage
Test:coverage.infoLines:15917789.8 %
Date:2024-09-22 08:21:07Functions:1616100.0 %
Branches:598470.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
common.c +
98.7%98.7%
+
98.7 %76 / 77100.0 %10 / 1058.3 %21 / 36
event_support.c +
100.0%
+
100.0 %42 / 42100.0 %1 / 184.6 %22 / 26
support.c +
70.7%70.7%
+
70.7 %41 / 58100.0 %5 / 572.7 %16 / 22
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/spdm_unit_test_common/support.c.func-sort-c.html b/coverage_log/unit_test/spdm_unit_test_common/support.c.func-sort-c.html new file mode 100644 index 00000000000..093ec5eca98 --- /dev/null +++ b/coverage_log/unit_test/spdm_unit_test_common/support.c.func-sort-c.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - unit_test/spdm_unit_test_common/support.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/spdm_unit_test_common - support.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:415870.7 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:162272.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_write_output_file66
libspdm_dump_hex_str71
libspdm_dump_hex150
libspdm_read_input_file1043
libspdm_dump_data1510
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/spdm_unit_test_common/support.c.func.html b/coverage_log/unit_test/spdm_unit_test_common/support.c.func.html new file mode 100644 index 00000000000..b5dbaccdf33 --- /dev/null +++ b/coverage_log/unit_test/spdm_unit_test_common/support.c.func.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - unit_test/spdm_unit_test_common/support.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/spdm_unit_test_common - support.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:415870.7 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:162272.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_dump_data1510
libspdm_dump_hex150
libspdm_dump_hex_str71
libspdm_read_input_file1043
libspdm_write_output_file66
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/spdm_unit_test_common/support.c.gcov.html b/coverage_log/unit_test/spdm_unit_test_common/support.c.gcov.html new file mode 100644 index 00000000000..2f695139eec --- /dev/null +++ b/coverage_log/unit_test/spdm_unit_test_common/support.c.gcov.html @@ -0,0 +1,245 @@ + + + + + + + LCOV - coverage.info - unit_test/spdm_unit_test_common/support.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/spdm_unit_test_common - support.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:415870.7 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:162272.7 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : 
+       9                 :            : #if !(defined(_WIN32) || (defined(__clang__) && (defined (LIBSPDM_CPU_AARCH64) || \
+      10                 :            :     defined(LIBSPDM_CPU_ARM))))
+      11                 :            :     #include <fcntl.h>
+      12                 :            :     #include <unistd.h>
+      13                 :            :     #include <sys/stat.h>
+      14                 :            : #endif
+      15                 :            : 
+      16                 :         71 : void libspdm_dump_hex_str(const uint8_t *buffer, size_t buffer_size)
+      17                 :            : {
+      18                 :            :     size_t index;
+      19                 :            : 
+      20         [ +  + ]:        923 :     for (index = 0; index < buffer_size; index++) {
+      21                 :        852 :         printf("%02x", buffer[index]);
+      22                 :            :     }
+      23                 :         71 : }
+      24                 :            : 
+      25                 :       1510 : void libspdm_dump_data(const uint8_t *buffer, size_t buffer_size)
+      26                 :            : {
+      27                 :            :     size_t index;
+      28                 :            : 
+      29         [ +  + ]:      47287 :     for (index = 0; index < buffer_size; index++) {
+      30                 :      45777 :         printf("%02x ", buffer[index]);
+      31                 :            :     }
+      32                 :       1510 : }
+      33                 :            : 
+      34                 :        150 : void libspdm_dump_hex(const uint8_t *data, size_t size)
+      35                 :            : {
+      36                 :            :     size_t index;
+      37                 :            :     size_t count;
+      38                 :            :     size_t left;
+      39                 :            : 
+      40                 :            : #define COLUME_SIZE (16 * 2)
+      41                 :            : 
+      42                 :        150 :     count = size / COLUME_SIZE;
+      43                 :        150 :     left = size % COLUME_SIZE;
+      44         [ +  + ]:       1512 :     for (index = 0; index < count; index++) {
+      45                 :       1362 :         printf("%04x: ", (uint32_t)(index * COLUME_SIZE));
+      46                 :       1362 :         libspdm_dump_data(data + index * COLUME_SIZE, COLUME_SIZE);
+      47                 :       1362 :         printf("\n");
+      48                 :            :     }
+      49                 :            : 
+      50         [ +  + ]:        150 :     if (left != 0) {
+      51                 :        147 :         printf("%04x: ", (uint32_t)(index * COLUME_SIZE));
+      52                 :        147 :         libspdm_dump_data(data + index * COLUME_SIZE, left);
+      53                 :        147 :         printf("\n");
+      54                 :            :     }
+      55                 :        150 : }
+      56                 :            : 
+      57                 :       1043 : bool libspdm_read_input_file(const char *file_name, void **file_data,
+      58                 :            :                              size_t *file_size)
+      59                 :            : {
+      60                 :            : #if defined(_WIN32) || (defined(__clang__) && (defined (LIBSPDM_CPU_AARCH64) || \
+      61                 :            :     defined(LIBSPDM_CPU_ARM)))
+      62                 :            :     FILE *fp_in;
+      63                 :            :     size_t temp_result;
+      64                 :            : #else
+      65                 :            :     int32_t temp_result;
+      66                 :            :     int64_t fp_in;
+      67                 :            : #endif
+      68                 :            : 
+      69                 :            : #if defined(_WIN32) || (defined(__clang__) && (defined (LIBSPDM_CPU_AARCH64) || \
+      70                 :            :     defined(LIBSPDM_CPU_ARM)))
+      71                 :            :     if ((fp_in = fopen(file_name, "rb")) == NULL) {
+      72                 :            :         printf("Unable to open file %s\n", file_name);
+      73                 :            :         *file_data = NULL;
+      74                 :            :         return false;
+      75                 :            :     }
+      76                 :            : 
+      77                 :            :     fseek(fp_in, 0, SEEK_END);
+      78                 :            :     *file_size = ftell(fp_in);
+      79                 :            : 
+      80                 :            :     *file_data = (void *)malloc(*file_size);
+      81                 :            :     if (NULL == *file_data) {
+      82                 :            :         printf("No sufficient memory to allocate %s\n", file_name);
+      83                 :            :         fclose(fp_in);
+      84                 :            :         return false;
+      85                 :            :     }
+      86                 :            : 
+      87                 :            :     fseek(fp_in, 0, SEEK_SET);
+      88                 :            :     temp_result = fread(*file_data, 1, *file_size, fp_in);
+      89                 :            :     if (temp_result != *file_size) {
+      90                 :            :         printf("Read input file error %s", file_name);
+      91                 :            :         free((void *)*file_data);
+      92                 :            :         fclose(fp_in);
+      93                 :            :         return false;
+      94                 :            :     }
+      95                 :            : 
+      96                 :            :     fclose(fp_in);
+      97                 :            : 
+      98                 :            : #else
+      99                 :       1043 :     fp_in = open(file_name, O_RDONLY, S_IRWXU);
+     100         [ +  + ]:       1043 :     if (fp_in == -1) {
+     101                 :         28 :         printf("Unable to open file %s\n", file_name);
+     102                 :         28 :         *file_data = NULL;
+     103                 :         28 :         return false;
+     104                 :            :     }
+     105                 :            : 
+     106                 :       1015 :     temp_result = lseek(fp_in, 0, SEEK_END);
+     107         [ -  + ]:       1015 :     if (temp_result == -1) {
+     108                 :          0 :         printf("Unable to open file %s\n", file_name);
+     109                 :          0 :         *file_data = NULL;
+     110                 :          0 :         return false;
+     111                 :            :     } else {
+     112                 :       1015 :         *file_size = (size_t)temp_result;
+     113                 :            :     }
+     114                 :            : 
+     115                 :       1015 :     *file_data = (void *)malloc(*file_size);
+     116         [ -  + ]:       1015 :     if (NULL == *file_data) {
+     117                 :          0 :         printf("No sufficient memory to allocate %s\n", file_name);
+     118                 :          0 :         close(fp_in);
+     119                 :          0 :         return false;
+     120                 :            :     }
+     121                 :            : 
+     122         [ -  + ]:       1015 :     if (lseek(fp_in, 0, SEEK_SET) == -1) {
+     123                 :          0 :         close(fp_in);
+     124                 :          0 :         return false;
+     125                 :            :     }
+     126                 :            : 
+     127                 :       1015 :     temp_result = read(fp_in, *file_data, *file_size);
+     128         [ -  + ]:       1015 :     if (temp_result != *file_size) {
+     129                 :          0 :         printf("Read input file error %s", file_name);
+     130                 :          0 :         free((void *)*file_data);
+     131                 :          0 :         close(fp_in);
+     132                 :          0 :         return false;
+     133                 :            :     }
+     134                 :            : 
+     135                 :       1015 :     close(fp_in);
+     136                 :            : #endif
+     137                 :            : 
+     138                 :       1015 :     return true;
+     139                 :            : }
+     140                 :            : 
+     141                 :         66 : bool libspdm_write_output_file(const char *file_name, const void *file_data,
+     142                 :            :                                size_t file_size)
+     143                 :            : {
+     144                 :            :     FILE *fp_out;
+     145                 :            : 
+     146         [ -  + ]:         66 :     if ((fp_out = fopen(file_name, "w+b")) == NULL) {
+     147                 :          0 :         printf("Unable to open file %s\n", file_name);
+     148                 :          0 :         return false;
+     149                 :            :     }
+     150                 :            : 
+     151         [ -  + ]:         66 :     if ((fwrite(file_data, 1, file_size, fp_out)) != file_size) {
+     152                 :          0 :         printf("Write output file error %s\n", file_name);
+     153                 :          0 :         fclose(fp_out);
+     154                 :          0 :         return false;
+     155                 :            :     }
+     156                 :            : 
+     157                 :         66 :     fclose(fp_out);
+     158                 :            : 
+     159                 :         66 :     return true;
+     160                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_common/context_data.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_common/context_data.c.func-sort-c.html new file mode 100644 index 00000000000..b2e3116e576 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_common/context_data.c.func-sort-c.html @@ -0,0 +1,189 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_common/context_data.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_common - context_data.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:60962397.8 %
Date:2024-09-22 08:21:07Functions:2727100.0 %
Branches:869392.5 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_common_context_data_test_main1
libspdm_test_check_context_case201
libspdm_test_common_context_data_case11
libspdm_test_common_context_data_case21
libspdm_test_common_context_data_case31
libspdm_test_common_context_data_case41
libspdm_test_export_master_secret_case191
libspdm_test_max_session_count_case211
libspdm_test_process_opaque_data_selection_version_data_case141
libspdm_test_process_opaque_data_selection_version_data_case151
libspdm_test_process_opaque_data_selection_version_data_case161
libspdm_test_process_opaque_data_selection_version_data_case171
libspdm_test_process_opaque_data_supported_version_data_case101
libspdm_test_process_opaque_data_supported_version_data_case111
libspdm_test_process_opaque_data_supported_version_data_case121
libspdm_test_process_opaque_data_supported_version_data_case131
libspdm_test_secured_message_context_location_selection_case181
libspdm_test_set_data_case91
libspdm_test_verify_peer_cert_chain_buffer_case51
libspdm_test_verify_peer_cert_chain_buffer_case61
libspdm_test_verify_peer_cert_chain_buffer_case71
libspdm_test_verify_peer_cert_chain_buffer_case81
libspdm_build_multi_element_opaque_data_supported_version_test4
libspdm_build_opaque_data_version_selection_data_test4
libspdm_get_multi_element_opaque_data_version_selection_data_size8
libspdm_verify_peer_cert_chain_buffer9
libspdm_get_multi_element_opaque_data_supported_version_data_size36
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_common/context_data.c.func.html b/coverage_log/unit_test/test_spdm_common/context_data.c.func.html new file mode 100644 index 00000000000..cbadce1ebad --- /dev/null +++ b/coverage_log/unit_test/test_spdm_common/context_data.c.func.html @@ -0,0 +1,189 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_common/context_data.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_common - context_data.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:60962397.8 %
Date:2024-09-22 08:21:07Functions:2727100.0 %
Branches:869392.5 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_build_multi_element_opaque_data_supported_version_test4
libspdm_build_opaque_data_version_selection_data_test4
libspdm_common_context_data_test_main1
libspdm_get_multi_element_opaque_data_supported_version_data_size36
libspdm_get_multi_element_opaque_data_version_selection_data_size8
libspdm_test_check_context_case201
libspdm_test_common_context_data_case11
libspdm_test_common_context_data_case21
libspdm_test_common_context_data_case31
libspdm_test_common_context_data_case41
libspdm_test_export_master_secret_case191
libspdm_test_max_session_count_case211
libspdm_test_process_opaque_data_selection_version_data_case141
libspdm_test_process_opaque_data_selection_version_data_case151
libspdm_test_process_opaque_data_selection_version_data_case161
libspdm_test_process_opaque_data_selection_version_data_case171
libspdm_test_process_opaque_data_supported_version_data_case101
libspdm_test_process_opaque_data_supported_version_data_case111
libspdm_test_process_opaque_data_supported_version_data_case121
libspdm_test_process_opaque_data_supported_version_data_case131
libspdm_test_secured_message_context_location_selection_case181
libspdm_test_set_data_case91
libspdm_test_verify_peer_cert_chain_buffer_case51
libspdm_test_verify_peer_cert_chain_buffer_case61
libspdm_test_verify_peer_cert_chain_buffer_case71
libspdm_test_verify_peer_cert_chain_buffer_case81
libspdm_verify_peer_cert_chain_buffer9
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_common/context_data.c.gcov.html b/coverage_log/unit_test/test_spdm_common/context_data.c.gcov.html new file mode 100644 index 00000000000..32e266cd921 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_common/context_data.c.gcov.html @@ -0,0 +1,1686 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_common/context_data.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_common - context_data.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:60962397.8 %
Date:2024-09-22 08:21:07Functions:2727100.0 %
Branches:869392.5 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_requester_lib.h"
+       9                 :            : #include "internal/libspdm_responder_lib.h"
+      10                 :            : #include "internal/libspdm_secured_message_lib.h"
+      11                 :            : 
+      12                 :            : libspdm_return_t spdm_device_acquire_sender_buffer (
+      13                 :            :     void *context, void **msg_buf_ptr);
+      14                 :            : 
+      15                 :            : void spdm_device_release_sender_buffer (void *context, const void *msg_buf_ptr);
+      16                 :            : 
+      17                 :            : libspdm_return_t spdm_device_acquire_receiver_buffer (
+      18                 :            :     void *context, void **msg_buf_ptr);
+      19                 :            : 
+      20                 :            : void spdm_device_release_receiver_buffer (void *context, const void *msg_buf_ptr);
+      21                 :            : 
+      22                 :            : static uint32_t libspdm_opaque_data = 0xDEADBEEF;
+      23                 :            : 
+      24                 :            : /**
+      25                 :            :  * This function verifies peer certificate chain buffer including spdm_cert_chain_t header.
+      26                 :            :  *
+      27                 :            :  * @param  spdm_context            A pointer to the SPDM context.
+      28                 :            :  * @param  cert_chain_buffer       Certificate chain buffer including spdm_cert_chain_t header.
+      29                 :            :  * @param  cert_chain_buffer_size  Size in bytes of the certificate chain buffer.
+      30                 :            :  * @param  trust_anchor            A buffer to hold the trust_anchor which is used to validate the
+      31                 :            :  *                                 peer certificate, if not NULL.
+      32                 :            :  * @param  trust_anchor_size       A buffer to hold the trust_anchor_size, if not NULL.
+      33                 :            :  *
+      34                 :            :  * @retval true  Peer certificate chain buffer verification passed.
+      35                 :            :  * @retval false Peer certificate chain buffer verification failed.
+      36                 :            :  **/
+      37                 :          9 : static bool libspdm_verify_peer_cert_chain_buffer(void *spdm_context,
+      38                 :            :                                                   const void *cert_chain_buffer,
+      39                 :            :                                                   size_t cert_chain_buffer_size,
+      40                 :            :                                                   const void **trust_anchor,
+      41                 :            :                                                   size_t *trust_anchor_size)
+      42                 :            : {
+      43                 :            :     bool result;
+      44                 :            : 
+      45                 :            :     /*verify peer cert chain integrity*/
+      46                 :          9 :     result = libspdm_verify_peer_cert_chain_buffer_integrity(spdm_context, cert_chain_buffer,
+      47                 :            :                                                              cert_chain_buffer_size);
+      48         [ -  + ]:          9 :     if (!result) {
+      49                 :          0 :         return false;
+      50                 :            :     }
+      51                 :            : 
+      52                 :            :     /*verify peer cert chain authority*/
+      53                 :          9 :     result = libspdm_verify_peer_cert_chain_buffer_authority(spdm_context, cert_chain_buffer,
+      54                 :            :                                                              cert_chain_buffer_size, trust_anchor,
+      55                 :            :                                                              trust_anchor_size);
+      56         [ +  + ]:          9 :     if (!result) {
+      57                 :          3 :         return false;
+      58                 :            :     }
+      59                 :            : 
+      60                 :          6 :     return true;
+      61                 :            : }
+      62                 :            : 
+      63                 :            : /**
+      64                 :            :  * Return the size in bytes of multi element opaque data supported version.
+      65                 :            :  *
+      66                 :            :  * @param  version_count                 Secure version count.
+      67                 :            :  *
+      68                 :            :  * @return the size in bytes of opaque data supported version.
+      69                 :            :  **/
+      70                 :         36 : size_t libspdm_get_multi_element_opaque_data_supported_version_data_size(
+      71                 :            :     libspdm_context_t *spdm_context, uint8_t version_count, uint8_t element_num)
+      72                 :            : {
+      73                 :            :     size_t size;
+      74                 :            :     uint8_t element_index;
+      75                 :            : 
+      76         [ +  + ]:         36 :     if (libspdm_get_connection_version (spdm_context) >= SPDM_MESSAGE_VERSION_12) {
+      77                 :         18 :         size = sizeof(spdm_general_opaque_data_table_header_t);
+      78         [ +  + ]:         60 :         for (element_index = 0; element_index < element_num; element_index++) {
+      79                 :         42 :             size += sizeof(secured_message_opaque_element_table_header_t) +
+      80                 :            :                     sizeof(secured_message_opaque_element_supported_version_t) +
+      81                 :         42 :                     sizeof(spdm_version_number_t) * version_count;
+      82                 :            :             /* Add Padding*/
+      83                 :         42 :             size = (size + 3) & ~3;
+      84                 :            :         }
+      85                 :            :     } else {
+      86                 :         18 :         size = sizeof(secured_message_general_opaque_data_table_header_t);
+      87         [ +  + ]:         60 :         for (element_index = 0; element_index < element_num; element_index++) {
+      88                 :         42 :             size += sizeof(secured_message_opaque_element_table_header_t) +
+      89                 :            :                     sizeof(secured_message_opaque_element_supported_version_t) +
+      90                 :         42 :                     sizeof(spdm_version_number_t) * version_count;
+      91                 :            :             /* Add Padding*/
+      92                 :         42 :             size = (size + 3) & ~3;
+      93                 :            :         }
+      94                 :            :     }
+      95                 :            : 
+      96                 :         36 :     return size;
+      97                 :            : }
+      98                 :            : 
+      99                 :            : /**
+     100                 :            :  * Build opaque data supported version test.
+     101                 :            :  *
+     102                 :            :  * @param  data_out_size[in]                 size in bytes of the data_out.
+     103                 :            :  *                                           On input, it means the size in bytes of data_out buffer.
+     104                 :            :  *                                           On output, it means the size in bytes of copied data_out buffer if RETURN_SUCCESS is returned,
+     105                 :            :  *                                           and means the size in bytes of desired data_out buffer if RETURN_BUFFER_TOO_SMALL is returned.
+     106                 :            :  * @param  data_out[in]                      A pointer to the desination buffer to store the opaque data supported version.
+     107                 :            :  * @param  element_num[in]                   in this test function, the element number < 9 is right. because element id is changed with element_index
+     108                 :            :  *
+     109                 :            :  * @retval RETURN_SUCCESS               The opaque data supported version is built successfully.
+     110                 :            :  * @retval RETURN_BUFFER_TOO_SMALL      The buffer is too small to hold the data.
+     111                 :            :  **/
+     112                 :            : libspdm_return_t
+     113                 :          4 : libspdm_build_multi_element_opaque_data_supported_version_test(libspdm_context_t *spdm_context,
+     114                 :            :                                                                size_t *data_out_size,
+     115                 :            :                                                                void *data_out,
+     116                 :            :                                                                uint8_t element_num)
+     117                 :            : {
+     118                 :            :     size_t final_data_size;
+     119                 :            :     secured_message_general_opaque_data_table_header_t
+     120                 :            :     *general_opaque_data_table_header;
+     121                 :            :     spdm_general_opaque_data_table_header_t
+     122                 :            :     *spdm_general_opaque_data_table_header;
+     123                 :            :     secured_message_opaque_element_table_header_t
+     124                 :            :     *opaque_element_table_header;
+     125                 :            :     secured_message_opaque_element_supported_version_t
+     126                 :            :     *opaque_element_support_version;
+     127                 :            :     spdm_version_number_t *versions_list;
+     128                 :            :     void *end;
+     129                 :            :     uint8_t element_index;
+     130                 :            : 
+     131                 :          4 :     if (spdm_context->local_context.secured_message_version
+     132         [ -  + ]:          4 :         .spdm_version_count == 0) {
+     133                 :          0 :         *data_out_size = 0;
+     134                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     135                 :            :     }
+     136                 :            : 
+     137                 :            :     final_data_size =
+     138                 :          4 :         libspdm_get_multi_element_opaque_data_supported_version_data_size(
+     139                 :            :             spdm_context,
+     140                 :          4 :             spdm_context->local_context.secured_message_version.spdm_version_count,
+     141                 :            :             element_num);
+     142         [ -  + ]:          4 :     if (*data_out_size < final_data_size) {
+     143                 :          0 :         *data_out_size = final_data_size;
+     144                 :          0 :         return LIBSPDM_STATUS_BUFFER_TOO_SMALL;
+     145                 :            :     }
+     146                 :            : 
+     147         [ +  + ]:          4 :     if (libspdm_get_connection_version (spdm_context) >= SPDM_MESSAGE_VERSION_12) {
+     148                 :          2 :         spdm_general_opaque_data_table_header = data_out;
+     149                 :          2 :         spdm_general_opaque_data_table_header->total_elements = element_num;
+     150                 :          2 :         libspdm_write_uint24(spdm_general_opaque_data_table_header->reserved, 0);
+     151                 :          2 :         opaque_element_table_header =
+     152                 :            :             (void *)(spdm_general_opaque_data_table_header + 1);
+     153                 :            :     } else {
+     154                 :          2 :         general_opaque_data_table_header = data_out;
+     155                 :          2 :         general_opaque_data_table_header->spec_id =
+     156                 :            :             SECURED_MESSAGE_OPAQUE_DATA_SPEC_ID;
+     157                 :          2 :         general_opaque_data_table_header->opaque_version =
+     158                 :            :             SECURED_MESSAGE_OPAQUE_VERSION;
+     159                 :          2 :         general_opaque_data_table_header->total_elements = element_num;
+     160                 :          2 :         general_opaque_data_table_header->reserved = 0;
+     161                 :          2 :         opaque_element_table_header =
+     162                 :            :             (void *)(general_opaque_data_table_header + 1);
+     163                 :            :     }
+     164                 :            : 
+     165         [ +  + ]:         32 :     for (element_index = 0; element_index < element_num; element_index++) {
+     166                 :            :         /*id is changed with element_index*/
+     167                 :         28 :         opaque_element_table_header->id = element_index;
+     168                 :         28 :         opaque_element_table_header->vendor_len = 0;
+     169                 :         28 :         opaque_element_table_header->opaque_element_data_len =
+     170                 :         28 :             sizeof(secured_message_opaque_element_supported_version_t) +
+     171                 :         28 :             sizeof(spdm_version_number_t) *
+     172                 :         28 :             spdm_context->local_context.secured_message_version.spdm_version_count;
+     173                 :            : 
+     174                 :         28 :         opaque_element_support_version =
+     175                 :            :             (void *)(opaque_element_table_header + 1);
+     176                 :         28 :         opaque_element_support_version->sm_data_version =
+     177                 :            :             SECURED_MESSAGE_OPAQUE_ELEMENT_SMDATA_DATA_VERSION;
+     178                 :         28 :         opaque_element_support_version->sm_data_id =
+     179                 :            :             SECURED_MESSAGE_OPAQUE_ELEMENT_SMDATA_ID_SUPPORTED_VERSION;
+     180                 :         28 :         opaque_element_support_version->version_count =
+     181                 :         28 :             spdm_context->local_context.secured_message_version.spdm_version_count;
+     182                 :            : 
+     183                 :         28 :         versions_list = (void *)(opaque_element_support_version + 1);
+     184                 :            : 
+     185                 :         28 :         libspdm_copy_mem(versions_list,
+     186                 :         28 :                          *data_out_size - ((uint8_t*)versions_list - (uint8_t*)data_out),
+     187                 :         28 :                          spdm_context->local_context.secured_message_version.spdm_version,
+     188                 :         28 :                          spdm_context->local_context.secured_message_version.spdm_version_count *
+     189                 :            :                          sizeof(spdm_version_number_t));
+     190                 :            : 
+     191                 :            :         /*move to next element*/
+     192         [ +  + ]:         28 :         if (libspdm_get_connection_version (spdm_context) >= SPDM_MESSAGE_VERSION_12) {
+     193                 :         14 :             opaque_element_table_header =
+     194                 :            :                 (secured_message_opaque_element_table_header_t *)(
+     195                 :            :                     (uint8_t *)opaque_element_table_header +
+     196                 :         14 :                     libspdm_get_multi_element_opaque_data_supported_version_data_size(
+     197                 :            :                         spdm_context,
+     198                 :         14 :                         spdm_context->local_context.secured_message_version.spdm_version_count,
+     199                 :         14 :                         1) -
+     200                 :            :                     sizeof(spdm_general_opaque_data_table_header_t));
+     201                 :            :         } else {
+     202                 :         14 :             opaque_element_table_header =
+     203                 :            :                 (secured_message_opaque_element_table_header_t *)(
+     204                 :            :                     (uint8_t *)opaque_element_table_header +
+     205                 :         14 :                     libspdm_get_multi_element_opaque_data_supported_version_data_size(
+     206                 :            :                         spdm_context,
+     207                 :         14 :                         spdm_context->local_context.secured_message_version.spdm_version_count,
+     208                 :         14 :                         1) -
+     209                 :            :                     sizeof(secured_message_general_opaque_data_table_header_t));
+     210                 :            :         }
+     211                 :            : 
+     212                 :            :         /* Zero Padding. *data_out_size does not need to be changed, because data is 0 padded */
+     213                 :         28 :         end = versions_list +
+     214                 :         28 :               spdm_context->local_context.secured_message_version.spdm_version_count;
+     215                 :         28 :         libspdm_zero_mem(end, (size_t)data_out + final_data_size - (size_t)end);
+     216                 :            :     }
+     217                 :            : 
+     218                 :          4 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+     219                 :            :                    "successful build multi element opaque data supported version! \n"));
+     220                 :          4 :     return LIBSPDM_STATUS_SUCCESS;
+     221                 :            : }
+     222                 :            : 
+     223                 :            : /**
+     224                 :            :  * Return the size in bytes of multi element opaque data selection version.
+     225                 :            :  *
+     226                 :            :  * @param  version_count                 Secure version count.
+     227                 :            :  *
+     228                 :            :  * @return the size in bytes of opaque data selection version.
+     229                 :            :  **/
+     230                 :          8 : size_t libspdm_get_multi_element_opaque_data_version_selection_data_size(
+     231                 :            :     const libspdm_context_t *spdm_context, uint8_t element_num)
+     232                 :            : {
+     233                 :            :     size_t size;
+     234                 :            :     uint8_t element_index;
+     235                 :            : 
+     236                 :          8 :     if (spdm_context->local_context.secured_message_version
+     237         [ -  + ]:          8 :         .spdm_version_count == 0) {
+     238                 :          0 :         return 0;
+     239                 :            :     }
+     240                 :            : 
+     241         [ +  + ]:          8 :     if (libspdm_get_connection_version (spdm_context) >= SPDM_MESSAGE_VERSION_12) {
+     242                 :          4 :         size = sizeof(spdm_general_opaque_data_table_header_t);
+     243         [ +  + ]:         32 :         for (element_index = 0; element_index < element_num; element_index++) {
+     244                 :         28 :             size += sizeof(secured_message_opaque_element_table_header_t) +
+     245                 :            :                     sizeof(secured_message_opaque_element_version_selection_t);
+     246                 :            :             /* Add Padding*/
+     247                 :         28 :             size = (size + 3) & ~3;
+     248                 :            :         }
+     249                 :            :     } else {
+     250                 :          4 :         size = sizeof(secured_message_general_opaque_data_table_header_t);
+     251         [ +  + ]:         32 :         for (element_index = 0; element_index < element_num; element_index++) {
+     252                 :         28 :             size += sizeof(secured_message_opaque_element_table_header_t) +
+     253                 :            :                     sizeof(secured_message_opaque_element_version_selection_t);
+     254                 :            :             /* Add Padding*/
+     255                 :         28 :             size = (size + 3) & ~3;
+     256                 :            :         }
+     257                 :            :     }
+     258                 :            : 
+     259                 :          8 :     return size;
+     260                 :            : }
+     261                 :            : 
+     262                 :            : /**
+     263                 :            :  * Build opaque data selection version test.
+     264                 :            :  *
+     265                 :            :  * @param  data_out_size[in]                 size in bytes of the data_out.
+     266                 :            :  *                                           On input, it means the size in bytes of data_out buffer.
+     267                 :            :  *                                           On output, it means the size in bytes of copied data_out buffer if RETURN_SUCCESS is returned,
+     268                 :            :  *                                           and means the size in bytes of desired data_out buffer if RETURN_BUFFER_TOO_SMALL is returned.
+     269                 :            :  * @param  data_out[in]                      A pointer to the desination buffer to store the opaque data selection version.
+     270                 :            :  * @param  element_num[in]                   in this test function, the element number < 9 is right. because element id is changed with element_index
+     271                 :            :  *
+     272                 :            :  * @retval RETURN_SUCCESS               The opaque data selection version is built successfully.
+     273                 :            :  * @retval RETURN_BUFFER_TOO_SMALL      The buffer is too small to hold the data.
+     274                 :            :  **/
+     275                 :            : libspdm_return_t
+     276                 :          4 : libspdm_build_opaque_data_version_selection_data_test(const libspdm_context_t *spdm_context,
+     277                 :            :                                                       size_t *data_out_size,
+     278                 :            :                                                       void *data_out,
+     279                 :            :                                                       uint8_t element_num)
+     280                 :            : {
+     281                 :            :     size_t final_data_size;
+     282                 :            :     secured_message_general_opaque_data_table_header_t
+     283                 :            :     *general_opaque_data_table_header;
+     284                 :            :     spdm_general_opaque_data_table_header_t
+     285                 :            :     *spdm_general_opaque_data_table_header;
+     286                 :            :     secured_message_opaque_element_table_header_t
+     287                 :            :     *opaque_element_table_header;
+     288                 :            :     secured_message_opaque_element_version_selection_t
+     289                 :            :     *opaque_element_version_section;
+     290                 :            :     void *end;
+     291                 :            :     uint8_t element_index;
+     292                 :            :     size_t current_element_len;
+     293                 :            : 
+     294                 :          4 :     if (spdm_context->local_context.secured_message_version
+     295         [ -  + ]:          4 :         .spdm_version_count == 0) {
+     296                 :          0 :         *data_out_size = 0;
+     297                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     298                 :            :     }
+     299                 :            : 
+     300                 :            :     final_data_size =
+     301                 :          4 :         libspdm_get_multi_element_opaque_data_version_selection_data_size(spdm_context,
+     302                 :            :                                                                           element_num);
+     303         [ -  + ]:          4 :     if (*data_out_size < final_data_size) {
+     304                 :          0 :         *data_out_size = final_data_size;
+     305                 :          0 :         return LIBSPDM_STATUS_BUFFER_TOO_SMALL;
+     306                 :            :     }
+     307                 :            : 
+     308         [ +  + ]:          4 :     if (libspdm_get_connection_version (spdm_context) >= SPDM_MESSAGE_VERSION_12) {
+     309                 :          2 :         spdm_general_opaque_data_table_header = data_out;
+     310                 :          2 :         spdm_general_opaque_data_table_header->total_elements = element_num;
+     311                 :          2 :         libspdm_write_uint24(spdm_general_opaque_data_table_header->reserved, 0);
+     312                 :            : 
+     313                 :          2 :         opaque_element_table_header =
+     314                 :            :             (void *)(spdm_general_opaque_data_table_header + 1);
+     315                 :            :     } else {
+     316                 :          2 :         general_opaque_data_table_header = data_out;
+     317                 :          2 :         general_opaque_data_table_header->spec_id =
+     318                 :            :             SECURED_MESSAGE_OPAQUE_DATA_SPEC_ID;
+     319                 :          2 :         general_opaque_data_table_header->opaque_version =
+     320                 :            :             SECURED_MESSAGE_OPAQUE_VERSION;
+     321                 :          2 :         general_opaque_data_table_header->total_elements = element_num;
+     322                 :          2 :         general_opaque_data_table_header->reserved = 0;
+     323                 :            : 
+     324                 :          2 :         opaque_element_table_header =
+     325                 :            :             (void *)(general_opaque_data_table_header + 1);
+     326                 :            :     }
+     327                 :            : 
+     328         [ +  + ]:         32 :     for (element_index = 0; element_index < element_num; element_index++) {
+     329                 :            :         /*id is changed with element_index*/
+     330                 :         28 :         opaque_element_table_header->id = element_index;
+     331                 :         28 :         opaque_element_table_header->vendor_len = 0;
+     332                 :         28 :         opaque_element_table_header->opaque_element_data_len =
+     333                 :            :             sizeof(secured_message_opaque_element_version_selection_t);
+     334                 :            : 
+     335                 :         28 :         opaque_element_version_section = (void *)(opaque_element_table_header + 1);
+     336                 :         28 :         opaque_element_version_section->sm_data_version =
+     337                 :            :             SECURED_MESSAGE_OPAQUE_ELEMENT_SMDATA_DATA_VERSION;
+     338                 :         28 :         opaque_element_version_section->sm_data_id =
+     339                 :            :             SECURED_MESSAGE_OPAQUE_ELEMENT_SMDATA_ID_VERSION_SELECTION;
+     340                 :         28 :         opaque_element_version_section->selected_version =
+     341                 :         28 :             spdm_context->connection_info.secured_message_version;
+     342                 :            : 
+     343                 :            :         /*move to next element*/
+     344                 :         28 :         current_element_len = sizeof(secured_message_opaque_element_table_header_t) +
+     345                 :         28 :                               opaque_element_table_header->opaque_element_data_len;
+     346                 :            :         /* Add Padding*/
+     347                 :         28 :         current_element_len = (current_element_len + 3) & ~3;
+     348                 :            : 
+     349                 :         28 :         opaque_element_table_header =
+     350                 :            :             (secured_message_opaque_element_table_header_t *)(
+     351                 :            :                 (uint8_t *)opaque_element_table_header + current_element_len);
+     352                 :            :     }
+     353                 :            : 
+     354                 :            :     /* Zero Padding*/
+     355                 :          4 :     end = opaque_element_version_section + 1;
+     356                 :          4 :     libspdm_zero_mem(end, (size_t)data_out + final_data_size - (size_t)end);
+     357                 :            : 
+     358                 :          4 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
+     359                 :            :                    "successful build multi element opaque data selection version! \n"));
+     360                 :            : 
+     361                 :          4 :     return LIBSPDM_STATUS_SUCCESS;
+     362                 :            : }
+     363                 :            : 
+     364                 :            : 
+     365                 :            : /**
+     366                 :            :  * Test 1: Basic test - tests happy path of setting and getting opaque data from
+     367                 :            :  * context successfully.
+     368                 :            :  **/
+     369                 :          1 : static void libspdm_test_common_context_data_case1(void **state)
+     370                 :            : {
+     371                 :            :     libspdm_return_t status;
+     372                 :            :     libspdm_test_context_t *spdm_test_context;
+     373                 :            :     libspdm_context_t *spdm_context;
+     374                 :          1 :     void *data = (void *)&libspdm_opaque_data;
+     375                 :          1 :     void *return_data = NULL;
+     376                 :          1 :     size_t data_return_size = 0;
+     377                 :            : 
+     378                 :          1 :     spdm_test_context = *state;
+     379                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     380                 :          1 :     spdm_test_context->case_id = 0x1;
+     381                 :            : 
+     382                 :          1 :     status = libspdm_set_data(spdm_context, LIBSPDM_DATA_APP_CONTEXT_DATA,
+     383                 :            :                               NULL, &data, sizeof(data));
+     384                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     385                 :            : 
+     386                 :          1 :     data_return_size = sizeof(return_data);
+     387                 :          1 :     status = libspdm_get_data(spdm_context, LIBSPDM_DATA_APP_CONTEXT_DATA,
+     388                 :            :                               NULL, &return_data, &data_return_size);
+     389                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     390                 :            : 
+     391                 :          1 :     assert_memory_equal(data, return_data, sizeof(data));
+     392                 :          1 :     assert_int_equal(data_return_size, sizeof(void*));
+     393                 :            : 
+     394                 :            :     /* check that nothing changed at the data location */
+     395                 :          1 :     assert_int_equal(libspdm_opaque_data, 0xDEADBEEF);
+     396                 :          1 : }
+     397                 :            : 
+     398                 :            : /**
+     399                 :            :  * Test 2: Test failure paths of setting opaque data in context. libspdm_set_data
+     400                 :            :  * should fail when an invalid size is passed.
+     401                 :            :  **/
+     402                 :          1 : static void libspdm_test_common_context_data_case2(void **state)
+     403                 :            : {
+     404                 :            :     libspdm_return_t status;
+     405                 :            :     libspdm_test_context_t *spdm_test_context;
+     406                 :            :     libspdm_context_t *spdm_context;
+     407                 :          1 :     void *data = (void *)&libspdm_opaque_data;
+     408                 :          1 :     void *return_data = NULL;
+     409                 :          1 :     void *current_return_data = NULL;
+     410                 :          1 :     size_t data_return_size = 0;
+     411                 :            : 
+     412                 :          1 :     spdm_test_context = *state;
+     413                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     414                 :          1 :     spdm_test_context->case_id = 0x2;
+     415                 :            : 
+     416                 :            :     /**
+     417                 :            :      * Get current opaque data in context. May have been set in previous
+     418                 :            :      * tests. This will be used to compare later to ensure the value hasn't
+     419                 :            :      * changed after a failed set data.
+     420                 :            :      */
+     421                 :          1 :     data_return_size = sizeof(current_return_data);
+     422                 :          1 :     status = libspdm_get_data(spdm_context, LIBSPDM_DATA_APP_CONTEXT_DATA,
+     423                 :            :                               NULL, &current_return_data, &data_return_size);
+     424                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     425                 :          1 :     assert_int_equal(data_return_size, sizeof(void*));
+     426                 :            : 
+     427                 :            :     /* Ensure nothing has changed between subsequent calls to get data */
+     428                 :          1 :     assert_ptr_equal(current_return_data, &libspdm_opaque_data);
+     429                 :            : 
+     430                 :            :     /*
+     431                 :            :      * Set data with invalid size, it should fail. Read back to ensure that
+     432                 :            :      * no data was set.
+     433                 :            :      */
+     434                 :          1 :     status = libspdm_set_data(spdm_context, LIBSPDM_DATA_APP_CONTEXT_DATA,
+     435                 :            :                               NULL, &data, 500);
+     436                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_PARAMETER);
+     437                 :            : 
+     438                 :          1 :     data_return_size = sizeof(return_data);
+     439                 :          1 :     status = libspdm_get_data(spdm_context, LIBSPDM_DATA_APP_CONTEXT_DATA,
+     440                 :            :                               NULL, &return_data, &data_return_size);
+     441                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     442                 :          1 :     assert_ptr_equal(return_data, current_return_data);
+     443                 :          1 :     assert_int_equal(data_return_size, sizeof(void*));
+     444                 :            : 
+     445                 :            :     /* check that nothing changed at the data location */
+     446                 :          1 :     assert_int_equal(libspdm_opaque_data, 0xDEADBEEF);
+     447                 :          1 : }
+     448                 :            : 
+     449                 :            : /**
+     450                 :            :  * Test 3: Test failure paths of setting opaque data in context. libspdm_set_data
+     451                 :            :  * should fail when data contains NULL value.
+     452                 :            :  **/
+     453                 :          1 : static void libspdm_test_common_context_data_case3(void **state)
+     454                 :            : {
+     455                 :            :     libspdm_return_t status;
+     456                 :            :     libspdm_test_context_t *spdm_test_context;
+     457                 :            :     libspdm_context_t *spdm_context;
+     458                 :          1 :     void *data = NULL;
+     459                 :          1 :     void *return_data = NULL;
+     460                 :          1 :     void *current_return_data = NULL;
+     461                 :          1 :     size_t data_return_size = 0;
+     462                 :            : 
+     463                 :          1 :     spdm_test_context = *state;
+     464                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     465                 :          1 :     spdm_test_context->case_id = 0x3;
+     466                 :            : 
+     467                 :            :     /**
+     468                 :            :      * Get current opaque data in context. May have been set in previous
+     469                 :            :      * tests. This will be used to compare later to ensure the value hasn't
+     470                 :            :      * changed after a failed set data.
+     471                 :            :      */
+     472                 :          1 :     data_return_size = sizeof(current_return_data);
+     473                 :          1 :     status = libspdm_get_data(spdm_context, LIBSPDM_DATA_APP_CONTEXT_DATA,
+     474                 :            :                               NULL, &current_return_data, &data_return_size);
+     475                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     476                 :          1 :     assert_int_equal(data_return_size, sizeof(void*));
+     477                 :            : 
+     478                 :            :     /* Ensure nothing has changed between subsequent calls to get data */
+     479                 :          1 :     assert_ptr_equal(current_return_data, &libspdm_opaque_data);
+     480                 :            : 
+     481                 :            : 
+     482                 :            :     /*
+     483                 :            :      * Set data with NULL data, it should fail. Read back to ensure that
+     484                 :            :      * no data was set.
+     485                 :            :      */
+     486                 :          1 :     status = libspdm_set_data(spdm_context, LIBSPDM_DATA_APP_CONTEXT_DATA,
+     487                 :            :                               NULL, &data, sizeof(void *));
+     488                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_PARAMETER);
+     489                 :            : 
+     490                 :          1 :     data_return_size = sizeof(return_data);
+     491                 :          1 :     status = libspdm_get_data(spdm_context, LIBSPDM_DATA_APP_CONTEXT_DATA,
+     492                 :            :                               NULL, &return_data, &data_return_size);
+     493                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     494                 :          1 :     assert_ptr_equal(return_data, current_return_data);
+     495                 :          1 :     assert_int_equal(data_return_size, sizeof(void*));
+     496                 :            : 
+     497                 :            :     /* check that nothing changed at the data location */
+     498                 :          1 :     assert_int_equal(libspdm_opaque_data, 0xDEADBEEF);
+     499                 :            : 
+     500                 :          1 : }
+     501                 :            : 
+     502                 :            : /**
+     503                 :            :  * Test 4: Test failure paths of getting opaque data in context. libspdm_get_data
+     504                 :            :  * should fail when the size of buffer to get is too small.
+     505                 :            :  **/
+     506                 :          1 : static void libspdm_test_common_context_data_case4(void **state)
+     507                 :            : {
+     508                 :            :     libspdm_return_t status;
+     509                 :            :     libspdm_test_context_t *spdm_test_context;
+     510                 :            :     libspdm_context_t *spdm_context;
+     511                 :          1 :     void *data = (void *)&libspdm_opaque_data;
+     512                 :          1 :     void *return_data = NULL;
+     513                 :          1 :     size_t data_return_size = 0;
+     514                 :            : 
+     515                 :          1 :     spdm_test_context = *state;
+     516                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     517                 :          1 :     spdm_test_context->case_id = 0x4;
+     518                 :            : 
+     519                 :            :     /*
+     520                 :            :      * Set data successfully.
+     521                 :            :      */
+     522                 :          1 :     status = libspdm_set_data(spdm_context, LIBSPDM_DATA_APP_CONTEXT_DATA,
+     523                 :            :                               NULL, &data, sizeof(void *));
+     524                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     525                 :            : 
+     526                 :            :     /*
+     527                 :            :      * Fail get data due to insufficient buffer for return value. returned
+     528                 :            :      * data size must return required buffer size.
+     529                 :            :      */
+     530                 :          1 :     data_return_size = sizeof(void*) - 1;
+     531                 :          1 :     status = libspdm_get_data(spdm_context, LIBSPDM_DATA_APP_CONTEXT_DATA,
+     532                 :            :                               NULL, &return_data, &data_return_size);
+     533                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_BUFFER_TOO_SMALL);
+     534                 :          1 :     assert_int_equal(data_return_size, sizeof(void*));
+     535                 :            : 
+     536                 :            :     /* check that nothing changed at the data location */
+     537                 :          1 :     assert_int_equal(libspdm_opaque_data, 0xDEADBEEF);
+     538                 :          1 : }
+     539                 :            : 
+     540                 :            : /**
+     541                 :            :  * Test 5: There is no root cert.
+     542                 :            :  * Expected Behavior: Return true result.
+     543                 :            :  **/
+     544                 :          1 : void libspdm_test_verify_peer_cert_chain_buffer_case5(void **state)
+     545                 :            : {
+     546                 :            :     libspdm_test_context_t *spdm_test_context;
+     547                 :            :     libspdm_context_t *spdm_context;
+     548                 :            :     void *data;
+     549                 :            :     size_t data_size;
+     550                 :            :     void *hash;
+     551                 :            :     size_t hash_size;
+     552                 :            :     const uint8_t *root_cert;
+     553                 :            :     size_t root_cert_size;
+     554                 :            : 
+     555                 :            :     const void *trust_anchor;
+     556                 :            :     size_t trust_anchor_size;
+     557                 :            :     bool result;
+     558                 :            :     uint8_t root_cert_index;
+     559                 :            : 
+     560                 :          1 :     spdm_test_context = *state;
+     561                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     562                 :          1 :     spdm_test_context->case_id = 0x5;
+     563                 :            :     /* Setting SPDM context as the first steps of the protocol has been accomplished*/
+     564                 :          1 :     spdm_context->connection_info.connection_state =
+     565                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_DIGESTS;
+     566                 :          1 :     spdm_context->connection_info.capability.flags |=
+     567                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     568                 :            :     /* Loading Root certificate and saving its hash*/
+     569                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     570                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     571                 :            :                                                     &data_size, &hash, &hash_size);
+     572                 :          1 :     libspdm_x509_get_cert_from_cert_chain((uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size,
+     573                 :          1 :                                           data_size - sizeof(spdm_cert_chain_t) - hash_size, 0,
+     574                 :            :                                           &root_cert, &root_cert_size);
+     575                 :            : 
+     576                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     577                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo= m_libspdm_use_asym_algo;
+     578                 :          1 :     spdm_context->local_context.is_requester = true;
+     579                 :            : 
+     580                 :            :     /*clear root cert array*/
+     581         [ +  + ]:         11 :     for (root_cert_index = 0; root_cert_index < LIBSPDM_MAX_ROOT_CERT_SUPPORT; root_cert_index++) {
+     582                 :         10 :         spdm_context->local_context.peer_root_cert_provision_size[root_cert_index] = 0;
+     583                 :         10 :         spdm_context->local_context.peer_root_cert_provision[root_cert_index] = NULL;
+     584                 :            :     }
+     585                 :          1 :     result = libspdm_verify_peer_cert_chain_buffer(spdm_context, data, data_size, &trust_anchor,
+     586                 :            :                                                    &trust_anchor_size);
+     587                 :          1 :     assert_int_equal (result, true);
+     588                 :            : 
+     589                 :          1 :     free(data);
+     590                 :          1 : }
+     591                 :            : 
+     592                 :            : /**
+     593                 :            :  * Test 6: There is one root cert. And the root cert has two case: match root cert, mismatch root cert.
+     594                 :            :  *
+     595                 :            :  * case                                              Expected Behavior
+     596                 :            :  * there is one match root cert;                     return false
+     597                 :            :  * there is one mismatch root cert;                  return true, and the return trust_anchor is root cert.
+     598                 :            :  **/
+     599                 :          1 : void libspdm_test_verify_peer_cert_chain_buffer_case6(void **state)
+     600                 :            : {
+     601                 :            :     libspdm_test_context_t *spdm_test_context;
+     602                 :            :     libspdm_context_t *spdm_context;
+     603                 :            :     void *data;
+     604                 :            :     size_t data_size;
+     605                 :            :     void *hash;
+     606                 :            :     size_t hash_size;
+     607                 :            :     const uint8_t *root_cert;
+     608                 :            :     size_t root_cert_size;
+     609                 :            : 
+     610                 :            :     void *data_test;
+     611                 :            :     size_t data_size_test;
+     612                 :            :     void *hash_test;
+     613                 :            :     size_t hash_size_test;
+     614                 :            :     const uint8_t *root_cert_test;
+     615                 :            :     size_t root_cert_size_test;
+     616                 :          1 :     uint32_t m_libspdm_use_asym_algo_test =SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048;
+     617                 :            : 
+     618                 :            :     const void *trust_anchor;
+     619                 :            :     size_t trust_anchor_size;
+     620                 :            :     bool result;
+     621                 :            :     uint8_t root_cert_index;
+     622                 :            : 
+     623                 :          1 :     spdm_test_context = *state;
+     624                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     625                 :          1 :     spdm_test_context->case_id = 0x6;
+     626                 :            :     /* Setting SPDM context as the first steps of the protocol has been accomplished*/
+     627                 :          1 :     spdm_context->connection_info.connection_state =
+     628                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_DIGESTS;
+     629                 :          1 :     spdm_context->connection_info.capability.flags |=
+     630                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     631                 :          1 :     spdm_context->local_context.is_requester = true;
+     632                 :            : 
+     633                 :            :     /* Loading Root certificate and saving its hash*/
+     634                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     635                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     636                 :            :                                                     &data_size, &hash, &hash_size);
+     637                 :          1 :     libspdm_x509_get_cert_from_cert_chain((uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size,
+     638                 :          1 :                                           data_size - sizeof(spdm_cert_chain_t) - hash_size, 0,
+     639                 :            :                                           &root_cert, &root_cert_size);
+     640                 :            :     /* Loading Other test Root certificate and saving its hash*/
+     641                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     642                 :            :                                                     m_libspdm_use_asym_algo_test, &data_test,
+     643                 :            :                                                     &data_size_test, &hash_test, &hash_size_test);
+     644                 :          1 :     libspdm_x509_get_cert_from_cert_chain(
+     645                 :          1 :         (uint8_t *)data_test + sizeof(spdm_cert_chain_t) + hash_size_test,
+     646                 :          1 :         data_size_test - sizeof(spdm_cert_chain_t) - hash_size_test, 0,
+     647                 :            :         &root_cert_test, &root_cert_size_test);
+     648                 :            : 
+     649                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     650                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo= m_libspdm_use_asym_algo;
+     651                 :            : 
+     652                 :            :     /*clear root cert array*/
+     653         [ +  + ]:         11 :     for (root_cert_index = 0; root_cert_index < LIBSPDM_MAX_ROOT_CERT_SUPPORT; root_cert_index++) {
+     654                 :         10 :         spdm_context->local_context.peer_root_cert_provision_size[root_cert_index] = 0;
+     655                 :         10 :         spdm_context->local_context.peer_root_cert_provision[root_cert_index] = NULL;
+     656                 :            :     }
+     657                 :            : 
+     658                 :            :     /*case: match root cert case*/
+     659                 :          1 :     spdm_context->local_context.peer_root_cert_provision_size[0] =root_cert_size_test;
+     660                 :          1 :     spdm_context->local_context.peer_root_cert_provision[0] = root_cert_test;
+     661                 :          1 :     result = libspdm_verify_peer_cert_chain_buffer(spdm_context, data, data_size, &trust_anchor,
+     662                 :            :                                                    &trust_anchor_size);
+     663                 :          1 :     assert_int_equal (result, false);
+     664                 :            : 
+     665                 :            :     /*case: mismatch root cert case*/
+     666                 :          1 :     spdm_context->local_context.peer_root_cert_provision_size[0] =root_cert_size;
+     667                 :          1 :     spdm_context->local_context.peer_root_cert_provision[0] = root_cert;
+     668                 :          1 :     result = libspdm_verify_peer_cert_chain_buffer(spdm_context, data, data_size, &trust_anchor,
+     669                 :            :                                                    &trust_anchor_size);
+     670                 :          1 :     assert_int_equal (result, true);
+     671                 :          1 :     assert_ptr_equal (trust_anchor, root_cert);
+     672                 :            : 
+     673                 :          1 :     free(data);
+     674                 :          1 :     free(data_test);
+     675                 :          1 : }
+     676                 :            : 
+     677                 :            : /**
+     678                 :            :  * Test 7: There are LIBSPDM_MAX_ROOT_CERT_SUPPORT/2 root cert.
+     679                 :            :  *
+     680                 :            :  * case                                              Expected Behavior
+     681                 :            :  * there is no match root cert;                      return false
+     682                 :            :  * there is one match root cert in the end;          return true, and the return trust_anchor is root cert.
+     683                 :            :  * there is one match root cert in the middle;       return true, and the return trust_anchor is root cert.
+     684                 :            :  **/
+     685                 :          1 : void libspdm_test_verify_peer_cert_chain_buffer_case7(void **state)
+     686                 :            : {
+     687                 :            :     libspdm_test_context_t *spdm_test_context;
+     688                 :            :     libspdm_context_t *spdm_context;
+     689                 :            :     void *data;
+     690                 :            :     size_t data_size;
+     691                 :            :     void *hash;
+     692                 :            :     size_t hash_size;
+     693                 :            :     const uint8_t *root_cert;
+     694                 :            :     size_t root_cert_size;
+     695                 :            : 
+     696                 :            :     void *data_test;
+     697                 :            :     size_t data_size_test;
+     698                 :            :     void *hash_test;
+     699                 :            :     size_t hash_size_test;
+     700                 :            :     const uint8_t *root_cert_test;
+     701                 :            :     size_t root_cert_size_test;
+     702                 :          1 :     uint32_t m_libspdm_use_asym_algo_test =SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048;
+     703                 :            : 
+     704                 :            :     const void *trust_anchor;
+     705                 :            :     size_t trust_anchor_size;
+     706                 :            :     bool result;
+     707                 :            :     uint8_t root_cert_index;
+     708                 :            : 
+     709                 :          1 :     spdm_test_context = *state;
+     710                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     711                 :          1 :     spdm_test_context->case_id = 0x7;
+     712                 :            :     /* Setting SPDM context as the first steps of the protocol has been accomplished*/
+     713                 :          1 :     spdm_context->connection_info.connection_state =
+     714                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_DIGESTS;
+     715                 :          1 :     spdm_context->connection_info.capability.flags |=
+     716                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     717                 :          1 :     spdm_context->local_context.is_requester = true;
+     718                 :            :     /* Loading Root certificate and saving its hash*/
+     719                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     720                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     721                 :            :                                                     &data_size, &hash, &hash_size);
+     722                 :          1 :     libspdm_x509_get_cert_from_cert_chain((uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size,
+     723                 :          1 :                                           data_size - sizeof(spdm_cert_chain_t) - hash_size, 0,
+     724                 :            :                                           &root_cert, &root_cert_size);
+     725                 :            :     /* Loading Other test Root certificate and saving its hash*/
+     726                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     727                 :            :                                                     m_libspdm_use_asym_algo_test, &data_test,
+     728                 :            :                                                     &data_size_test, &hash_test, &hash_size_test);
+     729                 :          1 :     libspdm_x509_get_cert_from_cert_chain(
+     730                 :          1 :         (uint8_t *)data_test + sizeof(spdm_cert_chain_t) + hash_size_test,
+     731                 :          1 :         data_size_test - sizeof(spdm_cert_chain_t) - hash_size_test, 0,
+     732                 :            :         &root_cert_test, &root_cert_size_test);
+     733                 :            : 
+     734                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     735                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo= m_libspdm_use_asym_algo;
+     736                 :            : 
+     737                 :            :     /*clear root cert array*/
+     738         [ +  + ]:         11 :     for (root_cert_index = 0; root_cert_index < LIBSPDM_MAX_ROOT_CERT_SUPPORT; root_cert_index++) {
+     739                 :         10 :         spdm_context->local_context.peer_root_cert_provision_size[root_cert_index] = 0;
+     740                 :         10 :         spdm_context->local_context.peer_root_cert_provision[root_cert_index] = NULL;
+     741                 :            :     }
+     742                 :            : 
+     743                 :            :     /*case: there is no match root cert*/
+     744         [ +  + ]:          6 :     for (root_cert_index = 0; root_cert_index < (LIBSPDM_MAX_ROOT_CERT_SUPPORT / 2);
+     745                 :          5 :          root_cert_index++) {
+     746                 :          5 :         spdm_context->local_context.peer_root_cert_provision_size[root_cert_index] =
+     747                 :            :             root_cert_size_test;
+     748                 :          5 :         spdm_context->local_context.peer_root_cert_provision[root_cert_index] = root_cert_test;
+     749                 :            :     }
+     750                 :          1 :     result = libspdm_verify_peer_cert_chain_buffer(spdm_context, data, data_size, &trust_anchor,
+     751                 :            :                                                    &trust_anchor_size);
+     752                 :          1 :     assert_int_equal (result, false);
+     753                 :            : 
+     754                 :            :     /*case: there is no match root cert in the end*/
+     755                 :            :     spdm_context->local_context.peer_root_cert_provision_size[LIBSPDM_MAX_ROOT_CERT_SUPPORT / 2 -
+     756                 :          1 :                                                               1] =root_cert_size;
+     757                 :            :     spdm_context->local_context.peer_root_cert_provision[LIBSPDM_MAX_ROOT_CERT_SUPPORT / 2 -
+     758                 :          1 :                                                          1] = root_cert;
+     759                 :          1 :     result = libspdm_verify_peer_cert_chain_buffer(spdm_context, data, data_size, &trust_anchor,
+     760                 :            :                                                    &trust_anchor_size);
+     761                 :          1 :     assert_int_equal (result, true);
+     762                 :          1 :     assert_ptr_equal (trust_anchor, root_cert);
+     763                 :            : 
+     764                 :            :     /*case: there is no match root cert in the middle*/
+     765                 :            :     spdm_context->local_context.peer_root_cert_provision_size[LIBSPDM_MAX_ROOT_CERT_SUPPORT /
+     766                 :          1 :                                                               4] =root_cert_size;
+     767                 :            :     spdm_context->local_context.peer_root_cert_provision[LIBSPDM_MAX_ROOT_CERT_SUPPORT /
+     768                 :          1 :                                                          4] = root_cert;
+     769                 :          1 :     result = libspdm_verify_peer_cert_chain_buffer(spdm_context, data, data_size, &trust_anchor,
+     770                 :            :                                                    &trust_anchor_size);
+     771                 :          1 :     assert_int_equal (result, true);
+     772                 :          1 :     assert_ptr_equal (trust_anchor, root_cert);
+     773                 :            : 
+     774                 :          1 :     free(data);
+     775                 :          1 :     free(data_test);
+     776                 :          1 : }
+     777                 :            : 
+     778                 :            : 
+     779                 :            : /**
+     780                 :            :  * Test 8: There are full(LIBSPDM_MAX_ROOT_CERT_SUPPORT - 1) root cert.
+     781                 :            :  *
+     782                 :            :  * case                                              Expected Behavior
+     783                 :            :  * there is no match root cert;                      return false
+     784                 :            :  * there is one match root cert in the end;          return true, and the return trust_anchor is root cert.
+     785                 :            :  * there is one match root cert in the middle;       return true, and the return trust_anchor is root cert.
+     786                 :            :  **/
+     787                 :          1 : void libspdm_test_verify_peer_cert_chain_buffer_case8(void **state)
+     788                 :            : {
+     789                 :            :     libspdm_test_context_t *spdm_test_context;
+     790                 :            :     libspdm_context_t *spdm_context;
+     791                 :            :     void *data;
+     792                 :            :     size_t data_size;
+     793                 :            :     void *hash;
+     794                 :            :     size_t hash_size;
+     795                 :            :     const uint8_t *root_cert;
+     796                 :            :     size_t root_cert_size;
+     797                 :            : 
+     798                 :            :     void *data_test;
+     799                 :            :     size_t data_size_test;
+     800                 :            :     void *hash_test;
+     801                 :            :     size_t hash_size_test;
+     802                 :            :     const uint8_t *root_cert_test;
+     803                 :            :     size_t root_cert_size_test;
+     804                 :          1 :     uint32_t m_libspdm_use_asym_algo_test =SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048;
+     805                 :            : 
+     806                 :            :     const void *trust_anchor;
+     807                 :            :     size_t trust_anchor_size;
+     808                 :            :     bool result;
+     809                 :            :     uint8_t root_cert_index;
+     810                 :            : 
+     811                 :          1 :     spdm_test_context = *state;
+     812                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     813                 :          1 :     spdm_test_context->case_id = 0x8;
+     814                 :            :     /* Setting SPDM context as the first steps of the protocol has been accomplished*/
+     815                 :          1 :     spdm_context->connection_info.connection_state =
+     816                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_DIGESTS;
+     817                 :          1 :     spdm_context->connection_info.capability.flags |=
+     818                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     819                 :          1 :     spdm_context->local_context.is_requester = true;
+     820                 :            :     /* Loading Root certificate and saving its hash*/
+     821                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     822                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     823                 :            :                                                     &data_size, &hash, &hash_size);
+     824                 :          1 :     libspdm_x509_get_cert_from_cert_chain((uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size,
+     825                 :          1 :                                           data_size - sizeof(spdm_cert_chain_t) - hash_size, 0,
+     826                 :            :                                           &root_cert, &root_cert_size);
+     827                 :            :     /* Loading Other test Root certificate and saving its hash*/
+     828                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     829                 :            :                                                     m_libspdm_use_asym_algo_test, &data_test,
+     830                 :            :                                                     &data_size_test, &hash_test, &hash_size_test);
+     831                 :          1 :     libspdm_x509_get_cert_from_cert_chain(
+     832                 :          1 :         (uint8_t *)data_test + sizeof(spdm_cert_chain_t) + hash_size_test,
+     833                 :          1 :         data_size_test - sizeof(spdm_cert_chain_t) - hash_size_test, 0,
+     834                 :            :         &root_cert_test, &root_cert_size_test);
+     835                 :            : 
+     836                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     837                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo= m_libspdm_use_asym_algo;
+     838                 :            : 
+     839                 :            :     /*case: there is no match root cert*/
+     840         [ +  + ]:         11 :     for (root_cert_index = 0; root_cert_index < LIBSPDM_MAX_ROOT_CERT_SUPPORT; root_cert_index++) {
+     841                 :         10 :         spdm_context->local_context.peer_root_cert_provision_size[root_cert_index] =
+     842                 :            :             root_cert_size_test;
+     843                 :         10 :         spdm_context->local_context.peer_root_cert_provision[root_cert_index] = root_cert_test;
+     844                 :            :     }
+     845                 :          1 :     result = libspdm_verify_peer_cert_chain_buffer(spdm_context, data, data_size, &trust_anchor,
+     846                 :            :                                                    &trust_anchor_size);
+     847                 :          1 :     assert_int_equal (result, false);
+     848                 :            : 
+     849                 :            :     /*case: there is no match root cert in the end*/
+     850                 :            :     spdm_context->local_context.peer_root_cert_provision_size[LIBSPDM_MAX_ROOT_CERT_SUPPORT -
+     851                 :          1 :                                                               1] =root_cert_size;
+     852                 :            :     spdm_context->local_context.peer_root_cert_provision[LIBSPDM_MAX_ROOT_CERT_SUPPORT -
+     853                 :          1 :                                                          1] = root_cert;
+     854                 :          1 :     result = libspdm_verify_peer_cert_chain_buffer(spdm_context, data, data_size, &trust_anchor,
+     855                 :            :                                                    &trust_anchor_size);
+     856                 :          1 :     assert_int_equal (result, true);
+     857                 :          1 :     assert_ptr_equal (trust_anchor, root_cert);
+     858                 :            : 
+     859                 :            :     /*case: there is no match root cert in the middle*/
+     860         [ +  + ]:         11 :     for (root_cert_index = 0; root_cert_index < LIBSPDM_MAX_ROOT_CERT_SUPPORT; root_cert_index++) {
+     861                 :         10 :         spdm_context->local_context.peer_root_cert_provision_size[root_cert_index] =
+     862                 :            :             root_cert_size_test;
+     863                 :         10 :         spdm_context->local_context.peer_root_cert_provision[root_cert_index] = root_cert_test;
+     864                 :            :     }
+     865                 :            :     spdm_context->local_context.peer_root_cert_provision_size[LIBSPDM_MAX_ROOT_CERT_SUPPORT /
+     866                 :          1 :                                                               2] =root_cert_size;
+     867                 :            :     spdm_context->local_context.peer_root_cert_provision[LIBSPDM_MAX_ROOT_CERT_SUPPORT /
+     868                 :          1 :                                                          2] = root_cert;
+     869                 :          1 :     result = libspdm_verify_peer_cert_chain_buffer(spdm_context, data, data_size, &trust_anchor,
+     870                 :            :                                                    &trust_anchor_size);
+     871                 :          1 :     assert_int_equal (result, true);
+     872                 :          1 :     assert_ptr_equal (trust_anchor, root_cert);
+     873                 :            : 
+     874                 :          1 :     free(data);
+     875                 :          1 :     free(data_test);
+     876                 :          1 : }
+     877                 :            : 
+     878                 :            : /**
+     879                 :            :  * Test 9: test set data for root cert.
+     880                 :            :  *
+     881                 :            :  * case                                              Expected Behavior
+     882                 :            :  * there is null root cert;                          return RETURN_SUCCESS, and the root cert is set successfully.
+     883                 :            :  * there is full root cert;                          return RETURN_OUT_OF_RESOURCES.
+     884                 :            :  **/
+     885                 :          1 : static void libspdm_test_set_data_case9(void **state)
+     886                 :            : {
+     887                 :            :     libspdm_return_t status;
+     888                 :            :     libspdm_test_context_t *spdm_test_context;
+     889                 :            :     libspdm_context_t *spdm_context;
+     890                 :            :     libspdm_data_parameter_t parameter;
+     891                 :            : 
+     892                 :            :     void *data;
+     893                 :            :     size_t data_size;
+     894                 :            :     void *hash;
+     895                 :            :     size_t hash_size;
+     896                 :            :     const uint8_t *root_cert;
+     897                 :            :     uint8_t root_cert_buffer[LIBSPDM_MAX_CERT_CHAIN_SIZE];
+     898                 :            :     size_t root_cert_size;
+     899                 :            : 
+     900                 :            :     uint8_t root_cert_index;
+     901                 :            : 
+     902                 :          1 :     spdm_test_context = *state;
+     903                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     904                 :          1 :     spdm_test_context->case_id = 0x9;
+     905                 :            : 
+     906                 :            :     /* Loading Root certificate and saving its hash*/
+     907                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     908                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     909                 :            :                                                     &data_size, &hash, &hash_size);
+     910                 :          1 :     libspdm_x509_get_cert_from_cert_chain((uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size,
+     911                 :          1 :                                           data_size - sizeof(spdm_cert_chain_t) - hash_size, 0,
+     912                 :            :                                           &root_cert, &root_cert_size);
+     913                 :          1 :     memcpy(root_cert_buffer, root_cert, root_cert_size);
+     914                 :            : 
+     915                 :            :     /*case: there is null root cert*/
+     916         [ +  + ]:         11 :     for (root_cert_index = 0; root_cert_index < LIBSPDM_MAX_ROOT_CERT_SUPPORT; root_cert_index++) {
+     917                 :         10 :         spdm_context->local_context.peer_root_cert_provision_size[root_cert_index] = 0;
+     918                 :         10 :         spdm_context->local_context.peer_root_cert_provision[root_cert_index] = NULL;
+     919                 :            :     }
+     920                 :          1 :     parameter.location = LIBSPDM_DATA_LOCATION_LOCAL;
+     921                 :          1 :     status = libspdm_set_data(spdm_context, LIBSPDM_DATA_PEER_PUBLIC_ROOT_CERT,
+     922                 :            :                               &parameter, root_cert_buffer, root_cert_size);
+     923                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+     924                 :          1 :     assert_int_equal (spdm_context->local_context.peer_root_cert_provision_size[0], root_cert_size);
+     925                 :          1 :     assert_ptr_equal (spdm_context->local_context.peer_root_cert_provision[0], root_cert_buffer);
+     926                 :            : 
+     927                 :            :     /*case: there is full root cert*/
+     928         [ +  + ]:         11 :     for (root_cert_index = 0; root_cert_index < LIBSPDM_MAX_ROOT_CERT_SUPPORT; root_cert_index++) {
+     929                 :         10 :         spdm_context->local_context.peer_root_cert_provision_size[root_cert_index] = root_cert_size;
+     930                 :         10 :         spdm_context->local_context.peer_root_cert_provision[root_cert_index] = root_cert_buffer;
+     931                 :            :     }
+     932                 :          1 :     status = libspdm_set_data(spdm_context, LIBSPDM_DATA_PEER_PUBLIC_ROOT_CERT,
+     933                 :            :                               &parameter, root_cert_buffer, root_cert_size);
+     934                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_BUFFER_FULL);
+     935                 :            : 
+     936                 :          1 :     free(data);
+     937                 :          1 : }
+     938                 :            : 
+     939                 :            : 
+     940                 :            : /**
+     941                 :            :  * Test 10: There is no root cert.
+     942                 :            :  * Expected Behavior: Return true result.
+     943                 :            :  **/
+     944                 :          1 : void libspdm_test_process_opaque_data_supported_version_data_case10(void **state)
+     945                 :            : {
+     946                 :            :     libspdm_return_t status;
+     947                 :            :     libspdm_test_context_t *spdm_test_context;
+     948                 :            :     libspdm_context_t *spdm_context;
+     949                 :            :     size_t opaque_data_size;
+     950                 :            :     uint8_t element_num;
+     951                 :            : 
+     952                 :          1 :     spdm_test_context = *state;
+     953                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     954                 :          1 :     spdm_test_context->case_id = 0xA;
+     955                 :            : 
+     956                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     957                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     958                 :            : 
+     959                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
+     960                 :            : 
+     961                 :          1 :     element_num = 2;
+     962                 :          1 :     opaque_data_size =
+     963                 :          1 :         libspdm_get_multi_element_opaque_data_supported_version_data_size(
+     964                 :            :             spdm_context,
+     965                 :          1 :             spdm_context->local_context.secured_message_version.spdm_version_count,
+     966                 :            :             element_num);
+     967                 :            : 
+     968                 :            :     uint8_t *opaque_data_ptr;
+     969                 :          1 :     opaque_data_ptr = malloc(opaque_data_size);
+     970                 :            : 
+     971                 :          1 :     libspdm_build_multi_element_opaque_data_supported_version_test(
+     972                 :            :         spdm_context, &opaque_data_size, opaque_data_ptr, element_num);
+     973                 :            : 
+     974                 :          1 :     status = libspdm_process_opaque_data_supported_version_data(spdm_context,
+     975                 :            :                                                                 opaque_data_size,
+     976                 :            :                                                                 opaque_data_ptr);
+     977                 :            : 
+     978                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+     979                 :            : 
+     980                 :          1 :     free(opaque_data_ptr);
+     981                 :          1 : }
+     982                 :            : 
+     983                 :          1 : void libspdm_test_process_opaque_data_supported_version_data_case11(void **state)
+     984                 :            : {
+     985                 :            :     libspdm_return_t status;
+     986                 :            :     libspdm_test_context_t *spdm_test_context;
+     987                 :            :     libspdm_context_t *spdm_context;
+     988                 :            :     size_t opaque_data_size;
+     989                 :            :     uint8_t element_num;
+     990                 :            : 
+     991                 :          1 :     spdm_test_context = *state;
+     992                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     993                 :          1 :     spdm_test_context->case_id = 0xB;
+     994                 :            : 
+     995                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     996                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     997                 :            : 
+     998                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
+     999                 :            : 
+    1000                 :            :     /*make element id wrong*/
+    1001                 :          1 :     element_num = SPDM_REGISTRY_ID_MAX + 2;
+    1002                 :          1 :     opaque_data_size =
+    1003                 :          1 :         libspdm_get_multi_element_opaque_data_supported_version_data_size(
+    1004                 :            :             spdm_context,
+    1005                 :          1 :             spdm_context->local_context.secured_message_version.spdm_version_count,
+    1006                 :            :             element_num);
+    1007                 :            : 
+    1008                 :            :     uint8_t *opaque_data_ptr;
+    1009                 :          1 :     opaque_data_ptr = malloc(opaque_data_size);
+    1010                 :            : 
+    1011                 :          1 :     libspdm_build_multi_element_opaque_data_supported_version_test(
+    1012                 :            :         spdm_context, &opaque_data_size, opaque_data_ptr, element_num);
+    1013                 :            : 
+    1014                 :          1 :     status = libspdm_process_opaque_data_supported_version_data(spdm_context,
+    1015                 :            :                                                                 opaque_data_size,
+    1016                 :            :                                                                 opaque_data_ptr);
+    1017                 :            : 
+    1018                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1019                 :            : 
+    1020                 :          1 :     free(opaque_data_ptr);
+    1021                 :          1 : }
+    1022                 :            : 
+    1023                 :          1 : void libspdm_test_process_opaque_data_supported_version_data_case12(void **state)
+    1024                 :            : {
+    1025                 :            :     libspdm_return_t status;
+    1026                 :            :     libspdm_test_context_t *spdm_test_context;
+    1027                 :            :     libspdm_context_t *spdm_context;
+    1028                 :            :     size_t opaque_data_size;
+    1029                 :            :     uint8_t element_num;
+    1030                 :            : 
+    1031                 :          1 :     spdm_test_context = *state;
+    1032                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1033                 :          1 :     spdm_test_context->case_id = 0xC;
+    1034                 :            : 
+    1035                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    1036                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1037                 :            : 
+    1038                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
+    1039                 :            : 
+    1040                 :          1 :     element_num = 2;
+    1041                 :          1 :     opaque_data_size =
+    1042                 :          1 :         libspdm_get_multi_element_opaque_data_supported_version_data_size(
+    1043                 :            :             spdm_context,
+    1044                 :          1 :             spdm_context->local_context.secured_message_version.spdm_version_count,
+    1045                 :            :             element_num);
+    1046                 :            : 
+    1047                 :            :     uint8_t *opaque_data_ptr;
+    1048                 :          1 :     opaque_data_ptr = malloc(opaque_data_size);
+    1049                 :            : 
+    1050                 :          1 :     libspdm_build_multi_element_opaque_data_supported_version_test(
+    1051                 :            :         spdm_context, &opaque_data_size, opaque_data_ptr, element_num);
+    1052                 :            : 
+    1053                 :          1 :     status = libspdm_process_opaque_data_supported_version_data(spdm_context,
+    1054                 :            :                                                                 opaque_data_size,
+    1055                 :            :                                                                 opaque_data_ptr);
+    1056                 :            : 
+    1057                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+    1058                 :            : 
+    1059                 :          1 :     free(opaque_data_ptr);
+    1060                 :          1 : }
+    1061                 :            : 
+    1062                 :          1 : void libspdm_test_process_opaque_data_supported_version_data_case13(void **state)
+    1063                 :            : {
+    1064                 :            :     libspdm_return_t status;
+    1065                 :            :     libspdm_test_context_t *spdm_test_context;
+    1066                 :            :     libspdm_context_t *spdm_context;
+    1067                 :            :     size_t opaque_data_size;
+    1068                 :            :     uint8_t element_num;
+    1069                 :            : 
+    1070                 :          1 :     spdm_test_context = *state;
+    1071                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1072                 :          1 :     spdm_test_context->case_id = 0xD;
+    1073                 :            : 
+    1074                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    1075                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1076                 :            : 
+    1077                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
+    1078                 :            : 
+    1079                 :            :     /*make element id wrong*/
+    1080                 :          1 :     element_num = SPDM_REGISTRY_ID_MAX + 2;
+    1081                 :          1 :     opaque_data_size =
+    1082                 :          1 :         libspdm_get_multi_element_opaque_data_supported_version_data_size(
+    1083                 :            :             spdm_context,
+    1084                 :          1 :             spdm_context->local_context.secured_message_version.spdm_version_count,
+    1085                 :            :             element_num);
+    1086                 :            : 
+    1087                 :            :     uint8_t *opaque_data_ptr;
+    1088                 :          1 :     opaque_data_ptr = malloc(opaque_data_size);
+    1089                 :            : 
+    1090                 :          1 :     libspdm_build_multi_element_opaque_data_supported_version_test(
+    1091                 :            :         spdm_context, &opaque_data_size, opaque_data_ptr, element_num);
+    1092                 :            : 
+    1093                 :          1 :     status = libspdm_process_opaque_data_supported_version_data(spdm_context,
+    1094                 :            :                                                                 opaque_data_size,
+    1095                 :            :                                                                 opaque_data_ptr);
+    1096                 :            : 
+    1097                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1098                 :            : 
+    1099                 :          1 :     free(opaque_data_ptr);
+    1100                 :          1 : }
+    1101                 :            : 
+    1102                 :            : 
+    1103                 :          1 : void libspdm_test_process_opaque_data_selection_version_data_case14(void **state)
+    1104                 :            : {
+    1105                 :            :     libspdm_return_t status;
+    1106                 :            :     libspdm_test_context_t *spdm_test_context;
+    1107                 :            :     libspdm_context_t *spdm_context;
+    1108                 :            :     size_t opaque_data_size;
+    1109                 :            :     uint8_t element_num;
+    1110                 :            : 
+    1111                 :          1 :     spdm_test_context = *state;
+    1112                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1113                 :          1 :     spdm_test_context->case_id = 0xE;
+    1114                 :            : 
+    1115                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1116                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1117                 :            : 
+    1118                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
+    1119                 :          1 :     spdm_context->connection_info.secured_message_version =
+    1120                 :            :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1121                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
+    1122                 :            :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1123                 :            : 
+    1124                 :          1 :     element_num = 2;
+    1125                 :          1 :     opaque_data_size =
+    1126                 :          1 :         libspdm_get_multi_element_opaque_data_version_selection_data_size(
+    1127                 :            :             spdm_context,
+    1128                 :            :             element_num);
+    1129                 :            : 
+    1130                 :            :     uint8_t *opaque_data_ptr;
+    1131                 :          1 :     opaque_data_ptr = malloc(opaque_data_size);
+    1132                 :            : 
+    1133                 :          1 :     libspdm_build_opaque_data_version_selection_data_test(
+    1134                 :            :         spdm_context, &opaque_data_size, opaque_data_ptr, element_num);
+    1135                 :            : 
+    1136                 :          1 :     status = libspdm_process_opaque_data_version_selection_data(spdm_context,
+    1137                 :            :                                                                 opaque_data_size,
+    1138                 :            :                                                                 opaque_data_ptr);
+    1139                 :            : 
+    1140                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+    1141                 :            : 
+    1142                 :          1 :     free(opaque_data_ptr);
+    1143                 :          1 : }
+    1144                 :            : 
+    1145                 :            : 
+    1146                 :          1 : void libspdm_test_process_opaque_data_selection_version_data_case15(void **state)
+    1147                 :            : {
+    1148                 :            :     libspdm_return_t status;
+    1149                 :            :     libspdm_test_context_t *spdm_test_context;
+    1150                 :            :     libspdm_context_t *spdm_context;
+    1151                 :            :     size_t opaque_data_size;
+    1152                 :            :     uint8_t element_num;
+    1153                 :            : 
+    1154                 :          1 :     spdm_test_context = *state;
+    1155                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1156                 :          1 :     spdm_test_context->case_id = 0xF;
+    1157                 :            : 
+    1158                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1159                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1160                 :            : 
+    1161                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
+    1162                 :          1 :     spdm_context->connection_info.secured_message_version =
+    1163                 :            :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1164                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
+    1165                 :            :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1166                 :            : 
+    1167                 :            :     /*make element id wrong*/
+    1168                 :          1 :     element_num = SPDM_REGISTRY_ID_MAX + 2;
+    1169                 :          1 :     opaque_data_size =
+    1170                 :          1 :         libspdm_get_multi_element_opaque_data_version_selection_data_size(
+    1171                 :            :             spdm_context,
+    1172                 :            :             element_num);
+    1173                 :            : 
+    1174                 :            :     uint8_t *opaque_data_ptr;
+    1175                 :          1 :     opaque_data_ptr = malloc(opaque_data_size);
+    1176                 :            : 
+    1177                 :          1 :     libspdm_build_opaque_data_version_selection_data_test(
+    1178                 :            :         spdm_context, &opaque_data_size, opaque_data_ptr, element_num);
+    1179                 :            : 
+    1180                 :          1 :     status = libspdm_process_opaque_data_version_selection_data(spdm_context,
+    1181                 :            :                                                                 opaque_data_size,
+    1182                 :            :                                                                 opaque_data_ptr);
+    1183                 :            : 
+    1184                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1185                 :            : 
+    1186                 :          1 :     free(opaque_data_ptr);
+    1187                 :          1 : }
+    1188                 :            : 
+    1189                 :            : 
+    1190                 :          1 : void libspdm_test_process_opaque_data_selection_version_data_case16(void **state)
+    1191                 :            : {
+    1192                 :            :     libspdm_return_t status;
+    1193                 :            :     libspdm_test_context_t *spdm_test_context;
+    1194                 :            :     libspdm_context_t *spdm_context;
+    1195                 :            :     size_t opaque_data_size;
+    1196                 :            :     uint8_t element_num;
+    1197                 :            : 
+    1198                 :          1 :     spdm_test_context = *state;
+    1199                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1200                 :          1 :     spdm_test_context->case_id = 0x10;
+    1201                 :            : 
+    1202                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    1203                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1204                 :            : 
+    1205                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
+    1206                 :          1 :     spdm_context->connection_info.secured_message_version =
+    1207                 :            :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1208                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
+    1209                 :            :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1210                 :            : 
+    1211                 :          1 :     element_num = 2;
+    1212                 :          1 :     opaque_data_size =
+    1213                 :          1 :         libspdm_get_multi_element_opaque_data_version_selection_data_size(
+    1214                 :            :             spdm_context,
+    1215                 :            :             element_num);
+    1216                 :            : 
+    1217                 :            :     uint8_t *opaque_data_ptr;
+    1218                 :          1 :     opaque_data_ptr = malloc(opaque_data_size);
+    1219                 :            : 
+    1220                 :          1 :     libspdm_build_opaque_data_version_selection_data_test(
+    1221                 :            :         spdm_context, &opaque_data_size, opaque_data_ptr, element_num);
+    1222                 :            : 
+    1223                 :          1 :     status = libspdm_process_opaque_data_version_selection_data(spdm_context,
+    1224                 :            :                                                                 opaque_data_size,
+    1225                 :            :                                                                 opaque_data_ptr);
+    1226                 :            : 
+    1227                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+    1228                 :            : 
+    1229                 :          1 :     free(opaque_data_ptr);
+    1230                 :          1 : }
+    1231                 :            : 
+    1232                 :          1 : void libspdm_test_process_opaque_data_selection_version_data_case17(void **state)
+    1233                 :            : {
+    1234                 :            :     libspdm_return_t status;
+    1235                 :            :     libspdm_test_context_t *spdm_test_context;
+    1236                 :            :     libspdm_context_t *spdm_context;
+    1237                 :            :     size_t opaque_data_size;
+    1238                 :            :     uint8_t element_num;
+    1239                 :            : 
+    1240                 :          1 :     spdm_test_context = *state;
+    1241                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1242                 :          1 :     spdm_test_context->case_id = 0x11;
+    1243                 :            : 
+    1244                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    1245                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1246                 :            : 
+    1247                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
+    1248                 :          1 :     spdm_context->connection_info.secured_message_version =
+    1249                 :            :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1250                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
+    1251                 :            :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1252                 :            : 
+    1253                 :            :     /*make element id wrong*/
+    1254                 :          1 :     element_num = SPDM_REGISTRY_ID_MAX + 2;
+    1255                 :          1 :     opaque_data_size =
+    1256                 :          1 :         libspdm_get_multi_element_opaque_data_version_selection_data_size(
+    1257                 :            :             spdm_context,
+    1258                 :            :             element_num);
+    1259                 :            : 
+    1260                 :            :     uint8_t *opaque_data_ptr;
+    1261                 :          1 :     opaque_data_ptr = malloc(opaque_data_size);
+    1262                 :            : 
+    1263                 :          1 :     libspdm_build_opaque_data_version_selection_data_test(
+    1264                 :            :         spdm_context, &opaque_data_size, opaque_data_ptr, element_num);
+    1265                 :            : 
+    1266                 :          1 :     status = libspdm_process_opaque_data_version_selection_data(spdm_context,
+    1267                 :            :                                                                 opaque_data_size,
+    1268                 :            :                                                                 opaque_data_ptr);
+    1269                 :            : 
+    1270                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1271                 :            : 
+    1272                 :          1 :     free(opaque_data_ptr);
+    1273                 :          1 : }
+    1274                 :            : 
+    1275                 :          1 : void libspdm_test_secured_message_context_location_selection_case18(void **state)
+    1276                 :            : {
+    1277                 :            :     libspdm_return_t status;
+    1278                 :            :     libspdm_test_context_t *spdm_test_context;
+    1279                 :            :     libspdm_context_t *spdm_context;
+    1280                 :            :     void *secured_message_contexts[LIBSPDM_MAX_SESSION_COUNT];
+    1281                 :            :     size_t index;
+    1282                 :            : 
+    1283                 :          1 :     spdm_test_context = *state;
+    1284                 :          1 :     spdm_test_context->case_id = 0x12;
+    1285                 :            : 
+    1286                 :          1 :     spdm_context = (libspdm_context_t *)malloc(libspdm_get_context_size_without_secured_context());
+    1287                 :            : 
+    1288         [ +  + ]:          5 :     for (index = 0; index < LIBSPDM_MAX_SESSION_COUNT; index++)
+    1289                 :            :     {
+    1290                 :          4 :         secured_message_contexts[index] =
+    1291                 :          4 :             (void *)malloc(libspdm_secured_message_get_context_size());
+    1292                 :            :     }
+    1293                 :            : 
+    1294                 :          1 :     status = libspdm_init_context_with_secured_context(spdm_context, secured_message_contexts,
+    1295                 :            :                                                        LIBSPDM_MAX_SESSION_COUNT);
+    1296                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+    1297                 :            : 
+    1298         [ +  + ]:          5 :     for (index = 0; index < LIBSPDM_MAX_SESSION_COUNT; index++)
+    1299                 :            :     {
+    1300                 :            :         /* Ensure the SPDM context points to the specified memory. */
+    1301                 :          4 :         assert_ptr_equal(spdm_context->session_info[index].secured_message_context,
+    1302                 :            :                          secured_message_contexts[index]);
+    1303                 :            :     }
+    1304                 :            : 
+    1305                 :          1 :     free(spdm_context);
+    1306         [ +  + ]:          5 :     for (index = 0; index < LIBSPDM_MAX_SESSION_COUNT; index++)
+    1307                 :            :     {
+    1308                 :          4 :         free(secured_message_contexts[index]);
+    1309                 :            :     }
+    1310                 :          1 : }
+    1311                 :            : 
+    1312                 :          1 : static void libspdm_test_export_master_secret_case19(void **state)
+    1313                 :            : {
+    1314                 :            :     uint8_t target_buffer[LIBSPDM_MAX_HASH_SIZE];
+    1315                 :            :     bool result;
+    1316                 :            :     libspdm_secured_message_context_t secured_message_context;
+    1317                 :            :     size_t export_master_secret_size;
+    1318                 :            : 
+    1319                 :            :     /* Get the entire EMS when the reported size of the target buffer is larger than the size of the
+    1320                 :            :      * EMS. */
+    1321         [ +  + ]:         65 :     for (int index = 0; index < LIBSPDM_MAX_HASH_SIZE; index++) {
+    1322                 :         64 :         secured_message_context.export_master_secret[index] = (uint8_t)index;
+    1323                 :         64 :         target_buffer[index] = 0x00;
+    1324                 :            :     }
+    1325                 :            : 
+    1326                 :          1 :     secured_message_context.hash_size = LIBSPDM_MAX_HASH_SIZE;
+    1327                 :          1 :     export_master_secret_size = LIBSPDM_MAX_HASH_SIZE + 0x100;
+    1328                 :            : 
+    1329                 :          1 :     result = libspdm_secured_message_export_master_secret(&secured_message_context,
+    1330                 :            :                                                           &target_buffer,
+    1331                 :            :                                                           &export_master_secret_size);
+    1332                 :          1 :     assert_int_equal(result, true);
+    1333                 :            : 
+    1334                 :          1 :     libspdm_secured_message_clear_export_master_secret(&secured_message_context);
+    1335                 :            : 
+    1336         [ +  + ]:         65 :     for (int index = 0; index < LIBSPDM_MAX_HASH_SIZE; index++) {
+    1337                 :         64 :         assert_int_equal(target_buffer[index], index);
+    1338                 :         64 :         assert_int_equal(secured_message_context.export_master_secret[index], 0x00);
+    1339                 :            :     }
+    1340                 :          1 :     assert_int_equal(export_master_secret_size, LIBSPDM_MAX_HASH_SIZE);
+    1341                 :            : 
+    1342                 :            :     /* Get the entire EMS when the size of the target buffer is the same size as the EMS. */
+    1343         [ +  + ]:         65 :     for (int index = 0; index < LIBSPDM_MAX_HASH_SIZE; index++) {
+    1344                 :         64 :         secured_message_context.export_master_secret[index] = (uint8_t)index;
+    1345                 :         64 :         target_buffer[index] = 0x00;
+    1346                 :            :     }
+    1347                 :            : 
+    1348                 :          1 :     secured_message_context.hash_size = LIBSPDM_MAX_HASH_SIZE;
+    1349                 :          1 :     export_master_secret_size = LIBSPDM_MAX_HASH_SIZE;
+    1350                 :            : 
+    1351                 :          1 :     result = libspdm_secured_message_export_master_secret(&secured_message_context,
+    1352                 :            :                                                           &target_buffer,
+    1353                 :            :                                                           &export_master_secret_size);
+    1354                 :          1 :     assert_int_equal(result, true);
+    1355                 :            : 
+    1356         [ +  + ]:         65 :     for (int index = 0; index < LIBSPDM_MAX_HASH_SIZE; index++) {
+    1357                 :         64 :         assert_int_equal(target_buffer[index], index);
+    1358                 :            :     }
+    1359                 :          1 :     assert_int_equal(export_master_secret_size, LIBSPDM_MAX_HASH_SIZE);
+    1360                 :            : 
+    1361                 :            :     /* Get the truncated EMS when the size of the target buffer is less than the size of the EMS. */
+    1362         [ +  + ]:         65 :     for (int index = 0; index < LIBSPDM_MAX_HASH_SIZE; index++) {
+    1363                 :         64 :         secured_message_context.export_master_secret[index] = (uint8_t)index;
+    1364                 :         64 :         target_buffer[index] = 0x00;
+    1365                 :            :     }
+    1366                 :            : 
+    1367                 :          1 :     secured_message_context.hash_size = LIBSPDM_MAX_HASH_SIZE;
+    1368                 :          1 :     export_master_secret_size = LIBSPDM_MAX_HASH_SIZE - 4;
+    1369                 :            : 
+    1370                 :          1 :     result = libspdm_secured_message_export_master_secret(&secured_message_context,
+    1371                 :            :                                                           &target_buffer,
+    1372                 :            :                                                           &export_master_secret_size);
+    1373                 :          1 :     assert_int_equal(result, true);
+    1374                 :            : 
+    1375         [ +  + ]:         65 :     for (int index = 0; index < LIBSPDM_MAX_HASH_SIZE; index++) {
+    1376         [ +  + ]:         64 :         if (index < LIBSPDM_MAX_HASH_SIZE - 4) {
+    1377                 :         60 :             assert_int_equal(target_buffer[index], index);
+    1378                 :            :         } else {
+    1379                 :          4 :             assert_int_equal(target_buffer[index], 0x00);
+    1380                 :            :         }
+    1381                 :            :     }
+    1382                 :          1 :     assert_int_equal(export_master_secret_size, LIBSPDM_MAX_HASH_SIZE - 4);
+    1383                 :          1 : }
+    1384                 :            : 
+    1385                 :          1 : static void libspdm_test_check_context_case20(void **state)
+    1386                 :            : {
+    1387                 :            :     void *context;
+    1388                 :            :     bool result;
+    1389                 :            : 
+    1390                 :          1 :     context = (void *)malloc (libspdm_get_context_size());
+    1391                 :            : 
+    1392                 :          1 :     libspdm_init_context (context);
+    1393                 :            : 
+    1394                 :          1 :     result = libspdm_check_context (context);
+    1395                 :          1 :     assert_int_equal(false, result);
+    1396                 :            : 
+    1397                 :          1 :     libspdm_register_transport_layer_func(context,
+    1398                 :            :                                           LIBSPDM_MAX_SPDM_MSG_SIZE,
+    1399                 :            :                                           LIBSPDM_TEST_TRANSPORT_HEADER_SIZE,
+    1400                 :            :                                           LIBSPDM_TEST_TRANSPORT_TAIL_SIZE,
+    1401                 :            :                                           libspdm_transport_test_encode_message,
+    1402                 :            :                                           libspdm_transport_test_decode_message);
+    1403                 :            : 
+    1404                 :          1 :     libspdm_register_device_buffer_func(context,
+    1405                 :            :                                         LIBSPDM_MAX_SENDER_RECEIVER_BUFFER_SIZE,
+    1406                 :            :                                         LIBSPDM_MAX_SENDER_RECEIVER_BUFFER_SIZE,
+    1407                 :            :                                         spdm_device_acquire_sender_buffer,
+    1408                 :            :                                         spdm_device_release_sender_buffer,
+    1409                 :            :                                         spdm_device_acquire_receiver_buffer,
+    1410                 :            :                                         spdm_device_release_receiver_buffer);
+    1411                 :            : 
+    1412                 :          1 :     result = libspdm_check_context (context);
+    1413                 :          1 :     assert_int_equal(true, result);
+    1414                 :            : 
+    1415                 :          1 :     libspdm_register_transport_layer_func(context,
+    1416                 :            :                                           SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12,
+    1417                 :            :                                           LIBSPDM_TEST_TRANSPORT_HEADER_SIZE,
+    1418                 :            :                                           LIBSPDM_TEST_TRANSPORT_TAIL_SIZE,
+    1419                 :            :                                           libspdm_transport_test_encode_message,
+    1420                 :            :                                           libspdm_transport_test_decode_message);
+    1421                 :            : 
+    1422                 :          1 :     result = libspdm_check_context (context);
+    1423                 :          1 :     assert_int_equal(false, result);
+    1424                 :          1 : }
+    1425                 :            : 
+    1426                 :          1 : static void libspdm_test_max_session_count_case21(void **state)
+    1427                 :            : {
+    1428                 :            :     libspdm_context_t *spdm_context;
+    1429                 :            :     libspdm_data_parameter_t parameter;
+    1430                 :            :     size_t index;
+    1431                 :            :     size_t round;
+    1432                 :            :     uint16_t req_id;
+    1433                 :            :     uint16_t rsp_id;
+    1434                 :            :     uint32_t session_id;
+    1435                 :            :     void *session_info;
+    1436                 :            :     uint32_t dhe_session_count;
+    1437                 :            :     uint32_t psk_session_count;
+    1438                 :            : 
+    1439         [ +  + ]:          7 :     for (round = 0; round <= 5; round++) {
+    1440                 :            :         /* prepare parameter */
+    1441   [ +  +  +  +  :          6 :         switch (round) {
+                +  +  - ]
+    1442                 :          1 :         case 0:
+    1443                 :          1 :             dhe_session_count = 1;
+    1444                 :          1 :             psk_session_count = 1;
+    1445                 :          1 :             break;
+    1446                 :          1 :         case 1:
+    1447                 :          1 :             dhe_session_count = LIBSPDM_MAX_SESSION_COUNT / 2;
+    1448                 :          1 :             psk_session_count = LIBSPDM_MAX_SESSION_COUNT - dhe_session_count;
+    1449                 :          1 :             break;
+    1450                 :          1 :         case 2:
+    1451                 :          1 :             dhe_session_count = 1;
+    1452                 :          1 :             psk_session_count = LIBSPDM_MAX_SESSION_COUNT - 1;
+    1453                 :          1 :             break;
+    1454                 :          1 :         case 3:
+    1455                 :          1 :             dhe_session_count = LIBSPDM_MAX_SESSION_COUNT - 1;
+    1456                 :          1 :             psk_session_count = 1;
+    1457                 :          1 :             break;
+    1458                 :          1 :         case 4:
+    1459                 :          1 :             dhe_session_count = 0;
+    1460                 :          1 :             psk_session_count = LIBSPDM_MAX_SESSION_COUNT;
+    1461                 :          1 :             break;
+    1462                 :          1 :         case 5:
+    1463                 :          1 :             dhe_session_count = LIBSPDM_MAX_SESSION_COUNT;
+    1464                 :          1 :             psk_session_count = 0;
+    1465                 :          1 :             break;
+    1466                 :          0 :         default:
+    1467                 :          0 :             dhe_session_count = 0;
+    1468                 :          0 :             psk_session_count = 0;
+    1469                 :          0 :             break;
+    1470                 :            :         }
+    1471                 :            : 
+    1472                 :            :         /* test */
+    1473                 :          6 :         spdm_context = (libspdm_context_t *)malloc(libspdm_get_context_size());
+    1474                 :          6 :         libspdm_init_context (spdm_context);
+    1475                 :          6 :         spdm_context->connection_info.capability.flags =
+    1476                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP |
+    1477                 :            :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    1478                 :          6 :         spdm_context->local_context.capability.flags =
+    1479                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP |
+    1480                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    1481                 :          6 :         spdm_context->connection_info.algorithm.base_hash_algo =
+    1482                 :            :             SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256;
+    1483                 :          6 :         spdm_context->connection_info.algorithm.dhe_named_group =
+    1484                 :            :             SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_256_R1;
+    1485                 :          6 :         spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1486                 :            :             SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_256_GCM;
+    1487                 :          6 :         spdm_context->connection_info.algorithm.key_schedule =
+    1488                 :            :             SPDM_ALGORITHMS_KEY_SCHEDULE_HMAC_HASH;
+    1489                 :            : 
+    1490                 :          6 :         libspdm_zero_mem(&parameter, sizeof(parameter));
+    1491                 :          6 :         parameter.location = LIBSPDM_DATA_LOCATION_LOCAL;
+    1492         [ +  + ]:          6 :         if (dhe_session_count != 0) {
+    1493                 :          5 :             libspdm_set_data (spdm_context, LIBSPDM_DATA_MAX_DHE_SESSION_COUNT, &parameter,
+    1494                 :            :                               &dhe_session_count, sizeof(dhe_session_count));
+    1495                 :            :         }
+    1496         [ +  + ]:          6 :         if (psk_session_count != 0) {
+    1497                 :          5 :             libspdm_set_data (spdm_context, LIBSPDM_DATA_MAX_PSK_SESSION_COUNT, &parameter,
+    1498                 :            :                               &psk_session_count, sizeof(psk_session_count));
+    1499                 :            :         }
+    1500                 :            : 
+    1501         [ +  + ]:          6 :         if (dhe_session_count != 0) {
+    1502         [ +  + ]:         16 :             for (index = 0; index < dhe_session_count; index++)
+    1503                 :            :             {
+    1504                 :         11 :                 req_id = libspdm_allocate_req_session_id (spdm_context, false);
+    1505                 :         11 :                 assert_int_not_equal (req_id, INVALID_SESSION_ID & 0xFFFF);
+    1506                 :            : 
+    1507                 :         11 :                 rsp_id = libspdm_allocate_rsp_session_id (spdm_context, false);
+    1508                 :         11 :                 assert_int_not_equal (rsp_id, (INVALID_SESSION_ID & 0xFFFF0000) >> 16);
+    1509                 :            : 
+    1510                 :         11 :                 session_id = libspdm_generate_session_id (req_id, rsp_id);
+    1511                 :         11 :                 session_info = libspdm_assign_session_id (spdm_context, session_id, false);
+    1512                 :         11 :                 assert_ptr_not_equal (session_info, NULL);
+    1513                 :            :             }
+    1514                 :          5 :             req_id = libspdm_allocate_req_session_id (spdm_context, false);
+    1515                 :          5 :             assert_int_equal (req_id, INVALID_SESSION_ID & 0xFFFF);
+    1516                 :            : 
+    1517                 :          5 :             rsp_id = libspdm_allocate_rsp_session_id (spdm_context, false);
+    1518                 :          5 :             assert_int_equal (rsp_id, (INVALID_SESSION_ID & 0xFFFF0000) >> 16);
+    1519                 :            :         }
+    1520                 :            : 
+    1521         [ +  + ]:          6 :         if (psk_session_count != 0) {
+    1522         [ +  + ]:         16 :             for (index = 0; index < psk_session_count; index++)
+    1523                 :            :             {
+    1524                 :         11 :                 req_id = libspdm_allocate_req_session_id (spdm_context, true);
+    1525                 :         11 :                 assert_int_not_equal (req_id, INVALID_SESSION_ID & 0xFFFF);
+    1526                 :            : 
+    1527                 :         11 :                 rsp_id = libspdm_allocate_rsp_session_id (spdm_context, true);
+    1528                 :         11 :                 assert_int_not_equal (rsp_id, (INVALID_SESSION_ID & 0xFFFF0000) >> 16);
+    1529                 :            : 
+    1530                 :         11 :                 session_id = libspdm_generate_session_id (req_id, rsp_id);
+    1531                 :         11 :                 session_info = libspdm_assign_session_id (spdm_context, session_id, true);
+    1532                 :         11 :                 assert_ptr_not_equal (session_info, NULL);
+    1533                 :            :             }
+    1534                 :          5 :             req_id = libspdm_allocate_req_session_id (spdm_context, true);
+    1535                 :          5 :             assert_int_equal (req_id, INVALID_SESSION_ID & 0xFFFF);
+    1536                 :            : 
+    1537                 :          5 :             rsp_id = libspdm_allocate_rsp_session_id (spdm_context, true);
+    1538                 :          5 :             assert_int_equal (rsp_id, (INVALID_SESSION_ID & 0xFFFF0000) >> 16);
+    1539                 :            :         }
+    1540                 :            : 
+    1541                 :          6 :         free(spdm_context);
+    1542                 :            :     }
+    1543                 :          1 : }
+    1544                 :            : 
+    1545                 :            : static libspdm_test_context_t m_libspdm_common_context_data_test_context = {
+    1546                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+    1547                 :            :     true,
+    1548                 :            :     NULL,
+    1549                 :            :     NULL,
+    1550                 :            : };
+    1551                 :            : 
+    1552                 :          1 : int libspdm_common_context_data_test_main(void)
+    1553                 :            : {
+    1554                 :          1 :     const struct CMUnitTest spdm_common_context_data_tests[] = {
+    1555                 :            :         cmocka_unit_test(libspdm_test_common_context_data_case1),
+    1556                 :            :         cmocka_unit_test(libspdm_test_common_context_data_case2),
+    1557                 :            :         cmocka_unit_test(libspdm_test_common_context_data_case3),
+    1558                 :            :         cmocka_unit_test(libspdm_test_common_context_data_case4),
+    1559                 :            : 
+    1560                 :            :         cmocka_unit_test(libspdm_test_verify_peer_cert_chain_buffer_case5),
+    1561                 :            :         cmocka_unit_test(libspdm_test_verify_peer_cert_chain_buffer_case6),
+    1562                 :            :         cmocka_unit_test(libspdm_test_verify_peer_cert_chain_buffer_case7),
+    1563                 :            :         cmocka_unit_test(libspdm_test_verify_peer_cert_chain_buffer_case8),
+    1564                 :            : 
+    1565                 :            :         cmocka_unit_test(libspdm_test_set_data_case9),
+    1566                 :            : 
+    1567                 :            :         /* Successful response V1.1 for multi element opaque data supported vesion, element number is 2*/
+    1568                 :            :         cmocka_unit_test(libspdm_test_process_opaque_data_supported_version_data_case10),
+    1569                 :            :         /* Failed response V1.1 for multi element opaque data supported vesion, element id is wrong*/
+    1570                 :            :         cmocka_unit_test(libspdm_test_process_opaque_data_supported_version_data_case11),
+    1571                 :            :         /* Successful response V1.2 for multi element opaque data supported vesion, element number is 2*/
+    1572                 :            :         cmocka_unit_test(libspdm_test_process_opaque_data_supported_version_data_case12),
+    1573                 :            :         /* Failed response V1.2 for multi element opaque data supported vesion, element id is wrong*/
+    1574                 :            :         cmocka_unit_test(libspdm_test_process_opaque_data_supported_version_data_case13),
+    1575                 :            :         /* Successful response V1.1 for multi element opaque data selecetion vesion, element number is 2*/
+    1576                 :            :         cmocka_unit_test(libspdm_test_process_opaque_data_selection_version_data_case14),
+    1577                 :            :         /* Failed response V1.1 for multi element opaque data selecetion vesion, element number is wrong*/
+    1578                 :            :         cmocka_unit_test(libspdm_test_process_opaque_data_selection_version_data_case15),
+    1579                 :            :         /* Successful response V1.2 for multi element opaque data selecetion vesion, element number is 2*/
+    1580                 :            :         cmocka_unit_test(libspdm_test_process_opaque_data_selection_version_data_case16),
+    1581                 :            :         /* Failed response V1.2 for multi element opaque data selecetion vesion, element number is wrong*/
+    1582                 :            :         cmocka_unit_test(libspdm_test_process_opaque_data_selection_version_data_case17),
+    1583                 :            : 
+    1584                 :            :         /* Successful initialization and setting of secured message context location. */
+    1585                 :            :         cmocka_unit_test(libspdm_test_secured_message_context_location_selection_case18),
+    1586                 :            : 
+    1587                 :            :         /* Test that the Export Master Secret can be exported and cleared. */
+    1588                 :            :         cmocka_unit_test(libspdm_test_export_master_secret_case19),
+    1589                 :            :         cmocka_unit_test(libspdm_test_check_context_case20),
+    1590                 :            : 
+    1591                 :            :         /* Test the max DHE/PSK session count */
+    1592                 :            :         cmocka_unit_test(libspdm_test_max_session_count_case21),
+    1593                 :            :     };
+    1594                 :            : 
+    1595                 :          1 :     libspdm_setup_test_context(&m_libspdm_common_context_data_test_context);
+    1596                 :            : 
+    1597                 :          1 :     return cmocka_run_group_tests(spdm_common_context_data_tests,
+    1598                 :            :                                   libspdm_unit_test_group_setup,
+    1599                 :            :                                   libspdm_unit_test_group_teardown);
+    1600                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_common/index-sort-b.html b/coverage_log/unit_test/test_spdm_common/index-sort-b.html new file mode 100644 index 00000000000..485da8bde15 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_common/index-sort-b.html @@ -0,0 +1,131 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_common + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_commonHitTotalCoverage
Test:coverage.infoLines:62063697.5 %
Date:2024-09-22 08:21:07Functions:3030100.0 %
Branches:889790.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
test_spdm_common.c +
71.4%71.4%
+
71.4 %5 / 7100.0 %1 / 150.0 %2 / 4
context_data.c +
97.8%97.8%
+
97.8 %609 / 623100.0 %27 / 2792.5 %86 / 93
support.c +
100.0%
+
100.0 %6 / 6100.0 %2 / 2-0 / 0
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_common/index-sort-f.html b/coverage_log/unit_test/test_spdm_common/index-sort-f.html new file mode 100644 index 00000000000..2f0780feeea --- /dev/null +++ b/coverage_log/unit_test/test_spdm_common/index-sort-f.html @@ -0,0 +1,131 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_common + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_commonHitTotalCoverage
Test:coverage.infoLines:62063697.5 %
Date:2024-09-22 08:21:07Functions:3030100.0 %
Branches:889790.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
test_spdm_common.c +
71.4%71.4%
+
71.4 %5 / 7100.0 %1 / 150.0 %2 / 4
support.c +
100.0%
+
100.0 %6 / 6100.0 %2 / 2-0 / 0
context_data.c +
97.8%97.8%
+
97.8 %609 / 623100.0 %27 / 2792.5 %86 / 93
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_common/index-sort-l.html b/coverage_log/unit_test/test_spdm_common/index-sort-l.html new file mode 100644 index 00000000000..509e6c40831 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_common/index-sort-l.html @@ -0,0 +1,131 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_common + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_commonHitTotalCoverage
Test:coverage.infoLines:62063697.5 %
Date:2024-09-22 08:21:07Functions:3030100.0 %
Branches:889790.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
test_spdm_common.c +
71.4%71.4%
+
71.4 %5 / 7100.0 %1 / 150.0 %2 / 4
context_data.c +
97.8%97.8%
+
97.8 %609 / 623100.0 %27 / 2792.5 %86 / 93
support.c +
100.0%
+
100.0 %6 / 6100.0 %2 / 2-0 / 0
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_common/index.html b/coverage_log/unit_test/test_spdm_common/index.html new file mode 100644 index 00000000000..76f916678a7 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_common/index.html @@ -0,0 +1,131 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_common + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_commonHitTotalCoverage
Test:coverage.infoLines:62063697.5 %
Date:2024-09-22 08:21:07Functions:3030100.0 %
Branches:889790.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
context_data.c +
97.8%97.8%
+
97.8 %609 / 623100.0 %27 / 2792.5 %86 / 93
support.c +
100.0%
+
100.0 %6 / 6100.0 %2 / 2-0 / 0
test_spdm_common.c +
71.4%71.4%
+
71.4 %5 / 7100.0 %1 / 150.0 %2 / 4
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_common/support.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_common/support.c.func-sort-c.html new file mode 100644 index 00000000000..0447cbfc96c --- /dev/null +++ b/coverage_log/unit_test/test_spdm_common/support.c.func-sort-c.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_common/support.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_common - support.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:66100.0 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_common_support_test_main1
libspdm_test_common_context_data_case11
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_common/support.c.func.html b/coverage_log/unit_test/test_spdm_common/support.c.func.html new file mode 100644 index 00000000000..7ff47195e5f --- /dev/null +++ b/coverage_log/unit_test/test_spdm_common/support.c.func.html @@ -0,0 +1,89 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_common/support.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_common - support.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:66100.0 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_common_support_test_main1
libspdm_test_common_context_data_case11
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_common/support.c.gcov.html b/coverage_log/unit_test/test_spdm_common/support.c.gcov.html new file mode 100644 index 00000000000..430490ff963 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_common/support.c.gcov.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_common/support.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_common - support.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:66100.0 %
Date:2024-09-22 08:21:07Functions:22100.0 %
Branches:00-
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : #include "spdm_unit_test.h"
+       2                 :            : #include "internal/libspdm_common_lib.h"
+       3                 :            : 
+       4                 :            : /**
+       5                 :            :  * Test 1: Test support functions.
+       6                 :            :  **/
+       7                 :          1 : static void libspdm_test_common_context_data_case1(void **state)
+       8                 :            : {
+       9                 :          1 :     assert_int_equal(0x0001020304050607, libspdm_le_to_be_64(UINT64_C(0x0706050403020100)));
+      10                 :          1 : }
+      11                 :            : 
+      12                 :          1 : int libspdm_common_support_test_main(void)
+      13                 :            : {
+      14                 :          1 :     const struct CMUnitTest spdm_common_context_data_tests[] = {
+      15                 :            :         cmocka_unit_test(libspdm_test_common_context_data_case1),
+      16                 :            : 
+      17                 :            :     };
+      18                 :            : 
+      19                 :          1 :     return cmocka_run_group_tests(spdm_common_context_data_tests,
+      20                 :            :                                   libspdm_unit_test_group_setup,
+      21                 :            :                                   libspdm_unit_test_group_teardown);
+      22                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_common/test_spdm_common.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_common/test_spdm_common.c.func-sort-c.html new file mode 100644 index 00000000000..28363949d5a --- /dev/null +++ b/coverage_log/unit_test/test_spdm_common/test_spdm_common.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_common/test_spdm_common.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_common - test_spdm_common.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:5771.4 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:2450.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
main1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_common/test_spdm_common.c.func.html b/coverage_log/unit_test/test_spdm_common/test_spdm_common.c.func.html new file mode 100644 index 00000000000..b971a862025 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_common/test_spdm_common.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_common/test_spdm_common.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_common - test_spdm_common.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:5771.4 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:2450.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
main1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_common/test_spdm_common.c.gcov.html b/coverage_log/unit_test/test_spdm_common/test_spdm_common.c.gcov.html new file mode 100644 index 00000000000..dc59acf188f --- /dev/null +++ b/coverage_log/unit_test/test_spdm_common/test_spdm_common.c.gcov.html @@ -0,0 +1,109 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_common/test_spdm_common.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_common - test_spdm_common.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:5771.4 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:2450.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 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                 :            : 
+       8                 :            : extern int libspdm_common_context_data_test_main(void);
+       9                 :            : extern int libspdm_common_support_test_main(void);
+      10                 :            : 
+      11                 :          1 : int main(void)
+      12                 :            : {
+      13                 :          1 :     int return_value = 0;
+      14                 :            : 
+      15         [ -  + ]:          1 :     if (libspdm_common_context_data_test_main() != 0) {
+      16                 :          0 :         return_value = 1;
+      17                 :            :     }
+      18                 :            : 
+      19         [ -  + ]:          1 :     if (libspdm_common_support_test_main() != 0) {
+      20                 :          0 :         return_value = 1;
+      21                 :            :     }
+      22                 :            : 
+      23                 :          1 :     return return_value;
+      24                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_crypt/index-sort-b.html b/coverage_log/unit_test/test_spdm_crypt/index-sort-b.html new file mode 100644 index 00000000000..580f1a837e7 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_crypt/index-sort-b.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_crypt + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_cryptHitTotalCoverage
Test:coverage.infoLines:43644398.4 %
Date:2024-09-22 08:21:07Functions:1616100.0 %
Branches:71070.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
test_spdm_crypt.c +
98.4%98.4%
+
98.4 %436 / 443100.0 %16 / 1670.0 %7 / 10
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_crypt/index-sort-f.html b/coverage_log/unit_test/test_spdm_crypt/index-sort-f.html new file mode 100644 index 00000000000..62f5bab3cb2 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_crypt/index-sort-f.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_crypt + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_cryptHitTotalCoverage
Test:coverage.infoLines:43644398.4 %
Date:2024-09-22 08:21:07Functions:1616100.0 %
Branches:71070.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
test_spdm_crypt.c +
98.4%98.4%
+
98.4 %436 / 443100.0 %16 / 1670.0 %7 / 10
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_crypt/index-sort-l.html b/coverage_log/unit_test/test_spdm_crypt/index-sort-l.html new file mode 100644 index 00000000000..94e15c94c02 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_crypt/index-sort-l.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_crypt + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_cryptHitTotalCoverage
Test:coverage.infoLines:43644398.4 %
Date:2024-09-22 08:21:07Functions:1616100.0 %
Branches:71070.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
test_spdm_crypt.c +
98.4%98.4%
+
98.4 %436 / 443100.0 %16 / 1670.0 %7 / 10
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_crypt/index.html b/coverage_log/unit_test/test_spdm_crypt/index.html new file mode 100644 index 00000000000..8031c49c06f --- /dev/null +++ b/coverage_log/unit_test/test_spdm_crypt/index.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_crypt + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_cryptHitTotalCoverage
Test:coverage.infoLines:43644398.4 %
Date:2024-09-22 08:21:07Functions:1616100.0 %
Branches:71070.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
test_spdm_crypt.c +
98.4%98.4%
+
98.4 %436 / 443100.0 %16 / 1670.0 %7 / 10
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_crypt/test_spdm_crypt.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_crypt/test_spdm_crypt.c.func-sort-c.html new file mode 100644 index 00000000000..51f41ce91b6 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_crypt/test_spdm_crypt.c.func-sort-c.html @@ -0,0 +1,145 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_crypt/test_spdm_crypt.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_crypt - test_spdm_crypt.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:43644398.4 %
Date:2024-09-22 08:21:07Functions:1616100.0 %
Branches:71070.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_crypt_lib_setup1
libspdm_crypt_lib_teardown1
libspdm_crypt_lib_test_main1
libspdm_test_crypt_asym_verify1
libspdm_test_crypt_ecdsa_palindrome1
libspdm_test_crypt_palindrome1
libspdm_test_crypt_req_asym_verify1
libspdm_test_crypt_rsa_palindrome1
libspdm_test_crypt_spdm_get_dmtf_subject_alt_name1
libspdm_test_crypt_spdm_get_dmtf_subject_alt_name_from_bytes1
libspdm_test_crypt_spdm_verify_cert_chain_data_ex1
libspdm_test_crypt_spdm_verify_certificate_chain_buffer_ex1
libspdm_test_crypt_spdm_x509_certificate_check1
libspdm_test_crypt_spdm_x509_certificate_check_ex1
libspdm_test_crypt_spdm_x509_set_cert_certificate_check_ex1
main1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_crypt/test_spdm_crypt.c.func.html b/coverage_log/unit_test/test_spdm_crypt/test_spdm_crypt.c.func.html new file mode 100644 index 00000000000..e1192c8e22d --- /dev/null +++ b/coverage_log/unit_test/test_spdm_crypt/test_spdm_crypt.c.func.html @@ -0,0 +1,145 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_crypt/test_spdm_crypt.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_crypt - test_spdm_crypt.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:43644398.4 %
Date:2024-09-22 08:21:07Functions:1616100.0 %
Branches:71070.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_crypt_lib_setup1
libspdm_crypt_lib_teardown1
libspdm_crypt_lib_test_main1
libspdm_test_crypt_asym_verify1
libspdm_test_crypt_ecdsa_palindrome1
libspdm_test_crypt_palindrome1
libspdm_test_crypt_req_asym_verify1
libspdm_test_crypt_rsa_palindrome1
libspdm_test_crypt_spdm_get_dmtf_subject_alt_name1
libspdm_test_crypt_spdm_get_dmtf_subject_alt_name_from_bytes1
libspdm_test_crypt_spdm_verify_cert_chain_data_ex1
libspdm_test_crypt_spdm_verify_certificate_chain_buffer_ex1
libspdm_test_crypt_spdm_x509_certificate_check1
libspdm_test_crypt_spdm_x509_certificate_check_ex1
libspdm_test_crypt_spdm_x509_set_cert_certificate_check_ex1
main1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_crypt/test_spdm_crypt.c.gcov.html b/coverage_log/unit_test/test_spdm_crypt/test_spdm_crypt.c.gcov.html new file mode 100644 index 00000000000..47644e9c324 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_crypt/test_spdm_crypt.c.gcov.html @@ -0,0 +1,1392 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_crypt/test_spdm_crypt.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_crypt - test_spdm_crypt.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:43644398.4 %
Date:2024-09-22 08:21:07Functions:1616100.0 %
Branches:71070.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "library/spdm_common_lib.h"
+       9                 :            : #include "spdm_crypt_ext_lib/spdm_crypt_ext_lib.h"
+      10                 :            : 
+      11                 :            : /* https://lapo.it/asn1js/#MCQGCisGAQQBgxyCEgEMFkFDTUU6V0lER0VUOjEyMzQ1Njc4OTA*/
+      12                 :            : uint8_t m_libspdm_subject_alt_name_buffer1[] = {
+      13                 :            :     0x30, 0x24, 0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83,
+      14                 :            :     0x1C, 0x82, 0x12, 0x01, 0x0C, 0x16, 0x41, 0x43, 0x4D, 0x45,
+      15                 :            :     0x3A, 0x57, 0x49, 0x44, 0x47, 0x45, 0x54, 0x3A, 0x31, 0x32,
+      16                 :            :     0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30
+      17                 :            : };
+      18                 :            : 
+      19                 :            : /* https://lapo.it/asn1js/#MCYGCisGAQQBgxyCEgGgGAwWQUNNRTpXSURHRVQ6MTIzNDU2Nzg5MA*/
+      20                 :            : uint8_t m_libspdm_subject_alt_name_buffer2[] = {
+      21                 :            :     0x30, 0x26, 0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83,
+      22                 :            :     0x1C, 0x82, 0x12, 0x01, 0xA0, 0x18, 0x0C, 0x16, 0x41, 0x43,
+      23                 :            :     0x4D, 0x45, 0x3A, 0x57, 0x49, 0x44, 0x47, 0x45, 0x54, 0x3A,
+      24                 :            :     0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30
+      25                 :            : };
+      26                 :            : 
+      27                 :            : /* https://lapo.it/asn1js/#MCigJgYKKwYBBAGDHIISAaAYDBZBQ01FOldJREdFVDoxMjM0NTY3ODkw*/
+      28                 :            : uint8_t m_libspdm_subject_alt_name_buffer3[] = {
+      29                 :            :     0x30, 0x28, 0xA0, 0x26, 0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01,
+      30                 :            :     0x83, 0x1C, 0x82, 0x12, 0x01, 0xA0, 0x18, 0x0C, 0x16, 0x41, 0x43,
+      31                 :            :     0x4D, 0x45, 0x3A, 0x57, 0x49, 0x44, 0x47, 0x45, 0x54, 0x3A, 0x31,
+      32                 :            :     0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30
+      33                 :            : };
+      34                 :            : 
+      35                 :            : uint8_t m_libspdm_dmtf_oid[] = { 0x2B, 0x06, 0x01, 0x4,  0x01,
+      36                 :            :                                  0x83, 0x1C, 0x82, 0x12, 0x01 };
+      37                 :            : 
+      38                 :          1 : void libspdm_test_crypt_spdm_get_dmtf_subject_alt_name_from_bytes(void **state)
+      39                 :            : {
+      40                 :            :     size_t common_name_size;
+      41                 :            :     char common_name[64];
+      42                 :            :     size_t dmtf_oid_size;
+      43                 :            :     uint8_t dmtf_oid[64];
+      44                 :            :     bool status;
+      45                 :            : 
+      46                 :          1 :     common_name_size = 64;
+      47                 :          1 :     dmtf_oid_size = 64;
+      48                 :          1 :     libspdm_zero_mem(common_name, common_name_size);
+      49                 :          1 :     libspdm_zero_mem(dmtf_oid, dmtf_oid_size);
+      50                 :          1 :     status = libspdm_get_dmtf_subject_alt_name_from_bytes(
+      51                 :            :         m_libspdm_subject_alt_name_buffer1, sizeof(m_libspdm_subject_alt_name_buffer1),
+      52                 :            :         common_name, &common_name_size, dmtf_oid, &dmtf_oid_size);
+      53                 :          1 :     assert_true(status);
+      54                 :          1 :     assert_memory_equal(m_libspdm_dmtf_oid, dmtf_oid, sizeof(m_libspdm_dmtf_oid));
+      55                 :          1 :     assert_string_equal(common_name, "ACME:WIDGET:1234567890");
+      56                 :            : 
+      57                 :          1 :     common_name_size = 64;
+      58                 :          1 :     dmtf_oid_size = 64;
+      59                 :          1 :     libspdm_zero_mem(common_name, common_name_size);
+      60                 :          1 :     libspdm_zero_mem(dmtf_oid, dmtf_oid_size);
+      61                 :          1 :     status = libspdm_get_dmtf_subject_alt_name_from_bytes(
+      62                 :            :         m_libspdm_subject_alt_name_buffer2, sizeof(m_libspdm_subject_alt_name_buffer2),
+      63                 :            :         common_name, &common_name_size, dmtf_oid, &dmtf_oid_size);
+      64                 :          1 :     assert_true(status);
+      65                 :          1 :     assert_memory_equal(m_libspdm_dmtf_oid, dmtf_oid, sizeof(m_libspdm_dmtf_oid));
+      66                 :          1 :     assert_string_equal(common_name, "ACME:WIDGET:1234567890");
+      67                 :            : 
+      68                 :          1 :     common_name_size = 64;
+      69                 :          1 :     dmtf_oid_size = 64;
+      70                 :          1 :     libspdm_zero_mem(common_name, common_name_size);
+      71                 :          1 :     libspdm_zero_mem(dmtf_oid, dmtf_oid_size);
+      72                 :          1 :     status = libspdm_get_dmtf_subject_alt_name_from_bytes(
+      73                 :            :         m_libspdm_subject_alt_name_buffer3, sizeof(m_libspdm_subject_alt_name_buffer3),
+      74                 :            :         common_name, &common_name_size, dmtf_oid, &dmtf_oid_size);
+      75                 :          1 :     assert_true(status);
+      76                 :          1 :     assert_memory_equal(m_libspdm_dmtf_oid, dmtf_oid, sizeof(m_libspdm_dmtf_oid));
+      77                 :          1 :     assert_string_equal(common_name, "ACME:WIDGET:1234567890");
+      78                 :          1 : }
+      79                 :            : 
+      80                 :          1 : void libspdm_test_crypt_spdm_get_dmtf_subject_alt_name(void **state)
+      81                 :            : {
+      82                 :            :     size_t common_name_size;
+      83                 :            :     char common_name[64];
+      84                 :            :     size_t dmtf_oid_size;
+      85                 :            :     uint8_t dmtf_oid[64];
+      86                 :            :     uint8_t *file_buffer;
+      87                 :            :     size_t file_buffer_size;
+      88                 :            :     bool status;
+      89                 :            : 
+      90                 :          1 :     status = libspdm_read_input_file("rsa2048/end_requester.cert.der",
+      91                 :            :                                      (void **)&file_buffer, &file_buffer_size);
+      92                 :          1 :     assert_true(status);
+      93                 :          1 :     dmtf_oid_size = 64;
+      94                 :          1 :     common_name_size = 64;
+      95                 :          1 :     status = libspdm_get_dmtf_subject_alt_name(file_buffer, file_buffer_size,
+      96                 :            :                                                common_name, &common_name_size,
+      97                 :            :                                                dmtf_oid, &dmtf_oid_size);
+      98                 :          1 :     assert_true(status);
+      99                 :          1 :     assert_memory_equal(m_libspdm_dmtf_oid, dmtf_oid, sizeof(m_libspdm_dmtf_oid));
+     100                 :          1 :     assert_string_equal(common_name, "ACME:WIDGET:1234567890");
+     101                 :          1 :     free(file_buffer);
+     102                 :            : 
+     103                 :          1 :     status = libspdm_read_input_file("rsa3072/end_requester.cert.der",
+     104                 :            :                                      (void **)&file_buffer, &file_buffer_size);
+     105                 :          1 :     assert_true(status);
+     106                 :          1 :     dmtf_oid_size = 64;
+     107                 :          1 :     common_name_size = 64;
+     108                 :          1 :     status = libspdm_get_dmtf_subject_alt_name(file_buffer, file_buffer_size,
+     109                 :            :                                                common_name, &common_name_size,
+     110                 :            :                                                dmtf_oid, &dmtf_oid_size);
+     111                 :          1 :     assert_true(status);
+     112                 :          1 :     assert_memory_equal(m_libspdm_dmtf_oid, dmtf_oid, sizeof(m_libspdm_dmtf_oid));
+     113                 :          1 :     assert_string_equal(common_name, "ACME:WIDGET:1234567890");
+     114                 :          1 :     free(file_buffer);
+     115                 :            : 
+     116                 :          1 :     status = libspdm_read_input_file("rsa4096/end_requester.cert.der",
+     117                 :            :                                      (void **)&file_buffer, &file_buffer_size);
+     118                 :          1 :     assert_true(status);
+     119                 :          1 :     dmtf_oid_size = 64;
+     120                 :          1 :     common_name_size = 64;
+     121                 :          1 :     status = libspdm_get_dmtf_subject_alt_name(file_buffer, file_buffer_size,
+     122                 :            :                                                common_name, &common_name_size,
+     123                 :            :                                                dmtf_oid, &dmtf_oid_size);
+     124                 :          1 :     assert_true(status);
+     125                 :          1 :     assert_memory_equal(m_libspdm_dmtf_oid, dmtf_oid, sizeof(m_libspdm_dmtf_oid));
+     126                 :          1 :     assert_string_equal(common_name, "ACME:WIDGET:1234567890");
+     127                 :          1 :     free(file_buffer);
+     128                 :            : 
+     129                 :          1 :     status = libspdm_read_input_file("ecp256/end_requester.cert.der",
+     130                 :            :                                      (void **)&file_buffer, &file_buffer_size);
+     131                 :          1 :     assert_true(status);
+     132                 :          1 :     dmtf_oid_size = 64;
+     133                 :          1 :     common_name_size = 64;
+     134                 :          1 :     status = libspdm_get_dmtf_subject_alt_name(file_buffer, file_buffer_size,
+     135                 :            :                                                common_name, &common_name_size,
+     136                 :            :                                                dmtf_oid, &dmtf_oid_size);
+     137                 :          1 :     assert_true(status);
+     138                 :          1 :     assert_memory_equal(m_libspdm_dmtf_oid, dmtf_oid, sizeof(m_libspdm_dmtf_oid));
+     139                 :          1 :     assert_string_equal(common_name, "ACME:WIDGET:1234567890");
+     140                 :          1 :     free(file_buffer);
+     141                 :            : 
+     142                 :          1 :     status = libspdm_read_input_file("ecp384/end_requester.cert.der",
+     143                 :            :                                      (void **)&file_buffer, &file_buffer_size);
+     144                 :          1 :     assert_true(status);
+     145                 :          1 :     dmtf_oid_size = 64;
+     146                 :          1 :     common_name_size = 64;
+     147                 :          1 :     status = libspdm_get_dmtf_subject_alt_name(file_buffer, file_buffer_size,
+     148                 :            :                                                common_name, &common_name_size,
+     149                 :            :                                                dmtf_oid, &dmtf_oid_size);
+     150                 :          1 :     assert_true(status);
+     151                 :          1 :     assert_memory_equal(m_libspdm_dmtf_oid, dmtf_oid, sizeof(m_libspdm_dmtf_oid));
+     152                 :          1 :     assert_string_equal(common_name, "ACME:WIDGET:1234567890");
+     153                 :          1 :     free(file_buffer);
+     154                 :            : 
+     155                 :          1 :     status = libspdm_read_input_file("ecp521/end_requester.cert.der",
+     156                 :            :                                      (void **)&file_buffer, &file_buffer_size);
+     157                 :          1 :     assert_true(status);
+     158                 :          1 :     dmtf_oid_size = 64;
+     159                 :          1 :     common_name_size = 64;
+     160                 :          1 :     status = libspdm_get_dmtf_subject_alt_name(file_buffer, file_buffer_size,
+     161                 :            :                                                common_name, &common_name_size,
+     162                 :            :                                                dmtf_oid, &dmtf_oid_size);
+     163                 :          1 :     assert_true(status);
+     164                 :          1 :     assert_memory_equal(m_libspdm_dmtf_oid, dmtf_oid, sizeof(m_libspdm_dmtf_oid));
+     165                 :          1 :     assert_string_equal(common_name, "ACME:WIDGET:1234567890");
+     166                 :          1 :     free(file_buffer);
+     167                 :          1 : }
+     168                 :            : 
+     169                 :          1 : void libspdm_test_crypt_spdm_x509_certificate_check(void **state)
+     170                 :            : {
+     171                 :            :     bool status;
+     172                 :            :     uint8_t *file_buffer;
+     173                 :            :     size_t file_buffer_size;
+     174                 :            : 
+     175                 :            :     if ((LIBSPDM_RSA_SSA_2048_SUPPORT) && (LIBSPDM_SHA256_SUPPORT)) {
+     176                 :          1 :         status = libspdm_read_input_file("rsa2048/end_requester.cert.der",
+     177                 :            :                                          (void **)&file_buffer, &file_buffer_size);
+     178                 :          1 :         assert_true(status);
+     179                 :            : 
+     180                 :          1 :         status = libspdm_x509_certificate_check(file_buffer, file_buffer_size,
+     181                 :            :                                                 SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048,
+     182                 :            :                                                 SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     183                 :            :                                                 true, true);
+     184                 :          1 :         assert_true(status);
+     185                 :          1 :         free(file_buffer);
+     186                 :            :     }
+     187                 :            :     if ((LIBSPDM_RSA_SSA_3072_SUPPORT) && (LIBSPDM_SHA384_SUPPORT)) {
+     188                 :          1 :         status = libspdm_read_input_file("rsa3072/end_requester.cert.der",
+     189                 :            :                                          (void **)&file_buffer, &file_buffer_size);
+     190                 :          1 :         assert_true(status);
+     191                 :          1 :         status = libspdm_x509_certificate_check(file_buffer, file_buffer_size,
+     192                 :            :                                                 SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072,
+     193                 :            :                                                 SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_384,
+     194                 :            :                                                 true, true);
+     195                 :          1 :         assert_true(status);
+     196                 :          1 :         free(file_buffer);
+     197                 :            :     }
+     198                 :            :     if ((LIBSPDM_RSA_SSA_4096_SUPPORT) && (LIBSPDM_SHA512_SUPPORT)) {
+     199                 :          1 :         status = libspdm_read_input_file("rsa4096/end_requester.cert.der",
+     200                 :            :                                          (void **)&file_buffer, &file_buffer_size);
+     201                 :          1 :         assert_true(status);
+     202                 :          1 :         status = libspdm_x509_certificate_check(file_buffer, file_buffer_size,
+     203                 :            :                                                 SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096,
+     204                 :            :                                                 SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512,
+     205                 :            :                                                 true, true);
+     206                 :          1 :         assert_true(status);
+     207                 :          1 :         free(file_buffer);
+     208                 :            :     }
+     209                 :            : 
+     210                 :            :     if ((LIBSPDM_ECDSA_P256_SUPPORT) && (LIBSPDM_SHA256_SUPPORT)) {
+     211                 :          1 :         status = libspdm_read_input_file("ecp256/end_requester.cert.der",
+     212                 :            :                                          (void **)&file_buffer, &file_buffer_size);
+     213                 :          1 :         assert_true(status);
+     214                 :          1 :         status = libspdm_x509_certificate_check(file_buffer, file_buffer_size,
+     215                 :            :                                                 SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256,
+     216                 :            :                                                 SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     217                 :            :                                                 true, true);
+     218                 :          1 :         assert_true(status);
+     219                 :          1 :         free(file_buffer);
+     220                 :            :     }
+     221                 :            :     if ((LIBSPDM_ECDSA_P384_SUPPORT) && (LIBSPDM_SHA384_SUPPORT)) {
+     222                 :          1 :         status = libspdm_read_input_file("ecp384/end_requester.cert.der",
+     223                 :            :                                          (void **)&file_buffer, &file_buffer_size);
+     224                 :          1 :         assert_true(status);
+     225                 :          1 :         status = libspdm_x509_certificate_check(file_buffer, file_buffer_size,
+     226                 :            :                                                 SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384,
+     227                 :            :                                                 SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_384,
+     228                 :            :                                                 true, true);
+     229                 :          1 :         assert_true(status);
+     230                 :          1 :         free(file_buffer);
+     231                 :            :     }
+     232                 :            :     if ((LIBSPDM_ECDSA_P521_SUPPORT) && (LIBSPDM_SHA512_SUPPORT)) {
+     233                 :          1 :         status = libspdm_read_input_file("ecp521/end_requester.cert.der",
+     234                 :            :                                          (void **)&file_buffer, &file_buffer_size);
+     235                 :          1 :         assert_true(status);
+     236                 :          1 :         status = libspdm_x509_certificate_check(file_buffer, file_buffer_size,
+     237                 :            :                                                 SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521,
+     238                 :            :                                                 SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512,
+     239                 :            :                                                 true, true);
+     240                 :          1 :         assert_true(status);
+     241                 :          1 :         free(file_buffer);
+     242                 :            :     }
+     243                 :            :     if ((LIBSPDM_ECDSA_P256_SUPPORT) && (LIBSPDM_SHA256_SUPPORT)) {
+     244                 :            :         /*check for leaf cert basic constraints, CA = true,pathlen:none*/
+     245                 :          1 :         status = libspdm_read_input_file("ecp256/end_requester_ca_false.cert.der",
+     246                 :            :                                          (void **)&file_buffer, &file_buffer_size);
+     247                 :          1 :         assert_true(status);
+     248                 :          1 :         status = libspdm_x509_certificate_check(file_buffer, file_buffer_size,
+     249                 :            :                                                 SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256,
+     250                 :            :                                                 SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     251                 :            :                                                 true, true);
+     252                 :          1 :         assert_false(status);
+     253                 :          1 :         free(file_buffer);
+     254                 :            : 
+     255                 :            : 
+     256                 :            :         /*check for leaf cert basic constraints, basic constraints is excluded*/
+     257                 :          1 :         status = libspdm_read_input_file("ecp256/end_requester_without_basic_constraint.cert.der",
+     258                 :            :                                          (void **)&file_buffer, &file_buffer_size);
+     259                 :          1 :         assert_true(status);
+     260                 :          1 :         status = libspdm_x509_certificate_check(file_buffer, file_buffer_size,
+     261                 :            :                                                 SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256,
+     262                 :            :                                                 SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     263                 :            :                                                 true, true);
+     264                 :          1 :         assert_true(status);
+     265                 :          1 :         free(file_buffer);
+     266                 :            :     }
+     267                 :            :     if ((LIBSPDM_RSA_SSA_2048_SUPPORT) && (LIBSPDM_SHA256_SUPPORT)) {
+     268                 :            :         /*check for leaf cert spdm defined eku*/
+     269                 :          1 :         status = libspdm_read_input_file("rsa2048/end_requester_with_spdm_req_rsp_eku.cert.der",
+     270                 :            :                                          (void **)&file_buffer, &file_buffer_size);
+     271                 :          1 :         assert_true(status);
+     272                 :            : 
+     273                 :          1 :         status = libspdm_x509_certificate_check(file_buffer, file_buffer_size,
+     274                 :            :                                                 SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048,
+     275                 :            :                                                 SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     276                 :            :                                                 true, true);
+     277                 :          1 :         assert_true(status);
+     278                 :          1 :         free(file_buffer);
+     279                 :            : 
+     280                 :          1 :         status = libspdm_read_input_file("rsa2048/end_requester_with_spdm_req_eku.cert.der",
+     281                 :            :                                          (void **)&file_buffer, &file_buffer_size);
+     282                 :          1 :         assert_true(status);
+     283                 :            : 
+     284                 :          1 :         status = libspdm_x509_certificate_check(file_buffer, file_buffer_size,
+     285                 :            :                                                 SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048,
+     286                 :            :                                                 SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     287                 :            :                                                 true, true);
+     288                 :          1 :         assert_true(status);
+     289                 :          1 :         free(file_buffer);
+     290                 :            : 
+     291                 :          1 :         status = libspdm_read_input_file("rsa2048/end_requester_with_spdm_rsp_eku.cert.der",
+     292                 :            :                                          (void **)&file_buffer, &file_buffer_size);
+     293                 :          1 :         assert_true(status);
+     294                 :            : 
+     295                 :          1 :         status = libspdm_x509_certificate_check(file_buffer, file_buffer_size,
+     296                 :            :                                                 SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048,
+     297                 :            :                                                 SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     298                 :            :                                                 true, true);
+     299                 :          1 :         assert_false(status);
+     300                 :          1 :         free(file_buffer);
+     301                 :            : 
+     302                 :          1 :         status = libspdm_read_input_file("rsa2048/end_responder_with_spdm_req_rsp_eku.cert.der",
+     303                 :            :                                          (void **)&file_buffer, &file_buffer_size);
+     304                 :          1 :         assert_true(status);
+     305                 :            : 
+     306                 :          1 :         status = libspdm_x509_certificate_check(file_buffer, file_buffer_size,
+     307                 :            :                                                 SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048,
+     308                 :            :                                                 SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     309                 :            :                                                 false, true);
+     310                 :          1 :         assert_true(status);
+     311                 :          1 :         free(file_buffer);
+     312                 :            : 
+     313                 :          1 :         status = libspdm_read_input_file("rsa2048/end_requester_with_spdm_req_eku.cert.der",
+     314                 :            :                                          (void **)&file_buffer, &file_buffer_size);
+     315                 :          1 :         assert_true(status);
+     316                 :            : 
+     317                 :          1 :         status = libspdm_x509_certificate_check(file_buffer, file_buffer_size,
+     318                 :            :                                                 SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048,
+     319                 :            :                                                 SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     320                 :            :                                                 false, true);
+     321                 :          1 :         assert_false(status);
+     322                 :          1 :         free(file_buffer);
+     323                 :            : 
+     324                 :          1 :         status = libspdm_read_input_file("rsa2048/end_requester_with_spdm_rsp_eku.cert.der",
+     325                 :            :                                          (void **)&file_buffer, &file_buffer_size);
+     326                 :          1 :         assert_true(status);
+     327                 :            : 
+     328                 :          1 :         status = libspdm_x509_certificate_check(file_buffer, file_buffer_size,
+     329                 :            :                                                 SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048,
+     330                 :            :                                                 SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     331                 :            :                                                 false, true);
+     332                 :          1 :         assert_true(status);
+     333                 :          1 :         free(file_buffer);
+     334                 :            :     }
+     335                 :            :     if ((LIBSPDM_RSA_SSA_3072_SUPPORT) && (LIBSPDM_SHA256_SUPPORT)) {
+     336                 :            :         /* cert mismatched negotiated base_aysm_algo check */
+     337                 :          1 :         status = libspdm_read_input_file("rsa2048/end_requester.cert.der",
+     338                 :            :                                          (void **)&file_buffer, &file_buffer_size);
+     339                 :          1 :         assert_true(status);
+     340                 :          1 :         status = libspdm_x509_certificate_check(file_buffer, file_buffer_size,
+     341                 :            :                                                 SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072,
+     342                 :            :                                                 SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     343                 :            :                                                 true, true);
+     344                 :          1 :         assert_false(status);
+     345                 :          1 :         free(file_buffer);
+     346                 :            : 
+     347                 :          1 :         status = libspdm_read_input_file("ecp256/end_requester.cert.der",
+     348                 :            :                                          (void **)&file_buffer, &file_buffer_size);
+     349                 :          1 :         assert_true(status);
+     350                 :          1 :         status = libspdm_x509_certificate_check(file_buffer, file_buffer_size,
+     351                 :            :                                                 SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072,
+     352                 :            :                                                 SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     353                 :            :                                                 true, true);
+     354                 :          1 :         assert_false(status);
+     355                 :          1 :         free(file_buffer);
+     356                 :            :     }
+     357                 :            :     if ((LIBSPDM_RSA_SSA_4096_SUPPORT) && (LIBSPDM_SHA256_SUPPORT)) {
+     358                 :            :         /*test web cert: cert public key algo is RSA case*/
+     359                 :          1 :         status = libspdm_read_input_file("test_web_cert/Google.cer",
+     360                 :            :                                          (void **)&file_buffer, &file_buffer_size);
+     361                 :          1 :         assert_true(status);
+     362                 :          1 :         status = libspdm_x509_certificate_check(file_buffer, file_buffer_size,
+     363                 :            :                                                 SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096,
+     364                 :            :                                                 SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     365                 :            :                                                 false, true);
+     366                 :          1 :         assert_true(status);
+     367                 :          1 :         free(file_buffer);
+     368                 :            :     }
+     369                 :            :     if ((LIBSPDM_RSA_SSA_2048_SUPPORT) && (LIBSPDM_SHA256_SUPPORT)) {
+     370                 :          1 :         status = libspdm_read_input_file("test_web_cert/Amazon.cer",
+     371                 :            :                                          (void **)&file_buffer, &file_buffer_size);
+     372                 :          1 :         assert_true(status);
+     373                 :          1 :         status = libspdm_x509_certificate_check(file_buffer, file_buffer_size,
+     374                 :            :                                                 SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048,
+     375                 :            :                                                 SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     376                 :            :                                                 false, true);
+     377                 :          1 :         assert_true(status);
+     378                 :          1 :         free(file_buffer);
+     379                 :            :     }
+     380                 :            : 
+     381                 :            :     if ((LIBSPDM_ECDSA_P256_SUPPORT) && (LIBSPDM_SHA256_SUPPORT)) {
+     382                 :            :         /*test web cert: ccert public key algo is ECC case*/
+     383                 :          1 :         status = libspdm_read_input_file("test_web_cert/GitHub.cer",
+     384                 :            :                                          (void **)&file_buffer, &file_buffer_size);
+     385                 :          1 :         assert_true(status);
+     386                 :          1 :         status = libspdm_x509_certificate_check(file_buffer, file_buffer_size,
+     387                 :            :                                                 SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256,
+     388                 :            :                                                 SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     389                 :            :                                                 false, true);
+     390                 :          1 :         assert_true(status);
+     391                 :          1 :         free(file_buffer);
+     392                 :            :     }
+     393                 :            :     if ((LIBSPDM_ECDSA_P256_SUPPORT) && (LIBSPDM_SHA256_SUPPORT)) {
+     394                 :          1 :         status = libspdm_read_input_file("test_web_cert/YouTube.cer",
+     395                 :            :                                          (void **)&file_buffer, &file_buffer_size);
+     396                 :          1 :         assert_true(status);
+     397                 :          1 :         status = libspdm_x509_certificate_check(file_buffer, file_buffer_size,
+     398                 :            :                                                 SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256,
+     399                 :            :                                                 SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     400                 :            :                                                 false, true);
+     401                 :          1 :         assert_true(status);
+     402                 :          1 :         free(file_buffer);
+     403                 :            :     }
+     404                 :          1 : }
+     405                 :            : 
+     406                 :          1 : void libspdm_test_crypt_spdm_x509_certificate_check_ex(void **state)
+     407                 :            : {
+     408                 :            :     bool status;
+     409                 :            :     uint8_t *file_buffer;
+     410                 :            :     size_t file_buffer_size;
+     411                 :            : 
+     412                 :            :     if ((LIBSPDM_RSA_SSA_2048_SUPPORT) && (LIBSPDM_SHA256_SUPPORT)) {
+     413                 :          1 :         status = libspdm_read_input_file("rsa2048/end_requester.cert.der",
+     414                 :            :                                          (void **)&file_buffer, &file_buffer_size);
+     415                 :          1 :         assert_true(status);
+     416                 :            : 
+     417                 :          1 :         status = libspdm_x509_certificate_check_ex(file_buffer, file_buffer_size,
+     418                 :            :                                                    SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048,
+     419                 :            :                                                    SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     420                 :            :                                                    true,
+     421                 :            :                                                    SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT);
+     422                 :          1 :         assert_true(status);
+     423                 :            : 
+     424                 :          1 :         status = libspdm_x509_certificate_check_ex(file_buffer, file_buffer_size,
+     425                 :            :                                                    SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048,
+     426                 :            :                                                    SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     427                 :            :                                                    true,
+     428                 :            :                                                    SPDM_CERTIFICATE_INFO_CERT_MODEL_ALIAS_CERT);
+     429                 :          1 :         assert_true(status);
+     430                 :          1 :         free(file_buffer);
+     431                 :            :     }
+     432                 :            :     if ((LIBSPDM_ECDSA_P256_SUPPORT) && (LIBSPDM_SHA256_SUPPORT)) {
+     433                 :          1 :         status = libspdm_read_input_file("ecp256/end_responder.cert.der",
+     434                 :            :                                          (void **)&file_buffer, &file_buffer_size);
+     435                 :          1 :         assert_true(status);
+     436                 :          1 :         status = libspdm_x509_certificate_check_ex(file_buffer, file_buffer_size,
+     437                 :            :                                                    SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256,
+     438                 :            :                                                    SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     439                 :            :                                                    false,
+     440                 :            :                                                    SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT);
+     441                 :          1 :         assert_true(status);
+     442                 :            : 
+     443                 :          1 :         status = libspdm_x509_certificate_check_ex(file_buffer, file_buffer_size,
+     444                 :            :                                                    SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256,
+     445                 :            :                                                    SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     446                 :            :                                                    false,
+     447                 :            :                                                    SPDM_CERTIFICATE_INFO_CERT_MODEL_ALIAS_CERT);
+     448                 :          1 :         assert_false(status);
+     449                 :          1 :         free(file_buffer);
+     450                 :            : 
+     451                 :          1 :         status = libspdm_read_input_file("ecp256/end_requester_without_basic_constraint.cert.der",
+     452                 :            :                                          (void **)&file_buffer, &file_buffer_size);
+     453                 :          1 :         assert_true(status);
+     454                 :          1 :         status = libspdm_x509_certificate_check_ex(file_buffer, file_buffer_size,
+     455                 :            :                                                    SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256,
+     456                 :            :                                                    SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     457                 :            :                                                    false,
+     458                 :            :                                                    SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT);
+     459                 :            :         /*the expected result is false, because basic_constraint is mandatory in SPDM 1.3*/
+     460                 :          1 :         assert_false(status);
+     461                 :          1 :         free(file_buffer);
+     462                 :            :     }
+     463                 :            : 
+     464                 :          1 : }
+     465                 :            : 
+     466                 :          1 : void libspdm_test_crypt_spdm_x509_set_cert_certificate_check_ex(void **state)
+     467                 :            : {
+     468                 :            :     bool status;
+     469                 :            :     uint8_t *file_buffer;
+     470                 :            :     size_t file_buffer_size;
+     471                 :            : 
+     472                 :            :     if ((LIBSPDM_RSA_SSA_2048_SUPPORT) && (LIBSPDM_SHA256_SUPPORT)) {
+     473                 :          1 :         status = libspdm_read_input_file("rsa2048/end_responder.cert.der",
+     474                 :            :                                          (void **)&file_buffer, &file_buffer_size);
+     475                 :          1 :         assert_true(status);
+     476                 :            : 
+     477                 :          1 :         status = libspdm_x509_set_cert_certificate_check_ex(file_buffer, file_buffer_size,
+     478                 :            :                                                             SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048,
+     479                 :            :                                                             SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     480                 :            :                                                             false,
+     481                 :            :                                                             SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT);
+     482                 :          1 :         assert_true(status);
+     483                 :            : 
+     484                 :          1 :         status = libspdm_x509_set_cert_certificate_check_ex(file_buffer, file_buffer_size,
+     485                 :            :                                                             SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048,
+     486                 :            :                                                             SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     487                 :            :                                                             false,
+     488                 :            :                                                             SPDM_CERTIFICATE_INFO_CERT_MODEL_ALIAS_CERT);
+     489                 :          1 :         assert_false(status);
+     490                 :          1 :         free(file_buffer);
+     491                 :            :     }
+     492                 :            :     if ((LIBSPDM_ECDSA_P256_SUPPORT) && (LIBSPDM_SHA256_SUPPORT)) {
+     493                 :          1 :         status = libspdm_read_input_file("ecp256/end_requester.cert.der",
+     494                 :            :                                          (void **)&file_buffer, &file_buffer_size);
+     495                 :          1 :         assert_true(status);
+     496                 :          1 :         status = libspdm_x509_set_cert_certificate_check_ex(file_buffer, file_buffer_size,
+     497                 :            :                                                             SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256,
+     498                 :            :                                                             SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     499                 :            :                                                             true,
+     500                 :            :                                                             SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT);
+     501                 :          1 :         assert_true(status);
+     502                 :            : 
+     503                 :          1 :         status = libspdm_x509_set_cert_certificate_check_ex(file_buffer, file_buffer_size,
+     504                 :            :                                                             SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256,
+     505                 :            :                                                             SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     506                 :            :                                                             true,
+     507                 :            :                                                             SPDM_CERTIFICATE_INFO_CERT_MODEL_ALIAS_CERT);
+     508                 :          1 :         assert_false(status);
+     509                 :            : 
+     510                 :          1 :         status = libspdm_read_input_file("ecp256/end_requester_ca_false.cert.der",
+     511                 :            :                                          (void **)&file_buffer, &file_buffer_size);
+     512                 :          1 :         assert_true(status);
+     513                 :          1 :         status = libspdm_x509_set_cert_certificate_check_ex(file_buffer, file_buffer_size,
+     514                 :            :                                                             SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256,
+     515                 :            :                                                             SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     516                 :            :                                                             true,
+     517                 :            :                                                             SPDM_CERTIFICATE_INFO_CERT_MODEL_ALIAS_CERT);
+     518                 :          1 :         assert_true(status);
+     519                 :          1 :         free(file_buffer);
+     520                 :            :     }
+     521                 :            : 
+     522                 :          1 : }
+     523                 :            : 
+     524                 :          1 : void libspdm_test_crypt_spdm_verify_cert_chain_data_ex(void **state)
+     525                 :            : {
+     526                 :            :     bool status;
+     527                 :            :     uint8_t *file_buffer;
+     528                 :            :     size_t file_buffer_size;
+     529                 :            : 
+     530                 :            :     if ((LIBSPDM_RSA_SSA_2048_SUPPORT) && (LIBSPDM_SHA256_SUPPORT)) {
+     531                 :          1 :         status = libspdm_read_input_file("rsa2048/bundle_requester.certchain.der",
+     532                 :            :                                          (void **)&file_buffer, &file_buffer_size);
+     533                 :          1 :         assert_true(status);
+     534                 :            : 
+     535                 :          1 :         status = libspdm_verify_cert_chain_data_ex(file_buffer, file_buffer_size,
+     536                 :            :                                                    SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048,
+     537                 :            :                                                    SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     538                 :            :                                                    true,
+     539                 :            :                                                    SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT);
+     540                 :          1 :         assert_true(status);
+     541                 :            : 
+     542                 :          1 :         status = libspdm_verify_cert_chain_data_ex(file_buffer, file_buffer_size + 1,
+     543                 :            :                                                    SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048,
+     544                 :            :                                                    SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     545                 :            :                                                    true,
+     546                 :            :                                                    SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT);
+     547                 :          1 :         assert_false(status);
+     548                 :            : 
+     549                 :          1 :         status = libspdm_verify_cert_chain_data_ex(file_buffer, file_buffer_size,
+     550                 :            :                                                    SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048,
+     551                 :            :                                                    SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     552                 :            :                                                    true,
+     553                 :            :                                                    SPDM_CERTIFICATE_INFO_CERT_MODEL_ALIAS_CERT);
+     554                 :          1 :         assert_true(status);
+     555                 :          1 :         free(file_buffer);
+     556                 :            :     }
+     557                 :            :     if ((LIBSPDM_ECDSA_P256_SUPPORT) && (LIBSPDM_SHA256_SUPPORT)) {
+     558                 :          1 :         status = libspdm_read_input_file("ecp256/bundle_responder.certchain.der",
+     559                 :            :                                          (void **)&file_buffer, &file_buffer_size);
+     560                 :          1 :         assert_true(status);
+     561                 :          1 :         status = libspdm_verify_cert_chain_data_ex(file_buffer, file_buffer_size,
+     562                 :            :                                                    SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256,
+     563                 :            :                                                    SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     564                 :            :                                                    false,
+     565                 :            :                                                    SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT);
+     566                 :          1 :         assert_true(status);
+     567                 :            : 
+     568                 :          1 :         status = libspdm_verify_cert_chain_data_ex(file_buffer, file_buffer_size + 1,
+     569                 :            :                                                    SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256,
+     570                 :            :                                                    SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     571                 :            :                                                    false,
+     572                 :            :                                                    SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT);
+     573                 :          1 :         assert_false(status);
+     574                 :            : 
+     575                 :          1 :         status = libspdm_verify_cert_chain_data_ex(file_buffer, file_buffer_size,
+     576                 :            :                                                    SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256,
+     577                 :            :                                                    SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     578                 :            :                                                    false,
+     579                 :            :                                                    SPDM_CERTIFICATE_INFO_CERT_MODEL_ALIAS_CERT);
+     580                 :          1 :         assert_false(status);
+     581                 :          1 :         free(file_buffer);
+     582                 :            :     }
+     583                 :          1 : }
+     584                 :            : 
+     585                 :            : 
+     586                 :          1 : void libspdm_test_crypt_spdm_verify_certificate_chain_buffer_ex(void **state)
+     587                 :            : {
+     588                 :            :     bool status;
+     589                 :            :     void *data;
+     590                 :            :     size_t data_size;
+     591                 :            : 
+     592                 :            :     if ((LIBSPDM_RSA_SSA_2048_SUPPORT) && (LIBSPDM_SHA256_SUPPORT)) {
+     593                 :          1 :         libspdm_read_responder_public_certificate_chain(
+     594                 :            :             SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     595                 :            :             SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048,
+     596                 :            :             &data,&data_size,
+     597                 :            :             NULL, NULL);
+     598                 :            : 
+     599                 :          1 :         status = libspdm_verify_certificate_chain_buffer_ex(
+     600                 :            :             SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     601                 :            :             SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048,
+     602                 :            :             data,data_size,
+     603                 :            :             true,
+     604                 :            :             SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT);
+     605                 :          1 :         assert_true(status);
+     606                 :            : 
+     607                 :          1 :         status = libspdm_verify_certificate_chain_buffer_ex(
+     608                 :            :             SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     609                 :            :             SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048,
+     610                 :            :             data,data_size + 1,
+     611                 :            :             true,
+     612                 :            :             SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT);
+     613                 :          1 :         assert_false(status);
+     614                 :            : 
+     615                 :          1 :         status = libspdm_verify_certificate_chain_buffer_ex(
+     616                 :            :             SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     617                 :            :             SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048,
+     618                 :            :             data,data_size,
+     619                 :            :             true,
+     620                 :            :             SPDM_CERTIFICATE_INFO_CERT_MODEL_ALIAS_CERT);
+     621                 :          1 :         assert_true(status);
+     622                 :          1 :         free(data);
+     623                 :            :     }
+     624                 :            : 
+     625                 :            :     if ((LIBSPDM_ECDSA_P256_SUPPORT) && (LIBSPDM_SHA256_SUPPORT)) {
+     626                 :          1 :         libspdm_read_responder_public_certificate_chain(
+     627                 :            :             SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     628                 :            :             SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256,
+     629                 :            :             &data,&data_size,
+     630                 :            :             NULL, NULL);
+     631                 :            : 
+     632                 :          1 :         status = libspdm_verify_certificate_chain_buffer_ex(
+     633                 :            :             SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     634                 :            :             SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256,
+     635                 :            :             data,data_size,
+     636                 :            :             false,
+     637                 :            :             SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT);
+     638                 :          1 :         assert_true(status);
+     639                 :            : 
+     640                 :          1 :         status = libspdm_verify_certificate_chain_buffer_ex(
+     641                 :            :             SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     642                 :            :             SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256,
+     643                 :            :             data,data_size + 1,
+     644                 :            :             false,
+     645                 :            :             SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT);
+     646                 :          1 :         assert_false(status);
+     647                 :            : 
+     648                 :          1 :         status = libspdm_verify_certificate_chain_buffer_ex(
+     649                 :            :             SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     650                 :            :             SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256,
+     651                 :            :             data,data_size,
+     652                 :            :             false,
+     653                 :            :             SPDM_CERTIFICATE_INFO_CERT_MODEL_ALIAS_CERT);
+     654                 :          1 :         assert_false(status);
+     655                 :          1 :         free(data);
+     656                 :            :     }
+     657                 :          1 : }
+     658                 :            : 
+     659                 :          1 : void libspdm_test_crypt_asym_verify(void **state)
+     660                 :            : {
+     661                 :            :     spdm_version_number_t spdm_version;
+     662                 :            :     void *context;
+     663                 :            :     void *data;
+     664                 :            :     size_t data_size;
+     665                 :            :     uint8_t signature[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     666                 :            :     size_t sig_size;
+     667                 :            :     uint8_t signature_endian;
+     668                 :            :     char *file;
+     669                 :            :     bool status;
+     670                 :            : 
+     671                 :          1 :     spdm_version = SPDM_MESSAGE_VERSION_11;
+     672                 :            : 
+     673                 :          1 :     file = "ecp256/end_responder.key";
+     674                 :          1 :     libspdm_read_input_file(file, &data, &data_size);
+     675                 :          1 :     status = libspdm_asym_get_private_key_from_pem(
+     676                 :            :         m_libspdm_use_asym_algo, data, data_size, NULL, &context);
+     677                 :            : 
+     678         [ -  + ]:          1 :     if (!status) {
+     679                 :          0 :         libspdm_zero_mem(data, data_size);
+     680                 :          0 :         free(data);
+     681                 :          0 :         assert_true(status);
+     682                 :            :     }
+     683                 :            : 
+     684                 :          1 :     const uint8_t message[] = {
+     685                 :            :         0x19, 0x90, 0x2d, 0x02, 0x34, 0x6e, 0xd5, 0x90,
+     686                 :            :         0x0e, 0x69, 0x51, 0x2f, 0xf2, 0xbd, 0x9d, 0x33,
+     687                 :            :         0x26, 0x71, 0x8f, 0x62, 0xa0, 0x01, 0xbd, 0xfd,
+     688                 :            :         0x94, 0xe2, 0x98, 0x17, 0x24, 0xfd, 0xca, 0xf0
+     689                 :            :     };
+     690                 :            : 
+     691                 :          1 :     sig_size = libspdm_get_asym_signature_size(m_libspdm_use_req_asym_algo);
+     692                 :            : 
+     693                 :          1 :     libspdm_asym_sign(spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     694                 :            :                       SPDM_MEASUREMENTS,
+     695                 :            :                       m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+     696                 :            :                       context,
+     697                 :            :                       message, sizeof(message),
+     698                 :            :                       signature, &sig_size);
+     699                 :            : 
+     700                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     701                 :            :     status = libspdm_asym_sign(spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     702                 :            :                                SPDM_MEASUREMENTS,
+     703                 :            :                                m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+     704                 :            :                                context,
+     705                 :            :                                message, sizeof(message),
+     706                 :            :                                signature, &sig_size);
+     707                 :            :     assert_true(status);
+     708                 :            : #else
+     709                 :            :     uint8_t message_hash[LIBSPDM_MAX_HASH_SIZE];
+     710                 :          1 :     status = libspdm_hash_all(m_libspdm_use_hash_algo, message, sizeof(message), message_hash);
+     711                 :            : 
+     712                 :          1 :     assert_true(status);
+     713                 :          1 :     status = libspdm_asym_sign_hash(spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     714                 :            :                                     SPDM_MEASUREMENTS,
+     715                 :            :                                     m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+     716                 :            :                                     context,
+     717                 :          1 :                                     message_hash, libspdm_get_hash_size(m_libspdm_use_hash_algo),
+     718                 :            :                                     signature, &sig_size);
+     719                 :          1 :     assert_true(status);
+     720                 :            : #endif
+     721                 :            : 
+     722                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     723                 :            :     /* Big Endian Signature. Big Endian Verify */
+     724                 :            :     signature_endian = LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_ONLY;
+     725                 :            :     status = libspdm_asym_verify_ex(
+     726                 :            :         spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     727                 :            :             SPDM_MEASUREMENTS,
+     728                 :            :             m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+     729                 :            :             context,
+     730                 :            :             message, sizeof(message),
+     731                 :            :             signature, sig_size,
+     732                 :            :             &signature_endian);
+     733                 :            :     assert_true(status);
+     734                 :            :     assert_int_equal(signature_endian, LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_ONLY);
+     735                 :            : 
+     736                 :            :     /*  Error: Big Endian Signature. Little Endian Verify */
+     737                 :            :     signature_endian = LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_LITTLE_ONLY;
+     738                 :            :     status = libspdm_asym_verify_ex(
+     739                 :            :         spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     740                 :            :             SPDM_MEASUREMENTS,
+     741                 :            :             m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+     742                 :            :             context,
+     743                 :            :             message, sizeof(message),
+     744                 :            :             signature, sig_size,
+     745                 :            :             &signature_endian);
+     746                 :            :     assert_true(!status);
+     747                 :            :     assert_int_equal(signature_endian, LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_LITTLE_ONLY);
+     748                 :            : 
+     749                 :            :     /* Big Endian Signature. Big or Little Endian Verify */
+     750                 :            :     signature_endian= LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_OR_LITTLE;
+     751                 :            :     status = libspdm_asym_verify_ex(
+     752                 :            :         spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     753                 :            :             SPDM_MEASUREMENTS,
+     754                 :            :             m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+     755                 :            :             context,
+     756                 :            :             message, sizeof(message),
+     757                 :            :             signature, sig_size,
+     758                 :            :             &signature_endian);
+     759                 :            :     assert_true(status);
+     760                 :            :     assert_int_equal(signature_endian, LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_ONLY);
+     761                 :            : 
+     762                 :            :     libspdm_copy_signature_swap_endian(
+     763                 :            :         m_libspdm_use_asym_algo,
+     764                 :            :         signature, sig_size, signature, sig_size);
+     765                 :            : 
+     766                 :            :     /* Little Endian Signature. Little Endian Verify */
+     767                 :            :     signature_endian = LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_LITTLE_ONLY;
+     768                 :            :     status = libspdm_asym_verify_ex(
+     769                 :            :         spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     770                 :            :             SPDM_MEASUREMENTS,
+     771                 :            :             m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+     772                 :            :             context,
+     773                 :            :             message, sizeof(message),
+     774                 :            :             signature, sig_size,
+     775                 :            :             &signature_endian);
+     776                 :            :     assert_true(status);
+     777                 :            :     assert_int_equal(signature_endian, LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_LITTLE_ONLY);
+     778                 :            : 
+     779                 :            :     /* Error: Little Endian Signature. Big Endian Verify */
+     780                 :            :     signature_endian = LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_ONLY;
+     781                 :            :     status = libspdm_asym_verify_ex(
+     782                 :            :         spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     783                 :            :             SPDM_MEASUREMENTS,
+     784                 :            :             m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+     785                 :            :             context,
+     786                 :            :             message, sizeof(message),
+     787                 :            :             signature, sig_size,
+     788                 :            :             &signature_endian);
+     789                 :            :     assert_true(!status);
+     790                 :            :     assert_int_equal(signature_endian, LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_ONLY);
+     791                 :            : 
+     792                 :            :     /* Little Endian Signature. Big or Little Endian Verify */
+     793                 :            :     signature_endian= LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_OR_LITTLE;
+     794                 :            :     status = libspdm_asym_verify_ex(
+     795                 :            :         spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     796                 :            :             SPDM_MEASUREMENTS,
+     797                 :            :             m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+     798                 :            :             context,
+     799                 :            :             message, sizeof(message),
+     800                 :            :             signature, sig_size,
+     801                 :            :             &signature_endian);
+     802                 :            :     assert_true(status);
+     803                 :            :     assert_int_equal(signature_endian, LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_LITTLE_ONLY);
+     804                 :            : #else
+     805                 :            :     /* Big Endian Signature. Big Endian Verify */
+     806                 :          1 :     signature_endian = LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_ONLY;
+     807                 :          2 :     status = libspdm_asym_verify_hash_ex(
+     808                 :          1 :         spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     809                 :            :             SPDM_MEASUREMENTS,
+     810                 :            :             m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+     811                 :            :             context,
+     812                 :          1 :             message_hash, libspdm_get_hash_size(m_libspdm_use_hash_algo),
+     813                 :            :             signature, sig_size,
+     814                 :            :             &signature_endian);
+     815                 :          1 :     assert_true(status);
+     816                 :          1 :     assert_int_equal(signature_endian, LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_ONLY);
+     817                 :            : 
+     818                 :            :     /*  Error: Big Endian Signature. Little Endian Verify */
+     819                 :          1 :     signature_endian = LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_LITTLE_ONLY;
+     820                 :          2 :     status = libspdm_asym_verify_hash_ex(
+     821                 :          1 :         spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     822                 :            :             SPDM_MEASUREMENTS,
+     823                 :            :             m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+     824                 :            :             context,
+     825                 :          1 :             message_hash, libspdm_get_hash_size(m_libspdm_use_hash_algo),
+     826                 :            :             signature, sig_size,
+     827                 :            :             &signature_endian);
+     828                 :          1 :     assert_true(!status);
+     829                 :          1 :     assert_int_equal(signature_endian, LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_LITTLE_ONLY);
+     830                 :            : 
+     831                 :            :     /* Big Endian Signature. Big or Little Endian Verify */
+     832                 :          1 :     signature_endian= LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_OR_LITTLE;
+     833                 :          2 :     status = libspdm_asym_verify_hash_ex(
+     834                 :          1 :         spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     835                 :            :             SPDM_MEASUREMENTS,
+     836                 :            :             m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+     837                 :            :             context,
+     838                 :          1 :             message_hash, libspdm_get_hash_size(m_libspdm_use_hash_algo),
+     839                 :            :             signature, sig_size,
+     840                 :            :             &signature_endian);
+     841                 :          1 :     assert_true(status);
+     842                 :          1 :     assert_int_equal(signature_endian, LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_ONLY);
+     843                 :            : 
+     844                 :          1 :     libspdm_copy_signature_swap_endian(
+     845                 :            :         m_libspdm_use_asym_algo,
+     846                 :            :         signature, sig_size, signature, sig_size);
+     847                 :            : 
+     848                 :            :     /* Little Endian Signature. Little Endian Verify */
+     849                 :          1 :     signature_endian = LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_LITTLE_ONLY;
+     850                 :          2 :     status = libspdm_asym_verify_hash_ex(
+     851                 :          1 :         spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     852                 :            :             SPDM_MEASUREMENTS,
+     853                 :            :             m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+     854                 :            :             context,
+     855                 :          1 :             message_hash, libspdm_get_hash_size(m_libspdm_use_hash_algo),
+     856                 :            :             signature, sig_size,
+     857                 :            :             &signature_endian);
+     858                 :          1 :     assert_true(status);
+     859                 :          1 :     assert_int_equal(signature_endian, LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_LITTLE_ONLY);
+     860                 :            : 
+     861                 :            :     /* Error: Little Endian Signature. Big Endian Verify */
+     862                 :          1 :     signature_endian = LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_ONLY;
+     863                 :          2 :     status = libspdm_asym_verify_hash_ex(
+     864                 :          1 :         spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     865                 :            :             SPDM_MEASUREMENTS,
+     866                 :            :             m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+     867                 :            :             context,
+     868                 :          1 :             message_hash, libspdm_get_hash_size(m_libspdm_use_hash_algo),
+     869                 :            :             signature, sig_size,
+     870                 :            :             &signature_endian);
+     871                 :          1 :     assert_true(!status);
+     872                 :          1 :     assert_int_equal(signature_endian, LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_ONLY);
+     873                 :            : 
+     874                 :            :     /* Little Endian Signature. Big or Little Endian Verify */
+     875                 :          1 :     signature_endian= LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_OR_LITTLE;
+     876                 :          2 :     status = libspdm_asym_verify_hash_ex(
+     877                 :          1 :         spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     878                 :            :             SPDM_MEASUREMENTS,
+     879                 :            :             m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+     880                 :            :             context,
+     881                 :          1 :             message_hash, libspdm_get_hash_size(m_libspdm_use_hash_algo),
+     882                 :            :             signature, sig_size,
+     883                 :            :             &signature_endian);
+     884                 :          1 :     assert_true(status);
+     885                 :          1 :     assert_int_equal(signature_endian, LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_LITTLE_ONLY);
+     886                 :            : 
+     887                 :            : #endif
+     888                 :          1 : }
+     889                 :            : 
+     890                 :          1 : void libspdm_test_crypt_req_asym_verify(void **state)
+     891                 :            : {
+     892                 :            :     spdm_version_number_t spdm_version;
+     893                 :            :     void *context;
+     894                 :            :     void *data;
+     895                 :            :     size_t data_size;
+     896                 :            :     uint8_t signature[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     897                 :            :     size_t sig_size;
+     898                 :            :     uint8_t signature_endian;
+     899                 :            :     char *file;
+     900                 :            :     bool status;
+     901                 :            : 
+     902                 :          1 :     spdm_version = SPDM_MESSAGE_VERSION_11;
+     903                 :            : 
+     904                 :          1 :     const uint8_t message[] = {
+     905                 :            :         0x19, 0x90, 0x2d, 0x02, 0x34, 0x6e, 0xd5, 0x90,
+     906                 :            :         0x0e, 0x69, 0x51, 0x2f, 0xf2, 0xbd, 0x9d, 0x33,
+     907                 :            :         0x26, 0x71, 0x8f, 0x62, 0xa0, 0x01, 0xbd, 0xfd,
+     908                 :            :         0x94, 0xe2, 0x98, 0x17, 0x24, 0xfd, 0xca, 0xf0
+     909                 :            :     };
+     910                 :            : 
+     911                 :          1 :     file = "rsa2048/end_requester.key";
+     912                 :          1 :     status = libspdm_read_input_file(file, &data, &data_size);
+     913                 :          1 :     assert_true(status);
+     914                 :            : 
+     915                 :          1 :     status = libspdm_req_asym_get_private_key_from_pem(m_libspdm_use_req_asym_algo,
+     916                 :            :                                                        data,
+     917                 :            :                                                        data_size, NULL,
+     918                 :            :                                                        &context);
+     919         [ -  + ]:          1 :     if (!status) {
+     920                 :          0 :         libspdm_zero_mem(data, data_size);
+     921                 :          0 :         free(data);
+     922                 :          0 :         assert_true(status);
+     923                 :            :     }
+     924                 :          1 :     sig_size = libspdm_get_asym_signature_size(m_libspdm_use_req_asym_algo);
+     925                 :            : 
+     926                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     927                 :            :     status = libspdm_req_asym_sign(spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     928                 :            :                                    SPDM_FINISH,
+     929                 :            :                                    m_libspdm_use_req_asym_algo, m_libspdm_use_hash_algo,
+     930                 :            :                                    context,
+     931                 :            :                                    message, sizeof(message),
+     932                 :            :                                    signature, &sig_size);
+     933                 :            :     assert_true(status);
+     934                 :            : #else
+     935                 :            :     uint8_t message_hash[LIBSPDM_MAX_HASH_SIZE];
+     936                 :          1 :     status = libspdm_hash_all(m_libspdm_use_hash_algo, message, sizeof(message), message_hash);
+     937                 :          1 :     assert_true(status);
+     938                 :          1 :     status = libspdm_req_asym_sign_hash(spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     939                 :            :                                         SPDM_FINISH,
+     940                 :            :                                         m_libspdm_use_req_asym_algo,
+     941                 :            :                                         m_libspdm_use_hash_algo, context,
+     942                 :            :                                         message_hash,
+     943                 :          1 :                                         libspdm_get_hash_size(m_libspdm_use_hash_algo),
+     944                 :            :                                         signature,
+     945                 :            :                                         &sig_size);
+     946                 :          1 :     assert_true(status);
+     947                 :            : #endif
+     948                 :            : 
+     949                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     950                 :            :     /* Big Endian Signature. Big Endian Verify */
+     951                 :            :     signature_endian = LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_ONLY;
+     952                 :            :     status = libspdm_req_asym_verify_ex(
+     953                 :            :         spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     954                 :            :             SPDM_FINISH,
+     955                 :            :             m_libspdm_use_req_asym_algo, m_libspdm_use_hash_algo,
+     956                 :            :             context,
+     957                 :            :             message, sizeof(message),
+     958                 :            :             signature, sig_size,
+     959                 :            :             &signature_endian);
+     960                 :            :     assert_true(status);
+     961                 :            :     assert_int_equal(signature_endian, LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_ONLY);
+     962                 :            : 
+     963                 :            :     /*  Error: Big Endian Signature. Little Endian Verify */
+     964                 :            :     signature_endian = LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_LITTLE_ONLY;
+     965                 :            :     status = libspdm_req_asym_verify_ex(
+     966                 :            :         spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     967                 :            :             SPDM_FINISH,
+     968                 :            :             m_libspdm_use_req_asym_algo, m_libspdm_use_hash_algo,
+     969                 :            :             context,
+     970                 :            :             message, sizeof(message),
+     971                 :            :             signature, sig_size,
+     972                 :            :             &signature_endian);
+     973                 :            :     assert_true(!status);
+     974                 :            :     assert_int_equal(signature_endian, LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_LITTLE_ONLY);
+     975                 :            : 
+     976                 :            :     /* Big Endian Signature. Big or Little Endian Verify */
+     977                 :            :     signature_endian= LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_OR_LITTLE;
+     978                 :            :     status = libspdm_req_asym_verify_ex(
+     979                 :            :         spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     980                 :            :             SPDM_FINISH,
+     981                 :            :             m_libspdm_use_req_asym_algo, m_libspdm_use_hash_algo,
+     982                 :            :             context,
+     983                 :            :             message, sizeof(message),
+     984                 :            :             signature, sig_size,
+     985                 :            :             &signature_endian);
+     986                 :            :     assert_true(status);
+     987                 :            :     assert_int_equal(signature_endian, LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_ONLY);
+     988                 :            : 
+     989                 :            :     libspdm_copy_signature_swap_endian(
+     990                 :            :         m_libspdm_use_req_asym_algo,
+     991                 :            :         signature, sig_size, signature, sig_size);
+     992                 :            : 
+     993                 :            :     /* Little Endian Signature. Little Endian Verify */
+     994                 :            :     signature_endian = LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_LITTLE_ONLY;
+     995                 :            :     status = libspdm_req_asym_verify_ex(
+     996                 :            :         spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     997                 :            :             SPDM_FINISH,
+     998                 :            :             m_libspdm_use_req_asym_algo, m_libspdm_use_hash_algo,
+     999                 :            :             context,
+    1000                 :            :             message, sizeof(message),
+    1001                 :            :             signature, sig_size,
+    1002                 :            :             &signature_endian);
+    1003                 :            :     assert_true(status);
+    1004                 :            :     assert_int_equal(signature_endian, LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_LITTLE_ONLY);
+    1005                 :            : 
+    1006                 :            :     /* Error: Little Endian Signature. Big Endian Verify */
+    1007                 :            :     signature_endian = LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_ONLY;
+    1008                 :            :     status = libspdm_req_asym_verify_ex(
+    1009                 :            :         spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    1010                 :            :             SPDM_FINISH,
+    1011                 :            :             m_libspdm_use_req_asym_algo, m_libspdm_use_hash_algo,
+    1012                 :            :             context,
+    1013                 :            :             message, sizeof(message),
+    1014                 :            :             signature, sig_size,
+    1015                 :            :             &signature_endian);
+    1016                 :            :     assert_true(!status);
+    1017                 :            :     assert_int_equal(signature_endian, LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_ONLY);
+    1018                 :            : 
+    1019                 :            :     /* Little Endian Signature. Big or Little Endian Verify */
+    1020                 :            :     signature_endian= LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_OR_LITTLE;
+    1021                 :            :     status = libspdm_req_asym_verify_ex(
+    1022                 :            :         spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    1023                 :            :             SPDM_FINISH,
+    1024                 :            :             m_libspdm_use_req_asym_algo, m_libspdm_use_hash_algo,
+    1025                 :            :             context,
+    1026                 :            :             message, sizeof(message),
+    1027                 :            :             signature, sig_size,
+    1028                 :            :             &signature_endian);
+    1029                 :            :     assert_true(status);
+    1030                 :            :     assert_int_equal(signature_endian, LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_LITTLE_ONLY);
+    1031                 :            : 
+    1032                 :            : #else
+    1033                 :            :     /* Big Endian Signature. Big Endian Verify */
+    1034                 :          1 :     signature_endian = LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_ONLY;
+    1035                 :          2 :     status = libspdm_req_asym_verify_hash_ex(
+    1036                 :          1 :         spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    1037                 :            :             SPDM_FINISH,
+    1038                 :            :             m_libspdm_use_req_asym_algo, m_libspdm_use_hash_algo,
+    1039                 :            :             context,
+    1040                 :          1 :             message_hash, libspdm_get_hash_size(m_libspdm_use_hash_algo),
+    1041                 :            :             signature, sig_size,
+    1042                 :            :             &signature_endian);
+    1043                 :          1 :     assert_true(status);
+    1044                 :          1 :     assert_int_equal(signature_endian, LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_ONLY);
+    1045                 :            : 
+    1046                 :            :     /*  Error: Big Endian Signature. Little Endian Verify */
+    1047                 :          1 :     signature_endian = LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_LITTLE_ONLY;
+    1048                 :          2 :     status = libspdm_req_asym_verify_hash_ex(
+    1049                 :          1 :         spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    1050                 :            :             SPDM_FINISH,
+    1051                 :            :             m_libspdm_use_req_asym_algo, m_libspdm_use_hash_algo,
+    1052                 :            :             context,
+    1053                 :          1 :             message_hash, libspdm_get_hash_size(m_libspdm_use_hash_algo),
+    1054                 :            :             signature, sig_size,
+    1055                 :            :             &signature_endian);
+    1056                 :          1 :     assert_true(!status);
+    1057                 :          1 :     assert_int_equal(signature_endian, LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_LITTLE_ONLY);
+    1058                 :            : 
+    1059                 :            :     /* Big Endian Signature. Big or Little Endian Verify */
+    1060                 :          1 :     signature_endian= LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_OR_LITTLE;
+    1061                 :          2 :     status = libspdm_req_asym_verify_hash_ex(
+    1062                 :          1 :         spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    1063                 :            :             SPDM_FINISH,
+    1064                 :            :             m_libspdm_use_req_asym_algo, m_libspdm_use_hash_algo,
+    1065                 :            :             context,
+    1066                 :          1 :             message_hash, libspdm_get_hash_size(m_libspdm_use_hash_algo),
+    1067                 :            :             signature, sig_size,
+    1068                 :            :             &signature_endian);
+    1069                 :          1 :     assert_true(status);
+    1070                 :          1 :     assert_int_equal(signature_endian, LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_ONLY);
+    1071                 :            : 
+    1072                 :          1 :     libspdm_copy_signature_swap_endian(
+    1073                 :            :         m_libspdm_use_req_asym_algo,
+    1074                 :            :         signature, sig_size, signature, sig_size);
+    1075                 :            : 
+    1076                 :            :     /* Little Endian Signature. Little Endian Verify */
+    1077                 :          1 :     signature_endian = LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_LITTLE_ONLY;
+    1078                 :          2 :     status = libspdm_req_asym_verify_hash_ex(
+    1079                 :          1 :         spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    1080                 :            :             SPDM_FINISH,
+    1081                 :            :             m_libspdm_use_req_asym_algo, m_libspdm_use_hash_algo,
+    1082                 :            :             context,
+    1083                 :          1 :             message_hash, libspdm_get_hash_size(m_libspdm_use_hash_algo),
+    1084                 :            :             signature, sig_size,
+    1085                 :            :             &signature_endian);
+    1086                 :          1 :     assert_true(status);
+    1087                 :          1 :     assert_int_equal(signature_endian, LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_LITTLE_ONLY);
+    1088                 :            : 
+    1089                 :            :     /* Error: Little Endian Signature. Big Endian Verify */
+    1090                 :          1 :     signature_endian = LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_ONLY;
+    1091                 :          2 :     status = libspdm_req_asym_verify_hash_ex(
+    1092                 :          1 :         spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    1093                 :            :             SPDM_FINISH,
+    1094                 :            :             m_libspdm_use_req_asym_algo, m_libspdm_use_hash_algo,
+    1095                 :            :             context,
+    1096                 :          1 :             message_hash, libspdm_get_hash_size(m_libspdm_use_hash_algo),
+    1097                 :            :             signature, sig_size,
+    1098                 :            :             &signature_endian);
+    1099                 :          1 :     assert_true(!status);
+    1100                 :          1 :     assert_int_equal(signature_endian, LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_ONLY);
+    1101                 :            : 
+    1102                 :            :     /* Little Endian Signature. Big or Little Endian Verify */
+    1103                 :          1 :     signature_endian= LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_OR_LITTLE;
+    1104                 :          2 :     status = libspdm_req_asym_verify_hash_ex(
+    1105                 :          1 :         spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    1106                 :            :             SPDM_FINISH,
+    1107                 :            :             m_libspdm_use_req_asym_algo, m_libspdm_use_hash_algo,
+    1108                 :            :             context,
+    1109                 :          1 :             message_hash, libspdm_get_hash_size(m_libspdm_use_hash_algo),
+    1110                 :            :             signature, sig_size,
+    1111                 :            :             &signature_endian);
+    1112                 :          1 :     assert_true(status);
+    1113                 :          1 :     assert_int_equal(signature_endian, LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_LITTLE_ONLY);
+    1114                 :            : #endif
+    1115                 :          1 : }
+    1116                 :            : 
+    1117                 :            : bool libspdm_is_palindrome(const uint8_t *buf, size_t buf_size);
+    1118                 :            : 
+    1119                 :            : bool libspdm_is_signature_buffer_palindrome(
+    1120                 :            :     uint32_t base_asym_algo, const uint8_t *buf, size_t buf_size);
+    1121                 :            : 
+    1122                 :          1 : void libspdm_test_crypt_palindrome(void **state)
+    1123                 :            : {
+    1124                 :            :     bool status;
+    1125                 :            : 
+    1126                 :            :     /* Test valid palindrome with even number of elements */
+    1127                 :          1 :     uint8_t buf1[] = {0, 1, 2, 3, 4, 5, 6, 7, 7, 6, 5, 4, 3, 2, 1, 0};
+    1128                 :          1 :     status = libspdm_is_palindrome(buf1, sizeof(buf1));
+    1129                 :          1 :     assert_true(status);
+    1130                 :            : 
+    1131                 :            :     /* Test valid palindrome with odd number of elements */
+    1132                 :          1 :     uint8_t buf2[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
+    1133                 :          1 :     status = libspdm_is_palindrome(buf2, sizeof(buf2));
+    1134                 :          1 :     assert_true(status);
+    1135                 :            : 
+    1136                 :            :     /* Test invalid palindrome where inner corner-case element is not matching */
+    1137                 :          1 :     uint8_t buf3[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 6, 5, 4, 3, 2, 1, 0 };
+    1138                 :          1 :     status = libspdm_is_palindrome(buf3, sizeof(buf3));
+    1139                 :          1 :     assert_false(status);
+    1140                 :            : 
+    1141                 :            :     /* Test invalid palindrome where outer corner-case element is not matching */
+    1142                 :          1 :     uint8_t buf4[] = { 0, 1, 2, 3, 4, 5, 6, 7, 7, 6, 5, 4, 3, 2, 1, 8 };
+    1143                 :          1 :     status = libspdm_is_palindrome(buf4, sizeof(buf4));
+    1144                 :          1 :     assert_false(status);
+    1145                 :            : 
+    1146                 :            :     /* Test invalid palindrome where middle element is not matching */
+    1147                 :          1 :     uint8_t buf5[] = { 0, 1, 2, 3, 4, 5, 6, 7, 7, 6, 5, 4, 4, 2, 1, 0 };
+    1148                 :          1 :     status = libspdm_is_palindrome(buf5, sizeof(buf5));
+    1149                 :          1 :     assert_false(status);
+    1150                 :          1 : }
+    1151                 :            : 
+    1152                 :          1 : void libspdm_test_crypt_rsa_palindrome(void **state)
+    1153                 :            : {
+    1154                 :            :     /* Test RSA Buffers as palindrone */
+    1155                 :            :     int i;
+    1156                 :            :     bool status;
+    1157                 :            : 
+    1158                 :          1 :     const uint32_t rsa_algos[] = {
+    1159                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048,
+    1160                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048,
+    1161                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072,
+    1162                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072,
+    1163                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096,
+    1164                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096
+    1165                 :            :     };
+    1166                 :            : 
+    1167                 :            :     /* Palindrome for RSA */
+    1168                 :          1 :     uint8_t buf0[] = { 0, 1, 2, 3, 4, 5, 6, 7, 7, 6, 5, 4, 3, 2, 1, 0 };
+    1169                 :            : 
+    1170                 :            :     /* Not Palindrome cases for RSA */
+    1171                 :            : 
+    1172                 :            :     /* Test invalid palindrome where inner corner-case element is not matching */
+    1173                 :          1 :     uint8_t buf1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 6, 5, 4, 3, 2, 1, 0 };
+    1174                 :            : 
+    1175                 :            :     /* Test invalid palindrome where outer corner-case element is not matching */
+    1176                 :          1 :     uint8_t buf2[] = { 0, 1, 2, 3, 4, 5, 6, 7, 7, 6, 5, 4, 3, 2, 1, 8 };
+    1177                 :            : 
+    1178                 :            :     /* Test invalid palindrome where middle element is not matching */
+    1179                 :          1 :     uint8_t buf3[] = { 0, 1, 2, 3, 4, 5, 6, 7, 7, 6, 5, 4, 4, 2, 1, 0 };
+    1180                 :            : 
+    1181                 :            :     /* Test each of these buffers against each RSA algo type */
+    1182         [ +  + ]:          7 :     for (i = 0; i < (sizeof(rsa_algos) / sizeof(rsa_algos[0])); i++) {
+    1183                 :            :         /* Test case where buffer is palindrone */
+    1184                 :          6 :         status = libspdm_is_signature_buffer_palindrome(rsa_algos[i], buf0, sizeof(buf0));
+    1185                 :          6 :         assert_true(status);
+    1186                 :            : 
+    1187                 :            :         /* Test cases where buffer is NOT palindrone */
+    1188                 :          6 :         status = libspdm_is_signature_buffer_palindrome(rsa_algos[i], buf1, sizeof(buf1));
+    1189                 :          6 :         assert_false(status);
+    1190                 :          6 :         status = libspdm_is_signature_buffer_palindrome(rsa_algos[i], buf2, sizeof(buf2));
+    1191                 :          6 :         assert_false(status);
+    1192                 :          6 :         status = libspdm_is_signature_buffer_palindrome(rsa_algos[i], buf3, sizeof(buf3));
+    1193                 :          6 :         assert_false(status);
+    1194                 :            :     }
+    1195                 :          1 : }
+    1196                 :            : 
+    1197                 :          1 : void libspdm_test_crypt_ecdsa_palindrome(void **state)
+    1198                 :            : {
+    1199                 :            :     int i;
+    1200                 :            :     bool status;
+    1201                 :            : 
+    1202                 :            :     /* Test ECDSA Buffers as palindrome */
+    1203                 :          1 :     const uint32_t ecdsa_algos[] = {
+    1204                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256,
+    1205                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384,
+    1206                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521
+    1207                 :            :     };
+    1208                 :            : 
+    1209                 :            :     /* Test for valid ECDSA buffer palindrome */
+    1210                 :          1 :     uint8_t buf0[] = { 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0 };
+    1211                 :            : 
+    1212                 :            :     /* Tests for ECDSA buffer not palidrome */
+    1213                 :            : 
+    1214                 :            :     /* Test for invalid palindrome where outer element of 1st buffer does not match */
+    1215                 :          1 :     uint8_t buf1[] = { 0, 1, 2, 3, 3, 2, 1, 1, 0, 1, 2, 3, 3, 2, 1, 0 };
+    1216                 :            : 
+    1217                 :            :     /* Test for invalid palindrome where outer element of 2nd buffer does not match */
+    1218                 :          1 :     uint8_t buf2[] = { 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 1 };
+    1219                 :            : 
+    1220                 :            :     /* Test for invalid palindrome where inner element of 1st buffer does not match */
+    1221                 :          1 :     uint8_t buf3[] = { 0, 1, 2, 3, 4, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0 };
+    1222                 :            : 
+    1223                 :            :     /* Test for invalid palindrome where inner element of 2nd buffer does not match */
+    1224                 :          1 :     uint8_t buf4[] = { 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 4, 2, 1, 0 };
+    1225                 :            : 
+    1226                 :            :     /* Test for invalid palindrome where middle element of 1st buffer does not match */
+    1227                 :          1 :     uint8_t buf5[] = { 0, 1, 2, 3, 3, 2, 0, 0, 0, 1, 2, 3, 3, 2, 1, 0 };
+    1228                 :            : 
+    1229                 :            :     /* Test for invalid palindrome where middle element of 2nd buffer does not match */
+    1230                 :          1 :     uint8_t buf6[] = { 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 0, 1, 0 };
+    1231                 :            : 
+    1232                 :            :     /* Test each of the buffers against each ECDSA algo type */
+    1233         [ +  + ]:          4 :     for (i = 0; i < (sizeof(ecdsa_algos) / sizeof(ecdsa_algos[0])); i++) {
+    1234                 :            :         /* Test case where buffer is palindrone */
+    1235                 :          3 :         status = libspdm_is_signature_buffer_palindrome(ecdsa_algos[i], buf0, sizeof(buf0));
+    1236                 :          3 :         assert_true(status);
+    1237                 :            : 
+    1238                 :            :         /* Test cases where buffer is NOT palindrone */
+    1239                 :          3 :         status = libspdm_is_signature_buffer_palindrome(ecdsa_algos[i], buf1, sizeof(buf1));
+    1240                 :          3 :         assert_false(status);
+    1241                 :          3 :         status = libspdm_is_signature_buffer_palindrome(ecdsa_algos[i], buf2, sizeof(buf2));
+    1242                 :          3 :         assert_false(status);
+    1243                 :          3 :         status = libspdm_is_signature_buffer_palindrome(ecdsa_algos[i], buf3, sizeof(buf3));
+    1244                 :          3 :         assert_false(status);
+    1245                 :          3 :         status = libspdm_is_signature_buffer_palindrome(ecdsa_algos[i], buf4, sizeof(buf4));
+    1246                 :          3 :         assert_false(status);
+    1247                 :          3 :         status = libspdm_is_signature_buffer_palindrome(ecdsa_algos[i], buf5, sizeof(buf5));
+    1248                 :          3 :         assert_false(status);
+    1249                 :          3 :         status = libspdm_is_signature_buffer_palindrome(ecdsa_algos[i], buf6, sizeof(buf6));
+    1250                 :          3 :         assert_false(status);
+    1251                 :            :     }
+    1252                 :          1 : }
+    1253                 :            : 
+    1254                 :          1 : int libspdm_crypt_lib_setup(void **state)
+    1255                 :            : {
+    1256                 :          1 :     return 0;
+    1257                 :            : }
+    1258                 :            : 
+    1259                 :          1 : int libspdm_crypt_lib_teardown(void **state)
+    1260                 :            : {
+    1261                 :          1 :     return 0;
+    1262                 :            : }
+    1263                 :            : 
+    1264                 :          1 : int libspdm_crypt_lib_test_main(void)
+    1265                 :            : {
+    1266                 :          1 :     const struct CMUnitTest spdm_crypt_lib_tests[] = {
+    1267                 :            :         cmocka_unit_test(
+    1268                 :            :             libspdm_test_crypt_spdm_get_dmtf_subject_alt_name_from_bytes),
+    1269                 :            : 
+    1270                 :            :         cmocka_unit_test(libspdm_test_crypt_spdm_get_dmtf_subject_alt_name),
+    1271                 :            : 
+    1272                 :            :         cmocka_unit_test(libspdm_test_crypt_spdm_x509_certificate_check),
+    1273                 :            : 
+    1274                 :            :         cmocka_unit_test(libspdm_test_crypt_spdm_x509_certificate_check_ex),
+    1275                 :            : 
+    1276                 :            :         cmocka_unit_test(libspdm_test_crypt_spdm_x509_set_cert_certificate_check_ex),
+    1277                 :            : 
+    1278                 :            :         cmocka_unit_test(libspdm_test_crypt_spdm_verify_cert_chain_data_ex),
+    1279                 :            : 
+    1280                 :            :         cmocka_unit_test(libspdm_test_crypt_spdm_verify_certificate_chain_buffer_ex),
+    1281                 :            : 
+    1282                 :            :         cmocka_unit_test(libspdm_test_crypt_asym_verify),
+    1283                 :            : 
+    1284                 :            :         cmocka_unit_test(libspdm_test_crypt_req_asym_verify),
+    1285                 :            : 
+    1286                 :            :         cmocka_unit_test(libspdm_test_crypt_palindrome),
+    1287                 :            : 
+    1288                 :            :         cmocka_unit_test(libspdm_test_crypt_rsa_palindrome),
+    1289                 :            : 
+    1290                 :            :         cmocka_unit_test(libspdm_test_crypt_ecdsa_palindrome),
+    1291                 :            :     };
+    1292                 :            : 
+    1293                 :          1 :     return cmocka_run_group_tests(spdm_crypt_lib_tests,
+    1294                 :            :                                   libspdm_crypt_lib_setup,
+    1295                 :            :                                   libspdm_crypt_lib_teardown);
+    1296                 :            : }
+    1297                 :            : 
+    1298                 :          1 : int main(void)
+    1299                 :            : {
+    1300                 :          1 :     int return_value = 0;
+    1301                 :            : 
+    1302         [ -  + ]:          1 :     if (libspdm_crypt_lib_test_main() != 0) {
+    1303                 :          0 :         return_value = 1;
+    1304                 :            :     }
+    1305                 :            : 
+    1306                 :          1 :     return return_value;
+    1307                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_fips/index-sort-b.html b/coverage_log/unit_test/test_spdm_fips/index-sort-b.html new file mode 100644 index 00000000000..4169a0f527f --- /dev/null +++ b/coverage_log/unit_test/test_spdm_fips/index-sort-b.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_fips + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_fipsHitTotalCoverage
Test:coverage.infoLines:181994.7 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:1250.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
test_spdm_fips.c +
94.7%94.7%
+
94.7 %18 / 19100.0 %5 / 550.0 %1 / 2
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_fips/index-sort-f.html b/coverage_log/unit_test/test_spdm_fips/index-sort-f.html new file mode 100644 index 00000000000..89b897a58e4 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_fips/index-sort-f.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_fips + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_fipsHitTotalCoverage
Test:coverage.infoLines:181994.7 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:1250.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
test_spdm_fips.c +
94.7%94.7%
+
94.7 %18 / 19100.0 %5 / 550.0 %1 / 2
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_fips/index-sort-l.html b/coverage_log/unit_test/test_spdm_fips/index-sort-l.html new file mode 100644 index 00000000000..47b2d63cb52 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_fips/index-sort-l.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_fips + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_fipsHitTotalCoverage
Test:coverage.infoLines:181994.7 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:1250.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
test_spdm_fips.c +
94.7%94.7%
+
94.7 %18 / 19100.0 %5 / 550.0 %1 / 2
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_fips/index.html b/coverage_log/unit_test/test_spdm_fips/index.html new file mode 100644 index 00000000000..d784ef816f4 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_fips/index.html @@ -0,0 +1,107 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_fips + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_fipsHitTotalCoverage
Test:coverage.infoLines:181994.7 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:1250.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
test_spdm_fips.c +
94.7%94.7%
+
94.7 %18 / 19100.0 %5 / 550.0 %1 / 2
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_fips/test_spdm_fips.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_fips/test_spdm_fips.c.func-sort-c.html new file mode 100644 index 00000000000..26b4304c698 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_fips/test_spdm_fips.c.func-sort-c.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_fips/test_spdm_fips.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_fips - test_spdm_fips.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:181994.7 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:1250.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_crypt_lib_setup1
libspdm_crypt_lib_teardown1
libspdm_crypt_lib_test_main1
libspdm_test_fips1
main1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_fips/test_spdm_fips.c.func.html b/coverage_log/unit_test/test_spdm_fips/test_spdm_fips.c.func.html new file mode 100644 index 00000000000..afbbe3aa174 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_fips/test_spdm_fips.c.func.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_fips/test_spdm_fips.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_fips - test_spdm_fips.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:181994.7 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:1250.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_crypt_lib_setup1
libspdm_crypt_lib_teardown1
libspdm_crypt_lib_test_main1
libspdm_test_fips1
main1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_fips/test_spdm_fips.c.gcov.html b/coverage_log/unit_test/test_spdm_fips/test_spdm_fips.c.gcov.html new file mode 100644 index 00000000000..f9ab1253a7e --- /dev/null +++ b/coverage_log/unit_test/test_spdm_fips/test_spdm_fips.c.gcov.html @@ -0,0 +1,145 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_fips/test_spdm_fips.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_fips - test_spdm_fips.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:181994.7 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:1250.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2023 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "library/spdm_crypt_lib.h"
+       9                 :            : #include "internal/libspdm_common_lib.h"
+      10                 :            : 
+      11                 :          1 : void libspdm_test_fips(void **state)
+      12                 :            : {
+      13                 :            :     bool status;
+      14                 :          1 :     status = false;
+      15                 :            : 
+      16                 :            : #if LIBSPDM_FIPS_MODE
+      17                 :            : 
+      18                 :            :     libspdm_fips_selftest_context fips_selftest_context;
+      19                 :          1 :     fips_selftest_context.tested_algo = 0;
+      20                 :          1 :     fips_selftest_context.self_test_result = 0;
+      21                 :            : 
+      22                 :          1 :     status = libspdm_fips_run_selftest(&fips_selftest_context);
+      23                 :          1 :     assert_true(status);
+      24                 :            : #else
+      25                 :            :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "test is valid only when LIBSPDM_FIPS_MODE is open.\n"));
+      26                 :            :     assert_true(status);
+      27                 :            : #endif
+      28                 :          1 : }
+      29                 :            : 
+      30                 :          1 : int libspdm_crypt_lib_setup(void **state)
+      31                 :            : {
+      32                 :          1 :     return 0;
+      33                 :            : }
+      34                 :            : 
+      35                 :          1 : int libspdm_crypt_lib_teardown(void **state)
+      36                 :            : {
+      37                 :          1 :     return 0;
+      38                 :            : }
+      39                 :            : 
+      40                 :          1 : int libspdm_crypt_lib_test_main(void)
+      41                 :            : {
+      42                 :          1 :     const struct CMUnitTest spdm_crypt_lib_tests[] = {
+      43                 :            :         cmocka_unit_test(libspdm_test_fips),
+      44                 :            :     };
+      45                 :            : 
+      46                 :          1 :     return cmocka_run_group_tests(spdm_crypt_lib_tests,
+      47                 :            :                                   libspdm_crypt_lib_setup,
+      48                 :            :                                   libspdm_crypt_lib_teardown);
+      49                 :            : }
+      50                 :            : 
+      51                 :          1 : int main(void)
+      52                 :            : {
+      53                 :          1 :     int return_value = 0;
+      54                 :            : 
+      55         [ -  + ]:          1 :     if (libspdm_crypt_lib_test_main() != 0) {
+      56                 :          0 :         return_value = 1;
+      57                 :            :     }
+      58                 :            : 
+      59                 :          1 :     return return_value;
+      60                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/challenge.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_requester/challenge.c.func-sort-c.html new file mode 100644 index 00000000000..974b38a708e --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/challenge.c.func-sort-c.html @@ -0,0 +1,205 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/challenge.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - challenge.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:1457163489.2 %
Date:2024-09-22 08:21:07Functions:303196.8 %
Branches:657784.4 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_test_requester_challenge_case210
libspdm_requester_challenge_test_main1
libspdm_test_requester_challenge_case11
libspdm_test_requester_challenge_case101
libspdm_test_requester_challenge_case111
libspdm_test_requester_challenge_case121
libspdm_test_requester_challenge_case131
libspdm_test_requester_challenge_case141
libspdm_test_requester_challenge_case151
libspdm_test_requester_challenge_case161
libspdm_test_requester_challenge_case171
libspdm_test_requester_challenge_case181
libspdm_test_requester_challenge_case191
libspdm_test_requester_challenge_case21
libspdm_test_requester_challenge_case201
libspdm_test_requester_challenge_case221
libspdm_test_requester_challenge_case231
libspdm_test_requester_challenge_case241
libspdm_test_requester_challenge_case251
libspdm_test_requester_challenge_case261
libspdm_test_requester_challenge_case271
libspdm_test_requester_challenge_case281
libspdm_test_requester_challenge_case31
libspdm_test_requester_challenge_case41
libspdm_test_requester_challenge_case51
libspdm_test_requester_challenge_case61
libspdm_test_requester_challenge_case71
libspdm_test_requester_challenge_case81
libspdm_test_requester_challenge_case91
libspdm_requester_challenge_test_receive_message44
libspdm_requester_challenge_test_send_message45
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/challenge.c.func.html b/coverage_log/unit_test/test_spdm_requester/challenge.c.func.html new file mode 100644 index 00000000000..2044f015afc --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/challenge.c.func.html @@ -0,0 +1,205 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/challenge.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - challenge.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:1457163489.2 %
Date:2024-09-22 08:21:07Functions:303196.8 %
Branches:657784.4 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_challenge_test_main1
libspdm_requester_challenge_test_receive_message44
libspdm_requester_challenge_test_send_message45
libspdm_test_requester_challenge_case11
libspdm_test_requester_challenge_case101
libspdm_test_requester_challenge_case111
libspdm_test_requester_challenge_case121
libspdm_test_requester_challenge_case131
libspdm_test_requester_challenge_case141
libspdm_test_requester_challenge_case151
libspdm_test_requester_challenge_case161
libspdm_test_requester_challenge_case171
libspdm_test_requester_challenge_case181
libspdm_test_requester_challenge_case191
libspdm_test_requester_challenge_case21
libspdm_test_requester_challenge_case201
libspdm_test_requester_challenge_case210
libspdm_test_requester_challenge_case221
libspdm_test_requester_challenge_case231
libspdm_test_requester_challenge_case241
libspdm_test_requester_challenge_case251
libspdm_test_requester_challenge_case261
libspdm_test_requester_challenge_case271
libspdm_test_requester_challenge_case281
libspdm_test_requester_challenge_case31
libspdm_test_requester_challenge_case41
libspdm_test_requester_challenge_case51
libspdm_test_requester_challenge_case61
libspdm_test_requester_challenge_case71
libspdm_test_requester_challenge_case81
libspdm_test_requester_challenge_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/challenge.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/challenge.c.gcov.html new file mode 100644 index 00000000000..99d60351cdd --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/challenge.c.gcov.html @@ -0,0 +1,4115 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/challenge.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - challenge.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:1457163489.2 %
Date:2024-09-22 08:21:07Functions:303196.8 %
Branches:657784.4 %
+
+ + + + + + + + +

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

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_chunk_get_test_case2_build_measurements_response1
libspdm_requester_chunk_get_test_case3_build_challenge_response1
libspdm_requester_chunk_get_test_case4_build_digest_response1
libspdm_requester_chunk_get_test_main1
libspdm_test_requester_chunk_get_case11
libspdm_test_requester_chunk_get_case21
libspdm_test_requester_chunk_get_case31
libspdm_test_requester_chunk_get_case41
libspdm_requester_chunk_get_test_case1_build_certificates_response2
libspdm_requester_chunk_get_test_receive_message73
libspdm_requester_chunk_get_test_send_message73
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/chunk_get.c.func.html b/coverage_log/unit_test/test_spdm_requester/chunk_get.c.func.html new file mode 100644 index 00000000000..72e5ca24315 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/chunk_get.c.func.html @@ -0,0 +1,125 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/chunk_get.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - chunk_get.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:37738398.4 %
Date:2024-09-22 08:21:07Functions:1111100.0 %
Branches:424887.5 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_chunk_get_test_case1_build_certificates_response2
libspdm_requester_chunk_get_test_case2_build_measurements_response1
libspdm_requester_chunk_get_test_case3_build_challenge_response1
libspdm_requester_chunk_get_test_case4_build_digest_response1
libspdm_requester_chunk_get_test_main1
libspdm_requester_chunk_get_test_receive_message73
libspdm_requester_chunk_get_test_send_message73
libspdm_test_requester_chunk_get_case11
libspdm_test_requester_chunk_get_case21
libspdm_test_requester_chunk_get_case31
libspdm_test_requester_chunk_get_case41
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/chunk_get.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/chunk_get.c.gcov.html new file mode 100644 index 00000000000..f797e568826 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/chunk_get.c.gcov.html @@ -0,0 +1,957 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/chunk_get.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - chunk_get.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:37738398.4 %
Date:2024-09-22 08:21:07Functions:1111100.0 %
Branches:424887.5 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_requester_lib.h"
+       9                 :            : #include "internal/libspdm_secured_message_lib.h"
+      10                 :            : 
+      11                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
+      12                 :            : 
+      13                 :            : static void *m_libspdm_local_certificate_chain_test_case_1;
+      14                 :            : static size_t m_libspdm_local_certificate_chain_size_test_case_1;
+      15                 :            : 
+      16                 :            : static uint8_t m_libspdm_local_large_response_buffer[LIBSPDM_MAX_SPDM_MSG_SIZE];
+      17                 :            : 
+      18                 :            : static size_t m_libspdm_local_buffer_size;
+      19                 :            : static uint8_t m_libspdm_local_buffer[LIBSPDM_MAX_MESSAGE_M1M2_BUFFER_SIZE];
+      20                 :            : 
+      21                 :            : static uint8_t m_libspdm_local_certificate_chain_test_case_4[LIBSPDM_MAX_CERT_CHAIN_SIZE];
+      22                 :            : 
+      23                 :            : /* Override the LIBSPDM_DATA_TRANSFER_SIZE just for the unit tests in this file.
+      24                 :            :  * All other unit tests have the default data transfer size due to the specific
+      25                 :            :  * unit tests requests and responses hardcode for each test case. */
+      26                 :            : #define CHUNK_GET_REQUESTER_UNIT_TEST_DATA_TRANSFER_SIZE (42)
+      27                 :            : 
+      28                 :            : /* Loading the target expiration certificate chain and saving root certificate hash
+      29                 :            :  * "rsa3072_Expiration/bundle_responder.certchain.der"*/
+      30                 :            : bool libspdm_libspdm_read_responder_public_certificate_chain_expiration(
+      31                 :            :     void** data, size_t* size, void** hash, size_t* hash_size);
+      32                 :            : 
+      33                 :            : #define CHUNK_GET_UNIT_TEST_CHUNK_HANDLE (10)
+      34                 :            : 
+      35                 :          2 : void libspdm_requester_chunk_get_test_case1_build_certificates_response(
+      36                 :            :     void *context, void *response, size_t *response_size,
+      37                 :            :     size_t sub_cert_index, size_t *sub_cert_count)
+      38                 :            : {
+      39                 :            :     spdm_certificate_response_t *cert_rsp;
+      40                 :            :     uint16_t sub_cert_portion_length;
+      41                 :            :     uint16_t sub_cert_remainder_length;
+      42                 :            : 
+      43         [ +  + ]:          2 :     if (m_libspdm_local_certificate_chain_test_case_1 == NULL) {
+      44                 :          1 :         libspdm_read_responder_public_certificate_chain(
+      45                 :            :             m_libspdm_use_hash_algo, m_libspdm_use_asym_algo,
+      46                 :            :             &m_libspdm_local_certificate_chain_test_case_1,
+      47                 :            :             &m_libspdm_local_certificate_chain_size_test_case_1, NULL, NULL);
+      48                 :            :     }
+      49         [ -  + ]:          2 :     LIBSPDM_ASSERT(m_libspdm_local_certificate_chain_test_case_1 != NULL);
+      50                 :            : 
+      51                 :          2 :     *sub_cert_count = (m_libspdm_local_certificate_chain_size_test_case_1 +
+      52                 :          2 :                        LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN - 1) /
+      53                 :            :                       LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN;
+      54                 :            : 
+      55         [ +  + ]:          2 :     if (sub_cert_index != *sub_cert_count - 1) {
+      56                 :          1 :         sub_cert_portion_length = LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN;
+      57                 :          1 :         sub_cert_remainder_length =
+      58                 :          1 :             (uint16_t) (m_libspdm_local_certificate_chain_size_test_case_1 -
+      59                 :            :                         LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN *
+      60                 :          1 :                         (sub_cert_index + 1));
+      61                 :            :     } else {
+      62                 :          1 :         sub_cert_portion_length = (uint16_t) (
+      63                 :            :             m_libspdm_local_certificate_chain_size_test_case_1 -
+      64                 :          1 :             LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN * (*sub_cert_count - 1));
+      65                 :          1 :         sub_cert_remainder_length = 0;
+      66                 :            :     }
+      67                 :            : 
+      68                 :          2 :     cert_rsp = (spdm_certificate_response_t*) ((uint8_t*) response);
+      69                 :            : 
+      70                 :          2 :     cert_rsp->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+      71                 :          2 :     cert_rsp->header.request_response_code = SPDM_CERTIFICATE;
+      72                 :          2 :     cert_rsp->header.param1 = 0;
+      73                 :          2 :     cert_rsp->header.param2 = 0;
+      74                 :          2 :     cert_rsp->portion_length = sub_cert_portion_length;
+      75                 :          2 :     cert_rsp->remainder_length = sub_cert_remainder_length;
+      76                 :            : 
+      77                 :          2 :     libspdm_copy_mem(
+      78                 :          2 :         cert_rsp + 1, sub_cert_portion_length,
+      79                 :          2 :         (uint8_t*) m_libspdm_local_certificate_chain_test_case_1 +
+      80                 :          2 :         LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN * sub_cert_index,
+      81                 :            :         sub_cert_portion_length);
+      82                 :            : 
+      83                 :          2 :     *response_size = sizeof(spdm_certificate_response_t) + sub_cert_portion_length;
+      84                 :          2 : }
+      85                 :            : 
+      86                 :          1 : void libspdm_requester_chunk_get_test_case2_build_measurements_response(
+      87                 :            :     void* context, void* response, size_t* response_size)
+      88                 :            : {
+      89                 :            :     libspdm_context_t* spdm_context;
+      90                 :          1 :     spdm_measurements_response_t* meas_rsp = NULL;
+      91                 :            :     spdm_measurement_block_dmtf_t* measurment_block;
+      92                 :            : 
+      93                 :          1 :     spdm_context = (libspdm_context_t*) context;
+      94                 :            :     /* This is get measurements test case 20, but changed to SPDM version 1.2
+      95                 :            :      * which includes opaque data */
+      96                 :            : 
+      97                 :            :     uint8_t* ptr;
+      98                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+      99                 :            :         m_libspdm_use_measurement_hash_algo;
+     100                 :            : 
+     101                 :          1 :     *response_size = sizeof(spdm_measurements_response_t) +
+     102                 :            :                      2 * (sizeof(spdm_measurement_block_dmtf_t) +
+     103                 :          1 :                           libspdm_get_measurement_hash_size(
+     104                 :            :                               m_libspdm_use_measurement_hash_algo)) +
+     105                 :          1 :                      SPDM_NONCE_SIZE + sizeof(uint16_t);
+     106                 :            : 
+     107                 :          1 :     meas_rsp = (spdm_measurements_response_t*)((uint8_t*) response);
+     108                 :          1 :     meas_rsp->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     109                 :          1 :     meas_rsp->header.request_response_code = SPDM_MEASUREMENTS;
+     110                 :          1 :     meas_rsp->header.param1 = 0;
+     111                 :          1 :     meas_rsp->header.param2 = 0;
+     112                 :          1 :     meas_rsp->number_of_blocks = 2;
+     113                 :          1 :     *(uint32_t*) meas_rsp->measurement_record_length =
+     114                 :          1 :         2 * ((uint32_t) (sizeof(spdm_measurement_block_dmtf_t) +
+     115                 :          1 :                          libspdm_get_measurement_hash_size(
+     116                 :            :                              m_libspdm_use_measurement_hash_algo)));
+     117                 :          1 :     measurment_block = (void*) (meas_rsp + 1);
+     118                 :          1 :     libspdm_set_mem(
+     119                 :            :         measurment_block,
+     120                 :          1 :         2 * (sizeof(spdm_measurement_block_dmtf_t) +
+     121                 :          1 :              libspdm_get_measurement_hash_size(
+     122                 :            :                  m_libspdm_use_measurement_hash_algo)),
+     123                 :            :         1);
+     124                 :          1 :     measurment_block->measurement_block_common_header.index = 1;
+     125                 :          1 :     measurment_block->measurement_block_common_header.measurement_specification =
+     126                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     127                 :          1 :     measurment_block->measurement_block_common_header.measurement_size =
+     128                 :          1 :         (uint16_t) (sizeof(spdm_measurement_block_dmtf_header_t) +
+     129                 :          1 :                     libspdm_get_measurement_hash_size(
+     130                 :            :                         m_libspdm_use_measurement_hash_algo));
+     131                 :          1 :     measurment_block =
+     132                 :            :         (void*) (((uint8_t*) measurment_block) +
+     133                 :          1 :                  (sizeof(spdm_measurement_block_dmtf_t) +
+     134                 :          1 :                   libspdm_get_measurement_hash_size(
+     135                 :            :                       m_libspdm_use_measurement_hash_algo)));
+     136                 :          1 :     measurment_block->measurement_block_common_header.index = 2;
+     137                 :          1 :     measurment_block->measurement_block_common_header.measurement_specification =
+     138                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     139                 :          1 :     measurment_block->measurement_block_common_header.measurement_size =
+     140                 :          1 :         (uint16_t) (sizeof(spdm_measurement_block_dmtf_header_t) +
+     141                 :          1 :                     libspdm_get_measurement_hash_size(
+     142                 :            :                         m_libspdm_use_measurement_hash_algo));
+     143                 :          1 :     ptr = (uint8_t*) meas_rsp + *response_size - SPDM_NONCE_SIZE - sizeof(uint16_t);
+     144                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
+     145                 :          1 :     ptr += SPDM_NONCE_SIZE;
+     146                 :            :     /* Set opaque data length to 0 */
+     147                 :          1 :     *ptr = 0;
+     148                 :          1 :     ptr++;
+     149                 :          1 :     *ptr = 0;
+     150                 :          1 : }
+     151                 :            : 
+     152                 :          1 : void libspdm_requester_chunk_get_test_case3_build_challenge_response(
+     153                 :            :     void* context, void* response, size_t* response_size)
+     154                 :            : {
+     155                 :            :     libspdm_context_t* spdm_context;
+     156                 :            :     spdm_challenge_auth_response_t* spdm_response;
+     157                 :            :     void* data;
+     158                 :            :     size_t data_size;
+     159                 :            :     uint8_t* ptr;
+     160                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     161                 :            :     size_t sig_size;
+     162                 :            : 
+     163                 :          1 :     spdm_context = (libspdm_context_t*) context;
+     164                 :          1 :     libspdm_read_responder_public_certificate_chain(
+     165                 :            :         m_libspdm_use_hash_algo,
+     166                 :            :         m_libspdm_use_asym_algo, &data,
+     167                 :            :         &data_size, NULL, NULL);
+     168                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
+     169                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     170                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     171                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     172                 :          1 :     *response_size = sizeof(spdm_challenge_auth_response_t) +
+     173                 :          1 :                      libspdm_get_hash_size(m_libspdm_use_hash_algo) +
+     174                 :          1 :                      SPDM_NONCE_SIZE + 0 + sizeof(uint16_t) + 0 +
+     175                 :          1 :                      libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+     176                 :          1 :     spdm_response = response;
+     177                 :            : 
+     178                 :          1 :     spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     179                 :          1 :     spdm_response->header.request_response_code = SPDM_CHALLENGE_AUTH;
+     180                 :          1 :     spdm_response->header.param1 = 0;
+     181                 :          1 :     spdm_response->header.param2 = (1 << 0);
+     182                 :          1 :     ptr = (void*) (spdm_response + 1);
+     183                 :          1 :     libspdm_hash_all(
+     184                 :            :         m_libspdm_use_hash_algo,
+     185                 :            :         spdm_context->local_context.local_cert_chain_provision[0],
+     186                 :            :         spdm_context->local_context.local_cert_chain_provision_size[0],
+     187                 :            :         ptr);
+     188                 :          1 :     free(data);
+     189                 :          1 :     data = NULL;
+     190                 :            : 
+     191                 :          1 :     ptr += libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     192                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
+     193                 :          1 :     ptr += SPDM_NONCE_SIZE;
+     194                 :            :     /* libspdm_zero_mem (ptr, libspdm_get_hash_size (m_libspdm_use_hash_algo));
+     195                 :            :      * ptr += libspdm_get_hash_size (m_libspdm_use_hash_algo);*/
+     196                 :          1 :     *(uint16_t*) ptr = 0;
+     197                 :          1 :     ptr += sizeof(uint16_t);
+     198                 :            : 
+     199                 :          1 :     libspdm_copy_mem(
+     200                 :          1 :         &m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+     201                 :            :         sizeof(m_libspdm_local_buffer) -
+     202                 :          1 :         (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] - m_libspdm_local_buffer),
+     203                 :          1 :         spdm_response, (size_t) ptr - (size_t) spdm_response);
+     204                 :          1 :     m_libspdm_local_buffer_size += ((size_t) ptr - (size_t) spdm_response);
+     205                 :          1 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+     206                 :            :                    m_libspdm_local_buffer_size));
+     207                 :          1 :     libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+     208                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
+     209                 :            :                      m_libspdm_local_buffer_size, hash_data);
+     210                 :          1 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
+     211                 :            :                    libspdm_get_hash_size(m_libspdm_use_hash_algo)));
+     212                 :          1 :     libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+     213                 :          1 :     sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+     214                 :          1 :     libspdm_responder_data_sign(
+     215                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+     216                 :            :         spdm_context,
+     217                 :            : #endif
+     218                 :          1 :         spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     219                 :            :             SPDM_CHALLENGE_AUTH,
+     220                 :            :             m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+     221                 :            :             false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
+     222                 :            :             ptr, &sig_size);
+     223                 :          1 :     ptr += sig_size;
+     224                 :          1 : }
+     225                 :            : 
+     226                 :          1 : void libspdm_requester_chunk_get_test_case4_build_digest_response(
+     227                 :            :     void* context, void* response, size_t* response_size)
+     228                 :            : {
+     229                 :            :     libspdm_context_t *spdm_context;
+     230                 :            :     spdm_digest_response_t* spdm_response;
+     231                 :            :     uint8_t* digest;
+     232                 :            :     uint8_t slot_id;
+     233                 :            : 
+     234                 :          1 :     spdm_context = (libspdm_context_t*)context;
+     235                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     236                 :            :         m_libspdm_use_hash_algo;
+     237                 :          1 :     *response_size = sizeof(spdm_digest_response_t) +
+     238                 :          1 :                      libspdm_get_hash_size(m_libspdm_use_hash_algo) * SPDM_MAX_SLOT_COUNT;
+     239                 :          1 :     spdm_response = response;
+     240                 :            : 
+     241                 :          1 :     spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     242                 :          1 :     spdm_response->header.param1 = 0;
+     243                 :          1 :     spdm_response->header.request_response_code = SPDM_DIGESTS;
+     244                 :          1 :     spdm_response->header.param2 = 0;
+     245                 :          1 :     libspdm_set_mem(m_libspdm_local_certificate_chain_test_case_4,
+     246                 :            :                     sizeof(m_libspdm_local_certificate_chain_test_case_4),
+     247                 :            :                     (uint8_t) (0xFF));
+     248                 :            : 
+     249                 :          1 :     digest = (void*) (spdm_response + 1);
+     250                 :          1 :     libspdm_zero_mem(digest,
+     251                 :          1 :                      libspdm_get_hash_size(m_libspdm_use_hash_algo) * SPDM_MAX_SLOT_COUNT);
+     252         [ +  + ]:          9 :     for (slot_id = 0; slot_id < SPDM_MAX_SLOT_COUNT; slot_id++) {
+     253                 :          8 :         libspdm_hash_all(
+     254                 :            :             m_libspdm_use_hash_algo,
+     255                 :            :             m_libspdm_local_certificate_chain_test_case_4,
+     256                 :            :             sizeof(m_libspdm_local_certificate_chain_test_case_4), &digest[0]);
+     257                 :          8 :         digest += libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     258                 :            :     }
+     259                 :          1 :     spdm_response->header.param2 |= (0xFF << 0);
+     260                 :          1 : }
+     261                 :            : 
+     262                 :         73 : libspdm_return_t libspdm_requester_chunk_get_test_send_message(
+     263                 :            :     void* spdm_context, size_t request_size, const void* request,
+     264                 :            :     uint64_t timeout)
+     265                 :            : {
+     266                 :            :     libspdm_test_context_t* spdm_test_context;
+     267                 :            : 
+     268                 :         73 :     spdm_test_context = libspdm_get_test_context();
+     269         [ +  + ]:         73 :     if (spdm_test_context->case_id == 0x1) {
+     270                 :         50 :         return LIBSPDM_STATUS_SUCCESS;
+     271         [ +  + ]:         23 :     } else if (spdm_test_context->case_id == 0x2) {
+     272                 :          7 :         return LIBSPDM_STATUS_SUCCESS;
+     273         [ +  + ]:         16 :     } else if (spdm_test_context->case_id == 0x3) {
+     274                 :            :         const uint8_t* ptr;
+     275                 :          6 :         ptr = (const uint8_t*) request;
+     276                 :            : 
+     277         [ +  + ]:          6 :         if (ptr[2] == SPDM_CHALLENGE) {
+     278                 :          1 :             m_libspdm_local_buffer_size = 0;
+     279                 :          1 :             libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     280                 :          1 :                              &ptr[1], request_size - 1);
+     281                 :          1 :             m_libspdm_local_buffer_size += (request_size - 1);
+     282                 :            :         }
+     283                 :          6 :         return LIBSPDM_STATUS_SUCCESS;
+     284         [ +  - ]:         10 :     } else if (spdm_test_context->case_id == 0x4) {
+     285                 :         10 :         return LIBSPDM_STATUS_SUCCESS;
+     286         [ #  # ]:          0 :     } else if (spdm_test_context->case_id == 0x5) {
+     287                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     288                 :            :     } else {
+     289                 :          0 :         return LIBSPDM_STATUS_SEND_FAIL;
+     290                 :            :     }
+     291                 :            : }
+     292                 :            : 
+     293                 :         73 : libspdm_return_t libspdm_requester_chunk_get_test_receive_message(
+     294                 :            :     void* spdm_context, size_t* response_size,
+     295                 :            :     void** response, uint64_t timeout)
+     296                 :            : {
+     297                 :            :     libspdm_test_context_t* spdm_test_context;
+     298                 :         73 :     uint8_t chunk_handle = CHUNK_GET_UNIT_TEST_CHUNK_HANDLE;
+     299                 :            :     static bool error_large_response_sent = false;
+     300                 :            : 
+     301                 :            :     static spdm_message_header_t* sub_rsp = NULL;
+     302                 :            :     static size_t sub_rsp_size = 0;
+     303                 :            :     static size_t sub_rsp_copied = 0;
+     304                 :            :     static size_t sub_rsp_remaining = 0;
+     305                 :            :     static uint16_t chunk_seq_no = 0;
+     306                 :            : 
+     307                 :            :     spdm_chunk_response_response_t* chunk_rsp;
+     308                 :            :     size_t chunk_rsp_size;
+     309                 :            :     uint8_t* chunk_copy_to;
+     310                 :            :     size_t chunk_copy_size;
+     311                 :            :     size_t transport_header_size;
+     312                 :            :     void (*build_response_func)(void*, void*, size_t *);
+     313                 :            : 
+     314                 :         73 :     build_response_func = NULL;
+     315                 :            : 
+     316                 :         73 :     spdm_test_context = libspdm_get_test_context();
+     317                 :            : 
+     318                 :            :     /* First response to these tests should always be error large response */
+     319         [ +  + ]:         73 :     if (error_large_response_sent == false) {
+     320                 :          5 :         error_large_response_sent = true;
+     321                 :            : 
+     322                 :            :         spdm_error_response_t* error_rsp;
+     323                 :            :         size_t error_rsp_size;
+     324                 :            : 
+     325                 :          5 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     326                 :          5 :         error_rsp = (void*) ((uint8_t*) *response + transport_header_size);
+     327                 :          5 :         error_rsp_size = sizeof(spdm_error_response_t) + sizeof(uint8_t);
+     328                 :            : 
+     329                 :          5 :         error_rsp->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     330                 :          5 :         error_rsp->header.request_response_code = SPDM_ERROR;
+     331                 :          5 :         error_rsp->header.param1 = SPDM_ERROR_CODE_LARGE_RESPONSE;
+     332                 :          5 :         error_rsp->header.param2 = 0;
+     333                 :          5 :         *((uint16_t*) (error_rsp + 1)) = chunk_handle;
+     334                 :            : 
+     335                 :          5 :         libspdm_transport_test_encode_message(
+     336                 :            :             spdm_context, NULL, false, false,
+     337                 :            :             error_rsp_size, error_rsp,
+     338                 :            :             response_size, response);
+     339                 :            : 
+     340                 :          5 :         return LIBSPDM_STATUS_SUCCESS;
+     341                 :            :     }
+     342                 :            : 
+     343         [ +  + ]:         68 :     if (spdm_test_context->case_id == 0x1) {
+     344                 :            : 
+     345                 :            :         /* Refers to just the certificate portion in the cert response */
+     346                 :            :         static size_t sub_cert_index = 0;
+     347                 :            :         static size_t sub_cert_count = 0;
+     348                 :            : 
+     349                 :         48 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     350                 :         48 :         chunk_rsp = (void*) ((uint8_t*) *response + transport_header_size);
+     351                 :            : 
+     352                 :         48 :         chunk_rsp->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     353                 :         48 :         chunk_rsp->header.request_response_code = SPDM_CHUNK_RESPONSE;
+     354                 :         48 :         chunk_rsp->header.param1 = 0;
+     355                 :         48 :         chunk_rsp->header.param2 = chunk_handle;
+     356                 :            : 
+     357                 :         48 :         chunk_copy_to = (uint8_t*) (chunk_rsp + 1);
+     358                 :         48 :         chunk_copy_size = CHUNK_GET_REQUESTER_UNIT_TEST_DATA_TRANSFER_SIZE
+     359                 :            :                           - sizeof(spdm_chunk_response_response_t);
+     360                 :            : 
+     361         [ +  + ]:         48 :         if (sub_rsp_copied == 0) {
+     362                 :          2 :             sub_rsp = (spdm_message_header_t*) m_libspdm_local_large_response_buffer;
+     363                 :          2 :             sub_rsp_size = sizeof(m_libspdm_local_large_response_buffer);
+     364                 :          2 :             libspdm_zero_mem(sub_rsp, sub_rsp_size);
+     365                 :            : 
+     366                 :          2 :             libspdm_requester_chunk_get_test_case1_build_certificates_response(
+     367                 :            :                 spdm_context, sub_rsp, &sub_rsp_size, sub_cert_index, &sub_cert_count);
+     368                 :            : 
+     369                 :          2 :             sub_rsp_remaining = sub_rsp_size;
+     370                 :          2 :             sub_rsp_copied = 0;
+     371                 :            : 
+     372                 :            :             /* first chunk has size of large response */
+     373                 :          2 :             chunk_seq_no = 0;
+     374                 :          2 :             *((uint32_t*) (chunk_rsp + 1)) = (uint32_t) sub_rsp_size;
+     375                 :            : 
+     376                 :          2 :             chunk_copy_to += sizeof(uint32_t);
+     377                 :          2 :             chunk_copy_size -= sizeof(uint32_t);
+     378                 :          2 :             chunk_copy_size = LIBSPDM_MIN(sub_rsp_remaining, chunk_copy_size);
+     379                 :          2 :             chunk_rsp_size = sizeof(spdm_chunk_response_response_t)
+     380                 :            :                              + sizeof(uint32_t) + chunk_copy_size;
+     381                 :            :         } else {
+     382                 :         46 :             chunk_copy_size = LIBSPDM_MIN(sub_rsp_remaining, chunk_copy_size);
+     383                 :         46 :             chunk_rsp_size = sizeof(spdm_chunk_response_response_t) + chunk_copy_size;
+     384                 :            :         }
+     385                 :            : 
+     386         [ +  + ]:         48 :         if (chunk_copy_size == sub_rsp_remaining) {
+     387                 :          2 :             chunk_rsp->header.param1 = SPDM_CHUNK_GET_RESPONSE_ATTRIBUTE_LAST_CHUNK;
+     388                 :            :         }
+     389                 :            : 
+     390                 :         48 :         libspdm_copy_mem(chunk_copy_to,
+     391                 :         48 :                          *response_size - (chunk_copy_to - (uint8_t*)*response),
+     392                 :         48 :                          (uint8_t*) sub_rsp + sub_rsp_copied,
+     393                 :            :                          chunk_copy_size);
+     394                 :            : 
+     395                 :         48 :         sub_rsp_copied += chunk_copy_size;
+     396                 :         48 :         sub_rsp_remaining -= chunk_copy_size;
+     397                 :         48 :         chunk_rsp->chunk_size = (uint32_t) chunk_copy_size;
+     398                 :         48 :         chunk_rsp->chunk_seq_no = chunk_seq_no;
+     399                 :         48 :         chunk_seq_no++;
+     400                 :            : 
+     401                 :         48 :         libspdm_transport_test_encode_message(
+     402                 :            :             spdm_context, NULL, false, false,
+     403                 :            :             chunk_rsp_size, chunk_rsp,
+     404                 :            :             response_size, response);
+     405                 :            : 
+     406         [ +  + ]:         48 :         if (sub_rsp_copied >= sub_rsp_size) {
+     407                 :          2 :             sub_cert_index++;
+     408                 :          2 :             sub_rsp = NULL;
+     409                 :          2 :             sub_rsp_size = 0;
+     410                 :          2 :             sub_rsp_copied = 0;
+     411                 :          2 :             sub_rsp_remaining = 0;
+     412                 :          2 :             chunk_seq_no = 0;
+     413                 :          2 :             error_large_response_sent = false;
+     414                 :            : 
+     415         [ +  + ]:          2 :             if (sub_cert_index == sub_cert_count) {
+     416                 :          1 :                 sub_cert_index = 0;
+     417                 :            : 
+     418                 :          1 :                 free(m_libspdm_local_certificate_chain_test_case_1);
+     419                 :          1 :                 m_libspdm_local_certificate_chain_test_case_1 = NULL;
+     420                 :          1 :                 m_libspdm_local_certificate_chain_size_test_case_1 = 0;
+     421                 :            :             }
+     422                 :            :         }
+     423                 :            : 
+     424                 :         48 :         return LIBSPDM_STATUS_SUCCESS;
+     425         [ +  + ]:         20 :     } else if (spdm_test_context->case_id == 0x2) {
+     426                 :          6 :         build_response_func =
+     427                 :            :             libspdm_requester_chunk_get_test_case2_build_measurements_response;
+     428         [ +  + ]:         14 :     } else if (spdm_test_context->case_id == 0x3) {
+     429                 :          5 :         build_response_func =
+     430                 :            :             libspdm_requester_chunk_get_test_case3_build_challenge_response;
+     431         [ +  - ]:          9 :     } else if (spdm_test_context->case_id == 0x4) {
+     432                 :          9 :         build_response_func =
+     433                 :            :             libspdm_requester_chunk_get_test_case4_build_digest_response;
+     434                 :            :     } else {
+     435                 :          0 :         LIBSPDM_ASSERT(0);
+     436                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+     437                 :            :     }
+     438                 :            : 
+     439         [ +  - ]:         20 :     if (build_response_func) {
+     440                 :         20 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     441                 :         20 :         chunk_rsp = (void*) ((uint8_t*) *response + transport_header_size);
+     442                 :            : 
+     443                 :         20 :         chunk_rsp->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     444                 :         20 :         chunk_rsp->header.request_response_code = SPDM_CHUNK_RESPONSE;
+     445                 :         20 :         chunk_rsp->header.param1 = 0;
+     446                 :         20 :         chunk_rsp->header.param2 = chunk_handle;
+     447                 :            : 
+     448                 :         20 :         chunk_copy_to = (uint8_t*) (chunk_rsp + 1);
+     449                 :         20 :         chunk_copy_size = CHUNK_GET_REQUESTER_UNIT_TEST_DATA_TRANSFER_SIZE
+     450                 :            :                           - sizeof(spdm_chunk_response_response_t);
+     451                 :            : 
+     452         [ +  + ]:         20 :         if (sub_rsp_copied == 0) {
+     453                 :            : 
+     454                 :          3 :             sub_rsp = (spdm_message_header_t*) m_libspdm_local_large_response_buffer;
+     455                 :          3 :             sub_rsp_size = sizeof(m_libspdm_local_large_response_buffer);
+     456                 :          3 :             libspdm_zero_mem(sub_rsp, sub_rsp_size);
+     457                 :            : 
+     458                 :          3 :             build_response_func(spdm_context, sub_rsp, &sub_rsp_size);
+     459                 :            : 
+     460                 :          3 :             sub_rsp_remaining = sub_rsp_size;
+     461                 :          3 :             sub_rsp_copied = 0;
+     462                 :            : 
+     463                 :            :             /* first chunk has size of large response */
+     464                 :          3 :             chunk_seq_no = 0;
+     465                 :          3 :             *((uint32_t*) (chunk_rsp + 1)) = (uint32_t) sub_rsp_size;
+     466                 :            : 
+     467                 :          3 :             chunk_copy_to += sizeof(uint32_t);
+     468                 :          3 :             chunk_copy_size -= sizeof(uint32_t);
+     469                 :          3 :             chunk_copy_size = LIBSPDM_MIN(sub_rsp_remaining, chunk_copy_size);
+     470                 :          3 :             chunk_rsp_size = sizeof(spdm_chunk_response_response_t)
+     471                 :            :                              + sizeof(uint32_t) + chunk_copy_size;
+     472                 :            :         } else {
+     473                 :         17 :             chunk_copy_size = LIBSPDM_MIN(sub_rsp_remaining, chunk_copy_size);
+     474                 :         17 :             chunk_rsp_size = sizeof(spdm_chunk_response_response_t) + chunk_copy_size;
+     475                 :            :         }
+     476                 :            : 
+     477         [ +  + ]:         20 :         if (chunk_copy_size == sub_rsp_remaining) {
+     478                 :          3 :             chunk_rsp->header.param1 = SPDM_CHUNK_GET_RESPONSE_ATTRIBUTE_LAST_CHUNK;
+     479                 :            :         }
+     480                 :            : 
+     481                 :         20 :         libspdm_copy_mem(chunk_copy_to,
+     482                 :         20 :                          *response_size - (chunk_copy_to - (uint8_t*) *response),
+     483                 :         20 :                          (uint8_t*) sub_rsp + sub_rsp_copied,
+     484                 :            :                          chunk_copy_size);
+     485                 :            : 
+     486                 :         20 :         sub_rsp_copied += chunk_copy_size;
+     487                 :         20 :         sub_rsp_remaining -= chunk_copy_size;
+     488                 :         20 :         chunk_rsp->chunk_size = (uint32_t) chunk_copy_size;
+     489                 :         20 :         chunk_rsp->chunk_seq_no = chunk_seq_no++;
+     490                 :            : 
+     491                 :         20 :         libspdm_transport_test_encode_message(
+     492                 :            :             spdm_context, NULL, false, false,
+     493                 :            :             chunk_rsp_size, chunk_rsp,
+     494                 :            :             response_size, response);
+     495                 :            : 
+     496         [ +  + ]:         20 :         if (sub_rsp_copied >= sub_rsp_size) {
+     497                 :          3 :             sub_rsp = NULL;
+     498                 :          3 :             sub_rsp_size = 0;
+     499                 :          3 :             sub_rsp_copied = 0;
+     500                 :          3 :             sub_rsp_remaining = 0;
+     501                 :          3 :             chunk_seq_no = 0;
+     502                 :          3 :             error_large_response_sent = false;
+     503                 :            :         }
+     504                 :         20 :         return LIBSPDM_STATUS_SUCCESS;
+     505                 :            :     }
+     506                 :          0 :     return LIBSPDM_STATUS_SEND_FAIL;
+     507                 :            : 
+     508                 :            : }
+     509                 :            : #if LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT
+     510                 :          1 : void libspdm_test_requester_chunk_get_case1(void** state)
+     511                 :            : {
+     512                 :            :     libspdm_return_t status;
+     513                 :            :     libspdm_test_context_t* spdm_test_context;
+     514                 :            :     libspdm_context_t* spdm_context;
+     515                 :            :     size_t cert_chain_size;
+     516                 :            :     uint8_t cert_chain[LIBSPDM_MAX_CERT_CHAIN_SIZE];
+     517                 :            :     void* data;
+     518                 :            :     size_t data_size;
+     519                 :            :     void* hash;
+     520                 :            :     size_t hash_size;
+     521                 :            :     const uint8_t* root_cert;
+     522                 :            :     size_t root_cert_size;
+     523                 :            :     #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     524                 :            :     size_t count;
+     525                 :            :     #endif
+     526                 :            : 
+     527                 :          1 :     spdm_test_context = *state;
+     528                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     529                 :          1 :     spdm_test_context->case_id = 0x1;
+     530                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     531                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     532                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_DIGESTS;
+     533                 :          1 :     spdm_context->connection_info.capability.flags |=
+     534                 :            :         (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP
+     535                 :            :          | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP
+     536                 :            :          | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP);
+     537                 :            : 
+     538                 :          1 :     spdm_context->local_context.capability.flags |=  SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP;
+     539                 :            :     spdm_context->local_context.capability.data_transfer_size
+     540                 :          1 :         = CHUNK_GET_REQUESTER_UNIT_TEST_DATA_TRANSFER_SIZE;
+     541                 :          1 :     spdm_context->local_context.is_requester = true;
+     542                 :            : 
+     543                 :          1 :     libspdm_read_responder_public_certificate_chain(
+     544                 :            :         m_libspdm_use_hash_algo,
+     545                 :            :         m_libspdm_use_asym_algo, &data,
+     546                 :            :         &data_size, &hash, &hash_size);
+     547                 :          1 :     libspdm_x509_get_cert_from_cert_chain(
+     548                 :          1 :         (uint8_t*) data + sizeof(spdm_cert_chain_t) + hash_size,
+     549                 :          1 :         data_size - sizeof(spdm_cert_chain_t) - hash_size, 0,
+     550                 :            :         &root_cert, &root_cert_size);
+     551                 :          1 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "root cert data :\n"));
+     552                 :          1 :     libspdm_dump_hex(root_cert, root_cert_size);
+     553                 :          1 :     spdm_context->local_context.peer_root_cert_provision_size[0] = root_cert_size;
+     554                 :            : 
+     555                 :          1 :     spdm_context->local_context.peer_root_cert_provision[0] = root_cert;
+     556                 :          1 :     libspdm_reset_message_b(spdm_context);
+     557                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     558                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     559                 :          1 :     spdm_context->connection_info.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+     560                 :            : 
+     561                 :            :     #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     562                 :            :     spdm_context->transcript.message_m.buffer_size =
+     563                 :            :         spdm_context->transcript.message_m.max_buffer_size;
+     564                 :            :     #endif
+     565                 :          1 :     cert_chain_size = sizeof(cert_chain);
+     566                 :          1 :     libspdm_zero_mem(cert_chain, sizeof(cert_chain));
+     567                 :          1 :     status = libspdm_get_certificate(spdm_context, NULL, 0, &cert_chain_size, cert_chain);
+     568                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     569                 :            :     #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     570                 :            :     count = (data_size + LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN - 1) / LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN;
+     571                 :            :     assert_int_equal(spdm_context->transcript.message_b.buffer_size,
+     572                 :            :                      sizeof(spdm_get_certificate_request_t) * count +
+     573                 :            :                      sizeof(spdm_certificate_response_t) * count +
+     574                 :            :                      data_size);
+     575                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+     576                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = 0;
+     577                 :            :     #else
+     578                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size = 0;
+     579                 :            :     #endif
+     580                 :          1 :     free(data);
+     581                 :          1 : }
+     582                 :            : #endif
+     583                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
+     584                 :          1 : void libspdm_test_requester_chunk_get_case2(void** state)
+     585                 :            : {
+     586                 :            :     /* Copied from Get Measurements Test Case 0x20 */
+     587                 :            :     libspdm_return_t status;
+     588                 :            :     libspdm_test_context_t* spdm_test_context;
+     589                 :            :     libspdm_context_t* spdm_context;
+     590                 :            :     uint8_t number_of_block;
+     591                 :            :     uint32_t measurement_record_length;
+     592                 :            :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
+     593                 :            :     uint8_t request_attribute;
+     594                 :            :     void* data;
+     595                 :            :     size_t data_size;
+     596                 :            :     void* hash;
+     597                 :            :     size_t hash_size;
+     598                 :            : 
+     599                 :          1 :     spdm_test_context = *state;
+     600                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     601                 :          1 :     spdm_test_context->case_id = 0x02;
+     602                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     603                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     604                 :          1 :     spdm_context->connection_info.connection_state =
+     605                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     606                 :          1 :     spdm_context->connection_info.capability.flags |=
+     607                 :            :         (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG
+     608                 :            :          | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP);
+     609                 :            : 
+     610                 :          1 :     spdm_context->local_context.capability.flags |=
+     611                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP;
+     612                 :            :     spdm_context->local_context.capability.data_transfer_size
+     613                 :          1 :         = CHUNK_GET_REQUESTER_UNIT_TEST_DATA_TRANSFER_SIZE;
+     614                 :            : 
+     615                 :          1 :     libspdm_read_responder_public_certificate_chain(
+     616                 :            :         m_libspdm_use_hash_algo, m_libspdm_use_asym_algo,
+     617                 :            :         &data, &data_size, &hash, &hash_size);
+     618                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+     619                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     620                 :            :         m_libspdm_use_measurement_spec;
+     621                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     622                 :            :         m_libspdm_use_measurement_hash_algo;
+     623                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     624                 :            :         m_libspdm_use_hash_algo;
+     625                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     626                 :            :         m_libspdm_use_asym_algo;
+     627                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+     628                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     629                 :            :     #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     630                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
+     631                 :            :     libspdm_copy_mem(
+     632                 :            :         spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+     633                 :            :         sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+     634                 :            :         data, data_size);
+     635                 :            :     #else
+     636                 :          1 :     libspdm_hash_all(
+     637                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+     638                 :            :         data, data_size,
+     639                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+     640                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+     641                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+     642                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+     643                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+     644                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+     645                 :            :         data, data_size,
+     646                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+     647                 :            :     #endif
+     648                 :          1 :     request_attribute = 0;
+     649                 :            : 
+     650                 :          1 :     measurement_record_length = sizeof(measurement_record);
+     651                 :          1 :     status = libspdm_get_measurement(
+     652                 :            :         spdm_context, NULL, request_attribute,
+     653                 :            :         SPDM_GET_MEASUREMENTS_REQUEST_MEASUREMENT_OPERATION_ALL_MEASUREMENTS,
+     654                 :            :         0, NULL, &number_of_block, &measurement_record_length,
+     655                 :            :         measurement_record);
+     656                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     657                 :            :     #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     658                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
+     659                 :            :                      sizeof(spdm_message_header_t) +
+     660                 :            :                      sizeof(spdm_measurements_response_t) +
+     661                 :            :                      2 * (sizeof(spdm_measurement_block_dmtf_t) +
+     662                 :            :                           libspdm_get_measurement_hash_size(
+     663                 :            :                               m_libspdm_use_measurement_hash_algo)) +
+     664                 :            :                      sizeof(uint16_t) + SPDM_NONCE_SIZE);
+     665                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = 0;
+     666                 :            :     #else
+     667                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size = 0;
+     668                 :            :     #endif
+     669                 :          1 :     free(data);
+     670                 :          1 : }
+     671                 :            : #endif
+     672                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP
+     673                 :          1 : void libspdm_test_requester_chunk_get_case3(void** state)
+     674                 :            : {
+     675                 :            :     /* Copied from Challenge Test Case 2*/
+     676                 :            :     libspdm_return_t status;
+     677                 :            :     libspdm_test_context_t* spdm_test_context;
+     678                 :            :     libspdm_context_t* spdm_context;
+     679                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+     680                 :            :     void* data;
+     681                 :            :     size_t data_size;
+     682                 :            :     void* hash;
+     683                 :            :     size_t hash_size;
+     684                 :            : 
+     685                 :          1 :     spdm_test_context = *state;
+     686                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     687                 :          1 :     spdm_test_context->case_id = 0x3;
+     688                 :          1 :     spdm_context->connection_info.connection_state =
+     689                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     690                 :          1 :     spdm_context->connection_info.capability.flags = 0;
+     691                 :          1 :     spdm_context->connection_info.capability.flags |=
+     692                 :            :         (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP
+     693                 :            :          | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP);
+     694                 :            : 
+     695                 :          1 :     spdm_context->local_context.capability.flags |=
+     696                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP;
+     697                 :            :     spdm_context->local_context.capability.data_transfer_size
+     698                 :          1 :         = CHUNK_GET_REQUESTER_UNIT_TEST_DATA_TRANSFER_SIZE;
+     699                 :            : 
+     700                 :          1 :     libspdm_read_responder_public_certificate_chain(
+     701                 :            :         m_libspdm_use_hash_algo, m_libspdm_use_asym_algo,
+     702                 :            :         &data, &data_size, &hash, &hash_size);
+     703                 :          1 :     libspdm_reset_message_a(spdm_context);
+     704                 :          1 :     libspdm_reset_message_b(spdm_context);
+     705                 :          1 :     libspdm_reset_message_c(spdm_context);
+     706                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     707                 :            :         m_libspdm_use_hash_algo;
+     708                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     709                 :            :         m_libspdm_use_asym_algo;
+     710                 :            : 
+     711                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     712                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     713                 :            : 
+     714                 :            :     #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     715                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
+     716                 :            :     libspdm_copy_mem(
+     717                 :            :         spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+     718                 :            :         sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+     719                 :            :         data, data_size);
+     720                 :            :     #else
+     721                 :          1 :     libspdm_hash_all(
+     722                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+     723                 :            :         data, data_size,
+     724                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+     725                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+     726                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+     727                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+     728                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+     729                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+     730                 :            :         data, data_size,
+     731                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+     732                 :            :     #endif
+     733                 :            : 
+     734                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+     735                 :          1 :     status = libspdm_challenge(
+     736                 :            :         spdm_context, NULL, 0,
+     737                 :            :         SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
+     738                 :            :         measurement_hash, NULL);
+     739                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     740                 :          1 :     free(data);
+     741                 :            :     #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     742                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = 0;
+     743                 :            :     #else
+     744                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size = 0;
+     745                 :            :     #endif
+     746                 :          1 : }
+     747                 :            : #endif
+     748                 :            : #if LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT
+     749                 :          1 : void libspdm_test_requester_chunk_get_case4(void** state)
+     750                 :            : {
+     751                 :            :     /* Copied from Get Digests Test Case 2*/
+     752                 :            :     libspdm_return_t status;
+     753                 :            :     libspdm_test_context_t* spdm_test_context;
+     754                 :            :     libspdm_context_t* spdm_context;
+     755                 :            :     libspdm_data_parameter_t parameter;
+     756                 :            :     uint8_t slot_mask;
+     757                 :            :     uint8_t slot_id;
+     758                 :            :     uint8_t total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
+     759                 :            :     uint8_t my_total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
+     760                 :            :     uint8_t* digest;
+     761                 :            :     size_t data_return_size;
+     762                 :            : 
+     763                 :          1 :     spdm_test_context = *state;
+     764                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     765                 :          1 :     spdm_test_context->case_id = 0x4;
+     766                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     767                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     768                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     769                 :          1 :     spdm_context->connection_info.capability.flags |=
+     770                 :            :         (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP
+     771                 :            :          | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP);
+     772                 :            : 
+     773                 :          1 :     spdm_context->local_context.capability.flags |=
+     774                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP;
+     775                 :            :     spdm_context->local_context.capability.data_transfer_size
+     776                 :          1 :         = CHUNK_GET_REQUESTER_UNIT_TEST_DATA_TRANSFER_SIZE;
+     777                 :            : 
+     778                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     779                 :            : 
+     780                 :          1 :     libspdm_set_mem(
+     781                 :            :         m_libspdm_local_certificate_chain_test_case_4,
+     782                 :            :         sizeof(m_libspdm_local_certificate_chain_test_case_4),
+     783                 :            :         (uint8_t) (0xFF));
+     784                 :          1 :     libspdm_reset_message_b(spdm_context);
+     785                 :            : 
+     786                 :            :     #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     787                 :            :     spdm_context->transcript.message_m.buffer_size =
+     788                 :            :         spdm_context->transcript.message_m.max_buffer_size;
+     789                 :            :     #endif
+     790                 :          1 :     libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
+     791                 :          1 :     status = libspdm_get_digest(spdm_context, NULL, &slot_mask, &total_digest_buffer);
+     792                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     793                 :            : 
+     794                 :          1 :     assert_int_equal(slot_mask, 0xFF);
+     795                 :          1 :     libspdm_zero_mem(my_total_digest_buffer, sizeof(my_total_digest_buffer));
+     796                 :          1 :     digest = my_total_digest_buffer;
+     797         [ +  + ]:          9 :     for (slot_id = 0; slot_id < SPDM_MAX_SLOT_COUNT; slot_id++) {
+     798                 :          8 :         libspdm_hash_all(m_libspdm_use_hash_algo,
+     799                 :            :                          m_libspdm_local_certificate_chain_test_case_4,
+     800                 :            :                          sizeof(m_libspdm_local_certificate_chain_test_case_4), digest);
+     801                 :          8 :         digest += libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     802                 :            :     }
+     803                 :          1 :     assert_memory_equal(total_digest_buffer, my_total_digest_buffer,
+     804                 :            :                         sizeof(my_total_digest_buffer));
+     805                 :            : 
+     806                 :          1 :     parameter.location = LIBSPDM_DATA_LOCATION_CONNECTION;
+     807                 :          1 :     data_return_size = sizeof(uint8_t);
+     808                 :          1 :     status = libspdm_get_data(spdm_context, LIBSPDM_DATA_PEER_SLOT_MASK,
+     809                 :            :                               &parameter, &slot_mask, &data_return_size);
+     810                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     811                 :          1 :     assert_int_equal(data_return_size, sizeof(uint8_t));
+     812                 :          1 :     assert_int_equal(slot_mask, 0xFF);
+     813                 :            : 
+     814                 :          1 :     data_return_size = sizeof(total_digest_buffer);
+     815                 :          1 :     status = libspdm_get_data(spdm_context, LIBSPDM_DATA_PEER_TOTAL_DIGEST_BUFFER,
+     816                 :            :                               &parameter, total_digest_buffer, &data_return_size);
+     817                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     818                 :          1 :     assert_int_equal(data_return_size, libspdm_get_hash_size(
+     819                 :            :                          m_libspdm_use_hash_algo) * SPDM_MAX_SLOT_COUNT);
+     820                 :          1 :     assert_memory_equal(total_digest_buffer, my_total_digest_buffer,
+     821                 :            :                         sizeof(my_total_digest_buffer));
+     822                 :            : 
+     823                 :            :     #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     824                 :            :     assert_int_equal(
+     825                 :            :         spdm_context->transcript.message_b.buffer_size,
+     826                 :            :         sizeof(spdm_get_digest_request_t) +
+     827                 :            :         sizeof(spdm_digest_response_t) +
+     828                 :            :         libspdm_get_hash_size(spdm_context->connection_info
+     829                 :            :                               .algorithm.base_hash_algo) * SPDM_MAX_SLOT_COUNT);
+     830                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+     831                 :            :     #endif
+     832                 :          1 : }
+     833                 :            : #endif
+     834                 :            : 
+     835                 :            : libspdm_test_context_t m_libspdm_requester_chunk_get_test_context = {
+     836                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+     837                 :            :     true,
+     838                 :            :     libspdm_requester_chunk_get_test_send_message,
+     839                 :            :     libspdm_requester_chunk_get_test_receive_message,
+     840                 :            : };
+     841                 :            : 
+     842                 :          1 : int libspdm_requester_chunk_get_test_main(void)
+     843                 :            : {
+     844                 :            :     /* Test the CHUNK_GET handlers in various requester handlers */
+     845                 :          1 :     const struct CMUnitTest spdm_requester_chunk_get_tests[] = {
+     846                 :            : #if LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT
+     847                 :            :         /* Request a certificate in portions */
+     848                 :            :         cmocka_unit_test(libspdm_test_requester_chunk_get_case1),
+     849                 :            : #endif
+     850                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
+     851                 :            :         /* Request all measurements */
+     852                 :            :         cmocka_unit_test(libspdm_test_requester_chunk_get_case2),
+     853                 :            : #endif
+     854                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP
+     855                 :            :         /* Request Challenge */
+     856                 :            :         cmocka_unit_test(libspdm_test_requester_chunk_get_case3),
+     857                 :            : #endif
+     858                 :            : #if LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT
+     859                 :            :         /* Request Digests */
+     860                 :            :         cmocka_unit_test(libspdm_test_requester_chunk_get_case4),
+     861                 :            : #endif
+     862                 :            :     };
+     863                 :            : 
+     864                 :          1 :     libspdm_setup_test_context(
+     865                 :            :         &m_libspdm_requester_chunk_get_test_context);
+     866                 :            : 
+     867                 :          1 :     return cmocka_run_group_tests(spdm_requester_chunk_get_tests,
+     868                 :            :                                   libspdm_unit_test_group_setup,
+     869                 :            :                                   libspdm_unit_test_group_teardown);
+     870                 :            : }
+     871                 :            : 
+     872                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/chunk_send.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_requester/chunk_send.c.func-sort-c.html new file mode 100644 index 00000000000..bfac8588c65 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/chunk_send.c.func-sort-c.html @@ -0,0 +1,149 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/chunk_send.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - chunk_send.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:23123797.5 %
Date:2024-09-22 08:21:07Functions:1717100.0 %
Branches:536088.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_chunk_send_test_main1
libspdm_test_requester_chunk_send_case11
libspdm_test_requester_chunk_send_case101
libspdm_test_requester_chunk_send_case111
libspdm_test_requester_chunk_send_case121
libspdm_test_requester_chunk_send_case21
libspdm_test_requester_chunk_send_case31
libspdm_test_requester_chunk_send_case41
libspdm_test_requester_chunk_send_case51
libspdm_test_requester_chunk_send_case61
libspdm_test_requester_chunk_send_case71
libspdm_test_requester_chunk_send_case81
libspdm_test_requester_chunk_send_case91
libspdm_requester_chunk_send_test_case1_build_algorithms_response3
libspdm_requester_chunk_send_test_receive_message12
libspdm_test_requester_chunk_send_generic_test_case12
libspdm_requester_chunk_send_test_send_message13
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/chunk_send.c.func.html b/coverage_log/unit_test/test_spdm_requester/chunk_send.c.func.html new file mode 100644 index 00000000000..63ad25c3261 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/chunk_send.c.func.html @@ -0,0 +1,149 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/chunk_send.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - chunk_send.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:23123797.5 %
Date:2024-09-22 08:21:07Functions:1717100.0 %
Branches:536088.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_chunk_send_test_case1_build_algorithms_response3
libspdm_requester_chunk_send_test_main1
libspdm_requester_chunk_send_test_receive_message12
libspdm_requester_chunk_send_test_send_message13
libspdm_test_requester_chunk_send_case11
libspdm_test_requester_chunk_send_case101
libspdm_test_requester_chunk_send_case111
libspdm_test_requester_chunk_send_case121
libspdm_test_requester_chunk_send_case21
libspdm_test_requester_chunk_send_case31
libspdm_test_requester_chunk_send_case41
libspdm_test_requester_chunk_send_case51
libspdm_test_requester_chunk_send_case61
libspdm_test_requester_chunk_send_case71
libspdm_test_requester_chunk_send_case81
libspdm_test_requester_chunk_send_case91
libspdm_test_requester_chunk_send_generic_test_case12
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/chunk_send.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/chunk_send.c.gcov.html new file mode 100644 index 00000000000..4c400854e17 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/chunk_send.c.gcov.html @@ -0,0 +1,605 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/chunk_send.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - chunk_send.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:23123797.5 %
Date:2024-09-22 08:21:07Functions:1717100.0 %
Branches:536088.3 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_requester_lib.h"
+       9                 :            : #include "internal/libspdm_secured_message_lib.h"
+      10                 :            : 
+      11                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
+      12                 :            : 
+      13                 :            : static bool m_libspdm_chunk_send_last_chunk = false;
+      14                 :            : static uint8_t m_libspdm_chunk_send_chunk_handle = 0;
+      15                 :            : static uint16_t m_libspdm_chunk_send_chunk_seq_no = 0;
+      16                 :            : 
+      17                 :            : /* Override the LIBSPDM_DATA_TRANSFER_SIZE just for the unit tests in this file.
+      18                 :            :  * All other unit tests have the default data transfer size due to the specific
+      19                 :            :  * unit tests requests and responses hardcode for each test case. */
+      20                 :            : #define CHUNK_SEND_REQUESTER_UNIT_TEST_DATA_TRANSFER_SIZE (42)
+      21                 :            : 
+      22                 :          3 : void libspdm_requester_chunk_send_test_case1_build_algorithms_response(
+      23                 :            :     void* context, void* response, size_t* response_size)
+      24                 :            : {
+      25                 :            :     spdm_algorithms_response_t* spdm_response;
+      26                 :            : 
+      27                 :          3 :     *response_size = sizeof(spdm_algorithms_response_t);
+      28                 :          3 :     spdm_response = (spdm_algorithms_response_t*) response;
+      29                 :            : 
+      30                 :          3 :     libspdm_zero_mem(spdm_response, *response_size);
+      31                 :          3 :     spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+      32                 :          3 :     spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+      33                 :          3 :     spdm_response->header.param1 = 0;
+      34                 :          3 :     spdm_response->header.param2 = 0;
+      35                 :          3 :     spdm_response->length = sizeof(spdm_algorithms_response_t);
+      36                 :          3 :     spdm_response->measurement_specification_sel =
+      37                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+      38                 :          3 :     spdm_response->measurement_hash_algo =
+      39                 :            :         m_libspdm_use_measurement_hash_algo;
+      40                 :          3 :     spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+      41                 :          3 :     spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+      42                 :          3 :     spdm_response->ext_asym_sel_count = 0;
+      43                 :          3 :     spdm_response->ext_hash_sel_count = 0;
+      44                 :          3 : }
+      45                 :            : 
+      46                 :            : 
+      47                 :         13 : libspdm_return_t libspdm_requester_chunk_send_test_send_message(
+      48                 :            :     void* spdm_context, size_t request_size, const void* request,
+      49                 :            :     uint64_t timeout)
+      50                 :            : {
+      51                 :            :     libspdm_test_context_t* spdm_test_context;
+      52                 :            :     const spdm_chunk_send_request_t* chunk_send;
+      53                 :            : 
+      54                 :         13 :     spdm_test_context = libspdm_get_test_context();
+      55                 :            : 
+      56                 :         13 :     chunk_send = (const spdm_chunk_send_request_t*)
+      57                 :            :                  ((const uint8_t*) request + sizeof(libspdm_test_message_header_t));
+      58                 :            : 
+      59                 :         13 :     m_libspdm_chunk_send_chunk_handle = chunk_send->header.param2;
+      60                 :         13 :     m_libspdm_chunk_send_chunk_seq_no = chunk_send->chunk_seq_no;
+      61                 :            : 
+      62         [ +  + ]:         13 :     if (chunk_send->header.param1 & SPDM_CHUNK_SEND_REQUEST_ATTRIBUTE_LAST_CHUNK) {
+      63                 :          2 :         m_libspdm_chunk_send_last_chunk = true;
+      64                 :            :     }
+      65                 :            : 
+      66         [ +  + ]:         13 :     if (spdm_test_context->case_id == 1) {
+      67                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+      68                 :            :     }
+      69         [ +  + ]:         11 :     if (spdm_test_context->case_id == 2) {
+      70                 :          1 :         return LIBSPDM_STATUS_SEND_FAIL;
+      71                 :            :     }
+      72         [ +  + ]:         10 :     if (spdm_test_context->case_id == 3) {
+      73                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      74                 :            :     }
+      75         [ +  + ]:          9 :     if (spdm_test_context->case_id == 4) {
+      76                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      77                 :            :     }
+      78         [ +  + ]:          8 :     if (spdm_test_context->case_id == 5) {
+      79                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      80                 :            :     }
+      81         [ +  + ]:          7 :     if (spdm_test_context->case_id == 6) {
+      82                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      83                 :            :     }
+      84         [ +  + ]:          6 :     if (spdm_test_context->case_id == 7) {
+      85                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      86                 :            :     }
+      87         [ +  + ]:          5 :     if (spdm_test_context->case_id == 8) {
+      88                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      89                 :            :     }
+      90         [ +  + ]:          4 :     if (spdm_test_context->case_id == 9) {
+      91                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      92                 :            :     }
+      93         [ +  + ]:          3 :     if (spdm_test_context->case_id == 10) {
+      94         [ +  - ]:          2 :         if (chunk_send->header.request_response_code == SPDM_CHUNK_SEND) {
+      95                 :          2 :             return LIBSPDM_STATUS_SUCCESS;
+      96                 :            :         }
+      97                 :          0 :         return LIBSPDM_STATUS_SEND_FAIL;
+      98                 :            :     }
+      99         [ -  + ]:          1 :     if (spdm_test_context->case_id == 11) {
+     100                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     101                 :            :     }
+     102         [ +  - ]:          1 :     if (spdm_test_context->case_id == 12) {
+     103                 :            :         /* Here the send request message should always be SPDM_CHUNK_SEND,
+     104                 :            :          * if not then something is wrong. */
+     105         [ -  + ]:          1 :         LIBSPDM_ASSERT(chunk_send->header.request_response_code == SPDM_CHUNK_SEND);
+     106                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     107                 :            :     }
+     108                 :          0 :     return LIBSPDM_STATUS_SEND_FAIL;
+     109                 :            : }
+     110                 :            : 
+     111                 :         12 : libspdm_return_t libspdm_requester_chunk_send_test_receive_message(
+     112                 :            :     void *context, size_t *response_size,
+     113                 :            :     void **response, uint64_t timeout)
+     114                 :            : {
+     115                 :            :     libspdm_test_context_t *spdm_test_context;
+     116                 :            :     libspdm_context_t *spdm_context;
+     117                 :            :     spdm_chunk_send_ack_response_t *chunk_send_ack_rsp;
+     118                 :            :     spdm_error_response_t *error_response;
+     119                 :            :     size_t chunk_rsp_size;
+     120                 :            :     uint8_t *chunk_copy_to;
+     121                 :            :     size_t chunk_size;
+     122                 :            : 
+     123                 :         12 :     spdm_test_context = libspdm_get_test_context();
+     124                 :         12 :     spdm_context = context;
+     125                 :            : 
+     126   [ +  +  +  + ]:         12 :     if ((spdm_test_context->case_id == 1) || (spdm_test_context->case_id == 10) ||
+     127         [ -  + ]:          8 :         (spdm_test_context->case_id == 11)) {
+     128                 :            :         /* Successful chunk send of algorithms request */
+     129                 :            :         chunk_send_ack_rsp
+     130                 :          4 :             = (void*) ((uint8_t*) *response + sizeof(libspdm_test_message_header_t));
+     131                 :            : 
+     132                 :          4 :         chunk_send_ack_rsp->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     133                 :          4 :         chunk_send_ack_rsp->header.request_response_code = SPDM_CHUNK_SEND_ACK;
+     134                 :          4 :         chunk_send_ack_rsp->header.param1 = 0;
+     135                 :          4 :         chunk_send_ack_rsp->header.param2 = m_libspdm_chunk_send_chunk_handle;
+     136                 :          4 :         chunk_send_ack_rsp->chunk_seq_no = m_libspdm_chunk_send_chunk_seq_no;
+     137                 :            : 
+     138         [ +  + ]:          4 :         if (m_libspdm_chunk_send_last_chunk) {
+     139                 :            : 
+     140                 :          3 :             chunk_copy_to = (uint8_t*) (chunk_send_ack_rsp + 1);
+     141                 :          3 :             chunk_size = *response_size - (chunk_copy_to - (uint8_t*) *response);
+     142                 :            : 
+     143                 :          3 :             libspdm_requester_chunk_send_test_case1_build_algorithms_response(
+     144                 :            :                 spdm_context, chunk_copy_to, &chunk_size);
+     145                 :          3 :             chunk_rsp_size = sizeof(spdm_chunk_send_ack_response_t) + chunk_size;
+     146                 :            : 
+     147                 :          3 :             libspdm_transport_test_encode_message(
+     148                 :            :                 spdm_context, NULL, false, false,
+     149                 :            :                 chunk_rsp_size, chunk_send_ack_rsp,
+     150                 :            :                 response_size, response);
+     151                 :            :         } else {
+     152                 :          1 :             chunk_rsp_size = sizeof(spdm_chunk_send_ack_response_t);
+     153                 :          1 :             libspdm_transport_test_encode_message(
+     154                 :            :                 spdm_context, NULL, false, false,
+     155                 :            :                 chunk_rsp_size, chunk_send_ack_rsp,
+     156                 :            :                 response_size, response);
+     157                 :            :         }
+     158                 :          4 :         return LIBSPDM_STATUS_SUCCESS;
+     159                 :            :     }
+     160         [ -  + ]:          8 :     if (spdm_test_context->case_id == 2) {
+     161                 :            :         /* Request fail send
+     162                 :            :          * Should never reach here since the test case is meant to fail at send */
+     163                 :          0 :         LIBSPDM_ASSERT(0);
+     164                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+     165                 :            :     }
+     166         [ +  + ]:          8 :     if (spdm_test_context->case_id == 3) {
+     167                 :            :         /* Response fail receive */
+     168                 :          1 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+     169                 :            :     }
+     170         [ +  + ]:          7 :     if (spdm_test_context->case_id == 4) {
+     171                 :            :         /* Response has bad SPDM version */
+     172                 :            :         chunk_send_ack_rsp
+     173                 :          1 :             = (void*) ((uint8_t*) *response + sizeof(libspdm_test_message_header_t));
+     174                 :            : 
+     175                 :          1 :         chunk_send_ack_rsp->header.spdm_version = SPDM_MESSAGE_VERSION_11; /* Bad SPDM version */
+     176                 :          1 :         chunk_send_ack_rsp->header.request_response_code = SPDM_CHUNK_SEND_ACK;
+     177                 :          1 :         chunk_send_ack_rsp->header.param1 = 0;
+     178                 :          1 :         chunk_send_ack_rsp->header.param2 = m_libspdm_chunk_send_chunk_handle;
+     179                 :          1 :         chunk_send_ack_rsp->chunk_seq_no = m_libspdm_chunk_send_chunk_seq_no;
+     180                 :            : 
+     181                 :          1 :         chunk_rsp_size = sizeof(spdm_chunk_send_ack_response_t);
+     182                 :          1 :         libspdm_transport_test_encode_message(
+     183                 :            :             spdm_context, NULL, false, false,
+     184                 :            :             chunk_rsp_size, chunk_send_ack_rsp,
+     185                 :            :             response_size, response);
+     186                 :            : 
+     187                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     188                 :            :     }
+     189         [ +  + ]:          6 :     if (spdm_test_context->case_id == 5) {
+     190                 :            :         /* Response has bad request response code */
+     191                 :            :         chunk_send_ack_rsp
+     192                 :          1 :             = (void*) ((uint8_t*) *response + sizeof(libspdm_test_message_header_t));
+     193                 :            : 
+     194                 :          1 :         chunk_send_ack_rsp->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     195                 :          1 :         chunk_send_ack_rsp->header.request_response_code = SPDM_ERROR; /* Bad response code */
+     196                 :          1 :         chunk_send_ack_rsp->header.param1 = 0;
+     197                 :          1 :         chunk_send_ack_rsp->header.param2 = 0;
+     198                 :            : 
+     199                 :          1 :         chunk_rsp_size = sizeof(spdm_chunk_send_ack_response_t);
+     200                 :          1 :         libspdm_transport_test_encode_message(
+     201                 :            :             spdm_context, NULL, false, false,
+     202                 :            :             chunk_rsp_size, chunk_send_ack_rsp,
+     203                 :            :             response_size, response);
+     204                 :            : 
+     205                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     206                 :            :     }
+     207         [ +  + ]:          5 :     if (spdm_test_context->case_id == 6) {
+     208                 :            :         /* Response has bad response size */
+     209                 :            :         chunk_send_ack_rsp
+     210                 :          1 :             = (void*) ((uint8_t*) *response + sizeof(libspdm_test_message_header_t));
+     211                 :            : 
+     212                 :          1 :         chunk_send_ack_rsp->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     213                 :          1 :         chunk_send_ack_rsp->header.request_response_code = SPDM_CHUNK_SEND_ACK;
+     214                 :          1 :         chunk_send_ack_rsp->header.param1 = 0;
+     215                 :          1 :         chunk_send_ack_rsp->header.param2 = m_libspdm_chunk_send_chunk_handle;
+     216                 :          1 :         chunk_send_ack_rsp->chunk_seq_no = m_libspdm_chunk_send_chunk_seq_no;
+     217                 :            : 
+     218                 :          1 :         chunk_rsp_size = 4; /* Bad response size */
+     219                 :            : 
+     220                 :          1 :         libspdm_transport_test_encode_message(
+     221                 :            :             spdm_context, NULL, false, false,
+     222                 :            :             chunk_rsp_size, chunk_send_ack_rsp,
+     223                 :            :             response_size, response);
+     224                 :            : 
+     225                 :            : 
+     226                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     227                 :            :     }
+     228         [ +  + ]:          4 :     if (spdm_test_context->case_id == 7) {
+     229                 :            :         /* Response has early error detected */
+     230                 :            :         chunk_send_ack_rsp
+     231                 :          1 :             = (void*) ((uint8_t*) *response + sizeof(libspdm_test_message_header_t));
+     232                 :            : 
+     233                 :          1 :         chunk_send_ack_rsp->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     234                 :          1 :         chunk_send_ack_rsp->header.request_response_code = SPDM_CHUNK_SEND_ACK;
+     235                 :            :         chunk_send_ack_rsp->header.param1
+     236                 :          1 :             = SPDM_CHUNK_SEND_ACK_RESPONSE_ATTRIBUTE_EARLY_ERROR_DETECTED;
+     237                 :          1 :         chunk_send_ack_rsp->header.param2 = m_libspdm_chunk_send_chunk_handle;
+     238                 :          1 :         chunk_send_ack_rsp->chunk_seq_no = m_libspdm_chunk_send_chunk_seq_no;
+     239                 :            : 
+     240                 :          1 :         error_response = (void*) (chunk_send_ack_rsp + 1);
+     241                 :          1 :         error_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     242                 :          1 :         error_response->header.request_response_code = SPDM_ERROR;
+     243                 :          1 :         error_response->header.param1 = SPDM_ERROR_CODE_UNSPECIFIED;
+     244                 :          1 :         error_response->header.param2 = 0;
+     245                 :            : 
+     246                 :          1 :         chunk_rsp_size = sizeof(spdm_chunk_send_ack_response_t) + sizeof(spdm_error_response_t);
+     247                 :          1 :         libspdm_transport_test_encode_message(
+     248                 :            :             spdm_context, NULL, false, false,
+     249                 :            :             chunk_rsp_size, chunk_send_ack_rsp,
+     250                 :            :             response_size, response);
+     251                 :            : 
+     252                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     253                 :            :     }
+     254         [ +  + ]:          3 :     if (spdm_test_context->case_id == 8) {
+     255                 :            :         /* Response has bad chunk handle */
+     256                 :            :         chunk_send_ack_rsp
+     257                 :          1 :             = (void*) ((uint8_t*) *response + sizeof(libspdm_test_message_header_t));
+     258                 :            : 
+     259                 :          1 :         chunk_send_ack_rsp->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     260                 :          1 :         chunk_send_ack_rsp->header.request_response_code = SPDM_CHUNK_SEND_ACK;
+     261                 :          1 :         chunk_send_ack_rsp->header.param1 = 0;
+     262                 :            : 
+     263                 :            :         /* Bad chunk handle */
+     264                 :          1 :         chunk_send_ack_rsp->header.param2 = m_libspdm_chunk_send_chunk_handle - 1;
+     265                 :          1 :         chunk_send_ack_rsp->chunk_seq_no = m_libspdm_chunk_send_chunk_seq_no;
+     266                 :            : 
+     267                 :          1 :         chunk_rsp_size = sizeof(spdm_chunk_send_ack_response_t);
+     268                 :          1 :         libspdm_transport_test_encode_message(
+     269                 :            :             spdm_context, NULL, false, false,
+     270                 :            :             chunk_rsp_size, chunk_send_ack_rsp,
+     271                 :            :             response_size, response);
+     272                 :            : 
+     273                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     274                 :            :     }
+     275         [ +  + ]:          2 :     if (spdm_test_context->case_id == 9) {
+     276                 :            :         /* Response has bad chunk seq no */
+     277                 :            :         chunk_send_ack_rsp
+     278                 :          1 :             = (void*) ((uint8_t*) *response + sizeof(libspdm_test_message_header_t));
+     279                 :            : 
+     280                 :          1 :         chunk_send_ack_rsp->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     281                 :          1 :         chunk_send_ack_rsp->header.request_response_code = SPDM_CHUNK_SEND_ACK;
+     282                 :          1 :         chunk_send_ack_rsp->header.param1 = 0;
+     283                 :          1 :         chunk_send_ack_rsp->header.param2 = m_libspdm_chunk_send_chunk_handle;
+     284                 :            : 
+     285                 :            :         /* Bad Chunk Seq No */
+     286                 :          1 :         chunk_send_ack_rsp->chunk_seq_no = m_libspdm_chunk_send_chunk_seq_no - 1;
+     287                 :            : 
+     288                 :          1 :         chunk_rsp_size = sizeof(spdm_chunk_send_ack_response_t);
+     289                 :          1 :         libspdm_transport_test_encode_message(
+     290                 :            :             spdm_context, NULL, false, false,
+     291                 :            :             chunk_rsp_size, chunk_send_ack_rsp,
+     292                 :            :             response_size, response);
+     293                 :            : 
+     294                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     295                 :            :     }
+     296         [ +  - ]:          1 :     if (spdm_test_context->case_id == 12) {
+     297                 :            :         /* ErrorCode == LargeResponse shall not be allowed in ResponseToLargeRequest */
+     298                 :            :         chunk_send_ack_rsp
+     299                 :          1 :             = (void*) ((uint8_t*) *response + sizeof(libspdm_test_message_header_t));
+     300                 :            : 
+     301                 :          1 :         chunk_send_ack_rsp->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     302                 :          1 :         chunk_send_ack_rsp->header.request_response_code = SPDM_CHUNK_SEND_ACK;
+     303                 :            :         chunk_send_ack_rsp->header.param1
+     304                 :          1 :             = SPDM_CHUNK_SEND_ACK_RESPONSE_ATTRIBUTE_EARLY_ERROR_DETECTED;
+     305                 :          1 :         chunk_send_ack_rsp->header.param2 = m_libspdm_chunk_send_chunk_handle;
+     306                 :          1 :         chunk_send_ack_rsp->chunk_seq_no = m_libspdm_chunk_send_chunk_seq_no;
+     307                 :            : 
+     308                 :          1 :         error_response = (void*) (chunk_send_ack_rsp + 1);
+     309                 :          1 :         error_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     310                 :          1 :         error_response->header.request_response_code = SPDM_ERROR;
+     311                 :            : 
+     312                 :            :         /* ErrorCode == LargeResponse in ResponseToLargeRequest */
+     313                 :          1 :         error_response->header.param1 = SPDM_ERROR_CODE_LARGE_RESPONSE;
+     314                 :          1 :         error_response->header.param2 = 0;
+     315                 :          1 :         *((uint8_t*) (error_response + 1)) = 0;
+     316                 :            : 
+     317                 :          1 :         chunk_rsp_size = sizeof(spdm_chunk_send_ack_response_t) + sizeof(spdm_error_response_t) +
+     318                 :            :                          sizeof(uint8_t);
+     319                 :          1 :         libspdm_transport_test_encode_message(
+     320                 :            :             spdm_context, NULL, false, false,
+     321                 :            :             chunk_rsp_size, chunk_send_ack_rsp,
+     322                 :            :             response_size, response);
+     323                 :            : 
+     324                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     325                 :            :     }
+     326                 :          0 :     return LIBSPDM_STATUS_RECEIVE_FAIL;
+     327                 :            : }
+     328                 :            : 
+     329                 :         12 : libspdm_return_t libspdm_test_requester_chunk_send_generic_test_case(
+     330                 :            :     void** state, uint32_t case_id)
+     331                 :            : {
+     332                 :            :     /* Copied from Neg. Algorithms test case 2 */
+     333                 :            :     libspdm_return_t status;
+     334                 :            :     libspdm_test_context_t* spdm_test_context;
+     335                 :            :     libspdm_context_t* spdm_context;
+     336                 :            : 
+     337                 :         12 :     spdm_test_context = *state;
+     338                 :         12 :     spdm_context = spdm_test_context->spdm_context;
+     339                 :         12 :     spdm_test_context->case_id = case_id;
+     340                 :         12 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     341                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     342                 :         12 :     spdm_context->connection_info.capability.max_spdm_msg_size = LIBSPDM_MAX_SPDM_MSG_SIZE;
+     343                 :         12 :     spdm_context->connection_info.connection_state =
+     344                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+     345                 :         12 :     spdm_context->connection_info.capability.flags |=
+     346                 :            :         (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP
+     347                 :            :          | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP);
+     348         [ +  + ]:         12 :     if (case_id != 10) {
+     349                 :            :         spdm_context->connection_info.capability.data_transfer_size
+     350                 :         11 :             = CHUNK_SEND_REQUESTER_UNIT_TEST_DATA_TRANSFER_SIZE;
+     351                 :            :         spdm_context->local_context.capability.sender_data_transfer_size
+     352                 :         11 :             = LIBSPDM_DATA_TRANSFER_SIZE;
+     353                 :            :     } else {
+     354                 :            :         spdm_context->connection_info.capability.data_transfer_size
+     355                 :          1 :             = LIBSPDM_DATA_TRANSFER_SIZE;
+     356                 :            :         spdm_context->local_context.capability.sender_data_transfer_size
+     357                 :          1 :             = CHUNK_SEND_REQUESTER_UNIT_TEST_DATA_TRANSFER_SIZE;
+     358                 :            :     }
+     359                 :            : 
+     360         [ +  + ]:         12 :     if (case_id == 11) {
+     361                 :          1 :         spdm_context->connection_info.capability.max_spdm_msg_size = 42;
+     362                 :            :     }
+     363                 :            : 
+     364                 :         12 :     spdm_context->local_context.capability.flags |=
+     365                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP;
+     366                 :         12 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP;
+     367                 :         12 :     spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     368                 :            : 
+     369                 :         12 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+     370                 :            :         m_libspdm_use_measurement_hash_algo;
+     371                 :         12 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     372                 :         12 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     373                 :         12 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+     374                 :         12 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+     375                 :         12 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+     376                 :         12 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+     377                 :         12 :     libspdm_reset_message_a(spdm_context);
+     378                 :            : 
+     379                 :         12 :     status = libspdm_negotiate_algorithms(spdm_context);
+     380                 :         12 :     return status;
+     381                 :            : }
+     382                 :            : 
+     383                 :          1 : void libspdm_test_requester_chunk_send_case1(void** state)
+     384                 :            : {
+     385                 :            :     libspdm_return_t status;
+     386                 :            : 
+     387                 :          1 :     status = libspdm_test_requester_chunk_send_generic_test_case(state, 1);
+     388                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     389                 :          1 : }
+     390                 :            : 
+     391                 :          1 : void libspdm_test_requester_chunk_send_case2(void** state)
+     392                 :            : {
+     393                 :            :     libspdm_return_t status;
+     394                 :          1 :     status = libspdm_test_requester_chunk_send_generic_test_case(state, 2);
+     395                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SEND_FAIL);
+     396                 :          1 : }
+     397                 :            : 
+     398                 :          1 : void libspdm_test_requester_chunk_send_case3(void** state)
+     399                 :            : {
+     400                 :            :     libspdm_return_t status;
+     401                 :          1 :     status = libspdm_test_requester_chunk_send_generic_test_case(state, 3);
+     402                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_RECEIVE_FAIL);
+     403                 :          1 : }
+     404                 :            : 
+     405                 :          1 : void libspdm_test_requester_chunk_send_case4(void** state)
+     406                 :            : {
+     407                 :            :     libspdm_return_t status;
+     408                 :          1 :     status = libspdm_test_requester_chunk_send_generic_test_case(state, 4);
+     409                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+     410                 :          1 : }
+     411                 :            : 
+     412                 :          1 : void libspdm_test_requester_chunk_send_case5(void** state)
+     413                 :            : {
+     414                 :            :     libspdm_return_t status;
+     415                 :          1 :     status = libspdm_test_requester_chunk_send_generic_test_case(state, 5);
+     416                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+     417                 :          1 : }
+     418                 :            : 
+     419                 :          1 : void libspdm_test_requester_chunk_send_case6(void** state)
+     420                 :            : {
+     421                 :            :     libspdm_return_t status;
+     422                 :          1 :     status = libspdm_test_requester_chunk_send_generic_test_case(state, 6);
+     423                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
+     424                 :          1 : }
+     425                 :            : 
+     426                 :          1 : void libspdm_test_requester_chunk_send_case7(void** state)
+     427                 :            : {
+     428                 :            :     libspdm_return_t status;
+     429                 :          1 :     status = libspdm_test_requester_chunk_send_generic_test_case(state, 7);
+     430                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_ERROR_PEER);
+     431                 :          1 : }
+     432                 :            : 
+     433                 :          1 : void libspdm_test_requester_chunk_send_case8(void** state)
+     434                 :            : {
+     435                 :            :     libspdm_return_t status;
+     436                 :          1 :     status = libspdm_test_requester_chunk_send_generic_test_case(state, 8);
+     437                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+     438                 :          1 : }
+     439                 :            : 
+     440                 :          1 : void libspdm_test_requester_chunk_send_case9(void** state)
+     441                 :            : {
+     442                 :            :     libspdm_return_t status;
+     443                 :          1 :     status = libspdm_test_requester_chunk_send_generic_test_case(state, 9);
+     444                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+     445                 :          1 : }
+     446                 :            : 
+     447                 :          1 : void libspdm_test_requester_chunk_send_case10(void** state)
+     448                 :            : {
+     449                 :            :     libspdm_return_t status;
+     450                 :          1 :     status = libspdm_test_requester_chunk_send_generic_test_case(state, 10);
+     451                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     452                 :          1 : }
+     453                 :            : 
+     454                 :          1 : void libspdm_test_requester_chunk_send_case11(void** state)
+     455                 :            : {
+     456                 :            :     libspdm_return_t status;
+     457                 :            : 
+     458                 :          1 :     status = libspdm_test_requester_chunk_send_generic_test_case(state, 11);
+     459                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_PEER_BUFFER_TOO_SMALL);
+     460                 :          1 : }
+     461                 :            : 
+     462                 :            : /**
+     463                 :            :  * Test 12: ErrorCode == LargeResponse shall not be allowed in ResponseToLargeRequest.
+     464                 :            :  * Expected behavior: returns a status of LIBSPDM_STATUS_ERROR_PEER,
+     465                 :            :  * Received an unexpected error message.
+     466                 :            :  **/
+     467                 :          1 : void libspdm_test_requester_chunk_send_case12(void** state)
+     468                 :            : {
+     469                 :            :     libspdm_return_t status;
+     470                 :            : 
+     471                 :          1 :     status = libspdm_test_requester_chunk_send_generic_test_case(state, 12);
+     472                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_ERROR_PEER);
+     473                 :          1 : }
+     474                 :            : 
+     475                 :            : libspdm_test_context_t m_libspdm_requester_chunk_send_test_context = {
+     476                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+     477                 :            :     true,
+     478                 :            :     libspdm_requester_chunk_send_test_send_message,
+     479                 :            :     libspdm_requester_chunk_send_test_receive_message,
+     480                 :            : };
+     481                 :            : 
+     482                 :          1 : int libspdm_requester_chunk_send_test_main(void)
+     483                 :            : {
+     484                 :            :     /* Test the CHUNK_SEND handlers in various requester handlers */
+     485                 :          1 :     const struct CMUnitTest spdm_requester_chunk_send_tests[] = {
+     486                 :            :         /* Request Algorithms successfully sent in chunks. */
+     487                 :            :         cmocka_unit_test(libspdm_test_requester_chunk_send_case1),
+     488                 :            :         /* Chunk Request fail send */
+     489                 :            :         cmocka_unit_test(libspdm_test_requester_chunk_send_case2),
+     490                 :            :         /* Chunk Response fail receive */
+     491                 :            :         cmocka_unit_test(libspdm_test_requester_chunk_send_case3),
+     492                 :            :         /* Chunk Response has bad SPDM version */
+     493                 :            :         cmocka_unit_test(libspdm_test_requester_chunk_send_case4),
+     494                 :            :         /* Chunk Response has bad request response code */
+     495                 :            :         cmocka_unit_test(libspdm_test_requester_chunk_send_case5),
+     496                 :            :         /* Chunk Response has bad response size */
+     497                 :            :         cmocka_unit_test(libspdm_test_requester_chunk_send_case6),
+     498                 :            :         /* Chunk Response has early error detected */
+     499                 :            :         cmocka_unit_test(libspdm_test_requester_chunk_send_case7),
+     500                 :            :         /* Chunk Response has bad chunk handle */
+     501                 :            :         cmocka_unit_test(libspdm_test_requester_chunk_send_case8),
+     502                 :            :         /* Chunk Response has bad chunk seq no */
+     503                 :            :         cmocka_unit_test(libspdm_test_requester_chunk_send_case9),
+     504                 :            :         /* sent in chunks due to greater than the sending transmit buffer size. */
+     505                 :            :         cmocka_unit_test(libspdm_test_requester_chunk_send_case10),
+     506                 :            :         /* requester message size greater than the responder max_spdm_msg_size, return LIBSPDM_STATUS_PEER_BUFFER_TOO_SMALL */
+     507                 :            :         cmocka_unit_test(libspdm_test_requester_chunk_send_case11),
+     508                 :            :         /* ErrorCode == LargeResponse shall not be allowed in ResponseToLargeRequest */
+     509                 :            :         cmocka_unit_test(libspdm_test_requester_chunk_send_case12),
+     510                 :            :     };
+     511                 :            : 
+     512                 :          1 :     libspdm_setup_test_context(
+     513                 :            :         &m_libspdm_requester_chunk_send_test_context);
+     514                 :            : 
+     515                 :          1 :     return cmocka_run_group_tests(spdm_requester_chunk_send_tests,
+     516                 :            :                                   libspdm_unit_test_group_setup,
+     517                 :            :                                   libspdm_unit_test_group_teardown);
+     518                 :            : }
+     519                 :            : 
+     520                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/encap_certificate.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_requester/encap_certificate.c.func-sort-c.html new file mode 100644 index 00000000000..2362c1aac16 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/encap_certificate.c.func-sort-c.html @@ -0,0 +1,113 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/encap_certificate.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - encap_certificate.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:15418782.4 %
Date:2024-09-22 08:21:07Functions:7887.5 %
Branches:142263.6 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_test_requester_encap_certificate_case30
libspdm_requester_encap_certificate_test_main1
libspdm_test_requester_encap_certificate_case11
libspdm_test_requester_encap_certificate_case21
libspdm_test_requester_encap_certificate_case41
libspdm_test_requester_encap_certificate_case51
libspdm_test_requester_encap_certificate_case61
libspdm_test_requester_encap_certificate_case71
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/encap_certificate.c.func.html b/coverage_log/unit_test/test_spdm_requester/encap_certificate.c.func.html new file mode 100644 index 00000000000..c3e8a96ffd7 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/encap_certificate.c.func.html @@ -0,0 +1,113 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/encap_certificate.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - encap_certificate.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:15418782.4 %
Date:2024-09-22 08:21:07Functions:7887.5 %
Branches:142263.6 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_encap_certificate_test_main1
libspdm_test_requester_encap_certificate_case11
libspdm_test_requester_encap_certificate_case21
libspdm_test_requester_encap_certificate_case30
libspdm_test_requester_encap_certificate_case41
libspdm_test_requester_encap_certificate_case51
libspdm_test_requester_encap_certificate_case61
libspdm_test_requester_encap_certificate_case71
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/encap_certificate.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/encap_certificate.c.gcov.html new file mode 100644 index 00000000000..2461f82119a --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/encap_certificate.c.gcov.html @@ -0,0 +1,645 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/encap_certificate.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - encap_certificate.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:15418782.4 %
Date:2024-09-22 08:21:07Functions:7887.5 %
Branches:142263.6 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link:
+       5                 :            :  * https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       6                 :            :  **/
+       7                 :            : 
+       8                 :            : #include "spdm_unit_test.h"
+       9                 :            : #include "internal/libspdm_requester_lib.h"
+      10                 :            : 
+      11                 :            : #if (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP) && \
+      12                 :            :     (LIBSPDM_ENABLE_CAPABILITY_CERT_CAP)
+      13                 :            : 
+      14                 :            : /* #define TEST_DEBUG*/
+      15                 :            : #ifdef TEST_DEBUG
+      16                 :            : #define TEST_DEBUG_PRINT(format, ...) printf(format, ## __VA_ARGS__)
+      17                 :            : #else
+      18                 :            : #define TEST_DEBUG_PRINT(...)
+      19                 :            : #endif
+      20                 :            : 
+      21                 :            : spdm_get_certificate_request_t m_spdm_get_certificate_request1 = {
+      22                 :            :     {SPDM_MESSAGE_VERSION_11, SPDM_GET_CERTIFICATE, 0, 0},
+      23                 :            :     0,
+      24                 :            :     LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN
+      25                 :            : };
+      26                 :            : size_t m_spdm_get_certificate_request1_size =
+      27                 :            :     sizeof(m_spdm_get_certificate_request1);
+      28                 :            : 
+      29                 :            : spdm_get_certificate_request_t m_spdm_get_certificate_request3 = {
+      30                 :            :     {SPDM_MESSAGE_VERSION_11, SPDM_GET_CERTIFICATE, 0, 0}, 0, 0
+      31                 :            : };
+      32                 :            : size_t m_spdm_get_certificate_request3_size =
+      33                 :            :     sizeof(m_spdm_get_certificate_request3);
+      34                 :            : 
+      35                 :            : spdm_get_certificate_request_t m_spdm_get_certificate_request4 = {
+      36                 :            :     {SPDM_MESSAGE_VERSION_13, SPDM_GET_CERTIFICATE, 0, 0},
+      37                 :            :     0,
+      38                 :            :     LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN
+      39                 :            : };
+      40                 :            : size_t m_spdm_get_certificate_request4_size =
+      41                 :            :     sizeof(m_spdm_get_certificate_request4);
+      42                 :            : 
+      43                 :            : /**
+      44                 :            :  * Test 1: request the first LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN bytes of the
+      45                 :            :  * certificate chain Expected Behavior: generate a correctly formed Certficate
+      46                 :            :  * message, including its portion_length and remainder_length fields
+      47                 :            :  **/
+      48                 :          1 : void libspdm_test_requester_encap_certificate_case1(void **state)
+      49                 :            : {
+      50                 :            :     libspdm_return_t status;
+      51                 :            :     libspdm_test_context_t *spdm_test_context;
+      52                 :            :     libspdm_context_t *spdm_context;
+      53                 :            :     size_t response_size;
+      54                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+      55                 :            :     spdm_certificate_response_t *spdm_response;
+      56                 :            :     void *data;
+      57                 :            :     size_t data_size;
+      58                 :            : 
+      59                 :          1 :     spdm_test_context = *state;
+      60                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+      61                 :          1 :     spdm_test_context->case_id = 0x1;
+      62                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11
+      63                 :            :                                             << SPDM_VERSION_NUMBER_SHIFT_BIT;
+      64                 :          1 :     spdm_context->connection_info.connection_state =
+      65                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_DIGESTS;
+      66                 :          1 :     spdm_context->local_context.capability.flags |=
+      67                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+      68                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+      69                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+      70                 :            :                                                     m_libspdm_use_asym_algo,
+      71                 :            :                                                     &data, &data_size, NULL, NULL);
+      72                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+      73                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
+      74                 :            : 
+      75                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+      76                 :            :     spdm_context->transcript.message_m.buffer_size =
+      77                 :            :         spdm_context->transcript.message_m.max_buffer_size;
+      78                 :            : #endif
+      79                 :            : 
+      80                 :          1 :     response_size = sizeof(response);
+      81                 :          1 :     status = libspdm_get_encap_response_certificate(
+      82                 :            :         spdm_context, m_spdm_get_certificate_request1_size,
+      83                 :            :         &m_spdm_get_certificate_request1, &response_size, response);
+      84                 :            : 
+      85                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+      86                 :          1 :     assert_int_equal(response_size, sizeof(spdm_certificate_response_t) +
+      87                 :            :                      LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN);
+      88                 :          1 :     spdm_response = (void *)response;
+      89                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+      90                 :            :                      SPDM_CERTIFICATE);
+      91                 :          1 :     assert_int_equal(spdm_response->header.param1, 0);
+      92                 :          1 :     assert_int_equal(spdm_response->portion_length,
+      93                 :            :                      LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN);
+      94                 :          1 :     assert_int_equal(spdm_response->remainder_length,
+      95                 :            :                      data_size - LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN);
+      96                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+      97                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+      98                 :            : #endif
+      99                 :          1 :     free(data);
+     100                 :          1 : }
+     101                 :            : 
+     102                 :            : /**
+     103                 :            :  * Test 2:
+     104                 :            :  * Expected Behavior:
+     105                 :            :  **/
+     106                 :          1 : void libspdm_test_requester_encap_certificate_case2(void **state)
+     107                 :            : {
+     108                 :          1 : }
+     109                 :            : 
+     110                 :            : /**
+     111                 :            :  * Test 3: request length at the boundary of maximum integer values, while
+     112                 :            :  * keeping offset 0 Expected Behavior: generate correctly formed Certficate
+     113                 :            :  * messages, including its portion_length and remainder_length fields
+     114                 :            :  **/
+     115                 :          0 : void libspdm_test_requester_encap_certificate_case3(void **state)
+     116                 :            : {
+     117                 :            :     libspdm_return_t status;
+     118                 :            :     libspdm_test_context_t *spdm_test_context;
+     119                 :            :     libspdm_context_t *spdm_context;
+     120                 :            :     size_t response_size;
+     121                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     122                 :            :     spdm_certificate_response_t *spdm_response;
+     123                 :            :     void *data;
+     124                 :            :     size_t data_size;
+     125                 :            : 
+     126                 :            :     /* Testing Lengths at the boundary of maximum integer values*/
+     127                 :          0 :     uint16_t test_lengths[] = {
+     128                 :            :         0,
+     129                 :            :         0x7F,
+     130                 :            :         (uint16_t)(0x7F + 1),
+     131                 :            :         0xFF,
+     132                 :            :         0x7FFF,
+     133                 :            :         (uint16_t)(0x7FFF + 1),
+     134                 :            :         0xFFFF,
+     135                 :            :     };
+     136                 :            :     uint16_t expected_chunk_size;
+     137                 :            : 
+     138                 :            :     /* Setting up the spdm_context and loading a sample certificate chain*/
+     139                 :          0 :     spdm_test_context = *state;
+     140                 :          0 :     spdm_context = spdm_test_context->spdm_context;
+     141                 :          0 :     spdm_test_context->case_id = 0x3;
+     142                 :          0 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11
+     143                 :            :                                             << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     144                 :          0 :     spdm_context->local_context.capability.flags |=
+     145                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     146                 :          0 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     147                 :          0 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     148                 :            :                                                     m_libspdm_use_asym_algo,
+     149                 :            :                                                     &data, &data_size, NULL, NULL);
+     150                 :          0 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     151                 :          0 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
+     152                 :            : 
+     153                 :            :     /* This tests considers only offset = 0, other tests vary offset value*/
+     154                 :          0 :     m_spdm_get_certificate_request3.offset = 0;
+     155                 :            : 
+     156         [ #  # ]:          0 :     for (int i = 0; i < sizeof(test_lengths) / sizeof(test_lengths[0]); i++)
+     157                 :            :     {
+     158                 :            :         TEST_DEBUG_PRINT("i:%d test_lengths[i]:%u\n", i, test_lengths[i]);
+     159                 :          0 :         m_spdm_get_certificate_request3.length = test_lengths[i];
+     160                 :            :         /* Expected received length is limited by LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN
+     161                 :            :          * (implementation specific?)*/
+     162                 :          0 :         expected_chunk_size = LIBSPDM_MIN(m_spdm_get_certificate_request3.length,
+     163                 :            :                                           LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN);
+     164                 :            : 
+     165                 :            :         /* reseting an internal buffer to avoid overflow and prevent tests to
+     166                 :            :          * succeed*/
+     167                 :          0 :         libspdm_reset_message_b(spdm_context);
+     168                 :          0 :         response_size = sizeof(response);
+     169                 :          0 :         m_spdm_get_certificate_request3_size =
+     170                 :            :             sizeof(m_spdm_get_certificate_request3);
+     171                 :          0 :         status = libspdm_get_encap_response_certificate(
+     172                 :            :             spdm_context, m_spdm_get_certificate_request3_size,
+     173                 :            :             &m_spdm_get_certificate_request3, &response_size, response);
+     174                 :          0 :         assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     175                 :          0 :         assert_int_equal(response_size,
+     176                 :            :                          sizeof(spdm_certificate_response_t) + expected_chunk_size);
+     177                 :          0 :         spdm_response = (void *)response;
+     178                 :          0 :         assert_int_equal(spdm_response->header.request_response_code,
+     179                 :            :                          SPDM_CERTIFICATE);
+     180                 :          0 :         assert_int_equal(spdm_response->header.param1, 0);
+     181                 :          0 :         assert_int_equal(spdm_response->portion_length, expected_chunk_size);
+     182                 :          0 :         assert_int_equal(spdm_response->remainder_length,
+     183                 :            :                          data_size - expected_chunk_size);
+     184                 :            :     }
+     185                 :          0 :     free(data);
+     186                 :          0 : }
+     187                 :            : 
+     188                 :            : /**
+     189                 :            :  * Test 4: request offset at the boundary of maximum integer values, while
+     190                 :            :  * keeping length 0 Expected Behavior: generate correctly formed Certficate
+     191                 :            :  * messages, including its portion_length and remainder_length fields
+     192                 :            :  **/
+     193                 :          1 : void libspdm_test_requester_encap_certificate_case4(void **state)
+     194                 :            : {
+     195                 :            :     libspdm_return_t status;
+     196                 :            :     libspdm_test_context_t *spdm_test_context;
+     197                 :            :     libspdm_context_t *spdm_context;
+     198                 :            :     size_t response_size;
+     199                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     200                 :            :     spdm_certificate_response_t *spdm_response;
+     201                 :            :     spdm_error_response_t *spdm_responseError;
+     202                 :            :     void *data;
+     203                 :            :     size_t data_size;
+     204                 :            : 
+     205                 :            :     /* Testing offsets at the boundary of maximum integer values and at the
+     206                 :            :      * boundary of certificate length (first three positions)*/
+     207                 :          1 :     uint16_t test_offsets[] = {(uint16_t)(-1),
+     208                 :            :                                0,
+     209                 :            :                                +1,
+     210                 :            :                                0,
+     211                 :            :                                0x7F,
+     212                 :            :                                (uint16_t)(0x7F + 1),
+     213                 :            :                                0xFF,
+     214                 :            :                                0x7FFF,
+     215                 :            :                                (uint16_t)(0x7FFF + 1),
+     216                 :            :                                0xFFFF,
+     217                 :            :                                (uint16_t)(-1)};
+     218                 :            : 
+     219                 :            :     /* Setting up the spdm_context and loading a sample certificate chain*/
+     220                 :          1 :     spdm_test_context = *state;
+     221                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     222                 :          1 :     spdm_test_context->case_id = 0x4;
+     223                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11
+     224                 :            :                                             << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     225                 :          1 :     spdm_context->local_context.capability.flags |=
+     226                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     227                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     228                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     229                 :            :                                                     m_libspdm_use_asym_algo,
+     230                 :            :                                                     &data, &data_size, NULL, NULL);
+     231                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     232                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
+     233                 :            : 
+     234                 :            :     /* This tests considers only length = 0, other tests vary length value*/
+     235                 :          1 :     m_spdm_get_certificate_request3.length = 0;
+     236                 :            :     /* Setting up offset values at the boundary of certificate length*/
+     237                 :          1 :     test_offsets[0] = (uint16_t)(test_offsets[0] + data_size);
+     238                 :          1 :     test_offsets[1] = (uint16_t)(test_offsets[1] + data_size);
+     239                 :          1 :     test_offsets[2] = (uint16_t)(test_offsets[2] + data_size);
+     240                 :            : 
+     241         [ +  + ]:         12 :     for (int i = 0; i < sizeof(test_offsets) / sizeof(test_offsets[0]); i++)
+     242                 :            :     {
+     243                 :            :         TEST_DEBUG_PRINT("i:%d test_offsets[i]:%u\n", i, test_offsets[i]);
+     244                 :         11 :         m_spdm_get_certificate_request3.offset = test_offsets[i];
+     245                 :            : 
+     246                 :            :         /* reseting an internal buffer to avoid overflow and prevent tests to
+     247                 :            :          * succeed*/
+     248                 :         11 :         libspdm_reset_message_b(spdm_context);
+     249                 :         11 :         response_size = sizeof(response);
+     250                 :         11 :         status = libspdm_get_encap_response_certificate(
+     251                 :            :             spdm_context, m_spdm_get_certificate_request3_size,
+     252                 :            :             &m_spdm_get_certificate_request3, &response_size, response);
+     253                 :         11 :         assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     254                 :            : 
+     255         [ +  + ]:         11 :         if (m_spdm_get_certificate_request3.offset >= data_size) {
+     256                 :            :             /* A too long of an offset should return an error*/
+     257                 :          6 :             spdm_responseError = (void *)response;
+     258                 :          6 :             assert_int_equal(spdm_responseError->header.request_response_code,
+     259                 :            :                              SPDM_ERROR);
+     260                 :          6 :             assert_int_equal(spdm_responseError->header.param1,
+     261                 :            :                              SPDM_ERROR_CODE_INVALID_REQUEST);
+     262                 :            :         } else {
+     263                 :            :             /* Otherwise it should work properly, considering length = 0*/
+     264                 :          5 :             assert_int_equal(response_size, sizeof(spdm_certificate_response_t));
+     265                 :          5 :             spdm_response = (void *)response;
+     266                 :          5 :             assert_int_equal(spdm_response->header.request_response_code,
+     267                 :            :                              SPDM_CERTIFICATE);
+     268                 :          5 :             assert_int_equal(spdm_response->header.param1, 0);
+     269                 :          5 :             assert_int_equal(spdm_response->portion_length, 0);
+     270                 :          5 :             assert_int_equal(
+     271                 :            :                 spdm_response->remainder_length,
+     272                 :            :                 (uint16_t)(data_size - m_spdm_get_certificate_request3.offset));
+     273                 :            :         }
+     274                 :            :     }
+     275                 :          1 :     free(data);
+     276                 :          1 : }
+     277                 :            : 
+     278                 :            : /**
+     279                 :            :  * Test 5: request LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN bytes of long certificate
+     280                 :            :  * chains, with the largest valid offset Expected Behavior: generate correctly
+     281                 :            :  * formed Certficate messages, including its portion_length and remainder_length
+     282                 :            :  * fields
+     283                 :            :  **/
+     284                 :          1 : void libspdm_test_requester_encap_certificate_case5(void **state)
+     285                 :            : {
+     286                 :            :     libspdm_return_t status;
+     287                 :            :     libspdm_test_context_t *spdm_test_context;
+     288                 :            :     libspdm_context_t *spdm_context;
+     289                 :            :     size_t response_size;
+     290                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     291                 :            :     spdm_certificate_response_t *spdm_response;
+     292                 :            :     spdm_error_response_t *spdm_responseError;
+     293                 :            :     void *data;
+     294                 :            :     size_t data_size;
+     295                 :            : 
+     296                 :          1 :     uint16_t test_cases[] = {LIBSPDM_TEST_CERT_MAXINT16, LIBSPDM_TEST_CERT_MAXUINT16};
+     297                 :            : 
+     298                 :            :     size_t expected_chunk_size;
+     299                 :            :     size_t expected_remainder;
+     300                 :            : 
+     301                 :            :     /* Setting up the spdm_context and loading a sample certificate chain*/
+     302                 :          1 :     spdm_test_context = *state;
+     303                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     304                 :          1 :     spdm_test_context->case_id = 0x5;
+     305                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11
+     306                 :            :                                             << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     307                 :          1 :     spdm_context->local_context.capability.flags |=
+     308                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     309                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     310                 :            : 
+     311                 :          1 :     m_spdm_get_certificate_request3.length = LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN;
+     312                 :            : 
+     313         [ +  + ]:          3 :     for (int i = 0; i < sizeof(test_cases) / sizeof(test_cases[0]); i++)
+     314                 :            :     {
+     315                 :          2 :         libspdm_read_responder_public_certificate_chain_by_size(
+     316                 :            :             /*MAXUINT16_CERT signature_algo is SHA256RSA */
+     317                 :            :             m_libspdm_use_hash_algo, SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048,
+     318                 :          2 :             test_cases[i], &data, &data_size, NULL, NULL);
+     319                 :            : 
+     320                 :          2 :         spdm_context->local_context.local_cert_chain_provision[0] = data;
+     321                 :          2 :         spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
+     322                 :            : 
+     323                 :          2 :         m_spdm_get_certificate_request3.offset =
+     324         [ +  - ]:          2 :             (uint16_t)(LIBSPDM_MIN(data_size - 1, 0xFFFF));
+     325                 :            :         TEST_DEBUG_PRINT("data_size: %u\n", data_size);
+     326                 :            :         TEST_DEBUG_PRINT("m_spdm_get_certificate_request3.offset: %u\n",
+     327                 :            :                          m_spdm_get_certificate_request3.offset);
+     328                 :            :         TEST_DEBUG_PRINT("m_spdm_get_certificate_request3.length: %u\n",
+     329                 :            :                          m_spdm_get_certificate_request3.length);
+     330                 :            :         TEST_DEBUG_PRINT("offset + length: %u\n",
+     331                 :            :                          m_spdm_get_certificate_request3.offset +
+     332                 :            :                          m_spdm_get_certificate_request3.length);
+     333                 :            : 
+     334                 :            :         /* reseting an internal buffer to avoid overflow and prevent tests to
+     335                 :            :          * succeed*/
+     336                 :          2 :         libspdm_reset_message_b(spdm_context);
+     337                 :          2 :         response_size = sizeof(response);
+     338                 :          2 :         status = libspdm_get_encap_response_certificate(
+     339                 :            :             spdm_context, m_spdm_get_certificate_request3_size,
+     340                 :            :             &m_spdm_get_certificate_request3, &response_size, response);
+     341                 :          2 :         assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     342                 :            : 
+     343                 :            :         /* Expected received length is limited by LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN
+     344                 :            :          * and by the remaining length*/
+     345                 :          2 :         expected_chunk_size =
+     346         [ -  + ]:          2 :             (uint16_t)(LIBSPDM_MIN(m_spdm_get_certificate_request3.length,
+     347                 :            :                                    data_size - m_spdm_get_certificate_request3.offset));
+     348                 :          2 :         expected_chunk_size =
+     349                 :            :             LIBSPDM_MIN(expected_chunk_size, LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN);
+     350                 :            :         /* Expected certificate length left*/
+     351                 :          2 :         expected_remainder =
+     352                 :          2 :             (uint16_t)(data_size - m_spdm_get_certificate_request3.offset -
+     353                 :            :                        expected_chunk_size);
+     354                 :            : 
+     355                 :            :         TEST_DEBUG_PRINT("expected_chunk_size %u\n", expected_chunk_size);
+     356                 :            :         TEST_DEBUG_PRINT("expected_remainder %u\n", expected_remainder);
+     357                 :            : 
+     358   [ +  -  -  + ]:          2 :         if (expected_remainder > 0xFFFF || expected_chunk_size > 0xFFFF) {
+     359                 :          0 :             spdm_responseError = (void *)response;
+     360                 :          0 :             assert_int_equal(spdm_responseError->header.request_response_code,
+     361                 :            :                              SPDM_ERROR);
+     362                 :          0 :             assert_int_equal(spdm_responseError->header.param1,
+     363                 :            :                              SPDM_ERROR_CODE_INVALID_REQUEST);
+     364                 :            :         } else {
+     365                 :          2 :             assert_int_equal(response_size, sizeof(spdm_certificate_response_t) +
+     366                 :            :                              expected_chunk_size);
+     367                 :          2 :             spdm_response = (void *)response;
+     368                 :          2 :             assert_int_equal(spdm_response->header.request_response_code,
+     369                 :            :                              SPDM_CERTIFICATE);
+     370                 :          2 :             assert_int_equal(spdm_response->header.param1, 0);
+     371                 :          2 :             assert_int_equal(spdm_response->portion_length, expected_chunk_size);
+     372                 :          2 :             assert_int_equal(spdm_response->remainder_length, expected_remainder);
+     373                 :            :         }
+     374                 :            : 
+     375                 :            :         TEST_DEBUG_PRINT("\n");
+     376                 :            : 
+     377                 :          2 :         spdm_context->local_context.local_cert_chain_provision[0] = NULL;
+     378                 :          2 :         spdm_context->local_context.local_cert_chain_provision_size[0] = 0;
+     379                 :          2 :         free(data);
+     380                 :            :     }
+     381                 :          1 : }
+     382                 :            : 
+     383                 :            : /**
+     384                 :            :  * Test 6: request a whole certificate chain byte by byte
+     385                 :            :  * Expected Behavior: generate correctly formed Certficate messages, including
+     386                 :            :  * its portion_length and remainder_length fields
+     387                 :            :  **/
+     388                 :          1 : void libspdm_test_requester_encap_certificate_case6(void **state)
+     389                 :            : {
+     390                 :            :     libspdm_return_t status;
+     391                 :            :     libspdm_test_context_t *spdm_test_context;
+     392                 :            :     libspdm_context_t *spdm_context;
+     393                 :            :     size_t response_size;
+     394                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     395                 :            :     spdm_certificate_response_t *spdm_response;
+     396                 :            :     void *data;
+     397                 :            :     size_t data_size;
+     398                 :            :     uint16_t expected_chunk_size;
+     399                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     400                 :            :     size_t count;
+     401                 :            : #endif
+     402                 :            :     /* Setting up the spdm_context and loading a sample certificate chain*/
+     403                 :          1 :     spdm_test_context = *state;
+     404                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     405                 :          1 :     spdm_test_context->case_id = 0x6;
+     406                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11
+     407                 :            :                                             << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     408                 :          1 :     spdm_context->local_context.capability.flags |=
+     409                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     410                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     411                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     412                 :            :                                                     m_libspdm_use_asym_algo,
+     413                 :            :                                                     &data, &data_size, NULL, NULL);
+     414                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     415                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
+     416                 :            : 
+     417                 :            :     /* This tests considers only length = 1*/
+     418                 :          1 :     m_spdm_get_certificate_request3.length = 1;
+     419                 :          1 :     expected_chunk_size = 1;
+     420                 :            : 
+     421                 :            :     /* reseting an internal buffer to avoid overflow and prevent tests to
+     422                 :            :      * succeed*/
+     423                 :          1 :     libspdm_reset_message_b(spdm_context);
+     424                 :            : 
+     425                 :          1 :     spdm_response = NULL;
+     426         [ +  + ]:       1391 :     for (size_t offset = 0; offset < data_size; offset++)
+     427                 :            :     {
+     428                 :            :         TEST_DEBUG_PRINT("offset:%u \n", offset);
+     429                 :       1390 :         m_spdm_get_certificate_request3.offset = (uint16_t)offset;
+     430                 :            : 
+     431                 :       1390 :         response_size = sizeof(response);
+     432                 :       1390 :         status = libspdm_get_encap_response_certificate(
+     433                 :            :             spdm_context, m_spdm_get_certificate_request3_size,
+     434                 :            :             &m_spdm_get_certificate_request3, &response_size, response);
+     435                 :       1390 :         assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     436                 :       1390 :         spdm_response = (void *)response;
+     437                 :            :         /* It may fail because the spdm does not support too many messages.
+     438                 :            :          * assert_int_equal (spdm_response->header.request_response_code,
+     439                 :            :          * SPDM_CERTIFICATE);*/
+     440         [ +  - ]:       1390 :         if (spdm_response->header.request_response_code == SPDM_CERTIFICATE) {
+     441                 :       1390 :             assert_int_equal(spdm_response->header.request_response_code,
+     442                 :            :                              SPDM_CERTIFICATE);
+     443                 :       1390 :             assert_int_equal(response_size, sizeof(spdm_certificate_response_t) +
+     444                 :            :                              expected_chunk_size);
+     445                 :       1390 :             assert_int_equal(spdm_response->header.param1, 0);
+     446                 :       1390 :             assert_int_equal(spdm_response->portion_length, expected_chunk_size);
+     447                 :       1390 :             assert_int_equal(spdm_response->remainder_length,
+     448                 :            :                              data_size - offset - expected_chunk_size);
+     449                 :       1390 :             assert_int_equal(((uint8_t *)data)[offset],
+     450                 :            :                              (response + sizeof(spdm_certificate_response_t))[0]);
+     451                 :            :         } else {
+     452                 :          0 :             assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
+     453                 :          0 :             break;
+     454                 :            :         }
+     455                 :            :     }
+     456         [ +  - ]:          1 :     if (spdm_response != NULL) {
+     457                 :          1 :         if (spdm_response->header.request_response_code == SPDM_CERTIFICATE) {
+     458                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     459                 :            :             count = (data_size + m_spdm_get_certificate_request3.length - 1) /
+     460                 :            :                     m_spdm_get_certificate_request3.length;
+     461                 :            :             assert_int_equal(spdm_context->transcript.message_b.buffer_size,
+     462                 :            :                              sizeof(spdm_get_certificate_request_t) * count +
+     463                 :            :                              sizeof(spdm_certificate_response_t) * count +
+     464                 :            :                              data_size);
+     465                 :            : #endif
+     466                 :            :         }
+     467                 :            :     }
+     468                 :          1 :     free(data);
+     469                 :          1 : }
+     470                 :            : 
+     471                 :            : /**
+     472                 :            :  * Test 7: check request attributes and response attributes , SlotSizeRequested=1b the Offset and Length fields in the
+     473                 :            :  * GET_CERTIFICATE request shall be ignored by the Responde
+     474                 :            :  * Expected Behavior: generate a correctly formed Certficate message, including its portion_length and remainder_length fields
+     475                 :            :  **/
+     476                 :          1 : void libspdm_test_requester_encap_certificate_case7(void **state)
+     477                 :            : {
+     478                 :            :     libspdm_return_t status;
+     479                 :            :     libspdm_test_context_t *spdm_test_context;
+     480                 :            :     libspdm_context_t *spdm_context;
+     481                 :            :     size_t response_size;
+     482                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     483                 :            :     spdm_certificate_response_t *spdm_response;
+     484                 :            :     void *data;
+     485                 :            :     size_t data_size;
+     486                 :            : 
+     487                 :          1 :     spdm_test_context = *state;
+     488                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     489                 :          1 :     spdm_test_context->case_id = 0x7;
+     490                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13
+     491                 :            :                                             << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     492                 :          1 :     spdm_context->connection_info.connection_state =
+     493                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_DIGESTS;
+     494                 :          1 :     spdm_context->local_context.capability.flags = 0;
+     495                 :          1 :     spdm_context->local_context.capability.flags |=
+     496                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     497                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     498                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     499                 :            :                                                     m_libspdm_use_asym_algo,
+     500                 :            :                                                     &data, &data_size, NULL, NULL);
+     501                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     502                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
+     503                 :            : 
+     504                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     505                 :            :     spdm_context->transcript.message_mut_b.buffer_size = 0;
+     506                 :            : #endif
+     507                 :            : 
+     508                 :            :     /* When SlotSizeRequested=1b , the Offset and Length fields in the GET_CERTIFICATE request shall be ignored by the Responder */
+     509                 :          1 :     m_spdm_get_certificate_request4.header.param2 =
+     510                 :            :         SPDM_GET_CERTIFICATE_REQUEST_ATTRIBUTES_SLOT_SIZE_REQUESTED;
+     511                 :          1 :     m_spdm_get_certificate_request4.length = LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN;
+     512                 :          1 :     m_spdm_get_certificate_request4.offset = 0xFF;
+     513                 :            : 
+     514                 :          1 :     response_size = sizeof(response);
+     515                 :          1 :     status = libspdm_get_encap_response_certificate(
+     516                 :            :         spdm_context, m_spdm_get_certificate_request4_size,
+     517                 :            :         &m_spdm_get_certificate_request4, &response_size, response);
+     518                 :            : 
+     519                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     520                 :          1 :     assert_int_equal(response_size, sizeof(spdm_certificate_response_t));
+     521                 :          1 :     spdm_response = (void *)response;
+     522                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     523                 :            :                      SPDM_CERTIFICATE);
+     524                 :          1 :     assert_int_equal(spdm_response->header.param1, 0);
+     525                 :          1 :     assert_int_equal(spdm_response->portion_length,0);
+     526                 :          1 :     assert_int_equal(spdm_response->remainder_length, data_size);
+     527                 :            : 
+     528                 :          1 :     free(data);
+     529                 :          1 : }
+     530                 :            : 
+     531                 :            : libspdm_test_context_t m_libspdm_requester_encap_certificate_test_context = {
+     532                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+     533                 :            :     false,
+     534                 :            : };
+     535                 :            : 
+     536                 :          1 : int libspdm_requester_encap_certificate_test_main(void)
+     537                 :            : {
+     538                 :          1 :     const struct CMUnitTest spdm_requester_encap_certificate_tests[] = {
+     539                 :            :         /* Success Case*/
+     540                 :            :         cmocka_unit_test(libspdm_test_requester_encap_certificate_case1),
+     541                 :            :         /* Can be populated with new test.*/
+     542                 :            :         cmocka_unit_test(libspdm_test_requester_encap_certificate_case2),
+     543                 :            :         /* Tests varying offset*/
+     544                 :            :         cmocka_unit_test(libspdm_test_requester_encap_certificate_case4),
+     545                 :            :         /* Tests large certificate chains*/
+     546                 :            :         cmocka_unit_test(libspdm_test_requester_encap_certificate_case5),
+     547                 :            :         /* Requests byte by byte*/
+     548                 :            :         cmocka_unit_test(libspdm_test_requester_encap_certificate_case6),
+     549                 :            :         /* check request attributes and response attributes*/
+     550                 :            :         cmocka_unit_test(libspdm_test_requester_encap_certificate_case7),
+     551                 :            :     };
+     552                 :            : 
+     553                 :          1 :     libspdm_setup_test_context(&m_libspdm_requester_encap_certificate_test_context);
+     554                 :            : 
+     555                 :          1 :     return cmocka_run_group_tests(spdm_requester_encap_certificate_tests,
+     556                 :            :                                   libspdm_unit_test_group_setup,
+     557                 :            :                                   libspdm_unit_test_group_teardown);
+     558                 :            : }
+     559                 :            : 
+     560                 :            : #endif /* (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (..) */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/encap_challenge_auth.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_requester/encap_challenge_auth.c.func-sort-c.html new file mode 100644 index 00000000000..81664589470 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/encap_challenge_auth.c.func-sort-c.html @@ -0,0 +1,117 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/encap_challenge_auth.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - encap_challenge_auth.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:239239100.0 %
Date:2024-09-22 08:21:07Functions:99100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_encap_challenge_auth_test_main1
test_libspdm_requester_encap_challenge_auth_case11
test_libspdm_requester_encap_challenge_auth_case21
test_libspdm_requester_encap_challenge_auth_case31
test_libspdm_requester_encap_challenge_auth_case41
test_libspdm_requester_encap_challenge_auth_case51
test_libspdm_requester_encap_challenge_auth_case61
test_libspdm_requester_encap_challenge_auth_case71
test_libspdm_requester_encap_challenge_auth_case81
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/encap_challenge_auth.c.func.html b/coverage_log/unit_test/test_spdm_requester/encap_challenge_auth.c.func.html new file mode 100644 index 00000000000..cbbc5ed478f --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/encap_challenge_auth.c.func.html @@ -0,0 +1,117 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/encap_challenge_auth.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - encap_challenge_auth.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:239239100.0 %
Date:2024-09-22 08:21:07Functions:99100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_encap_challenge_auth_test_main1
test_libspdm_requester_encap_challenge_auth_case11
test_libspdm_requester_encap_challenge_auth_case21
test_libspdm_requester_encap_challenge_auth_case31
test_libspdm_requester_encap_challenge_auth_case41
test_libspdm_requester_encap_challenge_auth_case51
test_libspdm_requester_encap_challenge_auth_case61
test_libspdm_requester_encap_challenge_auth_case71
test_libspdm_requester_encap_challenge_auth_case81
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/encap_challenge_auth.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/encap_challenge_auth.c.gcov.html new file mode 100644 index 00000000000..22361c08ec2 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/encap_challenge_auth.c.gcov.html @@ -0,0 +1,682 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/encap_challenge_auth.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - encap_challenge_auth.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:239239100.0 %
Date:2024-09-22 08:21:07Functions:99100.0 %
Branches:00-
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_requester_lib.h"
+       9                 :            : 
+      10                 :            : #if (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP) && \
+      11                 :            :     (LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP)
+      12                 :            : 
+      13                 :            : spdm_challenge_request_t m_spdm_challenge_request1 = {
+      14                 :            :     {SPDM_MESSAGE_VERSION_11, SPDM_CHALLENGE, 0,
+      15                 :            :      SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH},
+      16                 :            : };
+      17                 :            : size_t m_spdm_challenge_request1_size = sizeof(m_spdm_challenge_request1);
+      18                 :            : 
+      19                 :            : spdm_challenge_request_t m_spdm_challenge_request3 = {
+      20                 :            :     {SPDM_MESSAGE_VERSION_11, SPDM_CHALLENGE, SPDM_MAX_SLOT_COUNT,
+      21                 :            :      SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH},
+      22                 :            : };
+      23                 :            : size_t m_spdm_challenge_request3_size = sizeof(m_spdm_challenge_request3);
+      24                 :            : 
+      25                 :            : spdm_challenge_request_t m_spdm_challenge_request4 = {
+      26                 :            :     {SPDM_MESSAGE_VERSION_11, SPDM_CHALLENGE, 0xFF,
+      27                 :            :      SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH},
+      28                 :            : };
+      29                 :            : size_t m_spdm_challenge_request4_size = sizeof(m_spdm_challenge_request4);
+      30                 :            : 
+      31                 :            : spdm_challenge_request_t m_spdm_challenge_request5 = {
+      32                 :            :     {SPDM_MESSAGE_VERSION_13, SPDM_CHALLENGE, 0,
+      33                 :            :      SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH},
+      34                 :            : };
+      35                 :            : size_t m_spdm_challenge_request5_size = sizeof(m_spdm_challenge_request5);
+      36                 :            : 
+      37                 :            : extern size_t libspdm_secret_lib_challenge_opaque_data_size;
+      38                 :            : 
+      39                 :            : /**
+      40                 :            :  * Test 1: receiving a correct CHALLENGE message from the requester with
+      41                 :            :  * no opaque data, no measurements, and slot number 0.
+      42                 :            :  * Expected behavior: the requester accepts the request and produces a valid
+      43                 :            :  * CHALLENGE_AUTH response message and Completion of CHALLENGE sets M1/M2 to null.
+      44                 :            :  **/
+      45                 :          1 : void test_libspdm_requester_encap_challenge_auth_case1(void **state)
+      46                 :            : {
+      47                 :            :     libspdm_return_t status;
+      48                 :            :     libspdm_test_context_t *spdm_test_context;
+      49                 :            :     libspdm_context_t *spdm_context;
+      50                 :            :     size_t response_size;
+      51                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+      52                 :            :     spdm_challenge_auth_response_t *spdm_response;
+      53                 :            :     void *data;
+      54                 :            :     size_t data_size;
+      55                 :            : 
+      56                 :          1 :     spdm_test_context = *state;
+      57                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+      58                 :          1 :     spdm_test_context->case_id = 0x1;
+      59                 :            : 
+      60                 :          1 :     spdm_context->local_context.capability.flags = 0;
+      61                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
+      62                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP;
+      63                 :          1 :     spdm_context->connection_info.capability.flags = 0;
+      64                 :            : 
+      65                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+      66                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+      67                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+      68                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+      69                 :            :         m_libspdm_use_measurement_hash_algo;
+      70                 :            : 
+      71                 :          1 :     spdm_context->connection_info.connection_state =
+      72                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+      73                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+      74                 :            :         m_libspdm_use_hash_algo;
+      75                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+      76                 :            :         m_libspdm_use_asym_algo;
+      77                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+      78                 :            :         m_libspdm_use_measurement_spec;
+      79                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+      80                 :            :         m_libspdm_use_measurement_hash_algo;
+      81                 :            : 
+      82                 :          1 :     spdm_context->connection_info.algorithm.req_base_asym_alg =
+      83                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048;
+      84                 :            : 
+      85                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11
+      86                 :            :                                             << SPDM_VERSION_NUMBER_SHIFT_BIT;
+      87                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+      88                 :            :                                                     m_libspdm_use_asym_algo, &data,
+      89                 :            :                                                     &data_size, NULL, NULL);
+      90                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+      91                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+      92                 :            :         data_size;
+      93                 :            : 
+      94                 :          1 :     libspdm_secret_lib_challenge_opaque_data_size = 0;
+      95                 :          1 :     libspdm_reset_message_mut_c(spdm_context);
+      96                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+      97                 :            :     spdm_context->transcript.message_m.buffer_size =
+      98                 :            :         spdm_context->transcript.message_m.max_buffer_size;
+      99                 :            : #endif
+     100                 :            : 
+     101                 :          1 :     response_size = sizeof(response);
+     102                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
+     103                 :            :                               m_spdm_challenge_request1.nonce);
+     104                 :          1 :     status = libspdm_get_encap_response_challenge_auth(
+     105                 :            :         spdm_context, m_spdm_challenge_request1_size,
+     106                 :            :         &m_spdm_challenge_request1, &response_size, response);
+     107                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     108                 :          1 :     assert_int_equal(response_size, sizeof(spdm_challenge_auth_response_t) +
+     109                 :            :                      libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo) +
+     110                 :            :                      SPDM_NONCE_SIZE + 0 +
+     111                 :            :                      sizeof(uint16_t) +
+     112                 :            :                      libspdm_secret_lib_challenge_opaque_data_size +
+     113                 :            :                      libspdm_get_req_asym_signature_size(
+     114                 :            :                          spdm_context->connection_info.algorithm.req_base_asym_alg));
+     115                 :          1 :     spdm_response = (void *)response;
+     116                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     117                 :            :                      SPDM_CHALLENGE_AUTH);
+     118                 :          1 :     assert_int_equal(spdm_response->header.param1, 0);
+     119                 :          1 :     assert_int_equal(spdm_response->header.param2, 1 << 0);
+     120                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     121                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
+     122                 :            :                      0);
+     123                 :            :     assert_int_equal(spdm_context->transcript.message_mut_c.buffer_size, 0);
+     124                 :            : #else
+     125                 :          1 :     assert_null(spdm_context->transcript.digest_context_mut_m1m2);
+     126                 :            : #endif
+     127                 :          1 :     free(data);
+     128                 :          1 : }
+     129                 :            : 
+     130                 :            : /**
+     131                 :            :  * Test 2:
+     132                 :            :  * Expected behavior:
+     133                 :            :  **/
+     134                 :          1 : void test_libspdm_requester_encap_challenge_auth_case2(void **state)
+     135                 :            : {
+     136                 :          1 : }
+     137                 :            : 
+     138                 :            : /**
+     139                 :            :  * Test 3: receiving a correct CHALLENGE from the requester, but the requester does not
+     140                 :            :  * have the challenge capability set.
+     141                 :            :  * Expected behavior: the requester accepts the request and produces a valid
+     142                 :            :  * CHALLENGE_AUTH response message.
+     143                 :            :  **/
+     144                 :          1 : void test_libspdm_requester_encap_challenge_auth_case3(void **state)
+     145                 :            : {
+     146                 :            :     libspdm_return_t status;
+     147                 :            :     libspdm_test_context_t *spdm_test_context;
+     148                 :            :     libspdm_context_t *spdm_context;
+     149                 :            :     size_t response_size;
+     150                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     151                 :            :     spdm_challenge_auth_response_t *spdm_response;
+     152                 :            :     void *data;
+     153                 :            :     size_t data_size;
+     154                 :            : 
+     155                 :          1 :     spdm_test_context = *state;
+     156                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     157                 :          1 :     spdm_test_context->case_id = 0x3;
+     158                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     159                 :          1 :     spdm_context->local_context.capability.flags = 0;
+     160                 :            :     /* spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;*/
+     161                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     162                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     163                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+     164                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     165                 :            :         m_libspdm_use_measurement_hash_algo;
+     166                 :            : 
+     167                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11
+     168                 :            :                                             << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     169                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     170                 :            :                                                     m_libspdm_use_asym_algo, &data, &data_size,
+     171                 :            :                                                     NULL, NULL);
+     172                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     173                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
+     174                 :            : 
+     175                 :          1 :     libspdm_secret_lib_challenge_opaque_data_size = 0;
+     176                 :          1 :     libspdm_reset_message_c(spdm_context);
+     177                 :            : 
+     178                 :          1 :     response_size = sizeof(response);
+     179                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE, m_spdm_challenge_request1.nonce);
+     180                 :          1 :     status = libspdm_get_encap_response_challenge_auth(spdm_context, m_spdm_challenge_request1_size,
+     181                 :            :                                                        &m_spdm_challenge_request1, &response_size,
+     182                 :            :                                                        response);
+     183                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     184                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     185                 :          1 :     spdm_response = (void *)response;
+     186                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
+     187                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST);
+     188                 :          1 :     assert_int_equal(spdm_response->header.param2, SPDM_CHALLENGE);
+     189                 :          1 :     free(data);
+     190                 :          1 : }
+     191                 :            : 
+     192                 :            : /**
+     193                 :            :  * Test 4: receiving an incorrect CHALLENGE from the requester, with the slot number
+     194                 :            :  * larger than the specification limit.
+     195                 :            :  * Expected behavior: the requester rejects the request, and produces an ERROR message
+     196                 :            :  * indicating the UnexpectedRequest.
+     197                 :            :  **/
+     198                 :          1 : void test_libspdm_requester_encap_challenge_auth_case4(void **state)
+     199                 :            : {
+     200                 :            :     libspdm_return_t status;
+     201                 :            :     libspdm_test_context_t *spdm_test_context;
+     202                 :            :     libspdm_context_t *spdm_context;
+     203                 :            :     size_t response_size;
+     204                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     205                 :            :     spdm_challenge_auth_response_t *spdm_response;
+     206                 :            :     void *data;
+     207                 :            :     size_t data_size;
+     208                 :            : 
+     209                 :          1 :     spdm_test_context = *state;
+     210                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     211                 :          1 :     spdm_test_context->case_id = 0x4;
+     212                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     213                 :          1 :     spdm_context->local_context.capability.flags = 0;
+     214                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
+     215                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     216                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     217                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+     218                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     219                 :            :         m_libspdm_use_measurement_hash_algo;
+     220                 :            : 
+     221                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11
+     222                 :            :                                             << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     223                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     224                 :            :                                                     m_libspdm_use_asym_algo, &data, &data_size,
+     225                 :            :                                                     NULL, NULL);
+     226                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     227                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
+     228                 :            : 
+     229                 :          1 :     libspdm_secret_lib_challenge_opaque_data_size = 0;
+     230                 :          1 :     libspdm_reset_message_c(spdm_context);
+     231                 :            : 
+     232                 :          1 :     response_size = sizeof(response);
+     233                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE, m_spdm_challenge_request1.nonce);
+     234                 :          1 :     status = libspdm_get_encap_response_challenge_auth(spdm_context, m_spdm_challenge_request3_size,
+     235                 :            :                                                        &m_spdm_challenge_request3, &response_size,
+     236                 :            :                                                        response);
+     237                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     238                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     239                 :          1 :     spdm_response = (void *)response;
+     240                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
+     241                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+     242                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     243                 :          1 :     free(data);
+     244                 :          1 : }
+     245                 :            : 
+     246                 :            : /**
+     247                 :            :  * Test 5: receiving a correct CHALLENGE from the requester, but with certificate
+     248                 :            :  * unavailable at the requested slot number (1).
+     249                 :            :  * Expected behavior: the requester rejects the request, and produces an ERROR message
+     250                 :            :  * indicating the UnexpectedRequest.
+     251                 :            :  **/
+     252                 :          1 : void test_libspdm_requester_encap_challenge_auth_case5(void **state)
+     253                 :            : {
+     254                 :            :     libspdm_return_t status;
+     255                 :            :     libspdm_test_context_t *spdm_test_context;
+     256                 :            :     libspdm_context_t *spdm_context;
+     257                 :            :     size_t response_size;
+     258                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     259                 :            :     spdm_challenge_auth_response_t *spdm_response;
+     260                 :            :     void *data;
+     261                 :            :     size_t data_size;
+     262                 :            : 
+     263                 :          1 :     spdm_test_context = *state;
+     264                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     265                 :          1 :     spdm_test_context->case_id = 0x05;
+     266                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     267                 :          1 :     spdm_context->local_context.capability.flags = 0;
+     268                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
+     269                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     270                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     271                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+     272                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     273                 :            :         m_libspdm_use_measurement_hash_algo;
+     274                 :            : 
+     275                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11
+     276                 :            :                                             << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     277                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     278                 :            :                                                     m_libspdm_use_asym_algo, &data, &data_size,
+     279                 :            :                                                     NULL, NULL);
+     280                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     281                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
+     282                 :            : 
+     283                 :          1 :     libspdm_secret_lib_challenge_opaque_data_size = 0;
+     284                 :          1 :     libspdm_reset_message_c(spdm_context);
+     285                 :            : 
+     286                 :          1 :     response_size = sizeof(response);
+     287                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE, m_spdm_challenge_request1.nonce);
+     288                 :          1 :     status = libspdm_get_encap_response_challenge_auth(spdm_context, m_spdm_challenge_request3_size,
+     289                 :            :                                                        &m_spdm_challenge_request3, &response_size,
+     290                 :            :                                                        response);
+     291                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     292                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     293                 :          1 :     spdm_response = (void *)response;
+     294                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
+     295                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+     296                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     297                 :          1 :     free(data);
+     298                 :          1 : }
+     299                 :            : 
+     300                 :            : /**
+     301                 :            :  * Test 6: receiving a correct CHALLENGE message from the requester with
+     302                 :            :  * no opaque data, no measurements, and slot number 0xFF.
+     303                 :            :  * Expected behavior: the requester accepts the request and produces a valid
+     304                 :            :  * CHALLENGE_AUTH response message using provisioned public key (slot number 0xFF).
+     305                 :            :  **/
+     306                 :          1 : void test_libspdm_requester_encap_challenge_auth_case6(void **state)
+     307                 :            : {
+     308                 :            :     libspdm_return_t status;
+     309                 :            :     libspdm_test_context_t *spdm_test_context;
+     310                 :            :     libspdm_context_t *spdm_context;
+     311                 :            :     size_t response_size;
+     312                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     313                 :            :     spdm_challenge_auth_response_t *spdm_response;
+     314                 :            :     void *data;
+     315                 :            :     size_t data_size;
+     316                 :            : 
+     317                 :          1 :     spdm_test_context = *state;
+     318                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     319                 :          1 :     spdm_test_context->case_id = 0x6;
+     320                 :            : 
+     321                 :          1 :     spdm_context->local_context.capability.flags = 0;
+     322                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP;
+     323                 :            : 
+     324                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     325                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     326                 :          1 :     spdm_context->connection_info.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+     327                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11
+     328                 :            :                                             << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     329                 :            : 
+     330                 :          1 :     libspdm_read_requester_public_key(m_libspdm_use_req_asym_algo, &data, &data_size);
+     331                 :          1 :     spdm_context->local_context.local_public_key_provision = data;
+     332                 :          1 :     spdm_context->local_context.local_public_key_provision_size = data_size;
+     333                 :            : 
+     334                 :          1 :     libspdm_secret_lib_challenge_opaque_data_size = 0;
+     335                 :          1 :     libspdm_reset_message_c(spdm_context);
+     336                 :            : 
+     337                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     338                 :            :     spdm_context->transcript.message_m.buffer_size =
+     339                 :            :         spdm_context->transcript.message_m.max_buffer_size;
+     340                 :            : #endif
+     341                 :            : 
+     342                 :          1 :     response_size = sizeof(response);
+     343                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE, m_spdm_challenge_request4.nonce);
+     344                 :          1 :     status = libspdm_get_encap_response_challenge_auth(
+     345                 :            :         spdm_context,
+     346                 :            :         m_spdm_challenge_request4_size, &m_spdm_challenge_request4,
+     347                 :            :         &response_size, response);
+     348                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     349                 :          1 :     assert_int_equal(
+     350                 :            :         response_size,
+     351                 :            :         sizeof(spdm_challenge_auth_response_t) +
+     352                 :            :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo) +
+     353                 :            :         SPDM_NONCE_SIZE + 0 +
+     354                 :            :         sizeof(uint16_t) + 0 +
+     355                 :            :         libspdm_get_req_asym_signature_size(
+     356                 :            :             spdm_context->connection_info.algorithm.req_base_asym_alg));
+     357                 :          1 :     spdm_response = (void *)response;
+     358                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_CHALLENGE_AUTH);
+     359                 :          1 :     assert_int_equal(spdm_response->header.param1, 0xF);
+     360                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     361                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     362                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+     363                 :            : #endif
+     364                 :          1 :     free(data);
+     365                 :          1 : }
+     366                 :            : 
+     367                 :            : /**
+     368                 :            :  * Test 7: receiving a correct CHALLENGE message from the requester with context field
+     369                 :            :  * no opaque data, no measurements, and slot number 0.
+     370                 :            :  * Expected behavior:  get a RETURN_SUCCESS return code, correct context field
+     371                 :            :  **/
+     372                 :          1 : void test_libspdm_requester_encap_challenge_auth_case7(void **state)
+     373                 :            : {
+     374                 :            :     libspdm_return_t status;
+     375                 :            :     libspdm_test_context_t *spdm_test_context;
+     376                 :            :     libspdm_context_t *spdm_context;
+     377                 :            :     size_t response_size;
+     378                 :            :     uint8_t request[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     379                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     380                 :            :     spdm_challenge_auth_response_t *spdm_response;
+     381                 :            :     void *data;
+     382                 :            :     size_t data_size;
+     383                 :            :     uint8_t *requester_context;
+     384                 :            :     uint8_t *responder_context;
+     385                 :            : 
+     386                 :          1 :     spdm_test_context = *state;
+     387                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     388                 :          1 :     spdm_test_context->case_id = 0x7;
+     389                 :            : 
+     390                 :          1 :     spdm_context->local_context.capability.flags = 0;
+     391                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
+     392                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP;
+     393                 :          1 :     spdm_context->connection_info.capability.flags = 0;
+     394                 :            : 
+     395                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     396                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     397                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+     398                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     399                 :            :         m_libspdm_use_measurement_hash_algo;
+     400                 :            : 
+     401                 :          1 :     spdm_context->connection_info.connection_state =
+     402                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     403                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     404                 :            :         m_libspdm_use_hash_algo;
+     405                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     406                 :            :         m_libspdm_use_asym_algo;
+     407                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     408                 :            :         m_libspdm_use_measurement_spec;
+     409                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     410                 :            :         m_libspdm_use_measurement_hash_algo;
+     411                 :          1 :     spdm_context->connection_info.algorithm.req_base_asym_alg =
+     412                 :            :         m_libspdm_use_req_asym_algo;
+     413                 :            : 
+     414                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13
+     415                 :            :                                             << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     416                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     417                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     418                 :            :                                                     &data_size, NULL, NULL);
+     419                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     420                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     421                 :            :         data_size;
+     422                 :            : 
+     423                 :          1 :     libspdm_reset_message_mut_c(spdm_context);
+     424                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     425                 :            :     spdm_context->transcript.message_m.buffer_size =
+     426                 :            :         spdm_context->transcript.message_m.max_buffer_size;
+     427                 :            : #endif
+     428                 :            : 
+     429                 :          1 :     response_size = sizeof(response);
+     430                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
+     431                 :            :                               m_spdm_challenge_request5.nonce);
+     432                 :            : 
+     433                 :          1 :     libspdm_zero_mem(request, sizeof(request));
+     434                 :          1 :     libspdm_copy_mem(request, sizeof(spdm_challenge_request_t),
+     435                 :            :                      &m_spdm_challenge_request5, m_spdm_challenge_request5_size);
+     436                 :          1 :     requester_context = request + m_spdm_challenge_request5_size;
+     437                 :          1 :     libspdm_set_mem(requester_context, SPDM_REQ_CONTEXT_SIZE, 0xAA);
+     438                 :          1 :     m_spdm_challenge_request5_size += SPDM_REQ_CONTEXT_SIZE;
+     439                 :            : 
+     440                 :          1 :     status = libspdm_get_encap_response_challenge_auth(
+     441                 :            :         spdm_context, m_spdm_challenge_request5_size,
+     442                 :            :         request, &response_size, response);
+     443                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     444                 :          1 :     assert_int_equal(response_size, sizeof(spdm_challenge_auth_response_t) +
+     445                 :            :                      libspdm_get_hash_size(m_libspdm_use_hash_algo) +
+     446                 :            :                      SPDM_NONCE_SIZE + 0 + sizeof(uint16_t) +
+     447                 :            :                      libspdm_get_asym_signature_size(m_libspdm_use_req_asym_algo) +
+     448                 :            :                      SPDM_REQ_CONTEXT_SIZE);
+     449                 :          1 :     spdm_response = (void *)response;
+     450                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     451                 :            :                      SPDM_CHALLENGE_AUTH);
+     452                 :          1 :     assert_int_equal(spdm_response->header.param1, 0);
+     453                 :          1 :     assert_int_equal(spdm_response->header.param2, 1 << 0);
+     454                 :            : 
+     455                 :          1 :     responder_context = (void *)response;
+     456                 :          1 :     responder_context += sizeof(spdm_challenge_auth_response_t) +
+     457                 :          1 :                          libspdm_get_hash_size(m_libspdm_use_hash_algo) +
+     458                 :          1 :                          SPDM_NONCE_SIZE + 0 + sizeof(uint16_t);
+     459                 :          1 :     assert_memory_equal(requester_context, responder_context, SPDM_REQ_CONTEXT_SIZE);
+     460                 :            : 
+     461                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     462                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
+     463                 :            :                      0);
+     464                 :            :     assert_int_equal(spdm_context->transcript.message_mut_c.buffer_size, 0);
+     465                 :            : #else
+     466                 :          1 :     assert_null(spdm_context->transcript.digest_context_mut_m1m2);
+     467                 :            : #endif
+     468                 :          1 :     free(data);
+     469                 :          1 : }
+     470                 :            : 
+     471                 :            : /**
+     472                 :            :  * Test 8: The key usage bit mask is not set, the SlotID fields in CHALLENGE and CHALLENGE_AUTH shall not specify this certificate slot
+     473                 :            :  * Expected behavior: the responder accepts the request, but produces an ERROR message
+     474                 :            :  * indicating the invalid state.
+     475                 :            :  **/
+     476                 :          1 : void test_libspdm_requester_encap_challenge_auth_case8(void **state)
+     477                 :            : {
+     478                 :            :     libspdm_return_t status;
+     479                 :            :     libspdm_test_context_t *spdm_test_context;
+     480                 :            :     libspdm_context_t *spdm_context;
+     481                 :            :     size_t response_size;
+     482                 :            :     uint8_t request[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     483                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     484                 :            :     spdm_challenge_auth_response_t *spdm_response;
+     485                 :            :     void *data;
+     486                 :            :     size_t data_size;
+     487                 :            :     uint8_t *requester_context;
+     488                 :            :     uint8_t slot_id;
+     489                 :            : 
+     490                 :          1 :     spdm_test_context = *state;
+     491                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     492                 :          1 :     spdm_test_context->case_id = 0x8;
+     493                 :            : 
+     494                 :          1 :     spdm_context->local_context.capability.flags = 0;
+     495                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
+     496                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP;
+     497                 :          1 :     spdm_context->connection_info.capability.flags = 0;
+     498                 :            : 
+     499                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     500                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     501                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+     502                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     503                 :            :         m_libspdm_use_measurement_hash_algo;
+     504                 :            : 
+     505                 :          1 :     spdm_context->connection_info.connection_state =
+     506                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     507                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     508                 :            :         m_libspdm_use_hash_algo;
+     509                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     510                 :            :         m_libspdm_use_asym_algo;
+     511                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     512                 :            :         m_libspdm_use_measurement_spec;
+     513                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     514                 :            :         m_libspdm_use_measurement_hash_algo;
+     515                 :          1 :     spdm_context->connection_info.algorithm.req_base_asym_alg =
+     516                 :            :         m_libspdm_use_req_asym_algo;
+     517                 :          1 :     spdm_context->connection_info.multi_key_conn_req = true;
+     518                 :            : 
+     519                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13
+     520                 :            :                                             << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     521                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     522                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     523                 :            :                                                     &data_size, NULL, NULL);
+     524                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     525                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     526                 :            :         data_size;
+     527                 :            : 
+     528                 :          1 :     libspdm_reset_message_mut_c(spdm_context);
+     529                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     530                 :            :     spdm_context->transcript.message_m.buffer_size =
+     531                 :            :         spdm_context->transcript.message_m.max_buffer_size;
+     532                 :            : #endif
+     533                 :            : 
+     534                 :            :     /* If set, the SlotID fields in CHALLENGE and CHALLENGE_AUTH can specify this certificate slot. If not set, the
+     535                 :            :      * SlotID fields in CHALLENGE and CHALLENGE_AUTH shall not specify this certificate slot. */
+     536                 :          1 :     slot_id = 0;
+     537                 :          1 :     m_spdm_challenge_request5.header.param1 = slot_id;
+     538                 :          1 :     spdm_context->local_context.local_key_usage_bit_mask[slot_id] =
+     539                 :            :         SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE |
+     540                 :            :         SPDM_KEY_USAGE_BIT_MASK_MEASUREMENT_USE;
+     541                 :            : 
+     542                 :          1 :     response_size = sizeof(response);
+     543                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
+     544                 :            :                               m_spdm_challenge_request5.nonce);
+     545                 :            : 
+     546                 :          1 :     libspdm_zero_mem(request, sizeof(request));
+     547                 :          1 :     libspdm_copy_mem(request, sizeof(spdm_challenge_request_t),
+     548                 :            :                      &m_spdm_challenge_request5, sizeof(m_spdm_challenge_request5));
+     549                 :          1 :     requester_context = request + sizeof(m_spdm_challenge_request5);
+     550                 :          1 :     libspdm_set_mem(requester_context, SPDM_REQ_CONTEXT_SIZE, 0xAA);
+     551                 :          1 :     m_spdm_challenge_request5_size = sizeof(m_spdm_challenge_request5) + SPDM_REQ_CONTEXT_SIZE;
+     552                 :            : 
+     553                 :          1 :     status = libspdm_get_encap_response_challenge_auth(
+     554                 :            :         spdm_context, m_spdm_challenge_request5_size,
+     555                 :            :         request, &response_size, response);
+     556                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     557                 :          1 :     assert_int_equal (response_size, sizeof(spdm_error_response_t));
+     558                 :          1 :     spdm_response = (void *)response;
+     559                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_ERROR);
+     560                 :          1 :     assert_int_equal (spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+     561                 :          1 :     assert_int_equal (spdm_response->header.param2, 0);
+     562                 :            : 
+     563                 :          1 :     free(data);
+     564                 :          1 : }
+     565                 :            : 
+     566                 :            : libspdm_test_context_t m_spdm_requester_challenge_auth_test_context = {
+     567                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+     568                 :            :     false,
+     569                 :            : };
+     570                 :            : 
+     571                 :          1 : int libspdm_requester_encap_challenge_auth_test_main(void)
+     572                 :            : {
+     573                 :          1 :     const struct CMUnitTest spdm_requester_challenge_auth_tests[] = {
+     574                 :            :         /* Success Case*/
+     575                 :            :         cmocka_unit_test(test_libspdm_requester_encap_challenge_auth_case1),
+     576                 :            :         /* Can be populated with new test.*/
+     577                 :            :         cmocka_unit_test(test_libspdm_requester_encap_challenge_auth_case2),
+     578                 :            :         /* connection_state Check*/
+     579                 :            :         cmocka_unit_test(test_libspdm_requester_encap_challenge_auth_case3),
+     580                 :            :         cmocka_unit_test(test_libspdm_requester_encap_challenge_auth_case4),
+     581                 :            :         cmocka_unit_test(test_libspdm_requester_encap_challenge_auth_case5),
+     582                 :            :         /* Success Case, use provisioned public key (slot 0xFF) */
+     583                 :            :         cmocka_unit_test(test_libspdm_requester_encap_challenge_auth_case6),
+     584                 :            :         /* Success Case: V1.3 get a correct context field */
+     585                 :            :         cmocka_unit_test(test_libspdm_requester_encap_challenge_auth_case7),
+     586                 :            :         /* The key usage bit mask is not set, failed Case*/
+     587                 :            :         cmocka_unit_test(test_libspdm_requester_encap_challenge_auth_case8),
+     588                 :            :     };
+     589                 :            : 
+     590                 :          1 :     libspdm_setup_test_context(&m_spdm_requester_challenge_auth_test_context);
+     591                 :            : 
+     592                 :          1 :     return cmocka_run_group_tests(spdm_requester_challenge_auth_tests,
+     593                 :            :                                   libspdm_unit_test_group_setup,
+     594                 :            :                                   libspdm_unit_test_group_teardown);
+     595                 :            : }
+     596                 :            : 
+     597                 :            : #endif /* (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (..) */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/encap_digests.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_requester/encap_digests.c.func-sort-c.html new file mode 100644 index 00000000000..26d7b0183a2 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/encap_digests.c.func-sort-c.html @@ -0,0 +1,109 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/encap_digests.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - encap_digests.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:132132100.0 %
Date:2024-09-22 08:21:07Functions:77100.0 %
Branches:44100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_encap_digests_test_main1
test_spdm_requester_encap_get_digests_case11
test_spdm_requester_encap_get_digests_case21
test_spdm_requester_encap_get_digests_case31
test_spdm_requester_encap_get_digests_case41
test_spdm_requester_encap_get_digests_case51
test_spdm_requester_encap_get_digests_case61
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/encap_digests.c.func.html b/coverage_log/unit_test/test_spdm_requester/encap_digests.c.func.html new file mode 100644 index 00000000000..5526d2bd676 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/encap_digests.c.func.html @@ -0,0 +1,109 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/encap_digests.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - encap_digests.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:132132100.0 %
Date:2024-09-22 08:21:07Functions:77100.0 %
Branches:44100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_encap_digests_test_main1
test_spdm_requester_encap_get_digests_case11
test_spdm_requester_encap_get_digests_case21
test_spdm_requester_encap_get_digests_case31
test_spdm_requester_encap_get_digests_case41
test_spdm_requester_encap_get_digests_case51
test_spdm_requester_encap_get_digests_case61
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/encap_digests.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/encap_digests.c.gcov.html new file mode 100644 index 00000000000..1d9f8f0501d --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/encap_digests.c.gcov.html @@ -0,0 +1,523 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/encap_digests.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - encap_digests.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:132132100.0 %
Date:2024-09-22 08:21:07Functions:77100.0 %
Branches:44100.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 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                 :            : #include "spdm_unit_test.h"
+       7                 :            : #include "internal/libspdm_requester_lib.h"
+       8                 :            : 
+       9                 :            : #if (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP) && \
+      10                 :            :     (LIBSPDM_ENABLE_CAPABILITY_CERT_CAP)
+      11                 :            : 
+      12                 :            : spdm_get_digest_request_t m_spdm_get_digests_request1 = {
+      13                 :            :     {
+      14                 :            :         SPDM_MESSAGE_VERSION_11,
+      15                 :            :         SPDM_GET_DIGESTS,
+      16                 :            :     },
+      17                 :            : };
+      18                 :            : size_t m_spdm_get_digests_request1_size = sizeof(m_spdm_get_digests_request1);
+      19                 :            : 
+      20                 :            : 
+      21                 :            : spdm_get_digest_request_t m_spdm_get_digests_request2 = {
+      22                 :            :     {
+      23                 :            :         SPDM_MESSAGE_VERSION_13,
+      24                 :            :         SPDM_GET_DIGESTS,
+      25                 :            :     },
+      26                 :            : };
+      27                 :            : size_t m_spdm_get_digests_request2_size = sizeof(m_spdm_get_digests_request2);
+      28                 :            : 
+      29                 :            : static uint8_t m_local_certificate_chain[LIBSPDM_MAX_CERT_CHAIN_SIZE];
+      30                 :            : 
+      31                 :            : /**
+      32                 :            :  * Test 1: receives a valid GET_DIGESTS request message from Requester
+      33                 :            :  * Expected Behavior: produces a valid DIGESTS response message
+      34                 :            :  **/
+      35                 :          1 : void test_spdm_requester_encap_get_digests_case1(void **state)
+      36                 :            : {
+      37                 :            :     libspdm_return_t status;
+      38                 :            :     libspdm_test_context_t *spdm_test_context;
+      39                 :            :     libspdm_context_t *spdm_context;
+      40                 :            :     size_t response_size;
+      41                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+      42                 :            :     spdm_digest_response_t *spdm_response;
+      43                 :            : 
+      44                 :          1 :     spdm_test_context = *state;
+      45                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+      46                 :          1 :     spdm_test_context->case_id = 0x1;
+      47                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11
+      48                 :            :                                             << SPDM_VERSION_NUMBER_SHIFT_BIT;
+      49                 :          1 :     spdm_context->connection_info.connection_state =
+      50                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+      51                 :          1 :     spdm_context->local_context.capability.flags |=
+      52                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+      53                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+      54                 :            :         m_libspdm_use_hash_algo;
+      55                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] =
+      56                 :            :         m_local_certificate_chain;
+      57                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+      58                 :            :         sizeof(m_local_certificate_chain);
+      59                 :          1 :     libspdm_set_mem(m_local_certificate_chain, sizeof(m_local_certificate_chain),
+      60                 :            :                     (uint8_t)(0xFF));
+      61                 :            : 
+      62                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+      63                 :            :     spdm_context->transcript.message_m.buffer_size =
+      64                 :            :         spdm_context->transcript.message_m.max_buffer_size;
+      65                 :            : #endif
+      66                 :            : 
+      67                 :          1 :     response_size = sizeof(response);
+      68                 :          1 :     status = libspdm_get_encap_response_digest(spdm_context,
+      69                 :            :                                                m_spdm_get_digests_request1_size,
+      70                 :            :                                                &m_spdm_get_digests_request1,
+      71                 :            :                                                &response_size, response);
+      72                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+      73                 :          1 :     assert_int_equal(
+      74                 :            :         response_size,
+      75                 :            :         sizeof(spdm_digest_response_t) +
+      76                 :            :         libspdm_get_hash_size(spdm_context->connection_info
+      77                 :            :                               .algorithm.base_hash_algo));
+      78                 :          1 :     spdm_response = (void *)response;
+      79                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+      80                 :            :                      SPDM_DIGESTS);
+      81                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+      82                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
+      83                 :            :                      0);
+      84                 :            : #endif
+      85                 :          1 : }
+      86                 :            : 
+      87                 :            : /**
+      88                 :            :  * Test 2:
+      89                 :            :  * Expected Behavior:
+      90                 :            :  **/
+      91                 :          1 : void test_spdm_requester_encap_get_digests_case2(void **state)
+      92                 :            : {
+      93                 :          1 : }
+      94                 :            : 
+      95                 :            : /**
+      96                 :            :  * Test 3: receives a valid GET_DIGESTS request message from Requester, but the request message cannot be appended to the internal cache since the internal cache is full
+      97                 :            :  * Expected Behavior: produces an ERROR response message with error code = Unspecified
+      98                 :            :  **/
+      99                 :          1 : void test_spdm_requester_encap_get_digests_case3(void **state)
+     100                 :            : {
+     101                 :            :     libspdm_return_t status;
+     102                 :            :     libspdm_test_context_t *spdm_test_context;
+     103                 :            :     libspdm_context_t *spdm_context;
+     104                 :            :     size_t response_size;
+     105                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     106                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     107                 :            :     spdm_digest_response_t *spdm_response;
+     108                 :            : #endif
+     109                 :          1 :     spdm_test_context = *state;
+     110                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     111                 :          1 :     spdm_test_context->case_id = 0x3;
+     112                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11
+     113                 :            :                                             << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     114                 :          1 :     spdm_context->connection_info.connection_state =
+     115                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     116                 :          1 :     spdm_context->local_context.capability.flags |=
+     117                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     118                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     119                 :            :         m_libspdm_use_hash_algo;
+     120                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] =
+     121                 :            :         m_local_certificate_chain;
+     122                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     123                 :            :         sizeof(m_local_certificate_chain);
+     124                 :          1 :     libspdm_set_mem(m_local_certificate_chain, sizeof(m_local_certificate_chain),
+     125                 :            :                     (uint8_t)(0xFF));
+     126                 :            : 
+     127                 :          1 :     response_size = sizeof(response);
+     128                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     129                 :            :     spdm_context->transcript.message_b.buffer_size =
+     130                 :            :         spdm_context->transcript.message_b.max_buffer_size;
+     131                 :            : #endif
+     132                 :          1 :     status = libspdm_get_encap_response_digest(spdm_context,
+     133                 :            :                                                m_spdm_get_digests_request1_size,
+     134                 :            :                                                &m_spdm_get_digests_request1,
+     135                 :            :                                                &response_size, response);
+     136                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     137                 :            : 
+     138                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     139                 :            :     assert_int_equal(
+     140                 :            :         response_size,
+     141                 :            :         sizeof(spdm_digest_response_t) +
+     142                 :            :         libspdm_get_hash_size(spdm_context->connection_info
+     143                 :            :                               .algorithm.base_hash_algo));
+     144                 :            :     spdm_response = (void *)response;
+     145                 :            :     assert_int_equal(spdm_response->header.request_response_code,
+     146                 :            :                      SPDM_DIGESTS);
+     147                 :            :     assert_int_equal(spdm_response->header.param1,
+     148                 :            :                      0);
+     149                 :            :     assert_int_equal(spdm_response->header.param2, SPDM_ERROR_CODE_INVALID_REQUEST);
+     150                 :            : #endif
+     151                 :          1 : }
+     152                 :            : 
+     153                 :            : /**
+     154                 :            :  * Test 4: receives a valid GET_DIGESTS request message from Requester, but the response message cannot be appended to the internal cache since the internal cache is full
+     155                 :            :  * Expected Behavior: produces an ERROR response message with error code = Unspecified
+     156                 :            :  **/
+     157                 :          1 : void test_spdm_requester_encap_get_digests_case4(void **state)
+     158                 :            : {
+     159                 :            :     libspdm_test_context_t *spdm_test_context;
+     160                 :            :     libspdm_context_t *spdm_context;
+     161                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     162                 :            :     size_t response_size;
+     163                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     164                 :            :     libspdm_return_t status;
+     165                 :            :     spdm_digest_response_t *spdm_response;
+     166                 :            : #endif
+     167                 :            : 
+     168                 :          1 :     spdm_test_context = *state;
+     169                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     170                 :          1 :     spdm_test_context->case_id = 0x4;
+     171                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11
+     172                 :            :                                             << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     173                 :          1 :     spdm_context->connection_info.connection_state =
+     174                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     175                 :          1 :     spdm_context->local_context.capability.flags |=
+     176                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     177                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     178                 :            :         m_libspdm_use_hash_algo;
+     179                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] =
+     180                 :            :         m_local_certificate_chain;
+     181                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     182                 :            :         sizeof(m_local_certificate_chain);
+     183                 :          1 :     libspdm_set_mem(m_local_certificate_chain, sizeof(m_local_certificate_chain),
+     184                 :            :                     (uint8_t)(0xFF));
+     185                 :            : 
+     186                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     187                 :            :     spdm_context->transcript.message_b.buffer_size =
+     188                 :            :         spdm_context->transcript.message_b.max_buffer_size -
+     189                 :            :         sizeof(spdm_get_digest_request_t);
+     190                 :            :     response_size = sizeof(response);
+     191                 :            :     status = libspdm_get_encap_response_digest(spdm_context,
+     192                 :            :                                                m_spdm_get_digests_request1_size,
+     193                 :            :                                                &m_spdm_get_digests_request1,
+     194                 :            :                                                &response_size, response);
+     195                 :            :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     196                 :            :     assert_int_equal(
+     197                 :            :         response_size,
+     198                 :            :         sizeof(spdm_digest_response_t) +
+     199                 :            :         libspdm_get_hash_size(spdm_context->connection_info
+     200                 :            :                               .algorithm.base_hash_algo));
+     201                 :            :     spdm_response = (void *)response;
+     202                 :            :     assert_int_equal(spdm_response->header.request_response_code,
+     203                 :            :                      SPDM_DIGESTS);
+     204                 :            :     assert_int_equal(spdm_response->header.param1,
+     205                 :            :                      0);
+     206                 :            :     assert_int_equal(spdm_response->header.param2, SPDM_ERROR_CODE_INVALID_REQUEST);
+     207                 :            : #endif
+     208                 :          1 : }
+     209                 :            : 
+     210                 :            : /**
+     211                 :            :  * Test 5: receives a valid GET_DIGESTS request message from Requester ,
+     212                 :            :  * Set multi_key_conn_req to check if it responds correctly
+     213                 :            :  * Expected Behavior: produces a valid DIGESTS response message
+     214                 :            :  **/
+     215                 :          1 : void test_spdm_requester_encap_get_digests_case5(void **state)
+     216                 :            : {
+     217                 :            :     libspdm_return_t status;
+     218                 :            :     libspdm_test_context_t *spdm_test_context;
+     219                 :            :     libspdm_context_t *spdm_context;
+     220                 :            :     size_t response_size;
+     221                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     222                 :            :     spdm_digest_response_t *spdm_response;
+     223                 :            :     libspdm_session_info_t *session_info;
+     224                 :            :     uint32_t session_id;
+     225                 :            : 
+     226                 :          1 :     spdm_test_context = *state;
+     227                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     228                 :          1 :     spdm_test_context->case_id = 0x5;
+     229                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13
+     230                 :            :                                             << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     231                 :          1 :     spdm_context->connection_info.connection_state =
+     232                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     233                 :          1 :     spdm_context->local_context.capability.flags |=
+     234                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     235                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     236                 :            :         m_libspdm_use_hash_algo;
+     237                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] =
+     238                 :            :         m_local_certificate_chain;
+     239                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     240                 :            :         sizeof(m_local_certificate_chain);
+     241                 :          1 :     libspdm_set_mem(m_local_certificate_chain, sizeof(m_local_certificate_chain),
+     242                 :            :                     (uint8_t)(0xFF));
+     243                 :            : 
+     244                 :          1 :     session_id = 0xFFFFFFFF;
+     245                 :          1 :     spdm_context->latest_session_id = session_id;
+     246                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+     247                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+     248                 :          1 :     session_info = &spdm_context->session_info[0];
+     249                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+     250                 :          1 :     libspdm_secured_message_set_session_state(
+     251                 :            :         session_info->secured_message_context,
+     252                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+     253                 :            : 
+     254                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     255                 :            :     spdm_context->transcript.message_m.buffer_size =
+     256                 :            :         spdm_context->transcript.message_m.max_buffer_size;
+     257                 :            : #endif
+     258                 :            :     /* Sub Case 1: Set multi_key_conn_req to true*/
+     259                 :          1 :     spdm_context->connection_info.multi_key_conn_req = true;
+     260                 :          1 :     libspdm_reset_message_encap_d(spdm_context, session_info);
+     261                 :            : 
+     262                 :          1 :     response_size = sizeof(response);
+     263                 :          1 :     status = libspdm_get_encap_response_digest(spdm_context,
+     264                 :            :                                                m_spdm_get_digests_request2_size,
+     265                 :            :                                                &m_spdm_get_digests_request2,
+     266                 :            :                                                &response_size, response);
+     267                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     268                 :          1 :     assert_int_equal(
+     269                 :            :         response_size,
+     270                 :            :         sizeof(spdm_digest_response_t) +  sizeof(spdm_key_pair_id_t) +
+     271                 :            :         sizeof(spdm_certificate_info_t) +
+     272                 :            :         sizeof(spdm_key_usage_bit_mask_t) +
+     273                 :            :         libspdm_get_hash_size(spdm_context->connection_info
+     274                 :            :                               .algorithm.base_hash_algo));
+     275                 :          1 :     spdm_response = (void *)response;
+     276                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     277                 :            :                      SPDM_DIGESTS);
+     278                 :          1 :     assert_int_equal(session_info->session_transcript.message_encap_d.buffer_size,
+     279                 :            :                      sizeof(spdm_digest_response_t) +  sizeof(spdm_key_pair_id_t) +
+     280                 :            :                      sizeof(spdm_certificate_info_t) +
+     281                 :            :                      sizeof(spdm_key_usage_bit_mask_t) +
+     282                 :            :                      libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo));
+     283                 :            : 
+     284                 :            :     /* Sub Case 2: Set multi_key_conn_req to false*/
+     285                 :          1 :     spdm_context->connection_info.multi_key_conn_req = false;
+     286                 :          1 :     libspdm_reset_message_encap_d(spdm_context, session_info);
+     287                 :            : 
+     288                 :          1 :     response_size = sizeof(response);
+     289                 :          1 :     status = libspdm_get_encap_response_digest(spdm_context,
+     290                 :            :                                                m_spdm_get_digests_request2_size,
+     291                 :            :                                                &m_spdm_get_digests_request2,
+     292                 :            :                                                &response_size, response);
+     293                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     294                 :          1 :     assert_int_equal(
+     295                 :            :         response_size,
+     296                 :            :         sizeof(spdm_digest_response_t) +
+     297                 :            :         libspdm_get_hash_size(spdm_context->connection_info
+     298                 :            :                               .algorithm.base_hash_algo));
+     299                 :          1 :     spdm_response = (void *)response;
+     300                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     301                 :            :                      SPDM_DIGESTS);
+     302                 :          1 :     assert_int_equal(session_info->session_transcript.message_encap_d.buffer_size, 0);
+     303                 :          1 : }
+     304                 :            : 
+     305                 :            : /**
+     306                 :            :  * Test 6: receives a valid GET_DIGESTS request message from Requester ,
+     307                 :            :  * Check KeyPairID CertificateInfo and KeyUsageMask
+     308                 :            :  * Expected Behavior: produces a valid DIGESTS response message
+     309                 :            :  **/
+     310                 :          1 : void test_spdm_requester_encap_get_digests_case6(void **state)
+     311                 :            : {
+     312                 :            :     libspdm_return_t status;
+     313                 :            :     libspdm_test_context_t *spdm_test_context;
+     314                 :            :     libspdm_context_t *spdm_context;
+     315                 :            :     size_t response_size;
+     316                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     317                 :            :     spdm_digest_response_t *spdm_response;
+     318                 :            :     libspdm_session_info_t *session_info;
+     319                 :            :     uint32_t session_id;
+     320                 :            :     uint8_t *digest;
+     321                 :            :     spdm_key_pair_id_t *key_pair_id;
+     322                 :            :     spdm_certificate_info_t *cert_info;
+     323                 :            :     spdm_key_usage_bit_mask_t *key_usage_bit_mask;
+     324                 :            :     uint32_t hash_size;
+     325                 :            :     uint8_t slot_count;
+     326                 :            :     size_t additional_size;
+     327                 :            : 
+     328                 :          1 :     spdm_test_context = *state;
+     329                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     330                 :          1 :     spdm_test_context->case_id = 0x6;
+     331                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13
+     332                 :            :                                             << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     333                 :          1 :     spdm_context->connection_info.connection_state =
+     334                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     335                 :          1 :     spdm_context->local_context.capability.flags |=
+     336                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     337                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     338                 :            :         m_libspdm_use_hash_algo;
+     339                 :            : 
+     340                 :          1 :     slot_count = SPDM_MAX_SLOT_COUNT;
+     341                 :          1 :     additional_size = sizeof(spdm_key_pair_id_t) + sizeof(spdm_certificate_info_t) +
+     342                 :            :                       sizeof(spdm_key_usage_bit_mask_t);
+     343                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     344                 :            : 
+     345         [ +  + ]:          9 :     for (uint8_t index = 0; index < SPDM_MAX_SLOT_COUNT; index++) {
+     346                 :          8 :         spdm_context->local_context.local_cert_chain_provision[index] =
+     347                 :          8 :             &m_local_certificate_chain[hash_size * index];
+     348                 :            :         spdm_context->local_context
+     349                 :          8 :         .local_cert_chain_provision_size[index] = hash_size;
+     350                 :            :     }
+     351                 :            : 
+     352                 :          1 :     libspdm_set_mem(m_local_certificate_chain, sizeof(m_local_certificate_chain),
+     353                 :            :                     (uint8_t)(0xFF));
+     354                 :            : 
+     355                 :          1 :     session_id = 0xFFFFFFFF;
+     356                 :          1 :     spdm_context->latest_session_id = session_id;
+     357                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+     358                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+     359                 :          1 :     session_info = &spdm_context->session_info[0];
+     360                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+     361                 :          1 :     libspdm_secured_message_set_session_state(
+     362                 :            :         session_info->secured_message_context,
+     363                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+     364                 :            : 
+     365                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     366                 :            :     spdm_context->transcript.message_m.buffer_size =
+     367                 :            :         spdm_context->transcript.message_m.max_buffer_size;
+     368                 :            : #endif
+     369                 :          1 :     spdm_context->connection_info.multi_key_conn_req = true;
+     370                 :          1 :     libspdm_reset_message_encap_d(spdm_context, session_info);
+     371                 :            : 
+     372                 :          1 :     response_size = sizeof(response);
+     373                 :          1 :     status = libspdm_get_encap_response_digest(spdm_context,
+     374                 :            :                                                m_spdm_get_digests_request2_size,
+     375                 :            :                                                &m_spdm_get_digests_request2,
+     376                 :            :                                                &response_size, response);
+     377                 :            : 
+     378                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     379                 :          1 :     assert_int_equal(response_size,
+     380                 :            :                      sizeof(spdm_digest_response_t) + (hash_size + additional_size) * slot_count);
+     381                 :            : 
+     382                 :          1 :     spdm_response = (void *)response;
+     383                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     384                 :            :                      SPDM_DIGESTS);
+     385                 :          1 :     assert_int_equal(session_info->session_transcript.message_encap_d.buffer_size,
+     386                 :            :                      sizeof(spdm_digest_response_t) + (hash_size + additional_size) * slot_count);
+     387                 :            : 
+     388                 :          1 :     digest = (void *)(spdm_response + 1);
+     389                 :          1 :     libspdm_zero_mem (digest, hash_size * slot_count);
+     390                 :          1 :     key_pair_id = (spdm_key_pair_id_t *)((uint8_t *)digest + (hash_size * slot_count));
+     391                 :          1 :     cert_info = (spdm_certificate_info_t *)((uint8_t *)key_pair_id +
+     392                 :          1 :                                             sizeof(spdm_key_pair_id_t) * slot_count);
+     393                 :          1 :     key_usage_bit_mask = (spdm_key_usage_bit_mask_t *)((uint8_t *)cert_info +
+     394                 :          1 :                                                        sizeof(spdm_certificate_info_t) *
+     395                 :            :                                                        slot_count);
+     396         [ +  + ]:          9 :     for (uint8_t index = 0; index < SPDM_MAX_SLOT_COUNT; index++) {
+     397                 :          8 :         assert_memory_equal((void *)&key_pair_id[index],
+     398                 :            :                             (void *)&spdm_context->local_context.local_key_pair_id[index],
+     399                 :            :                             sizeof(spdm_key_pair_id_t));
+     400                 :          8 :         assert_memory_equal((void *)&cert_info[index],
+     401                 :            :                             (void *)&spdm_context->local_context.local_cert_info[index],
+     402                 :            :                             sizeof(spdm_certificate_info_t));
+     403                 :          8 :         assert_memory_equal((void *)&key_usage_bit_mask[index],
+     404                 :            :                             (void *)&spdm_context->local_context.local_key_usage_bit_mask[index],
+     405                 :            :                             sizeof(spdm_key_usage_bit_mask_t));
+     406                 :            :     }
+     407                 :          1 : }
+     408                 :            : 
+     409                 :            : libspdm_test_context_t m_spdm_requester_digests_test_context = {
+     410                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+     411                 :            :     false,
+     412                 :            : };
+     413                 :            : 
+     414                 :          1 : int libspdm_requester_encap_digests_test_main(void)
+     415                 :            : {
+     416                 :          1 :     const struct CMUnitTest spdm_requester_digests_tests[] = {
+     417                 :            :         /* Success Case*/
+     418                 :            :         cmocka_unit_test(test_spdm_requester_encap_get_digests_case1),
+     419                 :            :         /* Can be populated with new test.*/
+     420                 :            :         cmocka_unit_test(test_spdm_requester_encap_get_digests_case2),
+     421                 :            :         /* Internal cache full (request message)*/
+     422                 :            :         cmocka_unit_test(test_spdm_requester_encap_get_digests_case3),
+     423                 :            :         /* Internal cache full (response message)*/
+     424                 :            :         cmocka_unit_test(test_spdm_requester_encap_get_digests_case4),
+     425                 :            :         /* Set multi_key_conn_req to check if it responds correctly */
+     426                 :            :         cmocka_unit_test(test_spdm_requester_encap_get_digests_case5),
+     427                 :            :         /* Check KeyPairID CertificateInfo and KeyUsageMask*/
+     428                 :            :         cmocka_unit_test(test_spdm_requester_encap_get_digests_case6),
+     429                 :            :     };
+     430                 :            : 
+     431                 :          1 :     libspdm_setup_test_context(&m_spdm_requester_digests_test_context);
+     432                 :            : 
+     433                 :          1 :     return cmocka_run_group_tests(spdm_requester_digests_tests,
+     434                 :            :                                   libspdm_unit_test_group_setup,
+     435                 :            :                                   libspdm_unit_test_group_teardown);
+     436                 :            : }
+     437                 :            : 
+     438                 :            : #endif /* (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (..) */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/encap_key_update.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_requester/encap_key_update.c.func-sort-c.html new file mode 100644 index 00000000000..0559e2944ba --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/encap_key_update.c.func-sort-c.html @@ -0,0 +1,153 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/encap_key_update.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - encap_key_update.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:344344100.0 %
Date:2024-09-22 08:21:07Functions:1818100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_encap_key_update_test_main1
test_libspdm_requester_encap_key_update_case11
test_libspdm_requester_encap_key_update_case101
test_libspdm_requester_encap_key_update_case111
test_libspdm_requester_encap_key_update_case121
test_libspdm_requester_encap_key_update_case131
test_libspdm_requester_encap_key_update_case141
test_libspdm_requester_encap_key_update_case21
test_libspdm_requester_encap_key_update_case31
test_libspdm_requester_encap_key_update_case41
test_libspdm_requester_encap_key_update_case51
test_libspdm_requester_encap_key_update_case61
test_libspdm_requester_encap_key_update_case71
test_libspdm_requester_encap_key_update_case81
test_libspdm_requester_encap_key_update_case91
libspdm_compute_secret_update7
libspdm_set_standard_key_update_test_secrets13
spdm_set_standard_key_update_test_state14
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/encap_key_update.c.func.html b/coverage_log/unit_test/test_spdm_requester/encap_key_update.c.func.html new file mode 100644 index 00000000000..8f8456b44a8 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/encap_key_update.c.func.html @@ -0,0 +1,153 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/encap_key_update.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - encap_key_update.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:344344100.0 %
Date:2024-09-22 08:21:07Functions:1818100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_compute_secret_update7
libspdm_requester_encap_key_update_test_main1
libspdm_set_standard_key_update_test_secrets13
spdm_set_standard_key_update_test_state14
test_libspdm_requester_encap_key_update_case11
test_libspdm_requester_encap_key_update_case101
test_libspdm_requester_encap_key_update_case111
test_libspdm_requester_encap_key_update_case121
test_libspdm_requester_encap_key_update_case131
test_libspdm_requester_encap_key_update_case141
test_libspdm_requester_encap_key_update_case21
test_libspdm_requester_encap_key_update_case31
test_libspdm_requester_encap_key_update_case41
test_libspdm_requester_encap_key_update_case51
test_libspdm_requester_encap_key_update_case61
test_libspdm_requester_encap_key_update_case71
test_libspdm_requester_encap_key_update_case81
test_libspdm_requester_encap_key_update_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/encap_key_update.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/encap_key_update.c.gcov.html new file mode 100644 index 00000000000..345ae72111a --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/encap_key_update.c.gcov.html @@ -0,0 +1,1213 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/encap_key_update.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - encap_key_update.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:344344100.0 %
Date:2024-09-22 08:21:07Functions:1818100.0 %
Branches:00-
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 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                 :            : #include "spdm_unit_test.h"
+       7                 :            : #include "internal/libspdm_requester_lib.h"
+       8                 :            : #include "internal/libspdm_secured_message_lib.h"
+       9                 :            : 
+      10                 :            : #if LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP
+      11                 :            : 
+      12                 :            : spdm_key_update_request_t m_spdm_key_update_request1 = {
+      13                 :            :     {SPDM_MESSAGE_VERSION_11, SPDM_KEY_UPDATE,
+      14                 :            :      SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY, 0x3}
+      15                 :            : };
+      16                 :            : size_t m_spdm_key_update_request1_size = sizeof(m_spdm_key_update_request1);
+      17                 :            : 
+      18                 :            : spdm_key_update_request_t m_spdm_key_update_request2 = {
+      19                 :            :     {SPDM_MESSAGE_VERSION_11, SPDM_KEY_UPDATE,
+      20                 :            :      SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY, 0x3}
+      21                 :            : };
+      22                 :            : size_t m_spdm_key_update_request2_size = LIBSPDM_MAX_SPDM_MSG_SIZE;
+      23                 :            : 
+      24                 :            : spdm_key_update_request_t m_spdm_key_update_request3 = {
+      25                 :            :     {SPDM_MESSAGE_VERSION_11, SPDM_KEY_UPDATE,
+      26                 :            :      SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_ALL_KEYS, 0x71}
+      27                 :            : };
+      28                 :            : size_t m_spdm_key_update_request3_size = sizeof(m_spdm_key_update_request3);
+      29                 :            : 
+      30                 :            : spdm_key_update_request_t m_spdm_key_update_request4 = {
+      31                 :            :     {SPDM_MESSAGE_VERSION_11, SPDM_KEY_UPDATE,
+      32                 :            :      SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_ALL_KEYS, 0x71}
+      33                 :            : };
+      34                 :            : size_t m_spdm_key_update_request4_size = LIBSPDM_MAX_SPDM_MSG_SIZE;
+      35                 :            : 
+      36                 :            : spdm_key_update_request_t m_spdm_key_update_request5 = {
+      37                 :            :     {SPDM_MESSAGE_VERSION_11, SPDM_KEY_UPDATE,
+      38                 :            :      SPDM_KEY_UPDATE_OPERATIONS_TABLE_VERIFY_NEW_KEY, 0x4A}
+      39                 :            : };
+      40                 :            : size_t m_spdm_key_update_request5_size = sizeof(m_spdm_key_update_request5);
+      41                 :            : 
+      42                 :            : spdm_key_update_request_t m_spdm_key_update_request6 = {
+      43                 :            :     {SPDM_MESSAGE_VERSION_11, SPDM_KEY_UPDATE,
+      44                 :            :      SPDM_KEY_UPDATE_OPERATIONS_TABLE_VERIFY_NEW_KEY, 0x4A}
+      45                 :            : };
+      46                 :            : size_t m_spdm_key_update_request6_size = LIBSPDM_MAX_SPDM_MSG_SIZE;
+      47                 :            : 
+      48                 :            : spdm_key_update_request_t m_spdm_key_update_request7 = {
+      49                 :            :     {SPDM_MESSAGE_VERSION_11, SPDM_KEY_UPDATE,
+      50                 :            :      SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY, 0x92}
+      51                 :            : };
+      52                 :            : size_t m_spdm_key_update_request7_size = sizeof(m_spdm_key_update_request7);
+      53                 :            : 
+      54                 :            : spdm_key_update_request_t m_spdm_key_update_request8 = {
+      55                 :            :     {SPDM_MESSAGE_VERSION_11, SPDM_KEY_UPDATE,
+      56                 :            :      SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_ALL_KEYS, 0x13}
+      57                 :            : };
+      58                 :            : size_t m_spdm_key_update_request8_size = sizeof(m_spdm_key_update_request8);
+      59                 :            : 
+      60                 :            : spdm_key_update_request_t m_spdm_key_update_request9 = {
+      61                 :            :     {SPDM_MESSAGE_VERSION_11, SPDM_KEY_UPDATE,
+      62                 :            :      SPDM_KEY_UPDATE_OPERATIONS_TABLE_VERIFY_NEW_KEY, 0x22}
+      63                 :            : };
+      64                 :            : size_t m_spdm_key_update_request9_size = sizeof(m_spdm_key_update_request9);
+      65                 :            : 
+      66                 :            : spdm_key_update_request_t m_spdm_key_update_request10 = {
+      67                 :            :     {SPDM_MESSAGE_VERSION_11, SPDM_KEY_UPDATE, 0xFF, 0x12}
+      68                 :            : };
+      69                 :            : size_t m_spdm_key_update_request10_size = sizeof(m_spdm_key_update_request10);
+      70                 :            : 
+      71                 :         14 : static void spdm_set_standard_key_update_test_state(
+      72                 :            :     libspdm_context_t *spdm_context,  uint32_t *session_id)
+      73                 :            : {
+      74                 :            :     libspdm_session_info_t *session_info;
+      75                 :            : 
+      76                 :         14 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+      77                 :         14 :     spdm_context->connection_info.connection_state =
+      78                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+      79                 :         14 :     spdm_context->connection_info.capability.flags |=
+      80                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_UPD_CAP;
+      81                 :         14 :     spdm_context->connection_info.capability.flags |=
+      82                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+      83                 :         14 :     spdm_context->connection_info.capability.flags |=
+      84                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+      85                 :         14 :     spdm_context->local_context.capability.flags |=
+      86                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP;
+      87                 :         14 :     spdm_context->local_context.capability.flags |=
+      88                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+      89                 :         14 :     spdm_context->local_context.capability.flags |=
+      90                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+      91                 :            : 
+      92                 :         14 :     spdm_context->transcript.message_a.buffer_size = 0;
+      93                 :         14 :     spdm_context->connection_info.algorithm.base_hash_algo =
+      94                 :            :         m_libspdm_use_hash_algo;
+      95                 :         14 :     spdm_context->connection_info.algorithm.base_asym_algo =
+      96                 :            :         m_libspdm_use_asym_algo;
+      97                 :         14 :     spdm_context->connection_info.algorithm.dhe_named_group =
+      98                 :            :         m_libspdm_use_dhe_algo;
+      99                 :         14 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     100                 :            :         m_libspdm_use_aead_algo;
+     101                 :            : 
+     102                 :         14 :     *session_id = 0xFFFFFFFF;
+     103                 :         14 :     spdm_context->latest_session_id = *session_id;
+     104                 :         14 :     spdm_context->last_spdm_request_session_id_valid = true;
+     105                 :         14 :     spdm_context->last_spdm_request_session_id = *session_id;
+     106                 :         14 :     session_info = &spdm_context->session_info[0];
+     107                 :         14 :     libspdm_session_info_init(spdm_context, session_info, *session_id, true);
+     108                 :         14 :     libspdm_secured_message_set_session_state(
+     109                 :            :         session_info->secured_message_context,
+     110                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+     111                 :         14 : }
+     112                 :            : 
+     113                 :         13 : static void libspdm_set_standard_key_update_test_secrets(
+     114                 :            :     libspdm_secured_message_context_t *secured_message_context,
+     115                 :            :     uint8_t *m_rsp_secret_buffer,  uint8_t rsp_secret_fill,
+     116                 :            :     uint8_t *m_req_secret_buffer,  uint8_t req_secret_fill)
+     117                 :            : {
+     118                 :         13 :     libspdm_set_mem(m_rsp_secret_buffer, secured_message_context->hash_size, rsp_secret_fill);
+     119                 :         13 :     libspdm_set_mem(m_req_secret_buffer, secured_message_context->hash_size, req_secret_fill);
+     120                 :            : 
+     121                 :         13 :     libspdm_copy_mem(secured_message_context->application_secret.response_data_secret,
+     122                 :            :                      sizeof(secured_message_context->application_secret.response_data_secret),
+     123                 :            :                      m_rsp_secret_buffer, secured_message_context->aead_key_size);
+     124                 :         13 :     libspdm_copy_mem(secured_message_context->application_secret.request_data_secret,
+     125                 :            :                      sizeof(secured_message_context->application_secret.request_data_secret),
+     126                 :            :                      m_req_secret_buffer, secured_message_context->aead_key_size);
+     127                 :            : 
+     128                 :         13 :     libspdm_set_mem(secured_message_context->application_secret
+     129                 :         13 :                     .response_data_encryption_key,
+     130                 :            :                     secured_message_context->aead_key_size, rsp_secret_fill);
+     131                 :         13 :     libspdm_set_mem(secured_message_context->application_secret
+     132                 :         13 :                     .response_data_salt,
+     133                 :            :                     secured_message_context->aead_iv_size, rsp_secret_fill);
+     134                 :            : 
+     135                 :         13 :     libspdm_set_mem(secured_message_context->application_secret
+     136                 :         13 :                     .request_data_encryption_key,
+     137                 :            :                     secured_message_context->aead_key_size, req_secret_fill);
+     138                 :         13 :     libspdm_set_mem(secured_message_context->application_secret
+     139                 :         13 :                     .request_data_salt,
+     140                 :            :                     secured_message_context->aead_iv_size, req_secret_fill);
+     141                 :            : 
+     142                 :         13 :     secured_message_context->application_secret.response_data_sequence_number = 0;
+     143                 :         13 :     secured_message_context->application_secret.request_data_sequence_number = 0;
+     144                 :         13 : }
+     145                 :            : 
+     146                 :          7 : static void libspdm_compute_secret_update(spdm_version_number_t spdm_version,
+     147                 :            :                                           size_t hash_size,
+     148                 :            :                                           const uint8_t *in_secret,  uint8_t *out_secret,
+     149                 :            :                                           size_t out_secret_size)
+     150                 :            : {
+     151                 :            :     uint8_t bin_str9[128];
+     152                 :            :     size_t bin_str9_size;
+     153                 :            : 
+     154                 :          7 :     bin_str9_size = sizeof(bin_str9);
+     155                 :          7 :     libspdm_bin_concat(spdm_version,
+     156                 :            :                        SPDM_BIN_STR_9_LABEL, sizeof(SPDM_BIN_STR_9_LABEL) - 1,
+     157                 :          7 :                        NULL, (uint16_t)hash_size, hash_size, bin_str9,
+     158                 :            :                        &bin_str9_size);
+     159                 :            : 
+     160                 :          7 :     libspdm_hkdf_expand(m_libspdm_use_hash_algo, in_secret, hash_size, bin_str9,
+     161                 :            :                         bin_str9_size, out_secret, out_secret_size);
+     162                 :          7 : }
+     163                 :            : 
+     164                 :            : /**
+     165                 :            :  * Test 1: receiving a correct KEY_UPDATE message from the requester with
+     166                 :            :  * the UpdateKey operation.
+     167                 :            :  * Expected behavior: the encap requester accepts the request, produces a valid
+     168                 :            :  * KEY_UPDATE_ACK response message, and the request data key is updated.
+     169                 :            :  **/
+     170                 :          1 : void test_libspdm_requester_encap_key_update_case1(void **state)
+     171                 :            : {
+     172                 :            :     libspdm_return_t status;
+     173                 :            :     libspdm_test_context_t *spdm_test_context;
+     174                 :            :     libspdm_context_t *spdm_context;
+     175                 :            :     uint32_t session_id;
+     176                 :            :     libspdm_session_info_t *session_info;
+     177                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     178                 :            : 
+     179                 :            :     size_t response_size;
+     180                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     181                 :            :     spdm_key_update_response_t *spdm_response;
+     182                 :            : 
+     183                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     184                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     185                 :            : 
+     186                 :          1 :     spdm_test_context = *state;
+     187                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     188                 :          1 :     spdm_test_context->case_id = 0x01;
+     189                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     190                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     191                 :            : 
+     192                 :          1 :     spdm_set_standard_key_update_test_state(
+     193                 :            :         spdm_context, &session_id);
+     194                 :            : 
+     195                 :          1 :     session_info = &spdm_context->session_info[0];
+     196                 :          1 :     secured_message_context = session_info->secured_message_context;
+     197                 :            : 
+     198                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+     199                 :          1 :         session_info->secured_message_context,
+     200                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+     201                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+     202                 :            : 
+     203                 :            :     /*request side *not* updated*/
+     204                 :            : 
+     205                 :            :     /*response side updated */
+     206                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+     207                 :            :                                   secured_message_context->hash_size,
+     208                 :            :                                   m_rsp_secret_buffer, m_rsp_secret_buffer,
+     209                 :            :                                   secured_message_context->hash_size);
+     210                 :            : 
+     211                 :          1 :     response_size = sizeof(response);
+     212                 :          1 :     status = libspdm_get_encap_response_key_update(spdm_context,
+     213                 :            :                                                    m_spdm_key_update_request1_size,
+     214                 :            :                                                    &m_spdm_key_update_request1,
+     215                 :            :                                                    &response_size, response);
+     216                 :            : 
+     217                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     218                 :          1 :     assert_int_equal(response_size, sizeof(spdm_key_update_response_t));
+     219                 :          1 :     spdm_response = (void *)response;
+     220                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     221                 :            :                      SPDM_KEY_UPDATE_ACK);
+     222                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     223                 :            :                      SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY);
+     224                 :          1 :     assert_int_equal(spdm_response->header.param2,
+     225                 :            :                      m_spdm_key_update_request1.header.param2);
+     226                 :          1 :     assert_memory_equal(secured_message_context
+     227                 :            :                         ->application_secret.request_data_secret,
+     228                 :            :                         m_req_secret_buffer, secured_message_context->hash_size);
+     229                 :          1 :     assert_memory_equal(secured_message_context
+     230                 :            :                         ->application_secret.response_data_secret,
+     231                 :            :                         m_rsp_secret_buffer, secured_message_context->hash_size);
+     232                 :          1 : }
+     233                 :            : 
+     234                 :            : /**
+     235                 :            :  * Test 2: receiving a KEY_UPDATE message larger than specified, with the
+     236                 :            :  * UpdateKey operation.
+     237                 :            :  * Expected behavior: the encap requester refuses the KEY_UPDATE message and
+     238                 :            :  * produces an ERROR message indicating the InvalidRequest. No keys
+     239                 :            :  * are updated.
+     240                 :            :  **/
+     241                 :          1 : void test_libspdm_requester_encap_key_update_case2(void **state)
+     242                 :            : {
+     243                 :            :     libspdm_return_t status;
+     244                 :            :     libspdm_test_context_t *spdm_test_context;
+     245                 :            :     libspdm_context_t *spdm_context;
+     246                 :            :     uint32_t session_id;
+     247                 :            :     libspdm_session_info_t *session_info;
+     248                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     249                 :            : 
+     250                 :            :     size_t response_size;
+     251                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     252                 :            :     spdm_key_update_response_t *spdm_response;
+     253                 :            : 
+     254                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     255                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     256                 :            : 
+     257                 :          1 :     spdm_test_context = *state;
+     258                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     259                 :          1 :     spdm_test_context->case_id = 0x02;
+     260                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     261                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     262                 :            : 
+     263                 :          1 :     spdm_set_standard_key_update_test_state(
+     264                 :            :         spdm_context, &session_id);
+     265                 :            : 
+     266                 :          1 :     session_info = &spdm_context->session_info[0];
+     267                 :          1 :     secured_message_context = session_info->secured_message_context;
+     268                 :            : 
+     269                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+     270                 :          1 :         session_info->secured_message_context,
+     271                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+     272                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+     273                 :            : 
+     274                 :            :     /*no keys are updated*/
+     275                 :            : 
+     276                 :          1 :     response_size = sizeof(response);
+     277                 :          1 :     status = libspdm_get_encap_response_key_update(spdm_context,
+     278                 :            :                                                    m_spdm_key_update_request2_size,
+     279                 :            :                                                    &m_spdm_key_update_request2,
+     280                 :            :                                                    &response_size, response);
+     281                 :            : 
+     282                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     283                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     284                 :          1 :     spdm_response = (void *)response;
+     285                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     286                 :            :                      SPDM_ERROR);
+     287                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     288                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+     289                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     290                 :          1 :     assert_memory_equal(secured_message_context
+     291                 :            :                         ->application_secret.request_data_secret,
+     292                 :            :                         m_req_secret_buffer, secured_message_context->hash_size);
+     293                 :          1 :     assert_memory_equal(secured_message_context
+     294                 :            :                         ->application_secret.response_data_secret,
+     295                 :            :                         m_rsp_secret_buffer, secured_message_context->hash_size);
+     296                 :          1 : }
+     297                 :            : 
+     298                 :          1 : void test_libspdm_requester_encap_key_update_case3(void **state)
+     299                 :            : {
+     300                 :            :     libspdm_return_t status;
+     301                 :            :     libspdm_test_context_t *spdm_test_context;
+     302                 :            :     libspdm_context_t *spdm_context;
+     303                 :            :     uint32_t session_id;
+     304                 :            :     libspdm_session_info_t *session_info;
+     305                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     306                 :            : 
+     307                 :            :     size_t response_size;
+     308                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     309                 :            :     spdm_key_update_response_t *spdm_response;
+     310                 :            : 
+     311                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     312                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     313                 :            : 
+     314                 :          1 :     spdm_test_context = *state;
+     315                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     316                 :          1 :     spdm_test_context->case_id = 0x03;
+     317                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     318                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     319                 :            : 
+     320                 :          1 :     spdm_set_standard_key_update_test_state(
+     321                 :            :         spdm_context, &session_id);
+     322                 :            : 
+     323                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     324                 :            :     /*"filling" buffers*/
+     325                 :            :     spdm_context->transcript.message_m.buffer_size =
+     326                 :            :         spdm_context->transcript.message_m.max_buffer_size;
+     327                 :            :     spdm_context->transcript.message_b.buffer_size =
+     328                 :            :         spdm_context->transcript.message_b.max_buffer_size;
+     329                 :            :     spdm_context->transcript.message_c.buffer_size =
+     330                 :            :         spdm_context->transcript.message_c.max_buffer_size;
+     331                 :            :     spdm_context->transcript.message_mut_b.buffer_size =
+     332                 :            :         spdm_context->transcript.message_mut_b.max_buffer_size;
+     333                 :            :     spdm_context->transcript.message_mut_c.buffer_size =
+     334                 :            :         spdm_context->transcript.message_mut_c.max_buffer_size;
+     335                 :            : #endif
+     336                 :            : 
+     337                 :          1 :     session_info = &spdm_context->session_info[0];
+     338                 :          1 :     secured_message_context = session_info->secured_message_context;
+     339                 :            : 
+     340                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+     341                 :          1 :         session_info->secured_message_context,
+     342                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+     343                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+     344                 :            : 
+     345                 :            :     /*request side *not* updated*/
+     346                 :            : 
+     347                 :            :     /*response side updated */
+     348                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+     349                 :            :                                   secured_message_context->hash_size,
+     350                 :            :                                   m_rsp_secret_buffer, m_rsp_secret_buffer,
+     351                 :            :                                   secured_message_context->hash_size);
+     352                 :            : 
+     353                 :          1 :     response_size = sizeof(response);
+     354                 :          1 :     status = libspdm_get_encap_response_key_update(spdm_context,
+     355                 :            :                                                    m_spdm_key_update_request1_size,
+     356                 :            :                                                    &m_spdm_key_update_request1,
+     357                 :            :                                                    &response_size, response);
+     358                 :            : 
+     359                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     360                 :          1 :     assert_int_equal(response_size, sizeof(spdm_key_update_response_t));
+     361                 :          1 :     spdm_response = (void *)response;
+     362                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     363                 :            :                      SPDM_KEY_UPDATE_ACK);
+     364                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     365                 :            :                      SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY);
+     366                 :          1 :     assert_int_equal(spdm_response->header.param2,
+     367                 :            :                      m_spdm_key_update_request1.header.param2);
+     368                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     369                 :            :     assert_int_equal(session_info->session_transcript.message_m.buffer_size, 0);
+     370                 :            :     assert_int_equal(spdm_context->transcript.message_b.buffer_size, 0);
+     371                 :            :     assert_int_equal(spdm_context->transcript.message_c.buffer_size, 0);
+     372                 :            :     assert_int_equal(spdm_context->transcript.message_mut_b.buffer_size, 0);
+     373                 :            :     assert_int_equal(spdm_context->transcript.message_mut_c.buffer_size, 0);
+     374                 :            : #endif
+     375                 :          1 :     assert_memory_equal(secured_message_context
+     376                 :            :                         ->application_secret.request_data_secret,
+     377                 :            :                         m_req_secret_buffer, secured_message_context->hash_size);
+     378                 :          1 :     assert_memory_equal(secured_message_context
+     379                 :            :                         ->application_secret.response_data_secret,
+     380                 :            :                         m_rsp_secret_buffer, secured_message_context->hash_size);
+     381                 :          1 : }
+     382                 :            : 
+     383                 :            : /**
+     384                 :            :  * Test 4: receiving a correct KEY_UPDATE message from the requester, but the
+     385                 :            :  * responder has no capabilities for key update.
+     386                 :            :  * Expected behavior: the encap requester refuses the KEY_UPDATE message and
+     387                 :            :  * produces an ERROR message indicating the UnsupportedRequest. No keys are
+     388                 :            :  * updated.
+     389                 :            :  **/
+     390                 :          1 : void test_libspdm_requester_encap_key_update_case4(void **state)
+     391                 :            : {
+     392                 :            :     libspdm_return_t status;
+     393                 :            :     libspdm_test_context_t *spdm_test_context;
+     394                 :            :     libspdm_context_t *spdm_context;
+     395                 :            :     uint32_t session_id;
+     396                 :            :     libspdm_session_info_t *session_info;
+     397                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     398                 :            : 
+     399                 :            :     size_t response_size;
+     400                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     401                 :            :     spdm_key_update_response_t *spdm_response;
+     402                 :            : 
+     403                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     404                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     405                 :            : 
+     406                 :          1 :     spdm_test_context = *state;
+     407                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     408                 :          1 :     spdm_test_context->case_id = 0x04;
+     409                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     410                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     411                 :            : 
+     412                 :          1 :     spdm_set_standard_key_update_test_state(
+     413                 :            :         spdm_context, &session_id);
+     414                 :            : 
+     415                 :            :     /*no capabilities*/
+     416                 :          1 :     spdm_context->connection_info.capability.flags &=
+     417                 :            :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_UPD_CAP;
+     418                 :          1 :     spdm_context->local_context.capability.flags &=
+     419                 :            :         ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP;
+     420                 :            : 
+     421                 :          1 :     session_info = &spdm_context->session_info[0];
+     422                 :          1 :     secured_message_context = session_info->secured_message_context;
+     423                 :            : 
+     424                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+     425                 :          1 :         session_info->secured_message_context,
+     426                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+     427                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+     428                 :            : 
+     429                 :            :     /*no keys are updated*/
+     430                 :            : 
+     431                 :          1 :     response_size = sizeof(response);
+     432                 :          1 :     status = libspdm_get_encap_response_key_update(spdm_context,
+     433                 :            :                                                    m_spdm_key_update_request1_size,
+     434                 :            :                                                    &m_spdm_key_update_request1,
+     435                 :            :                                                    &response_size, response);
+     436                 :            : 
+     437                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     438                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     439                 :          1 :     spdm_response = (void *)response;
+     440                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     441                 :            :                      SPDM_ERROR);
+     442                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     443                 :            :                      SPDM_ERROR_CODE_UNSUPPORTED_REQUEST);
+     444                 :          1 :     assert_int_equal(spdm_response->header.param2, SPDM_KEY_UPDATE);
+     445                 :          1 :     assert_memory_equal(secured_message_context
+     446                 :            :                         ->application_secret.request_data_secret,
+     447                 :            :                         m_req_secret_buffer, secured_message_context->hash_size);
+     448                 :          1 :     assert_memory_equal(secured_message_context
+     449                 :            :                         ->application_secret.response_data_secret,
+     450                 :            :                         m_rsp_secret_buffer, secured_message_context->hash_size);
+     451                 :          1 : }
+     452                 :            : 
+     453                 :            : /**
+     454                 :            :  * Test 5: receiving a correct KEY_UPDATE message from the requester, but the
+     455                 :            :  * responder is not correctly setup by not initializing a session during
+     456                 :            :  * KEY_EXCHANGE.
+     457                 :            :  * Expected behavior: the encap requester refuses the KEY_UPDATE message and produces
+     458                 :            :  * an ERROR message indicating the UnsupportedRequest. No keys are updated.
+     459                 :            :  **/
+     460                 :          1 : void test_libspdm_requester_encap_key_update_case5(void **state)
+     461                 :            : {
+     462                 :            :     libspdm_return_t status;
+     463                 :            :     libspdm_test_context_t *spdm_test_context;
+     464                 :            :     libspdm_context_t *spdm_context;
+     465                 :            :     uint32_t session_id;
+     466                 :            :     libspdm_session_info_t *session_info;
+     467                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     468                 :            : 
+     469                 :            :     size_t response_size;
+     470                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     471                 :            :     spdm_key_update_response_t *spdm_response;
+     472                 :            : 
+     473                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     474                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     475                 :            : 
+     476                 :          1 :     spdm_test_context = *state;
+     477                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     478                 :          1 :     spdm_test_context->case_id = 0x04;
+     479                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     480                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     481                 :            : 
+     482                 :          1 :     spdm_set_standard_key_update_test_state(
+     483                 :            :         spdm_context, &session_id);
+     484                 :            : 
+     485                 :          1 :     session_info = &spdm_context->session_info[0];
+     486                 :          1 :     secured_message_context = session_info->secured_message_context;
+     487                 :            : 
+     488                 :            :     /*uninitialized session*/
+     489                 :          1 :     libspdm_secured_message_set_session_state(
+     490                 :            :         session_info->secured_message_context,
+     491                 :            :         LIBSPDM_SESSION_STATE_NOT_STARTED);
+     492                 :            : 
+     493                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+     494                 :          1 :         session_info->secured_message_context,
+     495                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+     496                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+     497                 :            : 
+     498                 :            :     /*no keys are updated*/
+     499                 :            : 
+     500                 :          1 :     response_size = sizeof(response);
+     501                 :          1 :     status = libspdm_get_encap_response_key_update(spdm_context,
+     502                 :            :                                                    m_spdm_key_update_request1_size,
+     503                 :            :                                                    &m_spdm_key_update_request1,
+     504                 :            :                                                    &response_size, response);
+     505                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     506                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     507                 :          1 :     spdm_response = (void *)response;
+     508                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     509                 :            :                      SPDM_ERROR);
+     510                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     511                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+     512                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     513                 :          1 :     assert_memory_equal(secured_message_context
+     514                 :            :                         ->application_secret.request_data_secret,
+     515                 :            :                         m_req_secret_buffer, secured_message_context->hash_size);
+     516                 :          1 :     assert_memory_equal(secured_message_context
+     517                 :            :                         ->application_secret.response_data_secret,
+     518                 :            :                         m_rsp_secret_buffer, secured_message_context->hash_size);
+     519                 :          1 : }
+     520                 :            : 
+     521                 :            : /**
+     522                 :            :  * Test 6: receiving a correct KEY_UPDATE message from the requester with
+     523                 :            :  * the UpdateAllKeys operation.
+     524                 :            :  * Expected behavior: the encap requester refuses the KEY_UPDATE message and produces
+     525                 :            :  * an ERROR message indicating the UnsupportedRequest. No keys are updated.
+     526                 :            :  **/
+     527                 :          1 : void test_libspdm_requester_encap_key_update_case6(void **state)
+     528                 :            : {
+     529                 :            :     libspdm_return_t status;
+     530                 :            :     libspdm_test_context_t *spdm_test_context;
+     531                 :            :     libspdm_context_t *spdm_context;
+     532                 :            :     uint32_t session_id;
+     533                 :            : 
+     534                 :            :     size_t response_size;
+     535                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     536                 :            :     spdm_key_update_response_t *spdm_response;
+     537                 :            : 
+     538                 :            : 
+     539                 :          1 :     spdm_test_context = *state;
+     540                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     541                 :          1 :     spdm_test_context->case_id = 0x06;
+     542                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     543                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     544                 :            : 
+     545                 :          1 :     spdm_set_standard_key_update_test_state(
+     546                 :            :         spdm_context, &session_id);
+     547                 :            : 
+     548                 :          1 :     response_size = sizeof(response);
+     549                 :          1 :     status = libspdm_get_encap_response_key_update(spdm_context,
+     550                 :            :                                                    m_spdm_key_update_request3_size,
+     551                 :            :                                                    &m_spdm_key_update_request3,
+     552                 :            :                                                    &response_size, response);
+     553                 :            : 
+     554                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     555                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     556                 :          1 :     spdm_response = (void *)response;
+     557                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     558                 :            :                      SPDM_ERROR);
+     559                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     560                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+     561                 :          1 :     assert_int_equal(spdm_response->header.param2,
+     562                 :            :                      0);
+     563                 :          1 : }
+     564                 :            : 
+     565                 :            : /**
+     566                 :            :  * Test 7: receiving a KEY_UPDATE message larger than specified, with the
+     567                 :            :  * UpdateAllKeys operation.
+     568                 :            :  * Expected behavior: the encap requester refuses the KEY_UPDATE message and
+     569                 :            :  * produces an ERROR message indicating the InvalidRequest. No keys
+     570                 :            :  * are updated.
+     571                 :            :  **/
+     572                 :          1 : void test_libspdm_requester_encap_key_update_case7(void **state)
+     573                 :            : {
+     574                 :            :     libspdm_return_t status;
+     575                 :            :     libspdm_test_context_t *spdm_test_context;
+     576                 :            :     libspdm_context_t *spdm_context;
+     577                 :            :     uint32_t session_id;
+     578                 :            :     libspdm_session_info_t *session_info;
+     579                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     580                 :            : 
+     581                 :            :     size_t response_size;
+     582                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     583                 :            :     spdm_key_update_response_t *spdm_response;
+     584                 :            : 
+     585                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     586                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     587                 :            : 
+     588                 :          1 :     spdm_test_context = *state;
+     589                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     590                 :          1 :     spdm_test_context->case_id = 0x07;
+     591                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     592                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     593                 :            : 
+     594                 :          1 :     spdm_set_standard_key_update_test_state(
+     595                 :            :         spdm_context, &session_id);
+     596                 :            : 
+     597                 :          1 :     session_info = &spdm_context->session_info[0];
+     598                 :          1 :     secured_message_context = session_info->secured_message_context;
+     599                 :            : 
+     600                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+     601                 :          1 :         session_info->secured_message_context,
+     602                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+     603                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+     604                 :            : 
+     605                 :            :     /*no keys are updated*/
+     606                 :            : 
+     607                 :          1 :     response_size = sizeof(response);
+     608                 :          1 :     status = libspdm_get_encap_response_key_update(spdm_context,
+     609                 :            :                                                    m_spdm_key_update_request4_size,
+     610                 :            :                                                    &m_spdm_key_update_request4,
+     611                 :            :                                                    &response_size, response);
+     612                 :            : 
+     613                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     614                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     615                 :          1 :     spdm_response = (void *)response;
+     616                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     617                 :            :                      SPDM_ERROR);
+     618                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     619                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+     620                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     621                 :          1 :     assert_memory_equal(secured_message_context
+     622                 :            :                         ->application_secret.request_data_secret,
+     623                 :            :                         m_req_secret_buffer, secured_message_context->hash_size);
+     624                 :          1 :     assert_memory_equal(secured_message_context
+     625                 :            :                         ->application_secret.response_data_secret,
+     626                 :            :                         m_rsp_secret_buffer, secured_message_context->hash_size);
+     627                 :          1 : }
+     628                 :            : 
+     629                 :            : /**
+     630                 :            :  * Test 8: receiving a invalid KEY_UPDATE message from the requester with
+     631                 :            :  * the VerifyNewKey operation. The responder is setup as if no valid
+     632                 :            :  * KEY_UPDATE request with either the UpdateKey or UpdateAllKeys has been
+     633                 :            :  * previously received.
+     634                 :            :  * Expected behavior: the encap requester refuses the KEY_UPDATE message and
+     635                 :            :  * produces an ERROR message indicating the InvalidRequest. No keys are
+     636                 :            :  * updated.
+     637                 :            :  **/
+     638                 :          1 : void test_libspdm_requester_encap_key_update_case8(void **state)
+     639                 :            : {
+     640                 :            :     libspdm_return_t status;
+     641                 :            :     libspdm_test_context_t *spdm_test_context;
+     642                 :            :     libspdm_context_t *spdm_context;
+     643                 :            :     uint32_t session_id;
+     644                 :            :     libspdm_session_info_t *session_info;
+     645                 :            : 
+     646                 :            :     size_t response_size;
+     647                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     648                 :            :     spdm_key_update_response_t *spdm_response;
+     649                 :            : 
+     650                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     651                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     652                 :            : 
+     653                 :          1 :     spdm_test_context = *state;
+     654                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     655                 :          1 :     spdm_test_context->case_id = 0x08;
+     656                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     657                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     658                 :            : 
+     659                 :          1 :     spdm_set_standard_key_update_test_state(
+     660                 :            :         spdm_context, &session_id);
+     661                 :            : 
+     662                 :          1 :     session_info = &spdm_context->session_info[0];
+     663                 :            : 
+     664                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+     665                 :          1 :         session_info->secured_message_context,
+     666                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+     667                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+     668                 :            : 
+     669                 :            :     /*no mocked major secret update*/
+     670                 :            : 
+     671                 :            :     /*no keys are updated*/
+     672                 :            : 
+     673                 :          1 :     response_size = sizeof(response);
+     674                 :          1 :     status = libspdm_get_encap_response_key_update(spdm_context,
+     675                 :            :                                                    m_spdm_key_update_request5_size,
+     676                 :            :                                                    &m_spdm_key_update_request5,
+     677                 :            :                                                    &response_size, response);
+     678                 :            : 
+     679                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     680                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     681                 :          1 :     spdm_response = (void *)response;
+     682                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     683                 :            :                      SPDM_ERROR);
+     684                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     685                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+     686                 :          1 :     assert_int_equal(spdm_response->header.param2,
+     687                 :            :                      0);
+     688                 :          1 : }
+     689                 :            : 
+     690                 :            : /**
+     691                 :            :  * Test 9: receiving a KEY_UPDATE message with a reserved operation code.
+     692                 :            :  * Expected behavior: the encap requester refuses the KEY_UPDATE message and
+     693                 :            :  * produces an ERROR message indicating the InvalidRequest. No keys
+     694                 :            :  * are updated.
+     695                 :            :  **/
+     696                 :          1 : void test_libspdm_requester_encap_key_update_case9(void **state)
+     697                 :            : {
+     698                 :            :     libspdm_return_t status;
+     699                 :            :     libspdm_test_context_t *spdm_test_context;
+     700                 :            :     libspdm_context_t *spdm_context;
+     701                 :            :     uint32_t session_id;
+     702                 :            :     libspdm_session_info_t *session_info;
+     703                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     704                 :            : 
+     705                 :            :     size_t response_size;
+     706                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     707                 :            :     spdm_key_update_response_t *spdm_response;
+     708                 :            : 
+     709                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     710                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     711                 :            : 
+     712                 :          1 :     spdm_test_context = *state;
+     713                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     714                 :          1 :     spdm_test_context->case_id = 0x09;
+     715                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     716                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     717                 :            : 
+     718                 :          1 :     spdm_set_standard_key_update_test_state(
+     719                 :            :         spdm_context, &session_id);
+     720                 :            : 
+     721                 :          1 :     session_info = &spdm_context->session_info[0];
+     722                 :          1 :     secured_message_context = session_info->secured_message_context;
+     723                 :            : 
+     724                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+     725                 :          1 :         session_info->secured_message_context,
+     726                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+     727                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+     728                 :            : 
+     729                 :            :     /*no keys are updated*/
+     730                 :            : 
+     731                 :          1 :     response_size = sizeof(response);
+     732                 :          1 :     status = libspdm_get_encap_response_key_update(spdm_context,
+     733                 :            :                                                    m_spdm_key_update_request10_size,
+     734                 :            :                                                    &m_spdm_key_update_request10,
+     735                 :            :                                                    &response_size, response);
+     736                 :            : 
+     737                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     738                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     739                 :          1 :     spdm_response = (void *)response;
+     740                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     741                 :            :                      SPDM_ERROR);
+     742                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     743                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+     744                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     745                 :          1 :     assert_memory_equal(secured_message_context
+     746                 :            :                         ->application_secret.request_data_secret,
+     747                 :            :                         m_req_secret_buffer, secured_message_context->hash_size);
+     748                 :          1 :     assert_memory_equal(secured_message_context
+     749                 :            :                         ->application_secret.response_data_secret,
+     750                 :            :                         m_rsp_secret_buffer, secured_message_context->hash_size);
+     751                 :          1 : }
+     752                 :            : 
+     753                 :            : /* UpdateKey + UpdateKey: failed*/
+     754                 :          1 : void test_libspdm_requester_encap_key_update_case10(void **state)
+     755                 :            : {
+     756                 :            :     libspdm_return_t status;
+     757                 :            :     libspdm_test_context_t *spdm_test_context;
+     758                 :            :     libspdm_context_t *spdm_context;
+     759                 :            :     uint32_t session_id;
+     760                 :            :     libspdm_session_info_t *session_info;
+     761                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     762                 :            : 
+     763                 :            :     size_t response_size;
+     764                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     765                 :            :     spdm_key_update_response_t *spdm_response;
+     766                 :            : 
+     767                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     768                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     769                 :            : 
+     770                 :          1 :     spdm_test_context = *state;
+     771                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     772                 :          1 :     spdm_test_context->case_id = 0x0A;
+     773                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     774                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     775                 :            : 
+     776                 :          1 :     spdm_set_standard_key_update_test_state(
+     777                 :            :         spdm_context, &session_id);
+     778                 :            : 
+     779                 :          1 :     session_info = &spdm_context->session_info[0];
+     780                 :          1 :     secured_message_context = session_info->secured_message_context;
+     781                 :            : 
+     782                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+     783                 :          1 :         session_info->secured_message_context,
+     784                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+     785                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+     786                 :            : 
+     787                 :            :     /*request side *not* updated*/
+     788                 :            : 
+     789                 :            :     /*last request: UpdateKey*/
+     790                 :          1 :     session_info->last_key_update_request = m_spdm_key_update_request1;
+     791                 :            : 
+     792                 :            :     /*response side updated */
+     793                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+     794                 :            :                                   secured_message_context->hash_size,
+     795                 :            :                                   m_rsp_secret_buffer, m_rsp_secret_buffer,
+     796                 :            :                                   secured_message_context->hash_size);
+     797                 :            : 
+     798                 :          1 :     response_size = sizeof(response);
+     799                 :          1 :     status = libspdm_get_encap_response_key_update(spdm_context,
+     800                 :            :                                                    m_spdm_key_update_request1_size,
+     801                 :            :                                                    &m_spdm_key_update_request1,
+     802                 :            :                                                    &response_size, response);
+     803                 :            : 
+     804                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     805                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     806                 :          1 :     spdm_response = (void *)response;
+     807                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     808                 :            :                      SPDM_ERROR);
+     809                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     810                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+     811                 :          1 :     assert_int_equal(spdm_response->header.param2,
+     812                 :            :                      0);
+     813                 :          1 : }
+     814                 :            : 
+     815                 :            : /* VerifyNewKey + UpdateKey: success*/
+     816                 :          1 : void test_libspdm_requester_encap_key_update_case11(void **state)
+     817                 :            : {
+     818                 :            :     libspdm_return_t status;
+     819                 :            :     libspdm_test_context_t *spdm_test_context;
+     820                 :            :     libspdm_context_t *spdm_context;
+     821                 :            :     uint32_t session_id;
+     822                 :            :     libspdm_session_info_t *session_info;
+     823                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     824                 :            : 
+     825                 :            :     size_t response_size;
+     826                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     827                 :            :     spdm_key_update_response_t *spdm_response;
+     828                 :            : 
+     829                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     830                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     831                 :            : 
+     832                 :          1 :     spdm_test_context = *state;
+     833                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     834                 :          1 :     spdm_test_context->case_id = 0x0B;
+     835                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     836                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     837                 :            : 
+     838                 :          1 :     spdm_set_standard_key_update_test_state(
+     839                 :            :         spdm_context, &session_id);
+     840                 :            : 
+     841                 :          1 :     session_info = &spdm_context->session_info[0];
+     842                 :          1 :     secured_message_context = session_info->secured_message_context;
+     843                 :            : 
+     844                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+     845                 :          1 :         session_info->secured_message_context,
+     846                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+     847                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+     848                 :            : 
+     849                 :            :     /*request side *not* updated*/
+     850                 :            : 
+     851                 :            :     /*last request: verify new key*/
+     852                 :          1 :     session_info->last_key_update_request = m_spdm_key_update_request5;
+     853                 :            :     /*verify new key clear last_key_update_request*/
+     854                 :          1 :     libspdm_zero_mem (&(session_info->last_key_update_request), sizeof(spdm_key_update_request_t));
+     855                 :            : 
+     856                 :            :     /*response side updated */
+     857                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+     858                 :            :                                   secured_message_context->hash_size,
+     859                 :            :                                   m_rsp_secret_buffer, m_rsp_secret_buffer,
+     860                 :            :                                   secured_message_context->hash_size);
+     861                 :            : 
+     862                 :          1 :     response_size = sizeof(response);
+     863                 :          1 :     status = libspdm_get_encap_response_key_update(spdm_context,
+     864                 :            :                                                    m_spdm_key_update_request1_size,
+     865                 :            :                                                    &m_spdm_key_update_request1,
+     866                 :            :                                                    &response_size, response);
+     867                 :            : 
+     868                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     869                 :          1 :     assert_int_equal(response_size, sizeof(spdm_key_update_response_t));
+     870                 :          1 :     spdm_response = (void *)response;
+     871                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     872                 :            :                      SPDM_KEY_UPDATE_ACK);
+     873                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     874                 :            :                      SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY);
+     875                 :          1 :     assert_int_equal(spdm_response->header.param2,
+     876                 :            :                      m_spdm_key_update_request1.header.param2);
+     877                 :          1 :     assert_memory_equal(secured_message_context
+     878                 :            :                         ->application_secret.request_data_secret,
+     879                 :            :                         m_req_secret_buffer, secured_message_context->hash_size);
+     880                 :          1 :     assert_memory_equal(secured_message_context
+     881                 :            :                         ->application_secret.response_data_secret,
+     882                 :            :                         m_rsp_secret_buffer, secured_message_context->hash_size);
+     883                 :          1 : }
+     884                 :            : 
+     885                 :            : /* VerifyNewKey + VerifyNewKey: failed*/
+     886                 :          1 : void test_libspdm_requester_encap_key_update_case12(void **state)
+     887                 :            : {
+     888                 :            :     libspdm_return_t status;
+     889                 :            :     libspdm_test_context_t *spdm_test_context;
+     890                 :            :     libspdm_context_t *spdm_context;
+     891                 :            :     uint32_t session_id;
+     892                 :            :     libspdm_session_info_t *session_info;
+     893                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     894                 :            : 
+     895                 :            :     size_t response_size;
+     896                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     897                 :            :     spdm_key_update_response_t *spdm_response;
+     898                 :            : 
+     899                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     900                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     901                 :            : 
+     902                 :          1 :     spdm_test_context = *state;
+     903                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     904                 :          1 :     spdm_test_context->case_id = 0x0C;
+     905                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     906                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     907                 :            : 
+     908                 :          1 :     spdm_set_standard_key_update_test_state(
+     909                 :            :         spdm_context, &session_id);
+     910                 :            : 
+     911                 :          1 :     session_info = &spdm_context->session_info[0];
+     912                 :          1 :     secured_message_context = session_info->secured_message_context;
+     913                 :            : 
+     914                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+     915                 :          1 :         session_info->secured_message_context,
+     916                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+     917                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+     918                 :            : 
+     919                 :            :     /*request side *not* updated*/
+     920                 :            : 
+     921                 :            :     /*last request: verify new key*/
+     922                 :          1 :     session_info->last_key_update_request = m_spdm_key_update_request5;
+     923                 :            :     /*verify new key clear last_key_update_request*/
+     924                 :          1 :     libspdm_zero_mem (&(session_info->last_key_update_request), sizeof(spdm_key_update_request_t));
+     925                 :            : 
+     926                 :            :     /*response side updated */
+     927                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+     928                 :            :                                   secured_message_context->hash_size,
+     929                 :            :                                   m_rsp_secret_buffer, m_rsp_secret_buffer,
+     930                 :            :                                   secured_message_context->hash_size);
+     931                 :            : 
+     932                 :          1 :     response_size = sizeof(response);
+     933                 :          1 :     status = libspdm_get_encap_response_key_update(spdm_context,
+     934                 :            :                                                    m_spdm_key_update_request5_size,
+     935                 :            :                                                    &m_spdm_key_update_request5,
+     936                 :            :                                                    &response_size, response);
+     937                 :            : 
+     938                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     939                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     940                 :          1 :     spdm_response = (void *)response;
+     941                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     942                 :            :                      SPDM_ERROR);
+     943                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     944                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+     945                 :          1 :     assert_int_equal(spdm_response->header.param2,
+     946                 :            :                      0);
+     947                 :          1 : }
+     948                 :            : 
+     949                 :            : 
+     950                 :            : /* ohter command + UpdateKey: success*/
+     951                 :          1 : void test_libspdm_requester_encap_key_update_case13(void **state)
+     952                 :            : {
+     953                 :            :     libspdm_return_t status;
+     954                 :            :     libspdm_test_context_t *spdm_test_context;
+     955                 :            :     libspdm_context_t *spdm_context;
+     956                 :            :     uint32_t session_id;
+     957                 :            :     libspdm_session_info_t *session_info;
+     958                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     959                 :            : 
+     960                 :            :     size_t response_size;
+     961                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     962                 :            :     spdm_key_update_response_t *spdm_response;
+     963                 :            : 
+     964                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     965                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     966                 :            : 
+     967                 :          1 :     spdm_test_context = *state;
+     968                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     969                 :          1 :     spdm_test_context->case_id = 0x0D;
+     970                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     971                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     972                 :            : 
+     973                 :          1 :     spdm_set_standard_key_update_test_state(
+     974                 :            :         spdm_context, &session_id);
+     975                 :            : 
+     976                 :          1 :     session_info = &spdm_context->session_info[0];
+     977                 :          1 :     secured_message_context = session_info->secured_message_context;
+     978                 :            : 
+     979                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+     980                 :          1 :         session_info->secured_message_context,
+     981                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+     982                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+     983                 :            : 
+     984                 :            :     /*request side *not* updated*/
+     985                 :            : 
+     986                 :            :     /*ohter command with cleared last_key_update_request*/
+     987                 :          1 :     libspdm_zero_mem (&(session_info->last_key_update_request), sizeof(spdm_key_update_request_t));
+     988                 :            : 
+     989                 :            :     /*response side updated */
+     990                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+     991                 :            :                                   secured_message_context->hash_size,
+     992                 :            :                                   m_rsp_secret_buffer, m_rsp_secret_buffer,
+     993                 :            :                                   secured_message_context->hash_size);
+     994                 :            : 
+     995                 :          1 :     response_size = sizeof(response);
+     996                 :          1 :     status = libspdm_get_encap_response_key_update(spdm_context,
+     997                 :            :                                                    m_spdm_key_update_request1_size,
+     998                 :            :                                                    &m_spdm_key_update_request1,
+     999                 :            :                                                    &response_size, response);
+    1000                 :            : 
+    1001                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1002                 :          1 :     assert_int_equal(response_size, sizeof(spdm_key_update_response_t));
+    1003                 :          1 :     spdm_response = (void *)response;
+    1004                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1005                 :            :                      SPDM_KEY_UPDATE_ACK);
+    1006                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1007                 :            :                      SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY);
+    1008                 :          1 :     assert_int_equal(spdm_response->header.param2,
+    1009                 :            :                      m_spdm_key_update_request1.header.param2);
+    1010                 :          1 :     assert_memory_equal(secured_message_context
+    1011                 :            :                         ->application_secret.request_data_secret,
+    1012                 :            :                         m_req_secret_buffer, secured_message_context->hash_size);
+    1013                 :          1 :     assert_memory_equal(secured_message_context
+    1014                 :            :                         ->application_secret.response_data_secret,
+    1015                 :            :                         m_rsp_secret_buffer, secured_message_context->hash_size);
+    1016                 :          1 : }
+    1017                 :            : 
+    1018                 :            : 
+    1019                 :            : /* ohter command + VerifyNewKey: failed*/
+    1020                 :          1 : void test_libspdm_requester_encap_key_update_case14(void **state)
+    1021                 :            : {
+    1022                 :            :     libspdm_return_t status;
+    1023                 :            :     libspdm_test_context_t *spdm_test_context;
+    1024                 :            :     libspdm_context_t *spdm_context;
+    1025                 :            :     uint32_t session_id;
+    1026                 :            :     libspdm_session_info_t *session_info;
+    1027                 :            :     libspdm_secured_message_context_t *secured_message_context;
+    1028                 :            : 
+    1029                 :            :     size_t response_size;
+    1030                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1031                 :            :     spdm_key_update_response_t *spdm_response;
+    1032                 :            : 
+    1033                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    1034                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    1035                 :            : 
+    1036                 :          1 :     spdm_test_context = *state;
+    1037                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1038                 :          1 :     spdm_test_context->case_id = 0x0E;
+    1039                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1040                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1041                 :            : 
+    1042                 :          1 :     spdm_set_standard_key_update_test_state(
+    1043                 :            :         spdm_context, &session_id);
+    1044                 :            : 
+    1045                 :          1 :     session_info = &spdm_context->session_info[0];
+    1046                 :          1 :     secured_message_context = session_info->secured_message_context;
+    1047                 :            : 
+    1048                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    1049                 :          1 :         session_info->secured_message_context,
+    1050                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    1051                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    1052                 :            : 
+    1053                 :            :     /*request side *not* updated*/
+    1054                 :            : 
+    1055                 :            :     /*ohter command with cleared last_key_update_request*/
+    1056                 :          1 :     libspdm_zero_mem (&(session_info->last_key_update_request), sizeof(spdm_key_update_request_t));
+    1057                 :            : 
+    1058                 :            :     /*response side updated */
+    1059                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    1060                 :            :                                   secured_message_context->hash_size,
+    1061                 :            :                                   m_rsp_secret_buffer, m_rsp_secret_buffer,
+    1062                 :            :                                   secured_message_context->hash_size);
+    1063                 :            : 
+    1064                 :          1 :     response_size = sizeof(response);
+    1065                 :          1 :     status = libspdm_get_encap_response_key_update(spdm_context,
+    1066                 :            :                                                    m_spdm_key_update_request5_size,
+    1067                 :            :                                                    &m_spdm_key_update_request5,
+    1068                 :            :                                                    &response_size, response);
+    1069                 :            : 
+    1070                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1071                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1072                 :          1 :     spdm_response = (void *)response;
+    1073                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1074                 :            :                      SPDM_ERROR);
+    1075                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1076                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+    1077                 :          1 :     assert_int_equal(spdm_response->header.param2,
+    1078                 :            :                      0);
+    1079                 :          1 : }
+    1080                 :            : 
+    1081                 :            : 
+    1082                 :            : 
+    1083                 :            : libspdm_test_context_t m_libspdm_requester_encap_key_update_test_context = {
+    1084                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+    1085                 :            :     false,
+    1086                 :            : };
+    1087                 :            : 
+    1088                 :          1 : int libspdm_requester_encap_key_update_test_main(void)
+    1089                 :            : {
+    1090                 :          1 :     const struct CMUnitTest spdm_requester_key_update_tests[] = {
+    1091                 :            :         /* Success Case -- UpdateKey*/
+    1092                 :            :         cmocka_unit_test(test_libspdm_requester_encap_key_update_case1),
+    1093                 :            :         /* Bad request size*/
+    1094                 :            :         cmocka_unit_test(test_libspdm_requester_encap_key_update_case2),
+    1095                 :            :         /* Buffer reset*/
+    1096                 :            :         cmocka_unit_test(test_libspdm_requester_encap_key_update_case3),
+    1097                 :            :         /* Unsupported KEY_UPD capabilities*/
+    1098                 :            :         cmocka_unit_test(test_libspdm_requester_encap_key_update_case4),
+    1099                 :            :         /* Uninitialized session*/
+    1100                 :            :         cmocka_unit_test(test_libspdm_requester_encap_key_update_case5),
+    1101                 :            :         /* ruquster RETURN_UNSUPPORTED*/
+    1102                 :            :         cmocka_unit_test(test_libspdm_requester_encap_key_update_case6),
+    1103                 :            :         /* Bad request size*/
+    1104                 :            :         cmocka_unit_test(test_libspdm_requester_encap_key_update_case7),
+    1105                 :            :         /* Uninitialized key update*/
+    1106                 :            :         cmocka_unit_test(test_libspdm_requester_encap_key_update_case8),
+    1107                 :            :         /* Invalid operation*/
+    1108                 :            :         cmocka_unit_test(test_libspdm_requester_encap_key_update_case9),
+    1109                 :            :         /* UpdateKey + UpdateKey: failed*/
+    1110                 :            :         cmocka_unit_test(test_libspdm_requester_encap_key_update_case10),
+    1111                 :            :         /* VerifyNewKey + UpdateKey: success*/
+    1112                 :            :         cmocka_unit_test(test_libspdm_requester_encap_key_update_case11),
+    1113                 :            :         /* VerifyNewKey + VerifyNewKey: failed*/
+    1114                 :            :         cmocka_unit_test(test_libspdm_requester_encap_key_update_case12),
+    1115                 :            :         /* ohter command + UpdateKey: success*/
+    1116                 :            :         cmocka_unit_test(test_libspdm_requester_encap_key_update_case13),
+    1117                 :            :         /* ohter command + VerifyNewKey: failed*/
+    1118                 :            :         cmocka_unit_test(test_libspdm_requester_encap_key_update_case14),
+    1119                 :            :     };
+    1120                 :            : 
+    1121                 :          1 :     libspdm_setup_test_context(&m_libspdm_requester_encap_key_update_test_context);
+    1122                 :            : 
+    1123                 :          1 :     return cmocka_run_group_tests(spdm_requester_key_update_tests,
+    1124                 :            :                                   libspdm_unit_test_group_setup,
+    1125                 :            :                                   libspdm_unit_test_group_teardown);
+    1126                 :            : }
+    1127                 :            : 
+    1128                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/encap_request.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_requester/encap_request.c.func-sort-c.html new file mode 100644 index 00000000000..1cc1585e458 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/encap_request.c.func-sort-c.html @@ -0,0 +1,133 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/encap_request.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - encap_request.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:56258695.9 %
Date:2024-09-22 08:21:07Functions:1313100.0 %
Branches:506675.8 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_encap_request_test_main1
libspdm_test_requester_encap_request_case11
libspdm_test_requester_encap_request_case101
libspdm_test_requester_encap_request_case21
libspdm_test_requester_encap_request_case31
libspdm_test_requester_encap_request_case41
libspdm_test_requester_encap_request_case51
libspdm_test_requester_encap_request_case61
libspdm_test_requester_encap_request_case71
libspdm_test_requester_encap_request_case81
libspdm_test_requester_encap_request_case91
libspdm_requester_encap_request_test_receive_message17
libspdm_requester_encap_request_test_send_message18
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/encap_request.c.func.html b/coverage_log/unit_test/test_spdm_requester/encap_request.c.func.html new file mode 100644 index 00000000000..563dd75e01f --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/encap_request.c.func.html @@ -0,0 +1,133 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/encap_request.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - encap_request.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:56258695.9 %
Date:2024-09-22 08:21:07Functions:1313100.0 %
Branches:506675.8 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_encap_request_test_main1
libspdm_requester_encap_request_test_receive_message17
libspdm_requester_encap_request_test_send_message18
libspdm_test_requester_encap_request_case11
libspdm_test_requester_encap_request_case101
libspdm_test_requester_encap_request_case21
libspdm_test_requester_encap_request_case31
libspdm_test_requester_encap_request_case41
libspdm_test_requester_encap_request_case51
libspdm_test_requester_encap_request_case61
libspdm_test_requester_encap_request_case71
libspdm_test_requester_encap_request_case81
libspdm_test_requester_encap_request_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/encap_request.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/encap_request.c.gcov.html new file mode 100644 index 00000000000..d362a51affa --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/encap_request.c.gcov.html @@ -0,0 +1,1205 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/encap_request.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - encap_request.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:56258695.9 %
Date:2024-09-22 08:21:07Functions:1313100.0 %
Branches:506675.8 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_requester_lib.h"
+       9                 :            : 
+      10                 :            : #if LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP
+      11                 :            : 
+      12                 :            : static uint8_t m_libspdm_local_certificate_chain[LIBSPDM_MAX_CERT_CHAIN_SIZE];
+      13                 :            : static uint8_t temp_buf[LIBSPDM_RECEIVER_BUFFER_SIZE];
+      14                 :            : static uint8_t temp_buff[LIBSPDM_MAX_SPDM_MSG_SIZE];
+      15                 :            : 
+      16                 :         18 : libspdm_return_t libspdm_requester_encap_request_test_send_message(void *spdm_context,
+      17                 :            :                                                                    size_t request_size,
+      18                 :            :                                                                    const void *request,
+      19                 :            :                                                                    uint64_t timeout)
+      20                 :            : {
+      21                 :            :     libspdm_test_context_t *spdm_test_context;
+      22                 :            : 
+      23                 :         18 :     spdm_test_context = libspdm_get_test_context();
+      24                 :            :     static uint8_t sub_index = 0;
+      25                 :            :     spdm_deliver_encapsulated_response_request_t *spdm_deliver_encapsulated_response_request;
+      26                 :            :     uint8_t send_temp_buf[LIBSPDM_SENDER_BUFFER_SIZE];
+      27                 :            :     size_t decode_message_size;
+      28                 :            :     spdm_error_response_t *spdm_response;
+      29                 :            :     libspdm_return_t status;
+      30                 :            :     uint32_t *message_session_id;
+      31                 :            :     bool is_message_app_message;
+      32                 :            :     uint8_t message_buffer[LIBSPDM_SENDER_BUFFER_SIZE];
+      33                 :            : 
+      34                 :         18 :     memcpy(message_buffer, request, request_size);
+      35                 :            : 
+      36   [ +  +  +  +  :         18 :     switch (spdm_test_context->case_id)
+          +  +  +  +  +  
+                   +  - ]
+      37                 :            :     {
+      38                 :          1 :     case 0x1:
+      39                 :          1 :         return LIBSPDM_STATUS_SEND_FAIL;
+      40                 :          2 :     case 0x2:
+      41                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+      42                 :          2 :     case 0x3:
+      43                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+      44                 :          1 :     case 0x4:
+      45                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      46                 :          2 :     case 0x5:
+      47                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+      48                 :          2 :     case 0x6:
+      49                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+      50                 :          2 :     case 0x7:
+      51                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+      52                 :          2 :     case 0x8:
+      53                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+      54                 :          2 :     case 0x9:
+      55                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+      56                 :          2 :     case 0xA:
+      57                 :            :     {
+      58         [ +  + ]:          2 :         if (sub_index == 0) {
+      59                 :          1 :             sub_index++;
+      60         [ +  - ]:          1 :         } else if (sub_index == 1) {
+      61                 :          1 :             sub_index = 0;
+      62                 :          1 :             message_session_id = NULL;
+      63                 :          1 :             is_message_app_message = false;
+      64                 :          1 :             spdm_deliver_encapsulated_response_request = (void*) send_temp_buf;
+      65                 :          1 :             decode_message_size = sizeof(spdm_deliver_encapsulated_response_request_t) +
+      66                 :            :                                   sizeof(spdm_error_response_t);
+      67                 :          1 :             status = libspdm_transport_test_decode_message(spdm_context, &message_session_id,
+      68                 :            :                                                            &is_message_app_message, true,
+      69                 :            :                                                            request_size, message_buffer,
+      70                 :            :                                                            &decode_message_size,
+      71                 :            :                                                            (void **)&spdm_deliver_encapsulated_response_request);
+      72         [ -  + ]:          1 :             if (LIBSPDM_STATUS_IS_ERROR(status)) {
+      73                 :          0 :                 LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR, "transport_decode_message - %xu\n",
+      74                 :            :                                status));
+      75                 :            :             }
+      76                 :          1 :             spdm_response = (void*) (spdm_deliver_encapsulated_response_request + 1);
+      77         [ -  + ]:          1 :             if (spdm_response->header.request_response_code != SPDM_ERROR) {
+      78                 :          0 :                 return LIBSPDM_STATUS_SEND_FAIL;
+      79                 :            :             }
+      80         [ -  + ]:          1 :             if (spdm_response->header.param1 != SPDM_ERROR_CODE_UNEXPECTED_REQUEST) { /* Here check ErrorCode should be UnexpectedRequestd */
+      81                 :          0 :                 return LIBSPDM_STATUS_SEND_FAIL;
+      82                 :            :             }
+      83         [ -  + ]:          1 :             if (spdm_response->header.param2 != 0) {
+      84                 :          0 :                 return LIBSPDM_STATUS_SEND_FAIL;
+      85                 :            :             }
+      86                 :            :         }
+      87                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+      88                 :            :     }
+      89                 :          0 :     default:
+      90                 :          0 :         return LIBSPDM_STATUS_SEND_FAIL;
+      91                 :            :     }
+      92                 :            : }
+      93                 :            : 
+      94                 :         17 : libspdm_return_t libspdm_requester_encap_request_test_receive_message(
+      95                 :            :     void *spdm_context, size_t *response_size,
+      96                 :            :     void **response, uint64_t timeout)
+      97                 :            : {
+      98                 :            : 
+      99                 :            :     libspdm_test_context_t *spdm_test_context;
+     100                 :            :     spdm_encapsulated_request_response_t *libspdm_encapsulated_request_response;
+     101                 :            :     uint8_t *digest;
+     102                 :            :     size_t temp_buf_size;
+     103                 :            :     uint8_t *temp_buf_ptr;
+     104                 :            : 
+     105                 :         17 :     spdm_test_context = libspdm_get_test_context();
+     106                 :            :     static uint8_t sub_index = 0;
+     107   [ -  +  +  +  :         17 :     switch (spdm_test_context->case_id)
+          +  +  +  +  +  
+                   +  - ]
+     108                 :            :     {
+     109                 :          0 :     case 0x1:
+     110                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+     111                 :            : 
+     112                 :          2 :     case 0x2:
+     113                 :            :     {
+     114                 :            :         spdm_digest_response_t *spdm_response;
+     115                 :            : 
+     116                 :            :         ((libspdm_context_t *)spdm_context)
+     117                 :          2 :         ->connection_info.algorithm.base_hash_algo =
+     118                 :            :             m_libspdm_use_hash_algo;
+     119         [ +  + ]:          2 :         if (sub_index == 0) {
+     120                 :          1 :             temp_buf_size = sizeof(spdm_digest_response_t) +
+     121                 :          1 :                             libspdm_get_hash_size(m_libspdm_use_hash_algo) +
+     122                 :            :                             sizeof(spdm_encapsulated_request_response_t);
+     123                 :          1 :             libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
+     124                 :          1 :             temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
+     125                 :          1 :             libspdm_encapsulated_request_response = (void*) temp_buf_ptr;
+     126                 :          1 :             libspdm_encapsulated_request_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     127                 :          1 :             libspdm_encapsulated_request_response->header.request_response_code =
+     128                 :            :                 SPDM_ENCAPSULATED_REQUEST;
+     129                 :          1 :             libspdm_encapsulated_request_response->header.param1 = 0;
+     130                 :          1 :             libspdm_encapsulated_request_response->header.param2 = 0;
+     131                 :            : 
+     132                 :          1 :             spdm_response = (void *)(temp_buf_ptr
+     133                 :            :                                      + sizeof(spdm_encapsulated_request_response_t));
+     134                 :          1 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     135                 :          1 :             spdm_response->header.request_response_code = SPDM_GET_DIGESTS;
+     136                 :          1 :             spdm_response->header.param1 = 0;
+     137                 :          1 :             spdm_response->header.param2 = 0;
+     138                 :          1 :             libspdm_set_mem(m_libspdm_local_certificate_chain,
+     139                 :            :                             sizeof(m_libspdm_local_certificate_chain),
+     140                 :            :                             (uint8_t)(0xFF));
+     141                 :            : 
+     142                 :          1 :             digest = (void *)(spdm_response + 1);
+     143                 :          1 :             libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
+     144                 :            :                              sizeof(m_libspdm_local_certificate_chain), &digest[0]);
+     145                 :          1 :             spdm_response->header.param2 |= (0x01 << 0);
+     146                 :          1 :             sub_index++;
+     147         [ +  - ]:          1 :         } else if (sub_index == 1) {
+     148                 :            :             /*When the version is SPDM_MESSAGE_VERSION_12, use the following code*/
+     149                 :            :             spdm_message_header_t *spdm_encapsulated_response_ack_response;
+     150                 :          1 :             temp_buf_size = sizeof(spdm_message_header_t);
+     151                 :          1 :             libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
+     152                 :          1 :             temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
+     153                 :          1 :             spdm_encapsulated_response_ack_response = (void*) temp_buf_ptr;
+     154                 :          1 :             spdm_encapsulated_response_ack_response->spdm_version = SPDM_MESSAGE_VERSION_11;
+     155                 :          1 :             spdm_encapsulated_response_ack_response->request_response_code =
+     156                 :            :                 SPDM_ENCAPSULATED_RESPONSE_ACK;
+     157                 :          1 :             spdm_encapsulated_response_ack_response->param1 = 0;
+     158                 :          1 :             spdm_encapsulated_response_ack_response->param2 =
+     159                 :            :                 SPDM_ENCAPSULATED_RESPONSE_ACK_RESPONSE_PAYLOAD_TYPE_ABSENT;
+     160                 :          1 :             sub_index = 0;
+     161                 :            :         } else {
+     162                 :          0 :             temp_buf_size = 0;
+     163                 :          0 :             temp_buf_ptr = NULL;
+     164                 :            :         }
+     165                 :          2 :         libspdm_transport_test_encode_message(spdm_context, NULL, false, false,
+     166                 :            :                                               temp_buf_size, temp_buf_ptr,
+     167                 :            :                                               response_size, response);
+     168                 :            :     }
+     169                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     170                 :          2 :     case 0x3:
+     171                 :            :     {
+     172                 :            :         spdm_digest_response_t *spdm_response;
+     173                 :            : 
+     174                 :            :         ((libspdm_context_t *)spdm_context)
+     175                 :          2 :         ->connection_info.algorithm.base_hash_algo =
+     176                 :            :             m_libspdm_use_hash_algo;
+     177         [ +  + ]:          2 :         if (sub_index == 0) {
+     178                 :          1 :             temp_buf_size = sizeof(spdm_digest_response_t) +
+     179                 :          1 :                             libspdm_get_hash_size(m_libspdm_use_hash_algo) +
+     180                 :            :                             sizeof(spdm_encapsulated_request_response_t);
+     181                 :          1 :             libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
+     182                 :          1 :             temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
+     183                 :          1 :             libspdm_encapsulated_request_response = (void *) temp_buf_ptr;
+     184                 :          1 :             libspdm_encapsulated_request_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     185                 :          1 :             libspdm_encapsulated_request_response->header.request_response_code =
+     186                 :            :                 SPDM_ENCAPSULATED_REQUEST;
+     187                 :          1 :             libspdm_encapsulated_request_response->header.param1 = 0;
+     188                 :          1 :             libspdm_encapsulated_request_response->header.param2 = 0;
+     189                 :            : 
+     190                 :          1 :             spdm_response =
+     191                 :            :                 (void *)(temp_buf_ptr + sizeof(spdm_encapsulated_request_response_t));
+     192                 :          1 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     193                 :          1 :             spdm_response->header.request_response_code = SPDM_GET_DIGESTS;
+     194                 :          1 :             spdm_response->header.param1 = 0;
+     195                 :          1 :             spdm_response->header.param2 = 0;
+     196                 :          1 :             libspdm_set_mem(m_libspdm_local_certificate_chain,
+     197                 :            :                             sizeof(m_libspdm_local_certificate_chain),
+     198                 :            :                             (uint8_t)(0xFF));
+     199                 :            : 
+     200                 :          1 :             digest = (void *)(spdm_response + 1);
+     201                 :          1 :             libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
+     202                 :            :                              sizeof(m_libspdm_local_certificate_chain), &digest[0]);
+     203                 :          1 :             spdm_response->header.param2 |= (0x01 << 0);
+     204                 :          1 :             sub_index++;
+     205         [ +  - ]:          1 :         } else if (sub_index == 1) {
+     206                 :            :             /*When the version is SPDM_MESSAGE_VERSION_12, use the following code*/
+     207                 :            :             spdm_encapsulated_response_ack_response_t *spdm_encapsulated_response_ack_response;
+     208                 :          1 :             temp_buf_size = sizeof(spdm_encapsulated_response_ack_response_t);
+     209                 :          1 :             libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
+     210                 :          1 :             temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
+     211                 :          1 :             spdm_encapsulated_response_ack_response = (void *) temp_buf_ptr;
+     212                 :          1 :             spdm_encapsulated_response_ack_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     213                 :          1 :             spdm_encapsulated_response_ack_response->header.request_response_code =
+     214                 :            :                 SPDM_ENCAPSULATED_RESPONSE_ACK;
+     215                 :          1 :             spdm_encapsulated_response_ack_response->header.param1 = 0;
+     216                 :          1 :             spdm_encapsulated_response_ack_response->header.param2 =
+     217                 :            :                 SPDM_ENCAPSULATED_RESPONSE_ACK_RESPONSE_PAYLOAD_TYPE_ABSENT;
+     218                 :          1 :             sub_index = 0;
+     219                 :            :         } else {
+     220                 :          0 :             temp_buf_size = 0;
+     221                 :          0 :             temp_buf_ptr = NULL;
+     222                 :            :         }
+     223                 :          2 :         libspdm_transport_test_encode_message(spdm_context, NULL, false, false,
+     224                 :            :                                               temp_buf_size, temp_buf_ptr,
+     225                 :            :                                               response_size, response);
+     226                 :            :     }
+     227                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     228                 :          1 :     case 0x4:
+     229                 :            :     {
+     230                 :            :         spdm_digest_response_t *spdm_response;
+     231                 :            : 
+     232                 :            :         ((libspdm_context_t *)spdm_context)
+     233                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+     234                 :            :             m_libspdm_use_hash_algo;
+     235                 :          1 :         temp_buf_size = sizeof(spdm_encapsulated_request_response_t);
+     236                 :          1 :         libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
+     237                 :          1 :         temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
+     238                 :          1 :         spdm_response = (void *) temp_buf_ptr;
+     239                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     240                 :          1 :         spdm_response->header.request_response_code = SPDM_ENCAPSULATED_REQUEST;
+     241                 :          1 :         spdm_response->header.param1 = 0;
+     242                 :          1 :         spdm_response->header.param2 = 0;
+     243                 :            : 
+     244                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false, false,
+     245                 :            :                                               temp_buf_size, temp_buf_ptr,
+     246                 :            :                                               response_size, response);
+     247                 :            :     }
+     248                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     249                 :          2 :     case 0x5:
+     250                 :            :     {
+     251                 :            :         spdm_digest_response_t *spdm_response;
+     252                 :            : 
+     253                 :            :         ((libspdm_context_t *)spdm_context)
+     254                 :          2 :         ->connection_info.algorithm.base_hash_algo =
+     255                 :            :             m_libspdm_use_hash_algo;
+     256         [ +  + ]:          2 :         if (sub_index == 0) {
+     257                 :          1 :             temp_buf_size = sizeof(spdm_digest_response_t) +
+     258                 :          1 :                             libspdm_get_hash_size(m_libspdm_use_hash_algo) +
+     259                 :            :                             sizeof(spdm_encapsulated_request_response_t);
+     260                 :          1 :             libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
+     261                 :          1 :             temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
+     262                 :          1 :             libspdm_encapsulated_request_response = (void *)temp_buf_ptr;
+     263                 :          1 :             libspdm_encapsulated_request_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     264                 :          1 :             libspdm_encapsulated_request_response->header.request_response_code =
+     265                 :            :                 SPDM_ENCAPSULATED_REQUEST;
+     266                 :          1 :             libspdm_encapsulated_request_response->header.param1 = 0;
+     267                 :          1 :             libspdm_encapsulated_request_response->header.param2 = 0;
+     268                 :            : 
+     269                 :          1 :             spdm_response =
+     270                 :            :                 (void *)(temp_buf_ptr + sizeof(spdm_encapsulated_request_response_t));
+     271                 :          1 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     272                 :          1 :             spdm_response->header.request_response_code = SPDM_GET_DIGESTS;
+     273                 :          1 :             spdm_response->header.param1 = 0;
+     274                 :          1 :             spdm_response->header.param2 = 0;
+     275                 :          1 :             libspdm_set_mem(m_libspdm_local_certificate_chain,
+     276                 :            :                             sizeof(m_libspdm_local_certificate_chain),
+     277                 :            :                             (uint8_t)(0xFF));
+     278                 :            : 
+     279                 :          1 :             digest = (void *)(spdm_response + 1);
+     280                 :          1 :             libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
+     281                 :            :                              sizeof(m_libspdm_local_certificate_chain), &digest[0]);
+     282                 :          1 :             spdm_response->header.param2 |= (0x01 << 0);
+     283                 :            : 
+     284                 :          1 :             libspdm_transport_test_encode_message(spdm_context, NULL, false, false,
+     285                 :            :                                                   temp_buf_size, temp_buf_ptr,
+     286                 :            :                                                   response_size, response);
+     287                 :          1 :             sub_index++;
+     288         [ +  - ]:          1 :         } else if (sub_index == 1) {
+     289                 :            :             size_t temp_buff_size;
+     290                 :            :             uint8_t *temp_buff_ptr;
+     291                 :            : 
+     292                 :          1 :             temp_buff_size = sizeof(spdm_message_header_t);
+     293                 :          1 :             libspdm_zero_mem(temp_buff, LIBSPDM_MAX_SPDM_MSG_SIZE);
+     294                 :          1 :             temp_buff_ptr = temp_buff + sizeof(libspdm_test_message_header_t);
+     295                 :            : 
+     296                 :          1 :             sub_index = 0;
+     297                 :          1 :             libspdm_transport_test_encode_message(spdm_context, NULL, false, false,
+     298                 :            :                                                   temp_buff_size, temp_buff_ptr,
+     299                 :            :                                                   response_size, response);
+     300                 :            :         }
+     301                 :            :     }
+     302                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     303                 :          2 :     case 0x6:
+     304                 :            :     {
+     305                 :            :         spdm_digest_response_t *spdm_response;
+     306                 :            : 
+     307                 :            :         ((libspdm_context_t *)spdm_context)
+     308                 :          2 :         ->connection_info.algorithm.base_hash_algo =
+     309                 :            :             m_libspdm_use_hash_algo;
+     310         [ +  + ]:          2 :         if (sub_index == 0) {
+     311                 :          1 :             temp_buf_size =
+     312                 :            :                 sizeof(spdm_digest_response_t) +
+     313                 :          1 :                 libspdm_get_hash_size(m_libspdm_use_hash_algo) +
+     314                 :            :                 sizeof(spdm_encapsulated_request_response_t);
+     315                 :          1 :             libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
+     316                 :          1 :             temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
+     317                 :            : 
+     318                 :          1 :             libspdm_encapsulated_request_response = (void*) temp_buf_ptr;
+     319                 :          1 :             libspdm_encapsulated_request_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     320                 :          1 :             libspdm_encapsulated_request_response->header.request_response_code =
+     321                 :            :                 SPDM_ENCAPSULATED_REQUEST;
+     322                 :          1 :             libspdm_encapsulated_request_response->header.param1 = 0;
+     323                 :          1 :             libspdm_encapsulated_request_response->header.param2 = 0;
+     324                 :            : 
+     325                 :          1 :             spdm_response =
+     326                 :            :                 (void*) (temp_buf_ptr + sizeof(spdm_encapsulated_request_response_t));
+     327                 :          1 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     328                 :          1 :             spdm_response->header.request_response_code = SPDM_GET_DIGESTS;
+     329                 :          1 :             spdm_response->header.param1 = 0;
+     330                 :          1 :             spdm_response->header.param2 = 0;
+     331                 :          1 :             libspdm_set_mem(m_libspdm_local_certificate_chain,
+     332                 :            :                             sizeof(m_libspdm_local_certificate_chain),
+     333                 :            :                             (uint8_t) (0xFF));
+     334                 :            : 
+     335                 :          1 :             digest = (void*) (spdm_response + 1);
+     336                 :          1 :             libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
+     337                 :            :                              sizeof(m_libspdm_local_certificate_chain), &digest[0]);
+     338                 :          1 :             spdm_response->header.param2 |= (0x01 << 0);
+     339                 :          1 :             sub_index++;
+     340         [ +  - ]:          1 :         } else if (sub_index == 1) {
+     341                 :            :             spdm_encapsulated_response_ack_response_t* spdm_encapsulated_response_ack_response;
+     342                 :          1 :             temp_buf_size = sizeof(spdm_encapsulated_response_ack_response_t);
+     343                 :          1 :             libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
+     344                 :          1 :             temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
+     345                 :          1 :             spdm_encapsulated_response_ack_response = (void*) temp_buf_ptr;
+     346                 :          1 :             spdm_encapsulated_response_ack_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     347                 :          1 :             spdm_encapsulated_response_ack_response->header.request_response_code =
+     348                 :            :                 SPDM_ENCAPSULATED_RESPONSE_ACK;
+     349                 :          1 :             spdm_encapsulated_response_ack_response->header.param1 = 0;
+     350                 :          1 :             spdm_encapsulated_response_ack_response->header.param2 = 0;
+     351                 :          1 :             sub_index = 0;
+     352                 :            :         } else {
+     353                 :          0 :             temp_buf_size = 0;
+     354                 :          0 :             temp_buf_ptr = NULL;
+     355                 :            :         }
+     356                 :          2 :         libspdm_transport_test_encode_message(spdm_context, NULL, false, false,
+     357                 :            :                                               temp_buf_size, temp_buf_ptr,
+     358                 :            :                                               response_size, response);
+     359                 :            :     }
+     360                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     361                 :          2 :     case 0x7:
+     362                 :            :     {
+     363                 :            :         spdm_digest_response_t *spdm_response;
+     364                 :            : 
+     365                 :            :         ((libspdm_context_t *)spdm_context)
+     366                 :          2 :         ->connection_info.algorithm.base_hash_algo =
+     367                 :            :             m_libspdm_use_hash_algo;
+     368         [ +  + ]:          2 :         if (sub_index == 0) {
+     369                 :          1 :             temp_buf_size = sizeof(spdm_digest_response_t) +
+     370                 :          1 :                             libspdm_get_hash_size(m_libspdm_use_hash_algo) +
+     371                 :            :                             sizeof(spdm_encapsulated_request_response_t);
+     372                 :          1 :             libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
+     373                 :          1 :             temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
+     374                 :          1 :             libspdm_encapsulated_request_response = (void *)temp_buf_ptr;
+     375                 :          1 :             libspdm_encapsulated_request_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     376                 :          1 :             libspdm_encapsulated_request_response->header.request_response_code =
+     377                 :            :                 SPDM_ENCAPSULATED_REQUEST;
+     378                 :          1 :             libspdm_encapsulated_request_response->header.param1 = 0;
+     379                 :          1 :             libspdm_encapsulated_request_response->header.param2 = 0;
+     380                 :            : 
+     381                 :          1 :             spdm_response =
+     382                 :            :                 (void *)(temp_buf_ptr + sizeof(spdm_encapsulated_request_response_t));
+     383                 :          1 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     384                 :          1 :             spdm_response->header.request_response_code = SPDM_GET_DIGESTS;
+     385                 :          1 :             spdm_response->header.param1 = 0;
+     386                 :          1 :             spdm_response->header.param2 = 0;
+     387                 :          1 :             libspdm_set_mem(m_libspdm_local_certificate_chain,
+     388                 :            :                             sizeof(m_libspdm_local_certificate_chain),
+     389                 :            :                             (uint8_t)(0xFF));
+     390                 :            : 
+     391                 :          1 :             digest = (void *)(spdm_response + 1);
+     392                 :          1 :             libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
+     393                 :            :                              sizeof(m_libspdm_local_certificate_chain), &digest[0]);
+     394                 :          1 :             spdm_response->header.param2 |= (0x01 << 0);
+     395                 :          1 :             sub_index++;
+     396         [ +  - ]:          1 :         } else if (sub_index == 1) {
+     397                 :            :             spdm_encapsulated_response_ack_response_t *spdm_encapsulated_response_ack_response;
+     398                 :          1 :             temp_buf_size = sizeof(spdm_encapsulated_response_ack_response_t);
+     399                 :          1 :             libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
+     400                 :          1 :             temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
+     401                 :          1 :             spdm_encapsulated_response_ack_response = (void *) temp_buf_ptr;
+     402                 :          1 :             spdm_encapsulated_response_ack_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     403                 :          1 :             spdm_encapsulated_response_ack_response->header.request_response_code =
+     404                 :            :                 SPDM_ENCAPSULATED_RESPONSE_ACK;
+     405                 :          1 :             spdm_encapsulated_response_ack_response->header.param1 = 0;
+     406                 :          1 :             spdm_encapsulated_response_ack_response->header.param2 =
+     407                 :            :                 SPDM_ENCAPSULATED_RESPONSE_ACK_RESPONSE_PAYLOAD_TYPE_REQ_SLOT_NUMBER;
+     408                 :          1 :             sub_index = 0;
+     409                 :            :         } else {
+     410                 :          0 :             temp_buf_size = 0;
+     411                 :          0 :             temp_buf_ptr = NULL;
+     412                 :            :         }
+     413                 :          2 :         libspdm_transport_test_encode_message(spdm_context, NULL, false, false,
+     414                 :            :                                               temp_buf_size, temp_buf_ptr,
+     415                 :            :                                               response_size, response);
+     416                 :            :     }
+     417                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     418                 :          2 :     case 0x8:
+     419                 :            :     {
+     420                 :            :         spdm_get_certificate_request_t *spdm_response;
+     421                 :            : 
+     422                 :            :         ((libspdm_context_t *)spdm_context)
+     423                 :          2 :         ->connection_info.algorithm.base_hash_algo =
+     424                 :            :             m_libspdm_use_hash_algo;
+     425         [ +  + ]:          2 :         if (sub_index == 0) {
+     426                 :          1 :             temp_buf_size = sizeof(spdm_get_certificate_request_t) +
+     427                 :            :                             sizeof(spdm_encapsulated_request_response_t);
+     428                 :          1 :             libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
+     429                 :          1 :             temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
+     430                 :          1 :             libspdm_encapsulated_request_response = (void *)temp_buf_ptr;
+     431                 :          1 :             libspdm_encapsulated_request_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     432                 :          1 :             libspdm_encapsulated_request_response->header.request_response_code =
+     433                 :            :                 SPDM_ENCAPSULATED_REQUEST;
+     434                 :          1 :             libspdm_encapsulated_request_response->header.param1 = 0;
+     435                 :          1 :             libspdm_encapsulated_request_response->header.param2 = 0;
+     436                 :            : 
+     437                 :          1 :             spdm_response =
+     438                 :            :                 (void *)(temp_buf_ptr + sizeof(spdm_encapsulated_request_response_t));
+     439                 :          1 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     440                 :          1 :             spdm_response->header.request_response_code = SPDM_GET_CERTIFICATE;
+     441                 :          1 :             spdm_response->header.param1 = 0;
+     442                 :          1 :             spdm_response->header.param2 = 0;
+     443                 :          1 :             spdm_response->offset = 0;
+     444                 :          1 :             spdm_response->length = LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN;
+     445                 :          1 :             sub_index++;
+     446         [ +  - ]:          1 :         } else if (sub_index == 1) {
+     447                 :            :             /*When the version is SPDM_MESSAGE_VERSION_12, use the following code*/
+     448                 :            :             spdm_message_header_t *spdm_encapsulated_response_ack_response;
+     449                 :          1 :             temp_buf_size = sizeof(spdm_message_header_t);
+     450                 :          1 :             libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
+     451                 :          1 :             temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
+     452                 :          1 :             spdm_encapsulated_response_ack_response = (void *)temp_buf_ptr;
+     453                 :          1 :             spdm_encapsulated_response_ack_response->spdm_version = SPDM_MESSAGE_VERSION_11;
+     454                 :          1 :             spdm_encapsulated_response_ack_response->request_response_code =
+     455                 :            :                 SPDM_ENCAPSULATED_RESPONSE_ACK;
+     456                 :          1 :             spdm_encapsulated_response_ack_response->param1 = 0;
+     457                 :          1 :             spdm_encapsulated_response_ack_response->param2 =
+     458                 :            :                 SPDM_ENCAPSULATED_RESPONSE_ACK_RESPONSE_PAYLOAD_TYPE_ABSENT;
+     459                 :          1 :             sub_index = 0;
+     460                 :            :         } else {
+     461                 :          0 :             temp_buf_size = 0;
+     462                 :          0 :             temp_buf_ptr = NULL;
+     463                 :            :         }
+     464                 :          2 :         libspdm_transport_test_encode_message(spdm_context, NULL, false, false,
+     465                 :            :                                               temp_buf_size, temp_buf_ptr,
+     466                 :            :                                               response_size, response);
+     467                 :            :     }
+     468                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     469                 :            : 
+     470                 :          2 :     case 0x9:
+     471                 :            :     {
+     472                 :            :         spdm_key_update_request_t *spdm_response;
+     473                 :            : 
+     474                 :            :         ((libspdm_context_t *)spdm_context)
+     475                 :          2 :         ->connection_info.algorithm.base_hash_algo =
+     476                 :            :             m_libspdm_use_hash_algo;
+     477         [ +  + ]:          2 :         if (sub_index == 0) {
+     478                 :          1 :             temp_buf_size = sizeof(spdm_key_update_request_t) +
+     479                 :            :                             sizeof(spdm_encapsulated_request_response_t);
+     480                 :          1 :             libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
+     481                 :          1 :             temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
+     482                 :          1 :             libspdm_encapsulated_request_response = (void *)temp_buf_ptr;
+     483                 :          1 :             libspdm_encapsulated_request_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     484                 :          1 :             libspdm_encapsulated_request_response->header.request_response_code =
+     485                 :            :                 SPDM_ENCAPSULATED_REQUEST;
+     486                 :          1 :             libspdm_encapsulated_request_response->header.param1 = 0;
+     487                 :          1 :             libspdm_encapsulated_request_response->header.param2 = 0;
+     488                 :            : 
+     489                 :          1 :             spdm_response =
+     490                 :            :                 (void *)(temp_buf_ptr + sizeof(spdm_encapsulated_request_response_t));
+     491                 :          1 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     492                 :          1 :             spdm_response->header.request_response_code = SPDM_KEY_UPDATE;
+     493                 :          1 :             spdm_response->header.param1 = SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY;
+     494                 :          1 :             spdm_response->header.param2 = 0x3;
+     495                 :            : 
+     496                 :          1 :             sub_index++;
+     497         [ +  - ]:          1 :         } else if (sub_index == 1) {
+     498                 :            :             /*When the version is SPDM_MESSAGE_VERSION_12, use the following code*/
+     499                 :            :             spdm_message_header_t *spdm_encapsulated_response_ack_response;
+     500                 :          1 :             temp_buf_size = sizeof(spdm_message_header_t);
+     501                 :          1 :             libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
+     502                 :          1 :             temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
+     503                 :          1 :             spdm_encapsulated_response_ack_response = (void *)temp_buf_ptr;
+     504                 :          1 :             spdm_encapsulated_response_ack_response->spdm_version = SPDM_MESSAGE_VERSION_11;
+     505                 :          1 :             spdm_encapsulated_response_ack_response->request_response_code =
+     506                 :            :                 SPDM_ENCAPSULATED_RESPONSE_ACK;
+     507                 :          1 :             spdm_encapsulated_response_ack_response->param1 = 0;
+     508                 :          1 :             spdm_encapsulated_response_ack_response->param2 =
+     509                 :            :                 SPDM_ENCAPSULATED_RESPONSE_ACK_RESPONSE_PAYLOAD_TYPE_ABSENT;
+     510                 :          1 :             sub_index = 0;
+     511                 :            :         } else {
+     512                 :          0 :             temp_buf_size = 0;
+     513                 :          0 :             temp_buf_ptr = NULL;
+     514                 :            :         }
+     515                 :          2 :         libspdm_transport_test_encode_message(spdm_context, NULL, false, false,
+     516                 :            :                                               temp_buf_size, temp_buf_ptr,
+     517                 :            :                                               response_size, response);
+     518                 :            :     }
+     519                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     520                 :            : 
+     521                 :          2 :     case 0xA:
+     522                 :            :     {
+     523                 :            :         spdm_get_encapsulated_request_request_t *spdm_response;
+     524                 :            : 
+     525         [ +  + ]:          2 :         if (sub_index == 0) {
+     526                 :          1 :             temp_buf_size = sizeof(spdm_encapsulated_request_response_t) +
+     527                 :            :                             sizeof(spdm_get_encapsulated_request_request_t);
+     528                 :          1 :             libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
+     529                 :          1 :             temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
+     530                 :            : 
+     531                 :            :             /* The following is ENCAPSULATED_REQUEST response message */
+     532                 :          1 :             libspdm_encapsulated_request_response = (void *) temp_buf_ptr;
+     533                 :          1 :             libspdm_encapsulated_request_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     534                 :          1 :             libspdm_encapsulated_request_response->header.request_response_code =
+     535                 :            :                 SPDM_ENCAPSULATED_REQUEST;
+     536                 :          1 :             libspdm_encapsulated_request_response->header.param1 = 0;
+     537                 :          1 :             libspdm_encapsulated_request_response->header.param2 = 0;
+     538                 :            : 
+     539                 :            :             /* The following is EncapsulatedRequest Field of the above ENCAPSULATED_REQUEST response message*/
+     540                 :          1 :             spdm_response =
+     541                 :            :                 (void *)(temp_buf_ptr + sizeof(spdm_get_encapsulated_request_request_t));
+     542                 :          1 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     543                 :          1 :             spdm_response->header.request_response_code = SPDM_GET_ENCAPSULATED_REQUEST;  /* Here invalid: GET_ENCAPSULATED_REQUEST is encapsulated */
+     544                 :          1 :             spdm_response->header.param1 = 0;
+     545                 :          1 :             spdm_response->header.param2 = 0;
+     546                 :            : 
+     547                 :          1 :             sub_index++;
+     548         [ +  - ]:          1 :         } else if (sub_index == 1) {
+     549                 :            :             spdm_message_header_t *spdm_encapsulated_response_ack_response;
+     550                 :          1 :             temp_buf_size = sizeof(spdm_message_header_t);
+     551                 :          1 :             libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
+     552                 :          1 :             temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
+     553                 :          1 :             spdm_encapsulated_response_ack_response = (void *)temp_buf_ptr;
+     554                 :          1 :             spdm_encapsulated_response_ack_response->spdm_version = SPDM_MESSAGE_VERSION_11;
+     555                 :          1 :             spdm_encapsulated_response_ack_response->request_response_code =
+     556                 :            :                 SPDM_ENCAPSULATED_RESPONSE_ACK;
+     557                 :          1 :             spdm_encapsulated_response_ack_response->param1 = 0;
+     558                 :          1 :             spdm_encapsulated_response_ack_response->param2 =
+     559                 :            :                 SPDM_ENCAPSULATED_RESPONSE_ACK_RESPONSE_PAYLOAD_TYPE_ABSENT;
+     560                 :          1 :             sub_index = 0;
+     561                 :            :         } else {
+     562                 :          0 :             temp_buf_size = 0;
+     563                 :          0 :             temp_buf_ptr = NULL;
+     564                 :            :         }
+     565                 :          2 :         libspdm_transport_test_encode_message(spdm_context, NULL, false, false,
+     566                 :            :                                               temp_buf_size, temp_buf_ptr,
+     567                 :            :                                               response_size, response);
+     568                 :            :     }
+     569                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     570                 :            : 
+     571                 :          0 :     default:
+     572                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+     573                 :            :     }
+     574                 :            : }
+     575                 :            : 
+     576                 :            : #if (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_ENABLE_CAPABILITY_CERT_CAP)
+     577                 :          1 : void libspdm_test_requester_encap_request_case1(void **State)
+     578                 :            : {
+     579                 :            :     libspdm_return_t status;
+     580                 :            :     libspdm_test_context_t *spdm_test_context;
+     581                 :            :     libspdm_context_t *spdm_context;
+     582                 :            :     void *data;
+     583                 :            :     size_t data_size;
+     584                 :            :     void *hash;
+     585                 :            :     size_t hash_size;
+     586                 :            : 
+     587                 :          1 :     spdm_test_context = *State;
+     588                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     589                 :          1 :     spdm_test_context->case_id = 0x1;
+     590                 :            : 
+     591                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     592                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     593                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     594                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     595                 :          1 :     spdm_context->connection_info.capability.flags |=
+     596                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+     597                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+     598                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     599                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+     600                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+     601                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
+     602                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
+     603                 :            : 
+     604                 :          1 :     spdm_context->connection_info.capability.flags |=
+     605                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
+     606                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     607                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     608                 :            :                                                     &data_size,
+     609                 :            :                                                     &hash, &hash_size);
+     610                 :          1 :     libspdm_reset_message_a(spdm_context);
+     611                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     612                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     613                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+     614                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+     615                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     616                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+     617                 :            :         data_size;
+     618                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+     619                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+     620                 :            :                      data, data_size);
+     621                 :            : #endif
+     622                 :            : 
+     623                 :          1 :     libspdm_register_get_encap_response_func(spdm_context, libspdm_get_encap_response_digest);
+     624                 :          1 :     status = libspdm_encapsulated_request(spdm_context, NULL, 0, NULL);
+     625                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SEND_FAIL);
+     626                 :          1 :     free(data);
+     627                 :          1 : }
+     628                 :            : 
+     629                 :          1 : void libspdm_test_requester_encap_request_case2(void **State)
+     630                 :            : {
+     631                 :            :     libspdm_return_t status;
+     632                 :            :     libspdm_test_context_t *spdm_test_context;
+     633                 :            :     libspdm_context_t *spdm_context;
+     634                 :            :     void *data;
+     635                 :            :     size_t data_size;
+     636                 :            :     void *hash;
+     637                 :            :     size_t hash_size;
+     638                 :            : 
+     639                 :          1 :     spdm_test_context = *State;
+     640                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     641                 :          1 :     spdm_test_context->case_id = 0x2;
+     642                 :            : 
+     643                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     644                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     645                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     646                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     647                 :          1 :     spdm_context->connection_info.capability.flags |=
+     648                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+     649                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+     650                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     651                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+     652                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+     653                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
+     654                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
+     655                 :          1 :     spdm_context->connection_info.capability.flags |=
+     656                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
+     657                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     658                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     659                 :            :                                                     &data_size,
+     660                 :            :                                                     &hash, &hash_size);
+     661                 :          1 :     libspdm_reset_message_a(spdm_context);
+     662                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     663                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     664                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+     665                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+     666                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     667                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+     668                 :            :         data_size;
+     669                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+     670                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+     671                 :            :                      data, data_size);
+     672                 :            : #endif
+     673                 :            : 
+     674                 :          1 :     libspdm_register_get_encap_response_func(spdm_context, libspdm_get_encap_response_digest);
+     675                 :          1 :     status = libspdm_encapsulated_request(spdm_context, NULL, 0, NULL);
+     676                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     677                 :          1 :     free(data);
+     678                 :          1 : }
+     679                 :            : 
+     680                 :          1 : void libspdm_test_requester_encap_request_case3(void **State)
+     681                 :            : {
+     682                 :            :     libspdm_return_t status;
+     683                 :            :     libspdm_test_context_t *spdm_test_context;
+     684                 :            :     libspdm_context_t *spdm_context;
+     685                 :            :     void *data;
+     686                 :            :     size_t data_size;
+     687                 :            :     void *hash;
+     688                 :            :     size_t hash_size;
+     689                 :            : 
+     690                 :          1 :     spdm_test_context = *State;
+     691                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     692                 :          1 :     spdm_test_context->case_id = 0x3;
+     693                 :            : 
+     694                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     695                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     696                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     697                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     698                 :          1 :     spdm_context->connection_info.capability.flags |=
+     699                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+     700                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+     701                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     702                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+     703                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+     704                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
+     705                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
+     706                 :          1 :     spdm_context->connection_info.capability.flags |=
+     707                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
+     708                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     709                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     710                 :            :                                                     &data_size,
+     711                 :            :                                                     &hash, &hash_size);
+     712                 :          1 :     libspdm_reset_message_a(spdm_context);
+     713                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     714                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     715                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+     716                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+     717                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     718                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+     719                 :            :         data_size;
+     720                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+     721                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+     722                 :            :                      data, data_size);
+     723                 :            : #endif
+     724                 :            : 
+     725                 :          1 :     libspdm_register_get_encap_response_func(spdm_context, libspdm_get_encap_response_digest);
+     726                 :          1 :     status = libspdm_encapsulated_request(spdm_context, NULL, 0, NULL);
+     727                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
+     728                 :          1 :     free(data);
+     729                 :          1 : }
+     730                 :            : 
+     731                 :          1 : void libspdm_test_requester_encap_request_case4(void **State)
+     732                 :            : {
+     733                 :            :     libspdm_return_t status;
+     734                 :            :     libspdm_test_context_t *spdm_test_context;
+     735                 :            :     libspdm_context_t *spdm_context;
+     736                 :            :     void *data;
+     737                 :            :     size_t data_size;
+     738                 :            :     void *hash;
+     739                 :            :     size_t hash_size;
+     740                 :            : 
+     741                 :          1 :     spdm_test_context = *State;
+     742                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     743                 :          1 :     spdm_test_context->case_id = 0x4;
+     744                 :            : 
+     745                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     746                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     747                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     748                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     749                 :          1 :     spdm_context->connection_info.capability.flags |=
+     750                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+     751                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+     752                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     753                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+     754                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+     755                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
+     756                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
+     757                 :          1 :     spdm_context->connection_info.capability.flags |=
+     758                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
+     759                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     760                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     761                 :            :                                                     &data_size,
+     762                 :            :                                                     &hash, &hash_size);
+     763                 :          1 :     libspdm_reset_message_a(spdm_context);
+     764                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     765                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     766                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+     767                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+     768                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     769                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+     770                 :            :         data_size;
+     771                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+     772                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+     773                 :            :                      data, data_size);
+     774                 :            : #endif
+     775                 :            : 
+     776                 :          1 :     libspdm_register_get_encap_response_func(spdm_context, libspdm_get_encap_response_digest);
+     777                 :          1 :     status = libspdm_encapsulated_request(spdm_context, NULL, 0, NULL);
+     778                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     779                 :          1 :     free(data);
+     780                 :          1 : }
+     781                 :            : 
+     782                 :          1 : void libspdm_test_requester_encap_request_case5(void **State)
+     783                 :            : {
+     784                 :            :     libspdm_return_t status;
+     785                 :            :     libspdm_test_context_t *spdm_test_context;
+     786                 :            :     libspdm_context_t *spdm_context;
+     787                 :            :     void *data;
+     788                 :            :     size_t data_size;
+     789                 :            :     void *hash;
+     790                 :            :     size_t hash_size;
+     791                 :            : 
+     792                 :          1 :     spdm_test_context = *State;
+     793                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     794                 :          1 :     spdm_test_context->case_id = 0x5;
+     795                 :            : 
+     796                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     797                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     798                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     799                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     800                 :          1 :     spdm_context->connection_info.capability.flags |=
+     801                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+     802                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+     803                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     804                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+     805                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+     806                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
+     807                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
+     808                 :          1 :     spdm_context->connection_info.capability.flags |=
+     809                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
+     810                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     811                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     812                 :            :                                                     &data_size,
+     813                 :            :                                                     &hash, &hash_size);
+     814                 :          1 :     libspdm_reset_message_a(spdm_context);
+     815                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     816                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     817                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+     818                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+     819                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     820                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+     821                 :            :         data_size;
+     822                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+     823                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+     824                 :            :                      data, data_size);
+     825                 :            : #endif
+     826                 :            : 
+     827                 :          1 :     libspdm_register_get_encap_response_func(spdm_context, libspdm_get_encap_response_digest);
+     828                 :          1 :     status = libspdm_encapsulated_request(spdm_context, NULL, 0, NULL);
+     829                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+     830                 :          1 :     free(data);
+     831                 :          1 : }
+     832                 :            : 
+     833                 :          1 : void libspdm_test_requester_encap_request_case6(void **State)
+     834                 :            : {
+     835                 :            :     libspdm_return_t status;
+     836                 :            :     libspdm_test_context_t *spdm_test_context;
+     837                 :            :     libspdm_context_t *spdm_context;
+     838                 :            :     void *data;
+     839                 :            :     size_t data_size;
+     840                 :            :     void *hash;
+     841                 :            :     size_t hash_size;
+     842                 :            : 
+     843                 :          1 :     spdm_test_context = *State;
+     844                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     845                 :          1 :     spdm_test_context->case_id = 0x6;
+     846                 :            : 
+     847                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     848                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     849                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     850                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     851                 :          1 :     spdm_context->connection_info.capability.flags |=
+     852                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+     853                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+     854                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     855                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+     856                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+     857                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
+     858                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
+     859                 :          1 :     spdm_context->connection_info.capability.flags |=
+     860                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
+     861                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     862                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     863                 :            :                                                     &data_size,
+     864                 :            :                                                     &hash, &hash_size);
+     865                 :          1 :     libspdm_reset_message_a(spdm_context);
+     866                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     867                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     868                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+     869                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+     870                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     871                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+     872                 :            :         data_size;
+     873                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+     874                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+     875                 :            :                      data, data_size);
+     876                 :            : #endif
+     877                 :            : 
+     878                 :          1 :     libspdm_register_get_encap_response_func(spdm_context, libspdm_get_encap_response_digest);
+     879                 :          1 :     status = libspdm_encapsulated_request(spdm_context, NULL, 0, NULL);
+     880                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
+     881                 :          1 :     free(data);
+     882                 :          1 : }
+     883                 :            : 
+     884                 :          1 : void libspdm_test_requester_encap_request_case7(void **State)
+     885                 :            : {
+     886                 :            :     libspdm_return_t status;
+     887                 :            :     libspdm_test_context_t *spdm_test_context;
+     888                 :            :     libspdm_context_t *spdm_context;
+     889                 :            :     void *data;
+     890                 :            :     size_t data_size;
+     891                 :            :     void *hash;
+     892                 :            :     size_t hash_size;
+     893                 :            : 
+     894                 :          1 :     spdm_test_context = *State;
+     895                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     896                 :          1 :     spdm_test_context->case_id = 0x7;
+     897                 :            : 
+     898                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     899                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     900                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     901                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     902                 :          1 :     spdm_context->connection_info.capability.flags |=
+     903                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+     904                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+     905                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     906                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+     907                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+     908                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
+     909                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
+     910                 :          1 :     spdm_context->connection_info.capability.flags |=
+     911                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
+     912                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     913                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     914                 :            :                                                     &data_size,
+     915                 :            :                                                     &hash, &hash_size);
+     916                 :          1 :     libspdm_reset_message_a(spdm_context);
+     917                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     918                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     919                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+     920                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+     921                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     922                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+     923                 :            :         data_size;
+     924                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+     925                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+     926                 :            :                      data, data_size);
+     927                 :            : #endif
+     928                 :            : 
+     929                 :          1 :     libspdm_register_get_encap_response_func(spdm_context, libspdm_get_encap_response_digest);
+     930                 :          1 :     status = libspdm_encapsulated_request(spdm_context, NULL, 0, NULL);
+     931                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     932                 :          1 :     free(data);
+     933                 :          1 : }
+     934                 :            : 
+     935                 :          1 : void libspdm_test_requester_encap_request_case8(void **State)
+     936                 :            : {
+     937                 :            :     libspdm_return_t status;
+     938                 :            :     libspdm_test_context_t *spdm_test_context;
+     939                 :            :     libspdm_context_t *spdm_context;
+     940                 :            :     void *data;
+     941                 :            :     size_t data_size;
+     942                 :            :     void *hash;
+     943                 :            :     size_t hash_size;
+     944                 :            : 
+     945                 :          1 :     spdm_test_context = *State;
+     946                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     947                 :          1 :     spdm_test_context->case_id = 0x8;
+     948                 :            : 
+     949                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     950                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     951                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     952                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     953                 :          1 :     spdm_context->connection_info.capability.flags |=
+     954                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+     955                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+     956                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     957                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+     958                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+     959                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
+     960                 :          1 :     spdm_context->local_context.capability.flags |=
+     961                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     962                 :          1 :     spdm_context->connection_info.capability.flags |=
+     963                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
+     964                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     965                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     966                 :            :                                                     &data_size,
+     967                 :            :                                                     &hash, &hash_size);
+     968                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     969                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
+     970                 :            : 
+     971                 :          1 :     libspdm_reset_message_a(spdm_context);
+     972                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     973                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     974                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+     975                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+     976                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     977                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+     978                 :            :         data_size;
+     979                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+     980                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+     981                 :            :                      data, data_size);
+     982                 :            : #endif
+     983                 :            : 
+     984                 :          1 :     libspdm_register_get_encap_response_func(spdm_context, libspdm_get_encap_response_certificate);
+     985                 :          1 :     status = libspdm_encapsulated_request(spdm_context, NULL, 0, NULL);
+     986                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     987                 :          1 :     free(data);
+     988                 :          1 : }
+     989                 :            : #endif /* (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_ENABLE_CAPABILITY_CERT_CAP) */
+     990                 :            : 
+     991                 :          1 : void libspdm_test_requester_encap_request_case9(void **State)
+     992                 :            : {
+     993                 :            :     libspdm_return_t status;
+     994                 :            :     libspdm_test_context_t *spdm_test_context;
+     995                 :            :     libspdm_context_t *spdm_context;
+     996                 :            :     void *data;
+     997                 :            :     size_t data_size;
+     998                 :            :     void *hash;
+     999                 :            :     size_t hash_size;
+    1000                 :            : 
+    1001                 :          1 :     spdm_test_context = *State;
+    1002                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1003                 :          1 :     spdm_test_context->case_id = 0x9;
+    1004                 :            : 
+    1005                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1006                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1007                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1008                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1009                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1010                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    1011                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    1012                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1013                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    1014                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    1015                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
+    1016                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1017                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_UPD_CAP;
+    1018                 :          1 :     spdm_context->local_context.capability.flags |=
+    1019                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP;
+    1020                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1021                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
+    1022                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1023                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    1024                 :            :                                                     &data_size,
+    1025                 :            :                                                     &hash, &hash_size);
+    1026                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+    1027                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
+    1028                 :            : 
+    1029                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1030                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1031                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1032                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    1033                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    1034                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1035                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    1036                 :            :         data_size;
+    1037                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    1038                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    1039                 :            :                      data, data_size);
+    1040                 :            : #endif
+    1041                 :            : 
+    1042                 :          1 :     libspdm_register_get_encap_response_func(spdm_context, libspdm_get_encap_response_key_update);
+    1043                 :          1 :     status = libspdm_encapsulated_request(spdm_context, NULL, 0, NULL);
+    1044                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1045                 :          1 :     free(data);
+    1046                 :          1 : }
+    1047                 :            : 
+    1048                 :            : /**
+    1049                 :            :  * Test 10: GET_ENCAPSULATED_REQUEST request message is encapsulated in ENCAPSULATED_REQUEST response message.
+    1050                 :            :  * Expected Behavior: the Requester should respond with ErrorCode=UnexpectedRequest.
+    1051                 :            :  **/
+    1052                 :          1 : void libspdm_test_requester_encap_request_case10(void **State)
+    1053                 :            : {
+    1054                 :            :     libspdm_return_t status;
+    1055                 :            :     libspdm_test_context_t *spdm_test_context;
+    1056                 :            :     libspdm_context_t *spdm_context;
+    1057                 :            : 
+    1058                 :          1 :     spdm_test_context = *State;
+    1059                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1060                 :          1 :     spdm_test_context->case_id = 0xA;
+    1061                 :            : 
+    1062                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1063                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1064                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1065                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
+    1066                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1067                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
+    1068                 :            : 
+    1069                 :          1 :     libspdm_register_get_encap_response_func(spdm_context, NULL);
+    1070                 :          1 :     status = libspdm_encapsulated_request(spdm_context, NULL, 0, NULL);
+    1071                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1072                 :          1 : }
+    1073                 :            : 
+    1074                 :            : libspdm_test_context_t m_libspdm_requester_encap_request_test_context = {
+    1075                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+    1076                 :            :     true,
+    1077                 :            :     libspdm_requester_encap_request_test_send_message,
+    1078                 :            :     libspdm_requester_encap_request_test_receive_message,
+    1079                 :            : };
+    1080                 :            : 
+    1081                 :          1 : int libspdm_requester_encap_request_test_main(void)
+    1082                 :            : {
+    1083                 :          1 :     const struct CMUnitTest spdm_requester_encap_request_tests[] = {
+    1084                 :            :         /* SendRequest failed*/
+    1085                 :            : #if (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_ENABLE_CAPABILITY_CERT_CAP)
+    1086                 :            :         cmocka_unit_test(libspdm_test_requester_encap_request_case1),
+    1087                 :            :         /* Success Case ,func :libspdm_get_encap_response_digest*/
+    1088                 :            :         cmocka_unit_test(libspdm_test_requester_encap_request_case2),
+    1089                 :            :         /* Error response: When spdm_encapsulated_response_ack_response versions are inconsistent*/
+    1090                 :            :         cmocka_unit_test(libspdm_test_requester_encap_request_case3),
+    1091                 :            :         /* Error response:Receive message only SPDM ENCAPSULATED_REQUEST response*/
+    1092                 :            :         cmocka_unit_test(libspdm_test_requester_encap_request_case4),
+    1093                 :            :         /* Error response: spdm_encapsulated_response_ack_response == NULL*/
+    1094                 :            :         cmocka_unit_test(libspdm_test_requester_encap_request_case5),
+    1095                 :            :         /* Error response: spdm_encapsulated_response_ack_response.param2 == NULL*/
+    1096                 :            :         cmocka_unit_test(libspdm_test_requester_encap_request_case6),
+    1097                 :            :         /* response: param2 == SPDM_ENCAPSULATED_RESPONSE_ACK_RESPONSE_PAYLOAD_TYPE_REQ_SLOT_NUMBER*/
+    1098                 :            :         cmocka_unit_test(libspdm_test_requester_encap_request_case7),
+    1099                 :            :         /*Success Case ,func :libspdm_get_encap_response_certificate */
+    1100                 :            :         cmocka_unit_test(libspdm_test_requester_encap_request_case8),
+    1101                 :            : #endif /* (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (..) */
+    1102                 :            : 
+    1103                 :            :         /*Success Case ,func :libspdm_get_encap_response_key_update */
+    1104                 :            :         cmocka_unit_test(libspdm_test_requester_encap_request_case9),
+    1105                 :            :         /*Error response: GET_ENCAPSULATED_REQUEST message is encapsulated */
+    1106                 :            :         cmocka_unit_test(libspdm_test_requester_encap_request_case10),
+    1107                 :            :     };
+    1108                 :            : 
+    1109                 :          1 :     libspdm_setup_test_context(&m_libspdm_requester_encap_request_test_context);
+    1110                 :            : 
+    1111                 :          1 :     return cmocka_run_group_tests(spdm_requester_encap_request_tests,
+    1112                 :            :                                   libspdm_unit_test_group_setup,
+    1113                 :            :                                   libspdm_unit_test_group_teardown);
+    1114                 :            : }
+    1115                 :            : 
+    1116                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/end_session.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_requester/end_session.c.func-sort-c.html new file mode 100644 index 00000000000..88847128ac5 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/end_session.c.func-sort-c.html @@ -0,0 +1,149 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/end_session.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - end_session.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:71675495.0 %
Date:2024-09-22 08:21:07Functions:1717100.0 %
Branches:598470.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_end_session_test_main1
libspdm_test_requester_end_session_case11
libspdm_test_requester_end_session_case101
libspdm_test_requester_end_session_case111
libspdm_test_requester_end_session_case121
libspdm_test_requester_end_session_case21
libspdm_test_requester_end_session_case31
libspdm_test_requester_end_session_case41
libspdm_test_requester_end_session_case51
libspdm_test_requester_end_session_case61
libspdm_test_requester_end_session_case71
libspdm_test_requester_end_session_case81
libspdm_test_requester_end_session_case91
libspdm_secured_message_set_response_data_encryption_key28
libspdm_secured_message_set_response_data_salt28
libspdm_requester_end_session_test_receive_message30
libspdm_requester_end_session_test_send_message31
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/end_session.c.func.html b/coverage_log/unit_test/test_spdm_requester/end_session.c.func.html new file mode 100644 index 00000000000..dde5b1de165 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/end_session.c.func.html @@ -0,0 +1,149 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/end_session.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - end_session.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:71675495.0 %
Date:2024-09-22 08:21:07Functions:1717100.0 %
Branches:598470.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_end_session_test_main1
libspdm_requester_end_session_test_receive_message30
libspdm_requester_end_session_test_send_message31
libspdm_secured_message_set_response_data_encryption_key28
libspdm_secured_message_set_response_data_salt28
libspdm_test_requester_end_session_case11
libspdm_test_requester_end_session_case101
libspdm_test_requester_end_session_case111
libspdm_test_requester_end_session_case121
libspdm_test_requester_end_session_case21
libspdm_test_requester_end_session_case31
libspdm_test_requester_end_session_case41
libspdm_test_requester_end_session_case51
libspdm_test_requester_end_session_case61
libspdm_test_requester_end_session_case71
libspdm_test_requester_end_session_case81
libspdm_test_requester_end_session_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/end_session.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/end_session.c.gcov.html new file mode 100644 index 00000000000..34eeaaacc90 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/end_session.c.gcov.html @@ -0,0 +1,1866 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/end_session.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - end_session.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:71675495.0 %
Date:2024-09-22 08:21:07Functions:1717100.0 %
Branches:598470.2 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_requester_lib.h"
+       9                 :            : #include "internal/libspdm_secured_message_lib.h"
+      10                 :            : 
+      11                 :            : #if (LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP) || (LIBSPDM_ENABLE_CAPABILITY_PSK_CAP)
+      12                 :            : 
+      13                 :            : static uint8_t m_dummy_key_buffer[LIBSPDM_MAX_AEAD_KEY_SIZE];
+      14                 :            : static uint8_t m_dummy_salt_buffer[LIBSPDM_MAX_AEAD_IV_SIZE];
+      15                 :            : 
+      16                 :         28 : static void libspdm_secured_message_set_response_data_encryption_key(
+      17                 :            :     void *spdm_secured_message_context, const void *key, size_t key_size)
+      18                 :            : {
+      19                 :            :     libspdm_secured_message_context_t *secured_message_context;
+      20                 :            : 
+      21                 :         28 :     secured_message_context = spdm_secured_message_context;
+      22         [ -  + ]:         28 :     LIBSPDM_ASSERT(key_size == secured_message_context->aead_key_size);
+      23                 :         28 :     libspdm_copy_mem(secured_message_context->application_secret.response_data_encryption_key,
+      24                 :            :                      sizeof(secured_message_context->application_secret.response_data_encryption_key),
+      25                 :            :                      key, secured_message_context->aead_key_size);
+      26                 :         28 : }
+      27                 :            : 
+      28                 :         28 : static void libspdm_secured_message_set_response_data_salt(
+      29                 :            :     void *spdm_secured_message_context, const void *salt,
+      30                 :            :     size_t salt_size)
+      31                 :            : {
+      32                 :            :     libspdm_secured_message_context_t *secured_message_context;
+      33                 :            : 
+      34                 :         28 :     secured_message_context = spdm_secured_message_context;
+      35         [ -  + ]:         28 :     LIBSPDM_ASSERT(salt_size == secured_message_context->aead_iv_size);
+      36                 :         28 :     libspdm_copy_mem(secured_message_context->application_secret.response_data_salt,
+      37                 :            :                      sizeof(secured_message_context->application_secret.response_data_salt),
+      38                 :            :                      salt, secured_message_context->aead_iv_size);
+      39                 :         28 : }
+      40                 :            : 
+      41                 :         31 : libspdm_return_t libspdm_requester_end_session_test_send_message(
+      42                 :            :     void *spdm_context, size_t request_size, const void *request,
+      43                 :            :     uint64_t timeout)
+      44                 :            : {
+      45                 :            :     libspdm_test_context_t *spdm_test_context;
+      46                 :            : 
+      47                 :         31 :     spdm_test_context = libspdm_get_test_context();
+      48   [ +  +  -  +  :         31 :     switch (spdm_test_context->case_id) {
+          +  +  +  +  +  
+             +  +  +  - ]
+      49                 :          1 :     case 0x1:
+      50                 :          1 :         return LIBSPDM_STATUS_SEND_FAIL;
+      51                 :          1 :     case 0x2:
+      52                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      53                 :          0 :     case 0x3:
+      54                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      55                 :          1 :     case 0x4:
+      56                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      57                 :          1 :     case 0x5:
+      58                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      59                 :          2 :     case 0x6:
+      60                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+      61                 :          1 :     case 0x7:
+      62                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      63                 :          2 :     case 0x8:
+      64                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+      65                 :          2 :     case 0x9:
+      66                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+      67                 :         18 :     case 0xA:
+      68                 :         18 :         return LIBSPDM_STATUS_SUCCESS;
+      69                 :          1 :     case 0xB:
+      70                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      71                 :          1 :     case 0xC:
+      72                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      73                 :          0 :     default:
+      74                 :          0 :         return LIBSPDM_STATUS_SEND_FAIL;
+      75                 :            :     }
+      76                 :            : }
+      77                 :            : 
+      78                 :         30 : libspdm_return_t libspdm_requester_end_session_test_receive_message(
+      79                 :            :     void *spdm_context, size_t *response_size,
+      80                 :            :     void **response, uint64_t timeout)
+      81                 :            : {
+      82                 :            :     libspdm_test_context_t *spdm_test_context;
+      83                 :            : 
+      84                 :         30 :     spdm_test_context = libspdm_get_test_context();
+      85   [ -  +  -  +  :         30 :     switch (spdm_test_context->case_id) {
+          +  +  +  +  +  
+             +  +  +  - ]
+      86                 :          0 :     case 0x1:
+      87                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+      88                 :            : 
+      89                 :          1 :     case 0x2: {
+      90                 :            :         spdm_end_session_response_t *spdm_response;
+      91                 :            :         size_t spdm_response_size;
+      92                 :            :         size_t transport_header_size;
+      93                 :            :         uint32_t session_id;
+      94                 :            :         libspdm_session_info_t *session_info;
+      95                 :            :         uint8_t *scratch_buffer;
+      96                 :            :         size_t scratch_buffer_size;
+      97                 :            : 
+      98                 :          1 :         session_id = 0xFFFFFFFF;
+      99                 :          1 :         spdm_response_size = sizeof(spdm_end_session_response_t);
+     100                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     101                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     102                 :            : 
+     103                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     104                 :          1 :         spdm_response->header.request_response_code =
+     105                 :            :             SPDM_END_SESSION_ACK;
+     106                 :          1 :         spdm_response->header.param1 = 0;
+     107                 :          1 :         spdm_response->header.param2 = 0;
+     108                 :            : 
+     109                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+     110                 :            :          * transport_message is always in sender buffer. */
+     111                 :          1 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+     112                 :          1 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+     113                 :            :                           scratch_buffer_size - transport_header_size,
+     114                 :            :                           spdm_response, spdm_response_size);
+     115                 :          1 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+     116                 :          1 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+     117                 :            :                                               false, false, spdm_response_size,
+     118                 :            :                                               spdm_response, response_size,
+     119                 :            :                                               response);
+     120                 :          1 :         session_info = libspdm_get_session_info_via_session_id(
+     121                 :            :             spdm_context, session_id);
+     122         [ -  + ]:          1 :         if (session_info == NULL) {
+     123                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+     124                 :            :         }
+     125                 :            :         /* WALKAROUND: If just use single context to encode message and then decode message */
+     126                 :            :         ((libspdm_secured_message_context_t
+     127                 :          1 :           *)(session_info->secured_message_context))
+     128                 :          1 :         ->application_secret.response_data_sequence_number--;
+     129                 :            :     }
+     130                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     131                 :            : 
+     132                 :          0 :     case 0x3: {
+     133                 :            :         spdm_end_session_response_t *spdm_response;
+     134                 :            :         size_t spdm_response_size;
+     135                 :            :         size_t transport_header_size;
+     136                 :            :         uint32_t session_id;
+     137                 :            :         libspdm_session_info_t *session_info;
+     138                 :            :         uint8_t *scratch_buffer;
+     139                 :            :         size_t scratch_buffer_size;
+     140                 :            : 
+     141                 :          0 :         session_id = 0xFFFFFFFF;
+     142                 :          0 :         spdm_response_size = sizeof(spdm_end_session_response_t);
+     143                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     144                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     145                 :            : 
+     146                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     147                 :          0 :         spdm_response->header.request_response_code =
+     148                 :            :             SPDM_END_SESSION_ACK;
+     149                 :          0 :         spdm_response->header.param1 = 0;
+     150                 :          0 :         spdm_response->header.param2 = 0;
+     151                 :            : 
+     152                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+     153                 :            :          * transport_message is always in sender buffer. */
+     154                 :          0 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+     155                 :          0 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+     156                 :            :                           scratch_buffer_size - transport_header_size,
+     157                 :            :                           spdm_response, spdm_response_size);
+     158                 :          0 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+     159                 :          0 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+     160                 :            :                                               false, false, spdm_response_size,
+     161                 :            :                                               spdm_response, response_size,
+     162                 :            :                                               response);
+     163                 :          0 :         session_info = libspdm_get_session_info_via_session_id(
+     164                 :            :             spdm_context, session_id);
+     165         [ #  # ]:          0 :         if (session_info == NULL) {
+     166                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+     167                 :            :         }
+     168                 :            :         ((libspdm_secured_message_context_t
+     169                 :          0 :           *)(session_info->secured_message_context))
+     170                 :          0 :         ->application_secret.response_data_sequence_number--;
+     171                 :            :     }
+     172                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     173                 :            : 
+     174                 :          1 :     case 0x4: {
+     175                 :            :         spdm_error_response_t *spdm_response;
+     176                 :            :         size_t spdm_response_size;
+     177                 :            :         size_t transport_header_size;
+     178                 :            :         uint32_t session_id;
+     179                 :            :         libspdm_session_info_t *session_info;
+     180                 :            :         uint8_t *scratch_buffer;
+     181                 :            :         size_t scratch_buffer_size;
+     182                 :            : 
+     183                 :          1 :         spdm_response_size = sizeof(spdm_error_response_t);
+     184                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     185                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     186                 :            : 
+     187                 :          1 :         session_id = 0xFFFFFFFF;
+     188                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     189                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     190                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_INVALID_REQUEST;
+     191                 :          1 :         spdm_response->header.param2 = 0;
+     192                 :            : 
+     193                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+     194                 :            :          * transport_message is always in sender buffer. */
+     195                 :          1 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+     196                 :          1 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+     197                 :            :                           scratch_buffer_size - transport_header_size,
+     198                 :            :                           spdm_response, spdm_response_size);
+     199                 :          1 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+     200                 :          1 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+     201                 :            :                                               false, false,
+     202                 :            :                                               spdm_response_size,
+     203                 :            :                                               spdm_response,
+     204                 :            :                                               response_size, response);
+     205                 :          1 :         session_info = libspdm_get_session_info_via_session_id(
+     206                 :            :             spdm_context, session_id);
+     207         [ -  + ]:          1 :         if (session_info == NULL) {
+     208                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+     209                 :            :         }
+     210                 :            :         ((libspdm_secured_message_context_t
+     211                 :          1 :           *)(session_info->secured_message_context))
+     212                 :          1 :         ->application_secret.response_data_sequence_number--;
+     213                 :            :     }
+     214                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     215                 :            : 
+     216                 :          1 :     case 0x5: {
+     217                 :            :         spdm_error_response_t *spdm_response;
+     218                 :            :         size_t spdm_response_size;
+     219                 :            :         size_t transport_header_size;
+     220                 :            :         uint32_t session_id;
+     221                 :            :         libspdm_session_info_t *session_info;
+     222                 :            :         uint8_t *scratch_buffer;
+     223                 :            :         size_t scratch_buffer_size;
+     224                 :            : 
+     225                 :          1 :         spdm_response_size = sizeof(spdm_error_response_t);
+     226                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     227                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     228                 :            : 
+     229                 :          1 :         session_id = 0xFFFFFFFF;
+     230                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     231                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     232                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
+     233                 :          1 :         spdm_response->header.param2 = 0;
+     234                 :            : 
+     235                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+     236                 :            :          * transport_message is always in sender buffer. */
+     237                 :          1 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+     238                 :          1 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+     239                 :            :                           scratch_buffer_size - transport_header_size,
+     240                 :            :                           spdm_response, spdm_response_size);
+     241                 :          1 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+     242                 :          1 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+     243                 :            :                                               false, false,
+     244                 :            :                                               spdm_response_size,
+     245                 :            :                                               spdm_response,
+     246                 :            :                                               response_size, response);
+     247                 :          1 :         session_info = libspdm_get_session_info_via_session_id(
+     248                 :            :             spdm_context, session_id);
+     249         [ -  + ]:          1 :         if (session_info == NULL) {
+     250                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+     251                 :            :         }
+     252                 :            :         ((libspdm_secured_message_context_t
+     253                 :          1 :           *)(session_info->secured_message_context))
+     254                 :          1 :         ->application_secret.response_data_sequence_number--;
+     255                 :            :     }
+     256                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     257                 :            : 
+     258                 :          2 :     case 0x6: {
+     259                 :            :         static size_t sub_index1 = 0;
+     260         [ +  + ]:          2 :         if (sub_index1 == 0) {
+     261                 :            :             spdm_error_response_t *spdm_response;
+     262                 :            :             size_t spdm_response_size;
+     263                 :            :             size_t transport_header_size;
+     264                 :            :             uint32_t session_id;
+     265                 :            :             libspdm_session_info_t *session_info;
+     266                 :            :             uint8_t *scratch_buffer;
+     267                 :            :             size_t scratch_buffer_size;
+     268                 :            : 
+     269                 :          1 :             spdm_response_size = sizeof(spdm_error_response_t);
+     270                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     271                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     272                 :            : 
+     273                 :          1 :             session_id = 0xFFFFFFFF;
+     274                 :          1 :             spdm_response->header.spdm_version =
+     275                 :            :                 SPDM_MESSAGE_VERSION_11;
+     276                 :          1 :             spdm_response->header.request_response_code = SPDM_ERROR;
+     277                 :          1 :             spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
+     278                 :          1 :             spdm_response->header.param2 = 0;
+     279                 :            : 
+     280                 :            :             /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+     281                 :            :              * transport_message is always in sender buffer. */
+     282                 :          1 :             libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+     283                 :            :                                         &scratch_buffer_size);
+     284                 :          1 :             libspdm_copy_mem (scratch_buffer + transport_header_size,
+     285                 :            :                               scratch_buffer_size - transport_header_size,
+     286                 :            :                               spdm_response, spdm_response_size);
+     287                 :          1 :             spdm_response = (void *)(scratch_buffer + transport_header_size);
+     288                 :          1 :             libspdm_transport_test_encode_message(
+     289                 :            :                 spdm_context, &session_id, false, false,
+     290                 :            :                 spdm_response_size, spdm_response,
+     291                 :            :                 response_size, response);
+     292                 :          1 :             sub_index1++;
+     293                 :          1 :             session_info = libspdm_get_session_info_via_session_id(
+     294                 :            :                 spdm_context, session_id);
+     295         [ -  + ]:          1 :             if (session_info == NULL) {
+     296                 :          0 :                 return LIBSPDM_STATUS_RECEIVE_FAIL;
+     297                 :            :             }
+     298                 :            :             ((libspdm_secured_message_context_t
+     299                 :          1 :               *)(session_info->secured_message_context))
+     300                 :            :             ->application_secret
+     301                 :          1 :             .response_data_sequence_number--;
+     302         [ +  - ]:          1 :         } else if (sub_index1 == 1) {
+     303                 :            :             spdm_end_session_response_t *spdm_response;
+     304                 :            :             size_t spdm_response_size;
+     305                 :            :             size_t transport_header_size;
+     306                 :            :             uint32_t session_id;
+     307                 :            :             libspdm_session_info_t *session_info;
+     308                 :            :             uint8_t *scratch_buffer;
+     309                 :            :             size_t scratch_buffer_size;
+     310                 :            : 
+     311                 :          1 :             session_id = 0xFFFFFFFF;
+     312                 :          1 :             spdm_response_size = sizeof(spdm_end_session_response_t);
+     313                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     314                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     315                 :            : 
+     316                 :          1 :             spdm_response->header.spdm_version =
+     317                 :            :                 SPDM_MESSAGE_VERSION_11;
+     318                 :          1 :             spdm_response->header.request_response_code =
+     319                 :            :                 SPDM_END_SESSION_ACK;
+     320                 :          1 :             spdm_response->header.param1 = 0;
+     321                 :          1 :             spdm_response->header.param2 = 0;
+     322                 :            : 
+     323                 :            :             /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+     324                 :            :              * transport_message is always in sender buffer. */
+     325                 :          1 :             libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+     326                 :            :                                         &scratch_buffer_size);
+     327                 :          1 :             libspdm_copy_mem (scratch_buffer + transport_header_size,
+     328                 :            :                               scratch_buffer_size - transport_header_size,
+     329                 :            :                               spdm_response, spdm_response_size);
+     330                 :          1 :             spdm_response = (void *)(scratch_buffer + transport_header_size);
+     331                 :          1 :             libspdm_transport_test_encode_message(
+     332                 :            :                 spdm_context, &session_id, false, false,
+     333                 :            :                 spdm_response_size, spdm_response, response_size,
+     334                 :            :                 response);
+     335                 :          1 :             session_info = libspdm_get_session_info_via_session_id(
+     336                 :            :                 spdm_context, session_id);
+     337         [ -  + ]:          1 :             if (session_info == NULL) {
+     338                 :          0 :                 return LIBSPDM_STATUS_RECEIVE_FAIL;
+     339                 :            :             }
+     340                 :            :             ((libspdm_secured_message_context_t
+     341                 :          1 :               *)(session_info->secured_message_context))
+     342                 :            :             ->application_secret
+     343                 :          1 :             .response_data_sequence_number--;
+     344                 :            :         }
+     345                 :            :     }
+     346                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     347                 :            : 
+     348                 :          1 :     case 0x7: {
+     349                 :            :         spdm_error_response_t *spdm_response;
+     350                 :            :         size_t spdm_response_size;
+     351                 :            :         size_t transport_header_size;
+     352                 :            :         uint32_t session_id;
+     353                 :            :         libspdm_session_info_t *session_info;
+     354                 :            :         uint8_t *scratch_buffer;
+     355                 :            :         size_t scratch_buffer_size;
+     356                 :            : 
+     357                 :          1 :         spdm_response_size = sizeof(spdm_error_response_t);
+     358                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     359                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     360                 :            : 
+     361                 :          1 :         session_id = 0xFFFFFFFF;
+     362                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     363                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     364                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_REQUEST_RESYNCH;
+     365                 :          1 :         spdm_response->header.param2 = 0;
+     366                 :            : 
+     367                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+     368                 :            :          * transport_message is always in sender buffer. */
+     369                 :          1 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+     370                 :          1 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+     371                 :            :                           scratch_buffer_size - transport_header_size,
+     372                 :            :                           spdm_response, spdm_response_size);
+     373                 :          1 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+     374                 :          1 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+     375                 :            :                                               false, false,
+     376                 :            :                                               spdm_response_size,
+     377                 :            :                                               spdm_response,
+     378                 :            :                                               response_size, response);
+     379                 :          1 :         session_info = libspdm_get_session_info_via_session_id(
+     380                 :            :             spdm_context, session_id);
+     381         [ -  + ]:          1 :         if (session_info == NULL) {
+     382                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+     383                 :            :         }
+     384                 :            :         ((libspdm_secured_message_context_t
+     385                 :          1 :           *)(session_info->secured_message_context))
+     386                 :          1 :         ->application_secret.response_data_sequence_number--;
+     387                 :            :     }
+     388                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     389                 :            : 
+     390                 :          2 :     case 0x8: {
+     391                 :            :         spdm_error_response_data_response_not_ready_t *spdm_response;
+     392                 :            :         size_t spdm_response_size;
+     393                 :            :         size_t transport_header_size;
+     394                 :            :         uint32_t session_id;
+     395                 :            :         libspdm_session_info_t *session_info;
+     396                 :            :         uint8_t *scratch_buffer;
+     397                 :            :         size_t scratch_buffer_size;
+     398                 :            : 
+     399                 :          2 :         spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
+     400                 :          2 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     401                 :          2 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     402                 :            : 
+     403                 :          2 :         session_id = 0xFFFFFFFF;
+     404                 :          2 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     405                 :          2 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     406                 :          2 :         spdm_response->header.param1 =
+     407                 :            :             SPDM_ERROR_CODE_RESPONSE_NOT_READY;
+     408                 :          2 :         spdm_response->header.param2 = 0;
+     409                 :          2 :         spdm_response->extend_error_data.rd_exponent = 1;
+     410                 :          2 :         spdm_response->extend_error_data.rd_tm = 2;
+     411                 :          2 :         spdm_response->extend_error_data.request_code = SPDM_END_SESSION;
+     412                 :          2 :         spdm_response->extend_error_data.token = 0;
+     413                 :            : 
+     414                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+     415                 :            :          * transport_message is always in sender buffer. */
+     416                 :          2 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+     417                 :          2 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+     418                 :            :                           scratch_buffer_size - transport_header_size,
+     419                 :            :                           spdm_response, spdm_response_size);
+     420                 :          2 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+     421                 :          2 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+     422                 :            :                                               false, false,
+     423                 :            :                                               spdm_response_size,
+     424                 :            :                                               spdm_response,
+     425                 :            :                                               response_size, response);
+     426                 :          2 :         session_info = libspdm_get_session_info_via_session_id(
+     427                 :            :             spdm_context, session_id);
+     428         [ -  + ]:          2 :         if (session_info == NULL) {
+     429                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+     430                 :            :         }
+     431                 :            :         ((libspdm_secured_message_context_t
+     432                 :          2 :           *)(session_info->secured_message_context))
+     433                 :          2 :         ->application_secret.response_data_sequence_number--;
+     434                 :            :     }
+     435                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     436                 :            : 
+     437                 :          2 :     case 0x9: {
+     438                 :            :         static size_t sub_index2 = 0;
+     439         [ +  + ]:          2 :         if (sub_index2 == 0) {
+     440                 :            :             spdm_error_response_data_response_not_ready_t
+     441                 :            :             *spdm_response;
+     442                 :            :             size_t spdm_response_size;
+     443                 :            :             size_t transport_header_size;
+     444                 :            :             uint32_t session_id;
+     445                 :            :             libspdm_session_info_t *session_info;
+     446                 :            :             uint8_t *scratch_buffer;
+     447                 :            :             size_t scratch_buffer_size;
+     448                 :            : 
+     449                 :          1 :             spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
+     450                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     451                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     452                 :            : 
+     453                 :          1 :             session_id = 0xFFFFFFFF;
+     454                 :          1 :             spdm_response->header.spdm_version =
+     455                 :            :                 SPDM_MESSAGE_VERSION_11;
+     456                 :          1 :             spdm_response->header.request_response_code = SPDM_ERROR;
+     457                 :          1 :             spdm_response->header.param1 =
+     458                 :            :                 SPDM_ERROR_CODE_RESPONSE_NOT_READY;
+     459                 :          1 :             spdm_response->header.param2 = 0;
+     460                 :          1 :             spdm_response->extend_error_data.rd_exponent = 1;
+     461                 :          1 :             spdm_response->extend_error_data.rd_tm = 2;
+     462                 :          1 :             spdm_response->extend_error_data.request_code =
+     463                 :            :                 SPDM_END_SESSION;
+     464                 :          1 :             spdm_response->extend_error_data.token = 1;
+     465                 :            : 
+     466                 :            :             /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+     467                 :            :              * transport_message is always in sender buffer. */
+     468                 :          1 :             libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+     469                 :            :                                         &scratch_buffer_size);
+     470                 :          1 :             libspdm_copy_mem (scratch_buffer + transport_header_size,
+     471                 :            :                               scratch_buffer_size - transport_header_size,
+     472                 :            :                               spdm_response, spdm_response_size);
+     473                 :          1 :             spdm_response = (void *)(scratch_buffer + transport_header_size);
+     474                 :          1 :             libspdm_transport_test_encode_message(
+     475                 :            :                 spdm_context, &session_id, false, false,
+     476                 :            :                 spdm_response_size, spdm_response,
+     477                 :            :                 response_size, response);
+     478                 :          1 :             sub_index2++;
+     479                 :          1 :             session_info = libspdm_get_session_info_via_session_id(
+     480                 :            :                 spdm_context, session_id);
+     481         [ -  + ]:          1 :             if (session_info == NULL) {
+     482                 :          0 :                 return LIBSPDM_STATUS_RECEIVE_FAIL;
+     483                 :            :             }
+     484                 :            :             ((libspdm_secured_message_context_t
+     485                 :          1 :               *)(session_info->secured_message_context))
+     486                 :            :             ->application_secret
+     487                 :          1 :             .response_data_sequence_number--;
+     488         [ +  - ]:          1 :         } else if (sub_index2 == 1) {
+     489                 :            :             spdm_end_session_response_t *spdm_response;
+     490                 :            :             size_t spdm_response_size;
+     491                 :            :             size_t transport_header_size;
+     492                 :            :             uint32_t session_id;
+     493                 :            :             libspdm_session_info_t *session_info;
+     494                 :            :             uint8_t *scratch_buffer;
+     495                 :            :             size_t scratch_buffer_size;
+     496                 :            : 
+     497                 :          1 :             session_id = 0xFFFFFFFF;
+     498                 :          1 :             spdm_response_size = sizeof(spdm_end_session_response_t);
+     499                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     500                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     501                 :            : 
+     502                 :          1 :             spdm_response->header.spdm_version =
+     503                 :            :                 SPDM_MESSAGE_VERSION_11;
+     504                 :          1 :             spdm_response->header.request_response_code =
+     505                 :            :                 SPDM_END_SESSION_ACK;
+     506                 :          1 :             spdm_response->header.param1 = 0;
+     507                 :          1 :             spdm_response->header.param2 = 0;
+     508                 :            : 
+     509                 :            :             /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+     510                 :            :              * transport_message is always in sender buffer. */
+     511                 :          1 :             libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+     512                 :            :                                         &scratch_buffer_size);
+     513                 :          1 :             libspdm_copy_mem (scratch_buffer + transport_header_size,
+     514                 :            :                               scratch_buffer_size - transport_header_size,
+     515                 :            :                               spdm_response, spdm_response_size);
+     516                 :          1 :             spdm_response = (void *)(scratch_buffer + transport_header_size);
+     517                 :          1 :             libspdm_transport_test_encode_message(
+     518                 :            :                 spdm_context, &session_id, false, false,
+     519                 :            :                 spdm_response_size, spdm_response, response_size,
+     520                 :            :                 response);
+     521                 :          1 :             session_info = libspdm_get_session_info_via_session_id(
+     522                 :            :                 spdm_context, session_id);
+     523         [ -  + ]:          1 :             if (session_info == NULL) {
+     524                 :          0 :                 return LIBSPDM_STATUS_RECEIVE_FAIL;
+     525                 :            :             }
+     526                 :            :             ((libspdm_secured_message_context_t
+     527                 :          1 :               *)(session_info->secured_message_context))
+     528                 :            :             ->application_secret
+     529                 :          1 :             .response_data_sequence_number--;
+     530                 :            :         }
+     531                 :            :     }
+     532                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     533                 :            : 
+     534                 :         18 :     case 0xA:
+     535                 :            :     {
+     536                 :            :         static uint16_t error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
+     537                 :            : 
+     538                 :            :         spdm_error_response_t *spdm_response;
+     539                 :            :         size_t spdm_response_size;
+     540                 :            :         size_t transport_header_size;
+     541                 :            :         uint32_t session_id;
+     542                 :            :         libspdm_session_info_t      *session_info;
+     543                 :            :         uint8_t *scratch_buffer;
+     544                 :            :         size_t scratch_buffer_size;
+     545                 :            : 
+     546                 :         18 :         spdm_response_size = sizeof(spdm_error_response_t);
+     547                 :         18 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     548                 :         18 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     549                 :            : 
+     550                 :         18 :         session_id = 0xFFFFFFFF;
+     551                 :            : 
+     552         [ +  - ]:         18 :         if(error_code <= 0xff) {
+     553                 :         18 :             libspdm_zero_mem (spdm_response, spdm_response_size);
+     554                 :         18 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     555                 :         18 :             spdm_response->header.request_response_code = SPDM_ERROR;
+     556                 :         18 :             spdm_response->header.param1 = (uint8_t) error_code;
+     557                 :         18 :             spdm_response->header.param2 = 0;
+     558                 :            : 
+     559                 :            :             /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+     560                 :            :              * transport_message is always in sender buffer. */
+     561                 :         18 :             libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+     562                 :            :                                         &scratch_buffer_size);
+     563                 :         18 :             libspdm_copy_mem (scratch_buffer + transport_header_size,
+     564                 :            :                               scratch_buffer_size - transport_header_size,
+     565                 :            :                               spdm_response, spdm_response_size);
+     566                 :         18 :             spdm_response = (void *)(scratch_buffer + transport_header_size);
+     567                 :         18 :             libspdm_transport_test_encode_message (spdm_context, &session_id, false, false,
+     568                 :            :                                                    spdm_response_size, spdm_response,
+     569                 :            :                                                    response_size, response);
+     570                 :         18 :             session_info = libspdm_get_session_info_via_session_id (spdm_context, session_id);
+     571                 :         18 :             ((libspdm_secured_message_context_t*)(session_info->secured_message_context))->
+     572                 :         18 :             application_secret.response_data_sequence_number--;
+     573                 :            :         }
+     574                 :            : 
+     575                 :         18 :         error_code++;
+     576         [ +  + ]:         18 :         if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
+     577                 :          1 :             error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
+     578                 :            :         }
+     579         [ +  + ]:         18 :         if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) { /*skip some reserved error codes (0d to 3e)*/
+     580                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
+     581                 :            :         }
+     582         [ +  + ]:         18 :         if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) { /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
+     583                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
+     584                 :            :         }
+     585                 :            :     }
+     586                 :         18 :         return LIBSPDM_STATUS_SUCCESS;
+     587                 :          1 :     case 0xB: {
+     588                 :            :         spdm_end_session_response_t *spdm_response;
+     589                 :            :         size_t spdm_response_size;
+     590                 :            :         size_t transport_header_size;
+     591                 :            :         uint32_t session_id;
+     592                 :            :         libspdm_session_info_t *session_info;
+     593                 :            :         uint8_t *scratch_buffer;
+     594                 :            :         size_t scratch_buffer_size;
+     595                 :            : 
+     596                 :          1 :         session_id = 0xFFFFFFFF;
+     597                 :          1 :         spdm_response_size = sizeof(spdm_end_session_response_t);
+     598                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     599                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     600                 :            : 
+     601                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     602                 :          1 :         spdm_response->header.request_response_code =
+     603                 :            :             SPDM_END_SESSION_ACK;
+     604                 :          1 :         spdm_response->header.param1 = 0;
+     605                 :          1 :         spdm_response->header.param2 = 0;
+     606                 :            : 
+     607                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+     608                 :            :          * transport_message is always in sender buffer. */
+     609                 :          1 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+     610                 :          1 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+     611                 :            :                           scratch_buffer_size - transport_header_size,
+     612                 :            :                           spdm_response, spdm_response_size);
+     613                 :          1 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+     614                 :          1 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+     615                 :            :                                               false, false, spdm_response_size,
+     616                 :            :                                               spdm_response, response_size,
+     617                 :            :                                               response);
+     618                 :          1 :         session_info = libspdm_get_session_info_via_session_id(
+     619                 :            :             spdm_context, session_id);
+     620         [ -  + ]:          1 :         if (session_info == NULL) {
+     621                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+     622                 :            :         }
+     623                 :            :         /* WALKAROUND: If just use single context to encode message and then decode message */
+     624                 :            :         ((libspdm_secured_message_context_t
+     625                 :          1 :           *)(session_info->secured_message_context))
+     626                 :          1 :         ->application_secret.response_data_sequence_number--;
+     627                 :            :     }
+     628                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     629                 :          1 :     case 0xC: {
+     630                 :            :         spdm_error_response_t *spdm_response;
+     631                 :            :         size_t spdm_response_size;
+     632                 :            :         size_t transport_header_size;
+     633                 :            :         uint32_t session_id;
+     634                 :            :         libspdm_session_info_t *session_info;
+     635                 :            :         uint8_t *scratch_buffer;
+     636                 :            :         size_t scratch_buffer_size;
+     637                 :            : 
+     638                 :          1 :         spdm_response_size = sizeof(spdm_error_response_t);
+     639                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     640                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     641                 :            : 
+     642                 :          1 :         session_id = 0xFFFFFFFF;
+     643                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     644                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     645                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_DECRYPT_ERROR;
+     646                 :          1 :         spdm_response->header.param2 = 0;
+     647                 :            : 
+     648                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+     649                 :            :          * transport_message is always in sender buffer. */
+     650                 :          1 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+     651                 :          1 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+     652                 :            :                           scratch_buffer_size - transport_header_size,
+     653                 :            :                           spdm_response, spdm_response_size);
+     654                 :          1 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+     655                 :          1 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+     656                 :            :                                               false, false,
+     657                 :            :                                               spdm_response_size,
+     658                 :            :                                               spdm_response,
+     659                 :            :                                               response_size, response);
+     660                 :          1 :         session_info = libspdm_get_session_info_via_session_id(
+     661                 :            :             spdm_context, session_id);
+     662         [ -  + ]:          1 :         if (session_info == NULL) {
+     663                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+     664                 :            :         }
+     665                 :            :         ((libspdm_secured_message_context_t
+     666                 :          1 :           *)(session_info->secured_message_context))
+     667                 :          1 :         ->application_secret.response_data_sequence_number--;
+     668                 :            :     }
+     669                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     670                 :            : 
+     671                 :          0 :     default:
+     672                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+     673                 :            :     }
+     674                 :            : }
+     675                 :            : 
+     676                 :          1 : void libspdm_test_requester_end_session_case1(void **state)
+     677                 :            : {
+     678                 :            :     libspdm_return_t status;
+     679                 :            :     libspdm_test_context_t *spdm_test_context;
+     680                 :            :     libspdm_context_t *spdm_context;
+     681                 :            :     uint32_t session_id;
+     682                 :            :     void *data;
+     683                 :            :     size_t data_size;
+     684                 :            :     void *hash;
+     685                 :            :     size_t hash_size;
+     686                 :            :     libspdm_session_info_t *session_info;
+     687                 :            : 
+     688                 :          1 :     spdm_test_context = *state;
+     689                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     690                 :          1 :     spdm_test_context->case_id = 0x1;
+     691                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     692                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     693                 :          1 :     spdm_context->connection_info.connection_state =
+     694                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     695                 :          1 :     spdm_context->connection_info.capability.flags |=
+     696                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     697                 :          1 :     spdm_context->connection_info.capability.flags |=
+     698                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+     699                 :          1 :     spdm_context->connection_info.capability.flags |=
+     700                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+     701                 :          1 :     spdm_context->local_context.capability.flags |=
+     702                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     703                 :          1 :     spdm_context->local_context.capability.flags |=
+     704                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+     705                 :          1 :     spdm_context->local_context.capability.flags |=
+     706                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+     707                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     708                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     709                 :            :                                                     &data_size, &hash, &hash_size);
+     710                 :          1 :     libspdm_reset_message_a(spdm_context);
+     711                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     712                 :            :         m_libspdm_use_hash_algo;
+     713                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     714                 :            :         m_libspdm_use_asym_algo;
+     715                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     716                 :            :         m_libspdm_use_dhe_algo;
+     717                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     718                 :            :         m_libspdm_use_aead_algo;
+     719                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     720                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+     721                 :            :         data_size;
+     722                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+     723                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+     724                 :            :                      data, data_size);
+     725                 :            : #endif
+     726                 :            : 
+     727                 :          1 :     session_id = 0xFFFFFFFF;
+     728                 :          1 :     session_info = &spdm_context->session_info[0];
+     729                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+     730                 :          1 :     libspdm_secured_message_set_session_state(
+     731                 :            :         session_info->secured_message_context,
+     732                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+     733                 :            : 
+     734                 :          1 :     status = libspdm_send_receive_end_session(spdm_context, session_id, 0);
+     735                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SEND_FAIL);
+     736                 :          1 :     free(data);
+     737                 :          1 : }
+     738                 :            : 
+     739                 :          1 : void libspdm_test_requester_end_session_case2(void **state)
+     740                 :            : {
+     741                 :            :     libspdm_return_t status;
+     742                 :            :     libspdm_test_context_t *spdm_test_context;
+     743                 :            :     libspdm_context_t *spdm_context;
+     744                 :            :     uint32_t session_id;
+     745                 :            :     void *data;
+     746                 :            :     size_t data_size;
+     747                 :            :     void *hash;
+     748                 :            :     size_t hash_size;
+     749                 :            :     libspdm_session_info_t *session_info;
+     750                 :            : 
+     751                 :          1 :     spdm_test_context = *state;
+     752                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     753                 :          1 :     spdm_test_context->case_id = 0x2;
+     754                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     755                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     756                 :          1 :     spdm_context->connection_info.connection_state =
+     757                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     758                 :          1 :     spdm_context->connection_info.capability.flags |=
+     759                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     760                 :          1 :     spdm_context->connection_info.capability.flags |=
+     761                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+     762                 :          1 :     spdm_context->connection_info.capability.flags |=
+     763                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+     764                 :          1 :     spdm_context->local_context.capability.flags |=
+     765                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     766                 :          1 :     spdm_context->local_context.capability.flags |=
+     767                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+     768                 :          1 :     spdm_context->local_context.capability.flags |=
+     769                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+     770                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     771                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     772                 :            :                                                     &data_size, &hash, &hash_size);
+     773                 :          1 :     libspdm_reset_message_a(spdm_context);
+     774                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     775                 :            :         m_libspdm_use_hash_algo;
+     776                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     777                 :            :         m_libspdm_use_asym_algo;
+     778                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     779                 :            :         m_libspdm_use_dhe_algo;
+     780                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     781                 :            :         m_libspdm_use_aead_algo;
+     782                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     783                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+     784                 :            :         data_size;
+     785                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+     786                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+     787                 :            :                      data, data_size);
+     788                 :            : #endif
+     789                 :            : 
+     790                 :          1 :     session_id = 0xFFFFFFFF;
+     791                 :          1 :     session_info = &spdm_context->session_info[0];
+     792                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+     793                 :          1 :     libspdm_secured_message_set_session_state(
+     794                 :            :         session_info->secured_message_context,
+     795                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+     796                 :          1 :     libspdm_set_mem(m_dummy_key_buffer,
+     797                 :            :                     ((libspdm_secured_message_context_t
+     798                 :          1 :                       *)(session_info->secured_message_context))
+     799                 :            :                     ->aead_key_size,
+     800                 :            :                     (uint8_t)(0xFF));
+     801                 :          1 :     libspdm_secured_message_set_response_data_encryption_key(
+     802                 :            :         session_info->secured_message_context, m_dummy_key_buffer,
+     803                 :            :         ((libspdm_secured_message_context_t
+     804                 :          1 :           *)(session_info->secured_message_context))
+     805                 :            :         ->aead_key_size);
+     806                 :          1 :     libspdm_set_mem(m_dummy_salt_buffer,
+     807                 :            :                     ((libspdm_secured_message_context_t
+     808                 :          1 :                       *)(session_info->secured_message_context))
+     809                 :            :                     ->aead_iv_size,
+     810                 :            :                     (uint8_t)(0xFF));
+     811                 :          1 :     libspdm_secured_message_set_response_data_salt(
+     812                 :            :         session_info->secured_message_context, m_dummy_salt_buffer,
+     813                 :            :         ((libspdm_secured_message_context_t
+     814                 :          1 :           *)(session_info->secured_message_context))
+     815                 :            :         ->aead_iv_size);
+     816                 :            :     ((libspdm_secured_message_context_t *)(session_info
+     817                 :          1 :                                            ->secured_message_context))
+     818                 :          1 :     ->application_secret.response_data_sequence_number = 0;
+     819                 :            : 
+     820                 :          1 :     status = libspdm_send_receive_end_session(spdm_context, session_id, 0);
+     821                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     822                 :          1 :     assert_int_equal(
+     823                 :            :         libspdm_secured_message_get_session_state(
+     824                 :            :             spdm_context->session_info[0].secured_message_context),
+     825                 :            :         LIBSPDM_SESSION_STATE_NOT_STARTED);
+     826                 :          1 :     free(data);
+     827                 :          1 : }
+     828                 :            : 
+     829                 :          1 : void libspdm_test_requester_end_session_case3(void **state)
+     830                 :            : {
+     831                 :            :     libspdm_return_t status;
+     832                 :            :     libspdm_test_context_t *spdm_test_context;
+     833                 :            :     libspdm_context_t *spdm_context;
+     834                 :            :     uint32_t session_id;
+     835                 :            :     void *data;
+     836                 :            :     size_t data_size;
+     837                 :            :     void *hash;
+     838                 :            :     size_t hash_size;
+     839                 :            :     libspdm_session_info_t *session_info;
+     840                 :            : 
+     841                 :          1 :     spdm_test_context = *state;
+     842                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     843                 :          1 :     spdm_test_context->case_id = 0x3;
+     844                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     845                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     846                 :          1 :     spdm_context->connection_info.connection_state =
+     847                 :            :         LIBSPDM_CONNECTION_STATE_NOT_STARTED;
+     848                 :          1 :     spdm_context->connection_info.capability.flags |=
+     849                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     850                 :          1 :     spdm_context->connection_info.capability.flags |=
+     851                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+     852                 :          1 :     spdm_context->connection_info.capability.flags |=
+     853                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+     854                 :          1 :     spdm_context->local_context.capability.flags |=
+     855                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     856                 :          1 :     spdm_context->local_context.capability.flags |=
+     857                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+     858                 :          1 :     spdm_context->local_context.capability.flags |=
+     859                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+     860                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     861                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     862                 :            :                                                     &data_size, &hash, &hash_size);
+     863                 :          1 :     libspdm_reset_message_a(spdm_context);
+     864                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     865                 :            :         m_libspdm_use_hash_algo;
+     866                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     867                 :            :         m_libspdm_use_asym_algo;
+     868                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     869                 :            :         m_libspdm_use_dhe_algo;
+     870                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     871                 :            :         m_libspdm_use_aead_algo;
+     872                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     873                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+     874                 :            :         data_size;
+     875                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+     876                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+     877                 :            :                      data, data_size);
+     878                 :            : #endif
+     879                 :            : 
+     880                 :          1 :     session_id = 0xFFFFFFFF;
+     881                 :          1 :     session_info = &spdm_context->session_info[0];
+     882                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+     883                 :          1 :     libspdm_secured_message_set_session_state(
+     884                 :            :         session_info->secured_message_context,
+     885                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+     886                 :          1 :     libspdm_set_mem(m_dummy_key_buffer,
+     887                 :            :                     ((libspdm_secured_message_context_t
+     888                 :          1 :                       *)(session_info->secured_message_context))
+     889                 :            :                     ->aead_key_size,
+     890                 :            :                     (uint8_t)(0xFF));
+     891                 :          1 :     libspdm_secured_message_set_response_data_encryption_key(
+     892                 :            :         session_info->secured_message_context, m_dummy_key_buffer,
+     893                 :            :         ((libspdm_secured_message_context_t
+     894                 :          1 :           *)(session_info->secured_message_context))
+     895                 :            :         ->aead_key_size);
+     896                 :          1 :     libspdm_set_mem(m_dummy_salt_buffer,
+     897                 :            :                     ((libspdm_secured_message_context_t
+     898                 :          1 :                       *)(session_info->secured_message_context))
+     899                 :            :                     ->aead_iv_size,
+     900                 :            :                     (uint8_t)(0xFF));
+     901                 :          1 :     libspdm_secured_message_set_response_data_salt(
+     902                 :            :         session_info->secured_message_context, m_dummy_salt_buffer,
+     903                 :            :         ((libspdm_secured_message_context_t
+     904                 :          1 :           *)(session_info->secured_message_context))
+     905                 :            :         ->aead_iv_size);
+     906                 :            :     ((libspdm_secured_message_context_t *)(session_info
+     907                 :          1 :                                            ->secured_message_context))
+     908                 :          1 :     ->application_secret.response_data_sequence_number = 0;
+     909                 :            : 
+     910                 :          1 :     status = libspdm_send_receive_end_session(spdm_context, session_id, 0);
+     911                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_STATE_LOCAL);
+     912                 :          1 :     free(data);
+     913                 :          1 : }
+     914                 :            : 
+     915                 :          1 : void libspdm_test_requester_end_session_case4(void **state)
+     916                 :            : {
+     917                 :            :     libspdm_return_t status;
+     918                 :            :     libspdm_test_context_t *spdm_test_context;
+     919                 :            :     libspdm_context_t *spdm_context;
+     920                 :            :     uint32_t session_id;
+     921                 :            :     void *data;
+     922                 :            :     size_t data_size;
+     923                 :            :     void *hash;
+     924                 :            :     size_t hash_size;
+     925                 :            :     libspdm_session_info_t *session_info;
+     926                 :            : 
+     927                 :          1 :     spdm_test_context = *state;
+     928                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     929                 :          1 :     spdm_test_context->case_id = 0x4;
+     930                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     931                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     932                 :          1 :     spdm_context->connection_info.connection_state =
+     933                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     934                 :          1 :     spdm_context->connection_info.capability.flags |=
+     935                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     936                 :          1 :     spdm_context->connection_info.capability.flags |=
+     937                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+     938                 :          1 :     spdm_context->connection_info.capability.flags |=
+     939                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+     940                 :          1 :     spdm_context->local_context.capability.flags |=
+     941                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     942                 :          1 :     spdm_context->local_context.capability.flags |=
+     943                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+     944                 :          1 :     spdm_context->local_context.capability.flags |=
+     945                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+     946                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     947                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     948                 :            :                                                     &data_size, &hash, &hash_size);
+     949                 :          1 :     libspdm_reset_message_a(spdm_context);
+     950                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     951                 :            :         m_libspdm_use_hash_algo;
+     952                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     953                 :            :         m_libspdm_use_asym_algo;
+     954                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     955                 :            :         m_libspdm_use_dhe_algo;
+     956                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     957                 :            :         m_libspdm_use_aead_algo;
+     958                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     959                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+     960                 :            :         data_size;
+     961                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+     962                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+     963                 :            :                      data, data_size);
+     964                 :            : #endif
+     965                 :            : 
+     966                 :          1 :     session_id = 0xFFFFFFFF;
+     967                 :          1 :     session_info = &spdm_context->session_info[0];
+     968                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+     969                 :          1 :     libspdm_secured_message_set_session_state(
+     970                 :            :         session_info->secured_message_context,
+     971                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+     972                 :          1 :     libspdm_set_mem(m_dummy_key_buffer,
+     973                 :            :                     ((libspdm_secured_message_context_t
+     974                 :          1 :                       *)(session_info->secured_message_context))
+     975                 :            :                     ->aead_key_size,
+     976                 :            :                     (uint8_t)(0xFF));
+     977                 :          1 :     libspdm_secured_message_set_response_data_encryption_key(
+     978                 :            :         session_info->secured_message_context, m_dummy_key_buffer,
+     979                 :            :         ((libspdm_secured_message_context_t
+     980                 :          1 :           *)(session_info->secured_message_context))
+     981                 :            :         ->aead_key_size);
+     982                 :          1 :     libspdm_set_mem(m_dummy_salt_buffer,
+     983                 :            :                     ((libspdm_secured_message_context_t
+     984                 :          1 :                       *)(session_info->secured_message_context))
+     985                 :            :                     ->aead_iv_size,
+     986                 :            :                     (uint8_t)(0xFF));
+     987                 :          1 :     libspdm_secured_message_set_response_data_salt(
+     988                 :            :         session_info->secured_message_context, m_dummy_salt_buffer,
+     989                 :            :         ((libspdm_secured_message_context_t
+     990                 :          1 :           *)(session_info->secured_message_context))
+     991                 :            :         ->aead_iv_size);
+     992                 :            :     ((libspdm_secured_message_context_t *)(session_info
+     993                 :          1 :                                            ->secured_message_context))
+     994                 :          1 :     ->application_secret.response_data_sequence_number = 0;
+     995                 :            : 
+     996                 :          1 :     status = libspdm_send_receive_end_session(spdm_context, session_id, 0);
+     997                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_ERROR_PEER);
+     998                 :          1 :     free(data);
+     999                 :          1 : }
+    1000                 :            : 
+    1001                 :          1 : void libspdm_test_requester_end_session_case5(void **state)
+    1002                 :            : {
+    1003                 :            :     libspdm_return_t status;
+    1004                 :            :     libspdm_test_context_t *spdm_test_context;
+    1005                 :            :     libspdm_context_t *spdm_context;
+    1006                 :            :     uint32_t session_id;
+    1007                 :            :     void *data;
+    1008                 :            :     size_t data_size;
+    1009                 :            :     void *hash;
+    1010                 :            :     size_t hash_size;
+    1011                 :            :     libspdm_session_info_t *session_info;
+    1012                 :            : 
+    1013                 :          1 :     spdm_test_context = *state;
+    1014                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1015                 :          1 :     spdm_test_context->case_id = 0x5;
+    1016                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1017                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1018                 :          1 :     spdm_context->connection_info.connection_state =
+    1019                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1020                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1021                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1022                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1023                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    1024                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1025                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    1026                 :          1 :     spdm_context->local_context.capability.flags |=
+    1027                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1028                 :          1 :     spdm_context->local_context.capability.flags |=
+    1029                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    1030                 :          1 :     spdm_context->local_context.capability.flags |=
+    1031                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    1032                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1033                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    1034                 :            :                                                     &data_size, &hash, &hash_size);
+    1035                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1036                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1037                 :            :         m_libspdm_use_hash_algo;
+    1038                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1039                 :            :         m_libspdm_use_asym_algo;
+    1040                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1041                 :            :         m_libspdm_use_dhe_algo;
+    1042                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1043                 :            :         m_libspdm_use_aead_algo;
+    1044                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1045                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    1046                 :            :         data_size;
+    1047                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    1048                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    1049                 :            :                      data, data_size);
+    1050                 :            : #endif
+    1051                 :            : 
+    1052                 :          1 :     session_id = 0xFFFFFFFF;
+    1053                 :          1 :     session_info = &spdm_context->session_info[0];
+    1054                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+    1055                 :          1 :     libspdm_secured_message_set_session_state(
+    1056                 :            :         session_info->secured_message_context,
+    1057                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+    1058                 :          1 :     libspdm_set_mem(m_dummy_key_buffer,
+    1059                 :            :                     ((libspdm_secured_message_context_t
+    1060                 :          1 :                       *)(session_info->secured_message_context))
+    1061                 :            :                     ->aead_key_size,
+    1062                 :            :                     (uint8_t)(0xFF));
+    1063                 :          1 :     libspdm_secured_message_set_response_data_encryption_key(
+    1064                 :            :         session_info->secured_message_context, m_dummy_key_buffer,
+    1065                 :            :         ((libspdm_secured_message_context_t
+    1066                 :          1 :           *)(session_info->secured_message_context))
+    1067                 :            :         ->aead_key_size);
+    1068                 :          1 :     libspdm_set_mem(m_dummy_salt_buffer,
+    1069                 :            :                     ((libspdm_secured_message_context_t
+    1070                 :          1 :                       *)(session_info->secured_message_context))
+    1071                 :            :                     ->aead_iv_size,
+    1072                 :            :                     (uint8_t)(0xFF));
+    1073                 :          1 :     libspdm_secured_message_set_response_data_salt(
+    1074                 :            :         session_info->secured_message_context, m_dummy_salt_buffer,
+    1075                 :            :         ((libspdm_secured_message_context_t
+    1076                 :          1 :           *)(session_info->secured_message_context))
+    1077                 :            :         ->aead_iv_size);
+    1078                 :            :     ((libspdm_secured_message_context_t *)(session_info
+    1079                 :          1 :                                            ->secured_message_context))
+    1080                 :          1 :     ->application_secret.response_data_sequence_number = 0;
+    1081                 :            : 
+    1082                 :          1 :     status = libspdm_send_receive_end_session(spdm_context, session_id, 0);
+    1083                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_BUSY_PEER);
+    1084                 :          1 :     free(data);
+    1085                 :          1 : }
+    1086                 :            : 
+    1087                 :          1 : void libspdm_test_requester_end_session_case6(void **state)
+    1088                 :            : {
+    1089                 :            :     libspdm_return_t status;
+    1090                 :            :     libspdm_test_context_t *spdm_test_context;
+    1091                 :            :     libspdm_context_t *spdm_context;
+    1092                 :            :     uint32_t session_id;
+    1093                 :            :     void *data;
+    1094                 :            :     size_t data_size;
+    1095                 :            :     void *hash;
+    1096                 :            :     size_t hash_size;
+    1097                 :            :     libspdm_session_info_t *session_info;
+    1098                 :            : 
+    1099                 :          1 :     spdm_test_context = *state;
+    1100                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1101                 :          1 :     spdm_test_context->case_id = 0x6;
+    1102                 :          1 :     spdm_context->retry_times = 3;
+    1103                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1104                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1105                 :          1 :     spdm_context->connection_info.connection_state =
+    1106                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1107                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1108                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1109                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1110                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    1111                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1112                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    1113                 :          1 :     spdm_context->local_context.capability.flags |=
+    1114                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1115                 :          1 :     spdm_context->local_context.capability.flags |=
+    1116                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    1117                 :          1 :     spdm_context->local_context.capability.flags |=
+    1118                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    1119                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1120                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    1121                 :            :                                                     &data_size, &hash, &hash_size);
+    1122                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1123                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1124                 :            :         m_libspdm_use_hash_algo;
+    1125                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1126                 :            :         m_libspdm_use_asym_algo;
+    1127                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1128                 :            :         m_libspdm_use_dhe_algo;
+    1129                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1130                 :            :         m_libspdm_use_aead_algo;
+    1131                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1132                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    1133                 :            :         data_size;
+    1134                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    1135                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    1136                 :            :                      data, data_size);
+    1137                 :            : #endif
+    1138                 :            : 
+    1139                 :          1 :     session_id = 0xFFFFFFFF;
+    1140                 :          1 :     session_info = &spdm_context->session_info[0];
+    1141                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+    1142                 :          1 :     libspdm_secured_message_set_session_state(
+    1143                 :            :         session_info->secured_message_context,
+    1144                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+    1145                 :          1 :     libspdm_set_mem(m_dummy_key_buffer,
+    1146                 :            :                     ((libspdm_secured_message_context_t
+    1147                 :          1 :                       *)(session_info->secured_message_context))
+    1148                 :            :                     ->aead_key_size,
+    1149                 :            :                     (uint8_t)(0xFF));
+    1150                 :          1 :     libspdm_secured_message_set_response_data_encryption_key(
+    1151                 :            :         session_info->secured_message_context, m_dummy_key_buffer,
+    1152                 :            :         ((libspdm_secured_message_context_t
+    1153                 :          1 :           *)(session_info->secured_message_context))
+    1154                 :            :         ->aead_key_size);
+    1155                 :          1 :     libspdm_set_mem(m_dummy_salt_buffer,
+    1156                 :            :                     ((libspdm_secured_message_context_t
+    1157                 :          1 :                       *)(session_info->secured_message_context))
+    1158                 :            :                     ->aead_iv_size,
+    1159                 :            :                     (uint8_t)(0xFF));
+    1160                 :          1 :     libspdm_secured_message_set_response_data_salt(
+    1161                 :            :         session_info->secured_message_context, m_dummy_salt_buffer,
+    1162                 :            :         ((libspdm_secured_message_context_t
+    1163                 :          1 :           *)(session_info->secured_message_context))
+    1164                 :            :         ->aead_iv_size);
+    1165                 :            :     ((libspdm_secured_message_context_t *)(session_info
+    1166                 :          1 :                                            ->secured_message_context))
+    1167                 :          1 :     ->application_secret.response_data_sequence_number = 0;
+    1168                 :            : 
+    1169                 :          1 :     status = libspdm_send_receive_end_session(spdm_context, session_id, 0);
+    1170                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1171                 :          1 :     assert_int_equal(
+    1172                 :            :         libspdm_secured_message_get_session_state(
+    1173                 :            :             spdm_context->session_info[0].secured_message_context),
+    1174                 :            :         LIBSPDM_SESSION_STATE_NOT_STARTED);
+    1175                 :          1 :     free(data);
+    1176                 :          1 : }
+    1177                 :            : 
+    1178                 :          1 : void libspdm_test_requester_end_session_case7(void **state)
+    1179                 :            : {
+    1180                 :            :     libspdm_return_t status;
+    1181                 :            :     libspdm_test_context_t *spdm_test_context;
+    1182                 :            :     libspdm_context_t *spdm_context;
+    1183                 :            :     uint32_t session_id;
+    1184                 :            :     void *data;
+    1185                 :            :     size_t data_size;
+    1186                 :            :     void *hash;
+    1187                 :            :     size_t hash_size;
+    1188                 :            :     libspdm_session_info_t *session_info;
+    1189                 :            : 
+    1190                 :          1 :     spdm_test_context = *state;
+    1191                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1192                 :          1 :     spdm_test_context->case_id = 0x7;
+    1193                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1194                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1195                 :          1 :     spdm_context->connection_info.connection_state =
+    1196                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1197                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1198                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1199                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1200                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    1201                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1202                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    1203                 :          1 :     spdm_context->local_context.capability.flags |=
+    1204                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1205                 :          1 :     spdm_context->local_context.capability.flags |=
+    1206                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    1207                 :          1 :     spdm_context->local_context.capability.flags |=
+    1208                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    1209                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1210                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    1211                 :            :                                                     &data_size, &hash, &hash_size);
+    1212                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1213                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1214                 :            :         m_libspdm_use_hash_algo;
+    1215                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1216                 :            :         m_libspdm_use_asym_algo;
+    1217                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1218                 :            :         m_libspdm_use_dhe_algo;
+    1219                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1220                 :            :         m_libspdm_use_aead_algo;
+    1221                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1222                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    1223                 :            :         data_size;
+    1224                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    1225                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    1226                 :            :                      data, data_size);
+    1227                 :            : #endif
+    1228                 :            : 
+    1229                 :          1 :     session_id = 0xFFFFFFFF;
+    1230                 :          1 :     session_info = &spdm_context->session_info[0];
+    1231                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+    1232                 :          1 :     libspdm_secured_message_set_session_state(
+    1233                 :            :         session_info->secured_message_context,
+    1234                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+    1235                 :          1 :     libspdm_set_mem(m_dummy_key_buffer,
+    1236                 :            :                     ((libspdm_secured_message_context_t
+    1237                 :          1 :                       *)(session_info->secured_message_context))
+    1238                 :            :                     ->aead_key_size,
+    1239                 :            :                     (uint8_t)(0xFF));
+    1240                 :          1 :     libspdm_secured_message_set_response_data_encryption_key(
+    1241                 :            :         session_info->secured_message_context, m_dummy_key_buffer,
+    1242                 :            :         ((libspdm_secured_message_context_t
+    1243                 :          1 :           *)(session_info->secured_message_context))
+    1244                 :            :         ->aead_key_size);
+    1245                 :          1 :     libspdm_set_mem(m_dummy_salt_buffer,
+    1246                 :            :                     ((libspdm_secured_message_context_t
+    1247                 :          1 :                       *)(session_info->secured_message_context))
+    1248                 :            :                     ->aead_iv_size,
+    1249                 :            :                     (uint8_t)(0xFF));
+    1250                 :          1 :     libspdm_secured_message_set_response_data_salt(
+    1251                 :            :         session_info->secured_message_context, m_dummy_salt_buffer,
+    1252                 :            :         ((libspdm_secured_message_context_t
+    1253                 :          1 :           *)(session_info->secured_message_context))
+    1254                 :            :         ->aead_iv_size);
+    1255                 :            :     ((libspdm_secured_message_context_t *)(session_info
+    1256                 :          1 :                                            ->secured_message_context))
+    1257                 :          1 :     ->application_secret.response_data_sequence_number = 0;
+    1258                 :            : 
+    1259                 :          1 :     status = libspdm_send_receive_end_session(spdm_context, session_id, 0);
+    1260                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_RESYNCH_PEER);
+    1261                 :          1 :     assert_int_equal(spdm_context->connection_info.connection_state,
+    1262                 :            :                      LIBSPDM_CONNECTION_STATE_NOT_STARTED);
+    1263                 :          1 :     free(data);
+    1264                 :          1 : }
+    1265                 :            : 
+    1266                 :          1 : void libspdm_test_requester_end_session_case8(void **state)
+    1267                 :            : {
+    1268                 :            :     libspdm_return_t status;
+    1269                 :            :     libspdm_test_context_t *spdm_test_context;
+    1270                 :            :     libspdm_context_t *spdm_context;
+    1271                 :            :     uint32_t session_id;
+    1272                 :            :     void *data;
+    1273                 :            :     size_t data_size;
+    1274                 :            :     void *hash;
+    1275                 :            :     size_t hash_size;
+    1276                 :            :     libspdm_session_info_t *session_info;
+    1277                 :            : 
+    1278                 :          1 :     spdm_test_context = *state;
+    1279                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1280                 :          1 :     spdm_test_context->case_id = 0x8;
+    1281                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1282                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1283                 :          1 :     spdm_context->connection_info.connection_state =
+    1284                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1285                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1286                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1287                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1288                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    1289                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1290                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    1291                 :          1 :     spdm_context->local_context.capability.flags |=
+    1292                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1293                 :          1 :     spdm_context->local_context.capability.flags |=
+    1294                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    1295                 :          1 :     spdm_context->local_context.capability.flags |=
+    1296                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    1297                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1298                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    1299                 :            :                                                     &data_size, &hash, &hash_size);
+    1300                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1301                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1302                 :            :         m_libspdm_use_hash_algo;
+    1303                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1304                 :            :         m_libspdm_use_asym_algo;
+    1305                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1306                 :            :         m_libspdm_use_dhe_algo;
+    1307                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1308                 :            :         m_libspdm_use_aead_algo;
+    1309                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1310                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    1311                 :            :         data_size;
+    1312                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    1313                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    1314                 :            :                      data, data_size);
+    1315                 :            : #endif
+    1316                 :            : 
+    1317                 :          1 :     session_id = 0xFFFFFFFF;
+    1318                 :          1 :     session_info = &spdm_context->session_info[0];
+    1319                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+    1320                 :          1 :     libspdm_secured_message_set_session_state(
+    1321                 :            :         session_info->secured_message_context,
+    1322                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+    1323                 :          1 :     libspdm_set_mem(m_dummy_key_buffer,
+    1324                 :            :                     ((libspdm_secured_message_context_t
+    1325                 :          1 :                       *)(session_info->secured_message_context))
+    1326                 :            :                     ->aead_key_size,
+    1327                 :            :                     (uint8_t)(0xFF));
+    1328                 :          1 :     libspdm_secured_message_set_response_data_encryption_key(
+    1329                 :            :         session_info->secured_message_context, m_dummy_key_buffer,
+    1330                 :            :         ((libspdm_secured_message_context_t
+    1331                 :          1 :           *)(session_info->secured_message_context))
+    1332                 :            :         ->aead_key_size);
+    1333                 :          1 :     libspdm_set_mem(m_dummy_salt_buffer,
+    1334                 :            :                     ((libspdm_secured_message_context_t
+    1335                 :          1 :                       *)(session_info->secured_message_context))
+    1336                 :            :                     ->aead_iv_size,
+    1337                 :            :                     (uint8_t)(0xFF));
+    1338                 :          1 :     libspdm_secured_message_set_response_data_salt(
+    1339                 :            :         session_info->secured_message_context, m_dummy_salt_buffer,
+    1340                 :            :         ((libspdm_secured_message_context_t
+    1341                 :          1 :           *)(session_info->secured_message_context))
+    1342                 :            :         ->aead_iv_size);
+    1343                 :            :     ((libspdm_secured_message_context_t *)(session_info
+    1344                 :          1 :                                            ->secured_message_context))
+    1345                 :          1 :     ->application_secret.response_data_sequence_number = 0;
+    1346                 :            : 
+    1347                 :          1 :     status = libspdm_send_receive_end_session(spdm_context, session_id, 0);
+    1348                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_NOT_READY_PEER);
+    1349                 :          1 :     free(data);
+    1350                 :          1 : }
+    1351                 :            : 
+    1352                 :          1 : void libspdm_test_requester_end_session_case9(void **state)
+    1353                 :            : {
+    1354                 :            :     libspdm_return_t status;
+    1355                 :            :     libspdm_test_context_t *spdm_test_context;
+    1356                 :            :     libspdm_context_t *spdm_context;
+    1357                 :            :     uint32_t session_id;
+    1358                 :            :     void *data;
+    1359                 :            :     size_t data_size;
+    1360                 :            :     void *hash;
+    1361                 :            :     size_t hash_size;
+    1362                 :            :     libspdm_session_info_t *session_info;
+    1363                 :            : 
+    1364                 :          1 :     spdm_test_context = *state;
+    1365                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1366                 :          1 :     spdm_test_context->case_id = 0x9;
+    1367                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1368                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1369                 :          1 :     spdm_context->connection_info.connection_state =
+    1370                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1371                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1372                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1373                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1374                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    1375                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1376                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    1377                 :          1 :     spdm_context->local_context.capability.flags |=
+    1378                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1379                 :          1 :     spdm_context->local_context.capability.flags |=
+    1380                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    1381                 :          1 :     spdm_context->local_context.capability.flags |=
+    1382                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    1383                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1384                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    1385                 :            :                                                     &data_size, &hash, &hash_size);
+    1386                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1387                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1388                 :            :         m_libspdm_use_hash_algo;
+    1389                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1390                 :            :         m_libspdm_use_asym_algo;
+    1391                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1392                 :            :         m_libspdm_use_dhe_algo;
+    1393                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1394                 :            :         m_libspdm_use_aead_algo;
+    1395                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1396                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
+    1397                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    1398                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    1399                 :            :                      data, data_size);
+    1400                 :            : #endif
+    1401                 :            : 
+    1402                 :          1 :     session_id = 0xFFFFFFFF;
+    1403                 :          1 :     session_info = &spdm_context->session_info[0];
+    1404                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+    1405                 :          1 :     libspdm_secured_message_set_session_state(
+    1406                 :            :         session_info->secured_message_context,
+    1407                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+    1408                 :          1 :     libspdm_set_mem(m_dummy_key_buffer,
+    1409                 :            :                     ((libspdm_secured_message_context_t
+    1410                 :          1 :                       *)(session_info->secured_message_context))
+    1411                 :            :                     ->aead_key_size,
+    1412                 :            :                     (uint8_t)(0xFF));
+    1413                 :          1 :     libspdm_secured_message_set_response_data_encryption_key(
+    1414                 :            :         session_info->secured_message_context, m_dummy_key_buffer,
+    1415                 :            :         ((libspdm_secured_message_context_t
+    1416                 :          1 :           *)(session_info->secured_message_context))
+    1417                 :            :         ->aead_key_size);
+    1418                 :          1 :     libspdm_set_mem(m_dummy_salt_buffer,
+    1419                 :            :                     ((libspdm_secured_message_context_t
+    1420                 :          1 :                       *)(session_info->secured_message_context))
+    1421                 :            :                     ->aead_iv_size,
+    1422                 :            :                     (uint8_t)(0xFF));
+    1423                 :          1 :     libspdm_secured_message_set_response_data_salt(
+    1424                 :            :         session_info->secured_message_context, m_dummy_salt_buffer,
+    1425                 :            :         ((libspdm_secured_message_context_t
+    1426                 :          1 :           *)(session_info->secured_message_context))->aead_iv_size);
+    1427                 :          1 :     ((libspdm_secured_message_context_t *)(session_info->secured_message_context))
+    1428                 :          1 :     ->application_secret.response_data_sequence_number = 0;
+    1429                 :            : 
+    1430                 :          1 :     status = libspdm_send_receive_end_session(spdm_context, session_id, 0);
+    1431                 :            :     if (LIBSPDM_RESPOND_IF_READY_SUPPORT) {
+    1432                 :          1 :         assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1433                 :          1 :         assert_int_equal(
+    1434                 :            :             libspdm_secured_message_get_session_state(
+    1435                 :            :                 spdm_context->session_info[0].secured_message_context),
+    1436                 :            :             LIBSPDM_SESSION_STATE_NOT_STARTED);
+    1437                 :            :     } else {
+    1438                 :            :         assert_int_equal(status, LIBSPDM_STATUS_NOT_READY_PEER);
+    1439                 :            :     }
+    1440                 :          1 :     free(data);
+    1441                 :          1 : }
+    1442                 :            : 
+    1443                 :          1 : void libspdm_test_requester_end_session_case10(void **state) {
+    1444                 :            :     libspdm_return_t status;
+    1445                 :            :     libspdm_test_context_t    *spdm_test_context;
+    1446                 :            :     libspdm_context_t  *spdm_context;
+    1447                 :            :     uint32_t session_id;
+    1448                 :            :     void                 *data;
+    1449                 :            :     size_t data_size;
+    1450                 :            :     void                 *hash;
+    1451                 :            :     size_t hash_size;
+    1452                 :            :     libspdm_session_info_t    *session_info;
+    1453                 :            :     uint16_t error_code;
+    1454                 :            : 
+    1455                 :          1 :     spdm_test_context = *state;
+    1456                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1457                 :          1 :     spdm_test_context->case_id = 0xA;
+    1458                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1459                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1460                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1461                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1462                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    1463                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    1464                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1465                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    1466                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    1467                 :          1 :     libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
+    1468                 :            :                                                      m_libspdm_use_asym_algo,
+    1469                 :            :                                                      &data, &data_size,
+    1470                 :            :                                                      &hash, &hash_size);
+    1471                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1472                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1473                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    1474                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    1475                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1476                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    1477                 :            :         data_size;
+    1478                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    1479                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    1480                 :            :                      data, data_size);
+    1481                 :            : #endif
+    1482                 :            : 
+    1483                 :          1 :     error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
+    1484         [ +  + ]:         19 :     while(error_code <= 0xff) {
+    1485                 :         18 :         spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1486                 :         18 :         libspdm_reset_message_a(spdm_context);
+    1487                 :            : 
+    1488                 :         18 :         session_id = 0xFFFFFFFF;
+    1489                 :         18 :         session_info = &spdm_context->session_info[0];
+    1490                 :         18 :         libspdm_session_info_init (spdm_context, session_info, session_id, true);
+    1491                 :         18 :         libspdm_secured_message_set_session_state (session_info->secured_message_context,
+    1492                 :            :                                                    LIBSPDM_SESSION_STATE_ESTABLISHED);
+    1493                 :         18 :         libspdm_set_mem (m_dummy_key_buffer,
+    1494                 :         18 :                          ((libspdm_secured_message_context_t*)(session_info->secured_message_context))->aead_key_size,
+    1495                 :            :                          (uint8_t)(0xFF));
+    1496                 :         18 :         libspdm_secured_message_set_response_data_encryption_key (
+    1497                 :            :             session_info->secured_message_context, m_dummy_key_buffer,
+    1498                 :         18 :             ((libspdm_secured_message_context_t*)(session_info->secured_message_context))->aead_key_size);
+    1499                 :         18 :         libspdm_set_mem (m_dummy_salt_buffer,
+    1500                 :         18 :                          ((libspdm_secured_message_context_t*)(session_info->secured_message_context))->aead_iv_size,
+    1501                 :            :                          (uint8_t)(0xFF));
+    1502                 :         18 :         libspdm_secured_message_set_response_data_salt (session_info->secured_message_context,
+    1503                 :            :                                                         m_dummy_salt_buffer,
+    1504                 :            :                                                         ((libspdm_secured_message_context_t*)(
+    1505                 :            :                                                              session_info
+    1506                 :         18 :                                                              ->
+    1507                 :            :                                                              secured_message_context))->aead_iv_size);
+    1508                 :         18 :         ((libspdm_secured_message_context_t*)(session_info->secured_message_context))->
+    1509                 :         18 :         application_secret.response_data_sequence_number = 0;
+    1510                 :            : 
+    1511                 :         18 :         status = libspdm_send_receive_end_session (spdm_context, session_id, 0);
+    1512         [ +  + ]:         18 :         if(error_code != SPDM_ERROR_CODE_DECRYPT_ERROR) {
+    1513         [ -  + ]:         17 :             LIBSPDM_ASSERT_INT_EQUAL_CASE (status, LIBSPDM_STATUS_ERROR_PEER, error_code);
+    1514                 :            :         } else {
+    1515         [ -  + ]:          1 :             LIBSPDM_ASSERT_INT_EQUAL_CASE (status, LIBSPDM_STATUS_SESSION_MSG_ERROR, error_code);
+    1516                 :            :         }
+    1517                 :            : 
+    1518                 :         18 :         error_code++;
+    1519         [ +  + ]:         18 :         if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
+    1520                 :          1 :             error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
+    1521                 :            :         }
+    1522         [ +  + ]:         18 :         if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) { /*skip some reserved error codes (0d to 3e)*/
+    1523                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
+    1524                 :            :         }
+    1525         [ +  + ]:         18 :         if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) { /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
+    1526                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
+    1527                 :            :         }
+    1528                 :            :     }
+    1529                 :            : 
+    1530                 :          1 :     free(data);
+    1531                 :          1 : }
+    1532                 :            : 
+    1533                 :          1 : void libspdm_test_requester_end_session_case11(void **state)
+    1534                 :            : {
+    1535                 :            :     libspdm_return_t status;
+    1536                 :            :     libspdm_test_context_t *spdm_test_context;
+    1537                 :            :     libspdm_context_t *spdm_context;
+    1538                 :            :     uint32_t session_id;
+    1539                 :            :     void *data;
+    1540                 :            :     size_t data_size;
+    1541                 :            :     void *hash;
+    1542                 :            :     size_t hash_size;
+    1543                 :            :     libspdm_session_info_t *session_info;
+    1544                 :            : 
+    1545                 :          1 :     spdm_test_context = *state;
+    1546                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1547                 :          1 :     spdm_test_context->case_id = 0xB;
+    1548                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1549                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1550                 :          1 :     spdm_context->connection_info.connection_state =
+    1551                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1552                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1553                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1554                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1555                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    1556                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1557                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    1558                 :          1 :     spdm_context->local_context.capability.flags |=
+    1559                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1560                 :          1 :     spdm_context->local_context.capability.flags |=
+    1561                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    1562                 :          1 :     spdm_context->local_context.capability.flags |=
+    1563                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    1564                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1565                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    1566                 :            :                                                     &data_size, &hash, &hash_size);
+    1567                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1568                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1569                 :            :         m_libspdm_use_hash_algo;
+    1570                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1571                 :            :         m_libspdm_use_asym_algo;
+    1572                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1573                 :            :         m_libspdm_use_dhe_algo;
+    1574                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1575                 :            :         m_libspdm_use_aead_algo;
+    1576                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1577                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    1578                 :            :         data_size;
+    1579                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    1580                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    1581                 :            :                      data, data_size);
+    1582                 :            : #endif
+    1583                 :            : 
+    1584                 :          1 :     session_id = 0xFFFFFFFF;
+    1585                 :          1 :     session_info = &spdm_context->session_info[0];
+    1586                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+    1587                 :          1 :     libspdm_secured_message_set_session_state(
+    1588                 :            :         session_info->secured_message_context,
+    1589                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+    1590                 :          1 :     libspdm_set_mem(m_dummy_key_buffer,
+    1591                 :            :                     ((libspdm_secured_message_context_t
+    1592                 :          1 :                       *)(session_info->secured_message_context))
+    1593                 :            :                     ->aead_key_size,
+    1594                 :            :                     (uint8_t)(0xFF));
+    1595                 :          1 :     libspdm_secured_message_set_response_data_encryption_key(
+    1596                 :            :         session_info->secured_message_context, m_dummy_key_buffer,
+    1597                 :            :         ((libspdm_secured_message_context_t
+    1598                 :          1 :           *)(session_info->secured_message_context))
+    1599                 :            :         ->aead_key_size);
+    1600                 :          1 :     libspdm_set_mem(m_dummy_salt_buffer,
+    1601                 :            :                     ((libspdm_secured_message_context_t
+    1602                 :          1 :                       *)(session_info->secured_message_context))
+    1603                 :            :                     ->aead_iv_size,
+    1604                 :            :                     (uint8_t)(0xFF));
+    1605                 :          1 :     libspdm_secured_message_set_response_data_salt(
+    1606                 :            :         session_info->secured_message_context, m_dummy_salt_buffer,
+    1607                 :            :         ((libspdm_secured_message_context_t
+    1608                 :          1 :           *)(session_info->secured_message_context))
+    1609                 :            :         ->aead_iv_size);
+    1610                 :            :     ((libspdm_secured_message_context_t *)(session_info
+    1611                 :          1 :                                            ->secured_message_context))
+    1612                 :          1 :     ->application_secret.response_data_sequence_number = 0;
+    1613                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1614                 :            :     session_info->session_transcript.message_m.buffer_size =
+    1615                 :            :         spdm_context->transcript.message_m.max_buffer_size;
+    1616                 :            :     spdm_context->transcript.message_b.buffer_size =
+    1617                 :            :         spdm_context->transcript.message_b.max_buffer_size;
+    1618                 :            :     spdm_context->transcript.message_c.buffer_size =
+    1619                 :            :         spdm_context->transcript.message_c.max_buffer_size;
+    1620                 :            :     spdm_context->transcript.message_mut_b.buffer_size =
+    1621                 :            :         spdm_context->transcript.message_mut_b.max_buffer_size;
+    1622                 :            :     spdm_context->transcript.message_mut_c.buffer_size =
+    1623                 :            :         spdm_context->transcript.message_mut_c.max_buffer_size;
+    1624                 :            : #endif
+    1625                 :            : 
+    1626                 :          1 :     status = libspdm_send_receive_end_session(spdm_context, session_id, 0);
+    1627                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1628                 :          1 :     assert_int_equal(
+    1629                 :            :         libspdm_secured_message_get_session_state(
+    1630                 :            :             spdm_context->session_info[0].secured_message_context),
+    1631                 :            :         LIBSPDM_SESSION_STATE_NOT_STARTED);
+    1632                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1633                 :            :     assert_int_equal(session_info->session_transcript.message_m.buffer_size, 0);
+    1634                 :            :     assert_int_equal(spdm_context->transcript.message_b.buffer_size, 0);
+    1635                 :            :     assert_int_equal(spdm_context->transcript.message_c.buffer_size, 0);
+    1636                 :            :     assert_int_equal(spdm_context->transcript.message_mut_b.buffer_size, 0);
+    1637                 :            :     assert_int_equal(spdm_context->transcript.message_mut_c.buffer_size, 0);
+    1638                 :            : #endif
+    1639                 :          1 :     free(data);
+    1640                 :          1 : }
+    1641                 :            : 
+    1642                 :            : /**
+    1643                 :            :  * Test 12: the requester is setup correctly, but receives an ERROR with SPDM_ERROR_CODE_DECRYPT_ERROR.
+    1644                 :            :  * Expected behavior: client returns a Status of INVALID_SESSION_ID  and free the session ID.
+    1645                 :            :  **/
+    1646                 :          1 : void libspdm_test_requester_end_session_case12(void **state)
+    1647                 :            : {
+    1648                 :            :     libspdm_return_t status;
+    1649                 :            :     libspdm_test_context_t *spdm_test_context;
+    1650                 :            :     libspdm_context_t *spdm_context;
+    1651                 :            :     uint32_t session_id;
+    1652                 :            :     void *data;
+    1653                 :            :     size_t data_size;
+    1654                 :            :     void *hash;
+    1655                 :            :     size_t hash_size;
+    1656                 :            :     libspdm_session_info_t *session_info;
+    1657                 :            : 
+    1658                 :          1 :     spdm_test_context = *state;
+    1659                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1660                 :          1 :     spdm_test_context->case_id = 0xC;
+    1661                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1662                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1663                 :          1 :     spdm_context->connection_info.connection_state =
+    1664                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1665                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1666                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1667                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1668                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    1669                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1670                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    1671                 :          1 :     spdm_context->local_context.capability.flags |=
+    1672                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1673                 :          1 :     spdm_context->local_context.capability.flags |=
+    1674                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    1675                 :          1 :     spdm_context->local_context.capability.flags |=
+    1676                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    1677                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1678                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    1679                 :            :                                                     &data_size, &hash, &hash_size);
+    1680                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1681                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1682                 :            :         m_libspdm_use_hash_algo;
+    1683                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1684                 :            :         m_libspdm_use_asym_algo;
+    1685                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1686                 :            :         m_libspdm_use_dhe_algo;
+    1687                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1688                 :            :         m_libspdm_use_aead_algo;
+    1689                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1690                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    1691                 :            :         data_size;
+    1692                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    1693                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    1694                 :            :                      data, data_size);
+    1695                 :            : #endif
+    1696                 :            : 
+    1697                 :          1 :     session_id = 0xFFFFFFFF;
+    1698                 :          1 :     session_info = &spdm_context->session_info[0];
+    1699                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+    1700                 :          1 :     libspdm_secured_message_set_session_state(
+    1701                 :            :         session_info->secured_message_context,
+    1702                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+    1703                 :          1 :     libspdm_set_mem(m_dummy_key_buffer,
+    1704                 :            :                     ((libspdm_secured_message_context_t
+    1705                 :          1 :                       *)(session_info->secured_message_context))
+    1706                 :            :                     ->aead_key_size,
+    1707                 :            :                     (uint8_t)(0xFF));
+    1708                 :          1 :     libspdm_secured_message_set_response_data_encryption_key(
+    1709                 :            :         session_info->secured_message_context, m_dummy_key_buffer,
+    1710                 :            :         ((libspdm_secured_message_context_t
+    1711                 :          1 :           *)(session_info->secured_message_context))
+    1712                 :            :         ->aead_key_size);
+    1713                 :          1 :     libspdm_set_mem(m_dummy_salt_buffer,
+    1714                 :            :                     ((libspdm_secured_message_context_t
+    1715                 :          1 :                       *)(session_info->secured_message_context))
+    1716                 :            :                     ->aead_iv_size,
+    1717                 :            :                     (uint8_t)(0xFF));
+    1718                 :          1 :     libspdm_secured_message_set_response_data_salt(
+    1719                 :            :         session_info->secured_message_context, m_dummy_salt_buffer,
+    1720                 :            :         ((libspdm_secured_message_context_t
+    1721                 :          1 :           *)(session_info->secured_message_context))
+    1722                 :            :         ->aead_iv_size);
+    1723                 :            :     ((libspdm_secured_message_context_t *)(session_info
+    1724                 :          1 :                                            ->secured_message_context))
+    1725                 :          1 :     ->application_secret.response_data_sequence_number = 0;
+    1726                 :            : 
+    1727                 :          1 :     status = libspdm_send_receive_end_session(spdm_context, session_id, 0);
+    1728                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SESSION_MSG_ERROR);
+    1729                 :          1 :     assert_int_equal(spdm_context->session_info->session_id, INVALID_SESSION_ID);
+    1730                 :            : 
+    1731                 :          1 :     free(data);
+    1732                 :          1 : }
+    1733                 :            : 
+    1734                 :            : libspdm_test_context_t m_libspdm_requester_end_session_test_context = {
+    1735                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+    1736                 :            :     true,
+    1737                 :            :     libspdm_requester_end_session_test_send_message,
+    1738                 :            :     libspdm_requester_end_session_test_receive_message,
+    1739                 :            : };
+    1740                 :            : 
+    1741                 :          1 : int libspdm_requester_end_session_test_main(void)
+    1742                 :            : {
+    1743                 :          1 :     const struct CMUnitTest spdm_requester_end_session_tests[] = {
+    1744                 :            :         /* SendRequest failed*/
+    1745                 :            :         cmocka_unit_test(libspdm_test_requester_end_session_case1),
+    1746                 :            :         /* Successful response*/
+    1747                 :            :         cmocka_unit_test(libspdm_test_requester_end_session_case2),
+    1748                 :            :         /* connection_state check failed*/
+    1749                 :            :         cmocka_unit_test(libspdm_test_requester_end_session_case3),
+    1750                 :            :         /* Error response: SPDM_ERROR_CODE_INVALID_REQUEST*/
+    1751                 :            :         cmocka_unit_test(libspdm_test_requester_end_session_case4),
+    1752                 :            :         /* Always SPDM_ERROR_CODE_BUSY*/
+    1753                 :            :         cmocka_unit_test(libspdm_test_requester_end_session_case5),
+    1754                 :            :         /* SPDM_ERROR_CODE_BUSY + Successful response*/
+    1755                 :            :         cmocka_unit_test(libspdm_test_requester_end_session_case6),
+    1756                 :            :         /* Error response: SPDM_ERROR_CODE_REQUEST_RESYNCH*/
+    1757                 :            :         cmocka_unit_test(libspdm_test_requester_end_session_case7),
+    1758                 :            :         /* Always SPDM_ERROR_CODE_RESPONSE_NOT_READY*/
+    1759                 :            :         cmocka_unit_test(libspdm_test_requester_end_session_case8),
+    1760                 :            :         /* SPDM_ERROR_CODE_RESPONSE_NOT_READY + Successful response*/
+    1761                 :            :         cmocka_unit_test(libspdm_test_requester_end_session_case9),
+    1762                 :            :         /* Unexpected errors*/
+    1763                 :            :         cmocka_unit_test(libspdm_test_requester_end_session_case10),
+    1764                 :            :         /* Buffer reset*/
+    1765                 :            :         cmocka_unit_test(libspdm_test_requester_end_session_case11),
+    1766                 :            :         /* Error response: SPDM_ERROR_CODE_DECRYPT_ERROR*/
+    1767                 :            :         cmocka_unit_test(libspdm_test_requester_end_session_case12),
+    1768                 :            :     };
+    1769                 :            : 
+    1770                 :          1 :     libspdm_setup_test_context(&m_libspdm_requester_end_session_test_context);
+    1771                 :            : 
+    1772                 :          1 :     return cmocka_run_group_tests(spdm_requester_end_session_tests,
+    1773                 :            :                                   libspdm_unit_test_group_setup,
+    1774                 :            :                                   libspdm_unit_test_group_teardown);
+    1775                 :            : }
+    1776                 :            : 
+    1777                 :            : #endif /* (LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP) || (LIBSPDM_ENABLE_CAPABILITY_PSK_CAP) */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/error_test/get_capabilities_err.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_requester/error_test/get_capabilities_err.c.func-sort-c.html new file mode 100644 index 00000000000..9d73bc92623 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/error_test/get_capabilities_err.c.func-sort-c.html @@ -0,0 +1,253 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/error_test/get_capabilities_err.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester/error_test - get_capabilities_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:1023104298.2 %
Date:2024-09-22 08:21:07Functions:4343100.0 %
Branches:909693.8 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_get_capabilities_error_test_main1
libspdm_test_requester_get_capabilities_err_case11
libspdm_test_requester_get_capabilities_err_case101
libspdm_test_requester_get_capabilities_err_case111
libspdm_test_requester_get_capabilities_err_case121
libspdm_test_requester_get_capabilities_err_case131
libspdm_test_requester_get_capabilities_err_case141
libspdm_test_requester_get_capabilities_err_case151
libspdm_test_requester_get_capabilities_err_case161
libspdm_test_requester_get_capabilities_err_case171
libspdm_test_requester_get_capabilities_err_case181
libspdm_test_requester_get_capabilities_err_case191
libspdm_test_requester_get_capabilities_err_case21
libspdm_test_requester_get_capabilities_err_case201
libspdm_test_requester_get_capabilities_err_case211
libspdm_test_requester_get_capabilities_err_case221
libspdm_test_requester_get_capabilities_err_case231
libspdm_test_requester_get_capabilities_err_case241
libspdm_test_requester_get_capabilities_err_case251
libspdm_test_requester_get_capabilities_err_case261
libspdm_test_requester_get_capabilities_err_case271
libspdm_test_requester_get_capabilities_err_case281
libspdm_test_requester_get_capabilities_err_case291
libspdm_test_requester_get_capabilities_err_case31
libspdm_test_requester_get_capabilities_err_case301
libspdm_test_requester_get_capabilities_err_case311
libspdm_test_requester_get_capabilities_err_case321
libspdm_test_requester_get_capabilities_err_case331
libspdm_test_requester_get_capabilities_err_case341
libspdm_test_requester_get_capabilities_err_case351
libspdm_test_requester_get_capabilities_err_case361
libspdm_test_requester_get_capabilities_err_case371
libspdm_test_requester_get_capabilities_err_case381
libspdm_test_requester_get_capabilities_err_case391
libspdm_test_requester_get_capabilities_err_case41
libspdm_test_requester_get_capabilities_err_case401
libspdm_test_requester_get_capabilities_err_case51
libspdm_test_requester_get_capabilities_err_case61
libspdm_test_requester_get_capabilities_err_case71
libspdm_test_requester_get_capabilities_err_case81
libspdm_test_requester_get_capabilities_err_case91
libspdm_requester_get_capabilities_test_receive_message53
libspdm_requester_get_capabilities_test_send_message55
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/error_test/get_capabilities_err.c.func.html b/coverage_log/unit_test/test_spdm_requester/error_test/get_capabilities_err.c.func.html new file mode 100644 index 00000000000..c2dc2454d72 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/error_test/get_capabilities_err.c.func.html @@ -0,0 +1,253 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/error_test/get_capabilities_err.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester/error_test - get_capabilities_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:1023104298.2 %
Date:2024-09-22 08:21:07Functions:4343100.0 %
Branches:909693.8 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_get_capabilities_error_test_main1
libspdm_requester_get_capabilities_test_receive_message53
libspdm_requester_get_capabilities_test_send_message55
libspdm_test_requester_get_capabilities_err_case11
libspdm_test_requester_get_capabilities_err_case101
libspdm_test_requester_get_capabilities_err_case111
libspdm_test_requester_get_capabilities_err_case121
libspdm_test_requester_get_capabilities_err_case131
libspdm_test_requester_get_capabilities_err_case141
libspdm_test_requester_get_capabilities_err_case151
libspdm_test_requester_get_capabilities_err_case161
libspdm_test_requester_get_capabilities_err_case171
libspdm_test_requester_get_capabilities_err_case181
libspdm_test_requester_get_capabilities_err_case191
libspdm_test_requester_get_capabilities_err_case21
libspdm_test_requester_get_capabilities_err_case201
libspdm_test_requester_get_capabilities_err_case211
libspdm_test_requester_get_capabilities_err_case221
libspdm_test_requester_get_capabilities_err_case231
libspdm_test_requester_get_capabilities_err_case241
libspdm_test_requester_get_capabilities_err_case251
libspdm_test_requester_get_capabilities_err_case261
libspdm_test_requester_get_capabilities_err_case271
libspdm_test_requester_get_capabilities_err_case281
libspdm_test_requester_get_capabilities_err_case291
libspdm_test_requester_get_capabilities_err_case31
libspdm_test_requester_get_capabilities_err_case301
libspdm_test_requester_get_capabilities_err_case311
libspdm_test_requester_get_capabilities_err_case321
libspdm_test_requester_get_capabilities_err_case331
libspdm_test_requester_get_capabilities_err_case341
libspdm_test_requester_get_capabilities_err_case351
libspdm_test_requester_get_capabilities_err_case361
libspdm_test_requester_get_capabilities_err_case371
libspdm_test_requester_get_capabilities_err_case381
libspdm_test_requester_get_capabilities_err_case391
libspdm_test_requester_get_capabilities_err_case41
libspdm_test_requester_get_capabilities_err_case401
libspdm_test_requester_get_capabilities_err_case51
libspdm_test_requester_get_capabilities_err_case61
libspdm_test_requester_get_capabilities_err_case71
libspdm_test_requester_get_capabilities_err_case81
libspdm_test_requester_get_capabilities_err_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/error_test/get_capabilities_err.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/error_test/get_capabilities_err.c.gcov.html new file mode 100644 index 00000000000..2adfe2c71c4 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/error_test/get_capabilities_err.c.gcov.html @@ -0,0 +1,2159 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/error_test/get_capabilities_err.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester/error_test - get_capabilities_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:1023104298.2 %
Date:2024-09-22 08:21:07Functions:4343100.0 %
Branches:909693.8 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_requester_lib.h"
+       9                 :            : 
+      10                 :            : #define LIBSPDM_DEFAULT_CAPABILITY_FLAG \
+      11                 :            :     (SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | \
+      12                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP)
+      13                 :            : 
+      14                 :            : #define LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11 \
+      15                 :            :     (SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | \
+      16                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP | \
+      17                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP | \
+      18                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP | \
+      19                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP | \
+      20                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP | \
+      21                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER | \
+      22                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP | \
+      23                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP | \
+      24                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP | \
+      25                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)
+      26                 :            : 
+      27                 :            : #define LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_12  SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP
+      28                 :            : 
+      29                 :            : #define LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 \
+      30                 :            :     (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CACHE_CAP | \
+      31                 :            :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP | \
+      32                 :            :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP | \
+      33                 :            :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG | \
+      34                 :            :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_FRESH_CAP | \
+      35                 :            :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP | \
+      36                 :            :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP | \
+      37                 :            :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP | \
+      38                 :            :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP | \
+      39                 :            :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT | \
+      40                 :            :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP | \
+      41                 :            :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP | \
+      42                 :            :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_UPD_CAP | \
+      43                 :            :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)
+      44                 :            : 
+      45                 :            : #define LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_12 \
+      46                 :            :     (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP | \
+      47                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | \
+      48                 :            :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ALIAS_CERT_CAP | \
+      49                 :            :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP)
+      50                 :            : 
+      51                 :         55 : static libspdm_return_t libspdm_requester_get_capabilities_test_send_message(
+      52                 :            :     void *spdm_context, size_t request_size, const void *request,
+      53                 :            :     uint64_t timeout)
+      54                 :            : {
+      55                 :            :     libspdm_test_context_t *spdm_test_context;
+      56                 :            : 
+      57                 :         55 :     spdm_test_context = libspdm_get_test_context();
+      58   [ +  +  +  +  :         55 :     switch (spdm_test_context->case_id) {
+          +  +  +  +  +  
+          +  +  +  +  +  
+          +  +  +  +  +  
+          +  +  +  +  +  
+          +  +  +  +  +  
+          +  +  +  +  +  
+             +  +  +  +  
+                      - ]
+      59                 :          1 :     case 0x1:
+      60                 :          1 :         return LIBSPDM_STATUS_SEND_FAIL;
+      61                 :          1 :     case 0x2:
+      62                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      63                 :          1 :     case 0x3:
+      64                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      65                 :          1 :     case 0x4:
+      66                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      67                 :          1 :     case 0x5:
+      68                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      69                 :          1 :     case 0x6:
+      70                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      71                 :          1 :     case 0x7:
+      72                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      73                 :          1 :     case 0x8:
+      74                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      75                 :          1 :     case 0x9:
+      76                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      77                 :          1 :     case 0xa:
+      78                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      79                 :          1 :     case 0xb:
+      80                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      81                 :          1 :     case 0xc:
+      82                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      83                 :          1 :     case 0xd:
+      84                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      85                 :          1 :     case 0xe:
+      86                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      87                 :          1 :     case 0xf:
+      88                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      89                 :          1 :     case 0x10:
+      90                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      91                 :          1 :     case 0x11:
+      92                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      93                 :          1 :     case 0x12:
+      94                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      95                 :          1 :     case 0x13:
+      96                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      97                 :          1 :     case 0x14:
+      98                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      99                 :          1 :     case 0x15:
+     100                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     101                 :          1 :     case 0x16:
+     102                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     103                 :          1 :     case 0x17:
+     104                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     105                 :          1 :     case 0x18:
+     106                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     107                 :          1 :     case 0x19:
+     108                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     109                 :          1 :     case 0x1a:
+     110                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     111                 :          1 :     case 0x1b:
+     112                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     113                 :          1 :     case 0x1c:
+     114                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     115                 :         18 :     case 0x1d:
+     116                 :         18 :         return LIBSPDM_STATUS_SUCCESS;
+     117                 :          1 :     case 0x1E:
+     118                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     119                 :          1 :     case 0x1F:
+     120                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     121                 :          1 :     case 0x20:
+     122                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     123                 :          1 :     case 0x21:
+     124                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     125                 :          1 :     case 0x22:
+     126                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     127                 :          1 :     case 0x23:
+     128                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     129                 :          1 :     case 0x24:
+     130                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     131                 :          1 :     case 0x25:
+     132                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     133                 :          1 :     case 0x26:
+     134                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     135                 :          0 :     default:
+     136                 :          0 :         return LIBSPDM_STATUS_SEND_FAIL;
+     137                 :            :     }
+     138                 :            : }
+     139                 :            : 
+     140                 :         53 : static libspdm_return_t libspdm_requester_get_capabilities_test_receive_message(
+     141                 :            :     void *spdm_context, size_t *response_size,
+     142                 :            :     void **response, uint64_t timeout)
+     143                 :            : {
+     144                 :            :     libspdm_test_context_t *spdm_test_context;
+     145                 :            : 
+     146                 :         53 :     spdm_test_context = libspdm_get_test_context();
+     147   [ -  +  -  +  :         53 :     switch (spdm_test_context->case_id) {
+          +  +  +  +  +  
+          +  +  +  +  +  
+          +  +  +  +  +  
+          +  +  +  +  +  
+          +  +  +  +  +  
+          +  +  +  +  +  
+             +  +  +  +  
+                      - ]
+     148                 :          0 :     case 0x1:
+     149                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+     150                 :            : 
+     151                 :          1 :     case 0x2: {
+     152                 :            :         spdm_capabilities_response_t *spdm_response;
+     153                 :            :         size_t spdm_response_size;
+     154                 :            :         size_t transport_header_size;
+     155                 :            : 
+     156                 :          1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     157                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     158                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     159                 :            : 
+     160                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     161                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     162                 :          1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     163                 :          1 :         spdm_response->header.param1 = 0;
+     164                 :          1 :         spdm_response->header.param2 = 0;
+     165                 :          1 :         spdm_response->ct_exponent = 0;
+     166                 :          1 :         spdm_response->flags = SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_FRESH_CAP;
+     167                 :            : 
+     168                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     169                 :            :                                               false, spdm_response_size,
+     170                 :            :                                               spdm_response,
+     171                 :            :                                               response_size, response);
+     172                 :            :     }
+     173                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     174                 :            : 
+     175                 :          0 :     case 0x3: {
+     176                 :            :         spdm_capabilities_response_t *spdm_response;
+     177                 :            :         size_t spdm_response_size;
+     178                 :            :         size_t transport_header_size;
+     179                 :            : 
+     180                 :          0 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     181                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     182                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     183                 :            : 
+     184                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     185                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     186                 :          0 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     187                 :          0 :         spdm_response->header.param1 = 0;
+     188                 :          0 :         spdm_response->header.param2 = 0;
+     189                 :          0 :         spdm_response->ct_exponent = 0;
+     190                 :          0 :         spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+     191                 :            : 
+     192                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     193                 :            :                                               false, spdm_response_size,
+     194                 :            :                                               spdm_response,
+     195                 :            :                                               response_size, response);
+     196                 :            :     }
+     197                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     198                 :            : 
+     199                 :          1 :     case 0x4: {
+     200                 :            :         spdm_error_response_t *spdm_response;
+     201                 :            :         size_t spdm_response_size;
+     202                 :            :         size_t transport_header_size;
+     203                 :            : 
+     204                 :          1 :         spdm_response_size = sizeof(spdm_error_response_t);
+     205                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     206                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     207                 :            : 
+     208                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     209                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     210                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     211                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_INVALID_REQUEST;
+     212                 :          1 :         spdm_response->header.param2 = 0;
+     213                 :            : 
+     214                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     215                 :            :                                               false, spdm_response_size,
+     216                 :            :                                               spdm_response,
+     217                 :            :                                               response_size, response);
+     218                 :            :     }
+     219                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     220                 :            : 
+     221                 :          1 :     case 0x5: {
+     222                 :            :         spdm_error_response_t *spdm_response;
+     223                 :            :         size_t spdm_response_size;
+     224                 :            :         size_t transport_header_size;
+     225                 :            : 
+     226                 :          1 :         spdm_response_size = sizeof(spdm_error_response_t);
+     227                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     228                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     229                 :            : 
+     230                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     231                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     232                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     233                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
+     234                 :          1 :         spdm_response->header.param2 = 0;
+     235                 :            : 
+     236                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     237                 :            :                                               false, spdm_response_size,
+     238                 :            :                                               spdm_response,
+     239                 :            :                                               response_size, response);
+     240                 :            :     }
+     241                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     242                 :            : 
+     243                 :          1 :     case 0x6: {
+     244                 :            :         spdm_capabilities_response_t *spdm_response;
+     245                 :            :         size_t spdm_response_size;
+     246                 :            :         size_t transport_header_size;
+     247                 :            : 
+     248                 :          1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     249                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     250                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     251                 :            : 
+     252                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     253                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     254                 :          1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     255                 :          1 :         spdm_response->header.param1 = 0;
+     256                 :          1 :         spdm_response->header.param2 = 0;
+     257                 :          1 :         spdm_response->ct_exponent = 0;
+     258                 :          1 :         spdm_response->flags = SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG |
+     259                 :            :                                SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
+     260                 :            : 
+     261                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     262                 :            :                                               false, spdm_response_size,
+     263                 :            :                                               spdm_response,
+     264                 :            :                                               response_size, response);
+     265                 :            :     }
+     266                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     267                 :            : 
+     268                 :          1 :     case 0x7: {
+     269                 :            :         spdm_error_response_t *spdm_response;
+     270                 :            :         size_t spdm_response_size;
+     271                 :            :         size_t transport_header_size;
+     272                 :            : 
+     273                 :          1 :         spdm_response_size = sizeof(spdm_error_response_t);
+     274                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     275                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     276                 :            : 
+     277                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     278                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     279                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     280                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_REQUEST_RESYNCH;
+     281                 :          1 :         spdm_response->header.param2 = 0;
+     282                 :            : 
+     283                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     284                 :            :                                               false, spdm_response_size,
+     285                 :            :                                               spdm_response,
+     286                 :            :                                               response_size, response);
+     287                 :            :     }
+     288                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     289                 :            : 
+     290                 :          1 :     case 0x8: {
+     291                 :            :         spdm_error_response_data_response_not_ready_t *spdm_response;
+     292                 :            :         size_t spdm_response_size;
+     293                 :            :         size_t transport_header_size;
+     294                 :            : 
+     295                 :          1 :         spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
+     296                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     297                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     298                 :            : 
+     299                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     300                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     301                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     302                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_RESPONSE_NOT_READY;
+     303                 :          1 :         spdm_response->header.param2 = 0;
+     304                 :          1 :         spdm_response->extend_error_data.rd_exponent = 1;
+     305                 :          1 :         spdm_response->extend_error_data.rd_tm = 2;
+     306                 :          1 :         spdm_response->extend_error_data.request_code = SPDM_GET_CAPABILITIES;
+     307                 :          1 :         spdm_response->extend_error_data.token = 0;
+     308                 :            : 
+     309                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     310                 :            :                                               false, spdm_response_size,
+     311                 :            :                                               spdm_response,
+     312                 :            :                                               response_size, response);
+     313                 :            :     }
+     314                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     315                 :            : 
+     316                 :          1 :     case 0x9: {
+     317                 :            :         spdm_capabilities_response_t *spdm_response;
+     318                 :            :         size_t spdm_response_size;
+     319                 :            :         size_t transport_header_size;
+     320                 :            : 
+     321                 :          1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     322                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     323                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     324                 :            : 
+     325                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     326                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     327                 :          1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     328                 :          1 :         spdm_response->header.param1 = 0;
+     329                 :          1 :         spdm_response->header.param2 = 0;
+     330                 :          1 :         spdm_response->ct_exponent = 0;
+     331                 :          1 :         spdm_response->flags = SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP;
+     332                 :            : 
+     333                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     334                 :            :                                               false, spdm_response_size,
+     335                 :            :                                               spdm_response,
+     336                 :            :                                               response_size, response);
+     337                 :            :     }
+     338                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     339                 :            : 
+     340                 :          1 :     case 0xa: {
+     341                 :            :         spdm_capabilities_response_t *spdm_response;
+     342                 :            :         size_t spdm_response_size;
+     343                 :            :         size_t transport_header_size;
+     344                 :            : 
+     345                 :          1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     346                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     347                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     348                 :            : 
+     349                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     350                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     351                 :          1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     352                 :          1 :         spdm_response->header.param1 = 0;
+     353                 :          1 :         spdm_response->header.param2 = 0;
+     354                 :          1 :         spdm_response->ct_exponent = 0;
+     355                 :          1 :         spdm_response->flags = SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+     356                 :            : 
+     357                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     358                 :            :                                               false, spdm_response_size,
+     359                 :            :                                               spdm_response,
+     360                 :            :                                               response_size, response);
+     361                 :            :     }
+     362                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     363                 :            : 
+     364                 :          1 :     case 0xb: {
+     365                 :            :         spdm_capabilities_response_t *spdm_response;
+     366                 :            :         size_t spdm_response_size;
+     367                 :            :         size_t transport_header_size;
+     368                 :            : 
+     369                 :          1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     370                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     371                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     372                 :            : 
+     373                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     374                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     375                 :          1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     376                 :          1 :         spdm_response->header.param1 = 0;
+     377                 :          1 :         spdm_response->header.param2 = 0;
+     378                 :          1 :         spdm_response->ct_exponent = 0;
+     379                 :          1 :         spdm_response->flags = SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     380                 :            : 
+     381                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     382                 :            :                                               false, spdm_response_size,
+     383                 :            :                                               spdm_response,
+     384                 :            :                                               response_size, response);
+     385                 :            :     }
+     386                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     387                 :            : 
+     388                 :          1 :     case 0xc: {
+     389                 :            :         spdm_capabilities_response_t *spdm_response;
+     390                 :            :         size_t spdm_response_size;
+     391                 :            :         size_t transport_header_size;
+     392                 :            : 
+     393                 :          1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     394                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     395                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     396                 :            : 
+     397                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     398                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     399                 :          1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     400                 :          1 :         spdm_response->header.param1 = 0;
+     401                 :          1 :         spdm_response->header.param2 = 0;
+     402                 :          1 :         spdm_response->ct_exponent = 0;
+     403                 :          1 :         spdm_response->flags = SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     404                 :            : 
+     405                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     406                 :            :                                               false, spdm_response_size,
+     407                 :            :                                               spdm_response,
+     408                 :            :                                               response_size, response);
+     409                 :            :     }
+     410                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     411                 :            : 
+     412                 :          1 :     case 0xd: {
+     413                 :            :         spdm_capabilities_response_t *spdm_response;
+     414                 :            :         size_t spdm_response_size;
+     415                 :            :         size_t transport_header_size;
+     416                 :            : 
+     417                 :          1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     418                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     419                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     420                 :            : 
+     421                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     422                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     423                 :          1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     424                 :          1 :         spdm_response->header.param1 = 0;
+     425                 :          1 :         spdm_response->header.param2 = 0;
+     426                 :            : 
+     427                 :          1 :         libspdm_transport_test_encode_message(
+     428                 :            :             spdm_context, NULL, false, false,
+     429                 :            :             sizeof(spdm_message_header_t), spdm_response,
+     430                 :            :             response_size, response);
+     431                 :            :     }
+     432                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     433                 :            : 
+     434                 :          1 :     case 0xe: {
+     435                 :            :         spdm_capabilities_response_t *spdm_response;
+     436                 :            :         size_t spdm_response_size;
+     437                 :            :         size_t transport_header_size;
+     438                 :            : 
+     439                 :          1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     440                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     441                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     442                 :            : 
+     443                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     444                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     445                 :          1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     446                 :          1 :         spdm_response->header.param1 = 0;
+     447                 :          1 :         spdm_response->header.param2 = 0;
+     448                 :          1 :         spdm_response->ct_exponent = 0;
+     449                 :          1 :         spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+     450                 :            : 
+     451                 :          1 :         libspdm_transport_test_encode_message(
+     452                 :            :             spdm_context, NULL, false, false,
+     453                 :            :             sizeof(spdm_capabilities_response_t) + sizeof(uint8_t), spdm_response,
+     454                 :            :             response_size, response);
+     455                 :            :     }
+     456                 :          1 :         return LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     457                 :            : 
+     458                 :          1 :     case 0xf: {
+     459                 :            :         spdm_capabilities_response_t *spdm_response;
+     460                 :            :         size_t spdm_response_size;
+     461                 :            :         size_t transport_header_size;
+     462                 :            : 
+     463                 :          1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     464                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     465                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     466                 :            : 
+     467                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     468                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     469                 :          1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     470                 :          1 :         spdm_response->header.param1 = 0;
+     471                 :          1 :         spdm_response->header.param2 = 0;
+     472                 :          1 :         spdm_response->ct_exponent = 0;
+     473                 :          1 :         spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+     474                 :            : 
+     475                 :          1 :         libspdm_transport_test_encode_message(
+     476                 :            :             spdm_context, NULL, false, false,
+     477                 :            :             sizeof(spdm_capabilities_response_t) - sizeof(uint8_t), spdm_response,
+     478                 :            :             response_size, response);
+     479                 :            :     }
+     480                 :          1 :         return LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     481                 :            : 
+     482                 :          1 :     case 0x10: {
+     483                 :            :         spdm_capabilities_response_t *spdm_response;
+     484                 :            :         size_t spdm_response_size;
+     485                 :            :         size_t transport_header_size;
+     486                 :            : 
+     487                 :          1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     488                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     489                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     490                 :            : 
+     491                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     492                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     493                 :          1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     494                 :          1 :         spdm_response->header.param1 = 0;
+     495                 :          1 :         spdm_response->header.param2 = 0;
+     496                 :          1 :         spdm_response->ct_exponent = 0;
+     497                 :          1 :         spdm_response->flags = SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
+     498                 :            :                                SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+     499                 :            : 
+     500                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     501                 :            :                                               false, spdm_response_size,
+     502                 :            :                                               spdm_response,
+     503                 :            :                                               response_size, response);
+     504                 :            :     }
+     505                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     506                 :            : 
+     507                 :          1 :     case 0x11: {
+     508                 :            :         spdm_capabilities_response_t *spdm_response;
+     509                 :            :         size_t spdm_response_size;
+     510                 :            :         size_t transport_header_size;
+     511                 :            : 
+     512                 :          1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     513                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     514                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     515                 :            : 
+     516                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     517                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     518                 :          1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     519                 :          1 :         spdm_response->header.param1 = 0;
+     520                 :          1 :         spdm_response->header.param2 = 0;
+     521                 :          1 :         spdm_response->ct_exponent = 0;
+     522                 :          1 :         spdm_response->flags =
+     523                 :            :             LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
+     524                 :            :             (0xFFFFFFFF ^
+     525                 :            :              (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
+     526                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP |
+     527                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP));
+     528                 :            : 
+     529                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     530                 :            :                                               false, spdm_response_size,
+     531                 :            :                                               spdm_response,
+     532                 :            :                                               response_size, response);
+     533                 :            :     }
+     534                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     535                 :            : 
+     536                 :          1 :     case 0x12: {
+     537                 :            :         spdm_capabilities_response_t *spdm_response;
+     538                 :            :         size_t spdm_response_size;
+     539                 :            :         size_t transport_header_size;
+     540                 :            : 
+     541                 :          1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     542                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     543                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     544                 :            : 
+     545                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     546                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     547                 :          1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     548                 :          1 :         spdm_response->header.param1 = 0;
+     549                 :          1 :         spdm_response->header.param2 = 0;
+     550                 :          1 :         spdm_response->ct_exponent = 0;
+     551                 :          1 :         spdm_response->flags =
+     552                 :            :             LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
+     553                 :            :             (0xFFFFFFFF ^
+     554                 :            :              (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP |
+     555                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
+     556                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP |
+     557                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP));
+     558                 :            : 
+     559                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     560                 :            :                                               false, spdm_response_size,
+     561                 :            :                                               spdm_response,
+     562                 :            :                                               response_size, response);
+     563                 :            :     }
+     564                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     565                 :            : 
+     566                 :          1 :     case 0x13: {
+     567                 :            :         spdm_capabilities_response_t *spdm_response;
+     568                 :            :         size_t spdm_response_size;
+     569                 :            :         size_t transport_header_size;
+     570                 :            : 
+     571                 :          1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     572                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     573                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     574                 :            : 
+     575                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     576                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     577                 :          1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     578                 :          1 :         spdm_response->header.param1 = 0;
+     579                 :          1 :         spdm_response->header.param2 = 0;
+     580                 :          1 :         spdm_response->ct_exponent = 0;
+     581                 :          1 :         spdm_response->flags =
+     582                 :            :             LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
+     583                 :            :             (0xFFFFFFFF ^
+     584                 :            :              (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP |
+     585                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
+     586                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP |
+     587                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP));
+     588                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     589                 :            :                                               false, spdm_response_size,
+     590                 :            :                                               spdm_response,
+     591                 :            :                                               response_size, response);
+     592                 :            :     }
+     593                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     594                 :            : 
+     595                 :          1 :     case 0x14: {
+     596                 :            :         spdm_capabilities_response_t *spdm_response;
+     597                 :            :         size_t spdm_response_size;
+     598                 :            :         size_t transport_header_size;
+     599                 :            : 
+     600                 :          1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     601                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     602                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     603                 :            : 
+     604                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     605                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     606                 :          1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     607                 :          1 :         spdm_response->header.param1 = 0;
+     608                 :          1 :         spdm_response->header.param2 = 0;
+     609                 :          1 :         spdm_response->ct_exponent = 0;
+     610                 :          1 :         spdm_response->flags =
+     611                 :            :             LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
+     612                 :            :             (0xFFFFFFFF ^
+     613                 :            :              (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP |
+     614                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP |
+     615                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP));
+     616                 :            : 
+     617                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     618                 :            :                                               false, spdm_response_size,
+     619                 :            :                                               spdm_response,
+     620                 :            :                                               response_size, response);
+     621                 :            :     }
+     622                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     623                 :            : 
+     624                 :          1 :     case 0x15: {
+     625                 :            :         spdm_capabilities_response_t *spdm_response;
+     626                 :            :         size_t spdm_response_size;
+     627                 :            :         size_t transport_header_size;
+     628                 :            : 
+     629                 :          1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     630                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     631                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     632                 :            : 
+     633                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     634                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     635                 :          1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     636                 :          1 :         spdm_response->header.param1 = 0;
+     637                 :          1 :         spdm_response->header.param2 = 0;
+     638                 :          1 :         spdm_response->ct_exponent = 0;
+     639                 :          1 :         spdm_response->flags =
+     640                 :            :             LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
+     641                 :            :             (0xFFFFFFFF ^
+     642                 :            :              (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP |
+     643                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP |
+     644                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP |
+     645                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP));
+     646                 :            : 
+     647                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     648                 :            :                                               false, spdm_response_size,
+     649                 :            :                                               spdm_response,
+     650                 :            :                                               response_size, response);
+     651                 :            :     }
+     652                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     653                 :            : 
+     654                 :          1 :     case 0x16: {
+     655                 :            :         spdm_capabilities_response_t *spdm_response;
+     656                 :            :         size_t spdm_response_size;
+     657                 :            :         size_t transport_header_size;
+     658                 :            : 
+     659                 :          1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     660                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     661                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     662                 :            : 
+     663                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     664                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     665                 :          1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     666                 :          1 :         spdm_response->header.param1 = 0;
+     667                 :          1 :         spdm_response->header.param2 = 0;
+     668                 :          1 :         spdm_response->ct_exponent = 0;
+     669                 :          1 :         spdm_response->flags =
+     670                 :            :             LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
+     671                 :            :             (0xFFFFFFFF ^
+     672                 :            :              (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP |
+     673                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP |
+     674                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
+     675                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP));
+     676                 :            : 
+     677                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     678                 :            :                                               false, spdm_response_size,
+     679                 :            :                                               spdm_response,
+     680                 :            :                                               response_size, response);
+     681                 :            :     }
+     682                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     683                 :            : 
+     684                 :          1 :     case 0x17: {
+     685                 :            :         spdm_capabilities_response_t *spdm_response;
+     686                 :            :         size_t spdm_response_size;
+     687                 :            :         size_t transport_header_size;
+     688                 :            : 
+     689                 :          1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     690                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     691                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     692                 :            : 
+     693                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     694                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     695                 :          1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     696                 :          1 :         spdm_response->header.param1 = 0;
+     697                 :          1 :         spdm_response->header.param2 = 0;
+     698                 :          1 :         spdm_response->ct_exponent = 0;
+     699                 :          1 :         spdm_response->flags =
+     700                 :            :             LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
+     701                 :            :             (0xFFFFFFFF ^
+     702                 :            :              (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP));
+     703                 :            : 
+     704                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     705                 :            :                                               false, spdm_response_size,
+     706                 :            :                                               spdm_response,
+     707                 :            :                                               response_size, response);
+     708                 :            :     }
+     709                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     710                 :            : 
+     711                 :          1 :     case 0x18: {
+     712                 :            :         spdm_capabilities_response_t *spdm_response;
+     713                 :            :         size_t spdm_response_size;
+     714                 :            :         size_t transport_header_size;
+     715                 :            : 
+     716                 :          1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     717                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     718                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     719                 :            : 
+     720                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     721                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     722                 :          1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     723                 :          1 :         spdm_response->header.param1 = 0;
+     724                 :          1 :         spdm_response->header.param2 = 0;
+     725                 :          1 :         spdm_response->ct_exponent = 0;
+     726                 :          1 :         spdm_response->flags =
+     727                 :            :             LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
+     728                 :            :             (0xFFFFFFFF ^
+     729                 :            :              (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP));
+     730                 :            : 
+     731                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     732                 :            :                                               false, spdm_response_size,
+     733                 :            :                                               spdm_response,
+     734                 :            :                                               response_size, response);
+     735                 :            :     }
+     736                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     737                 :            : 
+     738                 :          1 :     case 0x19: {
+     739                 :            :         spdm_capabilities_response_t *spdm_response;
+     740                 :            :         size_t spdm_response_size;
+     741                 :            :         size_t transport_header_size;
+     742                 :            : 
+     743                 :          1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     744                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     745                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     746                 :            : 
+     747                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     748                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     749                 :          1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     750                 :          1 :         spdm_response->header.param1 = 0;
+     751                 :          1 :         spdm_response->header.param2 = 0;
+     752                 :          1 :         spdm_response->ct_exponent = 0;
+     753                 :          1 :         spdm_response->flags =
+     754                 :            :             LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
+     755                 :            :             (0xFFFFFFFF ^
+     756                 :            :              (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP |
+     757                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP |
+     758                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP));
+     759                 :            : 
+     760                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     761                 :            :                                               false, spdm_response_size,
+     762                 :            :                                               spdm_response,
+     763                 :            :                                               response_size, response);
+     764                 :            :     }
+     765                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     766                 :            : 
+     767                 :          1 :     case 0x1a: {
+     768                 :            :         spdm_capabilities_response_t *spdm_response;
+     769                 :            :         size_t spdm_response_size;
+     770                 :            :         size_t transport_header_size;
+     771                 :            : 
+     772                 :          1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     773                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     774                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     775                 :            : 
+     776                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     777                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     778                 :          1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     779                 :          1 :         spdm_response->header.param1 = 0;
+     780                 :          1 :         spdm_response->header.param2 = 0;
+     781                 :          1 :         spdm_response->ct_exponent = 0;
+     782                 :          1 :         spdm_response->flags =
+     783                 :            :             LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 |
+     784                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PUB_KEY_ID_CAP;
+     785                 :            : 
+     786                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     787                 :            :                                               false, spdm_response_size,
+     788                 :            :                                               spdm_response,
+     789                 :            :                                               response_size, response);
+     790                 :            :     }
+     791                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     792                 :            : 
+     793                 :          1 :     case 0x1b: {
+     794                 :            :         spdm_capabilities_response_t *spdm_response;
+     795                 :            :         size_t spdm_response_size;
+     796                 :            :         size_t transport_header_size;
+     797                 :            : 
+     798                 :          1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     799                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     800                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     801                 :            : 
+     802                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     803                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     804                 :          1 :         spdm_response->header.request_response_code =
+     805                 :            :             SPDM_GET_CAPABILITIES;
+     806                 :          1 :         spdm_response->header.param1 = 0;
+     807                 :          1 :         spdm_response->header.param2 = 0;
+     808                 :          1 :         spdm_response->ct_exponent = 0;
+     809                 :          1 :         spdm_response->flags =
+     810                 :            :             LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11;
+     811                 :            : 
+     812                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     813                 :            :                                               false, spdm_response_size,
+     814                 :            :                                               spdm_response,
+     815                 :            :                                               response_size, response);
+     816                 :            :     }
+     817                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     818                 :            : 
+     819                 :          1 :     case 0x1c: {
+     820                 :            :         spdm_capabilities_response_t *spdm_response;
+     821                 :            :         size_t spdm_response_size;
+     822                 :            :         size_t transport_header_size;
+     823                 :            : 
+     824                 :          1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     825                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     826                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     827                 :            : 
+     828                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     829                 :          1 :         spdm_response->header.spdm_version = 0xFF;
+     830                 :          1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     831                 :          1 :         spdm_response->header.param1 = 0;
+     832                 :          1 :         spdm_response->header.param2 = 0;
+     833                 :          1 :         spdm_response->ct_exponent = 0;
+     834                 :          1 :         spdm_response->flags =
+     835                 :            :             LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11;
+     836                 :            : 
+     837                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     838                 :            :                                               false, spdm_response_size,
+     839                 :            :                                               spdm_response,
+     840                 :            :                                               response_size, response);
+     841                 :            :     }
+     842                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     843                 :            : 
+     844                 :         18 :     case 0x1d: {
+     845                 :            :         static uint16_t error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
+     846                 :            : 
+     847                 :            :         spdm_error_response_t *spdm_response;
+     848                 :            :         size_t spdm_response_size;
+     849                 :            :         size_t transport_header_size;
+     850                 :            : 
+     851                 :         18 :         spdm_response_size = sizeof(spdm_error_response_t);
+     852                 :         18 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     853                 :         18 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     854                 :            : 
+     855         [ +  - ]:         18 :         if(error_code <= 0xff) {
+     856                 :         18 :             libspdm_zero_mem(spdm_response, spdm_response_size);
+     857                 :         18 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     858                 :         18 :             spdm_response->header.request_response_code = SPDM_ERROR;
+     859                 :         18 :             spdm_response->header.param1 = (uint8_t) error_code;
+     860                 :         18 :             spdm_response->header.param2 = 0;
+     861                 :            : 
+     862                 :         18 :             libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+     863                 :            :                                                    spdm_response_size, spdm_response,
+     864                 :            :                                                    response_size, response);
+     865                 :            :         }
+     866                 :            : 
+     867                 :         18 :         error_code++;
+     868         [ +  + ]:         18 :         if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
+     869                 :          1 :             error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
+     870                 :            :         }
+     871         [ +  + ]:         18 :         if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) { /*skip some reserved error codes (0d to 3e)*/
+     872                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
+     873                 :            :         }
+     874         [ +  + ]:         18 :         if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) { /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
+     875                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
+     876                 :            :         }
+     877                 :            :     }
+     878                 :         18 :         return LIBSPDM_STATUS_SUCCESS;
+     879                 :            : 
+     880                 :          1 :     case 0x1e: {
+     881                 :            :         spdm_capabilities_response_t *spdm_response;
+     882                 :            :         size_t spdm_response_size;
+     883                 :            :         size_t transport_header_size;
+     884                 :            : 
+     885                 :          1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     886                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     887                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     888                 :            : 
+     889                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     890                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     891                 :          1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     892                 :          1 :         spdm_response->header.param1 = 0;
+     893                 :          1 :         spdm_response->header.param2 = 0;
+     894                 :          1 :         spdm_response->ct_exponent = 0;
+     895                 :          1 :         spdm_response->flags = SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ALIAS_CERT_CAP;
+     896                 :            : 
+     897                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     898                 :            :                                               false, spdm_response_size,
+     899                 :            :                                               spdm_response,
+     900                 :            :                                               response_size, response);
+     901                 :            :     }
+     902                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     903                 :            : 
+     904                 :          1 :     case 0x1F:
+     905                 :          1 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+     906                 :            : 
+     907                 :          1 :     case 0x20: {
+     908                 :            :         spdm_capabilities_response_t *spdm_response;
+     909                 :            :         size_t spdm_response_size;
+     910                 :            :         size_t transport_header_size;
+     911                 :            : 
+     912                 :          1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     913                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     914                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     915                 :            : 
+     916                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     917                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     918                 :          1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     919                 :          1 :         spdm_response->header.param1 = 0;
+     920                 :          1 :         spdm_response->header.param2 = 0;
+     921                 :          1 :         spdm_response->ct_exponent = 0;
+     922                 :          1 :         spdm_response->flags = SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CSR_CAP;
+     923                 :            : 
+     924                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     925                 :            :                                               false, spdm_response_size,
+     926                 :            :                                               spdm_response,
+     927                 :            :                                               response_size, response);
+     928                 :            :     }
+     929                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     930                 :            : 
+     931                 :          1 :     case 0x21: {
+     932                 :            :         spdm_capabilities_response_t *spdm_response;
+     933                 :            :         size_t spdm_response_size;
+     934                 :            :         size_t transport_header_size;
+     935                 :            : 
+     936                 :          1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     937                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     938                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     939                 :            : 
+     940                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     941                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     942                 :          1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     943                 :          1 :         spdm_response->header.param1 = 0;
+     944                 :          1 :         spdm_response->header.param2 = 0;
+     945                 :          1 :         spdm_response->ct_exponent = 0;
+     946                 :          1 :         spdm_response->flags = SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_INSTALL_RESET_CAP;
+     947                 :          1 :         spdm_response->data_transfer_size = LIBSPDM_DATA_TRANSFER_SIZE;
+     948                 :          1 :         spdm_response->max_spdm_msg_size = LIBSPDM_MAX_SPDM_MSG_SIZE;
+     949                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     950                 :            :                                               false, spdm_response_size,
+     951                 :            :                                               spdm_response,
+     952                 :            :                                               response_size, response);
+     953                 :            :     }
+     954                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     955                 :          1 :     case 0x22: {
+     956                 :            :         spdm_capabilities_response_t *spdm_response;
+     957                 :            :         size_t spdm_response_size;
+     958                 :            :         size_t transport_header_size;
+     959                 :            : 
+     960                 :          1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     961                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     962                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     963                 :            : 
+     964                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     965                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     966                 :          1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     967                 :          1 :         spdm_response->header.param1 = 0;
+     968                 :          1 :         spdm_response->header.param2 = 0;
+     969                 :          1 :         spdm_response->ct_exponent = 0;
+     970                 :          1 :         spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+     971                 :          1 :         spdm_response->data_transfer_size = LIBSPDM_DATA_TRANSFER_SIZE;
+     972                 :          1 :         spdm_response->max_spdm_msg_size = LIBSPDM_MAX_SPDM_MSG_SIZE;
+     973                 :            : 
+     974                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     975                 :            :                                               false, spdm_response_size,
+     976                 :            :                                               spdm_response,
+     977                 :            :                                               response_size, response);
+     978                 :            :     }
+     979                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     980                 :            : 
+     981                 :          1 :     case 0x23: {
+     982                 :            :         spdm_capabilities_response_t *spdm_response;
+     983                 :            :         size_t spdm_response_size;
+     984                 :            :         size_t transport_header_size;
+     985                 :            : 
+     986                 :          1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     987                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     988                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     989                 :            : 
+     990                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     991                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     992                 :          1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     993                 :          1 :         spdm_response->header.param1 = 0;
+     994                 :          1 :         spdm_response->header.param2 = 0;
+     995                 :          1 :         spdm_response->ct_exponent = 0;
+     996                 :          1 :         spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+     997                 :          1 :         spdm_response->data_transfer_size = 0;
+     998                 :          1 :         spdm_response->max_spdm_msg_size = LIBSPDM_MAX_SPDM_MSG_SIZE;
+     999                 :            : 
+    1000                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1001                 :            :                                               false, spdm_response_size,
+    1002                 :            :                                               spdm_response,
+    1003                 :            :                                               response_size, response);
+    1004                 :            :     }
+    1005                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1006                 :            : 
+    1007                 :          1 :     case 0x24: {
+    1008                 :            :         spdm_capabilities_response_t *spdm_response;
+    1009                 :            :         size_t spdm_response_size;
+    1010                 :            :         size_t transport_header_size;
+    1011                 :            : 
+    1012                 :          1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+    1013                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1014                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1015                 :            : 
+    1016                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+    1017                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+    1018                 :          1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+    1019                 :          1 :         spdm_response->header.param1 = 0;
+    1020                 :          1 :         spdm_response->header.param2 = 0;
+    1021                 :          1 :         spdm_response->ct_exponent = 0;
+    1022                 :          1 :         spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+    1023                 :          1 :         spdm_response->data_transfer_size = LIBSPDM_DATA_TRANSFER_SIZE - 1;
+    1024                 :          1 :         spdm_response->max_spdm_msg_size = LIBSPDM_MAX_SPDM_MSG_SIZE;
+    1025                 :            : 
+    1026                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1027                 :            :                                               false, spdm_response_size,
+    1028                 :            :                                               spdm_response,
+    1029                 :            :                                               response_size, response);
+    1030                 :            :     }
+    1031                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1032                 :            : 
+    1033                 :          1 :     case 0x25: {
+    1034                 :            :         spdm_capabilities_response_t *spdm_response;
+    1035                 :            :         size_t spdm_response_size;
+    1036                 :            :         size_t transport_header_size;
+    1037                 :            : 
+    1038                 :          1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+    1039                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1040                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1041                 :            : 
+    1042                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+    1043                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+    1044                 :          1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+    1045                 :          1 :         spdm_response->header.param1 = 0;
+    1046                 :          1 :         spdm_response->header.param2 = 0;
+    1047                 :          1 :         spdm_response->ct_exponent = 0;
+    1048                 :          1 :         spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_12;
+    1049                 :          1 :         spdm_response->data_transfer_size = LIBSPDM_DATA_TRANSFER_SIZE;
+    1050                 :          1 :         spdm_response->max_spdm_msg_size = LIBSPDM_DATA_TRANSFER_SIZE - 1;
+    1051                 :            : 
+    1052                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1053                 :            :                                               false, spdm_response_size,
+    1054                 :            :                                               spdm_response,
+    1055                 :            :                                               response_size, response);
+    1056                 :            :     }
+    1057                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1058                 :            : 
+    1059                 :          1 :     case 0x26: {
+    1060                 :            :         spdm_capabilities_response_t *spdm_response;
+    1061                 :            :         size_t spdm_response_size;
+    1062                 :            :         size_t transport_header_size;
+    1063                 :            : 
+    1064                 :          1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+    1065                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1066                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1067                 :            : 
+    1068                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+    1069                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+    1070                 :          1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+    1071                 :          1 :         spdm_response->header.param1 = 0;
+    1072                 :          1 :         spdm_response->header.param2 = 0;
+    1073                 :          1 :         spdm_response->ct_exponent = LIBSPDM_MAX_CT_EXPONENT + 1;
+    1074                 :          1 :         spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_12;
+    1075                 :          1 :         spdm_response->data_transfer_size = LIBSPDM_DATA_TRANSFER_SIZE;
+    1076                 :          1 :         spdm_response->max_spdm_msg_size = LIBSPDM_MAX_SPDM_MSG_SIZE;
+    1077                 :            : 
+    1078                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1079                 :            :                                               false, spdm_response_size,
+    1080                 :            :                                               spdm_response,
+    1081                 :            :                                               response_size, response);
+    1082                 :            :     }
+    1083                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1084                 :            : 
+    1085                 :          0 :     default:
+    1086                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+    1087                 :            :     }
+    1088                 :            : }
+    1089                 :            : 
+    1090                 :          1 : static void libspdm_test_requester_get_capabilities_err_case1(void **state)
+    1091                 :            : {
+    1092                 :            :     libspdm_return_t status;
+    1093                 :            :     libspdm_test_context_t *spdm_test_context;
+    1094                 :            :     libspdm_context_t *spdm_context;
+    1095                 :            : 
+    1096                 :          1 :     spdm_test_context = *state;
+    1097                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1098                 :          1 :     spdm_test_context->case_id = 0x1;
+    1099                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1100                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1101                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1102                 :            : 
+    1103                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1104                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+    1105                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1106                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SEND_FAIL);
+    1107                 :          1 : }
+    1108                 :            : 
+    1109                 :            : /**
+    1110                 :            :  * Test 2: Responder sets MEAS_FRESH_CAP but does not set MEAS_CAP.
+    1111                 :            :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
+    1112                 :            :  **/
+    1113                 :          1 : static void libspdm_test_requester_get_capabilities_err_case2(void **state)
+    1114                 :            : {
+    1115                 :            :     libspdm_return_t status;
+    1116                 :            :     libspdm_test_context_t *spdm_test_context;
+    1117                 :            :     libspdm_context_t *spdm_context;
+    1118                 :            : 
+    1119                 :          1 :     spdm_test_context = *state;
+    1120                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1121                 :          1 :     spdm_test_context->case_id = 0x2;
+    1122                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1123                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1124                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1125                 :            : 
+    1126                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1127                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+    1128                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1129                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1130                 :          1 : }
+    1131                 :            : 
+    1132                 :          1 : static void libspdm_test_requester_get_capabilities_err_case3(void **state)
+    1133                 :            : {
+    1134                 :            :     libspdm_return_t status;
+    1135                 :            :     libspdm_test_context_t *spdm_test_context;
+    1136                 :            :     libspdm_context_t *spdm_context;
+    1137                 :            : 
+    1138                 :          1 :     spdm_test_context = *state;
+    1139                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1140                 :          1 :     spdm_test_context->case_id = 0x3;
+    1141                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1142                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1143                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NOT_STARTED;
+    1144                 :            : 
+    1145                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1146                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+    1147                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1148                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_STATE_LOCAL);
+    1149                 :          1 : }
+    1150                 :            : 
+    1151                 :          1 : static void libspdm_test_requester_get_capabilities_err_case4(void **state)
+    1152                 :            : {
+    1153                 :            :     libspdm_return_t status;
+    1154                 :            :     libspdm_test_context_t *spdm_test_context;
+    1155                 :            :     libspdm_context_t *spdm_context;
+    1156                 :            : 
+    1157                 :          1 :     spdm_test_context = *state;
+    1158                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1159                 :          1 :     spdm_test_context->case_id = 0x4;
+    1160                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1161                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1162                 :          1 :     spdm_context->connection_info.connection_state =
+    1163                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1164                 :            : 
+    1165                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1166                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+    1167                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1168                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_ERROR_PEER);
+    1169                 :          1 : }
+    1170                 :            : 
+    1171                 :          1 : static void libspdm_test_requester_get_capabilities_err_case5(void **state)
+    1172                 :            : {
+    1173                 :            :     libspdm_return_t status;
+    1174                 :            :     libspdm_test_context_t *spdm_test_context;
+    1175                 :            :     libspdm_context_t *spdm_context;
+    1176                 :            : 
+    1177                 :          1 :     spdm_test_context = *state;
+    1178                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1179                 :          1 :     spdm_test_context->case_id = 0x5;
+    1180                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1181                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1182                 :          1 :     spdm_context->connection_info.connection_state =
+    1183                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1184                 :            : 
+    1185                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1186                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+    1187                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1188                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_BUSY_PEER);
+    1189                 :          1 : }
+    1190                 :            : 
+    1191                 :            : /**
+    1192                 :            :  * Test 6: Responder sets illegal SPDM 1.0 combination of MEAS_CAP (no signature), CERT_CAP,
+    1193                 :            :  *         and CHAL_CAP.
+    1194                 :            :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
+    1195                 :            :  **/
+    1196                 :          1 : static void libspdm_test_requester_get_capabilities_err_case6(void **state)
+    1197                 :            : {
+    1198                 :            :     libspdm_return_t status;
+    1199                 :            :     libspdm_test_context_t *spdm_test_context;
+    1200                 :            :     libspdm_context_t *spdm_context;
+    1201                 :            : 
+    1202                 :          1 :     spdm_test_context = *state;
+    1203                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1204                 :          1 :     spdm_test_context->case_id = 0x6;
+    1205                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1206                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1207                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1208                 :            : 
+    1209                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1210                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+    1211                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1212                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1213                 :          1 : }
+    1214                 :            : 
+    1215                 :          1 : static void libspdm_test_requester_get_capabilities_err_case7(void **state)
+    1216                 :            : {
+    1217                 :            :     libspdm_return_t status;
+    1218                 :            :     libspdm_test_context_t *spdm_test_context;
+    1219                 :            :     libspdm_context_t *spdm_context;
+    1220                 :            : 
+    1221                 :          1 :     spdm_test_context = *state;
+    1222                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1223                 :          1 :     spdm_test_context->case_id = 0x7;
+    1224                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1225                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1226                 :          1 :     spdm_context->connection_info.connection_state =
+    1227                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1228                 :            : 
+    1229                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1230                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+    1231                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1232                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_RESYNCH_PEER);
+    1233                 :          1 :     assert_int_equal(spdm_context->connection_info.connection_state,
+    1234                 :            :                      LIBSPDM_CONNECTION_STATE_NOT_STARTED);
+    1235                 :          1 : }
+    1236                 :            : 
+    1237                 :          1 : static void libspdm_test_requester_get_capabilities_err_case8(void **state)
+    1238                 :            : {
+    1239                 :            :     libspdm_return_t status;
+    1240                 :            :     libspdm_test_context_t *spdm_test_context;
+    1241                 :            :     libspdm_context_t *spdm_context;
+    1242                 :            : 
+    1243                 :          1 :     spdm_test_context = *state;
+    1244                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1245                 :          1 :     spdm_test_context->case_id = 0x8;
+    1246                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1247                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1248                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1249                 :            : 
+    1250                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1251                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+    1252                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1253                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_NOT_READY_PEER);
+    1254                 :          1 : }
+    1255                 :            : 
+    1256                 :            : /**
+    1257                 :            :  * Test 9: Responder returns a Reserved MEAS_CAP value.
+    1258                 :            :  * Expected behavior: returns a status of LIBSPDM_STATUS_INVALID_MSG_FIELD.
+    1259                 :            :  **/
+    1260                 :          1 : static void libspdm_test_requester_get_capabilities_err_case9(void **state)
+    1261                 :            : {
+    1262                 :            :     libspdm_return_t status;
+    1263                 :            :     libspdm_test_context_t *spdm_test_context;
+    1264                 :            :     libspdm_context_t *spdm_context;
+    1265                 :            : 
+    1266                 :          1 :     spdm_test_context = *state;
+    1267                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1268                 :          1 :     spdm_test_context->case_id = 0x9;
+    1269                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1270                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1271                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1272                 :            : 
+    1273                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1274                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+    1275                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1276                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1277                 :          1 : }
+    1278                 :            : 
+    1279                 :            : /**
+    1280                 :            :  * Test 10: Responder sets illegal SPDM 1.0 combination of MEAS_CAP (with signature), CERT_CAP,
+    1281                 :            :  *          and CHAL_CAP.
+    1282                 :            :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
+    1283                 :            :  **/
+    1284                 :          1 : static void libspdm_test_requester_get_capabilities_err_case10(void **state)
+    1285                 :            : {
+    1286                 :            :     libspdm_return_t status;
+    1287                 :            :     libspdm_test_context_t *spdm_test_context;
+    1288                 :            :     libspdm_context_t *spdm_context;
+    1289                 :            : 
+    1290                 :          1 :     spdm_test_context = *state;
+    1291                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1292                 :          1 :     spdm_test_context->case_id = 0xa;
+    1293                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1294                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1295                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1296                 :            : 
+    1297                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1298                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+    1299                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1300                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1301                 :          1 : }
+    1302                 :            : 
+    1303                 :            : /**
+    1304                 :            :  * Test 11: Responder sets illegal 1.1/1.2 PSK_CAP value (3).
+    1305                 :            :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
+    1306                 :            :  **/
+    1307                 :          1 : static void libspdm_test_requester_get_capabilities_err_case11(void **state)
+    1308                 :            : {
+    1309                 :            :     libspdm_return_t status;
+    1310                 :            :     libspdm_test_context_t *spdm_test_context;
+    1311                 :            :     libspdm_context_t *spdm_context;
+    1312                 :            : 
+    1313                 :          1 :     spdm_test_context = *state;
+    1314                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1315                 :          1 :     spdm_test_context->case_id = 0xb;
+    1316                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1317                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1318                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1319                 :            : 
+    1320                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1321                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+    1322                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1323                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1324                 :          1 : }
+    1325                 :            : 
+    1326                 :            : /**
+    1327                 :            :  * Test 11: Responder sets illegal 1.1/1.2 combination of values.
+    1328                 :            :  *          CERT_CAP enabled.
+    1329                 :            :  *          CHAL_CAP and KEY_EX_CAP disabled.
+    1330                 :            :  *          MEAS_CAP with signature is disabled.
+    1331                 :            :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
+    1332                 :            :  **/
+    1333                 :          1 : static void libspdm_test_requester_get_capabilities_err_case12(void **state)
+    1334                 :            : {
+    1335                 :            :     libspdm_return_t status;
+    1336                 :            :     libspdm_test_context_t *spdm_test_context;
+    1337                 :            :     libspdm_context_t *spdm_context;
+    1338                 :            : 
+    1339                 :          1 :     spdm_test_context = *state;
+    1340                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1341                 :          1 :     spdm_test_context->case_id = 0xc;
+    1342                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1343                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1344                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1345                 :            : 
+    1346                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1347                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+    1348                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1349                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1350                 :          1 : }
+    1351                 :            : 
+    1352                 :          1 : static void libspdm_test_requester_get_capabilities_err_case13(void **state)
+    1353                 :            : {
+    1354                 :            :     libspdm_return_t status;
+    1355                 :            :     libspdm_test_context_t *spdm_test_context;
+    1356                 :            :     libspdm_context_t *spdm_context;
+    1357                 :            : 
+    1358                 :          1 :     spdm_test_context = *state;
+    1359                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1360                 :          1 :     spdm_test_context->case_id = 0xd;
+    1361                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1362                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1363                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1364                 :            : 
+    1365                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1366                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+    1367                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1368                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
+    1369                 :          1 : }
+    1370                 :            : 
+    1371                 :          1 : static void libspdm_test_requester_get_capabilities_err_case14(void **state)
+    1372                 :            : {
+    1373                 :            :     libspdm_return_t status;
+    1374                 :            :     libspdm_test_context_t *spdm_test_context;
+    1375                 :            :     libspdm_context_t *spdm_context;
+    1376                 :            : 
+    1377                 :          1 :     spdm_test_context = *state;
+    1378                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1379                 :          1 :     spdm_test_context->case_id = 0xe;
+    1380                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1381                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1382                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1383                 :            : 
+    1384                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1385                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+    1386                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1387                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
+    1388                 :          1 : }
+    1389                 :            : 
+    1390                 :          1 : static void libspdm_test_requester_get_capabilities_err_case15(void **state)
+    1391                 :            : {
+    1392                 :            :     libspdm_return_t status;
+    1393                 :            :     libspdm_test_context_t *spdm_test_context;
+    1394                 :            :     libspdm_context_t *spdm_context;
+    1395                 :            : 
+    1396                 :          1 :     spdm_test_context = *state;
+    1397                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1398                 :          1 :     spdm_test_context->case_id = 0xf;
+    1399                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1400                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1401                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1402                 :            : 
+    1403                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1404                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+    1405                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1406                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
+    1407                 :          1 : }
+    1408                 :            : 
+    1409                 :            : /**
+    1410                 :            :  * Test 16: Responder sets illegal 1.1/1.2 combination of values.
+    1411                 :            :  *          CERT_CAP and PUB_KEY_ID_CAP disabled.
+    1412                 :            :  *          At least one of CHAL_CAP, KEY_EX_CAP, MEAS_CAP (with signature), or MUT_AUTH_CAP
+    1413                 :            :  *          is enabled.
+    1414                 :            :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
+    1415                 :            :  **/
+    1416                 :          1 : static void libspdm_test_requester_get_capabilities_err_case16(void **state)
+    1417                 :            : {
+    1418                 :            :     libspdm_return_t status;
+    1419                 :            :     libspdm_test_context_t *spdm_test_context;
+    1420                 :            :     libspdm_context_t *spdm_context;
+    1421                 :            : 
+    1422                 :          1 :     spdm_test_context = *state;
+    1423                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1424                 :          1 :     spdm_test_context->case_id = 0x10;
+    1425                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1426                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1427                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1428                 :            : 
+    1429                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1430                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+    1431                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1432                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1433                 :          1 : }
+    1434                 :            : 
+    1435                 :          1 : static void libspdm_test_requester_get_capabilities_err_case17(void **state)
+    1436                 :            : {
+    1437                 :            :     libspdm_return_t status;
+    1438                 :            :     libspdm_test_context_t *spdm_test_context;
+    1439                 :            :     libspdm_context_t *spdm_context;
+    1440                 :            : 
+    1441                 :          1 :     spdm_test_context = *state;
+    1442                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1443                 :          1 :     spdm_test_context->case_id = 0x11;
+    1444                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1445                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1446                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1447                 :            : 
+    1448                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1449                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
+    1450                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1451                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1452                 :            :     /*assert_int_equal (spdm_context->connection_info.capability.ct_exponent, 0);
+    1453                 :            :      * assert_int_equal (spdm_context->connection_info.capability.flags, LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 & (0xFFFFFFFF^(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)));*/
+    1454                 :          1 : }
+    1455                 :            : 
+    1456                 :          1 : static void libspdm_test_requester_get_capabilities_err_case18(void **state)
+    1457                 :            : {
+    1458                 :            :     libspdm_return_t status;
+    1459                 :            :     libspdm_test_context_t *spdm_test_context;
+    1460                 :            :     libspdm_context_t *spdm_context;
+    1461                 :            : 
+    1462                 :          1 :     spdm_test_context = *state;
+    1463                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1464                 :          1 :     spdm_test_context->case_id = 0x12;
+    1465                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1466                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1467                 :          1 :     spdm_context->connection_info.connection_state =
+    1468                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1469                 :            : 
+    1470                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1471                 :          1 :     spdm_context->local_context.capability.flags =
+    1472                 :            :         LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
+    1473                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1474                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1475                 :            :     /*assert_int_equal (spdm_context->connection_info.capability.ct_exponent, 0);
+    1476                 :            :      * assert_int_equal (spdm_context->connection_info.capability.flags, LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 & (0xFFFFFFFF^(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)));*/
+    1477                 :          1 : }
+    1478                 :            : 
+    1479                 :          1 : static void libspdm_test_requester_get_capabilities_err_case19(void **state)
+    1480                 :            : {
+    1481                 :            :     libspdm_return_t status;
+    1482                 :            :     libspdm_test_context_t *spdm_test_context;
+    1483                 :            :     libspdm_context_t *spdm_context;
+    1484                 :            : 
+    1485                 :          1 :     spdm_test_context = *state;
+    1486                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1487                 :          1 :     spdm_test_context->case_id = 0x13;
+    1488                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1489                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1490                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1491                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1492                 :            : 
+    1493                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1494                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
+    1495                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1496                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1497                 :            :     /*assert_int_equal (spdm_context->connection_info.capability.ct_exponent, 0);
+    1498                 :            :      * assert_int_equal (spdm_context->connection_info.capability.flags, LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 & (0xFFFFFFFF^(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)));*/
+    1499                 :          1 : }
+    1500                 :            : 
+    1501                 :          1 : static void libspdm_test_requester_get_capabilities_err_case20(void **state)
+    1502                 :            : {
+    1503                 :            :     libspdm_return_t status;
+    1504                 :            :     libspdm_test_context_t *spdm_test_context;
+    1505                 :            :     libspdm_context_t *spdm_context;
+    1506                 :            : 
+    1507                 :          1 :     spdm_test_context = *state;
+    1508                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1509                 :          1 :     spdm_test_context->case_id = 0x14;
+    1510                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1511                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1512                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1513                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1514                 :            : 
+    1515                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1516                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
+    1517                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1518                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1519                 :            :     /*assert_int_equal (spdm_context->connection_info.capability.ct_exponent, 0);
+    1520                 :            :      * assert_int_equal (spdm_context->connection_info.capability.flags, LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 & (0xFFFFFFFF^(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)));*/
+    1521                 :          1 : }
+    1522                 :            : 
+    1523                 :          1 : static void libspdm_test_requester_get_capabilities_err_case21(void **state)
+    1524                 :            : {
+    1525                 :            :     libspdm_return_t status;
+    1526                 :            :     libspdm_test_context_t *spdm_test_context;
+    1527                 :            :     libspdm_context_t *spdm_context;
+    1528                 :            : 
+    1529                 :          1 :     spdm_test_context = *state;
+    1530                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1531                 :          1 :     spdm_test_context->case_id = 0x15;
+    1532                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1533                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1534                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1535                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1536                 :            : 
+    1537                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1538                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
+    1539                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1540                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1541                 :            :     /*assert_int_equal (spdm_context->connection_info.capability.ct_exponent, 0);
+    1542                 :            :      * assert_int_equal (spdm_context->connection_info.capability.flags, LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 & (0xFFFFFFFF^(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)));*/
+    1543                 :          1 : }
+    1544                 :            : 
+    1545                 :          1 : static void libspdm_test_requester_get_capabilities_err_case22(void **state)
+    1546                 :            : {
+    1547                 :            :     libspdm_return_t status;
+    1548                 :            :     libspdm_test_context_t *spdm_test_context;
+    1549                 :            :     libspdm_context_t *spdm_context;
+    1550                 :            : 
+    1551                 :          1 :     spdm_test_context = *state;
+    1552                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1553                 :          1 :     spdm_test_context->case_id = 0x16;
+    1554                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1555                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1556                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1557                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1558                 :            : 
+    1559                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1560                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
+    1561                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1562                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1563                 :            :     /*assert_int_equal (spdm_context->connection_info.capability.ct_exponent, 0);
+    1564                 :            :      * assert_int_equal (spdm_context->connection_info.capability.flags, LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 & (0xFFFFFFFF^(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)));*/
+    1565                 :          1 : }
+    1566                 :            : 
+    1567                 :          1 : static void libspdm_test_requester_get_capabilities_err_case23(void **state)
+    1568                 :            : {
+    1569                 :            :     libspdm_return_t status;
+    1570                 :            :     libspdm_test_context_t *spdm_test_context;
+    1571                 :            :     libspdm_context_t *spdm_context;
+    1572                 :            : 
+    1573                 :          1 :     spdm_test_context = *state;
+    1574                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1575                 :          1 :     spdm_test_context->case_id = 0x17;
+    1576                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1577                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1578                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1579                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1580                 :            : 
+    1581                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1582                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
+    1583                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1584                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1585                 :            :     /*assert_int_equal (spdm_context->connection_info.capability.ct_exponent, 0);
+    1586                 :            :      * assert_int_equal (spdm_context->connection_info.capability.flags, LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 & (0xFFFFFFFF^(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP)));*/
+    1587                 :          1 : }
+    1588                 :            : 
+    1589                 :          1 : static void libspdm_test_requester_get_capabilities_err_case24(void **state)
+    1590                 :            : {
+    1591                 :            :     libspdm_return_t status;
+    1592                 :            :     libspdm_test_context_t *spdm_test_context;
+    1593                 :            :     libspdm_context_t *spdm_context;
+    1594                 :            : 
+    1595                 :          1 :     spdm_test_context = *state;
+    1596                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1597                 :          1 :     spdm_test_context->case_id = 0x18;
+    1598                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1599                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1600                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1601                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1602                 :            : 
+    1603                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1604                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
+    1605                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1606                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1607                 :            :     /*assert_int_equal (spdm_context->connection_info.capability.ct_exponent, 0);
+    1608                 :            :      * assert_int_equal (spdm_context->connection_info.capability.flags, LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 & (0xFFFFFFFF^(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP)));*/
+    1609                 :          1 : }
+    1610                 :            : 
+    1611                 :          1 : static void libspdm_test_requester_get_capabilities_err_case25(void **state)
+    1612                 :            : {
+    1613                 :            :     libspdm_return_t status;
+    1614                 :            :     libspdm_test_context_t *spdm_test_context;
+    1615                 :            :     libspdm_context_t *spdm_context;
+    1616                 :            : 
+    1617                 :          1 :     spdm_test_context = *state;
+    1618                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1619                 :          1 :     spdm_test_context->case_id = 0x19;
+    1620                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1621                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1622                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1623                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1624                 :            : 
+    1625                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1626                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
+    1627                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1628                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1629                 :            :     /*assert_int_equal (spdm_context->connection_info.capability.ct_exponent, 0);
+    1630                 :            :      * assert_int_equal (spdm_context->connection_info.capability.flags, LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 & (0xFFFFFFFF^(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP)));*/
+    1631                 :          1 : }
+    1632                 :            : 
+    1633                 :          1 : static void libspdm_test_requester_get_capabilities_err_case26(void **state)
+    1634                 :            : {
+    1635                 :            :     libspdm_return_t status;
+    1636                 :            :     libspdm_test_context_t *spdm_test_context;
+    1637                 :            :     libspdm_context_t *spdm_context;
+    1638                 :            : 
+    1639                 :          1 :     spdm_test_context = *state;
+    1640                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1641                 :          1 :     spdm_test_context->case_id = 0x1a;
+    1642                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1643                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1644                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1645                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1646                 :            : 
+    1647                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1648                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
+    1649                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1650                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1651                 :            :     /*assert_int_equal (spdm_context->connection_info.capability.ct_exponent, 0);
+    1652                 :            :      * assert_int_equal (spdm_context->connection_info.capability.flags, LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PUB_KEY_ID_CAP);*/
+    1653                 :          1 : }
+    1654                 :            : 
+    1655                 :          1 : static void libspdm_test_requester_get_capabilities_err_case27(void **state)
+    1656                 :            : {
+    1657                 :            :     libspdm_return_t status;
+    1658                 :            :     libspdm_test_context_t *spdm_test_context;
+    1659                 :            :     libspdm_context_t *spdm_context;
+    1660                 :            : 
+    1661                 :          1 :     spdm_test_context = *state;
+    1662                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1663                 :          1 :     spdm_test_context->case_id = 0x1b;
+    1664                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1665                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1666                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1667                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1668                 :            : 
+    1669                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1670                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
+    1671                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1672                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1673                 :          1 : }
+    1674                 :            : 
+    1675                 :          1 : static void libspdm_test_requester_get_capabilities_err_case28(void **state)
+    1676                 :            : {
+    1677                 :            :     libspdm_return_t status;
+    1678                 :            :     libspdm_test_context_t *spdm_test_context;
+    1679                 :            :     libspdm_context_t *spdm_context;
+    1680                 :            : 
+    1681                 :          1 :     spdm_test_context = *state;
+    1682                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1683                 :          1 :     spdm_test_context->case_id = 0x1c;
+    1684                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1685                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1686                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1687                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1688                 :            : 
+    1689                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1690                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
+    1691                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1692                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1693                 :          1 : }
+    1694                 :            : 
+    1695                 :          1 : static void libspdm_test_requester_get_capabilities_err_case29(void **state) {
+    1696                 :            :     libspdm_return_t status;
+    1697                 :            :     libspdm_test_context_t    *spdm_test_context;
+    1698                 :            :     libspdm_context_t  *spdm_context;
+    1699                 :            :     uint16_t error_code;
+    1700                 :            : 
+    1701                 :          1 :     spdm_test_context = *state;
+    1702                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1703                 :          1 :     spdm_test_context->case_id = 0x1d;
+    1704                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1705                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1706                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1707                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
+    1708                 :            : 
+    1709                 :          1 :     error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
+    1710         [ +  + ]:         19 :     while(error_code <= 0xff) {
+    1711                 :         18 :         spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1712                 :         18 :         libspdm_reset_message_a(spdm_context);
+    1713                 :            : 
+    1714                 :         18 :         status = libspdm_get_capabilities (spdm_context);
+    1715         [ -  + ]:         18 :         LIBSPDM_ASSERT_INT_EQUAL_CASE (status, LIBSPDM_STATUS_ERROR_PEER, error_code);
+    1716                 :            : 
+    1717                 :         18 :         error_code++;
+    1718         [ +  + ]:         18 :         if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
+    1719                 :          1 :             error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
+    1720                 :            :         }
+    1721         [ +  + ]:         18 :         if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) { /*skip some reserved error codes (0d to 3e)*/
+    1722                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
+    1723                 :            :         }
+    1724         [ +  + ]:         18 :         if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) { /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
+    1725                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
+    1726                 :            :         }
+    1727                 :            :     }
+    1728                 :          1 : }
+    1729                 :            : 
+    1730                 :            : /**
+    1731                 :            :  * Test 30: Responder sets illegal 1.2 combination of values.
+    1732                 :            :  *          CERT_CAP is disabled.
+    1733                 :            :  *          ALIAS_CERT_CAP is enabled.
+    1734                 :            :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
+    1735                 :            :  **/
+    1736                 :          1 : static void libspdm_test_requester_get_capabilities_err_case30(void **state)
+    1737                 :            : {
+    1738                 :            :     libspdm_return_t status;
+    1739                 :            :     libspdm_test_context_t *spdm_test_context;
+    1740                 :            :     libspdm_context_t *spdm_context;
+    1741                 :            : 
+    1742                 :          1 :     spdm_test_context = *state;
+    1743                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1744                 :          1 :     spdm_test_context->case_id = 0x1E;
+    1745                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    1746                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1747                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1748                 :            : 
+    1749                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1750                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+    1751                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1752                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1753                 :          1 : }
+    1754                 :            : 
+    1755                 :          1 : static void libspdm_test_requester_get_capabilities_err_case31(void **state)
+    1756                 :            : {
+    1757                 :            :     libspdm_return_t status;
+    1758                 :            :     libspdm_test_context_t *spdm_test_context;
+    1759                 :            :     libspdm_context_t *spdm_context;
+    1760                 :            : 
+    1761                 :          1 :     spdm_test_context = *state;
+    1762                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1763                 :          1 :     spdm_test_context->case_id = 0x1F;
+    1764                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1765                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1766                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1767                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1768                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+    1769                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1770                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_RECEIVE_FAIL);
+    1771                 :          1 : }
+    1772                 :            : 
+    1773                 :            : /**
+    1774                 :            :  * Test 32: Responder sets illegal 1.2 combination of values.
+    1775                 :            :  *          CSR_CAP is enabled.
+    1776                 :            :  *          SET_CERT_CAP is disabled.
+    1777                 :            :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
+    1778                 :            :  **/
+    1779                 :          1 : static void libspdm_test_requester_get_capabilities_err_case32(void **state)
+    1780                 :            : {
+    1781                 :            :     libspdm_return_t status;
+    1782                 :            :     libspdm_test_context_t *spdm_test_context;
+    1783                 :            :     libspdm_context_t *spdm_context;
+    1784                 :            : 
+    1785                 :          1 :     spdm_test_context = *state;
+    1786                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1787                 :          1 :     spdm_test_context->case_id = 0x20;
+    1788                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    1789                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1790                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1791                 :            : 
+    1792                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1793                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+    1794                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1795                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1796                 :          1 : }
+    1797                 :            : 
+    1798                 :            : /**
+    1799                 :            :  * Test 33: Responder sets illegal 1.2 combination of values.
+    1800                 :            :  *          CERT_INSTALL_RESET_CAP is enabled.
+    1801                 :            :  *          CSR_CAP and SET_CERT_CAP are disabled.
+    1802                 :            :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
+    1803                 :            :  **/
+    1804                 :          1 : static void libspdm_test_requester_get_capabilities_err_case33(void **state)
+    1805                 :            : {
+    1806                 :            :     libspdm_return_t status;
+    1807                 :            :     libspdm_test_context_t *spdm_test_context;
+    1808                 :            :     libspdm_context_t *spdm_context;
+    1809                 :            : 
+    1810                 :          1 :     spdm_test_context = *state;
+    1811                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1812                 :          1 :     spdm_test_context->case_id = 0x21;
+    1813                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    1814                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1815                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1816                 :            : 
+    1817                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1818                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+    1819                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1820                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1821                 :          1 : }
+    1822                 :            : 
+    1823                 :          1 : static void libspdm_test_requester_get_capabilities_err_case34(void **state)
+    1824                 :            : {
+    1825                 :            :     libspdm_return_t status;
+    1826                 :            :     libspdm_test_context_t *spdm_test_context;
+    1827                 :            :     libspdm_context_t *spdm_context;
+    1828                 :            : 
+    1829                 :          1 :     spdm_test_context = *state;
+    1830                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1831                 :          1 :     spdm_test_context->case_id = 0x22;
+    1832                 :            : 
+    1833                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    1834                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1835                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1836                 :          1 :     spdm_context->transcript.message_a.buffer_size =
+    1837                 :          1 :         spdm_context->transcript.message_a.max_buffer_size;
+    1838                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1839                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+    1840                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1841                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_BUFFER_FULL);
+    1842                 :            : 
+    1843                 :          1 :     spdm_context->transcript.message_a.buffer_size = 0;
+    1844                 :          1 : }
+    1845                 :            : 
+    1846                 :            : /**
+    1847                 :            :  * Test 35: Unable to acquire sender buffer.
+    1848                 :            :  * Expected behavior: returns with status LIBSPDM_STATUS_ACQUIRE_FAIL.
+    1849                 :            :  **/
+    1850                 :          1 : static void libspdm_test_requester_get_capabilities_err_case35(void **state)
+    1851                 :            : {
+    1852                 :            :     libspdm_return_t status;
+    1853                 :            :     libspdm_test_context_t *spdm_test_context;
+    1854                 :            :     libspdm_context_t *spdm_context;
+    1855                 :            : 
+    1856                 :          1 :     spdm_test_context = *state;
+    1857                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1858                 :          1 :     spdm_test_context->case_id = 0x3;
+    1859                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1860                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1861                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1862                 :            : 
+    1863                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1864                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+    1865                 :            : 
+    1866                 :          1 :     libspdm_force_error (LIBSPDM_ERR_ACQUIRE_SENDER_BUFFER);
+    1867                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1868                 :          1 :     libspdm_release_error (LIBSPDM_ERR_ACQUIRE_SENDER_BUFFER);
+    1869                 :            : 
+    1870                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_ACQUIRE_FAIL);
+    1871                 :          1 : }
+    1872                 :            : 
+    1873                 :            : /**
+    1874                 :            :  * Test 36: Unable to acquire receiver buffer.
+    1875                 :            :  * Expected behavior: returns with status LIBSPDM_STATUS_ACQUIRE_FAIL.
+    1876                 :            :  **/
+    1877                 :          1 : static void libspdm_test_requester_get_capabilities_err_case36(void **state)
+    1878                 :            : {
+    1879                 :            :     libspdm_return_t status;
+    1880                 :            :     libspdm_test_context_t *spdm_test_context;
+    1881                 :            :     libspdm_context_t *spdm_context;
+    1882                 :            : 
+    1883                 :          1 :     spdm_test_context = *state;
+    1884                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1885                 :          1 :     spdm_test_context->case_id = 0x3;
+    1886                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1887                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1888                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1889                 :            : 
+    1890                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1891                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+    1892                 :            : 
+    1893                 :          1 :     libspdm_force_error (LIBSPDM_ERR_ACQUIRE_RECEIVER_BUFFER);
+    1894                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1895                 :          1 :     libspdm_release_error (LIBSPDM_ERR_ACQUIRE_RECEIVER_BUFFER);
+    1896                 :            : 
+    1897                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_ACQUIRE_FAIL);
+    1898                 :          1 : }
+    1899                 :            : 
+    1900                 :            : /**
+    1901                 :            :  * Test 37: Responder sets illegal DataTransferSize that is less than MinDataTransferSize.
+    1902                 :            :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
+    1903                 :            :  **/
+    1904                 :          1 : static void libspdm_test_requester_get_capabilities_err_case37(void **state)
+    1905                 :            : {
+    1906                 :            :     libspdm_return_t status;
+    1907                 :            :     libspdm_test_context_t *spdm_test_context;
+    1908                 :            :     libspdm_context_t *spdm_context;
+    1909                 :            : 
+    1910                 :          1 :     spdm_test_context = *state;
+    1911                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1912                 :          1 :     spdm_test_context->case_id = 0x23;
+    1913                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    1914                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1915                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1916                 :            : 
+    1917                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1918                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+    1919                 :            : 
+    1920                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1921                 :            : 
+    1922                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1923                 :          1 : }
+    1924                 :            : 
+    1925                 :            : /**
+    1926                 :            :  * Test 38: Responder does not support chunking but also does not set DataTransferSize equal
+    1927                 :            :  *          to MaxSPDMmsgSize.
+    1928                 :            :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
+    1929                 :            :  **/
+    1930                 :          1 : static void libspdm_test_requester_get_capabilities_err_case38(void **state)
+    1931                 :            : {
+    1932                 :            :     libspdm_return_t status;
+    1933                 :            :     libspdm_test_context_t *spdm_test_context;
+    1934                 :            :     libspdm_context_t *spdm_context;
+    1935                 :            : 
+    1936                 :          1 :     spdm_test_context = *state;
+    1937                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1938                 :          1 :     spdm_test_context->case_id = 0x24;
+    1939                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    1940                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1941                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1942                 :            : 
+    1943                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1944                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+    1945                 :            : 
+    1946                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1947                 :            : 
+    1948                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1949                 :          1 : }
+    1950                 :            : 
+    1951                 :            : /**
+    1952                 :            :  * Test 39: Responder sets illegal MaxSPDMmsgSize that is less than DataTransferSize.
+    1953                 :            :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
+    1954                 :            :  **/
+    1955                 :          1 : static void libspdm_test_requester_get_capabilities_err_case39(void **state)
+    1956                 :            : {
+    1957                 :            :     libspdm_return_t status;
+    1958                 :            :     libspdm_test_context_t *spdm_test_context;
+    1959                 :            :     libspdm_context_t *spdm_context;
+    1960                 :            : 
+    1961                 :          1 :     spdm_test_context = *state;
+    1962                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1963                 :          1 :     spdm_test_context->case_id = 0x25;
+    1964                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    1965                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1966                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1967                 :            : 
+    1968                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1969                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+    1970                 :            : 
+    1971                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1972                 :            : 
+    1973                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1974                 :          1 : }
+    1975                 :            : 
+    1976                 :            : /**
+    1977                 :            :  * Test 40: Responder returns a CTExponent value that is larger than LIBSPDM_MAX_CT_EXPONENT.
+    1978                 :            :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
+    1979                 :            :  **/
+    1980                 :          1 : static void libspdm_test_requester_get_capabilities_err_case40(void **state)
+    1981                 :            : {
+    1982                 :            :     libspdm_return_t status;
+    1983                 :            :     libspdm_test_context_t *spdm_test_context;
+    1984                 :            :     libspdm_context_t *spdm_context;
+    1985                 :            : 
+    1986                 :          1 :     spdm_test_context = *state;
+    1987                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1988                 :          1 :     spdm_test_context->case_id = 0x26;
+    1989                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    1990                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1991                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1992                 :            : 
+    1993                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1994                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+    1995                 :            : 
+    1996                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1997                 :            : 
+    1998                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1999                 :          1 : }
+    2000                 :            : 
+    2001                 :            : static libspdm_test_context_t m_libspdm_requester_get_capabilities_test_context = {
+    2002                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+    2003                 :            :     true,
+    2004                 :            :     libspdm_requester_get_capabilities_test_send_message,
+    2005                 :            :     libspdm_requester_get_capabilities_test_receive_message,
+    2006                 :            : };
+    2007                 :            : 
+    2008                 :          1 : int libspdm_requester_get_capabilities_error_test_main(void)
+    2009                 :            : {
+    2010                 :          1 :     const struct CMUnitTest m_spdm_requester_get_capabilities_tests[] = {
+    2011                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case1),
+    2012                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case2),
+    2013                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case3),
+    2014                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case4),
+    2015                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case5),
+    2016                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case6),
+    2017                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case7),
+    2018                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case8),
+    2019                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case9),
+    2020                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case10),
+    2021                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case11),
+    2022                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case12),
+    2023                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case13),
+    2024                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case14),
+    2025                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case15),
+    2026                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case16),
+    2027                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case17),
+    2028                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case18),
+    2029                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case19),
+    2030                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case20),
+    2031                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case21),
+    2032                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case22),
+    2033                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case23),
+    2034                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case24),
+    2035                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case25),
+    2036                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case26),
+    2037                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case27),
+    2038                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case28),
+    2039                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case29),
+    2040                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case30),
+    2041                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case31),
+    2042                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case32),
+    2043                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case33),
+    2044                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case34),
+    2045                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case35),
+    2046                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case36),
+    2047                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case37),
+    2048                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case38),
+    2049                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case39),
+    2050                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case40),
+    2051                 :            :     };
+    2052                 :            : 
+    2053                 :          1 :     libspdm_setup_test_context(&m_libspdm_requester_get_capabilities_test_context);
+    2054                 :            : 
+    2055                 :          1 :     return cmocka_run_group_tests(m_spdm_requester_get_capabilities_tests,
+    2056                 :            :                                   libspdm_unit_test_group_setup,
+    2057                 :            :                                   libspdm_unit_test_group_teardown);
+    2058                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/error_test/get_digests_err.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_requester/error_test/get_digests_err.c.func-sort-c.html new file mode 100644 index 00000000000..74d91c1fc6e --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/error_test/get_digests_err.c.func-sort-c.html @@ -0,0 +1,181 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/error_test/get_digests_err.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester/error_test - get_digests_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:40868859.3 %
Date:2024-09-22 08:21:07Functions:2525100.0 %
Branches:409243.5 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_get_digests_error_test_main1
libspdm_test_requester_get_digests_err_case11
libspdm_test_requester_get_digests_err_case101
libspdm_test_requester_get_digests_err_case111
libspdm_test_requester_get_digests_err_case121
libspdm_test_requester_get_digests_err_case131
libspdm_test_requester_get_digests_err_case141
libspdm_test_requester_get_digests_err_case151
libspdm_test_requester_get_digests_err_case161
libspdm_test_requester_get_digests_err_case171
libspdm_test_requester_get_digests_err_case181
libspdm_test_requester_get_digests_err_case21
libspdm_test_requester_get_digests_err_case221
libspdm_test_requester_get_digests_err_case231
libspdm_test_requester_get_digests_err_case241
libspdm_test_requester_get_digests_err_case251
libspdm_test_requester_get_digests_err_case31
libspdm_test_requester_get_digests_err_case41
libspdm_test_requester_get_digests_err_case51
libspdm_test_requester_get_digests_err_case61
libspdm_test_requester_get_digests_err_case71
libspdm_test_requester_get_digests_err_case81
libspdm_test_requester_get_digests_err_case91
libspdm_requester_get_digests_test_receive_message28
libspdm_requester_get_digests_test_send_message30
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/error_test/get_digests_err.c.func.html b/coverage_log/unit_test/test_spdm_requester/error_test/get_digests_err.c.func.html new file mode 100644 index 00000000000..ab5aa0ea0c4 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/error_test/get_digests_err.c.func.html @@ -0,0 +1,181 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/error_test/get_digests_err.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester/error_test - get_digests_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:40868859.3 %
Date:2024-09-22 08:21:07Functions:2525100.0 %
Branches:409243.5 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_get_digests_error_test_main1
libspdm_requester_get_digests_test_receive_message28
libspdm_requester_get_digests_test_send_message30
libspdm_test_requester_get_digests_err_case11
libspdm_test_requester_get_digests_err_case101
libspdm_test_requester_get_digests_err_case111
libspdm_test_requester_get_digests_err_case121
libspdm_test_requester_get_digests_err_case131
libspdm_test_requester_get_digests_err_case141
libspdm_test_requester_get_digests_err_case151
libspdm_test_requester_get_digests_err_case161
libspdm_test_requester_get_digests_err_case171
libspdm_test_requester_get_digests_err_case181
libspdm_test_requester_get_digests_err_case21
libspdm_test_requester_get_digests_err_case221
libspdm_test_requester_get_digests_err_case231
libspdm_test_requester_get_digests_err_case241
libspdm_test_requester_get_digests_err_case251
libspdm_test_requester_get_digests_err_case31
libspdm_test_requester_get_digests_err_case41
libspdm_test_requester_get_digests_err_case51
libspdm_test_requester_get_digests_err_case61
libspdm_test_requester_get_digests_err_case71
libspdm_test_requester_get_digests_err_case81
libspdm_test_requester_get_digests_err_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/error_test/get_digests_err.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/error_test/get_digests_err.c.gcov.html new file mode 100644 index 00000000000..e4fedc3c799 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/error_test/get_digests_err.c.gcov.html @@ -0,0 +1,1728 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/error_test/get_digests_err.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester/error_test - get_digests_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:40868859.3 %
Date:2024-09-22 08:21:07Functions:2525100.0 %
Branches:409243.5 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_requester_lib.h"
+       9                 :            : #include "internal/libspdm_secured_message_lib.h"
+      10                 :            : 
+      11                 :            : #if LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT
+      12                 :            : 
+      13                 :            : static uint8_t m_libspdm_local_certificate_chain[LIBSPDM_MAX_CERT_CHAIN_SIZE];
+      14                 :            : 
+      15                 :            : static void *m_libspdm_local_certificate_chain_test_cert;
+      16                 :            : static size_t m_libspdm_local_certificate_chain_size;
+      17                 :            : 
+      18                 :            : static size_t m_libspdm_local_buffer_size;
+      19                 :            : static uint8_t m_libspdm_local_buffer[LIBSPDM_MAX_MESSAGE_M1M2_BUFFER_SIZE];
+      20                 :            : 
+      21                 :            : static bool m_get_digest;
+      22                 :            : 
+      23                 :         30 : static libspdm_return_t libspdm_requester_get_digests_test_send_message(
+      24                 :            :     void *spdm_context, size_t request_size, const void *request,
+      25                 :            :     uint64_t timeout)
+      26                 :            : {
+      27                 :            :     libspdm_test_context_t *spdm_test_context;
+      28                 :            : 
+      29                 :         30 :     spdm_test_context = libspdm_get_test_context();
+      30   [ +  +  -  +  :         30 :     switch (spdm_test_context->case_id) {
+          +  -  +  +  +  
+          -  +  -  +  +  
+          -  -  -  +  -  
+          -  -  +  -  -  
+                   -  - ]
+      31                 :          1 :     case 0x1:
+      32                 :          1 :         return LIBSPDM_STATUS_SEND_FAIL;
+      33                 :          1 :     case 0x2:
+      34                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      35                 :          0 :     case 0x3:
+      36                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      37                 :          1 :     case 0x4:
+      38                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      39                 :          1 :     case 0x5:
+      40                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      41                 :          0 :     case 0x6:
+      42                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      43                 :          1 :     case 0x7:
+      44                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      45                 :          2 :     case 0x8:
+      46                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+      47                 :          1 :     case 0x9:
+      48                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      49                 :          0 :     case 0xA:
+      50                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      51                 :          1 :     case 0xB:
+      52                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      53                 :          0 :     case 0xC:
+      54                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      55                 :          1 :     case 0xD:
+      56                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      57                 :          1 :     case 0xE:
+      58                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      59                 :          0 :     case 0xF:
+      60                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      61                 :          0 :     case 0x10:
+      62                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      63                 :          0 :     case 0x11:
+      64                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      65                 :          1 :     case 0x12:
+      66                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      67                 :          0 :     case 0x13:
+      68                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      69                 :          0 :     case 0x14:
+      70                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      71                 :          0 :     case 0x15:
+      72                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      73                 :         18 :     case 0x16:
+      74                 :         18 :         return LIBSPDM_STATUS_SUCCESS;
+      75                 :          0 :     case 0x17: {
+      76                 :          0 :         const uint8_t *ptr = (const uint8_t *)request;
+      77                 :            : 
+      78                 :          0 :         m_libspdm_local_buffer_size = 0;
+      79                 :          0 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+      80                 :          0 :                          &ptr[1], request_size - 1);
+      81                 :          0 :         m_libspdm_local_buffer_size += (request_size - 1);
+      82                 :            :     }
+      83                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      84                 :          0 :     case 0x18:
+      85                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      86                 :          0 :     case 0x19:
+      87                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      88                 :          0 :     default:
+      89                 :          0 :         return LIBSPDM_STATUS_SEND_FAIL;
+      90                 :            :     }
+      91                 :            : }
+      92                 :            : 
+      93                 :         28 : static libspdm_return_t libspdm_requester_get_digests_test_receive_message(
+      94                 :            :     void *spdm_context, size_t *response_size,
+      95                 :            :     void **response, uint64_t timeout)
+      96                 :            : {
+      97                 :            :     libspdm_test_context_t *spdm_test_context;
+      98                 :            : 
+      99                 :         28 :     spdm_test_context = libspdm_get_test_context();
+     100   [ -  -  -  +  :         28 :     switch (spdm_test_context->case_id) {
+          +  -  +  +  +  
+          -  +  -  +  +  
+          -  -  -  +  -  
+          -  -  +  -  -  
+                   -  - ]
+     101                 :          0 :     case 0x1:
+     102                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+     103                 :            : 
+     104                 :          0 :     case 0x2: {
+     105                 :            :         spdm_digest_response_t *spdm_response;
+     106                 :            :         uint8_t *digest;
+     107                 :            :         size_t spdm_response_size;
+     108                 :            :         size_t transport_header_size;
+     109                 :            : 
+     110                 :            :         ((libspdm_context_t *)spdm_context)
+     111                 :          0 :         ->connection_info.algorithm.base_hash_algo =
+     112                 :            :             m_libspdm_use_hash_algo;
+     113                 :          0 :         spdm_response_size = sizeof(spdm_digest_response_t) +
+     114                 :          0 :                              libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     115                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     116                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     117                 :            : 
+     118                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     119                 :          0 :         spdm_response->header.param1 = 0;
+     120                 :          0 :         spdm_response->header.request_response_code = SPDM_DIGESTS;
+     121                 :          0 :         spdm_response->header.param2 = 0;
+     122                 :          0 :         libspdm_set_mem(m_libspdm_local_certificate_chain,
+     123                 :            :                         sizeof(m_libspdm_local_certificate_chain),
+     124                 :            :                         (uint8_t)(0xFF));
+     125                 :            : 
+     126                 :          0 :         digest = (void *)(spdm_response + 1);
+     127                 :          0 :         libspdm_zero_mem (digest,
+     128                 :          0 :                           libspdm_get_hash_size(m_libspdm_use_hash_algo) *
+     129                 :            :                           (SPDM_MAX_SLOT_COUNT - 1));
+     130                 :          0 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
+     131                 :            :                          sizeof(m_libspdm_local_certificate_chain), &digest[0]);
+     132                 :          0 :         spdm_response->header.param2 |= (0x01 << 0);
+     133                 :            : 
+     134                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     135                 :            :                                               false, spdm_response_size,
+     136                 :            :                                               spdm_response, response_size,
+     137                 :            :                                               response);
+     138                 :            :     }
+     139                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     140                 :            : 
+     141                 :          0 :     case 0x3: {
+     142                 :            :         spdm_digest_response_t *spdm_response;
+     143                 :            :         uint8_t *digest;
+     144                 :            :         size_t spdm_response_size;
+     145                 :            :         size_t transport_header_size;
+     146                 :            : 
+     147                 :            :         ((libspdm_context_t *)spdm_context)
+     148                 :          0 :         ->connection_info.algorithm.base_hash_algo =
+     149                 :            :             m_libspdm_use_hash_algo;
+     150                 :          0 :         spdm_response_size = sizeof(spdm_digest_response_t) +
+     151                 :          0 :                              libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     152                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     153                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     154                 :            : 
+     155                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     156                 :          0 :         spdm_response->header.param1 = 0;
+     157                 :          0 :         spdm_response->header.request_response_code = SPDM_DIGESTS;
+     158                 :          0 :         spdm_response->header.param2 = 0;
+     159                 :          0 :         libspdm_set_mem(m_libspdm_local_certificate_chain,
+     160                 :            :                         sizeof(m_libspdm_local_certificate_chain),
+     161                 :            :                         (uint8_t)(0xFF));
+     162                 :            : 
+     163                 :          0 :         digest = (void *)(spdm_response + 1);
+     164                 :          0 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
+     165                 :            :                          sizeof(m_libspdm_local_certificate_chain), &digest[0]);
+     166                 :          0 :         spdm_response->header.param2 |= (1 << 0);
+     167                 :            : 
+     168                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     169                 :            :                                               false, spdm_response_size,
+     170                 :            :                                               spdm_response, response_size,
+     171                 :            :                                               response);
+     172                 :            :     }
+     173                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     174                 :            : 
+     175                 :          1 :     case 0x4: {
+     176                 :            :         spdm_error_response_t *spdm_response;
+     177                 :            :         size_t spdm_response_size;
+     178                 :            :         size_t transport_header_size;
+     179                 :            : 
+     180                 :          1 :         spdm_response_size = sizeof(spdm_error_response_t);
+     181                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     182                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     183                 :            : 
+     184                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     185                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     186                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_INVALID_REQUEST;
+     187                 :          1 :         spdm_response->header.param2 = 0;
+     188                 :            : 
+     189                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     190                 :            :                                               false, spdm_response_size,
+     191                 :            :                                               spdm_response,
+     192                 :            :                                               response_size, response);
+     193                 :            :     }
+     194                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     195                 :            : 
+     196                 :          1 :     case 0x5: {
+     197                 :            :         spdm_error_response_t *spdm_response;
+     198                 :            :         size_t spdm_response_size;
+     199                 :            :         size_t transport_header_size;
+     200                 :            : 
+     201                 :          1 :         spdm_response_size = sizeof(spdm_error_response_t);
+     202                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     203                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     204                 :            : 
+     205                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     206                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     207                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
+     208                 :          1 :         spdm_response->header.param2 = 0;
+     209                 :            : 
+     210                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     211                 :            :                                               false, spdm_response_size,
+     212                 :            :                                               spdm_response,
+     213                 :            :                                               response_size, response);
+     214                 :            :     }
+     215                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     216                 :            : 
+     217                 :          0 :     case 0x6: {
+     218                 :            :         static size_t sub_index1 = 0;
+     219         [ #  # ]:          0 :         if (sub_index1 == 0) {
+     220                 :            :             spdm_error_response_t *spdm_response;
+     221                 :            :             size_t spdm_response_size;
+     222                 :            :             size_t transport_header_size;
+     223                 :            : 
+     224                 :          0 :             spdm_response_size = sizeof(spdm_error_response_t);
+     225                 :          0 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     226                 :          0 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     227                 :            : 
+     228                 :          0 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     229                 :          0 :             spdm_response->header.request_response_code = SPDM_ERROR;
+     230                 :          0 :             spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
+     231                 :          0 :             spdm_response->header.param2 = 0;
+     232                 :            : 
+     233                 :          0 :             libspdm_transport_test_encode_message(
+     234                 :            :                 spdm_context, NULL, false, false,
+     235                 :            :                 spdm_response_size, spdm_response,
+     236                 :            :                 response_size, response);
+     237         [ #  # ]:          0 :         } else if (sub_index1 == 1) {
+     238                 :            :             spdm_digest_response_t *spdm_response;
+     239                 :            :             uint8_t *digest;
+     240                 :            :             size_t spdm_response_size;
+     241                 :            :             size_t transport_header_size;
+     242                 :            : 
+     243                 :            :             ((libspdm_context_t *)spdm_context)
+     244                 :          0 :             ->connection_info.algorithm.base_hash_algo =
+     245                 :            :                 m_libspdm_use_hash_algo;
+     246                 :          0 :             spdm_response_size = sizeof(spdm_digest_response_t) +
+     247                 :          0 :                                  libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     248                 :          0 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     249                 :          0 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     250                 :            : 
+     251                 :          0 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     252                 :          0 :             spdm_response->header.param1 = 0;
+     253                 :          0 :             spdm_response->header.request_response_code = SPDM_DIGESTS;
+     254                 :          0 :             spdm_response->header.param2 = 0;
+     255                 :          0 :             libspdm_set_mem(m_libspdm_local_certificate_chain,
+     256                 :            :                             sizeof(m_libspdm_local_certificate_chain), (uint8_t)(0xFF));
+     257                 :            : 
+     258                 :          0 :             digest = (void *)(spdm_response + 1);
+     259                 :          0 :             libspdm_hash_all(m_libspdm_use_hash_algo,
+     260                 :            :                              m_libspdm_local_certificate_chain,
+     261                 :            :                              sizeof(m_libspdm_local_certificate_chain), &digest[0]);
+     262                 :          0 :             spdm_response->header.param2 |= (1 << 0);
+     263                 :            : 
+     264                 :          0 :             libspdm_transport_test_encode_message(
+     265                 :            :                 spdm_context, NULL, false, false, spdm_response_size,
+     266                 :            :                 spdm_response, response_size, response);
+     267                 :            :         }
+     268                 :          0 :         sub_index1++;
+     269                 :            :     }
+     270                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     271                 :            : 
+     272                 :          1 :     case 0x7: {
+     273                 :            :         spdm_error_response_t *spdm_response;
+     274                 :            :         size_t spdm_response_size;
+     275                 :            :         size_t transport_header_size;
+     276                 :            : 
+     277                 :          1 :         spdm_response_size = sizeof(spdm_error_response_t);
+     278                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     279                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     280                 :            : 
+     281                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     282                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     283                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_REQUEST_RESYNCH;
+     284                 :          1 :         spdm_response->header.param2 = 0;
+     285                 :            : 
+     286                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     287                 :            :                                               false, spdm_response_size,
+     288                 :            :                                               spdm_response,
+     289                 :            :                                               response_size, response);
+     290                 :            :     }
+     291                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     292                 :            : 
+     293                 :          2 :     case 0x8: {
+     294                 :            :         spdm_error_response_data_response_not_ready_t *spdm_response;
+     295                 :            :         size_t spdm_response_size;
+     296                 :            :         size_t transport_header_size;
+     297                 :            : 
+     298                 :          2 :         spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
+     299                 :          2 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     300                 :          2 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     301                 :            : 
+     302                 :          2 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     303                 :          2 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     304                 :          2 :         spdm_response->header.param1 = SPDM_ERROR_CODE_RESPONSE_NOT_READY;
+     305                 :          2 :         spdm_response->header.param2 = 0;
+     306                 :          2 :         spdm_response->extend_error_data.rd_exponent = 1;
+     307                 :          2 :         spdm_response->extend_error_data.rd_tm = 2;
+     308                 :          2 :         spdm_response->extend_error_data.request_code = SPDM_GET_DIGESTS;
+     309                 :          2 :         spdm_response->extend_error_data.token = 0;
+     310                 :            : 
+     311                 :          2 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     312                 :            :                                               false, spdm_response_size,
+     313                 :            :                                               spdm_response,
+     314                 :            :                                               response_size, response);
+     315                 :            :     }
+     316                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     317                 :            : 
+     318                 :          1 :     case 0x9: {
+     319                 :            :         spdm_digest_response_t *spdm_response;
+     320                 :            :         uint8_t *digest;
+     321                 :            :         size_t spdm_response_size;
+     322                 :            :         size_t transport_header_size;
+     323                 :            : 
+     324                 :          1 :         ((libspdm_context_t *)spdm_context)->connection_info.algorithm.base_hash_algo =
+     325                 :            :             m_libspdm_use_hash_algo;
+     326                 :          1 :         spdm_response_size = sizeof(spdm_digest_response_t) +
+     327                 :          1 :                              libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     328                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     329                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     330                 :            : 
+     331                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     332                 :          1 :         spdm_response->header.param1 = 0;
+     333                 :          1 :         spdm_response->header.request_response_code = SPDM_DIGESTS;
+     334                 :          1 :         spdm_response->header.param2 = 0;
+     335                 :          1 :         libspdm_set_mem(m_libspdm_local_certificate_chain,
+     336                 :            :                         sizeof(m_libspdm_local_certificate_chain),
+     337                 :            :                         (uint8_t)(0xFF));
+     338                 :            : 
+     339                 :          1 :         digest = (void *)(spdm_response + 1);
+     340                 :          1 :         libspdm_zero_mem (digest,
+     341                 :          1 :                           libspdm_get_hash_size(m_libspdm_use_hash_algo) * SPDM_MAX_SLOT_COUNT);
+     342                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
+     343                 :            :                          sizeof(m_libspdm_local_certificate_chain), &digest[0]);
+     344                 :          1 :         spdm_response->header.param2 |= (0x01 << 0);
+     345                 :            : 
+     346                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     347                 :            :                                               false, spdm_response_size,
+     348                 :            :                                               spdm_response, response_size,
+     349                 :            :                                               response);
+     350                 :            :     }
+     351                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     352                 :            : 
+     353                 :          0 :     case 0xA:
+     354                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     355                 :            : 
+     356                 :          1 :     case 0xB:
+     357                 :          1 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+     358                 :            : 
+     359                 :          0 :     case 0xC: {
+     360                 :            :         spdm_digest_response_t *spdm_response;
+     361                 :            :         size_t spdm_response_size;
+     362                 :            :         size_t transport_header_size;
+     363                 :            : 
+     364                 :            :         ((libspdm_context_t *)spdm_context)
+     365                 :          0 :         ->connection_info.algorithm.base_hash_algo =
+     366                 :            :             m_libspdm_use_hash_algo;
+     367                 :          0 :         spdm_response_size = 2;
+     368                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     369                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     370                 :            : 
+     371                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     372                 :          0 :         spdm_response->header.param1 = 0;
+     373                 :          0 :         spdm_response->header.request_response_code = SPDM_DIGESTS;
+     374                 :          0 :         spdm_response->header.param2 = 0;
+     375                 :            : 
+     376                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     377                 :            :                                               false, spdm_response_size,
+     378                 :            :                                               spdm_response, response_size,
+     379                 :            :                                               response);
+     380                 :            :     }
+     381                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     382                 :            : 
+     383                 :          1 :     case 0xD: {
+     384                 :            :         spdm_digest_response_t *spdm_response;
+     385                 :            :         uint8_t *digest;
+     386                 :            :         size_t spdm_response_size;
+     387                 :            :         size_t transport_header_size;
+     388                 :            : 
+     389                 :            :         ((libspdm_context_t *)spdm_context)
+     390                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+     391                 :            :             m_libspdm_use_hash_algo;
+     392                 :          1 :         spdm_response_size = sizeof(spdm_digest_response_t) +
+     393                 :          1 :                              libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     394                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     395                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     396                 :            : 
+     397                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     398                 :          1 :         spdm_response->header.param1 = 0;
+     399                 :          1 :         spdm_response->header.request_response_code = SPDM_CERTIFICATE;
+     400                 :          1 :         spdm_response->header.param2 = 0;
+     401                 :          1 :         libspdm_set_mem(m_libspdm_local_certificate_chain,
+     402                 :            :                         sizeof(m_libspdm_local_certificate_chain),
+     403                 :            :                         (uint8_t)(0xFF));
+     404                 :            : 
+     405                 :          1 :         digest = (void *)(spdm_response + 1);
+     406                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
+     407                 :            :                          sizeof(m_libspdm_local_certificate_chain), &digest[0]);
+     408                 :          1 :         spdm_response->header.param2 |= (1 << 0);
+     409                 :            : 
+     410                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     411                 :            :                                               false, spdm_response_size,
+     412                 :            :                                               spdm_response, response_size,
+     413                 :            :                                               response);
+     414                 :            :     }
+     415                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     416                 :            : 
+     417                 :          1 :     case 0xE: {
+     418                 :            :         spdm_digest_response_t *spdm_response;
+     419                 :            :         size_t spdm_response_size;
+     420                 :            :         size_t transport_header_size;
+     421                 :            : 
+     422                 :          1 :         spdm_response_size = sizeof(spdm_digest_response_t);
+     423                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     424                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     425                 :            : 
+     426                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     427                 :          1 :         spdm_response->header.param1 = 0;
+     428                 :          1 :         spdm_response->header.request_response_code = SPDM_DIGESTS;
+     429                 :          1 :         spdm_response->header.param2 = 0;
+     430                 :            : 
+     431                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     432                 :            :                                               false, spdm_response_size,
+     433                 :            :                                               spdm_response,
+     434                 :            :                                               response_size, response);
+     435                 :            :     }
+     436                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     437                 :            : 
+     438                 :          0 :     case 0xF:
+     439                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     440                 :            : 
+     441                 :          0 :     case 0x10: {
+     442                 :            :         spdm_digest_response_t *spdm_response;
+     443                 :            :         uint8_t *digest;
+     444                 :            :         size_t spdm_response_size;
+     445                 :            :         size_t transport_header_size;
+     446                 :            : 
+     447                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     448                 :            :         ((libspdm_context_t *)spdm_context)->transcript.message_b.buffer_size =
+     449                 :            :             ((libspdm_context_t *)spdm_context)->transcript.message_b.max_buffer_size -
+     450                 :            :             (sizeof(spdm_digest_response_t));
+     451                 :            : #endif
+     452                 :            : 
+     453                 :            :         ((libspdm_context_t *)spdm_context)
+     454                 :          0 :         ->connection_info.algorithm.base_hash_algo =
+     455                 :            :             m_libspdm_use_hash_algo;
+     456                 :          0 :         spdm_response_size = sizeof(spdm_digest_response_t) +
+     457                 :          0 :                              libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     458                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     459                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     460                 :            : 
+     461                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     462                 :          0 :         spdm_response->header.param1 = 0;
+     463                 :          0 :         spdm_response->header.request_response_code = SPDM_DIGESTS;
+     464                 :          0 :         spdm_response->header.param2 = 0;
+     465                 :          0 :         libspdm_set_mem(m_libspdm_local_certificate_chain,
+     466                 :            :                         sizeof(m_libspdm_local_certificate_chain),
+     467                 :            :                         (uint8_t)(0xFF));
+     468                 :            : 
+     469                 :          0 :         digest = (void *)(spdm_response + 1);
+     470                 :          0 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
+     471                 :            :                          sizeof(m_libspdm_local_certificate_chain), &digest[0]);
+     472                 :          0 :         spdm_response->header.param2 |= (1 << 0);
+     473                 :            : 
+     474                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     475                 :            :                                               false, spdm_response_size,
+     476                 :            :                                               spdm_response, response_size,
+     477                 :            :                                               response);
+     478                 :            :     }
+     479                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     480                 :            : 
+     481                 :          0 :     case 0x11:
+     482                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     483                 :            : 
+     484                 :          1 :     case 0x12: {
+     485                 :            :         spdm_digest_response_t *spdm_response;
+     486                 :            :         uint8_t *digest;
+     487                 :            :         size_t digest_count;
+     488                 :            :         size_t spdm_response_size;
+     489                 :            :         size_t transport_header_size;
+     490                 :            :         size_t index;
+     491                 :            : 
+     492                 :            :         ((libspdm_context_t *)spdm_context)
+     493                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+     494                 :            :             m_libspdm_use_hash_algo;
+     495                 :          1 :         digest_count = 4;
+     496                 :          1 :         spdm_response_size = sizeof(spdm_digest_response_t) +
+     497                 :          1 :                              libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     498                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     499                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     500                 :            : 
+     501                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     502                 :          1 :         spdm_response->header.param1 = 0;
+     503                 :          1 :         spdm_response->header.request_response_code = SPDM_DIGESTS;
+     504                 :          1 :         spdm_response->header.param2 = 0;
+     505                 :          1 :         libspdm_set_mem(m_libspdm_local_certificate_chain,
+     506                 :            :                         sizeof(m_libspdm_local_certificate_chain),
+     507                 :            :                         (uint8_t)(0xFF));
+     508                 :            : 
+     509                 :          1 :         digest = (void *)(spdm_response + 1);
+     510                 :            : 
+     511                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
+     512                 :            :                          sizeof(m_libspdm_local_certificate_chain), &digest[0]);
+     513         [ +  + ]:          5 :         for (index = 0; index < digest_count; index++) {
+     514                 :          4 :             spdm_response->header.param2 |= (1 << index);
+     515                 :            :         }
+     516                 :            : 
+     517                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     518                 :            :                                               false, spdm_response_size,
+     519                 :            :                                               spdm_response, response_size,
+     520                 :            :                                               response);
+     521                 :            :     }
+     522                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     523                 :            : 
+     524                 :          0 :     case 0x13: {
+     525                 :            :         spdm_digest_response_t *spdm_response;
+     526                 :            :         uint8_t *digest;
+     527                 :            :         size_t digest_count;
+     528                 :            :         size_t spdm_response_size;
+     529                 :            :         size_t transport_header_size;
+     530                 :            :         size_t index;
+     531                 :            : 
+     532                 :            :         ((libspdm_context_t *)spdm_context)
+     533                 :          0 :         ->connection_info.algorithm.base_hash_algo =
+     534                 :            :             m_libspdm_use_hash_algo;
+     535                 :          0 :         digest_count = 4;
+     536                 :          0 :         spdm_response_size =
+     537                 :            :             sizeof(spdm_digest_response_t) +
+     538                 :          0 :             digest_count * libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     539                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     540                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     541                 :            : 
+     542                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     543                 :          0 :         spdm_response->header.param1 = 0;
+     544                 :          0 :         spdm_response->header.request_response_code = SPDM_DIGESTS;
+     545                 :          0 :         spdm_response->header.param2 = 0;
+     546                 :          0 :         libspdm_set_mem(m_libspdm_local_certificate_chain,
+     547                 :            :                         sizeof(m_libspdm_local_certificate_chain),
+     548                 :            :                         (uint8_t)(0xFF));
+     549                 :            : 
+     550                 :          0 :         digest = (void *)(spdm_response + 1);
+     551                 :            : 
+     552         [ #  # ]:          0 :         for (index = 0; index < digest_count; index++) {
+     553                 :          0 :             libspdm_hash_all(
+     554                 :            :                 m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
+     555                 :            :                 sizeof(m_libspdm_local_certificate_chain),
+     556                 :          0 :                 &digest[index *
+     557                 :          0 :                         libspdm_get_hash_size(m_libspdm_use_hash_algo)]);
+     558                 :          0 :             spdm_response->header.param2 |= (1 << index);
+     559         [ #  # ]:          0 :             if (index == 0) {
+     560                 :          0 :                 continue;
+     561                 :            :             }
+     562                 :          0 :             digest[(index + 1) * libspdm_get_hash_size(m_libspdm_use_hash_algo) -
+     563                 :          0 :                    1] = 0;
+     564                 :            :         }
+     565                 :            : 
+     566                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     567                 :            :                                               false, spdm_response_size,
+     568                 :            :                                               spdm_response, response_size,
+     569                 :            :                                               response);
+     570                 :            :     }
+     571                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     572                 :            : 
+     573                 :          0 :     case 0x14: {
+     574                 :            :         spdm_digest_response_t *spdm_response;
+     575                 :            :         size_t spdm_response_size;
+     576                 :            :         size_t transport_header_size;
+     577                 :            : 
+     578                 :          0 :         ((libspdm_context_t *)spdm_context)->connection_info.algorithm.base_hash_algo =
+     579                 :            :             m_libspdm_use_hash_algo;
+     580                 :          0 :         spdm_response_size = 5;
+     581                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     582                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     583                 :            : 
+     584                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     585                 :          0 :         spdm_response->header.param1 = 0;
+     586                 :          0 :         spdm_response->header.request_response_code = SPDM_DIGESTS;
+     587                 :          0 :         spdm_response->header.param2 = 0;
+     588                 :            : 
+     589                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     590                 :            :                                               false, spdm_response_size,
+     591                 :            :                                               spdm_response, response_size,
+     592                 :            :                                               response);
+     593                 :            :     }
+     594                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     595                 :            : 
+     596                 :          0 :     case 0x15: {
+     597                 :            :         spdm_digest_response_t *spdm_response;
+     598                 :            :         uint8_t *digest;
+     599                 :            :         size_t spdm_response_size;
+     600                 :            :         size_t transport_header_size;
+     601                 :            : 
+     602                 :            :         ((libspdm_context_t *)spdm_context)
+     603                 :          0 :         ->connection_info.algorithm.base_hash_algo =
+     604                 :            :             m_libspdm_use_hash_algo;
+     605                 :          0 :         spdm_response_size = sizeof(spdm_message_header_t) +
+     606                 :            :                              LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT + 1;
+     607                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     608                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     609                 :            : 
+     610                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     611                 :          0 :         spdm_response->header.param1 = 0;
+     612                 :          0 :         spdm_response->header.request_response_code = SPDM_DIGESTS;
+     613                 :          0 :         spdm_response->header.param2 = 0;
+     614                 :          0 :         libspdm_set_mem(m_libspdm_local_certificate_chain,
+     615                 :            :                         sizeof(m_libspdm_local_certificate_chain),
+     616                 :            :                         (uint8_t)(0xFF));
+     617                 :            : 
+     618                 :          0 :         digest = (void *)(spdm_response + 1);
+     619                 :          0 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
+     620                 :            :                          sizeof(m_libspdm_local_certificate_chain), &digest[0]);
+     621                 :          0 :         spdm_response->header.param2 |= (1 << 0);
+     622                 :            : 
+     623                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     624                 :            :                                               false, spdm_response_size,
+     625                 :            :                                               spdm_response, response_size,
+     626                 :            :                                               response);
+     627                 :            :     }
+     628                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     629                 :            : 
+     630                 :         18 :     case 0x16:
+     631                 :            :     {
+     632                 :            :         static uint16_t error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
+     633                 :            : 
+     634                 :            :         spdm_error_response_t *spdm_response;
+     635                 :            :         size_t spdm_response_size;
+     636                 :            :         size_t transport_header_size;
+     637                 :            : 
+     638                 :         18 :         spdm_response_size = sizeof(spdm_error_response_t);
+     639                 :         18 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     640                 :         18 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     641                 :            : 
+     642         [ +  - ]:         18 :         if(error_code <= 0xff) {
+     643                 :         18 :             libspdm_zero_mem (spdm_response, spdm_response_size);
+     644                 :         18 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     645                 :         18 :             spdm_response->header.request_response_code = SPDM_ERROR;
+     646                 :         18 :             spdm_response->header.param1 = (uint8_t) error_code;
+     647                 :         18 :             spdm_response->header.param2 = 0;
+     648                 :            : 
+     649                 :         18 :             libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+     650                 :            :                                                    spdm_response_size, spdm_response,
+     651                 :            :                                                    response_size, response);
+     652                 :            :         }
+     653                 :            : 
+     654                 :         18 :         error_code++;
+     655         [ +  + ]:         18 :         if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
+     656                 :          1 :             error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
+     657                 :            :         }
+     658         [ +  + ]:         18 :         if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) { /*skip some reserved error codes (0d to 3e)*/
+     659                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
+     660                 :            :         }
+     661         [ +  + ]:         18 :         if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) { /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
+     662                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
+     663                 :            :         }
+     664                 :            :     }
+     665                 :         18 :         return LIBSPDM_STATUS_SUCCESS;
+     666                 :            : 
+     667                 :          0 :     case 0x17: {
+     668                 :            :         spdm_digest_response_t *spdm_response;
+     669                 :            :         uint8_t *digest;
+     670                 :            :         size_t spdm_response_size;
+     671                 :            :         size_t transport_header_size;
+     672                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     673                 :            :         size_t arbitrary_size;
+     674                 :            : #endif
+     675                 :            : 
+     676                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     677                 :            :         /*filling B with arbitrary data*/
+     678                 :            :         arbitrary_size = 8;
+     679                 :            :         libspdm_set_mem(((libspdm_context_t *)spdm_context)->transcript.message_b.buffer,
+     680                 :            :                         arbitrary_size, (uint8_t) 0xEE);
+     681                 :            :         ((libspdm_context_t *)spdm_context)->transcript.message_b.buffer_size =
+     682                 :            :             arbitrary_size;
+     683                 :            : #endif
+     684                 :            : 
+     685                 :          0 :         ((libspdm_context_t *)spdm_context)->connection_info.algorithm.base_hash_algo =
+     686                 :            :             m_libspdm_use_hash_algo;
+     687                 :          0 :         spdm_response_size = sizeof(spdm_digest_response_t) +
+     688                 :          0 :                              libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     689                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     690                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     691                 :            : 
+     692                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     693                 :          0 :         spdm_response->header.param1 = 0;
+     694                 :          0 :         spdm_response->header.request_response_code = SPDM_DIGESTS;
+     695                 :          0 :         spdm_response->header.param2 = 0;
+     696                 :          0 :         libspdm_set_mem(m_libspdm_local_certificate_chain,
+     697                 :            :                         sizeof(m_libspdm_local_certificate_chain),
+     698                 :            :                         (uint8_t)(0xFF));
+     699                 :            : 
+     700                 :          0 :         digest = (void *)(spdm_response + 1);
+     701                 :          0 :         libspdm_set_mem(digest, libspdm_get_hash_size(m_libspdm_use_hash_algo), (uint8_t)(0xFF));
+     702                 :          0 :         spdm_response->header.param2 |= (0x01 << 0);
+     703                 :            : 
+     704                 :          0 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+     705                 :            :                          sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
+     706                 :            :                          spdm_response, spdm_response_size);
+     707                 :          0 :         m_libspdm_local_buffer_size += spdm_response_size;
+     708                 :            : 
+     709                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     710                 :            :                                               false, spdm_response_size,
+     711                 :            :                                               spdm_response, response_size,
+     712                 :            :                                               response);
+     713                 :            :     }
+     714                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     715                 :            : 
+     716                 :          0 :     case 0x18: {
+     717         [ #  # ]:          0 :         if (m_get_digest) {
+     718                 :            :             spdm_digest_response_t *spdm_response;
+     719                 :            :             uint8_t *digest;
+     720                 :            :             size_t spdm_response_size;
+     721                 :            :             size_t transport_header_size;
+     722                 :            : 
+     723                 :            :             ((libspdm_context_t *)spdm_context)
+     724                 :          0 :             ->connection_info.algorithm.base_hash_algo =
+     725                 :            :                 m_libspdm_use_hash_algo;
+     726                 :          0 :             spdm_response_size = sizeof(spdm_digest_response_t) +
+     727                 :          0 :                                  libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     728                 :          0 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     729                 :          0 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     730                 :            : 
+     731                 :          0 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     732                 :          0 :             spdm_response->header.param1 = 0;
+     733                 :          0 :             spdm_response->header.request_response_code = SPDM_DIGESTS;
+     734                 :          0 :             spdm_response->header.param2 = 0;
+     735                 :          0 :             libspdm_set_mem(m_libspdm_local_certificate_chain,
+     736                 :            :                             sizeof(m_libspdm_local_certificate_chain),
+     737                 :            :                             (uint8_t)(0xFF));
+     738                 :            : 
+     739                 :          0 :             digest = (void *)(spdm_response + 1);
+     740                 :          0 :             libspdm_zero_mem (digest,
+     741                 :          0 :                               libspdm_get_hash_size(m_libspdm_use_hash_algo) * SPDM_MAX_SLOT_COUNT);
+     742                 :          0 :             libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
+     743                 :            :                              sizeof(m_libspdm_local_certificate_chain), &digest[0]);
+     744                 :          0 :             spdm_response->header.param2 |= (0x01 << 0);
+     745                 :            : 
+     746                 :          0 :             libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     747                 :            :                                                   false, spdm_response_size,
+     748                 :            :                                                   spdm_response, response_size,
+     749                 :            :                                                   response);
+     750                 :            :         } else {
+     751                 :            :             spdm_certificate_response_t *spdm_response;
+     752                 :            :             size_t spdm_response_size;
+     753                 :            :             size_t transport_header_size;
+     754                 :            :             uint16_t portion_length;
+     755                 :            :             uint16_t remainder_length;
+     756                 :            :             size_t count;
+     757                 :            :             static size_t calling_index = 0;
+     758                 :            : 
+     759         [ #  # ]:          0 :             if (m_libspdm_local_certificate_chain_test_cert == NULL) {
+     760                 :          0 :                 libspdm_read_responder_public_certificate_chain(
+     761                 :            :                     m_libspdm_use_hash_algo, m_libspdm_use_asym_algo,
+     762                 :            :                     &m_libspdm_local_certificate_chain_test_cert,
+     763                 :            :                     &m_libspdm_local_certificate_chain_size, NULL, NULL);
+     764                 :            :             }
+     765         [ #  # ]:          0 :             if (m_libspdm_local_certificate_chain_test_cert == NULL) {
+     766                 :          0 :                 return LIBSPDM_STATUS_RECEIVE_FAIL;
+     767                 :            :             }
+     768                 :          0 :             count = (m_libspdm_local_certificate_chain_size +
+     769                 :          0 :                      LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN - 1) /
+     770                 :            :                     LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN;
+     771         [ #  # ]:          0 :             if (calling_index != count - 1) {
+     772                 :          0 :                 portion_length = LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN;
+     773                 :          0 :                 remainder_length =
+     774                 :          0 :                     (uint16_t)(m_libspdm_local_certificate_chain_size -
+     775                 :            :                                LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN *
+     776                 :          0 :                                (calling_index + 1));
+     777                 :            :             } else {
+     778                 :          0 :                 portion_length = (uint16_t)(
+     779                 :            :                     m_libspdm_local_certificate_chain_size -
+     780                 :          0 :                     LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN * (count - 1));
+     781                 :          0 :                 remainder_length = 0;
+     782                 :            :             }
+     783                 :            : 
+     784                 :          0 :             spdm_response_size =
+     785                 :          0 :                 sizeof(spdm_certificate_response_t) + portion_length;
+     786                 :          0 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     787                 :          0 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     788                 :            : 
+     789                 :          0 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     790                 :          0 :             spdm_response->header.request_response_code = SPDM_CERTIFICATE;
+     791                 :          0 :             spdm_response->header.param1 = 0;
+     792                 :          0 :             spdm_response->header.param2 = 0;
+     793                 :          0 :             spdm_response->portion_length = portion_length;
+     794                 :          0 :             spdm_response->remainder_length = remainder_length;
+     795                 :          0 :             libspdm_copy_mem(spdm_response + 1,
+     796                 :          0 :                              (size_t)(*response) + *response_size - (size_t)(spdm_response + 1),
+     797                 :          0 :                              (uint8_t *)m_libspdm_local_certificate_chain_test_cert +
+     798                 :          0 :                              LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN * calling_index,
+     799                 :            :                              portion_length);
+     800                 :            : 
+     801                 :          0 :             libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     802                 :            :                                                   false, spdm_response_size,
+     803                 :            :                                                   spdm_response, response_size,
+     804                 :            :                                                   response);
+     805                 :            : 
+     806                 :          0 :             calling_index++;
+     807         [ #  # ]:          0 :             if (calling_index == count) {
+     808                 :          0 :                 calling_index = 0;
+     809                 :          0 :                 free(m_libspdm_local_certificate_chain_test_cert);
+     810                 :          0 :                 m_libspdm_local_certificate_chain_test_cert = NULL;
+     811                 :          0 :                 m_libspdm_local_certificate_chain_size = 0;
+     812                 :            :             }
+     813                 :            :         }
+     814                 :            :     }
+     815                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     816                 :            : 
+     817                 :          0 :     case 0x19: {
+     818                 :            :         spdm_digest_response_t *spdm_response;
+     819                 :            :         uint8_t *digest;
+     820                 :            :         size_t spdm_response_size;
+     821                 :            :         size_t transport_header_size;
+     822                 :            :         uint32_t session_id;
+     823                 :            :         libspdm_session_info_t *session_info;
+     824                 :            :         uint8_t *scratch_buffer;
+     825                 :            :         size_t scratch_buffer_size;
+     826                 :            : 
+     827                 :          0 :         session_id = 0xFFFFFFFF;
+     828                 :            : 
+     829                 :            :         ((libspdm_context_t *)spdm_context)
+     830                 :          0 :         ->connection_info.algorithm.base_hash_algo =
+     831                 :            :             m_libspdm_use_hash_algo;
+     832                 :          0 :         spdm_response_size = sizeof(spdm_digest_response_t) +
+     833                 :          0 :                              libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     834                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     835                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     836                 :            : 
+     837                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     838                 :          0 :         spdm_response->header.param1 = 0;
+     839                 :          0 :         spdm_response->header.request_response_code = SPDM_DIGESTS;
+     840                 :          0 :         spdm_response->header.param2 = 0;
+     841                 :            : 
+     842                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+     843                 :            :          * transport_message is always in sender buffer. */
+     844                 :          0 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+     845                 :            : 
+     846                 :          0 :         libspdm_set_mem(m_libspdm_local_certificate_chain,
+     847                 :            :                         sizeof(m_libspdm_local_certificate_chain),
+     848                 :            :                         (uint8_t)(0xFF));
+     849                 :            : 
+     850                 :          0 :         digest = (void *)(spdm_response + 1);
+     851                 :          0 :         libspdm_zero_mem (digest,
+     852                 :          0 :                           libspdm_get_hash_size(m_libspdm_use_hash_algo) * SPDM_MAX_SLOT_COUNT);
+     853                 :          0 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
+     854                 :            :                          sizeof(m_libspdm_local_certificate_chain), &digest[0]);
+     855                 :          0 :         spdm_response->header.param2 |= (0x01 << 0);
+     856                 :            : 
+     857                 :          0 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+     858                 :            :                           scratch_buffer_size - transport_header_size,
+     859                 :            :                           spdm_response, spdm_response_size);
+     860                 :          0 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+     861                 :          0 :         libspdm_transport_test_encode_message(spdm_context, &session_id, false,
+     862                 :            :                                               false, spdm_response_size,
+     863                 :            :                                               spdm_response, response_size,
+     864                 :            :                                               response);
+     865                 :            : 
+     866                 :          0 :         session_info = libspdm_get_session_info_via_session_id(
+     867                 :            :             spdm_context, session_id);
+     868         [ #  # ]:          0 :         if (session_info == NULL) {
+     869                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+     870                 :            :         }
+     871                 :            :         /* WALKAROUND: If just use single context to encode message and then decode message */
+     872                 :            :         ((libspdm_secured_message_context_t
+     873                 :          0 :           *)(session_info->secured_message_context))
+     874                 :          0 :         ->application_secret.response_data_sequence_number--;
+     875                 :            : 
+     876                 :            :     }
+     877                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     878                 :            : 
+     879                 :          0 :     default:
+     880                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+     881                 :            :     }
+     882                 :            : }
+     883                 :            : 
+     884                 :            : /**
+     885                 :            :  * Test 1: a failure occurs during the sending of the request message
+     886                 :            :  * Expected Behavior: requester returns the status LIBSPDM_STATUS_SEND_FAIL, with no DIGESTS message received
+     887                 :            :  **/
+     888                 :          1 : static void libspdm_test_requester_get_digests_err_case1(void **state)
+     889                 :            : {
+     890                 :            :     libspdm_return_t status;
+     891                 :            :     libspdm_test_context_t *spdm_test_context;
+     892                 :            :     libspdm_context_t *spdm_context;
+     893                 :            :     uint8_t slot_mask;
+     894                 :            :     uint8_t total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
+     895                 :            : 
+     896                 :          1 :     spdm_test_context = *state;
+     897                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     898                 :          1 :     spdm_test_context->case_id = 0x1;
+     899                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+     900                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     901                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     902                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     903                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     904                 :          1 :     libspdm_set_mem(m_libspdm_local_certificate_chain,
+     905                 :            :                     sizeof(m_libspdm_local_certificate_chain),
+     906                 :            :                     (uint8_t)(0xFF));
+     907                 :          1 :     libspdm_reset_message_b(spdm_context);
+     908                 :            : 
+     909                 :          1 :     libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
+     910                 :          1 :     status = libspdm_get_digest(spdm_context, NULL, &slot_mask, &total_digest_buffer);
+     911                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SEND_FAIL);
+     912                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     913                 :            :     assert_int_equal(spdm_context->transcript.message_b.buffer_size, 0);
+     914                 :            : #endif
+     915                 :          1 : }
+     916                 :            : 
+     917                 :            : /**
+     918                 :            :  * Test 2: Requester is unable to acquire the sender buffer.
+     919                 :            :  * Expected Behavior: returns with error LIBSPDM_STATUS_ACQUIRE_FAIL.
+     920                 :            :  **/
+     921                 :          1 : static void libspdm_test_requester_get_digests_err_case2(void **state)
+     922                 :            : {
+     923                 :            :     libspdm_return_t status;
+     924                 :            :     libspdm_test_context_t *spdm_test_context;
+     925                 :            :     libspdm_context_t *spdm_context;
+     926                 :            :     uint8_t slot_mask;
+     927                 :            :     uint8_t total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
+     928                 :            : 
+     929                 :          1 :     spdm_test_context = *state;
+     930                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     931                 :          1 :     spdm_test_context->case_id = 0x2;
+     932                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+     933                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     934                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     935                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     936                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     937                 :          1 :     libspdm_set_mem(m_libspdm_local_certificate_chain,
+     938                 :            :                     sizeof(m_libspdm_local_certificate_chain),
+     939                 :            :                     (uint8_t)(0xFF));
+     940                 :          1 :     libspdm_reset_message_b(spdm_context);
+     941                 :            : 
+     942                 :          1 :     libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
+     943                 :            : 
+     944                 :          1 :     libspdm_force_error(LIBSPDM_ERR_ACQUIRE_SENDER_BUFFER);
+     945                 :          1 :     status = libspdm_get_digest(spdm_context, NULL, &slot_mask, &total_digest_buffer);
+     946                 :          1 :     libspdm_release_error(LIBSPDM_ERR_ACQUIRE_SENDER_BUFFER);
+     947                 :            : 
+     948                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_ACQUIRE_FAIL);
+     949                 :          1 : }
+     950                 :            : 
+     951                 :            : /**
+     952                 :            :  * Test 3: connection_state equals to zero and makes the check fail, meaning that steps
+     953                 :            :  * GET_CAPABILITIES-CAPABILITIES and NEGOTIATE_ALGORITHMS-ALGORITHMS of the protocol were not previously completed
+     954                 :            :  * Expected Behavior: requester returns the status LIBSPDM_STATUS_INVALID_STATE_LOCAL, with no DIGESTS message received
+     955                 :            :  **/
+     956                 :          1 : static void libspdm_test_requester_get_digests_err_case3(void **state)
+     957                 :            : {
+     958                 :            :     libspdm_return_t status;
+     959                 :            :     libspdm_test_context_t *spdm_test_context;
+     960                 :            :     libspdm_context_t *spdm_context;
+     961                 :            :     uint8_t slot_mask;
+     962                 :            :     uint8_t total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
+     963                 :            : 
+     964                 :          1 :     spdm_test_context = *state;
+     965                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     966                 :          1 :     spdm_test_context->case_id = 0x3;
+     967                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+     968                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     969                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NOT_STARTED;
+     970                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     971                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     972                 :          1 :     libspdm_set_mem(m_libspdm_local_certificate_chain,
+     973                 :            :                     sizeof(m_libspdm_local_certificate_chain),
+     974                 :            :                     (uint8_t)(0xFF));
+     975                 :          1 :     libspdm_reset_message_b(spdm_context);
+     976                 :            : 
+     977                 :          1 :     libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
+     978                 :          1 :     status = libspdm_get_digest(spdm_context, NULL, &slot_mask, &total_digest_buffer);
+     979                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_STATE_LOCAL);
+     980                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     981                 :            :     assert_int_equal(spdm_context->transcript.message_b.buffer_size, 0);
+     982                 :            : #endif
+     983                 :          1 : }
+     984                 :            : 
+     985                 :            : /**
+     986                 :            :  * Test 4: a request message is successfully sent and an ERROR response message with error code = InvalidRequest is received
+     987                 :            :  * Expected Behavior: requester returns the status LIBSPDM_STATUS_ERROR_PEER, with no DIGESTS message received
+     988                 :            :  **/
+     989                 :          1 : static void libspdm_test_requester_get_digests_err_case4(void **state)
+     990                 :            : {
+     991                 :            :     libspdm_return_t status;
+     992                 :            :     libspdm_test_context_t *spdm_test_context;
+     993                 :            :     libspdm_context_t *spdm_context;
+     994                 :            :     uint8_t slot_mask;
+     995                 :            :     uint8_t total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
+     996                 :            : 
+     997                 :          1 :     spdm_test_context = *state;
+     998                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     999                 :          1 :     spdm_test_context->case_id = 0x4;
+    1000                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1001                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1002                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1003                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+    1004                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1005                 :          1 :     libspdm_set_mem(m_libspdm_local_certificate_chain,
+    1006                 :            :                     sizeof(m_libspdm_local_certificate_chain),
+    1007                 :            :                     (uint8_t)(0xFF));
+    1008                 :          1 :     libspdm_reset_message_b(spdm_context);
+    1009                 :            : 
+    1010                 :          1 :     libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
+    1011                 :          1 :     status = libspdm_get_digest(spdm_context, NULL, &slot_mask, &total_digest_buffer);
+    1012                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_ERROR_PEER);
+    1013                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1014                 :            :     assert_int_equal(spdm_context->transcript.message_b.buffer_size, 0);
+    1015                 :            : #endif
+    1016                 :          1 : }
+    1017                 :            : 
+    1018                 :            : /**
+    1019                 :            :  * Test 5: request messages are successfully sent and ERROR response messages with error code = Busy are received in all attempts
+    1020                 :            :  * Expected Behavior: requester returns the status LIBSPDM_STATUS_BUSY_PEER, with no DIGESTS message received
+    1021                 :            :  **/
+    1022                 :          1 : static void libspdm_test_requester_get_digests_err_case5(void **state)
+    1023                 :            : {
+    1024                 :            :     libspdm_return_t status;
+    1025                 :            :     libspdm_test_context_t *spdm_test_context;
+    1026                 :            :     libspdm_context_t *spdm_context;
+    1027                 :            :     uint8_t slot_mask;
+    1028                 :            :     uint8_t total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
+    1029                 :            : 
+    1030                 :          1 :     spdm_test_context = *state;
+    1031                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1032                 :          1 :     spdm_test_context->case_id = 0x5;
+    1033                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1034                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1035                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1036                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+    1037                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1038                 :          1 :     libspdm_set_mem(m_libspdm_local_certificate_chain,
+    1039                 :            :                     sizeof(m_libspdm_local_certificate_chain),
+    1040                 :            :                     (uint8_t)(0xFF));
+    1041                 :          1 :     libspdm_reset_message_b(spdm_context);
+    1042                 :            : 
+    1043                 :          1 :     libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
+    1044                 :          1 :     status = libspdm_get_digest(spdm_context, NULL, &slot_mask, &total_digest_buffer);
+    1045                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_BUSY_PEER);
+    1046                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1047                 :            :     assert_int_equal(spdm_context->transcript.message_b.buffer_size, 0);
+    1048                 :            : #endif
+    1049                 :          1 : }
+    1050                 :            : 
+    1051                 :            : /**
+    1052                 :            :  * Test 6: Requester is unable to acquire the receiver buffer.
+    1053                 :            :  * Expected Behavior: returns with error LIBSPDM_STATUS_ACQUIRE_FAIL.
+    1054                 :            :  **/
+    1055                 :          1 : static void libspdm_test_requester_get_digests_err_case6(void **state)
+    1056                 :            : {
+    1057                 :            :     libspdm_return_t status;
+    1058                 :            :     libspdm_test_context_t *spdm_test_context;
+    1059                 :            :     libspdm_context_t *spdm_context;
+    1060                 :            :     uint8_t slot_mask;
+    1061                 :            :     uint8_t total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
+    1062                 :            : 
+    1063                 :          1 :     spdm_test_context = *state;
+    1064                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1065                 :          1 :     spdm_test_context->case_id = 0x2;
+    1066                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1067                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1068                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1069                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+    1070                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1071                 :          1 :     libspdm_set_mem(m_libspdm_local_certificate_chain,
+    1072                 :            :                     sizeof(m_libspdm_local_certificate_chain),
+    1073                 :            :                     (uint8_t)(0xFF));
+    1074                 :          1 :     libspdm_reset_message_b(spdm_context);
+    1075                 :            : 
+    1076                 :          1 :     libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
+    1077                 :            : 
+    1078                 :          1 :     libspdm_force_error(LIBSPDM_ERR_ACQUIRE_RECEIVER_BUFFER);
+    1079                 :          1 :     status = libspdm_get_digest(spdm_context, NULL, &slot_mask, &total_digest_buffer);
+    1080                 :          1 :     libspdm_release_error(LIBSPDM_ERR_ACQUIRE_RECEIVER_BUFFER);
+    1081                 :            : 
+    1082                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_ACQUIRE_FAIL);
+    1083                 :          1 : }
+    1084                 :            : 
+    1085                 :            : /**
+    1086                 :            :  * Test 7: a request message is successfully sent and an ERROR response message with error code = RequestResynch
+    1087                 :            :  * (Meaning Responder is requesting Requester to reissue GET_VERSION to resynchronize) is received
+    1088                 :            :  * Expected Behavior: requester returns the status RETURN_DEVICE_ERROR, with no DIGESTS message received
+    1089                 :            :  **/
+    1090                 :          1 : static void libspdm_test_requester_get_digests_err_case7(void **state)
+    1091                 :            : {
+    1092                 :            :     libspdm_return_t status;
+    1093                 :            :     libspdm_test_context_t *spdm_test_context;
+    1094                 :            :     libspdm_context_t *spdm_context;
+    1095                 :            :     uint8_t slot_mask;
+    1096                 :            :     uint8_t total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
+    1097                 :            : 
+    1098                 :          1 :     spdm_test_context = *state;
+    1099                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1100                 :          1 :     spdm_test_context->case_id = 0x7;
+    1101                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1102                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1103                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1104                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+    1105                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1106                 :          1 :     libspdm_set_mem(m_libspdm_local_certificate_chain,
+    1107                 :            :                     sizeof(m_libspdm_local_certificate_chain),
+    1108                 :            :                     (uint8_t)(0xFF));
+    1109                 :          1 :     libspdm_reset_message_b(spdm_context);
+    1110                 :            : 
+    1111                 :          1 :     libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
+    1112                 :          1 :     status = libspdm_get_digest(spdm_context, NULL, &slot_mask, &total_digest_buffer);
+    1113                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_RESYNCH_PEER);
+    1114                 :          1 :     assert_int_equal(spdm_context->connection_info.connection_state,
+    1115                 :            :                      LIBSPDM_CONNECTION_STATE_NOT_STARTED);
+    1116                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1117                 :            :     assert_int_equal(spdm_context->transcript.message_b.buffer_size, 0);
+    1118                 :            : #endif
+    1119                 :          1 : }
+    1120                 :            : 
+    1121                 :            : /**
+    1122                 :            :  * Test 8: request messages are successfully sent and ERROR response messages with error code = ResponseNotReady
+    1123                 :            :  * are received in all attempts
+    1124                 :            :  * Expected Behavior: requester returns the status LIBSPDM_STATUS_ERROR_PEER
+    1125                 :            :  **/
+    1126                 :          1 : static void libspdm_test_requester_get_digests_err_case8(void **state)
+    1127                 :            : {
+    1128                 :            :     libspdm_return_t status;
+    1129                 :            :     libspdm_test_context_t *spdm_test_context;
+    1130                 :            :     libspdm_context_t *spdm_context;
+    1131                 :            :     uint8_t slot_mask;
+    1132                 :            :     uint8_t total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
+    1133                 :            : 
+    1134                 :          1 :     spdm_test_context = *state;
+    1135                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1136                 :          1 :     spdm_test_context->case_id = 0x8;
+    1137                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1138                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1139                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1140                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+    1141                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1142                 :          1 :     libspdm_set_mem(m_libspdm_local_certificate_chain,
+    1143                 :            :                     sizeof(m_libspdm_local_certificate_chain),
+    1144                 :            :                     (uint8_t)(0xFF));
+    1145                 :          1 :     libspdm_reset_message_b(spdm_context);
+    1146                 :            : 
+    1147                 :          1 :     libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
+    1148                 :          1 :     status = libspdm_get_digest(spdm_context, NULL, &slot_mask, &total_digest_buffer);
+    1149                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_NOT_READY_PEER);
+    1150                 :          1 : }
+    1151                 :            : 
+    1152                 :            : /**
+    1153                 :            :  * Test 9: Invalid SPDM version in the DIGESTS response.
+    1154                 :            :  * Expected Behavior: returns with LIBSPDM_STATUS_INVALID_MSG_FIELD.
+    1155                 :            :  **/
+    1156                 :          1 : static void libspdm_test_requester_get_digests_err_case9(void **state)
+    1157                 :            : {
+    1158                 :            :     libspdm_return_t status;
+    1159                 :            :     libspdm_test_context_t *spdm_test_context;
+    1160                 :            :     libspdm_context_t *spdm_context;
+    1161                 :            :     uint8_t slot_mask;
+    1162                 :            :     uint8_t total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
+    1163                 :            : 
+    1164                 :          1 :     spdm_test_context = *state;
+    1165                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1166                 :          1 :     spdm_test_context->case_id = 0x9;
+    1167                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1168                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1169                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1170                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+    1171                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1172                 :          1 :     libspdm_set_mem(m_libspdm_local_certificate_chain,
+    1173                 :            :                     sizeof(m_libspdm_local_certificate_chain),
+    1174                 :            :                     (uint8_t)(0xFF));
+    1175                 :          1 :     libspdm_reset_message_b(spdm_context);
+    1176                 :            : 
+    1177                 :          1 :     libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
+    1178                 :          1 :     status = libspdm_get_digest(spdm_context, NULL, &slot_mask, &total_digest_buffer);
+    1179                 :            : 
+    1180                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1181                 :          1 : }
+    1182                 :            : 
+    1183                 :            : /**
+    1184                 :            :  * Test 10: flag cert_cap from CAPABILITIES is not setted meaning the Requester does not support DIGESTS and
+    1185                 :            :  * CERTIFICATE response messages
+    1186                 :            :  * Expected Behavior: requester returns the status LIBSPDM_STATUS_UNSUPPORTED_CAP, with no DIGESTS message received
+    1187                 :            :  **/
+    1188                 :          1 : static void libspdm_test_requester_get_digests_err_case10(void **state)
+    1189                 :            : {
+    1190                 :            :     libspdm_return_t status;
+    1191                 :            :     libspdm_test_context_t *spdm_test_context;
+    1192                 :            :     libspdm_context_t *spdm_context;
+    1193                 :            :     uint8_t slot_mask;
+    1194                 :            :     uint8_t total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
+    1195                 :            : 
+    1196                 :          1 :     spdm_test_context = *state;
+    1197                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1198                 :          1 :     spdm_test_context->case_id = 0xA;
+    1199                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1200                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1201                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1202                 :          1 :     spdm_context->connection_info.capability.flags = 0;
+    1203                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1204                 :          1 :     libspdm_set_mem(m_libspdm_local_certificate_chain,
+    1205                 :            :                     sizeof(m_libspdm_local_certificate_chain),
+    1206                 :            :                     (uint8_t)(0xFF));
+    1207                 :          1 :     libspdm_reset_message_b(spdm_context);
+    1208                 :            : 
+    1209                 :          1 :     libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
+    1210                 :          1 :     status = libspdm_get_digest(spdm_context, NULL, &slot_mask, &total_digest_buffer);
+    1211                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_UNSUPPORTED_CAP);
+    1212                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1213                 :            :     assert_int_equal(spdm_context->transcript.message_b.buffer_size, 0);
+    1214                 :            : #endif
+    1215                 :          1 : }
+    1216                 :            : 
+    1217                 :            : /**
+    1218                 :            :  * Test 11: a request message is successfully sent but a failure occurs during the receiving of the response message
+    1219                 :            :  * Expected Behavior: requester returns the status LIBSPDM_STATUS_RECEIVE_FAIL, with no DIGESTS message received
+    1220                 :            :  **/
+    1221                 :          1 : static void libspdm_test_requester_get_digests_err_case11(void **state)
+    1222                 :            : {
+    1223                 :            :     libspdm_return_t status;
+    1224                 :            :     libspdm_test_context_t *spdm_test_context;
+    1225                 :            :     libspdm_context_t *spdm_context;
+    1226                 :            :     uint8_t slot_mask;
+    1227                 :            :     uint8_t total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
+    1228                 :            : 
+    1229                 :          1 :     spdm_test_context = *state;
+    1230                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1231                 :          1 :     spdm_test_context->case_id = 0xB;
+    1232                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1233                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1234                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1235                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+    1236                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1237                 :          1 :     libspdm_set_mem(m_libspdm_local_certificate_chain,
+    1238                 :            :                     sizeof(m_libspdm_local_certificate_chain),
+    1239                 :            :                     (uint8_t)(0xFF));
+    1240                 :          1 :     libspdm_reset_message_b(spdm_context);
+    1241                 :            : 
+    1242                 :          1 :     libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
+    1243                 :          1 :     status = libspdm_get_digest(spdm_context, NULL, &slot_mask, &total_digest_buffer);
+    1244                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_RECEIVE_FAIL);
+    1245                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1246                 :            :     assert_int_equal(spdm_context->transcript.message_b.buffer_size,
+    1247                 :            :                      0);
+    1248                 :            : #endif
+    1249                 :          1 : }
+    1250                 :            : 
+    1251                 :            : /**
+    1252                 :            :  * Test 12:
+    1253                 :            :  * Expected Behavior:
+    1254                 :            :  **/
+    1255                 :          1 : static void libspdm_test_requester_get_digests_err_case12(void **state)
+    1256                 :            : {
+    1257                 :          1 : }
+    1258                 :            : 
+    1259                 :            : /**
+    1260                 :            :  * Test 13: a request message is successfully sent but the request_response_code from the response message is different than the code of SPDM_DIGESTS
+    1261                 :            :  * Expected Behavior: requester returns the status LIBSPDM_STATUS_INVALID_MSG_FIELD, with no DIGESTS message received
+    1262                 :            :  **/
+    1263                 :          1 : static void libspdm_test_requester_get_digests_err_case13(void **state)
+    1264                 :            : {
+    1265                 :            :     libspdm_return_t status;
+    1266                 :            :     libspdm_test_context_t *spdm_test_context;
+    1267                 :            :     libspdm_context_t *spdm_context;
+    1268                 :            :     uint8_t slot_mask;
+    1269                 :            :     uint8_t total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
+    1270                 :            : 
+    1271                 :          1 :     spdm_test_context = *state;
+    1272                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1273                 :          1 :     spdm_test_context->case_id = 0xD;
+    1274                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1275                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1276                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1277                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+    1278                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1279                 :          1 :     libspdm_set_mem(m_libspdm_local_certificate_chain,
+    1280                 :            :                     sizeof(m_libspdm_local_certificate_chain),
+    1281                 :            :                     (uint8_t)(0xFF));
+    1282                 :          1 :     libspdm_reset_message_b(spdm_context);
+    1283                 :            : 
+    1284                 :          1 :     libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
+    1285                 :          1 :     status = libspdm_get_digest(spdm_context, NULL, &slot_mask, &total_digest_buffer);
+    1286                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1287                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1288                 :            :     assert_int_equal(spdm_context->transcript.message_b.buffer_size, 0);
+    1289                 :            : #endif
+    1290                 :          1 : }
+    1291                 :            : 
+    1292                 :            : /**
+    1293                 :            :  * Test 14: a request message is successfully sent but the number of digests in the response message is equal to zero
+    1294                 :            :  * Expected Behavior: requester returns the status LIBSPDM_STATUS_INVALID_MSG_FIELD, with no successful DIGESTS message received
+    1295                 :            :  **/
+    1296                 :          1 : static void libspdm_test_requester_get_digests_err_case14(void **state)
+    1297                 :            : {
+    1298                 :            :     libspdm_return_t status;
+    1299                 :            :     libspdm_test_context_t *spdm_test_context;
+    1300                 :            :     libspdm_context_t *spdm_context;
+    1301                 :            :     uint8_t slot_mask;
+    1302                 :            :     uint8_t total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
+    1303                 :            : 
+    1304                 :          1 :     spdm_test_context = *state;
+    1305                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1306                 :          1 :     spdm_test_context->case_id = 0xE;
+    1307                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1308                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1309                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1310                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+    1311                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1312                 :          1 :     libspdm_set_mem(m_libspdm_local_certificate_chain,
+    1313                 :            :                     sizeof(m_libspdm_local_certificate_chain),
+    1314                 :            :                     (uint8_t)(0xFF));
+    1315                 :          1 :     libspdm_reset_message_b(spdm_context);
+    1316                 :            : 
+    1317                 :          1 :     libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
+    1318                 :          1 :     status = libspdm_get_digest(spdm_context, NULL, &slot_mask, &total_digest_buffer);
+    1319                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1320                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1321                 :            :     assert_int_equal(spdm_context->transcript.message_b.buffer_size,
+    1322                 :            :                      0);
+    1323                 :            : #endif
+    1324                 :          1 : }
+    1325                 :            : 
+    1326                 :            : /**
+    1327                 :            :  * Test 15:
+    1328                 :            :  * Expected Behavior:
+    1329                 :            :  **/
+    1330                 :          1 : static void libspdm_test_requester_get_digests_err_case15(void **state)
+    1331                 :            : {
+    1332                 :          1 : }
+    1333                 :            : 
+    1334                 :            : /**
+    1335                 :            :  * Test 16: a request message is successfully sent but the response message cannot be appended to the internal cache since the internal cache is full
+    1336                 :            :  * Expected Behavior: requester returns the status RETURN_SECURITY_VIOLATION
+    1337                 :            :  **/
+    1338                 :          1 : static void libspdm_test_requester_get_digests_err_case16(void **state)
+    1339                 :            : {
+    1340                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1341                 :            :     libspdm_return_t status;
+    1342                 :            :     uint8_t slot_mask;
+    1343                 :            : #endif
+    1344                 :            :     libspdm_test_context_t *spdm_test_context;
+    1345                 :            :     libspdm_context_t *spdm_context;
+    1346                 :            :     uint8_t total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
+    1347                 :            : 
+    1348                 :          1 :     spdm_test_context = *state;
+    1349                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1350                 :          1 :     spdm_test_context->case_id = 0x10;
+    1351                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1352                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1353                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1354                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+    1355                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1356                 :          1 :     libspdm_set_mem(m_libspdm_local_certificate_chain,
+    1357                 :            :                     sizeof(m_libspdm_local_certificate_chain),
+    1358                 :            :                     (uint8_t)(0xFF));
+    1359                 :            : 
+    1360                 :          1 :     libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
+    1361                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1362                 :            :     status = libspdm_get_digest(spdm_context, NULL, &slot_mask, &total_digest_buffer);
+    1363                 :            :     assert_int_equal(status, LIBSPDM_STATUS_BUFFER_FULL);
+    1364                 :            : #endif
+    1365                 :          1 : }
+    1366                 :            : 
+    1367                 :            : /**
+    1368                 :            :  * Test 17:
+    1369                 :            :  * Expected Behavior:
+    1370                 :            :  **/
+    1371                 :          1 : static void libspdm_test_requester_get_digests_err_case17(void **state)
+    1372                 :            : {
+    1373                 :          1 : }
+    1374                 :            : 
+    1375                 :            : /**
+    1376                 :            :  * Test 18: a request message is successfully sent but the number of digests received in the response message is different than
+    1377                 :            :  * the number of bits set in param2 - Slot mask
+    1378                 :            :  * Expected Behavior: requester returns the status RETURN_DEVICE_ERROR, with no successful DIGESTS message received (managed buffer not shrinked)
+    1379                 :            :  **/
+    1380                 :          1 : static void libspdm_test_requester_get_digests_err_case18(void **state)
+    1381                 :            : {
+    1382                 :            :     libspdm_return_t status;
+    1383                 :            :     libspdm_test_context_t *spdm_test_context;
+    1384                 :            :     libspdm_context_t *spdm_context;
+    1385                 :            :     uint8_t slot_mask;
+    1386                 :            :     uint8_t total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
+    1387                 :            : 
+    1388                 :          1 :     spdm_test_context = *state;
+    1389                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1390                 :          1 :     spdm_test_context->case_id = 0x12;
+    1391                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1392                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1393                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1394                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+    1395                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1396                 :          1 :     libspdm_set_mem(m_libspdm_local_certificate_chain,
+    1397                 :            :                     sizeof(m_libspdm_local_certificate_chain),
+    1398                 :            :                     (uint8_t)(0xFF));
+    1399                 :          1 :     libspdm_reset_message_b(spdm_context);
+    1400                 :            : 
+    1401                 :          1 :     libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
+    1402                 :          1 :     status = libspdm_get_digest(spdm_context, NULL, &slot_mask, &total_digest_buffer);
+    1403                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
+    1404                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1405                 :            :     assert_int_equal(spdm_context->transcript.message_b.buffer_size,
+    1406                 :            :                      0);
+    1407                 :            : #endif
+    1408                 :          1 : }
+    1409                 :            : 
+    1410                 :            : #if 0
+    1411                 :            : /**
+    1412                 :            :  * Test 19: a request message is successfully sent but several digests (except the first) received in the response message are invalid
+    1413                 :            :  * Expected Behavior: requester returns the status RETURN_SECURITY_VIOLATION, with error state LIBSPDM_STATUS_ERROR_CERTIFICATE_FAILURE
+    1414                 :            :  **/
+    1415                 :            : static void libspdm_test_requester_get_digests_err_case19(void **state)
+    1416                 :            : {
+    1417                 :            :     libspdm_return_t status;
+    1418                 :            :     libspdm_test_context_t *spdm_test_context;
+    1419                 :            :     libspdm_context_t *spdm_context;
+    1420                 :            :     uint8_t slot_mask;
+    1421                 :            :     uint8_t total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
+    1422                 :            : 
+    1423                 :            :     spdm_test_context = *state;
+    1424                 :            :     spdm_context = spdm_test_context->spdm_context;
+    1425                 :            :     spdm_test_context->case_id = 0x13;
+    1426                 :            :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1427                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1428                 :            :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1429                 :            :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+    1430                 :            :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1431                 :            :     libspdm_set_mem(m_libspdm_local_certificate_chain,
+    1432                 :            :                     sizeof(m_libspdm_local_certificate_chain),
+    1433                 :            :                     (uint8_t)(0xFF));
+    1434                 :            :     libspdm_reset_message_b(spdm_context);
+    1435                 :            : 
+    1436                 :            :     libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
+    1437                 :            :     status = libspdm_get_digest(spdm_context, NULL, &slot_mask, &total_digest_buffer);
+    1438                 :            :     assert_int_equal(status, LIBSPDM_STATUS_VERIF_FAIL);
+    1439                 :            : }
+    1440                 :            : 
+    1441                 :            : /**
+    1442                 :            :  * Test 20: a request message is successfully sent but the size of the response message is smaller than the minimum size of a SPDM DIGESTS response,
+    1443                 :            :  * meaning it is an invalid response message.
+    1444                 :            :  * Expected Behavior: requester returns the status RETURN_DEVICE_ERROR, with no successful DIGESTS message received (managed buffer not shrinked)
+    1445                 :            :  **/
+    1446                 :            : static void libspdm_test_requester_get_digests_err_case20(void **state)
+    1447                 :            : {
+    1448                 :            :     libspdm_return_t status;
+    1449                 :            :     libspdm_test_context_t *spdm_test_context;
+    1450                 :            :     libspdm_context_t *spdm_context;
+    1451                 :            :     uint8_t slot_mask;
+    1452                 :            :     uint8_t total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
+    1453                 :            : 
+    1454                 :            :     spdm_test_context = *state;
+    1455                 :            :     spdm_context = spdm_test_context->spdm_context;
+    1456                 :            :     spdm_test_context->case_id = 0x14;
+    1457                 :            :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1458                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1459                 :            :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1460                 :            :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+    1461                 :            :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1462                 :            :     libspdm_set_mem(m_libspdm_local_certificate_chain,
+    1463                 :            :                     sizeof(m_libspdm_local_certificate_chain),
+    1464                 :            :                     (uint8_t)(0xFF));
+    1465                 :            :     libspdm_reset_message_b(spdm_context);
+    1466                 :            : 
+    1467                 :            :     libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
+    1468                 :            :     status = libspdm_get_digest(spdm_context, NULL, &slot_mask, &total_digest_buffer);
+    1469                 :            :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
+    1470                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1471                 :            :     assert_int_equal(spdm_context->transcript.message_b.buffer_size,
+    1472                 :            :                      sizeof(spdm_get_digest_request_t));
+    1473                 :            : #endif
+    1474                 :            : }
+    1475                 :            : 
+    1476                 :            : /**
+    1477                 :            :  * Test 21: a request message is successfully sent but the size of the response message is bigger than the maximum size of a SPDM DIGESTS response,
+    1478                 :            :  * meaning it is an invalid response message.
+    1479                 :            :  * Expected Behavior: requester returns the status RETURN_DEVICE_ERROR, with no successful DIGESTS message received (managed buffer not shrinked)
+    1480                 :            :  **/
+    1481                 :            : static void libspdm_test_requester_get_digests_err_case21(void **state)
+    1482                 :            : {
+    1483                 :            :     libspdm_return_t status;
+    1484                 :            :     libspdm_test_context_t *spdm_test_context;
+    1485                 :            :     libspdm_context_t *spdm_context;
+    1486                 :            :     uint8_t slot_mask;
+    1487                 :            :     uint8_t total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
+    1488                 :            : 
+    1489                 :            :     spdm_test_context = *state;
+    1490                 :            :     spdm_context = spdm_test_context->spdm_context;
+    1491                 :            :     spdm_test_context->case_id = 0x15;
+    1492                 :            :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1493                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1494                 :            :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1495                 :            :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+    1496                 :            :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1497                 :            :     libspdm_set_mem(m_libspdm_local_certificate_chain,
+    1498                 :            :                     sizeof(m_libspdm_local_certificate_chain),
+    1499                 :            :                     (uint8_t)(0xFF));
+    1500                 :            :     libspdm_reset_message_b(spdm_context);
+    1501                 :            : 
+    1502                 :            :     libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
+    1503                 :            :     status = libspdm_get_digest(spdm_context, NULL, &slot_mask, &total_digest_buffer);
+    1504                 :            :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
+    1505                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1506                 :            :     assert_int_equal(spdm_context->transcript.message_b.buffer_size,
+    1507                 :            :                      sizeof(spdm_get_digest_request_t));
+    1508                 :            : #endif
+    1509                 :            : }
+    1510                 :            : #endif
+    1511                 :            : 
+    1512                 :            : /**
+    1513                 :            :  * Test 22: receiving an unexpected ERROR message from the responder.
+    1514                 :            :  * There are tests for all named codes, including some reserved ones
+    1515                 :            :  * (namely, 0x00, 0x0b, 0x0c, 0x3f, 0xfd, 0xfe).
+    1516                 :            :  * However, for having specific test cases, it is excluded from this case:
+    1517                 :            :  * Busy (0x03), ResponseNotReady (0x42), and RequestResync (0x43).
+    1518                 :            :  * Expected behavior: client returns a status of RETURN_DEVICE_ERROR.
+    1519                 :            :  **/
+    1520                 :          1 : static void libspdm_test_requester_get_digests_err_case22(void **state) {
+    1521                 :            :     libspdm_return_t status;
+    1522                 :            :     libspdm_test_context_t    *spdm_test_context;
+    1523                 :            :     libspdm_context_t  *spdm_context;
+    1524                 :            :     uint8_t slot_mask;
+    1525                 :            :     uint8_t total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
+    1526                 :            :     uint16_t error_code;
+    1527                 :            : 
+    1528                 :          1 :     spdm_test_context = *state;
+    1529                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1530                 :          1 :     spdm_test_context->case_id = 0x16;
+    1531                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1532                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1533                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+    1534                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1535                 :          1 :     libspdm_set_mem (m_libspdm_local_certificate_chain,
+    1536                 :            :                      sizeof(m_libspdm_local_certificate_chain),
+    1537                 :            :                      (uint8_t)(0xFF));
+    1538                 :            : 
+    1539                 :          1 :     error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
+    1540         [ +  + ]:         19 :     while(error_code <= 0xff) {
+    1541                 :         18 :         spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1542                 :         18 :         libspdm_reset_message_b(spdm_context);
+    1543                 :            : 
+    1544                 :         18 :         libspdm_zero_mem (total_digest_buffer, sizeof(total_digest_buffer));
+    1545                 :         18 :         status = libspdm_get_digest (spdm_context, NULL, &slot_mask, &total_digest_buffer);
+    1546         [ -  + ]:         18 :         LIBSPDM_ASSERT_INT_EQUAL_CASE (status, LIBSPDM_STATUS_ERROR_PEER, error_code);
+    1547                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1548                 :            :         LIBSPDM_ASSERT_INT_EQUAL_CASE (spdm_context->transcript.message_b.buffer_size, 0,
+    1549                 :            :                                        error_code);
+    1550                 :            : #endif
+    1551                 :            : 
+    1552                 :         18 :         error_code++;
+    1553         [ +  + ]:         18 :         if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
+    1554                 :          1 :             error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
+    1555                 :            :         }
+    1556         [ +  + ]:         18 :         if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) { /*skip some reserved error codes (0d to 3e)*/
+    1557                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
+    1558                 :            :         }
+    1559         [ +  + ]:         18 :         if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) { /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
+    1560                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
+    1561                 :            :         }
+    1562                 :            :     }
+    1563                 :          1 : }
+    1564                 :            : 
+    1565                 :            : /**
+    1566                 :            :  * Test 23:
+    1567                 :            :  * Expected Behavior:
+    1568                 :            :  **/
+    1569                 :          1 : static void libspdm_test_requester_get_digests_err_case23(void **state)
+    1570                 :            : {
+    1571                 :          1 : }
+    1572                 :            : 
+    1573                 :            : /**
+    1574                 :            :  * Test 24:
+    1575                 :            :  * Expected Behavior:
+    1576                 :            :  **/
+    1577                 :          1 : static void libspdm_test_requester_get_digests_err_case24(void **state)
+    1578                 :            : {
+    1579                 :          1 : }
+    1580                 :            : 
+    1581                 :            : /**
+    1582                 :            :  * Test 25:
+    1583                 :            :  * Expected Behavior:
+    1584                 :            :  **/
+    1585                 :          1 : static void libspdm_test_requester_get_digests_err_case25(void **state)
+    1586                 :            : {
+    1587                 :          1 : }
+    1588                 :            : 
+    1589                 :            : static libspdm_test_context_t m_libspdm_requester_get_digests_test_context = {
+    1590                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+    1591                 :            :     true,
+    1592                 :            :     libspdm_requester_get_digests_test_send_message,
+    1593                 :            :     libspdm_requester_get_digests_test_receive_message,
+    1594                 :            : };
+    1595                 :            : 
+    1596                 :          1 : int libspdm_requester_get_digests_error_test_main(void)
+    1597                 :            : {
+    1598                 :          1 :     const struct CMUnitTest spdm_requester_get_digests_tests[] = {
+    1599                 :            :         cmocka_unit_test(libspdm_test_requester_get_digests_err_case1),
+    1600                 :            :         cmocka_unit_test(libspdm_test_requester_get_digests_err_case2),
+    1601                 :            :         cmocka_unit_test(libspdm_test_requester_get_digests_err_case3),
+    1602                 :            :         cmocka_unit_test(libspdm_test_requester_get_digests_err_case4),
+    1603                 :            :         cmocka_unit_test(libspdm_test_requester_get_digests_err_case5),
+    1604                 :            :         cmocka_unit_test(libspdm_test_requester_get_digests_err_case6),
+    1605                 :            :         cmocka_unit_test(libspdm_test_requester_get_digests_err_case7),
+    1606                 :            :         cmocka_unit_test(libspdm_test_requester_get_digests_err_case8),
+    1607                 :            :         cmocka_unit_test(libspdm_test_requester_get_digests_err_case9),
+    1608                 :            :         cmocka_unit_test(libspdm_test_requester_get_digests_err_case10),
+    1609                 :            :         cmocka_unit_test(libspdm_test_requester_get_digests_err_case11),
+    1610                 :            :         cmocka_unit_test(libspdm_test_requester_get_digests_err_case12),
+    1611                 :            :         cmocka_unit_test(libspdm_test_requester_get_digests_err_case13),
+    1612                 :            :         cmocka_unit_test(libspdm_test_requester_get_digests_err_case14),
+    1613                 :            :         cmocka_unit_test(libspdm_test_requester_get_digests_err_case15),
+    1614                 :            :         cmocka_unit_test(libspdm_test_requester_get_digests_err_case16),
+    1615                 :            :         cmocka_unit_test(libspdm_test_requester_get_digests_err_case17),
+    1616                 :            :         cmocka_unit_test(libspdm_test_requester_get_digests_err_case18),
+    1617                 :            :         /* cmocka_unit_test(libspdm_test_requester_get_digests_err_case19),
+    1618                 :            :          * cmocka_unit_test(libspdm_test_requester_get_digests_err_case20),
+    1619                 :            :          * cmocka_unit_test(libspdm_test_requester_get_digests_err_case21), */
+    1620                 :            :         cmocka_unit_test(libspdm_test_requester_get_digests_err_case22),
+    1621                 :            :         cmocka_unit_test(libspdm_test_requester_get_digests_err_case23),
+    1622                 :            :         cmocka_unit_test(libspdm_test_requester_get_digests_err_case24),
+    1623                 :            :         cmocka_unit_test(libspdm_test_requester_get_digests_err_case25),
+    1624                 :            :     };
+    1625                 :            : 
+    1626                 :          1 :     libspdm_setup_test_context(&m_libspdm_requester_get_digests_test_context);
+    1627                 :            : 
+    1628                 :          1 :     return cmocka_run_group_tests(spdm_requester_get_digests_tests,
+    1629                 :            :                                   libspdm_unit_test_group_setup,
+    1630                 :            :                                   libspdm_unit_test_group_teardown);
+    1631                 :            : }
+    1632                 :            : 
+    1633                 :            : #endif /* LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/error_test/get_event_types_err.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_requester/error_test/get_event_types_err.c.func-sort-c.html new file mode 100644 index 00000000000..acc4b631af4 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/error_test/get_event_types_err.c.func-sort-c.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/error_test/get_event_types_err.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester/error_test - get_event_types_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:737597.3 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:3650.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_get_event_types_error_test_main1
libspdm_test_requester_get_event_types_err_case11
receive_message1
send_message1
set_standard_state1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/error_test/get_event_types_err.c.func.html b/coverage_log/unit_test/test_spdm_requester/error_test/get_event_types_err.c.func.html new file mode 100644 index 00000000000..e61c3ba8e09 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/error_test/get_event_types_err.c.func.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/error_test/get_event_types_err.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester/error_test - get_event_types_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:737597.3 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:3650.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_get_event_types_error_test_main1
libspdm_test_requester_get_event_types_err_case11
receive_message1
send_message1
set_standard_state1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/error_test/get_event_types_err.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/error_test/get_event_types_err.c.gcov.html new file mode 100644 index 00000000000..98e1fd98083 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/error_test/get_event_types_err.c.gcov.html @@ -0,0 +1,289 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/error_test/get_event_types_err.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester/error_test - get_event_types_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:737597.3 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:3650.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2024 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_requester_lib.h"
+       9                 :            : #include "internal/libspdm_secured_message_lib.h"
+      10                 :            : 
+      11                 :            : #if LIBSPDM_EVENT_RECIPIENT_SUPPORT
+      12                 :            : 
+      13                 :            : static uint8_t m_supported_event_groups_list[0x1000];
+      14                 :            : static uint8_t m_spdm_request_buffer[0x1000];
+      15                 :            : 
+      16                 :            : static const uint32_t m_session_id = 0xffffffff;
+      17                 :            : 
+      18                 :          1 : static void set_standard_state(libspdm_context_t *spdm_context, uint32_t *session_id)
+      19                 :            : {
+      20                 :            :     libspdm_session_info_t *session_info;
+      21                 :            : 
+      22                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+      23                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+      24                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+      25                 :            : 
+      26                 :          1 :     spdm_context->connection_info.capability.flags |=
+      27                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EVENT_CAP;
+      28                 :          1 :     spdm_context->connection_info.capability.flags |=
+      29                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+      30                 :          1 :     spdm_context->connection_info.capability.flags |=
+      31                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+      32                 :          1 :     spdm_context->connection_info.capability.flags |=
+      33                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+      34                 :            : 
+      35                 :          1 :     spdm_context->local_context.capability.flags |=
+      36                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+      37                 :          1 :     spdm_context->local_context.capability.flags |=
+      38                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+      39                 :          1 :     spdm_context->local_context.capability.flags |=
+      40                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+      41                 :            : 
+      42                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+      43                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+      44                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+      45                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+      46                 :            : 
+      47                 :          1 :     *session_id = m_session_id;
+      48                 :          1 :     session_info = &spdm_context->session_info[0];
+      49                 :          1 :     libspdm_session_info_init(spdm_context, session_info, *session_id, true);
+      50                 :          1 :     libspdm_secured_message_set_session_state(
+      51                 :            :         session_info->secured_message_context, LIBSPDM_SESSION_STATE_ESTABLISHED);
+      52                 :          1 : }
+      53                 :            : 
+      54                 :          1 : static libspdm_return_t send_message(
+      55                 :            :     void *spdm_context, size_t request_size, const void *request, uint64_t timeout)
+      56                 :            : {
+      57                 :            :     libspdm_return_t status;
+      58                 :            :     uint32_t session_id;
+      59                 :            :     uint32_t *message_session_id;
+      60                 :            :     spdm_get_supported_event_types_request_t *spdm_message;
+      61                 :            :     bool is_app_message;
+      62                 :            :     void *spdm_request_buffer;
+      63                 :            :     size_t spdm_request_size;
+      64                 :            :     libspdm_session_info_t *session_info;
+      65                 :            :     uint8_t request_buffer[0x1000];
+      66                 :            : 
+      67                 :            :     /* Workaround request being const. */
+      68                 :          1 :     libspdm_copy_mem(request_buffer, sizeof(request_buffer), request, request_size);
+      69                 :            : 
+      70                 :          1 :     session_id = m_session_id;
+      71                 :          1 :     session_info = libspdm_get_session_info_via_session_id(spdm_context, session_id);
+      72         [ -  + ]:          1 :     LIBSPDM_ASSERT(session_info != NULL);
+      73                 :            : 
+      74                 :          1 :     ((libspdm_secured_message_context_t *)(session_info->secured_message_context))->
+      75                 :          1 :     application_secret.request_data_sequence_number--;
+      76                 :            : 
+      77                 :          1 :     spdm_request_buffer = m_spdm_request_buffer;
+      78                 :          1 :     spdm_request_size = sizeof(m_spdm_request_buffer);
+      79                 :            : 
+      80                 :          1 :     status = libspdm_transport_test_decode_message(spdm_context, &message_session_id,
+      81                 :            :                                                    &is_app_message, true,
+      82                 :            :                                                    request_size, request_buffer,
+      83                 :            :                                                    &spdm_request_size, &spdm_request_buffer);
+      84                 :            : 
+      85                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+      86                 :          1 :     assert_int_equal(sizeof(spdm_get_supported_event_types_request_t), spdm_request_size);
+      87                 :            : 
+      88                 :          1 :     spdm_message = spdm_request_buffer;
+      89                 :            : 
+      90                 :          1 :     assert_int_equal(spdm_message->header.spdm_version, SPDM_MESSAGE_VERSION_13);
+      91                 :          1 :     assert_int_equal(spdm_message->header.request_response_code, SPDM_GET_SUPPORTED_EVENT_TYPES);
+      92                 :          1 :     assert_int_equal(spdm_message->header.param1, 0);
+      93                 :          1 :     assert_int_equal(spdm_message->header.param2, 0);
+      94                 :            : 
+      95                 :          1 :     return LIBSPDM_STATUS_SUCCESS;
+      96                 :            : }
+      97                 :            : 
+      98                 :          1 : static libspdm_return_t receive_message(
+      99                 :            :     void *spdm_context, size_t *response_size, void **response, uint64_t timeout)
+     100                 :            : {
+     101                 :            :     spdm_supported_event_types_response_t *spdm_response;
+     102                 :            :     size_t spdm_response_size;
+     103                 :            :     size_t transport_header_size;
+     104                 :            :     uint32_t session_id;
+     105                 :            :     libspdm_session_info_t *session_info;
+     106                 :            :     uint8_t *scratch_buffer;
+     107                 :            :     size_t scratch_buffer_size;
+     108                 :            :     uint8_t event_group_total_bytes;
+     109                 :            :     libspdm_test_context_t *spdm_test_context;
+     110                 :            : 
+     111                 :          1 :     spdm_test_context = libspdm_get_test_context();
+     112         [ +  - ]:          1 :     switch (spdm_test_context->case_id) {
+     113                 :          1 :     case 1: {
+     114                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     115                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     116                 :            : 
+     117                 :          1 :         session_id = m_session_id;
+     118                 :            : 
+     119                 :          1 :         session_info = libspdm_get_session_info_via_session_id(spdm_context, session_id);
+     120         [ -  + ]:          1 :         LIBSPDM_ASSERT((session_info != NULL));
+     121                 :            : 
+     122                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+     123                 :          1 :         spdm_response->header.request_response_code = SPDM_SUPPORTED_EVENT_TYPES;
+     124                 :            :         /* Illegal EventGroupCount value. */
+     125                 :          1 :         spdm_response->header.param1 = 0;
+     126                 :          1 :         spdm_response->header.param2 = 0;
+     127                 :            : 
+     128                 :          1 :         generate_dmtf_event_group(spdm_response + 1, &event_group_total_bytes, 0,
+     129                 :            :                                   true, true, true, true);
+     130                 :          1 :         spdm_response->supported_event_groups_list_len = event_group_total_bytes;
+     131                 :            : 
+     132                 :          1 :         spdm_response_size = sizeof(spdm_supported_event_types_response_t) +
+     133                 :            :                              event_group_total_bytes;
+     134                 :            : 
+     135                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+     136                 :            :          * transport_message is always in sender buffer. */
+     137                 :          1 :         libspdm_get_scratch_buffer(spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+     138                 :          1 :         libspdm_copy_mem(scratch_buffer + transport_header_size,
+     139                 :            :                          scratch_buffer_size - transport_header_size,
+     140                 :            :                          spdm_response, spdm_response_size);
+     141                 :            : 
+     142                 :          1 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+     143                 :            : 
+     144                 :          1 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+     145                 :            :                                               false, false, spdm_response_size,
+     146                 :            :                                               spdm_response, response_size, response);
+     147                 :            : 
+     148                 :            :         /* Workaround: Use single context to encode message and then decode message. */
+     149                 :          1 :         ((libspdm_secured_message_context_t *)(session_info->secured_message_context))->
+     150                 :          1 :         application_secret.response_data_sequence_number--;
+     151                 :            :     }
+     152                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     153                 :          0 :     default:
+     154                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+     155                 :            :     }
+     156                 :            : }
+     157                 :            : 
+     158                 :            : /**
+     159                 :            :  * Test 1: Responder returns a value of 0 for EventGroupCount (param1).
+     160                 :            :  * Expected Behavior: Returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
+     161                 :            :  **/
+     162                 :          1 : static void libspdm_test_requester_get_event_types_err_case1(void **state)
+     163                 :            : {
+     164                 :            :     libspdm_return_t status;
+     165                 :            :     libspdm_test_context_t *spdm_test_context;
+     166                 :            :     libspdm_context_t *spdm_context;
+     167                 :            :     uint32_t session_id;
+     168                 :            :     uint8_t event_group_count;
+     169                 :          1 :     uint32_t supported_event_groups_list_len = sizeof(m_supported_event_groups_list);
+     170                 :            : 
+     171                 :          1 :     spdm_test_context = *state;
+     172                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     173                 :          1 :     spdm_test_context->case_id = 1;
+     174                 :            : 
+     175                 :          1 :     set_standard_state(spdm_context, &session_id);
+     176                 :            : 
+     177                 :          1 :     status = libspdm_get_event_types(spdm_context, session_id, &event_group_count,
+     178                 :            :                                      &supported_event_groups_list_len,
+     179                 :            :                                      (void *)&m_supported_event_groups_list);
+     180                 :            : 
+     181                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+     182                 :          1 : }
+     183                 :            : 
+     184                 :            : static libspdm_test_context_t m_test_context = {
+     185                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+     186                 :            :     true,
+     187                 :            :     send_message,
+     188                 :            :     receive_message,
+     189                 :            : };
+     190                 :            : 
+     191                 :          1 : int libspdm_requester_get_event_types_error_test_main(void)
+     192                 :            : {
+     193                 :          1 :     const struct CMUnitTest spdm_requester_get_event_types_tests[] = {
+     194                 :            :         cmocka_unit_test(libspdm_test_requester_get_event_types_err_case1)
+     195                 :            :     };
+     196                 :            : 
+     197                 :          1 :     libspdm_setup_test_context(&m_test_context);
+     198                 :            : 
+     199                 :          1 :     return cmocka_run_group_tests(spdm_requester_get_event_types_tests,
+     200                 :            :                                   libspdm_unit_test_group_setup,
+     201                 :            :                                   libspdm_unit_test_group_teardown);
+     202                 :            : }
+     203                 :            : 
+     204                 :            : #endif /* LIBSPDM_EVENT_RECIPIENT_SUPPORT */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/error_test/get_key_pair_info_err.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_requester/error_test/get_key_pair_info_err.c.func-sort-c.html new file mode 100644 index 00000000000..9d21fefa1a3 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/error_test/get_key_pair_info_err.c.func-sort-c.html @@ -0,0 +1,97 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/error_test/get_key_pair_info_err.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester/error_test - get_key_pair_info_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:213070.0 %
Date:2024-09-22 08:21:07Functions:3475.0 %
Branches:1425.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_get_key_pair_info_error_test_receive_message0
libspdm_requester_get_key_pair_info_error_test_main1
libspdm_requester_get_key_pair_info_error_test_send_message1
libspdm_test_requester_get_key_pair_info_error_case11
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/error_test/get_key_pair_info_err.c.func.html b/coverage_log/unit_test/test_spdm_requester/error_test/get_key_pair_info_err.c.func.html new file mode 100644 index 00000000000..fea7a8b5610 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/error_test/get_key_pair_info_err.c.func.html @@ -0,0 +1,97 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/error_test/get_key_pair_info_err.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester/error_test - get_key_pair_info_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:213070.0 %
Date:2024-09-22 08:21:07Functions:3475.0 %
Branches:1425.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_get_key_pair_info_error_test_main1
libspdm_requester_get_key_pair_info_error_test_receive_message0
libspdm_requester_get_key_pair_info_error_test_send_message1
libspdm_test_requester_get_key_pair_info_error_case11
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/error_test/get_key_pair_info_err.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/error_test/get_key_pair_info_err.c.gcov.html new file mode 100644 index 00000000000..70dad74963f --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/error_test/get_key_pair_info_err.c.gcov.html @@ -0,0 +1,193 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/error_test/get_key_pair_info_err.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester/error_test - get_key_pair_info_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:213070.0 %
Date:2024-09-22 08:21:07Functions:3475.0 %
Branches:1425.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2024 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_requester_lib.h"
+       9                 :            : #include "internal/libspdm_secured_message_lib.h"
+      10                 :            : 
+      11                 :            : #if LIBSPDM_ENABLE_CAPABILITY_GET_KEY_PAIR_INFO_CAP
+      12                 :            : 
+      13                 :          1 : libspdm_return_t libspdm_requester_get_key_pair_info_error_test_send_message(
+      14                 :            :     void *spdm_context, size_t request_size, const void *request,
+      15                 :            :     uint64_t timeout)
+      16                 :            : {
+      17                 :            :     libspdm_test_context_t *spdm_test_context;
+      18                 :            : 
+      19                 :          1 :     spdm_test_context = libspdm_get_test_context();
+      20         [ +  - ]:          1 :     switch (spdm_test_context->case_id) {
+      21                 :          1 :     case 0x1:
+      22                 :          1 :         return LIBSPDM_STATUS_SEND_FAIL;
+      23                 :          0 :     default:
+      24                 :          0 :         return LIBSPDM_STATUS_SEND_FAIL;
+      25                 :            :     }
+      26                 :            : }
+      27                 :            : 
+      28                 :          0 : libspdm_return_t libspdm_requester_get_key_pair_info_error_test_receive_message(
+      29                 :            :     void *spdm_context, size_t *response_size,
+      30                 :            :     void **response, uint64_t timeout)
+      31                 :            : {
+      32                 :            :     libspdm_test_context_t *spdm_test_context;
+      33                 :            : 
+      34                 :          0 :     spdm_test_context = libspdm_get_test_context();
+      35         [ #  # ]:          0 :     switch (spdm_test_context->case_id) {
+      36                 :          0 :     case 0x1:
+      37                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+      38                 :          0 :     default:
+      39                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+      40                 :            :     }
+      41                 :            : }
+      42                 :            : 
+      43                 :            : /**
+      44                 :            :  * Test 1: message could not be sent
+      45                 :            :  * Expected Behavior: get a RETURN_DEVICE_ERROR return code
+      46                 :            :  **/
+      47                 :          1 : void libspdm_test_requester_get_key_pair_info_error_case1(void **state)
+      48                 :            : {
+      49                 :            :     libspdm_return_t status;
+      50                 :            :     libspdm_test_context_t *spdm_test_context;
+      51                 :            :     libspdm_context_t *spdm_context;
+      52                 :            : 
+      53                 :            :     uint8_t key_pair_id;
+      54                 :            :     uint8_t total_key_pairs;
+      55                 :            :     uint16_t capabilities;
+      56                 :            :     uint16_t key_usage_capabilities;
+      57                 :            :     uint16_t current_key_usage;
+      58                 :            :     uint32_t asym_algo_capabilities;
+      59                 :            :     uint32_t current_asym_algo;
+      60                 :            :     uint16_t public_key_info_len;
+      61                 :            :     uint8_t assoc_cert_slot_mask;
+      62                 :            :     uint8_t public_key_info[SPDM_MAX_PUBLIC_KEY_INFO_LEN];
+      63                 :            : 
+      64                 :          1 :     key_pair_id = 1;
+      65                 :          1 :     spdm_test_context = *state;
+      66                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+      67                 :          1 :     spdm_test_context->case_id = 0x1;
+      68                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+      69                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+      70                 :            : 
+      71                 :          1 :     spdm_context->connection_info.connection_state =
+      72                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+      73                 :          1 :     spdm_context->connection_info.capability.flags |=
+      74                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_GET_KEY_PAIR_INFO_CAP;
+      75                 :            : 
+      76                 :          1 :     public_key_info_len = SPDM_MAX_PUBLIC_KEY_INFO_LEN;
+      77                 :            : 
+      78                 :          1 :     status = libspdm_get_key_pair_info(spdm_context, NULL, key_pair_id, &total_key_pairs,
+      79                 :            :                                        &capabilities, &key_usage_capabilities, &current_key_usage,
+      80                 :            :                                        &asym_algo_capabilities, &current_asym_algo,
+      81                 :            :                                        &assoc_cert_slot_mask, &public_key_info_len,
+      82                 :            :                                        public_key_info);
+      83                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SEND_FAIL);
+      84                 :          1 : }
+      85                 :            : 
+      86                 :            : libspdm_test_context_t m_libspdm_requester_get_key_pair_info_error_test_context = {
+      87                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+      88                 :            :     true,
+      89                 :            :     libspdm_requester_get_key_pair_info_error_test_send_message,
+      90                 :            :     libspdm_requester_get_key_pair_info_error_test_receive_message,
+      91                 :            : };
+      92                 :            : 
+      93                 :          1 : int libspdm_requester_get_key_pair_info_error_test_main(void)
+      94                 :            : {
+      95                 :          1 :     const struct CMUnitTest spdm_requester_get_key_pair_info_error_tests[] = {
+      96                 :            :         /* SendRequest failed*/
+      97                 :            :         cmocka_unit_test(libspdm_test_requester_get_key_pair_info_error_case1),
+      98                 :            :     };
+      99                 :            : 
+     100                 :          1 :     libspdm_setup_test_context(
+     101                 :            :         &m_libspdm_requester_get_key_pair_info_error_test_context);
+     102                 :            : 
+     103                 :          1 :     return cmocka_run_group_tests(spdm_requester_get_key_pair_info_error_tests,
+     104                 :            :                                   libspdm_unit_test_group_setup,
+     105                 :            :                                   libspdm_unit_test_group_teardown);
+     106                 :            : }
+     107                 :            : 
+     108                 :            : #endif /*LIBSPDM_ENABLE_CAPABILITY_GET_KEY_PAIR_INFO_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/error_test/get_measurements_err.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_requester/error_test/get_measurements_err.c.func-sort-c.html new file mode 100644 index 00000000000..f0b2a63b017 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/error_test/get_measurements_err.c.func-sort-c.html @@ -0,0 +1,245 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/error_test/get_measurements_err.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester/error_test - get_measurements_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:1422206968.7 %
Date:2024-09-22 08:21:07Functions:4141100.0 %
Branches:7512858.6 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_get_measurements_error_test_main1
libspdm_test_requester_get_measurements_err_case11
libspdm_test_requester_get_measurements_err_case101
libspdm_test_requester_get_measurements_err_case111
libspdm_test_requester_get_measurements_err_case121
libspdm_test_requester_get_measurements_err_case131
libspdm_test_requester_get_measurements_err_case141
libspdm_test_requester_get_measurements_err_case151
libspdm_test_requester_get_measurements_err_case161
libspdm_test_requester_get_measurements_err_case171
libspdm_test_requester_get_measurements_err_case181
libspdm_test_requester_get_measurements_err_case191
libspdm_test_requester_get_measurements_err_case21
libspdm_test_requester_get_measurements_err_case201
libspdm_test_requester_get_measurements_err_case211
libspdm_test_requester_get_measurements_err_case221
libspdm_test_requester_get_measurements_err_case231
libspdm_test_requester_get_measurements_err_case241
libspdm_test_requester_get_measurements_err_case251
libspdm_test_requester_get_measurements_err_case261
libspdm_test_requester_get_measurements_err_case271
libspdm_test_requester_get_measurements_err_case281
libspdm_test_requester_get_measurements_err_case291
libspdm_test_requester_get_measurements_err_case31
libspdm_test_requester_get_measurements_err_case301
libspdm_test_requester_get_measurements_err_case311
libspdm_test_requester_get_measurements_err_case321
libspdm_test_requester_get_measurements_err_case331
libspdm_test_requester_get_measurements_err_case341
libspdm_test_requester_get_measurements_err_case351
libspdm_test_requester_get_measurements_err_case361
libspdm_test_requester_get_measurements_err_case371
libspdm_test_requester_get_measurements_err_case41
libspdm_test_requester_get_measurements_err_case51
libspdm_test_requester_get_measurements_err_case61
libspdm_test_requester_get_measurements_err_case71
libspdm_test_requester_get_measurements_err_case81
libspdm_test_requester_get_measurements_err_case91
libspdm_requester_get_measurements_test_receive_message139
libspdm_test_get_measurement_request_size140
libspdm_requester_get_measurements_test_send_message141
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/error_test/get_measurements_err.c.func.html b/coverage_log/unit_test/test_spdm_requester/error_test/get_measurements_err.c.func.html new file mode 100644 index 00000000000..38bae92fc82 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/error_test/get_measurements_err.c.func.html @@ -0,0 +1,245 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/error_test/get_measurements_err.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester/error_test - get_measurements_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:1422206968.7 %
Date:2024-09-22 08:21:07Functions:4141100.0 %
Branches:7512858.6 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_get_measurements_error_test_main1
libspdm_requester_get_measurements_test_receive_message139
libspdm_requester_get_measurements_test_send_message141
libspdm_test_get_measurement_request_size140
libspdm_test_requester_get_measurements_err_case11
libspdm_test_requester_get_measurements_err_case101
libspdm_test_requester_get_measurements_err_case111
libspdm_test_requester_get_measurements_err_case121
libspdm_test_requester_get_measurements_err_case131
libspdm_test_requester_get_measurements_err_case141
libspdm_test_requester_get_measurements_err_case151
libspdm_test_requester_get_measurements_err_case161
libspdm_test_requester_get_measurements_err_case171
libspdm_test_requester_get_measurements_err_case181
libspdm_test_requester_get_measurements_err_case191
libspdm_test_requester_get_measurements_err_case21
libspdm_test_requester_get_measurements_err_case201
libspdm_test_requester_get_measurements_err_case211
libspdm_test_requester_get_measurements_err_case221
libspdm_test_requester_get_measurements_err_case231
libspdm_test_requester_get_measurements_err_case241
libspdm_test_requester_get_measurements_err_case251
libspdm_test_requester_get_measurements_err_case261
libspdm_test_requester_get_measurements_err_case271
libspdm_test_requester_get_measurements_err_case281
libspdm_test_requester_get_measurements_err_case291
libspdm_test_requester_get_measurements_err_case31
libspdm_test_requester_get_measurements_err_case301
libspdm_test_requester_get_measurements_err_case311
libspdm_test_requester_get_measurements_err_case321
libspdm_test_requester_get_measurements_err_case331
libspdm_test_requester_get_measurements_err_case341
libspdm_test_requester_get_measurements_err_case351
libspdm_test_requester_get_measurements_err_case361
libspdm_test_requester_get_measurements_err_case371
libspdm_test_requester_get_measurements_err_case41
libspdm_test_requester_get_measurements_err_case51
libspdm_test_requester_get_measurements_err_case61
libspdm_test_requester_get_measurements_err_case71
libspdm_test_requester_get_measurements_err_case81
libspdm_test_requester_get_measurements_err_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/error_test/get_measurements_err.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/error_test/get_measurements_err.c.gcov.html new file mode 100644 index 00000000000..1cbea4ce9bd --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/error_test/get_measurements_err.c.gcov.html @@ -0,0 +1,4855 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/error_test/get_measurements_err.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester/error_test - get_measurements_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:1422206968.7 %
Date:2024-09-22 08:21:07Functions:4141100.0 %
Branches:7512858.6 %
+
+ + + + + + + + +

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

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_get_version_error_test_main1
libspdm_test_requester_get_version_err_case11
libspdm_test_requester_get_version_err_case101
libspdm_test_requester_get_version_err_case111
libspdm_test_requester_get_version_err_case121
libspdm_test_requester_get_version_err_case131
libspdm_test_requester_get_version_err_case141
libspdm_test_requester_get_version_err_case171
libspdm_test_requester_get_version_err_case181
libspdm_test_requester_get_version_err_case21
libspdm_test_requester_get_version_err_case31
libspdm_test_requester_get_version_err_case41
libspdm_test_requester_get_version_err_case51
libspdm_test_requester_get_version_err_case61
libspdm_test_requester_get_version_err_case71
libspdm_test_requester_get_version_err_case81
libspdm_test_requester_get_version_err_case91
receive_message30
send_message32
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/error_test/get_version_err.c.func.html b/coverage_log/unit_test/test_spdm_requester/error_test/get_version_err.c.func.html new file mode 100644 index 00000000000..d57294a6c8b --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/error_test/get_version_err.c.func.html @@ -0,0 +1,157 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/error_test/get_version_err.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester/error_test - get_version_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:32640580.5 %
Date:2024-09-22 08:21:07Functions:1919100.0 %
Branches:446073.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_get_version_error_test_main1
libspdm_test_requester_get_version_err_case11
libspdm_test_requester_get_version_err_case101
libspdm_test_requester_get_version_err_case111
libspdm_test_requester_get_version_err_case121
libspdm_test_requester_get_version_err_case131
libspdm_test_requester_get_version_err_case141
libspdm_test_requester_get_version_err_case171
libspdm_test_requester_get_version_err_case181
libspdm_test_requester_get_version_err_case21
libspdm_test_requester_get_version_err_case31
libspdm_test_requester_get_version_err_case41
libspdm_test_requester_get_version_err_case51
libspdm_test_requester_get_version_err_case61
libspdm_test_requester_get_version_err_case71
libspdm_test_requester_get_version_err_case81
libspdm_test_requester_get_version_err_case91
receive_message30
send_message32
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/error_test/get_version_err.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/error_test/get_version_err.c.gcov.html new file mode 100644 index 00000000000..ace5f929a53 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/error_test/get_version_err.c.gcov.html @@ -0,0 +1,975 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/error_test/get_version_err.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester/error_test - get_version_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:32640580.5 %
Date:2024-09-22 08:21:07Functions:1919100.0 %
Branches:446073.3 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_requester_lib.h"
+       9                 :            : 
+      10                 :            : #pragma pack(1)
+      11                 :            : typedef struct {
+      12                 :            :     spdm_message_header_t header;
+      13                 :            :     uint8_t reserved;
+      14                 :            :     uint8_t version_number_entry_count;
+      15                 :            :     spdm_version_number_t version_number_entry[LIBSPDM_MAX_VERSION_COUNT];
+      16                 :            : } libspdm_version_response_mine_t;
+      17                 :            : #pragma pack()
+      18                 :            : 
+      19                 :            : static size_t m_libspdm_local_buffer_size;
+      20                 :            : static uint8_t m_libspdm_local_buffer[LIBSPDM_MAX_MESSAGE_VCA_BUFFER_SIZE];
+      21                 :            : 
+      22                 :         32 : static libspdm_return_t send_message(
+      23                 :            :     void *spdm_context, size_t request_size, const void *request,
+      24                 :            :     uint64_t timeout)
+      25                 :            : {
+      26                 :            :     libspdm_test_context_t *spdm_test_context;
+      27                 :            : 
+      28                 :         32 :     spdm_test_context = libspdm_get_test_context();
+      29   [ +  -  +  +  :         32 :     switch (spdm_test_context->case_id) {
+          +  +  +  +  +  
+          +  +  +  +  +  
+             -  -  +  +  
+                      - ]
+      30                 :          1 :     case 0x1:
+      31                 :          1 :         return LIBSPDM_STATUS_SEND_FAIL;
+      32                 :          0 :     case 0x2:
+      33                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      34                 :          1 :     case 0x3:
+      35                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      36                 :          1 :     case 0x4:
+      37                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      38                 :          1 :     case 0x5:
+      39                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      40                 :          1 :     case 0x6:
+      41                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      42                 :          1 :     case 0x7:
+      43                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      44                 :          1 :     case 0x8:
+      45                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      46                 :          1 :     case 0x9:
+      47                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      48                 :          1 :     case 0xA:
+      49                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      50                 :          1 :     case 0xB:
+      51                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      52                 :          1 :     case 0xC:
+      53                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      54                 :          1 :     case 0xD:
+      55                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      56                 :         18 :     case 0xE:
+      57                 :         18 :         return LIBSPDM_STATUS_SUCCESS;
+      58                 :          0 :     case 0xF:
+      59                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      60                 :          0 :     case 0x10: {
+      61                 :          0 :         const uint8_t *ptr = (const uint8_t *)request;
+      62                 :            : 
+      63                 :          0 :         m_libspdm_local_buffer_size = 0;
+      64                 :          0 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+      65                 :          0 :                          &ptr[1], request_size - 1);
+      66                 :          0 :         m_libspdm_local_buffer_size += (request_size - 1);
+      67                 :            :     }
+      68                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      69                 :          1 :     case 0x11:
+      70                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      71                 :          1 :     case 0x12:
+      72                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      73                 :          0 :     default:
+      74                 :          0 :         return LIBSPDM_STATUS_SEND_FAIL;
+      75                 :            :     }
+      76                 :            : }
+      77                 :            : 
+      78                 :         30 : static libspdm_return_t receive_message(
+      79                 :            :     void *spdm_context, size_t *response_size,
+      80                 :            :     void **response, uint64_t timeout)
+      81                 :            : {
+      82                 :            :     libspdm_test_context_t *spdm_test_context;
+      83                 :            : 
+      84                 :         30 :     spdm_test_context = libspdm_get_test_context();
+      85   [ -  -  +  +  :         30 :     switch (spdm_test_context->case_id) {
+          +  -  +  +  +  
+          +  +  +  +  +  
+             -  -  +  +  
+                      - ]
+      86                 :          0 :     case 0x1:
+      87                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+      88                 :            : 
+      89                 :          0 :     case 0x2:
+      90                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      91                 :            : 
+      92                 :          1 :     case 0x3: {
+      93                 :            :         spdm_version_response_t *spdm_response;
+      94                 :            :         size_t spdm_response_size;
+      95                 :            :         size_t transport_header_size;
+      96                 :            : 
+      97                 :          1 :         spdm_response_size = sizeof(spdm_version_response_t);
+      98                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+      99                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     100                 :            : 
+     101                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     102                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     103                 :          1 :         spdm_response->header.request_response_code = SPDM_VERSION;
+     104                 :          1 :         spdm_response->header.param1 = 0;
+     105                 :          1 :         spdm_response->header.param2 = 0;
+     106                 :          1 :         spdm_response->version_number_entry_count = 0;
+     107                 :            : 
+     108                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     109                 :            :                                               false, spdm_response_size,
+     110                 :            :                                               spdm_response,
+     111                 :            :                                               response_size, response);
+     112                 :            :     }
+     113                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     114                 :            : 
+     115                 :          1 :     case 0x4: {
+     116                 :            :         spdm_error_response_t *spdm_response;
+     117                 :            :         size_t spdm_response_size;
+     118                 :            :         size_t transport_header_size;
+     119                 :            : 
+     120                 :          1 :         spdm_response_size = sizeof(spdm_error_response_t);
+     121                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     122                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     123                 :            : 
+     124                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     125                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     126                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     127                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_INVALID_REQUEST;
+     128                 :          1 :         spdm_response->header.param2 = 0;
+     129                 :            : 
+     130                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     131                 :            :                                               false, spdm_response_size,
+     132                 :            :                                               spdm_response,
+     133                 :            :                                               response_size, response);
+     134                 :            :     }
+     135                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     136                 :            : 
+     137                 :          1 :     case 0x5: {
+     138                 :            :         spdm_error_response_t *spdm_response;
+     139                 :            :         size_t spdm_response_size;
+     140                 :            :         size_t transport_header_size;
+     141                 :            : 
+     142                 :          1 :         spdm_response_size = sizeof(spdm_error_response_t);
+     143                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     144                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     145                 :            : 
+     146                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     147                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     148                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     149                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
+     150                 :          1 :         spdm_response->header.param2 = 0;
+     151                 :            : 
+     152                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     153                 :            :                                               false, spdm_response_size,
+     154                 :            :                                               spdm_response,
+     155                 :            :                                               response_size, response);
+     156                 :            :     }
+     157                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     158                 :            : 
+     159                 :          0 :     case 0x6: {
+     160                 :            :         static size_t sub_index1 = 0;
+     161         [ #  # ]:          0 :         if (sub_index1 == 0) {
+     162                 :            :             spdm_error_response_t *spdm_response;
+     163                 :            :             size_t spdm_response_size;
+     164                 :            :             size_t transport_header_size;
+     165                 :            : 
+     166                 :          0 :             spdm_response_size = sizeof(spdm_error_response_t);
+     167                 :          0 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     168                 :          0 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     169                 :            : 
+     170                 :          0 :             libspdm_zero_mem(spdm_response, spdm_response_size);
+     171                 :          0 :             spdm_response->header.spdm_version =
+     172                 :            :                 SPDM_MESSAGE_VERSION_10;
+     173                 :          0 :             spdm_response->header.request_response_code = SPDM_ERROR;
+     174                 :          0 :             spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
+     175                 :          0 :             spdm_response->header.param2 = 0;
+     176                 :            : 
+     177                 :          0 :             libspdm_transport_test_encode_message(
+     178                 :            :                 spdm_context, NULL, false, false,
+     179                 :            :                 spdm_response_size, spdm_response,
+     180                 :            :                 response_size, response);
+     181         [ #  # ]:          0 :         } else if (sub_index1 == 1) {
+     182                 :            :             libspdm_version_response_mine_t *spdm_response;
+     183                 :            :             size_t spdm_response_size;
+     184                 :            :             size_t transport_header_size;
+     185                 :            : 
+     186                 :          0 :             spdm_response_size = sizeof(libspdm_version_response_mine_t);
+     187                 :          0 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     188                 :          0 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     189                 :            : 
+     190                 :          0 :             libspdm_zero_mem(spdm_response, spdm_response_size);
+     191                 :          0 :             spdm_response->header.spdm_version =
+     192                 :            :                 SPDM_MESSAGE_VERSION_10;
+     193                 :          0 :             spdm_response->header.request_response_code =
+     194                 :            :                 SPDM_VERSION;
+     195                 :          0 :             spdm_response->header.param1 = 0;
+     196                 :          0 :             spdm_response->header.param2 = 0;
+     197                 :          0 :             spdm_response->version_number_entry_count = 2;
+     198                 :          0 :             spdm_response->version_number_entry[0] = 0x10 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     199                 :          0 :             spdm_response->version_number_entry[1] = 0x11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     200                 :            : 
+     201                 :          0 :             libspdm_transport_test_encode_message(
+     202                 :            :                 spdm_context, NULL, false, false,
+     203                 :            :                 spdm_response_size, spdm_response,
+     204                 :            :                 response_size, response);
+     205                 :            :         }
+     206                 :          0 :         sub_index1++;
+     207                 :            :     }
+     208                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     209                 :            : 
+     210                 :          1 :     case 0x7: {
+     211                 :            :         spdm_error_response_t *spdm_response;
+     212                 :            :         size_t spdm_response_size;
+     213                 :            :         size_t transport_header_size;
+     214                 :            : 
+     215                 :          1 :         spdm_response_size = sizeof(spdm_error_response_t);
+     216                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     217                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     218                 :            : 
+     219                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     220                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     221                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     222                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_REQUEST_RESYNCH;
+     223                 :          1 :         spdm_response->header.param2 = 0;
+     224                 :            : 
+     225                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     226                 :            :                                               false, spdm_response_size,
+     227                 :            :                                               spdm_response,
+     228                 :            :                                               response_size, response);
+     229                 :            :     }
+     230                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     231                 :            : 
+     232                 :          1 :     case 0x8: {
+     233                 :            :         spdm_error_response_data_response_not_ready_t *spdm_response;
+     234                 :            :         size_t spdm_response_size;
+     235                 :            :         size_t transport_header_size;
+     236                 :            : 
+     237                 :          1 :         spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
+     238                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     239                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     240                 :            : 
+     241                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     242                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     243                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     244                 :          1 :         spdm_response->header.param1 =
+     245                 :            :             SPDM_ERROR_CODE_RESPONSE_NOT_READY;
+     246                 :          1 :         spdm_response->header.param2 = 0;
+     247                 :          1 :         spdm_response->extend_error_data.rd_exponent = 1;
+     248                 :          1 :         spdm_response->extend_error_data.rd_tm = 2;
+     249                 :          1 :         spdm_response->extend_error_data.request_code = SPDM_GET_VERSION;
+     250                 :          1 :         spdm_response->extend_error_data.token = 0;
+     251                 :            : 
+     252                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     253                 :            :                                               false, spdm_response_size,
+     254                 :            :                                               spdm_response,
+     255                 :            :                                               response_size, response);
+     256                 :            :     }
+     257                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     258                 :            : 
+     259                 :          1 :     case 0x9: {
+     260                 :            :         libspdm_version_response_mine_t *spdm_response;
+     261                 :            :         size_t spdm_response_size;
+     262                 :            :         size_t transport_header_size;
+     263                 :            : 
+     264                 :          1 :         spdm_response_size = sizeof(libspdm_version_response_mine_t);
+     265                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     266                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     267                 :            : 
+     268                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     269                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     270                 :          1 :         spdm_response->header.request_response_code = SPDM_VERSION;
+     271                 :          1 :         spdm_response->header.param1 = 0;
+     272                 :          1 :         spdm_response->header.param2 = 0;
+     273                 :          1 :         spdm_response->version_number_entry_count = 255;
+     274                 :          1 :         spdm_response->version_number_entry[0] = 0x10 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     275                 :          1 :         spdm_response->version_number_entry[1] = 0x11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     276                 :          1 :         spdm_response->version_number_entry[2] = 0x12 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     277                 :            : 
+     278                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     279                 :            :                                               false, spdm_response_size,
+     280                 :            :                                               spdm_response,
+     281                 :            :                                               response_size, response);
+     282                 :            :     }
+     283                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     284                 :            : 
+     285                 :          1 :     case 0xA:
+     286                 :          1 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+     287                 :            : 
+     288                 :          1 :     case 0xB: {
+     289                 :            :         libspdm_version_response_mine_t *spdm_response;
+     290                 :            :         size_t spdm_response_size;
+     291                 :            :         size_t transport_header_size;
+     292                 :            : 
+     293                 :          1 :         spdm_response_size = sizeof(libspdm_version_response_mine_t);
+     294                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     295                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     296                 :            : 
+     297                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     298                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     299                 :          1 :         spdm_response->header.request_response_code = SPDM_VERSION;
+     300                 :          1 :         spdm_response->header.param1 = 0;
+     301                 :          1 :         spdm_response->header.param2 = 0;
+     302                 :          1 :         spdm_response->version_number_entry_count = 2;
+     303                 :          1 :         spdm_response->version_number_entry[0] = 0xA0 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     304                 :          1 :         spdm_response->version_number_entry[1] = 0xA1 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     305                 :            : 
+     306                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     307                 :            :                                               false, spdm_response_size,
+     308                 :            :                                               spdm_response,
+     309                 :            :                                               response_size, response);
+     310                 :            :     }
+     311                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     312                 :            : 
+     313                 :          1 :     case 0xC: {
+     314                 :            :         libspdm_version_response_mine_t *spdm_response;
+     315                 :            :         size_t spdm_response_size;
+     316                 :            :         size_t transport_header_size;
+     317                 :            : 
+     318                 :          1 :         spdm_response_size = sizeof(libspdm_version_response_mine_t);
+     319                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     320                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     321                 :            : 
+     322                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     323                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     324                 :          1 :         spdm_response->header.request_response_code = SPDM_VERSION;
+     325                 :          1 :         spdm_response->header.param1 = 0;
+     326                 :          1 :         spdm_response->header.param2 = 0;
+     327                 :          1 :         spdm_response->version_number_entry_count = 2;
+     328                 :          1 :         spdm_response->version_number_entry[0] = 0x10 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     329                 :          1 :         spdm_response->version_number_entry[1] = 0x11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     330                 :            : 
+     331                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     332                 :            :                                               false, spdm_response_size,
+     333                 :            :                                               spdm_response,
+     334                 :            :                                               response_size, response);
+     335                 :            :     }
+     336                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     337                 :            : 
+     338                 :          1 :     case 0xD: {
+     339                 :            :         libspdm_version_response_mine_t *spdm_response;
+     340                 :            :         size_t spdm_response_size;
+     341                 :            :         size_t transport_header_size;
+     342                 :            : 
+     343                 :          1 :         spdm_response_size = sizeof(libspdm_version_response_mine_t);
+     344                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     345                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     346                 :            : 
+     347                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     348                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     349                 :          1 :         spdm_response->header.request_response_code = SPDM_GET_VERSION;
+     350                 :          1 :         spdm_response->header.param1 = 0;
+     351                 :          1 :         spdm_response->header.param2 = 0;
+     352                 :          1 :         spdm_response->version_number_entry_count = 2;
+     353                 :          1 :         spdm_response->version_number_entry[0] = 0x10 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     354                 :          1 :         spdm_response->version_number_entry[1] = 0x11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     355                 :            : 
+     356                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     357                 :            :                                               false, spdm_response_size,
+     358                 :            :                                               spdm_response,
+     359                 :            :                                               response_size, response);
+     360                 :            :     }
+     361                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     362                 :            : 
+     363                 :         18 :     case 0xE:
+     364                 :            :     {
+     365                 :            :         static uint16_t error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
+     366                 :            : 
+     367                 :            :         spdm_error_response_t *spdm_response;
+     368                 :            :         size_t spdm_response_size;
+     369                 :            :         size_t transport_header_size;
+     370                 :            : 
+     371                 :         18 :         spdm_response_size = sizeof(libspdm_version_response_mine_t);
+     372                 :         18 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     373                 :         18 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     374                 :            : 
+     375         [ +  - ]:         18 :         if(error_code <= 0xff) {
+     376                 :         18 :             libspdm_zero_mem (spdm_response, spdm_response_size);
+     377                 :         18 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     378                 :         18 :             spdm_response->header.request_response_code = SPDM_ERROR;
+     379                 :         18 :             spdm_response->header.param1 = (uint8_t) error_code;
+     380                 :            : 
+     381                 :         18 :             libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+     382                 :            :                                                    spdm_response_size, spdm_response,
+     383                 :            :                                                    response_size, response);
+     384                 :            :         }
+     385                 :            : 
+     386                 :         18 :         error_code++;
+     387         [ +  + ]:         18 :         if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
+     388                 :          1 :             error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
+     389                 :            :         }
+     390         [ +  + ]:         18 :         if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) { /*skip some reserved error codes (0d to 3e)*/
+     391                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
+     392                 :            :         }
+     393         [ +  + ]:         18 :         if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) { /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
+     394                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
+     395                 :            :         }
+     396                 :            :     }
+     397                 :         18 :         return LIBSPDM_STATUS_SUCCESS;
+     398                 :            : 
+     399                 :          0 :     case 0xF: {
+     400                 :            :         libspdm_version_response_mine_t *spdm_response;
+     401                 :            :         size_t spdm_response_size;
+     402                 :            :         size_t transport_header_size;
+     403                 :            : 
+     404                 :          0 :         spdm_response_size = sizeof(libspdm_version_response_mine_t);
+     405                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     406                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     407                 :            : 
+     408                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     409                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     410                 :          0 :         spdm_response->header.request_response_code = SPDM_VERSION;
+     411                 :          0 :         spdm_response->header.param1 = 0;
+     412                 :          0 :         spdm_response->header.param2 = 0;
+     413                 :          0 :         spdm_response->version_number_entry_count = 5;
+     414                 :          0 :         spdm_response->version_number_entry[0] = 0x42 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     415                 :          0 :         spdm_response->version_number_entry[1] = 0x52 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     416                 :          0 :         spdm_response->version_number_entry[2] = 0x12 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     417                 :          0 :         spdm_response->version_number_entry[3] = 0x11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     418                 :          0 :         spdm_response->version_number_entry[4] = 0x10 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     419                 :            : 
+     420                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     421                 :            :                                               false, spdm_response_size,
+     422                 :            :                                               spdm_response,
+     423                 :            :                                               response_size, response);
+     424                 :            :     }
+     425                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     426                 :            : 
+     427                 :          0 :     case 0x10: {
+     428                 :            :         libspdm_version_response_mine_t *spdm_response;
+     429                 :            :         size_t spdm_response_size;
+     430                 :            :         size_t transport_header_size;
+     431                 :            : 
+     432                 :          0 :         spdm_response_size = sizeof(libspdm_version_response_mine_t);
+     433                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     434                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     435                 :            : 
+     436                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     437                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     438                 :          0 :         spdm_response->header.request_response_code = SPDM_VERSION;
+     439                 :          0 :         spdm_response->header.param1 = 0;
+     440                 :          0 :         spdm_response->header.param2 = 0;
+     441                 :          0 :         spdm_response->version_number_entry_count = 2;
+     442                 :          0 :         spdm_response->version_number_entry[0] = 0x10 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     443                 :          0 :         spdm_response->version_number_entry[1] = 0x11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     444                 :            : 
+     445                 :          0 :         spdm_response_size = 10;
+     446                 :            : 
+     447                 :          0 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+     448                 :            :                          sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
+     449                 :            :                          (uint8_t *)spdm_response, spdm_response_size);
+     450                 :          0 :         m_libspdm_local_buffer_size += spdm_response_size;
+     451                 :            : 
+     452                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     453                 :            :                                               false, spdm_response_size,
+     454                 :            :                                               spdm_response,
+     455                 :            :                                               response_size, response);
+     456                 :            :     }
+     457                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     458                 :            : 
+     459                 :          1 :     case 0x11: {
+     460                 :            :         spdm_message_header_t *spdm_response;
+     461                 :            :         size_t spdm_response_size;
+     462                 :            :         size_t transport_header_size;
+     463                 :            : 
+     464                 :          1 :         spdm_response_size = sizeof(spdm_message_header_t);
+     465                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     466                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     467                 :            : 
+     468                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     469                 :          1 :         spdm_response->spdm_version = SPDM_MESSAGE_VERSION_10;
+     470                 :          1 :         spdm_response->request_response_code = SPDM_VERSION;
+     471                 :          1 :         spdm_response->param1 = 0;
+     472                 :          1 :         spdm_response->param2 = 0;
+     473                 :            : 
+     474                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     475                 :            :                                               false, spdm_response_size,
+     476                 :            :                                               spdm_response,
+     477                 :            :                                               response_size, response);
+     478                 :            : 
+     479                 :            :     }
+     480                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     481                 :            : 
+     482                 :          1 :     case 0x12: {
+     483                 :            :         spdm_version_response_t *spdm_response;
+     484                 :            :         size_t spdm_response_size;
+     485                 :            :         size_t transport_header_size;
+     486                 :            : 
+     487                 :          1 :         spdm_response_size = sizeof(spdm_version_response_t);
+     488                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     489                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     490                 :            : 
+     491                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     492                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     493                 :          1 :         spdm_response->header.request_response_code = SPDM_VERSION;
+     494                 :          1 :         spdm_response->header.param1 = 0;
+     495                 :          1 :         spdm_response->header.param2 = 0;
+     496                 :          1 :         spdm_response->version_number_entry_count = LIBSPDM_MAX_VERSION_COUNT;
+     497                 :            : 
+     498                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     499                 :            :                                               false, spdm_response_size,
+     500                 :            :                                               spdm_response,
+     501                 :            :                                               response_size, response);
+     502                 :            : 
+     503                 :            :     }
+     504                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     505                 :            : 
+     506                 :          0 :     default:
+     507                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+     508                 :            :     }
+     509                 :            : }
+     510                 :            : 
+     511                 :            : /**
+     512                 :            :  * Test 1: Unable to send the GET_VERSION request.
+     513                 :            :  * Expected behavior: returns a status of LIBSPDM_STATUS_SEND_FAIL.
+     514                 :            :  **/
+     515                 :          1 : static void libspdm_test_requester_get_version_err_case1(void **state)
+     516                 :            : {
+     517                 :            :     libspdm_return_t status;
+     518                 :            :     libspdm_test_context_t *spdm_test_context;
+     519                 :            :     libspdm_context_t *spdm_context;
+     520                 :            : 
+     521                 :          1 :     spdm_test_context = *state;
+     522                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     523                 :          1 :     spdm_test_context->case_id = 0x1;
+     524                 :            : 
+     525                 :          1 :     status = libspdm_get_version(spdm_context, NULL, NULL);
+     526                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SEND_FAIL);
+     527                 :          1 : }
+     528                 :            : 
+     529                 :            : /**
+     530                 :            :  * Test 2: Requester is unable to acquire the sender buffer.
+     531                 :            :  * Expected behavior: returns with status LIBSPDM_STATUS_ACQUIRE_FAIL.
+     532                 :            :  **/
+     533                 :          1 : static void libspdm_test_requester_get_version_err_case2(void **state)
+     534                 :            : {
+     535                 :            :     libspdm_return_t status;
+     536                 :            :     libspdm_test_context_t *spdm_test_context;
+     537                 :            :     libspdm_context_t *spdm_context;
+     538                 :            : 
+     539                 :          1 :     spdm_test_context = *state;
+     540                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     541                 :          1 :     spdm_test_context->case_id = 0x2;
+     542                 :            : 
+     543                 :          1 :     libspdm_force_error (LIBSPDM_ERR_ACQUIRE_SENDER_BUFFER);
+     544                 :          1 :     status = libspdm_get_version(spdm_context, NULL, NULL);
+     545                 :          1 :     libspdm_release_error (LIBSPDM_ERR_ACQUIRE_SENDER_BUFFER);
+     546                 :            : 
+     547                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_ACQUIRE_FAIL);
+     548                 :          1 : }
+     549                 :            : 
+     550                 :            : /**
+     551                 :            :  * Test 3: receiving a correct VERSION message header, but with 0 versions available.
+     552                 :            :  * Expected behavior: client returns a status of LIBSPDM_STATUS_INVALID_MSG_FIELD.
+     553                 :            :  **/
+     554                 :          1 : static void libspdm_test_requester_get_version_err_case3(void **state)
+     555                 :            : {
+     556                 :            :     libspdm_return_t status;
+     557                 :            :     libspdm_test_context_t *spdm_test_context;
+     558                 :            :     libspdm_context_t *spdm_context;
+     559                 :            : 
+     560                 :          1 :     spdm_test_context = *state;
+     561                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     562                 :          1 :     spdm_test_context->case_id = 0x3;
+     563                 :            : 
+     564                 :          1 :     status = libspdm_get_version(spdm_context, NULL, NULL);
+     565                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+     566                 :          1 : }
+     567                 :            : 
+     568                 :            : /**
+     569                 :            :  * Test 4: receiving an InvalidRequest ERROR message from the responder.
+     570                 :            :  * Expected behavior: client returns a status of LIBSPDM_STATUS_ERROR_PEER.
+     571                 :            :  **/
+     572                 :          1 : static void libspdm_test_requester_get_version_err_case4(void **state)
+     573                 :            : {
+     574                 :            :     libspdm_return_t status;
+     575                 :            :     libspdm_test_context_t *spdm_test_context;
+     576                 :            :     libspdm_context_t *spdm_context;
+     577                 :            : 
+     578                 :          1 :     spdm_test_context = *state;
+     579                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     580                 :          1 :     spdm_test_context->case_id = 0x4;
+     581                 :            : 
+     582                 :          1 :     status = libspdm_get_version(spdm_context, NULL, NULL);
+     583                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_ERROR_PEER);
+     584                 :          1 : }
+     585                 :            : 
+     586                 :            : /**
+     587                 :            :  * Test 5: receiving a Busy ERROR message correct VERSION message from the responder.
+     588                 :            :  * Expected behavior: client returns a status of LIBSPDM_STATUS_BUSY_PEER.
+     589                 :            :  **/
+     590                 :          1 : static void libspdm_test_requester_get_version_err_case5(void **state)
+     591                 :            : {
+     592                 :            :     libspdm_return_t status;
+     593                 :            :     libspdm_test_context_t *spdm_test_context;
+     594                 :            :     libspdm_context_t *spdm_context;
+     595                 :            : 
+     596                 :          1 :     spdm_test_context = *state;
+     597                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     598                 :          1 :     spdm_test_context->case_id = 0x5;
+     599                 :            : 
+     600                 :          1 :     status = libspdm_get_version(spdm_context, NULL, NULL);
+     601                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_BUSY_PEER);
+     602                 :          1 : }
+     603                 :            : 
+     604                 :            : /**
+     605                 :            :  * Test 6: Requester is unable to acquire the receiver buffer.
+     606                 :            :  * Expected behavior: returns with status LIBSPDM_STATUS_ACQUIRE_FAIL.
+     607                 :            :  **/
+     608                 :          1 : static void libspdm_test_requester_get_version_err_case6(void **state)
+     609                 :            : {
+     610                 :            :     libspdm_return_t status;
+     611                 :            :     libspdm_test_context_t *spdm_test_context;
+     612                 :            :     libspdm_context_t *spdm_context;
+     613                 :            : 
+     614                 :          1 :     spdm_test_context = *state;
+     615                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     616                 :          1 :     spdm_test_context->case_id = 0x6;
+     617                 :            : 
+     618                 :          1 :     libspdm_force_error (LIBSPDM_ERR_ACQUIRE_RECEIVER_BUFFER);
+     619                 :          1 :     status = libspdm_get_version(spdm_context, NULL, NULL);
+     620                 :          1 :     libspdm_release_error (LIBSPDM_ERR_ACQUIRE_RECEIVER_BUFFER);
+     621                 :            : 
+     622                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_ACQUIRE_FAIL);
+     623                 :          1 : }
+     624                 :            : 
+     625                 :            : /**
+     626                 :            :  * Test 7: receiving a RequestResynch ERROR message from the responder.
+     627                 :            :  * Expected behavior: client returns a status of LIBSPDM_STATUS_RESYNCH_PEER, and the
+     628                 :            :  * internal state should be reset.
+     629                 :            :  **/
+     630                 :          1 : static void libspdm_test_requester_get_version_err_case7(void **state)
+     631                 :            : {
+     632                 :            :     libspdm_return_t status;
+     633                 :            :     libspdm_test_context_t *spdm_test_context;
+     634                 :            :     libspdm_context_t *spdm_context;
+     635                 :            : 
+     636                 :          1 :     spdm_test_context = *state;
+     637                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     638                 :          1 :     spdm_test_context->case_id = 0x7;
+     639                 :            : 
+     640                 :          1 :     status = libspdm_get_version(spdm_context, NULL, NULL);
+     641                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_RESYNCH_PEER);
+     642                 :          1 :     assert_int_equal(spdm_context->connection_info.connection_state,
+     643                 :            :                      LIBSPDM_CONNECTION_STATE_NOT_STARTED);
+     644                 :          1 : }
+     645                 :            : 
+     646                 :            : /**
+     647                 :            :  * Test 8: receiving a ResponseNotReady ERROR message from the responder,
+     648                 :            :  * but Responder shall not respond to the GET_VERSION request message with ErrorCode=ResponseNotReady.
+     649                 :            :  * Expected behavior: client returns a status of LIBSPDM_STATUS_ERROR_PEER,
+     650                 :            :  * Received an unexpected error message.
+     651                 :            :  **/
+     652                 :          1 : static void libspdm_test_requester_get_version_err_case8(void **state)
+     653                 :            : {
+     654                 :            :     libspdm_return_t status;
+     655                 :            :     libspdm_test_context_t *spdm_test_context;
+     656                 :            :     libspdm_context_t *spdm_context;
+     657                 :            : 
+     658                 :          1 :     spdm_test_context = *state;
+     659                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     660                 :          1 :     spdm_test_context->case_id = 0x8;
+     661                 :            : 
+     662                 :          1 :     status = libspdm_get_version(spdm_context, NULL, NULL);
+     663                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_ERROR_PEER);
+     664                 :          1 : }
+     665                 :            : 
+     666                 :            : /**
+     667                 :            :  * Test 9: Number of version entries are larger than what the Requester can tolerate.
+     668                 :            :  * Expected behavior: returns a status of LIBSPDM_STATUS_INVALID_MSG_FIELD.
+     669                 :            :  **/
+     670                 :          1 : static void libspdm_test_requester_get_version_err_case9(void **state)
+     671                 :            : {
+     672                 :            :     libspdm_return_t status;
+     673                 :            :     libspdm_test_context_t *spdm_test_context;
+     674                 :            :     libspdm_context_t *spdm_context;
+     675                 :            : 
+     676                 :            :     LIBSPDM_ASSERT(LIBSPDM_MAX_VERSION_COUNT != 255);
+     677                 :            : 
+     678                 :          1 :     spdm_test_context = *state;
+     679                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     680                 :          1 :     spdm_test_context->case_id = 0x9;
+     681                 :            : 
+     682                 :          1 :     status = libspdm_get_version(spdm_context, NULL, NULL);
+     683                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+     684                 :          1 : }
+     685                 :            : 
+     686                 :            : /**
+     687                 :            :  * Test 10: Requester is unable to receive a VERSION response from the Responder.
+     688                 :            :  * Expected behavior: returns a status of LIBSPDM_STATUS_RECEIVE_FAIL.
+     689                 :            :  **/
+     690                 :          1 : static void libspdm_test_requester_get_version_err_case10(void **state)
+     691                 :            : {
+     692                 :            :     libspdm_return_t status;
+     693                 :            :     libspdm_test_context_t *spdm_test_context;
+     694                 :            :     libspdm_context_t *spdm_context;
+     695                 :            : 
+     696                 :          1 :     spdm_test_context = *state;
+     697                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     698                 :          1 :     spdm_test_context->case_id = 0xa;
+     699                 :            : 
+     700                 :          1 :     status = libspdm_get_version(spdm_context, NULL, NULL);
+     701                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_RECEIVE_FAIL);
+     702                 :          1 : }
+     703                 :            : 
+     704                 :            : /**
+     705                 :            :  * Test 11: receiving a correct VERSION message with available version 1.0 and 1.1, but
+     706                 :            :  * the requester do not have compatible versions with the responder.
+     707                 :            :  * Expected behavior: client returns a status of LIBSPDM_STATUS_NEGOTIATION_FAIL.
+     708                 :            :  **/
+     709                 :          1 : static void libspdm_test_requester_get_version_err_case11(void **state)
+     710                 :            : {
+     711                 :            :     libspdm_return_t status;
+     712                 :            :     libspdm_test_context_t *spdm_test_context;
+     713                 :            :     libspdm_context_t *spdm_context;
+     714                 :            : 
+     715                 :          1 :     spdm_test_context = *state;
+     716                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     717                 :          1 :     spdm_test_context->case_id = 0xB;
+     718                 :            : 
+     719                 :          1 :     status = libspdm_get_version(spdm_context, NULL, NULL);
+     720                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_NEGOTIATION_FAIL);
+     721                 :          1 : }
+     722                 :            : 
+     723                 :            : /**
+     724                 :            :  * Test 12: receiving a VERSION message in SPDM version 1.1 (in the header), but correct
+     725                 :            :  * 1.0-version format, with available version 1.0 and 1.1.
+     726                 :            :  * Expected behavior: client returns a status of LIBSPDM_STATUS_INVALID_MSG_FIELD.
+     727                 :            :  **/
+     728                 :          1 : static void libspdm_test_requester_get_version_err_case12(void **state)
+     729                 :            : {
+     730                 :            :     libspdm_return_t status;
+     731                 :            :     libspdm_test_context_t *spdm_test_context;
+     732                 :            :     libspdm_context_t *spdm_context;
+     733                 :            : 
+     734                 :          1 :     spdm_test_context = *state;
+     735                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     736                 :          1 :     spdm_test_context->case_id = 0xC;
+     737                 :            : 
+     738                 :          1 :     status = libspdm_get_version(spdm_context, NULL, NULL);
+     739                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+     740                 :          1 : }
+     741                 :            : 
+     742                 :            : /**
+     743                 :            :  * Test 13: receiving a VERSION message with wrong SPDM request_response_code (in this
+     744                 :            :  * case, GET_VERSION 0x84 instead of VERSION 0x04). The remaining data is a correct
+     745                 :            :  * VERSION message, with available version 1.0 and 1.1.
+     746                 :            :  * Expected behavior: client returns a status of LIBSPDM_STATUS_INVALID_MSG_FIELD.
+     747                 :            :  **/
+     748                 :          1 : static void libspdm_test_requester_get_version_err_case13(void **state)
+     749                 :            : {
+     750                 :            :     libspdm_return_t status;
+     751                 :            :     libspdm_test_context_t *spdm_test_context;
+     752                 :            :     libspdm_context_t *spdm_context;
+     753                 :            : 
+     754                 :          1 :     spdm_test_context = *state;
+     755                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     756                 :          1 :     spdm_test_context->case_id = 0xD;
+     757                 :            : 
+     758                 :          1 :     status = libspdm_get_version(spdm_context, NULL, NULL);
+     759                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+     760                 :          1 : }
+     761                 :            : 
+     762                 :            : /**
+     763                 :            :  * Test 14: receiving an unexpected ERROR message from the responder.
+     764                 :            :  * There are tests for all named codes, including some reserved ones
+     765                 :            :  * (namely, 0x00, 0x0b, 0x0c, 0x3f, 0xfd, 0xfe).
+     766                 :            :  * However, for having specific test cases, it is excluded from this case:
+     767                 :            :  * Busy (0x03), ResponseNotReady (0x42), and RequestResync (0x43).
+     768                 :            :  * Expected behavior: client returns a status of LIBSPDM_STATUS_ERROR_PEER.
+     769                 :            :  **/
+     770                 :          1 : static void libspdm_test_requester_get_version_err_case14(void **state) {
+     771                 :            :     libspdm_return_t status;
+     772                 :            :     libspdm_test_context_t    *spdm_test_context;
+     773                 :            :     libspdm_context_t  *spdm_context;
+     774                 :            :     uint16_t error_code;
+     775                 :            : 
+     776                 :          1 :     spdm_test_context = *state;
+     777                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     778                 :          1 :     spdm_test_context->case_id = 0xE;
+     779                 :            : 
+     780                 :          1 :     error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
+     781         [ +  + ]:         19 :     while(error_code <= 0xff) {
+     782                 :            :         /* no additional state control is necessary as a new GET_VERSION resets the state*/
+     783                 :         18 :         status = libspdm_get_version (spdm_context, NULL, NULL);
+     784         [ -  + ]:         18 :         LIBSPDM_ASSERT_INT_EQUAL_CASE (status, LIBSPDM_STATUS_ERROR_PEER, error_code);
+     785                 :            : 
+     786                 :         18 :         error_code++;
+     787         [ +  + ]:         18 :         if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
+     788                 :          1 :             error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
+     789                 :            :         }
+     790         [ +  + ]:         18 :         if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) { /*skip some reserved error codes (0d to 3e)*/
+     791                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
+     792                 :            :         }
+     793         [ +  + ]:         18 :         if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) { /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
+     794                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
+     795                 :            :         }
+     796                 :            :     }
+     797                 :          1 : }
+     798                 :            : 
+     799                 :            : /*
+     800                 :            :  * static void libspdm_test_requester_get_version_err_case15(void **state)
+     801                 :            :  * {
+     802                 :            :  * }
+     803                 :            :  */
+     804                 :            : 
+     805                 :            : /*
+     806                 :            :  * static void libspdm_test_requester_get_version_err_case16(void **state)
+     807                 :            :  * {
+     808                 :            :  * }
+     809                 :            :  */
+     810                 :            : 
+     811                 :            : /**
+     812                 :            :  * Test 17: when no VERSION message is received, and the client returns a device error.
+     813                 :            :  * Expected behavior: client returns a status of LIBSPDM_STATUS_INVALID_MSG_FIELD.
+     814                 :            :  **/
+     815                 :          1 : static void libspdm_test_requester_get_version_err_case17(void **state)
+     816                 :            : {
+     817                 :            :     libspdm_return_t status;
+     818                 :            :     libspdm_test_context_t *spdm_test_context;
+     819                 :            :     libspdm_context_t *spdm_context;
+     820                 :            : 
+     821                 :          1 :     spdm_test_context = *state;
+     822                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     823                 :          1 :     spdm_test_context->case_id = 0x11;
+     824                 :            : 
+     825                 :          1 :     status = libspdm_get_version(spdm_context, NULL, NULL);
+     826                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
+     827                 :          1 : }
+     828                 :            : 
+     829                 :            : /**
+     830                 :            :  * Test 18: when no VERSION message is received, and the client returns a device error.
+     831                 :            :  * Expected behavior: client returns a status of LIBSPDM_STATUS_INVALID_MSG_FIELD.
+     832                 :            :  **/
+     833                 :          1 : static void libspdm_test_requester_get_version_err_case18(void **state)
+     834                 :            : {
+     835                 :            :     libspdm_return_t status;
+     836                 :            :     libspdm_test_context_t *spdm_test_context;
+     837                 :            :     libspdm_context_t *spdm_context;
+     838                 :            : 
+     839                 :          1 :     spdm_test_context = *state;
+     840                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     841                 :          1 :     spdm_test_context->case_id = 0x12;
+     842                 :            : 
+     843                 :          1 :     status = libspdm_get_version(spdm_context, NULL, NULL);
+     844                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
+     845                 :          1 : }
+     846                 :            : 
+     847                 :            : static libspdm_test_context_t m_libspdm_requester_get_version_test_context = {
+     848                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+     849                 :            :     true,
+     850                 :            :     send_message,
+     851                 :            :     receive_message,
+     852                 :            : };
+     853                 :            : 
+     854                 :          1 : int libspdm_requester_get_version_error_test_main(void)
+     855                 :            : {
+     856                 :          1 :     const struct CMUnitTest spdm_requester_get_version_tests[] = {
+     857                 :            :         cmocka_unit_test(libspdm_test_requester_get_version_err_case1),
+     858                 :            :         cmocka_unit_test(libspdm_test_requester_get_version_err_case2),
+     859                 :            :         cmocka_unit_test(libspdm_test_requester_get_version_err_case3),
+     860                 :            :         cmocka_unit_test(libspdm_test_requester_get_version_err_case4),
+     861                 :            :         cmocka_unit_test(libspdm_test_requester_get_version_err_case5),
+     862                 :            :         cmocka_unit_test(libspdm_test_requester_get_version_err_case6),
+     863                 :            :         cmocka_unit_test(libspdm_test_requester_get_version_err_case7),
+     864                 :            :         cmocka_unit_test(libspdm_test_requester_get_version_err_case8),
+     865                 :            :         cmocka_unit_test(libspdm_test_requester_get_version_err_case9),
+     866                 :            :         cmocka_unit_test(libspdm_test_requester_get_version_err_case10),
+     867                 :            :         cmocka_unit_test(libspdm_test_requester_get_version_err_case11),
+     868                 :            :         cmocka_unit_test(libspdm_test_requester_get_version_err_case12),
+     869                 :            :         cmocka_unit_test(libspdm_test_requester_get_version_err_case13),
+     870                 :            :         cmocka_unit_test(libspdm_test_requester_get_version_err_case14),
+     871                 :            :         /* cmocka_unit_test(libspdm_test_requester_get_version_err_case15),
+     872                 :            :          * cmocka_unit_test(libspdm_test_requester_get_version_err_case16), */
+     873                 :            :         cmocka_unit_test(libspdm_test_requester_get_version_err_case17),
+     874                 :            :         cmocka_unit_test(libspdm_test_requester_get_version_err_case18),
+     875                 :            :     };
+     876                 :            : 
+     877                 :          1 :     libspdm_setup_test_context(&m_libspdm_requester_get_version_test_context);
+     878                 :            : 
+     879                 :          1 :     return cmocka_run_group_tests(spdm_requester_get_version_tests,
+     880                 :            :                                   libspdm_unit_test_group_setup,
+     881                 :            :                                   libspdm_unit_test_group_teardown);
+     882                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/error_test/index-sort-b.html b/coverage_log/unit_test/test_spdm_requester/error_test/index-sort-b.html new file mode 100644 index 00000000000..c12c8d745cd --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/error_test/index-sort-b.html @@ -0,0 +1,227 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/error_test + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester/error_testHitTotalCoverage
Test:coverage.infoLines:7297922879.1 %
Date:2024-09-22 08:21:07Functions:22923597.4 %
Branches:41261866.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
subscribe_event_types_err.c +
55.9%55.9%
+
55.9 %52 / 9371.4 %5 / 70.0 %0 / 4
get_key_pair_info_err.c +
70.0%70.0%
+
70.0 %21 / 3075.0 %3 / 425.0 %1 / 4
set_key_pair_info_err.c +
72.7%72.7%
+
72.7 %24 / 3375.0 %3 / 425.0 %1 / 4
vendor_request_err.c +
73.9%73.9%
+
73.9 %68 / 9266.7 %4 / 630.0 %3 / 10
get_digests_err.c +
59.3%59.3%
+
59.3 %408 / 688100.0 %25 / 2543.5 %40 / 92
get_event_types_err.c +
97.3%97.3%
+
97.3 %73 / 75100.0 %5 / 550.0 %3 / 6
get_measurements_err.c +
68.7%68.7%
+
68.7 %1422 / 2069100.0 %41 / 4158.6 %75 / 128
key_exchange_err.c +
74.0%74.0%
+
74.0 %2113 / 2854100.0 %35 / 3562.5 %75 / 120
get_version_err.c +
80.5%80.5%
+
80.5 %326 / 405100.0 %19 / 1973.3 %44 / 60
negotiate_algorithms_err.c +
95.7%95.7%
+
95.7 %1767 / 1847100.0 %46 / 4685.1 %80 / 94
get_capabilities_err.c +
98.2%98.2%
+
98.2 %1023 / 1042100.0 %43 / 4393.8 %90 / 96
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/error_test/index-sort-f.html b/coverage_log/unit_test/test_spdm_requester/error_test/index-sort-f.html new file mode 100644 index 00000000000..eb4a251bf30 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/error_test/index-sort-f.html @@ -0,0 +1,227 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/error_test + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester/error_testHitTotalCoverage
Test:coverage.infoLines:7297922879.1 %
Date:2024-09-22 08:21:07Functions:22923597.4 %
Branches:41261866.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
vendor_request_err.c +
73.9%73.9%
+
73.9 %68 / 9266.7 %4 / 630.0 %3 / 10
subscribe_event_types_err.c +
55.9%55.9%
+
55.9 %52 / 9371.4 %5 / 70.0 %0 / 4
get_key_pair_info_err.c +
70.0%70.0%
+
70.0 %21 / 3075.0 %3 / 425.0 %1 / 4
set_key_pair_info_err.c +
72.7%72.7%
+
72.7 %24 / 3375.0 %3 / 425.0 %1 / 4
get_event_types_err.c +
97.3%97.3%
+
97.3 %73 / 75100.0 %5 / 550.0 %3 / 6
get_version_err.c +
80.5%80.5%
+
80.5 %326 / 405100.0 %19 / 1973.3 %44 / 60
get_digests_err.c +
59.3%59.3%
+
59.3 %408 / 688100.0 %25 / 2543.5 %40 / 92
key_exchange_err.c +
74.0%74.0%
+
74.0 %2113 / 2854100.0 %35 / 3562.5 %75 / 120
get_measurements_err.c +
68.7%68.7%
+
68.7 %1422 / 2069100.0 %41 / 4158.6 %75 / 128
get_capabilities_err.c +
98.2%98.2%
+
98.2 %1023 / 1042100.0 %43 / 4393.8 %90 / 96
negotiate_algorithms_err.c +
95.7%95.7%
+
95.7 %1767 / 1847100.0 %46 / 4685.1 %80 / 94
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/error_test/index-sort-l.html b/coverage_log/unit_test/test_spdm_requester/error_test/index-sort-l.html new file mode 100644 index 00000000000..b0d1f7e1fca --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/error_test/index-sort-l.html @@ -0,0 +1,227 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/error_test + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester/error_testHitTotalCoverage
Test:coverage.infoLines:7297922879.1 %
Date:2024-09-22 08:21:07Functions:22923597.4 %
Branches:41261866.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
subscribe_event_types_err.c +
55.9%55.9%
+
55.9 %52 / 9371.4 %5 / 70.0 %0 / 4
get_digests_err.c +
59.3%59.3%
+
59.3 %408 / 688100.0 %25 / 2543.5 %40 / 92
get_measurements_err.c +
68.7%68.7%
+
68.7 %1422 / 2069100.0 %41 / 4158.6 %75 / 128
get_key_pair_info_err.c +
70.0%70.0%
+
70.0 %21 / 3075.0 %3 / 425.0 %1 / 4
set_key_pair_info_err.c +
72.7%72.7%
+
72.7 %24 / 3375.0 %3 / 425.0 %1 / 4
vendor_request_err.c +
73.9%73.9%
+
73.9 %68 / 9266.7 %4 / 630.0 %3 / 10
key_exchange_err.c +
74.0%74.0%
+
74.0 %2113 / 2854100.0 %35 / 3562.5 %75 / 120
get_version_err.c +
80.5%80.5%
+
80.5 %326 / 405100.0 %19 / 1973.3 %44 / 60
negotiate_algorithms_err.c +
95.7%95.7%
+
95.7 %1767 / 1847100.0 %46 / 4685.1 %80 / 94
get_event_types_err.c +
97.3%97.3%
+
97.3 %73 / 75100.0 %5 / 550.0 %3 / 6
get_capabilities_err.c +
98.2%98.2%
+
98.2 %1023 / 1042100.0 %43 / 4393.8 %90 / 96
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/error_test/index.html b/coverage_log/unit_test/test_spdm_requester/error_test/index.html new file mode 100644 index 00000000000..8f5cb67a321 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/error_test/index.html @@ -0,0 +1,227 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/error_test + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester/error_testHitTotalCoverage
Test:coverage.infoLines:7297922879.1 %
Date:2024-09-22 08:21:07Functions:22923597.4 %
Branches:41261866.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
get_capabilities_err.c +
98.2%98.2%
+
98.2 %1023 / 1042100.0 %43 / 4393.8 %90 / 96
get_digests_err.c +
59.3%59.3%
+
59.3 %408 / 688100.0 %25 / 2543.5 %40 / 92
get_event_types_err.c +
97.3%97.3%
+
97.3 %73 / 75100.0 %5 / 550.0 %3 / 6
get_key_pair_info_err.c +
70.0%70.0%
+
70.0 %21 / 3075.0 %3 / 425.0 %1 / 4
get_measurements_err.c +
68.7%68.7%
+
68.7 %1422 / 2069100.0 %41 / 4158.6 %75 / 128
get_version_err.c +
80.5%80.5%
+
80.5 %326 / 405100.0 %19 / 1973.3 %44 / 60
key_exchange_err.c +
74.0%74.0%
+
74.0 %2113 / 2854100.0 %35 / 3562.5 %75 / 120
negotiate_algorithms_err.c +
95.7%95.7%
+
95.7 %1767 / 1847100.0 %46 / 4685.1 %80 / 94
set_key_pair_info_err.c +
72.7%72.7%
+
72.7 %24 / 3375.0 %3 / 425.0 %1 / 4
subscribe_event_types_err.c +
55.9%55.9%
+
55.9 %52 / 9371.4 %5 / 70.0 %0 / 4
vendor_request_err.c +
73.9%73.9%
+
73.9 %68 / 9266.7 %4 / 630.0 %3 / 10
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/error_test/key_exchange_err.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_requester/error_test/key_exchange_err.c.func-sort-c.html new file mode 100644 index 00000000000..7d8b042221f --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/error_test/key_exchange_err.c.func-sort-c.html @@ -0,0 +1,221 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/error_test/key_exchange_err.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester/error_test - key_exchange_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:2113285474.0 %
Date:2024-09-22 08:21:07Functions:3535100.0 %
Branches:7512062.5 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_key_exchange_error_test_main1
libspdm_test_requester_key_exchange_err_case11
libspdm_test_requester_key_exchange_err_case101
libspdm_test_requester_key_exchange_err_case111
libspdm_test_requester_key_exchange_err_case121
libspdm_test_requester_key_exchange_err_case131
libspdm_test_requester_key_exchange_err_case141
libspdm_test_requester_key_exchange_err_case151
libspdm_test_requester_key_exchange_err_case161
libspdm_test_requester_key_exchange_err_case171
libspdm_test_requester_key_exchange_err_case181
libspdm_test_requester_key_exchange_err_case191
libspdm_test_requester_key_exchange_err_case21
libspdm_test_requester_key_exchange_err_case201
libspdm_test_requester_key_exchange_err_case211
libspdm_test_requester_key_exchange_err_case221
libspdm_test_requester_key_exchange_err_case231
libspdm_test_requester_key_exchange_err_case241
libspdm_test_requester_key_exchange_err_case251
libspdm_test_requester_key_exchange_err_case261
libspdm_test_requester_key_exchange_err_case271
libspdm_test_requester_key_exchange_err_case281
libspdm_test_requester_key_exchange_err_case291
libspdm_test_requester_key_exchange_err_case31
libspdm_test_requester_key_exchange_err_case301
libspdm_test_requester_key_exchange_err_case311
libspdm_test_requester_key_exchange_err_case41
libspdm_test_requester_key_exchange_err_case51
libspdm_test_requester_key_exchange_err_case61
libspdm_test_requester_key_exchange_err_case71
libspdm_test_requester_key_exchange_err_case81
libspdm_test_requester_key_exchange_err_case91
libspdm_requester_key_exchange_test_receive_message39
libspdm_test_get_key_exchange_request_size40
libspdm_requester_key_exchange_test_send_message41
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/error_test/key_exchange_err.c.func.html b/coverage_log/unit_test/test_spdm_requester/error_test/key_exchange_err.c.func.html new file mode 100644 index 00000000000..7bcc7761838 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/error_test/key_exchange_err.c.func.html @@ -0,0 +1,221 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/error_test/key_exchange_err.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester/error_test - key_exchange_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:2113285474.0 %
Date:2024-09-22 08:21:07Functions:3535100.0 %
Branches:7512062.5 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_key_exchange_error_test_main1
libspdm_requester_key_exchange_test_receive_message39
libspdm_requester_key_exchange_test_send_message41
libspdm_test_get_key_exchange_request_size40
libspdm_test_requester_key_exchange_err_case11
libspdm_test_requester_key_exchange_err_case101
libspdm_test_requester_key_exchange_err_case111
libspdm_test_requester_key_exchange_err_case121
libspdm_test_requester_key_exchange_err_case131
libspdm_test_requester_key_exchange_err_case141
libspdm_test_requester_key_exchange_err_case151
libspdm_test_requester_key_exchange_err_case161
libspdm_test_requester_key_exchange_err_case171
libspdm_test_requester_key_exchange_err_case181
libspdm_test_requester_key_exchange_err_case191
libspdm_test_requester_key_exchange_err_case21
libspdm_test_requester_key_exchange_err_case201
libspdm_test_requester_key_exchange_err_case211
libspdm_test_requester_key_exchange_err_case221
libspdm_test_requester_key_exchange_err_case231
libspdm_test_requester_key_exchange_err_case241
libspdm_test_requester_key_exchange_err_case251
libspdm_test_requester_key_exchange_err_case261
libspdm_test_requester_key_exchange_err_case271
libspdm_test_requester_key_exchange_err_case281
libspdm_test_requester_key_exchange_err_case291
libspdm_test_requester_key_exchange_err_case31
libspdm_test_requester_key_exchange_err_case301
libspdm_test_requester_key_exchange_err_case311
libspdm_test_requester_key_exchange_err_case41
libspdm_test_requester_key_exchange_err_case51
libspdm_test_requester_key_exchange_err_case61
libspdm_test_requester_key_exchange_err_case71
libspdm_test_requester_key_exchange_err_case81
libspdm_test_requester_key_exchange_err_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/error_test/key_exchange_err.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/error_test/key_exchange_err.c.gcov.html new file mode 100644 index 00000000000..cc24e2a7bbb --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/error_test/key_exchange_err.c.gcov.html @@ -0,0 +1,6473 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/error_test/key_exchange_err.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester/error_test - key_exchange_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:2113285474.0 %
Date:2024-09-22 08:21:07Functions:3535100.0 %
Branches:7512062.5 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_requester_lib.h"
+       9                 :            : #include "internal/libspdm_responder_lib.h"
+      10                 :            : 
+      11                 :            : #if LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP
+      12                 :            : 
+      13                 :            : static size_t m_libspdm_local_buffer_size;
+      14                 :            : static uint8_t m_libspdm_local_buffer[LIBSPDM_MAX_MESSAGE_TH_BUFFER_SIZE];
+      15                 :            : static uint8_t m_libspdm_zero_filled_buffer[LIBSPDM_MAX_HASH_SIZE];
+      16                 :            : 
+      17                 :            : static libspdm_th_managed_buffer_t th_curr;
+      18                 :            : 
+      19                 :         40 : static size_t libspdm_test_get_key_exchange_request_size(const void *spdm_context,
+      20                 :            :                                                          const void *buffer,
+      21                 :            :                                                          size_t buffer_size)
+      22                 :            : {
+      23                 :            :     const spdm_key_exchange_request_t *spdm_request;
+      24                 :            :     size_t message_size;
+      25                 :            :     size_t dhe_key_size;
+      26                 :            :     uint16_t opaque_length;
+      27                 :            : 
+      28                 :         40 :     spdm_request = buffer;
+      29                 :         40 :     message_size = sizeof(spdm_message_header_t);
+      30         [ -  + ]:         40 :     if (buffer_size < message_size) {
+      31                 :          0 :         return buffer_size;
+      32                 :            :     }
+      33                 :            : 
+      34         [ +  + ]:         40 :     if (spdm_request->header.request_response_code != SPDM_KEY_EXCHANGE) {
+      35                 :          1 :         return buffer_size;
+      36                 :            :     }
+      37                 :            : 
+      38                 :         39 :     message_size = sizeof(spdm_key_exchange_request_t);
+      39         [ -  + ]:         39 :     if (buffer_size < message_size) {
+      40                 :          0 :         return buffer_size;
+      41                 :            :     }
+      42                 :            : 
+      43                 :         39 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+      44                 :         39 :     message_size += dhe_key_size + sizeof(uint16_t);
+      45         [ -  + ]:         39 :     if (buffer_size < message_size) {
+      46                 :          0 :         return buffer_size;
+      47                 :            :     }
+      48                 :            : 
+      49                 :         39 :     opaque_length =
+      50                 :         39 :         *(uint16_t *)((size_t)buffer +
+      51                 :         39 :                       sizeof(spdm_key_exchange_request_t) + dhe_key_size);
+      52                 :         39 :     message_size += opaque_length;
+      53         [ -  + ]:         39 :     if (buffer_size < message_size) {
+      54                 :          0 :         return buffer_size;
+      55                 :            :     }
+      56                 :            : 
+      57                 :            :     /* Good message, return actual size*/
+      58                 :         39 :     return message_size;
+      59                 :            : }
+      60                 :            : 
+      61                 :         41 : static libspdm_return_t libspdm_requester_key_exchange_test_send_message(
+      62                 :            :     void *spdm_context, size_t request_size, const void *request,
+      63                 :            :     uint64_t timeout)
+      64                 :            : {
+      65                 :            :     libspdm_test_context_t *spdm_test_context;
+      66                 :            :     size_t header_size;
+      67                 :            :     size_t message_size;
+      68                 :            : 
+      69                 :         41 :     spdm_test_context = libspdm_get_test_context();
+      70                 :         41 :     header_size = sizeof(libspdm_test_message_header_t);
+      71   [ +  +  -  +  :         41 :     switch (spdm_test_context->case_id) {
+          +  -  +  +  -  
+          +  +  +  +  +  
+          +  +  +  +  -  
+          +  +  +  +  -  
+          -  +  +  +  -  
+                -  +  - ]
+      72                 :          1 :     case 0x1:
+      73                 :          1 :         return LIBSPDM_STATUS_SEND_FAIL;
+      74                 :          1 :     case 0x2:
+      75                 :          1 :         m_libspdm_local_buffer_size = 0;
+      76                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+      77                 :            :             spdm_context, (const uint8_t *)request + header_size,
+      78                 :            :             request_size - header_size);
+      79                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+      80                 :            :                          (const uint8_t *)request + header_size, message_size);
+      81                 :          1 :         m_libspdm_local_buffer_size += message_size;
+      82                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      83                 :          0 :     case 0x3:
+      84                 :          0 :         m_libspdm_local_buffer_size = 0;
+      85                 :          0 :         message_size = libspdm_test_get_key_exchange_request_size(
+      86                 :            :             spdm_context, (const uint8_t *)request + header_size,
+      87                 :            :             request_size - header_size);
+      88                 :          0 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+      89                 :            :                          (const uint8_t *)request + header_size, message_size);
+      90                 :          0 :         m_libspdm_local_buffer_size += message_size;
+      91                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      92                 :          1 :     case 0x4:
+      93                 :          1 :         m_libspdm_local_buffer_size = 0;
+      94                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+      95                 :            :             spdm_context, (const uint8_t *)request + header_size,
+      96                 :            :             request_size - header_size);
+      97                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+      98                 :            :                          (const uint8_t *)request + header_size, message_size);
+      99                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     100                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     101                 :          1 :     case 0x5:
+     102                 :          1 :         m_libspdm_local_buffer_size = 0;
+     103                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     104                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     105                 :            :             request_size - header_size);
+     106                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     107                 :            :                          (const uint8_t *)request + header_size, message_size);
+     108                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     109                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     110                 :          0 :     case 0x6:
+     111                 :          0 :         m_libspdm_local_buffer_size = 0;
+     112                 :          0 :         message_size = libspdm_test_get_key_exchange_request_size(
+     113                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     114                 :            :             request_size - header_size);
+     115                 :          0 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     116                 :            :                          (const uint8_t *)request + header_size, message_size);
+     117                 :          0 :         m_libspdm_local_buffer_size += message_size;
+     118                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     119                 :          1 :     case 0x7:
+     120                 :          1 :         m_libspdm_local_buffer_size = 0;
+     121                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     122                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     123                 :            :             request_size - header_size);
+     124                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     125                 :            :                          (const uint8_t *)request + header_size, message_size);
+     126                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     127                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     128                 :          2 :     case 0x8:
+     129                 :          2 :         m_libspdm_local_buffer_size = 0;
+     130                 :          2 :         message_size = libspdm_test_get_key_exchange_request_size(
+     131                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     132                 :            :             request_size - header_size);
+     133                 :          2 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     134                 :            :                          (const uint8_t *)request + header_size, message_size);
+     135                 :          2 :         m_libspdm_local_buffer_size += message_size;
+     136                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     137                 :          0 :     case 0x9: {
+     138                 :            :         static size_t sub_index = 0;
+     139         [ #  # ]:          0 :         if (sub_index == 0) {
+     140                 :          0 :             m_libspdm_local_buffer_size = 0;
+     141                 :          0 :             message_size = libspdm_test_get_key_exchange_request_size(
+     142                 :            :                 spdm_context, (const uint8_t *)request + header_size,
+     143                 :            :                 request_size - header_size);
+     144                 :          0 :             libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     145                 :            :                              (const uint8_t *)request + header_size, message_size);
+     146                 :          0 :             m_libspdm_local_buffer_size += message_size;
+     147                 :          0 :             sub_index++;
+     148                 :            :         }
+     149                 :            :     }
+     150                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     151                 :         18 :     case 0xA:
+     152                 :         18 :         m_libspdm_local_buffer_size = 0;
+     153                 :         18 :         message_size = libspdm_test_get_key_exchange_request_size(
+     154                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     155                 :            :             request_size - header_size);
+     156                 :         18 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     157                 :            :                          (const uint8_t *)request + header_size, message_size);
+     158                 :         18 :         m_libspdm_local_buffer_size += message_size;
+     159                 :         18 :         return LIBSPDM_STATUS_SUCCESS;
+     160                 :          1 :     case 0xB:
+     161                 :          1 :         m_libspdm_local_buffer_size = 0;
+     162                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     163                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     164                 :            :             request_size - header_size);
+     165                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     166                 :            :                          (const uint8_t *)request + header_size, message_size);
+     167                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     168                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     169                 :          1 :     case 0xC:
+     170                 :          1 :         m_libspdm_local_buffer_size = 0;
+     171                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     172                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     173                 :            :             request_size - header_size);
+     174                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     175                 :            :                          (const uint8_t *)request + header_size, message_size);
+     176                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     177                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     178                 :          1 :     case 0xD:
+     179                 :          1 :         m_libspdm_local_buffer_size = 0;
+     180                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     181                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     182                 :            :             request_size - header_size);
+     183                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     184                 :            :                          (const uint8_t *)request + header_size, message_size);
+     185                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     186                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     187                 :          1 :     case 0xE:
+     188                 :          1 :         m_libspdm_local_buffer_size = 0;
+     189                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     190                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     191                 :            :             request_size - header_size);
+     192                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     193                 :            :                          (const uint8_t *)request + header_size, message_size);
+     194                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     195                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     196                 :          1 :     case 0xF:
+     197                 :          1 :         m_libspdm_local_buffer_size = 0;
+     198                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     199                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     200                 :            :             request_size - header_size);
+     201                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     202                 :            :                          (const uint8_t *)request + header_size, message_size);
+     203                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     204                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     205                 :          1 :     case 0x10:
+     206                 :          1 :         m_libspdm_local_buffer_size = 0;
+     207                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     208                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     209                 :            :             request_size - header_size);
+     210                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     211                 :            :                          (const uint8_t *)request + header_size, message_size);
+     212                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     213                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     214                 :          1 :     case 0x11:
+     215                 :          1 :         m_libspdm_local_buffer_size = 0;
+     216                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     217                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     218                 :            :             request_size - header_size);
+     219                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     220                 :            :                          (const uint8_t *)request + header_size, message_size);
+     221                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     222                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     223                 :          1 :     case 0x12:
+     224                 :          1 :         m_libspdm_local_buffer_size = 0;
+     225                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     226                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     227                 :            :             request_size - header_size);
+     228                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     229                 :            :                          (const uint8_t *)request + header_size, message_size);
+     230                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     231                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     232                 :          0 :     case 0x13:
+     233                 :          0 :         m_libspdm_local_buffer_size = 0;
+     234                 :          0 :         message_size = libspdm_test_get_key_exchange_request_size(
+     235                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     236                 :            :             request_size - header_size);
+     237                 :          0 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     238                 :            :                          (const uint8_t *)request + header_size, message_size);
+     239                 :          0 :         m_libspdm_local_buffer_size += message_size;
+     240                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     241                 :          1 :     case 0x14:
+     242                 :          1 :         m_libspdm_local_buffer_size = 0;
+     243                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     244                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     245                 :            :             request_size - header_size);
+     246                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     247                 :            :                          (const uint8_t *)request + header_size, message_size);
+     248                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     249                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     250                 :          1 :     case 0x15:
+     251                 :          1 :         m_libspdm_local_buffer_size = 0;
+     252                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     253                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     254                 :            :             request_size - header_size);
+     255                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     256                 :            :                          (const uint8_t *)request + header_size, message_size);
+     257                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     258                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     259                 :          1 :     case 0x16:
+     260                 :          1 :         m_libspdm_local_buffer_size = 0;
+     261                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     262                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     263                 :            :             request_size - header_size);
+     264                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     265                 :            :                          (const uint8_t *)request + header_size, message_size);
+     266                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     267                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     268                 :          1 :     case 0x17:
+     269                 :          1 :         m_libspdm_local_buffer_size = 0;
+     270                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     271                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     272                 :            :             request_size - header_size);
+     273                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     274                 :            :                          (const uint8_t *)request + header_size, message_size);
+     275                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     276                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     277                 :          0 :     case 0x18:
+     278                 :          0 :         m_libspdm_local_buffer_size = 0;
+     279                 :          0 :         message_size = libspdm_test_get_key_exchange_request_size(
+     280                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     281                 :            :             request_size - header_size);
+     282                 :          0 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     283                 :            :                          (const uint8_t *)request + header_size, message_size);
+     284                 :          0 :         m_libspdm_local_buffer_size += message_size;
+     285                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     286                 :          0 :     case 0x19:
+     287                 :          0 :         m_libspdm_local_buffer_size = 0;
+     288                 :          0 :         message_size = libspdm_test_get_key_exchange_request_size(
+     289                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     290                 :            :             request_size - header_size);
+     291                 :          0 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     292                 :            :                          (const uint8_t *)request + header_size, message_size);
+     293                 :          0 :         m_libspdm_local_buffer_size += message_size;
+     294                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     295                 :          1 :     case 0x1A:
+     296                 :          1 :         m_libspdm_local_buffer_size = 0;
+     297                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     298                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     299                 :            :             request_size - header_size);
+     300                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     301                 :            :                          (const uint8_t *)request + header_size, message_size);
+     302                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     303                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     304                 :          1 :     case 0x1B:
+     305                 :          1 :         m_libspdm_local_buffer_size = 0;
+     306                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     307                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     308                 :            :             request_size - header_size);
+     309                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     310                 :            :                          (const uint8_t *)request + header_size, message_size);
+     311                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     312                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     313                 :          1 :     case 0x1C:
+     314                 :          1 :         m_libspdm_local_buffer_size = 0;
+     315                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     316                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     317                 :            :             request_size - header_size);
+     318                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     319                 :            :                          (const uint8_t *)request + header_size, message_size);
+     320                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     321                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     322                 :          0 :     case 0x1D:
+     323                 :          0 :         m_libspdm_local_buffer_size = 0;
+     324                 :          0 :         message_size = libspdm_test_get_key_exchange_request_size(
+     325                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     326                 :            :             request_size - header_size);
+     327                 :          0 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     328                 :            :                          (const uint8_t *)request + header_size,  message_size);
+     329                 :          0 :         m_libspdm_local_buffer_size += message_size;
+     330                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     331                 :          0 :     case 0x1E:
+     332                 :          0 :         m_libspdm_local_buffer_size = 0;
+     333                 :          0 :         message_size = libspdm_test_get_key_exchange_request_size(
+     334                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     335                 :            :             request_size - header_size);
+     336                 :          0 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     337                 :            :                          (const uint8_t *)request + header_size, message_size);
+     338                 :          0 :         m_libspdm_local_buffer_size += message_size;
+     339                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     340                 :          1 :     case 0x1F:
+     341                 :          1 :         m_libspdm_local_buffer_size = 0;
+     342                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     343                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     344                 :            :             request_size - header_size);
+     345                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     346                 :            :                          (const uint8_t *)request + header_size, message_size);
+     347                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     348                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     349                 :          0 :     default:
+     350                 :          0 :         return LIBSPDM_STATUS_SEND_FAIL;
+     351                 :            :     }
+     352                 :            : }
+     353                 :            : 
+     354                 :         39 : static libspdm_return_t libspdm_requester_key_exchange_test_receive_message(
+     355                 :            :     void *spdm_context, size_t *response_size,
+     356                 :            :     void **response, uint64_t timeout)
+     357                 :            : {
+     358                 :            :     libspdm_test_context_t *spdm_test_context;
+     359                 :            : 
+     360                 :         39 :     spdm_test_context = libspdm_get_test_context();
+     361   [ -  +  -  +  :         39 :     switch (spdm_test_context->case_id) {
+          +  -  +  +  -  
+          +  -  +  +  +  
+          +  +  +  +  -  
+          +  +  +  +  -  
+          -  +  +  +  -  
+                -  +  - ]
+     362                 :          0 :     case 0x1:
+     363                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+     364                 :            : 
+     365                 :          1 :     case 0x2: {
+     366                 :            :         spdm_key_exchange_response_t *spdm_response;
+     367                 :            :         size_t dhe_key_size;
+     368                 :            :         uint32_t hash_size;
+     369                 :            :         size_t signature_size;
+     370                 :            :         uint32_t hmac_size;
+     371                 :            :         uint8_t *ptr;
+     372                 :            :         void *dhe_context;
+     373                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+     374                 :            :         size_t final_key_size;
+     375                 :            :         size_t opaque_key_exchange_rsp_size;
+     376                 :            :         void *data;
+     377                 :            :         size_t data_size;
+     378                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     379                 :            :         uint8_t *cert_buffer;
+     380                 :            :         size_t cert_buffer_size;
+     381                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+     382                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+     383                 :            :         uint8_t bin_str0[128];
+     384                 :            :         size_t bin_str0_size;
+     385                 :            :         uint8_t bin_str2[128];
+     386                 :            :         size_t bin_str2_size;
+     387                 :            :         uint8_t bin_str7[128];
+     388                 :            :         size_t bin_str7_size;
+     389                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+     390                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+     391                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+     392                 :            :         size_t spdm_response_size;
+     393                 :            :         size_t transport_header_size;
+     394                 :            : 
+     395                 :          1 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
+     396                 :            :             SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     397                 :            :         ((libspdm_context_t *)spdm_context)
+     398                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+     399                 :            :             m_libspdm_use_asym_algo;
+     400                 :            :         ((libspdm_context_t *)spdm_context)
+     401                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+     402                 :            :             m_libspdm_use_hash_algo;
+     403                 :            :         ((libspdm_context_t *)spdm_context)
+     404                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+     405                 :            :             m_libspdm_use_dhe_algo;
+     406                 :            :         ((libspdm_context_t *)spdm_context)
+     407                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+     408                 :            :             m_libspdm_use_measurement_hash_algo;
+     409                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+     410                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     411                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     412                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+     413                 :          1 :         opaque_key_exchange_rsp_size =
+     414                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+     415                 :            :                 spdm_context);
+     416                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+     417                 :          1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
+     418                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+     419                 :            :                              hmac_size;
+     420                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     421                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     422                 :            : 
+     423                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     424                 :          1 :         spdm_response->header.request_response_code =
+     425                 :            :             SPDM_KEY_EXCHANGE_RSP;
+     426                 :          1 :         spdm_response->header.param1 = 0;
+     427                 :          1 :         spdm_response->rsp_session_id =
+     428                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
+     429                 :          1 :         spdm_response->mut_auth_requested = 0;
+     430                 :          1 :         spdm_response->req_slot_id_param = 0;
+     431                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+     432                 :          1 :                                   spdm_response->random_data);
+     433                 :          1 :         ptr = (void *)(spdm_response + 1);
+     434                 :          1 :         dhe_context = libspdm_dhe_new(
+     435                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     436                 :            :                 m_libspdm_use_dhe_algo,
+     437                 :            :                 true);
+     438                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+     439                 :            :                                  &dhe_key_size);
+     440                 :          1 :         final_key_size = sizeof(final_key);
+     441                 :          1 :         libspdm_dhe_compute_key(
+     442                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+     443                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+     444                 :            :             sizeof(spdm_key_exchange_request_t),
+     445                 :            :             dhe_key_size, final_key, &final_key_size);
+     446                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+     447                 :          1 :         ptr += dhe_key_size;
+     448                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+     449                 :            :          * ptr += hash_size;*/
+     450                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+     451                 :          1 :         ptr += sizeof(uint16_t);
+     452                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+     453                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+     454                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+     455                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     456                 :            :                                                         m_libspdm_use_asym_algo, &data,
+     457                 :            :                                                         &data_size, NULL, NULL);
+     458                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+     459                 :            :                          sizeof(m_libspdm_local_buffer)
+     460                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+     461                 :            :                             m_libspdm_local_buffer),
+     462                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+     463                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+     464                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+     465                 :            :                        m_libspdm_local_buffer_size));
+     466                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+     467                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+     468                 :          1 :         cert_buffer = (uint8_t *)data;
+     469                 :          1 :         cert_buffer_size = data_size;
+     470                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+     471                 :            :                          cert_buffer_hash);
+     472                 :            :         /* transcript.message_a size is 0*/
+     473                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+     474                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+     475                 :            :                                       m_libspdm_local_buffer_size);
+     476                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+     477                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+     478                 :          1 :         free(data);
+     479                 :          1 :         libspdm_responder_data_sign(
+     480                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+     481                 :            :             spdm_context,
+     482                 :            : #endif
+     483                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     484                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+     485                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+     486                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+     487                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+     488                 :            :                 &signature_size);
+     489                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+     490                 :            :                          sizeof(m_libspdm_local_buffer)
+     491                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+     492                 :            :                             m_libspdm_local_buffer),
+     493                 :            :                          ptr, signature_size);
+     494                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+     495                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+     496                 :          1 :         ptr += signature_size;
+     497                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+     498                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+     499                 :            :                          th_curr_hash_data);
+     500                 :          1 :         bin_str0_size = sizeof(bin_str0);
+     501                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+     502                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+     503                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+     504                 :            :                            &bin_str0_size);
+     505                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+     506                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+     507                 :          1 :         bin_str2_size = sizeof(bin_str2);
+     508                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+     509                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+     510                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+     511                 :            :                            bin_str2, &bin_str2_size);
+     512                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+     513                 :            :                             bin_str2, bin_str2_size,
+     514                 :            :                             response_handshake_secret, hash_size);
+     515                 :          1 :         bin_str7_size = sizeof(bin_str7);
+     516                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+     517                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+     518                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+     519                 :            :                            &bin_str7_size);
+     520                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+     521                 :            :                             hash_size, bin_str7, bin_str7_size,
+     522                 :            :                             response_finished_key, hash_size);
+     523                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+     524                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+     525                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+     526                 :            :                          response_finished_key, hash_size, ptr);
+     527                 :          1 :         ptr += hmac_size;
+     528                 :            : 
+     529                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     530                 :            :                                               false, spdm_response_size,
+     531                 :            :                                               spdm_response, response_size,
+     532                 :            :                                               response);
+     533                 :            :     }
+     534                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     535                 :            : 
+     536                 :          0 :     case 0x3: {
+     537                 :            :         spdm_key_exchange_response_t *spdm_response;
+     538                 :            :         size_t dhe_key_size;
+     539                 :            :         uint32_t hash_size;
+     540                 :            :         size_t signature_size;
+     541                 :            :         uint32_t hmac_size;
+     542                 :            :         uint8_t *ptr;
+     543                 :            :         void *dhe_context;
+     544                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+     545                 :            :         size_t final_key_size;
+     546                 :            :         size_t opaque_key_exchange_rsp_size;
+     547                 :            :         void *data;
+     548                 :            :         size_t data_size;
+     549                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     550                 :            :         uint8_t *cert_buffer;
+     551                 :            :         size_t cert_buffer_size;
+     552                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+     553                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+     554                 :            :         uint8_t bin_str0[128];
+     555                 :            :         size_t bin_str0_size;
+     556                 :            :         uint8_t bin_str2[128];
+     557                 :            :         size_t bin_str2_size;
+     558                 :            :         uint8_t bin_str7[128];
+     559                 :            :         size_t bin_str7_size;
+     560                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+     561                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+     562                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+     563                 :            :         size_t spdm_response_size;
+     564                 :            :         size_t transport_header_size;
+     565                 :            : 
+     566                 :            :         ((libspdm_context_t *)spdm_context)
+     567                 :          0 :         ->connection_info.algorithm.base_asym_algo =
+     568                 :            :             m_libspdm_use_asym_algo;
+     569                 :            :         ((libspdm_context_t *)spdm_context)
+     570                 :          0 :         ->connection_info.algorithm.base_hash_algo =
+     571                 :            :             m_libspdm_use_hash_algo;
+     572                 :            :         ((libspdm_context_t *)spdm_context)
+     573                 :          0 :         ->connection_info.algorithm.dhe_named_group =
+     574                 :            :             m_libspdm_use_dhe_algo;
+     575                 :            :         ((libspdm_context_t *)spdm_context)
+     576                 :          0 :         ->connection_info.algorithm.measurement_hash_algo =
+     577                 :            :             m_libspdm_use_measurement_hash_algo;
+     578                 :          0 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+     579                 :          0 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     580                 :          0 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     581                 :          0 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+     582                 :          0 :         opaque_key_exchange_rsp_size =
+     583                 :          0 :             libspdm_get_opaque_data_version_selection_data_size(
+     584                 :            :                 spdm_context);
+     585                 :          0 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+     586                 :          0 :                              dhe_key_size + 0 + sizeof(uint16_t) +
+     587                 :          0 :                              opaque_key_exchange_rsp_size + signature_size +
+     588                 :            :                              hmac_size;
+     589                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     590                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     591                 :            : 
+     592                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     593                 :          0 :         spdm_response->header.request_response_code =
+     594                 :            :             SPDM_KEY_EXCHANGE_RSP;
+     595                 :          0 :         spdm_response->header.param1 = 0;
+     596                 :          0 :         spdm_response->rsp_session_id =
+     597                 :          0 :             libspdm_allocate_rsp_session_id(spdm_context, false);
+     598                 :          0 :         spdm_response->mut_auth_requested = 0;
+     599                 :          0 :         spdm_response->req_slot_id_param = 0;
+     600                 :          0 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+     601                 :          0 :                                   spdm_response->random_data);
+     602                 :          0 :         ptr = (void *)(spdm_response + 1);
+     603                 :          0 :         dhe_context = libspdm_dhe_new(
+     604                 :          0 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     605                 :            :                 m_libspdm_use_dhe_algo,
+     606                 :            :                 true);
+     607                 :          0 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+     608                 :            :                                  &dhe_key_size);
+     609                 :          0 :         final_key_size = sizeof(final_key);
+     610                 :          0 :         libspdm_dhe_compute_key(
+     611                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+     612                 :          0 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+     613                 :            :             sizeof(spdm_key_exchange_request_t),
+     614                 :            :             dhe_key_size, final_key, &final_key_size);
+     615                 :          0 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+     616                 :          0 :         ptr += dhe_key_size;
+     617                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+     618                 :            :          * ptr += hash_size;*/
+     619                 :          0 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+     620                 :          0 :         ptr += sizeof(uint16_t);
+     621                 :          0 :         libspdm_build_opaque_data_version_selection_data(
+     622                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+     623                 :          0 :         ptr += opaque_key_exchange_rsp_size;
+     624                 :          0 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     625                 :            :                                                         m_libspdm_use_asym_algo, &data,
+     626                 :            :                                                         &data_size, NULL, NULL);
+     627                 :          0 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+     628                 :            :                          sizeof(m_libspdm_local_buffer)
+     629                 :          0 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+     630                 :            :                             m_libspdm_local_buffer),
+     631                 :          0 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+     632                 :          0 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+     633                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+     634                 :            :                        m_libspdm_local_buffer_size));
+     635                 :          0 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+     636                 :          0 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+     637                 :          0 :         cert_buffer = (uint8_t *)data;
+     638                 :          0 :         cert_buffer_size = data_size;
+     639                 :          0 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+     640                 :            :                          cert_buffer_hash);
+     641                 :            :         /* transcript.message_a size is 0*/
+     642                 :          0 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+     643                 :          0 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+     644                 :            :                                       m_libspdm_local_buffer_size);
+     645                 :          0 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+     646                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+     647                 :          0 :         free(data);
+     648                 :          0 :         libspdm_responder_data_sign(
+     649                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+     650                 :            :             spdm_context,
+     651                 :            : #endif
+     652                 :          0 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     653                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+     654                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+     655                 :          0 :                 false, libspdm_get_managed_buffer(&th_curr),
+     656                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+     657                 :            :                 &signature_size);
+     658                 :          0 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+     659                 :            :                          sizeof(m_libspdm_local_buffer)
+     660                 :          0 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+     661                 :            :                             m_libspdm_local_buffer),
+     662                 :            :                          ptr, signature_size);
+     663                 :          0 :         m_libspdm_local_buffer_size += signature_size;
+     664                 :          0 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+     665                 :          0 :         ptr += signature_size;
+     666                 :          0 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+     667                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+     668                 :            :                          th_curr_hash_data);
+     669                 :          0 :         bin_str0_size = sizeof(bin_str0);
+     670                 :          0 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+     671                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+     672                 :          0 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+     673                 :            :                            &bin_str0_size);
+     674                 :          0 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+     675                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+     676                 :          0 :         bin_str2_size = sizeof(bin_str2);
+     677                 :          0 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+     678                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+     679                 :          0 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+     680                 :            :                            bin_str2, &bin_str2_size);
+     681                 :          0 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+     682                 :            :                             bin_str2, bin_str2_size,
+     683                 :            :                             response_handshake_secret, hash_size);
+     684                 :          0 :         bin_str7_size = sizeof(bin_str7);
+     685                 :          0 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+     686                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+     687                 :          0 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+     688                 :            :                            &bin_str7_size);
+     689                 :          0 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+     690                 :            :                             hash_size, bin_str7, bin_str7_size,
+     691                 :            :                             response_finished_key, hash_size);
+     692                 :          0 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+     693                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+     694                 :          0 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+     695                 :            :                          response_finished_key, hash_size, ptr);
+     696                 :          0 :         ptr += hmac_size;
+     697                 :            : 
+     698                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     699                 :            :                                               false, spdm_response_size,
+     700                 :            :                                               spdm_response, response_size,
+     701                 :            :                                               response);
+     702                 :            :     }
+     703                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     704                 :            : 
+     705                 :          1 :     case 0x4: {
+     706                 :            :         spdm_error_response_t *spdm_response;
+     707                 :            :         size_t spdm_response_size;
+     708                 :            :         size_t transport_header_size;
+     709                 :            : 
+     710                 :          1 :         spdm_response_size = sizeof(spdm_error_response_t);
+     711                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     712                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     713                 :            : 
+     714                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     715                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     716                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_INVALID_REQUEST;
+     717                 :          1 :         spdm_response->header.param2 = 0;
+     718                 :            : 
+     719                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     720                 :            :                                               false, spdm_response_size,
+     721                 :            :                                               spdm_response,
+     722                 :            :                                               response_size, response);
+     723                 :            :     }
+     724                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     725                 :            : 
+     726                 :          1 :     case 0x5: {
+     727                 :            :         spdm_error_response_t *spdm_response;
+     728                 :            :         size_t spdm_response_size;
+     729                 :            :         size_t transport_header_size;
+     730                 :            : 
+     731                 :          1 :         spdm_response_size = sizeof(spdm_error_response_t);
+     732                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     733                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     734                 :            : 
+     735                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     736                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     737                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
+     738                 :          1 :         spdm_response->header.param2 = 0;
+     739                 :            : 
+     740                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     741                 :            :                                               false, spdm_response_size,
+     742                 :            :                                               spdm_response,
+     743                 :            :                                               response_size, response);
+     744                 :            :     }
+     745                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     746                 :            : 
+     747                 :          0 :     case 0x6: {
+     748                 :            :         static size_t sub_index1 = 0;
+     749         [ #  # ]:          0 :         if (sub_index1 == 0) {
+     750                 :            :             spdm_error_response_t *spdm_response;
+     751                 :            :             size_t spdm_response_size;
+     752                 :            :             size_t transport_header_size;
+     753                 :            : 
+     754                 :          0 :             spdm_response_size = sizeof(spdm_error_response_t);
+     755                 :          0 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     756                 :          0 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     757                 :            : 
+     758                 :          0 :             spdm_response->header.spdm_version =
+     759                 :            :                 SPDM_MESSAGE_VERSION_11;
+     760                 :          0 :             spdm_response->header.request_response_code = SPDM_ERROR;
+     761                 :          0 :             spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
+     762                 :          0 :             spdm_response->header.param2 = 0;
+     763                 :            : 
+     764                 :          0 :             libspdm_transport_test_encode_message(
+     765                 :            :                 spdm_context, NULL, false, false,
+     766                 :            :                 spdm_response_size, spdm_response,
+     767                 :            :                 response_size, response);
+     768                 :          0 :             sub_index1++;
+     769         [ #  # ]:          0 :         } else if (sub_index1 == 1) {
+     770                 :            :             spdm_key_exchange_response_t *spdm_response;
+     771                 :            :             size_t dhe_key_size;
+     772                 :            :             uint32_t hash_size;
+     773                 :            :             size_t signature_size;
+     774                 :            :             uint32_t hmac_size;
+     775                 :            :             uint8_t *ptr;
+     776                 :            :             void *dhe_context;
+     777                 :            :             uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+     778                 :            :             size_t final_key_size;
+     779                 :            :             size_t opaque_key_exchange_rsp_size;
+     780                 :            :             void *data;
+     781                 :            :             size_t data_size;
+     782                 :            :             uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     783                 :            :             uint8_t *cert_buffer;
+     784                 :            :             size_t cert_buffer_size;
+     785                 :            :             uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+     786                 :            :             uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+     787                 :            :             uint8_t bin_str0[128];
+     788                 :            :             size_t bin_str0_size;
+     789                 :            :             uint8_t bin_str2[128];
+     790                 :            :             size_t bin_str2_size;
+     791                 :            :             uint8_t bin_str7[128];
+     792                 :            :             size_t bin_str7_size;
+     793                 :            :             uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+     794                 :            :             uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+     795                 :            :             uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+     796                 :            :             size_t spdm_response_size;
+     797                 :            :             size_t transport_header_size;
+     798                 :            : 
+     799                 :            :             ((libspdm_context_t *)spdm_context)
+     800                 :          0 :             ->connection_info.algorithm.base_asym_algo =
+     801                 :            :                 m_libspdm_use_asym_algo;
+     802                 :            :             ((libspdm_context_t *)spdm_context)
+     803                 :          0 :             ->connection_info.algorithm.base_hash_algo =
+     804                 :            :                 m_libspdm_use_hash_algo;
+     805                 :            :             ((libspdm_context_t *)spdm_context)
+     806                 :          0 :             ->connection_info.algorithm.dhe_named_group =
+     807                 :            :                 m_libspdm_use_dhe_algo;
+     808                 :            :             ((libspdm_context_t *)spdm_context)
+     809                 :            :             ->connection_info.algorithm
+     810                 :          0 :             .measurement_hash_algo =
+     811                 :            :                 m_libspdm_use_measurement_hash_algo;
+     812                 :          0 :             signature_size =
+     813                 :          0 :                 libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+     814                 :          0 :             hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     815                 :          0 :             hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     816                 :          0 :             dhe_key_size =
+     817                 :          0 :                 libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+     818                 :          0 :             opaque_key_exchange_rsp_size =
+     819                 :          0 :                 libspdm_get_opaque_data_version_selection_data_size(
+     820                 :            :                     spdm_context);
+     821                 :          0 :             spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+     822                 :          0 :                                  dhe_key_size + 0 + sizeof(uint16_t) +
+     823                 :          0 :                                  opaque_key_exchange_rsp_size +
+     824                 :          0 :                                  signature_size + hmac_size;
+     825                 :          0 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     826                 :          0 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     827                 :            : 
+     828                 :          0 :             spdm_response->header.spdm_version =
+     829                 :            :                 SPDM_MESSAGE_VERSION_11;
+     830                 :          0 :             spdm_response->header.request_response_code =
+     831                 :            :                 SPDM_KEY_EXCHANGE_RSP;
+     832                 :          0 :             spdm_response->header.param1 = 0;
+     833                 :          0 :             spdm_response->rsp_session_id =
+     834                 :          0 :                 libspdm_allocate_rsp_session_id(spdm_context, false);
+     835                 :          0 :             spdm_response->mut_auth_requested = 0;
+     836                 :          0 :             spdm_response->req_slot_id_param = 0;
+     837                 :          0 :             libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+     838                 :          0 :                                       spdm_response->random_data);
+     839                 :          0 :             ptr = (void *)(spdm_response + 1);
+     840                 :          0 :             dhe_context = libspdm_dhe_new(
+     841                 :          0 :                 spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     842                 :            :                     m_libspdm_use_dhe_algo, true);
+     843                 :          0 :             libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+     844                 :            :                                      &dhe_key_size);
+     845                 :          0 :             final_key_size = sizeof(final_key);
+     846                 :          0 :             libspdm_dhe_compute_key(
+     847                 :            :                 m_libspdm_use_dhe_algo, dhe_context,
+     848                 :          0 :                 (uint8_t *)&m_libspdm_local_buffer[0] +
+     849                 :            :                 sizeof(spdm_key_exchange_request_t),
+     850                 :            :                 dhe_key_size, final_key, &final_key_size);
+     851                 :          0 :             libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+     852                 :          0 :             ptr += dhe_key_size;
+     853                 :            :             /* libspdm_zero_mem (ptr, hash_size);
+     854                 :            :              * ptr += hash_size;*/
+     855                 :          0 :             *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+     856                 :          0 :             ptr += sizeof(uint16_t);
+     857                 :          0 :             libspdm_build_opaque_data_version_selection_data(
+     858                 :            :                 spdm_context, &opaque_key_exchange_rsp_size,
+     859                 :            :                 ptr);
+     860                 :          0 :             ptr += opaque_key_exchange_rsp_size;
+     861                 :          0 :             libspdm_read_responder_public_certificate_chain(
+     862                 :            :                 m_libspdm_use_hash_algo, m_libspdm_use_asym_algo, &data,
+     863                 :            :                 &data_size, NULL, NULL);
+     864                 :          0 :             libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+     865                 :            :                              sizeof(m_libspdm_local_buffer)
+     866                 :          0 :                              - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+     867                 :            :                                 m_libspdm_local_buffer),
+     868                 :          0 :                              spdm_response, (size_t)ptr - (size_t)spdm_response);
+     869                 :          0 :             m_libspdm_local_buffer_size +=
+     870                 :          0 :                 ((size_t)ptr - (size_t)spdm_response);
+     871                 :          0 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+     872                 :            :                            m_libspdm_local_buffer_size));
+     873                 :          0 :             libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+     874                 :          0 :             libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+     875                 :          0 :             cert_buffer = (uint8_t *)data;
+     876                 :          0 :             cert_buffer_size = data_size;
+     877                 :          0 :             libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer,
+     878                 :            :                              cert_buffer_size, cert_buffer_hash);
+     879                 :            :             /* transcript.message_a size is 0*/
+     880                 :          0 :             libspdm_append_managed_buffer(&th_curr, cert_buffer_hash,
+     881                 :            :                                           hash_size);
+     882                 :          0 :             libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+     883                 :            :                                           m_libspdm_local_buffer_size);
+     884                 :          0 :             libspdm_hash_all(m_libspdm_use_hash_algo,
+     885                 :          0 :                              libspdm_get_managed_buffer(&th_curr),
+     886                 :            :                              libspdm_get_managed_buffer_size(&th_curr),
+     887                 :            :                              hash_data);
+     888                 :          0 :             free(data);
+     889                 :          0 :             libspdm_responder_data_sign(
+     890                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+     891                 :            :                 spdm_context,
+     892                 :            : #endif
+     893                 :          0 :                 spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     894                 :            :                     SPDM_KEY_EXCHANGE_RSP,
+     895                 :            :                     m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+     896                 :          0 :                     false, libspdm_get_managed_buffer(&th_curr),
+     897                 :            :                     libspdm_get_managed_buffer_size(&th_curr), ptr,
+     898                 :            :                     &signature_size);
+     899                 :          0 :             libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+     900                 :            :                              sizeof(m_libspdm_local_buffer)
+     901                 :          0 :                              - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+     902                 :            :                                 m_libspdm_local_buffer),
+     903                 :            :                              ptr, signature_size);
+     904                 :          0 :             m_libspdm_local_buffer_size += signature_size;
+     905                 :          0 :             libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+     906                 :          0 :             ptr += signature_size;
+     907                 :          0 :             libspdm_hash_all(m_libspdm_use_hash_algo,
+     908                 :          0 :                              libspdm_get_managed_buffer(&th_curr),
+     909                 :            :                              libspdm_get_managed_buffer_size(&th_curr),
+     910                 :            :                              th_curr_hash_data);
+     911                 :          0 :             bin_str0_size = sizeof(bin_str0);
+     912                 :          0 :             libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+     913                 :            :                                SPDM_BIN_STR_0_LABEL,
+     914                 :            :                                sizeof(SPDM_BIN_STR_0_LABEL) - 1, NULL,
+     915                 :          0 :                                (uint16_t)hash_size, hash_size, bin_str0,
+     916                 :            :                                &bin_str0_size);
+     917                 :          0 :             libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+     918                 :            :                              m_libspdm_zero_filled_buffer, hash_size, handshake_secret);
+     919                 :          0 :             bin_str2_size = sizeof(bin_str2);
+     920                 :          0 :             libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+     921                 :            :                                SPDM_BIN_STR_2_LABEL,
+     922                 :            :                                sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+     923                 :          0 :                                th_curr_hash_data, (uint16_t)hash_size,
+     924                 :            :                                hash_size, bin_str2, &bin_str2_size);
+     925                 :          0 :             libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret,
+     926                 :            :                                 hash_size, bin_str2, bin_str2_size,
+     927                 :            :                                 response_handshake_secret, hash_size);
+     928                 :          0 :             bin_str7_size = sizeof(bin_str7);
+     929                 :          0 :             libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+     930                 :            :                                SPDM_BIN_STR_7_LABEL,
+     931                 :            :                                sizeof(SPDM_BIN_STR_7_LABEL) - 1, NULL,
+     932                 :          0 :                                (uint16_t)hash_size, hash_size, bin_str7,
+     933                 :            :                                &bin_str7_size);
+     934                 :          0 :             libspdm_hkdf_expand(m_libspdm_use_hash_algo,
+     935                 :            :                                 response_handshake_secret, hash_size,
+     936                 :            :                                 bin_str7, bin_str7_size,
+     937                 :            :                                 response_finished_key, hash_size);
+     938                 :          0 :             libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+     939                 :            :                              libspdm_get_managed_buffer_size(&th_curr), hash_data);
+     940                 :          0 :             libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+     941                 :            :                              response_finished_key, hash_size, ptr);
+     942                 :          0 :             ptr += hmac_size;
+     943                 :            : 
+     944                 :          0 :             libspdm_transport_test_encode_message(
+     945                 :            :                 spdm_context, NULL, false, false, spdm_response_size,
+     946                 :            :                 spdm_response, response_size, response);
+     947                 :            :         }
+     948                 :            :     }
+     949                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     950                 :            : 
+     951                 :          1 :     case 0x7: {
+     952                 :            :         spdm_error_response_t *spdm_response;
+     953                 :            :         size_t spdm_response_size;
+     954                 :            :         size_t transport_header_size;
+     955                 :            : 
+     956                 :          1 :         spdm_response_size = sizeof(spdm_error_response_t);
+     957                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     958                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     959                 :            : 
+     960                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     961                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     962                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_REQUEST_RESYNCH;
+     963                 :          1 :         spdm_response->header.param2 = 0;
+     964                 :            : 
+     965                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     966                 :            :                                               false, spdm_response_size,
+     967                 :            :                                               spdm_response,
+     968                 :            :                                               response_size, response);
+     969                 :            :     }
+     970                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     971                 :            : 
+     972                 :          2 :     case 0x8: {
+     973                 :            :         spdm_error_response_data_response_not_ready_t *spdm_response;
+     974                 :            :         size_t spdm_response_size;
+     975                 :            :         size_t transport_header_size;
+     976                 :            : 
+     977                 :          2 :         spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
+     978                 :          2 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     979                 :          2 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     980                 :            : 
+     981                 :          2 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     982                 :          2 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     983                 :          2 :         spdm_response->header.param1 =
+     984                 :            :             SPDM_ERROR_CODE_RESPONSE_NOT_READY;
+     985                 :          2 :         spdm_response->header.param2 = 0;
+     986                 :          2 :         spdm_response->extend_error_data.rd_exponent = 1;
+     987                 :          2 :         spdm_response->extend_error_data.rd_tm = 2;
+     988                 :          2 :         spdm_response->extend_error_data.request_code =
+     989                 :            :             SPDM_KEY_EXCHANGE;
+     990                 :          2 :         spdm_response->extend_error_data.token = 0;
+     991                 :            : 
+     992                 :          2 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     993                 :            :                                               false, spdm_response_size,
+     994                 :            :                                               spdm_response,
+     995                 :            :                                               response_size, response);
+     996                 :            :     }
+     997                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     998                 :            : 
+     999                 :          0 :     case 0x9: {
+    1000                 :            :         static size_t sub_index2 = 0;
+    1001         [ #  # ]:          0 :         if (sub_index2 == 0) {
+    1002                 :            :             spdm_error_response_data_response_not_ready_t
+    1003                 :            :             *spdm_response;
+    1004                 :            :             size_t spdm_response_size;
+    1005                 :            :             size_t transport_header_size;
+    1006                 :            : 
+    1007                 :          0 :             spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
+    1008                 :          0 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1009                 :          0 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1010                 :            : 
+    1011                 :          0 :             spdm_response->header.spdm_version =
+    1012                 :            :                 SPDM_MESSAGE_VERSION_11;
+    1013                 :          0 :             spdm_response->header.request_response_code = SPDM_ERROR;
+    1014                 :          0 :             spdm_response->header.param1 =
+    1015                 :            :                 SPDM_ERROR_CODE_RESPONSE_NOT_READY;
+    1016                 :          0 :             spdm_response->header.param2 = 0;
+    1017                 :          0 :             spdm_response->extend_error_data.rd_exponent = 1;
+    1018                 :          0 :             spdm_response->extend_error_data.rd_tm = 2;
+    1019                 :          0 :             spdm_response->extend_error_data.request_code =
+    1020                 :            :                 SPDM_KEY_EXCHANGE;
+    1021                 :          0 :             spdm_response->extend_error_data.token = 1;
+    1022                 :            : 
+    1023                 :          0 :             libspdm_transport_test_encode_message(
+    1024                 :            :                 spdm_context, NULL, false, false,
+    1025                 :            :                 spdm_response_size, spdm_response,
+    1026                 :            :                 response_size, response);
+    1027                 :          0 :             sub_index2++;
+    1028         [ #  # ]:          0 :         } else if (sub_index2 == 1) {
+    1029                 :            :             spdm_key_exchange_response_t *spdm_response;
+    1030                 :            :             size_t dhe_key_size;
+    1031                 :            :             uint32_t hash_size;
+    1032                 :            :             size_t signature_size;
+    1033                 :            :             uint32_t hmac_size;
+    1034                 :            :             uint8_t *ptr;
+    1035                 :            :             void *dhe_context;
+    1036                 :            :             uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    1037                 :            :             size_t final_key_size;
+    1038                 :            :             size_t opaque_key_exchange_rsp_size;
+    1039                 :            :             void *data;
+    1040                 :            :             size_t data_size;
+    1041                 :            :             uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1042                 :            :             uint8_t *cert_buffer;
+    1043                 :            :             size_t cert_buffer_size;
+    1044                 :            :             uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    1045                 :            :             uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1046                 :            :             uint8_t bin_str0[128];
+    1047                 :            :             size_t bin_str0_size;
+    1048                 :            :             uint8_t bin_str2[128];
+    1049                 :            :             size_t bin_str2_size;
+    1050                 :            :             uint8_t bin_str7[128];
+    1051                 :            :             size_t bin_str7_size;
+    1052                 :            :             uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    1053                 :            :             uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    1054                 :            :             uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    1055                 :            :             size_t spdm_response_size;
+    1056                 :            :             size_t transport_header_size;
+    1057                 :            : 
+    1058                 :            :             ((libspdm_context_t *)spdm_context)
+    1059                 :          0 :             ->connection_info.algorithm.base_asym_algo =
+    1060                 :            :                 m_libspdm_use_asym_algo;
+    1061                 :            :             ((libspdm_context_t *)spdm_context)
+    1062                 :          0 :             ->connection_info.algorithm.base_hash_algo =
+    1063                 :            :                 m_libspdm_use_hash_algo;
+    1064                 :            :             ((libspdm_context_t *)spdm_context)
+    1065                 :          0 :             ->connection_info.algorithm.dhe_named_group =
+    1066                 :            :                 m_libspdm_use_dhe_algo;
+    1067                 :            :             ((libspdm_context_t *)spdm_context)
+    1068                 :            :             ->connection_info.algorithm
+    1069                 :          0 :             .measurement_hash_algo =
+    1070                 :            :                 m_libspdm_use_measurement_hash_algo;
+    1071                 :          0 :             signature_size =
+    1072                 :          0 :                 libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    1073                 :          0 :             hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1074                 :          0 :             hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1075                 :          0 :             dhe_key_size =
+    1076                 :          0 :                 libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    1077                 :          0 :             opaque_key_exchange_rsp_size =
+    1078                 :          0 :                 libspdm_get_opaque_data_version_selection_data_size(
+    1079                 :            :                     spdm_context);
+    1080                 :          0 :             spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    1081                 :          0 :                                  dhe_key_size + 0 + sizeof(uint16_t) +
+    1082                 :          0 :                                  opaque_key_exchange_rsp_size +
+    1083                 :          0 :                                  signature_size + hmac_size;
+    1084                 :          0 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1085                 :          0 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1086                 :            : 
+    1087                 :          0 :             spdm_response->header.spdm_version =
+    1088                 :            :                 SPDM_MESSAGE_VERSION_11;
+    1089                 :          0 :             spdm_response->header.request_response_code =
+    1090                 :            :                 SPDM_KEY_EXCHANGE_RSP;
+    1091                 :          0 :             spdm_response->header.param1 = 0;
+    1092                 :          0 :             spdm_response->rsp_session_id =
+    1093                 :          0 :                 libspdm_allocate_rsp_session_id(spdm_context, false);
+    1094                 :          0 :             spdm_response->mut_auth_requested = 0;
+    1095                 :          0 :             spdm_response->req_slot_id_param = 0;
+    1096                 :          0 :             libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    1097                 :          0 :                                       spdm_response->random_data);
+    1098                 :          0 :             ptr = (void *)(spdm_response + 1);
+    1099                 :          0 :             dhe_context = libspdm_dhe_new(
+    1100                 :          0 :                 spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    1101                 :            :                     m_libspdm_use_dhe_algo, true);
+    1102                 :          0 :             libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+    1103                 :            :                                      &dhe_key_size);
+    1104                 :          0 :             final_key_size = sizeof(final_key);
+    1105                 :          0 :             libspdm_dhe_compute_key(
+    1106                 :            :                 m_libspdm_use_dhe_algo, dhe_context,
+    1107                 :          0 :                 (uint8_t *)&m_libspdm_local_buffer[0] +
+    1108                 :            :                 sizeof(spdm_key_exchange_request_t),
+    1109                 :            :                 dhe_key_size, final_key, &final_key_size);
+    1110                 :          0 :             libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    1111                 :          0 :             ptr += dhe_key_size;
+    1112                 :            :             /* libspdm_zero_mem (ptr, hash_size);
+    1113                 :            :              * ptr += hash_size;*/
+    1114                 :          0 :             *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    1115                 :          0 :             ptr += sizeof(uint16_t);
+    1116                 :          0 :             libspdm_build_opaque_data_version_selection_data(
+    1117                 :            :                 spdm_context, &opaque_key_exchange_rsp_size,
+    1118                 :            :                 ptr);
+    1119                 :          0 :             ptr += opaque_key_exchange_rsp_size;
+    1120                 :          0 :             libspdm_read_responder_public_certificate_chain(
+    1121                 :            :                 m_libspdm_use_hash_algo, m_libspdm_use_asym_algo, &data,
+    1122                 :            :                 &data_size, NULL, NULL);
+    1123                 :          0 :             libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    1124                 :            :                              sizeof(m_libspdm_local_buffer)
+    1125                 :          0 :                              - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    1126                 :            :                                 m_libspdm_local_buffer),
+    1127                 :          0 :                              spdm_response, (size_t)ptr - (size_t)spdm_response);
+    1128                 :          0 :             m_libspdm_local_buffer_size +=
+    1129                 :          0 :                 ((size_t)ptr - (size_t)spdm_response);
+    1130                 :          0 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    1131                 :            :                            m_libspdm_local_buffer_size));
+    1132                 :          0 :             libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    1133                 :          0 :             libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    1134                 :          0 :             cert_buffer = (uint8_t *)data;
+    1135                 :          0 :             cert_buffer_size = data_size;
+    1136                 :          0 :             libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer,
+    1137                 :            :                              cert_buffer_size, cert_buffer_hash);
+    1138                 :            :             /* transcript.message_a size is 0*/
+    1139                 :          0 :             libspdm_append_managed_buffer(&th_curr, cert_buffer_hash,
+    1140                 :            :                                           hash_size);
+    1141                 :          0 :             libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    1142                 :            :                                           m_libspdm_local_buffer_size);
+    1143                 :          0 :             libspdm_hash_all(m_libspdm_use_hash_algo,
+    1144                 :          0 :                              libspdm_get_managed_buffer(&th_curr),
+    1145                 :            :                              libspdm_get_managed_buffer_size(&th_curr),
+    1146                 :            :                              hash_data);
+    1147                 :          0 :             free(data);
+    1148                 :          0 :             libspdm_responder_data_sign(
+    1149                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    1150                 :            :                 spdm_context,
+    1151                 :            : #endif
+    1152                 :          0 :                 spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    1153                 :            :                     SPDM_KEY_EXCHANGE_RSP,
+    1154                 :            :                     m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    1155                 :          0 :                     false, libspdm_get_managed_buffer(&th_curr),
+    1156                 :            :                     libspdm_get_managed_buffer_size(&th_curr), ptr,
+    1157                 :            :                     &signature_size);
+    1158                 :          0 :             libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    1159                 :            :                              sizeof(m_libspdm_local_buffer)
+    1160                 :          0 :                              - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    1161                 :            :                                 m_libspdm_local_buffer),
+    1162                 :            :                              ptr, signature_size);
+    1163                 :          0 :             m_libspdm_local_buffer_size += signature_size;
+    1164                 :          0 :             libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    1165                 :          0 :             ptr += signature_size;
+    1166                 :          0 :             libspdm_hash_all(m_libspdm_use_hash_algo,
+    1167                 :          0 :                              libspdm_get_managed_buffer(&th_curr),
+    1168                 :            :                              libspdm_get_managed_buffer_size(&th_curr),
+    1169                 :            :                              th_curr_hash_data);
+    1170                 :          0 :             bin_str0_size = sizeof(bin_str0);
+    1171                 :          0 :             libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1172                 :            :                                SPDM_BIN_STR_0_LABEL,
+    1173                 :            :                                sizeof(SPDM_BIN_STR_0_LABEL) - 1, NULL,
+    1174                 :          0 :                                (uint16_t)hash_size, hash_size, bin_str0,
+    1175                 :            :                                &bin_str0_size);
+    1176                 :          0 :             libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    1177                 :            :                              m_libspdm_zero_filled_buffer, hash_size, handshake_secret);
+    1178                 :          0 :             bin_str2_size = sizeof(bin_str2);
+    1179                 :          0 :             libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1180                 :            :                                SPDM_BIN_STR_2_LABEL,
+    1181                 :            :                                sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    1182                 :          0 :                                th_curr_hash_data, (uint16_t)hash_size,
+    1183                 :            :                                hash_size, bin_str2, &bin_str2_size);
+    1184                 :          0 :             libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret,
+    1185                 :            :                                 hash_size, bin_str2, bin_str2_size,
+    1186                 :            :                                 response_handshake_secret, hash_size);
+    1187                 :          0 :             bin_str7_size = sizeof(bin_str7);
+    1188                 :          0 :             libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1189                 :            :                                SPDM_BIN_STR_7_LABEL,
+    1190                 :            :                                sizeof(SPDM_BIN_STR_7_LABEL) - 1, NULL,
+    1191                 :          0 :                                (uint16_t)hash_size, hash_size, bin_str7,
+    1192                 :            :                                &bin_str7_size);
+    1193                 :          0 :             libspdm_hkdf_expand(m_libspdm_use_hash_algo,
+    1194                 :            :                                 response_handshake_secret, hash_size,
+    1195                 :            :                                 bin_str7, bin_str7_size,
+    1196                 :            :                                 response_finished_key, hash_size);
+    1197                 :          0 :             libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1198                 :            :                              libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1199                 :          0 :             libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    1200                 :            :                              response_finished_key, hash_size, ptr);
+    1201                 :          0 :             ptr += hmac_size;
+    1202                 :            : 
+    1203                 :          0 :             libspdm_transport_test_encode_message(
+    1204                 :            :                 spdm_context, NULL, false, false, spdm_response_size,
+    1205                 :            :                 spdm_response, response_size, response);
+    1206                 :            :         }
+    1207                 :            :     }
+    1208                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+    1209                 :            : 
+    1210                 :         18 :     case 0xA:
+    1211                 :            :     {
+    1212                 :            :         static uint16_t error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
+    1213                 :            : 
+    1214                 :            :         spdm_error_response_t *spdm_response;
+    1215                 :            :         size_t spdm_response_size;
+    1216                 :            :         size_t transport_header_size;
+    1217                 :            : 
+    1218                 :         18 :         spdm_response_size = sizeof(spdm_error_response_t);
+    1219                 :         18 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1220                 :         18 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1221                 :            : 
+    1222         [ +  - ]:         18 :         if(error_code <= 0xff) {
+    1223                 :         18 :             libspdm_zero_mem (spdm_response, spdm_response_size);
+    1224                 :         18 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1225                 :         18 :             spdm_response->header.request_response_code = SPDM_ERROR;
+    1226                 :         18 :             spdm_response->header.param1 = (uint8_t) error_code;
+    1227                 :         18 :             spdm_response->header.param2 = 0;
+    1228                 :            : 
+    1229                 :         18 :             libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+    1230                 :            :                                                    spdm_response_size, spdm_response,
+    1231                 :            :                                                    response_size, response);
+    1232                 :            :         }
+    1233                 :            : 
+    1234                 :         18 :         error_code++;
+    1235         [ +  + ]:         18 :         if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
+    1236                 :          1 :             error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
+    1237                 :            :         }
+    1238         [ +  + ]:         18 :         if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) { /*skip some reserved error codes (0d to 3e)*/
+    1239                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
+    1240                 :            :         }
+    1241         [ +  + ]:         18 :         if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) { /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
+    1242                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
+    1243                 :            :         }
+    1244                 :            :     }
+    1245                 :         18 :         return LIBSPDM_STATUS_SUCCESS;
+    1246                 :          0 :     case 0xB: {
+    1247                 :            :         spdm_key_exchange_response_t *spdm_response;
+    1248                 :            :         size_t dhe_key_size;
+    1249                 :            :         uint32_t hash_size;
+    1250                 :            :         size_t signature_size;
+    1251                 :            :         uint32_t hmac_size;
+    1252                 :            :         uint8_t *ptr;
+    1253                 :            :         void *dhe_context;
+    1254                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    1255                 :            :         size_t final_key_size;
+    1256                 :            :         size_t opaque_key_exchange_rsp_size;
+    1257                 :            :         void *data;
+    1258                 :            :         size_t data_size;
+    1259                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1260                 :            :         uint8_t *cert_buffer;
+    1261                 :            :         size_t cert_buffer_size;
+    1262                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    1263                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1264                 :            :         uint8_t bin_str0[128];
+    1265                 :            :         size_t bin_str0_size;
+    1266                 :            :         uint8_t bin_str2[128];
+    1267                 :            :         size_t bin_str2_size;
+    1268                 :            :         uint8_t bin_str7[128];
+    1269                 :            :         size_t bin_str7_size;
+    1270                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    1271                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    1272                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    1273                 :            :         size_t spdm_response_size;
+    1274                 :            :         size_t transport_header_size;
+    1275                 :            : 
+    1276                 :            :         ((libspdm_context_t *)spdm_context)
+    1277                 :          0 :         ->connection_info.algorithm.base_asym_algo =
+    1278                 :            :             m_libspdm_use_asym_algo;
+    1279                 :            :         ((libspdm_context_t *)spdm_context)
+    1280                 :          0 :         ->connection_info.algorithm.base_hash_algo =
+    1281                 :            :             m_libspdm_use_hash_algo;
+    1282                 :            :         ((libspdm_context_t *)spdm_context)
+    1283                 :          0 :         ->connection_info.algorithm.dhe_named_group =
+    1284                 :            :             m_libspdm_use_dhe_algo;
+    1285                 :            :         ((libspdm_context_t *)spdm_context)
+    1286                 :          0 :         ->connection_info.algorithm.measurement_hash_algo =
+    1287                 :            :             m_libspdm_use_measurement_hash_algo;
+    1288                 :          0 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    1289                 :          0 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1290                 :          0 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1291                 :          0 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    1292                 :          0 :         opaque_key_exchange_rsp_size =
+    1293                 :          0 :             libspdm_get_opaque_data_version_selection_data_size(
+    1294                 :            :                 spdm_context);
+    1295                 :          0 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    1296                 :          0 :                              dhe_key_size + 0 + sizeof(uint16_t) +
+    1297                 :          0 :                              opaque_key_exchange_rsp_size + signature_size +
+    1298                 :            :                              hmac_size;
+    1299                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1300                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1301                 :            : 
+    1302                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1303                 :          0 :         spdm_response->header.request_response_code =
+    1304                 :            :             SPDM_KEY_EXCHANGE_RSP;
+    1305                 :          0 :         spdm_response->header.param1 = 0;
+    1306                 :          0 :         spdm_response->rsp_session_id =
+    1307                 :          0 :             libspdm_allocate_rsp_session_id(spdm_context, false);
+    1308                 :          0 :         spdm_response->mut_auth_requested = 0;
+    1309                 :          0 :         spdm_response->req_slot_id_param = 0;
+    1310                 :          0 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    1311                 :          0 :                                   spdm_response->random_data);
+    1312                 :          0 :         ptr = (void *)(spdm_response + 1);
+    1313                 :          0 :         dhe_context = libspdm_dhe_new(
+    1314                 :          0 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    1315                 :            :                 m_libspdm_use_dhe_algo,
+    1316                 :            :                 true);
+    1317                 :          0 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+    1318                 :            :                                  &dhe_key_size);
+    1319                 :          0 :         final_key_size = sizeof(final_key);
+    1320                 :          0 :         libspdm_dhe_compute_key(
+    1321                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    1322                 :          0 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    1323                 :            :             sizeof(spdm_key_exchange_request_t),
+    1324                 :            :             dhe_key_size, final_key, &final_key_size);
+    1325                 :          0 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    1326                 :          0 :         ptr += dhe_key_size;
+    1327                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    1328                 :            :          * ptr += hash_size;*/
+    1329                 :          0 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    1330                 :          0 :         ptr += sizeof(uint16_t);
+    1331                 :          0 :         libspdm_build_opaque_data_version_selection_data(
+    1332                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    1333                 :          0 :         ptr += opaque_key_exchange_rsp_size;
+    1334                 :          0 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1335                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    1336                 :            :                                                         &data_size, NULL, NULL);
+    1337                 :          0 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    1338                 :            :                          sizeof(m_libspdm_local_buffer)
+    1339                 :          0 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    1340                 :            :                             m_libspdm_local_buffer),
+    1341                 :          0 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    1342                 :          0 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    1343                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    1344                 :            :                        m_libspdm_local_buffer_size));
+    1345                 :          0 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    1346                 :          0 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    1347                 :          0 :         cert_buffer = (uint8_t *)data;
+    1348                 :          0 :         cert_buffer_size = data_size;
+    1349                 :          0 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    1350                 :            :                          cert_buffer_hash);
+    1351                 :            :         /* transcript.message_a size is 0*/
+    1352                 :          0 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    1353                 :          0 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    1354                 :            :                                       m_libspdm_local_buffer_size);
+    1355                 :          0 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1356                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1357                 :          0 :         free(data);
+    1358                 :          0 :         libspdm_responder_data_sign(
+    1359                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    1360                 :            :             spdm_context,
+    1361                 :            : #endif
+    1362                 :          0 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    1363                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    1364                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    1365                 :          0 :                 false, libspdm_get_managed_buffer(&th_curr),
+    1366                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    1367                 :            :                 &signature_size);
+    1368                 :          0 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    1369                 :            :                          sizeof(m_libspdm_local_buffer)
+    1370                 :          0 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    1371                 :            :                             m_libspdm_local_buffer),
+    1372                 :            :                          ptr, signature_size);
+    1373                 :          0 :         m_libspdm_local_buffer_size += signature_size;
+    1374                 :          0 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    1375                 :          0 :         ptr += signature_size;
+    1376                 :          0 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1377                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    1378                 :            :                          th_curr_hash_data);
+    1379                 :          0 :         bin_str0_size = sizeof(bin_str0);
+    1380                 :          0 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1381                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    1382                 :          0 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    1383                 :            :                            &bin_str0_size);
+    1384                 :          0 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    1385                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    1386                 :          0 :         bin_str2_size = sizeof(bin_str2);
+    1387                 :          0 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1388                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    1389                 :          0 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    1390                 :            :                            bin_str2, &bin_str2_size);
+    1391                 :          0 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    1392                 :            :                             bin_str2, bin_str2_size,
+    1393                 :            :                             response_handshake_secret, hash_size);
+    1394                 :          0 :         bin_str7_size = sizeof(bin_str7);
+    1395                 :          0 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1396                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    1397                 :          0 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    1398                 :            :                            &bin_str7_size);
+    1399                 :          0 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    1400                 :            :                             hash_size, bin_str7, bin_str7_size,
+    1401                 :            :                             response_finished_key, hash_size);
+    1402                 :          0 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1403                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1404                 :          0 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    1405                 :            :                          response_finished_key, hash_size, ptr);
+    1406                 :          0 :         ptr += hmac_size;
+    1407                 :            : 
+    1408                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1409                 :            :                                               false, spdm_response_size,
+    1410                 :            :                                               spdm_response, response_size,
+    1411                 :            :                                               response);
+    1412                 :            :     }
+    1413                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+    1414                 :          1 :     case 0xC: {
+    1415                 :            :         spdm_key_exchange_response_t *spdm_response;
+    1416                 :            :         size_t dhe_key_size;
+    1417                 :            :         uint32_t hash_size;
+    1418                 :            :         uint32_t measurement_hash_size;
+    1419                 :            :         size_t signature_size;
+    1420                 :            :         uint32_t hmac_size;
+    1421                 :            :         uint8_t *ptr;
+    1422                 :            :         void *dhe_context;
+    1423                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    1424                 :            :         size_t final_key_size;
+    1425                 :            :         size_t opaque_key_exchange_rsp_size;
+    1426                 :            :         void *data;
+    1427                 :            :         size_t data_size;
+    1428                 :            :         uint8_t measurement_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1429                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1430                 :            :         uint8_t *cert_buffer;
+    1431                 :            :         size_t cert_buffer_size;
+    1432                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    1433                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1434                 :            :         uint8_t bin_str0[128];
+    1435                 :            :         size_t bin_str0_size;
+    1436                 :            :         uint8_t bin_str2[128];
+    1437                 :            :         size_t bin_str2_size;
+    1438                 :            :         uint8_t bin_str7[128];
+    1439                 :            :         size_t bin_str7_size;
+    1440                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    1441                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    1442                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    1443                 :            :         size_t spdm_response_size;
+    1444                 :            :         size_t transport_header_size;
+    1445                 :            : 
+    1446                 :            :         ((libspdm_context_t *)spdm_context)
+    1447                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    1448                 :            :             m_libspdm_use_asym_algo;
+    1449                 :            :         ((libspdm_context_t *)spdm_context)
+    1450                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    1451                 :            :             m_libspdm_use_hash_algo;
+    1452                 :            :         ((libspdm_context_t *)spdm_context)
+    1453                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    1454                 :            :             m_libspdm_use_dhe_algo;
+    1455                 :            :         ((libspdm_context_t *)spdm_context)
+    1456                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    1457                 :            :             m_libspdm_use_measurement_hash_algo;
+    1458                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    1459                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1460                 :          1 :         measurement_hash_size = libspdm_get_hash_size(
+    1461                 :            :             m_libspdm_use_hash_algo);
+    1462                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1463                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    1464                 :          1 :         opaque_key_exchange_rsp_size =
+    1465                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    1466                 :            :                 spdm_context);
+    1467                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    1468                 :          1 :                              dhe_key_size + measurement_hash_size + sizeof(uint16_t) +
+    1469                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+    1470                 :            :                              hmac_size;
+    1471                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1472                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1473                 :          1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    1474                 :            : 
+    1475                 :            :         /* Incorrect version. Should be 1.1. */
+    1476                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+    1477                 :          1 :         spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
+    1478                 :          1 :         spdm_response->header.param1 = 0;
+    1479                 :          1 :         spdm_response->rsp_session_id =
+    1480                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
+    1481                 :          1 :         spdm_response->mut_auth_requested = 0;
+    1482                 :          1 :         spdm_response->req_slot_id_param = 0;
+    1483                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    1484                 :          1 :                                   spdm_response->random_data);
+    1485                 :          1 :         ptr = (void *)(spdm_response + 1);
+    1486                 :          1 :         dhe_context = libspdm_dhe_new(
+    1487                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    1488                 :            :                 m_libspdm_use_dhe_algo,
+    1489                 :            :                 true);
+    1490                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+    1491                 :            :                                  &dhe_key_size);
+    1492                 :          1 :         final_key_size = sizeof(final_key);
+    1493                 :          1 :         libspdm_dhe_compute_key(
+    1494                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    1495                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    1496                 :            :             sizeof(spdm_key_exchange_request_t),
+    1497                 :            :             dhe_key_size, final_key, &final_key_size);
+    1498                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    1499                 :          1 :         ptr += dhe_key_size;
+    1500                 :            :         /*Mock measurement hash as TCB*/
+    1501                 :          1 :         libspdm_copy_mem(measurement_hash_data, sizeof(measurement_hash_data),
+    1502                 :            :                          m_libspdm_use_tcb_hash_value, measurement_hash_size);
+    1503                 :          1 :         libspdm_copy_mem(ptr, spdm_response_size - (ptr - (uint8_t *)spdm_response),
+    1504                 :            :                          measurement_hash_data, measurement_hash_size);
+    1505                 :            :         /*libspdm_zero_mem (ptr, measurement_hash_size);*/
+    1506                 :          1 :         ptr += measurement_hash_size;
+    1507                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    1508                 :          1 :         ptr += sizeof(uint16_t);
+    1509                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    1510                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    1511                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+    1512                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1513                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    1514                 :            :                                                         &data_size, NULL, NULL);
+    1515                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    1516                 :            :                          sizeof(m_libspdm_local_buffer)
+    1517                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    1518                 :            :                             m_libspdm_local_buffer),
+    1519                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    1520                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    1521                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    1522                 :            :                        m_libspdm_local_buffer_size));
+    1523                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    1524                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    1525                 :          1 :         cert_buffer =  (uint8_t *)data;
+    1526                 :          1 :         cert_buffer_size = data_size;
+    1527                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    1528                 :            :                          cert_buffer_hash);
+    1529                 :            :         /* transcript.message_a size is 0*/
+    1530                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    1531                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    1532                 :            :                                       m_libspdm_local_buffer_size);
+    1533                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1534                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1535                 :          1 :         free(data);
+    1536                 :          1 :         libspdm_responder_data_sign(
+    1537                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    1538                 :            :             spdm_context,
+    1539                 :            : #endif
+    1540                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    1541                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    1542                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    1543                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+    1544                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    1545                 :            :                 &signature_size);
+    1546                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    1547                 :            :                          sizeof(m_libspdm_local_buffer)
+    1548                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    1549                 :            :                             m_libspdm_local_buffer),
+    1550                 :            :                          ptr, signature_size);
+    1551                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+    1552                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    1553                 :          1 :         ptr += signature_size;
+    1554                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1555                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    1556                 :            :                          th_curr_hash_data);
+    1557                 :          1 :         bin_str0_size = sizeof(bin_str0);
+    1558                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1559                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    1560                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    1561                 :            :                            &bin_str0_size);
+    1562                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    1563                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    1564                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    1565                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1566                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    1567                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    1568                 :            :                            bin_str2, &bin_str2_size);
+    1569                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    1570                 :            :                             bin_str2, bin_str2_size,
+    1571                 :            :                             response_handshake_secret, hash_size);
+    1572                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    1573                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1574                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    1575                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    1576                 :            :                            &bin_str7_size);
+    1577                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    1578                 :            :                             hash_size, bin_str7, bin_str7_size,
+    1579                 :            :                             response_finished_key, hash_size);
+    1580                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1581                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1582                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    1583                 :            :                          response_finished_key, hash_size, ptr);
+    1584                 :          1 :         ptr += hmac_size;
+    1585                 :            : 
+    1586                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1587                 :            :                                               false, spdm_response_size,
+    1588                 :            :                                               spdm_response, response_size,
+    1589                 :            :                                               response);
+    1590                 :            :     }
+    1591                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1592                 :            : 
+    1593                 :          1 :     case 0xD: {
+    1594                 :            :         spdm_key_exchange_response_t *spdm_response;
+    1595                 :            :         size_t dhe_key_size;
+    1596                 :            :         uint32_t hash_size;
+    1597                 :            :         uint32_t measurement_hash_size;
+    1598                 :            :         size_t signature_size;
+    1599                 :            :         uint32_t hmac_size;
+    1600                 :            :         uint8_t *ptr;
+    1601                 :            :         void *dhe_context;
+    1602                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    1603                 :            :         size_t final_key_size;
+    1604                 :            :         size_t opaque_key_exchange_rsp_size;
+    1605                 :            :         void *data;
+    1606                 :            :         size_t data_size;
+    1607                 :            :         uint8_t measurement_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1608                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1609                 :            :         uint8_t *cert_buffer;
+    1610                 :            :         size_t cert_buffer_size;
+    1611                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    1612                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1613                 :            :         uint8_t bin_str0[128];
+    1614                 :            :         size_t bin_str0_size;
+    1615                 :            :         uint8_t bin_str2[128];
+    1616                 :            :         size_t bin_str2_size;
+    1617                 :            :         uint8_t bin_str7[128];
+    1618                 :            :         size_t bin_str7_size;
+    1619                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    1620                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    1621                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    1622                 :            :         size_t spdm_response_size;
+    1623                 :            :         size_t transport_header_size;
+    1624                 :            : 
+    1625                 :            :         ((libspdm_context_t *)spdm_context)
+    1626                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    1627                 :            :             m_libspdm_use_asym_algo;
+    1628                 :            :         ((libspdm_context_t *)spdm_context)
+    1629                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    1630                 :            :             m_libspdm_use_hash_algo;
+    1631                 :            :         ((libspdm_context_t *)spdm_context)
+    1632                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    1633                 :            :             m_libspdm_use_dhe_algo;
+    1634                 :            :         ((libspdm_context_t *)spdm_context)
+    1635                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    1636                 :            :             m_libspdm_use_measurement_hash_algo;
+    1637                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    1638                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1639                 :          1 :         measurement_hash_size = libspdm_get_hash_size(
+    1640                 :            :             m_libspdm_use_hash_algo);
+    1641                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1642                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    1643                 :          1 :         opaque_key_exchange_rsp_size =
+    1644                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    1645                 :            :                 spdm_context);
+    1646                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    1647                 :          1 :                              dhe_key_size + measurement_hash_size + sizeof(uint16_t) +
+    1648                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+    1649                 :            :                              hmac_size;
+    1650                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1651                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1652                 :          1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    1653                 :            : 
+    1654                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1655                 :            :         /* Incorrect response code. */
+    1656                 :          1 :         spdm_response->header.request_response_code = SPDM_DIGESTS;
+    1657                 :          1 :         spdm_response->header.param1 = 0;
+    1658                 :          1 :         spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
+    1659                 :          1 :         spdm_response->mut_auth_requested = 0;
+    1660                 :          1 :         spdm_response->req_slot_id_param = 0;
+    1661                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_response->random_data);
+    1662                 :          1 :         ptr = (void *)(spdm_response + 1);
+    1663                 :          1 :         dhe_context = libspdm_dhe_new(
+    1664                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    1665                 :            :                 m_libspdm_use_dhe_algo, true);
+    1666                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
+    1667                 :          1 :         final_key_size = sizeof(final_key);
+    1668                 :          1 :         libspdm_dhe_compute_key(
+    1669                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    1670                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    1671                 :            :             sizeof(spdm_key_exchange_request_t),
+    1672                 :            :             dhe_key_size, final_key, &final_key_size);
+    1673                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    1674                 :          1 :         ptr += dhe_key_size;
+    1675                 :            :         /*Mock measurement hash as 0x00 array*/
+    1676                 :          1 :         libspdm_zero_mem(measurement_hash_data, measurement_hash_size);
+    1677                 :          1 :         libspdm_copy_mem(ptr, spdm_response_size - (ptr - (uint8_t *)spdm_response),
+    1678                 :            :                          measurement_hash_data, measurement_hash_size);
+    1679                 :            :         /*libspdm_zero_mem (ptr, measurement_hash_size);*/
+    1680                 :          1 :         ptr += measurement_hash_size;
+    1681                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    1682                 :          1 :         ptr += sizeof(uint16_t);
+    1683                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    1684                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    1685                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+    1686                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1687                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    1688                 :            :                                                         &data_size, NULL, NULL);
+    1689                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    1690                 :            :                          sizeof(m_libspdm_local_buffer)
+    1691                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    1692                 :            :                             m_libspdm_local_buffer),
+    1693                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    1694                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    1695                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    1696                 :            :                        m_libspdm_local_buffer_size));
+    1697                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    1698                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    1699                 :          1 :         cert_buffer = (uint8_t *)data;
+    1700                 :          1 :         cert_buffer_size =  data_size;
+    1701                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    1702                 :            :                          cert_buffer_hash);
+    1703                 :            :         /* transcript.message_a size is 0*/
+    1704                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    1705                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    1706                 :            :                                       m_libspdm_local_buffer_size);
+    1707                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1708                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1709                 :          1 :         free(data);
+    1710                 :          1 :         libspdm_responder_data_sign(
+    1711                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    1712                 :            :             spdm_context,
+    1713                 :            : #endif
+    1714                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    1715                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    1716                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    1717                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+    1718                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    1719                 :            :                 &signature_size);
+    1720                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    1721                 :            :                          sizeof(m_libspdm_local_buffer)
+    1722                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    1723                 :            :                             m_libspdm_local_buffer),
+    1724                 :            :                          ptr, signature_size);
+    1725                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+    1726                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    1727                 :          1 :         ptr += signature_size;
+    1728                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1729                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    1730                 :            :                          th_curr_hash_data);
+    1731                 :          1 :         bin_str0_size = sizeof(bin_str0);
+    1732                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1733                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    1734                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    1735                 :            :                            &bin_str0_size);
+    1736                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    1737                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    1738                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    1739                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1740                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    1741                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    1742                 :            :                            bin_str2, &bin_str2_size);
+    1743                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    1744                 :            :                             bin_str2, bin_str2_size,
+    1745                 :            :                             response_handshake_secret, hash_size);
+    1746                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    1747                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1748                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    1749                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    1750                 :            :                            &bin_str7_size);
+    1751                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    1752                 :            :                             hash_size, bin_str7, bin_str7_size,
+    1753                 :            :                             response_finished_key, hash_size);
+    1754                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1755                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1756                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    1757                 :            :                          response_finished_key, hash_size, ptr);
+    1758                 :          1 :         ptr += hmac_size;
+    1759                 :            : 
+    1760                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1761                 :            :                                               false, spdm_response_size,
+    1762                 :            :                                               spdm_response, response_size,
+    1763                 :            :                                               response);
+    1764                 :            :     }
+    1765                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1766                 :            : 
+    1767                 :          1 :     case 0xE: {
+    1768                 :            :         spdm_key_exchange_response_t *spdm_response;
+    1769                 :            :         size_t dhe_key_size;
+    1770                 :            :         uint32_t hash_size;
+    1771                 :            :         uint32_t measurement_hash_size;
+    1772                 :            :         size_t signature_size;
+    1773                 :            :         uint32_t hmac_size;
+    1774                 :            :         uint8_t *ptr;
+    1775                 :            :         void *dhe_context;
+    1776                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    1777                 :            :         size_t final_key_size;
+    1778                 :            :         size_t opaque_key_exchange_rsp_size;
+    1779                 :            :         void *data;
+    1780                 :            :         size_t data_size;
+    1781                 :            :         uint8_t measurement_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1782                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1783                 :            :         uint8_t *cert_buffer;
+    1784                 :            :         size_t cert_buffer_size;
+    1785                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    1786                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1787                 :            :         uint8_t bin_str0[128];
+    1788                 :            :         size_t bin_str0_size;
+    1789                 :            :         uint8_t bin_str2[128];
+    1790                 :            :         size_t bin_str2_size;
+    1791                 :            :         uint8_t bin_str7[128];
+    1792                 :            :         size_t bin_str7_size;
+    1793                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    1794                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    1795                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    1796                 :            :         size_t spdm_response_size;
+    1797                 :            :         size_t transport_header_size;
+    1798                 :            : 
+    1799                 :            :         ((libspdm_context_t *)spdm_context)
+    1800                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    1801                 :            :             m_libspdm_use_asym_algo;
+    1802                 :            :         ((libspdm_context_t *)spdm_context)
+    1803                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    1804                 :            :             m_libspdm_use_hash_algo;
+    1805                 :            :         ((libspdm_context_t *)spdm_context)
+    1806                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    1807                 :            :             m_libspdm_use_dhe_algo;
+    1808                 :            :         ((libspdm_context_t *)spdm_context)
+    1809                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    1810                 :            :             m_libspdm_use_measurement_hash_algo;
+    1811                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    1812                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1813                 :          1 :         measurement_hash_size = libspdm_get_hash_size(
+    1814                 :            :             m_libspdm_use_hash_algo);
+    1815                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1816                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    1817                 :          1 :         opaque_key_exchange_rsp_size =
+    1818                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    1819                 :            :                 spdm_context);
+    1820                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    1821                 :          1 :                              dhe_key_size + measurement_hash_size + sizeof(uint16_t) +
+    1822                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+    1823                 :            :                              hmac_size;
+    1824                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1825                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1826                 :          1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    1827                 :            : 
+    1828                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1829                 :          1 :         spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
+    1830                 :          1 :         spdm_response->header.param1 = 0;
+    1831                 :          1 :         spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
+    1832                 :            :         /* Mutual authentication is requested even though it is not supported. */
+    1833                 :          1 :         spdm_response->mut_auth_requested =
+    1834                 :            :             SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_ENCAP_REQUEST;
+    1835                 :          1 :         spdm_response->req_slot_id_param = 0;
+    1836                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_response->random_data);
+    1837                 :          1 :         ptr = (void *)(spdm_response + 1);
+    1838                 :          1 :         dhe_context = libspdm_dhe_new(
+    1839                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    1840                 :            :                 m_libspdm_use_dhe_algo,
+    1841                 :            :                 true);
+    1842                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+    1843                 :            :                                  &dhe_key_size);
+    1844                 :          1 :         final_key_size = sizeof(final_key);
+    1845                 :          1 :         libspdm_dhe_compute_key(
+    1846                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    1847                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    1848                 :            :             sizeof(spdm_key_exchange_request_t),
+    1849                 :            :             dhe_key_size, final_key, &final_key_size);
+    1850                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    1851                 :          1 :         ptr += dhe_key_size;
+    1852                 :            :         /*Mock measurement hash*/
+    1853                 :          1 :         libspdm_copy_mem(measurement_hash_data, sizeof(measurement_hash_data),
+    1854                 :            :                          m_libspdm_use_tcb_hash_value, measurement_hash_size);
+    1855                 :          1 :         libspdm_copy_mem(ptr, spdm_response_size - (ptr - (uint8_t *)spdm_response),
+    1856                 :            :                          measurement_hash_data, measurement_hash_size);
+    1857                 :            :         /*libspdm_zero_mem (ptr, measurement_hash_size);*/
+    1858                 :          1 :         ptr += measurement_hash_size;
+    1859                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    1860                 :          1 :         ptr += sizeof(uint16_t);
+    1861                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    1862                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    1863                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+    1864                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1865                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    1866                 :            :                                                         &data_size, NULL, NULL);
+    1867                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    1868                 :            :                          sizeof(m_libspdm_local_buffer)
+    1869                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    1870                 :            :                             m_libspdm_local_buffer),
+    1871                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    1872                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    1873                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    1874                 :            :                        m_libspdm_local_buffer_size));
+    1875                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    1876                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    1877                 :          1 :         cert_buffer =  (uint8_t *)data;
+    1878                 :          1 :         cert_buffer_size = data_size;
+    1879                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    1880                 :            :                          cert_buffer_hash);
+    1881                 :            :         /* transcript.message_a size is 0*/
+    1882                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    1883                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    1884                 :            :                                       m_libspdm_local_buffer_size);
+    1885                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1886                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1887                 :          1 :         free(data);
+    1888                 :          1 :         libspdm_responder_data_sign(
+    1889                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    1890                 :            :             spdm_context,
+    1891                 :            : #endif
+    1892                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    1893                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    1894                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    1895                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+    1896                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    1897                 :            :                 &signature_size);
+    1898                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    1899                 :            :                          sizeof(m_libspdm_local_buffer)
+    1900                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    1901                 :            :                             m_libspdm_local_buffer),
+    1902                 :            :                          ptr, signature_size);
+    1903                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+    1904                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    1905                 :          1 :         ptr += signature_size;
+    1906                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1907                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    1908                 :            :                          th_curr_hash_data);
+    1909                 :          1 :         bin_str0_size = sizeof(bin_str0);
+    1910                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1911                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    1912                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    1913                 :            :                            &bin_str0_size);
+    1914                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    1915                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    1916                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    1917                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1918                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    1919                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    1920                 :            :                            bin_str2, &bin_str2_size);
+    1921                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    1922                 :            :                             bin_str2, bin_str2_size,
+    1923                 :            :                             response_handshake_secret, hash_size);
+    1924                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    1925                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1926                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    1927                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    1928                 :            :                            &bin_str7_size);
+    1929                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    1930                 :            :                             hash_size, bin_str7, bin_str7_size,
+    1931                 :            :                             response_finished_key, hash_size);
+    1932                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1933                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1934                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    1935                 :            :                          response_finished_key, hash_size, ptr);
+    1936                 :          1 :         ptr += hmac_size;
+    1937                 :            : 
+    1938                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1939                 :            :                                               false, spdm_response_size,
+    1940                 :            :                                               spdm_response, response_size,
+    1941                 :            :                                               response);
+    1942                 :            :     }
+    1943                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1944                 :            : 
+    1945                 :          1 :     case 0xF: {
+    1946                 :            :         spdm_key_exchange_response_t *spdm_response;
+    1947                 :            :         size_t dhe_key_size;
+    1948                 :            :         uint32_t hash_size;
+    1949                 :            :         size_t signature_size;
+    1950                 :            :         uint32_t hmac_size;
+    1951                 :            :         uint8_t *ptr;
+    1952                 :            :         void *dhe_context;
+    1953                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    1954                 :            :         size_t final_key_size;
+    1955                 :            :         size_t opaque_key_exchange_rsp_size;
+    1956                 :            :         void *data;
+    1957                 :            :         size_t data_size;
+    1958                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1959                 :            :         uint8_t *cert_buffer;
+    1960                 :            :         size_t cert_buffer_size;
+    1961                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    1962                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1963                 :            :         uint8_t bin_str0[128];
+    1964                 :            :         size_t bin_str0_size;
+    1965                 :            :         uint8_t bin_str2[128];
+    1966                 :            :         size_t bin_str2_size;
+    1967                 :            :         uint8_t bin_str7[128];
+    1968                 :            :         size_t bin_str7_size;
+    1969                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    1970                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    1971                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    1972                 :            :         size_t spdm_response_size;
+    1973                 :            :         size_t transport_header_size;
+    1974                 :            : 
+    1975                 :            :         ((libspdm_context_t *)spdm_context)
+    1976                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    1977                 :            :             m_libspdm_use_asym_algo;
+    1978                 :            :         ((libspdm_context_t *)spdm_context)
+    1979                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    1980                 :            :             m_libspdm_use_hash_algo;
+    1981                 :            :         ((libspdm_context_t *)spdm_context)
+    1982                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    1983                 :            :             m_libspdm_use_dhe_algo;
+    1984                 :            :         ((libspdm_context_t *)spdm_context)
+    1985                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    1986                 :            :             m_libspdm_use_measurement_hash_algo;
+    1987                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    1988                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1989                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1990                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    1991                 :          1 :         opaque_key_exchange_rsp_size =
+    1992                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    1993                 :            :                 spdm_context);
+    1994                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    1995                 :          1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
+    1996                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+    1997                 :            :                              hmac_size;
+    1998                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1999                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2000                 :          1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    2001                 :            : 
+    2002                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2003                 :          1 :         spdm_response->header.request_response_code =
+    2004                 :            :             SPDM_KEY_EXCHANGE_RSP;
+    2005                 :          1 :         spdm_response->header.param1 = 0;
+    2006                 :          1 :         spdm_response->rsp_session_id =
+    2007                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
+    2008                 :          1 :         spdm_response->mut_auth_requested = 0;
+    2009                 :          1 :         spdm_response->req_slot_id_param = 0;
+    2010                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    2011                 :          1 :                                   spdm_response->random_data);
+    2012                 :          1 :         ptr = (void *)(spdm_response + 1);
+    2013                 :          1 :         dhe_context = libspdm_dhe_new(
+    2014                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    2015                 :            :                 m_libspdm_use_dhe_algo,
+    2016                 :            :                 true);
+    2017                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+    2018                 :            :                                  &dhe_key_size);
+    2019                 :          1 :         final_key_size = sizeof(final_key);
+    2020                 :          1 :         libspdm_dhe_compute_key(
+    2021                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    2022                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    2023                 :            :             sizeof(spdm_key_exchange_request_t),
+    2024                 :            :             dhe_key_size, final_key, &final_key_size);
+    2025                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    2026                 :          1 :         ptr += dhe_key_size;
+    2027                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    2028                 :            :          * ptr += hash_size;*/
+    2029                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    2030                 :          1 :         ptr += sizeof(uint16_t);
+    2031                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    2032                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    2033                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+    2034                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    2035                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    2036                 :            :                                                         &data_size, NULL, NULL);
+    2037                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    2038                 :            :                          sizeof(m_libspdm_local_buffer)
+    2039                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    2040                 :            :                             m_libspdm_local_buffer),
+    2041                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    2042                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    2043                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    2044                 :            :                        m_libspdm_local_buffer_size));
+    2045                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    2046                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    2047                 :          1 :         cert_buffer =  (uint8_t *)data;
+    2048                 :          1 :         cert_buffer_size = data_size;
+    2049                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    2050                 :            :                          cert_buffer_hash);
+    2051                 :            :         /* transcript.message_a size is 0*/
+    2052                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    2053                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    2054                 :            :                                       m_libspdm_local_buffer_size);
+    2055                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2056                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2057                 :          1 :         free(data);
+    2058                 :          1 :         libspdm_responder_data_sign(
+    2059                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    2060                 :            :             spdm_context,
+    2061                 :            : #endif
+    2062                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    2063                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    2064                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    2065                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+    2066                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    2067                 :            :                 &signature_size);
+    2068                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    2069                 :            :                          sizeof(m_libspdm_local_buffer)
+    2070                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    2071                 :            :                             m_libspdm_local_buffer),
+    2072                 :            :                          ptr, signature_size);
+    2073                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+    2074                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    2075                 :          1 :         ptr += signature_size;
+    2076                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2077                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    2078                 :            :                          th_curr_hash_data);
+    2079                 :          1 :         bin_str0_size = sizeof(bin_str0);
+    2080                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2081                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    2082                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    2083                 :            :                            &bin_str0_size);
+    2084                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    2085                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    2086                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    2087                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2088                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    2089                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    2090                 :            :                            bin_str2, &bin_str2_size);
+    2091                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    2092                 :            :                             bin_str2, bin_str2_size,
+    2093                 :            :                             response_handshake_secret, hash_size);
+    2094                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    2095                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2096                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    2097                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    2098                 :            :                            &bin_str7_size);
+    2099                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    2100                 :            :                             hash_size, bin_str7, bin_str7_size,
+    2101                 :            :                             response_finished_key, hash_size);
+    2102                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2103                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2104                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    2105                 :            :                          response_finished_key, hash_size, ptr);
+    2106                 :          1 :         ptr += hmac_size;
+    2107                 :            : 
+    2108                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    2109                 :            :                                               false, spdm_response_size,
+    2110                 :            :                                               spdm_response, response_size,
+    2111                 :            :                                               response);
+    2112                 :            :     }
+    2113                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    2114                 :            : 
+    2115                 :          1 :     case 0x10: {
+    2116                 :            :         spdm_key_exchange_response_t *spdm_response;
+    2117                 :            :         size_t dhe_key_size;
+    2118                 :            :         uint32_t hash_size;
+    2119                 :            :         size_t signature_size;
+    2120                 :            :         uint32_t hmac_size;
+    2121                 :            :         uint8_t *ptr;
+    2122                 :            :         void *dhe_context;
+    2123                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    2124                 :            :         size_t final_key_size;
+    2125                 :            :         size_t opaque_key_exchange_rsp_size;
+    2126                 :            :         void *data;
+    2127                 :            :         size_t data_size;
+    2128                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2129                 :            :         uint8_t *cert_buffer;
+    2130                 :            :         size_t cert_buffer_size;
+    2131                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    2132                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2133                 :            :         uint8_t bin_str0[128];
+    2134                 :            :         size_t bin_str0_size;
+    2135                 :            :         uint8_t bin_str2[128];
+    2136                 :            :         size_t bin_str2_size;
+    2137                 :            :         uint8_t bin_str7[128];
+    2138                 :            :         size_t bin_str7_size;
+    2139                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    2140                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    2141                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    2142                 :            :         size_t spdm_response_size;
+    2143                 :            :         size_t transport_header_size;
+    2144                 :            : 
+    2145                 :            :         ((libspdm_context_t *)spdm_context)
+    2146                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    2147                 :            :             m_libspdm_use_asym_algo;
+    2148                 :            :         ((libspdm_context_t *)spdm_context)
+    2149                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    2150                 :            :             m_libspdm_use_hash_algo;
+    2151                 :            :         ((libspdm_context_t *)spdm_context)
+    2152                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    2153                 :            :             m_libspdm_use_dhe_algo;
+    2154                 :            :         ((libspdm_context_t *)spdm_context)
+    2155                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    2156                 :            :             m_libspdm_use_measurement_hash_algo;
+    2157                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    2158                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2159                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2160                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    2161                 :          1 :         opaque_key_exchange_rsp_size =
+    2162                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    2163                 :            :                 spdm_context);
+    2164                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    2165                 :          1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
+    2166                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+    2167                 :            :                              hmac_size;
+    2168                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2169                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2170                 :          1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    2171                 :            : 
+    2172                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2173                 :          1 :         spdm_response->header.request_response_code =
+    2174                 :            :             SPDM_KEY_EXCHANGE_RSP;
+    2175                 :          1 :         spdm_response->header.param1 = 0;
+    2176                 :          1 :         spdm_response->rsp_session_id =
+    2177                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
+    2178                 :          1 :         spdm_response->mut_auth_requested = 0;
+    2179                 :          1 :         spdm_response->req_slot_id_param = 0;
+    2180                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    2181                 :          1 :                                   spdm_response->random_data);
+    2182                 :          1 :         ptr = (void *)(spdm_response + 1);
+    2183                 :          1 :         dhe_context = libspdm_dhe_new(
+    2184                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    2185                 :            :                 m_libspdm_use_dhe_algo,
+    2186                 :            :                 true);
+    2187                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+    2188                 :            :                                  &dhe_key_size);
+    2189                 :          1 :         final_key_size = sizeof(final_key);
+    2190                 :          1 :         libspdm_dhe_compute_key(
+    2191                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    2192                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    2193                 :            :             sizeof(spdm_key_exchange_request_t),
+    2194                 :            :             dhe_key_size, final_key, &final_key_size);
+    2195                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    2196                 :          1 :         ptr += dhe_key_size;
+    2197                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    2198                 :            :          * ptr += hash_size;*/
+    2199                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    2200                 :          1 :         ptr += sizeof(uint16_t);
+    2201                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    2202                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    2203                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+    2204                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    2205                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    2206                 :            :                                                         &data_size, NULL, NULL);
+    2207                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    2208                 :            :                          sizeof(m_libspdm_local_buffer)
+    2209                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    2210                 :            :                             m_libspdm_local_buffer),
+    2211                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    2212                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    2213                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    2214                 :            :                        m_libspdm_local_buffer_size));
+    2215                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    2216                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    2217                 :          1 :         cert_buffer =  (uint8_t *)data;
+    2218                 :          1 :         cert_buffer_size = data_size;
+    2219                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    2220                 :            :                          cert_buffer_hash);
+    2221                 :            :         /* transcript.message_a size is 0*/
+    2222                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    2223                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    2224                 :            :                                       m_libspdm_local_buffer_size);
+    2225                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2226                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2227                 :          1 :         free(data);
+    2228                 :          1 :         libspdm_responder_data_sign(
+    2229                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    2230                 :            :             spdm_context,
+    2231                 :            : #endif
+    2232                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    2233                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    2234                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    2235                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+    2236                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    2237                 :            :                 &signature_size);
+    2238                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    2239                 :            :                          sizeof(m_libspdm_local_buffer)
+    2240                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    2241                 :            :                             m_libspdm_local_buffer),
+    2242                 :            :                          ptr, signature_size);
+    2243                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+    2244                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    2245                 :          1 :         ptr += signature_size;
+    2246                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2247                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    2248                 :            :                          th_curr_hash_data);
+    2249                 :          1 :         bin_str0_size = sizeof(bin_str0);
+    2250                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2251                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    2252                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    2253                 :            :                            &bin_str0_size);
+    2254                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    2255                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    2256                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    2257                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2258                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    2259                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    2260                 :            :                            bin_str2, &bin_str2_size);
+    2261                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    2262                 :            :                             bin_str2, bin_str2_size,
+    2263                 :            :                             response_handshake_secret, hash_size);
+    2264                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    2265                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2266                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    2267                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    2268                 :            :                            &bin_str7_size);
+    2269                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    2270                 :            :                             hash_size, bin_str7, bin_str7_size,
+    2271                 :            :                             response_finished_key, hash_size);
+    2272                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2273                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2274                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    2275                 :            :                          response_finished_key, hash_size, ptr);
+    2276                 :          1 :         ptr += hmac_size;
+    2277                 :            : 
+    2278                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    2279                 :            :                                               false, spdm_response_size,
+    2280                 :            :                                               spdm_response, response_size,
+    2281                 :            :                                               response);
+    2282                 :            :     }
+    2283                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    2284                 :            : 
+    2285                 :          1 :     case 0x11: {
+    2286                 :            :         spdm_key_exchange_response_t *spdm_response;
+    2287                 :            :         size_t dhe_key_size;
+    2288                 :            :         uint32_t hash_size;
+    2289                 :            :         uint32_t measurement_hash_size;
+    2290                 :            :         size_t signature_size;
+    2291                 :            :         uint32_t hmac_size;
+    2292                 :            :         uint8_t *ptr;
+    2293                 :            :         void *dhe_context;
+    2294                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    2295                 :            :         size_t final_key_size;
+    2296                 :            :         size_t opaque_key_exchange_rsp_size;
+    2297                 :            :         void *data;
+    2298                 :            :         size_t data_size;
+    2299                 :            :         uint8_t measurement_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2300                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2301                 :            :         uint8_t *cert_buffer;
+    2302                 :            :         size_t cert_buffer_size;
+    2303                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    2304                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2305                 :            :         uint8_t bin_str0[128];
+    2306                 :            :         size_t bin_str0_size;
+    2307                 :            :         uint8_t bin_str2[128];
+    2308                 :            :         size_t bin_str2_size;
+    2309                 :            :         uint8_t bin_str7[128];
+    2310                 :            :         size_t bin_str7_size;
+    2311                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    2312                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    2313                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    2314                 :            :         size_t spdm_response_size;
+    2315                 :            :         size_t transport_header_size;
+    2316                 :            : 
+    2317                 :            :         ((libspdm_context_t *)spdm_context)
+    2318                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    2319                 :            :             m_libspdm_use_asym_algo;
+    2320                 :            :         ((libspdm_context_t *)spdm_context)
+    2321                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    2322                 :            :             m_libspdm_use_hash_algo;
+    2323                 :            :         ((libspdm_context_t *)spdm_context)
+    2324                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    2325                 :            :             m_libspdm_use_dhe_algo;
+    2326                 :            :         ((libspdm_context_t *)spdm_context)
+    2327                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    2328                 :            :             m_libspdm_use_measurement_hash_algo;
+    2329                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    2330                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2331                 :          1 :         measurement_hash_size = libspdm_get_hash_size(
+    2332                 :            :             m_libspdm_use_hash_algo);
+    2333                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2334                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    2335                 :          1 :         opaque_key_exchange_rsp_size =
+    2336                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    2337                 :            :                 spdm_context);
+    2338                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    2339                 :          1 :                              dhe_key_size + measurement_hash_size + sizeof(uint16_t) +
+    2340                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+    2341                 :            :                              hmac_size;
+    2342                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2343                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2344                 :          1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    2345                 :            : 
+    2346                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2347                 :          1 :         spdm_response->header.request_response_code =
+    2348                 :            :             SPDM_KEY_EXCHANGE_RSP;
+    2349                 :          1 :         spdm_response->header.param1 = 0;
+    2350                 :          1 :         spdm_response->rsp_session_id =
+    2351                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
+    2352                 :          1 :         spdm_response->mut_auth_requested = 0;
+    2353                 :          1 :         spdm_response->req_slot_id_param = 0;
+    2354                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    2355                 :          1 :                                   spdm_response->random_data);
+    2356                 :          1 :         ptr = (void *)(spdm_response + 1);
+    2357                 :          1 :         dhe_context = libspdm_dhe_new(
+    2358                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    2359                 :            :                 m_libspdm_use_dhe_algo,
+    2360                 :            :                 true);
+    2361                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+    2362                 :            :                                  &dhe_key_size);
+    2363                 :          1 :         final_key_size = sizeof(final_key);
+    2364                 :          1 :         libspdm_dhe_compute_key(
+    2365                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    2366                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    2367                 :            :             sizeof(spdm_key_exchange_request_t),
+    2368                 :            :             dhe_key_size, final_key, &final_key_size);
+    2369                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    2370                 :          1 :         ptr += dhe_key_size;
+    2371                 :            :         /*Mock measurement hash as TCB*/
+    2372                 :          1 :         libspdm_copy_mem(measurement_hash_data, sizeof(measurement_hash_data),
+    2373                 :            :                          m_libspdm_use_tcb_hash_value, measurement_hash_size);
+    2374                 :          1 :         libspdm_copy_mem(ptr, spdm_response_size - (ptr - (uint8_t *)spdm_response),
+    2375                 :            :                          measurement_hash_data, measurement_hash_size);
+    2376                 :            :         /*libspdm_zero_mem (ptr, measurement_hash_size);*/
+    2377                 :          1 :         ptr += measurement_hash_size;
+    2378                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    2379                 :          1 :         ptr += sizeof(uint16_t);
+    2380                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    2381                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    2382                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+    2383                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    2384                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    2385                 :            :                                                         &data_size, NULL, NULL);
+    2386                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    2387                 :            :                          sizeof(m_libspdm_local_buffer)
+    2388                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    2389                 :            :                             m_libspdm_local_buffer),
+    2390                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    2391                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    2392                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    2393                 :            :                        m_libspdm_local_buffer_size));
+    2394                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    2395                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    2396                 :          1 :         cert_buffer =  (uint8_t *)data;
+    2397                 :          1 :         cert_buffer_size = data_size;
+    2398                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    2399                 :            :                          cert_buffer_hash);
+    2400                 :            :         /* transcript.message_a size is 0*/
+    2401                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    2402                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    2403                 :            :                                       m_libspdm_local_buffer_size);
+    2404                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2405                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2406                 :          1 :         free(data);
+    2407                 :          1 :         libspdm_responder_data_sign(
+    2408                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    2409                 :            :             spdm_context,
+    2410                 :            : #endif
+    2411                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    2412                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    2413                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    2414                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+    2415                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    2416                 :            :                 &signature_size);
+    2417                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    2418                 :            :                          sizeof(m_libspdm_local_buffer)
+    2419                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    2420                 :            :                             m_libspdm_local_buffer),
+    2421                 :            :                          ptr, signature_size);
+    2422                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+    2423                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    2424                 :          1 :         ptr += signature_size;
+    2425                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2426                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    2427                 :            :                          th_curr_hash_data);
+    2428                 :          1 :         bin_str0_size = sizeof(bin_str0);
+    2429                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2430                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    2431                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    2432                 :            :                            &bin_str0_size);
+    2433                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    2434                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    2435                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    2436                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2437                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    2438                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    2439                 :            :                            bin_str2, &bin_str2_size);
+    2440                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    2441                 :            :                             bin_str2, bin_str2_size,
+    2442                 :            :                             response_handshake_secret, hash_size);
+    2443                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    2444                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2445                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    2446                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    2447                 :            :                            &bin_str7_size);
+    2448                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    2449                 :            :                             hash_size, bin_str7, bin_str7_size,
+    2450                 :            :                             response_finished_key, hash_size);
+    2451                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2452                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2453                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    2454                 :            :                          response_finished_key, hash_size, ptr);
+    2455                 :          1 :         ptr += hmac_size;
+    2456                 :            : 
+    2457                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    2458                 :            :                                               false, spdm_response_size,
+    2459                 :            :                                               spdm_response, response_size,
+    2460                 :            :                                               response);
+    2461                 :            :     }
+    2462                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    2463                 :            : 
+    2464                 :          1 :     case 0x12: {
+    2465                 :            :         spdm_key_exchange_response_t *spdm_response;
+    2466                 :            :         size_t dhe_key_size;
+    2467                 :            :         uint32_t hash_size;
+    2468                 :            :         uint32_t measurement_hash_size;
+    2469                 :            :         size_t signature_size;
+    2470                 :            :         uint32_t hmac_size;
+    2471                 :            :         uint8_t *ptr;
+    2472                 :            :         void *dhe_context;
+    2473                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    2474                 :            :         size_t final_key_size;
+    2475                 :            :         size_t opaque_key_exchange_rsp_size;
+    2476                 :            :         void *data;
+    2477                 :            :         size_t data_size;
+    2478                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2479                 :            :         uint8_t *cert_buffer;
+    2480                 :            :         size_t cert_buffer_size;
+    2481                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    2482                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2483                 :            :         uint8_t bin_str0[128];
+    2484                 :            :         size_t bin_str0_size;
+    2485                 :            :         uint8_t bin_str2[128];
+    2486                 :            :         size_t bin_str2_size;
+    2487                 :            :         uint8_t bin_str7[128];
+    2488                 :            :         size_t bin_str7_size;
+    2489                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    2490                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    2491                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    2492                 :            :         size_t spdm_response_size;
+    2493                 :            :         size_t transport_header_size;
+    2494                 :            : 
+    2495                 :            :         ((libspdm_context_t *)spdm_context)
+    2496                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    2497                 :            :             m_libspdm_use_asym_algo;
+    2498                 :            :         ((libspdm_context_t *)spdm_context)
+    2499                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    2500                 :            :             m_libspdm_use_hash_algo;
+    2501                 :            :         ((libspdm_context_t *)spdm_context)
+    2502                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    2503                 :            :             m_libspdm_use_dhe_algo;
+    2504                 :            :         ((libspdm_context_t *)spdm_context)
+    2505                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    2506                 :            :             m_libspdm_use_measurement_hash_algo;
+    2507                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    2508                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2509                 :          1 :         measurement_hash_size = 0;
+    2510                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2511                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    2512                 :          1 :         opaque_key_exchange_rsp_size =
+    2513                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    2514                 :            :                 spdm_context);
+    2515                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    2516                 :          1 :                              dhe_key_size + measurement_hash_size + sizeof(uint16_t) +
+    2517                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+    2518                 :            :                              hmac_size;
+    2519                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2520                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2521                 :          1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    2522                 :            : 
+    2523                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2524                 :          1 :         spdm_response->header.request_response_code =
+    2525                 :            :             SPDM_KEY_EXCHANGE_RSP;
+    2526                 :          1 :         spdm_response->header.param1 = 0;
+    2527                 :          1 :         spdm_response->rsp_session_id =
+    2528                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
+    2529                 :          1 :         spdm_response->mut_auth_requested = 0;
+    2530                 :          1 :         spdm_response->req_slot_id_param = 0;
+    2531                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    2532                 :          1 :                                   spdm_response->random_data);
+    2533                 :          1 :         ptr = (void *)(spdm_response + 1);
+    2534                 :          1 :         dhe_context = libspdm_dhe_new(
+    2535                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    2536                 :            :                 m_libspdm_use_dhe_algo,
+    2537                 :            :                 true);
+    2538                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+    2539                 :            :                                  &dhe_key_size);
+    2540                 :          1 :         final_key_size = sizeof(final_key);
+    2541                 :          1 :         libspdm_dhe_compute_key(
+    2542                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    2543                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    2544                 :            :             sizeof(spdm_key_exchange_request_t),
+    2545                 :            :             dhe_key_size, final_key, &final_key_size);
+    2546                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    2547                 :          1 :         ptr += dhe_key_size;
+    2548                 :            : 
+    2549                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    2550                 :          1 :         ptr += sizeof(uint16_t);
+    2551                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    2552                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    2553                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+    2554                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    2555                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    2556                 :            :                                                         &data_size, NULL, NULL);
+    2557                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    2558                 :            :                          sizeof(m_libspdm_local_buffer)
+    2559                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    2560                 :            :                             m_libspdm_local_buffer),
+    2561                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    2562                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    2563                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    2564                 :            :                        m_libspdm_local_buffer_size));
+    2565                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    2566                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    2567                 :          1 :         cert_buffer =  (uint8_t *)data;
+    2568                 :          1 :         cert_buffer_size = data_size;
+    2569                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    2570                 :            :                          cert_buffer_hash);
+    2571                 :            :         /* transcript.message_a size is 0*/
+    2572                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    2573                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    2574                 :            :                                       m_libspdm_local_buffer_size);
+    2575                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2576                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2577                 :          1 :         free(data);
+    2578                 :          1 :         libspdm_responder_data_sign(
+    2579                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    2580                 :            :             spdm_context,
+    2581                 :            : #endif
+    2582                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    2583                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    2584                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    2585                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+    2586                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    2587                 :            :                 &signature_size);
+    2588                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    2589                 :            :                          sizeof(m_libspdm_local_buffer)
+    2590                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    2591                 :            :                             m_libspdm_local_buffer),
+    2592                 :            :                          ptr, signature_size);
+    2593                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+    2594                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    2595                 :          1 :         ptr += signature_size-1;
+    2596                 :          1 :         *ptr ^= 0xFF;
+    2597                 :          1 :         ptr++;
+    2598                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2599                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    2600                 :            :                          th_curr_hash_data);
+    2601                 :          1 :         bin_str0_size = sizeof(bin_str0);
+    2602                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2603                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    2604                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    2605                 :            :                            &bin_str0_size);
+    2606                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    2607                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    2608                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    2609                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2610                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    2611                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    2612                 :            :                            bin_str2, &bin_str2_size);
+    2613                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    2614                 :            :                             bin_str2, bin_str2_size,
+    2615                 :            :                             response_handshake_secret, hash_size);
+    2616                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    2617                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2618                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    2619                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    2620                 :            :                            &bin_str7_size);
+    2621                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    2622                 :            :                             hash_size, bin_str7, bin_str7_size,
+    2623                 :            :                             response_finished_key, hash_size);
+    2624                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2625                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2626                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    2627                 :            :                          response_finished_key, hash_size, ptr);
+    2628                 :          1 :         ptr += hmac_size;
+    2629                 :            : 
+    2630                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    2631                 :            :                                               false, spdm_response_size,
+    2632                 :            :                                               spdm_response, response_size,
+    2633                 :            :                                               response);
+    2634                 :            :     }
+    2635                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    2636                 :            : 
+    2637                 :          0 :     case 0x13: {
+    2638                 :            :     }
+    2639                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+    2640                 :            : 
+    2641                 :          1 :     case 0x14: {
+    2642                 :            :         spdm_key_exchange_response_t *spdm_response;
+    2643                 :            :         size_t dhe_key_size;
+    2644                 :            :         uint32_t hash_size;
+    2645                 :            :         size_t signature_size;
+    2646                 :            :         uint32_t hmac_size;
+    2647                 :            :         uint8_t *ptr;
+    2648                 :            :         void *dhe_context;
+    2649                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    2650                 :            :         size_t final_key_size;
+    2651                 :            :         size_t opaque_key_exchange_rsp_size;
+    2652                 :            :         void *data;
+    2653                 :            :         size_t data_size;
+    2654                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2655                 :            :         uint8_t *cert_buffer;
+    2656                 :            :         size_t cert_buffer_size;
+    2657                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    2658                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2659                 :            :         uint8_t bin_str0[128];
+    2660                 :            :         size_t bin_str0_size;
+    2661                 :            :         uint8_t bin_str2[128];
+    2662                 :            :         size_t bin_str2_size;
+    2663                 :            :         uint8_t bin_str7[128];
+    2664                 :            :         size_t bin_str7_size;
+    2665                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    2666                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    2667                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    2668                 :            :         size_t spdm_response_size;
+    2669                 :            :         size_t transport_header_size;
+    2670                 :            : 
+    2671                 :            :         ((libspdm_context_t *)spdm_context)
+    2672                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    2673                 :            :             m_libspdm_use_asym_algo;
+    2674                 :            :         ((libspdm_context_t *)spdm_context)
+    2675                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    2676                 :            :             m_libspdm_use_hash_algo;
+    2677                 :            :         ((libspdm_context_t *)spdm_context)
+    2678                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    2679                 :            :             m_libspdm_use_dhe_algo;
+    2680                 :            :         ((libspdm_context_t *)spdm_context)
+    2681                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    2682                 :            :             m_libspdm_use_measurement_hash_algo;
+    2683                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    2684                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2685                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2686                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    2687                 :          1 :         opaque_key_exchange_rsp_size =
+    2688                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    2689                 :            :                 spdm_context);
+    2690                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    2691                 :          1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
+    2692                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+    2693                 :            :                              hmac_size;
+    2694                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2695                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2696                 :          1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    2697                 :            : 
+    2698                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2699                 :          1 :         spdm_response->header.request_response_code =
+    2700                 :            :             SPDM_KEY_EXCHANGE_RSP;
+    2701                 :          1 :         spdm_response->header.param1 = 5;
+    2702                 :          1 :         spdm_response->rsp_session_id =
+    2703                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
+    2704                 :          1 :         spdm_response->mut_auth_requested = 0;
+    2705                 :          1 :         spdm_response->req_slot_id_param = 0;
+    2706                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    2707                 :          1 :                                   spdm_response->random_data);
+    2708                 :          1 :         ptr = (void *)(spdm_response + 1);
+    2709                 :          1 :         dhe_context = libspdm_dhe_new(
+    2710                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    2711                 :            :                 m_libspdm_use_dhe_algo,
+    2712                 :            :                 true);
+    2713                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+    2714                 :            :                                  &dhe_key_size);
+    2715                 :          1 :         final_key_size = sizeof(final_key);
+    2716                 :          1 :         libspdm_dhe_compute_key(
+    2717                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    2718                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    2719                 :            :             sizeof(spdm_key_exchange_request_t),
+    2720                 :            :             dhe_key_size, final_key, &final_key_size);
+    2721                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    2722                 :          1 :         ptr += dhe_key_size;
+    2723                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    2724                 :            :          * ptr += hash_size;*/
+    2725                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    2726                 :          1 :         ptr += sizeof(uint16_t);
+    2727                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    2728                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    2729                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+    2730                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    2731                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    2732                 :            :                                                         &data_size, NULL, NULL);
+    2733                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    2734                 :            :                          sizeof(m_libspdm_local_buffer)
+    2735                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    2736                 :            :                             m_libspdm_local_buffer),
+    2737                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    2738                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    2739                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    2740                 :            :                        m_libspdm_local_buffer_size));
+    2741                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    2742                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    2743                 :          1 :         cert_buffer =  (uint8_t *)data;
+    2744                 :          1 :         cert_buffer_size = data_size;
+    2745                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    2746                 :            :                          cert_buffer_hash);
+    2747                 :            :         /* transcript.message_a size is 0*/
+    2748                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    2749                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    2750                 :            :                                       m_libspdm_local_buffer_size);
+    2751                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2752                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2753                 :          1 :         free(data);
+    2754                 :          1 :         libspdm_responder_data_sign(
+    2755                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    2756                 :            :             spdm_context,
+    2757                 :            : #endif
+    2758                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    2759                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    2760                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    2761                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+    2762                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    2763                 :            :                 &signature_size);
+    2764                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    2765                 :            :                          sizeof(m_libspdm_local_buffer)
+    2766                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    2767                 :            :                             m_libspdm_local_buffer),
+    2768                 :            :                          ptr, signature_size);
+    2769                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+    2770                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    2771                 :          1 :         ptr += signature_size;
+    2772                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2773                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    2774                 :            :                          th_curr_hash_data);
+    2775                 :          1 :         bin_str0_size = sizeof(bin_str0);
+    2776                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2777                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    2778                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    2779                 :            :                            &bin_str0_size);
+    2780                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    2781                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    2782                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    2783                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2784                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    2785                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    2786                 :            :                            bin_str2, &bin_str2_size);
+    2787                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    2788                 :            :                             bin_str2, bin_str2_size,
+    2789                 :            :                             response_handshake_secret, hash_size);
+    2790                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    2791                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2792                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    2793                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    2794                 :            :                            &bin_str7_size);
+    2795                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    2796                 :            :                             hash_size, bin_str7, bin_str7_size,
+    2797                 :            :                             response_finished_key, hash_size);
+    2798                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2799                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2800                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    2801                 :            :                          response_finished_key, hash_size, ptr);
+    2802                 :          1 :         ptr += hmac_size;
+    2803                 :            : 
+    2804                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    2805                 :            :                                               false, spdm_response_size,
+    2806                 :            :                                               spdm_response, response_size,
+    2807                 :            :                                               response);
+    2808                 :            :     }
+    2809                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    2810                 :            : 
+    2811                 :          1 :     case 0x15: {
+    2812                 :            :         spdm_key_exchange_response_t *spdm_response;
+    2813                 :            :         size_t dhe_key_size;
+    2814                 :            :         uint32_t hash_size;
+    2815                 :            :         size_t signature_size;
+    2816                 :            :         uint32_t hmac_size;
+    2817                 :            :         uint8_t *ptr;
+    2818                 :            :         void *dhe_context;
+    2819                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    2820                 :            :         size_t final_key_size;
+    2821                 :            :         size_t opaque_key_exchange_rsp_size;
+    2822                 :            :         void *data;
+    2823                 :            :         size_t data_size;
+    2824                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2825                 :            :         uint8_t *cert_buffer;
+    2826                 :            :         size_t cert_buffer_size;
+    2827                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    2828                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2829                 :            :         uint8_t bin_str0[128];
+    2830                 :            :         size_t bin_str0_size;
+    2831                 :            :         uint8_t bin_str2[128];
+    2832                 :            :         size_t bin_str2_size;
+    2833                 :            :         uint8_t bin_str7[128];
+    2834                 :            :         size_t bin_str7_size;
+    2835                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    2836                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    2837                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    2838                 :            :         size_t spdm_response_size;
+    2839                 :            :         size_t transport_header_size;
+    2840                 :            : 
+    2841                 :            :         ((libspdm_context_t *)spdm_context)
+    2842                 :          1 :         ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2843                 :            :         ((libspdm_context_t *)spdm_context)
+    2844                 :          1 :         ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2845                 :            :         ((libspdm_context_t *)spdm_context)
+    2846                 :          1 :         ->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    2847                 :            :         ((libspdm_context_t *)spdm_context)
+    2848                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    2849                 :            :             m_libspdm_use_measurement_hash_algo;
+    2850                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    2851                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2852                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2853                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    2854                 :          1 :         opaque_key_exchange_rsp_size =
+    2855                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(spdm_context);
+    2856                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    2857                 :          1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
+    2858                 :          1 :                              opaque_key_exchange_rsp_size + signature_size + hmac_size;
+    2859                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2860                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2861                 :          1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    2862                 :            : 
+    2863                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2864                 :          1 :         spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
+    2865                 :          1 :         spdm_response->header.param1 = 0;
+    2866                 :          1 :         spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
+    2867                 :          1 :         spdm_response->mut_auth_requested = 0;
+    2868                 :          1 :         spdm_response->req_slot_id_param = 0;
+    2869                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_response->random_data);
+    2870                 :          1 :         ptr = (void *)(spdm_response + 1);
+    2871                 :          1 :         dhe_context = libspdm_dhe_new(
+    2872                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    2873                 :            :                 m_libspdm_use_dhe_algo, true);
+    2874                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
+    2875                 :          1 :         final_key_size = sizeof(final_key);
+    2876                 :          1 :         libspdm_dhe_compute_key(
+    2877                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    2878                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    2879                 :            :             sizeof(spdm_key_exchange_request_t),
+    2880                 :            :             dhe_key_size, final_key, &final_key_size);
+    2881                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    2882                 :          1 :         ptr += dhe_key_size;
+    2883                 :            : 
+    2884                 :          1 :         *(uint16_t *)ptr = SPDM_MAX_OPAQUE_DATA_SIZE + 1;
+    2885                 :          1 :         ptr += sizeof(uint16_t);
+    2886                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    2887                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    2888                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+    2889                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    2890                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    2891                 :            :                                                         &data_size, NULL, NULL);
+    2892                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    2893                 :            :                          sizeof(m_libspdm_local_buffer)
+    2894                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    2895                 :            :                             m_libspdm_local_buffer),
+    2896                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    2897                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    2898                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    2899                 :            :                        m_libspdm_local_buffer_size));
+    2900                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    2901                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    2902                 :          1 :         cert_buffer = (uint8_t *)data;
+    2903                 :          1 :         cert_buffer_size =  data_size;
+    2904                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    2905                 :            :                          cert_buffer_hash);
+    2906                 :            :         /* transcript.message_a size is 0*/
+    2907                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    2908                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    2909                 :            :                                       m_libspdm_local_buffer_size);
+    2910                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2911                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2912                 :          1 :         free(data);
+    2913                 :          1 :         libspdm_responder_data_sign(
+    2914                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    2915                 :            :             spdm_context,
+    2916                 :            : #endif
+    2917                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    2918                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    2919                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    2920                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+    2921                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    2922                 :            :                 &signature_size);
+    2923                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    2924                 :            :                          sizeof(m_libspdm_local_buffer)
+    2925                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    2926                 :            :                             m_libspdm_local_buffer),
+    2927                 :            :                          ptr, signature_size);
+    2928                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+    2929                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    2930                 :          1 :         ptr += signature_size;
+    2931                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2932                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    2933                 :            :                          th_curr_hash_data);
+    2934                 :          1 :         bin_str0_size = sizeof(bin_str0);
+    2935                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2936                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    2937                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    2938                 :            :                            &bin_str0_size);
+    2939                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    2940                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    2941                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    2942                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2943                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    2944                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    2945                 :            :                            bin_str2, &bin_str2_size);
+    2946                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    2947                 :            :                             bin_str2, bin_str2_size,
+    2948                 :            :                             response_handshake_secret, hash_size);
+    2949                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    2950                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2951                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    2952                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    2953                 :            :                            &bin_str7_size);
+    2954                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    2955                 :            :                             hash_size, bin_str7, bin_str7_size,
+    2956                 :            :                             response_finished_key, hash_size);
+    2957                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2958                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2959                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    2960                 :            :                          response_finished_key, hash_size, ptr);
+    2961                 :          1 :         ptr += hmac_size;
+    2962                 :            : 
+    2963                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    2964                 :            :                                               false, spdm_response_size,
+    2965                 :            :                                               spdm_response, response_size,
+    2966                 :            :                                               response);
+    2967                 :            :     }
+    2968                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    2969                 :            : 
+    2970                 :          1 :     case 0x16: {
+    2971                 :            :         spdm_key_exchange_response_t *spdm_response;
+    2972                 :            :         size_t dhe_key_size;
+    2973                 :            :         uint32_t hash_size;
+    2974                 :            :         size_t signature_size;
+    2975                 :            :         uint32_t hmac_size;
+    2976                 :            :         uint8_t *ptr;
+    2977                 :            :         void *dhe_context;
+    2978                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    2979                 :            :         size_t final_key_size;
+    2980                 :            :         size_t opaque_key_exchange_rsp_size;
+    2981                 :            :         void *data;
+    2982                 :            :         size_t data_size;
+    2983                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2984                 :            :         uint8_t *cert_buffer;
+    2985                 :            :         size_t cert_buffer_size;
+    2986                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    2987                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2988                 :            :         uint8_t bin_str0[128];
+    2989                 :            :         size_t bin_str0_size;
+    2990                 :            :         uint8_t bin_str2[128];
+    2991                 :            :         size_t bin_str2_size;
+    2992                 :            :         uint8_t bin_str7[128];
+    2993                 :            :         size_t bin_str7_size;
+    2994                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    2995                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    2996                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    2997                 :            :         size_t spdm_response_size;
+    2998                 :            :         size_t transport_header_size;
+    2999                 :            : 
+    3000                 :            :         ((libspdm_context_t *)spdm_context)
+    3001                 :          1 :         ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    3002                 :            :         ((libspdm_context_t *)spdm_context)
+    3003                 :          1 :         ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    3004                 :            :         ((libspdm_context_t *)spdm_context)
+    3005                 :          1 :         ->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    3006                 :            :         ((libspdm_context_t *)spdm_context)
+    3007                 :          1 :         ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+    3008                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    3009                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3010                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3011                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    3012                 :          1 :         opaque_key_exchange_rsp_size =
+    3013                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(spdm_context);
+    3014                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    3015                 :          1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
+    3016                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+    3017                 :            :                              hmac_size;
+    3018                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    3019                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    3020                 :          1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    3021                 :            : 
+    3022                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    3023                 :          1 :         spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
+    3024                 :          1 :         spdm_response->header.param1 = 0;
+    3025                 :          1 :         spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
+    3026                 :            :         /* Requester's PUB_KEY_ID_CAP is set and Responder requests the encapsulated flow. */
+    3027                 :          1 :         spdm_response->mut_auth_requested =
+    3028                 :            :             SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_ENCAP_REQUEST;
+    3029                 :          1 :         spdm_response->req_slot_id_param = 0;
+    3030                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_response->random_data);
+    3031                 :          1 :         ptr = (void *)(spdm_response + 1);
+    3032                 :          1 :         dhe_context = libspdm_dhe_new(
+    3033                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    3034                 :            :                 m_libspdm_use_dhe_algo,
+    3035                 :            :                 true);
+    3036                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
+    3037                 :          1 :         final_key_size = sizeof(final_key);
+    3038                 :          1 :         libspdm_dhe_compute_key(
+    3039                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    3040                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    3041                 :            :             sizeof(spdm_key_exchange_request_t),
+    3042                 :            :             dhe_key_size, final_key, &final_key_size);
+    3043                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    3044                 :          1 :         ptr += dhe_key_size;
+    3045                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    3046                 :            :          * ptr += hash_size;*/
+    3047                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    3048                 :          1 :         ptr += sizeof(uint16_t);
+    3049                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    3050                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    3051                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+    3052                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3053                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    3054                 :            :                                                         &data_size, NULL, NULL);
+    3055                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    3056                 :            :                          sizeof(m_libspdm_local_buffer)
+    3057                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    3058                 :            :                             m_libspdm_local_buffer),
+    3059                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    3060                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    3061                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    3062                 :            :                        m_libspdm_local_buffer_size));
+    3063                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    3064                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    3065                 :          1 :         cert_buffer =  (uint8_t *)data;
+    3066                 :          1 :         cert_buffer_size = data_size;
+    3067                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    3068                 :            :                          cert_buffer_hash);
+    3069                 :            :         /* transcript.message_a size is 0*/
+    3070                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    3071                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    3072                 :            :                                       m_libspdm_local_buffer_size);
+    3073                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3074                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    3075                 :          1 :         free(data);
+    3076                 :          1 :         libspdm_responder_data_sign(
+    3077                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    3078                 :            :             spdm_context,
+    3079                 :            : #endif
+    3080                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    3081                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    3082                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    3083                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+    3084                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    3085                 :            :                 &signature_size);
+    3086                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    3087                 :            :                          sizeof(m_libspdm_local_buffer)
+    3088                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    3089                 :            :                             m_libspdm_local_buffer),
+    3090                 :            :                          ptr, signature_size);
+    3091                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+    3092                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    3093                 :          1 :         ptr += signature_size;
+    3094                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3095                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    3096                 :            :                          th_curr_hash_data);
+    3097                 :          1 :         bin_str0_size = sizeof(bin_str0);
+    3098                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    3099                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    3100                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    3101                 :            :                            &bin_str0_size);
+    3102                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    3103                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    3104                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    3105                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    3106                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    3107                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    3108                 :            :                            bin_str2, &bin_str2_size);
+    3109                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    3110                 :            :                             bin_str2, bin_str2_size,
+    3111                 :            :                             response_handshake_secret, hash_size);
+    3112                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    3113                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    3114                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    3115                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    3116                 :            :                            &bin_str7_size);
+    3117                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    3118                 :            :                             hash_size, bin_str7, bin_str7_size,
+    3119                 :            :                             response_finished_key, hash_size);
+    3120                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3121                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    3122                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    3123                 :            :                          response_finished_key, hash_size, ptr);
+    3124                 :          1 :         ptr += hmac_size;
+    3125                 :            : 
+    3126                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    3127                 :            :                                               false, spdm_response_size,
+    3128                 :            :                                               spdm_response, response_size,
+    3129                 :            :                                               response);
+    3130                 :            :     }
+    3131                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    3132                 :            : 
+    3133                 :          1 :     case 0x17: {
+    3134                 :            :         spdm_key_exchange_response_t *spdm_response;
+    3135                 :            :         size_t dhe_key_size;
+    3136                 :            :         uint32_t hash_size;
+    3137                 :            :         size_t signature_size;
+    3138                 :            :         uint32_t hmac_size;
+    3139                 :            :         uint8_t *ptr;
+    3140                 :            :         void *dhe_context;
+    3141                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    3142                 :            :         size_t final_key_size;
+    3143                 :            :         size_t opaque_key_exchange_rsp_size;
+    3144                 :            :         void *data;
+    3145                 :            :         size_t data_size;
+    3146                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    3147                 :            :         uint8_t *cert_buffer;
+    3148                 :            :         size_t cert_buffer_size;
+    3149                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    3150                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    3151                 :            :         uint8_t bin_str0[128];
+    3152                 :            :         size_t bin_str0_size;
+    3153                 :            :         uint8_t bin_str2[128];
+    3154                 :            :         size_t bin_str2_size;
+    3155                 :            :         uint8_t bin_str7[128];
+    3156                 :            :         size_t bin_str7_size;
+    3157                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    3158                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    3159                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    3160                 :            :         size_t spdm_response_size;
+    3161                 :            :         size_t transport_header_size;
+    3162                 :            : 
+    3163                 :            :         ((libspdm_context_t *)spdm_context)
+    3164                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    3165                 :            :             m_libspdm_use_asym_algo;
+    3166                 :            :         ((libspdm_context_t *)spdm_context)
+    3167                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    3168                 :            :             m_libspdm_use_hash_algo;
+    3169                 :            :         ((libspdm_context_t *)spdm_context)
+    3170                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    3171                 :            :             m_libspdm_use_dhe_algo;
+    3172                 :            :         ((libspdm_context_t *)spdm_context)
+    3173                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    3174                 :            :             m_libspdm_use_measurement_hash_algo;
+    3175                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    3176                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3177                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3178                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    3179                 :          1 :         opaque_key_exchange_rsp_size =
+    3180                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    3181                 :            :                 spdm_context);
+    3182                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    3183                 :          1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
+    3184                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+    3185                 :            :                              hmac_size;
+    3186                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    3187                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    3188                 :          1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    3189                 :            : 
+    3190                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    3191                 :          1 :         spdm_response->header.request_response_code =
+    3192                 :            :             SPDM_KEY_EXCHANGE_RSP;
+    3193                 :          1 :         spdm_response->header.param1 = 0;
+    3194                 :          1 :         spdm_response->rsp_session_id =
+    3195                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
+    3196                 :          1 :         spdm_response->mut_auth_requested =
+    3197                 :            :             SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_ENCAP_REQUEST;
+    3198                 :          1 :         spdm_response->req_slot_id_param = 0x0;
+    3199                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    3200                 :          1 :                                   spdm_response->random_data);
+    3201                 :          1 :         ptr = (void *)(spdm_response + 1);
+    3202                 :          1 :         dhe_context = libspdm_dhe_new(
+    3203                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    3204                 :            :                 m_libspdm_use_dhe_algo,
+    3205                 :            :                 true);
+    3206                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+    3207                 :            :                                  &dhe_key_size);
+    3208                 :          1 :         final_key_size = sizeof(final_key);
+    3209                 :          1 :         libspdm_dhe_compute_key(
+    3210                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    3211                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    3212                 :            :             sizeof(spdm_key_exchange_request_t),
+    3213                 :            :             dhe_key_size, final_key, &final_key_size);
+    3214                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    3215                 :          1 :         ptr += dhe_key_size;
+    3216                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    3217                 :            :          * ptr += hash_size;*/
+    3218                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    3219                 :          1 :         ptr += sizeof(uint16_t);
+    3220                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    3221                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    3222                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+    3223                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3224                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    3225                 :            :                                                         &data_size, NULL, NULL);
+    3226                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    3227                 :            :                          sizeof(m_libspdm_local_buffer)
+    3228                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    3229                 :            :                             m_libspdm_local_buffer),
+    3230                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    3231                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    3232                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    3233                 :            :                        m_libspdm_local_buffer_size));
+    3234                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    3235                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    3236                 :          1 :         cert_buffer =  (uint8_t *)data;
+    3237                 :          1 :         cert_buffer_size = data_size;
+    3238                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    3239                 :            :                          cert_buffer_hash);
+    3240                 :            :         /* transcript.message_a size is 0*/
+    3241                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    3242                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    3243                 :            :                                       m_libspdm_local_buffer_size);
+    3244                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3245                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    3246                 :          1 :         free(data);
+    3247                 :          1 :         libspdm_responder_data_sign(
+    3248                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    3249                 :            :             spdm_context,
+    3250                 :            : #endif
+    3251                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    3252                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    3253                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    3254                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+    3255                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    3256                 :            :                 &signature_size);
+    3257                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    3258                 :            :                          sizeof(m_libspdm_local_buffer)
+    3259                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    3260                 :            :                             m_libspdm_local_buffer),
+    3261                 :            :                          ptr, signature_size);
+    3262                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+    3263                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    3264                 :          1 :         ptr += signature_size;
+    3265                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3266                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    3267                 :            :                          th_curr_hash_data);
+    3268                 :          1 :         bin_str0_size = sizeof(bin_str0);
+    3269                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    3270                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    3271                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    3272                 :            :                            &bin_str0_size);
+    3273                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    3274                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    3275                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    3276                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    3277                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    3278                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    3279                 :            :                            bin_str2, &bin_str2_size);
+    3280                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    3281                 :            :                             bin_str2, bin_str2_size,
+    3282                 :            :                             response_handshake_secret, hash_size);
+    3283                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    3284                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    3285                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    3286                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    3287                 :            :                            &bin_str7_size);
+    3288                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    3289                 :            :                             hash_size, bin_str7, bin_str7_size,
+    3290                 :            :                             response_finished_key, hash_size);
+    3291                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3292                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    3293                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    3294                 :            :                          response_finished_key, hash_size, ptr);
+    3295                 :          1 :         ptr += hmac_size;
+    3296                 :            : 
+    3297                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    3298                 :            :                                               false, spdm_response_size,
+    3299                 :            :                                               spdm_response, response_size,
+    3300                 :            :                                               response);
+    3301                 :            :     }
+    3302                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    3303                 :            : 
+    3304                 :          0 :     case 0x18: {
+    3305                 :            :         spdm_key_exchange_response_t *spdm_response;
+    3306                 :            :         size_t dhe_key_size;
+    3307                 :            :         uint32_t hash_size;
+    3308                 :            :         size_t signature_size;
+    3309                 :            :         uint32_t hmac_size;
+    3310                 :            :         uint8_t *ptr;
+    3311                 :            :         void *dhe_context;
+    3312                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    3313                 :            :         size_t final_key_size;
+    3314                 :            :         size_t opaque_key_exchange_rsp_size;
+    3315                 :            :         void *data;
+    3316                 :            :         size_t data_size;
+    3317                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    3318                 :            :         uint8_t *cert_buffer;
+    3319                 :            :         size_t cert_buffer_size;
+    3320                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    3321                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    3322                 :            :         uint8_t bin_str0[128];
+    3323                 :            :         size_t bin_str0_size;
+    3324                 :            :         uint8_t bin_str2[128];
+    3325                 :            :         size_t bin_str2_size;
+    3326                 :            :         uint8_t bin_str7[128];
+    3327                 :            :         size_t bin_str7_size;
+    3328                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    3329                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    3330                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    3331                 :            :         size_t spdm_response_size;
+    3332                 :            :         size_t transport_header_size;
+    3333                 :            : 
+    3334                 :            :         ((libspdm_context_t *)spdm_context)
+    3335                 :          0 :         ->connection_info.algorithm.base_asym_algo =
+    3336                 :            :             m_libspdm_use_asym_algo;
+    3337                 :            :         ((libspdm_context_t *)spdm_context)
+    3338                 :          0 :         ->connection_info.algorithm.base_hash_algo =
+    3339                 :            :             m_libspdm_use_hash_algo;
+    3340                 :            :         ((libspdm_context_t *)spdm_context)
+    3341                 :          0 :         ->connection_info.algorithm.dhe_named_group =
+    3342                 :            :             m_libspdm_use_dhe_algo;
+    3343                 :            :         ((libspdm_context_t *)spdm_context)
+    3344                 :          0 :         ->connection_info.algorithm.measurement_hash_algo =
+    3345                 :            :             m_libspdm_use_measurement_hash_algo;
+    3346                 :          0 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    3347                 :          0 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3348                 :          0 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3349                 :          0 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    3350                 :          0 :         opaque_key_exchange_rsp_size =
+    3351                 :          0 :             libspdm_get_opaque_data_version_selection_data_size(
+    3352                 :            :                 spdm_context);
+    3353                 :          0 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    3354                 :          0 :                              dhe_key_size + 0 + sizeof(uint16_t) +
+    3355                 :          0 :                              opaque_key_exchange_rsp_size + signature_size +
+    3356                 :            :                              hmac_size;
+    3357                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    3358                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    3359                 :          0 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    3360                 :            : 
+    3361                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    3362                 :          0 :         spdm_response->header.request_response_code =
+    3363                 :            :             SPDM_KEY_EXCHANGE_RSP;
+    3364                 :          0 :         spdm_response->header.param1 = 0;
+    3365                 :          0 :         spdm_response->rsp_session_id =
+    3366                 :          0 :             libspdm_allocate_rsp_session_id(spdm_context, false);
+    3367                 :          0 :         spdm_response->mut_auth_requested =
+    3368                 :            :             SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_ENCAP_REQUEST;
+    3369                 :          0 :         spdm_response->req_slot_id_param = 0xF;
+    3370                 :          0 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    3371                 :          0 :                                   spdm_response->random_data);
+    3372                 :          0 :         ptr = (void *)(spdm_response + 1);
+    3373                 :          0 :         dhe_context = libspdm_dhe_new(
+    3374                 :          0 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    3375                 :            :                 m_libspdm_use_dhe_algo,
+    3376                 :            :                 true);
+    3377                 :          0 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+    3378                 :            :                                  &dhe_key_size);
+    3379                 :          0 :         final_key_size = sizeof(final_key);
+    3380                 :          0 :         libspdm_dhe_compute_key(
+    3381                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    3382                 :          0 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    3383                 :            :             sizeof(spdm_key_exchange_request_t),
+    3384                 :            :             dhe_key_size, final_key, &final_key_size);
+    3385                 :          0 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    3386                 :          0 :         ptr += dhe_key_size;
+    3387                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    3388                 :            :          * ptr += hash_size;*/
+    3389                 :          0 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    3390                 :          0 :         ptr += sizeof(uint16_t);
+    3391                 :          0 :         libspdm_build_opaque_data_version_selection_data(
+    3392                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    3393                 :          0 :         ptr += opaque_key_exchange_rsp_size;
+    3394                 :          0 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3395                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    3396                 :            :                                                         &data_size, NULL, NULL);
+    3397                 :          0 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    3398                 :            :                          sizeof(m_libspdm_local_buffer)
+    3399                 :          0 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    3400                 :            :                             m_libspdm_local_buffer),
+    3401                 :          0 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    3402                 :          0 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    3403                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    3404                 :            :                        m_libspdm_local_buffer_size));
+    3405                 :          0 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    3406                 :          0 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    3407                 :          0 :         cert_buffer =  (uint8_t *)data;
+    3408                 :          0 :         cert_buffer_size = data_size;
+    3409                 :          0 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    3410                 :            :                          cert_buffer_hash);
+    3411                 :            :         /* transcript.message_a size is 0*/
+    3412                 :          0 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    3413                 :          0 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    3414                 :            :                                       m_libspdm_local_buffer_size);
+    3415                 :          0 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3416                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    3417                 :          0 :         free(data);
+    3418                 :          0 :         libspdm_responder_data_sign(
+    3419                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    3420                 :            :             spdm_context,
+    3421                 :            : #endif
+    3422                 :          0 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    3423                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    3424                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    3425                 :          0 :                 false, libspdm_get_managed_buffer(&th_curr),
+    3426                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    3427                 :            :                 &signature_size);
+    3428                 :          0 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    3429                 :            :                          sizeof(m_libspdm_local_buffer)
+    3430                 :          0 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    3431                 :            :                             m_libspdm_local_buffer),
+    3432                 :            :                          ptr, signature_size);
+    3433                 :          0 :         m_libspdm_local_buffer_size += signature_size;
+    3434                 :          0 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    3435                 :          0 :         ptr += signature_size;
+    3436                 :          0 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3437                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    3438                 :            :                          th_curr_hash_data);
+    3439                 :          0 :         bin_str0_size = sizeof(bin_str0);
+    3440                 :          0 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    3441                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    3442                 :          0 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    3443                 :            :                            &bin_str0_size);
+    3444                 :          0 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    3445                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    3446                 :          0 :         bin_str2_size = sizeof(bin_str2);
+    3447                 :          0 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    3448                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    3449                 :          0 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    3450                 :            :                            bin_str2, &bin_str2_size);
+    3451                 :          0 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    3452                 :            :                             bin_str2, bin_str2_size,
+    3453                 :            :                             response_handshake_secret, hash_size);
+    3454                 :          0 :         bin_str7_size = sizeof(bin_str7);
+    3455                 :          0 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    3456                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    3457                 :          0 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    3458                 :            :                            &bin_str7_size);
+    3459                 :          0 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    3460                 :            :                             hash_size, bin_str7, bin_str7_size,
+    3461                 :            :                             response_finished_key, hash_size);
+    3462                 :          0 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3463                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    3464                 :          0 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    3465                 :            :                          response_finished_key, hash_size, ptr);
+    3466                 :          0 :         ptr += hmac_size;
+    3467                 :            : 
+    3468                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    3469                 :            :                                               false, spdm_response_size,
+    3470                 :            :                                               spdm_response, response_size,
+    3471                 :            :                                               response);
+    3472                 :            :     }
+    3473                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+    3474                 :            : 
+    3475                 :          0 :     case 0x19: {
+    3476                 :            :         spdm_key_exchange_response_t *spdm_response;
+    3477                 :            :         size_t dhe_key_size;
+    3478                 :            :         uint32_t hash_size;
+    3479                 :            :         size_t signature_size;
+    3480                 :            :         uint32_t hmac_size;
+    3481                 :            :         uint8_t *ptr;
+    3482                 :            :         void *dhe_context;
+    3483                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    3484                 :            :         size_t final_key_size;
+    3485                 :            :         size_t opaque_key_exchange_rsp_size;
+    3486                 :            :         void *data;
+    3487                 :            :         size_t data_size;
+    3488                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    3489                 :            :         uint8_t *cert_buffer;
+    3490                 :            :         size_t cert_buffer_size;
+    3491                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    3492                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    3493                 :            :         uint8_t bin_str0[128];
+    3494                 :            :         size_t bin_str0_size;
+    3495                 :            :         uint8_t bin_str2[128];
+    3496                 :            :         size_t bin_str2_size;
+    3497                 :            :         uint8_t bin_str7[128];
+    3498                 :            :         size_t bin_str7_size;
+    3499                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    3500                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    3501                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    3502                 :            :         size_t spdm_response_size;
+    3503                 :            :         size_t transport_header_size;
+    3504                 :            : 
+    3505                 :            :         ((libspdm_context_t *)spdm_context)
+    3506                 :          0 :         ->connection_info.algorithm.base_asym_algo =
+    3507                 :            :             m_libspdm_use_asym_algo;
+    3508                 :            :         ((libspdm_context_t *)spdm_context)
+    3509                 :          0 :         ->connection_info.algorithm.base_hash_algo =
+    3510                 :            :             m_libspdm_use_hash_algo;
+    3511                 :            :         ((libspdm_context_t *)spdm_context)
+    3512                 :          0 :         ->connection_info.algorithm.dhe_named_group =
+    3513                 :            :             m_libspdm_use_dhe_algo;
+    3514                 :            :         ((libspdm_context_t *)spdm_context)
+    3515                 :          0 :         ->connection_info.algorithm.measurement_hash_algo =
+    3516                 :            :             m_libspdm_use_measurement_hash_algo;
+    3517                 :          0 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    3518                 :          0 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3519                 :          0 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3520                 :          0 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    3521                 :          0 :         opaque_key_exchange_rsp_size =
+    3522                 :          0 :             libspdm_get_opaque_data_version_selection_data_size(
+    3523                 :            :                 spdm_context);
+    3524                 :          0 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    3525                 :          0 :                              dhe_key_size + 0 + sizeof(uint16_t) +
+    3526                 :          0 :                              opaque_key_exchange_rsp_size + signature_size +
+    3527                 :            :                              hmac_size;
+    3528                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    3529                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    3530                 :          0 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    3531                 :            : 
+    3532                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    3533                 :          0 :         spdm_response->header.request_response_code =
+    3534                 :            :             SPDM_KEY_EXCHANGE_RSP;
+    3535                 :          0 :         spdm_response->header.param1 = 0;
+    3536                 :          0 :         spdm_response->rsp_session_id =
+    3537                 :          0 :             libspdm_allocate_rsp_session_id(spdm_context, false);
+    3538                 :          0 :         spdm_response->mut_auth_requested =
+    3539                 :            :             SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_GET_DIGESTS;
+    3540                 :          0 :         spdm_response->req_slot_id_param = 0xF;
+    3541                 :          0 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    3542                 :          0 :                                   spdm_response->random_data);
+    3543                 :          0 :         ptr = (void *)(spdm_response + 1);
+    3544                 :          0 :         dhe_context = libspdm_dhe_new(
+    3545                 :          0 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    3546                 :            :                 m_libspdm_use_dhe_algo,
+    3547                 :            :                 true);
+    3548                 :          0 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+    3549                 :            :                                  &dhe_key_size);
+    3550                 :          0 :         final_key_size = sizeof(final_key);
+    3551                 :          0 :         libspdm_dhe_compute_key(
+    3552                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    3553                 :          0 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    3554                 :            :             sizeof(spdm_key_exchange_request_t),
+    3555                 :            :             dhe_key_size, final_key, &final_key_size);
+    3556                 :          0 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    3557                 :          0 :         ptr += dhe_key_size;
+    3558                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    3559                 :            :          * ptr += hash_size;*/
+    3560                 :          0 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    3561                 :          0 :         ptr += sizeof(uint16_t);
+    3562                 :          0 :         libspdm_build_opaque_data_version_selection_data(
+    3563                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    3564                 :          0 :         ptr += opaque_key_exchange_rsp_size;
+    3565                 :          0 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3566                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    3567                 :            :                                                         &data_size, NULL, NULL);
+    3568                 :          0 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    3569                 :            :                          sizeof(m_libspdm_local_buffer)
+    3570                 :          0 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    3571                 :            :                             m_libspdm_local_buffer),
+    3572                 :          0 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    3573                 :          0 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    3574                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    3575                 :            :                        m_libspdm_local_buffer_size));
+    3576                 :          0 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    3577                 :          0 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    3578                 :          0 :         cert_buffer =  (uint8_t *)data;
+    3579                 :          0 :         cert_buffer_size = data_size;
+    3580                 :          0 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    3581                 :            :                          cert_buffer_hash);
+    3582                 :            :         /* transcript.message_a size is 0*/
+    3583                 :          0 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    3584                 :          0 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    3585                 :            :                                       m_libspdm_local_buffer_size);
+    3586                 :          0 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3587                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    3588                 :          0 :         free(data);
+    3589                 :          0 :         libspdm_responder_data_sign(
+    3590                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    3591                 :            :             spdm_context,
+    3592                 :            : #endif
+    3593                 :          0 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    3594                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    3595                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    3596                 :          0 :                 false, libspdm_get_managed_buffer(&th_curr),
+    3597                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    3598                 :            :                 &signature_size);
+    3599                 :          0 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    3600                 :            :                          sizeof(m_libspdm_local_buffer)
+    3601                 :          0 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    3602                 :            :                             m_libspdm_local_buffer),
+    3603                 :            :                          ptr, signature_size);
+    3604                 :          0 :         m_libspdm_local_buffer_size += signature_size;
+    3605                 :          0 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    3606                 :          0 :         ptr += signature_size;
+    3607                 :          0 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3608                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    3609                 :            :                          th_curr_hash_data);
+    3610                 :          0 :         bin_str0_size = sizeof(bin_str0);
+    3611                 :          0 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    3612                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    3613                 :          0 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    3614                 :            :                            &bin_str0_size);
+    3615                 :          0 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    3616                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    3617                 :          0 :         bin_str2_size = sizeof(bin_str2);
+    3618                 :          0 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    3619                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    3620                 :          0 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    3621                 :            :                            bin_str2, &bin_str2_size);
+    3622                 :          0 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    3623                 :            :                             bin_str2, bin_str2_size,
+    3624                 :            :                             response_handshake_secret, hash_size);
+    3625                 :          0 :         bin_str7_size = sizeof(bin_str7);
+    3626                 :          0 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    3627                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    3628                 :          0 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    3629                 :            :                            &bin_str7_size);
+    3630                 :          0 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    3631                 :            :                             hash_size, bin_str7, bin_str7_size,
+    3632                 :            :                             response_finished_key, hash_size);
+    3633                 :          0 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3634                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    3635                 :          0 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    3636                 :            :                          response_finished_key, hash_size, ptr);
+    3637                 :          0 :         ptr += hmac_size;
+    3638                 :            : 
+    3639                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    3640                 :            :                                               false, spdm_response_size,
+    3641                 :            :                                               spdm_response, response_size,
+    3642                 :            :                                               response);
+    3643                 :            :     }
+    3644                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+    3645                 :            : 
+    3646                 :          1 :     case 0x1A: {
+    3647                 :            :         spdm_key_exchange_response_t *spdm_response;
+    3648                 :            :         size_t dhe_key_size;
+    3649                 :            :         uint32_t hash_size;
+    3650                 :            :         size_t signature_size;
+    3651                 :            :         uint32_t hmac_size;
+    3652                 :            :         uint8_t *ptr;
+    3653                 :            :         void *dhe_context;
+    3654                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    3655                 :            :         size_t final_key_size;
+    3656                 :            :         size_t opaque_key_exchange_rsp_size;
+    3657                 :            :         void *data;
+    3658                 :            :         size_t data_size;
+    3659                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    3660                 :            :         uint8_t *cert_buffer;
+    3661                 :            :         size_t cert_buffer_size;
+    3662                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    3663                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    3664                 :            :         uint8_t bin_str0[128];
+    3665                 :            :         size_t bin_str0_size;
+    3666                 :            :         uint8_t bin_str2[128];
+    3667                 :            :         size_t bin_str2_size;
+    3668                 :            :         uint8_t bin_str7[128];
+    3669                 :            :         size_t bin_str7_size;
+    3670                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    3671                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    3672                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    3673                 :            :         size_t spdm_response_size;
+    3674                 :            :         size_t transport_header_size;
+    3675                 :            : 
+    3676                 :            :         ((libspdm_context_t *)spdm_context)
+    3677                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    3678                 :            :             m_libspdm_use_asym_algo;
+    3679                 :            :         ((libspdm_context_t *)spdm_context)
+    3680                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    3681                 :            :             m_libspdm_use_hash_algo;
+    3682                 :            :         ((libspdm_context_t *)spdm_context)
+    3683                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    3684                 :            :             m_libspdm_use_dhe_algo;
+    3685                 :            :         ((libspdm_context_t *)spdm_context)
+    3686                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    3687                 :            :             m_libspdm_use_measurement_hash_algo;
+    3688                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    3689                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3690                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3691                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    3692                 :          1 :         opaque_key_exchange_rsp_size =
+    3693                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    3694                 :            :                 spdm_context);
+    3695                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    3696                 :          1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
+    3697                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+    3698                 :            :                              hmac_size;
+    3699                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    3700                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    3701                 :          1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    3702                 :            : 
+    3703                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    3704                 :          1 :         spdm_response->header.request_response_code =
+    3705                 :            :             SPDM_KEY_EXCHANGE_RSP;
+    3706                 :          1 :         spdm_response->header.param1 = 0;
+    3707                 :          1 :         spdm_response->rsp_session_id =
+    3708                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
+    3709                 :            :         /* Illegal combination. At most one bit can be set. */
+    3710                 :          1 :         spdm_response->mut_auth_requested =
+    3711                 :            :             SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED |
+    3712                 :            :             SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_ENCAP_REQUEST;
+    3713                 :          1 :         spdm_response->req_slot_id_param = 0xF;
+    3714                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    3715                 :          1 :                                   spdm_response->random_data);
+    3716                 :          1 :         ptr = (void *)(spdm_response + 1);
+    3717                 :          1 :         dhe_context = libspdm_dhe_new(
+    3718                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    3719                 :            :                 m_libspdm_use_dhe_algo,
+    3720                 :            :                 true);
+    3721                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+    3722                 :            :                                  &dhe_key_size);
+    3723                 :          1 :         final_key_size = sizeof(final_key);
+    3724                 :          1 :         libspdm_dhe_compute_key(
+    3725                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    3726                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    3727                 :            :             sizeof(spdm_key_exchange_request_t),
+    3728                 :            :             dhe_key_size, final_key, &final_key_size);
+    3729                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    3730                 :          1 :         ptr += dhe_key_size;
+    3731                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    3732                 :            :          * ptr += hash_size;*/
+    3733                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    3734                 :          1 :         ptr += sizeof(uint16_t);
+    3735                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    3736                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    3737                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+    3738                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3739                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    3740                 :            :                                                         &data_size, NULL, NULL);
+    3741                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    3742                 :            :                          sizeof(m_libspdm_local_buffer)
+    3743                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    3744                 :            :                             m_libspdm_local_buffer),
+    3745                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    3746                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    3747                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    3748                 :            :                        m_libspdm_local_buffer_size));
+    3749                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    3750                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    3751                 :          1 :         cert_buffer =  (uint8_t *)data;
+    3752                 :          1 :         cert_buffer_size = data_size;
+    3753                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    3754                 :            :                          cert_buffer_hash);
+    3755                 :            :         /* transcript.message_a size is 0*/
+    3756                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    3757                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    3758                 :            :                                       m_libspdm_local_buffer_size);
+    3759                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3760                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    3761                 :          1 :         free(data);
+    3762                 :          1 :         libspdm_responder_data_sign(
+    3763                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    3764                 :            :             spdm_context,
+    3765                 :            : #endif
+    3766                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    3767                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    3768                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    3769                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+    3770                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    3771                 :            :                 &signature_size);
+    3772                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    3773                 :            :                          sizeof(m_libspdm_local_buffer)
+    3774                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    3775                 :            :                             m_libspdm_local_buffer),
+    3776                 :            :                          ptr, signature_size);
+    3777                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+    3778                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    3779                 :          1 :         ptr += signature_size;
+    3780                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3781                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    3782                 :            :                          th_curr_hash_data);
+    3783                 :          1 :         bin_str0_size = sizeof(bin_str0);
+    3784                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    3785                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    3786                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    3787                 :            :                            &bin_str0_size);
+    3788                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    3789                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    3790                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    3791                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    3792                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    3793                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    3794                 :            :                            bin_str2, &bin_str2_size);
+    3795                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    3796                 :            :                             bin_str2, bin_str2_size,
+    3797                 :            :                             response_handshake_secret, hash_size);
+    3798                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    3799                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    3800                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    3801                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    3802                 :            :                            &bin_str7_size);
+    3803                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    3804                 :            :                             hash_size, bin_str7, bin_str7_size,
+    3805                 :            :                             response_finished_key, hash_size);
+    3806                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3807                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    3808                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    3809                 :            :                          response_finished_key, hash_size, ptr);
+    3810                 :          1 :         ptr += hmac_size;
+    3811                 :            : 
+    3812                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    3813                 :            :                                               false, spdm_response_size,
+    3814                 :            :                                               spdm_response, response_size,
+    3815                 :            :                                               response);
+    3816                 :            :     }
+    3817                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    3818                 :            : 
+    3819                 :          1 :     case 0x1B: {
+    3820                 :            :         spdm_key_exchange_response_t *spdm_response;
+    3821                 :            :         size_t dhe_key_size;
+    3822                 :            :         uint32_t hash_size;
+    3823                 :            :         size_t signature_size;
+    3824                 :            :         uint32_t hmac_size;
+    3825                 :            :         uint8_t *ptr;
+    3826                 :            :         void *dhe_context;
+    3827                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    3828                 :            :         size_t final_key_size;
+    3829                 :            :         size_t opaque_key_exchange_rsp_size;
+    3830                 :            :         void *data;
+    3831                 :            :         size_t data_size;
+    3832                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    3833                 :            :         uint8_t *cert_buffer;
+    3834                 :            :         size_t cert_buffer_size;
+    3835                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    3836                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    3837                 :            :         uint8_t bin_str0[128];
+    3838                 :            :         size_t bin_str0_size;
+    3839                 :            :         uint8_t bin_str2[128];
+    3840                 :            :         size_t bin_str2_size;
+    3841                 :            :         uint8_t bin_str7[128];
+    3842                 :            :         size_t bin_str7_size;
+    3843                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    3844                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    3845                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    3846                 :            :         size_t spdm_response_size;
+    3847                 :            :         size_t transport_header_size;
+    3848                 :            : 
+    3849                 :            :         ((libspdm_context_t *)spdm_context)
+    3850                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    3851                 :            :             m_libspdm_use_asym_algo;
+    3852                 :            :         ((libspdm_context_t *)spdm_context)
+    3853                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    3854                 :            :             m_libspdm_use_hash_algo;
+    3855                 :            :         ((libspdm_context_t *)spdm_context)
+    3856                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    3857                 :            :             m_libspdm_use_dhe_algo;
+    3858                 :            :         ((libspdm_context_t *)spdm_context)
+    3859                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    3860                 :            :             m_libspdm_use_measurement_hash_algo;
+    3861                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    3862                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3863                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3864                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    3865                 :          1 :         opaque_key_exchange_rsp_size =
+    3866                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    3867                 :            :                 spdm_context);
+    3868                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    3869                 :          1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
+    3870                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+    3871                 :            :                              hmac_size;
+    3872                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    3873                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    3874                 :          1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    3875                 :            : 
+    3876                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    3877                 :          1 :         spdm_response->header.request_response_code =
+    3878                 :            :             SPDM_KEY_EXCHANGE_RSP;
+    3879                 :          1 :         spdm_response->header.param1 = 0;
+    3880                 :          1 :         spdm_response->rsp_session_id =
+    3881                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
+    3882                 :            :         /* Illegal combination. At most one bit can be set. */
+    3883                 :          1 :         spdm_response->mut_auth_requested =
+    3884                 :            :             SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED |
+    3885                 :            :             SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_GET_DIGESTS;
+    3886                 :          1 :         spdm_response->req_slot_id_param = 0xF;
+    3887                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    3888                 :          1 :                                   spdm_response->random_data);
+    3889                 :          1 :         ptr = (void *)(spdm_response + 1);
+    3890                 :          1 :         dhe_context = libspdm_dhe_new(
+    3891                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    3892                 :            :                 m_libspdm_use_dhe_algo,
+    3893                 :            :                 true);
+    3894                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+    3895                 :            :                                  &dhe_key_size);
+    3896                 :          1 :         final_key_size = sizeof(final_key);
+    3897                 :          1 :         libspdm_dhe_compute_key(
+    3898                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    3899                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    3900                 :            :             sizeof(spdm_key_exchange_request_t),
+    3901                 :            :             dhe_key_size, final_key, &final_key_size);
+    3902                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    3903                 :          1 :         ptr += dhe_key_size;
+    3904                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    3905                 :            :          * ptr += hash_size;*/
+    3906                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    3907                 :          1 :         ptr += sizeof(uint16_t);
+    3908                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    3909                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    3910                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+    3911                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3912                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    3913                 :            :                                                         &data_size, NULL, NULL);
+    3914                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    3915                 :            :                          sizeof(m_libspdm_local_buffer)
+    3916                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    3917                 :            :                             m_libspdm_local_buffer),
+    3918                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    3919                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    3920                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    3921                 :            :                        m_libspdm_local_buffer_size));
+    3922                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    3923                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    3924                 :          1 :         cert_buffer =  (uint8_t *)data;
+    3925                 :          1 :         cert_buffer_size = data_size;
+    3926                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    3927                 :            :                          cert_buffer_hash);
+    3928                 :            :         /* transcript.message_a size is 0*/
+    3929                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    3930                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    3931                 :            :                                       m_libspdm_local_buffer_size);
+    3932                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3933                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    3934                 :          1 :         free(data);
+    3935                 :          1 :         libspdm_responder_data_sign(
+    3936                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    3937                 :            :             spdm_context,
+    3938                 :            : #endif
+    3939                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    3940                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    3941                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    3942                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+    3943                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    3944                 :            :                 &signature_size);
+    3945                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    3946                 :            :                          sizeof(m_libspdm_local_buffer)
+    3947                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    3948                 :            :                             m_libspdm_local_buffer),
+    3949                 :            :                          ptr, signature_size);
+    3950                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+    3951                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    3952                 :          1 :         ptr += signature_size;
+    3953                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3954                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    3955                 :            :                          th_curr_hash_data);
+    3956                 :          1 :         bin_str0_size = sizeof(bin_str0);
+    3957                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    3958                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    3959                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    3960                 :            :                            &bin_str0_size);
+    3961                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    3962                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    3963                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    3964                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    3965                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    3966                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    3967                 :            :                            bin_str2, &bin_str2_size);
+    3968                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    3969                 :            :                             bin_str2, bin_str2_size,
+    3970                 :            :                             response_handshake_secret, hash_size);
+    3971                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    3972                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    3973                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    3974                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    3975                 :            :                            &bin_str7_size);
+    3976                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    3977                 :            :                             hash_size, bin_str7, bin_str7_size,
+    3978                 :            :                             response_finished_key, hash_size);
+    3979                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3980                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    3981                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    3982                 :            :                          response_finished_key, hash_size, ptr);
+    3983                 :          1 :         ptr += hmac_size;
+    3984                 :            : 
+    3985                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    3986                 :            :                                               false, spdm_response_size,
+    3987                 :            :                                               spdm_response, response_size,
+    3988                 :            :                                               response);
+    3989                 :            :     }
+    3990                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    3991                 :            : 
+    3992                 :          1 :     case 0x1C: {
+    3993                 :            :         spdm_key_exchange_response_t *spdm_response;
+    3994                 :            :         size_t dhe_key_size;
+    3995                 :            :         uint32_t hash_size;
+    3996                 :            :         size_t signature_size;
+    3997                 :            :         uint32_t hmac_size;
+    3998                 :            :         uint8_t *ptr;
+    3999                 :            :         void *dhe_context;
+    4000                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    4001                 :            :         size_t final_key_size;
+    4002                 :            :         size_t opaque_key_exchange_rsp_size;
+    4003                 :            :         void *data;
+    4004                 :            :         size_t data_size;
+    4005                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    4006                 :            :         uint8_t *cert_buffer;
+    4007                 :            :         size_t cert_buffer_size;
+    4008                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    4009                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    4010                 :            :         uint8_t bin_str0[128];
+    4011                 :            :         size_t bin_str0_size;
+    4012                 :            :         uint8_t bin_str2[128];
+    4013                 :            :         size_t bin_str2_size;
+    4014                 :            :         uint8_t bin_str7[128];
+    4015                 :            :         size_t bin_str7_size;
+    4016                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    4017                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    4018                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    4019                 :            :         size_t spdm_response_size;
+    4020                 :            :         size_t transport_header_size;
+    4021                 :            : 
+    4022                 :            :         ((libspdm_context_t *)spdm_context)
+    4023                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    4024                 :            :             m_libspdm_use_asym_algo;
+    4025                 :            :         ((libspdm_context_t *)spdm_context)
+    4026                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    4027                 :            :             m_libspdm_use_hash_algo;
+    4028                 :            :         ((libspdm_context_t *)spdm_context)
+    4029                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    4030                 :            :             m_libspdm_use_dhe_algo;
+    4031                 :            :         ((libspdm_context_t *)spdm_context)
+    4032                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    4033                 :            :             m_libspdm_use_measurement_hash_algo;
+    4034                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    4035                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    4036                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    4037                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    4038                 :          1 :         opaque_key_exchange_rsp_size =
+    4039                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    4040                 :            :                 spdm_context);
+    4041                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    4042                 :          1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
+    4043                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+    4044                 :            :                              hmac_size;
+    4045                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    4046                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    4047                 :          1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    4048                 :            : 
+    4049                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    4050                 :          1 :         spdm_response->header.request_response_code =
+    4051                 :            :             SPDM_KEY_EXCHANGE_RSP;
+    4052                 :          1 :         spdm_response->header.param1 = 0;
+    4053                 :          1 :         spdm_response->rsp_session_id =
+    4054                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
+    4055                 :            :         /* Illegal combination. At most one bit can be set. */
+    4056                 :          1 :         spdm_response->mut_auth_requested =
+    4057                 :            :             SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_ENCAP_REQUEST |
+    4058                 :            :             SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_GET_DIGESTS;
+    4059                 :          1 :         spdm_response->req_slot_id_param = 0xF;
+    4060                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    4061                 :          1 :                                   spdm_response->random_data);
+    4062                 :          1 :         ptr = (void *)(spdm_response + 1);
+    4063                 :          1 :         dhe_context = libspdm_dhe_new(
+    4064                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    4065                 :            :                 m_libspdm_use_dhe_algo,
+    4066                 :            :                 true);
+    4067                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+    4068                 :            :                                  &dhe_key_size);
+    4069                 :          1 :         final_key_size = sizeof(final_key);
+    4070                 :          1 :         libspdm_dhe_compute_key(
+    4071                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    4072                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    4073                 :            :             sizeof(spdm_key_exchange_request_t),
+    4074                 :            :             dhe_key_size, final_key, &final_key_size);
+    4075                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    4076                 :          1 :         ptr += dhe_key_size;
+    4077                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    4078                 :            :          * ptr += hash_size;*/
+    4079                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    4080                 :          1 :         ptr += sizeof(uint16_t);
+    4081                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    4082                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    4083                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+    4084                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    4085                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    4086                 :            :                                                         &data_size, NULL, NULL);
+    4087                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    4088                 :            :                          sizeof(m_libspdm_local_buffer)
+    4089                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    4090                 :            :                             m_libspdm_local_buffer),
+    4091                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    4092                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    4093                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    4094                 :            :                        m_libspdm_local_buffer_size));
+    4095                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    4096                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    4097                 :          1 :         cert_buffer =  (uint8_t *)data;
+    4098                 :          1 :         cert_buffer_size = data_size;
+    4099                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    4100                 :            :                          cert_buffer_hash);
+    4101                 :            :         /* transcript.message_a size is 0*/
+    4102                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    4103                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    4104                 :            :                                       m_libspdm_local_buffer_size);
+    4105                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    4106                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    4107                 :          1 :         free(data);
+    4108                 :          1 :         libspdm_responder_data_sign(
+    4109                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    4110                 :            :             spdm_context,
+    4111                 :            : #endif
+    4112                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    4113                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    4114                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    4115                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+    4116                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    4117                 :            :                 &signature_size);
+    4118                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    4119                 :            :                          sizeof(m_libspdm_local_buffer)
+    4120                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    4121                 :            :                             m_libspdm_local_buffer),
+    4122                 :            :                          ptr, signature_size);
+    4123                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+    4124                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    4125                 :          1 :         ptr += signature_size;
+    4126                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    4127                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    4128                 :            :                          th_curr_hash_data);
+    4129                 :          1 :         bin_str0_size = sizeof(bin_str0);
+    4130                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    4131                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    4132                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    4133                 :            :                            &bin_str0_size);
+    4134                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    4135                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    4136                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    4137                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    4138                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    4139                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    4140                 :            :                            bin_str2, &bin_str2_size);
+    4141                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    4142                 :            :                             bin_str2, bin_str2_size,
+    4143                 :            :                             response_handshake_secret, hash_size);
+    4144                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    4145                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    4146                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    4147                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    4148                 :            :                            &bin_str7_size);
+    4149                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    4150                 :            :                             hash_size, bin_str7, bin_str7_size,
+    4151                 :            :                             response_finished_key, hash_size);
+    4152                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    4153                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    4154                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    4155                 :            :                          response_finished_key, hash_size, ptr);
+    4156                 :          1 :         ptr += hmac_size;
+    4157                 :            : 
+    4158                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    4159                 :            :                                               false, spdm_response_size,
+    4160                 :            :                                               spdm_response, response_size,
+    4161                 :            :                                               response);
+    4162                 :            :     }
+    4163                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    4164                 :            : 
+    4165                 :          0 :     case 0x1D: {
+    4166                 :            :         spdm_key_exchange_response_t *spdm_response;
+    4167                 :            :         size_t dhe_key_size;
+    4168                 :            :         uint32_t hash_size;
+    4169                 :            :         size_t signature_size;
+    4170                 :            :         uint32_t hmac_size;
+    4171                 :            :         uint8_t *ptr;
+    4172                 :            :         void *dhe_context;
+    4173                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    4174                 :            :         size_t final_key_size;
+    4175                 :            :         size_t opaque_key_exchange_rsp_size;
+    4176                 :            :         void *data;
+    4177                 :            :         size_t data_size;
+    4178                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    4179                 :            :         uint8_t *cert_buffer;
+    4180                 :            :         size_t cert_buffer_size;
+    4181                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    4182                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    4183                 :            :         uint8_t bin_str0[128];
+    4184                 :            :         size_t bin_str0_size;
+    4185                 :            :         uint8_t bin_str2[128];
+    4186                 :            :         size_t bin_str2_size;
+    4187                 :            :         uint8_t bin_str7[128];
+    4188                 :            :         size_t bin_str7_size;
+    4189                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    4190                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    4191                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    4192                 :            :         size_t spdm_response_size;
+    4193                 :            :         size_t transport_header_size;
+    4194                 :            : 
+    4195                 :          0 :         ((libspdm_context_t *)spdm_context)->connection_info.algorithm.base_asym_algo =
+    4196                 :            :             m_libspdm_use_asym_algo;
+    4197                 :          0 :         ((libspdm_context_t *)spdm_context)->connection_info.algorithm.base_hash_algo =
+    4198                 :            :             m_libspdm_use_hash_algo;
+    4199                 :          0 :         ((libspdm_context_t *)spdm_context)->connection_info.algorithm.dhe_named_group =
+    4200                 :            :             m_libspdm_use_dhe_algo;
+    4201                 :          0 :         ((libspdm_context_t *)spdm_context)->connection_info.algorithm.measurement_hash_algo =
+    4202                 :            :             m_libspdm_use_measurement_hash_algo;
+    4203                 :          0 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    4204                 :          0 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    4205                 :          0 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    4206                 :          0 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    4207                 :          0 :         opaque_key_exchange_rsp_size =
+    4208                 :          0 :             libspdm_get_opaque_data_version_selection_data_size(spdm_context);
+    4209                 :          0 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    4210                 :          0 :                              dhe_key_size + 0 + sizeof(uint16_t) +
+    4211                 :          0 :                              opaque_key_exchange_rsp_size + signature_size +
+    4212                 :            :                              hmac_size;
+    4213                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    4214                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    4215                 :            : 
+    4216                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    4217                 :          0 :         spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
+    4218                 :          0 :         spdm_response->header.param1 = 0;
+    4219                 :          0 :         spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
+    4220                 :          0 :         spdm_response->mut_auth_requested = 0;
+    4221                 :          0 :         spdm_response->req_slot_id_param = 0;
+    4222                 :          0 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_response->random_data);
+    4223                 :          0 :         ptr = (void *)(spdm_response + 1);
+    4224                 :          0 :         dhe_context = libspdm_dhe_new(
+    4225                 :          0 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    4226                 :            :                 m_libspdm_use_dhe_algo, true);
+    4227                 :          0 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
+    4228                 :          0 :         final_key_size = sizeof(final_key);
+    4229                 :          0 :         libspdm_dhe_compute_key(
+    4230                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    4231                 :          0 :             (uint8_t *)&m_libspdm_local_buffer[0] + sizeof(spdm_key_exchange_request_t),
+    4232                 :            :             dhe_key_size, final_key, &final_key_size);
+    4233                 :          0 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    4234                 :          0 :         ptr += dhe_key_size;
+    4235                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    4236                 :            :          * ptr += hash_size;*/
+    4237                 :          0 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    4238                 :          0 :         ptr += sizeof(uint16_t);
+    4239                 :          0 :         libspdm_build_opaque_data_version_selection_data(
+    4240                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    4241                 :          0 :         ptr += opaque_key_exchange_rsp_size;
+    4242                 :          0 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    4243                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    4244                 :            :                                                         &data_size, NULL, NULL);
+    4245                 :          0 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    4246                 :            :                          sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
+    4247                 :          0 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    4248                 :          0 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    4249                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer (0x%zx):\n",
+    4250                 :            :                        m_libspdm_local_buffer_size));
+    4251                 :          0 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    4252                 :          0 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    4253                 :          0 :         cert_buffer = (uint8_t *)data;
+    4254                 :          0 :         cert_buffer_size = data_size;
+    4255                 :          0 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    4256                 :            :                          cert_buffer_hash);
+    4257                 :            :         /* transcript.message_a size is 0*/
+    4258                 :          0 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    4259                 :          0 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    4260                 :            :                                       m_libspdm_local_buffer_size);
+    4261                 :          0 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    4262                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    4263                 :          0 :         free(data);
+    4264                 :          0 :         libspdm_responder_data_sign(
+    4265                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    4266                 :            :             spdm_context,
+    4267                 :            : #endif
+    4268                 :          0 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    4269                 :            :                 SPDM_KEY_EXCHANGE_RSP, m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    4270                 :          0 :                 false, libspdm_get_managed_buffer(&th_curr),
+    4271                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr, &signature_size);
+    4272                 :          0 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    4273                 :            :                          sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
+    4274                 :            :                          ptr, signature_size);
+    4275                 :          0 :         m_libspdm_local_buffer_size += signature_size;
+    4276                 :          0 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    4277                 :          0 :         ptr += signature_size;
+    4278                 :          0 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    4279                 :            :                          libspdm_get_managed_buffer_size(&th_curr), th_curr_hash_data);
+    4280                 :          0 :         bin_str0_size = sizeof(bin_str0);
+    4281                 :          0 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    4282                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    4283                 :          0 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0, &bin_str0_size);
+    4284                 :          0 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    4285                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    4286                 :          0 :         bin_str2_size = sizeof(bin_str2);
+    4287                 :          0 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    4288                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    4289                 :          0 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    4290                 :            :                            bin_str2, &bin_str2_size);
+    4291                 :          0 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    4292                 :            :                             bin_str2, bin_str2_size,
+    4293                 :            :                             response_handshake_secret, hash_size);
+    4294                 :          0 :         bin_str7_size = sizeof(bin_str7);
+    4295                 :          0 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    4296                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    4297                 :          0 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    4298                 :            :                            &bin_str7_size);
+    4299                 :          0 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    4300                 :            :                             hash_size, bin_str7, bin_str7_size,
+    4301                 :            :                             response_finished_key, hash_size);
+    4302                 :          0 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    4303                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    4304                 :          0 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    4305                 :            :                          response_finished_key, hash_size, ptr);
+    4306                 :          0 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    4307                 :            :                          sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
+    4308                 :            :                          ptr, hmac_size);
+    4309                 :          0 :         m_libspdm_local_buffer_size += hmac_size;
+    4310                 :          0 :         ptr += hmac_size;
+    4311                 :            : 
+    4312                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    4313                 :            :                                               false, spdm_response_size,
+    4314                 :            :                                               spdm_response, response_size,
+    4315                 :            :                                               response);
+    4316                 :            :     }
+    4317                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+    4318                 :          0 :     case 0x1E: {
+    4319                 :            :         spdm_key_exchange_response_t *spdm_response;
+    4320                 :            :         size_t dhe_key_size;
+    4321                 :            :         uint32_t hash_size;
+    4322                 :            :         size_t signature_size;
+    4323                 :            :         uint32_t hmac_size;
+    4324                 :            :         uint8_t *ptr;
+    4325                 :            :         void *dhe_context;
+    4326                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    4327                 :            :         size_t final_key_size;
+    4328                 :            :         size_t opaque_key_exchange_rsp_size;
+    4329                 :            :         void *data;
+    4330                 :            :         size_t data_size;
+    4331                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    4332                 :            :         uint8_t *cert_buffer;
+    4333                 :            :         size_t cert_buffer_size;
+    4334                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    4335                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    4336                 :            :         uint8_t bin_str0[128];
+    4337                 :            :         size_t bin_str0_size;
+    4338                 :            :         uint8_t bin_str2[128];
+    4339                 :            :         size_t bin_str2_size;
+    4340                 :            :         uint8_t bin_str7[128];
+    4341                 :            :         size_t bin_str7_size;
+    4342                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    4343                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    4344                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    4345                 :            :         size_t spdm_response_size;
+    4346                 :            :         size_t transport_header_size;
+    4347                 :            : 
+    4348                 :          0 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
+    4349                 :            :             SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4350                 :            :         ((libspdm_context_t *)spdm_context)
+    4351                 :          0 :         ->connection_info.algorithm.base_asym_algo =
+    4352                 :            :             m_libspdm_use_asym_algo;
+    4353                 :            :         ((libspdm_context_t *)spdm_context)
+    4354                 :          0 :         ->connection_info.algorithm.base_hash_algo =
+    4355                 :            :             m_libspdm_use_hash_algo;
+    4356                 :            :         ((libspdm_context_t *)spdm_context)
+    4357                 :          0 :         ->connection_info.algorithm.dhe_named_group =
+    4358                 :            :             m_libspdm_use_dhe_algo;
+    4359                 :            :         ((libspdm_context_t *)spdm_context)
+    4360                 :          0 :         ->connection_info.algorithm.measurement_hash_algo =
+    4361                 :            :             m_libspdm_use_measurement_hash_algo;
+    4362                 :          0 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    4363                 :          0 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    4364                 :          0 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    4365                 :          0 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    4366                 :          0 :         opaque_key_exchange_rsp_size =
+    4367                 :          0 :             libspdm_get_opaque_data_version_selection_data_size(
+    4368                 :            :                 spdm_context);
+    4369                 :          0 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    4370                 :          0 :                              dhe_key_size + 0 + sizeof(uint16_t) +
+    4371                 :          0 :                              opaque_key_exchange_rsp_size + signature_size +
+    4372                 :            :                              hmac_size;
+    4373                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    4374                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    4375                 :            : 
+    4376                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+    4377                 :          0 :         spdm_response->header.request_response_code =
+    4378                 :            :             SPDM_KEY_EXCHANGE_RSP;
+    4379                 :          0 :         spdm_response->header.param1 = 0;
+    4380                 :          0 :         spdm_response->rsp_session_id =
+    4381                 :          0 :             libspdm_allocate_rsp_session_id(spdm_context, false);
+    4382                 :          0 :         spdm_response->mut_auth_requested = 0;
+    4383                 :          0 :         spdm_response->req_slot_id_param = 0;
+    4384                 :          0 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    4385                 :          0 :                                   spdm_response->random_data);
+    4386                 :          0 :         ptr = (void *)(spdm_response + 1);
+    4387                 :          0 :         dhe_context = libspdm_dhe_new(
+    4388                 :          0 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    4389                 :            :                 m_libspdm_use_dhe_algo,
+    4390                 :            :                 true);
+    4391                 :          0 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+    4392                 :            :                                  &dhe_key_size);
+    4393                 :          0 :         final_key_size = sizeof(final_key);
+    4394                 :          0 :         libspdm_dhe_compute_key(
+    4395                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    4396                 :          0 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    4397                 :            :             sizeof(spdm_key_exchange_request_t),
+    4398                 :            :             dhe_key_size, final_key, &final_key_size);
+    4399                 :          0 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    4400                 :          0 :         ptr += dhe_key_size;
+    4401                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    4402                 :            :          * ptr += hash_size;*/
+    4403                 :          0 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    4404                 :          0 :         ptr += sizeof(uint16_t);
+    4405                 :          0 :         libspdm_build_opaque_data_version_selection_data(
+    4406                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    4407                 :          0 :         ptr += opaque_key_exchange_rsp_size;
+    4408                 :          0 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    4409                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    4410                 :            :                                                         &data_size, NULL, NULL);
+    4411                 :          0 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    4412                 :            :                          sizeof(m_libspdm_local_buffer)
+    4413                 :          0 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    4414                 :            :                             m_libspdm_local_buffer),
+    4415                 :          0 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    4416                 :          0 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    4417                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    4418                 :            :                        m_libspdm_local_buffer_size));
+    4419                 :          0 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    4420                 :          0 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    4421                 :          0 :         cert_buffer = (uint8_t *)data;
+    4422                 :          0 :         cert_buffer_size = data_size;
+    4423                 :          0 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    4424                 :            :                          cert_buffer_hash);
+    4425                 :            :         /* transcript.message_a size is 0*/
+    4426                 :          0 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    4427                 :          0 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    4428                 :            :                                       m_libspdm_local_buffer_size);
+    4429                 :          0 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    4430                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    4431                 :          0 :         free(data);
+    4432                 :          0 :         libspdm_responder_data_sign(
+    4433                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    4434                 :            :             spdm_context,
+    4435                 :            : #endif
+    4436                 :          0 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    4437                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    4438                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    4439                 :          0 :                 false, libspdm_get_managed_buffer(&th_curr),
+    4440                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    4441                 :            :                 &signature_size);
+    4442                 :          0 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    4443                 :            :                          sizeof(m_libspdm_local_buffer)
+    4444                 :          0 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    4445                 :            :                             m_libspdm_local_buffer),
+    4446                 :            :                          ptr, signature_size);
+    4447                 :          0 :         m_libspdm_local_buffer_size += signature_size;
+    4448                 :          0 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    4449                 :          0 :         ptr += signature_size;
+    4450                 :          0 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    4451                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    4452                 :            :                          th_curr_hash_data);
+    4453                 :          0 :         bin_str0_size = sizeof(bin_str0);
+    4454                 :          0 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    4455                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    4456                 :          0 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    4457                 :            :                            &bin_str0_size);
+    4458                 :          0 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    4459                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    4460                 :          0 :         bin_str2_size = sizeof(bin_str2);
+    4461                 :          0 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    4462                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    4463                 :          0 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    4464                 :            :                            bin_str2, &bin_str2_size);
+    4465                 :          0 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    4466                 :            :                             bin_str2, bin_str2_size,
+    4467                 :            :                             response_handshake_secret, hash_size);
+    4468                 :          0 :         bin_str7_size = sizeof(bin_str7);
+    4469                 :          0 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    4470                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    4471                 :          0 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    4472                 :            :                            &bin_str7_size);
+    4473                 :          0 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    4474                 :            :                             hash_size, bin_str7, bin_str7_size,
+    4475                 :            :                             response_finished_key, hash_size);
+    4476                 :          0 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    4477                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    4478                 :          0 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    4479                 :            :                          response_finished_key, hash_size, ptr);
+    4480                 :          0 :         ptr += hmac_size;
+    4481                 :            : 
+    4482                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    4483                 :            :                                               false, spdm_response_size,
+    4484                 :            :                                               spdm_response, response_size,
+    4485                 :            :                                               response);
+    4486                 :            :     }
+    4487                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+    4488                 :            : 
+    4489                 :          1 :     case 0x1F: {
+    4490                 :            :         spdm_key_exchange_response_t *spdm_response;
+    4491                 :            :         size_t dhe_key_size;
+    4492                 :            :         uint32_t hash_size;
+    4493                 :            :         size_t signature_size;
+    4494                 :            :         uint32_t hmac_size;
+    4495                 :            :         uint8_t *ptr;
+    4496                 :            :         void *dhe_context;
+    4497                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    4498                 :            :         size_t final_key_size;
+    4499                 :            :         size_t opaque_key_exchange_rsp_size;
+    4500                 :            :         void *data;
+    4501                 :            :         size_t data_size;
+    4502                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    4503                 :            :         uint8_t *cert_buffer;
+    4504                 :            :         size_t cert_buffer_size;
+    4505                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    4506                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    4507                 :            :         uint8_t bin_str0[128];
+    4508                 :            :         size_t bin_str0_size;
+    4509                 :            :         uint8_t bin_str2[128];
+    4510                 :            :         size_t bin_str2_size;
+    4511                 :            :         uint8_t bin_str7[128];
+    4512                 :            :         size_t bin_str7_size;
+    4513                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    4514                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    4515                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    4516                 :            :         size_t spdm_response_size;
+    4517                 :            :         size_t transport_header_size;
+    4518                 :            : 
+    4519                 :            :         ((libspdm_context_t *)spdm_context)
+    4520                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    4521                 :            :             m_libspdm_use_asym_algo;
+    4522                 :            :         ((libspdm_context_t *)spdm_context)
+    4523                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    4524                 :            :             m_libspdm_use_hash_algo;
+    4525                 :            :         ((libspdm_context_t *)spdm_context)
+    4526                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    4527                 :            :             m_libspdm_use_dhe_algo;
+    4528                 :            :         ((libspdm_context_t *)spdm_context)
+    4529                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    4530                 :            :             m_libspdm_use_measurement_hash_algo;
+    4531                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    4532                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    4533                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    4534                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    4535                 :          1 :         opaque_key_exchange_rsp_size =
+    4536                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    4537                 :            :                 spdm_context);
+    4538                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    4539                 :          1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
+    4540                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+    4541                 :            :                              hmac_size;
+    4542                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    4543                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    4544                 :          1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    4545                 :            : 
+    4546                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    4547                 :          1 :         spdm_response->header.request_response_code =
+    4548                 :            :             SPDM_KEY_EXCHANGE_RSP;
+    4549                 :          1 :         spdm_response->header.param1 = 0;
+    4550                 :          1 :         spdm_response->rsp_session_id =
+    4551                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
+    4552                 :          1 :         spdm_response->mut_auth_requested =
+    4553                 :            :             SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED;
+    4554                 :          1 :         spdm_response->req_slot_id_param = 9;  /* Invalid SlotID */
+    4555                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    4556                 :          1 :                                   spdm_response->random_data);
+    4557                 :          1 :         ptr = (void *)(spdm_response + 1);
+    4558                 :          1 :         dhe_context = libspdm_dhe_new(
+    4559                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    4560                 :            :                 m_libspdm_use_dhe_algo,
+    4561                 :            :                 true);
+    4562                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+    4563                 :            :                                  &dhe_key_size);
+    4564                 :          1 :         final_key_size = sizeof(final_key);
+    4565                 :          1 :         libspdm_dhe_compute_key(
+    4566                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    4567                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    4568                 :            :             sizeof(spdm_key_exchange_request_t),
+    4569                 :            :             dhe_key_size, final_key, &final_key_size);
+    4570                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    4571                 :          1 :         ptr += dhe_key_size;
+    4572                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    4573                 :            :          * ptr += hash_size;*/
+    4574                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    4575                 :          1 :         ptr += sizeof(uint16_t);
+    4576                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    4577                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    4578                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+    4579                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    4580                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    4581                 :            :                                                         &data_size, NULL, NULL);
+    4582                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    4583                 :            :                          sizeof(m_libspdm_local_buffer)
+    4584                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    4585                 :            :                             m_libspdm_local_buffer),
+    4586                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    4587                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    4588                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    4589                 :            :                        m_libspdm_local_buffer_size));
+    4590                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    4591                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    4592                 :          1 :         cert_buffer =  (uint8_t *)data;
+    4593                 :          1 :         cert_buffer_size = data_size;
+    4594                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    4595                 :            :                          cert_buffer_hash);
+    4596                 :            :         /* transcript.message_a size is 0*/
+    4597                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    4598                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    4599                 :            :                                       m_libspdm_local_buffer_size);
+    4600                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    4601                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    4602                 :          1 :         free(data);
+    4603                 :          1 :         libspdm_responder_data_sign(
+    4604                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    4605                 :            :             spdm_context,
+    4606                 :            : #endif
+    4607                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    4608                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    4609                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    4610                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+    4611                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    4612                 :            :                 &signature_size);
+    4613                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    4614                 :            :                          sizeof(m_libspdm_local_buffer)
+    4615                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    4616                 :            :                             m_libspdm_local_buffer),
+    4617                 :            :                          ptr, signature_size);
+    4618                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+    4619                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    4620                 :          1 :         ptr += signature_size;
+    4621                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    4622                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    4623                 :            :                          th_curr_hash_data);
+    4624                 :          1 :         bin_str0_size = sizeof(bin_str0);
+    4625                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    4626                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    4627                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    4628                 :            :                            &bin_str0_size);
+    4629                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    4630                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    4631                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    4632                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    4633                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    4634                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    4635                 :            :                            bin_str2, &bin_str2_size);
+    4636                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    4637                 :            :                             bin_str2, bin_str2_size,
+    4638                 :            :                             response_handshake_secret, hash_size);
+    4639                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    4640                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    4641                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    4642                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    4643                 :            :                            &bin_str7_size);
+    4644                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    4645                 :            :                             hash_size, bin_str7, bin_str7_size,
+    4646                 :            :                             response_finished_key, hash_size);
+    4647                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    4648                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    4649                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    4650                 :            :                          response_finished_key, hash_size, ptr);
+    4651                 :          1 :         ptr += hmac_size;
+    4652                 :            : 
+    4653                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    4654                 :            :                                               false, spdm_response_size,
+    4655                 :            :                                               spdm_response, response_size,
+    4656                 :            :                                               response);
+    4657                 :            :     }
+    4658                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    4659                 :            : 
+    4660                 :          0 :     default:
+    4661                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+    4662                 :            :     }
+    4663                 :            : }
+    4664                 :            : 
+    4665                 :          1 : static void libspdm_test_requester_key_exchange_err_case1(void **state)
+    4666                 :            : {
+    4667                 :            :     libspdm_return_t status;
+    4668                 :            :     libspdm_test_context_t *spdm_test_context;
+    4669                 :            :     libspdm_context_t *spdm_context;
+    4670                 :            :     uint32_t session_id;
+    4671                 :            :     uint8_t heartbeat_period;
+    4672                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    4673                 :            :     uint8_t slot_id_param;
+    4674                 :            :     void *data;
+    4675                 :            :     size_t data_size;
+    4676                 :            :     void *hash;
+    4677                 :            :     size_t hash_size;
+    4678                 :            : 
+    4679                 :          1 :     spdm_test_context = *state;
+    4680                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4681                 :          1 :     spdm_test_context->case_id = 0x1;
+    4682                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4683                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4684                 :          1 :     spdm_context->connection_info.connection_state =
+    4685                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    4686                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4687                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    4688                 :          1 :     spdm_context->local_context.capability.flags |=
+    4689                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    4690                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    4691                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    4692                 :            :                                                     &data_size, &hash, &hash_size);
+    4693                 :          1 :     libspdm_reset_message_a(spdm_context);
+    4694                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    4695                 :            :         m_libspdm_use_hash_algo;
+    4696                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    4697                 :            :         m_libspdm_use_asym_algo;
+    4698                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    4699                 :            :         m_libspdm_use_dhe_algo;
+    4700                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    4701                 :            :         m_libspdm_use_aead_algo;
+    4702                 :            : 
+    4703                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4704                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    4705                 :            :         data_size;
+    4706                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    4707                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    4708                 :            :                      data, data_size);
+    4709                 :            : #else
+    4710                 :          1 :     libspdm_hash_all(
+    4711                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    4712                 :            :         data, data_size,
+    4713                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    4714                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    4715                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    4716                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    4717                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    4718                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    4719                 :            :         data, data_size,
+    4720                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    4721                 :            : #endif
+    4722                 :            : 
+    4723                 :          1 :     heartbeat_period = 0;
+    4724                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    4725                 :          1 :     status = libspdm_send_receive_key_exchange(
+    4726                 :            :         spdm_context,
+    4727                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    4728                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    4729                 :            :         measurement_hash);
+    4730                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SEND_FAIL);
+    4731                 :          1 :     free(data);
+    4732                 :          1 : }
+    4733                 :            : 
+    4734                 :          1 : static void libspdm_test_requester_key_exchange_err_case2(void **state)
+    4735                 :            : {
+    4736                 :            :     libspdm_return_t status;
+    4737                 :            :     libspdm_test_context_t *spdm_test_context;
+    4738                 :            :     libspdm_context_t *spdm_context;
+    4739                 :            :     uint32_t session_id;
+    4740                 :            :     uint8_t heartbeat_period;
+    4741                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    4742                 :            :     uint8_t slot_id_param;
+    4743                 :            :     void *data;
+    4744                 :            :     size_t data_size;
+    4745                 :            :     void *hash;
+    4746                 :            :     size_t hash_size;
+    4747                 :            : 
+    4748                 :          1 :     spdm_test_context = *state;
+    4749                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4750                 :          1 :     spdm_test_context->case_id = 0x2;
+    4751                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4752                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4753                 :          1 :     spdm_context->connection_info.connection_state =
+    4754                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    4755                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4756                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    4757                 :          1 :     spdm_context->local_context.capability.flags |=
+    4758                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    4759                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
+    4760                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
+    4761                 :            :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4762                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    4763                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    4764                 :            :                                                     &data_size, &hash, &hash_size);
+    4765                 :          1 :     libspdm_reset_message_a(spdm_context);
+    4766                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    4767                 :            :         m_libspdm_use_hash_algo;
+    4768                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    4769                 :            :         m_libspdm_use_asym_algo;
+    4770                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    4771                 :            :         m_libspdm_use_dhe_algo;
+    4772                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    4773                 :            :         m_libspdm_use_aead_algo;
+    4774                 :            : 
+    4775                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4776                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    4777                 :            :         data_size;
+    4778                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    4779                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    4780                 :            :                      data, data_size);
+    4781                 :            : #else
+    4782                 :          1 :     libspdm_hash_all(
+    4783                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    4784                 :            :         data, data_size,
+    4785                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    4786                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    4787                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    4788                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    4789                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    4790                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    4791                 :            :         data, data_size,
+    4792                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    4793                 :            : #endif
+    4794                 :            : 
+    4795                 :          1 :     heartbeat_period = 0;
+    4796                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    4797                 :          1 :     status = libspdm_send_receive_key_exchange(
+    4798                 :            :         spdm_context,
+    4799                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    4800                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    4801                 :            :         measurement_hash);
+    4802                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    4803                 :          1 :     assert_int_equal(session_id, 0xFFFFFFFF);
+    4804                 :          1 :     assert_int_equal(
+    4805                 :            :         libspdm_secured_message_get_session_state(
+    4806                 :            :             spdm_context->session_info[0].secured_message_context),
+    4807                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    4808                 :          1 :     free(data);
+    4809                 :          1 : }
+    4810                 :            : 
+    4811                 :          1 : static void libspdm_test_requester_key_exchange_err_case3(void **state)
+    4812                 :            : {
+    4813                 :            :     libspdm_return_t status;
+    4814                 :            :     libspdm_test_context_t *spdm_test_context;
+    4815                 :            :     libspdm_context_t *spdm_context;
+    4816                 :            :     uint32_t session_id;
+    4817                 :            :     uint8_t heartbeat_period;
+    4818                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    4819                 :            :     uint8_t slot_id_param;
+    4820                 :            :     void *data;
+    4821                 :            :     size_t data_size;
+    4822                 :            :     void *hash;
+    4823                 :            :     size_t hash_size;
+    4824                 :            : 
+    4825                 :          1 :     spdm_test_context = *state;
+    4826                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4827                 :          1 :     spdm_test_context->case_id = 0x3;
+    4828                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4829                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4830                 :          1 :     spdm_context->connection_info.connection_state =
+    4831                 :            :         LIBSPDM_CONNECTION_STATE_NOT_STARTED;
+    4832                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4833                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    4834                 :          1 :     spdm_context->local_context.capability.flags |=
+    4835                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    4836                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    4837                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    4838                 :            :                                                     &data_size, &hash, &hash_size);
+    4839                 :          1 :     libspdm_reset_message_a(spdm_context);
+    4840                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    4841                 :            :         m_libspdm_use_hash_algo;
+    4842                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    4843                 :            :         m_libspdm_use_asym_algo;
+    4844                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    4845                 :            :         m_libspdm_use_dhe_algo;
+    4846                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    4847                 :            :         m_libspdm_use_aead_algo;
+    4848                 :            : 
+    4849                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4850                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    4851                 :            :         data_size;
+    4852                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    4853                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    4854                 :            :                      data, data_size);
+    4855                 :            : #else
+    4856                 :          1 :     libspdm_hash_all(
+    4857                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    4858                 :            :         data, data_size,
+    4859                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    4860                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    4861                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    4862                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    4863                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    4864                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    4865                 :            :         data, data_size,
+    4866                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    4867                 :            : #endif
+    4868                 :            : 
+    4869                 :          1 :     heartbeat_period = 0;
+    4870                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    4871                 :          1 :     status = libspdm_send_receive_key_exchange(
+    4872                 :            :         spdm_context,
+    4873                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    4874                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    4875                 :            :         measurement_hash);
+    4876                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_STATE_LOCAL);
+    4877                 :          1 :     free(data);
+    4878                 :          1 : }
+    4879                 :            : 
+    4880                 :          1 : static void libspdm_test_requester_key_exchange_err_case4(void **state)
+    4881                 :            : {
+    4882                 :            :     libspdm_return_t status;
+    4883                 :            :     libspdm_test_context_t *spdm_test_context;
+    4884                 :            :     libspdm_context_t *spdm_context;
+    4885                 :            :     uint32_t session_id;
+    4886                 :            :     uint8_t heartbeat_period;
+    4887                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    4888                 :            :     uint8_t slot_id_param;
+    4889                 :            :     void *data;
+    4890                 :            :     size_t data_size;
+    4891                 :            :     void *hash;
+    4892                 :            :     size_t hash_size;
+    4893                 :            : 
+    4894                 :          1 :     spdm_test_context = *state;
+    4895                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4896                 :          1 :     spdm_test_context->case_id = 0x4;
+    4897                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4898                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4899                 :          1 :     spdm_context->connection_info.connection_state =
+    4900                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    4901                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4902                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    4903                 :          1 :     spdm_context->local_context.capability.flags |=
+    4904                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    4905                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    4906                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    4907                 :            :                                                     &data_size, &hash, &hash_size);
+    4908                 :          1 :     libspdm_reset_message_a(spdm_context);
+    4909                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    4910                 :            :         m_libspdm_use_hash_algo;
+    4911                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    4912                 :            :         m_libspdm_use_asym_algo;
+    4913                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    4914                 :            :         m_libspdm_use_dhe_algo;
+    4915                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    4916                 :            :         m_libspdm_use_aead_algo;
+    4917                 :            : 
+    4918                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4919                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    4920                 :            :         data_size;
+    4921                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    4922                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    4923                 :            :                      data, data_size);
+    4924                 :            : #else
+    4925                 :          1 :     libspdm_hash_all(
+    4926                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    4927                 :            :         data, data_size,
+    4928                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    4929                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    4930                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    4931                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    4932                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    4933                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    4934                 :            :         data, data_size,
+    4935                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    4936                 :            : #endif
+    4937                 :            : 
+    4938                 :          1 :     heartbeat_period = 0;
+    4939                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    4940                 :          1 :     status = libspdm_send_receive_key_exchange(
+    4941                 :            :         spdm_context,
+    4942                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    4943                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    4944                 :            :         measurement_hash);
+    4945                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_ERROR_PEER);
+    4946                 :          1 :     free(data);
+    4947                 :          1 : }
+    4948                 :            : 
+    4949                 :          1 : static void libspdm_test_requester_key_exchange_err_case5(void **state)
+    4950                 :            : {
+    4951                 :            :     libspdm_return_t status;
+    4952                 :            :     libspdm_test_context_t *spdm_test_context;
+    4953                 :            :     libspdm_context_t *spdm_context;
+    4954                 :            :     uint32_t session_id;
+    4955                 :            :     uint8_t heartbeat_period;
+    4956                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    4957                 :            :     uint8_t slot_id_param;
+    4958                 :            :     void *data;
+    4959                 :            :     size_t data_size;
+    4960                 :            :     void *hash;
+    4961                 :            :     size_t hash_size;
+    4962                 :            : 
+    4963                 :          1 :     spdm_test_context = *state;
+    4964                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4965                 :          1 :     spdm_test_context->case_id = 0x5;
+    4966                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4967                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4968                 :          1 :     spdm_context->connection_info.connection_state =
+    4969                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    4970                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4971                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    4972                 :          1 :     spdm_context->local_context.capability.flags |=
+    4973                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    4974                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    4975                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    4976                 :            :                                                     &data_size, &hash, &hash_size);
+    4977                 :          1 :     libspdm_reset_message_a(spdm_context);
+    4978                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    4979                 :            :         m_libspdm_use_hash_algo;
+    4980                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    4981                 :            :         m_libspdm_use_asym_algo;
+    4982                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    4983                 :            :         m_libspdm_use_dhe_algo;
+    4984                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    4985                 :            :         m_libspdm_use_aead_algo;
+    4986                 :            : 
+    4987                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4988                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    4989                 :            :         data_size;
+    4990                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    4991                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    4992                 :            :                      data, data_size);
+    4993                 :            : #else
+    4994                 :          1 :     libspdm_hash_all(
+    4995                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    4996                 :            :         data, data_size,
+    4997                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    4998                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    4999                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    5000                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    5001                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5002                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    5003                 :            :         data, data_size,
+    5004                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    5005                 :            : #endif
+    5006                 :            : 
+    5007                 :          1 :     heartbeat_period = 0;
+    5008                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    5009                 :          1 :     status = libspdm_send_receive_key_exchange(
+    5010                 :            :         spdm_context,
+    5011                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    5012                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    5013                 :            :         measurement_hash);
+    5014                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_BUSY_PEER);
+    5015                 :          1 :     free(data);
+    5016                 :          1 : }
+    5017                 :            : 
+    5018                 :            : /**
+    5019                 :            :  * Test 6: Requester / Responder do not support key exchange.
+    5020                 :            :  * Expected Behavior: returns with error LIBSPDM_STATUS_UNSUPPORTED_CAP.
+    5021                 :            :  **/
+    5022                 :          1 : static void libspdm_test_requester_key_exchange_err_case6(void **state)
+    5023                 :            : {
+    5024                 :            :     libspdm_return_t status;
+    5025                 :            :     libspdm_test_context_t *spdm_test_context;
+    5026                 :            :     libspdm_context_t *spdm_context;
+    5027                 :            :     uint32_t session_id;
+    5028                 :            :     uint8_t slot_id_param;
+    5029                 :            : 
+    5030                 :          1 :     spdm_test_context = *state;
+    5031                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5032                 :          1 :     spdm_test_context->case_id = 0x6;
+    5033                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5034                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5035                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    5036                 :          1 :     spdm_context->connection_info.capability.flags = 0;
+    5037                 :          1 :     spdm_context->local_context.capability.flags = 0;
+    5038                 :            : 
+    5039                 :          1 :     status = libspdm_send_receive_key_exchange(
+    5040                 :            :         spdm_context, SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    5041                 :            :         &session_id, NULL, &slot_id_param, NULL);
+    5042                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_UNSUPPORTED_CAP);
+    5043                 :          1 : }
+    5044                 :            : 
+    5045                 :          1 : static void libspdm_test_requester_key_exchange_err_case7(void **state)
+    5046                 :            : {
+    5047                 :            :     libspdm_return_t status;
+    5048                 :            :     libspdm_test_context_t *spdm_test_context;
+    5049                 :            :     libspdm_context_t *spdm_context;
+    5050                 :            :     uint32_t session_id;
+    5051                 :            :     uint8_t heartbeat_period;
+    5052                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    5053                 :            :     uint8_t slot_id_param;
+    5054                 :            :     void *data;
+    5055                 :            :     size_t data_size;
+    5056                 :            :     void *hash;
+    5057                 :            :     size_t hash_size;
+    5058                 :            : 
+    5059                 :          1 :     spdm_test_context = *state;
+    5060                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5061                 :          1 :     spdm_test_context->case_id = 0x7;
+    5062                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5063                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5064                 :          1 :     spdm_context->connection_info.connection_state =
+    5065                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    5066                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5067                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    5068                 :          1 :     spdm_context->local_context.capability.flags |=
+    5069                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    5070                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    5071                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    5072                 :            :                                                     &data_size, &hash, &hash_size);
+    5073                 :          1 :     libspdm_reset_message_a(spdm_context);
+    5074                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    5075                 :            :         m_libspdm_use_hash_algo;
+    5076                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    5077                 :            :         m_libspdm_use_asym_algo;
+    5078                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    5079                 :            :         m_libspdm_use_dhe_algo;
+    5080                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    5081                 :            :         m_libspdm_use_aead_algo;
+    5082                 :            : 
+    5083                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5084                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    5085                 :            :         data_size;
+    5086                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    5087                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    5088                 :            :                      data, data_size);
+    5089                 :            : #else
+    5090                 :          1 :     libspdm_hash_all(
+    5091                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5092                 :            :         data, data_size,
+    5093                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    5094                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    5095                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    5096                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    5097                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5098                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    5099                 :            :         data, data_size,
+    5100                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    5101                 :            : #endif
+    5102                 :            : 
+    5103                 :          1 :     heartbeat_period = 0;
+    5104                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    5105                 :          1 :     status = libspdm_send_receive_key_exchange(
+    5106                 :            :         spdm_context,
+    5107                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    5108                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    5109                 :            :         measurement_hash);
+    5110                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_RESYNCH_PEER);
+    5111                 :          1 :     assert_int_equal(spdm_context->connection_info.connection_state,
+    5112                 :            :                      LIBSPDM_CONNECTION_STATE_NOT_STARTED);
+    5113                 :          1 :     free(data);
+    5114                 :          1 : }
+    5115                 :            : 
+    5116                 :          1 : static void libspdm_test_requester_key_exchange_err_case8(void **state)
+    5117                 :            : {
+    5118                 :            :     libspdm_return_t status;
+    5119                 :            :     libspdm_test_context_t *spdm_test_context;
+    5120                 :            :     libspdm_context_t *spdm_context;
+    5121                 :            :     uint32_t session_id;
+    5122                 :            :     uint8_t heartbeat_period;
+    5123                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    5124                 :            :     uint8_t slot_id_param;
+    5125                 :            :     void *data;
+    5126                 :            :     size_t data_size;
+    5127                 :            :     void *hash;
+    5128                 :            :     size_t hash_size;
+    5129                 :            : 
+    5130                 :          1 :     spdm_test_context = *state;
+    5131                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5132                 :          1 :     spdm_test_context->case_id = 0x8;
+    5133                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5134                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5135                 :          1 :     spdm_context->connection_info.connection_state =
+    5136                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    5137                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5138                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    5139                 :          1 :     spdm_context->local_context.capability.flags |=
+    5140                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    5141                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    5142                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    5143                 :            :                                                     &data_size, &hash, &hash_size);
+    5144                 :          1 :     libspdm_reset_message_a(spdm_context);
+    5145                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    5146                 :            :         m_libspdm_use_hash_algo;
+    5147                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    5148                 :            :         m_libspdm_use_asym_algo;
+    5149                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    5150                 :            :         m_libspdm_use_dhe_algo;
+    5151                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    5152                 :            :         m_libspdm_use_aead_algo;
+    5153                 :            : 
+    5154                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5155                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    5156                 :            :         data_size;
+    5157                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    5158                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    5159                 :            :                      data, data_size);
+    5160                 :            : #else
+    5161                 :          1 :     libspdm_hash_all(
+    5162                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5163                 :            :         data, data_size,
+    5164                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    5165                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    5166                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    5167                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    5168                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5169                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    5170                 :            :         data, data_size,
+    5171                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    5172                 :            : #endif
+    5173                 :            : 
+    5174                 :          1 :     heartbeat_period = 0;
+    5175                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    5176                 :          1 :     status = libspdm_send_receive_key_exchange(
+    5177                 :            :         spdm_context,
+    5178                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    5179                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    5180                 :            :         measurement_hash);
+    5181                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_NOT_READY_PEER);
+    5182                 :          1 :     free(data);
+    5183                 :          1 : }
+    5184                 :            : 
+    5185                 :            : /**
+    5186                 :            :  * Test 9: Unable to acquire the sender buffer.
+    5187                 :            :  * Expected Behavior: returns with error LIBSPDM_STATUS_ACQUIRE_FAIL.
+    5188                 :            :  **/
+    5189                 :          1 : static void libspdm_test_requester_key_exchange_err_case9(void **state)
+    5190                 :            : {
+    5191                 :            :     libspdm_return_t status;
+    5192                 :            :     libspdm_test_context_t *spdm_test_context;
+    5193                 :            :     libspdm_context_t *spdm_context;
+    5194                 :            :     uint32_t session_id;
+    5195                 :            :     uint8_t slot_id_param;
+    5196                 :            : 
+    5197                 :          1 :     spdm_test_context = *state;
+    5198                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5199                 :          1 :     spdm_test_context->case_id = 0x9;
+    5200                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5201                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5202                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    5203                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5204                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    5205                 :          1 :     spdm_context->local_context.capability.flags |=
+    5206                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    5207                 :            : 
+    5208                 :          1 :     libspdm_force_error (LIBSPDM_ERR_ACQUIRE_SENDER_BUFFER);
+    5209                 :          1 :     status = libspdm_send_receive_key_exchange(
+    5210                 :            :         spdm_context, SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    5211                 :            :         &session_id, NULL, &slot_id_param, NULL);
+    5212                 :          1 :     libspdm_release_error (LIBSPDM_ERR_ACQUIRE_SENDER_BUFFER);
+    5213                 :            : 
+    5214                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_ACQUIRE_FAIL);
+    5215                 :          1 : }
+    5216                 :            : 
+    5217                 :          1 : static void libspdm_test_requester_key_exchange_err_case10(void **state) {
+    5218                 :            :     libspdm_return_t status;
+    5219                 :            :     libspdm_test_context_t    *spdm_test_context;
+    5220                 :            :     libspdm_context_t  *spdm_context;
+    5221                 :            :     uint32_t session_id;
+    5222                 :            :     uint8_t heartbeat_period;
+    5223                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    5224                 :            :     uint8_t slot_id_param;
+    5225                 :            :     void                 *data;
+    5226                 :            :     size_t data_size;
+    5227                 :            :     void                 *hash;
+    5228                 :            :     size_t hash_size;
+    5229                 :            :     uint16_t error_code;
+    5230                 :            : 
+    5231                 :          1 :     spdm_test_context = *state;
+    5232                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5233                 :          1 :     spdm_test_context->case_id = 0xA;
+    5234                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5235                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5236                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5237                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    5238                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    5239                 :          1 :     libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
+    5240                 :            :                                                      m_libspdm_use_asym_algo,
+    5241                 :            :                                                      &data, &data_size,
+    5242                 :            :                                                      &hash, &hash_size);
+    5243                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    5244                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    5245                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    5246                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    5247                 :            : 
+    5248                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5249                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    5250                 :            :         data_size;
+    5251                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    5252                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    5253                 :            :                      data, data_size);
+    5254                 :            : #else
+    5255                 :          1 :     libspdm_hash_all(
+    5256                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5257                 :            :         data, data_size,
+    5258                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    5259                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    5260                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    5261                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    5262                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5263                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    5264                 :            :         data, data_size,
+    5265                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    5266                 :            : #endif
+    5267                 :            : 
+    5268                 :          1 :     error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
+    5269         [ +  + ]:         19 :     while(error_code <= 0xff) {
+    5270                 :         18 :         spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    5271                 :         18 :         libspdm_reset_message_a(spdm_context);
+    5272                 :            : 
+    5273                 :         18 :         heartbeat_period = 0;
+    5274                 :         18 :         libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    5275                 :         18 :         status = libspdm_send_receive_key_exchange (spdm_context,
+    5276                 :            :                                                     SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
+    5277                 :            :                                                     0, 0, &session_id, &heartbeat_period,
+    5278                 :            :                                                     &slot_id_param, measurement_hash);
+    5279         [ -  + ]:         18 :         LIBSPDM_ASSERT_INT_EQUAL_CASE (status, LIBSPDM_STATUS_ERROR_PEER, error_code);
+    5280                 :            : 
+    5281                 :         18 :         error_code++;
+    5282         [ +  + ]:         18 :         if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
+    5283                 :          1 :             error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
+    5284                 :            :         }
+    5285         [ +  + ]:         18 :         if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) { /*skip some reserved error codes (0d to 3e)*/
+    5286                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
+    5287                 :            :         }
+    5288         [ +  + ]:         18 :         if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) { /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
+    5289                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
+    5290                 :            :         }
+    5291                 :            :     }
+    5292                 :            : 
+    5293                 :          1 :     free(data);
+    5294                 :          1 : }
+    5295                 :            : 
+    5296                 :            : /**
+    5297                 :            :  * Test 11: Unable to acquire the receiver buffer.
+    5298                 :            :  * Expected Behavior: returns with error LIBSPDM_STATUS_ACQUIRE_FAIL.
+    5299                 :            :  **/
+    5300                 :          1 : static void libspdm_test_requester_key_exchange_err_case11(void **state)
+    5301                 :            : {
+    5302                 :            :     libspdm_return_t status;
+    5303                 :            :     libspdm_test_context_t *spdm_test_context;
+    5304                 :            :     libspdm_context_t *spdm_context;
+    5305                 :            :     uint32_t session_id;
+    5306                 :            :     uint8_t slot_id_param;
+    5307                 :            : 
+    5308                 :          1 :     spdm_test_context = *state;
+    5309                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5310                 :          1 :     spdm_test_context->case_id = 0xb;
+    5311                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5312                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5313                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    5314                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5315                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    5316                 :          1 :     spdm_context->local_context.capability.flags |=
+    5317                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    5318                 :            : 
+    5319                 :          1 :     libspdm_force_error (LIBSPDM_ERR_ACQUIRE_RECEIVER_BUFFER);
+    5320                 :          1 :     status = libspdm_send_receive_key_exchange(
+    5321                 :            :         spdm_context, SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    5322                 :            :         &session_id, NULL, &slot_id_param, NULL);
+    5323                 :          1 :     libspdm_release_error (LIBSPDM_ERR_ACQUIRE_RECEIVER_BUFFER);
+    5324                 :            : 
+    5325                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_ACQUIRE_FAIL);
+    5326                 :          1 : }
+    5327                 :            : 
+    5328                 :            : /**
+    5329                 :            :  * Test 12: Version in response is incorrect.
+    5330                 :            :  * Expected Behavior: returns with error LIBSPDM_STATUS_INVALID_MSG_FIELD.
+    5331                 :            :  **/
+    5332                 :          1 : static void libspdm_test_requester_key_exchange_err_case12(void **state)
+    5333                 :            : {
+    5334                 :            :     libspdm_return_t status;
+    5335                 :            :     libspdm_test_context_t *spdm_test_context;
+    5336                 :            :     libspdm_context_t *spdm_context;
+    5337                 :            :     uint32_t session_id;
+    5338                 :            :     uint8_t slot_id_param;
+    5339                 :            : 
+    5340                 :          1 :     spdm_test_context = *state;
+    5341                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5342                 :          1 :     spdm_test_context->case_id = 0xc;
+    5343                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5344                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5345                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    5346                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5347                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    5348                 :          1 :     spdm_context->local_context.capability.flags |=
+    5349                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    5350                 :            : 
+    5351                 :          1 :     status = libspdm_send_receive_key_exchange(
+    5352                 :            :         spdm_context, SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    5353                 :            :         &session_id, NULL, &slot_id_param, NULL);
+    5354                 :            : 
+    5355                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    5356                 :          1 : }
+    5357                 :            : 
+    5358                 :            : /**
+    5359                 :            :  * Test 13: Response code is incorrect.
+    5360                 :            :  * Expected Behavior: returns with error LIBSPDM_STATUS_INVALID_MSG_FIELD.
+    5361                 :            :  **/
+    5362                 :          1 : static void libspdm_test_requester_key_exchange_err_case13(void **state)
+    5363                 :            : {
+    5364                 :            :     libspdm_return_t status;
+    5365                 :            :     libspdm_test_context_t *spdm_test_context;
+    5366                 :            :     libspdm_context_t *spdm_context;
+    5367                 :            :     uint32_t session_id;
+    5368                 :            :     uint8_t slot_id_param;
+    5369                 :            : 
+    5370                 :          1 :     spdm_test_context = *state;
+    5371                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5372                 :          1 :     spdm_test_context->case_id = 0xd;
+    5373                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5374                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5375                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    5376                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5377                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    5378                 :          1 :     spdm_context->local_context.capability.flags |=
+    5379                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    5380                 :            : 
+    5381                 :          1 :     status = libspdm_send_receive_key_exchange(
+    5382                 :            :         spdm_context, SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    5383                 :            :         &session_id, NULL, &slot_id_param, NULL);
+    5384                 :            : 
+    5385                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    5386                 :          1 : }
+    5387                 :            : 
+    5388                 :            : /**
+    5389                 :            :  * Test 14: Responder requests mutual authentication when it is not supported.
+    5390                 :            :  * Expected Behavior: returns with error LIBSPDM_STATUS_INVALID_MSG_FIELD.
+    5391                 :            :  **/
+    5392                 :          1 : static void libspdm_test_requester_key_exchange_err_case14(void **state)
+    5393                 :            : {
+    5394                 :            :     libspdm_return_t status;
+    5395                 :            :     libspdm_test_context_t *spdm_test_context;
+    5396                 :            :     libspdm_context_t *spdm_context;
+    5397                 :            :     uint32_t session_id;
+    5398                 :            :     uint8_t slot_id_param;
+    5399                 :            : 
+    5400                 :          1 :     spdm_test_context = *state;
+    5401                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5402                 :          1 :     spdm_test_context->case_id = 0xe;
+    5403                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5404                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5405                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    5406                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5407                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    5408                 :          1 :     spdm_context->local_context.capability.flags |=
+    5409                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    5410                 :            : 
+    5411                 :          1 :     status = libspdm_send_receive_key_exchange(
+    5412                 :            :         spdm_context, SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    5413                 :            :         &session_id, NULL, &slot_id_param, NULL);
+    5414                 :            : 
+    5415                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    5416                 :          1 : }
+    5417                 :            : 
+    5418                 :          1 : static void libspdm_test_requester_key_exchange_err_case15(void **state)
+    5419                 :            : {
+    5420                 :            :     libspdm_return_t status;
+    5421                 :            :     libspdm_test_context_t *spdm_test_context;
+    5422                 :            :     libspdm_context_t *spdm_context;
+    5423                 :            :     uint32_t session_id;
+    5424                 :            :     uint8_t heartbeat_period;
+    5425                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    5426                 :            :     uint8_t slot_id_param;
+    5427                 :            :     void *data;
+    5428                 :            :     size_t data_size;
+    5429                 :            :     void *hash;
+    5430                 :            :     size_t hash_size;
+    5431                 :            : 
+    5432                 :          1 :     spdm_test_context = *state;
+    5433                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5434                 :            : 
+    5435         [ +  - ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    5436                 :          1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    5437                 :            :     }
+    5438                 :            : 
+    5439                 :          1 :     spdm_test_context->case_id = 0xF;
+    5440                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5441                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5442                 :          1 :     spdm_context->connection_info.connection_state =
+    5443                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    5444                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5445                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    5446                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5447                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    5448                 :          1 :     spdm_context->local_context.capability.flags |=
+    5449                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    5450                 :            : 
+    5451                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    5452                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    5453                 :            :                                                     &data_size, &hash, &hash_size);
+    5454                 :          1 :     libspdm_reset_message_a(spdm_context);
+    5455                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    5456                 :            :         m_libspdm_use_hash_algo;
+    5457                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    5458                 :            :         m_libspdm_use_asym_algo;
+    5459                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    5460                 :            :         m_libspdm_use_dhe_algo;
+    5461                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    5462                 :            :         m_libspdm_use_aead_algo;
+    5463                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    5464                 :            :         m_libspdm_use_measurement_hash_algo;
+    5465                 :            : 
+    5466                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5467                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    5468                 :            :         data_size;
+    5469                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    5470                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    5471                 :            :                      data, data_size);
+    5472                 :            : #else
+    5473                 :          1 :     libspdm_hash_all(
+    5474                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5475                 :            :         data, data_size,
+    5476                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    5477                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    5478                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    5479                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    5480                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5481                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    5482                 :            :         data, data_size,
+    5483                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    5484                 :            : #endif
+    5485                 :            : 
+    5486                 :          1 :     heartbeat_period = 0;
+    5487                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    5488                 :          1 :     status = libspdm_send_receive_key_exchange(
+    5489                 :            :         spdm_context,
+    5490                 :            :         SPDM_KEY_EXCHANGE_REQUEST_TCB_COMPONENT_MEASUREMENT_HASH, 0, 0,
+    5491                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    5492                 :            :         measurement_hash);
+    5493                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
+    5494                 :          1 :     free(data);
+    5495                 :          1 : }
+    5496                 :            : 
+    5497                 :          1 : static void libspdm_test_requester_key_exchange_err_case16(void **state)
+    5498                 :            : {
+    5499                 :            :     libspdm_return_t status;
+    5500                 :            :     libspdm_test_context_t *spdm_test_context;
+    5501                 :            :     libspdm_context_t *spdm_context;
+    5502                 :            :     uint32_t session_id;
+    5503                 :            :     uint8_t heartbeat_period;
+    5504                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    5505                 :            :     uint8_t slot_id_param;
+    5506                 :            :     void *data;
+    5507                 :            :     size_t data_size;
+    5508                 :            :     void *hash;
+    5509                 :            :     size_t hash_size;
+    5510                 :            : 
+    5511                 :          1 :     spdm_test_context = *state;
+    5512                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5513                 :            : 
+    5514         [ -  + ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    5515                 :          0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    5516                 :            :     }
+    5517                 :            : 
+    5518                 :          1 :     spdm_test_context->case_id = 0x10;
+    5519                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5520                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5521                 :          1 :     spdm_context->connection_info.connection_state =
+    5522                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    5523                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5524                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    5525                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5526                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    5527                 :          1 :     spdm_context->local_context.capability.flags |=
+    5528                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    5529                 :            : 
+    5530                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    5531                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    5532                 :            :                                                     &data_size, &hash, &hash_size);
+    5533                 :          1 :     libspdm_reset_message_a(spdm_context);
+    5534                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    5535                 :            :         m_libspdm_use_hash_algo;
+    5536                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    5537                 :            :         m_libspdm_use_asym_algo;
+    5538                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    5539                 :            :         m_libspdm_use_dhe_algo;
+    5540                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    5541                 :            :         m_libspdm_use_aead_algo;
+    5542                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    5543                 :            :         m_libspdm_use_measurement_hash_algo;
+    5544                 :            : 
+    5545                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5546                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    5547                 :            :         data_size;
+    5548                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    5549                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    5550                 :            :                      data, data_size);
+    5551                 :            : #else
+    5552                 :          1 :     libspdm_hash_all(
+    5553                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5554                 :            :         data, data_size,
+    5555                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    5556                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    5557                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    5558                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    5559                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5560                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    5561                 :            :         data, data_size,
+    5562                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    5563                 :            : #endif
+    5564                 :            : 
+    5565                 :          1 :     heartbeat_period = 0;
+    5566                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    5567                 :          1 :     status = libspdm_send_receive_key_exchange(
+    5568                 :            :         spdm_context,
+    5569                 :            :         SPDM_KEY_EXCHANGE_REQUEST_ALL_MEASUREMENTS_HASH, 0, 0,
+    5570                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    5571                 :            :         measurement_hash);
+    5572                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
+    5573                 :          1 :     free(data);
+    5574                 :          1 : }
+    5575                 :            : 
+    5576                 :          1 : static void libspdm_test_requester_key_exchange_err_case17(void **state)
+    5577                 :            : {
+    5578                 :            :     libspdm_return_t status;
+    5579                 :            :     libspdm_test_context_t *spdm_test_context;
+    5580                 :            :     libspdm_context_t *spdm_context;
+    5581                 :            :     uint32_t session_id;
+    5582                 :            :     uint8_t heartbeat_period;
+    5583                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    5584                 :            :     uint8_t slot_id_param;
+    5585                 :            :     void *data;
+    5586                 :            :     size_t data_size;
+    5587                 :            :     void *hash;
+    5588                 :            :     size_t hash_size;
+    5589                 :            : 
+    5590                 :          1 :     spdm_test_context = *state;
+    5591                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5592                 :            : 
+    5593         [ -  + ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    5594                 :          0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    5595                 :            :     }
+    5596                 :            : 
+    5597                 :          1 :     spdm_test_context->case_id = 0x11;
+    5598                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5599                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5600                 :          1 :     spdm_context->connection_info.connection_state =
+    5601                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    5602                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5603                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    5604                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5605                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    5606                 :          1 :     spdm_context->local_context.capability.flags |=
+    5607                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    5608                 :            : 
+    5609                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    5610                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    5611                 :            :                                                     &data_size, &hash, &hash_size);
+    5612                 :          1 :     libspdm_reset_message_a(spdm_context);
+    5613                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    5614                 :            :         m_libspdm_use_hash_algo;
+    5615                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    5616                 :            :         m_libspdm_use_asym_algo;
+    5617                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    5618                 :            :         m_libspdm_use_dhe_algo;
+    5619                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    5620                 :            :         m_libspdm_use_aead_algo;
+    5621                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    5622                 :            :         m_libspdm_use_measurement_hash_algo;
+    5623                 :            : 
+    5624                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5625                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    5626                 :            :         data_size;
+    5627                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    5628                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    5629                 :            :                      data, data_size);
+    5630                 :            : #else
+    5631                 :          1 :     libspdm_hash_all(
+    5632                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5633                 :            :         data, data_size,
+    5634                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    5635                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    5636                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    5637                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    5638                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5639                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    5640                 :            :         data, data_size,
+    5641                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    5642                 :            : #endif
+    5643                 :            : 
+    5644                 :          1 :     heartbeat_period = 0;
+    5645                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    5646                 :          1 :     status = libspdm_send_receive_key_exchange(
+    5647                 :            :         spdm_context,
+    5648                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    5649                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    5650                 :            :         measurement_hash);
+    5651                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
+    5652                 :          1 :     free(data);
+    5653                 :          1 : }
+    5654                 :            : 
+    5655                 :          1 : static void libspdm_test_requester_key_exchange_err_case18(void **state)
+    5656                 :            : {
+    5657                 :            :     libspdm_return_t status;
+    5658                 :            :     libspdm_test_context_t *spdm_test_context;
+    5659                 :            :     libspdm_context_t *spdm_context;
+    5660                 :            :     uint32_t session_id;
+    5661                 :            :     uint8_t heartbeat_period;
+    5662                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    5663                 :            :     uint8_t slot_id_param;
+    5664                 :            :     void *data;
+    5665                 :            :     size_t data_size;
+    5666                 :            :     void *hash;
+    5667                 :            :     size_t hash_size;
+    5668                 :            : 
+    5669                 :          1 :     spdm_test_context = *state;
+    5670                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5671                 :            : 
+    5672         [ -  + ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    5673                 :          0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    5674                 :            :     }
+    5675                 :            : 
+    5676                 :          1 :     spdm_test_context->case_id = 0x12;
+    5677                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5678                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5679                 :          1 :     spdm_context->connection_info.connection_state =
+    5680                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    5681                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5682                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    5683                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5684                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    5685                 :          1 :     spdm_context->local_context.capability.flags |=
+    5686                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    5687                 :            : 
+    5688                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    5689                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    5690                 :            :                                                     &data_size, &hash, &hash_size);
+    5691                 :          1 :     libspdm_reset_message_a(spdm_context);
+    5692                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    5693                 :            :         m_libspdm_use_hash_algo;
+    5694                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    5695                 :            :         m_libspdm_use_asym_algo;
+    5696                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    5697                 :            :         m_libspdm_use_dhe_algo;
+    5698                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    5699                 :            :         m_libspdm_use_aead_algo;
+    5700                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    5701                 :            :         m_libspdm_use_measurement_hash_algo;
+    5702                 :            : 
+    5703                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5704                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    5705                 :            :         data_size;
+    5706                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    5707                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    5708                 :            :                      data, data_size);
+    5709                 :            : #else
+    5710                 :          1 :     libspdm_hash_all(
+    5711                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5712                 :            :         data, data_size,
+    5713                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    5714                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    5715                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    5716                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    5717                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5718                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    5719                 :            :         data, data_size,
+    5720                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    5721                 :            : #endif
+    5722                 :            : 
+    5723                 :          1 :     heartbeat_period = 0;
+    5724                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    5725                 :          1 :     status = libspdm_send_receive_key_exchange(
+    5726                 :            :         spdm_context,
+    5727                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    5728                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    5729                 :            :         measurement_hash);
+    5730                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_VERIF_FAIL);
+    5731                 :          1 :     free(data);
+    5732                 :          1 : }
+    5733                 :            : 
+    5734                 :            : /**
+    5735                 :            :  * Test 19:
+    5736                 :            :  * Expected Behavior:
+    5737                 :            :  **/
+    5738                 :          1 : static void libspdm_test_requester_key_exchange_err_case19(void **state)
+    5739                 :            : {
+    5740                 :          1 : }
+    5741                 :            : 
+    5742                 :          1 : static void libspdm_test_requester_key_exchange_err_case20(void **state)
+    5743                 :            : {
+    5744                 :            :     libspdm_return_t status;
+    5745                 :            :     libspdm_test_context_t *spdm_test_context;
+    5746                 :            :     libspdm_context_t *spdm_context;
+    5747                 :            :     uint32_t session_id;
+    5748                 :            :     uint8_t heartbeat_period;
+    5749                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    5750                 :            :     uint8_t slot_id_param;
+    5751                 :            :     void *data;
+    5752                 :            :     size_t data_size;
+    5753                 :            :     void *hash;
+    5754                 :            :     size_t hash_size;
+    5755                 :            : 
+    5756                 :          1 :     spdm_test_context = *state;
+    5757                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5758                 :            : 
+    5759         [ -  + ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    5760                 :          0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    5761                 :            :     }
+    5762                 :            : 
+    5763                 :          1 :     spdm_test_context->case_id = 0x14;
+    5764                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5765                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5766                 :          1 :     spdm_context->connection_info.connection_state =
+    5767                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    5768                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5769                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    5770                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5771                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    5772                 :          1 :     spdm_context->local_context.capability.flags |=
+    5773                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    5774                 :            : 
+    5775                 :            : 
+    5776                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    5777                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    5778                 :            :                                                     &data_size, &hash, &hash_size);
+    5779                 :          1 :     libspdm_reset_message_a(spdm_context);
+    5780                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    5781                 :            :         m_libspdm_use_hash_algo;
+    5782                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    5783                 :            :         m_libspdm_use_asym_algo;
+    5784                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    5785                 :            :         m_libspdm_use_dhe_algo;
+    5786                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    5787                 :            :         m_libspdm_use_aead_algo;
+    5788                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    5789                 :            :         m_libspdm_use_measurement_hash_algo;
+    5790                 :            : 
+    5791                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5792                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    5793                 :            :         data_size;
+    5794                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    5795                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    5796                 :            :                      data, data_size);
+    5797                 :            : #else
+    5798                 :          1 :     libspdm_hash_all(
+    5799                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5800                 :            :         data, data_size,
+    5801                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    5802                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    5803                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    5804                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    5805                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5806                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    5807                 :            :         data, data_size,
+    5808                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    5809                 :            : #endif
+    5810                 :            : 
+    5811                 :          1 :     heartbeat_period = 0;
+    5812                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    5813                 :          1 :     status = libspdm_send_receive_key_exchange(
+    5814                 :            :         spdm_context,
+    5815                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    5816                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    5817                 :            :         measurement_hash);
+    5818                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    5819                 :          1 :     free(data);
+    5820                 :          1 : }
+    5821                 :            : 
+    5822                 :            : /**
+    5823                 :            :  * Test 21: OpaqueLength is larger than the recommended value.
+    5824                 :            :  * Expected Behavior: Returns with LIBSPDM_STATUS_INVALID_MSG_FIELD.
+    5825                 :            :  **/
+    5826                 :          1 : static void libspdm_test_requester_key_exchange_err_case21(void **state)
+    5827                 :            : {
+    5828                 :            :     libspdm_return_t status;
+    5829                 :            :     libspdm_test_context_t *spdm_test_context;
+    5830                 :            :     libspdm_context_t *spdm_context;
+    5831                 :            :     uint32_t session_id;
+    5832                 :            :     uint8_t slot_id_param;
+    5833                 :            : 
+    5834                 :          1 :     spdm_test_context = *state;
+    5835                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5836                 :          1 :     spdm_test_context->case_id = 0x15;
+    5837                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5838                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5839                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    5840                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5841                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    5842                 :          1 :     spdm_context->local_context.capability.flags |=
+    5843                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    5844                 :            : 
+    5845                 :          1 :     status = libspdm_send_receive_key_exchange(
+    5846                 :            :         spdm_context, SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    5847                 :            :         &session_id, NULL, &slot_id_param, NULL);
+    5848                 :            : 
+    5849                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    5850                 :          1 : }
+    5851                 :            : 
+    5852                 :            : /**
+    5853                 :            :  * Test 22: Requester's PUB_KEY_ID_CAP is 1 but Responder sets MutAuthRequested to 2 (encapsulated
+    5854                 :            :  *          flow).
+    5855                 :            :  * Expected Behavior: Returns with LIBSPDM_STATUS_INVALID_MSG_FIELD.
+    5856                 :            :  **/
+    5857                 :          1 : static void libspdm_test_requester_key_exchange_err_case22(void **state)
+    5858                 :            : {
+    5859                 :            :     libspdm_return_t status;
+    5860                 :            :     libspdm_test_context_t *spdm_test_context;
+    5861                 :            :     libspdm_context_t *spdm_context;
+    5862                 :            :     uint32_t session_id;
+    5863                 :            :     uint8_t slot_id_param;
+    5864                 :            : 
+    5865                 :          1 :     spdm_test_context = *state;
+    5866                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5867                 :          1 :     spdm_test_context->case_id = 0x16;
+    5868                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5869                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5870                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    5871                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5872                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
+    5873                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    5874                 :          1 :     spdm_context->local_context.capability.flags |=
+    5875                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
+    5876                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP |
+    5877                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PUB_KEY_ID_CAP;
+    5878                 :            : 
+    5879                 :          1 :     status = libspdm_send_receive_key_exchange(
+    5880                 :            :         spdm_context, SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    5881                 :            :         &session_id, NULL, &slot_id_param, NULL);
+    5882                 :            : 
+    5883                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    5884                 :          1 : }
+    5885                 :            : 
+    5886                 :            : /**
+    5887                 :            :  * Test 23: Responder attempts to initiate a mutual authentication encapsulated flow but both
+    5888                 :            :  *          endpoints do not support ENCAP_CAP.
+    5889                 :            :  * Expected Behavior: Returns with LIBSPDM_STATUS_INVALID_MSG_FIELD.
+    5890                 :            :  **/
+    5891                 :          1 : static void libspdm_test_requester_key_exchange_err_case23(void **state)
+    5892                 :            : {
+    5893                 :            :     libspdm_return_t status;
+    5894                 :            :     libspdm_test_context_t *spdm_test_context;
+    5895                 :            :     libspdm_context_t *spdm_context;
+    5896                 :            :     uint32_t session_id;
+    5897                 :            :     uint8_t slot_id_param;
+    5898                 :            : 
+    5899                 :          1 :     spdm_test_context = *state;
+    5900                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5901                 :          1 :     spdm_test_context->case_id = 0x17;
+    5902                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5903                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5904                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    5905                 :          1 :     spdm_context->connection_info.capability.flags =
+    5906                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
+    5907                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    5908                 :          1 :     spdm_context->local_context.capability.flags =
+    5909                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
+    5910                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP |
+    5911                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
+    5912                 :            : 
+    5913                 :          1 :     status = libspdm_send_receive_key_exchange(
+    5914                 :            :         spdm_context, SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    5915                 :            :         &session_id, NULL, &slot_id_param, NULL);
+    5916                 :            : 
+    5917                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    5918                 :          1 : }
+    5919                 :            : 
+    5920                 :          1 : static void libspdm_test_requester_key_exchange_err_case24(void **state)
+    5921                 :            : {
+    5922                 :          1 : }
+    5923                 :            : 
+    5924                 :          1 : static void libspdm_test_requester_key_exchange_err_case25(void **state)
+    5925                 :            : {
+    5926                 :          1 : }
+    5927                 :            : 
+    5928                 :          1 : static void libspdm_test_requester_key_exchange_err_case26(void **state)
+    5929                 :            : {
+    5930                 :            :     libspdm_return_t status;
+    5931                 :            :     libspdm_test_context_t *spdm_test_context;
+    5932                 :            :     libspdm_context_t *spdm_context;
+    5933                 :            :     uint32_t session_id;
+    5934                 :            :     uint8_t heartbeat_period;
+    5935                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    5936                 :            :     uint8_t slot_id_param;
+    5937                 :            :     void *data;
+    5938                 :            :     size_t data_size;
+    5939                 :            :     void *hash;
+    5940                 :            :     size_t hash_size;
+    5941                 :            : 
+    5942                 :          1 :     spdm_test_context = *state;
+    5943                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5944                 :            : 
+    5945         [ -  + ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    5946                 :          0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    5947                 :            :     }
+    5948                 :            : 
+    5949                 :          1 :     spdm_test_context->case_id = 0x1A;
+    5950                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5951                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5952                 :          1 :     spdm_context->connection_info.connection_state =
+    5953                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    5954                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5955                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    5956                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5957                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    5958                 :          1 :     spdm_context->local_context.capability.flags |=
+    5959                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    5960                 :            : 
+    5961                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5962                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    5963                 :          1 :     spdm_context->local_context.capability.flags |=
+    5964                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    5965                 :            : 
+    5966                 :            : 
+    5967                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    5968                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    5969                 :            :                                                     &data_size, &hash, &hash_size);
+    5970                 :          1 :     libspdm_reset_message_a(spdm_context);
+    5971                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    5972                 :            :         m_libspdm_use_hash_algo;
+    5973                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    5974                 :            :         m_libspdm_use_asym_algo;
+    5975                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    5976                 :            :         m_libspdm_use_dhe_algo;
+    5977                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    5978                 :            :         m_libspdm_use_aead_algo;
+    5979                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    5980                 :            :         m_libspdm_use_measurement_hash_algo;
+    5981                 :            : 
+    5982                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5983                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    5984                 :            :         data_size;
+    5985                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    5986                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    5987                 :            :                      data, data_size);
+    5988                 :            : #else
+    5989                 :          1 :     libspdm_hash_all(
+    5990                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5991                 :            :         data, data_size,
+    5992                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    5993                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    5994                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    5995                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    5996                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5997                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    5998                 :            :         data, data_size,
+    5999                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    6000                 :            : #endif
+    6001                 :            : 
+    6002                 :          1 :     heartbeat_period = 0;
+    6003                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    6004                 :          1 :     status = libspdm_send_receive_key_exchange(
+    6005                 :            :         spdm_context,
+    6006                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    6007                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    6008                 :            :         measurement_hash);
+    6009                 :            :     /* Clear Mut_auth flags */
+    6010                 :          1 :     spdm_context->connection_info.capability.flags &=
+    6011                 :            :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    6012                 :          1 :     spdm_context->local_context.capability.flags &=
+    6013                 :            :         ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    6014                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    6015                 :          1 :     free(data);
+    6016                 :          1 : }
+    6017                 :            : 
+    6018                 :          1 : static void libspdm_test_requester_key_exchange_err_case27(void **state)
+    6019                 :            : {
+    6020                 :            :     libspdm_return_t status;
+    6021                 :            :     libspdm_test_context_t *spdm_test_context;
+    6022                 :            :     libspdm_context_t *spdm_context;
+    6023                 :            :     uint32_t session_id;
+    6024                 :            :     uint8_t heartbeat_period;
+    6025                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    6026                 :            :     uint8_t slot_id_param;
+    6027                 :            :     void *data;
+    6028                 :            :     size_t data_size;
+    6029                 :            :     void *hash;
+    6030                 :            :     size_t hash_size;
+    6031                 :            : 
+    6032                 :          1 :     spdm_test_context = *state;
+    6033                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    6034                 :            : 
+    6035         [ -  + ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    6036                 :          0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    6037                 :            :     }
+    6038                 :            : 
+    6039                 :          1 :     spdm_test_context->case_id = 0x1B;
+    6040                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    6041                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    6042                 :          1 :     spdm_context->connection_info.connection_state =
+    6043                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    6044                 :          1 :     spdm_context->connection_info.capability.flags |=
+    6045                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    6046                 :          1 :     spdm_context->connection_info.capability.flags |=
+    6047                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    6048                 :          1 :     spdm_context->local_context.capability.flags |=
+    6049                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    6050                 :            : 
+    6051                 :          1 :     spdm_context->connection_info.capability.flags |=
+    6052                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    6053                 :          1 :     spdm_context->local_context.capability.flags |=
+    6054                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    6055                 :            : 
+    6056                 :            : 
+    6057                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    6058                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    6059                 :            :                                                     &data_size, &hash, &hash_size);
+    6060                 :          1 :     libspdm_reset_message_a(spdm_context);
+    6061                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    6062                 :            :         m_libspdm_use_hash_algo;
+    6063                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    6064                 :            :         m_libspdm_use_asym_algo;
+    6065                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    6066                 :            :         m_libspdm_use_dhe_algo;
+    6067                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    6068                 :            :         m_libspdm_use_aead_algo;
+    6069                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    6070                 :            :         m_libspdm_use_measurement_hash_algo;
+    6071                 :            : 
+    6072                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    6073                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    6074                 :            :         data_size;
+    6075                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    6076                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    6077                 :            :                      data, data_size);
+    6078                 :            : #else
+    6079                 :          1 :     libspdm_hash_all(
+    6080                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    6081                 :            :         data, data_size,
+    6082                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    6083                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    6084                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    6085                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    6086                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    6087                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    6088                 :            :         data, data_size,
+    6089                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    6090                 :            : #endif
+    6091                 :            : 
+    6092                 :          1 :     heartbeat_period = 0;
+    6093                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    6094                 :          1 :     status = libspdm_send_receive_key_exchange(
+    6095                 :            :         spdm_context,
+    6096                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    6097                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    6098                 :            :         measurement_hash);
+    6099                 :            :     /*Clear Mut_auth flags*/
+    6100                 :          1 :     spdm_context->connection_info.capability.flags &=
+    6101                 :            :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    6102                 :          1 :     spdm_context->local_context.capability.flags &=
+    6103                 :            :         ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    6104                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    6105                 :          1 :     free(data);
+    6106                 :          1 : }
+    6107                 :            : 
+    6108                 :          1 : static void libspdm_test_requester_key_exchange_err_case28(void **state)
+    6109                 :            : {
+    6110                 :            :     libspdm_return_t status;
+    6111                 :            :     libspdm_test_context_t *spdm_test_context;
+    6112                 :            :     libspdm_context_t *spdm_context;
+    6113                 :            :     uint32_t session_id;
+    6114                 :            :     uint8_t heartbeat_period;
+    6115                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    6116                 :            :     uint8_t slot_id_param;
+    6117                 :            :     void *data;
+    6118                 :            :     size_t data_size;
+    6119                 :            :     void *hash;
+    6120                 :            :     size_t hash_size;
+    6121                 :            : 
+    6122                 :          1 :     spdm_test_context = *state;
+    6123                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    6124                 :            : 
+    6125         [ -  + ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    6126                 :          0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    6127                 :            :     }
+    6128                 :            : 
+    6129                 :          1 :     spdm_test_context->case_id = 0x1C;
+    6130                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    6131                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    6132                 :          1 :     spdm_context->connection_info.connection_state =
+    6133                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    6134                 :          1 :     spdm_context->connection_info.capability.flags |=
+    6135                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    6136                 :          1 :     spdm_context->connection_info.capability.flags |=
+    6137                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    6138                 :          1 :     spdm_context->local_context.capability.flags |=
+    6139                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    6140                 :            : 
+    6141                 :          1 :     spdm_context->connection_info.capability.flags |=
+    6142                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    6143                 :          1 :     spdm_context->local_context.capability.flags |=
+    6144                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    6145                 :            : 
+    6146                 :            : 
+    6147                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    6148                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    6149                 :            :                                                     &data_size, &hash, &hash_size);
+    6150                 :          1 :     libspdm_reset_message_a(spdm_context);
+    6151                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    6152                 :            :         m_libspdm_use_hash_algo;
+    6153                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    6154                 :            :         m_libspdm_use_asym_algo;
+    6155                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    6156                 :            :         m_libspdm_use_dhe_algo;
+    6157                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    6158                 :            :         m_libspdm_use_aead_algo;
+    6159                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    6160                 :            :         m_libspdm_use_measurement_hash_algo;
+    6161                 :            : 
+    6162                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    6163                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    6164                 :            :         data_size;
+    6165                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    6166                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    6167                 :            :                      data, data_size);
+    6168                 :            : #else
+    6169                 :          1 :     libspdm_hash_all(
+    6170                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    6171                 :            :         data, data_size,
+    6172                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    6173                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    6174                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    6175                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    6176                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    6177                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    6178                 :            :         data, data_size,
+    6179                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    6180                 :            : #endif
+    6181                 :            : 
+    6182                 :          1 :     heartbeat_period = 0;
+    6183                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    6184                 :          1 :     status = libspdm_send_receive_key_exchange(
+    6185                 :            :         spdm_context,
+    6186                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    6187                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    6188                 :            :         measurement_hash);
+    6189                 :            :     /* Clear Mut_auth flags */
+    6190                 :          1 :     spdm_context->connection_info.capability.flags &=
+    6191                 :            :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    6192                 :          1 :     spdm_context->local_context.capability.flags &=
+    6193                 :            :         ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    6194                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    6195                 :          1 :     free(data);
+    6196                 :          1 : }
+    6197                 :            : 
+    6198                 :          1 : static void libspdm_test_requester_key_exchange_err_case29(void **state)
+    6199                 :            : {
+    6200                 :          1 : }
+    6201                 :            : 
+    6202                 :          1 : static void libspdm_test_requester_key_exchange_err_case30(void **state)
+    6203                 :            : {
+    6204                 :          1 : }
+    6205                 :            : 
+    6206                 :            : /**
+    6207                 :            :  * Test 31: Fail case, MutAuthRequested bit 0 set, and SlotID is 9 in KEY_EXCHANGE_RSP response
+    6208                 :            :  * message but SlotID should be between 0 and 7 inclusive.
+    6209                 :            :  * Expected Behavior: returns a status of INVALID_MSG_FIELD.
+    6210                 :            :  **/
+    6211                 :          1 : static void libspdm_test_requester_key_exchange_err_case31(void **state)
+    6212                 :            : {
+    6213                 :            :     libspdm_return_t status;
+    6214                 :            :     libspdm_test_context_t *spdm_test_context;
+    6215                 :            :     libspdm_context_t *spdm_context;
+    6216                 :            :     uint32_t session_id;
+    6217                 :            :     uint8_t heartbeat_period;
+    6218                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    6219                 :            :     uint8_t slot_id_param;
+    6220                 :            :     void *data;
+    6221                 :            :     size_t data_size;
+    6222                 :            :     void *hash;
+    6223                 :            :     size_t hash_size;
+    6224                 :            : 
+    6225                 :          1 :     spdm_test_context = *state;
+    6226                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    6227                 :            : 
+    6228         [ -  + ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    6229                 :          0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    6230                 :            :     }
+    6231                 :            : 
+    6232                 :          1 :     spdm_test_context->case_id = 0x1F;
+    6233                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    6234                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    6235                 :          1 :     spdm_context->connection_info.connection_state =
+    6236                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    6237                 :          1 :     spdm_context->connection_info.capability.flags |=
+    6238                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    6239                 :          1 :     spdm_context->connection_info.capability.flags |=
+    6240                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    6241                 :          1 :     spdm_context->local_context.capability.flags |=
+    6242                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    6243                 :            : 
+    6244                 :          1 :     spdm_context->connection_info.capability.flags |=
+    6245                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    6246                 :          1 :     spdm_context->local_context.capability.flags |=
+    6247                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    6248                 :          1 :     spdm_context->local_context.capability.flags |=
+    6249                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
+    6250                 :            : 
+    6251                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    6252                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    6253                 :            :                                                     &data_size, &hash, &hash_size);
+    6254                 :          1 :     libspdm_reset_message_a(spdm_context);
+    6255                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    6256                 :            :         m_libspdm_use_hash_algo;
+    6257                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    6258                 :            :         m_libspdm_use_asym_algo;
+    6259                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    6260                 :            :         m_libspdm_use_dhe_algo;
+    6261                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    6262                 :            :         m_libspdm_use_aead_algo;
+    6263                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    6264                 :            :         m_libspdm_use_measurement_hash_algo;
+    6265                 :            : 
+    6266                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    6267                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    6268                 :            :         data_size;
+    6269                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    6270                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    6271                 :            :                      data, data_size);
+    6272                 :            : #else
+    6273                 :          1 :     libspdm_hash_all(
+    6274                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    6275                 :            :         data, data_size,
+    6276                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    6277                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    6278                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    6279                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    6280                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    6281                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    6282                 :            :         data, data_size,
+    6283                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    6284                 :            : #endif
+    6285                 :            : 
+    6286                 :          1 :     heartbeat_period = 0;
+    6287                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    6288                 :          1 :     status = libspdm_send_receive_key_exchange(
+    6289                 :            :         spdm_context,
+    6290                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    6291                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    6292                 :            :         measurement_hash);
+    6293                 :            :     /* Clear Mut_auth flags */
+    6294                 :          1 :     spdm_context->connection_info.capability.flags &=
+    6295                 :            :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    6296                 :          1 :     spdm_context->local_context.capability.flags &=
+    6297                 :            :         ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    6298                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    6299                 :          1 :     free(data);
+    6300                 :          1 : }
+    6301                 :            : 
+    6302                 :            : static libspdm_test_context_t m_libspdm_requester_key_exchange_test_context = {
+    6303                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+    6304                 :            :     true,
+    6305                 :            :     libspdm_requester_key_exchange_test_send_message,
+    6306                 :            :     libspdm_requester_key_exchange_test_receive_message,
+    6307                 :            : };
+    6308                 :            : 
+    6309                 :          1 : int libspdm_requester_key_exchange_error_test_main(void)
+    6310                 :            : {
+    6311                 :          1 :     const struct CMUnitTest spdm_requester_key_exchange_tests[] = {
+    6312                 :            :         /* SendRequest failed*/
+    6313                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_err_case1),
+    6314                 :            :         /* Successful response*/
+    6315                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_err_case2),
+    6316                 :            :         /* connection_state check failed*/
+    6317                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_err_case3),
+    6318                 :            :         /* Error response: SPDM_ERROR_CODE_INVALID_REQUEST*/
+    6319                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_err_case4),
+    6320                 :            :         /* Always SPDM_ERROR_CODE_BUSY*/
+    6321                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_err_case5),
+    6322                 :            :         /* SPDM_ERROR_CODE_BUSY + Successful response*/
+    6323                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_err_case6),
+    6324                 :            :         /* Error response: SPDM_ERROR_CODE_REQUEST_RESYNCH*/
+    6325                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_err_case7),
+    6326                 :            :         /* Always SPDM_ERROR_CODE_RESPONSE_NOT_READY*/
+    6327                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_err_case8),
+    6328                 :            :         /* SPDM_ERROR_CODE_RESPONSE_NOT_READY + Successful response*/
+    6329                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_err_case9),
+    6330                 :            :         /* Unexpected errors*/
+    6331                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_err_case10),
+    6332                 :            :         /* Buffer reset*/
+    6333                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_err_case11),
+    6334                 :            :         /* Measurement hash 1, returns a measurement hash*/
+    6335                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_err_case12),
+    6336                 :            :         /* Measurement hash 1, returns a 0x00 array (no TCB components)*/
+    6337                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_err_case13),
+    6338                 :            :         /* Measurement hash FF, returns a measurement_hash*/
+    6339                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_err_case14),
+    6340                 :            :         /* Measurement hash 1, returns no measurement_hash*/
+    6341                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_err_case15),
+    6342                 :            :         /* Measurement hash FF, returns no measurement_hash*/
+    6343                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_err_case16),
+    6344                 :            :         /* Measurement hash not requested, returns a measurement_hash*/
+    6345                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_err_case17),
+    6346                 :            :         /* Wrong signature*/
+    6347                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_err_case18),
+    6348                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_err_case19),
+    6349                 :            :         /* Heartbeat not supported, heartbeat period different from 0 sent*/
+    6350                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_err_case20),
+    6351                 :            :         /* Heartbeat supported, heartbeat period different from 0 sent*/
+    6352                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_err_case21),
+    6353                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_err_case22),
+    6354                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_err_case23),
+    6355                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_err_case24),
+    6356                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_err_case25),
+    6357                 :            :         /* Muth Auth requested with Encapsulated request and bit 0 set*/
+    6358                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_err_case26),
+    6359                 :            :         /* Muth Auth requested with implicit get digest and bit 0 set*/
+    6360                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_err_case27),
+    6361                 :            :         /* Muth Auth requested with Encapsulated request and Muth Auth requested with implicit get digest simultaneously*/
+    6362                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_err_case28),
+    6363                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_err_case29),
+    6364                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_err_case30),
+    6365                 :            :         /* Muth Auth requested bit 0 set, but Invalid SlotID in KEY_EXCHANGE_RSP response message*/
+    6366                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_err_case31),
+    6367                 :            :     };
+    6368                 :            : 
+    6369                 :          1 :     libspdm_setup_test_context(&m_libspdm_requester_key_exchange_test_context);
+    6370                 :            : 
+    6371                 :          1 :     return cmocka_run_group_tests(spdm_requester_key_exchange_tests,
+    6372                 :            :                                   libspdm_unit_test_group_setup,
+    6373                 :            :                                   libspdm_unit_test_group_teardown);
+    6374                 :            : }
+    6375                 :            : 
+    6376                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/error_test/negotiate_algorithms_err.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_requester/error_test/negotiate_algorithms_err.c.func-sort-c.html new file mode 100644 index 00000000000..8d6847e5bb0 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/error_test/negotiate_algorithms_err.c.func-sort-c.html @@ -0,0 +1,265 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/error_test/negotiate_algorithms_err.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester/error_test - negotiate_algorithms_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:1767184795.7 %
Date:2024-09-22 08:21:07Functions:4646100.0 %
Branches:809485.1 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_negotiate_algorithms_error_test_main1
libspdm_test_requester_negotiate_algorithms_error_case11
libspdm_test_requester_negotiate_algorithms_error_case101
libspdm_test_requester_negotiate_algorithms_error_case111
libspdm_test_requester_negotiate_algorithms_error_case121
libspdm_test_requester_negotiate_algorithms_error_case131
libspdm_test_requester_negotiate_algorithms_error_case141
libspdm_test_requester_negotiate_algorithms_error_case151
libspdm_test_requester_negotiate_algorithms_error_case161
libspdm_test_requester_negotiate_algorithms_error_case171
libspdm_test_requester_negotiate_algorithms_error_case181
libspdm_test_requester_negotiate_algorithms_error_case191
libspdm_test_requester_negotiate_algorithms_error_case21
libspdm_test_requester_negotiate_algorithms_error_case201
libspdm_test_requester_negotiate_algorithms_error_case211
libspdm_test_requester_negotiate_algorithms_error_case221
libspdm_test_requester_negotiate_algorithms_error_case231
libspdm_test_requester_negotiate_algorithms_error_case241
libspdm_test_requester_negotiate_algorithms_error_case251
libspdm_test_requester_negotiate_algorithms_error_case261
libspdm_test_requester_negotiate_algorithms_error_case271
libspdm_test_requester_negotiate_algorithms_error_case281
libspdm_test_requester_negotiate_algorithms_error_case291
libspdm_test_requester_negotiate_algorithms_error_case31
libspdm_test_requester_negotiate_algorithms_error_case301
libspdm_test_requester_negotiate_algorithms_error_case311
libspdm_test_requester_negotiate_algorithms_error_case341
libspdm_test_requester_negotiate_algorithms_error_case351
libspdm_test_requester_negotiate_algorithms_error_case361
libspdm_test_requester_negotiate_algorithms_error_case371
libspdm_test_requester_negotiate_algorithms_error_case381
libspdm_test_requester_negotiate_algorithms_error_case391
libspdm_test_requester_negotiate_algorithms_error_case41
libspdm_test_requester_negotiate_algorithms_error_case401
libspdm_test_requester_negotiate_algorithms_error_case411
libspdm_test_requester_negotiate_algorithms_error_case421
libspdm_test_requester_negotiate_algorithms_error_case431
libspdm_test_requester_negotiate_algorithms_error_case51
libspdm_test_requester_negotiate_algorithms_error_case61
libspdm_test_requester_negotiate_algorithms_error_case71
libspdm_test_requester_negotiate_algorithms_error_case81
libspdm_test_requester_negotiate_algorithms_error_case91
libspdm_test_requester_negotiate_algorithms_error_case332
libspdm_test_requester_negotiate_algorithms_error_case323
libspdm_requester_negotiate_algorithm_test_receive_message42
libspdm_requester_negotiate_algorithms_test_send_message44
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/error_test/negotiate_algorithms_err.c.func.html b/coverage_log/unit_test/test_spdm_requester/error_test/negotiate_algorithms_err.c.func.html new file mode 100644 index 00000000000..8af2855e5ab --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/error_test/negotiate_algorithms_err.c.func.html @@ -0,0 +1,265 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/error_test/negotiate_algorithms_err.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester/error_test - negotiate_algorithms_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:1767184795.7 %
Date:2024-09-22 08:21:07Functions:4646100.0 %
Branches:809485.1 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_negotiate_algorithm_test_receive_message42
libspdm_requester_negotiate_algorithms_error_test_main1
libspdm_requester_negotiate_algorithms_test_send_message44
libspdm_test_requester_negotiate_algorithms_error_case11
libspdm_test_requester_negotiate_algorithms_error_case101
libspdm_test_requester_negotiate_algorithms_error_case111
libspdm_test_requester_negotiate_algorithms_error_case121
libspdm_test_requester_negotiate_algorithms_error_case131
libspdm_test_requester_negotiate_algorithms_error_case141
libspdm_test_requester_negotiate_algorithms_error_case151
libspdm_test_requester_negotiate_algorithms_error_case161
libspdm_test_requester_negotiate_algorithms_error_case171
libspdm_test_requester_negotiate_algorithms_error_case181
libspdm_test_requester_negotiate_algorithms_error_case191
libspdm_test_requester_negotiate_algorithms_error_case21
libspdm_test_requester_negotiate_algorithms_error_case201
libspdm_test_requester_negotiate_algorithms_error_case211
libspdm_test_requester_negotiate_algorithms_error_case221
libspdm_test_requester_negotiate_algorithms_error_case231
libspdm_test_requester_negotiate_algorithms_error_case241
libspdm_test_requester_negotiate_algorithms_error_case251
libspdm_test_requester_negotiate_algorithms_error_case261
libspdm_test_requester_negotiate_algorithms_error_case271
libspdm_test_requester_negotiate_algorithms_error_case281
libspdm_test_requester_negotiate_algorithms_error_case291
libspdm_test_requester_negotiate_algorithms_error_case31
libspdm_test_requester_negotiate_algorithms_error_case301
libspdm_test_requester_negotiate_algorithms_error_case311
libspdm_test_requester_negotiate_algorithms_error_case323
libspdm_test_requester_negotiate_algorithms_error_case332
libspdm_test_requester_negotiate_algorithms_error_case341
libspdm_test_requester_negotiate_algorithms_error_case351
libspdm_test_requester_negotiate_algorithms_error_case361
libspdm_test_requester_negotiate_algorithms_error_case371
libspdm_test_requester_negotiate_algorithms_error_case381
libspdm_test_requester_negotiate_algorithms_error_case391
libspdm_test_requester_negotiate_algorithms_error_case41
libspdm_test_requester_negotiate_algorithms_error_case401
libspdm_test_requester_negotiate_algorithms_error_case411
libspdm_test_requester_negotiate_algorithms_error_case421
libspdm_test_requester_negotiate_algorithms_error_case431
libspdm_test_requester_negotiate_algorithms_error_case51
libspdm_test_requester_negotiate_algorithms_error_case61
libspdm_test_requester_negotiate_algorithms_error_case71
libspdm_test_requester_negotiate_algorithms_error_case81
libspdm_test_requester_negotiate_algorithms_error_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/error_test/negotiate_algorithms_err.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/error_test/negotiate_algorithms_err.c.gcov.html new file mode 100644 index 00000000000..ee58d6dcfba --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/error_test/negotiate_algorithms_err.c.gcov.html @@ -0,0 +1,3281 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/error_test/negotiate_algorithms_err.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester/error_test - negotiate_algorithms_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:1767184795.7 %
Date:2024-09-22 08:21:07Functions:4646100.0 %
Branches:809485.1 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_requester_lib.h"
+       9                 :            : 
+      10                 :            : #pragma pack(1)
+      11                 :            : typedef struct {
+      12                 :            :     spdm_message_header_t header;
+      13                 :            :     uint16_t length;
+      14                 :            :     uint8_t measurement_specification_sel;
+      15                 :            :     uint8_t other_params_selection;
+      16                 :            :     uint32_t measurement_hash_algo;
+      17                 :            :     uint32_t base_asym_sel;
+      18                 :            :     uint32_t base_hash_sel;
+      19                 :            :     uint8_t reserved2[12];
+      20                 :            :     uint8_t ext_asym_sel_count;
+      21                 :            :     uint8_t ext_hash_sel_count;
+      22                 :            :     uint16_t reserved3;
+      23                 :            :     spdm_negotiate_algorithms_common_struct_table_t struct_table[4];
+      24                 :            : } libspdm_algorithms_response_spdm11_t;
+      25                 :            : #pragma pack()
+      26                 :            : 
+      27                 :            : static size_t m_libspdm_local_buffer_size;
+      28                 :            : static uint8_t m_libspdm_local_buffer[LIBSPDM_MAX_MESSAGE_VCA_BUFFER_SIZE];
+      29                 :            : 
+      30                 :         44 : static libspdm_return_t libspdm_requester_negotiate_algorithms_test_send_message(
+      31                 :            :     void *spdm_context, size_t request_size, const void *request, uint64_t timeout)
+      32                 :            : {
+      33                 :            :     libspdm_test_context_t *spdm_test_context;
+      34                 :            : 
+      35                 :         44 :     spdm_test_context = libspdm_get_test_context();
+      36   [ +  +  -  +  :         44 :     switch (spdm_test_context->case_id) {
+          +  -  +  +  -  
+          +  +  +  +  +  
+          +  +  +  +  +  
+          +  +  +  +  +  
+          +  +  +  +  +  
+          +  +  +  +  +  
+          +  +  +  +  +  
+          +  +  +  +  +  
+                      - ]
+      37                 :          1 :     case 0x1:
+      38                 :          1 :         return LIBSPDM_STATUS_SEND_FAIL;
+      39                 :          1 :     case 0x2:
+      40                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      41                 :          0 :     case 0x3:
+      42                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      43                 :          1 :     case 0x4:
+      44                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      45                 :          1 :     case 0x5:
+      46                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      47                 :          0 :     case 0x6:
+      48                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      49                 :          1 :     case 0x7:
+      50                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      51                 :          1 :     case 0x8:
+      52                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      53                 :          0 :     case 0x9:
+      54                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      55                 :          1 :     case 0xA:
+      56                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      57                 :          1 :     case 0xB:
+      58                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      59                 :          1 :     case 0xC:
+      60                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      61                 :          1 :     case 0xD:
+      62                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      63                 :          1 :     case 0xE:
+      64                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      65                 :          1 :     case 0xF:
+      66                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      67                 :          1 :     case 0x10:
+      68                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      69                 :          1 :     case 0x11:
+      70                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      71                 :          1 :     case 0x12:
+      72                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      73                 :          1 :     case 0x13:
+      74                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      75                 :          1 :     case 0x14:
+      76                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      77                 :          1 :     case 0x15:
+      78                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      79                 :          1 :     case 0x16:
+      80                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      81                 :          1 :     case 0x17:
+      82                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      83                 :          1 :     case 0x18:
+      84                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      85                 :          1 :     case 0x19:
+      86                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      87                 :          1 :     case 0x1A:
+      88                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      89                 :          1 :     case 0x1B:
+      90                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      91                 :          1 :     case 0x1C:
+      92                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      93                 :          1 :     case 0x1D:
+      94                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      95                 :          1 :     case 0x1E:
+      96                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      97                 :          1 :     case 0x1F:
+      98                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      99                 :          3 :     case 0x20: {
+     100                 :          3 :         const uint8_t *ptr = (const uint8_t *)request;
+     101                 :            : 
+     102                 :          3 :         m_libspdm_local_buffer_size = 0;
+     103                 :          3 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     104                 :          3 :                          &ptr[1], request_size - 1);
+     105                 :          3 :         m_libspdm_local_buffer_size += (request_size - 1);
+     106                 :            :     }
+     107                 :          3 :         return LIBSPDM_STATUS_SUCCESS;
+     108                 :          2 :     case 0x21:
+     109                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     110                 :          1 :     case 0x22:
+     111                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     112                 :          1 :     case 0x23:
+     113                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     114                 :          1 :     case 0x24:
+     115                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     116                 :          1 :     case 0x25:
+     117                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     118                 :          1 :     case 0x26:
+     119                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     120                 :          1 :     case 0x27:
+     121                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     122                 :          1 :     case 0x28:
+     123                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     124                 :          1 :     case 0x29:
+     125                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     126                 :          1 :     case 0x2A:
+     127                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     128                 :          1 :     case 0x2B:
+     129                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     130                 :          1 :     case 0x2C:
+     131                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     132                 :          0 :     default:
+     133                 :          0 :         return LIBSPDM_STATUS_SEND_FAIL;
+     134                 :            :     }
+     135                 :            : }
+     136                 :            : 
+     137                 :         42 : static libspdm_return_t libspdm_requester_negotiate_algorithm_test_receive_message(
+     138                 :            :     void *spdm_context, size_t *response_size,
+     139                 :            :     void **response, uint64_t timeout)
+     140                 :            : {
+     141                 :            :     libspdm_test_context_t *spdm_test_context;
+     142                 :            : 
+     143                 :         42 :     spdm_test_context = libspdm_get_test_context();
+     144   [ -  -  -  +  :         42 :     switch (spdm_test_context->case_id) {
+          +  -  +  +  -  
+          +  +  +  +  +  
+          +  +  +  +  +  
+          +  +  +  +  +  
+          +  +  +  +  +  
+          +  +  +  +  +  
+          +  +  +  +  +  
+          +  +  +  +  +  
+                      - ]
+     145                 :          0 :     case 0x1:
+     146                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+     147                 :            : 
+     148                 :          0 :     case 0x2: {
+     149                 :            :         spdm_algorithms_response_t *spdm_response;
+     150                 :            :         size_t spdm_response_size;
+     151                 :            :         size_t transport_header_size;
+     152                 :            : 
+     153                 :          0 :         spdm_response_size = sizeof(spdm_algorithms_response_t);
+     154                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     155                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     156                 :            : 
+     157                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     158                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     159                 :          0 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     160                 :          0 :         spdm_response->header.param1 = 0;
+     161                 :          0 :         spdm_response->header.param2 = 0;
+     162                 :          0 :         spdm_response->length = sizeof(spdm_algorithms_response_t);
+     163                 :          0 :         spdm_response->measurement_specification_sel =
+     164                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     165                 :          0 :         spdm_response->measurement_hash_algo =
+     166                 :            :             m_libspdm_use_measurement_hash_algo;
+     167                 :          0 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+     168                 :          0 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+     169                 :          0 :         spdm_response->ext_asym_sel_count = 0;
+     170                 :          0 :         spdm_response->ext_hash_sel_count = 0;
+     171                 :            : 
+     172                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     173                 :            :                                               false, spdm_response_size,
+     174                 :            :                                               spdm_response,
+     175                 :            :                                               response_size, response);
+     176                 :            :     }
+     177                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     178                 :            : 
+     179                 :          0 :     case 0x3: {
+     180                 :            :         spdm_algorithms_response_t *spdm_response;
+     181                 :            :         size_t spdm_response_size;
+     182                 :            :         size_t transport_header_size;
+     183                 :            : 
+     184                 :          0 :         spdm_response_size = sizeof(spdm_algorithms_response_t);
+     185                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     186                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     187                 :            : 
+     188                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     189                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     190                 :          0 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     191                 :          0 :         spdm_response->header.param1 = 0;
+     192                 :          0 :         spdm_response->header.param2 = 0;
+     193                 :          0 :         spdm_response->length = sizeof(spdm_algorithms_response_t);
+     194                 :          0 :         spdm_response->measurement_specification_sel =
+     195                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     196                 :          0 :         spdm_response->measurement_hash_algo =
+     197                 :            :             m_libspdm_use_measurement_hash_algo;
+     198                 :          0 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+     199                 :          0 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+     200                 :          0 :         spdm_response->ext_asym_sel_count = 0;
+     201                 :          0 :         spdm_response->ext_hash_sel_count = 0;
+     202                 :            : 
+     203                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     204                 :            :                                               false, spdm_response_size,
+     205                 :            :                                               spdm_response,
+     206                 :            :                                               response_size, response);
+     207                 :            :     }
+     208                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     209                 :            : 
+     210                 :          1 :     case 0x4: {
+     211                 :            :         spdm_error_response_t *spdm_response;
+     212                 :            :         size_t spdm_response_size;
+     213                 :            :         size_t transport_header_size;
+     214                 :            : 
+     215                 :          1 :         spdm_response_size = sizeof(spdm_error_response_t);
+     216                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     217                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     218                 :            : 
+     219                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     220                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     221                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     222                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_INVALID_REQUEST;
+     223                 :          1 :         spdm_response->header.param2 = 0;
+     224                 :            : 
+     225                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     226                 :            :                                               false, spdm_response_size,
+     227                 :            :                                               spdm_response,
+     228                 :            :                                               response_size, response);
+     229                 :            :     }
+     230                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     231                 :            : 
+     232                 :          1 :     case 0x5: {
+     233                 :            :         spdm_error_response_t *spdm_response;
+     234                 :            :         size_t spdm_response_size;
+     235                 :            :         size_t transport_header_size;
+     236                 :            : 
+     237                 :          1 :         spdm_response_size = sizeof(spdm_error_response_t);
+     238                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     239                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     240                 :            : 
+     241                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     242                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     243                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     244                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
+     245                 :          1 :         spdm_response->header.param2 = 0;
+     246                 :            : 
+     247                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     248                 :            :                                               false, spdm_response_size,
+     249                 :            :                                               spdm_response,
+     250                 :            :                                               response_size, response);
+     251                 :            :     }
+     252                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     253                 :            : 
+     254                 :          0 :     case 0x6: {
+     255                 :            :         static size_t sub_index1 = 0;
+     256         [ #  # ]:          0 :         if (sub_index1 == 0) {
+     257                 :            :             spdm_error_response_t *spdm_response;
+     258                 :            :             size_t spdm_response_size;
+     259                 :            :             size_t transport_header_size;
+     260                 :            : 
+     261                 :          0 :             spdm_response_size = sizeof(spdm_error_response_t);
+     262                 :          0 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     263                 :          0 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     264                 :            : 
+     265                 :          0 :             libspdm_zero_mem(spdm_response, spdm_response_size);
+     266                 :          0 :             spdm_response->header.spdm_version =
+     267                 :            :                 SPDM_MESSAGE_VERSION_10;
+     268                 :          0 :             spdm_response->header.request_response_code = SPDM_ERROR;
+     269                 :          0 :             spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
+     270                 :          0 :             spdm_response->header.param2 = 0;
+     271                 :            : 
+     272                 :          0 :             libspdm_transport_test_encode_message(
+     273                 :            :                 spdm_context, NULL, false, false,
+     274                 :            :                 spdm_response_size, spdm_response,
+     275                 :            :                 response_size, response);
+     276         [ #  # ]:          0 :         } else if (sub_index1 == 1) {
+     277                 :            :             spdm_algorithms_response_t *spdm_response;
+     278                 :            :             size_t spdm_response_size;
+     279                 :            :             size_t transport_header_size;
+     280                 :            : 
+     281                 :          0 :             spdm_response_size = sizeof(spdm_algorithms_response_t);
+     282                 :          0 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     283                 :          0 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     284                 :            : 
+     285                 :          0 :             libspdm_zero_mem(spdm_response, spdm_response_size);
+     286                 :          0 :             spdm_response->header.spdm_version =
+     287                 :            :                 SPDM_MESSAGE_VERSION_10;
+     288                 :          0 :             spdm_response->header.request_response_code =
+     289                 :            :                 SPDM_ALGORITHMS;
+     290                 :          0 :             spdm_response->header.param1 = 0;
+     291                 :          0 :             spdm_response->header.param2 = 0;
+     292                 :          0 :             spdm_response->length =
+     293                 :            :                 sizeof(spdm_algorithms_response_t);
+     294                 :          0 :             spdm_response->measurement_specification_sel =
+     295                 :            :                 SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     296                 :          0 :             spdm_response->measurement_hash_algo =
+     297                 :            :                 m_libspdm_use_measurement_hash_algo;
+     298                 :          0 :             spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+     299                 :          0 :             spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+     300                 :          0 :             spdm_response->ext_asym_sel_count = 0;
+     301                 :          0 :             spdm_response->ext_hash_sel_count = 0;
+     302                 :            : 
+     303                 :          0 :             libspdm_transport_test_encode_message(
+     304                 :            :                 spdm_context, NULL, false, false,
+     305                 :            :                 spdm_response_size, spdm_response,
+     306                 :            :                 response_size, response);
+     307                 :            :         }
+     308                 :          0 :         sub_index1++;
+     309                 :            :     }
+     310                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     311                 :            : 
+     312                 :          1 :     case 0x7: {
+     313                 :            :         spdm_error_response_t *spdm_response;
+     314                 :            :         size_t spdm_response_size;
+     315                 :            :         size_t transport_header_size;
+     316                 :            : 
+     317                 :          1 :         spdm_response_size = sizeof(spdm_error_response_t);
+     318                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     319                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     320                 :            : 
+     321                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     322                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     323                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     324                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_REQUEST_RESYNCH;
+     325                 :          1 :         spdm_response->header.param2 = 0;
+     326                 :            : 
+     327                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     328                 :            :                                               false, spdm_response_size,
+     329                 :            :                                               spdm_response,
+     330                 :            :                                               response_size, response);
+     331                 :            :     }
+     332                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     333                 :            : 
+     334                 :          1 :     case 0x8: {
+     335                 :            :         spdm_error_response_data_response_not_ready_t *spdm_response;
+     336                 :            :         size_t spdm_response_size;
+     337                 :            :         size_t transport_header_size;
+     338                 :            : 
+     339                 :          1 :         spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
+     340                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     341                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     342                 :            : 
+     343                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     344                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     345                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     346                 :          1 :         spdm_response->header.param1 =
+     347                 :            :             SPDM_ERROR_CODE_RESPONSE_NOT_READY;
+     348                 :          1 :         spdm_response->header.param2 = 0;
+     349                 :          1 :         spdm_response->extend_error_data.rd_exponent = 1;
+     350                 :          1 :         spdm_response->extend_error_data.rd_tm = 2;
+     351                 :          1 :         spdm_response->extend_error_data.request_code =
+     352                 :            :             SPDM_NEGOTIATE_ALGORITHMS;
+     353                 :          1 :         spdm_response->extend_error_data.token = 0;
+     354                 :            : 
+     355                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     356                 :            :                                               false, spdm_response_size,
+     357                 :            :                                               spdm_response,
+     358                 :            :                                               response_size, response);
+     359                 :            :     }
+     360                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     361                 :            : 
+     362                 :          0 :     case 0x9:
+     363                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     364                 :            : 
+     365                 :          1 :     case 0xA: {
+     366                 :            :         spdm_algorithms_response_t *spdm_response;
+     367                 :            :         size_t spdm_response_size;
+     368                 :            :         size_t transport_header_size;
+     369                 :            : 
+     370                 :          1 :         spdm_response_size = sizeof(spdm_algorithms_response_t);
+     371                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     372                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     373                 :            : 
+     374                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     375                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     376                 :          1 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     377                 :          1 :         spdm_response->header.param1 = 0;
+     378                 :          1 :         spdm_response->header.param2 = 0;
+     379                 :          1 :         spdm_response->length = sizeof(spdm_algorithms_response_t);
+     380                 :          1 :         spdm_response->measurement_specification_sel =
+     381                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     382                 :          1 :         spdm_response->measurement_hash_algo = 0;
+     383                 :          1 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+     384                 :          1 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+     385                 :          1 :         spdm_response->ext_asym_sel_count = 0;
+     386                 :          1 :         spdm_response->ext_hash_sel_count = 0;
+     387                 :            : 
+     388                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     389                 :            :                                               false, spdm_response_size,
+     390                 :            :                                               spdm_response,
+     391                 :            :                                               response_size, response);
+     392                 :            :     }
+     393                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     394                 :            : 
+     395                 :          1 :     case 0xB: {
+     396                 :            :         spdm_algorithms_response_t *spdm_response;
+     397                 :            :         size_t spdm_response_size;
+     398                 :            :         size_t transport_header_size;
+     399                 :            : 
+     400                 :          1 :         spdm_response_size = sizeof(spdm_algorithms_response_t);
+     401                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     402                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     403                 :            : 
+     404                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     405                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     406                 :          1 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     407                 :          1 :         spdm_response->header.param1 = 0;
+     408                 :          1 :         spdm_response->header.param2 = 0;
+     409                 :          1 :         spdm_response->length = sizeof(spdm_algorithms_response_t);
+     410                 :          1 :         spdm_response->measurement_specification_sel =
+     411                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     412                 :          1 :         spdm_response->measurement_hash_algo =
+     413                 :            :             m_libspdm_use_measurement_hash_algo;
+     414                 :          1 :         spdm_response->base_asym_sel = 0;
+     415                 :          1 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+     416                 :          1 :         spdm_response->ext_asym_sel_count = 0;
+     417                 :          1 :         spdm_response->ext_hash_sel_count = 0;
+     418                 :            : 
+     419                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     420                 :            :                                               false, spdm_response_size,
+     421                 :            :                                               spdm_response,
+     422                 :            :                                               response_size, response);
+     423                 :            :     }
+     424                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     425                 :            : 
+     426                 :          1 :     case 0xC: {
+     427                 :            :         spdm_algorithms_response_t *spdm_response;
+     428                 :            :         size_t spdm_response_size;
+     429                 :            :         size_t transport_header_size;
+     430                 :            : 
+     431                 :          1 :         spdm_response_size = sizeof(spdm_algorithms_response_t);
+     432                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     433                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     434                 :            : 
+     435                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     436                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     437                 :          1 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     438                 :          1 :         spdm_response->header.param1 = 0;
+     439                 :          1 :         spdm_response->header.param2 = 0;
+     440                 :          1 :         spdm_response->length = sizeof(spdm_algorithms_response_t);
+     441                 :          1 :         spdm_response->measurement_specification_sel =
+     442                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     443                 :          1 :         spdm_response->measurement_hash_algo =
+     444                 :            :             m_libspdm_use_measurement_hash_algo;
+     445                 :          1 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+     446                 :          1 :         spdm_response->base_hash_sel = 0;
+     447                 :          1 :         spdm_response->ext_asym_sel_count = 0;
+     448                 :          1 :         spdm_response->ext_hash_sel_count = 0;
+     449                 :            : 
+     450                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     451                 :            :                                               false, spdm_response_size,
+     452                 :            :                                               spdm_response,
+     453                 :            :                                               response_size, response);
+     454                 :            :     }
+     455                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     456                 :            : 
+     457                 :          1 :     case 0xD:
+     458                 :            :     {
+     459                 :            :         spdm_algorithms_response_t *spdm_response;
+     460                 :            :         size_t spdm_response_size;
+     461                 :            :         size_t transport_header_size;
+     462                 :            : 
+     463                 :          1 :         spdm_response_size = sizeof(spdm_algorithms_response_t);
+     464                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     465                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     466                 :            : 
+     467                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     468                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     469                 :          1 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     470                 :          1 :         spdm_response->header.param1 = 0;
+     471                 :          1 :         spdm_response->header.param2 = 0;
+     472                 :          1 :         spdm_response->length = sizeof(spdm_algorithms_response_t);
+     473                 :          1 :         spdm_response->measurement_specification_sel =
+     474                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     475                 :          1 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+     476                 :          1 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+     477                 :          1 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+     478                 :          1 :         spdm_response->ext_asym_sel_count = 0;
+     479                 :          1 :         spdm_response->ext_hash_sel_count = 0;
+     480                 :            : 
+     481                 :          1 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+     482                 :            :                                                sizeof(spdm_message_header_t), spdm_response,
+     483                 :            :                                                response_size, response);
+     484                 :            :     }
+     485                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     486                 :            : 
+     487                 :          1 :     case 0xE:
+     488                 :            :     {
+     489                 :            :         spdm_algorithms_response_t *spdm_response;
+     490                 :            :         size_t spdm_response_size;
+     491                 :            :         size_t transport_header_size;
+     492                 :            : 
+     493                 :          1 :         spdm_response_size = sizeof(spdm_algorithms_response_t);
+     494                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     495                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     496                 :            : 
+     497                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     498                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     499                 :          1 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     500                 :          1 :         spdm_response->header.param1 = 0;
+     501                 :          1 :         spdm_response->header.param2 = 0;
+     502                 :          1 :         spdm_response->length = sizeof(spdm_algorithms_response_t);
+     503                 :          1 :         spdm_response->measurement_specification_sel =
+     504                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     505                 :          1 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+     506                 :          1 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+     507                 :          1 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+     508                 :            : 
+     509                 :            : 
+     510                 :          1 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+     511                 :            :                                                sizeof(spdm_algorithms_response_t)/2, spdm_response,
+     512                 :            :                                                response_size, response);
+     513                 :            :     }
+     514                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     515                 :            : 
+     516                 :          1 :     case 0xF:
+     517                 :            :     {
+     518                 :            :         spdm_algorithms_response_t *spdm_response;
+     519                 :            :         size_t spdm_response_size;
+     520                 :            :         size_t transport_header_size;
+     521                 :            : 
+     522                 :          1 :         spdm_response_size = sizeof(spdm_algorithms_response_t);
+     523                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     524                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     525                 :            : 
+     526                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     527                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     528                 :          1 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     529                 :          1 :         spdm_response->header.param1 = 0;
+     530                 :          1 :         spdm_response->header.param2 = 0;
+     531                 :          1 :         spdm_response->length = sizeof(spdm_algorithms_response_t);
+     532                 :          1 :         spdm_response->measurement_specification_sel =
+     533                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     534                 :          1 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+     535                 :          1 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+     536                 :          1 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+     537                 :          1 :         spdm_response->ext_asym_sel_count = 2;
+     538                 :          1 :         spdm_response->ext_hash_sel_count = 0;
+     539                 :            : 
+     540                 :          1 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+     541                 :            :                                                spdm_response_size,
+     542                 :            :                                                spdm_response, response_size, response);
+     543                 :            :     }
+     544                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     545                 :            : 
+     546                 :          1 :     case 0x10:
+     547                 :            :     {
+     548                 :            :         spdm_algorithms_response_t *spdm_response;
+     549                 :            :         size_t spdm_response_size;
+     550                 :            :         size_t transport_header_size;
+     551                 :            : 
+     552                 :          1 :         spdm_response_size = sizeof(spdm_algorithms_response_t);
+     553                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     554                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     555                 :            : 
+     556                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     557                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     558                 :          1 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     559                 :          1 :         spdm_response->header.param1 = 0;
+     560                 :          1 :         spdm_response->header.param2 = 0;
+     561                 :          1 :         spdm_response->length = sizeof(spdm_algorithms_response_t);
+     562                 :          1 :         spdm_response->measurement_specification_sel =
+     563                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     564                 :          1 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+     565                 :          1 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+     566                 :          1 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+     567                 :          1 :         spdm_response->ext_asym_sel_count = 0;
+     568                 :          1 :         spdm_response->ext_hash_sel_count = 2;
+     569                 :            : 
+     570                 :          1 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+     571                 :            :                                                spdm_response_size,
+     572                 :            :                                                spdm_response, response_size, response);
+     573                 :            :     }
+     574                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     575                 :            : 
+     576                 :          1 :     case 0x11:
+     577                 :            :     {
+     578                 :            :         spdm_algorithms_response_t *spdm_response;
+     579                 :            :         size_t spdm_response_size;
+     580                 :            :         size_t transport_header_size;
+     581                 :            : 
+     582                 :          1 :         spdm_response_size = sizeof(spdm_algorithms_response_t);
+     583                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     584                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     585                 :            : 
+     586                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     587                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     588                 :          1 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     589                 :          1 :         spdm_response->header.param1 = 0;
+     590                 :          1 :         spdm_response->header.param2 = 0;
+     591                 :          1 :         spdm_response->length = sizeof(spdm_algorithms_response_t);
+     592                 :          1 :         spdm_response->measurement_specification_sel =
+     593                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     594                 :          1 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+     595                 :          1 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo >> 1;
+     596                 :          1 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+     597                 :          1 :         spdm_response->ext_asym_sel_count = 0;
+     598                 :          1 :         spdm_response->ext_hash_sel_count = 0;
+     599                 :            : 
+     600                 :          1 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+     601                 :            :                                                spdm_response_size,
+     602                 :            :                                                spdm_response, response_size, response);
+     603                 :            :     }
+     604                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     605                 :            : 
+     606                 :          1 :     case 0x12:
+     607                 :            :     {
+     608                 :            :         spdm_algorithms_response_t *spdm_response;
+     609                 :            :         size_t spdm_response_size;
+     610                 :            :         size_t transport_header_size;
+     611                 :            : 
+     612                 :          1 :         spdm_response_size = sizeof(spdm_algorithms_response_t);
+     613                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     614                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     615                 :            : 
+     616                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     617                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     618                 :          1 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     619                 :          1 :         spdm_response->header.param1 = 0;
+     620                 :          1 :         spdm_response->header.param2 = 0;
+     621                 :          1 :         spdm_response->length = sizeof(spdm_algorithms_response_t);
+     622                 :          1 :         spdm_response->measurement_specification_sel =
+     623                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     624                 :          1 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+     625                 :          1 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+     626                 :          1 :         spdm_response->base_hash_sel = SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_512;
+     627                 :          1 :         spdm_response->ext_asym_sel_count = 0;
+     628                 :          1 :         spdm_response->ext_hash_sel_count = 0;
+     629                 :            : 
+     630                 :          1 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+     631                 :            :                                                spdm_response_size,
+     632                 :            :                                                spdm_response, response_size, response);
+     633                 :            :     }
+     634                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     635                 :            : 
+     636                 :          1 :     case 0x13:
+     637                 :            :     {
+     638                 :            :         spdm_algorithms_response_t *spdm_response;
+     639                 :            :         size_t spdm_response_size;
+     640                 :            :         size_t transport_header_size;
+     641                 :            : 
+     642                 :          1 :         spdm_response_size = sizeof(spdm_algorithms_response_t);
+     643                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     644                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     645                 :            : 
+     646                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     647                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     648                 :          1 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     649                 :          1 :         spdm_response->header.param1 = 0;
+     650                 :          1 :         spdm_response->header.param2 = 0;
+     651                 :          1 :         spdm_response->length = sizeof(spdm_algorithms_response_t);
+     652                 :          1 :         spdm_response->measurement_specification_sel =
+     653                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     654                 :          1 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo|
+     655                 :            :                                                SPDM_ALGORITHMS_MEASUREMENT_HASH_ALGO_TPM_ALG_SHA3_512;
+     656                 :          1 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+     657                 :          1 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+     658                 :          1 :         spdm_response->ext_asym_sel_count = 0;
+     659                 :          1 :         spdm_response->ext_hash_sel_count = 0;
+     660                 :            : 
+     661                 :          1 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+     662                 :            :                                                spdm_response_size,
+     663                 :            :                                                spdm_response, response_size, response);
+     664                 :            :     }
+     665                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     666                 :            : 
+     667                 :          1 :     case 0x14:
+     668                 :            :     {
+     669                 :            :         spdm_algorithms_response_t *spdm_response;
+     670                 :            :         size_t spdm_response_size;
+     671                 :            :         size_t transport_header_size;
+     672                 :            : 
+     673                 :          1 :         spdm_response_size = sizeof(spdm_algorithms_response_t);
+     674                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     675                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     676                 :            : 
+     677                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     678                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     679                 :          1 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     680                 :          1 :         spdm_response->header.param1 = 0;
+     681                 :          1 :         spdm_response->header.param2 = 0;
+     682                 :          1 :         spdm_response->length = sizeof(spdm_algorithms_response_t);
+     683                 :          1 :         spdm_response->measurement_specification_sel =
+     684                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     685                 :          1 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+     686                 :          1 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo | (m_libspdm_use_asym_algo << 1);
+     687                 :          1 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+     688                 :          1 :         spdm_response->ext_asym_sel_count = 0;
+     689                 :          1 :         spdm_response->ext_hash_sel_count = 0;
+     690                 :            : 
+     691                 :          1 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+     692                 :            :                                                spdm_response_size,
+     693                 :            :                                                spdm_response, response_size, response);
+     694                 :            :     }
+     695                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     696                 :            : 
+     697                 :          1 :     case 0x15:
+     698                 :            :     {
+     699                 :            :         spdm_algorithms_response_t *spdm_response;
+     700                 :            :         size_t spdm_response_size;
+     701                 :            :         size_t transport_header_size;
+     702                 :            : 
+     703                 :          1 :         spdm_response_size = sizeof(spdm_algorithms_response_t);
+     704                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     705                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     706                 :            : 
+     707                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     708                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     709                 :          1 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     710                 :          1 :         spdm_response->header.param1 = 0;
+     711                 :          1 :         spdm_response->header.param2 = 0;
+     712                 :          1 :         spdm_response->length = sizeof(spdm_algorithms_response_t);
+     713                 :          1 :         spdm_response->measurement_specification_sel =
+     714                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     715                 :          1 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+     716                 :          1 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+     717                 :          1 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo|
+     718                 :            :                                        SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_512;
+     719                 :          1 :         spdm_response->ext_asym_sel_count = 0;
+     720                 :          1 :         spdm_response->ext_hash_sel_count = 0;
+     721                 :            : 
+     722                 :          1 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+     723                 :            :                                                spdm_response_size,
+     724                 :            :                                                spdm_response, response_size, response);
+     725                 :            :     }
+     726                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     727                 :            : 
+     728                 :          1 :     case 0x16:
+     729                 :            :     {
+     730                 :            :         libspdm_algorithms_response_spdm11_t *spdm_response;
+     731                 :            :         size_t spdm_response_size;
+     732                 :            :         size_t transport_header_size;
+     733                 :            : 
+     734                 :          1 :         spdm_response_size = sizeof(libspdm_algorithms_response_spdm11_t);
+     735                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     736                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     737                 :            : 
+     738                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     739                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     740                 :          1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     741                 :          1 :         spdm_response->header.param1 = 4;
+     742                 :          1 :         spdm_response->header.param2 = 0;
+     743                 :          1 :         spdm_response->length = sizeof(libspdm_algorithms_response_spdm11_t);
+     744                 :          1 :         spdm_response->measurement_specification_sel =
+     745                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     746                 :          1 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+     747                 :          1 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+     748                 :          1 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+     749                 :          1 :         spdm_response->ext_asym_sel_count = 0;
+     750                 :          1 :         spdm_response->ext_hash_sel_count = 0;
+     751                 :          1 :         spdm_response->struct_table[0].alg_type =
+     752                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE;
+     753                 :          1 :         spdm_response->struct_table[0].alg_count = 0x20;
+     754                 :          1 :         spdm_response->struct_table[0].alg_supported = m_libspdm_use_dhe_algo;
+     755                 :          1 :         spdm_response->struct_table[1].alg_type =
+     756                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD;
+     757                 :          1 :         spdm_response->struct_table[1].alg_count = 0x20;
+     758                 :          1 :         spdm_response->struct_table[1].alg_supported = m_libspdm_use_aead_algo;
+     759                 :          1 :         spdm_response->struct_table[2].alg_type =
+     760                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG;
+     761                 :          1 :         spdm_response->struct_table[2].alg_count = 0x20;
+     762                 :          1 :         spdm_response->struct_table[2].alg_supported = m_libspdm_use_req_asym_algo;
+     763                 :          1 :         spdm_response->struct_table[3].alg_type =
+     764                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE;
+     765                 :          1 :         spdm_response->struct_table[3].alg_count = 0x20;
+     766                 :          1 :         spdm_response->struct_table[3].alg_supported = m_libspdm_use_key_schedule_algo;
+     767                 :            : 
+     768                 :          1 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+     769                 :            :                                                spdm_response_size,
+     770                 :            :                                                spdm_response, response_size, response);
+     771                 :            :     }
+     772                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     773                 :            : 
+     774                 :          1 :     case 0x17:
+     775                 :            :     {
+     776                 :            :         libspdm_algorithms_response_spdm11_t *spdm_response;
+     777                 :            :         size_t spdm_response_size;
+     778                 :            :         size_t transport_header_size;
+     779                 :            : 
+     780                 :          1 :         spdm_response_size = sizeof(libspdm_algorithms_response_spdm11_t);
+     781                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     782                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     783                 :            : 
+     784                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     785                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     786                 :          1 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     787                 :          1 :         spdm_response->header.param1 = 4;
+     788                 :          1 :         spdm_response->header.param2 = 0;
+     789                 :          1 :         spdm_response->length = sizeof(libspdm_algorithms_response_spdm11_t);
+     790                 :          1 :         spdm_response->measurement_specification_sel =
+     791                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     792                 :          1 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+     793                 :          1 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+     794                 :          1 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+     795                 :          1 :         spdm_response->ext_asym_sel_count = 0;
+     796                 :          1 :         spdm_response->ext_hash_sel_count = 0;
+     797                 :          1 :         spdm_response->struct_table[0].alg_type =
+     798                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE;
+     799                 :          1 :         spdm_response->struct_table[0].alg_count = 0x00;
+     800                 :          1 :         spdm_response->struct_table[0].alg_supported = m_libspdm_use_dhe_algo;
+     801                 :          1 :         spdm_response->struct_table[1].alg_type =
+     802                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD;
+     803                 :          1 :         spdm_response->struct_table[1].alg_count = 0x20;
+     804                 :          1 :         spdm_response->struct_table[1].alg_supported = m_libspdm_use_aead_algo;
+     805                 :          1 :         spdm_response->struct_table[2].alg_type =
+     806                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG;
+     807                 :          1 :         spdm_response->struct_table[2].alg_count = 0x20;
+     808                 :          1 :         spdm_response->struct_table[2].alg_supported = m_libspdm_use_req_asym_algo;
+     809                 :          1 :         spdm_response->struct_table[3].alg_type =
+     810                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE;
+     811                 :          1 :         spdm_response->struct_table[3].alg_count = 0x20;
+     812                 :          1 :         spdm_response->struct_table[3].alg_supported = m_libspdm_use_key_schedule_algo;
+     813                 :            : 
+     814                 :          1 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+     815                 :            :                                                spdm_response_size,
+     816                 :            :                                                spdm_response, response_size, response);
+     817                 :            :     }
+     818                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     819                 :            : 
+     820                 :          1 :     case 0x18:
+     821                 :            :     {
+     822                 :            :         libspdm_algorithms_response_spdm11_t *spdm_response;
+     823                 :            :         size_t spdm_response_size;
+     824                 :            :         size_t transport_header_size;
+     825                 :            : 
+     826                 :          1 :         spdm_response_size = sizeof(libspdm_algorithms_response_spdm11_t);
+     827                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     828                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     829                 :            : 
+     830                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     831                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     832                 :          1 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     833                 :          1 :         spdm_response->header.param1 = 4;
+     834                 :          1 :         spdm_response->header.param2 = 0;
+     835                 :          1 :         spdm_response->length = sizeof(libspdm_algorithms_response_spdm11_t);
+     836                 :          1 :         spdm_response->measurement_specification_sel =
+     837                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     838                 :          1 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+     839                 :          1 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+     840                 :          1 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+     841                 :          1 :         spdm_response->ext_asym_sel_count = 0;
+     842                 :          1 :         spdm_response->ext_hash_sel_count = 0;
+     843                 :          1 :         spdm_response->struct_table[0].alg_type =
+     844                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE;
+     845                 :          1 :         spdm_response->struct_table[0].alg_count = 0x20;
+     846                 :          1 :         spdm_response->struct_table[0].alg_supported = SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_521_R1;
+     847                 :          1 :         spdm_response->struct_table[1].alg_type =
+     848                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD;
+     849                 :          1 :         spdm_response->struct_table[1].alg_count = 0x20;
+     850                 :          1 :         spdm_response->struct_table[1].alg_supported = m_libspdm_use_aead_algo;
+     851                 :          1 :         spdm_response->struct_table[2].alg_type =
+     852                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG;
+     853                 :          1 :         spdm_response->struct_table[2].alg_count = 0x20;
+     854                 :          1 :         spdm_response->struct_table[2].alg_supported = m_libspdm_use_req_asym_algo;
+     855                 :          1 :         spdm_response->struct_table[3].alg_type =
+     856                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE;
+     857                 :          1 :         spdm_response->struct_table[3].alg_count = 0x20;
+     858                 :          1 :         spdm_response->struct_table[3].alg_supported = m_libspdm_use_key_schedule_algo;
+     859                 :            : 
+     860                 :          1 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+     861                 :            :                                                spdm_response_size,
+     862                 :            :                                                spdm_response, response_size, response);
+     863                 :            :     }
+     864                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     865                 :            : 
+     866                 :          1 :     case 0x19:
+     867                 :            :     {
+     868                 :            :         libspdm_algorithms_response_spdm11_t *spdm_response;
+     869                 :            :         size_t spdm_response_size;
+     870                 :            :         size_t transport_header_size;
+     871                 :            : 
+     872                 :          1 :         spdm_response_size = sizeof(libspdm_algorithms_response_spdm11_t);
+     873                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     874                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     875                 :            : 
+     876                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     877                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     878                 :          1 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     879                 :          1 :         spdm_response->header.param1 = 4;
+     880                 :          1 :         spdm_response->header.param2 = 0;
+     881                 :          1 :         spdm_response->length = sizeof(libspdm_algorithms_response_spdm11_t);
+     882                 :          1 :         spdm_response->measurement_specification_sel =
+     883                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     884                 :          1 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+     885                 :          1 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+     886                 :          1 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+     887                 :          1 :         spdm_response->ext_asym_sel_count = 0;
+     888                 :          1 :         spdm_response->ext_hash_sel_count = 0;
+     889                 :          1 :         spdm_response->struct_table[0].alg_type =
+     890                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE;
+     891                 :          1 :         spdm_response->struct_table[0].alg_count = 0x20;
+     892                 :          1 :         spdm_response->struct_table[0].alg_supported = m_libspdm_use_dhe_algo;
+     893                 :          1 :         spdm_response->struct_table[1].alg_type =
+     894                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD;
+     895                 :          1 :         spdm_response->struct_table[1].alg_count = 0x20;
+     896                 :          1 :         spdm_response->struct_table[1].alg_supported =
+     897                 :            :             SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_CHACHA20_POLY1305;
+     898                 :          1 :         spdm_response->struct_table[2].alg_type =
+     899                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG;
+     900                 :          1 :         spdm_response->struct_table[2].alg_count = 0x20;
+     901                 :          1 :         spdm_response->struct_table[2].alg_supported = m_libspdm_use_req_asym_algo;
+     902                 :          1 :         spdm_response->struct_table[3].alg_type =
+     903                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE;
+     904                 :          1 :         spdm_response->struct_table[3].alg_count = 0x20;
+     905                 :          1 :         spdm_response->struct_table[3].alg_supported = m_libspdm_use_key_schedule_algo;
+     906                 :            : 
+     907                 :          1 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+     908                 :            :                                                spdm_response_size,
+     909                 :            :                                                spdm_response, response_size, response);
+     910                 :            :     }
+     911                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     912                 :            : 
+     913                 :          1 :     case 0x1A:
+     914                 :            :     {
+     915                 :            :         libspdm_algorithms_response_spdm11_t *spdm_response;
+     916                 :            :         size_t spdm_response_size;
+     917                 :            :         size_t transport_header_size;
+     918                 :            : 
+     919                 :          1 :         spdm_response_size = sizeof(libspdm_algorithms_response_spdm11_t);
+     920                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     921                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     922                 :            : 
+     923                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     924                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     925                 :          1 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     926                 :          1 :         spdm_response->header.param1 = 4;
+     927                 :          1 :         spdm_response->header.param2 = 0;
+     928                 :          1 :         spdm_response->length = sizeof(libspdm_algorithms_response_spdm11_t);
+     929                 :          1 :         spdm_response->measurement_specification_sel =
+     930                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     931                 :          1 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+     932                 :          1 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+     933                 :          1 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+     934                 :          1 :         spdm_response->ext_asym_sel_count = 0;
+     935                 :          1 :         spdm_response->ext_hash_sel_count = 0;
+     936                 :          1 :         spdm_response->struct_table[0].alg_type =
+     937                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE;
+     938                 :          1 :         spdm_response->struct_table[0].alg_count = 0x20;
+     939                 :          1 :         spdm_response->struct_table[0].alg_supported = m_libspdm_use_dhe_algo;
+     940                 :          1 :         spdm_response->struct_table[1].alg_type =
+     941                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD;
+     942                 :          1 :         spdm_response->struct_table[1].alg_count = 0x20;
+     943                 :          1 :         spdm_response->struct_table[1].alg_supported = m_libspdm_use_aead_algo;
+     944                 :          1 :         spdm_response->struct_table[2].alg_type =
+     945                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG;
+     946                 :          1 :         spdm_response->struct_table[2].alg_count = 0x20;
+     947                 :          1 :         spdm_response->struct_table[2].alg_supported =
+     948                 :            :             SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521;
+     949                 :          1 :         spdm_response->struct_table[3].alg_type =
+     950                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE;
+     951                 :          1 :         spdm_response->struct_table[3].alg_count = 0x20;
+     952                 :          1 :         spdm_response->struct_table[3].alg_supported = m_libspdm_use_key_schedule_algo;
+     953                 :            : 
+     954                 :          1 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+     955                 :            :                                                spdm_response_size,
+     956                 :            :                                                spdm_response, response_size, response);
+     957                 :            :     }
+     958                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     959                 :            : 
+     960                 :          1 :     case 0x1B:
+     961                 :            :     {
+     962                 :            :         libspdm_algorithms_response_spdm11_t *spdm_response;
+     963                 :            :         size_t spdm_response_size;
+     964                 :            :         size_t transport_header_size;
+     965                 :            : 
+     966                 :          1 :         spdm_response_size = sizeof(libspdm_algorithms_response_spdm11_t);
+     967                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     968                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     969                 :            : 
+     970                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     971                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     972                 :          1 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     973                 :          1 :         spdm_response->header.param1 = 4;
+     974                 :          1 :         spdm_response->header.param2 = 0;
+     975                 :          1 :         spdm_response->length = sizeof(libspdm_algorithms_response_spdm11_t);
+     976                 :          1 :         spdm_response->measurement_specification_sel =
+     977                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     978                 :          1 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+     979                 :          1 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+     980                 :          1 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+     981                 :          1 :         spdm_response->ext_asym_sel_count = 0;
+     982                 :          1 :         spdm_response->ext_hash_sel_count = 0;
+     983                 :          1 :         spdm_response->struct_table[0].alg_type =
+     984                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE;
+     985                 :          1 :         spdm_response->struct_table[0].alg_count = 0x20;
+     986                 :          1 :         spdm_response->struct_table[0].alg_supported = m_libspdm_use_dhe_algo;
+     987                 :          1 :         spdm_response->struct_table[1].alg_type =
+     988                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD;
+     989                 :          1 :         spdm_response->struct_table[1].alg_count = 0x20;
+     990                 :          1 :         spdm_response->struct_table[1].alg_supported = m_libspdm_use_aead_algo;
+     991                 :          1 :         spdm_response->struct_table[2].alg_type =
+     992                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG;
+     993                 :          1 :         spdm_response->struct_table[2].alg_count = 0x20;
+     994                 :          1 :         spdm_response->struct_table[2].alg_supported = m_libspdm_use_req_asym_algo;
+     995                 :          1 :         spdm_response->struct_table[3].alg_type =
+     996                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE;
+     997                 :          1 :         spdm_response->struct_table[3].alg_count = 0x20;
+     998                 :          1 :         spdm_response->struct_table[3].alg_supported = 0x00000020;
+     999                 :            : 
+    1000                 :          1 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+    1001                 :            :                                                spdm_response_size,
+    1002                 :            :                                                spdm_response, response_size, response);
+    1003                 :            :     }
+    1004                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1005                 :            : 
+    1006                 :          1 :     case 0x1C:
+    1007                 :            :     {
+    1008                 :            :         libspdm_algorithms_response_spdm11_t *spdm_response;
+    1009                 :            :         size_t spdm_response_size;
+    1010                 :            :         size_t transport_header_size;
+    1011                 :            : 
+    1012                 :          1 :         spdm_response_size = sizeof(libspdm_algorithms_response_spdm11_t);
+    1013                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1014                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1015                 :            : 
+    1016                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+    1017                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1018                 :          1 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+    1019                 :          1 :         spdm_response->header.param1 = 4;
+    1020                 :          1 :         spdm_response->header.param2 = 0;
+    1021                 :          1 :         spdm_response->length = sizeof(libspdm_algorithms_response_spdm11_t);
+    1022                 :          1 :         spdm_response->measurement_specification_sel =
+    1023                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1024                 :          1 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+    1025                 :          1 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+    1026                 :          1 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+    1027                 :          1 :         spdm_response->ext_asym_sel_count = 0;
+    1028                 :          1 :         spdm_response->ext_hash_sel_count = 0;
+    1029                 :          1 :         spdm_response->struct_table[0].alg_type =
+    1030                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE;
+    1031                 :          1 :         spdm_response->struct_table[0].alg_count = 0x20;
+    1032                 :          1 :         spdm_response->struct_table[0].alg_supported = m_libspdm_use_dhe_algo |
+    1033                 :            :                                                        SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_521_R1;
+    1034                 :          1 :         spdm_response->struct_table[1].alg_type =
+    1035                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD;
+    1036                 :          1 :         spdm_response->struct_table[1].alg_count = 0x20;
+    1037                 :          1 :         spdm_response->struct_table[1].alg_supported = m_libspdm_use_aead_algo;
+    1038                 :          1 :         spdm_response->struct_table[2].alg_type =
+    1039                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG;
+    1040                 :          1 :         spdm_response->struct_table[2].alg_count = 0x20;
+    1041                 :          1 :         spdm_response->struct_table[2].alg_supported = m_libspdm_use_req_asym_algo;
+    1042                 :          1 :         spdm_response->struct_table[3].alg_type =
+    1043                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE;
+    1044                 :          1 :         spdm_response->struct_table[3].alg_count = 0x20;
+    1045                 :          1 :         spdm_response->struct_table[3].alg_supported = m_libspdm_use_key_schedule_algo;
+    1046                 :            : 
+    1047                 :          1 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+    1048                 :            :                                                spdm_response_size,
+    1049                 :            :                                                spdm_response, response_size, response);
+    1050                 :            :     }
+    1051                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1052                 :            : 
+    1053                 :          1 :     case 0x1D:
+    1054                 :            :     {
+    1055                 :            :         libspdm_algorithms_response_spdm11_t *spdm_response;
+    1056                 :            :         size_t spdm_response_size;
+    1057                 :            :         size_t transport_header_size;
+    1058                 :            : 
+    1059                 :          1 :         spdm_response_size = sizeof(libspdm_algorithms_response_spdm11_t);
+    1060                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1061                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1062                 :            : 
+    1063                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+    1064                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1065                 :          1 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+    1066                 :          1 :         spdm_response->header.param1 = 4;
+    1067                 :          1 :         spdm_response->header.param2 = 0;
+    1068                 :          1 :         spdm_response->length = sizeof(libspdm_algorithms_response_spdm11_t);
+    1069                 :          1 :         spdm_response->measurement_specification_sel =
+    1070                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1071                 :          1 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+    1072                 :          1 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+    1073                 :          1 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+    1074                 :          1 :         spdm_response->ext_asym_sel_count = 0;
+    1075                 :          1 :         spdm_response->ext_hash_sel_count = 0;
+    1076                 :          1 :         spdm_response->struct_table[0].alg_type =
+    1077                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE;
+    1078                 :          1 :         spdm_response->struct_table[0].alg_count = 0x20;
+    1079                 :          1 :         spdm_response->struct_table[0].alg_supported = m_libspdm_use_dhe_algo;
+    1080                 :          1 :         spdm_response->struct_table[1].alg_type =
+    1081                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD;
+    1082                 :          1 :         spdm_response->struct_table[1].alg_count = 0x20;
+    1083                 :          1 :         spdm_response->struct_table[1].alg_supported = m_libspdm_use_aead_algo |
+    1084                 :            :                                                        SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_CHACHA20_POLY1305;
+    1085                 :          1 :         spdm_response->struct_table[2].alg_type =
+    1086                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG;
+    1087                 :          1 :         spdm_response->struct_table[2].alg_count = 0x20;
+    1088                 :          1 :         spdm_response->struct_table[2].alg_supported = m_libspdm_use_req_asym_algo;
+    1089                 :          1 :         spdm_response->struct_table[3].alg_type =
+    1090                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE;
+    1091                 :          1 :         spdm_response->struct_table[3].alg_count = 0x20;
+    1092                 :          1 :         spdm_response->struct_table[3].alg_supported = m_libspdm_use_key_schedule_algo;
+    1093                 :            : 
+    1094                 :          1 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+    1095                 :            :                                                spdm_response_size,
+    1096                 :            :                                                spdm_response, response_size, response);
+    1097                 :            :     }
+    1098                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1099                 :            : 
+    1100                 :          1 :     case 0x1E:
+    1101                 :            :     {
+    1102                 :            :         libspdm_algorithms_response_spdm11_t *spdm_response;
+    1103                 :            :         size_t spdm_response_size;
+    1104                 :            :         size_t transport_header_size;
+    1105                 :            : 
+    1106                 :          1 :         spdm_response_size = sizeof(libspdm_algorithms_response_spdm11_t);
+    1107                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1108                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1109                 :            : 
+    1110                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+    1111                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1112                 :          1 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+    1113                 :          1 :         spdm_response->header.param1 = 4;
+    1114                 :          1 :         spdm_response->header.param2 = 0;
+    1115                 :          1 :         spdm_response->length = sizeof(libspdm_algorithms_response_spdm11_t);
+    1116                 :          1 :         spdm_response->measurement_specification_sel =
+    1117                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1118                 :          1 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+    1119                 :          1 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+    1120                 :          1 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+    1121                 :          1 :         spdm_response->ext_asym_sel_count = 0;
+    1122                 :          1 :         spdm_response->ext_hash_sel_count = 0;
+    1123                 :          1 :         spdm_response->struct_table[0].alg_type =
+    1124                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE;
+    1125                 :          1 :         spdm_response->struct_table[0].alg_count = 0x20;
+    1126                 :          1 :         spdm_response->struct_table[0].alg_supported = m_libspdm_use_dhe_algo;
+    1127                 :          1 :         spdm_response->struct_table[1].alg_type =
+    1128                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD;
+    1129                 :          1 :         spdm_response->struct_table[1].alg_count = 0x20;
+    1130                 :          1 :         spdm_response->struct_table[1].alg_supported = m_libspdm_use_aead_algo;
+    1131                 :          1 :         spdm_response->struct_table[2].alg_type =
+    1132                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG;
+    1133                 :          1 :         spdm_response->struct_table[2].alg_count = 0x20;
+    1134                 :          1 :         spdm_response->struct_table[2].alg_supported = m_libspdm_use_req_asym_algo |
+    1135                 :            :                                                        SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521;
+    1136                 :          1 :         spdm_response->struct_table[3].alg_type =
+    1137                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE;
+    1138                 :          1 :         spdm_response->struct_table[3].alg_count = 0x20;
+    1139                 :          1 :         spdm_response->struct_table[3].alg_supported = m_libspdm_use_key_schedule_algo;
+    1140                 :            : 
+    1141                 :          1 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+    1142                 :            :                                                spdm_response_size,
+    1143                 :            :                                                spdm_response, response_size, response);
+    1144                 :            :     }
+    1145                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1146                 :            : 
+    1147                 :          1 :     case 0x1F:
+    1148                 :            :     {
+    1149                 :            :         libspdm_algorithms_response_spdm11_t *spdm_response;
+    1150                 :            :         size_t spdm_response_size;
+    1151                 :            :         size_t transport_header_size;
+    1152                 :            : 
+    1153                 :          1 :         spdm_response_size = sizeof(libspdm_algorithms_response_spdm11_t);
+    1154                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1155                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1156                 :            : 
+    1157                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+    1158                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1159                 :          1 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+    1160                 :          1 :         spdm_response->header.param1 = 4;
+    1161                 :          1 :         spdm_response->header.param2 = 0;
+    1162                 :          1 :         spdm_response->length = sizeof(libspdm_algorithms_response_spdm11_t);
+    1163                 :          1 :         spdm_response->measurement_specification_sel =
+    1164                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1165                 :          1 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+    1166                 :          1 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+    1167                 :          1 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+    1168                 :          1 :         spdm_response->ext_asym_sel_count = 0;
+    1169                 :          1 :         spdm_response->ext_hash_sel_count = 0;
+    1170                 :          1 :         spdm_response->struct_table[0].alg_type =
+    1171                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE;
+    1172                 :          1 :         spdm_response->struct_table[0].alg_count = 0x20;
+    1173                 :          1 :         spdm_response->struct_table[0].alg_supported = m_libspdm_use_dhe_algo;
+    1174                 :          1 :         spdm_response->struct_table[1].alg_type =
+    1175                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD;
+    1176                 :          1 :         spdm_response->struct_table[1].alg_count = 0x20;
+    1177                 :          1 :         spdm_response->struct_table[1].alg_supported = m_libspdm_use_aead_algo;
+    1178                 :          1 :         spdm_response->struct_table[2].alg_type =
+    1179                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG;
+    1180                 :          1 :         spdm_response->struct_table[2].alg_count = 0x20;
+    1181                 :          1 :         spdm_response->struct_table[2].alg_supported = m_libspdm_use_req_asym_algo;
+    1182                 :          1 :         spdm_response->struct_table[3].alg_type =
+    1183                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE;
+    1184                 :          1 :         spdm_response->struct_table[3].alg_count = 0x20;
+    1185                 :          1 :         spdm_response->struct_table[3].alg_supported = m_libspdm_use_key_schedule_algo | 0x00000020;
+    1186                 :            : 
+    1187                 :          1 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+    1188                 :            :                                                spdm_response_size,
+    1189                 :            :                                                spdm_response, response_size, response);
+    1190                 :            :     }
+    1191                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1192                 :            : 
+    1193                 :          3 :     case 0x20:
+    1194                 :            :     {
+    1195                 :            :         spdm_algorithms_response_t *spdm_response;
+    1196                 :            :         size_t spdm_response_size;
+    1197                 :            :         size_t transport_header_size;
+    1198                 :            : 
+    1199                 :          3 :         spdm_response_size = sizeof(spdm_algorithms_response_t);
+    1200                 :          3 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1201                 :          3 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1202                 :            : 
+    1203                 :          3 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+    1204                 :          3 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+    1205                 :          3 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+    1206                 :          3 :         spdm_response->header.param1 = 0;
+    1207                 :          3 :         spdm_response->header.param2 = 0;
+    1208                 :          3 :         spdm_response->length = sizeof(spdm_algorithms_response_t) - 1;
+    1209                 :          3 :         spdm_response->measurement_specification_sel =
+    1210                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1211                 :          3 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+    1212                 :          3 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+    1213                 :          3 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+    1214                 :          3 :         spdm_response->ext_asym_sel_count = 0;
+    1215                 :          3 :         spdm_response->ext_hash_sel_count = 0;
+    1216                 :            : 
+    1217                 :          3 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1218                 :            :                                               false, spdm_response_size,
+    1219                 :            :                                               spdm_response,
+    1220                 :            :                                               response_size, response);
+    1221                 :            :     }
+    1222                 :          3 :         return LIBSPDM_STATUS_SUCCESS;
+    1223                 :            : 
+    1224                 :          2 :     case 0x21:
+    1225                 :            :     {
+    1226                 :            :         libspdm_algorithms_response_spdm11_t *spdm_response;
+    1227                 :            :         size_t spdm_response_size;
+    1228                 :            :         size_t transport_header_size;
+    1229                 :            : 
+    1230                 :          2 :         spdm_response_size = sizeof(libspdm_algorithms_response_spdm11_t);
+    1231                 :          2 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1232                 :          2 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1233                 :            : 
+    1234                 :          2 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+    1235                 :          2 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+    1236                 :          2 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+    1237                 :          2 :         spdm_response->header.param1 = 4;
+    1238                 :          2 :         spdm_response->header.param2 = 0;
+    1239                 :          2 :         spdm_response->length = sizeof(libspdm_algorithms_response_spdm11_t);
+    1240                 :          2 :         spdm_response->measurement_specification_sel =
+    1241                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1242                 :          2 :         spdm_response->other_params_selection = SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
+    1243                 :          2 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+    1244                 :          2 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+    1245                 :          2 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+    1246                 :          2 :         spdm_response->ext_asym_sel_count = 0;
+    1247                 :          2 :         spdm_response->ext_hash_sel_count = 0;
+    1248                 :          2 :         spdm_response->struct_table[0].alg_type =
+    1249                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE;
+    1250                 :          2 :         spdm_response->struct_table[0].alg_count = 0x25;
+    1251                 :          2 :         spdm_response->struct_table[0].alg_supported = m_libspdm_use_dhe_algo;
+    1252                 :          2 :         spdm_response->struct_table[1].alg_type =
+    1253                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD;
+    1254                 :          2 :         spdm_response->struct_table[1].alg_count = 0x20;
+    1255                 :          2 :         spdm_response->struct_table[1].alg_supported = m_libspdm_use_aead_algo;
+    1256                 :          2 :         spdm_response->struct_table[2].alg_type =
+    1257                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG;
+    1258                 :          2 :         spdm_response->struct_table[2].alg_count = 0x20;
+    1259                 :          2 :         spdm_response->struct_table[2].alg_supported = m_libspdm_use_req_asym_algo;
+    1260                 :          2 :         spdm_response->struct_table[3].alg_type =
+    1261                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE;
+    1262                 :          2 :         spdm_response->struct_table[3].alg_count = 0x20;
+    1263                 :          2 :         spdm_response->struct_table[3].alg_supported = m_libspdm_use_key_schedule_algo;
+    1264                 :            : 
+    1265                 :          2 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+    1266                 :            :                                                spdm_response_size,
+    1267                 :            :                                                spdm_response, response_size, response);
+    1268                 :            :     }
+    1269                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+    1270                 :            : 
+    1271                 :          1 :     case 0x22:
+    1272                 :            :     {
+    1273                 :            :         libspdm_algorithms_response_spdm11_t *spdm_response;
+    1274                 :            :         size_t spdm_response_size;
+    1275                 :            :         size_t transport_header_size;
+    1276                 :            : 
+    1277                 :          1 :         spdm_response_size = sizeof(libspdm_algorithms_response_spdm11_t);
+    1278                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1279                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1280                 :            : 
+    1281                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+    1282                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+    1283                 :          1 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+    1284                 :          1 :         spdm_response->header.param1 = 4;
+    1285                 :          1 :         spdm_response->header.param2 = 0;
+    1286                 :          1 :         spdm_response->length = sizeof(libspdm_algorithms_response_spdm11_t);
+    1287                 :          1 :         spdm_response->measurement_specification_sel = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1288                 :            :         /* Return illegal value for OpaqueDataFmt. */
+    1289                 :          1 :         spdm_response->other_params_selection = 0x3;
+    1290                 :          1 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+    1291                 :          1 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+    1292                 :          1 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+    1293                 :          1 :         spdm_response->ext_asym_sel_count = 0;
+    1294                 :          1 :         spdm_response->ext_hash_sel_count = 0;
+    1295                 :          1 :         spdm_response->struct_table[0].alg_type =
+    1296                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE;
+    1297                 :          1 :         spdm_response->struct_table[0].alg_count = 0x20;
+    1298                 :          1 :         spdm_response->struct_table[0].alg_supported = m_libspdm_use_dhe_algo;
+    1299                 :          1 :         spdm_response->struct_table[1].alg_type =
+    1300                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD;
+    1301                 :          1 :         spdm_response->struct_table[1].alg_count = 0x20;
+    1302                 :          1 :         spdm_response->struct_table[1].alg_supported = m_libspdm_use_aead_algo;
+    1303                 :          1 :         spdm_response->struct_table[2].alg_type =
+    1304                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG;
+    1305                 :          1 :         spdm_response->struct_table[2].alg_count = 0x20;
+    1306                 :          1 :         spdm_response->struct_table[2].alg_supported = m_libspdm_use_req_asym_algo;
+    1307                 :          1 :         spdm_response->struct_table[3].alg_type =
+    1308                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE;
+    1309                 :          1 :         spdm_response->struct_table[3].alg_count = 0x20;
+    1310                 :          1 :         spdm_response->struct_table[3].alg_supported = m_libspdm_use_key_schedule_algo;
+    1311                 :            : 
+    1312                 :          1 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+    1313                 :            :                                                spdm_response_size,
+    1314                 :            :                                                spdm_response, response_size, response);
+    1315                 :            :     }
+    1316                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1317                 :            : 
+    1318                 :          1 :     case 0x23:
+    1319                 :          1 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+    1320                 :            : 
+    1321                 :          1 :     case 0x24:
+    1322                 :            :     {
+    1323                 :            :         libspdm_algorithms_response_spdm11_t *spdm_response;
+    1324                 :            :         size_t spdm_response_size;
+    1325                 :            :         size_t transport_header_size;
+    1326                 :            : 
+    1327                 :          1 :         spdm_response_size = sizeof(libspdm_algorithms_response_spdm11_t);
+    1328                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1329                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1330                 :            : 
+    1331                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+    1332                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1333                 :          1 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+    1334                 :          1 :         spdm_response->header.param1 = 4;
+    1335                 :          1 :         spdm_response->header.param2 = 0;
+    1336                 :          1 :         spdm_response->length = sizeof(libspdm_algorithms_response_spdm11_t);
+    1337                 :            :         /* Invalid measurement specification. */
+    1338                 :          1 :         spdm_response->measurement_specification_sel = 0x02;
+    1339                 :          1 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+    1340                 :          1 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+    1341                 :          1 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+    1342                 :          1 :         spdm_response->ext_asym_sel_count = 0;
+    1343                 :          1 :         spdm_response->ext_hash_sel_count = 0;
+    1344                 :            : 
+    1345                 :          1 :         spdm_response->struct_table[0].alg_type =
+    1346                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE;
+    1347                 :          1 :         spdm_response->struct_table[0].alg_count = 0x20;
+    1348                 :          1 :         spdm_response->struct_table[0].alg_supported = m_libspdm_use_dhe_algo;
+    1349                 :            : 
+    1350                 :          1 :         spdm_response->struct_table[1].alg_type =
+    1351                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD;
+    1352                 :          1 :         spdm_response->struct_table[1].alg_count = 0x20;
+    1353                 :          1 :         spdm_response->struct_table[1].alg_supported = m_libspdm_use_aead_algo;
+    1354                 :            : 
+    1355                 :          1 :         spdm_response->struct_table[2].alg_type =
+    1356                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG;
+    1357                 :          1 :         spdm_response->struct_table[2].alg_count = 0x20;
+    1358                 :          1 :         spdm_response->struct_table[2].alg_supported = m_libspdm_use_req_asym_algo;
+    1359                 :            : 
+    1360                 :          1 :         spdm_response->struct_table[3].alg_type =
+    1361                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE;
+    1362                 :          1 :         spdm_response->struct_table[3].alg_count = 0x20;
+    1363                 :          1 :         spdm_response->struct_table[3].alg_supported = m_libspdm_use_key_schedule_algo;
+    1364                 :            : 
+    1365                 :          1 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+    1366                 :            :                                                spdm_response_size,
+    1367                 :            :                                                spdm_response, response_size, response);
+    1368                 :            :     }
+    1369                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1370                 :            : 
+    1371                 :          1 :     case 0x25: {
+    1372                 :            :         spdm_algorithms_response_t *spdm_response;
+    1373                 :            :         size_t spdm_response_size;
+    1374                 :            :         size_t transport_header_size;
+    1375                 :            : 
+    1376                 :          1 :         spdm_response_size = sizeof(spdm_algorithms_response_t);
+    1377                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1378                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1379                 :            : 
+    1380                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+    1381                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+    1382                 :          1 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+    1383                 :          1 :         spdm_response->header.param1 = 0;
+    1384                 :          1 :         spdm_response->header.param2 = 0;
+    1385                 :          1 :         spdm_response->length = sizeof(spdm_algorithms_response_t);
+    1386                 :            :         /* Two bits set when only one should be set. */
+    1387                 :          1 :         spdm_response->measurement_specification_sel =
+    1388                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF | 0x80;
+    1389                 :          1 :         spdm_response->measurement_hash_algo =
+    1390                 :            :             m_libspdm_use_measurement_hash_algo;
+    1391                 :          1 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+    1392                 :          1 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+    1393                 :          1 :         spdm_response->ext_asym_sel_count = 0;
+    1394                 :          1 :         spdm_response->ext_hash_sel_count = 0;
+    1395                 :            : 
+    1396                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1397                 :            :                                               false, spdm_response_size,
+    1398                 :            :                                               spdm_response,
+    1399                 :            :                                               response_size, response);
+    1400                 :            :     }
+    1401                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1402                 :            : 
+    1403                 :          1 :     case 0x26: {
+    1404                 :            :         spdm_algorithms_response_t *spdm_response;
+    1405                 :            :         size_t spdm_response_size;
+    1406                 :            :         size_t transport_header_size;
+    1407                 :            : 
+    1408                 :          1 :         spdm_response_size = sizeof(spdm_algorithms_response_t);
+    1409                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1410                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1411                 :            : 
+    1412                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+    1413                 :            : 
+    1414                 :            :         /* Incorrect version; should be 1.0. */
+    1415                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1416                 :          1 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+    1417                 :          1 :         spdm_response->header.param1 = 0;
+    1418                 :          1 :         spdm_response->header.param2 = 0;
+    1419                 :          1 :         spdm_response->length = sizeof(spdm_algorithms_response_t);
+    1420                 :          1 :         spdm_response->measurement_specification_sel =
+    1421                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1422                 :          1 :         spdm_response->measurement_hash_algo =
+    1423                 :            :             m_libspdm_use_measurement_hash_algo;
+    1424                 :          1 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+    1425                 :          1 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+    1426                 :          1 :         spdm_response->ext_asym_sel_count = 0;
+    1427                 :          1 :         spdm_response->ext_hash_sel_count = 0;
+    1428                 :            : 
+    1429                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1430                 :            :                                               false, spdm_response_size,
+    1431                 :            :                                               spdm_response,
+    1432                 :            :                                               response_size, response);
+    1433                 :            :     }
+    1434                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1435                 :            : 
+    1436                 :          1 :     case 0x27: {
+    1437                 :            :         libspdm_algorithms_response_spdm11_t *spdm_response;
+    1438                 :            :         size_t spdm_response_size;
+    1439                 :            :         size_t transport_header_size;
+    1440                 :            : 
+    1441                 :          1 :         spdm_response_size = sizeof(libspdm_algorithms_response_spdm11_t);
+    1442                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1443                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1444                 :            : 
+    1445                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+    1446                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1447                 :          1 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+    1448                 :          1 :         spdm_response->header.param1 = 4;
+    1449                 :          1 :         spdm_response->header.param2 = 0;
+    1450                 :          1 :         spdm_response->length = sizeof(libspdm_algorithms_response_spdm11_t);
+    1451                 :          1 :         spdm_response->measurement_specification_sel =
+    1452                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1453                 :          1 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+    1454                 :          1 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+    1455                 :          1 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+    1456                 :          1 :         spdm_response->ext_asym_sel_count = 0;
+    1457                 :          1 :         spdm_response->ext_hash_sel_count = 0;
+    1458                 :          1 :         spdm_response->struct_table[0].alg_type =
+    1459                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE;
+    1460                 :          1 :         spdm_response->struct_table[0].alg_count = 0x20;
+    1461                 :          1 :         spdm_response->struct_table[0].alg_supported = m_libspdm_use_dhe_algo;
+    1462                 :            :         /* Reserved alg_type value. */
+    1463                 :          1 :         spdm_response->struct_table[1].alg_type = 0;
+    1464                 :          1 :         spdm_response->struct_table[1].alg_count = 0x20;
+    1465                 :          1 :         spdm_response->struct_table[1].alg_supported = m_libspdm_use_aead_algo;
+    1466                 :          1 :         spdm_response->struct_table[2].alg_type =
+    1467                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG;
+    1468                 :          1 :         spdm_response->struct_table[2].alg_count = 0x20;
+    1469                 :          1 :         spdm_response->struct_table[2].alg_supported = m_libspdm_use_req_asym_algo;
+    1470                 :          1 :         spdm_response->struct_table[3].alg_type =
+    1471                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE;
+    1472                 :          1 :         spdm_response->struct_table[3].alg_count = 0x20;
+    1473                 :          1 :         spdm_response->struct_table[3].alg_supported = m_libspdm_use_key_schedule_algo;
+    1474                 :            : 
+    1475                 :          1 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+    1476                 :            :                                                spdm_response_size,
+    1477                 :            :                                                spdm_response, response_size, response);
+    1478                 :            :     }
+    1479                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1480                 :            : 
+    1481                 :          1 :     case 0x28: {
+    1482                 :            :         libspdm_algorithms_response_spdm11_t* spdm_response;
+    1483                 :            :         size_t spdm_response_size;
+    1484                 :            :         size_t transport_header_size;
+    1485                 :            : 
+    1486                 :          1 :         spdm_response_size = sizeof(libspdm_algorithms_response_spdm11_t);
+    1487                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1488                 :          1 :         spdm_response = (void*)((uint8_t*)*response + transport_header_size);
+    1489                 :            : 
+    1490                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+    1491                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1492                 :          1 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+    1493                 :          1 :         spdm_response->header.param1 = 4;
+    1494                 :          1 :         spdm_response->header.param2 = 0;
+    1495                 :          1 :         spdm_response->length = sizeof(libspdm_algorithms_response_spdm11_t);
+    1496                 :          1 :         spdm_response->measurement_specification_sel =
+    1497                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1498                 :          1 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+    1499                 :          1 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+    1500                 :          1 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+    1501                 :          1 :         spdm_response->ext_asym_sel_count = 0;
+    1502                 :          1 :         spdm_response->ext_hash_sel_count = 0;
+    1503                 :          1 :         spdm_response->struct_table[0].alg_type =
+    1504                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE;
+    1505                 :          1 :         spdm_response->struct_table[0].alg_count = 0x20;
+    1506                 :          1 :         spdm_response->struct_table[0].alg_supported = m_libspdm_use_dhe_algo;
+    1507                 :            :         /* Redundant alg_type value. */
+    1508                 :          1 :         spdm_response->struct_table[1].alg_type =
+    1509                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE;
+    1510                 :          1 :         spdm_response->struct_table[1].alg_count = 0x20;
+    1511                 :          1 :         spdm_response->struct_table[1].alg_supported = m_libspdm_use_dhe_algo;
+    1512                 :          1 :         spdm_response->struct_table[2].alg_type =
+    1513                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG;
+    1514                 :          1 :         spdm_response->struct_table[2].alg_count = 0x20;
+    1515                 :          1 :         spdm_response->struct_table[2].alg_supported = m_libspdm_use_req_asym_algo;
+    1516                 :          1 :         spdm_response->struct_table[3].alg_type =
+    1517                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE;
+    1518                 :          1 :         spdm_response->struct_table[3].alg_count = 0x20;
+    1519                 :          1 :         spdm_response->struct_table[3].alg_supported = m_libspdm_use_key_schedule_algo;
+    1520                 :            : 
+    1521                 :          1 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+    1522                 :            :                                                spdm_response_size,
+    1523                 :            :                                                spdm_response, response_size, response);
+    1524                 :            :     }
+    1525                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1526                 :            : 
+    1527                 :          1 :     case 0x29: {
+    1528                 :            :         libspdm_algorithms_response_spdm11_t* spdm_response;
+    1529                 :            :         size_t spdm_response_size;
+    1530                 :            :         size_t transport_header_size;
+    1531                 :            : 
+    1532                 :          1 :         spdm_response_size = sizeof(libspdm_algorithms_response_spdm11_t);
+    1533                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1534                 :          1 :         spdm_response = (void*)((uint8_t*)*response + transport_header_size);
+    1535                 :            : 
+    1536                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+    1537                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1538                 :          1 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+    1539                 :          1 :         spdm_response->header.param1 = 4;
+    1540                 :          1 :         spdm_response->header.param2 = 0;
+    1541                 :          1 :         spdm_response->length = sizeof(libspdm_algorithms_response_spdm11_t);
+    1542                 :          1 :         spdm_response->measurement_specification_sel =
+    1543                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1544                 :          1 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+    1545                 :          1 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+    1546                 :          1 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+    1547                 :          1 :         spdm_response->ext_asym_sel_count = 0;
+    1548                 :          1 :         spdm_response->ext_hash_sel_count = 0;
+    1549                 :          1 :         spdm_response->struct_table[0].alg_type =
+    1550                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE;
+    1551                 :          1 :         spdm_response->struct_table[0].alg_count = 0x20;
+    1552                 :          1 :         spdm_response->struct_table[0].alg_supported = m_libspdm_use_dhe_algo;
+    1553                 :          1 :         spdm_response->struct_table[1].alg_type =
+    1554                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG;
+    1555                 :          1 :         spdm_response->struct_table[1].alg_count = 0x20;
+    1556                 :          1 :         spdm_response->struct_table[1].alg_supported = m_libspdm_use_req_asym_algo;
+    1557                 :          1 :         spdm_response->struct_table[2].alg_type =
+    1558                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE;
+    1559                 :          1 :         spdm_response->struct_table[2].alg_count = 0x20;
+    1560                 :          1 :         spdm_response->struct_table[2].alg_supported = m_libspdm_use_key_schedule_algo;
+    1561                 :            :         /* Decreasing alg_type value. */
+    1562                 :          1 :         spdm_response->struct_table[3].alg_type =
+    1563                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD;
+    1564                 :          1 :         spdm_response->struct_table[3].alg_count = 0x20;
+    1565                 :          1 :         spdm_response->struct_table[3].alg_supported = m_libspdm_use_aead_algo;
+    1566                 :            : 
+    1567                 :          1 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+    1568                 :            :                                                spdm_response_size,
+    1569                 :            :                                                spdm_response, response_size, response);
+    1570                 :            :     }
+    1571                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1572                 :            : 
+    1573                 :          1 :     case 0x2A: {
+    1574                 :            :         spdm_algorithms_response_t *spdm_response;
+    1575                 :            :         size_t spdm_response_size;
+    1576                 :            :         size_t transport_header_size;
+    1577                 :            : 
+    1578                 :          1 :         spdm_response_size = sizeof(spdm_algorithms_response_t);
+    1579                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1580                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1581                 :            : 
+    1582                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+    1583                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+    1584                 :          1 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+    1585                 :          1 :         spdm_response->header.param1 = 0;
+    1586                 :          1 :         spdm_response->header.param2 = 0;
+    1587                 :          1 :         spdm_response->length = sizeof(spdm_algorithms_response_t);
+    1588                 :          1 :         spdm_response->measurement_specification_sel =
+    1589                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1590                 :            :         /* Two bits set when only one should be set. */
+    1591                 :          1 :         spdm_response->other_params_selection =
+    1592                 :            :             SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_0 | SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
+    1593                 :          1 :         spdm_response->measurement_hash_algo =
+    1594                 :            :             m_libspdm_use_measurement_hash_algo;
+    1595                 :          1 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+    1596                 :          1 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+    1597                 :          1 :         spdm_response->ext_asym_sel_count = 0;
+    1598                 :          1 :         spdm_response->ext_hash_sel_count = 0;
+    1599                 :            : 
+    1600                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1601                 :            :                                               false, spdm_response_size,
+    1602                 :            :                                               spdm_response,
+    1603                 :            :                                               response_size, response);
+    1604                 :            :     }
+    1605                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1606                 :            : 
+    1607                 :          1 :     case 0x2B: {
+    1608                 :            :         libspdm_algorithms_response_spdm11_t* spdm_response;
+    1609                 :            :         size_t spdm_response_size;
+    1610                 :            :         size_t transport_header_size;
+    1611                 :            : 
+    1612                 :          1 :         spdm_response_size = sizeof(libspdm_algorithms_response_spdm11_t);
+    1613                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1614                 :          1 :         spdm_response = (void*)((uint8_t*)*response + transport_header_size);
+    1615                 :            : 
+    1616                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+    1617                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1618                 :          1 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+    1619                 :          1 :         spdm_response->header.param1 = 4;
+    1620                 :          1 :         spdm_response->header.param2 = 0;
+    1621                 :          1 :         spdm_response->length = sizeof(libspdm_algorithms_response_spdm11_t);
+    1622                 :          1 :         spdm_response->measurement_specification_sel =
+    1623                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1624                 :          1 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+    1625                 :          1 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+    1626                 :          1 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+    1627                 :          1 :         spdm_response->ext_asym_sel_count = 0;
+    1628                 :          1 :         spdm_response->ext_hash_sel_count = 0;
+    1629                 :          1 :         spdm_response->struct_table[0].alg_type =
+    1630                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE - 1;
+    1631                 :          1 :         spdm_response->struct_table[0].alg_count = 0x20;
+    1632                 :          1 :         spdm_response->struct_table[0].alg_supported = m_libspdm_use_dhe_algo;
+    1633                 :            :         /* Redundant alg_type value. */
+    1634                 :          1 :         spdm_response->struct_table[1].alg_type =
+    1635                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE;
+    1636                 :          1 :         spdm_response->struct_table[1].alg_count = 0x20;
+    1637                 :          1 :         spdm_response->struct_table[1].alg_supported = m_libspdm_use_dhe_algo;
+    1638                 :          1 :         spdm_response->struct_table[2].alg_type =
+    1639                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD;
+    1640                 :          1 :         spdm_response->struct_table[2].alg_count = 0x20;
+    1641                 :          1 :         spdm_response->struct_table[2].alg_supported = m_libspdm_use_aead_algo;
+    1642                 :          1 :         spdm_response->struct_table[3].alg_type =
+    1643                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG;
+    1644                 :          1 :         spdm_response->struct_table[3].alg_count = 0x20;
+    1645                 :          1 :         spdm_response->struct_table[3].alg_supported = m_libspdm_use_req_asym_algo;
+    1646                 :            : 
+    1647                 :          1 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+    1648                 :            :                                                spdm_response_size,
+    1649                 :            :                                                spdm_response, response_size, response);
+    1650                 :            :     }
+    1651                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1652                 :            : 
+    1653                 :          1 :     case 0x2C: {
+    1654                 :            :         libspdm_algorithms_response_spdm11_t* spdm_response;
+    1655                 :            :         size_t spdm_response_size;
+    1656                 :            :         size_t transport_header_size;
+    1657                 :            : 
+    1658                 :          1 :         spdm_response_size = sizeof(libspdm_algorithms_response_spdm11_t);
+    1659                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1660                 :          1 :         spdm_response = (void*)((uint8_t*)*response + transport_header_size);
+    1661                 :            : 
+    1662                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+    1663                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1664                 :          1 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+    1665                 :          1 :         spdm_response->header.param1 = 4;
+    1666                 :          1 :         spdm_response->header.param2 = 0;
+    1667                 :          1 :         spdm_response->length = sizeof(libspdm_algorithms_response_spdm11_t);
+    1668                 :          1 :         spdm_response->measurement_specification_sel =
+    1669                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1670                 :          1 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+    1671                 :          1 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+    1672                 :          1 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+    1673                 :          1 :         spdm_response->ext_asym_sel_count = 0;
+    1674                 :          1 :         spdm_response->ext_hash_sel_count = 0;
+    1675                 :          1 :         spdm_response->struct_table[0].alg_type =
+    1676                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD;
+    1677                 :          1 :         spdm_response->struct_table[0].alg_count = 0x20;
+    1678                 :          1 :         spdm_response->struct_table[0].alg_supported = m_libspdm_use_aead_algo;
+    1679                 :            :         /* Redundant alg_type value. */
+    1680                 :          1 :         spdm_response->struct_table[1].alg_type =
+    1681                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG;
+    1682                 :          1 :         spdm_response->struct_table[1].alg_count = 0x20;
+    1683                 :          1 :         spdm_response->struct_table[1].alg_supported = m_libspdm_use_req_asym_algo;
+    1684                 :          1 :         spdm_response->struct_table[2].alg_type =
+    1685                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE;
+    1686                 :          1 :         spdm_response->struct_table[2].alg_count = 0x20;
+    1687                 :          1 :         spdm_response->struct_table[2].alg_supported = m_libspdm_use_key_schedule_algo;
+    1688                 :          1 :         spdm_response->struct_table[3].alg_type =
+    1689                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE + 1;
+    1690                 :          1 :         spdm_response->struct_table[3].alg_count = 0x20;
+    1691                 :          1 :         spdm_response->struct_table[3].alg_supported = m_libspdm_use_key_schedule_algo;
+    1692                 :            : 
+    1693                 :          1 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+    1694                 :            :                                                spdm_response_size,
+    1695                 :            :                                                spdm_response, response_size, response);
+    1696                 :            :     }
+    1697                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1698                 :            : 
+    1699                 :          0 :     default:
+    1700                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+    1701                 :            :     }
+    1702                 :            : }
+    1703                 :            : 
+    1704                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case1(void **state)
+    1705                 :            : {
+    1706                 :            :     libspdm_return_t status;
+    1707                 :            :     libspdm_test_context_t *spdm_test_context;
+    1708                 :            :     libspdm_context_t *spdm_context;
+    1709                 :            : 
+    1710                 :          1 :     spdm_test_context = *state;
+    1711                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1712                 :          1 :     spdm_test_context->case_id = 0x1;
+    1713                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1714                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1715                 :          1 :     spdm_context->connection_info.connection_state =
+    1716                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1717                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    1718                 :            :         m_libspdm_use_measurement_hash_algo;
+    1719                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1720                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1721                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1722                 :            : 
+    1723                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    1724                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SEND_FAIL);
+    1725                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1726                 :            :     assert_int_equal(spdm_context->transcript.message_a.buffer_size, 0);
+    1727                 :            : #endif
+    1728                 :          1 : }
+    1729                 :            : 
+    1730                 :            : /**
+    1731                 :            :  * Test 2: Unable to acquire sender buffer.
+    1732                 :            :  * Expected behavior: returns with status LIBSPDM_STATUS_ACQUIRE_FAIL.
+    1733                 :            :  **/
+    1734                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case2(void **state)
+    1735                 :            : {
+    1736                 :            :     libspdm_return_t status;
+    1737                 :            :     libspdm_test_context_t *spdm_test_context;
+    1738                 :            :     libspdm_context_t *spdm_context;
+    1739                 :            : 
+    1740                 :          1 :     spdm_test_context = *state;
+    1741                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1742                 :          1 :     spdm_test_context->case_id = 0x1;
+    1743                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1744                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1745                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1746                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    1747                 :            :         m_libspdm_use_measurement_hash_algo;
+    1748                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1749                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1750                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1751                 :            : 
+    1752                 :          1 :     libspdm_force_error (LIBSPDM_ERR_ACQUIRE_SENDER_BUFFER);
+    1753                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    1754                 :          1 :     libspdm_release_error (LIBSPDM_ERR_ACQUIRE_SENDER_BUFFER);
+    1755                 :            : 
+    1756                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_ACQUIRE_FAIL);
+    1757                 :          1 : }
+    1758                 :            : 
+    1759                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case3(void **state)
+    1760                 :            : {
+    1761                 :            :     libspdm_return_t status;
+    1762                 :            :     libspdm_test_context_t *spdm_test_context;
+    1763                 :            :     libspdm_context_t *spdm_context;
+    1764                 :            : 
+    1765                 :          1 :     spdm_test_context = *state;
+    1766                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1767                 :          1 :     spdm_test_context->case_id = 0x3;
+    1768                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1769                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1770                 :          1 :     spdm_context->connection_info.connection_state =
+    1771                 :            :         LIBSPDM_CONNECTION_STATE_NOT_STARTED;
+    1772                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    1773                 :            :         m_libspdm_use_measurement_hash_algo;
+    1774                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1775                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1776                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1777                 :            : 
+    1778                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    1779                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_STATE_LOCAL);
+    1780                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1781                 :            :     assert_int_equal(spdm_context->transcript.message_a.buffer_size, 0);
+    1782                 :            : #endif
+    1783                 :          1 : }
+    1784                 :            : 
+    1785                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case4(void **state)
+    1786                 :            : {
+    1787                 :            :     libspdm_return_t status;
+    1788                 :            :     libspdm_test_context_t *spdm_test_context;
+    1789                 :            :     libspdm_context_t *spdm_context;
+    1790                 :            : 
+    1791                 :          1 :     spdm_test_context = *state;
+    1792                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1793                 :          1 :     spdm_test_context->case_id = 0x4;
+    1794                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1795                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1796                 :          1 :     spdm_context->connection_info.connection_state =
+    1797                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1798                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    1799                 :            :         m_libspdm_use_measurement_hash_algo;
+    1800                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1801                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1802                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1803                 :            : 
+    1804                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    1805                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_ERROR_PEER);
+    1806                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1807                 :            :     assert_int_equal(spdm_context->transcript.message_a.buffer_size, 0);
+    1808                 :            : #endif
+    1809                 :          1 : }
+    1810                 :            : 
+    1811                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case5(void **state)
+    1812                 :            : {
+    1813                 :            :     libspdm_return_t status;
+    1814                 :            :     libspdm_test_context_t *spdm_test_context;
+    1815                 :            :     libspdm_context_t *spdm_context;
+    1816                 :            : 
+    1817                 :          1 :     spdm_test_context = *state;
+    1818                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1819                 :          1 :     spdm_test_context->case_id = 0x5;
+    1820                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1821                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1822                 :          1 :     spdm_context->connection_info.connection_state =
+    1823                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1824                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    1825                 :            :         m_libspdm_use_measurement_hash_algo;
+    1826                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1827                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1828                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1829                 :            : 
+    1830                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    1831                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_BUSY_PEER);
+    1832                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1833                 :            :     assert_int_equal(spdm_context->transcript.message_a.buffer_size, 0);
+    1834                 :            : #endif
+    1835                 :          1 : }
+    1836                 :            : 
+    1837                 :            : /**
+    1838                 :            :  * Test 6: Unable to acquire receiver buffer.
+    1839                 :            :  * Expected behavior: returns with status LIBSPDM_STATUS_ACQUIRE_FAIL.
+    1840                 :            :  **/
+    1841                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case6(void **state)
+    1842                 :            : {
+    1843                 :            :     libspdm_return_t status;
+    1844                 :            :     libspdm_test_context_t *spdm_test_context;
+    1845                 :            :     libspdm_context_t *spdm_context;
+    1846                 :            : 
+    1847                 :          1 :     spdm_test_context = *state;
+    1848                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1849                 :          1 :     spdm_test_context->case_id = 0x2;
+    1850                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1851                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1852                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1853                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    1854                 :            :         m_libspdm_use_measurement_hash_algo;
+    1855                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1856                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1857                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1858                 :            : 
+    1859                 :          1 :     libspdm_force_error (LIBSPDM_ERR_ACQUIRE_RECEIVER_BUFFER);
+    1860                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    1861                 :          1 :     libspdm_release_error (LIBSPDM_ERR_ACQUIRE_RECEIVER_BUFFER);
+    1862                 :            : 
+    1863                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_ACQUIRE_FAIL);
+    1864                 :          1 : }
+    1865                 :            : 
+    1866                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case7(void **state)
+    1867                 :            : {
+    1868                 :            :     libspdm_return_t status;
+    1869                 :            :     libspdm_test_context_t *spdm_test_context;
+    1870                 :            :     libspdm_context_t *spdm_context;
+    1871                 :            : 
+    1872                 :          1 :     spdm_test_context = *state;
+    1873                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1874                 :          1 :     spdm_test_context->case_id = 0x7;
+    1875                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1876                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1877                 :          1 :     spdm_context->connection_info.connection_state =
+    1878                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1879                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    1880                 :            :         m_libspdm_use_measurement_hash_algo;
+    1881                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1882                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1883                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1884                 :            : 
+    1885                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    1886                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_RESYNCH_PEER);
+    1887                 :          1 :     assert_int_equal(spdm_context->connection_info.connection_state,
+    1888                 :            :                      LIBSPDM_CONNECTION_STATE_NOT_STARTED);
+    1889                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1890                 :            :     assert_int_equal(spdm_context->transcript.message_a.buffer_size, 0);
+    1891                 :            : #endif
+    1892                 :          1 : }
+    1893                 :            : 
+    1894                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case8(void **state)
+    1895                 :            : {
+    1896                 :            :     libspdm_return_t status;
+    1897                 :            :     libspdm_test_context_t *spdm_test_context;
+    1898                 :            :     libspdm_context_t *spdm_context;
+    1899                 :            : 
+    1900                 :          1 :     spdm_test_context = *state;
+    1901                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1902                 :          1 :     spdm_test_context->case_id = 0x8;
+    1903                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1904                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1905                 :          1 :     spdm_context->connection_info.connection_state =
+    1906                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1907                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    1908                 :            :         m_libspdm_use_measurement_hash_algo;
+    1909                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1910                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1911                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1912                 :            : 
+    1913                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    1914                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_NOT_READY_PEER);
+    1915                 :          1 : }
+    1916                 :            : 
+    1917                 :            : /**
+    1918                 :            :  * Test 9: Unable to receive response from Responder.
+    1919                 :            :  * Expected behavior: returns with status LIBSPDM_STATUS_RECEIVE_FAIL.
+    1920                 :            :  **/
+    1921                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case9(void **state)
+    1922                 :            : {
+    1923                 :            :     libspdm_return_t status;
+    1924                 :            :     libspdm_test_context_t *spdm_test_context;
+    1925                 :            :     libspdm_context_t *spdm_context;
+    1926                 :            : 
+    1927                 :          1 :     spdm_test_context = *state;
+    1928                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1929                 :          1 :     spdm_test_context->case_id = 0x23;
+    1930                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1931                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1932                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1933                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    1934                 :            :         m_libspdm_use_measurement_hash_algo;
+    1935                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1936                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1937                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1938                 :            : 
+    1939                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    1940                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_RECEIVE_FAIL);
+    1941                 :          1 : }
+    1942                 :            : 
+    1943                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case10(void **state)
+    1944                 :            : {
+    1945                 :            :     libspdm_return_t status;
+    1946                 :            :     libspdm_test_context_t *spdm_test_context;
+    1947                 :            :     libspdm_context_t *spdm_context;
+    1948                 :            : 
+    1949                 :          1 :     spdm_test_context = *state;
+    1950                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1951                 :          1 :     spdm_test_context->case_id = 0xA;
+    1952                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1953                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1954                 :          1 :     spdm_context->connection_info.connection_state =
+    1955                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1956                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    1957                 :            :         m_libspdm_use_measurement_hash_algo;
+    1958                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    1959                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1960                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1961                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1962                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo = 0;
+    1963                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = 0;
+    1964                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = 0;
+    1965                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1966                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG;
+    1967                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1968                 :            : 
+    1969                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    1970                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_NEGOTIATION_FAIL);
+    1971                 :          1 :     assert_int_equal(
+    1972                 :            :         spdm_context->connection_info.algorithm.measurement_hash_algo,
+    1973                 :            :         0);
+    1974                 :          1 : }
+    1975                 :            : 
+    1976                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case11(void **state)
+    1977                 :            : {
+    1978                 :            :     libspdm_return_t status;
+    1979                 :            :     libspdm_test_context_t *spdm_test_context;
+    1980                 :            :     libspdm_context_t *spdm_context;
+    1981                 :            : 
+    1982                 :          1 :     spdm_test_context = *state;
+    1983                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1984                 :          1 :     spdm_test_context->case_id = 0xB;
+    1985                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1986                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1987                 :          1 :     spdm_context->connection_info.connection_state =
+    1988                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1989                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    1990                 :            :         m_libspdm_use_measurement_hash_algo;
+    1991                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1992                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1993                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo = 0;
+    1994                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = 0;
+    1995                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = 0;
+    1996                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1997                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
+    1998                 :          1 :     spdm_context->local_context.capability.flags |=
+    1999                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP;
+    2000                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2001                 :            : 
+    2002                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    2003                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_NEGOTIATION_FAIL);
+    2004                 :          1 :     assert_int_equal(spdm_context->connection_info.algorithm.base_asym_algo, 0);
+    2005                 :          1 : }
+    2006                 :            : 
+    2007                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case12(void **state)
+    2008                 :            : {
+    2009                 :            :     libspdm_return_t status;
+    2010                 :            :     libspdm_test_context_t *spdm_test_context;
+    2011                 :            :     libspdm_context_t *spdm_context;
+    2012                 :            : 
+    2013                 :          1 :     spdm_test_context = *state;
+    2014                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2015                 :          1 :     spdm_test_context->case_id = 0xC;
+    2016                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    2017                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2018                 :          1 :     spdm_context->connection_info.connection_state =
+    2019                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2020                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    2021                 :            :         m_libspdm_use_measurement_hash_algo;
+    2022                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2023                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2024                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo = 0;
+    2025                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = 0;
+    2026                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = 0;
+    2027                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2028                 :            : 
+    2029                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    2030                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_NEGOTIATION_FAIL);
+    2031                 :          1 :     assert_int_equal(spdm_context->connection_info.algorithm.base_hash_algo,
+    2032                 :            :                      0);
+    2033                 :          1 : }
+    2034                 :            : 
+    2035                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case13(void **state) {
+    2036                 :            :     libspdm_return_t status;
+    2037                 :            :     libspdm_test_context_t    *spdm_test_context;
+    2038                 :            :     libspdm_context_t  *spdm_context;
+    2039                 :            : 
+    2040                 :          1 :     spdm_test_context = *state;
+    2041                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2042                 :          1 :     spdm_test_context->case_id = 0xD;
+    2043                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    2044                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2045                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2046                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    2047                 :            :         m_libspdm_use_measurement_hash_algo;
+    2048                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2049                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2050                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2051                 :            : 
+    2052                 :          1 :     status = libspdm_negotiate_algorithms (spdm_context);
+    2053                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
+    2054                 :          1 : }
+    2055                 :            : 
+    2056                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case14(void **state) {
+    2057                 :            :     libspdm_return_t status;
+    2058                 :            :     libspdm_test_context_t    *spdm_test_context;
+    2059                 :            :     libspdm_context_t  *spdm_context;
+    2060                 :            : 
+    2061                 :          1 :     spdm_test_context = *state;
+    2062                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2063                 :          1 :     spdm_test_context->case_id = 0xE;
+    2064                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    2065                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2066                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2067                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    2068                 :            :         m_libspdm_use_measurement_hash_algo;
+    2069                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2070                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2071                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2072                 :            : 
+    2073                 :          1 :     status = libspdm_negotiate_algorithms (spdm_context);
+    2074                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
+    2075                 :          1 : }
+    2076                 :            : 
+    2077                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case15(void **state) {
+    2078                 :            :     libspdm_return_t status;
+    2079                 :            :     libspdm_test_context_t    *spdm_test_context;
+    2080                 :            :     libspdm_context_t  *spdm_context;
+    2081                 :            : 
+    2082                 :          1 :     spdm_test_context = *state;
+    2083                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2084                 :          1 :     spdm_test_context->case_id = 0xF;
+    2085                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    2086                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2087                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2088                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    2089                 :            :         m_libspdm_use_measurement_hash_algo;
+    2090                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2091                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2092                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2093                 :            : 
+    2094                 :          1 :     status = libspdm_negotiate_algorithms (spdm_context);
+    2095                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    2096                 :          1 : }
+    2097                 :            : 
+    2098                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case16(void **state) {
+    2099                 :            :     libspdm_return_t status;
+    2100                 :            :     libspdm_test_context_t    *spdm_test_context;
+    2101                 :            :     libspdm_context_t  *spdm_context;
+    2102                 :            : 
+    2103                 :          1 :     spdm_test_context = *state;
+    2104                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2105                 :          1 :     spdm_test_context->case_id = 0x10;
+    2106                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    2107                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2108                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2109                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    2110                 :            :         m_libspdm_use_measurement_hash_algo;
+    2111                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2112                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2113                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2114                 :            : 
+    2115                 :          1 :     status = libspdm_negotiate_algorithms (spdm_context);
+    2116                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    2117                 :          1 : }
+    2118                 :            : 
+    2119                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case17(void **state) {
+    2120                 :            :     libspdm_return_t status;
+    2121                 :            :     libspdm_test_context_t    *spdm_test_context;
+    2122                 :            :     libspdm_context_t  *spdm_context;
+    2123                 :            : 
+    2124                 :          1 :     spdm_test_context = *state;
+    2125                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2126                 :          1 :     spdm_test_context->case_id = 0x11;
+    2127                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    2128                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2129                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2130                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    2131                 :            :         m_libspdm_use_measurement_hash_algo;
+    2132                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2133                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2134                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2135                 :            : 
+    2136                 :          1 :     status = libspdm_negotiate_algorithms (spdm_context);
+    2137                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_NEGOTIATION_FAIL);
+    2138                 :          1 : }
+    2139                 :            : 
+    2140                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case18(void **state) {
+    2141                 :            :     libspdm_return_t status;
+    2142                 :            :     libspdm_test_context_t    *spdm_test_context;
+    2143                 :            :     libspdm_context_t  *spdm_context;
+    2144                 :            : 
+    2145                 :          1 :     spdm_test_context = *state;
+    2146                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2147                 :          1 :     spdm_test_context->case_id = 0x12;
+    2148                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    2149                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2150                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2151                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    2152                 :            :         m_libspdm_use_measurement_hash_algo;
+    2153                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2154                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2155                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2156                 :            : 
+    2157                 :          1 :     status = libspdm_negotiate_algorithms (spdm_context);
+    2158                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_NEGOTIATION_FAIL);
+    2159                 :          1 : }
+    2160                 :            : 
+    2161                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case19(void **state) {
+    2162                 :            :     libspdm_return_t status;
+    2163                 :            :     libspdm_test_context_t    *spdm_test_context;
+    2164                 :            :     libspdm_context_t  *spdm_context;
+    2165                 :            : 
+    2166                 :          1 :     spdm_test_context = *state;
+    2167                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2168                 :          1 :     spdm_test_context->case_id = 0x13;
+    2169                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    2170                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2171                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2172                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    2173                 :            :         m_libspdm_use_measurement_hash_algo;
+    2174                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2175                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2176                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2177                 :            : 
+    2178                 :          1 :     status = libspdm_negotiate_algorithms (spdm_context);
+    2179                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    2180                 :          1 : }
+    2181                 :            : 
+    2182                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case20(void **state) {
+    2183                 :            :     libspdm_return_t status;
+    2184                 :            :     libspdm_test_context_t    *spdm_test_context;
+    2185                 :            :     libspdm_context_t  *spdm_context;
+    2186                 :            : 
+    2187                 :          1 :     spdm_test_context = *state;
+    2188                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2189                 :          1 :     spdm_test_context->case_id = 0x14;
+    2190                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    2191                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2192                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2193                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    2194                 :            :         m_libspdm_use_measurement_hash_algo;
+    2195                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2196                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2197                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2198                 :            : 
+    2199                 :          1 :     status = libspdm_negotiate_algorithms (spdm_context);
+    2200                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    2201                 :          1 : }
+    2202                 :            : 
+    2203                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case21(void **state)
+    2204                 :            : {
+    2205                 :            :     libspdm_return_t status;
+    2206                 :            :     libspdm_test_context_t    *spdm_test_context;
+    2207                 :            :     libspdm_context_t  *spdm_context;
+    2208                 :            : 
+    2209                 :          1 :     spdm_test_context = *state;
+    2210                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2211                 :          1 :     spdm_test_context->case_id = 0x15;
+    2212                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    2213                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2214                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2215                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    2216                 :            :         m_libspdm_use_measurement_hash_algo;
+    2217                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2218                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2219                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2220                 :            : 
+    2221                 :          1 :     status = libspdm_negotiate_algorithms (spdm_context);
+    2222                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    2223                 :          1 : }
+    2224                 :            : 
+    2225                 :            : /**
+    2226                 :            :  * Test 22: Request/response code is not equal to ALGORITHMS response.
+    2227                 :            :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
+    2228                 :            :  **/
+    2229                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case22(void **state)
+    2230                 :            : {
+    2231                 :            :     libspdm_return_t status;
+    2232                 :            :     libspdm_test_context_t *spdm_test_context;
+    2233                 :            :     libspdm_context_t *spdm_context;
+    2234                 :            : 
+    2235                 :          1 :     spdm_test_context = *state;
+    2236                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2237                 :          1 :     spdm_test_context->case_id = 0x16;
+    2238                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    2239                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2240                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2241                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    2242                 :            :         m_libspdm_use_measurement_hash_algo;
+    2243                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2244                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2245                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2246                 :            : 
+    2247                 :          1 :     status = libspdm_negotiate_algorithms (spdm_context);
+    2248                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    2249                 :          1 : }
+    2250                 :            : 
+    2251                 :            : /**
+    2252                 :            :  * Test 23: The upper four bits of AlgCount is not equal to 2.
+    2253                 :            :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
+    2254                 :            :  **/
+    2255                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case23(void **state)
+    2256                 :            : {
+    2257                 :            :     libspdm_return_t status;
+    2258                 :            :     libspdm_test_context_t *spdm_test_context;
+    2259                 :            :     libspdm_context_t *spdm_context;
+    2260                 :            : 
+    2261                 :          1 :     spdm_test_context = *state;
+    2262                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2263                 :          1 :     spdm_test_context->case_id = 0x17;
+    2264                 :            : 
+    2265                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    2266                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2267                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2268                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    2269                 :            :         m_libspdm_use_measurement_hash_algo;
+    2270                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2271                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2272                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2273                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    2274                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    2275                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    2276                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    2277                 :            : 
+    2278                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    2279                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2280                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    2281                 :            : 
+    2282                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    2283                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2284                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    2285                 :            : 
+    2286                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    2287                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    2288                 :            : 
+    2289                 :          1 :     spdm_context->local_context.capability.flags |=
+    2290                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    2291                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2292                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    2293                 :            : 
+    2294                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    2295                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    2296                 :            : 
+    2297                 :          1 :     status = libspdm_negotiate_algorithms (spdm_context);
+    2298                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    2299                 :          1 : }
+    2300                 :            : 
+    2301                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case24(void **state) {
+    2302                 :            :     libspdm_return_t status;
+    2303                 :            :     libspdm_test_context_t    *spdm_test_context;
+    2304                 :            :     libspdm_context_t  *spdm_context;
+    2305                 :            : 
+    2306                 :          1 :     spdm_test_context = *state;
+    2307                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2308                 :          1 :     spdm_test_context->case_id = 0x18;
+    2309                 :            : 
+    2310                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    2311                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2312                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2313                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    2314                 :            :         m_libspdm_use_measurement_hash_algo;
+    2315                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2316                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2317                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2318                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    2319                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    2320                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    2321                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    2322                 :            : 
+    2323                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    2324                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2325                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    2326                 :            : 
+    2327                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    2328                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2329                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    2330                 :            : 
+    2331                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    2332                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    2333                 :            : 
+    2334                 :          1 :     spdm_context->local_context.capability.flags |=
+    2335                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    2336                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2337                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    2338                 :            : 
+    2339                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    2340                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    2341                 :            : 
+    2342                 :          1 :     status = libspdm_negotiate_algorithms (spdm_context);
+    2343                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_NEGOTIATION_FAIL);
+    2344                 :          1 : }
+    2345                 :            : 
+    2346                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case25(void **state) {
+    2347                 :            :     libspdm_return_t status;
+    2348                 :            :     libspdm_test_context_t    *spdm_test_context;
+    2349                 :            :     libspdm_context_t  *spdm_context;
+    2350                 :            : 
+    2351                 :          1 :     spdm_test_context = *state;
+    2352                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2353                 :          1 :     spdm_test_context->case_id = 0x19;
+    2354                 :            : 
+    2355                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    2356                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2357                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2358                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    2359                 :            :         m_libspdm_use_measurement_hash_algo;
+    2360                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2361                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2362                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2363                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    2364                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    2365                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    2366                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    2367                 :            : 
+    2368                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    2369                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2370                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    2371                 :            : 
+    2372                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    2373                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2374                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    2375                 :            : 
+    2376                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    2377                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    2378                 :            : 
+    2379                 :          1 :     spdm_context->local_context.capability.flags |=
+    2380                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    2381                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2382                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    2383                 :            : 
+    2384                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    2385                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    2386                 :            : 
+    2387                 :          1 :     status = libspdm_negotiate_algorithms (spdm_context);
+    2388                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_NEGOTIATION_FAIL);
+    2389                 :          1 : }
+    2390                 :            : 
+    2391                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case26(void **state) {
+    2392                 :            :     libspdm_return_t status;
+    2393                 :            :     libspdm_test_context_t    *spdm_test_context;
+    2394                 :            :     libspdm_context_t  *spdm_context;
+    2395                 :            : 
+    2396                 :          1 :     spdm_test_context = *state;
+    2397                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2398                 :          1 :     spdm_test_context->case_id = 0x1A;
+    2399                 :            : 
+    2400                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    2401                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2402                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2403                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    2404                 :            :         m_libspdm_use_measurement_hash_algo;
+    2405                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2406                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2407                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2408                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    2409                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    2410                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    2411                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    2412                 :            : 
+    2413                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    2414                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2415                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    2416                 :            : 
+    2417                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    2418                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2419                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    2420                 :            : 
+    2421                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    2422                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    2423                 :            : 
+    2424                 :          1 :     spdm_context->local_context.capability.flags |=
+    2425                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    2426                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2427                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    2428                 :            : 
+    2429                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    2430                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    2431                 :            : 
+    2432                 :          1 :     status = libspdm_negotiate_algorithms (spdm_context);
+    2433                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_NEGOTIATION_FAIL);
+    2434                 :          1 : }
+    2435                 :            : 
+    2436                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case27(void **state) {
+    2437                 :            :     libspdm_return_t status;
+    2438                 :            :     libspdm_test_context_t    *spdm_test_context;
+    2439                 :            :     libspdm_context_t  *spdm_context;
+    2440                 :            : 
+    2441                 :          1 :     spdm_test_context = *state;
+    2442                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2443                 :          1 :     spdm_test_context->case_id = 0x1B;
+    2444                 :            : 
+    2445                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    2446                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2447                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2448                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    2449                 :            :         m_libspdm_use_measurement_hash_algo;
+    2450                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2451                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2452                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2453                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    2454                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    2455                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    2456                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    2457                 :            : 
+    2458                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    2459                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2460                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    2461                 :            : 
+    2462                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    2463                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2464                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    2465                 :            : 
+    2466                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    2467                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    2468                 :            : 
+    2469                 :          1 :     spdm_context->local_context.capability.flags |=
+    2470                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    2471                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2472                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    2473                 :            : 
+    2474                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    2475                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    2476                 :            : 
+    2477                 :          1 :     status = libspdm_negotiate_algorithms (spdm_context);
+    2478                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_NEGOTIATION_FAIL);
+    2479                 :          1 : }
+    2480                 :            : 
+    2481                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case28(void **state) {
+    2482                 :            :     libspdm_return_t status;
+    2483                 :            :     libspdm_test_context_t    *spdm_test_context;
+    2484                 :            :     libspdm_context_t  *spdm_context;
+    2485                 :            : 
+    2486                 :          1 :     spdm_test_context = *state;
+    2487                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2488                 :          1 :     spdm_test_context->case_id = 0x1C;
+    2489                 :            : 
+    2490                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    2491                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2492                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2493                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    2494                 :            :         m_libspdm_use_measurement_hash_algo;
+    2495                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2496                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2497                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2498                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    2499                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    2500                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    2501                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    2502                 :            : 
+    2503                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    2504                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2505                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    2506                 :            : 
+    2507                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    2508                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2509                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    2510                 :            : 
+    2511                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    2512                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    2513                 :            : 
+    2514                 :          1 :     spdm_context->local_context.capability.flags |=
+    2515                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    2516                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2517                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    2518                 :            : 
+    2519                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    2520                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    2521                 :            : 
+    2522                 :          1 :     status = libspdm_negotiate_algorithms (spdm_context);
+    2523                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    2524                 :          1 : }
+    2525                 :            : 
+    2526                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case29(void **state) {
+    2527                 :            :     libspdm_return_t status;
+    2528                 :            :     libspdm_test_context_t    *spdm_test_context;
+    2529                 :            :     libspdm_context_t  *spdm_context;
+    2530                 :            : 
+    2531                 :          1 :     spdm_test_context = *state;
+    2532                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2533                 :          1 :     spdm_test_context->case_id = 0x1D;
+    2534                 :            : 
+    2535                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    2536                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2537                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2538                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    2539                 :            :         m_libspdm_use_measurement_hash_algo;
+    2540                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2541                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2542                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2543                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    2544                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    2545                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    2546                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    2547                 :            : 
+    2548                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    2549                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2550                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    2551                 :            : 
+    2552                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    2553                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2554                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    2555                 :            : 
+    2556                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    2557                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    2558                 :            : 
+    2559                 :          1 :     spdm_context->local_context.capability.flags |=
+    2560                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    2561                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2562                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    2563                 :            : 
+    2564                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    2565                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    2566                 :            : 
+    2567                 :          1 :     status = libspdm_negotiate_algorithms (spdm_context);
+    2568                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    2569                 :          1 : }
+    2570                 :            : 
+    2571                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case30(void **state) {
+    2572                 :            :     libspdm_return_t status;
+    2573                 :            :     libspdm_test_context_t    *spdm_test_context;
+    2574                 :            :     libspdm_context_t  *spdm_context;
+    2575                 :            : 
+    2576                 :          1 :     spdm_test_context = *state;
+    2577                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2578                 :          1 :     spdm_test_context->case_id = 0x1E;
+    2579                 :            : 
+    2580                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    2581                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2582                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2583                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    2584                 :            :         m_libspdm_use_measurement_hash_algo;
+    2585                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2586                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2587                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2588                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    2589                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    2590                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    2591                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    2592                 :            : 
+    2593                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    2594                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2595                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    2596                 :            : 
+    2597                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    2598                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2599                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    2600                 :            : 
+    2601                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    2602                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    2603                 :            : 
+    2604                 :          1 :     spdm_context->local_context.capability.flags |=
+    2605                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    2606                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2607                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    2608                 :            : 
+    2609                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    2610                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    2611                 :            : 
+    2612                 :          1 :     status = libspdm_negotiate_algorithms (spdm_context);
+    2613                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    2614                 :          1 : }
+    2615                 :            : 
+    2616                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case31(void **state) {
+    2617                 :            :     libspdm_return_t status;
+    2618                 :            :     libspdm_test_context_t    *spdm_test_context;
+    2619                 :            :     libspdm_context_t  *spdm_context;
+    2620                 :            : 
+    2621                 :          1 :     spdm_test_context = *state;
+    2622                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2623                 :          1 :     spdm_test_context->case_id = 0x1F;
+    2624                 :            : 
+    2625                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    2626                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2627                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2628                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    2629                 :            :         m_libspdm_use_measurement_hash_algo;
+    2630                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2631                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2632                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2633                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    2634                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    2635                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    2636                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    2637                 :            : 
+    2638                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    2639                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2640                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    2641                 :            : 
+    2642                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    2643                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2644                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    2645                 :            : 
+    2646                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    2647                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    2648                 :            : 
+    2649                 :          1 :     spdm_context->local_context.capability.flags |=
+    2650                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    2651                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2652                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    2653                 :            : 
+    2654                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    2655                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    2656                 :            : 
+    2657                 :          1 :     status = libspdm_negotiate_algorithms (spdm_context);
+    2658                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    2659                 :          1 : }
+    2660                 :            : 
+    2661                 :            : /**
+    2662                 :            :  * Test 32: Length field is incorrect.
+    2663                 :            :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_SIZE.
+    2664                 :            :  **/
+    2665                 :          3 : static void libspdm_test_requester_negotiate_algorithms_error_case32(void **state)
+    2666                 :            : {
+    2667                 :            :     libspdm_return_t status;
+    2668                 :            :     libspdm_test_context_t *spdm_test_context;
+    2669                 :            :     libspdm_context_t *spdm_context;
+    2670                 :            : 
+    2671                 :          3 :     spdm_test_context = *state;
+    2672                 :          3 :     spdm_context = spdm_test_context->spdm_context;
+    2673                 :          3 :     spdm_test_context->case_id = 0x20;
+    2674                 :          3 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    2675                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2676                 :          3 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2677                 :          3 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    2678                 :            :         m_libspdm_use_measurement_hash_algo;
+    2679                 :          3 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2680                 :          3 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2681                 :          3 :     libspdm_reset_message_a(spdm_context);
+    2682                 :            : 
+    2683                 :          3 :     status = libspdm_negotiate_algorithms(spdm_context);
+    2684                 :          3 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
+    2685                 :          3 : }
+    2686                 :            : 
+    2687                 :            : /**
+    2688                 :            :  * Test 33: Non-zero ext_alg_count.
+    2689                 :            :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
+    2690                 :            :  **/
+    2691                 :          2 : static void libspdm_test_requester_negotiate_algorithms_error_case33(void **state)
+    2692                 :            : {
+    2693                 :            :     libspdm_return_t status;
+    2694                 :            :     libspdm_test_context_t *spdm_test_context;
+    2695                 :            :     libspdm_context_t *spdm_context;
+    2696                 :            : 
+    2697                 :          2 :     spdm_test_context = *state;
+    2698                 :          2 :     spdm_context = spdm_test_context->spdm_context;
+    2699                 :          2 :     spdm_test_context->case_id = 0x21;
+    2700                 :          2 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    2701                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2702                 :          2 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2703                 :          2 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    2704                 :            :         m_libspdm_use_measurement_hash_algo;
+    2705                 :          2 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2706                 :          2 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2707                 :          2 :     libspdm_reset_message_a(spdm_context);
+    2708                 :            : 
+    2709                 :          2 :     status = libspdm_negotiate_algorithms(spdm_context);
+    2710                 :          2 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    2711                 :          2 : }
+    2712                 :            : 
+    2713                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case34(void **state)
+    2714                 :            : {
+    2715                 :            :     libspdm_return_t status;
+    2716                 :            :     libspdm_test_context_t *spdm_test_context;
+    2717                 :            :     libspdm_context_t *spdm_context;
+    2718                 :            : 
+    2719                 :          1 :     spdm_test_context = *state;
+    2720                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2721                 :          1 :     spdm_test_context->case_id = 0x22;
+    2722                 :            : 
+    2723                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    2724                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2725                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2726                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    2727                 :            :         m_libspdm_use_measurement_hash_algo;
+    2728                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2729                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2730                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2731                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    2732                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    2733                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    2734                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    2735                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    2736                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2737                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    2738                 :            : 
+    2739                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    2740                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2741                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    2742                 :            : 
+    2743                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    2744                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    2745                 :            : 
+    2746                 :          1 :     spdm_context->local_context.capability.flags |=
+    2747                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    2748                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2749                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    2750                 :            : 
+    2751                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    2752                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    2753                 :            : 
+    2754                 :          1 :     status = libspdm_negotiate_algorithms (spdm_context);
+    2755                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    2756                 :          1 : }
+    2757                 :            : 
+    2758                 :            : /**
+    2759                 :            :  * Test 35: MeasurementSpecificationSel has exactly one bit set to an illegal value.
+    2760                 :            :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
+    2761                 :            :  **/
+    2762                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case35(void **state)
+    2763                 :            : {
+    2764                 :            :     libspdm_return_t status;
+    2765                 :            :     libspdm_test_context_t *spdm_test_context;
+    2766                 :            :     libspdm_context_t *spdm_context;
+    2767                 :            : 
+    2768                 :          1 :     spdm_test_context = *state;
+    2769                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2770                 :          1 :     spdm_test_context->case_id = 0x24;
+    2771                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    2772                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2773                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2774                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    2775                 :            :         m_libspdm_use_measurement_hash_algo;
+    2776                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2777                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2778                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    2779                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    2780                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2781                 :            : 
+    2782                 :          1 :     status = libspdm_negotiate_algorithms (spdm_context);
+    2783                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    2784                 :          1 : }
+    2785                 :            : 
+    2786                 :            : /**
+    2787                 :            :  * Test 36: MeasurementSpecificationSel has more than one bit set.
+    2788                 :            :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
+    2789                 :            :  **/
+    2790                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case36(void **state)
+    2791                 :            : {
+    2792                 :            :     libspdm_return_t status;
+    2793                 :            :     libspdm_test_context_t *spdm_test_context;
+    2794                 :            :     libspdm_context_t *spdm_context;
+    2795                 :            : 
+    2796                 :          1 :     spdm_test_context = *state;
+    2797                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2798                 :          1 :     spdm_test_context->case_id = 0x25;
+    2799                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    2800                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2801                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2802                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    2803                 :            :         m_libspdm_use_measurement_hash_algo;
+    2804                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2805                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2806                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2807                 :            : 
+    2808                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    2809                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    2810                 :          1 : }
+    2811                 :            : 
+    2812                 :            : /**
+    2813                 :            :  * Test 37: Incorrect SPDM version in response.
+    2814                 :            :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
+    2815                 :            :  **/
+    2816                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case37(void **state)
+    2817                 :            : {
+    2818                 :            :     libspdm_return_t status;
+    2819                 :            :     libspdm_test_context_t *spdm_test_context;
+    2820                 :            :     libspdm_context_t *spdm_context;
+    2821                 :            : 
+    2822                 :          1 :     spdm_test_context = *state;
+    2823                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2824                 :          1 :     spdm_test_context->case_id = 0x26;
+    2825                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    2826                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2827                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2828                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    2829                 :            :         m_libspdm_use_measurement_hash_algo;
+    2830                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2831                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2832                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2833                 :            : 
+    2834                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    2835                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    2836                 :          1 : }
+    2837                 :            : 
+    2838                 :            : /**
+    2839                 :            :  * Test 38: Reserverd alg_type value.
+    2840                 :            :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
+    2841                 :            :  **/
+    2842                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case38(void **state)
+    2843                 :            : {
+    2844                 :            :     libspdm_return_t status;
+    2845                 :            :     libspdm_test_context_t *spdm_test_context;
+    2846                 :            :     libspdm_context_t *spdm_context;
+    2847                 :            : 
+    2848                 :          1 :     spdm_test_context = *state;
+    2849                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2850                 :          1 :     spdm_test_context->case_id = 0x27;
+    2851                 :            : 
+    2852                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    2853                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2854                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2855                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    2856                 :            :         m_libspdm_use_measurement_hash_algo;
+    2857                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2858                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2859                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2860                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    2861                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    2862                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    2863                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    2864                 :            : 
+    2865                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    2866                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2867                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    2868                 :            : 
+    2869                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    2870                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2871                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    2872                 :            : 
+    2873                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    2874                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    2875                 :            : 
+    2876                 :          1 :     spdm_context->local_context.capability.flags |=
+    2877                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    2878                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2879                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    2880                 :            : 
+    2881                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    2882                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    2883                 :            : 
+    2884                 :          1 :     status = libspdm_negotiate_algorithms (spdm_context);
+    2885                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    2886                 :          1 : }
+    2887                 :            : 
+    2888                 :            : /**
+    2889                 :            :  * Test 39: AlgType shall monotonically increase for subsequent entries. Redundant alg_type value.
+    2890                 :            :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
+    2891                 :            :  **/
+    2892                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case39(void** state)
+    2893                 :            : {
+    2894                 :            :     libspdm_return_t status;
+    2895                 :            :     libspdm_test_context_t* spdm_test_context;
+    2896                 :            :     libspdm_context_t* spdm_context;
+    2897                 :            : 
+    2898                 :          1 :     spdm_test_context = *state;
+    2899                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2900                 :          1 :     spdm_test_context->case_id = 0x28;
+    2901                 :            : 
+    2902                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    2903                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2904                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2905                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    2906                 :            :         m_libspdm_use_measurement_hash_algo;
+    2907                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2908                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2909                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2910                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    2911                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    2912                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    2913                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    2914                 :            : 
+    2915                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    2916                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2917                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    2918                 :            : 
+    2919                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    2920                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2921                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    2922                 :            : 
+    2923                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    2924                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    2925                 :            : 
+    2926                 :          1 :     spdm_context->local_context.capability.flags |=
+    2927                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    2928                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2929                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    2930                 :            : 
+    2931                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    2932                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    2933                 :            : 
+    2934                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    2935                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    2936                 :          1 : }
+    2937                 :            : 
+    2938                 :            : /**
+    2939                 :            :  * Test 40: AlgType shall monotonically increase for subsequent entries. Decreasing alg_type value.
+    2940                 :            :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
+    2941                 :            :  **/
+    2942                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case40(void** state)
+    2943                 :            : {
+    2944                 :            :     libspdm_return_t status;
+    2945                 :            :     libspdm_test_context_t* spdm_test_context;
+    2946                 :            :     libspdm_context_t* spdm_context;
+    2947                 :            : 
+    2948                 :          1 :     spdm_test_context = *state;
+    2949                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2950                 :          1 :     spdm_test_context->case_id = 0x29;
+    2951                 :            : 
+    2952                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    2953                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2954                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2955                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    2956                 :            :         m_libspdm_use_measurement_hash_algo;
+    2957                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2958                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2959                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2960                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    2961                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    2962                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    2963                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    2964                 :            : 
+    2965                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    2966                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2967                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    2968                 :            : 
+    2969                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    2970                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2971                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    2972                 :            : 
+    2973                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    2974                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    2975                 :            : 
+    2976                 :          1 :     spdm_context->local_context.capability.flags |=
+    2977                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    2978                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2979                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    2980                 :            : 
+    2981                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    2982                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    2983                 :            : 
+    2984                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    2985                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    2986                 :          1 : }
+    2987                 :            : 
+    2988                 :            : /**
+    2989                 :            :  * Test 41: OtherParamsSelection is added in SPDM 1.2.
+    2990                 :            :  * OtherParamsSelection has more than one bit set.
+    2991                 :            :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
+    2992                 :            :  **/
+    2993                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case41(void **state)
+    2994                 :            : {
+    2995                 :            :     libspdm_return_t status;
+    2996                 :            :     libspdm_test_context_t *spdm_test_context;
+    2997                 :            :     libspdm_context_t *spdm_context;
+    2998                 :            : 
+    2999                 :          1 :     spdm_test_context = *state;
+    3000                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    3001                 :          1 :     spdm_test_context->case_id = 0x2A;
+    3002                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    3003                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3004                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    3005                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    3006                 :            :         m_libspdm_use_measurement_hash_algo;
+    3007                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    3008                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    3009                 :          1 :     libspdm_reset_message_a(spdm_context);
+    3010                 :            : 
+    3011                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    3012                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    3013                 :          1 : }
+    3014                 :            : 
+    3015                 :            : /**
+    3016                 :            :  * Test 42: AlgType shall between DHE and KEY_SCHEDULE. Use value smaller than DHE.
+    3017                 :            :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
+    3018                 :            :  **/
+    3019                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case42(void** state)
+    3020                 :            : {
+    3021                 :            :     libspdm_return_t status;
+    3022                 :            :     libspdm_test_context_t* spdm_test_context;
+    3023                 :            :     libspdm_context_t* spdm_context;
+    3024                 :            : 
+    3025                 :          1 :     spdm_test_context = *state;
+    3026                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    3027                 :          1 :     spdm_test_context->case_id = 0x2B;
+    3028                 :            : 
+    3029                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    3030                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3031                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    3032                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    3033                 :            :         m_libspdm_use_measurement_hash_algo;
+    3034                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    3035                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    3036                 :          1 :     libspdm_reset_message_a(spdm_context);
+    3037                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    3038                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    3039                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    3040                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    3041                 :            : 
+    3042                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    3043                 :          1 :     spdm_context->connection_info.capability.flags |=
+    3044                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    3045                 :            : 
+    3046                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    3047                 :          1 :     spdm_context->connection_info.capability.flags |=
+    3048                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    3049                 :            : 
+    3050                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    3051                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    3052                 :            : 
+    3053                 :          1 :     spdm_context->local_context.capability.flags |=
+    3054                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    3055                 :          1 :     spdm_context->connection_info.capability.flags |=
+    3056                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    3057                 :            : 
+    3058                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    3059                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    3060                 :            : 
+    3061                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    3062                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    3063                 :          1 : }
+    3064                 :            : 
+    3065                 :            : /**
+    3066                 :            :  * Test 43: AlgType shall between DHE and KEY_SCHEDULE. Use value bigger than KEY_SCHEDULE.
+    3067                 :            :  * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
+    3068                 :            :  **/
+    3069                 :          1 : static void libspdm_test_requester_negotiate_algorithms_error_case43(void** state)
+    3070                 :            : {
+    3071                 :            :     libspdm_return_t status;
+    3072                 :            :     libspdm_test_context_t* spdm_test_context;
+    3073                 :            :     libspdm_context_t* spdm_context;
+    3074                 :            : 
+    3075                 :          1 :     spdm_test_context = *state;
+    3076                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    3077                 :          1 :     spdm_test_context->case_id = 0x2C;
+    3078                 :            : 
+    3079                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    3080                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3081                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    3082                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    3083                 :            :         m_libspdm_use_measurement_hash_algo;
+    3084                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    3085                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    3086                 :          1 :     libspdm_reset_message_a(spdm_context);
+    3087                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    3088                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    3089                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    3090                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    3091                 :            : 
+    3092                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    3093                 :          1 :     spdm_context->connection_info.capability.flags |=
+    3094                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    3095                 :            : 
+    3096                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    3097                 :          1 :     spdm_context->connection_info.capability.flags |=
+    3098                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    3099                 :            : 
+    3100                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    3101                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    3102                 :            : 
+    3103                 :          1 :     spdm_context->local_context.capability.flags |=
+    3104                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    3105                 :          1 :     spdm_context->connection_info.capability.flags |=
+    3106                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    3107                 :            : 
+    3108                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    3109                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    3110                 :            : 
+    3111                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    3112                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    3113                 :          1 : }
+    3114                 :            : 
+    3115                 :            : libspdm_test_context_t m_libspdm_requester_negotiate_algorithms_test_context = {
+    3116                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+    3117                 :            :     true,
+    3118                 :            :     libspdm_requester_negotiate_algorithms_test_send_message,
+    3119                 :            :     libspdm_requester_negotiate_algorithm_test_receive_message,
+    3120                 :            : };
+    3121                 :            : 
+    3122                 :          1 : int libspdm_requester_negotiate_algorithms_error_test_main(void)
+    3123                 :            : {
+    3124                 :          1 :     const struct CMUnitTest spdm_requester_negotiate_algorithms_tests[] = {
+    3125                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case1),
+    3126                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case2),
+    3127                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case3),
+    3128                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case4),
+    3129                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case5),
+    3130                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case6),
+    3131                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case7),
+    3132                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case8),
+    3133                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case9),
+    3134                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case10),
+    3135                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case11),
+    3136                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case12),
+    3137                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case13),
+    3138                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case14),
+    3139                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case15),
+    3140                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case16),
+    3141                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case17),
+    3142                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case18),
+    3143                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case19),
+    3144                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case20),
+    3145                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case21),
+    3146                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case22),
+    3147                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case23),
+    3148                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case24),
+    3149                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case25),
+    3150                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case26),
+    3151                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case27),
+    3152                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case28),
+    3153                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case29),
+    3154                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case30),
+    3155                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case31),
+    3156                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case32),
+    3157                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case32),
+    3158                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case33),
+    3159                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case32),
+    3160                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case33),
+    3161                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case34),
+    3162                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case35),
+    3163                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case36),
+    3164                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case37),
+    3165                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case38),
+    3166                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case39),
+    3167                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case40),
+    3168                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case41),
+    3169                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case42),
+    3170                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case43),
+    3171                 :            :     };
+    3172                 :            : 
+    3173                 :          1 :     libspdm_setup_test_context(&m_libspdm_requester_negotiate_algorithms_test_context);
+    3174                 :            : 
+    3175                 :          1 :     return cmocka_run_group_tests(spdm_requester_negotiate_algorithms_tests,
+    3176                 :            :                                   libspdm_unit_test_group_setup,
+    3177                 :            :                                   libspdm_unit_test_group_teardown);
+    3178                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/error_test/set_key_pair_info_err.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_requester/error_test/set_key_pair_info_err.c.func-sort-c.html new file mode 100644 index 00000000000..1b8a4436eac --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/error_test/set_key_pair_info_err.c.func-sort-c.html @@ -0,0 +1,97 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/error_test/set_key_pair_info_err.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester/error_test - set_key_pair_info_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:243372.7 %
Date:2024-09-22 08:21:07Functions:3475.0 %
Branches:1425.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_set_key_pair_info_err_test_receive_message0
libspdm_requester_set_key_pair_info_err_test_send_message1
libspdm_requester_set_key_pair_info_error_test_main1
libspdm_test_requester_set_key_pair_info_err_case11
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/error_test/set_key_pair_info_err.c.func.html b/coverage_log/unit_test/test_spdm_requester/error_test/set_key_pair_info_err.c.func.html new file mode 100644 index 00000000000..f5626a1f855 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/error_test/set_key_pair_info_err.c.func.html @@ -0,0 +1,97 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/error_test/set_key_pair_info_err.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester/error_test - set_key_pair_info_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:243372.7 %
Date:2024-09-22 08:21:07Functions:3475.0 %
Branches:1425.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_set_key_pair_info_err_test_receive_message0
libspdm_requester_set_key_pair_info_err_test_send_message1
libspdm_requester_set_key_pair_info_error_test_main1
libspdm_test_requester_set_key_pair_info_err_case11
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/error_test/set_key_pair_info_err.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/error_test/set_key_pair_info_err.c.gcov.html new file mode 100644 index 00000000000..eedcb1b9091 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/error_test/set_key_pair_info_err.c.gcov.html @@ -0,0 +1,190 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/error_test/set_key_pair_info_err.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester/error_test - set_key_pair_info_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:243372.7 %
Date:2024-09-22 08:21:07Functions:3475.0 %
Branches:1425.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2024 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_requester_lib.h"
+       9                 :            : #include "internal/libspdm_secured_message_lib.h"
+      10                 :            : 
+      11                 :            : #if LIBSPDM_ENABLE_CAPABILITY_SET_KEY_PAIR_INFO_CAP
+      12                 :            : 
+      13                 :          1 : libspdm_return_t libspdm_requester_set_key_pair_info_err_test_send_message(
+      14                 :            :     void *spdm_context, size_t request_size, const void *request,
+      15                 :            :     uint64_t timeout)
+      16                 :            : {
+      17                 :            :     libspdm_test_context_t *spdm_test_context;
+      18                 :            : 
+      19                 :          1 :     spdm_test_context = libspdm_get_test_context();
+      20         [ +  - ]:          1 :     switch (spdm_test_context->case_id) {
+      21                 :          1 :     case 0x1:
+      22                 :          1 :         return LIBSPDM_STATUS_SEND_FAIL;
+      23                 :          0 :     default:
+      24                 :          0 :         return LIBSPDM_STATUS_SEND_FAIL;
+      25                 :            :     }
+      26                 :            : }
+      27                 :            : 
+      28                 :          0 : libspdm_return_t libspdm_requester_set_key_pair_info_err_test_receive_message(
+      29                 :            :     void *spdm_context, size_t *response_size,
+      30                 :            :     void **response, uint64_t timeout)
+      31                 :            : {
+      32                 :            :     libspdm_test_context_t *spdm_test_context;
+      33                 :            : 
+      34                 :          0 :     spdm_test_context = libspdm_get_test_context();
+      35         [ #  # ]:          0 :     switch (spdm_test_context->case_id) {
+      36                 :          0 :     case 0x1:
+      37                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+      38                 :            : 
+      39                 :          0 :     default:
+      40                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+      41                 :            :     }
+      42                 :            : }
+      43                 :            : 
+      44                 :            : /**
+      45                 :            :  * Test 1: message could not be sent
+      46                 :            :  * Expected Behavior: get a RETURN_DEVICE_ERROR return code
+      47                 :            :  **/
+      48                 :          1 : void libspdm_test_requester_set_key_pair_info_err_case1(void **state)
+      49                 :            : {
+      50                 :            :     libspdm_return_t status;
+      51                 :            :     libspdm_test_context_t *spdm_test_context;
+      52                 :            :     libspdm_context_t *spdm_context;
+      53                 :            : 
+      54                 :            :     uint8_t key_pair_id;
+      55                 :            :     uint8_t operation;
+      56                 :            :     uint16_t desired_key_usage;
+      57                 :            :     uint32_t desired_asym_algo;
+      58                 :            :     uint8_t desired_assoc_cert_slot_mask;
+      59                 :            : 
+      60                 :          1 :     spdm_test_context = *state;
+      61                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+      62                 :          1 :     spdm_test_context->case_id = 0x1;
+      63                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+      64                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+      65                 :            : 
+      66                 :          1 :     spdm_context->connection_info.connection_state =
+      67                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+      68                 :          1 :     spdm_context->connection_info.capability.flags |=
+      69                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_KEY_PAIR_INFO_CAP;
+      70                 :            : 
+      71                 :          1 :     key_pair_id = 1;
+      72                 :          1 :     operation = SPDM_SET_KEY_PAIR_INFO_ERASE_OPERATION;
+      73                 :          1 :     desired_key_usage = 0;
+      74                 :          1 :     desired_asym_algo = 0;
+      75                 :          1 :     desired_assoc_cert_slot_mask = 0;
+      76                 :            : 
+      77                 :          1 :     status = libspdm_set_key_pair_info(spdm_context, NULL, key_pair_id,
+      78                 :            :                                        operation, desired_key_usage, desired_asym_algo,
+      79                 :            :                                        desired_assoc_cert_slot_mask);
+      80                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SEND_FAIL);
+      81                 :          1 : }
+      82                 :            : 
+      83                 :            : libspdm_test_context_t m_libspdm_requester_set_key_pair_info_err_test_context = {
+      84                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+      85                 :            :     true,
+      86                 :            :     libspdm_requester_set_key_pair_info_err_test_send_message,
+      87                 :            :     libspdm_requester_set_key_pair_info_err_test_receive_message,
+      88                 :            : };
+      89                 :            : 
+      90                 :          1 : int libspdm_requester_set_key_pair_info_error_test_main(void)
+      91                 :            : {
+      92                 :          1 :     const struct CMUnitTest spdm_requester_set_key_pair_info_err_tests[] = {
+      93                 :            :         /* SendRequest failed*/
+      94                 :            :         cmocka_unit_test(libspdm_test_requester_set_key_pair_info_err_case1),
+      95                 :            :     };
+      96                 :            : 
+      97                 :          1 :     libspdm_setup_test_context(
+      98                 :            :         &m_libspdm_requester_set_key_pair_info_err_test_context);
+      99                 :            : 
+     100                 :          1 :     return cmocka_run_group_tests(spdm_requester_set_key_pair_info_err_tests,
+     101                 :            :                                   libspdm_unit_test_group_setup,
+     102                 :            :                                   libspdm_unit_test_group_teardown);
+     103                 :            : }
+     104                 :            : 
+     105                 :            : #endif /*LIBSPDM_ENABLE_CAPABILITY_SET_KEY_PAIR_INFO_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/error_test/subscribe_event_types_err.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_requester/error_test/subscribe_event_types_err.c.func-sort-c.html new file mode 100644 index 00000000000..bd1cbc6148f --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/error_test/subscribe_event_types_err.c.func-sort-c.html @@ -0,0 +1,109 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/error_test/subscribe_event_types_err.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester/error_test - subscribe_event_types_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:529355.9 %
Date:2024-09-22 08:21:07Functions:5771.4 %
Branches:040.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
receive_message0
send_message0
libspdm_requester_subscribe_event_types_error_test_main1
libspdm_test_requester_subscribe_event_types_err_case11
libspdm_test_requester_subscribe_event_types_err_case21
libspdm_test_requester_subscribe_event_types_err_case31
set_standard_state3
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/error_test/subscribe_event_types_err.c.func.html b/coverage_log/unit_test/test_spdm_requester/error_test/subscribe_event_types_err.c.func.html new file mode 100644 index 00000000000..ec39c23335e --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/error_test/subscribe_event_types_err.c.func.html @@ -0,0 +1,109 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/error_test/subscribe_event_types_err.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester/error_test - subscribe_event_types_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:529355.9 %
Date:2024-09-22 08:21:07Functions:5771.4 %
Branches:040.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_subscribe_event_types_error_test_main1
libspdm_test_requester_subscribe_event_types_err_case11
libspdm_test_requester_subscribe_event_types_err_case21
libspdm_test_requester_subscribe_event_types_err_case31
receive_message0
send_message0
set_standard_state3
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/error_test/subscribe_event_types_err.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/error_test/subscribe_event_types_err.c.gcov.html new file mode 100644 index 00000000000..9cbbb99be76 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/error_test/subscribe_event_types_err.c.gcov.html @@ -0,0 +1,342 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/error_test/subscribe_event_types_err.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester/error_test - subscribe_event_types_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:529355.9 %
Date:2024-09-22 08:21:07Functions:5771.4 %
Branches:040.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2024 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_requester_lib.h"
+       9                 :            : #include "internal/libspdm_secured_message_lib.h"
+      10                 :            : 
+      11                 :            : #if LIBSPDM_EVENT_RECIPIENT_SUPPORT
+      12                 :            : 
+      13                 :            : static const uint32_t m_session_id = 0xffffffff;
+      14                 :            : 
+      15                 :            : static uint8_t m_spdm_request_buffer[0x1000];
+      16                 :            : 
+      17                 :            : static struct test_params {
+      18                 :            :     uint8_t subscribe_event_group_count;
+      19                 :            :     uint32_t subscribe_list_len;
+      20                 :            :     uint8_t subscribe_list[0x1000];
+      21                 :            : } test_params;
+      22                 :            : 
+      23                 :          3 : static void set_standard_state(libspdm_context_t *spdm_context, uint32_t *session_id)
+      24                 :            : {
+      25                 :            :     libspdm_session_info_t *session_info;
+      26                 :            : 
+      27                 :          3 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+      28                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+      29                 :          3 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+      30                 :            : 
+      31                 :          3 :     spdm_context->connection_info.capability.flags |=
+      32                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EVENT_CAP;
+      33                 :          3 :     spdm_context->connection_info.capability.flags |=
+      34                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+      35                 :          3 :     spdm_context->connection_info.capability.flags |=
+      36                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+      37                 :          3 :     spdm_context->connection_info.capability.flags |=
+      38                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+      39                 :            : 
+      40                 :          3 :     spdm_context->local_context.capability.flags |=
+      41                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+      42                 :          3 :     spdm_context->local_context.capability.flags |=
+      43                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+      44                 :          3 :     spdm_context->local_context.capability.flags |=
+      45                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+      46                 :            : 
+      47                 :          3 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+      48                 :          3 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+      49                 :          3 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+      50                 :          3 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+      51                 :            : 
+      52                 :          3 :     *session_id = m_session_id;
+      53                 :          3 :     session_info = &spdm_context->session_info[0];
+      54                 :          3 :     libspdm_session_info_init(spdm_context, session_info, *session_id, true);
+      55                 :          3 :     libspdm_secured_message_set_session_state(
+      56                 :            :         session_info->secured_message_context, LIBSPDM_SESSION_STATE_ESTABLISHED);
+      57                 :          3 : }
+      58                 :            : 
+      59                 :          0 : static libspdm_return_t send_message(
+      60                 :            :     void *spdm_context, size_t request_size, const void *request, uint64_t timeout)
+      61                 :            : {
+      62                 :            :     libspdm_return_t status;
+      63                 :            :     uint32_t session_id;
+      64                 :            :     uint32_t *message_session_id;
+      65                 :            :     spdm_subscribe_event_types_request_t *spdm_message;
+      66                 :            :     bool is_app_message;
+      67                 :            :     void *spdm_request_buffer;
+      68                 :            :     size_t spdm_request_size;
+      69                 :            :     libspdm_session_info_t *session_info;
+      70                 :            :     uint8_t request_buffer[0x1000];
+      71                 :            : 
+      72                 :            :     /* Workaround request being const. */
+      73                 :          0 :     libspdm_copy_mem(request_buffer, sizeof(request_buffer), request, request_size);
+      74                 :            : 
+      75                 :          0 :     session_id = m_session_id;
+      76                 :          0 :     session_info = libspdm_get_session_info_via_session_id(spdm_context, session_id);
+      77         [ #  # ]:          0 :     LIBSPDM_ASSERT(session_info != NULL);
+      78                 :            : 
+      79                 :          0 :     ((libspdm_secured_message_context_t *)(session_info->secured_message_context))->
+      80                 :          0 :     application_secret.request_data_sequence_number--;
+      81                 :            : 
+      82                 :          0 :     spdm_request_buffer = m_spdm_request_buffer;
+      83                 :          0 :     spdm_request_size = sizeof(m_spdm_request_buffer);
+      84                 :            : 
+      85                 :          0 :     status = libspdm_transport_test_decode_message(spdm_context, &message_session_id,
+      86                 :            :                                                    &is_app_message, true,
+      87                 :            :                                                    request_size, request_buffer,
+      88                 :            :                                                    &spdm_request_size, &spdm_request_buffer);
+      89                 :            : 
+      90                 :          0 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+      91                 :          0 :     assert_int_equal(sizeof(spdm_subscribe_event_types_request_t) + test_params.subscribe_list_len,
+      92                 :            :                      spdm_request_size);
+      93                 :            : 
+      94                 :          0 :     spdm_message = spdm_request_buffer;
+      95                 :            : 
+      96                 :          0 :     assert_int_equal(spdm_message->header.spdm_version, SPDM_MESSAGE_VERSION_13);
+      97                 :          0 :     assert_int_equal(spdm_message->header.request_response_code, SPDM_SUBSCRIBE_EVENT_TYPES);
+      98                 :          0 :     assert_int_equal(spdm_message->header.param1, test_params.subscribe_event_group_count);
+      99                 :          0 :     assert_int_equal(spdm_message->header.param2, 0);
+     100                 :          0 :     assert_int_equal(spdm_message->subscribe_list_len, test_params.subscribe_list_len);
+     101                 :            : 
+     102                 :          0 :     assert_memory_equal(spdm_message + 1, test_params.subscribe_list,
+     103                 :            :                         spdm_message->subscribe_list_len);
+     104                 :            : 
+     105                 :          0 :     return LIBSPDM_STATUS_SUCCESS;
+     106                 :            : }
+     107                 :            : 
+     108                 :          0 : static libspdm_return_t receive_message(
+     109                 :            :     void *spdm_context, size_t *response_size, void **response, uint64_t timeout)
+     110                 :            : {
+     111                 :            :     spdm_subscribe_event_types_ack_response_t *spdm_response;
+     112                 :            :     size_t spdm_response_size;
+     113                 :            :     size_t transport_header_size;
+     114                 :            :     uint32_t session_id;
+     115                 :            :     libspdm_session_info_t *session_info;
+     116                 :            :     uint8_t *scratch_buffer;
+     117                 :            :     size_t scratch_buffer_size;
+     118                 :            : 
+     119                 :          0 :     transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     120                 :          0 :     spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     121                 :            : 
+     122                 :          0 :     session_id = m_session_id;
+     123                 :          0 :     session_info = libspdm_get_session_info_via_session_id(spdm_context, session_id);
+     124         [ #  # ]:          0 :     LIBSPDM_ASSERT((session_info != NULL));
+     125                 :            : 
+     126                 :          0 :     transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     127                 :          0 :     spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     128                 :            : 
+     129                 :          0 :     spdm_response_size = sizeof(spdm_subscribe_event_types_ack_response_t);
+     130                 :          0 :     libspdm_zero_mem(spdm_response, spdm_response_size);
+     131                 :            : 
+     132                 :          0 :     spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+     133                 :          0 :     spdm_response->header.request_response_code = SPDM_SUBSCRIBE_EVENT_TYPES_ACK;
+     134                 :          0 :     spdm_response->header.param1 = 0;
+     135                 :          0 :     spdm_response->header.param2 = 0;
+     136                 :            : 
+     137                 :            :     /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+     138                 :            :      * transport_message is always in sender buffer. */
+     139                 :          0 :     libspdm_get_scratch_buffer(spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+     140                 :          0 :     libspdm_copy_mem(scratch_buffer + transport_header_size,
+     141                 :            :                      scratch_buffer_size - transport_header_size,
+     142                 :            :                      spdm_response, spdm_response_size);
+     143                 :            : 
+     144                 :          0 :     spdm_response = (void *)(scratch_buffer + transport_header_size);
+     145                 :            : 
+     146                 :          0 :     libspdm_transport_test_encode_message(spdm_context, &session_id,
+     147                 :            :                                           false, false, spdm_response_size,
+     148                 :            :                                           spdm_response, response_size, response);
+     149                 :            : 
+     150                 :            :     /* Workaround: Use single context to encode message and then decode message. */
+     151                 :          0 :     ((libspdm_secured_message_context_t *)(session_info->secured_message_context))->
+     152                 :          0 :     application_secret.response_data_sequence_number--;
+     153                 :            : 
+     154                 :          0 :     return LIBSPDM_STATUS_SUCCESS;
+     155                 :            : }
+     156                 :            : 
+     157                 :            : /**
+     158                 :            :  * Test 1: Test invalid arguments for subscribe_event_group_count, subscribe_list_len, and
+     159                 :            :  *         subscribe_list.
+     160                 :            :  * Expected Behavior: Returns LIBSPDM_STATUS_INVALID_PARAMETER.
+     161                 :            :  **/
+     162                 :          1 : static void libspdm_test_requester_subscribe_event_types_err_case1(void **state)
+     163                 :            : {
+     164                 :            :     libspdm_return_t status;
+     165                 :            :     libspdm_test_context_t *spdm_test_context;
+     166                 :            :     libspdm_context_t *spdm_context;
+     167                 :            :     uint32_t session_id;
+     168                 :            : 
+     169                 :          1 :     spdm_test_context = *state;
+     170                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     171                 :          1 :     spdm_test_context->case_id = 0x1;
+     172                 :            : 
+     173                 :          1 :     set_standard_state(spdm_context, &session_id);
+     174                 :            : 
+     175                 :            :     /* subscribe_event_group_count is zero but subscribe_list_len is non-zero and subscribe_list is
+     176                 :            :      * not NULL. */
+     177                 :          1 :     status = libspdm_subscribe_event_types(spdm_context, session_id, 0, 10, &session_id);
+     178                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_PARAMETER);
+     179                 :            : 
+     180                 :            :     /* subscribe_event_group_count is non-zero but subscribe_list_len is zero and subscribe_list is
+     181                 :            :      * NULL. */
+     182                 :          1 :     status = libspdm_subscribe_event_types(spdm_context, session_id, 5, 0, NULL);
+     183                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_PARAMETER);
+     184                 :          1 : }
+     185                 :            : 
+     186                 :            : /**
+     187                 :            :  * Test 2: Test invalid state with SPDM version less than 1.3.
+     188                 :            :  * Expected Behavior: Returns LIBSPDM_STATUS_UNSUPPORTED_CAP.
+     189                 :            :  **/
+     190                 :          1 : static void libspdm_test_requester_subscribe_event_types_err_case2(void **state)
+     191                 :            : {
+     192                 :            :     libspdm_return_t status;
+     193                 :            :     libspdm_test_context_t *spdm_test_context;
+     194                 :            :     libspdm_context_t *spdm_context;
+     195                 :            :     uint32_t session_id;
+     196                 :            : 
+     197                 :          1 :     spdm_test_context = *state;
+     198                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     199                 :          1 :     spdm_test_context->case_id = 0x2;
+     200                 :            : 
+     201                 :          1 :     set_standard_state(spdm_context, &session_id);
+     202                 :            :     /* Invalid version. */
+     203                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     204                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     205                 :            : 
+     206                 :          1 :     status = libspdm_subscribe_event_types(spdm_context, session_id, 0, 0, NULL);
+     207                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_UNSUPPORTED_CAP);
+     208                 :          1 : }
+     209                 :            : 
+     210                 :            : /**
+     211                 :            :  * Test 3: Successful response to subscribe event types that includes one event group and all event
+     212                 :            :  *         types using the AllEventTypes attribute.
+     213                 :            :  * Expected Behavior: Returns LIBSPDM_STATUS_UNSUPPORTED_CAP.
+     214                 :            :  **/
+     215                 :          1 : static void libspdm_test_requester_subscribe_event_types_err_case3(void **state)
+     216                 :            : {
+     217                 :            :     libspdm_return_t status;
+     218                 :            :     libspdm_test_context_t *spdm_test_context;
+     219                 :            :     libspdm_context_t *spdm_context;
+     220                 :            :     uint32_t session_id;
+     221                 :            : 
+     222                 :          1 :     spdm_test_context = *state;
+     223                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     224                 :          1 :     spdm_test_context->case_id = 0x3;
+     225                 :            : 
+     226                 :          1 :     set_standard_state(spdm_context, &session_id);
+     227                 :            :     /* Responder does not support event mechanism. */
+     228                 :          1 :     spdm_context->connection_info.capability.flags &=
+     229                 :            :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EVENT_CAP;
+     230                 :            : 
+     231                 :          1 :     status = libspdm_subscribe_event_types(spdm_context, session_id, 0, 0, NULL);
+     232                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_UNSUPPORTED_CAP);
+     233                 :          1 : }
+     234                 :            : 
+     235                 :          1 : int libspdm_requester_subscribe_event_types_error_test_main(void)
+     236                 :            : {
+     237                 :          1 :     libspdm_test_context_t test_context = {
+     238                 :            :         LIBSPDM_TEST_CONTEXT_VERSION,
+     239                 :            :         true,
+     240                 :            :         send_message,
+     241                 :            :         receive_message,
+     242                 :            :     };
+     243                 :            : 
+     244                 :          1 :     const struct CMUnitTest spdm_requester_get_event_types_tests[] = {
+     245                 :            :         cmocka_unit_test(libspdm_test_requester_subscribe_event_types_err_case1),
+     246                 :            :         cmocka_unit_test(libspdm_test_requester_subscribe_event_types_err_case2),
+     247                 :            :         cmocka_unit_test(libspdm_test_requester_subscribe_event_types_err_case3)
+     248                 :            :     };
+     249                 :            : 
+     250                 :          1 :     libspdm_setup_test_context(&test_context);
+     251                 :            : 
+     252                 :          1 :     return cmocka_run_group_tests(spdm_requester_get_event_types_tests,
+     253                 :            :                                   libspdm_unit_test_group_setup,
+     254                 :            :                                   libspdm_unit_test_group_teardown);
+     255                 :            : }
+     256                 :            : 
+     257                 :            : #endif /* LIBSPDM_EVENT_RECIPIENT_SUPPORT */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/error_test/vendor_request_err.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_requester/error_test/vendor_request_err.c.func-sort-c.html new file mode 100644 index 00000000000..2ec86530b2e --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/error_test/vendor_request_err.c.func-sort-c.html @@ -0,0 +1,105 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/error_test/vendor_request_err.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester/error_test - vendor_request_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:689273.9 %
Date:2024-09-22 08:21:07Functions:4666.7 %
Branches:31030.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_vendor_get_id_func_err_test0
libspdm_vendor_response_func_err_test0
libspdm_requester_vendor_cmds_err_test_receive_message1
libspdm_requester_vendor_cmds_err_test_send_message1
libspdm_requester_vendor_cmds_error_test_main1
libspdm_test_requester_vendor_cmds_err_case11
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/error_test/vendor_request_err.c.func.html b/coverage_log/unit_test/test_spdm_requester/error_test/vendor_request_err.c.func.html new file mode 100644 index 00000000000..8d402af71fb --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/error_test/vendor_request_err.c.func.html @@ -0,0 +1,105 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/error_test/vendor_request_err.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester/error_test - vendor_request_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:689273.9 %
Date:2024-09-22 08:21:07Functions:4666.7 %
Branches:31030.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_vendor_cmds_err_test_receive_message1
libspdm_requester_vendor_cmds_err_test_send_message1
libspdm_requester_vendor_cmds_error_test_main1
libspdm_test_requester_vendor_cmds_err_case11
libspdm_vendor_get_id_func_err_test0
libspdm_vendor_response_func_err_test0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/error_test/vendor_request_err.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/error_test/vendor_request_err.c.gcov.html new file mode 100644 index 00000000000..d4c1077ebc2 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/error_test/vendor_request_err.c.gcov.html @@ -0,0 +1,325 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/error_test/vendor_request_err.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester/error_test - vendor_request_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:689273.9 %
Date:2024-09-22 08:21:07Functions:4666.7 %
Branches:31030.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2023-2024 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_requester_lib.h"
+       9                 :            : #include "internal/libspdm_responder_lib.h"
+      10                 :            : 
+      11                 :            : #if LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES
+      12                 :            : 
+      13                 :            : #pragma pack(1)
+      14                 :            : typedef struct {
+      15                 :            :     spdm_message_header_t header;
+      16                 :            :     uint16_t standard_id;
+      17                 :            :     uint8_t vendor_id_len;
+      18                 :            :     uint8_t vendor_id[SPDM_MAX_VENDOR_ID_LENGTH];
+      19                 :            :     uint16_t data_len;
+      20                 :            :     uint8_t data[16];
+      21                 :            : } libspdm_vendor_request_test;
+      22                 :            : 
+      23                 :            : typedef struct {
+      24                 :            :     spdm_message_header_t header;
+      25                 :            :     uint16_t standard_id;
+      26                 :            :     uint8_t vendor_id_len;
+      27                 :            :     uint8_t vendor_id[SPDM_MAX_VENDOR_ID_LENGTH];
+      28                 :            :     uint16_t data_len;
+      29                 :            :     uint8_t data[64];
+      30                 :            : } libspdm_vendor_response_test;
+      31                 :            : #pragma pack()
+      32                 :            : 
+      33                 :            : static size_t m_libspdm_local_buffer_size;
+      34                 :            : static uint8_t m_libspdm_local_buffer[LIBSPDM_MAX_MESSAGE_VCA_BUFFER_SIZE];
+      35                 :            : 
+      36                 :          0 : libspdm_return_t libspdm_vendor_get_id_func_err_test(
+      37                 :            :     void *spdm_context,
+      38                 :            :     uint16_t *resp_standard_id,
+      39                 :            :     uint8_t *resp_vendor_id_len,
+      40                 :            :     void *resp_vendor_id)
+      41                 :            : {
+      42                 :          0 :     *resp_standard_id = 6;
+      43                 :          0 :     *resp_vendor_id_len = 2;
+      44                 :          0 :     ((uint8_t*)resp_vendor_id)[0] = 0xAA;
+      45                 :          0 :     ((uint8_t*)resp_vendor_id)[1] = 0xAA;
+      46                 :            : 
+      47                 :          0 :     return LIBSPDM_STATUS_SUCCESS;
+      48                 :            : }
+      49                 :            : 
+      50                 :          0 : libspdm_return_t libspdm_vendor_response_func_err_test(
+      51                 :            :     void *spdm_context,
+      52                 :            :     uint16_t req_standard_id,
+      53                 :            :     uint8_t req_vendor_id_len,
+      54                 :            :     const void *req_vendor_id,
+      55                 :            :     uint16_t req_size,
+      56                 :            :     const void *req_data,
+      57                 :            :     uint16_t *resp_size,
+      58                 :            :     void *resp_data)
+      59                 :            : {
+      60                 :            :     libspdm_vendor_response_test test_response;
+      61                 :            :     /* get pointer to response data payload and populate */
+      62                 :          0 :     uint8_t *resp_payload = (uint8_t *)resp_data;
+      63                 :            :     /* get pointer to response length and populate */
+      64                 :          0 :     *resp_size = sizeof(test_response.data);
+      65                 :            :     /* store length of response */
+      66                 :          0 :     libspdm_set_mem(resp_payload, *resp_size, 0xFF);
+      67                 :            : 
+      68   [ #  #  #  # ]:          0 :     if (resp_size == NULL || *resp_size == 0)
+      69                 :          0 :         return LIBSPDM_STATUS_INVALID_PARAMETER;
+      70                 :            : 
+      71                 :            :     /* TBD make an error here, like response len 65000, but different this time. */
+      72                 :            : 
+      73                 :          0 :     printf("Got request 0x%x, sent response 0x%x\n",
+      74                 :          0 :            ((const uint8_t*)req_data)[0], ((uint8_t*)resp_data)[0]);
+      75                 :            : 
+      76                 :          0 :     return LIBSPDM_STATUS_SUCCESS;
+      77                 :            : }
+      78                 :            : 
+      79                 :          1 : static libspdm_return_t libspdm_requester_vendor_cmds_err_test_send_message(
+      80                 :            :     void *spdm_context, size_t request_size, const void *request,
+      81                 :            :     uint64_t timeout)
+      82                 :            : {
+      83                 :            :     libspdm_test_context_t *spdm_test_context;
+      84                 :            : 
+      85                 :          1 :     spdm_test_context = libspdm_get_test_context();
+      86         [ +  - ]:          1 :     switch (spdm_test_context->case_id) {
+      87                 :          1 :     case 0x1: {
+      88                 :          1 :         const uint8_t *ptr = (const uint8_t *)request;
+      89                 :            : 
+      90                 :          1 :         m_libspdm_local_buffer_size = 0;
+      91                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+      92                 :            :                          ptr, request_size);
+      93                 :          1 :         m_libspdm_local_buffer_size += request_size;
+      94                 :            :     }
+      95                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      96                 :          0 :     default:
+      97                 :          0 :         return LIBSPDM_STATUS_SEND_FAIL;
+      98                 :            :     }
+      99                 :            : }
+     100                 :            : 
+     101                 :            : /* Acts as the Responder Integration */
+     102                 :          1 : static libspdm_return_t libspdm_requester_vendor_cmds_err_test_receive_message(
+     103                 :            :     void *spdm_context, size_t *response_size,
+     104                 :            :     void **response, uint64_t timeout)
+     105                 :            : {
+     106                 :            :     libspdm_test_context_t *spdm_test_context;
+     107                 :          1 :     libspdm_return_t status = LIBSPDM_STATUS_SUCCESS;
+     108                 :            : 
+     109                 :          1 :     uint32_t* session_id = NULL;
+     110                 :          1 :     bool is_app_message = false;
+     111                 :          1 :     size_t transport_message_size = sizeof(libspdm_vendor_request_test);
+     112                 :            : 
+     113                 :          1 :     spdm_test_context = libspdm_get_test_context();
+     114         [ +  - ]:          1 :     switch (spdm_test_context->case_id) {
+     115                 :          1 :     case 0x1: {
+     116                 :            :         libspdm_vendor_response_test *spdm_response;
+     117                 :          1 :         libspdm_vendor_request_test* spdm_request = NULL;
+     118                 :          1 :         status = libspdm_transport_test_decode_message(
+     119                 :            :             spdm_context, &session_id, &is_app_message, true,
+     120                 :            :             m_libspdm_local_buffer_size, m_libspdm_local_buffer,
+     121                 :            :             &transport_message_size, (void **)(&spdm_request));
+     122                 :          1 :         assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     123                 :            :         size_t spdm_response_size;
+     124                 :            :         size_t transport_header_size;
+     125                 :            : 
+     126                 :          1 :         spdm_response_size = sizeof(libspdm_vendor_response_test);
+     127                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     128                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     129                 :            : 
+     130                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     131                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     132                 :          1 :         spdm_response->header.request_response_code = SPDM_VENDOR_DEFINED_RESPONSE;
+     133                 :          1 :         spdm_response->header.param1 = 0;
+     134                 :          1 :         spdm_response->header.param2 = 0;
+     135                 :            : 
+     136                 :          1 :         spdm_response->standard_id = spdm_request->standard_id;
+     137                 :          1 :         spdm_response->vendor_id_len = spdm_request->vendor_id_len;
+     138                 :            :         /* usually 2 bytes for vendor id */
+     139                 :          1 :         assert_int_equal(spdm_response->vendor_id_len, sizeof(uint16_t));
+     140                 :          1 :         libspdm_copy_mem(spdm_response->vendor_id, spdm_request->vendor_id_len,
+     141                 :          1 :                          spdm_request->vendor_id, spdm_request->vendor_id_len);
+     142                 :            : 
+     143         [ +  - ]:          1 :         if (spdm_response->data_len < sizeof(spdm_response->data))
+     144                 :          1 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
+     145                 :            : 
+     146                 :          0 :         spdm_response->data_len = sizeof(spdm_response->data);
+     147                 :          0 :         libspdm_set_mem(spdm_response->data, sizeof(spdm_response->data), 0xff);
+     148                 :            : 
+     149                 :          0 :         status = libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     150                 :            :                                                        false, spdm_response_size,
+     151                 :            :                                                        spdm_response,
+     152                 :            :                                                        response_size, response);
+     153                 :          0 :         assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     154                 :            :     }
+     155                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     156                 :            : 
+     157                 :          0 :     default:
+     158                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+     159                 :            :     }
+     160                 :            : }
+     161                 :            : 
+     162                 :            : /**
+     163                 :            :  * Test 1: Sending a vendor defined request
+     164                 :            :  * Expected behavior: client returns a status of LIBSPDM_STATUS_INVALID_PARAMETER
+     165                 :            :  * due to invalid length of data field in the response
+     166                 :            :  **/
+     167                 :          1 : static void libspdm_test_requester_vendor_cmds_err_case1(void **state)
+     168                 :            : {
+     169                 :            :     libspdm_return_t status;
+     170                 :            :     libspdm_test_context_t *spdm_test_context;
+     171                 :            :     libspdm_context_t *spdm_context;
+     172                 :            :     libspdm_vendor_request_test request;
+     173                 :          1 :     libspdm_vendor_response_test response = {0};
+     174                 :          1 :     response.vendor_id_len = sizeof(response.vendor_id);
+     175                 :          1 :     response.data_len = sizeof(response.data);
+     176                 :            : 
+     177                 :          1 :     spdm_test_context = *state;
+     178                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     179                 :          1 :     spdm_test_context->case_id = 0x1;
+     180                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+     181                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     182                 :          1 :     spdm_context->connection_info.connection_state =
+     183                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     184                 :          1 :     spdm_context->local_context.is_requester = true;
+     185                 :            : 
+     186                 :          1 :     status = libspdm_register_vendor_get_id_callback_func(spdm_context,
+     187                 :            :                                                           libspdm_vendor_get_id_func_err_test);
+     188                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     189                 :          1 :     status = libspdm_register_vendor_callback_func(spdm_context,
+     190                 :            :                                                    libspdm_vendor_response_func_err_test);
+     191                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     192                 :            : 
+     193                 :          1 :     request.standard_id = 6;
+     194                 :          1 :     request.vendor_id_len = 2;
+     195                 :          1 :     request.vendor_id[0] = 0xAA;
+     196                 :          1 :     request.vendor_id[1] = 0xAA;
+     197                 :          1 :     request.data_len = sizeof(request.data);
+     198                 :          1 :     libspdm_set_mem(request.data, sizeof(request.data), 0xAA);
+     199                 :            : 
+     200                 :          1 :     response.data_len = 0; /* will generate error */
+     201                 :            : 
+     202                 :          1 :     status = libspdm_vendor_send_request_receive_response(spdm_context, NULL,
+     203                 :          1 :                                                           request.standard_id,
+     204                 :          1 :                                                           request.vendor_id_len,
+     205                 :          1 :                                                           request.vendor_id, request.data_len,
+     206                 :            :                                                           request.data,
+     207                 :            :                                                           &response.standard_id,
+     208                 :            :                                                           &response.vendor_id_len,
+     209                 :            :                                                           response.vendor_id, &response.data_len,
+     210                 :            :                                                           response.data);
+     211                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_RECEIVE_FAIL);
+     212                 :          1 :     assert_int_equal(
+     213                 :            :         spdm_context->connection_info.version >> SPDM_VERSION_NUMBER_SHIFT_BIT,
+     214                 :            :         SPDM_MESSAGE_VERSION_10);
+     215                 :            : 
+     216                 :          1 :     printf("case 1 %d\n", response.data[0]);
+     217                 :          1 : }
+     218                 :            : 
+     219                 :            : libspdm_test_context_t m_libspdm_requester_vendor_cmds_err_test_context = {
+     220                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+     221                 :            :     true,
+     222                 :            :     libspdm_requester_vendor_cmds_err_test_send_message,
+     223                 :            :     libspdm_requester_vendor_cmds_err_test_receive_message,
+     224                 :            : };
+     225                 :            : 
+     226                 :          1 : int libspdm_requester_vendor_cmds_error_test_main(void)
+     227                 :            : {
+     228                 :          1 :     const struct CMUnitTest spdm_requester_vendor_cmds_tests[] = {
+     229                 :            :         cmocka_unit_test(libspdm_test_requester_vendor_cmds_err_case1),
+     230                 :            :     };
+     231                 :            : 
+     232                 :          1 :     libspdm_setup_test_context(&m_libspdm_requester_vendor_cmds_err_test_context);
+     233                 :            : 
+     234                 :          1 :     return cmocka_run_group_tests(spdm_requester_vendor_cmds_tests,
+     235                 :            :                                   libspdm_unit_test_group_setup,
+     236                 :            :                                   libspdm_unit_test_group_teardown);
+     237                 :            : }
+     238                 :            : 
+     239                 :            : 
+     240                 :            : #endif /* LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/finish.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_requester/finish.c.func-sort-c.html new file mode 100644 index 00000000000..bed9738036a --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/finish.c.func-sort-c.html @@ -0,0 +1,193 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/finish.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - finish.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:1505166690.3 %
Date:2024-09-22 08:21:07Functions:2828100.0 %
Branches:648377.1 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_finish_test_main1
libspdm_test_requester_finish_case11
libspdm_test_requester_finish_case101
libspdm_test_requester_finish_case111
libspdm_test_requester_finish_case121
libspdm_test_requester_finish_case131
libspdm_test_requester_finish_case141
libspdm_test_requester_finish_case151
libspdm_test_requester_finish_case161
libspdm_test_requester_finish_case171
libspdm_test_requester_finish_case181
libspdm_test_requester_finish_case191
libspdm_test_requester_finish_case21
libspdm_test_requester_finish_case201
libspdm_test_requester_finish_case211
libspdm_test_requester_finish_case221
libspdm_test_requester_finish_case231
libspdm_test_requester_finish_case241
libspdm_test_requester_finish_case31
libspdm_test_requester_finish_case41
libspdm_test_requester_finish_case51
libspdm_test_requester_finish_case61
libspdm_test_requester_finish_case71
libspdm_test_requester_finish_case81
libspdm_test_requester_finish_case91
libspdm_requester_finish_test_receive_message38
libspdm_requester_finish_test_send_message39
libspdm_secured_message_set_response_finished_key40
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/finish.c.func.html b/coverage_log/unit_test/test_spdm_requester/finish.c.func.html new file mode 100644 index 00000000000..002e8c26a10 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/finish.c.func.html @@ -0,0 +1,193 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/finish.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - finish.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:1505166690.3 %
Date:2024-09-22 08:21:07Functions:2828100.0 %
Branches:648377.1 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_finish_test_main1
libspdm_requester_finish_test_receive_message38
libspdm_requester_finish_test_send_message39
libspdm_secured_message_set_response_finished_key40
libspdm_test_requester_finish_case11
libspdm_test_requester_finish_case101
libspdm_test_requester_finish_case111
libspdm_test_requester_finish_case121
libspdm_test_requester_finish_case131
libspdm_test_requester_finish_case141
libspdm_test_requester_finish_case151
libspdm_test_requester_finish_case161
libspdm_test_requester_finish_case171
libspdm_test_requester_finish_case181
libspdm_test_requester_finish_case191
libspdm_test_requester_finish_case21
libspdm_test_requester_finish_case201
libspdm_test_requester_finish_case211
libspdm_test_requester_finish_case221
libspdm_test_requester_finish_case231
libspdm_test_requester_finish_case241
libspdm_test_requester_finish_case31
libspdm_test_requester_finish_case41
libspdm_test_requester_finish_case51
libspdm_test_requester_finish_case61
libspdm_test_requester_finish_case71
libspdm_test_requester_finish_case81
libspdm_test_requester_finish_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/finish.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/finish.c.gcov.html new file mode 100644 index 00000000000..c5f7ced8019 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/finish.c.gcov.html @@ -0,0 +1,3987 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/finish.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - finish.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:1505166690.3 %
Date:2024-09-22 08:21:07Functions:2828100.0 %
Branches:648377.1 %
+
+ + + + + + + + +

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

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_get_capabilities_test_main1
libspdm_test_requester_get_capabilities_case101
libspdm_test_requester_get_capabilities_case111
libspdm_test_requester_get_capabilities_case121
libspdm_test_requester_get_capabilities_case161
libspdm_test_requester_get_capabilities_case21
libspdm_test_requester_get_capabilities_case321
libspdm_test_requester_get_capabilities_case331
libspdm_test_requester_get_capabilities_case351
libspdm_test_requester_get_capabilities_case61
libspdm_requester_get_capabilities_test_receive_message10
libspdm_requester_get_capabilities_test_send_message10
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/get_capabilities.c.func.html b/coverage_log/unit_test/test_spdm_requester/get_capabilities.c.func.html new file mode 100644 index 00000000000..b4ee30f0653 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/get_capabilities.c.func.html @@ -0,0 +1,129 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/get_capabilities.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - get_capabilities.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:29764745.9 %
Date:2024-09-22 08:21:07Functions:1212100.0 %
Branches:218325.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_get_capabilities_test_main1
libspdm_requester_get_capabilities_test_receive_message10
libspdm_requester_get_capabilities_test_send_message10
libspdm_test_requester_get_capabilities_case101
libspdm_test_requester_get_capabilities_case111
libspdm_test_requester_get_capabilities_case121
libspdm_test_requester_get_capabilities_case161
libspdm_test_requester_get_capabilities_case21
libspdm_test_requester_get_capabilities_case321
libspdm_test_requester_get_capabilities_case331
libspdm_test_requester_get_capabilities_case351
libspdm_test_requester_get_capabilities_case61
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/get_capabilities.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/get_capabilities.c.gcov.html new file mode 100644 index 00000000000..349907381d9 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/get_capabilities.c.gcov.html @@ -0,0 +1,1572 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/get_capabilities.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - get_capabilities.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:29764745.9 %
Date:2024-09-22 08:21:07Functions:1212100.0 %
Branches:218325.3 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_requester_lib.h"
+       9                 :            : 
+      10                 :            : #define LIBSPDM_DEFAULT_CAPABILITY_FLAG \
+      11                 :            :     (SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | \
+      12                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP)
+      13                 :            : 
+      14                 :            : #define LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11 \
+      15                 :            :     (SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | \
+      16                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP | \
+      17                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP | \
+      18                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP | \
+      19                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP | \
+      20                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP | \
+      21                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER | \
+      22                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP | \
+      23                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP | \
+      24                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP | \
+      25                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)
+      26                 :            : 
+      27                 :            : #define LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_12  SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP
+      28                 :            : 
+      29                 :            : #define LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 \
+      30                 :            :     (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CACHE_CAP | \
+      31                 :            :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP | \
+      32                 :            :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP | \
+      33                 :            :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG | \
+      34                 :            :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_FRESH_CAP | \
+      35                 :            :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP | \
+      36                 :            :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP | \
+      37                 :            :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP | \
+      38                 :            :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP | \
+      39                 :            :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT | \
+      40                 :            :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP | \
+      41                 :            :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP | \
+      42                 :            :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_UPD_CAP | \
+      43                 :            :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)
+      44                 :            : 
+      45                 :            : #define LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_12 \
+      46                 :            :     (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP | \
+      47                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | \
+      48                 :            :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ALIAS_CERT_CAP | \
+      49                 :            :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP)
+      50                 :            : 
+      51                 :            :  #define LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_13 \
+      52                 :            :     (LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 | \
+      53                 :            :      LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_12 | \
+      54                 :            :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EP_INFO_CAP_NO_SIG  | \
+      55                 :            :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEL_CAP | \
+      56                 :            :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EVENT_CAP | \
+      57                 :            :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MULTI_KEY_CAP_ONLY | \
+      58                 :            :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_GET_KEY_PAIR_INFO_CAP)
+      59                 :            : 
+      60                 :            : static size_t m_libspdm_local_buffer_size;
+      61                 :            : static uint8_t m_libspdm_local_buffer[LIBSPDM_MAX_MESSAGE_VCA_BUFFER_SIZE];
+      62                 :            : 
+      63                 :         10 : static libspdm_return_t libspdm_requester_get_capabilities_test_send_message(
+      64                 :            :     void *spdm_context, size_t request_size, const void *request,
+      65                 :            :     uint64_t timeout)
+      66                 :            : {
+      67                 :            :     libspdm_test_context_t *spdm_test_context;
+      68                 :            : 
+      69                 :         10 :     spdm_test_context = libspdm_get_test_context();
+      70   [ -  +  -  -  :         10 :     switch (spdm_test_context->case_id) {
+          -  +  -  -  -  
+          +  +  +  -  -  
+          -  +  -  -  -  
+          -  -  -  -  -  
+          -  -  -  -  -  
+          -  -  +  +  -  
+                   +  - ]
+      71                 :          0 :     case 0x1:
+      72                 :          0 :         return LIBSPDM_STATUS_SEND_FAIL;
+      73                 :          1 :     case 0x2:
+      74                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      75                 :          0 :     case 0x3:
+      76                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      77                 :          0 :     case 0x4:
+      78                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      79                 :          0 :     case 0x5:
+      80                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      81                 :          2 :     case 0x6:
+      82                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+      83                 :          0 :     case 0x7:
+      84                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      85                 :          0 :     case 0x8:
+      86                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      87                 :          0 :     case 0x9:
+      88                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      89                 :          1 :     case 0xa:
+      90                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      91                 :          1 :     case 0xb:
+      92                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      93                 :          1 :     case 0xc:
+      94                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      95                 :          0 :     case 0xd:
+      96                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      97                 :          0 :     case 0xe:
+      98                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      99                 :          0 :     case 0xf:
+     100                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     101                 :          1 :     case 0x10:
+     102                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     103                 :          0 :     case 0x11:
+     104                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     105                 :          0 :     case 0x12:
+     106                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     107                 :          0 :     case 0x13:
+     108                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     109                 :          0 :     case 0x14:
+     110                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     111                 :          0 :     case 0x15:
+     112                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     113                 :          0 :     case 0x16:
+     114                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     115                 :          0 :     case 0x17:
+     116                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     117                 :          0 :     case 0x18:
+     118                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     119                 :          0 :     case 0x19:
+     120                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     121                 :          0 :     case 0x1a:
+     122                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     123                 :          0 :     case 0x1b:
+     124                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     125                 :          0 :     case 0x1c:
+     126                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     127                 :          0 :     case 0x1d:
+     128                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     129                 :          0 :     case 0x1E:
+     130                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     131                 :          0 :     case 0x1F:
+     132                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     133                 :          1 :     case 0x20: {
+     134                 :          1 :         const uint8_t *ptr = (const uint8_t *)request;
+     135                 :            : 
+     136                 :          1 :         m_libspdm_local_buffer_size = 0;
+     137                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer), &ptr[1],
+     138                 :            :                          request_size - 1);
+     139                 :          1 :         m_libspdm_local_buffer_size += (request_size - 1);
+     140                 :            :     }
+     141                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     142                 :          1 :     case 0x21:
+     143                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     144                 :          0 :     case 0x22:
+     145                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     146                 :          1 :     case 0x23:
+     147                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     148                 :          0 :     default:
+     149                 :          0 :         return LIBSPDM_STATUS_SEND_FAIL;
+     150                 :            :     }
+     151                 :            : }
+     152                 :            : 
+     153                 :         10 : static libspdm_return_t libspdm_requester_get_capabilities_test_receive_message(
+     154                 :            :     void *spdm_context, size_t *response_size,
+     155                 :            :     void **response, uint64_t timeout)
+     156                 :            : {
+     157                 :            :     libspdm_test_context_t *spdm_test_context;
+     158                 :            : 
+     159                 :         10 :     spdm_test_context = libspdm_get_test_context();
+     160   [ -  +  -  -  :         10 :     switch (spdm_test_context->case_id) {
+          -  +  -  -  -  
+          +  +  +  -  -  
+          -  +  -  -  -  
+          -  -  -  -  -  
+          -  -  -  -  -  
+          -  +  +  -  +  
+                      - ]
+     161                 :          0 :     case 0x1:
+     162                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+     163                 :            : 
+     164                 :          1 :     case 0x2: {
+     165                 :            :         spdm_capabilities_response_t *spdm_response;
+     166                 :            :         size_t spdm_response_size;
+     167                 :            :         size_t transport_header_size;
+     168                 :            : 
+     169                 :          1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     170                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     171                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     172                 :            : 
+     173                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     174                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     175                 :          1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     176                 :          1 :         spdm_response->header.param1 = 0;
+     177                 :          1 :         spdm_response->header.param2 = 0;
+     178                 :          1 :         spdm_response->ct_exponent = 0;
+     179                 :          1 :         spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+     180                 :            : 
+     181                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     182                 :            :                                               false, spdm_response_size,
+     183                 :            :                                               spdm_response,
+     184                 :            :                                               response_size, response);
+     185                 :            :     }
+     186                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     187                 :            : 
+     188                 :          0 :     case 0x3: {
+     189                 :            :         spdm_capabilities_response_t *spdm_response;
+     190                 :            :         size_t spdm_response_size;
+     191                 :            :         size_t transport_header_size;
+     192                 :            : 
+     193                 :          0 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     194                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     195                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     196                 :            : 
+     197                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     198                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     199                 :          0 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     200                 :          0 :         spdm_response->header.param1 = 0;
+     201                 :          0 :         spdm_response->header.param2 = 0;
+     202                 :          0 :         spdm_response->ct_exponent = 0;
+     203                 :          0 :         spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+     204                 :            : 
+     205                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     206                 :            :                                               false, spdm_response_size,
+     207                 :            :                                               spdm_response,
+     208                 :            :                                               response_size, response);
+     209                 :            :     }
+     210                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     211                 :            : 
+     212                 :          0 :     case 0x4: {
+     213                 :            :         spdm_error_response_t *spdm_response;
+     214                 :            :         size_t spdm_response_size;
+     215                 :            :         size_t transport_header_size;
+     216                 :            : 
+     217                 :          0 :         spdm_response_size = sizeof(spdm_error_response_t);
+     218                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     219                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     220                 :            : 
+     221                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     222                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     223                 :          0 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     224                 :          0 :         spdm_response->header.param1 = SPDM_ERROR_CODE_INVALID_REQUEST;
+     225                 :          0 :         spdm_response->header.param2 = 0;
+     226                 :            : 
+     227                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     228                 :            :                                               false, spdm_response_size,
+     229                 :            :                                               spdm_response,
+     230                 :            :                                               response_size, response);
+     231                 :            :     }
+     232                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     233                 :            : 
+     234                 :          0 :     case 0x5: {
+     235                 :            :         spdm_error_response_t *spdm_response;
+     236                 :            :         size_t spdm_response_size;
+     237                 :            :         size_t transport_header_size;
+     238                 :            : 
+     239                 :          0 :         spdm_response_size = sizeof(spdm_error_response_t);
+     240                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     241                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     242                 :            : 
+     243                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     244                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     245                 :          0 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     246                 :          0 :         spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
+     247                 :          0 :         spdm_response->header.param2 = 0;
+     248                 :            : 
+     249                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     250                 :            :                                               false, spdm_response_size,
+     251                 :            :                                               spdm_response,
+     252                 :            :                                               response_size, response);
+     253                 :            :     }
+     254                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     255                 :            : 
+     256                 :          2 :     case 0x6: {
+     257                 :            :         static size_t sub_index1 = 0;
+     258         [ +  + ]:          2 :         if (sub_index1 == 0) {
+     259                 :            :             spdm_error_response_t *spdm_response;
+     260                 :            :             size_t spdm_response_size;
+     261                 :            :             size_t transport_header_size;
+     262                 :            : 
+     263                 :          1 :             spdm_response_size = sizeof(spdm_error_response_t);
+     264                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     265                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     266                 :            : 
+     267                 :          1 :             libspdm_zero_mem(spdm_response, spdm_response_size);
+     268                 :          1 :             spdm_response->header.spdm_version =
+     269                 :            :                 SPDM_MESSAGE_VERSION_10;
+     270                 :          1 :             spdm_response->header.request_response_code = SPDM_ERROR;
+     271                 :          1 :             spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
+     272                 :          1 :             spdm_response->header.param2 = 0;
+     273                 :            : 
+     274                 :          1 :             libspdm_transport_test_encode_message(
+     275                 :            :                 spdm_context, NULL, false, false,
+     276                 :            :                 spdm_response_size, spdm_response,
+     277                 :            :                 response_size, response);
+     278         [ +  - ]:          1 :         } else if (sub_index1 == 1) {
+     279                 :            :             spdm_capabilities_response_t *spdm_response;
+     280                 :            :             size_t spdm_response_size;
+     281                 :            :             size_t transport_header_size;
+     282                 :            : 
+     283                 :          1 :             spdm_response_size = sizeof(spdm_capabilities_response_t);
+     284                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     285                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     286                 :            : 
+     287                 :          1 :             libspdm_zero_mem(spdm_response, spdm_response_size);
+     288                 :          1 :             spdm_response->header.spdm_version =
+     289                 :            :                 SPDM_MESSAGE_VERSION_10;
+     290                 :          1 :             spdm_response->header.request_response_code =
+     291                 :            :                 SPDM_CAPABILITIES;
+     292                 :          1 :             spdm_response->header.param1 = 0;
+     293                 :          1 :             spdm_response->header.param2 = 0;
+     294                 :          1 :             spdm_response->ct_exponent = 0;
+     295                 :          1 :             spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+     296                 :            : 
+     297                 :          1 :             libspdm_transport_test_encode_message(
+     298                 :            :                 spdm_context, NULL, false, false,
+     299                 :            :                 spdm_response_size, spdm_response,
+     300                 :            :                 response_size, response);
+     301                 :            :         }
+     302                 :          2 :         sub_index1++;
+     303                 :            :     }
+     304                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     305                 :            : 
+     306                 :          0 :     case 0x7: {
+     307                 :            :         spdm_error_response_t *spdm_response;
+     308                 :            :         size_t spdm_response_size;
+     309                 :            :         size_t transport_header_size;
+     310                 :            : 
+     311                 :          0 :         spdm_response_size = sizeof(spdm_error_response_t);
+     312                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     313                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     314                 :            : 
+     315                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     316                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     317                 :          0 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     318                 :          0 :         spdm_response->header.param1 = SPDM_ERROR_CODE_REQUEST_RESYNCH;
+     319                 :          0 :         spdm_response->header.param2 = 0;
+     320                 :            : 
+     321                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     322                 :            :                                               false, spdm_response_size,
+     323                 :            :                                               spdm_response,
+     324                 :            :                                               response_size, response);
+     325                 :            :     }
+     326                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     327                 :            : 
+     328                 :          0 :     case 0x8: {
+     329                 :            :         spdm_error_response_data_response_not_ready_t *spdm_response;
+     330                 :            :         size_t spdm_response_size;
+     331                 :            :         size_t transport_header_size;
+     332                 :            : 
+     333                 :          0 :         spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
+     334                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     335                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     336                 :            : 
+     337                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     338                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     339                 :          0 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     340                 :          0 :         spdm_response->header.param1 = SPDM_ERROR_CODE_RESPONSE_NOT_READY;
+     341                 :          0 :         spdm_response->header.param2 = 0;
+     342                 :          0 :         spdm_response->extend_error_data.rd_exponent = 1;
+     343                 :          0 :         spdm_response->extend_error_data.rd_tm = 2;
+     344                 :          0 :         spdm_response->extend_error_data.request_code = SPDM_GET_CAPABILITIES;
+     345                 :          0 :         spdm_response->extend_error_data.token = 0;
+     346                 :            : 
+     347                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     348                 :            :                                               false, spdm_response_size,
+     349                 :            :                                               spdm_response,
+     350                 :            :                                               response_size, response);
+     351                 :            :     }
+     352                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     353                 :            : 
+     354                 :          0 :     case 0x9:
+     355                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     356                 :            : 
+     357                 :          1 :     case 0xa: {
+     358                 :            :         spdm_capabilities_response_t *spdm_response;
+     359                 :            :         size_t spdm_response_size;
+     360                 :            :         size_t transport_header_size;
+     361                 :            : 
+     362                 :          1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     363                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     364                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     365                 :            : 
+     366                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     367                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     368                 :          1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     369                 :          1 :         spdm_response->header.param1 = 0;
+     370                 :          1 :         spdm_response->header.param2 = 0;
+     371                 :          1 :         spdm_response->ct_exponent = 0;
+     372                 :          1 :         spdm_response->flags =
+     373                 :            :             (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CACHE_CAP |
+     374                 :            :              SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP |
+     375                 :            :              SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP |
+     376                 :            :              SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG |
+     377                 :            :              SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_FRESH_CAP);
+     378                 :            : 
+     379                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     380                 :            :                                               false, spdm_response_size,
+     381                 :            :                                               spdm_response,
+     382                 :            :                                               response_size, response);
+     383                 :            :     }
+     384                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     385                 :            : 
+     386                 :          1 :     case 0xb: {
+     387                 :            :         spdm_capabilities_response_t *spdm_response;
+     388                 :            :         size_t spdm_response_size;
+     389                 :            :         size_t transport_header_size;
+     390                 :            : 
+     391                 :          1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     392                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     393                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     394                 :            : 
+     395                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     396                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     397                 :          1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     398                 :          1 :         spdm_response->header.param1 = 0;
+     399                 :          1 :         spdm_response->header.param2 = 0;
+     400                 :          1 :         spdm_response->ct_exponent = 0;
+     401                 :          1 :         spdm_response->flags =
+     402                 :            :             !(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CACHE_CAP |
+     403                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP |
+     404                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP |
+     405                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG |
+     406                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_FRESH_CAP);
+     407                 :            : 
+     408                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     409                 :            :                                               false, spdm_response_size,
+     410                 :            :                                               spdm_response,
+     411                 :            :                                               response_size, response);
+     412                 :            :     }
+     413                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     414                 :            : 
+     415                 :          1 :     case 0xc: {
+     416                 :            :         spdm_capabilities_response_t *spdm_response;
+     417                 :            :         size_t spdm_response_size;
+     418                 :            :         size_t transport_header_size;
+     419                 :            : 
+     420                 :          1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     421                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     422                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     423                 :            : 
+     424                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     425                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     426                 :          1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     427                 :          1 :         spdm_response->header.param1 = 0;
+     428                 :          1 :         spdm_response->header.param2 = 0;
+     429                 :          1 :         spdm_response->ct_exponent = 0;
+     430                 :          1 :         spdm_response->flags = SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_FRESH_CAP |
+     431                 :            :                                SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG;
+     432                 :            : 
+     433                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     434                 :            :                                               false, spdm_response_size,
+     435                 :            :                                               spdm_response,
+     436                 :            :                                               response_size, response);
+     437                 :            :     }
+     438                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     439                 :            : 
+     440                 :          0 :     case 0xd: {
+     441                 :            :         spdm_capabilities_response_t *spdm_response;
+     442                 :            :         size_t spdm_response_size;
+     443                 :            :         size_t transport_header_size;
+     444                 :            : 
+     445                 :          0 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     446                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     447                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     448                 :            : 
+     449                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     450                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     451                 :          0 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     452                 :          0 :         spdm_response->header.param1 = 0;
+     453                 :          0 :         spdm_response->header.param2 = 0;
+     454                 :            : 
+     455                 :          0 :         libspdm_transport_test_encode_message(
+     456                 :            :             spdm_context, NULL, false, false,
+     457                 :            :             sizeof(spdm_message_header_t), spdm_response,
+     458                 :            :             response_size, response);
+     459                 :            :     }
+     460                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     461                 :            : 
+     462                 :          0 :     case 0xe: {
+     463                 :            :         spdm_capabilities_response_t *spdm_response;
+     464                 :            :         size_t spdm_response_size;
+     465                 :            :         size_t transport_header_size;
+     466                 :            : 
+     467                 :          0 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     468                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     469                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     470                 :            : 
+     471                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     472                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     473                 :          0 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     474                 :          0 :         spdm_response->header.param1 = 0;
+     475                 :          0 :         spdm_response->header.param2 = 0;
+     476                 :          0 :         spdm_response->ct_exponent = 0;
+     477                 :          0 :         spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+     478                 :            : 
+     479                 :          0 :         libspdm_transport_test_encode_message(
+     480                 :            :             spdm_context, NULL, false, false,
+     481                 :            :             sizeof(spdm_capabilities_response_t) + sizeof(uint8_t), spdm_response,
+     482                 :            :             response_size, response);
+     483                 :            :     }
+     484                 :          0 :         return LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     485                 :            : 
+     486                 :          0 :     case 0xf: {
+     487                 :            :         spdm_capabilities_response_t *spdm_response;
+     488                 :            :         size_t spdm_response_size;
+     489                 :            :         size_t transport_header_size;
+     490                 :            : 
+     491                 :          0 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     492                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     493                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     494                 :            : 
+     495                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     496                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     497                 :          0 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     498                 :          0 :         spdm_response->header.param1 = 0;
+     499                 :          0 :         spdm_response->header.param2 = 0;
+     500                 :          0 :         spdm_response->ct_exponent = 0;
+     501                 :          0 :         spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+     502                 :            : 
+     503                 :          0 :         libspdm_transport_test_encode_message(
+     504                 :            :             spdm_context, NULL, false, false,
+     505                 :            :             sizeof(spdm_capabilities_response_t) - sizeof(uint8_t), spdm_response,
+     506                 :            :             response_size, response);
+     507                 :            :     }
+     508                 :          0 :         return LIBSPDM_STATUS_INVALID_MSG_SIZE;
+     509                 :            : 
+     510                 :          1 :     case 0x10: {
+     511                 :            :         spdm_capabilities_response_t *spdm_response;
+     512                 :            :         size_t spdm_response_size;
+     513                 :            :         size_t transport_header_size;
+     514                 :            : 
+     515                 :          1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     516                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     517                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     518                 :            : 
+     519                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     520                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     521                 :          1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     522                 :          1 :         spdm_response->header.param1 = 0;
+     523                 :          1 :         spdm_response->header.param2 = 0;
+     524                 :          1 :         spdm_response->ct_exponent = 0;
+     525                 :          1 :         spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11;
+     526                 :            : 
+     527                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     528                 :            :                                               false, spdm_response_size,
+     529                 :            :                                               spdm_response,
+     530                 :            :                                               response_size, response);
+     531                 :            :     }
+     532                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     533                 :            : 
+     534                 :          0 :     case 0x11: {
+     535                 :            :         spdm_capabilities_response_t *spdm_response;
+     536                 :            :         size_t spdm_response_size;
+     537                 :            :         size_t transport_header_size;
+     538                 :            : 
+     539                 :          0 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     540                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     541                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     542                 :            : 
+     543                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     544                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     545                 :          0 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     546                 :          0 :         spdm_response->header.param1 = 0;
+     547                 :          0 :         spdm_response->header.param2 = 0;
+     548                 :          0 :         spdm_response->ct_exponent = 0;
+     549                 :          0 :         spdm_response->flags =
+     550                 :            :             LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
+     551                 :            :             (0xFFFFFFFF ^
+     552                 :            :              (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
+     553                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP |
+     554                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP));
+     555                 :            : 
+     556                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     557                 :            :                                               false, spdm_response_size,
+     558                 :            :                                               spdm_response,
+     559                 :            :                                               response_size, response);
+     560                 :            :     }
+     561                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     562                 :            : 
+     563                 :          0 :     case 0x12: {
+     564                 :            :         spdm_capabilities_response_t *spdm_response;
+     565                 :            :         size_t spdm_response_size;
+     566                 :            :         size_t transport_header_size;
+     567                 :            : 
+     568                 :          0 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     569                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     570                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     571                 :            : 
+     572                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     573                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     574                 :          0 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     575                 :          0 :         spdm_response->header.param1 = 0;
+     576                 :          0 :         spdm_response->header.param2 = 0;
+     577                 :          0 :         spdm_response->ct_exponent = 0;
+     578                 :          0 :         spdm_response->flags =
+     579                 :            :             LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
+     580                 :            :             (0xFFFFFFFF ^
+     581                 :            :              (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP |
+     582                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
+     583                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP |
+     584                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP));
+     585                 :            : 
+     586                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     587                 :            :                                               false, spdm_response_size,
+     588                 :            :                                               spdm_response,
+     589                 :            :                                               response_size, response);
+     590                 :            :     }
+     591                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     592                 :            : 
+     593                 :          0 :     case 0x13: {
+     594                 :            :         spdm_capabilities_response_t *spdm_response;
+     595                 :            :         size_t spdm_response_size;
+     596                 :            :         size_t transport_header_size;
+     597                 :            : 
+     598                 :          0 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     599                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     600                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     601                 :            : 
+     602                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     603                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     604                 :          0 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     605                 :          0 :         spdm_response->header.param1 = 0;
+     606                 :          0 :         spdm_response->header.param2 = 0;
+     607                 :          0 :         spdm_response->ct_exponent = 0;
+     608                 :          0 :         spdm_response->flags =
+     609                 :            :             LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
+     610                 :            :             (0xFFFFFFFF ^
+     611                 :            :              (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP |
+     612                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
+     613                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP |
+     614                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP));
+     615                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     616                 :            :                                               false, spdm_response_size,
+     617                 :            :                                               spdm_response,
+     618                 :            :                                               response_size, response);
+     619                 :            :     }
+     620                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     621                 :            : 
+     622                 :          0 :     case 0x14: {
+     623                 :            :         spdm_capabilities_response_t *spdm_response;
+     624                 :            :         size_t spdm_response_size;
+     625                 :            :         size_t transport_header_size;
+     626                 :            : 
+     627                 :          0 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     628                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     629                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     630                 :            : 
+     631                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     632                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     633                 :          0 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     634                 :          0 :         spdm_response->header.param1 = 0;
+     635                 :          0 :         spdm_response->header.param2 = 0;
+     636                 :          0 :         spdm_response->ct_exponent = 0;
+     637                 :          0 :         spdm_response->flags =
+     638                 :            :             LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
+     639                 :            :             (0xFFFFFFFF ^
+     640                 :            :              (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP |
+     641                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP |
+     642                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP));
+     643                 :            : 
+     644                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     645                 :            :                                               false, spdm_response_size,
+     646                 :            :                                               spdm_response,
+     647                 :            :                                               response_size, response);
+     648                 :            :     }
+     649                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     650                 :            : 
+     651                 :          0 :     case 0x15: {
+     652                 :            :         spdm_capabilities_response_t *spdm_response;
+     653                 :            :         size_t spdm_response_size;
+     654                 :            :         size_t transport_header_size;
+     655                 :            : 
+     656                 :          0 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     657                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     658                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     659                 :            : 
+     660                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     661                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     662                 :          0 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     663                 :          0 :         spdm_response->header.param1 = 0;
+     664                 :          0 :         spdm_response->header.param2 = 0;
+     665                 :          0 :         spdm_response->ct_exponent = 0;
+     666                 :          0 :         spdm_response->flags =
+     667                 :            :             LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
+     668                 :            :             (0xFFFFFFFF ^
+     669                 :            :              (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP |
+     670                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP |
+     671                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP |
+     672                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP));
+     673                 :            : 
+     674                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     675                 :            :                                               false, spdm_response_size,
+     676                 :            :                                               spdm_response,
+     677                 :            :                                               response_size, response);
+     678                 :            :     }
+     679                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     680                 :            : 
+     681                 :          0 :     case 0x16: {
+     682                 :            :         spdm_capabilities_response_t *spdm_response;
+     683                 :            :         size_t spdm_response_size;
+     684                 :            :         size_t transport_header_size;
+     685                 :            : 
+     686                 :          0 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     687                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     688                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     689                 :            : 
+     690                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     691                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     692                 :          0 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     693                 :          0 :         spdm_response->header.param1 = 0;
+     694                 :          0 :         spdm_response->header.param2 = 0;
+     695                 :          0 :         spdm_response->ct_exponent = 0;
+     696                 :          0 :         spdm_response->flags =
+     697                 :            :             LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
+     698                 :            :             (0xFFFFFFFF ^
+     699                 :            :              (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP |
+     700                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP |
+     701                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
+     702                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP));
+     703                 :            : 
+     704                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     705                 :            :                                               false, spdm_response_size,
+     706                 :            :                                               spdm_response,
+     707                 :            :                                               response_size, response);
+     708                 :            :     }
+     709                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     710                 :            : 
+     711                 :          0 :     case 0x17: {
+     712                 :            :         spdm_capabilities_response_t *spdm_response;
+     713                 :            :         size_t spdm_response_size;
+     714                 :            :         size_t transport_header_size;
+     715                 :            : 
+     716                 :          0 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     717                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     718                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     719                 :            : 
+     720                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     721                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     722                 :          0 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     723                 :          0 :         spdm_response->header.param1 = 0;
+     724                 :          0 :         spdm_response->header.param2 = 0;
+     725                 :          0 :         spdm_response->ct_exponent = 0;
+     726                 :          0 :         spdm_response->flags =
+     727                 :            :             LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
+     728                 :            :             (0xFFFFFFFF ^
+     729                 :            :              (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP));
+     730                 :            : 
+     731                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     732                 :            :                                               false, spdm_response_size,
+     733                 :            :                                               spdm_response,
+     734                 :            :                                               response_size, response);
+     735                 :            :     }
+     736                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     737                 :            : 
+     738                 :          0 :     case 0x18: {
+     739                 :            :         spdm_capabilities_response_t *spdm_response;
+     740                 :            :         size_t spdm_response_size;
+     741                 :            :         size_t transport_header_size;
+     742                 :            : 
+     743                 :          0 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     744                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     745                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     746                 :            : 
+     747                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     748                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     749                 :          0 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     750                 :          0 :         spdm_response->header.param1 = 0;
+     751                 :          0 :         spdm_response->header.param2 = 0;
+     752                 :          0 :         spdm_response->ct_exponent = 0;
+     753                 :          0 :         spdm_response->flags =
+     754                 :            :             LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
+     755                 :            :             (0xFFFFFFFF ^
+     756                 :            :              (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP));
+     757                 :            : 
+     758                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     759                 :            :                                               false, spdm_response_size,
+     760                 :            :                                               spdm_response,
+     761                 :            :                                               response_size, response);
+     762                 :            :     }
+     763                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     764                 :            : 
+     765                 :          0 :     case 0x19: {
+     766                 :            :         spdm_capabilities_response_t *spdm_response;
+     767                 :            :         size_t spdm_response_size;
+     768                 :            :         size_t transport_header_size;
+     769                 :            : 
+     770                 :          0 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     771                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     772                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     773                 :            : 
+     774                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     775                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     776                 :          0 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     777                 :          0 :         spdm_response->header.param1 = 0;
+     778                 :          0 :         spdm_response->header.param2 = 0;
+     779                 :          0 :         spdm_response->ct_exponent = 0;
+     780                 :          0 :         spdm_response->flags =
+     781                 :            :             LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
+     782                 :            :             (0xFFFFFFFF ^
+     783                 :            :              (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP |
+     784                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP |
+     785                 :            :               SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP));
+     786                 :            : 
+     787                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     788                 :            :                                               false, spdm_response_size,
+     789                 :            :                                               spdm_response,
+     790                 :            :                                               response_size, response);
+     791                 :            :     }
+     792                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     793                 :            : 
+     794                 :          0 :     case 0x1a: {
+     795                 :            :         spdm_capabilities_response_t *spdm_response;
+     796                 :            :         size_t spdm_response_size;
+     797                 :            :         size_t transport_header_size;
+     798                 :            : 
+     799                 :          0 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     800                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     801                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     802                 :            : 
+     803                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     804                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     805                 :          0 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     806                 :          0 :         spdm_response->header.param1 = 0;
+     807                 :          0 :         spdm_response->header.param2 = 0;
+     808                 :          0 :         spdm_response->ct_exponent = 0;
+     809                 :          0 :         spdm_response->flags =
+     810                 :            :             LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 |
+     811                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PUB_KEY_ID_CAP;
+     812                 :            : 
+     813                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     814                 :            :                                               false, spdm_response_size,
+     815                 :            :                                               spdm_response,
+     816                 :            :                                               response_size, response);
+     817                 :            :     }
+     818                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     819                 :            : 
+     820                 :          0 :     case 0x1b: {
+     821                 :            :         spdm_capabilities_response_t *spdm_response;
+     822                 :            :         size_t spdm_response_size;
+     823                 :            :         size_t transport_header_size;
+     824                 :            : 
+     825                 :          0 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     826                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     827                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     828                 :            : 
+     829                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     830                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     831                 :          0 :         spdm_response->header.request_response_code =
+     832                 :            :             SPDM_GET_CAPABILITIES;
+     833                 :          0 :         spdm_response->header.param1 = 0;
+     834                 :          0 :         spdm_response->header.param2 = 0;
+     835                 :          0 :         spdm_response->ct_exponent = 0;
+     836                 :          0 :         spdm_response->flags =
+     837                 :            :             LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11;
+     838                 :            : 
+     839                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     840                 :            :                                               false, spdm_response_size,
+     841                 :            :                                               spdm_response,
+     842                 :            :                                               response_size, response);
+     843                 :            :     }
+     844                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     845                 :            : 
+     846                 :          0 :     case 0x1c: {
+     847                 :            :         spdm_capabilities_response_t *spdm_response;
+     848                 :            :         size_t spdm_response_size;
+     849                 :            :         size_t transport_header_size;
+     850                 :            : 
+     851                 :          0 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     852                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     853                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     854                 :            : 
+     855                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     856                 :          0 :         spdm_response->header.spdm_version = 0xFF;
+     857                 :          0 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     858                 :          0 :         spdm_response->header.param1 = 0;
+     859                 :          0 :         spdm_response->header.param2 = 0;
+     860                 :          0 :         spdm_response->ct_exponent = 0;
+     861                 :          0 :         spdm_response->flags =
+     862                 :            :             LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11;
+     863                 :            : 
+     864                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     865                 :            :                                               false, spdm_response_size,
+     866                 :            :                                               spdm_response,
+     867                 :            :                                               response_size, response);
+     868                 :            :     }
+     869                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     870                 :            : 
+     871                 :          0 :     case 0x1d:
+     872                 :            :     {
+     873                 :            :         static uint16_t error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
+     874                 :            : 
+     875                 :            :         spdm_error_response_t *spdm_response;
+     876                 :            :         size_t spdm_response_size;
+     877                 :            :         size_t transport_header_size;
+     878                 :            : 
+     879                 :          0 :         spdm_response_size = sizeof(spdm_error_response_t);
+     880                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     881                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     882                 :            : 
+     883         [ #  # ]:          0 :         if(error_code <= 0xff) {
+     884                 :          0 :             libspdm_zero_mem(spdm_response, spdm_response_size);
+     885                 :          0 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     886                 :          0 :             spdm_response->header.request_response_code = SPDM_ERROR;
+     887                 :          0 :             spdm_response->header.param1 = (uint8_t) error_code;
+     888                 :          0 :             spdm_response->header.param2 = 0;
+     889                 :            : 
+     890                 :          0 :             libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+     891                 :            :                                                    spdm_response_size, spdm_response,
+     892                 :            :                                                    response_size, response);
+     893                 :            :         }
+     894                 :            : 
+     895                 :          0 :         error_code++;
+     896         [ #  # ]:          0 :         if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
+     897                 :          0 :             error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
+     898                 :            :         }
+     899         [ #  # ]:          0 :         if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) { /*skip some reserved error codes (0d to 3e)*/
+     900                 :          0 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
+     901                 :            :         }
+     902         [ #  # ]:          0 :         if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) { /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
+     903                 :          0 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
+     904                 :            :         }
+     905                 :            :     }
+     906                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     907                 :            : 
+     908                 :          0 :     case 0x1F:
+     909                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+     910                 :            : 
+     911                 :          1 :     case 0x20: {
+     912                 :            :         spdm_capabilities_response_t *spdm_response;
+     913                 :            :         size_t spdm_response_size;
+     914                 :            :         size_t transport_header_size;
+     915                 :            : 
+     916                 :          1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     917                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     918                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     919                 :            : 
+     920                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     921                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     922                 :          1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     923                 :          1 :         spdm_response->header.param1 = 0;
+     924                 :          1 :         spdm_response->header.param2 = 0;
+     925                 :          1 :         spdm_response->ct_exponent = 0;
+     926                 :          1 :         spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11;
+     927                 :            : 
+     928                 :          1 :         spdm_response_size = sizeof(spdm_capabilities_response_t) -
+     929                 :            :                              sizeof(spdm_response->data_transfer_size) -
+     930                 :            :                              sizeof(spdm_response->max_spdm_msg_size);
+     931                 :            : 
+     932                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+     933                 :            :                          sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
+     934                 :            :                          (uint8_t *)spdm_response, spdm_response_size);
+     935                 :          1 :         m_libspdm_local_buffer_size += spdm_response_size;
+     936                 :            : 
+     937                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     938                 :            :                                               false, spdm_response_size,
+     939                 :            :                                               spdm_response,
+     940                 :            :                                               response_size, response);
+     941                 :            :     }
+     942                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     943                 :            : 
+     944                 :          1 :     case 0x21: {
+     945                 :            :         spdm_capabilities_response_t *spdm_response;
+     946                 :            :         size_t spdm_response_size;
+     947                 :            :         size_t transport_header_size;
+     948                 :            : 
+     949                 :          1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     950                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     951                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     952                 :            : 
+     953                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     954                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     955                 :          1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     956                 :          1 :         spdm_response->header.param1 = 0;
+     957                 :          1 :         spdm_response->header.param2 = 0;
+     958                 :          1 :         spdm_response->ct_exponent = 0;
+     959                 :          1 :         spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_12;
+     960                 :          1 :         spdm_response->data_transfer_size = LIBSPDM_DATA_TRANSFER_SIZE;
+     961                 :          1 :         spdm_response->max_spdm_msg_size = LIBSPDM_MAX_SPDM_MSG_SIZE;
+     962                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     963                 :            :                                               false, spdm_response_size,
+     964                 :            :                                               spdm_response,
+     965                 :            :                                               response_size, response);
+     966                 :            :     }
+     967                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     968                 :          0 :     case 0x22: {
+     969                 :            :         spdm_capabilities_response_t *spdm_response;
+     970                 :            :         size_t spdm_response_size;
+     971                 :            :         size_t transport_header_size;
+     972                 :            : 
+     973                 :          0 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     974                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     975                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     976                 :            : 
+     977                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     978                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     979                 :          0 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+     980                 :          0 :         spdm_response->header.param1 = 0;
+     981                 :          0 :         spdm_response->header.param2 = 0;
+     982                 :          0 :         spdm_response->ct_exponent = 0;
+     983                 :          0 :         spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+     984                 :          0 :         spdm_response->data_transfer_size = LIBSPDM_DATA_TRANSFER_SIZE;
+     985                 :          0 :         spdm_response->max_spdm_msg_size = LIBSPDM_MAX_SPDM_MSG_SIZE;
+     986                 :            : 
+     987                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     988                 :            :                                               false, spdm_response_size,
+     989                 :            :                                               spdm_response,
+     990                 :            :                                               response_size, response);
+     991                 :            :     }
+     992                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     993                 :          1 :     case 0x23: {
+     994                 :            :         spdm_capabilities_response_t *spdm_response;
+     995                 :            :         size_t spdm_response_size;
+     996                 :            :         size_t transport_header_size;
+     997                 :            : 
+     998                 :          1 :         spdm_response_size = sizeof(spdm_capabilities_response_t);
+     999                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1000                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1001                 :            : 
+    1002                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+    1003                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+    1004                 :          1 :         spdm_response->header.request_response_code = SPDM_CAPABILITIES;
+    1005                 :          1 :         spdm_response->header.param1 = 0;
+    1006                 :          1 :         spdm_response->header.param2 = 0;
+    1007                 :          1 :         spdm_response->ct_exponent = 0;
+    1008                 :          1 :         spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_13;
+    1009                 :          1 :         spdm_response->data_transfer_size = LIBSPDM_DATA_TRANSFER_SIZE;
+    1010                 :          1 :         spdm_response->max_spdm_msg_size = LIBSPDM_MAX_SPDM_MSG_SIZE;
+    1011                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1012                 :            :                                               false, spdm_response_size,
+    1013                 :            :                                               spdm_response,
+    1014                 :            :                                               response_size, response);
+    1015                 :            :     }
+    1016                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1017                 :          0 :     default:
+    1018                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+    1019                 :            :     }
+    1020                 :            : }
+    1021                 :            : 
+    1022                 :            : /*
+    1023                 :            :  * static void libspdm_test_requester_get_capabilities_case1(void **state)
+    1024                 :            :  * {
+    1025                 :            :  * }
+    1026                 :            :  */
+    1027                 :            : 
+    1028                 :          1 : static void libspdm_test_requester_get_capabilities_case2(void **state)
+    1029                 :            : {
+    1030                 :            :     libspdm_return_t status;
+    1031                 :            :     libspdm_test_context_t *spdm_test_context;
+    1032                 :            :     libspdm_context_t *spdm_context;
+    1033                 :            : 
+    1034                 :          1 :     spdm_test_context = *state;
+    1035                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1036                 :          1 :     spdm_test_context->case_id = 0x2;
+    1037                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1038                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1039                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1040                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1041                 :            :     spdm_context->transcript.message_m.buffer_size =
+    1042                 :            :         spdm_context->transcript.message_m.max_buffer_size;
+    1043                 :            : #endif
+    1044                 :            : 
+    1045                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1046                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+    1047                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1048                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1049                 :          1 :     assert_int_equal(spdm_context->connection_info.capability.ct_exponent, 0);
+    1050                 :          1 :     assert_int_equal(spdm_context->connection_info.capability.flags,
+    1051                 :            :                      LIBSPDM_DEFAULT_CAPABILITY_FLAG);
+    1052                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1053                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+    1054                 :            : #endif
+    1055                 :          1 : }
+    1056                 :            : 
+    1057                 :            : /*
+    1058                 :            :  * static void libspdm_test_requester_get_capabilities_case3(void **state)
+    1059                 :            :  * {
+    1060                 :            :  * }
+    1061                 :            :  */
+    1062                 :            : 
+    1063                 :            : /*
+    1064                 :            :  * static void libspdm_test_requester_get_capabilities_case4(void **state)
+    1065                 :            :  * {
+    1066                 :            :  * }
+    1067                 :            :  */
+    1068                 :            : 
+    1069                 :            : /*
+    1070                 :            :  * static void libspdm_test_requester_get_capabilities_case5(void **state)
+    1071                 :            :  * {
+    1072                 :            :  * }
+    1073                 :            :  */
+    1074                 :            : 
+    1075                 :          1 : static void libspdm_test_requester_get_capabilities_case6(void **state)
+    1076                 :            : {
+    1077                 :            :     libspdm_return_t status;
+    1078                 :            :     libspdm_test_context_t *spdm_test_context;
+    1079                 :            :     libspdm_context_t *spdm_context;
+    1080                 :            : 
+    1081                 :          1 :     spdm_test_context = *state;
+    1082                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1083                 :          1 :     spdm_test_context->case_id = 0x6;
+    1084                 :          1 :     spdm_context->retry_times = 3;
+    1085                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1086                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1087                 :          1 :     spdm_context->connection_info.connection_state =
+    1088                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1089                 :            : 
+    1090                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1091                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+    1092                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1093                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1094                 :          1 :     assert_int_equal(spdm_context->connection_info.capability.ct_exponent, 0);
+    1095                 :          1 :     assert_int_equal(spdm_context->connection_info.capability.flags,
+    1096                 :            :                      LIBSPDM_DEFAULT_CAPABILITY_FLAG);
+    1097                 :          1 : }
+    1098                 :            : 
+    1099                 :            : /*
+    1100                 :            :  * static void libspdm_test_requester_get_capabilities_case7(void **state)
+    1101                 :            :  * {
+    1102                 :            :  * }
+    1103                 :            :  */
+    1104                 :            : 
+    1105                 :            : /*
+    1106                 :            :  * static void libspdm_test_requester_get_capabilities_case8(void **state)
+    1107                 :            :  * {
+    1108                 :            :  * }
+    1109                 :            :  */
+    1110                 :            : 
+    1111                 :            : /*
+    1112                 :            :  * static void libspdm_test_requester_get_capabilities_case9(void **state)
+    1113                 :            :  * {
+    1114                 :            :  * }
+    1115                 :            :  */
+    1116                 :            : 
+    1117                 :          1 : static void libspdm_test_requester_get_capabilities_case10(void **state)
+    1118                 :            : {
+    1119                 :            :     libspdm_return_t status;
+    1120                 :            :     libspdm_test_context_t *spdm_test_context;
+    1121                 :            :     libspdm_context_t *spdm_context;
+    1122                 :            : 
+    1123                 :          1 :     spdm_test_context = *state;
+    1124                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1125                 :          1 :     spdm_test_context->case_id = 0xa;
+    1126                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1127                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1128                 :          1 :     spdm_context->connection_info.connection_state =
+    1129                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1130                 :            : 
+    1131                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1132                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+    1133                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1134                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1135                 :          1 :     assert_int_equal(spdm_context->connection_info.capability.ct_exponent, 0);
+    1136                 :          1 :     assert_int_equal(spdm_context->connection_info.capability.flags,
+    1137                 :            :                      (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CACHE_CAP |
+    1138                 :            :                       SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP |
+    1139                 :            :                       SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP |
+    1140                 :            :                       SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG |
+    1141                 :            :                       SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_FRESH_CAP));
+    1142                 :          1 : }
+    1143                 :            : 
+    1144                 :          1 : static void libspdm_test_requester_get_capabilities_case11(void **state)
+    1145                 :            : {
+    1146                 :            :     libspdm_return_t status;
+    1147                 :            :     libspdm_test_context_t *spdm_test_context;
+    1148                 :            :     libspdm_context_t *spdm_context;
+    1149                 :            : 
+    1150                 :          1 :     spdm_test_context = *state;
+    1151                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1152                 :          1 :     spdm_test_context->case_id = 0xb;
+    1153                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1154                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1155                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1156                 :            : 
+    1157                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1158                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+    1159                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1160                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1161                 :          1 :     assert_int_equal(spdm_context->connection_info.capability.ct_exponent, 0);
+    1162                 :          1 :     assert_int_equal(
+    1163                 :            :         spdm_context->connection_info.capability.flags,
+    1164                 :            :         !(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CACHE_CAP |
+    1165                 :            :           SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP |
+    1166                 :            :           SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP |
+    1167                 :            :           SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG |
+    1168                 :            :           SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_FRESH_CAP));
+    1169                 :          1 : }
+    1170                 :            : 
+    1171                 :          1 : static void libspdm_test_requester_get_capabilities_case12(void **state)
+    1172                 :            : {
+    1173                 :            :     libspdm_return_t status;
+    1174                 :            :     libspdm_test_context_t *spdm_test_context;
+    1175                 :            :     libspdm_context_t *spdm_context;
+    1176                 :            : 
+    1177                 :          1 :     spdm_test_context = *state;
+    1178                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1179                 :          1 :     spdm_test_context->case_id = 0xc;
+    1180                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1181                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1182                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1183                 :            : 
+    1184                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1185                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
+    1186                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1187                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1188                 :          1 :     assert_int_equal(spdm_context->connection_info.capability.ct_exponent, 0);
+    1189                 :          1 :     assert_int_equal(spdm_context->connection_info.capability.flags,
+    1190                 :            :                      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG |
+    1191                 :            :                      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_FRESH_CAP);
+    1192                 :          1 : }
+    1193                 :            : 
+    1194                 :            : /*
+    1195                 :            :  * static void libspdm_test_requester_get_capabilities_case13(void **state)
+    1196                 :            :  * {
+    1197                 :            :  * }
+    1198                 :            :  */
+    1199                 :            : 
+    1200                 :            : /*
+    1201                 :            :  * static void libspdm_test_requester_get_capabilities_case14(void **state)
+    1202                 :            :  * {
+    1203                 :            :  * }
+    1204                 :            :  */
+    1205                 :            : 
+    1206                 :            : /*
+    1207                 :            :  * static void libspdm_test_requester_get_capabilities_case15(void **state)
+    1208                 :            :  * {
+    1209                 :            :  * }
+    1210                 :            :  */
+    1211                 :            : 
+    1212                 :          1 : static void libspdm_test_requester_get_capabilities_case16(void **state)
+    1213                 :            : {
+    1214                 :            :     libspdm_return_t status;
+    1215                 :            :     libspdm_test_context_t *spdm_test_context;
+    1216                 :            :     libspdm_context_t *spdm_context;
+    1217                 :            : 
+    1218                 :          1 :     spdm_test_context = *state;
+    1219                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1220                 :          1 :     spdm_test_context->case_id = 0x10;
+    1221                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1222                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1223                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1224                 :            : 
+    1225                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1226                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
+    1227                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1228                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1229                 :          1 :     assert_int_equal(spdm_context->connection_info.capability.ct_exponent, 0);
+    1230                 :          1 :     assert_int_equal(spdm_context->connection_info.capability.flags,
+    1231                 :            :                      LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11);
+    1232                 :          1 : }
+    1233                 :            : 
+    1234                 :            : /*
+    1235                 :            :  * static void libspdm_test_requester_get_capabilities_case17(void **state)
+    1236                 :            :  * {
+    1237                 :            :  * }
+    1238                 :            :  */
+    1239                 :            : 
+    1240                 :            : /*
+    1241                 :            :  * static void libspdm_test_requester_get_capabilities_case18(void **state)
+    1242                 :            :  * {
+    1243                 :            :  * }
+    1244                 :            :  */
+    1245                 :            : 
+    1246                 :            : /*
+    1247                 :            :  * static void libspdm_test_requester_get_capabilities_case19(void **state)
+    1248                 :            :  * {
+    1249                 :            :  * }
+    1250                 :            :  */
+    1251                 :            : 
+    1252                 :            : /*
+    1253                 :            :  * static void libspdm_test_requester_get_capabilities_case20(void **state)
+    1254                 :            :  * {
+    1255                 :            :  * }
+    1256                 :            :  */
+    1257                 :            : 
+    1258                 :            : /*
+    1259                 :            :  * static void libspdm_test_requester_get_capabilities_case21(void **state)
+    1260                 :            :  * {
+    1261                 :            :  * }
+    1262                 :            :  */
+    1263                 :            : 
+    1264                 :            : /*
+    1265                 :            :  * static void libspdm_test_requester_get_capabilities_case22(void **state)
+    1266                 :            :  * {
+    1267                 :            :  * }
+    1268                 :            :  */
+    1269                 :            : 
+    1270                 :            : /*
+    1271                 :            :  * static void libspdm_test_requester_get_capabilities_case23(void **state)
+    1272                 :            :  * {
+    1273                 :            :  * }
+    1274                 :            :  */
+    1275                 :            : 
+    1276                 :            : /*
+    1277                 :            :  * static void libspdm_test_requester_get_capabilities_case24(void **state)
+    1278                 :            :  * {
+    1279                 :            :  * }
+    1280                 :            :  */
+    1281                 :            : 
+    1282                 :            : /*
+    1283                 :            :  * static void libspdm_test_requester_get_capabilities_case25(void **state)
+    1284                 :            :  * {
+    1285                 :            :  * }
+    1286                 :            :  */
+    1287                 :            : 
+    1288                 :            : /*
+    1289                 :            :  * static void libspdm_test_requester_get_capabilities_case26(void **state)
+    1290                 :            :  * {
+    1291                 :            :  * }
+    1292                 :            :  */
+    1293                 :            : 
+    1294                 :            : /*
+    1295                 :            :  * static void libspdm_test_requester_get_capabilities_case27(void **state)
+    1296                 :            :  * {
+    1297                 :            :  * }
+    1298                 :            :  */
+    1299                 :            : 
+    1300                 :            : /*
+    1301                 :            :  * static void libspdm_test_requester_get_capabilities_case28(void **state)
+    1302                 :            :  * {
+    1303                 :            :  * }
+    1304                 :            :  */
+    1305                 :            : 
+    1306                 :            : /*
+    1307                 :            :  * static void libspdm_test_requester_get_capabilities_case29(void **state)
+    1308                 :            :  * {
+    1309                 :            :  * }
+    1310                 :            :  */
+    1311                 :            : 
+    1312                 :            : /*
+    1313                 :            :  * static void libspdm_test_requester_get_capabilities_case30(void **state)
+    1314                 :            :  * {
+    1315                 :            :  * }
+    1316                 :            :  */
+    1317                 :            : 
+    1318                 :            : /*
+    1319                 :            :  * static void libspdm_test_requester_get_capabilities_case31(void **state)
+    1320                 :            :  * {
+    1321                 :            :  * }
+    1322                 :            :  */
+    1323                 :            : 
+    1324                 :          1 : static void libspdm_test_requester_get_capabilities_case32(void **state)
+    1325                 :            : {
+    1326                 :            :     libspdm_return_t status;
+    1327                 :            :     libspdm_test_context_t *spdm_test_context;
+    1328                 :            :     libspdm_context_t *spdm_context;
+    1329                 :            :     size_t arbitrary_size;
+    1330                 :            : 
+    1331                 :          1 :     spdm_test_context = *state;
+    1332                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1333                 :          1 :     spdm_test_context->case_id = 0x20;
+    1334                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1335                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1336                 :          1 :     spdm_context->connection_info.connection_state =
+    1337                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1338                 :            : 
+    1339                 :            :     /*filling A with arbitrary data*/
+    1340                 :          1 :     arbitrary_size = 10;
+    1341                 :          1 :     libspdm_set_mem(spdm_context->transcript.message_a.buffer, arbitrary_size, (uint8_t) 0xFF);
+    1342                 :          1 :     spdm_context->transcript.message_a.buffer_size = arbitrary_size;
+    1343                 :            : 
+    1344                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1345                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
+    1346                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1347                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1348                 :          1 :     assert_int_equal(spdm_context->connection_info.capability.ct_exponent, 0);
+    1349                 :          1 :     assert_int_equal(spdm_context->connection_info.capability.flags,
+    1350                 :            :                      LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11);
+    1351                 :          1 :     libspdm_dump_hex(spdm_context->transcript.message_a.buffer,
+    1352                 :            :                      spdm_context->transcript.message_a.buffer_size);
+    1353                 :          1 :     assert_int_equal(spdm_context->transcript.message_a.buffer_size,
+    1354                 :            :                      arbitrary_size + m_libspdm_local_buffer_size);
+    1355                 :          1 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer (0x%zx):\n",
+    1356                 :            :                    m_libspdm_local_buffer_size));
+    1357                 :          1 :     libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    1358                 :          1 :     assert_memory_equal(spdm_context->transcript.message_a.buffer + arbitrary_size,
+    1359                 :            :                         m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    1360                 :          1 : }
+    1361                 :            : 
+    1362                 :          1 : static void libspdm_test_requester_get_capabilities_case33(void **state)
+    1363                 :            : {
+    1364                 :            :     libspdm_return_t status;
+    1365                 :            :     libspdm_test_context_t *spdm_test_context;
+    1366                 :            :     libspdm_context_t *spdm_context;
+    1367                 :            : 
+    1368                 :          1 :     spdm_test_context = *state;
+    1369                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1370                 :          1 :     spdm_test_context->case_id = 0x21;
+    1371                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    1372                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1373                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1374                 :            : 
+    1375                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1376                 :          1 :     spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_12;
+    1377                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1378                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1379                 :          1 :     assert_int_equal(spdm_context->connection_info.capability.max_spdm_msg_size,
+    1380                 :            :                      LIBSPDM_MAX_SPDM_MSG_SIZE);
+    1381                 :          1 :     assert_int_equal(spdm_context->connection_info.capability.data_transfer_size,
+    1382                 :            :                      LIBSPDM_DATA_TRANSFER_SIZE);
+    1383                 :          1 :     assert_int_equal(spdm_context->connection_info.capability.ct_exponent, 0);
+    1384                 :          1 :     assert_int_equal(spdm_context->connection_info.capability.flags,
+    1385                 :            :                      LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_12);
+    1386                 :          1 : }
+    1387                 :            : 
+    1388                 :            : 
+    1389                 :            : /*
+    1390                 :            :  * static void libspdm_test_requester_get_capabilities_case34(void **state)
+    1391                 :            :  * {
+    1392                 :            :  * }
+    1393                 :            :  */
+    1394                 :            : 
+    1395                 :          1 : static void libspdm_test_requester_get_capabilities_case35(void **state)
+    1396                 :            : {
+    1397                 :            :     libspdm_return_t status;
+    1398                 :            :     libspdm_test_context_t *spdm_test_context;
+    1399                 :            :     libspdm_context_t *spdm_context;
+    1400                 :            : 
+    1401                 :          1 :     spdm_test_context = *state;
+    1402                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1403                 :          1 :     spdm_test_context->case_id = 0x23;
+    1404                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+    1405                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1406                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1407                 :          1 :     spdm_context->local_context.capability.ct_exponent = 0;
+    1408                 :            : 
+    1409                 :          1 :     status = libspdm_get_capabilities(spdm_context);
+    1410                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1411                 :          1 :     assert_int_equal(spdm_context->connection_info.capability.max_spdm_msg_size,
+    1412                 :            :                      LIBSPDM_MAX_SPDM_MSG_SIZE);
+    1413                 :          1 :     assert_int_equal(spdm_context->connection_info.capability.data_transfer_size,
+    1414                 :            :                      LIBSPDM_DATA_TRANSFER_SIZE);
+    1415                 :          1 :     assert_int_equal(spdm_context->connection_info.capability.ct_exponent, 0);
+    1416                 :          1 :     assert_int_equal(spdm_context->connection_info.capability.flags,
+    1417                 :            :                      LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_13);
+    1418                 :          1 : }
+    1419                 :            : 
+    1420                 :            : static libspdm_test_context_t m_libspdm_requester_get_capabilities_test_context = {
+    1421                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+    1422                 :            :     true,
+    1423                 :            :     libspdm_requester_get_capabilities_test_send_message,
+    1424                 :            :     libspdm_requester_get_capabilities_test_receive_message,
+    1425                 :            : };
+    1426                 :            : 
+    1427                 :          1 : int libspdm_requester_get_capabilities_test_main(void)
+    1428                 :            : {
+    1429                 :          1 :     const struct CMUnitTest m_spdm_requester_get_capabilities_tests[] = {
+    1430                 :            :         /* cmocka_unit_test(libspdm_test_requester_get_capabilities_case1), */
+    1431                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_case2),
+    1432                 :            :         /* cmocka_unit_test(libspdm_test_requester_get_capabilities_case3),
+    1433                 :            :          * cmocka_unit_test(libspdm_test_requester_get_capabilities_case4),
+    1434                 :            :          * cmocka_unit_test(libspdm_test_requester_get_capabilities_case5), */
+    1435                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_case6),
+    1436                 :            :         /* cmocka_unit_test(libspdm_test_requester_get_capabilities_case7),
+    1437                 :            :          * cmocka_unit_test(libspdm_test_requester_get_capabilities_case8),
+    1438                 :            :          * cmocka_unit_test(libspdm_test_requester_get_capabilities_case9), */
+    1439                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_case10),
+    1440                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_case11),
+    1441                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_case12),
+    1442                 :            :         /* cmocka_unit_test(libspdm_test_requester_get_capabilities_case13),
+    1443                 :            :          * cmocka_unit_test(libspdm_test_requester_get_capabilities_case14),
+    1444                 :            :          * cmocka_unit_test(libspdm_test_requester_get_capabilities_case15), */
+    1445                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_case16),
+    1446                 :            :         /* cmocka_unit_test(libspdm_test_requester_get_capabilities_case17),
+    1447                 :            :          * cmocka_unit_test(libspdm_test_requester_get_capabilities_case18),
+    1448                 :            :          * cmocka_unit_test(libspdm_test_requester_get_capabilities_case19),
+    1449                 :            :          * cmocka_unit_test(libspdm_test_requester_get_capabilities_case20),
+    1450                 :            :          * cmocka_unit_test(libspdm_test_requester_get_capabilities_case21),
+    1451                 :            :          * cmocka_unit_test(libspdm_test_requester_get_capabilities_case22),
+    1452                 :            :          * cmocka_unit_test(libspdm_test_requester_get_capabilities_case23),
+    1453                 :            :          * cmocka_unit_test(libspdm_test_requester_get_capabilities_case24),
+    1454                 :            :          * cmocka_unit_test(libspdm_test_requester_get_capabilities_case25),
+    1455                 :            :          * cmocka_unit_test(libspdm_test_requester_get_capabilities_case26),
+    1456                 :            :          * cmocka_unit_test(libspdm_test_requester_get_capabilities_case27),
+    1457                 :            :          * cmocka_unit_test(libspdm_test_requester_get_capabilities_case28),
+    1458                 :            :          * cmocka_unit_test(libspdm_test_requester_get_capabilities_case29),
+    1459                 :            :          * cmocka_unit_test(libspdm_test_requester_get_capabilities_case30),
+    1460                 :            :          * cmocka_unit_test(libspdm_test_requester_get_capabilities_case31), */
+    1461                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_case32),
+    1462                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_case33),
+    1463                 :            :         /* cmocka_unit_test(libspdm_test_requester_get_capabilities_case34), */
+    1464                 :            :         cmocka_unit_test(libspdm_test_requester_get_capabilities_case35),
+    1465                 :            :     };
+    1466                 :            : 
+    1467                 :          1 :     libspdm_setup_test_context(
+    1468                 :            :         &m_libspdm_requester_get_capabilities_test_context);
+    1469                 :            : 
+    1470                 :          1 :     return cmocka_run_group_tests(m_spdm_requester_get_capabilities_tests,
+    1471                 :            :                                   libspdm_unit_test_group_setup,
+    1472                 :            :                                   libspdm_unit_test_group_teardown);
+    1473                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/get_certificate.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_requester/get_certificate.c.func-sort-c.html new file mode 100644 index 00000000000..c1597941ac3 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/get_certificate.c.func-sort-c.html @@ -0,0 +1,217 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/get_certificate.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - get_certificate.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:1912203893.8 %
Date:2024-09-22 08:21:07Functions:3434100.0 %
Branches:24731977.4 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_get_certificate_test_main1
libspdm_test_requester_get_certificate_case11
libspdm_test_requester_get_certificate_case101
libspdm_test_requester_get_certificate_case111
libspdm_test_requester_get_certificate_case121
libspdm_test_requester_get_certificate_case131
libspdm_test_requester_get_certificate_case141
libspdm_test_requester_get_certificate_case151
libspdm_test_requester_get_certificate_case161
libspdm_test_requester_get_certificate_case171
libspdm_test_requester_get_certificate_case181
libspdm_test_requester_get_certificate_case191
libspdm_test_requester_get_certificate_case21
libspdm_test_requester_get_certificate_case201
libspdm_test_requester_get_certificate_case211
libspdm_test_requester_get_certificate_case221
libspdm_test_requester_get_certificate_case231
libspdm_test_requester_get_certificate_case241
libspdm_test_requester_get_certificate_case251
libspdm_test_requester_get_certificate_case261
libspdm_test_requester_get_certificate_case271
libspdm_test_requester_get_certificate_case281
libspdm_test_requester_get_certificate_case291
libspdm_test_requester_get_certificate_case31
libspdm_test_requester_get_certificate_case301
libspdm_test_requester_get_certificate_case41
libspdm_test_requester_get_certificate_case51
libspdm_test_requester_get_certificate_case61
libspdm_test_requester_get_certificate_case71
libspdm_test_requester_get_certificate_case81
libspdm_test_requester_get_certificate_case91
libspdm_libspdm_read_responder_public_certificate_chain_expiration2
libspdm_requester_get_certificate_test_receive_message1467
libspdm_requester_get_certificate_test_send_message1468
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/get_certificate.c.func.html b/coverage_log/unit_test/test_spdm_requester/get_certificate.c.func.html new file mode 100644 index 00000000000..8ea4740b0e8 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/get_certificate.c.func.html @@ -0,0 +1,217 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/get_certificate.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - get_certificate.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:1912203893.8 %
Date:2024-09-22 08:21:07Functions:3434100.0 %
Branches:24731977.4 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_libspdm_read_responder_public_certificate_chain_expiration2
libspdm_requester_get_certificate_test_main1
libspdm_requester_get_certificate_test_receive_message1467
libspdm_requester_get_certificate_test_send_message1468
libspdm_test_requester_get_certificate_case11
libspdm_test_requester_get_certificate_case101
libspdm_test_requester_get_certificate_case111
libspdm_test_requester_get_certificate_case121
libspdm_test_requester_get_certificate_case131
libspdm_test_requester_get_certificate_case141
libspdm_test_requester_get_certificate_case151
libspdm_test_requester_get_certificate_case161
libspdm_test_requester_get_certificate_case171
libspdm_test_requester_get_certificate_case181
libspdm_test_requester_get_certificate_case191
libspdm_test_requester_get_certificate_case21
libspdm_test_requester_get_certificate_case201
libspdm_test_requester_get_certificate_case211
libspdm_test_requester_get_certificate_case221
libspdm_test_requester_get_certificate_case231
libspdm_test_requester_get_certificate_case241
libspdm_test_requester_get_certificate_case251
libspdm_test_requester_get_certificate_case261
libspdm_test_requester_get_certificate_case271
libspdm_test_requester_get_certificate_case281
libspdm_test_requester_get_certificate_case291
libspdm_test_requester_get_certificate_case31
libspdm_test_requester_get_certificate_case301
libspdm_test_requester_get_certificate_case41
libspdm_test_requester_get_certificate_case51
libspdm_test_requester_get_certificate_case61
libspdm_test_requester_get_certificate_case71
libspdm_test_requester_get_certificate_case81
libspdm_test_requester_get_certificate_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/get_certificate.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/get_certificate.c.gcov.html new file mode 100644 index 00000000000..856fe5782ee --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/get_certificate.c.gcov.html @@ -0,0 +1,4524 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/get_certificate.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - get_certificate.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:1912203893.8 %
Date:2024-09-22 08:21:07Functions:3434100.0 %
Branches:24731977.4 %
+
+ + + + + + + + +

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

Function Name Sort by function nameHit count Sort by hit count
libspdm_clear_cached_csr1
libspdm_gen_req_info1
libspdm_requester_get_csr_test_main1
libspdm_test_requester_get_csr_case11
libspdm_test_requester_get_csr_case21
libspdm_test_requester_get_csr_case31
libspdm_test_requester_get_csr_case41
libspdm_test_requester_get_csr_case51
libspdm_test_requester_get_csr_case61
libspdm_test_requester_get_csr_case71
libspdm_read_requester_gen_csr5
libspdm_requester_get_csr_test_receive_message6
libspdm_requester_get_csr_test_send_message7
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/get_csr.c.func.html b/coverage_log/unit_test/test_spdm_requester/get_csr.c.func.html new file mode 100644 index 00000000000..fbac9b9ea40 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/get_csr.c.func.html @@ -0,0 +1,133 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/get_csr.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - get_csr.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:24125494.9 %
Date:2024-09-22 08:21:07Functions:1313100.0 %
Branches:142070.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_clear_cached_csr1
libspdm_gen_req_info1
libspdm_read_requester_gen_csr5
libspdm_requester_get_csr_test_main1
libspdm_requester_get_csr_test_receive_message6
libspdm_requester_get_csr_test_send_message7
libspdm_test_requester_get_csr_case11
libspdm_test_requester_get_csr_case21
libspdm_test_requester_get_csr_case31
libspdm_test_requester_get_csr_case41
libspdm_test_requester_get_csr_case51
libspdm_test_requester_get_csr_case61
libspdm_test_requester_get_csr_case71
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/get_csr.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/get_csr.c.gcov.html new file mode 100644 index 00000000000..250a368f098 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/get_csr.c.gcov.html @@ -0,0 +1,710 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/get_csr.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - get_csr.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:24125494.9 %
Date:2024-09-22 08:21:07Functions:1313100.0 %
Branches:142070.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_requester_lib.h"
+       9                 :            : #include "internal/libspdm_secured_message_lib.h"
+      10                 :            : 
+      11                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CSR_CAP
+      12                 :            : 
+      13                 :            : #define LIBSPDM_MAX_CSR_SIZE 0x1000
+      14                 :            : 
+      15                 :            : /*refer to https://github.com/Mbed-TLS/mbedtls/blob/3048c8c90654eb116a6b17c0d2d27c3ccbe6782c/programs/x509/cert_req.c#L119-L129*/
+      16                 :            : #define LIBSPDM_MAX_REQ_INFO_BUFFER_SIZE 4096
+      17                 :            : 
+      18                 :            : uint8_t csr_pointer[LIBSPDM_MAX_CSR_SIZE] = {0};
+      19                 :            : uint8_t *csr_data_pointer = csr_pointer;
+      20                 :            : size_t global_csr_len;
+      21                 :            : 
+      22                 :            : uint8_t m_csr_opaque_data[8] = "libspdm";
+      23                 :            : uint16_t m_csr_opaque_data_size = sizeof(m_csr_opaque_data);
+      24                 :            : 
+      25                 :            : /*ECC 256 req_info(include right req_info attribute)*/
+      26                 :            : uint8_t req_info_sequence[] = {0x30, 0x81, 0xBF,};
+      27                 :            : uint8_t req_info_version[] = {0x02, 0x01, 0x00,};
+      28                 :            : uint8_t req_info_subject[] = {
+      29                 :            :     0x30, 0x45, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x41, 0x55, 0x31,
+      30                 :            :     0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0C, 0x0A, 0x53, 0x6F, 0x6D, 0x65, 0x2D, 0x53,
+      31                 :            :     0x74, 0x61, 0x74, 0x65, 0x31, 0x21, 0x30, 0x1F, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C, 0x18, 0x49,
+      32                 :            :     0x6E, 0x74, 0x65, 0x72, 0x6E, 0x65, 0x74, 0x20, 0x57, 0x69, 0x64, 0x67, 0x69, 0x74, 0x73, 0x20,
+      33                 :            :     0x50, 0x74, 0x79, 0x20, 0x4C, 0x74, 0x64,
+      34                 :            : };
+      35                 :            : uint8_t req_info_right_attributes[] = {
+      36                 :            :     /*[0]: attributes*/
+      37                 :            :     0xA0, 0x18, 0x30, 0x16,
+      38                 :            :     /*OID*/
+      39                 :            :     0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09, 0x07,
+      40                 :            :     /*attributes*/
+      41                 :            :     0x31, 0x09, 0x0C, 0x07, 0x74, 0x65, 0x73, 0x74, 0x31, 0x32, 0x33
+      42                 :            : };
+      43                 :            : 
+      44                 :            : /*the unique attribute from right_req_info*/
+      45                 :            : char right_req_info_string[] = {0x74, 0x65, 0x73, 0x74, 0x31, 0x32, 0x33};
+      46                 :            : 
+      47                 :            : static uint8_t right_req_info[LIBSPDM_MAX_REQ_INFO_BUFFER_SIZE];
+      48                 :            : static uint16_t right_req_info_size;
+      49                 :            : 
+      50                 :            : /*gen right_req_info*/
+      51                 :          1 : void libspdm_gen_req_info() {
+      52                 :            :     uint8_t *req_info_p;
+      53                 :            :     void *req_info_pkinfo;
+      54                 :            :     size_t req_info_pkinfo_len;
+      55                 :            : 
+      56                 :          1 :     libspdm_zero_mem(right_req_info, sizeof(right_req_info));
+      57                 :            : 
+      58                 :          1 :     req_info_p = right_req_info;
+      59                 :          1 :     right_req_info_size = sizeof(right_req_info);
+      60                 :            : 
+      61                 :          1 :     libspdm_read_responder_public_key(m_libspdm_use_asym_algo,
+      62                 :            :                                       &req_info_pkinfo, &req_info_pkinfo_len);
+      63                 :            : 
+      64                 :            :     /*concat right_req_info*/
+      65                 :          1 :     libspdm_copy_mem(req_info_p, right_req_info_size, req_info_sequence, sizeof(req_info_sequence));
+      66                 :          1 :     req_info_p += sizeof(req_info_sequence);
+      67                 :          1 :     right_req_info_size -= sizeof(req_info_sequence);
+      68                 :            : 
+      69                 :          1 :     libspdm_copy_mem(req_info_p, right_req_info_size, req_info_version, sizeof(req_info_version));
+      70                 :          1 :     req_info_p += sizeof(req_info_version);
+      71                 :          1 :     right_req_info_size -= sizeof(req_info_version);
+      72                 :            : 
+      73                 :          1 :     libspdm_copy_mem(req_info_p, right_req_info_size, req_info_subject, sizeof(req_info_subject));
+      74                 :          1 :     req_info_p += sizeof(req_info_subject);
+      75                 :          1 :     right_req_info_size -= sizeof(req_info_subject);
+      76                 :            : 
+      77                 :          1 :     libspdm_copy_mem(req_info_p, right_req_info_size, req_info_pkinfo, req_info_pkinfo_len);
+      78                 :          1 :     req_info_p += req_info_pkinfo_len;
+      79                 :          1 :     right_req_info_size = (uint16_t)(right_req_info_size - req_info_pkinfo_len);
+      80                 :            : 
+      81                 :          1 :     libspdm_copy_mem(req_info_p, right_req_info_size,
+      82                 :            :                      req_info_right_attributes, sizeof(req_info_right_attributes));
+      83                 :          1 :     req_info_p += sizeof(req_info_right_attributes);
+      84                 :          1 :     right_req_info_size -= sizeof(req_info_right_attributes);
+      85                 :            : 
+      86                 :          1 :     right_req_info_size = sizeof(right_req_info) - right_req_info_size;
+      87                 :            : 
+      88                 :          1 :     free(req_info_pkinfo);
+      89                 :          1 : }
+      90                 :            : 
+      91                 :          5 : bool libspdm_read_requester_gen_csr(void **csr_data, size_t *csr_len)
+      92                 :            : {
+      93                 :            :     char *file;
+      94                 :            :     bool res;
+      95                 :            : 
+      96                 :          5 :     file = "test_csr/cached.csr";
+      97                 :          5 :     res = libspdm_read_input_file(file, csr_data, csr_len);
+      98         [ -  + ]:          5 :     if (!res) {
+      99                 :          0 :         return res;
+     100                 :            :     }
+     101                 :            : 
+     102                 :          5 :     return res;
+     103                 :            : }
+     104                 :            : 
+     105                 :            : /*ensure that cached.csr exists in test_csr at the beginning*/
+     106                 :          1 : void libspdm_clear_cached_csr()
+     107                 :            : {
+     108                 :          1 :     char *new_name = "test_csr/cached.csr";
+     109                 :          1 :     char *file_name = "test_csr/cached.staging";
+     110                 :            : 
+     111                 :          1 :     rename(file_name, new_name);
+     112                 :          1 : }
+     113                 :            : 
+     114                 :          7 : libspdm_return_t libspdm_requester_get_csr_test_send_message(
+     115                 :            :     void *spdm_context, size_t request_size, const void *request,
+     116                 :            :     uint64_t timeout)
+     117                 :            : {
+     118                 :            :     libspdm_test_context_t *spdm_test_context;
+     119                 :            : 
+     120                 :          7 :     spdm_test_context = libspdm_get_test_context();
+     121   [ +  +  +  +  :          7 :     switch (spdm_test_context->case_id) {
+             +  +  -  - ]
+     122                 :          1 :     case 0x1:
+     123                 :          1 :         return LIBSPDM_STATUS_SEND_FAIL;
+     124                 :          1 :     case 0x2:
+     125                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     126                 :          2 :     case 0x3:
+     127                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     128                 :          1 :     case 0x4: {
+     129                 :            :         const spdm_get_csr_request_t *spdm_request;
+     130                 :            :         uint16_t requester_info_length;
+     131                 :            :         uint16_t opaque_data_length;
+     132                 :            :         uint8_t *opaque_data;
+     133                 :            :         uint8_t *requester_info;
+     134                 :            : 
+     135                 :            :         /* Obtain the real spdm_request */
+     136                 :          1 :         spdm_request =
+     137                 :            :             (const spdm_get_csr_request_t *)((const uint8_t *)request +
+     138                 :            :                                              sizeof(libspdm_test_message_header_t));
+     139                 :            : 
+     140                 :          1 :         requester_info_length = spdm_request->requester_info_length;
+     141                 :          1 :         opaque_data_length = spdm_request->opaque_data_length;
+     142                 :            : 
+     143                 :          1 :         requester_info = (void*)((size_t)(spdm_request + 1));
+     144                 :          1 :         assert_memory_equal(requester_info, right_req_info, requester_info_length);
+     145                 :          1 :         opaque_data = (void *)(requester_info + requester_info_length);
+     146                 :          1 :         assert_memory_equal(opaque_data, m_csr_opaque_data, opaque_data_length);
+     147                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     148                 :            :     }
+     149                 :          1 :     case 0x5:
+     150                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     151                 :          1 :     case 0x6:
+     152                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     153                 :          0 :     case 0x7:
+     154                 :          0 :         assert_true(false);
+     155                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     156                 :          0 :     default:
+     157                 :          0 :         return LIBSPDM_STATUS_SEND_FAIL;
+     158                 :            :     }
+     159                 :            : }
+     160                 :            : 
+     161                 :          6 : libspdm_return_t libspdm_requester_get_csr_test_receive_message(
+     162                 :            :     void *spdm_context, size_t *response_size,
+     163                 :            :     void **response, uint64_t timeout)
+     164                 :            : {
+     165                 :            :     libspdm_test_context_t *spdm_test_context;
+     166                 :            :     libspdm_context_t *context;
+     167                 :            : 
+     168                 :          6 :     spdm_test_context = libspdm_get_test_context();
+     169   [ -  +  +  +  :          6 :     switch (spdm_test_context->case_id) {
+             +  +  -  - ]
+     170                 :          0 :     case 0x1:
+     171                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+     172                 :            : 
+     173                 :          1 :     case 0x2: {
+     174                 :            :         spdm_csr_response_t *spdm_response;
+     175                 :            :         size_t spdm_response_size;
+     176                 :            :         size_t transport_header_size;
+     177                 :            : 
+     178                 :          1 :         libspdm_read_requester_gen_csr((void *)&csr_data_pointer, &global_csr_len);
+     179                 :            : 
+     180                 :          1 :         spdm_response_size = sizeof(spdm_csr_response_t) + global_csr_len;
+     181                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     182                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     183                 :            : 
+     184                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     185                 :          1 :         spdm_response->header.request_response_code = SPDM_CSR;
+     186                 :          1 :         spdm_response->header.param1 = 0;
+     187                 :          1 :         spdm_response->header.param2 = 0;
+     188                 :          1 :         spdm_response->csr_length = (uint16_t)global_csr_len;
+     189                 :          1 :         spdm_response->reserved = 0;
+     190                 :            : 
+     191                 :          1 :         libspdm_copy_mem(spdm_response + 1, global_csr_len, csr_data_pointer, global_csr_len);
+     192                 :            : 
+     193                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     194                 :            :                                               false, spdm_response_size,
+     195                 :            :                                               spdm_response, response_size,
+     196                 :            :                                               response);
+     197                 :            :     }
+     198                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     199                 :            : 
+     200                 :          2 :     case 0x3: {
+     201                 :            :         spdm_csr_response_t *spdm_response;
+     202                 :            :         size_t spdm_response_size;
+     203                 :            :         size_t transport_header_size;
+     204                 :            : 
+     205                 :          2 :         libspdm_read_requester_gen_csr((void *)&csr_data_pointer, &global_csr_len);
+     206                 :            : 
+     207                 :          2 :         spdm_response_size = sizeof(spdm_csr_response_t) + global_csr_len;
+     208                 :          2 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     209                 :          2 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     210                 :            : 
+     211                 :          2 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     212                 :          2 :         spdm_response->header.param2 = 0;
+     213                 :          2 :         spdm_response->csr_length = (uint16_t)global_csr_len;
+     214                 :          2 :         spdm_response->reserved = 0;
+     215                 :            : 
+     216                 :          2 :         context = spdm_context;
+     217                 :            : 
+     218         [ +  + ]:          2 :         if (context->connection_info.capability.flags &
+     219                 :            :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_INSTALL_RESET_CAP) {
+     220                 :          1 :             spdm_response->header.request_response_code = SPDM_ERROR;
+     221                 :          1 :             spdm_response->header.param1 = SPDM_ERROR_CODE_RESET_REQUIRED;
+     222                 :            :         } else {
+     223                 :          1 :             spdm_response->header.request_response_code = SPDM_CSR;
+     224                 :          1 :             spdm_response->header.param1 = 0;
+     225                 :            : 
+     226                 :          1 :             libspdm_copy_mem(spdm_response + 1, global_csr_len, csr_data_pointer, global_csr_len);
+     227                 :            :         }
+     228                 :            : 
+     229                 :          2 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     230                 :            :                                               false, spdm_response_size,
+     231                 :            :                                               spdm_response, response_size,
+     232                 :            :                                               response);
+     233                 :            :     }
+     234                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     235                 :          1 :     case 0x4: {
+     236                 :            :         spdm_csr_response_t *spdm_response;
+     237                 :            :         size_t spdm_response_size;
+     238                 :            :         size_t transport_header_size;
+     239                 :            : 
+     240                 :          1 :         libspdm_read_requester_gen_csr((void *)&csr_data_pointer, &global_csr_len);
+     241                 :          1 :         spdm_response_size = sizeof(spdm_csr_response_t) + global_csr_len;
+     242                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     243                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     244                 :            : 
+     245                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     246                 :          1 :         spdm_response->header.request_response_code = SPDM_CSR;
+     247                 :          1 :         spdm_response->header.param1 = 0;
+     248                 :          1 :         spdm_response->header.param2 = 0;
+     249                 :          1 :         spdm_response->csr_length = (uint16_t)global_csr_len;
+     250                 :          1 :         spdm_response->reserved = 0;
+     251                 :          1 :         libspdm_copy_mem(spdm_response + 1, global_csr_len, csr_data_pointer, global_csr_len);
+     252                 :            : 
+     253                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     254                 :            :                                               false, spdm_response_size,
+     255                 :            :                                               spdm_response, response_size,
+     256                 :            :                                               response);
+     257                 :            :     }
+     258                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     259                 :          1 :     case 0x5: {
+     260                 :            :         spdm_csr_response_t *spdm_response;
+     261                 :            :         size_t spdm_response_size;
+     262                 :            :         size_t transport_header_size;
+     263                 :            : 
+     264                 :          1 :         libspdm_read_requester_gen_csr((void *)&csr_data_pointer, &global_csr_len);
+     265                 :            : 
+     266                 :          1 :         spdm_response_size = sizeof(spdm_csr_response_t) + global_csr_len;
+     267                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     268                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     269                 :            : 
+     270                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+     271                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     272                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_RESET_REQUIRED;
+     273                 :          1 :         spdm_response->header.param2 = 1;
+     274                 :          1 :         spdm_response->csr_length = (uint16_t)global_csr_len;
+     275                 :          1 :         spdm_response->reserved = 0;
+     276                 :            : 
+     277                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     278                 :            :                                               false, spdm_response_size,
+     279                 :            :                                               spdm_response, response_size,
+     280                 :            :                                               response);
+     281                 :            :     }
+     282                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     283                 :          1 :     case 0x6: {
+     284                 :            :         spdm_error_response_t *spdm_response;
+     285                 :            :         size_t spdm_response_size;
+     286                 :            :         size_t transport_header_size;
+     287                 :            : 
+     288                 :          1 :         spdm_response_size = sizeof(spdm_error_response_t);
+     289                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     290                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     291                 :            : 
+     292                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+     293                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     294                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_RESET_REQUIRED;
+     295                 :          1 :         spdm_response->header.param2 = 1;
+     296                 :            : 
+     297                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     298                 :            :                                               false, spdm_response_size,
+     299                 :            :                                               spdm_response, response_size,
+     300                 :            :                                               response);
+     301                 :            :     }
+     302                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     303                 :          0 :     case 0x7:
+     304                 :          0 :         assert_true(false);
+     305                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     306                 :          0 :     default:
+     307                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+     308                 :            :     }
+     309                 :            : }
+     310                 :            : 
+     311                 :            : /**
+     312                 :            :  * Test 1: message could not be sent
+     313                 :            :  * Expected Behavior: get a RETURN_DEVICE_ERROR return code
+     314                 :            :  **/
+     315                 :          1 : void libspdm_test_requester_get_csr_case1(void **state)
+     316                 :            : {
+     317                 :            :     libspdm_return_t status;
+     318                 :            :     libspdm_test_context_t *spdm_test_context;
+     319                 :            :     libspdm_context_t *spdm_context;
+     320                 :            : 
+     321                 :          1 :     uint8_t csr_form_get[LIBSPDM_MAX_CSR_SIZE] = {0};
+     322                 :            :     size_t csr_len;
+     323                 :            : 
+     324                 :          1 :     csr_len = LIBSPDM_MAX_CSR_SIZE;
+     325                 :            : 
+     326                 :          1 :     spdm_test_context = *state;
+     327                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     328                 :          1 :     spdm_test_context->case_id = 0x1;
+     329                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     330                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     331                 :            : 
+     332                 :          1 :     spdm_context->connection_info.connection_state =
+     333                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     334                 :          1 :     spdm_context->connection_info.capability.flags |=
+     335                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CSR_CAP;
+     336                 :            : 
+     337                 :            :     /*init req_info*/
+     338                 :          1 :     libspdm_gen_req_info();
+     339                 :            : 
+     340                 :          1 :     status = libspdm_get_csr(spdm_context, NULL, NULL, 0, NULL, 0, (void *)&csr_form_get,
+     341                 :            :                              &csr_len);
+     342                 :            : 
+     343                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SEND_FAIL);
+     344                 :          1 : }
+     345                 :            : 
+     346                 :            : /**
+     347                 :            :  * Test 2: Successful response to get csr
+     348                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code
+     349                 :            :  **/
+     350                 :          1 : void libspdm_test_requester_get_csr_case2(void **state)
+     351                 :            : {
+     352                 :            :     libspdm_return_t status;
+     353                 :            :     libspdm_test_context_t *spdm_test_context;
+     354                 :            :     libspdm_context_t *spdm_context;
+     355                 :            : 
+     356                 :          1 :     uint8_t csr_form_get[LIBSPDM_MAX_CSR_SIZE] = {0};
+     357                 :            :     size_t csr_len;
+     358                 :            : 
+     359                 :          1 :     csr_len = LIBSPDM_MAX_CSR_SIZE;
+     360                 :            : 
+     361                 :          1 :     spdm_test_context = *state;
+     362                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     363                 :          1 :     spdm_test_context->case_id = 0x2;
+     364                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     365                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     366                 :            : 
+     367                 :          1 :     spdm_context->connection_info.connection_state =
+     368                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     369                 :          1 :     spdm_context->connection_info.capability.flags |=
+     370                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CSR_CAP;
+     371                 :            : 
+     372                 :          1 :     status = libspdm_get_csr(spdm_context, NULL, NULL, 0, NULL, 0, (void *)&csr_form_get,
+     373                 :            :                              &csr_len);
+     374                 :            : 
+     375                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     376                 :          1 :     assert_int_equal(csr_len, global_csr_len);
+     377                 :          1 :     assert_memory_equal(csr_form_get, csr_data_pointer, global_csr_len);
+     378                 :          1 : }
+     379                 :            : 
+     380                 :            : /**
+     381                 :            :  * Test 3: Successful response to get csr,
+     382                 :            :  * with a reset required
+     383                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code
+     384                 :            :  **/
+     385                 :          1 : void libspdm_test_requester_get_csr_case3(void **state)
+     386                 :            : {
+     387                 :            :     libspdm_return_t status;
+     388                 :            :     libspdm_test_context_t *spdm_test_context;
+     389                 :            :     libspdm_context_t *spdm_context;
+     390                 :            : 
+     391                 :          1 :     uint8_t csr_form_get[LIBSPDM_MAX_CSR_SIZE] = {0};
+     392                 :            :     size_t csr_len;
+     393                 :            : 
+     394                 :          1 :     csr_len = LIBSPDM_MAX_CSR_SIZE;
+     395                 :            : 
+     396                 :          1 :     spdm_test_context = *state;
+     397                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     398                 :          1 :     spdm_test_context->case_id = 0x3;
+     399                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     400                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     401                 :            : 
+     402                 :          1 :     spdm_context->connection_info.connection_state =
+     403                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     404                 :          1 :     spdm_context->connection_info.capability.flags |=
+     405                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CSR_CAP |
+     406                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_INSTALL_RESET_CAP;
+     407                 :            : 
+     408                 :          1 :     status = libspdm_get_csr(spdm_context, NULL, NULL, 0, NULL, 0, (void *)&csr_form_get,
+     409                 :            :                              &csr_len);
+     410                 :            : 
+     411                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_RESET_REQUIRED_PEER);
+     412                 :            : 
+     413                 :            :     /* Let's reset the responder and send the request again */
+     414                 :          1 :     spdm_context->connection_info.capability.flags &=
+     415                 :            :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_INSTALL_RESET_CAP;
+     416                 :            : 
+     417                 :          1 :     status = libspdm_get_csr(spdm_context, NULL, NULL, 0, NULL, 0, (void *)&csr_form_get,
+     418                 :            :                              &csr_len);
+     419                 :            : 
+     420                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     421                 :          1 :     assert_int_equal(csr_len, global_csr_len);
+     422                 :          1 :     assert_memory_equal(csr_form_get, csr_data_pointer, global_csr_len);
+     423                 :          1 : }
+     424                 :            : 
+     425                 :            : /**
+     426                 :            :  * Test 4: Send correct req_info and opaque_data
+     427                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code and determine if req_info and opaque_data are correct
+     428                 :            :  **/
+     429                 :          1 : void libspdm_test_requester_get_csr_case4(void **state)
+     430                 :            : {
+     431                 :            :     libspdm_return_t status;
+     432                 :            :     libspdm_test_context_t *spdm_test_context;
+     433                 :            :     libspdm_context_t *spdm_context;
+     434                 :            : 
+     435                 :          1 :     uint8_t csr_form_get[LIBSPDM_MAX_CSR_SIZE] = {0};
+     436                 :            :     size_t csr_len;
+     437                 :            : 
+     438                 :          1 :     csr_len = LIBSPDM_MAX_CSR_SIZE;
+     439                 :            : 
+     440                 :          1 :     spdm_test_context = *state;
+     441                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     442                 :          1 :     spdm_test_context->case_id = 0x4;
+     443                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     444                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     445                 :            : 
+     446                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     447                 :          1 :     spdm_context->local_context.capability.flags = 0;
+     448                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CSR_CAP;
+     449                 :            : 
+     450                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     451                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     452                 :            : 
+     453                 :          1 :     spdm_context->connection_info.algorithm.other_params_support =
+     454                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_0;
+     455                 :            : 
+     456                 :          1 :     status = libspdm_get_csr(spdm_context, NULL,
+     457                 :            :                              right_req_info, right_req_info_size,
+     458                 :            :                              m_csr_opaque_data, m_csr_opaque_data_size,
+     459                 :            :                              (void *)&csr_form_get, &csr_len);
+     460                 :            : 
+     461                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     462                 :          1 :     assert_int_equal(csr_len, global_csr_len);
+     463                 :          1 :     assert_memory_equal(csr_form_get, csr_data_pointer, global_csr_len);
+     464                 :          1 : }
+     465                 :            : 
+     466                 :            : /**
+     467                 :            :  * Test 5: Successful response to libspdm_get_csr_ex,
+     468                 :            :  * with a reset required
+     469                 :            :  * Expected Behavior: get a LIBSPDM_STATUS_RESET_REQUIRED_PEER return code and available csr_tracking_tag
+     470                 :            :  **/
+     471                 :          1 : void libspdm_test_requester_get_csr_case5(void **state)
+     472                 :            : {
+     473                 :            :     libspdm_test_context_t *spdm_test_context;
+     474                 :            :     libspdm_context_t *spdm_context;
+     475                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CSR_CAP_EX
+     476                 :            :     libspdm_return_t status;
+     477                 :          1 :     uint8_t csr_form_get[LIBSPDM_MAX_CSR_SIZE] = {0};
+     478                 :            :     size_t csr_len;
+     479                 :            :     uint8_t reset_csr_tracking_tag;
+     480                 :            : 
+     481                 :          1 :     csr_len = LIBSPDM_MAX_CSR_SIZE;
+     482                 :          1 :     reset_csr_tracking_tag = 0;
+     483                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CSR_CAP_EX*/
+     484                 :          1 :     spdm_test_context = *state;
+     485                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     486                 :          1 :     spdm_test_context->case_id = 0x5;
+     487                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+     488                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     489                 :            : 
+     490                 :          1 :     spdm_context->connection_info.connection_state =
+     491                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     492                 :          1 :     spdm_context->connection_info.capability.flags |=
+     493                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CSR_CAP |
+     494                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_INSTALL_RESET_CAP;
+     495                 :            : 
+     496                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CSR_CAP_EX
+     497                 :          1 :     status = libspdm_get_csr_ex(spdm_context, NULL, NULL, 0, NULL, 0, (void *)&csr_form_get,
+     498                 :            :                                 &csr_len, 0, 0, &reset_csr_tracking_tag);
+     499                 :            : 
+     500                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_RESET_REQUIRED_PEER);
+     501                 :          1 :     assert_int_equal(reset_csr_tracking_tag, 1);
+     502                 :            : #endif /*LIBSPDM_ENABLE_CAPABILITY_CSR_CAP_EX*/
+     503                 :          1 : }
+     504                 :            : 
+     505                 :            : /**
+     506                 :            :  * Test 6: A 1.3 Responder returns ResetRequired when its CERT_INSTALL_RESET_CAP is 0.
+     507                 :            :  * Expected Behavior: libspdm returns LIBSPDM_STATUS_ERROR_PEER since Responder should
+     508                 :            :  *                    not produce that error message unless CERT_INSTALL_RESET_CAP is 1.
+     509                 :            :  **/
+     510                 :          1 : void libspdm_test_requester_get_csr_case6(void **state)
+     511                 :            : {
+     512                 :            :     libspdm_return_t status;
+     513                 :            :     libspdm_test_context_t *spdm_test_context;
+     514                 :            :     libspdm_context_t *spdm_context;
+     515                 :            : 
+     516                 :          1 :     uint8_t csr_form_get[LIBSPDM_MAX_CSR_SIZE] = {0};
+     517                 :            :     size_t csr_len;
+     518                 :            : 
+     519                 :          1 :     csr_len = LIBSPDM_MAX_CSR_SIZE;
+     520                 :            : 
+     521                 :          1 :     spdm_test_context = *state;
+     522                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     523                 :          1 :     spdm_test_context->case_id = 0x6;
+     524                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+     525                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     526                 :            : 
+     527                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     528                 :          1 :     spdm_context->local_context.capability.flags = 0;
+     529                 :            :     /* Don't set CERT_INSTALL_RESET_CAP. */
+     530                 :          1 :     spdm_context->connection_info.capability.flags = SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CSR_CAP;
+     531                 :            : 
+     532                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     533                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     534                 :            : 
+     535                 :          1 :     spdm_context->connection_info.algorithm.other_params_support =
+     536                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_0;
+     537                 :            : 
+     538                 :          1 :     status = libspdm_get_csr(spdm_context, NULL,
+     539                 :            :                              right_req_info, right_req_info_size,
+     540                 :            :                              m_csr_opaque_data, m_csr_opaque_data_size,
+     541                 :            :                              (void *)&csr_form_get, &csr_len);
+     542                 :            : 
+     543                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_ERROR_PEER);
+     544                 :          1 : }
+     545                 :            : 
+     546                 :            : /**
+     547                 :            :  * Test 7: Illegal combination of MULTI_KEY_CONN_RSP = true and CSRCertModel = 0.
+     548                 :            :  * Expected Behavior: returns LIBSPDM_STATUS_INVALID_PARAMETER.
+     549                 :            :  **/
+     550                 :          1 : void libspdm_test_requester_get_csr_case7(void **state)
+     551                 :            : {
+     552                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CSR_CAP_EX
+     553                 :            :     libspdm_return_t status;
+     554                 :            :     libspdm_test_context_t *spdm_test_context;
+     555                 :            :     libspdm_context_t *spdm_context;
+     556                 :            : 
+     557                 :          1 :     uint8_t csr_form_get[LIBSPDM_MAX_CSR_SIZE] = {0};
+     558                 :            :     size_t csr_len;
+     559                 :            :     uint8_t tracking_tag;
+     560                 :            : 
+     561                 :          1 :     csr_len = LIBSPDM_MAX_CSR_SIZE;
+     562                 :            : 
+     563                 :          1 :     spdm_test_context = *state;
+     564                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     565                 :          1 :     spdm_test_context->case_id = 0x7;
+     566                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+     567                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     568                 :            : 
+     569                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     570                 :          1 :     spdm_context->local_context.capability.flags = 0;
+     571                 :          1 :     spdm_context->connection_info.capability.flags = SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CSR_CAP;
+     572                 :          1 :     spdm_context->connection_info.multi_key_conn_rsp = true;
+     573                 :            : 
+     574                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     575                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     576                 :            : 
+     577                 :          1 :     spdm_context->connection_info.algorithm.other_params_support =
+     578                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_0;
+     579                 :            : 
+     580                 :          1 :     status = libspdm_get_csr_ex(spdm_context, NULL, NULL, 0, NULL, 0, (void *)&csr_form_get,
+     581                 :            :                                 &csr_len, SPDM_CERTIFICATE_INFO_CERT_MODEL_NONE, 1, &tracking_tag);
+     582                 :            : 
+     583                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_PARAMETER);
+     584                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CSR_CAP_EX */
+     585                 :          1 : }
+     586                 :            : 
+     587                 :            : libspdm_test_context_t m_libspdm_requester_get_csr_test_context = {
+     588                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+     589                 :            :     true,
+     590                 :            :     libspdm_requester_get_csr_test_send_message,
+     591                 :            :     libspdm_requester_get_csr_test_receive_message,
+     592                 :            : };
+     593                 :            : 
+     594                 :          1 : int libspdm_requester_get_csr_test_main(void)
+     595                 :            : {
+     596                 :          1 :     const struct CMUnitTest spdm_requester_get_csr_tests[] = {
+     597                 :            :         /* SendRequest failed*/
+     598                 :            :         cmocka_unit_test(libspdm_test_requester_get_csr_case1),
+     599                 :            :         /* Successful response to get csr*/
+     600                 :            :         cmocka_unit_test(libspdm_test_requester_get_csr_case2),
+     601                 :            :         /* Successful response to get csr with a reset required */
+     602                 :            :         cmocka_unit_test(libspdm_test_requester_get_csr_case3),
+     603                 :            :         /* Send req_info and opaque_data Successful response to get csr */
+     604                 :            :         cmocka_unit_test(libspdm_test_requester_get_csr_case4),
+     605                 :            :         /* Successful response to libspdm_get_csr_ex with a reset required */
+     606                 :            :         cmocka_unit_test(libspdm_test_requester_get_csr_case5),
+     607                 :            :         /* Illegal ResetRequired error response. */
+     608                 :            :         cmocka_unit_test(libspdm_test_requester_get_csr_case6),
+     609                 :            :         cmocka_unit_test(libspdm_test_requester_get_csr_case7),
+     610                 :            :     };
+     611                 :            : 
+     612                 :          1 :     libspdm_setup_test_context(
+     613                 :            :         &m_libspdm_requester_get_csr_test_context);
+     614                 :            : 
+     615                 :            :     /*ensure that cached.csr exists in test_csr at the beginning*/
+     616                 :          1 :     libspdm_clear_cached_csr();
+     617                 :            : 
+     618                 :          1 :     return cmocka_run_group_tests(spdm_requester_get_csr_tests,
+     619                 :            :                                   libspdm_unit_test_group_setup,
+     620                 :            :                                   libspdm_unit_test_group_teardown);
+     621                 :            : }
+     622                 :            : 
+     623                 :            : #endif /*LIBSPDM_ENABLE_CAPABILITY_CSR_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/get_digests.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_requester/get_digests.c.func-sort-c.html new file mode 100644 index 00000000000..02893e00a12 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/get_digests.c.func-sort-c.html @@ -0,0 +1,209 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/get_digests.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - get_digests.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:56790162.9 %
Date:2024-09-22 08:21:07Functions:3232100.0 %
Branches:2810028.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_get_digests_test_main1
libspdm_test_requester_get_digests_case11
libspdm_test_requester_get_digests_case101
libspdm_test_requester_get_digests_case111
libspdm_test_requester_get_digests_case121
libspdm_test_requester_get_digests_case131
libspdm_test_requester_get_digests_case141
libspdm_test_requester_get_digests_case151
libspdm_test_requester_get_digests_case161
libspdm_test_requester_get_digests_case171
libspdm_test_requester_get_digests_case181
libspdm_test_requester_get_digests_case191
libspdm_test_requester_get_digests_case21
libspdm_test_requester_get_digests_case201
libspdm_test_requester_get_digests_case211
libspdm_test_requester_get_digests_case221
libspdm_test_requester_get_digests_case231
libspdm_test_requester_get_digests_case241
libspdm_test_requester_get_digests_case251
libspdm_test_requester_get_digests_case261
libspdm_test_requester_get_digests_case271
libspdm_test_requester_get_digests_case281
libspdm_test_requester_get_digests_case291
libspdm_test_requester_get_digests_case31
libspdm_test_requester_get_digests_case41
libspdm_test_requester_get_digests_case51
libspdm_test_requester_get_digests_case61
libspdm_test_requester_get_digests_case71
libspdm_test_requester_get_digests_case81
libspdm_test_requester_get_digests_case91
libspdm_requester_get_digests_test_receive_message13
libspdm_requester_get_digests_test_send_message13
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/get_digests.c.func.html b/coverage_log/unit_test/test_spdm_requester/get_digests.c.func.html new file mode 100644 index 00000000000..29c55b2e341 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/get_digests.c.func.html @@ -0,0 +1,209 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/get_digests.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - get_digests.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:56790162.9 %
Date:2024-09-22 08:21:07Functions:3232100.0 %
Branches:2810028.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_get_digests_test_main1
libspdm_requester_get_digests_test_receive_message13
libspdm_requester_get_digests_test_send_message13
libspdm_test_requester_get_digests_case11
libspdm_test_requester_get_digests_case101
libspdm_test_requester_get_digests_case111
libspdm_test_requester_get_digests_case121
libspdm_test_requester_get_digests_case131
libspdm_test_requester_get_digests_case141
libspdm_test_requester_get_digests_case151
libspdm_test_requester_get_digests_case161
libspdm_test_requester_get_digests_case171
libspdm_test_requester_get_digests_case181
libspdm_test_requester_get_digests_case191
libspdm_test_requester_get_digests_case21
libspdm_test_requester_get_digests_case201
libspdm_test_requester_get_digests_case211
libspdm_test_requester_get_digests_case221
libspdm_test_requester_get_digests_case231
libspdm_test_requester_get_digests_case241
libspdm_test_requester_get_digests_case251
libspdm_test_requester_get_digests_case261
libspdm_test_requester_get_digests_case271
libspdm_test_requester_get_digests_case281
libspdm_test_requester_get_digests_case291
libspdm_test_requester_get_digests_case31
libspdm_test_requester_get_digests_case41
libspdm_test_requester_get_digests_case51
libspdm_test_requester_get_digests_case61
libspdm_test_requester_get_digests_case71
libspdm_test_requester_get_digests_case81
libspdm_test_requester_get_digests_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/get_digests.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/get_digests.c.gcov.html new file mode 100644 index 00000000000..485255d3bc6 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/get_digests.c.gcov.html @@ -0,0 +1,2121 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/get_digests.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - get_digests.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:56790162.9 %
Date:2024-09-22 08:21:07Functions:3232100.0 %
Branches:2810028.0 %
+
+ + + + + + + + +

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

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_get_event_types_test_main1
libspdm_test_requester_get_event_types_case11
receive_message1
send_message1
set_standard_state1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/get_event_types.c.func.html b/coverage_log/unit_test/test_spdm_requester/get_event_types.c.func.html new file mode 100644 index 00000000000..e2a790d0583 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/get_event_types.c.func.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/get_event_types.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - get_event_types.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:747697.4 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:3650.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_get_event_types_test_main1
libspdm_test_requester_get_event_types_case11
receive_message1
send_message1
set_standard_state1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/get_event_types.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/get_event_types.c.gcov.html new file mode 100644 index 00000000000..6531833c2a6 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/get_event_types.c.gcov.html @@ -0,0 +1,289 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/get_event_types.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - get_event_types.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:747697.4 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:3650.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2024 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_requester_lib.h"
+       9                 :            : #include "internal/libspdm_secured_message_lib.h"
+      10                 :            : 
+      11                 :            : #if LIBSPDM_EVENT_RECIPIENT_SUPPORT
+      12                 :            : 
+      13                 :            : static uint8_t m_supported_event_groups_list[0x1000];
+      14                 :            : static uint8_t m_spdm_request_buffer[0x1000];
+      15                 :            : 
+      16                 :            : static const uint32_t m_session_id = 0xffffffff;
+      17                 :            : 
+      18                 :          1 : static void set_standard_state(libspdm_context_t *spdm_context, uint32_t *session_id)
+      19                 :            : {
+      20                 :            :     libspdm_session_info_t *session_info;
+      21                 :            : 
+      22                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+      23                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+      24                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+      25                 :            : 
+      26                 :          1 :     spdm_context->connection_info.capability.flags |=
+      27                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EVENT_CAP;
+      28                 :          1 :     spdm_context->connection_info.capability.flags |=
+      29                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+      30                 :          1 :     spdm_context->connection_info.capability.flags |=
+      31                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+      32                 :          1 :     spdm_context->connection_info.capability.flags |=
+      33                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+      34                 :            : 
+      35                 :          1 :     spdm_context->local_context.capability.flags |=
+      36                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+      37                 :          1 :     spdm_context->local_context.capability.flags |=
+      38                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+      39                 :          1 :     spdm_context->local_context.capability.flags |=
+      40                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+      41                 :            : 
+      42                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+      43                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+      44                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+      45                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+      46                 :            : 
+      47                 :          1 :     *session_id = m_session_id;
+      48                 :          1 :     session_info = &spdm_context->session_info[0];
+      49                 :          1 :     libspdm_session_info_init(spdm_context, session_info, *session_id, true);
+      50                 :          1 :     libspdm_secured_message_set_session_state(
+      51                 :            :         session_info->secured_message_context, LIBSPDM_SESSION_STATE_ESTABLISHED);
+      52                 :          1 : }
+      53                 :            : 
+      54                 :          1 : static libspdm_return_t send_message(
+      55                 :            :     void *spdm_context, size_t request_size, const void *request, uint64_t timeout)
+      56                 :            : {
+      57                 :            :     libspdm_return_t status;
+      58                 :            :     uint32_t session_id;
+      59                 :            :     uint32_t *message_session_id;
+      60                 :            :     spdm_get_supported_event_types_request_t *spdm_message;
+      61                 :            :     bool is_app_message;
+      62                 :            :     void *spdm_request_buffer;
+      63                 :            :     size_t spdm_request_size;
+      64                 :            :     libspdm_session_info_t *session_info;
+      65                 :            :     uint8_t request_buffer[0x1000];
+      66                 :            : 
+      67                 :            :     /* Workaround request being const. */
+      68                 :          1 :     libspdm_copy_mem(request_buffer, sizeof(request_buffer), request, request_size);
+      69                 :            : 
+      70                 :          1 :     session_id = m_session_id;
+      71                 :          1 :     session_info = libspdm_get_session_info_via_session_id(spdm_context, session_id);
+      72         [ -  + ]:          1 :     LIBSPDM_ASSERT(session_info != NULL);
+      73                 :            : 
+      74                 :          1 :     ((libspdm_secured_message_context_t *)(session_info->secured_message_context))->
+      75                 :          1 :     application_secret.request_data_sequence_number--;
+      76                 :            : 
+      77                 :          1 :     spdm_request_buffer = m_spdm_request_buffer;
+      78                 :          1 :     spdm_request_size = sizeof(m_spdm_request_buffer);
+      79                 :            : 
+      80                 :          1 :     status = libspdm_transport_test_decode_message(spdm_context, &message_session_id,
+      81                 :            :                                                    &is_app_message, true,
+      82                 :            :                                                    request_size, request_buffer,
+      83                 :            :                                                    &spdm_request_size, &spdm_request_buffer);
+      84                 :            : 
+      85                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+      86                 :          1 :     assert_int_equal(sizeof(spdm_get_supported_event_types_request_t), spdm_request_size);
+      87                 :            : 
+      88                 :          1 :     spdm_message = spdm_request_buffer;
+      89                 :            : 
+      90                 :          1 :     assert_int_equal(spdm_message->header.spdm_version, SPDM_MESSAGE_VERSION_13);
+      91                 :          1 :     assert_int_equal(spdm_message->header.request_response_code, SPDM_GET_SUPPORTED_EVENT_TYPES);
+      92                 :          1 :     assert_int_equal(spdm_message->header.param1, 0);
+      93                 :          1 :     assert_int_equal(spdm_message->header.param2, 0);
+      94                 :            : 
+      95                 :          1 :     return LIBSPDM_STATUS_SUCCESS;
+      96                 :            : }
+      97                 :            : 
+      98                 :          1 : static libspdm_return_t receive_message(
+      99                 :            :     void *spdm_context, size_t *response_size, void **response, uint64_t timeout)
+     100                 :            : {
+     101                 :            :     spdm_supported_event_types_response_t *spdm_response;
+     102                 :            :     size_t spdm_response_size;
+     103                 :            :     size_t transport_header_size;
+     104                 :            :     uint32_t session_id;
+     105                 :            :     libspdm_session_info_t *session_info;
+     106                 :            :     uint8_t *scratch_buffer;
+     107                 :            :     size_t scratch_buffer_size;
+     108                 :            :     uint8_t event_group_total_bytes;
+     109                 :            :     libspdm_test_context_t *spdm_test_context;
+     110                 :            : 
+     111                 :          1 :     spdm_test_context = libspdm_get_test_context();
+     112         [ +  - ]:          1 :     switch (spdm_test_context->case_id) {
+     113                 :          1 :     case 1: {
+     114                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     115                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     116                 :            : 
+     117                 :          1 :         session_id = m_session_id;
+     118                 :            : 
+     119                 :          1 :         session_info = libspdm_get_session_info_via_session_id(spdm_context, session_id);
+     120         [ -  + ]:          1 :         LIBSPDM_ASSERT((session_info != NULL));
+     121                 :            : 
+     122                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+     123                 :          1 :         spdm_response->header.request_response_code = SPDM_SUPPORTED_EVENT_TYPES;
+     124                 :          1 :         spdm_response->header.param1 = 1;
+     125                 :          1 :         spdm_response->header.param2 = 0;
+     126                 :            : 
+     127                 :          1 :         generate_dmtf_event_group(spdm_response + 1, &event_group_total_bytes, 0,
+     128                 :            :                                   true, true, true, true);
+     129                 :          1 :         spdm_response->supported_event_groups_list_len = event_group_total_bytes;
+     130                 :            : 
+     131                 :          1 :         spdm_response_size = sizeof(spdm_supported_event_types_response_t) +
+     132                 :            :                              event_group_total_bytes;
+     133                 :            : 
+     134                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+     135                 :            :          * transport_message is always in sender buffer. */
+     136                 :          1 :         libspdm_get_scratch_buffer(spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+     137                 :          1 :         libspdm_copy_mem(scratch_buffer + transport_header_size,
+     138                 :            :                          scratch_buffer_size - transport_header_size,
+     139                 :            :                          spdm_response, spdm_response_size);
+     140                 :            : 
+     141                 :          1 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+     142                 :            : 
+     143                 :          1 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+     144                 :            :                                               false, false, spdm_response_size,
+     145                 :            :                                               spdm_response, response_size, response);
+     146                 :            : 
+     147                 :            :         /* Workaround: Use single context to encode message and then decode message. */
+     148                 :          1 :         ((libspdm_secured_message_context_t *)(session_info->secured_message_context))->
+     149                 :          1 :         application_secret.response_data_sequence_number--;
+     150                 :            :     }
+     151                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     152                 :          0 :     default:
+     153                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+     154                 :            :     }
+     155                 :            : }
+     156                 :            : 
+     157                 :            : /**
+     158                 :            :  * Test 1: Successful response to get supported event types.
+     159                 :            :  * Expected Behavior: Returns LIBSPDM_STATUS_SUCCESS with the expected values.
+     160                 :            :  **/
+     161                 :          1 : static void libspdm_test_requester_get_event_types_case1(void **state)
+     162                 :            : {
+     163                 :            :     libspdm_return_t status;
+     164                 :            :     libspdm_test_context_t *spdm_test_context;
+     165                 :            :     libspdm_context_t *spdm_context;
+     166                 :            :     uint32_t session_id;
+     167                 :            :     uint8_t event_group_count;
+     168                 :          1 :     uint32_t supported_event_groups_list_len = sizeof(m_supported_event_groups_list);
+     169                 :            : 
+     170                 :          1 :     spdm_test_context = *state;
+     171                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     172                 :          1 :     spdm_test_context->case_id = 1;
+     173                 :            : 
+     174                 :          1 :     set_standard_state(spdm_context, &session_id);
+     175                 :            : 
+     176                 :          1 :     status = libspdm_get_event_types(spdm_context, session_id, &event_group_count,
+     177                 :            :                                      &supported_event_groups_list_len,
+     178                 :            :                                      (void *)&m_supported_event_groups_list);
+     179                 :            : 
+     180                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     181                 :          1 :     assert_int_equal(event_group_count, 1);
+     182                 :          1 : }
+     183                 :            : 
+     184                 :            : static libspdm_test_context_t m_test_context = {
+     185                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+     186                 :            :     true,
+     187                 :            :     send_message,
+     188                 :            :     receive_message,
+     189                 :            : };
+     190                 :            : 
+     191                 :          1 : int libspdm_requester_get_event_types_test_main(void)
+     192                 :            : {
+     193                 :          1 :     const struct CMUnitTest spdm_requester_get_event_types_tests[] = {
+     194                 :            :         cmocka_unit_test(libspdm_test_requester_get_event_types_case1)
+     195                 :            :     };
+     196                 :            : 
+     197                 :          1 :     libspdm_setup_test_context(&m_test_context);
+     198                 :            : 
+     199                 :          1 :     return cmocka_run_group_tests(spdm_requester_get_event_types_tests,
+     200                 :            :                                   libspdm_unit_test_group_setup,
+     201                 :            :                                   libspdm_unit_test_group_teardown);
+     202                 :            : }
+     203                 :            : 
+     204                 :            : #endif /* LIBSPDM_EVENT_RECIPIENT_SUPPORT */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/get_key_pair_info.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_requester/get_key_pair_info.c.func-sort-c.html new file mode 100644 index 00000000000..de66df68b2e --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/get_key_pair_info.c.func-sort-c.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/get_key_pair_info.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - get_key_pair_info.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:6228621.7 %
Date:2024-09-22 08:21:07Functions:4580.0 %
Branches:2540.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_test_requester_get_key_pair_info_case30
libspdm_requester_get_key_pair_info_test_main1
libspdm_requester_get_key_pair_info_test_receive_message1
libspdm_requester_get_key_pair_info_test_send_message1
libspdm_test_requester_get_key_pair_info_case11
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/get_key_pair_info.c.func.html b/coverage_log/unit_test/test_spdm_requester/get_key_pair_info.c.func.html new file mode 100644 index 00000000000..b5b6bd3ec8e --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/get_key_pair_info.c.func.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/get_key_pair_info.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - get_key_pair_info.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:6228621.7 %
Date:2024-09-22 08:21:07Functions:4580.0 %
Branches:2540.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_get_key_pair_info_test_main1
libspdm_requester_get_key_pair_info_test_receive_message1
libspdm_requester_get_key_pair_info_test_send_message1
libspdm_test_requester_get_key_pair_info_case11
libspdm_test_requester_get_key_pair_info_case30
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/get_key_pair_info.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/get_key_pair_info.c.gcov.html new file mode 100644 index 00000000000..b69868750d2 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/get_key_pair_info.c.gcov.html @@ -0,0 +1,687 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/get_key_pair_info.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - get_key_pair_info.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:6228621.7 %
Date:2024-09-22 08:21:07Functions:4580.0 %
Branches:2540.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2024 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_requester_lib.h"
+       9                 :            : #include "internal/libspdm_secured_message_lib.h"
+      10                 :            : 
+      11                 :            : #if LIBSPDM_ENABLE_CAPABILITY_GET_KEY_PAIR_INFO_CAP
+      12                 :            : 
+      13                 :            : uint8_t m_response_total_key_pairs;
+      14                 :            : uint8_t m_response_key_pair_id;
+      15                 :            : uint16_t m_response_capabilities;
+      16                 :            : uint16_t m_response_key_usage_capabilities;
+      17                 :            : uint16_t m_response_current_key_usage;
+      18                 :            : uint32_t m_response_asym_algo_capabilities;
+      19                 :            : uint32_t m_response_current_asym_algo;
+      20                 :            : uint8_t m_response_assoc_cert_slot_mask;
+      21                 :            : 
+      22                 :          1 : libspdm_return_t libspdm_requester_get_key_pair_info_test_send_message(
+      23                 :            :     void *spdm_context, size_t request_size, const void *request,
+      24                 :            :     uint64_t timeout)
+      25                 :            : {
+      26                 :            :     libspdm_test_context_t *spdm_test_context;
+      27                 :            : 
+      28                 :          1 :     spdm_test_context = libspdm_get_test_context();
+      29         [ +  - ]:          1 :     switch (spdm_test_context->case_id) {
+      30                 :          1 :     case 0x1:
+      31                 :            :     case 0x2:
+      32                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      33                 :          0 :     default:
+      34                 :          0 :         return LIBSPDM_STATUS_SEND_FAIL;
+      35                 :            :     }
+      36                 :            : }
+      37                 :            : 
+      38                 :          1 : libspdm_return_t libspdm_requester_get_key_pair_info_test_receive_message(
+      39                 :            :     void *spdm_context, size_t *response_size,
+      40                 :            :     void **response, uint64_t timeout)
+      41                 :            : {
+      42                 :            :     libspdm_test_context_t *spdm_test_context;
+      43                 :            : 
+      44                 :          1 :     spdm_test_context = libspdm_get_test_context();
+      45      [ +  -  - ]:          1 :     switch (spdm_test_context->case_id) {
+      46                 :          1 :     case 0x1: {
+      47                 :            :         spdm_key_pair_info_response_t *spdm_response;
+      48                 :            :         size_t spdm_response_size;
+      49                 :            :         size_t transport_header_size;
+      50                 :            : 
+      51                 :            :         uint8_t total_key_pairs;
+      52                 :            :         uint8_t key_pair_id;
+      53                 :            :         uint16_t public_key_info_len;
+      54                 :            :         uint16_t capabilities;
+      55                 :            :         uint16_t key_usage_capabilities;
+      56                 :            :         uint16_t current_key_usage;
+      57                 :            :         uint32_t asym_algo_capabilities;
+      58                 :            :         uint32_t current_asym_algo;
+      59                 :            :         uint8_t assoc_cert_slot_mask;
+      60                 :            : 
+      61                 :          1 :         uint8_t public_key_info_rsa2048[] = {0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7,
+      62                 :            :                                              0x0D, 0x01, 0x01, 0x01, 0x05, 0x00};
+      63                 :            : 
+      64                 :          1 :         key_pair_id = 1;
+      65                 :          1 :         total_key_pairs = 1;
+      66                 :          1 :         public_key_info_len = (uint16_t)sizeof(public_key_info_rsa2048);
+      67                 :            : 
+      68                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+      69                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+      70                 :          1 :         spdm_response_size = sizeof(spdm_key_pair_info_response_t) + public_key_info_len;
+      71                 :            : 
+      72                 :          1 :         capabilities = SPDM_KEY_PAIR_CAP_GEN_KEY_CAP;
+      73                 :          1 :         key_usage_capabilities = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+      74                 :          1 :         current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+      75                 :          1 :         asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
+      76                 :          1 :         current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
+      77                 :            : 
+      78                 :            :         /*association with slot 1*/
+      79                 :          1 :         assoc_cert_slot_mask = 0x02;
+      80                 :            : 
+      81                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+      82                 :          1 :         spdm_response->header.request_response_code = SPDM_KEY_PAIR_INFO;
+      83                 :          1 :         spdm_response->header.param1 = 0;
+      84                 :          1 :         spdm_response->header.param2 = 0;
+      85                 :          1 :         spdm_response->total_key_pairs = total_key_pairs;
+      86                 :          1 :         spdm_response->key_pair_id = key_pair_id;
+      87                 :          1 :         spdm_response->capabilities = capabilities;
+      88                 :          1 :         spdm_response->key_usage_capabilities = key_usage_capabilities;
+      89                 :          1 :         spdm_response->current_key_usage = current_key_usage;
+      90                 :          1 :         spdm_response->asym_algo_capabilities = asym_algo_capabilities;
+      91                 :          1 :         spdm_response->current_asym_algo = current_asym_algo;
+      92                 :          1 :         spdm_response->public_key_info_len = public_key_info_len;
+      93                 :          1 :         spdm_response->assoc_cert_slot_mask = assoc_cert_slot_mask;
+      94                 :            : 
+      95                 :          1 :         libspdm_copy_mem((void*)(spdm_response + 1), public_key_info_len,
+      96                 :            :                          public_key_info_rsa2048, public_key_info_len);
+      97                 :            : 
+      98                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+      99                 :            :                                               false, spdm_response_size,
+     100                 :            :                                               spdm_response, response_size,
+     101                 :            :                                               response);
+     102                 :            :     }
+     103                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     104                 :            : 
+     105                 :          0 :     case 0x2: {
+     106                 :            :         spdm_key_pair_info_response_t *spdm_response;
+     107                 :            :         size_t spdm_response_size;
+     108                 :            :         size_t transport_header_size;
+     109                 :            : 
+     110                 :            :         uint16_t public_key_info_len;
+     111                 :          0 :         uint8_t public_key_info_rsa2048[] = {0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7,
+     112                 :            :                                              0x0D, 0x01, 0x01, 0x01, 0x05, 0x00};
+     113                 :            : 
+     114                 :          0 :         public_key_info_len = (uint16_t)sizeof(public_key_info_rsa2048);
+     115                 :            : 
+     116                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     117                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     118                 :          0 :         spdm_response_size = sizeof(spdm_key_pair_info_response_t) + public_key_info_len;
+     119                 :            : 
+     120                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+     121                 :          0 :         spdm_response->header.request_response_code = SPDM_KEY_PAIR_INFO;
+     122                 :          0 :         spdm_response->header.param1 = 0;
+     123                 :          0 :         spdm_response->header.param2 = 0;
+     124                 :          0 :         spdm_response->total_key_pairs = m_response_total_key_pairs;
+     125                 :          0 :         spdm_response->key_pair_id = m_response_key_pair_id;
+     126                 :          0 :         spdm_response->capabilities = m_response_capabilities;
+     127                 :          0 :         spdm_response->key_usage_capabilities = m_response_key_usage_capabilities;
+     128                 :          0 :         spdm_response->current_key_usage = m_response_current_key_usage;
+     129                 :          0 :         spdm_response->asym_algo_capabilities = m_response_asym_algo_capabilities;
+     130                 :          0 :         spdm_response->current_asym_algo = m_response_current_asym_algo;
+     131                 :          0 :         spdm_response->public_key_info_len = public_key_info_len;
+     132                 :          0 :         spdm_response->assoc_cert_slot_mask = m_response_assoc_cert_slot_mask;
+     133                 :            : 
+     134                 :            : 
+     135                 :          0 :         libspdm_copy_mem((void*)(spdm_response + 1), public_key_info_len,
+     136                 :            :                          public_key_info_rsa2048, public_key_info_len);
+     137                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     138                 :            :                                               false, spdm_response_size,
+     139                 :            :                                               spdm_response, response_size,
+     140                 :            :                                               response);
+     141                 :            :     }
+     142                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     143                 :            : 
+     144                 :          0 :     default:
+     145                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+     146                 :            :     }
+     147                 :            : }
+     148                 :            : 
+     149                 :            : /**
+     150                 :            :  * Test 1: Successful response to get key pair info
+     151                 :            :  * Expected Behavior: get a LIBSPDM_STATUS_SUCCESS return code
+     152                 :            :  **/
+     153                 :          1 : void libspdm_test_requester_get_key_pair_info_case1(void **state)
+     154                 :            : {
+     155                 :            :     libspdm_return_t status;
+     156                 :            :     libspdm_test_context_t *spdm_test_context;
+     157                 :            :     libspdm_context_t *spdm_context;
+     158                 :            : 
+     159                 :            :     uint8_t key_pair_id;
+     160                 :            :     uint8_t associated_slot_id;
+     161                 :            :     uint8_t total_key_pairs;
+     162                 :            :     uint16_t capabilities;
+     163                 :            :     uint16_t key_usage_capabilities;
+     164                 :            :     uint16_t current_key_usage;
+     165                 :            :     uint32_t asym_algo_capabilities;
+     166                 :            :     uint32_t current_asym_algo;
+     167                 :            :     uint16_t public_key_info_len;
+     168                 :            :     uint8_t assoc_cert_slot_mask;
+     169                 :            :     uint8_t public_key_info[SPDM_MAX_PUBLIC_KEY_INFO_LEN];
+     170                 :            : 
+     171                 :          1 :     key_pair_id = 1;
+     172                 :          1 :     associated_slot_id = 1;
+     173                 :          1 :     spdm_test_context = *state;
+     174                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     175                 :          1 :     spdm_test_context->case_id = 0x1;
+     176                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+     177                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     178                 :            : 
+     179                 :          1 :     spdm_context->connection_info.connection_state =
+     180                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     181                 :          1 :     spdm_context->connection_info.capability.flags |=
+     182                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_GET_KEY_PAIR_INFO_CAP |
+     183                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_KEY_PAIR_INFO_CAP;
+     184                 :            : 
+     185                 :          1 :     spdm_context->connection_info.peer_key_pair_id[associated_slot_id] = key_pair_id;
+     186                 :          1 :     public_key_info_len = SPDM_MAX_PUBLIC_KEY_INFO_LEN;
+     187                 :            : 
+     188                 :          1 :     status = libspdm_get_key_pair_info(spdm_context, NULL, key_pair_id, &total_key_pairs,
+     189                 :            :                                        &capabilities, &key_usage_capabilities, &current_key_usage,
+     190                 :            :                                        &asym_algo_capabilities, &current_asym_algo,
+     191                 :            :                                        &assoc_cert_slot_mask, &public_key_info_len,
+     192                 :            :                                        public_key_info);
+     193                 :            : 
+     194                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     195                 :          1 :     assert_int_equal(capabilities, SPDM_KEY_PAIR_CAP_GEN_KEY_CAP);
+     196                 :          1 :     assert_int_equal(key_usage_capabilities, SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE);
+     197                 :          1 :     assert_int_equal(current_key_usage, SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE);
+     198                 :          1 :     assert_int_equal(asym_algo_capabilities, SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048);
+     199                 :          1 :     assert_int_equal(current_asym_algo, SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048);
+     200                 :          1 : }
+     201                 :            : 
+     202                 :            : /**
+     203                 :            :  * Test 2: The collection of multiple sub-cases.
+     204                 :            :  **/
+     205                 :          0 : void libspdm_test_requester_get_key_pair_info_case3(void **state)
+     206                 :            : {
+     207                 :            :     libspdm_return_t status;
+     208                 :            :     libspdm_test_context_t *spdm_test_context;
+     209                 :            :     libspdm_context_t *spdm_context;
+     210                 :            : 
+     211                 :            :     uint8_t key_pair_id;
+     212                 :            :     uint8_t associated_slot_id;
+     213                 :            :     uint8_t total_key_pairs;
+     214                 :            :     uint16_t capabilities;
+     215                 :            :     uint16_t key_usage_capabilities;
+     216                 :            :     uint16_t current_key_usage;
+     217                 :            :     uint32_t asym_algo_capabilities;
+     218                 :            :     uint32_t current_asym_algo;
+     219                 :            :     uint16_t public_key_info_len;
+     220                 :            :     uint8_t assoc_cert_slot_mask;
+     221                 :            :     uint8_t public_key_info[SPDM_MAX_PUBLIC_KEY_INFO_LEN];
+     222                 :            : 
+     223                 :          0 :     spdm_test_context = *state;
+     224                 :          0 :     spdm_context = spdm_test_context->spdm_context;
+     225                 :          0 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+     226                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     227                 :            : 
+     228                 :          0 :     spdm_context->connection_info.connection_state =
+     229                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     230                 :          0 :     spdm_context->connection_info.capability.flags |=
+     231                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_GET_KEY_PAIR_INFO_CAP;
+     232                 :            : 
+     233                 :          0 :     spdm_test_context->case_id = 0x2;
+     234                 :          0 :     public_key_info_len = SPDM_MAX_PUBLIC_KEY_INFO_LEN;
+     235                 :            : 
+     236                 :            :     /* Sub Case 1: key_pair_id > total_key_pairs*/
+     237                 :          0 :     key_pair_id = 2;
+     238                 :          0 :     associated_slot_id = 1;
+     239                 :          0 :     spdm_context->connection_info.peer_key_pair_id[associated_slot_id] = key_pair_id;
+     240                 :            : 
+     241                 :          0 :     m_response_total_key_pairs = 1;
+     242                 :          0 :     m_response_key_pair_id = 2;
+     243                 :          0 :     m_response_capabilities = SPDM_KEY_PAIR_CAP_GEN_KEY_CAP;
+     244                 :          0 :     m_response_key_usage_capabilities =SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+     245                 :          0 :     m_response_current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+     246                 :          0 :     m_response_asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
+     247                 :          0 :     m_response_current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
+     248                 :            :     /* association with slot 1*/
+     249                 :          0 :     m_response_assoc_cert_slot_mask = 0x2;
+     250                 :            : 
+     251                 :          0 :     status = libspdm_get_key_pair_info(spdm_context, NULL, key_pair_id, &total_key_pairs,
+     252                 :            :                                        &capabilities, &key_usage_capabilities, &current_key_usage,
+     253                 :            :                                        &asym_algo_capabilities, &current_asym_algo,
+     254                 :            :                                        &assoc_cert_slot_mask, &public_key_info_len,
+     255                 :            :                                        public_key_info);
+     256                 :            : 
+     257                 :          0 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+     258                 :            : 
+     259                 :            :     /* Sub Case 2: responder and requester, the KeyPairID are not consistent.*/
+     260                 :          0 :     key_pair_id = 0xA0;
+     261                 :          0 :     associated_slot_id = 1;
+     262                 :          0 :     spdm_context->connection_info.peer_key_pair_id[associated_slot_id] = key_pair_id;
+     263                 :            : 
+     264                 :          0 :     m_response_total_key_pairs = 1;
+     265                 :          0 :     m_response_key_pair_id = 1;
+     266                 :          0 :     m_response_capabilities = SPDM_KEY_PAIR_CAP_GEN_KEY_CAP;
+     267                 :          0 :     m_response_key_usage_capabilities =SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+     268                 :          0 :     m_response_current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+     269                 :          0 :     m_response_asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
+     270                 :          0 :     m_response_current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
+     271                 :            :     /* association with slot 1*/
+     272                 :          0 :     m_response_assoc_cert_slot_mask = 0x2;
+     273                 :            : 
+     274                 :          0 :     status = libspdm_get_key_pair_info(spdm_context, NULL, key_pair_id, &total_key_pairs,
+     275                 :            :                                        &capabilities, &key_usage_capabilities, &current_key_usage,
+     276                 :            :                                        &asym_algo_capabilities, &current_asym_algo,
+     277                 :            :                                        &assoc_cert_slot_mask, &public_key_info_len,
+     278                 :            :                                        public_key_info);
+     279                 :            : 
+     280                 :          0 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+     281                 :            : 
+     282                 :            :     /* Sub Case 3: not set capabilities.*/
+     283                 :          0 :     key_pair_id = 1;
+     284                 :          0 :     associated_slot_id = 1;
+     285                 :          0 :     spdm_context->connection_info.peer_key_pair_id[associated_slot_id] = key_pair_id;
+     286                 :            : 
+     287                 :          0 :     m_response_total_key_pairs = 1;
+     288                 :          0 :     m_response_key_pair_id = 1;
+     289                 :          0 :     m_response_capabilities = 0;
+     290                 :          0 :     m_response_key_usage_capabilities =SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+     291                 :          0 :     m_response_current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+     292                 :          0 :     m_response_asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
+     293                 :          0 :     m_response_current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
+     294                 :            :     /* association with slot 1*/
+     295                 :          0 :     m_response_assoc_cert_slot_mask = 0x2;
+     296                 :            : 
+     297                 :          0 :     status = libspdm_get_key_pair_info(spdm_context, NULL, key_pair_id, &total_key_pairs,
+     298                 :            :                                        &capabilities, &key_usage_capabilities, &current_key_usage,
+     299                 :            :                                        &asym_algo_capabilities, &current_asym_algo,
+     300                 :            :                                        &assoc_cert_slot_mask, &public_key_info_len,
+     301                 :            :                                        public_key_info);
+     302                 :            : 
+     303                 :          0 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     304                 :          0 :     assert_int_equal(capabilities, 0);
+     305                 :          0 :     assert_int_equal(key_usage_capabilities, SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE);
+     306                 :          0 :     assert_int_equal(current_key_usage, SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE);
+     307                 :          0 :     assert_int_equal(asym_algo_capabilities, SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048);
+     308                 :          0 :     assert_int_equal(current_asym_algo, SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048);
+     309                 :            : 
+     310                 :            :     /* Sub Case 4: This bit shall not be set if CertAssocCap is not set.
+     311                 :            :      *              Set the ShareableCap bit and not set the CertAssocCap bit.*/
+     312                 :          0 :     key_pair_id = 1;
+     313                 :          0 :     associated_slot_id = 1;
+     314                 :          0 :     spdm_context->connection_info.peer_key_pair_id[associated_slot_id] = key_pair_id;
+     315                 :            : 
+     316                 :          0 :     m_response_total_key_pairs = 1;
+     317                 :          0 :     m_response_key_pair_id = 1;
+     318                 :            : 
+     319                 :          0 :     m_response_capabilities = 0;
+     320                 :          0 :     m_response_capabilities |= SPDM_KEY_PAIR_CAP_SHAREABLE_CAP;
+     321                 :          0 :     m_response_capabilities &= ~SPDM_KEY_PAIR_CAP_CERT_ASSOC_CAP;
+     322                 :            : 
+     323                 :          0 :     m_response_key_usage_capabilities =SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+     324                 :          0 :     m_response_current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+     325                 :          0 :     m_response_asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
+     326                 :          0 :     m_response_current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
+     327                 :            :     /* association with slot 1*/
+     328                 :          0 :     m_response_assoc_cert_slot_mask = 0x2;
+     329                 :            : 
+     330                 :          0 :     status = libspdm_get_key_pair_info(spdm_context, NULL, key_pair_id, &total_key_pairs,
+     331                 :            :                                        &capabilities, &key_usage_capabilities, &current_key_usage,
+     332                 :            :                                        &asym_algo_capabilities, &current_asym_algo,
+     333                 :            :                                        &assoc_cert_slot_mask, &public_key_info_len,
+     334                 :            :                                        public_key_info);
+     335                 :            : 
+     336                 :          0 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+     337                 :            : 
+     338                 :            :     /* Sub Case 5: KeyUsageCapabilities at least one bit shall be set, not set KeyUsageCapabilities.*/
+     339                 :          0 :     m_response_total_key_pairs = 1;
+     340                 :          0 :     m_response_key_pair_id = 1;
+     341                 :          0 :     m_response_capabilities = SPDM_KEY_PAIR_CAP_GEN_KEY_CAP;
+     342                 :          0 :     m_response_key_usage_capabilities =0;
+     343                 :          0 :     m_response_current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+     344                 :          0 :     m_response_asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
+     345                 :          0 :     m_response_current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
+     346                 :            :     /* association with slot 1*/
+     347                 :          0 :     m_response_assoc_cert_slot_mask = 0x2;
+     348                 :            : 
+     349                 :          0 :     status = libspdm_get_key_pair_info(spdm_context, NULL, key_pair_id, &total_key_pairs,
+     350                 :            :                                        &capabilities, &key_usage_capabilities, &current_key_usage,
+     351                 :            :                                        &asym_algo_capabilities, &current_asym_algo,
+     352                 :            :                                        &assoc_cert_slot_mask, &public_key_info_len,
+     353                 :            :                                        public_key_info);
+     354                 :            : 
+     355                 :          0 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+     356                 :            : 
+     357                 :            :     /* Sub Case 6: KeyUsageCapabilities Set multiple bits.*/
+     358                 :          0 :     m_response_total_key_pairs = 1;
+     359                 :          0 :     m_response_key_pair_id = 1;
+     360                 :          0 :     m_response_capabilities = SPDM_KEY_PAIR_CAP_GEN_KEY_CAP;
+     361                 :          0 :     m_response_key_usage_capabilities = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE |
+     362                 :            :                                         SPDM_KEY_USAGE_BIT_MASK_CHALLENGE_USE |
+     363                 :            :                                         SPDM_KEY_USAGE_BIT_MASK_MEASUREMENT_USE |
+     364                 :            :                                         SPDM_KEY_USAGE_BIT_MASK_ENDPOINT_INFO_USE |
+     365                 :            :                                         SPDM_KEY_USAGE_BIT_MASK_STANDARDS_KEY_USE |
+     366                 :            :                                         SPDM_KEY_USAGE_BIT_MASK_VENDOR_KEY_USE;
+     367                 :          0 :     m_response_current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+     368                 :          0 :     m_response_asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
+     369                 :          0 :     m_response_current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
+     370                 :            :     /* association with slot 1*/
+     371                 :          0 :     m_response_assoc_cert_slot_mask = 0x2;
+     372                 :            : 
+     373                 :          0 :     status = libspdm_get_key_pair_info(spdm_context, NULL, key_pair_id, &total_key_pairs,
+     374                 :            :                                        &capabilities, &key_usage_capabilities, &current_key_usage,
+     375                 :            :                                        &asym_algo_capabilities, &current_asym_algo,
+     376                 :            :                                        &assoc_cert_slot_mask, &public_key_info_len,
+     377                 :            :                                        public_key_info);
+     378                 :            : 
+     379                 :          0 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     380                 :          0 :     assert_int_equal(capabilities, SPDM_KEY_PAIR_CAP_GEN_KEY_CAP);
+     381                 :          0 :     assert_int_equal(key_usage_capabilities, SPDM_KEY_USAGE_BIT_MASK);
+     382                 :          0 :     assert_int_equal(current_key_usage, SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE);
+     383                 :          0 :     assert_int_equal(asym_algo_capabilities, SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048);
+     384                 :          0 :     assert_int_equal(current_asym_algo, SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048);
+     385                 :            : 
+     386                 :            :     /* Sub Case 7: not set CurrentKeyUsage*/
+     387                 :          0 :     m_response_total_key_pairs = 1;
+     388                 :          0 :     m_response_key_pair_id = 1;
+     389                 :          0 :     m_response_capabilities = SPDM_KEY_PAIR_CAP_GEN_KEY_CAP;
+     390                 :          0 :     m_response_key_usage_capabilities = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+     391                 :          0 :     m_response_current_key_usage = 0;
+     392                 :          0 :     m_response_asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
+     393                 :          0 :     m_response_current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
+     394                 :            :     /* association with slot 1*/
+     395                 :          0 :     m_response_assoc_cert_slot_mask = 0x2;
+     396                 :            : 
+     397                 :          0 :     status = libspdm_get_key_pair_info(spdm_context, NULL, key_pair_id, &total_key_pairs,
+     398                 :            :                                        &capabilities, &key_usage_capabilities, &current_key_usage,
+     399                 :            :                                        &asym_algo_capabilities, &current_asym_algo,
+     400                 :            :                                        &assoc_cert_slot_mask, &public_key_info_len,
+     401                 :            :                                        public_key_info);
+     402                 :          0 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     403                 :          0 :     assert_int_equal(capabilities, SPDM_KEY_PAIR_CAP_GEN_KEY_CAP);
+     404                 :          0 :     assert_int_equal(key_usage_capabilities, SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE);
+     405                 :          0 :     assert_int_equal(current_key_usage, 0);
+     406                 :          0 :     assert_int_equal(asym_algo_capabilities, SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048);
+     407                 :          0 :     assert_int_equal(current_asym_algo, SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048);
+     408                 :            : 
+     409                 :            :     /* Sub Case 8:  CurrentKeyUsage Set multiple bits.*/
+     410                 :          0 :     m_response_total_key_pairs = 1;
+     411                 :          0 :     m_response_key_pair_id = 1;
+     412                 :          0 :     m_response_capabilities = SPDM_KEY_PAIR_CAP_GEN_KEY_CAP;
+     413                 :          0 :     m_response_key_usage_capabilities = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+     414                 :          0 :     m_response_current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE |
+     415                 :            :                                    SPDM_KEY_USAGE_BIT_MASK_CHALLENGE_USE |
+     416                 :            :                                    SPDM_KEY_USAGE_BIT_MASK_MEASUREMENT_USE |
+     417                 :            :                                    SPDM_KEY_USAGE_BIT_MASK_ENDPOINT_INFO_USE |
+     418                 :            :                                    SPDM_KEY_USAGE_BIT_MASK_STANDARDS_KEY_USE |
+     419                 :            :                                    SPDM_KEY_USAGE_BIT_MASK_VENDOR_KEY_USE;
+     420                 :          0 :     m_response_asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
+     421                 :          0 :     m_response_current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
+     422                 :            :     /* association with slot 1*/
+     423                 :          0 :     m_response_assoc_cert_slot_mask = 0x2;
+     424                 :            : 
+     425                 :          0 :     status = libspdm_get_key_pair_info(spdm_context, NULL, key_pair_id, &total_key_pairs,
+     426                 :            :                                        &capabilities, &key_usage_capabilities, &current_key_usage,
+     427                 :            :                                        &asym_algo_capabilities, &current_asym_algo,
+     428                 :            :                                        &assoc_cert_slot_mask, &public_key_info_len,
+     429                 :            :                                        public_key_info);
+     430                 :          0 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+     431                 :            : 
+     432                 :            :     /* Sub Case 9:  CurrentKeyUsage and KeyUsageCapabilities, Set multiple bits.*/
+     433                 :          0 :     m_response_total_key_pairs = 1;
+     434                 :          0 :     m_response_key_pair_id = 1;
+     435                 :          0 :     m_response_capabilities = SPDM_KEY_PAIR_CAP_GEN_KEY_CAP;
+     436                 :          0 :     m_response_key_usage_capabilities = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE |
+     437                 :            :                                         SPDM_KEY_USAGE_BIT_MASK_CHALLENGE_USE;
+     438                 :          0 :     m_response_current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE |
+     439                 :            :                                    SPDM_KEY_USAGE_BIT_MASK_CHALLENGE_USE;
+     440                 :          0 :     m_response_asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
+     441                 :          0 :     m_response_current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
+     442                 :            :     /* association with slot 1*/
+     443                 :          0 :     m_response_assoc_cert_slot_mask = 0x2;
+     444                 :            : 
+     445                 :          0 :     status = libspdm_get_key_pair_info(spdm_context, NULL, key_pair_id, &total_key_pairs,
+     446                 :            :                                        &capabilities, &key_usage_capabilities, &current_key_usage,
+     447                 :            :                                        &asym_algo_capabilities, &current_asym_algo,
+     448                 :            :                                        &assoc_cert_slot_mask, &public_key_info_len,
+     449                 :            :                                        public_key_info);
+     450                 :          0 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     451                 :          0 :     assert_int_equal(capabilities, SPDM_KEY_PAIR_CAP_GEN_KEY_CAP);
+     452                 :          0 :     assert_int_equal(key_usage_capabilities, SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE |
+     453                 :            :                      SPDM_KEY_USAGE_BIT_MASK_CHALLENGE_USE);
+     454                 :          0 :     assert_int_equal(current_key_usage, SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE |
+     455                 :            :                      SPDM_KEY_USAGE_BIT_MASK_CHALLENGE_USE);
+     456                 :          0 :     assert_int_equal(asym_algo_capabilities, SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048);
+     457                 :          0 :     assert_int_equal(current_asym_algo, SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048);
+     458                 :            : 
+     459                 :            :     /* Sub Case 10: CurrentKeyUsage and KeyUsageCapabilities are not consistent.*/
+     460                 :          0 :     m_response_total_key_pairs = 1;
+     461                 :          0 :     m_response_key_pair_id = 1;
+     462                 :          0 :     m_response_capabilities = SPDM_KEY_PAIR_CAP_GEN_KEY_CAP;
+     463                 :          0 :     m_response_key_usage_capabilities = SPDM_KEY_USAGE_BIT_MASK_CHALLENGE_USE;
+     464                 :          0 :     m_response_current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+     465                 :          0 :     m_response_asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
+     466                 :          0 :     m_response_current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
+     467                 :            :     /* association with slot 1*/
+     468                 :          0 :     m_response_assoc_cert_slot_mask = 0x2;
+     469                 :            : 
+     470                 :          0 :     status = libspdm_get_key_pair_info(spdm_context, NULL, key_pair_id, &total_key_pairs,
+     471                 :            :                                        &capabilities, &key_usage_capabilities, &current_key_usage,
+     472                 :            :                                        &asym_algo_capabilities, &current_asym_algo,
+     473                 :            :                                        &assoc_cert_slot_mask, &public_key_info_len,
+     474                 :            :                                        public_key_info);
+     475                 :          0 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+     476                 :            : 
+     477                 :            :     /* Sub Case 11: AsymAlgoCapabilities, at least one bit shall be set.not set AsymAlgoCapabilities*/
+     478                 :          0 :     m_response_total_key_pairs = 1;
+     479                 :          0 :     m_response_key_pair_id = 1;
+     480                 :          0 :     m_response_capabilities = SPDM_KEY_PAIR_CAP_GEN_KEY_CAP;
+     481                 :          0 :     m_response_key_usage_capabilities = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+     482                 :          0 :     m_response_current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+     483                 :          0 :     m_response_asym_algo_capabilities = 0;
+     484                 :          0 :     m_response_current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
+     485                 :            :     /* association with slot 1*/
+     486                 :          0 :     m_response_assoc_cert_slot_mask = 0x2;
+     487                 :            : 
+     488                 :          0 :     status = libspdm_get_key_pair_info(spdm_context, NULL, key_pair_id, &total_key_pairs,
+     489                 :            :                                        &capabilities, &key_usage_capabilities, &current_key_usage,
+     490                 :            :                                        &asym_algo_capabilities, &current_asym_algo,
+     491                 :            :                                        &assoc_cert_slot_mask, &public_key_info_len,
+     492                 :            :                                        public_key_info);
+     493                 :            : 
+     494                 :          0 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+     495                 :            : 
+     496                 :            :     /* Sub Case 12: AsymAlgoCapabilities Set multiple bits.*/
+     497                 :          0 :     m_response_total_key_pairs = 1;
+     498                 :          0 :     m_response_key_pair_id = 1;
+     499                 :          0 :     m_response_capabilities = SPDM_KEY_PAIR_CAP_GEN_KEY_CAP;
+     500                 :          0 :     m_response_key_usage_capabilities = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+     501                 :          0 :     m_response_current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+     502                 :          0 :     m_response_asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048 |
+     503                 :            :                                         SPDM_KEY_PAIR_ASYM_ALGO_CAP_ED448;
+     504                 :          0 :     m_response_current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
+     505                 :            :     /* association with slot 1*/
+     506                 :          0 :     m_response_assoc_cert_slot_mask = 0x2;
+     507                 :            : 
+     508                 :          0 :     status = libspdm_get_key_pair_info(spdm_context, NULL, key_pair_id, &total_key_pairs,
+     509                 :            :                                        &capabilities, &key_usage_capabilities, &current_key_usage,
+     510                 :            :                                        &asym_algo_capabilities, &current_asym_algo,
+     511                 :            :                                        &assoc_cert_slot_mask, &public_key_info_len,
+     512                 :            :                                        public_key_info);
+     513                 :            : 
+     514                 :          0 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     515                 :          0 :     assert_int_equal(capabilities, SPDM_KEY_PAIR_CAP_GEN_KEY_CAP);
+     516                 :          0 :     assert_int_equal(key_usage_capabilities, SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE);
+     517                 :          0 :     assert_int_equal(current_key_usage, SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE);
+     518                 :          0 :     assert_int_equal(asym_algo_capabilities, SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048 |
+     519                 :            :                      SPDM_KEY_PAIR_ASYM_ALGO_CAP_ED448);
+     520                 :          0 :     assert_int_equal(current_asym_algo, SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048);
+     521                 :            : 
+     522                 :            :     /* Sub Case 13: CurrentAsymAlgo Set bits more than one bit.*/
+     523                 :          0 :     m_response_total_key_pairs = 1;
+     524                 :          0 :     m_response_key_pair_id = 1;
+     525                 :          0 :     m_response_capabilities = SPDM_KEY_PAIR_CAP_GEN_KEY_CAP;
+     526                 :          0 :     m_response_key_usage_capabilities = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+     527                 :          0 :     m_response_current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+     528                 :          0 :     m_response_asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
+     529                 :          0 :     m_response_current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048 |
+     530                 :            :                                    SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA3072;
+     531                 :            :     /* association with slot 1*/
+     532                 :          0 :     m_response_assoc_cert_slot_mask = 0x2;
+     533                 :            : 
+     534                 :          0 :     status = libspdm_get_key_pair_info(spdm_context, NULL, key_pair_id, &total_key_pairs,
+     535                 :            :                                        &capabilities, &key_usage_capabilities, &current_key_usage,
+     536                 :            :                                        &asym_algo_capabilities, &current_asym_algo,
+     537                 :            :                                        &assoc_cert_slot_mask, &public_key_info_len,
+     538                 :            :                                        public_key_info);
+     539                 :            : 
+     540                 :          0 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+     541                 :            : 
+     542                 :            :     /* Sub Case 14: AsymAlgoCapabilities and AsymAlgoCapabilities are not consistent.*/
+     543                 :          0 :     m_response_total_key_pairs = 1;
+     544                 :          0 :     m_response_key_pair_id = 1;
+     545                 :          0 :     m_response_capabilities = SPDM_KEY_PAIR_CAP_GEN_KEY_CAP;
+     546                 :          0 :     m_response_key_usage_capabilities = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+     547                 :          0 :     m_response_current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+     548                 :          0 :     m_response_asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA3072;
+     549                 :          0 :     m_response_current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
+     550                 :            :     /* association with slot 1*/
+     551                 :          0 :     m_response_assoc_cert_slot_mask = 0x2;
+     552                 :            : 
+     553                 :          0 :     status = libspdm_get_key_pair_info(spdm_context, NULL, key_pair_id, &total_key_pairs,
+     554                 :            :                                        &capabilities, &key_usage_capabilities, &current_key_usage,
+     555                 :            :                                        &asym_algo_capabilities, &current_asym_algo,
+     556                 :            :                                        &assoc_cert_slot_mask, &public_key_info_len,
+     557                 :            :                                        public_key_info);
+     558                 :            : 
+     559                 :          0 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+     560                 :            : 
+     561                 :            :     /* Sub Case 15: AssocCertSlotMask set more than one bit, but ShareableCap is not set.*/
+     562                 :          0 :     m_response_total_key_pairs = 1;
+     563                 :          0 :     m_response_key_pair_id = 1;
+     564                 :          0 :     m_response_capabilities = 0;
+     565                 :          0 :     m_response_key_usage_capabilities = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+     566                 :          0 :     m_response_current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+     567                 :          0 :     m_response_asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
+     568                 :          0 :     m_response_current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
+     569                 :            :     /* association with slot 1*/
+     570                 :          0 :     m_response_assoc_cert_slot_mask = 0xFF;
+     571                 :            : 
+     572                 :          0 :     status = libspdm_get_key_pair_info(spdm_context, NULL, key_pair_id, &total_key_pairs,
+     573                 :            :                                        &capabilities, &key_usage_capabilities, &current_key_usage,
+     574                 :            :                                        &asym_algo_capabilities, &current_asym_algo,
+     575                 :            :                                        &assoc_cert_slot_mask, &public_key_info_len,
+     576                 :            :                                        public_key_info);
+     577                 :            : 
+     578                 :          0 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+     579                 :          0 : }
+     580                 :            : 
+     581                 :          1 : int libspdm_requester_get_key_pair_info_test_main(void)
+     582                 :            : {
+     583                 :          1 :     const struct CMUnitTest spdm_requester_get_key_pair_info_tests[] = {
+     584                 :            :         /* Successful response to get key pair info, key_pair_id is 1*/
+     585                 :            :         cmocka_unit_test(libspdm_test_requester_get_key_pair_info_case1),
+     586                 :            :     };
+     587                 :            : 
+     588                 :          1 :     libspdm_test_context_t test_context = {
+     589                 :            :         LIBSPDM_TEST_CONTEXT_VERSION,
+     590                 :            :         true,
+     591                 :            :         libspdm_requester_get_key_pair_info_test_send_message,
+     592                 :            :         libspdm_requester_get_key_pair_info_test_receive_message,
+     593                 :            :     };
+     594                 :            : 
+     595                 :          1 :     libspdm_setup_test_context(&test_context);
+     596                 :            : 
+     597                 :          1 :     return cmocka_run_group_tests(spdm_requester_get_key_pair_info_tests,
+     598                 :            :                                   libspdm_unit_test_group_setup,
+     599                 :            :                                   libspdm_unit_test_group_teardown);
+     600                 :            : }
+     601                 :            : 
+     602                 :            : #endif /*LIBSPDM_ENABLE_CAPABILITY_GET_KEY_PAIR_INFO_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/get_measurement_extension_log.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_requester/get_measurement_extension_log.c.func-sort-c.html new file mode 100644 index 00000000000..3009473d57e --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/get_measurement_extension_log.c.func-sort-c.html @@ -0,0 +1,137 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/get_measurement_extension_log.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - get_measurement_extension_log.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:48950996.1 %
Date:2024-09-22 08:21:07Functions:1414100.0 %
Branches:384780.9 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_get_measurement_extension_log_test_main1
libspdm_test_requester_get_measurement_extension_log_case11
libspdm_test_requester_get_measurement_extension_log_case21
libspdm_test_requester_get_measurement_extension_log_case31
libspdm_test_requester_get_measurement_extension_log_case41
libspdm_test_requester_get_measurement_extension_log_case51
libspdm_test_requester_get_measurement_extension_log_case61
libspdm_test_requester_get_measurement_extension_log_case71
libspdm_test_requester_get_measurement_extension_log_case81
libspdm_test_requester_get_measurement_extension_log_case91
generate_mel_entry_test4
libspdm_generate_long_mel7
libspdm_requester_get_measurement_extension_log_test_receive_message14
libspdm_requester_get_measurement_extension_log_test_send_message15
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/get_measurement_extension_log.c.func.html b/coverage_log/unit_test/test_spdm_requester/get_measurement_extension_log.c.func.html new file mode 100644 index 00000000000..1a3c0b81180 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/get_measurement_extension_log.c.func.html @@ -0,0 +1,137 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/get_measurement_extension_log.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - get_measurement_extension_log.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:48950996.1 %
Date:2024-09-22 08:21:07Functions:1414100.0 %
Branches:384780.9 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
generate_mel_entry_test4
libspdm_generate_long_mel7
libspdm_requester_get_measurement_extension_log_test_main1
libspdm_requester_get_measurement_extension_log_test_receive_message14
libspdm_requester_get_measurement_extension_log_test_send_message15
libspdm_test_requester_get_measurement_extension_log_case11
libspdm_test_requester_get_measurement_extension_log_case21
libspdm_test_requester_get_measurement_extension_log_case31
libspdm_test_requester_get_measurement_extension_log_case41
libspdm_test_requester_get_measurement_extension_log_case51
libspdm_test_requester_get_measurement_extension_log_case61
libspdm_test_requester_get_measurement_extension_log_case71
libspdm_test_requester_get_measurement_extension_log_case81
libspdm_test_requester_get_measurement_extension_log_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/get_measurement_extension_log.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/get_measurement_extension_log.c.gcov.html new file mode 100644 index 00000000000..cbad3753c85 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/get_measurement_extension_log.c.gcov.html @@ -0,0 +1,1199 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/get_measurement_extension_log.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - get_measurement_extension_log.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:48950996.1 %
Date:2024-09-22 08:21:07Functions:1414100.0 %
Branches:384780.9 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2024 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_requester_lib.h"
+       9                 :            : #include "internal/libspdm_secured_message_lib.h"
+      10                 :            : 
+      11                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MEL_CAP
+      12                 :            : 
+      13                 :            : #define LIBSPDM_MAX_MEASUREMENT_EXTENSION_LOG_SIZE 0x1000
+      14                 :            : 
+      15                 :            : uint8_t m_libspdm_mel_test[LIBSPDM_MAX_MEASUREMENT_EXTENSION_LOG_SIZE];
+      16                 :            : size_t m_libspdm_mel_len;
+      17                 :            : uint8_t m_libspdm_mel_number;
+      18                 :            : 
+      19                 :          4 : void generate_mel_entry_test()
+      20                 :            : {
+      21                 :            :     spdm_measurement_extension_log_dmtf_t *measurement_extension_log;
+      22                 :            :     uint32_t mel_index;
+      23                 :            :     spdm_mel_entry_dmtf_t *mel_entry;
+      24                 :            :     size_t mel_entry_size;
+      25                 :          4 :     uint8_t rom_infomational[] = "ROM";
+      26                 :            : 
+      27                 :            :     /*generate MEL*/
+      28                 :          4 :     libspdm_zero_mem(m_libspdm_mel_test, sizeof(m_libspdm_mel_test));
+      29                 :          4 :     measurement_extension_log = (spdm_measurement_extension_log_dmtf_t *)m_libspdm_mel_test;
+      30                 :            : 
+      31                 :          4 :     measurement_extension_log->number_of_entries = 0;
+      32                 :          4 :     measurement_extension_log->mel_entries_len = 0;
+      33                 :          4 :     measurement_extension_log->reserved = 0;
+      34                 :            : 
+      35                 :          4 :     m_libspdm_mel_len = sizeof(spdm_measurement_extension_log_dmtf_t);
+      36                 :          4 :     mel_entry = (spdm_mel_entry_dmtf_t *)((uint8_t *)measurement_extension_log +
+      37                 :            :                                           sizeof(spdm_measurement_extension_log_dmtf_t));
+      38                 :            : 
+      39                 :          4 :     mel_index = 0;
+      40                 :          4 :     mel_entry_size = 0;
+      41                 :            : 
+      42                 :            :     while (1)
+      43                 :            :     {
+      44         [ +  + ]:       1092 :         if((m_libspdm_mel_len + sizeof(spdm_mel_entry_dmtf_t) + sizeof(rom_infomational)) >
+      45                 :            :            sizeof(m_libspdm_mel_test)) {
+      46                 :          4 :             break;
+      47                 :            :         }
+      48                 :            : 
+      49                 :       1088 :         mel_entry->mel_index = mel_index;
+      50                 :       1088 :         mel_entry->meas_index = LIBSPDM_MEASUREMENT_INDEX_HEM;
+      51                 :            : 
+      52                 :       1088 :         libspdm_write_uint24(mel_entry->reserved, 0);
+      53                 :       1088 :         mel_entry->measurement_block_dmtf_header.dmtf_spec_measurement_value_type =
+      54                 :            :             SPDM_MEASUREMENT_BLOCK_MEASUREMENT_TYPE_VERSION |
+      55                 :            :             SPDM_MEASUREMENT_BLOCK_MEASUREMENT_TYPE_RAW_BIT_STREAM;
+      56                 :       1088 :         mel_entry->measurement_block_dmtf_header.dmtf_spec_measurement_value_size =
+      57                 :            :             sizeof(rom_infomational);
+      58                 :       1088 :         libspdm_copy_mem((void *)(mel_entry + 1), sizeof(rom_infomational),
+      59                 :            :                          rom_infomational, sizeof(rom_infomational));
+      60                 :            : 
+      61                 :       1088 :         mel_entry_size = (sizeof(spdm_mel_entry_dmtf_t) + sizeof(rom_infomational));
+      62                 :       1088 :         m_libspdm_mel_len += mel_entry_size;
+      63                 :            : 
+      64                 :       1088 :         measurement_extension_log->number_of_entries = mel_index;
+      65                 :       1088 :         measurement_extension_log->mel_entries_len += (uint32_t)mel_entry_size;
+      66                 :       1088 :         measurement_extension_log->reserved = 0;
+      67                 :            : 
+      68                 :       1088 :         mel_entry = (spdm_mel_entry_dmtf_t *)
+      69                 :       1088 :                     ((uint8_t *)mel_entry + sizeof(spdm_mel_entry_dmtf_t)+
+      70                 :       1088 :                      mel_entry->measurement_block_dmtf_header.dmtf_spec_measurement_value_size);
+      71                 :            : 
+      72                 :       1088 :         mel_index++;
+      73                 :            :     }
+      74                 :          4 : }
+      75                 :            : 
+      76                 :            : /*generate different long mel according to the m_libspdm_mel_number*/
+      77                 :          7 : void libspdm_generate_long_mel(uint32_t measurement_hash_algo)
+      78                 :            : {
+      79                 :            :     spdm_measurement_extension_log_dmtf_t *measurement_extension_log;
+      80                 :            :     spdm_mel_entry_dmtf_t *mel_entry1;
+      81                 :            :     spdm_mel_entry_dmtf_t *mel_entry2;
+      82                 :            :     spdm_mel_entry_dmtf_t *mel_entry3;
+      83                 :            :     spdm_mel_entry_dmtf_t *mel_entry;
+      84                 :            :     uint8_t index;
+      85                 :            : 
+      86                 :          7 :     uint8_t rom_informational[] = "ROM";
+      87                 :          7 :     uint8_t bootfv_informational[] = "Boot FW";
+      88                 :          7 :     uint32_t version = 0x0100030A;
+      89                 :            : 
+      90                 :            :     /*generate MEL*/
+      91                 :          7 :     measurement_extension_log = (spdm_measurement_extension_log_dmtf_t *)m_libspdm_mel_test;
+      92                 :            : 
+      93                 :          7 :     measurement_extension_log->number_of_entries = m_libspdm_mel_number;
+      94                 :          7 :     measurement_extension_log->mel_entries_len =
+      95                 :          7 :         measurement_extension_log->number_of_entries * sizeof(spdm_mel_entry_dmtf_t) +
+      96                 :          7 :         sizeof(rom_informational) - 1 + sizeof(bootfv_informational) - 1 +
+      97                 :          7 :         sizeof(version) * (m_libspdm_mel_number - 2);
+      98                 :          7 :     measurement_extension_log->reserved = 0;
+      99                 :            : 
+     100                 :            :     /*MEL Entry 1: informational ROM */
+     101                 :          7 :     mel_entry1 = (spdm_mel_entry_dmtf_t *)((uint8_t *)measurement_extension_log +
+     102                 :            :                                            sizeof(spdm_measurement_extension_log_dmtf_t));
+     103                 :          7 :     mel_entry1->mel_index = 1;
+     104                 :          7 :     mel_entry1->meas_index = LIBSPDM_MEASUREMENT_INDEX_HEM;
+     105                 :          7 :     libspdm_write_uint24(mel_entry1->reserved, 0);
+     106                 :          7 :     mel_entry1->measurement_block_dmtf_header.dmtf_spec_measurement_value_type =
+     107                 :            :         SPDM_MEASUREMENT_BLOCK_MEASUREMENT_TYPE_INFORMATIONAL |
+     108                 :            :         SPDM_MEASUREMENT_BLOCK_MEASUREMENT_TYPE_RAW_BIT_STREAM;
+     109                 :          7 :     mel_entry1->measurement_block_dmtf_header.dmtf_spec_measurement_value_size =
+     110                 :            :         sizeof(rom_informational) - 1;
+     111                 :          7 :     libspdm_copy_mem((void *)(mel_entry1 + 1), sizeof(rom_informational) - 1,
+     112                 :            :                      rom_informational, sizeof(rom_informational) - 1);
+     113                 :            : 
+     114                 :            :     /*MEL Entry 2: informational Boot FW */
+     115                 :          7 :     mel_entry2 = (spdm_mel_entry_dmtf_t *)((uint8_t *)(mel_entry1 + 1) +
+     116                 :            :                                            sizeof(rom_informational) - 1);
+     117                 :          7 :     mel_entry2->mel_index = 2;
+     118                 :          7 :     mel_entry2->meas_index = LIBSPDM_MEASUREMENT_INDEX_HEM;
+     119                 :          7 :     libspdm_write_uint24(mel_entry2->reserved, 0);
+     120                 :          7 :     mel_entry2->measurement_block_dmtf_header.dmtf_spec_measurement_value_type =
+     121                 :            :         SPDM_MEASUREMENT_BLOCK_MEASUREMENT_TYPE_INFORMATIONAL |
+     122                 :            :         SPDM_MEASUREMENT_BLOCK_MEASUREMENT_TYPE_RAW_BIT_STREAM;
+     123                 :          7 :     mel_entry2->measurement_block_dmtf_header.dmtf_spec_measurement_value_size =
+     124                 :            :         sizeof(bootfv_informational) - 1;
+     125                 :          7 :     libspdm_copy_mem((void *)(mel_entry2 + 1), sizeof(bootfv_informational) - 1,
+     126                 :            :                      bootfv_informational, sizeof(bootfv_informational) - 1);
+     127                 :            : 
+     128                 :            :     /*MEL Entry 3: version 0x0100030A */
+     129                 :          7 :     mel_entry3 = (spdm_mel_entry_dmtf_t *)((uint8_t *)(mel_entry2 + 1) +
+     130                 :            :                                            sizeof(bootfv_informational) - 1);
+     131                 :          7 :     mel_entry3->mel_index = 3;
+     132                 :          7 :     mel_entry3->meas_index = LIBSPDM_MEASUREMENT_INDEX_HEM;
+     133                 :          7 :     libspdm_write_uint24(mel_entry3->reserved, 0);
+     134                 :          7 :     mel_entry3->measurement_block_dmtf_header.dmtf_spec_measurement_value_type =
+     135                 :            :         SPDM_MEASUREMENT_BLOCK_MEASUREMENT_TYPE_VERSION |
+     136                 :            :         SPDM_MEASUREMENT_BLOCK_MEASUREMENT_TYPE_RAW_BIT_STREAM;
+     137                 :          7 :     mel_entry3->measurement_block_dmtf_header.dmtf_spec_measurement_value_size = sizeof(version);
+     138                 :          7 :     libspdm_copy_mem((void *)(mel_entry3 + 1), sizeof(version), &version, sizeof(version));
+     139                 :            : 
+     140                 :            :     /*MEL Entry 4 -> m_libspdm_mel_number: version 0x0100030A */
+     141                 :          7 :     mel_entry = (spdm_mel_entry_dmtf_t *)((uint8_t *)(mel_entry3 + 1) +
+     142                 :            :                                           sizeof(version));
+     143         [ +  + ]:        694 :     for (index = 4; index <= m_libspdm_mel_number; index++) {
+     144                 :        687 :         mel_entry->mel_index = index;
+     145                 :        687 :         mel_entry->meas_index = LIBSPDM_MEASUREMENT_INDEX_HEM;
+     146                 :        687 :         libspdm_write_uint24(mel_entry->reserved, 0);
+     147                 :        687 :         mel_entry->measurement_block_dmtf_header.dmtf_spec_measurement_value_type =
+     148                 :            :             SPDM_MEASUREMENT_BLOCK_MEASUREMENT_TYPE_VERSION |
+     149                 :            :             SPDM_MEASUREMENT_BLOCK_MEASUREMENT_TYPE_RAW_BIT_STREAM;
+     150                 :        687 :         mel_entry->measurement_block_dmtf_header.dmtf_spec_measurement_value_size =
+     151                 :            :             sizeof(version);
+     152                 :        687 :         libspdm_copy_mem((void *)(mel_entry + 1), sizeof(version), &version, sizeof(version));
+     153                 :        687 :         mel_entry = (spdm_mel_entry_dmtf_t *)((uint8_t *)(mel_entry + 1) + sizeof(version));
+     154                 :            :     }
+     155                 :          7 : }
+     156                 :            : 
+     157                 :         15 : libspdm_return_t libspdm_requester_get_measurement_extension_log_test_send_message(
+     158                 :            :     void *spdm_context, size_t request_size, const void *request,
+     159                 :            :     uint64_t timeout)
+     160                 :            : {
+     161                 :            :     libspdm_test_context_t *spdm_test_context;
+     162                 :            : 
+     163                 :         15 :     spdm_test_context = libspdm_get_test_context();
+     164      [ +  +  - ]:         15 :     switch (spdm_test_context->case_id) {
+     165                 :          1 :     case 0x1:
+     166                 :          1 :         return LIBSPDM_STATUS_SEND_FAIL;
+     167                 :         14 :     case 0x2:
+     168                 :            :     case 0x3:
+     169                 :            :     case 0x4:
+     170                 :            :     case 0x5:
+     171                 :            :     case 0x6:
+     172                 :            :     case 0x7:
+     173                 :            :     case 0x8:
+     174                 :            :     case 0x9:
+     175                 :         14 :         return LIBSPDM_STATUS_SUCCESS;
+     176                 :          0 :     default:
+     177                 :          0 :         return LIBSPDM_STATUS_SEND_FAIL;
+     178                 :            :     }
+     179                 :            : }
+     180                 :            : 
+     181                 :         14 : libspdm_return_t libspdm_requester_get_measurement_extension_log_test_receive_message(
+     182                 :            :     void *spdm_context, size_t *response_size,
+     183                 :            :     void **response, uint64_t timeout)
+     184                 :            : {
+     185                 :            :     libspdm_test_context_t *spdm_test_context;
+     186                 :            : 
+     187                 :         14 :     spdm_test_context = libspdm_get_test_context();
+     188   [ -  +  +  +  :         14 :     switch (spdm_test_context->case_id) {
+          +  +  +  +  +  
+                      - ]
+     189                 :          0 :     case 0x1:
+     190                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+     191                 :            : 
+     192                 :          1 :     case 0x2: {
+     193                 :            :         spdm_measurement_extension_log_response_t *spdm_response;
+     194                 :            :         size_t spdm_response_size;
+     195                 :            :         size_t transport_header_size;
+     196                 :            :         uint32_t portion_length;
+     197                 :            :         uint32_t remainder_length;
+     198                 :            :         size_t count;
+     199                 :            :         static size_t calling_index = 0;
+     200                 :            :         spdm_measurement_extension_log_dmtf_t *spdm_mel;
+     201                 :            : 
+     202                 :          1 :         spdm_mel = NULL;
+     203                 :          1 :         m_libspdm_mel_len = 0;
+     204                 :            : 
+     205                 :          1 :         libspdm_measurement_extension_log_collection(
+     206                 :            :             spdm_context,
+     207                 :            :             m_libspdm_use_mel_spec,
+     208                 :            :             m_libspdm_use_measurement_spec,
+     209                 :            :             m_libspdm_use_measurement_hash_algo,
+     210                 :            :             (void **)&spdm_mel, &m_libspdm_mel_len);
+     211                 :            : 
+     212                 :          1 :         count = (m_libspdm_mel_len + LIBSPDM_MAX_MEL_BLOCK_LEN - 1) / LIBSPDM_MAX_MEL_BLOCK_LEN;
+     213         [ -  + ]:          1 :         if (calling_index != count - 1) {
+     214                 :          0 :             portion_length = LIBSPDM_MAX_MEL_BLOCK_LEN;
+     215                 :          0 :             remainder_length =
+     216                 :          0 :                 (uint32_t)(m_libspdm_mel_len -
+     217                 :            :                            LIBSPDM_MAX_MEL_BLOCK_LEN *
+     218                 :          0 :                            (calling_index + 1));
+     219                 :            :         } else {
+     220                 :          1 :             portion_length = (uint32_t)(
+     221                 :            :                 m_libspdm_mel_len -
+     222                 :          1 :                 LIBSPDM_MAX_MEL_BLOCK_LEN * (count - 1));
+     223                 :          1 :             remainder_length = 0;
+     224                 :            :         }
+     225                 :            : 
+     226                 :          1 :         spdm_response_size =
+     227                 :          1 :             sizeof(spdm_measurement_extension_log_response_t) + portion_length;
+     228                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     229                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     230                 :            : 
+     231                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+     232                 :          1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENT_EXTENSION_LOG;
+     233                 :          1 :         spdm_response->header.param1 = 0;
+     234                 :          1 :         spdm_response->header.param2 = 0;
+     235                 :          1 :         spdm_response->portion_length = portion_length;
+     236                 :          1 :         spdm_response->remainder_length = remainder_length;
+     237                 :          1 :         libspdm_copy_mem(spdm_response + 1,
+     238                 :          1 :                          (size_t)(*response) + *response_size - (size_t)(spdm_response + 1),
+     239                 :          1 :                          (uint8_t *)spdm_mel +
+     240                 :          1 :                          LIBSPDM_MAX_MEL_BLOCK_LEN * calling_index,
+     241                 :            :                          portion_length);
+     242                 :            : 
+     243                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     244                 :            :                                               false, spdm_response_size,
+     245                 :            :                                               spdm_response, response_size,
+     246                 :            :                                               response);
+     247                 :            : 
+     248                 :          1 :         calling_index++;
+     249         [ +  - ]:          1 :         if (calling_index == count) {
+     250                 :          1 :             calling_index = 0;
+     251                 :            :         }
+     252                 :            :     }
+     253                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     254                 :          1 :     case 0x3: {
+     255                 :            :         spdm_measurement_extension_log_response_t *spdm_response;
+     256                 :            :         size_t spdm_response_size;
+     257                 :            :         size_t transport_header_size;
+     258                 :            :         uint32_t portion_length;
+     259                 :            :         uint32_t remainder_length;
+     260                 :            :         size_t count;
+     261                 :            :         static size_t calling_index = 0;
+     262                 :            :         spdm_measurement_extension_log_dmtf_t *spdm_mel;
+     263                 :            :         spdm_measurement_extension_log_dmtf_t *measurement_extension_log;
+     264                 :            :         size_t mel_new_len;
+     265                 :            :         size_t mel_send_len;
+     266                 :            : 
+     267                 :          1 :         spdm_mel = NULL;
+     268                 :          1 :         m_libspdm_mel_len = 0;
+     269                 :          1 :         mel_new_len = 0;
+     270                 :          1 :         mel_send_len = 0;
+     271                 :          1 :         m_libspdm_mel_number = 3;
+     272                 :            : 
+     273                 :          1 :         libspdm_generate_long_mel(m_libspdm_use_measurement_hash_algo);
+     274                 :            : 
+     275                 :          1 :         measurement_extension_log = (spdm_measurement_extension_log_dmtf_t *)m_libspdm_mel_test;
+     276                 :          1 :         spdm_mel = (spdm_measurement_extension_log_dmtf_t *)m_libspdm_mel_test;
+     277                 :          1 :         m_libspdm_mel_len = (size_t)(measurement_extension_log->mel_entries_len) +
+     278                 :            :                             sizeof(spdm_measurement_extension_log_dmtf_t);
+     279                 :            : 
+     280         [ -  + ]:          1 :         if (calling_index == 1) {
+     281                 :          0 :             m_libspdm_mel_number = 4;
+     282                 :          0 :             libspdm_generate_long_mel(m_libspdm_use_measurement_hash_algo);
+     283                 :          0 :             measurement_extension_log = (spdm_measurement_extension_log_dmtf_t *)m_libspdm_mel_test;
+     284                 :          0 :             mel_new_len = (size_t)(measurement_extension_log->mel_entries_len) +
+     285                 :            :                           sizeof(spdm_measurement_extension_log_dmtf_t);
+     286                 :            :         }
+     287                 :            : 
+     288                 :          1 :         mel_send_len = (m_libspdm_mel_len > mel_new_len) ? m_libspdm_mel_len : mel_new_len;
+     289                 :            : 
+     290                 :          1 :         count = (mel_send_len + LIBSPDM_MAX_MEL_BLOCK_LEN - 1) / LIBSPDM_MAX_MEL_BLOCK_LEN;
+     291         [ -  + ]:          1 :         if (calling_index != count - 1) {
+     292                 :          0 :             portion_length = LIBSPDM_MAX_MEL_BLOCK_LEN;
+     293                 :          0 :             remainder_length =
+     294                 :          0 :                 (uint32_t)(mel_send_len -
+     295                 :            :                            LIBSPDM_MAX_MEL_BLOCK_LEN *
+     296                 :          0 :                            (calling_index + 1));
+     297                 :            :         } else {
+     298                 :          1 :             portion_length = (uint32_t)(
+     299                 :            :                 m_libspdm_mel_len -
+     300                 :          1 :                 LIBSPDM_MAX_MEL_BLOCK_LEN * (count - 1));
+     301                 :          1 :             remainder_length = (uint32_t)(
+     302                 :          1 :                 mel_send_len -
+     303                 :          1 :                 LIBSPDM_MAX_MEL_BLOCK_LEN * (count - 1) -
+     304                 :            :                 portion_length);
+     305                 :            :         }
+     306                 :            : 
+     307                 :          1 :         spdm_response_size =
+     308                 :          1 :             sizeof(spdm_measurement_extension_log_response_t) + portion_length;
+     309                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     310                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     311                 :            : 
+     312                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+     313                 :          1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENT_EXTENSION_LOG;
+     314                 :          1 :         spdm_response->header.param1 = 0;
+     315                 :          1 :         spdm_response->header.param2 = 0;
+     316                 :          1 :         spdm_response->portion_length = portion_length;
+     317                 :          1 :         spdm_response->remainder_length = remainder_length;
+     318                 :          1 :         libspdm_copy_mem(spdm_response + 1,
+     319                 :          1 :                          (size_t)(*response) + *response_size - (size_t)(spdm_response + 1),
+     320                 :            :                          (uint8_t *)spdm_mel +
+     321                 :          1 :                          LIBSPDM_MAX_MEL_BLOCK_LEN * calling_index,
+     322                 :            :                          portion_length);
+     323                 :            : 
+     324                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     325                 :            :                                               false, spdm_response_size,
+     326                 :            :                                               spdm_response, response_size,
+     327                 :            :                                               response);
+     328                 :            : 
+     329                 :          1 :         calling_index++;
+     330         [ +  - ]:          1 :         if (calling_index == count) {
+     331                 :          1 :             calling_index = 0;
+     332                 :            :         }
+     333                 :            :     }
+     334                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     335                 :          2 :     case 0x4: {
+     336                 :            :         spdm_measurement_extension_log_response_t *spdm_response;
+     337                 :            :         size_t spdm_response_size;
+     338                 :            :         size_t transport_header_size;
+     339                 :            :         uint32_t portion_length;
+     340                 :            :         uint32_t remainder_length;
+     341                 :            :         size_t count;
+     342                 :            :         static size_t calling_index = 0;
+     343                 :            :         spdm_measurement_extension_log_dmtf_t *spdm_mel;
+     344                 :            :         spdm_measurement_extension_log_dmtf_t *measurement_extension_log;
+     345                 :            :         size_t mel_new_len;
+     346                 :            :         size_t mel_send_len;
+     347                 :            : 
+     348                 :          2 :         spdm_mel = NULL;
+     349                 :          2 :         m_libspdm_mel_len = 0;
+     350                 :          2 :         mel_new_len = 0;
+     351                 :          2 :         mel_send_len = 0;
+     352                 :          2 :         m_libspdm_mel_number = 100;
+     353                 :            : 
+     354                 :          2 :         libspdm_generate_long_mel(m_libspdm_use_measurement_hash_algo);
+     355                 :            : 
+     356                 :          2 :         measurement_extension_log = (spdm_measurement_extension_log_dmtf_t *)m_libspdm_mel_test;
+     357                 :          2 :         spdm_mel = (spdm_measurement_extension_log_dmtf_t *)m_libspdm_mel_test;
+     358                 :          2 :         m_libspdm_mel_len = (size_t)(measurement_extension_log->mel_entries_len) +
+     359                 :            :                             sizeof(spdm_measurement_extension_log_dmtf_t);
+     360                 :            : 
+     361         [ +  + ]:          2 :         if (calling_index == 1) {
+     362                 :          1 :             m_libspdm_mel_number = 105;
+     363                 :          1 :             libspdm_generate_long_mel(m_libspdm_use_measurement_hash_algo);
+     364                 :          1 :             measurement_extension_log = (spdm_measurement_extension_log_dmtf_t *)m_libspdm_mel_test;
+     365                 :          1 :             mel_new_len = (size_t)(measurement_extension_log->mel_entries_len) +
+     366                 :            :                           sizeof(spdm_measurement_extension_log_dmtf_t);
+     367                 :            :         }
+     368                 :            : 
+     369                 :          2 :         mel_send_len = (m_libspdm_mel_len > mel_new_len) ? m_libspdm_mel_len : mel_new_len;
+     370                 :            : 
+     371                 :          2 :         count = (m_libspdm_mel_len + LIBSPDM_MAX_MEL_BLOCK_LEN - 1) / LIBSPDM_MAX_MEL_BLOCK_LEN;
+     372         [ +  + ]:          2 :         if (calling_index != count - 1) {
+     373                 :          1 :             portion_length = LIBSPDM_MAX_MEL_BLOCK_LEN;
+     374                 :          1 :             remainder_length =
+     375                 :          1 :                 (uint32_t)(mel_send_len -
+     376                 :            :                            LIBSPDM_MAX_MEL_BLOCK_LEN *
+     377                 :          1 :                            (calling_index + 1));
+     378                 :            :         } else {
+     379                 :          1 :             portion_length = (uint32_t)(
+     380                 :            :                 m_libspdm_mel_len -
+     381                 :          1 :                 LIBSPDM_MAX_MEL_BLOCK_LEN * (count - 1));
+     382                 :          1 :             remainder_length = (uint32_t)(
+     383                 :          1 :                 mel_send_len -
+     384                 :          1 :                 LIBSPDM_MAX_MEL_BLOCK_LEN * (count - 1) -
+     385                 :            :                 portion_length);
+     386                 :            :         }
+     387                 :            : 
+     388                 :          2 :         spdm_response_size =
+     389                 :          2 :             sizeof(spdm_measurement_extension_log_response_t) + portion_length;
+     390                 :          2 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     391                 :          2 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     392                 :            : 
+     393                 :          2 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+     394                 :          2 :         spdm_response->header.request_response_code = SPDM_MEASUREMENT_EXTENSION_LOG;
+     395                 :          2 :         spdm_response->header.param1 = 0;
+     396                 :          2 :         spdm_response->header.param2 = 0;
+     397                 :          2 :         spdm_response->portion_length = portion_length;
+     398                 :          2 :         spdm_response->remainder_length = remainder_length;
+     399                 :          2 :         libspdm_copy_mem(spdm_response + 1,
+     400                 :          2 :                          (size_t)(*response) + *response_size - (size_t)(spdm_response + 1),
+     401                 :            :                          (uint8_t *)spdm_mel +
+     402                 :          2 :                          LIBSPDM_MAX_MEL_BLOCK_LEN * calling_index,
+     403                 :            :                          portion_length);
+     404                 :            : 
+     405                 :          2 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     406                 :            :                                               false, spdm_response_size,
+     407                 :            :                                               spdm_response, response_size,
+     408                 :            :                                               response);
+     409                 :            : 
+     410                 :          2 :         calling_index++;
+     411         [ +  + ]:          2 :         if (calling_index == count) {
+     412                 :          1 :             calling_index = 0;
+     413                 :            :         }
+     414                 :            :     }
+     415                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     416                 :          2 :     case 0x5: {
+     417                 :            :         spdm_measurement_extension_log_response_t *spdm_response;
+     418                 :            :         size_t spdm_response_size;
+     419                 :            :         size_t transport_header_size;
+     420                 :            :         uint32_t portion_length;
+     421                 :            :         uint32_t remainder_length;
+     422                 :            :         size_t count;
+     423                 :            :         static size_t calling_index = 0;
+     424                 :            :         spdm_measurement_extension_log_dmtf_t *spdm_mel;
+     425                 :            :         spdm_measurement_extension_log_dmtf_t *measurement_extension_log;
+     426                 :            :         size_t mel_new_len;
+     427                 :            :         size_t mel_send_len;
+     428                 :            : 
+     429                 :          2 :         spdm_mel = NULL;
+     430                 :          2 :         m_libspdm_mel_len = 0;
+     431                 :          2 :         mel_new_len = 0;
+     432                 :          2 :         mel_send_len = 0;
+     433                 :          2 :         m_libspdm_mel_number = 100;
+     434                 :            : 
+     435                 :          2 :         libspdm_generate_long_mel(m_libspdm_use_measurement_hash_algo);
+     436                 :            : 
+     437                 :          2 :         measurement_extension_log = (spdm_measurement_extension_log_dmtf_t *)m_libspdm_mel_test;
+     438                 :          2 :         spdm_mel = (spdm_measurement_extension_log_dmtf_t *)m_libspdm_mel_test;
+     439                 :          2 :         m_libspdm_mel_len = (size_t)(measurement_extension_log->mel_entries_len) +
+     440                 :            :                             sizeof(spdm_measurement_extension_log_dmtf_t);
+     441                 :            : 
+     442         [ +  + ]:          2 :         if (calling_index == 1) {
+     443                 :          1 :             m_libspdm_mel_number = 200;
+     444                 :          1 :             libspdm_generate_long_mel(m_libspdm_use_measurement_hash_algo);
+     445                 :          1 :             measurement_extension_log = (spdm_measurement_extension_log_dmtf_t *)m_libspdm_mel_test;
+     446                 :          1 :             mel_new_len = (size_t)(measurement_extension_log->mel_entries_len) +
+     447                 :            :                           sizeof(spdm_measurement_extension_log_dmtf_t);
+     448                 :            :         }
+     449                 :            : 
+     450                 :          2 :         mel_send_len = (m_libspdm_mel_len > mel_new_len) ? m_libspdm_mel_len : mel_new_len;
+     451                 :            : 
+     452                 :          2 :         count = (m_libspdm_mel_len + LIBSPDM_MAX_MEL_BLOCK_LEN - 1) / LIBSPDM_MAX_MEL_BLOCK_LEN;
+     453         [ +  + ]:          2 :         if (calling_index != count - 1) {
+     454                 :          1 :             portion_length = LIBSPDM_MAX_MEL_BLOCK_LEN;
+     455                 :          1 :             remainder_length =
+     456                 :          1 :                 (uint32_t)(mel_send_len -
+     457                 :            :                            LIBSPDM_MAX_MEL_BLOCK_LEN *
+     458                 :          1 :                            (calling_index + 1));
+     459                 :            :         } else {
+     460                 :          1 :             portion_length = (uint32_t)(
+     461                 :            :                 m_libspdm_mel_len -
+     462                 :          1 :                 LIBSPDM_MAX_MEL_BLOCK_LEN * (count - 1));
+     463                 :          1 :             remainder_length = (uint32_t)(
+     464                 :          1 :                 mel_send_len -
+     465                 :          1 :                 LIBSPDM_MAX_MEL_BLOCK_LEN * (count - 1) -
+     466                 :            :                 portion_length);
+     467                 :            :         }
+     468                 :            : 
+     469                 :          2 :         spdm_response_size =
+     470                 :          2 :             sizeof(spdm_measurement_extension_log_response_t) + portion_length;
+     471                 :          2 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     472                 :          2 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     473                 :            : 
+     474                 :          2 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+     475                 :          2 :         spdm_response->header.request_response_code = SPDM_MEASUREMENT_EXTENSION_LOG;
+     476                 :          2 :         spdm_response->header.param1 = 0;
+     477                 :          2 :         spdm_response->header.param2 = 0;
+     478                 :          2 :         spdm_response->portion_length = portion_length;
+     479                 :          2 :         spdm_response->remainder_length = remainder_length;
+     480                 :          2 :         libspdm_copy_mem(spdm_response + 1,
+     481                 :          2 :                          (size_t)(*response) + *response_size - (size_t)(spdm_response + 1),
+     482                 :            :                          (uint8_t *)spdm_mel +
+     483                 :          2 :                          LIBSPDM_MAX_MEL_BLOCK_LEN * calling_index,
+     484                 :            :                          portion_length);
+     485                 :            : 
+     486                 :          2 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     487                 :            :                                               false, spdm_response_size,
+     488                 :            :                                               spdm_response, response_size,
+     489                 :            :                                               response);
+     490                 :            : 
+     491                 :          2 :         calling_index++;
+     492         [ +  + ]:          2 :         if (calling_index == count) {
+     493                 :          1 :             calling_index = 0;
+     494                 :            :         }
+     495                 :            :     }
+     496                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     497                 :          4 :     case 0x6:
+     498                 :            :     {
+     499                 :            :         spdm_measurement_extension_log_response_t *spdm_response;
+     500                 :            :         size_t spdm_response_size;
+     501                 :            :         size_t transport_header_size;
+     502                 :            :         uint32_t portion_length;
+     503                 :            :         uint32_t remainder_length;
+     504                 :            :         spdm_measurement_extension_log_dmtf_t *spdm_mel;
+     505                 :            : 
+     506                 :            :         static size_t count = 0;
+     507                 :            :         static size_t calling_index = 0;
+     508                 :            : 
+     509         [ +  + ]:          4 :         if (calling_index == 0) {
+     510                 :          1 :             count = (m_libspdm_mel_len / LIBSPDM_MAX_MEL_BLOCK_LEN) + 1;
+     511                 :            :         }
+     512                 :            : 
+     513                 :          4 :         spdm_mel = (spdm_measurement_extension_log_dmtf_t *)m_libspdm_mel_test;
+     514                 :            : 
+     515                 :          4 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     516                 :          4 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     517                 :            : 
+     518                 :          4 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+     519                 :          4 :         spdm_response->header.request_response_code = SPDM_MEASUREMENT_EXTENSION_LOG;
+     520                 :          4 :         spdm_response->header.param1 = 0;
+     521                 :          4 :         spdm_response->header.param2 = 0;
+     522                 :            : 
+     523         [ +  + ]:          4 :         if(m_libspdm_mel_len > LIBSPDM_MAX_MEL_BLOCK_LEN) {
+     524                 :          3 :             portion_length = LIBSPDM_MAX_MEL_BLOCK_LEN;
+     525                 :          3 :             remainder_length =
+     526                 :          3 :                 (uint32_t)(m_libspdm_mel_len - LIBSPDM_MAX_MEL_BLOCK_LEN);
+     527                 :            :         } else {
+     528                 :          1 :             portion_length  = (uint32_t)m_libspdm_mel_len;
+     529                 :          1 :             remainder_length = 0;
+     530                 :            :         }
+     531                 :            : 
+     532                 :          4 :         spdm_response->portion_length = portion_length;
+     533                 :          4 :         spdm_response->remainder_length = remainder_length;
+     534                 :            : 
+     535                 :          4 :         libspdm_copy_mem(spdm_response + 1,
+     536                 :          4 :                          (size_t)(*response) + *response_size - (size_t)(spdm_response + 1),
+     537                 :            :                          (uint8_t *)spdm_mel +
+     538                 :          4 :                          LIBSPDM_MAX_MEL_BLOCK_LEN * calling_index,
+     539                 :            :                          portion_length);
+     540                 :            : 
+     541                 :          4 :         spdm_response_size = sizeof(spdm_measurement_extension_log_response_t) + portion_length;
+     542                 :            : 
+     543                 :          4 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     544                 :            :                                               false, spdm_response_size,
+     545                 :            :                                               spdm_response, response_size,
+     546                 :            :                                               response);
+     547                 :            : 
+     548                 :          4 :         m_libspdm_mel_len -= portion_length;;
+     549                 :          4 :         calling_index++;
+     550                 :            : 
+     551         [ -  + ]:          4 :         if (calling_index == count) {
+     552                 :          0 :             calling_index = 0;
+     553                 :          0 :             m_libspdm_mel_len = 0;
+     554                 :            :         }
+     555                 :            :     }
+     556                 :          4 :         return LIBSPDM_STATUS_SUCCESS;
+     557                 :            : 
+     558                 :          2 :     case 0x7:
+     559                 :            :     {
+     560                 :            :         spdm_measurement_extension_log_response_t *spdm_response;
+     561                 :            :         size_t spdm_response_size;
+     562                 :            :         size_t transport_header_size;
+     563                 :            :         spdm_measurement_extension_log_dmtf_t *spdm_mel;
+     564                 :            : 
+     565                 :            :         static size_t calling_index = 0;
+     566                 :            : 
+     567                 :          2 :         spdm_mel = (spdm_measurement_extension_log_dmtf_t *)m_libspdm_mel_test;
+     568                 :            : 
+     569                 :          2 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     570                 :          2 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     571                 :            : 
+     572                 :          2 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+     573                 :          2 :         spdm_response->header.request_response_code = SPDM_MEASUREMENT_EXTENSION_LOG;
+     574                 :          2 :         spdm_response->header.param1 = 0;
+     575                 :          2 :         spdm_response->header.param2 = 0;
+     576         [ +  + ]:          2 :         if (calling_index == 0) {
+     577                 :          1 :             spdm_response->portion_length = LIBSPDM_MAX_MEL_BLOCK_LEN;
+     578                 :          1 :             spdm_response->remainder_length = LIBSPDM_MAX_MEL_BLOCK_LEN;
+     579                 :            :         } else {
+     580                 :            :             /* The total amount of messages actually sent by the responder is less than the negotiated total mel len*/
+     581                 :          1 :             spdm_response->portion_length = LIBSPDM_MAX_MEL_BLOCK_LEN / 2;
+     582                 :          1 :             spdm_response->remainder_length = 0;
+     583                 :            :         }
+     584                 :            : 
+     585                 :          2 :         libspdm_copy_mem(spdm_response + 1,
+     586                 :          2 :                          (size_t)(*response) + *response_size - (size_t)(spdm_response + 1),
+     587                 :            :                          (uint8_t *)spdm_mel,
+     588                 :            :                          LIBSPDM_MAX_MEL_BLOCK_LEN);
+     589                 :            : 
+     590                 :          2 :         spdm_response_size = sizeof(spdm_measurement_extension_log_response_t) +
+     591                 :            :                              LIBSPDM_MAX_MEL_BLOCK_LEN;
+     592                 :            : 
+     593                 :          2 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     594                 :            :                                               false, spdm_response_size,
+     595                 :            :                                               spdm_response, response_size,
+     596                 :            :                                               response);
+     597                 :          2 :         calling_index++;
+     598                 :            :     }
+     599                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     600                 :          1 :     case 0x8:
+     601                 :            :     {
+     602                 :            :         spdm_measurement_extension_log_response_t *spdm_response;
+     603                 :            :         size_t spdm_response_size;
+     604                 :            :         size_t transport_header_size;
+     605                 :            :         spdm_measurement_extension_log_dmtf_t *spdm_mel;
+     606                 :            : 
+     607                 :          1 :         spdm_mel = (spdm_measurement_extension_log_dmtf_t *)m_libspdm_mel_test;
+     608                 :            : 
+     609                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     610                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     611                 :            : 
+     612                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+     613                 :          1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENT_EXTENSION_LOG;
+     614                 :          1 :         spdm_response->header.param1 = 0;
+     615                 :          1 :         spdm_response->header.param2 = 0;
+     616                 :            :         /* Portion_length is greater than the LIBSPDM_MAX_MEL_BLOCK_LEN */
+     617                 :          1 :         spdm_response->portion_length = LIBSPDM_MAX_MEL_BLOCK_LEN + 1;
+     618                 :          1 :         spdm_response->remainder_length = 0;
+     619                 :            : 
+     620                 :          1 :         libspdm_copy_mem(spdm_response + 1,
+     621                 :          1 :                          (size_t)(*response) + *response_size - (size_t)(spdm_response + 1),
+     622                 :            :                          (uint8_t *)spdm_mel,
+     623                 :            :                          LIBSPDM_MAX_MEL_BLOCK_LEN);
+     624                 :            : 
+     625                 :          1 :         spdm_response_size = sizeof(spdm_measurement_extension_log_response_t) +
+     626                 :            :                              LIBSPDM_MAX_MEL_BLOCK_LEN;
+     627                 :            : 
+     628                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     629                 :            :                                               false, spdm_response_size,
+     630                 :            :                                               spdm_response, response_size,
+     631                 :            :                                               response);
+     632                 :            :     }
+     633                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     634                 :            : 
+     635                 :          1 :     case 0x9:
+     636                 :            :     {
+     637                 :            :         spdm_measurement_extension_log_response_t *spdm_response;
+     638                 :            :         size_t spdm_response_size;
+     639                 :            :         size_t transport_header_size;
+     640                 :            :         spdm_measurement_extension_log_dmtf_t *spdm_mel;
+     641                 :            : 
+     642                 :          1 :         spdm_mel = (spdm_measurement_extension_log_dmtf_t *)m_libspdm_mel_test;
+     643                 :            : 
+     644                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     645                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     646                 :            : 
+     647                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+     648                 :          1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENT_EXTENSION_LOG;
+     649                 :          1 :         spdm_response->header.param1 = 0;
+     650                 :          1 :         spdm_response->header.param2 = 0;
+     651                 :            :         /* The total MEL length is larger than SPDM_MAX_MEASUREMENT_EXTENSION_LOG_SIZE*/
+     652                 :          1 :         spdm_response->portion_length = LIBSPDM_MAX_MEL_BLOCK_LEN;
+     653                 :          1 :         spdm_response->remainder_length = SPDM_MAX_MEASUREMENT_EXTENSION_LOG_SIZE;
+     654                 :            : 
+     655                 :          1 :         libspdm_copy_mem(spdm_response + 1,
+     656                 :          1 :                          (size_t)(*response) + *response_size - (size_t)(spdm_response + 1),
+     657                 :            :                          (uint8_t *)spdm_mel,
+     658                 :            :                          LIBSPDM_MAX_MEL_BLOCK_LEN);
+     659                 :            : 
+     660                 :          1 :         spdm_response_size = sizeof(spdm_measurement_extension_log_response_t) +
+     661                 :            :                              LIBSPDM_MAX_MEL_BLOCK_LEN;
+     662                 :            : 
+     663                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     664                 :            :                                               false, spdm_response_size,
+     665                 :            :                                               spdm_response, response_size,
+     666                 :            :                                               response);
+     667                 :            :     }
+     668                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     669                 :            : 
+     670                 :          0 :     default:
+     671                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+     672                 :            :     }
+     673                 :            : }
+     674                 :            : 
+     675                 :            : /**
+     676                 :            :  * Test 1: message could not be sent
+     677                 :            :  * Expected Behavior: get a LIBSPDM_STATUS_SEND_FAIL, with no MEL messages received
+     678                 :            :  **/
+     679                 :          1 : void libspdm_test_requester_get_measurement_extension_log_case1(void **state)
+     680                 :            : {
+     681                 :            :     libspdm_return_t status;
+     682                 :            :     libspdm_test_context_t *spdm_test_context;
+     683                 :            :     libspdm_context_t *spdm_context;
+     684                 :            :     size_t spdm_mel_size;
+     685                 :            :     uint8_t spdm_mel[LIBSPDM_MAX_MEASUREMENT_EXTENSION_LOG_SIZE];
+     686                 :            : 
+     687                 :          1 :     spdm_test_context = *state;
+     688                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     689                 :          1 :     spdm_test_context->case_id = 0x1;
+     690                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+     691                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     692                 :          1 :     spdm_context->connection_info.connection_state =
+     693                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     694                 :          1 :     spdm_context->connection_info.capability.flags |=
+     695                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEL_CAP;
+     696                 :            : 
+     697                 :          1 :     libspdm_reset_message_b(spdm_context);
+     698                 :            : 
+     699                 :          1 :     spdm_mel_size = sizeof(spdm_mel);
+     700                 :          1 :     libspdm_zero_mem(spdm_mel, sizeof(spdm_mel));
+     701                 :            : 
+     702                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     703                 :            :         m_libspdm_use_measurement_spec;
+     704                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     705                 :            :         m_libspdm_use_measurement_hash_algo;
+     706                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     707                 :            :         m_libspdm_use_hash_algo;
+     708                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     709                 :            :         m_libspdm_use_asym_algo;
+     710                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+     711                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     712                 :            : 
+     713                 :          1 :     status = libspdm_get_measurement_extension_log(spdm_context, NULL,
+     714                 :            :                                                    &spdm_mel_size, spdm_mel);
+     715                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SEND_FAIL);
+     716                 :          1 : }
+     717                 :            : 
+     718                 :            : /**
+     719                 :            :  * Test 2: Normal case, request a MEL, the MEL size remains unchanged
+     720                 :            :  * Expected Behavior: receives a valid MEL
+     721                 :            :  **/
+     722                 :          1 : void libspdm_test_requester_get_measurement_extension_log_case2(void **state)
+     723                 :            : {
+     724                 :            :     libspdm_return_t status;
+     725                 :            :     libspdm_test_context_t *spdm_test_context;
+     726                 :            :     libspdm_context_t *spdm_context;
+     727                 :            :     size_t spdm_mel_size;
+     728                 :            :     uint8_t spdm_mel[LIBSPDM_MAX_MEASUREMENT_EXTENSION_LOG_SIZE];
+     729                 :            : 
+     730                 :          1 :     spdm_test_context = *state;
+     731                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     732                 :          1 :     spdm_test_context->case_id = 0x2;
+     733                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+     734                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     735                 :          1 :     spdm_context->connection_info.connection_state =
+     736                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     737                 :          1 :     spdm_context->connection_info.capability.flags |=
+     738                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEL_CAP;
+     739                 :            : 
+     740                 :          1 :     libspdm_reset_message_b(spdm_context);
+     741                 :          1 :     spdm_mel_size = sizeof(spdm_mel);
+     742                 :          1 :     libspdm_zero_mem(spdm_mel, sizeof(spdm_mel));
+     743                 :            : 
+     744                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     745                 :            :         m_libspdm_use_measurement_spec;
+     746                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     747                 :            :         m_libspdm_use_measurement_hash_algo;
+     748                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     749                 :            :         m_libspdm_use_hash_algo;
+     750                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     751                 :            :         m_libspdm_use_asym_algo;
+     752                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+     753                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     754                 :            : 
+     755                 :          1 :     status = libspdm_get_measurement_extension_log(spdm_context, NULL,
+     756                 :            :                                                    &spdm_mel_size, spdm_mel);
+     757                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     758                 :          1 :     assert_int_equal(spdm_mel_size, m_libspdm_mel_len);
+     759                 :          1 : }
+     760                 :            : 
+     761                 :            : /**
+     762                 :            :  * Test 3: Normal case, request a MEL, the MEL size become more bigger when get MEL
+     763                 :            :  * The original MEL number is 3, the new MEL number is 4.
+     764                 :            :  * Expected Behavior: receives a valid MEL, and the MEL size is same with the before MEL size.
+     765                 :            :  **/
+     766                 :          1 : void libspdm_test_requester_get_measurement_extension_log_case3(void **state)
+     767                 :            : {
+     768                 :            :     libspdm_return_t status;
+     769                 :            :     libspdm_test_context_t *spdm_test_context;
+     770                 :            :     libspdm_context_t *spdm_context;
+     771                 :            :     size_t spdm_mel_size;
+     772                 :            :     uint8_t spdm_mel[LIBSPDM_MAX_MEASUREMENT_EXTENSION_LOG_SIZE];
+     773                 :            : 
+     774                 :          1 :     spdm_test_context = *state;
+     775                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     776                 :            : 
+     777                 :          1 :     spdm_test_context->case_id = 0x3;
+     778                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+     779                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     780                 :          1 :     spdm_context->connection_info.connection_state =
+     781                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     782                 :          1 :     spdm_context->connection_info.capability.flags |=
+     783                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEL_CAP;
+     784                 :            : 
+     785                 :          1 :     libspdm_reset_message_b(spdm_context);
+     786                 :          1 :     spdm_mel_size = sizeof(spdm_mel);
+     787                 :          1 :     libspdm_zero_mem(spdm_mel, sizeof(spdm_mel));
+     788                 :            : 
+     789                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     790                 :            :         m_libspdm_use_measurement_spec;
+     791                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     792                 :            :         m_libspdm_use_measurement_hash_algo;
+     793                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     794                 :            :         m_libspdm_use_hash_algo;
+     795                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     796                 :            :         m_libspdm_use_asym_algo;
+     797                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+     798                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     799                 :            : 
+     800                 :          1 :     status = libspdm_get_measurement_extension_log(spdm_context, NULL,
+     801                 :            :                                                    &spdm_mel_size, spdm_mel);
+     802                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     803                 :          1 :     assert_int_equal(spdm_mel_size, m_libspdm_mel_len);
+     804                 :          1 : }
+     805                 :            : 
+     806                 :            : /**
+     807                 :            :  * Test 4: Normal case, request a MEL, the MEL size become more bigger when get MEL
+     808                 :            :  * The original MEL number is 100, the new MEL number is 105.
+     809                 :            :  * Expected Behavior: receives a valid MEL, and the MEL size is same with the before MEL size.
+     810                 :            :  **/
+     811                 :          1 : void libspdm_test_requester_get_measurement_extension_log_case4(void **state)
+     812                 :            : {
+     813                 :            :     libspdm_return_t status;
+     814                 :            :     libspdm_test_context_t *spdm_test_context;
+     815                 :            :     libspdm_context_t *spdm_context;
+     816                 :            :     size_t spdm_mel_size;
+     817                 :            :     uint8_t spdm_mel[LIBSPDM_MAX_MEASUREMENT_EXTENSION_LOG_SIZE];
+     818                 :            : 
+     819                 :          1 :     spdm_test_context = *state;
+     820                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     821                 :          1 :     spdm_test_context->case_id = 0x4;
+     822                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+     823                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     824                 :          1 :     spdm_context->connection_info.connection_state =
+     825                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     826                 :          1 :     spdm_context->connection_info.capability.flags |=
+     827                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEL_CAP;
+     828                 :            : 
+     829                 :          1 :     libspdm_reset_message_b(spdm_context);
+     830                 :          1 :     spdm_mel_size = sizeof(spdm_mel);
+     831                 :          1 :     libspdm_zero_mem(spdm_mel, sizeof(spdm_mel));
+     832                 :            : 
+     833                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     834                 :            :         m_libspdm_use_measurement_spec;
+     835                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     836                 :            :         m_libspdm_use_measurement_hash_algo;
+     837                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     838                 :            :         m_libspdm_use_hash_algo;
+     839                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     840                 :            :         m_libspdm_use_asym_algo;
+     841                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+     842                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     843                 :            : 
+     844                 :          1 :     status = libspdm_get_measurement_extension_log(spdm_context, NULL,
+     845                 :            :                                                    &spdm_mel_size, spdm_mel);
+     846                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     847                 :          1 :     assert_int_equal(spdm_mel_size, m_libspdm_mel_len);
+     848                 :          1 : }
+     849                 :            : 
+     850                 :            : /**
+     851                 :            :  * Test 5: Normal case, request a MEL, the MEL size become more bigger when get MEL
+     852                 :            :  * The original MEL number is 100, the new MEL number is 200.
+     853                 :            :  * Expected Behavior: receives a valid MEL, and the MEL size is same with the before MEL size.
+     854                 :            :  **/
+     855                 :          1 : void libspdm_test_requester_get_measurement_extension_log_case5(void **state)
+     856                 :            : {
+     857                 :            :     libspdm_return_t status;
+     858                 :            :     libspdm_test_context_t *spdm_test_context;
+     859                 :            :     libspdm_context_t *spdm_context;
+     860                 :            :     size_t spdm_mel_size;
+     861                 :            :     uint8_t spdm_mel[LIBSPDM_MAX_MEASUREMENT_EXTENSION_LOG_SIZE];
+     862                 :            : 
+     863                 :          1 :     spdm_test_context = *state;
+     864                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     865                 :          1 :     spdm_test_context->case_id = 0x5;
+     866                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+     867                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     868                 :          1 :     spdm_context->connection_info.connection_state =
+     869                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     870                 :          1 :     spdm_context->connection_info.capability.flags |=
+     871                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEL_CAP;
+     872                 :            : 
+     873                 :          1 :     libspdm_reset_message_b(spdm_context);
+     874                 :          1 :     spdm_mel_size = sizeof(spdm_mel);
+     875                 :          1 :     libspdm_zero_mem(spdm_mel, sizeof(spdm_mel));
+     876                 :            : 
+     877                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     878                 :            :         m_libspdm_use_measurement_spec;
+     879                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     880                 :            :         m_libspdm_use_measurement_hash_algo;
+     881                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     882                 :            :         m_libspdm_use_hash_algo;
+     883                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     884                 :            :         m_libspdm_use_asym_algo;
+     885                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+     886                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     887                 :            : 
+     888                 :          1 :     status = libspdm_get_measurement_extension_log(spdm_context, NULL,
+     889                 :            :                                                    &spdm_mel_size, spdm_mel);
+     890                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     891                 :          1 :     assert_int_equal(spdm_mel_size, m_libspdm_mel_len);
+     892                 :          1 : }
+     893                 :            : 
+     894                 :            : /**
+     895                 :            :  * Test 6: Normal case, request a LIBSPDM_MAX_MEASUREMENT_EXTENSION_LOG_SIZE MEL
+     896                 :            :  * Expected Behavior: receives a valid MEL
+     897                 :            :  **/
+     898                 :          1 : void libspdm_test_requester_get_measurement_extension_log_case6(void **state)
+     899                 :            : {
+     900                 :            :     libspdm_return_t status;
+     901                 :            :     libspdm_test_context_t *spdm_test_context;
+     902                 :            :     libspdm_context_t *spdm_context;
+     903                 :            :     size_t spdm_mel_size;
+     904                 :            :     uint8_t spdm_mel[LIBSPDM_MAX_MEASUREMENT_EXTENSION_LOG_SIZE];
+     905                 :            :     size_t mel_buffer_size;
+     906                 :            : 
+     907                 :          1 :     spdm_test_context = *state;
+     908                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     909                 :          1 :     spdm_test_context->case_id = 0x6;
+     910                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+     911                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     912                 :          1 :     spdm_context->connection_info.connection_state =
+     913                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     914                 :          1 :     spdm_context->connection_info.capability.flags |=
+     915                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEL_CAP;
+     916                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     917                 :            :         m_libspdm_use_measurement_spec;
+     918                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     919                 :            :         m_libspdm_use_measurement_hash_algo;
+     920                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     921                 :            :         m_libspdm_use_hash_algo;
+     922                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     923                 :            :         m_libspdm_use_asym_algo;
+     924                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+     925                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     926                 :            : 
+     927                 :          1 :     libspdm_reset_message_b(spdm_context);
+     928                 :          1 :     spdm_mel_size = sizeof(spdm_mel);
+     929                 :          1 :     libspdm_zero_mem(spdm_mel, sizeof(spdm_mel));
+     930                 :            : 
+     931                 :          1 :     generate_mel_entry_test();
+     932                 :          1 :     mel_buffer_size = m_libspdm_mel_len;
+     933                 :            : 
+     934                 :          1 :     status = libspdm_get_measurement_extension_log(spdm_context, NULL,
+     935                 :            :                                                    &spdm_mel_size, spdm_mel);
+     936                 :            : 
+     937                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     938                 :          1 :     assert_int_equal(spdm_mel_size, mel_buffer_size);
+     939                 :          1 :     assert_memory_equal(m_libspdm_mel_test, (void *)spdm_mel, spdm_mel_size);
+     940                 :          1 : }
+     941                 :            : 
+     942                 :            : /**
+     943                 :            :  * Test 7: The total amount of messages actually sent by the responder is less than the negotiated total mel len.
+     944                 :            :  * Expected Behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
+     945                 :            :  **/
+     946                 :          1 : void libspdm_test_requester_get_measurement_extension_log_case7(void **state)
+     947                 :            : {
+     948                 :            :     libspdm_return_t status;
+     949                 :            :     libspdm_test_context_t *spdm_test_context;
+     950                 :            :     libspdm_context_t *spdm_context;
+     951                 :            :     size_t spdm_mel_size;
+     952                 :            :     uint8_t spdm_mel[LIBSPDM_MAX_MEASUREMENT_EXTENSION_LOG_SIZE];
+     953                 :            : 
+     954                 :          1 :     spdm_test_context = *state;
+     955                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     956                 :          1 :     spdm_test_context->case_id = 0x7;
+     957                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+     958                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     959                 :          1 :     spdm_context->connection_info.connection_state =
+     960                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     961                 :          1 :     spdm_context->connection_info.capability.flags |=
+     962                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEL_CAP;
+     963                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     964                 :            :         m_libspdm_use_measurement_spec;
+     965                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     966                 :            :         m_libspdm_use_measurement_hash_algo;
+     967                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     968                 :            :         m_libspdm_use_hash_algo;
+     969                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     970                 :            :         m_libspdm_use_asym_algo;
+     971                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+     972                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     973                 :            : 
+     974                 :          1 :     libspdm_reset_message_b(spdm_context);
+     975                 :          1 :     spdm_mel_size = sizeof(spdm_mel);
+     976                 :          1 :     libspdm_zero_mem(spdm_mel, sizeof(spdm_mel));
+     977                 :            : 
+     978                 :          1 :     generate_mel_entry_test();
+     979                 :            : 
+     980                 :          1 :     status = libspdm_get_measurement_extension_log(spdm_context, NULL,
+     981                 :            :                                                    &spdm_mel_size, spdm_mel);
+     982                 :            : 
+     983                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+     984                 :          1 : }
+     985                 :            : 
+     986                 :            : /**
+     987                 :            :  * Test 8: Portion_length is greater than the LIBSPDM_MAX_MEL_BLOCK_LEN
+     988                 :            :  * Expected Behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
+     989                 :            :  **/
+     990                 :          1 : void libspdm_test_requester_get_measurement_extension_log_case8(void **state)
+     991                 :            : {
+     992                 :            :     libspdm_return_t status;
+     993                 :            :     libspdm_test_context_t *spdm_test_context;
+     994                 :            :     libspdm_context_t *spdm_context;
+     995                 :            :     size_t spdm_mel_size;
+     996                 :            :     uint8_t spdm_mel[LIBSPDM_MAX_MEASUREMENT_EXTENSION_LOG_SIZE];
+     997                 :            : 
+     998                 :          1 :     spdm_test_context = *state;
+     999                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1000                 :          1 :     spdm_test_context->case_id = 0x8;
+    1001                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+    1002                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1003                 :          1 :     spdm_context->connection_info.connection_state =
+    1004                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    1005                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1006                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEL_CAP;
+    1007                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    1008                 :            :         m_libspdm_use_measurement_spec;
+    1009                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1010                 :            :         m_libspdm_use_measurement_hash_algo;
+    1011                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1012                 :            :         m_libspdm_use_hash_algo;
+    1013                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1014                 :            :         m_libspdm_use_asym_algo;
+    1015                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    1016                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1017                 :            : 
+    1018                 :          1 :     libspdm_reset_message_b(spdm_context);
+    1019                 :          1 :     spdm_mel_size = sizeof(spdm_mel);
+    1020                 :          1 :     libspdm_zero_mem(spdm_mel, sizeof(spdm_mel));
+    1021                 :            : 
+    1022                 :          1 :     generate_mel_entry_test();
+    1023                 :            : 
+    1024                 :          1 :     status = libspdm_get_measurement_extension_log(spdm_context, NULL,
+    1025                 :            :                                                    &spdm_mel_size, spdm_mel);
+    1026                 :            : 
+    1027                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1028                 :          1 : }
+    1029                 :            : 
+    1030                 :            : /**
+    1031                 :            :  * Test 9: The total MEL length is larger than SPDM_MAX_MEASUREMENT_EXTENSION_LOG_SIZE
+    1032                 :            :  * Expected Behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
+    1033                 :            :  **/
+    1034                 :          1 : void libspdm_test_requester_get_measurement_extension_log_case9(void **state)
+    1035                 :            : {
+    1036                 :            :     libspdm_return_t status;
+    1037                 :            :     libspdm_test_context_t *spdm_test_context;
+    1038                 :            :     libspdm_context_t *spdm_context;
+    1039                 :            :     size_t spdm_mel_size;
+    1040                 :            :     uint8_t spdm_mel[LIBSPDM_MAX_MEASUREMENT_EXTENSION_LOG_SIZE];
+    1041                 :            : 
+    1042                 :          1 :     spdm_test_context = *state;
+    1043                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1044                 :          1 :     spdm_test_context->case_id = 0x9;
+    1045                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+    1046                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1047                 :          1 :     spdm_context->connection_info.connection_state =
+    1048                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    1049                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1050                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEL_CAP;
+    1051                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    1052                 :            :         m_libspdm_use_measurement_spec;
+    1053                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1054                 :            :         m_libspdm_use_measurement_hash_algo;
+    1055                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1056                 :            :         m_libspdm_use_hash_algo;
+    1057                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1058                 :            :         m_libspdm_use_asym_algo;
+    1059                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    1060                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1061                 :            : 
+    1062                 :          1 :     libspdm_reset_message_b(spdm_context);
+    1063                 :          1 :     spdm_mel_size = sizeof(spdm_mel);
+    1064                 :          1 :     libspdm_zero_mem(spdm_mel, sizeof(spdm_mel));
+    1065                 :            : 
+    1066                 :          1 :     generate_mel_entry_test();
+    1067                 :            : 
+    1068                 :          1 :     status = libspdm_get_measurement_extension_log(spdm_context, NULL,
+    1069                 :            :                                                    &spdm_mel_size, spdm_mel);
+    1070                 :            : 
+    1071                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1072                 :          1 : }
+    1073                 :            : 
+    1074                 :            : libspdm_test_context_t m_libspdm_requester_get_measurement_extension_log_test_context = {
+    1075                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+    1076                 :            :     true,
+    1077                 :            :     libspdm_requester_get_measurement_extension_log_test_send_message,
+    1078                 :            :     libspdm_requester_get_measurement_extension_log_test_receive_message,
+    1079                 :            : };
+    1080                 :            : 
+    1081                 :          1 : int libspdm_requester_get_measurement_extension_log_test_main(void)
+    1082                 :            : {
+    1083                 :          1 :     const struct CMUnitTest spdm_requester_get_measurement_extension_log_tests[] = {
+    1084                 :            :         /* SendRequest failed*/
+    1085                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurement_extension_log_case1),
+    1086                 :            :         /* Successful response, the MEL size remains unchanged*/
+    1087                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurement_extension_log_case2),
+    1088                 :            :         /* Successful response, the MEL size become more bigger when get MEL. MEL number change from 3 to 4*/
+    1089                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurement_extension_log_case3),
+    1090                 :            :         /* Successful response, the MEL size become more bigger when get MEL. MEL number change from 100 to 105*/
+    1091                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurement_extension_log_case4),
+    1092                 :            :         /* Successful response, the MEL size become more bigger when get MEL. MEL number change from 100 to 200*/
+    1093                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurement_extension_log_case5),
+    1094                 :            :         /* Successful response , LIBSPDM_MAX_MEASUREMENT_EXTENSION_LOG_SIZE*/
+    1095                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurement_extension_log_case6),
+    1096                 :            :         /* Failed response , The total amount of messages actually sent by the responder is less than the negotiated total mel len*/
+    1097                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurement_extension_log_case7),
+    1098                 :            :         /* Failed response , Portion_length is greater than the LIBSPDM_MAX_MEL_BLOCK_LEN*/
+    1099                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurement_extension_log_case8),
+    1100                 :            :         /* Failed response , The total MEL length is larger than SPDM_MAX_MEASUREMENT_EXTENSION_LOG_SIZE*/
+    1101                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurement_extension_log_case9),
+    1102                 :            : 
+    1103                 :            :     };
+    1104                 :            : 
+    1105                 :          1 :     libspdm_setup_test_context(&m_libspdm_requester_get_measurement_extension_log_test_context);
+    1106                 :            : 
+    1107                 :          1 :     return cmocka_run_group_tests(spdm_requester_get_measurement_extension_log_tests,
+    1108                 :            :                                   libspdm_unit_test_group_setup,
+    1109                 :            :                                   libspdm_unit_test_group_teardown);
+    1110                 :            : }
+    1111                 :            : 
+    1112                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEL_CAP */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/get_measurements.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_requester/get_measurements.c.func-sort-c.html new file mode 100644 index 00000000000..179b21e965e --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/get_measurements.c.func-sort-c.html @@ -0,0 +1,261 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/get_measurements.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - get_measurements.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:2586271395.3 %
Date:2024-09-22 08:21:07Functions:4545100.0 %
Branches:13215784.1 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_get_measurements_test_main1
libspdm_test_requester_get_measurements_case11
libspdm_test_requester_get_measurements_case101
libspdm_test_requester_get_measurements_case111
libspdm_test_requester_get_measurements_case121
libspdm_test_requester_get_measurements_case131
libspdm_test_requester_get_measurements_case141
libspdm_test_requester_get_measurements_case151
libspdm_test_requester_get_measurements_case161
libspdm_test_requester_get_measurements_case171
libspdm_test_requester_get_measurements_case181
libspdm_test_requester_get_measurements_case191
libspdm_test_requester_get_measurements_case21
libspdm_test_requester_get_measurements_case201
libspdm_test_requester_get_measurements_case211
libspdm_test_requester_get_measurements_case221
libspdm_test_requester_get_measurements_case231
libspdm_test_requester_get_measurements_case241
libspdm_test_requester_get_measurements_case251
libspdm_test_requester_get_measurements_case261
libspdm_test_requester_get_measurements_case271
libspdm_test_requester_get_measurements_case281
libspdm_test_requester_get_measurements_case291
libspdm_test_requester_get_measurements_case31
libspdm_test_requester_get_measurements_case301
libspdm_test_requester_get_measurements_case311
libspdm_test_requester_get_measurements_case321
libspdm_test_requester_get_measurements_case331
libspdm_test_requester_get_measurements_case341
libspdm_test_requester_get_measurements_case351
libspdm_test_requester_get_measurements_case361
libspdm_test_requester_get_measurements_case371
libspdm_test_requester_get_measurements_case381
libspdm_test_requester_get_measurements_case391
libspdm_test_requester_get_measurements_case41
libspdm_test_requester_get_measurements_case401
libspdm_test_requester_get_measurements_case411
libspdm_test_requester_get_measurements_case51
libspdm_test_requester_get_measurements_case61
libspdm_test_requester_get_measurements_case71
libspdm_test_requester_get_measurements_case81
libspdm_test_requester_get_measurements_case91
libspdm_test_get_measurement_request_size160
libspdm_requester_get_measurements_test_receive_message161
libspdm_requester_get_measurements_test_send_message162
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/get_measurements.c.func.html b/coverage_log/unit_test/test_spdm_requester/get_measurements.c.func.html new file mode 100644 index 00000000000..8309ca6a555 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/get_measurements.c.func.html @@ -0,0 +1,261 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/get_measurements.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - get_measurements.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:2586271395.3 %
Date:2024-09-22 08:21:07Functions:4545100.0 %
Branches:13215784.1 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_get_measurements_test_main1
libspdm_requester_get_measurements_test_receive_message161
libspdm_requester_get_measurements_test_send_message162
libspdm_test_get_measurement_request_size160
libspdm_test_requester_get_measurements_case11
libspdm_test_requester_get_measurements_case101
libspdm_test_requester_get_measurements_case111
libspdm_test_requester_get_measurements_case121
libspdm_test_requester_get_measurements_case131
libspdm_test_requester_get_measurements_case141
libspdm_test_requester_get_measurements_case151
libspdm_test_requester_get_measurements_case161
libspdm_test_requester_get_measurements_case171
libspdm_test_requester_get_measurements_case181
libspdm_test_requester_get_measurements_case191
libspdm_test_requester_get_measurements_case21
libspdm_test_requester_get_measurements_case201
libspdm_test_requester_get_measurements_case211
libspdm_test_requester_get_measurements_case221
libspdm_test_requester_get_measurements_case231
libspdm_test_requester_get_measurements_case241
libspdm_test_requester_get_measurements_case251
libspdm_test_requester_get_measurements_case261
libspdm_test_requester_get_measurements_case271
libspdm_test_requester_get_measurements_case281
libspdm_test_requester_get_measurements_case291
libspdm_test_requester_get_measurements_case31
libspdm_test_requester_get_measurements_case301
libspdm_test_requester_get_measurements_case311
libspdm_test_requester_get_measurements_case321
libspdm_test_requester_get_measurements_case331
libspdm_test_requester_get_measurements_case341
libspdm_test_requester_get_measurements_case351
libspdm_test_requester_get_measurements_case361
libspdm_test_requester_get_measurements_case371
libspdm_test_requester_get_measurements_case381
libspdm_test_requester_get_measurements_case391
libspdm_test_requester_get_measurements_case41
libspdm_test_requester_get_measurements_case401
libspdm_test_requester_get_measurements_case411
libspdm_test_requester_get_measurements_case51
libspdm_test_requester_get_measurements_case61
libspdm_test_requester_get_measurements_case71
libspdm_test_requester_get_measurements_case81
libspdm_test_requester_get_measurements_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/get_measurements.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/get_measurements.c.gcov.html new file mode 100644 index 00000000000..27cc96722a3 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/get_measurements.c.gcov.html @@ -0,0 +1,6552 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/get_measurements.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - get_measurements.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:2586271395.3 %
Date:2024-09-22 08:21:07Functions:4545100.0 %
Branches:13215784.1 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_requester_lib.h"
+       9                 :            : #include "internal/libspdm_secured_message_lib.h"
+      10                 :            : 
+      11                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
+      12                 :            : 
+      13                 :            : #define LIBSPDM_ALTERNATIVE_DEFAULT_SLOT_ID 2
+      14                 :            : #define LIBSPDM_LARGE_MEASUREMENT_SIZE ((1 << 24) - 1)
+      15                 :            : 
+      16                 :            : static size_t m_libspdm_local_buffer_size;
+      17                 :            : static uint8_t m_libspdm_local_buffer[LIBSPDM_MAX_MESSAGE_L1L2_BUFFER_SIZE];
+      18                 :            : static uint8_t m_libspdm_msg_log_buffer[LIBSPDM_MAX_MESSAGE_L1L2_BUFFER_SIZE * 2];
+      19                 :            : 
+      20                 :            : static size_t m_libspdm_opaque_data_size;
+      21                 :            : static uint8_t m_libspdm_opaque_data[SPDM_MAX_OPAQUE_DATA_SIZE];
+      22                 :            : 
+      23                 :            : static uint8_t m_requester_context[SPDM_REQ_CONTEXT_SIZE];
+      24                 :            : 
+      25                 :        160 : static size_t libspdm_test_get_measurement_request_size(const void *spdm_context,
+      26                 :            :                                                         const void *buffer,
+      27                 :            :                                                         size_t buffer_size)
+      28                 :            : {
+      29                 :            :     const spdm_get_measurements_request_t *spdm_request;
+      30                 :            :     size_t message_size;
+      31                 :            : 
+      32                 :        160 :     spdm_request = buffer;
+      33                 :        160 :     message_size = sizeof(spdm_message_header_t);
+      34         [ -  + ]:        160 :     if (buffer_size < message_size) {
+      35                 :          0 :         return buffer_size;
+      36                 :            :     }
+      37                 :            : 
+      38         [ +  + ]:        160 :     if (spdm_request->header.request_response_code !=
+      39                 :            :         SPDM_GET_MEASUREMENTS) {
+      40                 :          2 :         return buffer_size;
+      41                 :            :     }
+      42                 :            : 
+      43         [ +  + ]:        158 :     if ((spdm_request->header.param1 &
+      44                 :            :          SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE) != 0) {
+      45         [ +  - ]:         42 :         if (spdm_request->header.spdm_version >=
+      46                 :            :             SPDM_MESSAGE_VERSION_11) {
+      47         [ -  + ]:         42 :             if (buffer_size <
+      48                 :            :                 sizeof(spdm_get_measurements_request_t)) {
+      49                 :          0 :                 return buffer_size;
+      50                 :            :             }
+      51                 :         42 :             message_size = sizeof(spdm_get_measurements_request_t);
+      52                 :            :         } else {
+      53         [ #  # ]:          0 :             if (buffer_size <
+      54                 :            :                 sizeof(spdm_get_measurements_request_t) -
+      55                 :            :                 sizeof(spdm_request->slot_id_param)) {
+      56                 :          0 :                 return buffer_size;
+      57                 :            :             }
+      58                 :          0 :             message_size = sizeof(spdm_get_measurements_request_t) -
+      59                 :            :                            sizeof(spdm_request->slot_id_param);
+      60                 :            :         }
+      61                 :            :     } else {
+      62                 :            :         /* already checked before if buffer_size < sizeof(spdm_message_header_t)*/
+      63                 :        116 :         message_size = sizeof(spdm_message_header_t);
+      64                 :            :     }
+      65                 :            : 
+      66                 :            :     /* Good message, return actual size*/
+      67                 :        158 :     return message_size;
+      68                 :            : }
+      69                 :            : 
+      70                 :        162 : static libspdm_return_t libspdm_requester_get_measurements_test_send_message(
+      71                 :            :     void *spdm_context, size_t request_size, const void *request,
+      72                 :            :     uint64_t timeout)
+      73                 :            : {
+      74                 :            :     libspdm_test_context_t *spdm_test_context;
+      75                 :            :     size_t header_size;
+      76                 :            :     size_t message_size;
+      77                 :            :     uint32_t *session_id;
+      78                 :            :     libspdm_session_info_t *session_info;
+      79                 :            :     bool is_app_message;
+      80                 :            :     uint8_t *app_message;
+      81                 :            :     size_t app_message_size;
+      82                 :            :     uint8_t message_buffer[LIBSPDM_SENDER_BUFFER_SIZE];
+      83                 :            : 
+      84                 :        162 :     memcpy(message_buffer, request, request_size);
+      85                 :            : 
+      86                 :        162 :     spdm_test_context = libspdm_get_test_context();
+      87                 :        162 :     header_size = sizeof(libspdm_test_message_header_t);
+      88   [ +  +  +  +  :        162 :     switch (spdm_test_context->case_id) {
+          +  +  +  +  +  
+          +  +  +  +  +  
+          +  +  +  -  +  
+          +  +  +  +  +  
+          +  +  +  +  +  
+          -  -  +  +  +  
+          +  +  +  +  +  
+                   +  - ]
+      89                 :          1 :     case 0x1:
+      90                 :          1 :         return LIBSPDM_STATUS_SEND_FAIL;
+      91                 :          1 :     case 0x2:
+      92                 :          1 :         m_libspdm_local_buffer_size = 0;
+      93                 :          1 :         message_size = libspdm_test_get_measurement_request_size(
+      94                 :            :             spdm_context, (const uint8_t *)request + header_size,
+      95                 :            :             request_size - header_size);
+      96                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+      97                 :            :                          (const uint8_t *)request + header_size, message_size);
+      98                 :          1 :         m_libspdm_local_buffer_size += message_size;
+      99                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     100                 :          1 :     case 0x3:
+     101                 :          1 :         m_libspdm_local_buffer_size = 0;
+     102                 :          1 :         message_size = libspdm_test_get_measurement_request_size(
+     103                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     104                 :            :             request_size - header_size);
+     105                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     106                 :            :                          (const uint8_t *)request + header_size, message_size);
+     107                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     108                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     109                 :          1 :     case 0x4:
+     110                 :          1 :         m_libspdm_local_buffer_size = 0;
+     111                 :          1 :         message_size = libspdm_test_get_measurement_request_size(
+     112                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     113                 :            :             request_size - header_size);
+     114                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     115                 :            :                          (const uint8_t *)request + header_size, message_size);
+     116                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     117                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     118                 :          1 :     case 0x5:
+     119                 :          1 :         m_libspdm_local_buffer_size = 0;
+     120                 :          1 :         message_size = libspdm_test_get_measurement_request_size(
+     121                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     122                 :            :             request_size - header_size);
+     123                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     124                 :            :                          (const uint8_t *)request + header_size, message_size);
+     125                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     126                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     127                 :          2 :     case 0x6:
+     128                 :          2 :         m_libspdm_local_buffer_size = 0;
+     129                 :          2 :         message_size = libspdm_test_get_measurement_request_size(
+     130                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     131                 :            :             request_size - header_size);
+     132                 :          2 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     133                 :            :                          (const uint8_t *)request + header_size, message_size);
+     134                 :          2 :         m_libspdm_local_buffer_size += message_size;
+     135                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     136                 :          1 :     case 0x7:
+     137                 :          1 :         m_libspdm_local_buffer_size = 0;
+     138                 :          1 :         message_size = libspdm_test_get_measurement_request_size(
+     139                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     140                 :            :             request_size - header_size);
+     141                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     142                 :            :                          (const uint8_t *)request + header_size, message_size);
+     143                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     144                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     145                 :          2 :     case 0x8:
+     146                 :          2 :         m_libspdm_local_buffer_size = 0;
+     147                 :          2 :         message_size = libspdm_test_get_measurement_request_size(
+     148                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     149                 :            :             request_size - header_size);
+     150                 :          2 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     151                 :            :                          (const uint8_t *)request + header_size, message_size);
+     152                 :          2 :         m_libspdm_local_buffer_size += message_size;
+     153                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     154                 :          2 :     case 0x9: {
+     155                 :            :         static size_t sub_index = 0;
+     156         [ +  + ]:          2 :         if (sub_index == 0) {
+     157                 :          1 :             m_libspdm_local_buffer_size = 0;
+     158                 :          1 :             message_size = libspdm_test_get_measurement_request_size(
+     159                 :            :                 spdm_context, (const uint8_t *)request + header_size,
+     160                 :            :                 request_size - header_size);
+     161                 :          1 :             libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     162                 :            :                              (const uint8_t *)request + header_size,
+     163                 :            :                              message_size);
+     164                 :          1 :             m_libspdm_local_buffer_size += message_size;
+     165                 :          1 :             sub_index++;
+     166                 :            :         }
+     167                 :            :     }
+     168                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     169                 :          1 :     case 0xA:
+     170                 :          1 :         m_libspdm_local_buffer_size = 0;
+     171                 :          1 :         message_size = libspdm_test_get_measurement_request_size(
+     172                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     173                 :            :             request_size - header_size);
+     174                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     175                 :            :                          (const uint8_t *)request + header_size, message_size);
+     176                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     177                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     178                 :          1 :     case 0xB:
+     179                 :          1 :         m_libspdm_local_buffer_size = 0;
+     180                 :          1 :         message_size = libspdm_test_get_measurement_request_size(
+     181                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     182                 :            :             request_size - header_size);
+     183                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     184                 :            :                          (const uint8_t *)request + header_size, message_size);
+     185                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     186                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     187                 :          1 :     case 0xC:
+     188                 :          1 :         m_libspdm_local_buffer_size = 0;
+     189                 :          1 :         message_size = libspdm_test_get_measurement_request_size(
+     190                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     191                 :            :             request_size - header_size);
+     192                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     193                 :            :                          (const uint8_t *)request + header_size, message_size);
+     194                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     195                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     196                 :          1 :     case 0xD:
+     197                 :          1 :         m_libspdm_local_buffer_size = 0;
+     198                 :          1 :         message_size = libspdm_test_get_measurement_request_size(
+     199                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     200                 :            :             request_size - header_size);
+     201                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     202                 :            :                          (const uint8_t *)request + header_size, message_size);
+     203                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     204                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     205                 :          1 :     case 0xE:
+     206                 :          1 :         m_libspdm_local_buffer_size = 0;
+     207                 :          1 :         message_size = libspdm_test_get_measurement_request_size(
+     208                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     209                 :            :             request_size - header_size);
+     210                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     211                 :            :                          (const uint8_t *)request + header_size, message_size);
+     212                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     213                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     214                 :          1 :     case 0xF:
+     215                 :          1 :         m_libspdm_local_buffer_size = 0;
+     216                 :          1 :         message_size = libspdm_test_get_measurement_request_size(
+     217                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     218                 :            :             request_size - header_size);
+     219                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     220                 :            :                          (const uint8_t *)request + header_size, message_size);
+     221                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     222                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     223                 :          4 :     case 0x10:
+     224                 :          4 :         m_libspdm_local_buffer_size = 0;
+     225                 :          4 :         message_size = libspdm_test_get_measurement_request_size(
+     226                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     227                 :            :             request_size - header_size);
+     228                 :          4 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     229                 :            :                          (const uint8_t *)request + header_size, message_size);
+     230                 :          4 :         m_libspdm_local_buffer_size += message_size;
+     231                 :          4 :         return LIBSPDM_STATUS_SUCCESS;
+     232                 :          3 :     case 0x11:
+     233                 :          3 :         m_libspdm_local_buffer_size = 0;
+     234                 :          3 :         message_size = libspdm_test_get_measurement_request_size(
+     235                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     236                 :            :             request_size - header_size);
+     237                 :          3 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     238                 :            :                          (const uint8_t *)request + header_size, message_size);
+     239                 :          3 :         m_libspdm_local_buffer_size += message_size;
+     240                 :          3 :         return LIBSPDM_STATUS_SUCCESS;
+     241                 :          0 :     case 0x12:
+     242                 :          0 :         m_libspdm_local_buffer_size = 0;
+     243                 :          0 :         message_size = libspdm_test_get_measurement_request_size(
+     244                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     245                 :            :             request_size - header_size);
+     246                 :          0 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     247                 :            :                          (const uint8_t *)request + header_size, message_size);
+     248                 :          0 :         m_libspdm_local_buffer_size += message_size;
+     249                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     250                 :          1 :     case 0x13:
+     251                 :          1 :         m_libspdm_local_buffer_size = 0;
+     252                 :          1 :         message_size = libspdm_test_get_measurement_request_size(
+     253                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     254                 :            :             request_size - header_size);
+     255                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     256                 :            :                          (const uint8_t *)request + header_size, message_size);
+     257                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     258                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     259                 :          1 :     case 0x14:
+     260                 :          1 :         m_libspdm_local_buffer_size = 0;
+     261                 :          1 :         message_size = libspdm_test_get_measurement_request_size(
+     262                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     263                 :            :             request_size - header_size);
+     264                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     265                 :            :                          (const uint8_t *)request + header_size, message_size);
+     266                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     267                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     268                 :          1 :     case 0x15:
+     269                 :          1 :         m_libspdm_local_buffer_size = 0;
+     270                 :          1 :         message_size = libspdm_test_get_measurement_request_size(
+     271                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     272                 :            :             request_size - header_size);
+     273                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     274                 :            :                          (const uint8_t *)request + header_size, message_size);
+     275                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     276                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     277                 :        100 :     case 0x16:
+     278                 :        100 :         m_libspdm_local_buffer_size = 0;
+     279                 :        100 :         message_size = libspdm_test_get_measurement_request_size(
+     280                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     281                 :            :             request_size - header_size);
+     282                 :        100 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     283                 :            :                          (const uint8_t *)request + header_size, message_size);
+     284                 :        100 :         m_libspdm_local_buffer_size += message_size;
+     285                 :        100 :         return LIBSPDM_STATUS_SUCCESS;
+     286                 :          1 :     case 0x17:
+     287                 :          1 :         m_libspdm_local_buffer_size = 0;
+     288                 :          1 :         message_size = libspdm_test_get_measurement_request_size(
+     289                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     290                 :            :             request_size - header_size);
+     291                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     292                 :            :                          (const uint8_t *)request + header_size, message_size);
+     293                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     294                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     295                 :          1 :     case 0x18:
+     296                 :          1 :         m_libspdm_local_buffer_size = 0;
+     297                 :          1 :         message_size = libspdm_test_get_measurement_request_size(
+     298                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     299                 :            :             request_size - header_size);
+     300                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     301                 :            :                          (const uint8_t *)request + header_size, message_size);
+     302                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     303                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     304                 :          1 :     case 0x19:
+     305                 :          1 :         m_libspdm_local_buffer_size = 0;
+     306                 :          1 :         message_size = libspdm_test_get_measurement_request_size(
+     307                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     308                 :            :             request_size - header_size);
+     309                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     310                 :            :                          (const uint8_t *)request + header_size, message_size);
+     311                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     312                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     313                 :          1 :     case 0x1A:
+     314                 :          1 :         m_libspdm_local_buffer_size = 0;
+     315                 :          1 :         message_size = libspdm_test_get_measurement_request_size(
+     316                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     317                 :            :             request_size - header_size);
+     318                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     319                 :            :                          (const uint8_t *)request + header_size, message_size);
+     320                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     321                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     322                 :          1 :     case 0x1B:
+     323                 :          1 :         m_libspdm_local_buffer_size = 0;
+     324                 :          1 :         message_size = libspdm_test_get_measurement_request_size(
+     325                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     326                 :            :             request_size - header_size);
+     327                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     328                 :            :                          (const uint8_t *)request + header_size, message_size);
+     329                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     330                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     331                 :          1 :     case 0x1C:
+     332                 :          1 :         m_libspdm_local_buffer_size = 0;
+     333                 :          1 :         message_size = libspdm_test_get_measurement_request_size(
+     334                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     335                 :            :             request_size - header_size);
+     336                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     337                 :            :                          (const uint8_t *)request + header_size, message_size);
+     338                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     339                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     340                 :          1 :     case 0x1D:
+     341                 :          1 :         m_libspdm_local_buffer_size = 0;
+     342                 :          1 :         message_size = libspdm_test_get_measurement_request_size(
+     343                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     344                 :            :             request_size - header_size);
+     345                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     346                 :            :                          (const uint8_t *)request + header_size, message_size);
+     347                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     348                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     349                 :          0 :     case 0x1E:
+     350                 :          0 :         m_libspdm_local_buffer_size = 0;
+     351                 :          0 :         message_size = libspdm_test_get_measurement_request_size(
+     352                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     353                 :            :             request_size - header_size);
+     354                 :          0 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     355                 :            :                          (const uint8_t *)request + header_size, message_size);
+     356                 :          0 :         m_libspdm_local_buffer_size += message_size;
+     357                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     358                 :          0 :     case 0x1F:
+     359                 :          0 :         m_libspdm_local_buffer_size = 0;
+     360                 :          0 :         message_size = libspdm_test_get_measurement_request_size(
+     361                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     362                 :            :             request_size - header_size);
+     363                 :          0 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     364                 :            :                          (const uint8_t *)request + header_size, message_size);
+     365                 :          0 :         m_libspdm_local_buffer_size += message_size;
+     366                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     367                 :          1 :     case 0x20:
+     368                 :          1 :         m_libspdm_local_buffer_size = 0;
+     369                 :          1 :         message_size = libspdm_test_get_measurement_request_size(
+     370                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     371                 :            :             request_size - header_size);
+     372                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     373                 :            :                          (const uint8_t *)request + header_size, message_size);
+     374                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     375                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     376                 :         18 :     case 0x21:
+     377                 :         18 :         m_libspdm_local_buffer_size = 0;
+     378                 :         18 :         message_size = libspdm_test_get_measurement_request_size(
+     379                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     380                 :            :             request_size - header_size);
+     381                 :         18 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     382                 :            :                          (const uint8_t *)request + header_size, message_size);
+     383                 :         18 :         m_libspdm_local_buffer_size += message_size;
+     384                 :         18 :         return LIBSPDM_STATUS_SUCCESS;
+     385                 :          1 :     case 0x22:
+     386                 :          1 :         m_libspdm_local_buffer_size = 0;
+     387                 :          1 :         session_id = NULL;
+     388                 :          1 :         session_info = libspdm_get_session_info_via_session_id(
+     389                 :            :             spdm_context, 0xFFFFFFFF);
+     390                 :          1 :         message_size = libspdm_test_get_measurement_request_size(
+     391                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     392                 :            :             request_size - header_size);
+     393                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "Request (0x%zx):\n",
+     394                 :            :                        request_size));
+     395                 :          1 :         libspdm_dump_hex(request, request_size);
+     396                 :          1 :         libspdm_get_scratch_buffer (spdm_context, (void **)&app_message, &app_message_size);
+     397                 :          1 :         libspdm_transport_test_decode_message(
+     398                 :            :             spdm_context, &session_id, &is_app_message,
+     399                 :            :             false, request_size, message_buffer,
+     400                 :            :             &app_message_size, (void **)&app_message);
+     401                 :            :         ((libspdm_secured_message_context_t
+     402                 :          1 :           *)(session_info->secured_message_context))
+     403                 :          1 :         ->application_secret.response_data_sequence_number--;
+     404                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     405                 :            :                          app_message, app_message_size);
+     406                 :          1 :         m_libspdm_local_buffer_size += app_message_size;
+     407                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     408                 :          1 :     case 0x23:
+     409                 :            :         /* m_libspdm_local_buffer_size is set by case35 and already contains the arbitrary fill
+     410                 :            :          * data. */
+     411                 :          1 :         message_size = libspdm_test_get_measurement_request_size(
+     412                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     413                 :            :             request_size - header_size);
+     414                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer + m_libspdm_local_buffer_size,
+     415                 :            :                          sizeof(m_libspdm_local_buffer),
+     416                 :            :                          (const uint8_t *)request + header_size, message_size);
+     417                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     418                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     419                 :          1 :     case 0x24:
+     420                 :          1 :         m_libspdm_local_buffer_size = 0;
+     421                 :          1 :         message_size = libspdm_test_get_measurement_request_size(
+     422                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     423                 :            :             request_size - header_size);
+     424                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     425                 :            :                          (const uint8_t *)request + header_size, message_size);
+     426                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     427                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     428                 :          1 :     case 0x25:
+     429                 :          1 :         m_libspdm_local_buffer_size = 0;
+     430                 :          1 :         message_size = libspdm_test_get_measurement_request_size(
+     431                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     432                 :            :             request_size - header_size);
+     433                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     434                 :            :                          (const uint8_t *)request + header_size, message_size);
+     435                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     436                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     437                 :          1 :     case 0x26:
+     438                 :          1 :         m_libspdm_local_buffer_size = 0;
+     439                 :          1 :         message_size = libspdm_test_get_measurement_request_size(
+     440                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     441                 :            :             request_size - header_size);
+     442                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     443                 :            :                          (const uint8_t *)request + header_size, message_size);
+     444                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     445                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     446                 :          1 :     case 0x27:
+     447                 :          1 :         m_libspdm_local_buffer_size = 0;
+     448                 :          1 :         message_size = libspdm_test_get_measurement_request_size(
+     449                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     450                 :            :             request_size - header_size);
+     451                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     452                 :            :                          (const uint8_t *)request + header_size, message_size);
+     453                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     454                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     455                 :          2 :     case 0x28:
+     456                 :            :     case 0x29:
+     457                 :          2 :         m_libspdm_local_buffer_size = 0;
+     458                 :          2 :         message_size = libspdm_test_get_measurement_request_size(
+     459                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     460                 :            :             request_size - header_size);
+     461                 :          2 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     462                 :            :                          (const uint8_t *)request + header_size, message_size);
+     463                 :          2 :         m_libspdm_local_buffer_size += message_size;
+     464                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     465                 :          0 :     default:
+     466                 :          0 :         return LIBSPDM_STATUS_SEND_FAIL;
+     467                 :            :     }
+     468                 :            : }
+     469                 :            : 
+     470                 :        161 : static libspdm_return_t libspdm_requester_get_measurements_test_receive_message(
+     471                 :            :     void *spdm_context, size_t *response_size,
+     472                 :            :     void **response, uint64_t timeout)
+     473                 :            : {
+     474                 :            :     libspdm_test_context_t *spdm_test_context;
+     475                 :            :     libspdm_return_t status;
+     476                 :            : 
+     477                 :        161 :     spdm_test_context = libspdm_get_test_context();
+     478   [ -  +  +  +  :        161 :     switch (spdm_test_context->case_id) {
+          +  +  +  +  +  
+          +  +  +  +  +  
+          +  +  +  -  +  
+          +  +  +  +  +  
+          +  +  +  +  +  
+          -  -  +  +  +  
+          +  +  +  +  +  
+                +  +  - ]
+     479                 :          0 :     case 0x1:
+     480                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+     481                 :            : 
+     482                 :          1 :     case 0x2: {
+     483                 :            :         spdm_measurements_response_t *spdm_response;
+     484                 :            :         uint8_t *ptr;
+     485                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     486                 :            :         size_t sig_size;
+     487                 :            :         size_t measurment_sig_size;
+     488                 :            :         spdm_measurement_block_dmtf_t *measurment_block;
+     489                 :            :         size_t spdm_response_size;
+     490                 :            :         size_t transport_header_size;
+     491                 :            : 
+     492                 :            :         ((libspdm_context_t *)spdm_context)
+     493                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+     494                 :            :             m_libspdm_use_asym_algo;
+     495                 :            :         ((libspdm_context_t *)spdm_context)
+     496                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+     497                 :            :             m_libspdm_use_hash_algo;
+     498                 :            :         ((libspdm_context_t *)spdm_context)
+     499                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+     500                 :            :             m_libspdm_use_measurement_hash_algo;
+     501                 :          1 :         measurment_sig_size =
+     502                 :            :             SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
+     503                 :          1 :             libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+     504                 :          1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
+     505                 :            :                              sizeof(spdm_measurement_block_dmtf_t) +
+     506                 :          1 :                              libspdm_get_measurement_hash_size(
+     507                 :          1 :             m_libspdm_use_measurement_hash_algo) +
+     508                 :            :                              measurment_sig_size;
+     509                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     510                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     511                 :            : 
+     512                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     513                 :          1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
+     514                 :          1 :         spdm_response->header.param1 = 0;
+     515                 :          1 :         spdm_response->header.param2 = 0;
+     516                 :          1 :         spdm_response->number_of_blocks = 1;
+     517                 :          1 :         libspdm_write_uint24(
+     518                 :          1 :             spdm_response->measurement_record_length,
+     519                 :            :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
+     520                 :          1 :                        libspdm_get_measurement_hash_size(
+     521                 :            :                            m_libspdm_use_measurement_hash_algo)));
+     522                 :          1 :         measurment_block = (void *)(spdm_response + 1);
+     523                 :          1 :         libspdm_set_mem(measurment_block,
+     524                 :            :                         sizeof(spdm_measurement_block_dmtf_t) +
+     525                 :          1 :                         libspdm_get_measurement_hash_size(
+     526                 :            :                             m_libspdm_use_measurement_hash_algo),
+     527                 :            :                         1);
+     528                 :            :         measurment_block->measurement_block_common_header
+     529                 :          1 :         .measurement_specification =
+     530                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     531                 :            :         measurment_block->measurement_block_common_header
+     532                 :          1 :         .measurement_size =
+     533                 :          1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
+     534                 :          1 :                        libspdm_get_measurement_hash_size(
+     535                 :            :                            m_libspdm_use_measurement_hash_algo));
+     536                 :          1 :         ptr = (void *)((uint8_t *)spdm_response + spdm_response_size -
+     537                 :            :                        measurment_sig_size);
+     538                 :          1 :         libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
+     539                 :          1 :         ptr += SPDM_NONCE_SIZE;
+     540                 :          1 :         *(uint16_t *)ptr = 0;
+     541                 :          1 :         ptr += sizeof(uint16_t);
+     542                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+     543                 :            :                          sizeof(m_libspdm_local_buffer)
+     544                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+     545                 :            :                             m_libspdm_local_buffer),
+     546                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+     547                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+     548                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+     549                 :            :                        m_libspdm_local_buffer_size));
+     550                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+     551                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
+     552                 :            :                          m_libspdm_local_buffer_size, hash_data);
+     553                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
+     554                 :            :                        libspdm_get_hash_size(m_libspdm_use_hash_algo)));
+     555                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+     556                 :          1 :         sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+     557                 :          1 :         libspdm_responder_data_sign(
+     558                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+     559                 :            :             spdm_context,
+     560                 :            : #endif
+     561                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     562                 :            :                 SPDM_MEASUREMENTS,
+     563                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+     564                 :            :                 false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
+     565                 :            :                 ptr, &sig_size);
+     566                 :          1 :         ptr += sig_size;
+     567                 :            : 
+     568                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     569                 :            :                                               false, spdm_response_size,
+     570                 :            :                                               spdm_response, response_size,
+     571                 :            :                                               response);
+     572                 :            :     }
+     573                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     574                 :            : 
+     575                 :          1 :     case 0x3: {
+     576                 :            :         spdm_measurements_response_t *spdm_response;
+     577                 :            :         uint8_t *ptr;
+     578                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     579                 :            :         size_t sig_size;
+     580                 :            :         size_t measurment_sig_size;
+     581                 :            :         spdm_measurement_block_dmtf_t *measurment_block;
+     582                 :            :         size_t spdm_response_size;
+     583                 :            :         size_t transport_header_size;
+     584                 :            : 
+     585                 :            :         ((libspdm_context_t *)spdm_context)
+     586                 :          1 :         ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     587                 :            :         ((libspdm_context_t *)spdm_context)
+     588                 :          1 :         ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     589                 :            :         ((libspdm_context_t *)spdm_context)
+     590                 :          1 :         ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+     591                 :          1 :         measurment_sig_size = SPDM_NONCE_SIZE + sizeof(uint16_t) + strlen("libspdm") +
+     592                 :          1 :                               libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+     593                 :          1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
+     594                 :            :                              sizeof(spdm_measurement_block_dmtf_t) +
+     595                 :          1 :                              libspdm_get_measurement_hash_size(
+     596                 :          1 :             m_libspdm_use_measurement_hash_algo) + measurment_sig_size;
+     597                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     598                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     599                 :            : 
+     600                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     601                 :          1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
+     602                 :          1 :         spdm_response->header.param1 = 0;
+     603                 :          1 :         spdm_response->header.param2 = 0;
+     604                 :          1 :         spdm_response->number_of_blocks = 1;
+     605                 :          1 :         libspdm_write_uint24(
+     606                 :          1 :             spdm_response->measurement_record_length,
+     607                 :            :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
+     608                 :          1 :                        libspdm_get_measurement_hash_size(
+     609                 :            :                            m_libspdm_use_measurement_hash_algo)));
+     610                 :          1 :         measurment_block = (void *)(spdm_response + 1);
+     611                 :          1 :         libspdm_set_mem(measurment_block,
+     612                 :            :                         sizeof(spdm_measurement_block_dmtf_t) +
+     613                 :          1 :                         libspdm_get_measurement_hash_size(
+     614                 :            :                             m_libspdm_use_measurement_hash_algo), 1);
+     615                 :            :         measurment_block->measurement_block_common_header
+     616                 :          1 :         .measurement_specification = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     617                 :          1 :         measurment_block->measurement_block_common_header.measurement_size =
+     618                 :          1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
+     619                 :          1 :                        libspdm_get_measurement_hash_size(
+     620                 :            :                            m_libspdm_use_measurement_hash_algo));
+     621                 :          1 :         ptr = (void *)((uint8_t *)spdm_response + spdm_response_size - measurment_sig_size);
+     622                 :          1 :         libspdm_set_mem(ptr, SPDM_NONCE_SIZE, 0x12);
+     623                 :          1 :         ptr += SPDM_NONCE_SIZE;
+     624                 :            : 
+     625                 :          1 :         *(uint16_t *)ptr = (uint16_t)strlen("libspdm");
+     626                 :          1 :         ptr += sizeof(uint16_t);
+     627                 :          1 :         libspdm_copy_mem(ptr, strlen("libspdm"), "libspdm", strlen("libspdm"));
+     628                 :            : 
+     629                 :          1 :         ptr += strlen("libspdm");
+     630                 :            : 
+     631                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+     632                 :            :                          sizeof(m_libspdm_local_buffer)
+     633                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+     634                 :            :                             m_libspdm_local_buffer),
+     635                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+     636                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+     637                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+     638                 :            :                        m_libspdm_local_buffer_size));
+     639                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+     640                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
+     641                 :            :                          m_libspdm_local_buffer_size, hash_data);
+     642                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
+     643                 :            :                        libspdm_get_hash_size(m_libspdm_use_hash_algo)));
+     644                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+     645                 :          1 :         sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+     646                 :          1 :         libspdm_responder_data_sign(
+     647                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+     648                 :            :             spdm_context,
+     649                 :            : #endif
+     650                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     651                 :            :                 SPDM_MEASUREMENTS,
+     652                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+     653                 :            :                 false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
+     654                 :            :                 ptr, &sig_size);
+     655                 :          1 :         ptr += sig_size;
+     656                 :            : 
+     657                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     658                 :            :                                               false, spdm_response_size,
+     659                 :            :                                               spdm_response, response_size,
+     660                 :            :                                               response);
+     661                 :            :     }
+     662                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     663                 :            : 
+     664                 :          1 :     case 0x4: {
+     665                 :            :         spdm_error_response_t *spdm_response;
+     666                 :            :         size_t spdm_response_size;
+     667                 :            :         size_t transport_header_size;
+     668                 :            : 
+     669                 :          1 :         spdm_response_size = sizeof(spdm_error_response_t);
+     670                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     671                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     672                 :            : 
+     673                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     674                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     675                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_INVALID_REQUEST;
+     676                 :          1 :         spdm_response->header.param2 = 0;
+     677                 :            : 
+     678                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     679                 :            :                                               false, spdm_response_size,
+     680                 :            :                                               spdm_response,
+     681                 :            :                                               response_size, response);
+     682                 :            :     }
+     683                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     684                 :            : 
+     685                 :          1 :     case 0x5: {
+     686                 :            :         spdm_error_response_t *spdm_response;
+     687                 :            :         size_t spdm_response_size;
+     688                 :            :         size_t transport_header_size;
+     689                 :            : 
+     690                 :          1 :         spdm_response_size = sizeof(spdm_error_response_t);
+     691                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     692                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     693                 :            : 
+     694                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     695                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     696                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
+     697                 :          1 :         spdm_response->header.param2 = 0;
+     698                 :            : 
+     699                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     700                 :            :                                               false, spdm_response_size,
+     701                 :            :                                               spdm_response,
+     702                 :            :                                               response_size, response);
+     703                 :            :     }
+     704                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     705                 :            : 
+     706                 :          2 :     case 0x6: {
+     707                 :            :         static size_t sub_index1 = 0;
+     708         [ +  + ]:          2 :         if (sub_index1 == 0) {
+     709                 :            :             spdm_error_response_t *spdm_response;
+     710                 :            :             size_t spdm_response_size;
+     711                 :            :             size_t transport_header_size;
+     712                 :            : 
+     713                 :          1 :             spdm_response_size = sizeof(spdm_error_response_t);
+     714                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     715                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     716                 :            : 
+     717                 :          1 :             spdm_response->header.spdm_version =
+     718                 :            :                 SPDM_MESSAGE_VERSION_11;
+     719                 :          1 :             spdm_response->header.request_response_code = SPDM_ERROR;
+     720                 :          1 :             spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
+     721                 :          1 :             spdm_response->header.param2 = 0;
+     722                 :            : 
+     723                 :          1 :             libspdm_transport_test_encode_message(
+     724                 :            :                 spdm_context, NULL, false, false,
+     725                 :            :                 spdm_response_size, spdm_response,
+     726                 :            :                 response_size, response);
+     727                 :          1 :             sub_index1++;
+     728         [ +  - ]:          1 :         } else if (sub_index1 == 1) {
+     729                 :            :             spdm_measurements_response_t *spdm_response;
+     730                 :            :             uint8_t *ptr;
+     731                 :            :             uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     732                 :            :             size_t sig_size;
+     733                 :            :             size_t measurment_sig_size;
+     734                 :            :             spdm_measurement_block_dmtf_t *measurment_block;
+     735                 :            :             size_t spdm_response_size;
+     736                 :            :             size_t transport_header_size;
+     737                 :            : 
+     738                 :            :             ((libspdm_context_t *)spdm_context)
+     739                 :          1 :             ->connection_info.algorithm.base_asym_algo =
+     740                 :            :                 m_libspdm_use_asym_algo;
+     741                 :            :             ((libspdm_context_t *)spdm_context)
+     742                 :          1 :             ->connection_info.algorithm.base_hash_algo =
+     743                 :            :                 m_libspdm_use_hash_algo;
+     744                 :            :             ((libspdm_context_t *)spdm_context)
+     745                 :            :             ->connection_info.algorithm
+     746                 :          1 :             .measurement_hash_algo =
+     747                 :            :                 m_libspdm_use_measurement_hash_algo;
+     748                 :          1 :             measurment_sig_size =
+     749                 :            :                 SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
+     750                 :          1 :                 libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+     751                 :          1 :             spdm_response_size = sizeof(spdm_measurements_response_t) +
+     752                 :            :                                  sizeof(spdm_measurement_block_dmtf_t) +
+     753                 :          1 :                                  libspdm_get_measurement_hash_size(
+     754                 :          1 :                 m_libspdm_use_measurement_hash_algo) +
+     755                 :            :                                  measurment_sig_size;
+     756                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     757                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     758                 :            : 
+     759                 :          1 :             spdm_response->header.spdm_version =
+     760                 :            :                 SPDM_MESSAGE_VERSION_11;
+     761                 :          1 :             spdm_response->header.request_response_code =
+     762                 :            :                 SPDM_MEASUREMENTS;
+     763                 :          1 :             spdm_response->header.param1 = 0;
+     764                 :          1 :             spdm_response->header.param2 = 0;
+     765                 :          1 :             spdm_response->number_of_blocks = 1;
+     766                 :          1 :             libspdm_write_uint24(
+     767                 :          1 :                 spdm_response->measurement_record_length,
+     768                 :            :                 (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
+     769                 :          1 :                            libspdm_get_measurement_hash_size(
+     770                 :            :                                m_libspdm_use_measurement_hash_algo)));
+     771                 :          1 :             measurment_block = (void *)(spdm_response + 1);
+     772                 :          1 :             libspdm_set_mem(measurment_block,
+     773                 :            :                             sizeof(spdm_measurement_block_dmtf_t) +
+     774                 :          1 :                             libspdm_get_measurement_hash_size(
+     775                 :            :                                 m_libspdm_use_measurement_hash_algo),
+     776                 :            :                             1);
+     777                 :            :             measurment_block->measurement_block_common_header
+     778                 :          1 :             .measurement_specification =
+     779                 :            :                 SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     780                 :            :             measurment_block->measurement_block_common_header
+     781                 :          1 :             .measurement_size = (uint16_t)(
+     782                 :            :                 sizeof(spdm_measurement_block_dmtf_header_t) +
+     783                 :          1 :                 libspdm_get_measurement_hash_size(
+     784                 :            :                     m_libspdm_use_measurement_hash_algo));
+     785                 :          1 :             ptr = (void *)((uint8_t *)spdm_response + spdm_response_size -
+     786                 :            :                            measurment_sig_size);
+     787                 :          1 :             libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
+     788                 :          1 :             ptr += SPDM_NONCE_SIZE;
+     789                 :          1 :             *(uint16_t *)ptr = 0;
+     790                 :          1 :             ptr += sizeof(uint16_t);
+     791                 :          1 :             libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+     792                 :            :                              sizeof(m_libspdm_local_buffer)
+     793                 :          1 :                              - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+     794                 :            :                                 m_libspdm_local_buffer),
+     795                 :          1 :                              spdm_response, (size_t)ptr - (size_t)spdm_response);
+     796                 :          1 :             m_libspdm_local_buffer_size +=
+     797                 :          1 :                 ((size_t)ptr - (size_t)spdm_response);
+     798                 :          1 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+     799                 :            :                            m_libspdm_local_buffer_size));
+     800                 :          1 :             libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+     801                 :          1 :             libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
+     802                 :            :                              m_libspdm_local_buffer_size, hash_data);
+     803                 :          1 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
+     804                 :            :                            libspdm_get_hash_size(m_libspdm_use_hash_algo)));
+     805                 :          1 :             libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+     806                 :          1 :             sig_size =
+     807                 :          1 :                 libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+     808                 :          1 :             libspdm_responder_data_sign(
+     809                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+     810                 :            :                 spdm_context,
+     811                 :            : #endif
+     812                 :          1 :                 spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     813                 :            :                     SPDM_MEASUREMENTS,
+     814                 :            :                     m_libspdm_use_asym_algo,
+     815                 :            :                     m_libspdm_use_hash_algo,
+     816                 :            :                     false, m_libspdm_local_buffer,
+     817                 :            :                     m_libspdm_local_buffer_size, ptr,
+     818                 :            :                     &sig_size);
+     819                 :          1 :             ptr += sig_size;
+     820                 :            : 
+     821                 :          1 :             libspdm_transport_test_encode_message(
+     822                 :            :                 spdm_context, NULL, false, false, spdm_response_size,
+     823                 :            :                 spdm_response, response_size, response);
+     824                 :            :         }
+     825                 :            :     }
+     826                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     827                 :            : 
+     828                 :          1 :     case 0x7: {
+     829                 :            :         spdm_error_response_t *spdm_response;
+     830                 :            :         size_t spdm_response_size;
+     831                 :            :         size_t transport_header_size;
+     832                 :            : 
+     833                 :          1 :         spdm_response_size = sizeof(spdm_error_response_t);
+     834                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     835                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     836                 :            : 
+     837                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     838                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     839                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_REQUEST_RESYNCH;
+     840                 :          1 :         spdm_response->header.param2 = 0;
+     841                 :            : 
+     842                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     843                 :            :                                               false, spdm_response_size,
+     844                 :            :                                               spdm_response,
+     845                 :            :                                               response_size, response);
+     846                 :            :     }
+     847                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     848                 :            : 
+     849                 :          2 :     case 0x8: {
+     850                 :            :         spdm_error_response_data_response_not_ready_t *spdm_response;
+     851                 :            :         size_t spdm_response_size;
+     852                 :            :         size_t transport_header_size;
+     853                 :            : 
+     854                 :          2 :         spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
+     855                 :          2 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     856                 :          2 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     857                 :            : 
+     858                 :          2 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     859                 :          2 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     860                 :          2 :         spdm_response->header.param1 =
+     861                 :            :             SPDM_ERROR_CODE_RESPONSE_NOT_READY;
+     862                 :          2 :         spdm_response->header.param2 = 0;
+     863                 :          2 :         spdm_response->extend_error_data.rd_exponent = 1;
+     864                 :          2 :         spdm_response->extend_error_data.rd_tm = 2;
+     865                 :          2 :         spdm_response->extend_error_data.request_code =
+     866                 :            :             SPDM_GET_MEASUREMENTS;
+     867                 :          2 :         spdm_response->extend_error_data.token = 0;
+     868                 :            : 
+     869                 :          2 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     870                 :            :                                               false, spdm_response_size,
+     871                 :            :                                               spdm_response,
+     872                 :            :                                               response_size, response);
+     873                 :            :     }
+     874                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     875                 :            : 
+     876                 :          2 :     case 0x9: {
+     877                 :            :         static size_t sub_index2 = 0;
+     878         [ +  + ]:          2 :         if (sub_index2 == 0) {
+     879                 :            :             spdm_error_response_data_response_not_ready_t
+     880                 :            :             *spdm_response;
+     881                 :            :             size_t spdm_response_size;
+     882                 :            :             size_t transport_header_size;
+     883                 :            : 
+     884                 :          1 :             spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
+     885                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     886                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     887                 :            : 
+     888                 :          1 :             spdm_response->header.spdm_version =
+     889                 :            :                 SPDM_MESSAGE_VERSION_11;
+     890                 :          1 :             spdm_response->header.request_response_code = SPDM_ERROR;
+     891                 :          1 :             spdm_response->header.param1 =
+     892                 :            :                 SPDM_ERROR_CODE_RESPONSE_NOT_READY;
+     893                 :          1 :             spdm_response->header.param2 = 0;
+     894                 :          1 :             spdm_response->extend_error_data.rd_exponent = 1;
+     895                 :          1 :             spdm_response->extend_error_data.rd_tm = 2;
+     896                 :          1 :             spdm_response->extend_error_data.request_code =
+     897                 :            :                 SPDM_GET_MEASUREMENTS;
+     898                 :          1 :             spdm_response->extend_error_data.token = 1;
+     899                 :            : 
+     900                 :          1 :             libspdm_transport_test_encode_message(
+     901                 :            :                 spdm_context, NULL, false, false,
+     902                 :            :                 spdm_response_size, spdm_response,
+     903                 :            :                 response_size, response);
+     904                 :          1 :             sub_index2++;
+     905         [ +  - ]:          1 :         } else if (sub_index2 == 1) {
+     906                 :            :             spdm_measurements_response_t *spdm_response;
+     907                 :            :             uint8_t *ptr;
+     908                 :            :             uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     909                 :            :             size_t sig_size;
+     910                 :            :             size_t measurment_sig_size;
+     911                 :            :             spdm_measurement_block_dmtf_t *measurment_block;
+     912                 :            :             size_t spdm_response_size;
+     913                 :            :             size_t transport_header_size;
+     914                 :            : 
+     915                 :            :             ((libspdm_context_t *)spdm_context)
+     916                 :          1 :             ->connection_info.algorithm.base_asym_algo =
+     917                 :            :                 m_libspdm_use_asym_algo;
+     918                 :            :             ((libspdm_context_t *)spdm_context)
+     919                 :          1 :             ->connection_info.algorithm.base_hash_algo =
+     920                 :            :                 m_libspdm_use_hash_algo;
+     921                 :            :             ((libspdm_context_t *)spdm_context)
+     922                 :            :             ->connection_info.algorithm
+     923                 :          1 :             .measurement_hash_algo =
+     924                 :            :                 m_libspdm_use_measurement_hash_algo;
+     925                 :          1 :             measurment_sig_size =
+     926                 :            :                 SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
+     927                 :          1 :                 libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+     928                 :          1 :             spdm_response_size = sizeof(spdm_measurements_response_t) +
+     929                 :            :                                  sizeof(spdm_measurement_block_dmtf_t) +
+     930                 :          1 :                                  libspdm_get_measurement_hash_size(
+     931                 :          1 :                 m_libspdm_use_measurement_hash_algo) +
+     932                 :            :                                  measurment_sig_size;
+     933                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     934                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     935                 :            : 
+     936                 :          1 :             spdm_response->header.spdm_version =
+     937                 :            :                 SPDM_MESSAGE_VERSION_11;
+     938                 :          1 :             spdm_response->header.request_response_code =
+     939                 :            :                 SPDM_MEASUREMENTS;
+     940                 :          1 :             spdm_response->header.param1 = 0;
+     941                 :          1 :             spdm_response->header.param2 = 0;
+     942                 :          1 :             spdm_response->number_of_blocks = 1;
+     943                 :          1 :             libspdm_write_uint24(
+     944                 :          1 :                 spdm_response->measurement_record_length,
+     945                 :            :                 (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
+     946                 :          1 :                            libspdm_get_measurement_hash_size(
+     947                 :            :                                m_libspdm_use_measurement_hash_algo)));
+     948                 :          1 :             measurment_block = (void *)(spdm_response + 1);
+     949                 :          1 :             libspdm_set_mem(measurment_block,
+     950                 :            :                             sizeof(spdm_measurement_block_dmtf_t) +
+     951                 :          1 :                             libspdm_get_measurement_hash_size(
+     952                 :            :                                 m_libspdm_use_measurement_hash_algo),
+     953                 :            :                             1);
+     954                 :            :             measurment_block->measurement_block_common_header
+     955                 :          1 :             .measurement_specification =
+     956                 :            :                 SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     957                 :            :             measurment_block->measurement_block_common_header
+     958                 :          1 :             .measurement_size = (uint16_t)(
+     959                 :            :                 sizeof(spdm_measurement_block_dmtf_header_t) +
+     960                 :          1 :                 libspdm_get_measurement_hash_size(
+     961                 :            :                     m_libspdm_use_measurement_hash_algo));
+     962                 :          1 :             ptr = (void *)((uint8_t *)spdm_response + spdm_response_size -
+     963                 :            :                            measurment_sig_size);
+     964                 :          1 :             libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
+     965                 :          1 :             ptr += SPDM_NONCE_SIZE;
+     966                 :          1 :             *(uint16_t *)ptr = 0;
+     967                 :          1 :             ptr += sizeof(uint16_t);
+     968                 :          1 :             libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+     969                 :            :                              sizeof(m_libspdm_local_buffer)
+     970                 :          1 :                              - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+     971                 :            :                                 m_libspdm_local_buffer),
+     972                 :          1 :                              spdm_response, (size_t)ptr - (size_t)spdm_response);
+     973                 :          1 :             m_libspdm_local_buffer_size +=
+     974                 :          1 :                 ((size_t)ptr - (size_t)spdm_response);
+     975                 :          1 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+     976                 :            :                            m_libspdm_local_buffer_size));
+     977                 :          1 :             libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+     978                 :          1 :             libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
+     979                 :            :                              m_libspdm_local_buffer_size, hash_data);
+     980                 :          1 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
+     981                 :            :                            libspdm_get_hash_size(m_libspdm_use_hash_algo)));
+     982                 :          1 :             libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+     983                 :          1 :             sig_size =
+     984                 :          1 :                 libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+     985                 :          1 :             libspdm_responder_data_sign(
+     986                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+     987                 :            :                 spdm_context,
+     988                 :            : #endif
+     989                 :          1 :                 spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     990                 :            :                     SPDM_MEASUREMENTS,
+     991                 :            :                     m_libspdm_use_asym_algo,
+     992                 :            :                     m_libspdm_use_hash_algo,
+     993                 :            :                     false, m_libspdm_local_buffer,
+     994                 :            :                     m_libspdm_local_buffer_size, ptr,
+     995                 :            :                     &sig_size);
+     996                 :          1 :             ptr += sig_size;
+     997                 :            : 
+     998                 :          1 :             libspdm_transport_test_encode_message(
+     999                 :            :                 spdm_context, NULL, false, false, spdm_response_size,
+    1000                 :            :                 spdm_response, response_size, response);
+    1001                 :            :         }
+    1002                 :            :     }
+    1003                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+    1004                 :            : 
+    1005                 :          1 :     case 0xA: {
+    1006                 :            :         spdm_measurements_response_t *spdm_response;
+    1007                 :            :         size_t spdm_response_size;
+    1008                 :            :         size_t transport_header_size;
+    1009                 :            :         uint8_t *ptr;
+    1010                 :          1 :         spdm_response_size =
+    1011                 :            :             sizeof(spdm_measurements_response_t)
+    1012                 :            :             + SPDM_NONCE_SIZE + sizeof(uint16_t);
+    1013                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1014                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1015                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1016                 :          1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
+    1017                 :          1 :         spdm_response->header.param1 = 4;
+    1018                 :          1 :         spdm_response->header.param2 = 0;
+    1019                 :          1 :         spdm_response->number_of_blocks = 0;
+    1020                 :          1 :         libspdm_write_uint24(spdm_response->measurement_record_length, 0);
+    1021                 :            : 
+    1022                 :          1 :         ptr = (uint8_t *)spdm_response +
+    1023                 :            :               sizeof(spdm_measurements_response_t);
+    1024                 :          1 :         libspdm_get_random_number(SPDM_NONCE_SIZE,ptr);
+    1025                 :          1 :         ptr += SPDM_NONCE_SIZE;
+    1026                 :          1 :         *(uint16_t *)ptr = 0;
+    1027                 :            : 
+    1028                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1029                 :            :                                               false, spdm_response_size,
+    1030                 :            :                                               spdm_response, response_size,
+    1031                 :            :                                               response);
+    1032                 :            :     }
+    1033                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1034                 :            : 
+    1035                 :          1 :     case 0xB: {
+    1036                 :            :         spdm_measurements_response_t *spdm_response;
+    1037                 :            :         spdm_measurement_block_dmtf_t *measurment_block;
+    1038                 :            :         size_t spdm_response_size;
+    1039                 :            :         size_t transport_header_size;
+    1040                 :            :         uint8_t *ptr;
+    1041                 :            :         ((libspdm_context_t *)spdm_context)
+    1042                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    1043                 :            :             m_libspdm_use_measurement_hash_algo;
+    1044                 :          1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
+    1045                 :            :                              sizeof(spdm_measurement_block_dmtf_t) +
+    1046                 :          1 :                              libspdm_get_measurement_hash_size(
+    1047                 :            :             m_libspdm_use_measurement_hash_algo) +
+    1048                 :            :                              SPDM_NONCE_SIZE + sizeof(uint16_t);
+    1049                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1050                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1051                 :            : 
+    1052                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1053                 :          1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
+    1054                 :          1 :         spdm_response->header.param1 = 0;
+    1055                 :          1 :         spdm_response->header.param2 = 0;
+    1056                 :          1 :         spdm_response->number_of_blocks = 1;
+    1057                 :          1 :         libspdm_write_uint24(
+    1058                 :          1 :             spdm_response->measurement_record_length,
+    1059                 :            :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
+    1060                 :          1 :                        libspdm_get_measurement_hash_size(
+    1061                 :            :                            m_libspdm_use_measurement_hash_algo)));
+    1062                 :          1 :         measurment_block = (void *)(spdm_response + 1);
+    1063                 :          1 :         libspdm_set_mem(measurment_block,
+    1064                 :            :                         sizeof(spdm_measurement_block_dmtf_t) +
+    1065                 :          1 :                         libspdm_get_measurement_hash_size(
+    1066                 :            :                             m_libspdm_use_measurement_hash_algo),
+    1067                 :            :                         1);
+    1068                 :            :         measurment_block->measurement_block_common_header
+    1069                 :          1 :         .measurement_specification =
+    1070                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1071                 :            :         measurment_block->measurement_block_common_header
+    1072                 :          1 :         .measurement_size =
+    1073                 :          1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
+    1074                 :          1 :                        libspdm_get_measurement_hash_size(
+    1075                 :            :                            m_libspdm_use_measurement_hash_algo));
+    1076                 :            : 
+    1077                 :          1 :         ptr = (uint8_t *)spdm_response +
+    1078                 :            :               sizeof(spdm_measurements_response_t) +
+    1079                 :          1 :               sizeof(spdm_measurement_block_dmtf_t) +
+    1080                 :          1 :               libspdm_get_measurement_hash_size(
+    1081                 :            :             m_libspdm_use_measurement_hash_algo);
+    1082                 :          1 :         libspdm_get_random_number(SPDM_NONCE_SIZE,ptr);
+    1083                 :          1 :         *(uint16_t *)(ptr + SPDM_NONCE_SIZE) = 0;
+    1084                 :            : 
+    1085                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1086                 :            :                                               false, spdm_response_size,
+    1087                 :            :                                               spdm_response, response_size,
+    1088                 :            :                                               response);
+    1089                 :            :     }
+    1090                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1091                 :            : 
+    1092                 :          1 :     case 0xC: {
+    1093                 :            :         spdm_measurements_response_t *spdm_response;
+    1094                 :            :         uint8_t *ptr;
+    1095                 :            :         size_t sig_size;
+    1096                 :            :         size_t measurment_sig_size;
+    1097                 :            :         spdm_measurement_block_dmtf_t *measurment_block;
+    1098                 :            :         size_t spdm_response_size;
+    1099                 :            :         size_t transport_header_size;
+    1100                 :            : 
+    1101                 :            :         ((libspdm_context_t *)spdm_context)
+    1102                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    1103                 :            :             m_libspdm_use_asym_algo;
+    1104                 :            :         ((libspdm_context_t *)spdm_context)
+    1105                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    1106                 :            :             m_libspdm_use_hash_algo;
+    1107                 :            :         ((libspdm_context_t *)spdm_context)
+    1108                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    1109                 :            :             m_libspdm_use_measurement_hash_algo;
+    1110                 :            : 
+    1111                 :          1 :         measurment_sig_size =
+    1112                 :            :             SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
+    1113                 :          1 :             libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    1114                 :          1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
+    1115                 :            :                              sizeof(spdm_measurement_block_dmtf_t) +
+    1116                 :          1 :                              libspdm_get_measurement_hash_size(
+    1117                 :          1 :             m_libspdm_use_measurement_hash_algo) +
+    1118                 :            :                              measurment_sig_size;
+    1119                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1120                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1121                 :            : 
+    1122                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1123                 :          1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
+    1124                 :          1 :         spdm_response->header.param1 = 0;
+    1125                 :          1 :         spdm_response->header.param2 = 0;
+    1126                 :          1 :         spdm_response->number_of_blocks = 1;
+    1127                 :          1 :         libspdm_write_uint24(
+    1128                 :          1 :             spdm_response->measurement_record_length,
+    1129                 :            :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
+    1130                 :          1 :                        libspdm_get_measurement_hash_size(
+    1131                 :            :                            m_libspdm_use_measurement_hash_algo)));
+    1132                 :          1 :         measurment_block = (void *)(spdm_response + 1);
+    1133                 :          1 :         libspdm_set_mem(measurment_block,
+    1134                 :            :                         sizeof(spdm_measurement_block_dmtf_t) +
+    1135                 :          1 :                         libspdm_get_measurement_hash_size(
+    1136                 :            :                             m_libspdm_use_measurement_hash_algo),
+    1137                 :            :                         1);
+    1138                 :            :         measurment_block->measurement_block_common_header
+    1139                 :          1 :         .measurement_specification =
+    1140                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1141                 :            :         measurment_block->measurement_block_common_header
+    1142                 :          1 :         .measurement_size =
+    1143                 :          1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
+    1144                 :          1 :                        libspdm_get_measurement_hash_size(
+    1145                 :            :                            m_libspdm_use_measurement_hash_algo));
+    1146                 :          1 :         ptr = (void *)((uint8_t *)spdm_response + spdm_response_size -
+    1147                 :            :                        measurment_sig_size);
+    1148                 :          1 :         libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
+    1149                 :          1 :         ptr += SPDM_NONCE_SIZE;
+    1150                 :          1 :         *(uint16_t *)ptr = 0;
+    1151                 :          1 :         ptr += sizeof(uint16_t);
+    1152                 :          1 :         sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    1153                 :          1 :         libspdm_set_mem(ptr, sig_size, 0);
+    1154                 :          1 :         ptr += sig_size;
+    1155                 :            : 
+    1156                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1157                 :            :                                               false, spdm_response_size,
+    1158                 :            :                                               spdm_response, response_size,
+    1159                 :            :                                               response);
+    1160                 :            :     }
+    1161                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1162                 :            : 
+    1163                 :          1 :     case 0xD: {
+    1164                 :            :         spdm_measurements_response_t *spdm_response;
+    1165                 :            :         uint8_t *ptr;
+    1166                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1167                 :            :         size_t sig_size;
+    1168                 :            :         size_t measurment_sig_size;
+    1169                 :            :         spdm_measurement_block_dmtf_t *measurment_block;
+    1170                 :            :         size_t spdm_response_size;
+    1171                 :            :         size_t transport_header_size;
+    1172                 :            : 
+    1173                 :            :         ((libspdm_context_t *)spdm_context)
+    1174                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    1175                 :            :             m_libspdm_use_asym_algo;
+    1176                 :            :         ((libspdm_context_t *)spdm_context)
+    1177                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    1178                 :            :             m_libspdm_use_hash_algo;
+    1179                 :            :         ((libspdm_context_t *)spdm_context)
+    1180                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    1181                 :            :             m_libspdm_use_measurement_hash_algo;
+    1182                 :          1 :         measurment_sig_size =
+    1183                 :            :             SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
+    1184                 :          1 :             libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    1185                 :          1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
+    1186                 :            :                              sizeof(spdm_measurement_block_dmtf_t) +
+    1187                 :          1 :                              libspdm_get_measurement_hash_size(
+    1188                 :          1 :             m_libspdm_use_measurement_hash_algo) +
+    1189                 :            :                              measurment_sig_size;
+    1190                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1191                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1192                 :            : 
+    1193                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1194                 :          1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
+    1195                 :          1 :         spdm_response->header.param1 = 0;
+    1196                 :          1 :         spdm_response->header.param2 = 0;
+    1197                 :          1 :         spdm_response->number_of_blocks = 1;
+    1198                 :          1 :         libspdm_write_uint24(
+    1199                 :          1 :             spdm_response->measurement_record_length,
+    1200                 :            :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
+    1201                 :          1 :                        libspdm_get_measurement_hash_size(
+    1202                 :            :                            m_libspdm_use_measurement_hash_algo)));
+    1203                 :          1 :         measurment_block = (void *)(spdm_response + 1);
+    1204                 :          1 :         libspdm_set_mem(measurment_block,
+    1205                 :            :                         sizeof(spdm_measurement_block_dmtf_t) +
+    1206                 :          1 :                         libspdm_get_measurement_hash_size(
+    1207                 :            :                             m_libspdm_use_measurement_hash_algo),
+    1208                 :            :                         1);
+    1209                 :            :         measurment_block->measurement_block_common_header
+    1210                 :          1 :         .measurement_specification =
+    1211                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1212                 :            :         measurment_block->measurement_block_common_header
+    1213                 :          1 :         .measurement_size =
+    1214                 :          1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
+    1215                 :          1 :                        libspdm_get_measurement_hash_size(
+    1216                 :            :                            m_libspdm_use_measurement_hash_algo));
+    1217                 :          1 :         ptr = (void *)((uint8_t *)spdm_response + spdm_response_size -
+    1218                 :            :                        measurment_sig_size);
+    1219                 :          1 :         libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
+    1220                 :          1 :         ptr += SPDM_NONCE_SIZE;
+    1221                 :          1 :         *(uint16_t *)ptr = 0;
+    1222                 :          1 :         ptr += sizeof(uint16_t);
+    1223                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    1224                 :            :                          sizeof(m_libspdm_local_buffer)
+    1225                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    1226                 :            :                             m_libspdm_local_buffer),
+    1227                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    1228                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    1229                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    1230                 :            :                        m_libspdm_local_buffer_size));
+    1231                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    1232                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
+    1233                 :            :                          m_libspdm_local_buffer_size, hash_data);
+    1234                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
+    1235                 :            :                        libspdm_get_hash_size(m_libspdm_use_hash_algo)));
+    1236                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    1237                 :          1 :         sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    1238                 :          1 :         libspdm_get_random_number(sig_size, ptr);
+    1239                 :          1 :         ptr += sig_size;
+    1240                 :            : 
+    1241                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1242                 :            :                                               false, spdm_response_size,
+    1243                 :            :                                               spdm_response, response_size,
+    1244                 :            :                                               response);
+    1245                 :            :     }
+    1246                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1247                 :            : 
+    1248                 :          1 :     case 0xE: {
+    1249                 :            :         spdm_measurements_response_t *spdm_response;
+    1250                 :            :         spdm_measurement_block_dmtf_t *measurment_block;
+    1251                 :            :         size_t spdm_response_size;
+    1252                 :            :         size_t transport_header_size;
+    1253                 :            : 
+    1254                 :            :         ((libspdm_context_t *)spdm_context)
+    1255                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    1256                 :            :             m_libspdm_use_asym_algo;
+    1257                 :            :         ((libspdm_context_t *)spdm_context)
+    1258                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    1259                 :            :             m_libspdm_use_hash_algo;
+    1260                 :            :         ((libspdm_context_t *)spdm_context)
+    1261                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    1262                 :            :             m_libspdm_use_measurement_hash_algo;
+    1263                 :          1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
+    1264                 :            :                              sizeof(spdm_measurement_block_dmtf_t) +
+    1265                 :          1 :                              libspdm_get_measurement_hash_size(
+    1266                 :            :             m_libspdm_use_measurement_hash_algo) +
+    1267                 :            :                              SPDM_NONCE_SIZE + sizeof(uint16_t);
+    1268                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1269                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1270                 :            : 
+    1271                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1272                 :          1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
+    1273                 :          1 :         spdm_response->header.param1 = 0;
+    1274                 :          1 :         spdm_response->header.param2 = 0;
+    1275                 :          1 :         spdm_response->number_of_blocks = 1;
+    1276                 :          1 :         libspdm_write_uint24(
+    1277                 :          1 :             spdm_response->measurement_record_length,
+    1278                 :            :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
+    1279                 :          1 :                        libspdm_get_measurement_hash_size(
+    1280                 :            :                            m_libspdm_use_measurement_hash_algo)));
+    1281                 :          1 :         measurment_block = (void *)(spdm_response + 1);
+    1282                 :          1 :         libspdm_set_mem(measurment_block,
+    1283                 :            :                         sizeof(spdm_measurement_block_dmtf_t) +
+    1284                 :          1 :                         libspdm_get_measurement_hash_size(
+    1285                 :            :                             m_libspdm_use_measurement_hash_algo),
+    1286                 :            :                         1);
+    1287                 :            :         measurment_block->measurement_block_common_header
+    1288                 :          1 :         .measurement_specification =
+    1289                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1290                 :            :         measurment_block->measurement_block_common_header
+    1291                 :          1 :         .measurement_size =
+    1292                 :          1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
+    1293                 :          1 :                        libspdm_get_measurement_hash_size(
+    1294                 :            :                            m_libspdm_use_measurement_hash_algo));
+    1295                 :            : 
+    1296                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1297                 :            :                                               false, spdm_response_size,
+    1298                 :            :                                               spdm_response, response_size,
+    1299                 :            :                                               response);
+    1300                 :            :     }
+    1301                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1302                 :            : 
+    1303                 :          1 :     case 0xF: {
+    1304                 :            :         spdm_measurements_response_t *spdm_response;
+    1305                 :            :         uint8_t *ptr;
+    1306                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1307                 :            :         size_t sig_size;
+    1308                 :            :         size_t measurment_sig_size;
+    1309                 :            :         spdm_measurement_block_dmtf_t *measurment_block;
+    1310                 :            :         size_t spdm_response_size;
+    1311                 :            :         size_t transport_header_size;
+    1312                 :            : 
+    1313                 :            :         ((libspdm_context_t *)spdm_context)
+    1314                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    1315                 :            :             m_libspdm_use_asym_algo;
+    1316                 :            :         ((libspdm_context_t *)spdm_context)
+    1317                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    1318                 :            :             m_libspdm_use_hash_algo;
+    1319                 :            :         ((libspdm_context_t *)spdm_context)
+    1320                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    1321                 :            :             m_libspdm_use_measurement_hash_algo;
+    1322                 :          1 :         measurment_sig_size =
+    1323                 :            :             SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
+    1324                 :          1 :             libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    1325                 :          1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
+    1326                 :            :                              sizeof(spdm_measurement_block_dmtf_t) +
+    1327                 :          1 :                              libspdm_get_measurement_hash_size(
+    1328                 :          1 :             m_libspdm_use_measurement_hash_algo) +
+    1329                 :            :                              measurment_sig_size;
+    1330                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1331                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1332                 :            : 
+    1333                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1334                 :          1 :         spdm_response->header.request_response_code =
+    1335                 :            :             SPDM_MEASUREMENTS + 1;
+    1336                 :          1 :         spdm_response->header.param1 = 0;
+    1337                 :          1 :         spdm_response->header.param2 = 0;
+    1338                 :          1 :         spdm_response->number_of_blocks = 1;
+    1339                 :          1 :         libspdm_write_uint24(
+    1340                 :          1 :             spdm_response->measurement_record_length,
+    1341                 :            :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
+    1342                 :          1 :                        libspdm_get_measurement_hash_size(
+    1343                 :            :                            m_libspdm_use_measurement_hash_algo)));
+    1344                 :          1 :         measurment_block = (void *)(spdm_response + 1);
+    1345                 :          1 :         libspdm_set_mem(measurment_block,
+    1346                 :            :                         sizeof(spdm_measurement_block_dmtf_t) +
+    1347                 :          1 :                         libspdm_get_measurement_hash_size(
+    1348                 :            :                             m_libspdm_use_measurement_hash_algo),
+    1349                 :            :                         1);
+    1350                 :            :         measurment_block->measurement_block_common_header
+    1351                 :          1 :         .measurement_specification =
+    1352                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1353                 :            :         measurment_block->measurement_block_common_header
+    1354                 :          1 :         .measurement_size =
+    1355                 :          1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
+    1356                 :          1 :                        libspdm_get_measurement_hash_size(
+    1357                 :            :                            m_libspdm_use_measurement_hash_algo));
+    1358                 :          1 :         ptr = (void *)((uint8_t *)spdm_response + spdm_response_size -
+    1359                 :            :                        measurment_sig_size);
+    1360                 :          1 :         libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
+    1361                 :          1 :         ptr += SPDM_NONCE_SIZE;
+    1362                 :          1 :         *(uint16_t *)ptr = 0;
+    1363                 :          1 :         ptr += sizeof(uint16_t);
+    1364                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    1365                 :            :                          sizeof(m_libspdm_local_buffer)
+    1366                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    1367                 :            :                             m_libspdm_local_buffer),
+    1368                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    1369                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    1370                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    1371                 :            :                        m_libspdm_local_buffer_size));
+    1372                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    1373                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
+    1374                 :            :                          m_libspdm_local_buffer_size, hash_data);
+    1375                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
+    1376                 :            :                        libspdm_get_hash_size(m_libspdm_use_hash_algo)));
+    1377                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    1378                 :          1 :         sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    1379                 :          1 :         libspdm_responder_data_sign(
+    1380                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    1381                 :            :             spdm_context,
+    1382                 :            : #endif
+    1383                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    1384                 :            :                 SPDM_MEASUREMENTS,
+    1385                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    1386                 :            :                 false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
+    1387                 :            :                 ptr, &sig_size);
+    1388                 :          1 :         ptr += sig_size;
+    1389                 :            : 
+    1390                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1391                 :            :                                               false, spdm_response_size,
+    1392                 :            :                                               spdm_response, response_size,
+    1393                 :            :                                               response);
+    1394                 :            :     }
+    1395                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1396                 :            : 
+    1397                 :          4 :     case 0x10: {
+    1398                 :            :         spdm_measurements_response_t *spdm_response;
+    1399                 :            :         uint8_t *ptr;
+    1400                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1401                 :            :         size_t sig_size;
+    1402                 :            :         size_t measurment_sig_size;
+    1403                 :            :         spdm_measurement_block_dmtf_t *measurment_block;
+    1404                 :            :         size_t spdm_response_size;
+    1405                 :            :         size_t transport_header_size;
+    1406                 :            : 
+    1407                 :            :         ((libspdm_context_t *)spdm_context)
+    1408                 :          4 :         ->connection_info.algorithm.base_asym_algo =
+    1409                 :            :             m_libspdm_use_asym_algo;
+    1410                 :            :         ((libspdm_context_t *)spdm_context)
+    1411                 :          4 :         ->connection_info.algorithm.base_hash_algo =
+    1412                 :            :             m_libspdm_use_hash_algo;
+    1413                 :            :         ((libspdm_context_t *)spdm_context)
+    1414                 :          4 :         ->connection_info.algorithm.measurement_hash_algo =
+    1415                 :            :             m_libspdm_use_measurement_hash_algo;
+    1416                 :          4 :         measurment_sig_size =
+    1417                 :            :             SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
+    1418                 :          4 :             libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    1419                 :          4 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
+    1420                 :            :                              sizeof(spdm_measurement_block_dmtf_t) +
+    1421                 :          4 :                              libspdm_get_measurement_hash_size(
+    1422                 :          4 :             m_libspdm_use_measurement_hash_algo) +
+    1423                 :            :                              measurment_sig_size;
+    1424                 :          4 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1425                 :          4 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1426                 :            : 
+    1427                 :          4 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1428                 :          4 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
+    1429                 :          4 :         spdm_response->header.param1 = 0;
+    1430                 :          4 :         spdm_response->header.param2 = LIBSPDM_ALTERNATIVE_DEFAULT_SLOT_ID;
+    1431                 :          4 :         spdm_response->number_of_blocks = 1;
+    1432                 :          4 :         libspdm_write_uint24(
+    1433                 :          4 :             spdm_response->measurement_record_length,
+    1434                 :            :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
+    1435                 :          4 :                        libspdm_get_measurement_hash_size(
+    1436                 :            :                            m_libspdm_use_measurement_hash_algo)));
+    1437                 :          4 :         measurment_block = (void *)(spdm_response + 1);
+    1438                 :          4 :         libspdm_set_mem(measurment_block,
+    1439                 :            :                         sizeof(spdm_measurement_block_dmtf_t) +
+    1440                 :          4 :                         libspdm_get_measurement_hash_size(
+    1441                 :            :                             m_libspdm_use_measurement_hash_algo),
+    1442                 :            :                         1);
+    1443                 :            :         measurment_block->measurement_block_common_header
+    1444                 :          4 :         .measurement_specification =
+    1445                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1446                 :            :         measurment_block->measurement_block_common_header
+    1447                 :          4 :         .measurement_size =
+    1448                 :          4 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
+    1449                 :          4 :                        libspdm_get_measurement_hash_size(
+    1450                 :            :                            m_libspdm_use_measurement_hash_algo));
+    1451                 :          4 :         ptr = (void *)((uint8_t *)spdm_response + spdm_response_size -
+    1452                 :            :                        measurment_sig_size);
+    1453                 :          4 :         libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
+    1454                 :          4 :         ptr += SPDM_NONCE_SIZE;
+    1455                 :          4 :         *(uint16_t *)ptr = 0;
+    1456                 :          4 :         ptr += sizeof(uint16_t);
+    1457                 :          4 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    1458                 :            :                          sizeof(m_libspdm_local_buffer)
+    1459                 :          4 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    1460                 :            :                             m_libspdm_local_buffer),
+    1461                 :          4 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    1462                 :          4 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    1463                 :          4 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    1464                 :            :                        m_libspdm_local_buffer_size));
+    1465                 :          4 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    1466                 :          4 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
+    1467                 :            :                          m_libspdm_local_buffer_size, hash_data);
+    1468                 :          4 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
+    1469                 :            :                        libspdm_get_hash_size(m_libspdm_use_hash_algo)));
+    1470                 :          4 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    1471                 :          4 :         sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    1472                 :          4 :         libspdm_responder_data_sign(
+    1473                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    1474                 :            :             spdm_context,
+    1475                 :            : #endif
+    1476                 :          4 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    1477                 :            :                 SPDM_MEASUREMENTS,
+    1478                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    1479                 :            :                 false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
+    1480                 :            :                 ptr, &sig_size);
+    1481                 :          4 :         ptr += sig_size;
+    1482                 :            : 
+    1483                 :          4 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1484                 :            :                                               false, spdm_response_size,
+    1485                 :            :                                               spdm_response, response_size,
+    1486                 :            :                                               response);
+    1487                 :            :     }
+    1488                 :          4 :         return LIBSPDM_STATUS_SUCCESS;
+    1489                 :            : 
+    1490                 :          3 :     case 0x11: {
+    1491                 :            :         static size_t sub_index0x11 = 0;
+    1492                 :            : 
+    1493                 :            :         spdm_measurements_response_t *spdm_response;
+    1494                 :            :         spdm_measurement_block_dmtf_t *measurment_block;
+    1495                 :            :         size_t spdm_response_size;
+    1496                 :            :         size_t transport_header_size;
+    1497                 :          3 :         spdm_response_size = sizeof(spdm_measurements_response_t);
+    1498                 :            : 
+    1499                 :            :         ((libspdm_context_t *)spdm_context)
+    1500                 :          3 :         ->connection_info.algorithm.measurement_hash_algo =
+    1501                 :            :             m_libspdm_use_measurement_hash_algo;
+    1502                 :          3 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1503                 :          3 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1504                 :            : 
+    1505                 :          3 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1506                 :          3 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
+    1507                 :          3 :         spdm_response->header.param1 = 1;
+    1508                 :          3 :         spdm_response->header.param2 = 0;
+    1509         [ +  + ]:          3 :         if (sub_index0x11 == 0) {
+    1510                 :          1 :             spdm_response_size = sizeof(spdm_measurements_response_t) +
+    1511                 :            :                                  sizeof(spdm_measurement_block_dmtf_t) +
+    1512                 :          1 :                                  libspdm_get_measurement_hash_size(
+    1513                 :            :                 m_libspdm_use_measurement_hash_algo) +
+    1514                 :            :                                  SPDM_NONCE_SIZE + sizeof(uint16_t);
+    1515                 :          1 :             spdm_response->number_of_blocks = 1;
+    1516                 :          1 :             libspdm_write_uint24(
+    1517                 :          1 :                 spdm_response->measurement_record_length,
+    1518                 :            :                 (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
+    1519                 :          1 :                            libspdm_get_measurement_hash_size(
+    1520                 :            :                                m_libspdm_use_measurement_hash_algo)));
+    1521                 :          1 :             measurment_block = (void *)(spdm_response + 1);
+    1522                 :          1 :             libspdm_set_mem(measurment_block,
+    1523                 :            :                             sizeof(spdm_measurement_block_dmtf_t) +
+    1524                 :          1 :                             libspdm_get_measurement_hash_size(
+    1525                 :            :                                 m_libspdm_use_measurement_hash_algo),
+    1526                 :            :                             1);
+    1527                 :            :             measurment_block->measurement_block_common_header
+    1528                 :          1 :             .measurement_specification =
+    1529                 :            :                 SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1530                 :            :             measurment_block->measurement_block_common_header
+    1531                 :          1 :             .measurement_size = (uint16_t)(
+    1532                 :            :                 sizeof(spdm_measurement_block_dmtf_header_t) +
+    1533                 :          1 :                 libspdm_get_measurement_hash_size(
+    1534                 :            :                     m_libspdm_use_measurement_hash_algo));
+    1535         [ +  + ]:          2 :         } else if (sub_index0x11 == 1) {
+    1536                 :          1 :             spdm_response_size = sizeof(spdm_measurements_response_t) +
+    1537                 :            :                                  SPDM_NONCE_SIZE + sizeof(uint16_t);
+    1538                 :          1 :             spdm_response->number_of_blocks = 1;
+    1539                 :          1 :             libspdm_write_uint24(
+    1540                 :          1 :                 spdm_response->measurement_record_length, 0);
+    1541         [ +  - ]:          1 :         } else if (sub_index0x11 == 2) {
+    1542                 :          1 :             spdm_response_size = sizeof(spdm_measurements_response_t) +
+    1543                 :            :                                  sizeof(spdm_measurement_block_dmtf_t) +
+    1544                 :          1 :                                  libspdm_get_measurement_hash_size(
+    1545                 :            :                 m_libspdm_use_measurement_hash_algo) +
+    1546                 :            :                                  SPDM_NONCE_SIZE + sizeof(uint16_t);
+    1547                 :          1 :             spdm_response->number_of_blocks = 0;
+    1548                 :          1 :             libspdm_write_uint24(
+    1549                 :          1 :                 spdm_response->measurement_record_length,
+    1550                 :            :                 (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
+    1551                 :          1 :                            libspdm_get_measurement_hash_size(
+    1552                 :            :                                m_libspdm_use_measurement_hash_algo)));
+    1553                 :          1 :             measurment_block = (void *)(spdm_response + 1);
+    1554                 :          1 :             libspdm_set_mem(measurment_block,
+    1555                 :            :                             sizeof(spdm_measurement_block_dmtf_t) +
+    1556                 :          1 :                             libspdm_get_measurement_hash_size(
+    1557                 :            :                                 m_libspdm_use_measurement_hash_algo),
+    1558                 :            :                             1);
+    1559                 :            :             measurment_block->measurement_block_common_header
+    1560                 :          1 :             .measurement_specification =
+    1561                 :            :                 SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1562                 :            :             measurment_block->measurement_block_common_header
+    1563                 :          1 :             .measurement_size = (uint16_t)(
+    1564                 :            :                 sizeof(spdm_measurement_block_dmtf_header_t) +
+    1565                 :          1 :                 libspdm_get_measurement_hash_size(
+    1566                 :            :                     m_libspdm_use_measurement_hash_algo));
+    1567                 :            :         }
+    1568                 :          3 :         sub_index0x11++;
+    1569                 :            : 
+    1570                 :          3 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1571                 :            :                                               false, spdm_response_size,
+    1572                 :            :                                               spdm_response, response_size,
+    1573                 :            :                                               response);
+    1574                 :            :     }
+    1575                 :          3 :         return LIBSPDM_STATUS_SUCCESS;
+    1576                 :            : 
+    1577                 :          0 :     case 0x12: {
+    1578                 :            :         spdm_measurements_response_t *spdm_response;
+    1579                 :            :         spdm_measurement_block_dmtf_t *measurment_block;
+    1580                 :            :         uint8_t *large_spdm_response;
+    1581                 :            :         size_t spdm_response_size;
+    1582                 :            :         size_t transport_header_size;
+    1583                 :            :         size_t count;
+    1584                 :            : 
+    1585                 :            :         large_spdm_response =
+    1586                 :          0 :             (uint8_t *)malloc(sizeof(spdm_measurements_response_t) +
+    1587                 :            :                               LIBSPDM_LARGE_MEASUREMENT_SIZE);
+    1588                 :            : 
+    1589                 :            :         ((libspdm_context_t *)spdm_context)
+    1590                 :          0 :         ->connection_info.algorithm.measurement_hash_algo =
+    1591                 :            :             m_libspdm_use_measurement_hash_algo;
+    1592                 :          0 :         spdm_response_size = sizeof(spdm_measurements_response_t);
+    1593                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1594                 :          0 :         spdm_response = (void *)large_spdm_response;
+    1595                 :            : 
+    1596                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1597                 :          0 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
+    1598                 :          0 :         spdm_response->header.param1 = 0;
+    1599                 :          0 :         spdm_response->header.param2 = 0;
+    1600                 :          0 :         spdm_response->number_of_blocks = 0xFF;
+    1601                 :          0 :         libspdm_write_uint24(spdm_response->measurement_record_length,
+    1602                 :            :                              (uint32_t)(LIBSPDM_LARGE_MEASUREMENT_SIZE));
+    1603                 :          0 :         measurment_block = (void *)(spdm_response + 1);
+    1604                 :          0 :         libspdm_set_mem(measurment_block, LIBSPDM_LARGE_MEASUREMENT_SIZE, 1);
+    1605         [ #  # ]:          0 :         for (count = 0; count < spdm_response->number_of_blocks;
+    1606                 :          0 :              count++) {
+    1607                 :          0 :             measurment_block->measurement_block_common_header.index =
+    1608                 :          0 :                 (uint8_t)(count + 1);
+    1609                 :            :             measurment_block->measurement_block_common_header
+    1610                 :          0 :             .measurement_specification =
+    1611                 :            :                 SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1612                 :            :             measurment_block->measurement_block_common_header
+    1613                 :          0 :             .measurement_size = 0xFFFF;
+    1614                 :          0 :             spdm_response_size += (size_t)(
+    1615                 :            :                 sizeof(spdm_measurement_block_common_header_t) +
+    1616                 :            :                 0xFFFF);
+    1617                 :            :         }
+    1618                 :            : 
+    1619                 :          0 :         spdm_response = (void *)((uint8_t *)(*response) + transport_header_size);
+    1620         [ #  # ]:          0 :         if (spdm_response_size >  (size_t)(*response) + *response_size - (size_t)spdm_response) {
+    1621                 :          0 :             spdm_response_size =  (size_t)(*response) + *response_size - (size_t)spdm_response;
+    1622                 :            :         }
+    1623                 :          0 :         libspdm_copy_mem (spdm_response, spdm_response_size,
+    1624                 :            :                           large_spdm_response, spdm_response_size);
+    1625                 :            : 
+    1626                 :          0 :         status = libspdm_transport_test_encode_message(
+    1627                 :            :             spdm_context, NULL, false, false, spdm_response_size,
+    1628                 :            :             spdm_response, response_size, response);
+    1629                 :            : 
+    1630                 :          0 :         free(large_spdm_response);
+    1631                 :            :     }
+    1632                 :          0 :         return status;
+    1633                 :            : 
+    1634                 :          1 :     case 0x13: {
+    1635                 :            :         spdm_measurements_response_t *spdm_response;
+    1636                 :            :         spdm_measurement_block_dmtf_t *measurment_block;
+    1637                 :            :         size_t spdm_response_size;
+    1638                 :            :         size_t transport_header_size;
+    1639                 :            : 
+    1640                 :            :         ((libspdm_context_t *)spdm_context)
+    1641                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    1642                 :            :             m_libspdm_use_measurement_hash_algo;
+    1643                 :          1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
+    1644                 :            :                              sizeof(spdm_measurement_block_dmtf_t) +
+    1645                 :          1 :                              libspdm_get_measurement_hash_size(
+    1646                 :            :             m_libspdm_use_measurement_hash_algo) +
+    1647                 :            :                              SPDM_NONCE_SIZE + sizeof(uint16_t);
+    1648                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1649                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1650                 :            : 
+    1651                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1652                 :          1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
+    1653                 :          1 :         spdm_response->header.param1 = 0;
+    1654                 :          1 :         spdm_response->header.param2 = 0;
+    1655                 :          1 :         spdm_response->number_of_blocks = 1;
+    1656                 :          1 :         libspdm_write_uint24(
+    1657                 :          1 :             spdm_response->measurement_record_length,
+    1658                 :            :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
+    1659                 :          1 :                        libspdm_get_measurement_hash_size(
+    1660                 :            :                            m_libspdm_use_measurement_hash_algo)));
+    1661                 :          1 :         measurment_block = (void *)(spdm_response + 1);
+    1662                 :          1 :         libspdm_set_mem(measurment_block,
+    1663                 :            :                         sizeof(spdm_measurement_block_dmtf_t) +
+    1664                 :          1 :                         libspdm_get_measurement_hash_size(
+    1665                 :            :                             m_libspdm_use_measurement_hash_algo),
+    1666                 :            :                         1);
+    1667                 :          1 :         measurment_block->measurement_block_common_header.index = 1;
+    1668                 :            :         measurment_block->measurement_block_common_header
+    1669                 :          1 :         .measurement_specification = 0x00000001 | 0x00000002;
+    1670                 :            :         measurment_block->measurement_block_common_header
+    1671                 :          1 :         .measurement_size =
+    1672                 :          1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
+    1673                 :          1 :                        libspdm_get_measurement_hash_size(
+    1674                 :            :                            m_libspdm_use_measurement_hash_algo));
+    1675                 :            : 
+    1676                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1677                 :            :                                               false, spdm_response_size,
+    1678                 :            :                                               spdm_response, response_size,
+    1679                 :            :                                               response);
+    1680                 :            :     }
+    1681                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1682                 :            : 
+    1683                 :          1 :     case 0x14: {
+    1684                 :            :         spdm_measurements_response_t *spdm_response;
+    1685                 :            :         spdm_measurement_block_dmtf_t *measurment_block;
+    1686                 :            :         size_t spdm_response_size;
+    1687                 :            :         size_t transport_header_size;
+    1688                 :            : 
+    1689                 :            :         ((libspdm_context_t *)spdm_context)
+    1690                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    1691                 :            :             m_libspdm_use_measurement_hash_algo;
+    1692                 :          1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
+    1693                 :            :                              sizeof(spdm_measurement_block_dmtf_t) +
+    1694                 :          1 :                              libspdm_get_measurement_hash_size(
+    1695                 :            :             m_libspdm_use_measurement_hash_algo) +
+    1696                 :            :                              SPDM_NONCE_SIZE + sizeof(uint16_t);
+    1697                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1698                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1699                 :            : 
+    1700                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1701                 :          1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
+    1702                 :          1 :         spdm_response->header.param1 = 0;
+    1703                 :          1 :         spdm_response->header.param2 = 0;
+    1704                 :          1 :         spdm_response->number_of_blocks = 1;
+    1705                 :          1 :         libspdm_write_uint24(
+    1706                 :          1 :             spdm_response->measurement_record_length,
+    1707                 :            :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
+    1708                 :          1 :                        libspdm_get_measurement_hash_size(
+    1709                 :            :                            m_libspdm_use_measurement_hash_algo)));
+    1710                 :          1 :         measurment_block = (void *)(spdm_response + 1);
+    1711                 :          1 :         libspdm_set_mem(measurment_block,
+    1712                 :            :                         sizeof(spdm_measurement_block_dmtf_t) +
+    1713                 :          1 :                         libspdm_get_measurement_hash_size(
+    1714                 :            :                             m_libspdm_use_measurement_hash_algo),
+    1715                 :            :                         1);
+    1716                 :          1 :         measurment_block->measurement_block_common_header.index = 1;
+    1717                 :            :         measurment_block->measurement_block_common_header
+    1718                 :          1 :         .measurement_specification = 0x00000004 | 0x00000002;
+    1719                 :            :         measurment_block->measurement_block_common_header
+    1720                 :          1 :         .measurement_size =
+    1721                 :          1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
+    1722                 :          1 :                        libspdm_get_measurement_hash_size(
+    1723                 :            :                            m_libspdm_use_measurement_hash_algo));
+    1724                 :            : 
+    1725                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1726                 :            :                                               false, spdm_response_size,
+    1727                 :            :                                               spdm_response, response_size,
+    1728                 :            :                                               response);
+    1729                 :            :     }
+    1730                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1731                 :            : 
+    1732                 :          1 :     case 0x15: {
+    1733                 :            :         spdm_measurements_response_t *spdm_response;
+    1734                 :            :         spdm_measurement_block_dmtf_t *measurment_block;
+    1735                 :            :         size_t spdm_response_size;
+    1736                 :            :         size_t transport_header_size;
+    1737                 :            : 
+    1738                 :            :         ((libspdm_context_t *)spdm_context)
+    1739                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    1740                 :            :             m_libspdm_use_measurement_hash_algo;
+    1741                 :          1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
+    1742                 :            :                              sizeof(spdm_measurement_block_dmtf_t) +
+    1743                 :          1 :                              libspdm_get_measurement_hash_size(
+    1744                 :            :             m_libspdm_use_measurement_hash_algo) +
+    1745                 :            :                              SPDM_NONCE_SIZE + sizeof(uint16_t);
+    1746                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1747                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1748                 :            : 
+    1749                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1750                 :          1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
+    1751                 :          1 :         spdm_response->header.param1 = 0;
+    1752                 :          1 :         spdm_response->header.param2 = 0;
+    1753                 :          1 :         spdm_response->number_of_blocks = 1;
+    1754                 :          1 :         libspdm_write_uint24(
+    1755                 :          1 :             spdm_response->measurement_record_length,
+    1756                 :            :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
+    1757                 :          1 :                        libspdm_get_measurement_hash_size(
+    1758                 :            :                            m_libspdm_use_measurement_hash_algo)));
+    1759                 :          1 :         measurment_block = (void *)(spdm_response + 1);
+    1760                 :          1 :         libspdm_set_mem(measurment_block,
+    1761                 :            :                         sizeof(spdm_measurement_block_dmtf_t) +
+    1762                 :          1 :                         libspdm_get_measurement_hash_size(
+    1763                 :            :                             m_libspdm_use_measurement_hash_algo),
+    1764                 :            :                         1);
+    1765                 :          1 :         measurment_block->measurement_block_common_header.index = 1;
+    1766                 :            :         measurment_block->measurement_block_common_header
+    1767                 :          1 :         .measurement_specification =
+    1768                 :          1 :             (uint8_t)(m_libspdm_use_measurement_spec << 1);
+    1769                 :            :         measurment_block->measurement_block_common_header
+    1770                 :          1 :         .measurement_size =
+    1771                 :          1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
+    1772                 :          1 :                        libspdm_get_measurement_hash_size(
+    1773                 :            :                            m_libspdm_use_measurement_hash_algo));
+    1774                 :            : 
+    1775                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1776                 :            :                                               false, spdm_response_size,
+    1777                 :            :                                               spdm_response, response_size,
+    1778                 :            :                                               response);
+    1779                 :            :     }
+    1780                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1781                 :            : 
+    1782                 :        100 :     case 0x16: {
+    1783                 :            :         spdm_measurements_response_t *spdm_response;
+    1784                 :            :         spdm_measurement_block_dmtf_t *measurment_block;
+    1785                 :            :         size_t spdm_response_size;
+    1786                 :            :         size_t transport_header_size;
+    1787                 :            :         uint8_t *ptr;
+    1788                 :            :         ((libspdm_context_t *)spdm_context)
+    1789                 :        100 :         ->connection_info.algorithm.measurement_hash_algo =
+    1790                 :            :             m_libspdm_use_measurement_hash_algo;
+    1791                 :        100 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
+    1792                 :            :                              sizeof(spdm_measurement_block_dmtf_t) +
+    1793                 :        100 :                              libspdm_get_measurement_hash_size(
+    1794                 :            :             m_libspdm_use_measurement_hash_algo) +
+    1795                 :            :                              SPDM_NONCE_SIZE + sizeof(uint16_t);
+    1796                 :        100 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1797                 :        100 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1798                 :            : 
+    1799                 :        100 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1800                 :        100 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
+    1801                 :        100 :         spdm_response->header.param1 = 0;
+    1802                 :        100 :         spdm_response->header.param2 = 0;
+    1803                 :        100 :         spdm_response->number_of_blocks = 1;
+    1804                 :        100 :         libspdm_write_uint24(
+    1805                 :        100 :             spdm_response->measurement_record_length,
+    1806                 :            :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
+    1807                 :        100 :                        libspdm_get_measurement_hash_size(
+    1808                 :            :                            m_libspdm_use_measurement_hash_algo)));
+    1809                 :        100 :         measurment_block = (void *)(spdm_response + 1);
+    1810                 :        100 :         libspdm_set_mem(measurment_block,
+    1811                 :            :                         sizeof(spdm_measurement_block_dmtf_t) +
+    1812                 :        100 :                         libspdm_get_measurement_hash_size(
+    1813                 :            :                             m_libspdm_use_measurement_hash_algo),
+    1814                 :            :                         1);
+    1815                 :            :         measurment_block->measurement_block_common_header
+    1816                 :        100 :         .measurement_specification =
+    1817                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1818                 :            :         measurment_block->measurement_block_common_header
+    1819                 :        100 :         .measurement_size =
+    1820                 :        100 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
+    1821                 :        100 :                        libspdm_get_measurement_hash_size(
+    1822                 :            :                            m_libspdm_use_measurement_hash_algo));
+    1823                 :        100 :         *(uint16_t *)((uint8_t *)spdm_response +
+    1824                 :            :                       sizeof(spdm_measurements_response_t) +
+    1825                 :        100 :                       sizeof(spdm_measurement_block_dmtf_t) +
+    1826                 :        100 :                       libspdm_get_measurement_hash_size(
+    1827                 :        100 :                           m_libspdm_use_measurement_hash_algo)) = 0;
+    1828                 :        100 :         ptr = (uint8_t *)spdm_response + spdm_response_size - SPDM_NONCE_SIZE - sizeof(uint16_t);
+    1829                 :        100 :         libspdm_get_random_number(SPDM_NONCE_SIZE,ptr);
+    1830                 :        100 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1831                 :            :                                               false, spdm_response_size,
+    1832                 :            :                                               spdm_response, response_size,
+    1833                 :            :                                               response);
+    1834                 :            :     }
+    1835                 :        100 :         return LIBSPDM_STATUS_SUCCESS;
+    1836                 :            : 
+    1837                 :          1 :     case 0x17: {
+    1838                 :            :         spdm_measurements_response_t *spdm_response;
+    1839                 :            :         uint8_t *ptr;
+    1840                 :            :         spdm_measurement_block_dmtf_t *measurment_block;
+    1841                 :            :         size_t spdm_response_size;
+    1842                 :            :         size_t transport_header_size;
+    1843                 :            : 
+    1844                 :            :         ((libspdm_context_t *)spdm_context)
+    1845                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    1846                 :            :             m_libspdm_use_measurement_hash_algo;
+    1847                 :          1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
+    1848                 :            :                              sizeof(spdm_measurement_block_dmtf_t) +
+    1849                 :          1 :                              libspdm_get_measurement_hash_size(
+    1850                 :            :             m_libspdm_use_measurement_hash_algo) +
+    1851                 :            :                              SPDM_NONCE_SIZE +
+    1852                 :            :                              sizeof(uint16_t) + SPDM_MAX_OPAQUE_DATA_SIZE;
+    1853                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1854                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1855                 :            : 
+    1856                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1857                 :          1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
+    1858                 :          1 :         spdm_response->header.param1 = 0;
+    1859                 :          1 :         spdm_response->header.param2 = 0;
+    1860                 :          1 :         spdm_response->number_of_blocks = 1;
+    1861                 :          1 :         libspdm_write_uint24(
+    1862                 :          1 :             spdm_response->measurement_record_length,
+    1863                 :            :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
+    1864                 :          1 :                        libspdm_get_measurement_hash_size(
+    1865                 :            :                            m_libspdm_use_measurement_hash_algo)));
+    1866                 :          1 :         measurment_block = (void *)(spdm_response + 1);
+    1867                 :          1 :         libspdm_set_mem(measurment_block,
+    1868                 :            :                         sizeof(spdm_measurement_block_dmtf_t) +
+    1869                 :          1 :                         libspdm_get_measurement_hash_size(
+    1870                 :            :                             m_libspdm_use_measurement_hash_algo),
+    1871                 :            :                         1);
+    1872                 :            :         measurment_block->measurement_block_common_header
+    1873                 :          1 :         .measurement_specification =
+    1874                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1875                 :            :         measurment_block->measurement_block_common_header
+    1876                 :          1 :         .measurement_size =
+    1877                 :          1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
+    1878                 :          1 :                        libspdm_get_measurement_hash_size(
+    1879                 :            :                            m_libspdm_use_measurement_hash_algo));
+    1880                 :            :         /* adding extra fields: opaque_length, opaque_data*/
+    1881                 :          1 :         ptr = (void *)((uint8_t *)spdm_response +
+    1882                 :            :                        sizeof(spdm_measurements_response_t) +
+    1883                 :          1 :                        sizeof(spdm_measurement_block_dmtf_t) +
+    1884                 :          1 :                        libspdm_get_measurement_hash_size(
+    1885                 :            :                            m_libspdm_use_measurement_hash_algo));
+    1886                 :          1 :         libspdm_get_random_number (SPDM_NONCE_SIZE, ptr);
+    1887                 :          1 :         ptr += SPDM_NONCE_SIZE;
+    1888                 :          1 :         *(uint16_t *)ptr = SPDM_MAX_OPAQUE_DATA_SIZE; /* opaque_length*/
+    1889                 :          1 :         ptr += sizeof(uint16_t);
+    1890                 :          1 :         libspdm_set_mem(ptr, SPDM_MAX_OPAQUE_DATA_SIZE, 255);
+    1891                 :          1 :         ptr += SPDM_MAX_OPAQUE_DATA_SIZE;
+    1892                 :            : 
+    1893                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1894                 :            :                                               false, spdm_response_size,
+    1895                 :            :                                               spdm_response, response_size,
+    1896                 :            :                                               response);
+    1897                 :            :     }
+    1898                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1899                 :            : 
+    1900                 :          1 :     case 0x18: {
+    1901                 :            :         spdm_measurements_response_t *spdm_response;
+    1902                 :            :         uint8_t *ptr;
+    1903                 :            :         spdm_measurement_block_dmtf_t *measurment_block;
+    1904                 :            :         size_t spdm_response_size;
+    1905                 :            :         size_t transport_header_size;
+    1906                 :            : 
+    1907                 :            :         ((libspdm_context_t *)spdm_context)
+    1908                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    1909                 :            :             m_libspdm_use_measurement_hash_algo;
+    1910                 :          1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
+    1911                 :            :                              sizeof(spdm_measurement_block_dmtf_t) +
+    1912                 :          1 :                              libspdm_get_measurement_hash_size(
+    1913                 :            :             m_libspdm_use_measurement_hash_algo) +
+    1914                 :            :                              SPDM_NONCE_SIZE +
+    1915                 :            :                              sizeof(uint16_t) +
+    1916                 :            :                              (SPDM_MAX_OPAQUE_DATA_SIZE + 1);
+    1917                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1918                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1919                 :            : 
+    1920                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1921                 :          1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
+    1922                 :          1 :         spdm_response->header.param1 = 0;
+    1923                 :          1 :         spdm_response->header.param2 = 0;
+    1924                 :          1 :         spdm_response->number_of_blocks = 1;
+    1925                 :          1 :         libspdm_write_uint24(
+    1926                 :          1 :             spdm_response->measurement_record_length,
+    1927                 :            :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
+    1928                 :          1 :                        libspdm_get_measurement_hash_size(
+    1929                 :            :                            m_libspdm_use_measurement_hash_algo)));
+    1930                 :          1 :         measurment_block = (void *)(spdm_response + 1);
+    1931                 :          1 :         libspdm_set_mem(measurment_block,
+    1932                 :            :                         sizeof(spdm_measurement_block_dmtf_t) +
+    1933                 :          1 :                         libspdm_get_measurement_hash_size(
+    1934                 :            :                             m_libspdm_use_measurement_hash_algo),
+    1935                 :            :                         1);
+    1936                 :            :         measurment_block->measurement_block_common_header
+    1937                 :          1 :         .measurement_specification =
+    1938                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1939                 :            :         measurment_block->measurement_block_common_header
+    1940                 :          1 :         .measurement_size =
+    1941                 :          1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
+    1942                 :          1 :                        libspdm_get_measurement_hash_size(
+    1943                 :            :                            m_libspdm_use_measurement_hash_algo));
+    1944                 :            :         /* adding extra fields: opaque_length, opaque_data*/
+    1945                 :          1 :         ptr = (void *)((uint8_t *)spdm_response +
+    1946                 :            :                        sizeof(spdm_measurements_response_t) +
+    1947                 :          1 :                        sizeof(spdm_measurement_block_dmtf_t) +
+    1948                 :          1 :                        libspdm_get_measurement_hash_size(
+    1949                 :            :                            m_libspdm_use_measurement_hash_algo));
+    1950                 :          1 :         ptr += SPDM_NONCE_SIZE;
+    1951                 :          1 :         *(uint16_t *)ptr =
+    1952                 :            :             (SPDM_MAX_OPAQUE_DATA_SIZE + 1); /* opaque_length*/
+    1953                 :          1 :         ptr += sizeof(uint16_t);
+    1954                 :          1 :         libspdm_set_mem(ptr, (SPDM_MAX_OPAQUE_DATA_SIZE + 1), 255);
+    1955                 :          1 :         ptr += (SPDM_MAX_OPAQUE_DATA_SIZE + 1);
+    1956                 :            : 
+    1957                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1958                 :            :                                               false, spdm_response_size,
+    1959                 :            :                                               spdm_response, response_size,
+    1960                 :            :                                               response);
+    1961                 :            :     }
+    1962                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1963                 :            : 
+    1964                 :          1 :     case 0x19: {
+    1965                 :            :         spdm_measurements_response_t *spdm_response;
+    1966                 :            :         uint8_t *ptr;
+    1967                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1968                 :            :         size_t sig_size;
+    1969                 :            :         size_t measurment_sig_size;
+    1970                 :            :         spdm_measurement_block_dmtf_t *measurment_block;
+    1971                 :            :         size_t spdm_response_size;
+    1972                 :            :         size_t transport_header_size;
+    1973                 :          1 :         uint16_t opaque_size_test = SPDM_MAX_OPAQUE_DATA_SIZE;
+    1974                 :            : 
+    1975                 :            :         ((libspdm_context_t *)spdm_context)
+    1976                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    1977                 :            :             m_libspdm_use_asym_algo;
+    1978                 :            :         ((libspdm_context_t *)spdm_context)
+    1979                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    1980                 :            :             m_libspdm_use_hash_algo;
+    1981                 :            :         ((libspdm_context_t *)spdm_context)
+    1982                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    1983                 :            :             m_libspdm_use_measurement_hash_algo;
+    1984                 :          1 :         measurment_sig_size =
+    1985                 :          2 :             SPDM_NONCE_SIZE + sizeof(uint16_t) + opaque_size_test +
+    1986                 :          1 :             libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    1987                 :          1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
+    1988                 :            :                              sizeof(spdm_measurement_block_dmtf_t) +
+    1989                 :          1 :                              libspdm_get_measurement_hash_size(
+    1990                 :          1 :             m_libspdm_use_measurement_hash_algo) +
+    1991                 :            :                              measurment_sig_size;
+    1992                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1993                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1994                 :            : 
+    1995                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1996                 :          1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
+    1997                 :          1 :         spdm_response->header.param1 = 0;
+    1998                 :          1 :         spdm_response->header.param2 = 0;
+    1999                 :          1 :         spdm_response->number_of_blocks = 1;
+    2000                 :          1 :         libspdm_write_uint24(
+    2001                 :          1 :             spdm_response->measurement_record_length,
+    2002                 :            :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
+    2003                 :          1 :                        libspdm_get_measurement_hash_size(
+    2004                 :            :                            m_libspdm_use_measurement_hash_algo)));
+    2005                 :          1 :         measurment_block = (void *)(spdm_response + 1);
+    2006                 :          1 :         libspdm_set_mem(measurment_block,
+    2007                 :            :                         sizeof(spdm_measurement_block_dmtf_t) +
+    2008                 :          1 :                         libspdm_get_measurement_hash_size(
+    2009                 :            :                             m_libspdm_use_measurement_hash_algo),
+    2010                 :            :                         1);
+    2011                 :            :         measurment_block->measurement_block_common_header
+    2012                 :          1 :         .measurement_specification =
+    2013                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    2014                 :            :         measurment_block->measurement_block_common_header
+    2015                 :          1 :         .measurement_size =
+    2016                 :          1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
+    2017                 :          1 :                        libspdm_get_measurement_hash_size(
+    2018                 :            :                            m_libspdm_use_measurement_hash_algo));
+    2019                 :          1 :         ptr = (void *)((uint8_t *)spdm_response + spdm_response_size -
+    2020                 :            :                        measurment_sig_size);
+    2021                 :          1 :         libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
+    2022                 :          1 :         ptr += SPDM_NONCE_SIZE;
+    2023                 :            : 
+    2024                 :          1 :         *(uint16_t *)ptr = opaque_size_test; /* opaque_length*/
+    2025                 :          1 :         ptr += sizeof(uint16_t);
+    2026                 :          1 :         libspdm_set_mem(ptr, opaque_size_test, 255);
+    2027                 :          1 :         ptr += opaque_size_test;
+    2028                 :            : 
+    2029                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    2030                 :            :                          sizeof(m_libspdm_local_buffer)
+    2031                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    2032                 :            :                             m_libspdm_local_buffer),
+    2033                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    2034                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    2035                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    2036                 :            :                        m_libspdm_local_buffer_size));
+    2037                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    2038                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
+    2039                 :            :                          m_libspdm_local_buffer_size, hash_data);
+    2040                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
+    2041                 :            :                        libspdm_get_hash_size(m_libspdm_use_hash_algo)));
+    2042                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    2043                 :          1 :         sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    2044                 :          1 :         libspdm_responder_data_sign(
+    2045                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    2046                 :            :             spdm_context,
+    2047                 :            : #endif
+    2048                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    2049                 :            :                 SPDM_MEASUREMENTS,
+    2050                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    2051                 :            :                 false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
+    2052                 :            :                 ptr, &sig_size);
+    2053                 :          1 :         ptr += sig_size;
+    2054                 :            : 
+    2055                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    2056                 :            :                                               false, spdm_response_size,
+    2057                 :            :                                               spdm_response, response_size,
+    2058                 :            :                                               response);
+    2059                 :            :     }
+    2060                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    2061                 :            : 
+    2062                 :          1 :     case 0x1A: {
+    2063                 :            :         spdm_measurements_response_t *spdm_response;
+    2064                 :            :         uint8_t *ptr;
+    2065                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2066                 :            :         size_t sig_size;
+    2067                 :            :         size_t measurment_sig_size;
+    2068                 :            :         spdm_measurement_block_dmtf_t *measurment_block;
+    2069                 :            :         size_t spdm_response_size;
+    2070                 :            :         size_t transport_header_size;
+    2071                 :            :         size_t MissingBytes;
+    2072                 :          1 :         uint16_t opaque_size_test = SPDM_MAX_OPAQUE_DATA_SIZE;
+    2073                 :            : 
+    2074                 :          1 :         sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    2075                 :          1 :         MissingBytes = sig_size;
+    2076                 :            : 
+    2077                 :            :         ((libspdm_context_t *)spdm_context)
+    2078                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    2079                 :            :             m_libspdm_use_asym_algo;
+    2080                 :            :         ((libspdm_context_t *)spdm_context)
+    2081                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    2082                 :            :             m_libspdm_use_hash_algo;
+    2083                 :            :         ((libspdm_context_t *)spdm_context)
+    2084                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    2085                 :            :             m_libspdm_use_measurement_hash_algo;
+    2086                 :          1 :         measurment_sig_size =
+    2087                 :            :             SPDM_NONCE_SIZE + sizeof(uint16_t) +
+    2088                 :          2 :             (opaque_size_test - MissingBytes) +
+    2089                 :          1 :             libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    2090                 :          1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
+    2091                 :            :                              sizeof(spdm_measurement_block_dmtf_t) +
+    2092                 :          1 :                              libspdm_get_measurement_hash_size(
+    2093                 :          1 :             m_libspdm_use_measurement_hash_algo) +
+    2094                 :            :                              measurment_sig_size;
+    2095                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2096                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2097                 :            : 
+    2098                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2099                 :          1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
+    2100                 :          1 :         spdm_response->header.param1 = 0;
+    2101                 :          1 :         spdm_response->header.param2 = 0;
+    2102                 :          1 :         spdm_response->number_of_blocks = 1;
+    2103                 :          1 :         libspdm_write_uint24(
+    2104                 :          1 :             spdm_response->measurement_record_length,
+    2105                 :            :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
+    2106                 :          1 :                        libspdm_get_measurement_hash_size(
+    2107                 :            :                            m_libspdm_use_measurement_hash_algo)));
+    2108                 :          1 :         measurment_block = (void *)(spdm_response + 1);
+    2109                 :          1 :         libspdm_set_mem(measurment_block,
+    2110                 :            :                         sizeof(spdm_measurement_block_dmtf_t) +
+    2111                 :          1 :                         libspdm_get_measurement_hash_size(
+    2112                 :            :                             m_libspdm_use_measurement_hash_algo),
+    2113                 :            :                         1);
+    2114                 :            :         measurment_block->measurement_block_common_header
+    2115                 :          1 :         .measurement_specification =
+    2116                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    2117                 :            :         measurment_block->measurement_block_common_header
+    2118                 :          1 :         .measurement_size =
+    2119                 :          1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
+    2120                 :          1 :                        libspdm_get_measurement_hash_size(
+    2121                 :            :                            m_libspdm_use_measurement_hash_algo));
+    2122                 :          1 :         ptr = (void *)((uint8_t *)spdm_response + spdm_response_size -
+    2123                 :            :                        measurment_sig_size);
+    2124                 :          1 :         libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
+    2125                 :          1 :         ptr += SPDM_NONCE_SIZE;
+    2126                 :            : 
+    2127                 :          1 :         *(uint16_t *)ptr = opaque_size_test; /* opaque_length*/
+    2128                 :          1 :         ptr += sizeof(uint16_t);
+    2129                 :          1 :         libspdm_set_mem(ptr, opaque_size_test - MissingBytes, 255);
+    2130                 :          1 :         ptr += (opaque_size_test - MissingBytes);
+    2131                 :            : 
+    2132                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    2133                 :            :                          sizeof(m_libspdm_local_buffer)
+    2134                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    2135                 :            :                             m_libspdm_local_buffer),
+    2136                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    2137                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    2138                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    2139                 :            :                        m_libspdm_local_buffer_size));
+    2140                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    2141                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
+    2142                 :            :                          m_libspdm_local_buffer_size, hash_data);
+    2143                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
+    2144                 :            :                        libspdm_get_hash_size(m_libspdm_use_hash_algo)));
+    2145                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    2146                 :          1 :         libspdm_responder_data_sign(
+    2147                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    2148                 :            :             spdm_context,
+    2149                 :            : #endif
+    2150                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    2151                 :            :                 SPDM_MEASUREMENTS,
+    2152                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    2153                 :            :                 false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
+    2154                 :            :                 ptr, &sig_size);
+    2155                 :          1 :         ptr += sig_size;
+    2156                 :            : 
+    2157                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    2158                 :            :                                               false, spdm_response_size,
+    2159                 :            :                                               spdm_response, response_size,
+    2160                 :            :                                               response);
+    2161                 :            :     }
+    2162                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    2163                 :            : 
+    2164                 :          1 :     case 0x1B: {
+    2165                 :            :         spdm_measurements_response_t *spdm_response;
+    2166                 :            :         uint8_t *ptr;
+    2167                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2168                 :            :         size_t sig_size;
+    2169                 :            :         size_t measurment_sig_size;
+    2170                 :            :         spdm_measurement_block_dmtf_t *measurment_block;
+    2171                 :            :         size_t spdm_response_size;
+    2172                 :            :         size_t transport_header_size;
+    2173                 :            :         size_t MissingBytes;
+    2174                 :          1 :         uint16_t opaque_size_test = SPDM_MAX_OPAQUE_DATA_SIZE;
+    2175                 :            : 
+    2176                 :          1 :         sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    2177                 :          1 :         MissingBytes = sig_size + 1;
+    2178                 :            : 
+    2179                 :            :         ((libspdm_context_t *)spdm_context)
+    2180                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    2181                 :            :             m_libspdm_use_asym_algo;
+    2182                 :            :         ((libspdm_context_t *)spdm_context)
+    2183                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    2184                 :            :             m_libspdm_use_hash_algo;
+    2185                 :            :         ((libspdm_context_t *)spdm_context)
+    2186                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    2187                 :            :             m_libspdm_use_measurement_hash_algo;
+    2188                 :          1 :         measurment_sig_size =
+    2189                 :            :             SPDM_NONCE_SIZE + sizeof(uint16_t) +
+    2190                 :          2 :             (opaque_size_test - MissingBytes) +
+    2191                 :          1 :             libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    2192                 :          1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
+    2193                 :            :                              sizeof(spdm_measurement_block_dmtf_t) +
+    2194                 :          1 :                              libspdm_get_measurement_hash_size(
+    2195                 :          1 :             m_libspdm_use_measurement_hash_algo) +
+    2196                 :            :                              measurment_sig_size;
+    2197                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2198                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2199                 :            : 
+    2200                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2201                 :          1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
+    2202                 :          1 :         spdm_response->header.param1 = 0;
+    2203                 :          1 :         spdm_response->header.param2 = 0;
+    2204                 :          1 :         spdm_response->number_of_blocks = 1;
+    2205                 :          1 :         libspdm_write_uint24(
+    2206                 :          1 :             spdm_response->measurement_record_length,
+    2207                 :            :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
+    2208                 :          1 :                        libspdm_get_measurement_hash_size(
+    2209                 :            :                            m_libspdm_use_measurement_hash_algo)));
+    2210                 :          1 :         measurment_block = (void *)(spdm_response + 1);
+    2211                 :          1 :         libspdm_set_mem(measurment_block,
+    2212                 :            :                         sizeof(spdm_measurement_block_dmtf_t) +
+    2213                 :          1 :                         libspdm_get_measurement_hash_size(
+    2214                 :            :                             m_libspdm_use_measurement_hash_algo),
+    2215                 :            :                         1);
+    2216                 :            :         measurment_block->measurement_block_common_header
+    2217                 :          1 :         .measurement_specification =
+    2218                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    2219                 :            :         measurment_block->measurement_block_common_header
+    2220                 :          1 :         .measurement_size =
+    2221                 :          1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
+    2222                 :          1 :                        libspdm_get_measurement_hash_size(
+    2223                 :            :                            m_libspdm_use_measurement_hash_algo));
+    2224                 :          1 :         ptr = (void *)((uint8_t *)spdm_response + spdm_response_size -
+    2225                 :            :                        measurment_sig_size);
+    2226                 :          1 :         libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
+    2227                 :          1 :         ptr += SPDM_NONCE_SIZE;
+    2228                 :            : 
+    2229                 :          1 :         *(uint16_t *)ptr = opaque_size_test; /* opaque_length*/
+    2230                 :          1 :         ptr += sizeof(uint16_t);
+    2231                 :          1 :         libspdm_set_mem(ptr, opaque_size_test - MissingBytes, 255);
+    2232                 :          1 :         ptr += (opaque_size_test - MissingBytes);
+    2233                 :            : 
+    2234                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    2235                 :            :                          sizeof(m_libspdm_local_buffer)
+    2236                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    2237                 :            :                             m_libspdm_local_buffer),
+    2238                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    2239                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    2240                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    2241                 :            :                        m_libspdm_local_buffer_size));
+    2242                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    2243                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
+    2244                 :            :                          m_libspdm_local_buffer_size, hash_data);
+    2245                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
+    2246                 :            :                        libspdm_get_hash_size(m_libspdm_use_hash_algo)));
+    2247                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    2248                 :          1 :         libspdm_responder_data_sign(
+    2249                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    2250                 :            :             spdm_context,
+    2251                 :            : #endif
+    2252                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    2253                 :            :                 SPDM_MEASUREMENTS,
+    2254                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    2255                 :            :                 false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
+    2256                 :            :                 ptr, &sig_size);
+    2257                 :          1 :         ptr += sig_size;
+    2258                 :            : 
+    2259                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    2260                 :            :                                               false, spdm_response_size,
+    2261                 :            :                                               spdm_response, response_size,
+    2262                 :            :                                               response);
+    2263                 :            :     }
+    2264                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    2265                 :            : 
+    2266                 :          1 :     case 0x1C: {
+    2267                 :            :         spdm_measurements_response_t *spdm_response;
+    2268                 :            :         uint8_t *ptr;
+    2269                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2270                 :            :         size_t sig_size;
+    2271                 :            :         size_t measurment_sig_size;
+    2272                 :            :         spdm_measurement_block_dmtf_t *measurment_block;
+    2273                 :            :         size_t spdm_response_size;
+    2274                 :            :         size_t transport_header_size;
+    2275                 :          1 :         uint16_t opaque_size_test = SPDM_MAX_OPAQUE_DATA_SIZE / 2;
+    2276                 :          1 :         uint16_t opaque_informed_size = opaque_size_test - 1;
+    2277                 :            : 
+    2278                 :          1 :         sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    2279                 :            : 
+    2280                 :            :         ((libspdm_context_t *)spdm_context)
+    2281                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    2282                 :            :             m_libspdm_use_asym_algo;
+    2283                 :            :         ((libspdm_context_t *)spdm_context)
+    2284                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    2285                 :            :             m_libspdm_use_hash_algo;
+    2286                 :            :         ((libspdm_context_t *)spdm_context)
+    2287                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    2288                 :            :             m_libspdm_use_measurement_hash_algo;
+    2289                 :          1 :         measurment_sig_size =
+    2290                 :          2 :             SPDM_NONCE_SIZE + sizeof(uint16_t) + opaque_size_test +
+    2291                 :          1 :             libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    2292                 :          1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
+    2293                 :            :                              sizeof(spdm_measurement_block_dmtf_t) +
+    2294                 :          1 :                              libspdm_get_measurement_hash_size(
+    2295                 :          1 :             m_libspdm_use_measurement_hash_algo) +
+    2296                 :            :                              measurment_sig_size;
+    2297                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2298                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2299                 :            : 
+    2300                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2301                 :          1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
+    2302                 :          1 :         spdm_response->header.param1 = 0;
+    2303                 :          1 :         spdm_response->header.param2 = 0;
+    2304                 :          1 :         spdm_response->number_of_blocks = 1;
+    2305                 :          1 :         libspdm_write_uint24(
+    2306                 :          1 :             spdm_response->measurement_record_length,
+    2307                 :            :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
+    2308                 :          1 :                        libspdm_get_measurement_hash_size(
+    2309                 :            :                            m_libspdm_use_measurement_hash_algo)));
+    2310                 :          1 :         measurment_block = (void *)(spdm_response + 1);
+    2311                 :          1 :         libspdm_set_mem(measurment_block,
+    2312                 :            :                         sizeof(spdm_measurement_block_dmtf_t) +
+    2313                 :          1 :                         libspdm_get_measurement_hash_size(
+    2314                 :            :                             m_libspdm_use_measurement_hash_algo),
+    2315                 :            :                         1);
+    2316                 :            :         measurment_block->measurement_block_common_header
+    2317                 :          1 :         .measurement_specification =
+    2318                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    2319                 :            :         measurment_block->measurement_block_common_header
+    2320                 :          1 :         .measurement_size =
+    2321                 :          1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
+    2322                 :          1 :                        libspdm_get_measurement_hash_size(
+    2323                 :            :                            m_libspdm_use_measurement_hash_algo));
+    2324                 :          1 :         ptr = (void *)((uint8_t *)spdm_response + spdm_response_size -
+    2325                 :            :                        measurment_sig_size);
+    2326                 :          1 :         libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
+    2327                 :          1 :         ptr += SPDM_NONCE_SIZE;
+    2328                 :            : 
+    2329                 :          1 :         *(uint16_t *)ptr = opaque_informed_size; /* opaque_length*/
+    2330                 :          1 :         ptr += sizeof(uint16_t);
+    2331                 :          1 :         libspdm_set_mem(ptr, opaque_size_test, 255);
+    2332                 :          1 :         ptr += (opaque_size_test);
+    2333                 :            : 
+    2334                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    2335                 :            :                          sizeof(m_libspdm_local_buffer)
+    2336                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    2337                 :            :                             m_libspdm_local_buffer),
+    2338                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    2339                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    2340                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    2341                 :            :                        m_libspdm_local_buffer_size));
+    2342                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    2343                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
+    2344                 :            :                          m_libspdm_local_buffer_size, hash_data);
+    2345                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
+    2346                 :            :                        libspdm_get_hash_size(m_libspdm_use_hash_algo)));
+    2347                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    2348                 :          1 :         libspdm_responder_data_sign(
+    2349                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    2350                 :            :             spdm_context,
+    2351                 :            : #endif
+    2352                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    2353                 :            :                 SPDM_MEASUREMENTS,
+    2354                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    2355                 :            :                 false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
+    2356                 :            :                 ptr, &sig_size);
+    2357                 :          1 :         ptr += sig_size;
+    2358                 :            : 
+    2359                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    2360                 :            :                                               false, spdm_response_size,
+    2361                 :            :                                               spdm_response, response_size,
+    2362                 :            :                                               response);
+    2363                 :            :     }
+    2364                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    2365                 :            : 
+    2366                 :          1 :     case 0x1D: {
+    2367                 :            :         spdm_measurements_response_t *spdm_response;
+    2368                 :            :         uint8_t *ptr;
+    2369                 :            :         spdm_measurement_block_dmtf_t *measurment_block;
+    2370                 :            :         size_t spdm_response_size;
+    2371                 :            :         size_t transport_header_size;
+    2372                 :          1 :         uint16_t opaque_size_test = SPDM_MAX_OPAQUE_DATA_SIZE / 2;
+    2373                 :          1 :         uint16_t opaque_informed_size = opaque_size_test - 1;
+    2374                 :            : 
+    2375                 :            :         ((libspdm_context_t *)spdm_context)
+    2376                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    2377                 :            :             m_libspdm_use_measurement_hash_algo;
+    2378                 :          1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
+    2379                 :            :                              sizeof(spdm_measurement_block_dmtf_t) +
+    2380                 :          1 :                              libspdm_get_measurement_hash_size(
+    2381                 :            :             m_libspdm_use_measurement_hash_algo) +
+    2382                 :            :                              SPDM_NONCE_SIZE +
+    2383                 :          1 :                              sizeof(uint16_t) + opaque_size_test;
+    2384                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2385                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2386                 :            : 
+    2387                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2388                 :          1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
+    2389                 :          1 :         spdm_response->header.param1 = 0;
+    2390                 :          1 :         spdm_response->header.param2 = 0;
+    2391                 :          1 :         spdm_response->number_of_blocks = 1;
+    2392                 :          1 :         libspdm_write_uint24(
+    2393                 :          1 :             spdm_response->measurement_record_length,
+    2394                 :            :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
+    2395                 :          1 :                        libspdm_get_measurement_hash_size(
+    2396                 :            :                            m_libspdm_use_measurement_hash_algo)));
+    2397                 :          1 :         measurment_block = (void *)(spdm_response + 1);
+    2398                 :          1 :         libspdm_set_mem(measurment_block,
+    2399                 :            :                         sizeof(spdm_measurement_block_dmtf_t) +
+    2400                 :          1 :                         libspdm_get_measurement_hash_size(
+    2401                 :            :                             m_libspdm_use_measurement_hash_algo),
+    2402                 :            :                         1);
+    2403                 :            :         measurment_block->measurement_block_common_header
+    2404                 :          1 :         .measurement_specification =
+    2405                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    2406                 :            :         measurment_block->measurement_block_common_header
+    2407                 :          1 :         .measurement_size =
+    2408                 :          1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
+    2409                 :          1 :                        libspdm_get_measurement_hash_size(
+    2410                 :            :                            m_libspdm_use_measurement_hash_algo));
+    2411                 :            :         /* adding extra fields: opaque_length, opaque_data*/
+    2412                 :          1 :         ptr = (void *)((uint8_t *)spdm_response +
+    2413                 :            :                        sizeof(spdm_measurements_response_t) +
+    2414                 :          1 :                        sizeof(spdm_measurement_block_dmtf_t) +
+    2415                 :          1 :                        libspdm_get_measurement_hash_size(
+    2416                 :            :                            m_libspdm_use_measurement_hash_algo));
+    2417                 :          1 :         libspdm_get_random_number (SPDM_NONCE_SIZE, ptr);
+    2418                 :          1 :         ptr += SPDM_NONCE_SIZE;
+    2419                 :          1 :         *(uint16_t *)ptr = opaque_informed_size; /* opaque_length*/
+    2420                 :          1 :         ptr += sizeof(uint16_t);
+    2421                 :          1 :         libspdm_set_mem(ptr, opaque_size_test, 255);
+    2422                 :          1 :         ptr += opaque_size_test;
+    2423                 :            : 
+    2424                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    2425                 :            :                                               false, spdm_response_size,
+    2426                 :            :                                               spdm_response, response_size,
+    2427                 :            :                                               response);
+    2428                 :            :     }
+    2429                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    2430                 :            : 
+    2431                 :          0 :     case 0x1E: {
+    2432                 :            :         spdm_measurements_response_t *spdm_response;
+    2433                 :            :         uint8_t *ptr;
+    2434                 :            :         spdm_measurement_block_dmtf_t *measurment_block;
+    2435                 :            :         size_t spdm_response_size;
+    2436                 :            :         size_t transport_header_size;
+    2437                 :          0 :         uint16_t opaque_size_test = 0xFFFF;
+    2438                 :          0 :         uint16_t opaque_informed_size = SPDM_MAX_OPAQUE_DATA_SIZE / 2;
+    2439                 :            : 
+    2440                 :            :         ((libspdm_context_t *)spdm_context)
+    2441                 :          0 :         ->connection_info.algorithm.measurement_hash_algo =
+    2442                 :            :             m_libspdm_use_measurement_hash_algo;
+    2443                 :          0 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
+    2444                 :            :                              sizeof(spdm_measurement_block_dmtf_t) +
+    2445                 :          0 :                              libspdm_get_measurement_hash_size(
+    2446                 :            :             m_libspdm_use_measurement_hash_algo) +
+    2447                 :            :                              SPDM_NONCE_SIZE +
+    2448                 :          0 :                              sizeof(uint16_t) + opaque_size_test;
+    2449                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2450                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2451                 :            : 
+    2452                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2453                 :          0 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
+    2454                 :          0 :         spdm_response->header.param1 = 0;
+    2455                 :          0 :         spdm_response->header.param2 = 0;
+    2456                 :          0 :         spdm_response->number_of_blocks = 1;
+    2457                 :          0 :         libspdm_write_uint24(
+    2458                 :          0 :             spdm_response->measurement_record_length,
+    2459                 :            :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
+    2460                 :          0 :                        libspdm_get_measurement_hash_size(
+    2461                 :            :                            m_libspdm_use_measurement_hash_algo)));
+    2462                 :          0 :         measurment_block = (void *)(spdm_response + 1);
+    2463                 :          0 :         libspdm_set_mem(measurment_block,
+    2464                 :            :                         sizeof(spdm_measurement_block_dmtf_t) +
+    2465                 :          0 :                         libspdm_get_measurement_hash_size(
+    2466                 :            :                             m_libspdm_use_measurement_hash_algo),
+    2467                 :            :                         1);
+    2468                 :            :         measurment_block->measurement_block_common_header
+    2469                 :          0 :         .measurement_specification =
+    2470                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    2471                 :            :         measurment_block->measurement_block_common_header
+    2472                 :          0 :         .measurement_size =
+    2473                 :          0 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
+    2474                 :          0 :                        libspdm_get_measurement_hash_size(
+    2475                 :            :                            m_libspdm_use_measurement_hash_algo));
+    2476                 :            :         /* adding extra fields: NONCE, opaque_length, opaque_data*/
+    2477                 :          0 :         ptr = (void *)((uint8_t *)spdm_response +
+    2478                 :            :                        sizeof(spdm_measurements_response_t) +
+    2479                 :          0 :                        sizeof(spdm_measurement_block_dmtf_t) +
+    2480                 :          0 :                        libspdm_get_measurement_hash_size(
+    2481                 :            :                            m_libspdm_use_measurement_hash_algo));
+    2482                 :          0 :         ptr += SPDM_NONCE_SIZE;
+    2483                 :          0 :         *(uint16_t *)ptr = opaque_informed_size; /* opaque_length*/
+    2484                 :          0 :         ptr += sizeof(uint16_t);
+    2485                 :          0 :         libspdm_set_mem(ptr, opaque_size_test, 255);
+    2486                 :          0 :         ptr += opaque_size_test;
+    2487                 :            : 
+    2488                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    2489                 :            :                                               false, spdm_response_size,
+    2490                 :            :                                               spdm_response, response_size,
+    2491                 :            :                                               response);
+    2492                 :            :     }
+    2493                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+    2494                 :            : 
+    2495                 :          0 :     case 0x1F: {
+    2496                 :            :         spdm_measurements_response_t *spdm_response;
+    2497                 :            :         uint8_t *ptr;
+    2498                 :            :         spdm_measurement_block_dmtf_t *measurment_block;
+    2499                 :            :         size_t spdm_response_size;
+    2500                 :            :         size_t transport_header_size;
+    2501                 :          0 :         uint16_t opaque_size_test = 0xFFFF;
+    2502                 :            : 
+    2503                 :            :         ((libspdm_context_t *)spdm_context)
+    2504                 :          0 :         ->connection_info.algorithm.measurement_hash_algo =
+    2505                 :            :             m_libspdm_use_measurement_hash_algo;
+    2506                 :          0 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
+    2507                 :            :                              sizeof(spdm_measurement_block_dmtf_t) +
+    2508                 :          0 :                              libspdm_get_measurement_hash_size(
+    2509                 :            :             m_libspdm_use_measurement_hash_algo) +
+    2510                 :          0 :                              SPDM_NONCE_SIZE + sizeof(uint16_t) +
+    2511                 :            :                              opaque_size_test;
+    2512                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2513                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2514                 :            : 
+    2515                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2516                 :          0 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
+    2517                 :          0 :         spdm_response->header.param1 = 0;
+    2518                 :          0 :         spdm_response->header.param2 = 0;
+    2519                 :          0 :         spdm_response->number_of_blocks = 1;
+    2520                 :          0 :         libspdm_write_uint24(
+    2521                 :          0 :             spdm_response->measurement_record_length,
+    2522                 :            :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
+    2523                 :          0 :                        libspdm_get_measurement_hash_size(
+    2524                 :            :                            m_libspdm_use_measurement_hash_algo)));
+    2525                 :          0 :         measurment_block = (void *)(spdm_response + 1);
+    2526                 :          0 :         libspdm_set_mem(measurment_block,
+    2527                 :            :                         sizeof(spdm_measurement_block_dmtf_t) +
+    2528                 :          0 :                         libspdm_get_measurement_hash_size(
+    2529                 :            :                             m_libspdm_use_measurement_hash_algo),
+    2530                 :            :                         1);
+    2531                 :            :         measurment_block->measurement_block_common_header
+    2532                 :          0 :         .measurement_specification =
+    2533                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    2534                 :            :         measurment_block->measurement_block_common_header
+    2535                 :          0 :         .measurement_size =
+    2536                 :          0 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
+    2537                 :          0 :                        libspdm_get_measurement_hash_size(
+    2538                 :            :                            m_libspdm_use_measurement_hash_algo));
+    2539                 :            :         /* adding extra fields: NONCE, opaque_length, opaque_data*/
+    2540                 :          0 :         ptr = (void *)((uint8_t *)spdm_response +
+    2541                 :            :                        sizeof(spdm_measurements_response_t) +
+    2542                 :          0 :                        sizeof(spdm_measurement_block_dmtf_t) +
+    2543                 :          0 :                        libspdm_get_measurement_hash_size(
+    2544                 :            :                            m_libspdm_use_measurement_hash_algo));
+    2545                 :          0 :         libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
+    2546                 :          0 :         ptr += SPDM_NONCE_SIZE;
+    2547                 :          0 :         *(uint16_t *)ptr = (opaque_size_test); /* opaque_length*/
+    2548                 :          0 :         ptr += sizeof(uint16_t);
+    2549                 :          0 :         libspdm_set_mem(ptr, (opaque_size_test), 255);
+    2550                 :          0 :         ptr += (opaque_size_test);
+    2551                 :            : 
+    2552                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    2553                 :            :                                               false, spdm_response_size,
+    2554                 :            :                                               spdm_response, response_size,
+    2555                 :            :                                               response);
+    2556                 :            :     }
+    2557                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+    2558                 :            : 
+    2559                 :          1 :     case 0x20: {
+    2560                 :            :         spdm_measurements_response_t *spdm_response;
+    2561                 :            :         spdm_measurement_block_dmtf_t *measurment_block;
+    2562                 :            :         size_t spdm_response_size;
+    2563                 :            :         size_t transport_header_size;
+    2564                 :            :         uint8_t *ptr;
+    2565                 :            :         ((libspdm_context_t *)spdm_context)
+    2566                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    2567                 :            :             m_libspdm_use_measurement_hash_algo;
+    2568                 :          1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
+    2569                 :            :                              2 * (sizeof(spdm_measurement_block_dmtf_t) +
+    2570                 :          1 :                                   libspdm_get_measurement_hash_size(
+    2571                 :          1 :                                       m_libspdm_use_measurement_hash_algo)) +
+    2572                 :            :                              SPDM_NONCE_SIZE;
+    2573                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2574                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2575                 :            : 
+    2576                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2577                 :          1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
+    2578                 :          1 :         spdm_response->header.param1 = 0;
+    2579                 :          1 :         spdm_response->header.param2 = 0;
+    2580                 :          1 :         spdm_response->number_of_blocks = 2;
+    2581                 :          1 :         *(uint32_t *)spdm_response->measurement_record_length =
+    2582                 :          1 :             2 * ((uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
+    2583                 :          1 :                             libspdm_get_measurement_hash_size(
+    2584                 :            :                                 m_libspdm_use_measurement_hash_algo)));
+    2585                 :          1 :         measurment_block = (void *)(spdm_response + 1);
+    2586                 :          1 :         libspdm_set_mem(measurment_block,
+    2587                 :          1 :                         2 * (sizeof(spdm_measurement_block_dmtf_t) +
+    2588                 :          1 :                              libspdm_get_measurement_hash_size(
+    2589                 :            :                                  m_libspdm_use_measurement_hash_algo)),
+    2590                 :            :                         1);
+    2591                 :          1 :         measurment_block->measurement_block_common_header.index = 1;
+    2592                 :            :         measurment_block->measurement_block_common_header
+    2593                 :          1 :         .measurement_specification =
+    2594                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    2595                 :            :         measurment_block->measurement_block_common_header
+    2596                 :          1 :         .measurement_size =
+    2597                 :          1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
+    2598                 :          1 :                        libspdm_get_measurement_hash_size(
+    2599                 :            :                            m_libspdm_use_measurement_hash_algo));
+    2600                 :          1 :         measurment_block =
+    2601                 :            :             (void *)(((uint8_t *)measurment_block) +
+    2602                 :          1 :                      (sizeof(spdm_measurement_block_dmtf_t) +
+    2603                 :          1 :                       libspdm_get_measurement_hash_size(
+    2604                 :            :                           m_libspdm_use_measurement_hash_algo)));
+    2605                 :          1 :         measurment_block->measurement_block_common_header.index = 2;
+    2606                 :            :         measurment_block->measurement_block_common_header
+    2607                 :          1 :         .measurement_specification =
+    2608                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    2609                 :            :         measurment_block->measurement_block_common_header
+    2610                 :          1 :         .measurement_size =
+    2611                 :          1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
+    2612                 :          1 :                        libspdm_get_measurement_hash_size(
+    2613                 :            :                            m_libspdm_use_measurement_hash_algo));
+    2614                 :          1 :         ptr =  (uint8_t *)spdm_response + spdm_response_size - SPDM_NONCE_SIZE;
+    2615                 :          1 :         libspdm_get_random_number(SPDM_NONCE_SIZE,ptr);
+    2616                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    2617                 :            :                                               false, spdm_response_size,
+    2618                 :            :                                               spdm_response, response_size,
+    2619                 :            :                                               response);
+    2620                 :            :     }
+    2621                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    2622                 :            : 
+    2623                 :         18 :     case 0x21:
+    2624                 :            :     {
+    2625                 :            :         static uint16_t error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
+    2626                 :            : 
+    2627                 :            :         spdm_error_response_t *spdm_response;
+    2628                 :            :         size_t spdm_response_size;
+    2629                 :            :         size_t transport_header_size;
+    2630                 :            : 
+    2631                 :         18 :         spdm_response_size = sizeof(spdm_error_response_t);
+    2632                 :         18 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2633                 :         18 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2634                 :            : 
+    2635         [ +  - ]:         18 :         if(error_code <= 0xff) {
+    2636                 :         18 :             libspdm_zero_mem (spdm_response, spdm_response_size);
+    2637                 :         18 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2638                 :         18 :             spdm_response->header.request_response_code = SPDM_ERROR;
+    2639                 :         18 :             spdm_response->header.param1 = (uint8_t) error_code;
+    2640                 :         18 :             spdm_response->header.param2 = 0;
+    2641                 :            : 
+    2642                 :         18 :             libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+    2643                 :            :                                                    spdm_response_size, spdm_response,
+    2644                 :            :                                                    response_size, response);
+    2645                 :            :         }
+    2646                 :            : 
+    2647                 :         18 :         error_code++;
+    2648         [ +  + ]:         18 :         if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
+    2649                 :          1 :             error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
+    2650                 :            :         }
+    2651         [ +  + ]:         18 :         if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) { /*skip some reserved error codes (0d to 3e)*/
+    2652                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
+    2653                 :            :         }
+    2654         [ +  + ]:         18 :         if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) { /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
+    2655                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
+    2656                 :            :         }
+    2657                 :            :     }
+    2658                 :         18 :         return LIBSPDM_STATUS_SUCCESS;
+    2659                 :          1 :     case 0x22: {
+    2660                 :            :         spdm_measurements_response_t *spdm_response;
+    2661                 :            :         uint8_t *ptr;
+    2662                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2663                 :            :         size_t sig_size;
+    2664                 :            :         size_t measurment_sig_size;
+    2665                 :            :         spdm_measurement_block_dmtf_t *measurment_block;
+    2666                 :            :         size_t spdm_response_size;
+    2667                 :            :         size_t transport_header_size;
+    2668                 :            :         uint32_t session_id;
+    2669                 :            :         libspdm_session_info_t *session_info;
+    2670                 :            :         uint8_t *scratch_buffer;
+    2671                 :            :         size_t scratch_buffer_size;
+    2672                 :            : 
+    2673                 :          1 :         session_id = 0xFFFFFFFF;
+    2674                 :            :         ((libspdm_context_t *)spdm_context)
+    2675                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    2676                 :            :             m_libspdm_use_asym_algo;
+    2677                 :            :         ((libspdm_context_t *)spdm_context)
+    2678                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    2679                 :            :             m_libspdm_use_hash_algo;
+    2680                 :            :         ((libspdm_context_t *)spdm_context)
+    2681                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    2682                 :            :             m_libspdm_use_measurement_hash_algo;
+    2683                 :          1 :         measurment_sig_size =
+    2684                 :            :             SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
+    2685                 :          1 :             libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    2686                 :          1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
+    2687                 :            :                              sizeof(spdm_measurement_block_dmtf_t) +
+    2688                 :          1 :                              libspdm_get_measurement_hash_size(
+    2689                 :          1 :             m_libspdm_use_measurement_hash_algo) +
+    2690                 :            :                              measurment_sig_size;
+    2691                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2692                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2693                 :            : 
+    2694                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2695                 :          1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
+    2696                 :          1 :         spdm_response->header.param1 = 0;
+    2697                 :          1 :         spdm_response->header.param2 = 0;
+    2698                 :          1 :         spdm_response->number_of_blocks = 1;
+    2699                 :          1 :         libspdm_write_uint24(
+    2700                 :          1 :             spdm_response->measurement_record_length,
+    2701                 :            :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
+    2702                 :          1 :                        libspdm_get_measurement_hash_size(
+    2703                 :            :                            m_libspdm_use_measurement_hash_algo)));
+    2704                 :          1 :         measurment_block = (void *)(spdm_response + 1);
+    2705                 :          1 :         libspdm_set_mem(measurment_block,
+    2706                 :            :                         sizeof(spdm_measurement_block_dmtf_t) +
+    2707                 :          1 :                         libspdm_get_measurement_hash_size(
+    2708                 :            :                             m_libspdm_use_measurement_hash_algo),
+    2709                 :            :                         1);
+    2710                 :            :         measurment_block->measurement_block_common_header
+    2711                 :          1 :         .measurement_specification =
+    2712                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    2713                 :            :         measurment_block->measurement_block_common_header
+    2714                 :          1 :         .measurement_size =
+    2715                 :          1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
+    2716                 :          1 :                        libspdm_get_measurement_hash_size(
+    2717                 :            :                            m_libspdm_use_measurement_hash_algo));
+    2718                 :          1 :         ptr = (void *)((uint8_t *)spdm_response + spdm_response_size -
+    2719                 :            :                        measurment_sig_size);
+    2720                 :          1 :         libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
+    2721                 :          1 :         ptr += SPDM_NONCE_SIZE;
+    2722                 :          1 :         *(uint16_t *)ptr = 0;
+    2723                 :          1 :         ptr += sizeof(uint16_t);
+    2724                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    2725                 :            :                          sizeof(m_libspdm_local_buffer)
+    2726                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    2727                 :            :                             m_libspdm_local_buffer),
+    2728                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    2729                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    2730                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    2731                 :            :                        m_libspdm_local_buffer_size));
+    2732                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    2733                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
+    2734                 :            :                          m_libspdm_local_buffer_size, hash_data);
+    2735                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
+    2736                 :            :                        libspdm_get_hash_size(m_libspdm_use_hash_algo)));
+    2737                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    2738                 :          1 :         sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    2739                 :          1 :         libspdm_responder_data_sign(
+    2740                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    2741                 :            :             spdm_context,
+    2742                 :            : #endif
+    2743                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    2744                 :            :                 SPDM_MEASUREMENTS,
+    2745                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    2746                 :            :                 false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
+    2747                 :            :                 ptr, &sig_size);
+    2748                 :          1 :         ptr += sig_size;
+    2749                 :            : 
+    2750                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    2751                 :            :          * transport_message is always in sender buffer. */
+    2752                 :          1 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+    2753                 :          1 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+    2754                 :            :                           scratch_buffer_size - transport_header_size,
+    2755                 :            :                           spdm_response, spdm_response_size);
+    2756                 :          1 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+    2757                 :          1 :         libspdm_transport_test_encode_message(spdm_context, &session_id, false,
+    2758                 :            :                                               false, spdm_response_size,
+    2759                 :            :                                               spdm_response, response_size,
+    2760                 :            :                                               response);
+    2761                 :          1 :         session_info = libspdm_get_session_info_via_session_id(
+    2762                 :            :             spdm_context, session_id);
+    2763         [ -  + ]:          1 :         if (session_info == NULL) {
+    2764                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+    2765                 :            :         }
+    2766                 :            :         /* WALKAROUND: If just use single context to encode message and then decode message */
+    2767                 :          1 :         ((libspdm_secured_message_context_t *)(session_info->secured_message_context))
+    2768                 :          1 :         ->application_secret.response_data_sequence_number--;
+    2769                 :            :     }
+    2770                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    2771                 :            : 
+    2772                 :          1 :     case 0x23: {
+    2773                 :            :         spdm_measurements_response_t *spdm_response;
+    2774                 :            :         spdm_measurement_block_dmtf_t *measurment_block;
+    2775                 :            :         size_t spdm_response_size;
+    2776                 :            :         size_t transport_header_size;
+    2777                 :            :         uint8_t *ptr;
+    2778                 :          1 :         ((libspdm_context_t *)spdm_context)->connection_info.algorithm.measurement_hash_algo =
+    2779                 :            :             m_libspdm_use_measurement_hash_algo;
+    2780                 :          1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
+    2781                 :            :                              sizeof(spdm_measurement_block_dmtf_t) +
+    2782                 :          1 :                              libspdm_get_measurement_hash_size(
+    2783                 :            :             m_libspdm_use_measurement_hash_algo) + SPDM_NONCE_SIZE + sizeof(uint16_t);
+    2784                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2785                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2786                 :            : 
+    2787                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2788                 :          1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
+    2789                 :          1 :         spdm_response->header.param1 = 0;
+    2790                 :          1 :         spdm_response->header.param2 = 0;
+    2791                 :          1 :         spdm_response->number_of_blocks = 1;
+    2792                 :          1 :         libspdm_write_uint24(
+    2793                 :          1 :             spdm_response->measurement_record_length,
+    2794                 :            :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
+    2795                 :          1 :                        libspdm_get_measurement_hash_size(m_libspdm_use_measurement_hash_algo)));
+    2796                 :          1 :         measurment_block = (void *)(spdm_response + 1);
+    2797                 :          1 :         libspdm_set_mem(measurment_block,
+    2798                 :            :                         sizeof(spdm_measurement_block_dmtf_t) +
+    2799                 :          1 :                         libspdm_get_measurement_hash_size(m_libspdm_use_measurement_hash_algo), 1);
+    2800                 :          1 :         measurment_block->measurement_block_common_header.measurement_specification =
+    2801                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    2802                 :          1 :         measurment_block->measurement_block_common_header.measurement_size =
+    2803                 :          1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
+    2804                 :          1 :                        libspdm_get_measurement_hash_size(m_libspdm_use_measurement_hash_algo));
+    2805                 :            : 
+    2806                 :          1 :         ptr = (uint8_t *)spdm_response +
+    2807                 :            :               sizeof(spdm_measurements_response_t) +
+    2808                 :          1 :               sizeof(spdm_measurement_block_dmtf_t) +
+    2809                 :          1 :               libspdm_get_measurement_hash_size(m_libspdm_use_measurement_hash_algo);
+    2810                 :          1 :         libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
+    2811                 :          1 :         *(uint16_t *)(ptr + SPDM_NONCE_SIZE) = 0;
+    2812                 :            : 
+    2813                 :          1 :         libspdm_copy_mem (m_libspdm_local_buffer + m_libspdm_local_buffer_size,
+    2814                 :            :                           sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
+    2815                 :            :                           spdm_response, spdm_response_size);
+    2816                 :          1 :         m_libspdm_local_buffer_size += spdm_response_size;
+    2817                 :            : 
+    2818                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    2819                 :            :                                               false, spdm_response_size,
+    2820                 :            :                                               spdm_response, response_size,
+    2821                 :            :                                               response);
+    2822                 :            :     }
+    2823                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    2824                 :            : 
+    2825                 :          1 :     case 0x24: {
+    2826                 :            :         spdm_measurements_response_t *spdm_response;
+    2827                 :            :         uint8_t *ptr;
+    2828                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2829                 :            :         size_t sig_size;
+    2830                 :            :         size_t measurment_sig_size;
+    2831                 :            :         spdm_measurement_block_dmtf_t *measurment_block;
+    2832                 :            :         size_t spdm_response_size;
+    2833                 :            :         size_t transport_header_size;
+    2834                 :            : 
+    2835                 :            :         ((libspdm_context_t *)spdm_context)
+    2836                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    2837                 :            :             m_libspdm_use_asym_algo;
+    2838                 :            :         ((libspdm_context_t *)spdm_context)
+    2839                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    2840                 :            :             m_libspdm_use_hash_algo;
+    2841                 :            :         ((libspdm_context_t *)spdm_context)
+    2842                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    2843                 :            :             m_libspdm_use_measurement_hash_algo;
+    2844                 :          1 :         measurment_sig_size =
+    2845                 :            :             SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
+    2846                 :          1 :             libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    2847                 :          1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
+    2848                 :            :                              sizeof(spdm_measurement_block_dmtf_t) +
+    2849                 :          1 :                              libspdm_get_measurement_hash_size(
+    2850                 :          1 :             m_libspdm_use_measurement_hash_algo) +
+    2851                 :            :                              measurment_sig_size;
+    2852                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2853                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2854                 :            : 
+    2855                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+    2856                 :          1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
+    2857                 :          1 :         spdm_response->header.param1 = 0;
+    2858                 :          1 :         spdm_response->header.param2 = 0;
+    2859                 :          1 :         spdm_response->number_of_blocks = 1;
+    2860                 :          1 :         libspdm_write_uint24(
+    2861                 :          1 :             spdm_response->measurement_record_length,
+    2862                 :            :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
+    2863                 :          1 :                        libspdm_get_measurement_hash_size(
+    2864                 :            :                            m_libspdm_use_measurement_hash_algo)));
+    2865                 :          1 :         measurment_block = (void *)(spdm_response + 1);
+    2866                 :          1 :         libspdm_set_mem(measurment_block,
+    2867                 :            :                         sizeof(spdm_measurement_block_dmtf_t) +
+    2868                 :          1 :                         libspdm_get_measurement_hash_size(
+    2869                 :            :                             m_libspdm_use_measurement_hash_algo),
+    2870                 :            :                         1);
+    2871                 :            :         measurment_block->measurement_block_common_header
+    2872                 :          1 :         .measurement_specification =
+    2873                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    2874                 :            :         measurment_block->measurement_block_common_header
+    2875                 :          1 :         .measurement_size =
+    2876                 :          1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
+    2877                 :          1 :                        libspdm_get_measurement_hash_size(
+    2878                 :            :                            m_libspdm_use_measurement_hash_algo));
+    2879                 :          1 :         ptr = (void *)((uint8_t *)spdm_response + spdm_response_size -
+    2880                 :            :                        measurment_sig_size);
+    2881                 :          1 :         libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
+    2882                 :          1 :         ptr += SPDM_NONCE_SIZE;
+    2883                 :          1 :         *(uint16_t *)ptr = 0;
+    2884                 :          1 :         ptr += sizeof(uint16_t);
+    2885                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    2886                 :            :                          sizeof(m_libspdm_local_buffer)
+    2887                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    2888                 :            :                             m_libspdm_local_buffer),
+    2889                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    2890                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    2891                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    2892                 :            :                        m_libspdm_local_buffer_size));
+    2893                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    2894                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
+    2895                 :            :                          m_libspdm_local_buffer_size, hash_data);
+    2896                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
+    2897                 :            :                        libspdm_get_hash_size(m_libspdm_use_hash_algo)));
+    2898                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    2899                 :          1 :         sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    2900                 :          1 :         libspdm_responder_data_sign(
+    2901                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    2902                 :            :             spdm_context,
+    2903                 :            : #endif
+    2904                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    2905                 :            :                 SPDM_MEASUREMENTS,
+    2906                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    2907                 :            :                 false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
+    2908                 :            :                 ptr, &sig_size);
+    2909                 :          1 :         ptr += sig_size;
+    2910                 :            : 
+    2911                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    2912                 :            :                                               false, spdm_response_size,
+    2913                 :            :                                               spdm_response, response_size,
+    2914                 :            :                                               response);
+    2915                 :            :     }
+    2916                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    2917                 :          1 :     case 0x25: {
+    2918                 :            :         spdm_measurements_response_t *spdm_response;
+    2919                 :            :         size_t spdm_response_size;
+    2920                 :            :         size_t transport_header_size;
+    2921                 :            :         uint8_t *ptr;
+    2922                 :          1 :         spdm_response_size =
+    2923                 :            :             sizeof(spdm_measurements_response_t)
+    2924                 :            :             + SPDM_NONCE_SIZE + sizeof(uint16_t);
+    2925                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2926                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2927                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+    2928                 :          1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
+    2929                 :          1 :         spdm_response->header.param1 = 4;
+    2930                 :          1 :         spdm_response->header.param2 = 0;
+    2931                 :          1 :         spdm_response->number_of_blocks = 0;
+    2932                 :          1 :         libspdm_write_uint24(spdm_response->measurement_record_length, 0);
+    2933                 :            : 
+    2934                 :          1 :         ptr = (uint8_t *)spdm_response +
+    2935                 :            :               sizeof(spdm_measurements_response_t);
+    2936                 :          1 :         libspdm_get_random_number(SPDM_NONCE_SIZE,ptr);
+    2937                 :          1 :         ptr += SPDM_NONCE_SIZE;
+    2938                 :          1 :         *(uint16_t *)ptr = 0;
+    2939                 :            : 
+    2940                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    2941                 :            :                                               false, spdm_response_size,
+    2942                 :            :                                               spdm_response, response_size,
+    2943                 :            :                                               response);
+    2944                 :            :     }
+    2945                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    2946                 :          1 :     case 0x26: {
+    2947                 :            :         spdm_measurements_response_t *spdm_response;
+    2948                 :            :         uint8_t *ptr;
+    2949                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2950                 :            :         size_t sig_size;
+    2951                 :            :         size_t measurment_sig_size;
+    2952                 :            :         spdm_measurement_block_dmtf_t *measurment_block;
+    2953                 :            :         size_t spdm_response_size;
+    2954                 :            :         size_t transport_header_size;
+    2955                 :            : 
+    2956                 :            :         ((libspdm_context_t *)spdm_context)
+    2957                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    2958                 :            :             m_libspdm_use_asym_algo;
+    2959                 :            :         ((libspdm_context_t *)spdm_context)
+    2960                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    2961                 :            :             m_libspdm_use_hash_algo;
+    2962                 :            :         ((libspdm_context_t *)spdm_context)
+    2963                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    2964                 :            :             m_libspdm_use_measurement_hash_algo;
+    2965                 :          1 :         measurment_sig_size =
+    2966                 :            :             SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
+    2967                 :          1 :             libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    2968                 :          1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
+    2969                 :            :                              sizeof(spdm_measurement_block_dmtf_t) +
+    2970                 :          1 :                              libspdm_get_measurement_hash_size(
+    2971                 :          1 :             m_libspdm_use_measurement_hash_algo) +
+    2972                 :            :                              measurment_sig_size;
+    2973                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2974                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2975                 :            : 
+    2976                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+    2977                 :          1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
+    2978                 :          1 :         spdm_response->header.param1 = 0;
+    2979                 :          1 :         spdm_response->header.param2 = 0x0F;
+    2980                 :          1 :         spdm_response->number_of_blocks = 1;
+    2981                 :          1 :         libspdm_write_uint24(
+    2982                 :          1 :             spdm_response->measurement_record_length,
+    2983                 :            :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
+    2984                 :          1 :                        libspdm_get_measurement_hash_size(
+    2985                 :            :                            m_libspdm_use_measurement_hash_algo)));
+    2986                 :          1 :         measurment_block = (void *)(spdm_response + 1);
+    2987                 :          1 :         libspdm_set_mem(measurment_block,
+    2988                 :            :                         sizeof(spdm_measurement_block_dmtf_t) +
+    2989                 :          1 :                         libspdm_get_measurement_hash_size(
+    2990                 :            :                             m_libspdm_use_measurement_hash_algo),
+    2991                 :            :                         1);
+    2992                 :            :         measurment_block->measurement_block_common_header
+    2993                 :          1 :         .measurement_specification =
+    2994                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    2995                 :            :         measurment_block->measurement_block_common_header
+    2996                 :          1 :         .measurement_size =
+    2997                 :          1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
+    2998                 :          1 :                        libspdm_get_measurement_hash_size(
+    2999                 :            :                            m_libspdm_use_measurement_hash_algo));
+    3000                 :          1 :         ptr = (void *)((uint8_t *)spdm_response + spdm_response_size -
+    3001                 :            :                        measurment_sig_size);
+    3002                 :          1 :         libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
+    3003                 :          1 :         ptr += SPDM_NONCE_SIZE;
+    3004                 :          1 :         *(uint16_t *)ptr = 0;
+    3005                 :          1 :         ptr += sizeof(uint16_t);
+    3006                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    3007                 :            :                          sizeof(m_libspdm_local_buffer)
+    3008                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    3009                 :            :                             m_libspdm_local_buffer),
+    3010                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    3011                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    3012                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    3013                 :            :                        m_libspdm_local_buffer_size));
+    3014                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    3015                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
+    3016                 :            :                          m_libspdm_local_buffer_size, hash_data);
+    3017                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
+    3018                 :            :                        libspdm_get_hash_size(m_libspdm_use_hash_algo)));
+    3019                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    3020                 :          1 :         sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    3021                 :          1 :         libspdm_responder_data_sign(
+    3022                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    3023                 :            :             spdm_context,
+    3024                 :            : #endif
+    3025                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    3026                 :            :                 SPDM_MEASUREMENTS,
+    3027                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    3028                 :            :                 false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
+    3029                 :            :                 ptr, &sig_size);
+    3030                 :          1 :         ptr += sig_size;
+    3031                 :            : 
+    3032                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    3033                 :            :                                               false, spdm_response_size,
+    3034                 :            :                                               spdm_response, response_size,
+    3035                 :            :                                               response);
+    3036                 :            :     }
+    3037                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    3038                 :          1 :     case 0x27: {
+    3039                 :            :         spdm_measurements_response_t *spdm_response;
+    3040                 :            :         spdm_general_opaque_data_table_header_t
+    3041                 :            :         *spdm_general_opaque_data_table_header;
+    3042                 :            :         opaque_element_table_header_t
+    3043                 :            :         *opaque_element_table_header;
+    3044                 :            :         uint8_t *ptr;
+    3045                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    3046                 :            :         size_t sig_size;
+    3047                 :            :         size_t measurment_sig_size;
+    3048                 :            :         spdm_measurement_block_dmtf_t *measurment_block;
+    3049                 :            :         size_t spdm_response_size;
+    3050                 :            :         size_t transport_header_size;
+    3051                 :            :         uint8_t element_num;
+    3052                 :            :         uint8_t element_index;
+    3053                 :            :         size_t current_element_len;
+    3054                 :            :         uint16_t opaque_element_data_len;
+    3055                 :            : 
+    3056                 :            :         ((libspdm_context_t *)spdm_context)
+    3057                 :          1 :         ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    3058                 :            :         ((libspdm_context_t *)spdm_context)
+    3059                 :          1 :         ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    3060                 :            :         ((libspdm_context_t *)spdm_context)
+    3061                 :          1 :         ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+    3062                 :            : 
+    3063                 :          1 :         spdm_general_opaque_data_table_header = (void *)m_libspdm_opaque_data;
+    3064                 :          1 :         spdm_general_opaque_data_table_header->total_elements = 2;
+    3065                 :          1 :         opaque_element_table_header = (void *)(spdm_general_opaque_data_table_header + 1);
+    3066                 :            : 
+    3067                 :          1 :         element_num = spdm_general_opaque_data_table_header->total_elements;
+    3068                 :          1 :         m_libspdm_opaque_data_size = sizeof(spdm_general_opaque_data_table_header_t);
+    3069                 :            : 
+    3070         [ +  + ]:          3 :         for (element_index = 0; element_index < element_num; element_index++) {
+    3071                 :          2 :             opaque_element_table_header->id = SPDM_REGISTRY_ID_MAX;
+    3072                 :          2 :             opaque_element_table_header->vendor_len = 0;
+    3073                 :          2 :             opaque_element_data_len = (uint16_t)strlen("libspdm");
+    3074                 :            : 
+    3075                 :          2 :             ptr = (void *)(opaque_element_table_header + 1);
+    3076                 :          2 :             ptr += opaque_element_table_header->vendor_len;
+    3077                 :            : 
+    3078                 :          2 :             libspdm_copy_mem((uint16_t *)ptr,
+    3079                 :            :                              sizeof(opaque_element_data_len),
+    3080                 :            :                              &opaque_element_data_len,
+    3081                 :            :                              sizeof(opaque_element_data_len));
+    3082                 :            : 
+    3083                 :          2 :             libspdm_copy_mem(ptr + sizeof(opaque_element_data_len),
+    3084                 :            :                              SPDM_MAX_OPAQUE_DATA_SIZE -
+    3085                 :            :                              sizeof(opaque_element_table_header_t), "libspdm",
+    3086                 :            :                              strlen("libspdm"));
+    3087                 :            : 
+    3088                 :          2 :             current_element_len = sizeof(opaque_element_table_header_t) +
+    3089                 :          2 :                                   opaque_element_table_header->vendor_len +
+    3090                 :          2 :                                   sizeof(opaque_element_data_len) +
+    3091                 :            :                                   opaque_element_data_len;
+    3092                 :          2 :             current_element_len = (current_element_len + 3) & ~3;
+    3093                 :            : 
+    3094                 :            :             /*move to next element*/
+    3095                 :          2 :             opaque_element_table_header =
+    3096                 :            :                 (opaque_element_table_header_t *)
+    3097                 :            :                 ((uint8_t *)opaque_element_table_header +
+    3098                 :            :                  current_element_len);
+    3099                 :            : 
+    3100                 :          2 :             m_libspdm_opaque_data_size += current_element_len;
+    3101                 :            :         }
+    3102                 :            : 
+    3103                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    3104                 :            : 
+    3105                 :          1 :         measurment_sig_size = SPDM_NONCE_SIZE + sizeof(uint16_t) +
+    3106                 :          1 :                               m_libspdm_opaque_data_size +
+    3107                 :          1 :                               libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    3108                 :          1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
+    3109                 :            :                              sizeof(spdm_measurement_block_dmtf_t) +
+    3110                 :          1 :                              libspdm_get_measurement_hash_size(
+    3111                 :          1 :             m_libspdm_use_measurement_hash_algo) + measurment_sig_size;
+    3112                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    3113                 :            : 
+    3114                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+    3115                 :          1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
+    3116                 :          1 :         spdm_response->header.param1 = 0;
+    3117                 :          1 :         spdm_response->header.param2 = 0;
+    3118                 :          1 :         spdm_response->number_of_blocks = 1;
+    3119                 :          1 :         libspdm_write_uint24(
+    3120                 :          1 :             spdm_response->measurement_record_length,
+    3121                 :            :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
+    3122                 :          1 :                        libspdm_get_measurement_hash_size(
+    3123                 :            :                            m_libspdm_use_measurement_hash_algo)));
+    3124                 :          1 :         measurment_block = (void *)(spdm_response + 1);
+    3125                 :          1 :         libspdm_set_mem(measurment_block,
+    3126                 :            :                         sizeof(spdm_measurement_block_dmtf_t) +
+    3127                 :          1 :                         libspdm_get_measurement_hash_size(
+    3128                 :            :                             m_libspdm_use_measurement_hash_algo), 1);
+    3129                 :            :         measurment_block->measurement_block_common_header
+    3130                 :          1 :         .measurement_specification = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    3131                 :          1 :         measurment_block->measurement_block_common_header.measurement_size =
+    3132                 :          1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
+    3133                 :          1 :                        libspdm_get_measurement_hash_size(
+    3134                 :            :                            m_libspdm_use_measurement_hash_algo));
+    3135                 :          1 :         ptr = (void *)((uint8_t *)spdm_response + spdm_response_size - measurment_sig_size);
+    3136                 :          1 :         libspdm_set_mem(ptr, SPDM_NONCE_SIZE, 0x12);
+    3137                 :          1 :         ptr += SPDM_NONCE_SIZE;
+    3138                 :            : 
+    3139                 :          1 :         *(uint16_t *)ptr = (uint16_t)m_libspdm_opaque_data_size;
+    3140                 :          1 :         ptr += sizeof(uint16_t);
+    3141                 :          1 :         libspdm_copy_mem(ptr, (size_t)(*response) + *response_size - (size_t)ptr,
+    3142                 :            :                          m_libspdm_opaque_data,
+    3143                 :            :                          m_libspdm_opaque_data_size);
+    3144                 :          1 :         ptr += m_libspdm_opaque_data_size;
+    3145                 :            : 
+    3146                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    3147                 :            :                          sizeof(m_libspdm_local_buffer)
+    3148                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    3149                 :            :                             m_libspdm_local_buffer),
+    3150                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    3151                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    3152                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    3153                 :            :                        m_libspdm_local_buffer_size));
+    3154                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    3155                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
+    3156                 :            :                          m_libspdm_local_buffer_size, hash_data);
+    3157                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
+    3158                 :            :                        libspdm_get_hash_size(m_libspdm_use_hash_algo)));
+    3159                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    3160                 :          1 :         sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    3161                 :          1 :         libspdm_responder_data_sign(
+    3162                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    3163                 :            :             spdm_context,
+    3164                 :            : #endif
+    3165                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    3166                 :            :                 SPDM_MEASUREMENTS,
+    3167                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    3168                 :            :                 false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
+    3169                 :            :                 ptr, &sig_size);
+    3170                 :          1 :         ptr += sig_size;
+    3171                 :            : 
+    3172                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    3173                 :            :                                               false, spdm_response_size,
+    3174                 :            :                                               spdm_response, response_size,
+    3175                 :            :                                               response);
+    3176                 :            :     }
+    3177                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    3178                 :          1 :     case 0x28: {
+    3179                 :            :         spdm_measurements_response_t *spdm_response;
+    3180                 :            :         spdm_measurement_block_dmtf_t *measurment_block;
+    3181                 :            :         size_t spdm_response_size;
+    3182                 :            :         size_t transport_header_size;
+    3183                 :            :         uint8_t *ptr;
+    3184                 :            :         ((libspdm_context_t *)spdm_context)
+    3185                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    3186                 :            :             m_libspdm_use_measurement_hash_algo;
+    3187                 :          1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
+    3188                 :            :                              sizeof(spdm_measurement_block_dmtf_t) +
+    3189                 :          1 :                              libspdm_get_measurement_hash_size(m_libspdm_use_measurement_hash_algo)
+    3190                 :            :                              + SPDM_NONCE_SIZE + sizeof(uint16_t) + SPDM_REQ_CONTEXT_SIZE;
+    3191                 :            : 
+    3192                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    3193                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    3194                 :            : 
+    3195                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+    3196                 :          1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
+    3197                 :          1 :         spdm_response->header.param1 = 0;
+    3198                 :          1 :         spdm_response->header.param2 = 0;
+    3199                 :          1 :         spdm_response->number_of_blocks = 1;
+    3200                 :          1 :         libspdm_write_uint24(
+    3201                 :          1 :             spdm_response->measurement_record_length,
+    3202                 :            :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
+    3203                 :          1 :                        libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo)));
+    3204                 :            : 
+    3205                 :          1 :         measurment_block = (void *)(spdm_response + 1);
+    3206                 :          1 :         libspdm_set_mem(measurment_block,
+    3207                 :            :                         sizeof(spdm_measurement_block_dmtf_t) +
+    3208                 :          1 :                         libspdm_get_measurement_hash_size(
+    3209                 :            :                             m_libspdm_use_measurement_hash_algo),
+    3210                 :            :                         1);
+    3211                 :            : 
+    3212                 :            :         measurment_block->measurement_block_common_header
+    3213                 :          1 :         .measurement_specification =
+    3214                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    3215                 :            :         measurment_block->measurement_block_common_header
+    3216                 :          1 :         .measurement_size =
+    3217                 :          1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
+    3218                 :          1 :                        libspdm_get_measurement_hash_size(
+    3219                 :            :                            m_libspdm_use_measurement_hash_algo));
+    3220                 :            : 
+    3221                 :          1 :         ptr = (uint8_t *)spdm_response +
+    3222                 :            :               sizeof(spdm_measurements_response_t) +
+    3223                 :          1 :               sizeof(spdm_measurement_block_dmtf_t) +
+    3224                 :          1 :               libspdm_get_measurement_hash_size(
+    3225                 :            :             m_libspdm_use_measurement_hash_algo);
+    3226                 :          1 :         libspdm_get_random_number(SPDM_NONCE_SIZE,ptr);
+    3227                 :            : 
+    3228                 :          1 :         ptr += SPDM_NONCE_SIZE;
+    3229                 :          1 :         *(uint16_t *)ptr = 0;
+    3230                 :            : 
+    3231                 :          1 :         ptr += sizeof(uint16_t);
+    3232                 :          1 :         libspdm_copy_mem(ptr, SPDM_REQ_CONTEXT_SIZE, m_requester_context, SPDM_REQ_CONTEXT_SIZE);
+    3233                 :            : 
+    3234                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer + m_libspdm_local_buffer_size,
+    3235                 :            :                          sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
+    3236                 :            :                          spdm_response, spdm_response_size);
+    3237                 :            : 
+    3238                 :          1 :         m_libspdm_local_buffer_size += spdm_response_size;
+    3239                 :            : 
+    3240                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    3241                 :            :                                               false, spdm_response_size,
+    3242                 :            :                                               spdm_response, response_size,
+    3243                 :            :                                               response);
+    3244                 :            :     }
+    3245                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    3246                 :          1 :     case 0x29: {
+    3247                 :            :         spdm_measurements_response_t *spdm_response;
+    3248                 :            :         spdm_measurement_block_dmtf_t *measurment_block;
+    3249                 :            :         size_t spdm_response_size;
+    3250                 :            :         size_t transport_header_size;
+    3251                 :            :         uint8_t *ptr;
+    3252                 :            :         ((libspdm_context_t *)spdm_context)
+    3253                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    3254                 :            :             m_libspdm_use_measurement_hash_algo;
+    3255                 :          1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
+    3256                 :            :                              sizeof(spdm_measurement_block_dmtf_t) +
+    3257                 :          1 :                              libspdm_get_measurement_hash_size(m_libspdm_use_measurement_hash_algo)
+    3258                 :            :                              +
+    3259                 :            :                              SPDM_NONCE_SIZE + sizeof(uint16_t) + SPDM_REQ_CONTEXT_SIZE;
+    3260                 :            : 
+    3261                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    3262                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    3263                 :            : 
+    3264                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+    3265                 :          1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
+    3266                 :          1 :         spdm_response->header.param1 = 0;
+    3267                 :          1 :         spdm_response->header.param2 = 0;
+    3268                 :          1 :         spdm_response->number_of_blocks = 1;
+    3269                 :          1 :         libspdm_write_uint24(
+    3270                 :          1 :             spdm_response->measurement_record_length,
+    3271                 :            :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
+    3272                 :          1 :                        libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo)));
+    3273                 :            : 
+    3274                 :          1 :         measurment_block = (void *)(spdm_response + 1);
+    3275                 :          1 :         libspdm_set_mem(measurment_block,
+    3276                 :            :                         sizeof(spdm_measurement_block_dmtf_t) +
+    3277                 :          1 :                         libspdm_get_measurement_hash_size(
+    3278                 :            :                             m_libspdm_use_measurement_hash_algo),
+    3279                 :            :                         1);
+    3280                 :            : 
+    3281                 :            :         measurment_block->measurement_block_common_header
+    3282                 :          1 :         .measurement_specification =
+    3283                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    3284                 :            :         measurment_block->measurement_block_common_header
+    3285                 :          1 :         .measurement_size =
+    3286                 :          1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
+    3287                 :          1 :                        libspdm_get_measurement_hash_size(
+    3288                 :            :                            m_libspdm_use_measurement_hash_algo));
+    3289                 :            : 
+    3290                 :          1 :         ptr = (uint8_t *)spdm_response +
+    3291                 :            :               sizeof(spdm_measurements_response_t) +
+    3292                 :          1 :               sizeof(spdm_measurement_block_dmtf_t) +
+    3293                 :          1 :               libspdm_get_measurement_hash_size(
+    3294                 :            :             m_libspdm_use_measurement_hash_algo);
+    3295                 :          1 :         libspdm_get_random_number(SPDM_NONCE_SIZE,ptr);
+    3296                 :            : 
+    3297                 :          1 :         ptr += SPDM_NONCE_SIZE;
+    3298                 :          1 :         *(uint16_t *)ptr = 0;
+    3299                 :            : 
+    3300                 :          1 :         ptr += sizeof(uint16_t);
+    3301                 :          1 :         libspdm_get_random_number(SPDM_REQ_CONTEXT_SIZE,ptr);
+    3302                 :            : 
+    3303                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer + m_libspdm_local_buffer_size,
+    3304                 :            :                          sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
+    3305                 :            :                          spdm_response, spdm_response_size);
+    3306                 :            : 
+    3307                 :          1 :         m_libspdm_local_buffer_size += spdm_response_size;
+    3308                 :            : 
+    3309                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    3310                 :            :                                               false, spdm_response_size,
+    3311                 :            :                                               spdm_response, response_size,
+    3312                 :            :                                               response);
+    3313                 :            :     }
+    3314                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    3315                 :          0 :     default:
+    3316                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+    3317                 :            :     }
+    3318                 :            : }
+    3319                 :            : 
+    3320                 :            : /**
+    3321                 :            :  * Test 1: message could not be sent
+    3322                 :            :  * Expected Behavior: get a RETURN_DEVICE_ERROR return code, with an empty transcript.message_m
+    3323                 :            :  **/
+    3324                 :          1 : static void libspdm_test_requester_get_measurements_case1(void **state)
+    3325                 :            : {
+    3326                 :            :     libspdm_return_t status;
+    3327                 :            :     libspdm_test_context_t *spdm_test_context;
+    3328                 :            :     libspdm_context_t *spdm_context;
+    3329                 :            :     uint8_t number_of_block;
+    3330                 :            :     uint32_t measurement_record_length;
+    3331                 :            :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
+    3332                 :            :     uint8_t request_attribute;
+    3333                 :            :     void *data;
+    3334                 :            :     size_t data_size;
+    3335                 :            :     void *hash;
+    3336                 :            :     size_t hash_size;
+    3337                 :            : 
+    3338                 :          1 :     spdm_test_context = *state;
+    3339                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    3340                 :          1 :     spdm_test_context->case_id = 0x1;
+    3341                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    3342                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3343                 :          1 :     spdm_context->connection_info.connection_state =
+    3344                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    3345                 :          1 :     spdm_context->connection_info.capability.flags |=
+    3346                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    3347                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3348                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    3349                 :            :                                                     &data_size, &hash, &hash_size);
+    3350                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    3351                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    3352                 :            :         m_libspdm_use_measurement_spec;
+    3353                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    3354                 :            :         m_libspdm_use_measurement_hash_algo;
+    3355                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    3356                 :            :         m_libspdm_use_hash_algo;
+    3357                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    3358                 :            :         m_libspdm_use_asym_algo;
+    3359                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    3360                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    3361                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    3362                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    3363                 :            :         data_size;
+    3364                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    3365                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    3366                 :            :                      data, data_size);
+    3367                 :            : #else
+    3368                 :          1 :     libspdm_hash_all(
+    3369                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    3370                 :            :         data, data_size,
+    3371                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    3372                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    3373                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    3374                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    3375                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    3376                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    3377                 :            :         data, data_size,
+    3378                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    3379                 :            : #endif
+    3380                 :            : 
+    3381                 :          1 :     request_attribute =
+    3382                 :            :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
+    3383                 :            : 
+    3384                 :          1 :     measurement_record_length = sizeof(measurement_record);
+    3385                 :          1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
+    3386                 :            :                                      0, NULL, &number_of_block,
+    3387                 :            :                                      &measurement_record_length,
+    3388                 :            :                                      measurement_record);
+    3389                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SEND_FAIL);
+    3390                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    3391                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+    3392                 :            : #endif
+    3393                 :          1 :     free(data);
+    3394                 :          1 : }
+    3395                 :            : 
+    3396                 :            : /**
+    3397                 :            :  * Test 2: Successful response to get a measurement with signature
+    3398                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code, with an empty transcript.message_m
+    3399                 :            :  **/
+    3400                 :          1 : static void libspdm_test_requester_get_measurements_case2(void **state)
+    3401                 :            : {
+    3402                 :            :     libspdm_return_t status;
+    3403                 :            :     libspdm_test_context_t *spdm_test_context;
+    3404                 :            :     libspdm_context_t *spdm_context;
+    3405                 :            :     uint8_t number_of_block;
+    3406                 :            :     uint32_t measurement_record_length;
+    3407                 :            :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
+    3408                 :            :     uint8_t request_attribute;
+    3409                 :            :     void *data;
+    3410                 :            :     size_t data_size;
+    3411                 :            :     void *hash;
+    3412                 :            :     size_t hash_size;
+    3413                 :            : 
+    3414                 :          1 :     spdm_test_context = *state;
+    3415                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    3416                 :          1 :     spdm_test_context->case_id = 0x2;
+    3417                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    3418                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3419                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    3420                 :          1 :     spdm_context->connection_info.capability.flags |=
+    3421                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    3422                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3423                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    3424                 :            :                                                     &data_size, &hash, &hash_size);
+    3425                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    3426                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+    3427                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    3428                 :            :         m_libspdm_use_measurement_hash_algo;
+    3429                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    3430                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    3431                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    3432                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    3433                 :            : 
+    3434                 :            :     #if LIBSPDM_ENABLE_MSG_LOG
+    3435                 :          1 :     libspdm_init_msg_log (spdm_context, m_libspdm_msg_log_buffer, sizeof(m_libspdm_msg_log_buffer));
+    3436                 :          1 :     libspdm_set_msg_log_mode (spdm_context, LIBSPDM_MSG_LOG_MODE_ENABLE);
+    3437                 :            :     #endif /* LIBSPDM_ENABLE_MSG_LOG */
+    3438                 :            : 
+    3439                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    3440                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
+    3441                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    3442                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    3443                 :            :                      data, data_size);
+    3444                 :            : #else
+    3445                 :          1 :     libspdm_hash_all(
+    3446                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    3447                 :            :         data, data_size,
+    3448                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    3449                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    3450                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    3451                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    3452                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    3453                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    3454                 :            :         data, data_size,
+    3455                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    3456                 :            : #endif
+    3457                 :            : 
+    3458                 :          1 :     request_attribute = SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
+    3459                 :            : 
+    3460                 :          1 :     measurement_record_length = sizeof(measurement_record);
+    3461                 :          1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
+    3462                 :            :                                      0, NULL, &number_of_block,
+    3463                 :            :                                      &measurement_record_length,
+    3464                 :            :                                      measurement_record);
+    3465                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    3466                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    3467                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+    3468                 :            : #endif
+    3469                 :          1 :     free(data);
+    3470                 :            : 
+    3471                 :            :     #if LIBSPDM_ENABLE_MSG_LOG
+    3472                 :          1 :     libspdm_reset_msg_log(spdm_context);
+    3473                 :            :     #endif /* LIBSPDM_ENABLE_MSG_LOG */
+    3474                 :          1 : }
+    3475                 :            : 
+    3476                 :            : /**
+    3477                 :            :  * Test 3: Exercise the libspdm_get_measurement_ex function.
+    3478                 :            :  * Expected Behavior: Requester uses requester_nonce_in and returns responder_nonce.
+    3479                 :            :  **/
+    3480                 :          1 : static void libspdm_test_requester_get_measurements_case3(void **state)
+    3481                 :            : {
+    3482                 :            :     libspdm_return_t status;
+    3483                 :            :     libspdm_test_context_t *spdm_test_context;
+    3484                 :            :     libspdm_context_t *spdm_context;
+    3485                 :            :     uint8_t number_of_block;
+    3486                 :            :     uint32_t measurement_record_length;
+    3487                 :            :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
+    3488                 :            :     uint8_t request_attribute;
+    3489                 :            :     void *data;
+    3490                 :            :     size_t data_size;
+    3491                 :            :     void *hash;
+    3492                 :            :     size_t hash_size;
+    3493                 :            :     uint8_t requester_nonce_in[SPDM_NONCE_SIZE];
+    3494                 :            :     uint8_t requester_nonce[SPDM_NONCE_SIZE];
+    3495                 :            :     uint8_t responder_nonce[SPDM_NONCE_SIZE];
+    3496                 :            :     uint8_t opaque_data[SPDM_MAX_OPAQUE_DATA_SIZE];
+    3497                 :            :     size_t opaque_data_size;
+    3498                 :            : 
+    3499                 :          1 :     spdm_test_context = *state;
+    3500                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    3501                 :          1 :     spdm_test_context->case_id = 0x3;
+    3502                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    3503                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3504                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    3505                 :          1 :     spdm_context->connection_info.capability.flags |=
+    3506                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    3507                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3508                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    3509                 :            :                                                     &data_size, &hash, &hash_size);
+    3510                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    3511                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+    3512                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    3513                 :            :         m_libspdm_use_measurement_hash_algo;
+    3514                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    3515                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    3516                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    3517                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    3518                 :            : 
+    3519                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    3520                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
+    3521                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    3522                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    3523                 :            :                      data, data_size);
+    3524                 :            : #else
+    3525                 :          1 :     libspdm_hash_all(
+    3526                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    3527                 :            :         data, data_size,
+    3528                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    3529                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    3530                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    3531                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    3532                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    3533                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    3534                 :            :         data, data_size,
+    3535                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    3536                 :            : #endif
+    3537                 :            : 
+    3538                 :          1 :     request_attribute = SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
+    3539                 :            : 
+    3540                 :          1 :     measurement_record_length = sizeof(measurement_record);
+    3541                 :            : 
+    3542         [ +  + ]:         33 :     for (int index = 0; index < SPDM_NONCE_SIZE; index++) {
+    3543                 :         32 :         requester_nonce_in[index] = 0x5c;
+    3544                 :         32 :         requester_nonce[index] = 0x00;
+    3545                 :         32 :         responder_nonce[index] = 0x00;
+    3546                 :            :     }
+    3547                 :            : 
+    3548                 :          1 :     opaque_data_size = sizeof(opaque_data);
+    3549                 :            : 
+    3550                 :          1 :     status = libspdm_get_measurement_ex(spdm_context, NULL, request_attribute, 1,
+    3551                 :            :                                         0, NULL, &number_of_block,
+    3552                 :            :                                         &measurement_record_length,
+    3553                 :            :                                         measurement_record, requester_nonce_in,
+    3554                 :            :                                         requester_nonce, responder_nonce,
+    3555                 :            :                                         opaque_data, &opaque_data_size);
+    3556                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    3557         [ +  + ]:         33 :     for (int index = 0; index < SPDM_NONCE_SIZE; index++) {
+    3558                 :         32 :         assert_int_equal (requester_nonce_in[index], requester_nonce[index]);
+    3559                 :         32 :         assert_int_equal (responder_nonce[index], 0x12);
+    3560                 :            :     }
+    3561                 :          1 :     assert_int_equal(opaque_data_size, strlen("libspdm"));
+    3562                 :          1 :     assert_memory_equal(opaque_data, "libspdm", strlen("libspdm"));
+    3563                 :            : 
+    3564                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    3565                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+    3566                 :            : #endif
+    3567                 :          1 :     free(data);
+    3568                 :          1 : }
+    3569                 :            : 
+    3570                 :            : /**
+    3571                 :            :  * Test 4: Error case, always get an error response with code SPDM_ERROR_CODE_INVALID_REQUEST
+    3572                 :            :  * Expected Behavior: get a RETURN_DEVICE_ERROR return code, with an empty transcript.message_m
+    3573                 :            :  **/
+    3574                 :          1 : static void libspdm_test_requester_get_measurements_case4(void **state)
+    3575                 :            : {
+    3576                 :            :     libspdm_return_t status;
+    3577                 :            :     libspdm_test_context_t *spdm_test_context;
+    3578                 :            :     libspdm_context_t *spdm_context;
+    3579                 :            :     uint8_t number_of_block;
+    3580                 :            :     uint32_t measurement_record_length;
+    3581                 :            :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
+    3582                 :            :     uint8_t request_attribute;
+    3583                 :            :     void *data;
+    3584                 :            :     size_t data_size;
+    3585                 :            :     void *hash;
+    3586                 :            :     size_t hash_size;
+    3587                 :            : 
+    3588                 :          1 :     spdm_test_context = *state;
+    3589                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    3590                 :          1 :     spdm_test_context->case_id = 0x4;
+    3591                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    3592                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3593                 :          1 :     spdm_context->connection_info.connection_state =
+    3594                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    3595                 :          1 :     spdm_context->connection_info.capability.flags |=
+    3596                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    3597                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3598                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    3599                 :            :                                                     &data_size, &hash, &hash_size);
+    3600                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    3601                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    3602                 :            :         m_libspdm_use_measurement_spec;
+    3603                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    3604                 :            :         m_libspdm_use_measurement_hash_algo;
+    3605                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    3606                 :            :         m_libspdm_use_hash_algo;
+    3607                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    3608                 :            :         m_libspdm_use_asym_algo;
+    3609                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    3610                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    3611                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    3612                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    3613                 :            :         data_size;
+    3614                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    3615                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    3616                 :            :                      data, data_size);
+    3617                 :            : #else
+    3618                 :          1 :     libspdm_hash_all(
+    3619                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    3620                 :            :         data, data_size,
+    3621                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    3622                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    3623                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    3624                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    3625                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    3626                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    3627                 :            :         data, data_size,
+    3628                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    3629                 :            : #endif
+    3630                 :            : 
+    3631                 :          1 :     request_attribute =
+    3632                 :            :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
+    3633                 :            : 
+    3634                 :          1 :     measurement_record_length = sizeof(measurement_record);
+    3635                 :          1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
+    3636                 :            :                                      0, NULL, &number_of_block,
+    3637                 :            :                                      &measurement_record_length,
+    3638                 :            :                                      measurement_record);
+    3639                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_ERROR_PEER);
+    3640                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    3641                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+    3642                 :            : #endif
+    3643                 :          1 :     free(data);
+    3644                 :          1 : }
+    3645                 :            : 
+    3646                 :            : /**
+    3647                 :            :  * Test 5: Error case, always get an error response with code SPDM_ERROR_CODE_BUSY
+    3648                 :            :  * Expected Behavior: get a RETURN_DEVICE_ERROR return code, with an empty transcript.message_m
+    3649                 :            :  **/
+    3650                 :          1 : static void libspdm_test_requester_get_measurements_case5(void **state)
+    3651                 :            : {
+    3652                 :            :     libspdm_return_t status;
+    3653                 :            :     libspdm_test_context_t *spdm_test_context;
+    3654                 :            :     libspdm_context_t *spdm_context;
+    3655                 :            :     uint8_t number_of_block;
+    3656                 :            :     uint32_t measurement_record_length;
+    3657                 :            :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
+    3658                 :            :     uint8_t request_attribute;
+    3659                 :            :     void *data;
+    3660                 :            :     size_t data_size;
+    3661                 :            :     void *hash;
+    3662                 :            :     size_t hash_size;
+    3663                 :            : 
+    3664                 :          1 :     spdm_test_context = *state;
+    3665                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    3666                 :          1 :     spdm_test_context->case_id = 0x5;
+    3667                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    3668                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3669                 :          1 :     spdm_context->connection_info.connection_state =
+    3670                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    3671                 :          1 :     spdm_context->connection_info.capability.flags |=
+    3672                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    3673                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    3674                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    3675                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3676                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    3677                 :            :                                                     &data_size, &hash, &hash_size);
+    3678                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    3679                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    3680                 :            :         m_libspdm_use_measurement_spec;
+    3681                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    3682                 :            :         m_libspdm_use_measurement_hash_algo;
+    3683                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    3684                 :            :         m_libspdm_use_hash_algo;
+    3685                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    3686                 :            :         m_libspdm_use_asym_algo;
+    3687                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    3688                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    3689                 :            :         data_size;
+    3690                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    3691                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    3692                 :            :                      data, data_size);
+    3693                 :            : #else
+    3694                 :          1 :     libspdm_hash_all(
+    3695                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    3696                 :            :         data, data_size,
+    3697                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    3698                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    3699                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    3700                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    3701                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    3702                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    3703                 :            :         data, data_size,
+    3704                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    3705                 :            : #endif
+    3706                 :            : 
+    3707                 :          1 :     request_attribute =
+    3708                 :            :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
+    3709                 :            : 
+    3710                 :          1 :     measurement_record_length = sizeof(measurement_record);
+    3711                 :          1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
+    3712                 :            :                                      0, NULL, &number_of_block,
+    3713                 :            :                                      &measurement_record_length,
+    3714                 :            :                                      measurement_record);
+    3715                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_BUSY_PEER);
+    3716                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    3717                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+    3718                 :            : #endif
+    3719                 :          1 :     free(data);
+    3720                 :          1 : }
+    3721                 :            : 
+    3722                 :            : /**
+    3723                 :            :  * Test 6: Successfully get one measurement block (signed), after getting SPDM_ERROR_CODE_BUSY on first attempt
+    3724                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code, with an empty transcript.message_m
+    3725                 :            :  **/
+    3726                 :          1 : static void libspdm_test_requester_get_measurements_case6(void **state)
+    3727                 :            : {
+    3728                 :            :     libspdm_return_t status;
+    3729                 :            :     libspdm_test_context_t *spdm_test_context;
+    3730                 :            :     libspdm_context_t *spdm_context;
+    3731                 :            :     uint8_t number_of_block;
+    3732                 :            :     uint32_t measurement_record_length;
+    3733                 :            :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
+    3734                 :            :     uint8_t request_attribute;
+    3735                 :            :     void *data;
+    3736                 :            :     size_t data_size;
+    3737                 :            :     void *hash;
+    3738                 :            :     size_t hash_size;
+    3739                 :            : 
+    3740                 :          1 :     spdm_test_context = *state;
+    3741                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    3742                 :          1 :     spdm_test_context->case_id = 0x6;
+    3743                 :          1 :     spdm_context->retry_times = 3;
+    3744                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    3745                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3746                 :          1 :     spdm_context->connection_info.connection_state =
+    3747                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    3748                 :          1 :     spdm_context->connection_info.capability.flags |=
+    3749                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    3750                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    3751                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    3752                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3753                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    3754                 :            :                                                     &data_size, &hash, &hash_size);
+    3755                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    3756                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    3757                 :            :         m_libspdm_use_measurement_spec;
+    3758                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    3759                 :            :         m_libspdm_use_measurement_hash_algo;
+    3760                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    3761                 :            :         m_libspdm_use_hash_algo;
+    3762                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    3763                 :            :         m_libspdm_use_asym_algo;
+    3764                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    3765                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    3766                 :            :         data_size;
+    3767                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    3768                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    3769                 :            :                      data, data_size);
+    3770                 :            : #else
+    3771                 :          1 :     libspdm_hash_all(
+    3772                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    3773                 :            :         data, data_size,
+    3774                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    3775                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    3776                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    3777                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    3778                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    3779                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    3780                 :            :         data, data_size,
+    3781                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    3782                 :            : #endif
+    3783                 :            : 
+    3784                 :          1 :     request_attribute =
+    3785                 :            :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
+    3786                 :            : 
+    3787                 :          1 :     measurement_record_length = sizeof(measurement_record);
+    3788                 :          1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
+    3789                 :            :                                      0, NULL, &number_of_block,
+    3790                 :            :                                      &measurement_record_length,
+    3791                 :            :                                      measurement_record);
+    3792                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    3793                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    3794                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+    3795                 :            : #endif
+    3796                 :          1 :     free(data);
+    3797                 :          1 : }
+    3798                 :            : 
+    3799                 :            : /**
+    3800                 :            :  * Test 7: Error case, get an error response with code SPDM_ERROR_CODE_REQUEST_RESYNCH
+    3801                 :            :  * Expected Behavior: get a RETURN_DEVICE_ERROR return code, with an empty transcript.message_m
+    3802                 :            :  **/
+    3803                 :          1 : static void libspdm_test_requester_get_measurements_case7(void **state)
+    3804                 :            : {
+    3805                 :            :     libspdm_return_t status;
+    3806                 :            :     libspdm_test_context_t *spdm_test_context;
+    3807                 :            :     libspdm_context_t *spdm_context;
+    3808                 :            :     uint8_t number_of_block;
+    3809                 :            :     uint32_t measurement_record_length;
+    3810                 :            :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
+    3811                 :            :     uint8_t request_attribute;
+    3812                 :            :     void *data;
+    3813                 :            :     size_t data_size;
+    3814                 :            :     void *hash;
+    3815                 :            :     size_t hash_size;
+    3816                 :            : 
+    3817                 :          1 :     spdm_test_context = *state;
+    3818                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    3819                 :          1 :     spdm_test_context->case_id = 0x7;
+    3820                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    3821                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3822                 :          1 :     spdm_context->connection_info.connection_state =
+    3823                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    3824                 :          1 :     spdm_context->connection_info.capability.flags |=
+    3825                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    3826                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3827                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    3828                 :            :                                                     &data_size, &hash, &hash_size);
+    3829                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    3830                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    3831                 :            :         m_libspdm_use_measurement_spec;
+    3832                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    3833                 :            :         m_libspdm_use_measurement_hash_algo;
+    3834                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    3835                 :            :         m_libspdm_use_hash_algo;
+    3836                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    3837                 :            :         m_libspdm_use_asym_algo;
+    3838                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    3839                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    3840                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    3841                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    3842                 :            :         data_size;
+    3843                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    3844                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    3845                 :            :                      data, data_size);
+    3846                 :            : #else
+    3847                 :          1 :     libspdm_hash_all(
+    3848                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    3849                 :            :         data, data_size,
+    3850                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    3851                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    3852                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    3853                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    3854                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    3855                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    3856                 :            :         data, data_size,
+    3857                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    3858                 :            : #endif
+    3859                 :            : 
+    3860                 :          1 :     request_attribute =
+    3861                 :            :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
+    3862                 :            : 
+    3863                 :          1 :     measurement_record_length = sizeof(measurement_record);
+    3864                 :          1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
+    3865                 :            :                                      0, NULL, &number_of_block,
+    3866                 :            :                                      &measurement_record_length,
+    3867                 :            :                                      measurement_record);
+    3868                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_RESYNCH_PEER);
+    3869                 :          1 :     assert_int_equal(spdm_context->connection_info.connection_state,
+    3870                 :            :                      LIBSPDM_CONNECTION_STATE_NOT_STARTED);
+    3871                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    3872                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+    3873                 :            : #endif
+    3874                 :          1 :     free(data);
+    3875                 :          1 : }
+    3876                 :            : 
+    3877                 :            : /**
+    3878                 :            :  * Test 8: Error case, always get an error response with code SPDM_ERROR_CODE_RESPONSE_NOT_READY
+    3879                 :            :  * Expected Behavior: get a RETURN_DEVICE_ERROR return code, with an empty transcript.message_m
+    3880                 :            :  **/
+    3881                 :          1 : static void libspdm_test_requester_get_measurements_case8(void **state)
+    3882                 :            : {
+    3883                 :            :     libspdm_return_t status;
+    3884                 :            :     libspdm_test_context_t *spdm_test_context;
+    3885                 :            :     libspdm_context_t *spdm_context;
+    3886                 :            :     uint8_t number_of_block;
+    3887                 :            :     uint32_t measurement_record_length;
+    3888                 :            :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
+    3889                 :            :     uint8_t request_attribute;
+    3890                 :            :     void *data;
+    3891                 :            :     size_t data_size;
+    3892                 :            :     void *hash;
+    3893                 :            :     size_t hash_size;
+    3894                 :            : 
+    3895                 :          1 :     spdm_test_context = *state;
+    3896                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    3897                 :          1 :     spdm_test_context->case_id = 0x8;
+    3898                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    3899                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3900                 :          1 :     spdm_context->connection_info.connection_state =
+    3901                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    3902                 :          1 :     spdm_context->connection_info.capability.flags |=
+    3903                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    3904                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3905                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    3906                 :            :                                                     &data_size, &hash, &hash_size);
+    3907                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    3908                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    3909                 :            :         m_libspdm_use_measurement_spec;
+    3910                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    3911                 :            :         m_libspdm_use_measurement_hash_algo;
+    3912                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    3913                 :            :         m_libspdm_use_hash_algo;
+    3914                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    3915                 :            :         m_libspdm_use_asym_algo;
+    3916                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    3917                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    3918                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    3919                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    3920                 :            :         data_size;
+    3921                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    3922                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    3923                 :            :                      data, data_size);
+    3924                 :            : #else
+    3925                 :          1 :     libspdm_hash_all(
+    3926                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    3927                 :            :         data, data_size,
+    3928                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    3929                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    3930                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    3931                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    3932                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    3933                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    3934                 :            :         data, data_size,
+    3935                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    3936                 :            : #endif
+    3937                 :            : 
+    3938                 :          1 :     request_attribute =
+    3939                 :            :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
+    3940                 :            : 
+    3941                 :          1 :     measurement_record_length = sizeof(measurement_record);
+    3942                 :          1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
+    3943                 :            :                                      0, NULL, &number_of_block,
+    3944                 :            :                                      &measurement_record_length,
+    3945                 :            :                                      measurement_record);
+    3946                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_NOT_READY_PEER);
+    3947                 :          1 :     free(data);
+    3948                 :          1 : }
+    3949                 :            : 
+    3950                 :            : /**
+    3951                 :            :  * Test 9: Successfully get one measurement block (signed), after getting SPDM_ERROR_CODE_RESPONSE_NOT_READY on first attempt
+    3952                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code, with an empty transcript.message_m
+    3953                 :            :  **/
+    3954                 :          1 : static void libspdm_test_requester_get_measurements_case9(void **state)
+    3955                 :            : {
+    3956                 :            :     libspdm_return_t status;
+    3957                 :            :     libspdm_test_context_t *spdm_test_context;
+    3958                 :            :     libspdm_context_t *spdm_context;
+    3959                 :            :     uint8_t number_of_block;
+    3960                 :            :     uint32_t measurement_record_length;
+    3961                 :            :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
+    3962                 :            :     uint8_t request_attribute;
+    3963                 :            :     void *data;
+    3964                 :            :     size_t data_size;
+    3965                 :            :     void *hash;
+    3966                 :            :     size_t hash_size;
+    3967                 :            : 
+    3968                 :          1 :     spdm_test_context = *state;
+    3969                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    3970                 :          1 :     spdm_test_context->case_id = 0x9;
+    3971                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    3972                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3973                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    3974                 :          1 :     spdm_context->connection_info.capability.flags |=
+    3975                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    3976                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3977                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    3978                 :            :                                                     &data_size, &hash, &hash_size);
+    3979                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    3980                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+    3981                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    3982                 :            :         m_libspdm_use_measurement_hash_algo;
+    3983                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    3984                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    3985                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    3986                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    3987                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    3988                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
+    3989                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    3990                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    3991                 :            :                      data, data_size);
+    3992                 :            : #else
+    3993                 :          1 :     libspdm_hash_all(
+    3994                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    3995                 :            :         data, data_size,
+    3996                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    3997                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    3998                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    3999                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    4000                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    4001                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    4002                 :            :         data, data_size,
+    4003                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    4004                 :            : #endif
+    4005                 :            : 
+    4006                 :          1 :     request_attribute = SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
+    4007                 :            : 
+    4008                 :          1 :     measurement_record_length = sizeof(measurement_record);
+    4009                 :          1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
+    4010                 :            :                                      0, NULL, &number_of_block,
+    4011                 :            :                                      &measurement_record_length,
+    4012                 :            :                                      measurement_record);
+    4013                 :            :     if (LIBSPDM_RESPOND_IF_READY_SUPPORT) {
+    4014                 :          1 :         assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    4015                 :            :     } else {
+    4016                 :            :         assert_int_equal(status, LIBSPDM_STATUS_NOT_READY_PEER);
+    4017                 :            :     }
+    4018                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4019                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+    4020                 :            : #endif
+    4021                 :          1 :     free(data);
+    4022                 :          1 : }
+    4023                 :            : 
+    4024                 :            : /**
+    4025                 :            :  * Test 10: Successful response to get total number of measurements, without signature
+    4026                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code, correct number_of_blocks, correct transcript.message_m.buffer_size
+    4027                 :            :  **/
+    4028                 :          1 : static void libspdm_test_requester_get_measurements_case10(void **state)
+    4029                 :            : {
+    4030                 :            :     libspdm_return_t status;
+    4031                 :            :     libspdm_test_context_t *spdm_test_context;
+    4032                 :            :     libspdm_context_t *spdm_context;
+    4033                 :            :     uint8_t number_of_blocks;
+    4034                 :            :     uint8_t request_attribute;
+    4035                 :            :     void *data;
+    4036                 :            :     size_t data_size;
+    4037                 :            :     void *hash;
+    4038                 :            :     size_t hash_size;
+    4039                 :            : 
+    4040                 :          1 :     spdm_test_context = *state;
+    4041                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4042                 :          1 :     spdm_test_context->case_id = 0xA;
+    4043                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4044                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4045                 :          1 :     spdm_context->connection_info.connection_state =
+    4046                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    4047                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4048                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    4049                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    4050                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    4051                 :            :                                                     &data_size, &hash, &hash_size);
+    4052                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    4053                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    4054                 :            :         m_libspdm_use_measurement_spec;
+    4055                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    4056                 :            :         m_libspdm_use_measurement_hash_algo;
+    4057                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    4058                 :            :         m_libspdm_use_hash_algo;
+    4059                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    4060                 :            :         m_libspdm_use_asym_algo;
+    4061                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    4062                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    4063                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4064                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    4065                 :            :         data_size;
+    4066                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    4067                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    4068                 :            :                      data, data_size);
+    4069                 :            : #else
+    4070                 :          1 :     libspdm_hash_all(
+    4071                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    4072                 :            :         data, data_size,
+    4073                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    4074                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    4075                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    4076                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    4077                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    4078                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    4079                 :            :         data, data_size,
+    4080                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    4081                 :            : #endif
+    4082                 :            : 
+    4083                 :          1 :     request_attribute = 0;
+    4084                 :            : 
+    4085                 :          1 :     status = libspdm_get_measurement(
+    4086                 :            :         spdm_context, NULL, request_attribute,
+    4087                 :            :         SPDM_GET_MEASUREMENTS_REQUEST_MEASUREMENT_OPERATION_TOTAL_NUMBER_OF_MEASUREMENTS,
+    4088                 :            :         0, NULL, &number_of_blocks, NULL, NULL);
+    4089                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    4090                 :          1 :     assert_int_equal(number_of_blocks, 4);
+    4091                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4092                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
+    4093                 :            :                      sizeof(spdm_message_header_t) +
+    4094                 :            :                      sizeof(spdm_measurements_response_t) +
+    4095                 :            :                      SPDM_NONCE_SIZE + sizeof(uint16_t));
+    4096                 :            : #endif
+    4097                 :          1 :     free(data);
+    4098                 :          1 : }
+    4099                 :            : 
+    4100                 :            : /**
+    4101                 :            :  * Test 11: Successful response to get a measurement block, without signature
+    4102                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code, correct transcript.message_m.buffer_size
+    4103                 :            :  **/
+    4104                 :          1 : static void libspdm_test_requester_get_measurements_case11(void **state)
+    4105                 :            : {
+    4106                 :            :     libspdm_return_t status;
+    4107                 :            :     libspdm_test_context_t *spdm_test_context;
+    4108                 :            :     libspdm_context_t *spdm_context;
+    4109                 :            :     uint8_t number_of_block;
+    4110                 :            :     uint32_t measurement_record_length;
+    4111                 :            :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
+    4112                 :            :     uint8_t request_attribute;
+    4113                 :            :     void *data;
+    4114                 :            :     size_t data_size;
+    4115                 :            :     void *hash;
+    4116                 :            :     size_t hash_size;
+    4117                 :            : 
+    4118                 :          1 :     spdm_test_context = *state;
+    4119                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4120                 :          1 :     spdm_test_context->case_id = 0xB;
+    4121                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4122                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4123                 :          1 :     spdm_context->connection_info.connection_state =
+    4124                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    4125                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4126                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    4127                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    4128                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    4129                 :            :                                                     &data_size, &hash, &hash_size);
+    4130                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    4131                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    4132                 :            :         m_libspdm_use_measurement_spec;
+    4133                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    4134                 :            :         m_libspdm_use_measurement_hash_algo;
+    4135                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    4136                 :            :         m_libspdm_use_hash_algo;
+    4137                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    4138                 :            :         m_libspdm_use_asym_algo;
+    4139                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    4140                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    4141                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4142                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    4143                 :            :         data_size;
+    4144                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    4145                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    4146                 :            :                      data, data_size);
+    4147                 :            : #else
+    4148                 :          1 :     libspdm_hash_all(
+    4149                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    4150                 :            :         data, data_size,
+    4151                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    4152                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    4153                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    4154                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    4155                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    4156                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    4157                 :            :         data, data_size,
+    4158                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    4159                 :            : #endif
+    4160                 :            : 
+    4161                 :          1 :     request_attribute = 0;
+    4162                 :            : 
+    4163                 :          1 :     measurement_record_length = sizeof(measurement_record);
+    4164                 :          1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
+    4165                 :            :                                      0, NULL, &number_of_block,
+    4166                 :            :                                      &measurement_record_length,
+    4167                 :            :                                      measurement_record);
+    4168                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    4169                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4170                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
+    4171                 :            :                      sizeof(spdm_message_header_t) +
+    4172                 :            :                      sizeof(spdm_measurements_response_t) +
+    4173                 :            :                      sizeof(spdm_measurement_block_dmtf_t) +
+    4174                 :            :                      libspdm_get_measurement_hash_size(
+    4175                 :            :                          m_libspdm_use_measurement_hash_algo) +
+    4176                 :            :                      SPDM_NONCE_SIZE + sizeof(uint16_t));
+    4177                 :            : #endif
+    4178                 :          1 :     free(data);
+    4179                 :          1 : }
+    4180                 :            : 
+    4181                 :            : /**
+    4182                 :            :  * Test 12: Error case, signature is invalid (all bytes are 0)
+    4183                 :            :  * Expected Behavior: get a RETURN_SECURITY_VIOLATION return code
+    4184                 :            :  **/
+    4185                 :          1 : static void libspdm_test_requester_get_measurements_case12(void **state)
+    4186                 :            : {
+    4187                 :            :     libspdm_return_t status;
+    4188                 :            :     libspdm_test_context_t *spdm_test_context;
+    4189                 :            :     libspdm_context_t *spdm_context;
+    4190                 :            :     uint8_t number_of_block;
+    4191                 :            :     uint32_t measurement_record_length;
+    4192                 :            :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
+    4193                 :            :     uint8_t request_attribute;
+    4194                 :            :     void *data;
+    4195                 :            :     size_t data_size;
+    4196                 :            :     void *hash;
+    4197                 :            :     size_t hash_size;
+    4198                 :            : 
+    4199                 :          1 :     spdm_test_context = *state;
+    4200                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4201                 :          1 :     spdm_test_context->case_id = 0xC;
+    4202                 :            : 
+    4203                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4204                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4205                 :          1 :     spdm_context->connection_info.connection_state =
+    4206                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    4207                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4208                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    4209                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    4210                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    4211                 :            :                                                     &data_size, &hash, &hash_size);
+    4212                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    4213                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    4214                 :            :         m_libspdm_use_measurement_spec;
+    4215                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    4216                 :            :         m_libspdm_use_measurement_hash_algo;
+    4217                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    4218                 :            :         m_libspdm_use_hash_algo;
+    4219                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    4220                 :            :         m_libspdm_use_asym_algo;
+    4221                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    4222                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    4223                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4224                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    4225                 :            :         data_size;
+    4226                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    4227                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    4228                 :            :                      data, data_size);
+    4229                 :            : #else
+    4230                 :          1 :     libspdm_hash_all(
+    4231                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    4232                 :            :         data, data_size,
+    4233                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    4234                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    4235                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    4236                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    4237                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    4238                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    4239                 :            :         data, data_size,
+    4240                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    4241                 :            : #endif
+    4242                 :            : 
+    4243                 :          1 :     request_attribute =
+    4244                 :            :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
+    4245                 :            : 
+    4246                 :          1 :     measurement_record_length = sizeof(measurement_record);
+    4247                 :          1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
+    4248                 :            :                                      0, NULL, &number_of_block,
+    4249                 :            :                                      &measurement_record_length,
+    4250                 :            :                                      measurement_record);
+    4251                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_VERIF_FAIL);
+    4252                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4253                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+    4254                 :            : #endif
+    4255                 :          1 :     free(data);
+    4256                 :          1 : }
+    4257                 :            : 
+    4258                 :            : /**
+    4259                 :            :  * Test 13: Error case, signature is invalid (random)
+    4260                 :            :  * Expected Behavior: get a RETURN_SECURITY_VIOLATION return code
+    4261                 :            :  **/
+    4262                 :          1 : static void libspdm_test_requester_get_measurements_case13(void **state)
+    4263                 :            : {
+    4264                 :            :     libspdm_return_t status;
+    4265                 :            :     libspdm_test_context_t *spdm_test_context;
+    4266                 :            :     libspdm_context_t *spdm_context;
+    4267                 :            :     uint8_t number_of_block;
+    4268                 :            :     uint32_t measurement_record_length;
+    4269                 :            :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
+    4270                 :            :     uint8_t request_attribute;
+    4271                 :            :     void *data;
+    4272                 :            :     size_t data_size;
+    4273                 :            :     void *hash;
+    4274                 :            :     size_t hash_size;
+    4275                 :            : 
+    4276                 :          1 :     spdm_test_context = *state;
+    4277                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4278                 :          1 :     spdm_test_context->case_id = 0xD;
+    4279                 :            : 
+    4280                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4281                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4282                 :          1 :     spdm_context->connection_info.connection_state =
+    4283                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    4284                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4285                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    4286                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    4287                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    4288                 :            :                                                     &data_size, &hash, &hash_size);
+    4289                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    4290                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    4291                 :            :         m_libspdm_use_measurement_spec;
+    4292                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    4293                 :            :         m_libspdm_use_measurement_hash_algo;
+    4294                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    4295                 :            :         m_libspdm_use_hash_algo;
+    4296                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    4297                 :            :         m_libspdm_use_asym_algo;
+    4298                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    4299                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    4300                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4301                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    4302                 :            :         data_size;
+    4303                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    4304                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    4305                 :            :                      data, data_size);
+    4306                 :            : #else
+    4307                 :          1 :     libspdm_hash_all(
+    4308                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    4309                 :            :         data, data_size,
+    4310                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    4311                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    4312                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    4313                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    4314                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    4315                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    4316                 :            :         data, data_size,
+    4317                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    4318                 :            : #endif
+    4319                 :            : 
+    4320                 :          1 :     request_attribute =
+    4321                 :            :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
+    4322                 :            : 
+    4323                 :          1 :     measurement_record_length = sizeof(measurement_record);
+    4324                 :          1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
+    4325                 :            :                                      0, NULL, &number_of_block,
+    4326                 :            :                                      &measurement_record_length,
+    4327                 :            :                                      measurement_record);
+    4328                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_VERIF_FAIL);
+    4329                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4330                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+    4331                 :            : #endif
+    4332                 :          1 :     free(data);
+    4333                 :          1 : }
+    4334                 :            : 
+    4335                 :            : /**
+    4336                 :            :  * Test 14: Error case, request a signed response, but response is malformed (signature absent)
+    4337                 :            :  * Expected Behavior: get a RETURN_DEVICE_ERROR return code
+    4338                 :            :  **/
+    4339                 :          1 : static void libspdm_test_requester_get_measurements_case14(void **state)
+    4340                 :            : {
+    4341                 :            :     libspdm_return_t status;
+    4342                 :            :     libspdm_test_context_t *spdm_test_context;
+    4343                 :            :     libspdm_context_t *spdm_context;
+    4344                 :            :     uint8_t number_of_block;
+    4345                 :            :     uint32_t measurement_record_length;
+    4346                 :            :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
+    4347                 :            :     uint8_t request_attribute;
+    4348                 :            :     void *data;
+    4349                 :            :     size_t data_size;
+    4350                 :            :     void *hash;
+    4351                 :            :     size_t hash_size;
+    4352                 :            : 
+    4353                 :          1 :     spdm_test_context = *state;
+    4354                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4355                 :          1 :     spdm_test_context->case_id = 0xE;
+    4356                 :            : 
+    4357                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4358                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4359                 :          1 :     spdm_context->connection_info.connection_state =
+    4360                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    4361                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4362                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    4363                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    4364                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    4365                 :            :                                                     &data_size, &hash, &hash_size);
+    4366                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    4367                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    4368                 :            :         m_libspdm_use_measurement_spec;
+    4369                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    4370                 :            :         m_libspdm_use_measurement_hash_algo;
+    4371                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    4372                 :            :         m_libspdm_use_hash_algo;
+    4373                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    4374                 :            :         m_libspdm_use_asym_algo;
+    4375                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    4376                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    4377                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4378                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    4379                 :            :         data_size;
+    4380                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    4381                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    4382                 :            :                      data, data_size);
+    4383                 :            : #else
+    4384                 :          1 :     libspdm_hash_all(
+    4385                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    4386                 :            :         data, data_size,
+    4387                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    4388                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    4389                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    4390                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    4391                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    4392                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    4393                 :            :         data, data_size,
+    4394                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    4395                 :            : #endif
+    4396                 :            : 
+    4397                 :          1 :     request_attribute =
+    4398                 :            :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
+    4399                 :            : 
+    4400                 :          1 :     measurement_record_length = sizeof(measurement_record);
+    4401                 :          1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
+    4402                 :            :                                      0, NULL, &number_of_block,
+    4403                 :            :                                      &measurement_record_length,
+    4404                 :            :                                      measurement_record);
+    4405                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
+    4406                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4407                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+    4408                 :            : #endif
+    4409                 :          1 :     free(data);
+    4410                 :          1 : }
+    4411                 :            : 
+    4412                 :            : /**
+    4413                 :            :  * Test 15: Error case, response with wrong response code
+    4414                 :            :  * Expected Behavior: get a RETURN_DEVICE_ERROR return code
+    4415                 :            :  **/
+    4416                 :          1 : static void libspdm_test_requester_get_measurements_case15(void **state)
+    4417                 :            : {
+    4418                 :            :     libspdm_return_t status;
+    4419                 :            :     libspdm_test_context_t *spdm_test_context;
+    4420                 :            :     libspdm_context_t *spdm_context;
+    4421                 :            :     uint8_t number_of_block;
+    4422                 :            :     uint32_t measurement_record_length;
+    4423                 :            :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
+    4424                 :            :     uint8_t request_attribute;
+    4425                 :            :     void *data;
+    4426                 :            :     size_t data_size;
+    4427                 :            :     void *hash;
+    4428                 :            :     size_t hash_size;
+    4429                 :            : 
+    4430                 :          1 :     spdm_test_context = *state;
+    4431                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4432                 :          1 :     spdm_test_context->case_id = 0xF;
+    4433                 :            : 
+    4434                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4435                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4436                 :          1 :     spdm_context->connection_info.connection_state =
+    4437                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    4438                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4439                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    4440                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    4441                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    4442                 :            :                                                     &data_size, &hash, &hash_size);
+    4443                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    4444                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    4445                 :            :         m_libspdm_use_measurement_spec;
+    4446                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    4447                 :            :         m_libspdm_use_measurement_hash_algo;
+    4448                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    4449                 :            :         m_libspdm_use_hash_algo;
+    4450                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    4451                 :            :         m_libspdm_use_asym_algo;
+    4452                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    4453                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    4454                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4455                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    4456                 :            :         data_size;
+    4457                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    4458                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    4459                 :            :                      data, data_size);
+    4460                 :            : #else
+    4461                 :          1 :     libspdm_hash_all(
+    4462                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    4463                 :            :         data, data_size,
+    4464                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    4465                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    4466                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    4467                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    4468                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    4469                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    4470                 :            :         data, data_size,
+    4471                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    4472                 :            : #endif
+    4473                 :            : 
+    4474                 :          1 :     request_attribute =
+    4475                 :            :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
+    4476                 :            : 
+    4477                 :          1 :     measurement_record_length = sizeof(measurement_record);
+    4478                 :          1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
+    4479                 :            :                                      0, NULL, &number_of_block,
+    4480                 :            :                                      &measurement_record_length,
+    4481                 :            :                                      measurement_record);
+    4482                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    4483                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4484                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+    4485                 :            : #endif
+    4486                 :          1 :     free(data);
+    4487                 :          1 : }
+    4488                 :            : 
+    4489                 :            : /**
+    4490                 :            :  * Test 16: SlotID verificaton, the response's SlotID should match the request
+    4491                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code if the fields match, RETURN_DEVICE_ERROR otherwise. Either way, transcript.message_m should be empty
+    4492                 :            :  **/
+    4493                 :          1 : static void libspdm_test_requester_get_measurements_case16(void **state)
+    4494                 :            : {
+    4495                 :            :     libspdm_return_t status;
+    4496                 :            :     libspdm_test_context_t *spdm_test_context;
+    4497                 :            :     libspdm_context_t *spdm_context;
+    4498                 :            :     uint8_t number_of_block;
+    4499                 :            :     uint32_t measurement_record_length;
+    4500                 :            :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
+    4501                 :            :     uint8_t request_attribute;
+    4502                 :            :     void *data;
+    4503                 :            :     size_t data_size;
+    4504                 :            :     void *hash;
+    4505                 :            :     size_t hash_size;
+    4506                 :          1 :     uint8_t SlotIDs[] = { 0, 1, 2, 3 };
+    4507                 :            : 
+    4508                 :          1 :     spdm_test_context = *state;
+    4509                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4510                 :          1 :     spdm_test_context->case_id = 0x10;
+    4511                 :            : 
+    4512                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4513                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4514                 :          1 :     spdm_context->connection_info.connection_state =
+    4515                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    4516                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4517                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    4518                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    4519                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    4520                 :            :                                                     &data_size, &hash, &hash_size);
+    4521                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    4522                 :            :         m_libspdm_use_measurement_spec;
+    4523                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    4524                 :            :         m_libspdm_use_measurement_hash_algo;
+    4525                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    4526                 :            :         m_libspdm_use_hash_algo;
+    4527                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    4528                 :            :         m_libspdm_use_asym_algo;
+    4529                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    4530                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    4531                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4532                 :            :     for (int i = 0; i < sizeof(SlotIDs) / sizeof(SlotIDs[0]); i++) {
+    4533                 :            :         spdm_context->connection_info.peer_used_cert_chain[SlotIDs[i]].buffer_size =
+    4534                 :            :             data_size;
+    4535                 :            :         libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[SlotIDs[i]].buffer,
+    4536                 :            :                          sizeof(spdm_context->connection_info.peer_used_cert_chain[SlotIDs[i]].
+    4537                 :            :                                 buffer),
+    4538                 :            :                          data, data_size);
+    4539                 :            :     }
+    4540                 :            : #else
+    4541         [ +  + ]:          5 :     for (int i = 0; i < sizeof(SlotIDs) / sizeof(SlotIDs[0]); i++) {
+    4542                 :          4 :         libspdm_hash_all(
+    4543                 :            :             spdm_context->connection_info.algorithm.base_hash_algo,
+    4544                 :            :             data, data_size,
+    4545                 :          4 :             spdm_context->connection_info.peer_used_cert_chain[SlotIDs[i]].buffer_hash);
+    4546                 :          8 :         spdm_context->connection_info.peer_used_cert_chain[SlotIDs[i]].buffer_hash_size =
+    4547                 :          4 :             libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    4548                 :          4 :         libspdm_get_leaf_cert_public_key_from_cert_chain(
+    4549                 :            :             spdm_context->connection_info.algorithm.base_hash_algo,
+    4550                 :            :             spdm_context->connection_info.algorithm.base_asym_algo,
+    4551                 :            :             data, data_size,
+    4552                 :          4 :             &spdm_context->connection_info.peer_used_cert_chain[SlotIDs[i]].leaf_cert_public_key);
+    4553                 :            :     }
+    4554                 :            : #endif
+    4555                 :            : 
+    4556                 :          1 :     request_attribute =
+    4557                 :            :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
+    4558                 :            : 
+    4559         [ +  + ]:          5 :     for (int i = 0; i < sizeof(SlotIDs) / sizeof(SlotIDs[0]); i++) {
+    4560                 :          4 :         measurement_record_length = sizeof(measurement_record);
+    4561                 :          4 :         libspdm_reset_message_m(spdm_context, NULL);
+    4562                 :          4 :         status = libspdm_get_measurement(spdm_context, NULL,
+    4563                 :          4 :                                          request_attribute, 1, SlotIDs[i],
+    4564                 :            :                                          NULL, &number_of_block,
+    4565                 :            :                                          &measurement_record_length,
+    4566                 :            :                                          measurement_record);
+    4567         [ +  + ]:          4 :         if (SlotIDs[i] == LIBSPDM_ALTERNATIVE_DEFAULT_SLOT_ID) {
+    4568                 :          1 :             assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    4569                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4570                 :            :             assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+    4571                 :            : #endif
+    4572                 :            :         } else {
+    4573                 :          3 :             assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    4574                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4575                 :            :             assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+    4576                 :            : #endif
+    4577                 :            :         }
+    4578                 :            :     }
+    4579                 :          1 :     free(data);
+    4580                 :          1 : }
+    4581                 :            : 
+    4582                 :            : /**
+    4583                 :            :  * Test 17: Error case, response to get total number of measurements, but response number_of_blocks and/or measurement_record_length are non 0
+    4584                 :            :  * Expected Behavior: get a RETURN_DEVICE_ERROR return code
+    4585                 :            :  **/
+    4586                 :          1 : static void libspdm_test_requester_get_measurements_case17(void **state)
+    4587                 :            : {
+    4588                 :            :     libspdm_return_t status;
+    4589                 :            :     libspdm_test_context_t *spdm_test_context;
+    4590                 :            :     libspdm_context_t *spdm_context;
+    4591                 :            :     uint8_t number_of_blocks;
+    4592                 :            :     uint8_t request_attribute;
+    4593                 :            :     void *data;
+    4594                 :            :     size_t data_size;
+    4595                 :            :     void *hash;
+    4596                 :            :     size_t hash_size;
+    4597                 :            : 
+    4598                 :          1 :     spdm_test_context = *state;
+    4599                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4600                 :          1 :     spdm_test_context->case_id = 0x11;
+    4601                 :            : 
+    4602                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4603                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4604                 :          1 :     spdm_context->connection_info.connection_state =
+    4605                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    4606                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4607                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    4608                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    4609                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    4610                 :            :                                                     &data_size, &hash, &hash_size);
+    4611                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    4612                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    4613                 :            :         m_libspdm_use_measurement_spec;
+    4614                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    4615                 :            :         m_libspdm_use_measurement_hash_algo;
+    4616                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    4617                 :            :         m_libspdm_use_hash_algo;
+    4618                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    4619                 :            :         m_libspdm_use_asym_algo;
+    4620                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    4621                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    4622                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4623                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    4624                 :            :         data_size;
+    4625                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    4626                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    4627                 :            :                      data, data_size);
+    4628                 :            : #else
+    4629                 :          1 :     libspdm_hash_all(
+    4630                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    4631                 :            :         data, data_size,
+    4632                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    4633                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    4634                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    4635                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    4636                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    4637                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    4638                 :            :         data, data_size,
+    4639                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    4640                 :            : #endif
+    4641                 :            : 
+    4642                 :          1 :     request_attribute = 0;
+    4643                 :            : 
+    4644         [ +  + ]:          4 :     for (int i = 0; i < 3; i++) {
+    4645                 :            :         /* i=0 => both number_of_blocks and measurement_record_length are non 0
+    4646                 :            :          * i=1 => only number_of_blocks is non 0
+    4647                 :            :          * i=2 => only is measurement_record_length is non 0*/
+    4648                 :          3 :         status = libspdm_get_measurement(
+    4649                 :            :             spdm_context, NULL, request_attribute,
+    4650                 :            :             SPDM_GET_MEASUREMENTS_REQUEST_MEASUREMENT_OPERATION_TOTAL_NUMBER_OF_MEASUREMENTS,
+    4651                 :            :             0, NULL, &number_of_blocks, NULL, NULL);
+    4652                 :          3 :         assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    4653                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4654                 :            :         assert_int_equal(spdm_context->transcript.message_m.buffer_size,
+    4655                 :            :                          0);
+    4656                 :            : #endif
+    4657                 :            :     }
+    4658                 :          1 :     free(data);
+    4659                 :          1 : }
+    4660                 :            : 
+    4661                 :            : /**
+    4662                 :            :  * Test 18:
+    4663                 :            :  * Expected Behavior:
+    4664                 :            :  **/
+    4665                 :          1 : static void libspdm_test_requester_get_measurements_case18(void **state)
+    4666                 :            : {
+    4667                 :          1 : }
+    4668                 :            : 
+    4669                 :            : /**
+    4670                 :            :  * Test 19: Error case, measurement_specification field in response has 2 bits set (bit 0 is one of them)
+    4671                 :            :  * Expected Behavior: get a RETURN_DEVICE_ERROR return code,
+    4672                 :            :  **/
+    4673                 :          1 : static void libspdm_test_requester_get_measurements_case19(void **state)
+    4674                 :            : {
+    4675                 :            :     libspdm_return_t status;
+    4676                 :            :     libspdm_test_context_t *spdm_test_context;
+    4677                 :            :     libspdm_context_t *spdm_context;
+    4678                 :            :     uint8_t number_of_block;
+    4679                 :            :     uint32_t measurement_record_length;
+    4680                 :            :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
+    4681                 :            :     uint8_t request_attribute;
+    4682                 :            :     void *data;
+    4683                 :            :     size_t data_size;
+    4684                 :            :     void *hash;
+    4685                 :            :     size_t hash_size;
+    4686                 :            : 
+    4687                 :          1 :     spdm_test_context = *state;
+    4688                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4689                 :          1 :     spdm_test_context->case_id = 0x13;
+    4690                 :            : 
+    4691                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4692                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4693                 :          1 :     spdm_context->connection_info.connection_state =
+    4694                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    4695                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4696                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    4697                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    4698                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    4699                 :            :                                                     &data_size, &hash, &hash_size);
+    4700                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    4701                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    4702                 :            :         m_libspdm_use_measurement_spec;
+    4703                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    4704                 :            :         m_libspdm_use_measurement_hash_algo;
+    4705                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    4706                 :            :         m_libspdm_use_hash_algo;
+    4707                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    4708                 :            :         m_libspdm_use_asym_algo;
+    4709                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    4710                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    4711                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4712                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    4713                 :            :         data_size;
+    4714                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    4715                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    4716                 :            :                      data, data_size);
+    4717                 :            : #else
+    4718                 :          1 :     libspdm_hash_all(
+    4719                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    4720                 :            :         data, data_size,
+    4721                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    4722                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    4723                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    4724                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    4725                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    4726                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    4727                 :            :         data, data_size,
+    4728                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    4729                 :            : #endif
+    4730                 :            : 
+    4731                 :          1 :     request_attribute = 0;
+    4732                 :            : 
+    4733                 :          1 :     measurement_record_length = sizeof(measurement_record);
+    4734                 :          1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
+    4735                 :            :                                      0, NULL, &number_of_block,
+    4736                 :            :                                      &measurement_record_length,
+    4737                 :            :                                      measurement_record);
+    4738                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    4739                 :            : /* #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT*/
+    4740                 :            :     /* assert_int_equal (spdm_context->transcript.message_m.buffer_size, 0);*/
+    4741                 :            : /* #endif*/
+    4742                 :          1 :     free(data);
+    4743                 :          1 : }
+    4744                 :            : 
+    4745                 :            : /**
+    4746                 :            :  * Test 20: Error case, measurement_specification field in response has 2 bits set (bit 0 is not one of them)
+    4747                 :            :  * Expected Behavior: get a RETURN_DEVICE_ERROR return code,
+    4748                 :            :  **/
+    4749                 :          1 : static void libspdm_test_requester_get_measurements_case20(void **state)
+    4750                 :            : {
+    4751                 :            :     libspdm_return_t status;
+    4752                 :            :     libspdm_test_context_t *spdm_test_context;
+    4753                 :            :     libspdm_context_t *spdm_context;
+    4754                 :            :     uint8_t number_of_block;
+    4755                 :            :     uint32_t measurement_record_length;
+    4756                 :            :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
+    4757                 :            :     uint8_t request_attribute;
+    4758                 :            :     void *data;
+    4759                 :            :     size_t data_size;
+    4760                 :            :     void *hash;
+    4761                 :            :     size_t hash_size;
+    4762                 :            : 
+    4763                 :          1 :     spdm_test_context = *state;
+    4764                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4765                 :          1 :     spdm_test_context->case_id = 0x14;
+    4766                 :            : 
+    4767                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4768                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4769                 :          1 :     spdm_context->connection_info.connection_state =
+    4770                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    4771                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4772                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    4773                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    4774                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    4775                 :            :                                                     &data_size, &hash, &hash_size);
+    4776                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    4777                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    4778                 :            :         m_libspdm_use_measurement_spec;
+    4779                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    4780                 :            :         m_libspdm_use_measurement_hash_algo;
+    4781                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    4782                 :            :         m_libspdm_use_hash_algo;
+    4783                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    4784                 :            :         m_libspdm_use_asym_algo;
+    4785                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    4786                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    4787                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4788                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    4789                 :            :         data_size;
+    4790                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    4791                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    4792                 :            :                      data, data_size);
+    4793                 :            : #else
+    4794                 :          1 :     libspdm_hash_all(
+    4795                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    4796                 :            :         data, data_size,
+    4797                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    4798                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    4799                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    4800                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    4801                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    4802                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    4803                 :            :         data, data_size,
+    4804                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    4805                 :            : #endif
+    4806                 :            : 
+    4807                 :          1 :     request_attribute = 0;
+    4808                 :            : 
+    4809                 :          1 :     measurement_record_length = sizeof(measurement_record);
+    4810                 :          1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
+    4811                 :            :                                      0, NULL, &number_of_block,
+    4812                 :            :                                      &measurement_record_length,
+    4813                 :            :                                      measurement_record);
+    4814                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    4815                 :            : /* #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT*/
+    4816                 :            :     /* assert_int_equal (spdm_context->transcript.message_m.buffer_size, 0);*/
+    4817                 :            : /* #endif*/
+    4818                 :          1 :     free(data);
+    4819                 :          1 : }
+    4820                 :            : 
+    4821                 :            : /**
+    4822                 :            :  * Test 21: Error case, measurement_specification field in response does not "match the selected measurement specification in the ALGORITHMS message"
+    4823                 :            :  * Expected Behavior: get a RETURN_DEVICE_ERROR return code,
+    4824                 :            :  **/
+    4825                 :          1 : static void libspdm_test_requester_get_measurements_case21(void **state)
+    4826                 :            : {
+    4827                 :            :     libspdm_return_t status;
+    4828                 :            :     libspdm_test_context_t *spdm_test_context;
+    4829                 :            :     libspdm_context_t *spdm_context;
+    4830                 :            :     uint8_t number_of_block;
+    4831                 :            :     uint32_t measurement_record_length;
+    4832                 :            :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
+    4833                 :            :     uint8_t request_attribute;
+    4834                 :            :     void *data;
+    4835                 :            :     size_t data_size;
+    4836                 :            :     void *hash;
+    4837                 :            :     size_t hash_size;
+    4838                 :            : 
+    4839                 :          1 :     spdm_test_context = *state;
+    4840                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4841                 :          1 :     spdm_test_context->case_id = 0x15;
+    4842                 :            : 
+    4843                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4844                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4845                 :          1 :     spdm_context->connection_info.connection_state =
+    4846                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    4847                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4848                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    4849                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    4850                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    4851                 :            :                                                     &data_size, &hash, &hash_size);
+    4852                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    4853                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    4854                 :            :         m_libspdm_use_measurement_spec;
+    4855                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    4856                 :            :         m_libspdm_use_measurement_hash_algo;
+    4857                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    4858                 :            :         m_libspdm_use_hash_algo;
+    4859                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    4860                 :            :         m_libspdm_use_asym_algo;
+    4861                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    4862                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    4863                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4864                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    4865                 :            :         data_size;
+    4866                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    4867                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    4868                 :            :                      data, data_size);
+    4869                 :            : #else
+    4870                 :          1 :     libspdm_hash_all(
+    4871                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    4872                 :            :         data, data_size,
+    4873                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    4874                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    4875                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    4876                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    4877                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    4878                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    4879                 :            :         data, data_size,
+    4880                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    4881                 :            : #endif
+    4882                 :            : 
+    4883                 :          1 :     request_attribute = 0;
+    4884                 :            : 
+    4885                 :          1 :     measurement_record_length = sizeof(measurement_record);
+    4886                 :          1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
+    4887                 :            :                                      0, NULL, &number_of_block,
+    4888                 :            :                                      &measurement_record_length,
+    4889                 :            :                                      measurement_record);
+    4890                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    4891                 :            : /* #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT*/
+    4892                 :            :     /* assert_int_equal (spdm_context->transcript.message_m.buffer_size, 0);*/
+    4893                 :            : /* #endif*/
+    4894                 :          1 :     free(data);
+    4895                 :          1 : }
+    4896                 :            : 
+    4897                 :            : /**
+    4898                 :            :  * Test 22: request a large number of unsigned measurements before requesting a signature
+    4899                 :            :  * Expected Behavior: RETURN_SUCCESS return code and correct transcript.message_m.buffer_size while transcript.message_m has room; RETURN_DEVICE_ERROR otherwise
+    4900                 :            :  **/
+    4901                 :          1 : static void libspdm_test_requester_get_measurements_case22(void **state)
+    4902                 :            : {
+    4903                 :            :     libspdm_return_t status;
+    4904                 :            :     libspdm_test_context_t *spdm_test_context;
+    4905                 :            :     libspdm_context_t *spdm_context;
+    4906                 :            :     uint8_t number_of_block;
+    4907                 :            :     uint32_t measurement_record_length;
+    4908                 :            :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
+    4909                 :            :     uint8_t request_attribute;
+    4910                 :            :     void *data;
+    4911                 :            :     size_t data_size;
+    4912                 :            :     void *hash;
+    4913                 :            :     size_t hash_size;
+    4914                 :            :     size_t NumberOfMessages;
+    4915                 :            : #define TOTAL_MESSAGES 100
+    4916                 :            : 
+    4917                 :          1 :     spdm_test_context = *state;
+    4918                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4919                 :          1 :     spdm_test_context->case_id = 0x16;
+    4920                 :            : 
+    4921                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4922                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4923                 :          1 :     spdm_context->connection_info.connection_state =
+    4924                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    4925                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4926                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    4927                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    4928                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    4929                 :            :                                                     &data_size, &hash, &hash_size);
+    4930                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    4931                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    4932                 :            :         m_libspdm_use_measurement_spec;
+    4933                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    4934                 :            :         m_libspdm_use_measurement_hash_algo;
+    4935                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    4936                 :            :         m_libspdm_use_hash_algo;
+    4937                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    4938                 :            :         m_libspdm_use_asym_algo;
+    4939                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    4940                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    4941                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4942                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    4943                 :            :         data_size;
+    4944                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    4945                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    4946                 :            :                      data, data_size);
+    4947                 :            : #else
+    4948                 :          1 :     libspdm_hash_all(
+    4949                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    4950                 :            :         data, data_size,
+    4951                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    4952                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    4953                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    4954                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    4955                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    4956                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    4957                 :            :         data, data_size,
+    4958                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    4959                 :            : #endif
+    4960                 :            : 
+    4961                 :          1 :     request_attribute = 0;
+    4962                 :            : 
+    4963                 :          1 :     measurement_record_length = sizeof(measurement_record);
+    4964         [ +  + ]:        101 :     for (NumberOfMessages = 1; NumberOfMessages <= TOTAL_MESSAGES;
+    4965                 :        100 :          NumberOfMessages++) {
+    4966                 :        100 :         status = libspdm_get_measurement(spdm_context, NULL,
+    4967                 :            :                                          request_attribute, 1, 0,
+    4968                 :            :                                          NULL, &number_of_block,
+    4969                 :            :                                          &measurement_record_length,
+    4970                 :            :                                          measurement_record);
+    4971                 :            :         /* It may fail due to transcript.message_m overflow*/
+    4972         [ -  + ]:        100 :         if (status == LIBSPDM_STATUS_SUCCESS) {
+    4973                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4974                 :            :             assert_int_equal(
+    4975                 :            :                 spdm_context->transcript.message_m.buffer_size,
+    4976                 :            :                 NumberOfMessages *
+    4977                 :            :                 (sizeof(spdm_message_header_t) +
+    4978                 :            :                  sizeof(spdm_measurements_response_t) +
+    4979                 :            :                  sizeof(spdm_measurement_block_dmtf_t) +
+    4980                 :            :                  libspdm_get_measurement_hash_size(
+    4981                 :            :                      m_libspdm_use_measurement_hash_algo) +
+    4982                 :            :                  SPDM_NONCE_SIZE +
+    4983                 :            :                  sizeof(uint16_t)));
+    4984                 :            : #endif
+    4985                 :            :         } else {
+    4986                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4987                 :            :             assert_int_equal(
+    4988                 :            :                 spdm_context->transcript.message_m.buffer_size,
+    4989                 :            :                 0);
+    4990                 :            : #endif
+    4991                 :          0 :             break;
+    4992                 :            :         }
+    4993                 :            :     }
+    4994                 :          1 :     free(data);
+    4995                 :          1 : }
+    4996                 :            : 
+    4997                 :            : /**
+    4998                 :            :  * Test 23: Successful response to get a measurement block, without signature. response contains opaque data
+    4999                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code, correct transcript.message_m.buffer_size
+    5000                 :            :  **/
+    5001                 :          1 : static void libspdm_test_requester_get_measurements_case23(void **state)
+    5002                 :            : {
+    5003                 :            :     libspdm_return_t status;
+    5004                 :            :     libspdm_test_context_t *spdm_test_context;
+    5005                 :            :     libspdm_context_t *spdm_context;
+    5006                 :            :     uint8_t number_of_block;
+    5007                 :            :     uint32_t measurement_record_length;
+    5008                 :            :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
+    5009                 :            :     uint8_t request_attribute;
+    5010                 :            :     void *data;
+    5011                 :            :     size_t data_size;
+    5012                 :            :     void *hash;
+    5013                 :            :     size_t hash_size;
+    5014                 :            : 
+    5015                 :          1 :     spdm_test_context = *state;
+    5016                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5017                 :          1 :     spdm_test_context->case_id = 0x17;
+    5018                 :            : 
+    5019                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5020                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5021                 :          1 :     spdm_context->connection_info.connection_state =
+    5022                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    5023                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5024                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    5025                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    5026                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    5027                 :            :                                                     &data_size, &hash, &hash_size);
+    5028                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    5029                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    5030                 :            :         m_libspdm_use_measurement_spec;
+    5031                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    5032                 :            :         m_libspdm_use_measurement_hash_algo;
+    5033                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    5034                 :            :         m_libspdm_use_hash_algo;
+    5035                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    5036                 :            :         m_libspdm_use_asym_algo;
+    5037                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    5038                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    5039                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5040                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    5041                 :            :         data_size;
+    5042                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    5043                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    5044                 :            :                      data, data_size);
+    5045                 :            : #else
+    5046                 :          1 :     libspdm_hash_all(
+    5047                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5048                 :            :         data, data_size,
+    5049                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    5050                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    5051                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    5052                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    5053                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5054                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    5055                 :            :         data, data_size,
+    5056                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    5057                 :            : #endif
+    5058                 :            : 
+    5059                 :          1 :     request_attribute = 0;
+    5060                 :            : 
+    5061                 :          1 :     measurement_record_length = sizeof(measurement_record);
+    5062                 :          1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
+    5063                 :            :                                      0, NULL, &number_of_block,
+    5064                 :            :                                      &measurement_record_length,
+    5065                 :            :                                      measurement_record);
+    5066                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    5067                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5068                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
+    5069                 :            :                      sizeof(spdm_message_header_t) +
+    5070                 :            :                      sizeof(spdm_measurements_response_t) +
+    5071                 :            :                      sizeof(spdm_measurement_block_dmtf_t) +
+    5072                 :            :                      libspdm_get_measurement_hash_size(
+    5073                 :            :                          m_libspdm_use_measurement_hash_algo) +
+    5074                 :            :                      SPDM_NONCE_SIZE +
+    5075                 :            :                      sizeof(uint16_t) + SPDM_MAX_OPAQUE_DATA_SIZE);
+    5076                 :            : #endif
+    5077                 :          1 :     free(data);
+    5078                 :          1 : }
+    5079                 :            : 
+    5080                 :            : /**
+    5081                 :            :  * Test 24: Error case, reponse contains opaque data larger than the maximum allowed
+    5082                 :            :  * Expected Behavior: get a RETURN_DEVICE_ERROR return code, correct transcript.message_m.buffer_size
+    5083                 :            :  **/
+    5084                 :          1 : static void libspdm_test_requester_get_measurements_case24(void **state)
+    5085                 :            : {
+    5086                 :            :     libspdm_return_t status;
+    5087                 :            :     libspdm_test_context_t *spdm_test_context;
+    5088                 :            :     libspdm_context_t *spdm_context;
+    5089                 :            :     uint8_t number_of_block;
+    5090                 :            :     uint32_t measurement_record_length;
+    5091                 :            :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
+    5092                 :            :     uint8_t request_attribute;
+    5093                 :            :     void *data;
+    5094                 :            :     size_t data_size;
+    5095                 :            :     void *hash;
+    5096                 :            :     size_t hash_size;
+    5097                 :            : 
+    5098                 :          1 :     spdm_test_context = *state;
+    5099                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5100                 :          1 :     spdm_test_context->case_id = 0x18;
+    5101                 :            : 
+    5102                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5103                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5104                 :          1 :     spdm_context->connection_info.connection_state =
+    5105                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    5106                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5107                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    5108                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    5109                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    5110                 :            :                                                     &data_size, &hash, &hash_size);
+    5111                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    5112                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    5113                 :            :         m_libspdm_use_measurement_spec;
+    5114                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    5115                 :            :         m_libspdm_use_measurement_hash_algo;
+    5116                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    5117                 :            :         m_libspdm_use_hash_algo;
+    5118                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    5119                 :            :         m_libspdm_use_asym_algo;
+    5120                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    5121                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    5122                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5123                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    5124                 :            :         data_size;
+    5125                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    5126                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    5127                 :            :                      data, data_size);
+    5128                 :            : #else
+    5129                 :          1 :     libspdm_hash_all(
+    5130                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5131                 :            :         data, data_size,
+    5132                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    5133                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    5134                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    5135                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    5136                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5137                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    5138                 :            :         data, data_size,
+    5139                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    5140                 :            : #endif
+    5141                 :            : 
+    5142                 :          1 :     request_attribute = 0;
+    5143                 :            : 
+    5144                 :          1 :     measurement_record_length = sizeof(measurement_record);
+    5145                 :          1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
+    5146                 :            :                                      0, NULL, &number_of_block,
+    5147                 :            :                                      &measurement_record_length,
+    5148                 :            :                                      measurement_record);
+    5149                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    5150                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5151                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
+    5152                 :            :                      0);
+    5153                 :            : #endif
+    5154                 :          1 :     free(data);
+    5155                 :          1 : }
+    5156                 :            : 
+    5157                 :            : /**
+    5158                 :            :  * Test 25: Successful response to get a measurement block, with signature. response contains opaque data
+    5159                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code, empty transcript.message_m.buffer_size
+    5160                 :            :  **/
+    5161                 :          1 : static void libspdm_test_requester_get_measurements_case25(void **state)
+    5162                 :            : {
+    5163                 :            :     libspdm_return_t status;
+    5164                 :            :     libspdm_test_context_t *spdm_test_context;
+    5165                 :            :     libspdm_context_t *spdm_context;
+    5166                 :            :     uint8_t number_of_block;
+    5167                 :            :     uint32_t measurement_record_length;
+    5168                 :            :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
+    5169                 :            :     uint8_t request_attribute;
+    5170                 :            :     void *data;
+    5171                 :            :     size_t data_size;
+    5172                 :            :     void *hash;
+    5173                 :            :     size_t hash_size;
+    5174                 :            : 
+    5175                 :          1 :     spdm_test_context = *state;
+    5176                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5177                 :          1 :     spdm_test_context->case_id = 0x19;
+    5178                 :            : 
+    5179                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5180                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5181                 :          1 :     spdm_context->connection_info.connection_state =
+    5182                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    5183                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5184                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    5185                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    5186                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    5187                 :            :                                                     &data_size, &hash, &hash_size);
+    5188                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    5189                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    5190                 :            :         m_libspdm_use_measurement_spec;
+    5191                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    5192                 :            :         m_libspdm_use_measurement_hash_algo;
+    5193                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    5194                 :            :         m_libspdm_use_hash_algo;
+    5195                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    5196                 :            :         m_libspdm_use_asym_algo;
+    5197                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    5198                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    5199                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5200                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    5201                 :            :         data_size;
+    5202                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    5203                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    5204                 :            :                      data, data_size);
+    5205                 :            : #else
+    5206                 :          1 :     libspdm_hash_all(
+    5207                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5208                 :            :         data, data_size,
+    5209                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    5210                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    5211                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    5212                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    5213                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5214                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    5215                 :            :         data, data_size,
+    5216                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    5217                 :            : #endif
+    5218                 :            : 
+    5219                 :          1 :     request_attribute =
+    5220                 :            :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
+    5221                 :            : 
+    5222                 :          1 :     measurement_record_length = sizeof(measurement_record);
+    5223                 :          1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
+    5224                 :            :                                      0, NULL, &number_of_block,
+    5225                 :            :                                      &measurement_record_length,
+    5226                 :            :                                      measurement_record);
+    5227                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    5228                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5229                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+    5230                 :            : #endif
+    5231                 :          1 :     free(data);
+    5232                 :          1 : }
+    5233                 :            : 
+    5234                 :            : /**
+    5235                 :            :  * Test 26: Error case, request with signature, but response opaque data is S bytes shorter than informed
+    5236                 :            :  * Expected Behavior: get a RETURN_DEVICE_ERROR return code, correct transcript.message_m.buffer_size
+    5237                 :            :  **/
+    5238                 :          1 : static void libspdm_test_requester_get_measurements_case26(void **state)
+    5239                 :            : {
+    5240                 :            :     libspdm_return_t status;
+    5241                 :            :     libspdm_test_context_t *spdm_test_context;
+    5242                 :            :     libspdm_context_t *spdm_context;
+    5243                 :            :     uint8_t number_of_block;
+    5244                 :            :     uint32_t measurement_record_length;
+    5245                 :            :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
+    5246                 :            :     uint8_t request_attribute;
+    5247                 :            :     void *data;
+    5248                 :            :     size_t data_size;
+    5249                 :            :     void *hash;
+    5250                 :            :     size_t hash_size;
+    5251                 :            : 
+    5252                 :          1 :     spdm_test_context = *state;
+    5253                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5254                 :          1 :     spdm_test_context->case_id = 0x1A;
+    5255                 :            : 
+    5256                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5257                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5258                 :          1 :     spdm_context->connection_info.connection_state =
+    5259                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    5260                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5261                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    5262                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    5263                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    5264                 :            :                                                     &data_size, &hash, &hash_size);
+    5265                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    5266                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    5267                 :            :         m_libspdm_use_measurement_spec;
+    5268                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    5269                 :            :         m_libspdm_use_measurement_hash_algo;
+    5270                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    5271                 :            :         m_libspdm_use_hash_algo;
+    5272                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    5273                 :            :         m_libspdm_use_asym_algo;
+    5274                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    5275                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    5276                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5277                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    5278                 :            :         data_size;
+    5279                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    5280                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    5281                 :            :                      data, data_size);
+    5282                 :            : #else
+    5283                 :          1 :     libspdm_hash_all(
+    5284                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5285                 :            :         data, data_size,
+    5286                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    5287                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    5288                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    5289                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    5290                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5291                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    5292                 :            :         data, data_size,
+    5293                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    5294                 :            : #endif
+    5295                 :            : 
+    5296                 :          1 :     request_attribute =
+    5297                 :            :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
+    5298                 :            : 
+    5299                 :          1 :     measurement_record_length = sizeof(measurement_record);
+    5300                 :          1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
+    5301                 :            :                                      0, NULL, &number_of_block,
+    5302                 :            :                                      &measurement_record_length,
+    5303                 :            :                                      measurement_record);
+    5304                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
+    5305                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5306                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
+    5307                 :            :                      0);
+    5308                 :            : #endif
+    5309                 :          1 :     free(data);
+    5310                 :          1 : }
+    5311                 :            : 
+    5312                 :            : /**
+    5313                 :            :  * Test 27: Error case, request with signature, but response opaque data is (S+1) bytes shorter than informed
+    5314                 :            :  * Expected Behavior: get a RETURN_DEVICE_ERROR return code, correct transcript.message_m.buffer_size
+    5315                 :            :  **/
+    5316                 :          1 : static void libspdm_test_requester_get_measurements_case27(void **state)
+    5317                 :            : {
+    5318                 :            :     libspdm_return_t status;
+    5319                 :            :     libspdm_test_context_t *spdm_test_context;
+    5320                 :            :     libspdm_context_t *spdm_context;
+    5321                 :            :     uint8_t number_of_block;
+    5322                 :            :     uint32_t measurement_record_length;
+    5323                 :            :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
+    5324                 :            :     uint8_t request_attribute;
+    5325                 :            :     void *data;
+    5326                 :            :     size_t data_size;
+    5327                 :            :     void *hash;
+    5328                 :            :     size_t hash_size;
+    5329                 :            : 
+    5330                 :          1 :     spdm_test_context = *state;
+    5331                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5332                 :          1 :     spdm_test_context->case_id = 0x1B;
+    5333                 :            : 
+    5334                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5335                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5336                 :          1 :     spdm_context->connection_info.connection_state =
+    5337                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    5338                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5339                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    5340                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    5341                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    5342                 :            :                                                     &data_size, &hash, &hash_size);
+    5343                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    5344                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    5345                 :            :         m_libspdm_use_measurement_spec;
+    5346                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    5347                 :            :         m_libspdm_use_measurement_hash_algo;
+    5348                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    5349                 :            :         m_libspdm_use_hash_algo;
+    5350                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    5351                 :            :         m_libspdm_use_asym_algo;
+    5352                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    5353                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    5354                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5355                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    5356                 :            :         data_size;
+    5357                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    5358                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    5359                 :            :                      data, data_size);
+    5360                 :            : #else
+    5361                 :          1 :     libspdm_hash_all(
+    5362                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5363                 :            :         data, data_size,
+    5364                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    5365                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    5366                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    5367                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    5368                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5369                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    5370                 :            :         data, data_size,
+    5371                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    5372                 :            : #endif
+    5373                 :            : 
+    5374                 :          1 :     request_attribute =
+    5375                 :            :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
+    5376                 :            : 
+    5377                 :          1 :     measurement_record_length = sizeof(measurement_record);
+    5378                 :          1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
+    5379                 :            :                                      0, NULL, &number_of_block,
+    5380                 :            :                                      &measurement_record_length,
+    5381                 :            :                                      measurement_record);
+    5382                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
+    5383                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5384                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
+    5385                 :            :                      0);
+    5386                 :            : #endif
+    5387                 :          1 :     free(data);
+    5388                 :          1 : }
+    5389                 :            : 
+    5390                 :            : /**
+    5391                 :            :  * Test 28: Error case, request with signature, but response opaque data is 1 byte longer than informed
+    5392                 :            :  * Expected Behavior: get a RETURN_DEVICE_ERROR return code, correct transcript.message_m.buffer_size
+    5393                 :            :  **/
+    5394                 :          1 : static void libspdm_test_requester_get_measurements_case28(void **state)
+    5395                 :            : {
+    5396                 :            :     libspdm_return_t status;
+    5397                 :            :     libspdm_test_context_t *spdm_test_context;
+    5398                 :            :     libspdm_context_t *spdm_context;
+    5399                 :            :     uint8_t number_of_block;
+    5400                 :            :     uint32_t measurement_record_length;
+    5401                 :            :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
+    5402                 :            :     uint8_t request_attribute;
+    5403                 :            :     void *data;
+    5404                 :            :     size_t data_size;
+    5405                 :            :     void *hash;
+    5406                 :            :     size_t hash_size;
+    5407                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5408                 :            :     size_t ExpectedBufferSize;
+    5409                 :            : #endif
+    5410                 :          1 :     spdm_test_context = *state;
+    5411                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5412                 :          1 :     spdm_test_context->case_id = 0x1C;
+    5413                 :            : 
+    5414                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5415                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5416                 :          1 :     spdm_context->connection_info.connection_state =
+    5417                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    5418                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5419                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    5420                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    5421                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    5422                 :            :                                                     &data_size, &hash, &hash_size);
+    5423                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    5424                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    5425                 :            :         m_libspdm_use_measurement_spec;
+    5426                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    5427                 :            :         m_libspdm_use_measurement_hash_algo;
+    5428                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    5429                 :            :         m_libspdm_use_hash_algo;
+    5430                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    5431                 :            :         m_libspdm_use_asym_algo;
+    5432                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    5433                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    5434                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5435                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    5436                 :            :         data_size;
+    5437                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    5438                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    5439                 :            :                      data, data_size);
+    5440                 :            : #else
+    5441                 :          1 :     libspdm_hash_all(
+    5442                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5443                 :            :         data, data_size,
+    5444                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    5445                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    5446                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    5447                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    5448                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5449                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    5450                 :            :         data, data_size,
+    5451                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    5452                 :            : #endif
+    5453                 :            : 
+    5454                 :          1 :     request_attribute =
+    5455                 :            :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
+    5456                 :            : 
+    5457                 :          1 :     measurement_record_length = sizeof(measurement_record);
+    5458                 :          1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
+    5459                 :            :                                      0, NULL, &number_of_block,
+    5460                 :            :                                      &measurement_record_length,
+    5461                 :            :                                      measurement_record);
+    5462                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_VERIF_FAIL);
+    5463                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5464                 :            :     ExpectedBufferSize = 0;
+    5465                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
+    5466                 :            :                      ExpectedBufferSize);
+    5467                 :            : #endif
+    5468                 :          1 :     free(data);
+    5469                 :          1 : }
+    5470                 :            : 
+    5471                 :            : /**
+    5472                 :            :  * Test 29: request measurement without signature, but response opaque data is 1 byte longer than informed
+    5473                 :            :  * Expected Behavior: extra byte should just be ignored. Get a RETURN_SUCCESS return code, correct transcript.message_m.buffer_size
+    5474                 :            :  **/
+    5475                 :          1 : static void libspdm_test_requester_get_measurements_case29(void **state)
+    5476                 :            : {
+    5477                 :            :     libspdm_return_t status;
+    5478                 :            :     libspdm_test_context_t *spdm_test_context;
+    5479                 :            :     libspdm_context_t *spdm_context;
+    5480                 :            :     uint8_t number_of_block;
+    5481                 :            :     uint32_t measurement_record_length;
+    5482                 :            :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
+    5483                 :            :     uint8_t request_attribute;
+    5484                 :            :     void *data;
+    5485                 :            :     size_t data_size;
+    5486                 :            :     void *hash;
+    5487                 :            :     size_t hash_size;
+    5488                 :            : 
+    5489                 :          1 :     spdm_test_context = *state;
+    5490                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5491                 :          1 :     spdm_test_context->case_id = 0x1D;
+    5492                 :            : 
+    5493                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5494                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5495                 :          1 :     spdm_context->connection_info.connection_state =
+    5496                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    5497                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5498                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    5499                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    5500                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    5501                 :            :                                                     &data_size, &hash, &hash_size);
+    5502                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    5503                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    5504                 :            :         m_libspdm_use_measurement_spec;
+    5505                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    5506                 :            :         m_libspdm_use_measurement_hash_algo;
+    5507                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    5508                 :            :         m_libspdm_use_hash_algo;
+    5509                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    5510                 :            :         m_libspdm_use_asym_algo;
+    5511                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    5512                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    5513                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5514                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    5515                 :            :         data_size;
+    5516                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    5517                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    5518                 :            :                      data, data_size);
+    5519                 :            : #else
+    5520                 :          1 :     libspdm_hash_all(
+    5521                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5522                 :            :         data, data_size,
+    5523                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    5524                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    5525                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    5526                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    5527                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5528                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    5529                 :            :         data, data_size,
+    5530                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    5531                 :            : #endif
+    5532                 :            : 
+    5533                 :          1 :     request_attribute = 0;
+    5534                 :            : 
+    5535                 :          1 :     measurement_record_length = sizeof(measurement_record);
+    5536                 :          1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
+    5537                 :            :                                      0, NULL, &number_of_block,
+    5538                 :            :                                      &measurement_record_length,
+    5539                 :            :                                      measurement_record);
+    5540                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    5541                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5542                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
+    5543                 :            :                      sizeof(spdm_message_header_t) +
+    5544                 :            :                      sizeof(spdm_measurements_response_t) +
+    5545                 :            :                      sizeof(spdm_measurement_block_dmtf_t) +
+    5546                 :            :                      libspdm_get_measurement_hash_size(
+    5547                 :            :                          m_libspdm_use_measurement_hash_algo) +
+    5548                 :            :                      SPDM_NONCE_SIZE +
+    5549                 :            :                      sizeof(uint16_t) +
+    5550                 :            :                      SPDM_MAX_OPAQUE_DATA_SIZE / 2 - 1);
+    5551                 :            : #endif
+    5552                 :          1 :     free(data);
+    5553                 :          1 : }
+    5554                 :            : 
+    5555                 :            : /**
+    5556                 :            :  * Test 30:
+    5557                 :            :  * Expected Behavior:
+    5558                 :            :  **/
+    5559                 :          1 : static void libspdm_test_requester_get_measurements_case30(void **state)
+    5560                 :            : {
+    5561                 :          1 : }
+    5562                 :            : 
+    5563                 :            : /**
+    5564                 :            :  * Test 31:
+    5565                 :            :  * Expected Behavior:
+    5566                 :            :  **/
+    5567                 :          1 : static void libspdm_test_requester_get_measurements_case31(void **state)
+    5568                 :            : {
+    5569                 :          1 : }
+    5570                 :            : 
+    5571                 :            : /**
+    5572                 :            :  * Test 32: Successful response to get all measurement blocks, without signature
+    5573                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code, correct transcript.message_m.buffer_size
+    5574                 :            :  **/
+    5575                 :          1 : static void libspdm_test_requester_get_measurements_case32(void **state)
+    5576                 :            : {
+    5577                 :            :     libspdm_return_t status;
+    5578                 :            :     libspdm_test_context_t *spdm_test_context;
+    5579                 :            :     libspdm_context_t *spdm_context;
+    5580                 :            :     uint8_t number_of_block;
+    5581                 :            :     uint32_t measurement_record_length;
+    5582                 :            :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
+    5583                 :            :     uint8_t request_attribute;
+    5584                 :            :     void *data;
+    5585                 :            :     size_t data_size;
+    5586                 :            :     void *hash;
+    5587                 :            :     size_t hash_size;
+    5588                 :            : 
+    5589                 :          1 :     spdm_test_context = *state;
+    5590                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5591                 :          1 :     spdm_test_context->case_id = 0x20;
+    5592                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5593                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5594                 :          1 :     spdm_context->connection_info.connection_state =
+    5595                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    5596                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5597                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    5598                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    5599                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    5600                 :            :                                                     &data_size, &hash, &hash_size);
+    5601                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    5602                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    5603                 :            :         m_libspdm_use_measurement_spec;
+    5604                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    5605                 :            :         m_libspdm_use_measurement_hash_algo;
+    5606                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    5607                 :            :         m_libspdm_use_hash_algo;
+    5608                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    5609                 :            :         m_libspdm_use_asym_algo;
+    5610                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    5611                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    5612                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5613                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    5614                 :            :         data_size;
+    5615                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    5616                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    5617                 :            :                      data, data_size);
+    5618                 :            : #else
+    5619                 :          1 :     libspdm_hash_all(
+    5620                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5621                 :            :         data, data_size,
+    5622                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    5623                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    5624                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    5625                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    5626                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5627                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    5628                 :            :         data, data_size,
+    5629                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    5630                 :            : #endif
+    5631                 :            : 
+    5632                 :          1 :     request_attribute = 0;
+    5633                 :            : 
+    5634                 :          1 :     measurement_record_length = sizeof(measurement_record);
+    5635                 :          1 :     status = libspdm_get_measurement(
+    5636                 :            :         spdm_context, NULL, request_attribute,
+    5637                 :            :         SPDM_GET_MEASUREMENTS_REQUEST_MEASUREMENT_OPERATION_ALL_MEASUREMENTS,
+    5638                 :            :         0, NULL, &number_of_block, &measurement_record_length,
+    5639                 :            :         measurement_record);
+    5640                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    5641                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5642                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
+    5643                 :            :                      sizeof(spdm_message_header_t) +
+    5644                 :            :                      sizeof(spdm_measurements_response_t) +
+    5645                 :            :                      2 * (sizeof(spdm_measurement_block_dmtf_t) +
+    5646                 :            :                           libspdm_get_measurement_hash_size(
+    5647                 :            :                               m_libspdm_use_measurement_hash_algo)) +
+    5648                 :            :                      sizeof(uint16_t) + SPDM_NONCE_SIZE);
+    5649                 :            : #endif
+    5650                 :          1 :     free(data);
+    5651                 :          1 : }
+    5652                 :            : 
+    5653                 :            : /**
+    5654                 :            :  * Test 33: receiving an unexpected ERROR message from the responder.
+    5655                 :            :  * There are tests for all named codes, including some reserved ones
+    5656                 :            :  * (namely, 0x00, 0x0b, 0x0c, 0x3f, 0xfd, 0xfe).
+    5657                 :            :  * However, for having specific test cases, it is excluded from this case:
+    5658                 :            :  * Busy (0x03), ResponseNotReady (0x42), and RequestResync (0x43).
+    5659                 :            :  * Expected behavior: client returns a status of RETURN_DEVICE_ERROR.
+    5660                 :            :  **/
+    5661                 :          1 : static void libspdm_test_requester_get_measurements_case33(void **state) {
+    5662                 :            :     libspdm_return_t status;
+    5663                 :            :     libspdm_test_context_t    *spdm_test_context;
+    5664                 :            :     libspdm_context_t  *spdm_context;
+    5665                 :            :     uint8_t number_of_block;
+    5666                 :            :     uint32_t measurement_record_length;
+    5667                 :            :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
+    5668                 :            :     uint8_t request_attribute;
+    5669                 :            :     void                 *data;
+    5670                 :            :     size_t data_size;
+    5671                 :            :     void                 *hash;
+    5672                 :            :     size_t hash_size;
+    5673                 :            :     uint16_t error_code;
+    5674                 :            : 
+    5675                 :          1 :     spdm_test_context = *state;
+    5676                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5677                 :          1 :     spdm_test_context->case_id = 0x21;
+    5678                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5679                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    5680                 :          1 :     libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
+    5681                 :            :                                                      m_libspdm_use_asym_algo,
+    5682                 :            :                                                      &data, &data_size,
+    5683                 :            :                                                      &hash, &hash_size);
+    5684                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+    5685                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    5686                 :            :         m_libspdm_use_measurement_hash_algo;
+    5687                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    5688                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    5689                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    5690                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    5691                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5692                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    5693                 :            :         data_size;
+    5694                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    5695                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    5696                 :            :                      data, data_size);
+    5697                 :            : #else
+    5698                 :          1 :     libspdm_hash_all(
+    5699                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5700                 :            :         data, data_size,
+    5701                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    5702                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    5703                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    5704                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    5705                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5706                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    5707                 :            :         data, data_size,
+    5708                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    5709                 :            : #endif
+    5710                 :            : 
+    5711                 :          1 :     request_attribute = SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
+    5712                 :            : 
+    5713                 :          1 :     error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
+    5714         [ +  + ]:         19 :     while(error_code <= 0xff) {
+    5715                 :         18 :         spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    5716                 :         18 :         libspdm_reset_message_m(spdm_context, NULL);
+    5717                 :            : 
+    5718                 :         18 :         measurement_record_length = sizeof(measurement_record);
+    5719                 :         18 :         status = libspdm_get_measurement (spdm_context, NULL, request_attribute, 1, 0, NULL,
+    5720                 :            :                                           &number_of_block, &measurement_record_length,
+    5721                 :            :                                           measurement_record);
+    5722         [ -  + ]:         18 :         LIBSPDM_ASSERT_INT_EQUAL_CASE (status, LIBSPDM_STATUS_ERROR_PEER, error_code);
+    5723                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5724                 :            :         /* assert_int_equal (spdm_context->transcript.message_m.buffer_size, 0);*/
+    5725                 :            :         LIBSPDM_ASSERT_INT_EQUAL_CASE (spdm_context->transcript.message_m.buffer_size, 0,
+    5726                 :            :                                        error_code);
+    5727                 :            : #endif
+    5728                 :            : 
+    5729                 :         18 :         error_code++;
+    5730         [ +  + ]:         18 :         if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
+    5731                 :          1 :             error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
+    5732                 :            :         }
+    5733         [ +  + ]:         18 :         if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) { /*skip some reserved error codes (0d to 3e)*/
+    5734                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
+    5735                 :            :         }
+    5736         [ +  + ]:         18 :         if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) { /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
+    5737                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
+    5738                 :            :         }
+    5739                 :            :     }
+    5740                 :            : 
+    5741                 :          1 :     free(data);
+    5742                 :          1 : }
+    5743                 :            : 
+    5744                 :            : /**
+    5745                 :            :  * Test 34: Successful response to get a session based measurement with signature
+    5746                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code, with an empty session_transcript.message_m
+    5747                 :            :  **/
+    5748                 :          1 : static void libspdm_test_requester_get_measurements_case34(void **state)
+    5749                 :            : {
+    5750                 :            :     libspdm_return_t status;
+    5751                 :            :     libspdm_test_context_t *spdm_test_context;
+    5752                 :            :     libspdm_context_t *spdm_context;
+    5753                 :            :     uint32_t session_id;
+    5754                 :            :     libspdm_session_info_t *session_info;
+    5755                 :            :     uint8_t number_of_block;
+    5756                 :            :     uint32_t measurement_record_length;
+    5757                 :            :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
+    5758                 :            :     uint8_t request_attribute;
+    5759                 :            :     void *data;
+    5760                 :            :     size_t data_size;
+    5761                 :            :     void *hash;
+    5762                 :            :     size_t hash_size;
+    5763                 :            : 
+    5764                 :          1 :     spdm_test_context = *state;
+    5765                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5766                 :          1 :     spdm_test_context->case_id = 0x22;
+    5767                 :          1 :     spdm_context->connection_info.connection_state =
+    5768                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    5769                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5770                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    5771                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    5772                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    5773                 :            :                                                     &data_size, &hash, &hash_size);
+    5774                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5775                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    5776                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5777                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    5778                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5779                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    5780                 :          1 :     spdm_context->local_context.capability.flags |=
+    5781                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    5782                 :          1 :     spdm_context->local_context.capability.flags |=
+    5783                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    5784                 :          1 :     spdm_context->local_context.capability.flags |=
+    5785                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    5786                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    5787                 :            :         m_libspdm_use_dhe_algo;
+    5788                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    5789                 :            :         m_libspdm_use_aead_algo;
+    5790                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    5791                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    5792                 :          1 :     session_id = 0xFFFFFFFF;
+    5793                 :          1 :     session_info = &spdm_context->session_info[0];
+    5794                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+    5795                 :          1 :     libspdm_secured_message_set_session_state(
+    5796                 :            :         session_info->secured_message_context,
+    5797                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+    5798                 :            : 
+    5799                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    5800                 :            :         m_libspdm_use_measurement_spec;
+    5801                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    5802                 :            :         m_libspdm_use_measurement_hash_algo;
+    5803                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    5804                 :            :         m_libspdm_use_hash_algo;
+    5805                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    5806                 :            :         m_libspdm_use_asym_algo;
+    5807                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5808                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    5809                 :            :         data_size;
+    5810                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    5811                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    5812                 :            :                      data, data_size);
+    5813                 :            : #else
+    5814                 :          1 :     libspdm_hash_all(
+    5815                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5816                 :            :         data, data_size,
+    5817                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    5818                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    5819                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    5820                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    5821                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5822                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    5823                 :            :         data, data_size,
+    5824                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    5825                 :            : #endif
+    5826                 :            : 
+    5827                 :          1 :     request_attribute =
+    5828                 :            :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
+    5829                 :            : 
+    5830                 :          1 :     measurement_record_length = sizeof(measurement_record);
+    5831                 :          1 :     status = libspdm_get_measurement(spdm_context, &session_id, request_attribute, 1,
+    5832                 :            :                                      0, NULL, &number_of_block,
+    5833                 :            :                                      &measurement_record_length,
+    5834                 :            :                                      measurement_record);
+    5835                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    5836                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5837                 :            :     assert_int_equal(session_info->session_transcript.message_m.buffer_size, 0);
+    5838                 :            : #endif
+    5839                 :          1 :     free(data);
+    5840                 :          1 : }
+    5841                 :            : 
+    5842                 :            : /**
+    5843                 :            :  * Test 35: a request message is successfully sent and a response message is successfully received.
+    5844                 :            :  * Buffer M already has arbitrary data. No signature is requested.
+    5845                 :            :  * Expected Behavior: requester returns the status LIBSPDM_STATUS_SUCCESS and a MEASUREMENTS message
+    5846                 :            :  * is received, buffer M appends the exchanged GET_MEASUREMENTS and MEASUREMENTS messages.
+    5847                 :            :  *
+    5848                 :            :  * Note that this test is only exercised when LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT is enabled.
+    5849                 :            :  **/
+    5850                 :          1 : static void libspdm_test_requester_get_measurements_case35(void **state)
+    5851                 :            : {
+    5852                 :            :     libspdm_return_t status;
+    5853                 :            :     libspdm_test_context_t *spdm_test_context;
+    5854                 :            :     libspdm_context_t *spdm_context;
+    5855                 :            :     uint8_t number_of_block;
+    5856                 :            :     uint32_t measurement_record_length;
+    5857                 :            :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
+    5858                 :            :     uint8_t request_attribute;
+    5859                 :            :     void *data;
+    5860                 :            :     size_t data_size;
+    5861                 :            :     void *hash;
+    5862                 :            :     size_t hash_size;
+    5863                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5864                 :            :     const size_t arbitrary_fill_size = 18;
+    5865                 :            : #endif
+    5866                 :            : 
+    5867                 :          1 :     spdm_test_context = *state;
+    5868                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5869                 :          1 :     spdm_test_context->case_id = 0x23;
+    5870                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5871                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5872                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    5873                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5874                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    5875                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    5876                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    5877                 :            :                                                     &data_size, &hash, &hash_size);
+    5878                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    5879                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+    5880                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    5881                 :            :         m_libspdm_use_measurement_hash_algo;
+    5882                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    5883                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    5884                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    5885                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    5886                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5887                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
+    5888                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    5889                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    5890                 :            :                      data, data_size);
+    5891                 :            : #else
+    5892                 :          1 :     libspdm_hash_all(
+    5893                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5894                 :            :         data, data_size,
+    5895                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    5896                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    5897                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    5898                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    5899                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5900                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    5901                 :            :         data, data_size,
+    5902                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    5903                 :            : #endif
+    5904                 :            : 
+    5905                 :          1 :     request_attribute = 0; /* Do not request a signature. */
+    5906                 :            : 
+    5907                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5908                 :            :     /* Fill M buffer and local buffer with arbitrary data. */
+    5909                 :            :     libspdm_set_mem(spdm_context->transcript.message_m.buffer, arbitrary_fill_size, 0xFF);
+    5910                 :            :     libspdm_set_mem(m_libspdm_local_buffer, arbitrary_fill_size, 0xFF);
+    5911                 :            :     spdm_context->transcript.message_m.buffer_size = arbitrary_fill_size;
+    5912                 :            :     m_libspdm_local_buffer_size = arbitrary_fill_size;
+    5913                 :            : #endif
+    5914                 :            : 
+    5915                 :          1 :     measurement_record_length = sizeof(measurement_record);
+    5916                 :          1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
+    5917                 :            :                                      0, NULL, &number_of_block,
+    5918                 :            :                                      &measurement_record_length,
+    5919                 :            :                                      measurement_record);
+    5920                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    5921                 :            : 
+    5922                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5923                 :            :     /* Check that the size of the two buffers are the same (fill data + request + response) */
+    5924                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, m_libspdm_local_buffer_size);
+    5925                 :            :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer (0x%x):\n",
+    5926                 :            :                    m_libspdm_local_buffer_size));
+    5927                 :            :     libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    5928                 :            :     /* Check that the contents of the two buffers are the same (fill data, request, response) */
+    5929                 :            :     assert_memory_equal(spdm_context->transcript.message_m.buffer,
+    5930                 :            :                         m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    5931                 :            : #endif
+    5932                 :          1 :     free(data);
+    5933                 :          1 : }
+    5934                 :            : 
+    5935                 :          1 : static void libspdm_test_requester_get_measurements_case36(void **state)
+    5936                 :            : {
+    5937                 :            :     libspdm_return_t status;
+    5938                 :            :     libspdm_test_context_t *spdm_test_context;
+    5939                 :            :     libspdm_context_t *spdm_context;
+    5940                 :            :     uint8_t number_of_block;
+    5941                 :            :     uint32_t measurement_record_length;
+    5942                 :            :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
+    5943                 :            :     uint8_t request_attribute;
+    5944                 :            :     void *data;
+    5945                 :            :     size_t data_size;
+    5946                 :            :     void *hash;
+    5947                 :            :     size_t hash_size;
+    5948                 :            : 
+    5949                 :          1 :     spdm_test_context = *state;
+    5950                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5951                 :          1 :     spdm_test_context->case_id = 0x24;
+    5952                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    5953                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5954                 :          1 :     spdm_context->connection_info.connection_state =
+    5955                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    5956                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5957                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    5958                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    5959                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    5960                 :            :                                                     &data_size, &hash, &hash_size);
+    5961                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    5962                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    5963                 :            :         m_libspdm_use_measurement_spec;
+    5964                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    5965                 :            :         m_libspdm_use_measurement_hash_algo;
+    5966                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    5967                 :            :         m_libspdm_use_hash_algo;
+    5968                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    5969                 :            :         m_libspdm_use_asym_algo;
+    5970                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    5971                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    5972                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5973                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    5974                 :            :         data_size;
+    5975                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    5976                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    5977                 :            :                      data, data_size);
+    5978                 :            : #else
+    5979                 :          1 :     libspdm_hash_all(
+    5980                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5981                 :            :         data, data_size,
+    5982                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    5983                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    5984                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    5985                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    5986                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5987                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    5988                 :            :         data, data_size,
+    5989                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    5990                 :            : #endif
+    5991                 :            : 
+    5992                 :          1 :     request_attribute =
+    5993                 :            :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
+    5994                 :            : 
+    5995                 :          1 :     measurement_record_length = sizeof(measurement_record);
+    5996                 :          1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
+    5997                 :            :                                      0, NULL, &number_of_block,
+    5998                 :            :                                      &measurement_record_length,
+    5999                 :            :                                      measurement_record);
+    6000                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    6001                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    6002                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+    6003                 :            : #endif
+    6004                 :          1 :     free(data);
+    6005                 :          1 : }
+    6006                 :            : 
+    6007                 :          1 : static void libspdm_test_requester_get_measurements_case37(void **state)
+    6008                 :            : {
+    6009                 :            :     libspdm_return_t status;
+    6010                 :            :     libspdm_test_context_t *spdm_test_context;
+    6011                 :            :     libspdm_context_t *spdm_context;
+    6012                 :            :     uint8_t number_of_blocks;
+    6013                 :            :     uint8_t request_attribute;
+    6014                 :            :     void *data;
+    6015                 :            :     size_t data_size;
+    6016                 :            :     void *hash;
+    6017                 :            :     size_t hash_size;
+    6018                 :            : 
+    6019                 :          1 :     spdm_test_context = *state;
+    6020                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    6021                 :          1 :     spdm_test_context->case_id = 0x25;
+    6022                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    6023                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    6024                 :          1 :     spdm_context->connection_info.connection_state =
+    6025                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    6026                 :          1 :     spdm_context->connection_info.capability.flags |=
+    6027                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    6028                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    6029                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    6030                 :            :                                                     &data_size, &hash, &hash_size);
+    6031                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    6032                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    6033                 :            :         m_libspdm_use_measurement_spec;
+    6034                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    6035                 :            :         m_libspdm_use_measurement_hash_algo;
+    6036                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    6037                 :            :         m_libspdm_use_hash_algo;
+    6038                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    6039                 :            :         m_libspdm_use_asym_algo;
+    6040                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    6041                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    6042                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    6043                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    6044                 :            :         data_size;
+    6045                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    6046                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    6047                 :            :                      data, data_size);
+    6048                 :            : #else
+    6049                 :          1 :     libspdm_hash_all(
+    6050                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    6051                 :            :         data, data_size,
+    6052                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    6053                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    6054                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    6055                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    6056                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    6057                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    6058                 :            :         data, data_size,
+    6059                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    6060                 :            : #endif
+    6061                 :            : 
+    6062                 :          1 :     request_attribute = SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_RAW_BIT_STREAM_REQUESTED;
+    6063                 :            : 
+    6064                 :          1 :     status = libspdm_get_measurement(
+    6065                 :            :         spdm_context, NULL, request_attribute,
+    6066                 :            :         SPDM_GET_MEASUREMENTS_REQUEST_MEASUREMENT_OPERATION_TOTAL_NUMBER_OF_MEASUREMENTS,
+    6067                 :            :         0, NULL, &number_of_blocks, NULL, NULL);
+    6068                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    6069                 :          1 :     assert_int_equal(number_of_blocks, 4);
+    6070                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    6071                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
+    6072                 :            :                      sizeof(spdm_message_header_t) +
+    6073                 :            :                      sizeof(spdm_measurements_response_t) +
+    6074                 :            :                      SPDM_NONCE_SIZE + sizeof(uint16_t));
+    6075                 :            : #endif
+    6076                 :          1 :     free(data);
+    6077                 :          1 : }
+    6078                 :            : 
+    6079                 :          1 : static void libspdm_test_requester_get_measurements_case38(void **state)
+    6080                 :            : {
+    6081                 :            :     libspdm_return_t status;
+    6082                 :            :     libspdm_test_context_t *spdm_test_context;
+    6083                 :            :     libspdm_context_t *spdm_context;
+    6084                 :            :     uint8_t number_of_block;
+    6085                 :            :     uint32_t measurement_record_length;
+    6086                 :            :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
+    6087                 :            :     uint8_t request_attribute;
+    6088                 :            :     void *data;
+    6089                 :            :     size_t data_size;
+    6090                 :            : 
+    6091                 :          1 :     spdm_test_context = *state;
+    6092                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    6093                 :          1 :     spdm_test_context->case_id = 0x26;
+    6094                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    6095                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    6096                 :          1 :     spdm_context->connection_info.connection_state =
+    6097                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    6098                 :          1 :     spdm_context->connection_info.capability.flags |=
+    6099                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    6100                 :          1 :     spdm_context->connection_info.capability.flags |=
+    6101                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PUB_KEY_ID_CAP;
+    6102                 :          1 :     libspdm_read_responder_public_key(m_libspdm_use_asym_algo, &data, &data_size);
+    6103                 :          1 :     spdm_context->local_context.peer_public_key_provision = data;
+    6104                 :          1 :     spdm_context->local_context.peer_public_key_provision_size = data_size;
+    6105                 :            : 
+    6106                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    6107                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    6108                 :            :         m_libspdm_use_measurement_spec;
+    6109                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    6110                 :            :         m_libspdm_use_measurement_hash_algo;
+    6111                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    6112                 :            :         m_libspdm_use_hash_algo;
+    6113                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    6114                 :            :         m_libspdm_use_asym_algo;
+    6115                 :            : 
+    6116                 :          1 :     request_attribute =
+    6117                 :            :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
+    6118                 :            : 
+    6119                 :          1 :     measurement_record_length = sizeof(measurement_record);
+    6120                 :          1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
+    6121                 :            :                                      0xF, NULL, &number_of_block,
+    6122                 :            :                                      &measurement_record_length,
+    6123                 :            :                                      measurement_record);
+    6124                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    6125                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    6126                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+    6127                 :            : #endif
+    6128                 :          1 :     free(data);
+    6129                 :          1 : }
+    6130                 :            : 
+    6131                 :            : /**
+    6132                 :            :  * Test 39: Exercise the libspdm_get_measurement_ex function.
+    6133                 :            :  * Expected Behavior: client returns a status of RETURN_SUCCESS.
+    6134                 :            :  **/
+    6135                 :          1 : static void libspdm_test_requester_get_measurements_case39(void **state)
+    6136                 :            : {
+    6137                 :            :     libspdm_return_t status;
+    6138                 :            :     libspdm_test_context_t *spdm_test_context;
+    6139                 :            :     libspdm_context_t *spdm_context;
+    6140                 :            :     uint8_t number_of_block;
+    6141                 :            :     uint32_t measurement_record_length;
+    6142                 :            :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
+    6143                 :            :     uint8_t request_attribute;
+    6144                 :            :     void *data;
+    6145                 :            :     size_t data_size;
+    6146                 :            :     void *hash;
+    6147                 :            :     size_t hash_size;
+    6148                 :            :     uint8_t requester_nonce_in[SPDM_NONCE_SIZE];
+    6149                 :            :     uint8_t requester_nonce[SPDM_NONCE_SIZE];
+    6150                 :            :     uint8_t responder_nonce[SPDM_NONCE_SIZE];
+    6151                 :            :     uint8_t opaque_data[SPDM_MAX_OPAQUE_DATA_SIZE];
+    6152                 :            :     size_t opaque_data_size;
+    6153                 :            : 
+    6154                 :          1 :     spdm_test_context = *state;
+    6155                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    6156                 :          1 :     spdm_test_context->case_id = 0x27;
+    6157                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    6158                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    6159                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    6160                 :          1 :     spdm_context->connection_info.capability.flags |=
+    6161                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    6162                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    6163                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    6164                 :            :                                                     &data_size, &hash, &hash_size);
+    6165                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    6166                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+    6167                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    6168                 :            :         m_libspdm_use_measurement_hash_algo;
+    6169                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    6170                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    6171                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    6172                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    6173                 :          1 :     spdm_context->connection_info.algorithm.other_params_support =
+    6174                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
+    6175                 :            : 
+    6176                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    6177                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
+    6178                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    6179                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    6180                 :            :                      data, data_size);
+    6181                 :            : #else
+    6182                 :          1 :     libspdm_hash_all(
+    6183                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    6184                 :            :         data, data_size,
+    6185                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    6186                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    6187                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    6188                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    6189                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    6190                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    6191                 :            :         data, data_size,
+    6192                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    6193                 :            : #endif
+    6194                 :            : 
+    6195                 :          1 :     request_attribute = SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
+    6196                 :            : 
+    6197                 :          1 :     measurement_record_length = sizeof(measurement_record);
+    6198                 :            : 
+    6199         [ +  + ]:         33 :     for (int index = 0; index < SPDM_NONCE_SIZE; index++) {
+    6200                 :         32 :         requester_nonce_in[index] = 0x5c;
+    6201                 :         32 :         requester_nonce[index] = 0x00;
+    6202                 :         32 :         responder_nonce[index] = 0x00;
+    6203                 :            :     }
+    6204                 :            : 
+    6205                 :          1 :     opaque_data_size = sizeof(opaque_data);
+    6206                 :            : 
+    6207                 :          1 :     status = libspdm_get_measurement_ex(spdm_context, NULL, request_attribute, 1,
+    6208                 :            :                                         0, NULL, &number_of_block,
+    6209                 :            :                                         &measurement_record_length,
+    6210                 :            :                                         measurement_record, requester_nonce_in,
+    6211                 :            :                                         requester_nonce, responder_nonce,
+    6212                 :            :                                         opaque_data, &opaque_data_size);
+    6213                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    6214         [ +  + ]:         33 :     for (int index = 0; index < SPDM_NONCE_SIZE; index++) {
+    6215                 :         32 :         assert_int_equal (requester_nonce_in[index], requester_nonce[index]);
+    6216                 :         32 :         assert_int_equal (responder_nonce[index], 0x12);
+    6217                 :            :     }
+    6218                 :            : 
+    6219                 :          1 :     assert_int_equal(opaque_data_size, m_libspdm_opaque_data_size);
+    6220                 :          1 :     assert_memory_equal(opaque_data, m_libspdm_opaque_data, opaque_data_size);
+    6221                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    6222                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+    6223                 :            : #endif
+    6224                 :          1 :     free(data);
+    6225                 :          1 : }
+    6226                 :            : 
+    6227                 :            : /**
+    6228                 :            :  * Test 40: Successful case , correct measuerments context field , without signature
+    6229                 :            :  * Expected Behavior: client returns a status of RETURN_SUCCESS.
+    6230                 :            :  **/
+    6231                 :          1 : static void libspdm_test_requester_get_measurements_case40(void **state)
+    6232                 :            : {
+    6233                 :            :     libspdm_return_t status;
+    6234                 :            :     libspdm_test_context_t *spdm_test_context;
+    6235                 :            :     libspdm_context_t *spdm_context;
+    6236                 :            :     uint8_t number_of_block;
+    6237                 :            :     uint32_t measurement_record_length;
+    6238                 :            :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
+    6239                 :            :     uint8_t request_attribute;
+    6240                 :            :     void *data;
+    6241                 :            :     size_t data_size;
+    6242                 :            :     void *hash;
+    6243                 :            :     size_t hash_size;
+    6244                 :            : 
+    6245                 :          1 :     spdm_test_context = *state;
+    6246                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    6247                 :          1 :     spdm_test_context->case_id = 0x28;
+    6248                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+    6249                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    6250                 :          1 :     spdm_context->connection_info.connection_state =
+    6251                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    6252                 :          1 :     spdm_context->connection_info.capability.flags |=
+    6253                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    6254                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    6255                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    6256                 :            :                                                     &data_size, &hash, &hash_size);
+    6257                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    6258                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    6259                 :            :         m_libspdm_use_measurement_spec;
+    6260                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    6261                 :            :         m_libspdm_use_measurement_hash_algo;
+    6262                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    6263                 :            :         m_libspdm_use_hash_algo;
+    6264                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    6265                 :            :         m_libspdm_use_asym_algo;
+    6266                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    6267                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    6268                 :            : 
+    6269                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    6270                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
+    6271                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    6272                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    6273                 :            :                      data, data_size);
+    6274                 :            : #else
+    6275                 :          1 :     libspdm_hash_all(
+    6276                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    6277                 :            :         data, data_size,
+    6278                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    6279                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    6280                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    6281                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    6282                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    6283                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    6284                 :            :         data, data_size,
+    6285                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    6286                 :            : #endif
+    6287                 :            : 
+    6288                 :          1 :     measurement_record_length = sizeof(measurement_record);
+    6289                 :            : 
+    6290                 :          1 :     libspdm_set_mem(m_requester_context, SPDM_REQ_CONTEXT_SIZE, 0xAA);
+    6291                 :            : 
+    6292                 :          1 :     request_attribute = 0; /* Do not request a signature. */
+    6293                 :            : 
+    6294                 :          1 :     status = libspdm_get_measurement_ex2(spdm_context, NULL, request_attribute, 1,
+    6295                 :            :                                          0, m_requester_context, NULL, &number_of_block,
+    6296                 :            :                                          &measurement_record_length,
+    6297                 :            :                                          measurement_record, NULL, NULL, NULL, NULL, NULL);
+    6298                 :            : 
+    6299                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    6300                 :            : 
+    6301                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    6302                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
+    6303                 :            :                      sizeof(spdm_message_header_t) + SPDM_REQ_CONTEXT_SIZE +
+    6304                 :            :                      sizeof(spdm_measurements_response_t) +
+    6305                 :            :                      sizeof(spdm_measurement_block_dmtf_t) +
+    6306                 :            :                      libspdm_get_measurement_hash_size(m_libspdm_use_measurement_hash_algo) +
+    6307                 :            :                      SPDM_NONCE_SIZE + sizeof(uint16_t) + SPDM_REQ_CONTEXT_SIZE);
+    6308                 :            : #endif
+    6309                 :          1 :     free(data);
+    6310                 :          1 : }
+    6311                 :            : 
+    6312                 :            : /**
+    6313                 :            :  * Test 41: Error case , Measurement context fields are inconsistent , without signature
+    6314                 :            :  * Expected Behavior: get a LIBSPDM_STATUS_INVALID_MSG_FIELD return code
+    6315                 :            :  **/
+    6316                 :          1 : static void libspdm_test_requester_get_measurements_case41(void **state)
+    6317                 :            : {
+    6318                 :            :     libspdm_return_t status;
+    6319                 :            :     libspdm_test_context_t *spdm_test_context;
+    6320                 :            :     libspdm_context_t *spdm_context;
+    6321                 :            :     uint8_t number_of_block;
+    6322                 :            :     uint32_t measurement_record_length;
+    6323                 :            :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
+    6324                 :            :     uint8_t request_attribute;
+    6325                 :            :     void *data;
+    6326                 :            :     size_t data_size;
+    6327                 :            :     void *hash;
+    6328                 :            :     size_t hash_size;
+    6329                 :            : 
+    6330                 :          1 :     spdm_test_context = *state;
+    6331                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    6332                 :          1 :     spdm_test_context->case_id = 0x29;
+    6333                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+    6334                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    6335                 :          1 :     spdm_context->connection_info.connection_state =
+    6336                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    6337                 :          1 :     spdm_context->connection_info.capability.flags |=
+    6338                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    6339                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    6340                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    6341                 :            :                                                     &data_size, &hash, &hash_size);
+    6342                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    6343                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    6344                 :            :         m_libspdm_use_measurement_spec;
+    6345                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    6346                 :            :         m_libspdm_use_measurement_hash_algo;
+    6347                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    6348                 :            :         m_libspdm_use_hash_algo;
+    6349                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    6350                 :            :         m_libspdm_use_asym_algo;
+    6351                 :          1 :     spdm_context->local_context.algorithm.measurement_spec =
+    6352                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    6353                 :            : 
+    6354                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    6355                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
+    6356                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    6357                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    6358                 :            :                      data, data_size);
+    6359                 :            : #else
+    6360                 :          1 :     libspdm_hash_all(
+    6361                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    6362                 :            :         data, data_size,
+    6363                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    6364                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    6365                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    6366                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    6367                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    6368                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    6369                 :            :         data, data_size,
+    6370                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    6371                 :            : #endif
+    6372                 :            : 
+    6373                 :          1 :     measurement_record_length = sizeof(measurement_record);
+    6374                 :            : 
+    6375                 :          1 :     libspdm_set_mem(m_requester_context, SPDM_REQ_CONTEXT_SIZE, 0xAA);
+    6376                 :            : 
+    6377                 :          1 :     request_attribute = 0; /* Do not request a signature. */
+    6378                 :            : 
+    6379                 :          1 :     status = libspdm_get_measurement_ex2(spdm_context, NULL, request_attribute, 1,
+    6380                 :            :                                          0, m_requester_context, NULL, &number_of_block,
+    6381                 :            :                                          &measurement_record_length,
+    6382                 :            :                                          measurement_record, NULL, NULL, NULL, NULL, NULL);
+    6383                 :            : 
+    6384                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    6385                 :            : 
+    6386                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    6387                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+    6388                 :            : #endif
+    6389                 :          1 :     free(data);
+    6390                 :          1 : }
+    6391                 :            : libspdm_test_context_t m_libspdm_requester_get_measurements_test_context = {
+    6392                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+    6393                 :            :     true,
+    6394                 :            :     libspdm_requester_get_measurements_test_send_message,
+    6395                 :            :     libspdm_requester_get_measurements_test_receive_message,
+    6396                 :            : };
+    6397                 :            : 
+    6398                 :          1 : int libspdm_requester_get_measurements_test_main(void)
+    6399                 :            : {
+    6400                 :          1 :     const struct CMUnitTest spdm_requester_get_measurements_tests[] = {
+    6401                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case1),
+    6402                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case2),
+    6403                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case3),
+    6404                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case4),
+    6405                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case5),
+    6406                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case6),
+    6407                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case7),
+    6408                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case8),
+    6409                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case9),
+    6410                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case10),
+    6411                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case11),
+    6412                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case12),
+    6413                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case13),
+    6414                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case14),
+    6415                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case15),
+    6416                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case16),
+    6417                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case17),
+    6418                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case18),
+    6419                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case19),
+    6420                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case20),
+    6421                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case21),
+    6422                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case22),
+    6423                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case23),
+    6424                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case24),
+    6425                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case25),
+    6426                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case26),
+    6427                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case27),
+    6428                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case28),
+    6429                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case29),
+    6430                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case30),
+    6431                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case31),
+    6432                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case32),
+    6433                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case33),
+    6434                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case34),
+    6435                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case35),
+    6436                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case36),
+    6437                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case37),
+    6438                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case38),
+    6439                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case39),
+    6440                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case40),
+    6441                 :            :         cmocka_unit_test(libspdm_test_requester_get_measurements_case41),
+    6442                 :            :     };
+    6443                 :            : 
+    6444                 :          1 :     libspdm_setup_test_context(&m_libspdm_requester_get_measurements_test_context);
+    6445                 :            : 
+    6446                 :          1 :     return cmocka_run_group_tests(spdm_requester_get_measurements_tests,
+    6447                 :            :                                   libspdm_unit_test_group_setup,
+    6448                 :            :                                   libspdm_unit_test_group_teardown);
+    6449                 :            : }
+    6450                 :            : 
+    6451                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/get_version.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_requester/get_version.c.func-sort-c.html new file mode 100644 index 00000000000..b008fe028c2 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/get_version.c.func-sort-c.html @@ -0,0 +1,113 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/get_version.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - get_version.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:16233947.8 %
Date:2024-09-22 08:21:07Functions:88100.0 %
Branches:135026.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_get_version_test_main1
libspdm_test_requester_get_version_case101
libspdm_test_requester_get_version_case151
libspdm_test_requester_get_version_case161
libspdm_test_requester_get_version_case21
libspdm_test_requester_get_version_case61
libspdm_requester_get_version_test_receive_message6
libspdm_requester_get_version_test_send_message6
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/get_version.c.func.html b/coverage_log/unit_test/test_spdm_requester/get_version.c.func.html new file mode 100644 index 00000000000..55cceee7842 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/get_version.c.func.html @@ -0,0 +1,113 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/get_version.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - get_version.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:16233947.8 %
Date:2024-09-22 08:21:07Functions:88100.0 %
Branches:135026.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_get_version_test_main1
libspdm_requester_get_version_test_receive_message6
libspdm_requester_get_version_test_send_message6
libspdm_test_requester_get_version_case101
libspdm_test_requester_get_version_case151
libspdm_test_requester_get_version_case161
libspdm_test_requester_get_version_case21
libspdm_test_requester_get_version_case61
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/get_version.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/get_version.c.gcov.html new file mode 100644 index 00000000000..cf8025cbb66 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/get_version.c.gcov.html @@ -0,0 +1,918 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/get_version.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - get_version.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:16233947.8 %
Date:2024-09-22 08:21:07Functions:88100.0 %
Branches:135026.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_requester_lib.h"
+       9                 :            : 
+      10                 :            : #pragma pack(1)
+      11                 :            : typedef struct {
+      12                 :            :     spdm_message_header_t header;
+      13                 :            :     uint8_t reserved;
+      14                 :            :     uint8_t version_number_entry_count;
+      15                 :            :     spdm_version_number_t version_number_entry[LIBSPDM_MAX_VERSION_COUNT];
+      16                 :            : } libspdm_version_response_mine_t;
+      17                 :            : #pragma pack()
+      18                 :            : 
+      19                 :            : static size_t m_libspdm_local_buffer_size;
+      20                 :            : static uint8_t m_libspdm_local_buffer[LIBSPDM_MAX_MESSAGE_VCA_BUFFER_SIZE];
+      21                 :            : 
+      22                 :          6 : static libspdm_return_t libspdm_requester_get_version_test_send_message(
+      23                 :            :     void *spdm_context, size_t request_size, const void *request,
+      24                 :            :     uint64_t timeout)
+      25                 :            : {
+      26                 :            :     libspdm_test_context_t *spdm_test_context;
+      27                 :            : 
+      28                 :          6 :     spdm_test_context = libspdm_get_test_context();
+      29   [ -  +  -  -  :          6 :     switch (spdm_test_context->case_id) {
+          -  +  -  -  -  
+          +  -  -  -  -  
+             +  +  -  -  
+                      - ]
+      30                 :          0 :     case 0x1:
+      31                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      32                 :          1 :     case 0x2:
+      33                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      34                 :          0 :     case 0x3:
+      35                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      36                 :          0 :     case 0x4:
+      37                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      38                 :          0 :     case 0x5:
+      39                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      40                 :          2 :     case 0x6:
+      41                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+      42                 :          0 :     case 0x7:
+      43                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      44                 :          0 :     case 0x8:
+      45                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      46                 :          0 :     case 0x9:
+      47                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      48                 :          1 :     case 0xA:
+      49                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      50                 :          0 :     case 0xB:
+      51                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      52                 :          0 :     case 0xC:
+      53                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      54                 :          0 :     case 0xD:
+      55                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      56                 :          0 :     case 0xE:
+      57                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      58                 :          1 :     case 0xF:
+      59                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      60                 :          1 :     case 0x10: {
+      61                 :          1 :         const uint8_t *ptr = (const uint8_t *)request;
+      62                 :            : 
+      63                 :          1 :         m_libspdm_local_buffer_size = 0;
+      64                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+      65                 :          1 :                          &ptr[1], request_size - 1);
+      66                 :          1 :         m_libspdm_local_buffer_size += (request_size - 1);
+      67                 :            :     }
+      68                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      69                 :          0 :     case 0x11:
+      70                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      71                 :          0 :     case 0x12:
+      72                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      73                 :          0 :     default:
+      74                 :          0 :         return LIBSPDM_STATUS_SEND_FAIL;
+      75                 :            :     }
+      76                 :            : }
+      77                 :            : 
+      78                 :          6 : static libspdm_return_t libspdm_requester_get_version_test_receive_message(
+      79                 :            :     void *spdm_context, size_t *response_size,
+      80                 :            :     void **response, uint64_t timeout)
+      81                 :            : {
+      82                 :            :     libspdm_test_context_t *spdm_test_context;
+      83                 :            : 
+      84                 :          6 :     spdm_test_context = libspdm_get_test_context();
+      85   [ -  +  -  -  :          6 :     switch (spdm_test_context->case_id) {
+          -  +  -  -  -  
+          +  -  -  -  -  
+             +  +  -  -  
+                      - ]
+      86                 :          0 :     case 0x1:
+      87                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+      88                 :            : 
+      89                 :          1 :     case 0x2: {
+      90                 :            :         libspdm_version_response_mine_t *spdm_response;
+      91                 :            :         size_t spdm_response_size;
+      92                 :            :         size_t transport_header_size;
+      93                 :            : 
+      94                 :          1 :         spdm_response_size = sizeof(libspdm_version_response_mine_t);
+      95                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+      96                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+      97                 :            : 
+      98                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+      99                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     100                 :          1 :         spdm_response->header.request_response_code = SPDM_VERSION;
+     101                 :          1 :         spdm_response->header.param1 = 0;
+     102                 :          1 :         spdm_response->header.param2 = 0;
+     103                 :          1 :         spdm_response->version_number_entry_count = 2;
+     104                 :          1 :         spdm_response->version_number_entry[0] = 0x10 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     105                 :          1 :         spdm_response->version_number_entry[1] = 0x11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     106                 :            : 
+     107                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     108                 :            :                                               false, spdm_response_size,
+     109                 :            :                                               spdm_response,
+     110                 :            :                                               response_size, response);
+     111                 :            :     }
+     112                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     113                 :            : 
+     114                 :          0 :     case 0x3: {
+     115                 :            :         spdm_version_response_t *spdm_response;
+     116                 :            :         size_t spdm_response_size;
+     117                 :            :         size_t transport_header_size;
+     118                 :            : 
+     119                 :          0 :         spdm_response_size = sizeof(spdm_version_response_t);
+     120                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     121                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     122                 :            : 
+     123                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     124                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     125                 :          0 :         spdm_response->header.request_response_code = SPDM_VERSION;
+     126                 :          0 :         spdm_response->header.param1 = 0;
+     127                 :          0 :         spdm_response->header.param2 = 0;
+     128                 :          0 :         spdm_response->version_number_entry_count = 0;
+     129                 :            : 
+     130                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     131                 :            :                                               false, spdm_response_size,
+     132                 :            :                                               spdm_response,
+     133                 :            :                                               response_size, response);
+     134                 :            :     }
+     135                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     136                 :            : 
+     137                 :          0 :     case 0x4: {
+     138                 :            :         spdm_error_response_t *spdm_response;
+     139                 :            :         size_t spdm_response_size;
+     140                 :            :         size_t transport_header_size;
+     141                 :            : 
+     142                 :          0 :         spdm_response_size = sizeof(spdm_error_response_t);
+     143                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     144                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     145                 :            : 
+     146                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     147                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     148                 :          0 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     149                 :          0 :         spdm_response->header.param1 = SPDM_ERROR_CODE_INVALID_REQUEST;
+     150                 :          0 :         spdm_response->header.param2 = 0;
+     151                 :            : 
+     152                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     153                 :            :                                               false, spdm_response_size,
+     154                 :            :                                               spdm_response,
+     155                 :            :                                               response_size, response);
+     156                 :            :     }
+     157                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     158                 :            : 
+     159                 :          0 :     case 0x5: {
+     160                 :            :         spdm_error_response_t *spdm_response;
+     161                 :            :         size_t spdm_response_size;
+     162                 :            :         size_t transport_header_size;
+     163                 :            : 
+     164                 :          0 :         spdm_response_size = sizeof(spdm_error_response_t);
+     165                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     166                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     167                 :            : 
+     168                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     169                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     170                 :          0 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     171                 :          0 :         spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
+     172                 :          0 :         spdm_response->header.param2 = 0;
+     173                 :            : 
+     174                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     175                 :            :                                               false, spdm_response_size,
+     176                 :            :                                               spdm_response,
+     177                 :            :                                               response_size, response);
+     178                 :            :     }
+     179                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     180                 :            : 
+     181                 :          2 :     case 0x6: {
+     182                 :            :         static size_t sub_index1 = 0;
+     183         [ +  + ]:          2 :         if (sub_index1 == 0) {
+     184                 :            :             spdm_error_response_t *spdm_response;
+     185                 :            :             size_t spdm_response_size;
+     186                 :            :             size_t transport_header_size;
+     187                 :            : 
+     188                 :          1 :             spdm_response_size = sizeof(spdm_error_response_t);
+     189                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     190                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     191                 :            : 
+     192                 :          1 :             libspdm_zero_mem(spdm_response, spdm_response_size);
+     193                 :          1 :             spdm_response->header.spdm_version =
+     194                 :            :                 SPDM_MESSAGE_VERSION_10;
+     195                 :          1 :             spdm_response->header.request_response_code = SPDM_ERROR;
+     196                 :          1 :             spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
+     197                 :          1 :             spdm_response->header.param2 = 0;
+     198                 :            : 
+     199                 :          1 :             libspdm_transport_test_encode_message(
+     200                 :            :                 spdm_context, NULL, false, false,
+     201                 :            :                 spdm_response_size, spdm_response,
+     202                 :            :                 response_size, response);
+     203         [ +  - ]:          1 :         } else if (sub_index1 == 1) {
+     204                 :            :             libspdm_version_response_mine_t *spdm_response;
+     205                 :            :             size_t spdm_response_size;
+     206                 :            :             size_t transport_header_size;
+     207                 :            : 
+     208                 :          1 :             spdm_response_size = sizeof(libspdm_version_response_mine_t);
+     209                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     210                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     211                 :            : 
+     212                 :          1 :             libspdm_zero_mem(spdm_response, spdm_response_size);
+     213                 :          1 :             spdm_response->header.spdm_version =
+     214                 :            :                 SPDM_MESSAGE_VERSION_10;
+     215                 :          1 :             spdm_response->header.request_response_code =
+     216                 :            :                 SPDM_VERSION;
+     217                 :          1 :             spdm_response->header.param1 = 0;
+     218                 :          1 :             spdm_response->header.param2 = 0;
+     219                 :          1 :             spdm_response->version_number_entry_count = 2;
+     220                 :          1 :             spdm_response->version_number_entry[0] = 0x10 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     221                 :          1 :             spdm_response->version_number_entry[1] = 0x11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     222                 :            : 
+     223                 :          1 :             libspdm_transport_test_encode_message(
+     224                 :            :                 spdm_context, NULL, false, false,
+     225                 :            :                 spdm_response_size, spdm_response,
+     226                 :            :                 response_size, response);
+     227                 :            :         }
+     228                 :          2 :         sub_index1++;
+     229                 :            :     }
+     230                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     231                 :            : 
+     232                 :          0 :     case 0x7: {
+     233                 :            :         spdm_error_response_t *spdm_response;
+     234                 :            :         size_t spdm_response_size;
+     235                 :            :         size_t transport_header_size;
+     236                 :            : 
+     237                 :          0 :         spdm_response_size = sizeof(spdm_error_response_t);
+     238                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     239                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     240                 :            : 
+     241                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     242                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     243                 :          0 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     244                 :          0 :         spdm_response->header.param1 = SPDM_ERROR_CODE_REQUEST_RESYNCH;
+     245                 :          0 :         spdm_response->header.param2 = 0;
+     246                 :            : 
+     247                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     248                 :            :                                               false, spdm_response_size,
+     249                 :            :                                               spdm_response,
+     250                 :            :                                               response_size, response);
+     251                 :            :     }
+     252                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     253                 :            : 
+     254                 :          0 :     case 0x8: {
+     255                 :            :         spdm_error_response_data_response_not_ready_t *spdm_response;
+     256                 :            :         size_t spdm_response_size;
+     257                 :            :         size_t transport_header_size;
+     258                 :            : 
+     259                 :          0 :         spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
+     260                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     261                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     262                 :            : 
+     263                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     264                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     265                 :          0 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     266                 :          0 :         spdm_response->header.param1 =
+     267                 :            :             SPDM_ERROR_CODE_RESPONSE_NOT_READY;
+     268                 :          0 :         spdm_response->header.param2 = 0;
+     269                 :          0 :         spdm_response->extend_error_data.rd_exponent = 1;
+     270                 :          0 :         spdm_response->extend_error_data.rd_tm = 2;
+     271                 :          0 :         spdm_response->extend_error_data.request_code = SPDM_GET_VERSION;
+     272                 :          0 :         spdm_response->extend_error_data.token = 0;
+     273                 :            : 
+     274                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     275                 :            :                                               false, spdm_response_size,
+     276                 :            :                                               spdm_response,
+     277                 :            :                                               response_size, response);
+     278                 :            :     }
+     279                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     280                 :            : 
+     281                 :          0 :     case 0x9:
+     282                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     283                 :            : 
+     284                 :          1 :     case 0xA: {
+     285                 :            :         libspdm_version_response_mine_t *spdm_response;
+     286                 :            :         size_t spdm_response_size;
+     287                 :            :         size_t transport_header_size;
+     288                 :            : 
+     289                 :          1 :         spdm_response_size = sizeof(libspdm_version_response_mine_t);
+     290                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     291                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     292                 :            : 
+     293                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     294                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     295                 :          1 :         spdm_response->header.request_response_code = SPDM_VERSION;
+     296                 :          1 :         spdm_response->header.param1 = 0;
+     297                 :          1 :         spdm_response->header.param2 = 0;
+     298                 :          1 :         spdm_response->version_number_entry_count = 2;
+     299                 :          1 :         spdm_response->version_number_entry[0] = 0x10 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     300                 :          1 :         spdm_response->version_number_entry[1] = 0x11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     301                 :          1 :         spdm_response->version_number_entry[2] = 0x12 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     302                 :            : 
+     303                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     304                 :            :                                               false, spdm_response_size,
+     305                 :            :                                               spdm_response,
+     306                 :            :                                               response_size, response);
+     307                 :            :     }
+     308                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     309                 :            : 
+     310                 :          0 :     case 0xB: {
+     311                 :            :         libspdm_version_response_mine_t *spdm_response;
+     312                 :            :         size_t spdm_response_size;
+     313                 :            :         size_t transport_header_size;
+     314                 :            : 
+     315                 :          0 :         spdm_response_size = sizeof(libspdm_version_response_mine_t);
+     316                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     317                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     318                 :            : 
+     319                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     320                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     321                 :          0 :         spdm_response->header.request_response_code = SPDM_VERSION;
+     322                 :          0 :         spdm_response->header.param1 = 0;
+     323                 :          0 :         spdm_response->header.param2 = 0;
+     324                 :          0 :         spdm_response->version_number_entry_count = 2;
+     325                 :          0 :         spdm_response->version_number_entry[0] = 0xA0 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     326                 :          0 :         spdm_response->version_number_entry[1] = 0xA1 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     327                 :            : 
+     328                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     329                 :            :                                               false, spdm_response_size,
+     330                 :            :                                               spdm_response,
+     331                 :            :                                               response_size, response);
+     332                 :            :     }
+     333                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     334                 :            : 
+     335                 :          0 :     case 0xC: {
+     336                 :            :         libspdm_version_response_mine_t *spdm_response;
+     337                 :            :         size_t spdm_response_size;
+     338                 :            :         size_t transport_header_size;
+     339                 :            : 
+     340                 :          0 :         spdm_response_size = sizeof(libspdm_version_response_mine_t);
+     341                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     342                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     343                 :            : 
+     344                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     345                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     346                 :          0 :         spdm_response->header.request_response_code = SPDM_VERSION;
+     347                 :          0 :         spdm_response->header.param1 = 0;
+     348                 :          0 :         spdm_response->header.param2 = 0;
+     349                 :          0 :         spdm_response->version_number_entry_count = 2;
+     350                 :          0 :         spdm_response->version_number_entry[0] = 0x10 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     351                 :          0 :         spdm_response->version_number_entry[1] = 0x11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     352                 :            : 
+     353                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     354                 :            :                                               false, spdm_response_size,
+     355                 :            :                                               spdm_response,
+     356                 :            :                                               response_size, response);
+     357                 :            :     }
+     358                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     359                 :            : 
+     360                 :          0 :     case 0xD: {
+     361                 :            :         libspdm_version_response_mine_t *spdm_response;
+     362                 :            :         size_t spdm_response_size;
+     363                 :            :         size_t transport_header_size;
+     364                 :            : 
+     365                 :          0 :         spdm_response_size = sizeof(libspdm_version_response_mine_t);
+     366                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     367                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     368                 :            : 
+     369                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     370                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     371                 :          0 :         spdm_response->header.request_response_code = SPDM_GET_VERSION;
+     372                 :          0 :         spdm_response->header.param1 = 0;
+     373                 :          0 :         spdm_response->header.param2 = 0;
+     374                 :          0 :         spdm_response->version_number_entry_count = 2;
+     375                 :          0 :         spdm_response->version_number_entry[0] = 0x10 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     376                 :          0 :         spdm_response->version_number_entry[1] = 0x11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     377                 :            : 
+     378                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     379                 :            :                                               false, spdm_response_size,
+     380                 :            :                                               spdm_response,
+     381                 :            :                                               response_size, response);
+     382                 :            :     }
+     383                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     384                 :            : 
+     385                 :          0 :     case 0xE:
+     386                 :            :     {
+     387                 :            :         static uint16_t error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
+     388                 :            : 
+     389                 :            :         spdm_error_response_t *spdm_response;
+     390                 :            :         size_t spdm_response_size;
+     391                 :            :         size_t transport_header_size;
+     392                 :            : 
+     393                 :          0 :         spdm_response_size = sizeof(libspdm_version_response_mine_t);
+     394                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     395                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     396                 :            : 
+     397         [ #  # ]:          0 :         if(error_code <= 0xff) {
+     398                 :          0 :             libspdm_zero_mem (spdm_response, spdm_response_size);
+     399                 :          0 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     400                 :          0 :             spdm_response->header.request_response_code = SPDM_ERROR;
+     401                 :          0 :             spdm_response->header.param1 = (uint8_t) error_code;
+     402                 :            : 
+     403                 :          0 :             libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+     404                 :            :                                                    spdm_response_size, spdm_response,
+     405                 :            :                                                    response_size, response);
+     406                 :            :         }
+     407                 :            : 
+     408                 :          0 :         error_code++;
+     409         [ #  # ]:          0 :         if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
+     410                 :          0 :             error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
+     411                 :            :         }
+     412         [ #  # ]:          0 :         if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) { /*skip some reserved error codes (0d to 3e)*/
+     413                 :          0 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
+     414                 :            :         }
+     415         [ #  # ]:          0 :         if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) { /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
+     416                 :          0 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
+     417                 :            :         }
+     418                 :            :     }
+     419                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     420                 :            : 
+     421                 :          1 :     case 0xF: {
+     422                 :            :         libspdm_version_response_mine_t *spdm_response;
+     423                 :            :         size_t spdm_response_size;
+     424                 :            :         size_t transport_header_size;
+     425                 :            : 
+     426                 :          1 :         spdm_response_size = sizeof(libspdm_version_response_mine_t);
+     427                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     428                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     429                 :            : 
+     430                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     431                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     432                 :          1 :         spdm_response->header.request_response_code = SPDM_VERSION;
+     433                 :          1 :         spdm_response->header.param1 = 0;
+     434                 :          1 :         spdm_response->header.param2 = 0;
+     435                 :          1 :         spdm_response->version_number_entry_count = 5;
+     436                 :          1 :         spdm_response->version_number_entry[0] = 0x42 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     437                 :          1 :         spdm_response->version_number_entry[1] = 0x52 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     438                 :          1 :         spdm_response->version_number_entry[2] = 0x12 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     439                 :          1 :         spdm_response->version_number_entry[3] = 0x11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     440                 :          1 :         spdm_response->version_number_entry[4] = 0x10 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     441                 :            : 
+     442                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     443                 :            :                                               false, spdm_response_size,
+     444                 :            :                                               spdm_response,
+     445                 :            :                                               response_size, response);
+     446                 :            :     }
+     447                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     448                 :            : 
+     449                 :          1 :     case 0x10: {
+     450                 :            :         libspdm_version_response_mine_t *spdm_response;
+     451                 :            :         size_t spdm_response_size;
+     452                 :            :         size_t transport_header_size;
+     453                 :            : 
+     454                 :          1 :         spdm_response_size = sizeof(libspdm_version_response_mine_t);
+     455                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     456                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     457                 :            : 
+     458                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     459                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     460                 :          1 :         spdm_response->header.request_response_code = SPDM_VERSION;
+     461                 :          1 :         spdm_response->header.param1 = 0;
+     462                 :          1 :         spdm_response->header.param2 = 0;
+     463                 :          1 :         spdm_response->version_number_entry_count = 2;
+     464                 :          1 :         spdm_response->version_number_entry[0] = 0x10 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     465                 :          1 :         spdm_response->version_number_entry[1] = 0x11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     466                 :            : 
+     467                 :          1 :         spdm_response_size = 10;
+     468                 :            : 
+     469                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+     470                 :            :                          sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
+     471                 :            :                          (uint8_t *)spdm_response, spdm_response_size);
+     472                 :          1 :         m_libspdm_local_buffer_size += spdm_response_size;
+     473                 :            : 
+     474                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     475                 :            :                                               false, spdm_response_size,
+     476                 :            :                                               spdm_response,
+     477                 :            :                                               response_size, response);
+     478                 :            :     }
+     479                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     480                 :            : 
+     481                 :          0 :     case 0x11: {
+     482                 :            :         spdm_message_header_t *spdm_response;
+     483                 :            :         size_t spdm_response_size;
+     484                 :            :         size_t transport_header_size;
+     485                 :            : 
+     486                 :          0 :         spdm_response_size = sizeof(spdm_message_header_t);
+     487                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     488                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     489                 :            : 
+     490                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     491                 :          0 :         spdm_response->spdm_version = SPDM_MESSAGE_VERSION_10;
+     492                 :          0 :         spdm_response->request_response_code = SPDM_VERSION;
+     493                 :          0 :         spdm_response->param1 = 0;
+     494                 :          0 :         spdm_response->param2 = 0;
+     495                 :            : 
+     496                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     497                 :            :                                               false, spdm_response_size,
+     498                 :            :                                               spdm_response,
+     499                 :            :                                               response_size, response);
+     500                 :            : 
+     501                 :            :     }
+     502                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     503                 :            : 
+     504                 :          0 :     case 0x12: {
+     505                 :            :         spdm_version_response_t *spdm_response;
+     506                 :            :         size_t spdm_response_size;
+     507                 :            :         size_t transport_header_size;
+     508                 :            : 
+     509                 :          0 :         spdm_response_size = sizeof(spdm_version_response_t);
+     510                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     511                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     512                 :            : 
+     513                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     514                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     515                 :          0 :         spdm_response->header.request_response_code = SPDM_VERSION;
+     516                 :          0 :         spdm_response->header.param1 = 0;
+     517                 :          0 :         spdm_response->header.param2 = 0;
+     518                 :          0 :         spdm_response->version_number_entry_count = LIBSPDM_MAX_VERSION_COUNT;
+     519                 :            : 
+     520                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     521                 :            :                                               false, spdm_response_size,
+     522                 :            :                                               spdm_response,
+     523                 :            :                                               response_size, response);
+     524                 :            : 
+     525                 :            :     }
+     526                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     527                 :            : 
+     528                 :          0 :     default:
+     529                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+     530                 :            :     }
+     531                 :            : }
+     532                 :            : 
+     533                 :            : /**
+     534                 :            :  * Test 1: Can be populated with new test.
+     535                 :            :  **/
+     536                 :            : 
+     537                 :            : /*
+     538                 :            :  * static void libspdm_test_requester_get_version_case1(void **state)
+     539                 :            :  * {
+     540                 :            :  * }
+     541                 :            :  */
+     542                 :            : 
+     543                 :            : /**
+     544                 :            :  * Test 2: receiving a correct VERSION message with available version 1.0 and 1.1.
+     545                 :            :  * Expected behavior: client returns a status of LIBSPDM_STATUS_SUCCESS.
+     546                 :            :  **/
+     547                 :          1 : static void libspdm_test_requester_get_version_case2(void **state)
+     548                 :            : {
+     549                 :            :     libspdm_return_t status;
+     550                 :            :     libspdm_test_context_t *spdm_test_context;
+     551                 :            :     libspdm_context_t *spdm_context;
+     552                 :            : 
+     553                 :          1 :     spdm_test_context = *state;
+     554                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     555                 :          1 :     spdm_test_context->case_id = 0x2;
+     556                 :            : 
+     557                 :          1 :     status = libspdm_get_version(spdm_context, NULL, NULL);
+     558                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     559                 :          1 : }
+     560                 :            : 
+     561                 :            : /**
+     562                 :            :  * Test 3: Can be populated with new test.
+     563                 :            :  **/
+     564                 :            : 
+     565                 :            : /*
+     566                 :            :  * static void libspdm_test_requester_get_version_case3(void **state)
+     567                 :            :  * {
+     568                 :            :  * }
+     569                 :            :  */
+     570                 :            : 
+     571                 :            : /**
+     572                 :            :  * Test 4: Can be populated with new test.
+     573                 :            :  **/
+     574                 :            : 
+     575                 :            : /*
+     576                 :            :  * static void libspdm_test_requester_get_version_case4(void **state)
+     577                 :            :  * {
+     578                 :            :  * }
+     579                 :            :  */
+     580                 :            : 
+     581                 :            : /**
+     582                 :            :  * Test 5: Can be populated with new test.
+     583                 :            :  **/
+     584                 :            : 
+     585                 :            : /*
+     586                 :            :  * static void libspdm_test_requester_get_version_case5(void **state)
+     587                 :            :  * {
+     588                 :            :  * }
+     589                 :            :  */
+     590                 :            : 
+     591                 :            : /**
+     592                 :            :  * Test 6: on the first try, receiving a Busy ERROR message, and on retry, receiving
+     593                 :            :  * a correct VERSION message with available version 1.0 and 1.1.
+     594                 :            :  * Expected behavior: client returns a status of LIBSPDM_STATUS_SUCCESS.
+     595                 :            :  **/
+     596                 :          1 : static void libspdm_test_requester_get_version_case6(void **state)
+     597                 :            : {
+     598                 :            :     libspdm_return_t status;
+     599                 :            :     libspdm_test_context_t *spdm_test_context;
+     600                 :            :     libspdm_context_t *spdm_context;
+     601                 :            : 
+     602                 :          1 :     spdm_test_context = *state;
+     603                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     604                 :          1 :     spdm_test_context->case_id = 0x6;
+     605                 :            : 
+     606                 :          1 :     spdm_context->retry_times = 3;
+     607                 :          1 :     status = libspdm_get_version(spdm_context, NULL, NULL);
+     608                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     609                 :          1 : }
+     610                 :            : 
+     611                 :            : /**
+     612                 :            :  * Test 7: Can be populated with new test.
+     613                 :            :  **/
+     614                 :            : 
+     615                 :            : /*
+     616                 :            :  * static void libspdm_test_requester_get_version_case7(void **state)
+     617                 :            :  * {
+     618                 :            :  * }
+     619                 :            :  */
+     620                 :            : 
+     621                 :            : /**
+     622                 :            :  * Test 8: Can be populated with new test.
+     623                 :            :  **/
+     624                 :            : 
+     625                 :            : /*
+     626                 :            :  * static void libspdm_test_requester_get_version_case8(void **state)
+     627                 :            :  * {
+     628                 :            :  * }
+     629                 :            :  */
+     630                 :            : 
+     631                 :            : /**
+     632                 :            :  * Test 9: Can be populated with new test.
+     633                 :            :  **/
+     634                 :            : 
+     635                 :            : /*
+     636                 :            :  * static void libspdm_test_requester_get_version_case9(void **state)
+     637                 :            :  * {
+     638                 :            :  * }
+     639                 :            :  */
+     640                 :            : 
+     641                 :            : /**
+     642                 :            :  * Test 10: receiving a VERSION message with a larger list of available versions than indicated.
+     643                 :            :  * The presence of only two versions are indicated, but the VERSION message presents a list
+     644                 :            :  * with 3 versions: 1.0, 1.1 and 1.2.
+     645                 :            :  * Expected behavior: client returns a status of LIBSPDM_STATUS_SUCCESS, but truncate the message
+     646                 :            :  * to consider only the two first versions, as indicated in the message.
+     647                 :            :  **/
+     648                 :          1 : static void libspdm_test_requester_get_version_case10(void **state)
+     649                 :            : {
+     650                 :            :     libspdm_return_t status;
+     651                 :            :     libspdm_test_context_t *spdm_test_context;
+     652                 :            :     libspdm_context_t *spdm_context;
+     653                 :            : 
+     654                 :          1 :     spdm_test_context = *state;
+     655                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     656                 :          1 :     spdm_test_context->case_id = 0xA;
+     657                 :            : 
+     658                 :          1 :     status = libspdm_get_version(spdm_context, NULL, NULL);
+     659                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     660                 :          1 : }
+     661                 :            : 
+     662                 :            : /**
+     663                 :            :  * Test 11: Can be populated with new test.
+     664                 :            :  **/
+     665                 :            : 
+     666                 :            : /*
+     667                 :            :  * static void libspdm_test_requester_get_version_case11(void **state)
+     668                 :            :  * {
+     669                 :            :  * }
+     670                 :            :  */
+     671                 :            : 
+     672                 :            : /**
+     673                 :            :  * Test 12: Can be populated with new test.
+     674                 :            :  **/
+     675                 :            : 
+     676                 :            : /*
+     677                 :            :  * static void libspdm_test_requester_get_version_case12(void **state)
+     678                 :            :  * {
+     679                 :            :  * }
+     680                 :            :  */
+     681                 :            : 
+     682                 :            : /**
+     683                 :            :  * Test 13: Can be populated with new test.
+     684                 :            :  **/
+     685                 :            : 
+     686                 :            : /*
+     687                 :            :  * static void libspdm_test_requester_get_version_case13(void **state)
+     688                 :            :  * {
+     689                 :            :  * }
+     690                 :            :  */
+     691                 :            : 
+     692                 :            : /**
+     693                 :            :  * Test 14: Can be populated with new test.
+     694                 :            :  **/
+     695                 :            : 
+     696                 :            : /*
+     697                 :            :  * static void libspdm_test_requester_get_version_case14(void **state)
+     698                 :            :  * {
+     699                 :            :  * }
+     700                 :            :  */
+     701                 :            : 
+     702                 :            : /**
+     703                 :            :  * Test 15: receiving a VERSION message with unordered vesion list.
+     704                 :            :  * Requester list:5.5, 0.9, 1.0, 1.1
+     705                 :            :  * Responder list:4.2, 5.2, 1.2, 1.1, 1.0
+     706                 :            :  * Expected behavior: client returns a status of LIBSPDM_STATUS_SUCCESS and right negotiated version 1.1.
+     707                 :            :  **/
+     708                 :          1 : static void libspdm_test_requester_get_version_case15(void **state)
+     709                 :            : {
+     710                 :            :     libspdm_return_t status;
+     711                 :            :     libspdm_test_context_t *spdm_test_context;
+     712                 :            :     libspdm_context_t *spdm_context;
+     713                 :            : 
+     714                 :          1 :     spdm_test_context = *state;
+     715                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     716                 :          1 :     spdm_test_context->case_id = 0xF;
+     717                 :          1 :     spdm_context->local_context.version.spdm_version_count = 4;
+     718                 :          1 :     spdm_context->local_context.version.spdm_version[0] = 0x55 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     719                 :          1 :     spdm_context->local_context.version.spdm_version[1] = 0x09 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     720                 :          1 :     spdm_context->local_context.version.spdm_version[2] = 0x10 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     721                 :          1 :     spdm_context->local_context.version.spdm_version[3] = 0x11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     722                 :          1 :     status = libspdm_get_version(spdm_context, NULL, NULL);
+     723                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     724                 :          1 :     assert_int_equal(
+     725                 :            :         spdm_context->connection_info.version >> SPDM_VERSION_NUMBER_SHIFT_BIT, 0x11);
+     726                 :          1 : }
+     727                 :            : 
+     728                 :            : /**
+     729                 :            :  * Test 16: receiving a correct VERSION message with available version 1.0 and 1.1.
+     730                 :            :  * Buffers A, B and C already have arbitrary data.
+     731                 :            :  * Expected behavior: client returns a status of RETURN_SUCCESS, buffers A, B and C
+     732                 :            :  * should be first reset, and then buffer A receives only the exchanged GET_VERSION
+     733                 :            :  * and VERSION messages.
+     734                 :            :  **/
+     735                 :          1 : static void libspdm_test_requester_get_version_case16(void **state)
+     736                 :            : {
+     737                 :            :     libspdm_return_t status;
+     738                 :            :     libspdm_test_context_t *spdm_test_context;
+     739                 :            :     libspdm_context_t *spdm_context;
+     740                 :            : 
+     741                 :          1 :     spdm_test_context = *state;
+     742                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     743                 :          1 :     spdm_test_context->case_id = 0x10;
+     744                 :            : 
+     745                 :            :     /*filling buffers with arbitrary data*/
+     746                 :          1 :     libspdm_set_mem(spdm_context->transcript.message_a.buffer, 10, (uint8_t) 0xFF);
+     747                 :          1 :     spdm_context->transcript.message_a.buffer_size = 10;
+     748                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     749                 :            :     libspdm_set_mem(spdm_context->transcript.message_b.buffer, 8, (uint8_t) 0xEE);
+     750                 :            :     spdm_context->transcript.message_b.buffer_size = 8;
+     751                 :            :     libspdm_set_mem(spdm_context->transcript.message_c.buffer, 12, (uint8_t) 0xDD);
+     752                 :            :     spdm_context->transcript.message_c.buffer_size = 12;
+     753                 :            : #endif
+     754                 :            : 
+     755                 :          1 :     status = libspdm_get_version(spdm_context, NULL, NULL);
+     756                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     757                 :          1 :     assert_int_equal(spdm_context->transcript.message_a.buffer_size,
+     758                 :            :                      m_libspdm_local_buffer_size);
+     759                 :          1 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer (0x%zx):\n",
+     760                 :            :                    m_libspdm_local_buffer_size));
+     761                 :          1 :     libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+     762                 :          1 :     assert_memory_equal(spdm_context->transcript.message_a.buffer,
+     763                 :            :                         m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+     764                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     765                 :            :     assert_int_equal(spdm_context->transcript.message_b.buffer_size, 0);
+     766                 :            :     assert_int_equal(spdm_context->transcript.message_c.buffer_size, 0);
+     767                 :            : #endif
+     768                 :          1 : }
+     769                 :            : 
+     770                 :            : /**
+     771                 :            :  * Test 17: Can be populated with new test.
+     772                 :            :  **/
+     773                 :            : 
+     774                 :            : /*
+     775                 :            :  * static void libspdm_test_requester_get_version_case17(void **state)
+     776                 :            :  * {
+     777                 :            :  * }
+     778                 :            :  */
+     779                 :            : 
+     780                 :            : /**
+     781                 :            :  * Test 18: Can be populated with new test.
+     782                 :            :  **/
+     783                 :            : 
+     784                 :            : /*
+     785                 :            :  * static void libspdm_test_requester_get_version_case18(void **state)
+     786                 :            :  * {
+     787                 :            :  * }
+     788                 :            :  */
+     789                 :            : 
+     790                 :            : libspdm_test_context_t m_libspdm_requester_get_version_test_context = {
+     791                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+     792                 :            :     true,
+     793                 :            :     libspdm_requester_get_version_test_send_message,
+     794                 :            :     libspdm_requester_get_version_test_receive_message,
+     795                 :            : };
+     796                 :            : 
+     797                 :          1 : int libspdm_requester_get_version_test_main(void)
+     798                 :            : {
+     799                 :          1 :     const struct CMUnitTest spdm_requester_get_version_tests[] = {
+     800                 :            :         /* cmocka_unit_test(libspdm_test_requester_get_version_case1), */
+     801                 :            :         cmocka_unit_test(libspdm_test_requester_get_version_case2),
+     802                 :            :         /* cmocka_unit_test(libspdm_test_requester_get_version_case3),
+     803                 :            :          * cmocka_unit_test(libspdm_test_requester_get_version_case4),
+     804                 :            :          * cmocka_unit_test(libspdm_test_requester_get_version_case5), */
+     805                 :            :         cmocka_unit_test(libspdm_test_requester_get_version_case6),
+     806                 :            :         /* cmocka_unit_test(libspdm_test_requester_get_version_case7),
+     807                 :            :          * cmocka_unit_test(libspdm_test_requester_get_version_case8),
+     808                 :            :          * cmocka_unit_test(libspdm_test_requester_get_version_case9), */
+     809                 :            :         cmocka_unit_test(libspdm_test_requester_get_version_case10),
+     810                 :            :         /* cmocka_unit_test(libspdm_test_requester_get_version_case11),
+     811                 :            :          * cmocka_unit_test(libspdm_test_requester_get_version_case12),
+     812                 :            :          * cmocka_unit_test(libspdm_test_requester_get_version_case13),
+     813                 :            :          * cmocka_unit_test(libspdm_test_requester_get_version_case14), */
+     814                 :            :         cmocka_unit_test(libspdm_test_requester_get_version_case15),
+     815                 :            :         cmocka_unit_test(libspdm_test_requester_get_version_case16),
+     816                 :            :         /* cmocka_unit_test(libspdm_test_requester_get_version_case17),
+     817                 :            :          * cmocka_unit_test(libspdm_test_requester_get_version_case18), */
+     818                 :            :     };
+     819                 :            : 
+     820                 :          1 :     libspdm_setup_test_context(&m_libspdm_requester_get_version_test_context);
+     821                 :            : 
+     822                 :          1 :     return cmocka_run_group_tests(spdm_requester_get_version_tests,
+     823                 :            :                                   libspdm_unit_test_group_setup,
+     824                 :            :                                   libspdm_unit_test_group_teardown);
+     825                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/heartbeat.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_requester/heartbeat.c.func-sort-c.html new file mode 100644 index 00000000000..c30cb89f61c --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/heartbeat.c.func-sort-c.html @@ -0,0 +1,153 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/heartbeat.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - heartbeat.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:76079895.2 %
Date:2024-09-22 08:21:07Functions:1818100.0 %
Branches:598470.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_heartbeat_test_main1
libspdm_test_requester_heartbeat_case11
libspdm_test_requester_heartbeat_case101
libspdm_test_requester_heartbeat_case111
libspdm_test_requester_heartbeat_case121
libspdm_test_requester_heartbeat_case131
libspdm_test_requester_heartbeat_case21
libspdm_test_requester_heartbeat_case31
libspdm_test_requester_heartbeat_case41
libspdm_test_requester_heartbeat_case51
libspdm_test_requester_heartbeat_case61
libspdm_test_requester_heartbeat_case71
libspdm_test_requester_heartbeat_case81
libspdm_test_requester_heartbeat_case91
libspdm_secured_message_set_response_data_encryption_key29
libspdm_secured_message_set_response_data_salt29
libspdm_requester_heartbeat_test_receive_message30
libspdm_requester_heartbeat_test_send_message31
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/heartbeat.c.func.html b/coverage_log/unit_test/test_spdm_requester/heartbeat.c.func.html new file mode 100644 index 00000000000..16b86c2234c --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/heartbeat.c.func.html @@ -0,0 +1,153 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/heartbeat.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - heartbeat.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:76079895.2 %
Date:2024-09-22 08:21:07Functions:1818100.0 %
Branches:598470.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_heartbeat_test_main1
libspdm_requester_heartbeat_test_receive_message30
libspdm_requester_heartbeat_test_send_message31
libspdm_secured_message_set_response_data_encryption_key29
libspdm_secured_message_set_response_data_salt29
libspdm_test_requester_heartbeat_case11
libspdm_test_requester_heartbeat_case101
libspdm_test_requester_heartbeat_case111
libspdm_test_requester_heartbeat_case121
libspdm_test_requester_heartbeat_case131
libspdm_test_requester_heartbeat_case21
libspdm_test_requester_heartbeat_case31
libspdm_test_requester_heartbeat_case41
libspdm_test_requester_heartbeat_case51
libspdm_test_requester_heartbeat_case61
libspdm_test_requester_heartbeat_case71
libspdm_test_requester_heartbeat_case81
libspdm_test_requester_heartbeat_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/heartbeat.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/heartbeat.c.gcov.html new file mode 100644 index 00000000000..bd7b001a06b --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/heartbeat.c.gcov.html @@ -0,0 +1,1942 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/heartbeat.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - heartbeat.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:76079895.2 %
Date:2024-09-22 08:21:07Functions:1818100.0 %
Branches:598470.2 %
+
+ + + + + + + + +

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

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
vendor_request.c +
73.7%73.7%
+
73.7 %70 / 9566.7 %4 / 611.1 %2 / 18
negotiate_algorithms.c +
50.3%50.3%
+
50.3 %633 / 1258100.0 %39 / 3923.7 %18 / 76
get_capabilities.c +
45.9%45.9%
+
45.9 %297 / 647100.0 %12 / 1225.3 %21 / 83
get_version.c +
47.8%47.8%
+
47.8 %162 / 339100.0 %8 / 826.0 %13 / 50
get_digests.c +
62.9%62.9%
+
62.9 %567 / 901100.0 %32 / 3228.0 %28 / 100
get_key_pair_info.c +
21.7%21.7%
+
21.7 %62 / 28680.0 %4 / 540.0 %2 / 5
get_event_types.c +
97.4%97.4%
+
97.4 %74 / 76100.0 %5 / 550.0 %3 / 6
test_spdm_requester.c +
51.8%51.8%
+
51.8 %43 / 83100.0 %1 / 150.0 %40 / 80
set_certificate.c +
84.8%84.8%
+
84.8 %218 / 257100.0 %11 / 1154.2 %13 / 24
encap_certificate.c +
82.4%82.4%
+
82.4 %154 / 18787.5 %7 / 863.6 %14 / 22
psk_finish.c +
91.9%91.9%
+
91.9 %955 / 1039100.0 %22 / 2264.4 %67 / 104
key_update.c +
90.3%90.3%
+
90.3 %1861 / 2061100.0 %41 / 4165.6 %244 / 372
subscribe_event_types.c +
100.0%
+
100.0 %101 / 101100.0 %7 / 766.7 %4 / 6
set_key_pair_info.c +
95.8%95.8%
+
95.8 %91 / 95100.0 %6 / 666.7 %4 / 6
get_csr.c +
94.9%94.9%
+
94.9 %241 / 254100.0 %13 / 1370.0 %14 / 20
end_session.c +
95.0%95.0%
+
95.0 %716 / 754100.0 %17 / 1770.2 %59 / 84
heartbeat.c +
95.2%95.2%
+
95.2 %760 / 798100.0 %18 / 1870.2 %59 / 84
encap_request.c +
95.9%95.9%
+
95.9 %562 / 586100.0 %13 / 1375.8 %50 / 66
psk_exchange.c +
92.7%92.7%
+
92.7 %2086 / 225196.8 %30 / 3176.7 %92 / 120
finish.c +
90.3%90.3%
+
90.3 %1505 / 1666100.0 %28 / 2877.1 %64 / 83
get_certificate.c +
93.8%93.8%
+
93.8 %1912 / 2038100.0 %34 / 3477.4 %247 / 319
key_exchange.c +
97.2%97.2%
+
97.2 %3520 / 3622100.0 %38 / 3878.7 %118 / 150
get_measurement_extension_log.c +
96.1%96.1%
+
96.1 %489 / 509100.0 %14 / 1480.9 %38 / 47
get_measurements.c +
95.3%95.3%
+
95.3 %2586 / 2713100.0 %45 / 4584.1 %132 / 157
challenge.c +
89.2%89.2%
+
89.2 %1457 / 163496.8 %30 / 3184.4 %65 / 77
chunk_get.c +
98.4%98.4%
+
98.4 %377 / 383100.0 %11 / 1187.5 %42 / 48
chunk_send.c +
97.5%97.5%
+
97.5 %231 / 237100.0 %17 / 1788.3 %53 / 60
encap_challenge_auth.c +
100.0%
+
100.0 %239 / 239100.0 %9 / 9-0 / 0
encap_key_update.c +
100.0%
+
100.0 %344 / 344100.0 %18 / 18-0 / 0
encap_digests.c +
100.0%
+
100.0 %132 / 132100.0 %7 / 7100.0 %4 / 4
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/index-sort-f.html b/coverage_log/unit_test/test_spdm_requester/index-sort-f.html new file mode 100644 index 00000000000..8fd47c53d7f --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/index-sort-f.html @@ -0,0 +1,455 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requesterHitTotalCoverage
Test:coverage.infoLines:224452558587.7 %
Date:2024-09-22 08:21:07Functions:54154798.9 %
Branches:1510227166.5 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
vendor_request.c +
73.7%73.7%
+
73.7 %70 / 9566.7 %4 / 611.1 %2 / 18
get_key_pair_info.c +
21.7%21.7%
+
21.7 %62 / 28680.0 %4 / 540.0 %2 / 5
encap_certificate.c +
82.4%82.4%
+
82.4 %154 / 18787.5 %7 / 863.6 %14 / 22
challenge.c +
89.2%89.2%
+
89.2 %1457 / 163496.8 %30 / 3184.4 %65 / 77
psk_exchange.c +
92.7%92.7%
+
92.7 %2086 / 225196.8 %30 / 3176.7 %92 / 120
test_spdm_requester.c +
51.8%51.8%
+
51.8 %43 / 83100.0 %1 / 150.0 %40 / 80
get_event_types.c +
97.4%97.4%
+
97.4 %74 / 76100.0 %5 / 550.0 %3 / 6
set_key_pair_info.c +
95.8%95.8%
+
95.8 %91 / 95100.0 %6 / 666.7 %4 / 6
subscribe_event_types.c +
100.0%
+
100.0 %101 / 101100.0 %7 / 766.7 %4 / 6
encap_digests.c +
100.0%
+
100.0 %132 / 132100.0 %7 / 7100.0 %4 / 4
get_version.c +
47.8%47.8%
+
47.8 %162 / 339100.0 %8 / 826.0 %13 / 50
encap_challenge_auth.c +
100.0%
+
100.0 %239 / 239100.0 %9 / 9-0 / 0
chunk_get.c +
98.4%98.4%
+
98.4 %377 / 383100.0 %11 / 1187.5 %42 / 48
set_certificate.c +
84.8%84.8%
+
84.8 %218 / 257100.0 %11 / 1154.2 %13 / 24
get_capabilities.c +
45.9%45.9%
+
45.9 %297 / 647100.0 %12 / 1225.3 %21 / 83
encap_request.c +
95.9%95.9%
+
95.9 %562 / 586100.0 %13 / 1375.8 %50 / 66
get_csr.c +
94.9%94.9%
+
94.9 %241 / 254100.0 %13 / 1370.0 %14 / 20
get_measurement_extension_log.c +
96.1%96.1%
+
96.1 %489 / 509100.0 %14 / 1480.9 %38 / 47
chunk_send.c +
97.5%97.5%
+
97.5 %231 / 237100.0 %17 / 1788.3 %53 / 60
end_session.c +
95.0%95.0%
+
95.0 %716 / 754100.0 %17 / 1770.2 %59 / 84
heartbeat.c +
95.2%95.2%
+
95.2 %760 / 798100.0 %18 / 1870.2 %59 / 84
encap_key_update.c +
100.0%
+
100.0 %344 / 344100.0 %18 / 18-0 / 0
psk_finish.c +
91.9%91.9%
+
91.9 %955 / 1039100.0 %22 / 2264.4 %67 / 104
finish.c +
90.3%90.3%
+
90.3 %1505 / 1666100.0 %28 / 2877.1 %64 / 83
get_digests.c +
62.9%62.9%
+
62.9 %567 / 901100.0 %32 / 3228.0 %28 / 100
get_certificate.c +
93.8%93.8%
+
93.8 %1912 / 2038100.0 %34 / 3477.4 %247 / 319
key_exchange.c +
97.2%97.2%
+
97.2 %3520 / 3622100.0 %38 / 3878.7 %118 / 150
negotiate_algorithms.c +
50.3%50.3%
+
50.3 %633 / 1258100.0 %39 / 3923.7 %18 / 76
key_update.c +
90.3%90.3%
+
90.3 %1861 / 2061100.0 %41 / 4165.6 %244 / 372
get_measurements.c +
95.3%95.3%
+
95.3 %2586 / 2713100.0 %45 / 4584.1 %132 / 157
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/index-sort-l.html b/coverage_log/unit_test/test_spdm_requester/index-sort-l.html new file mode 100644 index 00000000000..7ec14112618 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/index-sort-l.html @@ -0,0 +1,455 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requesterHitTotalCoverage
Test:coverage.infoLines:224452558587.7 %
Date:2024-09-22 08:21:07Functions:54154798.9 %
Branches:1510227166.5 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
get_key_pair_info.c +
21.7%21.7%
+
21.7 %62 / 28680.0 %4 / 540.0 %2 / 5
get_capabilities.c +
45.9%45.9%
+
45.9 %297 / 647100.0 %12 / 1225.3 %21 / 83
get_version.c +
47.8%47.8%
+
47.8 %162 / 339100.0 %8 / 826.0 %13 / 50
negotiate_algorithms.c +
50.3%50.3%
+
50.3 %633 / 1258100.0 %39 / 3923.7 %18 / 76
test_spdm_requester.c +
51.8%51.8%
+
51.8 %43 / 83100.0 %1 / 150.0 %40 / 80
get_digests.c +
62.9%62.9%
+
62.9 %567 / 901100.0 %32 / 3228.0 %28 / 100
vendor_request.c +
73.7%73.7%
+
73.7 %70 / 9566.7 %4 / 611.1 %2 / 18
encap_certificate.c +
82.4%82.4%
+
82.4 %154 / 18787.5 %7 / 863.6 %14 / 22
set_certificate.c +
84.8%84.8%
+
84.8 %218 / 257100.0 %11 / 1154.2 %13 / 24
challenge.c +
89.2%89.2%
+
89.2 %1457 / 163496.8 %30 / 3184.4 %65 / 77
key_update.c +
90.3%90.3%
+
90.3 %1861 / 2061100.0 %41 / 4165.6 %244 / 372
finish.c +
90.3%90.3%
+
90.3 %1505 / 1666100.0 %28 / 2877.1 %64 / 83
psk_finish.c +
91.9%91.9%
+
91.9 %955 / 1039100.0 %22 / 2264.4 %67 / 104
psk_exchange.c +
92.7%92.7%
+
92.7 %2086 / 225196.8 %30 / 3176.7 %92 / 120
get_certificate.c +
93.8%93.8%
+
93.8 %1912 / 2038100.0 %34 / 3477.4 %247 / 319
get_csr.c +
94.9%94.9%
+
94.9 %241 / 254100.0 %13 / 1370.0 %14 / 20
end_session.c +
95.0%95.0%
+
95.0 %716 / 754100.0 %17 / 1770.2 %59 / 84
heartbeat.c +
95.2%95.2%
+
95.2 %760 / 798100.0 %18 / 1870.2 %59 / 84
get_measurements.c +
95.3%95.3%
+
95.3 %2586 / 2713100.0 %45 / 4584.1 %132 / 157
set_key_pair_info.c +
95.8%95.8%
+
95.8 %91 / 95100.0 %6 / 666.7 %4 / 6
encap_request.c +
95.9%95.9%
+
95.9 %562 / 586100.0 %13 / 1375.8 %50 / 66
get_measurement_extension_log.c +
96.1%96.1%
+
96.1 %489 / 509100.0 %14 / 1480.9 %38 / 47
key_exchange.c +
97.2%97.2%
+
97.2 %3520 / 3622100.0 %38 / 3878.7 %118 / 150
get_event_types.c +
97.4%97.4%
+
97.4 %74 / 76100.0 %5 / 550.0 %3 / 6
chunk_send.c +
97.5%97.5%
+
97.5 %231 / 237100.0 %17 / 1788.3 %53 / 60
chunk_get.c +
98.4%98.4%
+
98.4 %377 / 383100.0 %11 / 1187.5 %42 / 48
subscribe_event_types.c +
100.0%
+
100.0 %101 / 101100.0 %7 / 766.7 %4 / 6
encap_digests.c +
100.0%
+
100.0 %132 / 132100.0 %7 / 7100.0 %4 / 4
encap_challenge_auth.c +
100.0%
+
100.0 %239 / 239100.0 %9 / 9-0 / 0
encap_key_update.c +
100.0%
+
100.0 %344 / 344100.0 %18 / 18-0 / 0
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/index.html b/coverage_log/unit_test/test_spdm_requester/index.html new file mode 100644 index 00000000000..0e9b35c3389 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/index.html @@ -0,0 +1,455 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requesterHitTotalCoverage
Test:coverage.infoLines:224452558587.7 %
Date:2024-09-22 08:21:07Functions:54154798.9 %
Branches:1510227166.5 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
challenge.c +
89.2%89.2%
+
89.2 %1457 / 163496.8 %30 / 3184.4 %65 / 77
chunk_get.c +
98.4%98.4%
+
98.4 %377 / 383100.0 %11 / 1187.5 %42 / 48
chunk_send.c +
97.5%97.5%
+
97.5 %231 / 237100.0 %17 / 1788.3 %53 / 60
encap_certificate.c +
82.4%82.4%
+
82.4 %154 / 18787.5 %7 / 863.6 %14 / 22
encap_challenge_auth.c +
100.0%
+
100.0 %239 / 239100.0 %9 / 9-0 / 0
encap_digests.c +
100.0%
+
100.0 %132 / 132100.0 %7 / 7100.0 %4 / 4
encap_key_update.c +
100.0%
+
100.0 %344 / 344100.0 %18 / 18-0 / 0
encap_request.c +
95.9%95.9%
+
95.9 %562 / 586100.0 %13 / 1375.8 %50 / 66
end_session.c +
95.0%95.0%
+
95.0 %716 / 754100.0 %17 / 1770.2 %59 / 84
finish.c +
90.3%90.3%
+
90.3 %1505 / 1666100.0 %28 / 2877.1 %64 / 83
get_capabilities.c +
45.9%45.9%
+
45.9 %297 / 647100.0 %12 / 1225.3 %21 / 83
get_certificate.c +
93.8%93.8%
+
93.8 %1912 / 2038100.0 %34 / 3477.4 %247 / 319
get_csr.c +
94.9%94.9%
+
94.9 %241 / 254100.0 %13 / 1370.0 %14 / 20
get_digests.c +
62.9%62.9%
+
62.9 %567 / 901100.0 %32 / 3228.0 %28 / 100
get_event_types.c +
97.4%97.4%
+
97.4 %74 / 76100.0 %5 / 550.0 %3 / 6
get_key_pair_info.c +
21.7%21.7%
+
21.7 %62 / 28680.0 %4 / 540.0 %2 / 5
get_measurement_extension_log.c +
96.1%96.1%
+
96.1 %489 / 509100.0 %14 / 1480.9 %38 / 47
get_measurements.c +
95.3%95.3%
+
95.3 %2586 / 2713100.0 %45 / 4584.1 %132 / 157
get_version.c +
47.8%47.8%
+
47.8 %162 / 339100.0 %8 / 826.0 %13 / 50
heartbeat.c +
95.2%95.2%
+
95.2 %760 / 798100.0 %18 / 1870.2 %59 / 84
key_exchange.c +
97.2%97.2%
+
97.2 %3520 / 3622100.0 %38 / 3878.7 %118 / 150
key_update.c +
90.3%90.3%
+
90.3 %1861 / 2061100.0 %41 / 4165.6 %244 / 372
negotiate_algorithms.c +
50.3%50.3%
+
50.3 %633 / 1258100.0 %39 / 3923.7 %18 / 76
psk_exchange.c +
92.7%92.7%
+
92.7 %2086 / 225196.8 %30 / 3176.7 %92 / 120
psk_finish.c +
91.9%91.9%
+
91.9 %955 / 1039100.0 %22 / 2264.4 %67 / 104
set_certificate.c +
84.8%84.8%
+
84.8 %218 / 257100.0 %11 / 1154.2 %13 / 24
set_key_pair_info.c +
95.8%95.8%
+
95.8 %91 / 95100.0 %6 / 666.7 %4 / 6
subscribe_event_types.c +
100.0%
+
100.0 %101 / 101100.0 %7 / 766.7 %4 / 6
test_spdm_requester.c +
51.8%51.8%
+
51.8 %43 / 83100.0 %1 / 150.0 %40 / 80
vendor_request.c +
73.7%73.7%
+
73.7 %70 / 9566.7 %4 / 611.1 %2 / 18
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/key_exchange.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_requester/key_exchange.c.func-sort-c.html new file mode 100644 index 00000000000..20219a54f20 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/key_exchange.c.func-sort-c.html @@ -0,0 +1,233 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/key_exchange.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - key_exchange.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:3520362297.2 %
Date:2024-09-22 08:21:07Functions:3838100.0 %
Branches:11815078.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_key_exchange_test_main1
libspdm_test_requester_key_exchange_case11
libspdm_test_requester_key_exchange_case101
libspdm_test_requester_key_exchange_case111
libspdm_test_requester_key_exchange_case121
libspdm_test_requester_key_exchange_case131
libspdm_test_requester_key_exchange_case141
libspdm_test_requester_key_exchange_case151
libspdm_test_requester_key_exchange_case161
libspdm_test_requester_key_exchange_case171
libspdm_test_requester_key_exchange_case181
libspdm_test_requester_key_exchange_case191
libspdm_test_requester_key_exchange_case21
libspdm_test_requester_key_exchange_case201
libspdm_test_requester_key_exchange_case211
libspdm_test_requester_key_exchange_case221
libspdm_test_requester_key_exchange_case231
libspdm_test_requester_key_exchange_case241
libspdm_test_requester_key_exchange_case251
libspdm_test_requester_key_exchange_case261
libspdm_test_requester_key_exchange_case271
libspdm_test_requester_key_exchange_case281
libspdm_test_requester_key_exchange_case291
libspdm_test_requester_key_exchange_case31
libspdm_test_requester_key_exchange_case301
libspdm_test_requester_key_exchange_case311
libspdm_test_requester_key_exchange_case321
libspdm_test_requester_key_exchange_case331
libspdm_test_requester_key_exchange_case341
libspdm_test_requester_key_exchange_case41
libspdm_test_requester_key_exchange_case51
libspdm_test_requester_key_exchange_case61
libspdm_test_requester_key_exchange_case71
libspdm_test_requester_key_exchange_case81
libspdm_test_requester_key_exchange_case91
libspdm_test_get_key_exchange_request_size51
libspdm_requester_key_exchange_test_receive_message52
libspdm_requester_key_exchange_test_send_message53
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/key_exchange.c.func.html b/coverage_log/unit_test/test_spdm_requester/key_exchange.c.func.html new file mode 100644 index 00000000000..c9de73332da --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/key_exchange.c.func.html @@ -0,0 +1,233 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/key_exchange.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - key_exchange.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:3520362297.2 %
Date:2024-09-22 08:21:07Functions:3838100.0 %
Branches:11815078.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_key_exchange_test_main1
libspdm_requester_key_exchange_test_receive_message52
libspdm_requester_key_exchange_test_send_message53
libspdm_test_get_key_exchange_request_size51
libspdm_test_requester_key_exchange_case11
libspdm_test_requester_key_exchange_case101
libspdm_test_requester_key_exchange_case111
libspdm_test_requester_key_exchange_case121
libspdm_test_requester_key_exchange_case131
libspdm_test_requester_key_exchange_case141
libspdm_test_requester_key_exchange_case151
libspdm_test_requester_key_exchange_case161
libspdm_test_requester_key_exchange_case171
libspdm_test_requester_key_exchange_case181
libspdm_test_requester_key_exchange_case191
libspdm_test_requester_key_exchange_case21
libspdm_test_requester_key_exchange_case201
libspdm_test_requester_key_exchange_case211
libspdm_test_requester_key_exchange_case221
libspdm_test_requester_key_exchange_case231
libspdm_test_requester_key_exchange_case241
libspdm_test_requester_key_exchange_case251
libspdm_test_requester_key_exchange_case261
libspdm_test_requester_key_exchange_case271
libspdm_test_requester_key_exchange_case281
libspdm_test_requester_key_exchange_case291
libspdm_test_requester_key_exchange_case31
libspdm_test_requester_key_exchange_case301
libspdm_test_requester_key_exchange_case311
libspdm_test_requester_key_exchange_case321
libspdm_test_requester_key_exchange_case331
libspdm_test_requester_key_exchange_case341
libspdm_test_requester_key_exchange_case41
libspdm_test_requester_key_exchange_case51
libspdm_test_requester_key_exchange_case61
libspdm_test_requester_key_exchange_case71
libspdm_test_requester_key_exchange_case81
libspdm_test_requester_key_exchange_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/key_exchange.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/key_exchange.c.gcov.html new file mode 100644 index 00000000000..9fb6ddec991 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/key_exchange.c.gcov.html @@ -0,0 +1,8327 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/key_exchange.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - key_exchange.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:3520362297.2 %
Date:2024-09-22 08:21:07Functions:3838100.0 %
Branches:11815078.7 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_requester_lib.h"
+       9                 :            : #include "internal/libspdm_responder_lib.h"
+      10                 :            : 
+      11                 :            : #if LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP
+      12                 :            : 
+      13                 :            : static size_t m_libspdm_local_buffer_size;
+      14                 :            : static uint8_t m_libspdm_local_buffer[LIBSPDM_MAX_MESSAGE_TH_BUFFER_SIZE];
+      15                 :            : static uint8_t m_libspdm_zero_filled_buffer[LIBSPDM_MAX_HASH_SIZE];
+      16                 :            : 
+      17                 :            : static libspdm_th_managed_buffer_t th_curr;
+      18                 :            : 
+      19                 :         51 : static size_t libspdm_test_get_key_exchange_request_size(const void *spdm_context,
+      20                 :            :                                                          const void *buffer,
+      21                 :            :                                                          size_t buffer_size)
+      22                 :            : {
+      23                 :            :     const spdm_key_exchange_request_t *spdm_request;
+      24                 :            :     size_t message_size;
+      25                 :            :     size_t dhe_key_size;
+      26                 :            :     uint16_t opaque_length;
+      27                 :            : 
+      28                 :         51 :     spdm_request = buffer;
+      29                 :         51 :     message_size = sizeof(spdm_message_header_t);
+      30         [ -  + ]:         51 :     if (buffer_size < message_size) {
+      31                 :          0 :         return buffer_size;
+      32                 :            :     }
+      33                 :            : 
+      34         [ +  + ]:         51 :     if (spdm_request->header.request_response_code != SPDM_KEY_EXCHANGE) {
+      35                 :          1 :         return buffer_size;
+      36                 :            :     }
+      37                 :            : 
+      38                 :         50 :     message_size = sizeof(spdm_key_exchange_request_t);
+      39         [ -  + ]:         50 :     if (buffer_size < message_size) {
+      40                 :          0 :         return buffer_size;
+      41                 :            :     }
+      42                 :            : 
+      43                 :         50 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+      44                 :         50 :     message_size += dhe_key_size + sizeof(uint16_t);
+      45         [ -  + ]:         50 :     if (buffer_size < message_size) {
+      46                 :          0 :         return buffer_size;
+      47                 :            :     }
+      48                 :            : 
+      49                 :         50 :     opaque_length =
+      50                 :         50 :         *(uint16_t *)((size_t)buffer +
+      51                 :         50 :                       sizeof(spdm_key_exchange_request_t) + dhe_key_size);
+      52                 :         50 :     message_size += opaque_length;
+      53         [ -  + ]:         50 :     if (buffer_size < message_size) {
+      54                 :          0 :         return buffer_size;
+      55                 :            :     }
+      56                 :            : 
+      57                 :            :     /* Good message, return actual size*/
+      58                 :         50 :     return message_size;
+      59                 :            : }
+      60                 :            : 
+      61                 :         53 : static libspdm_return_t libspdm_requester_key_exchange_test_send_message(
+      62                 :            :     void *spdm_context, size_t request_size, const void *request,
+      63                 :            :     uint64_t timeout)
+      64                 :            : {
+      65                 :            :     libspdm_test_context_t *spdm_test_context;
+      66                 :            :     size_t header_size;
+      67                 :            :     size_t message_size;
+      68                 :            : 
+      69                 :         53 :     spdm_test_context = libspdm_get_test_context();
+      70                 :         53 :     header_size = sizeof(libspdm_test_message_header_t);
+      71   [ +  +  -  +  :         53 :     switch (spdm_test_context->case_id) {
+          +  +  +  +  +  
+          +  +  +  +  +  
+          +  +  +  +  +  
+          +  +  +  +  +  
+          +  +  +  +  +  
+          +  +  +  +  +  
+                      - ]
+      72                 :          1 :     case 0x1:
+      73                 :          1 :         return LIBSPDM_STATUS_SEND_FAIL;
+      74                 :          1 :     case 0x2:
+      75                 :          1 :         m_libspdm_local_buffer_size = 0;
+      76                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+      77                 :            :             spdm_context, (const uint8_t *)request + header_size,
+      78                 :            :             request_size - header_size);
+      79                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+      80                 :            :                          (const uint8_t *)request + header_size, message_size);
+      81                 :          1 :         m_libspdm_local_buffer_size += message_size;
+      82                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      83                 :          0 :     case 0x3:
+      84                 :          0 :         m_libspdm_local_buffer_size = 0;
+      85                 :          0 :         message_size = libspdm_test_get_key_exchange_request_size(
+      86                 :            :             spdm_context, (const uint8_t *)request + header_size,
+      87                 :            :             request_size - header_size);
+      88                 :          0 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+      89                 :            :                          (const uint8_t *)request + header_size, message_size);
+      90                 :          0 :         m_libspdm_local_buffer_size += message_size;
+      91                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      92                 :          1 :     case 0x4:
+      93                 :          1 :         m_libspdm_local_buffer_size = 0;
+      94                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+      95                 :            :             spdm_context, (const uint8_t *)request + header_size,
+      96                 :            :             request_size - header_size);
+      97                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+      98                 :            :                          (const uint8_t *)request + header_size, message_size);
+      99                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     100                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     101                 :          1 :     case 0x5:
+     102                 :          1 :         m_libspdm_local_buffer_size = 0;
+     103                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     104                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     105                 :            :             request_size - header_size);
+     106                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     107                 :            :                          (const uint8_t *)request + header_size, message_size);
+     108                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     109                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     110                 :          2 :     case 0x6:
+     111                 :          2 :         m_libspdm_local_buffer_size = 0;
+     112                 :          2 :         message_size = libspdm_test_get_key_exchange_request_size(
+     113                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     114                 :            :             request_size - header_size);
+     115                 :          2 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     116                 :            :                          (const uint8_t *)request + header_size, message_size);
+     117                 :          2 :         m_libspdm_local_buffer_size += message_size;
+     118                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     119                 :          1 :     case 0x7:
+     120                 :          1 :         m_libspdm_local_buffer_size = 0;
+     121                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     122                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     123                 :            :             request_size - header_size);
+     124                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     125                 :            :                          (const uint8_t *)request + header_size, message_size);
+     126                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     127                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     128                 :          2 :     case 0x8:
+     129                 :          2 :         m_libspdm_local_buffer_size = 0;
+     130                 :          2 :         message_size = libspdm_test_get_key_exchange_request_size(
+     131                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     132                 :            :             request_size - header_size);
+     133                 :          2 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     134                 :            :                          (const uint8_t *)request + header_size, message_size);
+     135                 :          2 :         m_libspdm_local_buffer_size += message_size;
+     136                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     137                 :          2 :     case 0x9: {
+     138                 :            :         static size_t sub_index = 0;
+     139         [ +  + ]:          2 :         if (sub_index == 0) {
+     140                 :          1 :             m_libspdm_local_buffer_size = 0;
+     141                 :          1 :             message_size = libspdm_test_get_key_exchange_request_size(
+     142                 :            :                 spdm_context, (const uint8_t *)request + header_size,
+     143                 :            :                 request_size - header_size);
+     144                 :          1 :             libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     145                 :            :                              (const uint8_t *)request + header_size, message_size);
+     146                 :          1 :             m_libspdm_local_buffer_size += message_size;
+     147                 :          1 :             sub_index++;
+     148                 :            :         }
+     149                 :            :     }
+     150                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     151                 :         18 :     case 0xA:
+     152                 :         18 :         m_libspdm_local_buffer_size = 0;
+     153                 :         18 :         message_size = libspdm_test_get_key_exchange_request_size(
+     154                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     155                 :            :             request_size - header_size);
+     156                 :         18 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     157                 :            :                          (const uint8_t *)request + header_size, message_size);
+     158                 :         18 :         m_libspdm_local_buffer_size += message_size;
+     159                 :         18 :         return LIBSPDM_STATUS_SUCCESS;
+     160                 :          1 :     case 0xB:
+     161                 :          1 :         m_libspdm_local_buffer_size = 0;
+     162                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     163                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     164                 :            :             request_size - header_size);
+     165                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     166                 :            :                          (const uint8_t *)request + header_size, message_size);
+     167                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     168                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     169                 :          1 :     case 0xC:
+     170                 :          1 :         m_libspdm_local_buffer_size = 0;
+     171                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     172                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     173                 :            :             request_size - header_size);
+     174                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     175                 :            :                          (const uint8_t *)request + header_size, message_size);
+     176                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     177                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     178                 :          1 :     case 0xD:
+     179                 :          1 :         m_libspdm_local_buffer_size = 0;
+     180                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     181                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     182                 :            :             request_size - header_size);
+     183                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     184                 :            :                          (const uint8_t *)request + header_size, message_size);
+     185                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     186                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     187                 :          1 :     case 0xE:
+     188                 :          1 :         m_libspdm_local_buffer_size = 0;
+     189                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     190                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     191                 :            :             request_size - header_size);
+     192                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     193                 :            :                          (const uint8_t *)request + header_size, message_size);
+     194                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     195                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     196                 :          1 :     case 0xF:
+     197                 :          1 :         m_libspdm_local_buffer_size = 0;
+     198                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     199                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     200                 :            :             request_size - header_size);
+     201                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     202                 :            :                          (const uint8_t *)request + header_size, message_size);
+     203                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     204                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     205                 :          1 :     case 0x10:
+     206                 :          1 :         m_libspdm_local_buffer_size = 0;
+     207                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     208                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     209                 :            :             request_size - header_size);
+     210                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     211                 :            :                          (const uint8_t *)request + header_size, message_size);
+     212                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     213                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     214                 :          1 :     case 0x11:
+     215                 :          1 :         m_libspdm_local_buffer_size = 0;
+     216                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     217                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     218                 :            :             request_size - header_size);
+     219                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     220                 :            :                          (const uint8_t *)request + header_size, message_size);
+     221                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     222                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     223                 :          1 :     case 0x12:
+     224                 :          1 :         m_libspdm_local_buffer_size = 0;
+     225                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     226                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     227                 :            :             request_size - header_size);
+     228                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     229                 :            :                          (const uint8_t *)request + header_size, message_size);
+     230                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     231                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     232                 :          1 :     case 0x13:
+     233                 :          1 :         m_libspdm_local_buffer_size = 0;
+     234                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     235                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     236                 :            :             request_size - header_size);
+     237                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     238                 :            :                          (const uint8_t *)request + header_size, message_size);
+     239                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     240                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     241                 :          1 :     case 0x14:
+     242                 :          1 :         m_libspdm_local_buffer_size = 0;
+     243                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     244                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     245                 :            :             request_size - header_size);
+     246                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     247                 :            :                          (const uint8_t *)request + header_size, message_size);
+     248                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     249                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     250                 :          1 :     case 0x15:
+     251                 :          1 :         m_libspdm_local_buffer_size = 0;
+     252                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     253                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     254                 :            :             request_size - header_size);
+     255                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     256                 :            :                          (const uint8_t *)request + header_size, message_size);
+     257                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     258                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     259                 :          1 :     case 0x16:
+     260                 :          1 :         m_libspdm_local_buffer_size = 0;
+     261                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     262                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     263                 :            :             request_size - header_size);
+     264                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     265                 :            :                          (const uint8_t *)request + header_size, message_size);
+     266                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     267                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     268                 :          1 :     case 0x17:
+     269                 :          1 :         m_libspdm_local_buffer_size = 0;
+     270                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     271                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     272                 :            :             request_size - header_size);
+     273                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     274                 :            :                          (const uint8_t *)request + header_size, message_size);
+     275                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     276                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     277                 :          1 :     case 0x18:
+     278                 :          1 :         m_libspdm_local_buffer_size = 0;
+     279                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     280                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     281                 :            :             request_size - header_size);
+     282                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     283                 :            :                          (const uint8_t *)request + header_size, message_size);
+     284                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     285                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     286                 :          1 :     case 0x19:
+     287                 :          1 :         m_libspdm_local_buffer_size = 0;
+     288                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     289                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     290                 :            :             request_size - header_size);
+     291                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     292                 :            :                          (const uint8_t *)request + header_size, message_size);
+     293                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     294                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     295                 :          1 :     case 0x1A:
+     296                 :          1 :         m_libspdm_local_buffer_size = 0;
+     297                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     298                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     299                 :            :             request_size - header_size);
+     300                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     301                 :            :                          (const uint8_t *)request + header_size, message_size);
+     302                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     303                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     304                 :          1 :     case 0x1B:
+     305                 :          1 :         m_libspdm_local_buffer_size = 0;
+     306                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     307                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     308                 :            :             request_size - header_size);
+     309                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     310                 :            :                          (const uint8_t *)request + header_size, message_size);
+     311                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     312                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     313                 :          1 :     case 0x1C:
+     314                 :          1 :         m_libspdm_local_buffer_size = 0;
+     315                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     316                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     317                 :            :             request_size - header_size);
+     318                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     319                 :            :                          (const uint8_t *)request + header_size, message_size);
+     320                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     321                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     322                 :          1 :     case 0x1D:
+     323                 :          1 :         m_libspdm_local_buffer_size = 0;
+     324                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     325                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     326                 :            :             request_size - header_size);
+     327                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     328                 :            :                          (const uint8_t *)request + header_size,  message_size);
+     329                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     330                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     331                 :          1 :     case 0x1E:
+     332                 :          1 :         m_libspdm_local_buffer_size = 0;
+     333                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     334                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     335                 :            :             request_size - header_size);
+     336                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     337                 :            :                          (const uint8_t *)request + header_size, message_size);
+     338                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     339                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     340                 :          1 :     case 0x1F:
+     341                 :          1 :         m_libspdm_local_buffer_size = 0;
+     342                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     343                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     344                 :            :             request_size - header_size);
+     345                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     346                 :            :                          (const uint8_t *)request + header_size, message_size);
+     347                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     348                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     349                 :          1 :     case 0x20:
+     350                 :          1 :         m_libspdm_local_buffer_size = 0;
+     351                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     352                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     353                 :            :             request_size - header_size);
+     354                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     355                 :            :                          (const uint8_t *)request + header_size, message_size);
+     356                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     357                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     358                 :          1 :     case 0x21:
+     359                 :          1 :         m_libspdm_local_buffer_size = 0;
+     360                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     361                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     362                 :            :             request_size - header_size);
+     363                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     364                 :            :                          (const uint8_t *)request + header_size, message_size);
+     365                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     366                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     367                 :          1 :     case 0x22:
+     368                 :          1 :         m_libspdm_local_buffer_size = 0;
+     369                 :          1 :         message_size = libspdm_test_get_key_exchange_request_size(
+     370                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     371                 :            :             request_size - header_size);
+     372                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     373                 :            :                          (const uint8_t *)request + header_size, message_size);
+     374                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     375                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     376                 :          0 :     default:
+     377                 :          0 :         return LIBSPDM_STATUS_SEND_FAIL;
+     378                 :            :     }
+     379                 :            : }
+     380                 :            : 
+     381                 :         52 : static libspdm_return_t libspdm_requester_key_exchange_test_receive_message(
+     382                 :            :     void *spdm_context, size_t *response_size,
+     383                 :            :     void **response, uint64_t timeout)
+     384                 :            : {
+     385                 :            :     libspdm_test_context_t *spdm_test_context;
+     386                 :            : 
+     387                 :         52 :     spdm_test_context = libspdm_get_test_context();
+     388   [ -  +  -  +  :         52 :     switch (spdm_test_context->case_id) {
+          +  +  +  +  +  
+          +  +  +  +  +  
+          +  +  +  +  +  
+          +  +  +  +  +  
+          +  +  +  +  +  
+          +  +  +  +  +  
+                      - ]
+     389                 :          0 :     case 0x1:
+     390                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+     391                 :            : 
+     392                 :          1 :     case 0x2: {
+     393                 :            :         spdm_key_exchange_response_t *spdm_response;
+     394                 :            :         size_t dhe_key_size;
+     395                 :            :         uint32_t hash_size;
+     396                 :            :         size_t signature_size;
+     397                 :            :         uint32_t hmac_size;
+     398                 :            :         uint8_t *ptr;
+     399                 :            :         void *dhe_context;
+     400                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+     401                 :            :         size_t final_key_size;
+     402                 :            :         size_t opaque_key_exchange_rsp_size;
+     403                 :            :         void *data;
+     404                 :            :         size_t data_size;
+     405                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     406                 :            :         uint8_t *cert_buffer;
+     407                 :            :         size_t cert_buffer_size;
+     408                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+     409                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+     410                 :            :         uint8_t bin_str0[128];
+     411                 :            :         size_t bin_str0_size;
+     412                 :            :         uint8_t bin_str2[128];
+     413                 :            :         size_t bin_str2_size;
+     414                 :            :         uint8_t bin_str7[128];
+     415                 :            :         size_t bin_str7_size;
+     416                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+     417                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+     418                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+     419                 :            :         size_t spdm_response_size;
+     420                 :            :         size_t transport_header_size;
+     421                 :            : 
+     422                 :          1 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
+     423                 :            :             SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     424                 :            :         ((libspdm_context_t *)spdm_context)
+     425                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+     426                 :            :             m_libspdm_use_asym_algo;
+     427                 :            :         ((libspdm_context_t *)spdm_context)
+     428                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+     429                 :            :             m_libspdm_use_hash_algo;
+     430                 :            :         ((libspdm_context_t *)spdm_context)
+     431                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+     432                 :            :             m_libspdm_use_dhe_algo;
+     433                 :            :         ((libspdm_context_t *)spdm_context)
+     434                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+     435                 :            :             m_libspdm_use_measurement_hash_algo;
+     436                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+     437                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     438                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     439                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+     440                 :          1 :         opaque_key_exchange_rsp_size =
+     441                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+     442                 :            :                 spdm_context);
+     443                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+     444                 :          1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
+     445                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+     446                 :            :                              hmac_size;
+     447                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     448                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     449                 :            : 
+     450                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     451                 :          1 :         spdm_response->header.request_response_code =
+     452                 :            :             SPDM_KEY_EXCHANGE_RSP;
+     453                 :          1 :         spdm_response->header.param1 = 0;
+     454                 :          1 :         spdm_response->rsp_session_id =
+     455                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
+     456                 :          1 :         spdm_response->mut_auth_requested = 0;
+     457                 :          1 :         spdm_response->req_slot_id_param = 0;
+     458                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+     459                 :          1 :                                   spdm_response->random_data);
+     460                 :          1 :         ptr = (void *)(spdm_response + 1);
+     461                 :          1 :         dhe_context = libspdm_dhe_new(
+     462                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     463                 :            :                 m_libspdm_use_dhe_algo,
+     464                 :            :                 true);
+     465                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+     466                 :            :                                  &dhe_key_size);
+     467                 :          1 :         final_key_size = sizeof(final_key);
+     468                 :          1 :         libspdm_dhe_compute_key(
+     469                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+     470                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+     471                 :            :             sizeof(spdm_key_exchange_request_t),
+     472                 :            :             dhe_key_size, final_key, &final_key_size);
+     473                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+     474                 :          1 :         ptr += dhe_key_size;
+     475                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+     476                 :            :          * ptr += hash_size;*/
+     477                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+     478                 :          1 :         ptr += sizeof(uint16_t);
+     479                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+     480                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+     481                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+     482                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     483                 :            :                                                         m_libspdm_use_asym_algo, &data,
+     484                 :            :                                                         &data_size, NULL, NULL);
+     485                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+     486                 :            :                          sizeof(m_libspdm_local_buffer)
+     487                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+     488                 :            :                             m_libspdm_local_buffer),
+     489                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+     490                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+     491                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+     492                 :            :                        m_libspdm_local_buffer_size));
+     493                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+     494                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+     495                 :          1 :         cert_buffer = (uint8_t *)data;
+     496                 :          1 :         cert_buffer_size = data_size;
+     497                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+     498                 :            :                          cert_buffer_hash);
+     499                 :            :         /* transcript.message_a size is 0*/
+     500                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+     501                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+     502                 :            :                                       m_libspdm_local_buffer_size);
+     503                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+     504                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+     505                 :          1 :         free(data);
+     506                 :          1 :         libspdm_responder_data_sign(
+     507                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+     508                 :            :             spdm_context,
+     509                 :            : #endif
+     510                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     511                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+     512                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+     513                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+     514                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+     515                 :            :                 &signature_size);
+     516                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+     517                 :            :                          sizeof(m_libspdm_local_buffer)
+     518                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+     519                 :            :                             m_libspdm_local_buffer),
+     520                 :            :                          ptr, signature_size);
+     521                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+     522                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+     523                 :          1 :         ptr += signature_size;
+     524                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+     525                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+     526                 :            :                          th_curr_hash_data);
+     527                 :          1 :         bin_str0_size = sizeof(bin_str0);
+     528                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+     529                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+     530                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+     531                 :            :                            &bin_str0_size);
+     532                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+     533                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+     534                 :          1 :         bin_str2_size = sizeof(bin_str2);
+     535                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+     536                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+     537                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+     538                 :            :                            bin_str2, &bin_str2_size);
+     539                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+     540                 :            :                             bin_str2, bin_str2_size,
+     541                 :            :                             response_handshake_secret, hash_size);
+     542                 :          1 :         bin_str7_size = sizeof(bin_str7);
+     543                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+     544                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+     545                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+     546                 :            :                            &bin_str7_size);
+     547                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+     548                 :            :                             hash_size, bin_str7, bin_str7_size,
+     549                 :            :                             response_finished_key, hash_size);
+     550                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+     551                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+     552                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+     553                 :            :                          response_finished_key, hash_size, ptr);
+     554                 :          1 :         ptr += hmac_size;
+     555                 :            : 
+     556                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     557                 :            :                                               false, spdm_response_size,
+     558                 :            :                                               spdm_response, response_size,
+     559                 :            :                                               response);
+     560                 :            :     }
+     561                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     562                 :            : 
+     563                 :          0 :     case 0x3: {
+     564                 :            :         spdm_key_exchange_response_t *spdm_response;
+     565                 :            :         size_t dhe_key_size;
+     566                 :            :         uint32_t hash_size;
+     567                 :            :         size_t signature_size;
+     568                 :            :         uint32_t hmac_size;
+     569                 :            :         uint8_t *ptr;
+     570                 :            :         void *dhe_context;
+     571                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+     572                 :            :         size_t final_key_size;
+     573                 :            :         size_t opaque_key_exchange_rsp_size;
+     574                 :            :         void *data;
+     575                 :            :         size_t data_size;
+     576                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     577                 :            :         uint8_t *cert_buffer;
+     578                 :            :         size_t cert_buffer_size;
+     579                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+     580                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+     581                 :            :         uint8_t bin_str0[128];
+     582                 :            :         size_t bin_str0_size;
+     583                 :            :         uint8_t bin_str2[128];
+     584                 :            :         size_t bin_str2_size;
+     585                 :            :         uint8_t bin_str7[128];
+     586                 :            :         size_t bin_str7_size;
+     587                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+     588                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+     589                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+     590                 :            :         size_t spdm_response_size;
+     591                 :            :         size_t transport_header_size;
+     592                 :            : 
+     593                 :            :         ((libspdm_context_t *)spdm_context)
+     594                 :          0 :         ->connection_info.algorithm.base_asym_algo =
+     595                 :            :             m_libspdm_use_asym_algo;
+     596                 :            :         ((libspdm_context_t *)spdm_context)
+     597                 :          0 :         ->connection_info.algorithm.base_hash_algo =
+     598                 :            :             m_libspdm_use_hash_algo;
+     599                 :            :         ((libspdm_context_t *)spdm_context)
+     600                 :          0 :         ->connection_info.algorithm.dhe_named_group =
+     601                 :            :             m_libspdm_use_dhe_algo;
+     602                 :            :         ((libspdm_context_t *)spdm_context)
+     603                 :          0 :         ->connection_info.algorithm.measurement_hash_algo =
+     604                 :            :             m_libspdm_use_measurement_hash_algo;
+     605                 :          0 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+     606                 :          0 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     607                 :          0 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     608                 :          0 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+     609                 :          0 :         opaque_key_exchange_rsp_size =
+     610                 :          0 :             libspdm_get_opaque_data_version_selection_data_size(
+     611                 :            :                 spdm_context);
+     612                 :          0 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+     613                 :          0 :                              dhe_key_size + 0 + sizeof(uint16_t) +
+     614                 :          0 :                              opaque_key_exchange_rsp_size + signature_size +
+     615                 :            :                              hmac_size;
+     616                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     617                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     618                 :            : 
+     619                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     620                 :          0 :         spdm_response->header.request_response_code =
+     621                 :            :             SPDM_KEY_EXCHANGE_RSP;
+     622                 :          0 :         spdm_response->header.param1 = 0;
+     623                 :          0 :         spdm_response->rsp_session_id =
+     624                 :          0 :             libspdm_allocate_rsp_session_id(spdm_context, false);
+     625                 :          0 :         spdm_response->mut_auth_requested = 0;
+     626                 :          0 :         spdm_response->req_slot_id_param = 0;
+     627                 :          0 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+     628                 :          0 :                                   spdm_response->random_data);
+     629                 :          0 :         ptr = (void *)(spdm_response + 1);
+     630                 :          0 :         dhe_context = libspdm_dhe_new(
+     631                 :          0 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     632                 :            :                 m_libspdm_use_dhe_algo,
+     633                 :            :                 true);
+     634                 :          0 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+     635                 :            :                                  &dhe_key_size);
+     636                 :          0 :         final_key_size = sizeof(final_key);
+     637                 :          0 :         libspdm_dhe_compute_key(
+     638                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+     639                 :          0 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+     640                 :            :             sizeof(spdm_key_exchange_request_t),
+     641                 :            :             dhe_key_size, final_key, &final_key_size);
+     642                 :          0 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+     643                 :          0 :         ptr += dhe_key_size;
+     644                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+     645                 :            :          * ptr += hash_size;*/
+     646                 :          0 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+     647                 :          0 :         ptr += sizeof(uint16_t);
+     648                 :          0 :         libspdm_build_opaque_data_version_selection_data(
+     649                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+     650                 :          0 :         ptr += opaque_key_exchange_rsp_size;
+     651                 :          0 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     652                 :            :                                                         m_libspdm_use_asym_algo, &data,
+     653                 :            :                                                         &data_size, NULL, NULL);
+     654                 :          0 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+     655                 :            :                          sizeof(m_libspdm_local_buffer)
+     656                 :          0 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+     657                 :            :                             m_libspdm_local_buffer),
+     658                 :          0 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+     659                 :          0 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+     660                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+     661                 :            :                        m_libspdm_local_buffer_size));
+     662                 :          0 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+     663                 :          0 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+     664                 :          0 :         cert_buffer = (uint8_t *)data;
+     665                 :          0 :         cert_buffer_size = data_size;
+     666                 :          0 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+     667                 :            :                          cert_buffer_hash);
+     668                 :            :         /* transcript.message_a size is 0*/
+     669                 :          0 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+     670                 :          0 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+     671                 :            :                                       m_libspdm_local_buffer_size);
+     672                 :          0 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+     673                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+     674                 :          0 :         free(data);
+     675                 :          0 :         libspdm_responder_data_sign(
+     676                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+     677                 :            :             spdm_context,
+     678                 :            : #endif
+     679                 :          0 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     680                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+     681                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+     682                 :          0 :                 false, libspdm_get_managed_buffer(&th_curr),
+     683                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+     684                 :            :                 &signature_size);
+     685                 :          0 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+     686                 :            :                          sizeof(m_libspdm_local_buffer)
+     687                 :          0 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+     688                 :            :                             m_libspdm_local_buffer),
+     689                 :            :                          ptr, signature_size);
+     690                 :          0 :         m_libspdm_local_buffer_size += signature_size;
+     691                 :          0 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+     692                 :          0 :         ptr += signature_size;
+     693                 :          0 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+     694                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+     695                 :            :                          th_curr_hash_data);
+     696                 :          0 :         bin_str0_size = sizeof(bin_str0);
+     697                 :          0 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+     698                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+     699                 :          0 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+     700                 :            :                            &bin_str0_size);
+     701                 :          0 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+     702                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+     703                 :          0 :         bin_str2_size = sizeof(bin_str2);
+     704                 :          0 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+     705                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+     706                 :          0 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+     707                 :            :                            bin_str2, &bin_str2_size);
+     708                 :          0 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+     709                 :            :                             bin_str2, bin_str2_size,
+     710                 :            :                             response_handshake_secret, hash_size);
+     711                 :          0 :         bin_str7_size = sizeof(bin_str7);
+     712                 :          0 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+     713                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+     714                 :          0 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+     715                 :            :                            &bin_str7_size);
+     716                 :          0 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+     717                 :            :                             hash_size, bin_str7, bin_str7_size,
+     718                 :            :                             response_finished_key, hash_size);
+     719                 :          0 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+     720                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+     721                 :          0 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+     722                 :            :                          response_finished_key, hash_size, ptr);
+     723                 :          0 :         ptr += hmac_size;
+     724                 :            : 
+     725                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     726                 :            :                                               false, spdm_response_size,
+     727                 :            :                                               spdm_response, response_size,
+     728                 :            :                                               response);
+     729                 :            :     }
+     730                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     731                 :            : 
+     732                 :          1 :     case 0x4: {
+     733                 :            :         spdm_error_response_t *spdm_response;
+     734                 :            :         size_t spdm_response_size;
+     735                 :            :         size_t transport_header_size;
+     736                 :            : 
+     737                 :          1 :         spdm_response_size = sizeof(spdm_error_response_t);
+     738                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     739                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     740                 :            : 
+     741                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     742                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     743                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_INVALID_REQUEST;
+     744                 :          1 :         spdm_response->header.param2 = 0;
+     745                 :            : 
+     746                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     747                 :            :                                               false, spdm_response_size,
+     748                 :            :                                               spdm_response,
+     749                 :            :                                               response_size, response);
+     750                 :            :     }
+     751                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     752                 :            : 
+     753                 :          1 :     case 0x5: {
+     754                 :            :         spdm_error_response_t *spdm_response;
+     755                 :            :         size_t spdm_response_size;
+     756                 :            :         size_t transport_header_size;
+     757                 :            : 
+     758                 :          1 :         spdm_response_size = sizeof(spdm_error_response_t);
+     759                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     760                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     761                 :            : 
+     762                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     763                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     764                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
+     765                 :          1 :         spdm_response->header.param2 = 0;
+     766                 :            : 
+     767                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     768                 :            :                                               false, spdm_response_size,
+     769                 :            :                                               spdm_response,
+     770                 :            :                                               response_size, response);
+     771                 :            :     }
+     772                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     773                 :            : 
+     774                 :          2 :     case 0x6: {
+     775                 :            :         static size_t sub_index1 = 0;
+     776         [ +  + ]:          2 :         if (sub_index1 == 0) {
+     777                 :            :             spdm_error_response_t *spdm_response;
+     778                 :            :             size_t spdm_response_size;
+     779                 :            :             size_t transport_header_size;
+     780                 :            : 
+     781                 :          1 :             spdm_response_size = sizeof(spdm_error_response_t);
+     782                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     783                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     784                 :            : 
+     785                 :          1 :             spdm_response->header.spdm_version =
+     786                 :            :                 SPDM_MESSAGE_VERSION_11;
+     787                 :          1 :             spdm_response->header.request_response_code = SPDM_ERROR;
+     788                 :          1 :             spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
+     789                 :          1 :             spdm_response->header.param2 = 0;
+     790                 :            : 
+     791                 :          1 :             libspdm_transport_test_encode_message(
+     792                 :            :                 spdm_context, NULL, false, false,
+     793                 :            :                 spdm_response_size, spdm_response,
+     794                 :            :                 response_size, response);
+     795                 :          1 :             sub_index1++;
+     796         [ +  - ]:          1 :         } else if (sub_index1 == 1) {
+     797                 :            :             spdm_key_exchange_response_t *spdm_response;
+     798                 :            :             size_t dhe_key_size;
+     799                 :            :             uint32_t hash_size;
+     800                 :            :             size_t signature_size;
+     801                 :            :             uint32_t hmac_size;
+     802                 :            :             uint8_t *ptr;
+     803                 :            :             void *dhe_context;
+     804                 :            :             uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+     805                 :            :             size_t final_key_size;
+     806                 :            :             size_t opaque_key_exchange_rsp_size;
+     807                 :            :             void *data;
+     808                 :            :             size_t data_size;
+     809                 :            :             uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     810                 :            :             uint8_t *cert_buffer;
+     811                 :            :             size_t cert_buffer_size;
+     812                 :            :             uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+     813                 :            :             uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+     814                 :            :             uint8_t bin_str0[128];
+     815                 :            :             size_t bin_str0_size;
+     816                 :            :             uint8_t bin_str2[128];
+     817                 :            :             size_t bin_str2_size;
+     818                 :            :             uint8_t bin_str7[128];
+     819                 :            :             size_t bin_str7_size;
+     820                 :            :             uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+     821                 :            :             uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+     822                 :            :             uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+     823                 :            :             size_t spdm_response_size;
+     824                 :            :             size_t transport_header_size;
+     825                 :            : 
+     826                 :            :             ((libspdm_context_t *)spdm_context)
+     827                 :          1 :             ->connection_info.algorithm.base_asym_algo =
+     828                 :            :                 m_libspdm_use_asym_algo;
+     829                 :            :             ((libspdm_context_t *)spdm_context)
+     830                 :          1 :             ->connection_info.algorithm.base_hash_algo =
+     831                 :            :                 m_libspdm_use_hash_algo;
+     832                 :            :             ((libspdm_context_t *)spdm_context)
+     833                 :          1 :             ->connection_info.algorithm.dhe_named_group =
+     834                 :            :                 m_libspdm_use_dhe_algo;
+     835                 :            :             ((libspdm_context_t *)spdm_context)
+     836                 :            :             ->connection_info.algorithm
+     837                 :          1 :             .measurement_hash_algo =
+     838                 :            :                 m_libspdm_use_measurement_hash_algo;
+     839                 :          1 :             signature_size =
+     840                 :          1 :                 libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+     841                 :          1 :             hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     842                 :          1 :             hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     843                 :          1 :             dhe_key_size =
+     844                 :          1 :                 libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+     845                 :          1 :             opaque_key_exchange_rsp_size =
+     846                 :          1 :                 libspdm_get_opaque_data_version_selection_data_size(
+     847                 :            :                     spdm_context);
+     848                 :          1 :             spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+     849                 :          1 :                                  dhe_key_size + 0 + sizeof(uint16_t) +
+     850                 :          1 :                                  opaque_key_exchange_rsp_size +
+     851                 :          1 :                                  signature_size + hmac_size;
+     852                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     853                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     854                 :            : 
+     855                 :          1 :             spdm_response->header.spdm_version =
+     856                 :            :                 SPDM_MESSAGE_VERSION_11;
+     857                 :          1 :             spdm_response->header.request_response_code =
+     858                 :            :                 SPDM_KEY_EXCHANGE_RSP;
+     859                 :          1 :             spdm_response->header.param1 = 0;
+     860                 :          1 :             spdm_response->rsp_session_id =
+     861                 :          1 :                 libspdm_allocate_rsp_session_id(spdm_context, false);
+     862                 :          1 :             spdm_response->mut_auth_requested = 0;
+     863                 :          1 :             spdm_response->req_slot_id_param = 0;
+     864                 :          1 :             libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+     865                 :          1 :                                       spdm_response->random_data);
+     866                 :          1 :             ptr = (void *)(spdm_response + 1);
+     867                 :          1 :             dhe_context = libspdm_dhe_new(
+     868                 :          1 :                 spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     869                 :            :                     m_libspdm_use_dhe_algo, true);
+     870                 :          1 :             libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+     871                 :            :                                      &dhe_key_size);
+     872                 :          1 :             final_key_size = sizeof(final_key);
+     873                 :          1 :             libspdm_dhe_compute_key(
+     874                 :            :                 m_libspdm_use_dhe_algo, dhe_context,
+     875                 :          1 :                 (uint8_t *)&m_libspdm_local_buffer[0] +
+     876                 :            :                 sizeof(spdm_key_exchange_request_t),
+     877                 :            :                 dhe_key_size, final_key, &final_key_size);
+     878                 :          1 :             libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+     879                 :          1 :             ptr += dhe_key_size;
+     880                 :            :             /* libspdm_zero_mem (ptr, hash_size);
+     881                 :            :              * ptr += hash_size;*/
+     882                 :          1 :             *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+     883                 :          1 :             ptr += sizeof(uint16_t);
+     884                 :          1 :             libspdm_build_opaque_data_version_selection_data(
+     885                 :            :                 spdm_context, &opaque_key_exchange_rsp_size,
+     886                 :            :                 ptr);
+     887                 :          1 :             ptr += opaque_key_exchange_rsp_size;
+     888                 :          1 :             libspdm_read_responder_public_certificate_chain(
+     889                 :            :                 m_libspdm_use_hash_algo, m_libspdm_use_asym_algo, &data,
+     890                 :            :                 &data_size, NULL, NULL);
+     891                 :          1 :             libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+     892                 :            :                              sizeof(m_libspdm_local_buffer)
+     893                 :          1 :                              - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+     894                 :            :                                 m_libspdm_local_buffer),
+     895                 :          1 :                              spdm_response, (size_t)ptr - (size_t)spdm_response);
+     896                 :          1 :             m_libspdm_local_buffer_size +=
+     897                 :          1 :                 ((size_t)ptr - (size_t)spdm_response);
+     898                 :          1 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+     899                 :            :                            m_libspdm_local_buffer_size));
+     900                 :          1 :             libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+     901                 :          1 :             libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+     902                 :          1 :             cert_buffer = (uint8_t *)data;
+     903                 :          1 :             cert_buffer_size = data_size;
+     904                 :          1 :             libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer,
+     905                 :            :                              cert_buffer_size, cert_buffer_hash);
+     906                 :            :             /* transcript.message_a size is 0*/
+     907                 :          1 :             libspdm_append_managed_buffer(&th_curr, cert_buffer_hash,
+     908                 :            :                                           hash_size);
+     909                 :          1 :             libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+     910                 :            :                                           m_libspdm_local_buffer_size);
+     911                 :          2 :             libspdm_hash_all(m_libspdm_use_hash_algo,
+     912                 :          1 :                              libspdm_get_managed_buffer(&th_curr),
+     913                 :            :                              libspdm_get_managed_buffer_size(&th_curr),
+     914                 :            :                              hash_data);
+     915                 :          1 :             free(data);
+     916                 :          1 :             libspdm_responder_data_sign(
+     917                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+     918                 :            :                 spdm_context,
+     919                 :            : #endif
+     920                 :          1 :                 spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     921                 :            :                     SPDM_KEY_EXCHANGE_RSP,
+     922                 :            :                     m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+     923                 :          1 :                     false, libspdm_get_managed_buffer(&th_curr),
+     924                 :            :                     libspdm_get_managed_buffer_size(&th_curr), ptr,
+     925                 :            :                     &signature_size);
+     926                 :          1 :             libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+     927                 :            :                              sizeof(m_libspdm_local_buffer)
+     928                 :          1 :                              - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+     929                 :            :                                 m_libspdm_local_buffer),
+     930                 :            :                              ptr, signature_size);
+     931                 :          1 :             m_libspdm_local_buffer_size += signature_size;
+     932                 :          1 :             libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+     933                 :          1 :             ptr += signature_size;
+     934                 :          2 :             libspdm_hash_all(m_libspdm_use_hash_algo,
+     935                 :          1 :                              libspdm_get_managed_buffer(&th_curr),
+     936                 :            :                              libspdm_get_managed_buffer_size(&th_curr),
+     937                 :            :                              th_curr_hash_data);
+     938                 :          1 :             bin_str0_size = sizeof(bin_str0);
+     939                 :          1 :             libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+     940                 :            :                                SPDM_BIN_STR_0_LABEL,
+     941                 :            :                                sizeof(SPDM_BIN_STR_0_LABEL) - 1, NULL,
+     942                 :          1 :                                (uint16_t)hash_size, hash_size, bin_str0,
+     943                 :            :                                &bin_str0_size);
+     944                 :          1 :             libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+     945                 :            :                              m_libspdm_zero_filled_buffer, hash_size, handshake_secret);
+     946                 :          1 :             bin_str2_size = sizeof(bin_str2);
+     947                 :          1 :             libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+     948                 :            :                                SPDM_BIN_STR_2_LABEL,
+     949                 :            :                                sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+     950                 :          1 :                                th_curr_hash_data, (uint16_t)hash_size,
+     951                 :            :                                hash_size, bin_str2, &bin_str2_size);
+     952                 :          1 :             libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret,
+     953                 :            :                                 hash_size, bin_str2, bin_str2_size,
+     954                 :            :                                 response_handshake_secret, hash_size);
+     955                 :          1 :             bin_str7_size = sizeof(bin_str7);
+     956                 :          1 :             libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+     957                 :            :                                SPDM_BIN_STR_7_LABEL,
+     958                 :            :                                sizeof(SPDM_BIN_STR_7_LABEL) - 1, NULL,
+     959                 :          1 :                                (uint16_t)hash_size, hash_size, bin_str7,
+     960                 :            :                                &bin_str7_size);
+     961                 :          1 :             libspdm_hkdf_expand(m_libspdm_use_hash_algo,
+     962                 :            :                                 response_handshake_secret, hash_size,
+     963                 :            :                                 bin_str7, bin_str7_size,
+     964                 :            :                                 response_finished_key, hash_size);
+     965                 :          1 :             libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+     966                 :            :                              libspdm_get_managed_buffer_size(&th_curr), hash_data);
+     967                 :          1 :             libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+     968                 :            :                              response_finished_key, hash_size, ptr);
+     969                 :          1 :             ptr += hmac_size;
+     970                 :            : 
+     971                 :          1 :             libspdm_transport_test_encode_message(
+     972                 :            :                 spdm_context, NULL, false, false, spdm_response_size,
+     973                 :            :                 spdm_response, response_size, response);
+     974                 :            :         }
+     975                 :            :     }
+     976                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     977                 :            : 
+     978                 :          1 :     case 0x7: {
+     979                 :            :         spdm_error_response_t *spdm_response;
+     980                 :            :         size_t spdm_response_size;
+     981                 :            :         size_t transport_header_size;
+     982                 :            : 
+     983                 :          1 :         spdm_response_size = sizeof(spdm_error_response_t);
+     984                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     985                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     986                 :            : 
+     987                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     988                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     989                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_REQUEST_RESYNCH;
+     990                 :          1 :         spdm_response->header.param2 = 0;
+     991                 :            : 
+     992                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     993                 :            :                                               false, spdm_response_size,
+     994                 :            :                                               spdm_response,
+     995                 :            :                                               response_size, response);
+     996                 :            :     }
+     997                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     998                 :            : 
+     999                 :          2 :     case 0x8: {
+    1000                 :            :         spdm_error_response_data_response_not_ready_t *spdm_response;
+    1001                 :            :         size_t spdm_response_size;
+    1002                 :            :         size_t transport_header_size;
+    1003                 :            : 
+    1004                 :          2 :         spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
+    1005                 :          2 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1006                 :          2 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1007                 :            : 
+    1008                 :          2 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1009                 :          2 :         spdm_response->header.request_response_code = SPDM_ERROR;
+    1010                 :          2 :         spdm_response->header.param1 =
+    1011                 :            :             SPDM_ERROR_CODE_RESPONSE_NOT_READY;
+    1012                 :          2 :         spdm_response->header.param2 = 0;
+    1013                 :          2 :         spdm_response->extend_error_data.rd_exponent = 1;
+    1014                 :          2 :         spdm_response->extend_error_data.rd_tm = 2;
+    1015                 :          2 :         spdm_response->extend_error_data.request_code =
+    1016                 :            :             SPDM_KEY_EXCHANGE;
+    1017                 :          2 :         spdm_response->extend_error_data.token = 0;
+    1018                 :            : 
+    1019                 :          2 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1020                 :            :                                               false, spdm_response_size,
+    1021                 :            :                                               spdm_response,
+    1022                 :            :                                               response_size, response);
+    1023                 :            :     }
+    1024                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+    1025                 :            : 
+    1026                 :          2 :     case 0x9: {
+    1027                 :            :         static size_t sub_index2 = 0;
+    1028         [ +  + ]:          2 :         if (sub_index2 == 0) {
+    1029                 :            :             spdm_error_response_data_response_not_ready_t
+    1030                 :            :             *spdm_response;
+    1031                 :            :             size_t spdm_response_size;
+    1032                 :            :             size_t transport_header_size;
+    1033                 :            : 
+    1034                 :          1 :             spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
+    1035                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1036                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1037                 :            : 
+    1038                 :          1 :             spdm_response->header.spdm_version =
+    1039                 :            :                 SPDM_MESSAGE_VERSION_11;
+    1040                 :          1 :             spdm_response->header.request_response_code = SPDM_ERROR;
+    1041                 :          1 :             spdm_response->header.param1 =
+    1042                 :            :                 SPDM_ERROR_CODE_RESPONSE_NOT_READY;
+    1043                 :          1 :             spdm_response->header.param2 = 0;
+    1044                 :          1 :             spdm_response->extend_error_data.rd_exponent = 1;
+    1045                 :          1 :             spdm_response->extend_error_data.rd_tm = 2;
+    1046                 :          1 :             spdm_response->extend_error_data.request_code =
+    1047                 :            :                 SPDM_KEY_EXCHANGE;
+    1048                 :          1 :             spdm_response->extend_error_data.token = 1;
+    1049                 :            : 
+    1050                 :          1 :             libspdm_transport_test_encode_message(
+    1051                 :            :                 spdm_context, NULL, false, false,
+    1052                 :            :                 spdm_response_size, spdm_response,
+    1053                 :            :                 response_size, response);
+    1054                 :          1 :             sub_index2++;
+    1055         [ +  - ]:          1 :         } else if (sub_index2 == 1) {
+    1056                 :            :             spdm_key_exchange_response_t *spdm_response;
+    1057                 :            :             size_t dhe_key_size;
+    1058                 :            :             uint32_t hash_size;
+    1059                 :            :             size_t signature_size;
+    1060                 :            :             uint32_t hmac_size;
+    1061                 :            :             uint8_t *ptr;
+    1062                 :            :             void *dhe_context;
+    1063                 :            :             uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    1064                 :            :             size_t final_key_size;
+    1065                 :            :             size_t opaque_key_exchange_rsp_size;
+    1066                 :            :             void *data;
+    1067                 :            :             size_t data_size;
+    1068                 :            :             uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1069                 :            :             uint8_t *cert_buffer;
+    1070                 :            :             size_t cert_buffer_size;
+    1071                 :            :             uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    1072                 :            :             uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1073                 :            :             uint8_t bin_str0[128];
+    1074                 :            :             size_t bin_str0_size;
+    1075                 :            :             uint8_t bin_str2[128];
+    1076                 :            :             size_t bin_str2_size;
+    1077                 :            :             uint8_t bin_str7[128];
+    1078                 :            :             size_t bin_str7_size;
+    1079                 :            :             uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    1080                 :            :             uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    1081                 :            :             uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    1082                 :            :             size_t spdm_response_size;
+    1083                 :            :             size_t transport_header_size;
+    1084                 :            : 
+    1085                 :            :             ((libspdm_context_t *)spdm_context)
+    1086                 :          1 :             ->connection_info.algorithm.base_asym_algo =
+    1087                 :            :                 m_libspdm_use_asym_algo;
+    1088                 :            :             ((libspdm_context_t *)spdm_context)
+    1089                 :          1 :             ->connection_info.algorithm.base_hash_algo =
+    1090                 :            :                 m_libspdm_use_hash_algo;
+    1091                 :            :             ((libspdm_context_t *)spdm_context)
+    1092                 :          1 :             ->connection_info.algorithm.dhe_named_group =
+    1093                 :            :                 m_libspdm_use_dhe_algo;
+    1094                 :            :             ((libspdm_context_t *)spdm_context)
+    1095                 :            :             ->connection_info.algorithm
+    1096                 :          1 :             .measurement_hash_algo =
+    1097                 :            :                 m_libspdm_use_measurement_hash_algo;
+    1098                 :          1 :             signature_size =
+    1099                 :          1 :                 libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    1100                 :          1 :             hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1101                 :          1 :             hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1102                 :          1 :             dhe_key_size =
+    1103                 :          1 :                 libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    1104                 :          1 :             opaque_key_exchange_rsp_size =
+    1105                 :          1 :                 libspdm_get_opaque_data_version_selection_data_size(
+    1106                 :            :                     spdm_context);
+    1107                 :          1 :             spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    1108                 :          1 :                                  dhe_key_size + 0 + sizeof(uint16_t) +
+    1109                 :          1 :                                  opaque_key_exchange_rsp_size +
+    1110                 :          1 :                                  signature_size + hmac_size;
+    1111                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1112                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1113                 :            : 
+    1114                 :          1 :             spdm_response->header.spdm_version =
+    1115                 :            :                 SPDM_MESSAGE_VERSION_11;
+    1116                 :          1 :             spdm_response->header.request_response_code =
+    1117                 :            :                 SPDM_KEY_EXCHANGE_RSP;
+    1118                 :          1 :             spdm_response->header.param1 = 0;
+    1119                 :          1 :             spdm_response->rsp_session_id =
+    1120                 :          1 :                 libspdm_allocate_rsp_session_id(spdm_context, false);
+    1121                 :          1 :             spdm_response->mut_auth_requested = 0;
+    1122                 :          1 :             spdm_response->req_slot_id_param = 0;
+    1123                 :          1 :             libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    1124                 :          1 :                                       spdm_response->random_data);
+    1125                 :          1 :             ptr = (void *)(spdm_response + 1);
+    1126                 :          1 :             dhe_context = libspdm_dhe_new(
+    1127                 :          1 :                 spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    1128                 :            :                     m_libspdm_use_dhe_algo, true);
+    1129                 :          1 :             libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+    1130                 :            :                                      &dhe_key_size);
+    1131                 :          1 :             final_key_size = sizeof(final_key);
+    1132                 :          1 :             libspdm_dhe_compute_key(
+    1133                 :            :                 m_libspdm_use_dhe_algo, dhe_context,
+    1134                 :          1 :                 (uint8_t *)&m_libspdm_local_buffer[0] +
+    1135                 :            :                 sizeof(spdm_key_exchange_request_t),
+    1136                 :            :                 dhe_key_size, final_key, &final_key_size);
+    1137                 :          1 :             libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    1138                 :          1 :             ptr += dhe_key_size;
+    1139                 :            :             /* libspdm_zero_mem (ptr, hash_size);
+    1140                 :            :              * ptr += hash_size;*/
+    1141                 :          1 :             *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    1142                 :          1 :             ptr += sizeof(uint16_t);
+    1143                 :          1 :             libspdm_build_opaque_data_version_selection_data(
+    1144                 :            :                 spdm_context, &opaque_key_exchange_rsp_size,
+    1145                 :            :                 ptr);
+    1146                 :          1 :             ptr += opaque_key_exchange_rsp_size;
+    1147                 :          1 :             libspdm_read_responder_public_certificate_chain(
+    1148                 :            :                 m_libspdm_use_hash_algo, m_libspdm_use_asym_algo, &data,
+    1149                 :            :                 &data_size, NULL, NULL);
+    1150                 :          1 :             libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    1151                 :            :                              sizeof(m_libspdm_local_buffer)
+    1152                 :          1 :                              - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    1153                 :            :                                 m_libspdm_local_buffer),
+    1154                 :          1 :                              spdm_response, (size_t)ptr - (size_t)spdm_response);
+    1155                 :          1 :             m_libspdm_local_buffer_size +=
+    1156                 :          1 :                 ((size_t)ptr - (size_t)spdm_response);
+    1157                 :          1 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    1158                 :            :                            m_libspdm_local_buffer_size));
+    1159                 :          1 :             libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    1160                 :          1 :             libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    1161                 :          1 :             cert_buffer = (uint8_t *)data;
+    1162                 :          1 :             cert_buffer_size = data_size;
+    1163                 :          1 :             libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer,
+    1164                 :            :                              cert_buffer_size, cert_buffer_hash);
+    1165                 :            :             /* transcript.message_a size is 0*/
+    1166                 :          1 :             libspdm_append_managed_buffer(&th_curr, cert_buffer_hash,
+    1167                 :            :                                           hash_size);
+    1168                 :          1 :             libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    1169                 :            :                                           m_libspdm_local_buffer_size);
+    1170                 :          2 :             libspdm_hash_all(m_libspdm_use_hash_algo,
+    1171                 :          1 :                              libspdm_get_managed_buffer(&th_curr),
+    1172                 :            :                              libspdm_get_managed_buffer_size(&th_curr),
+    1173                 :            :                              hash_data);
+    1174                 :          1 :             free(data);
+    1175                 :          1 :             libspdm_responder_data_sign(
+    1176                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    1177                 :            :                 spdm_context,
+    1178                 :            : #endif
+    1179                 :          1 :                 spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    1180                 :            :                     SPDM_KEY_EXCHANGE_RSP,
+    1181                 :            :                     m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    1182                 :          1 :                     false, libspdm_get_managed_buffer(&th_curr),
+    1183                 :            :                     libspdm_get_managed_buffer_size(&th_curr), ptr,
+    1184                 :            :                     &signature_size);
+    1185                 :          1 :             libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    1186                 :            :                              sizeof(m_libspdm_local_buffer)
+    1187                 :          1 :                              - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    1188                 :            :                                 m_libspdm_local_buffer),
+    1189                 :            :                              ptr, signature_size);
+    1190                 :          1 :             m_libspdm_local_buffer_size += signature_size;
+    1191                 :          1 :             libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    1192                 :          1 :             ptr += signature_size;
+    1193                 :          2 :             libspdm_hash_all(m_libspdm_use_hash_algo,
+    1194                 :          1 :                              libspdm_get_managed_buffer(&th_curr),
+    1195                 :            :                              libspdm_get_managed_buffer_size(&th_curr),
+    1196                 :            :                              th_curr_hash_data);
+    1197                 :          1 :             bin_str0_size = sizeof(bin_str0);
+    1198                 :          1 :             libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1199                 :            :                                SPDM_BIN_STR_0_LABEL,
+    1200                 :            :                                sizeof(SPDM_BIN_STR_0_LABEL) - 1, NULL,
+    1201                 :          1 :                                (uint16_t)hash_size, hash_size, bin_str0,
+    1202                 :            :                                &bin_str0_size);
+    1203                 :          1 :             libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    1204                 :            :                              m_libspdm_zero_filled_buffer, hash_size, handshake_secret);
+    1205                 :          1 :             bin_str2_size = sizeof(bin_str2);
+    1206                 :          1 :             libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1207                 :            :                                SPDM_BIN_STR_2_LABEL,
+    1208                 :            :                                sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    1209                 :          1 :                                th_curr_hash_data, (uint16_t)hash_size,
+    1210                 :            :                                hash_size, bin_str2, &bin_str2_size);
+    1211                 :          1 :             libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret,
+    1212                 :            :                                 hash_size, bin_str2, bin_str2_size,
+    1213                 :            :                                 response_handshake_secret, hash_size);
+    1214                 :          1 :             bin_str7_size = sizeof(bin_str7);
+    1215                 :          1 :             libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1216                 :            :                                SPDM_BIN_STR_7_LABEL,
+    1217                 :            :                                sizeof(SPDM_BIN_STR_7_LABEL) - 1, NULL,
+    1218                 :          1 :                                (uint16_t)hash_size, hash_size, bin_str7,
+    1219                 :            :                                &bin_str7_size);
+    1220                 :          1 :             libspdm_hkdf_expand(m_libspdm_use_hash_algo,
+    1221                 :            :                                 response_handshake_secret, hash_size,
+    1222                 :            :                                 bin_str7, bin_str7_size,
+    1223                 :            :                                 response_finished_key, hash_size);
+    1224                 :          1 :             libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1225                 :            :                              libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1226                 :          1 :             libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    1227                 :            :                              response_finished_key, hash_size, ptr);
+    1228                 :          1 :             ptr += hmac_size;
+    1229                 :            : 
+    1230                 :          1 :             libspdm_transport_test_encode_message(
+    1231                 :            :                 spdm_context, NULL, false, false, spdm_response_size,
+    1232                 :            :                 spdm_response, response_size, response);
+    1233                 :            :         }
+    1234                 :            :     }
+    1235                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+    1236                 :            : 
+    1237                 :         18 :     case 0xA:
+    1238                 :            :     {
+    1239                 :            :         static uint16_t error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
+    1240                 :            : 
+    1241                 :            :         spdm_error_response_t *spdm_response;
+    1242                 :            :         size_t spdm_response_size;
+    1243                 :            :         size_t transport_header_size;
+    1244                 :            : 
+    1245                 :         18 :         spdm_response_size = sizeof(spdm_error_response_t);
+    1246                 :         18 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1247                 :         18 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1248                 :            : 
+    1249         [ +  - ]:         18 :         if(error_code <= 0xff) {
+    1250                 :         18 :             libspdm_zero_mem (spdm_response, spdm_response_size);
+    1251                 :         18 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1252                 :         18 :             spdm_response->header.request_response_code = SPDM_ERROR;
+    1253                 :         18 :             spdm_response->header.param1 = (uint8_t) error_code;
+    1254                 :         18 :             spdm_response->header.param2 = 0;
+    1255                 :            : 
+    1256                 :         18 :             libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+    1257                 :            :                                                    spdm_response_size, spdm_response,
+    1258                 :            :                                                    response_size, response);
+    1259                 :            :         }
+    1260                 :            : 
+    1261                 :         18 :         error_code++;
+    1262         [ +  + ]:         18 :         if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
+    1263                 :          1 :             error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
+    1264                 :            :         }
+    1265         [ +  + ]:         18 :         if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) { /*skip some reserved error codes (0d to 3e)*/
+    1266                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
+    1267                 :            :         }
+    1268         [ +  + ]:         18 :         if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) { /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
+    1269                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
+    1270                 :            :         }
+    1271                 :            :     }
+    1272                 :         18 :         return LIBSPDM_STATUS_SUCCESS;
+    1273                 :          1 :     case 0xB: {
+    1274                 :            :         spdm_key_exchange_response_t *spdm_response;
+    1275                 :            :         size_t dhe_key_size;
+    1276                 :            :         uint32_t hash_size;
+    1277                 :            :         size_t signature_size;
+    1278                 :            :         uint32_t hmac_size;
+    1279                 :            :         uint8_t *ptr;
+    1280                 :            :         void *dhe_context;
+    1281                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    1282                 :            :         size_t final_key_size;
+    1283                 :            :         size_t opaque_key_exchange_rsp_size;
+    1284                 :            :         void *data;
+    1285                 :            :         size_t data_size;
+    1286                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1287                 :            :         uint8_t *cert_buffer;
+    1288                 :            :         size_t cert_buffer_size;
+    1289                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    1290                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1291                 :            :         uint8_t bin_str0[128];
+    1292                 :            :         size_t bin_str0_size;
+    1293                 :            :         uint8_t bin_str2[128];
+    1294                 :            :         size_t bin_str2_size;
+    1295                 :            :         uint8_t bin_str7[128];
+    1296                 :            :         size_t bin_str7_size;
+    1297                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    1298                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    1299                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    1300                 :            :         size_t spdm_response_size;
+    1301                 :            :         size_t transport_header_size;
+    1302                 :            : 
+    1303                 :            :         ((libspdm_context_t *)spdm_context)
+    1304                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    1305                 :            :             m_libspdm_use_asym_algo;
+    1306                 :            :         ((libspdm_context_t *)spdm_context)
+    1307                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    1308                 :            :             m_libspdm_use_hash_algo;
+    1309                 :            :         ((libspdm_context_t *)spdm_context)
+    1310                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    1311                 :            :             m_libspdm_use_dhe_algo;
+    1312                 :            :         ((libspdm_context_t *)spdm_context)
+    1313                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    1314                 :            :             m_libspdm_use_measurement_hash_algo;
+    1315                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    1316                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1317                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1318                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    1319                 :          1 :         opaque_key_exchange_rsp_size =
+    1320                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    1321                 :            :                 spdm_context);
+    1322                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    1323                 :          1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
+    1324                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+    1325                 :            :                              hmac_size;
+    1326                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1327                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1328                 :            : 
+    1329                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1330                 :          1 :         spdm_response->header.request_response_code =
+    1331                 :            :             SPDM_KEY_EXCHANGE_RSP;
+    1332                 :          1 :         spdm_response->header.param1 = 0;
+    1333                 :          1 :         spdm_response->rsp_session_id =
+    1334                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
+    1335                 :          1 :         spdm_response->mut_auth_requested = 0;
+    1336                 :          1 :         spdm_response->req_slot_id_param = 0;
+    1337                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    1338                 :          1 :                                   spdm_response->random_data);
+    1339                 :          1 :         ptr = (void *)(spdm_response + 1);
+    1340                 :          1 :         dhe_context = libspdm_dhe_new(
+    1341                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    1342                 :            :                 m_libspdm_use_dhe_algo,
+    1343                 :            :                 true);
+    1344                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+    1345                 :            :                                  &dhe_key_size);
+    1346                 :          1 :         final_key_size = sizeof(final_key);
+    1347                 :          1 :         libspdm_dhe_compute_key(
+    1348                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    1349                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    1350                 :            :             sizeof(spdm_key_exchange_request_t),
+    1351                 :            :             dhe_key_size, final_key, &final_key_size);
+    1352                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    1353                 :          1 :         ptr += dhe_key_size;
+    1354                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    1355                 :            :          * ptr += hash_size;*/
+    1356                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    1357                 :          1 :         ptr += sizeof(uint16_t);
+    1358                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    1359                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    1360                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+    1361                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1362                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    1363                 :            :                                                         &data_size, NULL, NULL);
+    1364                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    1365                 :            :                          sizeof(m_libspdm_local_buffer)
+    1366                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    1367                 :            :                             m_libspdm_local_buffer),
+    1368                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    1369                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    1370                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    1371                 :            :                        m_libspdm_local_buffer_size));
+    1372                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    1373                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    1374                 :          1 :         cert_buffer = (uint8_t *)data;
+    1375                 :          1 :         cert_buffer_size = data_size;
+    1376                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    1377                 :            :                          cert_buffer_hash);
+    1378                 :            :         /* transcript.message_a size is 0*/
+    1379                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    1380                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    1381                 :            :                                       m_libspdm_local_buffer_size);
+    1382                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1383                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1384                 :          1 :         free(data);
+    1385                 :          1 :         libspdm_responder_data_sign(
+    1386                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    1387                 :            :             spdm_context,
+    1388                 :            : #endif
+    1389                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    1390                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    1391                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    1392                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+    1393                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    1394                 :            :                 &signature_size);
+    1395                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    1396                 :            :                          sizeof(m_libspdm_local_buffer)
+    1397                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    1398                 :            :                             m_libspdm_local_buffer),
+    1399                 :            :                          ptr, signature_size);
+    1400                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+    1401                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    1402                 :          1 :         ptr += signature_size;
+    1403                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1404                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    1405                 :            :                          th_curr_hash_data);
+    1406                 :          1 :         bin_str0_size = sizeof(bin_str0);
+    1407                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1408                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    1409                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    1410                 :            :                            &bin_str0_size);
+    1411                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    1412                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    1413                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    1414                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1415                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    1416                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    1417                 :            :                            bin_str2, &bin_str2_size);
+    1418                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    1419                 :            :                             bin_str2, bin_str2_size,
+    1420                 :            :                             response_handshake_secret, hash_size);
+    1421                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    1422                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1423                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    1424                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    1425                 :            :                            &bin_str7_size);
+    1426                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    1427                 :            :                             hash_size, bin_str7, bin_str7_size,
+    1428                 :            :                             response_finished_key, hash_size);
+    1429                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1430                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1431                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    1432                 :            :                          response_finished_key, hash_size, ptr);
+    1433                 :          1 :         ptr += hmac_size;
+    1434                 :            : 
+    1435                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1436                 :            :                                               false, spdm_response_size,
+    1437                 :            :                                               spdm_response, response_size,
+    1438                 :            :                                               response);
+    1439                 :            :     }
+    1440                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1441                 :          1 :     case 0xC: {
+    1442                 :            :         spdm_key_exchange_response_t *spdm_response;
+    1443                 :            :         size_t dhe_key_size;
+    1444                 :            :         uint32_t hash_size;
+    1445                 :            :         uint32_t measurement_hash_size;
+    1446                 :            :         size_t signature_size;
+    1447                 :            :         uint32_t hmac_size;
+    1448                 :            :         uint8_t *ptr;
+    1449                 :            :         void *dhe_context;
+    1450                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    1451                 :            :         size_t final_key_size;
+    1452                 :            :         size_t opaque_key_exchange_rsp_size;
+    1453                 :            :         void *data;
+    1454                 :            :         size_t data_size;
+    1455                 :            :         uint8_t measurement_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1456                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1457                 :            :         uint8_t *cert_buffer;
+    1458                 :            :         size_t cert_buffer_size;
+    1459                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    1460                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1461                 :            :         uint8_t bin_str0[128];
+    1462                 :            :         size_t bin_str0_size;
+    1463                 :            :         uint8_t bin_str2[128];
+    1464                 :            :         size_t bin_str2_size;
+    1465                 :            :         uint8_t bin_str7[128];
+    1466                 :            :         size_t bin_str7_size;
+    1467                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    1468                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    1469                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    1470                 :            :         size_t spdm_response_size;
+    1471                 :            :         size_t transport_header_size;
+    1472                 :            : 
+    1473                 :            :         ((libspdm_context_t *)spdm_context)
+    1474                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    1475                 :            :             m_libspdm_use_asym_algo;
+    1476                 :            :         ((libspdm_context_t *)spdm_context)
+    1477                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    1478                 :            :             m_libspdm_use_hash_algo;
+    1479                 :            :         ((libspdm_context_t *)spdm_context)
+    1480                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    1481                 :            :             m_libspdm_use_dhe_algo;
+    1482                 :            :         ((libspdm_context_t *)spdm_context)
+    1483                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    1484                 :            :             m_libspdm_use_measurement_hash_algo;
+    1485                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    1486                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1487                 :          1 :         measurement_hash_size = libspdm_get_hash_size(
+    1488                 :            :             m_libspdm_use_hash_algo);
+    1489                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1490                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    1491                 :          1 :         opaque_key_exchange_rsp_size =
+    1492                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    1493                 :            :                 spdm_context);
+    1494                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    1495                 :          1 :                              dhe_key_size + measurement_hash_size + sizeof(uint16_t) +
+    1496                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+    1497                 :            :                              hmac_size;
+    1498                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1499                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1500                 :          1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    1501                 :            : 
+    1502                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1503                 :          1 :         spdm_response->header.request_response_code =
+    1504                 :            :             SPDM_KEY_EXCHANGE_RSP;
+    1505                 :          1 :         spdm_response->header.param1 = 0;
+    1506                 :          1 :         spdm_response->rsp_session_id =
+    1507                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
+    1508                 :          1 :         spdm_response->mut_auth_requested = 0;
+    1509                 :          1 :         spdm_response->req_slot_id_param = 0;
+    1510                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    1511                 :          1 :                                   spdm_response->random_data);
+    1512                 :          1 :         ptr = (void *)(spdm_response + 1);
+    1513                 :          1 :         dhe_context = libspdm_dhe_new(
+    1514                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    1515                 :            :                 m_libspdm_use_dhe_algo,
+    1516                 :            :                 true);
+    1517                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+    1518                 :            :                                  &dhe_key_size);
+    1519                 :          1 :         final_key_size = sizeof(final_key);
+    1520                 :          1 :         libspdm_dhe_compute_key(
+    1521                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    1522                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    1523                 :            :             sizeof(spdm_key_exchange_request_t),
+    1524                 :            :             dhe_key_size, final_key, &final_key_size);
+    1525                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    1526                 :          1 :         ptr += dhe_key_size;
+    1527                 :            :         /*Mock measurement hash as TCB*/
+    1528                 :          1 :         libspdm_copy_mem(measurement_hash_data, sizeof(measurement_hash_data),
+    1529                 :            :                          m_libspdm_use_tcb_hash_value, measurement_hash_size);
+    1530                 :          1 :         libspdm_copy_mem(ptr, spdm_response_size - (ptr - (uint8_t *)spdm_response),
+    1531                 :            :                          measurement_hash_data, measurement_hash_size);
+    1532                 :            :         /*libspdm_zero_mem (ptr, measurement_hash_size);*/
+    1533                 :          1 :         ptr += measurement_hash_size;
+    1534                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    1535                 :          1 :         ptr += sizeof(uint16_t);
+    1536                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    1537                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    1538                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+    1539                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1540                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    1541                 :            :                                                         &data_size, NULL, NULL);
+    1542                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    1543                 :            :                          sizeof(m_libspdm_local_buffer)
+    1544                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    1545                 :            :                             m_libspdm_local_buffer),
+    1546                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    1547                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    1548                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    1549                 :            :                        m_libspdm_local_buffer_size));
+    1550                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    1551                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    1552                 :          1 :         cert_buffer =  (uint8_t *)data;
+    1553                 :          1 :         cert_buffer_size = data_size;
+    1554                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    1555                 :            :                          cert_buffer_hash);
+    1556                 :            :         /* transcript.message_a size is 0*/
+    1557                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    1558                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    1559                 :            :                                       m_libspdm_local_buffer_size);
+    1560                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1561                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1562                 :          1 :         free(data);
+    1563                 :          1 :         libspdm_responder_data_sign(
+    1564                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    1565                 :            :             spdm_context,
+    1566                 :            : #endif
+    1567                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    1568                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    1569                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    1570                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+    1571                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    1572                 :            :                 &signature_size);
+    1573                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    1574                 :            :                          sizeof(m_libspdm_local_buffer)
+    1575                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    1576                 :            :                             m_libspdm_local_buffer),
+    1577                 :            :                          ptr, signature_size);
+    1578                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+    1579                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    1580                 :          1 :         ptr += signature_size;
+    1581                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1582                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    1583                 :            :                          th_curr_hash_data);
+    1584                 :          1 :         bin_str0_size = sizeof(bin_str0);
+    1585                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1586                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    1587                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    1588                 :            :                            &bin_str0_size);
+    1589                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    1590                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    1591                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    1592                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1593                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    1594                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    1595                 :            :                            bin_str2, &bin_str2_size);
+    1596                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    1597                 :            :                             bin_str2, bin_str2_size,
+    1598                 :            :                             response_handshake_secret, hash_size);
+    1599                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    1600                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1601                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    1602                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    1603                 :            :                            &bin_str7_size);
+    1604                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    1605                 :            :                             hash_size, bin_str7, bin_str7_size,
+    1606                 :            :                             response_finished_key, hash_size);
+    1607                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1608                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1609                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    1610                 :            :                          response_finished_key, hash_size, ptr);
+    1611                 :          1 :         ptr += hmac_size;
+    1612                 :            : 
+    1613                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1614                 :            :                                               false, spdm_response_size,
+    1615                 :            :                                               spdm_response, response_size,
+    1616                 :            :                                               response);
+    1617                 :            :     }
+    1618                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1619                 :            : 
+    1620                 :          1 :     case 0xD: {
+    1621                 :            :         spdm_key_exchange_response_t *spdm_response;
+    1622                 :            :         size_t dhe_key_size;
+    1623                 :            :         uint32_t hash_size;
+    1624                 :            :         uint32_t measurement_hash_size;
+    1625                 :            :         size_t signature_size;
+    1626                 :            :         uint32_t hmac_size;
+    1627                 :            :         uint8_t *ptr;
+    1628                 :            :         void *dhe_context;
+    1629                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    1630                 :            :         size_t final_key_size;
+    1631                 :            :         size_t opaque_key_exchange_rsp_size;
+    1632                 :            :         void *data;
+    1633                 :            :         size_t data_size;
+    1634                 :            :         uint8_t measurement_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1635                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1636                 :            :         uint8_t *cert_buffer;
+    1637                 :            :         size_t cert_buffer_size;
+    1638                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    1639                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1640                 :            :         uint8_t bin_str0[128];
+    1641                 :            :         size_t bin_str0_size;
+    1642                 :            :         uint8_t bin_str2[128];
+    1643                 :            :         size_t bin_str2_size;
+    1644                 :            :         uint8_t bin_str7[128];
+    1645                 :            :         size_t bin_str7_size;
+    1646                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    1647                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    1648                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    1649                 :            :         size_t spdm_response_size;
+    1650                 :            :         size_t transport_header_size;
+    1651                 :            : 
+    1652                 :            :         ((libspdm_context_t *)spdm_context)
+    1653                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    1654                 :            :             m_libspdm_use_asym_algo;
+    1655                 :            :         ((libspdm_context_t *)spdm_context)
+    1656                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    1657                 :            :             m_libspdm_use_hash_algo;
+    1658                 :            :         ((libspdm_context_t *)spdm_context)
+    1659                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    1660                 :            :             m_libspdm_use_dhe_algo;
+    1661                 :            :         ((libspdm_context_t *)spdm_context)
+    1662                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    1663                 :            :             m_libspdm_use_measurement_hash_algo;
+    1664                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    1665                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1666                 :          1 :         measurement_hash_size = libspdm_get_hash_size(
+    1667                 :            :             m_libspdm_use_hash_algo);
+    1668                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1669                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    1670                 :          1 :         opaque_key_exchange_rsp_size =
+    1671                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    1672                 :            :                 spdm_context);
+    1673                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    1674                 :          1 :                              dhe_key_size + measurement_hash_size + sizeof(uint16_t) +
+    1675                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+    1676                 :            :                              hmac_size;
+    1677                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1678                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1679                 :          1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    1680                 :            : 
+    1681                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1682                 :          1 :         spdm_response->header.request_response_code =
+    1683                 :            :             SPDM_KEY_EXCHANGE_RSP;
+    1684                 :          1 :         spdm_response->header.param1 = 0;
+    1685                 :          1 :         spdm_response->rsp_session_id =
+    1686                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
+    1687                 :          1 :         spdm_response->mut_auth_requested = 0;
+    1688                 :          1 :         spdm_response->req_slot_id_param = 0;
+    1689                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    1690                 :          1 :                                   spdm_response->random_data);
+    1691                 :          1 :         ptr = (void *)(spdm_response + 1);
+    1692                 :          1 :         dhe_context = libspdm_dhe_new(
+    1693                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    1694                 :            :                 m_libspdm_use_dhe_algo,
+    1695                 :            :                 true);
+    1696                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+    1697                 :            :                                  &dhe_key_size);
+    1698                 :          1 :         final_key_size = sizeof(final_key);
+    1699                 :          1 :         libspdm_dhe_compute_key(
+    1700                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    1701                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    1702                 :            :             sizeof(spdm_key_exchange_request_t),
+    1703                 :            :             dhe_key_size, final_key, &final_key_size);
+    1704                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    1705                 :          1 :         ptr += dhe_key_size;
+    1706                 :            :         /*Mock measurement hash as 0x00 array*/
+    1707                 :          1 :         libspdm_zero_mem(measurement_hash_data, measurement_hash_size);
+    1708                 :          1 :         libspdm_copy_mem(ptr, spdm_response_size - (ptr - (uint8_t *)spdm_response),
+    1709                 :            :                          measurement_hash_data, measurement_hash_size);
+    1710                 :            :         /*libspdm_zero_mem (ptr, measurement_hash_size);*/
+    1711                 :          1 :         ptr += measurement_hash_size;
+    1712                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    1713                 :          1 :         ptr += sizeof(uint16_t);
+    1714                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    1715                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    1716                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+    1717                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1718                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    1719                 :            :                                                         &data_size, NULL, NULL);
+    1720                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    1721                 :            :                          sizeof(m_libspdm_local_buffer)
+    1722                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    1723                 :            :                             m_libspdm_local_buffer),
+    1724                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    1725                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    1726                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    1727                 :            :                        m_libspdm_local_buffer_size));
+    1728                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    1729                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    1730                 :          1 :         cert_buffer = (uint8_t *)data;
+    1731                 :          1 :         cert_buffer_size =  data_size;
+    1732                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    1733                 :            :                          cert_buffer_hash);
+    1734                 :            :         /* transcript.message_a size is 0*/
+    1735                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    1736                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    1737                 :            :                                       m_libspdm_local_buffer_size);
+    1738                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1739                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1740                 :          1 :         free(data);
+    1741                 :          1 :         libspdm_responder_data_sign(
+    1742                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    1743                 :            :             spdm_context,
+    1744                 :            : #endif
+    1745                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    1746                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    1747                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    1748                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+    1749                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    1750                 :            :                 &signature_size);
+    1751                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    1752                 :            :                          sizeof(m_libspdm_local_buffer)
+    1753                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    1754                 :            :                             m_libspdm_local_buffer),
+    1755                 :            :                          ptr, signature_size);
+    1756                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+    1757                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    1758                 :          1 :         ptr += signature_size;
+    1759                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1760                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    1761                 :            :                          th_curr_hash_data);
+    1762                 :          1 :         bin_str0_size = sizeof(bin_str0);
+    1763                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1764                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    1765                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    1766                 :            :                            &bin_str0_size);
+    1767                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    1768                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    1769                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    1770                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1771                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    1772                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    1773                 :            :                            bin_str2, &bin_str2_size);
+    1774                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    1775                 :            :                             bin_str2, bin_str2_size,
+    1776                 :            :                             response_handshake_secret, hash_size);
+    1777                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    1778                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1779                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    1780                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    1781                 :            :                            &bin_str7_size);
+    1782                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    1783                 :            :                             hash_size, bin_str7, bin_str7_size,
+    1784                 :            :                             response_finished_key, hash_size);
+    1785                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1786                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1787                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    1788                 :            :                          response_finished_key, hash_size, ptr);
+    1789                 :          1 :         ptr += hmac_size;
+    1790                 :            : 
+    1791                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1792                 :            :                                               false, spdm_response_size,
+    1793                 :            :                                               spdm_response, response_size,
+    1794                 :            :                                               response);
+    1795                 :            :     }
+    1796                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1797                 :            : 
+    1798                 :          1 :     case 0xE: {
+    1799                 :            :         spdm_key_exchange_response_t *spdm_response;
+    1800                 :            :         size_t dhe_key_size;
+    1801                 :            :         uint32_t hash_size;
+    1802                 :            :         uint32_t measurement_hash_size;
+    1803                 :            :         size_t signature_size;
+    1804                 :            :         uint32_t hmac_size;
+    1805                 :            :         uint8_t *ptr;
+    1806                 :            :         void *dhe_context;
+    1807                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    1808                 :            :         size_t final_key_size;
+    1809                 :            :         size_t opaque_key_exchange_rsp_size;
+    1810                 :            :         void *data;
+    1811                 :            :         size_t data_size;
+    1812                 :            :         uint8_t measurement_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1813                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1814                 :            :         uint8_t *cert_buffer;
+    1815                 :            :         size_t cert_buffer_size;
+    1816                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    1817                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1818                 :            :         uint8_t bin_str0[128];
+    1819                 :            :         size_t bin_str0_size;
+    1820                 :            :         uint8_t bin_str2[128];
+    1821                 :            :         size_t bin_str2_size;
+    1822                 :            :         uint8_t bin_str7[128];
+    1823                 :            :         size_t bin_str7_size;
+    1824                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    1825                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    1826                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    1827                 :            :         size_t spdm_response_size;
+    1828                 :            :         size_t transport_header_size;
+    1829                 :            : 
+    1830                 :            :         ((libspdm_context_t *)spdm_context)
+    1831                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    1832                 :            :             m_libspdm_use_asym_algo;
+    1833                 :            :         ((libspdm_context_t *)spdm_context)
+    1834                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    1835                 :            :             m_libspdm_use_hash_algo;
+    1836                 :            :         ((libspdm_context_t *)spdm_context)
+    1837                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    1838                 :            :             m_libspdm_use_dhe_algo;
+    1839                 :            :         ((libspdm_context_t *)spdm_context)
+    1840                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    1841                 :            :             m_libspdm_use_measurement_hash_algo;
+    1842                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    1843                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1844                 :          1 :         measurement_hash_size = libspdm_get_hash_size(
+    1845                 :            :             m_libspdm_use_hash_algo);
+    1846                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1847                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    1848                 :          1 :         opaque_key_exchange_rsp_size =
+    1849                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    1850                 :            :                 spdm_context);
+    1851                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    1852                 :          1 :                              dhe_key_size + measurement_hash_size + sizeof(uint16_t) +
+    1853                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+    1854                 :            :                              hmac_size;
+    1855                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1856                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1857                 :          1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    1858                 :            : 
+    1859                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1860                 :          1 :         spdm_response->header.request_response_code =
+    1861                 :            :             SPDM_KEY_EXCHANGE_RSP;
+    1862                 :          1 :         spdm_response->header.param1 = 0;
+    1863                 :          1 :         spdm_response->rsp_session_id =
+    1864                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
+    1865                 :          1 :         spdm_response->mut_auth_requested = 0;
+    1866                 :          1 :         spdm_response->req_slot_id_param = 0;
+    1867                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    1868                 :          1 :                                   spdm_response->random_data);
+    1869                 :          1 :         ptr = (void *)(spdm_response + 1);
+    1870                 :          1 :         dhe_context = libspdm_dhe_new(
+    1871                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    1872                 :            :                 m_libspdm_use_dhe_algo,
+    1873                 :            :                 true);
+    1874                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+    1875                 :            :                                  &dhe_key_size);
+    1876                 :          1 :         final_key_size = sizeof(final_key);
+    1877                 :          1 :         libspdm_dhe_compute_key(
+    1878                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    1879                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    1880                 :            :             sizeof(spdm_key_exchange_request_t),
+    1881                 :            :             dhe_key_size, final_key, &final_key_size);
+    1882                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    1883                 :          1 :         ptr += dhe_key_size;
+    1884                 :            :         /*Mock measurement hash*/
+    1885                 :          1 :         libspdm_copy_mem(measurement_hash_data, sizeof(measurement_hash_data),
+    1886                 :            :                          m_libspdm_use_tcb_hash_value, measurement_hash_size);
+    1887                 :          1 :         libspdm_copy_mem(ptr, spdm_response_size - (ptr - (uint8_t *)spdm_response),
+    1888                 :            :                          measurement_hash_data, measurement_hash_size);
+    1889                 :            :         /*libspdm_zero_mem (ptr, measurement_hash_size);*/
+    1890                 :          1 :         ptr += measurement_hash_size;
+    1891                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    1892                 :          1 :         ptr += sizeof(uint16_t);
+    1893                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    1894                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    1895                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+    1896                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1897                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    1898                 :            :                                                         &data_size, NULL, NULL);
+    1899                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    1900                 :            :                          sizeof(m_libspdm_local_buffer)
+    1901                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    1902                 :            :                             m_libspdm_local_buffer),
+    1903                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    1904                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    1905                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    1906                 :            :                        m_libspdm_local_buffer_size));
+    1907                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    1908                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    1909                 :          1 :         cert_buffer =  (uint8_t *)data;
+    1910                 :          1 :         cert_buffer_size = data_size;
+    1911                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    1912                 :            :                          cert_buffer_hash);
+    1913                 :            :         /* transcript.message_a size is 0*/
+    1914                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    1915                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    1916                 :            :                                       m_libspdm_local_buffer_size);
+    1917                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1918                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1919                 :          1 :         free(data);
+    1920                 :          1 :         libspdm_responder_data_sign(
+    1921                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    1922                 :            :             spdm_context,
+    1923                 :            : #endif
+    1924                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    1925                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    1926                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    1927                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+    1928                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    1929                 :            :                 &signature_size);
+    1930                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    1931                 :            :                          sizeof(m_libspdm_local_buffer)
+    1932                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    1933                 :            :                             m_libspdm_local_buffer),
+    1934                 :            :                          ptr, signature_size);
+    1935                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+    1936                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    1937                 :          1 :         ptr += signature_size;
+    1938                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1939                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    1940                 :            :                          th_curr_hash_data);
+    1941                 :          1 :         bin_str0_size = sizeof(bin_str0);
+    1942                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1943                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    1944                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    1945                 :            :                            &bin_str0_size);
+    1946                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    1947                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    1948                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    1949                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1950                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    1951                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    1952                 :            :                            bin_str2, &bin_str2_size);
+    1953                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    1954                 :            :                             bin_str2, bin_str2_size,
+    1955                 :            :                             response_handshake_secret, hash_size);
+    1956                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    1957                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1958                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    1959                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    1960                 :            :                            &bin_str7_size);
+    1961                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    1962                 :            :                             hash_size, bin_str7, bin_str7_size,
+    1963                 :            :                             response_finished_key, hash_size);
+    1964                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1965                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1966                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    1967                 :            :                          response_finished_key, hash_size, ptr);
+    1968                 :          1 :         ptr += hmac_size;
+    1969                 :            : 
+    1970                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1971                 :            :                                               false, spdm_response_size,
+    1972                 :            :                                               spdm_response, response_size,
+    1973                 :            :                                               response);
+    1974                 :            :     }
+    1975                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1976                 :            : 
+    1977                 :          1 :     case 0xF: {
+    1978                 :            :         spdm_key_exchange_response_t *spdm_response;
+    1979                 :            :         size_t dhe_key_size;
+    1980                 :            :         uint32_t hash_size;
+    1981                 :            :         size_t signature_size;
+    1982                 :            :         uint32_t hmac_size;
+    1983                 :            :         uint8_t *ptr;
+    1984                 :            :         void *dhe_context;
+    1985                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    1986                 :            :         size_t final_key_size;
+    1987                 :            :         size_t opaque_key_exchange_rsp_size;
+    1988                 :            :         void *data;
+    1989                 :            :         size_t data_size;
+    1990                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1991                 :            :         uint8_t *cert_buffer;
+    1992                 :            :         size_t cert_buffer_size;
+    1993                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    1994                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1995                 :            :         uint8_t bin_str0[128];
+    1996                 :            :         size_t bin_str0_size;
+    1997                 :            :         uint8_t bin_str2[128];
+    1998                 :            :         size_t bin_str2_size;
+    1999                 :            :         uint8_t bin_str7[128];
+    2000                 :            :         size_t bin_str7_size;
+    2001                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    2002                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    2003                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    2004                 :            :         size_t spdm_response_size;
+    2005                 :            :         size_t transport_header_size;
+    2006                 :            : 
+    2007                 :            :         ((libspdm_context_t *)spdm_context)
+    2008                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    2009                 :            :             m_libspdm_use_asym_algo;
+    2010                 :            :         ((libspdm_context_t *)spdm_context)
+    2011                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    2012                 :            :             m_libspdm_use_hash_algo;
+    2013                 :            :         ((libspdm_context_t *)spdm_context)
+    2014                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    2015                 :            :             m_libspdm_use_dhe_algo;
+    2016                 :            :         ((libspdm_context_t *)spdm_context)
+    2017                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    2018                 :            :             m_libspdm_use_measurement_hash_algo;
+    2019                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    2020                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2021                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2022                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    2023                 :          1 :         opaque_key_exchange_rsp_size =
+    2024                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    2025                 :            :                 spdm_context);
+    2026                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    2027                 :          1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
+    2028                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+    2029                 :            :                              hmac_size;
+    2030                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2031                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2032                 :          1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    2033                 :            : 
+    2034                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2035                 :          1 :         spdm_response->header.request_response_code =
+    2036                 :            :             SPDM_KEY_EXCHANGE_RSP;
+    2037                 :          1 :         spdm_response->header.param1 = 0;
+    2038                 :          1 :         spdm_response->rsp_session_id =
+    2039                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
+    2040                 :          1 :         spdm_response->mut_auth_requested = 0;
+    2041                 :          1 :         spdm_response->req_slot_id_param = 0;
+    2042                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    2043                 :          1 :                                   spdm_response->random_data);
+    2044                 :          1 :         ptr = (void *)(spdm_response + 1);
+    2045                 :          1 :         dhe_context = libspdm_dhe_new(
+    2046                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    2047                 :            :                 m_libspdm_use_dhe_algo,
+    2048                 :            :                 true);
+    2049                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+    2050                 :            :                                  &dhe_key_size);
+    2051                 :          1 :         final_key_size = sizeof(final_key);
+    2052                 :          1 :         libspdm_dhe_compute_key(
+    2053                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    2054                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    2055                 :            :             sizeof(spdm_key_exchange_request_t),
+    2056                 :            :             dhe_key_size, final_key, &final_key_size);
+    2057                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    2058                 :          1 :         ptr += dhe_key_size;
+    2059                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    2060                 :            :          * ptr += hash_size;*/
+    2061                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    2062                 :          1 :         ptr += sizeof(uint16_t);
+    2063                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    2064                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    2065                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+    2066                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    2067                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    2068                 :            :                                                         &data_size, NULL, NULL);
+    2069                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    2070                 :            :                          sizeof(m_libspdm_local_buffer)
+    2071                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    2072                 :            :                             m_libspdm_local_buffer),
+    2073                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    2074                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    2075                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    2076                 :            :                        m_libspdm_local_buffer_size));
+    2077                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    2078                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    2079                 :          1 :         cert_buffer =  (uint8_t *)data;
+    2080                 :          1 :         cert_buffer_size = data_size;
+    2081                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    2082                 :            :                          cert_buffer_hash);
+    2083                 :            :         /* transcript.message_a size is 0*/
+    2084                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    2085                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    2086                 :            :                                       m_libspdm_local_buffer_size);
+    2087                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2088                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2089                 :          1 :         free(data);
+    2090                 :          1 :         libspdm_responder_data_sign(
+    2091                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    2092                 :            :             spdm_context,
+    2093                 :            : #endif
+    2094                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    2095                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    2096                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    2097                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+    2098                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    2099                 :            :                 &signature_size);
+    2100                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    2101                 :            :                          sizeof(m_libspdm_local_buffer)
+    2102                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    2103                 :            :                             m_libspdm_local_buffer),
+    2104                 :            :                          ptr, signature_size);
+    2105                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+    2106                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    2107                 :          1 :         ptr += signature_size;
+    2108                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2109                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    2110                 :            :                          th_curr_hash_data);
+    2111                 :          1 :         bin_str0_size = sizeof(bin_str0);
+    2112                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2113                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    2114                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    2115                 :            :                            &bin_str0_size);
+    2116                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    2117                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    2118                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    2119                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2120                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    2121                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    2122                 :            :                            bin_str2, &bin_str2_size);
+    2123                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    2124                 :            :                             bin_str2, bin_str2_size,
+    2125                 :            :                             response_handshake_secret, hash_size);
+    2126                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    2127                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2128                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    2129                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    2130                 :            :                            &bin_str7_size);
+    2131                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    2132                 :            :                             hash_size, bin_str7, bin_str7_size,
+    2133                 :            :                             response_finished_key, hash_size);
+    2134                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2135                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2136                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    2137                 :            :                          response_finished_key, hash_size, ptr);
+    2138                 :          1 :         ptr += hmac_size;
+    2139                 :            : 
+    2140                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    2141                 :            :                                               false, spdm_response_size,
+    2142                 :            :                                               spdm_response, response_size,
+    2143                 :            :                                               response);
+    2144                 :            :     }
+    2145                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    2146                 :            : 
+    2147                 :          1 :     case 0x10: {
+    2148                 :            :         spdm_key_exchange_response_t *spdm_response;
+    2149                 :            :         size_t dhe_key_size;
+    2150                 :            :         uint32_t hash_size;
+    2151                 :            :         size_t signature_size;
+    2152                 :            :         uint32_t hmac_size;
+    2153                 :            :         uint8_t *ptr;
+    2154                 :            :         void *dhe_context;
+    2155                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    2156                 :            :         size_t final_key_size;
+    2157                 :            :         size_t opaque_key_exchange_rsp_size;
+    2158                 :            :         void *data;
+    2159                 :            :         size_t data_size;
+    2160                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2161                 :            :         uint8_t *cert_buffer;
+    2162                 :            :         size_t cert_buffer_size;
+    2163                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    2164                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2165                 :            :         uint8_t bin_str0[128];
+    2166                 :            :         size_t bin_str0_size;
+    2167                 :            :         uint8_t bin_str2[128];
+    2168                 :            :         size_t bin_str2_size;
+    2169                 :            :         uint8_t bin_str7[128];
+    2170                 :            :         size_t bin_str7_size;
+    2171                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    2172                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    2173                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    2174                 :            :         size_t spdm_response_size;
+    2175                 :            :         size_t transport_header_size;
+    2176                 :            : 
+    2177                 :            :         ((libspdm_context_t *)spdm_context)
+    2178                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    2179                 :            :             m_libspdm_use_asym_algo;
+    2180                 :            :         ((libspdm_context_t *)spdm_context)
+    2181                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    2182                 :            :             m_libspdm_use_hash_algo;
+    2183                 :            :         ((libspdm_context_t *)spdm_context)
+    2184                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    2185                 :            :             m_libspdm_use_dhe_algo;
+    2186                 :            :         ((libspdm_context_t *)spdm_context)
+    2187                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    2188                 :            :             m_libspdm_use_measurement_hash_algo;
+    2189                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    2190                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2191                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2192                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    2193                 :          1 :         opaque_key_exchange_rsp_size =
+    2194                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    2195                 :            :                 spdm_context);
+    2196                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    2197                 :          1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
+    2198                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+    2199                 :            :                              hmac_size;
+    2200                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2201                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2202                 :          1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    2203                 :            : 
+    2204                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2205                 :          1 :         spdm_response->header.request_response_code =
+    2206                 :            :             SPDM_KEY_EXCHANGE_RSP;
+    2207                 :          1 :         spdm_response->header.param1 = 0;
+    2208                 :          1 :         spdm_response->rsp_session_id =
+    2209                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
+    2210                 :          1 :         spdm_response->mut_auth_requested = 0;
+    2211                 :          1 :         spdm_response->req_slot_id_param = 0;
+    2212                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    2213                 :          1 :                                   spdm_response->random_data);
+    2214                 :          1 :         ptr = (void *)(spdm_response + 1);
+    2215                 :          1 :         dhe_context = libspdm_dhe_new(
+    2216                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    2217                 :            :                 m_libspdm_use_dhe_algo,
+    2218                 :            :                 true);
+    2219                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+    2220                 :            :                                  &dhe_key_size);
+    2221                 :          1 :         final_key_size = sizeof(final_key);
+    2222                 :          1 :         libspdm_dhe_compute_key(
+    2223                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    2224                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    2225                 :            :             sizeof(spdm_key_exchange_request_t),
+    2226                 :            :             dhe_key_size, final_key, &final_key_size);
+    2227                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    2228                 :          1 :         ptr += dhe_key_size;
+    2229                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    2230                 :            :          * ptr += hash_size;*/
+    2231                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    2232                 :          1 :         ptr += sizeof(uint16_t);
+    2233                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    2234                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    2235                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+    2236                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    2237                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    2238                 :            :                                                         &data_size, NULL, NULL);
+    2239                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    2240                 :            :                          sizeof(m_libspdm_local_buffer)
+    2241                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    2242                 :            :                             m_libspdm_local_buffer),
+    2243                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    2244                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    2245                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    2246                 :            :                        m_libspdm_local_buffer_size));
+    2247                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    2248                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    2249                 :          1 :         cert_buffer =  (uint8_t *)data;
+    2250                 :          1 :         cert_buffer_size = data_size;
+    2251                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    2252                 :            :                          cert_buffer_hash);
+    2253                 :            :         /* transcript.message_a size is 0*/
+    2254                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    2255                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    2256                 :            :                                       m_libspdm_local_buffer_size);
+    2257                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2258                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2259                 :          1 :         free(data);
+    2260                 :          1 :         libspdm_responder_data_sign(
+    2261                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    2262                 :            :             spdm_context,
+    2263                 :            : #endif
+    2264                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    2265                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    2266                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    2267                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+    2268                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    2269                 :            :                 &signature_size);
+    2270                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    2271                 :            :                          sizeof(m_libspdm_local_buffer)
+    2272                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    2273                 :            :                             m_libspdm_local_buffer),
+    2274                 :            :                          ptr, signature_size);
+    2275                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+    2276                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    2277                 :          1 :         ptr += signature_size;
+    2278                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2279                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    2280                 :            :                          th_curr_hash_data);
+    2281                 :          1 :         bin_str0_size = sizeof(bin_str0);
+    2282                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2283                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    2284                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    2285                 :            :                            &bin_str0_size);
+    2286                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    2287                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    2288                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    2289                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2290                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    2291                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    2292                 :            :                            bin_str2, &bin_str2_size);
+    2293                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    2294                 :            :                             bin_str2, bin_str2_size,
+    2295                 :            :                             response_handshake_secret, hash_size);
+    2296                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    2297                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2298                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    2299                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    2300                 :            :                            &bin_str7_size);
+    2301                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    2302                 :            :                             hash_size, bin_str7, bin_str7_size,
+    2303                 :            :                             response_finished_key, hash_size);
+    2304                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2305                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2306                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    2307                 :            :                          response_finished_key, hash_size, ptr);
+    2308                 :          1 :         ptr += hmac_size;
+    2309                 :            : 
+    2310                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    2311                 :            :                                               false, spdm_response_size,
+    2312                 :            :                                               spdm_response, response_size,
+    2313                 :            :                                               response);
+    2314                 :            :     }
+    2315                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    2316                 :            : 
+    2317                 :          1 :     case 0x11: {
+    2318                 :            :         spdm_key_exchange_response_t *spdm_response;
+    2319                 :            :         size_t dhe_key_size;
+    2320                 :            :         uint32_t hash_size;
+    2321                 :            :         uint32_t measurement_hash_size;
+    2322                 :            :         size_t signature_size;
+    2323                 :            :         uint32_t hmac_size;
+    2324                 :            :         uint8_t *ptr;
+    2325                 :            :         void *dhe_context;
+    2326                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    2327                 :            :         size_t final_key_size;
+    2328                 :            :         size_t opaque_key_exchange_rsp_size;
+    2329                 :            :         void *data;
+    2330                 :            :         size_t data_size;
+    2331                 :            :         uint8_t measurement_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2332                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2333                 :            :         uint8_t *cert_buffer;
+    2334                 :            :         size_t cert_buffer_size;
+    2335                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    2336                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2337                 :            :         uint8_t bin_str0[128];
+    2338                 :            :         size_t bin_str0_size;
+    2339                 :            :         uint8_t bin_str2[128];
+    2340                 :            :         size_t bin_str2_size;
+    2341                 :            :         uint8_t bin_str7[128];
+    2342                 :            :         size_t bin_str7_size;
+    2343                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    2344                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    2345                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    2346                 :            :         size_t spdm_response_size;
+    2347                 :            :         size_t transport_header_size;
+    2348                 :            : 
+    2349                 :            :         ((libspdm_context_t *)spdm_context)
+    2350                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    2351                 :            :             m_libspdm_use_asym_algo;
+    2352                 :            :         ((libspdm_context_t *)spdm_context)
+    2353                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    2354                 :            :             m_libspdm_use_hash_algo;
+    2355                 :            :         ((libspdm_context_t *)spdm_context)
+    2356                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    2357                 :            :             m_libspdm_use_dhe_algo;
+    2358                 :            :         ((libspdm_context_t *)spdm_context)
+    2359                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    2360                 :            :             m_libspdm_use_measurement_hash_algo;
+    2361                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    2362                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2363                 :          1 :         measurement_hash_size = libspdm_get_hash_size(
+    2364                 :            :             m_libspdm_use_hash_algo);
+    2365                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2366                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    2367                 :          1 :         opaque_key_exchange_rsp_size =
+    2368                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    2369                 :            :                 spdm_context);
+    2370                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    2371                 :          1 :                              dhe_key_size + measurement_hash_size + sizeof(uint16_t) +
+    2372                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+    2373                 :            :                              hmac_size;
+    2374                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2375                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2376                 :          1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    2377                 :            : 
+    2378                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2379                 :          1 :         spdm_response->header.request_response_code =
+    2380                 :            :             SPDM_KEY_EXCHANGE_RSP;
+    2381                 :          1 :         spdm_response->header.param1 = 0;
+    2382                 :          1 :         spdm_response->rsp_session_id =
+    2383                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
+    2384                 :          1 :         spdm_response->mut_auth_requested = 0;
+    2385                 :          1 :         spdm_response->req_slot_id_param = 0;
+    2386                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    2387                 :          1 :                                   spdm_response->random_data);
+    2388                 :          1 :         ptr = (void *)(spdm_response + 1);
+    2389                 :          1 :         dhe_context = libspdm_dhe_new(
+    2390                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    2391                 :            :                 m_libspdm_use_dhe_algo,
+    2392                 :            :                 true);
+    2393                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+    2394                 :            :                                  &dhe_key_size);
+    2395                 :          1 :         final_key_size = sizeof(final_key);
+    2396                 :          1 :         libspdm_dhe_compute_key(
+    2397                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    2398                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    2399                 :            :             sizeof(spdm_key_exchange_request_t),
+    2400                 :            :             dhe_key_size, final_key, &final_key_size);
+    2401                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    2402                 :          1 :         ptr += dhe_key_size;
+    2403                 :            :         /*Mock measurement hash as TCB*/
+    2404                 :          1 :         libspdm_copy_mem(measurement_hash_data, sizeof(measurement_hash_data),
+    2405                 :            :                          m_libspdm_use_tcb_hash_value, measurement_hash_size);
+    2406                 :          1 :         libspdm_copy_mem(ptr, spdm_response_size - (ptr - (uint8_t *)spdm_response),
+    2407                 :            :                          measurement_hash_data, measurement_hash_size);
+    2408                 :            :         /*libspdm_zero_mem (ptr, measurement_hash_size);*/
+    2409                 :          1 :         ptr += measurement_hash_size;
+    2410                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    2411                 :          1 :         ptr += sizeof(uint16_t);
+    2412                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    2413                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    2414                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+    2415                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    2416                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    2417                 :            :                                                         &data_size, NULL, NULL);
+    2418                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    2419                 :            :                          sizeof(m_libspdm_local_buffer)
+    2420                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    2421                 :            :                             m_libspdm_local_buffer),
+    2422                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    2423                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    2424                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    2425                 :            :                        m_libspdm_local_buffer_size));
+    2426                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    2427                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    2428                 :          1 :         cert_buffer =  (uint8_t *)data;
+    2429                 :          1 :         cert_buffer_size = data_size;
+    2430                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    2431                 :            :                          cert_buffer_hash);
+    2432                 :            :         /* transcript.message_a size is 0*/
+    2433                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    2434                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    2435                 :            :                                       m_libspdm_local_buffer_size);
+    2436                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2437                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2438                 :          1 :         free(data);
+    2439                 :          1 :         libspdm_responder_data_sign(
+    2440                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    2441                 :            :             spdm_context,
+    2442                 :            : #endif
+    2443                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    2444                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    2445                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    2446                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+    2447                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    2448                 :            :                 &signature_size);
+    2449                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    2450                 :            :                          sizeof(m_libspdm_local_buffer)
+    2451                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    2452                 :            :                             m_libspdm_local_buffer),
+    2453                 :            :                          ptr, signature_size);
+    2454                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+    2455                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    2456                 :          1 :         ptr += signature_size;
+    2457                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2458                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    2459                 :            :                          th_curr_hash_data);
+    2460                 :          1 :         bin_str0_size = sizeof(bin_str0);
+    2461                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2462                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    2463                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    2464                 :            :                            &bin_str0_size);
+    2465                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    2466                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    2467                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    2468                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2469                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    2470                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    2471                 :            :                            bin_str2, &bin_str2_size);
+    2472                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    2473                 :            :                             bin_str2, bin_str2_size,
+    2474                 :            :                             response_handshake_secret, hash_size);
+    2475                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    2476                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2477                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    2478                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    2479                 :            :                            &bin_str7_size);
+    2480                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    2481                 :            :                             hash_size, bin_str7, bin_str7_size,
+    2482                 :            :                             response_finished_key, hash_size);
+    2483                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2484                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2485                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    2486                 :            :                          response_finished_key, hash_size, ptr);
+    2487                 :          1 :         ptr += hmac_size;
+    2488                 :            : 
+    2489                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    2490                 :            :                                               false, spdm_response_size,
+    2491                 :            :                                               spdm_response, response_size,
+    2492                 :            :                                               response);
+    2493                 :            :     }
+    2494                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    2495                 :            : 
+    2496                 :          1 :     case 0x12: {
+    2497                 :            :         spdm_key_exchange_response_t *spdm_response;
+    2498                 :            :         size_t dhe_key_size;
+    2499                 :            :         uint32_t hash_size;
+    2500                 :            :         uint32_t measurement_hash_size;
+    2501                 :            :         size_t signature_size;
+    2502                 :            :         uint32_t hmac_size;
+    2503                 :            :         uint8_t *ptr;
+    2504                 :            :         void *dhe_context;
+    2505                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    2506                 :            :         size_t final_key_size;
+    2507                 :            :         size_t opaque_key_exchange_rsp_size;
+    2508                 :            :         void *data;
+    2509                 :            :         size_t data_size;
+    2510                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2511                 :            :         uint8_t *cert_buffer;
+    2512                 :            :         size_t cert_buffer_size;
+    2513                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    2514                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2515                 :            :         uint8_t bin_str0[128];
+    2516                 :            :         size_t bin_str0_size;
+    2517                 :            :         uint8_t bin_str2[128];
+    2518                 :            :         size_t bin_str2_size;
+    2519                 :            :         uint8_t bin_str7[128];
+    2520                 :            :         size_t bin_str7_size;
+    2521                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    2522                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    2523                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    2524                 :            :         size_t spdm_response_size;
+    2525                 :            :         size_t transport_header_size;
+    2526                 :            : 
+    2527                 :            :         ((libspdm_context_t *)spdm_context)
+    2528                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    2529                 :            :             m_libspdm_use_asym_algo;
+    2530                 :            :         ((libspdm_context_t *)spdm_context)
+    2531                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    2532                 :            :             m_libspdm_use_hash_algo;
+    2533                 :            :         ((libspdm_context_t *)spdm_context)
+    2534                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    2535                 :            :             m_libspdm_use_dhe_algo;
+    2536                 :            :         ((libspdm_context_t *)spdm_context)
+    2537                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    2538                 :            :             m_libspdm_use_measurement_hash_algo;
+    2539                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    2540                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2541                 :          1 :         measurement_hash_size = 0;
+    2542                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2543                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    2544                 :          1 :         opaque_key_exchange_rsp_size =
+    2545                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    2546                 :            :                 spdm_context);
+    2547                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    2548                 :          1 :                              dhe_key_size + measurement_hash_size + sizeof(uint16_t) +
+    2549                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+    2550                 :            :                              hmac_size;
+    2551                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2552                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2553                 :          1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    2554                 :            : 
+    2555                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2556                 :          1 :         spdm_response->header.request_response_code =
+    2557                 :            :             SPDM_KEY_EXCHANGE_RSP;
+    2558                 :          1 :         spdm_response->header.param1 = 0;
+    2559                 :          1 :         spdm_response->rsp_session_id =
+    2560                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
+    2561                 :          1 :         spdm_response->mut_auth_requested = 0;
+    2562                 :          1 :         spdm_response->req_slot_id_param = 0;
+    2563                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    2564                 :          1 :                                   spdm_response->random_data);
+    2565                 :          1 :         ptr = (void *)(spdm_response + 1);
+    2566                 :          1 :         dhe_context = libspdm_dhe_new(
+    2567                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    2568                 :            :                 m_libspdm_use_dhe_algo,
+    2569                 :            :                 true);
+    2570                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+    2571                 :            :                                  &dhe_key_size);
+    2572                 :          1 :         final_key_size = sizeof(final_key);
+    2573                 :          1 :         libspdm_dhe_compute_key(
+    2574                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    2575                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    2576                 :            :             sizeof(spdm_key_exchange_request_t),
+    2577                 :            :             dhe_key_size, final_key, &final_key_size);
+    2578                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    2579                 :          1 :         ptr += dhe_key_size;
+    2580                 :            : 
+    2581                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    2582                 :          1 :         ptr += sizeof(uint16_t);
+    2583                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    2584                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    2585                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+    2586                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    2587                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    2588                 :            :                                                         &data_size, NULL, NULL);
+    2589                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    2590                 :            :                          sizeof(m_libspdm_local_buffer)
+    2591                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    2592                 :            :                             m_libspdm_local_buffer),
+    2593                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    2594                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    2595                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    2596                 :            :                        m_libspdm_local_buffer_size));
+    2597                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    2598                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    2599                 :          1 :         cert_buffer =  (uint8_t *)data;
+    2600                 :          1 :         cert_buffer_size = data_size;
+    2601                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    2602                 :            :                          cert_buffer_hash);
+    2603                 :            :         /* transcript.message_a size is 0*/
+    2604                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    2605                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    2606                 :            :                                       m_libspdm_local_buffer_size);
+    2607                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2608                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2609                 :          1 :         free(data);
+    2610                 :          1 :         libspdm_responder_data_sign(
+    2611                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    2612                 :            :             spdm_context,
+    2613                 :            : #endif
+    2614                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    2615                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    2616                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    2617                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+    2618                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    2619                 :            :                 &signature_size);
+    2620                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    2621                 :            :                          sizeof(m_libspdm_local_buffer)
+    2622                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    2623                 :            :                             m_libspdm_local_buffer),
+    2624                 :            :                          ptr, signature_size);
+    2625                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+    2626                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    2627                 :          1 :         ptr += signature_size-1;
+    2628                 :          1 :         *ptr ^= 0xFF;
+    2629                 :          1 :         ptr++;
+    2630                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2631                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    2632                 :            :                          th_curr_hash_data);
+    2633                 :          1 :         bin_str0_size = sizeof(bin_str0);
+    2634                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2635                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    2636                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    2637                 :            :                            &bin_str0_size);
+    2638                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    2639                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    2640                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    2641                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2642                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    2643                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    2644                 :            :                            bin_str2, &bin_str2_size);
+    2645                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    2646                 :            :                             bin_str2, bin_str2_size,
+    2647                 :            :                             response_handshake_secret, hash_size);
+    2648                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    2649                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2650                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    2651                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    2652                 :            :                            &bin_str7_size);
+    2653                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    2654                 :            :                             hash_size, bin_str7, bin_str7_size,
+    2655                 :            :                             response_finished_key, hash_size);
+    2656                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2657                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2658                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    2659                 :            :                          response_finished_key, hash_size, ptr);
+    2660                 :          1 :         ptr += hmac_size;
+    2661                 :            : 
+    2662                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    2663                 :            :                                               false, spdm_response_size,
+    2664                 :            :                                               spdm_response, response_size,
+    2665                 :            :                                               response);
+    2666                 :            :     }
+    2667                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    2668                 :            : 
+    2669                 :          1 :     case 0x13: {
+    2670                 :            :         spdm_key_exchange_response_t *spdm_response;
+    2671                 :            :         size_t dhe_key_size;
+    2672                 :            :         uint32_t hash_size;
+    2673                 :            :         size_t signature_size;
+    2674                 :            :         uint32_t hmac_size;
+    2675                 :            :         uint8_t *ptr;
+    2676                 :            :         void *dhe_context;
+    2677                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    2678                 :            :         size_t final_key_size;
+    2679                 :            :         size_t opaque_key_exchange_rsp_size;
+    2680                 :            :         void *data;
+    2681                 :            :         size_t data_size;
+    2682                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2683                 :            :         uint8_t *cert_buffer;
+    2684                 :            :         size_t cert_buffer_size;
+    2685                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    2686                 :            :         size_t spdm_response_size;
+    2687                 :            :         size_t transport_header_size;
+    2688                 :            : 
+    2689                 :            :         ((libspdm_context_t *)spdm_context)
+    2690                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    2691                 :            :             m_libspdm_use_asym_algo;
+    2692                 :            :         ((libspdm_context_t *)spdm_context)
+    2693                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    2694                 :            :             m_libspdm_use_hash_algo;
+    2695                 :            :         ((libspdm_context_t *)spdm_context)
+    2696                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    2697                 :            :             m_libspdm_use_dhe_algo;
+    2698                 :            :         ((libspdm_context_t *)spdm_context)
+    2699                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    2700                 :            :             m_libspdm_use_measurement_hash_algo;
+    2701                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    2702                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2703                 :          1 :         hmac_size = 0;
+    2704                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    2705                 :          1 :         opaque_key_exchange_rsp_size =
+    2706                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    2707                 :            :                 spdm_context);
+    2708                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    2709                 :          1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
+    2710                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+    2711                 :            :                              hmac_size;
+    2712                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2713                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2714                 :          1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    2715                 :            : 
+    2716                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2717                 :          1 :         spdm_response->header.request_response_code =
+    2718                 :            :             SPDM_KEY_EXCHANGE_RSP;
+    2719                 :          1 :         spdm_response->header.param1 = 0;
+    2720                 :          1 :         spdm_response->rsp_session_id =
+    2721                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
+    2722                 :          1 :         spdm_response->mut_auth_requested = 0;
+    2723                 :          1 :         spdm_response->req_slot_id_param = 0;
+    2724                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    2725                 :          1 :                                   spdm_response->random_data);
+    2726                 :          1 :         ptr = (void *)(spdm_response + 1);
+    2727                 :          1 :         dhe_context = libspdm_dhe_new(
+    2728                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    2729                 :            :                 m_libspdm_use_dhe_algo,
+    2730                 :            :                 true);
+    2731                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+    2732                 :            :                                  &dhe_key_size);
+    2733                 :          1 :         final_key_size = sizeof(final_key);
+    2734                 :          1 :         libspdm_dhe_compute_key(
+    2735                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    2736                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    2737                 :            :             sizeof(spdm_key_exchange_request_t),
+    2738                 :            :             dhe_key_size, final_key, &final_key_size);
+    2739                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    2740                 :          1 :         ptr += dhe_key_size;
+    2741                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    2742                 :            :          * ptr += hash_size;*/
+    2743                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    2744                 :          1 :         ptr += sizeof(uint16_t);
+    2745                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    2746                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    2747                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+    2748                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    2749                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    2750                 :            :                                                         &data_size, NULL, NULL);
+    2751                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    2752                 :            :                          sizeof(m_libspdm_local_buffer)
+    2753                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    2754                 :            :                             m_libspdm_local_buffer),
+    2755                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    2756                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    2757                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    2758                 :            :                        m_libspdm_local_buffer_size));
+    2759                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    2760                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    2761                 :          1 :         cert_buffer =  (uint8_t *)data;
+    2762                 :          1 :         cert_buffer_size = data_size;
+    2763                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    2764                 :            :                          cert_buffer_hash);
+    2765                 :            :         /* transcript.message_a size is 0*/
+    2766                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    2767                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    2768                 :            :                                       m_libspdm_local_buffer_size);
+    2769                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2770                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2771                 :          1 :         free(data);
+    2772                 :          1 :         libspdm_responder_data_sign(
+    2773                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    2774                 :            :             spdm_context,
+    2775                 :            : #endif
+    2776                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    2777                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    2778                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    2779                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+    2780                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    2781                 :            :                 &signature_size);
+    2782                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    2783                 :            :                          sizeof(m_libspdm_local_buffer)
+    2784                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    2785                 :            :                             m_libspdm_local_buffer),
+    2786                 :            :                          ptr, signature_size);
+    2787                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+    2788                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    2789                 :          1 :         ptr += signature_size;
+    2790                 :            : 
+    2791                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    2792                 :            :                                               false, spdm_response_size,
+    2793                 :            :                                               spdm_response, response_size,
+    2794                 :            :                                               response);
+    2795                 :            :     }
+    2796                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    2797                 :            : 
+    2798                 :          1 :     case 0x14: {
+    2799                 :            :         spdm_key_exchange_response_t *spdm_response;
+    2800                 :            :         size_t dhe_key_size;
+    2801                 :            :         uint32_t hash_size;
+    2802                 :            :         size_t signature_size;
+    2803                 :            :         uint32_t hmac_size;
+    2804                 :            :         uint8_t *ptr;
+    2805                 :            :         void *dhe_context;
+    2806                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    2807                 :            :         size_t final_key_size;
+    2808                 :            :         size_t opaque_key_exchange_rsp_size;
+    2809                 :            :         void *data;
+    2810                 :            :         size_t data_size;
+    2811                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2812                 :            :         uint8_t *cert_buffer;
+    2813                 :            :         size_t cert_buffer_size;
+    2814                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    2815                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2816                 :            :         uint8_t bin_str0[128];
+    2817                 :            :         size_t bin_str0_size;
+    2818                 :            :         uint8_t bin_str2[128];
+    2819                 :            :         size_t bin_str2_size;
+    2820                 :            :         uint8_t bin_str7[128];
+    2821                 :            :         size_t bin_str7_size;
+    2822                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    2823                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    2824                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    2825                 :            :         size_t spdm_response_size;
+    2826                 :            :         size_t transport_header_size;
+    2827                 :            : 
+    2828                 :            :         ((libspdm_context_t *)spdm_context)
+    2829                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    2830                 :            :             m_libspdm_use_asym_algo;
+    2831                 :            :         ((libspdm_context_t *)spdm_context)
+    2832                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    2833                 :            :             m_libspdm_use_hash_algo;
+    2834                 :            :         ((libspdm_context_t *)spdm_context)
+    2835                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    2836                 :            :             m_libspdm_use_dhe_algo;
+    2837                 :            :         ((libspdm_context_t *)spdm_context)
+    2838                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    2839                 :            :             m_libspdm_use_measurement_hash_algo;
+    2840                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    2841                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2842                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2843                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    2844                 :          1 :         opaque_key_exchange_rsp_size =
+    2845                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    2846                 :            :                 spdm_context);
+    2847                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    2848                 :          1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
+    2849                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+    2850                 :            :                              hmac_size;
+    2851                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2852                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2853                 :          1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    2854                 :            : 
+    2855                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2856                 :          1 :         spdm_response->header.request_response_code =
+    2857                 :            :             SPDM_KEY_EXCHANGE_RSP;
+    2858                 :          1 :         spdm_response->header.param1 = 5;
+    2859                 :          1 :         spdm_response->rsp_session_id =
+    2860                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
+    2861                 :          1 :         spdm_response->mut_auth_requested = 0;
+    2862                 :          1 :         spdm_response->req_slot_id_param = 0;
+    2863                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    2864                 :          1 :                                   spdm_response->random_data);
+    2865                 :          1 :         ptr = (void *)(spdm_response + 1);
+    2866                 :          1 :         dhe_context = libspdm_dhe_new(
+    2867                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    2868                 :            :                 m_libspdm_use_dhe_algo,
+    2869                 :            :                 true);
+    2870                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+    2871                 :            :                                  &dhe_key_size);
+    2872                 :          1 :         final_key_size = sizeof(final_key);
+    2873                 :          1 :         libspdm_dhe_compute_key(
+    2874                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    2875                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    2876                 :            :             sizeof(spdm_key_exchange_request_t),
+    2877                 :            :             dhe_key_size, final_key, &final_key_size);
+    2878                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    2879                 :          1 :         ptr += dhe_key_size;
+    2880                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    2881                 :            :          * ptr += hash_size;*/
+    2882                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    2883                 :          1 :         ptr += sizeof(uint16_t);
+    2884                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    2885                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    2886                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+    2887                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    2888                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    2889                 :            :                                                         &data_size, NULL, NULL);
+    2890                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    2891                 :            :                          sizeof(m_libspdm_local_buffer)
+    2892                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    2893                 :            :                             m_libspdm_local_buffer),
+    2894                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    2895                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    2896                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    2897                 :            :                        m_libspdm_local_buffer_size));
+    2898                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    2899                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    2900                 :          1 :         cert_buffer =  (uint8_t *)data;
+    2901                 :          1 :         cert_buffer_size = data_size;
+    2902                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    2903                 :            :                          cert_buffer_hash);
+    2904                 :            :         /* transcript.message_a size is 0*/
+    2905                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    2906                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    2907                 :            :                                       m_libspdm_local_buffer_size);
+    2908                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2909                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2910                 :          1 :         free(data);
+    2911                 :          1 :         libspdm_responder_data_sign(
+    2912                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    2913                 :            :             spdm_context,
+    2914                 :            : #endif
+    2915                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    2916                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    2917                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    2918                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+    2919                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    2920                 :            :                 &signature_size);
+    2921                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    2922                 :            :                          sizeof(m_libspdm_local_buffer)
+    2923                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    2924                 :            :                             m_libspdm_local_buffer),
+    2925                 :            :                          ptr, signature_size);
+    2926                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+    2927                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    2928                 :          1 :         ptr += signature_size;
+    2929                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2930                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    2931                 :            :                          th_curr_hash_data);
+    2932                 :          1 :         bin_str0_size = sizeof(bin_str0);
+    2933                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2934                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    2935                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    2936                 :            :                            &bin_str0_size);
+    2937                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    2938                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    2939                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    2940                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2941                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    2942                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    2943                 :            :                            bin_str2, &bin_str2_size);
+    2944                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    2945                 :            :                             bin_str2, bin_str2_size,
+    2946                 :            :                             response_handshake_secret, hash_size);
+    2947                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    2948                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2949                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    2950                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    2951                 :            :                            &bin_str7_size);
+    2952                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    2953                 :            :                             hash_size, bin_str7, bin_str7_size,
+    2954                 :            :                             response_finished_key, hash_size);
+    2955                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2956                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2957                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    2958                 :            :                          response_finished_key, hash_size, ptr);
+    2959                 :          1 :         ptr += hmac_size;
+    2960                 :            : 
+    2961                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    2962                 :            :                                               false, spdm_response_size,
+    2963                 :            :                                               spdm_response, response_size,
+    2964                 :            :                                               response);
+    2965                 :            :     }
+    2966                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    2967                 :            : 
+    2968                 :          1 :     case 0x15: {
+    2969                 :            :         spdm_key_exchange_response_t *spdm_response;
+    2970                 :            :         size_t dhe_key_size;
+    2971                 :            :         uint32_t hash_size;
+    2972                 :            :         size_t signature_size;
+    2973                 :            :         uint32_t hmac_size;
+    2974                 :            :         uint8_t *ptr;
+    2975                 :            :         void *dhe_context;
+    2976                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    2977                 :            :         size_t final_key_size;
+    2978                 :            :         size_t opaque_key_exchange_rsp_size;
+    2979                 :            :         void *data;
+    2980                 :            :         size_t data_size;
+    2981                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2982                 :            :         uint8_t *cert_buffer;
+    2983                 :            :         size_t cert_buffer_size;
+    2984                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    2985                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2986                 :            :         uint8_t bin_str0[128];
+    2987                 :            :         size_t bin_str0_size;
+    2988                 :            :         uint8_t bin_str2[128];
+    2989                 :            :         size_t bin_str2_size;
+    2990                 :            :         uint8_t bin_str7[128];
+    2991                 :            :         size_t bin_str7_size;
+    2992                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    2993                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    2994                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    2995                 :            :         size_t spdm_response_size;
+    2996                 :            :         size_t transport_header_size;
+    2997                 :            : 
+    2998                 :            :         ((libspdm_context_t *)spdm_context)
+    2999                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    3000                 :            :             m_libspdm_use_asym_algo;
+    3001                 :            :         ((libspdm_context_t *)spdm_context)
+    3002                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    3003                 :            :             m_libspdm_use_hash_algo;
+    3004                 :            :         ((libspdm_context_t *)spdm_context)
+    3005                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    3006                 :            :             m_libspdm_use_dhe_algo;
+    3007                 :            :         ((libspdm_context_t *)spdm_context)
+    3008                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    3009                 :            :             m_libspdm_use_measurement_hash_algo;
+    3010                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    3011                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3012                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3013                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    3014                 :          1 :         opaque_key_exchange_rsp_size =
+    3015                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    3016                 :            :                 spdm_context);
+    3017                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    3018                 :          1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
+    3019                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+    3020                 :            :                              hmac_size;
+    3021                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    3022                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    3023                 :          1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    3024                 :            : 
+    3025                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    3026                 :          1 :         spdm_response->header.request_response_code =
+    3027                 :            :             SPDM_KEY_EXCHANGE_RSP;
+    3028                 :          1 :         spdm_response->header.param1 = 5;
+    3029                 :          1 :         spdm_response->rsp_session_id =
+    3030                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
+    3031                 :          1 :         spdm_response->mut_auth_requested = 0;
+    3032                 :          1 :         spdm_response->req_slot_id_param = 0;
+    3033                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    3034                 :          1 :                                   spdm_response->random_data);
+    3035                 :          1 :         ptr = (void *)(spdm_response + 1);
+    3036                 :          1 :         dhe_context = libspdm_dhe_new(
+    3037                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    3038                 :            :                 m_libspdm_use_dhe_algo,
+    3039                 :            :                 true);
+    3040                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+    3041                 :            :                                  &dhe_key_size);
+    3042                 :          1 :         final_key_size = sizeof(final_key);
+    3043                 :          1 :         libspdm_dhe_compute_key(
+    3044                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    3045                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    3046                 :            :             sizeof(spdm_key_exchange_request_t),
+    3047                 :            :             dhe_key_size, final_key, &final_key_size);
+    3048                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    3049                 :          1 :         ptr += dhe_key_size;
+    3050                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    3051                 :            :          * ptr += hash_size;*/
+    3052                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    3053                 :          1 :         ptr += sizeof(uint16_t);
+    3054                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    3055                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    3056                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+    3057                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3058                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    3059                 :            :                                                         &data_size, NULL, NULL);
+    3060                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    3061                 :            :                          sizeof(m_libspdm_local_buffer)
+    3062                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    3063                 :            :                             m_libspdm_local_buffer),
+    3064                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    3065                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    3066                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    3067                 :            :                        m_libspdm_local_buffer_size));
+    3068                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    3069                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    3070                 :          1 :         cert_buffer = (uint8_t *)data;
+    3071                 :          1 :         cert_buffer_size = data_size;
+    3072                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    3073                 :            :                          cert_buffer_hash);
+    3074                 :            :         /* transcript.message_a size is 0*/
+    3075                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    3076                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    3077                 :            :                                       m_libspdm_local_buffer_size);
+    3078                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3079                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    3080                 :          1 :         free(data);
+    3081                 :          1 :         libspdm_responder_data_sign(
+    3082                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    3083                 :            :             spdm_context,
+    3084                 :            : #endif
+    3085                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    3086                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    3087                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    3088                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+    3089                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    3090                 :            :                 &signature_size);
+    3091                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    3092                 :            :                          sizeof(m_libspdm_local_buffer)
+    3093                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    3094                 :            :                             m_libspdm_local_buffer),
+    3095                 :            :                          ptr, signature_size);
+    3096                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+    3097                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    3098                 :          1 :         ptr += signature_size;
+    3099                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3100                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    3101                 :            :                          th_curr_hash_data);
+    3102                 :          1 :         bin_str0_size = sizeof(bin_str0);
+    3103                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    3104                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    3105                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    3106                 :            :                            &bin_str0_size);
+    3107                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    3108                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    3109                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    3110                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    3111                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    3112                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    3113                 :            :                            bin_str2, &bin_str2_size);
+    3114                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    3115                 :            :                             bin_str2, bin_str2_size,
+    3116                 :            :                             response_handshake_secret, hash_size);
+    3117                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    3118                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    3119                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    3120                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    3121                 :            :                            &bin_str7_size);
+    3122                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    3123                 :            :                             hash_size, bin_str7, bin_str7_size,
+    3124                 :            :                             response_finished_key, hash_size);
+    3125                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3126                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    3127                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    3128                 :            :                          response_finished_key, hash_size, ptr);
+    3129                 :          1 :         ptr += hmac_size;
+    3130                 :            : 
+    3131                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    3132                 :            :                                               false, spdm_response_size,
+    3133                 :            :                                               spdm_response, response_size,
+    3134                 :            :                                               response);
+    3135                 :            :     }
+    3136                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    3137                 :            : 
+    3138                 :          1 :     case 0x16: {
+    3139                 :            :         spdm_key_exchange_response_t *spdm_response;
+    3140                 :            :         size_t dhe_key_size;
+    3141                 :            :         uint32_t hash_size;
+    3142                 :            :         size_t signature_size;
+    3143                 :            :         uint32_t hmac_size;
+    3144                 :            :         uint8_t *ptr;
+    3145                 :            :         void *dhe_context;
+    3146                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    3147                 :            :         size_t final_key_size;
+    3148                 :            :         size_t opaque_key_exchange_rsp_size;
+    3149                 :            :         void *data;
+    3150                 :            :         size_t data_size;
+    3151                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    3152                 :            :         uint8_t *cert_buffer;
+    3153                 :            :         size_t cert_buffer_size;
+    3154                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    3155                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    3156                 :            :         uint8_t bin_str0[128];
+    3157                 :            :         size_t bin_str0_size;
+    3158                 :            :         uint8_t bin_str2[128];
+    3159                 :            :         size_t bin_str2_size;
+    3160                 :            :         uint8_t bin_str7[128];
+    3161                 :            :         size_t bin_str7_size;
+    3162                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    3163                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    3164                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    3165                 :            :         size_t spdm_response_size;
+    3166                 :            :         size_t transport_header_size;
+    3167                 :            : 
+    3168                 :            :         ((libspdm_context_t *)spdm_context)
+    3169                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    3170                 :            :             m_libspdm_use_asym_algo;
+    3171                 :            :         ((libspdm_context_t *)spdm_context)
+    3172                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    3173                 :            :             m_libspdm_use_hash_algo;
+    3174                 :            :         ((libspdm_context_t *)spdm_context)
+    3175                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    3176                 :            :             m_libspdm_use_dhe_algo;
+    3177                 :            :         ((libspdm_context_t *)spdm_context)
+    3178                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    3179                 :            :             m_libspdm_use_measurement_hash_algo;
+    3180                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    3181                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3182                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3183                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    3184                 :          1 :         opaque_key_exchange_rsp_size =
+    3185                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    3186                 :            :                 spdm_context);
+    3187                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    3188                 :          1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
+    3189                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+    3190                 :            :                              hmac_size;
+    3191                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    3192                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    3193                 :          1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    3194                 :            : 
+    3195                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    3196                 :          1 :         spdm_response->header.request_response_code =
+    3197                 :            :             SPDM_KEY_EXCHANGE_RSP;
+    3198                 :          1 :         spdm_response->header.param1 = 0;
+    3199                 :          1 :         spdm_response->rsp_session_id =
+    3200                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
+    3201                 :          1 :         spdm_response->mut_auth_requested = 0;
+    3202                 :          1 :         spdm_response->req_slot_id_param = 0;
+    3203                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    3204                 :          1 :                                   spdm_response->random_data);
+    3205                 :          1 :         ptr = (void *)(spdm_response + 1);
+    3206                 :          1 :         dhe_context = libspdm_dhe_new(
+    3207                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    3208                 :            :                 m_libspdm_use_dhe_algo,
+    3209                 :            :                 true);
+    3210                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+    3211                 :            :                                  &dhe_key_size);
+    3212                 :          1 :         final_key_size = sizeof(final_key);
+    3213                 :          1 :         libspdm_dhe_compute_key(
+    3214                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    3215                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    3216                 :            :             sizeof(spdm_key_exchange_request_t),
+    3217                 :            :             dhe_key_size, final_key, &final_key_size);
+    3218                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    3219                 :          1 :         ptr += dhe_key_size;
+    3220                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    3221                 :            :          * ptr += hash_size;*/
+    3222                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    3223                 :          1 :         ptr += sizeof(uint16_t);
+    3224                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    3225                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    3226                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+    3227                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3228                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    3229                 :            :                                                         &data_size, NULL, NULL);
+    3230                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    3231                 :            :                          sizeof(m_libspdm_local_buffer)
+    3232                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    3233                 :            :                             m_libspdm_local_buffer),
+    3234                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    3235                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    3236                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    3237                 :            :                        m_libspdm_local_buffer_size));
+    3238                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    3239                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    3240                 :          1 :         cert_buffer =  (uint8_t *)data;
+    3241                 :          1 :         cert_buffer_size = data_size;
+    3242                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    3243                 :            :                          cert_buffer_hash);
+    3244                 :            :         /* transcript.message_a size is 0*/
+    3245                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    3246                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    3247                 :            :                                       m_libspdm_local_buffer_size);
+    3248                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3249                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    3250                 :          1 :         free(data);
+    3251                 :          1 :         libspdm_responder_data_sign(
+    3252                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    3253                 :            :             spdm_context,
+    3254                 :            : #endif
+    3255                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    3256                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    3257                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    3258                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+    3259                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    3260                 :            :                 &signature_size);
+    3261                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    3262                 :            :                          sizeof(m_libspdm_local_buffer)
+    3263                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    3264                 :            :                             m_libspdm_local_buffer),
+    3265                 :            :                          ptr, signature_size);
+    3266                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+    3267                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    3268                 :          1 :         ptr += signature_size;
+    3269                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3270                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    3271                 :            :                          th_curr_hash_data);
+    3272                 :          1 :         bin_str0_size = sizeof(bin_str0);
+    3273                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    3274                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    3275                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    3276                 :            :                            &bin_str0_size);
+    3277                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    3278                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    3279                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    3280                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    3281                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    3282                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    3283                 :            :                            bin_str2, &bin_str2_size);
+    3284                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    3285                 :            :                             bin_str2, bin_str2_size,
+    3286                 :            :                             response_handshake_secret, hash_size);
+    3287                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    3288                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    3289                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    3290                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    3291                 :            :                            &bin_str7_size);
+    3292                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    3293                 :            :                             hash_size, bin_str7, bin_str7_size,
+    3294                 :            :                             response_finished_key, hash_size);
+    3295                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3296                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    3297                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    3298                 :            :                          response_finished_key, hash_size, ptr);
+    3299                 :          1 :         ptr += hmac_size;
+    3300                 :            : 
+    3301                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    3302                 :            :                                               false, spdm_response_size,
+    3303                 :            :                                               spdm_response, response_size,
+    3304                 :            :                                               response);
+    3305                 :            :     }
+    3306                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    3307                 :            : 
+    3308                 :          1 :     case 0x17: {
+    3309                 :            :         spdm_key_exchange_response_t *spdm_response;
+    3310                 :            :         size_t dhe_key_size;
+    3311                 :            :         uint32_t hash_size;
+    3312                 :            :         size_t signature_size;
+    3313                 :            :         uint32_t hmac_size;
+    3314                 :            :         uint8_t *ptr;
+    3315                 :            :         void *dhe_context;
+    3316                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    3317                 :            :         size_t final_key_size;
+    3318                 :            :         size_t opaque_key_exchange_rsp_size;
+    3319                 :            :         void *data;
+    3320                 :            :         size_t data_size;
+    3321                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    3322                 :            :         uint8_t *cert_buffer;
+    3323                 :            :         size_t cert_buffer_size;
+    3324                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    3325                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    3326                 :            :         uint8_t bin_str0[128];
+    3327                 :            :         size_t bin_str0_size;
+    3328                 :            :         uint8_t bin_str2[128];
+    3329                 :            :         size_t bin_str2_size;
+    3330                 :            :         uint8_t bin_str7[128];
+    3331                 :            :         size_t bin_str7_size;
+    3332                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    3333                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    3334                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    3335                 :            :         size_t spdm_response_size;
+    3336                 :            :         size_t transport_header_size;
+    3337                 :            : 
+    3338                 :            :         ((libspdm_context_t *)spdm_context)
+    3339                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    3340                 :            :             m_libspdm_use_asym_algo;
+    3341                 :            :         ((libspdm_context_t *)spdm_context)
+    3342                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    3343                 :            :             m_libspdm_use_hash_algo;
+    3344                 :            :         ((libspdm_context_t *)spdm_context)
+    3345                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    3346                 :            :             m_libspdm_use_dhe_algo;
+    3347                 :            :         ((libspdm_context_t *)spdm_context)
+    3348                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    3349                 :            :             m_libspdm_use_measurement_hash_algo;
+    3350                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    3351                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3352                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3353                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    3354                 :          1 :         opaque_key_exchange_rsp_size =
+    3355                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    3356                 :            :                 spdm_context);
+    3357                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    3358                 :          1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
+    3359                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+    3360                 :            :                              hmac_size;
+    3361                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    3362                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    3363                 :          1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    3364                 :            : 
+    3365                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    3366                 :          1 :         spdm_response->header.request_response_code =
+    3367                 :            :             SPDM_KEY_EXCHANGE_RSP;
+    3368                 :          1 :         spdm_response->header.param1 = 0;
+    3369                 :          1 :         spdm_response->rsp_session_id =
+    3370                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
+    3371                 :          1 :         spdm_response->mut_auth_requested =
+    3372                 :            :             SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED;
+    3373                 :          1 :         spdm_response->req_slot_id_param = 0xF;
+    3374                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    3375                 :          1 :                                   spdm_response->random_data);
+    3376                 :          1 :         ptr = (void *)(spdm_response + 1);
+    3377                 :          1 :         dhe_context = libspdm_dhe_new(
+    3378                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    3379                 :            :                 m_libspdm_use_dhe_algo,
+    3380                 :            :                 true);
+    3381                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+    3382                 :            :                                  &dhe_key_size);
+    3383                 :          1 :         final_key_size = sizeof(final_key);
+    3384                 :          1 :         libspdm_dhe_compute_key(
+    3385                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    3386                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    3387                 :            :             sizeof(spdm_key_exchange_request_t),
+    3388                 :            :             dhe_key_size, final_key, &final_key_size);
+    3389                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    3390                 :          1 :         ptr += dhe_key_size;
+    3391                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    3392                 :            :          * ptr += hash_size;*/
+    3393                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    3394                 :          1 :         ptr += sizeof(uint16_t);
+    3395                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    3396                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    3397                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+    3398                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3399                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    3400                 :            :                                                         &data_size, NULL, NULL);
+    3401                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    3402                 :            :                          sizeof(m_libspdm_local_buffer)
+    3403                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    3404                 :            :                             m_libspdm_local_buffer),
+    3405                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    3406                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    3407                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    3408                 :            :                        m_libspdm_local_buffer_size));
+    3409                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    3410                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    3411                 :          1 :         cert_buffer =  (uint8_t *)data;
+    3412                 :          1 :         cert_buffer_size = data_size;
+    3413                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    3414                 :            :                          cert_buffer_hash);
+    3415                 :            :         /* transcript.message_a size is 0*/
+    3416                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    3417                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    3418                 :            :                                       m_libspdm_local_buffer_size);
+    3419                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3420                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    3421                 :          1 :         free(data);
+    3422                 :          1 :         libspdm_responder_data_sign(
+    3423                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    3424                 :            :             spdm_context,
+    3425                 :            : #endif
+    3426                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    3427                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    3428                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    3429                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+    3430                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    3431                 :            :                 &signature_size);
+    3432                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    3433                 :            :                          sizeof(m_libspdm_local_buffer)
+    3434                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    3435                 :            :                             m_libspdm_local_buffer),
+    3436                 :            :                          ptr, signature_size);
+    3437                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+    3438                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    3439                 :          1 :         ptr += signature_size;
+    3440                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3441                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    3442                 :            :                          th_curr_hash_data);
+    3443                 :          1 :         bin_str0_size = sizeof(bin_str0);
+    3444                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    3445                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    3446                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    3447                 :            :                            &bin_str0_size);
+    3448                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    3449                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    3450                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    3451                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    3452                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    3453                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    3454                 :            :                            bin_str2, &bin_str2_size);
+    3455                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    3456                 :            :                             bin_str2, bin_str2_size,
+    3457                 :            :                             response_handshake_secret, hash_size);
+    3458                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    3459                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    3460                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    3461                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    3462                 :            :                            &bin_str7_size);
+    3463                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    3464                 :            :                             hash_size, bin_str7, bin_str7_size,
+    3465                 :            :                             response_finished_key, hash_size);
+    3466                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3467                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    3468                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    3469                 :            :                          response_finished_key, hash_size, ptr);
+    3470                 :          1 :         ptr += hmac_size;
+    3471                 :            : 
+    3472                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    3473                 :            :                                               false, spdm_response_size,
+    3474                 :            :                                               spdm_response, response_size,
+    3475                 :            :                                               response);
+    3476                 :            :     }
+    3477                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    3478                 :            : 
+    3479                 :          1 :     case 0x18: {
+    3480                 :            :         spdm_key_exchange_response_t *spdm_response;
+    3481                 :            :         size_t dhe_key_size;
+    3482                 :            :         uint32_t hash_size;
+    3483                 :            :         size_t signature_size;
+    3484                 :            :         uint32_t hmac_size;
+    3485                 :            :         uint8_t *ptr;
+    3486                 :            :         void *dhe_context;
+    3487                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    3488                 :            :         size_t final_key_size;
+    3489                 :            :         size_t opaque_key_exchange_rsp_size;
+    3490                 :            :         void *data;
+    3491                 :            :         size_t data_size;
+    3492                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    3493                 :            :         uint8_t *cert_buffer;
+    3494                 :            :         size_t cert_buffer_size;
+    3495                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    3496                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    3497                 :            :         uint8_t bin_str0[128];
+    3498                 :            :         size_t bin_str0_size;
+    3499                 :            :         uint8_t bin_str2[128];
+    3500                 :            :         size_t bin_str2_size;
+    3501                 :            :         uint8_t bin_str7[128];
+    3502                 :            :         size_t bin_str7_size;
+    3503                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    3504                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    3505                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    3506                 :            :         size_t spdm_response_size;
+    3507                 :            :         size_t transport_header_size;
+    3508                 :            : 
+    3509                 :            :         ((libspdm_context_t *)spdm_context)
+    3510                 :          1 :         ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    3511                 :            :         ((libspdm_context_t *)spdm_context)
+    3512                 :          1 :         ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    3513                 :            :         ((libspdm_context_t *)spdm_context)
+    3514                 :          1 :         ->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    3515                 :            :         ((libspdm_context_t *)spdm_context)
+    3516                 :          1 :         ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+    3517                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    3518                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3519                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3520                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    3521                 :          1 :         opaque_key_exchange_rsp_size =
+    3522                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(spdm_context);
+    3523                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    3524                 :          1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
+    3525                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+    3526                 :            :                              hmac_size;
+    3527                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    3528                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    3529                 :          1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    3530                 :            : 
+    3531                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    3532                 :          1 :         spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
+    3533                 :          1 :         spdm_response->header.param1 = 0x0;
+    3534                 :          1 :         spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
+    3535                 :          1 :         spdm_response->mut_auth_requested =
+    3536                 :            :             SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_ENCAP_REQUEST;
+    3537                 :          1 :         spdm_response->req_slot_id_param = 0x0;
+    3538                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_response->random_data);
+    3539                 :          1 :         ptr = (void *)(spdm_response + 1);
+    3540                 :          1 :         dhe_context = libspdm_dhe_new(
+    3541                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    3542                 :            :                 m_libspdm_use_dhe_algo, true);
+    3543                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
+    3544                 :          1 :         final_key_size = sizeof(final_key);
+    3545                 :          1 :         libspdm_dhe_compute_key(
+    3546                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    3547                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    3548                 :            :             sizeof(spdm_key_exchange_request_t),
+    3549                 :            :             dhe_key_size, final_key, &final_key_size);
+    3550                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    3551                 :          1 :         ptr += dhe_key_size;
+    3552                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    3553                 :            :          * ptr += hash_size;*/
+    3554                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    3555                 :          1 :         ptr += sizeof(uint16_t);
+    3556                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    3557                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    3558                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+    3559                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3560                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    3561                 :            :                                                         &data_size, NULL, NULL);
+    3562                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    3563                 :            :                          sizeof(m_libspdm_local_buffer)
+    3564                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    3565                 :            :                             m_libspdm_local_buffer),
+    3566                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    3567                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    3568                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    3569                 :            :                        m_libspdm_local_buffer_size));
+    3570                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    3571                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    3572                 :          1 :         cert_buffer =  (uint8_t *)data;
+    3573                 :          1 :         cert_buffer_size = data_size;
+    3574                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    3575                 :            :                          cert_buffer_hash);
+    3576                 :            :         /* transcript.message_a size is 0*/
+    3577                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    3578                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    3579                 :            :                                       m_libspdm_local_buffer_size);
+    3580                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3581                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    3582                 :          1 :         free(data);
+    3583                 :          1 :         libspdm_responder_data_sign(
+    3584                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    3585                 :            :             spdm_context,
+    3586                 :            : #endif
+    3587                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    3588                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    3589                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    3590                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+    3591                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    3592                 :            :                 &signature_size);
+    3593                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    3594                 :            :                          sizeof(m_libspdm_local_buffer)
+    3595                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    3596                 :            :                             m_libspdm_local_buffer),
+    3597                 :            :                          ptr, signature_size);
+    3598                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+    3599                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    3600                 :          1 :         ptr += signature_size;
+    3601                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3602                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    3603                 :            :                          th_curr_hash_data);
+    3604                 :          1 :         bin_str0_size = sizeof(bin_str0);
+    3605                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    3606                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    3607                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    3608                 :            :                            &bin_str0_size);
+    3609                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    3610                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    3611                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    3612                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    3613                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    3614                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    3615                 :            :                            bin_str2, &bin_str2_size);
+    3616                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    3617                 :            :                             bin_str2, bin_str2_size,
+    3618                 :            :                             response_handshake_secret, hash_size);
+    3619                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    3620                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    3621                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    3622                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    3623                 :            :                            &bin_str7_size);
+    3624                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    3625                 :            :                             hash_size, bin_str7, bin_str7_size,
+    3626                 :            :                             response_finished_key, hash_size);
+    3627                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3628                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    3629                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    3630                 :            :                          response_finished_key, hash_size, ptr);
+    3631                 :          1 :         ptr += hmac_size;
+    3632                 :            : 
+    3633                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    3634                 :            :                                               false, spdm_response_size,
+    3635                 :            :                                               spdm_response, response_size,
+    3636                 :            :                                               response);
+    3637                 :            :     }
+    3638                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    3639                 :            : 
+    3640                 :          1 :     case 0x19: {
+    3641                 :            :         spdm_key_exchange_response_t *spdm_response;
+    3642                 :            :         size_t dhe_key_size;
+    3643                 :            :         uint32_t hash_size;
+    3644                 :            :         size_t signature_size;
+    3645                 :            :         uint32_t hmac_size;
+    3646                 :            :         uint8_t *ptr;
+    3647                 :            :         void *dhe_context;
+    3648                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    3649                 :            :         size_t final_key_size;
+    3650                 :            :         size_t opaque_key_exchange_rsp_size;
+    3651                 :            :         void *data;
+    3652                 :            :         size_t data_size;
+    3653                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    3654                 :            :         uint8_t *cert_buffer;
+    3655                 :            :         size_t cert_buffer_size;
+    3656                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    3657                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    3658                 :            :         uint8_t bin_str0[128];
+    3659                 :            :         size_t bin_str0_size;
+    3660                 :            :         uint8_t bin_str2[128];
+    3661                 :            :         size_t bin_str2_size;
+    3662                 :            :         uint8_t bin_str7[128];
+    3663                 :            :         size_t bin_str7_size;
+    3664                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    3665                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    3666                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    3667                 :            :         size_t spdm_response_size;
+    3668                 :            :         size_t transport_header_size;
+    3669                 :            : 
+    3670                 :            :         ((libspdm_context_t *)spdm_context)
+    3671                 :          1 :         ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    3672                 :            :         ((libspdm_context_t *)spdm_context)
+    3673                 :          1 :         ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    3674                 :            :         ((libspdm_context_t *)spdm_context)
+    3675                 :          1 :         ->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    3676                 :            :         ((libspdm_context_t *)spdm_context)
+    3677                 :          1 :         ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+    3678                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    3679                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3680                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3681                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    3682                 :          1 :         opaque_key_exchange_rsp_size =
+    3683                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(spdm_context);
+    3684                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    3685                 :          1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
+    3686                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+    3687                 :            :                              hmac_size;
+    3688                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    3689                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    3690                 :          1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    3691                 :            : 
+    3692                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    3693                 :          1 :         spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
+    3694                 :          1 :         spdm_response->header.param1 = 0;
+    3695                 :          1 :         spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
+    3696                 :          1 :         spdm_response->mut_auth_requested =
+    3697                 :            :             SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_GET_DIGESTS;
+    3698                 :          1 :         spdm_response->req_slot_id_param = 0;
+    3699                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    3700                 :          1 :                                   spdm_response->random_data);
+    3701                 :          1 :         ptr = (void *)(spdm_response + 1);
+    3702                 :          1 :         dhe_context = libspdm_dhe_new(
+    3703                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    3704                 :            :                 m_libspdm_use_dhe_algo, true);
+    3705                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
+    3706                 :          1 :         final_key_size = sizeof(final_key);
+    3707                 :          1 :         libspdm_dhe_compute_key(
+    3708                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    3709                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    3710                 :            :             sizeof(spdm_key_exchange_request_t),
+    3711                 :            :             dhe_key_size, final_key, &final_key_size);
+    3712                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    3713                 :          1 :         ptr += dhe_key_size;
+    3714                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    3715                 :            :          * ptr += hash_size;*/
+    3716                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    3717                 :          1 :         ptr += sizeof(uint16_t);
+    3718                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    3719                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    3720                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+    3721                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3722                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    3723                 :            :                                                         &data_size, NULL, NULL);
+    3724                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    3725                 :            :                          sizeof(m_libspdm_local_buffer)
+    3726                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    3727                 :            :                             m_libspdm_local_buffer),
+    3728                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    3729                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    3730                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    3731                 :            :                        m_libspdm_local_buffer_size));
+    3732                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    3733                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    3734                 :          1 :         cert_buffer =  (uint8_t *)data;
+    3735                 :          1 :         cert_buffer_size = data_size;
+    3736                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    3737                 :            :                          cert_buffer_hash);
+    3738                 :            :         /* transcript.message_a size is 0*/
+    3739                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    3740                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    3741                 :            :                                       m_libspdm_local_buffer_size);
+    3742                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3743                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    3744                 :          1 :         free(data);
+    3745                 :          1 :         libspdm_responder_data_sign(
+    3746                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    3747                 :            :             spdm_context,
+    3748                 :            : #endif
+    3749                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    3750                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    3751                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    3752                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+    3753                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    3754                 :            :                 &signature_size);
+    3755                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    3756                 :            :                          sizeof(m_libspdm_local_buffer)
+    3757                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    3758                 :            :                             m_libspdm_local_buffer),
+    3759                 :            :                          ptr, signature_size);
+    3760                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+    3761                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    3762                 :          1 :         ptr += signature_size;
+    3763                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3764                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    3765                 :            :                          th_curr_hash_data);
+    3766                 :          1 :         bin_str0_size = sizeof(bin_str0);
+    3767                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    3768                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    3769                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    3770                 :            :                            &bin_str0_size);
+    3771                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    3772                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    3773                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    3774                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    3775                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    3776                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    3777                 :            :                            bin_str2, &bin_str2_size);
+    3778                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    3779                 :            :                             bin_str2, bin_str2_size,
+    3780                 :            :                             response_handshake_secret, hash_size);
+    3781                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    3782                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    3783                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    3784                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    3785                 :            :                            &bin_str7_size);
+    3786                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    3787                 :            :                             hash_size, bin_str7, bin_str7_size,
+    3788                 :            :                             response_finished_key, hash_size);
+    3789                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3790                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    3791                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    3792                 :            :                          response_finished_key, hash_size, ptr);
+    3793                 :          1 :         ptr += hmac_size;
+    3794                 :            : 
+    3795                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    3796                 :            :                                               false, spdm_response_size,
+    3797                 :            :                                               spdm_response, response_size,
+    3798                 :            :                                               response);
+    3799                 :            :     }
+    3800                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    3801                 :            : 
+    3802                 :          1 :     case 0x1A: {
+    3803                 :            :         spdm_key_exchange_response_t *spdm_response;
+    3804                 :            :         size_t dhe_key_size;
+    3805                 :            :         uint32_t hash_size;
+    3806                 :            :         size_t signature_size;
+    3807                 :            :         uint32_t hmac_size;
+    3808                 :            :         uint8_t *ptr;
+    3809                 :            :         void *dhe_context;
+    3810                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    3811                 :            :         size_t final_key_size;
+    3812                 :            :         size_t opaque_key_exchange_rsp_size;
+    3813                 :            :         void *data;
+    3814                 :            :         size_t data_size;
+    3815                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    3816                 :            :         uint8_t *cert_buffer;
+    3817                 :            :         size_t cert_buffer_size;
+    3818                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    3819                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    3820                 :            :         uint8_t bin_str0[128];
+    3821                 :            :         size_t bin_str0_size;
+    3822                 :            :         uint8_t bin_str2[128];
+    3823                 :            :         size_t bin_str2_size;
+    3824                 :            :         uint8_t bin_str7[128];
+    3825                 :            :         size_t bin_str7_size;
+    3826                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    3827                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    3828                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    3829                 :            :         size_t spdm_response_size;
+    3830                 :            :         size_t transport_header_size;
+    3831                 :            : 
+    3832                 :            :         ((libspdm_context_t *)spdm_context)
+    3833                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    3834                 :            :             m_libspdm_use_asym_algo;
+    3835                 :            :         ((libspdm_context_t *)spdm_context)
+    3836                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    3837                 :            :             m_libspdm_use_hash_algo;
+    3838                 :            :         ((libspdm_context_t *)spdm_context)
+    3839                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    3840                 :            :             m_libspdm_use_dhe_algo;
+    3841                 :            :         ((libspdm_context_t *)spdm_context)
+    3842                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    3843                 :            :             m_libspdm_use_measurement_hash_algo;
+    3844                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    3845                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3846                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3847                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    3848                 :          1 :         opaque_key_exchange_rsp_size =
+    3849                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    3850                 :            :                 spdm_context);
+    3851                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    3852                 :          1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
+    3853                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+    3854                 :            :                              hmac_size;
+    3855                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    3856                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    3857                 :          1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    3858                 :            : 
+    3859                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    3860                 :          1 :         spdm_response->header.request_response_code =
+    3861                 :            :             SPDM_KEY_EXCHANGE_RSP;
+    3862                 :          1 :         spdm_response->header.param1 = 0;
+    3863                 :          1 :         spdm_response->rsp_session_id =
+    3864                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
+    3865                 :          1 :         spdm_response->mut_auth_requested =
+    3866                 :            :             SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED |
+    3867                 :            :             SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_ENCAP_REQUEST;
+    3868                 :          1 :         spdm_response->req_slot_id_param = 0xF;
+    3869                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    3870                 :          1 :                                   spdm_response->random_data);
+    3871                 :          1 :         ptr = (void *)(spdm_response + 1);
+    3872                 :          1 :         dhe_context = libspdm_dhe_new(
+    3873                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    3874                 :            :                 m_libspdm_use_dhe_algo,
+    3875                 :            :                 true);
+    3876                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+    3877                 :            :                                  &dhe_key_size);
+    3878                 :          1 :         final_key_size = sizeof(final_key);
+    3879                 :          1 :         libspdm_dhe_compute_key(
+    3880                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    3881                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    3882                 :            :             sizeof(spdm_key_exchange_request_t),
+    3883                 :            :             dhe_key_size, final_key, &final_key_size);
+    3884                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    3885                 :          1 :         ptr += dhe_key_size;
+    3886                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    3887                 :            :          * ptr += hash_size;*/
+    3888                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    3889                 :          1 :         ptr += sizeof(uint16_t);
+    3890                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    3891                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    3892                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+    3893                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3894                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    3895                 :            :                                                         &data_size, NULL, NULL);
+    3896                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    3897                 :            :                          sizeof(m_libspdm_local_buffer)
+    3898                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    3899                 :            :                             m_libspdm_local_buffer),
+    3900                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    3901                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    3902                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    3903                 :            :                        m_libspdm_local_buffer_size));
+    3904                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    3905                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    3906                 :          1 :         cert_buffer =  (uint8_t *)data;
+    3907                 :          1 :         cert_buffer_size = data_size;
+    3908                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    3909                 :            :                          cert_buffer_hash);
+    3910                 :            :         /* transcript.message_a size is 0*/
+    3911                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    3912                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    3913                 :            :                                       m_libspdm_local_buffer_size);
+    3914                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3915                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    3916                 :          1 :         free(data);
+    3917                 :          1 :         libspdm_responder_data_sign(
+    3918                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    3919                 :            :             spdm_context,
+    3920                 :            : #endif
+    3921                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    3922                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    3923                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    3924                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+    3925                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    3926                 :            :                 &signature_size);
+    3927                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    3928                 :            :                          sizeof(m_libspdm_local_buffer)
+    3929                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    3930                 :            :                             m_libspdm_local_buffer),
+    3931                 :            :                          ptr, signature_size);
+    3932                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+    3933                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    3934                 :          1 :         ptr += signature_size;
+    3935                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3936                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    3937                 :            :                          th_curr_hash_data);
+    3938                 :          1 :         bin_str0_size = sizeof(bin_str0);
+    3939                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    3940                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    3941                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    3942                 :            :                            &bin_str0_size);
+    3943                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    3944                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    3945                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    3946                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    3947                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    3948                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    3949                 :            :                            bin_str2, &bin_str2_size);
+    3950                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    3951                 :            :                             bin_str2, bin_str2_size,
+    3952                 :            :                             response_handshake_secret, hash_size);
+    3953                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    3954                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    3955                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    3956                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    3957                 :            :                            &bin_str7_size);
+    3958                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    3959                 :            :                             hash_size, bin_str7, bin_str7_size,
+    3960                 :            :                             response_finished_key, hash_size);
+    3961                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3962                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    3963                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    3964                 :            :                          response_finished_key, hash_size, ptr);
+    3965                 :          1 :         ptr += hmac_size;
+    3966                 :            : 
+    3967                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    3968                 :            :                                               false, spdm_response_size,
+    3969                 :            :                                               spdm_response, response_size,
+    3970                 :            :                                               response);
+    3971                 :            :     }
+    3972                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    3973                 :            : 
+    3974                 :          1 :     case 0x1B: {
+    3975                 :            :         spdm_key_exchange_response_t *spdm_response;
+    3976                 :            :         size_t dhe_key_size;
+    3977                 :            :         uint32_t hash_size;
+    3978                 :            :         size_t signature_size;
+    3979                 :            :         uint32_t hmac_size;
+    3980                 :            :         uint8_t *ptr;
+    3981                 :            :         void *dhe_context;
+    3982                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    3983                 :            :         size_t final_key_size;
+    3984                 :            :         size_t opaque_key_exchange_rsp_size;
+    3985                 :            :         void *data;
+    3986                 :            :         size_t data_size;
+    3987                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    3988                 :            :         uint8_t *cert_buffer;
+    3989                 :            :         size_t cert_buffer_size;
+    3990                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    3991                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    3992                 :            :         uint8_t bin_str0[128];
+    3993                 :            :         size_t bin_str0_size;
+    3994                 :            :         uint8_t bin_str2[128];
+    3995                 :            :         size_t bin_str2_size;
+    3996                 :            :         uint8_t bin_str7[128];
+    3997                 :            :         size_t bin_str7_size;
+    3998                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    3999                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    4000                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    4001                 :            :         size_t spdm_response_size;
+    4002                 :            :         size_t transport_header_size;
+    4003                 :            : 
+    4004                 :            :         ((libspdm_context_t *)spdm_context)
+    4005                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    4006                 :            :             m_libspdm_use_asym_algo;
+    4007                 :            :         ((libspdm_context_t *)spdm_context)
+    4008                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    4009                 :            :             m_libspdm_use_hash_algo;
+    4010                 :            :         ((libspdm_context_t *)spdm_context)
+    4011                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    4012                 :            :             m_libspdm_use_dhe_algo;
+    4013                 :            :         ((libspdm_context_t *)spdm_context)
+    4014                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    4015                 :            :             m_libspdm_use_measurement_hash_algo;
+    4016                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    4017                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    4018                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    4019                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    4020                 :          1 :         opaque_key_exchange_rsp_size =
+    4021                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    4022                 :            :                 spdm_context);
+    4023                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    4024                 :          1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
+    4025                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+    4026                 :            :                              hmac_size;
+    4027                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    4028                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    4029                 :          1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    4030                 :            : 
+    4031                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    4032                 :          1 :         spdm_response->header.request_response_code =
+    4033                 :            :             SPDM_KEY_EXCHANGE_RSP;
+    4034                 :          1 :         spdm_response->header.param1 = 0;
+    4035                 :          1 :         spdm_response->rsp_session_id =
+    4036                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
+    4037                 :          1 :         spdm_response->mut_auth_requested =
+    4038                 :            :             SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED |
+    4039                 :            :             SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_GET_DIGESTS;
+    4040                 :          1 :         spdm_response->req_slot_id_param = 0xF;
+    4041                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    4042                 :          1 :                                   spdm_response->random_data);
+    4043                 :          1 :         ptr = (void *)(spdm_response + 1);
+    4044                 :          1 :         dhe_context = libspdm_dhe_new(
+    4045                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    4046                 :            :                 m_libspdm_use_dhe_algo,
+    4047                 :            :                 true);
+    4048                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+    4049                 :            :                                  &dhe_key_size);
+    4050                 :          1 :         final_key_size = sizeof(final_key);
+    4051                 :          1 :         libspdm_dhe_compute_key(
+    4052                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    4053                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    4054                 :            :             sizeof(spdm_key_exchange_request_t),
+    4055                 :            :             dhe_key_size, final_key, &final_key_size);
+    4056                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    4057                 :          1 :         ptr += dhe_key_size;
+    4058                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    4059                 :            :          * ptr += hash_size;*/
+    4060                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    4061                 :          1 :         ptr += sizeof(uint16_t);
+    4062                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    4063                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    4064                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+    4065                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    4066                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    4067                 :            :                                                         &data_size, NULL, NULL);
+    4068                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    4069                 :            :                          sizeof(m_libspdm_local_buffer)
+    4070                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    4071                 :            :                             m_libspdm_local_buffer),
+    4072                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    4073                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    4074                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    4075                 :            :                        m_libspdm_local_buffer_size));
+    4076                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    4077                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    4078                 :          1 :         cert_buffer =  (uint8_t *)data;
+    4079                 :          1 :         cert_buffer_size = data_size;
+    4080                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    4081                 :            :                          cert_buffer_hash);
+    4082                 :            :         /* transcript.message_a size is 0*/
+    4083                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    4084                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    4085                 :            :                                       m_libspdm_local_buffer_size);
+    4086                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    4087                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    4088                 :          1 :         free(data);
+    4089                 :          1 :         libspdm_responder_data_sign(
+    4090                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    4091                 :            :             spdm_context,
+    4092                 :            : #endif
+    4093                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    4094                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    4095                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    4096                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+    4097                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    4098                 :            :                 &signature_size);
+    4099                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    4100                 :            :                          sizeof(m_libspdm_local_buffer)
+    4101                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    4102                 :            :                             m_libspdm_local_buffer),
+    4103                 :            :                          ptr, signature_size);
+    4104                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+    4105                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    4106                 :          1 :         ptr += signature_size;
+    4107                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    4108                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    4109                 :            :                          th_curr_hash_data);
+    4110                 :          1 :         bin_str0_size = sizeof(bin_str0);
+    4111                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    4112                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    4113                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    4114                 :            :                            &bin_str0_size);
+    4115                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    4116                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    4117                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    4118                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    4119                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    4120                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    4121                 :            :                            bin_str2, &bin_str2_size);
+    4122                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    4123                 :            :                             bin_str2, bin_str2_size,
+    4124                 :            :                             response_handshake_secret, hash_size);
+    4125                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    4126                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    4127                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    4128                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    4129                 :            :                            &bin_str7_size);
+    4130                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    4131                 :            :                             hash_size, bin_str7, bin_str7_size,
+    4132                 :            :                             response_finished_key, hash_size);
+    4133                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    4134                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    4135                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    4136                 :            :                          response_finished_key, hash_size, ptr);
+    4137                 :          1 :         ptr += hmac_size;
+    4138                 :            : 
+    4139                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    4140                 :            :                                               false, spdm_response_size,
+    4141                 :            :                                               spdm_response, response_size,
+    4142                 :            :                                               response);
+    4143                 :            :     }
+    4144                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    4145                 :            : 
+    4146                 :          1 :     case 0x1C: {
+    4147                 :            :         spdm_key_exchange_response_t *spdm_response;
+    4148                 :            :         size_t dhe_key_size;
+    4149                 :            :         uint32_t hash_size;
+    4150                 :            :         size_t signature_size;
+    4151                 :            :         uint32_t hmac_size;
+    4152                 :            :         uint8_t *ptr;
+    4153                 :            :         void *dhe_context;
+    4154                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    4155                 :            :         size_t final_key_size;
+    4156                 :            :         size_t opaque_key_exchange_rsp_size;
+    4157                 :            :         void *data;
+    4158                 :            :         size_t data_size;
+    4159                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    4160                 :            :         uint8_t *cert_buffer;
+    4161                 :            :         size_t cert_buffer_size;
+    4162                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    4163                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    4164                 :            :         uint8_t bin_str0[128];
+    4165                 :            :         size_t bin_str0_size;
+    4166                 :            :         uint8_t bin_str2[128];
+    4167                 :            :         size_t bin_str2_size;
+    4168                 :            :         uint8_t bin_str7[128];
+    4169                 :            :         size_t bin_str7_size;
+    4170                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    4171                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    4172                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    4173                 :            :         size_t spdm_response_size;
+    4174                 :            :         size_t transport_header_size;
+    4175                 :            : 
+    4176                 :            :         ((libspdm_context_t *)spdm_context)
+    4177                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    4178                 :            :             m_libspdm_use_asym_algo;
+    4179                 :            :         ((libspdm_context_t *)spdm_context)
+    4180                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    4181                 :            :             m_libspdm_use_hash_algo;
+    4182                 :            :         ((libspdm_context_t *)spdm_context)
+    4183                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    4184                 :            :             m_libspdm_use_dhe_algo;
+    4185                 :            :         ((libspdm_context_t *)spdm_context)
+    4186                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    4187                 :            :             m_libspdm_use_measurement_hash_algo;
+    4188                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    4189                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    4190                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    4191                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    4192                 :          1 :         opaque_key_exchange_rsp_size =
+    4193                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    4194                 :            :                 spdm_context);
+    4195                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    4196                 :          1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
+    4197                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+    4198                 :            :                              hmac_size;
+    4199                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    4200                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    4201                 :          1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    4202                 :            : 
+    4203                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    4204                 :          1 :         spdm_response->header.request_response_code =
+    4205                 :            :             SPDM_KEY_EXCHANGE_RSP;
+    4206                 :          1 :         spdm_response->header.param1 = 0;
+    4207                 :          1 :         spdm_response->rsp_session_id =
+    4208                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
+    4209                 :          1 :         spdm_response->mut_auth_requested =
+    4210                 :            :             SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_ENCAP_REQUEST |
+    4211                 :            :             SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_GET_DIGESTS;
+    4212                 :          1 :         spdm_response->req_slot_id_param = 0xF;
+    4213                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    4214                 :          1 :                                   spdm_response->random_data);
+    4215                 :          1 :         ptr = (void *)(spdm_response + 1);
+    4216                 :          1 :         dhe_context = libspdm_dhe_new(
+    4217                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    4218                 :            :                 m_libspdm_use_dhe_algo,
+    4219                 :            :                 true);
+    4220                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+    4221                 :            :                                  &dhe_key_size);
+    4222                 :          1 :         final_key_size = sizeof(final_key);
+    4223                 :          1 :         libspdm_dhe_compute_key(
+    4224                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    4225                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    4226                 :            :             sizeof(spdm_key_exchange_request_t),
+    4227                 :            :             dhe_key_size, final_key, &final_key_size);
+    4228                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    4229                 :          1 :         ptr += dhe_key_size;
+    4230                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    4231                 :            :          * ptr += hash_size;*/
+    4232                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    4233                 :          1 :         ptr += sizeof(uint16_t);
+    4234                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    4235                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    4236                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+    4237                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    4238                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    4239                 :            :                                                         &data_size, NULL, NULL);
+    4240                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    4241                 :            :                          sizeof(m_libspdm_local_buffer)
+    4242                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    4243                 :            :                             m_libspdm_local_buffer),
+    4244                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    4245                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    4246                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    4247                 :            :                        m_libspdm_local_buffer_size));
+    4248                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    4249                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    4250                 :          1 :         cert_buffer =  (uint8_t *)data;
+    4251                 :          1 :         cert_buffer_size = data_size;
+    4252                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    4253                 :            :                          cert_buffer_hash);
+    4254                 :            :         /* transcript.message_a size is 0*/
+    4255                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    4256                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    4257                 :            :                                       m_libspdm_local_buffer_size);
+    4258                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    4259                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    4260                 :          1 :         free(data);
+    4261                 :          1 :         libspdm_responder_data_sign(
+    4262                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    4263                 :            :             spdm_context,
+    4264                 :            : #endif
+    4265                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    4266                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    4267                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    4268                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+    4269                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    4270                 :            :                 &signature_size);
+    4271                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    4272                 :            :                          sizeof(m_libspdm_local_buffer)
+    4273                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    4274                 :            :                             m_libspdm_local_buffer),
+    4275                 :            :                          ptr, signature_size);
+    4276                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+    4277                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    4278                 :          1 :         ptr += signature_size;
+    4279                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    4280                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    4281                 :            :                          th_curr_hash_data);
+    4282                 :          1 :         bin_str0_size = sizeof(bin_str0);
+    4283                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    4284                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    4285                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    4286                 :            :                            &bin_str0_size);
+    4287                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    4288                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    4289                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    4290                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    4291                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    4292                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    4293                 :            :                            bin_str2, &bin_str2_size);
+    4294                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    4295                 :            :                             bin_str2, bin_str2_size,
+    4296                 :            :                             response_handshake_secret, hash_size);
+    4297                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    4298                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    4299                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    4300                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    4301                 :            :                            &bin_str7_size);
+    4302                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    4303                 :            :                             hash_size, bin_str7, bin_str7_size,
+    4304                 :            :                             response_finished_key, hash_size);
+    4305                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    4306                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    4307                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    4308                 :            :                          response_finished_key, hash_size, ptr);
+    4309                 :          1 :         ptr += hmac_size;
+    4310                 :            : 
+    4311                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    4312                 :            :                                               false, spdm_response_size,
+    4313                 :            :                                               spdm_response, response_size,
+    4314                 :            :                                               response);
+    4315                 :            :     }
+    4316                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    4317                 :            : 
+    4318                 :          1 :     case 0x1D: {
+    4319                 :            :         spdm_key_exchange_response_t *spdm_response;
+    4320                 :            :         size_t dhe_key_size;
+    4321                 :            :         uint32_t hash_size;
+    4322                 :            :         size_t signature_size;
+    4323                 :            :         uint32_t hmac_size;
+    4324                 :            :         uint8_t *ptr;
+    4325                 :            :         void *dhe_context;
+    4326                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    4327                 :            :         size_t final_key_size;
+    4328                 :            :         size_t opaque_key_exchange_rsp_size;
+    4329                 :            :         void *data;
+    4330                 :            :         size_t data_size;
+    4331                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    4332                 :            :         uint8_t *cert_buffer;
+    4333                 :            :         size_t cert_buffer_size;
+    4334                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    4335                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    4336                 :            :         uint8_t bin_str0[128];
+    4337                 :            :         size_t bin_str0_size;
+    4338                 :            :         uint8_t bin_str2[128];
+    4339                 :            :         size_t bin_str2_size;
+    4340                 :            :         uint8_t bin_str7[128];
+    4341                 :            :         size_t bin_str7_size;
+    4342                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    4343                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    4344                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    4345                 :            :         size_t spdm_response_size;
+    4346                 :            :         size_t transport_header_size;
+    4347                 :            : 
+    4348                 :          1 :         ((libspdm_context_t *)spdm_context)->connection_info.algorithm.base_asym_algo =
+    4349                 :            :             m_libspdm_use_asym_algo;
+    4350                 :          1 :         ((libspdm_context_t *)spdm_context)->connection_info.algorithm.base_hash_algo =
+    4351                 :            :             m_libspdm_use_hash_algo;
+    4352                 :          1 :         ((libspdm_context_t *)spdm_context)->connection_info.algorithm.dhe_named_group =
+    4353                 :            :             m_libspdm_use_dhe_algo;
+    4354                 :          1 :         ((libspdm_context_t *)spdm_context)->connection_info.algorithm.measurement_hash_algo =
+    4355                 :            :             m_libspdm_use_measurement_hash_algo;
+    4356                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    4357                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    4358                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    4359                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    4360                 :          1 :         opaque_key_exchange_rsp_size =
+    4361                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(spdm_context);
+    4362                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    4363                 :          1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
+    4364                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+    4365                 :            :                              hmac_size;
+    4366                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    4367                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    4368                 :            : 
+    4369                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    4370                 :          1 :         spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
+    4371                 :          1 :         spdm_response->header.param1 = 0;
+    4372                 :          1 :         spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
+    4373                 :          1 :         spdm_response->mut_auth_requested = 0;
+    4374                 :          1 :         spdm_response->req_slot_id_param = 0;
+    4375                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_response->random_data);
+    4376                 :          1 :         ptr = (void *)(spdm_response + 1);
+    4377                 :          1 :         dhe_context = libspdm_dhe_new(
+    4378                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    4379                 :            :                 m_libspdm_use_dhe_algo, true);
+    4380                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
+    4381                 :          1 :         final_key_size = sizeof(final_key);
+    4382                 :          1 :         libspdm_dhe_compute_key(
+    4383                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    4384                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] + sizeof(spdm_key_exchange_request_t),
+    4385                 :            :             dhe_key_size, final_key, &final_key_size);
+    4386                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    4387                 :          1 :         ptr += dhe_key_size;
+    4388                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    4389                 :            :          * ptr += hash_size;*/
+    4390                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    4391                 :          1 :         ptr += sizeof(uint16_t);
+    4392                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    4393                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    4394                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+    4395                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    4396                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    4397                 :            :                                                         &data_size, NULL, NULL);
+    4398                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    4399                 :            :                          sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
+    4400                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    4401                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    4402                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer (0x%zx):\n",
+    4403                 :            :                        m_libspdm_local_buffer_size));
+    4404                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    4405                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    4406                 :          1 :         cert_buffer = (uint8_t *)data;
+    4407                 :          1 :         cert_buffer_size = data_size;
+    4408                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    4409                 :            :                          cert_buffer_hash);
+    4410                 :            :         /* transcript.message_a size is 0*/
+    4411                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    4412                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    4413                 :            :                                       m_libspdm_local_buffer_size);
+    4414                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    4415                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    4416                 :          1 :         free(data);
+    4417                 :          1 :         libspdm_responder_data_sign(
+    4418                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    4419                 :            :             spdm_context,
+    4420                 :            : #endif
+    4421                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    4422                 :            :                 SPDM_KEY_EXCHANGE_RSP, m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    4423                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+    4424                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr, &signature_size);
+    4425                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    4426                 :            :                          sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
+    4427                 :            :                          ptr, signature_size);
+    4428                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+    4429                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    4430                 :          1 :         ptr += signature_size;
+    4431                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    4432                 :            :                          libspdm_get_managed_buffer_size(&th_curr), th_curr_hash_data);
+    4433                 :          1 :         bin_str0_size = sizeof(bin_str0);
+    4434                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    4435                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    4436                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0, &bin_str0_size);
+    4437                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    4438                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    4439                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    4440                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    4441                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    4442                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    4443                 :            :                            bin_str2, &bin_str2_size);
+    4444                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    4445                 :            :                             bin_str2, bin_str2_size,
+    4446                 :            :                             response_handshake_secret, hash_size);
+    4447                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    4448                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    4449                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    4450                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    4451                 :            :                            &bin_str7_size);
+    4452                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    4453                 :            :                             hash_size, bin_str7, bin_str7_size,
+    4454                 :            :                             response_finished_key, hash_size);
+    4455                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    4456                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    4457                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    4458                 :            :                          response_finished_key, hash_size, ptr);
+    4459                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    4460                 :            :                          sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
+    4461                 :            :                          ptr, hmac_size);
+    4462                 :          1 :         m_libspdm_local_buffer_size += hmac_size;
+    4463                 :          1 :         ptr += hmac_size;
+    4464                 :            : 
+    4465                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    4466                 :            :                                               false, spdm_response_size,
+    4467                 :            :                                               spdm_response, response_size,
+    4468                 :            :                                               response);
+    4469                 :            :     }
+    4470                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    4471                 :          1 :     case 0x1E: {
+    4472                 :            :         spdm_key_exchange_response_t *spdm_response;
+    4473                 :            :         size_t dhe_key_size;
+    4474                 :            :         uint32_t hash_size;
+    4475                 :            :         size_t signature_size;
+    4476                 :            :         uint32_t hmac_size;
+    4477                 :            :         uint8_t *ptr;
+    4478                 :            :         void *dhe_context;
+    4479                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    4480                 :            :         size_t final_key_size;
+    4481                 :            :         size_t opaque_key_exchange_rsp_size;
+    4482                 :            :         void *data;
+    4483                 :            :         size_t data_size;
+    4484                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    4485                 :            :         uint8_t *cert_buffer;
+    4486                 :            :         size_t cert_buffer_size;
+    4487                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    4488                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    4489                 :            :         uint8_t bin_str0[128];
+    4490                 :            :         size_t bin_str0_size;
+    4491                 :            :         uint8_t bin_str2[128];
+    4492                 :            :         size_t bin_str2_size;
+    4493                 :            :         uint8_t bin_str7[128];
+    4494                 :            :         size_t bin_str7_size;
+    4495                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    4496                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    4497                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    4498                 :            :         size_t spdm_response_size;
+    4499                 :            :         size_t transport_header_size;
+    4500                 :            : 
+    4501                 :          1 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
+    4502                 :            :             SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4503                 :            :         ((libspdm_context_t *)spdm_context)
+    4504                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    4505                 :            :             m_libspdm_use_asym_algo;
+    4506                 :            :         ((libspdm_context_t *)spdm_context)
+    4507                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    4508                 :            :             m_libspdm_use_hash_algo;
+    4509                 :            :         ((libspdm_context_t *)spdm_context)
+    4510                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    4511                 :            :             m_libspdm_use_dhe_algo;
+    4512                 :            :         ((libspdm_context_t *)spdm_context)
+    4513                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    4514                 :            :             m_libspdm_use_measurement_hash_algo;
+    4515                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    4516                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    4517                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    4518                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    4519                 :          1 :         opaque_key_exchange_rsp_size =
+    4520                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    4521                 :            :                 spdm_context);
+    4522                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    4523                 :          1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
+    4524                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+    4525                 :            :                              hmac_size;
+    4526                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    4527                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    4528                 :            : 
+    4529                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+    4530                 :          1 :         spdm_response->header.request_response_code =
+    4531                 :            :             SPDM_KEY_EXCHANGE_RSP;
+    4532                 :          1 :         spdm_response->header.param1 = 0;
+    4533                 :          1 :         spdm_response->rsp_session_id =
+    4534                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
+    4535                 :          1 :         spdm_response->mut_auth_requested = 0;
+    4536                 :          1 :         spdm_response->req_slot_id_param = 0;
+    4537                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    4538                 :          1 :                                   spdm_response->random_data);
+    4539                 :          1 :         ptr = (void *)(spdm_response + 1);
+    4540                 :          1 :         dhe_context = libspdm_dhe_new(
+    4541                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    4542                 :            :                 m_libspdm_use_dhe_algo,
+    4543                 :            :                 true);
+    4544                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+    4545                 :            :                                  &dhe_key_size);
+    4546                 :          1 :         final_key_size = sizeof(final_key);
+    4547                 :          1 :         libspdm_dhe_compute_key(
+    4548                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    4549                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    4550                 :            :             sizeof(spdm_key_exchange_request_t),
+    4551                 :            :             dhe_key_size, final_key, &final_key_size);
+    4552                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    4553                 :          1 :         ptr += dhe_key_size;
+    4554                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    4555                 :            :          * ptr += hash_size;*/
+    4556                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    4557                 :          1 :         ptr += sizeof(uint16_t);
+    4558                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    4559                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    4560                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+    4561                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    4562                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    4563                 :            :                                                         &data_size, NULL, NULL);
+    4564                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    4565                 :            :                          sizeof(m_libspdm_local_buffer)
+    4566                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    4567                 :            :                             m_libspdm_local_buffer),
+    4568                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    4569                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    4570                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    4571                 :            :                        m_libspdm_local_buffer_size));
+    4572                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    4573                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    4574                 :          1 :         cert_buffer = (uint8_t *)data;
+    4575                 :          1 :         cert_buffer_size = data_size;
+    4576                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    4577                 :            :                          cert_buffer_hash);
+    4578                 :            :         /* transcript.message_a size is 0*/
+    4579                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    4580                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    4581                 :            :                                       m_libspdm_local_buffer_size);
+    4582                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    4583                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    4584                 :          1 :         free(data);
+    4585                 :          1 :         libspdm_responder_data_sign(
+    4586                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    4587                 :            :             spdm_context,
+    4588                 :            : #endif
+    4589                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    4590                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    4591                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    4592                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+    4593                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    4594                 :            :                 &signature_size);
+    4595                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    4596                 :            :                          sizeof(m_libspdm_local_buffer)
+    4597                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    4598                 :            :                             m_libspdm_local_buffer),
+    4599                 :            :                          ptr, signature_size);
+    4600                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+    4601                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    4602                 :          1 :         ptr += signature_size;
+    4603                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    4604                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    4605                 :            :                          th_curr_hash_data);
+    4606                 :          1 :         bin_str0_size = sizeof(bin_str0);
+    4607                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    4608                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    4609                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    4610                 :            :                            &bin_str0_size);
+    4611                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    4612                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    4613                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    4614                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    4615                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    4616                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    4617                 :            :                            bin_str2, &bin_str2_size);
+    4618                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    4619                 :            :                             bin_str2, bin_str2_size,
+    4620                 :            :                             response_handshake_secret, hash_size);
+    4621                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    4622                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    4623                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    4624                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    4625                 :            :                            &bin_str7_size);
+    4626                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    4627                 :            :                             hash_size, bin_str7, bin_str7_size,
+    4628                 :            :                             response_finished_key, hash_size);
+    4629                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    4630                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    4631                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    4632                 :            :                          response_finished_key, hash_size, ptr);
+    4633                 :          1 :         ptr += hmac_size;
+    4634                 :            : 
+    4635                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    4636                 :            :                                               false, spdm_response_size,
+    4637                 :            :                                               spdm_response, response_size,
+    4638                 :            :                                               response);
+    4639                 :            :     }
+    4640                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    4641                 :            : 
+    4642                 :          1 :     case 0x1F: {
+    4643                 :            :         spdm_key_exchange_response_t *spdm_response;
+    4644                 :            :         size_t dhe_key_size;
+    4645                 :            :         uint32_t hash_size;
+    4646                 :            :         size_t signature_size;
+    4647                 :            :         uint32_t hmac_size;
+    4648                 :            :         uint8_t *ptr;
+    4649                 :            :         void *dhe_context;
+    4650                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    4651                 :            :         size_t final_key_size;
+    4652                 :            :         size_t opaque_key_exchange_rsp_size;
+    4653                 :            :         void *data;
+    4654                 :            :         size_t data_size;
+    4655                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    4656                 :            :         uint8_t *cert_buffer;
+    4657                 :            :         size_t cert_buffer_size;
+    4658                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    4659                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    4660                 :            :         uint8_t bin_str0[128];
+    4661                 :            :         size_t bin_str0_size;
+    4662                 :            :         uint8_t bin_str2[128];
+    4663                 :            :         size_t bin_str2_size;
+    4664                 :            :         uint8_t bin_str7[128];
+    4665                 :            :         size_t bin_str7_size;
+    4666                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    4667                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    4668                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    4669                 :            :         size_t spdm_response_size;
+    4670                 :            :         size_t transport_header_size;
+    4671                 :            : 
+    4672                 :          1 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
+    4673                 :            :             SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4674                 :            :         ((libspdm_context_t *)spdm_context)
+    4675                 :          1 :         ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    4676                 :            :         ((libspdm_context_t *)spdm_context)
+    4677                 :          1 :         ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    4678                 :            :         ((libspdm_context_t *)spdm_context)
+    4679                 :          1 :         ->connection_info.algorithm.dhe_named_group =  m_libspdm_use_dhe_algo;
+    4680                 :            :         ((libspdm_context_t *)spdm_context)
+    4681                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    4682                 :            :             m_libspdm_use_measurement_hash_algo;
+    4683                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    4684                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    4685                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    4686                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    4687                 :          1 :         opaque_key_exchange_rsp_size =
+    4688                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(spdm_context);
+    4689                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    4690                 :          1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
+    4691                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+    4692                 :            :                              hmac_size;
+    4693                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    4694                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    4695                 :            : 
+    4696                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    4697                 :          1 :         spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
+    4698                 :          1 :         spdm_response->header.param1 = 0;
+    4699                 :          1 :         spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
+    4700                 :          1 :         spdm_response->mut_auth_requested = 0;
+    4701                 :          1 :         spdm_response->req_slot_id_param = 0;
+    4702                 :          1 :         memset(spdm_response->random_data, 0x5c, SPDM_RANDOM_DATA_SIZE);
+    4703                 :          1 :         ptr = (void *)(spdm_response + 1);
+    4704                 :          1 :         dhe_context = libspdm_dhe_new(
+    4705                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    4706                 :            :                 m_libspdm_use_dhe_algo, true);
+    4707                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
+    4708                 :          1 :         final_key_size = sizeof(final_key);
+    4709                 :          1 :         libspdm_dhe_compute_key(
+    4710                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    4711                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    4712                 :            :             sizeof(spdm_key_exchange_request_t),
+    4713                 :            :             dhe_key_size, final_key, &final_key_size);
+    4714                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    4715                 :          1 :         ptr += dhe_key_size;
+    4716                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    4717                 :            :          * ptr += hash_size;*/
+    4718                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    4719                 :          1 :         ptr += sizeof(uint16_t);
+    4720                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    4721                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    4722                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+    4723                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    4724                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    4725                 :            :                                                         &data_size, NULL, NULL);
+    4726                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    4727                 :            :                          sizeof(m_libspdm_local_buffer)
+    4728                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    4729                 :            :                             m_libspdm_local_buffer),
+    4730                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    4731                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    4732                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    4733                 :            :                        m_libspdm_local_buffer_size));
+    4734                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    4735                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    4736                 :          1 :         cert_buffer = (uint8_t *)data;
+    4737                 :          1 :         cert_buffer_size = data_size;
+    4738                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size, cert_buffer_hash);
+    4739                 :            :         /* transcript.message_a size is 0*/
+    4740                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    4741                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    4742                 :            :                                       m_libspdm_local_buffer_size);
+    4743                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    4744                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    4745                 :          1 :         free(data);
+    4746                 :          1 :         libspdm_responder_data_sign(
+    4747                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    4748                 :            :             spdm_context,
+    4749                 :            : #endif
+    4750                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    4751                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    4752                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    4753                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+    4754                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    4755                 :            :                 &signature_size);
+    4756                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    4757                 :            :                          sizeof(m_libspdm_local_buffer)
+    4758                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    4759                 :            :                             m_libspdm_local_buffer),
+    4760                 :            :                          ptr, signature_size);
+    4761                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+    4762                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    4763                 :          1 :         ptr += signature_size;
+    4764                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    4765                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    4766                 :            :                          th_curr_hash_data);
+    4767                 :          1 :         bin_str0_size = sizeof(bin_str0);
+    4768                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    4769                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    4770                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    4771                 :            :                            &bin_str0_size);
+    4772                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    4773                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    4774                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    4775                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    4776                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    4777                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    4778                 :            :                            bin_str2, &bin_str2_size);
+    4779                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    4780                 :            :                             bin_str2, bin_str2_size,
+    4781                 :            :                             response_handshake_secret, hash_size);
+    4782                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    4783                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    4784                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    4785                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    4786                 :            :                            &bin_str7_size);
+    4787                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    4788                 :            :                             hash_size, bin_str7, bin_str7_size,
+    4789                 :            :                             response_finished_key, hash_size);
+    4790                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    4791                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    4792                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    4793                 :            :                          response_finished_key, hash_size, ptr);
+    4794                 :          1 :         ptr += hmac_size;
+    4795                 :            : 
+    4796                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    4797                 :            :                                               false, spdm_response_size,
+    4798                 :            :                                               spdm_response, response_size,
+    4799                 :            :                                               response);
+    4800                 :            :     }
+    4801                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    4802                 :            : 
+    4803                 :          1 :     case 0x20: {
+    4804                 :            :         spdm_key_exchange_response_t *spdm_response;
+    4805                 :            :         size_t dhe_key_size;
+    4806                 :            :         uint32_t hash_size;
+    4807                 :            :         size_t signature_size;
+    4808                 :            :         uint32_t hmac_size;
+    4809                 :            :         uint8_t *ptr;
+    4810                 :            :         void *dhe_context;
+    4811                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    4812                 :            :         size_t final_key_size;
+    4813                 :            :         size_t opaque_key_exchange_rsp_size;
+    4814                 :            :         void *data;
+    4815                 :            :         size_t data_size;
+    4816                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    4817                 :            :         uint8_t *cert_buffer;
+    4818                 :            :         size_t cert_buffer_size;
+    4819                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    4820                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    4821                 :            :         uint8_t bin_str0[128];
+    4822                 :            :         size_t bin_str0_size;
+    4823                 :            :         uint8_t bin_str2[128];
+    4824                 :            :         size_t bin_str2_size;
+    4825                 :            :         uint8_t bin_str7[128];
+    4826                 :            :         size_t bin_str7_size;
+    4827                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    4828                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    4829                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    4830                 :            :         size_t spdm_response_size;
+    4831                 :            :         size_t transport_header_size;
+    4832                 :            : 
+    4833                 :          1 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
+    4834                 :            :             SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4835                 :            :         ((libspdm_context_t *)spdm_context)
+    4836                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    4837                 :            :             m_libspdm_use_asym_algo;
+    4838                 :            :         ((libspdm_context_t *)spdm_context)
+    4839                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    4840                 :            :             m_libspdm_use_hash_algo;
+    4841                 :            :         ((libspdm_context_t *)spdm_context)
+    4842                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    4843                 :            :             m_libspdm_use_dhe_algo;
+    4844                 :            :         ((libspdm_context_t *)spdm_context)
+    4845                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    4846                 :            :             m_libspdm_use_measurement_hash_algo;
+    4847                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    4848                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    4849                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    4850                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    4851                 :          1 :         opaque_key_exchange_rsp_size =
+    4852                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    4853                 :            :                 spdm_context);
+    4854                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    4855                 :          1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
+    4856                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+    4857                 :            :                              hmac_size;
+    4858                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    4859                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    4860                 :            : 
+    4861                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+    4862                 :          1 :         spdm_response->header.request_response_code =
+    4863                 :            :             SPDM_KEY_EXCHANGE_RSP;
+    4864                 :          1 :         spdm_response->header.param1 = 0;
+    4865                 :          1 :         spdm_response->rsp_session_id =
+    4866                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
+    4867                 :          1 :         spdm_response->mut_auth_requested = 0;
+    4868                 :          1 :         spdm_response->req_slot_id_param = 0;
+    4869                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    4870                 :          1 :                                   spdm_response->random_data);
+    4871                 :          1 :         ptr = (void *)(spdm_response + 1);
+    4872                 :          1 :         dhe_context = libspdm_dhe_new(
+    4873                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    4874                 :            :                 m_libspdm_use_dhe_algo,
+    4875                 :            :                 true);
+    4876                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+    4877                 :            :                                  &dhe_key_size);
+    4878                 :          1 :         final_key_size = sizeof(final_key);
+    4879                 :          1 :         libspdm_dhe_compute_key(
+    4880                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    4881                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    4882                 :            :             sizeof(spdm_key_exchange_request_t),
+    4883                 :            :             dhe_key_size, final_key, &final_key_size);
+    4884                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    4885                 :          1 :         ptr += dhe_key_size;
+    4886                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    4887                 :            :          * ptr += hash_size;*/
+    4888                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    4889                 :          1 :         ptr += sizeof(uint16_t);
+    4890                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    4891                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    4892                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+    4893                 :          1 :         libspdm_read_responder_public_key(m_libspdm_use_asym_algo, &data, &data_size);
+    4894                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    4895                 :            :                          sizeof(m_libspdm_local_buffer)
+    4896                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    4897                 :            :                             m_libspdm_local_buffer),
+    4898                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    4899                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    4900                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    4901                 :            :                        m_libspdm_local_buffer_size));
+    4902                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    4903                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    4904                 :          1 :         cert_buffer = (uint8_t *)data;
+    4905                 :          1 :         cert_buffer_size = data_size;
+    4906                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    4907                 :            :                          cert_buffer_hash);
+    4908                 :            :         /* transcript.message_a size is 0*/
+    4909                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    4910                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    4911                 :            :                                       m_libspdm_local_buffer_size);
+    4912                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    4913                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    4914                 :          1 :         free(data);
+    4915                 :          1 :         libspdm_responder_data_sign(
+    4916                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    4917                 :            :             spdm_context,
+    4918                 :            : #endif
+    4919                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    4920                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    4921                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    4922                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+    4923                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    4924                 :            :                 &signature_size);
+    4925                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    4926                 :            :                          sizeof(m_libspdm_local_buffer)
+    4927                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    4928                 :            :                             m_libspdm_local_buffer),
+    4929                 :            :                          ptr, signature_size);
+    4930                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+    4931                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    4932                 :          1 :         ptr += signature_size;
+    4933                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    4934                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    4935                 :            :                          th_curr_hash_data);
+    4936                 :          1 :         bin_str0_size = sizeof(bin_str0);
+    4937                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    4938                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    4939                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    4940                 :            :                            &bin_str0_size);
+    4941                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    4942                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    4943                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    4944                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    4945                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    4946                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    4947                 :            :                            bin_str2, &bin_str2_size);
+    4948                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    4949                 :            :                             bin_str2, bin_str2_size,
+    4950                 :            :                             response_handshake_secret, hash_size);
+    4951                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    4952                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    4953                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    4954                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    4955                 :            :                            &bin_str7_size);
+    4956                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    4957                 :            :                             hash_size, bin_str7, bin_str7_size,
+    4958                 :            :                             response_finished_key, hash_size);
+    4959                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    4960                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    4961                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    4962                 :            :                          response_finished_key, hash_size, ptr);
+    4963                 :          1 :         ptr += hmac_size;
+    4964                 :            : 
+    4965                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    4966                 :            :                                               false, spdm_response_size,
+    4967                 :            :                                               spdm_response, response_size,
+    4968                 :            :                                               response);
+    4969                 :            :     }
+    4970                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    4971                 :          1 :     case 0x21: {
+    4972                 :            :         spdm_key_exchange_response_t *spdm_response;
+    4973                 :            :         size_t dhe_key_size;
+    4974                 :            :         uint32_t hash_size;
+    4975                 :            :         size_t signature_size;
+    4976                 :            :         uint32_t hmac_size;
+    4977                 :            :         uint8_t *ptr;
+    4978                 :            :         void *dhe_context;
+    4979                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    4980                 :            :         size_t final_key_size;
+    4981                 :            :         size_t opaque_key_exchange_rsp_size;
+    4982                 :            :         void *data;
+    4983                 :            :         size_t data_size;
+    4984                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    4985                 :            :         uint8_t *cert_buffer;
+    4986                 :            :         size_t cert_buffer_size;
+    4987                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    4988                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    4989                 :            :         uint8_t bin_str0[128];
+    4990                 :            :         size_t bin_str0_size;
+    4991                 :            :         uint8_t bin_str2[128];
+    4992                 :            :         size_t bin_str2_size;
+    4993                 :            :         uint8_t bin_str7[128];
+    4994                 :            :         size_t bin_str7_size;
+    4995                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    4996                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    4997                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    4998                 :            :         size_t spdm_response_size;
+    4999                 :            :         size_t transport_header_size;
+    5000                 :            : 
+    5001                 :          1 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
+    5002                 :            :             SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5003                 :            :         ((libspdm_context_t *)spdm_context)
+    5004                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    5005                 :            :             m_libspdm_use_asym_algo;
+    5006                 :            :         ((libspdm_context_t *)spdm_context)
+    5007                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    5008                 :            :             m_libspdm_use_hash_algo;
+    5009                 :            :         ((libspdm_context_t *)spdm_context)
+    5010                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    5011                 :            :             m_libspdm_use_dhe_algo;
+    5012                 :            :         ((libspdm_context_t *)spdm_context)
+    5013                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    5014                 :            :             m_libspdm_use_measurement_hash_algo;
+    5015                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    5016                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    5017                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    5018                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    5019                 :          1 :         opaque_key_exchange_rsp_size =
+    5020                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    5021                 :            :                 spdm_context);
+    5022                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    5023                 :          1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
+    5024                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+    5025                 :            :                              hmac_size;
+    5026                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    5027                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    5028                 :            : 
+    5029                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+    5030                 :          1 :         spdm_response->header.request_response_code =
+    5031                 :            :             SPDM_KEY_EXCHANGE_RSP;
+    5032                 :          1 :         spdm_response->header.param1 = 0;
+    5033                 :          1 :         spdm_response->rsp_session_id =
+    5034                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
+    5035                 :          1 :         spdm_response->mut_auth_requested = 0;
+    5036                 :          1 :         spdm_response->req_slot_id_param = 0;
+    5037                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    5038                 :          1 :                                   spdm_response->random_data);
+    5039                 :          1 :         ptr = (void *)(spdm_response + 1);
+    5040                 :          1 :         dhe_context = libspdm_dhe_new(
+    5041                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    5042                 :            :                 m_libspdm_use_dhe_algo,
+    5043                 :            :                 true);
+    5044                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
+    5045                 :            :                                  &dhe_key_size);
+    5046                 :          1 :         final_key_size = sizeof(final_key);
+    5047                 :          1 :         libspdm_dhe_compute_key(
+    5048                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    5049                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    5050                 :            :             sizeof(spdm_key_exchange_request_t),
+    5051                 :            :             dhe_key_size, final_key, &final_key_size);
+    5052                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    5053                 :          1 :         ptr += dhe_key_size;
+    5054                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    5055                 :            :          * ptr += hash_size;*/
+    5056                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    5057                 :          1 :         ptr += sizeof(uint16_t);
+    5058                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    5059                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    5060                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+    5061                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    5062                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    5063                 :            :                                                         &data_size, NULL, NULL);
+    5064                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    5065                 :            :                          sizeof(m_libspdm_local_buffer)
+    5066                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    5067                 :            :                             m_libspdm_local_buffer),
+    5068                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    5069                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    5070                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    5071                 :            :                        m_libspdm_local_buffer_size));
+    5072                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    5073                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    5074                 :          1 :         cert_buffer = (uint8_t *)data;
+    5075                 :          1 :         cert_buffer_size = data_size;
+    5076                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    5077                 :            :                          cert_buffer_hash);
+    5078                 :            :         /* transcript.message_a size is 0*/
+    5079                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    5080                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    5081                 :            :                                       m_libspdm_local_buffer_size);
+    5082                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    5083                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    5084                 :          1 :         free(data);
+    5085                 :          1 :         libspdm_responder_data_sign(
+    5086                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    5087                 :            :             spdm_context,
+    5088                 :            : #endif
+    5089                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    5090                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    5091                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    5092                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+    5093                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    5094                 :            :                 &signature_size);
+    5095                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    5096                 :            :                          sizeof(m_libspdm_local_buffer)
+    5097                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    5098                 :            :                             m_libspdm_local_buffer),
+    5099                 :            :                          ptr, signature_size);
+    5100                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+    5101                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    5102                 :          1 :         ptr += signature_size;
+    5103                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    5104                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    5105                 :            :                          th_curr_hash_data);
+    5106                 :          1 :         bin_str0_size = sizeof(bin_str0);
+    5107                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    5108                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    5109                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    5110                 :            :                            &bin_str0_size);
+    5111                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    5112                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    5113                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    5114                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    5115                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    5116                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    5117                 :            :                            bin_str2, &bin_str2_size);
+    5118                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    5119                 :            :                             bin_str2, bin_str2_size,
+    5120                 :            :                             response_handshake_secret, hash_size);
+    5121                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    5122                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    5123                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    5124                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    5125                 :            :                            &bin_str7_size);
+    5126                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    5127                 :            :                             hash_size, bin_str7, bin_str7_size,
+    5128                 :            :                             response_finished_key, hash_size);
+    5129                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    5130                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    5131                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    5132                 :            :                          response_finished_key, hash_size, ptr);
+    5133                 :          1 :         ptr += hmac_size;
+    5134                 :            : 
+    5135                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    5136                 :            :                                               false, spdm_response_size,
+    5137                 :            :                                               spdm_response, response_size,
+    5138                 :            :                                               response);
+    5139                 :            :     }
+    5140                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    5141                 :          1 :     case 0x22: {
+    5142                 :            :         spdm_key_exchange_response_t *spdm_response;
+    5143                 :            :         size_t dhe_key_size;
+    5144                 :            :         uint32_t hash_size;
+    5145                 :            :         size_t signature_size;
+    5146                 :            :         uint32_t hmac_size;
+    5147                 :            :         uint8_t *ptr;
+    5148                 :            :         void *dhe_context;
+    5149                 :            :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
+    5150                 :            :         size_t final_key_size;
+    5151                 :            :         size_t opaque_key_exchange_rsp_size;
+    5152                 :            :         void *data;
+    5153                 :            :         size_t data_size;
+    5154                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    5155                 :            :         uint8_t *cert_buffer;
+    5156                 :            :         size_t cert_buffer_size;
+    5157                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    5158                 :            :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    5159                 :            :         uint8_t bin_str0[128];
+    5160                 :            :         size_t bin_str0_size;
+    5161                 :            :         uint8_t bin_str2[128];
+    5162                 :            :         size_t bin_str2_size;
+    5163                 :            :         uint8_t bin_str7[128];
+    5164                 :            :         size_t bin_str7_size;
+    5165                 :            :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    5166                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    5167                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    5168                 :            :         size_t spdm_response_size;
+    5169                 :            :         size_t transport_header_size;
+    5170                 :            : 
+    5171                 :          1 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
+    5172                 :            :             SECURED_SPDM_VERSION_12 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5173                 :            :         ((libspdm_context_t *)spdm_context)
+    5174                 :          1 :         ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    5175                 :            :         ((libspdm_context_t *)spdm_context)
+    5176                 :          1 :         ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    5177                 :            :         ((libspdm_context_t *)spdm_context)
+    5178                 :          1 :         ->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    5179                 :            :         ((libspdm_context_t *)spdm_context)
+    5180                 :          1 :         ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+    5181                 :          1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    5182                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    5183                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    5184                 :          1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    5185                 :          1 :         opaque_key_exchange_rsp_size =
+    5186                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(spdm_context);
+    5187                 :          1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
+    5188                 :          1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
+    5189                 :          1 :                              opaque_key_exchange_rsp_size + signature_size +
+    5190                 :            :                              hmac_size;
+    5191                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    5192                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    5193                 :            : 
+    5194                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    5195                 :          1 :         spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
+    5196                 :          1 :         spdm_response->header.param1 = 0;
+    5197                 :          1 :         spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
+    5198                 :          1 :         spdm_response->mut_auth_requested = 0;
+    5199                 :          1 :         spdm_response->req_slot_id_param = 0;
+    5200                 :          1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_response->random_data);
+    5201                 :          1 :         ptr = (void *)(spdm_response + 1);
+    5202                 :          1 :         dhe_context = libspdm_dhe_new(
+    5203                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    5204                 :            :                 m_libspdm_use_dhe_algo, true);
+    5205                 :          1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
+    5206                 :          1 :         final_key_size = sizeof(final_key);
+    5207                 :          1 :         libspdm_dhe_compute_key(
+    5208                 :            :             m_libspdm_use_dhe_algo, dhe_context,
+    5209                 :          1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
+    5210                 :            :             sizeof(spdm_key_exchange_request_t),
+    5211                 :            :             dhe_key_size, final_key, &final_key_size);
+    5212                 :          1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    5213                 :          1 :         ptr += dhe_key_size;
+    5214                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    5215                 :            :          * ptr += hash_size;*/
+    5216                 :          1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
+    5217                 :          1 :         ptr += sizeof(uint16_t);
+    5218                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    5219                 :            :             spdm_context, &opaque_key_exchange_rsp_size, ptr);
+    5220                 :          1 :         ptr += opaque_key_exchange_rsp_size;
+    5221                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    5222                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    5223                 :            :                                                         &data_size, NULL, NULL);
+    5224                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    5225                 :            :                          sizeof(m_libspdm_local_buffer)
+    5226                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    5227                 :            :                             m_libspdm_local_buffer),
+    5228                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    5229                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    5230                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    5231                 :            :                        m_libspdm_local_buffer_size));
+    5232                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    5233                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    5234                 :          1 :         cert_buffer = (uint8_t *)data;
+    5235                 :          1 :         cert_buffer_size = data_size;
+    5236                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    5237                 :            :                          cert_buffer_hash);
+    5238                 :            :         /* transcript.message_a size is 0*/
+    5239                 :          1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    5240                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    5241                 :            :                                       m_libspdm_local_buffer_size);
+    5242                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    5243                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    5244                 :          1 :         free(data);
+    5245                 :          1 :         libspdm_responder_data_sign(
+    5246                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    5247                 :            :             spdm_context,
+    5248                 :            : #endif
+    5249                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    5250                 :            :                 SPDM_KEY_EXCHANGE_RSP,
+    5251                 :            :                 m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
+    5252                 :          1 :                 false, libspdm_get_managed_buffer(&th_curr),
+    5253                 :            :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
+    5254                 :            :                 &signature_size);
+    5255                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    5256                 :            :                          sizeof(m_libspdm_local_buffer)
+    5257                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    5258                 :            :                             m_libspdm_local_buffer),
+    5259                 :            :                          ptr, signature_size);
+    5260                 :          1 :         m_libspdm_local_buffer_size += signature_size;
+    5261                 :          1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
+    5262                 :          1 :         ptr += signature_size;
+    5263                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    5264                 :            :                          libspdm_get_managed_buffer_size(&th_curr),
+    5265                 :            :                          th_curr_hash_data);
+    5266                 :          1 :         bin_str0_size = sizeof(bin_str0);
+    5267                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    5268                 :            :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
+    5269                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
+    5270                 :            :                            &bin_str0_size);
+    5271                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
+    5272                 :            :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
+    5273                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    5274                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    5275                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    5276                 :          1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
+    5277                 :            :                            bin_str2, &bin_str2_size);
+    5278                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
+    5279                 :            :                             bin_str2, bin_str2_size,
+    5280                 :            :                             response_handshake_secret, hash_size);
+    5281                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    5282                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    5283                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    5284                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    5285                 :            :                            &bin_str7_size);
+    5286                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    5287                 :            :                             hash_size, bin_str7, bin_str7_size,
+    5288                 :            :                             response_finished_key, hash_size);
+    5289                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    5290                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    5291                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    5292                 :            :                          response_finished_key, hash_size, ptr);
+    5293                 :          1 :         ptr += hmac_size;
+    5294                 :            : 
+    5295                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    5296                 :            :                                               false, spdm_response_size,
+    5297                 :            :                                               spdm_response, response_size,
+    5298                 :            :                                               response);
+    5299                 :            :     }
+    5300                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    5301                 :            : 
+    5302                 :          0 :     default:
+    5303                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+    5304                 :            :     }
+    5305                 :            : }
+    5306                 :            : 
+    5307                 :          1 : static void libspdm_test_requester_key_exchange_case1(void **state)
+    5308                 :            : {
+    5309                 :            :     libspdm_return_t status;
+    5310                 :            :     libspdm_test_context_t *spdm_test_context;
+    5311                 :            :     libspdm_context_t *spdm_context;
+    5312                 :            :     uint32_t session_id;
+    5313                 :            :     uint8_t heartbeat_period;
+    5314                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    5315                 :            :     uint8_t slot_id_param;
+    5316                 :            :     void *data;
+    5317                 :            :     size_t data_size;
+    5318                 :            :     void *hash;
+    5319                 :            :     size_t hash_size;
+    5320                 :            : 
+    5321                 :          1 :     spdm_test_context = *state;
+    5322                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5323                 :          1 :     spdm_test_context->case_id = 0x1;
+    5324                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5325                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5326                 :          1 :     spdm_context->connection_info.connection_state =
+    5327                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    5328                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5329                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    5330                 :          1 :     spdm_context->local_context.capability.flags |=
+    5331                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    5332                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    5333                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    5334                 :            :                                                     &data_size, &hash, &hash_size);
+    5335                 :          1 :     libspdm_reset_message_a(spdm_context);
+    5336                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    5337                 :            :         m_libspdm_use_hash_algo;
+    5338                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    5339                 :            :         m_libspdm_use_asym_algo;
+    5340                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    5341                 :            :         m_libspdm_use_dhe_algo;
+    5342                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    5343                 :            :         m_libspdm_use_aead_algo;
+    5344                 :            : 
+    5345                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5346                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    5347                 :            :         data_size;
+    5348                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    5349                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    5350                 :            :                      data, data_size);
+    5351                 :            : #else
+    5352                 :          1 :     libspdm_hash_all(
+    5353                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5354                 :            :         data, data_size,
+    5355                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    5356                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    5357                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    5358                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    5359                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5360                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    5361                 :            :         data, data_size,
+    5362                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    5363                 :            : #endif
+    5364                 :            : 
+    5365                 :          1 :     heartbeat_period = 0;
+    5366                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    5367                 :          1 :     status = libspdm_send_receive_key_exchange(
+    5368                 :            :         spdm_context,
+    5369                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    5370                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    5371                 :            :         measurement_hash);
+    5372                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SEND_FAIL);
+    5373                 :          1 :     free(data);
+    5374                 :          1 : }
+    5375                 :            : 
+    5376                 :          1 : static void libspdm_test_requester_key_exchange_case2(void **state)
+    5377                 :            : {
+    5378                 :            :     libspdm_return_t status;
+    5379                 :            :     libspdm_test_context_t *spdm_test_context;
+    5380                 :            :     libspdm_context_t *spdm_context;
+    5381                 :            :     uint32_t session_id;
+    5382                 :            :     uint8_t heartbeat_period;
+    5383                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    5384                 :            :     uint8_t slot_id_param;
+    5385                 :            :     void *data;
+    5386                 :            :     size_t data_size;
+    5387                 :            :     void *hash;
+    5388                 :            :     size_t hash_size;
+    5389                 :            : 
+    5390                 :          1 :     spdm_test_context = *state;
+    5391                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5392                 :          1 :     spdm_test_context->case_id = 0x2;
+    5393                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5394                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5395                 :          1 :     spdm_context->connection_info.connection_state =
+    5396                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    5397                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5398                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    5399                 :          1 :     spdm_context->local_context.capability.flags |=
+    5400                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    5401                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
+    5402                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
+    5403                 :            :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5404                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    5405                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    5406                 :            :                                                     &data_size, &hash, &hash_size);
+    5407                 :          1 :     libspdm_reset_message_a(spdm_context);
+    5408                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    5409                 :            :         m_libspdm_use_hash_algo;
+    5410                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    5411                 :            :         m_libspdm_use_asym_algo;
+    5412                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    5413                 :            :         m_libspdm_use_dhe_algo;
+    5414                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    5415                 :            :         m_libspdm_use_aead_algo;
+    5416                 :            : 
+    5417                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5418                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    5419                 :            :         data_size;
+    5420                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    5421                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    5422                 :            :                      data, data_size);
+    5423                 :            : #else
+    5424                 :          1 :     libspdm_hash_all(
+    5425                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5426                 :            :         data, data_size,
+    5427                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    5428                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    5429                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    5430                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    5431                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5432                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    5433                 :            :         data, data_size,
+    5434                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    5435                 :            : #endif
+    5436                 :            : 
+    5437                 :          1 :     heartbeat_period = 0;
+    5438                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    5439                 :          1 :     status = libspdm_send_receive_key_exchange(
+    5440                 :            :         spdm_context,
+    5441                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    5442                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    5443                 :            :         measurement_hash);
+    5444                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    5445                 :          1 :     assert_int_equal(session_id, 0xFFFFFFFF);
+    5446                 :          1 :     assert_int_equal(
+    5447                 :            :         libspdm_secured_message_get_session_state(
+    5448                 :            :             spdm_context->session_info[0].secured_message_context),
+    5449                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    5450                 :          1 :     free(data);
+    5451                 :          1 : }
+    5452                 :            : 
+    5453                 :          1 : static void libspdm_test_requester_key_exchange_case3(void **state)
+    5454                 :            : {
+    5455                 :            :     libspdm_return_t status;
+    5456                 :            :     libspdm_test_context_t *spdm_test_context;
+    5457                 :            :     libspdm_context_t *spdm_context;
+    5458                 :            :     uint32_t session_id;
+    5459                 :            :     uint8_t heartbeat_period;
+    5460                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    5461                 :            :     uint8_t slot_id_param;
+    5462                 :            :     void *data;
+    5463                 :            :     size_t data_size;
+    5464                 :            :     void *hash;
+    5465                 :            :     size_t hash_size;
+    5466                 :            : 
+    5467                 :          1 :     spdm_test_context = *state;
+    5468                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5469                 :          1 :     spdm_test_context->case_id = 0x3;
+    5470                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5471                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5472                 :          1 :     spdm_context->connection_info.connection_state =
+    5473                 :            :         LIBSPDM_CONNECTION_STATE_NOT_STARTED;
+    5474                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5475                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    5476                 :          1 :     spdm_context->local_context.capability.flags |=
+    5477                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    5478                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    5479                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    5480                 :            :                                                     &data_size, &hash, &hash_size);
+    5481                 :          1 :     libspdm_reset_message_a(spdm_context);
+    5482                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    5483                 :            :         m_libspdm_use_hash_algo;
+    5484                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    5485                 :            :         m_libspdm_use_asym_algo;
+    5486                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    5487                 :            :         m_libspdm_use_dhe_algo;
+    5488                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    5489                 :            :         m_libspdm_use_aead_algo;
+    5490                 :            : 
+    5491                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5492                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    5493                 :            :         data_size;
+    5494                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    5495                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    5496                 :            :                      data, data_size);
+    5497                 :            : #else
+    5498                 :          1 :     libspdm_hash_all(
+    5499                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5500                 :            :         data, data_size,
+    5501                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    5502                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    5503                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    5504                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    5505                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5506                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    5507                 :            :         data, data_size,
+    5508                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    5509                 :            : #endif
+    5510                 :            : 
+    5511                 :          1 :     heartbeat_period = 0;
+    5512                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    5513                 :          1 :     status = libspdm_send_receive_key_exchange(
+    5514                 :            :         spdm_context,
+    5515                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    5516                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    5517                 :            :         measurement_hash);
+    5518                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_STATE_LOCAL);
+    5519                 :          1 :     free(data);
+    5520                 :          1 : }
+    5521                 :            : 
+    5522                 :          1 : static void libspdm_test_requester_key_exchange_case4(void **state)
+    5523                 :            : {
+    5524                 :            :     libspdm_return_t status;
+    5525                 :            :     libspdm_test_context_t *spdm_test_context;
+    5526                 :            :     libspdm_context_t *spdm_context;
+    5527                 :            :     uint32_t session_id;
+    5528                 :            :     uint8_t heartbeat_period;
+    5529                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    5530                 :            :     uint8_t slot_id_param;
+    5531                 :            :     void *data;
+    5532                 :            :     size_t data_size;
+    5533                 :            :     void *hash;
+    5534                 :            :     size_t hash_size;
+    5535                 :            : 
+    5536                 :          1 :     spdm_test_context = *state;
+    5537                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5538                 :          1 :     spdm_test_context->case_id = 0x4;
+    5539                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5540                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5541                 :          1 :     spdm_context->connection_info.connection_state =
+    5542                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    5543                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5544                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    5545                 :          1 :     spdm_context->local_context.capability.flags |=
+    5546                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    5547                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    5548                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    5549                 :            :                                                     &data_size, &hash, &hash_size);
+    5550                 :          1 :     libspdm_reset_message_a(spdm_context);
+    5551                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    5552                 :            :         m_libspdm_use_hash_algo;
+    5553                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    5554                 :            :         m_libspdm_use_asym_algo;
+    5555                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    5556                 :            :         m_libspdm_use_dhe_algo;
+    5557                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    5558                 :            :         m_libspdm_use_aead_algo;
+    5559                 :            : 
+    5560                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5561                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    5562                 :            :         data_size;
+    5563                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    5564                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    5565                 :            :                      data, data_size);
+    5566                 :            : #else
+    5567                 :          1 :     libspdm_hash_all(
+    5568                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5569                 :            :         data, data_size,
+    5570                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    5571                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    5572                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    5573                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    5574                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5575                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    5576                 :            :         data, data_size,
+    5577                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    5578                 :            : #endif
+    5579                 :            : 
+    5580                 :          1 :     heartbeat_period = 0;
+    5581                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    5582                 :          1 :     status = libspdm_send_receive_key_exchange(
+    5583                 :            :         spdm_context,
+    5584                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    5585                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    5586                 :            :         measurement_hash);
+    5587                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_ERROR_PEER);
+    5588                 :          1 :     free(data);
+    5589                 :          1 : }
+    5590                 :            : 
+    5591                 :          1 : static void libspdm_test_requester_key_exchange_case5(void **state)
+    5592                 :            : {
+    5593                 :            :     libspdm_return_t status;
+    5594                 :            :     libspdm_test_context_t *spdm_test_context;
+    5595                 :            :     libspdm_context_t *spdm_context;
+    5596                 :            :     uint32_t session_id;
+    5597                 :            :     uint8_t heartbeat_period;
+    5598                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    5599                 :            :     uint8_t slot_id_param;
+    5600                 :            :     void *data;
+    5601                 :            :     size_t data_size;
+    5602                 :            :     void *hash;
+    5603                 :            :     size_t hash_size;
+    5604                 :            : 
+    5605                 :          1 :     spdm_test_context = *state;
+    5606                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5607                 :          1 :     spdm_test_context->case_id = 0x5;
+    5608                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5609                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5610                 :          1 :     spdm_context->connection_info.connection_state =
+    5611                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    5612                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5613                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    5614                 :          1 :     spdm_context->local_context.capability.flags |=
+    5615                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    5616                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    5617                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    5618                 :            :                                                     &data_size, &hash, &hash_size);
+    5619                 :          1 :     libspdm_reset_message_a(spdm_context);
+    5620                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    5621                 :            :         m_libspdm_use_hash_algo;
+    5622                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    5623                 :            :         m_libspdm_use_asym_algo;
+    5624                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    5625                 :            :         m_libspdm_use_dhe_algo;
+    5626                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    5627                 :            :         m_libspdm_use_aead_algo;
+    5628                 :            : 
+    5629                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5630                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    5631                 :            :         data_size;
+    5632                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    5633                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    5634                 :            :                      data, data_size);
+    5635                 :            : #else
+    5636                 :          1 :     libspdm_hash_all(
+    5637                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5638                 :            :         data, data_size,
+    5639                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    5640                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    5641                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    5642                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    5643                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5644                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    5645                 :            :         data, data_size,
+    5646                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    5647                 :            : #endif
+    5648                 :            : 
+    5649                 :          1 :     heartbeat_period = 0;
+    5650                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    5651                 :          1 :     status = libspdm_send_receive_key_exchange(
+    5652                 :            :         spdm_context,
+    5653                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    5654                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    5655                 :            :         measurement_hash);
+    5656                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_BUSY_PEER);
+    5657                 :          1 :     free(data);
+    5658                 :          1 : }
+    5659                 :            : 
+    5660                 :          1 : static void libspdm_test_requester_key_exchange_case6(void **state)
+    5661                 :            : {
+    5662                 :            :     libspdm_return_t status;
+    5663                 :            :     libspdm_test_context_t *spdm_test_context;
+    5664                 :            :     libspdm_context_t *spdm_context;
+    5665                 :            :     uint32_t session_id;
+    5666                 :            :     uint8_t heartbeat_period;
+    5667                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    5668                 :            :     uint8_t slot_id_param;
+    5669                 :            :     void *data;
+    5670                 :            :     size_t data_size;
+    5671                 :            :     void *hash;
+    5672                 :            :     size_t hash_size;
+    5673                 :            : 
+    5674                 :          1 :     spdm_test_context = *state;
+    5675                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5676                 :          1 :     spdm_test_context->case_id = 0x6;
+    5677                 :          1 :     spdm_context->retry_times = 3;
+    5678                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5679                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5680                 :          1 :     spdm_context->connection_info.connection_state =
+    5681                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    5682                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5683                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    5684                 :          1 :     spdm_context->local_context.capability.flags |=
+    5685                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    5686                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    5687                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    5688                 :            :                                                     &data_size, &hash, &hash_size);
+    5689                 :          1 :     libspdm_reset_message_a(spdm_context);
+    5690                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    5691                 :            :         m_libspdm_use_hash_algo;
+    5692                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    5693                 :            :         m_libspdm_use_asym_algo;
+    5694                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    5695                 :            :         m_libspdm_use_dhe_algo;
+    5696                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    5697                 :            :         m_libspdm_use_aead_algo;
+    5698                 :            : 
+    5699                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5700                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    5701                 :            :         data_size;
+    5702                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    5703                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    5704                 :            :                      data, data_size);
+    5705                 :            : #else
+    5706                 :          1 :     libspdm_hash_all(
+    5707                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5708                 :            :         data, data_size,
+    5709                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    5710                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    5711                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    5712                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    5713                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5714                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    5715                 :            :         data, data_size,
+    5716                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    5717                 :            : #endif
+    5718                 :            : 
+    5719                 :          1 :     heartbeat_period = 0;
+    5720                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    5721                 :          1 :     status = libspdm_send_receive_key_exchange(
+    5722                 :            :         spdm_context,
+    5723                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    5724                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    5725                 :            :         measurement_hash);
+    5726                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    5727                 :          1 :     assert_int_equal(session_id, 0xFFFEFFFE);
+    5728                 :          1 :     assert_int_equal(
+    5729                 :            :         libspdm_secured_message_get_session_state(
+    5730                 :            :             spdm_context->session_info[0].secured_message_context),
+    5731                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    5732                 :          1 :     free(data);
+    5733                 :          1 : }
+    5734                 :            : 
+    5735                 :          1 : static void libspdm_test_requester_key_exchange_case7(void **state)
+    5736                 :            : {
+    5737                 :            :     libspdm_return_t status;
+    5738                 :            :     libspdm_test_context_t *spdm_test_context;
+    5739                 :            :     libspdm_context_t *spdm_context;
+    5740                 :            :     uint32_t session_id;
+    5741                 :            :     uint8_t heartbeat_period;
+    5742                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    5743                 :            :     uint8_t slot_id_param;
+    5744                 :            :     void *data;
+    5745                 :            :     size_t data_size;
+    5746                 :            :     void *hash;
+    5747                 :            :     size_t hash_size;
+    5748                 :            : 
+    5749                 :          1 :     spdm_test_context = *state;
+    5750                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5751                 :          1 :     spdm_test_context->case_id = 0x7;
+    5752                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5753                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5754                 :          1 :     spdm_context->connection_info.connection_state =
+    5755                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    5756                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5757                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    5758                 :          1 :     spdm_context->local_context.capability.flags |=
+    5759                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    5760                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    5761                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    5762                 :            :                                                     &data_size, &hash, &hash_size);
+    5763                 :          1 :     libspdm_reset_message_a(spdm_context);
+    5764                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    5765                 :            :         m_libspdm_use_hash_algo;
+    5766                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    5767                 :            :         m_libspdm_use_asym_algo;
+    5768                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    5769                 :            :         m_libspdm_use_dhe_algo;
+    5770                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    5771                 :            :         m_libspdm_use_aead_algo;
+    5772                 :            : 
+    5773                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5774                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    5775                 :            :         data_size;
+    5776                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    5777                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    5778                 :            :                      data, data_size);
+    5779                 :            : #else
+    5780                 :          1 :     libspdm_hash_all(
+    5781                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5782                 :            :         data, data_size,
+    5783                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    5784                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    5785                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    5786                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    5787                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5788                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    5789                 :            :         data, data_size,
+    5790                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    5791                 :            : #endif
+    5792                 :            : 
+    5793                 :          1 :     heartbeat_period = 0;
+    5794                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    5795                 :          1 :     status = libspdm_send_receive_key_exchange(
+    5796                 :            :         spdm_context,
+    5797                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    5798                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    5799                 :            :         measurement_hash);
+    5800                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_RESYNCH_PEER);
+    5801                 :          1 :     assert_int_equal(spdm_context->connection_info.connection_state,
+    5802                 :            :                      LIBSPDM_CONNECTION_STATE_NOT_STARTED);
+    5803                 :          1 :     free(data);
+    5804                 :          1 : }
+    5805                 :            : 
+    5806                 :          1 : static void libspdm_test_requester_key_exchange_case8(void **state)
+    5807                 :            : {
+    5808                 :            :     libspdm_return_t status;
+    5809                 :            :     libspdm_test_context_t *spdm_test_context;
+    5810                 :            :     libspdm_context_t *spdm_context;
+    5811                 :            :     uint32_t session_id;
+    5812                 :            :     uint8_t heartbeat_period;
+    5813                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    5814                 :            :     uint8_t slot_id_param;
+    5815                 :            :     void *data;
+    5816                 :            :     size_t data_size;
+    5817                 :            :     void *hash;
+    5818                 :            :     size_t hash_size;
+    5819                 :            : 
+    5820                 :          1 :     spdm_test_context = *state;
+    5821                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5822                 :          1 :     spdm_test_context->case_id = 0x8;
+    5823                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5824                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5825                 :          1 :     spdm_context->connection_info.connection_state =
+    5826                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    5827                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5828                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    5829                 :          1 :     spdm_context->local_context.capability.flags |=
+    5830                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    5831                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    5832                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    5833                 :            :                                                     &data_size, &hash, &hash_size);
+    5834                 :          1 :     libspdm_reset_message_a(spdm_context);
+    5835                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    5836                 :            :         m_libspdm_use_hash_algo;
+    5837                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    5838                 :            :         m_libspdm_use_asym_algo;
+    5839                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    5840                 :            :         m_libspdm_use_dhe_algo;
+    5841                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    5842                 :            :         m_libspdm_use_aead_algo;
+    5843                 :            : 
+    5844                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5845                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    5846                 :            :         data_size;
+    5847                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    5848                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    5849                 :            :                      data, data_size);
+    5850                 :            : #else
+    5851                 :          1 :     libspdm_hash_all(
+    5852                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5853                 :            :         data, data_size,
+    5854                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    5855                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    5856                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    5857                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    5858                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5859                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    5860                 :            :         data, data_size,
+    5861                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    5862                 :            : #endif
+    5863                 :            : 
+    5864                 :          1 :     heartbeat_period = 0;
+    5865                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    5866                 :          1 :     status = libspdm_send_receive_key_exchange(
+    5867                 :            :         spdm_context,
+    5868                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    5869                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    5870                 :            :         measurement_hash);
+    5871                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_NOT_READY_PEER);
+    5872                 :          1 :     free(data);
+    5873                 :          1 : }
+    5874                 :            : 
+    5875                 :          1 : static void libspdm_test_requester_key_exchange_case9(void **state)
+    5876                 :            : {
+    5877                 :            :     libspdm_return_t status;
+    5878                 :            :     libspdm_test_context_t *spdm_test_context;
+    5879                 :            :     libspdm_context_t *spdm_context;
+    5880                 :            :     uint32_t session_id;
+    5881                 :            :     uint8_t heartbeat_period;
+    5882                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    5883                 :            :     uint8_t slot_id_param;
+    5884                 :            :     void *data;
+    5885                 :            :     size_t data_size;
+    5886                 :            :     void *hash;
+    5887                 :            :     size_t hash_size;
+    5888                 :            : 
+    5889                 :          1 :     spdm_test_context = *state;
+    5890                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5891                 :          1 :     spdm_test_context->case_id = 0x9;
+    5892                 :          1 :     spdm_context->retry_times = 3;
+    5893                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5894                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5895                 :          1 :     spdm_context->connection_info.connection_state =
+    5896                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    5897                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5898                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    5899                 :          1 :     spdm_context->local_context.capability.flags |=
+    5900                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    5901                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    5902                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    5903                 :            :                                                     &data_size, &hash, &hash_size);
+    5904                 :          1 :     libspdm_reset_message_a(spdm_context);
+    5905                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    5906                 :            :         m_libspdm_use_hash_algo;
+    5907                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    5908                 :            :         m_libspdm_use_asym_algo;
+    5909                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    5910                 :            :         m_libspdm_use_dhe_algo;
+    5911                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    5912                 :            :         m_libspdm_use_aead_algo;
+    5913                 :            : 
+    5914                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5915                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    5916                 :            :         data_size;
+    5917                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    5918                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    5919                 :            :                      data, data_size);
+    5920                 :            : #else
+    5921                 :          1 :     libspdm_hash_all(
+    5922                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5923                 :            :         data, data_size,
+    5924                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    5925                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    5926                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    5927                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    5928                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5929                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    5930                 :            :         data, data_size,
+    5931                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    5932                 :            : #endif
+    5933                 :            : 
+    5934                 :          1 :     heartbeat_period = 0;
+    5935                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    5936                 :          1 :     status = libspdm_send_receive_key_exchange(
+    5937                 :            :         spdm_context,
+    5938                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    5939                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    5940                 :            :         measurement_hash);
+    5941                 :            :     if (LIBSPDM_RESPOND_IF_READY_SUPPORT) {
+    5942                 :          1 :         assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    5943                 :          1 :         assert_int_equal(session_id, 0xFFFDFFFD);
+    5944                 :          1 :         assert_int_equal(
+    5945                 :            :             libspdm_secured_message_get_session_state(
+    5946                 :            :                 spdm_context->session_info[0].secured_message_context),
+    5947                 :            :             LIBSPDM_SESSION_STATE_HANDSHAKING);
+    5948                 :            :     } else {
+    5949                 :            :         assert_int_equal(status, LIBSPDM_STATUS_NOT_READY_PEER);
+    5950                 :            :     }
+    5951                 :          1 :     free(data);
+    5952                 :          1 : }
+    5953                 :            : 
+    5954                 :          1 : static void libspdm_test_requester_key_exchange_case10(void **state) {
+    5955                 :            :     libspdm_return_t status;
+    5956                 :            :     libspdm_test_context_t    *spdm_test_context;
+    5957                 :            :     libspdm_context_t  *spdm_context;
+    5958                 :            :     uint32_t session_id;
+    5959                 :            :     uint8_t heartbeat_period;
+    5960                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    5961                 :            :     uint8_t slot_id_param;
+    5962                 :            :     void                 *data;
+    5963                 :            :     size_t data_size;
+    5964                 :            :     void                 *hash;
+    5965                 :            :     size_t hash_size;
+    5966                 :            :     uint16_t error_code;
+    5967                 :            : 
+    5968                 :          1 :     spdm_test_context = *state;
+    5969                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5970                 :          1 :     spdm_test_context->case_id = 0xA;
+    5971                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5972                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5973                 :          1 :     spdm_context->connection_info.capability.flags |=
+    5974                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    5975                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    5976                 :          1 :     libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
+    5977                 :            :                                                      m_libspdm_use_asym_algo,
+    5978                 :            :                                                      &data, &data_size,
+    5979                 :            :                                                      &hash, &hash_size);
+    5980                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    5981                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    5982                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    5983                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    5984                 :            : 
+    5985                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    5986                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    5987                 :            :         data_size;
+    5988                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    5989                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    5990                 :            :                      data, data_size);
+    5991                 :            : #else
+    5992                 :          1 :     libspdm_hash_all(
+    5993                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    5994                 :            :         data, data_size,
+    5995                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    5996                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    5997                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    5998                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    5999                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    6000                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    6001                 :            :         data, data_size,
+    6002                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    6003                 :            : #endif
+    6004                 :            : 
+    6005                 :          1 :     error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
+    6006         [ +  + ]:         19 :     while(error_code <= 0xff) {
+    6007                 :         18 :         spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    6008                 :         18 :         libspdm_reset_message_a(spdm_context);
+    6009                 :            : 
+    6010                 :         18 :         heartbeat_period = 0;
+    6011                 :         18 :         libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    6012                 :         18 :         status = libspdm_send_receive_key_exchange (spdm_context,
+    6013                 :            :                                                     SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
+    6014                 :            :                                                     0, 0, &session_id, &heartbeat_period,
+    6015                 :            :                                                     &slot_id_param, measurement_hash);
+    6016         [ -  + ]:         18 :         LIBSPDM_ASSERT_INT_EQUAL_CASE (status, LIBSPDM_STATUS_ERROR_PEER, error_code);
+    6017                 :            : 
+    6018                 :         18 :         error_code++;
+    6019         [ +  + ]:         18 :         if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
+    6020                 :          1 :             error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
+    6021                 :            :         }
+    6022         [ +  + ]:         18 :         if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) { /*skip some reserved error codes (0d to 3e)*/
+    6023                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
+    6024                 :            :         }
+    6025         [ +  + ]:         18 :         if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) { /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
+    6026                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
+    6027                 :            :         }
+    6028                 :            :     }
+    6029                 :            : 
+    6030                 :          1 :     free(data);
+    6031                 :          1 : }
+    6032                 :            : 
+    6033                 :          1 : static void libspdm_test_requester_key_exchange_case11(void **state)
+    6034                 :            : {
+    6035                 :            :     libspdm_return_t status;
+    6036                 :            :     libspdm_test_context_t *spdm_test_context;
+    6037                 :            :     libspdm_context_t *spdm_context;
+    6038                 :            :     uint32_t session_id;
+    6039                 :            :     uint8_t heartbeat_period;
+    6040                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    6041                 :            :     uint8_t slot_id_param;
+    6042                 :            :     void *data;
+    6043                 :            :     size_t data_size;
+    6044                 :            :     void *hash;
+    6045                 :            :     size_t hash_size;
+    6046                 :            : 
+    6047                 :          1 :     spdm_test_context = *state;
+    6048                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    6049                 :          1 :     spdm_test_context->case_id = 0xB;
+    6050                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    6051                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    6052                 :          1 :     spdm_context->connection_info.connection_state =
+    6053                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    6054                 :          1 :     spdm_context->connection_info.capability.flags |=
+    6055                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    6056                 :          1 :     spdm_context->local_context.capability.flags |=
+    6057                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    6058                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    6059                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    6060                 :            :                                                     &data_size, &hash, &hash_size);
+    6061                 :          1 :     libspdm_reset_message_a(spdm_context);
+    6062                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    6063                 :            :         m_libspdm_use_hash_algo;
+    6064                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    6065                 :            :         m_libspdm_use_asym_algo;
+    6066                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    6067                 :            :         m_libspdm_use_dhe_algo;
+    6068                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    6069                 :            :         m_libspdm_use_aead_algo;
+    6070                 :            : 
+    6071                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    6072                 :            :     spdm_context->transcript.message_m.buffer_size =
+    6073                 :            :         spdm_context->transcript.message_m.max_buffer_size;
+    6074                 :            :     spdm_context->transcript.message_b.buffer_size =
+    6075                 :            :         spdm_context->transcript.message_b.max_buffer_size;
+    6076                 :            :     spdm_context->transcript.message_c.buffer_size =
+    6077                 :            :         spdm_context->transcript.message_c.max_buffer_size;
+    6078                 :            :     spdm_context->transcript.message_mut_b.buffer_size =
+    6079                 :            :         spdm_context->transcript.message_mut_b.max_buffer_size;
+    6080                 :            :     spdm_context->transcript.message_mut_c.buffer_size =
+    6081                 :            :         spdm_context->transcript.message_mut_c.max_buffer_size;
+    6082                 :            : #endif
+    6083                 :            : 
+    6084                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    6085                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    6086                 :            :         data_size;
+    6087                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    6088                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    6089                 :            :                      data, data_size);
+    6090                 :            : #else
+    6091                 :          1 :     libspdm_hash_all(
+    6092                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    6093                 :            :         data, data_size,
+    6094                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    6095                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    6096                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    6097                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    6098                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    6099                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    6100                 :            :         data, data_size,
+    6101                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    6102                 :            : #endif
+    6103                 :            : 
+    6104                 :          1 :     heartbeat_period = 0;
+    6105                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    6106                 :          1 :     status = libspdm_send_receive_key_exchange(
+    6107                 :            :         spdm_context,
+    6108                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    6109                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    6110                 :            :         measurement_hash);
+    6111                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    6112                 :          1 :     assert_int_equal(
+    6113                 :            :         libspdm_secured_message_get_session_state(
+    6114                 :            :             spdm_context->session_info[0].secured_message_context),
+    6115                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    6116                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    6117                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+    6118                 :            :     assert_int_equal(spdm_context->transcript.message_b.buffer_size, 0);
+    6119                 :            :     assert_int_equal(spdm_context->transcript.message_c.buffer_size, 0);
+    6120                 :            :     assert_int_equal(spdm_context->transcript.message_mut_b.buffer_size, 0);
+    6121                 :            :     assert_int_equal(spdm_context->transcript.message_mut_c.buffer_size, 0);
+    6122                 :            : #endif
+    6123                 :          1 :     free(data);
+    6124                 :          1 : }
+    6125                 :            : 
+    6126                 :          1 : static void libspdm_test_requester_key_exchange_case12(void **state)
+    6127                 :            : {
+    6128                 :            :     libspdm_return_t status;
+    6129                 :            :     libspdm_test_context_t *spdm_test_context;
+    6130                 :            :     libspdm_context_t *spdm_context;
+    6131                 :            :     uint32_t session_id;
+    6132                 :            :     uint8_t heartbeat_period;
+    6133                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    6134                 :            :     uint8_t slot_id_param;
+    6135                 :            :     void *data;
+    6136                 :            :     size_t data_size;
+    6137                 :            :     void *hash;
+    6138                 :            :     size_t hash_size;
+    6139                 :            : 
+    6140                 :          1 :     spdm_test_context = *state;
+    6141                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    6142                 :            : 
+    6143         [ +  - ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    6144                 :          1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    6145                 :            :     }
+    6146                 :            : 
+    6147                 :          1 :     spdm_test_context->case_id = 0xC;
+    6148                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    6149                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    6150                 :          1 :     spdm_context->connection_info.connection_state =
+    6151                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    6152                 :          1 :     spdm_context->connection_info.capability.flags |=
+    6153                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    6154                 :          1 :     spdm_context->connection_info.capability.flags |=
+    6155                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    6156                 :          1 :     spdm_context->local_context.capability.flags |=
+    6157                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    6158                 :            : 
+    6159                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    6160                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    6161                 :            :                                                     &data_size, &hash, &hash_size);
+    6162                 :          1 :     libspdm_reset_message_a(spdm_context);
+    6163                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    6164                 :            :         m_libspdm_use_hash_algo;
+    6165                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    6166                 :            :         m_libspdm_use_asym_algo;
+    6167                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    6168                 :            :         m_libspdm_use_dhe_algo;
+    6169                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    6170                 :            :         m_libspdm_use_aead_algo;
+    6171                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    6172                 :            :         m_libspdm_use_measurement_hash_algo;
+    6173                 :            : 
+    6174                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    6175                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    6176                 :            :         data_size;
+    6177                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    6178                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    6179                 :            :                      data, data_size);
+    6180                 :            : #else
+    6181                 :          1 :     libspdm_hash_all(
+    6182                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    6183                 :            :         data, data_size,
+    6184                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    6185                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    6186                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    6187                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    6188                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    6189                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    6190                 :            :         data, data_size,
+    6191                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    6192                 :            : #endif
+    6193                 :            : 
+    6194                 :          1 :     heartbeat_period = 0;
+    6195                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    6196                 :          1 :     status = libspdm_send_receive_key_exchange(
+    6197                 :            :         spdm_context,
+    6198                 :            :         SPDM_KEY_EXCHANGE_REQUEST_TCB_COMPONENT_MEASUREMENT_HASH, 0, 0,
+    6199                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    6200                 :            :         measurement_hash);
+    6201                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    6202                 :          1 :     assert_int_equal(session_id, 0xFFFFFFFF);
+    6203                 :          1 :     assert_memory_equal(
+    6204                 :            :         measurement_hash,
+    6205                 :            :         m_libspdm_use_tcb_hash_value,
+    6206                 :            :         libspdm_get_hash_size(m_libspdm_use_hash_algo));
+    6207                 :          1 :     assert_int_equal(
+    6208                 :            :         libspdm_secured_message_get_session_state(
+    6209                 :            :             spdm_context->session_info[0].secured_message_context),
+    6210                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    6211                 :          1 :     free(data);
+    6212                 :          1 : }
+    6213                 :            : 
+    6214                 :          1 : static void libspdm_test_requester_key_exchange_case13(void **state)
+    6215                 :            : {
+    6216                 :            :     libspdm_return_t status;
+    6217                 :            :     libspdm_test_context_t *spdm_test_context;
+    6218                 :            :     libspdm_context_t *spdm_context;
+    6219                 :            :     uint32_t session_id;
+    6220                 :            :     uint8_t heartbeat_period;
+    6221                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    6222                 :            :     uint8_t slot_id_param;
+    6223                 :            :     void *data;
+    6224                 :            :     size_t data_size;
+    6225                 :            :     void *hash;
+    6226                 :            :     size_t hash_size;
+    6227                 :            : 
+    6228                 :          1 :     spdm_test_context = *state;
+    6229                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    6230                 :            : 
+    6231         [ +  - ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    6232                 :          1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    6233                 :            :     }
+    6234                 :            : 
+    6235                 :          1 :     spdm_test_context->case_id = 0xD;
+    6236                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    6237                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    6238                 :          1 :     spdm_context->connection_info.connection_state =
+    6239                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    6240                 :          1 :     spdm_context->connection_info.capability.flags |=
+    6241                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    6242                 :          1 :     spdm_context->connection_info.capability.flags |=
+    6243                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    6244                 :          1 :     spdm_context->local_context.capability.flags |=
+    6245                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    6246                 :            : 
+    6247                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    6248                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    6249                 :            :                                                     &data_size, &hash, &hash_size);
+    6250                 :          1 :     libspdm_reset_message_a(spdm_context);
+    6251                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    6252                 :            :         m_libspdm_use_hash_algo;
+    6253                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    6254                 :            :         m_libspdm_use_asym_algo;
+    6255                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    6256                 :            :         m_libspdm_use_dhe_algo;
+    6257                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    6258                 :            :         m_libspdm_use_aead_algo;
+    6259                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    6260                 :            :         m_libspdm_use_measurement_hash_algo;
+    6261                 :            : 
+    6262                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    6263                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    6264                 :            :         data_size;
+    6265                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    6266                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    6267                 :            :                      data, data_size);
+    6268                 :            : #else
+    6269                 :          1 :     libspdm_hash_all(
+    6270                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    6271                 :            :         data, data_size,
+    6272                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    6273                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    6274                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    6275                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    6276                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    6277                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    6278                 :            :         data, data_size,
+    6279                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    6280                 :            : #endif
+    6281                 :            : 
+    6282                 :          1 :     heartbeat_period = 0;
+    6283                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    6284                 :          1 :     status = libspdm_send_receive_key_exchange(
+    6285                 :            :         spdm_context,
+    6286                 :            :         SPDM_KEY_EXCHANGE_REQUEST_TCB_COMPONENT_MEASUREMENT_HASH, 0, 0,
+    6287                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    6288                 :            :         measurement_hash);
+    6289                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    6290                 :          1 :     assert_int_equal(session_id, 0xFFFFFFFF);
+    6291                 :          1 :     assert_memory_equal(
+    6292                 :            :         measurement_hash,
+    6293                 :            :         m_libspdm_zero_filled_buffer,
+    6294                 :            :         libspdm_get_hash_size(m_libspdm_use_hash_algo));
+    6295                 :          1 :     assert_int_equal(
+    6296                 :            :         libspdm_secured_message_get_session_state(
+    6297                 :            :             spdm_context->session_info[0].secured_message_context),
+    6298                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    6299                 :          1 :     free(data);
+    6300                 :          1 : }
+    6301                 :            : 
+    6302                 :          1 : static void libspdm_test_requester_key_exchange_case14(void **state)
+    6303                 :            : {
+    6304                 :            :     libspdm_return_t status;
+    6305                 :            :     libspdm_test_context_t *spdm_test_context;
+    6306                 :            :     libspdm_context_t *spdm_context;
+    6307                 :            :     uint32_t session_id;
+    6308                 :            :     uint8_t heartbeat_period;
+    6309                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    6310                 :            :     uint8_t slot_id_param;
+    6311                 :            :     void *data;
+    6312                 :            :     size_t data_size;
+    6313                 :            :     void *hash;
+    6314                 :            :     size_t hash_size;
+    6315                 :            : 
+    6316                 :          1 :     spdm_test_context = *state;
+    6317                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    6318                 :            : 
+    6319         [ +  - ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    6320                 :          1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    6321                 :            :     }
+    6322                 :            : 
+    6323                 :          1 :     spdm_test_context->case_id = 0xE;
+    6324                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    6325                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    6326                 :          1 :     spdm_context->connection_info.connection_state =
+    6327                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    6328                 :          1 :     spdm_context->connection_info.capability.flags |=
+    6329                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    6330                 :          1 :     spdm_context->connection_info.capability.flags |=
+    6331                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    6332                 :          1 :     spdm_context->local_context.capability.flags |=
+    6333                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    6334                 :            : 
+    6335                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    6336                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    6337                 :            :                                                     &data_size, &hash, &hash_size);
+    6338                 :          1 :     libspdm_reset_message_a(spdm_context);
+    6339                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    6340                 :            :         m_libspdm_use_hash_algo;
+    6341                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    6342                 :            :         m_libspdm_use_asym_algo;
+    6343                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    6344                 :            :         m_libspdm_use_dhe_algo;
+    6345                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    6346                 :            :         m_libspdm_use_aead_algo;
+    6347                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    6348                 :            :         m_libspdm_use_measurement_hash_algo;
+    6349                 :            : 
+    6350                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    6351                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    6352                 :            :         data_size;
+    6353                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    6354                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    6355                 :            :                      data, data_size);
+    6356                 :            : #else
+    6357                 :          1 :     libspdm_hash_all(
+    6358                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    6359                 :            :         data, data_size,
+    6360                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    6361                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    6362                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    6363                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    6364                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    6365                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    6366                 :            :         data, data_size,
+    6367                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    6368                 :            : #endif
+    6369                 :            : 
+    6370                 :          1 :     heartbeat_period = 0;
+    6371                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    6372                 :          1 :     status = libspdm_send_receive_key_exchange(
+    6373                 :            :         spdm_context,
+    6374                 :            :         SPDM_KEY_EXCHANGE_REQUEST_ALL_MEASUREMENTS_HASH, 0, 0,
+    6375                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    6376                 :            :         measurement_hash);
+    6377                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    6378                 :          1 :     assert_int_equal(session_id, 0xFFFFFFFF);
+    6379                 :          1 :     assert_memory_equal(
+    6380                 :            :         measurement_hash,
+    6381                 :            :         m_libspdm_use_tcb_hash_value,
+    6382                 :            :         libspdm_get_hash_size(m_libspdm_use_hash_algo));
+    6383                 :          1 :     assert_int_equal(
+    6384                 :            :         libspdm_secured_message_get_session_state(
+    6385                 :            :             spdm_context->session_info[0].secured_message_context),
+    6386                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    6387                 :          1 :     free(data);
+    6388                 :          1 : }
+    6389                 :            : 
+    6390                 :          1 : static void libspdm_test_requester_key_exchange_case15(void **state)
+    6391                 :            : {
+    6392                 :            :     libspdm_return_t status;
+    6393                 :            :     libspdm_test_context_t *spdm_test_context;
+    6394                 :            :     libspdm_context_t *spdm_context;
+    6395                 :            :     uint32_t session_id;
+    6396                 :            :     uint8_t heartbeat_period;
+    6397                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    6398                 :            :     uint8_t slot_id_param;
+    6399                 :            :     void *data;
+    6400                 :            :     size_t data_size;
+    6401                 :            :     void *hash;
+    6402                 :            :     size_t hash_size;
+    6403                 :            : 
+    6404                 :          1 :     spdm_test_context = *state;
+    6405                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    6406                 :            : 
+    6407         [ +  - ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    6408                 :          1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    6409                 :            :     }
+    6410                 :            : 
+    6411                 :          1 :     spdm_test_context->case_id = 0xF;
+    6412                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    6413                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    6414                 :          1 :     spdm_context->connection_info.connection_state =
+    6415                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    6416                 :          1 :     spdm_context->connection_info.capability.flags |=
+    6417                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    6418                 :          1 :     spdm_context->connection_info.capability.flags |=
+    6419                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    6420                 :          1 :     spdm_context->local_context.capability.flags |=
+    6421                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    6422                 :            : 
+    6423                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    6424                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    6425                 :            :                                                     &data_size, &hash, &hash_size);
+    6426                 :          1 :     libspdm_reset_message_a(spdm_context);
+    6427                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    6428                 :            :         m_libspdm_use_hash_algo;
+    6429                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    6430                 :            :         m_libspdm_use_asym_algo;
+    6431                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    6432                 :            :         m_libspdm_use_dhe_algo;
+    6433                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    6434                 :            :         m_libspdm_use_aead_algo;
+    6435                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    6436                 :            :         m_libspdm_use_measurement_hash_algo;
+    6437                 :            : 
+    6438                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    6439                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    6440                 :            :         data_size;
+    6441                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    6442                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    6443                 :            :                      data, data_size);
+    6444                 :            : #else
+    6445                 :          1 :     libspdm_hash_all(
+    6446                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    6447                 :            :         data, data_size,
+    6448                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    6449                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    6450                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    6451                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    6452                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    6453                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    6454                 :            :         data, data_size,
+    6455                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    6456                 :            : #endif
+    6457                 :            : 
+    6458                 :          1 :     heartbeat_period = 0;
+    6459                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    6460                 :          1 :     status = libspdm_send_receive_key_exchange(
+    6461                 :            :         spdm_context,
+    6462                 :            :         SPDM_KEY_EXCHANGE_REQUEST_TCB_COMPONENT_MEASUREMENT_HASH, 0, 0,
+    6463                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    6464                 :            :         measurement_hash);
+    6465                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
+    6466                 :          1 :     free(data);
+    6467                 :          1 : }
+    6468                 :            : 
+    6469                 :          1 : static void libspdm_test_requester_key_exchange_case16(void **state)
+    6470                 :            : {
+    6471                 :            :     libspdm_return_t status;
+    6472                 :            :     libspdm_test_context_t *spdm_test_context;
+    6473                 :            :     libspdm_context_t *spdm_context;
+    6474                 :            :     uint32_t session_id;
+    6475                 :            :     uint8_t heartbeat_period;
+    6476                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    6477                 :            :     uint8_t slot_id_param;
+    6478                 :            :     void *data;
+    6479                 :            :     size_t data_size;
+    6480                 :            :     void *hash;
+    6481                 :            :     size_t hash_size;
+    6482                 :            : 
+    6483                 :          1 :     spdm_test_context = *state;
+    6484                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    6485                 :            : 
+    6486         [ -  + ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    6487                 :          0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    6488                 :            :     }
+    6489                 :            : 
+    6490                 :          1 :     spdm_test_context->case_id = 0x10;
+    6491                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    6492                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    6493                 :          1 :     spdm_context->connection_info.connection_state =
+    6494                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    6495                 :          1 :     spdm_context->connection_info.capability.flags |=
+    6496                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    6497                 :          1 :     spdm_context->connection_info.capability.flags |=
+    6498                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    6499                 :          1 :     spdm_context->local_context.capability.flags |=
+    6500                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    6501                 :            : 
+    6502                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    6503                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    6504                 :            :                                                     &data_size, &hash, &hash_size);
+    6505                 :          1 :     libspdm_reset_message_a(spdm_context);
+    6506                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    6507                 :            :         m_libspdm_use_hash_algo;
+    6508                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    6509                 :            :         m_libspdm_use_asym_algo;
+    6510                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    6511                 :            :         m_libspdm_use_dhe_algo;
+    6512                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    6513                 :            :         m_libspdm_use_aead_algo;
+    6514                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    6515                 :            :         m_libspdm_use_measurement_hash_algo;
+    6516                 :            : 
+    6517                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    6518                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    6519                 :            :         data_size;
+    6520                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    6521                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    6522                 :            :                      data, data_size);
+    6523                 :            : #else
+    6524                 :          1 :     libspdm_hash_all(
+    6525                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    6526                 :            :         data, data_size,
+    6527                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    6528                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    6529                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    6530                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    6531                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    6532                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    6533                 :            :         data, data_size,
+    6534                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    6535                 :            : #endif
+    6536                 :            : 
+    6537                 :          1 :     heartbeat_period = 0;
+    6538                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    6539                 :          1 :     status = libspdm_send_receive_key_exchange(
+    6540                 :            :         spdm_context,
+    6541                 :            :         SPDM_KEY_EXCHANGE_REQUEST_ALL_MEASUREMENTS_HASH, 0, 0,
+    6542                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    6543                 :            :         measurement_hash);
+    6544                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
+    6545                 :          1 :     free(data);
+    6546                 :          1 : }
+    6547                 :            : 
+    6548                 :          1 : static void libspdm_test_requester_key_exchange_case17(void **state)
+    6549                 :            : {
+    6550                 :            :     libspdm_return_t status;
+    6551                 :            :     libspdm_test_context_t *spdm_test_context;
+    6552                 :            :     libspdm_context_t *spdm_context;
+    6553                 :            :     uint32_t session_id;
+    6554                 :            :     uint8_t heartbeat_period;
+    6555                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    6556                 :            :     uint8_t slot_id_param;
+    6557                 :            :     void *data;
+    6558                 :            :     size_t data_size;
+    6559                 :            :     void *hash;
+    6560                 :            :     size_t hash_size;
+    6561                 :            : 
+    6562                 :          1 :     spdm_test_context = *state;
+    6563                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    6564                 :            : 
+    6565         [ -  + ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    6566                 :          0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    6567                 :            :     }
+    6568                 :            : 
+    6569                 :          1 :     spdm_test_context->case_id = 0x11;
+    6570                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    6571                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    6572                 :          1 :     spdm_context->connection_info.connection_state =
+    6573                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    6574                 :          1 :     spdm_context->connection_info.capability.flags |=
+    6575                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    6576                 :          1 :     spdm_context->connection_info.capability.flags |=
+    6577                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    6578                 :          1 :     spdm_context->local_context.capability.flags |=
+    6579                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    6580                 :            : 
+    6581                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    6582                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    6583                 :            :                                                     &data_size, &hash, &hash_size);
+    6584                 :          1 :     libspdm_reset_message_a(spdm_context);
+    6585                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    6586                 :            :         m_libspdm_use_hash_algo;
+    6587                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    6588                 :            :         m_libspdm_use_asym_algo;
+    6589                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    6590                 :            :         m_libspdm_use_dhe_algo;
+    6591                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    6592                 :            :         m_libspdm_use_aead_algo;
+    6593                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    6594                 :            :         m_libspdm_use_measurement_hash_algo;
+    6595                 :            : 
+    6596                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    6597                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    6598                 :            :         data_size;
+    6599                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    6600                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    6601                 :            :                      data, data_size);
+    6602                 :            : #else
+    6603                 :          1 :     libspdm_hash_all(
+    6604                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    6605                 :            :         data, data_size,
+    6606                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    6607                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    6608                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    6609                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    6610                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    6611                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    6612                 :            :         data, data_size,
+    6613                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    6614                 :            : #endif
+    6615                 :            : 
+    6616                 :          1 :     heartbeat_period = 0;
+    6617                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    6618                 :          1 :     status = libspdm_send_receive_key_exchange(
+    6619                 :            :         spdm_context,
+    6620                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    6621                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    6622                 :            :         measurement_hash);
+    6623                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
+    6624                 :          1 :     free(data);
+    6625                 :          1 : }
+    6626                 :            : 
+    6627                 :          1 : static void libspdm_test_requester_key_exchange_case18(void **state)
+    6628                 :            : {
+    6629                 :            :     libspdm_return_t status;
+    6630                 :            :     libspdm_test_context_t *spdm_test_context;
+    6631                 :            :     libspdm_context_t *spdm_context;
+    6632                 :            :     uint32_t session_id;
+    6633                 :            :     uint8_t heartbeat_period;
+    6634                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    6635                 :            :     uint8_t slot_id_param;
+    6636                 :            :     void *data;
+    6637                 :            :     size_t data_size;
+    6638                 :            :     void *hash;
+    6639                 :            :     size_t hash_size;
+    6640                 :            : 
+    6641                 :          1 :     spdm_test_context = *state;
+    6642                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    6643                 :            : 
+    6644         [ -  + ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    6645                 :          0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    6646                 :            :     }
+    6647                 :            : 
+    6648                 :          1 :     spdm_test_context->case_id = 0x12;
+    6649                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    6650                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    6651                 :          1 :     spdm_context->connection_info.connection_state =
+    6652                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    6653                 :          1 :     spdm_context->connection_info.capability.flags |=
+    6654                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    6655                 :          1 :     spdm_context->connection_info.capability.flags |=
+    6656                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    6657                 :          1 :     spdm_context->local_context.capability.flags |=
+    6658                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    6659                 :            : 
+    6660                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    6661                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    6662                 :            :                                                     &data_size, &hash, &hash_size);
+    6663                 :          1 :     libspdm_reset_message_a(spdm_context);
+    6664                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    6665                 :            :         m_libspdm_use_hash_algo;
+    6666                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    6667                 :            :         m_libspdm_use_asym_algo;
+    6668                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    6669                 :            :         m_libspdm_use_dhe_algo;
+    6670                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    6671                 :            :         m_libspdm_use_aead_algo;
+    6672                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    6673                 :            :         m_libspdm_use_measurement_hash_algo;
+    6674                 :            : 
+    6675                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    6676                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    6677                 :            :         data_size;
+    6678                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    6679                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    6680                 :            :                      data, data_size);
+    6681                 :            : #else
+    6682                 :          1 :     libspdm_hash_all(
+    6683                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    6684                 :            :         data, data_size,
+    6685                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    6686                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    6687                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    6688                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    6689                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    6690                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    6691                 :            :         data, data_size,
+    6692                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    6693                 :            : #endif
+    6694                 :            : 
+    6695                 :          1 :     heartbeat_period = 0;
+    6696                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    6697                 :          1 :     status = libspdm_send_receive_key_exchange(
+    6698                 :            :         spdm_context,
+    6699                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    6700                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    6701                 :            :         measurement_hash);
+    6702                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_VERIF_FAIL);
+    6703                 :          1 :     free(data);
+    6704                 :          1 : }
+    6705                 :            : 
+    6706                 :          1 : static void libspdm_test_requester_key_exchange_case19(void **state)
+    6707                 :            : {
+    6708                 :            :     libspdm_return_t status;
+    6709                 :            :     libspdm_test_context_t *spdm_test_context;
+    6710                 :            :     libspdm_context_t *spdm_context;
+    6711                 :            :     uint32_t session_id;
+    6712                 :            :     uint8_t heartbeat_period;
+    6713                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    6714                 :            :     uint8_t slot_id_param;
+    6715                 :            :     void *data;
+    6716                 :            :     size_t data_size;
+    6717                 :            :     void *hash;
+    6718                 :            :     size_t hash_size;
+    6719                 :            : 
+    6720                 :          1 :     spdm_test_context = *state;
+    6721                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    6722                 :          1 :     spdm_test_context->case_id = 0x13;
+    6723                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    6724                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    6725                 :          1 :     spdm_context->connection_info.connection_state =
+    6726                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    6727                 :          1 :     spdm_context->connection_info.capability.flags |=
+    6728                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    6729                 :          1 :     spdm_context->connection_info.capability.flags |=
+    6730                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    6731                 :          1 :     spdm_context->local_context.capability.flags |=
+    6732                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    6733                 :            : 
+    6734                 :          1 :     spdm_context->connection_info.capability.flags |=
+    6735                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    6736                 :          1 :     spdm_context->local_context.capability.flags |=
+    6737                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    6738                 :            : 
+    6739                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    6740                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    6741                 :            :                                                     &data_size, &hash, &hash_size);
+    6742                 :          1 :     libspdm_reset_message_a(spdm_context);
+    6743                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    6744                 :            :         m_libspdm_use_hash_algo;
+    6745                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    6746                 :            :         m_libspdm_use_asym_algo;
+    6747                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    6748                 :            :         m_libspdm_use_dhe_algo;
+    6749                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    6750                 :            :         m_libspdm_use_aead_algo;
+    6751                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    6752                 :            :         m_libspdm_use_measurement_hash_algo;
+    6753                 :            : 
+    6754                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    6755                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    6756                 :            :         data_size;
+    6757                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    6758                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    6759                 :            :                      data, data_size);
+    6760                 :            : #else
+    6761                 :          1 :     libspdm_hash_all(
+    6762                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    6763                 :            :         data, data_size,
+    6764                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    6765                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    6766                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    6767                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    6768                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    6769                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    6770                 :            :         data, data_size,
+    6771                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    6772                 :            : #endif
+    6773                 :            : 
+    6774                 :          1 :     heartbeat_period = 0;
+    6775                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    6776                 :          1 :     status = libspdm_send_receive_key_exchange(
+    6777                 :            :         spdm_context,
+    6778                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    6779                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    6780                 :            :         measurement_hash);
+    6781                 :            :     /* Clear Handshake in the clear flags */
+    6782                 :          1 :     spdm_context->connection_info.capability.flags &=
+    6783                 :            :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    6784                 :          1 :     spdm_context->local_context.capability.flags &=
+    6785                 :            :         ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    6786                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    6787                 :          1 :     assert_int_equal(session_id, 0xFFFFFFFF);
+    6788                 :          1 :     assert_int_equal(
+    6789                 :            :         libspdm_secured_message_get_session_state(
+    6790                 :            :             spdm_context->session_info[0].secured_message_context),
+    6791                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    6792                 :          1 :     free(data);
+    6793                 :          1 : }
+    6794                 :            : 
+    6795                 :          1 : static void libspdm_test_requester_key_exchange_case20(void **state)
+    6796                 :            : {
+    6797                 :            :     libspdm_return_t status;
+    6798                 :            :     libspdm_test_context_t *spdm_test_context;
+    6799                 :            :     libspdm_context_t *spdm_context;
+    6800                 :            :     uint32_t session_id;
+    6801                 :            :     uint8_t heartbeat_period;
+    6802                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    6803                 :            :     uint8_t slot_id_param;
+    6804                 :            :     void *data;
+    6805                 :            :     size_t data_size;
+    6806                 :            :     void *hash;
+    6807                 :            :     size_t hash_size;
+    6808                 :            : 
+    6809                 :          1 :     spdm_test_context = *state;
+    6810                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    6811                 :            : 
+    6812         [ +  - ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    6813                 :          1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    6814                 :            :     }
+    6815                 :            : 
+    6816                 :          1 :     spdm_test_context->case_id = 0x14;
+    6817                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    6818                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    6819                 :          1 :     spdm_context->connection_info.connection_state =
+    6820                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    6821                 :          1 :     spdm_context->connection_info.capability.flags |=
+    6822                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    6823                 :          1 :     spdm_context->connection_info.capability.flags |=
+    6824                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    6825                 :          1 :     spdm_context->local_context.capability.flags |=
+    6826                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    6827                 :            : 
+    6828                 :            : 
+    6829                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    6830                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    6831                 :            :                                                     &data_size, &hash, &hash_size);
+    6832                 :          1 :     libspdm_reset_message_a(spdm_context);
+    6833                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    6834                 :            :         m_libspdm_use_hash_algo;
+    6835                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    6836                 :            :         m_libspdm_use_asym_algo;
+    6837                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    6838                 :            :         m_libspdm_use_dhe_algo;
+    6839                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    6840                 :            :         m_libspdm_use_aead_algo;
+    6841                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    6842                 :            :         m_libspdm_use_measurement_hash_algo;
+    6843                 :            : 
+    6844                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    6845                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    6846                 :            :         data_size;
+    6847                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    6848                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    6849                 :            :                      data, data_size);
+    6850                 :            : #else
+    6851                 :          1 :     libspdm_hash_all(
+    6852                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    6853                 :            :         data, data_size,
+    6854                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    6855                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    6856                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    6857                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    6858                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    6859                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    6860                 :            :         data, data_size,
+    6861                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    6862                 :            : #endif
+    6863                 :            : 
+    6864                 :          1 :     heartbeat_period = 0;
+    6865                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    6866                 :          1 :     status = libspdm_send_receive_key_exchange(
+    6867                 :            :         spdm_context,
+    6868                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    6869                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    6870                 :            :         measurement_hash);
+    6871                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    6872                 :          1 :     free(data);
+    6873                 :          1 : }
+    6874                 :            : 
+    6875                 :          1 : static void libspdm_test_requester_key_exchange_case21(void **state)
+    6876                 :            : {
+    6877                 :            :     libspdm_return_t status;
+    6878                 :            :     libspdm_test_context_t *spdm_test_context;
+    6879                 :            :     libspdm_context_t *spdm_context;
+    6880                 :            :     uint32_t session_id;
+    6881                 :            :     uint8_t heartbeat_period;
+    6882                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    6883                 :            :     uint8_t slot_id_param;
+    6884                 :            :     void *data;
+    6885                 :            :     size_t data_size;
+    6886                 :            :     void *hash;
+    6887                 :            :     size_t hash_size;
+    6888                 :            : 
+    6889                 :          1 :     spdm_test_context = *state;
+    6890                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    6891                 :            : 
+    6892         [ -  + ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    6893                 :          0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    6894                 :            :     }
+    6895                 :            : 
+    6896                 :          1 :     spdm_test_context->case_id = 0x15;
+    6897                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    6898                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    6899                 :          1 :     spdm_context->connection_info.connection_state =
+    6900                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    6901                 :          1 :     spdm_context->connection_info.capability.flags |=
+    6902                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    6903                 :          1 :     spdm_context->connection_info.capability.flags |=
+    6904                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    6905                 :          1 :     spdm_context->local_context.capability.flags |=
+    6906                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    6907                 :            : 
+    6908                 :          1 :     spdm_context->connection_info.capability.flags |=
+    6909                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP;
+    6910                 :          1 :     spdm_context->local_context.capability.flags |=
+    6911                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP;
+    6912                 :            : 
+    6913                 :            : 
+    6914                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    6915                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    6916                 :            :                                                     &data_size, &hash, &hash_size);
+    6917                 :          1 :     libspdm_reset_message_a(spdm_context);
+    6918                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    6919                 :            :         m_libspdm_use_hash_algo;
+    6920                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    6921                 :            :         m_libspdm_use_asym_algo;
+    6922                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    6923                 :            :         m_libspdm_use_dhe_algo;
+    6924                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    6925                 :            :         m_libspdm_use_aead_algo;
+    6926                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    6927                 :            :         m_libspdm_use_measurement_hash_algo;
+    6928                 :            : 
+    6929                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    6930                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    6931                 :            :         data_size;
+    6932                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    6933                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    6934                 :            :                      data, data_size);
+    6935                 :            : #else
+    6936                 :          1 :     libspdm_hash_all(
+    6937                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    6938                 :            :         data, data_size,
+    6939                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    6940                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    6941                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    6942                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    6943                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    6944                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    6945                 :            :         data, data_size,
+    6946                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    6947                 :            : #endif
+    6948                 :            : 
+    6949                 :          1 :     heartbeat_period = 0;
+    6950                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    6951                 :          1 :     status = libspdm_send_receive_key_exchange(
+    6952                 :            :         spdm_context,
+    6953                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    6954                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    6955                 :            :         measurement_hash);
+    6956                 :            :     /* clear Heartbeat flags */
+    6957                 :          1 :     spdm_context->connection_info.capability.flags &=
+    6958                 :            :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP;
+    6959                 :          1 :     spdm_context->local_context.capability.flags &=
+    6960                 :            :         ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP;
+    6961                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    6962                 :          1 :     assert_int_equal(session_id, 0xFFFFFFFF);
+    6963                 :          1 :     assert_int_equal(
+    6964                 :            :         libspdm_secured_message_get_session_state(
+    6965                 :            :             spdm_context->session_info[0].secured_message_context),
+    6966                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    6967                 :          1 :     assert_int_equal(heartbeat_period,5);
+    6968                 :          1 :     free(data);
+    6969                 :          1 : }
+    6970                 :            : 
+    6971                 :          1 : static void libspdm_test_requester_key_exchange_case22(void **state)
+    6972                 :            : {
+    6973                 :            :     libspdm_return_t status;
+    6974                 :            :     libspdm_test_context_t *spdm_test_context;
+    6975                 :            :     libspdm_context_t *spdm_context;
+    6976                 :            :     uint32_t session_id;
+    6977                 :            :     uint8_t heartbeat_period;
+    6978                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    6979                 :            :     uint8_t slot_id_param;
+    6980                 :            :     void *data;
+    6981                 :            :     size_t data_size;
+    6982                 :            :     void *hash;
+    6983                 :            :     size_t hash_size;
+    6984                 :            : 
+    6985                 :          1 :     spdm_test_context = *state;
+    6986                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    6987                 :            : 
+    6988         [ +  - ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    6989                 :          1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    6990                 :            :     }
+    6991                 :            : 
+    6992                 :          1 :     spdm_test_context->case_id = 0x16;
+    6993                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    6994                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    6995                 :          1 :     spdm_context->connection_info.connection_state =
+    6996                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    6997                 :          1 :     spdm_context->connection_info.capability.flags |=
+    6998                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    6999                 :          1 :     spdm_context->connection_info.capability.flags |=
+    7000                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    7001                 :          1 :     spdm_context->local_context.capability.flags |=
+    7002                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    7003                 :            : 
+    7004                 :          1 :     spdm_context->connection_info.capability.flags |=
+    7005                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP;
+    7006                 :          1 :     spdm_context->local_context.capability.flags |=
+    7007                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP;
+    7008                 :            : 
+    7009                 :            : 
+    7010                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    7011                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    7012                 :            :                                                     &data_size, &hash, &hash_size);
+    7013                 :          1 :     libspdm_reset_message_a(spdm_context);
+    7014                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    7015                 :            :         m_libspdm_use_hash_algo;
+    7016                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    7017                 :            :         m_libspdm_use_asym_algo;
+    7018                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    7019                 :            :         m_libspdm_use_dhe_algo;
+    7020                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    7021                 :            :         m_libspdm_use_aead_algo;
+    7022                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    7023                 :            :         m_libspdm_use_measurement_hash_algo;
+    7024                 :            : 
+    7025                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    7026                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    7027                 :            :         data_size;
+    7028                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    7029                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    7030                 :            :                      data, data_size);
+    7031                 :            : #else
+    7032                 :          1 :     libspdm_hash_all(
+    7033                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    7034                 :            :         data, data_size,
+    7035                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    7036                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    7037                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    7038                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    7039                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    7040                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    7041                 :            :         data, data_size,
+    7042                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    7043                 :            : #endif
+    7044                 :            : 
+    7045                 :          1 :     heartbeat_period = 0;
+    7046                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    7047                 :          1 :     status = libspdm_send_receive_key_exchange(
+    7048                 :            :         spdm_context,
+    7049                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    7050                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    7051                 :            :         measurement_hash);
+    7052                 :            : 
+    7053                 :            :     /*clear Heartbeat flags*/
+    7054                 :          1 :     spdm_context->connection_info.capability.flags &=
+    7055                 :            :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP;
+    7056                 :          1 :     spdm_context->local_context.capability.flags &=
+    7057                 :            :         ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP;
+    7058                 :            : 
+    7059                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    7060                 :          1 :     assert_int_equal(session_id, 0xFFFFFFFF);
+    7061                 :          1 :     assert_int_equal(
+    7062                 :            :         libspdm_secured_message_get_session_state(
+    7063                 :            :             spdm_context->session_info[0].secured_message_context),
+    7064                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    7065                 :          1 :     assert_int_equal(heartbeat_period,0);
+    7066                 :          1 :     free(data);
+    7067                 :          1 : }
+    7068                 :            : 
+    7069                 :          1 : static void libspdm_test_requester_key_exchange_case23(void **state)
+    7070                 :            : {
+    7071                 :            :     libspdm_return_t status;
+    7072                 :            :     libspdm_test_context_t *spdm_test_context;
+    7073                 :            :     libspdm_context_t *spdm_context;
+    7074                 :            :     uint32_t session_id;
+    7075                 :            :     uint8_t heartbeat_period;
+    7076                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    7077                 :            :     uint8_t slot_id_param;
+    7078                 :            :     void *data;
+    7079                 :            :     size_t data_size;
+    7080                 :            :     void *hash;
+    7081                 :            :     size_t hash_size;
+    7082                 :            : 
+    7083                 :          1 :     spdm_test_context = *state;
+    7084                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    7085                 :            : 
+    7086         [ +  - ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    7087                 :          1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    7088                 :            :     }
+    7089                 :            : 
+    7090                 :          1 :     spdm_test_context->case_id = 0x17;
+    7091                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    7092                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    7093                 :          1 :     spdm_context->connection_info.connection_state =
+    7094                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    7095                 :          1 :     spdm_context->connection_info.capability.flags |=
+    7096                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    7097                 :          1 :     spdm_context->connection_info.capability.flags |=
+    7098                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    7099                 :          1 :     spdm_context->local_context.capability.flags |=
+    7100                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    7101                 :            : 
+    7102                 :          1 :     spdm_context->connection_info.capability.flags |=
+    7103                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    7104                 :          1 :     spdm_context->local_context.capability.flags |=
+    7105                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    7106                 :            : 
+    7107                 :            : 
+    7108                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    7109                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    7110                 :            :                                                     &data_size, &hash, &hash_size);
+    7111                 :          1 :     libspdm_reset_message_a(spdm_context);
+    7112                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    7113                 :            :         m_libspdm_use_hash_algo;
+    7114                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    7115                 :            :         m_libspdm_use_asym_algo;
+    7116                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    7117                 :            :         m_libspdm_use_dhe_algo;
+    7118                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    7119                 :            :         m_libspdm_use_aead_algo;
+    7120                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    7121                 :            :         m_libspdm_use_measurement_hash_algo;
+    7122                 :            : 
+    7123                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    7124                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    7125                 :            :         data_size;
+    7126                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    7127                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    7128                 :            :                      data, data_size);
+    7129                 :            : #else
+    7130                 :          1 :     libspdm_hash_all(
+    7131                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    7132                 :            :         data, data_size,
+    7133                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    7134                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    7135                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    7136                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    7137                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    7138                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    7139                 :            :         data, data_size,
+    7140                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    7141                 :            : #endif
+    7142                 :            : 
+    7143                 :          1 :     heartbeat_period = 0;
+    7144                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    7145                 :          1 :     status = libspdm_send_receive_key_exchange(
+    7146                 :            :         spdm_context,
+    7147                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    7148                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    7149                 :            :         measurement_hash);
+    7150                 :            :     /* Clear Mut_auth flags */
+    7151                 :          1 :     spdm_context->connection_info.capability.flags &=
+    7152                 :            :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    7153                 :          1 :     spdm_context->local_context.capability.flags &=
+    7154                 :            :         ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    7155                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    7156                 :          1 :     assert_int_equal(session_id, 0xFFFFFFFF);
+    7157                 :          1 :     assert_int_equal(
+    7158                 :            :         libspdm_secured_message_get_session_state(
+    7159                 :            :             spdm_context->session_info[0].secured_message_context),
+    7160                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    7161                 :          1 :     assert_int_equal(
+    7162                 :            :         spdm_context->session_info[0].mut_auth_requested,
+    7163                 :            :         SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED);
+    7164                 :          1 :     free(data);
+    7165                 :          1 : }
+    7166                 :            : 
+    7167                 :          1 : static void libspdm_test_requester_key_exchange_case24(void **state)
+    7168                 :            : {
+    7169                 :            :     libspdm_return_t status;
+    7170                 :            :     libspdm_test_context_t *spdm_test_context;
+    7171                 :            :     libspdm_context_t *spdm_context;
+    7172                 :            :     uint32_t session_id;
+    7173                 :            :     uint8_t heartbeat_period;
+    7174                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    7175                 :            :     uint8_t slot_id_param;
+    7176                 :            :     void *data;
+    7177                 :            :     size_t data_size;
+    7178                 :            :     void *hash;
+    7179                 :            :     size_t hash_size;
+    7180                 :            : 
+    7181                 :          1 :     spdm_test_context = *state;
+    7182                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    7183                 :            : 
+    7184         [ +  - ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    7185                 :          1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    7186                 :            :     }
+    7187                 :            : 
+    7188                 :          1 :     spdm_test_context->case_id = 0x18;
+    7189                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    7190                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    7191                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    7192                 :          1 :     spdm_context->connection_info.capability.flags |=
+    7193                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    7194                 :          1 :     spdm_context->connection_info.capability.flags |=
+    7195                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    7196                 :          1 :     spdm_context->local_context.capability.flags |=
+    7197                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    7198                 :            : 
+    7199                 :          1 :     spdm_context->connection_info.capability.flags |=
+    7200                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    7201                 :          1 :     spdm_context->local_context.capability.flags |=
+    7202                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    7203                 :            : 
+    7204                 :          1 :     spdm_context->connection_info.capability.flags |=
+    7205                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
+    7206                 :          1 :     spdm_context->local_context.capability.flags |=
+    7207                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
+    7208                 :            : 
+    7209                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    7210                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    7211                 :            :                                                     &data_size, &hash, &hash_size);
+    7212                 :          1 :     libspdm_reset_message_a(spdm_context);
+    7213                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    7214                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    7215                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    7216                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    7217                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    7218                 :            :         m_libspdm_use_measurement_hash_algo;
+    7219                 :            : 
+    7220                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    7221                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    7222                 :            :         data_size;
+    7223                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    7224                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    7225                 :            :                      data, data_size);
+    7226                 :            : #else
+    7227                 :          1 :     libspdm_hash_all(
+    7228                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    7229                 :            :         data, data_size,
+    7230                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    7231                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    7232                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    7233                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    7234                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    7235                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    7236                 :            :         data, data_size,
+    7237                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    7238                 :            : #endif
+    7239                 :            : 
+    7240                 :          1 :     heartbeat_period = 0;
+    7241                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    7242                 :          1 :     status = libspdm_send_receive_key_exchange(
+    7243                 :            :         spdm_context,
+    7244                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    7245                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    7246                 :            :         measurement_hash);
+    7247                 :            :     /* Clear Mut_auth flags */
+    7248                 :          1 :     spdm_context->connection_info.capability.flags &=
+    7249                 :            :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    7250                 :          1 :     spdm_context->local_context.capability.flags &=
+    7251                 :            :         ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    7252                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    7253                 :          1 :     assert_int_equal(session_id, 0xFFFFFFFF);
+    7254                 :          1 :     assert_int_equal(
+    7255                 :            :         libspdm_secured_message_get_session_state(
+    7256                 :            :             spdm_context->session_info[0].secured_message_context),
+    7257                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    7258                 :          1 :     assert_int_equal(
+    7259                 :            :         spdm_context->session_info[0].mut_auth_requested,
+    7260                 :            :         SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_ENCAP_REQUEST);
+    7261                 :          1 :     free(data);
+    7262                 :          1 : }
+    7263                 :            : 
+    7264                 :          1 : static void libspdm_test_requester_key_exchange_case25(void **state)
+    7265                 :            : {
+    7266                 :            :     libspdm_return_t status;
+    7267                 :            :     libspdm_test_context_t *spdm_test_context;
+    7268                 :            :     libspdm_context_t *spdm_context;
+    7269                 :            :     uint32_t session_id;
+    7270                 :            :     uint8_t heartbeat_period;
+    7271                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    7272                 :            :     uint8_t slot_id_param;
+    7273                 :            :     void *data;
+    7274                 :            :     size_t data_size;
+    7275                 :            :     void *hash;
+    7276                 :            :     size_t hash_size;
+    7277                 :            : 
+    7278                 :          1 :     spdm_test_context = *state;
+    7279                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    7280                 :            : 
+    7281         [ +  - ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    7282                 :          1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    7283                 :            :     }
+    7284                 :            : 
+    7285                 :          1 :     spdm_test_context->case_id = 0x19;
+    7286                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    7287                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    7288                 :          1 :     spdm_context->connection_info.connection_state =
+    7289                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    7290                 :          1 :     spdm_context->connection_info.capability.flags |=
+    7291                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    7292                 :          1 :     spdm_context->connection_info.capability.flags |=
+    7293                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    7294                 :          1 :     spdm_context->local_context.capability.flags |=
+    7295                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    7296                 :            : 
+    7297                 :          1 :     spdm_context->connection_info.capability.flags |=
+    7298                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    7299                 :          1 :     spdm_context->local_context.capability.flags |=
+    7300                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    7301                 :            : 
+    7302                 :          1 :     spdm_context->connection_info.capability.flags |=
+    7303                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
+    7304                 :          1 :     spdm_context->local_context.capability.flags |=
+    7305                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
+    7306                 :            : 
+    7307                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    7308                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    7309                 :            :                                                     &data_size, &hash, &hash_size);
+    7310                 :          1 :     libspdm_reset_message_a(spdm_context);
+    7311                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    7312                 :            :         m_libspdm_use_hash_algo;
+    7313                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    7314                 :            :         m_libspdm_use_asym_algo;
+    7315                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    7316                 :            :         m_libspdm_use_dhe_algo;
+    7317                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    7318                 :            :         m_libspdm_use_aead_algo;
+    7319                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    7320                 :            :         m_libspdm_use_measurement_hash_algo;
+    7321                 :            : 
+    7322                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    7323                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    7324                 :            :         data_size;
+    7325                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    7326                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    7327                 :            :                      data, data_size);
+    7328                 :            : #else
+    7329                 :          1 :     libspdm_hash_all(
+    7330                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    7331                 :            :         data, data_size,
+    7332                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    7333                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    7334                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    7335                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    7336                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    7337                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    7338                 :            :         data, data_size,
+    7339                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    7340                 :            : #endif
+    7341                 :            : 
+    7342                 :          1 :     heartbeat_period = 0;
+    7343                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    7344                 :          1 :     status = libspdm_send_receive_key_exchange(
+    7345                 :            :         spdm_context,
+    7346                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    7347                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    7348                 :            :         measurement_hash);
+    7349                 :            :     /* Clear Mut_auth flags */
+    7350                 :          1 :     spdm_context->connection_info.capability.flags &=
+    7351                 :            :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    7352                 :          1 :     spdm_context->local_context.capability.flags &=
+    7353                 :            :         ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    7354                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    7355                 :          1 :     assert_int_equal(session_id, 0xFFFFFFFF);
+    7356                 :          1 :     assert_int_equal(
+    7357                 :            :         libspdm_secured_message_get_session_state(
+    7358                 :            :             spdm_context->session_info[0].secured_message_context),
+    7359                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    7360                 :          1 :     assert_int_equal(
+    7361                 :            :         spdm_context->session_info[0].mut_auth_requested,
+    7362                 :            :         SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_GET_DIGESTS);
+    7363                 :          1 :     free(data);
+    7364                 :          1 : }
+    7365                 :            : 
+    7366                 :          1 : static void libspdm_test_requester_key_exchange_case26(void **state)
+    7367                 :            : {
+    7368                 :            :     libspdm_return_t status;
+    7369                 :            :     libspdm_test_context_t *spdm_test_context;
+    7370                 :            :     libspdm_context_t *spdm_context;
+    7371                 :            :     uint32_t session_id;
+    7372                 :            :     uint8_t heartbeat_period;
+    7373                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    7374                 :            :     uint8_t slot_id_param;
+    7375                 :            :     void *data;
+    7376                 :            :     size_t data_size;
+    7377                 :            :     void *hash;
+    7378                 :            :     size_t hash_size;
+    7379                 :            : 
+    7380                 :          1 :     spdm_test_context = *state;
+    7381                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    7382                 :            : 
+    7383         [ +  - ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    7384                 :          1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    7385                 :            :     }
+    7386                 :            : 
+    7387                 :          1 :     spdm_test_context->case_id = 0x1A;
+    7388                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    7389                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    7390                 :          1 :     spdm_context->connection_info.connection_state =
+    7391                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    7392                 :          1 :     spdm_context->connection_info.capability.flags |=
+    7393                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    7394                 :          1 :     spdm_context->connection_info.capability.flags |=
+    7395                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    7396                 :          1 :     spdm_context->local_context.capability.flags |=
+    7397                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    7398                 :            : 
+    7399                 :          1 :     spdm_context->connection_info.capability.flags |=
+    7400                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    7401                 :          1 :     spdm_context->local_context.capability.flags |=
+    7402                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    7403                 :            : 
+    7404                 :            : 
+    7405                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    7406                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    7407                 :            :                                                     &data_size, &hash, &hash_size);
+    7408                 :          1 :     libspdm_reset_message_a(spdm_context);
+    7409                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    7410                 :            :         m_libspdm_use_hash_algo;
+    7411                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    7412                 :            :         m_libspdm_use_asym_algo;
+    7413                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    7414                 :            :         m_libspdm_use_dhe_algo;
+    7415                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    7416                 :            :         m_libspdm_use_aead_algo;
+    7417                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    7418                 :            :         m_libspdm_use_measurement_hash_algo;
+    7419                 :            : 
+    7420                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    7421                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    7422                 :            :         data_size;
+    7423                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    7424                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    7425                 :            :                      data, data_size);
+    7426                 :            : #else
+    7427                 :          1 :     libspdm_hash_all(
+    7428                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    7429                 :            :         data, data_size,
+    7430                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    7431                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    7432                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    7433                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    7434                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    7435                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    7436                 :            :         data, data_size,
+    7437                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    7438                 :            : #endif
+    7439                 :            : 
+    7440                 :          1 :     heartbeat_period = 0;
+    7441                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    7442                 :          1 :     status = libspdm_send_receive_key_exchange(
+    7443                 :            :         spdm_context,
+    7444                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    7445                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    7446                 :            :         measurement_hash);
+    7447                 :            :     /* Clear Mut_auth flags */
+    7448                 :          1 :     spdm_context->connection_info.capability.flags &=
+    7449                 :            :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    7450                 :          1 :     spdm_context->local_context.capability.flags &=
+    7451                 :            :         ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    7452                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    7453                 :          1 :     free(data);
+    7454                 :          1 : }
+    7455                 :            : 
+    7456                 :          1 : static void libspdm_test_requester_key_exchange_case27(void **state)
+    7457                 :            : {
+    7458                 :            :     libspdm_return_t status;
+    7459                 :            :     libspdm_test_context_t *spdm_test_context;
+    7460                 :            :     libspdm_context_t *spdm_context;
+    7461                 :            :     uint32_t session_id;
+    7462                 :            :     uint8_t heartbeat_period;
+    7463                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    7464                 :            :     uint8_t slot_id_param;
+    7465                 :            :     void *data;
+    7466                 :            :     size_t data_size;
+    7467                 :            :     void *hash;
+    7468                 :            :     size_t hash_size;
+    7469                 :            : 
+    7470                 :          1 :     spdm_test_context = *state;
+    7471                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    7472                 :            : 
+    7473         [ -  + ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    7474                 :          0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    7475                 :            :     }
+    7476                 :            : 
+    7477                 :          1 :     spdm_test_context->case_id = 0x1B;
+    7478                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    7479                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    7480                 :          1 :     spdm_context->connection_info.connection_state =
+    7481                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    7482                 :          1 :     spdm_context->connection_info.capability.flags |=
+    7483                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    7484                 :          1 :     spdm_context->connection_info.capability.flags |=
+    7485                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    7486                 :          1 :     spdm_context->local_context.capability.flags |=
+    7487                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    7488                 :            : 
+    7489                 :          1 :     spdm_context->connection_info.capability.flags |=
+    7490                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    7491                 :          1 :     spdm_context->local_context.capability.flags |=
+    7492                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    7493                 :            : 
+    7494                 :            : 
+    7495                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    7496                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    7497                 :            :                                                     &data_size, &hash, &hash_size);
+    7498                 :          1 :     libspdm_reset_message_a(spdm_context);
+    7499                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    7500                 :            :         m_libspdm_use_hash_algo;
+    7501                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    7502                 :            :         m_libspdm_use_asym_algo;
+    7503                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    7504                 :            :         m_libspdm_use_dhe_algo;
+    7505                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    7506                 :            :         m_libspdm_use_aead_algo;
+    7507                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    7508                 :            :         m_libspdm_use_measurement_hash_algo;
+    7509                 :            : 
+    7510                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    7511                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    7512                 :            :         data_size;
+    7513                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    7514                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    7515                 :            :                      data, data_size);
+    7516                 :            : #else
+    7517                 :          1 :     libspdm_hash_all(
+    7518                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    7519                 :            :         data, data_size,
+    7520                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    7521                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    7522                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    7523                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    7524                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    7525                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    7526                 :            :         data, data_size,
+    7527                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    7528                 :            : #endif
+    7529                 :            : 
+    7530                 :          1 :     heartbeat_period = 0;
+    7531                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    7532                 :          1 :     status = libspdm_send_receive_key_exchange(
+    7533                 :            :         spdm_context,
+    7534                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    7535                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    7536                 :            :         measurement_hash);
+    7537                 :            :     /*Clear Mut_auth flags*/
+    7538                 :          1 :     spdm_context->connection_info.capability.flags &=
+    7539                 :            :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    7540                 :          1 :     spdm_context->local_context.capability.flags &=
+    7541                 :            :         ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    7542                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    7543                 :          1 :     free(data);
+    7544                 :          1 : }
+    7545                 :            : 
+    7546                 :          1 : static void libspdm_test_requester_key_exchange_case28(void **state)
+    7547                 :            : {
+    7548                 :            :     libspdm_return_t status;
+    7549                 :            :     libspdm_test_context_t *spdm_test_context;
+    7550                 :            :     libspdm_context_t *spdm_context;
+    7551                 :            :     uint32_t session_id;
+    7552                 :            :     uint8_t heartbeat_period;
+    7553                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    7554                 :            :     uint8_t slot_id_param;
+    7555                 :            :     void *data;
+    7556                 :            :     size_t data_size;
+    7557                 :            :     void *hash;
+    7558                 :            :     size_t hash_size;
+    7559                 :            : 
+    7560                 :          1 :     spdm_test_context = *state;
+    7561                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    7562                 :            : 
+    7563         [ -  + ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    7564                 :          0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    7565                 :            :     }
+    7566                 :            : 
+    7567                 :          1 :     spdm_test_context->case_id = 0x1C;
+    7568                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    7569                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    7570                 :          1 :     spdm_context->connection_info.connection_state =
+    7571                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    7572                 :          1 :     spdm_context->connection_info.capability.flags |=
+    7573                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    7574                 :          1 :     spdm_context->connection_info.capability.flags |=
+    7575                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    7576                 :          1 :     spdm_context->local_context.capability.flags |=
+    7577                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    7578                 :            : 
+    7579                 :          1 :     spdm_context->connection_info.capability.flags |=
+    7580                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    7581                 :          1 :     spdm_context->local_context.capability.flags |=
+    7582                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    7583                 :            : 
+    7584                 :            : 
+    7585                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    7586                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    7587                 :            :                                                     &data_size, &hash, &hash_size);
+    7588                 :          1 :     libspdm_reset_message_a(spdm_context);
+    7589                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    7590                 :            :         m_libspdm_use_hash_algo;
+    7591                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    7592                 :            :         m_libspdm_use_asym_algo;
+    7593                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    7594                 :            :         m_libspdm_use_dhe_algo;
+    7595                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    7596                 :            :         m_libspdm_use_aead_algo;
+    7597                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    7598                 :            :         m_libspdm_use_measurement_hash_algo;
+    7599                 :            : 
+    7600                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    7601                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    7602                 :            :         data_size;
+    7603                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    7604                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    7605                 :            :                      data, data_size);
+    7606                 :            : #else
+    7607                 :          1 :     libspdm_hash_all(
+    7608                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    7609                 :            :         data, data_size,
+    7610                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    7611                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    7612                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    7613                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    7614                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    7615                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    7616                 :            :         data, data_size,
+    7617                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    7618                 :            : #endif
+    7619                 :            : 
+    7620                 :          1 :     heartbeat_period = 0;
+    7621                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    7622                 :          1 :     status = libspdm_send_receive_key_exchange(
+    7623                 :            :         spdm_context,
+    7624                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    7625                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    7626                 :            :         measurement_hash);
+    7627                 :            :     /* Clear Mut_auth flags */
+    7628                 :          1 :     spdm_context->connection_info.capability.flags &=
+    7629                 :            :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    7630                 :          1 :     spdm_context->local_context.capability.flags &=
+    7631                 :            :         ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    7632                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    7633                 :          1 :     free(data);
+    7634                 :          1 : }
+    7635                 :            : 
+    7636                 :          1 : static void libspdm_test_requester_key_exchange_case29(void **state)
+    7637                 :            : {
+    7638                 :            :     libspdm_return_t status;
+    7639                 :            :     libspdm_test_context_t *spdm_test_context;
+    7640                 :            :     libspdm_context_t *spdm_context;
+    7641                 :            :     uint32_t session_id;
+    7642                 :            :     uint8_t heartbeat_period;
+    7643                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    7644                 :            :     uint8_t slot_id_param;
+    7645                 :            :     void *data;
+    7646                 :            :     size_t data_size;
+    7647                 :            :     void *hash;
+    7648                 :            :     size_t hash_size;
+    7649                 :            : 
+    7650                 :          1 :     spdm_test_context = *state;
+    7651                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    7652                 :            : 
+    7653         [ -  + ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    7654                 :          0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    7655                 :            :     }
+    7656                 :            : 
+    7657                 :          1 :     spdm_test_context->case_id = 0x1D;
+    7658                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    7659                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    7660                 :          1 :     spdm_context->connection_info.connection_state =
+    7661                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    7662                 :          1 :     spdm_context->connection_info.capability.flags |=
+    7663                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    7664                 :          1 :     spdm_context->local_context.capability.flags |=
+    7665                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    7666                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    7667                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    7668                 :            :                                                     &data_size, &hash, &hash_size);
+    7669                 :          1 :     libspdm_reset_message_a(spdm_context);
+    7670                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    7671                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    7672                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    7673                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    7674                 :            : 
+    7675                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    7676                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    7677                 :            :         data_size;
+    7678                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    7679                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    7680                 :            :                      data, data_size);
+    7681                 :            : #else
+    7682                 :          1 :     libspdm_hash_all(
+    7683                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    7684                 :            :         data, data_size,
+    7685                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    7686                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    7687                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    7688                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    7689                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    7690                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    7691                 :            :         data, data_size,
+    7692                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    7693                 :            : #endif
+    7694                 :            : 
+    7695                 :          1 :     heartbeat_period = 0;
+    7696                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    7697                 :          1 :     status = libspdm_send_receive_key_exchange(
+    7698                 :            :         spdm_context,
+    7699                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    7700                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    7701                 :            :         measurement_hash);
+    7702                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    7703                 :          1 :     assert_int_equal(session_id, 0xFFFFFFFF);
+    7704                 :          1 :     assert_int_equal(
+    7705                 :            :         libspdm_secured_message_get_session_state(
+    7706                 :            :             spdm_context->session_info[0].secured_message_context),
+    7707                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    7708                 :            : 
+    7709                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    7710                 :            :     assert_int_equal(spdm_context->session_info[0].session_transcript.message_k.buffer_size,
+    7711                 :            :                      m_libspdm_local_buffer_size);
+    7712                 :            :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer (0x%x):\n",
+    7713                 :            :                    m_libspdm_local_buffer_size));
+    7714                 :            :     libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    7715                 :            :     assert_memory_equal(spdm_context->session_info[0].session_transcript.message_k.buffer,
+    7716                 :            :                         m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    7717                 :            : #endif
+    7718                 :            : 
+    7719                 :          1 :     free(data);
+    7720                 :          1 : }
+    7721                 :            : 
+    7722                 :          1 : static void libspdm_test_requester_key_exchange_case30(void **state)
+    7723                 :            : {
+    7724                 :            :     libspdm_return_t status;
+    7725                 :            :     libspdm_test_context_t *spdm_test_context;
+    7726                 :            :     libspdm_context_t *spdm_context;
+    7727                 :            :     uint32_t session_id;
+    7728                 :            :     uint8_t heartbeat_period;
+    7729                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    7730                 :            :     uint8_t slot_id_param;
+    7731                 :            :     void *data;
+    7732                 :            :     size_t data_size;
+    7733                 :            :     void *hash;
+    7734                 :            :     size_t hash_size;
+    7735                 :            : 
+    7736                 :          1 :     spdm_test_context = *state;
+    7737                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    7738                 :          1 :     spdm_test_context->case_id = 0x1e;
+    7739                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    7740                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    7741                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    7742                 :          1 :     spdm_context->connection_info.capability.flags |=
+    7743                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    7744                 :          1 :     spdm_context->local_context.capability.flags |=
+    7745                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    7746                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
+    7747                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
+    7748                 :            :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    7749                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    7750                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    7751                 :            :                                                     &data_size, &hash, &hash_size);
+    7752                 :          1 :     libspdm_reset_message_a(spdm_context);
+    7753                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    7754                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    7755                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    7756                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    7757                 :          1 :     spdm_context->connection_info.algorithm.other_params_support =
+    7758                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
+    7759                 :          1 :     libspdm_session_info_init(spdm_context,
+    7760                 :          1 :                               spdm_context->session_info,
+    7761                 :            :                               INVALID_SESSION_ID, false);
+    7762                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    7763                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    7764                 :            :         data_size;
+    7765                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    7766                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    7767                 :            :                      data, data_size);
+    7768                 :            : #else
+    7769                 :          1 :     libspdm_hash_all(
+    7770                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    7771                 :            :         data, data_size,
+    7772                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    7773                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    7774                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    7775                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    7776                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    7777                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    7778                 :            :         data, data_size,
+    7779                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    7780                 :            : #endif
+    7781                 :            : 
+    7782                 :          1 :     heartbeat_period = 0;
+    7783                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    7784                 :          1 :     status = libspdm_send_receive_key_exchange(
+    7785                 :            :         spdm_context,
+    7786                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0xFF,
+    7787                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    7788                 :            :         measurement_hash);
+    7789                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    7790                 :          1 :     assert_int_equal(session_id, 0xFFFFFFFF);
+    7791                 :          1 :     assert_int_equal(
+    7792                 :            :         libspdm_secured_message_get_session_state(
+    7793                 :            :             spdm_context->session_info[0].secured_message_context),
+    7794                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    7795                 :          1 :     assert_int_equal(spdm_context->session_info[0].session_policy, 0xFF);
+    7796                 :          1 :     free(data);
+    7797                 :          1 : }
+    7798                 :            : 
+    7799                 :            : /**
+    7800                 :            :  * Test 31: Exercise the libspdm_send_receive_key_exchange_ex path
+    7801                 :            :  * Expected Behavior: requester_random_in is sent to Responder and correct responder_random is
+    7802                 :            :  *                    returned to Requester.
+    7803                 :            :  **/
+    7804                 :          1 : static void libspdm_test_requester_key_exchange_case31(void **state)
+    7805                 :            : {
+    7806                 :            :     libspdm_return_t status;
+    7807                 :            :     libspdm_test_context_t *spdm_test_context;
+    7808                 :            :     libspdm_context_t *spdm_context;
+    7809                 :            :     uint32_t session_id;
+    7810                 :            :     uint8_t heartbeat_period;
+    7811                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    7812                 :            :     uint8_t slot_id_param;
+    7813                 :            :     void *data;
+    7814                 :            :     size_t data_size;
+    7815                 :            :     void *hash;
+    7816                 :            :     size_t hash_size;
+    7817                 :            :     uint8_t requester_random_in[SPDM_RANDOM_DATA_SIZE];
+    7818                 :            :     uint8_t requester_random[SPDM_RANDOM_DATA_SIZE];
+    7819                 :            :     uint8_t responder_random[SPDM_RANDOM_DATA_SIZE];
+    7820                 :            :     uint8_t responder_opaque_data[SPDM_MAX_OPAQUE_DATA_SIZE];
+    7821                 :            :     size_t responder_opaque_data_size;
+    7822                 :            :     uint8_t requester_opaque_data[SPDM_MAX_OPAQUE_DATA_SIZE];
+    7823                 :            :     size_t requester_opaque_data_size;
+    7824                 :            : 
+    7825                 :          1 :     spdm_test_context = *state;
+    7826                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    7827                 :          1 :     spdm_test_context->case_id = 0x1f;
+    7828                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    7829                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    7830                 :          1 :     spdm_context->connection_info.connection_state =
+    7831                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    7832                 :          1 :     spdm_context->connection_info.capability.flags |=
+    7833                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    7834                 :          1 :     spdm_context->local_context.capability.flags |=
+    7835                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    7836                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
+    7837                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
+    7838                 :            :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    7839                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    7840                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    7841                 :            :                                                     &data_size, &hash, &hash_size);
+    7842                 :          1 :     libspdm_reset_message_a(spdm_context);
+    7843                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    7844                 :            :         m_libspdm_use_hash_algo;
+    7845                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    7846                 :            :         m_libspdm_use_asym_algo;
+    7847                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    7848                 :            :         m_libspdm_use_dhe_algo;
+    7849                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    7850                 :            :         m_libspdm_use_aead_algo;
+    7851                 :            : 
+    7852         [ +  - ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    7853                 :          1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    7854                 :            :     }
+    7855                 :            : 
+    7856                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    7857                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    7858                 :            :         data_size;
+    7859                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    7860                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    7861                 :            :                      data, data_size);
+    7862                 :            : #else
+    7863                 :          1 :     libspdm_hash_all(
+    7864                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    7865                 :            :         data, data_size,
+    7866                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    7867                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    7868                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    7869                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    7870                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    7871                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    7872                 :            :         data, data_size,
+    7873                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    7874                 :            : #endif
+    7875                 :            : 
+    7876         [ +  + ]:         33 :     for (int index = 0; index < SPDM_RANDOM_DATA_SIZE; index++) {
+    7877                 :         32 :         requester_random_in[index] = 0x12;
+    7878                 :            :     }
+    7879                 :            : 
+    7880                 :          1 :     heartbeat_period = 0;
+    7881                 :          1 :     responder_opaque_data_size = sizeof(responder_opaque_data);
+    7882                 :          1 :     requester_opaque_data_size = sizeof(requester_opaque_data);
+    7883                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    7884                 :          1 :     status = libspdm_send_receive_key_exchange_ex(
+    7885                 :            :         spdm_context,
+    7886                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    7887                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    7888                 :            :         measurement_hash, requester_random_in, requester_random, responder_random,
+    7889                 :            :         requester_opaque_data, requester_opaque_data_size,
+    7890                 :            :         responder_opaque_data, &responder_opaque_data_size);
+    7891                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    7892                 :          1 :     assert_int_equal(session_id, 0xFFFFFFFF);
+    7893                 :          1 :     assert_int_equal(
+    7894                 :            :         libspdm_secured_message_get_session_state(
+    7895                 :            :             spdm_context->session_info[0].secured_message_context),
+    7896                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    7897                 :            : 
+    7898         [ +  + ]:         33 :     for (int index = 0; index < SPDM_RANDOM_DATA_SIZE; index++) {
+    7899                 :         32 :         assert_int_equal(requester_random[index], requester_random_in[index]);
+    7900                 :         32 :         assert_int_equal(requester_random[index], 0x12);
+    7901                 :         32 :         assert_int_equal(responder_random[index], 0x5c);
+    7902                 :            :     }
+    7903                 :            : 
+    7904                 :          1 :     free(data);
+    7905                 :          1 : }
+    7906                 :            : 
+    7907                 :          1 : void libspdm_test_requester_key_exchange_case32(void **state)
+    7908                 :            : {
+    7909                 :            :     libspdm_return_t status;
+    7910                 :            :     libspdm_test_context_t *spdm_test_context;
+    7911                 :            :     libspdm_context_t *spdm_context;
+    7912                 :            :     uint32_t session_id;
+    7913                 :            :     uint8_t heartbeat_period;
+    7914                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    7915                 :            :     uint8_t slot_id_param;
+    7916                 :            :     void *data;
+    7917                 :            :     size_t data_size;
+    7918                 :            : 
+    7919                 :          1 :     spdm_test_context = *state;
+    7920                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    7921                 :          1 :     spdm_test_context->case_id = 0x20;
+    7922                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    7923                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    7924                 :          1 :     spdm_context->connection_info.connection_state =
+    7925                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    7926                 :          1 :     spdm_context->connection_info.capability.flags |=
+    7927                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    7928                 :          1 :     spdm_context->local_context.capability.flags |=
+    7929                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    7930                 :          1 :     spdm_context->connection_info.capability.flags |=
+    7931                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PUB_KEY_ID_CAP;
+    7932                 :          1 :     spdm_context->local_context.capability.flags |=
+    7933                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PUB_KEY_ID_CAP;
+    7934                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
+    7935                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
+    7936                 :            :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    7937                 :          1 :     libspdm_read_responder_public_key(m_libspdm_use_asym_algo, &data, &data_size);
+    7938                 :          1 :     spdm_context->local_context.peer_public_key_provision = data;
+    7939                 :          1 :     spdm_context->local_context.peer_public_key_provision_size = data_size;
+    7940                 :            : 
+    7941                 :          1 :     libspdm_reset_message_a(spdm_context);
+    7942                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    7943                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    7944                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    7945                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    7946                 :          1 :     spdm_context->connection_info.algorithm.other_params_support =
+    7947                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
+    7948                 :          1 :     libspdm_session_info_init(spdm_context,
+    7949                 :          1 :                               spdm_context->session_info,
+    7950                 :            :                               INVALID_SESSION_ID, false);
+    7951                 :            : 
+    7952                 :          1 :     heartbeat_period = 0;
+    7953                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    7954                 :          1 :     status = libspdm_send_receive_key_exchange(
+    7955                 :            :         spdm_context,
+    7956                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0xFF, 0xFF,
+    7957                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    7958                 :            :         measurement_hash);
+    7959                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    7960                 :          1 :     assert_int_equal(session_id, 0xFFFFFFFF);
+    7961                 :          1 :     assert_int_equal(
+    7962                 :            :         libspdm_secured_message_get_session_state(
+    7963                 :            :             spdm_context->session_info[0].secured_message_context),
+    7964                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    7965                 :          1 :     assert_int_equal(
+    7966                 :            :         spdm_context->session_info[0].session_policy,
+    7967                 :            :         0xFF);
+    7968                 :          1 :     free(data);
+    7969                 :          1 : }
+    7970                 :            : 
+    7971                 :          1 : static void libspdm_test_requester_key_exchange_case33(void **state)
+    7972                 :            : {
+    7973                 :            :     libspdm_return_t status;
+    7974                 :            :     libspdm_test_context_t *spdm_test_context;
+    7975                 :            :     libspdm_context_t *spdm_context;
+    7976                 :            :     uint32_t session_id;
+    7977                 :            :     uint8_t heartbeat_period;
+    7978                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    7979                 :            :     uint8_t slot_id_param;
+    7980                 :            :     void *data;
+    7981                 :            :     size_t data_size;
+    7982                 :            :     void *hash;
+    7983                 :            :     size_t hash_size;
+    7984                 :            : 
+    7985                 :          1 :     spdm_test_context = *state;
+    7986                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    7987                 :          1 :     spdm_test_context->case_id = 0x21;
+    7988                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    7989                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    7990                 :          1 :     spdm_context->connection_info.connection_state =
+    7991                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    7992                 :          1 :     spdm_context->connection_info.capability.flags |=
+    7993                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    7994                 :          1 :     spdm_context->local_context.capability.flags |=
+    7995                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    7996                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
+    7997                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
+    7998                 :            :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    7999                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    8000                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    8001                 :            :                                                     &data_size, &hash, &hash_size);
+    8002                 :          1 :     libspdm_reset_message_a(spdm_context);
+    8003                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    8004                 :            :         m_libspdm_use_hash_algo;
+    8005                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    8006                 :            :         m_libspdm_use_asym_algo;
+    8007                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    8008                 :            :         m_libspdm_use_dhe_algo;
+    8009                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    8010                 :            :         m_libspdm_use_aead_algo;
+    8011                 :          1 :     spdm_context->connection_info.algorithm.other_params_support =
+    8012                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
+    8013                 :          1 :     libspdm_session_info_init(spdm_context,
+    8014                 :          1 :                               spdm_context->session_info,
+    8015                 :            :                               INVALID_SESSION_ID, false);
+    8016                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    8017                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    8018                 :            :         data_size;
+    8019                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    8020                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    8021                 :            :                      data, data_size);
+    8022                 :            : #else
+    8023                 :          1 :     libspdm_hash_all(
+    8024                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    8025                 :            :         data, data_size,
+    8026                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    8027                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    8028                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    8029                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    8030                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    8031                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    8032                 :            :         data, data_size,
+    8033                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    8034                 :            : #endif
+    8035                 :            : 
+    8036                 :          1 :     heartbeat_period = 0;
+    8037                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    8038                 :          1 :     status = libspdm_send_receive_key_exchange(
+    8039                 :            :         spdm_context,
+    8040                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0xFF,
+    8041                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    8042                 :            :         measurement_hash);
+    8043                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    8044                 :          1 :     assert_int_equal(session_id, 0xFFFFFFFF);
+    8045                 :          1 :     assert_int_equal(
+    8046                 :            :         libspdm_secured_message_get_session_state(
+    8047                 :            :             spdm_context->session_info[0].secured_message_context),
+    8048                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    8049                 :          1 :     assert_int_equal(
+    8050                 :            :         spdm_context->session_info[0].session_policy, 0xFF);
+    8051                 :          1 :     free(data);
+    8052                 :          1 : }
+    8053                 :            : 
+    8054                 :            : /**
+    8055                 :            :  * Test 34: The secured message version is 1.2 and the Integrator has set the sequence number
+    8056                 :            :  *          endianness to big-endian. After key exchange the session's endianness will be
+    8057                 :            :  *          little-endian as 277 1.2 only supports little-endian.
+    8058                 :            :  * Expected Behavior: A successful key exchange with the session's endianness set to little-endian.
+    8059                 :            :  **/
+    8060                 :          1 : static void libspdm_test_requester_key_exchange_case34(void **state)
+    8061                 :            : {
+    8062                 :            :     libspdm_return_t status;
+    8063                 :            :     libspdm_test_context_t *spdm_test_context;
+    8064                 :            :     libspdm_context_t *spdm_context;
+    8065                 :            :     uint32_t session_id;
+    8066                 :            :     uint8_t heartbeat_period;
+    8067                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    8068                 :            :     uint8_t slot_id_param;
+    8069                 :            :     void *data;
+    8070                 :            :     size_t data_size;
+    8071                 :            :     void *hash;
+    8072                 :            :     size_t hash_size;
+    8073                 :            : 
+    8074                 :          1 :     spdm_test_context = *state;
+    8075                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    8076                 :            : 
+    8077         [ +  - ]:          1 :     if (spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    8078                 :          1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    8079                 :            :     }
+    8080                 :            : 
+    8081                 :          1 :     spdm_test_context->case_id = 0x22;
+    8082                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    8083                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    8084                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    8085                 :          1 :     spdm_context->connection_info.capability.flags |=
+    8086                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    8087                 :          1 :     spdm_context->local_context.capability.flags |=
+    8088                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    8089                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
+    8090                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
+    8091                 :            :         SECURED_SPDM_VERSION_12 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    8092                 :            : 
+    8093                 :            :     /* Set 277 sequence number endianness to big-endian. */
+    8094                 :          1 :     spdm_context->sequence_number_endian = LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_BIG_DEC_BIG;
+    8095                 :            : 
+    8096                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    8097                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    8098                 :            :                                                     &data_size, &hash, &hash_size);
+    8099                 :          1 :     libspdm_reset_message_a(spdm_context);
+    8100                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    8101                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    8102                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    8103                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    8104                 :            : 
+    8105                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    8106                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
+    8107                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    8108                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    8109                 :            :                      data, data_size);
+    8110                 :            : #else
+    8111                 :          1 :     libspdm_hash_all(
+    8112                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    8113                 :            :         data, data_size,
+    8114                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    8115                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    8116                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    8117                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    8118                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    8119                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    8120                 :            :         data, data_size,
+    8121                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    8122                 :            : #endif
+    8123                 :            : 
+    8124                 :          1 :     heartbeat_period = 0;
+    8125                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    8126                 :          1 :     status = libspdm_send_receive_key_exchange(
+    8127                 :            :         spdm_context,
+    8128                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
+    8129                 :            :         &session_id, &heartbeat_period, &slot_id_param,
+    8130                 :            :         measurement_hash);
+    8131                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    8132                 :          1 :     assert_int_equal(session_id, 0xFFFFFFFF);
+    8133                 :          1 :     assert_int_equal(
+    8134                 :            :         libspdm_secured_message_get_session_state(
+    8135                 :            :             spdm_context->session_info[0].secured_message_context),
+    8136                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    8137                 :          1 :     assert_int_equal(((libspdm_secured_message_context_t *)spdm_context->session_info->
+    8138                 :            :                       secured_message_context)->sequence_number_endian,
+    8139                 :            :                      LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_LITTLE_DEC_LITTLE);
+    8140                 :          1 :     free(data);
+    8141                 :          1 : }
+    8142                 :            : 
+    8143                 :            : static libspdm_test_context_t m_libspdm_requester_key_exchange_test_context = {
+    8144                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+    8145                 :            :     true,
+    8146                 :            :     libspdm_requester_key_exchange_test_send_message,
+    8147                 :            :     libspdm_requester_key_exchange_test_receive_message,
+    8148                 :            : };
+    8149                 :            : 
+    8150                 :          1 : int libspdm_requester_key_exchange_test_main(void)
+    8151                 :            : {
+    8152                 :          1 :     const struct CMUnitTest spdm_requester_key_exchange_tests[] = {
+    8153                 :            :         /* SendRequest failed*/
+    8154                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_case1),
+    8155                 :            :         /* Successful response*/
+    8156                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_case2),
+    8157                 :            :         /* connection_state check failed*/
+    8158                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_case3),
+    8159                 :            :         /* Error response: SPDM_ERROR_CODE_INVALID_REQUEST*/
+    8160                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_case4),
+    8161                 :            :         /* Always SPDM_ERROR_CODE_BUSY*/
+    8162                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_case5),
+    8163                 :            :         /* SPDM_ERROR_CODE_BUSY + Successful response*/
+    8164                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_case6),
+    8165                 :            :         /* Error response: SPDM_ERROR_CODE_REQUEST_RESYNCH*/
+    8166                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_case7),
+    8167                 :            :         /* Always SPDM_ERROR_CODE_RESPONSE_NOT_READY*/
+    8168                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_case8),
+    8169                 :            :         /* SPDM_ERROR_CODE_RESPONSE_NOT_READY + Successful response*/
+    8170                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_case9),
+    8171                 :            :         /* Unexpected errors*/
+    8172                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_case10),
+    8173                 :            :         /* Buffer reset*/
+    8174                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_case11),
+    8175                 :            :         /* Measurement hash 1, returns a measurement hash*/
+    8176                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_case12),
+    8177                 :            :         /* Measurement hash 1, returns a 0x00 array (no TCB components)*/
+    8178                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_case13),
+    8179                 :            :         /* Measurement hash FF, returns a measurement_hash*/
+    8180                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_case14),
+    8181                 :            :         /* Measurement hash 1, returns no measurement_hash*/
+    8182                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_case15),
+    8183                 :            :         /* Measurement hash FF, returns no measurement_hash*/
+    8184                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_case16),
+    8185                 :            :         /* Measurement hash not requested, returns a measurement_hash*/
+    8186                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_case17),
+    8187                 :            :         /* Wrong signature*/
+    8188                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_case18),
+    8189                 :            :         /* Requester and Responder Handshake in the clear set, no ResponderVerifyData*/
+    8190                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_case19),
+    8191                 :            :         /* Heartbeat not supported, heartbeat period different from 0 sent*/
+    8192                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_case20),
+    8193                 :            :         /* Heartbeat supported, heartbeat period different from 0 sent*/
+    8194                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_case21),
+    8195                 :            :         /* Heartbeat supported, heartbeat period 0 sent NOTE: This should disable heartbeat*/
+    8196                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_case22),
+    8197                 :            :         /* Muth Auth requested*/
+    8198                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_case23),
+    8199                 :            :         /* Muth Auth requested with Encapsulated request*/
+    8200                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_case24),
+    8201                 :            :         /* Muth Auth requested with implicit get digest*/
+    8202                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_case25),
+    8203                 :            :         /* Muth Auth requested with Encapsulated request and bit 0 set*/
+    8204                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_case26),
+    8205                 :            :         /* Muth Auth requested with implicit get digest and bit 0 set*/
+    8206                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_case27),
+    8207                 :            :         /* Muth Auth requested with Encapsulated request and Muth Auth requested with implicit get digest simultaneously*/
+    8208                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_case28),
+    8209                 :            :         /* Buffer verification*/
+    8210                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_case29),
+    8211                 :            :         /* Successful response V1.2*/
+    8212                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_case30),
+    8213                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_case31),
+    8214                 :            :         /* Successful response using provisioned public key (slot_id 0xFF) */
+    8215                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_case32),
+    8216                 :            :         /* OpaqueData only supports OpaqueDataFmt1, Success Case */
+    8217                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_case33),
+    8218                 :            :         cmocka_unit_test(libspdm_test_requester_key_exchange_case34),
+    8219                 :            :     };
+    8220                 :            : 
+    8221                 :          1 :     libspdm_setup_test_context(&m_libspdm_requester_key_exchange_test_context);
+    8222                 :            : 
+    8223                 :          1 :     return cmocka_run_group_tests(spdm_requester_key_exchange_tests,
+    8224                 :            :                                   libspdm_unit_test_group_setup,
+    8225                 :            :                                   libspdm_unit_test_group_teardown);
+    8226                 :            : }
+    8227                 :            : 
+    8228                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/key_update.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_requester/key_update.c.func-sort-c.html new file mode 100644 index 00000000000..5b8fccd89e5 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/key_update.c.func-sort-c.html @@ -0,0 +1,245 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/key_update.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - key_update.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:1861206190.3 %
Date:2024-09-22 08:21:07Functions:4141100.0 %
Branches:24437265.6 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_key_update_test_main1
libspdm_test_requester_key_update_case11
libspdm_test_requester_key_update_case101
libspdm_test_requester_key_update_case111
libspdm_test_requester_key_update_case121
libspdm_test_requester_key_update_case131
libspdm_test_requester_key_update_case141
libspdm_test_requester_key_update_case151
libspdm_test_requester_key_update_case161
libspdm_test_requester_key_update_case171
libspdm_test_requester_key_update_case181
libspdm_test_requester_key_update_case191
libspdm_test_requester_key_update_case21
libspdm_test_requester_key_update_case201
libspdm_test_requester_key_update_case211
libspdm_test_requester_key_update_case221
libspdm_test_requester_key_update_case231
libspdm_test_requester_key_update_case241
libspdm_test_requester_key_update_case251
libspdm_test_requester_key_update_case261
libspdm_test_requester_key_update_case271
libspdm_test_requester_key_update_case281
libspdm_test_requester_key_update_case291
libspdm_test_requester_key_update_case31
libspdm_test_requester_key_update_case301
libspdm_test_requester_key_update_case311
libspdm_test_requester_key_update_case321
libspdm_test_requester_key_update_case331
libspdm_test_requester_key_update_case341
libspdm_test_requester_key_update_case351
libspdm_test_requester_key_update_case41
libspdm_test_requester_key_update_case51
libspdm_test_requester_key_update_case61
libspdm_test_requester_key_update_case71
libspdm_test_requester_key_update_case81
libspdm_test_requester_key_update_case91
libspdm_compute_secret_update35
libspdm_set_standard_key_update_test_state35
libspdm_set_standard_key_update_test_secrets83
libspdm_requester_key_update_test_receive_message127
libspdm_requester_key_update_test_send_message128
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/key_update.c.func.html b/coverage_log/unit_test/test_spdm_requester/key_update.c.func.html new file mode 100644 index 00000000000..c30bceb5b2a --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/key_update.c.func.html @@ -0,0 +1,245 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/key_update.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - key_update.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:1861206190.3 %
Date:2024-09-22 08:21:07Functions:4141100.0 %
Branches:24437265.6 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_compute_secret_update35
libspdm_requester_key_update_test_main1
libspdm_requester_key_update_test_receive_message127
libspdm_requester_key_update_test_send_message128
libspdm_set_standard_key_update_test_secrets83
libspdm_set_standard_key_update_test_state35
libspdm_test_requester_key_update_case11
libspdm_test_requester_key_update_case101
libspdm_test_requester_key_update_case111
libspdm_test_requester_key_update_case121
libspdm_test_requester_key_update_case131
libspdm_test_requester_key_update_case141
libspdm_test_requester_key_update_case151
libspdm_test_requester_key_update_case161
libspdm_test_requester_key_update_case171
libspdm_test_requester_key_update_case181
libspdm_test_requester_key_update_case191
libspdm_test_requester_key_update_case21
libspdm_test_requester_key_update_case201
libspdm_test_requester_key_update_case211
libspdm_test_requester_key_update_case221
libspdm_test_requester_key_update_case231
libspdm_test_requester_key_update_case241
libspdm_test_requester_key_update_case251
libspdm_test_requester_key_update_case261
libspdm_test_requester_key_update_case271
libspdm_test_requester_key_update_case281
libspdm_test_requester_key_update_case291
libspdm_test_requester_key_update_case31
libspdm_test_requester_key_update_case301
libspdm_test_requester_key_update_case311
libspdm_test_requester_key_update_case321
libspdm_test_requester_key_update_case331
libspdm_test_requester_key_update_case341
libspdm_test_requester_key_update_case351
libspdm_test_requester_key_update_case41
libspdm_test_requester_key_update_case51
libspdm_test_requester_key_update_case61
libspdm_test_requester_key_update_case71
libspdm_test_requester_key_update_case81
libspdm_test_requester_key_update_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/key_update.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/key_update.c.gcov.html new file mode 100644 index 00000000000..b841a862abb --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/key_update.c.gcov.html @@ -0,0 +1,5843 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/key_update.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - key_update.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:1861206190.3 %
Date:2024-09-22 08:21:07Functions:4141100.0 %
Branches:24437265.6 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_requester_lib.h"
+       9                 :            : #include "internal/libspdm_secured_message_lib.h"
+      10                 :            : 
+      11                 :            : #if (LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP) || (LIBSPDM_ENABLE_CAPABILITY_PSK_CAP)
+      12                 :            : 
+      13                 :            : static uint8_t m_libspdm_last_token;
+      14                 :            : static uint8_t m_libspdm_last_rsp_enc_key[LIBSPDM_MAX_AEAD_KEY_SIZE];
+      15                 :            : static uint8_t m_libspdm_last_rsp_salt[LIBSPDM_MAX_AEAD_IV_SIZE];
+      16                 :            : static uint64_t m_libspdm_last_rsp_sequence_number;
+      17                 :            : 
+      18                 :         35 : static void libspdm_set_standard_key_update_test_state(
+      19                 :            :     libspdm_context_t *spdm_context, uint32_t *session_id)
+      20                 :            : {
+      21                 :            :     void                   *data;
+      22                 :            :     size_t data_size;
+      23                 :            :     void                   *hash;
+      24                 :            :     size_t hash_size;
+      25                 :            :     libspdm_session_info_t    *session_info;
+      26                 :            : 
+      27                 :         35 :     spdm_context->connection_info.connection_state =
+      28                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+      29                 :         35 :     spdm_context->connection_info.capability.flags |=
+      30                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_UPD_CAP;
+      31                 :         35 :     spdm_context->connection_info.capability.flags |=
+      32                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+      33                 :         35 :     spdm_context->connection_info.capability.flags |=
+      34                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+      35                 :         35 :     spdm_context->local_context.capability.flags |=
+      36                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP;
+      37                 :         35 :     spdm_context->local_context.capability.flags |=
+      38                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+      39                 :         35 :     spdm_context->local_context.capability.flags |=
+      40                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+      41                 :         35 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+      42                 :            :                                                     m_libspdm_use_asym_algo, &data,
+      43                 :            :                                                     &data_size, &hash, &hash_size);
+      44                 :         35 :     spdm_context->transcript.message_a.buffer_size = 0;
+      45                 :         35 :     spdm_context->connection_info.algorithm.base_hash_algo =
+      46                 :            :         m_libspdm_use_hash_algo;
+      47                 :         35 :     spdm_context->connection_info.algorithm.base_asym_algo =
+      48                 :            :         m_libspdm_use_asym_algo;
+      49                 :         35 :     spdm_context->connection_info.algorithm.dhe_named_group =
+      50                 :            :         m_libspdm_use_dhe_algo;
+      51                 :         35 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+      52                 :            :         m_libspdm_use_aead_algo;
+      53                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+      54                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+      55                 :            :         data_size;
+      56                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+      57                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+      58                 :            :                      data, data_size);
+      59                 :            : #endif
+      60                 :            : 
+      61                 :         35 :     *session_id = 0xFFFFFFFF;
+      62                 :         35 :     session_info = &spdm_context->session_info[0];
+      63                 :         35 :     libspdm_session_info_init(spdm_context, session_info, *session_id, true);
+      64                 :         35 :     libspdm_secured_message_set_session_state(
+      65                 :            :         session_info->secured_message_context,
+      66                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+      67                 :            : 
+      68                 :         35 :     free(data);
+      69                 :         35 : }
+      70                 :            : 
+      71                 :         83 : static void libspdm_set_standard_key_update_test_secrets(
+      72                 :            :     libspdm_secured_message_context_t *secured_message_context,
+      73                 :            :     uint8_t *m_rsp_secret_buffer, uint8_t rsp_secret_fill,
+      74                 :            :     uint8_t *m_req_secret_buffer, uint8_t req_secret_fill)
+      75                 :            : {
+      76                 :         83 :     libspdm_set_mem(m_rsp_secret_buffer, secured_message_context
+      77                 :            :                     ->hash_size, rsp_secret_fill);
+      78                 :         83 :     libspdm_set_mem(m_req_secret_buffer, secured_message_context
+      79                 :            :                     ->hash_size, req_secret_fill);
+      80                 :            : 
+      81                 :         83 :     libspdm_copy_mem(secured_message_context->application_secret.response_data_secret,
+      82                 :            :                      sizeof(secured_message_context->application_secret.response_data_secret),
+      83                 :            :                      m_rsp_secret_buffer, secured_message_context->aead_key_size);
+      84                 :         83 :     libspdm_copy_mem(secured_message_context->application_secret.request_data_secret,
+      85                 :            :                      sizeof(secured_message_context->application_secret.request_data_secret),
+      86                 :            :                      m_req_secret_buffer, secured_message_context->aead_key_size);
+      87                 :            : 
+      88                 :         83 :     libspdm_set_mem(secured_message_context->application_secret
+      89                 :         83 :                     .response_data_encryption_key,
+      90                 :            :                     secured_message_context->aead_key_size, (uint8_t)(0xFF));
+      91                 :         83 :     libspdm_set_mem(secured_message_context->application_secret
+      92                 :         83 :                     .response_data_salt,
+      93                 :            :                     secured_message_context->aead_iv_size, (uint8_t)(0xFF));
+      94                 :            : 
+      95                 :            : 
+      96                 :         83 :     libspdm_set_mem(secured_message_context->application_secret
+      97                 :         83 :                     .request_data_encryption_key,
+      98                 :            :                     secured_message_context->aead_key_size, (uint8_t)(0xEE));
+      99                 :         83 :     libspdm_set_mem(secured_message_context->application_secret
+     100                 :         83 :                     .request_data_salt,
+     101                 :            :                     secured_message_context->aead_iv_size, (uint8_t)(0xEE));
+     102                 :            : 
+     103                 :            :     secured_message_context->application_secret.
+     104                 :         83 :     response_data_sequence_number = 0;
+     105                 :            :     secured_message_context->application_secret.
+     106                 :         83 :     request_data_sequence_number = 0;
+     107                 :         83 : }
+     108                 :            : 
+     109                 :         35 : static void libspdm_compute_secret_update(spdm_version_number_t spdm_version,
+     110                 :            :                                           size_t hash_size,
+     111                 :            :                                           const uint8_t *in_secret, uint8_t *out_secret,
+     112                 :            :                                           size_t out_secret_size)
+     113                 :            : {
+     114                 :            :     uint8_t bin_str9[128];
+     115                 :            :     size_t bin_str9_size;
+     116                 :            : 
+     117                 :         35 :     bin_str9_size = sizeof(bin_str9);
+     118                 :         35 :     libspdm_bin_concat(spdm_version,
+     119                 :            :                        SPDM_BIN_STR_9_LABEL, sizeof(SPDM_BIN_STR_9_LABEL) - 1,
+     120                 :         35 :                        NULL, (uint16_t)hash_size, hash_size, bin_str9,
+     121                 :            :                        &bin_str9_size);
+     122                 :            : 
+     123                 :         35 :     libspdm_hkdf_expand(m_libspdm_use_hash_algo, in_secret, hash_size, bin_str9,
+     124                 :            :                         bin_str9_size, out_secret, out_secret_size);
+     125                 :         35 : }
+     126                 :            : 
+     127                 :        128 : libspdm_return_t libspdm_requester_key_update_test_send_message(
+     128                 :            :     void *spdm_context, size_t request_size, const void *request,
+     129                 :            :     uint64_t timeout)
+     130                 :            : {
+     131                 :            :     libspdm_test_context_t *spdm_test_context;
+     132                 :            : 
+     133                 :        128 :     spdm_test_context = libspdm_get_test_context();
+     134   [ +  +  -  +  :        128 :     switch (spdm_test_context->case_id) {
+          +  +  +  +  +  
+          +  +  +  +  +  
+          +  +  +  +  +  
+                +  +  - ]
+     135                 :          1 :     case 0x1:
+     136                 :          1 :         return LIBSPDM_STATUS_SEND_FAIL;
+     137                 :          2 :     case 0x2: {
+     138                 :            :         libspdm_return_t status;
+     139                 :            :         uint8_t *decoded_message;
+     140                 :            :         size_t decoded_message_size;
+     141                 :            :         uint32_t session_id;
+     142                 :            :         uint32_t              *message_session_id;
+     143                 :            :         bool is_app_message;
+     144                 :            :         libspdm_session_info_t *session_info;
+     145                 :            :         uint8_t message_buffer[LIBSPDM_SENDER_BUFFER_SIZE];
+     146                 :            : 
+     147                 :          2 :         message_session_id = NULL;
+     148                 :          2 :         session_id = 0xFFFFFFFF;
+     149                 :            : 
+     150                 :          2 :         session_info = libspdm_get_session_info_via_session_id(
+     151                 :            :             spdm_context, session_id);
+     152         [ -  + ]:          2 :         if (session_info == NULL) {
+     153                 :          0 :             return LIBSPDM_STATUS_SEND_FAIL;
+     154                 :            :         }
+     155                 :            : 
+     156                 :          2 :         memcpy(message_buffer, request, request_size);
+     157                 :            : 
+     158                 :            :         ((libspdm_secured_message_context_t
+     159                 :          2 :           *)(session_info->secured_message_context))
+     160                 :          2 :         ->application_secret.request_data_sequence_number--;
+     161                 :          2 :         libspdm_get_scratch_buffer (spdm_context, (void **)&decoded_message, &decoded_message_size);
+     162                 :          2 :         status = libspdm_transport_test_decode_message(spdm_context,
+     163                 :            :                                                        &message_session_id, &is_app_message, true,
+     164                 :            :                                                        request_size,
+     165                 :            :                                                        message_buffer, &decoded_message_size,
+     166                 :            :                                                        (void **)&decoded_message);
+     167         [ -  + ]:          2 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     168                 :          0 :             return LIBSPDM_STATUS_SEND_FAIL;
+     169                 :            :         }
+     170                 :            : 
+     171                 :          2 :         m_libspdm_last_token = ((spdm_key_update_request_t
+     172                 :          2 :                                  *) decoded_message)->header.param2;
+     173                 :            :     }
+     174                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     175                 :          0 :     case 0x3: {
+     176                 :            :         static size_t sub_index = 0;
+     177                 :            : 
+     178         [ #  # ]:          0 :         if(sub_index > 0) {
+     179                 :            :             libspdm_return_t status;
+     180                 :            :             uint8_t *decoded_message;
+     181                 :            :             size_t decoded_message_size;
+     182                 :            :             uint32_t session_id;
+     183                 :            :             uint32_t              *message_session_id;
+     184                 :            :             bool is_app_message;
+     185                 :            :             libspdm_session_info_t *session_info;
+     186                 :            :             uint8_t message_buffer[LIBSPDM_SENDER_BUFFER_SIZE];
+     187                 :            : 
+     188                 :          0 :             message_session_id = NULL;
+     189                 :          0 :             session_id = 0xFFFFFFFF;
+     190                 :            : 
+     191                 :          0 :             session_info = libspdm_get_session_info_via_session_id(
+     192                 :            :                 spdm_context, session_id);
+     193         [ #  # ]:          0 :             if (session_info == NULL) {
+     194                 :          0 :                 return LIBSPDM_STATUS_SEND_FAIL;
+     195                 :            :             }
+     196                 :            : 
+     197                 :          0 :             memcpy(message_buffer, request, request_size);
+     198                 :            : 
+     199                 :            :             ((libspdm_secured_message_context_t
+     200                 :          0 :               *)(session_info->secured_message_context))
+     201                 :          0 :             ->application_secret.request_data_sequence_number--;
+     202                 :          0 :             libspdm_get_scratch_buffer (spdm_context, (void **)&decoded_message,
+     203                 :            :                                         &decoded_message_size);
+     204                 :          0 :             status = libspdm_transport_test_decode_message(spdm_context,
+     205                 :            :                                                            &message_session_id, &is_app_message,
+     206                 :            :                                                            true,
+     207                 :            :                                                            request_size,
+     208                 :            :                                                            message_buffer, &decoded_message_size,
+     209                 :            :                                                            (void **)&decoded_message);
+     210         [ #  # ]:          0 :             if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     211                 :          0 :                 return LIBSPDM_STATUS_SEND_FAIL;
+     212                 :            :             }
+     213                 :            : 
+     214                 :          0 :             m_libspdm_last_token = ((spdm_key_update_request_t
+     215                 :          0 :                                      *) decoded_message)->header.param2;
+     216                 :            :         }
+     217                 :            : 
+     218                 :          0 :         sub_index++;
+     219                 :            :     }
+     220                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     221                 :          1 :     case 0x4: {
+     222                 :            :         static size_t sub_index = 0;
+     223                 :            : 
+     224         [ -  + ]:          1 :         if(sub_index > 0) {
+     225                 :            :             libspdm_return_t status;
+     226                 :            :             uint8_t *decoded_message;
+     227                 :            :             size_t decoded_message_size;
+     228                 :            :             uint32_t session_id;
+     229                 :            :             uint32_t              *message_session_id;
+     230                 :            :             bool is_app_message;
+     231                 :            :             libspdm_session_info_t *session_info;
+     232                 :            :             uint8_t message_buffer[LIBSPDM_SENDER_BUFFER_SIZE];
+     233                 :            : 
+     234                 :          0 :             message_session_id = NULL;
+     235                 :          0 :             session_id = 0xFFFFFFFF;
+     236                 :            : 
+     237                 :          0 :             session_info = libspdm_get_session_info_via_session_id(
+     238                 :            :                 spdm_context, session_id);
+     239         [ #  # ]:          0 :             if (session_info == NULL) {
+     240                 :          0 :                 return LIBSPDM_STATUS_SEND_FAIL;
+     241                 :            :             }
+     242                 :            : 
+     243                 :          0 :             memcpy(message_buffer, request, request_size);
+     244                 :            : 
+     245                 :            :             ((libspdm_secured_message_context_t
+     246                 :          0 :               *)(session_info->secured_message_context))
+     247                 :          0 :             ->application_secret.request_data_sequence_number--;
+     248                 :          0 :             libspdm_get_scratch_buffer (spdm_context, (void **)&decoded_message,
+     249                 :            :                                         &decoded_message_size);
+     250                 :          0 :             status = libspdm_transport_test_decode_message(spdm_context,
+     251                 :            :                                                            &message_session_id, &is_app_message,
+     252                 :            :                                                            true,
+     253                 :            :                                                            request_size,
+     254                 :            :                                                            message_buffer, &decoded_message_size,
+     255                 :            :                                                            (void **)&decoded_message);
+     256         [ #  # ]:          0 :             if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     257                 :          0 :                 return LIBSPDM_STATUS_SEND_FAIL;
+     258                 :            :             }
+     259                 :            : 
+     260                 :          0 :             m_libspdm_last_token = ((spdm_key_update_request_t
+     261                 :          0 :                                      *) decoded_message)->header.param2;
+     262                 :            :         }
+     263                 :            : 
+     264                 :          1 :         sub_index++;
+     265                 :            :     }
+     266                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     267                 :          1 :     case 0x5: {
+     268                 :            :         static size_t sub_index = 0;
+     269                 :            : 
+     270         [ -  + ]:          1 :         if(sub_index > 0) {
+     271                 :            :             libspdm_return_t status;
+     272                 :            :             uint8_t *decoded_message;
+     273                 :            :             size_t decoded_message_size;
+     274                 :            :             uint32_t session_id;
+     275                 :            :             uint32_t              *message_session_id;
+     276                 :            :             bool is_app_message;
+     277                 :            :             libspdm_session_info_t *session_info;
+     278                 :            :             uint8_t message_buffer[LIBSPDM_SENDER_BUFFER_SIZE];
+     279                 :            : 
+     280                 :          0 :             message_session_id = NULL;
+     281                 :          0 :             session_id = 0xFFFFFFFF;
+     282                 :            : 
+     283                 :          0 :             session_info = libspdm_get_session_info_via_session_id(
+     284                 :            :                 spdm_context, session_id);
+     285         [ #  # ]:          0 :             if (session_info == NULL) {
+     286                 :          0 :                 return LIBSPDM_STATUS_SEND_FAIL;
+     287                 :            :             }
+     288                 :            : 
+     289                 :          0 :             memcpy(message_buffer, request, request_size);
+     290                 :            : 
+     291                 :            :             ((libspdm_secured_message_context_t
+     292                 :          0 :               *)(session_info->secured_message_context))
+     293                 :          0 :             ->application_secret.request_data_sequence_number--;
+     294                 :          0 :             libspdm_get_scratch_buffer (spdm_context, (void **)&decoded_message,
+     295                 :            :                                         &decoded_message_size);
+     296                 :          0 :             status = libspdm_transport_test_decode_message(spdm_context,
+     297                 :            :                                                            &message_session_id, &is_app_message,
+     298                 :            :                                                            true,
+     299                 :            :                                                            request_size,
+     300                 :            :                                                            message_buffer, &decoded_message_size,
+     301                 :            :                                                            (void **)&decoded_message);
+     302         [ #  # ]:          0 :             if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     303                 :          0 :                 return LIBSPDM_STATUS_SEND_FAIL;
+     304                 :            :             }
+     305                 :            : 
+     306                 :          0 :             m_libspdm_last_token = ((spdm_key_update_request_t
+     307                 :          0 :                                      *) decoded_message)->header.param2;
+     308                 :            :         }
+     309                 :            : 
+     310                 :          1 :         sub_index++;
+     311                 :            :     }
+     312                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     313                 :          3 :     case 0x6: {
+     314                 :            :         static size_t sub_index = 0;
+     315                 :            : 
+     316         [ +  + ]:          3 :         if(sub_index > 0) {
+     317                 :            :             libspdm_return_t status;
+     318                 :            :             uint8_t *decoded_message;
+     319                 :            :             size_t decoded_message_size;
+     320                 :            :             uint32_t session_id;
+     321                 :            :             uint32_t              *message_session_id;
+     322                 :            :             bool is_app_message;
+     323                 :            :             libspdm_session_info_t *session_info;
+     324                 :            :             uint8_t message_buffer[LIBSPDM_SENDER_BUFFER_SIZE];
+     325                 :            : 
+     326                 :          2 :             message_session_id = NULL;
+     327                 :          2 :             session_id = 0xFFFFFFFF;
+     328                 :            : 
+     329                 :          2 :             session_info = libspdm_get_session_info_via_session_id(
+     330                 :            :                 spdm_context, session_id);
+     331         [ -  + ]:          2 :             if (session_info == NULL) {
+     332                 :          0 :                 return LIBSPDM_STATUS_SEND_FAIL;
+     333                 :            :             }
+     334                 :            : 
+     335                 :          2 :             memcpy(message_buffer, request, request_size);
+     336                 :            : 
+     337                 :            :             ((libspdm_secured_message_context_t
+     338                 :          2 :               *)(session_info->secured_message_context))
+     339                 :          2 :             ->application_secret.request_data_sequence_number--;
+     340                 :          2 :             libspdm_get_scratch_buffer (spdm_context, (void **)&decoded_message,
+     341                 :            :                                         &decoded_message_size);
+     342                 :          2 :             status = libspdm_transport_test_decode_message(spdm_context,
+     343                 :            :                                                            &message_session_id, &is_app_message,
+     344                 :            :                                                            true,
+     345                 :            :                                                            request_size,
+     346                 :            :                                                            message_buffer, &decoded_message_size,
+     347                 :            :                                                            (void **)&decoded_message);
+     348         [ -  + ]:          2 :             if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     349                 :          0 :                 return LIBSPDM_STATUS_SEND_FAIL;
+     350                 :            :             }
+     351                 :            : 
+     352                 :          2 :             m_libspdm_last_token = ((spdm_key_update_request_t
+     353                 :          2 :                                      *) decoded_message)->header.param2;
+     354                 :            :         }
+     355                 :            : 
+     356                 :          3 :         sub_index++;
+     357                 :            :     }
+     358                 :          3 :         return LIBSPDM_STATUS_SUCCESS;
+     359                 :          3 :     case 0x7:
+     360                 :            :     case 0x8:
+     361                 :          3 :         return LIBSPDM_STATUS_SUCCESS;
+     362                 :          3 :     case 0x9: {
+     363                 :            :         static size_t sub_index = 0;
+     364                 :            : 
+     365         [ +  + ]:          3 :         if(sub_index != 1) {
+     366                 :            :             libspdm_return_t status;
+     367                 :            :             uint8_t *decoded_message;
+     368                 :            :             size_t decoded_message_size;
+     369                 :            :             uint32_t session_id;
+     370                 :            :             uint32_t *message_session_id;
+     371                 :            :             bool is_app_message;
+     372                 :            :             libspdm_session_info_t    *session_info;
+     373                 :            :             uint8_t message_buffer[LIBSPDM_SENDER_BUFFER_SIZE];
+     374                 :            : 
+     375                 :          2 :             message_session_id = NULL;
+     376                 :          2 :             session_id = 0xFFFFFFFF;
+     377                 :            : 
+     378                 :          2 :             session_info = libspdm_get_session_info_via_session_id(
+     379                 :            :                 spdm_context, session_id);
+     380         [ -  + ]:          2 :             if (session_info == NULL) {
+     381                 :          0 :                 return LIBSPDM_STATUS_SEND_FAIL;
+     382                 :            :             }
+     383                 :            : 
+     384                 :          2 :             memcpy(message_buffer, request, request_size);
+     385                 :            : 
+     386                 :            :             ((libspdm_secured_message_context_t
+     387                 :          2 :               *)(session_info->secured_message_context))
+     388                 :          2 :             ->application_secret.request_data_sequence_number--;
+     389                 :          2 :             libspdm_get_scratch_buffer (spdm_context, (void **)&decoded_message,
+     390                 :            :                                         &decoded_message_size);
+     391                 :          2 :             status = libspdm_transport_test_decode_message(spdm_context,
+     392                 :            :                                                            &message_session_id, &is_app_message,
+     393                 :            :                                                            true,
+     394                 :            :                                                            request_size,
+     395                 :            :                                                            message_buffer, &decoded_message_size,
+     396                 :            :                                                            (void **)&decoded_message);
+     397         [ -  + ]:          2 :             if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     398                 :          0 :                 return LIBSPDM_STATUS_SEND_FAIL;
+     399                 :            :             }
+     400                 :            : 
+     401                 :          2 :             m_libspdm_last_token = ((spdm_key_update_request_t
+     402                 :          2 :                                      *) decoded_message)->header.param2;
+     403                 :            :         }
+     404                 :            : 
+     405                 :          3 :         sub_index++;
+     406                 :            :     }
+     407                 :          3 :         return LIBSPDM_STATUS_SUCCESS;
+     408                 :         17 :     case 0xA:
+     409                 :         17 :         return LIBSPDM_STATUS_SUCCESS;
+     410                 :         20 :     case 0xB:
+     411                 :            :     case 0xC:
+     412                 :            :     case 0xD:
+     413                 :            :     case 0xE:
+     414                 :            :     case 0xF:
+     415                 :            :     case 0x10:
+     416                 :            :     case 0x11:
+     417                 :            :     case 0x12:
+     418                 :            :     case 0x13:
+     419                 :            :     case 0x14:
+     420                 :            :     case 0x15: {
+     421                 :            :         libspdm_return_t status;
+     422                 :            :         uint8_t *decoded_message;
+     423                 :            :         size_t decoded_message_size;
+     424                 :            :         uint32_t session_id;
+     425                 :            :         uint32_t              *message_session_id;
+     426                 :            :         bool is_app_message;
+     427                 :            :         libspdm_session_info_t *session_info;
+     428                 :            :         uint8_t message_buffer[LIBSPDM_SENDER_BUFFER_SIZE];
+     429                 :            : 
+     430                 :         20 :         message_session_id = NULL;
+     431                 :         20 :         session_id = 0xFFFFFFFF;
+     432                 :            : 
+     433                 :         20 :         session_info = libspdm_get_session_info_via_session_id(
+     434                 :            :             spdm_context, session_id);
+     435         [ -  + ]:         20 :         if (session_info == NULL) {
+     436                 :          0 :             return LIBSPDM_STATUS_SEND_FAIL;
+     437                 :            :         }
+     438                 :            : 
+     439                 :         20 :         memcpy(message_buffer, request, request_size);
+     440                 :            : 
+     441                 :            :         ((libspdm_secured_message_context_t
+     442                 :         20 :           *)(session_info->secured_message_context))
+     443                 :         20 :         ->application_secret.request_data_sequence_number--;
+     444                 :         20 :         libspdm_get_scratch_buffer (spdm_context, (void **)&decoded_message, &decoded_message_size);
+     445                 :         20 :         status = libspdm_transport_test_decode_message(spdm_context,
+     446                 :            :                                                        &message_session_id, &is_app_message, true,
+     447                 :            :                                                        request_size,
+     448                 :            :                                                        message_buffer, &decoded_message_size,
+     449                 :            :                                                        (void **)&decoded_message);
+     450         [ -  + ]:         20 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     451                 :          0 :             return LIBSPDM_STATUS_SEND_FAIL;
+     452                 :            :         }
+     453                 :            : 
+     454                 :         20 :         m_libspdm_last_token = ((spdm_key_update_request_t
+     455                 :         20 :                                  *) decoded_message)->header.param2;
+     456                 :            :     }
+     457                 :         20 :         return LIBSPDM_STATUS_SUCCESS;
+     458                 :          3 :     case 0x16: {
+     459                 :            :         static size_t sub_index = 0;
+     460                 :            : 
+     461         [ +  + ]:          3 :         if(sub_index < 2) {
+     462                 :            :             libspdm_return_t status;
+     463                 :            :             uint8_t *decoded_message;
+     464                 :            :             size_t decoded_message_size;
+     465                 :            :             uint32_t session_id;
+     466                 :            :             uint32_t *message_session_id;
+     467                 :            :             bool is_app_message;
+     468                 :            :             libspdm_session_info_t    *session_info;
+     469                 :            :             uint8_t message_buffer[LIBSPDM_SENDER_BUFFER_SIZE];
+     470                 :            : 
+     471                 :          2 :             message_session_id = NULL;
+     472                 :          2 :             session_id = 0xFFFFFFFF;
+     473                 :            : 
+     474                 :          2 :             session_info = libspdm_get_session_info_via_session_id(
+     475                 :            :                 spdm_context, session_id);
+     476         [ -  + ]:          2 :             if (session_info == NULL) {
+     477                 :          0 :                 return LIBSPDM_STATUS_SEND_FAIL;
+     478                 :            :             }
+     479                 :            : 
+     480                 :          2 :             memcpy(message_buffer, request, request_size);
+     481                 :            : 
+     482                 :            :             ((libspdm_secured_message_context_t
+     483                 :          2 :               *)(session_info->secured_message_context))
+     484                 :          2 :             ->application_secret.request_data_sequence_number--;
+     485                 :          2 :             libspdm_get_scratch_buffer (spdm_context, (void **)&decoded_message,
+     486                 :            :                                         &decoded_message_size);
+     487                 :          2 :             status = libspdm_transport_test_decode_message(spdm_context,
+     488                 :            :                                                            &message_session_id, &is_app_message,
+     489                 :            :                                                            true,
+     490                 :            :                                                            request_size,
+     491                 :            :                                                            message_buffer, &decoded_message_size,
+     492                 :            :                                                            (void **)&decoded_message);
+     493         [ -  + ]:          2 :             if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     494                 :          0 :                 return LIBSPDM_STATUS_SEND_FAIL;
+     495                 :            :             }
+     496                 :            : 
+     497                 :          2 :             m_libspdm_last_token = ((spdm_key_update_request_t
+     498                 :          2 :                                      *) decoded_message)->header.param2;
+     499                 :            :         }
+     500                 :            : 
+     501                 :          3 :         sub_index++;
+     502                 :            :     }
+     503                 :          3 :         return LIBSPDM_STATUS_SUCCESS;
+     504                 :         34 :     case 0x17: {
+     505                 :            :         static size_t sub_index = 0;
+     506                 :            : 
+     507                 :         34 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "send message: %zu\n", sub_index));
+     508                 :            : 
+     509         [ +  + ]:         34 :         if(sub_index%2 == 0) {
+     510                 :            :             libspdm_return_t status;
+     511                 :            :             uint8_t *decoded_message;
+     512                 :            :             size_t decoded_message_size;
+     513                 :            :             uint32_t session_id;
+     514                 :            :             uint32_t *message_session_id;
+     515                 :            :             bool is_app_message;
+     516                 :            :             libspdm_session_info_t    *session_info;
+     517                 :            :             uint8_t message_buffer[LIBSPDM_SENDER_BUFFER_SIZE];
+     518                 :            : 
+     519                 :         17 :             message_session_id = NULL;
+     520                 :         17 :             session_id = 0xFFFFFFFF;
+     521                 :            : 
+     522                 :         17 :             session_info = libspdm_get_session_info_via_session_id(
+     523                 :            :                 spdm_context, session_id);
+     524         [ -  + ]:         17 :             if (session_info == NULL) {
+     525                 :          0 :                 return LIBSPDM_STATUS_SEND_FAIL;
+     526                 :            :             }
+     527                 :            : 
+     528                 :         17 :             memcpy(message_buffer, request, request_size);
+     529                 :            : 
+     530                 :            :             ((libspdm_secured_message_context_t
+     531                 :         17 :               *)(session_info->secured_message_context))
+     532                 :         17 :             ->application_secret.request_data_sequence_number--;
+     533                 :         17 :             libspdm_get_scratch_buffer (spdm_context, (void **)&decoded_message,
+     534                 :            :                                         &decoded_message_size);
+     535                 :         17 :             status = libspdm_transport_test_decode_message(spdm_context,
+     536                 :            :                                                            &message_session_id, &is_app_message,
+     537                 :            :                                                            true,
+     538                 :            :                                                            request_size,
+     539                 :            :                                                            message_buffer, &decoded_message_size,
+     540                 :            :                                                            (void **)&decoded_message);
+     541         [ -  + ]:         17 :             if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     542                 :          0 :                 return LIBSPDM_STATUS_SEND_FAIL;
+     543                 :            :             }
+     544                 :            : 
+     545                 :         17 :             m_libspdm_last_token = ((spdm_key_update_request_t
+     546                 :         17 :                                      *) decoded_message)->header.param2;
+     547                 :            : 
+     548                 :         17 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "last token: %x\n", m_libspdm_last_token));
+     549                 :            :         }
+     550                 :            : 
+     551                 :         34 :         sub_index++;
+     552                 :            :     }
+     553                 :         34 :         return LIBSPDM_STATUS_SUCCESS;
+     554                 :          6 :     case 0x18:
+     555                 :            :     case 0x19:
+     556                 :            :     case 0x1A: {
+     557                 :            :         libspdm_return_t status;
+     558                 :            :         uint8_t *decoded_message;
+     559                 :            :         size_t decoded_message_size;
+     560                 :            :         uint32_t session_id;
+     561                 :            :         uint32_t              *message_session_id;
+     562                 :            :         bool is_app_message;
+     563                 :            :         libspdm_session_info_t *session_info;
+     564                 :            :         uint8_t message_buffer[LIBSPDM_SENDER_BUFFER_SIZE];
+     565                 :            : 
+     566                 :          6 :         message_session_id = NULL;
+     567                 :          6 :         session_id = 0xFFFFFFFF;
+     568                 :            : 
+     569                 :          6 :         session_info = libspdm_get_session_info_via_session_id(
+     570                 :            :             spdm_context, session_id);
+     571         [ -  + ]:          6 :         if (session_info == NULL) {
+     572                 :          0 :             return LIBSPDM_STATUS_SEND_FAIL;
+     573                 :            :         }
+     574                 :            : 
+     575                 :          6 :         memcpy(message_buffer, request, request_size);
+     576                 :            : 
+     577                 :            :         ((libspdm_secured_message_context_t
+     578                 :          6 :           *)(session_info->secured_message_context))
+     579                 :          6 :         ->application_secret.request_data_sequence_number--;
+     580                 :          6 :         libspdm_get_scratch_buffer (spdm_context, (void **)&decoded_message, &decoded_message_size);
+     581                 :          6 :         status = libspdm_transport_test_decode_message(spdm_context,
+     582                 :            :                                                        &message_session_id, &is_app_message, true,
+     583                 :            :                                                        request_size,
+     584                 :            :                                                        message_buffer, &decoded_message_size,
+     585                 :            :                                                        (void **)&decoded_message);
+     586         [ -  + ]:          6 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     587                 :          0 :             return LIBSPDM_STATUS_SEND_FAIL;
+     588                 :            :         }
+     589                 :            : 
+     590                 :          6 :         m_libspdm_last_token = ((spdm_key_update_request_t
+     591                 :          6 :                                  *) decoded_message)->header.param2;
+     592                 :            :     }
+     593                 :          6 :         return LIBSPDM_STATUS_SUCCESS;
+     594                 :          2 :     case 0x1B: {
+     595                 :            :         libspdm_return_t status;
+     596                 :            :         uint8_t *decoded_message;
+     597                 :            :         size_t decoded_message_size;
+     598                 :            :         uint32_t session_id;
+     599                 :            :         uint32_t              *message_session_id;
+     600                 :            :         bool is_app_message;
+     601                 :            :         libspdm_session_info_t *session_info;
+     602                 :            :         uint8_t message_buffer[LIBSPDM_SENDER_BUFFER_SIZE];
+     603                 :            : 
+     604                 :          2 :         message_session_id = NULL;
+     605                 :          2 :         session_id = 0xFFFFFFFF;
+     606                 :            : 
+     607                 :          2 :         session_info = libspdm_get_session_info_via_session_id(
+     608                 :            :             spdm_context, session_id);
+     609         [ -  + ]:          2 :         if (session_info == NULL) {
+     610                 :          0 :             return LIBSPDM_STATUS_SEND_FAIL;
+     611                 :            :         }
+     612                 :            : 
+     613                 :          2 :         memcpy(message_buffer, request, request_size);
+     614                 :            : 
+     615                 :            :         ((libspdm_secured_message_context_t
+     616                 :          2 :           *)(session_info->secured_message_context))
+     617                 :          2 :         ->application_secret.request_data_sequence_number--;
+     618                 :          2 :         libspdm_get_scratch_buffer (spdm_context, (void **)&decoded_message, &decoded_message_size);
+     619                 :          2 :         status = libspdm_transport_test_decode_message(spdm_context,
+     620                 :            :                                                        &message_session_id, &is_app_message, true,
+     621                 :            :                                                        request_size,
+     622                 :            :                                                        message_buffer, &decoded_message_size,
+     623                 :            :                                                        (void **)&decoded_message);
+     624         [ -  + ]:          2 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     625                 :          0 :             return LIBSPDM_STATUS_SEND_FAIL;
+     626                 :            :         }
+     627                 :            : 
+     628                 :          2 :         m_libspdm_last_token = ((spdm_key_update_request_t
+     629                 :          2 :                                  *) decoded_message)->header.param2;
+     630                 :            :     }
+     631                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     632                 :          1 :     case 0x1C: {
+     633                 :            :         static size_t sub_index = 0;
+     634                 :            : 
+     635         [ -  + ]:          1 :         if(sub_index > 0) {
+     636                 :            :             libspdm_return_t status;
+     637                 :            :             uint8_t *decoded_message;
+     638                 :            :             size_t decoded_message_size;
+     639                 :            :             uint32_t session_id;
+     640                 :            :             uint32_t              *message_session_id;
+     641                 :            :             bool is_app_message;
+     642                 :            :             libspdm_session_info_t *session_info;
+     643                 :            :             uint8_t message_buffer[LIBSPDM_SENDER_BUFFER_SIZE];
+     644                 :            : 
+     645                 :          0 :             message_session_id = NULL;
+     646                 :          0 :             session_id = 0xFFFFFFFF;
+     647                 :            : 
+     648                 :          0 :             session_info = libspdm_get_session_info_via_session_id(
+     649                 :            :                 spdm_context, session_id);
+     650         [ #  # ]:          0 :             if (session_info == NULL) {
+     651                 :          0 :                 return LIBSPDM_STATUS_SEND_FAIL;
+     652                 :            :             }
+     653                 :            : 
+     654                 :          0 :             memcpy(message_buffer, request, request_size);
+     655                 :            : 
+     656                 :            :             ((libspdm_secured_message_context_t
+     657                 :          0 :               *)(session_info->secured_message_context))
+     658                 :          0 :             ->application_secret.request_data_sequence_number--;
+     659                 :          0 :             libspdm_get_scratch_buffer (spdm_context, (void **)&decoded_message,
+     660                 :            :                                         &decoded_message_size);
+     661                 :          0 :             status = libspdm_transport_test_decode_message(spdm_context,
+     662                 :            :                                                            &message_session_id, &is_app_message,
+     663                 :            :                                                            true,
+     664                 :            :                                                            request_size,
+     665                 :            :                                                            message_buffer, &decoded_message_size,
+     666                 :            :                                                            (void **)&decoded_message);
+     667         [ #  # ]:          0 :             if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     668                 :          0 :                 return LIBSPDM_STATUS_SEND_FAIL;
+     669                 :            :             }
+     670                 :            : 
+     671                 :          0 :             m_libspdm_last_token = ((spdm_key_update_request_t
+     672                 :          0 :                                      *) decoded_message)->header.param2;
+     673                 :            :         }
+     674                 :            : 
+     675                 :          1 :         sub_index++;
+     676                 :            :     }
+     677                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     678                 :          4 :     case 0x1D: {
+     679                 :            :         static size_t sub_index = 0;
+     680                 :            : 
+     681         [ +  + ]:          4 :         if(sub_index > 0) {
+     682                 :            :             libspdm_return_t status;
+     683                 :            :             uint8_t *decoded_message;
+     684                 :            :             size_t decoded_message_size;
+     685                 :            :             uint32_t session_id;
+     686                 :            :             uint32_t              *message_session_id;
+     687                 :            :             bool is_app_message;
+     688                 :            :             libspdm_session_info_t *session_info;
+     689                 :            :             uint8_t message_buffer[LIBSPDM_SENDER_BUFFER_SIZE];
+     690                 :            : 
+     691                 :          3 :             message_session_id = NULL;
+     692                 :          3 :             session_id = 0xFFFFFFFF;
+     693                 :            : 
+     694                 :          3 :             session_info = libspdm_get_session_info_via_session_id(
+     695                 :            :                 spdm_context, session_id);
+     696         [ -  + ]:          3 :             if (session_info == NULL) {
+     697                 :          0 :                 return LIBSPDM_STATUS_SEND_FAIL;
+     698                 :            :             }
+     699                 :            : 
+     700                 :          3 :             memcpy(message_buffer, request, request_size);
+     701                 :            : 
+     702                 :            :             ((libspdm_secured_message_context_t
+     703                 :          3 :               *)(session_info->secured_message_context))
+     704                 :          3 :             ->application_secret.request_data_sequence_number--;
+     705                 :          3 :             libspdm_get_scratch_buffer (spdm_context, (void **)&decoded_message,
+     706                 :            :                                         &decoded_message_size);
+     707                 :          3 :             status = libspdm_transport_test_decode_message(spdm_context,
+     708                 :            :                                                            &message_session_id, &is_app_message,
+     709                 :            :                                                            true,
+     710                 :            :                                                            request_size,
+     711                 :            :                                                            message_buffer, &decoded_message_size,
+     712                 :            :                                                            (void **)&decoded_message);
+     713         [ -  + ]:          3 :             if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     714                 :          0 :                 return LIBSPDM_STATUS_SEND_FAIL;
+     715                 :            :             }
+     716                 :            : 
+     717                 :          3 :             m_libspdm_last_token = ((spdm_key_update_request_t
+     718                 :          3 :                                      *) decoded_message)->header.param2;
+     719                 :            :         }
+     720                 :            : 
+     721                 :          4 :         sub_index++;
+     722                 :            :     }
+     723                 :          4 :         return LIBSPDM_STATUS_SUCCESS;
+     724                 :          3 :     case 0x1E: {
+     725                 :            :         static size_t sub_index = 0;
+     726                 :            : 
+     727         [ +  + ]:          3 :         if(sub_index > 0) {
+     728                 :            :             libspdm_return_t status;
+     729                 :            :             uint8_t *decoded_message;
+     730                 :            :             size_t decoded_message_size;
+     731                 :            :             uint32_t session_id;
+     732                 :            :             uint32_t              *message_session_id;
+     733                 :            :             bool is_app_message;
+     734                 :            :             libspdm_session_info_t *session_info;
+     735                 :            :             uint8_t message_buffer[LIBSPDM_SENDER_BUFFER_SIZE];
+     736                 :            : 
+     737                 :          2 :             message_session_id = NULL;
+     738                 :          2 :             session_id = 0xFFFFFFFF;
+     739                 :            : 
+     740                 :          2 :             session_info = libspdm_get_session_info_via_session_id(
+     741                 :            :                 spdm_context, session_id);
+     742         [ -  + ]:          2 :             if (session_info == NULL) {
+     743                 :          0 :                 return LIBSPDM_STATUS_SEND_FAIL;
+     744                 :            :             }
+     745                 :            : 
+     746                 :          2 :             memcpy(message_buffer, request, request_size);
+     747                 :            : 
+     748                 :            :             ((libspdm_secured_message_context_t
+     749                 :          2 :               *)(session_info->secured_message_context))
+     750                 :          2 :             ->application_secret.request_data_sequence_number--;
+     751                 :          2 :             libspdm_get_scratch_buffer (spdm_context, (void **)&decoded_message,
+     752                 :            :                                         &decoded_message_size);
+     753                 :          2 :             status = libspdm_transport_test_decode_message(spdm_context,
+     754                 :            :                                                            &message_session_id, &is_app_message,
+     755                 :            :                                                            true,
+     756                 :            :                                                            request_size,
+     757                 :            :                                                            message_buffer, &decoded_message_size,
+     758                 :            :                                                            (void **)&decoded_message);
+     759         [ -  + ]:          2 :             if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     760                 :          0 :                 return LIBSPDM_STATUS_SEND_FAIL;
+     761                 :            :             }
+     762                 :            : 
+     763                 :          2 :             m_libspdm_last_token = ((spdm_key_update_request_t
+     764                 :          2 :                                      *) decoded_message)->header.param2;
+     765                 :            :         }
+     766                 :            : 
+     767                 :          3 :         sub_index++;
+     768                 :            :     }
+     769                 :          3 :         return LIBSPDM_STATUS_SUCCESS;
+     770                 :          3 :     case 0x1F:
+     771                 :            :     case 0x20:
+     772                 :          3 :         return LIBSPDM_STATUS_SUCCESS;
+     773                 :          3 :     case 0x21: {
+     774                 :            :         static size_t sub_index = 0;
+     775                 :            : 
+     776         [ +  + ]:          3 :         if(sub_index != 1) {
+     777                 :            :             libspdm_return_t status;
+     778                 :            :             uint8_t *decoded_message;
+     779                 :            :             size_t decoded_message_size;
+     780                 :            :             uint32_t session_id;
+     781                 :            :             uint32_t *message_session_id;
+     782                 :            :             bool is_app_message;
+     783                 :            :             libspdm_session_info_t    *session_info;
+     784                 :            :             uint8_t message_buffer[LIBSPDM_SENDER_BUFFER_SIZE];
+     785                 :            : 
+     786                 :          2 :             message_session_id = NULL;
+     787                 :          2 :             session_id = 0xFFFFFFFF;
+     788                 :            : 
+     789                 :          2 :             session_info = libspdm_get_session_info_via_session_id(
+     790                 :            :                 spdm_context, session_id);
+     791         [ -  + ]:          2 :             if (session_info == NULL) {
+     792                 :          0 :                 return LIBSPDM_STATUS_SEND_FAIL;
+     793                 :            :             }
+     794                 :            : 
+     795                 :          2 :             memcpy(message_buffer, request, request_size);
+     796                 :            : 
+     797                 :            :             ((libspdm_secured_message_context_t
+     798                 :          2 :               *)(session_info->secured_message_context))
+     799                 :          2 :             ->application_secret.request_data_sequence_number--;
+     800                 :          2 :             libspdm_get_scratch_buffer (spdm_context, (void **)&decoded_message,
+     801                 :            :                                         &decoded_message_size);
+     802                 :          2 :             status = libspdm_transport_test_decode_message(spdm_context,
+     803                 :            :                                                            &message_session_id, &is_app_message,
+     804                 :            :                                                            true,
+     805                 :            :                                                            request_size,
+     806                 :            :                                                            message_buffer, &decoded_message_size,
+     807                 :            :                                                            (void **)&decoded_message);
+     808         [ -  + ]:          2 :             if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     809                 :          0 :                 return LIBSPDM_STATUS_SEND_FAIL;
+     810                 :            :             }
+     811                 :            : 
+     812                 :          2 :             m_libspdm_last_token = ((spdm_key_update_request_t
+     813                 :          2 :                                      *) decoded_message)->header.param2;
+     814                 :            :         }
+     815                 :            : 
+     816                 :          3 :         sub_index++;
+     817                 :            :     }
+     818                 :          3 :         return LIBSPDM_STATUS_SUCCESS;
+     819                 :         17 :     case 0x22:
+     820                 :         17 :         return LIBSPDM_STATUS_SUCCESS;
+     821                 :          1 :     case 0x23:
+     822                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     823                 :          0 :     default:
+     824                 :          0 :         return LIBSPDM_STATUS_SEND_FAIL;
+     825                 :            :     }
+     826                 :            : }
+     827                 :            : 
+     828                 :        127 : libspdm_return_t libspdm_requester_key_update_test_receive_message(
+     829                 :            :     void *spdm_context, size_t *response_size,
+     830                 :            :     void **response, uint64_t timeout)
+     831                 :            : {
+     832                 :            :     libspdm_test_context_t *spdm_test_context;
+     833                 :            : 
+     834                 :        127 :     spdm_test_context = libspdm_get_test_context();
+     835   [ -  +  -  +  :        127 :     switch (spdm_test_context->case_id) {
+          +  +  +  +  +  
+          +  +  +  -  -  
+          +  +  +  +  +  
+          +  +  +  +  +  
+          +  +  +  +  +  
+          +  +  +  +  +  
+                   +  - ]
+     836                 :          0 :     case 0x1:
+     837                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+     838                 :            : 
+     839                 :          2 :     case 0x2: {
+     840                 :            :         static size_t sub_index = 0;
+     841                 :            : 
+     842                 :            :         spdm_key_update_response_t *spdm_response;
+     843                 :            :         size_t spdm_response_size;
+     844                 :            :         size_t transport_header_size;
+     845                 :            :         uint32_t session_id;
+     846                 :            :         libspdm_session_info_t        *session_info;
+     847                 :            :         uint8_t *scratch_buffer;
+     848                 :            :         size_t scratch_buffer_size;
+     849                 :            : 
+     850                 :          2 :         spdm_response_size = sizeof(spdm_key_update_response_t);
+     851                 :          2 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     852                 :          2 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     853                 :            : 
+     854                 :          2 :         session_id = 0xFFFFFFFF;
+     855                 :            : 
+     856                 :          2 :         session_info = libspdm_get_session_info_via_session_id(
+     857                 :            :             spdm_context, session_id);
+     858         [ -  + ]:          2 :         if (session_info == NULL) {
+     859                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+     860                 :            :         }
+     861                 :            : 
+     862                 :          2 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     863                 :          2 :         spdm_response->header.request_response_code =
+     864                 :            :             SPDM_KEY_UPDATE_ACK;
+     865         [ +  + ]:          2 :         if (sub_index == 0) {
+     866                 :          1 :             spdm_response->header.param1 =
+     867                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY;
+     868                 :          1 :             spdm_response->header.param2 = m_libspdm_last_token;
+     869         [ +  - ]:          1 :         } else if (sub_index == 1) {
+     870                 :          1 :             spdm_response->header.param1 =
+     871                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_VERIFY_NEW_KEY;
+     872                 :          1 :             spdm_response->header.param2 = m_libspdm_last_token;
+     873                 :            :         }
+     874                 :            : 
+     875                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+     876                 :            :          * transport_message is always in sender buffer. */
+     877                 :          2 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+     878                 :          2 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+     879                 :            :                           scratch_buffer_size - transport_header_size,
+     880                 :            :                           spdm_response, spdm_response_size);
+     881                 :          2 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+     882                 :          2 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+     883                 :            :                                               false, false, spdm_response_size,
+     884                 :            :                                               spdm_response, response_size, response);
+     885                 :            :         /* WALKAROUND: If just use single context to encode
+     886                 :            :          * message and then decode message */
+     887                 :            :         ((libspdm_secured_message_context_t
+     888                 :          2 :           *)(session_info->secured_message_context))
+     889                 :          2 :         ->application_secret.response_data_sequence_number--;
+     890                 :            : 
+     891                 :          2 :         sub_index++;
+     892                 :            :     }
+     893                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     894                 :            : 
+     895                 :          0 :     case 0x3: {
+     896                 :            :         static size_t sub_index = 0;
+     897                 :            : 
+     898                 :            :         spdm_key_update_response_t *spdm_response;
+     899                 :            :         size_t spdm_response_size;
+     900                 :            :         size_t transport_header_size;
+     901                 :            :         uint32_t session_id;
+     902                 :            :         libspdm_session_info_t        *session_info;
+     903                 :            :         uint8_t *scratch_buffer;
+     904                 :            :         size_t scratch_buffer_size;
+     905                 :            : 
+     906                 :          0 :         spdm_response_size = sizeof(spdm_key_update_response_t);
+     907                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     908                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     909                 :            : 
+     910                 :          0 :         session_id = 0xFFFFFFFF;
+     911                 :            : 
+     912                 :          0 :         session_info = libspdm_get_session_info_via_session_id(
+     913                 :            :             spdm_context, session_id);
+     914         [ #  # ]:          0 :         if (session_info == NULL) {
+     915                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+     916                 :            :         }
+     917                 :            : 
+     918                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     919                 :          0 :         spdm_response->header.request_response_code =
+     920                 :            :             SPDM_KEY_UPDATE_ACK;
+     921         [ #  # ]:          0 :         if (sub_index == 0) {
+     922                 :          0 :             spdm_response->header.param1 =
+     923                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY;
+     924                 :          0 :             spdm_response->header.param2 = m_libspdm_last_token;
+     925         [ #  # ]:          0 :         } else if (sub_index == 1) {
+     926                 :          0 :             spdm_response->header.param1 =
+     927                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_VERIFY_NEW_KEY;
+     928                 :          0 :             spdm_response->header.param2 = m_libspdm_last_token;
+     929                 :            :         }
+     930                 :            : 
+     931                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+     932                 :            :          * transport_message is always in sender buffer. */
+     933                 :          0 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+     934                 :          0 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+     935                 :            :                           scratch_buffer_size - transport_header_size,
+     936                 :            :                           spdm_response, spdm_response_size);
+     937                 :          0 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+     938                 :          0 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+     939                 :            :                                               false, false, spdm_response_size,
+     940                 :            :                                               spdm_response, response_size, response);
+     941                 :            :         /* WALKAROUND: If just use single context to encode
+     942                 :            :          * message and then decode message */
+     943                 :            :         ((libspdm_secured_message_context_t
+     944                 :          0 :           *)(session_info->secured_message_context))
+     945                 :          0 :         ->application_secret.response_data_sequence_number--;
+     946                 :            : 
+     947                 :          0 :         sub_index++;
+     948                 :            :     }
+     949                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     950                 :            : 
+     951                 :          1 :     case 0x4: {
+     952                 :            :         spdm_error_response_t *spdm_response;
+     953                 :            :         size_t spdm_response_size;
+     954                 :            :         size_t transport_header_size;
+     955                 :            :         uint32_t session_id;
+     956                 :            :         libspdm_session_info_t    *session_info;
+     957                 :            :         uint8_t *scratch_buffer;
+     958                 :            :         size_t scratch_buffer_size;
+     959                 :            : 
+     960                 :          1 :         spdm_response_size = sizeof(spdm_error_response_t);
+     961                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     962                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     963                 :            : 
+     964                 :          1 :         session_id = 0xFFFFFFFF;
+     965                 :          1 :         session_info = libspdm_get_session_info_via_session_id(
+     966                 :            :             spdm_context, session_id);
+     967         [ -  + ]:          1 :         if (session_info == NULL) {
+     968                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+     969                 :            :         }
+     970                 :            : 
+     971                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     972                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     973                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_INVALID_REQUEST;
+     974                 :          1 :         spdm_response->header.param2 = 0;
+     975                 :            : 
+     976                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+     977                 :            :          * transport_message is always in sender buffer. */
+     978                 :          1 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+     979                 :          1 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+     980                 :            :                           scratch_buffer_size - transport_header_size,
+     981                 :            :                           spdm_response, spdm_response_size);
+     982                 :          1 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+     983                 :          1 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+     984                 :            :                                               false, false, spdm_response_size,
+     985                 :            :                                               spdm_response, response_size, response);
+     986                 :            :         /* WALKAROUND: If just use single context to encode
+     987                 :            :          * message and then decode message */
+     988                 :            :         ((libspdm_secured_message_context_t
+     989                 :          1 :           *)(session_info->secured_message_context))
+     990                 :          1 :         ->application_secret.response_data_sequence_number--;
+     991                 :            :     }
+     992                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     993                 :            : 
+     994                 :          1 :     case 0x5: {
+     995                 :            :         spdm_error_response_t *spdm_response;
+     996                 :            :         size_t spdm_response_size;
+     997                 :            :         size_t transport_header_size;
+     998                 :            :         uint32_t session_id;
+     999                 :            :         libspdm_session_info_t    *session_info;
+    1000                 :            :         uint8_t *scratch_buffer;
+    1001                 :            :         size_t scratch_buffer_size;
+    1002                 :            : 
+    1003                 :          1 :         spdm_response_size = sizeof(spdm_error_response_t);
+    1004                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1005                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1006                 :            : 
+    1007                 :          1 :         session_id = 0xFFFFFFFF;
+    1008                 :          1 :         session_info = libspdm_get_session_info_via_session_id(
+    1009                 :            :             spdm_context, session_id);
+    1010         [ -  + ]:          1 :         if (session_info == NULL) {
+    1011                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+    1012                 :            :         }
+    1013                 :            : 
+    1014                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1015                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+    1016                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
+    1017                 :          1 :         spdm_response->header.param2 = 0;
+    1018                 :            : 
+    1019                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    1020                 :            :          * transport_message is always in sender buffer. */
+    1021                 :          1 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+    1022                 :          1 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+    1023                 :            :                           scratch_buffer_size - transport_header_size,
+    1024                 :            :                           spdm_response, spdm_response_size);
+    1025                 :          1 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+    1026                 :          1 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+    1027                 :            :                                               false, false, spdm_response_size,
+    1028                 :            :                                               spdm_response, response_size, response);
+    1029                 :            :         /* WALKAROUND: If just use single context to encode
+    1030                 :            :          * message and then decode message */
+    1031                 :            :         ((libspdm_secured_message_context_t
+    1032                 :          1 :           *)(session_info->secured_message_context))
+    1033                 :          1 :         ->application_secret.response_data_sequence_number--;
+    1034                 :            :     }
+    1035                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1036                 :            : 
+    1037                 :          3 :     case 0x6: {
+    1038                 :            :         static size_t sub_index = 0;
+    1039                 :            : 
+    1040                 :            :         uint32_t session_id;
+    1041                 :            :         libspdm_session_info_t    *session_info;
+    1042                 :            : 
+    1043                 :          3 :         session_id = 0xFFFFFFFF;
+    1044                 :          3 :         session_info = libspdm_get_session_info_via_session_id(
+    1045                 :            :             spdm_context, session_id);
+    1046         [ -  + ]:          3 :         if (session_info == NULL) {
+    1047                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+    1048                 :            :         }
+    1049                 :            : 
+    1050         [ +  + ]:          3 :         if (sub_index == 0) {
+    1051                 :            :             spdm_error_response_t *spdm_response;
+    1052                 :            :             size_t spdm_response_size;
+    1053                 :            :             size_t transport_header_size;
+    1054                 :            :             uint8_t *scratch_buffer;
+    1055                 :            :             size_t scratch_buffer_size;
+    1056                 :            : 
+    1057                 :          1 :             spdm_response_size = sizeof(spdm_error_response_t);
+    1058                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1059                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1060                 :            : 
+    1061                 :          1 :             spdm_response->header.spdm_version =
+    1062                 :            :                 SPDM_MESSAGE_VERSION_11;
+    1063                 :          1 :             spdm_response->header.request_response_code = SPDM_ERROR;
+    1064                 :          1 :             spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
+    1065                 :          1 :             spdm_response->header.param2 = 0;
+    1066                 :            : 
+    1067                 :            :             /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    1068                 :            :              * transport_message is always in sender buffer. */
+    1069                 :          1 :             libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+    1070                 :            :                                         &scratch_buffer_size);
+    1071                 :          1 :             libspdm_copy_mem (scratch_buffer + transport_header_size,
+    1072                 :            :                               scratch_buffer_size - transport_header_size,
+    1073                 :            :                               spdm_response, spdm_response_size);
+    1074                 :          1 :             spdm_response = (void *)(scratch_buffer + transport_header_size);
+    1075                 :          1 :             libspdm_transport_test_encode_message(spdm_context,
+    1076                 :            :                                                   &session_id, false, false,
+    1077                 :            :                                                   spdm_response_size, spdm_response,
+    1078                 :            :                                                   response_size, response);
+    1079                 :            :             /* WALKAROUND: If just use single context to encode
+    1080                 :            :              * message and then decode message */
+    1081                 :            :             ((libspdm_secured_message_context_t
+    1082                 :          1 :               *)(session_info->secured_message_context))
+    1083                 :          1 :             ->application_secret.response_data_sequence_number--;
+    1084         [ +  + ]:          2 :         } else if (sub_index == 1) {
+    1085                 :            :             spdm_key_update_response_t *spdm_response;
+    1086                 :            :             size_t spdm_response_size;
+    1087                 :            :             size_t transport_header_size;
+    1088                 :            :             uint8_t *scratch_buffer;
+    1089                 :            :             size_t scratch_buffer_size;
+    1090                 :            : 
+    1091                 :          1 :             spdm_response_size = sizeof(spdm_key_update_response_t);
+    1092                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1093                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1094                 :            : 
+    1095                 :          1 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1096                 :          1 :             spdm_response->header.request_response_code =
+    1097                 :            :                 SPDM_KEY_UPDATE_ACK;
+    1098                 :          1 :             spdm_response->header.param1 =
+    1099                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY;
+    1100                 :          1 :             spdm_response->header.param2 = m_libspdm_last_token;
+    1101                 :            : 
+    1102                 :            :             /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    1103                 :            :              * transport_message is always in sender buffer. */
+    1104                 :          1 :             libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+    1105                 :            :                                         &scratch_buffer_size);
+    1106                 :          1 :             libspdm_copy_mem (scratch_buffer + transport_header_size,
+    1107                 :            :                               scratch_buffer_size - transport_header_size,
+    1108                 :            :                               spdm_response, spdm_response_size);
+    1109                 :          1 :             spdm_response = (void *)(scratch_buffer + transport_header_size);
+    1110                 :          1 :             libspdm_transport_test_encode_message(spdm_context,
+    1111                 :            :                                                   &session_id, false, false,
+    1112                 :            :                                                   spdm_response_size, spdm_response,
+    1113                 :            :                                                   response_size, response);
+    1114                 :            :             /* WALKAROUND: If just use single context to encode
+    1115                 :            :              * message and then decode message */
+    1116                 :            :             ((libspdm_secured_message_context_t
+    1117                 :          1 :               *)(session_info->secured_message_context))
+    1118                 :          1 :             ->application_secret.response_data_sequence_number--;
+    1119         [ +  - ]:          1 :         } else if (sub_index == 2) {
+    1120                 :            :             spdm_key_update_response_t *spdm_response;
+    1121                 :            :             size_t spdm_response_size;
+    1122                 :            :             size_t transport_header_size;
+    1123                 :            :             uint8_t *scratch_buffer;
+    1124                 :            :             size_t scratch_buffer_size;
+    1125                 :            : 
+    1126                 :          1 :             spdm_response_size = sizeof(spdm_key_update_response_t);
+    1127                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1128                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1129                 :            : 
+    1130                 :          1 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1131                 :          1 :             spdm_response->header.request_response_code =
+    1132                 :            :                 SPDM_KEY_UPDATE_ACK;
+    1133                 :          1 :             spdm_response->header.param1 =
+    1134                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_VERIFY_NEW_KEY;
+    1135                 :          1 :             spdm_response->header.param2 = m_libspdm_last_token;
+    1136                 :            : 
+    1137                 :            :             /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    1138                 :            :              * transport_message is always in sender buffer. */
+    1139                 :          1 :             libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+    1140                 :            :                                         &scratch_buffer_size);
+    1141                 :          1 :             libspdm_copy_mem (scratch_buffer + transport_header_size,
+    1142                 :            :                               scratch_buffer_size - transport_header_size,
+    1143                 :            :                               spdm_response, spdm_response_size);
+    1144                 :          1 :             spdm_response = (void *)(scratch_buffer + transport_header_size);
+    1145                 :          1 :             libspdm_transport_test_encode_message(spdm_context,
+    1146                 :            :                                                   &session_id, false, false,
+    1147                 :            :                                                   spdm_response_size, spdm_response,
+    1148                 :            :                                                   response_size, response);
+    1149                 :            :             /* WALKAROUND: If just use single context to encode
+    1150                 :            :              * message and then decode message */
+    1151                 :            :             ((libspdm_secured_message_context_t
+    1152                 :          1 :               *)(session_info->secured_message_context))
+    1153                 :          1 :             ->application_secret.response_data_sequence_number--;
+    1154                 :            :         }
+    1155                 :            : 
+    1156                 :          3 :         sub_index++;
+    1157                 :            :     }
+    1158                 :          3 :         return LIBSPDM_STATUS_SUCCESS;
+    1159                 :            : 
+    1160                 :          1 :     case 0x7: {
+    1161                 :            :         spdm_error_response_t *spdm_response;
+    1162                 :            :         size_t spdm_response_size;
+    1163                 :            :         size_t transport_header_size;
+    1164                 :            :         uint32_t session_id;
+    1165                 :            :         libspdm_session_info_t    *session_info;
+    1166                 :            :         uint8_t *scratch_buffer;
+    1167                 :            :         size_t scratch_buffer_size;
+    1168                 :            : 
+    1169                 :          1 :         spdm_response_size = sizeof(spdm_error_response_t);
+    1170                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1171                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1172                 :            : 
+    1173                 :          1 :         session_id = 0xFFFFFFFF;
+    1174                 :          1 :         session_info = libspdm_get_session_info_via_session_id(
+    1175                 :            :             spdm_context, session_id);
+    1176         [ -  + ]:          1 :         if (session_info == NULL) {
+    1177                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+    1178                 :            :         }
+    1179                 :            : 
+    1180                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1181                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+    1182                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_REQUEST_RESYNCH;
+    1183                 :          1 :         spdm_response->header.param2 = 0;
+    1184                 :            : 
+    1185                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    1186                 :            :          * transport_message is always in sender buffer. */
+    1187                 :          1 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+    1188                 :          1 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+    1189                 :            :                           scratch_buffer_size - transport_header_size,
+    1190                 :            :                           spdm_response, spdm_response_size);
+    1191                 :          1 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+    1192                 :          1 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+    1193                 :            :                                               false, false, spdm_response_size,
+    1194                 :            :                                               spdm_response, response_size, response);
+    1195                 :            :         /* WALKAROUND: If just use single context to encode
+    1196                 :            :          * message and then decode message */
+    1197                 :            :         ((libspdm_secured_message_context_t
+    1198                 :          1 :           *)(session_info->secured_message_context))
+    1199                 :          1 :         ->application_secret.response_data_sequence_number--;
+    1200                 :            :     }
+    1201                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1202                 :            : 
+    1203                 :          2 :     case 0x8: {
+    1204                 :            :         spdm_error_response_data_response_not_ready_t *spdm_response;
+    1205                 :            :         size_t spdm_response_size;
+    1206                 :            :         size_t transport_header_size;
+    1207                 :            :         uint32_t session_id;
+    1208                 :            :         libspdm_session_info_t    *session_info;
+    1209                 :            :         uint8_t *scratch_buffer;
+    1210                 :            :         size_t scratch_buffer_size;
+    1211                 :            : 
+    1212                 :          2 :         spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
+    1213                 :          2 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1214                 :          2 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1215                 :            : 
+    1216                 :          2 :         session_id = 0xFFFFFFFF;
+    1217                 :          2 :         session_info = libspdm_get_session_info_via_session_id(
+    1218                 :            :             spdm_context, session_id);
+    1219         [ -  + ]:          2 :         if (session_info == NULL) {
+    1220                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+    1221                 :            :         }
+    1222                 :            : 
+    1223                 :          2 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1224                 :          2 :         spdm_response->header.request_response_code = SPDM_ERROR;
+    1225                 :          2 :         spdm_response->header.param1 =
+    1226                 :            :             SPDM_ERROR_CODE_RESPONSE_NOT_READY;
+    1227                 :          2 :         spdm_response->header.param2 = 0;
+    1228                 :          2 :         spdm_response->extend_error_data.rd_exponent = 1;
+    1229                 :          2 :         spdm_response->extend_error_data.rd_tm = 2;
+    1230                 :          2 :         spdm_response->extend_error_data.request_code = SPDM_KEY_UPDATE;
+    1231                 :          2 :         spdm_response->extend_error_data.token = 0;
+    1232                 :            : 
+    1233                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    1234                 :            :          * transport_message is always in sender buffer. */
+    1235                 :          2 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+    1236                 :          2 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+    1237                 :            :                           scratch_buffer_size - transport_header_size,
+    1238                 :            :                           spdm_response, spdm_response_size);
+    1239                 :          2 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+    1240                 :          2 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+    1241                 :            :                                               false, false, spdm_response_size,
+    1242                 :            :                                               spdm_response, response_size, response);
+    1243                 :            :         /* WALKAROUND: If just use single context to encode
+    1244                 :            :          * message and then decode message */
+    1245                 :            :         ((libspdm_secured_message_context_t
+    1246                 :          2 :           *)(session_info->secured_message_context))
+    1247                 :          2 :         ->application_secret.response_data_sequence_number--;
+    1248                 :            :     }
+    1249                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+    1250                 :            : 
+    1251                 :          3 :     case 0x9: {
+    1252                 :            :         static size_t sub_index = 0;
+    1253                 :            : 
+    1254                 :            :         uint32_t session_id;
+    1255                 :            :         libspdm_session_info_t    *session_info;
+    1256                 :            : 
+    1257                 :          3 :         session_id = 0xFFFFFFFF;
+    1258                 :          3 :         session_info = libspdm_get_session_info_via_session_id(
+    1259                 :            :             spdm_context, session_id);
+    1260         [ -  + ]:          3 :         if (session_info == NULL) {
+    1261                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+    1262                 :            :         }
+    1263                 :            : 
+    1264         [ +  + ]:          3 :         if (sub_index == 0) {
+    1265                 :            :             spdm_error_response_data_response_not_ready_t
+    1266                 :            :             *spdm_response;
+    1267                 :            :             size_t spdm_response_size;
+    1268                 :            :             size_t transport_header_size;
+    1269                 :            :             uint8_t *scratch_buffer;
+    1270                 :            :             size_t scratch_buffer_size;
+    1271                 :            : 
+    1272                 :          1 :             spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
+    1273                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1274                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1275                 :            : 
+    1276                 :          1 :             spdm_response->header.spdm_version =
+    1277                 :            :                 SPDM_MESSAGE_VERSION_11;
+    1278                 :          1 :             spdm_response->header.request_response_code = SPDM_ERROR;
+    1279                 :          1 :             spdm_response->header.param1 =
+    1280                 :            :                 SPDM_ERROR_CODE_RESPONSE_NOT_READY;
+    1281                 :          1 :             spdm_response->header.param2 = 0;
+    1282                 :          1 :             spdm_response->extend_error_data.rd_exponent = 1;
+    1283                 :          1 :             spdm_response->extend_error_data.rd_tm = 2;
+    1284                 :          1 :             spdm_response->extend_error_data.request_code =
+    1285                 :            :                 SPDM_KEY_UPDATE;
+    1286                 :          1 :             spdm_response->extend_error_data.token = 1;
+    1287                 :            : 
+    1288                 :            :             /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    1289                 :            :              * transport_message is always in sender buffer. */
+    1290                 :          1 :             libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+    1291                 :            :                                         &scratch_buffer_size);
+    1292                 :          1 :             libspdm_copy_mem (scratch_buffer + transport_header_size,
+    1293                 :            :                               scratch_buffer_size - transport_header_size,
+    1294                 :            :                               spdm_response, spdm_response_size);
+    1295                 :          1 :             spdm_response = (void *)(scratch_buffer + transport_header_size);
+    1296                 :          1 :             libspdm_transport_test_encode_message(spdm_context,
+    1297                 :            :                                                   &session_id, false, false,
+    1298                 :            :                                                   spdm_response_size, spdm_response,
+    1299                 :            :                                                   response_size, response);
+    1300                 :            :             /* WALKAROUND: If just use single context to encode
+    1301                 :            :              * message and then decode message */
+    1302                 :            :             ((libspdm_secured_message_context_t
+    1303                 :          1 :               *)(session_info->secured_message_context))
+    1304                 :          1 :             ->application_secret.response_data_sequence_number--;
+    1305         [ +  + ]:          2 :         } else if (sub_index == 1) {
+    1306                 :            :             spdm_key_update_response_t *spdm_response;
+    1307                 :            :             size_t spdm_response_size;
+    1308                 :            :             size_t transport_header_size;
+    1309                 :            :             uint8_t *scratch_buffer;
+    1310                 :            :             size_t scratch_buffer_size;
+    1311                 :            : 
+    1312                 :          1 :             spdm_response_size = sizeof(spdm_key_update_response_t);
+    1313                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1314                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1315                 :            : 
+    1316                 :          1 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1317                 :          1 :             spdm_response->header.request_response_code =
+    1318                 :            :                 SPDM_KEY_UPDATE_ACK;
+    1319                 :          1 :             spdm_response->header.param1 =
+    1320                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY;
+    1321                 :          1 :             spdm_response->header.param2 = m_libspdm_last_token;
+    1322                 :            : 
+    1323                 :            :             /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    1324                 :            :              * transport_message is always in sender buffer. */
+    1325                 :          1 :             libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+    1326                 :            :                                         &scratch_buffer_size);
+    1327                 :          1 :             libspdm_copy_mem (scratch_buffer + transport_header_size,
+    1328                 :            :                               scratch_buffer_size - transport_header_size,
+    1329                 :            :                               spdm_response, spdm_response_size);
+    1330                 :          1 :             spdm_response = (void *)(scratch_buffer + transport_header_size);
+    1331                 :          1 :             libspdm_transport_test_encode_message(spdm_context,
+    1332                 :            :                                                   &session_id, false, false,
+    1333                 :            :                                                   spdm_response_size, spdm_response,
+    1334                 :            :                                                   response_size, response);
+    1335                 :            :             /* WALKAROUND: If just use single context to encode
+    1336                 :            :              * message and then decode message */
+    1337                 :            :             ((libspdm_secured_message_context_t
+    1338                 :          1 :               *)(session_info->secured_message_context))
+    1339                 :          1 :             ->application_secret.response_data_sequence_number--;
+    1340         [ +  - ]:          1 :         } else if (sub_index == 2) {
+    1341                 :            :             spdm_key_update_response_t *spdm_response;
+    1342                 :            :             size_t spdm_response_size;
+    1343                 :            :             size_t transport_header_size;
+    1344                 :            :             uint8_t *scratch_buffer;
+    1345                 :            :             size_t scratch_buffer_size;
+    1346                 :            : 
+    1347                 :          1 :             spdm_response_size = sizeof(spdm_key_update_response_t);
+    1348                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1349                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1350                 :            : 
+    1351                 :          1 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1352                 :          1 :             spdm_response->header.request_response_code =
+    1353                 :            :                 SPDM_KEY_UPDATE_ACK;
+    1354                 :          1 :             spdm_response->header.param1 =
+    1355                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_VERIFY_NEW_KEY;
+    1356                 :          1 :             spdm_response->header.param2 = m_libspdm_last_token;
+    1357                 :            : 
+    1358                 :            :             /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    1359                 :            :              * transport_message is always in sender buffer. */
+    1360                 :          1 :             libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+    1361                 :            :                                         &scratch_buffer_size);
+    1362                 :          1 :             libspdm_copy_mem (scratch_buffer + transport_header_size,
+    1363                 :            :                               scratch_buffer_size - transport_header_size,
+    1364                 :            :                               spdm_response, spdm_response_size);
+    1365                 :          1 :             spdm_response = (void *)(scratch_buffer + transport_header_size);
+    1366                 :          1 :             libspdm_transport_test_encode_message(spdm_context,
+    1367                 :            :                                                   &session_id, false, false,
+    1368                 :            :                                                   spdm_response_size, spdm_response,
+    1369                 :            :                                                   response_size, response);
+    1370                 :            :             /* WALKAROUND: If just use single context to encode
+    1371                 :            :              * message and then decode message */
+    1372                 :            :             ((libspdm_secured_message_context_t
+    1373                 :          1 :               *)(session_info->secured_message_context))
+    1374                 :          1 :             ->application_secret.response_data_sequence_number--;
+    1375                 :            :         }
+    1376                 :            : 
+    1377                 :          3 :         sub_index++;
+    1378                 :            :     }
+    1379                 :          3 :         return LIBSPDM_STATUS_SUCCESS;
+    1380                 :            : 
+    1381                 :         17 :     case 0xA: {
+    1382                 :            :         static uint16_t error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
+    1383                 :            : 
+    1384                 :            :         uint32_t session_id;
+    1385                 :            :         libspdm_session_info_t    *session_info;
+    1386                 :            : 
+    1387                 :            :         spdm_error_response_t *spdm_response;
+    1388                 :            :         size_t spdm_response_size;
+    1389                 :            :         size_t transport_header_size;
+    1390                 :            :         uint8_t *scratch_buffer;
+    1391                 :            :         size_t scratch_buffer_size;
+    1392                 :            : 
+    1393                 :         17 :         spdm_response_size = sizeof(spdm_error_response_t);
+    1394                 :         17 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1395                 :         17 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1396                 :            : 
+    1397                 :         17 :         session_id = 0xFFFFFFFF;
+    1398                 :         17 :         session_info = libspdm_get_session_info_via_session_id(
+    1399                 :            :             spdm_context, session_id);
+    1400         [ -  + ]:         17 :         if (session_info == NULL) {
+    1401                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+    1402                 :            :         }
+    1403                 :            : 
+    1404         [ +  - ]:         17 :         if(error_code <= 0xff) {
+    1405                 :            :             /* skip SPDM_ERROR_CODE_DECRYPT_ERROR, because this case will free context*/
+    1406         [ +  + ]:         17 :             if(error_code == SPDM_ERROR_CODE_DECRYPT_ERROR) {
+    1407                 :          1 :                 error_code++;
+    1408                 :            :             }
+    1409                 :         17 :             libspdm_zero_mem (spdm_response, spdm_response_size);
+    1410                 :         17 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1411                 :         17 :             spdm_response->header.request_response_code = SPDM_ERROR;
+    1412                 :         17 :             spdm_response->header.param1 = (uint8_t) error_code;
+    1413                 :         17 :             spdm_response->header.param2 = 0;
+    1414                 :            : 
+    1415                 :            :             /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    1416                 :            :              * transport_message is always in sender buffer. */
+    1417                 :         17 :             libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+    1418                 :            :                                         &scratch_buffer_size);
+    1419                 :         17 :             libspdm_copy_mem (scratch_buffer + transport_header_size,
+    1420                 :            :                               scratch_buffer_size - transport_header_size,
+    1421                 :            :                               spdm_response, spdm_response_size);
+    1422                 :         17 :             spdm_response = (void *)(scratch_buffer + transport_header_size);
+    1423                 :         17 :             libspdm_transport_test_encode_message(spdm_context,
+    1424                 :            :                                                   &session_id, false, false,
+    1425                 :            :                                                   spdm_response_size, spdm_response,
+    1426                 :            :                                                   response_size, response);
+    1427                 :            :             /* WALKAROUND: If just use single context to encode
+    1428                 :            :              * message and then decode message */
+    1429                 :            :             ((libspdm_secured_message_context_t
+    1430                 :         17 :               *)(session_info->secured_message_context))
+    1431                 :         17 :             ->application_secret.response_data_sequence_number--;
+    1432                 :            :         }
+    1433                 :            : 
+    1434                 :         17 :         error_code++;
+    1435                 :            :         /*busy is treated in cases 5 and 6*/
+    1436         [ +  + ]:         17 :         if(error_code == SPDM_ERROR_CODE_BUSY) {
+    1437                 :          1 :             error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
+    1438                 :            :         }
+    1439                 :            :         /*skip some reserved error codes (0d to 3e)*/
+    1440         [ +  + ]:         17 :         if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) {
+    1441                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
+    1442                 :            :         }
+    1443                 :            :         /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
+    1444         [ +  + ]:         17 :         if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) {
+    1445                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
+    1446                 :            :         }
+    1447                 :            :     }
+    1448                 :         17 :         return LIBSPDM_STATUS_SUCCESS;
+    1449                 :            : 
+    1450                 :          2 :     case 0xB: {
+    1451                 :            :         static size_t sub_index = 0;
+    1452                 :            : 
+    1453                 :            :         spdm_key_update_response_t *spdm_response;
+    1454                 :            :         size_t spdm_response_size;
+    1455                 :            :         size_t transport_header_size;
+    1456                 :            :         uint32_t session_id;
+    1457                 :            :         libspdm_session_info_t        *session_info;
+    1458                 :            :         uint8_t *scratch_buffer;
+    1459                 :            :         size_t scratch_buffer_size;
+    1460                 :            : 
+    1461                 :          2 :         spdm_response_size = sizeof(spdm_key_update_response_t);
+    1462                 :          2 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1463                 :          2 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1464                 :            : 
+    1465                 :          2 :         session_id = 0xFFFFFFFF;
+    1466                 :            : 
+    1467                 :          2 :         session_info = libspdm_get_session_info_via_session_id(
+    1468                 :            :             spdm_context, session_id);
+    1469         [ -  + ]:          2 :         if (session_info == NULL) {
+    1470                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+    1471                 :            :         }
+    1472                 :            : 
+    1473                 :          2 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1474                 :          2 :         spdm_response->header.request_response_code =
+    1475                 :            :             SPDM_KEY_UPDATE_ACK;
+    1476         [ +  + ]:          2 :         if (sub_index == 0) {
+    1477                 :          1 :             spdm_response->header.param1 =
+    1478                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY;
+    1479                 :          1 :             spdm_response->header.param2 = m_libspdm_last_token;
+    1480         [ +  - ]:          1 :         } else if (sub_index == 1) {
+    1481                 :          1 :             spdm_response->header.param1 =
+    1482                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_VERIFY_NEW_KEY;
+    1483                 :          1 :             spdm_response->header.param2 = m_libspdm_last_token;
+    1484                 :            :         }
+    1485                 :            : 
+    1486                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    1487                 :            :          * transport_message is always in sender buffer. */
+    1488                 :          2 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+    1489                 :          2 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+    1490                 :            :                           scratch_buffer_size - transport_header_size,
+    1491                 :            :                           spdm_response, spdm_response_size);
+    1492                 :          2 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+    1493                 :          2 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+    1494                 :            :                                               false, false, spdm_response_size,
+    1495                 :            :                                               spdm_response, response_size, response);
+    1496                 :            :         /* WALKAROUND: If just use single context to encode
+    1497                 :            :          * message and then decode message */
+    1498                 :            :         ((libspdm_secured_message_context_t
+    1499                 :          2 :           *)(session_info->secured_message_context))
+    1500                 :          2 :         ->application_secret.response_data_sequence_number--;
+    1501                 :            : 
+    1502                 :          2 :         sub_index++;
+    1503                 :            :     }
+    1504                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+    1505                 :            : 
+    1506                 :          1 :     case 0xC: {
+    1507                 :            :         static size_t sub_index = 0;
+    1508                 :            : 
+    1509                 :            :         spdm_key_update_response_t *spdm_response;
+    1510                 :            :         size_t spdm_response_size;
+    1511                 :            :         size_t transport_header_size;
+    1512                 :            :         uint32_t session_id;
+    1513                 :            :         libspdm_session_info_t        *session_info;
+    1514                 :            :         uint8_t *scratch_buffer;
+    1515                 :            :         size_t scratch_buffer_size;
+    1516                 :            : 
+    1517                 :          1 :         spdm_response_size = sizeof(spdm_key_update_response_t);
+    1518                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1519                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1520                 :            : 
+    1521                 :          1 :         session_id = 0xFFFFFFFF;
+    1522                 :            : 
+    1523                 :          1 :         session_info = libspdm_get_session_info_via_session_id(
+    1524                 :            :             spdm_context, session_id);
+    1525         [ -  + ]:          1 :         if (session_info == NULL) {
+    1526                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+    1527                 :            :         }
+    1528                 :            : 
+    1529                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1530                 :            :         /*wrong response code*/
+    1531                 :          1 :         spdm_response->header.request_response_code =
+    1532                 :            :             SPDM_KEY_UPDATE;
+    1533         [ +  - ]:          1 :         if (sub_index == 0) {
+    1534                 :          1 :             spdm_response->header.param1 =
+    1535                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY;
+    1536                 :          1 :             spdm_response->header.param2 = m_libspdm_last_token;
+    1537         [ #  # ]:          0 :         } else if (sub_index == 1) {
+    1538                 :          0 :             spdm_response->header.param1 =
+    1539                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_VERIFY_NEW_KEY;
+    1540                 :          0 :             spdm_response->header.param2 = m_libspdm_last_token;
+    1541                 :            :         }
+    1542                 :            : 
+    1543                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    1544                 :            :          * transport_message is always in sender buffer. */
+    1545                 :          1 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+    1546                 :          1 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+    1547                 :            :                           scratch_buffer_size - transport_header_size,
+    1548                 :            :                           spdm_response, spdm_response_size);
+    1549                 :          1 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+    1550                 :          1 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+    1551                 :            :                                               false, false, spdm_response_size,
+    1552                 :            :                                               spdm_response, response_size, response);
+    1553                 :            :         /* WALKAROUND: If just use single context to encode
+    1554                 :            :          * message and then decode message */
+    1555                 :            :         ((libspdm_secured_message_context_t
+    1556                 :          1 :           *)(session_info->secured_message_context))
+    1557                 :          1 :         ->application_secret.response_data_sequence_number--;
+    1558                 :            : 
+    1559                 :          1 :         sub_index++;
+    1560                 :            :     }
+    1561                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1562                 :            : 
+    1563                 :          0 :     case 0xD: {
+    1564                 :            :         static size_t sub_index = 0;
+    1565                 :            : 
+    1566                 :            :         spdm_key_update_response_t *spdm_response;
+    1567                 :            :         size_t spdm_response_size;
+    1568                 :            :         size_t transport_header_size;
+    1569                 :            :         uint32_t session_id;
+    1570                 :            :         libspdm_session_info_t        *session_info;
+    1571                 :            :         uint8_t *scratch_buffer;
+    1572                 :            :         size_t scratch_buffer_size;
+    1573                 :            : 
+    1574                 :          0 :         spdm_response_size = sizeof(spdm_key_update_response_t);
+    1575                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1576                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1577                 :            : 
+    1578                 :          0 :         session_id = 0xFFFFFFFF;
+    1579                 :            : 
+    1580                 :          0 :         session_info = libspdm_get_session_info_via_session_id(
+    1581                 :            :             spdm_context, session_id);
+    1582         [ #  # ]:          0 :         if (session_info == NULL) {
+    1583                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+    1584                 :            :         }
+    1585                 :            : 
+    1586                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1587                 :          0 :         spdm_response->header.request_response_code =
+    1588                 :            :             SPDM_KEY_UPDATE_ACK;
+    1589         [ #  # ]:          0 :         if (sub_index == 0) {
+    1590                 :          0 :             spdm_response->header.param1 =
+    1591                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY;
+    1592                 :          0 :             spdm_response->header.param2 = m_libspdm_last_token;
+    1593         [ #  # ]:          0 :         } else if (sub_index == 1) {
+    1594                 :          0 :             spdm_response->header.param1 =
+    1595                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_VERIFY_NEW_KEY;
+    1596                 :          0 :             spdm_response->header.param2 = m_libspdm_last_token;
+    1597                 :            :         }
+    1598                 :            : 
+    1599                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    1600                 :            :          * transport_message is always in sender buffer. */
+    1601                 :          0 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+    1602                 :          0 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+    1603                 :            :                           scratch_buffer_size - transport_header_size,
+    1604                 :            :                           spdm_response, spdm_response_size);
+    1605                 :          0 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+    1606                 :          0 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+    1607                 :            :                                               false, false, spdm_response_size,
+    1608                 :            :                                               spdm_response, response_size, response);
+    1609                 :            :         /* WALKAROUND: If just use single context to encode
+    1610                 :            :          * message and then decode message */
+    1611                 :            :         ((libspdm_secured_message_context_t
+    1612                 :          0 :           *)(session_info->secured_message_context))
+    1613                 :          0 :         ->application_secret.response_data_sequence_number--;
+    1614                 :            : 
+    1615                 :          0 :         sub_index++;
+    1616                 :            :     }
+    1617                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+    1618                 :            : 
+    1619                 :          0 :     case 0xE: {
+    1620                 :            :         static size_t sub_index = 0;
+    1621                 :            : 
+    1622                 :            :         spdm_key_update_response_t *spdm_response;
+    1623                 :            :         size_t spdm_response_size;
+    1624                 :            :         size_t transport_header_size;
+    1625                 :            :         uint32_t session_id;
+    1626                 :            :         libspdm_session_info_t        *session_info;
+    1627                 :            :         uint8_t *scratch_buffer;
+    1628                 :            :         size_t scratch_buffer_size;
+    1629                 :            : 
+    1630                 :          0 :         spdm_response_size = sizeof(spdm_key_update_response_t);
+    1631                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1632                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1633                 :            : 
+    1634                 :          0 :         session_id = 0xFFFFFFFF;
+    1635                 :            : 
+    1636                 :          0 :         session_info = libspdm_get_session_info_via_session_id(
+    1637                 :            :             spdm_context, session_id);
+    1638         [ #  # ]:          0 :         if (session_info == NULL) {
+    1639                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+    1640                 :            :         }
+    1641                 :            : 
+    1642                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1643                 :          0 :         spdm_response->header.request_response_code =
+    1644                 :            :             SPDM_KEY_UPDATE_ACK;
+    1645         [ #  # ]:          0 :         if (sub_index == 0) {
+    1646                 :          0 :             spdm_response->header.param1 =
+    1647                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY;
+    1648                 :          0 :             spdm_response->header.param2 = m_libspdm_last_token;
+    1649         [ #  # ]:          0 :         } else if (sub_index == 1) {
+    1650                 :          0 :             spdm_response->header.param1 =
+    1651                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_VERIFY_NEW_KEY;
+    1652                 :          0 :             spdm_response->header.param2 = m_libspdm_last_token;
+    1653                 :            :         }
+    1654                 :            : 
+    1655                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    1656                 :            :          * transport_message is always in sender buffer. */
+    1657                 :          0 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+    1658                 :          0 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+    1659                 :            :                           scratch_buffer_size - transport_header_size,
+    1660                 :            :                           spdm_response, spdm_response_size);
+    1661                 :          0 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+    1662                 :          0 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+    1663                 :            :                                               false, false, spdm_response_size,
+    1664                 :            :                                               spdm_response, response_size, response);
+    1665                 :            :         /* WALKAROUND: If just use single context to encode
+    1666                 :            :          * message and then decode message */
+    1667                 :            :         ((libspdm_secured_message_context_t
+    1668                 :          0 :           *)(session_info->secured_message_context))
+    1669                 :          0 :         ->application_secret.response_data_sequence_number--;
+    1670                 :            : 
+    1671                 :          0 :         sub_index++;
+    1672                 :            :     }
+    1673                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+    1674                 :            : 
+    1675                 :          1 :     case 0xF: {
+    1676                 :            :         static size_t sub_index = 0;
+    1677                 :            : 
+    1678                 :            :         spdm_key_update_response_t *spdm_response;
+    1679                 :            :         size_t spdm_response_size;
+    1680                 :            :         size_t transport_header_size;
+    1681                 :            :         uint32_t session_id;
+    1682                 :            :         libspdm_session_info_t        *session_info;
+    1683                 :            :         uint8_t *scratch_buffer;
+    1684                 :            :         size_t scratch_buffer_size;
+    1685                 :            : 
+    1686                 :          1 :         spdm_response_size = sizeof(spdm_key_update_response_t);
+    1687                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1688                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1689                 :            : 
+    1690                 :          1 :         session_id = 0xFFFFFFFF;
+    1691                 :            : 
+    1692                 :          1 :         session_info = libspdm_get_session_info_via_session_id(
+    1693                 :            :             spdm_context, session_id);
+    1694         [ -  + ]:          1 :         if (session_info == NULL) {
+    1695                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+    1696                 :            :         }
+    1697                 :            : 
+    1698                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1699                 :          1 :         spdm_response->header.request_response_code =
+    1700                 :            :             SPDM_KEY_UPDATE_ACK;
+    1701         [ +  - ]:          1 :         if (sub_index == 0) {
+    1702                 :          1 :             spdm_response->header.param1 =
+    1703                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY;
+    1704                 :            :             /*wrong token*/
+    1705                 :          1 :             spdm_response->header.param2 = m_libspdm_last_token + 1;
+    1706         [ #  # ]:          0 :         } else if (sub_index == 1) {
+    1707                 :          0 :             spdm_response->header.param1 =
+    1708                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_VERIFY_NEW_KEY;
+    1709                 :          0 :             spdm_response->header.param2 = m_libspdm_last_token;
+    1710                 :            :         }
+    1711                 :            : 
+    1712                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    1713                 :            :          * transport_message is always in sender buffer. */
+    1714                 :          1 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+    1715                 :          1 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+    1716                 :            :                           scratch_buffer_size - transport_header_size,
+    1717                 :            :                           spdm_response, spdm_response_size);
+    1718                 :          1 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+    1719                 :          1 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+    1720                 :            :                                               false, false, spdm_response_size,
+    1721                 :            :                                               spdm_response, response_size, response);
+    1722                 :            :         /* WALKAROUND: If just use single context to encode
+    1723                 :            :          * message and then decode message */
+    1724                 :            :         ((libspdm_secured_message_context_t
+    1725                 :          1 :           *)(session_info->secured_message_context))
+    1726                 :          1 :         ->application_secret.response_data_sequence_number--;
+    1727                 :            : 
+    1728                 :          1 :         sub_index++;
+    1729                 :            :     }
+    1730                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1731                 :            : 
+    1732                 :          1 :     case 0x10: {
+    1733                 :            :         static size_t sub_index = 0;
+    1734                 :            : 
+    1735                 :            :         spdm_key_update_response_t *spdm_response;
+    1736                 :            :         size_t spdm_response_size;
+    1737                 :            :         size_t transport_header_size;
+    1738                 :            :         uint32_t session_id;
+    1739                 :            :         libspdm_session_info_t        *session_info;
+    1740                 :            :         uint8_t *scratch_buffer;
+    1741                 :            :         size_t scratch_buffer_size;
+    1742                 :            : 
+    1743                 :          1 :         spdm_response_size = sizeof(spdm_key_update_response_t);
+    1744                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1745                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1746                 :            : 
+    1747                 :          1 :         session_id = 0xFFFFFFFF;
+    1748                 :            : 
+    1749                 :          1 :         session_info = libspdm_get_session_info_via_session_id(
+    1750                 :            :             spdm_context, session_id);
+    1751         [ -  + ]:          1 :         if (session_info == NULL) {
+    1752                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+    1753                 :            :         }
+    1754                 :            : 
+    1755                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1756                 :          1 :         spdm_response->header.request_response_code =
+    1757                 :            :             SPDM_KEY_UPDATE_ACK;
+    1758         [ +  - ]:          1 :         if (sub_index == 0) {
+    1759                 :            :             /*wrong operation code*/
+    1760                 :          1 :             spdm_response->header.param1 =
+    1761                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_ALL_KEYS;
+    1762                 :          1 :             spdm_response->header.param2 = m_libspdm_last_token;
+    1763         [ #  # ]:          0 :         } else if (sub_index == 1) {
+    1764                 :          0 :             spdm_response->header.param1 =
+    1765                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_VERIFY_NEW_KEY;
+    1766                 :          0 :             spdm_response->header.param2 = m_libspdm_last_token;
+    1767                 :            :         }
+    1768                 :            : 
+    1769                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    1770                 :            :          * transport_message is always in sender buffer. */
+    1771                 :          1 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+    1772                 :          1 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+    1773                 :            :                           scratch_buffer_size - transport_header_size,
+    1774                 :            :                           spdm_response, spdm_response_size);
+    1775                 :          1 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+    1776                 :          1 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+    1777                 :            :                                               false, false, spdm_response_size,
+    1778                 :            :                                               spdm_response, response_size, response);
+    1779                 :            :         /* WALKAROUND: If just use single context to encode
+    1780                 :            :          * message and then decode message */
+    1781                 :            :         ((libspdm_secured_message_context_t
+    1782                 :          1 :           *)(session_info->secured_message_context))
+    1783                 :          1 :         ->application_secret.response_data_sequence_number--;
+    1784                 :            : 
+    1785                 :          1 :         sub_index++;
+    1786                 :            :     }
+    1787                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1788                 :            : 
+    1789                 :          2 :     case 0x11: {
+    1790                 :            :         static size_t sub_index = 0;
+    1791                 :            : 
+    1792                 :            :         uint32_t session_id;
+    1793                 :            :         libspdm_session_info_t    *session_info;
+    1794                 :            : 
+    1795                 :          2 :         session_id = 0xFFFFFFFF;
+    1796                 :          2 :         session_info = libspdm_get_session_info_via_session_id(
+    1797                 :            :             spdm_context, session_id);
+    1798         [ -  + ]:          2 :         if (session_info == NULL) {
+    1799                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+    1800                 :            :         }
+    1801                 :            : 
+    1802         [ +  + ]:          2 :         if (sub_index == 0) {
+    1803                 :            :             spdm_key_update_response_t *spdm_response;
+    1804                 :            :             size_t spdm_response_size;
+    1805                 :            :             size_t transport_header_size;
+    1806                 :            :             uint8_t *scratch_buffer;
+    1807                 :            :             size_t scratch_buffer_size;
+    1808                 :            : 
+    1809                 :          1 :             spdm_response_size = sizeof(spdm_key_update_response_t);
+    1810                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1811                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1812                 :            : 
+    1813                 :          1 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1814                 :          1 :             spdm_response->header.request_response_code =
+    1815                 :            :                 SPDM_KEY_UPDATE_ACK;
+    1816                 :          1 :             spdm_response->header.param1 =
+    1817                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY;
+    1818                 :          1 :             spdm_response->header.param2 = m_libspdm_last_token;
+    1819                 :            : 
+    1820                 :            :             /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    1821                 :            :              * transport_message is always in sender buffer. */
+    1822                 :          1 :             libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+    1823                 :            :                                         &scratch_buffer_size);
+    1824                 :          1 :             libspdm_copy_mem (scratch_buffer + transport_header_size,
+    1825                 :            :                               scratch_buffer_size - transport_header_size,
+    1826                 :            :                               spdm_response, spdm_response_size);
+    1827                 :          1 :             spdm_response = (void *)(scratch_buffer + transport_header_size);
+    1828                 :          1 :             libspdm_transport_test_encode_message(spdm_context,
+    1829                 :            :                                                   &session_id, false, false,
+    1830                 :            :                                                   spdm_response_size, spdm_response,
+    1831                 :            :                                                   response_size, response);
+    1832                 :            :             /* WALKAROUND: If just use single context to encode
+    1833                 :            :              * message and then decode message */
+    1834                 :            :             ((libspdm_secured_message_context_t
+    1835                 :          1 :               *)(session_info->secured_message_context))
+    1836                 :          1 :             ->application_secret.response_data_sequence_number--;
+    1837         [ +  - ]:          1 :         } else if (sub_index == 1) {
+    1838                 :            :             spdm_error_response_t *spdm_response;
+    1839                 :            :             size_t spdm_response_size;
+    1840                 :            :             size_t transport_header_size;
+    1841                 :            :             uint8_t *scratch_buffer;
+    1842                 :            :             size_t scratch_buffer_size;
+    1843                 :            : 
+    1844                 :          1 :             spdm_response_size = sizeof(spdm_error_response_t);
+    1845                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1846                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1847                 :            : 
+    1848                 :          1 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1849                 :          1 :             spdm_response->header.request_response_code = SPDM_ERROR;
+    1850                 :          1 :             spdm_response->header.param1 = SPDM_ERROR_CODE_INVALID_REQUEST;
+    1851                 :          1 :             spdm_response->header.param2 = 0;
+    1852                 :            : 
+    1853                 :            :             /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    1854                 :            :              * transport_message is always in sender buffer. */
+    1855                 :          1 :             libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+    1856                 :            :                                         &scratch_buffer_size);
+    1857                 :          1 :             libspdm_copy_mem (scratch_buffer + transport_header_size,
+    1858                 :            :                               scratch_buffer_size - transport_header_size,
+    1859                 :            :                               spdm_response, spdm_response_size);
+    1860                 :          1 :             spdm_response = (void *)(scratch_buffer + transport_header_size);
+    1861                 :          1 :             libspdm_transport_test_encode_message(spdm_context,
+    1862                 :            :                                                   &session_id, false, false,
+    1863                 :            :                                                   spdm_response_size, spdm_response,
+    1864                 :            :                                                   response_size, response);
+    1865                 :            :             /* WALKAROUND: If just use single context to encode
+    1866                 :            :              * message and then decode message */
+    1867                 :            :             ((libspdm_secured_message_context_t
+    1868                 :          1 :               *)(session_info->secured_message_context))
+    1869                 :          1 :             ->application_secret.response_data_sequence_number--;
+    1870                 :            :         }
+    1871                 :            : 
+    1872                 :          2 :         sub_index++;
+    1873                 :            :     }
+    1874                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+    1875                 :            : 
+    1876                 :          5 :     case 0x12: {
+    1877                 :            :         static size_t sub_index = 0;
+    1878                 :            : 
+    1879                 :            :         uint32_t session_id;
+    1880                 :            :         libspdm_session_info_t    *session_info;
+    1881                 :            : 
+    1882                 :          5 :         session_id = 0xFFFFFFFF;
+    1883                 :          5 :         session_info = libspdm_get_session_info_via_session_id(
+    1884                 :            :             spdm_context, session_id);
+    1885         [ -  + ]:          5 :         if (session_info == NULL) {
+    1886                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+    1887                 :            :         }
+    1888                 :            : 
+    1889         [ +  + ]:          5 :         if (sub_index == 0) {
+    1890                 :            :             spdm_key_update_response_t *spdm_response;
+    1891                 :            :             size_t spdm_response_size;
+    1892                 :            :             size_t transport_header_size;
+    1893                 :            :             uint8_t *scratch_buffer;
+    1894                 :            :             size_t scratch_buffer_size;
+    1895                 :            : 
+    1896                 :          1 :             spdm_response_size = sizeof(spdm_key_update_response_t);
+    1897                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1898                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1899                 :            : 
+    1900                 :          1 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1901                 :          1 :             spdm_response->header.request_response_code =
+    1902                 :            :                 SPDM_KEY_UPDATE_ACK;
+    1903                 :          1 :             spdm_response->header.param1 =
+    1904                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY;
+    1905                 :          1 :             spdm_response->header.param2 = m_libspdm_last_token;
+    1906                 :            : 
+    1907                 :            :             /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    1908                 :            :              * transport_message is always in sender buffer. */
+    1909                 :          1 :             libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+    1910                 :            :                                         &scratch_buffer_size);
+    1911                 :          1 :             libspdm_copy_mem (scratch_buffer + transport_header_size,
+    1912                 :            :                               scratch_buffer_size - transport_header_size,
+    1913                 :            :                               spdm_response, spdm_response_size);
+    1914                 :          1 :             spdm_response = (void *)(scratch_buffer + transport_header_size);
+    1915                 :          1 :             libspdm_transport_test_encode_message(spdm_context,
+    1916                 :            :                                                   &session_id, false, false,
+    1917                 :            :                                                   spdm_response_size, spdm_response,
+    1918                 :            :                                                   response_size, response);
+    1919                 :            :             /* WALKAROUND: If just use single context to encode
+    1920                 :            :              * message and then decode message */
+    1921                 :            :             ((libspdm_secured_message_context_t
+    1922                 :          1 :               *)(session_info->secured_message_context))
+    1923                 :          1 :             ->application_secret.response_data_sequence_number--;
+    1924                 :            :         } else {
+    1925                 :            :             spdm_error_response_t *spdm_response;
+    1926                 :            :             size_t spdm_response_size;
+    1927                 :            :             size_t transport_header_size;
+    1928                 :            :             uint8_t *scratch_buffer;
+    1929                 :            :             size_t scratch_buffer_size;
+    1930                 :            : 
+    1931                 :          4 :             spdm_response_size = sizeof(spdm_error_response_t);
+    1932                 :          4 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1933                 :          4 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1934                 :            : 
+    1935                 :          4 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1936                 :          4 :             spdm_response->header.request_response_code = SPDM_ERROR;
+    1937                 :          4 :             spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
+    1938                 :          4 :             spdm_response->header.param2 = 0;
+    1939                 :            : 
+    1940                 :            :             /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    1941                 :            :              * transport_message is always in sender buffer. */
+    1942                 :          4 :             libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+    1943                 :            :                                         &scratch_buffer_size);
+    1944                 :          4 :             libspdm_copy_mem (scratch_buffer + transport_header_size,
+    1945                 :            :                               scratch_buffer_size - transport_header_size,
+    1946                 :            :                               spdm_response, spdm_response_size);
+    1947                 :          4 :             spdm_response = (void *)(scratch_buffer + transport_header_size);
+    1948                 :          4 :             libspdm_transport_test_encode_message(spdm_context,
+    1949                 :            :                                                   &session_id, false, false,
+    1950                 :            :                                                   spdm_response_size, spdm_response,
+    1951                 :            :                                                   response_size, response);
+    1952                 :            :             /* WALKAROUND: If just use single context to encode
+    1953                 :            :              * message and then decode message */
+    1954                 :            :             ((libspdm_secured_message_context_t
+    1955                 :          4 :               *)(session_info->secured_message_context))
+    1956                 :          4 :             ->application_secret.response_data_sequence_number--;
+    1957                 :            :         }
+    1958                 :            : 
+    1959                 :          5 :         sub_index++;
+    1960                 :            :     }
+    1961                 :          5 :         return LIBSPDM_STATUS_SUCCESS;
+    1962                 :            : 
+    1963                 :          3 :     case 0x13: {
+    1964                 :            :         static size_t sub_index = 0;
+    1965                 :            : 
+    1966                 :            :         uint32_t session_id;
+    1967                 :            :         libspdm_session_info_t    *session_info;
+    1968                 :            : 
+    1969                 :          3 :         session_id = 0xFFFFFFFF;
+    1970                 :          3 :         session_info = libspdm_get_session_info_via_session_id(
+    1971                 :            :             spdm_context, session_id);
+    1972         [ -  + ]:          3 :         if (session_info == NULL) {
+    1973                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+    1974                 :            :         }
+    1975                 :            : 
+    1976         [ +  + ]:          3 :         if (sub_index == 0) {
+    1977                 :            :             spdm_key_update_response_t *spdm_response;
+    1978                 :            :             size_t spdm_response_size;
+    1979                 :            :             size_t transport_header_size;
+    1980                 :            :             uint8_t *scratch_buffer;
+    1981                 :            :             size_t scratch_buffer_size;
+    1982                 :            : 
+    1983                 :          1 :             spdm_response_size = sizeof(spdm_key_update_response_t);
+    1984                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1985                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1986                 :            : 
+    1987                 :          1 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1988                 :          1 :             spdm_response->header.request_response_code =
+    1989                 :            :                 SPDM_KEY_UPDATE_ACK;
+    1990                 :          1 :             spdm_response->header.param1 =
+    1991                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY;
+    1992                 :          1 :             spdm_response->header.param2 = m_libspdm_last_token;
+    1993                 :            : 
+    1994                 :            :             /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    1995                 :            :              * transport_message is always in sender buffer. */
+    1996                 :          1 :             libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+    1997                 :            :                                         &scratch_buffer_size);
+    1998                 :          1 :             libspdm_copy_mem (scratch_buffer + transport_header_size,
+    1999                 :            :                               scratch_buffer_size - transport_header_size,
+    2000                 :            :                               spdm_response, spdm_response_size);
+    2001                 :          1 :             spdm_response = (void *)(scratch_buffer + transport_header_size);
+    2002                 :          1 :             libspdm_transport_test_encode_message(spdm_context,
+    2003                 :            :                                                   &session_id, false, false,
+    2004                 :            :                                                   spdm_response_size, spdm_response,
+    2005                 :            :                                                   response_size, response);
+    2006                 :            :             /* WALKAROUND: If just use single context to encode
+    2007                 :            :              * message and then decode message */
+    2008                 :            :             ((libspdm_secured_message_context_t
+    2009                 :          1 :               *)(session_info->secured_message_context))
+    2010                 :          1 :             ->application_secret.response_data_sequence_number--;
+    2011         [ +  + ]:          2 :         } else if (sub_index == 1) {
+    2012                 :            :             spdm_error_response_t *spdm_response;
+    2013                 :            :             size_t spdm_response_size;
+    2014                 :            :             size_t transport_header_size;
+    2015                 :            :             uint8_t *scratch_buffer;
+    2016                 :            :             size_t scratch_buffer_size;
+    2017                 :            : 
+    2018                 :          1 :             spdm_response_size = sizeof(spdm_error_response_t);
+    2019                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2020                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2021                 :            : 
+    2022                 :          1 :             spdm_response->header.spdm_version =
+    2023                 :            :                 SPDM_MESSAGE_VERSION_11;
+    2024                 :          1 :             spdm_response->header.request_response_code = SPDM_ERROR;
+    2025                 :          1 :             spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
+    2026                 :          1 :             spdm_response->header.param2 = 0;
+    2027                 :            : 
+    2028                 :            :             /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    2029                 :            :              * transport_message is always in sender buffer. */
+    2030                 :          1 :             libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+    2031                 :            :                                         &scratch_buffer_size);
+    2032                 :          1 :             libspdm_copy_mem (scratch_buffer + transport_header_size,
+    2033                 :            :                               scratch_buffer_size - transport_header_size,
+    2034                 :            :                               spdm_response, spdm_response_size);
+    2035                 :          1 :             spdm_response = (void *)(scratch_buffer + transport_header_size);
+    2036                 :          1 :             libspdm_transport_test_encode_message(spdm_context,
+    2037                 :            :                                                   &session_id, false, false,
+    2038                 :            :                                                   spdm_response_size, spdm_response,
+    2039                 :            :                                                   response_size, response);
+    2040                 :            :             /* WALKAROUND: If just use single context to encode
+    2041                 :            :              * message and then decode message */
+    2042                 :            :             ((libspdm_secured_message_context_t
+    2043                 :          1 :               *)(session_info->secured_message_context))
+    2044                 :          1 :             ->application_secret.response_data_sequence_number--;
+    2045         [ +  - ]:          1 :         } else if (sub_index == 2) {
+    2046                 :            :             spdm_key_update_response_t *spdm_response;
+    2047                 :            :             size_t spdm_response_size;
+    2048                 :            :             size_t transport_header_size;
+    2049                 :            :             uint8_t *scratch_buffer;
+    2050                 :            :             size_t scratch_buffer_size;
+    2051                 :            : 
+    2052                 :          1 :             spdm_response_size = sizeof(spdm_key_update_response_t);
+    2053                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2054                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2055                 :            : 
+    2056                 :          1 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2057                 :          1 :             spdm_response->header.request_response_code =
+    2058                 :            :                 SPDM_KEY_UPDATE_ACK;
+    2059                 :          1 :             spdm_response->header.param1 =
+    2060                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_VERIFY_NEW_KEY;
+    2061                 :          1 :             spdm_response->header.param2 = m_libspdm_last_token;
+    2062                 :            : 
+    2063                 :            :             /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    2064                 :            :              * transport_message is always in sender buffer. */
+    2065                 :          1 :             libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+    2066                 :            :                                         &scratch_buffer_size);
+    2067                 :          1 :             libspdm_copy_mem (scratch_buffer + transport_header_size,
+    2068                 :            :                               scratch_buffer_size - transport_header_size,
+    2069                 :            :                               spdm_response, spdm_response_size);
+    2070                 :          1 :             spdm_response = (void *)(scratch_buffer + transport_header_size);
+    2071                 :          1 :             libspdm_transport_test_encode_message(spdm_context,
+    2072                 :            :                                                   &session_id, false, false,
+    2073                 :            :                                                   spdm_response_size, spdm_response,
+    2074                 :            :                                                   response_size, response);
+    2075                 :            :             /* WALKAROUND: If just use single context to encode
+    2076                 :            :              * message and then decode message */
+    2077                 :            :             ((libspdm_secured_message_context_t
+    2078                 :          1 :               *)(session_info->secured_message_context))
+    2079                 :          1 :             ->application_secret.response_data_sequence_number--;
+    2080                 :            :         }
+    2081                 :            : 
+    2082                 :          3 :         sub_index++;
+    2083                 :            :     }
+    2084                 :          3 :         return LIBSPDM_STATUS_SUCCESS;
+    2085                 :            : 
+    2086                 :          2 :     case 0x14: {
+    2087                 :            :         static size_t sub_index = 0;
+    2088                 :            : 
+    2089                 :            :         uint32_t session_id;
+    2090                 :            :         libspdm_session_info_t    *session_info;
+    2091                 :            : 
+    2092                 :          2 :         session_id = 0xFFFFFFFF;
+    2093                 :          2 :         session_info = libspdm_get_session_info_via_session_id(
+    2094                 :            :             spdm_context, session_id);
+    2095         [ -  + ]:          2 :         if (session_info == NULL) {
+    2096                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+    2097                 :            :         }
+    2098                 :            : 
+    2099         [ +  + ]:          2 :         if (sub_index == 0) {
+    2100                 :            :             spdm_key_update_response_t *spdm_response;
+    2101                 :            :             size_t spdm_response_size;
+    2102                 :            :             size_t transport_header_size;
+    2103                 :            :             uint8_t *scratch_buffer;
+    2104                 :            :             size_t scratch_buffer_size;
+    2105                 :            : 
+    2106                 :          1 :             spdm_response_size = sizeof(spdm_key_update_response_t);
+    2107                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2108                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2109                 :            : 
+    2110                 :          1 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2111                 :          1 :             spdm_response->header.request_response_code =
+    2112                 :            :                 SPDM_KEY_UPDATE_ACK;
+    2113                 :          1 :             spdm_response->header.param1 =
+    2114                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY;
+    2115                 :          1 :             spdm_response->header.param2 = m_libspdm_last_token;
+    2116                 :            : 
+    2117                 :            :             /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    2118                 :            :              * transport_message is always in sender buffer. */
+    2119                 :          1 :             libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+    2120                 :            :                                         &scratch_buffer_size);
+    2121                 :          1 :             libspdm_copy_mem (scratch_buffer + transport_header_size,
+    2122                 :            :                               scratch_buffer_size - transport_header_size,
+    2123                 :            :                               spdm_response, spdm_response_size);
+    2124                 :          1 :             spdm_response = (void *)(scratch_buffer + transport_header_size);
+    2125                 :          1 :             libspdm_transport_test_encode_message(spdm_context,
+    2126                 :            :                                                   &session_id, false, false,
+    2127                 :            :                                                   spdm_response_size, spdm_response,
+    2128                 :            :                                                   response_size, response);
+    2129                 :            :             /* WALKAROUND: If just use single context to encode
+    2130                 :            :              * message and then decode message */
+    2131                 :            :             ((libspdm_secured_message_context_t
+    2132                 :          1 :               *)(session_info->secured_message_context))
+    2133                 :          1 :             ->application_secret.response_data_sequence_number--;
+    2134         [ +  - ]:          1 :         } else if (sub_index == 1) {
+    2135                 :            :             spdm_error_response_t *spdm_response;
+    2136                 :            :             size_t spdm_response_size;
+    2137                 :            :             size_t transport_header_size;
+    2138                 :            :             uint8_t *scratch_buffer;
+    2139                 :            :             size_t scratch_buffer_size;
+    2140                 :            : 
+    2141                 :          1 :             spdm_response_size = sizeof(spdm_error_response_t);
+    2142                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2143                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2144                 :            : 
+    2145                 :          1 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2146                 :          1 :             spdm_response->header.request_response_code = SPDM_ERROR;
+    2147                 :          1 :             spdm_response->header.param1 = SPDM_ERROR_CODE_REQUEST_RESYNCH;
+    2148                 :          1 :             spdm_response->header.param2 = 0;
+    2149                 :            : 
+    2150                 :            :             /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    2151                 :            :              * transport_message is always in sender buffer. */
+    2152                 :          1 :             libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+    2153                 :            :                                         &scratch_buffer_size);
+    2154                 :          1 :             libspdm_copy_mem (scratch_buffer + transport_header_size,
+    2155                 :            :                               scratch_buffer_size - transport_header_size,
+    2156                 :            :                               spdm_response, spdm_response_size);
+    2157                 :          1 :             spdm_response = (void *)(scratch_buffer + transport_header_size);
+    2158                 :          1 :             libspdm_transport_test_encode_message(spdm_context,
+    2159                 :            :                                                   &session_id, false, false,
+    2160                 :            :                                                   spdm_response_size, spdm_response,
+    2161                 :            :                                                   response_size, response);
+    2162                 :            :             /* WALKAROUND: If just use single context to encode
+    2163                 :            :              * message and then decode message */
+    2164                 :            :             ((libspdm_secured_message_context_t
+    2165                 :          1 :               *)(session_info->secured_message_context))
+    2166                 :          1 :             ->application_secret.response_data_sequence_number--;
+    2167                 :            :         }
+    2168                 :            : 
+    2169                 :          2 :         sub_index++;
+    2170                 :            :     }
+    2171                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+    2172                 :            : 
+    2173                 :          3 :     case 0x15: {
+    2174                 :            :         static size_t sub_index = 0;
+    2175                 :            : 
+    2176                 :            :         uint32_t session_id;
+    2177                 :            :         libspdm_session_info_t    *session_info;
+    2178                 :            : 
+    2179                 :          3 :         session_id = 0xFFFFFFFF;
+    2180                 :          3 :         session_info = libspdm_get_session_info_via_session_id(
+    2181                 :            :             spdm_context, session_id);
+    2182         [ -  + ]:          3 :         if (session_info == NULL) {
+    2183                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+    2184                 :            :         }
+    2185                 :            : 
+    2186         [ +  + ]:          3 :         if (sub_index == 0) {
+    2187                 :            :             spdm_key_update_response_t *spdm_response;
+    2188                 :            :             size_t spdm_response_size;
+    2189                 :            :             size_t transport_header_size;
+    2190                 :            :             uint8_t *scratch_buffer;
+    2191                 :            :             size_t scratch_buffer_size;
+    2192                 :            : 
+    2193                 :          1 :             spdm_response_size = sizeof(spdm_key_update_response_t);
+    2194                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2195                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2196                 :            : 
+    2197                 :          1 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2198                 :          1 :             spdm_response->header.request_response_code =
+    2199                 :            :                 SPDM_KEY_UPDATE_ACK;
+    2200                 :          1 :             spdm_response->header.param1 =
+    2201                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY;
+    2202                 :          1 :             spdm_response->header.param2 = m_libspdm_last_token;
+    2203                 :            : 
+    2204                 :            :             /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    2205                 :            :              * transport_message is always in sender buffer. */
+    2206                 :          1 :             libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+    2207                 :            :                                         &scratch_buffer_size);
+    2208                 :          1 :             libspdm_copy_mem (scratch_buffer + transport_header_size,
+    2209                 :            :                               scratch_buffer_size - transport_header_size,
+    2210                 :            :                               spdm_response, spdm_response_size);
+    2211                 :          1 :             spdm_response = (void *)(scratch_buffer + transport_header_size);
+    2212                 :          1 :             libspdm_transport_test_encode_message(spdm_context,
+    2213                 :            :                                                   &session_id, false, false,
+    2214                 :            :                                                   spdm_response_size, spdm_response,
+    2215                 :            :                                                   response_size, response);
+    2216                 :            :             /* WALKAROUND: If just use single context to encode
+    2217                 :            :              * message and then decode message */
+    2218                 :            :             ((libspdm_secured_message_context_t
+    2219                 :          1 :               *)(session_info->secured_message_context))
+    2220                 :          1 :             ->application_secret.response_data_sequence_number--;
+    2221                 :            :         } else {
+    2222                 :            :             spdm_error_response_data_response_not_ready_t *spdm_response;
+    2223                 :            :             size_t spdm_response_size;
+    2224                 :            :             size_t transport_header_size;
+    2225                 :            :             uint8_t *scratch_buffer;
+    2226                 :            :             size_t scratch_buffer_size;
+    2227                 :            : 
+    2228                 :          2 :             spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
+    2229                 :          2 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2230                 :          2 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2231                 :            : 
+    2232                 :          2 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2233                 :          2 :             spdm_response->header.request_response_code = SPDM_ERROR;
+    2234                 :          2 :             spdm_response->header.param1 =
+    2235                 :            :                 SPDM_ERROR_CODE_RESPONSE_NOT_READY;
+    2236                 :          2 :             spdm_response->header.param2 = 0;
+    2237                 :          2 :             spdm_response->extend_error_data.rd_exponent = 1;
+    2238                 :          2 :             spdm_response->extend_error_data.rd_tm = 2;
+    2239                 :          2 :             spdm_response->extend_error_data.request_code = SPDM_KEY_UPDATE;
+    2240                 :          2 :             spdm_response->extend_error_data.token = 0;
+    2241                 :            : 
+    2242                 :            :             /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    2243                 :            :              * transport_message is always in sender buffer. */
+    2244                 :          2 :             libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+    2245                 :            :                                         &scratch_buffer_size);
+    2246                 :          2 :             libspdm_copy_mem (scratch_buffer + transport_header_size,
+    2247                 :            :                               scratch_buffer_size - transport_header_size,
+    2248                 :            :                               spdm_response, spdm_response_size);
+    2249                 :          2 :             spdm_response = (void *)(scratch_buffer + transport_header_size);
+    2250                 :          2 :             libspdm_transport_test_encode_message(spdm_context,
+    2251                 :            :                                                   &session_id, false, false,
+    2252                 :            :                                                   spdm_response_size, spdm_response,
+    2253                 :            :                                                   response_size, response);
+    2254                 :            :             /* WALKAROUND: If just use single context to encode
+    2255                 :            :              * message and then decode message */
+    2256                 :            :             ((libspdm_secured_message_context_t
+    2257                 :          2 :               *)(session_info->secured_message_context))
+    2258                 :          2 :             ->application_secret.response_data_sequence_number--;
+    2259                 :            :         }
+    2260                 :            : 
+    2261                 :          3 :         sub_index++;
+    2262                 :            :     }
+    2263                 :          3 :         return LIBSPDM_STATUS_SUCCESS;
+    2264                 :            : 
+    2265                 :          3 :     case 0x16: {
+    2266                 :            :         static size_t sub_index = 0;
+    2267                 :            : 
+    2268                 :            :         uint32_t session_id;
+    2269                 :            :         libspdm_session_info_t    *session_info;
+    2270                 :            : 
+    2271                 :          3 :         session_id = 0xFFFFFFFF;
+    2272                 :          3 :         session_info = libspdm_get_session_info_via_session_id(
+    2273                 :            :             spdm_context, session_id);
+    2274         [ -  + ]:          3 :         if (session_info == NULL) {
+    2275                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+    2276                 :            :         }
+    2277                 :            : 
+    2278         [ +  + ]:          3 :         if (sub_index == 0) {
+    2279                 :            :             spdm_key_update_response_t *spdm_response;
+    2280                 :            :             size_t spdm_response_size;
+    2281                 :            :             size_t transport_header_size;
+    2282                 :            :             uint8_t *scratch_buffer;
+    2283                 :            :             size_t scratch_buffer_size;
+    2284                 :            : 
+    2285                 :          1 :             spdm_response_size = sizeof(spdm_key_update_response_t);
+    2286                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2287                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2288                 :            : 
+    2289                 :          1 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2290                 :          1 :             spdm_response->header.request_response_code =
+    2291                 :            :                 SPDM_KEY_UPDATE_ACK;
+    2292                 :          1 :             spdm_response->header.param1 =
+    2293                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY;
+    2294                 :          1 :             spdm_response->header.param2 = m_libspdm_last_token;
+    2295                 :            : 
+    2296                 :            :             /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    2297                 :            :              * transport_message is always in sender buffer. */
+    2298                 :          1 :             libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+    2299                 :            :                                         &scratch_buffer_size);
+    2300                 :          1 :             libspdm_copy_mem (scratch_buffer + transport_header_size,
+    2301                 :            :                               scratch_buffer_size - transport_header_size,
+    2302                 :            :                               spdm_response, spdm_response_size);
+    2303                 :          1 :             spdm_response = (void *)(scratch_buffer + transport_header_size);
+    2304                 :          1 :             libspdm_transport_test_encode_message(spdm_context,
+    2305                 :            :                                                   &session_id, false, false,
+    2306                 :            :                                                   spdm_response_size, spdm_response,
+    2307                 :            :                                                   response_size, response);
+    2308                 :            :             /* WALKAROUND: If just use single context to encode
+    2309                 :            :              * message and then decode message */
+    2310                 :            :             ((libspdm_secured_message_context_t
+    2311                 :          1 :               *)(session_info->secured_message_context))
+    2312                 :          1 :             ->application_secret.response_data_sequence_number--;
+    2313         [ +  + ]:          2 :         } else if (sub_index == 1) {
+    2314                 :            :             spdm_error_response_data_response_not_ready_t *spdm_response;
+    2315                 :            :             size_t spdm_response_size;
+    2316                 :            :             size_t transport_header_size;
+    2317                 :            :             uint8_t *scratch_buffer;
+    2318                 :            :             size_t scratch_buffer_size;
+    2319                 :            : 
+    2320                 :          1 :             spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
+    2321                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2322                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2323                 :            : 
+    2324                 :          1 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2325                 :          1 :             spdm_response->header.request_response_code = SPDM_ERROR;
+    2326                 :          1 :             spdm_response->header.param1 =
+    2327                 :            :                 SPDM_ERROR_CODE_RESPONSE_NOT_READY;
+    2328                 :          1 :             spdm_response->header.param2 = 0;
+    2329                 :          1 :             spdm_response->extend_error_data.rd_exponent = 1;
+    2330                 :          1 :             spdm_response->extend_error_data.rd_tm = 2;
+    2331                 :          1 :             spdm_response->extend_error_data.request_code = SPDM_KEY_UPDATE;
+    2332                 :          1 :             spdm_response->extend_error_data.token = 0;
+    2333                 :            : 
+    2334                 :            :             /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    2335                 :            :              * transport_message is always in sender buffer. */
+    2336                 :          1 :             libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+    2337                 :            :                                         &scratch_buffer_size);
+    2338                 :          1 :             libspdm_copy_mem (scratch_buffer + transport_header_size,
+    2339                 :            :                               scratch_buffer_size - transport_header_size,
+    2340                 :            :                               spdm_response, spdm_response_size);
+    2341                 :          1 :             spdm_response = (void *)(scratch_buffer + transport_header_size);
+    2342                 :          1 :             libspdm_transport_test_encode_message(spdm_context,
+    2343                 :            :                                                   &session_id, false, false,
+    2344                 :            :                                                   spdm_response_size, spdm_response,
+    2345                 :            :                                                   response_size, response);
+    2346                 :            :             /* WALKAROUND: If just use single context to encode
+    2347                 :            :              * message and then decode message */
+    2348                 :            :             ((libspdm_secured_message_context_t
+    2349                 :          1 :               *)(session_info->secured_message_context))
+    2350                 :          1 :             ->application_secret.response_data_sequence_number--;
+    2351         [ +  - ]:          1 :         } else if (sub_index == 2) {
+    2352                 :            :             spdm_key_update_response_t *spdm_response;
+    2353                 :            :             size_t spdm_response_size;
+    2354                 :            :             size_t transport_header_size;
+    2355                 :            :             uint8_t *scratch_buffer;
+    2356                 :            :             size_t scratch_buffer_size;
+    2357                 :            : 
+    2358                 :          1 :             spdm_response_size = sizeof(spdm_key_update_response_t);
+    2359                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2360                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2361                 :            : 
+    2362                 :          1 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2363                 :          1 :             spdm_response->header.request_response_code =
+    2364                 :            :                 SPDM_KEY_UPDATE_ACK;
+    2365                 :          1 :             spdm_response->header.param1 =
+    2366                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_VERIFY_NEW_KEY;
+    2367                 :          1 :             spdm_response->header.param2 = m_libspdm_last_token;
+    2368                 :            : 
+    2369                 :            :             /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    2370                 :            :              * transport_message is always in sender buffer. */
+    2371                 :          1 :             libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+    2372                 :            :                                         &scratch_buffer_size);
+    2373                 :          1 :             libspdm_copy_mem (scratch_buffer + transport_header_size,
+    2374                 :            :                               scratch_buffer_size - transport_header_size,
+    2375                 :            :                               spdm_response, spdm_response_size);
+    2376                 :          1 :             spdm_response = (void *)(scratch_buffer + transport_header_size);
+    2377                 :          1 :             libspdm_transport_test_encode_message(spdm_context,
+    2378                 :            :                                                   &session_id, false, false,
+    2379                 :            :                                                   spdm_response_size, spdm_response,
+    2380                 :            :                                                   response_size, response);
+    2381                 :            :             /* WALKAROUND: If just use single context to encode
+    2382                 :            :              * message and then decode message */
+    2383                 :            :             ((libspdm_secured_message_context_t
+    2384                 :          1 :               *)(session_info->secured_message_context))
+    2385                 :          1 :             ->application_secret.response_data_sequence_number--;
+    2386                 :            :         }
+    2387                 :            : 
+    2388                 :          3 :         sub_index++;
+    2389                 :            :     }
+    2390                 :          3 :         return LIBSPDM_STATUS_SUCCESS;
+    2391                 :            : 
+    2392                 :         34 :     case 0x17: {
+    2393                 :            :         static size_t sub_index = 0;
+    2394                 :            :         static uint16_t error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
+    2395                 :            : 
+    2396                 :            :         uint32_t session_id;
+    2397                 :            :         libspdm_session_info_t    *session_info;
+    2398                 :            : 
+    2399                 :         34 :         session_id = 0xFFFFFFFF;
+    2400                 :         34 :         session_info = libspdm_get_session_info_via_session_id(
+    2401                 :            :             spdm_context, session_id);
+    2402         [ -  + ]:         34 :         if (session_info == NULL) {
+    2403                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+    2404                 :            :         }
+    2405                 :            : 
+    2406         [ +  - ]:         34 :         if(error_code <= 0xff) {
+    2407                 :            :             /* skip SPDM_ERROR_CODE_DECRYPT_ERROR, because this case will free context*/
+    2408         [ +  + ]:         34 :             if(error_code == SPDM_ERROR_CODE_DECRYPT_ERROR) {
+    2409                 :          1 :                 error_code++;
+    2410                 :            :             }
+    2411         [ +  + ]:         34 :             if (sub_index%2 == 0) {
+    2412                 :            :                 spdm_key_update_response_t *spdm_response;
+    2413                 :            :                 size_t spdm_response_size;
+    2414                 :            :                 size_t transport_header_size;
+    2415                 :            :                 uint8_t *scratch_buffer;
+    2416                 :            :                 size_t scratch_buffer_size;
+    2417                 :            : 
+    2418                 :         17 :                 spdm_response_size = sizeof(spdm_key_update_response_t);
+    2419                 :         17 :                 transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2420                 :         17 :                 spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2421                 :            : 
+    2422                 :         17 :                 spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2423                 :         17 :                 spdm_response->header.request_response_code =
+    2424                 :            :                     SPDM_KEY_UPDATE_ACK;
+    2425                 :         17 :                 spdm_response->header.param1 =
+    2426                 :            :                     SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY;
+    2427                 :         17 :                 spdm_response->header.param2 = m_libspdm_last_token;
+    2428                 :            : 
+    2429                 :            :                 /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    2430                 :            :                  * transport_message is always in sender buffer. */
+    2431                 :         17 :                 libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+    2432                 :            :                                             &scratch_buffer_size);
+    2433                 :         17 :                 libspdm_copy_mem (scratch_buffer + transport_header_size,
+    2434                 :            :                                   scratch_buffer_size - transport_header_size,
+    2435                 :            :                                   spdm_response, spdm_response_size);
+    2436                 :         17 :                 spdm_response = (void *)(scratch_buffer + transport_header_size);
+    2437                 :         17 :                 libspdm_transport_test_encode_message(spdm_context,
+    2438                 :            :                                                       &session_id, false, false,
+    2439                 :            :                                                       spdm_response_size, spdm_response,
+    2440                 :            :                                                       response_size, response);
+    2441                 :            :                 /* WALKAROUND: If just use single context to encode
+    2442                 :            :                  * message and then decode message */
+    2443                 :            :                 ((libspdm_secured_message_context_t
+    2444                 :         17 :                   *)(session_info->secured_message_context))
+    2445                 :         17 :                 ->application_secret.response_data_sequence_number--;
+    2446                 :            :             } else {
+    2447                 :            :                 spdm_error_response_t *spdm_response;
+    2448                 :            :                 size_t spdm_response_size;
+    2449                 :            :                 size_t transport_header_size;
+    2450                 :            :                 uint8_t *scratch_buffer;
+    2451                 :            :                 size_t scratch_buffer_size;
+    2452                 :            : 
+    2453                 :         17 :                 spdm_response_size = sizeof(spdm_error_response_t);
+    2454                 :         17 :                 transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2455                 :         17 :                 spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2456                 :            : 
+    2457                 :         17 :                 libspdm_zero_mem (spdm_response, spdm_response_size);
+    2458                 :         17 :                 spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2459                 :         17 :                 spdm_response->header.request_response_code = SPDM_ERROR;
+    2460                 :         17 :                 spdm_response->header.param1 = (uint8_t) error_code;
+    2461                 :         17 :                 spdm_response->header.param2 = 0;
+    2462                 :            : 
+    2463                 :            :                 /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    2464                 :            :                  * transport_message is always in sender buffer. */
+    2465                 :         17 :                 libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+    2466                 :            :                                             &scratch_buffer_size);
+    2467                 :         17 :                 libspdm_copy_mem (scratch_buffer + transport_header_size,
+    2468                 :            :                                   scratch_buffer_size - transport_header_size,
+    2469                 :            :                                   spdm_response, spdm_response_size);
+    2470                 :         17 :                 spdm_response = (void *)(scratch_buffer + transport_header_size);
+    2471                 :         17 :                 libspdm_transport_test_encode_message(spdm_context,
+    2472                 :            :                                                       &session_id, false, false,
+    2473                 :            :                                                       spdm_response_size, spdm_response,
+    2474                 :            :                                                       response_size, response);
+    2475                 :            :                 /* WALKAROUND: If just use single context to encode
+    2476                 :            :                  * message and then decode message */
+    2477                 :            :                 ((libspdm_secured_message_context_t
+    2478                 :         17 :                   *)(session_info->secured_message_context))
+    2479                 :         17 :                 ->application_secret.response_data_sequence_number--;
+    2480                 :            : 
+    2481                 :         17 :                 error_code++;
+    2482                 :            :                 /*busy is treated in cases 5 and 6*/
+    2483         [ +  + ]:         17 :                 if(error_code == SPDM_ERROR_CODE_BUSY) {
+    2484                 :          1 :                     error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
+    2485                 :            :                 }
+    2486                 :            :                 /*skip some reserved error codes (0d to 3e)*/
+    2487         [ +  + ]:         17 :                 if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) {
+    2488                 :          1 :                     error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
+    2489                 :            :                 }
+    2490                 :            :                 /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
+    2491         [ +  + ]:         17 :                 if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) {
+    2492                 :          1 :                     error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
+    2493                 :            :                 }
+    2494                 :            :             }
+    2495                 :            :         }
+    2496                 :            : 
+    2497                 :         34 :         sub_index++;
+    2498                 :            :     }
+    2499                 :         34 :         return LIBSPDM_STATUS_SUCCESS;
+    2500                 :            : 
+    2501                 :          2 :     case 0x18: {
+    2502                 :            :         static size_t sub_index = 0;
+    2503                 :            : 
+    2504                 :            :         spdm_key_update_response_t *spdm_response;
+    2505                 :            :         size_t spdm_response_size;
+    2506                 :            :         size_t transport_header_size;
+    2507                 :            :         uint32_t session_id;
+    2508                 :            :         libspdm_session_info_t        *session_info;
+    2509                 :            :         uint8_t *scratch_buffer;
+    2510                 :            :         size_t scratch_buffer_size;
+    2511                 :            : 
+    2512                 :          2 :         spdm_response_size = sizeof(spdm_key_update_response_t);
+    2513                 :          2 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2514                 :          2 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2515                 :            : 
+    2516                 :          2 :         session_id = 0xFFFFFFFF;
+    2517                 :            : 
+    2518                 :          2 :         session_info = libspdm_get_session_info_via_session_id(
+    2519                 :            :             spdm_context, session_id);
+    2520         [ -  + ]:          2 :         if (session_info == NULL) {
+    2521                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+    2522                 :            :         }
+    2523                 :            : 
+    2524                 :          2 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2525                 :          2 :         spdm_response->header.request_response_code =
+    2526                 :            :             SPDM_KEY_UPDATE_ACK;
+    2527         [ +  + ]:          2 :         if (sub_index == 0) {
+    2528                 :          1 :             spdm_response->header.request_response_code =
+    2529                 :            :                 SPDM_KEY_UPDATE_ACK;
+    2530                 :          1 :             spdm_response->header.param1 =
+    2531                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY;
+    2532                 :          1 :             spdm_response->header.param2 = m_libspdm_last_token;
+    2533         [ +  - ]:          1 :         } else if (sub_index == 1) {
+    2534                 :            :             /*wrong response code*/
+    2535                 :          1 :             spdm_response->header.request_response_code =
+    2536                 :            :                 SPDM_KEY_UPDATE;
+    2537                 :          1 :             spdm_response->header.param1 =
+    2538                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_VERIFY_NEW_KEY;
+    2539                 :          1 :             spdm_response->header.param2 = m_libspdm_last_token;
+    2540                 :            :         }
+    2541                 :            : 
+    2542                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    2543                 :            :          * transport_message is always in sender buffer. */
+    2544                 :          2 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+    2545                 :          2 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+    2546                 :            :                           scratch_buffer_size - transport_header_size,
+    2547                 :            :                           spdm_response, spdm_response_size);
+    2548                 :          2 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+    2549                 :          2 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+    2550                 :            :                                               false, false, spdm_response_size,
+    2551                 :            :                                               spdm_response, response_size, response);
+    2552                 :            :         /* WALKAROUND: If just use single context to encode
+    2553                 :            :          * message and then decode message */
+    2554                 :            :         ((libspdm_secured_message_context_t
+    2555                 :          2 :           *)(session_info->secured_message_context))
+    2556                 :          2 :         ->application_secret.response_data_sequence_number--;
+    2557                 :            : 
+    2558                 :          2 :         sub_index++;
+    2559                 :            :     }
+    2560                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+    2561                 :            : 
+    2562                 :          2 :     case 0x19: {
+    2563                 :            :         static size_t sub_index = 0;
+    2564                 :            : 
+    2565                 :            :         spdm_key_update_response_t *spdm_response;
+    2566                 :            :         size_t spdm_response_size;
+    2567                 :            :         size_t transport_header_size;
+    2568                 :            :         uint32_t session_id;
+    2569                 :            :         libspdm_session_info_t        *session_info;
+    2570                 :            :         uint8_t *scratch_buffer;
+    2571                 :            :         size_t scratch_buffer_size;
+    2572                 :            : 
+    2573                 :          2 :         spdm_response_size = sizeof(spdm_key_update_response_t);
+    2574                 :          2 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2575                 :          2 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2576                 :            : 
+    2577                 :          2 :         session_id = 0xFFFFFFFF;
+    2578                 :            : 
+    2579                 :          2 :         session_info = libspdm_get_session_info_via_session_id(
+    2580                 :            :             spdm_context, session_id);
+    2581         [ -  + ]:          2 :         if (session_info == NULL) {
+    2582                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+    2583                 :            :         }
+    2584                 :            : 
+    2585                 :          2 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2586                 :          2 :         spdm_response->header.request_response_code =
+    2587                 :            :             SPDM_KEY_UPDATE_ACK;
+    2588         [ +  + ]:          2 :         if (sub_index == 0) {
+    2589                 :          1 :             spdm_response->header.param1 =
+    2590                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY;
+    2591                 :          1 :             spdm_response->header.param2 = m_libspdm_last_token;
+    2592         [ +  - ]:          1 :         } else if (sub_index == 1) {
+    2593                 :          1 :             spdm_response->header.param1 =
+    2594                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_VERIFY_NEW_KEY;
+    2595                 :            :             /*wrong token*/
+    2596                 :          1 :             spdm_response->header.param2 = m_libspdm_last_token + 1;
+    2597                 :            :         }
+    2598                 :            : 
+    2599                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    2600                 :            :          * transport_message is always in sender buffer. */
+    2601                 :          2 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+    2602                 :          2 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+    2603                 :            :                           scratch_buffer_size - transport_header_size,
+    2604                 :            :                           spdm_response, spdm_response_size);
+    2605                 :          2 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+    2606                 :          2 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+    2607                 :            :                                               false, false, spdm_response_size,
+    2608                 :            :                                               spdm_response, response_size, response);
+    2609                 :            :         /* WALKAROUND: If just use single context to encode
+    2610                 :            :          * message and then decode message */
+    2611                 :            :         ((libspdm_secured_message_context_t
+    2612                 :          2 :           *)(session_info->secured_message_context))
+    2613                 :          2 :         ->application_secret.response_data_sequence_number--;
+    2614                 :            : 
+    2615                 :          2 :         sub_index++;
+    2616                 :            :     }
+    2617                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+    2618                 :            : 
+    2619                 :          2 :     case 0x1A: {
+    2620                 :            :         static size_t sub_index = 0;
+    2621                 :            : 
+    2622                 :            :         spdm_key_update_response_t *spdm_response;
+    2623                 :            :         size_t spdm_response_size;
+    2624                 :            :         size_t transport_header_size;
+    2625                 :            :         uint32_t session_id;
+    2626                 :            :         libspdm_session_info_t        *session_info;
+    2627                 :            :         uint8_t *scratch_buffer;
+    2628                 :            :         size_t scratch_buffer_size;
+    2629                 :            : 
+    2630                 :          2 :         spdm_response_size = sizeof(spdm_key_update_response_t);
+    2631                 :          2 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2632                 :          2 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2633                 :            : 
+    2634                 :          2 :         session_id = 0xFFFFFFFF;
+    2635                 :            : 
+    2636                 :          2 :         session_info = libspdm_get_session_info_via_session_id(
+    2637                 :            :             spdm_context, session_id);
+    2638         [ -  + ]:          2 :         if (session_info == NULL) {
+    2639                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+    2640                 :            :         }
+    2641                 :            : 
+    2642                 :          2 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2643                 :          2 :         spdm_response->header.request_response_code =
+    2644                 :            :             SPDM_KEY_UPDATE_ACK;
+    2645         [ +  + ]:          2 :         if (sub_index == 0) {
+    2646                 :          1 :             spdm_response->header.param1 =
+    2647                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY;
+    2648                 :          1 :             spdm_response->header.param2 = m_libspdm_last_token;
+    2649         [ +  - ]:          1 :         } else if (sub_index == 1) {
+    2650                 :            :             /*wrong operation code*/
+    2651                 :          1 :             spdm_response->header.param1 =
+    2652                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY;
+    2653                 :          1 :             spdm_response->header.param2 = m_libspdm_last_token;
+    2654                 :            :         }
+    2655                 :            : 
+    2656                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    2657                 :            :          * transport_message is always in sender buffer. */
+    2658                 :          2 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+    2659                 :          2 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+    2660                 :            :                           scratch_buffer_size - transport_header_size,
+    2661                 :            :                           spdm_response, spdm_response_size);
+    2662                 :          2 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+    2663                 :          2 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+    2664                 :            :                                               false, false, spdm_response_size,
+    2665                 :            :                                               spdm_response, response_size, response);
+    2666                 :            :         /* WALKAROUND: If just use single context to encode
+    2667                 :            :          * message and then decode message */
+    2668                 :            :         ((libspdm_secured_message_context_t
+    2669                 :          2 :           *)(session_info->secured_message_context))
+    2670                 :          2 :         ->application_secret.response_data_sequence_number--;
+    2671                 :            : 
+    2672                 :          2 :         sub_index++;
+    2673                 :            :     }
+    2674                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+    2675                 :            : 
+    2676                 :          2 :     case 0x1B: {
+    2677                 :            :         static size_t sub_index = 0;
+    2678                 :            : 
+    2679                 :            :         spdm_key_update_response_t *spdm_response;
+    2680                 :            :         size_t spdm_response_size;
+    2681                 :            :         size_t transport_header_size;
+    2682                 :            :         uint32_t session_id;
+    2683                 :            :         libspdm_session_info_t        *session_info;
+    2684                 :            :         uint8_t *scratch_buffer;
+    2685                 :            :         size_t scratch_buffer_size;
+    2686                 :            : 
+    2687                 :          2 :         spdm_response_size = sizeof(spdm_key_update_response_t);
+    2688                 :          2 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2689                 :          2 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2690                 :            : 
+    2691                 :          2 :         session_id = 0xFFFFFFFF;
+    2692                 :            : 
+    2693                 :          2 :         session_info = libspdm_get_session_info_via_session_id(
+    2694                 :            :             spdm_context, session_id);
+    2695         [ -  + ]:          2 :         if (session_info == NULL) {
+    2696                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+    2697                 :            :         }
+    2698                 :            : 
+    2699                 :          2 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2700                 :          2 :         spdm_response->header.request_response_code = SPDM_KEY_UPDATE_ACK;
+    2701         [ +  + ]:          2 :         if (sub_index == 0) {
+    2702                 :          1 :             spdm_response->header.param1 =
+    2703                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_ALL_KEYS;
+    2704                 :          1 :             spdm_response->header.param2 = m_libspdm_last_token;
+    2705         [ +  - ]:          1 :         } else if (sub_index == 1) {
+    2706                 :          1 :             spdm_response->header.param1 =
+    2707                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_VERIFY_NEW_KEY;
+    2708                 :          1 :             spdm_response->header.param2 = m_libspdm_last_token;
+    2709                 :            : 
+    2710                 :            :             /* as it is using single context, the keys were updated
+    2711                 :            :              * in the requester and do not need to be updated before
+    2712                 :            :              * sending the response */
+    2713                 :            :         }
+    2714                 :            : 
+    2715                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    2716                 :            :          * transport_message is always in sender buffer. */
+    2717                 :          2 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+    2718                 :          2 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+    2719                 :            :                           scratch_buffer_size - transport_header_size,
+    2720                 :            :                           spdm_response, spdm_response_size);
+    2721                 :          2 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+    2722                 :          2 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+    2723                 :            :                                               false, false, spdm_response_size,
+    2724                 :            :                                               spdm_response, response_size, response);
+    2725                 :            :         /* WALKAROUND: If just use single context to encode
+    2726                 :            :          * message and then decode message */
+    2727                 :            :         ((libspdm_secured_message_context_t
+    2728                 :          2 :           *)(session_info->secured_message_context))
+    2729                 :          2 :         ->application_secret.response_data_sequence_number--;
+    2730                 :            : 
+    2731                 :          2 :         sub_index++;
+    2732                 :            :     }
+    2733                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+    2734                 :            : 
+    2735                 :          1 :     case 0x1C: {
+    2736                 :            :         spdm_error_response_t *spdm_response;
+    2737                 :            :         size_t spdm_response_size;
+    2738                 :            :         size_t transport_header_size;
+    2739                 :            :         uint32_t session_id;
+    2740                 :            :         libspdm_session_info_t    *session_info;
+    2741                 :            :         uint8_t *scratch_buffer;
+    2742                 :            :         size_t scratch_buffer_size;
+    2743                 :            : 
+    2744                 :            :         libspdm_secured_message_context_t *secured_message_context;
+    2745                 :            :         uint8_t curr_rsp_enc_key[LIBSPDM_MAX_AEAD_KEY_SIZE];
+    2746                 :            :         uint8_t curr_rsp_salt[LIBSPDM_MAX_AEAD_IV_SIZE];
+    2747                 :            :         uint64_t curr_rsp_sequence_number;
+    2748                 :            : 
+    2749                 :          1 :         spdm_response_size = sizeof(spdm_key_update_response_t);
+    2750                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2751                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2752                 :            : 
+    2753                 :          1 :         session_id = 0xFFFFFFFF;
+    2754                 :          1 :         session_info = libspdm_get_session_info_via_session_id(
+    2755                 :            :             spdm_context, session_id);
+    2756         [ -  + ]:          1 :         if (session_info == NULL) {
+    2757                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+    2758                 :            :         }
+    2759                 :          1 :         secured_message_context = session_info->secured_message_context;
+    2760                 :            : 
+    2761                 :            :         /*use previous key to send*/
+    2762                 :          1 :         libspdm_copy_mem(curr_rsp_enc_key, sizeof(curr_rsp_enc_key),
+    2763                 :            :                          secured_message_context
+    2764                 :          1 :                          ->application_secret.response_data_encryption_key,
+    2765                 :            :                          secured_message_context->aead_key_size);
+    2766                 :          1 :         libspdm_copy_mem(curr_rsp_salt, sizeof(curr_rsp_salt),
+    2767                 :            :                          secured_message_context
+    2768                 :          1 :                          ->application_secret.response_data_salt,
+    2769                 :            :                          secured_message_context->aead_iv_size);
+    2770                 :          1 :         curr_rsp_sequence_number = m_libspdm_last_rsp_sequence_number;
+    2771                 :            : 
+    2772                 :          1 :         libspdm_copy_mem(secured_message_context->application_secret
+    2773                 :          1 :                          .response_data_encryption_key,
+    2774                 :            :                          sizeof(secured_message_context->application_secret
+    2775                 :            :                                 .response_data_encryption_key),
+    2776                 :            :                          m_libspdm_last_rsp_enc_key,
+    2777                 :            :                          secured_message_context->aead_key_size);
+    2778                 :          1 :         libspdm_copy_mem(secured_message_context->application_secret
+    2779                 :          1 :                          .response_data_salt,
+    2780                 :            :                          sizeof(secured_message_context->application_secret
+    2781                 :            :                                 .response_data_salt),
+    2782                 :            :                          m_libspdm_last_rsp_salt,
+    2783                 :            :                          secured_message_context->aead_iv_size);
+    2784                 :            :         secured_message_context->application_secret
+    2785                 :          1 :         .response_data_sequence_number = m_libspdm_last_rsp_sequence_number;
+    2786                 :            : 
+    2787                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2788                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+    2789                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_INVALID_REQUEST;
+    2790                 :          1 :         spdm_response->header.param2 = 0;
+    2791                 :            : 
+    2792                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    2793                 :            :          * transport_message is always in sender buffer. */
+    2794                 :          1 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+    2795                 :          1 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+    2796                 :            :                           scratch_buffer_size - transport_header_size,
+    2797                 :            :                           spdm_response, spdm_response_size);
+    2798                 :          1 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+    2799                 :          1 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+    2800                 :            :                                               false, false, spdm_response_size,
+    2801                 :            :                                               spdm_response, response_size, response);
+    2802                 :            : 
+    2803                 :            :         /*restore new key*/
+    2804                 :          1 :         libspdm_copy_mem(secured_message_context->application_secret
+    2805                 :          1 :                          .response_data_encryption_key,
+    2806                 :            :                          sizeof(secured_message_context->application_secret
+    2807                 :            :                                 .response_data_encryption_key),
+    2808                 :            :                          curr_rsp_enc_key,
+    2809                 :            :                          secured_message_context->aead_key_size);
+    2810                 :          1 :         libspdm_copy_mem(secured_message_context->application_secret
+    2811                 :          1 :                          .response_data_salt,
+    2812                 :            :                          sizeof(secured_message_context->application_secret
+    2813                 :            :                                 .response_data_salt),
+    2814                 :            :                          curr_rsp_salt,
+    2815                 :            :                          secured_message_context->aead_iv_size);
+    2816                 :            :         secured_message_context->application_secret
+    2817                 :          1 :         .response_data_sequence_number = curr_rsp_sequence_number;
+    2818                 :            :     }
+    2819                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    2820                 :            : 
+    2821                 :          4 :     case 0x1D: {
+    2822                 :            :         spdm_error_response_t *spdm_response;
+    2823                 :            :         size_t spdm_response_size;
+    2824                 :            :         size_t transport_header_size;
+    2825                 :            :         uint32_t session_id;
+    2826                 :            :         libspdm_session_info_t    *session_info;
+    2827                 :            :         uint8_t *scratch_buffer;
+    2828                 :            :         size_t scratch_buffer_size;
+    2829                 :            : 
+    2830                 :            :         libspdm_secured_message_context_t *secured_message_context;
+    2831                 :            :         uint8_t curr_rsp_enc_key[LIBSPDM_MAX_AEAD_KEY_SIZE];
+    2832                 :            :         uint8_t curr_rsp_salt[LIBSPDM_MAX_AEAD_IV_SIZE];
+    2833                 :            :         uint64_t curr_rsp_sequence_number;
+    2834                 :            : 
+    2835                 :          4 :         spdm_response_size = sizeof(spdm_key_update_response_t);
+    2836                 :          4 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2837                 :          4 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2838                 :            : 
+    2839                 :          4 :         session_id = 0xFFFFFFFF;
+    2840                 :          4 :         session_info = libspdm_get_session_info_via_session_id(
+    2841                 :            :             spdm_context, session_id);
+    2842         [ -  + ]:          4 :         if (session_info == NULL) {
+    2843                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+    2844                 :            :         }
+    2845                 :          4 :         secured_message_context = session_info->secured_message_context;
+    2846                 :            : 
+    2847                 :            :         /*use previous key to send*/
+    2848                 :          4 :         libspdm_copy_mem(curr_rsp_enc_key, sizeof(curr_rsp_enc_key),
+    2849                 :            :                          secured_message_context
+    2850                 :          4 :                          ->application_secret.response_data_encryption_key,
+    2851                 :            :                          secured_message_context->aead_key_size);
+    2852                 :          4 :         libspdm_copy_mem(curr_rsp_salt, sizeof(curr_rsp_salt),
+    2853                 :            :                          secured_message_context
+    2854                 :          4 :                          ->application_secret.response_data_salt,
+    2855                 :            :                          secured_message_context->aead_iv_size);
+    2856                 :          4 :         curr_rsp_sequence_number = m_libspdm_last_rsp_sequence_number;
+    2857                 :            : 
+    2858                 :          4 :         libspdm_copy_mem(secured_message_context->application_secret
+    2859                 :          4 :                          .response_data_encryption_key,
+    2860                 :            :                          sizeof(secured_message_context->application_secret
+    2861                 :            :                                 .response_data_encryption_key),
+    2862                 :            :                          m_libspdm_last_rsp_enc_key,
+    2863                 :            :                          secured_message_context->aead_key_size);
+    2864                 :          4 :         libspdm_copy_mem(secured_message_context->application_secret
+    2865                 :          4 :                          .response_data_salt,
+    2866                 :            :                          sizeof(secured_message_context->application_secret
+    2867                 :            :                                 .response_data_salt),
+    2868                 :            :                          m_libspdm_last_rsp_salt,
+    2869                 :            :                          secured_message_context->aead_iv_size);
+    2870                 :            :         secured_message_context->application_secret
+    2871                 :          4 :         .response_data_sequence_number = m_libspdm_last_rsp_sequence_number;
+    2872                 :            : 
+    2873                 :            :         /* once the sequence number is used, it should be increased for next BUSY message.*/
+    2874                 :          4 :         m_libspdm_last_rsp_sequence_number++;
+    2875                 :            : 
+    2876                 :          4 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2877                 :          4 :         spdm_response->header.request_response_code = SPDM_ERROR;
+    2878                 :          4 :         spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
+    2879                 :          4 :         spdm_response->header.param2 = 0;
+    2880                 :            : 
+    2881                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    2882                 :            :          * transport_message is always in sender buffer. */
+    2883                 :          4 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+    2884                 :          4 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+    2885                 :            :                           scratch_buffer_size - transport_header_size,
+    2886                 :            :                           spdm_response, spdm_response_size);
+    2887                 :          4 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+    2888                 :          4 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+    2889                 :            :                                               false, false, spdm_response_size,
+    2890                 :            :                                               spdm_response, response_size, response);
+    2891                 :            : 
+    2892                 :            :         /*restore new key*/
+    2893                 :          4 :         libspdm_copy_mem(secured_message_context->application_secret
+    2894                 :          4 :                          .response_data_encryption_key,
+    2895                 :            :                          sizeof(secured_message_context->application_secret
+    2896                 :            :                                 .response_data_encryption_key),
+    2897                 :            :                          curr_rsp_enc_key,
+    2898                 :            :                          secured_message_context->aead_key_size);
+    2899                 :          4 :         libspdm_copy_mem(secured_message_context->application_secret
+    2900                 :          4 :                          .response_data_salt,
+    2901                 :            :                          sizeof(secured_message_context->application_secret
+    2902                 :            :                                 .response_data_salt),
+    2903                 :            :                          curr_rsp_salt,
+    2904                 :            :                          secured_message_context->aead_iv_size);
+    2905                 :            :         secured_message_context->application_secret
+    2906                 :          4 :         .response_data_sequence_number = curr_rsp_sequence_number;
+    2907                 :            :     }
+    2908                 :          4 :         return LIBSPDM_STATUS_SUCCESS;
+    2909                 :            : 
+    2910                 :          3 :     case 0x1E: {
+    2911                 :            :         static size_t sub_index = 0;
+    2912                 :            : 
+    2913                 :            :         uint32_t session_id;
+    2914                 :            :         libspdm_session_info_t    *session_info;
+    2915                 :            : 
+    2916                 :            :         libspdm_secured_message_context_t *secured_message_context;
+    2917                 :            : 
+    2918                 :          3 :         session_id = 0xFFFFFFFF;
+    2919                 :          3 :         session_info = libspdm_get_session_info_via_session_id(
+    2920                 :            :             spdm_context, session_id);
+    2921         [ -  + ]:          3 :         if (session_info == NULL) {
+    2922                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+    2923                 :            :         }
+    2924                 :          3 :         secured_message_context = session_info->secured_message_context;
+    2925                 :            : 
+    2926         [ +  + ]:          3 :         if (sub_index == 0) {
+    2927                 :            :             spdm_error_response_t *spdm_response;
+    2928                 :            :             size_t spdm_response_size;
+    2929                 :            :             size_t transport_header_size;
+    2930                 :            :             uint8_t *scratch_buffer;
+    2931                 :            :             size_t scratch_buffer_size;
+    2932                 :            : 
+    2933                 :          1 :             spdm_response_size = sizeof(spdm_error_response_t);
+    2934                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2935                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2936                 :            : 
+    2937                 :            :             uint8_t curr_rsp_enc_key[LIBSPDM_MAX_AEAD_KEY_SIZE];
+    2938                 :            :             uint8_t curr_rsp_salt[LIBSPDM_MAX_AEAD_IV_SIZE];
+    2939                 :            :             uint64_t curr_rsp_sequence_number;
+    2940                 :            : 
+    2941                 :            :             /*use previous key to send*/
+    2942                 :          1 :             libspdm_copy_mem(curr_rsp_enc_key, sizeof(curr_rsp_enc_key),
+    2943                 :            :                              secured_message_context
+    2944                 :          1 :                              ->application_secret.response_data_encryption_key,
+    2945                 :            :                              secured_message_context->aead_key_size);
+    2946                 :          1 :             libspdm_copy_mem(curr_rsp_salt, sizeof(curr_rsp_salt),
+    2947                 :            :                              secured_message_context
+    2948                 :          1 :                              ->application_secret.response_data_salt,
+    2949                 :            :                              secured_message_context->aead_iv_size);
+    2950                 :          1 :             curr_rsp_sequence_number = m_libspdm_last_rsp_sequence_number;
+    2951                 :            : 
+    2952                 :          1 :             libspdm_copy_mem(secured_message_context->application_secret
+    2953                 :          1 :                              .response_data_encryption_key,
+    2954                 :            :                              sizeof(secured_message_context->application_secret
+    2955                 :            :                                     .response_data_encryption_key),
+    2956                 :            :                              m_libspdm_last_rsp_enc_key,
+    2957                 :            :                              secured_message_context->aead_key_size);
+    2958                 :          1 :             libspdm_copy_mem(secured_message_context->application_secret
+    2959                 :          1 :                              .response_data_salt,
+    2960                 :            :                              sizeof(secured_message_context->application_secret
+    2961                 :            :                                     .response_data_salt),
+    2962                 :            :                              m_libspdm_last_rsp_salt,
+    2963                 :            :                              secured_message_context->aead_iv_size);
+    2964                 :            :             secured_message_context->application_secret
+    2965                 :          1 :             .response_data_sequence_number = m_libspdm_last_rsp_sequence_number;
+    2966                 :            : 
+    2967                 :          1 :             spdm_response->header.spdm_version =
+    2968                 :            :                 SPDM_MESSAGE_VERSION_11;
+    2969                 :          1 :             spdm_response->header.request_response_code = SPDM_ERROR;
+    2970                 :          1 :             spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
+    2971                 :          1 :             spdm_response->header.param2 = 0;
+    2972                 :            : 
+    2973                 :            :             /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    2974                 :            :              * transport_message is always in sender buffer. */
+    2975                 :          1 :             libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+    2976                 :            :                                         &scratch_buffer_size);
+    2977                 :          1 :             libspdm_copy_mem (scratch_buffer + transport_header_size,
+    2978                 :            :                               scratch_buffer_size - transport_header_size,
+    2979                 :            :                               spdm_response, spdm_response_size);
+    2980                 :          1 :             spdm_response = (void *)(scratch_buffer + transport_header_size);
+    2981                 :          1 :             libspdm_transport_test_encode_message(spdm_context,
+    2982                 :            :                                                   &session_id, false, false,
+    2983                 :            :                                                   spdm_response_size, spdm_response,
+    2984                 :            :                                                   response_size, response);
+    2985                 :            : 
+    2986                 :            :             /*restore new key*/
+    2987                 :          1 :             libspdm_copy_mem(secured_message_context->application_secret
+    2988                 :          1 :                              .response_data_encryption_key,
+    2989                 :            :                              sizeof(secured_message_context->application_secret
+    2990                 :            :                                     .response_data_encryption_key),
+    2991                 :            :                              curr_rsp_enc_key,
+    2992                 :            :                              secured_message_context->aead_key_size);
+    2993                 :          1 :             libspdm_copy_mem(secured_message_context->application_secret
+    2994                 :          1 :                              .response_data_salt,
+    2995                 :            :                              sizeof(secured_message_context->application_secret
+    2996                 :            :                                     .response_data_salt),
+    2997                 :            :                              curr_rsp_salt,
+    2998                 :            :                              secured_message_context->aead_iv_size);
+    2999                 :            :             secured_message_context->application_secret
+    3000                 :          1 :             .response_data_sequence_number = curr_rsp_sequence_number;
+    3001         [ +  + ]:          2 :         } else if (sub_index == 1) {
+    3002                 :            :             spdm_key_update_response_t *spdm_response;
+    3003                 :            :             size_t spdm_response_size;
+    3004                 :            :             size_t transport_header_size;
+    3005                 :            :             uint8_t *scratch_buffer;
+    3006                 :            :             size_t scratch_buffer_size;
+    3007                 :            : 
+    3008                 :          1 :             spdm_response_size = sizeof(spdm_key_update_response_t);
+    3009                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    3010                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    3011                 :            : 
+    3012                 :          1 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    3013                 :          1 :             spdm_response->header.request_response_code =
+    3014                 :            :                 SPDM_KEY_UPDATE_ACK;
+    3015                 :          1 :             spdm_response->header.param1 =
+    3016                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_ALL_KEYS;
+    3017                 :          1 :             spdm_response->header.param2 = m_libspdm_last_token;
+    3018                 :            : 
+    3019                 :            :             /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    3020                 :            :              * transport_message is always in sender buffer. */
+    3021                 :          1 :             libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+    3022                 :            :                                         &scratch_buffer_size);
+    3023                 :          1 :             libspdm_copy_mem (scratch_buffer + transport_header_size,
+    3024                 :            :                               scratch_buffer_size - transport_header_size,
+    3025                 :            :                               spdm_response, spdm_response_size);
+    3026                 :          1 :             spdm_response = (void *)(scratch_buffer + transport_header_size);
+    3027                 :          1 :             libspdm_transport_test_encode_message(spdm_context,
+    3028                 :            :                                                   &session_id, false, false,
+    3029                 :            :                                                   spdm_response_size, spdm_response,
+    3030                 :            :                                                   response_size, response);
+    3031                 :            :             /* WALKAROUND: If just use single context to encode
+    3032                 :            :              * message and then decode message */
+    3033                 :            :             secured_message_context->application_secret
+    3034                 :          1 :             .response_data_sequence_number--;
+    3035         [ +  - ]:          1 :         } else if (sub_index == 2) {
+    3036                 :            :             spdm_key_update_response_t *spdm_response;
+    3037                 :            :             size_t spdm_response_size;
+    3038                 :            :             size_t transport_header_size;
+    3039                 :            :             uint8_t *scratch_buffer;
+    3040                 :            :             size_t scratch_buffer_size;
+    3041                 :            : 
+    3042                 :          1 :             spdm_response_size = sizeof(spdm_key_update_response_t);
+    3043                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    3044                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    3045                 :            : 
+    3046                 :          1 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    3047                 :          1 :             spdm_response->header.request_response_code =
+    3048                 :            :                 SPDM_KEY_UPDATE_ACK;
+    3049                 :          1 :             spdm_response->header.param1 =
+    3050                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_VERIFY_NEW_KEY;
+    3051                 :          1 :             spdm_response->header.param2 = m_libspdm_last_token;
+    3052                 :            : 
+    3053                 :            :             /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    3054                 :            :              * transport_message is always in sender buffer. */
+    3055                 :          1 :             libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+    3056                 :            :                                         &scratch_buffer_size);
+    3057                 :          1 :             libspdm_copy_mem (scratch_buffer + transport_header_size,
+    3058                 :            :                               scratch_buffer_size - transport_header_size,
+    3059                 :            :                               spdm_response, spdm_response_size);
+    3060                 :          1 :             spdm_response = (void *)(scratch_buffer + transport_header_size);
+    3061                 :          1 :             libspdm_transport_test_encode_message(spdm_context,
+    3062                 :            :                                                   &session_id, false, false,
+    3063                 :            :                                                   spdm_response_size, spdm_response,
+    3064                 :            :                                                   response_size, response);
+    3065                 :            :             /* WALKAROUND: If just use single context to encode
+    3066                 :            :              * message and then decode message */
+    3067                 :            :             secured_message_context->application_secret
+    3068                 :          1 :             .response_data_sequence_number--;
+    3069                 :            :         }
+    3070                 :            : 
+    3071                 :          3 :         sub_index++;
+    3072                 :            :     }
+    3073                 :          3 :         return LIBSPDM_STATUS_SUCCESS;
+    3074                 :            : 
+    3075                 :          1 :     case 0x1F: {
+    3076                 :            :         spdm_error_response_t *spdm_response;
+    3077                 :            :         size_t spdm_response_size;
+    3078                 :            :         size_t transport_header_size;
+    3079                 :            :         uint32_t session_id;
+    3080                 :            :         libspdm_session_info_t    *session_info;
+    3081                 :            :         uint8_t *scratch_buffer;
+    3082                 :            :         size_t scratch_buffer_size;
+    3083                 :            : 
+    3084                 :            :         libspdm_secured_message_context_t *secured_message_context;
+    3085                 :            :         uint8_t curr_rsp_enc_key[LIBSPDM_MAX_AEAD_KEY_SIZE];
+    3086                 :            :         uint8_t curr_rsp_salt[LIBSPDM_MAX_AEAD_IV_SIZE];
+    3087                 :            :         uint64_t curr_rsp_sequence_number;
+    3088                 :            : 
+    3089                 :          1 :         spdm_response_size = sizeof(spdm_error_response_t);
+    3090                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    3091                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    3092                 :            : 
+    3093                 :          1 :         session_id = 0xFFFFFFFF;
+    3094                 :          1 :         session_info = libspdm_get_session_info_via_session_id(
+    3095                 :            :             spdm_context, session_id);
+    3096         [ -  + ]:          1 :         if (session_info == NULL) {
+    3097                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+    3098                 :            :         }
+    3099                 :          1 :         secured_message_context = session_info->secured_message_context;
+    3100                 :            : 
+    3101                 :            :         /*use previous key to send*/
+    3102                 :          1 :         libspdm_copy_mem(curr_rsp_enc_key, sizeof(curr_rsp_enc_key),
+    3103                 :            :                          secured_message_context
+    3104                 :          1 :                          ->application_secret.response_data_encryption_key,
+    3105                 :            :                          secured_message_context->aead_key_size);
+    3106                 :          1 :         libspdm_copy_mem(curr_rsp_salt, sizeof(curr_rsp_salt),
+    3107                 :            :                          secured_message_context
+    3108                 :          1 :                          ->application_secret.response_data_salt,
+    3109                 :            :                          secured_message_context->aead_iv_size);
+    3110                 :          1 :         curr_rsp_sequence_number = m_libspdm_last_rsp_sequence_number;
+    3111                 :            : 
+    3112                 :          1 :         libspdm_copy_mem(secured_message_context->application_secret
+    3113                 :          1 :                          .response_data_encryption_key,
+    3114                 :            :                          sizeof(secured_message_context->application_secret
+    3115                 :            :                                 .response_data_encryption_key),
+    3116                 :            :                          m_libspdm_last_rsp_enc_key,
+    3117                 :            :                          secured_message_context->aead_key_size);
+    3118                 :          1 :         libspdm_copy_mem(secured_message_context->application_secret
+    3119                 :          1 :                          .response_data_salt,
+    3120                 :            :                          sizeof(secured_message_context->application_secret
+    3121                 :            :                                 .response_data_salt),
+    3122                 :            :                          m_libspdm_last_rsp_salt,
+    3123                 :            :                          secured_message_context->aead_iv_size);
+    3124                 :            :         secured_message_context->application_secret
+    3125                 :          1 :         .response_data_sequence_number = m_libspdm_last_rsp_sequence_number;
+    3126                 :            : 
+    3127                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    3128                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+    3129                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_REQUEST_RESYNCH;
+    3130                 :          1 :         spdm_response->header.param2 = 0;
+    3131                 :            : 
+    3132                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    3133                 :            :          * transport_message is always in sender buffer. */
+    3134                 :          1 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+    3135                 :          1 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+    3136                 :            :                           scratch_buffer_size - transport_header_size,
+    3137                 :            :                           spdm_response, spdm_response_size);
+    3138                 :          1 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+    3139                 :          1 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+    3140                 :            :                                               false, false, spdm_response_size,
+    3141                 :            :                                               spdm_response, response_size, response);
+    3142                 :            : 
+    3143                 :            :         /*restore new key*/
+    3144                 :          1 :         libspdm_copy_mem(secured_message_context->application_secret
+    3145                 :          1 :                          .response_data_encryption_key,
+    3146                 :            :                          sizeof(secured_message_context->application_secret
+    3147                 :            :                                 .response_data_encryption_key),
+    3148                 :            :                          curr_rsp_enc_key,
+    3149                 :            :                          secured_message_context->aead_key_size);
+    3150                 :          1 :         libspdm_copy_mem(secured_message_context->application_secret
+    3151                 :          1 :                          .response_data_salt,
+    3152                 :            :                          sizeof(secured_message_context->application_secret
+    3153                 :            :                                 .response_data_salt),
+    3154                 :            :                          curr_rsp_salt,
+    3155                 :            :                          secured_message_context->aead_iv_size);
+    3156                 :            :         secured_message_context->application_secret
+    3157                 :          1 :         .response_data_sequence_number = curr_rsp_sequence_number;
+    3158                 :            :     }
+    3159                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    3160                 :            : 
+    3161                 :          2 :     case 0x20: {
+    3162                 :            :         spdm_error_response_data_response_not_ready_t *spdm_response;
+    3163                 :            :         size_t spdm_response_size;
+    3164                 :            :         size_t transport_header_size;
+    3165                 :            :         uint32_t session_id;
+    3166                 :            :         libspdm_session_info_t    *session_info;
+    3167                 :            :         uint8_t *scratch_buffer;
+    3168                 :            :         size_t scratch_buffer_size;
+    3169                 :            : 
+    3170                 :            :         libspdm_secured_message_context_t *secured_message_context;
+    3171                 :            :         uint8_t curr_rsp_enc_key[LIBSPDM_MAX_AEAD_KEY_SIZE];
+    3172                 :            :         uint8_t curr_rsp_salt[LIBSPDM_MAX_AEAD_IV_SIZE];
+    3173                 :            :         uint64_t curr_rsp_sequence_number;
+    3174                 :            : 
+    3175                 :          2 :         spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
+    3176                 :          2 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    3177                 :          2 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    3178                 :            : 
+    3179                 :          2 :         session_id = 0xFFFFFFFF;
+    3180                 :          2 :         session_info = libspdm_get_session_info_via_session_id(
+    3181                 :            :             spdm_context, session_id);
+    3182         [ -  + ]:          2 :         if (session_info == NULL) {
+    3183                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+    3184                 :            :         }
+    3185                 :          2 :         secured_message_context = session_info->secured_message_context;
+    3186                 :            : 
+    3187                 :            :         /*use previous key to send*/
+    3188                 :          2 :         libspdm_copy_mem(curr_rsp_enc_key, sizeof(curr_rsp_enc_key),
+    3189                 :            :                          secured_message_context
+    3190                 :          2 :                          ->application_secret.response_data_encryption_key,
+    3191                 :            :                          secured_message_context->aead_key_size);
+    3192                 :          2 :         libspdm_copy_mem(curr_rsp_salt, sizeof(curr_rsp_salt),
+    3193                 :            :                          secured_message_context
+    3194                 :          2 :                          ->application_secret.response_data_salt,
+    3195                 :            :                          secured_message_context->aead_iv_size);
+    3196                 :          2 :         curr_rsp_sequence_number = m_libspdm_last_rsp_sequence_number;
+    3197                 :            : 
+    3198                 :          2 :         libspdm_copy_mem(secured_message_context->application_secret
+    3199                 :          2 :                          .response_data_encryption_key,
+    3200                 :            :                          sizeof(secured_message_context->application_secret
+    3201                 :            :                                 .response_data_encryption_key),
+    3202                 :            :                          m_libspdm_last_rsp_enc_key,
+    3203                 :            :                          secured_message_context->aead_key_size);
+    3204                 :          2 :         libspdm_copy_mem(secured_message_context->application_secret
+    3205                 :          2 :                          .response_data_salt,
+    3206                 :            :                          sizeof(secured_message_context->application_secret
+    3207                 :            :                                 .response_data_salt),
+    3208                 :            :                          m_libspdm_last_rsp_salt,
+    3209                 :            :                          secured_message_context->aead_iv_size);
+    3210                 :            :         secured_message_context->application_secret
+    3211                 :          2 :         .response_data_sequence_number = m_libspdm_last_rsp_sequence_number;
+    3212                 :            : 
+    3213                 :            :         /* once the sequence number is used, it should be increased for next NOT_READY message.*/
+    3214                 :          2 :         m_libspdm_last_rsp_sequence_number++;
+    3215                 :            : 
+    3216                 :          2 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    3217                 :          2 :         spdm_response->header.request_response_code = SPDM_ERROR;
+    3218                 :          2 :         spdm_response->header.param1 =
+    3219                 :            :             SPDM_ERROR_CODE_RESPONSE_NOT_READY;
+    3220                 :          2 :         spdm_response->header.param2 = 0;
+    3221                 :          2 :         spdm_response->extend_error_data.rd_exponent = 1;
+    3222                 :          2 :         spdm_response->extend_error_data.rd_tm = 2;
+    3223                 :          2 :         spdm_response->extend_error_data.request_code = SPDM_KEY_UPDATE;
+    3224                 :          2 :         spdm_response->extend_error_data.token = 0;
+    3225                 :            : 
+    3226                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    3227                 :            :          * transport_message is always in sender buffer. */
+    3228                 :          2 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+    3229                 :          2 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+    3230                 :            :                           scratch_buffer_size - transport_header_size,
+    3231                 :            :                           spdm_response, spdm_response_size);
+    3232                 :          2 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+    3233                 :          2 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+    3234                 :            :                                               false, false, spdm_response_size,
+    3235                 :            :                                               spdm_response, response_size, response);
+    3236                 :            : 
+    3237                 :            :         /*restore new key*/
+    3238                 :          2 :         libspdm_copy_mem(secured_message_context->application_secret
+    3239                 :          2 :                          .response_data_encryption_key,
+    3240                 :            :                          sizeof(secured_message_context->application_secret
+    3241                 :            :                                 .response_data_encryption_key),
+    3242                 :            :                          curr_rsp_enc_key,
+    3243                 :            :                          secured_message_context->aead_key_size);
+    3244                 :          2 :         libspdm_copy_mem(secured_message_context->application_secret
+    3245                 :          2 :                          .response_data_salt,
+    3246                 :            :                          sizeof(secured_message_context->application_secret
+    3247                 :            :                                 .response_data_salt),
+    3248                 :            :                          curr_rsp_salt,
+    3249                 :            :                          secured_message_context->aead_iv_size);
+    3250                 :            :         secured_message_context->application_secret
+    3251                 :          2 :         .response_data_sequence_number = curr_rsp_sequence_number;
+    3252                 :            :     }
+    3253                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+    3254                 :            : 
+    3255                 :          3 :     case 0x21: {
+    3256                 :            :         static size_t sub_index = 0;
+    3257                 :            : 
+    3258                 :            :         uint32_t session_id;
+    3259                 :            :         libspdm_session_info_t    *session_info;
+    3260                 :            : 
+    3261                 :            :         libspdm_secured_message_context_t *secured_message_context;
+    3262                 :            : 
+    3263                 :          3 :         session_id = 0xFFFFFFFF;
+    3264                 :          3 :         session_info = libspdm_get_session_info_via_session_id(
+    3265                 :            :             spdm_context, session_id);
+    3266         [ -  + ]:          3 :         if (session_info == NULL) {
+    3267                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+    3268                 :            :         }
+    3269                 :          3 :         secured_message_context = session_info->secured_message_context;
+    3270                 :            : 
+    3271         [ +  + ]:          3 :         if (sub_index == 0) {
+    3272                 :            :             spdm_error_response_data_response_not_ready_t
+    3273                 :            :             *spdm_response;
+    3274                 :            :             size_t spdm_response_size;
+    3275                 :            :             size_t transport_header_size;
+    3276                 :            :             uint8_t *scratch_buffer;
+    3277                 :            :             size_t scratch_buffer_size;
+    3278                 :            : 
+    3279                 :            :             uint8_t curr_rsp_enc_key[LIBSPDM_MAX_AEAD_KEY_SIZE];
+    3280                 :            :             uint8_t curr_rsp_salt[LIBSPDM_MAX_AEAD_IV_SIZE];
+    3281                 :            :             uint64_t curr_rsp_sequence_number;
+    3282                 :            : 
+    3283                 :          1 :             spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
+    3284                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    3285                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    3286                 :            : 
+    3287                 :            :             /*use previous key to send*/
+    3288                 :          1 :             libspdm_copy_mem(curr_rsp_enc_key, sizeof(curr_rsp_enc_key),
+    3289                 :            :                              secured_message_context
+    3290                 :          1 :                              ->application_secret.response_data_encryption_key,
+    3291                 :            :                              secured_message_context->aead_key_size);
+    3292                 :          1 :             libspdm_copy_mem(curr_rsp_salt, sizeof(curr_rsp_salt),
+    3293                 :            :                              secured_message_context
+    3294                 :          1 :                              ->application_secret.response_data_salt,
+    3295                 :            :                              secured_message_context->aead_iv_size);
+    3296                 :          1 :             curr_rsp_sequence_number = m_libspdm_last_rsp_sequence_number;
+    3297                 :            : 
+    3298                 :          1 :             libspdm_copy_mem(secured_message_context->application_secret
+    3299                 :          1 :                              .response_data_encryption_key,
+    3300                 :            :                              sizeof(secured_message_context->application_secret
+    3301                 :            :                                     .response_data_encryption_key),
+    3302                 :            :                              m_libspdm_last_rsp_enc_key,
+    3303                 :            :                              secured_message_context->aead_key_size);
+    3304                 :          1 :             libspdm_copy_mem(secured_message_context->application_secret
+    3305                 :          1 :                              .response_data_salt,
+    3306                 :            :                              sizeof(secured_message_context->application_secret
+    3307                 :            :                                     .response_data_salt),
+    3308                 :            :                              m_libspdm_last_rsp_salt,
+    3309                 :            :                              secured_message_context->aead_iv_size);
+    3310                 :            :             secured_message_context->application_secret
+    3311                 :          1 :             .response_data_sequence_number = m_libspdm_last_rsp_sequence_number;
+    3312                 :            : 
+    3313                 :          1 :             spdm_response->header.spdm_version =
+    3314                 :            :                 SPDM_MESSAGE_VERSION_11;
+    3315                 :          1 :             spdm_response->header.request_response_code = SPDM_ERROR;
+    3316                 :          1 :             spdm_response->header.param1 =
+    3317                 :            :                 SPDM_ERROR_CODE_RESPONSE_NOT_READY;
+    3318                 :          1 :             spdm_response->header.param2 = 0;
+    3319                 :          1 :             spdm_response->extend_error_data.rd_exponent = 1;
+    3320                 :          1 :             spdm_response->extend_error_data.rd_tm = 2;
+    3321                 :          1 :             spdm_response->extend_error_data.request_code =
+    3322                 :            :                 SPDM_KEY_UPDATE;
+    3323                 :          1 :             spdm_response->extend_error_data.token = 1;
+    3324                 :            : 
+    3325                 :            :             /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    3326                 :            :              * transport_message is always in sender buffer. */
+    3327                 :          1 :             libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+    3328                 :            :                                         &scratch_buffer_size);
+    3329                 :          1 :             libspdm_copy_mem (scratch_buffer + transport_header_size,
+    3330                 :            :                               scratch_buffer_size - transport_header_size,
+    3331                 :            :                               spdm_response, spdm_response_size);
+    3332                 :          1 :             spdm_response = (void *)(scratch_buffer + transport_header_size);
+    3333                 :          1 :             libspdm_transport_test_encode_message(spdm_context,
+    3334                 :            :                                                   &session_id, false, false,
+    3335                 :            :                                                   spdm_response_size, spdm_response,
+    3336                 :            :                                                   response_size, response);
+    3337                 :            : 
+    3338                 :            :             /*restore new key*/
+    3339                 :          1 :             libspdm_copy_mem(secured_message_context->application_secret
+    3340                 :          1 :                              .response_data_encryption_key,
+    3341                 :            :                              sizeof(secured_message_context->application_secret
+    3342                 :            :                                     .response_data_encryption_key),
+    3343                 :            :                              curr_rsp_enc_key,
+    3344                 :            :                              secured_message_context->aead_key_size);
+    3345                 :          1 :             libspdm_copy_mem(secured_message_context->application_secret
+    3346                 :          1 :                              .response_data_salt,
+    3347                 :            :                              sizeof(secured_message_context->application_secret
+    3348                 :            :                                     .response_data_salt),
+    3349                 :            :                              curr_rsp_salt,
+    3350                 :            :                              secured_message_context->aead_iv_size);
+    3351                 :            :             secured_message_context->application_secret
+    3352                 :          1 :             .response_data_sequence_number = curr_rsp_sequence_number;
+    3353         [ +  + ]:          2 :         } else if (sub_index == 1) {
+    3354                 :            :             spdm_key_update_response_t *spdm_response;
+    3355                 :            :             size_t spdm_response_size;
+    3356                 :            :             size_t transport_header_size;
+    3357                 :            :             uint8_t *scratch_buffer;
+    3358                 :            :             size_t scratch_buffer_size;
+    3359                 :            : 
+    3360                 :          1 :             spdm_response_size = sizeof(spdm_key_update_response_t);
+    3361                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    3362                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    3363                 :            : 
+    3364                 :          1 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    3365                 :          1 :             spdm_response->header.request_response_code =
+    3366                 :            :                 SPDM_KEY_UPDATE_ACK;
+    3367                 :          1 :             spdm_response->header.param1 =
+    3368                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_ALL_KEYS;
+    3369                 :          1 :             spdm_response->header.param2 = m_libspdm_last_token;
+    3370                 :            : 
+    3371                 :            :             /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    3372                 :            :              * transport_message is always in sender buffer. */
+    3373                 :          1 :             libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+    3374                 :            :                                         &scratch_buffer_size);
+    3375                 :          1 :             libspdm_copy_mem (scratch_buffer + transport_header_size,
+    3376                 :            :                               scratch_buffer_size - transport_header_size,
+    3377                 :            :                               spdm_response, spdm_response_size);
+    3378                 :          1 :             spdm_response = (void *)(scratch_buffer + transport_header_size);
+    3379                 :          1 :             libspdm_transport_test_encode_message(spdm_context,
+    3380                 :            :                                                   &session_id, false, false,
+    3381                 :            :                                                   spdm_response_size, spdm_response,
+    3382                 :            :                                                   response_size, response);
+    3383                 :            :             /* WALKAROUND: If just use single context to encode
+    3384                 :            :              * message and then decode message */
+    3385                 :            :             secured_message_context->application_secret
+    3386                 :          1 :             .response_data_sequence_number--;
+    3387         [ +  - ]:          1 :         } else if (sub_index == 2) {
+    3388                 :            :             spdm_key_update_response_t *spdm_response;
+    3389                 :            :             size_t spdm_response_size;
+    3390                 :            :             size_t transport_header_size;
+    3391                 :            :             uint8_t *scratch_buffer;
+    3392                 :            :             size_t scratch_buffer_size;
+    3393                 :            : 
+    3394                 :          1 :             spdm_response_size = sizeof(spdm_key_update_response_t);
+    3395                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    3396                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    3397                 :            : 
+    3398                 :          1 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    3399                 :          1 :             spdm_response->header.request_response_code =
+    3400                 :            :                 SPDM_KEY_UPDATE_ACK;
+    3401                 :          1 :             spdm_response->header.param1 =
+    3402                 :            :                 SPDM_KEY_UPDATE_OPERATIONS_TABLE_VERIFY_NEW_KEY;
+    3403                 :          1 :             spdm_response->header.param2 = m_libspdm_last_token;
+    3404                 :            : 
+    3405                 :            :             /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    3406                 :            :              * transport_message is always in sender buffer. */
+    3407                 :          1 :             libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+    3408                 :            :                                         &scratch_buffer_size);
+    3409                 :          1 :             libspdm_copy_mem (scratch_buffer + transport_header_size,
+    3410                 :            :                               scratch_buffer_size - transport_header_size,
+    3411                 :            :                               spdm_response, spdm_response_size);
+    3412                 :          1 :             spdm_response = (void *)(scratch_buffer + transport_header_size);
+    3413                 :          1 :             libspdm_transport_test_encode_message(spdm_context,
+    3414                 :            :                                                   &session_id, false, false,
+    3415                 :            :                                                   spdm_response_size, spdm_response,
+    3416                 :            :                                                   response_size, response);
+    3417                 :            :             /* WALKAROUND: If just use single context to encode
+    3418                 :            :              * message and then decode message */
+    3419                 :            :             secured_message_context->application_secret
+    3420                 :          1 :             .response_data_sequence_number--;
+    3421                 :            :         }
+    3422                 :            : 
+    3423                 :          3 :         sub_index++;
+    3424                 :            :     }
+    3425                 :          3 :         return LIBSPDM_STATUS_SUCCESS;
+    3426                 :            : 
+    3427                 :         17 :     case 0x22: {
+    3428                 :            :         static uint16_t error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
+    3429                 :            : 
+    3430                 :            :         uint32_t session_id;
+    3431                 :            :         libspdm_session_info_t    *session_info;
+    3432                 :            : 
+    3433                 :            :         spdm_error_response_t *spdm_response;
+    3434                 :            :         size_t spdm_response_size;
+    3435                 :            :         size_t transport_header_size;
+    3436                 :            :         uint8_t *scratch_buffer;
+    3437                 :            :         size_t scratch_buffer_size;
+    3438                 :            : 
+    3439                 :            :         libspdm_secured_message_context_t *secured_message_context;
+    3440                 :            :         uint8_t curr_rsp_enc_key[LIBSPDM_MAX_AEAD_KEY_SIZE];
+    3441                 :            :         uint8_t curr_rsp_salt[LIBSPDM_MAX_AEAD_IV_SIZE];
+    3442                 :            :         uint64_t curr_rsp_sequence_number;
+    3443                 :            : 
+    3444                 :         17 :         spdm_response_size = sizeof(spdm_error_response_t);
+    3445                 :         17 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    3446                 :         17 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    3447                 :            : 
+    3448                 :         17 :         session_id = 0xFFFFFFFF;
+    3449                 :         17 :         session_info = libspdm_get_session_info_via_session_id(
+    3450                 :            :             spdm_context, session_id);
+    3451         [ -  + ]:         17 :         if (session_info == NULL) {
+    3452                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+    3453                 :            :         }
+    3454                 :         17 :         secured_message_context = session_info->secured_message_context;
+    3455                 :            : 
+    3456         [ +  - ]:         17 :         if(error_code <= 0xff) {
+    3457                 :            :             /* skip SPDM_ERROR_CODE_DECRYPT_ERROR, because this case will free context*/
+    3458         [ +  + ]:         17 :             if(error_code == SPDM_ERROR_CODE_DECRYPT_ERROR) {
+    3459                 :          1 :                 error_code++;
+    3460                 :            :             }
+    3461                 :            :             /*use previous key to send*/
+    3462                 :         17 :             libspdm_copy_mem(curr_rsp_enc_key, sizeof(curr_rsp_enc_key),
+    3463                 :            :                              secured_message_context
+    3464                 :         17 :                              ->application_secret.response_data_encryption_key,
+    3465                 :            :                              secured_message_context->aead_key_size);
+    3466                 :         17 :             libspdm_copy_mem(curr_rsp_salt, sizeof(curr_rsp_salt),
+    3467                 :            :                              secured_message_context
+    3468                 :         17 :                              ->application_secret.response_data_salt,
+    3469                 :            :                              secured_message_context->aead_iv_size);
+    3470                 :         17 :             curr_rsp_sequence_number = m_libspdm_last_rsp_sequence_number;
+    3471                 :            : 
+    3472                 :         17 :             libspdm_copy_mem(secured_message_context->application_secret
+    3473                 :         17 :                              .response_data_encryption_key,
+    3474                 :            :                              sizeof(secured_message_context->application_secret
+    3475                 :            :                                     .response_data_encryption_key),
+    3476                 :            :                              m_libspdm_last_rsp_enc_key,
+    3477                 :            :                              secured_message_context->aead_key_size);
+    3478                 :         17 :             libspdm_copy_mem(secured_message_context->application_secret
+    3479                 :         17 :                              .response_data_salt,
+    3480                 :            :                              sizeof(secured_message_context->application_secret
+    3481                 :            :                                     .response_data_salt),
+    3482                 :            :                              m_libspdm_last_rsp_salt,
+    3483                 :            :                              secured_message_context->aead_iv_size);
+    3484                 :            :             secured_message_context->application_secret
+    3485                 :         17 :             .response_data_sequence_number = m_libspdm_last_rsp_sequence_number;
+    3486                 :            : 
+    3487                 :         17 :             libspdm_zero_mem (spdm_response, spdm_response_size);
+    3488                 :         17 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    3489                 :         17 :             spdm_response->header.request_response_code = SPDM_ERROR;
+    3490                 :         17 :             spdm_response->header.param1 = (uint8_t) error_code;
+    3491                 :         17 :             spdm_response->header.param2 = 0;
+    3492                 :            : 
+    3493                 :            :             /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    3494                 :            :              * transport_message is always in sender buffer. */
+    3495                 :         17 :             libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+    3496                 :            :                                         &scratch_buffer_size);
+    3497                 :         17 :             libspdm_copy_mem (scratch_buffer + transport_header_size,
+    3498                 :            :                               scratch_buffer_size - transport_header_size,
+    3499                 :            :                               spdm_response, spdm_response_size);
+    3500                 :         17 :             spdm_response = (void *)(scratch_buffer + transport_header_size);
+    3501                 :         17 :             libspdm_transport_test_encode_message(spdm_context,
+    3502                 :            :                                                   &session_id, false, false,
+    3503                 :            :                                                   spdm_response_size, spdm_response,
+    3504                 :            :                                                   response_size, response);
+    3505                 :            : 
+    3506                 :            :             /*restore new key*/
+    3507                 :         17 :             libspdm_copy_mem(secured_message_context->application_secret
+    3508                 :         17 :                              .response_data_encryption_key,
+    3509                 :            :                              sizeof(secured_message_context->application_secret
+    3510                 :            :                                     .response_data_encryption_key),
+    3511                 :            :                              curr_rsp_enc_key,
+    3512                 :            :                              secured_message_context->aead_key_size);
+    3513                 :         17 :             libspdm_copy_mem(secured_message_context->application_secret
+    3514                 :         17 :                              .response_data_salt,
+    3515                 :            :                              sizeof(secured_message_context->application_secret
+    3516                 :            :                                     .response_data_salt),
+    3517                 :            :                              curr_rsp_salt,
+    3518                 :            :                              secured_message_context->aead_iv_size);
+    3519                 :            :             secured_message_context->application_secret
+    3520                 :         17 :             .response_data_sequence_number = curr_rsp_sequence_number;
+    3521                 :            :         }
+    3522                 :            : 
+    3523                 :         17 :         error_code++;
+    3524                 :            :         /*busy is treated in cases 5 and 6*/
+    3525         [ +  + ]:         17 :         if(error_code == SPDM_ERROR_CODE_BUSY) {
+    3526                 :          1 :             error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
+    3527                 :            :         }
+    3528                 :            :         /*skip some reserved error codes (0d to 3e)*/
+    3529         [ +  + ]:         17 :         if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) {
+    3530                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
+    3531                 :            :         }
+    3532                 :            :         /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
+    3533         [ +  + ]:         17 :         if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) {
+    3534                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
+    3535                 :            :         }
+    3536                 :            :     }
+    3537                 :         17 :         return LIBSPDM_STATUS_SUCCESS;
+    3538                 :            : 
+    3539                 :          1 :     case 0x23: {
+    3540                 :            :         spdm_error_response_t *spdm_response;
+    3541                 :            :         size_t spdm_response_size;
+    3542                 :            :         size_t transport_header_size;
+    3543                 :            :         uint32_t session_id;
+    3544                 :            :         libspdm_session_info_t    *session_info;
+    3545                 :            :         uint8_t *scratch_buffer;
+    3546                 :            :         size_t scratch_buffer_size;
+    3547                 :            : 
+    3548                 :          1 :         spdm_response_size = sizeof(spdm_error_response_t);
+    3549                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    3550                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    3551                 :            : 
+    3552                 :          1 :         session_id = 0xFFFFFFFF;
+    3553                 :          1 :         session_info = libspdm_get_session_info_via_session_id(
+    3554                 :            :             spdm_context, session_id);
+    3555         [ -  + ]:          1 :         if (session_info == NULL) {
+    3556                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+    3557                 :            :         }
+    3558                 :            : 
+    3559                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    3560                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+    3561                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_DECRYPT_ERROR;
+    3562                 :          1 :         spdm_response->header.param2 = 0;
+    3563                 :            : 
+    3564                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+    3565                 :            :          * transport_message is always in sender buffer. */
+    3566                 :          1 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+    3567                 :          1 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+    3568                 :            :                           scratch_buffer_size - transport_header_size,
+    3569                 :            :                           spdm_response, spdm_response_size);
+    3570                 :          1 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+    3571                 :          1 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+    3572                 :            :                                               false, false, spdm_response_size,
+    3573                 :            :                                               spdm_response, response_size, response);
+    3574                 :            :         /* WALKAROUND: If just use single context to encode
+    3575                 :            :          * message and then decode message */
+    3576                 :            :         ((libspdm_secured_message_context_t
+    3577                 :          1 :           *)(session_info->secured_message_context))
+    3578                 :          1 :         ->application_secret.response_data_sequence_number--;
+    3579                 :            :     }
+    3580                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    3581                 :            : 
+    3582                 :          0 :     default:
+    3583                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+    3584                 :            :     }
+    3585                 :            : }
+    3586                 :            : 
+    3587                 :            : 
+    3588                 :            : /**
+    3589                 :            :  * Test 1: when no KEY_UPDATE_ACK message is received, and the client
+    3590                 :            :  * returns a device error.
+    3591                 :            :  * Expected behavior: client returns a Status of RETURN_DEVICE_ERROR.
+    3592                 :            :  **/
+    3593                 :          1 : void libspdm_test_requester_key_update_case1(void **state)
+    3594                 :            : {
+    3595                 :            :     libspdm_return_t status;
+    3596                 :            :     libspdm_test_context_t    *spdm_test_context;
+    3597                 :            :     libspdm_context_t         *spdm_context;
+    3598                 :            :     uint32_t session_id;
+    3599                 :            :     libspdm_session_info_t    *session_info;
+    3600                 :            : 
+    3601                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    3602                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    3603                 :            : 
+    3604                 :          1 :     spdm_test_context = *state;
+    3605                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    3606                 :          1 :     spdm_test_context->case_id = 0x1;
+    3607                 :            : 
+    3608                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    3609                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3610                 :          1 :     libspdm_set_standard_key_update_test_state(
+    3611                 :            :         spdm_context, &session_id);
+    3612                 :            : 
+    3613                 :          1 :     session_info = &spdm_context->session_info[0];
+    3614                 :            : 
+    3615                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    3616                 :          1 :         session_info->secured_message_context,
+    3617                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    3618                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    3619                 :            : 
+    3620                 :          1 :     status = libspdm_key_update(
+    3621                 :            :         spdm_context, session_id, true);
+    3622                 :            : 
+    3623                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SEND_FAIL);
+    3624                 :          1 : }
+    3625                 :            : 
+    3626                 :            : /**
+    3627                 :            :  * Test 2: receiving a correct UPDATE_KEY_ACK message for updating
+    3628                 :            :  * only the request data key.
+    3629                 :            :  * Expected behavior: client returns a Status of RETURN_SUCCESS, the
+    3630                 :            :  * request data key is updated, but not the response data key.
+    3631                 :            :  **/
+    3632                 :          1 : void libspdm_test_requester_key_update_case2(void **state)
+    3633                 :            : {
+    3634                 :            :     libspdm_return_t status;
+    3635                 :            :     libspdm_test_context_t    *spdm_test_context;
+    3636                 :            :     libspdm_context_t         *spdm_context;
+    3637                 :            :     uint32_t session_id;
+    3638                 :            :     libspdm_session_info_t    *session_info;
+    3639                 :            : 
+    3640                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    3641                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    3642                 :            : 
+    3643                 :          1 :     spdm_test_context = *state;
+    3644                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    3645                 :          1 :     spdm_test_context->case_id = 0x2;
+    3646                 :            : 
+    3647                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    3648                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3649                 :          1 :     libspdm_set_standard_key_update_test_state(
+    3650                 :            :         spdm_context, &session_id);
+    3651                 :            : 
+    3652                 :          1 :     session_info = &spdm_context->session_info[0];
+    3653                 :            : 
+    3654                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    3655                 :          1 :         session_info->secured_message_context,
+    3656                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    3657                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    3658                 :            : 
+    3659                 :            :     /*request side updated*/
+    3660                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    3661                 :            :                                   ((libspdm_secured_message_context_t
+    3662                 :          1 :                                     *)(session_info->secured_message_context))->hash_size,
+    3663                 :            :                                   m_req_secret_buffer, m_req_secret_buffer,
+    3664                 :            :                                   sizeof(m_req_secret_buffer));
+    3665                 :            :     /*response side *not* updated*/
+    3666                 :            : 
+    3667                 :          1 :     status = libspdm_key_update(
+    3668                 :            :         spdm_context, session_id, true);
+    3669                 :            : 
+    3670                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    3671                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    3672                 :            :                           *)(session_info->secured_message_context))
+    3673                 :            :                         ->application_secret.request_data_secret,
+    3674                 :            :                         m_req_secret_buffer, ((libspdm_secured_message_context_t
+    3675                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    3676                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    3677                 :            :                           *)(session_info->secured_message_context))
+    3678                 :            :                         ->application_secret.response_data_secret,
+    3679                 :            :                         m_rsp_secret_buffer, ((libspdm_secured_message_context_t
+    3680                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    3681                 :          1 : }
+    3682                 :            : 
+    3683                 :            : /**
+    3684                 :            :  * Test 3: requester state has not been negotiated, as if GET_VERSION,
+    3685                 :            :  * GET_CAPABILITIES and NEGOTIATE_ALGORITHMS had not been exchanged.
+    3686                 :            :  * Expected behavior: client returns a Status of RETURN_UNSUPPORTED.
+    3687                 :            :  **/
+    3688                 :          1 : void libspdm_test_requester_key_update_case3(void **state)
+    3689                 :            : {
+    3690                 :            :     libspdm_return_t status;
+    3691                 :            :     libspdm_test_context_t    *spdm_test_context;
+    3692                 :            :     libspdm_context_t         *spdm_context;
+    3693                 :            :     uint32_t session_id;
+    3694                 :            :     libspdm_session_info_t    *session_info;
+    3695                 :            : 
+    3696                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    3697                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    3698                 :            : 
+    3699                 :          1 :     spdm_test_context = *state;
+    3700                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    3701                 :          1 :     spdm_test_context->case_id = 0x3;
+    3702                 :            : 
+    3703                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    3704                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3705                 :          1 :     libspdm_set_standard_key_update_test_state(
+    3706                 :            :         spdm_context, &session_id);
+    3707                 :            : 
+    3708                 :            :     /*state not negotiated*/
+    3709                 :          1 :     spdm_context->connection_info.connection_state =
+    3710                 :            :         LIBSPDM_CONNECTION_STATE_NOT_STARTED;
+    3711                 :            : 
+    3712                 :          1 :     session_info = &spdm_context->session_info[0];
+    3713                 :            : 
+    3714                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    3715                 :          1 :         session_info->secured_message_context,
+    3716                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    3717                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    3718                 :            : 
+    3719                 :          1 :     status = libspdm_key_update(
+    3720                 :            :         spdm_context, session_id, true);
+    3721                 :            : 
+    3722                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_STATE_LOCAL);
+    3723                 :          1 : }
+    3724                 :            : 
+    3725                 :            : /**
+    3726                 :            :  * Test 4: the requester is setup correctly (see Test 2), but receives an ERROR
+    3727                 :            :  * message indicating InvalidParameters when updating key.
+    3728                 :            :  * Expected behavior: client returns a Status of RETURN_DEVICE_ERROR, and
+    3729                 :            :  * no keys should be updated.
+    3730                 :            :  **/
+    3731                 :          1 : void libspdm_test_requester_key_update_case4(void **state)
+    3732                 :            : {
+    3733                 :            :     libspdm_return_t status;
+    3734                 :            :     libspdm_test_context_t    *spdm_test_context;
+    3735                 :            :     libspdm_context_t         *spdm_context;
+    3736                 :            :     uint32_t session_id;
+    3737                 :            :     libspdm_session_info_t    *session_info;
+    3738                 :            : 
+    3739                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    3740                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    3741                 :            : 
+    3742                 :          1 :     spdm_test_context = *state;
+    3743                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    3744                 :          1 :     spdm_test_context->case_id = 0x4;
+    3745                 :            : 
+    3746                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    3747                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3748                 :          1 :     libspdm_set_standard_key_update_test_state(
+    3749                 :            :         spdm_context, &session_id);
+    3750                 :            : 
+    3751                 :          1 :     session_info = &spdm_context->session_info[0];
+    3752                 :            : 
+    3753                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    3754                 :          1 :         session_info->secured_message_context,
+    3755                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    3756                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    3757                 :            : 
+    3758                 :            :     /*no keys are updated*/
+    3759                 :            : 
+    3760                 :          1 :     status = libspdm_key_update(
+    3761                 :            :         spdm_context, session_id, true);
+    3762                 :            : 
+    3763                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_ERROR_PEER);
+    3764                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    3765                 :            :                           *)(session_info->secured_message_context))
+    3766                 :            :                         ->application_secret.request_data_secret,
+    3767                 :            :                         m_req_secret_buffer, ((libspdm_secured_message_context_t
+    3768                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    3769                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    3770                 :            :                           *)(session_info->secured_message_context))
+    3771                 :            :                         ->application_secret.response_data_secret,
+    3772                 :            :                         m_rsp_secret_buffer, ((libspdm_secured_message_context_t
+    3773                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    3774                 :          1 : }
+    3775                 :            : 
+    3776                 :            : /**
+    3777                 :            :  * Test 5: the requester is setup correctly (see Test 2), but receives an ERROR
+    3778                 :            :  * message indicating the Busy status of the responder, when updating key.
+    3779                 :            :  * Expected behavior: client returns a Status of RETURN_NO_RESPONSE, and
+    3780                 :            :  * no keys should be updated.
+    3781                 :            :  **/
+    3782                 :          1 : void libspdm_test_requester_key_update_case5(void **state)
+    3783                 :            : {
+    3784                 :            :     libspdm_return_t status;
+    3785                 :            :     libspdm_test_context_t    *spdm_test_context;
+    3786                 :            :     libspdm_context_t         *spdm_context;
+    3787                 :            :     uint32_t session_id;
+    3788                 :            :     libspdm_session_info_t    *session_info;
+    3789                 :            : 
+    3790                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    3791                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    3792                 :            : 
+    3793                 :          1 :     spdm_test_context = *state;
+    3794                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    3795                 :          1 :     spdm_test_context->case_id = 0x5;
+    3796                 :            : 
+    3797                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    3798                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3799                 :          1 :     libspdm_set_standard_key_update_test_state(
+    3800                 :            :         spdm_context, &session_id);
+    3801                 :            : 
+    3802                 :          1 :     session_info = &spdm_context->session_info[0];
+    3803                 :            : 
+    3804                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    3805                 :          1 :         session_info->secured_message_context,
+    3806                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    3807                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    3808                 :            : 
+    3809                 :            :     /*no keys are updated*/
+    3810                 :            : 
+    3811                 :          1 :     status = libspdm_key_update(
+    3812                 :            :         spdm_context, session_id, true);
+    3813                 :            : 
+    3814                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_BUSY_PEER);
+    3815                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    3816                 :            :                           *)(session_info->secured_message_context))
+    3817                 :            :                         ->application_secret.request_data_secret,
+    3818                 :            :                         m_req_secret_buffer, ((libspdm_secured_message_context_t
+    3819                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    3820                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    3821                 :            :                           *)(session_info->secured_message_context))
+    3822                 :            :                         ->application_secret.response_data_secret,
+    3823                 :            :                         m_rsp_secret_buffer, ((libspdm_secured_message_context_t
+    3824                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    3825                 :          1 : }
+    3826                 :            : 
+    3827                 :            : /**
+    3828                 :            :  * Test 6: the requester is setup correctly (see Test 2), but, when updating
+    3829                 :            :  * key, on the first try, receiving a Busy ERROR message, and on retry,
+    3830                 :            :  * receiving a correct KEY_UPDATE_ACK message. The VERIFY_KEY behavior is
+    3831                 :            :  * not altered.
+    3832                 :            :  * Expected behavior: client returns a Status of RETURN_SUCCESS, the
+    3833                 :            :  * request data key is updated, but not the response data key.
+    3834                 :            :  **/
+    3835                 :          1 : void libspdm_test_requester_key_update_case6(void **state)
+    3836                 :            : {
+    3837                 :            :     libspdm_return_t status;
+    3838                 :            :     libspdm_test_context_t    *spdm_test_context;
+    3839                 :            :     libspdm_context_t         *spdm_context;
+    3840                 :            :     uint32_t session_id;
+    3841                 :            :     libspdm_session_info_t    *session_info;
+    3842                 :            : 
+    3843                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    3844                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    3845                 :            : 
+    3846                 :          1 :     spdm_test_context = *state;
+    3847                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    3848                 :          1 :     spdm_test_context->case_id = 0x6;
+    3849                 :            : 
+    3850                 :          1 :     spdm_context->retry_times = 3;
+    3851                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    3852                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3853                 :          1 :     libspdm_set_standard_key_update_test_state(
+    3854                 :            :         spdm_context, &session_id);
+    3855                 :            : 
+    3856                 :          1 :     session_info = &spdm_context->session_info[0];
+    3857                 :            : 
+    3858                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    3859                 :          1 :         session_info->secured_message_context,
+    3860                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    3861                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    3862                 :            : 
+    3863                 :            :     /*request side updated*/
+    3864                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    3865                 :            :                                   ((libspdm_secured_message_context_t
+    3866                 :          1 :                                     *)(session_info->secured_message_context))->hash_size,
+    3867                 :            :                                   m_req_secret_buffer, m_req_secret_buffer,
+    3868                 :            :                                   sizeof(m_req_secret_buffer));
+    3869                 :            :     /*response side *not* updated*/
+    3870                 :            : 
+    3871                 :          1 :     status = libspdm_key_update(
+    3872                 :            :         spdm_context, session_id, true);
+    3873                 :            : 
+    3874                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    3875                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    3876                 :            :                           *)(session_info->secured_message_context))
+    3877                 :            :                         ->application_secret.request_data_secret,
+    3878                 :            :                         m_req_secret_buffer, ((libspdm_secured_message_context_t
+    3879                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    3880                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    3881                 :            :                           *)(session_info->secured_message_context))
+    3882                 :            :                         ->application_secret.response_data_secret,
+    3883                 :            :                         m_rsp_secret_buffer, ((libspdm_secured_message_context_t
+    3884                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    3885                 :          1 : }
+    3886                 :            : 
+    3887                 :            : /**
+    3888                 :            :  * Test 7: the requester is setup correctly (see Test 2), but receives an ERROR
+    3889                 :            :  * message indicating the RequestResynch status of the responder, when updating
+    3890                 :            :  * key.
+    3891                 :            :  * Expected behavior: client returns a Status of RETURN_DEVICE_ERROR, and the
+    3892                 :            :  * communication is reset to expect a new GET_VERSION message.
+    3893                 :            :  **/
+    3894                 :          1 : void libspdm_test_requester_key_update_case7(void **state)
+    3895                 :            : {
+    3896                 :            :     libspdm_return_t status;
+    3897                 :            :     libspdm_test_context_t    *spdm_test_context;
+    3898                 :            :     libspdm_context_t         *spdm_context;
+    3899                 :            :     uint32_t session_id;
+    3900                 :            :     libspdm_session_info_t    *session_info;
+    3901                 :            : 
+    3902                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    3903                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    3904                 :            : 
+    3905                 :          1 :     spdm_test_context = *state;
+    3906                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    3907                 :          1 :     spdm_test_context->case_id = 0x7;
+    3908                 :            : 
+    3909                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    3910                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3911                 :          1 :     libspdm_set_standard_key_update_test_state(
+    3912                 :            :         spdm_context, &session_id);
+    3913                 :            : 
+    3914                 :          1 :     session_info = &spdm_context->session_info[0];
+    3915                 :            : 
+    3916                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    3917                 :          1 :         session_info->secured_message_context,
+    3918                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    3919                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    3920                 :            : 
+    3921                 :          1 :     status = libspdm_key_update(
+    3922                 :            :         spdm_context, session_id, true);
+    3923                 :            : 
+    3924                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_RESYNCH_PEER);
+    3925                 :          1 :     assert_int_equal(spdm_context->connection_info.connection_state,
+    3926                 :            :                      LIBSPDM_CONNECTION_STATE_NOT_STARTED);
+    3927                 :          1 : }
+    3928                 :            : 
+    3929                 :            : /**
+    3930                 :            :  * Test 8: the requester is setup correctly (see Test 2), but receives an ERROR
+    3931                 :            :  * message indicating the ResponseNotReady status of the responder, when
+    3932                 :            :  * updating key.
+    3933                 :            :  * Expected behavior: client returns a Status of RETURN_DEVICE_ERROR, and
+    3934                 :            :  * no keys should be updated.
+    3935                 :            :  **/
+    3936                 :          1 : void libspdm_test_requester_key_update_case8(void **state)
+    3937                 :            : {
+    3938                 :            :     libspdm_return_t status;
+    3939                 :            :     libspdm_test_context_t    *spdm_test_context;
+    3940                 :            :     libspdm_context_t         *spdm_context;
+    3941                 :            :     uint32_t session_id;
+    3942                 :            :     libspdm_session_info_t    *session_info;
+    3943                 :            : 
+    3944                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    3945                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    3946                 :            : 
+    3947                 :          1 :     spdm_test_context = *state;
+    3948                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    3949                 :          1 :     spdm_test_context->case_id = 0x8;
+    3950                 :            : 
+    3951                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    3952                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3953                 :          1 :     libspdm_set_standard_key_update_test_state(
+    3954                 :            :         spdm_context, &session_id);
+    3955                 :            : 
+    3956                 :          1 :     session_info = &spdm_context->session_info[0];
+    3957                 :            : 
+    3958                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    3959                 :          1 :         session_info->secured_message_context,
+    3960                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    3961                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    3962                 :            : 
+    3963                 :            :     /*no keys are updated*/
+    3964                 :            : 
+    3965                 :          1 :     status = libspdm_key_update(
+    3966                 :            :         spdm_context, session_id, true);
+    3967                 :            : 
+    3968                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_NOT_READY_PEER);
+    3969                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    3970                 :            :                           *)(session_info->secured_message_context))
+    3971                 :            :                         ->application_secret.request_data_secret,
+    3972                 :            :                         m_req_secret_buffer, ((libspdm_secured_message_context_t
+    3973                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    3974                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    3975                 :            :                           *)(session_info->secured_message_context))
+    3976                 :            :                         ->application_secret.response_data_secret,
+    3977                 :            :                         m_rsp_secret_buffer, ((libspdm_secured_message_context_t
+    3978                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    3979                 :          1 : }
+    3980                 :            : 
+    3981                 :            : /**
+    3982                 :            :  * Test 9: the requester is setup correctly (see Test 2), but, when updating
+    3983                 :            :  * key, on the first try, receiving a ResponseNotReady ERROR message, and on
+    3984                 :            :  * retry, receiving a correct KEY_UPDATE_ACK message. The VERIFY_KEY
+    3985                 :            :  * behavior is not altered.
+    3986                 :            :  * Expected behavior: client returns a Status of RETURN_SUCCESS, the
+    3987                 :            :  * request data key is updated, but not the response data key.
+    3988                 :            :  **/
+    3989                 :          1 : void libspdm_test_requester_key_update_case9(void **state)
+    3990                 :            : {
+    3991                 :            :     libspdm_return_t status;
+    3992                 :            :     libspdm_test_context_t    *spdm_test_context;
+    3993                 :            :     libspdm_context_t         *spdm_context;
+    3994                 :            :     uint32_t session_id;
+    3995                 :            :     libspdm_session_info_t    *session_info;
+    3996                 :            : 
+    3997                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    3998                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    3999                 :            : 
+    4000                 :          1 :     spdm_test_context = *state;
+    4001                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4002                 :          1 :     spdm_test_context->case_id = 0x9;
+    4003                 :            : 
+    4004                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4005                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4006                 :          1 :     libspdm_set_standard_key_update_test_state(spdm_context, &session_id);
+    4007                 :            : 
+    4008                 :          1 :     session_info = &spdm_context->session_info[0];
+    4009                 :            : 
+    4010                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    4011                 :          1 :         session_info->secured_message_context,
+    4012                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    4013                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    4014                 :            : 
+    4015                 :            :     /*request side updated*/
+    4016                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    4017                 :            :                                   ((libspdm_secured_message_context_t
+    4018                 :          1 :                                     *)(session_info->secured_message_context))->hash_size,
+    4019                 :            :                                   m_req_secret_buffer, m_req_secret_buffer,
+    4020                 :            :                                   sizeof(m_req_secret_buffer));
+    4021                 :            :     /*response side *not* updated*/
+    4022                 :            : 
+    4023                 :          1 :     status = libspdm_key_update(spdm_context, session_id, true);
+    4024                 :            : 
+    4025                 :            :     if (LIBSPDM_RESPOND_IF_READY_SUPPORT) {
+    4026                 :          1 :         assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    4027                 :          1 :         assert_memory_equal(((libspdm_secured_message_context_t *)
+    4028                 :            :                              (session_info->secured_message_context))->application_secret.request_data_secret,
+    4029                 :            :                             m_req_secret_buffer, ((libspdm_secured_message_context_t *)
+    4030                 :            :                                                   (session_info->secured_message_context))->hash_size);
+    4031                 :            : 
+    4032                 :          1 :         assert_memory_equal(((libspdm_secured_message_context_t *)
+    4033                 :            :                              (session_info->secured_message_context))->application_secret.response_data_secret,
+    4034                 :            :                             m_rsp_secret_buffer, ((libspdm_secured_message_context_t *)
+    4035                 :            :                                                   (session_info->secured_message_context))->hash_size);
+    4036                 :            :     } else {
+    4037                 :            :         assert_int_equal(status, LIBSPDM_STATUS_NOT_READY_PEER);
+    4038                 :            :     }
+    4039                 :            : 
+    4040                 :          1 : }
+    4041                 :            : 
+    4042                 :            : /**
+    4043                 :            :  * Test 10: receiving an unexpected ERROR message from the responder,
+    4044                 :            :  * when updating key.
+    4045                 :            :  * There are tests for all named codes, including some reserved ones
+    4046                 :            :  * (namely, 0x00, 0x0b, 0x0c, 0x3f, 0xfd, 0xfe).
+    4047                 :            :  * However, for having specific test cases, it is excluded from this case:
+    4048                 :            :  * Busy (0x03), ResponseNotReady (0x42), and RequestResync (0x43).
+    4049                 :            :  * Expected behavior: client returns a status of RETURN_DEVICE_ERROR, and
+    4050                 :            :  * no keys should be updated.
+    4051                 :            :  **/
+    4052                 :          1 : void libspdm_test_requester_key_update_case10(void **state)
+    4053                 :            : {
+    4054                 :            :     libspdm_return_t status;
+    4055                 :            :     libspdm_test_context_t    *spdm_test_context;
+    4056                 :            :     libspdm_context_t         *spdm_context;
+    4057                 :            :     uint32_t session_id;
+    4058                 :            :     libspdm_session_info_t    *session_info;
+    4059                 :            :     uint16_t error_code;
+    4060                 :            : 
+    4061                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    4062                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    4063                 :            : 
+    4064                 :          1 :     spdm_test_context = *state;
+    4065                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4066                 :          1 :     spdm_test_context->case_id = 0xA;
+    4067                 :            : 
+    4068                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4069                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4070                 :          1 :     libspdm_set_standard_key_update_test_state(
+    4071                 :            :         spdm_context, &session_id);
+    4072                 :            : 
+    4073                 :          1 :     session_info = &spdm_context->session_info[0];
+    4074                 :            : 
+    4075                 :          1 :     error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
+    4076         [ +  + ]:         18 :     while(error_code <= 0xff) {
+    4077                 :            :         /* skip SPDM_ERROR_CODE_DECRYPT_ERROR, because this case will free context*/
+    4078         [ +  + ]:         17 :         if(error_code == SPDM_ERROR_CODE_DECRYPT_ERROR) {
+    4079                 :          1 :             error_code++;
+    4080                 :            :         }
+    4081                 :         17 :         libspdm_set_standard_key_update_test_secrets(
+    4082                 :         17 :             session_info->secured_message_context,
+    4083                 :            :             m_rsp_secret_buffer, (uint8_t)(0xFF),
+    4084                 :            :             m_req_secret_buffer, (uint8_t)(0xEE));
+    4085                 :            : 
+    4086                 :            :         /*no keys are updated*/
+    4087                 :            : 
+    4088                 :         17 :         status = libspdm_key_update(
+    4089                 :            :             spdm_context, session_id, true);
+    4090                 :            : 
+    4091         [ -  + ]:         17 :         LIBSPDM_ASSERT_INT_EQUAL_CASE (status, LIBSPDM_STATUS_ERROR_PEER, error_code);
+    4092                 :         17 :         assert_memory_equal(((libspdm_secured_message_context_t
+    4093                 :            :                               *)(session_info->secured_message_context))
+    4094                 :            :                             ->application_secret.request_data_secret,
+    4095                 :            :                             m_req_secret_buffer, ((libspdm_secured_message_context_t
+    4096                 :            :                                                    *)(session_info->secured_message_context))->hash_size);
+    4097                 :         17 :         assert_memory_equal(((libspdm_secured_message_context_t
+    4098                 :            :                               *)(session_info->secured_message_context))
+    4099                 :            :                             ->application_secret.response_data_secret,
+    4100                 :            :                             m_rsp_secret_buffer, ((libspdm_secured_message_context_t
+    4101                 :            :                                                    *)(session_info->secured_message_context))->hash_size);
+    4102                 :            : 
+    4103                 :         17 :         error_code++;
+    4104                 :            :         /*busy is treated in cases 5 and 6*/
+    4105         [ +  + ]:         17 :         if(error_code == SPDM_ERROR_CODE_BUSY) {
+    4106                 :          1 :             error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
+    4107                 :            :         }
+    4108                 :            :         /*skip some reserved error codes (0d to 3e)*/
+    4109         [ +  + ]:         17 :         if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) {
+    4110                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
+    4111                 :            :         }
+    4112                 :            :         /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
+    4113         [ +  + ]:         17 :         if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) {
+    4114                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
+    4115                 :            :         }
+    4116                 :            :     }
+    4117                 :          1 : }
+    4118                 :            : 
+    4119                 :          1 : void libspdm_test_requester_key_update_case11(void **state)
+    4120                 :            : {
+    4121                 :            :     libspdm_return_t status;
+    4122                 :            :     libspdm_test_context_t    *spdm_test_context;
+    4123                 :            :     libspdm_context_t         *spdm_context;
+    4124                 :            :     uint32_t session_id;
+    4125                 :            :     libspdm_session_info_t    *session_info;
+    4126                 :            : 
+    4127                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    4128                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    4129                 :            : 
+    4130                 :          1 :     spdm_test_context = *state;
+    4131                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4132                 :          1 :     spdm_test_context->case_id = 0xB;
+    4133                 :            : 
+    4134                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4135                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4136                 :          1 :     libspdm_set_standard_key_update_test_state(
+    4137                 :            :         spdm_context, &session_id);
+    4138                 :            : 
+    4139                 :          1 :     session_info = &spdm_context->session_info[0];
+    4140                 :            : 
+    4141                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    4142                 :          1 :         session_info->secured_message_context,
+    4143                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    4144                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    4145                 :            : 
+    4146                 :            :     /*request side updated*/
+    4147                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    4148                 :            :                                   ((libspdm_secured_message_context_t
+    4149                 :          1 :                                     *)(session_info->secured_message_context))->hash_size,
+    4150                 :            :                                   m_req_secret_buffer, m_req_secret_buffer,
+    4151                 :            :                                   sizeof(m_req_secret_buffer));
+    4152                 :            :     /*response side *not* updated*/
+    4153                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4154                 :            :     session_info->session_transcript.message_m.buffer_size =
+    4155                 :            :         session_info->session_transcript.message_m.max_buffer_size;
+    4156                 :            :     spdm_context->transcript.message_b.buffer_size =
+    4157                 :            :         spdm_context->transcript.message_b.max_buffer_size;
+    4158                 :            :     spdm_context->transcript.message_c.buffer_size =
+    4159                 :            :         spdm_context->transcript.message_c.max_buffer_size;
+    4160                 :            :     spdm_context->transcript.message_mut_b.buffer_size =
+    4161                 :            :         spdm_context->transcript.message_mut_b.max_buffer_size;
+    4162                 :            :     spdm_context->transcript.message_mut_c.buffer_size =
+    4163                 :            :         spdm_context->transcript.message_mut_c.max_buffer_size;
+    4164                 :            : #endif
+    4165                 :            : 
+    4166                 :          1 :     status = libspdm_key_update(
+    4167                 :            :         spdm_context, session_id, true);
+    4168                 :            : 
+    4169                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    4170                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    4171                 :            :                           *)(session_info->secured_message_context))
+    4172                 :            :                         ->application_secret.request_data_secret,
+    4173                 :            :                         m_req_secret_buffer, ((libspdm_secured_message_context_t
+    4174                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    4175                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    4176                 :            :                           *)(session_info->secured_message_context))
+    4177                 :            :                         ->application_secret.response_data_secret,
+    4178                 :            :                         m_rsp_secret_buffer, ((libspdm_secured_message_context_t
+    4179                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    4180                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4181                 :            :     assert_int_equal(session_info->session_transcript.message_m.buffer_size, 0);
+    4182                 :            :     assert_int_equal(spdm_context->transcript.message_b.buffer_size, 0);
+    4183                 :            :     assert_int_equal(spdm_context->transcript.message_c.buffer_size, 0);
+    4184                 :            :     assert_int_equal(spdm_context->transcript.message_mut_b.buffer_size, 0);
+    4185                 :            :     assert_int_equal(spdm_context->transcript.message_mut_c.buffer_size, 0);
+    4186                 :            : #endif
+    4187                 :          1 : }
+    4188                 :            : 
+    4189                 :            : /**
+    4190                 :            :  * Test 12: requester is not setup correctly to support key update
+    4191                 :            :  * (no capabilities). The responder would attempt to return a correct
+    4192                 :            :  * KEY_UPDATE_ACK message.
+    4193                 :            :  * Expected behavior: client returns a Status of RETURN_UNSUPPORTED,
+    4194                 :            :  * and no keys are updated.
+    4195                 :            :  **/
+    4196                 :          1 : void libspdm_test_requester_key_update_case12(void **state)
+    4197                 :            : {
+    4198                 :            :     libspdm_return_t status;
+    4199                 :            :     libspdm_test_context_t    *spdm_test_context;
+    4200                 :            :     libspdm_context_t         *spdm_context;
+    4201                 :            :     uint32_t session_id;
+    4202                 :            :     libspdm_session_info_t    *session_info;
+    4203                 :            : 
+    4204                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    4205                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    4206                 :            : 
+    4207                 :          1 :     spdm_test_context = *state;
+    4208                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4209                 :          1 :     spdm_test_context->case_id = 0xC;
+    4210                 :            : 
+    4211                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4212                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4213                 :          1 :     libspdm_set_standard_key_update_test_state(
+    4214                 :            :         spdm_context, &session_id);
+    4215                 :            : 
+    4216                 :            :     /*no capabilities*/
+    4217                 :          1 :     spdm_context->connection_info.capability.flags &=
+    4218                 :            :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_UPD_CAP;
+    4219                 :          1 :     spdm_context->local_context.capability.flags &=
+    4220                 :            :         ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP;
+    4221                 :            : 
+    4222                 :          1 :     session_info = &spdm_context->session_info[0];
+    4223                 :            : 
+    4224                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    4225                 :          1 :         session_info->secured_message_context,
+    4226                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    4227                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    4228                 :            : 
+    4229                 :            :     /*no keys are updated*/
+    4230                 :            : 
+    4231                 :          1 :     status = libspdm_key_update(
+    4232                 :            :         spdm_context, session_id, true);
+    4233                 :            : 
+    4234                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_UNSUPPORTED_CAP);
+    4235                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    4236                 :            :                           *)(session_info->secured_message_context))
+    4237                 :            :                         ->application_secret.request_data_secret,
+    4238                 :            :                         m_req_secret_buffer, ((libspdm_secured_message_context_t
+    4239                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    4240                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    4241                 :            :                           *)(session_info->secured_message_context))
+    4242                 :            :                         ->application_secret.response_data_secret,
+    4243                 :            :                         m_rsp_secret_buffer, ((libspdm_secured_message_context_t
+    4244                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    4245                 :          1 : }
+    4246                 :            : 
+    4247                 :            : /**
+    4248                 :            :  * Test 13: receiving an incorrect KEY_UPDATE_ACK message, with wrong
+    4249                 :            :  * response code, but all other field correct, when updating key.
+    4250                 :            :  * Expected behavior: client returns a Status of RETURN_DEVICE_ERROR,
+    4251                 :            :  * no keys are updated.
+    4252                 :            :  **/
+    4253                 :          1 : void libspdm_test_requester_key_update_case13(void **state)
+    4254                 :            : {
+    4255                 :            :     libspdm_return_t status;
+    4256                 :            :     libspdm_test_context_t    *spdm_test_context;
+    4257                 :            :     libspdm_context_t         *spdm_context;
+    4258                 :            :     uint32_t session_id;
+    4259                 :            :     libspdm_session_info_t    *session_info;
+    4260                 :            : 
+    4261                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    4262                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    4263                 :            : 
+    4264                 :          1 :     spdm_test_context = *state;
+    4265                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4266                 :          1 :     spdm_test_context->case_id = 0xC;
+    4267                 :            : 
+    4268                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4269                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4270                 :          1 :     libspdm_set_standard_key_update_test_state(
+    4271                 :            :         spdm_context, &session_id);
+    4272                 :            : 
+    4273                 :          1 :     session_info = &spdm_context->session_info[0];
+    4274                 :            : 
+    4275                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    4276                 :          1 :         session_info->secured_message_context,
+    4277                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    4278                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    4279                 :            : 
+    4280                 :            :     /*no keys are updated*/
+    4281                 :            : 
+    4282                 :          1 :     status = libspdm_key_update(
+    4283                 :            :         spdm_context, session_id, true);
+    4284                 :            : 
+    4285                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    4286                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    4287                 :            :                           *)(session_info->secured_message_context))
+    4288                 :            :                         ->application_secret.request_data_secret,
+    4289                 :            :                         m_req_secret_buffer, ((libspdm_secured_message_context_t
+    4290                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    4291                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    4292                 :            :                           *)(session_info->secured_message_context))
+    4293                 :            :                         ->application_secret.response_data_secret,
+    4294                 :            :                         m_rsp_secret_buffer, ((libspdm_secured_message_context_t
+    4295                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    4296                 :          1 : }
+    4297                 :            : 
+    4298                 :            : /**
+    4299                 :            :  * Test 14: requester is not setup correctly by not initializing a
+    4300                 :            :  * session during KEY_EXCHANGE. The responder would attempt to
+    4301                 :            :  * return a correct KEY_UPDATE_ACK message.
+    4302                 :            :  * Expected behavior: client returns a Status of RETURN_UNSUPPORTED,
+    4303                 :            :  * and no keys are updated.
+    4304                 :            :  **/
+    4305                 :          1 : void libspdm_test_requester_key_update_case14(void **state)
+    4306                 :            : {
+    4307                 :            :     libspdm_return_t status;
+    4308                 :            :     libspdm_test_context_t    *spdm_test_context;
+    4309                 :            :     libspdm_context_t         *spdm_context;
+    4310                 :            :     uint32_t session_id;
+    4311                 :            :     libspdm_session_info_t    *session_info;
+    4312                 :            : 
+    4313                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    4314                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    4315                 :            : 
+    4316                 :          1 :     spdm_test_context = *state;
+    4317                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4318                 :          1 :     spdm_test_context->case_id = 0xD;
+    4319                 :            : 
+    4320                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4321                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4322                 :          1 :     libspdm_set_standard_key_update_test_state(
+    4323                 :            :         spdm_context, &session_id);
+    4324                 :            : 
+    4325                 :          1 :     session_info = &spdm_context->session_info[0];
+    4326                 :            : 
+    4327                 :            :     /*session not initialized*/
+    4328                 :          1 :     libspdm_secured_message_set_session_state(
+    4329                 :            :         session_info->secured_message_context,
+    4330                 :            :         LIBSPDM_SESSION_STATE_NOT_STARTED);
+    4331                 :            : 
+    4332                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    4333                 :          1 :         session_info->secured_message_context,
+    4334                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    4335                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    4336                 :            : 
+    4337                 :            :     /*no keys are updated*/
+    4338                 :            : 
+    4339                 :          1 :     status = libspdm_key_update(
+    4340                 :            :         spdm_context, session_id, true);
+    4341                 :            : 
+    4342                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_STATE_LOCAL);
+    4343                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    4344                 :            :                           *)(session_info->secured_message_context))
+    4345                 :            :                         ->application_secret.request_data_secret,
+    4346                 :            :                         m_req_secret_buffer, ((libspdm_secured_message_context_t
+    4347                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    4348                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    4349                 :            :                           *)(session_info->secured_message_context))
+    4350                 :            :                         ->application_secret.response_data_secret,
+    4351                 :            :                         m_rsp_secret_buffer, ((libspdm_secured_message_context_t
+    4352                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    4353                 :          1 : }
+    4354                 :            : 
+    4355                 :            : /**
+    4356                 :            :  * Test 15: the requester is setup correctly (see Test 2), but receives a
+    4357                 :            :  * KEY_UPDATE_ACK response with the wrong token. The VERIFY_KEY behavior
+    4358                 :            :  * is not altered.
+    4359                 :            :  * Expected behavior: client returns a Status of RETURN_DEVICE_ERROR, and
+    4360                 :            :  * no keys should be updated.
+    4361                 :            :  **/
+    4362                 :          1 : void libspdm_test_requester_key_update_case15(void **state)
+    4363                 :            : {
+    4364                 :            :     libspdm_return_t status;
+    4365                 :            :     libspdm_test_context_t    *spdm_test_context;
+    4366                 :            :     libspdm_context_t         *spdm_context;
+    4367                 :            :     uint32_t session_id;
+    4368                 :            :     libspdm_session_info_t    *session_info;
+    4369                 :            : 
+    4370                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    4371                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    4372                 :            : 
+    4373                 :          1 :     spdm_test_context = *state;
+    4374                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4375                 :          1 :     spdm_test_context->case_id = 0xF;
+    4376                 :            : 
+    4377                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4378                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4379                 :          1 :     libspdm_set_standard_key_update_test_state(
+    4380                 :            :         spdm_context, &session_id);
+    4381                 :            : 
+    4382                 :          1 :     session_info = &spdm_context->session_info[0];
+    4383                 :            : 
+    4384                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    4385                 :          1 :         session_info->secured_message_context,
+    4386                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    4387                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    4388                 :            : 
+    4389                 :            :     /*no keys are updated*/
+    4390                 :            : 
+    4391                 :          1 :     status = libspdm_key_update(
+    4392                 :            :         spdm_context, session_id, true);
+    4393                 :            : 
+    4394                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    4395                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    4396                 :            :                           *)(session_info->secured_message_context))
+    4397                 :            :                         ->application_secret.request_data_secret,
+    4398                 :            :                         m_req_secret_buffer, ((libspdm_secured_message_context_t
+    4399                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    4400                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    4401                 :            :                           *)(session_info->secured_message_context))
+    4402                 :            :                         ->application_secret.response_data_secret,
+    4403                 :            :                         m_rsp_secret_buffer, ((libspdm_secured_message_context_t
+    4404                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    4405                 :          1 : }
+    4406                 :            : 
+    4407                 :            : /**
+    4408                 :            :  * Test 16: the requester is setup correctly (see Test 2), but receives a
+    4409                 :            :  * KEY_UPDATE_ACK response with the operation code. The VERIFY_KEY
+    4410                 :            :  * behavior is not altered.
+    4411                 :            :  * Expected behavior: client returns a Status of RETURN_DEVICE_ERROR, and
+    4412                 :            :  * no keys should be updated.
+    4413                 :            :  **/
+    4414                 :          1 : void libspdm_test_requester_key_update_case16(void **state)
+    4415                 :            : {
+    4416                 :            :     libspdm_return_t status;
+    4417                 :            :     libspdm_test_context_t    *spdm_test_context;
+    4418                 :            :     libspdm_context_t         *spdm_context;
+    4419                 :            :     uint32_t session_id;
+    4420                 :            :     libspdm_session_info_t    *session_info;
+    4421                 :            : 
+    4422                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    4423                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    4424                 :            : 
+    4425                 :          1 :     spdm_test_context = *state;
+    4426                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4427                 :          1 :     spdm_test_context->case_id = 0x10;
+    4428                 :            : 
+    4429                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4430                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4431                 :          1 :     libspdm_set_standard_key_update_test_state(
+    4432                 :            :         spdm_context, &session_id);
+    4433                 :            : 
+    4434                 :          1 :     session_info = &spdm_context->session_info[0];
+    4435                 :            : 
+    4436                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    4437                 :          1 :         session_info->secured_message_context,
+    4438                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    4439                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    4440                 :            : 
+    4441                 :            :     /*no keys are updated*/
+    4442                 :            : 
+    4443                 :          1 :     status = libspdm_key_update(
+    4444                 :            :         spdm_context, session_id, true);
+    4445                 :            : 
+    4446                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    4447                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    4448                 :            :                           *)(session_info->secured_message_context))
+    4449                 :            :                         ->application_secret.request_data_secret,
+    4450                 :            :                         m_req_secret_buffer, ((libspdm_secured_message_context_t
+    4451                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    4452                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    4453                 :            :                           *)(session_info->secured_message_context))
+    4454                 :            :                         ->application_secret.response_data_secret,
+    4455                 :            :                         m_rsp_secret_buffer, ((libspdm_secured_message_context_t
+    4456                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    4457                 :          1 : }
+    4458                 :            : 
+    4459                 :            : /**
+    4460                 :            :  * Test 17: the requester is setup correctly (see Test 2), but receives an
+    4461                 :            :  * ERROR message indicating InvalidParameters when verifying key.
+    4462                 :            :  * Expected behavior: client returns a Status of RETURN_DEVICE_ERROR, the
+    4463                 :            :  * request data key is not rollbacked.
+    4464                 :            :  **/
+    4465                 :          1 : void libspdm_test_requester_key_update_case17(void **state)
+    4466                 :            : {
+    4467                 :            :     libspdm_return_t status;
+    4468                 :            :     libspdm_test_context_t    *spdm_test_context;
+    4469                 :            :     libspdm_context_t         *spdm_context;
+    4470                 :            :     uint32_t session_id;
+    4471                 :            :     libspdm_session_info_t    *session_info;
+    4472                 :            : 
+    4473                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    4474                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    4475                 :            : 
+    4476                 :          1 :     spdm_test_context = *state;
+    4477                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4478                 :          1 :     spdm_test_context->case_id = 0x11;
+    4479                 :            : 
+    4480                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4481                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4482                 :          1 :     libspdm_set_standard_key_update_test_state(spdm_context, &session_id);
+    4483                 :            : 
+    4484                 :          1 :     session_info = &spdm_context->session_info[0];
+    4485                 :            : 
+    4486                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    4487                 :          1 :         session_info->secured_message_context,
+    4488                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    4489                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    4490                 :            : 
+    4491                 :            :     /*request side updated*/
+    4492                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    4493                 :            :                                   ((libspdm_secured_message_context_t
+    4494                 :          1 :                                     *)(session_info->secured_message_context))->hash_size,
+    4495                 :            :                                   m_req_secret_buffer, m_req_secret_buffer,
+    4496                 :            :                                   sizeof(m_req_secret_buffer));
+    4497                 :            :     /*response side *not* updated*/
+    4498                 :            : 
+    4499                 :          1 :     status = libspdm_key_update(spdm_context, session_id, true);
+    4500                 :            : 
+    4501                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_ERROR_PEER);
+    4502                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    4503                 :            :                           *)(session_info->secured_message_context))
+    4504                 :            :                         ->application_secret.request_data_secret,
+    4505                 :            :                         m_req_secret_buffer, ((libspdm_secured_message_context_t
+    4506                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    4507                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    4508                 :            :                           *)(session_info->secured_message_context))
+    4509                 :            :                         ->application_secret.response_data_secret,
+    4510                 :            :                         m_rsp_secret_buffer, ((libspdm_secured_message_context_t
+    4511                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    4512                 :          1 : }
+    4513                 :            : 
+    4514                 :            : /**
+    4515                 :            :  * Test 18: the requester is setup correctly (see Test 2), but receives an
+    4516                 :            :  * ERROR message indicating the Busy status of the responder, when verifying
+    4517                 :            :  * key.
+    4518                 :            :  * Expected behavior: client returns a Status of RETURN_NO_RESPONSE, the
+    4519                 :            :  * request data key is not rollbacked.
+    4520                 :            :  **/
+    4521                 :          1 : void libspdm_test_requester_key_update_case18(void **state)
+    4522                 :            : {
+    4523                 :            :     libspdm_return_t status;
+    4524                 :            :     libspdm_test_context_t    *spdm_test_context;
+    4525                 :            :     libspdm_context_t         *spdm_context;
+    4526                 :            :     uint32_t session_id;
+    4527                 :            :     libspdm_session_info_t    *session_info;
+    4528                 :            : 
+    4529                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    4530                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    4531                 :            : 
+    4532                 :          1 :     spdm_test_context = *state;
+    4533                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4534                 :          1 :     spdm_test_context->case_id = 0x12;
+    4535                 :            : 
+    4536                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4537                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4538                 :          1 :     libspdm_set_standard_key_update_test_state(
+    4539                 :            :         spdm_context, &session_id);
+    4540                 :            : 
+    4541                 :          1 :     session_info = &spdm_context->session_info[0];
+    4542                 :            : 
+    4543                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    4544                 :          1 :         session_info->secured_message_context,
+    4545                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    4546                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    4547                 :            : 
+    4548                 :            :     /*request side updated*/
+    4549                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    4550                 :            :                                   ((libspdm_secured_message_context_t
+    4551                 :          1 :                                     *)(session_info->secured_message_context))->hash_size,
+    4552                 :            :                                   m_req_secret_buffer, m_req_secret_buffer,
+    4553                 :            :                                   sizeof(m_req_secret_buffer));
+    4554                 :            :     /*response side *not* updated*/
+    4555                 :            : 
+    4556                 :          1 :     status = libspdm_key_update(
+    4557                 :            :         spdm_context, session_id, true);
+    4558                 :            : 
+    4559                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_BUSY_PEER);
+    4560                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    4561                 :            :                           *)(session_info->secured_message_context))
+    4562                 :            :                         ->application_secret.request_data_secret,
+    4563                 :            :                         m_req_secret_buffer, ((libspdm_secured_message_context_t
+    4564                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    4565                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    4566                 :            :                           *)(session_info->secured_message_context))
+    4567                 :            :                         ->application_secret.response_data_secret,
+    4568                 :            :                         m_rsp_secret_buffer, ((libspdm_secured_message_context_t
+    4569                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    4570                 :          1 : }
+    4571                 :            : 
+    4572                 :            : /**
+    4573                 :            :  * Test 19: the requester is setup correctly (see Test 2), but, when
+    4574                 :            :  * verifying key, on the first try, receiving a Busy ERROR message,
+    4575                 :            :  * and on retry, receiving a correct KEY_UPDATE_ACK message. The
+    4576                 :            :  * VERIFY_KEY behavior is not altered.
+    4577                 :            :  * Expected behavior: client returns a Status of RETURN_SUCCESS, the
+    4578                 :            :  * request data key is not rollbacked.
+    4579                 :            :  **/
+    4580                 :          1 : void libspdm_test_requester_key_update_case19(void **state)
+    4581                 :            : {
+    4582                 :            :     libspdm_return_t status;
+    4583                 :            :     libspdm_test_context_t    *spdm_test_context;
+    4584                 :            :     libspdm_context_t         *spdm_context;
+    4585                 :            :     uint32_t session_id;
+    4586                 :            :     libspdm_session_info_t    *session_info;
+    4587                 :            : 
+    4588                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    4589                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    4590                 :            : 
+    4591                 :          1 :     spdm_test_context = *state;
+    4592                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4593                 :          1 :     spdm_test_context->case_id = 0x13;
+    4594                 :            : 
+    4595                 :          1 :     spdm_context->retry_times = 3;
+    4596                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4597                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4598                 :          1 :     libspdm_set_standard_key_update_test_state(
+    4599                 :            :         spdm_context, &session_id);
+    4600                 :            : 
+    4601                 :          1 :     session_info = &spdm_context->session_info[0];
+    4602                 :            : 
+    4603                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    4604                 :          1 :         session_info->secured_message_context,
+    4605                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    4606                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    4607                 :            : 
+    4608                 :            :     /*request side updated*/
+    4609                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    4610                 :            :                                   ((libspdm_secured_message_context_t
+    4611                 :          1 :                                     *)(session_info->secured_message_context))->hash_size,
+    4612                 :            :                                   m_req_secret_buffer, m_req_secret_buffer,
+    4613                 :            :                                   sizeof(m_req_secret_buffer));
+    4614                 :            :     /*response side *not* updated*/
+    4615                 :            : 
+    4616                 :          1 :     status = libspdm_key_update(
+    4617                 :            :         spdm_context, session_id, true);
+    4618                 :            : 
+    4619                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    4620                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    4621                 :            :                           *)(session_info->secured_message_context))
+    4622                 :            :                         ->application_secret.request_data_secret,
+    4623                 :            :                         m_req_secret_buffer, ((libspdm_secured_message_context_t
+    4624                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    4625                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    4626                 :            :                           *)(session_info->secured_message_context))
+    4627                 :            :                         ->application_secret.response_data_secret,
+    4628                 :            :                         m_rsp_secret_buffer, ((libspdm_secured_message_context_t
+    4629                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    4630                 :          1 : }
+    4631                 :            : 
+    4632                 :            : /**
+    4633                 :            :  * Test 20: the requester is setup correctly (see Test 2), but receives an
+    4634                 :            :  * ERROR message indicating the RequestResynch status of the responder, when
+    4635                 :            :  * verifying key.
+    4636                 :            :  * Expected behavior: client returns a Status of RETURN_DEVICE_ERROR, and the
+    4637                 :            :  * communication is reset to expect a new GET_VERSION message.
+    4638                 :            :  **/
+    4639                 :          1 : void libspdm_test_requester_key_update_case20(void **state)
+    4640                 :            : {
+    4641                 :            :     libspdm_return_t status;
+    4642                 :            :     libspdm_test_context_t    *spdm_test_context;
+    4643                 :            :     libspdm_context_t         *spdm_context;
+    4644                 :            :     uint32_t session_id;
+    4645                 :            :     libspdm_session_info_t    *session_info;
+    4646                 :            : 
+    4647                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    4648                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    4649                 :            : 
+    4650                 :          1 :     spdm_test_context = *state;
+    4651                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4652                 :          1 :     spdm_test_context->case_id = 0x14;
+    4653                 :            : 
+    4654                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4655                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4656                 :          1 :     libspdm_set_standard_key_update_test_state(
+    4657                 :            :         spdm_context, &session_id);
+    4658                 :            : 
+    4659                 :          1 :     session_info = &spdm_context->session_info[0];
+    4660                 :            : 
+    4661                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    4662                 :          1 :         session_info->secured_message_context,
+    4663                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    4664                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    4665                 :            : 
+    4666                 :          1 :     status = libspdm_key_update(
+    4667                 :            :         spdm_context, session_id, true);
+    4668                 :            : 
+    4669                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_RESYNCH_PEER);
+    4670                 :          1 :     assert_int_equal(spdm_context->connection_info.connection_state,
+    4671                 :            :                      LIBSPDM_CONNECTION_STATE_NOT_STARTED);
+    4672                 :          1 : }
+    4673                 :            : 
+    4674                 :            : /**
+    4675                 :            :  * Test 21: the requester is setup correctly (see Test 2), but receives an
+    4676                 :            :  * ERROR message indicating the ResponseNotReady status of the responder, when
+    4677                 :            :  * verifying key.
+    4678                 :            :  * Expected behavior: client returns a Status of RETURN_DEVICE_ERROR, the
+    4679                 :            :  * request data key is not rollbacked.
+    4680                 :            :  **/
+    4681                 :          1 : void libspdm_test_requester_key_update_case21(void **state)
+    4682                 :            : {
+    4683                 :            :     libspdm_return_t status;
+    4684                 :            :     libspdm_test_context_t    *spdm_test_context;
+    4685                 :            :     libspdm_context_t         *spdm_context;
+    4686                 :            :     uint32_t session_id;
+    4687                 :            :     libspdm_session_info_t    *session_info;
+    4688                 :            : 
+    4689                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    4690                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    4691                 :            : 
+    4692                 :          1 :     spdm_test_context = *state;
+    4693                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4694                 :          1 :     spdm_test_context->case_id = 0x15;
+    4695                 :            : 
+    4696                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4697                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4698                 :          1 :     libspdm_set_standard_key_update_test_state(
+    4699                 :            :         spdm_context, &session_id);
+    4700                 :            : 
+    4701                 :          1 :     session_info = &spdm_context->session_info[0];
+    4702                 :            : 
+    4703                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    4704                 :          1 :         session_info->secured_message_context,
+    4705                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    4706                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    4707                 :            : 
+    4708                 :            :     /*request side updated*/
+    4709                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    4710                 :            :                                   ((libspdm_secured_message_context_t
+    4711                 :          1 :                                     *)(session_info->secured_message_context))->hash_size,
+    4712                 :            :                                   m_req_secret_buffer, m_req_secret_buffer,
+    4713                 :            :                                   sizeof(m_req_secret_buffer));
+    4714                 :            :     /*response side *not* updated*/
+    4715                 :            : 
+    4716                 :          1 :     status = libspdm_key_update(
+    4717                 :            :         spdm_context, session_id, true);
+    4718                 :            : 
+    4719                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_NOT_READY_PEER);
+    4720                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    4721                 :            :                           *)(session_info->secured_message_context))
+    4722                 :            :                         ->application_secret.request_data_secret,
+    4723                 :            :                         m_req_secret_buffer, ((libspdm_secured_message_context_t
+    4724                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    4725                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    4726                 :            :                           *)(session_info->secured_message_context))
+    4727                 :            :                         ->application_secret.response_data_secret,
+    4728                 :            :                         m_rsp_secret_buffer, ((libspdm_secured_message_context_t
+    4729                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    4730                 :          1 : }
+    4731                 :            : 
+    4732                 :            : /**
+    4733                 :            :  * Test 22: the requester is setup correctly (see Test 2), but, when verifying
+    4734                 :            :  * key, on the first try, receiving a ResponseNotReady ERROR message, and on
+    4735                 :            :  * retry, receiving a correct KEY_UPDATE_ACK message.
+    4736                 :            :  * Expected behavior: client returns a Status of RETURN_SUCCESS, the
+    4737                 :            :  * request data key is not rollbacked.
+    4738                 :            :  **/
+    4739                 :          1 : void libspdm_test_requester_key_update_case22(void **state)
+    4740                 :            : {
+    4741                 :            :     libspdm_return_t status;
+    4742                 :            :     libspdm_test_context_t    *spdm_test_context;
+    4743                 :            :     libspdm_context_t         *spdm_context;
+    4744                 :            :     uint32_t session_id;
+    4745                 :            :     libspdm_session_info_t    *session_info;
+    4746                 :            : 
+    4747                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    4748                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    4749                 :            : 
+    4750                 :          1 :     spdm_test_context = *state;
+    4751                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4752                 :          1 :     spdm_test_context->case_id = 0x16;
+    4753                 :            : 
+    4754                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4755                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4756                 :          1 :     libspdm_set_standard_key_update_test_state(
+    4757                 :            :         spdm_context, &session_id);
+    4758                 :            : 
+    4759                 :          1 :     session_info = &spdm_context->session_info[0];
+    4760                 :            : 
+    4761                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    4762                 :          1 :         session_info->secured_message_context,
+    4763                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    4764                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    4765                 :            : 
+    4766                 :            :     /*request side updated*/
+    4767                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    4768                 :            :                                   ((libspdm_secured_message_context_t
+    4769                 :          1 :                                     *)(session_info->secured_message_context))->hash_size,
+    4770                 :            :                                   m_req_secret_buffer, m_req_secret_buffer,
+    4771                 :            :                                   sizeof(m_req_secret_buffer));
+    4772                 :            :     /*response side *not* updated*/
+    4773                 :            : 
+    4774                 :          1 :     status = libspdm_key_update(spdm_context, session_id, true);
+    4775                 :            : 
+    4776                 :            :     if (LIBSPDM_RESPOND_IF_READY_SUPPORT) {
+    4777                 :          1 :         assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    4778                 :          1 :         assert_memory_equal(((libspdm_secured_message_context_t
+    4779                 :            :                               *)(session_info->secured_message_context))
+    4780                 :            :                             ->application_secret.request_data_secret,
+    4781                 :            :                             m_req_secret_buffer, ((libspdm_secured_message_context_t
+    4782                 :            :                                                    *)(session_info->secured_message_context))->hash_size);
+    4783                 :          1 :         assert_memory_equal(((libspdm_secured_message_context_t
+    4784                 :            :                               *)(session_info->secured_message_context))
+    4785                 :            :                             ->application_secret.response_data_secret,
+    4786                 :            :                             m_rsp_secret_buffer, ((libspdm_secured_message_context_t
+    4787                 :            :                                                    *)(session_info->secured_message_context))->hash_size);
+    4788                 :            :     } else {
+    4789                 :            :         assert_int_equal(status, LIBSPDM_STATUS_NOT_READY_PEER);
+    4790                 :            :     }
+    4791                 :          1 : }
+    4792                 :            : 
+    4793                 :            : /**
+    4794                 :            :  * Test 23: receiving an unexpected ERROR message from the responder,
+    4795                 :            :  * when verifying key.
+    4796                 :            :  * There are tests for all named codes, including some reserved ones
+    4797                 :            :  * (namely, 0x00, 0x0b, 0x0c, 0x3f, 0xfd, 0xfe).
+    4798                 :            :  * However, for having specific test cases, it is excluded from this case:
+    4799                 :            :  * Busy (0x03), ResponseNotReady (0x42), and RequestResync (0x43).
+    4800                 :            :  * Expected behavior: client returns a status of RETURN_DEVICE_ERROR, the
+    4801                 :            :  * request data key is not rollbacked.
+    4802                 :            :  **/
+    4803                 :          1 : void libspdm_test_requester_key_update_case23(void **state)
+    4804                 :            : {
+    4805                 :            :     libspdm_return_t status;
+    4806                 :            :     libspdm_test_context_t    *spdm_test_context;
+    4807                 :            :     libspdm_context_t         *spdm_context;
+    4808                 :            :     uint32_t session_id;
+    4809                 :            :     libspdm_session_info_t    *session_info;
+    4810                 :            :     uint16_t error_code;
+    4811                 :            : 
+    4812                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    4813                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    4814                 :            : 
+    4815                 :          1 :     spdm_test_context = *state;
+    4816                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4817                 :          1 :     spdm_test_context->case_id = 0x17;
+    4818                 :            : 
+    4819                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4820                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4821                 :          1 :     libspdm_set_standard_key_update_test_state(
+    4822                 :            :         spdm_context, &session_id);
+    4823                 :            : 
+    4824                 :          1 :     session_info = &spdm_context->session_info[0];
+    4825                 :            : 
+    4826                 :          1 :     error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
+    4827         [ +  + ]:         18 :     while(error_code <= 0xff) {
+    4828                 :            :         /* skip SPDM_ERROR_CODE_DECRYPT_ERROR, because this case will free context*/
+    4829         [ +  + ]:         17 :         if(error_code == SPDM_ERROR_CODE_DECRYPT_ERROR) {
+    4830                 :          1 :             error_code++;
+    4831                 :            :         }
+    4832                 :         17 :         libspdm_set_standard_key_update_test_secrets(
+    4833                 :         17 :             session_info->secured_message_context,
+    4834                 :            :             m_rsp_secret_buffer, (uint8_t)(0xFF),
+    4835                 :            :             m_req_secret_buffer, (uint8_t)(0xEE));
+    4836                 :            : 
+    4837                 :            :         /*request side updated*/
+    4838                 :         17 :         libspdm_compute_secret_update(spdm_context->connection_info.version,
+    4839                 :            :                                       ((libspdm_secured_message_context_t
+    4840                 :         17 :                                         *)(session_info->secured_message_context))->hash_size,
+    4841                 :            :                                       m_req_secret_buffer, m_req_secret_buffer,
+    4842                 :            :                                       sizeof(m_req_secret_buffer));
+    4843                 :            :         /*response side *not* updated*/
+    4844                 :            : 
+    4845                 :         17 :         status = libspdm_key_update(
+    4846                 :            :             spdm_context, session_id, true);
+    4847                 :            : 
+    4848         [ -  + ]:         17 :         LIBSPDM_ASSERT_INT_EQUAL_CASE (status, LIBSPDM_STATUS_ERROR_PEER, error_code);
+    4849                 :         17 :         assert_memory_equal(((libspdm_secured_message_context_t
+    4850                 :            :                               *)(session_info->secured_message_context))
+    4851                 :            :                             ->application_secret.request_data_secret,
+    4852                 :            :                             m_req_secret_buffer, ((libspdm_secured_message_context_t
+    4853                 :            :                                                    *)(session_info->secured_message_context))->hash_size);
+    4854                 :         17 :         assert_memory_equal(((libspdm_secured_message_context_t
+    4855                 :            :                               *)(session_info->secured_message_context))
+    4856                 :            :                             ->application_secret.response_data_secret,
+    4857                 :            :                             m_rsp_secret_buffer, ((libspdm_secured_message_context_t
+    4858                 :            :                                                    *)(session_info->secured_message_context))->hash_size);
+    4859                 :            : 
+    4860                 :         17 :         error_code++;
+    4861                 :            :         /*busy is treated in cases 5 and 6*/
+    4862         [ +  + ]:         17 :         if(error_code == SPDM_ERROR_CODE_BUSY) {
+    4863                 :          1 :             error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
+    4864                 :            :         }
+    4865                 :            :         /*skip some reserved error codes (0d to 3e)*/
+    4866         [ +  + ]:         17 :         if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) {
+    4867                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
+    4868                 :            :         }
+    4869                 :            :         /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
+    4870         [ +  + ]:         17 :         if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) {
+    4871                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
+    4872                 :            :         }
+    4873                 :            :     }
+    4874                 :          1 : }
+    4875                 :            : 
+    4876                 :            : /**
+    4877                 :            :  * Test 24: receiving an incorrect KEY_UPDATE_ACK message, with wrong
+    4878                 :            :  * response code, but all other field correct, when verifying key.
+    4879                 :            :  * Expected behavior: client returns a Status of RETURN_DEVICE_ERROR, the
+    4880                 :            :  * request data key is not rollbacked.
+    4881                 :            :  **/
+    4882                 :          1 : void libspdm_test_requester_key_update_case24(void **state)
+    4883                 :            : {
+    4884                 :            :     libspdm_return_t status;
+    4885                 :            :     libspdm_test_context_t    *spdm_test_context;
+    4886                 :            :     libspdm_context_t         *spdm_context;
+    4887                 :            :     uint32_t session_id;
+    4888                 :            :     libspdm_session_info_t    *session_info;
+    4889                 :            : 
+    4890                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    4891                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    4892                 :            : 
+    4893                 :          1 :     spdm_test_context = *state;
+    4894                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4895                 :          1 :     spdm_test_context->case_id = 0x18;
+    4896                 :            : 
+    4897                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4898                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4899                 :          1 :     libspdm_set_standard_key_update_test_state(
+    4900                 :            :         spdm_context, &session_id);
+    4901                 :            : 
+    4902                 :          1 :     session_info = &spdm_context->session_info[0];
+    4903                 :            : 
+    4904                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    4905                 :          1 :         session_info->secured_message_context,
+    4906                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    4907                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    4908                 :            : 
+    4909                 :            :     /*request side updated*/
+    4910                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    4911                 :            :                                   ((libspdm_secured_message_context_t
+    4912                 :          1 :                                     *)(session_info->secured_message_context))->hash_size,
+    4913                 :            :                                   m_req_secret_buffer, m_req_secret_buffer,
+    4914                 :            :                                   sizeof(m_req_secret_buffer));
+    4915                 :            :     /*response side *not* updated*/
+    4916                 :            : 
+    4917                 :          1 :     status = libspdm_key_update(
+    4918                 :            :         spdm_context, session_id, true);
+    4919                 :            : 
+    4920                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    4921                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    4922                 :            :                           *)(session_info->secured_message_context))
+    4923                 :            :                         ->application_secret.request_data_secret,
+    4924                 :            :                         m_req_secret_buffer, ((libspdm_secured_message_context_t
+    4925                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    4926                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    4927                 :            :                           *)(session_info->secured_message_context))
+    4928                 :            :                         ->application_secret.response_data_secret,
+    4929                 :            :                         m_rsp_secret_buffer, ((libspdm_secured_message_context_t
+    4930                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    4931                 :          1 : }
+    4932                 :            : 
+    4933                 :            : /**
+    4934                 :            :  * Test 25: the requester is setup correctly (see Test 2), and receives a
+    4935                 :            :  * correct KEY_UPDATE_ACK to update key. However, it receives a
+    4936                 :            :  * KEY_UPDATE_ACK response with the wrong token to verify the key.
+    4937                 :            :  * Expected behavior: client returns a Status of RETURN_DEVICE_ERROR, the
+    4938                 :            :  * request data key is not rollbacked.
+    4939                 :            :  **/
+    4940                 :          1 : void libspdm_test_requester_key_update_case25(void **state)
+    4941                 :            : {
+    4942                 :            :     libspdm_return_t status;
+    4943                 :            :     libspdm_test_context_t    *spdm_test_context;
+    4944                 :            :     libspdm_context_t         *spdm_context;
+    4945                 :            :     uint32_t session_id;
+    4946                 :            :     libspdm_session_info_t    *session_info;
+    4947                 :            : 
+    4948                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    4949                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    4950                 :            : 
+    4951                 :          1 :     spdm_test_context = *state;
+    4952                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4953                 :          1 :     spdm_test_context->case_id = 0x19;
+    4954                 :            : 
+    4955                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4956                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4957                 :          1 :     libspdm_set_standard_key_update_test_state(
+    4958                 :            :         spdm_context, &session_id);
+    4959                 :            : 
+    4960                 :          1 :     session_info = &spdm_context->session_info[0];
+    4961                 :            : 
+    4962                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    4963                 :          1 :         session_info->secured_message_context,
+    4964                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    4965                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    4966                 :            : 
+    4967                 :            :     /*request side updated*/
+    4968                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    4969                 :            :                                   ((libspdm_secured_message_context_t
+    4970                 :          1 :                                     *)(session_info->secured_message_context))->hash_size,
+    4971                 :            :                                   m_req_secret_buffer, m_req_secret_buffer,
+    4972                 :            :                                   sizeof(m_req_secret_buffer));
+    4973                 :            :     /*response side *not* updated*/
+    4974                 :            : 
+    4975                 :          1 :     status = libspdm_key_update(
+    4976                 :            :         spdm_context, session_id, true);
+    4977                 :            : 
+    4978                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    4979                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    4980                 :            :                           *)(session_info->secured_message_context))
+    4981                 :            :                         ->application_secret.request_data_secret,
+    4982                 :            :                         m_req_secret_buffer, ((libspdm_secured_message_context_t
+    4983                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    4984                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    4985                 :            :                           *)(session_info->secured_message_context))
+    4986                 :            :                         ->application_secret.response_data_secret,
+    4987                 :            :                         m_rsp_secret_buffer, ((libspdm_secured_message_context_t
+    4988                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    4989                 :          1 : }
+    4990                 :            : 
+    4991                 :            : /**
+    4992                 :            :  * Test 26: the requester is setup correctly (see Test 2) and receives a
+    4993                 :            :  * correct KEY_UPDATE_ACK to update key. However, it receives a
+    4994                 :            :  * KEY_UPDATE_ACK response with the wrong operation code to verify the key.
+    4995                 :            :  * Expected behavior: client returns a Status of RETURN_DEVICE_ERROR, the
+    4996                 :            :  * request data key is not rollbacked.
+    4997                 :            :  **/
+    4998                 :          1 : void libspdm_test_requester_key_update_case26(void **state)
+    4999                 :            : {
+    5000                 :            :     libspdm_return_t status;
+    5001                 :            :     libspdm_test_context_t    *spdm_test_context;
+    5002                 :            :     libspdm_context_t         *spdm_context;
+    5003                 :            :     uint32_t session_id;
+    5004                 :            :     libspdm_session_info_t    *session_info;
+    5005                 :            : 
+    5006                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    5007                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    5008                 :            : 
+    5009                 :          1 :     spdm_test_context = *state;
+    5010                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5011                 :          1 :     spdm_test_context->case_id = 0x1A;
+    5012                 :            : 
+    5013                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5014                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5015                 :          1 :     libspdm_set_standard_key_update_test_state(
+    5016                 :            :         spdm_context, &session_id);
+    5017                 :            : 
+    5018                 :          1 :     session_info = &spdm_context->session_info[0];
+    5019                 :            : 
+    5020                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    5021                 :          1 :         session_info->secured_message_context,
+    5022                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    5023                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    5024                 :            : 
+    5025                 :            :     /*request side updated*/
+    5026                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    5027                 :            :                                   ((libspdm_secured_message_context_t
+    5028                 :          1 :                                     *)(session_info->secured_message_context))->hash_size,
+    5029                 :            :                                   m_req_secret_buffer, m_req_secret_buffer,
+    5030                 :            :                                   sizeof(m_req_secret_buffer));
+    5031                 :            :     /*response side *not* updated*/
+    5032                 :            : 
+    5033                 :          1 :     status = libspdm_key_update(
+    5034                 :            :         spdm_context, session_id, true);
+    5035                 :            : 
+    5036                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    5037                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    5038                 :            :                           *)(session_info->secured_message_context))
+    5039                 :            :                         ->application_secret.request_data_secret,
+    5040                 :            :                         m_req_secret_buffer, ((libspdm_secured_message_context_t
+    5041                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    5042                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    5043                 :            :                           *)(session_info->secured_message_context))
+    5044                 :            :                         ->application_secret.response_data_secret,
+    5045                 :            :                         m_rsp_secret_buffer, ((libspdm_secured_message_context_t
+    5046                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    5047                 :          1 : }
+    5048                 :            : 
+    5049                 :            : /**
+    5050                 :            :  * Test 27: receiving a correct UPDATE_KEY_ACK message for updating
+    5051                 :            :  * both the request data key and the response data key.
+    5052                 :            :  * Expected behavior: client returns a Status of RETURN_SUCCESS, and
+    5053                 :            :  * the request data key and response data key are updated.
+    5054                 :            :  **/
+    5055                 :          1 : void libspdm_test_requester_key_update_case27(void **state)
+    5056                 :            : {
+    5057                 :            :     libspdm_return_t status;
+    5058                 :            :     libspdm_test_context_t    *spdm_test_context;
+    5059                 :            :     libspdm_context_t         *spdm_context;
+    5060                 :            :     uint32_t session_id;
+    5061                 :            :     libspdm_session_info_t    *session_info;
+    5062                 :            : 
+    5063                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    5064                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    5065                 :            : 
+    5066                 :          1 :     spdm_test_context = *state;
+    5067                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5068                 :          1 :     spdm_test_context->case_id = 0x1B;
+    5069                 :            : 
+    5070                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5071                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5072                 :          1 :     libspdm_set_standard_key_update_test_state(
+    5073                 :            :         spdm_context, &session_id);
+    5074                 :            : 
+    5075                 :          1 :     session_info = &spdm_context->session_info[0];
+    5076                 :            : 
+    5077                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    5078                 :          1 :         session_info->secured_message_context,
+    5079                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    5080                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    5081                 :            : 
+    5082                 :            :     /*request side updated*/
+    5083                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    5084                 :            :                                   ((libspdm_secured_message_context_t
+    5085                 :          1 :                                     *)(session_info->secured_message_context))->hash_size,
+    5086                 :            :                                   m_req_secret_buffer, m_req_secret_buffer,
+    5087                 :            :                                   sizeof(m_req_secret_buffer));
+    5088                 :            :     /*response side updated*/
+    5089                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    5090                 :            :                                   ((libspdm_secured_message_context_t
+    5091                 :          1 :                                     *)(session_info->secured_message_context))->hash_size,
+    5092                 :            :                                   m_rsp_secret_buffer, m_rsp_secret_buffer,
+    5093                 :            :                                   sizeof(m_rsp_secret_buffer));
+    5094                 :            : 
+    5095                 :          1 :     status = libspdm_key_update(
+    5096                 :            :         spdm_context, session_id, false);
+    5097                 :            : 
+    5098                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    5099                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    5100                 :            :                           *)(session_info->secured_message_context))
+    5101                 :            :                         ->application_secret.request_data_secret,
+    5102                 :            :                         m_req_secret_buffer, ((libspdm_secured_message_context_t
+    5103                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    5104                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    5105                 :            :                           *)(session_info->secured_message_context))
+    5106                 :            :                         ->application_secret.response_data_secret,
+    5107                 :            :                         m_rsp_secret_buffer, ((libspdm_secured_message_context_t
+    5108                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    5109                 :          1 : }
+    5110                 :            : 
+    5111                 :            : /**
+    5112                 :            :  * Test 28: the requester is setup correctly (see Test 27), but receives an
+    5113                 :            :  * ERROR message indicating InvalidParameters when updating all keys.
+    5114                 :            :  * Expected behavior: client returns a Status of RETURN_DEVICE_ERROR, and
+    5115                 :            :  * no keys should be updated.
+    5116                 :            :  **/
+    5117                 :          1 : void libspdm_test_requester_key_update_case28(void **state)
+    5118                 :            : {
+    5119                 :            :     libspdm_return_t status;
+    5120                 :            :     libspdm_test_context_t    *spdm_test_context;
+    5121                 :            :     libspdm_context_t         *spdm_context;
+    5122                 :            :     uint32_t session_id;
+    5123                 :            :     libspdm_session_info_t    *session_info;
+    5124                 :            : 
+    5125                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    5126                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    5127                 :            : 
+    5128                 :            :     libspdm_secured_message_context_t *secured_message_context;
+    5129                 :            : 
+    5130                 :          1 :     spdm_test_context = *state;
+    5131                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5132                 :          1 :     spdm_test_context->case_id = 0x1C;
+    5133                 :            : 
+    5134                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5135                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5136                 :          1 :     libspdm_set_standard_key_update_test_state(
+    5137                 :            :         spdm_context, &session_id);
+    5138                 :            : 
+    5139                 :          1 :     session_info = &spdm_context->session_info[0];
+    5140                 :          1 :     secured_message_context = session_info->secured_message_context;
+    5141                 :            : 
+    5142                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    5143                 :          1 :         session_info->secured_message_context,
+    5144                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    5145                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    5146                 :            : 
+    5147                 :            :     /*store previous encryption state*/
+    5148                 :          1 :     libspdm_copy_mem(m_libspdm_last_rsp_enc_key, sizeof(m_libspdm_last_rsp_enc_key),
+    5149                 :            :                      secured_message_context
+    5150                 :          1 :                      ->application_secret.response_data_encryption_key,
+    5151                 :            :                      secured_message_context->aead_key_size);
+    5152                 :          1 :     libspdm_copy_mem(m_libspdm_last_rsp_salt, sizeof(m_libspdm_last_rsp_salt),
+    5153                 :            :                      secured_message_context
+    5154                 :          1 :                      ->application_secret.response_data_salt,
+    5155                 :            :                      secured_message_context->aead_iv_size);
+    5156                 :          1 :     m_libspdm_last_rsp_sequence_number = secured_message_context
+    5157                 :          1 :                                          ->application_secret.response_data_sequence_number;
+    5158                 :            : 
+    5159                 :            :     /*no keys are updated*/
+    5160                 :            : 
+    5161                 :          1 :     status = libspdm_key_update(
+    5162                 :            :         spdm_context, session_id, false);
+    5163                 :            : 
+    5164                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_ERROR_PEER);
+    5165                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    5166                 :            :                           *)(session_info->secured_message_context))
+    5167                 :            :                         ->application_secret.request_data_secret,
+    5168                 :            :                         m_req_secret_buffer, ((libspdm_secured_message_context_t
+    5169                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    5170                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    5171                 :            :                           *)(session_info->secured_message_context))
+    5172                 :            :                         ->application_secret.response_data_secret,
+    5173                 :            :                         m_rsp_secret_buffer, ((libspdm_secured_message_context_t
+    5174                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    5175                 :          1 : }
+    5176                 :            : 
+    5177                 :            : /**
+    5178                 :            :  * Test 29: the requester is setup correctly (see Test 27), but receives an
+    5179                 :            :  * ERROR message indicating the Busy status of the responder, when updating
+    5180                 :            :  * all keys.
+    5181                 :            :  * Expected behavior: client returns a Status of RETURN_NO_RESPONSE, and
+    5182                 :            :  * no keys should be updated.
+    5183                 :            :  **/
+    5184                 :          1 : void libspdm_test_requester_key_update_case29(void **state)
+    5185                 :            : {
+    5186                 :            :     libspdm_return_t status;
+    5187                 :            :     libspdm_test_context_t    *spdm_test_context;
+    5188                 :            :     libspdm_context_t         *spdm_context;
+    5189                 :            :     uint32_t session_id;
+    5190                 :            :     libspdm_session_info_t    *session_info;
+    5191                 :            : 
+    5192                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    5193                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    5194                 :            : 
+    5195                 :            :     libspdm_secured_message_context_t *secured_message_context;
+    5196                 :            : 
+    5197                 :          1 :     spdm_test_context = *state;
+    5198                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5199                 :          1 :     spdm_test_context->case_id = 0x1D;
+    5200                 :            : 
+    5201                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5202                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5203                 :          1 :     libspdm_set_standard_key_update_test_state(
+    5204                 :            :         spdm_context, &session_id);
+    5205                 :            : 
+    5206                 :          1 :     session_info = &spdm_context->session_info[0];
+    5207                 :          1 :     secured_message_context = session_info->secured_message_context;
+    5208                 :            : 
+    5209                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    5210                 :          1 :         session_info->secured_message_context,
+    5211                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    5212                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    5213                 :            : 
+    5214                 :            :     /*store previous encryption state*/
+    5215                 :          1 :     libspdm_copy_mem(m_libspdm_last_rsp_enc_key, sizeof(m_libspdm_last_rsp_enc_key),
+    5216                 :            :                      secured_message_context
+    5217                 :          1 :                      ->application_secret.response_data_encryption_key,
+    5218                 :            :                      secured_message_context->aead_key_size);
+    5219                 :          1 :     libspdm_copy_mem(m_libspdm_last_rsp_salt, sizeof(m_libspdm_last_rsp_salt),
+    5220                 :            :                      secured_message_context
+    5221                 :          1 :                      ->application_secret.response_data_salt,
+    5222                 :            :                      secured_message_context->aead_iv_size);
+    5223                 :          1 :     m_libspdm_last_rsp_sequence_number = secured_message_context
+    5224                 :          1 :                                          ->application_secret.response_data_sequence_number;
+    5225                 :            : 
+    5226                 :            :     /*no keys are updated*/
+    5227                 :            : 
+    5228                 :          1 :     status = libspdm_key_update(
+    5229                 :            :         spdm_context, session_id, false);
+    5230                 :            : 
+    5231                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_BUSY_PEER);
+    5232                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    5233                 :            :                           *)(session_info->secured_message_context))
+    5234                 :            :                         ->application_secret.request_data_secret,
+    5235                 :            :                         m_req_secret_buffer, ((libspdm_secured_message_context_t
+    5236                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    5237                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    5238                 :            :                           *)(session_info->secured_message_context))
+    5239                 :            :                         ->application_secret.response_data_secret,
+    5240                 :            :                         m_rsp_secret_buffer, ((libspdm_secured_message_context_t
+    5241                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    5242                 :          1 : }
+    5243                 :            : 
+    5244                 :            : /**
+    5245                 :            :  * Test 30: the requester is setup correctly (see Test 27), but, when updating
+    5246                 :            :  * all keys, on the first try, receiving a Busy ERROR message, and on retry,
+    5247                 :            :  * receiving a correct KEY_UPDATE_ACK message. The VERIFY_KEY behavior is
+    5248                 :            :  * not altered.
+    5249                 :            :  * Expected behavior: client returns a Status of RETURN_SUCCESS, and
+    5250                 :            :  * the request data key and response data key are updated.
+    5251                 :            :  **/
+    5252                 :          1 : void libspdm_test_requester_key_update_case30(void **state)
+    5253                 :            : {
+    5254                 :            :     libspdm_return_t status;
+    5255                 :            :     libspdm_test_context_t    *spdm_test_context;
+    5256                 :            :     libspdm_context_t         *spdm_context;
+    5257                 :            :     uint32_t session_id;
+    5258                 :            :     libspdm_session_info_t    *session_info;
+    5259                 :            : 
+    5260                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    5261                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    5262                 :            : 
+    5263                 :            :     libspdm_secured_message_context_t *secured_message_context;
+    5264                 :            : 
+    5265                 :          1 :     spdm_test_context = *state;
+    5266                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5267                 :          1 :     spdm_test_context->case_id = 0x1E;
+    5268                 :            : 
+    5269                 :          1 :     spdm_context->retry_times = 3;
+    5270                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5271                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5272                 :          1 :     libspdm_set_standard_key_update_test_state(
+    5273                 :            :         spdm_context, &session_id);
+    5274                 :            : 
+    5275                 :          1 :     session_info = &spdm_context->session_info[0];
+    5276                 :          1 :     secured_message_context = session_info->secured_message_context;
+    5277                 :            : 
+    5278                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    5279                 :          1 :         session_info->secured_message_context,
+    5280                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    5281                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    5282                 :            : 
+    5283                 :            :     /*store previous encryption state*/
+    5284                 :          1 :     libspdm_copy_mem(m_libspdm_last_rsp_enc_key, sizeof(m_libspdm_last_rsp_enc_key),
+    5285                 :            :                      secured_message_context
+    5286                 :          1 :                      ->application_secret.response_data_encryption_key,
+    5287                 :            :                      secured_message_context->aead_key_size);
+    5288                 :          1 :     libspdm_copy_mem(m_libspdm_last_rsp_salt, sizeof(m_libspdm_last_rsp_salt),
+    5289                 :            :                      secured_message_context
+    5290                 :          1 :                      ->application_secret.response_data_salt,
+    5291                 :            :                      secured_message_context->aead_iv_size);
+    5292                 :          1 :     m_libspdm_last_rsp_sequence_number = secured_message_context
+    5293                 :          1 :                                          ->application_secret.response_data_sequence_number;
+    5294                 :            : 
+    5295                 :            :     /*request side updated*/
+    5296                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    5297                 :            :                                   ((libspdm_secured_message_context_t
+    5298                 :          1 :                                     *)(session_info->secured_message_context))->hash_size,
+    5299                 :            :                                   m_req_secret_buffer, m_req_secret_buffer,
+    5300                 :            :                                   sizeof(m_req_secret_buffer));
+    5301                 :            :     /*response side updated*/
+    5302                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    5303                 :            :                                   ((libspdm_secured_message_context_t
+    5304                 :          1 :                                     *)(session_info->secured_message_context))->hash_size,
+    5305                 :            :                                   m_rsp_secret_buffer, m_rsp_secret_buffer,
+    5306                 :            :                                   sizeof(m_rsp_secret_buffer));
+    5307                 :            : 
+    5308                 :          1 :     status = libspdm_key_update(
+    5309                 :            :         spdm_context, session_id, false);
+    5310                 :            : 
+    5311                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    5312                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    5313                 :            :                           *)(session_info->secured_message_context))
+    5314                 :            :                         ->application_secret.request_data_secret,
+    5315                 :            :                         m_req_secret_buffer, ((libspdm_secured_message_context_t
+    5316                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    5317                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    5318                 :            :                           *)(session_info->secured_message_context))
+    5319                 :            :                         ->application_secret.response_data_secret,
+    5320                 :            :                         m_rsp_secret_buffer, ((libspdm_secured_message_context_t
+    5321                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    5322                 :          1 : }
+    5323                 :            : 
+    5324                 :            : /**
+    5325                 :            :  * Test 31: the requester is setup correctly (see Test 27), but receives an
+    5326                 :            :  * ERROR message indicating the RequestResynch status of the responder, when
+    5327                 :            :  * updating all keys.
+    5328                 :            :  * Expected behavior: client returns a Status of RETURN_DEVICE_ERROR, and the
+    5329                 :            :  * communication is reset to expect a new GET_VERSION message.
+    5330                 :            :  **/
+    5331                 :          1 : void libspdm_test_requester_key_update_case31(void **state)
+    5332                 :            : {
+    5333                 :            :     libspdm_return_t status;
+    5334                 :            :     libspdm_test_context_t    *spdm_test_context;
+    5335                 :            :     libspdm_context_t         *spdm_context;
+    5336                 :            :     uint32_t session_id;
+    5337                 :            :     libspdm_session_info_t    *session_info;
+    5338                 :            : 
+    5339                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    5340                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    5341                 :            : 
+    5342                 :            :     libspdm_secured_message_context_t *secured_message_context;
+    5343                 :            : 
+    5344                 :          1 :     spdm_test_context = *state;
+    5345                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5346                 :          1 :     spdm_test_context->case_id = 0x1F;
+    5347                 :            : 
+    5348                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5349                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5350                 :          1 :     libspdm_set_standard_key_update_test_state(
+    5351                 :            :         spdm_context, &session_id);
+    5352                 :            : 
+    5353                 :          1 :     session_info = &spdm_context->session_info[0];
+    5354                 :          1 :     secured_message_context = session_info->secured_message_context;
+    5355                 :            : 
+    5356                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    5357                 :          1 :         session_info->secured_message_context,
+    5358                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    5359                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    5360                 :            : 
+    5361                 :            :     /*store previous encryption state*/
+    5362                 :          1 :     libspdm_copy_mem(m_libspdm_last_rsp_enc_key, sizeof(m_libspdm_last_rsp_enc_key),
+    5363                 :            :                      secured_message_context
+    5364                 :          1 :                      ->application_secret.response_data_encryption_key,
+    5365                 :            :                      secured_message_context->aead_key_size);
+    5366                 :          1 :     libspdm_copy_mem(m_libspdm_last_rsp_salt, sizeof(m_libspdm_last_rsp_salt),
+    5367                 :            :                      secured_message_context
+    5368                 :          1 :                      ->application_secret.response_data_salt,
+    5369                 :            :                      secured_message_context->aead_iv_size);
+    5370                 :          1 :     m_libspdm_last_rsp_sequence_number = secured_message_context
+    5371                 :          1 :                                          ->application_secret.response_data_sequence_number;
+    5372                 :            : 
+    5373                 :          1 :     status = libspdm_key_update(
+    5374                 :            :         spdm_context, session_id, false);
+    5375                 :            : 
+    5376                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_RESYNCH_PEER);
+    5377                 :          1 :     assert_int_equal(spdm_context->connection_info.connection_state,
+    5378                 :            :                      LIBSPDM_CONNECTION_STATE_NOT_STARTED);
+    5379                 :          1 : }
+    5380                 :            : 
+    5381                 :            : /**
+    5382                 :            :  * Test 32: the requester is setup correctly (see Test 27), but receives an
+    5383                 :            :  * ERROR message indicating the ResponseNotReady status of the responder, when
+    5384                 :            :  * updating all keys.
+    5385                 :            :  * Expected behavior: client returns a Status of RETURN_DEVICE_ERROR, and
+    5386                 :            :  * no keys should be updated.
+    5387                 :            :  **/
+    5388                 :          1 : void libspdm_test_requester_key_update_case32(void **state)
+    5389                 :            : {
+    5390                 :            :     libspdm_return_t status;
+    5391                 :            :     libspdm_test_context_t    *spdm_test_context;
+    5392                 :            :     libspdm_context_t         *spdm_context;
+    5393                 :            :     uint32_t session_id;
+    5394                 :            :     libspdm_session_info_t    *session_info;
+    5395                 :            : 
+    5396                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    5397                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    5398                 :            : 
+    5399                 :            :     libspdm_secured_message_context_t *secured_message_context;
+    5400                 :            : 
+    5401                 :          1 :     spdm_test_context = *state;
+    5402                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5403                 :          1 :     spdm_test_context->case_id = 0x20;
+    5404                 :            : 
+    5405                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5406                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5407                 :          1 :     libspdm_set_standard_key_update_test_state(
+    5408                 :            :         spdm_context, &session_id);
+    5409                 :            : 
+    5410                 :          1 :     session_info = &spdm_context->session_info[0];
+    5411                 :          1 :     secured_message_context = session_info->secured_message_context;
+    5412                 :            : 
+    5413                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    5414                 :          1 :         session_info->secured_message_context,
+    5415                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    5416                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    5417                 :            : 
+    5418                 :            :     /*store previous encryption state*/
+    5419                 :          1 :     libspdm_copy_mem(m_libspdm_last_rsp_enc_key, sizeof(m_libspdm_last_rsp_enc_key),
+    5420                 :            :                      secured_message_context
+    5421                 :          1 :                      ->application_secret.response_data_encryption_key,
+    5422                 :            :                      secured_message_context->aead_key_size);
+    5423                 :          1 :     libspdm_copy_mem(m_libspdm_last_rsp_salt, sizeof(m_libspdm_last_rsp_salt),
+    5424                 :            :                      secured_message_context
+    5425                 :          1 :                      ->application_secret.response_data_salt,
+    5426                 :            :                      secured_message_context->aead_iv_size);
+    5427                 :          1 :     m_libspdm_last_rsp_sequence_number = secured_message_context
+    5428                 :          1 :                                          ->application_secret.response_data_sequence_number;
+    5429                 :            : 
+    5430                 :            :     /*no keys are updated*/
+    5431                 :            : 
+    5432                 :          1 :     status = libspdm_key_update(
+    5433                 :            :         spdm_context, session_id, false);
+    5434                 :            : 
+    5435                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_NOT_READY_PEER);
+    5436                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    5437                 :            :                           *)(session_info->secured_message_context))
+    5438                 :            :                         ->application_secret.request_data_secret,
+    5439                 :            :                         m_req_secret_buffer, ((libspdm_secured_message_context_t
+    5440                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    5441                 :          1 :     assert_memory_equal(((libspdm_secured_message_context_t
+    5442                 :            :                           *)(session_info->secured_message_context))
+    5443                 :            :                         ->application_secret.response_data_secret,
+    5444                 :            :                         m_rsp_secret_buffer, ((libspdm_secured_message_context_t
+    5445                 :            :                                                *)(session_info->secured_message_context))->hash_size);
+    5446                 :          1 : }
+    5447                 :            : 
+    5448                 :            : /**
+    5449                 :            :  * Test 33: the requester is setup correctly (see Test 27), but, when updating
+    5450                 :            :  * all keys, on the first try, receiving a ResponseNotReady ERROR message, and
+    5451                 :            :  * on retry, receiving a correct KEY_UPDATE_ACK message. The VERIFY_KEY
+    5452                 :            :  * behavior is not altered.
+    5453                 :            :  * Expected behavior: client returns a Status of RETURN_SUCCESS, and
+    5454                 :            :  * the request data key and response data key are updated.
+    5455                 :            :  **/
+    5456                 :          1 : void libspdm_test_requester_key_update_case33(void **state)
+    5457                 :            : {
+    5458                 :            :     libspdm_return_t status;
+    5459                 :            :     libspdm_test_context_t    *spdm_test_context;
+    5460                 :            :     libspdm_context_t         *spdm_context;
+    5461                 :            :     uint32_t session_id;
+    5462                 :            :     libspdm_session_info_t    *session_info;
+    5463                 :            : 
+    5464                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    5465                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    5466                 :            : 
+    5467                 :            :     libspdm_secured_message_context_t *secured_message_context;
+    5468                 :            : 
+    5469                 :          1 :     spdm_test_context = *state;
+    5470                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5471                 :          1 :     spdm_test_context->case_id = 0x21;
+    5472                 :            : 
+    5473                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5474                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5475                 :          1 :     libspdm_set_standard_key_update_test_state(spdm_context, &session_id);
+    5476                 :            : 
+    5477                 :          1 :     session_info = &spdm_context->session_info[0];
+    5478                 :          1 :     secured_message_context = session_info->secured_message_context;
+    5479                 :            : 
+    5480                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    5481                 :          1 :         session_info->secured_message_context,
+    5482                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    5483                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    5484                 :            : 
+    5485                 :            :     /*store previous encryption state*/
+    5486                 :          1 :     libspdm_copy_mem(m_libspdm_last_rsp_enc_key, sizeof(m_libspdm_last_rsp_enc_key),
+    5487                 :            :                      secured_message_context
+    5488                 :          1 :                      ->application_secret.response_data_encryption_key,
+    5489                 :            :                      secured_message_context->aead_key_size);
+    5490                 :          1 :     libspdm_copy_mem(m_libspdm_last_rsp_salt, sizeof(m_libspdm_last_rsp_salt),
+    5491                 :            :                      secured_message_context
+    5492                 :          1 :                      ->application_secret.response_data_salt,
+    5493                 :            :                      secured_message_context->aead_iv_size);
+    5494                 :          1 :     m_libspdm_last_rsp_sequence_number = secured_message_context
+    5495                 :          1 :                                          ->application_secret.response_data_sequence_number;
+    5496                 :            : 
+    5497                 :            :     /*request side updated*/
+    5498                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    5499                 :            :                                   ((libspdm_secured_message_context_t
+    5500                 :          1 :                                     *)(session_info->secured_message_context))->hash_size,
+    5501                 :            :                                   m_req_secret_buffer, m_req_secret_buffer,
+    5502                 :            :                                   sizeof(m_req_secret_buffer));
+    5503                 :            :     /*response side updated*/
+    5504                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    5505                 :            :                                   ((libspdm_secured_message_context_t
+    5506                 :          1 :                                     *)(session_info->secured_message_context))->hash_size,
+    5507                 :            :                                   m_rsp_secret_buffer, m_rsp_secret_buffer,
+    5508                 :            :                                   sizeof(m_rsp_secret_buffer));
+    5509                 :            : 
+    5510                 :          1 :     status = libspdm_key_update(spdm_context, session_id, false);
+    5511                 :            : 
+    5512                 :            :     if (LIBSPDM_RESPOND_IF_READY_SUPPORT) {
+    5513                 :          1 :         assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    5514                 :          1 :         assert_memory_equal(((libspdm_secured_message_context_t
+    5515                 :            :                               *)(session_info->secured_message_context))
+    5516                 :            :                             ->application_secret.request_data_secret,
+    5517                 :            :                             m_req_secret_buffer, ((libspdm_secured_message_context_t
+    5518                 :            :                                                    *)(session_info->secured_message_context))->hash_size);
+    5519                 :          1 :         assert_memory_equal(((libspdm_secured_message_context_t
+    5520                 :            :                               *)(session_info->secured_message_context))
+    5521                 :            :                             ->application_secret.response_data_secret,
+    5522                 :            :                             m_rsp_secret_buffer, ((libspdm_secured_message_context_t
+    5523                 :            :                                                    *)(session_info->secured_message_context))->hash_size);
+    5524                 :            :     } else {
+    5525                 :            :         assert_int_equal(status, LIBSPDM_STATUS_NOT_READY_PEER);
+    5526                 :            :     }
+    5527                 :          1 : }
+    5528                 :            : 
+    5529                 :            : /**
+    5530                 :            :  * Test 34: receiving an unexpected ERROR message from the responder,
+    5531                 :            :  * when updating all keys.
+    5532                 :            :  * There are tests for all named codes, including some reserved ones
+    5533                 :            :  * (namely, 0x00, 0x0b, 0x0c, 0x3f, 0xfd, 0xfe).
+    5534                 :            :  * However, for having specific test cases, it is excluded from this case:
+    5535                 :            :  * Busy (0x03), ResponseNotReady (0x42), and RequestResync (0x43).
+    5536                 :            :  * Expected behavior: client returns a status of RETURN_DEVICE_ERROR, and
+    5537                 :            :  * no keys should be updated.
+    5538                 :            :  **/
+    5539                 :          1 : void libspdm_test_requester_key_update_case34(void **state)
+    5540                 :            : {
+    5541                 :            :     libspdm_return_t status;
+    5542                 :            :     libspdm_test_context_t    *spdm_test_context;
+    5543                 :            :     libspdm_context_t         *spdm_context;
+    5544                 :            :     uint32_t session_id;
+    5545                 :            :     libspdm_session_info_t    *session_info;
+    5546                 :            :     uint16_t error_code;
+    5547                 :            : 
+    5548                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    5549                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    5550                 :            : 
+    5551                 :            :     libspdm_secured_message_context_t *secured_message_context;
+    5552                 :            : 
+    5553                 :          1 :     spdm_test_context = *state;
+    5554                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5555                 :          1 :     spdm_test_context->case_id = 0x22;
+    5556                 :            : 
+    5557                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5558                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5559                 :          1 :     libspdm_set_standard_key_update_test_state(
+    5560                 :            :         spdm_context, &session_id);
+    5561                 :            : 
+    5562                 :          1 :     session_info = &spdm_context->session_info[0];
+    5563                 :          1 :     secured_message_context = session_info->secured_message_context;
+    5564                 :            : 
+    5565                 :          1 :     error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
+    5566         [ +  + ]:         18 :     while(error_code <= 0xff) {
+    5567                 :            :         /* skip SPDM_ERROR_CODE_DECRYPT_ERROR, because this case will free context*/
+    5568         [ +  + ]:         17 :         if(error_code == SPDM_ERROR_CODE_DECRYPT_ERROR) {
+    5569                 :          1 :             error_code++;
+    5570                 :            :         }
+    5571                 :         17 :         libspdm_set_standard_key_update_test_secrets(
+    5572                 :         17 :             session_info->secured_message_context,
+    5573                 :            :             m_rsp_secret_buffer, (uint8_t)(0xFF),
+    5574                 :            :             m_req_secret_buffer, (uint8_t)(0xEE));
+    5575                 :            : 
+    5576                 :            :         /*store previous encryption state*/
+    5577                 :         17 :         libspdm_copy_mem(m_libspdm_last_rsp_enc_key, sizeof(m_libspdm_last_rsp_enc_key),
+    5578                 :            :                          secured_message_context
+    5579                 :         17 :                          ->application_secret.response_data_encryption_key,
+    5580                 :            :                          secured_message_context->aead_key_size);
+    5581                 :         17 :         libspdm_copy_mem(m_libspdm_last_rsp_salt, sizeof(m_libspdm_last_rsp_salt),
+    5582                 :            :                          secured_message_context
+    5583                 :         17 :                          ->application_secret.response_data_salt,
+    5584                 :            :                          secured_message_context->aead_iv_size);
+    5585                 :         17 :         m_libspdm_last_rsp_sequence_number = secured_message_context
+    5586                 :         17 :                                              ->application_secret.response_data_sequence_number;
+    5587                 :            : 
+    5588                 :            :         /*no keys are updated*/
+    5589                 :            : 
+    5590                 :         17 :         status = libspdm_key_update(
+    5591                 :            :             spdm_context, session_id, false);
+    5592                 :            : 
+    5593         [ -  + ]:         17 :         LIBSPDM_ASSERT_INT_EQUAL_CASE (status, LIBSPDM_STATUS_ERROR_PEER, error_code);
+    5594                 :         17 :         assert_memory_equal(((libspdm_secured_message_context_t
+    5595                 :            :                               *)(session_info->secured_message_context))
+    5596                 :            :                             ->application_secret.request_data_secret,
+    5597                 :            :                             m_req_secret_buffer, ((libspdm_secured_message_context_t
+    5598                 :            :                                                    *)(session_info->secured_message_context))->hash_size);
+    5599                 :         17 :         assert_memory_equal(((libspdm_secured_message_context_t
+    5600                 :            :                               *)(session_info->secured_message_context))
+    5601                 :            :                             ->application_secret.response_data_secret,
+    5602                 :            :                             m_rsp_secret_buffer, ((libspdm_secured_message_context_t
+    5603                 :            :                                                    *)(session_info->secured_message_context))->hash_size);
+    5604                 :            : 
+    5605                 :         17 :         error_code++;
+    5606                 :            :         /*busy is treated in cases 5 and 6*/
+    5607         [ +  + ]:         17 :         if(error_code == SPDM_ERROR_CODE_BUSY) {
+    5608                 :          1 :             error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
+    5609                 :            :         }
+    5610                 :            :         /*skip some reserved error codes (0d to 3e)*/
+    5611         [ +  + ]:         17 :         if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) {
+    5612                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
+    5613                 :            :         }
+    5614                 :            :         /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
+    5615         [ +  + ]:         17 :         if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) {
+    5616                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
+    5617                 :            :         }
+    5618                 :            :     }
+    5619                 :          1 : }
+    5620                 :            : 
+    5621                 :            : /**
+    5622                 :            :  * Test 35: the requester is setup correctly, but receives an ERROR with SPDM_ERROR_CODE_DECRYPT_ERROR.
+    5623                 :            :  * Expected behavior: client returns a Status of INVALID_SESSION_ID  and free the session ID.
+    5624                 :            :  **/
+    5625                 :          1 : void libspdm_test_requester_key_update_case35(void **state)
+    5626                 :            : {
+    5627                 :            :     libspdm_return_t status;
+    5628                 :            :     libspdm_test_context_t    *spdm_test_context;
+    5629                 :            :     libspdm_context_t         *spdm_context;
+    5630                 :            :     uint32_t session_id;
+    5631                 :            :     libspdm_session_info_t    *session_info;
+    5632                 :            : 
+    5633                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    5634                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    5635                 :            : 
+    5636                 :          1 :     spdm_test_context = *state;
+    5637                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    5638                 :          1 :     spdm_test_context->case_id = 0x23;
+    5639                 :            : 
+    5640                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    5641                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    5642                 :          1 :     libspdm_set_standard_key_update_test_state(spdm_context, &session_id);
+    5643                 :            : 
+    5644                 :          1 :     session_info = &spdm_context->session_info[0];
+    5645                 :            : 
+    5646                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    5647                 :          1 :         session_info->secured_message_context,
+    5648                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    5649                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    5650                 :            : 
+    5651                 :            :     /*no keys are updated*/
+    5652                 :            : 
+    5653                 :          1 :     status = libspdm_key_update(spdm_context, session_id, true);
+    5654                 :            : 
+    5655                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SESSION_MSG_ERROR);
+    5656                 :          1 :     assert_int_equal(spdm_context->session_info->session_id, INVALID_SESSION_ID);
+    5657                 :          1 : }
+    5658                 :            : 
+    5659                 :            : libspdm_test_context_t m_libspdm_requester_key_update_test_context = {
+    5660                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+    5661                 :            :     true,
+    5662                 :            :     libspdm_requester_key_update_test_send_message,
+    5663                 :            :     libspdm_requester_key_update_test_receive_message,
+    5664                 :            : };
+    5665                 :            : 
+    5666                 :          1 : int libspdm_requester_key_update_test_main(void)
+    5667                 :            : {
+    5668                 :          1 :     const struct CMUnitTest spdm_requester_key_update_tests[] = {
+    5669                 :            :         /* SendRequest failed*/
+    5670                 :            :         cmocka_unit_test(libspdm_test_requester_key_update_case1),
+    5671                 :            :         /* update single key
+    5672                 :            :          * Successful response*/
+    5673                 :            :         cmocka_unit_test(libspdm_test_requester_key_update_case2),
+    5674                 :            :         /* connection_state check failed*/
+    5675                 :            :         cmocka_unit_test(libspdm_test_requester_key_update_case3),
+    5676                 :            :         /* Error response: SPDM_ERROR_CODE_INVALID_REQUEST*/
+    5677                 :            :         cmocka_unit_test(libspdm_test_requester_key_update_case4),
+    5678                 :            :         /* Always SPDM_ERROR_CODE_BUSY*/
+    5679                 :            :         cmocka_unit_test(libspdm_test_requester_key_update_case5),
+    5680                 :            :         /* SPDM_ERROR_CODE_BUSY + Successful response*/
+    5681                 :            :         cmocka_unit_test(libspdm_test_requester_key_update_case6),
+    5682                 :            :         /* Error response: SPDM_ERROR_CODE_REQUEST_RESYNCH*/
+    5683                 :            :         cmocka_unit_test(libspdm_test_requester_key_update_case7),
+    5684                 :            :         /* Always SPDM_ERROR_CODE_RESPONSE_NOT_READY*/
+    5685                 :            :         cmocka_unit_test(libspdm_test_requester_key_update_case8),
+    5686                 :            :         /* SPDM_ERROR_CODE_RESPONSE_NOT_READY + Successful response*/
+    5687                 :            :         cmocka_unit_test(libspdm_test_requester_key_update_case9),
+    5688                 :            :         /* Unexpected errors*/
+    5689                 :            :         cmocka_unit_test(libspdm_test_requester_key_update_case10),
+    5690                 :            :         /* Buffer reset*/
+    5691                 :            :         cmocka_unit_test(libspdm_test_requester_key_update_case11),
+    5692                 :            :         /* No correct setup*/
+    5693                 :            :         cmocka_unit_test(libspdm_test_requester_key_update_case12),
+    5694                 :            :         cmocka_unit_test(libspdm_test_requester_key_update_case13),
+    5695                 :            :         cmocka_unit_test(libspdm_test_requester_key_update_case14),
+    5696                 :            :         /* Wrong parameters*/
+    5697                 :            :         cmocka_unit_test(libspdm_test_requester_key_update_case15),
+    5698                 :            :         cmocka_unit_test(libspdm_test_requester_key_update_case16),
+    5699                 :            :         /* verify key
+    5700                 :            :          * Error response: SPDM_ERROR_CODE_INVALID_REQUEST*/
+    5701                 :            :         cmocka_unit_test(libspdm_test_requester_key_update_case17),
+    5702                 :            :         /* Always SPDM_ERROR_CODE_BUSY*/
+    5703                 :            :         cmocka_unit_test(libspdm_test_requester_key_update_case18),
+    5704                 :            :         /* SPDM_ERROR_CODE_BUSY + Successful response*/
+    5705                 :            :         cmocka_unit_test(libspdm_test_requester_key_update_case19),
+    5706                 :            :         /* Error response: SPDM_ERROR_CODE_REQUEST_RESYNCH*/
+    5707                 :            :         cmocka_unit_test(libspdm_test_requester_key_update_case20),
+    5708                 :            :         /* Always SPDM_ERROR_CODE_RESPONSE_NOT_READY*/
+    5709                 :            :         cmocka_unit_test(libspdm_test_requester_key_update_case21),
+    5710                 :            :         /* SPDM_ERROR_CODE_RESPONSE_NOT_READY + Successful response*/
+    5711                 :            :         cmocka_unit_test(libspdm_test_requester_key_update_case22),
+    5712                 :            :         /* Unexpected errors*/
+    5713                 :            :         cmocka_unit_test(libspdm_test_requester_key_update_case23),
+    5714                 :            :         /* No correct setup*/
+    5715                 :            :         cmocka_unit_test(libspdm_test_requester_key_update_case24),
+    5716                 :            :         /* Wrong parameters*/
+    5717                 :            :         cmocka_unit_test(libspdm_test_requester_key_update_case25),
+    5718                 :            :         cmocka_unit_test(libspdm_test_requester_key_update_case26),
+    5719                 :            :         /* update all keys
+    5720                 :            :          * Sucessful response*/
+    5721                 :            :         cmocka_unit_test(libspdm_test_requester_key_update_case27),
+    5722                 :            :         /* Error response: SPDM_ERROR_CODE_INVALID_REQUEST*/
+    5723                 :            :         cmocka_unit_test(libspdm_test_requester_key_update_case28),
+    5724                 :            :         /* Always SPDM_ERROR_CODE_BUSY*/
+    5725                 :            :         cmocka_unit_test(libspdm_test_requester_key_update_case29),
+    5726                 :            :         /* SPDM_ERROR_CODE_BUSY + Successful response*/
+    5727                 :            :         cmocka_unit_test(libspdm_test_requester_key_update_case30),
+    5728                 :            :         /* Error response: SPDM_ERROR_CODE_REQUEST_RESYNCH*/
+    5729                 :            :         cmocka_unit_test(libspdm_test_requester_key_update_case31),
+    5730                 :            :         /* Always SPDM_ERROR_CODE_RESPONSE_NOT_READY*/
+    5731                 :            :         cmocka_unit_test(libspdm_test_requester_key_update_case32),
+    5732                 :            :         /* SPDM_ERROR_CODE_RESPONSE_NOT_READY + Successful response*/
+    5733                 :            :         cmocka_unit_test(libspdm_test_requester_key_update_case33),
+    5734                 :            :         /* Unexpected errors*/
+    5735                 :            :         cmocka_unit_test(libspdm_test_requester_key_update_case34),
+    5736                 :            :         /* Error response: SPDM_ERROR_CODE_DECRYPT_ERROR*/
+    5737                 :            :         cmocka_unit_test(libspdm_test_requester_key_update_case35),
+    5738                 :            :     };
+    5739                 :            : 
+    5740                 :          1 :     libspdm_setup_test_context(&m_libspdm_requester_key_update_test_context);
+    5741                 :            : 
+    5742                 :          1 :     return cmocka_run_group_tests(spdm_requester_key_update_tests,
+    5743                 :            :                                   libspdm_unit_test_group_setup,
+    5744                 :            :                                   libspdm_unit_test_group_teardown);
+    5745                 :            : }
+    5746                 :            : 
+    5747                 :            : #endif /* (LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP) || (LIBSPDM_ENABLE_CAPABILITY_PSK_CAP) */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/negotiate_algorithms.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_requester/negotiate_algorithms.c.func-sort-c.html new file mode 100644 index 00000000000..c2b70ab46ab --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/negotiate_algorithms.c.func-sort-c.html @@ -0,0 +1,237 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/negotiate_algorithms.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - negotiate_algorithms.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:633125850.3 %
Date:2024-09-22 08:21:07Functions:3939100.0 %
Branches:187623.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_negotiate_algorithms_test_main1
libspdm_test_requester_negotiate_algorithms_case11
libspdm_test_requester_negotiate_algorithms_case101
libspdm_test_requester_negotiate_algorithms_case111
libspdm_test_requester_negotiate_algorithms_case121
libspdm_test_requester_negotiate_algorithms_case131
libspdm_test_requester_negotiate_algorithms_case141
libspdm_test_requester_negotiate_algorithms_case151
libspdm_test_requester_negotiate_algorithms_case161
libspdm_test_requester_negotiate_algorithms_case171
libspdm_test_requester_negotiate_algorithms_case181
libspdm_test_requester_negotiate_algorithms_case191
libspdm_test_requester_negotiate_algorithms_case21
libspdm_test_requester_negotiate_algorithms_case201
libspdm_test_requester_negotiate_algorithms_case211
libspdm_test_requester_negotiate_algorithms_case221
libspdm_test_requester_negotiate_algorithms_case231
libspdm_test_requester_negotiate_algorithms_case241
libspdm_test_requester_negotiate_algorithms_case251
libspdm_test_requester_negotiate_algorithms_case261
libspdm_test_requester_negotiate_algorithms_case271
libspdm_test_requester_negotiate_algorithms_case281
libspdm_test_requester_negotiate_algorithms_case291
libspdm_test_requester_negotiate_algorithms_case31
libspdm_test_requester_negotiate_algorithms_case301
libspdm_test_requester_negotiate_algorithms_case311
libspdm_test_requester_negotiate_algorithms_case321
libspdm_test_requester_negotiate_algorithms_case331
libspdm_test_requester_negotiate_algorithms_case341
libspdm_test_requester_negotiate_algorithms_case351
libspdm_test_requester_negotiate_algorithms_case361
libspdm_test_requester_negotiate_algorithms_case41
libspdm_test_requester_negotiate_algorithms_case51
libspdm_test_requester_negotiate_algorithms_case61
libspdm_test_requester_negotiate_algorithms_case71
libspdm_test_requester_negotiate_algorithms_case81
libspdm_test_requester_negotiate_algorithms_case91
libspdm_requester_negotiate_algorithm_test_receive_message29
libspdm_requester_negotiate_algorithms_test_send_message29
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/negotiate_algorithms.c.func.html b/coverage_log/unit_test/test_spdm_requester/negotiate_algorithms.c.func.html new file mode 100644 index 00000000000..73e755edc56 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/negotiate_algorithms.c.func.html @@ -0,0 +1,237 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/negotiate_algorithms.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - negotiate_algorithms.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:633125850.3 %
Date:2024-09-22 08:21:07Functions:3939100.0 %
Branches:187623.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_negotiate_algorithm_test_receive_message29
libspdm_requester_negotiate_algorithms_test_main1
libspdm_requester_negotiate_algorithms_test_send_message29
libspdm_test_requester_negotiate_algorithms_case11
libspdm_test_requester_negotiate_algorithms_case101
libspdm_test_requester_negotiate_algorithms_case111
libspdm_test_requester_negotiate_algorithms_case121
libspdm_test_requester_negotiate_algorithms_case131
libspdm_test_requester_negotiate_algorithms_case141
libspdm_test_requester_negotiate_algorithms_case151
libspdm_test_requester_negotiate_algorithms_case161
libspdm_test_requester_negotiate_algorithms_case171
libspdm_test_requester_negotiate_algorithms_case181
libspdm_test_requester_negotiate_algorithms_case191
libspdm_test_requester_negotiate_algorithms_case21
libspdm_test_requester_negotiate_algorithms_case201
libspdm_test_requester_negotiate_algorithms_case211
libspdm_test_requester_negotiate_algorithms_case221
libspdm_test_requester_negotiate_algorithms_case231
libspdm_test_requester_negotiate_algorithms_case241
libspdm_test_requester_negotiate_algorithms_case251
libspdm_test_requester_negotiate_algorithms_case261
libspdm_test_requester_negotiate_algorithms_case271
libspdm_test_requester_negotiate_algorithms_case281
libspdm_test_requester_negotiate_algorithms_case291
libspdm_test_requester_negotiate_algorithms_case31
libspdm_test_requester_negotiate_algorithms_case301
libspdm_test_requester_negotiate_algorithms_case311
libspdm_test_requester_negotiate_algorithms_case321
libspdm_test_requester_negotiate_algorithms_case331
libspdm_test_requester_negotiate_algorithms_case341
libspdm_test_requester_negotiate_algorithms_case351
libspdm_test_requester_negotiate_algorithms_case361
libspdm_test_requester_negotiate_algorithms_case41
libspdm_test_requester_negotiate_algorithms_case51
libspdm_test_requester_negotiate_algorithms_case61
libspdm_test_requester_negotiate_algorithms_case71
libspdm_test_requester_negotiate_algorithms_case81
libspdm_test_requester_negotiate_algorithms_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/negotiate_algorithms.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/negotiate_algorithms.c.gcov.html new file mode 100644 index 00000000000..201af4cb290 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/negotiate_algorithms.c.gcov.html @@ -0,0 +1,2332 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/negotiate_algorithms.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - negotiate_algorithms.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:633125850.3 %
Date:2024-09-22 08:21:07Functions:3939100.0 %
Branches:187623.7 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_requester_lib.h"
+       9                 :            : 
+      10                 :            : #pragma pack(1)
+      11                 :            : typedef struct {
+      12                 :            :     spdm_message_header_t header;
+      13                 :            :     uint16_t length;
+      14                 :            :     uint8_t measurement_specification_sel;
+      15                 :            :     uint8_t other_params_selection;
+      16                 :            :     uint32_t measurement_hash_algo;
+      17                 :            :     uint32_t base_asym_sel;
+      18                 :            :     uint32_t base_hash_sel;
+      19                 :            :     uint8_t reserved2[11];
+      20                 :            :     uint8_t mel_specification_sel;
+      21                 :            :     uint8_t ext_asym_sel_count;
+      22                 :            :     uint8_t ext_hash_sel_count;
+      23                 :            :     uint16_t reserved3;
+      24                 :            :     spdm_negotiate_algorithms_common_struct_table_t struct_table[4];
+      25                 :            : } libspdm_algorithms_response_spdm11_t;
+      26                 :            : #pragma pack()
+      27                 :            : 
+      28                 :            : static size_t m_libspdm_local_buffer_size;
+      29                 :            : static uint8_t m_libspdm_local_buffer[LIBSPDM_MAX_MESSAGE_VCA_BUFFER_SIZE];
+      30                 :            : 
+      31                 :            : static uint8_t m_connection_other_params_support;
+      32                 :            : 
+      33                 :            : static uint8_t m_mel_specification_sel;
+      34                 :            : 
+      35                 :            : static uint8_t m_measurement_specification_sel;
+      36                 :            : 
+      37                 :         29 : static libspdm_return_t libspdm_requester_negotiate_algorithms_test_send_message(
+      38                 :            :     void *spdm_context, size_t request_size, const void *request, uint64_t timeout)
+      39                 :            : {
+      40                 :            :     libspdm_test_context_t *spdm_test_context;
+      41                 :            : 
+      42                 :         29 :     spdm_test_context = libspdm_get_test_context();
+      43   [ -  +  +  -  :         29 :     switch (spdm_test_context->case_id) {
+          -  +  -  -  -  
+          -  -  -  -  -  
+          -  -  -  -  -  
+          -  -  -  +  -  
+          -  -  -  -  -  
+          -  -  +  +  +  
+                      - ]
+      44                 :          0 :     case 0x1:
+      45                 :          0 :         return LIBSPDM_STATUS_SEND_FAIL;
+      46                 :          1 :     case 0x2:
+      47                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      48                 :          8 :     case 0x3:
+      49                 :          8 :         return LIBSPDM_STATUS_SUCCESS;
+      50                 :          0 :     case 0x4:
+      51                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      52                 :          0 :     case 0x5:
+      53                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      54                 :          2 :     case 0x6:
+      55                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+      56                 :          0 :     case 0x7:
+      57                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      58                 :          0 :     case 0x8:
+      59                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      60                 :          0 :     case 0x9:
+      61                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      62                 :          0 :     case 0xA:
+      63                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      64                 :          0 :     case 0xB:
+      65                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      66                 :          0 :     case 0xC:
+      67                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      68                 :          0 :     case 0xD:
+      69                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      70                 :          0 :     case 0xE:
+      71                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      72                 :          0 :     case 0xF:
+      73                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      74                 :          0 :     case 0x10:
+      75                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      76                 :          0 :     case 0x11:
+      77                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      78                 :          0 :     case 0x12:
+      79                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      80                 :          0 :     case 0x13:
+      81                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      82                 :          0 :     case 0x14:
+      83                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      84                 :          0 :     case 0x15:
+      85                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      86                 :          0 :     case 0x16:
+      87                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      88                 :          1 :     case 0x17:
+      89                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      90                 :          0 :     case 0x18:
+      91                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      92                 :          0 :     case 0x19:
+      93                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      94                 :          0 :     case 0x1A:
+      95                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      96                 :          0 :     case 0x1B:
+      97                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      98                 :          0 :     case 0x1C:
+      99                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     100                 :          0 :     case 0x1D:
+     101                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     102                 :          0 :     case 0x1E:
+     103                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     104                 :          0 :     case 0x1F:
+     105                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     106                 :          1 :     case 0x20: {
+     107                 :          1 :         const uint8_t *ptr = (const uint8_t *)request;
+     108                 :            : 
+     109                 :          1 :         m_libspdm_local_buffer_size = 0;
+     110                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     111                 :          1 :                          &ptr[1], request_size - 1);
+     112                 :          1 :         m_libspdm_local_buffer_size += (request_size - 1);
+     113                 :            :     }
+     114                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     115                 :          2 :     case 0x21: {
+     116                 :            :         const spdm_negotiate_algorithms_request_t *spdm_request;
+     117                 :          2 :         spdm_request =
+     118                 :            :             (const spdm_negotiate_algorithms_request_t *)((const uint8_t *)request +
+     119                 :            :                                                           sizeof(libspdm_test_message_header_t));
+     120                 :            : 
+     121                 :          2 :         assert_int_equal (spdm_request->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+     122                 :          2 :         assert_int_equal (spdm_request->header.request_response_code, SPDM_NEGOTIATE_ALGORITHMS);
+     123                 :          2 :         assert_int_equal (spdm_request->other_params_support, SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1);
+     124                 :            :     }
+     125                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     126                 :         14 :     case 0x22:
+     127                 :            :     case 0x23:
+     128                 :            :     case 0x24:
+     129                 :         14 :         return LIBSPDM_STATUS_SUCCESS;
+     130                 :          0 :     default:
+     131                 :          0 :         return LIBSPDM_STATUS_SEND_FAIL;
+     132                 :            :     }
+     133                 :            : }
+     134                 :            : 
+     135                 :         29 : static libspdm_return_t libspdm_requester_negotiate_algorithm_test_receive_message(
+     136                 :            :     void *spdm_context, size_t *response_size,
+     137                 :            :     void **response, uint64_t timeout)
+     138                 :            : {
+     139                 :            :     libspdm_test_context_t *spdm_test_context;
+     140                 :            : 
+     141                 :         29 :     spdm_test_context = libspdm_get_test_context();
+     142   [ -  +  +  -  :         29 :     switch (spdm_test_context->case_id) {
+          -  +  -  -  -  
+          -  -  -  -  -  
+          -  -  -  -  -  
+          -  -  -  +  -  
+          -  -  -  -  -  
+          -  -  +  +  -  
+                +  +  - ]
+     143                 :          0 :     case 0x1:
+     144                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+     145                 :            : 
+     146                 :          1 :     case 0x2: {
+     147                 :            :         spdm_algorithms_response_t *spdm_response;
+     148                 :            :         size_t spdm_response_size;
+     149                 :            :         size_t transport_header_size;
+     150                 :            : 
+     151                 :          1 :         spdm_response_size = sizeof(spdm_algorithms_response_t);
+     152                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     153                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     154                 :            : 
+     155                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     156                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     157                 :          1 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     158                 :          1 :         spdm_response->header.param1 = 0;
+     159                 :          1 :         spdm_response->header.param2 = 0;
+     160                 :          1 :         spdm_response->length = sizeof(spdm_algorithms_response_t);
+     161                 :          1 :         spdm_response->measurement_specification_sel =
+     162                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     163                 :          1 :         spdm_response->measurement_hash_algo =
+     164                 :            :             m_libspdm_use_measurement_hash_algo;
+     165                 :          1 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+     166                 :          1 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+     167                 :          1 :         spdm_response->ext_asym_sel_count = 0;
+     168                 :          1 :         spdm_response->ext_hash_sel_count = 0;
+     169                 :            : 
+     170                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     171                 :            :                                               false, spdm_response_size,
+     172                 :            :                                               spdm_response,
+     173                 :            :                                               response_size, response);
+     174                 :            :     }
+     175                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     176                 :            : 
+     177                 :          8 :     case 0x3: {
+     178                 :            :         spdm_algorithms_response_t *spdm_response;
+     179                 :            :         size_t spdm_response_size;
+     180                 :            :         size_t transport_header_size;
+     181                 :            : 
+     182                 :          8 :         spdm_response_size = sizeof(spdm_algorithms_response_t);
+     183                 :          8 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     184                 :          8 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     185                 :            : 
+     186                 :          8 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     187                 :          8 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     188                 :          8 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     189                 :          8 :         spdm_response->header.param1 = 0;
+     190                 :          8 :         spdm_response->header.param2 = 0;
+     191                 :          8 :         spdm_response->length = sizeof(spdm_algorithms_response_t);
+     192                 :          8 :         spdm_response->measurement_specification_sel =
+     193                 :            :             m_measurement_specification_sel;
+     194                 :          8 :         spdm_response->measurement_hash_algo =
+     195                 :            :             m_libspdm_use_measurement_hash_algo;
+     196                 :          8 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+     197                 :          8 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+     198                 :          8 :         spdm_response->ext_asym_sel_count = 0;
+     199                 :          8 :         spdm_response->ext_hash_sel_count = 0;
+     200                 :            : 
+     201                 :          8 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     202                 :            :                                               false, spdm_response_size,
+     203                 :            :                                               spdm_response,
+     204                 :            :                                               response_size, response);
+     205                 :            :     }
+     206                 :          8 :         return LIBSPDM_STATUS_SUCCESS;
+     207                 :            : 
+     208                 :          0 :     case 0x4: {
+     209                 :            :         spdm_error_response_t *spdm_response;
+     210                 :            :         size_t spdm_response_size;
+     211                 :            :         size_t transport_header_size;
+     212                 :            : 
+     213                 :          0 :         spdm_response_size = sizeof(spdm_error_response_t);
+     214                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     215                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     216                 :            : 
+     217                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     218                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     219                 :          0 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     220                 :          0 :         spdm_response->header.param1 = SPDM_ERROR_CODE_INVALID_REQUEST;
+     221                 :          0 :         spdm_response->header.param2 = 0;
+     222                 :            : 
+     223                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     224                 :            :                                               false, spdm_response_size,
+     225                 :            :                                               spdm_response,
+     226                 :            :                                               response_size, response);
+     227                 :            :     }
+     228                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     229                 :            : 
+     230                 :          0 :     case 0x5: {
+     231                 :            :         spdm_error_response_t *spdm_response;
+     232                 :            :         size_t spdm_response_size;
+     233                 :            :         size_t transport_header_size;
+     234                 :            : 
+     235                 :          0 :         spdm_response_size = sizeof(spdm_error_response_t);
+     236                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     237                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     238                 :            : 
+     239                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     240                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     241                 :          0 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     242                 :          0 :         spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
+     243                 :          0 :         spdm_response->header.param2 = 0;
+     244                 :            : 
+     245                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     246                 :            :                                               false, spdm_response_size,
+     247                 :            :                                               spdm_response,
+     248                 :            :                                               response_size, response);
+     249                 :            :     }
+     250                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     251                 :            : 
+     252                 :          2 :     case 0x6: {
+     253                 :            :         static size_t sub_index1 = 0;
+     254         [ +  + ]:          2 :         if (sub_index1 == 0) {
+     255                 :            :             spdm_error_response_t *spdm_response;
+     256                 :            :             size_t spdm_response_size;
+     257                 :            :             size_t transport_header_size;
+     258                 :            : 
+     259                 :          1 :             spdm_response_size = sizeof(spdm_error_response_t);
+     260                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     261                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     262                 :            : 
+     263                 :          1 :             libspdm_zero_mem(spdm_response, spdm_response_size);
+     264                 :          1 :             spdm_response->header.spdm_version =
+     265                 :            :                 SPDM_MESSAGE_VERSION_10;
+     266                 :          1 :             spdm_response->header.request_response_code = SPDM_ERROR;
+     267                 :          1 :             spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
+     268                 :          1 :             spdm_response->header.param2 = 0;
+     269                 :            : 
+     270                 :          1 :             libspdm_transport_test_encode_message(
+     271                 :            :                 spdm_context, NULL, false, false,
+     272                 :            :                 spdm_response_size, spdm_response,
+     273                 :            :                 response_size, response);
+     274         [ +  - ]:          1 :         } else if (sub_index1 == 1) {
+     275                 :            :             spdm_algorithms_response_t *spdm_response;
+     276                 :            :             size_t spdm_response_size;
+     277                 :            :             size_t transport_header_size;
+     278                 :            : 
+     279                 :          1 :             spdm_response_size = sizeof(spdm_algorithms_response_t);
+     280                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     281                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     282                 :            : 
+     283                 :          1 :             libspdm_zero_mem(spdm_response, spdm_response_size);
+     284                 :          1 :             spdm_response->header.spdm_version =
+     285                 :            :                 SPDM_MESSAGE_VERSION_10;
+     286                 :          1 :             spdm_response->header.request_response_code =
+     287                 :            :                 SPDM_ALGORITHMS;
+     288                 :          1 :             spdm_response->header.param1 = 0;
+     289                 :          1 :             spdm_response->header.param2 = 0;
+     290                 :          1 :             spdm_response->length =
+     291                 :            :                 sizeof(spdm_algorithms_response_t);
+     292                 :          1 :             spdm_response->measurement_specification_sel =
+     293                 :            :                 SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     294                 :          1 :             spdm_response->measurement_hash_algo =
+     295                 :            :                 m_libspdm_use_measurement_hash_algo;
+     296                 :          1 :             spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+     297                 :          1 :             spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+     298                 :          1 :             spdm_response->ext_asym_sel_count = 0;
+     299                 :          1 :             spdm_response->ext_hash_sel_count = 0;
+     300                 :            : 
+     301                 :          1 :             libspdm_transport_test_encode_message(
+     302                 :            :                 spdm_context, NULL, false, false,
+     303                 :            :                 spdm_response_size, spdm_response,
+     304                 :            :                 response_size, response);
+     305                 :            :         }
+     306                 :          2 :         sub_index1++;
+     307                 :            :     }
+     308                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     309                 :            : 
+     310                 :          0 :     case 0x7: {
+     311                 :            :         spdm_error_response_t *spdm_response;
+     312                 :            :         size_t spdm_response_size;
+     313                 :            :         size_t transport_header_size;
+     314                 :            : 
+     315                 :          0 :         spdm_response_size = sizeof(spdm_error_response_t);
+     316                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     317                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     318                 :            : 
+     319                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     320                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     321                 :          0 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     322                 :          0 :         spdm_response->header.param1 = SPDM_ERROR_CODE_REQUEST_RESYNCH;
+     323                 :          0 :         spdm_response->header.param2 = 0;
+     324                 :            : 
+     325                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     326                 :            :                                               false, spdm_response_size,
+     327                 :            :                                               spdm_response,
+     328                 :            :                                               response_size, response);
+     329                 :            :     }
+     330                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     331                 :            : 
+     332                 :          0 :     case 0x8: {
+     333                 :            :         spdm_error_response_data_response_not_ready_t *spdm_response;
+     334                 :            :         size_t spdm_response_size;
+     335                 :            :         size_t transport_header_size;
+     336                 :            : 
+     337                 :          0 :         spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
+     338                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     339                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     340                 :            : 
+     341                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     342                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     343                 :          0 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     344                 :          0 :         spdm_response->header.param1 =
+     345                 :            :             SPDM_ERROR_CODE_RESPONSE_NOT_READY;
+     346                 :          0 :         spdm_response->header.param2 = 0;
+     347                 :          0 :         spdm_response->extend_error_data.rd_exponent = 1;
+     348                 :          0 :         spdm_response->extend_error_data.rd_tm = 2;
+     349                 :          0 :         spdm_response->extend_error_data.request_code =
+     350                 :            :             SPDM_NEGOTIATE_ALGORITHMS;
+     351                 :          0 :         spdm_response->extend_error_data.token = 0;
+     352                 :            : 
+     353                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     354                 :            :                                               false, spdm_response_size,
+     355                 :            :                                               spdm_response,
+     356                 :            :                                               response_size, response);
+     357                 :            :     }
+     358                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     359                 :            : 
+     360                 :          0 :     case 0x9:
+     361                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     362                 :            : 
+     363                 :          0 :     case 0xA: {
+     364                 :            :         spdm_algorithms_response_t *spdm_response;
+     365                 :            :         size_t spdm_response_size;
+     366                 :            :         size_t transport_header_size;
+     367                 :            : 
+     368                 :          0 :         spdm_response_size = sizeof(spdm_algorithms_response_t);
+     369                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     370                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     371                 :            : 
+     372                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     373                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     374                 :          0 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     375                 :          0 :         spdm_response->header.param1 = 0;
+     376                 :          0 :         spdm_response->header.param2 = 0;
+     377                 :          0 :         spdm_response->length = sizeof(spdm_algorithms_response_t);
+     378                 :          0 :         spdm_response->measurement_specification_sel =
+     379                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     380                 :          0 :         spdm_response->measurement_hash_algo = 0;
+     381                 :          0 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+     382                 :          0 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+     383                 :          0 :         spdm_response->ext_asym_sel_count = 0;
+     384                 :          0 :         spdm_response->ext_hash_sel_count = 0;
+     385                 :            : 
+     386                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     387                 :            :                                               false, spdm_response_size,
+     388                 :            :                                               spdm_response,
+     389                 :            :                                               response_size, response);
+     390                 :            :     }
+     391                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     392                 :            : 
+     393                 :          0 :     case 0xB: {
+     394                 :            :         spdm_algorithms_response_t *spdm_response;
+     395                 :            :         size_t spdm_response_size;
+     396                 :            :         size_t transport_header_size;
+     397                 :            : 
+     398                 :          0 :         spdm_response_size = sizeof(spdm_algorithms_response_t);
+     399                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     400                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     401                 :            : 
+     402                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     403                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     404                 :          0 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     405                 :          0 :         spdm_response->header.param1 = 0;
+     406                 :          0 :         spdm_response->header.param2 = 0;
+     407                 :          0 :         spdm_response->length = sizeof(spdm_algorithms_response_t);
+     408                 :          0 :         spdm_response->measurement_specification_sel =
+     409                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     410                 :          0 :         spdm_response->measurement_hash_algo =
+     411                 :            :             m_libspdm_use_measurement_hash_algo;
+     412                 :          0 :         spdm_response->base_asym_sel = 0;
+     413                 :          0 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+     414                 :          0 :         spdm_response->ext_asym_sel_count = 0;
+     415                 :          0 :         spdm_response->ext_hash_sel_count = 0;
+     416                 :            : 
+     417                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     418                 :            :                                               false, spdm_response_size,
+     419                 :            :                                               spdm_response,
+     420                 :            :                                               response_size, response);
+     421                 :            :     }
+     422                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     423                 :            : 
+     424                 :          0 :     case 0xC: {
+     425                 :            :         spdm_algorithms_response_t *spdm_response;
+     426                 :            :         size_t spdm_response_size;
+     427                 :            :         size_t transport_header_size;
+     428                 :            : 
+     429                 :          0 :         spdm_response_size = sizeof(spdm_algorithms_response_t);
+     430                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     431                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     432                 :            : 
+     433                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     434                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     435                 :          0 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     436                 :          0 :         spdm_response->header.param1 = 0;
+     437                 :          0 :         spdm_response->header.param2 = 0;
+     438                 :          0 :         spdm_response->length = sizeof(spdm_algorithms_response_t);
+     439                 :          0 :         spdm_response->measurement_specification_sel =
+     440                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     441                 :          0 :         spdm_response->measurement_hash_algo =
+     442                 :            :             m_libspdm_use_measurement_hash_algo;
+     443                 :          0 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+     444                 :          0 :         spdm_response->base_hash_sel = 0;
+     445                 :          0 :         spdm_response->ext_asym_sel_count = 0;
+     446                 :          0 :         spdm_response->ext_hash_sel_count = 0;
+     447                 :            : 
+     448                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     449                 :            :                                               false, spdm_response_size,
+     450                 :            :                                               spdm_response,
+     451                 :            :                                               response_size, response);
+     452                 :            :     }
+     453                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     454                 :            : 
+     455                 :          0 :     case 0xD:
+     456                 :            :     {
+     457                 :            :         spdm_algorithms_response_t *spdm_response;
+     458                 :            :         size_t spdm_response_size;
+     459                 :            :         size_t transport_header_size;
+     460                 :            : 
+     461                 :          0 :         spdm_response_size = sizeof(spdm_algorithms_response_t);
+     462                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     463                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     464                 :            : 
+     465                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     466                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     467                 :          0 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     468                 :          0 :         spdm_response->header.param1 = 0;
+     469                 :          0 :         spdm_response->header.param2 = 0;
+     470                 :          0 :         spdm_response->length = sizeof(spdm_algorithms_response_t);
+     471                 :          0 :         spdm_response->measurement_specification_sel =
+     472                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     473                 :          0 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+     474                 :          0 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+     475                 :          0 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+     476                 :          0 :         spdm_response->ext_asym_sel_count = 0;
+     477                 :          0 :         spdm_response->ext_hash_sel_count = 0;
+     478                 :            : 
+     479                 :          0 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+     480                 :            :                                                sizeof(spdm_message_header_t), spdm_response,
+     481                 :            :                                                response_size, response);
+     482                 :            :     }
+     483                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     484                 :            : 
+     485                 :          0 :     case 0xE:
+     486                 :            :     {
+     487                 :            :         spdm_algorithms_response_t *spdm_response;
+     488                 :            :         size_t spdm_response_size;
+     489                 :            :         size_t transport_header_size;
+     490                 :            : 
+     491                 :          0 :         spdm_response_size = sizeof(spdm_algorithms_response_t);
+     492                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     493                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     494                 :            : 
+     495                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     496                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     497                 :          0 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     498                 :          0 :         spdm_response->header.param1 = 0;
+     499                 :          0 :         spdm_response->header.param2 = 0;
+     500                 :          0 :         spdm_response->length = sizeof(spdm_algorithms_response_t);
+     501                 :          0 :         spdm_response->measurement_specification_sel =
+     502                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     503                 :          0 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+     504                 :          0 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+     505                 :          0 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+     506                 :            : 
+     507                 :            : 
+     508                 :          0 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+     509                 :            :                                                sizeof(spdm_algorithms_response_t)/2, spdm_response,
+     510                 :            :                                                response_size, response);
+     511                 :            :     }
+     512                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     513                 :            : 
+     514                 :          0 :     case 0xF:
+     515                 :            :     {
+     516                 :            :         spdm_algorithms_response_t *spdm_response;
+     517                 :            :         size_t spdm_response_size;
+     518                 :            :         size_t transport_header_size;
+     519                 :            : 
+     520                 :          0 :         spdm_response_size = sizeof(spdm_algorithms_response_t);
+     521                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     522                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     523                 :            : 
+     524                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     525                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     526                 :          0 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     527                 :          0 :         spdm_response->header.param1 = 0;
+     528                 :          0 :         spdm_response->header.param2 = 0;
+     529                 :          0 :         spdm_response->length = sizeof(spdm_algorithms_response_t);
+     530                 :          0 :         spdm_response->measurement_specification_sel =
+     531                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     532                 :          0 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+     533                 :          0 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+     534                 :          0 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+     535                 :          0 :         spdm_response->ext_asym_sel_count = 2;
+     536                 :          0 :         spdm_response->ext_hash_sel_count = 0;
+     537                 :            : 
+     538                 :          0 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+     539                 :            :                                                spdm_response_size,
+     540                 :            :                                                spdm_response, response_size, response);
+     541                 :            :     }
+     542                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     543                 :            : 
+     544                 :          0 :     case 0x10:
+     545                 :            :     {
+     546                 :            :         spdm_algorithms_response_t *spdm_response;
+     547                 :            :         size_t spdm_response_size;
+     548                 :            :         size_t transport_header_size;
+     549                 :            : 
+     550                 :          0 :         spdm_response_size = sizeof(spdm_algorithms_response_t);
+     551                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     552                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     553                 :            : 
+     554                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     555                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     556                 :          0 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     557                 :          0 :         spdm_response->header.param1 = 0;
+     558                 :          0 :         spdm_response->header.param2 = 0;
+     559                 :          0 :         spdm_response->length = sizeof(spdm_algorithms_response_t);
+     560                 :          0 :         spdm_response->measurement_specification_sel =
+     561                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     562                 :          0 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+     563                 :          0 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+     564                 :          0 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+     565                 :          0 :         spdm_response->ext_asym_sel_count = 0;
+     566                 :          0 :         spdm_response->ext_hash_sel_count = 2;
+     567                 :            : 
+     568                 :          0 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+     569                 :            :                                                spdm_response_size,
+     570                 :            :                                                spdm_response, response_size, response);
+     571                 :            :     }
+     572                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     573                 :            : 
+     574                 :          0 :     case 0x11:
+     575                 :            :     {
+     576                 :            :         spdm_algorithms_response_t *spdm_response;
+     577                 :            :         size_t spdm_response_size;
+     578                 :            :         size_t transport_header_size;
+     579                 :            : 
+     580                 :          0 :         spdm_response_size = sizeof(spdm_algorithms_response_t);
+     581                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     582                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     583                 :            : 
+     584                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     585                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     586                 :          0 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     587                 :          0 :         spdm_response->header.param1 = 0;
+     588                 :          0 :         spdm_response->header.param2 = 0;
+     589                 :          0 :         spdm_response->length = sizeof(spdm_algorithms_response_t);
+     590                 :          0 :         spdm_response->measurement_specification_sel =
+     591                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     592                 :          0 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+     593                 :          0 :         spdm_response->base_asym_sel = SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521;
+     594                 :          0 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+     595                 :          0 :         spdm_response->ext_asym_sel_count = 0;
+     596                 :          0 :         spdm_response->ext_hash_sel_count = 0;
+     597                 :            : 
+     598                 :          0 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+     599                 :            :                                                spdm_response_size,
+     600                 :            :                                                spdm_response, response_size, response);
+     601                 :            :     }
+     602                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     603                 :            : 
+     604                 :          0 :     case 0x12:
+     605                 :            :     {
+     606                 :            :         spdm_algorithms_response_t *spdm_response;
+     607                 :            :         size_t spdm_response_size;
+     608                 :            :         size_t transport_header_size;
+     609                 :            : 
+     610                 :          0 :         spdm_response_size = sizeof(spdm_algorithms_response_t);
+     611                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     612                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     613                 :            : 
+     614                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     615                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     616                 :          0 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     617                 :          0 :         spdm_response->header.param1 = 0;
+     618                 :          0 :         spdm_response->header.param2 = 0;
+     619                 :          0 :         spdm_response->length = sizeof(spdm_algorithms_response_t);
+     620                 :          0 :         spdm_response->measurement_specification_sel =
+     621                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     622                 :          0 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+     623                 :          0 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+     624                 :          0 :         spdm_response->base_hash_sel = SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_512;
+     625                 :          0 :         spdm_response->ext_asym_sel_count = 0;
+     626                 :          0 :         spdm_response->ext_hash_sel_count = 0;
+     627                 :            : 
+     628                 :          0 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+     629                 :            :                                                spdm_response_size,
+     630                 :            :                                                spdm_response, response_size, response);
+     631                 :            :     }
+     632                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     633                 :            : 
+     634                 :          0 :     case 0x13:
+     635                 :            :     {
+     636                 :            :         spdm_algorithms_response_t *spdm_response;
+     637                 :            :         size_t spdm_response_size;
+     638                 :            :         size_t transport_header_size;
+     639                 :            : 
+     640                 :          0 :         spdm_response_size = sizeof(spdm_algorithms_response_t);
+     641                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     642                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     643                 :            : 
+     644                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     645                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     646                 :          0 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     647                 :          0 :         spdm_response->header.param1 = 0;
+     648                 :          0 :         spdm_response->header.param2 = 0;
+     649                 :          0 :         spdm_response->length = sizeof(spdm_algorithms_response_t);
+     650                 :          0 :         spdm_response->measurement_specification_sel =
+     651                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     652                 :          0 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo|
+     653                 :            :                                                SPDM_ALGORITHMS_MEASUREMENT_HASH_ALGO_TPM_ALG_SHA3_512;
+     654                 :          0 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+     655                 :          0 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+     656                 :          0 :         spdm_response->ext_asym_sel_count = 0;
+     657                 :          0 :         spdm_response->ext_hash_sel_count = 0;
+     658                 :            : 
+     659                 :          0 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+     660                 :            :                                                spdm_response_size,
+     661                 :            :                                                spdm_response, response_size, response);
+     662                 :            :     }
+     663                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     664                 :            : 
+     665                 :          0 :     case 0x14:
+     666                 :            :     {
+     667                 :            :         spdm_algorithms_response_t *spdm_response;
+     668                 :            :         size_t spdm_response_size;
+     669                 :            :         size_t transport_header_size;
+     670                 :            : 
+     671                 :          0 :         spdm_response_size = sizeof(spdm_algorithms_response_t);
+     672                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     673                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     674                 :            : 
+     675                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     676                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     677                 :          0 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     678                 :          0 :         spdm_response->header.param1 = 0;
+     679                 :          0 :         spdm_response->header.param2 = 0;
+     680                 :          0 :         spdm_response->length = sizeof(spdm_algorithms_response_t);
+     681                 :          0 :         spdm_response->measurement_specification_sel =
+     682                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     683                 :          0 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+     684                 :          0 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo|
+     685                 :            :                                        SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521;
+     686                 :          0 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+     687                 :          0 :         spdm_response->ext_asym_sel_count = 0;
+     688                 :          0 :         spdm_response->ext_hash_sel_count = 0;
+     689                 :            : 
+     690                 :          0 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+     691                 :            :                                                spdm_response_size,
+     692                 :            :                                                spdm_response, response_size, response);
+     693                 :            :     }
+     694                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     695                 :            : 
+     696                 :          0 :     case 0x15:
+     697                 :            :     {
+     698                 :            :         spdm_algorithms_response_t *spdm_response;
+     699                 :            :         size_t spdm_response_size;
+     700                 :            :         size_t transport_header_size;
+     701                 :            : 
+     702                 :          0 :         spdm_response_size = sizeof(spdm_algorithms_response_t);
+     703                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     704                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     705                 :            : 
+     706                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     707                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     708                 :          0 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     709                 :          0 :         spdm_response->header.param1 = 0;
+     710                 :          0 :         spdm_response->header.param2 = 0;
+     711                 :          0 :         spdm_response->length = sizeof(spdm_algorithms_response_t);
+     712                 :          0 :         spdm_response->measurement_specification_sel =
+     713                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     714                 :          0 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+     715                 :          0 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+     716                 :          0 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo|
+     717                 :            :                                        SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_512;
+     718                 :          0 :         spdm_response->ext_asym_sel_count = 0;
+     719                 :          0 :         spdm_response->ext_hash_sel_count = 0;
+     720                 :            : 
+     721                 :          0 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+     722                 :            :                                                spdm_response_size,
+     723                 :            :                                                spdm_response, response_size, response);
+     724                 :            :     }
+     725                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     726                 :            : 
+     727                 :          0 :     case 0x16:
+     728                 :            :     {
+     729                 :            :         libspdm_algorithms_response_spdm11_t *spdm_response;
+     730                 :            :         size_t spdm_response_size;
+     731                 :            :         size_t transport_header_size;
+     732                 :            : 
+     733                 :          0 :         spdm_response_size = sizeof(libspdm_algorithms_response_spdm11_t);
+     734                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     735                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     736                 :            : 
+     737                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     738                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     739                 :          0 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     740                 :          0 :         spdm_response->header.param1 = 4;
+     741                 :          0 :         spdm_response->header.param2 = 0;
+     742                 :          0 :         spdm_response->length = sizeof(libspdm_algorithms_response_spdm11_t);
+     743                 :          0 :         spdm_response->measurement_specification_sel =
+     744                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     745                 :          0 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+     746                 :          0 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+     747                 :          0 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+     748                 :          0 :         spdm_response->ext_asym_sel_count = 0;
+     749                 :          0 :         spdm_response->ext_hash_sel_count = 0;
+     750                 :          0 :         spdm_response->struct_table[0].alg_type =
+     751                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE;
+     752                 :          0 :         spdm_response->struct_table[0].alg_count = 0x20;
+     753                 :          0 :         spdm_response->struct_table[0].alg_supported = m_libspdm_use_dhe_algo;
+     754                 :          0 :         spdm_response->struct_table[1].alg_type =
+     755                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD;
+     756                 :          0 :         spdm_response->struct_table[1].alg_count = 0x20;
+     757                 :          0 :         spdm_response->struct_table[1].alg_supported = m_libspdm_use_aead_algo;
+     758                 :          0 :         spdm_response->struct_table[2].alg_type =
+     759                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG;
+     760                 :          0 :         spdm_response->struct_table[2].alg_count = 0x20;
+     761                 :          0 :         spdm_response->struct_table[2].alg_supported = m_libspdm_use_req_asym_algo;
+     762                 :          0 :         spdm_response->struct_table[3].alg_type =
+     763                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE;
+     764                 :          0 :         spdm_response->struct_table[3].alg_count = 0x20;
+     765                 :          0 :         spdm_response->struct_table[3].alg_supported = m_libspdm_use_key_schedule_algo;
+     766                 :            : 
+     767                 :          0 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+     768                 :            :                                                spdm_response_size,
+     769                 :            :                                                spdm_response, response_size, response);
+     770                 :            :     }
+     771                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     772                 :            : 
+     773                 :          1 :     case 0x17:
+     774                 :            :     {
+     775                 :            :         libspdm_algorithms_response_spdm11_t *spdm_response;
+     776                 :            :         size_t spdm_response_size;
+     777                 :            :         size_t transport_header_size;
+     778                 :            : 
+     779                 :          1 :         spdm_response_size = sizeof(libspdm_algorithms_response_spdm11_t);
+     780                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     781                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     782                 :            : 
+     783                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     784                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     785                 :          1 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     786                 :          1 :         spdm_response->header.param1 = 4;
+     787                 :          1 :         spdm_response->header.param2 = 0;
+     788                 :          1 :         spdm_response->length = sizeof(libspdm_algorithms_response_spdm11_t);
+     789                 :          1 :         spdm_response->measurement_specification_sel =
+     790                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     791                 :          1 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+     792                 :          1 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+     793                 :          1 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+     794                 :          1 :         spdm_response->ext_asym_sel_count = 0;
+     795                 :          1 :         spdm_response->ext_hash_sel_count = 0;
+     796                 :          1 :         spdm_response->struct_table[0].alg_type =
+     797                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE;
+     798                 :          1 :         spdm_response->struct_table[0].alg_count = 0x20;
+     799                 :          1 :         spdm_response->struct_table[0].alg_supported = m_libspdm_use_dhe_algo;
+     800                 :          1 :         spdm_response->struct_table[1].alg_type =
+     801                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD;
+     802                 :          1 :         spdm_response->struct_table[1].alg_count = 0x20;
+     803                 :          1 :         spdm_response->struct_table[1].alg_supported = m_libspdm_use_aead_algo;
+     804                 :          1 :         spdm_response->struct_table[2].alg_type =
+     805                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG;
+     806                 :          1 :         spdm_response->struct_table[2].alg_count = 0x20;
+     807                 :          1 :         spdm_response->struct_table[2].alg_supported = m_libspdm_use_req_asym_algo;
+     808                 :          1 :         spdm_response->struct_table[3].alg_type =
+     809                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE;
+     810                 :          1 :         spdm_response->struct_table[3].alg_count = 0x20;
+     811                 :          1 :         spdm_response->struct_table[3].alg_supported = m_libspdm_use_key_schedule_algo;
+     812                 :            : 
+     813                 :          1 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+     814                 :            :                                                spdm_response_size,
+     815                 :            :                                                spdm_response, response_size, response);
+     816                 :            :     }
+     817                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     818                 :            : 
+     819                 :          0 :     case 0x18:
+     820                 :            :     {
+     821                 :            :         libspdm_algorithms_response_spdm11_t *spdm_response;
+     822                 :            :         size_t spdm_response_size;
+     823                 :            :         size_t transport_header_size;
+     824                 :            : 
+     825                 :          0 :         spdm_response_size = sizeof(libspdm_algorithms_response_spdm11_t);
+     826                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     827                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     828                 :            : 
+     829                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     830                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     831                 :          0 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     832                 :          0 :         spdm_response->header.param1 = 4;
+     833                 :          0 :         spdm_response->header.param2 = 0;
+     834                 :          0 :         spdm_response->length = sizeof(libspdm_algorithms_response_spdm11_t);
+     835                 :          0 :         spdm_response->measurement_specification_sel =
+     836                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     837                 :          0 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+     838                 :          0 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+     839                 :          0 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+     840                 :          0 :         spdm_response->ext_asym_sel_count = 0;
+     841                 :          0 :         spdm_response->ext_hash_sel_count = 0;
+     842                 :          0 :         spdm_response->struct_table[0].alg_type =
+     843                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE;
+     844                 :          0 :         spdm_response->struct_table[0].alg_count = 0x20;
+     845                 :          0 :         spdm_response->struct_table[0].alg_supported = SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_521_R1;
+     846                 :          0 :         spdm_response->struct_table[1].alg_type =
+     847                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD;
+     848                 :          0 :         spdm_response->struct_table[1].alg_count = 0x20;
+     849                 :          0 :         spdm_response->struct_table[1].alg_supported = m_libspdm_use_aead_algo;
+     850                 :          0 :         spdm_response->struct_table[2].alg_type =
+     851                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG;
+     852                 :          0 :         spdm_response->struct_table[2].alg_count = 0x20;
+     853                 :          0 :         spdm_response->struct_table[2].alg_supported = m_libspdm_use_req_asym_algo;
+     854                 :          0 :         spdm_response->struct_table[3].alg_type =
+     855                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE;
+     856                 :          0 :         spdm_response->struct_table[3].alg_count = 0x20;
+     857                 :          0 :         spdm_response->struct_table[3].alg_supported = m_libspdm_use_key_schedule_algo;
+     858                 :            : 
+     859                 :          0 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+     860                 :            :                                                spdm_response_size,
+     861                 :            :                                                spdm_response, response_size, response);
+     862                 :            :     }
+     863                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     864                 :            : 
+     865                 :          0 :     case 0x19:
+     866                 :            :     {
+     867                 :            :         libspdm_algorithms_response_spdm11_t *spdm_response;
+     868                 :            :         size_t spdm_response_size;
+     869                 :            :         size_t transport_header_size;
+     870                 :            : 
+     871                 :          0 :         spdm_response_size = sizeof(libspdm_algorithms_response_spdm11_t);
+     872                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     873                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     874                 :            : 
+     875                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     876                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     877                 :          0 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     878                 :          0 :         spdm_response->header.param1 = 4;
+     879                 :          0 :         spdm_response->header.param2 = 0;
+     880                 :          0 :         spdm_response->length = sizeof(libspdm_algorithms_response_spdm11_t);
+     881                 :          0 :         spdm_response->measurement_specification_sel =
+     882                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     883                 :          0 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+     884                 :          0 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+     885                 :          0 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+     886                 :          0 :         spdm_response->ext_asym_sel_count = 0;
+     887                 :          0 :         spdm_response->ext_hash_sel_count = 0;
+     888                 :          0 :         spdm_response->struct_table[0].alg_type =
+     889                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE;
+     890                 :          0 :         spdm_response->struct_table[0].alg_count = 0x20;
+     891                 :          0 :         spdm_response->struct_table[0].alg_supported = m_libspdm_use_dhe_algo;
+     892                 :          0 :         spdm_response->struct_table[1].alg_type =
+     893                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD;
+     894                 :          0 :         spdm_response->struct_table[1].alg_count = 0x20;
+     895                 :          0 :         spdm_response->struct_table[1].alg_supported =
+     896                 :            :             SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_CHACHA20_POLY1305;
+     897                 :          0 :         spdm_response->struct_table[2].alg_type =
+     898                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG;
+     899                 :          0 :         spdm_response->struct_table[2].alg_count = 0x20;
+     900                 :          0 :         spdm_response->struct_table[2].alg_supported = m_libspdm_use_req_asym_algo;
+     901                 :          0 :         spdm_response->struct_table[3].alg_type =
+     902                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE;
+     903                 :          0 :         spdm_response->struct_table[3].alg_count = 0x20;
+     904                 :          0 :         spdm_response->struct_table[3].alg_supported = m_libspdm_use_key_schedule_algo;
+     905                 :            : 
+     906                 :          0 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+     907                 :            :                                                spdm_response_size,
+     908                 :            :                                                spdm_response, response_size, response);
+     909                 :            :     }
+     910                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     911                 :            : 
+     912                 :          0 :     case 0x1A:
+     913                 :            :     {
+     914                 :            :         libspdm_algorithms_response_spdm11_t *spdm_response;
+     915                 :            :         size_t spdm_response_size;
+     916                 :            :         size_t transport_header_size;
+     917                 :            : 
+     918                 :          0 :         spdm_response_size = sizeof(libspdm_algorithms_response_spdm11_t);
+     919                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     920                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     921                 :            : 
+     922                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     923                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     924                 :          0 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     925                 :          0 :         spdm_response->header.param1 = 4;
+     926                 :          0 :         spdm_response->header.param2 = 0;
+     927                 :          0 :         spdm_response->length = sizeof(libspdm_algorithms_response_spdm11_t);
+     928                 :          0 :         spdm_response->measurement_specification_sel =
+     929                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     930                 :          0 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+     931                 :          0 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+     932                 :          0 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+     933                 :          0 :         spdm_response->ext_asym_sel_count = 0;
+     934                 :          0 :         spdm_response->ext_hash_sel_count = 0;
+     935                 :          0 :         spdm_response->struct_table[0].alg_type =
+     936                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE;
+     937                 :          0 :         spdm_response->struct_table[0].alg_count = 0x20;
+     938                 :          0 :         spdm_response->struct_table[0].alg_supported = m_libspdm_use_dhe_algo;
+     939                 :          0 :         spdm_response->struct_table[1].alg_type =
+     940                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD;
+     941                 :          0 :         spdm_response->struct_table[1].alg_count = 0x20;
+     942                 :          0 :         spdm_response->struct_table[1].alg_supported = m_libspdm_use_aead_algo;
+     943                 :          0 :         spdm_response->struct_table[2].alg_type =
+     944                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG;
+     945                 :          0 :         spdm_response->struct_table[2].alg_count = 0x20;
+     946                 :          0 :         spdm_response->struct_table[2].alg_supported =
+     947                 :            :             SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521;
+     948                 :          0 :         spdm_response->struct_table[3].alg_type =
+     949                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE;
+     950                 :          0 :         spdm_response->struct_table[3].alg_count = 0x20;
+     951                 :          0 :         spdm_response->struct_table[3].alg_supported = m_libspdm_use_key_schedule_algo;
+     952                 :            : 
+     953                 :          0 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+     954                 :            :                                                spdm_response_size,
+     955                 :            :                                                spdm_response, response_size, response);
+     956                 :            :     }
+     957                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     958                 :            : 
+     959                 :          0 :     case 0x1B:
+     960                 :            :     {
+     961                 :            :         libspdm_algorithms_response_spdm11_t *spdm_response;
+     962                 :            :         size_t spdm_response_size;
+     963                 :            :         size_t transport_header_size;
+     964                 :            : 
+     965                 :          0 :         spdm_response_size = sizeof(libspdm_algorithms_response_spdm11_t);
+     966                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     967                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     968                 :            : 
+     969                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     970                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     971                 :          0 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+     972                 :          0 :         spdm_response->header.param1 = 4;
+     973                 :          0 :         spdm_response->header.param2 = 0;
+     974                 :          0 :         spdm_response->length = sizeof(libspdm_algorithms_response_spdm11_t);
+     975                 :          0 :         spdm_response->measurement_specification_sel =
+     976                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+     977                 :          0 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+     978                 :          0 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+     979                 :          0 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+     980                 :          0 :         spdm_response->ext_asym_sel_count = 0;
+     981                 :          0 :         spdm_response->ext_hash_sel_count = 0;
+     982                 :          0 :         spdm_response->struct_table[0].alg_type =
+     983                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE;
+     984                 :          0 :         spdm_response->struct_table[0].alg_count = 0x20;
+     985                 :          0 :         spdm_response->struct_table[0].alg_supported = m_libspdm_use_dhe_algo;
+     986                 :          0 :         spdm_response->struct_table[1].alg_type =
+     987                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD;
+     988                 :          0 :         spdm_response->struct_table[1].alg_count = 0x20;
+     989                 :          0 :         spdm_response->struct_table[1].alg_supported = m_libspdm_use_aead_algo;
+     990                 :          0 :         spdm_response->struct_table[2].alg_type =
+     991                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG;
+     992                 :          0 :         spdm_response->struct_table[2].alg_count = 0x20;
+     993                 :          0 :         spdm_response->struct_table[2].alg_supported = m_libspdm_use_req_asym_algo;
+     994                 :          0 :         spdm_response->struct_table[3].alg_type =
+     995                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE;
+     996                 :          0 :         spdm_response->struct_table[3].alg_count = 0x20;
+     997                 :          0 :         spdm_response->struct_table[3].alg_supported = 0x00000020;
+     998                 :            : 
+     999                 :          0 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+    1000                 :            :                                                spdm_response_size,
+    1001                 :            :                                                spdm_response, response_size, response);
+    1002                 :            :     }
+    1003                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+    1004                 :            : 
+    1005                 :          0 :     case 0x1C:
+    1006                 :            :     {
+    1007                 :            :         libspdm_algorithms_response_spdm11_t *spdm_response;
+    1008                 :            :         size_t spdm_response_size;
+    1009                 :            :         size_t transport_header_size;
+    1010                 :            : 
+    1011                 :          0 :         spdm_response_size = sizeof(libspdm_algorithms_response_spdm11_t);
+    1012                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1013                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1014                 :            : 
+    1015                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+    1016                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1017                 :          0 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+    1018                 :          0 :         spdm_response->header.param1 = 4;
+    1019                 :          0 :         spdm_response->header.param2 = 0;
+    1020                 :          0 :         spdm_response->length = sizeof(libspdm_algorithms_response_spdm11_t);
+    1021                 :          0 :         spdm_response->measurement_specification_sel =
+    1022                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1023                 :          0 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+    1024                 :          0 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+    1025                 :          0 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+    1026                 :          0 :         spdm_response->ext_asym_sel_count = 0;
+    1027                 :          0 :         spdm_response->ext_hash_sel_count = 0;
+    1028                 :          0 :         spdm_response->struct_table[0].alg_type =
+    1029                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE;
+    1030                 :          0 :         spdm_response->struct_table[0].alg_count = 0x20;
+    1031                 :          0 :         spdm_response->struct_table[0].alg_supported = m_libspdm_use_dhe_algo |
+    1032                 :            :                                                        SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_521_R1;
+    1033                 :          0 :         spdm_response->struct_table[1].alg_type =
+    1034                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD;
+    1035                 :          0 :         spdm_response->struct_table[1].alg_count = 0x20;
+    1036                 :          0 :         spdm_response->struct_table[1].alg_supported = m_libspdm_use_aead_algo;
+    1037                 :          0 :         spdm_response->struct_table[2].alg_type =
+    1038                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG;
+    1039                 :          0 :         spdm_response->struct_table[2].alg_count = 0x20;
+    1040                 :          0 :         spdm_response->struct_table[2].alg_supported = m_libspdm_use_req_asym_algo;
+    1041                 :          0 :         spdm_response->struct_table[3].alg_type =
+    1042                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE;
+    1043                 :          0 :         spdm_response->struct_table[3].alg_count = 0x20;
+    1044                 :          0 :         spdm_response->struct_table[3].alg_supported = m_libspdm_use_key_schedule_algo;
+    1045                 :            : 
+    1046                 :          0 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+    1047                 :            :                                                spdm_response_size,
+    1048                 :            :                                                spdm_response, response_size, response);
+    1049                 :            :     }
+    1050                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+    1051                 :            : 
+    1052                 :          0 :     case 0x1D:
+    1053                 :            :     {
+    1054                 :            :         libspdm_algorithms_response_spdm11_t *spdm_response;
+    1055                 :            :         size_t spdm_response_size;
+    1056                 :            :         size_t transport_header_size;
+    1057                 :            : 
+    1058                 :          0 :         spdm_response_size = sizeof(libspdm_algorithms_response_spdm11_t);
+    1059                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1060                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1061                 :            : 
+    1062                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+    1063                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1064                 :          0 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+    1065                 :          0 :         spdm_response->header.param1 = 4;
+    1066                 :          0 :         spdm_response->header.param2 = 0;
+    1067                 :          0 :         spdm_response->length = sizeof(libspdm_algorithms_response_spdm11_t);
+    1068                 :          0 :         spdm_response->measurement_specification_sel =
+    1069                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1070                 :          0 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+    1071                 :          0 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+    1072                 :          0 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+    1073                 :          0 :         spdm_response->ext_asym_sel_count = 0;
+    1074                 :          0 :         spdm_response->ext_hash_sel_count = 0;
+    1075                 :          0 :         spdm_response->struct_table[0].alg_type =
+    1076                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE;
+    1077                 :          0 :         spdm_response->struct_table[0].alg_count = 0x20;
+    1078                 :          0 :         spdm_response->struct_table[0].alg_supported = m_libspdm_use_dhe_algo;
+    1079                 :          0 :         spdm_response->struct_table[1].alg_type =
+    1080                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD;
+    1081                 :          0 :         spdm_response->struct_table[1].alg_count = 0x20;
+    1082                 :          0 :         spdm_response->struct_table[1].alg_supported = m_libspdm_use_aead_algo |
+    1083                 :            :                                                        SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_CHACHA20_POLY1305;
+    1084                 :          0 :         spdm_response->struct_table[2].alg_type =
+    1085                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG;
+    1086                 :          0 :         spdm_response->struct_table[2].alg_count = 0x20;
+    1087                 :          0 :         spdm_response->struct_table[2].alg_supported = m_libspdm_use_req_asym_algo;
+    1088                 :          0 :         spdm_response->struct_table[3].alg_type =
+    1089                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE;
+    1090                 :          0 :         spdm_response->struct_table[3].alg_count = 0x20;
+    1091                 :          0 :         spdm_response->struct_table[3].alg_supported = m_libspdm_use_key_schedule_algo;
+    1092                 :            : 
+    1093                 :          0 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+    1094                 :            :                                                spdm_response_size,
+    1095                 :            :                                                spdm_response, response_size, response);
+    1096                 :            :     }
+    1097                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+    1098                 :            : 
+    1099                 :          0 :     case 0x1E:
+    1100                 :            :     {
+    1101                 :            :         libspdm_algorithms_response_spdm11_t *spdm_response;
+    1102                 :            :         size_t spdm_response_size;
+    1103                 :            :         size_t transport_header_size;
+    1104                 :            : 
+    1105                 :          0 :         spdm_response_size = sizeof(libspdm_algorithms_response_spdm11_t);
+    1106                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1107                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1108                 :            : 
+    1109                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+    1110                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1111                 :          0 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+    1112                 :          0 :         spdm_response->header.param1 = 4;
+    1113                 :          0 :         spdm_response->header.param2 = 0;
+    1114                 :          0 :         spdm_response->length = sizeof(libspdm_algorithms_response_spdm11_t);
+    1115                 :          0 :         spdm_response->measurement_specification_sel =
+    1116                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1117                 :          0 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+    1118                 :          0 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+    1119                 :          0 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+    1120                 :          0 :         spdm_response->ext_asym_sel_count = 0;
+    1121                 :          0 :         spdm_response->ext_hash_sel_count = 0;
+    1122                 :          0 :         spdm_response->struct_table[0].alg_type =
+    1123                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE;
+    1124                 :          0 :         spdm_response->struct_table[0].alg_count = 0x20;
+    1125                 :          0 :         spdm_response->struct_table[0].alg_supported = m_libspdm_use_dhe_algo;
+    1126                 :          0 :         spdm_response->struct_table[1].alg_type =
+    1127                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD;
+    1128                 :          0 :         spdm_response->struct_table[1].alg_count = 0x20;
+    1129                 :          0 :         spdm_response->struct_table[1].alg_supported = m_libspdm_use_aead_algo;
+    1130                 :          0 :         spdm_response->struct_table[2].alg_type =
+    1131                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG;
+    1132                 :          0 :         spdm_response->struct_table[2].alg_count = 0x20;
+    1133                 :          0 :         spdm_response->struct_table[2].alg_supported = m_libspdm_use_req_asym_algo |
+    1134                 :            :                                                        SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521;
+    1135                 :          0 :         spdm_response->struct_table[3].alg_type =
+    1136                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE;
+    1137                 :          0 :         spdm_response->struct_table[3].alg_count = 0x20;
+    1138                 :          0 :         spdm_response->struct_table[3].alg_supported = m_libspdm_use_key_schedule_algo;
+    1139                 :            : 
+    1140                 :          0 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+    1141                 :            :                                                spdm_response_size,
+    1142                 :            :                                                spdm_response, response_size, response);
+    1143                 :            :     }
+    1144                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+    1145                 :            : 
+    1146                 :          0 :     case 0x1F:
+    1147                 :            :     {
+    1148                 :            :         libspdm_algorithms_response_spdm11_t *spdm_response;
+    1149                 :            :         size_t spdm_response_size;
+    1150                 :            :         size_t transport_header_size;
+    1151                 :            : 
+    1152                 :          0 :         spdm_response_size = sizeof(libspdm_algorithms_response_spdm11_t);
+    1153                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1154                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1155                 :            : 
+    1156                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+    1157                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1158                 :          0 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+    1159                 :          0 :         spdm_response->header.param1 = 4;
+    1160                 :          0 :         spdm_response->header.param2 = 0;
+    1161                 :          0 :         spdm_response->length = sizeof(libspdm_algorithms_response_spdm11_t);
+    1162                 :          0 :         spdm_response->measurement_specification_sel =
+    1163                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1164                 :          0 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+    1165                 :          0 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+    1166                 :          0 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+    1167                 :          0 :         spdm_response->ext_asym_sel_count = 0;
+    1168                 :          0 :         spdm_response->ext_hash_sel_count = 0;
+    1169                 :          0 :         spdm_response->struct_table[0].alg_type =
+    1170                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE;
+    1171                 :          0 :         spdm_response->struct_table[0].alg_count = 0x20;
+    1172                 :          0 :         spdm_response->struct_table[0].alg_supported = m_libspdm_use_dhe_algo;
+    1173                 :          0 :         spdm_response->struct_table[1].alg_type =
+    1174                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD;
+    1175                 :          0 :         spdm_response->struct_table[1].alg_count = 0x20;
+    1176                 :          0 :         spdm_response->struct_table[1].alg_supported = m_libspdm_use_aead_algo;
+    1177                 :          0 :         spdm_response->struct_table[2].alg_type =
+    1178                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG;
+    1179                 :          0 :         spdm_response->struct_table[2].alg_count = 0x20;
+    1180                 :          0 :         spdm_response->struct_table[2].alg_supported = m_libspdm_use_req_asym_algo;
+    1181                 :          0 :         spdm_response->struct_table[3].alg_type =
+    1182                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE;
+    1183                 :          0 :         spdm_response->struct_table[3].alg_count = 0x20;
+    1184                 :          0 :         spdm_response->struct_table[3].alg_supported = m_libspdm_use_key_schedule_algo | 0x00000020;
+    1185                 :            : 
+    1186                 :          0 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+    1187                 :            :                                                spdm_response_size,
+    1188                 :            :                                                spdm_response, response_size, response);
+    1189                 :            :     }
+    1190                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+    1191                 :            : 
+    1192                 :          1 :     case 0x20:
+    1193                 :            :     {
+    1194                 :            :         libspdm_algorithms_response_spdm11_t *spdm_response;
+    1195                 :            :         size_t spdm_response_size;
+    1196                 :            :         size_t transport_header_size;
+    1197                 :            : 
+    1198                 :          1 :         spdm_response_size = sizeof(libspdm_algorithms_response_spdm11_t);
+    1199                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1200                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1201                 :            : 
+    1202                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+    1203                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1204                 :          1 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+    1205                 :          1 :         spdm_response->header.param1 = 4;
+    1206                 :          1 :         spdm_response->header.param2 = 0;
+    1207                 :          1 :         spdm_response->length = sizeof(libspdm_algorithms_response_spdm11_t);
+    1208                 :          1 :         spdm_response->measurement_specification_sel =
+    1209                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1210                 :          1 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+    1211                 :          1 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+    1212                 :          1 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+    1213                 :          1 :         spdm_response->ext_asym_sel_count = 0;
+    1214                 :          1 :         spdm_response->ext_hash_sel_count = 0;
+    1215                 :          1 :         spdm_response->struct_table[0].alg_type =
+    1216                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE;
+    1217                 :          1 :         spdm_response->struct_table[0].alg_count = 0x20;
+    1218                 :          1 :         spdm_response->struct_table[0].alg_supported = m_libspdm_use_dhe_algo;
+    1219                 :          1 :         spdm_response->struct_table[1].alg_type =
+    1220                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD;
+    1221                 :          1 :         spdm_response->struct_table[1].alg_count = 0x20;
+    1222                 :          1 :         spdm_response->struct_table[1].alg_supported = m_libspdm_use_aead_algo;
+    1223                 :          1 :         spdm_response->struct_table[2].alg_type =
+    1224                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG;
+    1225                 :          1 :         spdm_response->struct_table[2].alg_count = 0x20;
+    1226                 :          1 :         spdm_response->struct_table[2].alg_supported = m_libspdm_use_req_asym_algo;
+    1227                 :          1 :         spdm_response->struct_table[3].alg_type =
+    1228                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE;
+    1229                 :          1 :         spdm_response->struct_table[3].alg_count = 0x20;
+    1230                 :          1 :         spdm_response->struct_table[3].alg_supported = m_libspdm_use_key_schedule_algo;
+    1231                 :            : 
+    1232                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    1233                 :            :                          sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
+    1234                 :            :                          (uint8_t *)spdm_response, spdm_response_size);
+    1235                 :          1 :         m_libspdm_local_buffer_size += spdm_response_size;
+    1236                 :            : 
+    1237                 :          1 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+    1238                 :            :                                                spdm_response_size,
+    1239                 :            :                                                spdm_response, response_size, response);
+    1240                 :            :     }
+    1241                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1242                 :            : 
+    1243                 :          2 :     case 0x21:
+    1244                 :            :     {
+    1245                 :            :         libspdm_algorithms_response_spdm11_t *spdm_response;
+    1246                 :            :         size_t spdm_response_size;
+    1247                 :            :         size_t transport_header_size;
+    1248                 :            : 
+    1249                 :          2 :         spdm_response_size = sizeof(libspdm_algorithms_response_spdm11_t);
+    1250                 :          2 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1251                 :          2 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1252                 :            : 
+    1253                 :          2 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+    1254                 :          2 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+    1255                 :          2 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+    1256                 :          2 :         spdm_response->header.param1 = 4;
+    1257                 :          2 :         spdm_response->header.param2 = 0;
+    1258                 :          2 :         spdm_response->length = sizeof(libspdm_algorithms_response_spdm11_t);
+    1259                 :          2 :         spdm_response->measurement_specification_sel =
+    1260                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1261                 :          2 :         spdm_response->other_params_selection = SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
+    1262                 :          2 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+    1263                 :          2 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+    1264                 :          2 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+    1265                 :          2 :         spdm_response->ext_asym_sel_count = 0;
+    1266                 :          2 :         spdm_response->ext_hash_sel_count = 0;
+    1267                 :          2 :         spdm_response->struct_table[0].alg_type =
+    1268                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE;
+    1269                 :          2 :         spdm_response->struct_table[0].alg_count = 0x20;
+    1270                 :          2 :         spdm_response->struct_table[0].alg_supported = m_libspdm_use_dhe_algo;
+    1271                 :          2 :         spdm_response->struct_table[1].alg_type =
+    1272                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD;
+    1273                 :          2 :         spdm_response->struct_table[1].alg_count = 0x20;
+    1274                 :          2 :         spdm_response->struct_table[1].alg_supported = m_libspdm_use_aead_algo;
+    1275                 :          2 :         spdm_response->struct_table[2].alg_type =
+    1276                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG;
+    1277                 :          2 :         spdm_response->struct_table[2].alg_count = 0x20;
+    1278                 :          2 :         spdm_response->struct_table[2].alg_supported = m_libspdm_use_req_asym_algo;
+    1279                 :          2 :         spdm_response->struct_table[3].alg_type =
+    1280                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE;
+    1281                 :          2 :         spdm_response->struct_table[3].alg_count = 0x20;
+    1282                 :          2 :         spdm_response->struct_table[3].alg_supported = m_libspdm_use_key_schedule_algo;
+    1283                 :            : 
+    1284                 :          2 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+    1285                 :            :                                                spdm_response_size,
+    1286                 :            :                                                spdm_response, response_size, response);
+    1287                 :            :     }
+    1288                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+    1289                 :            : 
+    1290                 :          0 :     case 0x22:
+    1291                 :            :     {
+    1292                 :            :         libspdm_algorithms_response_spdm11_t *spdm_response;
+    1293                 :            :         size_t spdm_response_size;
+    1294                 :            :         size_t transport_header_size;
+    1295                 :            : 
+    1296                 :          0 :         spdm_response_size = sizeof(libspdm_algorithms_response_spdm11_t);
+    1297                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1298                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1299                 :            : 
+    1300                 :          0 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+    1301                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+    1302                 :          0 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+    1303                 :          0 :         spdm_response->header.param1 = 4;
+    1304                 :          0 :         spdm_response->header.param2 = 0;
+    1305                 :          0 :         spdm_response->length = sizeof(libspdm_algorithms_response_spdm11_t);
+    1306                 :          0 :         spdm_response->measurement_specification_sel =
+    1307                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1308                 :          0 :         spdm_response->other_params_selection = 0;
+    1309                 :          0 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+    1310                 :          0 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+    1311                 :          0 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+    1312                 :          0 :         spdm_response->ext_asym_sel_count = 0;
+    1313                 :          0 :         spdm_response->ext_hash_sel_count = 0;
+    1314                 :          0 :         spdm_response->struct_table[0].alg_type =
+    1315                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE;
+    1316                 :          0 :         spdm_response->struct_table[0].alg_count = 0x20;
+    1317                 :          0 :         spdm_response->struct_table[0].alg_supported = m_libspdm_use_dhe_algo;
+    1318                 :          0 :         spdm_response->struct_table[1].alg_type =
+    1319                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD;
+    1320                 :          0 :         spdm_response->struct_table[1].alg_count = 0x20;
+    1321                 :          0 :         spdm_response->struct_table[1].alg_supported = m_libspdm_use_aead_algo;
+    1322                 :          0 :         spdm_response->struct_table[2].alg_type =
+    1323                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG;
+    1324                 :          0 :         spdm_response->struct_table[2].alg_count = 0x20;
+    1325                 :          0 :         spdm_response->struct_table[2].alg_supported = m_libspdm_use_req_asym_algo;
+    1326                 :          0 :         spdm_response->struct_table[3].alg_type =
+    1327                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE;
+    1328                 :          0 :         spdm_response->struct_table[3].alg_count = 0x20;
+    1329                 :          0 :         spdm_response->struct_table[3].alg_supported = m_libspdm_use_key_schedule_algo;
+    1330                 :            : 
+    1331                 :          0 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+    1332                 :            :                                                spdm_response_size,
+    1333                 :            :                                                spdm_response, response_size, response);
+    1334                 :            :     }
+    1335                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+    1336                 :            : 
+    1337                 :          6 :     case 0x23:
+    1338                 :            :     {
+    1339                 :            :         spdm_algorithms_response_t *spdm_response;
+    1340                 :            :         size_t spdm_response_size;
+    1341                 :            :         size_t transport_header_size;
+    1342                 :            : 
+    1343                 :          6 :         spdm_response_size = sizeof(spdm_algorithms_response_t);
+    1344                 :          6 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1345                 :          6 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1346                 :            : 
+    1347                 :          6 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+    1348                 :          6 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+    1349                 :          6 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+    1350                 :          6 :         spdm_response->header.param1 = 0;
+    1351                 :          6 :         spdm_response->header.param2 = 0;
+    1352                 :          6 :         spdm_response->length = sizeof(spdm_algorithms_response_t);
+    1353                 :          6 :         spdm_response->measurement_specification_sel =
+    1354                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1355                 :          6 :         spdm_response->measurement_hash_algo =
+    1356                 :            :             m_libspdm_use_measurement_hash_algo;
+    1357                 :          6 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+    1358                 :          6 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+    1359                 :          6 :         spdm_response->ext_asym_sel_count = 0;
+    1360                 :          6 :         spdm_response->ext_hash_sel_count = 0;
+    1361                 :          6 :         spdm_response->other_params_selection = m_connection_other_params_support;
+    1362                 :            : 
+    1363                 :          6 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1364                 :            :                                               false, spdm_response_size,
+    1365                 :            :                                               spdm_response,
+    1366                 :            :                                               response_size, response);
+    1367                 :            :     }
+    1368                 :          6 :         return LIBSPDM_STATUS_SUCCESS;
+    1369                 :          8 :     case 0x24:
+    1370                 :            :     {
+    1371                 :            :         libspdm_algorithms_response_spdm11_t *spdm_response;
+    1372                 :            :         size_t spdm_response_size;
+    1373                 :            :         size_t transport_header_size;
+    1374                 :            : 
+    1375                 :          8 :         spdm_response_size = sizeof(libspdm_algorithms_response_spdm11_t);
+    1376                 :          8 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1377                 :          8 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1378                 :            : 
+    1379                 :          8 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+    1380                 :          8 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+    1381                 :          8 :         spdm_response->header.request_response_code = SPDM_ALGORITHMS;
+    1382                 :          8 :         spdm_response->header.param1 = 4;
+    1383                 :          8 :         spdm_response->header.param2 = 0;
+    1384                 :          8 :         spdm_response->length = sizeof(libspdm_algorithms_response_spdm11_t);
+    1385                 :          8 :         spdm_response->measurement_specification_sel =
+    1386                 :            :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1387                 :          8 :         spdm_response->measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
+    1388                 :          8 :         spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
+    1389                 :          8 :         spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
+    1390                 :          8 :         spdm_response->ext_asym_sel_count = 0;
+    1391                 :          8 :         spdm_response->ext_hash_sel_count = 0;
+    1392                 :          8 :         spdm_response->mel_specification_sel = m_mel_specification_sel;
+    1393                 :          8 :         spdm_response->other_params_selection = SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
+    1394                 :            : 
+    1395                 :          8 :         spdm_response->struct_table[0].alg_type =
+    1396                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE;
+    1397                 :          8 :         spdm_response->struct_table[0].alg_count = 0x20;
+    1398                 :          8 :         spdm_response->struct_table[0].alg_supported = m_libspdm_use_dhe_algo;
+    1399                 :          8 :         spdm_response->struct_table[1].alg_type =
+    1400                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD;
+    1401                 :          8 :         spdm_response->struct_table[1].alg_count = 0x20;
+    1402                 :          8 :         spdm_response->struct_table[1].alg_supported = m_libspdm_use_aead_algo;
+    1403                 :          8 :         spdm_response->struct_table[2].alg_type =
+    1404                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG;
+    1405                 :          8 :         spdm_response->struct_table[2].alg_count = 0x20;
+    1406                 :          8 :         spdm_response->struct_table[2].alg_supported = m_libspdm_use_req_asym_algo;
+    1407                 :          8 :         spdm_response->struct_table[3].alg_type =
+    1408                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE;
+    1409                 :          8 :         spdm_response->struct_table[3].alg_count = 0x20;
+    1410                 :          8 :         spdm_response->struct_table[3].alg_supported = m_libspdm_use_key_schedule_algo;
+    1411                 :            : 
+    1412                 :          8 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+    1413                 :            :                                                spdm_response_size,
+    1414                 :            :                                                spdm_response, response_size, response);
+    1415                 :            : 
+    1416                 :            :     }
+    1417                 :          8 :         return LIBSPDM_STATUS_SUCCESS;
+    1418                 :          0 :     default:
+    1419                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+    1420                 :            :     }
+    1421                 :            : }
+    1422                 :            : 
+    1423                 :          1 : static void libspdm_test_requester_negotiate_algorithms_case1(void **state)
+    1424                 :            : {
+    1425                 :          1 : }
+    1426                 :            : 
+    1427                 :          1 : static void libspdm_test_requester_negotiate_algorithms_case2(void **state)
+    1428                 :            : {
+    1429                 :            :     libspdm_return_t status;
+    1430                 :            :     libspdm_test_context_t *spdm_test_context;
+    1431                 :            :     libspdm_context_t *spdm_context;
+    1432                 :            : 
+    1433                 :          1 :     spdm_test_context = *state;
+    1434                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1435                 :          1 :     spdm_test_context->case_id = 0x2;
+    1436                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1437                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1438                 :          1 :     spdm_context->connection_info.connection_state =
+    1439                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1440                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    1441                 :            :         m_libspdm_use_measurement_hash_algo;
+    1442                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1443                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1444                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP;
+    1445                 :          1 :     spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1446                 :            : 
+    1447                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1448                 :            : 
+    1449                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    1450                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1451                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1452                 :            :     assert_int_equal(spdm_context->transcript.message_a.buffer_size,
+    1453                 :            :                      sizeof(spdm_negotiate_algorithms_request_t) +
+    1454                 :            :                      sizeof(spdm_algorithms_response_t));
+    1455                 :            : #endif
+    1456                 :          1 : }
+    1457                 :            : 
+    1458                 :            : /**
+    1459                 :            :  * Case 3:
+    1460                 :            :  * +---------------+--------------------------+--------------------------+-----------------------------------+
+    1461                 :            :  * | MEAS_CAP | MeasurementSpecification   | MeasurementSpecificationSel |          Expected result          |
+    1462                 :            :  * |          | NEGOTIATE_ALGORITHMS       |       ALGORITHMS            |                                   |
+    1463                 :            :  * +----------+----------------------------+-----------------------------+-----------------------------------+
+    1464                 :            :  * | set      | DMTFmeasSpec               | DMTFmeasSpec                | LIBSPDM_STATUS_SUCCESS            |
+    1465                 :            :  *  ---------------------------------------------------------------------------------------------------------+
+    1466                 :            :  * | set      | DMTFmeasSpec               | 0                           | LIBSPDM_STATUS_INVALID_MSG_FIELD  |
+    1467                 :            :  *  ----------------------------------------------------------------------------------------------------------
+    1468                 :            :  * | set      | 0                          | DMTFmeasSpec                | LIBSPDM_STATUS_INVALID_MSG_FIELD  |
+    1469                 :            :  *  ---------------------------------------------------------------------------------------------------------+
+    1470                 :            :  * | set      | 0                          | 0                           | LIBSPDM_STATUS_SUCCESS            |
+    1471                 :            :  *  ----------------------------------------------------------------------------------------------------------
+    1472                 :            :  * | Not set  | DMTFmeasSpec               | DMTFmeasSpec                | LIBSPDM_STATUS_INVALID_MSG_FIELD  |
+    1473                 :            :  *  ---------------------------------------------------------------------------------------------------------+
+    1474                 :            :  * | Not set  | DMTFmeasSpec               | 0                           | LIBSPDM_STATUS_SUCCESS            |
+    1475                 :            :  *  ----------------------------------------------------------------------------------------------------------
+    1476                 :            :  * | Not set  | 0                          | DMTFmeasSpec                | LIBSPDM_STATUS_INVALID_MSG_FIELD  |
+    1477                 :            :  *  ---------------------------------------------------------------------------------------------------------+
+    1478                 :            :  * | Not set  | 0                          | 0                           | LIBSPDM_STATUS_SUCCESS            |
+    1479                 :            :  *  ----------------------------------------------------------------------------------------------------------
+    1480                 :            :  **/
+    1481                 :          1 : static void libspdm_test_requester_negotiate_algorithms_case3(void **state)
+    1482                 :            : {
+    1483                 :            :     libspdm_return_t status;
+    1484                 :            :     libspdm_test_context_t *spdm_test_context;
+    1485                 :            :     libspdm_context_t *spdm_context;
+    1486                 :          1 :     spdm_test_context = *state;
+    1487                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1488                 :          1 :     spdm_test_context->case_id = 0x3;
+    1489                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1490                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1491                 :          1 :     spdm_context->connection_info.connection_state =
+    1492                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1493                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    1494                 :            :         m_libspdm_use_measurement_hash_algo;
+    1495                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1496                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1497                 :          1 :     spdm_context->connection_info.capability.flags = 0;
+    1498                 :            : 
+    1499                 :            :     /* Sub Case 1: MEAS_CAP set 1, measurement_spec_sel and measurement_spec set SPDM_MEASUREMENT_SPECIFICATION_DMTF*/
+    1500                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP;
+    1501                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1502                 :          1 :     m_measurement_specification_sel = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1503                 :          1 :     spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1504                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1505                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    1506                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1507                 :            : 
+    1508                 :            :     /* Sub Case 2: MEAS_CAP set 1, measurement_spec_sel set 0 , measurement_spec set SPDM_MEASUREMENT_SPECIFICATION_DMTF*/
+    1509                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1510                 :          1 :     m_measurement_specification_sel = 0;
+    1511                 :          1 :     spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1512                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1513                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    1514                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1515                 :            : 
+    1516                 :            :     /* Sub Case 3: MEAS_CAP set 1, measurement_spec_sel set SPDM_MEASUREMENT_SPECIFICATION_DMTF , measurement_spec set 0*/
+    1517                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1518                 :          1 :     m_measurement_specification_sel = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1519                 :          1 :     spdm_context->local_context.algorithm.measurement_spec = 0;
+    1520                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1521                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    1522                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1523                 :            : 
+    1524                 :            :     /* Sub Case 4: MEAS_CAP set 1,measurement_spec_sel set 0 , measurement_spec set 0*/
+    1525                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1526                 :          1 :     m_measurement_specification_sel = 0;
+    1527                 :          1 :     spdm_context->local_context.algorithm.measurement_spec = 0;
+    1528                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1529                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    1530                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1531                 :            : 
+    1532                 :            :     /* Sub Case 5:MEAS_CAP set 0, measurement_spec_sel and measurement_spec set SPDM_MEASUREMENT_SPECIFICATION_DMTF*/
+    1533                 :          1 :     spdm_context->connection_info.capability.flags = 0;
+    1534                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1535                 :          1 :     m_measurement_specification_sel = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1536                 :          1 :     spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1537                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1538                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    1539                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1540                 :            : 
+    1541                 :            :     /* Sub Case 6: MEAS_CAP set 0, measurement_spec_sel set 0 , measurement_spec set SPDM_MEASUREMENT_SPECIFICATION_DMTF*/
+    1542                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1543                 :          1 :     m_measurement_specification_sel = 0;
+    1544                 :          1 :     spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1545                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1546                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    1547                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1548                 :            : 
+    1549                 :            :     /* Sub Case 7: MEAS_CAP set 0,measurement_spec_sel set SPDM_MEASUREMENT_SPECIFICATION_DMTF , measurement_spec set 0*/
+    1550                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1551                 :          1 :     m_measurement_specification_sel = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1552                 :          1 :     spdm_context->local_context.algorithm.measurement_spec = 0;
+    1553                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1554                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    1555                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1556                 :            : 
+    1557                 :            :     /* Sub Case 8: MEAS_CAP set 0,measurement_spec_sel set 0 , measurement_spec set 0*/
+    1558                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1559                 :          1 :     m_measurement_specification_sel = 0;
+    1560                 :          1 :     spdm_context->local_context.algorithm.measurement_spec = 0;
+    1561                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1562                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    1563                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1564                 :          1 : }
+    1565                 :            : 
+    1566                 :          1 : static void libspdm_test_requester_negotiate_algorithms_case4(void **state)
+    1567                 :            : {
+    1568                 :          1 : }
+    1569                 :            : 
+    1570                 :          1 : static void libspdm_test_requester_negotiate_algorithms_case5(void **state)
+    1571                 :            : {
+    1572                 :          1 : }
+    1573                 :            : 
+    1574                 :          1 : static void libspdm_test_requester_negotiate_algorithms_case6(void **state)
+    1575                 :            : {
+    1576                 :            :     libspdm_return_t status;
+    1577                 :            :     libspdm_test_context_t *spdm_test_context;
+    1578                 :            :     libspdm_context_t *spdm_context;
+    1579                 :            : 
+    1580                 :          1 :     spdm_test_context = *state;
+    1581                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1582                 :          1 :     spdm_test_context->case_id = 0x6;
+    1583                 :          1 :     spdm_context->retry_times = 3;
+    1584                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1585                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1586                 :          1 :     spdm_context->connection_info.connection_state =
+    1587                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1588                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    1589                 :            :         m_libspdm_use_measurement_hash_algo;
+    1590                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1591                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1592                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP;
+    1593                 :          1 :     spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1594                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1595                 :            : 
+    1596                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    1597                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1598                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1599                 :            :     assert_int_equal(spdm_context->transcript.message_a.buffer_size,
+    1600                 :            :                      sizeof(spdm_negotiate_algorithms_request_t) +
+    1601                 :            :                      sizeof(spdm_algorithms_response_t));
+    1602                 :            : #endif
+    1603                 :          1 : }
+    1604                 :            : 
+    1605                 :          1 : static void libspdm_test_requester_negotiate_algorithms_case7(void **state)
+    1606                 :            : {
+    1607                 :          1 : }
+    1608                 :            : 
+    1609                 :          1 : static void libspdm_test_requester_negotiate_algorithms_case8(void **state)
+    1610                 :            : {
+    1611                 :          1 : }
+    1612                 :            : 
+    1613                 :          1 : static void libspdm_test_requester_negotiate_algorithms_case9(void **state)
+    1614                 :            : {
+    1615                 :          1 : }
+    1616                 :            : 
+    1617                 :          1 : static void libspdm_test_requester_negotiate_algorithms_case10(void **state)
+    1618                 :            : {
+    1619                 :          1 : }
+    1620                 :            : 
+    1621                 :          1 : static void libspdm_test_requester_negotiate_algorithms_case11(void **state)
+    1622                 :            : {
+    1623                 :          1 : }
+    1624                 :            : 
+    1625                 :          1 : static void libspdm_test_requester_negotiate_algorithms_case12(void **state)
+    1626                 :            : {
+    1627                 :          1 : }
+    1628                 :            : 
+    1629                 :          1 : static void libspdm_test_requester_negotiate_algorithms_case13(void **state)
+    1630                 :            : {
+    1631                 :            : 
+    1632                 :          1 : }
+    1633                 :            : 
+    1634                 :          1 : static void libspdm_test_requester_negotiate_algorithms_case14(void **state)
+    1635                 :            : {
+    1636                 :          1 : }
+    1637                 :            : 
+    1638                 :          1 : static void libspdm_test_requester_negotiate_algorithms_case15(void **state)
+    1639                 :            : {
+    1640                 :          1 : }
+    1641                 :            : 
+    1642                 :          1 : static void libspdm_test_requester_negotiate_algorithms_case16(void **state)
+    1643                 :            : {
+    1644                 :          1 : }
+    1645                 :            : 
+    1646                 :          1 : static void libspdm_test_requester_negotiate_algorithms_case17(void **state)
+    1647                 :            : {
+    1648                 :          1 : }
+    1649                 :            : 
+    1650                 :          1 : static void libspdm_test_requester_negotiate_algorithms_case18(void **state)
+    1651                 :            : {
+    1652                 :          1 : }
+    1653                 :            : 
+    1654                 :          1 : static void libspdm_test_requester_negotiate_algorithms_case19(void **state)
+    1655                 :            : {
+    1656                 :          1 : }
+    1657                 :            : 
+    1658                 :          1 : static void libspdm_test_requester_negotiate_algorithms_case20(void **state)
+    1659                 :            : {
+    1660                 :          1 : }
+    1661                 :            : 
+    1662                 :          1 : static void libspdm_test_requester_negotiate_algorithms_case21(void **state)
+    1663                 :            : {
+    1664                 :          1 : }
+    1665                 :            : 
+    1666                 :          1 : static void libspdm_test_requester_negotiate_algorithms_case22(void **state)
+    1667                 :            : {
+    1668                 :          1 : }
+    1669                 :            : 
+    1670                 :          1 : static void libspdm_test_requester_negotiate_algorithms_case23(void **state)
+    1671                 :            : {
+    1672                 :            :     libspdm_return_t status;
+    1673                 :            :     libspdm_test_context_t *spdm_test_context;
+    1674                 :            :     libspdm_context_t *spdm_context;
+    1675                 :            : 
+    1676                 :          1 :     spdm_test_context = *state;
+    1677                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1678                 :          1 :     spdm_test_context->case_id = 0x17;
+    1679                 :            : 
+    1680                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1681                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1682                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1683                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    1684                 :            :         m_libspdm_use_measurement_hash_algo;
+    1685                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1686                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1687                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1688                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    1689                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    1690                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    1691                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    1692                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP;
+    1693                 :          1 :     spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1694                 :            : 
+    1695                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    1696                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1697                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    1698                 :            : 
+    1699                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    1700                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1701                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    1702                 :            : 
+    1703                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    1704                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    1705                 :            : 
+    1706                 :          1 :     spdm_context->local_context.capability.flags |=
+    1707                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    1708                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1709                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    1710                 :            : 
+    1711                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1712                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1713                 :            : 
+    1714                 :          1 :     status = libspdm_negotiate_algorithms (spdm_context);
+    1715                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+    1716                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1717                 :            :     assert_int_equal (spdm_context->transcript.message_a.buffer_size,
+    1718                 :            :                       sizeof(spdm_negotiate_algorithms_request_t) + 4*
+    1719                 :            :                       sizeof(spdm_negotiate_algorithms_common_struct_table_t) +
+    1720                 :            :                       sizeof(libspdm_algorithms_response_spdm11_t));
+    1721                 :            : #endif
+    1722                 :          1 : }
+    1723                 :            : 
+    1724                 :          1 : static void libspdm_test_requester_negotiate_algorithms_case24(void **state)
+    1725                 :            : {
+    1726                 :          1 : }
+    1727                 :            : 
+    1728                 :          1 : static void libspdm_test_requester_negotiate_algorithms_case25(void **state)
+    1729                 :            : {
+    1730                 :          1 : }
+    1731                 :            : 
+    1732                 :          1 : static void libspdm_test_requester_negotiate_algorithms_case26(void **state)
+    1733                 :            : {
+    1734                 :          1 : }
+    1735                 :            : 
+    1736                 :          1 : static void libspdm_test_requester_negotiate_algorithms_case27(void **state)
+    1737                 :            : {
+    1738                 :          1 : }
+    1739                 :            : 
+    1740                 :          1 : static void libspdm_test_requester_negotiate_algorithms_case28(void **state)
+    1741                 :            : {
+    1742                 :          1 : }
+    1743                 :            : 
+    1744                 :          1 : static void libspdm_test_requester_negotiate_algorithms_case29(void **state)
+    1745                 :            : {
+    1746                 :          1 : }
+    1747                 :            : 
+    1748                 :          1 : static void libspdm_test_requester_negotiate_algorithms_case30(void **state)
+    1749                 :            : {
+    1750                 :          1 : }
+    1751                 :            : 
+    1752                 :          1 : static void libspdm_test_requester_negotiate_algorithms_case31(void **state)
+    1753                 :            : {
+    1754                 :          1 : }
+    1755                 :            : 
+    1756                 :          1 : static void libspdm_test_requester_negotiate_algorithms_case32(void **state) {
+    1757                 :            :     libspdm_return_t status;
+    1758                 :            :     libspdm_test_context_t *spdm_test_context;
+    1759                 :            :     libspdm_context_t *spdm_context;
+    1760                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1761                 :            :     size_t arbitrary_size;
+    1762                 :            : #endif
+    1763                 :            : 
+    1764                 :          1 :     spdm_test_context = *state;
+    1765                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1766                 :          1 :     spdm_test_context->case_id = 0x20;
+    1767                 :            : 
+    1768                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1769                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1770                 :          1 :     spdm_context->connection_info.connection_state =
+    1771                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1772                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    1773                 :            :         m_libspdm_use_measurement_hash_algo;
+    1774                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1775                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1776                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1777                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    1778                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    1779                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    1780                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    1781                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP;
+    1782                 :          1 :     spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1783                 :            : 
+    1784                 :          1 :     spdm_context->local_context.capability.flags |=
+    1785                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    1786                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1787                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    1788                 :            : 
+    1789                 :          1 :     spdm_context->local_context.capability.flags |=
+    1790                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    1791                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1792                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    1793                 :            : 
+    1794                 :          1 :     spdm_context->local_context.capability.flags |=
+    1795                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    1796                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1797                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    1798                 :            : 
+    1799                 :          1 :     spdm_context->local_context.capability.flags |=
+    1800                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    1801                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1802                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    1803                 :            : 
+    1804                 :          1 :     spdm_context->local_context.capability.flags |=
+    1805                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1806                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1807                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1808                 :            : 
+    1809                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1810                 :            :     /*filling A with arbitrary data*/
+    1811                 :            :     arbitrary_size = 10;
+    1812                 :            :     libspdm_set_mem(spdm_context->transcript.message_a.buffer, arbitrary_size, (uint8_t) 0xFF);
+    1813                 :            :     spdm_context->transcript.message_a.buffer_size = arbitrary_size;
+    1814                 :            : #endif
+    1815                 :            : 
+    1816                 :          1 :     status = libspdm_negotiate_algorithms (spdm_context);
+    1817                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+    1818                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1819                 :            :     assert_int_equal (spdm_context->transcript.message_a.buffer_size,
+    1820                 :            :                       arbitrary_size + m_libspdm_local_buffer_size);
+    1821                 :            :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer (0x%x):\n",
+    1822                 :            :                    m_libspdm_local_buffer_size));
+    1823                 :            :     libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    1824                 :            :     assert_memory_equal(spdm_context->transcript.message_a.buffer + arbitrary_size,
+    1825                 :            :                         m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    1826                 :            : #endif
+    1827                 :          1 : }
+    1828                 :            : 
+    1829                 :          1 : static void libspdm_test_requester_negotiate_algorithms_case33(void **state) {
+    1830                 :            :     libspdm_return_t status;
+    1831                 :            :     libspdm_test_context_t    *spdm_test_context;
+    1832                 :            :     libspdm_context_t  *spdm_context;
+    1833                 :            : 
+    1834                 :          1 :     spdm_test_context = *state;
+    1835                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1836                 :          1 :     spdm_test_context->case_id = 0x21;
+    1837                 :            : 
+    1838                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    1839                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1840                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    1841                 :            :         m_libspdm_use_measurement_hash_algo;
+    1842                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1843                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1844                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1845                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    1846                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    1847                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    1848                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    1849                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    1850                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1851                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    1852                 :            : 
+    1853                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    1854                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1855                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    1856                 :            : 
+    1857                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    1858                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    1859                 :            : 
+    1860                 :          1 :     spdm_context->local_context.capability.flags |=
+    1861                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    1862                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1863                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    1864                 :            : 
+    1865                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1866                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1867                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP;
+    1868                 :          1 :     spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1869                 :            : 
+    1870                 :            :     /* Sub Case 1: other_params_support set OpaqueDataFmt1 */
+    1871                 :          1 :     spdm_context->local_context.algorithm.other_params_support =
+    1872                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
+    1873                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1874                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1875                 :            : 
+    1876                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    1877                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+    1878                 :          1 :     assert_int_equal(spdm_context->connection_info.algorithm.other_params_support,
+    1879                 :            :                      SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1);
+    1880                 :            : 
+    1881                 :            :     /* Sub Case 2: Populate reserved field for version 1.2, field values marked as Reserved shall be written as zero ( 0 )*/
+    1882                 :          1 :     spdm_context->local_context.algorithm.other_params_support =
+    1883                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1 |
+    1884                 :            :         SPDM_ALGORITHMS_MULTI_KEY_CONN;
+    1885                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1886                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1887                 :            : 
+    1888                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    1889                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+    1890                 :          1 :     assert_int_equal(spdm_context->connection_info.algorithm.other_params_support,
+    1891                 :            :                      SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1);
+    1892                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1893                 :            :     assert_int_equal (spdm_context->transcript.message_a.buffer_size,
+    1894                 :            :                       sizeof(spdm_negotiate_algorithms_request_t) + 4*
+    1895                 :            :                       sizeof(spdm_negotiate_algorithms_common_struct_table_t) +
+    1896                 :            :                       sizeof(libspdm_algorithms_response_spdm11_t));
+    1897                 :            : #endif
+    1898                 :          1 : }
+    1899                 :            : 
+    1900                 :            : 
+    1901                 :          1 : static void libspdm_test_requester_negotiate_algorithms_case34(void **state)
+    1902                 :            : {
+    1903                 :          1 : }
+    1904                 :            : 
+    1905                 :            : /**
+    1906                 :            :  * Test 35: MULTI_KEY_CONN_REQ and MULTI_KEY_CONN_RSP value calculation
+    1907                 :            :  * +---------------+--------------------------+--------------------+
+    1908                 :            :  * | MULTI_KEY_CAP | RequesterMultiKeyConnSel | MULTI_KEY_CONN_REQ |
+    1909                 :            :  * +---------------+--------------------------+--------------------+
+    1910                 :            :  * | 00b           | 0                        | false              |
+    1911                 :            :  *  ----------------------------------------------------------------
+    1912                 :            :  * | 00b           | 1                        | invalid            |
+    1913                 :            :  *  ----------------------------------------------------------------
+    1914                 :            :  * | 01b           | 0                        | invalid            |
+    1915                 :            :  *  ----------------------------------------------------------------
+    1916                 :            :  * | 01b           | 1                        | true               |
+    1917                 :            :  *  ----------------------------------------------------------------
+    1918                 :            :  * | 10b           | 0                        | false              |
+    1919                 :            :  *  ----------------------------------------------------------------
+    1920                 :            :  * | 10b           | 1                        | true               |
+    1921                 :            :  * +---------------+--------------------------+--------------------+
+    1922                 :            :  * | MULTI_KEY_CAP | ResponderMultiKeyConn    | MULTI_KEY_CONN_RSP |
+    1923                 :            :  * +---------------+--------------------------+--------------------+
+    1924                 :            :  * | 00b           | 0                        | false              |
+    1925                 :            :  *  ----------------------------------------------------------------
+    1926                 :            :  * | 00b           | 1                        | invalid            |
+    1927                 :            :  *  ----------------------------------------------------------------
+    1928                 :            :  * | 01b           | 0                        | invalid            |
+    1929                 :            :  *  ----------------------------------------------------------------
+    1930                 :            :  * | 01b           | 1                        | true               |
+    1931                 :            :  *  ----------------------------------------------------------------
+    1932                 :            :  * | 10b           | 0                        | false              |
+    1933                 :            :  *  ----------------------------------------------------------------
+    1934                 :            :  * | 10b           | 1                        | true               |
+    1935                 :            :  *  ----------------------------------------------------------------
+    1936                 :            :  **/
+    1937                 :          1 : static void libspdm_test_requester_negotiate_algorithms_case35(void **state)
+    1938                 :            : {
+    1939                 :            :     libspdm_return_t status;
+    1940                 :            :     libspdm_test_context_t *spdm_test_context;
+    1941                 :            :     libspdm_context_t *spdm_context;
+    1942                 :            : 
+    1943                 :          1 :     spdm_test_context = *state;
+    1944                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1945                 :          1 :     spdm_test_context->case_id = 0x23;
+    1946                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+    1947                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1948                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    1949                 :            :         m_libspdm_use_measurement_hash_algo;
+    1950                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1951                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1952                 :            : 
+    1953                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1954                 :          1 :     spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    1955                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1956                 :            : 
+    1957                 :          1 :     spdm_context->connection_info.capability.flags = 0;
+    1958                 :          1 :     spdm_context->local_context.capability.flags = 0;
+    1959                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP;
+    1960                 :          1 :     spdm_context->local_context.algorithm.other_params_support = 0;
+    1961                 :          1 :     m_connection_other_params_support = 0;
+    1962                 :            : 
+    1963                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    1964                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1965                 :          1 :     assert_int_equal(spdm_context->connection_info.multi_key_conn_rsp, false);
+    1966                 :          1 :     assert_int_equal(spdm_context->connection_info.multi_key_conn_req, false);
+    1967                 :            : 
+    1968                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1969                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1970                 :            : 
+    1971                 :          1 :     spdm_context->connection_info.capability.flags = 0;
+    1972                 :          1 :     spdm_context->local_context.capability.flags = 0;
+    1973                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP;
+    1974                 :          1 :     spdm_context->local_context.algorithm.other_params_support = SPDM_ALGORITHMS_MULTI_KEY_CONN;
+    1975                 :          1 :     m_connection_other_params_support = SPDM_ALGORITHMS_MULTI_KEY_CONN;
+    1976                 :            : 
+    1977                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    1978                 :            :     /* MULTI_KEY_CONN_REQ and MULTI_KEY_CONN_RSP invalid */
+    1979                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_NEGOTIATION_FAIL);
+    1980                 :            : 
+    1981                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1982                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1983                 :            : 
+    1984                 :          1 :     spdm_context->connection_info.capability.flags =
+    1985                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MULTI_KEY_CAP_ONLY;
+    1986                 :          1 :     spdm_context->local_context.capability.flags =
+    1987                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MULTI_KEY_CAP_ONLY;
+    1988                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP;
+    1989                 :          1 :     spdm_context->local_context.algorithm.other_params_support = 0;
+    1990                 :          1 :     m_connection_other_params_support = 0;
+    1991                 :            : 
+    1992                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    1993                 :            :     /* MULTI_KEY_CONN_REQ and MULTI_KEY_CONN_RSP invalid */
+    1994                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_NEGOTIATION_FAIL);
+    1995                 :            : 
+    1996                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1997                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1998                 :            : 
+    1999                 :          1 :     spdm_context->connection_info.capability.flags =
+    2000                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MULTI_KEY_CAP_ONLY;
+    2001                 :          1 :     spdm_context->local_context.capability.flags =
+    2002                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MULTI_KEY_CAP_ONLY;
+    2003                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP;
+    2004                 :          1 :     spdm_context->local_context.algorithm.other_params_support = SPDM_ALGORITHMS_MULTI_KEY_CONN;
+    2005                 :          1 :     m_connection_other_params_support = SPDM_ALGORITHMS_MULTI_KEY_CONN;
+    2006                 :            : 
+    2007                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    2008                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2009                 :          1 :     assert_int_equal(spdm_context->connection_info.multi_key_conn_rsp, true);
+    2010                 :          1 :     assert_int_equal(spdm_context->connection_info.multi_key_conn_req, true);
+    2011                 :            : 
+    2012                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2013                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2014                 :            : 
+    2015                 :          1 :     spdm_context->connection_info.capability.flags =
+    2016                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MULTI_KEY_CAP_NEG;
+    2017                 :          1 :     spdm_context->local_context.capability.flags =
+    2018                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MULTI_KEY_CAP_NEG;
+    2019                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP;
+    2020                 :          1 :     spdm_context->local_context.algorithm.other_params_support = 0;
+    2021                 :          1 :     m_connection_other_params_support = 0;
+    2022                 :            : 
+    2023                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    2024                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2025                 :          1 :     assert_int_equal(spdm_context->connection_info.multi_key_conn_rsp, false);
+    2026                 :          1 :     assert_int_equal(spdm_context->connection_info.multi_key_conn_req, false);
+    2027                 :            : 
+    2028                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2029                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2030                 :            : 
+    2031                 :          1 :     spdm_context->connection_info.capability.flags =
+    2032                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MULTI_KEY_CAP_NEG;
+    2033                 :          1 :     spdm_context->local_context.capability.flags =
+    2034                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MULTI_KEY_CAP_NEG;
+    2035                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP;
+    2036                 :          1 :     spdm_context->local_context.algorithm.other_params_support = SPDM_ALGORITHMS_MULTI_KEY_CONN;
+    2037                 :          1 :     m_connection_other_params_support = SPDM_ALGORITHMS_MULTI_KEY_CONN;
+    2038                 :            : 
+    2039                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    2040                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2041                 :          1 :     assert_int_equal(spdm_context->connection_info.multi_key_conn_rsp, true);
+    2042                 :          1 :     assert_int_equal(spdm_context->connection_info.multi_key_conn_req, true);
+    2043                 :          1 : }
+    2044                 :            : 
+    2045                 :            : /**
+    2046                 :            :  * Test 36: ALGORITHMS message received with MEL
+    2047                 :            :  * +---------------+--------------------------+--------------------------+-----------------------------------+
+    2048                 :            :  * | MEAS_CAP |       MELspecification     |     MELspecificationSel     |          Expected result          |
+    2049                 :            :  * |          |     NEGOTIATE_ALGORITHMS   |         ALGORITHMS          |                                   |
+    2050                 :            :  * +----------+----------------------------+-----------------------------+-----------------------------------+
+    2051                 :            :  * | set      | DMTFmeasSpec               | DMTFmeasSpec                | LIBSPDM_STATUS_SUCCESS            |
+    2052                 :            :  *  ---------------------------------------------------------------------------------------------------------+
+    2053                 :            :  * | set      | DMTFmeasSpec               | 0                           | LIBSPDM_STATUS_INVALID_MSG_FIELD  |
+    2054                 :            :  *  ----------------------------------------------------------------------------------------------------------
+    2055                 :            :  * | set      | 0                          | DMTFmeasSpec                | LIBSPDM_STATUS_INVALID_MSG_FIELD  |
+    2056                 :            :  *  ---------------------------------------------------------------------------------------------------------+
+    2057                 :            :  * | set      | 0                          | 0                           | LIBSPDM_STATUS_SUCCESS            |
+    2058                 :            :  *  ----------------------------------------------------------------------------------------------------------
+    2059                 :            :  * | Not set  | DMTFmeasSpec               | DMTFmeasSpec                | LIBSPDM_STATUS_INVALID_MSG_FIELD  |
+    2060                 :            :  *  ---------------------------------------------------------------------------------------------------------+
+    2061                 :            :  * | Not set  | DMTFmeasSpec               | 0                           | LIBSPDM_STATUS_SUCCESS            |
+    2062                 :            :  *  ----------------------------------------------------------------------------------------------------------
+    2063                 :            :  * | Not set  | 0                          | DMTFmeasSpec                | LIBSPDM_STATUS_INVALID_MSG_FIELD  |
+    2064                 :            :  *  ---------------------------------------------------------------------------------------------------------+
+    2065                 :            :  * | Not set  | 0                          | 0                           | LIBSPDM_STATUS_SUCCESS            |
+    2066                 :            :  *  ----------------------------------------------------------------------------------------------------------
+    2067                 :            :  **/
+    2068                 :          1 : static void libspdm_test_requester_negotiate_algorithms_case36(void **state)
+    2069                 :            : {
+    2070                 :            :     libspdm_return_t status;
+    2071                 :            :     libspdm_test_context_t *spdm_test_context;
+    2072                 :            :     libspdm_context_t *spdm_context;
+    2073                 :            :     uint32_t local_capability_flags;
+    2074                 :            :     uint32_t connection_capability_flags;
+    2075                 :            : 
+    2076                 :          1 :     spdm_test_context = *state;
+    2077                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2078                 :          1 :     spdm_test_context->case_id = 0x24;
+    2079                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+    2080                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2081                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    2082                 :            :         m_libspdm_use_measurement_hash_algo;
+    2083                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2084                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2085                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    2086                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    2087                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    2088                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    2089                 :          1 :     spdm_context->local_context.algorithm.other_params_support = 0;
+    2090                 :            : 
+    2091                 :          1 :     local_capability_flags = SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
+    2092                 :            :                              SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP|
+    2093                 :            :                              SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP|
+    2094                 :            :                              SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP|
+    2095                 :            :                              SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    2096                 :          1 :     connection_capability_flags =
+    2097                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
+    2098                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP |
+    2099                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP |
+    2100                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP |
+    2101                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP |
+    2102                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    2103                 :            : 
+    2104                 :          1 :     spdm_context->connection_info.capability.flags = connection_capability_flags;
+    2105                 :          1 :     spdm_context->local_context.capability.flags = local_capability_flags;
+    2106                 :            : 
+    2107                 :            :     /* Sub Case 1: MEL_CAP set 1, mel_specification_sel and mel_specification set SPDM_MEL_SPECIFICATION_DMTF*/
+    2108                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEL_CAP;
+    2109                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2110                 :          1 :     m_mel_specification_sel = SPDM_MEL_SPECIFICATION_DMTF;
+    2111                 :          1 :     spdm_context->local_context.algorithm.mel_spec = SPDM_MEL_SPECIFICATION_DMTF;
+    2112                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2113                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    2114                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2115                 :            : 
+    2116                 :            :     /* Sub Case 2: MEL_CAP set 1, mel_specification_sel set 0 , mel_specification set SPDM_MEL_SPECIFICATION_DMTF*/
+    2117                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEL_CAP;
+    2118                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2119                 :          1 :     m_mel_specification_sel = 0;
+    2120                 :          1 :     spdm_context->local_context.algorithm.mel_spec = SPDM_MEL_SPECIFICATION_DMTF;
+    2121                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2122                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    2123                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    2124                 :            : 
+    2125                 :            :     /* Sub Case 3: MEL_CAP set 1, mel_specification_sel set SPDM_MEL_SPECIFICATION_DMTF , mel_specification set 0*/
+    2126                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEL_CAP;
+    2127                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2128                 :          1 :     m_mel_specification_sel = SPDM_MEL_SPECIFICATION_DMTF;
+    2129                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2130                 :          1 :     spdm_context->local_context.algorithm.mel_spec = 0;
+    2131                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    2132                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    2133                 :            : 
+    2134                 :            :     /* Sub Case 4: MEL_CAP set 1,mel_specification_sel set 0 , mel_specification set 0*/
+    2135                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEL_CAP;
+    2136                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2137                 :          1 :     m_mel_specification_sel = 0;
+    2138                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2139                 :          1 :     spdm_context->local_context.algorithm.mel_spec = 0;
+    2140                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    2141                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2142                 :            : 
+    2143                 :            :     /* Sub Case 5:MEL_CAP set 0, mel_specification_sel and mel_specification set SPDM_MEL_SPECIFICATION_DMTF*/
+    2144                 :          1 :     spdm_context->connection_info.capability.flags = connection_capability_flags;
+    2145                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2146                 :          1 :     m_mel_specification_sel = SPDM_MEL_SPECIFICATION_DMTF;
+    2147                 :          1 :     spdm_context->local_context.algorithm.mel_spec = SPDM_MEL_SPECIFICATION_DMTF;
+    2148                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2149                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    2150                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    2151                 :            : 
+    2152                 :            :     /* Sub Case 6: MEL_CAP set 0, mel_specification_sel set 0 , mel_specification set SPDM_MEL_SPECIFICATION_DMTF*/
+    2153                 :          1 :     spdm_context->connection_info.capability.flags = connection_capability_flags;
+    2154                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2155                 :          1 :     m_mel_specification_sel = 0;
+    2156                 :          1 :     spdm_context->local_context.algorithm.mel_spec = SPDM_MEL_SPECIFICATION_DMTF;
+    2157                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2158                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    2159                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2160                 :            : 
+    2161                 :            :     /* Sub Case 7: MEL_CAP set 0,mel_specification_sel set SPDM_MEL_SPECIFICATION_DMTF , mel_specification set 0*/
+    2162                 :          1 :     spdm_context->connection_info.capability.flags = connection_capability_flags;
+    2163                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2164                 :          1 :     m_mel_specification_sel = SPDM_MEL_SPECIFICATION_DMTF;
+    2165                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2166                 :          1 :     spdm_context->local_context.algorithm.mel_spec = 0;
+    2167                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    2168                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    2169                 :            : 
+    2170                 :            :     /* Sub Case 8: MEL_CAP set 0,mel_specification_sel set 0 , mel_specification set 0*/
+    2171                 :          1 :     spdm_context->connection_info.capability.flags = connection_capability_flags;
+    2172                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2173                 :          1 :     m_mel_specification_sel = 0;
+    2174                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2175                 :          1 :     spdm_context->local_context.algorithm.mel_spec = 0;
+    2176                 :          1 :     status = libspdm_negotiate_algorithms(spdm_context);
+    2177                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2178                 :          1 : }
+    2179                 :            : 
+    2180                 :            : static libspdm_test_context_t m_libspdm_requester_negotiate_algorithms_test_context = {
+    2181                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+    2182                 :            :     true,
+    2183                 :            :     libspdm_requester_negotiate_algorithms_test_send_message,
+    2184                 :            :     libspdm_requester_negotiate_algorithm_test_receive_message,
+    2185                 :            : };
+    2186                 :            : 
+    2187                 :          1 : int libspdm_requester_negotiate_algorithms_test_main(void)
+    2188                 :            : {
+    2189                 :          1 :     const struct CMUnitTest spdm_requester_negotiate_algorithms_tests[] = {
+    2190                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case1),
+    2191                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case2),
+    2192                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case3),
+    2193                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case4),
+    2194                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case5),
+    2195                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case6),
+    2196                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case7),
+    2197                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case8),
+    2198                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case9),
+    2199                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case10),
+    2200                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case11),
+    2201                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case12),
+    2202                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case13),
+    2203                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case14),
+    2204                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case15),
+    2205                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case16),
+    2206                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case17),
+    2207                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case18),
+    2208                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case19),
+    2209                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case20),
+    2210                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case21),
+    2211                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case22),
+    2212                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case23),
+    2213                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case24),
+    2214                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case25),
+    2215                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case26),
+    2216                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case27),
+    2217                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case28),
+    2218                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case29),
+    2219                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case30),
+    2220                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case31),
+    2221                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case32),
+    2222                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case33),
+    2223                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case34),
+    2224                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case35),
+    2225                 :            :         cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case36),
+    2226                 :            :     };
+    2227                 :            : 
+    2228                 :          1 :     libspdm_setup_test_context(&m_libspdm_requester_negotiate_algorithms_test_context);
+    2229                 :            : 
+    2230                 :          1 :     return cmocka_run_group_tests(spdm_requester_negotiate_algorithms_tests,
+    2231                 :            :                                   libspdm_unit_test_group_setup,
+    2232                 :            :                                   libspdm_unit_test_group_teardown);
+    2233                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/psk_exchange.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_requester/psk_exchange.c.func-sort-c.html new file mode 100644 index 00000000000..61506247446 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/psk_exchange.c.func-sort-c.html @@ -0,0 +1,205 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/psk_exchange.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - psk_exchange.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:2086225192.7 %
Date:2024-09-22 08:21:07Functions:303196.8 %
Branches:9212076.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_test_requester_psk_exchange_case110
libspdm_requester_psk_exchange_test_main1
libspdm_test_requester_psk_exchange_case11
libspdm_test_requester_psk_exchange_case101
libspdm_test_requester_psk_exchange_case121
libspdm_test_requester_psk_exchange_case131
libspdm_test_requester_psk_exchange_case141
libspdm_test_requester_psk_exchange_case151
libspdm_test_requester_psk_exchange_case161
libspdm_test_requester_psk_exchange_case171
libspdm_test_requester_psk_exchange_case181
libspdm_test_requester_psk_exchange_case191
libspdm_test_requester_psk_exchange_case21
libspdm_test_requester_psk_exchange_case201
libspdm_test_requester_psk_exchange_case211
libspdm_test_requester_psk_exchange_case221
libspdm_test_requester_psk_exchange_case231
libspdm_test_requester_psk_exchange_case241
libspdm_test_requester_psk_exchange_case251
libspdm_test_requester_psk_exchange_case261
libspdm_test_requester_psk_exchange_case271
libspdm_test_requester_psk_exchange_case31
libspdm_test_requester_psk_exchange_case41
libspdm_test_requester_psk_exchange_case51
libspdm_test_requester_psk_exchange_case61
libspdm_test_requester_psk_exchange_case71
libspdm_test_requester_psk_exchange_case81
libspdm_test_requester_psk_exchange_case91
libspdm_test_get_psk_exchange_request_size43
libspdm_requester_psk_exchange_test_receive_message44
libspdm_requester_psk_exchange_test_send_message45
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/psk_exchange.c.func.html b/coverage_log/unit_test/test_spdm_requester/psk_exchange.c.func.html new file mode 100644 index 00000000000..e3f83475a54 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/psk_exchange.c.func.html @@ -0,0 +1,205 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/psk_exchange.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - psk_exchange.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:2086225192.7 %
Date:2024-09-22 08:21:07Functions:303196.8 %
Branches:9212076.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_psk_exchange_test_main1
libspdm_requester_psk_exchange_test_receive_message44
libspdm_requester_psk_exchange_test_send_message45
libspdm_test_get_psk_exchange_request_size43
libspdm_test_requester_psk_exchange_case11
libspdm_test_requester_psk_exchange_case101
libspdm_test_requester_psk_exchange_case110
libspdm_test_requester_psk_exchange_case121
libspdm_test_requester_psk_exchange_case131
libspdm_test_requester_psk_exchange_case141
libspdm_test_requester_psk_exchange_case151
libspdm_test_requester_psk_exchange_case161
libspdm_test_requester_psk_exchange_case171
libspdm_test_requester_psk_exchange_case181
libspdm_test_requester_psk_exchange_case191
libspdm_test_requester_psk_exchange_case21
libspdm_test_requester_psk_exchange_case201
libspdm_test_requester_psk_exchange_case211
libspdm_test_requester_psk_exchange_case221
libspdm_test_requester_psk_exchange_case231
libspdm_test_requester_psk_exchange_case241
libspdm_test_requester_psk_exchange_case251
libspdm_test_requester_psk_exchange_case261
libspdm_test_requester_psk_exchange_case271
libspdm_test_requester_psk_exchange_case31
libspdm_test_requester_psk_exchange_case41
libspdm_test_requester_psk_exchange_case51
libspdm_test_requester_psk_exchange_case61
libspdm_test_requester_psk_exchange_case71
libspdm_test_requester_psk_exchange_case81
libspdm_test_requester_psk_exchange_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/psk_exchange.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/psk_exchange.c.gcov.html new file mode 100644 index 00000000000..bcc66efb414 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/psk_exchange.c.gcov.html @@ -0,0 +1,5189 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/psk_exchange.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - psk_exchange.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:2086225192.7 %
Date:2024-09-22 08:21:07Functions:303196.8 %
Branches:9212076.7 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_requester_lib.h"
+       9                 :            : #include "internal/libspdm_responder_lib.h"
+      10                 :            : 
+      11                 :            : #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
+      12                 :            : 
+      13                 :            : #define LIBSPDM_BIN_STR_2_LABEL "rsp hs data"
+      14                 :            : #define LIBSPDM_BIN_STR_7_LABEL "finished"
+      15                 :            : 
+      16                 :            : static size_t m_libspdm_local_buffer_size;
+      17                 :            : static uint8_t m_libspdm_local_buffer[LIBSPDM_MAX_MESSAGE_TH_BUFFER_SIZE];
+      18                 :            : static uint8_t m_libspdm_zero_filled_buffer[LIBSPDM_MAX_HASH_SIZE];
+      19                 :            : 
+      20                 :            : static libspdm_th_managed_buffer_t th_curr;
+      21                 :            : 
+      22                 :         43 : size_t libspdm_test_get_psk_exchange_request_size(const void *spdm_context,
+      23                 :            :                                                   const void *buffer,
+      24                 :            :                                                   size_t buffer_size)
+      25                 :            : {
+      26                 :            :     const spdm_psk_exchange_request_t *spdm_request;
+      27                 :            :     size_t message_size;
+      28                 :            : 
+      29                 :         43 :     spdm_request = buffer;
+      30                 :         43 :     message_size = sizeof(spdm_message_header_t);
+      31         [ -  + ]:         43 :     if (buffer_size < message_size) {
+      32                 :          0 :         return buffer_size;
+      33                 :            :     }
+      34                 :            : 
+      35         [ +  + ]:         43 :     if (spdm_request->header.request_response_code != SPDM_PSK_EXCHANGE) {
+      36                 :          1 :         return buffer_size;
+      37                 :            :     }
+      38                 :            : 
+      39                 :         42 :     message_size = sizeof(spdm_psk_exchange_request_t);
+      40         [ -  + ]:         42 :     if (buffer_size < message_size) {
+      41                 :          0 :         return buffer_size;
+      42                 :            :     }
+      43                 :            : 
+      44                 :         42 :     message_size += spdm_request->psk_hint_length +
+      45                 :         42 :                     spdm_request->context_length +
+      46                 :         42 :                     spdm_request->opaque_length;
+      47         [ -  + ]:         42 :     if (buffer_size < message_size) {
+      48                 :          0 :         return buffer_size;
+      49                 :            :     }
+      50                 :            : 
+      51                 :            :     /* Good message, return actual size*/
+      52                 :         42 :     return message_size;
+      53                 :            : }
+      54                 :            : 
+      55                 :         45 : libspdm_return_t libspdm_requester_psk_exchange_test_send_message(
+      56                 :            :     void *spdm_context, size_t request_size, const void *request,
+      57                 :            :     uint64_t timeout)
+      58                 :            : {
+      59                 :            :     libspdm_test_context_t *spdm_test_context;
+      60                 :            :     size_t header_size;
+      61                 :            :     size_t message_size;
+      62                 :            : 
+      63                 :         45 :     spdm_test_context = libspdm_get_test_context();
+      64                 :         45 :     header_size = sizeof(libspdm_test_message_header_t);
+      65   [ +  +  -  +  :         45 :     switch (spdm_test_context->case_id) {
+          +  +  +  +  +  
+          +  -  +  +  +  
+          +  +  +  +  +  
+          +  +  +  +  +  
+             +  +  +  - ]
+      66                 :          1 :     case 0x1:
+      67                 :          1 :         return LIBSPDM_STATUS_SEND_FAIL;
+      68                 :          1 :     case 0x2:
+      69                 :          1 :         m_libspdm_local_buffer_size = 0;
+      70                 :          1 :         message_size = libspdm_test_get_psk_exchange_request_size(
+      71                 :            :             spdm_context, (const uint8_t *)request + header_size,
+      72                 :            :             request_size - header_size);
+      73                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+      74                 :            :                          (const uint8_t *)request + header_size, message_size);
+      75                 :          1 :         m_libspdm_local_buffer_size += message_size;
+      76                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      77                 :          0 :     case 0x3:
+      78                 :          0 :         m_libspdm_local_buffer_size = 0;
+      79                 :          0 :         message_size = libspdm_test_get_psk_exchange_request_size(
+      80                 :            :             spdm_context, (const uint8_t *)request + header_size,
+      81                 :            :             request_size - header_size);
+      82                 :          0 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+      83                 :            :                          (const uint8_t *)request + header_size, message_size);
+      84                 :          0 :         m_libspdm_local_buffer_size += message_size;
+      85                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      86                 :          1 :     case 0x4:
+      87                 :          1 :         m_libspdm_local_buffer_size = 0;
+      88                 :          1 :         message_size = libspdm_test_get_psk_exchange_request_size(
+      89                 :            :             spdm_context, (const uint8_t *)request + header_size,
+      90                 :            :             request_size - header_size);
+      91                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+      92                 :            :                          (const uint8_t *)request + header_size, message_size);
+      93                 :          1 :         m_libspdm_local_buffer_size += message_size;
+      94                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      95                 :          1 :     case 0x5:
+      96                 :          1 :         m_libspdm_local_buffer_size = 0;
+      97                 :          1 :         message_size = libspdm_test_get_psk_exchange_request_size(
+      98                 :            :             spdm_context, (const uint8_t *)request + header_size,
+      99                 :            :             request_size - header_size);
+     100                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     101                 :            :                          (const uint8_t *)request + header_size, message_size);
+     102                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     103                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     104                 :          2 :     case 0x6:
+     105                 :          2 :         m_libspdm_local_buffer_size = 0;
+     106                 :          2 :         message_size = libspdm_test_get_psk_exchange_request_size(
+     107                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     108                 :            :             request_size - header_size);
+     109                 :          2 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     110                 :            :                          (const uint8_t *)request + header_size, message_size);
+     111                 :          2 :         m_libspdm_local_buffer_size += message_size;
+     112                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     113                 :          1 :     case 0x7:
+     114                 :          1 :         m_libspdm_local_buffer_size = 0;
+     115                 :          1 :         message_size = libspdm_test_get_psk_exchange_request_size(
+     116                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     117                 :            :             request_size - header_size);
+     118                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     119                 :            :                          (const uint8_t *)request + header_size, message_size);
+     120                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     121                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     122                 :          2 :     case 0x8:
+     123                 :          2 :         m_libspdm_local_buffer_size = 0;
+     124                 :          2 :         message_size = libspdm_test_get_psk_exchange_request_size(
+     125                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     126                 :            :             request_size - header_size);
+     127                 :          2 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     128                 :            :                          (const uint8_t *)request + header_size, message_size);
+     129                 :          2 :         m_libspdm_local_buffer_size += message_size;
+     130                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     131                 :          2 :     case 0x9: {
+     132                 :            :         static size_t sub_index = 0;
+     133         [ +  + ]:          2 :         if (sub_index == 0) {
+     134                 :          1 :             m_libspdm_local_buffer_size = 0;
+     135                 :          1 :             message_size = libspdm_test_get_psk_exchange_request_size(
+     136                 :            :                 spdm_context, (const uint8_t *)request + header_size,
+     137                 :            :                 request_size - header_size);
+     138                 :          1 :             libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     139                 :            :                              (const uint8_t *)request + header_size, message_size);
+     140                 :          1 :             m_libspdm_local_buffer_size += message_size;
+     141                 :          1 :             sub_index++;
+     142                 :            :         }
+     143                 :            :     }
+     144                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     145                 :         18 :     case 0xA:
+     146                 :         18 :         m_libspdm_local_buffer_size = 0;
+     147                 :         18 :         message_size = libspdm_test_get_psk_exchange_request_size(
+     148                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     149                 :            :             request_size - header_size);
+     150                 :         18 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     151                 :            :                          (const uint8_t *)request + header_size, message_size);
+     152                 :         18 :         m_libspdm_local_buffer_size += message_size;
+     153                 :         18 :         return LIBSPDM_STATUS_SUCCESS;
+     154                 :          0 :     case 0xB:
+     155                 :          0 :         m_libspdm_local_buffer_size = 0;
+     156                 :          0 :         message_size = libspdm_test_get_psk_exchange_request_size(
+     157                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     158                 :            :             request_size - header_size);
+     159                 :          0 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     160                 :            :                          (const uint8_t *)request + header_size, message_size);
+     161                 :          0 :         m_libspdm_local_buffer_size += message_size;
+     162                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     163                 :          1 :     case 0xC:
+     164                 :          1 :         m_libspdm_local_buffer_size = 0;
+     165                 :          1 :         message_size = libspdm_test_get_psk_exchange_request_size(
+     166                 :            :             spdm_context, (const uint8_t *)request + header_size, request_size - header_size);
+     167                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     168                 :            :                          (const uint8_t *)request + header_size, message_size);
+     169                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     170                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     171                 :          1 :     case 0xD:
+     172                 :          1 :         m_libspdm_local_buffer_size = 0;
+     173                 :          1 :         message_size = libspdm_test_get_psk_exchange_request_size(
+     174                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     175                 :            :             request_size - header_size);
+     176                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     177                 :            :                          (const uint8_t *)request + header_size, message_size);
+     178                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     179                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     180                 :          1 :     case 0xE:
+     181                 :          1 :         m_libspdm_local_buffer_size = 0;
+     182                 :          1 :         message_size = libspdm_test_get_psk_exchange_request_size(
+     183                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     184                 :            :             request_size - header_size);
+     185                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     186                 :            :                          (const uint8_t *)request + header_size, message_size);
+     187                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     188                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     189                 :          1 :     case 0xF:
+     190                 :          1 :         m_libspdm_local_buffer_size = 0;
+     191                 :          1 :         message_size = libspdm_test_get_psk_exchange_request_size(
+     192                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     193                 :            :             request_size - header_size);
+     194                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     195                 :            :                          (const uint8_t *)request + header_size, message_size);
+     196                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     197                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     198                 :          1 :     case 0x10:
+     199                 :          1 :         m_libspdm_local_buffer_size = 0;
+     200                 :          1 :         message_size = libspdm_test_get_psk_exchange_request_size(
+     201                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     202                 :            :             request_size - header_size);
+     203                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     204                 :            :                          (const uint8_t *)request + header_size, message_size);
+     205                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     206                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     207                 :          1 :     case 0x11:
+     208                 :          1 :         m_libspdm_local_buffer_size = 0;
+     209                 :          1 :         message_size = libspdm_test_get_psk_exchange_request_size(
+     210                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     211                 :            :             request_size - header_size);
+     212                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     213                 :            :                          (const uint8_t *)request + header_size, message_size);
+     214                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     215                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     216                 :          1 :     case 0x12:
+     217                 :          1 :         m_libspdm_local_buffer_size = 0;
+     218                 :          1 :         message_size = libspdm_test_get_psk_exchange_request_size(
+     219                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     220                 :            :             request_size - header_size);
+     221                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     222                 :            :                          (const uint8_t *)request + header_size, message_size);
+     223                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     224                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     225                 :          1 :     case 0x13:
+     226                 :          1 :         m_libspdm_local_buffer_size = 0;
+     227                 :          1 :         message_size = libspdm_test_get_psk_exchange_request_size(
+     228                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     229                 :            :             request_size - header_size);
+     230                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     231                 :            :                          (const uint8_t *)request + header_size, message_size);
+     232                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     233                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     234                 :          1 :     case 0x14:
+     235                 :          1 :         m_libspdm_local_buffer_size = 0;
+     236                 :          1 :         message_size = libspdm_test_get_psk_exchange_request_size(
+     237                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     238                 :            :             request_size - header_size);
+     239                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     240                 :            :                          (const uint8_t *)request + header_size, message_size);
+     241                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     242                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     243                 :          1 :     case 0x15:
+     244                 :          1 :         m_libspdm_local_buffer_size = 0;
+     245                 :          1 :         message_size = libspdm_test_get_psk_exchange_request_size(
+     246                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     247                 :            :             request_size - header_size);
+     248                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     249                 :            :                          (const uint8_t *)request + header_size, message_size);
+     250                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     251                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     252                 :          1 :     case 0x16:
+     253                 :          1 :         m_libspdm_local_buffer_size = 0;
+     254                 :          1 :         message_size = libspdm_test_get_psk_exchange_request_size(
+     255                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     256                 :            :             request_size - header_size);
+     257                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     258                 :            :                          (const uint8_t *)request + header_size, message_size);
+     259                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     260                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     261                 :          1 :     case 0x17:
+     262                 :          1 :         m_libspdm_local_buffer_size = 0;
+     263                 :          1 :         message_size = libspdm_test_get_psk_exchange_request_size(
+     264                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     265                 :            :             request_size - header_size);
+     266                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     267                 :            :                          (const uint8_t *)request + header_size, message_size);
+     268                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     269                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     270                 :          1 :     case 0x18:
+     271                 :          1 :         m_libspdm_local_buffer_size = 0;
+     272                 :          1 :         message_size = libspdm_test_get_psk_exchange_request_size(
+     273                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     274                 :            :             request_size - header_size);
+     275                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     276                 :            :                          (const uint8_t *)request + header_size, message_size);
+     277                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     278                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     279                 :          1 :     case 0x19:
+     280                 :          1 :         m_libspdm_local_buffer_size = 0;
+     281                 :          1 :         message_size = libspdm_test_get_psk_exchange_request_size(
+     282                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     283                 :            :             request_size - header_size);
+     284                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     285                 :            :                          (const uint8_t *)request + header_size, message_size);
+     286                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     287                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     288                 :          1 :     case 0x1A:
+     289                 :          1 :         m_libspdm_local_buffer_size = 0;
+     290                 :          1 :         message_size = libspdm_test_get_psk_exchange_request_size(
+     291                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     292                 :            :             request_size - header_size);
+     293                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     294                 :            :                          (const uint8_t *)request + header_size, message_size);
+     295                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     296                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     297                 :          1 :     case 0x1B:
+     298                 :          1 :         m_libspdm_local_buffer_size = 0;
+     299                 :          1 :         message_size = libspdm_test_get_psk_exchange_request_size(
+     300                 :            :             spdm_context, (const uint8_t *)request + header_size,
+     301                 :            :             request_size - header_size);
+     302                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     303                 :            :                          (const uint8_t *)request + header_size, message_size);
+     304                 :          1 :         m_libspdm_local_buffer_size += message_size;
+     305                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     306                 :          0 :     default:
+     307                 :          0 :         return LIBSPDM_STATUS_SEND_FAIL;
+     308                 :            :     }
+     309                 :            : }
+     310                 :            : 
+     311                 :         44 : libspdm_return_t libspdm_requester_psk_exchange_test_receive_message(
+     312                 :            :     void *spdm_context, size_t *response_size,
+     313                 :            :     void **response, uint64_t timeout)
+     314                 :            : {
+     315                 :            :     libspdm_test_context_t *spdm_test_context;
+     316                 :            : 
+     317                 :         44 :     spdm_test_context = libspdm_get_test_context();
+     318   [ -  +  -  +  :         44 :     switch (spdm_test_context->case_id) {
+          +  +  +  +  +  
+          +  -  +  +  +  
+          +  +  +  +  +  
+          +  +  +  +  +  
+             +  +  +  - ]
+     319                 :          0 :     case 0x1:
+     320                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+     321                 :            : 
+     322                 :          1 :     case 0x2: {
+     323                 :            :         spdm_psk_exchange_response_t *spdm_response;
+     324                 :            :         uint32_t hash_size;
+     325                 :            :         uint32_t hmac_size;
+     326                 :            :         uint8_t *ptr;
+     327                 :            :         size_t opaque_psk_exchange_rsp_size;
+     328                 :            :         void *data;
+     329                 :            :         size_t data_size;
+     330                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     331                 :            :         uint8_t *cert_buffer;
+     332                 :            :         size_t cert_buffer_size;
+     333                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+     334                 :            :         uint8_t bin_str2[128];
+     335                 :            :         size_t bin_str2_size;
+     336                 :            :         uint8_t bin_str7[128];
+     337                 :            :         size_t bin_str7_size;
+     338                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+     339                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+     340                 :            :         size_t spdm_response_size;
+     341                 :            :         size_t transport_header_size;
+     342                 :            : 
+     343                 :          1 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
+     344                 :            :             SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+     345                 :            :         ((libspdm_context_t *)spdm_context)
+     346                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+     347                 :            :             m_libspdm_use_asym_algo;
+     348                 :            :         ((libspdm_context_t *)spdm_context)
+     349                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+     350                 :            :             m_libspdm_use_hash_algo;
+     351                 :            :         ((libspdm_context_t *)spdm_context)
+     352                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+     353                 :            :             m_libspdm_use_dhe_algo;
+     354                 :            :         ((libspdm_context_t *)spdm_context)
+     355                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+     356                 :            :             m_libspdm_use_measurement_hash_algo;
+     357                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     358                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     359                 :          1 :         opaque_psk_exchange_rsp_size =
+     360                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+     361                 :            :                 spdm_context);
+     362                 :          1 :         spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
+     363                 :            :                              LIBSPDM_PSK_CONTEXT_LENGTH +
+     364                 :          1 :                              opaque_psk_exchange_rsp_size + hmac_size;
+     365                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     366                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     367                 :            : 
+     368                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     369                 :          1 :         spdm_response->header.request_response_code =
+     370                 :            :             SPDM_PSK_EXCHANGE_RSP;
+     371                 :          1 :         spdm_response->header.param1 = 0;
+     372                 :          1 :         spdm_response->header.param2 = 0;
+     373                 :          1 :         spdm_response->rsp_session_id =
+     374                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, true);
+     375                 :          1 :         spdm_response->reserved = 0;
+     376                 :          1 :         spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
+     377                 :          1 :         spdm_response->opaque_length =
+     378                 :          1 :             (uint16_t)opaque_psk_exchange_rsp_size;
+     379                 :          1 :         ptr = (void *)(spdm_response + 1);
+     380                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+     381                 :            :          * ptr += hash_size;*/
+     382                 :          1 :         libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
+     383                 :          1 :         ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
+     384                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+     385                 :            :             spdm_context, &opaque_psk_exchange_rsp_size, ptr);
+     386                 :          1 :         ptr += opaque_psk_exchange_rsp_size;
+     387                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+     388                 :            :                          sizeof(m_libspdm_local_buffer)
+     389                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+     390                 :            :                             m_libspdm_local_buffer),
+     391                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+     392                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+     393                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+     394                 :            :                        m_libspdm_local_buffer_size));
+     395                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+     396                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+     397                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     398                 :            :                                                         m_libspdm_use_asym_algo, &data,
+     399                 :            :                                                         &data_size, NULL, NULL);
+     400                 :          1 :         cert_buffer =
+     401                 :          1 :             (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
+     402                 :          1 :         cert_buffer_size =
+     403                 :          1 :             data_size - (sizeof(spdm_cert_chain_t) + hash_size);
+     404                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+     405                 :            :                          cert_buffer_hash);
+     406                 :            :         /* transcript.message_a size is 0*/
+     407                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+     408                 :            :                                       m_libspdm_local_buffer_size);
+     409                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+     410                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+     411                 :          1 :         free(data);
+     412                 :          1 :         bin_str2_size = sizeof(bin_str2);
+     413                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+     414                 :            :                            LIBSPDM_BIN_STR_2_LABEL, sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1,
+     415                 :          1 :                            hash_data, (uint16_t)hash_size, hash_size,
+     416                 :            :                            bin_str2, &bin_str2_size);
+     417                 :          1 :         libspdm_psk_handshake_secret_hkdf_expand(
+     418                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     419                 :            :                 m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
+     420                 :            :                 sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
+     421                 :            :                 bin_str2_size,
+     422                 :            :                 response_handshake_secret, hash_size);
+     423                 :          1 :         bin_str7_size = sizeof(bin_str7);
+     424                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+     425                 :            :                            LIBSPDM_BIN_STR_7_LABEL, sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1,
+     426                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+     427                 :            :                            &bin_str7_size);
+     428                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+     429                 :            :                             hash_size, bin_str7, bin_str7_size,
+     430                 :            :                             response_finished_key, hash_size);
+     431                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+     432                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+     433                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+     434                 :            :                          response_finished_key, hash_size, ptr);
+     435                 :          1 :         ptr += hmac_size;
+     436                 :            : 
+     437                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     438                 :            :                                               false, spdm_response_size,
+     439                 :            :                                               spdm_response, response_size,
+     440                 :            :                                               response);
+     441                 :            :     }
+     442                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     443                 :            : 
+     444                 :          0 :     case 0x3: {
+     445                 :            :         spdm_psk_exchange_response_t *spdm_response;
+     446                 :            :         uint32_t hash_size;
+     447                 :            :         uint32_t hmac_size;
+     448                 :            :         uint8_t *ptr;
+     449                 :            :         size_t opaque_psk_exchange_rsp_size;
+     450                 :            :         void *data;
+     451                 :            :         size_t data_size;
+     452                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     453                 :            :         uint8_t *cert_buffer;
+     454                 :            :         size_t cert_buffer_size;
+     455                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+     456                 :            :         uint8_t bin_str2[128];
+     457                 :            :         size_t bin_str2_size;
+     458                 :            :         uint8_t bin_str7[128];
+     459                 :            :         size_t bin_str7_size;
+     460                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+     461                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+     462                 :            :         size_t spdm_response_size;
+     463                 :            :         size_t transport_header_size;
+     464                 :            : 
+     465                 :            :         ((libspdm_context_t *)spdm_context)
+     466                 :          0 :         ->connection_info.algorithm.base_asym_algo =
+     467                 :            :             m_libspdm_use_asym_algo;
+     468                 :            :         ((libspdm_context_t *)spdm_context)
+     469                 :          0 :         ->connection_info.algorithm.base_hash_algo =
+     470                 :            :             m_libspdm_use_hash_algo;
+     471                 :            :         ((libspdm_context_t *)spdm_context)
+     472                 :          0 :         ->connection_info.algorithm.dhe_named_group =
+     473                 :            :             m_libspdm_use_dhe_algo;
+     474                 :            :         ((libspdm_context_t *)spdm_context)
+     475                 :          0 :         ->connection_info.algorithm.measurement_hash_algo =
+     476                 :            :             m_libspdm_use_measurement_hash_algo;
+     477                 :          0 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     478                 :          0 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     479                 :          0 :         opaque_psk_exchange_rsp_size =
+     480                 :          0 :             libspdm_get_opaque_data_version_selection_data_size(
+     481                 :            :                 spdm_context);
+     482                 :          0 :         spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
+     483                 :            :                              LIBSPDM_PSK_CONTEXT_LENGTH +
+     484                 :          0 :                              opaque_psk_exchange_rsp_size + hmac_size;
+     485                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     486                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     487                 :            : 
+     488                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     489                 :          0 :         spdm_response->header.request_response_code =
+     490                 :            :             SPDM_PSK_EXCHANGE_RSP;
+     491                 :          0 :         spdm_response->header.param1 = 0;
+     492                 :          0 :         spdm_response->header.param2 = 0;
+     493                 :          0 :         spdm_response->rsp_session_id =
+     494                 :          0 :             libspdm_allocate_rsp_session_id(spdm_context, true);
+     495                 :          0 :         spdm_response->reserved = 0;
+     496                 :          0 :         spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
+     497                 :          0 :         spdm_response->opaque_length =
+     498                 :          0 :             (uint16_t)opaque_psk_exchange_rsp_size;
+     499                 :          0 :         ptr = (void *)(spdm_response + 1);
+     500                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+     501                 :            :          * ptr += hash_size;*/
+     502                 :          0 :         libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
+     503                 :          0 :         ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
+     504                 :          0 :         libspdm_build_opaque_data_version_selection_data(
+     505                 :            :             spdm_context, &opaque_psk_exchange_rsp_size, ptr);
+     506                 :          0 :         ptr += opaque_psk_exchange_rsp_size;
+     507                 :          0 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+     508                 :            :                          sizeof(m_libspdm_local_buffer)
+     509                 :          0 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+     510                 :            :                             m_libspdm_local_buffer),
+     511                 :          0 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+     512                 :          0 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+     513                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+     514                 :            :                        m_libspdm_local_buffer_size));
+     515                 :          0 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+     516                 :          0 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+     517                 :          0 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     518                 :            :                                                         m_libspdm_use_asym_algo, &data,
+     519                 :            :                                                         &data_size, NULL, NULL);
+     520                 :          0 :         cert_buffer =
+     521                 :          0 :             (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
+     522                 :          0 :         cert_buffer_size =
+     523                 :          0 :             data_size - (sizeof(spdm_cert_chain_t) + hash_size);
+     524                 :          0 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+     525                 :            :                          cert_buffer_hash);
+     526                 :            :         /* transcript.message_a size is 0*/
+     527                 :          0 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+     528                 :            :                                       m_libspdm_local_buffer_size);
+     529                 :          0 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+     530                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+     531                 :          0 :         free(data);
+     532                 :          0 :         bin_str2_size = sizeof(bin_str2);
+     533                 :          0 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+     534                 :            :                            LIBSPDM_BIN_STR_2_LABEL, sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1,
+     535                 :          0 :                            hash_data, (uint16_t)hash_size, hash_size,
+     536                 :            :                            bin_str2, &bin_str2_size);
+     537                 :          0 :         libspdm_psk_handshake_secret_hkdf_expand(
+     538                 :          0 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     539                 :            :                 m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
+     540                 :            :                 sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
+     541                 :            :                 bin_str2_size,
+     542                 :            :                 response_handshake_secret, hash_size);
+     543                 :          0 :         bin_str7_size = sizeof(bin_str7);
+     544                 :          0 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+     545                 :            :                            LIBSPDM_BIN_STR_7_LABEL, sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1,
+     546                 :          0 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+     547                 :            :                            &bin_str7_size);
+     548                 :          0 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+     549                 :            :                             hash_size, bin_str7, bin_str7_size,
+     550                 :            :                             response_finished_key, hash_size);
+     551                 :          0 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+     552                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+     553                 :          0 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+     554                 :            :                          response_finished_key, hash_size, ptr);
+     555                 :          0 :         ptr += hmac_size;
+     556                 :            : 
+     557                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     558                 :            :                                               false, spdm_response_size,
+     559                 :            :                                               spdm_response, response_size,
+     560                 :            :                                               response);
+     561                 :            :     }
+     562                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     563                 :            : 
+     564                 :          1 :     case 0x4: {
+     565                 :            :         spdm_error_response_t *spdm_response;
+     566                 :            :         size_t spdm_response_size;
+     567                 :            :         size_t transport_header_size;
+     568                 :            : 
+     569                 :          1 :         spdm_response_size = sizeof(spdm_error_response_t);
+     570                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     571                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     572                 :            : 
+     573                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     574                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     575                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_INVALID_REQUEST;
+     576                 :          1 :         spdm_response->header.param2 = 0;
+     577                 :            : 
+     578                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     579                 :            :                                               false, spdm_response_size,
+     580                 :            :                                               spdm_response,
+     581                 :            :                                               response_size, response);
+     582                 :            :     }
+     583                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     584                 :            : 
+     585                 :          1 :     case 0x5: {
+     586                 :            :         spdm_error_response_t *spdm_response;
+     587                 :            :         size_t spdm_response_size;
+     588                 :            :         size_t transport_header_size;
+     589                 :            : 
+     590                 :          1 :         spdm_response_size = sizeof(spdm_error_response_t);
+     591                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     592                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     593                 :            : 
+     594                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     595                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     596                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
+     597                 :          1 :         spdm_response->header.param2 = 0;
+     598                 :            : 
+     599                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     600                 :            :                                               false, spdm_response_size,
+     601                 :            :                                               spdm_response,
+     602                 :            :                                               response_size, response);
+     603                 :            :     }
+     604                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     605                 :            : 
+     606                 :          2 :     case 0x6: {
+     607                 :            :         static size_t sub_index1 = 0;
+     608         [ +  + ]:          2 :         if (sub_index1 == 0) {
+     609                 :            :             spdm_error_response_t *spdm_response;
+     610                 :            :             size_t spdm_response_size;
+     611                 :            :             size_t transport_header_size;
+     612                 :            : 
+     613                 :          1 :             spdm_response_size = sizeof(spdm_error_response_t);
+     614                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     615                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     616                 :            : 
+     617                 :          1 :             spdm_response->header.spdm_version =
+     618                 :            :                 SPDM_MESSAGE_VERSION_11;
+     619                 :          1 :             spdm_response->header.request_response_code = SPDM_ERROR;
+     620                 :          1 :             spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
+     621                 :          1 :             spdm_response->header.param2 = 0;
+     622                 :            : 
+     623                 :          1 :             libspdm_transport_test_encode_message(
+     624                 :            :                 spdm_context, NULL, false, false,
+     625                 :            :                 spdm_response_size, spdm_response,
+     626                 :            :                 response_size, response);
+     627                 :          1 :             sub_index1++;
+     628         [ +  - ]:          1 :         } else if (sub_index1 == 1) {
+     629                 :            :             spdm_psk_exchange_response_t *spdm_response;
+     630                 :            :             uint32_t hash_size;
+     631                 :            :             uint32_t hmac_size;
+     632                 :            :             uint8_t *ptr;
+     633                 :            :             size_t opaque_psk_exchange_rsp_size;
+     634                 :            :             void *data;
+     635                 :            :             size_t data_size;
+     636                 :            :             uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     637                 :            :             uint8_t *cert_buffer;
+     638                 :            :             size_t cert_buffer_size;
+     639                 :            :             uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+     640                 :            :             uint8_t bin_str2[128];
+     641                 :            :             size_t bin_str2_size;
+     642                 :            :             uint8_t bin_str7[128];
+     643                 :            :             size_t bin_str7_size;
+     644                 :            :             uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+     645                 :            :             uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+     646                 :            :             size_t spdm_response_size;
+     647                 :            :             size_t transport_header_size;
+     648                 :            : 
+     649                 :            :             ((libspdm_context_t *)spdm_context)
+     650                 :          1 :             ->connection_info.algorithm.base_asym_algo =
+     651                 :            :                 m_libspdm_use_asym_algo;
+     652                 :            :             ((libspdm_context_t *)spdm_context)
+     653                 :          1 :             ->connection_info.algorithm.base_hash_algo =
+     654                 :            :                 m_libspdm_use_hash_algo;
+     655                 :            :             ((libspdm_context_t *)spdm_context)
+     656                 :          1 :             ->connection_info.algorithm.dhe_named_group =
+     657                 :            :                 m_libspdm_use_dhe_algo;
+     658                 :            :             ((libspdm_context_t *)spdm_context)
+     659                 :            :             ->connection_info.algorithm
+     660                 :          1 :             .measurement_hash_algo =
+     661                 :            :                 m_libspdm_use_measurement_hash_algo;
+     662                 :          1 :             hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     663                 :          1 :             hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     664                 :          1 :             opaque_psk_exchange_rsp_size =
+     665                 :          1 :                 libspdm_get_opaque_data_version_selection_data_size(
+     666                 :            :                     spdm_context);
+     667                 :          1 :             spdm_response_size = sizeof(spdm_psk_exchange_response_t) +
+     668                 :            :                                  0 + LIBSPDM_PSK_CONTEXT_LENGTH +
+     669                 :          1 :                                  opaque_psk_exchange_rsp_size +
+     670                 :            :                                  hmac_size;
+     671                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     672                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     673                 :            : 
+     674                 :          1 :             spdm_response->header.spdm_version =
+     675                 :            :                 SPDM_MESSAGE_VERSION_11;
+     676                 :          1 :             spdm_response->header.request_response_code =
+     677                 :            :                 SPDM_PSK_EXCHANGE_RSP;
+     678                 :          1 :             spdm_response->header.param1 = 0;
+     679                 :          1 :             spdm_response->header.param2 = 0;
+     680                 :          1 :             spdm_response->rsp_session_id =
+     681                 :          1 :                 libspdm_allocate_rsp_session_id(spdm_context, true);
+     682                 :          1 :             spdm_response->reserved = 0;
+     683                 :          1 :             spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
+     684                 :          1 :             spdm_response->opaque_length =
+     685                 :          1 :                 (uint16_t)opaque_psk_exchange_rsp_size;
+     686                 :          1 :             ptr = (void *)(spdm_response + 1);
+     687                 :            :             /* libspdm_zero_mem (ptr, hash_size);
+     688                 :            :              * ptr += hash_size;*/
+     689                 :          1 :             libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
+     690                 :          1 :             ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
+     691                 :          1 :             libspdm_build_opaque_data_version_selection_data(
+     692                 :            :                 spdm_context, &opaque_psk_exchange_rsp_size,
+     693                 :            :                 ptr);
+     694                 :          1 :             ptr += opaque_psk_exchange_rsp_size;
+     695                 :          1 :             libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+     696                 :            :                              sizeof(m_libspdm_local_buffer)
+     697                 :          1 :                              - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+     698                 :            :                                 m_libspdm_local_buffer),
+     699                 :          1 :                              spdm_response, (size_t)ptr - (size_t)spdm_response);
+     700                 :          1 :             m_libspdm_local_buffer_size +=
+     701                 :          1 :                 ((size_t)ptr - (size_t)spdm_response);
+     702                 :          1 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+     703                 :            :                            m_libspdm_local_buffer_size));
+     704                 :          1 :             libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+     705                 :          1 :             libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+     706                 :          1 :             libspdm_read_responder_public_certificate_chain(
+     707                 :            :                 m_libspdm_use_hash_algo, m_libspdm_use_asym_algo, &data,
+     708                 :            :                 &data_size, NULL, NULL);
+     709                 :          1 :             cert_buffer = (uint8_t *)data +
+     710                 :          1 :                           sizeof(spdm_cert_chain_t) + hash_size;
+     711                 :          1 :             cert_buffer_size =
+     712                 :          1 :                 data_size -
+     713                 :            :                 (sizeof(spdm_cert_chain_t) + hash_size);
+     714                 :          1 :             libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer,
+     715                 :            :                              cert_buffer_size, cert_buffer_hash);
+     716                 :            :             /* transcript.message_a size is 0*/
+     717                 :          1 :             libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+     718                 :            :                                           m_libspdm_local_buffer_size);
+     719                 :          2 :             libspdm_hash_all(m_libspdm_use_hash_algo,
+     720                 :          1 :                              libspdm_get_managed_buffer(&th_curr),
+     721                 :            :                              libspdm_get_managed_buffer_size(&th_curr),
+     722                 :            :                              hash_data);
+     723                 :          1 :             free(data);
+     724                 :          1 :             bin_str2_size = sizeof(bin_str2);
+     725                 :          1 :             libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+     726                 :            :                                LIBSPDM_BIN_STR_2_LABEL,
+     727                 :            :                                sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1, hash_data,
+     728                 :          1 :                                (uint16_t)hash_size, hash_size, bin_str2,
+     729                 :            :                                &bin_str2_size);
+     730                 :          1 :             libspdm_psk_handshake_secret_hkdf_expand(
+     731                 :          1 :                 spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     732                 :            :                     m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
+     733                 :            :                     sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
+     734                 :            :                     bin_str2_size, response_handshake_secret,
+     735                 :            :                     hash_size);
+     736                 :          1 :             bin_str7_size = sizeof(bin_str7);
+     737                 :          1 :             libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+     738                 :            :                                LIBSPDM_BIN_STR_7_LABEL,
+     739                 :            :                                sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1, NULL,
+     740                 :          1 :                                (uint16_t)hash_size, hash_size, bin_str7,
+     741                 :            :                                &bin_str7_size);
+     742                 :          1 :             libspdm_hkdf_expand(m_libspdm_use_hash_algo,
+     743                 :            :                                 response_handshake_secret, hash_size,
+     744                 :            :                                 bin_str7, bin_str7_size,
+     745                 :            :                                 response_finished_key, hash_size);
+     746                 :          1 :             libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+     747                 :            :                              libspdm_get_managed_buffer_size(&th_curr), hash_data);
+     748                 :          1 :             libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+     749                 :            :                              response_finished_key, hash_size, ptr);
+     750                 :          1 :             ptr += hmac_size;
+     751                 :            : 
+     752                 :          1 :             libspdm_transport_test_encode_message(
+     753                 :            :                 spdm_context, NULL, false, false, spdm_response_size,
+     754                 :            :                 spdm_response, response_size, response);
+     755                 :            :         }
+     756                 :            :     }
+     757                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     758                 :            : 
+     759                 :          1 :     case 0x7: {
+     760                 :            :         spdm_error_response_t *spdm_response;
+     761                 :            :         size_t spdm_response_size;
+     762                 :            :         size_t transport_header_size;
+     763                 :            : 
+     764                 :          1 :         spdm_response_size = sizeof(spdm_error_response_t);
+     765                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     766                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     767                 :            : 
+     768                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     769                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     770                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_REQUEST_RESYNCH;
+     771                 :          1 :         spdm_response->header.param2 = 0;
+     772                 :            : 
+     773                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     774                 :            :                                               false, spdm_response_size,
+     775                 :            :                                               spdm_response,
+     776                 :            :                                               response_size, response);
+     777                 :            :     }
+     778                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     779                 :            : 
+     780                 :          2 :     case 0x8: {
+     781                 :            :         spdm_error_response_data_response_not_ready_t *spdm_response;
+     782                 :            :         size_t spdm_response_size;
+     783                 :            :         size_t transport_header_size;
+     784                 :            : 
+     785                 :          2 :         spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
+     786                 :          2 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     787                 :          2 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     788                 :            : 
+     789                 :          2 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     790                 :          2 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     791                 :          2 :         spdm_response->header.param1 =
+     792                 :            :             SPDM_ERROR_CODE_RESPONSE_NOT_READY;
+     793                 :          2 :         spdm_response->header.param2 = 0;
+     794                 :          2 :         spdm_response->extend_error_data.rd_exponent = 1;
+     795                 :          2 :         spdm_response->extend_error_data.rd_tm = 2;
+     796                 :          2 :         spdm_response->extend_error_data.request_code =
+     797                 :            :             SPDM_PSK_EXCHANGE;
+     798                 :          2 :         spdm_response->extend_error_data.token = 0;
+     799                 :            : 
+     800                 :          2 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     801                 :            :                                               false, spdm_response_size,
+     802                 :            :                                               spdm_response,
+     803                 :            :                                               response_size, response);
+     804                 :            :     }
+     805                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     806                 :            : 
+     807                 :          2 :     case 0x9: {
+     808                 :            :         static size_t sub_index2 = 0;
+     809         [ +  + ]:          2 :         if (sub_index2 == 0) {
+     810                 :            :             spdm_error_response_data_response_not_ready_t
+     811                 :            :             *spdm_response;
+     812                 :            :             size_t spdm_response_size;
+     813                 :            :             size_t transport_header_size;
+     814                 :            : 
+     815                 :          1 :             spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
+     816                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     817                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     818                 :            : 
+     819                 :          1 :             spdm_response->header.spdm_version =
+     820                 :            :                 SPDM_MESSAGE_VERSION_11;
+     821                 :          1 :             spdm_response->header.request_response_code = SPDM_ERROR;
+     822                 :          1 :             spdm_response->header.param1 =
+     823                 :            :                 SPDM_ERROR_CODE_RESPONSE_NOT_READY;
+     824                 :          1 :             spdm_response->header.param2 = 0;
+     825                 :          1 :             spdm_response->extend_error_data.rd_exponent = 1;
+     826                 :          1 :             spdm_response->extend_error_data.rd_tm = 2;
+     827                 :          1 :             spdm_response->extend_error_data.request_code =
+     828                 :            :                 SPDM_PSK_EXCHANGE;
+     829                 :          1 :             spdm_response->extend_error_data.token = 1;
+     830                 :            : 
+     831                 :          1 :             libspdm_transport_test_encode_message(
+     832                 :            :                 spdm_context, NULL, false, false,
+     833                 :            :                 spdm_response_size, spdm_response,
+     834                 :            :                 response_size, response);
+     835                 :          1 :             sub_index2++;
+     836         [ +  - ]:          1 :         } else if (sub_index2 == 1) {
+     837                 :            :             spdm_psk_exchange_response_t *spdm_response;
+     838                 :            :             uint32_t hash_size;
+     839                 :            :             uint32_t hmac_size;
+     840                 :            :             uint8_t *ptr;
+     841                 :            :             size_t opaque_psk_exchange_rsp_size;
+     842                 :            :             void *data;
+     843                 :            :             size_t data_size;
+     844                 :            :             uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     845                 :            :             uint8_t *cert_buffer;
+     846                 :            :             size_t cert_buffer_size;
+     847                 :            :             uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+     848                 :            :             uint8_t bin_str2[128];
+     849                 :            :             size_t bin_str2_size;
+     850                 :            :             uint8_t bin_str7[128];
+     851                 :            :             size_t bin_str7_size;
+     852                 :            :             uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+     853                 :            :             uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+     854                 :            :             size_t spdm_response_size;
+     855                 :            :             size_t transport_header_size;
+     856                 :            : 
+     857                 :            :             ((libspdm_context_t *)spdm_context)
+     858                 :          1 :             ->connection_info.algorithm.base_asym_algo =
+     859                 :            :                 m_libspdm_use_asym_algo;
+     860                 :            :             ((libspdm_context_t *)spdm_context)
+     861                 :          1 :             ->connection_info.algorithm.base_hash_algo =
+     862                 :            :                 m_libspdm_use_hash_algo;
+     863                 :            :             ((libspdm_context_t *)spdm_context)
+     864                 :          1 :             ->connection_info.algorithm.dhe_named_group =
+     865                 :            :                 m_libspdm_use_dhe_algo;
+     866                 :            :             ((libspdm_context_t *)spdm_context)
+     867                 :            :             ->connection_info.algorithm
+     868                 :          1 :             .measurement_hash_algo =
+     869                 :            :                 m_libspdm_use_measurement_hash_algo;
+     870                 :          1 :             hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     871                 :          1 :             hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     872                 :          1 :             opaque_psk_exchange_rsp_size =
+     873                 :          1 :                 libspdm_get_opaque_data_version_selection_data_size(
+     874                 :            :                     spdm_context);
+     875                 :          1 :             spdm_response_size = sizeof(spdm_psk_exchange_response_t) +
+     876                 :            :                                  0 + LIBSPDM_PSK_CONTEXT_LENGTH +
+     877                 :          1 :                                  opaque_psk_exchange_rsp_size +
+     878                 :            :                                  hmac_size;
+     879                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     880                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     881                 :            : 
+     882                 :          1 :             spdm_response->header.spdm_version =
+     883                 :            :                 SPDM_MESSAGE_VERSION_11;
+     884                 :          1 :             spdm_response->header.request_response_code =
+     885                 :            :                 SPDM_PSK_EXCHANGE_RSP;
+     886                 :          1 :             spdm_response->header.param1 = 0;
+     887                 :          1 :             spdm_response->header.param2 = 0;
+     888                 :          1 :             spdm_response->rsp_session_id =
+     889                 :          1 :                 libspdm_allocate_rsp_session_id(spdm_context, true);
+     890                 :          1 :             spdm_response->reserved = 0;
+     891                 :          1 :             spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
+     892                 :          1 :             spdm_response->opaque_length =
+     893                 :          1 :                 (uint16_t)opaque_psk_exchange_rsp_size;
+     894                 :          1 :             ptr = (void *)(spdm_response + 1);
+     895                 :            :             /* libspdm_zero_mem (ptr, hash_size);
+     896                 :            :              * ptr += hash_size;*/
+     897                 :          1 :             libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
+     898                 :          1 :             ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
+     899                 :          1 :             libspdm_build_opaque_data_version_selection_data(
+     900                 :            :                 spdm_context, &opaque_psk_exchange_rsp_size,
+     901                 :            :                 ptr);
+     902                 :          1 :             ptr += opaque_psk_exchange_rsp_size;
+     903                 :          1 :             libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+     904                 :            :                              sizeof(m_libspdm_local_buffer)
+     905                 :          1 :                              - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+     906                 :            :                                 m_libspdm_local_buffer),
+     907                 :          1 :                              spdm_response, (size_t)ptr - (size_t)spdm_response);
+     908                 :          1 :             m_libspdm_local_buffer_size +=
+     909                 :          1 :                 ((size_t)ptr - (size_t)spdm_response);
+     910                 :          1 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+     911                 :            :                            m_libspdm_local_buffer_size));
+     912                 :          1 :             libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+     913                 :          1 :             libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+     914                 :          1 :             libspdm_read_responder_public_certificate_chain(
+     915                 :            :                 m_libspdm_use_hash_algo, m_libspdm_use_asym_algo, &data,
+     916                 :            :                 &data_size, NULL, NULL);
+     917                 :          1 :             cert_buffer = (uint8_t *)data +
+     918                 :          1 :                           sizeof(spdm_cert_chain_t) + hash_size;
+     919                 :          1 :             cert_buffer_size =
+     920                 :          1 :                 data_size -
+     921                 :            :                 (sizeof(spdm_cert_chain_t) + hash_size);
+     922                 :          1 :             libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer,
+     923                 :            :                              cert_buffer_size, cert_buffer_hash);
+     924                 :            :             /* transcript.message_a size is 0*/
+     925                 :          1 :             libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+     926                 :            :                                           m_libspdm_local_buffer_size);
+     927                 :          2 :             libspdm_hash_all(m_libspdm_use_hash_algo,
+     928                 :          1 :                              libspdm_get_managed_buffer(&th_curr),
+     929                 :            :                              libspdm_get_managed_buffer_size(&th_curr),
+     930                 :            :                              hash_data);
+     931                 :          1 :             free(data);
+     932                 :          1 :             bin_str2_size = sizeof(bin_str2);
+     933                 :          1 :             libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+     934                 :            :                                LIBSPDM_BIN_STR_2_LABEL,
+     935                 :            :                                sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1, hash_data,
+     936                 :          1 :                                (uint16_t)hash_size, hash_size, bin_str2,
+     937                 :            :                                &bin_str2_size);
+     938                 :          1 :             libspdm_psk_handshake_secret_hkdf_expand(
+     939                 :          1 :                 spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     940                 :            :                     m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
+     941                 :            :                     sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
+     942                 :            :                     bin_str2_size, response_handshake_secret,
+     943                 :            :                     hash_size);
+     944                 :          1 :             bin_str7_size = sizeof(bin_str7);
+     945                 :          1 :             libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+     946                 :            :                                LIBSPDM_BIN_STR_7_LABEL,
+     947                 :            :                                sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1, NULL,
+     948                 :          1 :                                (uint16_t)hash_size, hash_size, bin_str7,
+     949                 :            :                                &bin_str7_size);
+     950                 :          1 :             libspdm_hkdf_expand(m_libspdm_use_hash_algo,
+     951                 :            :                                 response_handshake_secret, hash_size,
+     952                 :            :                                 bin_str7, bin_str7_size,
+     953                 :            :                                 response_finished_key, hash_size);
+     954                 :          1 :             libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+     955                 :            :                              libspdm_get_managed_buffer_size(&th_curr), hash_data);
+     956                 :          1 :             libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+     957                 :            :                              response_finished_key, hash_size, ptr);
+     958                 :          1 :             ptr += hmac_size;
+     959                 :            : 
+     960                 :          1 :             libspdm_transport_test_encode_message(
+     961                 :            :                 spdm_context, NULL, false, false, spdm_response_size,
+     962                 :            :                 spdm_response, response_size, response);
+     963                 :            :         }
+     964                 :            :     }
+     965                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     966                 :            : 
+     967                 :         18 :     case 0xA:
+     968                 :            :     {
+     969                 :            :         static uint16_t error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
+     970                 :            : 
+     971                 :            :         spdm_error_response_t *spdm_response;
+     972                 :            :         size_t spdm_response_size;
+     973                 :            :         size_t transport_header_size;
+     974                 :            : 
+     975                 :         18 :         spdm_response_size = sizeof(spdm_error_response_t);
+     976                 :         18 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     977                 :         18 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     978                 :            : 
+     979         [ +  - ]:         18 :         if(error_code <= 0xff) {
+     980                 :         18 :             libspdm_zero_mem (spdm_response, spdm_response_size);
+     981                 :         18 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     982                 :         18 :             spdm_response->header.request_response_code = SPDM_ERROR;
+     983                 :         18 :             spdm_response->header.param1 = (uint8_t) error_code;
+     984                 :         18 :             spdm_response->header.param2 = 0;
+     985                 :            : 
+     986                 :         18 :             libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
+     987                 :            :                                                    spdm_response_size, spdm_response,
+     988                 :            :                                                    response_size, response);
+     989                 :            :         }
+     990                 :            : 
+     991                 :         18 :         error_code++;
+     992         [ +  + ]:         18 :         if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
+     993                 :          1 :             error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
+     994                 :            :         }
+     995         [ +  + ]:         18 :         if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) { /*skip some reserved error codes (0d to 3e)*/
+     996                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
+     997                 :            :         }
+     998         [ +  + ]:         18 :         if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) { /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
+     999                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
+    1000                 :            :         }
+    1001                 :            :     }
+    1002                 :         18 :         return LIBSPDM_STATUS_SUCCESS;
+    1003                 :            : 
+    1004                 :          0 :     case 0xB: {
+    1005                 :            :         spdm_psk_exchange_response_t *spdm_response;
+    1006                 :            :         uint32_t hash_size;
+    1007                 :            :         uint32_t hmac_size;
+    1008                 :            :         uint8_t *ptr;
+    1009                 :            :         size_t opaque_psk_exchange_rsp_size;
+    1010                 :            :         void *data;
+    1011                 :            :         size_t data_size;
+    1012                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1013                 :            :         uint8_t *cert_buffer;
+    1014                 :            :         size_t cert_buffer_size;
+    1015                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    1016                 :            :         uint8_t bin_str2[128];
+    1017                 :            :         size_t bin_str2_size;
+    1018                 :            :         uint8_t bin_str7[128];
+    1019                 :            :         size_t bin_str7_size;
+    1020                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    1021                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    1022                 :            :         size_t spdm_response_size;
+    1023                 :            :         size_t transport_header_size;
+    1024                 :            : 
+    1025                 :            :         ((libspdm_context_t *)spdm_context)
+    1026                 :          0 :         ->connection_info.algorithm.base_asym_algo =
+    1027                 :            :             m_libspdm_use_asym_algo;
+    1028                 :            :         ((libspdm_context_t *)spdm_context)
+    1029                 :          0 :         ->connection_info.algorithm.base_hash_algo =
+    1030                 :            :             m_libspdm_use_hash_algo;
+    1031                 :            :         ((libspdm_context_t *)spdm_context)
+    1032                 :          0 :         ->connection_info.algorithm.dhe_named_group =
+    1033                 :            :             m_libspdm_use_dhe_algo;
+    1034                 :            :         ((libspdm_context_t *)spdm_context)
+    1035                 :          0 :         ->connection_info.algorithm.measurement_hash_algo =
+    1036                 :            :             m_libspdm_use_measurement_hash_algo;
+    1037                 :          0 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1038                 :          0 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1039                 :          0 :         opaque_psk_exchange_rsp_size =
+    1040                 :          0 :             libspdm_get_opaque_data_version_selection_data_size(
+    1041                 :            :                 spdm_context);
+    1042                 :          0 :         spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
+    1043                 :            :                              LIBSPDM_PSK_CONTEXT_LENGTH +
+    1044                 :          0 :                              opaque_psk_exchange_rsp_size + hmac_size;
+    1045                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1046                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1047                 :            : 
+    1048                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1049                 :          0 :         spdm_response->header.request_response_code =
+    1050                 :            :             SPDM_PSK_EXCHANGE_RSP;
+    1051                 :          0 :         spdm_response->header.param1 = 0;
+    1052                 :          0 :         spdm_response->header.param2 = 0;
+    1053                 :          0 :         spdm_response->rsp_session_id =
+    1054                 :          0 :             libspdm_allocate_rsp_session_id(spdm_context, true);
+    1055                 :          0 :         spdm_response->reserved = 0;
+    1056                 :          0 :         spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
+    1057                 :          0 :         spdm_response->opaque_length =
+    1058                 :          0 :             (uint16_t)opaque_psk_exchange_rsp_size;
+    1059                 :          0 :         ptr = (void *)(spdm_response + 1);
+    1060                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    1061                 :            :          * ptr += hash_size;*/
+    1062                 :          0 :         libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
+    1063                 :          0 :         ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
+    1064                 :          0 :         libspdm_build_opaque_data_version_selection_data(
+    1065                 :            :             spdm_context, &opaque_psk_exchange_rsp_size, ptr);
+    1066                 :          0 :         ptr += opaque_psk_exchange_rsp_size;
+    1067                 :          0 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    1068                 :            :                          sizeof(m_libspdm_local_buffer)
+    1069                 :          0 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    1070                 :            :                             m_libspdm_local_buffer),
+    1071                 :          0 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    1072                 :          0 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    1073                 :          0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    1074                 :            :                        m_libspdm_local_buffer_size));
+    1075                 :          0 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    1076                 :          0 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    1077                 :          0 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1078                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    1079                 :            :                                                         &data_size, NULL, NULL);
+    1080                 :          0 :         cert_buffer =
+    1081                 :          0 :             (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
+    1082                 :          0 :         cert_buffer_size =
+    1083                 :          0 :             data_size - (sizeof(spdm_cert_chain_t) + hash_size);
+    1084                 :          0 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    1085                 :            :                          cert_buffer_hash);
+    1086                 :            :         /* transcript.message_a size is 0*/
+    1087                 :          0 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    1088                 :            :                                       m_libspdm_local_buffer_size);
+    1089                 :          0 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1090                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1091                 :          0 :         free(data);
+    1092                 :          0 :         bin_str2_size = sizeof(bin_str2);
+    1093                 :          0 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1094                 :            :                            LIBSPDM_BIN_STR_2_LABEL, sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1,
+    1095                 :          0 :                            hash_data, (uint16_t)hash_size, hash_size,
+    1096                 :            :                            bin_str2, &bin_str2_size);
+    1097                 :          0 :         libspdm_psk_handshake_secret_hkdf_expand(
+    1098                 :          0 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    1099                 :            :                 m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
+    1100                 :            :                 sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
+    1101                 :            :                 bin_str2_size,
+    1102                 :            :                 response_handshake_secret, hash_size);
+    1103                 :          0 :         bin_str7_size = sizeof(bin_str7);
+    1104                 :          0 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1105                 :            :                            LIBSPDM_BIN_STR_7_LABEL, sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1,
+    1106                 :          0 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    1107                 :            :                            &bin_str7_size);
+    1108                 :          0 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    1109                 :            :                             hash_size, bin_str7, bin_str7_size,
+    1110                 :            :                             response_finished_key, hash_size);
+    1111                 :          0 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1112                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1113                 :          0 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    1114                 :            :                          response_finished_key, hash_size, ptr);
+    1115                 :          0 :         ptr += hmac_size;
+    1116                 :            : 
+    1117                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1118                 :            :                                               false, spdm_response_size,
+    1119                 :            :                                               spdm_response, response_size,
+    1120                 :            :                                               response);
+    1121                 :            :     }
+    1122                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+    1123                 :            : 
+    1124                 :          1 :     case 0xC: {
+    1125                 :            :         spdm_psk_exchange_response_t *spdm_response;
+    1126                 :            :         uint32_t hash_size;
+    1127                 :            :         uint32_t hmac_size;
+    1128                 :            :         uint8_t *ptr;
+    1129                 :            :         size_t opaque_psk_exchange_rsp_size;
+    1130                 :            :         void *data;
+    1131                 :            :         size_t data_size;
+    1132                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1133                 :            :         uint8_t *cert_buffer;
+    1134                 :            :         size_t cert_buffer_size;
+    1135                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    1136                 :            :         uint8_t bin_str2[128];
+    1137                 :            :         size_t bin_str2_size;
+    1138                 :            :         uint8_t bin_str7[128];
+    1139                 :            :         size_t bin_str7_size;
+    1140                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    1141                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    1142                 :            :         size_t spdm_response_size;
+    1143                 :            :         size_t transport_header_size;
+    1144                 :            : 
+    1145                 :          1 :         ((libspdm_context_t *)spdm_context)->connection_info.algorithm.base_asym_algo =
+    1146                 :            :             m_libspdm_use_asym_algo;
+    1147                 :          1 :         ((libspdm_context_t *)spdm_context)->connection_info.algorithm.base_hash_algo =
+    1148                 :            :             m_libspdm_use_hash_algo;
+    1149                 :          1 :         ((libspdm_context_t *)spdm_context)->connection_info.algorithm.dhe_named_group =
+    1150                 :            :             m_libspdm_use_dhe_algo;
+    1151                 :          1 :         ((libspdm_context_t *)spdm_context)->connection_info.algorithm.measurement_hash_algo =
+    1152                 :            :             m_libspdm_use_measurement_hash_algo;
+    1153                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1154                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1155                 :          1 :         opaque_psk_exchange_rsp_size =
+    1156                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(spdm_context);
+    1157                 :          1 :         spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
+    1158                 :            :                              LIBSPDM_PSK_CONTEXT_LENGTH +
+    1159                 :          1 :                              opaque_psk_exchange_rsp_size + hmac_size;
+    1160                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1161                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1162                 :            : 
+    1163                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1164                 :          1 :         spdm_response->header.request_response_code = SPDM_PSK_EXCHANGE_RSP;
+    1165                 :          1 :         spdm_response->header.param1 = 0;
+    1166                 :          1 :         spdm_response->header.param2 = 0;
+    1167                 :          1 :         spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, true);
+    1168                 :          1 :         spdm_response->reserved = 0;
+    1169                 :          1 :         spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
+    1170                 :          1 :         spdm_response->opaque_length = (uint16_t)opaque_psk_exchange_rsp_size;
+    1171                 :          1 :         ptr = (void *)(spdm_response + 1);
+    1172                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    1173                 :            :          * ptr += hash_size;*/
+    1174                 :          1 :         libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
+    1175                 :          1 :         ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
+    1176                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    1177                 :            :             spdm_context, &opaque_psk_exchange_rsp_size, ptr);
+    1178                 :          1 :         ptr += opaque_psk_exchange_rsp_size;
+    1179                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    1180                 :            :                          sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
+    1181                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    1182                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    1183                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer (0x%zx):\n",
+    1184                 :            :                        m_libspdm_local_buffer_size));
+    1185                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    1186                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    1187                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1188                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    1189                 :            :                                                         &data_size, NULL, NULL);
+    1190                 :          1 :         cert_buffer = (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
+    1191                 :          1 :         cert_buffer_size = data_size - (sizeof(spdm_cert_chain_t) + hash_size);
+    1192                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    1193                 :            :                          cert_buffer_hash);
+    1194                 :            :         /* transcript.message_a size is 0*/
+    1195                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    1196                 :            :                                       m_libspdm_local_buffer_size);
+    1197                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1198                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1199                 :          1 :         free(data);
+    1200                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    1201                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1202                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    1203                 :          1 :                            hash_data, (uint16_t)hash_size, hash_size,
+    1204                 :            :                            bin_str2, &bin_str2_size);
+    1205                 :          1 :         libspdm_psk_handshake_secret_hkdf_expand(
+    1206                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    1207                 :            :                 m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
+    1208                 :            :                 sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2, bin_str2_size,
+    1209                 :            :                 response_handshake_secret, hash_size);
+    1210                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    1211                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1212                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    1213                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7, &bin_str7_size);
+    1214                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    1215                 :            :                             hash_size, bin_str7, bin_str7_size,
+    1216                 :            :                             response_finished_key, hash_size);
+    1217                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1218                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1219                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    1220                 :            :                          response_finished_key, hash_size, ptr);
+    1221                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    1222                 :            :                          sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
+    1223                 :            :                          ptr, hmac_size);
+    1224                 :          1 :         m_libspdm_local_buffer_size += hmac_size;
+    1225                 :          1 :         ptr += hmac_size;
+    1226                 :            : 
+    1227                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1228                 :            :                                               false, spdm_response_size,
+    1229                 :            :                                               spdm_response, response_size,
+    1230                 :            :                                               response);
+    1231                 :            :     }
+    1232                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1233                 :          1 :     case 0xD: {
+    1234                 :            :         spdm_psk_exchange_response_t *spdm_response;
+    1235                 :            :         uint32_t hash_size;
+    1236                 :            :         uint32_t hmac_size;
+    1237                 :            :         uint8_t *ptr;
+    1238                 :            :         size_t opaque_psk_exchange_rsp_size;
+    1239                 :            :         void *data;
+    1240                 :            :         size_t data_size;
+    1241                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1242                 :            :         uint8_t *cert_buffer;
+    1243                 :            :         size_t cert_buffer_size;
+    1244                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    1245                 :            :         uint8_t bin_str2[128];
+    1246                 :            :         size_t bin_str2_size;
+    1247                 :            :         uint8_t bin_str7[128];
+    1248                 :            :         size_t bin_str7_size;
+    1249                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    1250                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    1251                 :            :         size_t spdm_response_size;
+    1252                 :            :         size_t transport_header_size;
+    1253                 :            : 
+    1254                 :          1 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
+    1255                 :            :             SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1256                 :            :         ((libspdm_context_t *)spdm_context)
+    1257                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    1258                 :            :             m_libspdm_use_asym_algo;
+    1259                 :            :         ((libspdm_context_t *)spdm_context)
+    1260                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    1261                 :            :             m_libspdm_use_hash_algo;
+    1262                 :            :         ((libspdm_context_t *)spdm_context)
+    1263                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    1264                 :            :             m_libspdm_use_dhe_algo;
+    1265                 :            :         ((libspdm_context_t *)spdm_context)
+    1266                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    1267                 :            :             m_libspdm_use_measurement_hash_algo;
+    1268                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1269                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1270                 :          1 :         opaque_psk_exchange_rsp_size =
+    1271                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    1272                 :            :                 spdm_context);
+    1273                 :          1 :         spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
+    1274                 :            :                              LIBSPDM_PSK_CONTEXT_LENGTH +
+    1275                 :          1 :                              opaque_psk_exchange_rsp_size + hmac_size;
+    1276                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1277                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1278                 :            : 
+    1279                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+    1280                 :          1 :         spdm_response->header.request_response_code =
+    1281                 :            :             SPDM_PSK_EXCHANGE_RSP;
+    1282                 :          1 :         spdm_response->header.param1 = 0;
+    1283                 :          1 :         spdm_response->header.param2 = 0;
+    1284                 :          1 :         spdm_response->rsp_session_id =
+    1285                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, true);
+    1286                 :          1 :         spdm_response->reserved = 0;
+    1287                 :          1 :         spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
+    1288                 :          1 :         spdm_response->opaque_length =
+    1289                 :          1 :             (uint16_t)opaque_psk_exchange_rsp_size;
+    1290                 :          1 :         ptr = (void *)(spdm_response + 1);
+    1291                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    1292                 :            :          * ptr += hash_size;*/
+    1293                 :          1 :         libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
+    1294                 :          1 :         ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
+    1295                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    1296                 :            :             spdm_context, &opaque_psk_exchange_rsp_size, ptr);
+    1297                 :          1 :         ptr += opaque_psk_exchange_rsp_size;
+    1298                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    1299                 :            :                          sizeof(m_libspdm_local_buffer)
+    1300                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    1301                 :            :                             m_libspdm_local_buffer),
+    1302                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    1303                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    1304                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    1305                 :            :                        m_libspdm_local_buffer_size));
+    1306                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    1307                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    1308                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1309                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    1310                 :            :                                                         &data_size, NULL, NULL);
+    1311                 :          1 :         cert_buffer =
+    1312                 :          1 :             (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
+    1313                 :          1 :         cert_buffer_size =
+    1314                 :          1 :             data_size - (sizeof(spdm_cert_chain_t) + hash_size);
+    1315                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    1316                 :            :                          cert_buffer_hash);
+    1317                 :            :         /* transcript.message_a size is 0*/
+    1318                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    1319                 :            :                                       m_libspdm_local_buffer_size);
+    1320                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1321                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1322                 :          1 :         free(data);
+    1323                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    1324                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1325                 :            :                            LIBSPDM_BIN_STR_2_LABEL, sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1,
+    1326                 :          1 :                            hash_data, (uint16_t)hash_size, hash_size,
+    1327                 :            :                            bin_str2, &bin_str2_size);
+    1328                 :          1 :         libspdm_psk_handshake_secret_hkdf_expand(
+    1329                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    1330                 :            :                 m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
+    1331                 :            :                 sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
+    1332                 :            :                 bin_str2_size,
+    1333                 :            :                 response_handshake_secret, hash_size);
+    1334                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    1335                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1336                 :            :                            LIBSPDM_BIN_STR_7_LABEL, sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1,
+    1337                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    1338                 :            :                            &bin_str7_size);
+    1339                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    1340                 :            :                             hash_size, bin_str7, bin_str7_size,
+    1341                 :            :                             response_finished_key, hash_size);
+    1342                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1343                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1344                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    1345                 :            :                          response_finished_key, hash_size, ptr);
+    1346                 :          1 :         ptr += hmac_size;
+    1347                 :            : 
+    1348                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1349                 :            :                                               false, spdm_response_size,
+    1350                 :            :                                               spdm_response, response_size,
+    1351                 :            :                                               response);
+    1352                 :            :     }
+    1353                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1354                 :          1 :     case 0xE: {
+    1355                 :            :         spdm_psk_exchange_response_t *spdm_response;
+    1356                 :            :         uint32_t hash_size;
+    1357                 :            :         uint32_t hmac_size;
+    1358                 :            :         uint32_t measurement_hash_size;
+    1359                 :            :         uint8_t *ptr;
+    1360                 :            :         size_t opaque_psk_exchange_rsp_size;
+    1361                 :            :         void *data;
+    1362                 :            :         size_t data_size;
+    1363                 :            :         uint8_t measurement_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1364                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1365                 :            :         uint8_t *cert_buffer;
+    1366                 :            :         size_t cert_buffer_size;
+    1367                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    1368                 :            :         uint8_t bin_str2[128];
+    1369                 :            :         size_t bin_str2_size;
+    1370                 :            :         uint8_t bin_str7[128];
+    1371                 :            :         size_t bin_str7_size;
+    1372                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    1373                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    1374                 :            :         size_t spdm_response_size;
+    1375                 :            :         size_t transport_header_size;
+    1376                 :            : 
+    1377                 :          1 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
+    1378                 :            :             SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1379                 :            :         ((libspdm_context_t *)spdm_context)
+    1380                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    1381                 :            :             m_libspdm_use_asym_algo;
+    1382                 :            :         ((libspdm_context_t *)spdm_context)
+    1383                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    1384                 :            :             m_libspdm_use_hash_algo;
+    1385                 :            :         ((libspdm_context_t *)spdm_context)
+    1386                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    1387                 :            :             m_libspdm_use_dhe_algo;
+    1388                 :            :         ((libspdm_context_t *)spdm_context)
+    1389                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    1390                 :            :             m_libspdm_use_measurement_hash_algo;
+    1391                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1392                 :          1 :         measurement_hash_size = libspdm_get_hash_size(
+    1393                 :            :             m_libspdm_use_hash_algo);
+    1394                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1395                 :          1 :         opaque_psk_exchange_rsp_size =
+    1396                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    1397                 :            :                 spdm_context);
+    1398                 :          1 :         spdm_response_size = sizeof(spdm_psk_exchange_response_t) +
+    1399                 :          1 :                              measurement_hash_size + LIBSPDM_PSK_CONTEXT_LENGTH +
+    1400                 :          1 :                              opaque_psk_exchange_rsp_size + hmac_size;
+    1401                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1402                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1403                 :            : 
+    1404                 :          1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    1405                 :            : 
+    1406                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1407                 :          1 :         spdm_response->header.request_response_code =
+    1408                 :            :             SPDM_PSK_EXCHANGE_RSP;
+    1409                 :          1 :         spdm_response->header.param1 = 0;
+    1410                 :          1 :         spdm_response->header.param2 = 0;
+    1411                 :          1 :         spdm_response->rsp_session_id =
+    1412                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, true);
+    1413                 :          1 :         spdm_response->reserved = 0;
+    1414                 :          1 :         spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
+    1415                 :          1 :         spdm_response->opaque_length =
+    1416                 :          1 :             (uint16_t)opaque_psk_exchange_rsp_size;
+    1417                 :          1 :         ptr = (void *)(spdm_response + 1);
+    1418                 :            :         /*Mock measurement hash as TCB*/
+    1419                 :          1 :         libspdm_copy_mem(measurement_hash_data, sizeof(measurement_hash_data),
+    1420                 :            :                          m_libspdm_use_tcb_hash_value, measurement_hash_size);
+    1421                 :          1 :         libspdm_copy_mem(ptr, spdm_response_size - (ptr - (uint8_t *)spdm_response),
+    1422                 :            :                          measurement_hash_data, measurement_hash_size);
+    1423                 :            :         /*libspdm_zero_mem (ptr, measurement_hash_size);*/
+    1424                 :          1 :         ptr += measurement_hash_size;
+    1425                 :          1 :         libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
+    1426                 :          1 :         ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
+    1427                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    1428                 :            :             spdm_context, &opaque_psk_exchange_rsp_size, ptr);
+    1429                 :          1 :         ptr += opaque_psk_exchange_rsp_size;
+    1430                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    1431                 :            :                          sizeof(m_libspdm_local_buffer)
+    1432                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    1433                 :            :                             m_libspdm_local_buffer),
+    1434                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    1435                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    1436                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    1437                 :            :                        m_libspdm_local_buffer_size));
+    1438                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    1439                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    1440                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1441                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    1442                 :            :                                                         &data_size, NULL, NULL);
+    1443                 :          1 :         cert_buffer =
+    1444                 :          1 :             (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
+    1445                 :          1 :         cert_buffer_size =
+    1446                 :          1 :             data_size - (sizeof(spdm_cert_chain_t) + hash_size);
+    1447                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    1448                 :            :                          cert_buffer_hash);
+    1449                 :            :         /* transcript.message_a size is 0*/
+    1450                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    1451                 :            :                                       m_libspdm_local_buffer_size);
+    1452                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1453                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1454                 :          1 :         free(data);
+    1455                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    1456                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1457                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    1458                 :          1 :                            hash_data, (uint16_t)hash_size, hash_size,
+    1459                 :            :                            bin_str2, &bin_str2_size);
+    1460                 :          1 :         libspdm_psk_handshake_secret_hkdf_expand(
+    1461                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    1462                 :            :                 m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
+    1463                 :            :                 sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
+    1464                 :            :                 bin_str2_size,
+    1465                 :            :                 response_handshake_secret, hash_size);
+    1466                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    1467                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1468                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    1469                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    1470                 :            :                            &bin_str7_size);
+    1471                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    1472                 :            :                             hash_size, bin_str7, bin_str7_size,
+    1473                 :            :                             response_finished_key, hash_size);
+    1474                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1475                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1476                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    1477                 :            :                          response_finished_key, hash_size, ptr);
+    1478                 :          1 :         ptr += hmac_size;
+    1479                 :            : 
+    1480                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1481                 :            :                                               false, spdm_response_size,
+    1482                 :            :                                               spdm_response, response_size,
+    1483                 :            :                                               response);
+    1484                 :            :     }
+    1485                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1486                 :            : 
+    1487                 :          1 :     case 0xF: {
+    1488                 :            :         spdm_psk_exchange_response_t *spdm_response;
+    1489                 :            :         uint32_t hash_size;
+    1490                 :            :         uint32_t hmac_size;
+    1491                 :            :         uint32_t measurement_hash_size;
+    1492                 :            :         uint8_t *ptr;
+    1493                 :            :         size_t opaque_psk_exchange_rsp_size;
+    1494                 :            :         void *data;
+    1495                 :            :         size_t data_size;
+    1496                 :            :         uint8_t measurement_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1497                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1498                 :            :         uint8_t *cert_buffer;
+    1499                 :            :         size_t cert_buffer_size;
+    1500                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    1501                 :            :         uint8_t bin_str2[128];
+    1502                 :            :         size_t bin_str2_size;
+    1503                 :            :         uint8_t bin_str7[128];
+    1504                 :            :         size_t bin_str7_size;
+    1505                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    1506                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    1507                 :            :         size_t spdm_response_size;
+    1508                 :            :         size_t transport_header_size;
+    1509                 :            : 
+    1510                 :          1 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
+    1511                 :            :             SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1512                 :            :         ((libspdm_context_t *)spdm_context)
+    1513                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    1514                 :            :             m_libspdm_use_asym_algo;
+    1515                 :            :         ((libspdm_context_t *)spdm_context)
+    1516                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    1517                 :            :             m_libspdm_use_hash_algo;
+    1518                 :            :         ((libspdm_context_t *)spdm_context)
+    1519                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    1520                 :            :             m_libspdm_use_dhe_algo;
+    1521                 :            :         ((libspdm_context_t *)spdm_context)
+    1522                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    1523                 :            :             m_libspdm_use_measurement_hash_algo;
+    1524                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1525                 :          1 :         measurement_hash_size = libspdm_get_hash_size(
+    1526                 :            :             m_libspdm_use_hash_algo);
+    1527                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1528                 :          1 :         opaque_psk_exchange_rsp_size =
+    1529                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    1530                 :            :                 spdm_context);
+    1531                 :          1 :         spdm_response_size = sizeof(spdm_psk_exchange_response_t) +
+    1532                 :          1 :                              measurement_hash_size + LIBSPDM_PSK_CONTEXT_LENGTH +
+    1533                 :          1 :                              opaque_psk_exchange_rsp_size + hmac_size;
+    1534                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1535                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1536                 :            : 
+    1537                 :          1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    1538                 :            : 
+    1539                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1540                 :          1 :         spdm_response->header.request_response_code =
+    1541                 :            :             SPDM_PSK_EXCHANGE_RSP;
+    1542                 :          1 :         spdm_response->header.param1 = 0;
+    1543                 :          1 :         spdm_response->header.param2 = 0;
+    1544                 :          1 :         spdm_response->rsp_session_id =
+    1545                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, true);
+    1546                 :          1 :         spdm_response->reserved = 0;
+    1547                 :          1 :         spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
+    1548                 :          1 :         spdm_response->opaque_length =
+    1549                 :          1 :             (uint16_t)opaque_psk_exchange_rsp_size;
+    1550                 :          1 :         ptr = (void *)(spdm_response + 1);
+    1551                 :            :         /*Mock measurement hash as 0x00 array*/
+    1552                 :          1 :         libspdm_zero_mem(measurement_hash_data, measurement_hash_size);
+    1553                 :          1 :         libspdm_copy_mem(ptr, spdm_response_size - (ptr - (uint8_t *)spdm_response),
+    1554                 :            :                          measurement_hash_data, measurement_hash_size);
+    1555                 :            :         /*libspdm_zero_mem (ptr, measurement_hash_size);*/
+    1556                 :          1 :         ptr += measurement_hash_size;
+    1557                 :          1 :         libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
+    1558                 :          1 :         ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
+    1559                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    1560                 :            :             spdm_context, &opaque_psk_exchange_rsp_size, ptr);
+    1561                 :          1 :         ptr += opaque_psk_exchange_rsp_size;
+    1562                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    1563                 :            :                          sizeof(m_libspdm_local_buffer)
+    1564                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    1565                 :            :                             m_libspdm_local_buffer),
+    1566                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    1567                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    1568                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    1569                 :            :                        m_libspdm_local_buffer_size));
+    1570                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    1571                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    1572                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1573                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    1574                 :            :                                                         &data_size, NULL, NULL);
+    1575                 :          1 :         cert_buffer =
+    1576                 :          1 :             (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
+    1577                 :          1 :         cert_buffer_size =
+    1578                 :          1 :             data_size - (sizeof(spdm_cert_chain_t) + hash_size);
+    1579                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    1580                 :            :                          cert_buffer_hash);
+    1581                 :            :         /* transcript.message_a size is 0*/
+    1582                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    1583                 :            :                                       m_libspdm_local_buffer_size);
+    1584                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1585                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1586                 :          1 :         free(data);
+    1587                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    1588                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1589                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    1590                 :          1 :                            hash_data, (uint16_t)hash_size, hash_size,
+    1591                 :            :                            bin_str2, &bin_str2_size);
+    1592                 :          1 :         libspdm_psk_handshake_secret_hkdf_expand(
+    1593                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    1594                 :            :                 m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
+    1595                 :            :                 sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
+    1596                 :            :                 bin_str2_size,
+    1597                 :            :                 response_handshake_secret, hash_size);
+    1598                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    1599                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1600                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    1601                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    1602                 :            :                            &bin_str7_size);
+    1603                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    1604                 :            :                             hash_size, bin_str7, bin_str7_size,
+    1605                 :            :                             response_finished_key, hash_size);
+    1606                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1607                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1608                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    1609                 :            :                          response_finished_key, hash_size, ptr);
+    1610                 :          1 :         ptr += hmac_size;
+    1611                 :            : 
+    1612                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1613                 :            :                                               false, spdm_response_size,
+    1614                 :            :                                               spdm_response, response_size,
+    1615                 :            :                                               response);
+    1616                 :            :     }
+    1617                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1618                 :            : 
+    1619                 :          1 :     case 0x10: {
+    1620                 :            :         spdm_psk_exchange_response_t *spdm_response;
+    1621                 :            :         uint32_t hash_size;
+    1622                 :            :         uint32_t hmac_size;
+    1623                 :            :         uint32_t measurement_hash_size;
+    1624                 :            :         uint8_t *ptr;
+    1625                 :            :         size_t opaque_psk_exchange_rsp_size;
+    1626                 :            :         void *data;
+    1627                 :            :         size_t data_size;
+    1628                 :            :         uint8_t measurement_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1629                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1630                 :            :         uint8_t *cert_buffer;
+    1631                 :            :         size_t cert_buffer_size;
+    1632                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    1633                 :            :         uint8_t bin_str2[128];
+    1634                 :            :         size_t bin_str2_size;
+    1635                 :            :         uint8_t bin_str7[128];
+    1636                 :            :         size_t bin_str7_size;
+    1637                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    1638                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    1639                 :            :         size_t spdm_response_size;
+    1640                 :            :         size_t transport_header_size;
+    1641                 :            : 
+    1642                 :          1 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
+    1643                 :            :             SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1644                 :            :         ((libspdm_context_t *)spdm_context)
+    1645                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    1646                 :            :             m_libspdm_use_asym_algo;
+    1647                 :            :         ((libspdm_context_t *)spdm_context)
+    1648                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    1649                 :            :             m_libspdm_use_hash_algo;
+    1650                 :            :         ((libspdm_context_t *)spdm_context)
+    1651                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    1652                 :            :             m_libspdm_use_dhe_algo;
+    1653                 :            :         ((libspdm_context_t *)spdm_context)
+    1654                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    1655                 :            :             m_libspdm_use_measurement_hash_algo;
+    1656                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1657                 :          1 :         measurement_hash_size = libspdm_get_hash_size(
+    1658                 :            :             m_libspdm_use_hash_algo);
+    1659                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1660                 :          1 :         opaque_psk_exchange_rsp_size =
+    1661                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    1662                 :            :                 spdm_context);
+    1663                 :          1 :         spdm_response_size = sizeof(spdm_psk_exchange_response_t) +
+    1664                 :          1 :                              measurement_hash_size + LIBSPDM_PSK_CONTEXT_LENGTH +
+    1665                 :          1 :                              opaque_psk_exchange_rsp_size + hmac_size;
+    1666                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1667                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1668                 :            : 
+    1669                 :          1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    1670                 :            : 
+    1671                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1672                 :          1 :         spdm_response->header.request_response_code =
+    1673                 :            :             SPDM_PSK_EXCHANGE_RSP;
+    1674                 :          1 :         spdm_response->header.param1 = 0;
+    1675                 :          1 :         spdm_response->header.param2 = 0;
+    1676                 :          1 :         spdm_response->rsp_session_id =
+    1677                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, true);
+    1678                 :          1 :         spdm_response->reserved = 0;
+    1679                 :          1 :         spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
+    1680                 :          1 :         spdm_response->opaque_length =
+    1681                 :          1 :             (uint16_t)opaque_psk_exchange_rsp_size;
+    1682                 :          1 :         ptr = (void *)(spdm_response + 1);
+    1683                 :            :         /*Mock measurement hash*/
+    1684                 :          1 :         libspdm_copy_mem(measurement_hash_data, sizeof(measurement_hash_data),
+    1685                 :            :                          m_libspdm_use_tcb_hash_value, measurement_hash_size);
+    1686                 :          1 :         libspdm_copy_mem(ptr, spdm_response_size - (ptr - (uint8_t *)spdm_response),
+    1687                 :            :                          measurement_hash_data, measurement_hash_size);
+    1688                 :            :         /*libspdm_zero_mem (ptr, measurement_hash_size);*/
+    1689                 :          1 :         ptr += measurement_hash_size;
+    1690                 :          1 :         libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
+    1691                 :          1 :         ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
+    1692                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    1693                 :            :             spdm_context, &opaque_psk_exchange_rsp_size, ptr);
+    1694                 :          1 :         ptr += opaque_psk_exchange_rsp_size;
+    1695                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    1696                 :            :                          sizeof(m_libspdm_local_buffer)
+    1697                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    1698                 :            :                             m_libspdm_local_buffer),
+    1699                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    1700                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    1701                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    1702                 :            :                        m_libspdm_local_buffer_size));
+    1703                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    1704                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    1705                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1706                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    1707                 :            :                                                         &data_size, NULL, NULL);
+    1708                 :          1 :         cert_buffer =
+    1709                 :          1 :             (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
+    1710                 :          1 :         cert_buffer_size =
+    1711                 :          1 :             data_size - (sizeof(spdm_cert_chain_t) + hash_size);
+    1712                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    1713                 :            :                          cert_buffer_hash);
+    1714                 :            :         /* transcript.message_a size is 0*/
+    1715                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    1716                 :            :                                       m_libspdm_local_buffer_size);
+    1717                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1718                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1719                 :          1 :         free(data);
+    1720                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    1721                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1722                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    1723                 :          1 :                            hash_data, (uint16_t)hash_size, hash_size,
+    1724                 :            :                            bin_str2, &bin_str2_size);
+    1725                 :          1 :         libspdm_psk_handshake_secret_hkdf_expand(
+    1726                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    1727                 :            :                 m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
+    1728                 :            :                 sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
+    1729                 :            :                 bin_str2_size,
+    1730                 :            :                 response_handshake_secret, hash_size);
+    1731                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    1732                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1733                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    1734                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    1735                 :            :                            &bin_str7_size);
+    1736                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    1737                 :            :                             hash_size, bin_str7, bin_str7_size,
+    1738                 :            :                             response_finished_key, hash_size);
+    1739                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1740                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1741                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    1742                 :            :                          response_finished_key, hash_size, ptr);
+    1743                 :          1 :         ptr += hmac_size;
+    1744                 :            : 
+    1745                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1746                 :            :                                               false, spdm_response_size,
+    1747                 :            :                                               spdm_response, response_size,
+    1748                 :            :                                               response);
+    1749                 :            :     }
+    1750                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1751                 :            : 
+    1752                 :          1 :     case 0x11: {
+    1753                 :            :         spdm_psk_exchange_response_t *spdm_response;
+    1754                 :            :         uint32_t hash_size;
+    1755                 :            :         uint32_t hmac_size;
+    1756                 :            :         uint8_t *ptr;
+    1757                 :            :         size_t opaque_psk_exchange_rsp_size;
+    1758                 :            :         void *data;
+    1759                 :            :         size_t data_size;
+    1760                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1761                 :            :         uint8_t *cert_buffer;
+    1762                 :            :         size_t cert_buffer_size;
+    1763                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    1764                 :            :         uint8_t bin_str2[128];
+    1765                 :            :         size_t bin_str2_size;
+    1766                 :            :         uint8_t bin_str7[128];
+    1767                 :            :         size_t bin_str7_size;
+    1768                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    1769                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    1770                 :            :         size_t spdm_response_size;
+    1771                 :            :         size_t transport_header_size;
+    1772                 :            : 
+    1773                 :          1 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
+    1774                 :            :             SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1775                 :            :         ((libspdm_context_t *)spdm_context)
+    1776                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    1777                 :            :             m_libspdm_use_asym_algo;
+    1778                 :            :         ((libspdm_context_t *)spdm_context)
+    1779                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    1780                 :            :             m_libspdm_use_hash_algo;
+    1781                 :            :         ((libspdm_context_t *)spdm_context)
+    1782                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    1783                 :            :             m_libspdm_use_dhe_algo;
+    1784                 :            :         ((libspdm_context_t *)spdm_context)
+    1785                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    1786                 :            :             m_libspdm_use_measurement_hash_algo;
+    1787                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1788                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1789                 :          1 :         opaque_psk_exchange_rsp_size =
+    1790                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    1791                 :            :                 spdm_context);
+    1792                 :          1 :         spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
+    1793                 :            :                              LIBSPDM_PSK_CONTEXT_LENGTH +
+    1794                 :          1 :                              opaque_psk_exchange_rsp_size + hmac_size;
+    1795                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1796                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1797                 :            : 
+    1798                 :          1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    1799                 :            : 
+    1800                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1801                 :          1 :         spdm_response->header.request_response_code =
+    1802                 :            :             SPDM_PSK_EXCHANGE_RSP;
+    1803                 :          1 :         spdm_response->header.param1 = 0;
+    1804                 :          1 :         spdm_response->header.param2 = 0;
+    1805                 :          1 :         spdm_response->rsp_session_id =
+    1806                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, true);
+    1807                 :          1 :         spdm_response->reserved = 0;
+    1808                 :          1 :         spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
+    1809                 :          1 :         spdm_response->opaque_length =
+    1810                 :          1 :             (uint16_t)opaque_psk_exchange_rsp_size;
+    1811                 :          1 :         ptr = (void *)(spdm_response + 1);
+    1812                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    1813                 :            :          * ptr += hash_size;*/
+    1814                 :          1 :         libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
+    1815                 :          1 :         ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
+    1816                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    1817                 :            :             spdm_context, &opaque_psk_exchange_rsp_size, ptr);
+    1818                 :          1 :         ptr += opaque_psk_exchange_rsp_size;
+    1819                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    1820                 :            :                          sizeof(m_libspdm_local_buffer)
+    1821                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    1822                 :            :                             m_libspdm_local_buffer),
+    1823                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    1824                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    1825                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    1826                 :            :                        m_libspdm_local_buffer_size));
+    1827                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    1828                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    1829                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1830                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    1831                 :            :                                                         &data_size, NULL, NULL);
+    1832                 :          1 :         cert_buffer =
+    1833                 :          1 :             (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
+    1834                 :          1 :         cert_buffer_size =
+    1835                 :          1 :             data_size - (sizeof(spdm_cert_chain_t) + hash_size);
+    1836                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    1837                 :            :                          cert_buffer_hash);
+    1838                 :            :         /* transcript.message_a size is 0*/
+    1839                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    1840                 :            :                                       m_libspdm_local_buffer_size);
+    1841                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1842                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1843                 :          1 :         free(data);
+    1844                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    1845                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1846                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    1847                 :          1 :                            hash_data, (uint16_t)hash_size, hash_size,
+    1848                 :            :                            bin_str2, &bin_str2_size);
+    1849                 :          1 :         libspdm_psk_handshake_secret_hkdf_expand(
+    1850                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    1851                 :            :                 m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
+    1852                 :            :                 sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
+    1853                 :            :                 bin_str2_size,
+    1854                 :            :                 response_handshake_secret, hash_size);
+    1855                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    1856                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1857                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    1858                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    1859                 :            :                            &bin_str7_size);
+    1860                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    1861                 :            :                             hash_size, bin_str7, bin_str7_size,
+    1862                 :            :                             response_finished_key, hash_size);
+    1863                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1864                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1865                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    1866                 :            :                          response_finished_key, hash_size, ptr);
+    1867                 :          1 :         ptr += hmac_size;
+    1868                 :            : 
+    1869                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1870                 :            :                                               false, spdm_response_size,
+    1871                 :            :                                               spdm_response, response_size,
+    1872                 :            :                                               response);
+    1873                 :            :     }
+    1874                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1875                 :            : 
+    1876                 :          1 :     case 0x12: {
+    1877                 :            :         spdm_psk_exchange_response_t *spdm_response;
+    1878                 :            :         uint32_t hash_size;
+    1879                 :            :         uint32_t hmac_size;
+    1880                 :            :         uint8_t *ptr;
+    1881                 :            :         size_t opaque_psk_exchange_rsp_size;
+    1882                 :            :         void *data;
+    1883                 :            :         size_t data_size;
+    1884                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1885                 :            :         uint8_t *cert_buffer;
+    1886                 :            :         size_t cert_buffer_size;
+    1887                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    1888                 :            :         uint8_t bin_str2[128];
+    1889                 :            :         size_t bin_str2_size;
+    1890                 :            :         uint8_t bin_str7[128];
+    1891                 :            :         size_t bin_str7_size;
+    1892                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    1893                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    1894                 :            :         size_t spdm_response_size;
+    1895                 :            :         size_t transport_header_size;
+    1896                 :            : 
+    1897                 :          1 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
+    1898                 :            :             SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1899                 :            :         ((libspdm_context_t *)spdm_context)
+    1900                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    1901                 :            :             m_libspdm_use_asym_algo;
+    1902                 :            :         ((libspdm_context_t *)spdm_context)
+    1903                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    1904                 :            :             m_libspdm_use_hash_algo;
+    1905                 :            :         ((libspdm_context_t *)spdm_context)
+    1906                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    1907                 :            :             m_libspdm_use_dhe_algo;
+    1908                 :            :         ((libspdm_context_t *)spdm_context)
+    1909                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    1910                 :            :             m_libspdm_use_measurement_hash_algo;
+    1911                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1912                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1913                 :          1 :         opaque_psk_exchange_rsp_size =
+    1914                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    1915                 :            :                 spdm_context);
+    1916                 :          1 :         spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
+    1917                 :            :                              LIBSPDM_PSK_CONTEXT_LENGTH +
+    1918                 :          1 :                              opaque_psk_exchange_rsp_size + hmac_size;
+    1919                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    1920                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    1921                 :            : 
+    1922                 :          1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    1923                 :            : 
+    1924                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    1925                 :          1 :         spdm_response->header.request_response_code =
+    1926                 :            :             SPDM_PSK_EXCHANGE_RSP;
+    1927                 :          1 :         spdm_response->header.param1 = 0;
+    1928                 :          1 :         spdm_response->header.param2 = 0;
+    1929                 :          1 :         spdm_response->rsp_session_id =
+    1930                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, true);
+    1931                 :          1 :         spdm_response->reserved = 0;
+    1932                 :          1 :         spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
+    1933                 :          1 :         spdm_response->opaque_length =
+    1934                 :          1 :             (uint16_t)opaque_psk_exchange_rsp_size;
+    1935                 :          1 :         ptr = (void *)(spdm_response + 1);
+    1936                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    1937                 :            :          * ptr += hash_size;*/
+    1938                 :          1 :         libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
+    1939                 :          1 :         ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
+    1940                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    1941                 :            :             spdm_context, &opaque_psk_exchange_rsp_size, ptr);
+    1942                 :          1 :         ptr += opaque_psk_exchange_rsp_size;
+    1943                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    1944                 :            :                          sizeof(m_libspdm_local_buffer)
+    1945                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    1946                 :            :                             m_libspdm_local_buffer),
+    1947                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    1948                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    1949                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    1950                 :            :                        m_libspdm_local_buffer_size));
+    1951                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    1952                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    1953                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1954                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    1955                 :            :                                                         &data_size, NULL, NULL);
+    1956                 :          1 :         cert_buffer =
+    1957                 :          1 :             (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
+    1958                 :          1 :         cert_buffer_size =
+    1959                 :          1 :             data_size - (sizeof(spdm_cert_chain_t) + hash_size);
+    1960                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    1961                 :            :                          cert_buffer_hash);
+    1962                 :            :         /* transcript.message_a size is 0*/
+    1963                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    1964                 :            :                                       m_libspdm_local_buffer_size);
+    1965                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1966                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1967                 :          1 :         free(data);
+    1968                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    1969                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1970                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    1971                 :          1 :                            hash_data, (uint16_t)hash_size, hash_size,
+    1972                 :            :                            bin_str2, &bin_str2_size);
+    1973                 :          1 :         libspdm_psk_handshake_secret_hkdf_expand(
+    1974                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    1975                 :            :                 m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
+    1976                 :            :                 sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
+    1977                 :            :                 bin_str2_size,
+    1978                 :            :                 response_handshake_secret, hash_size);
+    1979                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    1980                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    1981                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    1982                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    1983                 :            :                            &bin_str7_size);
+    1984                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    1985                 :            :                             hash_size, bin_str7, bin_str7_size,
+    1986                 :            :                             response_finished_key, hash_size);
+    1987                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1988                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1989                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    1990                 :            :                          response_finished_key, hash_size, ptr);
+    1991                 :          1 :         ptr += hmac_size;
+    1992                 :            : 
+    1993                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    1994                 :            :                                               false, spdm_response_size,
+    1995                 :            :                                               spdm_response, response_size,
+    1996                 :            :                                               response);
+    1997                 :            :     }
+    1998                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    1999                 :            : 
+    2000                 :          1 :     case 0x13: {
+    2001                 :            :         spdm_psk_exchange_response_t *spdm_response;
+    2002                 :            :         uint32_t hash_size;
+    2003                 :            :         uint32_t hmac_size;
+    2004                 :            :         uint32_t measurement_hash_size;
+    2005                 :            :         uint8_t *ptr;
+    2006                 :            :         size_t opaque_psk_exchange_rsp_size;
+    2007                 :            :         void *data;
+    2008                 :            :         size_t data_size;
+    2009                 :            :         uint8_t measurement_hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2010                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2011                 :            :         uint8_t *cert_buffer;
+    2012                 :            :         size_t cert_buffer_size;
+    2013                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    2014                 :            :         uint8_t bin_str2[128];
+    2015                 :            :         size_t bin_str2_size;
+    2016                 :            :         uint8_t bin_str7[128];
+    2017                 :            :         size_t bin_str7_size;
+    2018                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    2019                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    2020                 :            :         size_t spdm_response_size;
+    2021                 :            :         size_t transport_header_size;
+    2022                 :            : 
+    2023                 :          1 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
+    2024                 :            :             SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2025                 :            :         ((libspdm_context_t *)spdm_context)
+    2026                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    2027                 :            :             m_libspdm_use_asym_algo;
+    2028                 :            :         ((libspdm_context_t *)spdm_context)
+    2029                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    2030                 :            :             m_libspdm_use_hash_algo;
+    2031                 :            :         ((libspdm_context_t *)spdm_context)
+    2032                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    2033                 :            :             m_libspdm_use_dhe_algo;
+    2034                 :            :         ((libspdm_context_t *)spdm_context)
+    2035                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    2036                 :            :             m_libspdm_use_measurement_hash_algo;
+    2037                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2038                 :          1 :         measurement_hash_size = libspdm_get_hash_size(
+    2039                 :            :             m_libspdm_use_hash_algo);
+    2040                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2041                 :          1 :         opaque_psk_exchange_rsp_size =
+    2042                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    2043                 :            :                 spdm_context);
+    2044                 :          1 :         spdm_response_size = sizeof(spdm_psk_exchange_response_t) +
+    2045                 :          1 :                              measurement_hash_size + LIBSPDM_PSK_CONTEXT_LENGTH +
+    2046                 :          1 :                              opaque_psk_exchange_rsp_size + hmac_size;
+    2047                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2048                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2049                 :            : 
+    2050                 :          1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
+    2051                 :            : 
+    2052                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2053                 :          1 :         spdm_response->header.request_response_code =
+    2054                 :            :             SPDM_PSK_EXCHANGE_RSP;
+    2055                 :          1 :         spdm_response->header.param1 = 0;
+    2056                 :          1 :         spdm_response->header.param2 = 0;
+    2057                 :          1 :         spdm_response->rsp_session_id =
+    2058                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, true);
+    2059                 :          1 :         spdm_response->reserved = 0;
+    2060                 :          1 :         spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
+    2061                 :          1 :         spdm_response->opaque_length =
+    2062                 :          1 :             (uint16_t)opaque_psk_exchange_rsp_size;
+    2063                 :          1 :         ptr = (void *)(spdm_response + 1);
+    2064                 :            :         /*Mock measurement hash as TCB*/
+    2065                 :          1 :         libspdm_copy_mem(measurement_hash_data, sizeof(measurement_hash_data),
+    2066                 :            :                          m_libspdm_use_tcb_hash_value, measurement_hash_size);
+    2067                 :          1 :         libspdm_copy_mem(ptr, spdm_response_size - (ptr - (uint8_t *)spdm_response),
+    2068                 :            :                          measurement_hash_data, measurement_hash_size);
+    2069                 :            :         /*libspdm_zero_mem (ptr, measurement_hash_size);*/
+    2070                 :          1 :         ptr += measurement_hash_size;
+    2071                 :          1 :         libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
+    2072                 :          1 :         ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
+    2073                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    2074                 :            :             spdm_context, &opaque_psk_exchange_rsp_size, ptr);
+    2075                 :          1 :         ptr += opaque_psk_exchange_rsp_size;
+    2076                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    2077                 :            :                          sizeof(m_libspdm_local_buffer)
+    2078                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    2079                 :            :                             m_libspdm_local_buffer),
+    2080                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    2081                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    2082                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    2083                 :            :                        m_libspdm_local_buffer_size));
+    2084                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    2085                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    2086                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    2087                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    2088                 :            :                                                         &data_size, NULL, NULL);
+    2089                 :          1 :         cert_buffer =
+    2090                 :          1 :             (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
+    2091                 :          1 :         cert_buffer_size =
+    2092                 :          1 :             data_size - (sizeof(spdm_cert_chain_t) + hash_size);
+    2093                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    2094                 :            :                          cert_buffer_hash);
+    2095                 :            :         /* transcript.message_a size is 0*/
+    2096                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    2097                 :            :                                       m_libspdm_local_buffer_size);
+    2098                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2099                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2100                 :          1 :         free(data);
+    2101                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    2102                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2103                 :            :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
+    2104                 :          1 :                            hash_data, (uint16_t)hash_size, hash_size,
+    2105                 :            :                            bin_str2, &bin_str2_size);
+    2106                 :          1 :         libspdm_psk_handshake_secret_hkdf_expand(
+    2107                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    2108                 :            :                 m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
+    2109                 :            :                 sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
+    2110                 :            :                 bin_str2_size,
+    2111                 :            :                 response_handshake_secret, hash_size);
+    2112                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    2113                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2114                 :            :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
+    2115                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    2116                 :            :                            &bin_str7_size);
+    2117                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    2118                 :            :                             hash_size, bin_str7, bin_str7_size,
+    2119                 :            :                             response_finished_key, hash_size);
+    2120                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2121                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2122                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    2123                 :            :                          response_finished_key, hash_size, ptr);
+    2124                 :          1 :         ptr += hmac_size;
+    2125                 :            : 
+    2126                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    2127                 :            :                                               false, spdm_response_size,
+    2128                 :            :                                               spdm_response, response_size,
+    2129                 :            :                                               response);
+    2130                 :            :     }
+    2131                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    2132                 :            : 
+    2133                 :          1 :     case 0x14: {
+    2134                 :            :         spdm_psk_exchange_response_t *spdm_response;
+    2135                 :            :         uint32_t hash_size;
+    2136                 :            :         uint32_t hmac_size;
+    2137                 :            :         uint8_t *ptr;
+    2138                 :            :         size_t opaque_psk_exchange_rsp_size;
+    2139                 :            :         void *data;
+    2140                 :            :         size_t data_size;
+    2141                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2142                 :            :         uint8_t *cert_buffer;
+    2143                 :            :         size_t cert_buffer_size;
+    2144                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    2145                 :            :         uint8_t bin_str2[128];
+    2146                 :            :         size_t bin_str2_size;
+    2147                 :            :         uint8_t bin_str7[128];
+    2148                 :            :         size_t bin_str7_size;
+    2149                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    2150                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    2151                 :            :         size_t spdm_response_size;
+    2152                 :            :         size_t transport_header_size;
+    2153                 :            : 
+    2154                 :          1 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
+    2155                 :            :             SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2156                 :            :         ((libspdm_context_t *)spdm_context)
+    2157                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    2158                 :            :             m_libspdm_use_asym_algo;
+    2159                 :            :         ((libspdm_context_t *)spdm_context)
+    2160                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    2161                 :            :             m_libspdm_use_hash_algo;
+    2162                 :            :         ((libspdm_context_t *)spdm_context)
+    2163                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    2164                 :            :             m_libspdm_use_dhe_algo;
+    2165                 :            :         ((libspdm_context_t *)spdm_context)
+    2166                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    2167                 :            :             m_libspdm_use_measurement_hash_algo;
+    2168                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2169                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2170                 :          1 :         opaque_psk_exchange_rsp_size =
+    2171                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    2172                 :            :                 spdm_context);
+    2173                 :          1 :         spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
+    2174                 :            :                              LIBSPDM_PSK_CONTEXT_LENGTH +
+    2175                 :          1 :                              opaque_psk_exchange_rsp_size + hmac_size;
+    2176                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2177                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2178                 :            : 
+    2179                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2180                 :          1 :         spdm_response->header.request_response_code =
+    2181                 :            :             SPDM_PSK_EXCHANGE_RSP;
+    2182                 :          1 :         spdm_response->header.param1 = 5;
+    2183                 :          1 :         spdm_response->header.param2 = 0;
+    2184                 :          1 :         spdm_response->rsp_session_id =
+    2185                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, true);
+    2186                 :          1 :         spdm_response->reserved = 0;
+    2187                 :          1 :         spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
+    2188                 :          1 :         spdm_response->opaque_length =
+    2189                 :          1 :             (uint16_t)opaque_psk_exchange_rsp_size;
+    2190                 :          1 :         ptr = (void *)(spdm_response + 1);
+    2191                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    2192                 :            :          * ptr += hash_size;*/
+    2193                 :          1 :         libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
+    2194                 :          1 :         ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
+    2195                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    2196                 :            :             spdm_context, &opaque_psk_exchange_rsp_size, ptr);
+    2197                 :          1 :         ptr += opaque_psk_exchange_rsp_size;
+    2198                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    2199                 :            :                          sizeof(m_libspdm_local_buffer)
+    2200                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    2201                 :            :                             m_libspdm_local_buffer),
+    2202                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    2203                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    2204                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    2205                 :            :                        m_libspdm_local_buffer_size));
+    2206                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    2207                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    2208                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    2209                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    2210                 :            :                                                         &data_size, NULL, NULL);
+    2211                 :          1 :         cert_buffer =
+    2212                 :          1 :             (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
+    2213                 :          1 :         cert_buffer_size =
+    2214                 :          1 :             data_size - (sizeof(spdm_cert_chain_t) + hash_size);
+    2215                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    2216                 :            :                          cert_buffer_hash);
+    2217                 :            :         /* transcript.message_a size is 0*/
+    2218                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    2219                 :            :                                       m_libspdm_local_buffer_size);
+    2220                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2221                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2222                 :          1 :         free(data);
+    2223                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    2224                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2225                 :            :                            LIBSPDM_BIN_STR_2_LABEL, sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1,
+    2226                 :          1 :                            hash_data, (uint16_t)hash_size, hash_size,
+    2227                 :            :                            bin_str2, &bin_str2_size);
+    2228                 :          1 :         libspdm_psk_handshake_secret_hkdf_expand(
+    2229                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    2230                 :            :                 m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
+    2231                 :            :                 sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
+    2232                 :            :                 bin_str2_size,
+    2233                 :            :                 response_handshake_secret, hash_size);
+    2234                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    2235                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2236                 :            :                            LIBSPDM_BIN_STR_7_LABEL, sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1,
+    2237                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    2238                 :            :                            &bin_str7_size);
+    2239                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    2240                 :            :                             hash_size, bin_str7, bin_str7_size,
+    2241                 :            :                             response_finished_key, hash_size);
+    2242                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2243                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2244                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    2245                 :            :                          response_finished_key, hash_size, ptr);
+    2246                 :          1 :         ptr += hmac_size;
+    2247                 :            : 
+    2248                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    2249                 :            :                                               false, spdm_response_size,
+    2250                 :            :                                               spdm_response, response_size,
+    2251                 :            :                                               response);
+    2252                 :            :     }
+    2253                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    2254                 :            : 
+    2255                 :          1 :     case 0x15: {
+    2256                 :            :         spdm_psk_exchange_response_t *spdm_response;
+    2257                 :            :         uint32_t hash_size;
+    2258                 :            :         uint32_t hmac_size;
+    2259                 :            :         uint8_t *ptr;
+    2260                 :            :         size_t opaque_psk_exchange_rsp_size;
+    2261                 :            :         void *data;
+    2262                 :            :         size_t data_size;
+    2263                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2264                 :            :         uint8_t *cert_buffer;
+    2265                 :            :         size_t cert_buffer_size;
+    2266                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    2267                 :            :         uint8_t bin_str2[128];
+    2268                 :            :         size_t bin_str2_size;
+    2269                 :            :         uint8_t bin_str7[128];
+    2270                 :            :         size_t bin_str7_size;
+    2271                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    2272                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    2273                 :            :         size_t spdm_response_size;
+    2274                 :            :         size_t transport_header_size;
+    2275                 :            : 
+    2276                 :          1 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
+    2277                 :            :             SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2278                 :            :         ((libspdm_context_t *)spdm_context)
+    2279                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    2280                 :            :             m_libspdm_use_asym_algo;
+    2281                 :            :         ((libspdm_context_t *)spdm_context)
+    2282                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    2283                 :            :             m_libspdm_use_hash_algo;
+    2284                 :            :         ((libspdm_context_t *)spdm_context)
+    2285                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    2286                 :            :             m_libspdm_use_dhe_algo;
+    2287                 :            :         ((libspdm_context_t *)spdm_context)
+    2288                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    2289                 :            :             m_libspdm_use_measurement_hash_algo;
+    2290                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2291                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2292                 :          1 :         opaque_psk_exchange_rsp_size =
+    2293                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    2294                 :            :                 spdm_context);
+    2295                 :          1 :         spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
+    2296                 :            :                              LIBSPDM_PSK_CONTEXT_LENGTH +
+    2297                 :          1 :                              opaque_psk_exchange_rsp_size + hmac_size;
+    2298                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2299                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2300                 :            : 
+    2301                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2302                 :          1 :         spdm_response->header.request_response_code =
+    2303                 :            :             SPDM_PSK_EXCHANGE_RSP;
+    2304                 :          1 :         spdm_response->header.param1 = 5;
+    2305                 :          1 :         spdm_response->header.param2 = 0;
+    2306                 :          1 :         spdm_response->rsp_session_id =
+    2307                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, true);
+    2308                 :          1 :         spdm_response->reserved = 0;
+    2309                 :          1 :         spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
+    2310                 :          1 :         spdm_response->opaque_length =
+    2311                 :          1 :             (uint16_t)opaque_psk_exchange_rsp_size;
+    2312                 :          1 :         ptr = (void *)(spdm_response + 1);
+    2313                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    2314                 :            :          * ptr += hash_size;*/
+    2315                 :          1 :         libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
+    2316                 :          1 :         ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
+    2317                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    2318                 :            :             spdm_context, &opaque_psk_exchange_rsp_size, ptr);
+    2319                 :          1 :         ptr += opaque_psk_exchange_rsp_size;
+    2320                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    2321                 :            :                          sizeof(m_libspdm_local_buffer)
+    2322                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    2323                 :            :                             m_libspdm_local_buffer),
+    2324                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    2325                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    2326                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    2327                 :            :                        m_libspdm_local_buffer_size));
+    2328                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    2329                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    2330                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    2331                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    2332                 :            :                                                         &data_size, NULL, NULL);
+    2333                 :          1 :         cert_buffer =
+    2334                 :          1 :             (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
+    2335                 :          1 :         cert_buffer_size =
+    2336                 :          1 :             data_size - (sizeof(spdm_cert_chain_t) + hash_size);
+    2337                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    2338                 :            :                          cert_buffer_hash);
+    2339                 :            :         /* transcript.message_a size is 0*/
+    2340                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    2341                 :            :                                       m_libspdm_local_buffer_size);
+    2342                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2343                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2344                 :          1 :         free(data);
+    2345                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    2346                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2347                 :            :                            LIBSPDM_BIN_STR_2_LABEL, sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1,
+    2348                 :          1 :                            hash_data, (uint16_t)hash_size, hash_size,
+    2349                 :            :                            bin_str2, &bin_str2_size);
+    2350                 :          1 :         libspdm_psk_handshake_secret_hkdf_expand(
+    2351                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    2352                 :            :                 m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
+    2353                 :            :                 sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
+    2354                 :            :                 bin_str2_size,
+    2355                 :            :                 response_handshake_secret, hash_size);
+    2356                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    2357                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2358                 :            :                            LIBSPDM_BIN_STR_7_LABEL, sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1,
+    2359                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    2360                 :            :                            &bin_str7_size);
+    2361                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    2362                 :            :                             hash_size, bin_str7, bin_str7_size,
+    2363                 :            :                             response_finished_key, hash_size);
+    2364                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2365                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2366                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    2367                 :            :                          response_finished_key, hash_size, ptr);
+    2368                 :          1 :         ptr += hmac_size;
+    2369                 :            : 
+    2370                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    2371                 :            :                                               false, spdm_response_size,
+    2372                 :            :                                               spdm_response, response_size,
+    2373                 :            :                                               response);
+    2374                 :            :     }
+    2375                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    2376                 :            : 
+    2377                 :          1 :     case 0x16: {
+    2378                 :            :         spdm_psk_exchange_response_t *spdm_response;
+    2379                 :            :         uint32_t hash_size;
+    2380                 :            :         uint32_t hmac_size;
+    2381                 :            :         uint8_t *ptr;
+    2382                 :            :         size_t opaque_psk_exchange_rsp_size;
+    2383                 :            :         void *data;
+    2384                 :            :         size_t data_size;
+    2385                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2386                 :            :         uint8_t *cert_buffer;
+    2387                 :            :         size_t cert_buffer_size;
+    2388                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    2389                 :            :         uint8_t bin_str2[128];
+    2390                 :            :         size_t bin_str2_size;
+    2391                 :            :         uint8_t bin_str7[128];
+    2392                 :            :         size_t bin_str7_size;
+    2393                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    2394                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    2395                 :            :         size_t spdm_response_size;
+    2396                 :            :         size_t transport_header_size;
+    2397                 :            : 
+    2398                 :          1 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
+    2399                 :            :             SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2400                 :            :         ((libspdm_context_t *)spdm_context)
+    2401                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    2402                 :            :             m_libspdm_use_asym_algo;
+    2403                 :            :         ((libspdm_context_t *)spdm_context)
+    2404                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    2405                 :            :             m_libspdm_use_hash_algo;
+    2406                 :            :         ((libspdm_context_t *)spdm_context)
+    2407                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    2408                 :            :             m_libspdm_use_dhe_algo;
+    2409                 :            :         ((libspdm_context_t *)spdm_context)
+    2410                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    2411                 :            :             m_libspdm_use_measurement_hash_algo;
+    2412                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2413                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2414                 :          1 :         opaque_psk_exchange_rsp_size =
+    2415                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    2416                 :            :                 spdm_context);
+    2417                 :          1 :         spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
+    2418                 :            :                              LIBSPDM_PSK_CONTEXT_LENGTH +
+    2419                 :          1 :                              opaque_psk_exchange_rsp_size + hmac_size;
+    2420                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2421                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2422                 :            : 
+    2423                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2424                 :          1 :         spdm_response->header.request_response_code =
+    2425                 :            :             SPDM_PSK_EXCHANGE_RSP;
+    2426                 :          1 :         spdm_response->header.param1 = 0;
+    2427                 :          1 :         spdm_response->header.param2 = 0;
+    2428                 :          1 :         spdm_response->rsp_session_id =
+    2429                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, true);
+    2430                 :          1 :         spdm_response->reserved = 0;
+    2431                 :          1 :         spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
+    2432                 :          1 :         spdm_response->opaque_length =
+    2433                 :          1 :             (uint16_t)opaque_psk_exchange_rsp_size;
+    2434                 :          1 :         ptr = (void *)(spdm_response + 1);
+    2435                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    2436                 :            :          * ptr += hash_size;*/
+    2437                 :          1 :         libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
+    2438                 :          1 :         ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
+    2439                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    2440                 :            :             spdm_context, &opaque_psk_exchange_rsp_size, ptr);
+    2441                 :          1 :         ptr += opaque_psk_exchange_rsp_size;
+    2442                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    2443                 :            :                          sizeof(m_libspdm_local_buffer)
+    2444                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    2445                 :            :                             m_libspdm_local_buffer),
+    2446                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    2447                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    2448                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    2449                 :            :                        m_libspdm_local_buffer_size));
+    2450                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    2451                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    2452                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    2453                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    2454                 :            :                                                         &data_size, NULL, NULL);
+    2455                 :          1 :         cert_buffer =
+    2456                 :          1 :             (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
+    2457                 :          1 :         cert_buffer_size =
+    2458                 :          1 :             data_size - (sizeof(spdm_cert_chain_t) + hash_size);
+    2459                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    2460                 :            :                          cert_buffer_hash);
+    2461                 :            :         /* transcript.message_a size is 0*/
+    2462                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    2463                 :            :                                       m_libspdm_local_buffer_size);
+    2464                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2465                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2466                 :          1 :         free(data);
+    2467                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    2468                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2469                 :            :                            LIBSPDM_BIN_STR_2_LABEL, sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1,
+    2470                 :          1 :                            hash_data, (uint16_t)hash_size, hash_size,
+    2471                 :            :                            bin_str2, &bin_str2_size);
+    2472                 :          1 :         libspdm_psk_handshake_secret_hkdf_expand(
+    2473                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    2474                 :            :                 m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
+    2475                 :            :                 sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
+    2476                 :            :                 bin_str2_size,
+    2477                 :            :                 response_handshake_secret, hash_size);
+    2478                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    2479                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2480                 :            :                            LIBSPDM_BIN_STR_7_LABEL, sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1,
+    2481                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    2482                 :            :                            &bin_str7_size);
+    2483                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    2484                 :            :                             hash_size, bin_str7, bin_str7_size,
+    2485                 :            :                             response_finished_key, hash_size);
+    2486                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2487                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2488                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    2489                 :            :                          response_finished_key, hash_size, ptr);
+    2490                 :          1 :         ptr += hmac_size;
+    2491                 :            : 
+    2492                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    2493                 :            :                                               false, spdm_response_size,
+    2494                 :            :                                               spdm_response, response_size,
+    2495                 :            :                                               response);
+    2496                 :            :     }
+    2497                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    2498                 :            : 
+    2499                 :          1 :     case 0x17: {
+    2500                 :            :         spdm_psk_exchange_response_t *spdm_response;
+    2501                 :            :         uint32_t hash_size;
+    2502                 :            :         uint32_t hmac_size;
+    2503                 :            :         uint8_t *ptr;
+    2504                 :            :         size_t opaque_psk_exchange_rsp_size;
+    2505                 :            :         void *data;
+    2506                 :            :         size_t data_size;
+    2507                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2508                 :            :         uint8_t *cert_buffer;
+    2509                 :            :         size_t cert_buffer_size;
+    2510                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    2511                 :            :         uint8_t bin_str2[128];
+    2512                 :            :         size_t bin_str2_size;
+    2513                 :            :         uint8_t bin_str7[128];
+    2514                 :            :         size_t bin_str7_size;
+    2515                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    2516                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    2517                 :            :         size_t spdm_response_size;
+    2518                 :            :         size_t transport_header_size;
+    2519                 :            : 
+    2520                 :          1 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
+    2521                 :            :             SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2522                 :            :         ((libspdm_context_t *)spdm_context)
+    2523                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    2524                 :            :             m_libspdm_use_asym_algo;
+    2525                 :            :         ((libspdm_context_t *)spdm_context)
+    2526                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    2527                 :            :             m_libspdm_use_hash_algo;
+    2528                 :            :         ((libspdm_context_t *)spdm_context)
+    2529                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    2530                 :            :             m_libspdm_use_dhe_algo;
+    2531                 :            :         ((libspdm_context_t *)spdm_context)
+    2532                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    2533                 :            :             m_libspdm_use_measurement_hash_algo;
+    2534                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2535                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2536                 :          1 :         opaque_psk_exchange_rsp_size =
+    2537                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    2538                 :            :                 spdm_context);
+    2539                 :          1 :         spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
+    2540                 :            :                              LIBSPDM_PSK_CONTEXT_LENGTH +
+    2541                 :          1 :                              opaque_psk_exchange_rsp_size + hmac_size;
+    2542                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2543                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2544                 :            : 
+    2545                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2546                 :          1 :         spdm_response->header.request_response_code =
+    2547                 :            :             SPDM_PSK_EXCHANGE_RSP;
+    2548                 :          1 :         spdm_response->header.param1 = 0;
+    2549                 :          1 :         spdm_response->header.param2 = 0;
+    2550                 :          1 :         spdm_response->rsp_session_id =
+    2551                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, true);
+    2552                 :          1 :         spdm_response->reserved = 0;
+    2553                 :          1 :         spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
+    2554                 :          1 :         spdm_response->opaque_length =
+    2555                 :          1 :             (uint16_t)opaque_psk_exchange_rsp_size;
+    2556                 :          1 :         ptr = (void *)(spdm_response + 1);
+    2557                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    2558                 :            :          * ptr += hash_size;*/
+    2559                 :          1 :         libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
+    2560                 :          1 :         ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
+    2561                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    2562                 :            :             spdm_context, &opaque_psk_exchange_rsp_size, ptr);
+    2563                 :          1 :         ptr += opaque_psk_exchange_rsp_size;
+    2564                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    2565                 :            :                          sizeof(m_libspdm_local_buffer)
+    2566                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    2567                 :            :                             m_libspdm_local_buffer),
+    2568                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    2569                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    2570                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    2571                 :            :                        m_libspdm_local_buffer_size));
+    2572                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    2573                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    2574                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    2575                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    2576                 :            :                                                         &data_size, NULL, NULL);
+    2577                 :          1 :         cert_buffer =
+    2578                 :          1 :             (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
+    2579                 :          1 :         cert_buffer_size =
+    2580                 :          1 :             data_size - (sizeof(spdm_cert_chain_t) + hash_size);
+    2581                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    2582                 :            :                          cert_buffer_hash);
+    2583                 :            :         /* transcript.message_a size is 0*/
+    2584                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    2585                 :            :                                       m_libspdm_local_buffer_size);
+    2586                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2587                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2588                 :          1 :         free(data);
+    2589                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    2590                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2591                 :            :                            LIBSPDM_BIN_STR_2_LABEL, sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1,
+    2592                 :          1 :                            hash_data, (uint16_t)hash_size, hash_size,
+    2593                 :            :                            bin_str2, &bin_str2_size);
+    2594                 :          1 :         libspdm_psk_handshake_secret_hkdf_expand(
+    2595                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    2596                 :            :                 m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
+    2597                 :            :                 sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
+    2598                 :            :                 bin_str2_size,
+    2599                 :            :                 response_handshake_secret, hash_size);
+    2600                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    2601                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2602                 :            :                            LIBSPDM_BIN_STR_7_LABEL, sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1,
+    2603                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    2604                 :            :                            &bin_str7_size);
+    2605                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    2606                 :            :                             hash_size, bin_str7, bin_str7_size,
+    2607                 :            :                             response_finished_key, hash_size);
+    2608                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2609                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2610                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    2611                 :            :                          response_finished_key, hash_size, ptr);
+    2612                 :            :         /* Flip last byte of ResponderVerifyData*/
+    2613                 :          1 :         ptr += hmac_size-1;
+    2614                 :          1 :         *ptr ^= 0xFF;
+    2615                 :          1 :         ptr++;
+    2616                 :            : 
+    2617                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    2618                 :            :                                               false, spdm_response_size,
+    2619                 :            :                                               spdm_response, response_size,
+    2620                 :            :                                               response);
+    2621                 :            :     }
+    2622                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    2623                 :            : 
+    2624                 :          1 :     case 0x18: {
+    2625                 :            :         spdm_psk_exchange_response_t *spdm_response;
+    2626                 :            :         uint32_t hash_size;
+    2627                 :            :         uint32_t hmac_size;
+    2628                 :            :         uint8_t *ptr;
+    2629                 :            :         size_t opaque_psk_exchange_rsp_size;
+    2630                 :            :         void *data;
+    2631                 :            :         size_t data_size;
+    2632                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2633                 :            :         uint8_t *cert_buffer;
+    2634                 :            :         size_t cert_buffer_size;
+    2635                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    2636                 :            :         uint8_t bin_str2[128];
+    2637                 :            :         size_t bin_str2_size;
+    2638                 :            :         uint8_t bin_str7[128];
+    2639                 :            :         size_t bin_str7_size;
+    2640                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    2641                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    2642                 :            :         size_t spdm_response_size;
+    2643                 :            :         size_t transport_header_size;
+    2644                 :            : 
+    2645                 :          1 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
+    2646                 :            :             SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2647                 :            :         ((libspdm_context_t *)spdm_context)
+    2648                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    2649                 :            :             m_libspdm_use_asym_algo;
+    2650                 :            :         ((libspdm_context_t *)spdm_context)
+    2651                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    2652                 :            :             m_libspdm_use_hash_algo;
+    2653                 :            :         ((libspdm_context_t *)spdm_context)
+    2654                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    2655                 :            :             m_libspdm_use_dhe_algo;
+    2656                 :            :         ((libspdm_context_t *)spdm_context)
+    2657                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    2658                 :            :             m_libspdm_use_measurement_hash_algo;
+    2659                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2660                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2661                 :          1 :         opaque_psk_exchange_rsp_size =
+    2662                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    2663                 :            :                 spdm_context);
+    2664                 :          1 :         spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
+    2665                 :            :                              0 +
+    2666                 :          1 :                              opaque_psk_exchange_rsp_size + hmac_size;
+    2667                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2668                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2669                 :            : 
+    2670                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2671                 :          1 :         spdm_response->header.request_response_code =
+    2672                 :            :             SPDM_PSK_EXCHANGE_RSP;
+    2673                 :          1 :         spdm_response->header.param1 = 0;
+    2674                 :          1 :         spdm_response->header.param2 = 0;
+    2675                 :          1 :         spdm_response->rsp_session_id =
+    2676                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, true);
+    2677                 :          1 :         spdm_response->reserved = 0;
+    2678                 :          1 :         spdm_response->context_length = 0;
+    2679                 :          1 :         spdm_response->opaque_length =
+    2680                 :          1 :             (uint16_t)opaque_psk_exchange_rsp_size;
+    2681                 :          1 :         ptr = (void *)(spdm_response + 1);
+    2682                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    2683                 :            :          * ptr += hash_size;*/
+    2684                 :            :         /* libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
+    2685                 :            :          * ptr += LIBSPDM_PSK_CONTEXT_LENGTH;*/
+    2686                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    2687                 :            :             spdm_context, &opaque_psk_exchange_rsp_size, ptr);
+    2688                 :          1 :         ptr += opaque_psk_exchange_rsp_size;
+    2689                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    2690                 :            :                          sizeof(m_libspdm_local_buffer)
+    2691                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    2692                 :            :                             m_libspdm_local_buffer),
+    2693                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    2694                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    2695                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    2696                 :            :                        m_libspdm_local_buffer_size));
+    2697                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    2698                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    2699                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    2700                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    2701                 :            :                                                         &data_size, NULL, NULL);
+    2702                 :          1 :         cert_buffer =
+    2703                 :          1 :             (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
+    2704                 :          1 :         cert_buffer_size =
+    2705                 :          1 :             data_size - (sizeof(spdm_cert_chain_t) + hash_size);
+    2706                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    2707                 :            :                          cert_buffer_hash);
+    2708                 :            :         /* transcript.message_a size is 0*/
+    2709                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    2710                 :            :                                       m_libspdm_local_buffer_size);
+    2711                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2712                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2713                 :          1 :         free(data);
+    2714                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    2715                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2716                 :            :                            LIBSPDM_BIN_STR_2_LABEL, sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1,
+    2717                 :          1 :                            hash_data, (uint16_t)hash_size, hash_size,
+    2718                 :            :                            bin_str2, &bin_str2_size);
+    2719                 :          1 :         libspdm_psk_handshake_secret_hkdf_expand(
+    2720                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    2721                 :            :                 m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
+    2722                 :            :                 sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
+    2723                 :            :                 bin_str2_size,
+    2724                 :            :                 response_handshake_secret, hash_size);
+    2725                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    2726                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2727                 :            :                            LIBSPDM_BIN_STR_7_LABEL, sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1,
+    2728                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    2729                 :            :                            &bin_str7_size);
+    2730                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    2731                 :            :                             hash_size, bin_str7, bin_str7_size,
+    2732                 :            :                             response_finished_key, hash_size);
+    2733                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2734                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2735                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    2736                 :            :                          response_finished_key, hash_size, ptr);
+    2737                 :          1 :         ptr += hmac_size;
+    2738                 :            : 
+    2739                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    2740                 :            :                                               false, spdm_response_size,
+    2741                 :            :                                               spdm_response, response_size,
+    2742                 :            :                                               response);
+    2743                 :            :     }
+    2744                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    2745                 :            : 
+    2746                 :          1 :     case 0x19: {
+    2747                 :            :         spdm_psk_exchange_response_t *spdm_response;
+    2748                 :            :         uint32_t hash_size;
+    2749                 :            :         uint32_t hmac_size;
+    2750                 :            :         uint8_t *ptr;
+    2751                 :            :         size_t opaque_psk_exchange_rsp_size;
+    2752                 :            :         void *data;
+    2753                 :            :         size_t data_size;
+    2754                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2755                 :            :         uint8_t *cert_buffer;
+    2756                 :            :         size_t cert_buffer_size;
+    2757                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    2758                 :            :         uint8_t bin_str2[128];
+    2759                 :            :         size_t bin_str2_size;
+    2760                 :            :         uint8_t bin_str7[128];
+    2761                 :            :         size_t bin_str7_size;
+    2762                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    2763                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    2764                 :            :         size_t spdm_response_size;
+    2765                 :            :         size_t transport_header_size;
+    2766                 :            : 
+    2767                 :          1 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
+    2768                 :            :             SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2769                 :            :         ((libspdm_context_t *)spdm_context)
+    2770                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    2771                 :            :             m_libspdm_use_asym_algo;
+    2772                 :            :         ((libspdm_context_t *)spdm_context)
+    2773                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    2774                 :            :             m_libspdm_use_hash_algo;
+    2775                 :            :         ((libspdm_context_t *)spdm_context)
+    2776                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    2777                 :            :             m_libspdm_use_dhe_algo;
+    2778                 :            :         ((libspdm_context_t *)spdm_context)
+    2779                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    2780                 :            :             m_libspdm_use_measurement_hash_algo;
+    2781                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2782                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2783                 :          1 :         opaque_psk_exchange_rsp_size = 0;
+    2784                 :          1 :         spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
+    2785                 :            :                              LIBSPDM_PSK_CONTEXT_LENGTH +
+    2786                 :          1 :                              opaque_psk_exchange_rsp_size + hmac_size;
+    2787                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2788                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2789                 :            : 
+    2790                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2791                 :          1 :         spdm_response->header.request_response_code =
+    2792                 :            :             SPDM_PSK_EXCHANGE_RSP;
+    2793                 :          1 :         spdm_response->header.param1 = 0;
+    2794                 :          1 :         spdm_response->header.param2 = 0;
+    2795                 :          1 :         spdm_response->rsp_session_id =
+    2796                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, true);
+    2797                 :          1 :         spdm_response->reserved = 0;
+    2798                 :          1 :         spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
+    2799                 :          1 :         spdm_response->opaque_length =
+    2800                 :          1 :             (uint16_t)opaque_psk_exchange_rsp_size;
+    2801                 :          1 :         ptr = (void *)(spdm_response + 1);
+    2802                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    2803                 :            :          * ptr += hash_size;*/
+    2804                 :          1 :         libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
+    2805                 :          1 :         ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
+    2806                 :            :         /* libspdm_build_opaque_data_version_selection_data(
+    2807                 :            :          *    spdm_context, &opaque_psk_exchange_rsp_size, ptr);
+    2808                 :            :          * ptr += opaque_psk_exchange_rsp_size;*/
+    2809                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    2810                 :            :                          sizeof(m_libspdm_local_buffer)
+    2811                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    2812                 :            :                             m_libspdm_local_buffer),
+    2813                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    2814                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    2815                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    2816                 :            :                        m_libspdm_local_buffer_size));
+    2817                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    2818                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    2819                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    2820                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    2821                 :            :                                                         &data_size, NULL, NULL);
+    2822                 :          1 :         cert_buffer =
+    2823                 :          1 :             (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
+    2824                 :          1 :         cert_buffer_size =
+    2825                 :          1 :             data_size - (sizeof(spdm_cert_chain_t) + hash_size);
+    2826                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    2827                 :            :                          cert_buffer_hash);
+    2828                 :            :         /* transcript.message_a size is 0*/
+    2829                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    2830                 :            :                                       m_libspdm_local_buffer_size);
+    2831                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2832                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2833                 :          1 :         free(data);
+    2834                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    2835                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2836                 :            :                            LIBSPDM_BIN_STR_2_LABEL, sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1,
+    2837                 :          1 :                            hash_data, (uint16_t)hash_size, hash_size,
+    2838                 :            :                            bin_str2, &bin_str2_size);
+    2839                 :          1 :         libspdm_psk_handshake_secret_hkdf_expand(
+    2840                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    2841                 :            :                 m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
+    2842                 :            :                 sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
+    2843                 :            :                 bin_str2_size,
+    2844                 :            :                 response_handshake_secret, hash_size);
+    2845                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    2846                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2847                 :            :                            LIBSPDM_BIN_STR_7_LABEL, sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1,
+    2848                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    2849                 :            :                            &bin_str7_size);
+    2850                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    2851                 :            :                             hash_size, bin_str7, bin_str7_size,
+    2852                 :            :                             response_finished_key, hash_size);
+    2853                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2854                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2855                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    2856                 :            :                          response_finished_key, hash_size, ptr);
+    2857                 :          1 :         ptr += hmac_size;
+    2858                 :            : 
+    2859                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    2860                 :            :                                               false, spdm_response_size,
+    2861                 :            :                                               spdm_response, response_size,
+    2862                 :            :                                               response);
+    2863                 :            :     }
+    2864                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    2865                 :            : 
+    2866                 :          1 :     case 0x1A: {
+    2867                 :            :         spdm_psk_exchange_response_t *spdm_response;
+    2868                 :            :         uint32_t hash_size;
+    2869                 :            :         uint32_t hmac_size;
+    2870                 :            :         uint8_t *ptr;
+    2871                 :            :         size_t opaque_psk_exchange_rsp_size;
+    2872                 :            :         void *data;
+    2873                 :            :         size_t data_size;
+    2874                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2875                 :            :         uint8_t *cert_buffer;
+    2876                 :            :         size_t cert_buffer_size;
+    2877                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    2878                 :            :         uint8_t bin_str2[128];
+    2879                 :            :         size_t bin_str2_size;
+    2880                 :            :         uint8_t bin_str7[128];
+    2881                 :            :         size_t bin_str7_size;
+    2882                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    2883                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    2884                 :            :         size_t spdm_response_size;
+    2885                 :            :         size_t transport_header_size;
+    2886                 :            : 
+    2887                 :          1 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
+    2888                 :            :             SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2889                 :            :         ((libspdm_context_t *)spdm_context)
+    2890                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    2891                 :            :             m_libspdm_use_asym_algo;
+    2892                 :            :         ((libspdm_context_t *)spdm_context)
+    2893                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    2894                 :            :             m_libspdm_use_hash_algo;
+    2895                 :            :         ((libspdm_context_t *)spdm_context)
+    2896                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    2897                 :            :             m_libspdm_use_dhe_algo;
+    2898                 :            :         ((libspdm_context_t *)spdm_context)
+    2899                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    2900                 :            :             m_libspdm_use_measurement_hash_algo;
+    2901                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2902                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2903                 :          1 :         opaque_psk_exchange_rsp_size = 0;
+    2904                 :          1 :         spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
+    2905                 :            :                              0 +
+    2906                 :          1 :                              opaque_psk_exchange_rsp_size + hmac_size;
+    2907                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    2908                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    2909                 :            : 
+    2910                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+    2911                 :          1 :         spdm_response->header.request_response_code =
+    2912                 :            :             SPDM_PSK_EXCHANGE_RSP;
+    2913                 :          1 :         spdm_response->header.param1 = 0;
+    2914                 :          1 :         spdm_response->header.param2 = 0;
+    2915                 :          1 :         spdm_response->rsp_session_id =
+    2916                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, true);
+    2917                 :          1 :         spdm_response->reserved = 0;
+    2918                 :          1 :         spdm_response->context_length = 0;
+    2919                 :          1 :         spdm_response->opaque_length =
+    2920                 :          1 :             (uint16_t)opaque_psk_exchange_rsp_size;
+    2921                 :          1 :         ptr = (void *)(spdm_response + 1);
+    2922                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    2923                 :            :          * ptr += hash_size;*/
+    2924                 :            :         /*libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
+    2925                 :            :          * ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
+    2926                 :            :          * libspdm_build_opaque_data_version_selection_data(
+    2927                 :            :          *  spdm_context, &opaque_psk_exchange_rsp_size, ptr);
+    2928                 :            :          * ptr += opaque_psk_exchange_rsp_size;*/
+    2929                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    2930                 :            :                          sizeof(m_libspdm_local_buffer)
+    2931                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    2932                 :            :                             m_libspdm_local_buffer),
+    2933                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    2934                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    2935                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    2936                 :            :                        m_libspdm_local_buffer_size));
+    2937                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    2938                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    2939                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    2940                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    2941                 :            :                                                         &data_size, NULL, NULL);
+    2942                 :          1 :         cert_buffer =
+    2943                 :          1 :             (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
+    2944                 :          1 :         cert_buffer_size =
+    2945                 :          1 :             data_size - (sizeof(spdm_cert_chain_t) + hash_size);
+    2946                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    2947                 :            :                          cert_buffer_hash);
+    2948                 :            :         /* transcript.message_a size is 0*/
+    2949                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    2950                 :            :                                       m_libspdm_local_buffer_size);
+    2951                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2952                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2953                 :          1 :         free(data);
+    2954                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    2955                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2956                 :            :                            LIBSPDM_BIN_STR_2_LABEL, sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1,
+    2957                 :          1 :                            hash_data, (uint16_t)hash_size, hash_size,
+    2958                 :            :                            bin_str2, &bin_str2_size);
+    2959                 :          1 :         libspdm_psk_handshake_secret_hkdf_expand(
+    2960                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    2961                 :            :                 m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
+    2962                 :            :                 sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
+    2963                 :            :                 bin_str2_size,
+    2964                 :            :                 response_handshake_secret, hash_size);
+    2965                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    2966                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    2967                 :            :                            LIBSPDM_BIN_STR_7_LABEL, sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1,
+    2968                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    2969                 :            :                            &bin_str7_size);
+    2970                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    2971                 :            :                             hash_size, bin_str7, bin_str7_size,
+    2972                 :            :                             response_finished_key, hash_size);
+    2973                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2974                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2975                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    2976                 :            :                          response_finished_key, hash_size, ptr);
+    2977                 :          1 :         ptr += hmac_size;
+    2978                 :            : 
+    2979                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    2980                 :            :                                               false, spdm_response_size,
+    2981                 :            :                                               spdm_response, response_size,
+    2982                 :            :                                               response);
+    2983                 :            :     }
+    2984                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    2985                 :          1 :     case 0x1B: {
+    2986                 :            :         spdm_psk_exchange_response_t *spdm_response;
+    2987                 :            :         uint32_t hash_size;
+    2988                 :            :         uint32_t hmac_size;
+    2989                 :            :         uint8_t *ptr;
+    2990                 :            :         size_t opaque_psk_exchange_rsp_size;
+    2991                 :            :         void *data;
+    2992                 :            :         size_t data_size;
+    2993                 :            :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2994                 :            :         uint8_t *cert_buffer;
+    2995                 :            :         size_t cert_buffer_size;
+    2996                 :            :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    2997                 :            :         uint8_t bin_str2[128];
+    2998                 :            :         size_t bin_str2_size;
+    2999                 :            :         uint8_t bin_str7[128];
+    3000                 :            :         size_t bin_str7_size;
+    3001                 :            :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
+    3002                 :            :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    3003                 :            :         size_t spdm_response_size;
+    3004                 :            :         size_t transport_header_size;
+    3005                 :            : 
+    3006                 :          1 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
+    3007                 :            :             SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3008                 :            :         ((libspdm_context_t *)spdm_context)
+    3009                 :          1 :         ->connection_info.algorithm.base_asym_algo =
+    3010                 :            :             m_libspdm_use_asym_algo;
+    3011                 :            :         ((libspdm_context_t *)spdm_context)
+    3012                 :          1 :         ->connection_info.algorithm.base_hash_algo =
+    3013                 :            :             m_libspdm_use_hash_algo;
+    3014                 :            :         ((libspdm_context_t *)spdm_context)
+    3015                 :          1 :         ->connection_info.algorithm.dhe_named_group =
+    3016                 :            :             m_libspdm_use_dhe_algo;
+    3017                 :            :         ((libspdm_context_t *)spdm_context)
+    3018                 :          1 :         ->connection_info.algorithm.measurement_hash_algo =
+    3019                 :            :             m_libspdm_use_measurement_hash_algo;
+    3020                 :          1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3021                 :          1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3022                 :          1 :         opaque_psk_exchange_rsp_size =
+    3023                 :          1 :             libspdm_get_opaque_data_version_selection_data_size(
+    3024                 :            :                 spdm_context);
+    3025                 :          1 :         spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
+    3026                 :            :                              LIBSPDM_PSK_CONTEXT_LENGTH +
+    3027                 :          1 :                              opaque_psk_exchange_rsp_size + hmac_size;
+    3028                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+    3029                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+    3030                 :            : 
+    3031                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+    3032                 :          1 :         spdm_response->header.request_response_code =
+    3033                 :            :             SPDM_PSK_EXCHANGE_RSP;
+    3034                 :          1 :         spdm_response->header.param1 = 0;
+    3035                 :          1 :         spdm_response->header.param2 = 0;
+    3036                 :          1 :         spdm_response->rsp_session_id =
+    3037                 :          1 :             libspdm_allocate_rsp_session_id(spdm_context, true);
+    3038                 :          1 :         spdm_response->reserved = 0;
+    3039                 :          1 :         spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
+    3040                 :          1 :         spdm_response->opaque_length =
+    3041                 :          1 :             (uint16_t)opaque_psk_exchange_rsp_size;
+    3042                 :          1 :         ptr = (void *)(spdm_response + 1);
+    3043                 :            :         /* libspdm_zero_mem (ptr, hash_size);
+    3044                 :            :          * ptr += hash_size;*/
+    3045                 :          1 :         libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
+    3046                 :          1 :         ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
+    3047                 :          1 :         libspdm_build_opaque_data_version_selection_data(
+    3048                 :            :             spdm_context, &opaque_psk_exchange_rsp_size, ptr);
+    3049                 :          1 :         ptr += opaque_psk_exchange_rsp_size;
+    3050                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+    3051                 :            :                          sizeof(m_libspdm_local_buffer)
+    3052                 :          1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
+    3053                 :            :                             m_libspdm_local_buffer),
+    3054                 :          1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
+    3055                 :          1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
+    3056                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
+    3057                 :            :                        m_libspdm_local_buffer_size));
+    3058                 :          1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    3059                 :          1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    3060                 :          1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3061                 :            :                                                         m_libspdm_use_asym_algo, &data,
+    3062                 :            :                                                         &data_size, NULL, NULL);
+    3063                 :          1 :         cert_buffer =
+    3064                 :          1 :             (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
+    3065                 :          1 :         cert_buffer_size =
+    3066                 :          1 :             data_size - (sizeof(spdm_cert_chain_t) + hash_size);
+    3067                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    3068                 :            :                          cert_buffer_hash);
+    3069                 :            :         /* transcript.message_a size is 0*/
+    3070                 :          1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
+    3071                 :            :                                       m_libspdm_local_buffer_size);
+    3072                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3073                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    3074                 :          1 :         free(data);
+    3075                 :          1 :         bin_str2_size = sizeof(bin_str2);
+    3076                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    3077                 :            :                            LIBSPDM_BIN_STR_2_LABEL, sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1,
+    3078                 :          1 :                            hash_data, (uint16_t)hash_size, hash_size,
+    3079                 :            :                            bin_str2, &bin_str2_size);
+    3080                 :          1 :         libspdm_psk_handshake_secret_hkdf_expand(
+    3081                 :          1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    3082                 :            :                 m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
+    3083                 :            :                 sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
+    3084                 :            :                 bin_str2_size,
+    3085                 :            :                 response_handshake_secret, hash_size);
+    3086                 :          1 :         bin_str7_size = sizeof(bin_str7);
+    3087                 :          1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
+    3088                 :            :                            LIBSPDM_BIN_STR_7_LABEL, sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1,
+    3089                 :          1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
+    3090                 :            :                            &bin_str7_size);
+    3091                 :          1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
+    3092                 :            :                             hash_size, bin_str7, bin_str7_size,
+    3093                 :            :                             response_finished_key, hash_size);
+    3094                 :          1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3095                 :            :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    3096                 :          1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    3097                 :            :                          response_finished_key, hash_size, ptr);
+    3098                 :          1 :         ptr += hmac_size;
+    3099                 :            : 
+    3100                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+    3101                 :            :                                               false, spdm_response_size,
+    3102                 :            :                                               spdm_response, response_size,
+    3103                 :            :                                               response);
+    3104                 :            :     }
+    3105                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+    3106                 :            : 
+    3107                 :          0 :     default:
+    3108                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+    3109                 :            :     }
+    3110                 :            : }
+    3111                 :            : 
+    3112                 :          1 : void libspdm_test_requester_psk_exchange_case1(void **state)
+    3113                 :            : {
+    3114                 :            :     libspdm_return_t status;
+    3115                 :            :     libspdm_test_context_t *spdm_test_context;
+    3116                 :            :     libspdm_context_t *spdm_context;
+    3117                 :            :     uint32_t session_id;
+    3118                 :            :     uint8_t heartbeat_period;
+    3119                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    3120                 :            :     void *data;
+    3121                 :            :     size_t data_size;
+    3122                 :            :     void *hash;
+    3123                 :            :     size_t hash_size;
+    3124                 :            : 
+    3125                 :          1 :     spdm_test_context = *state;
+    3126                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    3127                 :          1 :     spdm_test_context->case_id = 0x1;
+    3128                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    3129                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3130                 :          1 :     spdm_context->connection_info.connection_state =
+    3131                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    3132                 :          1 :     spdm_context->connection_info.capability.flags &=
+    3133                 :            :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
+    3134                 :          1 :     spdm_context->connection_info.capability.flags |=
+    3135                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
+    3136                 :          1 :     spdm_context->local_context.capability.flags |=
+    3137                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
+    3138                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3139                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    3140                 :            :                                                     &data_size, &hash, &hash_size);
+    3141                 :          1 :     libspdm_reset_message_a(spdm_context);
+    3142                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    3143                 :            :         m_libspdm_use_hash_algo;
+    3144                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    3145                 :            :         m_libspdm_use_dhe_algo;
+    3146                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    3147                 :            :         m_libspdm_use_aead_algo;
+    3148                 :          1 :     spdm_context->connection_info.algorithm.key_schedule =
+    3149                 :            :         m_libspdm_use_key_schedule_algo;
+    3150                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    3151                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    3152                 :            :         data_size;
+    3153                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    3154                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    3155                 :            :                      data, data_size);
+    3156                 :            : #endif
+    3157                 :            : 
+    3158                 :          1 :     heartbeat_period = 0;
+    3159                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    3160                 :          1 :     status = libspdm_send_receive_psk_exchange(
+    3161                 :            :         spdm_context, NULL, 0,
+    3162                 :            :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
+    3163                 :            :         &heartbeat_period, measurement_hash);
+    3164                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SEND_FAIL);
+    3165                 :          1 :     free(data);
+    3166                 :          1 : }
+    3167                 :            : 
+    3168                 :          1 : void libspdm_test_requester_psk_exchange_case2(void **state)
+    3169                 :            : {
+    3170                 :            :     libspdm_return_t status;
+    3171                 :            :     libspdm_test_context_t *spdm_test_context;
+    3172                 :            :     libspdm_context_t *spdm_context;
+    3173                 :            :     uint32_t session_id;
+    3174                 :            :     uint8_t heartbeat_period;
+    3175                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    3176                 :            :     void *data;
+    3177                 :            :     size_t data_size;
+    3178                 :            :     void *hash;
+    3179                 :            :     size_t hash_size;
+    3180                 :            : 
+    3181                 :          1 :     spdm_test_context = *state;
+    3182                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    3183                 :          1 :     spdm_test_context->case_id = 0x2;
+    3184                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    3185                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3186                 :          1 :     spdm_context->connection_info.connection_state =
+    3187                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    3188                 :          1 :     spdm_context->connection_info.capability.flags &=
+    3189                 :            :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
+    3190                 :          1 :     spdm_context->connection_info.capability.flags |=
+    3191                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
+    3192                 :          1 :     spdm_context->local_context.capability.flags |=
+    3193                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
+    3194                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
+    3195                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
+    3196                 :            :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3197                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3198                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    3199                 :            :                                                     &data_size, &hash, &hash_size);
+    3200                 :          1 :     libspdm_reset_message_a(spdm_context);
+    3201                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    3202                 :            :         m_libspdm_use_hash_algo;
+    3203                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    3204                 :            :         m_libspdm_use_dhe_algo;
+    3205                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    3206                 :            :         m_libspdm_use_aead_algo;
+    3207                 :          1 :     spdm_context->connection_info.algorithm.key_schedule =
+    3208                 :            :         m_libspdm_use_key_schedule_algo;
+    3209                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    3210                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    3211                 :            :         data_size;
+    3212                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    3213                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    3214                 :            :                      data, data_size);
+    3215                 :            : #endif
+    3216                 :            : 
+    3217                 :          1 :     heartbeat_period = 0;
+    3218                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    3219                 :          1 :     status = libspdm_send_receive_psk_exchange(
+    3220                 :            :         spdm_context,
+    3221                 :            :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
+    3222                 :            :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
+    3223                 :            :         &heartbeat_period, measurement_hash);
+    3224                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    3225                 :          1 :     assert_int_equal(session_id, 0xFFFFFFFF);
+    3226                 :          1 :     assert_int_equal(
+    3227                 :            :         libspdm_secured_message_get_session_state(
+    3228                 :            :             spdm_context->session_info[0].secured_message_context),
+    3229                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    3230                 :          1 :     free(data);
+    3231                 :          1 : }
+    3232                 :            : 
+    3233                 :          1 : void libspdm_test_requester_psk_exchange_case3(void **state)
+    3234                 :            : {
+    3235                 :            :     libspdm_return_t status;
+    3236                 :            :     libspdm_test_context_t *spdm_test_context;
+    3237                 :            :     libspdm_context_t *spdm_context;
+    3238                 :            :     uint32_t session_id;
+    3239                 :            :     uint8_t heartbeat_period;
+    3240                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    3241                 :            :     void *data;
+    3242                 :            :     size_t data_size;
+    3243                 :            :     void *hash;
+    3244                 :            :     size_t hash_size;
+    3245                 :            : 
+    3246                 :          1 :     spdm_test_context = *state;
+    3247                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    3248                 :          1 :     spdm_test_context->case_id = 0x3;
+    3249                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    3250                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3251                 :          1 :     spdm_context->connection_info.connection_state =
+    3252                 :            :         LIBSPDM_CONNECTION_STATE_NOT_STARTED;
+    3253                 :          1 :     spdm_context->connection_info.capability.flags &=
+    3254                 :            :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
+    3255                 :          1 :     spdm_context->connection_info.capability.flags |=
+    3256                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
+    3257                 :          1 :     spdm_context->local_context.capability.flags |=
+    3258                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
+    3259                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3260                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    3261                 :            :                                                     &data_size, &hash, &hash_size);
+    3262                 :          1 :     libspdm_reset_message_a(spdm_context);
+    3263                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    3264                 :            :         m_libspdm_use_hash_algo;
+    3265                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    3266                 :            :         m_libspdm_use_dhe_algo;
+    3267                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    3268                 :            :         m_libspdm_use_aead_algo;
+    3269                 :          1 :     spdm_context->connection_info.algorithm.key_schedule =
+    3270                 :            :         m_libspdm_use_key_schedule_algo;
+    3271                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    3272                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    3273                 :            :         data_size;
+    3274                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    3275                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    3276                 :            :                      data, data_size);
+    3277                 :            : #endif
+    3278                 :            : 
+    3279                 :          1 :     heartbeat_period = 0;
+    3280                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    3281                 :          1 :     status = libspdm_send_receive_psk_exchange(
+    3282                 :            :         spdm_context,
+    3283                 :            :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
+    3284                 :            :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
+    3285                 :            :         &heartbeat_period, measurement_hash);
+    3286                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_STATE_LOCAL);
+    3287                 :          1 :     free(data);
+    3288                 :          1 : }
+    3289                 :            : 
+    3290                 :          1 : void libspdm_test_requester_psk_exchange_case4(void **state)
+    3291                 :            : {
+    3292                 :            :     libspdm_return_t status;
+    3293                 :            :     libspdm_test_context_t *spdm_test_context;
+    3294                 :            :     libspdm_context_t *spdm_context;
+    3295                 :            :     uint32_t session_id;
+    3296                 :            :     uint8_t heartbeat_period;
+    3297                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    3298                 :            :     void *data;
+    3299                 :            :     size_t data_size;
+    3300                 :            :     void *hash;
+    3301                 :            :     size_t hash_size;
+    3302                 :            : 
+    3303                 :          1 :     spdm_test_context = *state;
+    3304                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    3305                 :          1 :     spdm_test_context->case_id = 0x4;
+    3306                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    3307                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3308                 :          1 :     spdm_context->connection_info.connection_state =
+    3309                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    3310                 :          1 :     spdm_context->connection_info.capability.flags &=
+    3311                 :            :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
+    3312                 :          1 :     spdm_context->connection_info.capability.flags |=
+    3313                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
+    3314                 :          1 :     spdm_context->local_context.capability.flags |=
+    3315                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
+    3316                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3317                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    3318                 :            :                                                     &data_size, &hash, &hash_size);
+    3319                 :          1 :     libspdm_reset_message_a(spdm_context);
+    3320                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    3321                 :            :         m_libspdm_use_hash_algo;
+    3322                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    3323                 :            :         m_libspdm_use_dhe_algo;
+    3324                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    3325                 :            :         m_libspdm_use_aead_algo;
+    3326                 :          1 :     spdm_context->connection_info.algorithm.key_schedule =
+    3327                 :            :         m_libspdm_use_key_schedule_algo;
+    3328                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    3329                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    3330                 :            :         data_size;
+    3331                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    3332                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    3333                 :            :                      data, data_size);
+    3334                 :            : #endif
+    3335                 :            : 
+    3336                 :          1 :     heartbeat_period = 0;
+    3337                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    3338                 :          1 :     status = libspdm_send_receive_psk_exchange(
+    3339                 :            :         spdm_context,
+    3340                 :            :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
+    3341                 :            :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
+    3342                 :            :         &heartbeat_period, measurement_hash);
+    3343                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_ERROR_PEER);
+    3344                 :          1 :     free(data);
+    3345                 :          1 : }
+    3346                 :            : 
+    3347                 :          1 : void libspdm_test_requester_psk_exchange_case5(void **state)
+    3348                 :            : {
+    3349                 :            :     libspdm_return_t status;
+    3350                 :            :     libspdm_test_context_t *spdm_test_context;
+    3351                 :            :     libspdm_context_t *spdm_context;
+    3352                 :            :     uint32_t session_id;
+    3353                 :            :     uint8_t heartbeat_period;
+    3354                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    3355                 :            :     void *data;
+    3356                 :            :     size_t data_size;
+    3357                 :            :     void *hash;
+    3358                 :            :     size_t hash_size;
+    3359                 :            : 
+    3360                 :          1 :     spdm_test_context = *state;
+    3361                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    3362                 :          1 :     spdm_test_context->case_id = 0x5;
+    3363                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    3364                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3365                 :          1 :     spdm_context->connection_info.connection_state =
+    3366                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    3367                 :          1 :     spdm_context->connection_info.capability.flags &=
+    3368                 :            :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
+    3369                 :          1 :     spdm_context->connection_info.capability.flags |=
+    3370                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
+    3371                 :          1 :     spdm_context->local_context.capability.flags |=
+    3372                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
+    3373                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3374                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    3375                 :            :                                                     &data_size, &hash, &hash_size);
+    3376                 :          1 :     libspdm_reset_message_a(spdm_context);
+    3377                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    3378                 :            :         m_libspdm_use_hash_algo;
+    3379                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    3380                 :            :         m_libspdm_use_asym_algo;
+    3381                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    3382                 :            :         m_libspdm_use_dhe_algo;
+    3383                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    3384                 :            :         m_libspdm_use_aead_algo;
+    3385                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    3386                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    3387                 :            :         data_size;
+    3388                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    3389                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    3390                 :            :                      data, data_size);
+    3391                 :            : #endif
+    3392                 :            : 
+    3393                 :          1 :     heartbeat_period = 0;
+    3394                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    3395                 :          1 :     status = libspdm_send_receive_psk_exchange(
+    3396                 :            :         spdm_context,
+    3397                 :            :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
+    3398                 :            :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
+    3399                 :            :         &heartbeat_period, measurement_hash);
+    3400                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_BUSY_PEER);
+    3401                 :          1 :     free(data);
+    3402                 :          1 : }
+    3403                 :            : 
+    3404                 :          1 : void libspdm_test_requester_psk_exchange_case6(void **state)
+    3405                 :            : {
+    3406                 :            :     libspdm_return_t status;
+    3407                 :            :     libspdm_test_context_t *spdm_test_context;
+    3408                 :            :     libspdm_context_t *spdm_context;
+    3409                 :            :     uint32_t session_id;
+    3410                 :            :     uint8_t heartbeat_period;
+    3411                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    3412                 :            :     void *data;
+    3413                 :            :     size_t data_size;
+    3414                 :            :     void *hash;
+    3415                 :            :     size_t hash_size;
+    3416                 :            : 
+    3417                 :          1 :     spdm_test_context = *state;
+    3418                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    3419                 :          1 :     spdm_test_context->case_id = 0x6;
+    3420                 :          1 :     spdm_context->retry_times = 3;
+    3421                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    3422                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3423                 :          1 :     spdm_context->connection_info.connection_state =
+    3424                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    3425                 :          1 :     spdm_context->connection_info.capability.flags &=
+    3426                 :            :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
+    3427                 :          1 :     spdm_context->connection_info.capability.flags |=
+    3428                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
+    3429                 :          1 :     spdm_context->local_context.capability.flags |=
+    3430                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
+    3431                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3432                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    3433                 :            :                                                     &data_size, &hash, &hash_size);
+    3434                 :          1 :     libspdm_reset_message_a(spdm_context);
+    3435                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    3436                 :            :         m_libspdm_use_hash_algo;
+    3437                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    3438                 :            :         m_libspdm_use_dhe_algo;
+    3439                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    3440                 :            :         m_libspdm_use_aead_algo;
+    3441                 :          1 :     spdm_context->connection_info.algorithm.key_schedule =
+    3442                 :            :         m_libspdm_use_key_schedule_algo;
+    3443                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    3444                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    3445                 :            :         data_size;
+    3446                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    3447                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    3448                 :            :                      data, data_size);
+    3449                 :            : #endif
+    3450                 :            : 
+    3451                 :          1 :     heartbeat_period = 0;
+    3452                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    3453                 :          1 :     status = libspdm_send_receive_psk_exchange(
+    3454                 :            :         spdm_context,
+    3455                 :            :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
+    3456                 :            :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
+    3457                 :            :         &heartbeat_period, measurement_hash);
+    3458                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    3459                 :          1 :     assert_int_equal(session_id, 0xFFFEFFFE);
+    3460                 :          1 :     assert_int_equal(
+    3461                 :            :         libspdm_secured_message_get_session_state(
+    3462                 :            :             spdm_context->session_info[0].secured_message_context),
+    3463                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    3464                 :          1 :     free(data);
+    3465                 :          1 : }
+    3466                 :            : 
+    3467                 :          1 : void libspdm_test_requester_psk_exchange_case7(void **state)
+    3468                 :            : {
+    3469                 :            :     libspdm_return_t status;
+    3470                 :            :     libspdm_test_context_t *spdm_test_context;
+    3471                 :            :     libspdm_context_t *spdm_context;
+    3472                 :            :     uint32_t session_id;
+    3473                 :            :     uint8_t heartbeat_period;
+    3474                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    3475                 :            :     void *data;
+    3476                 :            :     size_t data_size;
+    3477                 :            :     void *hash;
+    3478                 :            :     size_t hash_size;
+    3479                 :            : 
+    3480                 :          1 :     spdm_test_context = *state;
+    3481                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    3482                 :          1 :     spdm_test_context->case_id = 0x7;
+    3483                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    3484                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3485                 :          1 :     spdm_context->connection_info.connection_state =
+    3486                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    3487                 :          1 :     spdm_context->connection_info.capability.flags &=
+    3488                 :            :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
+    3489                 :          1 :     spdm_context->connection_info.capability.flags |=
+    3490                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
+    3491                 :          1 :     spdm_context->local_context.capability.flags |=
+    3492                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
+    3493                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3494                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    3495                 :            :                                                     &data_size, &hash, &hash_size);
+    3496                 :          1 :     libspdm_reset_message_a(spdm_context);
+    3497                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    3498                 :            :         m_libspdm_use_hash_algo;
+    3499                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    3500                 :            :         m_libspdm_use_dhe_algo;
+    3501                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    3502                 :            :         m_libspdm_use_aead_algo;
+    3503                 :          1 :     spdm_context->connection_info.algorithm.key_schedule =
+    3504                 :            :         m_libspdm_use_key_schedule_algo;
+    3505                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    3506                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    3507                 :            :         data_size;
+    3508                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    3509                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    3510                 :            :                      data, data_size);
+    3511                 :            : #endif
+    3512                 :            : 
+    3513                 :          1 :     heartbeat_period = 0;
+    3514                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    3515                 :          1 :     status = libspdm_send_receive_psk_exchange(
+    3516                 :            :         spdm_context,
+    3517                 :            :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
+    3518                 :            :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
+    3519                 :            :         &heartbeat_period, measurement_hash);
+    3520                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_RESYNCH_PEER);
+    3521                 :          1 :     assert_int_equal(spdm_context->connection_info.connection_state,
+    3522                 :            :                      LIBSPDM_CONNECTION_STATE_NOT_STARTED);
+    3523                 :          1 :     free(data);
+    3524                 :          1 : }
+    3525                 :            : 
+    3526                 :          1 : void libspdm_test_requester_psk_exchange_case8(void **state)
+    3527                 :            : {
+    3528                 :            :     libspdm_return_t status;
+    3529                 :            :     libspdm_test_context_t *spdm_test_context;
+    3530                 :            :     libspdm_context_t *spdm_context;
+    3531                 :            :     uint32_t session_id;
+    3532                 :            :     uint8_t heartbeat_period;
+    3533                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    3534                 :            :     void *data;
+    3535                 :            :     size_t data_size;
+    3536                 :            :     void *hash;
+    3537                 :            :     size_t hash_size;
+    3538                 :            : 
+    3539                 :          1 :     spdm_test_context = *state;
+    3540                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    3541                 :          1 :     spdm_test_context->case_id = 0x8;
+    3542                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    3543                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3544                 :          1 :     spdm_context->connection_info.connection_state =
+    3545                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    3546                 :          1 :     spdm_context->connection_info.capability.flags &=
+    3547                 :            :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
+    3548                 :          1 :     spdm_context->connection_info.capability.flags |=
+    3549                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
+    3550                 :          1 :     spdm_context->local_context.capability.flags |=
+    3551                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
+    3552                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3553                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    3554                 :            :                                                     &data_size, &hash, &hash_size);
+    3555                 :          1 :     libspdm_reset_message_a(spdm_context);
+    3556                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    3557                 :            :         m_libspdm_use_hash_algo;
+    3558                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    3559                 :            :         m_libspdm_use_dhe_algo;
+    3560                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    3561                 :            :         m_libspdm_use_aead_algo;
+    3562                 :          1 :     spdm_context->connection_info.algorithm.key_schedule =
+    3563                 :            :         m_libspdm_use_key_schedule_algo;
+    3564                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    3565                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    3566                 :            :         data_size;
+    3567                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    3568                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    3569                 :            :                      data, data_size);
+    3570                 :            : #endif
+    3571                 :            : 
+    3572                 :          1 :     heartbeat_period = 0;
+    3573                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    3574                 :          1 :     status = libspdm_send_receive_psk_exchange(
+    3575                 :            :         spdm_context,
+    3576                 :            :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
+    3577                 :            :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
+    3578                 :            :         &heartbeat_period, measurement_hash);
+    3579                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_NOT_READY_PEER);
+    3580                 :          1 :     free(data);
+    3581                 :          1 : }
+    3582                 :            : 
+    3583                 :          1 : void libspdm_test_requester_psk_exchange_case9(void **state)
+    3584                 :            : {
+    3585                 :            :     libspdm_return_t status;
+    3586                 :            :     libspdm_test_context_t *spdm_test_context;
+    3587                 :            :     libspdm_context_t *spdm_context;
+    3588                 :            :     uint32_t session_id;
+    3589                 :            :     uint8_t heartbeat_period;
+    3590                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    3591                 :            :     void *data;
+    3592                 :            :     size_t data_size;
+    3593                 :            :     void *hash;
+    3594                 :            :     size_t hash_size;
+    3595                 :            : 
+    3596                 :          1 :     spdm_test_context = *state;
+    3597                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    3598                 :          1 :     spdm_test_context->case_id = 0x9;
+    3599                 :          1 :     spdm_context->retry_times = 3;
+    3600                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    3601                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3602                 :          1 :     spdm_context->connection_info.connection_state =
+    3603                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    3604                 :          1 :     spdm_context->connection_info.capability.flags &=
+    3605                 :            :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
+    3606                 :          1 :     spdm_context->connection_info.capability.flags |=
+    3607                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
+    3608                 :          1 :     spdm_context->local_context.capability.flags |=
+    3609                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
+    3610                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3611                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    3612                 :            :                                                     &data_size, &hash, &hash_size);
+    3613                 :          1 :     libspdm_reset_message_a(spdm_context);
+    3614                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    3615                 :            :         m_libspdm_use_hash_algo;
+    3616                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    3617                 :            :         m_libspdm_use_dhe_algo;
+    3618                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    3619                 :            :         m_libspdm_use_aead_algo;
+    3620                 :          1 :     spdm_context->connection_info.algorithm.key_schedule =
+    3621                 :            :         m_libspdm_use_key_schedule_algo;
+    3622                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    3623                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    3624                 :            :         data_size;
+    3625                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    3626                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    3627                 :            :                      data, data_size);
+    3628                 :            : #endif
+    3629                 :            : 
+    3630                 :          1 :     heartbeat_period = 0;
+    3631                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    3632                 :          1 :     status = libspdm_send_receive_psk_exchange(
+    3633                 :            :         spdm_context,
+    3634                 :            :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
+    3635                 :            :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
+    3636                 :            :         &heartbeat_period, measurement_hash);
+    3637                 :            :     if (LIBSPDM_RESPOND_IF_READY_SUPPORT) {
+    3638                 :          1 :         assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    3639                 :          1 :         assert_int_equal(session_id, 0xFFFDFFFD);
+    3640                 :          1 :         assert_int_equal(
+    3641                 :            :             libspdm_secured_message_get_session_state(
+    3642                 :            :                 spdm_context->session_info[0].secured_message_context),
+    3643                 :            :             LIBSPDM_SESSION_STATE_HANDSHAKING);
+    3644                 :            :     } else {
+    3645                 :            :         assert_int_equal(status, LIBSPDM_STATUS_NOT_READY_PEER);
+    3646                 :            :     }
+    3647                 :            : 
+    3648                 :          1 :     free(data);
+    3649                 :          1 : }
+    3650                 :            : 
+    3651                 :          1 : void libspdm_test_requester_psk_exchange_case10(void **state) {
+    3652                 :            :     libspdm_return_t status;
+    3653                 :            :     libspdm_test_context_t    *spdm_test_context;
+    3654                 :            :     libspdm_context_t  *spdm_context;
+    3655                 :            :     uint32_t session_id;
+    3656                 :            :     uint8_t heartbeat_period;
+    3657                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    3658                 :            :     void                 *data;
+    3659                 :            :     size_t data_size;
+    3660                 :            :     void                 *hash;
+    3661                 :            :     size_t hash_size;
+    3662                 :            :     uint16_t error_code;
+    3663                 :            : 
+    3664                 :          1 :     spdm_test_context = *state;
+    3665                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    3666                 :          1 :     spdm_test_context->case_id = 0xA;
+    3667                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    3668                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3669                 :          1 :     spdm_context->connection_info.capability.flags |=
+    3670                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
+    3671                 :          1 :     spdm_context->local_context.capability.flags |=
+    3672                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
+    3673                 :          1 :     libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
+    3674                 :            :                                                      m_libspdm_use_asym_algo,
+    3675                 :            :                                                      &data, &data_size,
+    3676                 :            :                                                      &hash, &hash_size);
+    3677                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    3678                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    3679                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    3680                 :          1 :     spdm_context->connection_info.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    3681                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    3682                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    3683                 :            :         data_size;
+    3684                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    3685                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    3686                 :            :                      data, data_size);
+    3687                 :            : #endif
+    3688                 :            : 
+    3689                 :          1 :     error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
+    3690         [ +  + ]:         19 :     while(error_code <= 0xff) {
+    3691                 :         18 :         spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    3692                 :         18 :         libspdm_reset_message_a(spdm_context);
+    3693                 :            : 
+    3694                 :         18 :         heartbeat_period = 0;
+    3695                 :         18 :         libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    3696                 :         18 :         status = libspdm_send_receive_psk_exchange (spdm_context,
+    3697                 :            :                                                     LIBSPDM_TEST_PSK_HINT_STRING,
+    3698                 :            :                                                     sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
+    3699                 :            :                                                     SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
+    3700                 :            :                                                     0,
+    3701                 :            :                                                     &session_id, &heartbeat_period,
+    3702                 :            :                                                     measurement_hash);
+    3703         [ -  + ]:         18 :         LIBSPDM_ASSERT_INT_EQUAL_CASE (status, LIBSPDM_STATUS_ERROR_PEER, error_code);
+    3704                 :            : 
+    3705                 :         18 :         error_code++;
+    3706         [ +  + ]:         18 :         if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
+    3707                 :          1 :             error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
+    3708                 :            :         }
+    3709         [ +  + ]:         18 :         if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) { /*skip some reserved error codes (0d to 3e)*/
+    3710                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
+    3711                 :            :         }
+    3712         [ +  + ]:         18 :         if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) { /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
+    3713                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
+    3714                 :            :         }
+    3715                 :            :     }
+    3716                 :            : 
+    3717                 :          1 :     free(data);
+    3718                 :          1 : }
+    3719                 :            : 
+    3720                 :          0 : void libspdm_test_requester_psk_exchange_case11(void **state)
+    3721                 :            : {
+    3722                 :            :     libspdm_return_t status;
+    3723                 :            :     libspdm_test_context_t *spdm_test_context;
+    3724                 :            :     libspdm_context_t *spdm_context;
+    3725                 :            :     uint32_t session_id;
+    3726                 :            :     uint8_t heartbeat_period;
+    3727                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    3728                 :            :     void *data;
+    3729                 :            :     size_t data_size;
+    3730                 :            :     void *hash;
+    3731                 :            :     size_t hash_size;
+    3732                 :            : 
+    3733                 :          0 :     spdm_test_context = *state;
+    3734                 :          0 :     spdm_context = spdm_test_context->spdm_context;
+    3735                 :          0 :     spdm_test_context->case_id = 0xB;
+    3736                 :          0 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    3737                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3738                 :          0 :     spdm_context->connection_info.connection_state =
+    3739                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    3740                 :          0 :     spdm_context->connection_info.capability.flags &=
+    3741                 :            :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
+    3742                 :          0 :     spdm_context->connection_info.capability.flags |=
+    3743                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
+    3744                 :          0 :     spdm_context->local_context.capability.flags |=
+    3745                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
+    3746                 :          0 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3747                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    3748                 :            :                                                     &data_size, &hash, &hash_size);
+    3749                 :          0 :     libspdm_reset_message_a(spdm_context);
+    3750                 :          0 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    3751                 :            :         m_libspdm_use_hash_algo;
+    3752                 :          0 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    3753                 :            :         m_libspdm_use_dhe_algo;
+    3754                 :          0 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    3755                 :            :         m_libspdm_use_aead_algo;
+    3756                 :          0 :     spdm_context->connection_info.algorithm.key_schedule =
+    3757                 :            :         m_libspdm_use_key_schedule_algo;
+    3758                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    3759                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    3760                 :            :         data_size;
+    3761                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    3762                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    3763                 :            :                      data, data_size);
+    3764                 :            : #endif
+    3765                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    3766                 :            :     spdm_context->transcript.message_m.buffer_size =
+    3767                 :            :         spdm_context->transcript.message_m.max_buffer_size;
+    3768                 :            :     spdm_context->transcript.message_b.buffer_size =
+    3769                 :            :         spdm_context->transcript.message_b.max_buffer_size;
+    3770                 :            :     spdm_context->transcript.message_c.buffer_size =
+    3771                 :            :         spdm_context->transcript.message_c.max_buffer_size;
+    3772                 :            :     spdm_context->transcript.message_mut_b.buffer_size =
+    3773                 :            :         spdm_context->transcript.message_mut_b.max_buffer_size;
+    3774                 :            :     spdm_context->transcript.message_mut_c.buffer_size =
+    3775                 :            :         spdm_context->transcript.message_mut_c.max_buffer_size;
+    3776                 :            : #endif
+    3777                 :            : 
+    3778                 :          0 :     heartbeat_period = 0;
+    3779                 :          0 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    3780                 :          0 :     status = libspdm_send_receive_psk_exchange(
+    3781                 :            :         spdm_context,
+    3782                 :            :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
+    3783                 :            :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
+    3784                 :            :         &heartbeat_period, measurement_hash);
+    3785                 :          0 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    3786                 :          0 :     assert_int_equal(session_id, 0xFFFFFFFF);
+    3787                 :          0 :     assert_int_equal(
+    3788                 :            :         libspdm_secured_message_get_session_state(
+    3789                 :            :             spdm_context->session_info[0].secured_message_context),
+    3790                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    3791                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    3792                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+    3793                 :            :     assert_int_equal(spdm_context->transcript.message_b.buffer_size, 0);
+    3794                 :            :     assert_int_equal(spdm_context->transcript.message_c.buffer_size, 0);
+    3795                 :            :     assert_int_equal(spdm_context->transcript.message_mut_b.buffer_size, 0);
+    3796                 :            :     assert_int_equal(spdm_context->transcript.message_mut_c.buffer_size, 0);
+    3797                 :            : #endif
+    3798                 :            : 
+    3799                 :          0 :     free(data);
+    3800                 :          0 : }
+    3801                 :            : 
+    3802                 :          1 : void libspdm_test_requester_psk_exchange_case12(void **state)
+    3803                 :            : {
+    3804                 :            :     libspdm_return_t status;
+    3805                 :            :     libspdm_test_context_t *spdm_test_context;
+    3806                 :            :     libspdm_context_t *spdm_context;
+    3807                 :            :     uint32_t session_id;
+    3808                 :            :     uint8_t heartbeat_period;
+    3809                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    3810                 :            :     void *data;
+    3811                 :            :     size_t data_size;
+    3812                 :            :     void *hash;
+    3813                 :            :     size_t hash_size;
+    3814                 :            : 
+    3815                 :          1 :     spdm_test_context = *state;
+    3816                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    3817                 :            : 
+    3818         [ +  - ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    3819                 :          1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    3820                 :            :     }
+    3821                 :            : 
+    3822                 :          1 :     spdm_test_context->case_id = 0xC;
+    3823                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    3824                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3825                 :          1 :     spdm_context->connection_info.connection_state =
+    3826                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    3827                 :          1 :     spdm_context->connection_info.capability.flags &=
+    3828                 :            :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
+    3829                 :          1 :     spdm_context->connection_info.capability.flags |=
+    3830                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
+    3831                 :          1 :     spdm_context->local_context.capability.flags |=
+    3832                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
+    3833                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3834                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    3835                 :            :                                                     &data_size, &hash, &hash_size);
+    3836                 :          1 :     libspdm_reset_message_a(spdm_context);
+    3837                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    3838                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    3839                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    3840                 :          1 :     spdm_context->connection_info.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    3841                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    3842                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    3843                 :            :         data_size;
+    3844                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    3845                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    3846                 :            :                      data, data_size);
+    3847                 :            : #endif
+    3848                 :            : 
+    3849                 :          1 :     heartbeat_period = 0;
+    3850                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    3851                 :          1 :     status = libspdm_send_receive_psk_exchange(
+    3852                 :            :         spdm_context,
+    3853                 :            :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
+    3854                 :            :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
+    3855                 :            :         &heartbeat_period, measurement_hash);
+    3856                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    3857                 :          1 :     assert_int_equal(session_id, 0xFFFFFFFF);
+    3858                 :          1 :     assert_int_equal(
+    3859                 :            :         libspdm_secured_message_get_session_state(
+    3860                 :            :             spdm_context->session_info[0].secured_message_context),
+    3861                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    3862                 :            : 
+    3863                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    3864                 :            :     assert_int_equal(spdm_context->session_info[0].session_transcript.message_k.buffer_size,
+    3865                 :            :                      m_libspdm_local_buffer_size);
+    3866                 :            :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer (0x%x):\n",
+    3867                 :            :                    m_libspdm_local_buffer_size));
+    3868                 :            :     libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    3869                 :            :     assert_memory_equal(spdm_context->session_info[0].session_transcript.message_k.buffer,
+    3870                 :            :                         m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    3871                 :            : #endif
+    3872                 :          1 :     free(data);
+    3873                 :          1 : }
+    3874                 :            : 
+    3875                 :          1 : void libspdm_test_requester_psk_exchange_case13(void **state)
+    3876                 :            : {
+    3877                 :            :     libspdm_return_t status;
+    3878                 :            :     libspdm_test_context_t *spdm_test_context;
+    3879                 :            :     libspdm_context_t *spdm_context;
+    3880                 :            :     uint32_t session_id;
+    3881                 :            :     uint8_t heartbeat_period;
+    3882                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    3883                 :            :     void *data;
+    3884                 :            :     size_t data_size;
+    3885                 :            :     void *hash;
+    3886                 :            :     size_t hash_size;
+    3887                 :            : 
+    3888                 :          1 :     spdm_test_context = *state;
+    3889                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    3890                 :          1 :     spdm_test_context->case_id = 0xD;
+    3891                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    3892                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3893                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    3894                 :          1 :     spdm_context->connection_info.capability.flags &=
+    3895                 :            :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
+    3896                 :          1 :     spdm_context->connection_info.capability.flags |=
+    3897                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
+    3898                 :          1 :     spdm_context->local_context.capability.flags |=
+    3899                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
+    3900                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
+    3901                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
+    3902                 :            :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3903                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3904                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    3905                 :            :                                                     &data_size, &hash, &hash_size);
+    3906                 :          1 :     libspdm_reset_message_a(spdm_context);
+    3907                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    3908                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    3909                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    3910                 :          1 :     spdm_context->connection_info.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    3911                 :          1 :     spdm_context->connection_info.algorithm.other_params_support =
+    3912                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
+    3913                 :          1 :     libspdm_session_info_init(spdm_context,
+    3914                 :          1 :                               spdm_context->session_info,
+    3915                 :            :                               INVALID_SESSION_ID, false);
+    3916                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    3917                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    3918                 :            :         data_size;
+    3919                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    3920                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    3921                 :            :                      data, data_size);
+    3922                 :            : #endif
+    3923                 :            : 
+    3924                 :          1 :     heartbeat_period = 0;
+    3925                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    3926                 :          1 :     status = libspdm_send_receive_psk_exchange(
+    3927                 :            :         spdm_context,
+    3928                 :            :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
+    3929                 :            :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
+    3930                 :            :         SPDM_PSK_EXCHANGE_REQUEST_ALL_MEASUREMENTS_HASH, &session_id,
+    3931                 :            :         &heartbeat_period, measurement_hash);
+    3932                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    3933                 :          1 :     assert_int_equal(session_id, 0xFFFFFFFF);
+    3934                 :          1 :     assert_int_equal(
+    3935                 :            :         libspdm_secured_message_get_session_state(
+    3936                 :            :             spdm_context->session_info[0].secured_message_context),
+    3937                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    3938                 :          1 :     assert_int_equal(
+    3939                 :            :         spdm_context->session_info[0].session_policy,
+    3940                 :            :         SPDM_PSK_EXCHANGE_REQUEST_ALL_MEASUREMENTS_HASH);
+    3941                 :          1 :     free(data);
+    3942                 :          1 : }
+    3943                 :            : 
+    3944                 :          1 : void libspdm_test_requester_psk_exchange_case14(void **state)
+    3945                 :            : {
+    3946                 :            :     libspdm_return_t status;
+    3947                 :            :     libspdm_test_context_t *spdm_test_context;
+    3948                 :            :     libspdm_context_t *spdm_context;
+    3949                 :            :     uint32_t session_id;
+    3950                 :            :     uint8_t heartbeat_period;
+    3951                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    3952                 :            :     void *data;
+    3953                 :            :     size_t data_size;
+    3954                 :            :     void *hash;
+    3955                 :            :     size_t hash_size;
+    3956                 :            : 
+    3957                 :          1 :     spdm_test_context = *state;
+    3958                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    3959                 :            : 
+    3960         [ +  - ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    3961                 :          1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    3962                 :            :     }
+    3963                 :            : 
+    3964                 :          1 :     spdm_test_context->case_id = 0xE;
+    3965                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    3966                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3967                 :          1 :     spdm_context->connection_info.connection_state =
+    3968                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    3969                 :          1 :     spdm_context->connection_info.capability.flags &=
+    3970                 :            :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
+    3971                 :          1 :     spdm_context->connection_info.capability.flags |=
+    3972                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
+    3973                 :          1 :     spdm_context->local_context.capability.flags |=
+    3974                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
+    3975                 :          1 :     spdm_context->connection_info.capability.flags |=
+    3976                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG;
+    3977                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    3978                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    3979                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
+    3980                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
+    3981                 :            :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3982                 :            : 
+    3983                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3984                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    3985                 :            :                                                     &data_size, &hash, &hash_size);
+    3986                 :          1 :     libspdm_reset_message_a(spdm_context);
+    3987                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    3988                 :            :         m_libspdm_use_hash_algo;
+    3989                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    3990                 :            :         m_libspdm_use_dhe_algo;
+    3991                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    3992                 :            :         m_libspdm_use_aead_algo;
+    3993                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    3994                 :            :         m_libspdm_use_measurement_hash_algo;
+    3995                 :          1 :     spdm_context->connection_info.algorithm.key_schedule =
+    3996                 :            :         m_libspdm_use_key_schedule_algo;
+    3997                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    3998                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    3999                 :            :         data_size;
+    4000                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    4001                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    4002                 :            :                      data, data_size);
+    4003                 :            : 
+    4004                 :            : #endif
+    4005                 :            : 
+    4006                 :          1 :     heartbeat_period = 0;
+    4007                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    4008                 :          1 :     status = libspdm_send_receive_psk_exchange(
+    4009                 :            :         spdm_context,
+    4010                 :            :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
+    4011                 :            :         SPDM_PSK_EXCHANGE_REQUEST_TCB_COMPONENT_MEASUREMENT_HASH, 0, &session_id,
+    4012                 :            :         &heartbeat_period, measurement_hash);
+    4013                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    4014                 :          1 :     assert_int_equal(session_id, 0xFFFFFFFF);
+    4015                 :          1 :     assert_memory_equal(
+    4016                 :            :         measurement_hash,
+    4017                 :            :         m_libspdm_use_tcb_hash_value,
+    4018                 :            :         libspdm_get_hash_size(m_libspdm_use_hash_algo));
+    4019                 :          1 :     assert_int_equal(
+    4020                 :            :         libspdm_secured_message_get_session_state(
+    4021                 :            :             spdm_context->session_info[0].secured_message_context),
+    4022                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    4023                 :          1 :     free(data);
+    4024                 :          1 : }
+    4025                 :            : 
+    4026                 :          1 : void libspdm_test_requester_psk_exchange_case15(void **state)
+    4027                 :            : {
+    4028                 :            :     libspdm_return_t status;
+    4029                 :            :     libspdm_test_context_t *spdm_test_context;
+    4030                 :            :     libspdm_context_t *spdm_context;
+    4031                 :            :     uint32_t session_id;
+    4032                 :            :     uint8_t heartbeat_period;
+    4033                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    4034                 :            :     void *data;
+    4035                 :            :     size_t data_size;
+    4036                 :            :     void *hash;
+    4037                 :            :     size_t hash_size;
+    4038                 :            : 
+    4039                 :          1 :     spdm_test_context = *state;
+    4040                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4041                 :            : 
+    4042         [ +  - ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    4043                 :          1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    4044                 :            :     }
+    4045                 :            : 
+    4046                 :          1 :     spdm_test_context->case_id = 0xF;
+    4047                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4048                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4049                 :          1 :     spdm_context->connection_info.connection_state =
+    4050                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    4051                 :          1 :     spdm_context->connection_info.capability.flags &=
+    4052                 :            :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
+    4053                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4054                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
+    4055                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4056                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG;
+    4057                 :          1 :     spdm_context->local_context.capability.flags |=
+    4058                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
+    4059                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    4060                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    4061                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
+    4062                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
+    4063                 :            :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4064                 :            : 
+    4065                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    4066                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    4067                 :            :                                                     &data_size, &hash, &hash_size);
+    4068                 :          1 :     libspdm_reset_message_a(spdm_context);
+    4069                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    4070                 :            :         m_libspdm_use_hash_algo;
+    4071                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    4072                 :            :         m_libspdm_use_dhe_algo;
+    4073                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    4074                 :            :         m_libspdm_use_aead_algo;
+    4075                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    4076                 :            :         m_libspdm_use_measurement_hash_algo;
+    4077                 :          1 :     spdm_context->connection_info.algorithm.key_schedule =
+    4078                 :            :         m_libspdm_use_key_schedule_algo;
+    4079                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4080                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    4081                 :            :         data_size;
+    4082                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    4083                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    4084                 :            :                      data, data_size);
+    4085                 :            : 
+    4086                 :            : #endif
+    4087                 :            : 
+    4088                 :          1 :     heartbeat_period = 0;
+    4089                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    4090                 :          1 :     status = libspdm_send_receive_psk_exchange(
+    4091                 :            :         spdm_context,
+    4092                 :            :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
+    4093                 :            :         SPDM_PSK_EXCHANGE_REQUEST_TCB_COMPONENT_MEASUREMENT_HASH, 0, &session_id,
+    4094                 :            :         &heartbeat_period, measurement_hash);
+    4095                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    4096                 :          1 :     assert_int_equal(session_id, 0xFFFFFFFF);
+    4097                 :          1 :     assert_memory_equal(
+    4098                 :            :         measurement_hash,
+    4099                 :            :         m_libspdm_zero_filled_buffer,
+    4100                 :            :         libspdm_get_hash_size(m_libspdm_use_hash_algo));
+    4101                 :          1 :     assert_int_equal(
+    4102                 :            :         libspdm_secured_message_get_session_state(
+    4103                 :            :             spdm_context->session_info[0].secured_message_context),
+    4104                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    4105                 :          1 :     free(data);
+    4106                 :          1 : }
+    4107                 :            : 
+    4108                 :          1 : void libspdm_test_requester_psk_exchange_case16(void **state)
+    4109                 :            : {
+    4110                 :            :     libspdm_return_t status;
+    4111                 :            :     libspdm_test_context_t *spdm_test_context;
+    4112                 :            :     libspdm_context_t *spdm_context;
+    4113                 :            :     uint32_t session_id;
+    4114                 :            :     uint8_t heartbeat_period;
+    4115                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    4116                 :            :     void *data;
+    4117                 :            :     size_t data_size;
+    4118                 :            :     void *hash;
+    4119                 :            :     size_t hash_size;
+    4120                 :            : 
+    4121                 :          1 :     spdm_test_context = *state;
+    4122                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4123                 :            : 
+    4124         [ +  - ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    4125                 :          1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    4126                 :            :     }
+    4127                 :            : 
+    4128                 :          1 :     spdm_test_context->case_id = 0x10;
+    4129                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4130                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4131                 :          1 :     spdm_context->connection_info.connection_state =
+    4132                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    4133                 :          1 :     spdm_context->connection_info.capability.flags &=
+    4134                 :            :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
+    4135                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4136                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
+    4137                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4138                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG;
+    4139                 :          1 :     spdm_context->local_context.capability.flags |=
+    4140                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
+    4141                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    4142                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    4143                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
+    4144                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
+    4145                 :            :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4146                 :            : 
+    4147                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    4148                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    4149                 :            :                                                     &data_size, &hash, &hash_size);
+    4150                 :          1 :     libspdm_reset_message_a(spdm_context);
+    4151                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    4152                 :            :         m_libspdm_use_hash_algo;
+    4153                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    4154                 :            :         m_libspdm_use_dhe_algo;
+    4155                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    4156                 :            :         m_libspdm_use_aead_algo;
+    4157                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    4158                 :            :         m_libspdm_use_measurement_hash_algo;
+    4159                 :          1 :     spdm_context->connection_info.algorithm.key_schedule =
+    4160                 :            :         m_libspdm_use_key_schedule_algo;
+    4161                 :            : 
+    4162                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4163                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    4164                 :            :         data_size;
+    4165                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    4166                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    4167                 :            :                      data, data_size);
+    4168                 :            : 
+    4169                 :            : #endif
+    4170                 :            : 
+    4171                 :          1 :     heartbeat_period = 0;
+    4172                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    4173                 :          1 :     status = libspdm_send_receive_psk_exchange(
+    4174                 :            :         spdm_context,
+    4175                 :            :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
+    4176                 :            :         SPDM_PSK_EXCHANGE_REQUEST_ALL_MEASUREMENTS_HASH, 0, &session_id,
+    4177                 :            :         &heartbeat_period, measurement_hash);
+    4178                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    4179                 :          1 :     assert_int_equal(session_id, 0xFFFFFFFF);
+    4180                 :          1 :     assert_memory_equal(
+    4181                 :            :         measurement_hash,
+    4182                 :            :         m_libspdm_use_tcb_hash_value,
+    4183                 :            :         libspdm_get_hash_size(m_libspdm_use_hash_algo));
+    4184                 :          1 :     assert_int_equal(
+    4185                 :            :         libspdm_secured_message_get_session_state(
+    4186                 :            :             spdm_context->session_info[0].secured_message_context),
+    4187                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    4188                 :          1 :     free(data);
+    4189                 :          1 : }
+    4190                 :            : 
+    4191                 :          1 : void libspdm_test_requester_psk_exchange_case17(void **state)
+    4192                 :            : {
+    4193                 :            :     libspdm_return_t status;
+    4194                 :            :     libspdm_test_context_t *spdm_test_context;
+    4195                 :            :     libspdm_context_t *spdm_context;
+    4196                 :            :     uint32_t session_id;
+    4197                 :            :     uint8_t heartbeat_period;
+    4198                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    4199                 :            :     void *data;
+    4200                 :            :     size_t data_size;
+    4201                 :            :     void *hash;
+    4202                 :            :     size_t hash_size;
+    4203                 :            : 
+    4204                 :          1 :     spdm_test_context = *state;
+    4205                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4206                 :            : 
+    4207         [ +  - ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    4208                 :          1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    4209                 :            :     }
+    4210                 :            : 
+    4211                 :          1 :     spdm_test_context->case_id = 0x11;
+    4212                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4213                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4214                 :          1 :     spdm_context->connection_info.connection_state =
+    4215                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    4216                 :          1 :     spdm_context->connection_info.capability.flags &=
+    4217                 :            :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
+    4218                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4219                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
+    4220                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4221                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG;
+    4222                 :          1 :     spdm_context->local_context.capability.flags |=
+    4223                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
+    4224                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    4225                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    4226                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
+    4227                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
+    4228                 :            :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4229                 :            : 
+    4230                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    4231                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    4232                 :            :                                                     &data_size, &hash, &hash_size);
+    4233                 :          1 :     libspdm_reset_message_a(spdm_context);
+    4234                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    4235                 :            :         m_libspdm_use_hash_algo;
+    4236                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    4237                 :            :         m_libspdm_use_dhe_algo;
+    4238                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    4239                 :            :         m_libspdm_use_aead_algo;
+    4240                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    4241                 :            :         m_libspdm_use_measurement_hash_algo;
+    4242                 :          1 :     spdm_context->connection_info.algorithm.key_schedule =
+    4243                 :            :         m_libspdm_use_key_schedule_algo;
+    4244                 :            : 
+    4245                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4246                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    4247                 :            :         data_size;
+    4248                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    4249                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    4250                 :            :                      data, data_size);
+    4251                 :            : 
+    4252                 :            : #endif
+    4253                 :            : 
+    4254                 :          1 :     heartbeat_period = 0;
+    4255                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    4256                 :          1 :     status = libspdm_send_receive_psk_exchange(
+    4257                 :            :         spdm_context,
+    4258                 :            :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
+    4259                 :            :         SPDM_PSK_EXCHANGE_REQUEST_TCB_COMPONENT_MEASUREMENT_HASH, 0, &session_id,
+    4260                 :            :         &heartbeat_period, measurement_hash);
+    4261                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
+    4262                 :          1 :     free(data);
+    4263                 :          1 : }
+    4264                 :            : 
+    4265                 :          1 : void libspdm_test_requester_psk_exchange_case18(void **state)
+    4266                 :            : {
+    4267                 :            :     libspdm_return_t status;
+    4268                 :            :     libspdm_test_context_t *spdm_test_context;
+    4269                 :            :     libspdm_context_t *spdm_context;
+    4270                 :            :     uint32_t session_id;
+    4271                 :            :     uint8_t heartbeat_period;
+    4272                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    4273                 :            :     void *data;
+    4274                 :            :     size_t data_size;
+    4275                 :            :     void *hash;
+    4276                 :            :     size_t hash_size;
+    4277                 :            : 
+    4278                 :          1 :     spdm_test_context = *state;
+    4279                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4280                 :            : 
+    4281         [ -  + ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    4282                 :          0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    4283                 :            :     }
+    4284                 :            : 
+    4285                 :          1 :     spdm_test_context->case_id = 0x12;
+    4286                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4287                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4288                 :          1 :     spdm_context->connection_info.connection_state =
+    4289                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    4290                 :          1 :     spdm_context->connection_info.capability.flags &=
+    4291                 :            :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
+    4292                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4293                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
+    4294                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4295                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG;
+    4296                 :          1 :     spdm_context->local_context.capability.flags |=
+    4297                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
+    4298                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    4299                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    4300                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
+    4301                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
+    4302                 :            :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4303                 :            : 
+    4304                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    4305                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    4306                 :            :                                                     &data_size, &hash, &hash_size);
+    4307                 :          1 :     libspdm_reset_message_a(spdm_context);
+    4308                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    4309                 :            :         m_libspdm_use_hash_algo;
+    4310                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    4311                 :            :         m_libspdm_use_dhe_algo;
+    4312                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    4313                 :            :         m_libspdm_use_aead_algo;
+    4314                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    4315                 :            :         m_libspdm_use_measurement_hash_algo;
+    4316                 :          1 :     spdm_context->connection_info.algorithm.key_schedule =
+    4317                 :            :         m_libspdm_use_key_schedule_algo;
+    4318                 :            : 
+    4319                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4320                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    4321                 :            :         data_size;
+    4322                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    4323                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    4324                 :            :                      data, data_size);
+    4325                 :            : 
+    4326                 :            : #endif
+    4327                 :            : 
+    4328                 :          1 :     heartbeat_period = 0;
+    4329                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    4330                 :          1 :     status = libspdm_send_receive_psk_exchange(
+    4331                 :            :         spdm_context,
+    4332                 :            :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
+    4333                 :            :         SPDM_PSK_EXCHANGE_REQUEST_ALL_MEASUREMENTS_HASH, 0, &session_id,
+    4334                 :            :         &heartbeat_period, measurement_hash);
+    4335                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
+    4336                 :          1 :     free(data);
+    4337                 :          1 : }
+    4338                 :            : 
+    4339                 :          1 : void libspdm_test_requester_psk_exchange_case19(void **state)
+    4340                 :            : {
+    4341                 :            :     libspdm_return_t status;
+    4342                 :            :     libspdm_test_context_t *spdm_test_context;
+    4343                 :            :     libspdm_context_t *spdm_context;
+    4344                 :            :     uint32_t session_id;
+    4345                 :            :     uint8_t heartbeat_period;
+    4346                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    4347                 :            :     void *data;
+    4348                 :            :     size_t data_size;
+    4349                 :            :     void *hash;
+    4350                 :            :     size_t hash_size;
+    4351                 :            : 
+    4352                 :          1 :     spdm_test_context = *state;
+    4353                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4354                 :            : 
+    4355         [ -  + ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    4356                 :          0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    4357                 :            :     }
+    4358                 :            : 
+    4359                 :          1 :     spdm_test_context->case_id = 0x13;
+    4360                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4361                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4362                 :          1 :     spdm_context->connection_info.connection_state =
+    4363                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    4364                 :          1 :     spdm_context->connection_info.capability.flags &=
+    4365                 :            :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
+    4366                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4367                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
+    4368                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4369                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG;
+    4370                 :          1 :     spdm_context->local_context.capability.flags |=
+    4371                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
+    4372                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    4373                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    4374                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
+    4375                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
+    4376                 :            :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4377                 :            : 
+    4378                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    4379                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    4380                 :            :                                                     &data_size, &hash, &hash_size);
+    4381                 :          1 :     libspdm_reset_message_a(spdm_context);
+    4382                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    4383                 :            :         m_libspdm_use_hash_algo;
+    4384                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    4385                 :            :         m_libspdm_use_dhe_algo;
+    4386                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    4387                 :            :         m_libspdm_use_aead_algo;
+    4388                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    4389                 :            :         m_libspdm_use_measurement_hash_algo;
+    4390                 :          1 :     spdm_context->connection_info.algorithm.key_schedule =
+    4391                 :            :         m_libspdm_use_key_schedule_algo;
+    4392                 :            : 
+    4393                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4394                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    4395                 :            :         data_size;
+    4396                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    4397                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    4398                 :            :                      data, data_size);
+    4399                 :            : 
+    4400                 :            : #endif
+    4401                 :            : 
+    4402                 :          1 :     heartbeat_period = 0;
+    4403                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    4404                 :          1 :     status = libspdm_send_receive_psk_exchange(
+    4405                 :            :         spdm_context,
+    4406                 :            :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
+    4407                 :            :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
+    4408                 :            :         &heartbeat_period, measurement_hash);
+    4409                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    4410                 :          1 :     free(data);
+    4411                 :          1 : }
+    4412                 :            : 
+    4413                 :          1 : void libspdm_test_requester_psk_exchange_case20(void **state)
+    4414                 :            : {
+    4415                 :            :     libspdm_return_t status;
+    4416                 :            :     libspdm_test_context_t *spdm_test_context;
+    4417                 :            :     libspdm_context_t *spdm_context;
+    4418                 :            :     uint32_t session_id;
+    4419                 :            :     uint8_t heartbeat_period;
+    4420                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    4421                 :            :     void *data;
+    4422                 :            :     size_t data_size;
+    4423                 :            :     void *hash;
+    4424                 :            :     size_t hash_size;
+    4425                 :            : 
+    4426                 :          1 :     spdm_test_context = *state;
+    4427                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4428                 :            : 
+    4429         [ -  + ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    4430                 :          0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    4431                 :            :     }
+    4432                 :            : 
+    4433                 :          1 :     spdm_test_context->case_id = 0x14;
+    4434                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4435                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4436                 :          1 :     spdm_context->connection_info.connection_state =
+    4437                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    4438                 :          1 :     spdm_context->connection_info.capability.flags &=
+    4439                 :            :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
+    4440                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4441                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
+    4442                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4443                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG;
+    4444                 :          1 :     spdm_context->local_context.capability.flags |=
+    4445                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
+    4446                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    4447                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    4448                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
+    4449                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
+    4450                 :            :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4451                 :            : 
+    4452                 :            : 
+    4453                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    4454                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    4455                 :            :                                                     &data_size, &hash, &hash_size);
+    4456                 :          1 :     libspdm_reset_message_a(spdm_context);
+    4457                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    4458                 :            :         m_libspdm_use_hash_algo;
+    4459                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    4460                 :            :         m_libspdm_use_dhe_algo;
+    4461                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    4462                 :            :         m_libspdm_use_aead_algo;
+    4463                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    4464                 :            :         m_libspdm_use_measurement_hash_algo;
+    4465                 :          1 :     spdm_context->connection_info.algorithm.key_schedule =
+    4466                 :            :         m_libspdm_use_key_schedule_algo;
+    4467                 :            : 
+    4468                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4469                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    4470                 :            :         data_size;
+    4471                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    4472                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    4473                 :            :                      data, data_size);
+    4474                 :            : 
+    4475                 :            : #endif
+    4476                 :            : 
+    4477                 :          1 :     heartbeat_period = 0;
+    4478                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    4479                 :          1 :     status = libspdm_send_receive_psk_exchange(
+    4480                 :            :         spdm_context,
+    4481                 :            :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
+    4482                 :            :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
+    4483                 :            :         &heartbeat_period, measurement_hash);
+    4484                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    4485                 :          1 :     free(data);
+    4486                 :          1 : }
+    4487                 :            : 
+    4488                 :          1 : void libspdm_test_requester_psk_exchange_case21(void **state)
+    4489                 :            : {
+    4490                 :            :     libspdm_return_t status;
+    4491                 :            :     libspdm_test_context_t *spdm_test_context;
+    4492                 :            :     libspdm_context_t *spdm_context;
+    4493                 :            :     uint32_t session_id;
+    4494                 :            :     uint8_t heartbeat_period;
+    4495                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    4496                 :            :     void *data;
+    4497                 :            :     size_t data_size;
+    4498                 :            :     void *hash;
+    4499                 :            :     size_t hash_size;
+    4500                 :            : 
+    4501                 :          1 :     spdm_test_context = *state;
+    4502                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4503                 :            : 
+    4504         [ -  + ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    4505                 :          0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    4506                 :            :     }
+    4507                 :            : 
+    4508                 :          1 :     spdm_test_context->case_id = 0x15;
+    4509                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4510                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4511                 :          1 :     spdm_context->connection_info.connection_state =
+    4512                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    4513                 :          1 :     spdm_context->connection_info.capability.flags &=
+    4514                 :            :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
+    4515                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4516                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
+    4517                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4518                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG;
+    4519                 :          1 :     spdm_context->local_context.capability.flags |=
+    4520                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
+    4521                 :            : 
+    4522                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4523                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP;
+    4524                 :          1 :     spdm_context->local_context.capability.flags |=
+    4525                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP;
+    4526                 :            : 
+    4527                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    4528                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    4529                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
+    4530                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
+    4531                 :            :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4532                 :            : 
+    4533                 :            : 
+    4534                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    4535                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    4536                 :            :                                                     &data_size, &hash, &hash_size);
+    4537                 :          1 :     libspdm_reset_message_a(spdm_context);
+    4538                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    4539                 :            :         m_libspdm_use_hash_algo;
+    4540                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    4541                 :            :         m_libspdm_use_dhe_algo;
+    4542                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    4543                 :            :         m_libspdm_use_aead_algo;
+    4544                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    4545                 :            :         m_libspdm_use_measurement_hash_algo;
+    4546                 :          1 :     spdm_context->connection_info.algorithm.key_schedule =
+    4547                 :            :         m_libspdm_use_key_schedule_algo;
+    4548                 :            : 
+    4549                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4550                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    4551                 :            :         data_size;
+    4552                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    4553                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    4554                 :            :                      data, data_size);
+    4555                 :            : 
+    4556                 :            : #endif
+    4557                 :            : 
+    4558                 :          1 :     heartbeat_period = 0;
+    4559                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    4560                 :          1 :     status = libspdm_send_receive_psk_exchange(
+    4561                 :            :         spdm_context,
+    4562                 :            :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
+    4563                 :            :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
+    4564                 :            :         &heartbeat_period, measurement_hash);
+    4565                 :            :     /* clear Heartbeat flags */
+    4566                 :          1 :     spdm_context->connection_info.capability.flags &=
+    4567                 :            :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP;
+    4568                 :          1 :     spdm_context->local_context.capability.flags &=
+    4569                 :            :         ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP;
+    4570                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    4571                 :          1 :     assert_int_equal(session_id, 0xFFFFFFFF);
+    4572                 :          1 :     assert_int_equal(
+    4573                 :            :         libspdm_secured_message_get_session_state(
+    4574                 :            :             spdm_context->session_info[0].secured_message_context),
+    4575                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    4576                 :          1 :     assert_int_equal(heartbeat_period,5);
+    4577                 :          1 :     free(data);
+    4578                 :          1 : }
+    4579                 :            : 
+    4580                 :          1 : void libspdm_test_requester_psk_exchange_case22(void **state)
+    4581                 :            : {
+    4582                 :            :     libspdm_return_t status;
+    4583                 :            :     libspdm_test_context_t *spdm_test_context;
+    4584                 :            :     libspdm_context_t *spdm_context;
+    4585                 :            :     uint32_t session_id;
+    4586                 :            :     uint8_t heartbeat_period;
+    4587                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    4588                 :            :     void *data;
+    4589                 :            :     size_t data_size;
+    4590                 :            :     void *hash;
+    4591                 :            :     size_t hash_size;
+    4592                 :            : 
+    4593                 :          1 :     spdm_test_context = *state;
+    4594                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4595                 :            : 
+    4596         [ +  - ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    4597                 :          1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    4598                 :            :     }
+    4599                 :            : 
+    4600                 :          1 :     spdm_test_context->case_id = 0x16;
+    4601                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4602                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4603                 :          1 :     spdm_context->connection_info.connection_state =
+    4604                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    4605                 :          1 :     spdm_context->connection_info.capability.flags &=
+    4606                 :            :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
+    4607                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4608                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
+    4609                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4610                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG;
+    4611                 :          1 :     spdm_context->local_context.capability.flags |=
+    4612                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
+    4613                 :            : 
+    4614                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4615                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP;
+    4616                 :          1 :     spdm_context->local_context.capability.flags |=
+    4617                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP;
+    4618                 :            : 
+    4619                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    4620                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    4621                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
+    4622                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
+    4623                 :            :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4624                 :            : 
+    4625                 :            : 
+    4626                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    4627                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    4628                 :            :                                                     &data_size, &hash, &hash_size);
+    4629                 :          1 :     libspdm_reset_message_a(spdm_context);
+    4630                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    4631                 :            :         m_libspdm_use_hash_algo;
+    4632                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    4633                 :            :         m_libspdm_use_dhe_algo;
+    4634                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    4635                 :            :         m_libspdm_use_aead_algo;
+    4636                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    4637                 :            :         m_libspdm_use_measurement_hash_algo;
+    4638                 :          1 :     spdm_context->connection_info.algorithm.key_schedule =
+    4639                 :            :         m_libspdm_use_key_schedule_algo;
+    4640                 :            : 
+    4641                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4642                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    4643                 :            :         data_size;
+    4644                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    4645                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    4646                 :            :                      data, data_size);
+    4647                 :            : 
+    4648                 :            : #endif
+    4649                 :            : 
+    4650                 :          1 :     heartbeat_period = 0;
+    4651                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    4652                 :          1 :     status = libspdm_send_receive_psk_exchange(
+    4653                 :            :         spdm_context,
+    4654                 :            :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
+    4655                 :            :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
+    4656                 :            :         &heartbeat_period, measurement_hash);
+    4657                 :            : 
+    4658                 :            :     /*clear Heartbeat flags*/
+    4659                 :          1 :     spdm_context->connection_info.capability.flags &=
+    4660                 :            :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP;
+    4661                 :          1 :     spdm_context->local_context.capability.flags &=
+    4662                 :            :         ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP;
+    4663                 :            : 
+    4664                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    4665                 :          1 :     assert_int_equal(session_id, 0xFFFFFFFF);
+    4666                 :          1 :     assert_int_equal(
+    4667                 :            :         libspdm_secured_message_get_session_state(
+    4668                 :            :             spdm_context->session_info[0].secured_message_context),
+    4669                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    4670                 :          1 :     assert_int_equal(heartbeat_period,0);
+    4671                 :          1 :     free(data);
+    4672                 :          1 : }
+    4673                 :            : 
+    4674                 :          1 : void libspdm_test_requester_psk_exchange_case23(void **state)
+    4675                 :            : {
+    4676                 :            :     libspdm_return_t status;
+    4677                 :            :     libspdm_test_context_t *spdm_test_context;
+    4678                 :            :     libspdm_context_t *spdm_context;
+    4679                 :            :     uint32_t session_id;
+    4680                 :            :     uint8_t heartbeat_period;
+    4681                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    4682                 :            :     void *data;
+    4683                 :            :     size_t data_size;
+    4684                 :            :     void *hash;
+    4685                 :            :     size_t hash_size;
+    4686                 :            : 
+    4687                 :          1 :     spdm_test_context = *state;
+    4688                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4689                 :            : 
+    4690         [ +  - ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    4691                 :          1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    4692                 :            :     }
+    4693                 :            : 
+    4694                 :          1 :     spdm_test_context->case_id = 0x17;
+    4695                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4696                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4697                 :          1 :     spdm_context->connection_info.connection_state =
+    4698                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    4699                 :          1 :     spdm_context->connection_info.capability.flags &=
+    4700                 :            :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
+    4701                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4702                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
+    4703                 :          1 :     spdm_context->local_context.capability.flags |=
+    4704                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
+    4705                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
+    4706                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
+    4707                 :            :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4708                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    4709                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    4710                 :            :                                                     &data_size, &hash, &hash_size);
+    4711                 :          1 :     libspdm_reset_message_a(spdm_context);
+    4712                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    4713                 :            :         m_libspdm_use_hash_algo;
+    4714                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    4715                 :            :         m_libspdm_use_dhe_algo;
+    4716                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    4717                 :            :         m_libspdm_use_aead_algo;
+    4718                 :          1 :     spdm_context->connection_info.algorithm.key_schedule =
+    4719                 :            :         m_libspdm_use_key_schedule_algo;
+    4720                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4721                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    4722                 :            :         data_size;
+    4723                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    4724                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    4725                 :            :                      data, data_size);
+    4726                 :            : #endif
+    4727                 :            : 
+    4728                 :          1 :     heartbeat_period = 0;
+    4729                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    4730                 :          1 :     status = libspdm_send_receive_psk_exchange(
+    4731                 :            :         spdm_context,
+    4732                 :            :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
+    4733                 :            :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
+    4734                 :            :         &heartbeat_period, measurement_hash);
+    4735                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_VERIF_FAIL);
+    4736                 :          1 :     free(data);
+    4737                 :          1 : }
+    4738                 :            : 
+    4739                 :          1 : void libspdm_test_requester_psk_exchange_case24(void **state)
+    4740                 :            : {
+    4741                 :            :     libspdm_return_t status;
+    4742                 :            :     libspdm_test_context_t *spdm_test_context;
+    4743                 :            :     libspdm_context_t *spdm_context;
+    4744                 :            :     uint32_t session_id;
+    4745                 :            :     uint8_t heartbeat_period;
+    4746                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    4747                 :            :     void *data;
+    4748                 :            :     size_t data_size;
+    4749                 :            :     void *hash;
+    4750                 :            :     size_t hash_size;
+    4751                 :            : 
+    4752                 :          1 :     spdm_test_context = *state;
+    4753                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4754                 :            : 
+    4755         [ -  + ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    4756                 :          0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    4757                 :            :     }
+    4758                 :            : 
+    4759                 :          1 :     spdm_test_context->case_id = 0x18;
+    4760                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4761                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4762                 :          1 :     spdm_context->connection_info.connection_state =
+    4763                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    4764                 :          1 :     spdm_context->connection_info.capability.flags &=
+    4765                 :            :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
+    4766                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4767                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER;
+    4768                 :          1 :     spdm_context->local_context.capability.flags |=
+    4769                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
+    4770                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
+    4771                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
+    4772                 :            :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4773                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    4774                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    4775                 :            :                                                     &data_size, &hash, &hash_size);
+    4776                 :          1 :     libspdm_reset_message_a(spdm_context);
+    4777                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    4778                 :            :         m_libspdm_use_hash_algo;
+    4779                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    4780                 :            :         m_libspdm_use_dhe_algo;
+    4781                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    4782                 :            :         m_libspdm_use_aead_algo;
+    4783                 :          1 :     spdm_context->connection_info.algorithm.key_schedule =
+    4784                 :            :         m_libspdm_use_key_schedule_algo;
+    4785                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4786                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    4787                 :            :         data_size;
+    4788                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    4789                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    4790                 :            :                      data, data_size);
+    4791                 :            : #endif
+    4792                 :            : 
+    4793                 :          1 :     heartbeat_period = 0;
+    4794                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    4795                 :          1 :     status = libspdm_send_receive_psk_exchange(
+    4796                 :            :         spdm_context,
+    4797                 :            :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
+    4798                 :            :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
+    4799                 :            :         &heartbeat_period, measurement_hash);
+    4800                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    4801                 :          1 :     assert_int_equal(session_id, 0xFFFFFFFF);
+    4802                 :          1 :     assert_int_equal(
+    4803                 :            :         libspdm_secured_message_get_session_state(
+    4804                 :            :             spdm_context->session_info[0].secured_message_context),
+    4805                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+    4806                 :          1 :     free(data);
+    4807                 :          1 : }
+    4808                 :            : 
+    4809                 :          1 : void libspdm_test_requester_psk_exchange_case25(void **state)
+    4810                 :            : {
+    4811                 :            :     libspdm_return_t status;
+    4812                 :            :     libspdm_test_context_t *spdm_test_context;
+    4813                 :            :     libspdm_context_t *spdm_context;
+    4814                 :            :     uint32_t session_id;
+    4815                 :            :     uint8_t heartbeat_period;
+    4816                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    4817                 :            :     void *data;
+    4818                 :            :     size_t data_size;
+    4819                 :            :     void *hash;
+    4820                 :            :     size_t hash_size;
+    4821                 :            : 
+    4822                 :          1 :     spdm_test_context = *state;
+    4823                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4824                 :            : 
+    4825         [ +  - ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    4826                 :          1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    4827                 :            :     }
+    4828                 :            : 
+    4829                 :          1 :     spdm_test_context->case_id = 0x19;
+    4830                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4831                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4832                 :          1 :     spdm_context->connection_info.connection_state =
+    4833                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    4834                 :          1 :     spdm_context->connection_info.capability.flags &=
+    4835                 :            :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
+    4836                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4837                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
+    4838                 :          1 :     spdm_context->local_context.capability.flags |=
+    4839                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
+    4840                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
+    4841                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
+    4842                 :            :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4843                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    4844                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    4845                 :            :                                                     &data_size, &hash, &hash_size);
+    4846                 :          1 :     libspdm_reset_message_a(spdm_context);
+    4847                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    4848                 :            :         m_libspdm_use_hash_algo;
+    4849                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    4850                 :            :         m_libspdm_use_dhe_algo;
+    4851                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    4852                 :            :         m_libspdm_use_aead_algo;
+    4853                 :          1 :     spdm_context->connection_info.algorithm.key_schedule =
+    4854                 :            :         m_libspdm_use_key_schedule_algo;
+    4855                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4856                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    4857                 :            :         data_size;
+    4858                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    4859                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    4860                 :            :                      data, data_size);
+    4861                 :            : #endif
+    4862                 :            : 
+    4863                 :          1 :     heartbeat_period = 0;
+    4864                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    4865                 :          1 :     status = libspdm_send_receive_psk_exchange(
+    4866                 :            :         spdm_context,
+    4867                 :            :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
+    4868                 :            :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
+    4869                 :            :         &heartbeat_period, measurement_hash);
+    4870                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    4871                 :          1 :     assert_int_equal(session_id, 0xFFFFFFFF);
+    4872                 :          1 :     assert_int_equal(
+    4873                 :            :         libspdm_secured_message_get_session_state(
+    4874                 :            :             spdm_context->session_info[0].secured_message_context),
+    4875                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    4876                 :          1 :     free(data);
+    4877                 :          1 : }
+    4878                 :            : 
+    4879                 :          1 : void libspdm_test_requester_psk_exchange_case26(void **state)
+    4880                 :            : {
+    4881                 :            :     libspdm_return_t status;
+    4882                 :            :     libspdm_test_context_t *spdm_test_context;
+    4883                 :            :     libspdm_context_t *spdm_context;
+    4884                 :            :     uint32_t session_id;
+    4885                 :            :     uint8_t heartbeat_period;
+    4886                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    4887                 :            :     void *data;
+    4888                 :            :     size_t data_size;
+    4889                 :            :     void *hash;
+    4890                 :            :     size_t hash_size;
+    4891                 :            : 
+    4892                 :          1 :     spdm_test_context = *state;
+    4893                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4894                 :            : 
+    4895         [ +  - ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    4896                 :          1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    4897                 :            :     }
+    4898                 :            : 
+    4899                 :          1 :     spdm_test_context->case_id = 0x1A;
+    4900                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    4901                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4902                 :          1 :     spdm_context->connection_info.connection_state =
+    4903                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    4904                 :          1 :     spdm_context->connection_info.capability.flags &=
+    4905                 :            :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
+    4906                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4907                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER;
+    4908                 :          1 :     spdm_context->local_context.capability.flags |=
+    4909                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
+    4910                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
+    4911                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
+    4912                 :            :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4913                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    4914                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    4915                 :            :                                                     &data_size, &hash, &hash_size);
+    4916                 :          1 :     libspdm_reset_message_a(spdm_context);
+    4917                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    4918                 :            :         m_libspdm_use_hash_algo;
+    4919                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    4920                 :            :         m_libspdm_use_dhe_algo;
+    4921                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    4922                 :            :         m_libspdm_use_aead_algo;
+    4923                 :          1 :     spdm_context->connection_info.algorithm.key_schedule =
+    4924                 :            :         m_libspdm_use_key_schedule_algo;
+    4925                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4926                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    4927                 :            :         data_size;
+    4928                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    4929                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    4930                 :            :                      data, data_size);
+    4931                 :            : #endif
+    4932                 :            : 
+    4933                 :          1 :     heartbeat_period = 0;
+    4934                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    4935                 :          1 :     status = libspdm_send_receive_psk_exchange(
+    4936                 :            :         spdm_context,
+    4937                 :            :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
+    4938                 :            :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
+    4939                 :            :         &heartbeat_period, measurement_hash);
+    4940                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    4941                 :          1 :     assert_int_equal(session_id, 0xFFFFFFFF);
+    4942                 :          1 :     assert_int_equal(
+    4943                 :            :         libspdm_secured_message_get_session_state(
+    4944                 :            :             spdm_context->session_info[0].secured_message_context),
+    4945                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+    4946                 :          1 :     free(data);
+    4947                 :          1 : }
+    4948                 :            : 
+    4949                 :          1 : void libspdm_test_requester_psk_exchange_case27(void **state)
+    4950                 :            : {
+    4951                 :            :     libspdm_return_t status;
+    4952                 :            :     libspdm_test_context_t *spdm_test_context;
+    4953                 :            :     libspdm_context_t *spdm_context;
+    4954                 :            :     uint32_t session_id;
+    4955                 :            :     uint8_t heartbeat_period;
+    4956                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    4957                 :            :     void *data;
+    4958                 :            :     size_t data_size;
+    4959                 :            :     void *hash;
+    4960                 :            :     size_t hash_size;
+    4961                 :            : 
+    4962                 :          1 :     spdm_test_context = *state;
+    4963                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    4964                 :          1 :     spdm_test_context->case_id = 0x1B;
+    4965                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    4966                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4967                 :          1 :     spdm_context->connection_info.connection_state =
+    4968                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    4969                 :          1 :     spdm_context->connection_info.capability.flags &=
+    4970                 :            :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
+    4971                 :          1 :     spdm_context->connection_info.capability.flags |=
+    4972                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
+    4973                 :          1 :     spdm_context->local_context.capability.flags |=
+    4974                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
+    4975                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
+    4976                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
+    4977                 :            :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
+    4978                 :          1 :     spdm_context->connection_info.algorithm.other_params_support =
+    4979                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
+    4980                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    4981                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    4982                 :            :                                                     &data_size, &hash, &hash_size);
+    4983                 :          1 :     libspdm_reset_message_a(spdm_context);
+    4984                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    4985                 :            :         m_libspdm_use_hash_algo;
+    4986                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    4987                 :            :         m_libspdm_use_dhe_algo;
+    4988                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    4989                 :            :         m_libspdm_use_aead_algo;
+    4990                 :          1 :     spdm_context->connection_info.algorithm.key_schedule =
+    4991                 :            :         m_libspdm_use_key_schedule_algo;
+    4992                 :          1 :     libspdm_session_info_init(spdm_context,
+    4993                 :          1 :                               spdm_context->session_info,
+    4994                 :            :                               INVALID_SESSION_ID, false);
+    4995                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    4996                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    4997                 :            :         data_size;
+    4998                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    4999                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    5000                 :            :                      data, data_size);
+    5001                 :            : #endif
+    5002                 :            : 
+    5003                 :          1 :     heartbeat_period = 0;
+    5004                 :          1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
+    5005                 :          1 :     status = libspdm_send_receive_psk_exchange(
+    5006                 :            :         spdm_context,
+    5007                 :            :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
+    5008                 :            :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
+    5009                 :            :         SPDM_PSK_EXCHANGE_REQUEST_ALL_MEASUREMENTS_HASH, &session_id,
+    5010                 :            :         &heartbeat_period, measurement_hash);
+    5011                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    5012                 :          1 :     assert_int_equal(session_id, 0xFFFFFFFF);
+    5013                 :          1 :     assert_int_equal(
+    5014                 :            :         libspdm_secured_message_get_session_state(
+    5015                 :            :             spdm_context->session_info[0].secured_message_context),
+    5016                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    5017                 :          1 :     assert_int_equal(
+    5018                 :            :         spdm_context->session_info[0].session_policy,
+    5019                 :            :         SPDM_PSK_EXCHANGE_REQUEST_ALL_MEASUREMENTS_HASH);
+    5020                 :          1 :     free(data);
+    5021                 :          1 : }
+    5022                 :            : 
+    5023                 :            : libspdm_test_context_t m_libspdm_requester_psk_exchange_test_context = {
+    5024                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+    5025                 :            :     true,
+    5026                 :            :     libspdm_requester_psk_exchange_test_send_message,
+    5027                 :            :     libspdm_requester_psk_exchange_test_receive_message,
+    5028                 :            : };
+    5029                 :            : 
+    5030                 :          1 : int libspdm_requester_psk_exchange_test_main(void)
+    5031                 :            : {
+    5032                 :          1 :     const struct CMUnitTest spdm_requester_psk_exchange_tests[] = {
+    5033                 :            :         /* SendRequest failed*/
+    5034                 :            :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case1),
+    5035                 :            :         /* Successful response*/
+    5036                 :            :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case2),
+    5037                 :            :         /* connection_state check failed*/
+    5038                 :            :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case3),
+    5039                 :            :         /* Error response: SPDM_ERROR_CODE_INVALID_REQUEST*/
+    5040                 :            :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case4),
+    5041                 :            :         /* Always SPDM_ERROR_CODE_BUSY*/
+    5042                 :            :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case5),
+    5043                 :            :         /* SPDM_ERROR_CODE_BUSY + Successful response*/
+    5044                 :            :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case6),
+    5045                 :            :         /* Error response: SPDM_ERROR_CODE_REQUEST_RESYNCH*/
+    5046                 :            :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case7),
+    5047                 :            :         /* Always SPDM_ERROR_CODE_RESPONSE_NOT_READY*/
+    5048                 :            :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case8),
+    5049                 :            :         /* SPDM_ERROR_CODE_RESPONSE_NOT_READY + Successful response*/
+    5050                 :            :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case9),
+    5051                 :            :         /* Unexpected errors*/
+    5052                 :            :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case10),
+    5053                 :            :         /* Buffer verification*/
+    5054                 :            :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case12),
+    5055                 :            :         /* Successful response V1.2*/
+    5056                 :            :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case13),
+    5057                 :            :         /* Measurement hash 1, returns a measurement hash*/
+    5058                 :            :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case14),
+    5059                 :            :         /* Measurement hash 1, returns a 0x00 array (no TCB components)*/
+    5060                 :            :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case15),
+    5061                 :            :         /* Measurement hash FF, returns a measurement_hash*/
+    5062                 :            :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case16),
+    5063                 :            :         /* Measurement hash 1, returns no measurement_hash*/
+    5064                 :            :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case17),
+    5065                 :            :         /* Measurement hash FF, returns no measurement_hash*/
+    5066                 :            :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case18),
+    5067                 :            :         /* Measurement hash not requested, returns a measurement_hash*/
+    5068                 :            :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case19),
+    5069                 :            :         /* Heartbeat not supported, heartbeat period different from 0 sent*/
+    5070                 :            :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case20),
+    5071                 :            :         /* Heartbeat supported, heartbeat period different from 0 sent*/
+    5072                 :            :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case21),
+    5073                 :            :         /* Heartbeat supported, heartbeat period 0 sent NOTE: This should disable heartbeat*/
+    5074                 :            :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case22),
+    5075                 :            :         /* Wrong ResponderVerifyData*/
+    5076                 :            :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case23),
+    5077                 :            :         /* No ResponderContext*/
+    5078                 :            :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case24),
+    5079                 :            :         /* No OpaqueData*/
+    5080                 :            :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case25),
+    5081                 :            :         /* No ResponderContext and OpaqueData*/
+    5082                 :            :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case26),
+    5083                 :            :         /* OpaqueData only supports OpaqueDataFmt1, Success Case */
+    5084                 :            :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case27),
+    5085                 :            :     };
+    5086                 :            : 
+    5087                 :          1 :     libspdm_setup_test_context(&m_libspdm_requester_psk_exchange_test_context);
+    5088                 :            : 
+    5089                 :          1 :     return cmocka_run_group_tests(spdm_requester_psk_exchange_tests,
+    5090                 :            :                                   libspdm_unit_test_group_setup,
+    5091                 :            :                                   libspdm_unit_test_group_teardown);
+    5092                 :            : }
+    5093                 :            : 
+    5094                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/psk_finish.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_requester/psk_finish.c.func-sort-c.html new file mode 100644 index 00000000000..49f5c029ea8 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/psk_finish.c.func-sort-c.html @@ -0,0 +1,169 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/psk_finish.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - psk_finish.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:955103991.9 %
Date:2024-09-22 08:21:07Functions:2222100.0 %
Branches:6710464.4 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_psk_finish_test_main1
libspdm_test_requester_psk_finish_case11
libspdm_test_requester_psk_finish_case101
libspdm_test_requester_psk_finish_case111
libspdm_test_requester_psk_finish_case121
libspdm_test_requester_psk_finish_case131
libspdm_test_requester_psk_finish_case141
libspdm_test_requester_psk_finish_case151
libspdm_test_requester_psk_finish_case161
libspdm_test_requester_psk_finish_case21
libspdm_test_requester_psk_finish_case31
libspdm_test_requester_psk_finish_case41
libspdm_test_requester_psk_finish_case51
libspdm_test_requester_psk_finish_case61
libspdm_test_requester_psk_finish_case71
libspdm_test_requester_psk_finish_case81
libspdm_test_requester_psk_finish_case91
libspdm_requester_psk_finish_test_receive_message32
libspdm_secured_message_set_response_handshake_encryption_key32
libspdm_secured_message_set_response_handshake_salt32
libspdm_requester_psk_finish_test_send_message33
libspdm_secured_message_set_dummy_finished_key33
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/psk_finish.c.func.html b/coverage_log/unit_test/test_spdm_requester/psk_finish.c.func.html new file mode 100644 index 00000000000..6ce3e706dc0 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/psk_finish.c.func.html @@ -0,0 +1,169 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/psk_finish.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - psk_finish.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:955103991.9 %
Date:2024-09-22 08:21:07Functions:2222100.0 %
Branches:6710464.4 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_psk_finish_test_main1
libspdm_requester_psk_finish_test_receive_message32
libspdm_requester_psk_finish_test_send_message33
libspdm_secured_message_set_dummy_finished_key33
libspdm_secured_message_set_response_handshake_encryption_key32
libspdm_secured_message_set_response_handshake_salt32
libspdm_test_requester_psk_finish_case11
libspdm_test_requester_psk_finish_case101
libspdm_test_requester_psk_finish_case111
libspdm_test_requester_psk_finish_case121
libspdm_test_requester_psk_finish_case131
libspdm_test_requester_psk_finish_case141
libspdm_test_requester_psk_finish_case151
libspdm_test_requester_psk_finish_case161
libspdm_test_requester_psk_finish_case21
libspdm_test_requester_psk_finish_case31
libspdm_test_requester_psk_finish_case41
libspdm_test_requester_psk_finish_case51
libspdm_test_requester_psk_finish_case61
libspdm_test_requester_psk_finish_case71
libspdm_test_requester_psk_finish_case81
libspdm_test_requester_psk_finish_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/psk_finish.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/psk_finish.c.gcov.html new file mode 100644 index 00000000000..4cfc288a152 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/psk_finish.c.gcov.html @@ -0,0 +1,2612 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/psk_finish.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - psk_finish.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:955103991.9 %
Date:2024-09-22 08:21:07Functions:2222100.0 %
Branches:6710464.4 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_requester_lib.h"
+       9                 :            : #include "internal/libspdm_secured_message_lib.h"
+      10                 :            : 
+      11                 :            : #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
+      12                 :            : 
+      13                 :            : static uint8_t m_libspdm_dummy_key_buffer[LIBSPDM_MAX_AEAD_KEY_SIZE];
+      14                 :            : static uint8_t m_libspdm_dummy_salt_buffer[LIBSPDM_MAX_AEAD_IV_SIZE];
+      15                 :            : 
+      16                 :            : static size_t m_libspdm_local_buffer_size;
+      17                 :            : static uint8_t m_libspdm_local_buffer[LIBSPDM_MAX_MESSAGE_TH_BUFFER_SIZE];
+      18                 :            : 
+      19                 :         33 : static void libspdm_secured_message_set_dummy_finished_key(
+      20                 :            :     void *spdm_secured_message_context)
+      21                 :            : {
+      22                 :         33 : }
+      23                 :            : 
+      24                 :         32 : void libspdm_secured_message_set_response_handshake_encryption_key(
+      25                 :            :     void *spdm_secured_message_context, const void *key, size_t key_size)
+      26                 :            : {
+      27                 :            :     libspdm_secured_message_context_t *secured_message_context;
+      28                 :            : 
+      29                 :         32 :     secured_message_context = spdm_secured_message_context;
+      30         [ -  + ]:         32 :     LIBSPDM_ASSERT(key_size == secured_message_context->aead_key_size);
+      31                 :         32 :     libspdm_copy_mem(secured_message_context->handshake_secret.response_handshake_encryption_key,
+      32                 :            :                      sizeof(secured_message_context->handshake_secret.
+      33                 :            :                             response_handshake_encryption_key),
+      34                 :            :                      key, secured_message_context->aead_key_size);
+      35                 :         32 : }
+      36                 :            : 
+      37                 :         32 : void libspdm_secured_message_set_response_handshake_salt(
+      38                 :            :     void *spdm_secured_message_context, const void *salt,
+      39                 :            :     size_t salt_size)
+      40                 :            : {
+      41                 :            :     libspdm_secured_message_context_t *secured_message_context;
+      42                 :            : 
+      43                 :         32 :     secured_message_context = spdm_secured_message_context;
+      44         [ -  + ]:         32 :     LIBSPDM_ASSERT(salt_size == secured_message_context->aead_iv_size);
+      45                 :         32 :     libspdm_copy_mem(secured_message_context->handshake_secret.response_handshake_salt,
+      46                 :            :                      sizeof(secured_message_context->handshake_secret.response_handshake_salt),
+      47                 :            :                      salt, secured_message_context->aead_iv_size);
+      48                 :         32 : }
+      49                 :            : 
+      50                 :         33 : libspdm_return_t libspdm_requester_psk_finish_test_send_message(void *spdm_context,
+      51                 :            :                                                                 size_t request_size,
+      52                 :            :                                                                 const void *request,
+      53                 :            :                                                                 uint64_t timeout)
+      54                 :            : {
+      55                 :            :     libspdm_test_context_t *spdm_test_context;
+      56                 :            : 
+      57                 :         33 :     spdm_test_context = libspdm_get_test_context();
+      58   [ +  +  -  +  :         33 :     switch (spdm_test_context->case_id) {
+          +  +  +  +  +  
+          +  +  -  +  -  
+                +  +  - ]
+      59                 :          1 :     case 0x1:
+      60                 :          1 :         return LIBSPDM_STATUS_SEND_FAIL;
+      61                 :          1 :     case 0x2:
+      62                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      63                 :          0 :     case 0x3:
+      64                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      65                 :          1 :     case 0x4:
+      66                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      67                 :          1 :     case 0x5:
+      68                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      69                 :          2 :     case 0x6:
+      70                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+      71                 :          1 :     case 0x7:
+      72                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      73                 :          2 :     case 0x8:
+      74                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+      75                 :          2 :     case 0x9:
+      76                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+      77                 :         18 :     case 0xA:
+      78                 :         18 :         return LIBSPDM_STATUS_SUCCESS;
+      79                 :          1 :     case 0xB:
+      80                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      81                 :          0 :     case 0xC:
+      82                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      83                 :          1 :     case 0xD:
+      84                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      85                 :          0 :     case 0xE:
+      86                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      87                 :          1 :     case 0xF:
+      88                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      89                 :          1 :     case 0x10: {
+      90                 :            :         libspdm_return_t status;
+      91                 :            :         uint8_t *decoded_message;
+      92                 :            :         size_t decoded_message_size;
+      93                 :            :         uint32_t session_id;
+      94                 :            :         uint32_t *message_session_id;
+      95                 :            :         bool is_app_message;
+      96                 :            :         libspdm_session_info_t *session_info;
+      97                 :            :         uint8_t message_buffer[LIBSPDM_SENDER_BUFFER_SIZE];
+      98                 :            : 
+      99                 :          1 :         message_session_id = NULL;
+     100                 :          1 :         session_id = 0xFFFFFFFF;
+     101                 :          1 :         decoded_message = (uint8_t *) &m_libspdm_local_buffer[0];
+     102                 :          1 :         decoded_message_size = sizeof(m_libspdm_local_buffer);
+     103                 :            : 
+     104                 :          1 :         session_info = libspdm_get_session_info_via_session_id(spdm_context, session_id);
+     105         [ -  + ]:          1 :         if (session_info == NULL) {
+     106                 :          0 :             return LIBSPDM_STATUS_SEND_FAIL;
+     107                 :            :         }
+     108                 :            : 
+     109                 :          1 :         memcpy(message_buffer, request, request_size);
+     110                 :            : 
+     111                 :          1 :         ((libspdm_secured_message_context_t *)(session_info->secured_message_context))
+     112                 :          1 :         ->handshake_secret.request_handshake_sequence_number--;
+     113                 :          1 :         m_libspdm_local_buffer_size = 0;
+     114                 :          1 :         libspdm_get_scratch_buffer (spdm_context, (void **)&decoded_message, &decoded_message_size);
+     115                 :          1 :         status = libspdm_transport_test_decode_message(
+     116                 :            :             spdm_context,
+     117                 :            :             &message_session_id, &is_app_message, true, request_size, message_buffer,
+     118                 :            :             &decoded_message_size, (void **)&decoded_message);
+     119         [ -  + ]:          1 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
+     120                 :          0 :             return LIBSPDM_STATUS_SEND_FAIL;
+     121                 :            :         }
+     122                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+     123                 :            :                          sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
+     124                 :            :                          decoded_message, decoded_message_size);
+     125                 :          1 :         m_libspdm_local_buffer_size += decoded_message_size;
+     126                 :            :     }
+     127                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     128                 :          0 :     default:
+     129                 :          0 :         return LIBSPDM_STATUS_SEND_FAIL;
+     130                 :            :     }
+     131                 :            : }
+     132                 :            : 
+     133                 :         32 : libspdm_return_t libspdm_requester_psk_finish_test_receive_message(
+     134                 :            :     void *spdm_context, size_t *response_size,
+     135                 :            :     void **response, uint64_t timeout)
+     136                 :            : {
+     137                 :            :     libspdm_test_context_t *spdm_test_context;
+     138                 :            : 
+     139                 :         32 :     spdm_test_context = libspdm_get_test_context();
+     140   [ -  +  -  +  :         32 :     switch (spdm_test_context->case_id) {
+          +  +  +  +  +  
+          +  +  -  +  -  
+                +  +  - ]
+     141                 :          0 :     case 0x1:
+     142                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+     143                 :            : 
+     144                 :          1 :     case 0x2: {
+     145                 :            :         spdm_psk_finish_response_t *spdm_response;
+     146                 :            :         size_t spdm_response_size;
+     147                 :            :         size_t transport_header_size;
+     148                 :            :         uint32_t session_id;
+     149                 :            :         libspdm_session_info_t *session_info;
+     150                 :            :         uint8_t *scratch_buffer;
+     151                 :            :         size_t scratch_buffer_size;
+     152                 :            : 
+     153                 :          1 :         session_id = 0xFFFFFFFF;
+     154                 :          1 :         spdm_response_size = sizeof(spdm_psk_finish_response_t);
+     155                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     156                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     157                 :            : 
+     158                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     159                 :          1 :         spdm_response->header.request_response_code =
+     160                 :            :             SPDM_PSK_FINISH_RSP;
+     161                 :          1 :         spdm_response->header.param1 = 0;
+     162                 :          1 :         spdm_response->header.param2 = 0;
+     163                 :            : 
+     164                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+     165                 :            :          * transport_message is always in sender buffer. */
+     166                 :          1 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+     167                 :          1 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+     168                 :            :                           scratch_buffer_size - transport_header_size,
+     169                 :            :                           spdm_response, spdm_response_size);
+     170                 :          1 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+     171                 :          1 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+     172                 :            :                                               false, false, spdm_response_size,
+     173                 :            :                                               spdm_response, response_size,
+     174                 :            :                                               response);
+     175                 :          1 :         session_info = libspdm_get_session_info_via_session_id(
+     176                 :            :             spdm_context, session_id);
+     177         [ -  + ]:          1 :         if (session_info == NULL) {
+     178                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+     179                 :            :         }
+     180                 :            :         /* WALKAROUND: If just use single context to encode message and then decode message */
+     181                 :            :         ((libspdm_secured_message_context_t
+     182                 :          1 :           *)(session_info->secured_message_context))
+     183                 :          1 :         ->handshake_secret.response_handshake_sequence_number--;
+     184                 :            :     }
+     185                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     186                 :            : 
+     187                 :          0 :     case 0x3: {
+     188                 :            :         spdm_psk_finish_response_t *spdm_response;
+     189                 :            :         size_t spdm_response_size;
+     190                 :            :         size_t transport_header_size;
+     191                 :            :         uint32_t session_id;
+     192                 :            :         libspdm_session_info_t *session_info;
+     193                 :            :         uint8_t *scratch_buffer;
+     194                 :            :         size_t scratch_buffer_size;
+     195                 :            : 
+     196                 :          0 :         session_id = 0xFFFFFFFF;
+     197                 :          0 :         spdm_response_size = sizeof(spdm_psk_finish_response_t);
+     198                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     199                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     200                 :            : 
+     201                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     202                 :          0 :         spdm_response->header.request_response_code =
+     203                 :            :             SPDM_PSK_FINISH_RSP;
+     204                 :          0 :         spdm_response->header.param1 = 0;
+     205                 :          0 :         spdm_response->header.param2 = 0;
+     206                 :            : 
+     207                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+     208                 :            :          * transport_message is always in sender buffer. */
+     209                 :          0 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+     210                 :          0 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+     211                 :            :                           scratch_buffer_size - transport_header_size,
+     212                 :            :                           spdm_response, spdm_response_size);
+     213                 :          0 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+     214                 :          0 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+     215                 :            :                                               false, false, spdm_response_size,
+     216                 :            :                                               spdm_response, response_size,
+     217                 :            :                                               response);
+     218                 :          0 :         session_info = libspdm_get_session_info_via_session_id(
+     219                 :            :             spdm_context, session_id);
+     220         [ #  # ]:          0 :         if (session_info == NULL) {
+     221                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+     222                 :            :         }
+     223                 :            :         ((libspdm_secured_message_context_t
+     224                 :          0 :           *)(session_info->secured_message_context))
+     225                 :          0 :         ->handshake_secret.response_handshake_sequence_number--;
+     226                 :            :     }
+     227                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     228                 :            : 
+     229                 :          1 :     case 0x4: {
+     230                 :            :         spdm_error_response_t *spdm_response;
+     231                 :            :         size_t spdm_response_size;
+     232                 :            :         size_t transport_header_size;
+     233                 :            :         uint32_t session_id;
+     234                 :            :         libspdm_session_info_t *session_info;
+     235                 :            :         uint8_t *scratch_buffer;
+     236                 :            :         size_t scratch_buffer_size;
+     237                 :            : 
+     238                 :          1 :         spdm_response_size = sizeof(spdm_error_response_t);
+     239                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     240                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     241                 :            : 
+     242                 :          1 :         session_id = 0xFFFFFFFF;
+     243                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     244                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     245                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_INVALID_REQUEST;
+     246                 :          1 :         spdm_response->header.param2 = 0;
+     247                 :            : 
+     248                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+     249                 :            :          * transport_message is always in sender buffer. */
+     250                 :          1 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+     251                 :          1 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+     252                 :            :                           scratch_buffer_size - transport_header_size,
+     253                 :            :                           spdm_response, spdm_response_size);
+     254                 :          1 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+     255                 :          1 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+     256                 :            :                                               false, false,
+     257                 :            :                                               spdm_response_size,
+     258                 :            :                                               spdm_response,
+     259                 :            :                                               response_size, response);
+     260                 :          1 :         session_info = libspdm_get_session_info_via_session_id(
+     261                 :            :             spdm_context, session_id);
+     262         [ -  + ]:          1 :         if (session_info == NULL) {
+     263                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+     264                 :            :         }
+     265                 :            :         ((libspdm_secured_message_context_t
+     266                 :          1 :           *)(session_info->secured_message_context))
+     267                 :          1 :         ->handshake_secret.response_handshake_sequence_number--;
+     268                 :            :     }
+     269                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     270                 :            : 
+     271                 :          1 :     case 0x5: {
+     272                 :            :         spdm_error_response_t *spdm_response;
+     273                 :            :         size_t spdm_response_size;
+     274                 :            :         size_t transport_header_size;
+     275                 :            :         uint32_t session_id;
+     276                 :            :         libspdm_session_info_t *session_info;
+     277                 :            :         uint8_t *scratch_buffer;
+     278                 :            :         size_t scratch_buffer_size;
+     279                 :            : 
+     280                 :          1 :         spdm_response_size = sizeof(spdm_error_response_t);
+     281                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     282                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     283                 :            : 
+     284                 :          1 :         session_id = 0xFFFFFFFF;
+     285                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     286                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     287                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
+     288                 :          1 :         spdm_response->header.param2 = 0;
+     289                 :            : 
+     290                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+     291                 :            :          * transport_message is always in sender buffer. */
+     292                 :          1 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+     293                 :          1 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+     294                 :            :                           scratch_buffer_size - transport_header_size,
+     295                 :            :                           spdm_response, spdm_response_size);
+     296                 :          1 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+     297                 :          1 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+     298                 :            :                                               false, false,
+     299                 :            :                                               spdm_response_size,
+     300                 :            :                                               spdm_response,
+     301                 :            :                                               response_size, response);
+     302                 :          1 :         session_info = libspdm_get_session_info_via_session_id(
+     303                 :            :             spdm_context, session_id);
+     304         [ -  + ]:          1 :         if (session_info == NULL) {
+     305                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+     306                 :            :         }
+     307                 :            :         ((libspdm_secured_message_context_t
+     308                 :          1 :           *)(session_info->secured_message_context))
+     309                 :          1 :         ->handshake_secret.response_handshake_sequence_number--;
+     310                 :            :     }
+     311                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     312                 :            : 
+     313                 :          2 :     case 0x6: {
+     314                 :            :         static size_t sub_index1 = 0;
+     315         [ +  + ]:          2 :         if (sub_index1 == 0) {
+     316                 :            :             spdm_error_response_t *spdm_response;
+     317                 :            :             size_t spdm_response_size;
+     318                 :            :             size_t transport_header_size;
+     319                 :            :             uint32_t session_id;
+     320                 :            :             libspdm_session_info_t *session_info;
+     321                 :            :             uint8_t *scratch_buffer;
+     322                 :            :             size_t scratch_buffer_size;
+     323                 :            : 
+     324                 :          1 :             spdm_response_size = sizeof(spdm_error_response_t);
+     325                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     326                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     327                 :            : 
+     328                 :          1 :             session_id = 0xFFFFFFFF;
+     329                 :          1 :             spdm_response->header.spdm_version =
+     330                 :            :                 SPDM_MESSAGE_VERSION_11;
+     331                 :          1 :             spdm_response->header.request_response_code = SPDM_ERROR;
+     332                 :          1 :             spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
+     333                 :          1 :             spdm_response->header.param2 = 0;
+     334                 :            : 
+     335                 :            :             /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+     336                 :            :              * transport_message is always in sender buffer. */
+     337                 :          1 :             libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+     338                 :            :                                         &scratch_buffer_size);
+     339                 :          1 :             libspdm_copy_mem (scratch_buffer + transport_header_size,
+     340                 :            :                               scratch_buffer_size - transport_header_size,
+     341                 :            :                               spdm_response, spdm_response_size);
+     342                 :          1 :             spdm_response = (void *)(scratch_buffer + transport_header_size);
+     343                 :          1 :             libspdm_transport_test_encode_message(
+     344                 :            :                 spdm_context, &session_id, false, false,
+     345                 :            :                 spdm_response_size, spdm_response,
+     346                 :            :                 response_size, response);
+     347                 :          1 :             sub_index1++;
+     348                 :          1 :             session_info = libspdm_get_session_info_via_session_id(
+     349                 :            :                 spdm_context, session_id);
+     350         [ -  + ]:          1 :             if (session_info == NULL) {
+     351                 :          0 :                 return LIBSPDM_STATUS_RECEIVE_FAIL;
+     352                 :            :             }
+     353                 :            :             ((libspdm_secured_message_context_t
+     354                 :          1 :               *)(session_info->secured_message_context))
+     355                 :            :             ->handshake_secret
+     356                 :          1 :             .response_handshake_sequence_number--;
+     357         [ +  - ]:          1 :         } else if (sub_index1 == 1) {
+     358                 :            :             spdm_psk_finish_response_t *spdm_response;
+     359                 :            :             size_t spdm_response_size;
+     360                 :            :             size_t transport_header_size;
+     361                 :            :             uint32_t session_id;
+     362                 :            :             libspdm_session_info_t *session_info;
+     363                 :            :             uint8_t *scratch_buffer;
+     364                 :            :             size_t scratch_buffer_size;
+     365                 :            : 
+     366                 :          1 :             session_id = 0xFFFFFFFF;
+     367                 :          1 :             spdm_response_size = sizeof(spdm_psk_finish_response_t);
+     368                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     369                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     370                 :            : 
+     371                 :          1 :             spdm_response->header.spdm_version =
+     372                 :            :                 SPDM_MESSAGE_VERSION_11;
+     373                 :          1 :             spdm_response->header.request_response_code =
+     374                 :            :                 SPDM_PSK_FINISH_RSP;
+     375                 :          1 :             spdm_response->header.param1 = 0;
+     376                 :          1 :             spdm_response->header.param2 = 0;
+     377                 :            : 
+     378                 :            :             /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+     379                 :            :              * transport_message is always in sender buffer. */
+     380                 :          1 :             libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+     381                 :            :                                         &scratch_buffer_size);
+     382                 :          1 :             libspdm_copy_mem (scratch_buffer + transport_header_size,
+     383                 :            :                               scratch_buffer_size - transport_header_size,
+     384                 :            :                               spdm_response, spdm_response_size);
+     385                 :          1 :             spdm_response = (void *)(scratch_buffer + transport_header_size);
+     386                 :          1 :             libspdm_transport_test_encode_message(
+     387                 :            :                 spdm_context, &session_id, false, false,
+     388                 :            :                 spdm_response_size, spdm_response, response_size,
+     389                 :            :                 response);
+     390                 :          1 :             session_info = libspdm_get_session_info_via_session_id(
+     391                 :            :                 spdm_context, session_id);
+     392         [ -  + ]:          1 :             if (session_info == NULL) {
+     393                 :          0 :                 return LIBSPDM_STATUS_RECEIVE_FAIL;
+     394                 :            :             }
+     395                 :            :             ((libspdm_secured_message_context_t
+     396                 :          1 :               *)(session_info->secured_message_context))
+     397                 :            :             ->handshake_secret
+     398                 :          1 :             .response_handshake_sequence_number--;
+     399                 :            :         }
+     400                 :            :     }
+     401                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     402                 :            : 
+     403                 :          1 :     case 0x7: {
+     404                 :            :         spdm_error_response_t *spdm_response;
+     405                 :            :         size_t spdm_response_size;
+     406                 :            :         size_t transport_header_size;
+     407                 :            :         uint32_t session_id;
+     408                 :            :         libspdm_session_info_t *session_info;
+     409                 :            :         uint8_t *scratch_buffer;
+     410                 :            :         size_t scratch_buffer_size;
+     411                 :            : 
+     412                 :          1 :         spdm_response_size = sizeof(spdm_error_response_t);
+     413                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     414                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     415                 :            : 
+     416                 :          1 :         session_id = 0xFFFFFFFF;
+     417                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     418                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     419                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_REQUEST_RESYNCH;
+     420                 :          1 :         spdm_response->header.param2 = 0;
+     421                 :            : 
+     422                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+     423                 :            :          * transport_message is always in sender buffer. */
+     424                 :          1 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+     425                 :          1 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+     426                 :            :                           scratch_buffer_size - transport_header_size,
+     427                 :            :                           spdm_response, spdm_response_size);
+     428                 :          1 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+     429                 :          1 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+     430                 :            :                                               false, false,
+     431                 :            :                                               spdm_response_size,
+     432                 :            :                                               spdm_response,
+     433                 :            :                                               response_size, response);
+     434                 :          1 :         session_info = libspdm_get_session_info_via_session_id(
+     435                 :            :             spdm_context, session_id);
+     436         [ -  + ]:          1 :         if (session_info == NULL) {
+     437                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+     438                 :            :         }
+     439                 :            :         ((libspdm_secured_message_context_t
+     440                 :          1 :           *)(session_info->secured_message_context))
+     441                 :          1 :         ->handshake_secret.response_handshake_sequence_number--;
+     442                 :            :     }
+     443                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     444                 :            : 
+     445                 :          2 :     case 0x8: {
+     446                 :            :         spdm_error_response_data_response_not_ready_t *spdm_response;
+     447                 :            :         size_t spdm_response_size;
+     448                 :            :         size_t transport_header_size;
+     449                 :            :         uint32_t session_id;
+     450                 :            :         libspdm_session_info_t *session_info;
+     451                 :            :         uint8_t *scratch_buffer;
+     452                 :            :         size_t scratch_buffer_size;
+     453                 :            : 
+     454                 :          2 :         spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
+     455                 :          2 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     456                 :          2 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     457                 :            : 
+     458                 :          2 :         session_id = 0xFFFFFFFF;
+     459                 :          2 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     460                 :          2 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     461                 :          2 :         spdm_response->header.param1 =
+     462                 :            :             SPDM_ERROR_CODE_RESPONSE_NOT_READY;
+     463                 :          2 :         spdm_response->header.param2 = 0;
+     464                 :          2 :         spdm_response->extend_error_data.rd_exponent = 1;
+     465                 :          2 :         spdm_response->extend_error_data.rd_tm = 2;
+     466                 :          2 :         spdm_response->extend_error_data.request_code = SPDM_PSK_FINISH;
+     467                 :          2 :         spdm_response->extend_error_data.token = 0;
+     468                 :            : 
+     469                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+     470                 :            :          * transport_message is always in sender buffer. */
+     471                 :          2 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+     472                 :          2 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+     473                 :            :                           scratch_buffer_size - transport_header_size,
+     474                 :            :                           spdm_response, spdm_response_size);
+     475                 :          2 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+     476                 :          2 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+     477                 :            :                                               false, false,
+     478                 :            :                                               spdm_response_size,
+     479                 :            :                                               spdm_response,
+     480                 :            :                                               response_size, response);
+     481                 :          2 :         session_info = libspdm_get_session_info_via_session_id(
+     482                 :            :             spdm_context, session_id);
+     483         [ -  + ]:          2 :         if (session_info == NULL) {
+     484                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+     485                 :            :         }
+     486                 :            :         ((libspdm_secured_message_context_t
+     487                 :          2 :           *)(session_info->secured_message_context))
+     488                 :          2 :         ->handshake_secret.response_handshake_sequence_number--;
+     489                 :            :     }
+     490                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     491                 :            : 
+     492                 :          2 :     case 0x9: {
+     493                 :            :         static size_t sub_index2 = 0;
+     494         [ +  + ]:          2 :         if (sub_index2 == 0) {
+     495                 :            :             spdm_error_response_data_response_not_ready_t
+     496                 :            :             *spdm_response;
+     497                 :            :             size_t spdm_response_size;
+     498                 :            :             size_t transport_header_size;
+     499                 :            :             uint32_t session_id;
+     500                 :            :             libspdm_session_info_t *session_info;
+     501                 :            :             uint8_t *scratch_buffer;
+     502                 :            :             size_t scratch_buffer_size;
+     503                 :            : 
+     504                 :          1 :             spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
+     505                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     506                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     507                 :            : 
+     508                 :          1 :             session_id = 0xFFFFFFFF;
+     509                 :          1 :             spdm_response->header.spdm_version =
+     510                 :            :                 SPDM_MESSAGE_VERSION_11;
+     511                 :          1 :             spdm_response->header.request_response_code = SPDM_ERROR;
+     512                 :          1 :             spdm_response->header.param1 =
+     513                 :            :                 SPDM_ERROR_CODE_RESPONSE_NOT_READY;
+     514                 :          1 :             spdm_response->header.param2 = 0;
+     515                 :          1 :             spdm_response->extend_error_data.rd_exponent = 1;
+     516                 :          1 :             spdm_response->extend_error_data.rd_tm = 2;
+     517                 :          1 :             spdm_response->extend_error_data.request_code =
+     518                 :            :                 SPDM_PSK_FINISH;
+     519                 :          1 :             spdm_response->extend_error_data.token = 1;
+     520                 :            : 
+     521                 :            :             /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+     522                 :            :              * transport_message is always in sender buffer. */
+     523                 :          1 :             libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+     524                 :            :                                         &scratch_buffer_size);
+     525                 :          1 :             libspdm_copy_mem (scratch_buffer + transport_header_size,
+     526                 :            :                               scratch_buffer_size - transport_header_size,
+     527                 :            :                               spdm_response, spdm_response_size);
+     528                 :          1 :             spdm_response = (void *)(scratch_buffer + transport_header_size);
+     529                 :          1 :             libspdm_transport_test_encode_message(
+     530                 :            :                 spdm_context, &session_id, false, false,
+     531                 :            :                 spdm_response_size, spdm_response,
+     532                 :            :                 response_size, response);
+     533                 :          1 :             sub_index2++;
+     534                 :          1 :             session_info = libspdm_get_session_info_via_session_id(
+     535                 :            :                 spdm_context, session_id);
+     536         [ -  + ]:          1 :             if (session_info == NULL) {
+     537                 :          0 :                 return LIBSPDM_STATUS_RECEIVE_FAIL;
+     538                 :            :             }
+     539                 :            :             ((libspdm_secured_message_context_t
+     540                 :          1 :               *)(session_info->secured_message_context))
+     541                 :            :             ->handshake_secret
+     542                 :          1 :             .response_handshake_sequence_number--;
+     543         [ +  - ]:          1 :         } else if (sub_index2 == 1) {
+     544                 :            :             spdm_psk_finish_response_t *spdm_response;
+     545                 :            :             size_t spdm_response_size;
+     546                 :            :             size_t transport_header_size;
+     547                 :            :             uint32_t session_id;
+     548                 :            :             libspdm_session_info_t *session_info;
+     549                 :            :             uint8_t *scratch_buffer;
+     550                 :            :             size_t scratch_buffer_size;
+     551                 :            : 
+     552                 :          1 :             session_id = 0xFFFFFFFF;
+     553                 :          1 :             spdm_response_size = sizeof(spdm_psk_finish_response_t);
+     554                 :          1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     555                 :          1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     556                 :            : 
+     557                 :          1 :             spdm_response->header.spdm_version =
+     558                 :            :                 SPDM_MESSAGE_VERSION_11;
+     559                 :          1 :             spdm_response->header.request_response_code =
+     560                 :            :                 SPDM_PSK_FINISH_RSP;
+     561                 :          1 :             spdm_response->header.param1 = 0;
+     562                 :          1 :             spdm_response->header.param2 = 0;
+     563                 :            : 
+     564                 :            :             /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+     565                 :            :              * transport_message is always in sender buffer. */
+     566                 :          1 :             libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+     567                 :            :                                         &scratch_buffer_size);
+     568                 :          1 :             libspdm_copy_mem (scratch_buffer + transport_header_size,
+     569                 :            :                               scratch_buffer_size - transport_header_size,
+     570                 :            :                               spdm_response, spdm_response_size);
+     571                 :          1 :             spdm_response = (void *)(scratch_buffer + transport_header_size);
+     572                 :          1 :             libspdm_transport_test_encode_message(
+     573                 :            :                 spdm_context, &session_id, false, false,
+     574                 :            :                 spdm_response_size, spdm_response, response_size,
+     575                 :            :                 response);
+     576                 :          1 :             session_info = libspdm_get_session_info_via_session_id(
+     577                 :            :                 spdm_context, session_id);
+     578         [ -  + ]:          1 :             if (session_info == NULL) {
+     579                 :          0 :                 return LIBSPDM_STATUS_RECEIVE_FAIL;
+     580                 :            :             }
+     581                 :            :             ((libspdm_secured_message_context_t
+     582                 :          1 :               *)(session_info->secured_message_context))
+     583                 :            :             ->handshake_secret
+     584                 :          1 :             .response_handshake_sequence_number--;
+     585                 :            :         }
+     586                 :            :     }
+     587                 :          2 :         return LIBSPDM_STATUS_SUCCESS;
+     588                 :            : 
+     589                 :         18 :     case 0xA:
+     590                 :            :     {
+     591                 :            :         static uint16_t error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
+     592                 :            : 
+     593                 :            :         spdm_error_response_t *spdm_response;
+     594                 :            :         size_t spdm_response_size;
+     595                 :            :         size_t transport_header_size;
+     596                 :            :         uint32_t session_id;
+     597                 :            :         libspdm_session_info_t      *session_info;
+     598                 :            :         uint8_t *scratch_buffer;
+     599                 :            :         size_t scratch_buffer_size;
+     600                 :            : 
+     601                 :         18 :         session_id = 0xFFFFFFFF;
+     602                 :            : 
+     603                 :         18 :         spdm_response_size = sizeof(spdm_error_response_t);
+     604                 :         18 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     605                 :         18 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     606                 :            : 
+     607         [ +  - ]:         18 :         if(error_code <= 0xff) {
+     608                 :         18 :             libspdm_zero_mem (spdm_response, spdm_response_size);
+     609                 :         18 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     610                 :         18 :             spdm_response->header.request_response_code = SPDM_ERROR;
+     611                 :         18 :             spdm_response->header.param1 = (uint8_t) error_code;
+     612                 :         18 :             spdm_response->header.param2 = 0;
+     613                 :            : 
+     614                 :            :             /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+     615                 :            :              * transport_message is always in sender buffer. */
+     616                 :         18 :             libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer,
+     617                 :            :                                         &scratch_buffer_size);
+     618                 :         18 :             libspdm_copy_mem (scratch_buffer + transport_header_size,
+     619                 :            :                               scratch_buffer_size - transport_header_size,
+     620                 :            :                               spdm_response, spdm_response_size);
+     621                 :         18 :             spdm_response = (void *)(scratch_buffer + transport_header_size);
+     622                 :         18 :             libspdm_transport_test_encode_message (spdm_context, &session_id, false, false,
+     623                 :            :                                                    spdm_response_size, spdm_response,
+     624                 :            :                                                    response_size, response);
+     625                 :         18 :             session_info = libspdm_get_session_info_via_session_id (spdm_context, session_id);
+     626                 :         18 :             ((libspdm_secured_message_context_t*)(session_info->secured_message_context))->
+     627                 :         18 :             handshake_secret.response_handshake_sequence_number--;
+     628                 :            :         }
+     629                 :            : 
+     630                 :         18 :         error_code++;
+     631         [ +  + ]:         18 :         if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
+     632                 :          1 :             error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
+     633                 :            :         }
+     634         [ +  + ]:         18 :         if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) { /*skip some reserved error codes (0d to 3e)*/
+     635                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
+     636                 :            :         }
+     637         [ +  + ]:         18 :         if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) { /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
+     638                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
+     639                 :            :         }
+     640                 :            :     }
+     641                 :         18 :         return LIBSPDM_STATUS_SUCCESS;
+     642                 :          1 :     case 0xB: {
+     643                 :            :         spdm_psk_finish_response_t *spdm_response;
+     644                 :            :         size_t spdm_response_size;
+     645                 :            :         size_t transport_header_size;
+     646                 :            :         uint32_t session_id;
+     647                 :            :         libspdm_session_info_t *session_info;
+     648                 :            :         uint8_t *scratch_buffer;
+     649                 :            :         size_t scratch_buffer_size;
+     650                 :            : 
+     651                 :          1 :         session_id = 0xFFFFFFFF;
+     652                 :          1 :         spdm_response_size = sizeof(spdm_psk_finish_response_t);
+     653                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     654                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     655                 :            : 
+     656                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     657                 :          1 :         spdm_response->header.request_response_code =
+     658                 :            :             SPDM_PSK_FINISH_RSP;
+     659                 :          1 :         spdm_response->header.param1 = 0;
+     660                 :          1 :         spdm_response->header.param2 = 0;
+     661                 :            : 
+     662                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+     663                 :            :          * transport_message is always in sender buffer. */
+     664                 :          1 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+     665                 :          1 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+     666                 :            :                           scratch_buffer_size - transport_header_size,
+     667                 :            :                           spdm_response, spdm_response_size);
+     668                 :          1 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+     669                 :          1 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+     670                 :            :                                               false, false, spdm_response_size,
+     671                 :            :                                               spdm_response, response_size,
+     672                 :            :                                               response);
+     673                 :          1 :         session_info = libspdm_get_session_info_via_session_id(
+     674                 :            :             spdm_context, session_id);
+     675         [ -  + ]:          1 :         if (session_info == NULL) {
+     676                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+     677                 :            :         }
+     678                 :            :         /* WALKAROUND: If just use single context to encode message and then decode message */
+     679                 :            :         ((libspdm_secured_message_context_t
+     680                 :          1 :           *)(session_info->secured_message_context))
+     681                 :          1 :         ->handshake_secret.response_handshake_sequence_number--;
+     682                 :            :     }
+     683                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     684                 :            : 
+     685                 :          0 :     case 0xC: {
+     686                 :            :         spdm_psk_finish_response_t *spdm_response;
+     687                 :            :         size_t spdm_response_size;
+     688                 :            :         size_t transport_header_size;
+     689                 :            :         uint32_t session_id;
+     690                 :            :         libspdm_session_info_t *session_info;
+     691                 :            :         uint8_t *scratch_buffer;
+     692                 :            :         size_t scratch_buffer_size;
+     693                 :            : 
+     694                 :          0 :         session_id = 0xFFFFFFFF;
+     695                 :          0 :         spdm_response_size = sizeof(spdm_psk_finish_response_t);
+     696                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     697                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     698                 :            : 
+     699                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     700                 :          0 :         spdm_response->header.request_response_code =
+     701                 :            :             SPDM_PSK_FINISH_RSP;
+     702                 :          0 :         spdm_response->header.param1 = 0;
+     703                 :          0 :         spdm_response->header.param2 = 0;
+     704                 :            : 
+     705                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+     706                 :            :          * transport_message is always in sender buffer. */
+     707                 :          0 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+     708                 :          0 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+     709                 :            :                           scratch_buffer_size - transport_header_size,
+     710                 :            :                           spdm_response, spdm_response_size);
+     711                 :          0 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+     712                 :          0 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+     713                 :            :                                               false, false, spdm_response_size,
+     714                 :            :                                               spdm_response, response_size,
+     715                 :            :                                               response);
+     716                 :          0 :         session_info = libspdm_get_session_info_via_session_id(
+     717                 :            :             spdm_context, session_id);
+     718         [ #  # ]:          0 :         if (session_info == NULL) {
+     719                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+     720                 :            :         }
+     721                 :            :         /* WALKAROUND: If just use single context to encode message and then decode message */
+     722                 :            :         ((libspdm_secured_message_context_t
+     723                 :          0 :           *)(session_info->secured_message_context))
+     724                 :          0 :         ->handshake_secret.response_handshake_sequence_number--;
+     725                 :            :     }
+     726                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     727                 :            : 
+     728                 :          1 :     case 0xD: {
+     729                 :            :         spdm_psk_finish_response_t *spdm_response;
+     730                 :            :         size_t spdm_response_size;
+     731                 :            :         size_t transport_header_size;
+     732                 :            :         uint32_t session_id;
+     733                 :            :         libspdm_session_info_t *session_info;
+     734                 :            :         uint8_t *scratch_buffer;
+     735                 :            :         size_t scratch_buffer_size;
+     736                 :            : 
+     737                 :          1 :         session_id = 0xFFFFFFFF;
+     738                 :          1 :         spdm_response_size = sizeof(spdm_psk_finish_response_t);
+     739                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     740                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     741                 :            : 
+     742                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     743                 :          1 :         spdm_response->header.request_response_code =
+     744                 :            :             SPDM_FINISH_RSP; /*wrong response code*/
+     745                 :          1 :         spdm_response->header.param1 = 0;
+     746                 :          1 :         spdm_response->header.param2 = 0;
+     747                 :            : 
+     748                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+     749                 :            :          * transport_message is always in sender buffer. */
+     750                 :          1 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+     751                 :          1 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+     752                 :            :                           scratch_buffer_size - transport_header_size,
+     753                 :            :                           spdm_response, spdm_response_size);
+     754                 :          1 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+     755                 :          1 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+     756                 :            :                                               false, false, spdm_response_size,
+     757                 :            :                                               spdm_response, response_size,
+     758                 :            :                                               response);
+     759                 :          1 :         session_info = libspdm_get_session_info_via_session_id(
+     760                 :            :             spdm_context, session_id);
+     761         [ -  + ]:          1 :         if (session_info == NULL) {
+     762                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+     763                 :            :         }
+     764                 :            :         /* WALKAROUND: If just use single context to encode message and then decode message */
+     765                 :            :         ((libspdm_secured_message_context_t
+     766                 :          1 :           *)(session_info->secured_message_context))
+     767                 :          1 :         ->handshake_secret.response_handshake_sequence_number--;
+     768                 :            :     }
+     769                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     770                 :            : 
+     771                 :          0 :     case 0xE: {
+     772                 :            :         spdm_psk_finish_response_t *spdm_response;
+     773                 :            :         size_t spdm_response_size;
+     774                 :            :         size_t transport_header_size;
+     775                 :            :         uint32_t session_id;
+     776                 :            :         libspdm_session_info_t *session_info;
+     777                 :            :         uint8_t *scratch_buffer;
+     778                 :            :         size_t scratch_buffer_size;
+     779                 :            : 
+     780                 :          0 :         session_id = 0xFFFFFFFF;
+     781                 :          0 :         spdm_response_size = sizeof(spdm_psk_finish_response_t);
+     782                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     783                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     784                 :            : 
+     785                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     786                 :          0 :         spdm_response->header.request_response_code =
+     787                 :            :             SPDM_PSK_FINISH_RSP;
+     788                 :          0 :         spdm_response->header.param1 = 0;
+     789                 :          0 :         spdm_response->header.param2 = 0;
+     790                 :            : 
+     791                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+     792                 :            :          * transport_message is always in sender buffer. */
+     793                 :          0 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+     794                 :          0 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+     795                 :            :                           scratch_buffer_size - transport_header_size,
+     796                 :            :                           spdm_response, spdm_response_size);
+     797                 :          0 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+     798                 :          0 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+     799                 :            :                                               false, false, spdm_response_size,
+     800                 :            :                                               spdm_response, response_size,
+     801                 :            :                                               response);
+     802                 :          0 :         session_info = libspdm_get_session_info_via_session_id(
+     803                 :            :             spdm_context, session_id);
+     804         [ #  # ]:          0 :         if (session_info == NULL) {
+     805                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+     806                 :            :         }
+     807                 :            :         /* WALKAROUND: If just use single context to encode message and then decode message */
+     808                 :            :         ((libspdm_secured_message_context_t
+     809                 :          0 :           *)(session_info->secured_message_context))
+     810                 :          0 :         ->handshake_secret.response_handshake_sequence_number--;
+     811                 :            :     }
+     812                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     813                 :            : 
+     814                 :          1 :     case 0xF: {
+     815                 :            :         spdm_error_response_t *spdm_response;
+     816                 :            :         size_t spdm_response_size;
+     817                 :            :         size_t transport_header_size;
+     818                 :            :         uint32_t session_id;
+     819                 :            :         libspdm_session_info_t *session_info;
+     820                 :            :         uint8_t *scratch_buffer;
+     821                 :            :         size_t scratch_buffer_size;
+     822                 :            : 
+     823                 :          1 :         session_id = 0xFFFFFFFF;
+     824                 :            : 
+     825                 :          1 :         spdm_response_size = sizeof(spdm_error_response_t);
+     826                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     827                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     828                 :            : 
+     829                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     830                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     831                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_DECRYPT_ERROR;
+     832                 :          1 :         spdm_response->header.param2 = 0;
+     833                 :            : 
+     834                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+     835                 :            :          * transport_message is always in sender buffer. */
+     836                 :          1 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+     837                 :          1 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+     838                 :            :                           scratch_buffer_size - transport_header_size,
+     839                 :            :                           spdm_response, spdm_response_size);
+     840                 :          1 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+     841                 :          1 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+     842                 :            :                                               false, false,
+     843                 :            :                                               spdm_response_size,
+     844                 :            :                                               spdm_response,
+     845                 :            :                                               response_size, response);
+     846                 :          1 :         session_info = libspdm_get_session_info_via_session_id(
+     847                 :            :             spdm_context, session_id);
+     848         [ -  + ]:          1 :         if (session_info == NULL) {
+     849                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+     850                 :            :         }
+     851                 :            :         ((libspdm_secured_message_context_t
+     852                 :          1 :           *)(session_info->secured_message_context))
+     853                 :          1 :         ->handshake_secret.response_handshake_sequence_number--;
+     854                 :            :     }
+     855                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     856                 :            : 
+     857                 :          1 :     case 0x10: {
+     858                 :            :         spdm_psk_finish_response_t *spdm_response;
+     859                 :            :         size_t spdm_response_size;
+     860                 :            :         size_t transport_header_size;
+     861                 :            :         uint32_t session_id;
+     862                 :            :         libspdm_session_info_t *session_info;
+     863                 :            :         uint8_t *scratch_buffer;
+     864                 :            :         size_t scratch_buffer_size;
+     865                 :            : 
+     866                 :          1 :         session_id = 0xFFFFFFFF;
+     867                 :          1 :         spdm_response_size = sizeof(spdm_psk_finish_response_t);
+     868                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     869                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     870                 :            : 
+     871                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     872                 :          1 :         spdm_response->header.request_response_code =
+     873                 :            :             SPDM_PSK_FINISH_RSP;
+     874                 :          1 :         spdm_response->header.param1 = 0;
+     875                 :          1 :         spdm_response->header.param2 = 0;
+     876                 :            : 
+     877                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+     878                 :            :          * transport_message is always in sender buffer. */
+     879                 :          1 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+     880                 :          1 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+     881                 :            :                           scratch_buffer_size - transport_header_size,
+     882                 :            :                           spdm_response, spdm_response_size);
+     883                 :          1 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+     884                 :            : 
+     885                 :          1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
+     886                 :            :                          sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
+     887                 :            :                          spdm_response, spdm_response_size);
+     888                 :          1 :         m_libspdm_local_buffer_size += spdm_response_size;
+     889                 :            : 
+     890                 :          1 :         libspdm_transport_test_encode_message(spdm_context, &session_id,
+     891                 :            :                                               false, false, spdm_response_size,
+     892                 :            :                                               spdm_response, response_size,
+     893                 :            :                                               response);
+     894                 :          1 :         session_info = libspdm_get_session_info_via_session_id(spdm_context, session_id);
+     895         [ -  + ]:          1 :         if (session_info == NULL) {
+     896                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+     897                 :            :         }
+     898                 :            :         /* WALKAROUND: If just use single context to encode message and then decode message */
+     899                 :          1 :         ((libspdm_secured_message_context_t*)(session_info->secured_message_context))
+     900                 :          1 :         ->handshake_secret.response_handshake_sequence_number--;
+     901                 :            :     }
+     902                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     903                 :            : 
+     904                 :          0 :     default:
+     905                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+     906                 :            :     }
+     907                 :            : }
+     908                 :            : 
+     909                 :            : /**
+     910                 :            :  * Test 1: when no PSK_FINISH_RSP message is received, and the client returns
+     911                 :            :  * a device error.
+     912                 :            :  * Expected behavior: client returns a Status of RETURN_DEVICE_ERROR.
+     913                 :            :  **/
+     914                 :          1 : void libspdm_test_requester_psk_finish_case1(void **state)
+     915                 :            : {
+     916                 :            :     libspdm_return_t status;
+     917                 :            :     libspdm_test_context_t *spdm_test_context;
+     918                 :            :     libspdm_context_t *spdm_context;
+     919                 :            :     uint32_t session_id;
+     920                 :            :     void *data;
+     921                 :            :     size_t data_size;
+     922                 :            :     void *hash;
+     923                 :            :     size_t hash_size;
+     924                 :            :     libspdm_session_info_t *session_info;
+     925                 :            : 
+     926                 :          1 :     spdm_test_context = *state;
+     927                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     928                 :          1 :     spdm_test_context->case_id = 0x1;
+     929                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     930                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     931                 :          1 :     spdm_context->connection_info.connection_state =
+     932                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     933                 :          1 :     spdm_context->connection_info.capability.flags |=
+     934                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     935                 :          1 :     spdm_context->connection_info.capability.flags |=
+     936                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+     937                 :          1 :     spdm_context->connection_info.capability.flags |=
+     938                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+     939                 :          1 :     spdm_context->local_context.capability.flags |=
+     940                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     941                 :          1 :     spdm_context->local_context.capability.flags |=
+     942                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+     943                 :          1 :     spdm_context->local_context.capability.flags |=
+     944                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+     945                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     946                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     947                 :            :                                                     &data_size, &hash, &hash_size);
+     948                 :          1 :     libspdm_reset_message_a(spdm_context);
+     949                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     950                 :            :         m_libspdm_use_hash_algo;
+     951                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     952                 :            :         m_libspdm_use_asym_algo;
+     953                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     954                 :            :         m_libspdm_use_dhe_algo;
+     955                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     956                 :            :         m_libspdm_use_aead_algo;
+     957                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     958                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+     959                 :            :         data_size;
+     960                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+     961                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+     962                 :            :                      data, data_size);
+     963                 :            : #endif
+     964                 :            : 
+     965                 :          1 :     session_id = 0xFFFFFFFF;
+     966                 :          1 :     session_info = &spdm_context->session_info[0];
+     967                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+     968                 :          1 :     libspdm_session_info_set_psk_hint(session_info,
+     969                 :            :                                       LIBSPDM_TEST_PSK_HINT_STRING,
+     970                 :            :                                       sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+     971                 :          1 :     libspdm_secured_message_set_session_state(
+     972                 :            :         session_info->secured_message_context,
+     973                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+     974                 :          1 :     libspdm_secured_message_set_dummy_finished_key (session_info->secured_message_context);
+     975                 :            : 
+     976                 :          1 :     status = libspdm_send_receive_psk_finish(spdm_context, session_id);
+     977                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SEND_FAIL);
+     978                 :          1 :     free(data);
+     979                 :          1 : }
+     980                 :            : 
+     981                 :            : /**
+     982                 :            :  * Test 2: receiving a correct PSK_FINISH_RSP message.
+     983                 :            :  * Expected behavior: client returns a Status of RETURN_SUCCESS and
+     984                 :            :  * session is established.
+     985                 :            :  **/
+     986                 :          1 : void libspdm_test_requester_psk_finish_case2(void **state)
+     987                 :            : {
+     988                 :            :     libspdm_return_t status;
+     989                 :            :     libspdm_test_context_t *spdm_test_context;
+     990                 :            :     libspdm_context_t *spdm_context;
+     991                 :            :     uint32_t session_id;
+     992                 :            :     void *data;
+     993                 :            :     size_t data_size;
+     994                 :            :     void *hash;
+     995                 :            :     size_t hash_size;
+     996                 :            :     libspdm_session_info_t *session_info;
+     997                 :            : 
+     998                 :          1 :     spdm_test_context = *state;
+     999                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1000                 :          1 :     spdm_test_context->case_id = 0x2;
+    1001                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1002                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1003                 :          1 :     spdm_context->connection_info.connection_state =
+    1004                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1005                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1006                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1007                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1008                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    1009                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1010                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    1011                 :          1 :     spdm_context->local_context.capability.flags |=
+    1012                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1013                 :          1 :     spdm_context->local_context.capability.flags |=
+    1014                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    1015                 :          1 :     spdm_context->local_context.capability.flags |=
+    1016                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    1017                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1018                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    1019                 :            :                                                     &data_size, &hash, &hash_size);
+    1020                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1021                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1022                 :            :         m_libspdm_use_hash_algo;
+    1023                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1024                 :            :         m_libspdm_use_asym_algo;
+    1025                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1026                 :            :         m_libspdm_use_dhe_algo;
+    1027                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1028                 :            :         m_libspdm_use_aead_algo;
+    1029                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1030                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    1031                 :            :         data_size;
+    1032                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    1033                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    1034                 :            :                      data, data_size);
+    1035                 :            : #endif
+    1036                 :            : 
+    1037                 :          1 :     session_id = 0xFFFFFFFF;
+    1038                 :          1 :     session_info = &spdm_context->session_info[0];
+    1039                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+    1040                 :          1 :     libspdm_session_info_set_psk_hint(session_info,
+    1041                 :            :                                       LIBSPDM_TEST_PSK_HINT_STRING,
+    1042                 :            :                                       sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+    1043                 :          1 :     libspdm_secured_message_set_session_state(
+    1044                 :            :         session_info->secured_message_context,
+    1045                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    1046                 :          1 :     libspdm_set_mem(m_libspdm_dummy_key_buffer,
+    1047                 :            :                     ((libspdm_secured_message_context_t
+    1048                 :          1 :                       *)(session_info->secured_message_context))
+    1049                 :            :                     ->aead_key_size,
+    1050                 :            :                     (uint8_t)(0xFF));
+    1051                 :          1 :     libspdm_secured_message_set_response_handshake_encryption_key(
+    1052                 :            :         session_info->secured_message_context, m_libspdm_dummy_key_buffer,
+    1053                 :            :         ((libspdm_secured_message_context_t
+    1054                 :          1 :           *)(session_info->secured_message_context))
+    1055                 :            :         ->aead_key_size);
+    1056                 :          1 :     libspdm_set_mem(m_libspdm_dummy_salt_buffer,
+    1057                 :            :                     ((libspdm_secured_message_context_t
+    1058                 :          1 :                       *)(session_info->secured_message_context))
+    1059                 :            :                     ->aead_iv_size,
+    1060                 :            :                     (uint8_t)(0xFF));
+    1061                 :          1 :     libspdm_secured_message_set_response_handshake_salt(
+    1062                 :            :         session_info->secured_message_context, m_libspdm_dummy_salt_buffer,
+    1063                 :            :         ((libspdm_secured_message_context_t
+    1064                 :          1 :           *)(session_info->secured_message_context))
+    1065                 :            :         ->aead_iv_size);
+    1066                 :            :     ((libspdm_secured_message_context_t *)(session_info
+    1067                 :          1 :                                            ->secured_message_context))
+    1068                 :          1 :     ->handshake_secret.response_handshake_sequence_number = 0;
+    1069                 :          1 :     libspdm_secured_message_set_dummy_finished_key (session_info->secured_message_context);
+    1070                 :            : 
+    1071                 :          1 :     status = libspdm_send_receive_psk_finish(spdm_context, session_id);
+    1072                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1073                 :          1 :     assert_int_equal(
+    1074                 :            :         libspdm_secured_message_get_session_state(
+    1075                 :            :             spdm_context->session_info[0].secured_message_context),
+    1076                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+    1077                 :          1 :     free(data);
+    1078                 :          1 : }
+    1079                 :            : 
+    1080                 :            : /**
+    1081                 :            :  * Test 3: requester state has not been negotiated, as if GET_VERSION,
+    1082                 :            :  * GET_CAPABILITIES and NEGOTIATE_ALGORITHMS had not been exchanged.
+    1083                 :            :  * Expected behavior: client returns a Status of RETURN_UNSUPPORTED.
+    1084                 :            :  **/
+    1085                 :          1 : void libspdm_test_requester_psk_finish_case3(void **state)
+    1086                 :            : {
+    1087                 :            :     libspdm_return_t status;
+    1088                 :            :     libspdm_test_context_t *spdm_test_context;
+    1089                 :            :     libspdm_context_t *spdm_context;
+    1090                 :            :     uint32_t session_id;
+    1091                 :            :     void *data;
+    1092                 :            :     size_t data_size;
+    1093                 :            :     void *hash;
+    1094                 :            :     size_t hash_size;
+    1095                 :            :     libspdm_session_info_t *session_info;
+    1096                 :            : 
+    1097                 :          1 :     spdm_test_context = *state;
+    1098                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1099                 :          1 :     spdm_test_context->case_id = 0x3;
+    1100                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1101                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1102                 :          1 :     spdm_context->connection_info.connection_state =
+    1103                 :            :         LIBSPDM_CONNECTION_STATE_NOT_STARTED;
+    1104                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1105                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1106                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1107                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    1108                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1109                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    1110                 :          1 :     spdm_context->local_context.capability.flags |=
+    1111                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1112                 :          1 :     spdm_context->local_context.capability.flags |=
+    1113                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    1114                 :          1 :     spdm_context->local_context.capability.flags |=
+    1115                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    1116                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1117                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    1118                 :            :                                                     &data_size, &hash, &hash_size);
+    1119                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1120                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1121                 :            :         m_libspdm_use_hash_algo;
+    1122                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1123                 :            :         m_libspdm_use_asym_algo;
+    1124                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1125                 :            :         m_libspdm_use_dhe_algo;
+    1126                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1127                 :            :         m_libspdm_use_aead_algo;
+    1128                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1129                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    1130                 :            :         data_size;
+    1131                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    1132                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    1133                 :            :                      data, data_size);
+    1134                 :            : #endif
+    1135                 :            : 
+    1136                 :          1 :     session_id = 0xFFFFFFFF;
+    1137                 :          1 :     session_info = &spdm_context->session_info[0];
+    1138                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+    1139                 :          1 :     libspdm_session_info_set_psk_hint(session_info,
+    1140                 :            :                                       LIBSPDM_TEST_PSK_HINT_STRING,
+    1141                 :            :                                       sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+    1142                 :          1 :     libspdm_secured_message_set_session_state(
+    1143                 :            :         session_info->secured_message_context,
+    1144                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    1145                 :          1 :     libspdm_set_mem(m_libspdm_dummy_key_buffer,
+    1146                 :            :                     ((libspdm_secured_message_context_t
+    1147                 :          1 :                       *)(session_info->secured_message_context))
+    1148                 :            :                     ->aead_key_size,
+    1149                 :            :                     (uint8_t)(0xFF));
+    1150                 :          1 :     libspdm_secured_message_set_response_handshake_encryption_key(
+    1151                 :            :         session_info->secured_message_context, m_libspdm_dummy_key_buffer,
+    1152                 :            :         ((libspdm_secured_message_context_t
+    1153                 :          1 :           *)(session_info->secured_message_context))
+    1154                 :            :         ->aead_key_size);
+    1155                 :          1 :     libspdm_set_mem(m_libspdm_dummy_salt_buffer,
+    1156                 :            :                     ((libspdm_secured_message_context_t
+    1157                 :          1 :                       *)(session_info->secured_message_context))
+    1158                 :            :                     ->aead_iv_size,
+    1159                 :            :                     (uint8_t)(0xFF));
+    1160                 :          1 :     libspdm_secured_message_set_response_handshake_salt(
+    1161                 :            :         session_info->secured_message_context, m_libspdm_dummy_salt_buffer,
+    1162                 :            :         ((libspdm_secured_message_context_t
+    1163                 :          1 :           *)(session_info->secured_message_context))
+    1164                 :            :         ->aead_iv_size);
+    1165                 :            :     ((libspdm_secured_message_context_t *)(session_info
+    1166                 :          1 :                                            ->secured_message_context))
+    1167                 :          1 :     ->handshake_secret.response_handshake_sequence_number = 0;
+    1168                 :          1 :     libspdm_secured_message_set_dummy_finished_key (session_info->secured_message_context);
+    1169                 :            : 
+    1170                 :          1 :     status = libspdm_send_receive_psk_finish(spdm_context, session_id);
+    1171                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_STATE_LOCAL);
+    1172                 :          1 :     free(data);
+    1173                 :          1 : }
+    1174                 :            : 
+    1175                 :            : /**
+    1176                 :            :  * Test 4: the requester is setup correctly, but receives an ERROR message
+    1177                 :            :  * indicating InvalidParameters.
+    1178                 :            :  * Expected behavior: client returns a Status of RETURN_DEVICE_ERROR.
+    1179                 :            :  **/
+    1180                 :          1 : void libspdm_test_requester_psk_finish_case4(void **state)
+    1181                 :            : {
+    1182                 :            :     libspdm_return_t status;
+    1183                 :            :     libspdm_test_context_t *spdm_test_context;
+    1184                 :            :     libspdm_context_t *spdm_context;
+    1185                 :            :     uint32_t session_id;
+    1186                 :            :     void *data;
+    1187                 :            :     size_t data_size;
+    1188                 :            :     void *hash;
+    1189                 :            :     size_t hash_size;
+    1190                 :            :     libspdm_session_info_t *session_info;
+    1191                 :            : 
+    1192                 :          1 :     spdm_test_context = *state;
+    1193                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1194                 :          1 :     spdm_test_context->case_id = 0x4;
+    1195                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1196                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1197                 :          1 :     spdm_context->connection_info.connection_state =
+    1198                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1199                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1200                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1201                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1202                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    1203                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1204                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    1205                 :          1 :     spdm_context->local_context.capability.flags |=
+    1206                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1207                 :          1 :     spdm_context->local_context.capability.flags |=
+    1208                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    1209                 :          1 :     spdm_context->local_context.capability.flags |=
+    1210                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    1211                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1212                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    1213                 :            :                                                     &data_size, &hash, &hash_size);
+    1214                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1215                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1216                 :            :         m_libspdm_use_hash_algo;
+    1217                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1218                 :            :         m_libspdm_use_asym_algo;
+    1219                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1220                 :            :         m_libspdm_use_dhe_algo;
+    1221                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1222                 :            :         m_libspdm_use_aead_algo;
+    1223                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1224                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    1225                 :            :         data_size;
+    1226                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    1227                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    1228                 :            :                      data, data_size);
+    1229                 :            : #endif
+    1230                 :            : 
+    1231                 :          1 :     session_id = 0xFFFFFFFF;
+    1232                 :          1 :     session_info = &spdm_context->session_info[0];
+    1233                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+    1234                 :          1 :     libspdm_session_info_set_psk_hint(session_info,
+    1235                 :            :                                       LIBSPDM_TEST_PSK_HINT_STRING,
+    1236                 :            :                                       sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+    1237                 :          1 :     libspdm_secured_message_set_session_state(
+    1238                 :            :         session_info->secured_message_context,
+    1239                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    1240                 :          1 :     libspdm_set_mem(m_libspdm_dummy_key_buffer,
+    1241                 :            :                     ((libspdm_secured_message_context_t
+    1242                 :          1 :                       *)(session_info->secured_message_context))
+    1243                 :            :                     ->aead_key_size,
+    1244                 :            :                     (uint8_t)(0xFF));
+    1245                 :          1 :     libspdm_secured_message_set_response_handshake_encryption_key(
+    1246                 :            :         session_info->secured_message_context, m_libspdm_dummy_key_buffer,
+    1247                 :            :         ((libspdm_secured_message_context_t
+    1248                 :          1 :           *)(session_info->secured_message_context))
+    1249                 :            :         ->aead_key_size);
+    1250                 :          1 :     libspdm_set_mem(m_libspdm_dummy_salt_buffer,
+    1251                 :            :                     ((libspdm_secured_message_context_t
+    1252                 :          1 :                       *)(session_info->secured_message_context))
+    1253                 :            :                     ->aead_iv_size,
+    1254                 :            :                     (uint8_t)(0xFF));
+    1255                 :          1 :     libspdm_secured_message_set_response_handshake_salt(
+    1256                 :            :         session_info->secured_message_context, m_libspdm_dummy_salt_buffer,
+    1257                 :            :         ((libspdm_secured_message_context_t
+    1258                 :          1 :           *)(session_info->secured_message_context))
+    1259                 :            :         ->aead_iv_size);
+    1260                 :            :     ((libspdm_secured_message_context_t *)(session_info
+    1261                 :          1 :                                            ->secured_message_context))
+    1262                 :          1 :     ->handshake_secret.response_handshake_sequence_number = 0;
+    1263                 :          1 :     libspdm_secured_message_set_dummy_finished_key (session_info->secured_message_context);
+    1264                 :            : 
+    1265                 :          1 :     status = libspdm_send_receive_psk_finish(spdm_context, session_id);
+    1266                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_ERROR_PEER);
+    1267                 :          1 :     assert_int_equal(spdm_context->session_info->session_id, INVALID_SESSION_ID);
+    1268                 :          1 :     free(data);
+    1269                 :          1 : }
+    1270                 :            : 
+    1271                 :            : /**
+    1272                 :            :  * Test 5: the requester is setup correctly, but receives an ERROR message
+    1273                 :            :  * indicating the Busy status of the responder.
+    1274                 :            :  * Expected behavior: client returns a Status of RETURN_DEVICE_ERROR.
+    1275                 :            :  **/
+    1276                 :          1 : void libspdm_test_requester_psk_finish_case5(void **state)
+    1277                 :            : {
+    1278                 :            :     libspdm_return_t status;
+    1279                 :            :     libspdm_test_context_t *spdm_test_context;
+    1280                 :            :     libspdm_context_t *spdm_context;
+    1281                 :            :     uint32_t session_id;
+    1282                 :            :     void *data;
+    1283                 :            :     size_t data_size;
+    1284                 :            :     void *hash;
+    1285                 :            :     size_t hash_size;
+    1286                 :            :     libspdm_session_info_t *session_info;
+    1287                 :            : 
+    1288                 :          1 :     spdm_test_context = *state;
+    1289                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1290                 :          1 :     spdm_test_context->case_id = 0x5;
+    1291                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1292                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1293                 :          1 :     spdm_context->connection_info.connection_state =
+    1294                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1295                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1296                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1297                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1298                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    1299                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1300                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    1301                 :          1 :     spdm_context->local_context.capability.flags |=
+    1302                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1303                 :          1 :     spdm_context->local_context.capability.flags |=
+    1304                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    1305                 :          1 :     spdm_context->local_context.capability.flags |=
+    1306                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    1307                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1308                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    1309                 :            :                                                     &data_size, &hash, &hash_size);
+    1310                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1311                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1312                 :            :         m_libspdm_use_hash_algo;
+    1313                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1314                 :            :         m_libspdm_use_asym_algo;
+    1315                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1316                 :            :         m_libspdm_use_dhe_algo;
+    1317                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1318                 :            :         m_libspdm_use_aead_algo;
+    1319                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1320                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    1321                 :            :         data_size;
+    1322                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    1323                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    1324                 :            :                      data, data_size);
+    1325                 :            : #endif
+    1326                 :            : 
+    1327                 :          1 :     session_id = 0xFFFFFFFF;
+    1328                 :          1 :     session_info = &spdm_context->session_info[0];
+    1329                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+    1330                 :          1 :     libspdm_session_info_set_psk_hint(session_info,
+    1331                 :            :                                       LIBSPDM_TEST_PSK_HINT_STRING,
+    1332                 :            :                                       sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+    1333                 :          1 :     libspdm_secured_message_set_session_state(
+    1334                 :            :         session_info->secured_message_context,
+    1335                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    1336                 :          1 :     libspdm_set_mem(m_libspdm_dummy_key_buffer,
+    1337                 :            :                     ((libspdm_secured_message_context_t
+    1338                 :          1 :                       *)(session_info->secured_message_context))
+    1339                 :            :                     ->aead_key_size,
+    1340                 :            :                     (uint8_t)(0xFF));
+    1341                 :          1 :     libspdm_secured_message_set_response_handshake_encryption_key(
+    1342                 :            :         session_info->secured_message_context, m_libspdm_dummy_key_buffer,
+    1343                 :            :         ((libspdm_secured_message_context_t
+    1344                 :          1 :           *)(session_info->secured_message_context))
+    1345                 :            :         ->aead_key_size);
+    1346                 :          1 :     libspdm_set_mem(m_libspdm_dummy_salt_buffer,
+    1347                 :            :                     ((libspdm_secured_message_context_t
+    1348                 :          1 :                       *)(session_info->secured_message_context))
+    1349                 :            :                     ->aead_iv_size,
+    1350                 :            :                     (uint8_t)(0xFF));
+    1351                 :          1 :     libspdm_secured_message_set_response_handshake_salt(
+    1352                 :            :         session_info->secured_message_context, m_libspdm_dummy_salt_buffer,
+    1353                 :            :         ((libspdm_secured_message_context_t
+    1354                 :          1 :           *)(session_info->secured_message_context))
+    1355                 :            :         ->aead_iv_size);
+    1356                 :            :     ((libspdm_secured_message_context_t *)(session_info
+    1357                 :          1 :                                            ->secured_message_context))
+    1358                 :          1 :     ->handshake_secret.response_handshake_sequence_number = 0;
+    1359                 :          1 :     libspdm_secured_message_set_dummy_finished_key (session_info->secured_message_context);
+    1360                 :            : 
+    1361                 :          1 :     status = libspdm_send_receive_psk_finish(spdm_context, session_id);
+    1362                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_BUSY_PEER);
+    1363                 :          1 :     free(data);
+    1364                 :          1 : }
+    1365                 :            : 
+    1366                 :            : /**
+    1367                 :            :  * Test 6: the requester is setup correctly, but, on the first try, receiving
+    1368                 :            :  * a Busy ERROR message, and, on retry, receiving a correct PSK_FINISH_RSP
+    1369                 :            :  * message.
+    1370                 :            :  * Expected behavior: client returns a Status of RETURN_SUCCESS and session
+    1371                 :            :  * is established.
+    1372                 :            :  **/
+    1373                 :          1 : void libspdm_test_requester_psk_finish_case6(void **state)
+    1374                 :            : {
+    1375                 :            :     libspdm_return_t status;
+    1376                 :            :     libspdm_test_context_t *spdm_test_context;
+    1377                 :            :     libspdm_context_t *spdm_context;
+    1378                 :            :     uint32_t session_id;
+    1379                 :            :     void *data;
+    1380                 :            :     size_t data_size;
+    1381                 :            :     void *hash;
+    1382                 :            :     size_t hash_size;
+    1383                 :            :     libspdm_session_info_t *session_info;
+    1384                 :            : 
+    1385                 :          1 :     spdm_test_context = *state;
+    1386                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1387                 :          1 :     spdm_test_context->case_id = 0x6;
+    1388                 :          1 :     spdm_context->retry_times = 3;
+    1389                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1390                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1391                 :          1 :     spdm_context->connection_info.connection_state =
+    1392                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1393                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1394                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1395                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1396                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    1397                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1398                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    1399                 :          1 :     spdm_context->local_context.capability.flags |=
+    1400                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1401                 :          1 :     spdm_context->local_context.capability.flags |=
+    1402                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    1403                 :          1 :     spdm_context->local_context.capability.flags |=
+    1404                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    1405                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1406                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    1407                 :            :                                                     &data_size, &hash, &hash_size);
+    1408                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1409                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1410                 :            :         m_libspdm_use_hash_algo;
+    1411                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1412                 :            :         m_libspdm_use_asym_algo;
+    1413                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1414                 :            :         m_libspdm_use_dhe_algo;
+    1415                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1416                 :            :         m_libspdm_use_aead_algo;
+    1417                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1418                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    1419                 :            :         data_size;
+    1420                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    1421                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    1422                 :            :                      data, data_size);
+    1423                 :            : #endif
+    1424                 :            : 
+    1425                 :          1 :     session_id = 0xFFFFFFFF;
+    1426                 :          1 :     session_info = &spdm_context->session_info[0];
+    1427                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+    1428                 :          1 :     libspdm_session_info_set_psk_hint(session_info,
+    1429                 :            :                                       LIBSPDM_TEST_PSK_HINT_STRING,
+    1430                 :            :                                       sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+    1431                 :          1 :     libspdm_secured_message_set_session_state(
+    1432                 :            :         session_info->secured_message_context,
+    1433                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    1434                 :          1 :     libspdm_set_mem(m_libspdm_dummy_key_buffer,
+    1435                 :            :                     ((libspdm_secured_message_context_t
+    1436                 :          1 :                       *)(session_info->secured_message_context))
+    1437                 :            :                     ->aead_key_size,
+    1438                 :            :                     (uint8_t)(0xFF));
+    1439                 :          1 :     libspdm_secured_message_set_response_handshake_encryption_key(
+    1440                 :            :         session_info->secured_message_context, m_libspdm_dummy_key_buffer,
+    1441                 :            :         ((libspdm_secured_message_context_t
+    1442                 :          1 :           *)(session_info->secured_message_context))
+    1443                 :            :         ->aead_key_size);
+    1444                 :          1 :     libspdm_set_mem(m_libspdm_dummy_salt_buffer,
+    1445                 :            :                     ((libspdm_secured_message_context_t
+    1446                 :          1 :                       *)(session_info->secured_message_context))
+    1447                 :            :                     ->aead_iv_size,
+    1448                 :            :                     (uint8_t)(0xFF));
+    1449                 :          1 :     libspdm_secured_message_set_response_handshake_salt(
+    1450                 :            :         session_info->secured_message_context, m_libspdm_dummy_salt_buffer,
+    1451                 :            :         ((libspdm_secured_message_context_t
+    1452                 :          1 :           *)(session_info->secured_message_context))
+    1453                 :            :         ->aead_iv_size);
+    1454                 :            :     ((libspdm_secured_message_context_t *)(session_info
+    1455                 :          1 :                                            ->secured_message_context))
+    1456                 :          1 :     ->handshake_secret.response_handshake_sequence_number = 0;
+    1457                 :          1 :     libspdm_secured_message_set_dummy_finished_key (session_info->secured_message_context);
+    1458                 :            : 
+    1459                 :          1 :     status = libspdm_send_receive_psk_finish(spdm_context, session_id);
+    1460                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1461                 :          1 :     assert_int_equal(
+    1462                 :            :         libspdm_secured_message_get_session_state(
+    1463                 :            :             spdm_context->session_info[0].secured_message_context),
+    1464                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+    1465                 :          1 :     free(data);
+    1466                 :          1 : }
+    1467                 :            : 
+    1468                 :            : /**
+    1469                 :            :  * Test 7: the requester is setup correctly, but receives an ERROR message
+    1470                 :            :  * indicating the RequestResynch status of the responder.
+    1471                 :            :  * Expected behavior: client returns a Status of RETURN_DEVICE_ERROR, and the
+    1472                 :            :  * communication is reset to expect a new GET_VERSION message.
+    1473                 :            :  **/
+    1474                 :          1 : void libspdm_test_requester_psk_finish_case7(void **state)
+    1475                 :            : {
+    1476                 :            :     libspdm_return_t status;
+    1477                 :            :     libspdm_test_context_t *spdm_test_context;
+    1478                 :            :     libspdm_context_t *spdm_context;
+    1479                 :            :     uint32_t session_id;
+    1480                 :            :     void *data;
+    1481                 :            :     size_t data_size;
+    1482                 :            :     void *hash;
+    1483                 :            :     size_t hash_size;
+    1484                 :            :     libspdm_session_info_t *session_info;
+    1485                 :            : 
+    1486                 :          1 :     spdm_test_context = *state;
+    1487                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1488                 :          1 :     spdm_test_context->case_id = 0x7;
+    1489                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1490                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1491                 :          1 :     spdm_context->connection_info.connection_state =
+    1492                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1493                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1494                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1495                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1496                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    1497                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1498                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    1499                 :          1 :     spdm_context->local_context.capability.flags |=
+    1500                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1501                 :          1 :     spdm_context->local_context.capability.flags |=
+    1502                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    1503                 :          1 :     spdm_context->local_context.capability.flags |=
+    1504                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    1505                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1506                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    1507                 :            :                                                     &data_size, &hash, &hash_size);
+    1508                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1509                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1510                 :            :         m_libspdm_use_hash_algo;
+    1511                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1512                 :            :         m_libspdm_use_asym_algo;
+    1513                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1514                 :            :         m_libspdm_use_dhe_algo;
+    1515                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1516                 :            :         m_libspdm_use_aead_algo;
+    1517                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1518                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    1519                 :            :         data_size;
+    1520                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    1521                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    1522                 :            :                      data, data_size);
+    1523                 :            : #endif
+    1524                 :            : 
+    1525                 :          1 :     session_id = 0xFFFFFFFF;
+    1526                 :          1 :     session_info = &spdm_context->session_info[0];
+    1527                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+    1528                 :          1 :     libspdm_session_info_set_psk_hint(session_info,
+    1529                 :            :                                       LIBSPDM_TEST_PSK_HINT_STRING,
+    1530                 :            :                                       sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+    1531                 :          1 :     libspdm_secured_message_set_session_state(
+    1532                 :            :         session_info->secured_message_context,
+    1533                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    1534                 :          1 :     libspdm_set_mem(m_libspdm_dummy_key_buffer,
+    1535                 :            :                     ((libspdm_secured_message_context_t
+    1536                 :          1 :                       *)(session_info->secured_message_context))
+    1537                 :            :                     ->aead_key_size,
+    1538                 :            :                     (uint8_t)(0xFF));
+    1539                 :          1 :     libspdm_secured_message_set_response_handshake_encryption_key(
+    1540                 :            :         session_info->secured_message_context, m_libspdm_dummy_key_buffer,
+    1541                 :            :         ((libspdm_secured_message_context_t
+    1542                 :          1 :           *)(session_info->secured_message_context))
+    1543                 :            :         ->aead_key_size);
+    1544                 :          1 :     libspdm_set_mem(m_libspdm_dummy_salt_buffer,
+    1545                 :            :                     ((libspdm_secured_message_context_t
+    1546                 :          1 :                       *)(session_info->secured_message_context))
+    1547                 :            :                     ->aead_iv_size,
+    1548                 :            :                     (uint8_t)(0xFF));
+    1549                 :          1 :     libspdm_secured_message_set_response_handshake_salt(
+    1550                 :            :         session_info->secured_message_context, m_libspdm_dummy_salt_buffer,
+    1551                 :            :         ((libspdm_secured_message_context_t
+    1552                 :          1 :           *)(session_info->secured_message_context))
+    1553                 :            :         ->aead_iv_size);
+    1554                 :            :     ((libspdm_secured_message_context_t *)(session_info
+    1555                 :          1 :                                            ->secured_message_context))
+    1556                 :          1 :     ->handshake_secret.response_handshake_sequence_number = 0;
+    1557                 :          1 :     libspdm_secured_message_set_dummy_finished_key (session_info->secured_message_context);
+    1558                 :            : 
+    1559                 :          1 :     status = libspdm_send_receive_psk_finish(spdm_context, session_id);
+    1560                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_RESYNCH_PEER);
+    1561                 :          1 :     assert_int_equal(spdm_context->connection_info.connection_state,
+    1562                 :            :                      LIBSPDM_CONNECTION_STATE_NOT_STARTED);
+    1563                 :          1 :     free(data);
+    1564                 :          1 : }
+    1565                 :            : 
+    1566                 :            : /**
+    1567                 :            :  * Test 8: the requester is setup correctly, but receives an ERROR message
+    1568                 :            :  * indicating the ResponseNotReady status of the responder.
+    1569                 :            :  * Expected behavior: client returns a Status of RETURN_DEVICE_ERROR.
+    1570                 :            :  **/
+    1571                 :          1 : void libspdm_test_requester_psk_finish_case8(void **state)
+    1572                 :            : {
+    1573                 :            :     libspdm_return_t status;
+    1574                 :            :     libspdm_test_context_t *spdm_test_context;
+    1575                 :            :     libspdm_context_t *spdm_context;
+    1576                 :            :     uint32_t session_id;
+    1577                 :            :     void *data;
+    1578                 :            :     size_t data_size;
+    1579                 :            :     void *hash;
+    1580                 :            :     size_t hash_size;
+    1581                 :            :     libspdm_session_info_t *session_info;
+    1582                 :            : 
+    1583                 :          1 :     spdm_test_context = *state;
+    1584                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1585                 :          1 :     spdm_test_context->case_id = 0x8;
+    1586                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1587                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1588                 :          1 :     spdm_context->connection_info.connection_state =
+    1589                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1590                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1591                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1592                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1593                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    1594                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1595                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    1596                 :          1 :     spdm_context->local_context.capability.flags |=
+    1597                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1598                 :          1 :     spdm_context->local_context.capability.flags |=
+    1599                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    1600                 :          1 :     spdm_context->local_context.capability.flags |=
+    1601                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    1602                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1603                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    1604                 :            :                                                     &data_size, &hash, &hash_size);
+    1605                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1606                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1607                 :            :         m_libspdm_use_hash_algo;
+    1608                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1609                 :            :         m_libspdm_use_asym_algo;
+    1610                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1611                 :            :         m_libspdm_use_dhe_algo;
+    1612                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1613                 :            :         m_libspdm_use_aead_algo;
+    1614                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1615                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    1616                 :            :         data_size;
+    1617                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    1618                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    1619                 :            :                      data, data_size);
+    1620                 :            : #endif
+    1621                 :            : 
+    1622                 :          1 :     session_id = 0xFFFFFFFF;
+    1623                 :          1 :     session_info = &spdm_context->session_info[0];
+    1624                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+    1625                 :          1 :     libspdm_session_info_set_psk_hint(session_info,
+    1626                 :            :                                       LIBSPDM_TEST_PSK_HINT_STRING,
+    1627                 :            :                                       sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+    1628                 :          1 :     libspdm_secured_message_set_session_state(
+    1629                 :            :         session_info->secured_message_context,
+    1630                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    1631                 :          1 :     libspdm_set_mem(m_libspdm_dummy_key_buffer,
+    1632                 :            :                     ((libspdm_secured_message_context_t
+    1633                 :          1 :                       *)(session_info->secured_message_context))
+    1634                 :            :                     ->aead_key_size,
+    1635                 :            :                     (uint8_t)(0xFF));
+    1636                 :          1 :     libspdm_secured_message_set_response_handshake_encryption_key(
+    1637                 :            :         session_info->secured_message_context, m_libspdm_dummy_key_buffer,
+    1638                 :            :         ((libspdm_secured_message_context_t
+    1639                 :          1 :           *)(session_info->secured_message_context))
+    1640                 :            :         ->aead_key_size);
+    1641                 :          1 :     libspdm_set_mem(m_libspdm_dummy_salt_buffer,
+    1642                 :            :                     ((libspdm_secured_message_context_t
+    1643                 :          1 :                       *)(session_info->secured_message_context))
+    1644                 :            :                     ->aead_iv_size,
+    1645                 :            :                     (uint8_t)(0xFF));
+    1646                 :          1 :     libspdm_secured_message_set_response_handshake_salt(
+    1647                 :            :         session_info->secured_message_context, m_libspdm_dummy_salt_buffer,
+    1648                 :            :         ((libspdm_secured_message_context_t
+    1649                 :          1 :           *)(session_info->secured_message_context))
+    1650                 :            :         ->aead_iv_size);
+    1651                 :            :     ((libspdm_secured_message_context_t *)(session_info
+    1652                 :          1 :                                            ->secured_message_context))
+    1653                 :          1 :     ->handshake_secret.response_handshake_sequence_number = 0;
+    1654                 :          1 :     libspdm_secured_message_set_dummy_finished_key (session_info->secured_message_context);
+    1655                 :            : 
+    1656                 :          1 :     status = libspdm_send_receive_psk_finish(spdm_context, session_id);
+    1657                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_NOT_READY_PEER);
+    1658                 :          1 :     free(data);
+    1659                 :          1 : }
+    1660                 :            : 
+    1661                 :            : /**
+    1662                 :            :  * Test 9: the requester is setup correctly, but, on the first try, receiving
+    1663                 :            :  * a ResponseNotReady ERROR message, and, on retry, receiving a correct
+    1664                 :            :  * PSK_FINISH_RSP message.
+    1665                 :            :  * Expected behavior: client returns a Status of RETURN_SUCCESS and session
+    1666                 :            :  * is established.
+    1667                 :            :  **/
+    1668                 :          1 : void libspdm_test_requester_psk_finish_case9(void **state)
+    1669                 :            : {
+    1670                 :            :     libspdm_return_t status;
+    1671                 :            :     libspdm_test_context_t *spdm_test_context;
+    1672                 :            :     libspdm_context_t *spdm_context;
+    1673                 :            :     uint32_t session_id;
+    1674                 :            :     void *data;
+    1675                 :            :     size_t data_size;
+    1676                 :            :     void *hash;
+    1677                 :            :     size_t hash_size;
+    1678                 :            :     libspdm_session_info_t *session_info;
+    1679                 :            : 
+    1680                 :          1 :     spdm_test_context = *state;
+    1681                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1682                 :          1 :     spdm_test_context->case_id = 0x9;
+    1683                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1684                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1685                 :          1 :     spdm_context->connection_info.connection_state =
+    1686                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1687                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1688                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1689                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1690                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    1691                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1692                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    1693                 :          1 :     spdm_context->local_context.capability.flags |=
+    1694                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1695                 :          1 :     spdm_context->local_context.capability.flags |=
+    1696                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    1697                 :          1 :     spdm_context->local_context.capability.flags |=
+    1698                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    1699                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1700                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    1701                 :            :                                                     &data_size, &hash, &hash_size);
+    1702                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1703                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1704                 :            :         m_libspdm_use_hash_algo;
+    1705                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1706                 :            :         m_libspdm_use_asym_algo;
+    1707                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1708                 :            :         m_libspdm_use_dhe_algo;
+    1709                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1710                 :            :         m_libspdm_use_aead_algo;
+    1711                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1712                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    1713                 :            :         data_size;
+    1714                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    1715                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    1716                 :            :                      data, data_size);
+    1717                 :            : #endif
+    1718                 :            : 
+    1719                 :          1 :     session_id = 0xFFFFFFFF;
+    1720                 :          1 :     session_info = &spdm_context->session_info[0];
+    1721                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+    1722                 :          1 :     libspdm_session_info_set_psk_hint(session_info,
+    1723                 :            :                                       LIBSPDM_TEST_PSK_HINT_STRING,
+    1724                 :            :                                       sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+    1725                 :          1 :     libspdm_secured_message_set_session_state(
+    1726                 :            :         session_info->secured_message_context,
+    1727                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    1728                 :          1 :     libspdm_set_mem(m_libspdm_dummy_key_buffer,
+    1729                 :            :                     ((libspdm_secured_message_context_t
+    1730                 :          1 :                       *)(session_info->secured_message_context))
+    1731                 :            :                     ->aead_key_size,
+    1732                 :            :                     (uint8_t)(0xFF));
+    1733                 :          1 :     libspdm_secured_message_set_response_handshake_encryption_key(
+    1734                 :            :         session_info->secured_message_context, m_libspdm_dummy_key_buffer,
+    1735                 :            :         ((libspdm_secured_message_context_t
+    1736                 :          1 :           *)(session_info->secured_message_context))
+    1737                 :            :         ->aead_key_size);
+    1738                 :          1 :     libspdm_set_mem(m_libspdm_dummy_salt_buffer,
+    1739                 :            :                     ((libspdm_secured_message_context_t
+    1740                 :          1 :                       *)(session_info->secured_message_context))
+    1741                 :            :                     ->aead_iv_size,
+    1742                 :            :                     (uint8_t)(0xFF));
+    1743                 :          1 :     libspdm_secured_message_set_response_handshake_salt(
+    1744                 :            :         session_info->secured_message_context, m_libspdm_dummy_salt_buffer,
+    1745                 :            :         ((libspdm_secured_message_context_t
+    1746                 :          1 :           *)(session_info->secured_message_context))
+    1747                 :            :         ->aead_iv_size);
+    1748                 :            :     ((libspdm_secured_message_context_t *)(session_info
+    1749                 :          1 :                                            ->secured_message_context))
+    1750                 :          1 :     ->handshake_secret.response_handshake_sequence_number = 0;
+    1751                 :          1 :     libspdm_secured_message_set_dummy_finished_key (session_info->secured_message_context);
+    1752                 :            : 
+    1753                 :          1 :     status = libspdm_send_receive_psk_finish(spdm_context, session_id);
+    1754                 :            :     if (LIBSPDM_RESPOND_IF_READY_SUPPORT) {
+    1755                 :          1 :         assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1756                 :          1 :         assert_int_equal(
+    1757                 :            :             libspdm_secured_message_get_session_state(
+    1758                 :            :                 spdm_context->session_info[0].secured_message_context),
+    1759                 :            :             LIBSPDM_SESSION_STATE_ESTABLISHED);
+    1760                 :            :     } else {
+    1761                 :            :         assert_int_equal(status, LIBSPDM_STATUS_NOT_READY_PEER);
+    1762                 :            :     }
+    1763                 :            : 
+    1764                 :          1 :     free(data);
+    1765                 :          1 : }
+    1766                 :            : 
+    1767                 :            : /**
+    1768                 :            :  * Test 10: receiving an unexpected ERROR message from the responder.
+    1769                 :            :  * There are tests for all named codes, including some reserved ones
+    1770                 :            :  * (namely, 0x00, 0x0b, 0x0c, 0x3f, 0xfd, 0xfe).
+    1771                 :            :  * However, for having specific test cases, it is excluded from this case:
+    1772                 :            :  * Busy (0x03), ResponseNotReady (0x42), and RequestResync (0x43).
+    1773                 :            :  * Expected behavior: client returns a status of RETURN_DEVICE_ERROR.
+    1774                 :            :  **/
+    1775                 :          1 : void libspdm_test_requester_psk_finish_case10(void **state) {
+    1776                 :            :     libspdm_return_t status;
+    1777                 :            :     libspdm_test_context_t    *spdm_test_context;
+    1778                 :            :     libspdm_context_t  *spdm_context;
+    1779                 :            :     uint32_t session_id;
+    1780                 :            :     void                 *data;
+    1781                 :            :     size_t data_size;
+    1782                 :            :     void                 *hash;
+    1783                 :            :     size_t hash_size;
+    1784                 :            :     libspdm_session_info_t    *session_info;
+    1785                 :            :     uint16_t error_code;
+    1786                 :            : 
+    1787                 :          1 :     spdm_test_context = *state;
+    1788                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1789                 :          1 :     spdm_test_context->case_id = 0xA;
+    1790                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1791                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1792                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1793                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1794                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    1795                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    1796                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1797                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    1798                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    1799                 :          1 :     libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
+    1800                 :            :                                                      m_libspdm_use_asym_algo,
+    1801                 :            :                                                      &data, &data_size,
+    1802                 :            :                                                      &hash, &hash_size);
+    1803                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1804                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1805                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    1806                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    1807                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1808                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    1809                 :            :         data_size;
+    1810                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    1811                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    1812                 :            :                      data, data_size);
+    1813                 :            : #endif
+    1814                 :            : 
+    1815                 :          1 :     error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
+    1816         [ +  + ]:         19 :     while(error_code <= 0xff) {
+    1817                 :         18 :         spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1818                 :         18 :         libspdm_reset_message_a(spdm_context);
+    1819                 :            : 
+    1820                 :         18 :         session_id = 0xFFFFFFFF;
+    1821                 :         18 :         session_info = &spdm_context->session_info[0];
+    1822                 :         18 :         libspdm_session_info_init (spdm_context, session_info, session_id, true);
+    1823                 :         18 :         libspdm_session_info_set_psk_hint(session_info,
+    1824                 :            :                                           LIBSPDM_TEST_PSK_HINT_STRING,
+    1825                 :            :                                           sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+    1826                 :         18 :         libspdm_secured_message_set_session_state (session_info->secured_message_context,
+    1827                 :            :                                                    LIBSPDM_SESSION_STATE_HANDSHAKING);
+    1828                 :         18 :         libspdm_set_mem (m_libspdm_dummy_key_buffer,
+    1829                 :         18 :                          ((libspdm_secured_message_context_t*)(session_info->secured_message_context))->aead_key_size,
+    1830                 :            :                          (uint8_t)(0xFF));
+    1831                 :         18 :         libspdm_secured_message_set_response_handshake_encryption_key (
+    1832                 :            :             session_info->secured_message_context, m_libspdm_dummy_key_buffer,
+    1833                 :         18 :             ((libspdm_secured_message_context_t*)(session_info->secured_message_context))->aead_key_size);
+    1834                 :         18 :         libspdm_set_mem (m_libspdm_dummy_salt_buffer,
+    1835                 :         18 :                          ((libspdm_secured_message_context_t*)(session_info->secured_message_context))->aead_iv_size,
+    1836                 :            :                          (uint8_t)(0xFF));
+    1837                 :         18 :         libspdm_secured_message_set_response_handshake_salt (session_info->secured_message_context,
+    1838                 :            :                                                              m_libspdm_dummy_salt_buffer,
+    1839                 :            :                                                              ((libspdm_secured_message_context_t*)(
+    1840                 :         18 :                                                                   session_info->
+    1841                 :            :                                                                   secured_message_context))->aead_iv_size);
+    1842                 :         18 :         ((libspdm_secured_message_context_t*)(session_info->secured_message_context))->
+    1843                 :            :         handshake_secret
+    1844                 :         18 :         .response_handshake_sequence_number = 0;
+    1845                 :         18 :         libspdm_secured_message_set_dummy_finished_key (session_info->secured_message_context);
+    1846                 :            : 
+    1847                 :         18 :         status = libspdm_send_receive_psk_finish (spdm_context, session_id);
+    1848         [ +  + ]:         18 :         if(error_code != SPDM_ERROR_CODE_DECRYPT_ERROR) {
+    1849         [ -  + ]:         17 :             LIBSPDM_ASSERT_INT_EQUAL_CASE (status, LIBSPDM_STATUS_ERROR_PEER, error_code);
+    1850                 :            :         } else {
+    1851         [ -  + ]:          1 :             LIBSPDM_ASSERT_INT_EQUAL_CASE (status, LIBSPDM_STATUS_SESSION_MSG_ERROR, error_code);
+    1852                 :            :         }
+    1853                 :            : 
+    1854                 :         18 :         error_code++;
+    1855         [ +  + ]:         18 :         if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
+    1856                 :          1 :             error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
+    1857                 :            :         }
+    1858         [ +  + ]:         18 :         if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) { /*skip some reserved error codes (0d to 3e)*/
+    1859                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
+    1860                 :            :         }
+    1861         [ +  + ]:         18 :         if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) { /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
+    1862                 :          1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
+    1863                 :            :         }
+    1864                 :            :     }
+    1865                 :            : 
+    1866                 :          1 :     free(data);
+    1867                 :          1 : }
+    1868                 :            : 
+    1869                 :          1 : void libspdm_test_requester_psk_finish_case11(void **state)
+    1870                 :            : {
+    1871                 :            :     libspdm_return_t status;
+    1872                 :            :     libspdm_test_context_t *spdm_test_context;
+    1873                 :            :     libspdm_context_t *spdm_context;
+    1874                 :            :     uint32_t session_id;
+    1875                 :            :     void *data;
+    1876                 :            :     size_t data_size;
+    1877                 :            :     void *hash;
+    1878                 :            :     size_t hash_size;
+    1879                 :            :     libspdm_session_info_t *session_info;
+    1880                 :            : 
+    1881                 :          1 :     spdm_test_context = *state;
+    1882                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1883                 :          1 :     spdm_test_context->case_id = 0xB;
+    1884                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1885                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1886                 :          1 :     spdm_context->connection_info.connection_state =
+    1887                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1888                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1889                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1890                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1891                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    1892                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1893                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    1894                 :          1 :     spdm_context->local_context.capability.flags |=
+    1895                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1896                 :          1 :     spdm_context->local_context.capability.flags |=
+    1897                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    1898                 :          1 :     spdm_context->local_context.capability.flags |=
+    1899                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    1900                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1901                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    1902                 :            :                                                     &data_size, &hash, &hash_size);
+    1903                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1904                 :            : 
+    1905                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1906                 :            :         m_libspdm_use_hash_algo;
+    1907                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1908                 :            :         m_libspdm_use_asym_algo;
+    1909                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1910                 :            :         m_libspdm_use_dhe_algo;
+    1911                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1912                 :            :         m_libspdm_use_aead_algo;
+    1913                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1914                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    1915                 :            :         data_size;
+    1916                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    1917                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    1918                 :            :                      data, data_size);
+    1919                 :            : #endif
+    1920                 :            : 
+    1921                 :          1 :     session_id = 0xFFFFFFFF;
+    1922                 :          1 :     session_info = &spdm_context->session_info[0];
+    1923                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+    1924                 :          1 :     libspdm_session_info_set_psk_hint(session_info,
+    1925                 :            :                                       LIBSPDM_TEST_PSK_HINT_STRING,
+    1926                 :            :                                       sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+    1927                 :          1 :     libspdm_secured_message_set_session_state(
+    1928                 :            :         session_info->secured_message_context,
+    1929                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    1930                 :          1 :     libspdm_set_mem(m_libspdm_dummy_key_buffer,
+    1931                 :            :                     ((libspdm_secured_message_context_t
+    1932                 :          1 :                       *)(session_info->secured_message_context))
+    1933                 :            :                     ->aead_key_size,
+    1934                 :            :                     (uint8_t)(0xFF));
+    1935                 :          1 :     libspdm_secured_message_set_response_handshake_encryption_key(
+    1936                 :            :         session_info->secured_message_context, m_libspdm_dummy_key_buffer,
+    1937                 :            :         ((libspdm_secured_message_context_t
+    1938                 :          1 :           *)(session_info->secured_message_context))
+    1939                 :            :         ->aead_key_size);
+    1940                 :          1 :     libspdm_set_mem(m_libspdm_dummy_salt_buffer,
+    1941                 :            :                     ((libspdm_secured_message_context_t
+    1942                 :          1 :                       *)(session_info->secured_message_context))
+    1943                 :            :                     ->aead_iv_size,
+    1944                 :            :                     (uint8_t)(0xFF));
+    1945                 :          1 :     libspdm_secured_message_set_response_handshake_salt(
+    1946                 :            :         session_info->secured_message_context, m_libspdm_dummy_salt_buffer,
+    1947                 :            :         ((libspdm_secured_message_context_t
+    1948                 :          1 :           *)(session_info->secured_message_context))
+    1949                 :            :         ->aead_iv_size);
+    1950                 :            :     ((libspdm_secured_message_context_t *)(session_info
+    1951                 :          1 :                                            ->secured_message_context))
+    1952                 :          1 :     ->handshake_secret.response_handshake_sequence_number = 0;
+    1953                 :          1 :     libspdm_secured_message_set_dummy_finished_key (session_info->secured_message_context);
+    1954                 :            : 
+    1955                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1956                 :            :     session_info->session_transcript.message_m.buffer_size =
+    1957                 :            :         session_info->session_transcript.message_m.max_buffer_size;
+    1958                 :            :     spdm_context->transcript.message_b.buffer_size =
+    1959                 :            :         spdm_context->transcript.message_b.max_buffer_size;
+    1960                 :            :     spdm_context->transcript.message_c.buffer_size =
+    1961                 :            :         spdm_context->transcript.message_c.max_buffer_size;
+    1962                 :            :     spdm_context->transcript.message_mut_b.buffer_size =
+    1963                 :            :         spdm_context->transcript.message_mut_b.max_buffer_size;
+    1964                 :            :     spdm_context->transcript.message_mut_c.buffer_size =
+    1965                 :            :         spdm_context->transcript.message_mut_c.max_buffer_size;
+    1966                 :            : #endif
+    1967                 :            : 
+    1968                 :          1 :     status = libspdm_send_receive_psk_finish(spdm_context, session_id);
+    1969                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1970                 :          1 :     assert_int_equal(
+    1971                 :            :         libspdm_secured_message_get_session_state(
+    1972                 :            :             spdm_context->session_info[0].secured_message_context),
+    1973                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+    1974                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1975                 :            :     assert_int_equal(session_info->session_transcript.message_m.buffer_size, 0);
+    1976                 :            :     assert_int_equal(spdm_context->transcript.message_b.buffer_size, 0);
+    1977                 :            :     assert_int_equal(spdm_context->transcript.message_c.buffer_size, 0);
+    1978                 :            :     assert_int_equal(spdm_context->transcript.message_mut_b.buffer_size, 0);
+    1979                 :            :     assert_int_equal(spdm_context->transcript.message_mut_c.buffer_size, 0);
+    1980                 :            : #endif
+    1981                 :          1 :     free(data);
+    1982                 :          1 : }
+    1983                 :            : 
+    1984                 :            : /**
+    1985                 :            :  * Test 12: requester is not setup correctly to support pre-shared keys
+    1986                 :            :  * (no capabilities). The responder would attempt to return a correct
+    1987                 :            :  * PSK_FINISH_RSP message.
+    1988                 :            :  * Expected behavior: client returns a Status of RETURN_UNSUPPORTED.
+    1989                 :            :  **/
+    1990                 :          1 : void libspdm_test_requester_psk_finish_case12(void **state)
+    1991                 :            : {
+    1992                 :            :     libspdm_return_t status;
+    1993                 :            :     libspdm_test_context_t *spdm_test_context;
+    1994                 :            :     libspdm_context_t *spdm_context;
+    1995                 :            :     uint32_t session_id;
+    1996                 :            :     void *data;
+    1997                 :            :     size_t data_size;
+    1998                 :            :     void *hash;
+    1999                 :            :     size_t hash_size;
+    2000                 :            :     libspdm_session_info_t *session_info;
+    2001                 :            : 
+    2002                 :          1 :     spdm_test_context = *state;
+    2003                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2004                 :          1 :     spdm_test_context->case_id = 0xC;
+    2005                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    2006                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2007                 :          1 :     spdm_context->connection_info.connection_state =
+    2008                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    2009                 :            :     /*no PSK capabilities*/
+    2010                 :          1 :     spdm_context->connection_info.capability.flags &=
+    2011                 :            :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
+    2012                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2013                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    2014                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2015                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    2016                 :          1 :     spdm_context->local_context.capability.flags |=
+    2017                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    2018                 :          1 :     spdm_context->local_context.capability.flags |=
+    2019                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    2020                 :          1 :     spdm_context->local_context.capability.flags |=
+    2021                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    2022                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    2023                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    2024                 :            :                                                     &data_size, &hash, &hash_size);
+    2025                 :          1 :     spdm_context->transcript.message_a.buffer_size = 0;
+    2026                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    2027                 :            :         m_libspdm_use_hash_algo;
+    2028                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    2029                 :            :         m_libspdm_use_asym_algo;
+    2030                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    2031                 :            :         m_libspdm_use_dhe_algo;
+    2032                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    2033                 :            :         m_libspdm_use_aead_algo;
+    2034                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    2035                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    2036                 :            :         data_size;
+    2037                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    2038                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    2039                 :            :                      data, data_size);
+    2040                 :            : #endif
+    2041                 :            : 
+    2042                 :          1 :     session_id = 0xFFFFFFFF;
+    2043                 :          1 :     session_info = &spdm_context->session_info[0];
+    2044                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+    2045                 :          1 :     libspdm_session_info_set_psk_hint(session_info,
+    2046                 :            :                                       LIBSPDM_TEST_PSK_HINT_STRING,
+    2047                 :            :                                       sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+    2048                 :          1 :     libspdm_secured_message_set_session_state(
+    2049                 :            :         session_info->secured_message_context,
+    2050                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    2051                 :          1 :     libspdm_set_mem(m_libspdm_dummy_key_buffer,
+    2052                 :            :                     ((libspdm_secured_message_context_t
+    2053                 :          1 :                       *)(session_info->secured_message_context))
+    2054                 :            :                     ->aead_key_size,
+    2055                 :            :                     (uint8_t)(0xFF));
+    2056                 :          1 :     libspdm_secured_message_set_response_handshake_encryption_key(
+    2057                 :            :         session_info->secured_message_context, m_libspdm_dummy_key_buffer,
+    2058                 :            :         ((libspdm_secured_message_context_t
+    2059                 :          1 :           *)(session_info->secured_message_context))
+    2060                 :            :         ->aead_key_size);
+    2061                 :          1 :     libspdm_set_mem(m_libspdm_dummy_salt_buffer,
+    2062                 :            :                     ((libspdm_secured_message_context_t
+    2063                 :          1 :                       *)(session_info->secured_message_context))
+    2064                 :            :                     ->aead_iv_size,
+    2065                 :            :                     (uint8_t)(0xFF));
+    2066                 :          1 :     libspdm_secured_message_set_response_handshake_salt(
+    2067                 :            :         session_info->secured_message_context, m_libspdm_dummy_salt_buffer,
+    2068                 :            :         ((libspdm_secured_message_context_t
+    2069                 :          1 :           *)(session_info->secured_message_context))
+    2070                 :            :         ->aead_iv_size);
+    2071                 :            :     ((libspdm_secured_message_context_t *)(session_info
+    2072                 :          1 :                                            ->secured_message_context))
+    2073                 :          1 :     ->handshake_secret.response_handshake_sequence_number = 0;
+    2074                 :          1 :     libspdm_secured_message_set_dummy_finished_key (session_info->secured_message_context);
+    2075                 :            : 
+    2076                 :          1 :     status = libspdm_send_receive_psk_finish(spdm_context, session_id);
+    2077                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_UNSUPPORTED_CAP);
+    2078                 :          1 :     free(data);
+    2079                 :          1 : }
+    2080                 :            : 
+    2081                 :            : /**
+    2082                 :            :  * Test 13: receiving an incorrect FINISH_RSP message, with wrong response
+    2083                 :            :  * code, but all other field correct.
+    2084                 :            :  * Expected behavior: client returns a Status of RETURN_DEVICE_ERROR.
+    2085                 :            :  **/
+    2086                 :          1 : void libspdm_test_requester_psk_finish_case13(void **state)
+    2087                 :            : {
+    2088                 :            :     libspdm_return_t status;
+    2089                 :            :     libspdm_test_context_t *spdm_test_context;
+    2090                 :            :     libspdm_context_t *spdm_context;
+    2091                 :            :     uint32_t session_id;
+    2092                 :            :     void *data;
+    2093                 :            :     size_t data_size;
+    2094                 :            :     void *hash;
+    2095                 :            :     size_t hash_size;
+    2096                 :            :     libspdm_session_info_t *session_info;
+    2097                 :            : 
+    2098                 :          1 :     spdm_test_context = *state;
+    2099                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2100                 :          1 :     spdm_test_context->case_id = 0xD;
+    2101                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    2102                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2103                 :          1 :     spdm_context->connection_info.connection_state =
+    2104                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    2105                 :            :     /*no PSK capabilities*/
+    2106                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2107                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    2108                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2109                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    2110                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2111                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    2112                 :          1 :     spdm_context->local_context.capability.flags |=
+    2113                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    2114                 :          1 :     spdm_context->local_context.capability.flags |=
+    2115                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    2116                 :          1 :     spdm_context->local_context.capability.flags |=
+    2117                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    2118                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    2119                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    2120                 :            :                                                     &data_size, &hash, &hash_size);
+    2121                 :          1 :     spdm_context->transcript.message_a.buffer_size = 0;
+    2122                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    2123                 :            :         m_libspdm_use_hash_algo;
+    2124                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    2125                 :            :         m_libspdm_use_asym_algo;
+    2126                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    2127                 :            :         m_libspdm_use_dhe_algo;
+    2128                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    2129                 :            :         m_libspdm_use_aead_algo;
+    2130                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    2131                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    2132                 :            :         data_size;
+    2133                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    2134                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    2135                 :            :                      data, data_size);
+    2136                 :            : #endif
+    2137                 :            : 
+    2138                 :          1 :     session_id = 0xFFFFFFFF;
+    2139                 :          1 :     session_info = &spdm_context->session_info[0];
+    2140                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+    2141                 :          1 :     libspdm_session_info_set_psk_hint(session_info,
+    2142                 :            :                                       LIBSPDM_TEST_PSK_HINT_STRING,
+    2143                 :            :                                       sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+    2144                 :          1 :     libspdm_secured_message_set_session_state(
+    2145                 :            :         session_info->secured_message_context,
+    2146                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    2147                 :          1 :     libspdm_set_mem(m_libspdm_dummy_key_buffer,
+    2148                 :            :                     ((libspdm_secured_message_context_t
+    2149                 :          1 :                       *)(session_info->secured_message_context))
+    2150                 :            :                     ->aead_key_size,
+    2151                 :            :                     (uint8_t)(0xFF));
+    2152                 :          1 :     libspdm_secured_message_set_response_handshake_encryption_key(
+    2153                 :            :         session_info->secured_message_context, m_libspdm_dummy_key_buffer,
+    2154                 :            :         ((libspdm_secured_message_context_t
+    2155                 :          1 :           *)(session_info->secured_message_context))
+    2156                 :            :         ->aead_key_size);
+    2157                 :          1 :     libspdm_set_mem(m_libspdm_dummy_salt_buffer,
+    2158                 :            :                     ((libspdm_secured_message_context_t
+    2159                 :          1 :                       *)(session_info->secured_message_context))
+    2160                 :            :                     ->aead_iv_size,
+    2161                 :            :                     (uint8_t)(0xFF));
+    2162                 :          1 :     libspdm_secured_message_set_response_handshake_salt(
+    2163                 :            :         session_info->secured_message_context, m_libspdm_dummy_salt_buffer,
+    2164                 :            :         ((libspdm_secured_message_context_t
+    2165                 :          1 :           *)(session_info->secured_message_context))
+    2166                 :            :         ->aead_iv_size);
+    2167                 :            :     ((libspdm_secured_message_context_t *)(session_info
+    2168                 :          1 :                                            ->secured_message_context))
+    2169                 :          1 :     ->handshake_secret.response_handshake_sequence_number = 0;
+    2170                 :          1 :     libspdm_secured_message_set_dummy_finished_key (session_info->secured_message_context);
+    2171                 :            : 
+    2172                 :          1 :     status = libspdm_send_receive_psk_finish(spdm_context, session_id);
+    2173                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    2174                 :          1 :     free(data);
+    2175                 :          1 : }
+    2176                 :            : 
+    2177                 :            : /**
+    2178                 :            :  * Test 14: requester is not setup correctly by not initializing a
+    2179                 :            :  * session during PSK_EXCHANGE. The responder would attempt to
+    2180                 :            :  * return a correct PSK_FINISH_RSP message.
+    2181                 :            :  * Expected behavior: client returns a Status of RETURN_UNSUPPORTED.
+    2182                 :            :  **/
+    2183                 :          1 : void libspdm_test_requester_psk_finish_case14(void **state)
+    2184                 :            : {
+    2185                 :            :     libspdm_return_t status;
+    2186                 :            :     libspdm_test_context_t *spdm_test_context;
+    2187                 :            :     libspdm_context_t *spdm_context;
+    2188                 :            :     uint32_t session_id;
+    2189                 :            :     void *data;
+    2190                 :            :     size_t data_size;
+    2191                 :            :     void *hash;
+    2192                 :            :     size_t hash_size;
+    2193                 :            :     libspdm_session_info_t *session_info;
+    2194                 :            : 
+    2195                 :          1 :     spdm_test_context = *state;
+    2196                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2197                 :          1 :     spdm_test_context->case_id = 0xE;
+    2198                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    2199                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2200                 :          1 :     spdm_context->connection_info.connection_state =
+    2201                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    2202                 :            :     /*no PSK capabilities*/
+    2203                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2204                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    2205                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2206                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    2207                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2208                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    2209                 :          1 :     spdm_context->local_context.capability.flags |=
+    2210                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    2211                 :          1 :     spdm_context->local_context.capability.flags |=
+    2212                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    2213                 :          1 :     spdm_context->local_context.capability.flags |=
+    2214                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    2215                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    2216                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    2217                 :            :                                                     &data_size, &hash, &hash_size);
+    2218                 :          1 :     spdm_context->transcript.message_a.buffer_size = 0;
+    2219                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    2220                 :            :         m_libspdm_use_hash_algo;
+    2221                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    2222                 :            :         m_libspdm_use_asym_algo;
+    2223                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    2224                 :            :         m_libspdm_use_dhe_algo;
+    2225                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    2226                 :            :         m_libspdm_use_aead_algo;
+    2227                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    2228                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    2229                 :            :         data_size;
+    2230                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    2231                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    2232                 :            :                      data, data_size);
+    2233                 :            : #endif
+    2234                 :            : 
+    2235                 :          1 :     session_id = 0xFFFFFFFF;
+    2236                 :          1 :     session_info = &spdm_context->session_info[0];
+    2237                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+    2238                 :          1 :     libspdm_session_info_set_psk_hint(session_info,
+    2239                 :            :                                       LIBSPDM_TEST_PSK_HINT_STRING,
+    2240                 :            :                                       sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+    2241                 :          1 :     libspdm_secured_message_set_session_state(
+    2242                 :            :         session_info->secured_message_context,
+    2243                 :            :         LIBSPDM_SESSION_STATE_NOT_STARTED);
+    2244                 :          1 :     libspdm_set_mem(m_libspdm_dummy_key_buffer,
+    2245                 :            :                     ((libspdm_secured_message_context_t
+    2246                 :          1 :                       *)(session_info->secured_message_context))
+    2247                 :            :                     ->aead_key_size,
+    2248                 :            :                     (uint8_t)(0xFF));
+    2249                 :          1 :     libspdm_secured_message_set_response_handshake_encryption_key(
+    2250                 :            :         session_info->secured_message_context, m_libspdm_dummy_key_buffer,
+    2251                 :            :         ((libspdm_secured_message_context_t
+    2252                 :          1 :           *)(session_info->secured_message_context))
+    2253                 :            :         ->aead_key_size);
+    2254                 :          1 :     libspdm_set_mem(m_libspdm_dummy_salt_buffer,
+    2255                 :            :                     ((libspdm_secured_message_context_t
+    2256                 :          1 :                       *)(session_info->secured_message_context))
+    2257                 :            :                     ->aead_iv_size,
+    2258                 :            :                     (uint8_t)(0xFF));
+    2259                 :          1 :     libspdm_secured_message_set_response_handshake_salt(
+    2260                 :            :         session_info->secured_message_context, m_libspdm_dummy_salt_buffer,
+    2261                 :            :         ((libspdm_secured_message_context_t
+    2262                 :          1 :           *)(session_info->secured_message_context))
+    2263                 :            :         ->aead_iv_size);
+    2264                 :            :     ((libspdm_secured_message_context_t *)(session_info
+    2265                 :          1 :                                            ->secured_message_context))
+    2266                 :          1 :     ->handshake_secret.response_handshake_sequence_number = 0;
+    2267                 :          1 :     libspdm_secured_message_set_dummy_finished_key (session_info->secured_message_context);
+    2268                 :            : 
+    2269                 :          1 :     status = libspdm_send_receive_psk_finish(spdm_context, session_id);
+    2270                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_STATE_LOCAL);
+    2271                 :          1 :     free(data);
+    2272                 :          1 : }
+    2273                 :            : 
+    2274                 :            : /**
+    2275                 :            :  * Test 15 the requester is setup correctly, but receives an ERROR with SPDM_ERROR_CODE_DECRYPT_ERROR.
+    2276                 :            :  * Expected behavior: client returns a Status of INVALID_SESSION_ID  and free the session ID.
+    2277                 :            :  **/
+    2278                 :          1 : void libspdm_test_requester_psk_finish_case15(void **state)
+    2279                 :            : {
+    2280                 :            :     libspdm_return_t status;
+    2281                 :            :     libspdm_test_context_t *spdm_test_context;
+    2282                 :            :     libspdm_context_t *spdm_context;
+    2283                 :            :     uint32_t session_id;
+    2284                 :            :     void *data;
+    2285                 :            :     size_t data_size;
+    2286                 :            :     void *hash;
+    2287                 :            :     size_t hash_size;
+    2288                 :            :     libspdm_session_info_t *session_info;
+    2289                 :            : 
+    2290                 :          1 :     spdm_test_context = *state;
+    2291                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2292                 :          1 :     spdm_test_context->case_id = 0xF;
+    2293                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    2294                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2295                 :          1 :     spdm_context->connection_info.connection_state =
+    2296                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    2297                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2298                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    2299                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2300                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    2301                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2302                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    2303                 :          1 :     spdm_context->local_context.capability.flags |=
+    2304                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    2305                 :          1 :     spdm_context->local_context.capability.flags |=
+    2306                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    2307                 :          1 :     spdm_context->local_context.capability.flags |=
+    2308                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    2309                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    2310                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    2311                 :            :                                                     &data_size, &hash, &hash_size);
+    2312                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2313                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    2314                 :            :         m_libspdm_use_hash_algo;
+    2315                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    2316                 :            :         m_libspdm_use_asym_algo;
+    2317                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    2318                 :            :         m_libspdm_use_dhe_algo;
+    2319                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    2320                 :            :         m_libspdm_use_aead_algo;
+    2321                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    2322                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    2323                 :            :         data_size;
+    2324                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    2325                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    2326                 :            :                      data, data_size);
+    2327                 :            : #endif
+    2328                 :            : 
+    2329                 :          1 :     session_id = 0xFFFFFFFF;
+    2330                 :          1 :     session_info = &spdm_context->session_info[0];
+    2331                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+    2332                 :          1 :     libspdm_session_info_set_psk_hint(session_info,
+    2333                 :            :                                       LIBSPDM_TEST_PSK_HINT_STRING,
+    2334                 :            :                                       sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+    2335                 :          1 :     libspdm_secured_message_set_session_state(
+    2336                 :            :         session_info->secured_message_context,
+    2337                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    2338                 :          1 :     libspdm_set_mem(m_libspdm_dummy_key_buffer,
+    2339                 :            :                     ((libspdm_secured_message_context_t
+    2340                 :          1 :                       *)(session_info->secured_message_context))
+    2341                 :            :                     ->aead_key_size,
+    2342                 :            :                     (uint8_t)(0xFF));
+    2343                 :          1 :     libspdm_secured_message_set_response_handshake_encryption_key(
+    2344                 :            :         session_info->secured_message_context, m_libspdm_dummy_key_buffer,
+    2345                 :            :         ((libspdm_secured_message_context_t
+    2346                 :          1 :           *)(session_info->secured_message_context))
+    2347                 :            :         ->aead_key_size);
+    2348                 :          1 :     libspdm_set_mem(m_libspdm_dummy_salt_buffer,
+    2349                 :            :                     ((libspdm_secured_message_context_t
+    2350                 :          1 :                       *)(session_info->secured_message_context))
+    2351                 :            :                     ->aead_iv_size,
+    2352                 :            :                     (uint8_t)(0xFF));
+    2353                 :          1 :     libspdm_secured_message_set_response_handshake_salt(
+    2354                 :            :         session_info->secured_message_context, m_libspdm_dummy_salt_buffer,
+    2355                 :            :         ((libspdm_secured_message_context_t
+    2356                 :          1 :           *)(session_info->secured_message_context))
+    2357                 :            :         ->aead_iv_size);
+    2358                 :            :     ((libspdm_secured_message_context_t *)(session_info
+    2359                 :          1 :                                            ->secured_message_context))
+    2360                 :          1 :     ->handshake_secret.response_handshake_sequence_number = 0;
+    2361                 :          1 :     libspdm_secured_message_set_dummy_finished_key (session_info->secured_message_context);
+    2362                 :            : 
+    2363                 :          1 :     status = libspdm_send_receive_psk_finish(spdm_context, session_id);
+    2364                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SESSION_MSG_ERROR);
+    2365                 :          1 :     assert_int_equal(spdm_context->session_info->session_id, INVALID_SESSION_ID);
+    2366                 :          1 :     free(data);
+    2367                 :          1 : }
+    2368                 :            : 
+    2369                 :            : /**
+    2370                 :            :  * Test 16: a request message is successfully sent and a response message is successfully received.
+    2371                 :            :  * Expected Behavior: requester returns the status RETURN_SUCCESS and a PSK_FINISH_RSP message is
+    2372                 :            :  * received, buffer F appends the exchanged PSK_FINISH and PSK_FINISH_RSP messages.
+    2373                 :            :  **/
+    2374                 :          1 : void libspdm_test_requester_psk_finish_case16(void **state)
+    2375                 :            : {
+    2376                 :            :     libspdm_return_t status;
+    2377                 :            :     libspdm_test_context_t *spdm_test_context;
+    2378                 :            :     libspdm_context_t *spdm_context;
+    2379                 :            :     uint32_t session_id;
+    2380                 :            :     void *data;
+    2381                 :            :     size_t data_size;
+    2382                 :            :     void *hash;
+    2383                 :            :     size_t hash_size;
+    2384                 :            :     libspdm_session_info_t *session_info;
+    2385                 :            : 
+    2386                 :          1 :     spdm_test_context = *state;
+    2387                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2388                 :          1 :     spdm_test_context->case_id = 0x10;
+    2389                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    2390                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2391                 :          1 :     spdm_context->connection_info.connection_state =
+    2392                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    2393                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2394                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    2395                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2396                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    2397                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2398                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    2399                 :          1 :     spdm_context->local_context.capability.flags |=
+    2400                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    2401                 :          1 :     spdm_context->local_context.capability.flags |=
+    2402                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    2403                 :          1 :     spdm_context->local_context.capability.flags |=
+    2404                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    2405                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    2406                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    2407                 :            :                                                     &data_size, &hash, &hash_size);
+    2408                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2409                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2410                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2411                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    2412                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    2413                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    2414                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    2415                 :            :         data_size;
+    2416                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    2417                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    2418                 :            :                      data, data_size);
+    2419                 :            : #endif
+    2420                 :            : 
+    2421                 :            : 
+    2422                 :          1 :     session_id = 0xFFFFFFFF;
+    2423                 :          1 :     session_info = &spdm_context->session_info[0];
+    2424                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+    2425                 :          1 :     libspdm_session_info_set_psk_hint(session_info,
+    2426                 :            :                                       LIBSPDM_TEST_PSK_HINT_STRING,
+    2427                 :            :                                       sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+    2428                 :          1 :     libspdm_secured_message_set_session_state(
+    2429                 :            :         session_info->secured_message_context,
+    2430                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    2431                 :          1 :     libspdm_set_mem(m_libspdm_dummy_key_buffer,
+    2432                 :          1 :                     ((libspdm_secured_message_context_t*)(session_info->secured_message_context))
+    2433                 :            :                     ->aead_key_size, (uint8_t)(0xFF));
+    2434                 :          1 :     libspdm_secured_message_set_response_handshake_encryption_key(
+    2435                 :            :         session_info->secured_message_context, m_libspdm_dummy_key_buffer,
+    2436                 :          1 :         ((libspdm_secured_message_context_t*)(session_info->secured_message_context))
+    2437                 :            :         ->aead_key_size);
+    2438                 :          1 :     libspdm_set_mem(m_libspdm_dummy_salt_buffer,
+    2439                 :          1 :                     ((libspdm_secured_message_context_t*)(session_info->secured_message_context))
+    2440                 :            :                     ->aead_iv_size, (uint8_t)(0xFF));
+    2441                 :          1 :     libspdm_secured_message_set_response_handshake_salt(
+    2442                 :            :         session_info->secured_message_context, m_libspdm_dummy_salt_buffer,
+    2443                 :          1 :         ((libspdm_secured_message_context_t*)(session_info->secured_message_context))
+    2444                 :            :         ->aead_iv_size);
+    2445                 :          1 :     ((libspdm_secured_message_context_t *)(session_info->secured_message_context))
+    2446                 :          1 :     ->handshake_secret.response_handshake_sequence_number = 0;
+    2447                 :          1 :     ((libspdm_secured_message_context_t *)(session_info->secured_message_context))
+    2448                 :          1 :     ->handshake_secret.request_handshake_sequence_number = 0;
+    2449                 :          1 :     libspdm_secured_message_set_dummy_finished_key (session_info->secured_message_context);
+    2450                 :            : 
+    2451                 :          1 :     status = libspdm_send_receive_psk_finish(spdm_context, session_id);
+    2452                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2453                 :          1 :     assert_int_equal(
+    2454                 :            :         libspdm_secured_message_get_session_state(
+    2455                 :            :             spdm_context->session_info[0].secured_message_context),
+    2456                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+    2457                 :            : 
+    2458                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    2459                 :            :     assert_int_equal(spdm_context->session_info[0].session_transcript.message_f.buffer_size,
+    2460                 :            :                      m_libspdm_local_buffer_size);
+    2461                 :            :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer (0x%x):\n",
+    2462                 :            :                    m_libspdm_local_buffer_size));
+    2463                 :            :     libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    2464                 :            :     assert_memory_equal(spdm_context->session_info[0].session_transcript.message_f.buffer,
+    2465                 :            :                         m_libspdm_local_buffer, m_libspdm_local_buffer_size);
+    2466                 :            : #endif
+    2467                 :          1 :     free(data);
+    2468                 :          1 : }
+    2469                 :            : 
+    2470                 :            : libspdm_test_context_t m_libspdm_requester_psk_finish_test_context = {
+    2471                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+    2472                 :            :     true,
+    2473                 :            :     libspdm_requester_psk_finish_test_send_message,
+    2474                 :            :     libspdm_requester_psk_finish_test_receive_message,
+    2475                 :            : };
+    2476                 :            : 
+    2477                 :          1 : int libspdm_requester_psk_finish_test_main(void)
+    2478                 :            : {
+    2479                 :          1 :     const struct CMUnitTest spdm_requester_psk_finish_tests[] = {
+    2480                 :            :         /* SendRequest failed*/
+    2481                 :            :         cmocka_unit_test(libspdm_test_requester_psk_finish_case1),
+    2482                 :            :         /* Successful response*/
+    2483                 :            :         cmocka_unit_test(libspdm_test_requester_psk_finish_case2),
+    2484                 :            :         /* connection_state check failed*/
+    2485                 :            :         cmocka_unit_test(libspdm_test_requester_psk_finish_case3),
+    2486                 :            :         /* Error response: SPDM_ERROR_CODE_INVALID_REQUEST*/
+    2487                 :            :         cmocka_unit_test(libspdm_test_requester_psk_finish_case4),
+    2488                 :            :         /* Always SPDM_ERROR_CODE_BUSY*/
+    2489                 :            :         cmocka_unit_test(libspdm_test_requester_psk_finish_case5),
+    2490                 :            :         /* SPDM_ERROR_CODE_BUSY + Successful response*/
+    2491                 :            :         cmocka_unit_test(libspdm_test_requester_psk_finish_case6),
+    2492                 :            :         /* Error response: SPDM_ERROR_CODE_REQUEST_RESYNCH*/
+    2493                 :            :         cmocka_unit_test(libspdm_test_requester_psk_finish_case7),
+    2494                 :            :         /* Always SPDM_ERROR_CODE_RESPONSE_NOT_READY*/
+    2495                 :            :         cmocka_unit_test(libspdm_test_requester_psk_finish_case8),
+    2496                 :            :         /* SPDM_ERROR_CODE_RESPONSE_NOT_READY + Successful response*/
+    2497                 :            :         cmocka_unit_test(libspdm_test_requester_psk_finish_case9),
+    2498                 :            :         /* Unexpected errors*/
+    2499                 :            :         cmocka_unit_test(libspdm_test_requester_psk_finish_case10),
+    2500                 :            :         /* Buffer reset*/
+    2501                 :            :         cmocka_unit_test(libspdm_test_requester_psk_finish_case11),
+    2502                 :            :         /* No correct setup*/
+    2503                 :            :         cmocka_unit_test(libspdm_test_requester_psk_finish_case12),
+    2504                 :            :         /* Wrong response code*/
+    2505                 :            :         cmocka_unit_test(libspdm_test_requester_psk_finish_case13),
+    2506                 :            :         /* Uninitialized session*/
+    2507                 :            :         cmocka_unit_test(libspdm_test_requester_psk_finish_case14),
+    2508                 :            :         /* Error response: SPDM_ERROR_CODE_DECRYPT_ERROR*/
+    2509                 :            :         cmocka_unit_test(libspdm_test_requester_psk_finish_case15),
+    2510                 :            :         /* Buffer verification*/
+    2511                 :            :         cmocka_unit_test(libspdm_test_requester_psk_finish_case16),
+    2512                 :            :     };
+    2513                 :            : 
+    2514                 :          1 :     libspdm_setup_test_context(&m_libspdm_requester_psk_finish_test_context);
+    2515                 :            : 
+    2516                 :          1 :     return cmocka_run_group_tests(spdm_requester_psk_finish_tests,
+    2517                 :            :                                   libspdm_unit_test_group_setup,
+    2518                 :            :                                   libspdm_unit_test_group_teardown);
+    2519                 :            : }
+    2520                 :            : 
+    2521                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/set_certificate.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_requester/set_certificate.c.func-sort-c.html new file mode 100644 index 00000000000..804614a6e59 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/set_certificate.c.func-sort-c.html @@ -0,0 +1,125 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/set_certificate.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - set_certificate.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:21825784.8 %
Date:2024-09-22 08:21:07Functions:1111100.0 %
Branches:132454.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_set_certificate_test_main1
libspdm_test_requester_set_certificate_case11
libspdm_test_requester_set_certificate_case21
libspdm_test_requester_set_certificate_case31
libspdm_test_requester_set_certificate_case51
libspdm_test_requester_set_certificate_case61
libspdm_test_requester_set_certificate_case71
libspdm_test_requester_set_certificate_case81
libspdm_test_requester_set_certificate_case91
libspdm_requester_set_certificate_test_receive_message5
libspdm_requester_set_certificate_test_send_message6
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/set_certificate.c.func.html b/coverage_log/unit_test/test_spdm_requester/set_certificate.c.func.html new file mode 100644 index 00000000000..b827cb66bef --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/set_certificate.c.func.html @@ -0,0 +1,125 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/set_certificate.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - set_certificate.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:21825784.8 %
Date:2024-09-22 08:21:07Functions:1111100.0 %
Branches:132454.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_set_certificate_test_main1
libspdm_requester_set_certificate_test_receive_message5
libspdm_requester_set_certificate_test_send_message6
libspdm_test_requester_set_certificate_case11
libspdm_test_requester_set_certificate_case21
libspdm_test_requester_set_certificate_case31
libspdm_test_requester_set_certificate_case51
libspdm_test_requester_set_certificate_case61
libspdm_test_requester_set_certificate_case71
libspdm_test_requester_set_certificate_case81
libspdm_test_requester_set_certificate_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/set_certificate.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/set_certificate.c.gcov.html new file mode 100644 index 00000000000..b2586a7f717 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/set_certificate.c.gcov.html @@ -0,0 +1,723 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/set_certificate.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - set_certificate.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:21825784.8 %
Date:2024-09-22 08:21:07Functions:1111100.0 %
Branches:132454.2 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_requester_lib.h"
+       9                 :            : #include "internal/libspdm_secured_message_lib.h"
+      10                 :            : 
+      11                 :            : #if LIBSPDM_ENABLE_CAPABILITY_SET_CERT_CAP
+      12                 :            : 
+      13                 :          6 : libspdm_return_t libspdm_requester_set_certificate_test_send_message(
+      14                 :            :     void *spdm_context, size_t request_size, const void *request,
+      15                 :            :     uint64_t timeout)
+      16                 :            : {
+      17                 :            :     libspdm_test_context_t *spdm_test_context;
+      18                 :            :     uint32_t *session_id;
+      19                 :            :     libspdm_session_info_t *session_info;
+      20                 :            :     bool is_app_message;
+      21                 :            :     uint8_t *app_message;
+      22                 :            :     size_t app_message_size;
+      23                 :            :     uint8_t message_buffer[LIBSPDM_SENDER_BUFFER_SIZE];
+      24                 :            :     spdm_set_certificate_request_t *spdm_request;
+      25                 :            : 
+      26                 :          6 :     memcpy(message_buffer, request, request_size);
+      27                 :          6 :     libspdm_transport_test_decode_message(spdm_context, &session_id, &is_app_message, true,
+      28                 :            :                                           request_size, message_buffer, &app_message_size,
+      29                 :            :                                           (void **)&app_message);
+      30                 :            : 
+      31                 :          6 :     spdm_test_context = libspdm_get_test_context();
+      32   [ +  +  -  -  :          6 :     switch (spdm_test_context->case_id) {
+          +  +  +  -  +  
+                      - ]
+      33                 :          1 :     case 0x1:
+      34                 :          1 :         return LIBSPDM_STATUS_SEND_FAIL;
+      35                 :          1 :     case 0x2:
+      36                 :          1 :         spdm_request = (spdm_set_certificate_request_t *)app_message;
+      37                 :            : 
+      38                 :          1 :         assert_int_equal(spdm_request->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+      39                 :          1 :         assert_int_equal(spdm_request->header.request_response_code, SPDM_SET_CERTIFICATE);
+      40                 :          1 :         assert_int_equal(spdm_request->header.param1 & SPDM_SET_CERTIFICATE_REQUEST_SLOT_ID_MASK,
+      41                 :            :                          0);
+      42                 :          1 :         assert_int_equal(spdm_request->header.param2, 0);
+      43                 :            : 
+      44                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      45                 :          0 :     case 0x3:
+      46                 :          0 :         assert_true(false);
+      47                 :            : 
+      48                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      49                 :          0 :     case 0x4:
+      50                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+      51                 :          1 :     case 0x5:
+      52                 :          1 :         session_id = NULL;
+      53                 :          1 :         session_info = libspdm_get_session_info_via_session_id(spdm_context, 0xFFFFFFFF);
+      54         [ -  + ]:          1 :         if (session_info == NULL) {
+      55                 :          0 :             return LIBSPDM_STATUS_SEND_FAIL;
+      56                 :            :         }
+      57                 :          1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "Request (0x%zx):\n", request_size));
+      58                 :          1 :         libspdm_dump_hex(request, request_size);
+      59                 :            : 
+      60                 :          1 :         libspdm_get_scratch_buffer (spdm_context, (void **)&app_message, &app_message_size);
+      61                 :          1 :         libspdm_transport_test_decode_message(
+      62                 :            :             spdm_context, &session_id, &is_app_message,
+      63                 :            :             false, request_size, message_buffer,
+      64                 :            :             &app_message_size, (void **)&app_message);
+      65                 :            : 
+      66                 :            :         /* WALKAROUND: If just use single context to encode
+      67                 :            :          * message and then decode message */
+      68                 :            :         ((libspdm_secured_message_context_t
+      69                 :          1 :           *)(session_info->secured_message_context))
+      70                 :          1 :         ->application_secret.request_data_sequence_number--;
+      71                 :            : 
+      72                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      73                 :          1 :     case 0x6:
+      74                 :          1 :         spdm_request = (spdm_set_certificate_request_t *)app_message;
+      75                 :            : 
+      76                 :          1 :         assert_int_equal(spdm_request->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+      77                 :          1 :         assert_int_equal(spdm_request->header.request_response_code, SPDM_SET_CERTIFICATE);
+      78                 :          1 :         assert_int_equal(spdm_request->header.param1 & SPDM_SET_CERTIFICATE_REQUEST_SLOT_ID_MASK,
+      79                 :            :                          0);
+      80                 :          1 :         assert_int_equal(spdm_request->header.param2, 0);
+      81                 :            : 
+      82                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      83                 :          1 :     case 0x7:
+      84                 :          1 :         spdm_request = (spdm_set_certificate_request_t *)app_message;
+      85                 :            : 
+      86                 :          1 :         assert_int_equal(spdm_request->header.spdm_version, SPDM_MESSAGE_VERSION_13);
+      87                 :          1 :         assert_int_equal(spdm_request->header.request_response_code, SPDM_SET_CERTIFICATE);
+      88                 :          1 :         assert_int_equal(spdm_request->header.param1 & SPDM_SET_CERTIFICATE_REQUEST_SLOT_ID_MASK,
+      89                 :            :                          0);
+      90                 :          1 :         assert_int_equal((spdm_request->header.param1 &
+      91                 :            :                           SPDM_SET_CERTIFICATE_REQUEST_ATTRIBUTES_CERT_MODEL_MASK) >>
+      92                 :            :                          SPDM_SET_CERTIFICATE_REQUEST_ATTRIBUTES_CERT_MODEL_OFFSET,
+      93                 :            :                          SPDM_CERTIFICATE_INFO_CERT_MODEL_NONE);
+      94                 :          1 :         assert_int_equal(spdm_request->header.param1 &
+      95                 :            :                          SPDM_SET_CERTIFICATE_REQUEST_ATTRIBUTES_ERASE,
+      96                 :            :                          SPDM_SET_CERTIFICATE_REQUEST_ATTRIBUTES_ERASE);
+      97                 :          1 :         assert_int_equal(spdm_request->header.param2, 0);
+      98                 :            : 
+      99                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     100                 :          0 :     case 0x8:
+     101                 :          0 :         assert_true(false);
+     102                 :          0 :         return LIBSPDM_STATUS_SEND_FAIL;
+     103                 :          1 :     case 0x9:
+     104                 :          1 :         spdm_request = (spdm_set_certificate_request_t *)app_message;
+     105                 :            : 
+     106                 :          1 :         assert_int_equal(spdm_request->header.spdm_version, SPDM_MESSAGE_VERSION_13);
+     107                 :          1 :         assert_int_equal(spdm_request->header.request_response_code, SPDM_SET_CERTIFICATE);
+     108                 :          1 :         assert_int_equal(spdm_request->header.param1 & SPDM_SET_CERTIFICATE_REQUEST_SLOT_ID_MASK,
+     109                 :            :                          3);
+     110                 :          1 :         assert_int_equal((spdm_request->header.param1 &
+     111                 :            :                           SPDM_SET_CERTIFICATE_REQUEST_ATTRIBUTES_CERT_MODEL_MASK) >>
+     112                 :            :                          SPDM_SET_CERTIFICATE_REQUEST_ATTRIBUTES_CERT_MODEL_OFFSET,
+     113                 :            :                          SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT);
+     114                 :          1 :         assert_int_equal(spdm_request->header.param2, 1);
+     115                 :            : 
+     116                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     117                 :            : 
+     118                 :          0 :     default:
+     119                 :          0 :         return LIBSPDM_STATUS_SEND_FAIL;
+     120                 :            :     }
+     121                 :            : }
+     122                 :            : 
+     123                 :          5 : libspdm_return_t libspdm_requester_set_certificate_test_receive_message(
+     124                 :            :     void *spdm_context, size_t *response_size,
+     125                 :            :     void **response, uint64_t timeout)
+     126                 :            : {
+     127                 :            :     libspdm_test_context_t *spdm_test_context;
+     128                 :            : 
+     129                 :          5 :     spdm_test_context = libspdm_get_test_context();
+     130   [ -  +  -  -  :          5 :     switch (spdm_test_context->case_id) {
+          +  +  +  -  +  
+                      - ]
+     131                 :          0 :     case 0x1:
+     132                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+     133                 :            : 
+     134                 :          1 :     case 0x2: {
+     135                 :            :         spdm_set_certificate_response_t *spdm_response;
+     136                 :            :         size_t spdm_response_size;
+     137                 :            :         size_t transport_header_size;
+     138                 :            : 
+     139                 :          1 :         spdm_response_size = sizeof(spdm_set_certificate_response_t);
+     140                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     141                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     142                 :            : 
+     143                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     144                 :          1 :         spdm_response->header.request_response_code = SPDM_SET_CERTIFICATE_RSP;
+     145                 :          1 :         spdm_response->header.param1 = 0;
+     146                 :          1 :         spdm_response->header.param2 = 0;
+     147                 :            : 
+     148                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     149                 :            :                                               false, spdm_response_size,
+     150                 :            :                                               spdm_response, response_size,
+     151                 :            :                                               response);
+     152                 :            :     }
+     153                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     154                 :            : 
+     155                 :          0 :     case 0x3: {
+     156                 :            :         spdm_set_certificate_response_t *spdm_response;
+     157                 :            :         size_t spdm_response_size;
+     158                 :            :         size_t transport_header_size;
+     159                 :            : 
+     160                 :          0 :         spdm_response_size = sizeof(spdm_set_certificate_response_t);
+     161                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     162                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     163                 :            : 
+     164                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     165                 :          0 :         spdm_response->header.request_response_code = SPDM_SET_CERTIFICATE_RSP;
+     166                 :          0 :         spdm_response->header.param1 = 0;
+     167                 :          0 :         spdm_response->header.param2 = 0;
+     168                 :            : 
+     169                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     170                 :            :                                               false, spdm_response_size,
+     171                 :            :                                               spdm_response, response_size,
+     172                 :            :                                               response);
+     173                 :            :     }
+     174                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     175                 :            : 
+     176                 :          0 :     case 0x4: {
+     177                 :            :         spdm_set_certificate_response_t *spdm_response;
+     178                 :            :         size_t spdm_response_size;
+     179                 :            :         size_t transport_header_size;
+     180                 :            : 
+     181                 :          0 :         spdm_response_size = sizeof(spdm_set_certificate_response_t);
+     182                 :          0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     183                 :          0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     184                 :            : 
+     185                 :          0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     186                 :          0 :         spdm_response->header.request_response_code = SPDM_SET_CERTIFICATE_RSP;
+     187                 :          0 :         spdm_response->header.param1 = 1;
+     188                 :          0 :         spdm_response->header.param2 = 0;
+     189                 :            : 
+     190                 :          0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     191                 :            :                                               false, spdm_response_size,
+     192                 :            :                                               spdm_response, response_size,
+     193                 :            :                                               response);
+     194                 :            :     }
+     195                 :          0 :         return LIBSPDM_STATUS_SUCCESS;
+     196                 :            : 
+     197                 :          1 :     case 0x05: {
+     198                 :            :         spdm_set_certificate_response_t *spdm_response;
+     199                 :            :         size_t spdm_response_size;
+     200                 :            :         size_t transport_header_size;
+     201                 :            :         uint32_t session_id;
+     202                 :            :         libspdm_session_info_t *session_info;
+     203                 :            :         uint8_t *scratch_buffer;
+     204                 :            :         size_t scratch_buffer_size;
+     205                 :            : 
+     206                 :          1 :         session_id = 0xFFFFFFFF;
+     207                 :            : 
+     208                 :          1 :         spdm_response_size = sizeof(spdm_set_certificate_response_t);
+     209                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     210                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     211                 :            : 
+     212                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     213                 :          1 :         spdm_response->header.request_response_code = SPDM_SET_CERTIFICATE_RSP;
+     214                 :            :         /*slot id is 1*/
+     215                 :          1 :         spdm_response->header.param1 = 1;
+     216                 :          1 :         spdm_response->header.param2 = 0;
+     217                 :            : 
+     218                 :            :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+     219                 :            :          * transport_message is always in sender buffer. */
+     220                 :          1 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+     221                 :          1 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
+     222                 :            :                           scratch_buffer_size - transport_header_size,
+     223                 :            :                           spdm_response, spdm_response_size);
+     224                 :          1 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
+     225                 :          1 :         libspdm_transport_test_encode_message(spdm_context, &session_id, false,
+     226                 :            :                                               false, spdm_response_size,
+     227                 :            :                                               spdm_response, response_size,
+     228                 :            :                                               response);
+     229                 :          1 :         session_info = libspdm_get_session_info_via_session_id(
+     230                 :            :             spdm_context, session_id);
+     231         [ -  + ]:          1 :         if (session_info == NULL) {
+     232                 :          0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
+     233                 :            :         }
+     234                 :            :         /* WALKAROUND: If just use single context to encode message and then decode message */
+     235                 :            :         ((libspdm_secured_message_context_t
+     236                 :          1 :           *)(session_info->secured_message_context))
+     237                 :          1 :         ->application_secret.response_data_sequence_number--;
+     238                 :            :     }
+     239                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     240                 :            : 
+     241                 :          1 :     case 0x6: {
+     242                 :            :         spdm_set_certificate_response_t *spdm_response;
+     243                 :            :         size_t spdm_response_size;
+     244                 :            :         size_t transport_header_size;
+     245                 :            : 
+     246                 :          1 :         spdm_response_size = sizeof(spdm_set_certificate_response_t);
+     247                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     248                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     249                 :            : 
+     250                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     251                 :          1 :         spdm_response->header.request_response_code = SPDM_ERROR;
+     252                 :          1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_RESET_REQUIRED;
+     253                 :          1 :         spdm_response->header.param2 = 0;
+     254                 :            : 
+     255                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     256                 :            :                                               false, spdm_response_size,
+     257                 :            :                                               spdm_response, response_size,
+     258                 :            :                                               response);
+     259                 :            :     }
+     260                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     261                 :            : 
+     262                 :          1 :     case 0x7: {
+     263                 :            :         spdm_set_certificate_response_t *spdm_response;
+     264                 :            :         size_t spdm_response_size;
+     265                 :            :         size_t transport_header_size;
+     266                 :            : 
+     267                 :          1 :         spdm_response_size = sizeof(spdm_set_certificate_response_t);
+     268                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     269                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     270                 :            : 
+     271                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+     272                 :          1 :         spdm_response->header.request_response_code = SPDM_SET_CERTIFICATE_RSP;
+     273                 :          1 :         spdm_response->header.param1 = 0;
+     274                 :          1 :         spdm_response->header.param2 = 0;
+     275                 :            : 
+     276                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     277                 :            :                                               false, spdm_response_size,
+     278                 :            :                                               spdm_response, response_size,
+     279                 :            :                                               response);
+     280                 :            :     }
+     281                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     282                 :            : 
+     283                 :          0 :     case 0x8:
+     284                 :          0 :         assert_true(false);
+     285                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+     286                 :            : 
+     287                 :          1 :     case 0x9: {
+     288                 :            :         spdm_set_certificate_response_t *spdm_response;
+     289                 :            :         size_t spdm_response_size;
+     290                 :            :         size_t transport_header_size;
+     291                 :            : 
+     292                 :          1 :         spdm_response_size = sizeof(spdm_set_certificate_response_t);
+     293                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     294                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     295                 :            : 
+     296                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+     297                 :          1 :         spdm_response->header.request_response_code = SPDM_SET_CERTIFICATE_RSP;
+     298                 :          1 :         spdm_response->header.param1 = 3;
+     299                 :          1 :         spdm_response->header.param2 = 0;
+     300                 :            : 
+     301                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     302                 :            :                                               false, spdm_response_size,
+     303                 :            :                                               spdm_response, response_size,
+     304                 :            :                                               response);
+     305                 :            :     }
+     306                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     307                 :            : 
+     308                 :          0 :     default:
+     309                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+     310                 :            :     }
+     311                 :            : }
+     312                 :            : 
+     313                 :            : 
+     314                 :            : /**
+     315                 :            :  * Test 1: message could not be sent
+     316                 :            :  * Expected Behavior: get a RETURN_DEVICE_ERROR return code
+     317                 :            :  **/
+     318                 :          1 : void libspdm_test_requester_set_certificate_case1(void **state)
+     319                 :            : {
+     320                 :            :     libspdm_return_t status;
+     321                 :            :     libspdm_test_context_t *spdm_test_context;
+     322                 :            :     libspdm_context_t *spdm_context;
+     323                 :            : 
+     324                 :            :     void *data;
+     325                 :            :     size_t data_size;
+     326                 :            : 
+     327                 :          1 :     spdm_test_context = *state;
+     328                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     329                 :          1 :     spdm_test_context->case_id = 0x1;
+     330                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     331                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     332                 :            : 
+     333                 :          1 :     spdm_context->connection_info.connection_state =
+     334                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     335                 :          1 :     spdm_context->connection_info.capability.flags |=
+     336                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_CERT_CAP;
+     337                 :            : 
+     338                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     339                 :            :                                                     m_libspdm_use_asym_algo,
+     340                 :            :                                                     &data, &data_size, NULL, NULL);
+     341                 :            : 
+     342                 :          1 :     status = libspdm_set_certificate(spdm_context, NULL, 0, data, data_size);
+     343                 :            : 
+     344                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SEND_FAIL);
+     345                 :          1 :     free(data);
+     346                 :          1 : }
+     347                 :            : 
+     348                 :            : /**
+     349                 :            :  * Test 2: Successful response to set certificate for slot 0
+     350                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code
+     351                 :            :  **/
+     352                 :          1 : void libspdm_test_requester_set_certificate_case2(void **state)
+     353                 :            : {
+     354                 :            :     libspdm_return_t status;
+     355                 :            :     libspdm_test_context_t *spdm_test_context;
+     356                 :            :     libspdm_context_t *spdm_context;
+     357                 :            : 
+     358                 :            :     void *data;
+     359                 :            :     size_t data_size;
+     360                 :            : 
+     361                 :          1 :     spdm_test_context = *state;
+     362                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     363                 :          1 :     spdm_test_context->case_id = 0x2;
+     364                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     365                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     366                 :            : 
+     367                 :          1 :     spdm_context->connection_info.connection_state =
+     368                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     369                 :          1 :     spdm_context->connection_info.capability.flags |=
+     370                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_CERT_CAP;
+     371                 :            : 
+     372                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     373                 :            :                                                     m_libspdm_use_asym_algo,
+     374                 :            :                                                     &data, &data_size, NULL, NULL);
+     375                 :            : 
+     376                 :          1 :     status = libspdm_set_certificate(spdm_context, NULL, 0, data, data_size);
+     377                 :            : 
+     378                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     379                 :          1 :     free(data);
+     380                 :          1 : }
+     381                 :            : 
+     382                 :            : /**
+     383                 :            :  * Test 3: Unsuccessful response to set certificate for slot 0, because cert_chain is NULL.
+     384                 :            :  * Expected Behavior: get a LIBSPDM_STATUS_INVALID_PARAMETER return code
+     385                 :            :  **/
+     386                 :          1 : void libspdm_test_requester_set_certificate_case3(void **state)
+     387                 :            : {
+     388                 :            :     libspdm_return_t status;
+     389                 :            :     libspdm_test_context_t *spdm_test_context;
+     390                 :            :     libspdm_context_t *spdm_context;
+     391                 :            : 
+     392                 :          1 :     spdm_test_context = *state;
+     393                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     394                 :          1 :     spdm_test_context->case_id = 0x3;
+     395                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     396                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     397                 :            : 
+     398                 :          1 :     spdm_context->connection_info.connection_state =
+     399                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     400                 :          1 :     spdm_context->connection_info.capability.flags |=
+     401                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_CERT_CAP;
+     402                 :            : 
+     403                 :          1 :     status = libspdm_set_certificate(spdm_context, NULL, 0, NULL, 0);
+     404                 :            : 
+     405                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_PARAMETER);
+     406                 :          1 : }
+     407                 :            : 
+     408                 :            : /**
+     409                 :            :  * Test 5: Successful response to set certificate for slot 1 in secure session
+     410                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code
+     411                 :            :  **/
+     412                 :          1 : void libspdm_test_requester_set_certificate_case5(void **state)
+     413                 :            : {
+     414                 :            :     libspdm_return_t status;
+     415                 :            :     libspdm_test_context_t *spdm_test_context;
+     416                 :            :     libspdm_context_t *spdm_context;
+     417                 :            :     uint32_t session_id;
+     418                 :            :     libspdm_session_info_t *session_info;
+     419                 :            : 
+     420                 :            :     void *data;
+     421                 :            :     size_t data_size;
+     422                 :            : 
+     423                 :          1 :     spdm_test_context = *state;
+     424                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     425                 :          1 :     spdm_test_context->case_id = 0x05;
+     426                 :          1 :     spdm_context->connection_info.connection_state =
+     427                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     428                 :            : 
+     429                 :          1 :     spdm_context->connection_info.capability.flags |=
+     430                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+     431                 :          1 :     spdm_context->connection_info.capability.flags |=
+     432                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     433                 :          1 :     spdm_context->connection_info.capability.flags |=
+     434                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+     435                 :          1 :     spdm_context->connection_info.capability.flags |=
+     436                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+     437                 :          1 :     spdm_context->local_context.capability.flags |=
+     438                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     439                 :          1 :     spdm_context->local_context.capability.flags |=
+     440                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+     441                 :          1 :     spdm_context->local_context.capability.flags |=
+     442                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+     443                 :          1 :     spdm_context->connection_info.capability.flags |=
+     444                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_CERT_CAP;
+     445                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     446                 :            :         m_libspdm_use_dhe_algo;
+     447                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     448                 :            :         m_libspdm_use_aead_algo;
+     449                 :            : 
+     450                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     451                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     452                 :            :                                                     &data_size, NULL, NULL);
+     453                 :            : 
+     454                 :          1 :     session_id = 0xFFFFFFFF;
+     455                 :          1 :     session_info = &spdm_context->session_info[0];
+     456                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+     457                 :          1 :     libspdm_secured_message_set_session_state(session_info->secured_message_context,
+     458                 :            :                                               LIBSPDM_SESSION_STATE_ESTABLISHED);
+     459                 :            : 
+     460                 :            :     /* slot id is 1*/
+     461                 :          1 :     status = libspdm_set_certificate(spdm_context, &session_id, 1, data, data_size);
+     462                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     463                 :            : 
+     464                 :          1 :     free(data);
+     465                 :          1 : }
+     466                 :            : 
+     467                 :            : /**
+     468                 :            :  * Test 6: Successful response to set certificate for slot 0 with a reset required
+     469                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code
+     470                 :            :  **/
+     471                 :          1 : void libspdm_test_requester_set_certificate_case6(void **state)
+     472                 :            : {
+     473                 :            :     libspdm_return_t status;
+     474                 :            :     libspdm_test_context_t *spdm_test_context;
+     475                 :            :     libspdm_context_t *spdm_context;
+     476                 :            : 
+     477                 :            :     void *data;
+     478                 :            :     size_t data_size;
+     479                 :            : 
+     480                 :          1 :     spdm_test_context = *state;
+     481                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     482                 :          1 :     spdm_test_context->case_id = 0x6;
+     483                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     484                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     485                 :            : 
+     486                 :          1 :     spdm_context->connection_info.connection_state =
+     487                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     488                 :          1 :     spdm_context->connection_info.capability.flags |=
+     489                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_CERT_CAP |
+     490                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_INSTALL_RESET_CAP;
+     491                 :            : 
+     492                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     493                 :            :                                                     m_libspdm_use_asym_algo,
+     494                 :            :                                                     &data, &data_size, NULL, NULL);
+     495                 :            : 
+     496                 :          1 :     status = libspdm_set_certificate(spdm_context, NULL, 0, data, data_size);
+     497                 :            : 
+     498                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_RESET_REQUIRED_PEER);
+     499                 :          1 :     free(data);
+     500                 :          1 : }
+     501                 :            : 
+     502                 :            : /**
+     503                 :            :  * Test 7: Successful response to erase certificate for slot 0
+     504                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code
+     505                 :            :  **/
+     506                 :          1 : void libspdm_test_requester_set_certificate_case7(void **state)
+     507                 :            : {
+     508                 :            :     libspdm_return_t status;
+     509                 :            :     libspdm_test_context_t *spdm_test_context;
+     510                 :            :     libspdm_context_t *spdm_context;
+     511                 :            : 
+     512                 :          1 :     spdm_test_context = *state;
+     513                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     514                 :          1 :     spdm_test_context->case_id = 0x7;
+     515                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+     516                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     517                 :            : 
+     518                 :          1 :     spdm_context->connection_info.connection_state =
+     519                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     520                 :          1 :     spdm_context->connection_info.capability.flags |=
+     521                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_CERT_CAP;
+     522                 :            : 
+     523                 :          1 :     status = libspdm_set_certificate_ex(spdm_context, NULL, 0, NULL, 0,
+     524                 :            :                                         SPDM_SET_CERTIFICATE_REQUEST_ATTRIBUTES_ERASE, 0);
+     525                 :            : 
+     526                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     527                 :          1 : }
+     528                 :            : 
+     529                 :            : /**
+     530                 :            :  * Test 8: Illegal combination of MULTI_KEY_CONN_RSP = true, Erase = false, and SetCertModel = 0.
+     531                 :            :  * Expected Behavior: function returns LIBSPDM_STATUS_INVALID_PARAMETER.
+     532                 :            :  **/
+     533                 :          1 : void libspdm_test_requester_set_certificate_case8(void **state)
+     534                 :            : {
+     535                 :            :     libspdm_return_t status;
+     536                 :            :     libspdm_test_context_t *spdm_test_context;
+     537                 :            :     libspdm_context_t *spdm_context;
+     538                 :            : 
+     539                 :            :     void *data;
+     540                 :            :     size_t data_size;
+     541                 :            : 
+     542                 :          1 :     spdm_test_context = *state;
+     543                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     544                 :          1 :     spdm_test_context->case_id = 0x8;
+     545                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+     546                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     547                 :            : 
+     548                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     549                 :          1 :     spdm_context->connection_info.capability.flags |=
+     550                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_CERT_CAP;
+     551                 :          1 :     spdm_context->connection_info.multi_key_conn_rsp = true;
+     552                 :            : 
+     553                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     554                 :            :                                                     m_libspdm_use_asym_algo,
+     555                 :            :                                                     &data, &data_size, NULL, NULL);
+     556                 :            : 
+     557                 :          1 :     status = libspdm_set_certificate_ex(spdm_context, NULL, 0, data, data_size,
+     558                 :            :                                         (SPDM_CERTIFICATE_INFO_CERT_MODEL_NONE <<
+     559                 :            :                                          SPDM_SET_CERTIFICATE_REQUEST_ATTRIBUTES_CERT_MODEL_OFFSET),
+     560                 :            :                                         1);
+     561                 :            : 
+     562                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_PARAMETER);
+     563                 :          1 : }
+     564                 :            : 
+     565                 :            : /**
+     566                 :            :  * Test 9: Set MULTI_KEY_CONN_RSP = true, Erase = false, and SetCertModel = DeviceCert.
+     567                 :            :  * Expected Behavior: function returns LIBSPDM_STATUS_SUCCESS.
+     568                 :            :  **/
+     569                 :          1 : void libspdm_test_requester_set_certificate_case9(void **state)
+     570                 :            : {
+     571                 :            :     libspdm_return_t status;
+     572                 :            :     libspdm_test_context_t *spdm_test_context;
+     573                 :            :     libspdm_context_t *spdm_context;
+     574                 :            : 
+     575                 :            :     void *data;
+     576                 :            :     size_t data_size;
+     577                 :            : 
+     578                 :          1 :     spdm_test_context = *state;
+     579                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     580                 :          1 :     spdm_test_context->case_id = 0x9;
+     581                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+     582                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     583                 :            : 
+     584                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     585                 :          1 :     spdm_context->connection_info.capability.flags |=
+     586                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_CERT_CAP;
+     587                 :          1 :     spdm_context->connection_info.multi_key_conn_rsp = true;
+     588                 :            : 
+     589                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     590                 :            :                                                     m_libspdm_use_asym_algo,
+     591                 :            :                                                     &data, &data_size, NULL, NULL);
+     592                 :            : 
+     593                 :          1 :     status = libspdm_set_certificate_ex(spdm_context, NULL, 3, data, data_size,
+     594                 :            :                                         (SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT <<
+     595                 :            :                                          SPDM_SET_CERTIFICATE_REQUEST_ATTRIBUTES_CERT_MODEL_OFFSET),
+     596                 :            :                                         1);
+     597                 :            : 
+     598                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     599                 :          1 : }
+     600                 :            : 
+     601                 :            : libspdm_test_context_t m_libspdm_requester_set_certificate_test_context = {
+     602                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+     603                 :            :     true,
+     604                 :            :     libspdm_requester_set_certificate_test_send_message,
+     605                 :            :     libspdm_requester_set_certificate_test_receive_message,
+     606                 :            : };
+     607                 :            : 
+     608                 :          1 : int libspdm_requester_set_certificate_test_main(void)
+     609                 :            : {
+     610                 :          1 :     const struct CMUnitTest spdm_requester_set_certificate_tests[] = {
+     611                 :            :         /* SendRequest failed*/
+     612                 :            :         cmocka_unit_test(libspdm_test_requester_set_certificate_case1),
+     613                 :            :         /* Successful response to set certificate*/
+     614                 :            :         cmocka_unit_test(libspdm_test_requester_set_certificate_case2),
+     615                 :            :         /* Set null cert_chain for slot 0*/
+     616                 :            :         cmocka_unit_test(libspdm_test_requester_set_certificate_case3),
+     617                 :            :         /* Successful response to set certificate for slot 1 in secure session*/
+     618                 :            :         cmocka_unit_test(libspdm_test_requester_set_certificate_case5),
+     619                 :            :         /* Successful response to set certificate with a reset required */
+     620                 :            :         cmocka_unit_test(libspdm_test_requester_set_certificate_case6),
+     621                 :            :         /* Successful response to erase certificate*/
+     622                 :            :         cmocka_unit_test(libspdm_test_requester_set_certificate_case7),
+     623                 :            :         cmocka_unit_test(libspdm_test_requester_set_certificate_case8),
+     624                 :            :         cmocka_unit_test(libspdm_test_requester_set_certificate_case9),
+     625                 :            :     };
+     626                 :            : 
+     627                 :          1 :     libspdm_setup_test_context(&m_libspdm_requester_set_certificate_test_context);
+     628                 :            : 
+     629                 :          1 :     return cmocka_run_group_tests(spdm_requester_set_certificate_tests,
+     630                 :            :                                   libspdm_unit_test_group_setup,
+     631                 :            :                                   libspdm_unit_test_group_teardown);
+     632                 :            : }
+     633                 :            : 
+     634                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_SET_CERT_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/set_key_pair_info.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_requester/set_key_pair_info.c.func-sort-c.html new file mode 100644 index 00000000000..519fff3e11f --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/set_key_pair_info.c.func-sort-c.html @@ -0,0 +1,105 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/set_key_pair_info.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - set_key_pair_info.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:919595.8 %
Date:2024-09-22 08:21:07Functions:66100.0 %
Branches:4666.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_set_key_pair_info_test_main1
libspdm_test_requester_set_key_pair_info_case11
libspdm_test_requester_set_key_pair_info_case21
libspdm_test_requester_set_key_pair_info_case31
libspdm_requester_set_key_pair_info_test_receive_message3
libspdm_requester_set_key_pair_info_test_send_message3
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/set_key_pair_info.c.func.html b/coverage_log/unit_test/test_spdm_requester/set_key_pair_info.c.func.html new file mode 100644 index 00000000000..0052112ea09 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/set_key_pair_info.c.func.html @@ -0,0 +1,105 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/set_key_pair_info.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - set_key_pair_info.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:919595.8 %
Date:2024-09-22 08:21:07Functions:66100.0 %
Branches:4666.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_set_key_pair_info_test_main1
libspdm_requester_set_key_pair_info_test_receive_message3
libspdm_requester_set_key_pair_info_test_send_message3
libspdm_test_requester_set_key_pair_info_case11
libspdm_test_requester_set_key_pair_info_case21
libspdm_test_requester_set_key_pair_info_case31
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/set_key_pair_info.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/set_key_pair_info.c.gcov.html new file mode 100644 index 00000000000..36b834e129e --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/set_key_pair_info.c.gcov.html @@ -0,0 +1,341 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/set_key_pair_info.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - set_key_pair_info.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:919595.8 %
Date:2024-09-22 08:21:07Functions:66100.0 %
Branches:4666.7 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2024 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_requester_lib.h"
+       9                 :            : #include "internal/libspdm_secured_message_lib.h"
+      10                 :            : 
+      11                 :            : #if LIBSPDM_ENABLE_CAPABILITY_SET_KEY_PAIR_INFO_CAP
+      12                 :            : 
+      13                 :          3 : libspdm_return_t libspdm_requester_set_key_pair_info_test_send_message(
+      14                 :            :     void *spdm_context, size_t request_size, const void *request,
+      15                 :            :     uint64_t timeout)
+      16                 :            : {
+      17                 :            :     libspdm_test_context_t *spdm_test_context;
+      18                 :            : 
+      19                 :          3 :     spdm_test_context = libspdm_get_test_context();
+      20         [ +  - ]:          3 :     switch (spdm_test_context->case_id) {
+      21                 :          3 :     case 0x1:
+      22                 :            :     case 0x2:
+      23                 :            :     case 0x3:
+      24                 :          3 :         return LIBSPDM_STATUS_SUCCESS;
+      25                 :          0 :     default:
+      26                 :          0 :         return LIBSPDM_STATUS_SEND_FAIL;
+      27                 :            :     }
+      28                 :            : }
+      29                 :            : 
+      30                 :          3 : libspdm_return_t libspdm_requester_set_key_pair_info_test_receive_message(
+      31                 :            :     void *spdm_context, size_t *response_size,
+      32                 :            :     void **response, uint64_t timeout)
+      33                 :            : {
+      34                 :            :     libspdm_test_context_t *spdm_test_context;
+      35                 :            : 
+      36                 :          3 :     spdm_test_context = libspdm_get_test_context();
+      37   [ +  +  +  - ]:          3 :     switch (spdm_test_context->case_id) {
+      38                 :            : 
+      39                 :          1 :     case 0x1: {
+      40                 :            :         spdm_key_pair_info_response_t *spdm_response;
+      41                 :            :         size_t spdm_response_size;
+      42                 :            :         size_t transport_header_size;
+      43                 :            : 
+      44                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+      45                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+      46                 :          1 :         spdm_response_size = sizeof(spdm_key_pair_info_response_t);
+      47                 :            : 
+      48                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+      49                 :          1 :         spdm_response->header.request_response_code = SPDM_SET_KEY_PAIR_INFO_ACK;
+      50                 :          1 :         spdm_response->header.param1 = 0;
+      51                 :          1 :         spdm_response->header.param2 = 0;
+      52                 :            : 
+      53                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+      54                 :            :                                               false, spdm_response_size,
+      55                 :            :                                               spdm_response, response_size,
+      56                 :            :                                               response);
+      57                 :            :     }
+      58                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      59                 :          1 :     case 0x2: {
+      60                 :            :         spdm_key_pair_info_response_t *spdm_response;
+      61                 :            :         size_t spdm_response_size;
+      62                 :            :         size_t transport_header_size;
+      63                 :            : 
+      64                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+      65                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+      66                 :          1 :         spdm_response_size = sizeof(spdm_key_pair_info_response_t);
+      67                 :            : 
+      68                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+      69                 :          1 :         spdm_response->header.request_response_code = SPDM_SET_KEY_PAIR_INFO_ACK;
+      70                 :          1 :         spdm_response->header.param1 = 0;
+      71                 :          1 :         spdm_response->header.param2 = 0;
+      72                 :            : 
+      73                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+      74                 :            :                                               false, spdm_response_size,
+      75                 :            :                                               spdm_response, response_size,
+      76                 :            :                                               response);
+      77                 :            :     }
+      78                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+      79                 :            : 
+      80                 :          1 :     case 0x3: {
+      81                 :            :         spdm_key_pair_info_response_t *spdm_response;
+      82                 :            :         size_t spdm_response_size;
+      83                 :            :         size_t transport_header_size;
+      84                 :            : 
+      85                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+      86                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+      87                 :          1 :         spdm_response_size = sizeof(spdm_key_pair_info_response_t);
+      88                 :            : 
+      89                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+      90                 :          1 :         spdm_response->header.request_response_code = SPDM_KEY_PAIR_INFO;
+      91                 :          1 :         spdm_response->header.param1 = 0;
+      92                 :          1 :         spdm_response->header.param2 = 0;
+      93                 :            : 
+      94                 :          1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
+      95                 :            :                                               false, spdm_response_size,
+      96                 :            :                                               spdm_response, response_size,
+      97                 :            :                                               response);
+      98                 :            :     }
+      99                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     100                 :            : 
+     101                 :          0 :     default:
+     102                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+     103                 :            :     }
+     104                 :            : }
+     105                 :            : 
+     106                 :            : /**
+     107                 :            :  * Test 1: Successful response to set key pair info
+     108                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code
+     109                 :            :  **/
+     110                 :          1 : void libspdm_test_requester_set_key_pair_info_case1(void **state)
+     111                 :            : {
+     112                 :            :     libspdm_return_t status;
+     113                 :            :     libspdm_test_context_t *spdm_test_context;
+     114                 :            :     libspdm_context_t *spdm_context;
+     115                 :            : 
+     116                 :            :     uint8_t key_pair_id;
+     117                 :            :     uint8_t operation;
+     118                 :            :     uint16_t desired_key_usage;
+     119                 :            :     uint32_t desired_asym_algo;
+     120                 :            :     uint8_t desired_assoc_cert_slot_mask;
+     121                 :            : 
+     122                 :          1 :     spdm_test_context = *state;
+     123                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     124                 :          1 :     spdm_test_context->case_id = 0x1;
+     125                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+     126                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     127                 :            : 
+     128                 :          1 :     spdm_context->connection_info.connection_state =
+     129                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     130                 :          1 :     spdm_context->connection_info.capability.flags |=
+     131                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_KEY_PAIR_INFO_CAP;
+     132                 :            : 
+     133                 :          1 :     key_pair_id = 1;
+     134                 :          1 :     operation = SPDM_SET_KEY_PAIR_INFO_ERASE_OPERATION;
+     135                 :          1 :     desired_key_usage = 0;
+     136                 :          1 :     desired_asym_algo = 0;
+     137                 :          1 :     desired_assoc_cert_slot_mask = 0;
+     138                 :          1 :     status = libspdm_set_key_pair_info(spdm_context, NULL, key_pair_id,
+     139                 :            :                                        operation, desired_key_usage, desired_asym_algo,
+     140                 :            :                                        desired_assoc_cert_slot_mask);
+     141                 :            : 
+     142                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     143                 :            : 
+     144                 :            :     /*wrong desired_assoc_cert_slot_mask when operation is erase*/
+     145                 :          1 :     desired_assoc_cert_slot_mask = 1;
+     146                 :          1 :     status = libspdm_set_key_pair_info(spdm_context, NULL, key_pair_id,
+     147                 :            :                                        operation, desired_key_usage, desired_asym_algo,
+     148                 :            :                                        desired_assoc_cert_slot_mask);
+     149                 :            : 
+     150                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_PARAMETER);
+     151                 :          1 : }
+     152                 :            : 
+     153                 :            : /**
+     154                 :            :  * Test 2: Fail case, The response version is incorrect .
+     155                 :            :  * Expected Behavior: returns a status of LIBSPDM_STATUS_INVALID_MSG_FIELD.
+     156                 :            :  **/
+     157                 :          1 : void libspdm_test_requester_set_key_pair_info_case2(void **state)
+     158                 :            : {
+     159                 :            :     libspdm_return_t status;
+     160                 :            :     libspdm_test_context_t *spdm_test_context;
+     161                 :            :     libspdm_context_t *spdm_context;
+     162                 :            : 
+     163                 :            :     uint8_t key_pair_id;
+     164                 :            :     uint8_t operation;
+     165                 :            :     uint16_t desired_key_usage;
+     166                 :            :     uint32_t desired_asym_algo;
+     167                 :            :     uint8_t desired_assoc_cert_slot_mask;
+     168                 :            : 
+     169                 :          1 :     spdm_test_context = *state;
+     170                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     171                 :          1 :     spdm_test_context->case_id = 0x2;
+     172                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+     173                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     174                 :            : 
+     175                 :          1 :     spdm_context->connection_info.connection_state =
+     176                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     177                 :          1 :     spdm_context->connection_info.capability.flags |=
+     178                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_KEY_PAIR_INFO_CAP;
+     179                 :            : 
+     180                 :          1 :     key_pair_id = 1;
+     181                 :          1 :     operation = SPDM_SET_KEY_PAIR_INFO_ERASE_OPERATION;
+     182                 :          1 :     desired_key_usage = 0;
+     183                 :          1 :     desired_asym_algo = 0;
+     184                 :          1 :     desired_assoc_cert_slot_mask = 0;
+     185                 :          1 :     status = libspdm_set_key_pair_info(spdm_context, NULL, key_pair_id,
+     186                 :            :                                        operation, desired_key_usage, desired_asym_algo,
+     187                 :            :                                        desired_assoc_cert_slot_mask);
+     188                 :            : 
+     189                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+     190                 :          1 : }
+     191                 :            : 
+     192                 :            : /**
+     193                 :            :  * Test 3: Fail case, The response code is incorrect
+     194                 :            :  * Expected Behavior: returns a status of LIBSPDM_STATUS_INVALID_MSG_FIELD.
+     195                 :            :  **/
+     196                 :          1 : void libspdm_test_requester_set_key_pair_info_case3(void **state)
+     197                 :            : {
+     198                 :            :     libspdm_return_t status;
+     199                 :            :     libspdm_test_context_t *spdm_test_context;
+     200                 :            :     libspdm_context_t *spdm_context;
+     201                 :            : 
+     202                 :            :     uint8_t key_pair_id;
+     203                 :            :     uint8_t operation;
+     204                 :            :     uint16_t desired_key_usage;
+     205                 :            :     uint32_t desired_asym_algo;
+     206                 :            :     uint8_t desired_assoc_cert_slot_mask;
+     207                 :            : 
+     208                 :          1 :     spdm_test_context = *state;
+     209                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     210                 :          1 :     spdm_test_context->case_id = 0x3;
+     211                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+     212                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     213                 :            : 
+     214                 :          1 :     spdm_context->connection_info.connection_state =
+     215                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     216                 :          1 :     spdm_context->connection_info.capability.flags |=
+     217                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_KEY_PAIR_INFO_CAP;
+     218                 :            : 
+     219                 :          1 :     key_pair_id = 1;
+     220                 :          1 :     operation = SPDM_SET_KEY_PAIR_INFO_ERASE_OPERATION;
+     221                 :          1 :     desired_key_usage = 0;
+     222                 :          1 :     desired_asym_algo = 0;
+     223                 :          1 :     desired_assoc_cert_slot_mask = 0;
+     224                 :          1 :     status = libspdm_set_key_pair_info(spdm_context, NULL, key_pair_id,
+     225                 :            :                                        operation, desired_key_usage, desired_asym_algo,
+     226                 :            :                                        desired_assoc_cert_slot_mask);
+     227                 :            : 
+     228                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+     229                 :          1 : }
+     230                 :            : 
+     231                 :          1 : int libspdm_requester_set_key_pair_info_test_main(void)
+     232                 :            : {
+     233                 :          1 :     const struct CMUnitTest spdm_requester_set_key_pair_info_tests[] = {
+     234                 :            :         /* Successful response to set key pair info, key_pair_id is 1*/
+     235                 :            :         cmocka_unit_test(libspdm_test_requester_set_key_pair_info_case1),
+     236                 :            :         /* The response version is incorrect */
+     237                 :            :         cmocka_unit_test(libspdm_test_requester_set_key_pair_info_case2),
+     238                 :            :         /* The response code is incorrect */
+     239                 :            :         cmocka_unit_test(libspdm_test_requester_set_key_pair_info_case3),
+     240                 :            :     };
+     241                 :            : 
+     242                 :          1 :     libspdm_test_context_t test_context = {
+     243                 :            :         LIBSPDM_TEST_CONTEXT_VERSION,
+     244                 :            :         true,
+     245                 :            :         libspdm_requester_set_key_pair_info_test_send_message,
+     246                 :            :         libspdm_requester_set_key_pair_info_test_receive_message,
+     247                 :            :     };
+     248                 :            : 
+     249                 :          1 :     libspdm_setup_test_context(&test_context);
+     250                 :            : 
+     251                 :          1 :     return cmocka_run_group_tests(spdm_requester_set_key_pair_info_tests,
+     252                 :            :                                   libspdm_unit_test_group_setup,
+     253                 :            :                                   libspdm_unit_test_group_teardown);
+     254                 :            : }
+     255                 :            : 
+     256                 :            : #endif /*LIBSPDM_ENABLE_CAPABILITY_SET_KEY_PAIR_INFO_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/subscribe_event_types.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_requester/subscribe_event_types.c.func-sort-c.html new file mode 100644 index 00000000000..3bb35a9ec1e --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/subscribe_event_types.c.func-sort-c.html @@ -0,0 +1,109 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/subscribe_event_types.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - subscribe_event_types.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:101101100.0 %
Date:2024-09-22 08:21:07Functions:77100.0 %
Branches:4666.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_subscribe_event_types_test_main1
libspdm_test_requester_subscribe_event_types_case11
libspdm_test_requester_subscribe_event_types_case21
libspdm_test_requester_subscribe_event_types_case31
receive_message3
send_message3
set_standard_state3
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/subscribe_event_types.c.func.html b/coverage_log/unit_test/test_spdm_requester/subscribe_event_types.c.func.html new file mode 100644 index 00000000000..f8e0abab4ce --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/subscribe_event_types.c.func.html @@ -0,0 +1,109 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/subscribe_event_types.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - subscribe_event_types.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:101101100.0 %
Date:2024-09-22 08:21:07Functions:77100.0 %
Branches:4666.7 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_subscribe_event_types_test_main1
libspdm_test_requester_subscribe_event_types_case11
libspdm_test_requester_subscribe_event_types_case21
libspdm_test_requester_subscribe_event_types_case31
receive_message3
send_message3
set_standard_state3
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/subscribe_event_types.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/subscribe_event_types.c.gcov.html new file mode 100644 index 00000000000..804f19bf211 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/subscribe_event_types.c.gcov.html @@ -0,0 +1,355 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/subscribe_event_types.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - subscribe_event_types.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:101101100.0 %
Date:2024-09-22 08:21:07Functions:77100.0 %
Branches:4666.7 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2024 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_requester_lib.h"
+       9                 :            : #include "internal/libspdm_secured_message_lib.h"
+      10                 :            : 
+      11                 :            : #if LIBSPDM_EVENT_RECIPIENT_SUPPORT
+      12                 :            : 
+      13                 :            : static const uint32_t m_session_id = 0xffffffff;
+      14                 :            : 
+      15                 :            : static uint8_t m_spdm_request_buffer[0x1000];
+      16                 :            : 
+      17                 :            : static struct test_params {
+      18                 :            :     uint8_t subscribe_event_group_count;
+      19                 :            :     uint32_t subscribe_list_len;
+      20                 :            :     uint8_t subscribe_list[0x1000];
+      21                 :            : } test_params;
+      22                 :            : 
+      23                 :          3 : static void set_standard_state(libspdm_context_t *spdm_context, uint32_t *session_id)
+      24                 :            : {
+      25                 :            :     libspdm_session_info_t *session_info;
+      26                 :            : 
+      27                 :          3 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+      28                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+      29                 :          3 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+      30                 :            : 
+      31                 :          3 :     spdm_context->connection_info.capability.flags |=
+      32                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EVENT_CAP;
+      33                 :          3 :     spdm_context->connection_info.capability.flags |=
+      34                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+      35                 :          3 :     spdm_context->connection_info.capability.flags |=
+      36                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+      37                 :          3 :     spdm_context->connection_info.capability.flags |=
+      38                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+      39                 :            : 
+      40                 :          3 :     spdm_context->local_context.capability.flags |=
+      41                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+      42                 :          3 :     spdm_context->local_context.capability.flags |=
+      43                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+      44                 :          3 :     spdm_context->local_context.capability.flags |=
+      45                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+      46                 :            : 
+      47                 :          3 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+      48                 :          3 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+      49                 :          3 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+      50                 :          3 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+      51                 :            : 
+      52                 :          3 :     *session_id = m_session_id;
+      53                 :          3 :     session_info = &spdm_context->session_info[0];
+      54                 :          3 :     libspdm_session_info_init(spdm_context, session_info, *session_id, true);
+      55                 :          3 :     libspdm_secured_message_set_session_state(
+      56                 :            :         session_info->secured_message_context, LIBSPDM_SESSION_STATE_ESTABLISHED);
+      57                 :          3 : }
+      58                 :            : 
+      59                 :          3 : static libspdm_return_t send_message(
+      60                 :            :     void *spdm_context, size_t request_size, const void *request, uint64_t timeout)
+      61                 :            : {
+      62                 :            :     libspdm_return_t status;
+      63                 :            :     uint32_t session_id;
+      64                 :            :     uint32_t *message_session_id;
+      65                 :            :     spdm_subscribe_event_types_request_t *spdm_message;
+      66                 :            :     bool is_app_message;
+      67                 :            :     void *spdm_request_buffer;
+      68                 :            :     size_t spdm_request_size;
+      69                 :            :     libspdm_session_info_t *session_info;
+      70                 :            :     uint8_t request_buffer[0x1000];
+      71                 :            : 
+      72                 :            :     /* Workaround request being const. */
+      73                 :          3 :     libspdm_copy_mem(request_buffer, sizeof(request_buffer), request, request_size);
+      74                 :            : 
+      75                 :          3 :     session_id = m_session_id;
+      76                 :          3 :     session_info = libspdm_get_session_info_via_session_id(spdm_context, session_id);
+      77         [ -  + ]:          3 :     LIBSPDM_ASSERT(session_info != NULL);
+      78                 :            : 
+      79                 :          3 :     ((libspdm_secured_message_context_t *)(session_info->secured_message_context))->
+      80                 :          3 :     application_secret.request_data_sequence_number--;
+      81                 :            : 
+      82                 :          3 :     spdm_request_buffer = m_spdm_request_buffer;
+      83                 :          3 :     spdm_request_size = sizeof(m_spdm_request_buffer);
+      84                 :            : 
+      85                 :          3 :     status = libspdm_transport_test_decode_message(spdm_context, &message_session_id,
+      86                 :            :                                                    &is_app_message, true,
+      87                 :            :                                                    request_size, request_buffer,
+      88                 :            :                                                    &spdm_request_size, &spdm_request_buffer);
+      89                 :            : 
+      90                 :          3 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+      91                 :            : 
+      92                 :          3 :     spdm_message = spdm_request_buffer;
+      93                 :            : 
+      94                 :          3 :     assert_int_equal(spdm_message->header.spdm_version, SPDM_MESSAGE_VERSION_13);
+      95                 :          3 :     assert_int_equal(spdm_message->header.request_response_code, SPDM_SUBSCRIBE_EVENT_TYPES);
+      96                 :          3 :     assert_int_equal(spdm_message->header.param1, test_params.subscribe_event_group_count);
+      97                 :          3 :     assert_int_equal(spdm_message->header.param2, 0);
+      98                 :            : 
+      99         [ +  + ]:          3 :     if (test_params.subscribe_event_group_count == 0) {
+     100                 :          1 :         assert_int_equal(sizeof(spdm_message->header), spdm_request_size);
+     101                 :            :     } else {
+     102                 :          2 :         assert_int_equal(spdm_message->subscribe_list_len, test_params.subscribe_list_len);
+     103                 :          2 :         assert_memory_equal(spdm_message + 1, test_params.subscribe_list,
+     104                 :            :                             spdm_message->subscribe_list_len);
+     105                 :            :     }
+     106                 :            : 
+     107                 :          3 :     return LIBSPDM_STATUS_SUCCESS;
+     108                 :            : }
+     109                 :            : 
+     110                 :          3 : static libspdm_return_t receive_message(
+     111                 :            :     void *spdm_context, size_t *response_size, void **response, uint64_t timeout)
+     112                 :            : {
+     113                 :            :     spdm_subscribe_event_types_ack_response_t *spdm_response;
+     114                 :            :     size_t spdm_response_size;
+     115                 :            :     size_t transport_header_size;
+     116                 :            :     uint32_t session_id;
+     117                 :            :     libspdm_session_info_t *session_info;
+     118                 :            :     uint8_t *scratch_buffer;
+     119                 :            :     size_t scratch_buffer_size;
+     120                 :            : 
+     121                 :          3 :     transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     122                 :          3 :     spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     123                 :            : 
+     124                 :          3 :     session_id = m_session_id;
+     125                 :          3 :     session_info = libspdm_get_session_info_via_session_id(spdm_context, session_id);
+     126         [ -  + ]:          3 :     LIBSPDM_ASSERT((session_info != NULL));
+     127                 :            : 
+     128                 :          3 :     transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     129                 :          3 :     spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     130                 :            : 
+     131                 :          3 :     spdm_response_size = sizeof(spdm_subscribe_event_types_ack_response_t);
+     132                 :          3 :     libspdm_zero_mem(spdm_response, spdm_response_size);
+     133                 :            : 
+     134                 :          3 :     spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+     135                 :          3 :     spdm_response->header.request_response_code = SPDM_SUBSCRIBE_EVENT_TYPES_ACK;
+     136                 :          3 :     spdm_response->header.param1 = 0;
+     137                 :          3 :     spdm_response->header.param2 = 0;
+     138                 :            : 
+     139                 :            :     /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
+     140                 :            :      * transport_message is always in sender buffer. */
+     141                 :          3 :     libspdm_get_scratch_buffer(spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
+     142                 :          3 :     libspdm_copy_mem(scratch_buffer + transport_header_size,
+     143                 :            :                      scratch_buffer_size - transport_header_size,
+     144                 :            :                      spdm_response, spdm_response_size);
+     145                 :            : 
+     146                 :          3 :     spdm_response = (void *)(scratch_buffer + transport_header_size);
+     147                 :            : 
+     148                 :          3 :     libspdm_transport_test_encode_message(spdm_context, &session_id,
+     149                 :            :                                           false, false, spdm_response_size,
+     150                 :            :                                           spdm_response, response_size, response);
+     151                 :            : 
+     152                 :            :     /* Workaround: Use single context to encode message and then decode message. */
+     153                 :          3 :     ((libspdm_secured_message_context_t *)(session_info->secured_message_context))->
+     154                 :          3 :     application_secret.response_data_sequence_number--;
+     155                 :            : 
+     156                 :          3 :     return LIBSPDM_STATUS_SUCCESS;
+     157                 :            : }
+     158                 :            : 
+     159                 :            : /**
+     160                 :            :  * Test 1: Successful response to subscribe event types that clears all subscriptions.
+     161                 :            :  * Expected Behavior: Returns LIBSPDM_STATUS_SUCCESS.
+     162                 :            :  **/
+     163                 :          1 : static void libspdm_test_requester_subscribe_event_types_case1(void **state)
+     164                 :            : {
+     165                 :            :     libspdm_return_t status;
+     166                 :            :     libspdm_test_context_t *spdm_test_context;
+     167                 :            :     libspdm_context_t *spdm_context;
+     168                 :            :     uint32_t session_id;
+     169                 :            : 
+     170                 :          1 :     spdm_test_context = *state;
+     171                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     172                 :          1 :     spdm_test_context->case_id = 0x1;
+     173                 :            : 
+     174                 :          1 :     set_standard_state(spdm_context, &session_id);
+     175                 :          1 :     test_params.subscribe_event_group_count = 0;
+     176                 :          1 :     test_params.subscribe_list_len = 0;
+     177                 :            : 
+     178                 :          1 :     status = libspdm_subscribe_event_types(spdm_context, session_id,
+     179                 :          1 :                                            test_params.subscribe_event_group_count,
+     180                 :            :                                            test_params.subscribe_list_len, NULL);
+     181                 :            : 
+     182                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     183                 :          1 : }
+     184                 :            : 
+     185                 :            : /**
+     186                 :            :  * Test 2: Successful response to subscribe event types that includes one event group and two event
+     187                 :            :  *         types.
+     188                 :            :  * Expected Behavior: Returns LIBSPDM_STATUS_SUCCESS.
+     189                 :            :  **/
+     190                 :          1 : static void libspdm_test_requester_subscribe_event_types_case2(void **state)
+     191                 :            : {
+     192                 :            :     libspdm_return_t status;
+     193                 :            :     libspdm_test_context_t *spdm_test_context;
+     194                 :            :     libspdm_context_t *spdm_context;
+     195                 :            :     uint32_t session_id;
+     196                 :            :     uint8_t event_group_size;
+     197                 :            : 
+     198                 :          1 :     spdm_test_context = *state;
+     199                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     200                 :          1 :     spdm_test_context->case_id = 0x2;
+     201                 :            : 
+     202                 :          1 :     set_standard_state(spdm_context, &session_id);
+     203                 :          1 :     generate_dmtf_event_group(test_params.subscribe_list, &event_group_size, 0,
+     204                 :            :                               true, true, false, false);
+     205                 :          1 :     test_params.subscribe_event_group_count = 1;
+     206                 :          1 :     test_params.subscribe_list_len = event_group_size;
+     207                 :            : 
+     208                 :          1 :     status = libspdm_subscribe_event_types(spdm_context, session_id,
+     209                 :          1 :                                            test_params.subscribe_event_group_count,
+     210                 :            :                                            test_params.subscribe_list_len,
+     211                 :            :                                            test_params.subscribe_list);
+     212                 :            : 
+     213                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     214                 :          1 : }
+     215                 :            : 
+     216                 :            : /**
+     217                 :            :  * Test 3: Successful response to subscribe event types that includes one event group and all event
+     218                 :            :  *         types using the AllEventTypes attribute.
+     219                 :            :  * Expected Behavior: Returns LIBSPDM_STATUS_SUCCESS.
+     220                 :            :  **/
+     221                 :          1 : static void libspdm_test_requester_subscribe_event_types_case3(void **state)
+     222                 :            : {
+     223                 :            :     libspdm_return_t status;
+     224                 :            :     libspdm_test_context_t *spdm_test_context;
+     225                 :            :     libspdm_context_t *spdm_context;
+     226                 :            :     uint32_t session_id;
+     227                 :            :     uint8_t event_group_size;
+     228                 :            : 
+     229                 :          1 :     spdm_test_context = *state;
+     230                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     231                 :          1 :     spdm_test_context->case_id = 0x3;
+     232                 :            : 
+     233                 :          1 :     set_standard_state(spdm_context, &session_id);
+     234                 :          1 :     generate_dmtf_event_group(test_params.subscribe_list, &event_group_size,
+     235                 :            :                               SPDM_SUBSCRIBE_EVENT_TYPES_REQUEST_ATTRIBUTE_ALL,
+     236                 :            :                               false, false, false, false);
+     237                 :          1 :     test_params.subscribe_event_group_count = 1;
+     238                 :          1 :     test_params.subscribe_list_len = event_group_size;
+     239                 :            : 
+     240                 :          1 :     status = libspdm_subscribe_event_types(spdm_context, session_id,
+     241                 :          1 :                                            test_params.subscribe_event_group_count,
+     242                 :            :                                            test_params.subscribe_list_len,
+     243                 :            :                                            test_params.subscribe_list);
+     244                 :            : 
+     245                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     246                 :          1 : }
+     247                 :            : 
+     248                 :          1 : int libspdm_requester_subscribe_event_types_test_main(void)
+     249                 :            : {
+     250                 :          1 :     libspdm_test_context_t test_context = {
+     251                 :            :         LIBSPDM_TEST_CONTEXT_VERSION,
+     252                 :            :         true,
+     253                 :            :         send_message,
+     254                 :            :         receive_message,
+     255                 :            :     };
+     256                 :            : 
+     257                 :          1 :     const struct CMUnitTest spdm_requester_get_event_types_tests[] = {
+     258                 :            :         cmocka_unit_test(libspdm_test_requester_subscribe_event_types_case1),
+     259                 :            :         cmocka_unit_test(libspdm_test_requester_subscribe_event_types_case2),
+     260                 :            :         cmocka_unit_test(libspdm_test_requester_subscribe_event_types_case3)
+     261                 :            :     };
+     262                 :            : 
+     263                 :          1 :     libspdm_setup_test_context(&test_context);
+     264                 :            : 
+     265                 :          1 :     return cmocka_run_group_tests(spdm_requester_get_event_types_tests,
+     266                 :            :                                   libspdm_unit_test_group_setup,
+     267                 :            :                                   libspdm_unit_test_group_teardown);
+     268                 :            : }
+     269                 :            : 
+     270                 :            : #endif /* LIBSPDM_EVENT_RECIPIENT_SUPPORT */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/test_spdm_requester.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_requester/test_spdm_requester.c.func-sort-c.html new file mode 100644 index 00000000000..178196407e1 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/test_spdm_requester.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/test_spdm_requester.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - test_spdm_requester.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:438351.8 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:408050.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
main1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/test_spdm_requester.c.func.html b/coverage_log/unit_test/test_spdm_requester/test_spdm_requester.c.func.html new file mode 100644 index 00000000000..64f9998e65b --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/test_spdm_requester.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/test_spdm_requester.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - test_spdm_requester.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:438351.8 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:408050.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
main1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/test_spdm_requester.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/test_spdm_requester.c.gcov.html new file mode 100644 index 00000000000..84d07d03553 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/test_spdm_requester.c.gcov.html @@ -0,0 +1,366 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/test_spdm_requester.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - test_spdm_requester.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:438351.8 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:408050.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_requester_lib.h"
+       9                 :            : 
+      10                 :            : int libspdm_requester_get_version_test_main(void);
+      11                 :            : int libspdm_requester_get_version_error_test_main(void);
+      12                 :            : int libspdm_requester_get_capabilities_test_main(void);
+      13                 :            : int libspdm_requester_get_capabilities_error_test_main(void);
+      14                 :            : int libspdm_requester_negotiate_algorithms_test_main(void);
+      15                 :            : int libspdm_requester_negotiate_algorithms_error_test_main(void);
+      16                 :            : 
+      17                 :            : #if LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT
+      18                 :            : int libspdm_requester_get_digests_test_main(void);
+      19                 :            : int libspdm_requester_get_digests_error_test_main(void);
+      20                 :            : int libspdm_requester_get_certificate_test_main(void);
+      21                 :            : #endif /* LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT */
+      22                 :            : 
+      23                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP
+      24                 :            : int libspdm_requester_challenge_test_main(void);
+      25                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP*/
+      26                 :            : 
+      27                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
+      28                 :            : int libspdm_requester_get_measurements_test_main(void);
+      29                 :            : int libspdm_requester_get_measurements_error_test_main(void);
+      30                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP*/
+      31                 :            : 
+      32                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MEL_CAP
+      33                 :            : int libspdm_requester_get_measurement_extension_log_test_main(void);
+      34                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEL_CAP*/
+      35                 :            : 
+      36                 :            : #if LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP
+      37                 :            : int libspdm_requester_key_exchange_test_main(void);
+      38                 :            : int libspdm_requester_key_exchange_error_test_main(void);
+      39                 :            : int libspdm_requester_finish_test_main(void);
+      40                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP*/
+      41                 :            : 
+      42                 :            : #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
+      43                 :            : int libspdm_requester_psk_exchange_test_main(void);
+      44                 :            : int libspdm_requester_psk_finish_test_main(void);
+      45                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP*/
+      46                 :            : 
+      47                 :            : #if (LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP) || (LIBSPDM_ENABLE_CAPABILITY_PSK_CAP)
+      48                 :            : int libspdm_requester_heartbeat_test_main(void);
+      49                 :            : int libspdm_requester_key_update_test_main(void);
+      50                 :            : int libspdm_requester_end_session_test_main(void);
+      51                 :            : #endif /* (LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP) || (LIBSPDM_ENABLE_CAPABILITY_PSK_CAP) */
+      52                 :            : 
+      53                 :            : #if LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP
+      54                 :            : int libspdm_requester_encap_request_test_main(void);
+      55                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP
+      56                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CERT_CAP
+      57                 :            : int libspdm_requester_encap_digests_test_main(void);
+      58                 :            : int libspdm_requester_encap_certificate_test_main(void);
+      59                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CERT_CAP */
+      60                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP
+      61                 :            : int libspdm_requester_encap_challenge_auth_test_main(void);
+      62                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CERT_CAP */
+      63                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP */
+      64                 :            : int libspdm_requester_encap_key_update_test_main(void);
+      65                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP */
+      66                 :            : 
+      67                 :            : int libspdm_requester_set_certificate_test_main(void);
+      68                 :            : int libspdm_requester_get_csr_test_main(void);
+      69                 :            : 
+      70                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
+      71                 :            : int libspdm_requester_chunk_get_test_main(void);
+      72                 :            : int libspdm_requester_chunk_send_test_main(void);
+      73                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP */
+      74                 :            : 
+      75                 :            : #if LIBSPDM_EVENT_RECIPIENT_SUPPORT
+      76                 :            : int libspdm_requester_get_event_types_test_main(void);
+      77                 :            : int libspdm_requester_get_event_types_error_test_main(void);
+      78                 :            : int libspdm_requester_subscribe_event_types_test_main(void);
+      79                 :            : int libspdm_requester_subscribe_event_types_error_test_main(void);
+      80                 :            : #endif /* LIBSPDM_EVENT_RECIPIENT_SUPPORT */
+      81                 :            : 
+      82                 :            : #if LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES
+      83                 :            : int libspdm_requester_vendor_cmds_test_main(void);
+      84                 :            : int libspdm_requester_vendor_cmds_error_test_main(void);
+      85                 :            : #endif /* LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES */
+      86                 :            : 
+      87                 :            : #if LIBSPDM_ENABLE_CAPABILITY_GET_KEY_PAIR_INFO_CAP
+      88                 :            : int libspdm_requester_get_key_pair_info_test_main(void);
+      89                 :            : int libspdm_requester_get_key_pair_info_error_test_main(void);
+      90                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_GET_KEY_PAIR_INFO_CAP */
+      91                 :            : 
+      92                 :            : #if LIBSPDM_ENABLE_CAPABILITY_SET_KEY_PAIR_INFO_CAP
+      93                 :            : int libspdm_requester_set_key_pair_info_test_main(void);
+      94                 :            : int libspdm_requester_set_key_pair_info_error_test_main(void);
+      95                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_SET_KEY_PAIR_INFO_CAP */
+      96                 :            : 
+      97                 :          1 : int main(void)
+      98                 :            : {
+      99                 :          1 :     int return_value = 0;
+     100         [ -  + ]:          1 :     if (libspdm_requester_get_version_test_main() != 0) {
+     101                 :          0 :         return_value = 1;
+     102                 :            :     }
+     103         [ -  + ]:          1 :     if (libspdm_requester_get_version_error_test_main() != 0) {
+     104                 :          0 :         return_value = 1;
+     105                 :            :     }
+     106                 :            : 
+     107         [ -  + ]:          1 :     if (libspdm_requester_get_capabilities_test_main() != 0) {
+     108                 :          0 :         return_value = 1;
+     109                 :            :     }
+     110         [ -  + ]:          1 :     if (libspdm_requester_get_capabilities_error_test_main() != 0) {
+     111                 :          0 :         return_value = 1;
+     112                 :            :     }
+     113                 :            : 
+     114         [ -  + ]:          1 :     if (libspdm_requester_negotiate_algorithms_test_main() != 0) {
+     115                 :          0 :         return_value = 1;
+     116                 :            :     }
+     117         [ -  + ]:          1 :     if (libspdm_requester_negotiate_algorithms_error_test_main() != 0) {
+     118                 :          0 :         return_value = 1;
+     119                 :            :     }
+     120                 :            : 
+     121                 :            :     #if LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT
+     122         [ -  + ]:          1 :     if (libspdm_requester_get_digests_test_main() != 0) {
+     123                 :          0 :         return_value = 1;
+     124                 :            :     }
+     125         [ -  + ]:          1 :     if (libspdm_requester_get_digests_error_test_main() != 0) {
+     126                 :          0 :         return_value = 1;
+     127                 :            :     }
+     128         [ -  + ]:          1 :     if (libspdm_requester_get_certificate_test_main() != 0) {
+     129                 :          0 :         return_value = 1;
+     130                 :            :     }
+     131                 :            :     #endif /* LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT */
+     132                 :            : 
+     133                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP
+     134         [ -  + ]:          1 :     if (libspdm_requester_challenge_test_main() != 0) {
+     135                 :          0 :         return_value = 1;
+     136                 :            :     }
+     137                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP*/
+     138                 :            : 
+     139                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
+     140         [ -  + ]:          1 :     if (libspdm_requester_get_measurements_test_main() != 0) {
+     141                 :          0 :         return_value = 1;
+     142                 :            :     }
+     143         [ -  + ]:          1 :     if (libspdm_requester_get_measurements_error_test_main() != 0) {
+     144                 :          0 :         return_value = 1;
+     145                 :            :     }
+     146                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP */
+     147                 :            : 
+     148                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_MEL_CAP
+     149         [ -  + ]:          1 :     if (libspdm_requester_get_measurement_extension_log_test_main() != 0) {
+     150                 :          0 :         return_value = 1;
+     151                 :            :     }
+     152                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_MEL_CAP */
+     153                 :            : 
+     154                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP
+     155         [ -  + ]:          1 :     if (libspdm_requester_key_exchange_test_main() != 0) {
+     156                 :          0 :         return_value = 1;
+     157                 :            :     }
+     158         [ -  + ]:          1 :     if (libspdm_requester_key_exchange_error_test_main() != 0) {
+     159                 :          0 :         return_value = 1;
+     160                 :            :     }
+     161                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP*/
+     162                 :            : 
+     163                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP
+     164         [ -  + ]:          1 :     if (libspdm_requester_finish_test_main() != 0) {
+     165                 :          0 :         return_value = 1;
+     166                 :            :     }
+     167                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP*/
+     168                 :            : 
+     169                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
+     170         [ -  + ]:          1 :     if (libspdm_requester_psk_exchange_test_main() != 0) {
+     171                 :          0 :         return_value = 1;
+     172                 :            :     }
+     173                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP*/
+     174                 :            : 
+     175                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
+     176         [ -  + ]:          1 :     if (libspdm_requester_psk_finish_test_main() != 0) {
+     177                 :          0 :         return_value = 1;
+     178                 :            :     }
+     179                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP*/
+     180                 :            : 
+     181                 :            :     #if (LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP) || (LIBSPDM_ENABLE_CAPABILITY_PSK_CAP)
+     182         [ -  + ]:          1 :     if (libspdm_requester_heartbeat_test_main() != 0) {
+     183                 :          0 :         return_value = 1;
+     184                 :            :     }
+     185         [ -  + ]:          1 :     if (libspdm_requester_key_update_test_main() != 0) {
+     186                 :          0 :         return_value = 1;
+     187                 :            :     }
+     188         [ -  + ]:          1 :     if (libspdm_requester_end_session_test_main() != 0) {
+     189                 :          0 :         return_value = 1;
+     190                 :            :     }
+     191                 :            :     #endif /* (LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP) || (LIBSPDM_ENABLE_CAPABILITY_PSK_CAP) */
+     192                 :            : 
+     193                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP
+     194         [ -  + ]:          1 :     if (libspdm_requester_encap_request_test_main() != 0) {
+     195                 :          0 :         return_value = 1;
+     196                 :            :     }
+     197                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP
+     198                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_CERT_CAP
+     199         [ -  + ]:          1 :     if (libspdm_requester_encap_digests_test_main() != 0) {
+     200                 :          0 :         return_value = 1;
+     201                 :            :     }
+     202         [ -  + ]:          1 :     if (libspdm_requester_encap_certificate_test_main() != 0) {
+     203                 :          0 :         return_value = 1;
+     204                 :            :     }
+     205                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_CERT_CAP */
+     206                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP
+     207         [ -  + ]:          1 :     if (libspdm_requester_encap_challenge_auth_test_main() != 0) {
+     208                 :          0 :         return_value = 1;
+     209                 :            :     }
+     210                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_CERT_CAP */
+     211                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP */
+     212         [ -  + ]:          1 :     if (libspdm_requester_encap_key_update_test_main() != 0) {
+     213                 :          0 :         return_value = 1;
+     214                 :            :     }
+     215                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP */
+     216                 :            : 
+     217                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_SET_CERT_CAP
+     218         [ -  + ]:          1 :     if (libspdm_requester_set_certificate_test_main() != 0) {
+     219                 :          0 :         return_value = 1;
+     220                 :            :     }
+     221                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_SET_CERT_CAP */
+     222                 :            : 
+     223                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_CSR_CAP
+     224         [ -  + ]:          1 :     if (libspdm_requester_get_csr_test_main() != 0) {
+     225                 :          0 :         return_value = 1;
+     226                 :            :     }
+     227                 :            :     #endif /*LIBSPDM_ENABLE_CAPABILITY_CSR_CAP*/
+     228                 :            : 
+     229                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
+     230         [ -  + ]:          1 :     if (libspdm_requester_chunk_get_test_main() != 0) {
+     231                 :          0 :         return_value = 1;
+     232                 :            :     }
+     233         [ -  + ]:          1 :     if (libspdm_requester_chunk_send_test_main() != 0) {
+     234                 :          0 :         return_value = 1;
+     235                 :            :     }
+     236                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP */
+     237                 :            : 
+     238                 :            :     #if LIBSPDM_EVENT_RECIPIENT_SUPPORT
+     239         [ -  + ]:          1 :     if (libspdm_requester_get_event_types_test_main() != 0) {
+     240                 :          0 :         return_value = 1;
+     241                 :            :     }
+     242         [ -  + ]:          1 :     if (libspdm_requester_get_event_types_error_test_main() != 0) {
+     243                 :          0 :         return_value = 1;
+     244                 :            :     }
+     245         [ -  + ]:          1 :     if (libspdm_requester_subscribe_event_types_test_main() != 0) {
+     246                 :          0 :         return_value = 1;
+     247                 :            :     }
+     248         [ -  + ]:          1 :     if (libspdm_requester_subscribe_event_types_error_test_main() != 0) {
+     249                 :          0 :         return_value = 1;
+     250                 :            :     }
+     251                 :            :     #endif /* LIBSPDM_EVENT_RECIPIENT_SUPPORT */
+     252                 :            : 
+     253                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_GET_KEY_PAIR_INFO_CAP
+     254         [ -  + ]:          1 :     if (libspdm_requester_get_key_pair_info_test_main() != 0) {
+     255                 :          0 :         return_value = 1;
+     256                 :            :     }
+     257         [ -  + ]:          1 :     if (libspdm_requester_get_key_pair_info_error_test_main() != 0) {
+     258                 :          0 :         return_value = 1;
+     259                 :            :     }
+     260                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_GET_KEY_PAIR_INFO_CAP */
+     261                 :            : 
+     262                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_SET_KEY_PAIR_INFO_CAP
+     263         [ -  + ]:          1 :     if (libspdm_requester_set_key_pair_info_test_main() != 0) {
+     264                 :          0 :         return_value = 1;
+     265                 :            :     }
+     266         [ -  + ]:          1 :     if (libspdm_requester_set_key_pair_info_error_test_main() != 0) {
+     267                 :          0 :         return_value = 1;
+     268                 :            :     }
+     269                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_SET_KEY_PAIR_INFO_CAP */
+     270                 :            : 
+     271                 :            :     #if LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES
+     272         [ -  + ]:          1 :     if (libspdm_requester_vendor_cmds_test_main() != 0) {
+     273                 :          0 :         return_value = 1;
+     274                 :            :     }
+     275         [ -  + ]:          1 :     if (libspdm_requester_vendor_cmds_error_test_main() != 0) {
+     276                 :          0 :         return_value = 1;
+     277                 :            :     }
+     278                 :            :     #endif /* LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES */
+     279                 :            : 
+     280                 :          1 :     return return_value;
+     281                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/vendor_request.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_requester/vendor_request.c.func-sort-c.html new file mode 100644 index 00000000000..19b5df6bbd5 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/vendor_request.c.func-sort-c.html @@ -0,0 +1,105 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/vendor_request.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - vendor_request.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:709573.7 %
Date:2024-09-22 08:21:07Functions:4666.7 %
Branches:21811.1 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_vendor_get_id_func_test0
libspdm_vendor_response_func_test0
libspdm_requester_vendor_cmds_test_main1
libspdm_requester_vendor_cmds_test_receive_message1
libspdm_requester_vendor_cmds_test_send_message1
libspdm_test_requester_vendor_cmds_case11
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/vendor_request.c.func.html b/coverage_log/unit_test/test_spdm_requester/vendor_request.c.func.html new file mode 100644 index 00000000000..37168707139 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/vendor_request.c.func.html @@ -0,0 +1,105 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/vendor_request.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - vendor_request.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:709573.7 %
Date:2024-09-22 08:21:07Functions:4666.7 %
Branches:21811.1 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_requester_vendor_cmds_test_main1
libspdm_requester_vendor_cmds_test_receive_message1
libspdm_requester_vendor_cmds_test_send_message1
libspdm_test_requester_vendor_cmds_case11
libspdm_vendor_get_id_func_test0
libspdm_vendor_response_func_test0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_requester/vendor_request.c.gcov.html b/coverage_log/unit_test/test_spdm_requester/vendor_request.c.gcov.html new file mode 100644 index 00000000000..6c0b720aaad --- /dev/null +++ b/coverage_log/unit_test/test_spdm_requester/vendor_request.c.gcov.html @@ -0,0 +1,327 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_requester/vendor_request.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_requester - vendor_request.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:709573.7 %
Date:2024-09-22 08:21:07Functions:4666.7 %
Branches:21811.1 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2023-2024 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_requester_lib.h"
+       9                 :            : #include "internal/libspdm_responder_lib.h"
+      10                 :            : 
+      11                 :            : #if LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES
+      12                 :            : 
+      13                 :            : #pragma pack(1)
+      14                 :            : typedef struct {
+      15                 :            :     spdm_message_header_t header;
+      16                 :            :     uint16_t standard_id;
+      17                 :            :     uint8_t vendor_id_len;
+      18                 :            :     uint8_t vendor_id[SPDM_MAX_VENDOR_ID_LENGTH];
+      19                 :            :     uint16_t data_len;
+      20                 :            :     uint8_t data[16];
+      21                 :            : } libspdm_vendor_request_test;
+      22                 :            : 
+      23                 :            : typedef struct {
+      24                 :            :     spdm_message_header_t header;
+      25                 :            :     uint16_t standard_id;
+      26                 :            :     uint8_t vendor_id_len;
+      27                 :            :     uint8_t vendor_id[SPDM_MAX_VENDOR_ID_LENGTH];
+      28                 :            :     uint16_t data_len;
+      29                 :            :     uint8_t data[64];
+      30                 :            : } libspdm_vendor_response_test;
+      31                 :            : #pragma pack()
+      32                 :            : 
+      33                 :            : static size_t m_libspdm_local_buffer_size;
+      34                 :            : static uint8_t m_libspdm_local_buffer[LIBSPDM_MAX_MESSAGE_VCA_BUFFER_SIZE];
+      35                 :            : 
+      36                 :          0 : libspdm_return_t libspdm_vendor_get_id_func_test(
+      37                 :            :     void *spdm_context,
+      38                 :            :     uint16_t *resp_standard_id,
+      39                 :            :     uint8_t *resp_vendor_id_len,
+      40                 :            :     void *resp_vendor_id)
+      41                 :            : {
+      42   [ #  #  #  # ]:          0 :     if (resp_standard_id == NULL ||
+      43         [ #  # ]:          0 :         resp_vendor_id_len == NULL ||
+      44                 :            :         resp_vendor_id == NULL)
+      45                 :          0 :         return LIBSPDM_STATUS_INVALID_PARAMETER;
+      46                 :            : 
+      47                 :            :     /* vendor id length in bytes */
+      48         [ #  # ]:          0 :     if (*resp_vendor_id_len < 2)
+      49                 :          0 :         return LIBSPDM_STATUS_INVALID_PARAMETER;
+      50                 :            : 
+      51                 :          0 :     *resp_standard_id = 6;
+      52                 :            :     /* vendor id length in bytes */
+      53                 :          0 :     *resp_vendor_id_len = 2;
+      54                 :          0 :     ((uint8_t*)resp_vendor_id)[0] = 0xAA;
+      55                 :          0 :     ((uint8_t*)resp_vendor_id)[1] = 0xAA;
+      56                 :            : 
+      57                 :          0 :     return LIBSPDM_STATUS_SUCCESS;
+      58                 :            : }
+      59                 :            : 
+      60                 :          0 : libspdm_return_t libspdm_vendor_response_func_test(
+      61                 :            :     void *spdm_context,
+      62                 :            :     uint16_t req_standard_id,
+      63                 :            :     uint8_t req_vendor_id_len,
+      64                 :            :     const void *req_vendor_id,
+      65                 :            :     uint16_t req_size,
+      66                 :            :     const void *req_data,
+      67                 :            :     uint16_t *resp_size,
+      68                 :            :     void *resp_data)
+      69                 :            : {
+      70   [ #  #  #  # ]:          0 :     if (req_data == NULL ||
+      71         [ #  # ]:          0 :         resp_size == NULL ||
+      72                 :            :         resp_data == NULL)
+      73                 :          0 :         return LIBSPDM_STATUS_INVALID_PARAMETER;
+      74                 :            : 
+      75                 :            :     libspdm_vendor_response_test test_response;
+      76                 :            :     /* get pointer to response data payload and populate */
+      77                 :          0 :     uint8_t *resp_payload = (uint8_t *)resp_data;
+      78                 :            :     /* get pointer to response length and populate */
+      79                 :          0 :     *resp_size = sizeof(test_response.data);
+      80                 :            :     /* store length of response */
+      81                 :          0 :     libspdm_set_mem(resp_payload, *resp_size, 0xFF);
+      82                 :            : 
+      83                 :          0 :     printf("Got request 0x%x, sent response 0x%x\n",
+      84                 :          0 :            ((const uint8_t*)req_data)[0], ((uint8_t*)resp_data)[0]);
+      85                 :            : 
+      86                 :          0 :     return LIBSPDM_STATUS_SUCCESS;
+      87                 :            : }
+      88                 :            : 
+      89                 :          1 : static libspdm_return_t libspdm_requester_vendor_cmds_test_send_message(
+      90                 :            :     void *spdm_context, size_t request_size, const void *request,
+      91                 :            :     uint64_t timeout)
+      92                 :            : {
+      93                 :            :     libspdm_test_context_t *spdm_test_context;
+      94                 :            : 
+      95                 :          1 :     spdm_test_context = libspdm_get_test_context();
+      96         [ +  - ]:          1 :     switch (spdm_test_context->case_id) {
+      97                 :          1 :     case 0x1: {
+      98                 :          1 :         const uint8_t *ptr = (const uint8_t *)request;
+      99                 :            : 
+     100                 :          1 :         m_libspdm_local_buffer_size = 0;
+     101                 :          1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
+     102                 :            :                          ptr, request_size);
+     103                 :          1 :         m_libspdm_local_buffer_size += request_size;
+     104                 :            :     }
+     105                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     106                 :          0 :     default:
+     107                 :          0 :         return LIBSPDM_STATUS_SEND_FAIL;
+     108                 :            :     }
+     109                 :            : }
+     110                 :            : 
+     111                 :            : /* Acts as the Responder Integration */
+     112                 :          1 : static libspdm_return_t libspdm_requester_vendor_cmds_test_receive_message(
+     113                 :            :     void *spdm_context, size_t *response_size,
+     114                 :            :     void **response, uint64_t timeout)
+     115                 :            : {
+     116                 :            :     libspdm_test_context_t *spdm_test_context;
+     117                 :          1 :     libspdm_return_t status = LIBSPDM_STATUS_SUCCESS;
+     118                 :            : 
+     119                 :          1 :     uint32_t* session_id = NULL;
+     120                 :          1 :     bool is_app_message = false;
+     121                 :          1 :     size_t transport_message_size = sizeof(libspdm_vendor_request_test);
+     122                 :            : 
+     123                 :          1 :     spdm_test_context = libspdm_get_test_context();
+     124         [ +  - ]:          1 :     switch (spdm_test_context->case_id) {
+     125                 :          1 :     case 0x1: {
+     126                 :            :         libspdm_vendor_response_test *spdm_response;
+     127                 :          1 :         libspdm_vendor_request_test* spdm_request = NULL;
+     128                 :            :         size_t spdm_response_size;
+     129                 :            :         size_t transport_header_size;
+     130                 :          1 :         status = libspdm_transport_test_decode_message(
+     131                 :            :             spdm_context, &session_id, &is_app_message, true,
+     132                 :            :             m_libspdm_local_buffer_size, m_libspdm_local_buffer,
+     133                 :            :             &transport_message_size, (void **)(&spdm_request));
+     134                 :          1 :         assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     135                 :            : 
+     136                 :          1 :         spdm_response_size = sizeof(libspdm_vendor_response_test);
+     137                 :          1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
+     138                 :          1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
+     139                 :            : 
+     140                 :          1 :         libspdm_zero_mem(spdm_response, spdm_response_size);
+     141                 :          1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     142                 :          1 :         spdm_response->header.request_response_code = SPDM_VENDOR_DEFINED_RESPONSE;
+     143                 :          1 :         spdm_response->header.param1 = 0;
+     144                 :          1 :         spdm_response->header.param2 = 0;
+     145                 :            : 
+     146                 :          1 :         spdm_response->standard_id = spdm_request->standard_id;
+     147                 :          1 :         spdm_response->vendor_id_len = spdm_request->vendor_id_len;
+     148                 :            :         /* usually 2 bytes for vendor id */
+     149                 :          1 :         assert_int_equal(spdm_response->vendor_id_len, sizeof(uint16_t));
+     150                 :          1 :         libspdm_copy_mem(spdm_response->vendor_id, spdm_request->vendor_id_len,
+     151                 :          1 :                          spdm_request->vendor_id, spdm_request->vendor_id_len);
+     152                 :          1 :         spdm_response->data_len = sizeof(spdm_response->data);
+     153                 :          1 :         libspdm_set_mem(spdm_response->data, sizeof(spdm_response->data), 0xff);
+     154                 :            : 
+     155                 :          1 :         status = libspdm_transport_test_encode_message(spdm_context, NULL, false,
+     156                 :            :                                                        false, spdm_response_size,
+     157                 :            :                                                        spdm_response,
+     158                 :            :                                                        response_size, response);
+     159                 :          1 :         assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     160                 :            :     }
+     161                 :          1 :         return LIBSPDM_STATUS_SUCCESS;
+     162                 :            : 
+     163                 :          0 :     default:
+     164                 :          0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
+     165                 :            :     }
+     166                 :            : }
+     167                 :            : 
+     168                 :            : /**
+     169                 :            :  * Test 1: Sending a vendor defined request
+     170                 :            :  * Expected behavior: client returns a status of LIBSPDM_STATUS_SUCCESS and expected response
+     171                 :            :  **/
+     172                 :          1 : static void libspdm_test_requester_vendor_cmds_case1(void **state)
+     173                 :            : {
+     174                 :            :     libspdm_return_t status;
+     175                 :            :     libspdm_test_context_t *spdm_test_context;
+     176                 :            :     libspdm_context_t *spdm_context;
+     177                 :            :     libspdm_vendor_request_test request;
+     178                 :          1 :     libspdm_vendor_response_test response = {0};
+     179                 :          1 :     response.vendor_id_len = sizeof(response.vendor_id);
+     180                 :          1 :     response.data_len = sizeof(response.data);
+     181                 :            : 
+     182                 :          1 :     spdm_test_context = *state;
+     183                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     184                 :          1 :     spdm_test_context->case_id = 0x1;
+     185                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+     186                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     187                 :          1 :     spdm_context->connection_info.connection_state =
+     188                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     189                 :          1 :     spdm_context->local_context.is_requester = true;
+     190                 :            : 
+     191                 :          1 :     status = libspdm_register_vendor_get_id_callback_func(spdm_context,
+     192                 :            :                                                           libspdm_vendor_get_id_func_test);
+     193                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     194                 :          1 :     status = libspdm_register_vendor_callback_func(spdm_context,
+     195                 :            :                                                    libspdm_vendor_response_func_test);
+     196                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     197                 :            : 
+     198                 :          1 :     request.standard_id = 6;
+     199                 :          1 :     request.vendor_id_len = 2;
+     200                 :          1 :     request.vendor_id[0] = 0xAA;
+     201                 :          1 :     request.vendor_id[1] = 0xAA;
+     202                 :          1 :     request.data_len = sizeof(request.data);
+     203                 :          1 :     libspdm_set_mem(request.data, sizeof(request.data), 0xAA);
+     204                 :            : 
+     205                 :          1 :     status = libspdm_vendor_send_request_receive_response(spdm_context, NULL,
+     206                 :          1 :                                                           request.standard_id,
+     207                 :          1 :                                                           request.vendor_id_len,
+     208                 :          1 :                                                           request.vendor_id, request.data_len,
+     209                 :            :                                                           request.data,
+     210                 :            :                                                           &response.standard_id,
+     211                 :            :                                                           &response.vendor_id_len,
+     212                 :            :                                                           response.vendor_id, &response.data_len,
+     213                 :            :                                                           response.data);
+     214                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     215                 :          1 :     assert_int_equal(
+     216                 :            :         spdm_context->connection_info.version >> SPDM_VERSION_NUMBER_SHIFT_BIT,
+     217                 :            :         SPDM_MESSAGE_VERSION_10);
+     218                 :            : 
+     219                 :          1 :     printf("case 1 %d\n", response.data[0]);
+     220                 :          1 : }
+     221                 :            : 
+     222                 :            : libspdm_test_context_t m_libspdm_requester_vendor_cmds_test_context = {
+     223                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+     224                 :            :     true,
+     225                 :            :     libspdm_requester_vendor_cmds_test_send_message,
+     226                 :            :     libspdm_requester_vendor_cmds_test_receive_message,
+     227                 :            : };
+     228                 :            : 
+     229                 :          1 : int libspdm_requester_vendor_cmds_test_main(void)
+     230                 :            : {
+     231                 :          1 :     const struct CMUnitTest spdm_requester_vendor_cmds_tests[] = {
+     232                 :            :         cmocka_unit_test(libspdm_test_requester_vendor_cmds_case1),
+     233                 :            :     };
+     234                 :            : 
+     235                 :          1 :     libspdm_setup_test_context(&m_libspdm_requester_vendor_cmds_test_context);
+     236                 :            : 
+     237                 :          1 :     return cmocka_run_group_tests(spdm_requester_vendor_cmds_tests,
+     238                 :            :                                   libspdm_unit_test_group_setup,
+     239                 :            :                                   libspdm_unit_test_group_teardown);
+     240                 :            : }
+     241                 :            : 
+     242                 :            : #endif /* LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/algorithms.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_responder/algorithms.c.func-sort-c.html new file mode 100644 index 00000000000..c9024af4b1b --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/algorithms.c.func-sort-c.html @@ -0,0 +1,209 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/algorithms.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - algorithms.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:11151115100.0 %
Date:2024-09-22 08:21:07Functions:3232100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_algorithms_test_main1
libspdm_test_responder_algorithms_case11
libspdm_test_responder_algorithms_case101
libspdm_test_responder_algorithms_case111
libspdm_test_responder_algorithms_case121
libspdm_test_responder_algorithms_case131
libspdm_test_responder_algorithms_case141
libspdm_test_responder_algorithms_case151
libspdm_test_responder_algorithms_case161
libspdm_test_responder_algorithms_case171
libspdm_test_responder_algorithms_case181
libspdm_test_responder_algorithms_case191
libspdm_test_responder_algorithms_case21
libspdm_test_responder_algorithms_case201
libspdm_test_responder_algorithms_case211
libspdm_test_responder_algorithms_case221
libspdm_test_responder_algorithms_case231
libspdm_test_responder_algorithms_case241
libspdm_test_responder_algorithms_case251
libspdm_test_responder_algorithms_case261
libspdm_test_responder_algorithms_case271
libspdm_test_responder_algorithms_case281
libspdm_test_responder_algorithms_case291
libspdm_test_responder_algorithms_case31
libspdm_test_responder_algorithms_case301
libspdm_test_responder_algorithms_case311
libspdm_test_responder_algorithms_case321
libspdm_test_responder_algorithms_case41
libspdm_test_responder_algorithms_case61
libspdm_test_responder_algorithms_case71
libspdm_test_responder_algorithms_case81
libspdm_test_responder_algorithms_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/algorithms.c.func.html b/coverage_log/unit_test/test_spdm_responder/algorithms.c.func.html new file mode 100644 index 00000000000..2d20dbb97ad --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/algorithms.c.func.html @@ -0,0 +1,209 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/algorithms.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - algorithms.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:11151115100.0 %
Date:2024-09-22 08:21:07Functions:3232100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_algorithms_test_main1
libspdm_test_responder_algorithms_case11
libspdm_test_responder_algorithms_case101
libspdm_test_responder_algorithms_case111
libspdm_test_responder_algorithms_case121
libspdm_test_responder_algorithms_case131
libspdm_test_responder_algorithms_case141
libspdm_test_responder_algorithms_case151
libspdm_test_responder_algorithms_case161
libspdm_test_responder_algorithms_case171
libspdm_test_responder_algorithms_case181
libspdm_test_responder_algorithms_case191
libspdm_test_responder_algorithms_case21
libspdm_test_responder_algorithms_case201
libspdm_test_responder_algorithms_case211
libspdm_test_responder_algorithms_case221
libspdm_test_responder_algorithms_case231
libspdm_test_responder_algorithms_case241
libspdm_test_responder_algorithms_case251
libspdm_test_responder_algorithms_case261
libspdm_test_responder_algorithms_case271
libspdm_test_responder_algorithms_case281
libspdm_test_responder_algorithms_case291
libspdm_test_responder_algorithms_case31
libspdm_test_responder_algorithms_case301
libspdm_test_responder_algorithms_case311
libspdm_test_responder_algorithms_case321
libspdm_test_responder_algorithms_case41
libspdm_test_responder_algorithms_case61
libspdm_test_responder_algorithms_case71
libspdm_test_responder_algorithms_case81
libspdm_test_responder_algorithms_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/algorithms.c.gcov.html b/coverage_log/unit_test/test_spdm_responder/algorithms.c.gcov.html new file mode 100644 index 00000000000..47b232c5547 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/algorithms.c.gcov.html @@ -0,0 +1,3187 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/algorithms.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - algorithms.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:11151115100.0 %
Date:2024-09-22 08:21:07Functions:3232100.0 %
Branches:00-
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_responder_lib.h"
+       9                 :            : 
+      10                 :            : #pragma pack(1)
+      11                 :            : typedef struct {
+      12                 :            :     spdm_negotiate_algorithms_request_t spdm_request_version10;
+      13                 :            :     spdm_negotiate_algorithms_common_struct_table_t struct_table[4];
+      14                 :            : } libspdm_negotiate_algorithms_request_spdm11_t;
+      15                 :            : 
+      16                 :            : typedef struct {
+      17                 :            :     spdm_negotiate_algorithms_request_t spdm_request_version10;
+      18                 :            :     uint32_t extra[21];
+      19                 :            :     spdm_negotiate_algorithms_common_struct_table_t struct_table[4];
+      20                 :            : } libspdm_negotiate_algorithms_request_spdm11_oversized_t;
+      21                 :            : 
+      22                 :            : typedef struct {
+      23                 :            :     spdm_negotiate_algorithms_request_t spdm_request_version10;
+      24                 :            :     spdm_negotiate_algorithms_common_struct_table_t struct_table[12];
+      25                 :            : } libspdm_negotiate_algorithms_request_spdm11_multiple_tables_t;
+      26                 :            : 
+      27                 :            : typedef struct {
+      28                 :            :     spdm_negotiate_algorithms_request_t spdm_request_version10;
+      29                 :            :     spdm_negotiate_algorithms_common_struct_table_t struct_table[4];
+      30                 :            : } libspdm_negotiate_algorithms_request_spdm12_t;
+      31                 :            : 
+      32                 :            : typedef struct {
+      33                 :            :     spdm_negotiate_algorithms_request_t spdm_request_version10;
+      34                 :            :     spdm_negotiate_algorithms_common_struct_table_t struct_table[5];
+      35                 :            : } libspdm_negotiate_algorithms_request_spdm12_more_algo_t;
+      36                 :            : 
+      37                 :            : typedef struct {
+      38                 :            :     spdm_message_header_t header;
+      39                 :            :     uint16_t length;
+      40                 :            :     uint8_t measurement_specification_sel;
+      41                 :            :     uint8_t reserved;
+      42                 :            :     uint32_t measurement_hash_algo;
+      43                 :            :     uint32_t base_asym_sel;
+      44                 :            :     uint32_t base_hash_sel;
+      45                 :            :     uint8_t reserved2[12];
+      46                 :            :     uint8_t ext_asym_sel_count;
+      47                 :            :     uint8_t ext_hash_sel_count;
+      48                 :            :     uint16_t reserved3;
+      49                 :            :     spdm_negotiate_algorithms_common_struct_table_t struct_table[4];
+      50                 :            : } libspdm_algorithms_response_mine_t;
+      51                 :            : #pragma pack()
+      52                 :            : 
+      53                 :            : spdm_negotiate_algorithms_request_t m_libspdm_negotiate_algorithms_request1 = {
+      54                 :            :     { SPDM_MESSAGE_VERSION_10, SPDM_NEGOTIATE_ALGORITHMS, 0, 0 },
+      55                 :            :     sizeof(spdm_negotiate_algorithms_request_t),
+      56                 :            :     SPDM_MEASUREMENT_SPECIFICATION_DMTF,
+      57                 :            : };
+      58                 :            : size_t m_libspdm_negotiate_algorithms_request1_size =
+      59                 :            :     sizeof(m_libspdm_negotiate_algorithms_request1);
+      60                 :            : 
+      61                 :            : spdm_negotiate_algorithms_request_t m_libspdm_negotiate_algorithms_request2 = {
+      62                 :            :     { SPDM_MESSAGE_VERSION_10, SPDM_NEGOTIATE_ALGORITHMS, 0, 0 },
+      63                 :            :     sizeof(spdm_negotiate_algorithms_request_t),
+      64                 :            :     SPDM_MEASUREMENT_SPECIFICATION_DMTF,
+      65                 :            : };
+      66                 :            : size_t m_libspdm_negotiate_algorithms_request2_size = sizeof(spdm_message_header_t);
+      67                 :            : 
+      68                 :            : libspdm_negotiate_algorithms_request_spdm11_t m_libspdm_negotiate_algorithm_request3 = {
+      69                 :            :     {
+      70                 :            :         {
+      71                 :            :             SPDM_MESSAGE_VERSION_11,
+      72                 :            :             SPDM_NEGOTIATE_ALGORITHMS,
+      73                 :            :             4,
+      74                 :            :             0
+      75                 :            :         },
+      76                 :            :         sizeof(libspdm_negotiate_algorithms_request_spdm11_t),
+      77                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF,
+      78                 :            :     },
+      79                 :            :     {
+      80                 :            :         {
+      81                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE,
+      82                 :            :             0x20,
+      83                 :            :             SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_256_R1
+      84                 :            :         },
+      85                 :            :         {
+      86                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD,
+      87                 :            :             0x20,
+      88                 :            :             SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_256_GCM
+      89                 :            :         },
+      90                 :            :         {
+      91                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG,
+      92                 :            :             0x20,
+      93                 :            :             SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048
+      94                 :            :         },
+      95                 :            :         {
+      96                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE,
+      97                 :            :             0x20,
+      98                 :            :             SPDM_ALGORITHMS_KEY_SCHEDULE_HMAC_HASH
+      99                 :            :         }
+     100                 :            :     }
+     101                 :            : };
+     102                 :            : size_t m_libspdm_negotiate_algorithm_request3_size = sizeof(m_libspdm_negotiate_algorithm_request3);
+     103                 :            : 
+     104                 :            : libspdm_negotiate_algorithms_request_spdm11_t m_libspdm_negotiate_algorithm_request4 = {
+     105                 :            :     {
+     106                 :            :         {
+     107                 :            :             SPDM_MESSAGE_VERSION_11,
+     108                 :            :             SPDM_NEGOTIATE_ALGORITHMS,
+     109                 :            :             4,
+     110                 :            :             0
+     111                 :            :         },
+     112                 :            :         sizeof(libspdm_negotiate_algorithms_request_spdm11_t),
+     113                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF,
+     114                 :            :     },
+     115                 :            :     {
+     116                 :            :         {
+     117                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE,
+     118                 :            :             0x20,
+     119                 :            :             SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_256_R1
+     120                 :            :         },
+     121                 :            :         {
+     122                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD,
+     123                 :            :             0x20,
+     124                 :            :             SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_256_GCM
+     125                 :            :         },
+     126                 :            :         {
+     127                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG,
+     128                 :            :             0x20,
+     129                 :            :             SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048
+     130                 :            :         },
+     131                 :            :         {
+     132                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE,
+     133                 :            :             0x20,
+     134                 :            :             SPDM_ALGORITHMS_KEY_SCHEDULE_HMAC_HASH
+     135                 :            :         }
+     136                 :            :     }
+     137                 :            : };
+     138                 :            : size_t m_libspdm_negotiate_algorithm_request4_size = sizeof(m_libspdm_negotiate_algorithm_request4);
+     139                 :            : 
+     140                 :            : libspdm_negotiate_algorithms_request_spdm11_t m_libspdm_negotiate_algorithm_request5 = {
+     141                 :            :     {
+     142                 :            :         {
+     143                 :            :             SPDM_MESSAGE_VERSION_11,
+     144                 :            :             SPDM_NEGOTIATE_ALGORITHMS,
+     145                 :            :             4,
+     146                 :            :             0
+     147                 :            :         },
+     148                 :            :         sizeof(libspdm_negotiate_algorithms_request_spdm11_t),
+     149                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF,
+     150                 :            :     },
+     151                 :            :     {
+     152                 :            :         {
+     153                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE,
+     154                 :            :             0x20,
+     155                 :            :             SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_256_R1
+     156                 :            :         },
+     157                 :            :         {
+     158                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD,
+     159                 :            :             0x20,
+     160                 :            :             SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_256_GCM
+     161                 :            :         },
+     162                 :            :         {
+     163                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG,
+     164                 :            :             0x20,
+     165                 :            :             SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048
+     166                 :            :         },
+     167                 :            :         {
+     168                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE,
+     169                 :            :             0x20,
+     170                 :            :             SPDM_ALGORITHMS_KEY_SCHEDULE_HMAC_HASH
+     171                 :            :         }
+     172                 :            :     }
+     173                 :            : };
+     174                 :            : size_t m_libspdm_negotiate_algorithm_request5_size = sizeof(m_libspdm_negotiate_algorithm_request5);
+     175                 :            : 
+     176                 :            : libspdm_negotiate_algorithms_request_spdm11_t m_libspdm_negotiate_algorithm_request6 = {
+     177                 :            :     {
+     178                 :            :         {
+     179                 :            :             SPDM_MESSAGE_VERSION_11,
+     180                 :            :             SPDM_NEGOTIATE_ALGORITHMS,
+     181                 :            :             4,
+     182                 :            :             0
+     183                 :            :         },
+     184                 :            :         sizeof(libspdm_negotiate_algorithms_request_spdm11_t),
+     185                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF,
+     186                 :            :     },
+     187                 :            :     {
+     188                 :            :         {
+     189                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE,
+     190                 :            :             0x20,
+     191                 :            :             SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_521_R1
+     192                 :            :         },
+     193                 :            :         {
+     194                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD,
+     195                 :            :             0x20,
+     196                 :            :             SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_256_GCM
+     197                 :            :         },
+     198                 :            :         {
+     199                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG,
+     200                 :            :             0x20,
+     201                 :            :             SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048
+     202                 :            :         },
+     203                 :            :         {
+     204                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE,
+     205                 :            :             0x20,
+     206                 :            :             SPDM_ALGORITHMS_KEY_SCHEDULE_HMAC_HASH
+     207                 :            :         }
+     208                 :            :     }
+     209                 :            : };
+     210                 :            : size_t m_libspdm_negotiate_algorithm_request6_size = sizeof(m_libspdm_negotiate_algorithm_request6);
+     211                 :            : 
+     212                 :            : libspdm_negotiate_algorithms_request_spdm11_t m_libspdm_negotiate_algorithm_request7 = {
+     213                 :            :     {
+     214                 :            :         {
+     215                 :            :             SPDM_MESSAGE_VERSION_11,
+     216                 :            :             SPDM_NEGOTIATE_ALGORITHMS,
+     217                 :            :             4,
+     218                 :            :             0
+     219                 :            :         },
+     220                 :            :         sizeof(libspdm_negotiate_algorithms_request_spdm11_t),
+     221                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF,
+     222                 :            :     },
+     223                 :            :     {
+     224                 :            :         {
+     225                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE,
+     226                 :            :             0x20,
+     227                 :            :             SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_256_R1
+     228                 :            :         },
+     229                 :            :         {
+     230                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD,
+     231                 :            :             0x20,
+     232                 :            :             SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_CHACHA20_POLY1305
+     233                 :            :         },
+     234                 :            :         {
+     235                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG,
+     236                 :            :             0x20,
+     237                 :            :             SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048
+     238                 :            :         },
+     239                 :            :         {
+     240                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE,
+     241                 :            :             0x20,
+     242                 :            :             SPDM_ALGORITHMS_KEY_SCHEDULE_HMAC_HASH
+     243                 :            :         }
+     244                 :            :     }
+     245                 :            : };
+     246                 :            : size_t m_libspdm_negotiate_algorithm_request7_size = sizeof(m_libspdm_negotiate_algorithm_request7);
+     247                 :            : 
+     248                 :            : libspdm_negotiate_algorithms_request_spdm11_t m_libspdm_negotiate_algorithm_request8 = {
+     249                 :            :     {
+     250                 :            :         {
+     251                 :            :             SPDM_MESSAGE_VERSION_11,
+     252                 :            :             SPDM_NEGOTIATE_ALGORITHMS,
+     253                 :            :             4,
+     254                 :            :             0
+     255                 :            :         },
+     256                 :            :         sizeof(libspdm_negotiate_algorithms_request_spdm11_t),
+     257                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF,
+     258                 :            :     },
+     259                 :            :     {
+     260                 :            :         {
+     261                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE,
+     262                 :            :             0x20,
+     263                 :            :             SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_256_R1
+     264                 :            :         },
+     265                 :            :         {
+     266                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD,
+     267                 :            :             0x20,
+     268                 :            :             SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_256_GCM
+     269                 :            :         },
+     270                 :            :         {
+     271                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG,
+     272                 :            :             0x20,
+     273                 :            :             SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521
+     274                 :            :         },
+     275                 :            :         {
+     276                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE,
+     277                 :            :             0x20,
+     278                 :            :             SPDM_ALGORITHMS_KEY_SCHEDULE_HMAC_HASH
+     279                 :            :         }
+     280                 :            :     }
+     281                 :            : };
+     282                 :            : size_t m_libspdm_negotiate_algorithm_request8_size = sizeof(m_libspdm_negotiate_algorithm_request8);
+     283                 :            : 
+     284                 :            : libspdm_negotiate_algorithms_request_spdm11_t m_libspdm_negotiate_algorithm_request9 = {
+     285                 :            :     {
+     286                 :            :         {
+     287                 :            :             SPDM_MESSAGE_VERSION_11,
+     288                 :            :             SPDM_NEGOTIATE_ALGORITHMS,
+     289                 :            :             4,
+     290                 :            :             0
+     291                 :            :         },
+     292                 :            :         sizeof(libspdm_negotiate_algorithms_request_spdm11_t),
+     293                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF,
+     294                 :            :     },
+     295                 :            :     {
+     296                 :            :         {
+     297                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE,
+     298                 :            :             0x20,
+     299                 :            :             SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_256_R1
+     300                 :            :         },
+     301                 :            :         {
+     302                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD,
+     303                 :            :             0x20,
+     304                 :            :             SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_256_GCM
+     305                 :            :         },
+     306                 :            :         {
+     307                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG,
+     308                 :            :             0x20,
+     309                 :            :             SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048
+     310                 :            :         },
+     311                 :            :         {
+     312                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE,
+     313                 :            :             0x20,
+     314                 :            :             0x00000020
+     315                 :            :         }
+     316                 :            :     }
+     317                 :            : };
+     318                 :            : size_t m_libspdm_negotiate_algorithm_request9_size = sizeof(m_libspdm_negotiate_algorithm_request9);
+     319                 :            : 
+     320                 :            : spdm_negotiate_algorithms_request_t m_libspdm_negotiate_algorithm_request10 = {
+     321                 :            :     {
+     322                 :            :         SPDM_MESSAGE_VERSION_10,
+     323                 :            :         SPDM_NEGOTIATE_ALGORITHMS,
+     324                 :            :         0,
+     325                 :            :         0
+     326                 :            :     },
+     327                 :            :     0x44,
+     328                 :            :     SPDM_MEASUREMENT_SPECIFICATION_DMTF,
+     329                 :            : };
+     330                 :            : size_t m_libspdm_negotiate_algorithm_request10_size = 0x44;
+     331                 :            : 
+     332                 :            : libspdm_negotiate_algorithms_request_spdm11_oversized_t m_libspdm_negotiate_algorithm_request11 = {
+     333                 :            :     {
+     334                 :            :         {
+     335                 :            :             SPDM_MESSAGE_VERSION_11,
+     336                 :            :             SPDM_NEGOTIATE_ALGORITHMS,
+     337                 :            :             4,
+     338                 :            :             0
+     339                 :            :         },
+     340                 :            :         sizeof(libspdm_negotiate_algorithms_request_spdm11_oversized_t),
+     341                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF,
+     342                 :            :     },
+     343                 :            :     {0},
+     344                 :            :     {
+     345                 :            :         {
+     346                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE,
+     347                 :            :             0x20,
+     348                 :            :             SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_256_R1
+     349                 :            :         },
+     350                 :            :         {
+     351                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD,
+     352                 :            :             0x20,
+     353                 :            :             SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_256_GCM
+     354                 :            :         },
+     355                 :            :         {
+     356                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG,
+     357                 :            :             0x20,
+     358                 :            :             SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048
+     359                 :            :         },
+     360                 :            :         {
+     361                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE,
+     362                 :            :             0x20,
+     363                 :            :             SPDM_ALGORITHMS_KEY_SCHEDULE_HMAC_HASH
+     364                 :            :         }
+     365                 :            :     }
+     366                 :            : };
+     367                 :            : size_t m_libspdm_negotiate_algorithm_request11_size =
+     368                 :            :     sizeof(m_libspdm_negotiate_algorithm_request11);
+     369                 :            : 
+     370                 :            : libspdm_negotiate_algorithms_request_spdm11_multiple_tables_t
+     371                 :            :     m_libspdm_negotiate_algorithm_request12 =
+     372                 :            : {
+     373                 :            :     {
+     374                 :            :         {
+     375                 :            :             SPDM_MESSAGE_VERSION_11,
+     376                 :            :             SPDM_NEGOTIATE_ALGORITHMS,
+     377                 :            :             12,
+     378                 :            :             0
+     379                 :            :         },
+     380                 :            :         sizeof(libspdm_negotiate_algorithms_request_spdm11_multiple_tables_t),
+     381                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF,
+     382                 :            :     },
+     383                 :            :     {
+     384                 :            :         {
+     385                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE,
+     386                 :            :             0x20,
+     387                 :            :             SPDM_ALGORITHMS_DHE_NAMED_GROUP_FFDHE_2048
+     388                 :            :         },
+     389                 :            :         {
+     390                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD,
+     391                 :            :             0x20,
+     392                 :            :             SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_128_GCM
+     393                 :            :         },
+     394                 :            :         {
+     395                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG,
+     396                 :            :             0x20,
+     397                 :            :             SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256
+     398                 :            :         },
+     399                 :            :         {
+     400                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE,
+     401                 :            :             0x20,
+     402                 :            :             SPDM_ALGORITHMS_KEY_SCHEDULE_HMAC_HASH
+     403                 :            :         },
+     404                 :            :         {
+     405                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE,
+     406                 :            :             0x20,
+     407                 :            :             SPDM_ALGORITHMS_DHE_NAMED_GROUP_FFDHE_3072
+     408                 :            :         },
+     409                 :            :         {
+     410                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD,
+     411                 :            :             0x20,
+     412                 :            :             SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_CHACHA20_POLY1305
+     413                 :            :         },
+     414                 :            :         {
+     415                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG,
+     416                 :            :             0x20,
+     417                 :            :             SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384
+     418                 :            :         },
+     419                 :            :         {
+     420                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE,
+     421                 :            :             0x20,
+     422                 :            :             SPDM_ALGORITHMS_KEY_SCHEDULE_HMAC_HASH
+     423                 :            :         },
+     424                 :            :         {
+     425                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE,
+     426                 :            :             0x20,
+     427                 :            :             SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_256_R1
+     428                 :            :         },
+     429                 :            :         {
+     430                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD,
+     431                 :            :             0x20,
+     432                 :            :             SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_256_GCM
+     433                 :            :         },
+     434                 :            :         {
+     435                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG,
+     436                 :            :             0x20,
+     437                 :            :             SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048
+     438                 :            :         },
+     439                 :            :         {
+     440                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE,
+     441                 :            :             0x20,
+     442                 :            :             SPDM_ALGORITHMS_KEY_SCHEDULE_HMAC_HASH
+     443                 :            :         }
+     444                 :            :     }
+     445                 :            : };
+     446                 :            : size_t m_libspdm_negotiate_algorithm_request12_size =
+     447                 :            :     sizeof(m_libspdm_negotiate_algorithm_request12);
+     448                 :            : 
+     449                 :            : libspdm_negotiate_algorithms_request_spdm11_t
+     450                 :            :     m_libspdm_negotiate_algorithm_request13 =
+     451                 :            : {
+     452                 :            :     {
+     453                 :            :         {
+     454                 :            :             SPDM_MESSAGE_VERSION_11,
+     455                 :            :             SPDM_NEGOTIATE_ALGORITHMS,
+     456                 :            :             3,
+     457                 :            :             0
+     458                 :            :         },
+     459                 :            :         sizeof(libspdm_negotiate_algorithms_request_spdm11_t)-
+     460                 :            :         sizeof(spdm_negotiate_algorithms_common_struct_table_t),
+     461                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF,
+     462                 :            :     },
+     463                 :            :     {
+     464                 :            :         {
+     465                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE,
+     466                 :            :             0x20,
+     467                 :            :             SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_256_R1
+     468                 :            :         },
+     469                 :            :         {
+     470                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD,
+     471                 :            :             0x20,
+     472                 :            :             SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_256_GCM
+     473                 :            :         },
+     474                 :            :         {
+     475                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG,
+     476                 :            :             0x20,
+     477                 :            :             SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048
+     478                 :            :         },
+     479                 :            :         {
+     480                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE,
+     481                 :            :             0x20,
+     482                 :            :             SPDM_ALGORITHMS_KEY_SCHEDULE_HMAC_HASH
+     483                 :            :         }
+     484                 :            :     }
+     485                 :            : };
+     486                 :            : size_t m_libspdm_negotiate_algorithm_request13_size =
+     487                 :            :     sizeof(m_libspdm_negotiate_algorithm_request13)-
+     488                 :            :     sizeof(
+     489                 :            :         spdm_negotiate_algorithms_common_struct_table_t);
+     490                 :            : 
+     491                 :            : libspdm_negotiate_algorithms_request_spdm11_t
+     492                 :            :     m_libspdm_negotiate_algorithm_request14 =
+     493                 :            : {
+     494                 :            :     {
+     495                 :            :         {
+     496                 :            :             SPDM_MESSAGE_VERSION_11,
+     497                 :            :             SPDM_NEGOTIATE_ALGORITHMS,
+     498                 :            :             5,
+     499                 :            :             0
+     500                 :            :         },
+     501                 :            :         sizeof(libspdm_negotiate_algorithms_request_spdm11_t)+
+     502                 :            :         sizeof(spdm_negotiate_algorithms_common_struct_table_t),
+     503                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF,
+     504                 :            :     },
+     505                 :            :     {
+     506                 :            :         {
+     507                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE,
+     508                 :            :             0x20,
+     509                 :            :             SPDM_ALGORITHMS_DHE_NAMED_GROUP_FFDHE_2048
+     510                 :            :         },
+     511                 :            :         {
+     512                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD,
+     513                 :            :             0x20,
+     514                 :            :             SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_128_GCM
+     515                 :            :         },
+     516                 :            :         {
+     517                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG,
+     518                 :            :             0x20,
+     519                 :            :             SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256
+     520                 :            :         },
+     521                 :            :         {
+     522                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE,
+     523                 :            :             0x20,
+     524                 :            :             SPDM_ALGORITHMS_KEY_SCHEDULE_HMAC_HASH
+     525                 :            :         },
+     526                 :            :     }
+     527                 :            : };
+     528                 :            : size_t m_libspdm_negotiate_algorithm_request14_size =
+     529                 :            :     sizeof(m_libspdm_negotiate_algorithm_request14)+
+     530                 :            :     sizeof(
+     531                 :            :         spdm_negotiate_algorithms_common_struct_table_t);
+     532                 :            : 
+     533                 :            : libspdm_negotiate_algorithms_request_spdm11_t
+     534                 :            :     m_libspdm_negotiate_algorithm_request15 =
+     535                 :            : {
+     536                 :            :     {
+     537                 :            :         {
+     538                 :            :             SPDM_MESSAGE_VERSION_11,
+     539                 :            :             SPDM_NEGOTIATE_ALGORITHMS,
+     540                 :            :             12,
+     541                 :            :             0
+     542                 :            :         },
+     543                 :            :         sizeof(libspdm_negotiate_algorithms_request_spdm11_t),
+     544                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF,
+     545                 :            :     },
+     546                 :            :     {
+     547                 :            :         {
+     548                 :            :             1,
+     549                 :            :             0x20,
+     550                 :            :             SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_256_R1
+     551                 :            :         },
+     552                 :            :         {
+     553                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD,
+     554                 :            :             0x20,
+     555                 :            :             SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_256_GCM
+     556                 :            :         },
+     557                 :            :         {
+     558                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG,
+     559                 :            :             0x20,
+     560                 :            :             SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048
+     561                 :            :         },
+     562                 :            :         {
+     563                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE,
+     564                 :            :             0x20,
+     565                 :            :             SPDM_ALGORITHMS_KEY_SCHEDULE_HMAC_HASH
+     566                 :            :         }
+     567                 :            :     }
+     568                 :            : };
+     569                 :            : size_t m_libspdm_negotiate_algorithm_request15_size =
+     570                 :            :     sizeof(m_libspdm_negotiate_algorithm_request15);
+     571                 :            : 
+     572                 :            : libspdm_negotiate_algorithms_request_spdm11_t m_libspdm_negotiate_algorithm_request16 = {
+     573                 :            :     {
+     574                 :            :         {
+     575                 :            :             SPDM_MESSAGE_VERSION_11,
+     576                 :            :             SPDM_NEGOTIATE_ALGORITHMS,
+     577                 :            :             4,
+     578                 :            :             0
+     579                 :            :         },
+     580                 :            :         sizeof(libspdm_negotiate_algorithms_request_spdm11_t),
+     581                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF,
+     582                 :            :     },
+     583                 :            :     {
+     584                 :            :         {
+     585                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE,
+     586                 :            :             0x20,
+     587                 :            :             SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_256_R1 |
+     588                 :            :             SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_384_R1
+     589                 :            :         },
+     590                 :            :         {
+     591                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD,
+     592                 :            :             0x20,
+     593                 :            :             SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_256_GCM
+     594                 :            :         },
+     595                 :            :         {
+     596                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG,
+     597                 :            :             0x20,
+     598                 :            :             SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048
+     599                 :            :         },
+     600                 :            :         {
+     601                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE,
+     602                 :            :             0x20,
+     603                 :            :             SPDM_ALGORITHMS_KEY_SCHEDULE_HMAC_HASH
+     604                 :            :         }
+     605                 :            :     }
+     606                 :            : };
+     607                 :            : size_t m_libspdm_negotiate_algorithm_request16_size =
+     608                 :            :     sizeof(m_libspdm_negotiate_algorithm_request16);
+     609                 :            : 
+     610                 :            : libspdm_negotiate_algorithms_request_spdm12_t
+     611                 :            :     m_libspdm_negotiate_algorithm_request17 =
+     612                 :            : {
+     613                 :            :     {
+     614                 :            :         {
+     615                 :            :             SPDM_MESSAGE_VERSION_12,
+     616                 :            :             SPDM_NEGOTIATE_ALGORITHMS,
+     617                 :            :             4,
+     618                 :            :             0
+     619                 :            :         },
+     620                 :            :         sizeof(libspdm_negotiate_algorithms_request_spdm12_t),
+     621                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF,
+     622                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1,
+     623                 :            :     },
+     624                 :            :     {
+     625                 :            :         {
+     626                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE,
+     627                 :            :             0x20,
+     628                 :            :             SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_256_R1
+     629                 :            :         },
+     630                 :            :         {
+     631                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD,
+     632                 :            :             0x20,
+     633                 :            :             SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_256_GCM
+     634                 :            :         },
+     635                 :            :         {
+     636                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG,
+     637                 :            :             0x20,
+     638                 :            :             SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048
+     639                 :            :         },
+     640                 :            :         {
+     641                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE,
+     642                 :            :             0x20,
+     643                 :            :             SPDM_ALGORITHMS_KEY_SCHEDULE_HMAC_HASH
+     644                 :            :         }
+     645                 :            :     }
+     646                 :            : };
+     647                 :            : size_t m_libspdm_negotiate_algorithm_request17_size =
+     648                 :            :     sizeof(m_libspdm_negotiate_algorithm_request17);
+     649                 :            : 
+     650                 :            : libspdm_negotiate_algorithms_request_spdm12_t
+     651                 :            :     m_libspdm_negotiate_algorithm_request18 =
+     652                 :            : {
+     653                 :            :     {
+     654                 :            :         {
+     655                 :            :             SPDM_MESSAGE_VERSION_12,
+     656                 :            :             SPDM_NEGOTIATE_ALGORITHMS,
+     657                 :            :             4,
+     658                 :            :             0
+     659                 :            :         },
+     660                 :            :         sizeof(libspdm_negotiate_algorithms_request_spdm12_t),
+     661                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF,
+     662                 :            :         /* Illegal OpaqueDataFmt. */
+     663                 :            :         0x04,
+     664                 :            :     },
+     665                 :            :     {
+     666                 :            :         {
+     667                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE,
+     668                 :            :             0x20,
+     669                 :            :             SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_256_R1
+     670                 :            :         },
+     671                 :            :         {
+     672                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD,
+     673                 :            :             0x20,
+     674                 :            :             SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_256_GCM
+     675                 :            :         },
+     676                 :            :         {
+     677                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG,
+     678                 :            :             0x20,
+     679                 :            :             SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048
+     680                 :            :         },
+     681                 :            :         {
+     682                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE,
+     683                 :            :             0x20,
+     684                 :            :             SPDM_ALGORITHMS_KEY_SCHEDULE_HMAC_HASH
+     685                 :            :         }
+     686                 :            :     }
+     687                 :            : };
+     688                 :            : size_t m_libspdm_negotiate_algorithm_request18_size =
+     689                 :            :     sizeof(m_libspdm_negotiate_algorithm_request18);
+     690                 :            : 
+     691                 :            : libspdm_negotiate_algorithms_request_spdm11_t m_libspdm_negotiate_algorithm_request24 = {
+     692                 :            :     {
+     693                 :            :         {
+     694                 :            :             SPDM_MESSAGE_VERSION_12,
+     695                 :            :             SPDM_NEGOTIATE_ALGORITHMS,
+     696                 :            :             4,
+     697                 :            :             0
+     698                 :            :         },
+     699                 :            :         sizeof(libspdm_negotiate_algorithms_request_spdm11_t),
+     700                 :            :         0, /* SPDM_MEASUREMENT_SPECIFICATION_DMTF */
+     701                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1,
+     702                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256,
+     703                 :            :         SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     704                 :            :     },
+     705                 :            :     {
+     706                 :            :         {
+     707                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE,
+     708                 :            :             0x20,
+     709                 :            :             SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_256_R1
+     710                 :            :         },
+     711                 :            :         {
+     712                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD,
+     713                 :            :             0x20,
+     714                 :            :             SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_256_GCM
+     715                 :            :         },
+     716                 :            :         {
+     717                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG,
+     718                 :            :             0x20,
+     719                 :            :             SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048
+     720                 :            :         },
+     721                 :            :         {
+     722                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE,
+     723                 :            :             0x20,
+     724                 :            :             SPDM_ALGORITHMS_KEY_SCHEDULE_HMAC_HASH
+     725                 :            :         }
+     726                 :            :     }
+     727                 :            : };
+     728                 :            : size_t m_libspdm_negotiate_algorithm_request24_size =
+     729                 :            :     sizeof(m_libspdm_negotiate_algorithm_request24);
+     730                 :            : 
+     731                 :            : libspdm_negotiate_algorithms_request_spdm12_t
+     732                 :            :     m_libspdm_negotiate_algorithm_request25 =
+     733                 :            : {
+     734                 :            :     {
+     735                 :            :         {
+     736                 :            :             SPDM_MESSAGE_VERSION_12,
+     737                 :            :             SPDM_NEGOTIATE_ALGORITHMS,
+     738                 :            :             4,
+     739                 :            :             0
+     740                 :            :         },
+     741                 :            :         sizeof(libspdm_negotiate_algorithms_request_spdm12_t),
+     742                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF,
+     743                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1,
+     744                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256,
+     745                 :            :         SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     746                 :            :     },
+     747                 :            :     {
+     748                 :            :         {
+     749                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE,
+     750                 :            :             0x20,
+     751                 :            :             SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_256_R1
+     752                 :            :         },
+     753                 :            :         {
+     754                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE,
+     755                 :            :             0x20,
+     756                 :            :             SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_256_R1
+     757                 :            :         },
+     758                 :            :         {
+     759                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG,
+     760                 :            :             0x20,
+     761                 :            :             SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048
+     762                 :            :         },
+     763                 :            :         {
+     764                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE,
+     765                 :            :             0x20,
+     766                 :            :             SPDM_ALGORITHMS_KEY_SCHEDULE_HMAC_HASH
+     767                 :            :         }
+     768                 :            :     }
+     769                 :            : };
+     770                 :            : size_t m_libspdm_negotiate_algorithm_request25_size =
+     771                 :            :     sizeof(m_libspdm_negotiate_algorithm_request25);
+     772                 :            : 
+     773                 :            : libspdm_negotiate_algorithms_request_spdm12_t
+     774                 :            :     m_libspdm_negotiate_algorithm_request26 =
+     775                 :            : {
+     776                 :            :     {
+     777                 :            :         {
+     778                 :            :             SPDM_MESSAGE_VERSION_12,
+     779                 :            :             SPDM_NEGOTIATE_ALGORITHMS,
+     780                 :            :             4,
+     781                 :            :             0
+     782                 :            :         },
+     783                 :            :         sizeof(libspdm_negotiate_algorithms_request_spdm12_t),
+     784                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF,
+     785                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1,
+     786                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256,
+     787                 :            :         SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     788                 :            :     },
+     789                 :            :     {
+     790                 :            :         {
+     791                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE,
+     792                 :            :             0x20,
+     793                 :            :             SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_256_R1
+     794                 :            :         },
+     795                 :            :         {
+     796                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG,
+     797                 :            :             0x20,
+     798                 :            :             SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048
+     799                 :            :         },
+     800                 :            :         {
+     801                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE,
+     802                 :            :             0x20,
+     803                 :            :             SPDM_ALGORITHMS_KEY_SCHEDULE_HMAC_HASH
+     804                 :            :         },
+     805                 :            :         {
+     806                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD,
+     807                 :            :             0x20,
+     808                 :            :             SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_256_GCM
+     809                 :            :         }
+     810                 :            :     }
+     811                 :            : };
+     812                 :            : size_t m_libspdm_negotiate_algorithm_request26_size =
+     813                 :            :     sizeof(m_libspdm_negotiate_algorithm_request26);
+     814                 :            : 
+     815                 :            : libspdm_negotiate_algorithms_request_spdm12_more_algo_t
+     816                 :            :     m_libspdm_negotiate_algorithm_request27 =
+     817                 :            : {
+     818                 :            :     {
+     819                 :            :         {
+     820                 :            :             SPDM_MESSAGE_VERSION_12,
+     821                 :            :             SPDM_NEGOTIATE_ALGORITHMS,
+     822                 :            :             5,
+     823                 :            :             0
+     824                 :            :         },
+     825                 :            :         sizeof(libspdm_negotiate_algorithms_request_spdm12_more_algo_t),
+     826                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF,
+     827                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1,
+     828                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256,
+     829                 :            :         SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     830                 :            :     },
+     831                 :            :     {
+     832                 :            :         {
+     833                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE - 1,
+     834                 :            :             0x20,
+     835                 :            :             SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_256_R1
+     836                 :            :         },
+     837                 :            :         {
+     838                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE,
+     839                 :            :             0x20,
+     840                 :            :             SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_256_R1
+     841                 :            :         },
+     842                 :            :         {
+     843                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD,
+     844                 :            :             0x20,
+     845                 :            :             SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_256_GCM
+     846                 :            :         },
+     847                 :            :         {
+     848                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG,
+     849                 :            :             0x20,
+     850                 :            :             SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048
+     851                 :            :         },
+     852                 :            :         {
+     853                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE,
+     854                 :            :             0x20,
+     855                 :            :             SPDM_ALGORITHMS_KEY_SCHEDULE_HMAC_HASH
+     856                 :            :         },
+     857                 :            :     }
+     858                 :            : };
+     859                 :            : size_t m_libspdm_negotiate_algorithm_request27_size =
+     860                 :            :     sizeof(m_libspdm_negotiate_algorithm_request27);
+     861                 :            : 
+     862                 :            : libspdm_negotiate_algorithms_request_spdm12_more_algo_t
+     863                 :            :     m_libspdm_negotiate_algorithm_request28 =
+     864                 :            : {
+     865                 :            :     {
+     866                 :            :         {
+     867                 :            :             SPDM_MESSAGE_VERSION_12,
+     868                 :            :             SPDM_NEGOTIATE_ALGORITHMS,
+     869                 :            :             5,
+     870                 :            :             0
+     871                 :            :         },
+     872                 :            :         sizeof(libspdm_negotiate_algorithms_request_spdm12_more_algo_t),
+     873                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF,
+     874                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1,
+     875                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256,
+     876                 :            :         SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     877                 :            :     },
+     878                 :            :     {
+     879                 :            :         {
+     880                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE,
+     881                 :            :             0x20,
+     882                 :            :             SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_256_R1
+     883                 :            :         },
+     884                 :            :         {
+     885                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD,
+     886                 :            :             0x20,
+     887                 :            :             SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_256_GCM
+     888                 :            :         },
+     889                 :            :         {
+     890                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG,
+     891                 :            :             0x20,
+     892                 :            :             SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048
+     893                 :            :         },
+     894                 :            :         {
+     895                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE,
+     896                 :            :             0x20,
+     897                 :            :             SPDM_ALGORITHMS_KEY_SCHEDULE_HMAC_HASH
+     898                 :            :         },
+     899                 :            :         {
+     900                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE + 1,
+     901                 :            :             0x20,
+     902                 :            :             SPDM_ALGORITHMS_KEY_SCHEDULE_HMAC_HASH
+     903                 :            :         }
+     904                 :            :     }
+     905                 :            : };
+     906                 :            : size_t m_libspdm_negotiate_algorithm_request28_size =
+     907                 :            :     sizeof(m_libspdm_negotiate_algorithm_request28);
+     908                 :            : 
+     909                 :            : libspdm_negotiate_algorithms_request_spdm12_t
+     910                 :            :     m_libspdm_negotiate_algorithm_request29 =
+     911                 :            : {
+     912                 :            :     {
+     913                 :            :         {
+     914                 :            :             SPDM_MESSAGE_VERSION_12,
+     915                 :            :             SPDM_NEGOTIATE_ALGORITHMS,
+     916                 :            :             4,
+     917                 :            :             0
+     918                 :            :         },
+     919                 :            :         sizeof(libspdm_negotiate_algorithms_request_spdm12_t),
+     920                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF,
+     921                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1,
+     922                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256,
+     923                 :            :         SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256,
+     924                 :            :     },
+     925                 :            :     {
+     926                 :            :         {
+     927                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE,
+     928                 :            :             0x20,
+     929                 :            :             SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_256_R1
+     930                 :            :         },
+     931                 :            :         {
+     932                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD,
+     933                 :            :             0x20,
+     934                 :            :             /* No supported AlgTypes */
+     935                 :            :             0x00
+     936                 :            :         },
+     937                 :            :         {
+     938                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG,
+     939                 :            :             0x20,
+     940                 :            :             SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048
+     941                 :            :         },
+     942                 :            :         {
+     943                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE,
+     944                 :            :             0x20,
+     945                 :            :             SPDM_ALGORITHMS_KEY_SCHEDULE_HMAC_HASH
+     946                 :            :         }
+     947                 :            :     }
+     948                 :            : };
+     949                 :            : size_t m_libspdm_negotiate_algorithm_request29_size =
+     950                 :            :     sizeof(m_libspdm_negotiate_algorithm_request29);
+     951                 :            : 
+     952                 :            : spdm_negotiate_algorithms_request_t m_libspdm_negotiate_algorithms_request30 = {
+     953                 :            :     { SPDM_MESSAGE_VERSION_13, SPDM_NEGOTIATE_ALGORITHMS, 0, 0 },
+     954                 :            :     sizeof(spdm_negotiate_algorithms_request_t),
+     955                 :            :     SPDM_MEASUREMENT_SPECIFICATION_DMTF,
+     956                 :            :     SPDM_ALGORITHMS_MULTI_KEY_CONN,
+     957                 :            : };
+     958                 :            : size_t m_libspdm_negotiate_algorithms_request30_size =
+     959                 :            :     sizeof(m_libspdm_negotiate_algorithms_request30);
+     960                 :            : 
+     961                 :          1 : void libspdm_test_responder_algorithms_case1(void **state)
+     962                 :            : {
+     963                 :            :     libspdm_return_t status;
+     964                 :            :     libspdm_test_context_t *spdm_test_context;
+     965                 :            :     libspdm_context_t *spdm_context;
+     966                 :            :     size_t response_size;
+     967                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     968                 :            :     spdm_algorithms_response_t *spdm_response;
+     969                 :            : 
+     970                 :          1 :     spdm_test_context = *state;
+     971                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     972                 :          1 :     spdm_test_context->case_id = 0x1;
+     973                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+     974                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     975                 :          1 :     spdm_context->connection_info.connection_state =
+     976                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+     977                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     978                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     979                 :            : 
+     980                 :          1 :     response_size = sizeof(response);
+     981                 :          1 :     status = libspdm_get_response_algorithms(
+     982                 :            :         spdm_context, m_libspdm_negotiate_algorithms_request1_size,
+     983                 :            :         &m_libspdm_negotiate_algorithms_request1, &response_size,
+     984                 :            :         response);
+     985                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     986                 :          1 :     assert_int_equal(response_size, sizeof(spdm_algorithms_response_t));
+     987                 :          1 :     spdm_response = (void *)response;
+     988                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     989                 :            :                      SPDM_ALGORITHMS);
+     990                 :          1 : }
+     991                 :            : 
+     992                 :          1 : void libspdm_test_responder_algorithms_case2(void **state)
+     993                 :            : {
+     994                 :            :     libspdm_return_t status;
+     995                 :            :     libspdm_test_context_t *spdm_test_context;
+     996                 :            :     libspdm_context_t *spdm_context;
+     997                 :            :     size_t response_size;
+     998                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     999                 :            :     spdm_algorithms_response_t *spdm_response;
+    1000                 :            : 
+    1001                 :          1 :     spdm_test_context = *state;
+    1002                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1003                 :          1 :     spdm_test_context->case_id = 0x2;
+    1004                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1005                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1006                 :          1 :     spdm_context->connection_info.connection_state =
+    1007                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1008                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1009                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1010                 :            : 
+    1011                 :          1 :     response_size = sizeof(response);
+    1012                 :          1 :     status = libspdm_get_response_algorithms(
+    1013                 :            :         spdm_context, m_libspdm_negotiate_algorithms_request2_size,
+    1014                 :            :         &m_libspdm_negotiate_algorithms_request2, &response_size,
+    1015                 :            :         response);
+    1016                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1017                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1018                 :          1 :     spdm_response = (void *)response;
+    1019                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1020                 :            :                      SPDM_ERROR);
+    1021                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1022                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+    1023                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1024                 :          1 : }
+    1025                 :            : 
+    1026                 :          1 : void libspdm_test_responder_algorithms_case3(void **state)
+    1027                 :            : {
+    1028                 :            :     libspdm_return_t status;
+    1029                 :            :     libspdm_test_context_t *spdm_test_context;
+    1030                 :            :     libspdm_context_t *spdm_context;
+    1031                 :            :     size_t response_size;
+    1032                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1033                 :            :     spdm_algorithms_response_t *spdm_response;
+    1034                 :            : 
+    1035                 :          1 :     spdm_test_context = *state;
+    1036                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1037                 :          1 :     spdm_test_context->case_id = 0x3;
+    1038                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1039                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1040                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_BUSY;
+    1041                 :          1 :     spdm_context->connection_info.connection_state =
+    1042                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1043                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1044                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1045                 :            : 
+    1046                 :          1 :     response_size = sizeof(response);
+    1047                 :          1 :     status = libspdm_get_response_algorithms(
+    1048                 :            :         spdm_context, m_libspdm_negotiate_algorithms_request1_size,
+    1049                 :            :         &m_libspdm_negotiate_algorithms_request1, &response_size,
+    1050                 :            :         response);
+    1051                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1052                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1053                 :          1 :     spdm_response = (void *)response;
+    1054                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1055                 :            :                      SPDM_ERROR);
+    1056                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_BUSY);
+    1057                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1058                 :          1 :     assert_int_equal(spdm_context->response_state,
+    1059                 :            :                      LIBSPDM_RESPONSE_STATE_BUSY);
+    1060                 :          1 : }
+    1061                 :            : 
+    1062                 :          1 : void libspdm_test_responder_algorithms_case4(void **state)
+    1063                 :            : {
+    1064                 :            :     libspdm_return_t status;
+    1065                 :            :     libspdm_test_context_t *spdm_test_context;
+    1066                 :            :     libspdm_context_t *spdm_context;
+    1067                 :            :     size_t response_size;
+    1068                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1069                 :            :     spdm_algorithms_response_t *spdm_response;
+    1070                 :            : 
+    1071                 :          1 :     spdm_test_context = *state;
+    1072                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1073                 :          1 :     spdm_test_context->case_id = 0x4;
+    1074                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1075                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1076                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NEED_RESYNC;
+    1077                 :          1 :     spdm_context->connection_info.connection_state =
+    1078                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1079                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1080                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1081                 :            : 
+    1082                 :          1 :     response_size = sizeof(response);
+    1083                 :          1 :     status = libspdm_get_response_algorithms(
+    1084                 :            :         spdm_context, m_libspdm_negotiate_algorithms_request1_size,
+    1085                 :            :         &m_libspdm_negotiate_algorithms_request1, &response_size,
+    1086                 :            :         response);
+    1087                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1088                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1089                 :          1 :     spdm_response = (void *)response;
+    1090                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1091                 :            :                      SPDM_ERROR);
+    1092                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1093                 :            :                      SPDM_ERROR_CODE_REQUEST_RESYNCH);
+    1094                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1095                 :          1 :     assert_int_equal(spdm_context->response_state,
+    1096                 :            :                      LIBSPDM_RESPONSE_STATE_NEED_RESYNC);
+    1097                 :          1 : }
+    1098                 :            : 
+    1099                 :          1 : void libspdm_test_responder_algorithms_case6(void **state)
+    1100                 :            : {
+    1101                 :            :     libspdm_return_t status;
+    1102                 :            :     libspdm_test_context_t *spdm_test_context;
+    1103                 :            :     libspdm_context_t *spdm_context;
+    1104                 :            :     size_t response_size;
+    1105                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1106                 :            :     spdm_algorithms_response_t *spdm_response;
+    1107                 :            : 
+    1108                 :          1 :     spdm_test_context = *state;
+    1109                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1110                 :          1 :     spdm_test_context->case_id = 0x6;
+    1111                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1112                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1113                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+    1114                 :          1 :     spdm_context->connection_info.connection_state =
+    1115                 :            :         LIBSPDM_CONNECTION_STATE_NOT_STARTED;
+    1116                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1117                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1118                 :            : 
+    1119                 :          1 :     response_size = sizeof(response);
+    1120                 :          1 :     status = libspdm_get_response_algorithms(
+    1121                 :            :         spdm_context, m_libspdm_negotiate_algorithms_request1_size,
+    1122                 :            :         &m_libspdm_negotiate_algorithms_request1, &response_size,
+    1123                 :            :         response);
+    1124                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1125                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1126                 :          1 :     spdm_response = (void *)response;
+    1127                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1128                 :            :                      SPDM_ERROR);
+    1129                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1130                 :            :                      SPDM_ERROR_CODE_UNEXPECTED_REQUEST);
+    1131                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1132                 :          1 : }
+    1133                 :            : 
+    1134                 :          1 : void libspdm_test_responder_algorithms_case7(void **state) {
+    1135                 :            :     libspdm_return_t status;
+    1136                 :            :     libspdm_test_context_t    *spdm_test_context;
+    1137                 :            :     libspdm_context_t  *spdm_context;
+    1138                 :            :     size_t response_size;
+    1139                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1140                 :            :     libspdm_algorithms_response_mine_t *spdm_response;
+    1141                 :            : 
+    1142                 :          1 :     spdm_test_context = *state;
+    1143                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1144                 :          1 :     spdm_test_context->case_id = 0x7;
+    1145                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1146                 :            : 
+    1147                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1148                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1149                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1150                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1151                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    1152                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    1153                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    1154                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    1155                 :            : 
+    1156                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1157                 :            : 
+    1158                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    1159                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1160                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    1161                 :            : 
+    1162                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    1163                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1164                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    1165                 :            : 
+    1166                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    1167                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    1168                 :            : 
+    1169                 :          1 :     spdm_context->local_context.capability.flags |=
+    1170                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    1171                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1172                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    1173                 :            : 
+    1174                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1175                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1176                 :            : 
+    1177                 :          1 :     response_size = sizeof(response);
+    1178                 :          1 :     status = libspdm_get_response_algorithms (spdm_context,
+    1179                 :            :                                               m_libspdm_negotiate_algorithm_request3_size,
+    1180                 :            :                                               &m_libspdm_negotiate_algorithm_request3,
+    1181                 :            :                                               &response_size,
+    1182                 :            :                                               response);
+    1183                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+    1184                 :          1 :     assert_int_equal (response_size,
+    1185                 :            :                       sizeof(spdm_algorithms_response_t)+4*
+    1186                 :            :                       sizeof(spdm_negotiate_algorithms_common_struct_table_t));
+    1187                 :          1 :     spdm_response = (void *)response;
+    1188                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_ALGORITHMS);
+    1189                 :          1 :     assert_int_equal (spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_11);
+    1190                 :            : 
+    1191                 :          1 :     assert_int_equal (spdm_response->struct_table[0].alg_supported,
+    1192                 :            :                       spdm_context->local_context.algorithm.dhe_named_group);
+    1193                 :          1 :     assert_int_equal (spdm_response->struct_table[1].alg_supported,
+    1194                 :            :                       spdm_context->local_context.algorithm.aead_cipher_suite);
+    1195                 :          1 :     assert_int_equal (spdm_response->struct_table[2].alg_supported,
+    1196                 :            :                       spdm_context->local_context.algorithm.req_base_asym_alg);
+    1197                 :          1 :     assert_int_equal (spdm_response->struct_table[3].alg_supported,
+    1198                 :            :                       spdm_context->local_context.algorithm.key_schedule);
+    1199                 :          1 : }
+    1200                 :            : 
+    1201                 :          1 : void libspdm_test_responder_algorithms_case8(void **state) {
+    1202                 :            :     libspdm_return_t status;
+    1203                 :            :     libspdm_test_context_t    *spdm_test_context;
+    1204                 :            :     libspdm_context_t  *spdm_context;
+    1205                 :            :     size_t response_size;
+    1206                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1207                 :            :     spdm_algorithms_response_t *spdm_response;
+    1208                 :            : 
+    1209                 :          1 :     spdm_test_context = *state;
+    1210                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1211                 :          1 :     spdm_test_context->case_id = 0x8;
+    1212                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1213                 :            : 
+    1214                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1215                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1216                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1217                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1218                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    1219                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    1220                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    1221                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    1222                 :            : 
+    1223                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1224                 :            : 
+    1225                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP;
+    1226                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
+    1227                 :            : 
+    1228                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    1229                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1230                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    1231                 :            : 
+    1232                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    1233                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1234                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    1235                 :            : 
+    1236                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    1237                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    1238                 :            : 
+    1239                 :          1 :     spdm_context->local_context.capability.flags |=
+    1240                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    1241                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1242                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    1243                 :            : 
+    1244                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1245                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1246                 :            : 
+    1247                 :          1 :     response_size = sizeof(response);
+    1248                 :          1 :     status = libspdm_get_response_algorithms (spdm_context,
+    1249                 :            :                                               m_libspdm_negotiate_algorithm_request4_size,
+    1250                 :            :                                               &m_libspdm_negotiate_algorithm_request4,
+    1251                 :            :                                               &response_size,
+    1252                 :            :                                               response);
+    1253                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+    1254                 :          1 :     assert_int_equal (response_size, sizeof(spdm_error_response_t));
+    1255                 :          1 :     spdm_response = (void *)response;
+    1256                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_ERROR);
+    1257                 :          1 :     assert_int_equal (spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+    1258                 :          1 :     assert_int_equal (spdm_response->header.param2, 0);
+    1259                 :          1 : }
+    1260                 :            : 
+    1261                 :          1 : void libspdm_test_responder_algorithms_case9(void **state) {
+    1262                 :            :     libspdm_return_t status;
+    1263                 :            :     libspdm_test_context_t    *spdm_test_context;
+    1264                 :            :     libspdm_context_t  *spdm_context;
+    1265                 :            :     size_t response_size;
+    1266                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1267                 :            :     spdm_algorithms_response_t *spdm_response;
+    1268                 :            : 
+    1269                 :          1 :     spdm_test_context = *state;
+    1270                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1271                 :          1 :     spdm_test_context->case_id = 0x9;
+    1272                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1273                 :            : 
+    1274                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1275                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1276                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1277                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1278                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    1279                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    1280                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    1281                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    1282                 :            : 
+    1283                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1284                 :            : 
+    1285                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP;
+    1286                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
+    1287                 :            : 
+    1288                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    1289                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1290                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    1291                 :            : 
+    1292                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    1293                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1294                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    1295                 :            : 
+    1296                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    1297                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    1298                 :            : 
+    1299                 :          1 :     spdm_context->local_context.capability.flags |=
+    1300                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    1301                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1302                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    1303                 :            : 
+    1304                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1305                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1306                 :            : 
+    1307                 :          1 :     response_size = sizeof(response);
+    1308                 :          1 :     status = libspdm_get_response_algorithms (spdm_context,
+    1309                 :            :                                               m_libspdm_negotiate_algorithm_request5_size,
+    1310                 :            :                                               &m_libspdm_negotiate_algorithm_request5,
+    1311                 :            :                                               &response_size,
+    1312                 :            :                                               response);
+    1313                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+    1314                 :          1 :     assert_int_equal (response_size, sizeof(spdm_error_response_t));
+    1315                 :          1 :     spdm_response = (void *)response;
+    1316                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_ERROR);
+    1317                 :          1 :     assert_int_equal (spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+    1318                 :          1 :     assert_int_equal (spdm_response->header.param2, 0);
+    1319                 :          1 : }
+    1320                 :            : 
+    1321                 :          1 : void libspdm_test_responder_algorithms_case10(void **state) {
+    1322                 :            :     libspdm_return_t status;
+    1323                 :            :     libspdm_test_context_t    *spdm_test_context;
+    1324                 :            :     libspdm_context_t  *spdm_context;
+    1325                 :            :     size_t response_size;
+    1326                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1327                 :            :     spdm_algorithms_response_t *spdm_response;
+    1328                 :            : 
+    1329                 :          1 :     spdm_test_context = *state;
+    1330                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1331                 :          1 :     spdm_test_context->case_id = 0xA;
+    1332                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1333                 :            : 
+    1334                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1335                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1336                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1337                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1338                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    1339                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    1340                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    1341                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    1342                 :            : 
+    1343                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1344                 :            : 
+    1345                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP;
+    1346                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
+    1347                 :            : 
+    1348                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    1349                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1350                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    1351                 :            : 
+    1352                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    1353                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1354                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    1355                 :            : 
+    1356                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    1357                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    1358                 :            : 
+    1359                 :          1 :     spdm_context->local_context.capability.flags |=
+    1360                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    1361                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1362                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    1363                 :            : 
+    1364                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1365                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1366                 :            : 
+    1367                 :          1 :     response_size = sizeof(response);
+    1368                 :          1 :     status = libspdm_get_response_algorithms (spdm_context,
+    1369                 :            :                                               m_libspdm_negotiate_algorithm_request6_size,
+    1370                 :            :                                               &m_libspdm_negotiate_algorithm_request6,
+    1371                 :            :                                               &response_size,
+    1372                 :            :                                               response);
+    1373                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+    1374                 :          1 :     assert_int_equal (response_size, sizeof(spdm_error_response_t));
+    1375                 :          1 :     spdm_response = (void *)response;
+    1376                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_ERROR);
+    1377                 :          1 :     assert_int_equal (spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+    1378                 :          1 :     assert_int_equal (spdm_response->header.param2, 0);
+    1379                 :          1 : }
+    1380                 :            : 
+    1381                 :          1 : void libspdm_test_responder_algorithms_case11(void **state) {
+    1382                 :            :     libspdm_return_t status;
+    1383                 :            :     libspdm_test_context_t    *spdm_test_context;
+    1384                 :            :     libspdm_context_t  *spdm_context;
+    1385                 :            :     size_t response_size;
+    1386                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1387                 :            :     spdm_algorithms_response_t *spdm_response;
+    1388                 :            : 
+    1389                 :          1 :     spdm_test_context = *state;
+    1390                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1391                 :          1 :     spdm_test_context->case_id = 0xB;
+    1392                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1393                 :            : 
+    1394                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1395                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1396                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1397                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1398                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    1399                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    1400                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    1401                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    1402                 :            : 
+    1403                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1404                 :            : 
+    1405                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP;
+    1406                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
+    1407                 :            : 
+    1408                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    1409                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1410                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    1411                 :            : 
+    1412                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    1413                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1414                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    1415                 :            : 
+    1416                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    1417                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    1418                 :            : 
+    1419                 :          1 :     spdm_context->local_context.capability.flags |=
+    1420                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    1421                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1422                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    1423                 :            : 
+    1424                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1425                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1426                 :            : 
+    1427                 :          1 :     response_size = sizeof(response);
+    1428                 :          1 :     status = libspdm_get_response_algorithms (spdm_context,
+    1429                 :            :                                               m_libspdm_negotiate_algorithm_request7_size,
+    1430                 :            :                                               &m_libspdm_negotiate_algorithm_request7,
+    1431                 :            :                                               &response_size,
+    1432                 :            :                                               response);
+    1433                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+    1434                 :          1 :     assert_int_equal (response_size, sizeof(spdm_error_response_t));
+    1435                 :          1 :     spdm_response = (void *)response;
+    1436                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_ERROR);
+    1437                 :          1 :     assert_int_equal (spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+    1438                 :          1 :     assert_int_equal (spdm_response->header.param2, 0);
+    1439                 :          1 : }
+    1440                 :            : 
+    1441                 :          1 : void libspdm_test_responder_algorithms_case12(void **state) {
+    1442                 :            :     libspdm_return_t status;
+    1443                 :            :     libspdm_test_context_t    *spdm_test_context;
+    1444                 :            :     libspdm_context_t  *spdm_context;
+    1445                 :            :     size_t response_size;
+    1446                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1447                 :            :     spdm_algorithms_response_t *spdm_response;
+    1448                 :            : 
+    1449                 :          1 :     spdm_test_context = *state;
+    1450                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1451                 :          1 :     spdm_test_context->case_id = 0xC;
+    1452                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1453                 :            : 
+    1454                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1455                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1456                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1457                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1458                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    1459                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    1460                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    1461                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    1462                 :            : 
+    1463                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1464                 :            : 
+    1465                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP;
+    1466                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
+    1467                 :            : 
+    1468                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    1469                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1470                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    1471                 :            : 
+    1472                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    1473                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1474                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    1475                 :            : 
+    1476                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    1477                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    1478                 :            : 
+    1479                 :          1 :     spdm_context->local_context.capability.flags |=
+    1480                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    1481                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1482                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    1483                 :            : 
+    1484                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1485                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1486                 :            : 
+    1487                 :          1 :     response_size = sizeof(response);
+    1488                 :          1 :     status = libspdm_get_response_algorithms (spdm_context,
+    1489                 :            :                                               m_libspdm_negotiate_algorithm_request8_size,
+    1490                 :            :                                               &m_libspdm_negotiate_algorithm_request8,
+    1491                 :            :                                               &response_size,
+    1492                 :            :                                               response);
+    1493                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+    1494                 :          1 :     assert_int_equal (response_size, sizeof(spdm_error_response_t));
+    1495                 :          1 :     spdm_response = (void *)response;
+    1496                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_ERROR);
+    1497                 :          1 :     assert_int_equal (spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+    1498                 :          1 :     assert_int_equal (spdm_response->header.param2, 0);
+    1499                 :          1 : }
+    1500                 :            : 
+    1501                 :          1 : void libspdm_test_responder_algorithms_case13(void **state) {
+    1502                 :            :     libspdm_return_t status;
+    1503                 :            :     libspdm_test_context_t    *spdm_test_context;
+    1504                 :            :     libspdm_context_t  *spdm_context;
+    1505                 :            :     size_t response_size;
+    1506                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1507                 :            :     spdm_algorithms_response_t *spdm_response;
+    1508                 :            : 
+    1509                 :          1 :     spdm_test_context = *state;
+    1510                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1511                 :          1 :     spdm_test_context->case_id = 0xD;
+    1512                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1513                 :            : 
+    1514                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1515                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1516                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1517                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1518                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    1519                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    1520                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    1521                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    1522                 :            : 
+    1523                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1524                 :            : 
+    1525                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP;
+    1526                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
+    1527                 :            : 
+    1528                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    1529                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1530                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    1531                 :            : 
+    1532                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    1533                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1534                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    1535                 :            : 
+    1536                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    1537                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    1538                 :            : 
+    1539                 :          1 :     spdm_context->local_context.capability.flags |=
+    1540                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    1541                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1542                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    1543                 :            : 
+    1544                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1545                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1546                 :            : 
+    1547                 :          1 :     response_size = sizeof(response);
+    1548                 :          1 :     status = libspdm_get_response_algorithms (spdm_context,
+    1549                 :            :                                               m_libspdm_negotiate_algorithm_request9_size,
+    1550                 :            :                                               &m_libspdm_negotiate_algorithm_request9,
+    1551                 :            :                                               &response_size,
+    1552                 :            :                                               response);
+    1553                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+    1554                 :          1 :     assert_int_equal (response_size, sizeof(spdm_error_response_t));
+    1555                 :          1 :     spdm_response = (void *)response;
+    1556                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_ERROR);
+    1557                 :          1 :     assert_int_equal (spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+    1558                 :          1 :     assert_int_equal (spdm_response->header.param2, 0);
+    1559                 :          1 : }
+    1560                 :            : 
+    1561                 :          1 : void libspdm_test_responder_algorithms_case14(void **state) {
+    1562                 :            :     libspdm_return_t status;
+    1563                 :            :     libspdm_test_context_t    *spdm_test_context;
+    1564                 :            :     libspdm_context_t  *spdm_context;
+    1565                 :            :     size_t response_size;
+    1566                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1567                 :            :     spdm_algorithms_response_t *spdm_response;
+    1568                 :            : 
+    1569                 :          1 :     spdm_test_context = *state;
+    1570                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1571                 :          1 :     spdm_test_context->case_id = 0xE;
+    1572                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1573                 :            : 
+    1574                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1575                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1576                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1577                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1578                 :            : 
+    1579                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1580                 :            : 
+    1581                 :          1 :     response_size = sizeof(response);
+    1582                 :          1 :     status = libspdm_get_response_algorithms (spdm_context,
+    1583                 :            :                                               m_libspdm_negotiate_algorithm_request10_size,
+    1584                 :            :                                               &m_libspdm_negotiate_algorithm_request10,
+    1585                 :            :                                               &response_size,
+    1586                 :            :                                               response);
+    1587                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+    1588                 :          1 :     assert_int_equal (response_size, sizeof(spdm_error_response_t));
+    1589                 :          1 :     spdm_response = (void *)response;
+    1590                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_ERROR);
+    1591                 :          1 :     assert_int_equal (spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+    1592                 :          1 :     assert_int_equal (spdm_response->header.param2, 0);
+    1593                 :          1 : }
+    1594                 :            : 
+    1595                 :          1 : void libspdm_test_responder_algorithms_case15(void **state) {
+    1596                 :            :     libspdm_return_t status;
+    1597                 :            :     libspdm_test_context_t    *spdm_test_context;
+    1598                 :            :     libspdm_context_t  *spdm_context;
+    1599                 :            :     size_t response_size;
+    1600                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1601                 :            :     spdm_algorithms_response_t *spdm_response;
+    1602                 :            : 
+    1603                 :          1 :     spdm_test_context = *state;
+    1604                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1605                 :          1 :     spdm_test_context->case_id = 0xF;
+    1606                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1607                 :            : 
+    1608                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1609                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1610                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1611                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1612                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    1613                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    1614                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    1615                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    1616                 :            : 
+    1617                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1618                 :            : 
+    1619                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    1620                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1621                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    1622                 :            : 
+    1623                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    1624                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1625                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    1626                 :            : 
+    1627                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    1628                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    1629                 :            : 
+    1630                 :          1 :     spdm_context->local_context.capability.flags |=
+    1631                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    1632                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1633                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    1634                 :            : 
+    1635                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1636                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1637                 :            : 
+    1638                 :          1 :     response_size = sizeof(response);
+    1639                 :          1 :     status = libspdm_get_response_algorithms (spdm_context,
+    1640                 :            :                                               m_libspdm_negotiate_algorithm_request11_size,
+    1641                 :            :                                               &m_libspdm_negotiate_algorithm_request11,
+    1642                 :            :                                               &response_size,
+    1643                 :            :                                               response);
+    1644                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+    1645                 :          1 :     assert_int_equal (response_size, sizeof(spdm_error_response_t));
+    1646                 :          1 :     spdm_response = (void *)response;
+    1647                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_ERROR);
+    1648                 :          1 :     assert_int_equal (spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+    1649                 :          1 :     assert_int_equal (spdm_response->header.param2, 0);
+    1650                 :          1 : }
+    1651                 :            : 
+    1652                 :          1 : void libspdm_test_responder_algorithms_case16(void **state) {
+    1653                 :            :     libspdm_return_t status;
+    1654                 :            :     libspdm_test_context_t    *spdm_test_context;
+    1655                 :            :     libspdm_context_t  *spdm_context;
+    1656                 :            :     size_t response_size;
+    1657                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1658                 :            :     libspdm_algorithms_response_mine_t *spdm_response;
+    1659                 :            : 
+    1660                 :          1 :     spdm_test_context = *state;
+    1661                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1662                 :          1 :     spdm_test_context->case_id = 0x10;
+    1663                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1664                 :            : 
+    1665                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1666                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1667                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1668                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1669                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    1670                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    1671                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    1672                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    1673                 :            : 
+    1674                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1675                 :            : 
+    1676                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    1677                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1678                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    1679                 :            : 
+    1680                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    1681                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1682                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    1683                 :            : 
+    1684                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    1685                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    1686                 :            : 
+    1687                 :          1 :     spdm_context->local_context.capability.flags |=
+    1688                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    1689                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1690                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    1691                 :            : 
+    1692                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1693                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1694                 :            : 
+    1695                 :          1 :     response_size = sizeof(response);
+    1696                 :          1 :     status = libspdm_get_response_algorithms (spdm_context,
+    1697                 :            :                                               m_libspdm_negotiate_algorithm_request12_size,
+    1698                 :            :                                               &m_libspdm_negotiate_algorithm_request12,
+    1699                 :            :                                               &response_size,
+    1700                 :            :                                               response);
+    1701                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1702                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1703                 :          1 :     spdm_response = (void*)response;
+    1704                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
+    1705                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+    1706                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1707                 :          1 : }
+    1708                 :            : 
+    1709                 :          1 : void libspdm_test_responder_algorithms_case17(void **state) {
+    1710                 :            :     libspdm_return_t status;
+    1711                 :            :     libspdm_test_context_t    *spdm_test_context;
+    1712                 :            :     libspdm_context_t  *spdm_context;
+    1713                 :            :     size_t response_size;
+    1714                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1715                 :            :     libspdm_algorithms_response_mine_t *spdm_response;
+    1716                 :            : 
+    1717                 :          1 :     spdm_test_context = *state;
+    1718                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1719                 :          1 :     spdm_test_context->case_id = 0x11;
+    1720                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1721                 :            : 
+    1722                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1723                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1724                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1725                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1726                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    1727                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    1728                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    1729                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    1730                 :            : 
+    1731                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1732                 :            : 
+    1733                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    1734                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1735                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    1736                 :            : 
+    1737                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    1738                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1739                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    1740                 :            : 
+    1741                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    1742                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    1743                 :            : 
+    1744                 :          1 :     spdm_context->local_context.capability.flags |=
+    1745                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    1746                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1747                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    1748                 :            : 
+    1749                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1750                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1751                 :            : 
+    1752                 :          1 :     response_size = sizeof(response);
+    1753                 :          1 :     status = libspdm_get_response_algorithms (spdm_context,
+    1754                 :            :                                               m_libspdm_negotiate_algorithm_request13_size,
+    1755                 :            :                                               &m_libspdm_negotiate_algorithm_request13,
+    1756                 :            :                                               &response_size,
+    1757                 :            :                                               response);
+    1758                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1759                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1760                 :          1 :     spdm_response = (void*)response;
+    1761                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
+    1762                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+    1763                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1764                 :          1 : }
+    1765                 :            : 
+    1766                 :          1 : void libspdm_test_responder_algorithms_case18(void **state) {
+    1767                 :            :     libspdm_return_t status;
+    1768                 :            :     libspdm_test_context_t    *spdm_test_context;
+    1769                 :            :     libspdm_context_t  *spdm_context;
+    1770                 :            :     size_t response_size;
+    1771                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1772                 :            :     libspdm_algorithms_response_mine_t *spdm_response;
+    1773                 :            : 
+    1774                 :          1 :     spdm_test_context = *state;
+    1775                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1776                 :          1 :     spdm_test_context->case_id = 0x12;
+    1777                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1778                 :            : 
+    1779                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1780                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1781                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1782                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1783                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    1784                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    1785                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    1786                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    1787                 :            : 
+    1788                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1789                 :            : 
+    1790                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    1791                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1792                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    1793                 :            : 
+    1794                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    1795                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1796                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    1797                 :            : 
+    1798                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    1799                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    1800                 :            : 
+    1801                 :          1 :     spdm_context->local_context.capability.flags |=
+    1802                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    1803                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1804                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    1805                 :            : 
+    1806                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1807                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1808                 :            : 
+    1809                 :          1 :     response_size = sizeof(response);
+    1810                 :          1 :     status = libspdm_get_response_algorithms (spdm_context,
+    1811                 :            :                                               m_libspdm_negotiate_algorithm_request14_size,
+    1812                 :            :                                               &m_libspdm_negotiate_algorithm_request14,
+    1813                 :            :                                               &response_size,
+    1814                 :            :                                               response);
+    1815                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+    1816                 :          1 :     assert_int_equal (response_size, sizeof(spdm_error_response_t));
+    1817                 :          1 :     spdm_response = (void *)response;
+    1818                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_ERROR);
+    1819                 :          1 :     assert_int_equal (spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+    1820                 :          1 :     assert_int_equal (spdm_response->header.param2, 0);
+    1821                 :          1 : }
+    1822                 :            : 
+    1823                 :          1 : void libspdm_test_responder_algorithms_case19(void **state) {
+    1824                 :            :     libspdm_return_t status;
+    1825                 :            :     libspdm_test_context_t    *spdm_test_context;
+    1826                 :            :     libspdm_context_t  *spdm_context;
+    1827                 :            :     size_t response_size;
+    1828                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1829                 :            :     libspdm_algorithms_response_mine_t *spdm_response;
+    1830                 :            : 
+    1831                 :          1 :     spdm_test_context = *state;
+    1832                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1833                 :          1 :     spdm_test_context->case_id = 0x13;
+    1834                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1835                 :            : 
+    1836                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1837                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1838                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1839                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1840                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    1841                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    1842                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    1843                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    1844                 :            : 
+    1845                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1846                 :            : 
+    1847                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    1848                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1849                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    1850                 :            : 
+    1851                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    1852                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1853                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    1854                 :            : 
+    1855                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    1856                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    1857                 :            : 
+    1858                 :          1 :     spdm_context->local_context.capability.flags |=
+    1859                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    1860                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1861                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    1862                 :            : 
+    1863                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1864                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1865                 :            : 
+    1866                 :          1 :     response_size = sizeof(response);
+    1867                 :          1 :     status = libspdm_get_response_algorithms (spdm_context,
+    1868                 :            :                                               m_libspdm_negotiate_algorithm_request15_size,
+    1869                 :            :                                               &m_libspdm_negotiate_algorithm_request15,
+    1870                 :            :                                               &response_size,
+    1871                 :            :                                               response);
+    1872                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1873                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1874                 :          1 :     spdm_response = (void*)response;
+    1875                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
+    1876                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+    1877                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1878                 :          1 : }
+    1879                 :            : 
+    1880                 :            : /* When both of requester and responder support multiple algorithms, then defaults to choose the strongest available algorithm*/
+    1881                 :          1 : void libspdm_test_responder_algorithms_case20(void **state) {
+    1882                 :            :     libspdm_return_t status;
+    1883                 :            :     libspdm_test_context_t    *spdm_test_context;
+    1884                 :            :     libspdm_context_t  *spdm_context;
+    1885                 :            :     size_t response_size;
+    1886                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1887                 :            :     libspdm_algorithms_response_mine_t *spdm_response;
+    1888                 :            : 
+    1889                 :          1 :     spdm_test_context = *state;
+    1890                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1891                 :          1 :     spdm_test_context->case_id = 0x14;
+    1892                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1893                 :            : 
+    1894                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1895                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1896                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo =
+    1897                 :            :         SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512 |
+    1898                 :            :         SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256;
+    1899                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo =
+    1900                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521 |
+    1901                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384 |
+    1902                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048;
+    1903                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group =
+    1904                 :            :         SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_521_R1 |
+    1905                 :            :         SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_384_R1 |
+    1906                 :            :         SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_256_R1;
+    1907                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    1908                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    1909                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    1910                 :            : 
+    1911                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1912                 :            : 
+    1913                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    1914                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1915                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    1916                 :            : 
+    1917                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    1918                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1919                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    1920                 :            : 
+    1921                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    1922                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    1923                 :            : 
+    1924                 :          1 :     spdm_context->local_context.capability.flags |=
+    1925                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    1926                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1927                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    1928                 :            : 
+    1929                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1930                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1931                 :            : 
+    1932                 :          1 :     response_size = sizeof(response);
+    1933                 :          1 :     status = libspdm_get_response_algorithms (spdm_context,
+    1934                 :            :                                               m_libspdm_negotiate_algorithm_request16_size,
+    1935                 :            :                                               &m_libspdm_negotiate_algorithm_request16,
+    1936                 :            :                                               &response_size,
+    1937                 :            :                                               response);
+    1938                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+    1939                 :          1 :     assert_int_equal (response_size,
+    1940                 :            :                       sizeof(spdm_algorithms_response_t)+4*
+    1941                 :            :                       sizeof(spdm_negotiate_algorithms_common_struct_table_t));
+    1942                 :          1 :     spdm_response = (void *)response;
+    1943                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_ALGORITHMS);
+    1944                 :          1 :     assert_int_equal (spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_11);
+    1945                 :            : 
+    1946                 :          1 :     assert_int_equal (spdm_response->base_hash_sel, SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512);
+    1947                 :          1 :     assert_int_equal (spdm_response->base_hash_sel,
+    1948                 :            :                       spdm_context->connection_info.algorithm.base_hash_algo);
+    1949                 :            : 
+    1950                 :          1 :     assert_int_equal (spdm_response->base_asym_sel,
+    1951                 :            :                       SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521);
+    1952                 :          1 :     assert_int_equal (spdm_response->base_asym_sel,
+    1953                 :            :                       spdm_context->connection_info.algorithm.base_asym_algo);
+    1954                 :            : 
+    1955                 :          1 :     assert_int_equal (spdm_response->struct_table[0].alg_supported,
+    1956                 :            :                       SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_384_R1);
+    1957                 :          1 :     assert_int_equal (spdm_response->struct_table[0].alg_supported,
+    1958                 :            :                       spdm_context->connection_info.algorithm.dhe_named_group);
+    1959                 :            : 
+    1960                 :          1 :     assert_int_equal (spdm_response->struct_table[1].alg_supported,
+    1961                 :            :                       spdm_context->connection_info.algorithm.aead_cipher_suite);
+    1962                 :          1 :     assert_int_equal (spdm_response->struct_table[2].alg_supported,
+    1963                 :            :                       spdm_context->connection_info.algorithm.req_base_asym_alg);
+    1964                 :          1 :     assert_int_equal (spdm_response->struct_table[3].alg_supported,
+    1965                 :            :                       spdm_context->connection_info.algorithm.key_schedule);
+    1966                 :          1 : }
+    1967                 :            : 
+    1968                 :          1 : void libspdm_test_responder_algorithms_case21(void **state) {
+    1969                 :            :     libspdm_return_t status;
+    1970                 :            :     libspdm_test_context_t *spdm_test_context;
+    1971                 :            :     libspdm_context_t *spdm_context;
+    1972                 :            :     size_t response_size;
+    1973                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1974                 :            :     libspdm_algorithms_response_mine_t *spdm_response;
+    1975                 :            :     size_t arbitrary_size;
+    1976                 :            : 
+    1977                 :          1 :     spdm_test_context = *state;
+    1978                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1979                 :          1 :     spdm_test_context->case_id = 0x15;
+    1980                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    1981                 :            : 
+    1982                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1983                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1984                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1985                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1986                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    1987                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    1988                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    1989                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    1990                 :            : 
+    1991                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1992                 :            : 
+    1993                 :          1 :     spdm_context->local_context.capability.flags |=
+    1994                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    1995                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1996                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    1997                 :            : 
+    1998                 :          1 :     spdm_context->local_context.capability.flags |=
+    1999                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    2000                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2001                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    2002                 :            : 
+    2003                 :          1 :     spdm_context->local_context.capability.flags |=
+    2004                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    2005                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2006                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    2007                 :            : 
+    2008                 :          1 :     spdm_context->local_context.capability.flags |=
+    2009                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    2010                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2011                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    2012                 :            : 
+    2013                 :          1 :     spdm_context->local_context.capability.flags |=
+    2014                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    2015                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2016                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    2017                 :            : 
+    2018                 :            :     /*filling A with arbitrary data*/
+    2019                 :          1 :     arbitrary_size = 10;
+    2020                 :          1 :     libspdm_set_mem(spdm_context->transcript.message_a.buffer, arbitrary_size, (uint8_t) 0xFF);
+    2021                 :          1 :     spdm_context->transcript.message_a.buffer_size = arbitrary_size;
+    2022                 :            : 
+    2023                 :          1 :     response_size = sizeof(response);
+    2024                 :          1 :     status = libspdm_get_response_algorithms(
+    2025                 :            :         spdm_context,
+    2026                 :            :         m_libspdm_negotiate_algorithm_request3_size, &m_libspdm_negotiate_algorithm_request3,
+    2027                 :            :         &response_size, response);
+    2028                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2029                 :          1 :     assert_int_equal(response_size,
+    2030                 :            :                      sizeof(spdm_algorithms_response_t) +
+    2031                 :            :                      4*sizeof(spdm_negotiate_algorithms_common_struct_table_t));
+    2032                 :          1 :     spdm_response = (void *)response;
+    2033                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ALGORITHMS);
+    2034                 :          1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_11);
+    2035                 :            : 
+    2036                 :          1 :     assert_int_equal(spdm_response->struct_table[0].alg_supported,
+    2037                 :            :                      spdm_context->local_context.algorithm.dhe_named_group);
+    2038                 :          1 :     assert_int_equal(spdm_response->struct_table[1].alg_supported,
+    2039                 :            :                      spdm_context->local_context.algorithm.aead_cipher_suite);
+    2040                 :          1 :     assert_int_equal(spdm_response->struct_table[2].alg_supported,
+    2041                 :            :                      spdm_context->local_context.algorithm.req_base_asym_alg);
+    2042                 :          1 :     assert_int_equal(spdm_response->struct_table[3].alg_supported,
+    2043                 :            :                      spdm_context->local_context.algorithm.key_schedule);
+    2044                 :            : 
+    2045                 :          1 :     assert_int_equal(spdm_context->transcript.message_a.buffer_size,
+    2046                 :            :                      arbitrary_size + m_libspdm_negotiate_algorithm_request3_size + response_size);
+    2047                 :          1 :     assert_memory_equal(spdm_context->transcript.message_a.buffer + arbitrary_size,
+    2048                 :            :                         &m_libspdm_negotiate_algorithm_request3,
+    2049                 :            :                         m_libspdm_negotiate_algorithm_request3_size);
+    2050                 :          1 :     assert_memory_equal(spdm_context->transcript.message_a.buffer + arbitrary_size +
+    2051                 :            :                         m_libspdm_negotiate_algorithm_request3_size, response, response_size);
+    2052                 :          1 : }
+    2053                 :            : 
+    2054                 :          1 : void libspdm_test_responder_algorithms_case22(void **state)
+    2055                 :            : {
+    2056                 :            :     libspdm_return_t status;
+    2057                 :            :     libspdm_test_context_t    *spdm_test_context;
+    2058                 :            :     libspdm_context_t  *spdm_context;
+    2059                 :            :     size_t response_size;
+    2060                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    2061                 :            :     libspdm_algorithms_response_mine_t *spdm_response;
+    2062                 :            : 
+    2063                 :          1 :     spdm_test_context = *state;
+    2064                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2065                 :          1 :     spdm_test_context->case_id = 0x16;
+    2066                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2067                 :            : 
+    2068                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    2069                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2070                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2071                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2072                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    2073                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    2074                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    2075                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    2076                 :          1 :     spdm_context->local_context.algorithm.other_params_support =
+    2077                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
+    2078                 :            :     /* spdm_context->connection_info.algorithm.other_params_support = SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1; */
+    2079                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2080                 :          1 :     spdm_context->local_context.capability.flags = 0;
+    2081                 :          1 :     spdm_context->connection_info.capability.flags = 0;
+    2082                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    2083                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2084                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    2085                 :            : 
+    2086                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    2087                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2088                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    2089                 :            : 
+    2090                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    2091                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    2092                 :            : 
+    2093                 :          1 :     spdm_context->local_context.capability.flags |=
+    2094                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    2095                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2096                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    2097                 :            : 
+    2098                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    2099                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    2100                 :            : 
+    2101                 :          1 :     response_size = sizeof(response);
+    2102                 :          1 :     status = libspdm_get_response_algorithms (spdm_context,
+    2103                 :            :                                               m_libspdm_negotiate_algorithm_request17_size,
+    2104                 :            :                                               &m_libspdm_negotiate_algorithm_request17,
+    2105                 :            :                                               &response_size,
+    2106                 :            :                                               response);
+    2107                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+    2108                 :          1 :     assert_int_equal (response_size,
+    2109                 :            :                       sizeof(spdm_algorithms_response_t)+4*
+    2110                 :            :                       sizeof(spdm_negotiate_algorithms_common_struct_table_t));
+    2111                 :          1 :     spdm_response = (void *)response;
+    2112                 :          1 :     assert_int_equal (spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+    2113                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_ALGORITHMS);
+    2114                 :          1 :     assert_int_equal(spdm_response->header.param1, 4);
+    2115                 :          1 :     assert_int_equal (spdm_response->struct_table[0].alg_supported,
+    2116                 :            :                       spdm_context->local_context.algorithm.dhe_named_group);
+    2117                 :          1 :     assert_int_equal (spdm_response->struct_table[1].alg_supported,
+    2118                 :            :                       spdm_context->local_context.algorithm.aead_cipher_suite);
+    2119                 :          1 :     assert_int_equal (spdm_response->struct_table[2].alg_supported,
+    2120                 :            :                       spdm_context->local_context.algorithm.req_base_asym_alg);
+    2121                 :          1 :     assert_int_equal (spdm_response->struct_table[3].alg_supported,
+    2122                 :            :                       spdm_context->local_context.algorithm.key_schedule);
+    2123                 :          1 : }
+    2124                 :            : 
+    2125                 :          1 : void libspdm_test_responder_algorithms_case23(void **state)
+    2126                 :            : {
+    2127                 :            :     libspdm_return_t status;
+    2128                 :            :     libspdm_test_context_t    *spdm_test_context;
+    2129                 :            :     libspdm_context_t  *spdm_context;
+    2130                 :            :     size_t response_size;
+    2131                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    2132                 :            :     spdm_algorithms_response_t *spdm_response;
+    2133                 :            : 
+    2134                 :          1 :     spdm_test_context = *state;
+    2135                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2136                 :          1 :     spdm_test_context->case_id = 0x17;
+    2137                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2138                 :            : 
+    2139                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    2140                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2141                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2142                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2143                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    2144                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    2145                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    2146                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    2147                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2148                 :          1 :     spdm_context->local_context.capability.flags = 0;
+    2149                 :          1 :     spdm_context->connection_info.capability.flags = 0;
+    2150                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    2151                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2152                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    2153                 :            : 
+    2154                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    2155                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2156                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    2157                 :            : 
+    2158                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    2159                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    2160                 :            : 
+    2161                 :          1 :     spdm_context->local_context.capability.flags |=
+    2162                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    2163                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2164                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    2165                 :            : 
+    2166                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    2167                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    2168                 :            : 
+    2169                 :            :     /* Sub Case 1: other_params_support set Illegal OpaqueDataFmt */
+    2170                 :          1 :     m_libspdm_negotiate_algorithm_request18.spdm_request_version10.other_params_support = 0x04;
+    2171                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2172                 :            : 
+    2173                 :          1 :     response_size = sizeof(response);
+    2174                 :          1 :     status = libspdm_get_response_algorithms (spdm_context,
+    2175                 :            :                                               m_libspdm_negotiate_algorithm_request18_size,
+    2176                 :            :                                               &m_libspdm_negotiate_algorithm_request18,
+    2177                 :            :                                               &response_size,
+    2178                 :            :                                               response);
+    2179                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+    2180                 :          1 :     assert_int_equal (response_size, sizeof(spdm_error_response_t));
+    2181                 :          1 :     spdm_response = (void *)response;
+    2182                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_ERROR);
+    2183                 :          1 :     assert_int_equal (spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+    2184                 :          1 :     assert_int_equal (spdm_response->header.param2, 0);
+    2185                 :            : 
+    2186                 :            :     /* Sub Case 2: other_params_support set OpaqueDataFmt1 */
+    2187                 :          1 :     m_libspdm_negotiate_algorithm_request18.spdm_request_version10.other_params_support =
+    2188                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
+    2189                 :          1 :     spdm_context->local_context.algorithm.other_params_support =
+    2190                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
+    2191                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2192                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2193                 :            : 
+    2194                 :          1 :     response_size = sizeof(response);
+    2195                 :          1 :     status = libspdm_get_response_algorithms (spdm_context,
+    2196                 :            :                                               m_libspdm_negotiate_algorithm_request18_size,
+    2197                 :            :                                               &m_libspdm_negotiate_algorithm_request18,
+    2198                 :            :                                               &response_size,
+    2199                 :            :                                               response);
+    2200                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2201                 :          1 :     assert_int_equal(response_size,
+    2202                 :            :                      sizeof(spdm_algorithms_response_t) + 4*
+    2203                 :            :                      sizeof(spdm_negotiate_algorithms_common_struct_table_t));
+    2204                 :          1 :     spdm_response = (void *)response;
+    2205                 :          1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+    2206                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ALGORITHMS);
+    2207                 :          1 :     assert_int_equal(spdm_response->other_params_selection, SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1);
+    2208                 :          1 :     assert_int_equal(spdm_context->connection_info.algorithm.other_params_support,
+    2209                 :            :                      SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1);
+    2210                 :            : 
+    2211                 :            :     /* Sub Case 3: Populate reserved field for version 1.2, field values marked as Reserved shall be written as zero ( 0 )*/
+    2212                 :          1 :     spdm_context->local_context.algorithm.other_params_support =
+    2213                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1 |
+    2214                 :            :         SPDM_ALGORITHMS_MULTI_KEY_CONN;
+    2215                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2216                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2217                 :          1 :     response_size = sizeof(response);
+    2218                 :          1 :     status = libspdm_get_response_algorithms (spdm_context,
+    2219                 :            :                                               m_libspdm_negotiate_algorithm_request18_size,
+    2220                 :            :                                               &m_libspdm_negotiate_algorithm_request18,
+    2221                 :            :                                               &response_size,
+    2222                 :            :                                               response);
+    2223                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2224                 :          1 :     assert_int_equal(response_size,
+    2225                 :            :                      sizeof(spdm_algorithms_response_t) + 4*
+    2226                 :            :                      sizeof(spdm_negotiate_algorithms_common_struct_table_t));
+    2227                 :          1 :     spdm_response = (void *)response;
+    2228                 :          1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+    2229                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ALGORITHMS);
+    2230                 :          1 :     assert_int_equal(spdm_response->other_params_selection, SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1);
+    2231                 :          1 :     assert_int_equal(spdm_context->connection_info.algorithm.other_params_support,
+    2232                 :            :                      SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1);
+    2233                 :            : 
+    2234                 :            :     /* Sub Case 4: OpaqueDataFmt. Supports both SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_0 and SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1*/
+    2235                 :          1 :     m_libspdm_negotiate_algorithm_request18.spdm_request_version10.other_params_support =
+    2236                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_0 |
+    2237                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
+    2238                 :          1 :     spdm_context->local_context.algorithm.other_params_support =
+    2239                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_0 |
+    2240                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
+    2241                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2242                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2243                 :          1 :     response_size = sizeof(response);
+    2244                 :          1 :     status = libspdm_get_response_algorithms (spdm_context,
+    2245                 :            :                                               m_libspdm_negotiate_algorithm_request18_size,
+    2246                 :            :                                               &m_libspdm_negotiate_algorithm_request18,
+    2247                 :            :                                               &response_size,
+    2248                 :            :                                               response);
+    2249                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2250                 :          1 :     assert_int_equal(response_size,
+    2251                 :            :                      sizeof(spdm_algorithms_response_t) + 4*
+    2252                 :            :                      sizeof(spdm_negotiate_algorithms_common_struct_table_t));
+    2253                 :          1 :     spdm_response = (void *)response;
+    2254                 :          1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+    2255                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ALGORITHMS);
+    2256                 :          1 :     assert_int_equal(spdm_response->other_params_selection, SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1);
+    2257                 :          1 :     assert_int_equal(spdm_context->connection_info.algorithm.other_params_support,
+    2258                 :            :                      SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1);
+    2259                 :          1 : }
+    2260                 :            : 
+    2261                 :          1 : void libspdm_test_responder_algorithms_case24(void **state)
+    2262                 :            : {
+    2263                 :            :     libspdm_return_t status;
+    2264                 :            :     libspdm_test_context_t    *spdm_test_context;
+    2265                 :            :     libspdm_context_t  *spdm_context;
+    2266                 :            :     size_t response_size;
+    2267                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    2268                 :            :     spdm_algorithms_response_t *spdm_response;
+    2269                 :            : 
+    2270                 :          1 :     spdm_test_context = *state;
+    2271                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2272                 :          1 :     spdm_test_context->case_id = 0x18;
+    2273                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2274                 :            : 
+    2275                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    2276                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2277                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2278                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2279                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    2280                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    2281                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    2282                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    2283                 :          1 :     spdm_context->local_context.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+    2284                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    2285                 :            :         m_libspdm_use_measurement_hash_algo;
+    2286                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2287                 :          1 :     spdm_context->local_context.capability.flags =
+    2288                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    2289                 :          1 :     spdm_context->connection_info.capability.flags = 0;
+    2290                 :            : 
+    2291                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    2292                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2293                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    2294                 :            : 
+    2295                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    2296                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2297                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    2298                 :            : 
+    2299                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    2300                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    2301                 :            : 
+    2302                 :          1 :     spdm_context->local_context.capability.flags |=
+    2303                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    2304                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2305                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    2306                 :            : 
+    2307                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    2308                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    2309                 :            : 
+    2310                 :          1 :     response_size = sizeof(response);
+    2311                 :          1 :     status = libspdm_get_response_algorithms (spdm_context,
+    2312                 :            :                                               m_libspdm_negotiate_algorithm_request24_size,
+    2313                 :            :                                               &m_libspdm_negotiate_algorithm_request24,
+    2314                 :            :                                               &response_size,
+    2315                 :            :                                               response);
+    2316                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+    2317                 :          1 :     assert_int_equal(response_size,
+    2318                 :            :                      sizeof(spdm_algorithms_response_t) +
+    2319                 :            :                      4*sizeof(spdm_negotiate_algorithms_common_struct_table_t));
+    2320                 :          1 :     spdm_response = (void *)response;
+    2321                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    2322                 :            :                      SPDM_ALGORITHMS);
+    2323                 :          1 :     assert_int_equal(spdm_response->measurement_hash_algo, 0);
+    2324                 :          1 :     assert_int_equal(spdm_response->measurement_specification_sel, 0);
+    2325                 :          1 : }
+    2326                 :            : 
+    2327                 :          1 : void libspdm_test_responder_algorithms_case25(void **state)
+    2328                 :            : {
+    2329                 :            :     libspdm_return_t status;
+    2330                 :            :     libspdm_test_context_t    *spdm_test_context;
+    2331                 :            :     libspdm_context_t  *spdm_context;
+    2332                 :            :     size_t response_size;
+    2333                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    2334                 :            :     spdm_algorithms_response_t *spdm_response;
+    2335                 :            : 
+    2336                 :          1 :     spdm_test_context = *state;
+    2337                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2338                 :          1 :     spdm_test_context->case_id = 0x19;
+    2339                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2340                 :            : 
+    2341                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    2342                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2343                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2344                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2345                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    2346                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    2347                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    2348                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    2349                 :          1 :     spdm_context->local_context.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+    2350                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    2351                 :            :         m_libspdm_use_measurement_hash_algo;
+    2352                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2353                 :          1 :     spdm_context->local_context.capability.flags =
+    2354                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    2355                 :          1 :     spdm_context->connection_info.capability.flags = 0;
+    2356                 :            : 
+    2357                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    2358                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2359                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    2360                 :            : 
+    2361                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    2362                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2363                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    2364                 :            : 
+    2365                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    2366                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    2367                 :            : 
+    2368                 :          1 :     spdm_context->local_context.capability.flags |=
+    2369                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    2370                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2371                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    2372                 :            : 
+    2373                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    2374                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    2375                 :            : 
+    2376                 :          1 :     response_size = sizeof(response);
+    2377                 :          1 :     status = libspdm_get_response_algorithms (spdm_context,
+    2378                 :            :                                               m_libspdm_negotiate_algorithm_request25_size,
+    2379                 :            :                                               &m_libspdm_negotiate_algorithm_request25,
+    2380                 :            :                                               &response_size,
+    2381                 :            :                                               response);
+    2382                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+    2383                 :          1 :     assert_int_equal (response_size, sizeof(spdm_error_response_t));
+    2384                 :          1 :     spdm_response = (void *)response;
+    2385                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_ERROR);
+    2386                 :          1 :     assert_int_equal (spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+    2387                 :          1 :     assert_int_equal (spdm_response->header.param2, 0);
+    2388                 :          1 : }
+    2389                 :            : 
+    2390                 :          1 : void libspdm_test_responder_algorithms_case26(void **state)
+    2391                 :            : {
+    2392                 :            :     libspdm_return_t status;
+    2393                 :            :     libspdm_test_context_t    *spdm_test_context;
+    2394                 :            :     libspdm_context_t  *spdm_context;
+    2395                 :            :     size_t response_size;
+    2396                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    2397                 :            :     spdm_algorithms_response_t *spdm_response;
+    2398                 :            : 
+    2399                 :          1 :     spdm_test_context = *state;
+    2400                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2401                 :          1 :     spdm_test_context->case_id = 0x1A;
+    2402                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2403                 :            : 
+    2404                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    2405                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2406                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2407                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2408                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    2409                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    2410                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    2411                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    2412                 :          1 :     spdm_context->local_context.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+    2413                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    2414                 :            :         m_libspdm_use_measurement_hash_algo;
+    2415                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2416                 :          1 :     spdm_context->local_context.capability.flags =
+    2417                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    2418                 :          1 :     spdm_context->connection_info.capability.flags = 0;
+    2419                 :            : 
+    2420                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    2421                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2422                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    2423                 :            : 
+    2424                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    2425                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2426                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    2427                 :            : 
+    2428                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    2429                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    2430                 :            : 
+    2431                 :          1 :     spdm_context->local_context.capability.flags |=
+    2432                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    2433                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2434                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    2435                 :            : 
+    2436                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    2437                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    2438                 :            : 
+    2439                 :          1 :     response_size = sizeof(response);
+    2440                 :          1 :     status = libspdm_get_response_algorithms (spdm_context,
+    2441                 :            :                                               m_libspdm_negotiate_algorithm_request26_size,
+    2442                 :            :                                               &m_libspdm_negotiate_algorithm_request26,
+    2443                 :            :                                               &response_size,
+    2444                 :            :                                               response);
+    2445                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+    2446                 :          1 :     assert_int_equal (response_size, sizeof(spdm_error_response_t));
+    2447                 :          1 :     spdm_response = (void *)response;
+    2448                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_ERROR);
+    2449                 :          1 :     assert_int_equal (spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+    2450                 :          1 :     assert_int_equal (spdm_response->header.param2, 0);
+    2451                 :          1 : }
+    2452                 :            : 
+    2453                 :          1 : void libspdm_test_responder_algorithms_case27(void **state)
+    2454                 :            : {
+    2455                 :            :     libspdm_return_t status;
+    2456                 :            :     libspdm_test_context_t    *spdm_test_context;
+    2457                 :            :     libspdm_context_t  *spdm_context;
+    2458                 :            :     size_t response_size;
+    2459                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    2460                 :            :     spdm_algorithms_response_t *spdm_response;
+    2461                 :            : 
+    2462                 :          1 :     spdm_test_context = *state;
+    2463                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2464                 :          1 :     spdm_test_context->case_id = 0x1B;
+    2465                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2466                 :            : 
+    2467                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    2468                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2469                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2470                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2471                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    2472                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    2473                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    2474                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    2475                 :          1 :     spdm_context->local_context.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+    2476                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    2477                 :            :         m_libspdm_use_measurement_hash_algo;
+    2478                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2479                 :          1 :     spdm_context->local_context.capability.flags =
+    2480                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    2481                 :          1 :     spdm_context->connection_info.capability.flags = 0;
+    2482                 :            : 
+    2483                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    2484                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2485                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    2486                 :            : 
+    2487                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    2488                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2489                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    2490                 :            : 
+    2491                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    2492                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    2493                 :            : 
+    2494                 :          1 :     spdm_context->local_context.capability.flags |=
+    2495                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    2496                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2497                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    2498                 :            : 
+    2499                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    2500                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    2501                 :            : 
+    2502                 :          1 :     response_size = sizeof(response);
+    2503                 :          1 :     status = libspdm_get_response_algorithms (spdm_context,
+    2504                 :            :                                               m_libspdm_negotiate_algorithm_request27_size,
+    2505                 :            :                                               &m_libspdm_negotiate_algorithm_request27,
+    2506                 :            :                                               &response_size,
+    2507                 :            :                                               response);
+    2508                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+    2509                 :          1 :     assert_int_equal (response_size, sizeof(spdm_error_response_t));
+    2510                 :          1 :     spdm_response = (void *)response;
+    2511                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_ERROR);
+    2512                 :          1 :     assert_int_equal (spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+    2513                 :          1 :     assert_int_equal (spdm_response->header.param2, 0);
+    2514                 :          1 : }
+    2515                 :            : 
+    2516                 :          1 : void libspdm_test_responder_algorithms_case28(void **state)
+    2517                 :            : {
+    2518                 :            :     libspdm_return_t status;
+    2519                 :            :     libspdm_test_context_t    *spdm_test_context;
+    2520                 :            :     libspdm_context_t  *spdm_context;
+    2521                 :            :     size_t response_size;
+    2522                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    2523                 :            :     spdm_algorithms_response_t *spdm_response;
+    2524                 :            : 
+    2525                 :          1 :     spdm_test_context = *state;
+    2526                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2527                 :          1 :     spdm_test_context->case_id = 0x1C;
+    2528                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2529                 :            : 
+    2530                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    2531                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2532                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2533                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2534                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    2535                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    2536                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    2537                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    2538                 :          1 :     spdm_context->local_context.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+    2539                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    2540                 :            :         m_libspdm_use_measurement_hash_algo;
+    2541                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2542                 :          1 :     spdm_context->local_context.capability.flags =
+    2543                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    2544                 :          1 :     spdm_context->connection_info.capability.flags = 0;
+    2545                 :            : 
+    2546                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    2547                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2548                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    2549                 :            : 
+    2550                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+    2551                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2552                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+    2553                 :            : 
+    2554                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+    2555                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+    2556                 :            : 
+    2557                 :          1 :     spdm_context->local_context.capability.flags |=
+    2558                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+    2559                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2560                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+    2561                 :            : 
+    2562                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    2563                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    2564                 :            : 
+    2565                 :          1 :     response_size = sizeof(response);
+    2566                 :          1 :     status = libspdm_get_response_algorithms (spdm_context,
+    2567                 :            :                                               m_libspdm_negotiate_algorithm_request28_size,
+    2568                 :            :                                               &m_libspdm_negotiate_algorithm_request28,
+    2569                 :            :                                               &response_size,
+    2570                 :            :                                               response);
+    2571                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+    2572                 :          1 :     assert_int_equal (response_size, sizeof(spdm_error_response_t));
+    2573                 :          1 :     spdm_response = (void *)response;
+    2574                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_ERROR);
+    2575                 :          1 :     assert_int_equal (spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+    2576                 :          1 :     assert_int_equal (spdm_response->header.param2, 0);
+    2577                 :          1 : }
+    2578                 :            : 
+    2579                 :          1 : void libspdm_test_responder_algorithms_case29(void **state)
+    2580                 :            : {
+    2581                 :            :     libspdm_return_t status;
+    2582                 :            :     libspdm_test_context_t    *spdm_test_context;
+    2583                 :            :     libspdm_context_t  *spdm_context;
+    2584                 :            :     size_t response_size;
+    2585                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    2586                 :            :     spdm_algorithms_response_t *spdm_response;
+    2587                 :            : 
+    2588                 :          1 :     spdm_test_context = *state;
+    2589                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2590                 :          1 :     spdm_test_context->case_id = 0x1C;
+    2591                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2592                 :            : 
+    2593                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    2594                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2595                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2596                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2597                 :          1 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    2598                 :          1 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    2599                 :          1 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+    2600                 :          1 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+    2601                 :          1 :     spdm_context->local_context.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+    2602                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    2603                 :            :         m_libspdm_use_measurement_hash_algo;
+    2604                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2605                 :            : 
+    2606                 :          1 :     response_size = sizeof(response);
+    2607                 :          1 :     status = libspdm_get_response_algorithms (spdm_context,
+    2608                 :            :                                               m_libspdm_negotiate_algorithm_request29_size,
+    2609                 :            :                                               &m_libspdm_negotiate_algorithm_request29,
+    2610                 :            :                                               &response_size,
+    2611                 :            :                                               response);
+    2612                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+    2613                 :          1 :     assert_int_equal (response_size, sizeof(spdm_error_response_t));
+    2614                 :          1 :     spdm_response = (void *)response;
+    2615                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_ERROR);
+    2616                 :          1 :     assert_int_equal (spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+    2617                 :          1 :     assert_int_equal (spdm_response->header.param2, 0);
+    2618                 :          1 : }
+    2619                 :            : 
+    2620                 :            : /**
+    2621                 :            :  * Test 30: MULTI_KEY_CONN_REQ and MULTI_KEY_CONN_RSP value calculation
+    2622                 :            :  * +---------------+--------------------------+--------------------+
+    2623                 :            :  * | MULTI_KEY_CAP | RequesterMultiKeyConnSel | MULTI_KEY_CONN_REQ |
+    2624                 :            :  * +---------------+--------------------------+--------------------+
+    2625                 :            :  * | 00b           | 0                        | false              |
+    2626                 :            :  *  ----------------------------------------------------------------
+    2627                 :            :  * | 00b           | 1                        | invalid            |
+    2628                 :            :  *  ----------------------------------------------------------------
+    2629                 :            :  * | 01b           | 0                        | invalid            |
+    2630                 :            :  *  ----------------------------------------------------------------
+    2631                 :            :  * | 01b           | 1                        | true               |
+    2632                 :            :  *  ----------------------------------------------------------------
+    2633                 :            :  * | 10b           | 0                        | false              |
+    2634                 :            :  *  ----------------------------------------------------------------
+    2635                 :            :  * | 10b           | 1                        | true               |
+    2636                 :            :  * +---------------+--------------------------+--------------------+
+    2637                 :            :  * | MULTI_KEY_CAP | ResponderMultiKeyConn    | MULTI_KEY_CONN_RSP |
+    2638                 :            :  * +---------------+--------------------------+--------------------+
+    2639                 :            :  * | 00b           | 0                        | false              |
+    2640                 :            :  *  ----------------------------------------------------------------
+    2641                 :            :  * | 00b           | 1                        | invalid            |
+    2642                 :            :  *  ----------------------------------------------------------------
+    2643                 :            :  * | 01b           | 0                        | invalid            |
+    2644                 :            :  *  ----------------------------------------------------------------
+    2645                 :            :  * | 01b           | 1                        | true               |
+    2646                 :            :  *  ----------------------------------------------------------------
+    2647                 :            :  * | 10b           | 0                        | false              |
+    2648                 :            :  *  ----------------------------------------------------------------
+    2649                 :            :  * | 10b           | 1                        | true               |
+    2650                 :            :  *  ----------------------------------------------------------------
+    2651                 :            :  **/
+    2652                 :          1 : void libspdm_test_responder_algorithms_case30(void **state)
+    2653                 :            : {
+    2654                 :            :     libspdm_return_t status;
+    2655                 :            :     libspdm_test_context_t *spdm_test_context;
+    2656                 :            :     libspdm_context_t *spdm_context;
+    2657                 :            :     size_t response_size;
+    2658                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    2659                 :            :     spdm_algorithms_response_t *spdm_response;
+    2660                 :            : 
+    2661                 :          1 :     spdm_test_context = *state;
+    2662                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2663                 :          1 :     spdm_test_context->case_id = 0x1D;
+    2664                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+    2665                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2666                 :            : 
+    2667                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2668                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2669                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo = 0;
+    2670                 :          1 :     spdm_context->local_context.algorithm.measurement_spec = 0;
+    2671                 :          1 :     spdm_context->local_context.capability.flags = 0;
+    2672                 :            : 
+    2673                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2674                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2675                 :            : 
+    2676                 :          1 :     spdm_context->local_context.capability.flags = 0;
+    2677                 :          1 :     spdm_context->local_context.algorithm.other_params_support = 0;
+    2678                 :          1 :     spdm_context->connection_info.capability.flags = 0;
+    2679                 :          1 :     m_libspdm_negotiate_algorithms_request30.other_params_support = 0;
+    2680                 :            : 
+    2681                 :          1 :     response_size = sizeof(response);
+    2682                 :          1 :     status = libspdm_get_response_algorithms(
+    2683                 :            :         spdm_context, m_libspdm_negotiate_algorithms_request30_size,
+    2684                 :            :         &m_libspdm_negotiate_algorithms_request30, &response_size,
+    2685                 :            :         response);
+    2686                 :            : 
+    2687                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2688                 :          1 :     assert_int_equal(response_size, sizeof(spdm_algorithms_response_t));
+    2689                 :          1 :     spdm_response = (void *)response;
+    2690                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    2691                 :            :                      SPDM_ALGORITHMS);
+    2692                 :          1 :     assert_int_equal(spdm_context->connection_info.multi_key_conn_rsp, false);
+    2693                 :          1 :     assert_int_equal(spdm_context->connection_info.multi_key_conn_req, false);
+    2694                 :            : 
+    2695                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2696                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2697                 :            : 
+    2698                 :          1 :     spdm_context->local_context.capability.flags = 0;
+    2699                 :          1 :     spdm_context->local_context.algorithm.other_params_support = SPDM_ALGORITHMS_MULTI_KEY_CONN;
+    2700                 :          1 :     spdm_context->connection_info.capability.flags = 0;
+    2701                 :          1 :     m_libspdm_negotiate_algorithms_request30.other_params_support = SPDM_ALGORITHMS_MULTI_KEY_CONN;
+    2702                 :            : 
+    2703                 :          1 :     response_size = sizeof(response);
+    2704                 :          1 :     status = libspdm_get_response_algorithms(
+    2705                 :            :         spdm_context, m_libspdm_negotiate_algorithms_request30_size,
+    2706                 :            :         &m_libspdm_negotiate_algorithms_request30, &response_size,
+    2707                 :            :         response);
+    2708                 :            :     /* MULTI_KEY_CONN_REQ and MULTI_KEY_CONN_RSP invalid */
+    2709                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2710                 :          1 :     assert_int_equal (response_size, sizeof(spdm_error_response_t));
+    2711                 :          1 :     spdm_response = (void *)response;
+    2712                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    2713                 :            :                      SPDM_ERROR);
+    2714                 :            : 
+    2715                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2716                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2717                 :            : 
+    2718                 :          1 :     spdm_context->local_context.capability.flags =
+    2719                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MULTI_KEY_CAP_ONLY;
+    2720                 :          1 :     spdm_context->local_context.algorithm.other_params_support = 0;
+    2721                 :          1 :     spdm_context->connection_info.capability.flags =
+    2722                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MULTI_KEY_CAP_ONLY;
+    2723                 :          1 :     m_libspdm_negotiate_algorithms_request30.other_params_support = 0;
+    2724                 :            : 
+    2725                 :          1 :     response_size = sizeof(response);
+    2726                 :          1 :     status = libspdm_get_response_algorithms(
+    2727                 :            :         spdm_context, m_libspdm_negotiate_algorithms_request30_size,
+    2728                 :            :         &m_libspdm_negotiate_algorithms_request30, &response_size,
+    2729                 :            :         response);
+    2730                 :            :     /* MULTI_KEY_CONN_REQ and MULTI_KEY_CONN_RSP invalid */
+    2731                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2732                 :          1 :     assert_int_equal (response_size, sizeof(spdm_error_response_t));
+    2733                 :          1 :     spdm_response = (void *)response;
+    2734                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    2735                 :            :                      SPDM_ERROR);
+    2736                 :            : 
+    2737                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2738                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2739                 :            : 
+    2740                 :          1 :     spdm_context->local_context.capability.flags =
+    2741                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MULTI_KEY_CAP_ONLY;
+    2742                 :          1 :     spdm_context->local_context.algorithm.other_params_support = SPDM_ALGORITHMS_MULTI_KEY_CONN;
+    2743                 :          1 :     spdm_context->connection_info.capability.flags =
+    2744                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MULTI_KEY_CAP_ONLY;
+    2745                 :          1 :     m_libspdm_negotiate_algorithms_request30.other_params_support = SPDM_ALGORITHMS_MULTI_KEY_CONN;
+    2746                 :            : 
+    2747                 :          1 :     response_size = sizeof(response);
+    2748                 :          1 :     status = libspdm_get_response_algorithms(
+    2749                 :            :         spdm_context, m_libspdm_negotiate_algorithms_request30_size,
+    2750                 :            :         &m_libspdm_negotiate_algorithms_request30, &response_size,
+    2751                 :            :         response);
+    2752                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2753                 :          1 :     assert_int_equal(response_size, sizeof(spdm_algorithms_response_t));
+    2754                 :          1 :     spdm_response = (void *)response;
+    2755                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    2756                 :            :                      SPDM_ALGORITHMS);
+    2757                 :          1 :     assert_int_equal(spdm_context->connection_info.multi_key_conn_rsp, true);
+    2758                 :          1 :     assert_int_equal(spdm_context->connection_info.multi_key_conn_req, true);
+    2759                 :            : 
+    2760                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2761                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2762                 :            : 
+    2763                 :          1 :     spdm_context->local_context.capability.flags =
+    2764                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MULTI_KEY_CAP_NEG;
+    2765                 :          1 :     spdm_context->local_context.algorithm.other_params_support = 0;
+    2766                 :          1 :     spdm_context->connection_info.capability.flags =
+    2767                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MULTI_KEY_CAP_NEG;
+    2768                 :          1 :     m_libspdm_negotiate_algorithms_request30.other_params_support = 0;
+    2769                 :            : 
+    2770                 :          1 :     response_size = sizeof(response);
+    2771                 :          1 :     status = libspdm_get_response_algorithms(
+    2772                 :            :         spdm_context, m_libspdm_negotiate_algorithms_request30_size,
+    2773                 :            :         &m_libspdm_negotiate_algorithms_request30, &response_size,
+    2774                 :            :         response);
+    2775                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2776                 :          1 :     assert_int_equal(response_size, sizeof(spdm_algorithms_response_t));
+    2777                 :          1 :     spdm_response = (void *)response;
+    2778                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    2779                 :            :                      SPDM_ALGORITHMS);
+    2780                 :          1 :     assert_int_equal(spdm_context->connection_info.multi_key_conn_rsp, false);
+    2781                 :          1 :     assert_int_equal(spdm_context->connection_info.multi_key_conn_req, false);
+    2782                 :            : 
+    2783                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2784                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2785                 :            : 
+    2786                 :          1 :     spdm_context->local_context.capability.flags =
+    2787                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MULTI_KEY_CAP_NEG;
+    2788                 :          1 :     spdm_context->local_context.algorithm.other_params_support = SPDM_ALGORITHMS_MULTI_KEY_CONN;
+    2789                 :          1 :     spdm_context->connection_info.capability.flags =
+    2790                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MULTI_KEY_CAP_NEG;
+    2791                 :          1 :     m_libspdm_negotiate_algorithms_request30.other_params_support = SPDM_ALGORITHMS_MULTI_KEY_CONN;
+    2792                 :            : 
+    2793                 :          1 :     response_size = sizeof(response);
+    2794                 :          1 :     status = libspdm_get_response_algorithms(
+    2795                 :            :         spdm_context, m_libspdm_negotiate_algorithms_request30_size,
+    2796                 :            :         &m_libspdm_negotiate_algorithms_request30, &response_size,
+    2797                 :            :         response);
+    2798                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2799                 :          1 :     assert_int_equal(response_size, sizeof(spdm_algorithms_response_t));
+    2800                 :          1 :     spdm_response = (void *)response;
+    2801                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    2802                 :            :                      SPDM_ALGORITHMS);
+    2803                 :          1 :     assert_int_equal(spdm_context->connection_info.multi_key_conn_rsp, true);
+    2804                 :          1 :     assert_int_equal(spdm_context->connection_info.multi_key_conn_req, true);
+    2805                 :          1 : }
+    2806                 :            : 
+    2807                 :            : 
+    2808                 :            : /**
+    2809                 :            :  * Test 31: NEGOTIATE_ALGORITHMS message received with MEL correct
+    2810                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code
+    2811                 :            :  **/
+    2812                 :          1 : void libspdm_test_responder_algorithms_case31(void **state)
+    2813                 :            : {
+    2814                 :            :     libspdm_return_t status;
+    2815                 :            :     libspdm_test_context_t *spdm_test_context;
+    2816                 :            :     libspdm_context_t *spdm_context;
+    2817                 :            :     size_t response_size;
+    2818                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    2819                 :            :     spdm_algorithms_response_t *spdm_response;
+    2820                 :            : 
+    2821                 :          1 :     spdm_test_context = *state;
+    2822                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2823                 :          1 :     spdm_test_context->case_id = 0x1E;
+    2824                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+    2825                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2826                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2827                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2828                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2829                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo = 0;
+    2830                 :          1 :     spdm_context->local_context.algorithm.measurement_spec = 0;
+    2831                 :          1 :     spdm_context->local_context.capability.flags = 0;
+    2832                 :          1 :     spdm_context->local_context.algorithm.other_params_support = 0;
+    2833                 :          1 :     spdm_context->local_context.algorithm.mel_spec = SPDM_MEL_SPECIFICATION_DMTF;
+    2834                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2835                 :            : 
+    2836                 :            :     /* Sub Case 1: MEL_CAP set 1, mel_specification set SPDM_MEL_SPECIFICATION_DMTF*/
+    2837                 :          1 :     m_libspdm_negotiate_algorithms_request30.other_params_support = 0;
+    2838                 :          1 :     m_libspdm_negotiate_algorithms_request30.mel_specification = SPDM_MEL_SPECIFICATION_DMTF;
+    2839                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEL_CAP;
+    2840                 :            : 
+    2841                 :          1 :     response_size = sizeof(response);
+    2842                 :          1 :     status = libspdm_get_response_algorithms(
+    2843                 :            :         spdm_context, m_libspdm_negotiate_algorithms_request30_size,
+    2844                 :            :         &m_libspdm_negotiate_algorithms_request30, &response_size,
+    2845                 :            :         response);
+    2846                 :            : 
+    2847                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2848                 :          1 :     assert_int_equal(response_size, sizeof(spdm_algorithms_response_t));
+    2849                 :          1 :     spdm_response = (void *)response;
+    2850                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    2851                 :            :                      SPDM_ALGORITHMS);
+    2852                 :          1 :     assert_int_equal(spdm_response->mel_specification_sel, SPDM_MEL_SPECIFICATION_DMTF);
+    2853                 :          1 :     assert_int_equal(spdm_context->connection_info.algorithm.mel_spec, SPDM_MEL_SPECIFICATION_DMTF);
+    2854                 :            : 
+    2855                 :            :     /* Sub Case 2: MEL_CAP set 0, mel_specification set SPDM_MEL_SPECIFICATION_DMTF*/
+    2856                 :          1 :     m_libspdm_negotiate_algorithms_request30.mel_specification = SPDM_MEL_SPECIFICATION_DMTF;
+    2857                 :          1 :     spdm_context->local_context.capability.flags = 0;
+    2858                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2859                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2860                 :            : 
+    2861                 :          1 :     response_size = sizeof(response);
+    2862                 :          1 :     status = libspdm_get_response_algorithms(
+    2863                 :            :         spdm_context, m_libspdm_negotiate_algorithms_request30_size,
+    2864                 :            :         &m_libspdm_negotiate_algorithms_request30, &response_size,
+    2865                 :            :         response);
+    2866                 :            : 
+    2867                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2868                 :          1 :     assert_int_equal(response_size, sizeof(spdm_algorithms_response_t));
+    2869                 :          1 :     spdm_response = (void *)response;
+    2870                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    2871                 :            :                      SPDM_ALGORITHMS);
+    2872                 :          1 :     assert_int_equal(spdm_response->mel_specification_sel, 0);
+    2873                 :          1 :     assert_int_equal(spdm_context->connection_info.algorithm.mel_spec, 0);
+    2874                 :          1 : }
+    2875                 :            : 
+    2876                 :            : /**
+    2877                 :            :  * Test 32: NEGOTIATE_ALGORITHMS message received with MEAS correct
+    2878                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code
+    2879                 :            :  **/
+    2880                 :          1 : void libspdm_test_responder_algorithms_case32(void **state)
+    2881                 :            : {
+    2882                 :            :     libspdm_return_t status;
+    2883                 :            :     libspdm_test_context_t *spdm_test_context;
+    2884                 :            :     libspdm_context_t *spdm_context;
+    2885                 :            :     size_t response_size;
+    2886                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    2887                 :            :     spdm_algorithms_response_t *spdm_response;
+    2888                 :            : 
+    2889                 :          1 :     spdm_test_context = *state;
+    2890                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2891                 :          1 :     spdm_test_context->case_id = 0x1F;
+    2892                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    2893                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2894                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2895                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    2896                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    2897                 :          1 :     spdm_context->local_context.algorithm.measurement_spec = 0;
+    2898                 :          1 :     spdm_context->local_context.algorithm.measurement_spec |= SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    2899                 :          1 :     spdm_context->local_context.capability.flags = 0;
+    2900                 :          1 :     spdm_context->local_context.algorithm.other_params_support = 0;
+    2901                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2902                 :            : 
+    2903                 :            :     /* Sub Case 1: MEL_CAP set 1, measurement_spec set SPDM_MEASUREMENT_SPECIFICATION_DMTF*/
+    2904                 :          1 :     spdm_context->local_context.capability.flags |=
+    2905                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    2906                 :          1 :     spdm_context->local_context.algorithm.measurement_spec |= SPDM_MEASUREMENT_SPECIFICATION_DMTF;
+    2907                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo =
+    2908                 :            :         m_libspdm_use_measurement_hash_algo;
+    2909                 :            : 
+    2910                 :          1 :     response_size = sizeof(response);
+    2911                 :          1 :     status = libspdm_get_response_algorithms(
+    2912                 :            :         spdm_context, m_libspdm_negotiate_algorithms_request1_size,
+    2913                 :            :         &m_libspdm_negotiate_algorithms_request1, &response_size,
+    2914                 :            :         response);
+    2915                 :            : 
+    2916                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2917                 :          1 :     assert_int_equal(response_size, sizeof(spdm_algorithms_response_t));
+    2918                 :          1 :     spdm_response = (void *)response;
+    2919                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    2920                 :            :                      SPDM_ALGORITHMS);
+    2921                 :          1 :     assert_int_equal(spdm_response->measurement_specification_sel,
+    2922                 :            :                      SPDM_MEASUREMENT_SPECIFICATION_DMTF);
+    2923                 :          1 :     assert_int_equal(spdm_context->connection_info.algorithm.measurement_spec,
+    2924                 :            :                      SPDM_MEASUREMENT_SPECIFICATION_DMTF);
+    2925                 :            : 
+    2926                 :            :     /* Sub Case 2: MEL_CAP set 0, measurement_spec set 0*/
+    2927                 :          1 :     spdm_context->local_context.capability.flags = 0;
+    2928                 :          1 :     spdm_context->local_context.algorithm.measurement_hash_algo = 0;
+    2929                 :          1 :     spdm_context->local_context.algorithm.measurement_spec = 0;
+    2930                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+    2931                 :          1 :     m_libspdm_negotiate_algorithms_request1.measurement_specification = 0;
+    2932                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2933                 :            : 
+    2934                 :          1 :     response_size = sizeof(response);
+    2935                 :          1 :     status = libspdm_get_response_algorithms(
+    2936                 :            :         spdm_context, m_libspdm_negotiate_algorithms_request1_size,
+    2937                 :            :         &m_libspdm_negotiate_algorithms_request1, &response_size,
+    2938                 :            :         response);
+    2939                 :            : 
+    2940                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2941                 :          1 :     assert_int_equal(response_size, sizeof(spdm_algorithms_response_t));
+    2942                 :          1 :     spdm_response = (void *)response;
+    2943                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    2944                 :            :                      SPDM_ALGORITHMS);
+    2945                 :          1 :     assert_int_equal(spdm_response->measurement_specification_sel, 0);
+    2946                 :          1 :     assert_int_equal(spdm_context->connection_info.algorithm.measurement_spec, 0);
+    2947                 :          1 : }
+    2948                 :            : 
+    2949                 :            : libspdm_test_context_t m_libspdm_responder_algorithms_test_context = {
+    2950                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+    2951                 :            :     false,
+    2952                 :            : };
+    2953                 :            : 
+    2954                 :          1 : int libspdm_responder_algorithms_test_main(void)
+    2955                 :            : {
+    2956                 :          1 :     const struct CMUnitTest spdm_responder_algorithms_tests[] = {
+    2957                 :            :         /* Success Case*/
+    2958                 :            :         cmocka_unit_test(libspdm_test_responder_algorithms_case1),
+    2959                 :            :         /* Bad request size*/
+    2960                 :            :         cmocka_unit_test(libspdm_test_responder_algorithms_case2),
+    2961                 :            :         /* response_state: LIBSPDM_RESPONSE_STATE_BUSY*/
+    2962                 :            :         cmocka_unit_test(libspdm_test_responder_algorithms_case3),
+    2963                 :            :         /* response_state: LIBSPDM_RESPONSE_STATE_NEED_RESYNC*/
+    2964                 :            :         cmocka_unit_test(libspdm_test_responder_algorithms_case4),
+    2965                 :            :         /* connection_state Check*/
+    2966                 :            :         cmocka_unit_test(libspdm_test_responder_algorithms_case6),
+    2967                 :            :         /* Success case V1.1*/
+    2968                 :            :         cmocka_unit_test(libspdm_test_responder_algorithms_case7),
+    2969                 :            :         /* No match for base_asym_algo*/
+    2970                 :            :         cmocka_unit_test(libspdm_test_responder_algorithms_case8),
+    2971                 :            :         /* No match for base_hash_algo*/
+    2972                 :            :         cmocka_unit_test(libspdm_test_responder_algorithms_case9),
+    2973                 :            :         /* No match for dhe_named_group*/
+    2974                 :            :         cmocka_unit_test(libspdm_test_responder_algorithms_case10),
+    2975                 :            :         /* No match for aead_cipher_suite*/
+    2976                 :            :         cmocka_unit_test(libspdm_test_responder_algorithms_case11),
+    2977                 :            :         /* No match for req_base_asym_alg*/
+    2978                 :            :         cmocka_unit_test(libspdm_test_responder_algorithms_case12),
+    2979                 :            :         /* No match for key_schedule*/
+    2980                 :            :         cmocka_unit_test(libspdm_test_responder_algorithms_case13),
+    2981                 :            :         /* Spdm length greater than 64 bytes for V1.0*/
+    2982                 :            :         cmocka_unit_test(libspdm_test_responder_algorithms_case14),
+    2983                 :            :         /* Spdm length greater than 128 bytes for V1.1*/
+    2984                 :            :         cmocka_unit_test(libspdm_test_responder_algorithms_case15),
+    2985                 :            :         /* Multiple repeated Alg structs for V1.1*/
+    2986                 :            :         cmocka_unit_test(libspdm_test_responder_algorithms_case16),
+    2987                 :            :         /* param1 is smaller than the number of Alg structs for V1.1*/
+    2988                 :            :         cmocka_unit_test(libspdm_test_responder_algorithms_case17),
+    2989                 :            :         /* param1 is bigger than the number of  Alg structs for V1.1*/
+    2990                 :            :         cmocka_unit_test(libspdm_test_responder_algorithms_case18),
+    2991                 :            :         /* Invalid  Alg structs + valid Alg Structs for V1.1*/
+    2992                 :            :         cmocka_unit_test(libspdm_test_responder_algorithms_case19),
+    2993                 :            :         /* When support multiple algorithms, then defaults to choose the strongest available algorithm*/
+    2994                 :            :         cmocka_unit_test(libspdm_test_responder_algorithms_case20),
+    2995                 :            :         /* Buffer verification*/
+    2996                 :            :         cmocka_unit_test(libspdm_test_responder_algorithms_case21),
+    2997                 :            :         /* Success case V1.2*/
+    2998                 :            :         cmocka_unit_test(libspdm_test_responder_algorithms_case22),
+    2999                 :            :         /* Version 1.2 Check other_params_support */
+    3000                 :            :         cmocka_unit_test(libspdm_test_responder_algorithms_case23),
+    3001                 :            :         /* No support for MEASUREMENT from requester*/
+    3002                 :            :         cmocka_unit_test(libspdm_test_responder_algorithms_case24),
+    3003                 :            :         /* Invalid (Redundant) alg_type value*/
+    3004                 :            :         cmocka_unit_test(libspdm_test_responder_algorithms_case25),
+    3005                 :            :         /* Invalid (Decreasing) alg_type value*/
+    3006                 :            :         cmocka_unit_test(libspdm_test_responder_algorithms_case26),
+    3007                 :            :         /* Invalid (smaller than DHE) alg_type value*/
+    3008                 :            :         cmocka_unit_test(libspdm_test_responder_algorithms_case27),
+    3009                 :            :         /* Invalid (bigger than KEY_SCHEDULE) alg_type value*/
+    3010                 :            :         cmocka_unit_test(libspdm_test_responder_algorithms_case28),
+    3011                 :            :         /* Invalid AlgStruct, contains an AlgSupported=0 (Non-supported)*/
+    3012                 :            :         cmocka_unit_test(libspdm_test_responder_algorithms_case29),
+    3013                 :            :         /* MULTI_KEY_CONN_REQ and MULTI_KEY_CONN_RSP value validation*/
+    3014                 :            :         cmocka_unit_test(libspdm_test_responder_algorithms_case30),
+    3015                 :            :         /* Success Case , set MELspecificationSel*/
+    3016                 :            :         cmocka_unit_test(libspdm_test_responder_algorithms_case31),
+    3017                 :            :         /* Success Case , set MeasurementSpecification*/
+    3018                 :            :         cmocka_unit_test(libspdm_test_responder_algorithms_case32),
+    3019                 :            :     };
+    3020                 :            : 
+    3021                 :          1 :     m_libspdm_negotiate_algorithms_request1.base_asym_algo = m_libspdm_use_asym_algo;
+    3022                 :          1 :     m_libspdm_negotiate_algorithms_request1.base_hash_algo = m_libspdm_use_hash_algo;
+    3023                 :          1 :     m_libspdm_negotiate_algorithms_request2.base_asym_algo = m_libspdm_use_asym_algo;
+    3024                 :          1 :     m_libspdm_negotiate_algorithms_request2.base_hash_algo = m_libspdm_use_hash_algo;
+    3025                 :          1 :     m_libspdm_negotiate_algorithm_request3.spdm_request_version10.base_asym_algo =
+    3026                 :            :         m_libspdm_use_asym_algo;
+    3027                 :          1 :     m_libspdm_negotiate_algorithm_request3.spdm_request_version10.base_hash_algo =
+    3028                 :            :         m_libspdm_use_hash_algo;
+    3029                 :          1 :     m_libspdm_negotiate_algorithm_request4.spdm_request_version10.base_asym_algo =
+    3030                 :          1 :         (m_libspdm_use_asym_algo >> 1);
+    3031                 :          1 :     m_libspdm_negotiate_algorithm_request4.spdm_request_version10.base_hash_algo =
+    3032                 :            :         m_libspdm_use_hash_algo;
+    3033                 :          1 :     m_libspdm_negotiate_algorithm_request5.spdm_request_version10.base_asym_algo =
+    3034                 :            :         m_libspdm_use_asym_algo;
+    3035                 :          1 :     m_libspdm_negotiate_algorithm_request5.spdm_request_version10.base_hash_algo =
+    3036                 :            :         SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_512;
+    3037                 :          1 :     m_libspdm_negotiate_algorithm_request6.spdm_request_version10.base_asym_algo =
+    3038                 :            :         m_libspdm_use_asym_algo;
+    3039                 :          1 :     m_libspdm_negotiate_algorithm_request6.spdm_request_version10.base_hash_algo =
+    3040                 :            :         m_libspdm_use_hash_algo;
+    3041                 :          1 :     m_libspdm_negotiate_algorithm_request7.spdm_request_version10.base_asym_algo =
+    3042                 :            :         m_libspdm_use_asym_algo;
+    3043                 :          1 :     m_libspdm_negotiate_algorithm_request7.spdm_request_version10.base_hash_algo =
+    3044                 :            :         m_libspdm_use_hash_algo;
+    3045                 :          1 :     m_libspdm_negotiate_algorithm_request8.spdm_request_version10.base_asym_algo =
+    3046                 :            :         m_libspdm_use_asym_algo;
+    3047                 :          1 :     m_libspdm_negotiate_algorithm_request8.spdm_request_version10.base_hash_algo =
+    3048                 :            :         m_libspdm_use_hash_algo;
+    3049                 :          1 :     m_libspdm_negotiate_algorithm_request9.spdm_request_version10.base_asym_algo =
+    3050                 :            :         m_libspdm_use_asym_algo;
+    3051                 :          1 :     m_libspdm_negotiate_algorithm_request9.spdm_request_version10.base_hash_algo =
+    3052                 :            :         m_libspdm_use_hash_algo;
+    3053                 :          1 :     m_libspdm_negotiate_algorithm_request10.base_asym_algo = m_libspdm_use_asym_algo;
+    3054                 :          1 :     m_libspdm_negotiate_algorithm_request10.base_hash_algo = m_libspdm_use_hash_algo;
+    3055                 :          1 :     m_libspdm_negotiate_algorithm_request10.ext_asym_count = 0x09;
+    3056                 :          1 :     m_libspdm_negotiate_algorithm_request11.spdm_request_version10.base_asym_algo =
+    3057                 :            :         m_libspdm_use_asym_algo;
+    3058                 :          1 :     m_libspdm_negotiate_algorithm_request11.spdm_request_version10.base_hash_algo =
+    3059                 :            :         m_libspdm_use_hash_algo;
+    3060                 :          1 :     m_libspdm_negotiate_algorithm_request11.spdm_request_version10.ext_asym_count = 0x15;
+    3061                 :          1 :     m_libspdm_negotiate_algorithm_request12.spdm_request_version10.base_asym_algo =
+    3062                 :            :         m_libspdm_use_asym_algo;
+    3063                 :          1 :     m_libspdm_negotiate_algorithm_request12.spdm_request_version10.base_hash_algo =
+    3064                 :            :         m_libspdm_use_hash_algo;
+    3065                 :          1 :     m_libspdm_negotiate_algorithm_request13.spdm_request_version10.base_asym_algo =
+    3066                 :            :         m_libspdm_use_asym_algo;
+    3067                 :          1 :     m_libspdm_negotiate_algorithm_request13.spdm_request_version10.base_hash_algo =
+    3068                 :            :         m_libspdm_use_hash_algo;
+    3069                 :          1 :     m_libspdm_negotiate_algorithm_request14.spdm_request_version10.base_asym_algo =
+    3070                 :            :         m_libspdm_use_asym_algo;
+    3071                 :          1 :     m_libspdm_negotiate_algorithm_request14.spdm_request_version10.base_hash_algo =
+    3072                 :            :         m_libspdm_use_hash_algo;
+    3073                 :          1 :     m_libspdm_negotiate_algorithm_request15.spdm_request_version10.base_asym_algo =
+    3074                 :            :         m_libspdm_use_asym_algo;
+    3075                 :          1 :     m_libspdm_negotiate_algorithm_request15.spdm_request_version10.base_hash_algo =
+    3076                 :            :         m_libspdm_use_hash_algo;
+    3077                 :          1 :     m_libspdm_negotiate_algorithm_request16.spdm_request_version10.base_asym_algo =
+    3078                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521 |
+    3079                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384 |
+    3080                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256 |
+    3081                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072 |
+    3082                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048;
+    3083                 :          1 :     m_libspdm_negotiate_algorithm_request16.spdm_request_version10.base_hash_algo =
+    3084                 :            :         SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512 |
+    3085                 :            :         SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_384 |
+    3086                 :            :         SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256;
+    3087                 :          1 :     m_libspdm_negotiate_algorithm_request17.spdm_request_version10.base_hash_algo =
+    3088                 :            :         m_libspdm_use_hash_algo;
+    3089                 :          1 :     m_libspdm_negotiate_algorithm_request17.spdm_request_version10.base_asym_algo =
+    3090                 :            :         m_libspdm_use_asym_algo;
+    3091                 :          1 :     m_libspdm_negotiate_algorithm_request18.spdm_request_version10.base_hash_algo =
+    3092                 :            :         m_libspdm_use_hash_algo;
+    3093                 :          1 :     m_libspdm_negotiate_algorithm_request18.spdm_request_version10.base_asym_algo =
+    3094                 :            :         m_libspdm_use_asym_algo;
+    3095                 :          1 :     m_libspdm_negotiate_algorithm_request24.spdm_request_version10.base_asym_algo =
+    3096                 :            :         m_libspdm_use_asym_algo;
+    3097                 :          1 :     libspdm_setup_test_context(&m_libspdm_responder_algorithms_test_context);
+    3098                 :            : 
+    3099                 :          1 :     return cmocka_run_group_tests(spdm_responder_algorithms_tests,
+    3100                 :            :                                   libspdm_unit_test_group_setup,
+    3101                 :            :                                   libspdm_unit_test_group_teardown);
+    3102                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/capabilities.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_responder/capabilities.c.func-sort-c.html new file mode 100644 index 00000000000..bec7937bd89 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/capabilities.c.func-sort-c.html @@ -0,0 +1,189 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/capabilities.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - capabilities.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:359359100.0 %
Date:2024-09-22 08:21:07Functions:2727100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_capabilities_test_main1
libspdm_test_responder_capabilities_case11
libspdm_test_responder_capabilities_case101
libspdm_test_responder_capabilities_case111
libspdm_test_responder_capabilities_case121
libspdm_test_responder_capabilities_case131
libspdm_test_responder_capabilities_case141
libspdm_test_responder_capabilities_case151
libspdm_test_responder_capabilities_case161
libspdm_test_responder_capabilities_case171
libspdm_test_responder_capabilities_case181
libspdm_test_responder_capabilities_case191
libspdm_test_responder_capabilities_case21
libspdm_test_responder_capabilities_case201
libspdm_test_responder_capabilities_case211
libspdm_test_responder_capabilities_case221
libspdm_test_responder_capabilities_case231
libspdm_test_responder_capabilities_case241
libspdm_test_responder_capabilities_case251
libspdm_test_responder_capabilities_case261
libspdm_test_responder_capabilities_case271
libspdm_test_responder_capabilities_case31
libspdm_test_responder_capabilities_case41
libspdm_test_responder_capabilities_case61
libspdm_test_responder_capabilities_case71
libspdm_test_responder_capabilities_case81
libspdm_test_responder_capabilities_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/capabilities.c.func.html b/coverage_log/unit_test/test_spdm_responder/capabilities.c.func.html new file mode 100644 index 00000000000..4ed7c59f75a --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/capabilities.c.func.html @@ -0,0 +1,189 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/capabilities.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - capabilities.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:359359100.0 %
Date:2024-09-22 08:21:07Functions:2727100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_capabilities_test_main1
libspdm_test_responder_capabilities_case11
libspdm_test_responder_capabilities_case101
libspdm_test_responder_capabilities_case111
libspdm_test_responder_capabilities_case121
libspdm_test_responder_capabilities_case131
libspdm_test_responder_capabilities_case141
libspdm_test_responder_capabilities_case151
libspdm_test_responder_capabilities_case161
libspdm_test_responder_capabilities_case171
libspdm_test_responder_capabilities_case181
libspdm_test_responder_capabilities_case191
libspdm_test_responder_capabilities_case21
libspdm_test_responder_capabilities_case201
libspdm_test_responder_capabilities_case211
libspdm_test_responder_capabilities_case221
libspdm_test_responder_capabilities_case231
libspdm_test_responder_capabilities_case241
libspdm_test_responder_capabilities_case251
libspdm_test_responder_capabilities_case261
libspdm_test_responder_capabilities_case271
libspdm_test_responder_capabilities_case31
libspdm_test_responder_capabilities_case41
libspdm_test_responder_capabilities_case61
libspdm_test_responder_capabilities_case71
libspdm_test_responder_capabilities_case81
libspdm_test_responder_capabilities_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/capabilities.c.gcov.html b/coverage_log/unit_test/test_spdm_responder/capabilities.c.gcov.html new file mode 100644 index 00000000000..76cdedf5b81 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/capabilities.c.gcov.html @@ -0,0 +1,1378 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/capabilities.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - capabilities.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:359359100.0 %
Date:2024-09-22 08:21:07Functions:2727100.0 %
Branches:00-
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_responder_lib.h"
+       9                 :            : 
+      10                 :            : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request1 = {
+      11                 :            :     {
+      12                 :            :         SPDM_MESSAGE_VERSION_10,
+      13                 :            :         SPDM_GET_CAPABILITIES,
+      14                 :            :     },
+      15                 :            : };
+      16                 :            : /* version 1.0 message consists of only header (size 0x04).
+      17                 :            :  * However, spdm_get_capabilities_request_t has a size of 0x0c.
+      18                 :            :  * Therefore, sending a v1.0 request with this structure results in a wrong size request.
+      19                 :            :  * size information was corrected to reflect the actual size of a get_capabilities 1.0 message.*/
+      20                 :            : size_t m_libspdm_get_capabilities_request1_size = sizeof(spdm_message_header_t);
+      21                 :            : 
+      22                 :            : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request2 = {
+      23                 :            :     {
+      24                 :            :         SPDM_MESSAGE_VERSION_10,
+      25                 :            :         SPDM_GET_CAPABILITIES,
+      26                 :            :     },
+      27                 :            : };
+      28                 :            : size_t m_libspdm_get_capabilities_request2_size = LIBSPDM_MAX_SPDM_MSG_SIZE;
+      29                 :            : 
+      30                 :            : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request4 = {
+      31                 :            :     {
+      32                 :            :         SPDM_MESSAGE_VERSION_11,
+      33                 :            :         SPDM_GET_CAPABILITIES,
+      34                 :            :     }, /*header*/
+      35                 :            :     0x00, /*reserved*/
+      36                 :            :     0x01, /*ct_exponent*/
+      37                 :            :     0x0000, /*reserved, 2 bytes*/
+      38                 :            :     (SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | /*flags*/
+      39                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP |
+      40                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP |
+      41                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP |
+      42                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP |
+      43                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
+      44                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER |
+      45                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP |
+      46                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP |
+      47                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP |
+      48                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)
+      49                 :            : };
+      50                 :            : size_t m_libspdm_get_capabilities_request4_size =
+      51                 :            :     sizeof(m_libspdm_get_capabilities_request4) -
+      52                 :            :     sizeof(m_libspdm_get_capabilities_request4.data_transfer_size) -
+      53                 :            :     sizeof(m_libspdm_get_capabilities_request4.max_spdm_msg_size);
+      54                 :            : 
+      55                 :            : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request5 = {
+      56                 :            :     {
+      57                 :            :         SPDM_MESSAGE_VERSION_11,
+      58                 :            :         SPDM_GET_CAPABILITIES,
+      59                 :            :     }, /*header*/
+      60                 :            :     0x00, /*reserved*/
+      61                 :            :     0x01, /*ct_exponent*/
+      62                 :            :     0x0000, /*reserved, 2 bytes*/
+      63                 :            :     (0x01 | SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | /*flags*/
+      64                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP |
+      65                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP |
+      66                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP |
+      67                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP |
+      68                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
+      69                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER |
+      70                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP |
+      71                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP |
+      72                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP |
+      73                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)
+      74                 :            : };
+      75                 :            : size_t m_libspdm_get_capabilities_request5_size =
+      76                 :            :     sizeof(m_libspdm_get_capabilities_request5) -
+      77                 :            :     sizeof(m_libspdm_get_capabilities_request5.data_transfer_size) -
+      78                 :            :     sizeof(m_libspdm_get_capabilities_request5.max_spdm_msg_size);
+      79                 :            : 
+      80                 :            : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request6 = {
+      81                 :            :     {
+      82                 :            :         SPDM_MESSAGE_VERSION_11,
+      83                 :            :         SPDM_GET_CAPABILITIES,
+      84                 :            :     }, /*header*/
+      85                 :            :     0x00, /*reserved*/
+      86                 :            :     0x01, /*ct_exponent*/
+      87                 :            :     0x0000, /*reserved, 2 bytes*/
+      88                 :            :     (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG |
+      89                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | /*flags*/
+      90                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP |
+      91                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP |
+      92                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP |
+      93                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP |
+      94                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
+      95                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER |
+      96                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP |
+      97                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP |
+      98                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP |
+      99                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)
+     100                 :            : };
+     101                 :            : size_t m_libspdm_get_capabilities_request6_size =
+     102                 :            :     sizeof(m_libspdm_get_capabilities_request6) -
+     103                 :            :     sizeof(m_libspdm_get_capabilities_request6.data_transfer_size) -
+     104                 :            :     sizeof(m_libspdm_get_capabilities_request6.max_spdm_msg_size);
+     105                 :            : 
+     106                 :            : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request7 = {
+     107                 :            :     {
+     108                 :            :         SPDM_MESSAGE_VERSION_11,
+     109                 :            :         SPDM_GET_CAPABILITIES,
+     110                 :            :     }, /*header*/
+     111                 :            :     0x00, /*reserved*/
+     112                 :            :     LIBSPDM_MAX_CT_EXPONENT + 1, /*Illegal ct_exponent*/
+     113                 :            :     0x0000, /*reserved, 2 bytes*/
+     114                 :            :     (0x100000 | SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | /*flags*/
+     115                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP |
+     116                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP |
+     117                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP |
+     118                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP |
+     119                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
+     120                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER |
+     121                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP |
+     122                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP |
+     123                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP |
+     124                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)
+     125                 :            : };
+     126                 :            : size_t m_libspdm_get_capabilities_request7_size =
+     127                 :            :     sizeof(m_libspdm_get_capabilities_request7) -
+     128                 :            :     sizeof(m_libspdm_get_capabilities_request7.data_transfer_size) -
+     129                 :            :     sizeof(m_libspdm_get_capabilities_request7.max_spdm_msg_size);
+     130                 :            : 
+     131                 :            : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request8 = {
+     132                 :            :     {
+     133                 :            :         SPDM_MESSAGE_VERSION_11,
+     134                 :            :         SPDM_GET_CAPABILITIES,
+     135                 :            :     }, /*header*/
+     136                 :            :     0x00, /*reserved*/
+     137                 :            :     0x01, /*ct_exponent*/
+     138                 :            :     0x0000, /*reserved, 2 bytes*/
+     139                 :            :     (0x100000 | SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | /*flags*/
+     140                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP |
+     141                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP |
+     142                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP |
+     143                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP |
+     144                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
+     145                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER |
+     146                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP |
+     147                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP |
+     148                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP |
+     149                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)
+     150                 :            : };
+     151                 :            : size_t m_libspdm_get_capabilities_request8_size =
+     152                 :            :     sizeof(m_libspdm_get_capabilities_request8) -
+     153                 :            :     sizeof(m_libspdm_get_capabilities_request8.data_transfer_size) -
+     154                 :            :     sizeof(m_libspdm_get_capabilities_request8.max_spdm_msg_size);
+     155                 :            : 
+     156                 :            : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request9 = {
+     157                 :            :     {
+     158                 :            :         SPDM_MESSAGE_VERSION_11,
+     159                 :            :         SPDM_GET_CAPABILITIES,
+     160                 :            :     }, /*header*/
+     161                 :            :     0x00, /*reserved*/
+     162                 :            :     0x01, /*ct_exponent*/
+     163                 :            :     0x0000, /*reserved, 2 bytes*/
+     164                 :            :     (SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PUB_KEY_ID_CAP |
+     165                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | /*flags*/
+     166                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP |
+     167                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP |
+     168                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP |
+     169                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP |
+     170                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
+     171                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER |
+     172                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP |
+     173                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP |
+     174                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP |
+     175                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)
+     176                 :            : };
+     177                 :            : size_t m_libspdm_get_capabilities_request9_size =
+     178                 :            :     sizeof(m_libspdm_get_capabilities_request9) -
+     179                 :            :     sizeof(m_libspdm_get_capabilities_request9.data_transfer_size) -
+     180                 :            :     sizeof(m_libspdm_get_capabilities_request9.max_spdm_msg_size);
+     181                 :            : 
+     182                 :            : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request10 = {
+     183                 :            :     {
+     184                 :            :         SPDM_MESSAGE_VERSION_11,
+     185                 :            :         SPDM_GET_CAPABILITIES,
+     186                 :            :     }, /*header*/
+     187                 :            :     0x00, /*reserved*/
+     188                 :            :     0x01, /*ct_exponent*/
+     189                 :            :     0x0000, /*reserved, 2 bytes*/
+     190                 :            :     (SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | /*flags*/
+     191                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP |
+     192                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP |
+     193                 :            : 
+     194                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP |
+     195                 :            : 
+     196                 :            : 
+     197                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP |
+     198                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP |
+     199                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP |
+     200                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)
+     201                 :            : };
+     202                 :            : size_t m_libspdm_get_capabilities_request10_size =
+     203                 :            :     sizeof(m_libspdm_get_capabilities_request10) -
+     204                 :            :     sizeof(m_libspdm_get_capabilities_request10.data_transfer_size) -
+     205                 :            :     sizeof(m_libspdm_get_capabilities_request10.max_spdm_msg_size);
+     206                 :            : 
+     207                 :            : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request11 = {
+     208                 :            :     {
+     209                 :            :         SPDM_MESSAGE_VERSION_11,
+     210                 :            :         SPDM_GET_CAPABILITIES,
+     211                 :            :     }, /*header*/
+     212                 :            :     0x00, /*reserved*/
+     213                 :            :     0x01, /*ct_exponent*/
+     214                 :            :     0x0000, /*reserved, 2 bytes*/
+     215                 :            :     (SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | /*flags*/
+     216                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP |
+     217                 :            : 
+     218                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP |
+     219                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP |
+     220                 :            : 
+     221                 :            : 
+     222                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP |
+     223                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP |
+     224                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP |
+     225                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)
+     226                 :            : };
+     227                 :            : size_t m_libspdm_get_capabilities_request11_size =
+     228                 :            :     sizeof(m_libspdm_get_capabilities_request11) -
+     229                 :            :     sizeof(m_libspdm_get_capabilities_request11.data_transfer_size) -
+     230                 :            :     sizeof(m_libspdm_get_capabilities_request11.max_spdm_msg_size);
+     231                 :            : 
+     232                 :            : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request12 = {
+     233                 :            :     {
+     234                 :            :         SPDM_MESSAGE_VERSION_11,
+     235                 :            :         SPDM_GET_CAPABILITIES,
+     236                 :            :     }, /*header*/
+     237                 :            :     0x00, /*reserved*/
+     238                 :            :     0x01, /*ct_exponent*/
+     239                 :            :     0x0000, /*reserved, 2 bytes*/
+     240                 :            :     (SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | /*flags*/
+     241                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP |
+     242                 :            : 
+     243                 :            : 
+     244                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP |
+     245                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
+     246                 :            : 
+     247                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP |
+     248                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP |
+     249                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP
+     250                 :            : 
+     251                 :            :     )
+     252                 :            : };
+     253                 :            : size_t m_libspdm_get_capabilities_request12_size =
+     254                 :            :     sizeof(m_libspdm_get_capabilities_request12) -
+     255                 :            :     sizeof(m_libspdm_get_capabilities_request12.data_transfer_size) -
+     256                 :            :     sizeof(m_libspdm_get_capabilities_request12.max_spdm_msg_size);
+     257                 :            : 
+     258                 :            : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request13 = {
+     259                 :            :     {
+     260                 :            :         SPDM_MESSAGE_VERSION_11,
+     261                 :            :         SPDM_GET_CAPABILITIES,
+     262                 :            :     }, /*header*/
+     263                 :            :     0x00, /*reserved*/
+     264                 :            :     0x01, /*ct_exponent*/
+     265                 :            :     0x0000, /*reserved, 2 bytes*/
+     266                 :            :     (SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | /*flags*/
+     267                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP |
+     268                 :            : 
+     269                 :            : 
+     270                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP |
+     271                 :            : 
+     272                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER |
+     273                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP |
+     274                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP |
+     275                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP
+     276                 :            : 
+     277                 :            :     )
+     278                 :            : };
+     279                 :            : size_t m_libspdm_get_capabilities_request13_size =
+     280                 :            :     sizeof(m_libspdm_get_capabilities_request13) -
+     281                 :            :     sizeof(m_libspdm_get_capabilities_request13.data_transfer_size) -
+     282                 :            :     sizeof(m_libspdm_get_capabilities_request13.max_spdm_msg_size);
+     283                 :            : 
+     284                 :            : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request14 = {
+     285                 :            :     {
+     286                 :            :         SPDM_MESSAGE_VERSION_11,
+     287                 :            :         SPDM_GET_CAPABILITIES,
+     288                 :            :     }, /*header*/
+     289                 :            :     0x00, /*reserved*/
+     290                 :            :     0x01, /*ct_exponent*/
+     291                 :            :     0x0000, /*reserved, 2 bytes*/
+     292                 :            :     (SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | /*flags*/
+     293                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP |
+     294                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP |
+     295                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP |
+     296                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP |
+     297                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
+     298                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER |
+     299                 :            : 
+     300                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP |
+     301                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP |
+     302                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)
+     303                 :            : };
+     304                 :            : size_t m_libspdm_get_capabilities_request14_size =
+     305                 :            :     sizeof(m_libspdm_get_capabilities_request14) -
+     306                 :            :     sizeof(m_libspdm_get_capabilities_request14.data_transfer_size) -
+     307                 :            :     sizeof(m_libspdm_get_capabilities_request14.max_spdm_msg_size);
+     308                 :            : 
+     309                 :            : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request15 = {
+     310                 :            :     {
+     311                 :            :         SPDM_MESSAGE_VERSION_11,
+     312                 :            :         SPDM_GET_CAPABILITIES,
+     313                 :            :     }, /*header*/
+     314                 :            :     0x00, /*reserved*/
+     315                 :            :     0x01, /*ct_exponent*/
+     316                 :            :     0x0000, /*reserved, 2 bytes*/
+     317                 :            :     (SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | /*flags*/
+     318                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP |
+     319                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP |
+     320                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP |
+     321                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP |
+     322                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
+     323                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER |
+     324                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP |
+     325                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP |
+     326                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP |
+     327                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP |
+     328                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PUB_KEY_ID_CAP)
+     329                 :            : };
+     330                 :            : size_t m_libspdm_get_capabilities_request15_size =
+     331                 :            :     sizeof(m_libspdm_get_capabilities_request15) -
+     332                 :            :     sizeof(m_libspdm_get_capabilities_request15.data_transfer_size) -
+     333                 :            :     sizeof(m_libspdm_get_capabilities_request15.max_spdm_msg_size);
+     334                 :            : 
+     335                 :            : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request16 = {
+     336                 :            :     {
+     337                 :            :         SPDM_MESSAGE_VERSION_11,
+     338                 :            :         SPDM_GET_CAPABILITIES,
+     339                 :            :     }, /*header*/
+     340                 :            :     0x00, /*reserved*/
+     341                 :            :     0x01, /*ct_exponent*/
+     342                 :            :     0x0000, /*reserved, 2 bytes*/
+     343                 :            :     (SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | /*flags*/
+     344                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP |
+     345                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP |
+     346                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP |
+     347                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP |
+     348                 :            : 
+     349                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER |
+     350                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP |
+     351                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP |
+     352                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP |
+     353                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)
+     354                 :            : };
+     355                 :            : size_t m_libspdm_get_capabilities_request16_size =
+     356                 :            :     sizeof(m_libspdm_get_capabilities_request16) -
+     357                 :            :     sizeof(m_libspdm_get_capabilities_request16.data_transfer_size) -
+     358                 :            :     sizeof(m_libspdm_get_capabilities_request16.max_spdm_msg_size);
+     359                 :            : 
+     360                 :            : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request17 = {
+     361                 :            :     {
+     362                 :            :         SPDM_MESSAGE_VERSION_11,
+     363                 :            :         SPDM_GET_CAPABILITIES,
+     364                 :            :     }, /*header*/
+     365                 :            :     0x00, /*reserved*/
+     366                 :            :     0x01, /*ct_exponent*/
+     367                 :            :     0x0000, /*reserved, 2 bytes*/
+     368                 :            :     (SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | /*flags*/
+     369                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP |
+     370                 :            : 
+     371                 :            : 
+     372                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP |
+     373                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
+     374                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER |
+     375                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP |
+     376                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP |
+     377                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP |
+     378                 :            :      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)
+     379                 :            : };
+     380                 :            : size_t m_libspdm_get_capabilities_request17_size =
+     381                 :            :     sizeof(m_libspdm_get_capabilities_request17) -
+     382                 :            :     sizeof(m_libspdm_get_capabilities_request17.data_transfer_size) -
+     383                 :            :     sizeof(m_libspdm_get_capabilities_request17.max_spdm_msg_size);
+     384                 :            : 
+     385                 :            : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request18 = {
+     386                 :            :     {
+     387                 :            :         SPDM_MESSAGE_VERSION_11,
+     388                 :            :         SPDM_GET_CAPABILITIES,
+     389                 :            :     }, /*header*/
+     390                 :            :     0x00, /*reserved*/
+     391                 :            :     0x01, /*ct_exponent*/
+     392                 :            :     0x0000, /*reserved, 2 bytes*/
+     393                 :            :     ( /*flags*/
+     394                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP |
+     395                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP |
+     396                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP |
+     397                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP |
+     398                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
+     399                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER |
+     400                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP |
+     401                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP |
+     402                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP |
+     403                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP |
+     404                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PUB_KEY_ID_CAP)
+     405                 :            : };
+     406                 :            : size_t m_libspdm_get_capabilities_request18_size =
+     407                 :            :     sizeof(m_libspdm_get_capabilities_request18) -
+     408                 :            :     sizeof(m_libspdm_get_capabilities_request18.data_transfer_size) -
+     409                 :            :     sizeof(m_libspdm_get_capabilities_request18.max_spdm_msg_size);
+     410                 :            : 
+     411                 :            : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request19 = {
+     412                 :            :     {
+     413                 :            :         SPDM_MESSAGE_VERSION_12,
+     414                 :            :         SPDM_GET_CAPABILITIES,
+     415                 :            :     }, /*header*/
+     416                 :            :     0x00, /*reserved*/
+     417                 :            :     0x01, /*ct_exponent*/
+     418                 :            :     0x0000, /*reserved, 2 bytes*/
+     419                 :            :     (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP|
+     420                 :            :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ALIAS_CERT_CAP),
+     421                 :            :     LIBSPDM_DATA_TRANSFER_SIZE,
+     422                 :            :     LIBSPDM_MAX_SPDM_MSG_SIZE,
+     423                 :            : };
+     424                 :            : size_t m_libspdm_get_capabilities_request19_size = sizeof(m_libspdm_get_capabilities_request19);
+     425                 :            : 
+     426                 :            : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request25 = {
+     427                 :            :     {
+     428                 :            :         SPDM_MESSAGE_VERSION_12,
+     429                 :            :         SPDM_GET_CAPABILITIES,
+     430                 :            :     }, /*header*/
+     431                 :            :     0x00, /*reserved*/
+     432                 :            :     0x01, /*ct_exponent*/
+     433                 :            :     0x0000, /*reserved, 2 bytes*/
+     434                 :            :     0,
+     435                 :            :     LIBSPDM_DATA_TRANSFER_SIZE - 1,
+     436                 :            :     LIBSPDM_MAX_SPDM_MSG_SIZE,
+     437                 :            : };
+     438                 :            : size_t m_libspdm_get_capabilities_request25_size = sizeof(m_libspdm_get_capabilities_request25);
+     439                 :            : 
+     440                 :            : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request26 = {
+     441                 :            :     {
+     442                 :            :         SPDM_MESSAGE_VERSION_12,
+     443                 :            :         SPDM_GET_CAPABILITIES,
+     444                 :            :     }, /*header*/
+     445                 :            :     0x00, /*reserved*/
+     446                 :            :     0x01, /*ct_exponent*/
+     447                 :            :     0x0000, /*reserved, 2 bytes*/
+     448                 :            :     (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP|
+     449                 :            :      SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ALIAS_CERT_CAP),
+     450                 :            :     LIBSPDM_DATA_TRANSFER_SIZE,
+     451                 :            :     LIBSPDM_DATA_TRANSFER_SIZE - 1,
+     452                 :            : };
+     453                 :            : size_t m_libspdm_get_capabilities_request26_size = sizeof(m_libspdm_get_capabilities_request26);
+     454                 :            : 
+     455                 :            : 
+     456                 :            : spdm_get_capabilities_request_t m_libspdm_get_capabilities_request27 = {
+     457                 :            :     {
+     458                 :            :         SPDM_MESSAGE_VERSION_13,
+     459                 :            :         SPDM_GET_CAPABILITIES,
+     460                 :            :     },
+     461                 :            :     0x00, /*reserved*/
+     462                 :            :     0x01, /*ct_exponent*/
+     463                 :            :     0x0000, /*reserved, 2 bytes*/
+     464                 :            :     SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MULTI_KEY_CAP_ONLY,
+     465                 :            :     LIBSPDM_DATA_TRANSFER_SIZE,
+     466                 :            :     LIBSPDM_MAX_SPDM_MSG_SIZE,
+     467                 :            : };
+     468                 :            : size_t m_libspdm_get_capabilities_request27_size = sizeof(m_libspdm_get_capabilities_request27);
+     469                 :            : 
+     470                 :          1 : void libspdm_test_responder_capabilities_case1(void **state)
+     471                 :            : {
+     472                 :            :     libspdm_return_t status;
+     473                 :            :     libspdm_test_context_t *spdm_test_context;
+     474                 :            :     libspdm_context_t *spdm_context;
+     475                 :            :     size_t response_size;
+     476                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     477                 :            :     spdm_capabilities_response_t *spdm_response;
+     478                 :            : 
+     479                 :          1 :     spdm_test_context = *state;
+     480                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     481                 :          1 :     spdm_test_context->case_id = 0x1;
+     482                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+     483                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     484                 :            :     spdm_context->transcript.message_m.buffer_size =
+     485                 :            :         spdm_context->transcript.message_m.max_buffer_size;
+     486                 :            : #endif
+     487                 :            : 
+     488                 :          1 :     response_size = sizeof(response);
+     489                 :          1 :     status = libspdm_get_response_capabilities(
+     490                 :            :         spdm_context, m_libspdm_get_capabilities_request1_size,
+     491                 :            :         &m_libspdm_get_capabilities_request1, &response_size, response);
+     492                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     493                 :          1 :     assert_int_equal(response_size, sizeof(spdm_capabilities_response_t) -
+     494                 :            :                      sizeof(spdm_response->data_transfer_size) -
+     495                 :            :                      sizeof(spdm_response->max_spdm_msg_size));
+     496                 :          1 :     spdm_response = (void *)response;
+     497                 :          1 :     assert_int_equal(m_libspdm_get_capabilities_request1.header.spdm_version,
+     498                 :            :                      spdm_response->header.spdm_version);
+     499                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     500                 :            :                      SPDM_CAPABILITIES);
+     501                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     502                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+     503                 :            : #endif
+     504                 :          1 : }
+     505                 :            : 
+     506                 :          1 : void libspdm_test_responder_capabilities_case2(void **state)
+     507                 :            : {
+     508                 :            :     libspdm_return_t status;
+     509                 :            :     libspdm_test_context_t *spdm_test_context;
+     510                 :            :     libspdm_context_t *spdm_context;
+     511                 :            :     size_t response_size;
+     512                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     513                 :            :     spdm_capabilities_response_t *spdm_response;
+     514                 :            : 
+     515                 :          1 :     spdm_test_context = *state;
+     516                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     517                 :          1 :     spdm_test_context->case_id = 0x2;
+     518                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+     519                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     520                 :            :     spdm_context->transcript.message_m.buffer_size =
+     521                 :            :         spdm_context->transcript.message_m.max_buffer_size;
+     522                 :            : #endif
+     523                 :            : 
+     524                 :          1 :     response_size = sizeof(response);
+     525                 :          1 :     status = libspdm_get_response_capabilities(
+     526                 :            :         spdm_context, m_libspdm_get_capabilities_request2_size,
+     527                 :            :         &m_libspdm_get_capabilities_request2, &response_size, response);
+     528                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     529                 :          1 :     assert_int_equal(response_size, sizeof(spdm_capabilities_response_t) -
+     530                 :            :                      sizeof(spdm_response->data_transfer_size) -
+     531                 :            :                      sizeof(spdm_response->max_spdm_msg_size));
+     532                 :          1 :     spdm_response = (void *)response;
+     533                 :          1 :     assert_int_equal(m_libspdm_get_capabilities_request2.header.spdm_version,
+     534                 :            :                      spdm_response->header.spdm_version);
+     535                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_CAPABILITIES);
+     536                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     537                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+     538                 :            : #endif
+     539                 :          1 : }
+     540                 :            : 
+     541                 :          1 : void libspdm_test_responder_capabilities_case3(void **state)
+     542                 :            : {
+     543                 :            :     libspdm_return_t status;
+     544                 :            :     libspdm_test_context_t *spdm_test_context;
+     545                 :            :     libspdm_context_t *spdm_context;
+     546                 :            :     size_t response_size;
+     547                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     548                 :            :     spdm_capabilities_response_t *spdm_response;
+     549                 :            : 
+     550                 :          1 :     spdm_test_context = *state;
+     551                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     552                 :          1 :     spdm_test_context->case_id = 0x3;
+     553                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_BUSY;
+     554                 :          1 :     spdm_context->connection_info.connection_state =
+     555                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+     556                 :            : 
+     557                 :          1 :     response_size = sizeof(response);
+     558                 :          1 :     status = libspdm_get_response_capabilities(
+     559                 :            :         spdm_context, m_libspdm_get_capabilities_request1_size,
+     560                 :            :         &m_libspdm_get_capabilities_request1, &response_size, response);
+     561                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     562                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     563                 :          1 :     spdm_response = (void *)response;
+     564                 :          1 :     assert_int_equal(m_libspdm_get_capabilities_request1.header.spdm_version,
+     565                 :            :                      spdm_response->header.spdm_version);
+     566                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     567                 :            :                      SPDM_ERROR);
+     568                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_BUSY);
+     569                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     570                 :          1 :     assert_int_equal(spdm_context->response_state,
+     571                 :            :                      LIBSPDM_RESPONSE_STATE_BUSY);
+     572                 :          1 : }
+     573                 :            : 
+     574                 :          1 : void libspdm_test_responder_capabilities_case4(void **state)
+     575                 :            : {
+     576                 :            :     libspdm_return_t status;
+     577                 :            :     libspdm_test_context_t *spdm_test_context;
+     578                 :            :     libspdm_context_t *spdm_context;
+     579                 :            :     size_t response_size;
+     580                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     581                 :            :     spdm_capabilities_response_t *spdm_response;
+     582                 :            : 
+     583                 :          1 :     spdm_test_context = *state;
+     584                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     585                 :          1 :     spdm_test_context->case_id = 0x4;
+     586                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NEED_RESYNC;
+     587                 :          1 :     spdm_context->connection_info.connection_state =
+     588                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+     589                 :            : 
+     590                 :          1 :     response_size = sizeof(response);
+     591                 :          1 :     status = libspdm_get_response_capabilities(
+     592                 :            :         spdm_context, m_libspdm_get_capabilities_request1_size,
+     593                 :            :         &m_libspdm_get_capabilities_request1, &response_size, response);
+     594                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     595                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     596                 :          1 :     spdm_response = (void *)response;
+     597                 :          1 :     assert_int_equal(m_libspdm_get_capabilities_request1.header.spdm_version,
+     598                 :            :                      spdm_response->header.spdm_version);
+     599                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     600                 :            :                      SPDM_ERROR);
+     601                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     602                 :            :                      SPDM_ERROR_CODE_REQUEST_RESYNCH);
+     603                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     604                 :          1 :     assert_int_equal(spdm_context->response_state,
+     605                 :            :                      LIBSPDM_RESPONSE_STATE_NEED_RESYNC);
+     606                 :          1 : }
+     607                 :            : 
+     608                 :          1 : void libspdm_test_responder_capabilities_case6(void **state)
+     609                 :            : {
+     610                 :            :     libspdm_return_t status;
+     611                 :            :     libspdm_test_context_t *spdm_test_context;
+     612                 :            :     libspdm_context_t *spdm_context;
+     613                 :            :     size_t response_size;
+     614                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     615                 :            :     spdm_capabilities_response_t *spdm_response;
+     616                 :            : 
+     617                 :          1 :     spdm_test_context = *state;
+     618                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     619                 :          1 :     spdm_test_context->case_id = 0x6;
+     620                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+     621                 :          1 :     spdm_context->connection_info.connection_state =
+     622                 :            :         LIBSPDM_CONNECTION_STATE_NOT_STARTED;
+     623                 :            : 
+     624                 :          1 :     response_size = sizeof(response);
+     625                 :          1 :     status = libspdm_get_response_capabilities(
+     626                 :            :         spdm_context, m_libspdm_get_capabilities_request1_size,
+     627                 :            :         &m_libspdm_get_capabilities_request1, &response_size, response);
+     628                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     629                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     630                 :          1 :     spdm_response = (void *)response;
+     631                 :          1 :     assert_int_equal(m_libspdm_get_capabilities_request1.header.spdm_version,
+     632                 :            :                      spdm_response->header.spdm_version);
+     633                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     634                 :            :                      SPDM_ERROR);
+     635                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     636                 :            :                      SPDM_ERROR_CODE_UNEXPECTED_REQUEST);
+     637                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     638                 :          1 : }
+     639                 :            : 
+     640                 :            : /**
+     641                 :            :  * Test 7: Requester sets a CTExponent value that is larger than LIBSPDM_MAX_CT_EXPONENT.
+     642                 :            :  * Expected behavior: returns with error code SPDM_ERROR_CODE_INVALID_REQUEST.
+     643                 :            :  **/
+     644                 :          1 : void libspdm_test_responder_capabilities_case7(void **state)
+     645                 :            : {
+     646                 :            :     libspdm_return_t status;
+     647                 :            :     libspdm_test_context_t *spdm_test_context;
+     648                 :            :     libspdm_context_t *spdm_context;
+     649                 :            :     size_t response_size;
+     650                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     651                 :            :     spdm_capabilities_response_t *spdm_response;
+     652                 :            : 
+     653                 :          1 :     spdm_test_context = *state;
+     654                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     655                 :          1 :     spdm_test_context->case_id = 0x7;
+     656                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+     657                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+     658                 :            : 
+     659                 :          1 :     response_size = sizeof(response);
+     660                 :          1 :     status = libspdm_get_response_capabilities(
+     661                 :            :         spdm_context, m_libspdm_get_capabilities_request7_size,
+     662                 :            :         &m_libspdm_get_capabilities_request7, &response_size, response);
+     663                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     664                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     665                 :          1 :     spdm_response = (void *)response;
+     666                 :          1 :     assert_int_equal(m_libspdm_get_capabilities_request7.header.spdm_version,
+     667                 :            :                      spdm_response->header.spdm_version);
+     668                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
+     669                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+     670                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     671                 :          1 : }
+     672                 :            : 
+     673                 :          1 : void libspdm_test_responder_capabilities_case8(void **state)
+     674                 :            : {
+     675                 :            :     libspdm_return_t status;
+     676                 :            :     libspdm_test_context_t *spdm_test_context;
+     677                 :            :     libspdm_context_t *spdm_context;
+     678                 :            :     size_t response_size;
+     679                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     680                 :            :     spdm_capabilities_response_t *spdm_response;
+     681                 :            : 
+     682                 :          1 :     spdm_test_context = *state;
+     683                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     684                 :          1 :     spdm_test_context->case_id = 0x8;
+     685                 :          1 :     spdm_context->connection_info.connection_state =
+     686                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+     687                 :            : 
+     688                 :          1 :     response_size = sizeof(response);
+     689                 :          1 :     status = libspdm_get_response_capabilities(
+     690                 :            :         spdm_context, m_libspdm_get_capabilities_request4_size,
+     691                 :            :         &m_libspdm_get_capabilities_request4, &response_size, response);
+     692                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     693                 :          1 :     assert_int_equal(response_size, sizeof(spdm_capabilities_response_t) -
+     694                 :            :                      sizeof(spdm_response->data_transfer_size) -
+     695                 :            :                      sizeof(spdm_response->max_spdm_msg_size));
+     696                 :          1 :     spdm_response = (void *)response;
+     697                 :          1 :     assert_int_equal(m_libspdm_get_capabilities_request4.header.spdm_version,
+     698                 :            :                      spdm_response->header.spdm_version);
+     699                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     700                 :            :                      SPDM_CAPABILITIES);
+     701                 :          1 : }
+     702                 :            : 
+     703                 :          1 : void libspdm_test_responder_capabilities_case9(void **state)
+     704                 :            : {
+     705                 :            :     libspdm_return_t status;
+     706                 :            :     libspdm_test_context_t *spdm_test_context;
+     707                 :            :     libspdm_context_t *spdm_context;
+     708                 :            :     size_t response_size;
+     709                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     710                 :            :     spdm_capabilities_response_t *spdm_response;
+     711                 :            : 
+     712                 :          1 :     spdm_test_context = *state;
+     713                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     714                 :          1 :     spdm_test_context->case_id = 0x9;
+     715                 :          1 :     spdm_context->connection_info.connection_state =
+     716                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+     717                 :            : 
+     718                 :          1 :     response_size = sizeof(response);
+     719                 :          1 :     status = libspdm_get_response_capabilities(
+     720                 :            :         spdm_context, m_libspdm_get_capabilities_request5_size,
+     721                 :            :         &m_libspdm_get_capabilities_request5, &response_size, response);
+     722                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     723                 :          1 :     assert_int_equal(response_size, sizeof(spdm_capabilities_response_t) -
+     724                 :            :                      sizeof(spdm_response->data_transfer_size) -
+     725                 :            :                      sizeof(spdm_response->max_spdm_msg_size));
+     726                 :          1 :     spdm_response = (void *)response;
+     727                 :          1 :     assert_int_equal(m_libspdm_get_capabilities_request4.header.spdm_version,
+     728                 :            :                      spdm_response->header.spdm_version);
+     729                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     730                 :            :                      SPDM_CAPABILITIES);
+     731                 :          1 : }
+     732                 :            : 
+     733                 :          1 : void libspdm_test_responder_capabilities_case10(void **state)
+     734                 :            : {
+     735                 :          1 : }
+     736                 :            : 
+     737                 :          1 : void libspdm_test_responder_capabilities_case11(void **state)
+     738                 :            : {
+     739                 :          1 : }
+     740                 :            : 
+     741                 :          1 : void libspdm_test_responder_capabilities_case12(void **state)
+     742                 :            : {
+     743                 :          1 : }
+     744                 :            : 
+     745                 :          1 : void libspdm_test_responder_capabilities_case13(void **state)
+     746                 :            : {
+     747                 :            :     libspdm_return_t status;
+     748                 :            :     libspdm_test_context_t *spdm_test_context;
+     749                 :            :     libspdm_context_t *spdm_context;
+     750                 :            :     size_t response_size;
+     751                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     752                 :            :     spdm_capabilities_response_t *spdm_response;
+     753                 :            : 
+     754                 :          1 :     spdm_test_context = *state;
+     755                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     756                 :          1 :     spdm_test_context->case_id = 0xd;
+     757                 :          1 :     spdm_context->connection_info.connection_state =
+     758                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+     759                 :            : 
+     760                 :          1 :     response_size = sizeof(response);
+     761                 :          1 :     status = libspdm_get_response_capabilities(
+     762                 :            :         spdm_context, m_libspdm_get_capabilities_request9_size,
+     763                 :            :         &m_libspdm_get_capabilities_request9, &response_size, response);
+     764                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     765                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     766                 :          1 :     spdm_response = (void *)response;
+     767                 :          1 :     assert_int_equal(m_libspdm_get_capabilities_request9.header.spdm_version,
+     768                 :            :                      spdm_response->header.spdm_version);
+     769                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     770                 :            :                      SPDM_ERROR);
+     771                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     772                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+     773                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     774                 :          1 : }
+     775                 :            : 
+     776                 :          1 : void libspdm_test_responder_capabilities_case14(void **state)
+     777                 :            : {
+     778                 :            :     libspdm_return_t status;
+     779                 :            :     libspdm_test_context_t *spdm_test_context;
+     780                 :            :     libspdm_context_t *spdm_context;
+     781                 :            :     size_t response_size;
+     782                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     783                 :            :     spdm_capabilities_response_t *spdm_response;
+     784                 :            : 
+     785                 :          1 :     spdm_test_context = *state;
+     786                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     787                 :          1 :     spdm_test_context->case_id = 0xe;
+     788                 :          1 :     spdm_context->connection_info.connection_state =
+     789                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+     790                 :            : 
+     791                 :          1 :     response_size = sizeof(response);
+     792                 :          1 :     status = libspdm_get_response_capabilities(
+     793                 :            :         spdm_context, m_libspdm_get_capabilities_request10_size,
+     794                 :            :         &m_libspdm_get_capabilities_request10, &response_size, response);
+     795                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     796                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     797                 :          1 :     spdm_response = (void *)response;
+     798                 :          1 :     assert_int_equal(m_libspdm_get_capabilities_request10.header.spdm_version,
+     799                 :            :                      spdm_response->header.spdm_version);
+     800                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     801                 :            :                      SPDM_ERROR);
+     802                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     803                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+     804                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     805                 :          1 : }
+     806                 :            : 
+     807                 :          1 : void libspdm_test_responder_capabilities_case15(void **state)
+     808                 :            : {
+     809                 :            :     libspdm_return_t status;
+     810                 :            :     libspdm_test_context_t *spdm_test_context;
+     811                 :            :     libspdm_context_t *spdm_context;
+     812                 :            :     size_t response_size;
+     813                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     814                 :            :     spdm_capabilities_response_t *spdm_response;
+     815                 :            : 
+     816                 :          1 :     spdm_test_context = *state;
+     817                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     818                 :          1 :     spdm_test_context->case_id = 0xf;
+     819                 :          1 :     spdm_context->connection_info.connection_state =
+     820                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+     821                 :            : 
+     822                 :          1 :     response_size = sizeof(response);
+     823                 :          1 :     status = libspdm_get_response_capabilities(
+     824                 :            :         spdm_context, m_libspdm_get_capabilities_request11_size,
+     825                 :            :         &m_libspdm_get_capabilities_request11, &response_size, response);
+     826                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     827                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     828                 :          1 :     spdm_response = (void *)response;
+     829                 :          1 :     assert_int_equal(m_libspdm_get_capabilities_request11.header.spdm_version,
+     830                 :            :                      spdm_response->header.spdm_version);
+     831                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     832                 :            :                      SPDM_ERROR);
+     833                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     834                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+     835                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     836                 :          1 : }
+     837                 :            : 
+     838                 :          1 : void libspdm_test_responder_capabilities_case16(void **state)
+     839                 :            : {
+     840                 :            :     libspdm_return_t status;
+     841                 :            :     libspdm_test_context_t *spdm_test_context;
+     842                 :            :     libspdm_context_t *spdm_context;
+     843                 :            :     size_t response_size;
+     844                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     845                 :            :     spdm_capabilities_response_t *spdm_response;
+     846                 :            : 
+     847                 :          1 :     spdm_test_context = *state;
+     848                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     849                 :          1 :     spdm_test_context->case_id = 0x10;
+     850                 :          1 :     spdm_context->connection_info.connection_state =
+     851                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+     852                 :            : 
+     853                 :          1 :     response_size = sizeof(response);
+     854                 :          1 :     status = libspdm_get_response_capabilities(
+     855                 :            :         spdm_context, m_libspdm_get_capabilities_request12_size,
+     856                 :            :         &m_libspdm_get_capabilities_request12, &response_size, response);
+     857                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     858                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     859                 :          1 :     spdm_response = (void *)response;
+     860                 :          1 :     assert_int_equal(m_libspdm_get_capabilities_request12.header.spdm_version,
+     861                 :            :                      spdm_response->header.spdm_version);
+     862                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     863                 :            :                      SPDM_ERROR);
+     864                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     865                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+     866                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     867                 :          1 : }
+     868                 :            : 
+     869                 :          1 : void libspdm_test_responder_capabilities_case17(void **state)
+     870                 :            : {
+     871                 :            :     libspdm_return_t status;
+     872                 :            :     libspdm_test_context_t *spdm_test_context;
+     873                 :            :     libspdm_context_t *spdm_context;
+     874                 :            :     size_t response_size;
+     875                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     876                 :            :     spdm_capabilities_response_t *spdm_response;
+     877                 :            : 
+     878                 :          1 :     spdm_test_context = *state;
+     879                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     880                 :          1 :     spdm_test_context->case_id = 0x11;
+     881                 :          1 :     spdm_context->connection_info.connection_state =
+     882                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+     883                 :            : 
+     884                 :          1 :     response_size = sizeof(response);
+     885                 :          1 :     status = libspdm_get_response_capabilities(
+     886                 :            :         spdm_context, m_libspdm_get_capabilities_request13_size,
+     887                 :            :         &m_libspdm_get_capabilities_request13, &response_size, response);
+     888                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     889                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     890                 :          1 :     spdm_response = (void *)response;
+     891                 :          1 :     assert_int_equal(m_libspdm_get_capabilities_request13.header.spdm_version,
+     892                 :            :                      spdm_response->header.spdm_version);
+     893                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     894                 :            :                      SPDM_ERROR);
+     895                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     896                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+     897                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     898                 :          1 : }
+     899                 :            : 
+     900                 :          1 : void libspdm_test_responder_capabilities_case18(void **state)
+     901                 :            : {
+     902                 :            :     libspdm_return_t status;
+     903                 :            :     libspdm_test_context_t *spdm_test_context;
+     904                 :            :     libspdm_context_t *spdm_context;
+     905                 :            :     size_t response_size;
+     906                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     907                 :            :     spdm_capabilities_response_t *spdm_response;
+     908                 :            : 
+     909                 :          1 :     spdm_test_context = *state;
+     910                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     911                 :          1 :     spdm_test_context->case_id = 0x12;
+     912                 :          1 :     spdm_context->connection_info.connection_state =
+     913                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+     914                 :            : 
+     915                 :          1 :     libspdm_reset_message_a(spdm_context);
+     916                 :            : 
+     917                 :          1 :     response_size = sizeof(response);
+     918                 :          1 :     status = libspdm_get_response_capabilities(
+     919                 :            :         spdm_context, m_libspdm_get_capabilities_request14_size,
+     920                 :            :         &m_libspdm_get_capabilities_request14, &response_size, response);
+     921                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     922                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     923                 :          1 :     spdm_response = (void *)response;
+     924                 :          1 :     assert_int_equal(m_libspdm_get_capabilities_request14.header.spdm_version,
+     925                 :            :                      spdm_response->header.spdm_version);
+     926                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     927                 :            :                      SPDM_ERROR);
+     928                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     929                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+     930                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     931                 :          1 : }
+     932                 :            : 
+     933                 :          1 : void libspdm_test_responder_capabilities_case19(void **state)
+     934                 :            : {
+     935                 :            :     libspdm_return_t status;
+     936                 :            :     libspdm_test_context_t *spdm_test_context;
+     937                 :            :     libspdm_context_t *spdm_context;
+     938                 :            :     size_t response_size;
+     939                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     940                 :            :     spdm_capabilities_response_t *spdm_response;
+     941                 :            : 
+     942                 :          1 :     spdm_test_context = *state;
+     943                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     944                 :          1 :     spdm_test_context->case_id = 0x13;
+     945                 :          1 :     spdm_context->connection_info.connection_state =
+     946                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+     947                 :            : 
+     948                 :          1 :     response_size = sizeof(response);
+     949                 :          1 :     status = libspdm_get_response_capabilities(
+     950                 :            :         spdm_context, m_libspdm_get_capabilities_request15_size,
+     951                 :            :         &m_libspdm_get_capabilities_request15, &response_size, response);
+     952                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     953                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     954                 :          1 :     spdm_response = (void *)response;
+     955                 :          1 :     assert_int_equal(m_libspdm_get_capabilities_request15.header.spdm_version,
+     956                 :            :                      spdm_response->header.spdm_version);
+     957                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     958                 :            :                      SPDM_ERROR);
+     959                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     960                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+     961                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     962                 :          1 : }
+     963                 :            : 
+     964                 :          1 : void libspdm_test_responder_capabilities_case20(void **state)
+     965                 :            : {
+     966                 :            :     libspdm_return_t status;
+     967                 :            :     libspdm_test_context_t *spdm_test_context;
+     968                 :            :     libspdm_context_t *spdm_context;
+     969                 :            :     size_t response_size;
+     970                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     971                 :            :     spdm_capabilities_response_t *spdm_response;
+     972                 :            : 
+     973                 :          1 :     spdm_test_context = *state;
+     974                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     975                 :          1 :     spdm_test_context->case_id = 0x14;
+     976                 :          1 :     spdm_context->connection_info.connection_state =
+     977                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+     978                 :            : 
+     979                 :          1 :     response_size = sizeof(response);
+     980                 :          1 :     status = libspdm_get_response_capabilities(
+     981                 :            :         spdm_context, m_libspdm_get_capabilities_request16_size,
+     982                 :            :         &m_libspdm_get_capabilities_request16, &response_size, response);
+     983                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     984                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     985                 :          1 :     spdm_response = (void *)response;
+     986                 :          1 :     assert_int_equal(m_libspdm_get_capabilities_request16.header.spdm_version,
+     987                 :            :                      spdm_response->header.spdm_version);
+     988                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     989                 :            :                      SPDM_ERROR);
+     990                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     991                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+     992                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     993                 :          1 : }
+     994                 :            : 
+     995                 :          1 : void libspdm_test_responder_capabilities_case21(void **state)
+     996                 :            : {
+     997                 :            :     libspdm_return_t status;
+     998                 :            :     libspdm_test_context_t *spdm_test_context;
+     999                 :            :     libspdm_context_t *spdm_context;
+    1000                 :            :     size_t response_size;
+    1001                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1002                 :            :     spdm_capabilities_response_t *spdm_response;
+    1003                 :            : 
+    1004                 :          1 :     spdm_test_context = *state;
+    1005                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1006                 :          1 :     spdm_test_context->case_id = 0x15;
+    1007                 :          1 :     spdm_context->connection_info.connection_state =
+    1008                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1009                 :            : 
+    1010                 :          1 :     response_size = sizeof(response);
+    1011                 :          1 :     status = libspdm_get_response_capabilities(
+    1012                 :            :         spdm_context, m_libspdm_get_capabilities_request17_size,
+    1013                 :            :         &m_libspdm_get_capabilities_request17, &response_size, response);
+    1014                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1015                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1016                 :          1 :     spdm_response = (void *)response;
+    1017                 :          1 :     assert_int_equal(m_libspdm_get_capabilities_request17.header.spdm_version,
+    1018                 :            :                      spdm_response->header.spdm_version);
+    1019                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1020                 :            :                      SPDM_ERROR);
+    1021                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1022                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+    1023                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1024                 :          1 : }
+    1025                 :            : 
+    1026                 :          1 : void libspdm_test_responder_capabilities_case22(void **state)
+    1027                 :            : {
+    1028                 :            :     libspdm_return_t status;
+    1029                 :            :     libspdm_test_context_t *spdm_test_context;
+    1030                 :            :     libspdm_context_t *spdm_context;
+    1031                 :            :     size_t response_size;
+    1032                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1033                 :            :     spdm_capabilities_response_t *spdm_response;
+    1034                 :            : 
+    1035                 :          1 :     spdm_test_context = *state;
+    1036                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1037                 :          1 :     spdm_test_context->case_id = 0x16;
+    1038                 :          1 :     spdm_context->connection_info.connection_state =
+    1039                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1040                 :            : 
+    1041                 :          1 :     response_size = sizeof(response);
+    1042                 :          1 :     status = libspdm_get_response_capabilities(
+    1043                 :            :         spdm_context, m_libspdm_get_capabilities_request18_size,
+    1044                 :            :         &m_libspdm_get_capabilities_request18, &response_size, response);
+    1045                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1046                 :          1 :     assert_int_equal(response_size, sizeof(spdm_capabilities_response_t) -
+    1047                 :            :                      sizeof(spdm_response->data_transfer_size) -
+    1048                 :            :                      sizeof(spdm_response->max_spdm_msg_size));
+    1049                 :          1 :     spdm_response = (void *)response;
+    1050                 :          1 :     assert_int_equal(m_libspdm_get_capabilities_request18.header.spdm_version,
+    1051                 :            :                      spdm_response->header.spdm_version);
+    1052                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1053                 :            :                      SPDM_CAPABILITIES);
+    1054                 :          1 : }
+    1055                 :            : 
+    1056                 :          1 : void libspdm_test_responder_capabilities_case23(void **state)
+    1057                 :            : {
+    1058                 :            :     libspdm_return_t status;
+    1059                 :            :     libspdm_test_context_t *spdm_test_context;
+    1060                 :            :     libspdm_context_t *spdm_context;
+    1061                 :            :     size_t response_size;
+    1062                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1063                 :            :     spdm_capabilities_response_t *spdm_response;
+    1064                 :            :     size_t arbitrary_size;
+    1065                 :            : 
+    1066                 :          1 :     spdm_test_context = *state;
+    1067                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1068                 :          1 :     spdm_test_context->case_id = 0x17;
+    1069                 :          1 :     spdm_context->connection_info.connection_state =
+    1070                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1071                 :            : 
+    1072                 :            :     /*filling A with arbitrary data*/
+    1073                 :          1 :     arbitrary_size = 10;
+    1074                 :          1 :     libspdm_set_mem(spdm_context->transcript.message_a.buffer, arbitrary_size, (uint8_t) 0xFF);
+    1075                 :          1 :     spdm_context->transcript.message_a.buffer_size = arbitrary_size;
+    1076                 :            : 
+    1077                 :          1 :     response_size = sizeof(response);
+    1078                 :          1 :     status = libspdm_get_response_capabilities(
+    1079                 :            :         spdm_context, m_libspdm_get_capabilities_request4_size,
+    1080                 :            :         &m_libspdm_get_capabilities_request4, &response_size, response);
+    1081                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1082                 :          1 :     assert_int_equal(response_size, sizeof(spdm_capabilities_response_t) -
+    1083                 :            :                      sizeof(spdm_response->data_transfer_size) -
+    1084                 :            :                      sizeof(spdm_response->max_spdm_msg_size));
+    1085                 :          1 :     spdm_response = (void *)response;
+    1086                 :          1 :     assert_int_equal(m_libspdm_get_capabilities_request4.header.spdm_version,
+    1087                 :            :                      spdm_response->header.spdm_version);
+    1088                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_CAPABILITIES);
+    1089                 :            : 
+    1090                 :          1 :     assert_int_equal(spdm_context->transcript.message_a.buffer_size,
+    1091                 :            :                      arbitrary_size + m_libspdm_get_capabilities_request4_size + response_size);
+    1092                 :          1 :     assert_memory_equal(spdm_context->transcript.message_a.buffer + arbitrary_size,
+    1093                 :            :                         &m_libspdm_get_capabilities_request4,
+    1094                 :            :                         m_libspdm_get_capabilities_request4_size);
+    1095                 :          1 :     assert_memory_equal(spdm_context->transcript.message_a.buffer + arbitrary_size +
+    1096                 :            :                         m_libspdm_get_capabilities_request4_size,
+    1097                 :            :                         response, response_size);
+    1098                 :          1 : }
+    1099                 :            : 
+    1100                 :          1 : void libspdm_test_responder_capabilities_case24(void **state)
+    1101                 :            : {
+    1102                 :            :     libspdm_return_t status;
+    1103                 :            :     libspdm_test_context_t *spdm_test_context;
+    1104                 :            :     libspdm_context_t *spdm_context;
+    1105                 :            :     size_t response_size;
+    1106                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1107                 :            :     spdm_capabilities_response_t *spdm_response;
+    1108                 :            : 
+    1109                 :          1 :     spdm_test_context = *state;
+    1110                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1111                 :          1 :     spdm_test_context->case_id = 0x18;
+    1112                 :          1 :     spdm_context->connection_info.connection_state =
+    1113                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1114                 :            : 
+    1115                 :          1 :     response_size = sizeof(response);
+    1116                 :          1 :     status = libspdm_get_response_capabilities(
+    1117                 :            :         spdm_context, m_libspdm_get_capabilities_request19_size,
+    1118                 :            :         &m_libspdm_get_capabilities_request19, &response_size, response);
+    1119                 :          1 :     assert_int_equal(spdm_context->connection_info.capability.max_spdm_msg_size,
+    1120                 :            :                      m_libspdm_get_capabilities_request19.max_spdm_msg_size);
+    1121                 :          1 :     assert_int_equal(spdm_context->connection_info.capability.data_transfer_size,
+    1122                 :            :                      m_libspdm_get_capabilities_request19.data_transfer_size);
+    1123                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1124                 :          1 :     assert_int_equal(response_size, sizeof(spdm_capabilities_response_t));
+    1125                 :          1 :     spdm_response = (void *)response;
+    1126                 :          1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+    1127                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1128                 :            :                      SPDM_CAPABILITIES);
+    1129                 :          1 :     assert_int_equal(spdm_response->data_transfer_size, LIBSPDM_DATA_TRANSFER_SIZE);
+    1130                 :          1 :     assert_int_equal(spdm_response->max_spdm_msg_size, LIBSPDM_MAX_SPDM_MSG_SIZE);
+    1131                 :          1 : }
+    1132                 :            : 
+    1133                 :          1 : void libspdm_test_responder_capabilities_case25(void **state)
+    1134                 :            : {
+    1135                 :            :     libspdm_return_t status;
+    1136                 :            :     libspdm_test_context_t *spdm_test_context;
+    1137                 :            :     libspdm_context_t *spdm_context;
+    1138                 :            :     size_t response_size;
+    1139                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1140                 :            :     spdm_capabilities_response_t *spdm_response;
+    1141                 :            : 
+    1142                 :          1 :     spdm_test_context = *state;
+    1143                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1144                 :          1 :     spdm_test_context->case_id = 0x19;
+    1145                 :          1 :     spdm_context->connection_info.connection_state =
+    1146                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1147                 :            : 
+    1148                 :          1 :     response_size = sizeof(response);
+    1149                 :          1 :     status = libspdm_get_response_capabilities(
+    1150                 :            :         spdm_context, m_libspdm_get_capabilities_request25_size,
+    1151                 :            :         &m_libspdm_get_capabilities_request25, &response_size, response);
+    1152                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1153                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1154                 :          1 :     spdm_response = (void *)response;
+    1155                 :          1 :     assert_int_equal(m_libspdm_get_capabilities_request25.header.spdm_version,
+    1156                 :            :                      spdm_response->header.spdm_version);
+    1157                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1158                 :            :                      SPDM_ERROR);
+    1159                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1160                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+    1161                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1162                 :          1 : }
+    1163                 :            : 
+    1164                 :          1 : void libspdm_test_responder_capabilities_case26(void **state)
+    1165                 :            : {
+    1166                 :            :     libspdm_return_t status;
+    1167                 :            :     libspdm_test_context_t *spdm_test_context;
+    1168                 :            :     libspdm_context_t *spdm_context;
+    1169                 :            :     size_t response_size;
+    1170                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1171                 :            :     spdm_capabilities_response_t *spdm_response;
+    1172                 :            : 
+    1173                 :          1 :     spdm_test_context = *state;
+    1174                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1175                 :          1 :     spdm_test_context->case_id = 0x1A;
+    1176                 :          1 :     spdm_context->connection_info.connection_state =
+    1177                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1178                 :            : 
+    1179                 :          1 :     response_size = sizeof(response);
+    1180                 :          1 :     status = libspdm_get_response_capabilities(
+    1181                 :            :         spdm_context, m_libspdm_get_capabilities_request26_size,
+    1182                 :            :         &m_libspdm_get_capabilities_request26, &response_size, response);
+    1183                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1184                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1185                 :          1 :     spdm_response = (void *)response;
+    1186                 :          1 :     assert_int_equal(m_libspdm_get_capabilities_request26.header.spdm_version,
+    1187                 :            :                      spdm_response->header.spdm_version);
+    1188                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1189                 :            :                      SPDM_ERROR);
+    1190                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1191                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+    1192                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1193                 :          1 : }
+    1194                 :            : 
+    1195                 :          1 : void libspdm_test_responder_capabilities_case27(void **state)
+    1196                 :            : {
+    1197                 :            :     libspdm_return_t status;
+    1198                 :            :     libspdm_test_context_t *spdm_test_context;
+    1199                 :            :     libspdm_context_t *spdm_context;
+    1200                 :            :     size_t response_size;
+    1201                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1202                 :            :     spdm_capabilities_response_t *spdm_response;
+    1203                 :            : 
+    1204                 :          1 :     spdm_test_context = *state;
+    1205                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1206                 :          1 :     spdm_test_context->case_id = 0x1B;
+    1207                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
+    1208                 :            : 
+    1209                 :          1 :     response_size = sizeof(response);
+    1210                 :          1 :     status = libspdm_get_response_capabilities(
+    1211                 :            :         spdm_context, m_libspdm_get_capabilities_request27_size,
+    1212                 :            :         &m_libspdm_get_capabilities_request27, &response_size, response);
+    1213                 :            : 
+    1214                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1215                 :          1 :     assert_int_equal(response_size, sizeof(spdm_capabilities_response_t));
+    1216                 :          1 :     spdm_response = (void *)response;
+    1217                 :          1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_13);
+    1218                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1219                 :            :                      SPDM_CAPABILITIES);
+    1220                 :          1 :     assert_int_equal(spdm_response->data_transfer_size, LIBSPDM_DATA_TRANSFER_SIZE);
+    1221                 :          1 :     assert_int_equal(spdm_response->max_spdm_msg_size, LIBSPDM_MAX_SPDM_MSG_SIZE);
+    1222                 :          1 :     assert_int_equal(spdm_context->connection_info.capability.flags,
+    1223                 :            :                      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MULTI_KEY_CAP_ONLY);
+    1224                 :          1 : }
+    1225                 :            : 
+    1226                 :            : libspdm_test_context_t m_libspdm_responder_capabilities_test_context = {
+    1227                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+    1228                 :            :     false,
+    1229                 :            : };
+    1230                 :            : 
+    1231                 :          1 : int libspdm_responder_capabilities_test_main(void)
+    1232                 :            : {
+    1233                 :          1 :     const struct CMUnitTest spdm_responder_capabilities_tests[] = {
+    1234                 :            :         /* Success Case*/
+    1235                 :            :         cmocka_unit_test(libspdm_test_responder_capabilities_case1),
+    1236                 :            :         /* Success case where request size is larger than actual message. */
+    1237                 :            :         cmocka_unit_test(libspdm_test_responder_capabilities_case2),
+    1238                 :            :         /* response_state: LIBSPDM_RESPONSE_STATE_BUSY*/
+    1239                 :            :         cmocka_unit_test(libspdm_test_responder_capabilities_case3),
+    1240                 :            :         /* response_state: LIBSPDM_RESPONSE_STATE_NEED_RESYNC*/
+    1241                 :            :         cmocka_unit_test(libspdm_test_responder_capabilities_case4),
+    1242                 :            :         /* connection_state Check*/
+    1243                 :            :         cmocka_unit_test(libspdm_test_responder_capabilities_case6),
+    1244                 :            :         /* Invalid requester capabilities flag (random flag)*/
+    1245                 :            :         cmocka_unit_test(libspdm_test_responder_capabilities_case7),
+    1246                 :            :         /* V1.1 Success case, all possible flags set*/
+    1247                 :            :         cmocka_unit_test(libspdm_test_responder_capabilities_case8),
+    1248                 :            :         /* Requester capabilities flag bit 0 is set. reserved value should ne ignored*/
+    1249                 :            :         cmocka_unit_test(libspdm_test_responder_capabilities_case9),
+    1250                 :            :         /* Can be populated with new test. */
+    1251                 :            :         cmocka_unit_test(libspdm_test_responder_capabilities_case10),
+    1252                 :            :         /* Can be populated with new test. */
+    1253                 :            :         cmocka_unit_test(libspdm_test_responder_capabilities_case11),
+    1254                 :            :         /* Can be populated with new test. */
+    1255                 :            :         cmocka_unit_test(libspdm_test_responder_capabilities_case12),
+    1256                 :            :         /* pub_key_id_cap and cert_cap set (flags are mutually exclusive)*/
+    1257                 :            :         cmocka_unit_test(libspdm_test_responder_capabilities_case13),
+    1258                 :            :         /* encrypt_cap set and key_ex_cap and psk_cap cleared (encrypt_cap demands key_ex_cap or psk_cap to be set)*/
+    1259                 :            :         cmocka_unit_test(libspdm_test_responder_capabilities_case14),
+    1260                 :            :         /* mac_cap set and key_ex_cap and psk_cap cleared (mac_cap demands key_ex_cap or psk_cap to be set)*/
+    1261                 :            :         cmocka_unit_test(libspdm_test_responder_capabilities_case15),
+    1262                 :            :         /* key_ex_cap set and encrypt_cap and mac_cap cleared (key_ex_cap demands encrypt_cap or mac_cap to be set)*/
+    1263                 :            :         cmocka_unit_test(libspdm_test_responder_capabilities_case16),
+    1264                 :            :         /* psk_cap set and encrypt_cap and mac_cap cleared (psk_cap demands encrypt_cap or mac_cap to be set)*/
+    1265                 :            :         cmocka_unit_test(libspdm_test_responder_capabilities_case17),
+    1266                 :            :         /* encap_cap cleared and MUT_AUTH set (MUT_AUTH demands encap_cap to be set)*/
+    1267                 :            :         cmocka_unit_test(libspdm_test_responder_capabilities_case18),
+    1268                 :            :         /* cert_cap set and pub_key_id_cap set (pub_key_id_cap demands cert_cap to be cleared)*/
+    1269                 :            :         cmocka_unit_test(libspdm_test_responder_capabilities_case19),
+    1270                 :            :         /* key_ex_cap cleared and handshake_in_the_clear_cap set (handshake_in_the_clear_cap demands key_ex_cap to be set)*/
+    1271                 :            :         cmocka_unit_test(libspdm_test_responder_capabilities_case20),
+    1272                 :            :         /* encrypt_cap and mac_cap cleared and handshake_in_the_clear_cap set (handshake_in_the_clear_cap shall be cleared if encrypt_cap and mac_cap are cleared)*/
+    1273                 :            :         cmocka_unit_test(libspdm_test_responder_capabilities_case21),
+    1274                 :            :         /* cert_cap cleared and pub_key_id_cap set (pub_key_id_cap demands cert_cap to be cleared)*/
+    1275                 :            :         cmocka_unit_test(libspdm_test_responder_capabilities_case22),
+    1276                 :            :         /* Buffer verification*/
+    1277                 :            :         cmocka_unit_test(libspdm_test_responder_capabilities_case23),
+    1278                 :            :         /* V1.2 Success case, all possible flags set*/
+    1279                 :            :         cmocka_unit_test(libspdm_test_responder_capabilities_case24),
+    1280                 :            :         /* CHUNK_CAP == 0 and data_transfer_size != max_spdm_msg_size should result in error. */
+    1281                 :            :         cmocka_unit_test(libspdm_test_responder_capabilities_case25),
+    1282                 :            :         /* MaxSPDMmsgSize is less than DataTransferSize, then should result in error. */
+    1283                 :            :         cmocka_unit_test(libspdm_test_responder_capabilities_case26),
+    1284                 :            :         /* Success Case , capability supports MULTI_KEY_CAP */
+    1285                 :            :         cmocka_unit_test(libspdm_test_responder_capabilities_case27),
+    1286                 :            :     };
+    1287                 :            : 
+    1288                 :          1 :     libspdm_setup_test_context(&m_libspdm_responder_capabilities_test_context);
+    1289                 :            : 
+    1290                 :          1 :     return cmocka_run_group_tests(spdm_responder_capabilities_tests,
+    1291                 :            :                                   libspdm_unit_test_group_setup,
+    1292                 :            :                                   libspdm_unit_test_group_teardown);
+    1293                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/certificate.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_responder/certificate.c.func-sort-c.html new file mode 100644 index 00000000000..e20d87e2526 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/certificate.c.func-sort-c.html @@ -0,0 +1,157 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/certificate.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - certificate.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:48549498.2 %
Date:2024-09-22 08:21:07Functions:1919100.0 %
Branches:293876.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_certificate_test_main1
libspdm_test_responder_certificate_case11
libspdm_test_responder_certificate_case101
libspdm_test_responder_certificate_case111
libspdm_test_responder_certificate_case121
libspdm_test_responder_certificate_case131
libspdm_test_responder_certificate_case141
libspdm_test_responder_certificate_case151
libspdm_test_responder_certificate_case161
libspdm_test_responder_certificate_case171
libspdm_test_responder_certificate_case181
libspdm_test_responder_certificate_case21
libspdm_test_responder_certificate_case31
libspdm_test_responder_certificate_case41
libspdm_test_responder_certificate_case51
libspdm_test_responder_certificate_case61
libspdm_test_responder_certificate_case71
libspdm_test_responder_certificate_case81
libspdm_test_responder_certificate_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/certificate.c.func.html b/coverage_log/unit_test/test_spdm_responder/certificate.c.func.html new file mode 100644 index 00000000000..5cc153cdbce --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/certificate.c.func.html @@ -0,0 +1,157 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/certificate.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - certificate.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:48549498.2 %
Date:2024-09-22 08:21:07Functions:1919100.0 %
Branches:293876.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_certificate_test_main1
libspdm_test_responder_certificate_case11
libspdm_test_responder_certificate_case101
libspdm_test_responder_certificate_case111
libspdm_test_responder_certificate_case121
libspdm_test_responder_certificate_case131
libspdm_test_responder_certificate_case141
libspdm_test_responder_certificate_case151
libspdm_test_responder_certificate_case161
libspdm_test_responder_certificate_case171
libspdm_test_responder_certificate_case181
libspdm_test_responder_certificate_case21
libspdm_test_responder_certificate_case31
libspdm_test_responder_certificate_case41
libspdm_test_responder_certificate_case51
libspdm_test_responder_certificate_case61
libspdm_test_responder_certificate_case71
libspdm_test_responder_certificate_case81
libspdm_test_responder_certificate_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/certificate.c.gcov.html b/coverage_log/unit_test/test_spdm_responder/certificate.c.gcov.html new file mode 100644 index 00000000000..2b3ffdc2ed0 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/certificate.c.gcov.html @@ -0,0 +1,1467 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/certificate.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - certificate.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:48549498.2 %
Date:2024-09-22 08:21:07Functions:1919100.0 %
Branches:293876.3 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_responder_lib.h"
+       9                 :            : 
+      10                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CERT_CAP
+      11                 :            : 
+      12                 :            : /* #define TEST_LIBSPDM_DEBUG*/
+      13                 :            : #ifdef TEST_LIBSPDM_DEBUG
+      14                 :            : #define TEST_LIBSPDM_DEBUG_PRINT(format, ...) printf(format, ## __VA_ARGS__)
+      15                 :            : #else
+      16                 :            : #define TEST_LIBSPDM_DEBUG_PRINT(...)
+      17                 :            : #endif
+      18                 :            : 
+      19                 :            : spdm_get_certificate_request_t m_libspdm_get_certificate_request1 = {
+      20                 :            :     { SPDM_MESSAGE_VERSION_10, SPDM_GET_CERTIFICATE, 0, 0 },
+      21                 :            :     0,
+      22                 :            :     LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN
+      23                 :            : };
+      24                 :            : size_t m_libspdm_get_certificate_request1_size = sizeof(m_libspdm_get_certificate_request1);
+      25                 :            : 
+      26                 :            : spdm_get_certificate_request_t m_libspdm_get_certificate_request3 = {
+      27                 :            :     { SPDM_MESSAGE_VERSION_10, SPDM_GET_CERTIFICATE, 0, 0 },
+      28                 :            :     0,
+      29                 :            :     0
+      30                 :            : };
+      31                 :            : size_t m_libspdm_get_certificate_request3_size = sizeof(m_libspdm_get_certificate_request3);
+      32                 :            : 
+      33                 :            : spdm_get_certificate_request_t m_libspdm_get_certificate_request4 = {
+      34                 :            :     { SPDM_MESSAGE_VERSION_10, SPDM_GET_CERTIFICATE, 9, 0 },
+      35                 :            :     0,
+      36                 :            :     LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN
+      37                 :            : };
+      38                 :            : size_t m_libspdm_get_certificate_request4_size = sizeof(m_libspdm_get_certificate_request4);
+      39                 :            : 
+      40                 :            : spdm_get_certificate_request_t m_libspdm_get_certificate_request5 = {
+      41                 :            :     { SPDM_MESSAGE_VERSION_13, SPDM_GET_CERTIFICATE, 0, 0 },
+      42                 :            :     0,
+      43                 :            :     LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN
+      44                 :            : };
+      45                 :            : size_t m_libspdm_get_certificate_request5_size = sizeof(m_libspdm_get_certificate_request5);
+      46                 :            : /**
+      47                 :            :  * Test 1: request the first LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN bytes of the certificate chain
+      48                 :            :  * Expected Behavior: generate a correctly formed Certficate message, including its portion_length and remainder_length fields
+      49                 :            :  **/
+      50                 :          1 : void libspdm_test_responder_certificate_case1(void **state)
+      51                 :            : {
+      52                 :            :     libspdm_return_t status;
+      53                 :            :     libspdm_test_context_t *spdm_test_context;
+      54                 :            :     libspdm_context_t *spdm_context;
+      55                 :            :     size_t response_size;
+      56                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+      57                 :            :     spdm_certificate_response_t *spdm_response;
+      58                 :            :     void *data;
+      59                 :            :     size_t data_size;
+      60                 :            : 
+      61                 :          1 :     spdm_test_context = *state;
+      62                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+      63                 :          1 :     spdm_test_context->case_id = 0x1;
+      64                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+      65                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+      66                 :          1 :     spdm_context->connection_info.connection_state =
+      67                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_DIGESTS;
+      68                 :          1 :     spdm_context->local_context.capability.flags |=
+      69                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+      70                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+      71                 :            :         m_libspdm_use_hash_algo;
+      72                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+      73                 :            :                                                     m_libspdm_use_asym_algo, &data,
+      74                 :            :                                                     &data_size, NULL, NULL);
+      75                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+      76                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+      77                 :            :         data_size;
+      78                 :            : 
+      79                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+      80                 :            :     spdm_context->transcript.message_m.buffer_size =
+      81                 :            :         spdm_context->transcript.message_m.max_buffer_size;
+      82                 :            : #endif
+      83                 :            : 
+      84                 :          1 :     response_size = sizeof(response);
+      85                 :          1 :     status = libspdm_get_response_certificate(
+      86                 :            :         spdm_context, m_libspdm_get_certificate_request1_size,
+      87                 :            :         &m_libspdm_get_certificate_request1, &response_size, response);
+      88                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+      89                 :          1 :     assert_int_equal(response_size, sizeof(spdm_certificate_response_t) +
+      90                 :            :                      LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN);
+      91                 :          1 :     spdm_response = (void *)response;
+      92                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+      93                 :            :                      SPDM_CERTIFICATE);
+      94                 :          1 :     assert_int_equal(spdm_response->header.param1, 0);
+      95                 :          1 :     assert_int_equal(spdm_response->portion_length,
+      96                 :            :                      LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN);
+      97                 :          1 :     assert_int_equal(spdm_response->remainder_length,
+      98                 :            :                      data_size - LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN);
+      99                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     100                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
+     101                 :            :                      0);
+     102                 :            : #endif
+     103                 :          1 :     free(data);
+     104                 :          1 : }
+     105                 :            : 
+     106                 :            : /**
+     107                 :            :  * Test 2:
+     108                 :            :  * Expected Behavior:
+     109                 :            :  **/
+     110                 :          1 : void libspdm_test_responder_certificate_case2(void **state)
+     111                 :            : {
+     112                 :          1 : }
+     113                 :            : 
+     114                 :            : /**
+     115                 :            :  * Test 3: Force response_state = LIBSPDM_RESPONSE_STATE_BUSY when asked GET_CERTIFICATE
+     116                 :            :  * Expected Behavior: generate an ERROR_RESPONSE with code SPDM_ERROR_CODE_BUSY
+     117                 :            :  **/
+     118                 :          1 : void libspdm_test_responder_certificate_case3(void **state)
+     119                 :            : {
+     120                 :            :     libspdm_return_t status;
+     121                 :            :     libspdm_test_context_t *spdm_test_context;
+     122                 :            :     libspdm_context_t *spdm_context;
+     123                 :            :     size_t response_size;
+     124                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     125                 :            :     spdm_certificate_response_t *spdm_response;
+     126                 :            :     void *data;
+     127                 :            :     size_t data_size;
+     128                 :            : 
+     129                 :          1 :     spdm_test_context = *state;
+     130                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     131                 :          1 :     spdm_test_context->case_id = 0x3;
+     132                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+     133                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     134                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_BUSY;
+     135                 :          1 :     spdm_context->connection_info.connection_state =
+     136                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_DIGESTS;
+     137                 :          1 :     spdm_context->local_context.capability.flags |=
+     138                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     139                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     140                 :            :         m_libspdm_use_hash_algo;
+     141                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     142                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     143                 :            :                                                     &data_size, NULL, NULL);
+     144                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     145                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     146                 :            :         data_size;
+     147                 :            : 
+     148                 :          1 :     response_size = sizeof(response);
+     149                 :          1 :     status = libspdm_get_response_certificate(
+     150                 :            :         spdm_context, m_libspdm_get_certificate_request1_size,
+     151                 :            :         &m_libspdm_get_certificate_request1, &response_size, response);
+     152                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     153                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     154                 :          1 :     spdm_response = (void *)response;
+     155                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     156                 :            :                      SPDM_ERROR);
+     157                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_BUSY);
+     158                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     159                 :          1 :     assert_int_equal(spdm_context->response_state,
+     160                 :            :                      LIBSPDM_RESPONSE_STATE_BUSY);
+     161                 :          1 :     free(data);
+     162                 :          1 : }
+     163                 :            : 
+     164                 :            : /**
+     165                 :            :  * Test 4: Force response_state = LIBSPDM_RESPONSE_STATE_NEED_RESYNC when asked GET_CERTIFICATE
+     166                 :            :  * Expected Behavior: generate an ERROR_RESPONSE with code SPDM_ERROR_CODE_REQUEST_RESYNCH
+     167                 :            :  **/
+     168                 :          1 : void libspdm_test_responder_certificate_case4(void **state)
+     169                 :            : {
+     170                 :            :     libspdm_return_t status;
+     171                 :            :     libspdm_test_context_t *spdm_test_context;
+     172                 :            :     libspdm_context_t *spdm_context;
+     173                 :            :     size_t response_size;
+     174                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     175                 :            :     spdm_certificate_response_t *spdm_response;
+     176                 :            :     void *data;
+     177                 :            :     size_t data_size;
+     178                 :            : 
+     179                 :          1 :     spdm_test_context = *state;
+     180                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     181                 :          1 :     spdm_test_context->case_id = 0x4;
+     182                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+     183                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     184                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NEED_RESYNC;
+     185                 :          1 :     spdm_context->connection_info.connection_state =
+     186                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_DIGESTS;
+     187                 :          1 :     spdm_context->local_context.capability.flags |=
+     188                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     189                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     190                 :            :         m_libspdm_use_hash_algo;
+     191                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     192                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     193                 :            :                                                     &data_size, NULL, NULL);
+     194                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     195                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     196                 :            :         data_size;
+     197                 :            : 
+     198                 :          1 :     response_size = sizeof(response);
+     199                 :          1 :     status = libspdm_get_response_certificate(
+     200                 :            :         spdm_context, m_libspdm_get_certificate_request1_size,
+     201                 :            :         &m_libspdm_get_certificate_request1, &response_size, response);
+     202                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     203                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     204                 :          1 :     spdm_response = (void *)response;
+     205                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     206                 :            :                      SPDM_ERROR);
+     207                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     208                 :            :                      SPDM_ERROR_CODE_REQUEST_RESYNCH);
+     209                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     210                 :          1 :     assert_int_equal(spdm_context->response_state,
+     211                 :            :                      LIBSPDM_RESPONSE_STATE_NEED_RESYNC);
+     212                 :          1 :     free(data);
+     213                 :          1 : }
+     214                 :            : 
+     215                 :            : #if LIBSPDM_RESPOND_IF_READY_SUPPORT
+     216                 :            : /**
+     217                 :            :  * Test 5: Force response_state = LIBSPDM_RESPONSE_STATE_NOT_READY when asked GET_CERTIFICATE
+     218                 :            :  * Expected Behavior: generate an ERROR_RESPONSE with code SPDM_ERROR_CODE_RESPONSE_NOT_READY and correct error_data
+     219                 :            :  **/
+     220                 :          1 : void libspdm_test_responder_certificate_case5(void **state)
+     221                 :            : {
+     222                 :            :     libspdm_return_t status;
+     223                 :            :     libspdm_test_context_t *spdm_test_context;
+     224                 :            :     libspdm_context_t *spdm_context;
+     225                 :            :     size_t response_size;
+     226                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     227                 :            :     spdm_certificate_response_t *spdm_response;
+     228                 :            :     void *data;
+     229                 :            :     size_t data_size;
+     230                 :            :     spdm_error_data_response_not_ready_t *error_data;
+     231                 :            : 
+     232                 :          1 :     spdm_test_context = *state;
+     233                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     234                 :          1 :     spdm_test_context->case_id = 0x5;
+     235                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+     236                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     237                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NOT_READY;
+     238                 :          1 :     spdm_context->connection_info.connection_state =
+     239                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_DIGESTS;
+     240                 :          1 :     spdm_context->local_context.capability.flags |=
+     241                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     242                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     243                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     244                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     245                 :            :                                                     &data_size, NULL, NULL);
+     246                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     247                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
+     248                 :            : 
+     249                 :          1 :     response_size = sizeof(response);
+     250                 :          1 :     status = libspdm_get_response_certificate(
+     251                 :            :         spdm_context, m_libspdm_get_certificate_request1_size,
+     252                 :            :         &m_libspdm_get_certificate_request1, &response_size, response);
+     253                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     254                 :          1 :     assert_int_equal(response_size,
+     255                 :            :                      sizeof(spdm_error_response_t) +
+     256                 :            :                      sizeof(spdm_error_data_response_not_ready_t));
+     257                 :          1 :     spdm_response = (void *)response;
+     258                 :          1 :     error_data = (spdm_error_data_response_not_ready_t
+     259                 :            :                   *)(&spdm_response->portion_length);
+     260                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     261                 :            :                      SPDM_ERROR);
+     262                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     263                 :            :                      SPDM_ERROR_CODE_RESPONSE_NOT_READY);
+     264                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     265                 :          1 :     assert_int_equal(spdm_context->response_state,
+     266                 :            :                      LIBSPDM_RESPONSE_STATE_NOT_READY);
+     267                 :          1 :     assert_int_equal(error_data->request_code, SPDM_GET_CERTIFICATE);
+     268                 :          1 :     free(data);
+     269                 :          1 : }
+     270                 :            : #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
+     271                 :            : 
+     272                 :            : /**
+     273                 :            :  * Test 6: simulate wrong connection_state when asked GET_CERTIFICATE (missing SPDM_GET_DIGESTS_RECEIVE_FLAG and SPDM_GET_CAPABILITIES_RECEIVE_FLAG)
+     274                 :            :  * Expected Behavior: generate an ERROR_RESPONSE with code SPDM_ERROR_CODE_UNEXPECTED_REQUEST
+     275                 :            :  **/
+     276                 :          1 : void libspdm_test_responder_certificate_case6(void **state)
+     277                 :            : {
+     278                 :            :     libspdm_return_t status;
+     279                 :            :     libspdm_test_context_t *spdm_test_context;
+     280                 :            :     libspdm_context_t *spdm_context;
+     281                 :            :     size_t response_size;
+     282                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     283                 :            :     spdm_certificate_response_t *spdm_response;
+     284                 :            :     void *data;
+     285                 :            :     size_t data_size;
+     286                 :            : 
+     287                 :          1 :     spdm_test_context = *state;
+     288                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     289                 :          1 :     spdm_test_context->case_id = 0x6;
+     290                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+     291                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     292                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+     293                 :          1 :     spdm_context->connection_info.connection_state =
+     294                 :            :         LIBSPDM_CONNECTION_STATE_NOT_STARTED;
+     295                 :          1 :     spdm_context->local_context.capability.flags |=
+     296                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     297                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     298                 :            :         m_libspdm_use_hash_algo;
+     299                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     300                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     301                 :            :                                                     &data_size, NULL, NULL);
+     302                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     303                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     304                 :            :         data_size;
+     305                 :            : 
+     306                 :            : 
+     307                 :          1 :     response_size = sizeof(response);
+     308                 :          1 :     status = libspdm_get_response_certificate(
+     309                 :            :         spdm_context, m_libspdm_get_certificate_request1_size,
+     310                 :            :         &m_libspdm_get_certificate_request1, &response_size, response);
+     311                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     312                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     313                 :          1 :     spdm_response = (void *)response;
+     314                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     315                 :            :                      SPDM_ERROR);
+     316                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     317                 :            :                      SPDM_ERROR_CODE_UNEXPECTED_REQUEST);
+     318                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     319                 :          1 :     free(data);
+     320                 :          1 : }
+     321                 :            : 
+     322                 :            : /**
+     323                 :            :  * Test 7: request length at the boundary of maximum integer values, while keeping offset 0
+     324                 :            :  * Expected Behavior: generate correctly formed Certficate messages, including its portion_length and remainder_length fields
+     325                 :            :  **/
+     326                 :          1 : void libspdm_test_responder_certificate_case7(void **state)
+     327                 :            : {
+     328                 :            :     libspdm_return_t status;
+     329                 :            :     libspdm_test_context_t *spdm_test_context;
+     330                 :            :     libspdm_context_t *spdm_context;
+     331                 :            :     size_t response_size;
+     332                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     333                 :            :     spdm_certificate_response_t *spdm_response;
+     334                 :            :     void *data;
+     335                 :            :     size_t data_size;
+     336                 :            : 
+     337                 :            :     /* Testing Lengths at the boundary of maximum integer values*/
+     338                 :          1 :     uint16_t test_lengths[] = {
+     339                 :            :         1,        0x7F,     (uint16_t)(0x7F + 1),
+     340                 :            :         0xFF,  0x7FFF,     (uint16_t)(0x7FFF + 1),
+     341                 :            :         0xFFFF, (uint16_t)(-1)
+     342                 :            :     };
+     343                 :            :     uint16_t expected_chunk_size;
+     344                 :            : 
+     345                 :            :     /* Setting up the spdm_context and loading a sample certificate chain*/
+     346                 :          1 :     spdm_test_context = *state;
+     347                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     348                 :          1 :     spdm_test_context->case_id = 0x7;
+     349                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+     350                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     351                 :          1 :     spdm_context->connection_info.connection_state =
+     352                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_DIGESTS;
+     353                 :          1 :     spdm_context->local_context.capability.flags |=
+     354                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     355                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     356                 :            :         m_libspdm_use_hash_algo;
+     357                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     358                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     359                 :            :                                                     &data_size, NULL, NULL);
+     360                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     361                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     362                 :            :         data_size;
+     363                 :            : 
+     364                 :            :     /* This tests considers only offset = 0, other tests vary offset value*/
+     365                 :          1 :     m_libspdm_get_certificate_request3.offset = 0;
+     366                 :            : 
+     367         [ +  + ]:          9 :     for (int i = 0; i < sizeof(test_lengths) / sizeof(test_lengths[0]); i++) {
+     368                 :            :         TEST_LIBSPDM_DEBUG_PRINT("i:%d test_lengths[i]:%u\n", i, test_lengths[i]);
+     369                 :          8 :         m_libspdm_get_certificate_request3.length = test_lengths[i];
+     370                 :            :         /* Expected received length is limited by LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN (implementation specific?)*/
+     371                 :          8 :         expected_chunk_size = LIBSPDM_MIN(m_libspdm_get_certificate_request3.length,
+     372                 :            :                                           LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN);
+     373                 :            : 
+     374                 :            :         /* reseting an internal buffer to avoid overflow and prevent tests to succeed*/
+     375                 :          8 :         libspdm_reset_message_b(spdm_context);
+     376                 :          8 :         response_size = sizeof(response);
+     377                 :          8 :         status = libspdm_get_response_certificate(
+     378                 :            :             spdm_context, m_libspdm_get_certificate_request3_size,
+     379                 :            :             &m_libspdm_get_certificate_request3, &response_size,
+     380                 :            :             response);
+     381                 :          8 :         assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     382                 :          8 :         assert_int_equal(response_size,
+     383                 :            :                          sizeof(spdm_certificate_response_t) +
+     384                 :            :                          expected_chunk_size);
+     385                 :          8 :         spdm_response = (void *)response;
+     386                 :          8 :         assert_int_equal(spdm_response->header.request_response_code,
+     387                 :            :                          SPDM_CERTIFICATE);
+     388                 :          8 :         assert_int_equal(spdm_response->header.param1, 0);
+     389                 :          8 :         assert_int_equal(spdm_response->portion_length,
+     390                 :            :                          expected_chunk_size);
+     391                 :          8 :         assert_int_equal(spdm_response->remainder_length,
+     392                 :            :                          data_size - expected_chunk_size);
+     393                 :            :     }
+     394                 :          1 :     free(data);
+     395                 :          1 : }
+     396                 :            : 
+     397                 :            : /**
+     398                 :            :  * Test 8: request offset at the boundary of maximum integer values, while keeping length 0
+     399                 :            :  * Expected Behavior: generate correctly formed Certficate messages, including its portion_length and remainder_length fields
+     400                 :            :  **/
+     401                 :          1 : void libspdm_test_responder_certificate_case8(void **state)
+     402                 :            : {
+     403                 :            :     libspdm_return_t status;
+     404                 :            :     libspdm_test_context_t *spdm_test_context;
+     405                 :            :     libspdm_context_t *spdm_context;
+     406                 :            :     size_t response_size;
+     407                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     408                 :            :     spdm_certificate_response_t *spdm_response;
+     409                 :            :     spdm_error_response_t *spdm_responseError;
+     410                 :            :     void *data;
+     411                 :            :     size_t data_size;
+     412                 :            : 
+     413                 :            :     /* Testing offsets at the boundary of maximum integer values and at the boundary of certificate length (first three positions)*/
+     414                 :          1 :     uint16_t test_offsets[] = { (uint16_t)(-1),
+     415                 :            :                                 0,
+     416                 :            :                                 +1,
+     417                 :            :                                 0,
+     418                 :            :                                 0x7F,
+     419                 :            :                                 (uint16_t)(0x7F + 1),
+     420                 :            :                                 0xFF,
+     421                 :            :                                 0x7FFF,
+     422                 :            :                                 (uint16_t)(0x7FFF + 1),
+     423                 :            :                                 0xFFFF,
+     424                 :            :                                 (uint16_t)(-1) };
+     425                 :            : 
+     426                 :            :     /* Setting up the spdm_context and loading a sample certificate chain*/
+     427                 :          1 :     spdm_test_context = *state;
+     428                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     429                 :          1 :     spdm_test_context->case_id = 0x8;
+     430                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+     431                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     432                 :          1 :     spdm_context->connection_info.connection_state =
+     433                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_DIGESTS;
+     434                 :          1 :     spdm_context->local_context.capability.flags |=
+     435                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     436                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     437                 :            :         m_libspdm_use_hash_algo;
+     438                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     439                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     440                 :            :                                                     &data_size, NULL, NULL);
+     441                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     442                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     443                 :            :         data_size;
+     444                 :            : 
+     445                 :            :     /* This tests considers only length = 1, other tests vary length value*/
+     446                 :          1 :     m_libspdm_get_certificate_request3.length = 1;
+     447                 :            :     /* Setting up offset values at the boundary of certificate length*/
+     448                 :          1 :     test_offsets[0] = (uint16_t)(test_offsets[0] + data_size);
+     449                 :          1 :     test_offsets[1] = (uint16_t)(test_offsets[1] + data_size);
+     450                 :          1 :     test_offsets[2] = (uint16_t)(test_offsets[2] + data_size);
+     451                 :            : 
+     452         [ +  + ]:         12 :     for (int i = 0; i < sizeof(test_offsets) / sizeof(test_offsets[0]); i++) {
+     453                 :            :         TEST_LIBSPDM_DEBUG_PRINT("i:%d test_offsets[i]:%u\n", i, test_offsets[i]);
+     454                 :         11 :         m_libspdm_get_certificate_request3.offset = test_offsets[i];
+     455                 :            : 
+     456                 :            :         /* reseting an internal buffer to avoid overflow and prevent tests to succeed*/
+     457                 :         11 :         libspdm_reset_message_b(spdm_context);
+     458                 :         11 :         response_size = sizeof(response);
+     459                 :         11 :         status = libspdm_get_response_certificate(
+     460                 :            :             spdm_context, m_libspdm_get_certificate_request3_size,
+     461                 :            :             &m_libspdm_get_certificate_request3, &response_size,
+     462                 :            :             response);
+     463                 :         11 :         assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     464                 :            : 
+     465         [ +  + ]:         11 :         if (m_libspdm_get_certificate_request3.offset >= data_size) {
+     466                 :            :             /* A too long of an offset should return an error*/
+     467                 :          6 :             spdm_responseError = (void *)response;
+     468                 :          6 :             assert_int_equal(
+     469                 :            :                 spdm_responseError->header.request_response_code,
+     470                 :            :                 SPDM_ERROR);
+     471                 :          6 :             assert_int_equal(spdm_responseError->header.param1,
+     472                 :            :                              SPDM_ERROR_CODE_INVALID_REQUEST);
+     473                 :            :         } else {
+     474                 :            :             /* Otherwise it should work properly, considering length = 1*/
+     475                 :          5 :             assert_int_equal(response_size,
+     476                 :            :                              sizeof(spdm_certificate_response_t) + 1);
+     477                 :          5 :             spdm_response = (void *)response;
+     478                 :          5 :             assert_int_equal(
+     479                 :            :                 spdm_response->header.request_response_code,
+     480                 :            :                 SPDM_CERTIFICATE);
+     481                 :          5 :             assert_int_equal(spdm_response->header.param1, 0);
+     482                 :          5 :             assert_int_equal(spdm_response->portion_length, 1);
+     483                 :          5 :             assert_int_equal(
+     484                 :            :                 spdm_response->remainder_length + 1,
+     485                 :            :                 (uint16_t)(
+     486                 :            :                     data_size -
+     487                 :            :                     m_libspdm_get_certificate_request3.offset));
+     488                 :            :         }
+     489                 :            :     }
+     490                 :          1 :     free(data);
+     491                 :          1 : }
+     492                 :            : 
+     493                 :            : /**
+     494                 :            :  * Test 9: request offset and length at the boundary of maximum integer values
+     495                 :            :  * Expected Behavior: generate correctly formed Certficate messages, including its portion_length and remainder_length fields
+     496                 :            :  **/
+     497                 :          1 : void libspdm_test_responder_certificate_case9(void **state)
+     498                 :            : {
+     499                 :            :     libspdm_return_t status;
+     500                 :            :     libspdm_test_context_t *spdm_test_context;
+     501                 :            :     libspdm_context_t *spdm_context;
+     502                 :            :     size_t response_size;
+     503                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     504                 :            :     spdm_certificate_response_t *spdm_response;
+     505                 :            :     spdm_error_response_t *spdm_responseError;
+     506                 :            :     void *data;
+     507                 :            :     size_t data_size;
+     508                 :            : 
+     509                 :            :     /* Testing offsets and length combinations
+     510                 :            :      * Check at the boundary of maximum integer values and at the boundary of certificate length*/
+     511                 :          1 :     uint16_t test_sizes[] = {
+     512                 :            :         (uint16_t)(-1),
+     513                 :            :         0,
+     514                 :            :         +1, /* reserved for sizes around the certificate chain size*/
+     515                 :            :         (uint16_t)(-1),
+     516                 :            :         +1,
+     517                 :            :         (uint16_t)(0x7F - 1),
+     518                 :            :         0x7F,
+     519                 :            :         (uint16_t)(0x7F + 1),
+     520                 :            :         (uint16_t)(0xFF - 1),
+     521                 :            :         0xFF,
+     522                 :            :         (uint16_t)(0x7FFF - 1),
+     523                 :            :         0x7FFF,
+     524                 :            :         (uint16_t)(0x7FFF + 1),
+     525                 :            :         (uint16_t)(0xFFFF - 1),
+     526                 :            :         0xFFFF
+     527                 :            :     };
+     528                 :            :     uint16_t expected_chunk_size;
+     529                 :            :     uint16_t expected_remainder;
+     530                 :            : 
+     531                 :            :     /* Setting up the spdm_context and loading a sample certificate chain*/
+     532                 :          1 :     spdm_test_context = *state;
+     533                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     534                 :          1 :     spdm_test_context->case_id = 0x9;
+     535                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+     536                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     537                 :          1 :     spdm_context->connection_info.connection_state =
+     538                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_DIGESTS;
+     539                 :          1 :     spdm_context->local_context.capability.flags |=
+     540                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     541                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     542                 :            :         m_libspdm_use_hash_algo;
+     543                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     544                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     545                 :            :                                                     &data_size, NULL, NULL);
+     546                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     547                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     548                 :            :         data_size;
+     549                 :            : 
+     550                 :            :     /* Setting up offset values at the boundary of certificate length*/
+     551                 :          1 :     test_sizes[0] += (uint16_t)(test_sizes[0] + data_size);
+     552                 :          1 :     test_sizes[1] += (uint16_t)(test_sizes[1] + data_size);
+     553                 :          1 :     test_sizes[2] += (uint16_t)(test_sizes[2] + data_size);
+     554                 :            : 
+     555         [ +  + ]:         16 :     for (int i = 0; i < sizeof(test_sizes) / sizeof(test_sizes[0]); i++) {
+     556                 :            :         TEST_LIBSPDM_DEBUG_PRINT("i:%d test_sizes[i]=length:%u\n", i,
+     557                 :            :                                  test_sizes[i]);
+     558                 :         15 :         m_libspdm_get_certificate_request3.length = test_sizes[i];
+     559         [ +  + ]:        240 :         for (int j = 0; j < sizeof(test_sizes) / sizeof(test_sizes[0]);
+     560                 :        225 :              j++) {
+     561                 :            :             TEST_LIBSPDM_DEBUG_PRINT("\tj:%d test_sizes[j]=offset:%u\n", j,
+     562                 :            :                                      test_sizes[j]);
+     563                 :        225 :             m_libspdm_get_certificate_request3.offset = test_sizes[j];
+     564                 :            : 
+     565                 :            :             /* reseting an internal buffer to avoid overflow and prevent tests to succeed*/
+     566                 :        225 :             libspdm_reset_message_b(spdm_context);
+     567                 :        225 :             response_size = sizeof(response);
+     568                 :        225 :             status = libspdm_get_response_certificate(
+     569                 :            :                 spdm_context,
+     570                 :            :                 m_libspdm_get_certificate_request3_size,
+     571                 :            :                 &m_libspdm_get_certificate_request3,
+     572                 :            :                 &response_size, response);
+     573                 :        225 :             assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     574                 :            : 
+     575         [ +  + ]:        225 :             if (m_libspdm_get_certificate_request3.offset >=
+     576                 :            :                 data_size) {
+     577                 :            :                 /* A too long of an offset should return an error*/
+     578                 :        120 :                 spdm_responseError = (void *)response;
+     579                 :        120 :                 assert_int_equal(spdm_responseError->header
+     580                 :            :                                  .request_response_code,
+     581                 :            :                                  SPDM_ERROR);
+     582                 :        120 :                 assert_int_equal(
+     583                 :            :                     spdm_responseError->header.param1,
+     584                 :            :                     SPDM_ERROR_CODE_INVALID_REQUEST);
+     585                 :            :             } else {
+     586                 :            :                 /* Otherwise it should work properly*/
+     587                 :            : 
+     588                 :            :                 /* Expected received length is limited by LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN and by the remaining length*/
+     589         [ +  + ]:        105 :                 expected_chunk_size = (uint16_t)(LIBSPDM_MIN(
+     590                 :            :                                                      m_libspdm_get_certificate_request3.length,
+     591                 :            :                                                      data_size -
+     592                 :            :                                                      m_libspdm_get_certificate_request3
+     593                 :            :                                                      .offset));
+     594                 :        105 :                 expected_chunk_size =
+     595                 :            :                     LIBSPDM_MIN(expected_chunk_size,
+     596                 :            :                                 LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN);
+     597                 :            :                 /* Expected certificate length left*/
+     598                 :        105 :                 expected_remainder = (uint16_t)(
+     599                 :        105 :                     data_size -
+     600                 :        105 :                     m_libspdm_get_certificate_request3.offset -
+     601                 :            :                     expected_chunk_size);
+     602                 :            : 
+     603                 :        105 :                 assert_int_equal(
+     604                 :            :                     response_size,
+     605                 :            :                     sizeof(spdm_certificate_response_t) +
+     606                 :            :                     expected_chunk_size);
+     607                 :        105 :                 spdm_response = (void *)response;
+     608                 :        105 :                 assert_int_equal(spdm_response->header
+     609                 :            :                                  .request_response_code,
+     610                 :            :                                  SPDM_CERTIFICATE);
+     611                 :        105 :                 assert_int_equal(spdm_response->header.param1,
+     612                 :            :                                  0);
+     613                 :        105 :                 assert_int_equal(spdm_response->portion_length,
+     614                 :            :                                  expected_chunk_size);
+     615                 :        105 :                 assert_int_equal(
+     616                 :            :                     spdm_response->remainder_length,
+     617                 :            :                     expected_remainder);
+     618                 :            :             }
+     619                 :            :         }
+     620                 :            :     }
+     621                 :          1 :     free(data);
+     622                 :          1 : }
+     623                 :            : 
+     624                 :            : /**
+     625                 :            :  * Test 10: request LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN bytes of long certificate chains, with the largest valid offset
+     626                 :            :  * Expected Behavior: generate correctly formed Certficate messages, including its portion_length and remainder_length fields
+     627                 :            :  **/
+     628                 :          1 : void libspdm_test_responder_certificate_case10(void **state)
+     629                 :            : {
+     630                 :            :     libspdm_return_t status;
+     631                 :            :     libspdm_test_context_t *spdm_test_context;
+     632                 :            :     libspdm_context_t *spdm_context;
+     633                 :            :     size_t response_size;
+     634                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     635                 :            :     spdm_certificate_response_t *spdm_response;
+     636                 :            :     spdm_error_response_t *spdm_responseError;
+     637                 :            :     void *data;
+     638                 :            :     size_t data_size;
+     639                 :            : 
+     640                 :          1 :     uint16_t test_cases[] = { LIBSPDM_TEST_CERT_MAXINT16, LIBSPDM_TEST_CERT_MAXUINT16 };
+     641                 :            : 
+     642                 :            :     size_t expected_chunk_size;
+     643                 :            :     size_t expected_remainder;
+     644                 :            : 
+     645                 :            :     /* Setting up the spdm_context and loading a sample certificate chain*/
+     646                 :          1 :     spdm_test_context = *state;
+     647                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     648                 :          1 :     spdm_test_context->case_id = 0xA;
+     649                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+     650                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     651                 :          1 :     spdm_context->connection_info.connection_state =
+     652                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_DIGESTS;
+     653                 :          1 :     spdm_context->local_context.capability.flags |=
+     654                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     655                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     656                 :            :         m_libspdm_use_hash_algo;
+     657                 :            : 
+     658                 :          1 :     m_libspdm_get_certificate_request3.length = LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN;
+     659                 :            : 
+     660         [ +  + ]:          3 :     for (int i = 0; i < sizeof(test_cases) / sizeof(test_cases[0]); i++) {
+     661                 :          2 :         libspdm_read_responder_public_certificate_chain_by_size(
+     662                 :            :             /*MAXUINT16_CERT signature_algo is SHA256RSA */
+     663                 :            :             m_libspdm_use_hash_algo, SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048,
+     664                 :          2 :             test_cases[i], &data, &data_size, NULL, NULL);
+     665                 :            : 
+     666                 :          2 :         spdm_context->local_context.local_cert_chain_provision[0] =
+     667                 :            :             data;
+     668                 :          2 :         spdm_context->local_context.local_cert_chain_provision_size[0] =
+     669                 :            :             data_size;
+     670                 :            : 
+     671                 :          2 :         m_libspdm_get_certificate_request3.offset =
+     672         [ +  - ]:          2 :             (uint16_t)(LIBSPDM_MIN(data_size - 1, 0xFFFF));
+     673                 :            :         TEST_LIBSPDM_DEBUG_PRINT("data_size: %u\n", data_size);
+     674                 :            :         TEST_LIBSPDM_DEBUG_PRINT("m_libspdm_get_certificate_request3.offset: %u\n",
+     675                 :            :                                  m_libspdm_get_certificate_request3.offset);
+     676                 :            :         TEST_LIBSPDM_DEBUG_PRINT("m_libspdm_get_certificate_request3.length: %u\n",
+     677                 :            :                                  m_libspdm_get_certificate_request3.length);
+     678                 :            :         TEST_LIBSPDM_DEBUG_PRINT(
+     679                 :            :             "offset + length: %u\n",
+     680                 :            :             m_libspdm_get_certificate_request3.offset +
+     681                 :            :             m_libspdm_get_certificate_request3.length);
+     682                 :            : 
+     683                 :            :         /* reseting an internal buffer to avoid overflow and prevent tests to succeed*/
+     684                 :          2 :         libspdm_reset_message_b(spdm_context);
+     685                 :          2 :         response_size = sizeof(response);
+     686                 :          2 :         status = libspdm_get_response_certificate(
+     687                 :            :             spdm_context, m_libspdm_get_certificate_request3_size,
+     688                 :            :             &m_libspdm_get_certificate_request3, &response_size,
+     689                 :            :             response);
+     690                 :          2 :         assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     691                 :            : 
+     692                 :            :         /* Expected received length is limited by LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN and by the remaining length*/
+     693         [ -  + ]:          2 :         expected_chunk_size = (uint16_t)(LIBSPDM_MIN(
+     694                 :            :                                              m_libspdm_get_certificate_request3.length,
+     695                 :            :                                              data_size -
+     696                 :            :                                              m_libspdm_get_certificate_request3.offset));
+     697                 :          2 :         expected_chunk_size =
+     698                 :            :             LIBSPDM_MIN(expected_chunk_size, LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN);
+     699                 :            :         /* Expected certificate length left*/
+     700                 :          2 :         expected_remainder = (uint16_t)(
+     701                 :          2 :             data_size - m_libspdm_get_certificate_request3.offset -
+     702                 :            :             expected_chunk_size);
+     703                 :            : 
+     704                 :            :         TEST_LIBSPDM_DEBUG_PRINT("expected_chunk_size %u\n", expected_chunk_size);
+     705                 :            :         TEST_LIBSPDM_DEBUG_PRINT("expected_remainder %u\n", expected_remainder);
+     706                 :            : 
+     707   [ +  -  -  + ]:          2 :         if (expected_remainder > 0xFFFF ||
+     708                 :            :             expected_chunk_size > 0xFFFF) {
+     709                 :          0 :             spdm_responseError = (void *)response;
+     710                 :          0 :             assert_int_equal(
+     711                 :            :                 spdm_responseError->header.request_response_code,
+     712                 :            :                 SPDM_ERROR);
+     713                 :          0 :             assert_int_equal(spdm_responseError->header.param1,
+     714                 :            :                              SPDM_ERROR_CODE_INVALID_REQUEST);
+     715                 :            :         } else {
+     716                 :          2 :             assert_int_equal(response_size,
+     717                 :            :                              sizeof(spdm_certificate_response_t) +
+     718                 :            :                              expected_chunk_size);
+     719                 :          2 :             spdm_response = (void *)response;
+     720                 :          2 :             assert_int_equal(
+     721                 :            :                 spdm_response->header.request_response_code,
+     722                 :            :                 SPDM_CERTIFICATE);
+     723                 :          2 :             assert_int_equal(spdm_response->header.param1, 0);
+     724                 :          2 :             assert_int_equal(spdm_response->portion_length,
+     725                 :            :                              expected_chunk_size);
+     726                 :          2 :             assert_int_equal(spdm_response->remainder_length,
+     727                 :            :                              expected_remainder);
+     728                 :            :         }
+     729                 :            : 
+     730                 :            :         TEST_LIBSPDM_DEBUG_PRINT("\n");
+     731                 :            : 
+     732                 :          2 :         spdm_context->local_context.local_cert_chain_provision[0] =
+     733                 :            :             NULL;
+     734                 :          2 :         spdm_context->local_context.local_cert_chain_provision_size[0] =
+     735                 :            :             0;
+     736                 :          2 :         free(data);
+     737                 :            :     }
+     738                 :          1 : }
+     739                 :            : 
+     740                 :            : /**
+     741                 :            :  * Test 11: request LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN bytes of a short certificate chain (fits in 1 message)
+     742                 :            :  * Expected Behavior: generate correctly formed Certficate messages, including its portion_length and remainder_length fields
+     743                 :            :  **/
+     744                 :          1 : void libspdm_test_responder_certificate_case11(void **state)
+     745                 :            : {
+     746                 :            :     libspdm_return_t status;
+     747                 :            :     libspdm_test_context_t *spdm_test_context;
+     748                 :            :     libspdm_context_t *spdm_context;
+     749                 :            :     size_t response_size;
+     750                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     751                 :            :     spdm_certificate_response_t *spdm_response;
+     752                 :            :     spdm_error_response_t *spdm_responseError;
+     753                 :            :     void *data;
+     754                 :            :     size_t data_size;
+     755                 :            : 
+     756                 :          1 :     uint16_t test_cases[] = { LIBSPDM_TEST_CERT_SMALL };
+     757                 :            : 
+     758                 :            :     size_t expected_chunk_size;
+     759                 :            :     size_t expected_remainder;
+     760                 :            : 
+     761                 :            :     /* This case requires a short certificate chain (fits in 1 message) for testing,
+     762                 :            :      * so skip when m_libspdm_use_asym_algo is other than ECC_P256 */
+     763         [ -  + ]:          1 :     if (m_libspdm_use_asym_algo !=
+     764                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256) {
+     765                 :          0 :         return;
+     766                 :            :     }
+     767                 :            : 
+     768                 :            :     /* Setting up the spdm_context and loading a sample certificate chain*/
+     769                 :          1 :     spdm_test_context = *state;
+     770                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     771                 :          1 :     spdm_test_context->case_id = 0xB;
+     772                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+     773                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     774                 :          1 :     spdm_context->connection_info.connection_state =
+     775                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_DIGESTS;
+     776                 :          1 :     spdm_context->local_context.capability.flags |=
+     777                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     778                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     779                 :            :         m_libspdm_use_hash_algo;
+     780                 :            : 
+     781                 :          1 :     m_libspdm_get_certificate_request3.length = LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN;
+     782                 :          1 :     m_libspdm_get_certificate_request3.offset = 0;
+     783                 :            : 
+     784         [ +  + ]:          2 :     for (int i = 0; i < sizeof(test_cases) / sizeof(test_cases[0]); i++) {
+     785                 :          1 :         libspdm_read_responder_public_certificate_chain_by_size(
+     786                 :          1 :             m_libspdm_use_hash_algo, m_libspdm_use_asym_algo, test_cases[i], &data,
+     787                 :            :             &data_size, NULL, NULL);
+     788                 :          1 :         spdm_context->local_context.local_cert_chain_provision[0] =
+     789                 :            :             data;
+     790                 :          1 :         spdm_context->local_context.local_cert_chain_provision_size[0] =
+     791                 :            :             data_size;
+     792                 :            : 
+     793                 :            :         TEST_LIBSPDM_DEBUG_PRINT("data_size: %u\n", data_size);
+     794                 :            :         TEST_LIBSPDM_DEBUG_PRINT("m_libspdm_get_certificate_request3.offset: %u\n",
+     795                 :            :                                  m_libspdm_get_certificate_request3.offset);
+     796                 :            :         TEST_LIBSPDM_DEBUG_PRINT("m_libspdm_get_certificate_request3.length: %u\n",
+     797                 :            :                                  m_libspdm_get_certificate_request3.length);
+     798                 :            :         TEST_LIBSPDM_DEBUG_PRINT(
+     799                 :            :             "offset + length: %u\n",
+     800                 :            :             m_libspdm_get_certificate_request3.offset +
+     801                 :            :             m_libspdm_get_certificate_request3.length);
+     802                 :            : 
+     803                 :            :         /* reseting an internal buffer to avoid overflow and prevent tests to succeed*/
+     804                 :          1 :         libspdm_reset_message_b(spdm_context);
+     805                 :          1 :         response_size = sizeof(response);
+     806                 :          1 :         status = libspdm_get_response_certificate(
+     807                 :            :             spdm_context, m_libspdm_get_certificate_request3_size,
+     808                 :            :             &m_libspdm_get_certificate_request3, &response_size,
+     809                 :            :             response);
+     810                 :          1 :         assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     811                 :            : 
+     812                 :            :         /* Expected received length is limited by LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN and by the remaining length*/
+     813                 :          1 :         expected_chunk_size =
+     814                 :          1 :             LIBSPDM_MIN(m_libspdm_get_certificate_request3.length,
+     815                 :            :                         data_size - m_libspdm_get_certificate_request3.offset);
+     816                 :          1 :         expected_chunk_size =
+     817                 :            :             LIBSPDM_MIN(expected_chunk_size, LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN);
+     818                 :            :         /* Expected certificate length left*/
+     819                 :          1 :         expected_remainder = data_size -
+     820                 :          1 :                              m_libspdm_get_certificate_request3.offset -
+     821                 :            :                              expected_chunk_size;
+     822                 :            : 
+     823                 :            :         TEST_LIBSPDM_DEBUG_PRINT("expected_chunk_size %u\n", expected_chunk_size);
+     824                 :            :         TEST_LIBSPDM_DEBUG_PRINT("expected_remainder %u\n", expected_remainder);
+     825                 :            : 
+     826   [ +  -  -  + ]:          1 :         if (expected_remainder > 0xFFFF ||
+     827                 :            :             expected_chunk_size > 0xFFFF) {
+     828                 :          0 :             spdm_responseError = (void *)response;
+     829                 :          0 :             assert_int_equal(
+     830                 :            :                 spdm_responseError->header.request_response_code,
+     831                 :            :                 SPDM_ERROR);
+     832                 :          0 :             assert_int_equal(spdm_responseError->header.param1,
+     833                 :            :                              SPDM_ERROR_CODE_INVALID_REQUEST);
+     834                 :            :         } else {
+     835                 :          1 :             assert_int_equal(response_size,
+     836                 :            :                              sizeof(spdm_certificate_response_t) +
+     837                 :            :                              expected_chunk_size);
+     838                 :          1 :             spdm_response = (void *)response;
+     839                 :          1 :             assert_int_equal(
+     840                 :            :                 spdm_response->header.request_response_code,
+     841                 :            :                 SPDM_CERTIFICATE);
+     842                 :          1 :             assert_int_equal(spdm_response->header.param1, 0);
+     843                 :          1 :             assert_int_equal(spdm_response->portion_length,
+     844                 :            :                              expected_chunk_size);
+     845                 :          1 :             assert_int_equal(spdm_response->remainder_length,
+     846                 :            :                              expected_remainder);
+     847                 :            :         }
+     848                 :            : 
+     849                 :            :         TEST_LIBSPDM_DEBUG_PRINT("\n");
+     850                 :            : 
+     851                 :          1 :         free(data);
+     852                 :            :     }
+     853                 :            : }
+     854                 :            : 
+     855                 :            : /**
+     856                 :            :  * Test 12: request a whole certificate chain byte by byte
+     857                 :            :  * Expected Behavior: generate correctly formed Certficate messages, including its portion_length and remainder_length fields
+     858                 :            :  **/
+     859                 :          1 : void libspdm_test_responder_certificate_case12(void **state)
+     860                 :            : {
+     861                 :            :     libspdm_return_t status;
+     862                 :            :     libspdm_test_context_t *spdm_test_context;
+     863                 :            :     libspdm_context_t *spdm_context;
+     864                 :            :     size_t response_size;
+     865                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     866                 :            :     spdm_certificate_response_t *spdm_response;
+     867                 :            :     void *data;
+     868                 :            :     size_t data_size;
+     869                 :            :     uint16_t expected_chunk_size;
+     870                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     871                 :            :     size_t count;
+     872                 :            : #endif
+     873                 :            :     /* Setting up the spdm_context and loading a sample certificate chain*/
+     874                 :          1 :     spdm_test_context = *state;
+     875                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     876                 :          1 :     spdm_test_context->case_id = 0xC;
+     877                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+     878                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     879                 :          1 :     spdm_context->connection_info.connection_state =
+     880                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_DIGESTS;
+     881                 :          1 :     spdm_context->local_context.capability.flags |=
+     882                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     883                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     884                 :            :         m_libspdm_use_hash_algo;
+     885                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     886                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     887                 :            :                                                     &data_size, NULL, NULL);
+     888                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     889                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     890                 :            :         data_size;
+     891                 :            : 
+     892                 :            :     /* This tests considers only length = 1*/
+     893                 :          1 :     m_libspdm_get_certificate_request3.length = 1;
+     894                 :          1 :     expected_chunk_size = 1;
+     895                 :            : 
+     896                 :            : 
+     897                 :            :     /* reseting an internal buffer to avoid overflow and prevent tests to succeed*/
+     898                 :          1 :     libspdm_reset_message_b(spdm_context);
+     899                 :            : 
+     900                 :          1 :     spdm_response = NULL;
+     901         [ +  + ]:       1391 :     for (size_t offset = 0; offset < data_size; offset++) {
+     902                 :            :         TEST_LIBSPDM_DEBUG_PRINT("offset:%u \n", offset);
+     903                 :       1390 :         m_libspdm_get_certificate_request3.offset = (uint16_t)offset;
+     904                 :            : 
+     905                 :       1390 :         response_size = sizeof(response);
+     906                 :       1390 :         status = libspdm_get_response_certificate(
+     907                 :            :             spdm_context, m_libspdm_get_certificate_request3_size,
+     908                 :            :             &m_libspdm_get_certificate_request3, &response_size,
+     909                 :            :             response);
+     910                 :       1390 :         assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     911                 :       1390 :         spdm_response = (void *)response;
+     912                 :            :         /* It may fail because the spdm does not support too many messages.
+     913                 :            :          * assert_int_equal (spdm_response->header.request_response_code, SPDM_CERTIFICATE);*/
+     914         [ +  - ]:       1390 :         if (spdm_response->header.request_response_code ==
+     915                 :            :             SPDM_CERTIFICATE) {
+     916                 :       1390 :             assert_int_equal(
+     917                 :            :                 spdm_response->header.request_response_code,
+     918                 :            :                 SPDM_CERTIFICATE);
+     919                 :       1390 :             assert_int_equal(response_size,
+     920                 :            :                              sizeof(spdm_certificate_response_t) +
+     921                 :            :                              expected_chunk_size);
+     922                 :       1390 :             assert_int_equal(spdm_response->header.param1, 0);
+     923                 :       1390 :             assert_int_equal(spdm_response->portion_length,
+     924                 :            :                              expected_chunk_size);
+     925                 :       1390 :             assert_int_equal(spdm_response->remainder_length,
+     926                 :            :                              data_size - offset -
+     927                 :            :                              expected_chunk_size);
+     928                 :       1390 :             assert_int_equal(
+     929                 :            :                 ((uint8_t *)data)[offset],
+     930                 :            :                 (response +
+     931                 :            :                  sizeof(spdm_certificate_response_t))[0]);
+     932                 :            :         } else {
+     933                 :          0 :             assert_int_equal(
+     934                 :            :                 spdm_response->header.request_response_code,
+     935                 :            :                 SPDM_ERROR);
+     936                 :          0 :             break;
+     937                 :            :         }
+     938                 :            :     }
+     939         [ +  - ]:          1 :     if (spdm_response != NULL) {
+     940                 :          1 :         if (spdm_response->header.request_response_code ==
+     941                 :            :             SPDM_CERTIFICATE) {
+     942                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     943                 :            :             count = (data_size + m_libspdm_get_certificate_request3.length - 1) /
+     944                 :            :                     m_libspdm_get_certificate_request3.length;
+     945                 :            :             assert_int_equal(
+     946                 :            :                 spdm_context->transcript.message_b.buffer_size,
+     947                 :            :                 sizeof(spdm_get_certificate_request_t) * count +
+     948                 :            :                 sizeof(spdm_certificate_response_t) *
+     949                 :            :                 count +
+     950                 :            :                 data_size);
+     951                 :            : #endif
+     952                 :            :         }
+     953                 :            :     }
+     954                 :          1 :     free(data);
+     955                 :          1 : }
+     956                 :            : 
+     957                 :            : /**
+     958                 :            :  * Test 13: receiving a correct GET_CERTIFICATE from the requester. Buffer B
+     959                 :            :  * already has arbitrary data.
+     960                 :            :  * Expected behavior: the responder accepts the request and produces a valid
+     961                 :            :  * CERTIFICATE response message, and buffer B receives the exchanged
+     962                 :            :  * GET_CERTIFICATE and CERTIFICATE messages.
+     963                 :            :  **/
+     964                 :          1 : void libspdm_test_responder_certificate_case13(void **state)
+     965                 :            : {
+     966                 :            :     libspdm_return_t status;
+     967                 :            :     libspdm_test_context_t *spdm_test_context;
+     968                 :            :     libspdm_context_t *spdm_context;
+     969                 :            :     size_t response_size;
+     970                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     971                 :            :     spdm_certificate_response_t *spdm_response;
+     972                 :            :     void *data;
+     973                 :            :     size_t data_size;
+     974                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     975                 :            :     size_t arbitrary_size;
+     976                 :            : #endif
+     977                 :            : 
+     978                 :          1 :     spdm_test_context = *state;
+     979                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     980                 :          1 :     spdm_test_context->case_id = 0xD;
+     981                 :          1 :     spdm_context->connection_info.connection_state =
+     982                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_DIGESTS;
+     983                 :          1 :     spdm_context->local_context.capability.flags |=
+     984                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     985                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     986                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     987                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     988                 :            :                                                     &data_size, NULL, NULL);
+     989                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     990                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
+     991                 :            : 
+     992                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     993                 :            :     /*filling buffer B with arbitrary data*/
+     994                 :            :     arbitrary_size = 8;
+     995                 :            :     libspdm_set_mem(spdm_context->transcript.message_b.buffer, arbitrary_size, (uint8_t) 0xEE);
+     996                 :            :     spdm_context->transcript.message_b.buffer_size = arbitrary_size;
+     997                 :            : #endif
+     998                 :            : 
+     999                 :          1 :     response_size = sizeof(response);
+    1000                 :          1 :     status = libspdm_get_response_certificate(
+    1001                 :            :         spdm_context, m_libspdm_get_certificate_request1_size,
+    1002                 :            :         &m_libspdm_get_certificate_request1, &response_size, response);
+    1003                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1004                 :          1 :     assert_int_equal(response_size, sizeof(spdm_certificate_response_t) +
+    1005                 :            :                      LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN);
+    1006                 :          1 :     spdm_response = (void *)response;
+    1007                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_CERTIFICATE);
+    1008                 :          1 :     assert_int_equal(spdm_response->header.param1, 0);
+    1009                 :          1 :     assert_int_equal(spdm_response->portion_length, LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN);
+    1010                 :          1 :     assert_int_equal(spdm_response->remainder_length,
+    1011                 :            :                      data_size - LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN);
+    1012                 :            : 
+    1013                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1014                 :            :     assert_int_equal(spdm_context->transcript.message_b.buffer_size,
+    1015                 :            :                      arbitrary_size + m_libspdm_get_certificate_request1_size + response_size);
+    1016                 :            :     assert_memory_equal(spdm_context->transcript.message_b.buffer + arbitrary_size,
+    1017                 :            :                         &m_libspdm_get_certificate_request1,
+    1018                 :            :                         m_libspdm_get_certificate_request1_size);
+    1019                 :            :     assert_memory_equal(spdm_context->transcript.message_b.buffer + arbitrary_size +
+    1020                 :            :                         m_libspdm_get_certificate_request1_size,
+    1021                 :            :                         response, response_size);
+    1022                 :            : #endif
+    1023                 :            : 
+    1024                 :          1 :     free(data);
+    1025                 :          1 : }
+    1026                 :            : 
+    1027                 :            : /**
+    1028                 :            :  * Test 14: request the first LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN bytes of the certificate chain in a session
+    1029                 :            :  * Expected Behavior: generate a correctly formed Certficate message, including its portion_length and remainder_length fields
+    1030                 :            :  **/
+    1031                 :          1 : void libspdm_test_responder_certificate_case14(void **state)
+    1032                 :            : {
+    1033                 :            :     libspdm_return_t status;
+    1034                 :            :     libspdm_test_context_t *spdm_test_context;
+    1035                 :            :     libspdm_context_t *spdm_context;
+    1036                 :            :     size_t response_size;
+    1037                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1038                 :            :     spdm_certificate_response_t *spdm_response;
+    1039                 :            :     void *data;
+    1040                 :            :     size_t data_size;
+    1041                 :            :     libspdm_session_info_t *session_info;
+    1042                 :            :     uint32_t session_id;
+    1043                 :            : 
+    1044                 :          1 :     spdm_test_context = *state;
+    1045                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1046                 :          1 :     spdm_test_context->case_id = 0xE;
+    1047                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1048                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1049                 :          1 :     spdm_context->connection_info.connection_state =
+    1050                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_DIGESTS;
+    1051                 :          1 :     spdm_context->local_context.capability.flags |=
+    1052                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+    1053                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1054                 :            :         m_libspdm_use_hash_algo;
+    1055                 :            : 
+    1056                 :          1 :     session_id = 0xFFFFFFFF;
+    1057                 :          1 :     spdm_context->latest_session_id = session_id;
+    1058                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+    1059                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+    1060                 :          1 :     session_info = &spdm_context->session_info[0];
+    1061                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+    1062                 :          1 :     libspdm_secured_message_set_session_state(
+    1063                 :            :         session_info->secured_message_context,
+    1064                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+    1065                 :            : 
+    1066                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1067                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    1068                 :            :                                                     &data_size, NULL, NULL);
+    1069                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+    1070                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    1071                 :            :         data_size;
+    1072                 :            : 
+    1073                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1074                 :            :     session_info->session_transcript.message_m.buffer_size =
+    1075                 :            :         session_info->session_transcript.message_m.max_buffer_size;
+    1076                 :            : #endif
+    1077                 :            : 
+    1078                 :          1 :     response_size = sizeof(response);
+    1079                 :          1 :     status = libspdm_get_response_certificate(
+    1080                 :            :         spdm_context, m_libspdm_get_certificate_request1_size,
+    1081                 :            :         &m_libspdm_get_certificate_request1, &response_size, response);
+    1082                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1083                 :          1 :     assert_int_equal(response_size, sizeof(spdm_certificate_response_t) +
+    1084                 :            :                      LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN);
+    1085                 :          1 :     spdm_response = (void *)response;
+    1086                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1087                 :            :                      SPDM_CERTIFICATE);
+    1088                 :          1 :     assert_int_equal(spdm_response->header.param1, 0);
+    1089                 :          1 :     assert_int_equal(spdm_response->portion_length,
+    1090                 :            :                      LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN);
+    1091                 :          1 :     assert_int_equal(spdm_response->remainder_length,
+    1092                 :            :                      data_size - LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN);
+    1093                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1094                 :            :     assert_int_equal(session_info->session_transcript.message_m.buffer_size,
+    1095                 :            :                      0);
+    1096                 :            : #endif
+    1097                 :          1 :     free(data);
+    1098                 :          1 : }
+    1099                 :            : 
+    1100                 :            : /**
+    1101                 :            :  * Test 15: Produce a CERTIFICATE response that is meant to be chunked.
+    1102                 :            :  *          LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN is ignored when chunking is enabled.
+    1103                 :            :  **/
+    1104                 :          1 : void libspdm_test_responder_certificate_case15(void **state)
+    1105                 :            : {
+    1106                 :            :     libspdm_return_t status;
+    1107                 :            :     bool ret;
+    1108                 :            :     libspdm_test_context_t *spdm_test_context;
+    1109                 :            :     libspdm_context_t *spdm_context;
+    1110                 :            :     size_t response_size;
+    1111                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1112                 :            :     uint8_t request[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1113                 :            :     spdm_get_certificate_request_t *spdm_cert_request;
+    1114                 :            :     spdm_certificate_response_t *spdm_cert_response;
+    1115                 :            :     void *data;
+    1116                 :            :     size_t data_size;
+    1117                 :            : 
+    1118                 :          1 :     spdm_test_context = *state;
+    1119                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1120                 :          1 :     spdm_test_context->case_id = 15;
+    1121                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    1122                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1123                 :            : 
+    1124                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1125                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1126                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1127                 :          1 :     spdm_context->connection_info.capability.flags = 0;
+    1128                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP;
+    1129                 :          1 :     spdm_context->connection_info.capability.data_transfer_size =
+    1130                 :            :         SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12;
+    1131                 :            : 
+    1132                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1133                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1134                 :          1 :     spdm_context->local_context.capability.data_transfer_size =
+    1135                 :            :         SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12;
+    1136                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP |
+    1137                 :            :                                                     SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+    1138                 :            : 
+    1139                 :          1 :     ret = libspdm_read_responder_public_certificate_chain(
+    1140                 :            :         m_libspdm_use_hash_algo, m_libspdm_use_asym_algo, &data,
+    1141                 :            :         &data_size, NULL, NULL);
+    1142                 :          1 :     assert_true(ret);
+    1143                 :            : 
+    1144                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+    1145                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
+    1146                 :            : 
+    1147                 :          1 :     spdm_cert_request = (spdm_get_certificate_request_t *) request;
+    1148                 :            : 
+    1149                 :          1 :     spdm_cert_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+    1150                 :          1 :     spdm_cert_request->header.request_response_code = SPDM_GET_CERTIFICATE;
+    1151                 :          1 :     spdm_cert_request->header.param1 = 0;
+    1152                 :          1 :     spdm_cert_request->header.param2 = 0;
+    1153                 :          1 :     spdm_cert_request->offset = 0;
+    1154                 :          1 :     spdm_cert_request->length = 0xffff;
+    1155                 :            : 
+    1156                 :          1 :     response_size = sizeof(response);
+    1157                 :          1 :     libspdm_zero_mem(response, response_size);
+    1158                 :            : 
+    1159                 :          1 :     status = libspdm_get_response_certificate(
+    1160                 :            :         spdm_context,
+    1161                 :            :         sizeof(spdm_get_certificate_request_t), &request,
+    1162                 :            :         &response_size, response);
+    1163                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1164                 :            : 
+    1165                 :          1 :     spdm_cert_response = (spdm_certificate_response_t *) response;
+    1166                 :            : 
+    1167                 :          1 :     assert_int_equal(spdm_cert_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+    1168                 :          1 :     assert_int_equal(spdm_cert_response->header.request_response_code, SPDM_CERTIFICATE);
+    1169                 :          1 :     assert_int_equal(spdm_cert_response->header.param1, 0);
+    1170                 :          1 :     assert_int_equal(spdm_cert_response->header.param2, 0);
+    1171                 :          1 :     assert_int_equal(spdm_cert_response->portion_length, data_size);
+    1172                 :          1 :     assert_int_equal(spdm_cert_response->remainder_length, 0);
+    1173                 :            : 
+    1174                 :          1 :     free(data);
+    1175                 :          1 : }
+    1176                 :            : 
+    1177                 :            : /**
+    1178                 :            :  * Test 16: request a 0 byte certificate chain
+    1179                 :            :  * Expected Behavior: portion length should be 0 and remainder length should be the size of the
+    1180                 :            :  *                    certificate chain.
+    1181                 :            :  **/
+    1182                 :          1 : void libspdm_test_responder_certificate_case16(void **state)
+    1183                 :            : {
+    1184                 :            :     libspdm_return_t status;
+    1185                 :            :     libspdm_test_context_t *spdm_test_context;
+    1186                 :            :     libspdm_context_t *spdm_context;
+    1187                 :            :     size_t response_size;
+    1188                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1189                 :            :     spdm_certificate_response_t *spdm_response;
+    1190                 :            :     void *data;
+    1191                 :            :     size_t data_size;
+    1192                 :            : 
+    1193                 :          1 :     spdm_test_context = *state;
+    1194                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1195                 :          1 :     spdm_test_context->case_id = 16;
+    1196                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1197                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1198                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_DIGESTS;
+    1199                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+    1200                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1201                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1202                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    1203                 :            :                                                     &data_size, NULL, NULL);
+    1204                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+    1205                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
+    1206                 :            : 
+    1207                 :          1 :     m_libspdm_get_certificate_request3.offset = 0;
+    1208                 :          1 :     m_libspdm_get_certificate_request3.length = 0;
+    1209                 :            : 
+    1210                 :          1 :     response_size = sizeof(response);
+    1211                 :          1 :     status = libspdm_get_response_certificate(
+    1212                 :            :         spdm_context, m_libspdm_get_certificate_request3_size,
+    1213                 :            :         &m_libspdm_get_certificate_request3, &response_size, response);
+    1214                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1215                 :          1 :     assert_int_equal(response_size, sizeof(spdm_certificate_response_t));
+    1216                 :          1 :     spdm_response = (void *)response;
+    1217                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_CERTIFICATE);
+    1218                 :          1 :     assert_int_equal(spdm_response->header.param1, 0);
+    1219                 :          1 :     assert_int_equal(spdm_response->portion_length, 0);
+    1220                 :          1 :     assert_int_equal(spdm_response->remainder_length, data_size);
+    1221                 :            : 
+    1222                 :          1 :     free(data);
+    1223                 :          1 : }
+    1224                 :            : 
+    1225                 :            : /**
+    1226                 :            :  * Test 17: SlotID in GET_CERTIFICATE request message is 9, but it should be between 0 and 7 inclusive.
+    1227                 :            :  * Expected Behavior: generate an ERROR_RESPONSE with code SPDM_ERROR_CODE_INVALID_REQUEST.
+    1228                 :            :  **/
+    1229                 :          1 : void libspdm_test_responder_certificate_case17(void **state)
+    1230                 :            : {
+    1231                 :            :     libspdm_return_t status;
+    1232                 :            :     libspdm_test_context_t *spdm_test_context;
+    1233                 :            :     libspdm_context_t *spdm_context;
+    1234                 :            :     size_t response_size;
+    1235                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1236                 :            :     spdm_certificate_response_t *spdm_response;
+    1237                 :            :     void *data;
+    1238                 :            :     size_t data_size;
+    1239                 :            : 
+    1240                 :          1 :     spdm_test_context = *state;
+    1241                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1242                 :          1 :     spdm_test_context->case_id = 17;
+    1243                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1244                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1245                 :          1 :     spdm_context->connection_info.connection_state =
+    1246                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_DIGESTS;
+    1247                 :          1 :     spdm_context->local_context.capability.flags |=
+    1248                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+    1249                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1250                 :            :         m_libspdm_use_hash_algo;
+    1251                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1252                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    1253                 :            :                                                     &data_size, NULL, NULL);
+    1254                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+    1255                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    1256                 :            :         data_size;
+    1257                 :            : 
+    1258                 :          1 :     response_size = sizeof(response);
+    1259                 :          1 :     status = libspdm_get_response_certificate(
+    1260                 :            :         spdm_context, m_libspdm_get_certificate_request4_size,
+    1261                 :            :         &m_libspdm_get_certificate_request4, &response_size, response);
+    1262                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1263                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1264                 :          1 :     spdm_response = (void *)response;
+    1265                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1266                 :            :                      SPDM_ERROR);
+    1267                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1268                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+    1269                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1270                 :          1 :     free(data);
+    1271                 :          1 : }
+    1272                 :            : 
+    1273                 :            : /**
+    1274                 :            :  * Test 18: check request attributes and response attributes , SlotSizeRequested=1b the Offset and Length fields in the
+    1275                 :            :  * GET_CERTIFICATE request shall be ignored by the Responde
+    1276                 :            :  * Expected Behavior: generate a correctly formed Certficate message, including its portion_length and remainder_length fields
+    1277                 :            :  **/
+    1278                 :          1 : void libspdm_test_responder_certificate_case18(void **state)
+    1279                 :            : {
+    1280                 :            :     libspdm_return_t status;
+    1281                 :            :     libspdm_test_context_t *spdm_test_context;
+    1282                 :            :     libspdm_context_t *spdm_context;
+    1283                 :            :     size_t response_size;
+    1284                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1285                 :            :     spdm_certificate_response_t *spdm_response;
+    1286                 :            :     void *data;
+    1287                 :            :     size_t data_size;
+    1288                 :            : 
+    1289                 :          1 :     spdm_test_context = *state;
+    1290                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1291                 :          1 :     spdm_test_context->case_id = 18;
+    1292                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+    1293                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1294                 :          1 :     spdm_context->connection_info.connection_state =
+    1295                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_DIGESTS;
+    1296                 :          1 :     spdm_context->local_context.capability.flags |=
+    1297                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+    1298                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1299                 :            :         m_libspdm_use_hash_algo;
+    1300                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1301                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    1302                 :            :                                                     &data_size, NULL, NULL);
+    1303                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+    1304                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    1305                 :            :         data_size;
+    1306                 :            : 
+    1307                 :            :     /* When SlotSizeRequested=1b , the Offset and Length fields in the GET_CERTIFICATE request shall be ignored by the Responder */
+    1308                 :          1 :     m_libspdm_get_certificate_request5.header.param2 =
+    1309                 :            :         SPDM_GET_CERTIFICATE_REQUEST_ATTRIBUTES_SLOT_SIZE_REQUESTED;
+    1310                 :          1 :     m_libspdm_get_certificate_request5.length = LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN;
+    1311                 :          1 :     m_libspdm_get_certificate_request5.offset = 0xFF;
+    1312                 :            : 
+    1313                 :          1 :     response_size = sizeof(response);
+    1314                 :          1 :     status = libspdm_get_response_certificate(
+    1315                 :            :         spdm_context, m_libspdm_get_certificate_request5_size,
+    1316                 :            :         &m_libspdm_get_certificate_request5, &response_size, response);
+    1317                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1318                 :          1 :     assert_int_equal(response_size, sizeof(spdm_certificate_response_t));
+    1319                 :          1 :     spdm_response = (void *)response;
+    1320                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1321                 :            :                      SPDM_CERTIFICATE);
+    1322                 :          1 :     assert_int_equal(spdm_response->header.param1, 0);
+    1323                 :          1 :     assert_int_equal(spdm_response->portion_length,0);
+    1324                 :          1 :     assert_int_equal(spdm_response->remainder_length, data_size);
+    1325                 :          1 :     free(data);
+    1326                 :          1 : }
+    1327                 :            : 
+    1328                 :            : libspdm_test_context_t m_libspdm_responder_certificate_test_context = {
+    1329                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+    1330                 :            :     false,
+    1331                 :            : };
+    1332                 :            : 
+    1333                 :          1 : int libspdm_responder_certificate_test_main(void)
+    1334                 :            : {
+    1335                 :          1 :     const struct CMUnitTest spdm_responder_certificate_tests[] = {
+    1336                 :            :         /* Success Case*/
+    1337                 :            :         cmocka_unit_test(libspdm_test_responder_certificate_case1),
+    1338                 :            :         /* Can be populated with new test.*/
+    1339                 :            :         cmocka_unit_test(libspdm_test_responder_certificate_case2),
+    1340                 :            :         /* response_state: LIBSPDM_RESPONSE_STATE_BUSY*/
+    1341                 :            :         cmocka_unit_test(libspdm_test_responder_certificate_case3),
+    1342                 :            :         /* response_state: LIBSPDM_RESPONSE_STATE_NEED_RESYNC*/
+    1343                 :            :         cmocka_unit_test(libspdm_test_responder_certificate_case4),
+    1344                 :            :         #if LIBSPDM_RESPOND_IF_READY_SUPPORT
+    1345                 :            :         /* response_state: LIBSPDM_RESPONSE_STATE_NOT_READY*/
+    1346                 :            :         cmocka_unit_test(libspdm_test_responder_certificate_case5),
+    1347                 :            :         #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
+    1348                 :            :         /* connection_state Check*/
+    1349                 :            :         cmocka_unit_test(libspdm_test_responder_certificate_case6),
+    1350                 :            :         /* Tests varying length*/
+    1351                 :            :         cmocka_unit_test(libspdm_test_responder_certificate_case7),
+    1352                 :            :         /* Tests varying offset*/
+    1353                 :            :         cmocka_unit_test(libspdm_test_responder_certificate_case8),
+    1354                 :            :         /* Tests varying length and offset*/
+    1355                 :            :         cmocka_unit_test(libspdm_test_responder_certificate_case9),
+    1356                 :            :         /* Tests large certificate chains*/
+    1357                 :            :         cmocka_unit_test(libspdm_test_responder_certificate_case10),
+    1358                 :            :         /* Certificate fits in one single message*/
+    1359                 :            :         cmocka_unit_test(libspdm_test_responder_certificate_case11),
+    1360                 :            :         /* Requests byte by byte*/
+    1361                 :            :         cmocka_unit_test(libspdm_test_responder_certificate_case12),
+    1362                 :            :         /* Buffer verification*/
+    1363                 :            :         cmocka_unit_test(libspdm_test_responder_certificate_case13),
+    1364                 :            :         /* Success Case in a session*/
+    1365                 :            :         cmocka_unit_test(libspdm_test_responder_certificate_case14),
+    1366                 :            :         /* Produce a CERTIFICATE response that is meant to be chunked. */
+    1367                 :            :         cmocka_unit_test(libspdm_test_responder_certificate_case15),
+    1368                 :            :         cmocka_unit_test(libspdm_test_responder_certificate_case16),
+    1369                 :            :         /* Bad SlotID in request message */
+    1370                 :            :         cmocka_unit_test(libspdm_test_responder_certificate_case17),
+    1371                 :            :         /* check request attributes and response attributes*/
+    1372                 :            :         cmocka_unit_test(libspdm_test_responder_certificate_case18),
+    1373                 :            :     };
+    1374                 :            : 
+    1375                 :          1 :     libspdm_setup_test_context(&m_libspdm_responder_certificate_test_context);
+    1376                 :            : 
+    1377                 :          1 :     return cmocka_run_group_tests(spdm_responder_certificate_tests,
+    1378                 :            :                                   libspdm_unit_test_group_setup,
+    1379                 :            :                                   libspdm_unit_test_group_teardown);
+    1380                 :            : }
+    1381                 :            : 
+    1382                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CERT_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/challenge_auth.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_responder/challenge_auth.c.func-sort-c.html new file mode 100644 index 00000000000..6c2d65e6a90 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/challenge_auth.c.func-sort-c.html @@ -0,0 +1,161 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/challenge_auth.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - challenge_auth.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:553553100.0 %
Date:2024-09-22 08:21:07Functions:2020100.0 %
Branches:66100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_challenge_auth_test_main1
libspdm_test_responder_challenge_auth_case11
libspdm_test_responder_challenge_auth_case101
libspdm_test_responder_challenge_auth_case111
libspdm_test_responder_challenge_auth_case121
libspdm_test_responder_challenge_auth_case131
libspdm_test_responder_challenge_auth_case141
libspdm_test_responder_challenge_auth_case151
libspdm_test_responder_challenge_auth_case161
libspdm_test_responder_challenge_auth_case171
libspdm_test_responder_challenge_auth_case181
libspdm_test_responder_challenge_auth_case191
libspdm_test_responder_challenge_auth_case21
libspdm_test_responder_challenge_auth_case31
libspdm_test_responder_challenge_auth_case41
libspdm_test_responder_challenge_auth_case51
libspdm_test_responder_challenge_auth_case61
libspdm_test_responder_challenge_auth_case71
libspdm_test_responder_challenge_auth_case81
libspdm_test_responder_challenge_auth_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/challenge_auth.c.func.html b/coverage_log/unit_test/test_spdm_responder/challenge_auth.c.func.html new file mode 100644 index 00000000000..3c617af673f --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/challenge_auth.c.func.html @@ -0,0 +1,161 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/challenge_auth.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - challenge_auth.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:553553100.0 %
Date:2024-09-22 08:21:07Functions:2020100.0 %
Branches:66100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_challenge_auth_test_main1
libspdm_test_responder_challenge_auth_case11
libspdm_test_responder_challenge_auth_case101
libspdm_test_responder_challenge_auth_case111
libspdm_test_responder_challenge_auth_case121
libspdm_test_responder_challenge_auth_case131
libspdm_test_responder_challenge_auth_case141
libspdm_test_responder_challenge_auth_case151
libspdm_test_responder_challenge_auth_case161
libspdm_test_responder_challenge_auth_case171
libspdm_test_responder_challenge_auth_case181
libspdm_test_responder_challenge_auth_case191
libspdm_test_responder_challenge_auth_case21
libspdm_test_responder_challenge_auth_case31
libspdm_test_responder_challenge_auth_case41
libspdm_test_responder_challenge_auth_case51
libspdm_test_responder_challenge_auth_case61
libspdm_test_responder_challenge_auth_case71
libspdm_test_responder_challenge_auth_case81
libspdm_test_responder_challenge_auth_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/challenge_auth.c.gcov.html b/coverage_log/unit_test/test_spdm_responder/challenge_auth.c.gcov.html new file mode 100644 index 00000000000..6009fff94ba --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/challenge_auth.c.gcov.html @@ -0,0 +1,1351 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/challenge_auth.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - challenge_auth.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:553553100.0 %
Date:2024-09-22 08:21:07Functions:2020100.0 %
Branches:66100.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_responder_lib.h"
+       9                 :            : 
+      10                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP
+      11                 :            : 
+      12                 :            : spdm_challenge_request_t m_libspdm_challenge_request1 = {
+      13                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_CHALLENGE, 0,
+      14                 :            :       SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH },
+      15                 :            : };
+      16                 :            : size_t m_libspdm_challenge_request1_size = sizeof(m_libspdm_challenge_request1);
+      17                 :            : 
+      18                 :            : spdm_challenge_request_t m_libspdm_challenge_request3 = {
+      19                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_CHALLENGE, SPDM_MAX_SLOT_COUNT,
+      20                 :            :       SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH },
+      21                 :            : };
+      22                 :            : size_t m_libspdm_challenge_request3_size = sizeof(m_libspdm_challenge_request3);
+      23                 :            : 
+      24                 :            : spdm_challenge_request_t m_libspdm_challenge_request4 = {
+      25                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_CHALLENGE, 1,
+      26                 :            :       SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH },
+      27                 :            : };
+      28                 :            : size_t m_libspdm_challenge_request4_size = sizeof(m_libspdm_challenge_request4);
+      29                 :            : 
+      30                 :            : spdm_challenge_request_t m_libspdm_challenge_request5 = {
+      31                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_CHALLENGE, 0,
+      32                 :            :       SPDM_CHALLENGE_REQUEST_TCB_COMPONENT_MEASUREMENT_HASH },
+      33                 :            : };
+      34                 :            : size_t m_libspdm_challenge_request5_size = sizeof(m_libspdm_challenge_request5);
+      35                 :            : 
+      36                 :            : spdm_challenge_request_t m_libspdm_challenge_request6 = {
+      37                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_CHALLENGE, 0,
+      38                 :            :       SPDM_CHALLENGE_REQUEST_ALL_MEASUREMENTS_HASH },
+      39                 :            : };
+      40                 :            : size_t m_libspdm_challenge_request6_size = sizeof(m_libspdm_challenge_request6);
+      41                 :            : 
+      42                 :            : spdm_challenge_request_t m_libspdm_challenge_request7 = {
+      43                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_CHALLENGE, 0xFF,
+      44                 :            :       SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH },
+      45                 :            : };
+      46                 :            : size_t m_libspdm_challenge_request7_size = sizeof(m_libspdm_challenge_request7);
+      47                 :            : 
+      48                 :            : spdm_challenge_request_t m_libspdm_challenge_request8 = {
+      49                 :            :     {SPDM_MESSAGE_VERSION_13, SPDM_CHALLENGE, 0,
+      50                 :            :      SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH},
+      51                 :            : };
+      52                 :            : size_t m_libspdm_challenge_request8_size = sizeof(m_libspdm_challenge_request8);
+      53                 :            : 
+      54                 :            : extern size_t libspdm_secret_lib_challenge_opaque_data_size;
+      55                 :            : 
+      56                 :            : /**
+      57                 :            :  * Test 1: receiving a correct CHALLENGE message from the requester with
+      58                 :            :  * no opaque data, no measurements, and slot number 0.
+      59                 :            :  * Expected behavior: the responder accepts the request and produces a valid
+      60                 :            :  * CHALLENGE_AUTH response message.
+      61                 :            :  **/
+      62                 :          1 : void libspdm_test_responder_challenge_auth_case1(void **state)
+      63                 :            : {
+      64                 :            :     libspdm_return_t status;
+      65                 :            :     libspdm_test_context_t *spdm_test_context;
+      66                 :            :     libspdm_context_t *spdm_context;
+      67                 :            :     size_t response_size;
+      68                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+      69                 :            :     spdm_challenge_auth_response_t *spdm_response;
+      70                 :            :     void *data1;
+      71                 :            :     size_t data_size1;
+      72                 :            : 
+      73                 :          1 :     spdm_test_context = *state;
+      74                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+      75                 :          1 :     spdm_test_context->case_id = 0x1;
+      76                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+      77                 :          1 :     spdm_context->local_context.capability.flags = 0;
+      78                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
+      79                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+      80                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+      81                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+      82                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+      83                 :            :         m_libspdm_use_measurement_hash_algo;
+      84                 :            : 
+      85                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+      86                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+      87                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+      88                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+      89                 :            :                                                     &data_size1, NULL, NULL);
+      90                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+      91                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
+      92                 :            : 
+      93                 :          1 :     libspdm_secret_lib_challenge_opaque_data_size = 0;
+      94                 :          1 :     libspdm_reset_message_c(spdm_context);
+      95                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+      96                 :            :     spdm_context->transcript.message_m.buffer_size =
+      97                 :            :         spdm_context->transcript.message_m.max_buffer_size;
+      98                 :            : #endif
+      99                 :            : 
+     100                 :          1 :     response_size = sizeof(response);
+     101                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE, m_libspdm_challenge_request1.nonce);
+     102                 :          1 :     status = libspdm_get_response_challenge_auth(
+     103                 :            :         spdm_context, m_libspdm_challenge_request1_size,
+     104                 :            :         &m_libspdm_challenge_request1, &response_size, response);
+     105                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     106                 :          1 :     assert_int_equal(response_size,
+     107                 :            :                      sizeof(spdm_challenge_auth_response_t) +
+     108                 :            :                      libspdm_get_hash_size(m_libspdm_use_hash_algo) +
+     109                 :            :                      SPDM_NONCE_SIZE + 0 + sizeof(uint16_t) + 0 +
+     110                 :            :                      libspdm_get_asym_signature_size(m_libspdm_use_asym_algo));
+     111                 :          1 :     spdm_response = (void *)response;
+     112                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_CHALLENGE_AUTH);
+     113                 :          1 :     assert_int_equal(spdm_response->header.param1, 0);
+     114                 :          1 :     assert_int_equal(spdm_response->header.param2, 1 << 0);
+     115                 :            :     /* Completion of CHALLENGE sets M1/M2 to null. */
+     116                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     117                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+     118                 :            :     assert_int_equal(spdm_context->transcript.message_c.buffer_size, 0);
+     119                 :            : #else
+     120                 :          1 :     assert_null(spdm_context->transcript.digest_context_m1m2);
+     121                 :            : #endif
+     122                 :          1 :     free(data1);
+     123                 :          1 : }
+     124                 :            : 
+     125                 :            : /**
+     126                 :            :  * Test 2:
+     127                 :            :  * Expected behavior:
+     128                 :            :  **/
+     129                 :          1 : void libspdm_test_responder_challenge_auth_case2(void **state)
+     130                 :            : {
+     131                 :          1 : }
+     132                 :            : 
+     133                 :            : /**
+     134                 :            :  * Test 3: receiving a correct CHALLENGE from the requester, but the responder is in
+     135                 :            :  * a Busy state.
+     136                 :            :  * Expected behavior: the responder accepts the request, but produces an ERROR message
+     137                 :            :  * indicating the Busy state.
+     138                 :            :  **/
+     139                 :          1 : void libspdm_test_responder_challenge_auth_case3(void **state)
+     140                 :            : {
+     141                 :            :     libspdm_return_t status;
+     142                 :            :     libspdm_test_context_t *spdm_test_context;
+     143                 :            :     libspdm_context_t *spdm_context;
+     144                 :            :     size_t response_size;
+     145                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     146                 :            :     spdm_challenge_auth_response_t *spdm_response;
+     147                 :            :     void *data1;
+     148                 :            :     size_t data_size1;
+     149                 :            : 
+     150                 :          1 :     spdm_test_context = *state;
+     151                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     152                 :          1 :     spdm_test_context->case_id = 0x3;
+     153                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_BUSY;
+     154                 :          1 :     spdm_context->connection_info.connection_state =
+     155                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     156                 :          1 :     spdm_context->local_context.capability.flags = 0;
+     157                 :          1 :     spdm_context->local_context.capability.flags |=
+     158                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
+     159                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     160                 :            :         m_libspdm_use_hash_algo;
+     161                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     162                 :            :         m_libspdm_use_asym_algo;
+     163                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     164                 :            :         m_libspdm_use_measurement_spec;
+     165                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     166                 :            :         m_libspdm_use_measurement_hash_algo;
+     167                 :            : 
+     168                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     169                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     170                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     171                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     172                 :            :                                                     &data_size1, NULL, NULL);
+     173                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     174                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     175                 :            :         data_size1;
+     176                 :            : 
+     177                 :          1 :     libspdm_secret_lib_challenge_opaque_data_size = 0;
+     178                 :          1 :     libspdm_reset_message_c(spdm_context);
+     179                 :            : 
+     180                 :          1 :     response_size = sizeof(response);
+     181                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
+     182                 :            :                               m_libspdm_challenge_request1.nonce);
+     183                 :          1 :     status = libspdm_get_response_challenge_auth(
+     184                 :            :         spdm_context, m_libspdm_challenge_request1_size,
+     185                 :            :         &m_libspdm_challenge_request1, &response_size, response);
+     186                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     187                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     188                 :          1 :     spdm_response = (void *)response;
+     189                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     190                 :            :                      SPDM_ERROR);
+     191                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_BUSY);
+     192                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     193                 :          1 :     assert_int_equal(spdm_context->response_state,
+     194                 :            :                      LIBSPDM_RESPONSE_STATE_BUSY);
+     195                 :          1 :     free(data1);
+     196                 :          1 : }
+     197                 :            : 
+     198                 :            : /**
+     199                 :            :  * Test 4: receiving a correct CHALLENGE from the requester, but the responder requires
+     200                 :            :  * resynchronization with the requester.
+     201                 :            :  * Expected behavior: the responder accepts the request, but produces an ERROR message
+     202                 :            :  * indicating the NeedResynch state.
+     203                 :            :  **/
+     204                 :          1 : void libspdm_test_responder_challenge_auth_case4(void **state)
+     205                 :            : {
+     206                 :            :     libspdm_return_t status;
+     207                 :            :     libspdm_test_context_t *spdm_test_context;
+     208                 :            :     libspdm_context_t *spdm_context;
+     209                 :            :     size_t response_size;
+     210                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     211                 :            :     spdm_challenge_auth_response_t *spdm_response;
+     212                 :            :     void *data1;
+     213                 :            :     size_t data_size1;
+     214                 :            : 
+     215                 :          1 :     spdm_test_context = *state;
+     216                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     217                 :          1 :     spdm_test_context->case_id = 0x4;
+     218                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NEED_RESYNC;
+     219                 :          1 :     spdm_context->connection_info.connection_state =
+     220                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     221                 :          1 :     spdm_context->local_context.capability.flags = 0;
+     222                 :          1 :     spdm_context->local_context.capability.flags |=
+     223                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
+     224                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     225                 :            :         m_libspdm_use_hash_algo;
+     226                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     227                 :            :         m_libspdm_use_asym_algo;
+     228                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     229                 :            :         m_libspdm_use_measurement_spec;
+     230                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     231                 :            :         m_libspdm_use_measurement_hash_algo;
+     232                 :            : 
+     233                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     234                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     235                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     236                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     237                 :            :                                                     &data_size1, NULL, NULL);
+     238                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     239                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     240                 :            :         data_size1;
+     241                 :            : 
+     242                 :          1 :     libspdm_secret_lib_challenge_opaque_data_size = 0;
+     243                 :          1 :     libspdm_reset_message_c(spdm_context);
+     244                 :            : 
+     245                 :          1 :     response_size = sizeof(response);
+     246                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
+     247                 :            :                               m_libspdm_challenge_request1.nonce);
+     248                 :          1 :     status = libspdm_get_response_challenge_auth(
+     249                 :            :         spdm_context, m_libspdm_challenge_request1_size,
+     250                 :            :         &m_libspdm_challenge_request1, &response_size, response);
+     251                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     252                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     253                 :          1 :     spdm_response = (void *)response;
+     254                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     255                 :            :                      SPDM_ERROR);
+     256                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     257                 :            :                      SPDM_ERROR_CODE_REQUEST_RESYNCH);
+     258                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     259                 :          1 :     assert_int_equal(spdm_context->response_state,
+     260                 :            :                      LIBSPDM_RESPONSE_STATE_NEED_RESYNC);
+     261                 :          1 :     free(data1);
+     262                 :          1 : }
+     263                 :            : 
+     264                 :            : #if LIBSPDM_RESPOND_IF_READY_SUPPORT
+     265                 :            : /**
+     266                 :            :  * Test 5: receiving a correct CHALLENGE from the requester, but the responder could not
+     267                 :            :  * produce the response in time.
+     268                 :            :  * Expected behavior: the responder accepts the request, but produces an ERROR message
+     269                 :            :  * indicating the ResponseNotReady state.
+     270                 :            :  **/
+     271                 :          1 : void libspdm_test_responder_challenge_auth_case5(void **state)
+     272                 :            : {
+     273                 :            :     libspdm_return_t status;
+     274                 :            :     libspdm_test_context_t *spdm_test_context;
+     275                 :            :     libspdm_context_t *spdm_context;
+     276                 :            :     size_t response_size;
+     277                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     278                 :            :     spdm_challenge_auth_response_t *spdm_response;
+     279                 :            :     void *data1;
+     280                 :            :     size_t data_size1;
+     281                 :            :     spdm_error_data_response_not_ready_t *error_data;
+     282                 :            : 
+     283                 :          1 :     spdm_test_context = *state;
+     284                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     285                 :          1 :     spdm_test_context->case_id = 0x5;
+     286                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NOT_READY;
+     287                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     288                 :          1 :     spdm_context->local_context.capability.flags = 0;
+     289                 :          1 :     spdm_context->local_context.capability.flags |=
+     290                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
+     291                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     292                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     293                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+     294                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     295                 :            :         m_libspdm_use_measurement_hash_algo;
+     296                 :            : 
+     297                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     298                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     299                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     300                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     301                 :            :                                                     &data_size1, NULL, NULL);
+     302                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     303                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
+     304                 :            : 
+     305                 :          1 :     libspdm_secret_lib_challenge_opaque_data_size = 0;
+     306                 :          1 :     libspdm_reset_message_c(spdm_context);
+     307                 :            : 
+     308                 :          1 :     response_size = sizeof(response);
+     309                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE, m_libspdm_challenge_request1.nonce);
+     310                 :          1 :     status = libspdm_get_response_challenge_auth(
+     311                 :            :         spdm_context, m_libspdm_challenge_request1_size,
+     312                 :            :         &m_libspdm_challenge_request1, &response_size, response);
+     313                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     314                 :          1 :     assert_int_equal(response_size,
+     315                 :            :                      sizeof(spdm_error_response_t) +
+     316                 :            :                      sizeof(spdm_error_data_response_not_ready_t));
+     317                 :          1 :     spdm_response = (void *)response;
+     318                 :          1 :     error_data = (spdm_error_data_response_not_ready_t *)(spdm_response + 1);
+     319                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
+     320                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_RESPONSE_NOT_READY);
+     321                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     322                 :          1 :     assert_int_equal(spdm_context->response_state, LIBSPDM_RESPONSE_STATE_NOT_READY);
+     323                 :          1 :     assert_int_equal(error_data->request_code, SPDM_CHALLENGE);
+     324                 :          1 :     free(data1);
+     325                 :          1 : }
+     326                 :            : #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
+     327                 :            : 
+     328                 :            : /**
+     329                 :            :  * Test 6: receiving a correct CHALLENGE from the requester, but the responder is not set
+     330                 :            :  * no receive a CHALLENGE message because previous messages (namely, GET_CAPABILITIES,
+     331                 :            :  * NEGOTIATE_ALGORITHMS or GET_DIGESTS) have not been received.
+     332                 :            :  * Expected behavior: the responder rejects the request, and produces an ERROR message
+     333                 :            :  * indicating the UnexpectedRequest.
+     334                 :            :  **/
+     335                 :          1 : void libspdm_test_responder_challenge_auth_case6(void **state)
+     336                 :            : {
+     337                 :            :     libspdm_return_t status;
+     338                 :            :     libspdm_test_context_t *spdm_test_context;
+     339                 :            :     libspdm_context_t *spdm_context;
+     340                 :            :     size_t response_size;
+     341                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     342                 :            :     spdm_challenge_auth_response_t *spdm_response;
+     343                 :            :     void *data1;
+     344                 :            :     size_t data_size1;
+     345                 :            : 
+     346                 :          1 :     spdm_test_context = *state;
+     347                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     348                 :          1 :     spdm_test_context->case_id = 0x6;
+     349                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+     350                 :          1 :     spdm_context->connection_info.connection_state =
+     351                 :            :         LIBSPDM_CONNECTION_STATE_NOT_STARTED;
+     352                 :          1 :     spdm_context->local_context.capability.flags = 0;
+     353                 :          1 :     spdm_context->local_context.capability.flags |=
+     354                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
+     355                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     356                 :            :         m_libspdm_use_hash_algo;
+     357                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     358                 :            :         m_libspdm_use_asym_algo;
+     359                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     360                 :            :         m_libspdm_use_measurement_spec;
+     361                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     362                 :            :         m_libspdm_use_measurement_hash_algo;
+     363                 :            : 
+     364                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     365                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     366                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     367                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     368                 :            :                                                     &data_size1, NULL, NULL);
+     369                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     370                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     371                 :            :         data_size1;
+     372                 :            : 
+     373                 :          1 :     libspdm_secret_lib_challenge_opaque_data_size = 0;
+     374                 :          1 :     libspdm_reset_message_c(spdm_context);
+     375                 :            : 
+     376                 :          1 :     response_size = sizeof(response);
+     377                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
+     378                 :            :                               m_libspdm_challenge_request1.nonce);
+     379                 :          1 :     status = libspdm_get_response_challenge_auth(
+     380                 :            :         spdm_context, m_libspdm_challenge_request1_size,
+     381                 :            :         &m_libspdm_challenge_request1, &response_size, response);
+     382                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     383                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     384                 :          1 :     spdm_response = (void *)response;
+     385                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     386                 :            :                      SPDM_ERROR);
+     387                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     388                 :            :                      SPDM_ERROR_CODE_UNEXPECTED_REQUEST);
+     389                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     390                 :          1 :     free(data1);
+     391                 :          1 : }
+     392                 :            : 
+     393                 :            : /**
+     394                 :            :  * Test 7: receiving a correct CHALLENGE from the requester, but the responder does not
+     395                 :            :  * have the challenge capability set.
+     396                 :            :  * Expected behavior: the responder accepts the request and produces a valid
+     397                 :            :  * CHALLENGE_AUTH response message.
+     398                 :            :  **/
+     399                 :          1 : void libspdm_test_responder_challenge_auth_case7(void **state) {
+     400                 :            :     libspdm_return_t status;
+     401                 :            :     libspdm_test_context_t    *spdm_test_context;
+     402                 :            :     libspdm_context_t  *spdm_context;
+     403                 :            :     size_t response_size;
+     404                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     405                 :            :     spdm_challenge_auth_response_t *spdm_response;
+     406                 :            :     void                 *data1;
+     407                 :            :     size_t data_size1;
+     408                 :            : 
+     409                 :          1 :     spdm_test_context = *state;
+     410                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     411                 :          1 :     spdm_test_context->case_id = 0x7;
+     412                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     413                 :          1 :     spdm_context->local_context.capability.flags = 0;
+     414                 :            :     /* spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;*/
+     415                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     416                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     417                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+     418                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     419                 :            :         m_libspdm_use_measurement_hash_algo;
+     420                 :            : 
+     421                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     422                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     423                 :          1 :     libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
+     424                 :            :                                                      m_libspdm_use_asym_algo,
+     425                 :            :                                                      &data1, &data_size1,
+     426                 :            :                                                      NULL, NULL);
+     427                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     428                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
+     429                 :            : 
+     430                 :          1 :     libspdm_secret_lib_challenge_opaque_data_size = 0;
+     431                 :          1 :     libspdm_reset_message_c(spdm_context);
+     432                 :            : 
+     433                 :          1 :     response_size = sizeof(response);
+     434                 :          1 :     libspdm_get_random_number (SPDM_NONCE_SIZE, m_libspdm_challenge_request1.nonce);
+     435                 :          1 :     status = libspdm_get_response_challenge_auth (spdm_context, m_libspdm_challenge_request1_size,
+     436                 :            :                                                   &m_libspdm_challenge_request1, &response_size,
+     437                 :            :                                                   response);
+     438                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     439                 :          1 :     assert_int_equal (response_size, sizeof(spdm_error_response_t));
+     440                 :          1 :     spdm_response = (void *)response;
+     441                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_ERROR);
+     442                 :          1 :     assert_int_equal (spdm_response->header.param1, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST);
+     443                 :          1 :     assert_int_equal (spdm_response->header.param2, SPDM_CHALLENGE);
+     444                 :          1 :     free(data1);
+     445                 :          1 : }
+     446                 :            : 
+     447                 :            : /**
+     448                 :            :  * Test 8: receiving an incorrect CHALLENGE from the requester, with the slot number
+     449                 :            :  * larger than the specification limit.
+     450                 :            :  * Expected behavior: the responder rejects the request, and produces an ERROR message
+     451                 :            :  * indicating the UnexpectedRequest.
+     452                 :            :  **/
+     453                 :          1 : void libspdm_test_responder_challenge_auth_case8(void **state) {
+     454                 :            :     libspdm_return_t status;
+     455                 :            :     libspdm_test_context_t    *spdm_test_context;
+     456                 :            :     libspdm_context_t  *spdm_context;
+     457                 :            :     size_t response_size;
+     458                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     459                 :            :     spdm_challenge_auth_response_t *spdm_response;
+     460                 :            :     void                 *data1;
+     461                 :            :     size_t data_size1;
+     462                 :            : 
+     463                 :          1 :     spdm_test_context = *state;
+     464                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     465                 :          1 :     spdm_test_context->case_id = 0x8;
+     466                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     467                 :          1 :     spdm_context->local_context.capability.flags = 0;
+     468                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
+     469                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     470                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     471                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+     472                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     473                 :            :         m_libspdm_use_measurement_hash_algo;
+     474                 :            : 
+     475                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     476                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     477                 :          1 :     libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
+     478                 :            :                                                      m_libspdm_use_asym_algo,
+     479                 :            :                                                      &data1, &data_size1,
+     480                 :            :                                                      NULL, NULL);
+     481                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     482                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
+     483                 :            : 
+     484                 :          1 :     libspdm_secret_lib_challenge_opaque_data_size = 0;
+     485                 :          1 :     libspdm_reset_message_c(spdm_context);
+     486                 :            : 
+     487                 :          1 :     response_size = sizeof(response);
+     488                 :          1 :     libspdm_get_random_number (SPDM_NONCE_SIZE, m_libspdm_challenge_request3.nonce);
+     489                 :          1 :     status = libspdm_get_response_challenge_auth (spdm_context, m_libspdm_challenge_request3_size,
+     490                 :            :                                                   &m_libspdm_challenge_request3, &response_size,
+     491                 :            :                                                   response);
+     492                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     493                 :          1 :     assert_int_equal (response_size, sizeof(spdm_error_response_t));
+     494                 :          1 :     spdm_response = (void *)response;
+     495                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_ERROR);
+     496                 :          1 :     assert_int_equal (spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+     497                 :          1 :     assert_int_equal (spdm_response->header.param2, 0);
+     498                 :          1 :     free(data1);
+     499                 :          1 : }
+     500                 :            : 
+     501                 :            : /**
+     502                 :            :  * Test 9: eceiving a correct CHALLENGE message from the requester with
+     503                 :            :  * no opaque data, no measurements, and slot number 1.
+     504                 :            :  * Expected behavior: the responder accepts the request and produces a valid
+     505                 :            :  * CHALLENGE_AUTH response message.
+     506                 :            :  **/
+     507                 :          1 : void libspdm_test_responder_challenge_auth_case9(void **state) {
+     508                 :            :     libspdm_return_t status;
+     509                 :            :     libspdm_test_context_t    *spdm_test_context;
+     510                 :            :     libspdm_context_t  *spdm_context;
+     511                 :            :     size_t response_size;
+     512                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     513                 :            :     spdm_challenge_auth_response_t *spdm_response;
+     514                 :            :     void                 *data1;
+     515                 :            :     size_t data_size1;
+     516                 :            :     size_t index;
+     517                 :            :     uint8_t slot_mask;
+     518                 :            : 
+     519                 :          1 :     spdm_test_context = *state;
+     520                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     521                 :          1 :     spdm_test_context->case_id = 0x9;
+     522                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     523                 :          1 :     spdm_context->local_context.capability.flags = 0;
+     524                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
+     525                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     526                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     527                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+     528                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     529                 :            :         m_libspdm_use_measurement_hash_algo;
+     530                 :            : 
+     531                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     532                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     533                 :          1 :     libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
+     534                 :            :                                                      m_libspdm_use_asym_algo,
+     535                 :            :                                                      &data1, &data_size1,
+     536                 :            :                                                      NULL, NULL);
+     537                 :          1 :     spdm_context->local_context.local_cert_chain_provision[1] = data1;
+     538                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[1] = data_size1;
+     539                 :          1 :     libspdm_secret_lib_challenge_opaque_data_size = 0;
+     540                 :          1 :     libspdm_reset_message_c(spdm_context);
+     541                 :            : 
+     542                 :          1 :     response_size = sizeof(response);
+     543                 :          1 :     libspdm_get_random_number (SPDM_NONCE_SIZE, m_libspdm_challenge_request4.nonce);
+     544                 :          1 :     status = libspdm_get_response_challenge_auth (spdm_context, m_libspdm_challenge_request4_size,
+     545                 :            :                                                   &m_libspdm_challenge_request4, &response_size,
+     546                 :            :                                                   response);
+     547                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     548                 :          1 :     assert_int_equal (response_size, sizeof(spdm_challenge_auth_response_t) + libspdm_get_hash_size (
+     549                 :            :                           m_libspdm_use_hash_algo) + SPDM_NONCE_SIZE + 0 + sizeof(uint16_t) + 0 + libspdm_get_asym_signature_size (
+     550                 :            :                           m_libspdm_use_asym_algo));
+     551                 :          1 :     spdm_response = (void *)response;
+     552                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_CHALLENGE_AUTH);
+     553                 :          1 :     assert_int_equal (spdm_response->header.param1, 1);
+     554                 :            : 
+     555                 :          1 :     slot_mask = 0;
+     556         [ +  + ]:          9 :     for (index = 0; index < SPDM_MAX_SLOT_COUNT; index++) {
+     557                 :          8 :         if (spdm_context->local_context
+     558         [ +  + ]:          8 :             .local_cert_chain_provision[index] != NULL) {
+     559                 :          2 :             slot_mask |= (1 << index);
+     560                 :            :         }
+     561                 :            :     }
+     562                 :          1 :     assert_int_equal (spdm_response->header.param2, slot_mask);
+     563                 :          1 :     free(data1);
+     564                 :          1 : }
+     565                 :            : 
+     566                 :            : /**
+     567                 :            :  * Test 10: receiving a correct CHALLENGE from the requester, but with certificate
+     568                 :            :  * unavailable at the requested slot number (1).
+     569                 :            :  * Expected behavior: the responder rejects the request, and produces an ERROR message
+     570                 :            :  * indicating the UnexpectedRequest.
+     571                 :            :  **/
+     572                 :          1 : void libspdm_test_responder_challenge_auth_case10(void **state) {
+     573                 :            :     libspdm_return_t status;
+     574                 :            :     libspdm_test_context_t    *spdm_test_context;
+     575                 :            :     libspdm_context_t  *spdm_context;
+     576                 :            :     size_t response_size;
+     577                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     578                 :            :     spdm_challenge_auth_response_t *spdm_response;
+     579                 :            :     void                 *data1;
+     580                 :            :     size_t data_size1;
+     581                 :            :     size_t index;
+     582                 :            : 
+     583                 :          1 :     spdm_test_context = *state;
+     584                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     585                 :          1 :     spdm_test_context->case_id = 0xA;
+     586                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     587                 :          1 :     spdm_context->local_context.capability.flags = 0;
+     588                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
+     589                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     590                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     591                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+     592                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     593                 :            :         m_libspdm_use_measurement_hash_algo;
+     594                 :            : 
+     595                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     596                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     597                 :          1 :     libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
+     598                 :            :                                                      m_libspdm_use_asym_algo,
+     599                 :            :                                                      &data1, &data_size1,
+     600                 :            :                                                      NULL, NULL);
+     601                 :            :     /*clear local_cert_chain_provision*/
+     602         [ +  + ]:          9 :     for (index = 0; index <SPDM_MAX_SLOT_COUNT; index++) {
+     603                 :          8 :         spdm_context->local_context.local_cert_chain_provision[index] = NULL;
+     604                 :          8 :         spdm_context->local_context.local_cert_chain_provision_size[index] = 0;
+     605                 :            :     }
+     606                 :            : 
+     607                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     608                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
+     609                 :            : 
+     610                 :          1 :     libspdm_secret_lib_challenge_opaque_data_size = 0;
+     611                 :          1 :     libspdm_reset_message_c(spdm_context);
+     612                 :            : 
+     613                 :          1 :     response_size = sizeof(response);
+     614                 :          1 :     libspdm_get_random_number (SPDM_NONCE_SIZE, m_libspdm_challenge_request4.nonce);
+     615                 :          1 :     status = libspdm_get_response_challenge_auth (spdm_context, m_libspdm_challenge_request4_size,
+     616                 :            :                                                   &m_libspdm_challenge_request4, &response_size,
+     617                 :            :                                                   response);
+     618                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     619                 :          1 :     assert_int_equal (response_size, sizeof(spdm_error_response_t));
+     620                 :          1 :     spdm_response = (void *)response;
+     621                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_ERROR);
+     622                 :          1 :     assert_int_equal (spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+     623                 :          1 :     assert_int_equal (spdm_response->header.param2, 0);
+     624                 :          1 :     free(data1);
+     625                 :          1 : }
+     626                 :            : 
+     627                 :            : /**
+     628                 :            :  * Test 11: receiving a correct CHALLENGE message from the requester with opaque
+     629                 :            :  * data as the bytes of the string "libspdm", no measurements, and slot number 0.
+     630                 :            :  * Expected behavior: the responder accepts the request and produces a valid
+     631                 :            :  * CHALLENGE_AUTH response message.
+     632                 :            :  **/
+     633                 :          1 : void libspdm_test_responder_challenge_auth_case11(void **state) {
+     634                 :            :     libspdm_return_t status;
+     635                 :            :     libspdm_test_context_t    *spdm_test_context;
+     636                 :            :     libspdm_context_t  *spdm_context;
+     637                 :            :     size_t response_size;
+     638                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     639                 :            :     spdm_challenge_auth_response_t *spdm_response;
+     640                 :            :     void                 *data1;
+     641                 :            :     size_t data_size1;
+     642                 :            : 
+     643                 :          1 :     spdm_test_context = *state;
+     644                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     645                 :          1 :     spdm_test_context->case_id = 0xB;
+     646                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     647                 :          1 :     spdm_context->local_context.capability.flags = 0;
+     648                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
+     649                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     650                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     651                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+     652                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     653                 :            :         m_libspdm_use_measurement_hash_algo;
+     654                 :            : 
+     655                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     656                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     657                 :          1 :     libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
+     658                 :            :                                                      m_libspdm_use_asym_algo,
+     659                 :            :                                                      &data1, &data_size1,
+     660                 :            :                                                      NULL, NULL);
+     661                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     662                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
+     663                 :            : 
+     664                 :          1 :     libspdm_secret_lib_challenge_opaque_data_size = 8;
+     665                 :          1 :     libspdm_reset_message_c(spdm_context);
+     666                 :            : 
+     667                 :          1 :     response_size = sizeof(response);
+     668                 :          1 :     libspdm_get_random_number (SPDM_NONCE_SIZE, m_libspdm_challenge_request1.nonce);
+     669                 :          1 :     status = libspdm_get_response_challenge_auth (spdm_context, m_libspdm_challenge_request1_size,
+     670                 :            :                                                   &m_libspdm_challenge_request1, &response_size,
+     671                 :            :                                                   response);
+     672                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     673                 :          1 :     assert_int_equal (response_size, sizeof(spdm_challenge_auth_response_t) + libspdm_get_hash_size (
+     674                 :            :                           m_libspdm_use_hash_algo) + SPDM_NONCE_SIZE + 0 + sizeof(uint16_t) + 8 + libspdm_get_asym_signature_size (
+     675                 :            :                           m_libspdm_use_asym_algo));
+     676                 :          1 :     spdm_response = (void *)response;
+     677                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_CHALLENGE_AUTH);
+     678                 :          1 :     assert_int_equal (spdm_response->header.param1, 0);
+     679                 :          1 :     assert_int_equal (spdm_response->header.param2, 1 << 0);
+     680                 :          1 :     free(data1);
+     681                 :          1 : }
+     682                 :            : 
+     683                 :            : /**
+     684                 :            :  * Test 12: receiving a correct CHALLENGE message from the requester with
+     685                 :            :  * no opaque data, TCB measurement hash, and slot number 0.
+     686                 :            :  * Expected behavior: the responder accepts the request and produces a valid
+     687                 :            :  * CHALLENGE_AUTH response message.
+     688                 :            :  **/
+     689                 :          1 : void libspdm_test_responder_challenge_auth_case12(void **state) {
+     690                 :            :     libspdm_return_t status;
+     691                 :            :     libspdm_test_context_t    *spdm_test_context;
+     692                 :            :     libspdm_context_t  *spdm_context;
+     693                 :            :     size_t response_size;
+     694                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     695                 :            :     spdm_challenge_auth_response_t *spdm_response;
+     696                 :            :     void                 *data1;
+     697                 :            :     size_t data_size1;
+     698                 :            : 
+     699                 :          1 :     spdm_test_context = *state;
+     700                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     701                 :          1 :     spdm_test_context->case_id = 0xC;
+     702                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     703                 :          1 :     spdm_context->local_context.capability.flags = 0;
+     704                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
+     705                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP; /*additional measurement capability*/
+     706                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     707                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     708                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+     709                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     710                 :            :         m_libspdm_use_measurement_hash_algo;
+     711                 :            : 
+     712                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     713                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     714                 :          1 :     libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
+     715                 :            :                                                      m_libspdm_use_asym_algo,
+     716                 :            :                                                      &data1, &data_size1,
+     717                 :            :                                                      NULL, NULL);
+     718                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     719                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
+     720                 :            : 
+     721                 :          1 :     libspdm_secret_lib_challenge_opaque_data_size = 0;
+     722                 :          1 :     libspdm_reset_message_c(spdm_context);
+     723                 :            : 
+     724                 :          1 :     response_size = sizeof(response);
+     725                 :          1 :     libspdm_get_random_number (SPDM_NONCE_SIZE, m_libspdm_challenge_request5.nonce);
+     726                 :          1 :     status = libspdm_get_response_challenge_auth (spdm_context, m_libspdm_challenge_request5_size,
+     727                 :            :                                                   &m_libspdm_challenge_request5, &response_size,
+     728                 :            :                                                   response);
+     729                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     730                 :          1 :     assert_int_equal (response_size, sizeof(spdm_challenge_auth_response_t) + libspdm_get_hash_size (
+     731                 :            :                           m_libspdm_use_hash_algo) + SPDM_NONCE_SIZE +
+     732                 :            :                       libspdm_get_hash_size (m_libspdm_use_hash_algo) +
+     733                 :            :                       sizeof(uint16_t) + 0 +
+     734                 :            :                       libspdm_get_asym_signature_size (m_libspdm_use_asym_algo));
+     735                 :          1 :     spdm_response = (void *)response;
+     736                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_CHALLENGE_AUTH);
+     737                 :          1 :     assert_int_equal (spdm_response->header.param1, 0);
+     738                 :          1 :     assert_int_equal (spdm_response->header.param2, 1 << 0);
+     739                 :          1 :     free(data1);
+     740                 :          1 : }
+     741                 :            : 
+     742                 :            : /**
+     743                 :            :  * Test 13: receiving a correct CHALLENGE message from the requester with
+     744                 :            :  * no opaque data, all measurement hashes, and slot number 0.
+     745                 :            :  * Expected behavior: the responder accepts the request and produces a valid
+     746                 :            :  * CHALLENGE_AUTH response message.
+     747                 :            :  **/
+     748                 :          1 : void libspdm_test_responder_challenge_auth_case13(void **state) {
+     749                 :            :     libspdm_return_t status;
+     750                 :            :     libspdm_test_context_t    *spdm_test_context;
+     751                 :            :     libspdm_context_t  *spdm_context;
+     752                 :            :     size_t response_size;
+     753                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     754                 :            :     spdm_challenge_auth_response_t *spdm_response;
+     755                 :            :     void                 *data1;
+     756                 :            :     size_t data_size1;
+     757                 :            : 
+     758                 :          1 :     spdm_test_context = *state;
+     759                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     760                 :          1 :     spdm_test_context->case_id = 0xD;
+     761                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     762                 :          1 :     spdm_context->local_context.capability.flags = 0;
+     763                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
+     764                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP; /*additional measurement capability*/
+     765                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     766                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     767                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+     768                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     769                 :            :         m_libspdm_use_measurement_hash_algo;
+     770                 :            : 
+     771                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     772                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     773                 :          1 :     libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
+     774                 :            :                                                      m_libspdm_use_asym_algo,
+     775                 :            :                                                      &data1, &data_size1,
+     776                 :            :                                                      NULL, NULL);
+     777                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     778                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
+     779                 :            : 
+     780                 :          1 :     libspdm_secret_lib_challenge_opaque_data_size = 0;
+     781                 :          1 :     libspdm_reset_message_c(spdm_context);
+     782                 :            : 
+     783                 :          1 :     response_size = sizeof(response);
+     784                 :          1 :     libspdm_get_random_number (SPDM_NONCE_SIZE, m_libspdm_challenge_request6.nonce);
+     785                 :          1 :     status = libspdm_get_response_challenge_auth (spdm_context, m_libspdm_challenge_request6_size,
+     786                 :            :                                                   &m_libspdm_challenge_request6, &response_size,
+     787                 :            :                                                   response);
+     788                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     789                 :          1 :     assert_int_equal (response_size, sizeof(spdm_challenge_auth_response_t) + libspdm_get_hash_size (
+     790                 :            :                           m_libspdm_use_hash_algo) + SPDM_NONCE_SIZE +
+     791                 :            :                       libspdm_get_hash_size (m_libspdm_use_hash_algo) +
+     792                 :            :                       sizeof(uint16_t) + 0 +
+     793                 :            :                       libspdm_get_asym_signature_size (m_libspdm_use_asym_algo));
+     794                 :          1 :     spdm_response = (void *)response;
+     795                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_CHALLENGE_AUTH);
+     796                 :          1 :     assert_int_equal (spdm_response->header.param1, 0);
+     797                 :          1 :     assert_int_equal (spdm_response->header.param2, 1 << 0);
+     798                 :          1 :     free(data1);
+     799                 :          1 : }
+     800                 :            : 
+     801                 :            : /**
+     802                 :            :  * Test 14: the responder does not have measurements capabilities, but
+     803                 :            :  * receives a correct CHALLENGE message from the requester with
+     804                 :            :  * no opaque data, all measurement hashes, and slot number 0.
+     805                 :            :  * Expected behavior: the responder refuses the CHALLENGE message and produces an
+     806                 :            :  * ERROR message indicating the InvalidRequest.
+     807                 :            :  **/
+     808                 :          1 : void libspdm_test_responder_challenge_auth_case14(void **state) {
+     809                 :            :     libspdm_return_t status;
+     810                 :            :     libspdm_test_context_t    *spdm_test_context;
+     811                 :            :     libspdm_context_t  *spdm_context;
+     812                 :            :     size_t response_size;
+     813                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     814                 :            :     spdm_challenge_auth_response_t *spdm_response;
+     815                 :            :     void                 *data1;
+     816                 :            :     size_t data_size1;
+     817                 :            : 
+     818                 :          1 :     spdm_test_context = *state;
+     819                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     820                 :          1 :     spdm_test_context->case_id = 0xE;
+     821                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     822                 :          1 :     spdm_context->local_context.capability.flags = 0;
+     823                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
+     824                 :            :     /* spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP;   no measurement capability*/
+     825                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     826                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     827                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+     828                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     829                 :            :         m_libspdm_use_measurement_hash_algo;
+     830                 :            : 
+     831                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     832                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     833                 :          1 :     libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
+     834                 :            :                                                      m_libspdm_use_asym_algo,
+     835                 :            :                                                      &data1, &data_size1,
+     836                 :            :                                                      NULL, NULL);
+     837                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     838                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
+     839                 :            : 
+     840                 :          1 :     libspdm_secret_lib_challenge_opaque_data_size = 0;
+     841                 :          1 :     libspdm_reset_message_c(spdm_context);
+     842                 :            : 
+     843                 :          1 :     response_size = sizeof(response);
+     844                 :          1 :     libspdm_get_random_number (SPDM_NONCE_SIZE, m_libspdm_challenge_request6.nonce);
+     845                 :          1 :     status = libspdm_get_response_challenge_auth (spdm_context, m_libspdm_challenge_request6_size,
+     846                 :            :                                                   &m_libspdm_challenge_request6, &response_size,
+     847                 :            :                                                   response);
+     848                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     849                 :          1 :     assert_int_equal (response_size, sizeof(spdm_error_response_t));
+     850                 :          1 :     spdm_response = (void *)response;
+     851                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_ERROR);
+     852                 :          1 :     assert_int_equal (spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+     853                 :          1 :     assert_int_equal (spdm_response->header.param2, 0);
+     854                 :          1 :     free(data1);
+     855                 :          1 : }
+     856                 :            : 
+     857                 :            : /**
+     858                 :            :  * Test 15: receiving a correct CHALLENGE from the requester. Buffers A, B and
+     859                 :            :  * C already have arbitrary data.
+     860                 :            :  * Expected behavior: the responder accepts the request and produces a valid
+     861                 :            :  * CHALLENGE_AUTH response message, and buffer C receives the exchanged CHALLENGE
+     862                 :            :  * and CHALLENGE_AUTH (without signature) messages.
+     863                 :            :  **/
+     864                 :          1 : void libspdm_test_responder_challenge_auth_case15(void **state)
+     865                 :            : {
+     866                 :            :     libspdm_return_t status;
+     867                 :            :     libspdm_test_context_t *spdm_test_context;
+     868                 :            :     libspdm_context_t *spdm_context;
+     869                 :            :     size_t response_size;
+     870                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     871                 :            :     spdm_challenge_auth_response_t *spdm_response;
+     872                 :            :     void *data1;
+     873                 :            :     size_t data_size1;
+     874                 :            : 
+     875                 :          1 :     spdm_test_context = *state;
+     876                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     877                 :          1 :     spdm_test_context->case_id = 0xF;
+     878                 :          1 :     spdm_context->connection_info.connection_state =
+     879                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     880                 :          1 :     spdm_context->local_context.capability.flags = 0;
+     881                 :          1 :     spdm_context->local_context.capability.flags |=
+     882                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
+     883                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     884                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     885                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+     886                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     887                 :            :         m_libspdm_use_measurement_hash_algo;
+     888                 :            : 
+     889                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     890                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     891                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     892                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     893                 :            :                                                     &data_size1, NULL, NULL);
+     894                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     895                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
+     896                 :            : 
+     897                 :          1 :     libspdm_secret_lib_challenge_opaque_data_size = 0;
+     898                 :          1 :     libspdm_reset_message_c(spdm_context);
+     899                 :            : 
+     900                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     901                 :            :     /*filling buffers with arbitrary data*/
+     902                 :            :     libspdm_set_mem(spdm_context->transcript.message_a.buffer, 10, (uint8_t) 0xFF);
+     903                 :            :     spdm_context->transcript.message_a.buffer_size = 10;
+     904                 :            :     libspdm_set_mem(spdm_context->transcript.message_b.buffer, 8, (uint8_t) 0xEE);
+     905                 :            :     spdm_context->transcript.message_b.buffer_size = 8;
+     906                 :            :     libspdm_set_mem(spdm_context->transcript.message_c.buffer, 12, (uint8_t) 0xDD);
+     907                 :            :     spdm_context->transcript.message_c.buffer_size = 12;
+     908                 :            : #endif
+     909                 :            : 
+     910                 :          1 :     response_size = sizeof(response);
+     911                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE, m_libspdm_challenge_request1.nonce);
+     912                 :          1 :     status = libspdm_get_response_challenge_auth(
+     913                 :            :         spdm_context, m_libspdm_challenge_request1_size,
+     914                 :            :         &m_libspdm_challenge_request1, &response_size, response);
+     915                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     916                 :          1 :     assert_int_equal(response_size,
+     917                 :            :                      sizeof(spdm_challenge_auth_response_t) +
+     918                 :            :                      libspdm_get_hash_size(m_libspdm_use_hash_algo) +
+     919                 :            :                      SPDM_NONCE_SIZE + 0 + sizeof(uint16_t) + 0 +
+     920                 :            :                      libspdm_get_asym_signature_size(m_libspdm_use_asym_algo));
+     921                 :          1 :     spdm_response = (void *)response;
+     922                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_CHALLENGE_AUTH);
+     923                 :          1 :     assert_int_equal(spdm_response->header.param1, 0);
+     924                 :          1 :     assert_int_equal(spdm_response->header.param2, 1 << 0);
+     925                 :            : 
+     926                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     927                 :            :     assert_int_equal(spdm_context->transcript.message_a.buffer_size, 10);
+     928                 :            : #endif
+     929                 :          1 :     free(data1);
+     930                 :          1 : }
+     931                 :            : 
+     932                 :            : /**
+     933                 :            :  * Test 16: Receive a CHALLENGE request within a secure session.
+     934                 :            :  * Expected behavior: the Responder replies with error UnexpectedRequest as that is not legal.
+     935                 :            :  **/
+     936                 :          1 : void libspdm_test_responder_challenge_auth_case16(void **state)
+     937                 :            : {
+     938                 :            :     libspdm_return_t status;
+     939                 :            :     libspdm_test_context_t *spdm_test_context;
+     940                 :            :     libspdm_context_t *spdm_context;
+     941                 :            :     size_t response_size;
+     942                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     943                 :            :     spdm_challenge_auth_response_t *spdm_response;
+     944                 :            :     libspdm_session_info_t *session_info;
+     945                 :            :     uint32_t session_id;
+     946                 :            : 
+     947                 :          1 :     spdm_test_context = *state;
+     948                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     949                 :          1 :     spdm_test_context->case_id = 0x10;
+     950                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     951                 :          1 :     spdm_context->local_context.capability.flags = 0;
+     952                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
+     953                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     954                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     955                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+     956                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     957                 :            :         m_libspdm_use_measurement_hash_algo;
+     958                 :            : 
+     959                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     960                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     961                 :            : 
+     962                 :          1 :     session_id = 0xFFFFFFFF;
+     963                 :          1 :     spdm_context->latest_session_id = session_id;
+     964                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+     965                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+     966                 :          1 :     session_info = &spdm_context->session_info[0];
+     967                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+     968                 :          1 :     libspdm_secured_message_set_session_state(
+     969                 :            :         session_info->secured_message_context, LIBSPDM_SESSION_STATE_ESTABLISHED);
+     970                 :            : 
+     971                 :          1 :     response_size = sizeof(response);
+     972                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE, m_libspdm_challenge_request1.nonce);
+     973                 :          1 :     status = libspdm_get_response_challenge_auth(
+     974                 :            :         spdm_context, m_libspdm_challenge_request1_size,
+     975                 :            :         &m_libspdm_challenge_request1, &response_size, response);
+     976                 :            : 
+     977                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     978                 :          1 :     assert_int_equal (response_size, sizeof(spdm_error_response_t));
+     979                 :          1 :     spdm_response = (void *)response;
+     980                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_ERROR);
+     981                 :          1 :     assert_int_equal (spdm_response->header.param1, SPDM_ERROR_CODE_UNEXPECTED_REQUEST);
+     982                 :          1 :     assert_int_equal (spdm_response->header.param2, 0);
+     983                 :            : 
+     984                 :            :     /* Clear session */
+     985                 :          1 :     libspdm_free_session_id(spdm_context, 0xFFFFFFFF);
+     986                 :          1 :     spdm_context->latest_session_id = 0;
+     987                 :          1 :     spdm_context->last_spdm_request_session_id_valid = false;
+     988                 :          1 : }
+     989                 :            : 
+     990                 :            : /**
+     991                 :            :  * Test 16: receiving a correct CHALLENGE message from the requester with
+     992                 :            :  * slot number 0xFF.
+     993                 :            :  * Expected behavior: the responder accepts the request and produces a valid
+     994                 :            :  * CHALLENGE_AUTH response message.
+     995                 :            :  **/
+     996                 :          1 : void libspdm_test_responder_challenge_auth_case17(void **state)
+     997                 :            : {
+     998                 :            :     libspdm_return_t status;
+     999                 :            :     libspdm_test_context_t *spdm_test_context;
+    1000                 :            :     libspdm_context_t *spdm_context;
+    1001                 :            :     size_t response_size;
+    1002                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1003                 :            :     spdm_challenge_auth_response_t *spdm_response;
+    1004                 :            :     void *data1;
+    1005                 :            :     size_t data_size1;
+    1006                 :            : 
+    1007                 :          1 :     spdm_test_context = *state;
+    1008                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1009                 :          1 :     spdm_test_context->case_id = 0x11;
+    1010                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1011                 :          1 :     spdm_context->local_context.capability.flags = 0;
+    1012                 :          1 :     spdm_context->local_context.capability.flags |=
+    1013                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
+    1014                 :          1 :     spdm_context->local_context.capability.flags |=
+    1015                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PUB_KEY_ID_CAP;
+    1016                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1017                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1018                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+    1019                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1020                 :            :         m_libspdm_use_measurement_hash_algo;
+    1021                 :            : 
+    1022                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1023                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1024                 :          1 :     libspdm_read_responder_public_key(m_libspdm_use_asym_algo, &data1, &data_size1);
+    1025                 :          1 :     spdm_context->local_context.local_public_key_provision = data1;
+    1026                 :          1 :     spdm_context->local_context.local_public_key_provision_size = data_size1;
+    1027                 :            : 
+    1028                 :          1 :     libspdm_secret_lib_challenge_opaque_data_size = 0;
+    1029                 :          1 :     libspdm_reset_message_c(spdm_context);
+    1030                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1031                 :            :     spdm_context->transcript.message_m.buffer_size =
+    1032                 :            :         spdm_context->transcript.message_m.max_buffer_size;
+    1033                 :            : #endif
+    1034                 :            : 
+    1035                 :          1 :     response_size = sizeof(response);
+    1036                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
+    1037                 :            :                               m_libspdm_challenge_request7.nonce);
+    1038                 :          1 :     status = libspdm_get_response_challenge_auth(
+    1039                 :            :         spdm_context, m_libspdm_challenge_request7_size,
+    1040                 :            :         &m_libspdm_challenge_request7, &response_size, response);
+    1041                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1042                 :          1 :     assert_int_equal(response_size,
+    1043                 :            :                      sizeof(spdm_challenge_auth_response_t) +
+    1044                 :            :                      libspdm_get_hash_size(m_libspdm_use_hash_algo) +
+    1045                 :            :                      SPDM_NONCE_SIZE + 0 + sizeof(uint16_t) + 0 +
+    1046                 :            :                      libspdm_get_asym_signature_size(m_libspdm_use_asym_algo));
+    1047                 :          1 :     spdm_response = (void *)response;
+    1048                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1049                 :            :                      SPDM_CHALLENGE_AUTH);
+    1050                 :          1 :     assert_int_equal(spdm_response->header.param1, 0xF);
+    1051                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1052                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1053                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+    1054                 :            : #endif
+    1055                 :          1 :     free(data1);
+    1056                 :          1 : }
+    1057                 :            : 
+    1058                 :            : /**
+    1059                 :            :  * Test 18: Successfully reply to V1.3 to get CHALLENGE message with context field
+    1060                 :            :  * no opaque data, no measurements, and slot number 0.
+    1061                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code, correct context field
+    1062                 :            :  **/
+    1063                 :          1 : void libspdm_test_responder_challenge_auth_case18(void **state)
+    1064                 :            : {
+    1065                 :            :     libspdm_return_t status;
+    1066                 :            :     libspdm_test_context_t *spdm_test_context;
+    1067                 :            :     libspdm_context_t *spdm_context;
+    1068                 :            :     size_t response_size;
+    1069                 :            :     uint8_t request[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1070                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1071                 :            : 
+    1072                 :            :     spdm_challenge_auth_response_t *spdm_response;
+    1073                 :            :     void *data1;
+    1074                 :            :     size_t data_size1;
+    1075                 :            :     uint8_t *requester_context;
+    1076                 :            :     uint8_t *responder_context;
+    1077                 :            : 
+    1078                 :          1 :     spdm_test_context = *state;
+    1079                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1080                 :          1 :     spdm_test_context->case_id = 0x12;
+    1081                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1082                 :          1 :     spdm_context->local_context.capability.flags = 0;
+    1083                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
+    1084                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1085                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1086                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+    1087                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1088                 :            :         m_libspdm_use_measurement_hash_algo;
+    1089                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+    1090                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1091                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1092                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    1093                 :            :                                                     &data_size1, NULL, NULL);
+    1094                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    1095                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
+    1096                 :          1 :     libspdm_secret_lib_challenge_opaque_data_size = 0;
+    1097                 :          1 :     libspdm_reset_message_c(spdm_context);
+    1098                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1099                 :            :     spdm_context->transcript.message_m.buffer_size =
+    1100                 :            :         spdm_context->transcript.message_m.max_buffer_size;
+    1101                 :            : #endif
+    1102                 :          1 :     response_size = sizeof(response);
+    1103                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE, m_libspdm_challenge_request8.nonce);
+    1104                 :            : 
+    1105                 :          1 :     libspdm_zero_mem(request, sizeof(request));
+    1106                 :          1 :     libspdm_copy_mem(request, sizeof(spdm_challenge_request_t),
+    1107                 :            :                      &m_libspdm_challenge_request8, m_libspdm_challenge_request8_size);
+    1108                 :          1 :     requester_context = request + m_libspdm_challenge_request8_size;
+    1109                 :          1 :     libspdm_set_mem(requester_context, SPDM_REQ_CONTEXT_SIZE, 0xAA);
+    1110                 :          1 :     m_libspdm_challenge_request8_size += SPDM_REQ_CONTEXT_SIZE;
+    1111                 :            : 
+    1112                 :          1 :     status = libspdm_get_response_challenge_auth(
+    1113                 :            :         spdm_context, m_libspdm_challenge_request8_size,
+    1114                 :            :         request, &response_size, response);
+    1115                 :            : 
+    1116                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1117                 :          1 :     assert_int_equal(response_size,
+    1118                 :            :                      sizeof(spdm_challenge_auth_response_t) +
+    1119                 :            :                      libspdm_get_hash_size(m_libspdm_use_hash_algo) +
+    1120                 :            :                      SPDM_NONCE_SIZE + 0 + sizeof(uint16_t) + 0 +
+    1121                 :            :                      libspdm_get_asym_signature_size(m_libspdm_use_asym_algo) +
+    1122                 :            :                      SPDM_REQ_CONTEXT_SIZE);
+    1123                 :          1 :     spdm_response = (void *)response;
+    1124                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_CHALLENGE_AUTH);
+    1125                 :          1 :     assert_int_equal(spdm_response->header.param1, 0);
+    1126                 :          1 :     assert_int_equal(spdm_response->header.param2, 1 << 0);
+    1127                 :            : 
+    1128                 :          1 :     responder_context = (void *)response;
+    1129                 :          1 :     responder_context += sizeof(spdm_challenge_auth_response_t) +
+    1130                 :          1 :                          libspdm_get_hash_size(m_libspdm_use_hash_algo) +
+    1131                 :          1 :                          SPDM_NONCE_SIZE + 0 + sizeof(uint16_t);
+    1132                 :          1 :     assert_memory_equal(requester_context, responder_context, SPDM_REQ_CONTEXT_SIZE);
+    1133                 :            : 
+    1134                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1135                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+    1136                 :            : #endif
+    1137                 :          1 :     free(data1);
+    1138                 :          1 : }
+    1139                 :            : 
+    1140                 :            : /**
+    1141                 :            :  * Test 19: The key usage bit mask is not set, the SlotID fields in CHALLENGE and CHALLENGE_AUTH shall not specify this certificate slot
+    1142                 :            :  * Expected behavior: the responder accepts the request, but produces an ERROR message
+    1143                 :            :  * indicating the invalid state.
+    1144                 :            :  **/
+    1145                 :          1 : void libspdm_test_responder_challenge_auth_case19(void **state)
+    1146                 :            : {
+    1147                 :            :     libspdm_return_t status;
+    1148                 :            :     libspdm_test_context_t *spdm_test_context;
+    1149                 :            :     libspdm_context_t *spdm_context;
+    1150                 :            :     size_t response_size;
+    1151                 :            :     spdm_challenge_auth_response_t *spdm_response;
+    1152                 :            :     void *data1;
+    1153                 :            :     size_t data_size1;
+    1154                 :            :     uint8_t *requester_context;
+    1155                 :            :     uint8_t request[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1156                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1157                 :            :     uint8_t slot_id;
+    1158                 :            : 
+    1159                 :          1 :     spdm_test_context = *state;
+    1160                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1161                 :          1 :     spdm_test_context->case_id = 0x13;
+    1162                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1163                 :          1 :     spdm_context->local_context.capability.flags = 0;
+    1164                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
+    1165                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1166                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1167                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+    1168                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1169                 :            :         m_libspdm_use_measurement_hash_algo;
+    1170                 :          1 :     spdm_context->connection_info.multi_key_conn_rsp = true;
+    1171                 :            : 
+    1172                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+    1173                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1174                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1175                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    1176                 :            :                                                     &data_size1, NULL, NULL);
+    1177                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    1178                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
+    1179                 :            : 
+    1180                 :          1 :     libspdm_secret_lib_challenge_opaque_data_size = 0;
+    1181                 :          1 :     libspdm_reset_message_c(spdm_context);
+    1182                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1183                 :            :     spdm_context->transcript.message_m.buffer_size =
+    1184                 :            :         spdm_context->transcript.message_m.max_buffer_size;
+    1185                 :            : #endif
+    1186                 :            : 
+    1187                 :            :     /* If set, the SlotID fields in CHALLENGE and CHALLENGE_AUTH can specify this certificate slot. If not set, the
+    1188                 :            :      * SlotID fields in CHALLENGE and CHALLENGE_AUTH shall not specify this certificate slot. */
+    1189                 :          1 :     slot_id = 0;
+    1190                 :          1 :     m_libspdm_challenge_request8.header.param1 = slot_id;
+    1191                 :          1 :     spdm_context->local_context.local_key_usage_bit_mask[slot_id] =
+    1192                 :            :         SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE |
+    1193                 :            :         SPDM_KEY_USAGE_BIT_MASK_MEASUREMENT_USE;
+    1194                 :            : 
+    1195                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE, m_libspdm_challenge_request8.nonce);
+    1196                 :            : 
+    1197                 :          1 :     libspdm_zero_mem(request, sizeof(request));
+    1198                 :          1 :     libspdm_copy_mem(request, sizeof(spdm_challenge_request_t),
+    1199                 :            :                      &m_libspdm_challenge_request8, sizeof(m_libspdm_challenge_request8));
+    1200                 :          1 :     requester_context = request + sizeof(m_libspdm_challenge_request8);
+    1201                 :          1 :     libspdm_set_mem(requester_context, SPDM_REQ_CONTEXT_SIZE, 0xAA);
+    1202                 :          1 :     m_libspdm_challenge_request8_size = sizeof(m_libspdm_challenge_request8) +
+    1203                 :            :                                         SPDM_REQ_CONTEXT_SIZE;
+    1204                 :            : 
+    1205                 :          1 :     response_size = sizeof(response);
+    1206                 :          1 :     status = libspdm_get_response_challenge_auth(
+    1207                 :            :         spdm_context, m_libspdm_challenge_request8_size,
+    1208                 :            :         request, &response_size, response);
+    1209                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1210                 :          1 :     assert_int_equal (response_size, sizeof(spdm_error_response_t));
+    1211                 :          1 :     spdm_response = (void *)response;
+    1212                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_ERROR);
+    1213                 :          1 :     assert_int_equal (spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+    1214                 :          1 :     assert_int_equal (spdm_response->header.param2, 0);
+    1215                 :          1 :     free(data1);
+    1216                 :          1 : }
+    1217                 :            : libspdm_test_context_t m_libspdm_responder_challenge_auth_test_context = {
+    1218                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+    1219                 :            :     false,
+    1220                 :            : };
+    1221                 :            : 
+    1222                 :          1 : int libspdm_responder_challenge_auth_test_main(void)
+    1223                 :            : {
+    1224                 :          1 :     const struct CMUnitTest spdm_responder_challenge_auth_tests[] = {
+    1225                 :            :         /* Success Case*/
+    1226                 :            :         cmocka_unit_test(libspdm_test_responder_challenge_auth_case1),
+    1227                 :            :         /* Can be populated with new test.*/
+    1228                 :            :         cmocka_unit_test(libspdm_test_responder_challenge_auth_case2),
+    1229                 :            :         /* response_state: LIBSPDM_RESPONSE_STATE_BUSY*/
+    1230                 :            :         cmocka_unit_test(libspdm_test_responder_challenge_auth_case3),
+    1231                 :            :         /* response_state: LIBSPDM_RESPONSE_STATE_NEED_RESYNC*/
+    1232                 :            :         cmocka_unit_test(libspdm_test_responder_challenge_auth_case4),
+    1233                 :            :         #if LIBSPDM_RESPOND_IF_READY_SUPPORT
+    1234                 :            :         /* response_state: LIBSPDM_RESPONSE_STATE_NOT_READY*/
+    1235                 :            :         cmocka_unit_test(libspdm_test_responder_challenge_auth_case5),
+    1236                 :            :         #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
+    1237                 :            :         /* connection_state Check*/
+    1238                 :            :         cmocka_unit_test(libspdm_test_responder_challenge_auth_case6),
+    1239                 :            :         cmocka_unit_test(libspdm_test_responder_challenge_auth_case7),
+    1240                 :            :         cmocka_unit_test(libspdm_test_responder_challenge_auth_case8),
+    1241                 :            :         cmocka_unit_test(libspdm_test_responder_challenge_auth_case9),
+    1242                 :            :         cmocka_unit_test(libspdm_test_responder_challenge_auth_case10),
+    1243                 :            :         cmocka_unit_test(libspdm_test_responder_challenge_auth_case11),
+    1244                 :            :         cmocka_unit_test(libspdm_test_responder_challenge_auth_case12),
+    1245                 :            :         cmocka_unit_test(libspdm_test_responder_challenge_auth_case13),
+    1246                 :            :         cmocka_unit_test(libspdm_test_responder_challenge_auth_case14),
+    1247                 :            :         /* Buffer verification*/
+    1248                 :            :         cmocka_unit_test(libspdm_test_responder_challenge_auth_case15),
+    1249                 :            :         cmocka_unit_test(libspdm_test_responder_challenge_auth_case16),
+    1250                 :            :         /* using provisioned public key (slot_id 0xFF) */
+    1251                 :            :         cmocka_unit_test(libspdm_test_responder_challenge_auth_case17),
+    1252                 :            :         /* Success Case: V1.3 get a correct context field */
+    1253                 :            :         cmocka_unit_test(libspdm_test_responder_challenge_auth_case18),
+    1254                 :            :         /* The key usage bit mask is not set, failed Case*/
+    1255                 :            :         cmocka_unit_test(libspdm_test_responder_challenge_auth_case19),
+    1256                 :            : 
+    1257                 :            :     };
+    1258                 :            : 
+    1259                 :          1 :     libspdm_setup_test_context(&m_libspdm_responder_challenge_auth_test_context);
+    1260                 :            : 
+    1261                 :          1 :     return cmocka_run_group_tests(spdm_responder_challenge_auth_tests,
+    1262                 :            :                                   libspdm_unit_test_group_setup,
+    1263                 :            :                                   libspdm_unit_test_group_teardown);
+    1264                 :            : }
+    1265                 :            : 
+    1266                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/chunk_get.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_responder/chunk_get.c.func-sort-c.html new file mode 100644 index 00000000000..239c38bde18 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/chunk_get.c.func-sort-c.html @@ -0,0 +1,137 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/chunk_get.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - chunk_get.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:498498100.0 %
Date:2024-09-22 08:21:07Functions:1414100.0 %
Branches:121675.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_chunk_get_rsp_test_main1
libspdm_test_responder_chunk_get_rsp_case11
libspdm_test_responder_chunk_get_rsp_case101
libspdm_test_responder_chunk_get_rsp_case111
libspdm_test_responder_chunk_get_rsp_case121
libspdm_test_responder_chunk_get_rsp_case131
libspdm_test_responder_chunk_get_rsp_case21
libspdm_test_responder_chunk_get_rsp_case31
libspdm_test_responder_chunk_get_rsp_case41
libspdm_test_responder_chunk_get_rsp_case51
libspdm_test_responder_chunk_get_rsp_case61
libspdm_test_responder_chunk_get_rsp_case71
libspdm_test_responder_chunk_get_rsp_case81
libspdm_test_responder_chunk_get_rsp_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/chunk_get.c.func.html b/coverage_log/unit_test/test_spdm_responder/chunk_get.c.func.html new file mode 100644 index 00000000000..84d869af55b --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/chunk_get.c.func.html @@ -0,0 +1,137 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/chunk_get.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - chunk_get.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:498498100.0 %
Date:2024-09-22 08:21:07Functions:1414100.0 %
Branches:121675.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_chunk_get_rsp_test_main1
libspdm_test_responder_chunk_get_rsp_case11
libspdm_test_responder_chunk_get_rsp_case101
libspdm_test_responder_chunk_get_rsp_case111
libspdm_test_responder_chunk_get_rsp_case121
libspdm_test_responder_chunk_get_rsp_case131
libspdm_test_responder_chunk_get_rsp_case21
libspdm_test_responder_chunk_get_rsp_case31
libspdm_test_responder_chunk_get_rsp_case41
libspdm_test_responder_chunk_get_rsp_case51
libspdm_test_responder_chunk_get_rsp_case61
libspdm_test_responder_chunk_get_rsp_case71
libspdm_test_responder_chunk_get_rsp_case81
libspdm_test_responder_chunk_get_rsp_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/chunk_get.c.gcov.html b/coverage_log/unit_test/test_spdm_responder/chunk_get.c.gcov.html new file mode 100644 index 00000000000..213ea5db4b2 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/chunk_get.c.gcov.html @@ -0,0 +1,1128 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/chunk_get.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - chunk_get.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:498498100.0 %
Date:2024-09-22 08:21:07Functions:1414100.0 %
Branches:121675.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_responder_lib.h"
+       9                 :            : 
+      10                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
+      11                 :            : 
+      12                 :            : #define CHUNK_GET_RESPONDER_UNIT_TEST_DATA_TRANSFER_SIZE (44)
+      13                 :            : 
+      14                 :            : /**
+      15                 :            :  * Test 1: Responder receives a CHUNK_GET request when it is not expecting it.
+      16                 :            :  * Responder does not have response CHUNK cap set.
+      17                 :            :  * Expected Behavior: Returns ERROR response message
+      18                 :            :  * with SPDM_ERROR_CODE_UNEXPECTED_REQUEST error code.
+      19                 :            :  **/
+      20                 :          1 : void libspdm_test_responder_chunk_get_rsp_case1(void** state)
+      21                 :            : {
+      22                 :            :     libspdm_return_t status;
+      23                 :            :     libspdm_test_context_t* spdm_test_context;
+      24                 :            :     libspdm_context_t* spdm_context;
+      25                 :            :     size_t response_size;
+      26                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+      27                 :            :     spdm_error_response_t* spdm_response;
+      28                 :            :     spdm_chunk_get_request_t spdm_request;
+      29                 :            : 
+      30                 :          1 :     spdm_test_context = *state;
+      31                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+      32                 :          1 :     spdm_test_context->case_id = 1;
+      33                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+      34                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+      35                 :            : 
+      36                 :          1 :     spdm_context->connection_info.connection_state =
+      37                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+      38                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+      39                 :            :         m_libspdm_use_hash_algo;
+      40                 :            : 
+      41                 :          1 :     spdm_context->connection_info.capability.data_transfer_size =
+      42                 :            :         CHUNK_GET_RESPONDER_UNIT_TEST_DATA_TRANSFER_SIZE;
+      43                 :            : 
+      44                 :          1 :     libspdm_zero_mem(&spdm_request, sizeof(spdm_request));
+      45                 :          1 :     spdm_request.header.spdm_version = SPDM_MESSAGE_VERSION_12;
+      46                 :          1 :     spdm_request.header.request_response_code = SPDM_CHUNK_GET;
+      47                 :          1 :     spdm_request.header.param1 = 0;
+      48                 :          1 :     spdm_request.header.param2 = 0;
+      49                 :          1 :     spdm_request.chunk_seq_no = 0;
+      50                 :            : 
+      51                 :          1 :     response_size = sizeof(response);
+      52                 :          1 :     status = libspdm_get_response_chunk_get(
+      53                 :            :         spdm_context,
+      54                 :            :         sizeof(spdm_request), &spdm_request,
+      55                 :            :         &response_size, response);
+      56                 :            : 
+      57                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+      58                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+      59                 :            : 
+      60                 :          1 :     spdm_response = (spdm_error_response_t*) response;
+      61                 :          1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+      62                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
+      63                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_UNEXPECTED_REQUEST);
+      64                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+      65                 :          1 : }
+      66                 :            : 
+      67                 :            : /**
+      68                 :            :  * Test 2: Responder receives a CHUNK_GET request with bad response state.
+      69                 :            :  * Expected Behavior: Returns ERROR response message with an error code.
+      70                 :            :  **/
+      71                 :          1 : void libspdm_test_responder_chunk_get_rsp_case2(void** state)
+      72                 :            : {
+      73                 :            :     libspdm_return_t status;
+      74                 :            :     libspdm_test_context_t* spdm_test_context;
+      75                 :            :     libspdm_context_t* spdm_context;
+      76                 :            :     size_t response_size;
+      77                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+      78                 :            :     spdm_error_response_t* spdm_response;
+      79                 :            :     spdm_chunk_get_request_t spdm_request;
+      80                 :            : 
+      81                 :          1 :     spdm_test_context = *state;
+      82                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+      83                 :          1 :     spdm_test_context->case_id = 2;
+      84                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+      85                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+      86                 :            : 
+      87                 :          1 :     spdm_context->connection_info.connection_state =
+      88                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+      89                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+      90                 :            :         m_libspdm_use_hash_algo;
+      91                 :            : 
+      92                 :          1 :     spdm_context->local_context.capability.data_transfer_size =
+      93                 :            :         CHUNK_GET_RESPONDER_UNIT_TEST_DATA_TRANSFER_SIZE;
+      94                 :            : 
+      95                 :          1 :     spdm_context->local_context.capability.flags |=
+      96                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP;
+      97                 :          1 :     spdm_context->connection_info.capability.flags |=
+      98                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP;
+      99                 :            : 
+     100                 :            :     /* Set bad response state */
+     101                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_BUSY;
+     102                 :            : 
+     103                 :          1 :     libspdm_zero_mem(&spdm_request, sizeof(spdm_request));
+     104                 :          1 :     spdm_request.header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     105                 :          1 :     spdm_request.header.request_response_code = SPDM_CHUNK_GET;
+     106                 :          1 :     spdm_request.header.param1 = 0;
+     107                 :          1 :     spdm_request.header.param2 = 0;
+     108                 :          1 :     spdm_request.chunk_seq_no = 0;
+     109                 :            : 
+     110                 :          1 :     response_size = sizeof(response);
+     111                 :          1 :     status = libspdm_get_response_chunk_get(
+     112                 :            :         spdm_context,
+     113                 :            :         sizeof(spdm_request), &spdm_request,
+     114                 :            :         &response_size, response);
+     115                 :            : 
+     116                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     117                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     118                 :            : 
+     119                 :          1 :     spdm_response = (spdm_error_response_t*) response;
+     120                 :          1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+     121                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
+     122                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_BUSY);
+     123                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     124                 :          1 : }
+     125                 :            : 
+     126                 :            : /**
+     127                 :            :  * Test 3: Responder receives a CHUNK_GET request with bad connection state.
+     128                 :            :  * Expected Behavior: Returns ERROR response message
+     129                 :            :  * with SPDM_ERROR_CODE_UNEXPECTED_REQUEST error code.
+     130                 :            :  **/
+     131                 :          1 : void libspdm_test_responder_chunk_get_rsp_case3(void** state)
+     132                 :            : {
+     133                 :            :     libspdm_return_t status;
+     134                 :            :     libspdm_test_context_t* spdm_test_context;
+     135                 :            :     libspdm_context_t* spdm_context;
+     136                 :            :     size_t response_size;
+     137                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     138                 :            :     spdm_error_response_t* spdm_response;
+     139                 :            :     spdm_chunk_get_request_t spdm_request;
+     140                 :            : 
+     141                 :          1 :     spdm_test_context = *state;
+     142                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     143                 :          1 :     spdm_test_context->case_id = 3;
+     144                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     145                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     146                 :            : 
+     147                 :            :     /* Set bad connection_state */
+     148                 :          1 :     spdm_context->connection_info.connection_state =
+     149                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES - 1;
+     150                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     151                 :            :         m_libspdm_use_hash_algo;
+     152                 :            : 
+     153                 :          1 :     spdm_context->local_context.capability.data_transfer_size =
+     154                 :            :         CHUNK_GET_RESPONDER_UNIT_TEST_DATA_TRANSFER_SIZE;
+     155                 :          1 :     spdm_context->local_context.capability.flags |=
+     156                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP;
+     157                 :          1 :     spdm_context->connection_info.capability.flags |=
+     158                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP;
+     159                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+     160                 :            : 
+     161                 :          1 :     libspdm_zero_mem(&spdm_request, sizeof(spdm_request));
+     162                 :          1 :     spdm_request.header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     163                 :          1 :     spdm_request.header.request_response_code = SPDM_CHUNK_GET;
+     164                 :          1 :     spdm_request.header.param1 = 0;
+     165                 :          1 :     spdm_request.header.param2 = 0; /* Handle */
+     166                 :          1 :     spdm_request.chunk_seq_no = 0;
+     167                 :            : 
+     168                 :          1 :     response_size = sizeof(response);
+     169                 :          1 :     status = libspdm_get_response_chunk_get(
+     170                 :            :         spdm_context,
+     171                 :            :         sizeof(spdm_request), &spdm_request,
+     172                 :            :         &response_size, response);
+     173                 :            : 
+     174                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     175                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     176                 :            : 
+     177                 :          1 :     spdm_response = (spdm_error_response_t*) response;
+     178                 :          1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+     179                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
+     180                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_UNEXPECTED_REQUEST);
+     181                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     182                 :          1 : }
+     183                 :            : 
+     184                 :            : /**
+     185                 :            :  * Test 4: Responder receives a CHUNK_GET request with bad size.
+     186                 :            :  * Expected Behavior: Returns ERROR response message
+     187                 :            :  * with SPDM_ERROR_CODE_INVALID_REQUEST error code.
+     188                 :            :  **/
+     189                 :          1 : void libspdm_test_responder_chunk_get_rsp_case4(void** state)
+     190                 :            : {
+     191                 :            :     libspdm_return_t status;
+     192                 :            :     libspdm_test_context_t* spdm_test_context;
+     193                 :            :     libspdm_context_t* spdm_context;
+     194                 :            :     size_t response_size;
+     195                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     196                 :            :     spdm_error_response_t* spdm_response;
+     197                 :            :     spdm_chunk_get_request_t spdm_request;
+     198                 :            : 
+     199                 :          1 :     spdm_test_context = *state;
+     200                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     201                 :          1 :     spdm_test_context->case_id = 4;
+     202                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     203                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     204                 :            : 
+     205                 :          1 :     spdm_context->connection_info.connection_state =
+     206                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+     207                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     208                 :            :         m_libspdm_use_hash_algo;
+     209                 :            : 
+     210                 :          1 :     spdm_context->local_context.capability.data_transfer_size =
+     211                 :            :         CHUNK_GET_RESPONDER_UNIT_TEST_DATA_TRANSFER_SIZE;
+     212                 :            : 
+     213                 :          1 :     spdm_context->local_context.capability.flags |=
+     214                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP;
+     215                 :          1 :     spdm_context->connection_info.capability.flags |=
+     216                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP;
+     217                 :            : 
+     218                 :          1 :     libspdm_zero_mem(&spdm_request, sizeof(spdm_request));
+     219                 :          1 :     spdm_request.header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     220                 :          1 :     spdm_request.header.request_response_code = SPDM_CHUNK_GET;
+     221                 :          1 :     spdm_request.header.param1 = 0;
+     222                 :          1 :     spdm_request.header.param2 = 0;
+     223                 :          1 :     spdm_request.chunk_seq_no = 0;
+     224                 :            : 
+     225                 :          1 :     response_size = sizeof(response);
+     226                 :          1 :     status = libspdm_get_response_chunk_get(
+     227                 :            :         spdm_context,
+     228                 :            :         sizeof(spdm_request) - 1, &spdm_request, /* Bad request size */
+     229                 :            :         &response_size, response);
+     230                 :            : 
+     231                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     232                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     233                 :            : 
+     234                 :          1 :     spdm_response = (spdm_error_response_t*) response;
+     235                 :          1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+     236                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
+     237                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+     238                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     239                 :          1 : }
+     240                 :            : 
+     241                 :            : /**
+     242                 :            :  * Test 5: Responder receives a CHUNK_GET request with wrong SPDM version.
+     243                 :            :  * Expected Behavior: Returns ERROR response message
+     244                 :            :  * with SPDM_ERROR_CODE_VERSION_MISMATCH error code.
+     245                 :            :  **/
+     246                 :          1 : void libspdm_test_responder_chunk_get_rsp_case5(void** state)
+     247                 :            : {
+     248                 :            :     libspdm_return_t status;
+     249                 :            :     libspdm_test_context_t* spdm_test_context;
+     250                 :            :     libspdm_context_t* spdm_context;
+     251                 :            :     size_t response_size;
+     252                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     253                 :            :     spdm_error_response_t* spdm_response;
+     254                 :            :     spdm_chunk_get_request_t spdm_request;
+     255                 :            : 
+     256                 :          1 :     spdm_test_context = *state;
+     257                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     258                 :          1 :     spdm_test_context->case_id = 5;
+     259                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     260                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     261                 :            : 
+     262                 :          1 :     spdm_context->connection_info.connection_state =
+     263                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+     264                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     265                 :            :         m_libspdm_use_hash_algo;
+     266                 :            : 
+     267                 :          1 :     spdm_context->local_context.capability.data_transfer_size =
+     268                 :            :         CHUNK_GET_RESPONDER_UNIT_TEST_DATA_TRANSFER_SIZE;
+     269                 :          1 :     spdm_context->local_context.capability.flags |=
+     270                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP;
+     271                 :          1 :     spdm_context->connection_info.capability.flags |=
+     272                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP;
+     273                 :            : 
+     274                 :          1 :     libspdm_zero_mem(&spdm_request, sizeof(spdm_request));
+     275                 :          1 :     spdm_request.header.spdm_version = SPDM_MESSAGE_VERSION_11; /* Mismatching SPDM version */
+     276                 :          1 :     spdm_request.header.request_response_code = SPDM_CHUNK_GET;
+     277                 :          1 :     spdm_request.header.param1 = 0;
+     278                 :          1 :     spdm_request.header.param2 = 0;
+     279                 :          1 :     spdm_request.chunk_seq_no = 0;
+     280                 :            : 
+     281                 :          1 :     response_size = sizeof(response);
+     282                 :          1 :     status = libspdm_get_response_chunk_get(
+     283                 :            :         spdm_context,
+     284                 :            :         sizeof(spdm_request), &spdm_request,
+     285                 :            :         &response_size, response);
+     286                 :            : 
+     287                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     288                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     289                 :            : 
+     290                 :          1 :     spdm_response = (spdm_error_response_t*) response;
+     291                 :          1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+     292                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
+     293                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST);
+     294                 :          1 :     assert_int_equal(spdm_response->header.param2, SPDM_CHUNK_GET);
+     295                 :          1 : }
+     296                 :            : 
+     297                 :            : /**
+     298                 :            :  * Test 6: Responder has no chunk saved to get.
+     299                 :            :  **/
+     300                 :          1 : void libspdm_test_responder_chunk_get_rsp_case6(void** state)
+     301                 :            : {
+     302                 :            :     libspdm_return_t status;
+     303                 :            :     libspdm_test_context_t* spdm_test_context;
+     304                 :            :     libspdm_context_t* spdm_context;
+     305                 :            :     size_t response_size;
+     306                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     307                 :            :     spdm_error_response_t* spdm_response;
+     308                 :            :     spdm_chunk_get_request_t spdm_request;
+     309                 :            : 
+     310                 :          1 :     spdm_test_context = *state;
+     311                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     312                 :          1 :     spdm_test_context->case_id = 6;
+     313                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     314                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     315                 :            : 
+     316                 :          1 :     spdm_context->connection_info.connection_state =
+     317                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+     318                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     319                 :            :         m_libspdm_use_hash_algo;
+     320                 :            : 
+     321                 :          1 :     spdm_context->local_context.capability.data_transfer_size =
+     322                 :            :         CHUNK_GET_RESPONDER_UNIT_TEST_DATA_TRANSFER_SIZE;
+     323                 :          1 :     spdm_context->local_context.capability.flags |=
+     324                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP;
+     325                 :          1 :     spdm_context->connection_info.capability.flags |=
+     326                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP;
+     327                 :            : 
+     328                 :            :     /* Set no chunk saved */
+     329                 :          1 :     spdm_context->chunk_context.get.chunk_in_use = false;
+     330                 :            : 
+     331                 :          1 :     libspdm_zero_mem(&spdm_request, sizeof(spdm_request));
+     332                 :          1 :     spdm_request.header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     333                 :          1 :     spdm_request.header.request_response_code = SPDM_CHUNK_GET;
+     334                 :          1 :     spdm_request.header.param1 = 0;
+     335                 :          1 :     spdm_request.header.param2 = 0;
+     336                 :          1 :     spdm_request.chunk_seq_no = 0;
+     337                 :            : 
+     338                 :          1 :     response_size = sizeof(response);
+     339                 :          1 :     status = libspdm_get_response_chunk_get(
+     340                 :            :         spdm_context,
+     341                 :            :         sizeof(spdm_request), &spdm_request,
+     342                 :            :         &response_size, response);
+     343                 :            : 
+     344                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     345                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     346                 :            : 
+     347                 :          1 :     spdm_response = (spdm_error_response_t*) response;
+     348                 :          1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+     349                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
+     350                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_UNEXPECTED_REQUEST);
+     351                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     352                 :          1 : }
+     353                 :            : 
+     354                 :            : /**
+     355                 :            :  * Test 7: Responder has handle that does not match request.
+     356                 :            :  **/
+     357                 :          1 : void libspdm_test_responder_chunk_get_rsp_case7(void** state)
+     358                 :            : {
+     359                 :            :     libspdm_return_t status;
+     360                 :            :     libspdm_test_context_t* spdm_test_context;
+     361                 :            :     libspdm_context_t* spdm_context;
+     362                 :            :     size_t response_size;
+     363                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     364                 :            :     spdm_error_response_t* spdm_response;
+     365                 :            :     spdm_chunk_get_request_t spdm_request;
+     366                 :            :     void* scratch_buffer;
+     367                 :            :     size_t scratch_buffer_size;
+     368                 :            : 
+     369                 :            :     uint8_t chunk_handle;
+     370                 :            : 
+     371                 :          1 :     spdm_test_context = *state;
+     372                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     373                 :          1 :     spdm_test_context->case_id = 7;
+     374                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     375                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     376                 :            : 
+     377                 :          1 :     spdm_context->connection_info.connection_state =
+     378                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+     379                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     380                 :            :         m_libspdm_use_hash_algo;
+     381                 :            : 
+     382                 :          1 :     spdm_context->local_context.capability.data_transfer_size =
+     383                 :            :         CHUNK_GET_RESPONDER_UNIT_TEST_DATA_TRANSFER_SIZE;
+     384                 :          1 :     spdm_context->local_context.capability.flags |=
+     385                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP;
+     386                 :          1 :     spdm_context->connection_info.capability.flags |=
+     387                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP;
+     388                 :            : 
+     389                 :          1 :     libspdm_get_scratch_buffer(spdm_context, &scratch_buffer, &scratch_buffer_size);
+     390                 :            : 
+     391                 :          2 :     scratch_buffer = (uint8_t*)scratch_buffer +
+     392                 :          1 :                      libspdm_get_scratch_buffer_large_message_offset(spdm_context);
+     393                 :          2 :     scratch_buffer_size = scratch_buffer_size -
+     394                 :          1 :                           libspdm_get_scratch_buffer_large_message_offset(spdm_context);
+     395                 :          1 :     libspdm_zero_mem(scratch_buffer, scratch_buffer_size);
+     396                 :            : 
+     397                 :          1 :     chunk_handle = (uint8_t) spdm_test_context->case_id;
+     398                 :          1 :     spdm_context->chunk_context.get.chunk_in_use = true;
+     399                 :          1 :     spdm_context->chunk_context.get.chunk_handle = (uint8_t) spdm_test_context->case_id;
+     400                 :          1 :     spdm_context->chunk_context.get.chunk_seq_no = chunk_handle;
+     401                 :          1 :     spdm_context->chunk_context.get.large_message = scratch_buffer;
+     402                 :          1 :     spdm_context->chunk_context.get.large_message_size = scratch_buffer_size;
+     403                 :            : 
+     404                 :          1 :     libspdm_zero_mem(&spdm_request, sizeof(spdm_request));
+     405                 :          1 :     spdm_request.header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     406                 :          1 :     spdm_request.header.request_response_code = SPDM_CHUNK_GET;
+     407                 :          1 :     spdm_request.header.param1 = 0;
+     408                 :          1 :     spdm_request.header.param2 = chunk_handle - 1; /* Bad chunk handle */
+     409                 :          1 :     spdm_request.chunk_seq_no = 0;
+     410                 :            : 
+     411                 :          1 :     response_size = sizeof(response);
+     412                 :          1 :     status = libspdm_get_response_chunk_get(
+     413                 :            :         spdm_context,
+     414                 :            :         sizeof(spdm_request), &spdm_request,
+     415                 :            :         &response_size, response);
+     416                 :            : 
+     417                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     418                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     419                 :            : 
+     420                 :          1 :     spdm_response = (spdm_error_response_t*) response;
+     421                 :          1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+     422                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
+     423                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+     424                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     425                 :          1 : }
+     426                 :            : 
+     427                 :            : /**
+     428                 :            :  * Test 8: Responder has earlier sequence number than request .
+     429                 :            :  **/
+     430                 :          1 : void libspdm_test_responder_chunk_get_rsp_case8(void** state)
+     431                 :            : {
+     432                 :            :     libspdm_return_t status;
+     433                 :            :     libspdm_test_context_t* spdm_test_context;
+     434                 :            :     libspdm_context_t* spdm_context;
+     435                 :            :     size_t response_size;
+     436                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     437                 :            :     spdm_error_response_t* spdm_response;
+     438                 :            :     spdm_chunk_get_request_t spdm_request;
+     439                 :            :     void* scratch_buffer;
+     440                 :            :     size_t scratch_buffer_size;
+     441                 :            :     uint8_t chunk_handle;
+     442                 :            : 
+     443                 :          1 :     spdm_test_context = *state;
+     444                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     445                 :          1 :     spdm_test_context->case_id = 8;
+     446                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     447                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     448                 :            : 
+     449                 :          1 :     spdm_context->connection_info.connection_state =
+     450                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     451                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     452                 :            :         m_libspdm_use_hash_algo;
+     453                 :            : 
+     454                 :          1 :     spdm_context->local_context.capability.data_transfer_size =
+     455                 :            :         CHUNK_GET_RESPONDER_UNIT_TEST_DATA_TRANSFER_SIZE;
+     456                 :          1 :     spdm_context->local_context.capability.flags |=
+     457                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP;
+     458                 :          1 :     spdm_context->connection_info.capability.flags |=
+     459                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP;
+     460                 :            : 
+     461                 :          1 :     libspdm_get_scratch_buffer(spdm_context, &scratch_buffer, &scratch_buffer_size);
+     462                 :            : 
+     463                 :          2 :     scratch_buffer = (uint8_t*)scratch_buffer +
+     464                 :          1 :                      libspdm_get_scratch_buffer_large_message_offset(spdm_context);
+     465                 :          2 :     scratch_buffer_size = scratch_buffer_size -
+     466                 :          1 :                           libspdm_get_scratch_buffer_large_message_offset(spdm_context);
+     467                 :          1 :     libspdm_zero_mem(scratch_buffer, scratch_buffer_size);
+     468                 :            : 
+     469                 :          1 :     chunk_handle = (uint8_t) spdm_test_context->case_id;
+     470                 :          1 :     spdm_context->chunk_context.get.chunk_in_use = true;
+     471                 :          1 :     spdm_context->chunk_context.get.chunk_handle = chunk_handle;
+     472                 :          1 :     spdm_context->chunk_context.get.chunk_seq_no = 0;
+     473                 :          1 :     spdm_context->chunk_context.get.large_message = scratch_buffer;
+     474                 :          1 :     spdm_context->chunk_context.get.large_message_size = scratch_buffer_size;
+     475                 :            : 
+     476                 :          1 :     libspdm_zero_mem(&spdm_request, sizeof(spdm_request));
+     477                 :          1 :     spdm_request.header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     478                 :          1 :     spdm_request.header.request_response_code = SPDM_CHUNK_GET;
+     479                 :          1 :     spdm_request.header.param1 = 0;
+     480                 :          1 :     spdm_request.header.param2 = chunk_handle;
+     481                 :          1 :     spdm_request.chunk_seq_no = 1; /* Bad chunk seq no */
+     482                 :            : 
+     483                 :          1 :     response_size = sizeof(response);
+     484                 :          1 :     status = libspdm_get_response_chunk_get(
+     485                 :            :         spdm_context,
+     486                 :            :         sizeof(spdm_request), &spdm_request,
+     487                 :            :         &response_size, response);
+     488                 :            : 
+     489                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     490                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     491                 :            : 
+     492                 :          1 :     spdm_response = (spdm_error_response_t*) response;
+     493                 :          1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+     494                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
+     495                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+     496                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     497                 :          1 : }
+     498                 :            : 
+     499                 :            : /**
+     500                 :            :  * Test 9: Responder has later sequence number than request.
+     501                 :            :  **/
+     502                 :          1 : void libspdm_test_responder_chunk_get_rsp_case9(void** state)
+     503                 :            : {
+     504                 :            :     libspdm_return_t status;
+     505                 :            :     libspdm_test_context_t* spdm_test_context;
+     506                 :            :     libspdm_context_t* spdm_context;
+     507                 :            :     size_t response_size;
+     508                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     509                 :            :     spdm_error_response_t* spdm_response;
+     510                 :            :     spdm_chunk_get_request_t spdm_request;
+     511                 :            :     void* scratch_buffer;
+     512                 :            :     size_t scratch_buffer_size;
+     513                 :            :     uint8_t chunk_handle;
+     514                 :            : 
+     515                 :          1 :     spdm_test_context = *state;
+     516                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     517                 :          1 :     spdm_test_context->case_id = 9;
+     518                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     519                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     520                 :            : 
+     521                 :          1 :     spdm_context->connection_info.connection_state =
+     522                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     523                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     524                 :            :         m_libspdm_use_hash_algo;
+     525                 :            : 
+     526                 :          1 :     spdm_context->local_context.capability.data_transfer_size =
+     527                 :            :         CHUNK_GET_RESPONDER_UNIT_TEST_DATA_TRANSFER_SIZE;
+     528                 :          1 :     spdm_context->local_context.capability.flags |=
+     529                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP;
+     530                 :          1 :     spdm_context->connection_info.capability.flags |=
+     531                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP;
+     532                 :            : 
+     533                 :          1 :     libspdm_get_scratch_buffer(spdm_context, &scratch_buffer, &scratch_buffer_size);
+     534                 :            : 
+     535                 :          2 :     scratch_buffer = (uint8_t*)scratch_buffer +
+     536                 :          1 :                      libspdm_get_scratch_buffer_large_message_offset(spdm_context);
+     537                 :          2 :     scratch_buffer_size = scratch_buffer_size -
+     538                 :          1 :                           libspdm_get_scratch_buffer_large_message_offset(spdm_context);
+     539                 :          1 :     libspdm_zero_mem(scratch_buffer, scratch_buffer_size);
+     540                 :            : 
+     541                 :          1 :     chunk_handle = (uint8_t) spdm_test_context->case_id;
+     542                 :          1 :     spdm_context->chunk_context.get.chunk_in_use = true;
+     543                 :          1 :     spdm_context->chunk_context.get.chunk_handle = chunk_handle;
+     544                 :          1 :     spdm_context->chunk_context.get.chunk_seq_no = 0;
+     545                 :          1 :     spdm_context->chunk_context.get.large_message = scratch_buffer;
+     546                 :          1 :     spdm_context->chunk_context.get.large_message_size = scratch_buffer_size;
+     547                 :          1 :     spdm_context->chunk_context.get.chunk_bytes_transferred = 0;
+     548                 :            : 
+     549                 :          1 :     libspdm_zero_mem(&spdm_request, sizeof(spdm_request));
+     550                 :          1 :     spdm_request.header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     551                 :          1 :     spdm_request.header.request_response_code = SPDM_CHUNK_GET;
+     552                 :          1 :     spdm_request.header.param1 = 0;
+     553                 :          1 :     spdm_request.header.param2 = chunk_handle;
+     554                 :          1 :     spdm_request.chunk_seq_no = 1; /* Bad chunk seq no */
+     555                 :            : 
+     556                 :          1 :     response_size = sizeof(response);
+     557                 :          1 :     status = libspdm_get_response_chunk_get(
+     558                 :            :         spdm_context,
+     559                 :            :         sizeof(spdm_request), &spdm_request,
+     560                 :            :         &response_size, response);
+     561                 :            : 
+     562                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     563                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     564                 :            : 
+     565                 :          1 :     spdm_response = (spdm_error_response_t*) response;
+     566                 :          1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+     567                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
+     568                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+     569                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     570                 :          1 : }
+     571                 :            : 
+     572                 :            : /**
+     573                 :            :  * Test 10: Successful request of first chunk.
+     574                 :            :  **/
+     575                 :          1 : void libspdm_test_responder_chunk_get_rsp_case10(void** state)
+     576                 :            : {
+     577                 :            :     libspdm_return_t status;
+     578                 :            :     libspdm_test_context_t* spdm_test_context;
+     579                 :            :     libspdm_context_t* spdm_context;
+     580                 :            :     size_t response_size;
+     581                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     582                 :            :     spdm_chunk_response_response_t* spdm_response;
+     583                 :            :     spdm_chunk_get_request_t spdm_request;
+     584                 :            :     void* scratch_buffer;
+     585                 :            :     size_t scratch_buffer_size;
+     586                 :            : 
+     587                 :            :     uint8_t chunk_handle;
+     588                 :            :     uint32_t data_transfer_size;
+     589                 :            :     uint32_t first_chunk_size;
+     590                 :            :     uint32_t second_chunk_size;
+     591                 :            :     uint32_t third_chunk_size;
+     592                 :            :     uint32_t total_chunk_size;
+     593                 :            :     uint32_t large_response;
+     594                 :            :     uint8_t* chunk_ptr;
+     595                 :            :     uint32_t i;
+     596                 :            : 
+     597                 :          1 :     spdm_test_context = *state;
+     598                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     599                 :          1 :     spdm_test_context->case_id = 10;
+     600                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     601                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     602                 :            : 
+     603                 :          1 :     spdm_context->connection_info.connection_state =
+     604                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     605                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     606                 :            :         m_libspdm_use_hash_algo;
+     607                 :            : 
+     608                 :          1 :     data_transfer_size = CHUNK_GET_RESPONDER_UNIT_TEST_DATA_TRANSFER_SIZE;
+     609                 :          1 :     spdm_context->local_context.capability.data_transfer_size = data_transfer_size;
+     610                 :          1 :     spdm_context->local_context.capability.flags |=
+     611                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP;
+     612                 :          1 :     spdm_context->connection_info.capability.flags |=
+     613                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP;
+     614                 :            : 
+     615                 :          1 :     libspdm_get_scratch_buffer(spdm_context, &scratch_buffer, &scratch_buffer_size);
+     616                 :            : 
+     617                 :          2 :     scratch_buffer = (uint8_t*)scratch_buffer +
+     618                 :          1 :                      libspdm_get_scratch_buffer_large_message_offset(spdm_context);
+     619                 :          2 :     scratch_buffer_size = scratch_buffer_size -
+     620                 :          1 :                           libspdm_get_scratch_buffer_large_message_offset(spdm_context);
+     621                 :          1 :     libspdm_zero_mem(scratch_buffer, scratch_buffer_size);
+     622                 :            : 
+     623                 :            :     /* Fill 1st chunk with 1, 2nd chunk with 2, 3rd chunk with 3 */
+     624                 :          1 :     first_chunk_size = data_transfer_size -
+     625                 :            :                        (sizeof(spdm_chunk_response_response_t) + sizeof(uint32_t));
+     626                 :          1 :     second_chunk_size = data_transfer_size - sizeof(spdm_chunk_response_response_t);
+     627                 :          1 :     third_chunk_size = data_transfer_size - sizeof(spdm_chunk_response_response_t);
+     628                 :          1 :     total_chunk_size = first_chunk_size + second_chunk_size + third_chunk_size;
+     629         [ -  + ]:          1 :     LIBSPDM_ASSERT(total_chunk_size <= scratch_buffer_size);
+     630                 :            : 
+     631                 :          1 :     libspdm_set_mem(scratch_buffer, first_chunk_size, 1);
+     632                 :          1 :     libspdm_set_mem((uint8_t*)scratch_buffer + first_chunk_size, second_chunk_size, 2);
+     633                 :          1 :     libspdm_set_mem((uint8_t*) scratch_buffer + first_chunk_size + second_chunk_size,
+     634                 :            :                     third_chunk_size, 3);
+     635                 :            : 
+     636                 :          1 :     chunk_handle = (uint8_t) spdm_test_context->case_id; /* Any number is fine */
+     637                 :          1 :     spdm_context->chunk_context.get.chunk_in_use = true;
+     638                 :          1 :     spdm_context->chunk_context.get.chunk_handle = chunk_handle;
+     639                 :          1 :     spdm_context->chunk_context.get.chunk_seq_no = 0;
+     640                 :          1 :     spdm_context->chunk_context.get.large_message = scratch_buffer;
+     641                 :          1 :     spdm_context->chunk_context.get.large_message_size = total_chunk_size;
+     642                 :          1 :     spdm_context->chunk_context.get.chunk_bytes_transferred = 0;
+     643                 :            : 
+     644                 :          1 :     libspdm_zero_mem(&spdm_request, sizeof(spdm_request));
+     645                 :          1 :     spdm_request.header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     646                 :          1 :     spdm_request.header.request_response_code = SPDM_CHUNK_GET;
+     647                 :          1 :     spdm_request.header.param1 = 0;
+     648                 :          1 :     spdm_request.header.param2 = chunk_handle;
+     649                 :          1 :     spdm_request.chunk_seq_no = 0;
+     650                 :            : 
+     651                 :          1 :     response_size = sizeof(response);
+     652                 :          1 :     status = libspdm_get_response_chunk_get(
+     653                 :            :         spdm_context,
+     654                 :            :         sizeof(spdm_request), &spdm_request,
+     655                 :            :         &response_size, response);
+     656                 :            : 
+     657                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     658                 :          1 :     assert_int_equal(response_size, data_transfer_size);
+     659                 :            : 
+     660                 :          1 :     spdm_response = (spdm_chunk_response_response_t*) response;
+     661                 :          1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+     662                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_CHUNK_RESPONSE);
+     663                 :          1 :     assert_int_equal(spdm_response->header.param1, 0);
+     664                 :          1 :     assert_int_equal(spdm_response->header.param2, chunk_handle);
+     665                 :          1 :     assert_int_equal(spdm_response->chunk_seq_no, 0);
+     666                 :          1 :     assert_int_equal(spdm_response->chunk_size, first_chunk_size);
+     667                 :            : 
+     668                 :          1 :     large_response = *(uint32_t*) (spdm_response + 1);
+     669                 :          1 :     assert_int_equal(large_response, total_chunk_size);
+     670                 :            : 
+     671                 :            :     /* Verify the 1st chunk is filled with 1 */
+     672                 :          1 :     chunk_ptr = (uint8_t*)(((uint32_t*) (spdm_response + 1)) + 1);
+     673         [ +  + ]:         29 :     for (i = 0; i < spdm_response->chunk_size; i++) {
+     674                 :         28 :         assert_int_equal(chunk_ptr[i], 1);
+     675                 :            :     }
+     676                 :          1 : }
+     677                 :            : 
+     678                 :            : /**
+     679                 :            :  * Test 11: Successful request of middle chunk.
+     680                 :            :  **/
+     681                 :          1 : void libspdm_test_responder_chunk_get_rsp_case11(void** state)
+     682                 :            : {
+     683                 :            :     libspdm_return_t status;
+     684                 :            :     libspdm_test_context_t* spdm_test_context;
+     685                 :            :     libspdm_context_t* spdm_context;
+     686                 :            :     size_t response_size;
+     687                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     688                 :            :     spdm_chunk_response_response_t* spdm_response;
+     689                 :            :     spdm_chunk_get_request_t spdm_request;
+     690                 :            :     void* scratch_buffer;
+     691                 :            :     size_t scratch_buffer_size;
+     692                 :            : 
+     693                 :            :     uint8_t chunk_handle;
+     694                 :            :     uint16_t chunk_seq_no;
+     695                 :            :     uint32_t data_transfer_size;
+     696                 :            :     uint32_t first_chunk_size;
+     697                 :            :     uint32_t second_chunk_size;
+     698                 :            :     uint32_t third_chunk_size;
+     699                 :            :     uint32_t total_chunk_size;
+     700                 :            :     uint8_t* chunk_ptr;
+     701                 :            :     uint32_t i;
+     702                 :            : 
+     703                 :          1 :     spdm_test_context = *state;
+     704                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     705                 :          1 :     spdm_test_context->case_id = 11;
+     706                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     707                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     708                 :            : 
+     709                 :          1 :     spdm_context->connection_info.connection_state =
+     710                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     711                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     712                 :            :         m_libspdm_use_hash_algo;
+     713                 :            : 
+     714                 :          1 :     data_transfer_size = CHUNK_GET_RESPONDER_UNIT_TEST_DATA_TRANSFER_SIZE;
+     715                 :          1 :     spdm_context->local_context.capability.data_transfer_size = data_transfer_size;
+     716                 :          1 :     spdm_context->local_context.capability.flags |=
+     717                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP;
+     718                 :          1 :     spdm_context->connection_info.capability.flags |=
+     719                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP;
+     720                 :            : 
+     721                 :          1 :     libspdm_get_scratch_buffer(spdm_context, &scratch_buffer, &scratch_buffer_size);
+     722                 :            : 
+     723                 :          2 :     scratch_buffer = (uint8_t*)scratch_buffer +
+     724                 :          1 :                      libspdm_get_scratch_buffer_large_message_offset(spdm_context);
+     725                 :          2 :     scratch_buffer_size = scratch_buffer_size -
+     726                 :          1 :                           libspdm_get_scratch_buffer_large_message_offset(spdm_context);
+     727                 :          1 :     libspdm_zero_mem(scratch_buffer, scratch_buffer_size);
+     728                 :            : 
+     729                 :            :     /* Fill 1st chunk with 1, 2nd chunk with 2, 3rd chunk with 3 */
+     730                 :          1 :     first_chunk_size = data_transfer_size -
+     731                 :            :                        (sizeof(spdm_chunk_response_response_t) + sizeof(uint32_t));
+     732                 :          1 :     second_chunk_size = data_transfer_size - sizeof(spdm_chunk_response_response_t);
+     733                 :          1 :     third_chunk_size = data_transfer_size - sizeof(spdm_chunk_response_response_t);
+     734                 :          1 :     total_chunk_size = first_chunk_size + second_chunk_size + third_chunk_size;
+     735         [ -  + ]:          1 :     LIBSPDM_ASSERT(total_chunk_size <= scratch_buffer_size);
+     736                 :            : 
+     737                 :          1 :     libspdm_set_mem(scratch_buffer, first_chunk_size, 1);
+     738                 :          1 :     libspdm_set_mem((uint8_t*) scratch_buffer + first_chunk_size, second_chunk_size, 2);
+     739                 :          1 :     libspdm_set_mem((uint8_t*) scratch_buffer + first_chunk_size + second_chunk_size,
+     740                 :            :                     third_chunk_size, 3);
+     741                 :            : 
+     742                 :          1 :     chunk_handle = (uint8_t) spdm_test_context->case_id; /* Any number is fine */
+     743                 :          1 :     chunk_seq_no = 1; /* 1 == 2nd chunk */
+     744                 :          1 :     spdm_context->chunk_context.get.chunk_in_use = true;
+     745                 :          1 :     spdm_context->chunk_context.get.chunk_handle = chunk_handle;
+     746                 :          1 :     spdm_context->chunk_context.get.chunk_seq_no = chunk_seq_no;
+     747                 :          1 :     spdm_context->chunk_context.get.large_message = scratch_buffer;
+     748                 :          1 :     spdm_context->chunk_context.get.large_message_size = total_chunk_size;
+     749                 :          1 :     spdm_context->chunk_context.get.chunk_bytes_transferred = first_chunk_size;
+     750                 :            : 
+     751                 :          1 :     libspdm_zero_mem(&spdm_request, sizeof(spdm_request));
+     752                 :          1 :     spdm_request.header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     753                 :          1 :     spdm_request.header.request_response_code = SPDM_CHUNK_GET;
+     754                 :          1 :     spdm_request.header.param1 = 0;
+     755                 :          1 :     spdm_request.header.param2 = chunk_handle;
+     756                 :          1 :     spdm_request.chunk_seq_no = chunk_seq_no;
+     757                 :            : 
+     758                 :          1 :     response_size = sizeof(response);
+     759                 :          1 :     status = libspdm_get_response_chunk_get(
+     760                 :            :         spdm_context,
+     761                 :            :         sizeof(spdm_request), &spdm_request,
+     762                 :            :         &response_size, response);
+     763                 :            : 
+     764                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     765                 :          1 :     assert_int_equal(response_size, data_transfer_size);
+     766                 :            : 
+     767                 :          1 :     spdm_response = (spdm_chunk_response_response_t*) response;
+     768                 :          1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+     769                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_CHUNK_RESPONSE);
+     770                 :          1 :     assert_int_equal(spdm_response->header.param1, 0);
+     771                 :          1 :     assert_int_equal(spdm_response->header.param2, chunk_handle);
+     772                 :          1 :     assert_int_equal(spdm_response->chunk_seq_no, chunk_seq_no);
+     773                 :          1 :     assert_int_equal(spdm_response->chunk_size, second_chunk_size);
+     774                 :            : 
+     775                 :            :     /* Verify the 2nd chunk is filled with 2 */
+     776                 :          1 :     chunk_ptr = (uint8_t*) (spdm_response + 1);
+     777         [ +  + ]:         33 :     for (i = 0; i < spdm_response->chunk_size; i++) {
+     778                 :         32 :         assert_int_equal(chunk_ptr[i], 2);
+     779                 :            :     }
+     780                 :          1 : }
+     781                 :            : 
+     782                 :            : /**
+     783                 :            :  * Test 12: Succesful request of last chunk where size is exactly max chunk size
+     784                 :            :  **/
+     785                 :          1 : void libspdm_test_responder_chunk_get_rsp_case12(void** state)
+     786                 :            : {
+     787                 :            :     libspdm_return_t status;
+     788                 :            :     libspdm_test_context_t* spdm_test_context;
+     789                 :            :     libspdm_context_t* spdm_context;
+     790                 :            :     size_t response_size;
+     791                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     792                 :            :     spdm_chunk_response_response_t* spdm_response;
+     793                 :            :     spdm_chunk_get_request_t spdm_request;
+     794                 :            :     void* scratch_buffer;
+     795                 :            :     size_t scratch_buffer_size;
+     796                 :            : 
+     797                 :            :     uint8_t chunk_handle;
+     798                 :            :     uint16_t chunk_seq_no;
+     799                 :            :     uint32_t data_transfer_size;
+     800                 :            :     uint32_t first_chunk_size;
+     801                 :            :     uint32_t second_chunk_size;
+     802                 :            :     uint32_t third_chunk_size;
+     803                 :            :     uint32_t total_chunk_size;
+     804                 :            :     uint8_t* chunk_ptr;
+     805                 :            :     uint32_t i;
+     806                 :            : 
+     807                 :          1 :     spdm_test_context = *state;
+     808                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     809                 :          1 :     spdm_test_context->case_id = 12;
+     810                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     811                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     812                 :            : 
+     813                 :          1 :     spdm_context->connection_info.connection_state =
+     814                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     815                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     816                 :            :         m_libspdm_use_hash_algo;
+     817                 :            : 
+     818                 :          1 :     data_transfer_size = CHUNK_GET_RESPONDER_UNIT_TEST_DATA_TRANSFER_SIZE;
+     819                 :          1 :     spdm_context->local_context.capability.data_transfer_size = data_transfer_size;
+     820                 :          1 :     spdm_context->local_context.capability.flags |=
+     821                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP;
+     822                 :          1 :     spdm_context->connection_info.capability.flags |=
+     823                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP;
+     824                 :            : 
+     825                 :          1 :     libspdm_get_scratch_buffer(spdm_context, &scratch_buffer, &scratch_buffer_size);
+     826                 :            : 
+     827                 :          2 :     scratch_buffer = (uint8_t*)scratch_buffer +
+     828                 :          1 :                      libspdm_get_scratch_buffer_large_message_offset(spdm_context);
+     829                 :          2 :     scratch_buffer_size = scratch_buffer_size -
+     830                 :          1 :                           libspdm_get_scratch_buffer_large_message_offset(spdm_context);
+     831                 :          1 :     libspdm_zero_mem(scratch_buffer, scratch_buffer_size);
+     832                 :            : 
+     833                 :            :     /* Fill 1st chunk with 1, 2nd chunk with 2, 3rd chunk with 3 */
+     834                 :          1 :     first_chunk_size = data_transfer_size -
+     835                 :            :                        (sizeof(spdm_chunk_response_response_t) + sizeof(uint32_t));
+     836                 :          1 :     second_chunk_size = data_transfer_size - sizeof(spdm_chunk_response_response_t);
+     837                 :          1 :     third_chunk_size = data_transfer_size - sizeof(spdm_chunk_response_response_t);
+     838                 :          1 :     total_chunk_size = first_chunk_size + second_chunk_size + third_chunk_size;
+     839         [ -  + ]:          1 :     LIBSPDM_ASSERT(total_chunk_size <= scratch_buffer_size);
+     840                 :            : 
+     841                 :          1 :     libspdm_set_mem(scratch_buffer, first_chunk_size, 1);
+     842                 :          1 :     libspdm_set_mem((uint8_t*) scratch_buffer + first_chunk_size, second_chunk_size, 2);
+     843                 :          1 :     libspdm_set_mem((uint8_t*) scratch_buffer + first_chunk_size + second_chunk_size,
+     844                 :            :                     third_chunk_size, 3);
+     845                 :            : 
+     846                 :          1 :     chunk_handle = (uint8_t) spdm_test_context->case_id; /* Any number is fine */
+     847                 :          1 :     chunk_seq_no = 2; /* 2 == 3rd chunk */
+     848                 :          1 :     spdm_context->chunk_context.get.chunk_in_use = true;
+     849                 :          1 :     spdm_context->chunk_context.get.chunk_handle = chunk_handle;
+     850                 :          1 :     spdm_context->chunk_context.get.chunk_seq_no = chunk_seq_no;
+     851                 :          1 :     spdm_context->chunk_context.get.large_message = scratch_buffer;
+     852                 :          1 :     spdm_context->chunk_context.get.large_message_size = total_chunk_size;
+     853                 :          1 :     spdm_context->chunk_context.get.chunk_bytes_transferred = first_chunk_size + second_chunk_size;
+     854                 :            : 
+     855                 :          1 :     libspdm_zero_mem(&spdm_request, sizeof(spdm_request));
+     856                 :          1 :     spdm_request.header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     857                 :          1 :     spdm_request.header.request_response_code = SPDM_CHUNK_GET;
+     858                 :          1 :     spdm_request.header.param1 = 0;
+     859                 :          1 :     spdm_request.header.param2 = chunk_handle;
+     860                 :          1 :     spdm_request.chunk_seq_no = chunk_seq_no;
+     861                 :            : 
+     862                 :          1 :     response_size = sizeof(response);
+     863                 :          1 :     status = libspdm_get_response_chunk_get(
+     864                 :            :         spdm_context,
+     865                 :            :         sizeof(spdm_request), &spdm_request,
+     866                 :            :         &response_size, response);
+     867                 :            : 
+     868                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     869                 :          1 :     assert_int_equal(response_size, data_transfer_size);
+     870                 :            : 
+     871                 :          1 :     spdm_response = (spdm_chunk_response_response_t*) response;
+     872                 :          1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+     873                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_CHUNK_RESPONSE);
+     874                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_CHUNK_GET_RESPONSE_ATTRIBUTE_LAST_CHUNK);
+     875                 :          1 :     assert_int_equal(spdm_response->header.param2, chunk_handle);
+     876                 :          1 :     assert_int_equal(spdm_response->chunk_seq_no, chunk_seq_no);
+     877                 :          1 :     assert_int_equal(spdm_response->chunk_size, third_chunk_size);
+     878                 :            : 
+     879                 :            :     /* Verify the 3nd chunk is filled with 3 */
+     880                 :          1 :     chunk_ptr = (uint8_t*) (spdm_response + 1);
+     881         [ +  + ]:         33 :     for (i = 0; i < spdm_response->chunk_size; i++) {
+     882                 :         32 :         assert_int_equal(chunk_ptr[i], 3);
+     883                 :            :     }
+     884                 :          1 : }
+     885                 :            : 
+     886                 :            : /**
+     887                 :            :  * Test 13: Succesful request of last chunk where size is exactly 1.
+     888                 :            :  **/
+     889                 :          1 : void libspdm_test_responder_chunk_get_rsp_case13(void** state)
+     890                 :            : {
+     891                 :            :     libspdm_return_t status;
+     892                 :            :     libspdm_test_context_t* spdm_test_context;
+     893                 :            :     libspdm_context_t* spdm_context;
+     894                 :            :     size_t response_size;
+     895                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     896                 :            :     spdm_chunk_response_response_t* spdm_response;
+     897                 :            :     spdm_chunk_get_request_t spdm_request;
+     898                 :            :     void* scratch_buffer;
+     899                 :            :     size_t scratch_buffer_size;
+     900                 :            : 
+     901                 :            :     uint8_t chunk_handle;
+     902                 :            :     uint16_t chunk_seq_no;
+     903                 :            :     uint32_t data_transfer_size;
+     904                 :            :     uint32_t first_chunk_size;
+     905                 :            :     uint32_t second_chunk_size;
+     906                 :            :     uint32_t third_chunk_size;
+     907                 :            :     uint32_t total_chunk_size;
+     908                 :            :     uint32_t fourth_chunk_size;
+     909                 :            :     uint32_t expected_response_size;
+     910                 :            :     uint8_t* chunk_ptr;
+     911                 :            :     uint32_t i;
+     912                 :            : 
+     913                 :          1 :     spdm_test_context = *state;
+     914                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     915                 :          1 :     spdm_test_context->case_id = 12;
+     916                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     917                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     918                 :            : 
+     919                 :          1 :     spdm_context->connection_info.connection_state =
+     920                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     921                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     922                 :            :         m_libspdm_use_hash_algo;
+     923                 :            : 
+     924                 :          1 :     data_transfer_size = CHUNK_GET_RESPONDER_UNIT_TEST_DATA_TRANSFER_SIZE;
+     925                 :          1 :     spdm_context->local_context.capability.data_transfer_size = data_transfer_size;
+     926                 :          1 :     spdm_context->local_context.capability.flags |=
+     927                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP;
+     928                 :          1 :     spdm_context->connection_info.capability.flags |=
+     929                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP;
+     930                 :            : 
+     931                 :          1 :     libspdm_get_scratch_buffer(spdm_context, &scratch_buffer, &scratch_buffer_size);
+     932                 :            : 
+     933                 :          2 :     scratch_buffer = (uint8_t*)scratch_buffer +
+     934                 :          1 :                      libspdm_get_scratch_buffer_large_message_offset(spdm_context);
+     935                 :          2 :     scratch_buffer_size = scratch_buffer_size -
+     936                 :          1 :                           libspdm_get_scratch_buffer_large_message_offset(spdm_context);
+     937                 :          1 :     libspdm_zero_mem(scratch_buffer, scratch_buffer_size);
+     938                 :            : 
+     939                 :            :     /* Fill 1st chunk with 1, 2nd chunk with 2, 3rd chunk with 3, 4th chunk with 4 */
+     940                 :          1 :     first_chunk_size = data_transfer_size -
+     941                 :            :                        (sizeof(spdm_chunk_response_response_t) + sizeof(uint32_t));
+     942                 :          1 :     second_chunk_size = data_transfer_size - sizeof(spdm_chunk_response_response_t);
+     943                 :          1 :     third_chunk_size = data_transfer_size - sizeof(spdm_chunk_response_response_t);
+     944                 :          1 :     fourth_chunk_size = 1;
+     945                 :            : 
+     946                 :          1 :     total_chunk_size = first_chunk_size + second_chunk_size + third_chunk_size + fourth_chunk_size;
+     947                 :          1 :     expected_response_size = sizeof(spdm_chunk_response_response_t) + fourth_chunk_size;
+     948         [ -  + ]:          1 :     LIBSPDM_ASSERT(total_chunk_size <= scratch_buffer_size);
+     949                 :            : 
+     950                 :          1 :     libspdm_set_mem(scratch_buffer, first_chunk_size, 1);
+     951                 :          1 :     libspdm_set_mem((uint8_t*) scratch_buffer + first_chunk_size, second_chunk_size, 2);
+     952                 :          1 :     libspdm_set_mem((uint8_t*) scratch_buffer + first_chunk_size + second_chunk_size,
+     953                 :            :                     third_chunk_size, 3);
+     954                 :          1 :     libspdm_set_mem((uint8_t*) scratch_buffer + first_chunk_size
+     955                 :          1 :                     + second_chunk_size + third_chunk_size,
+     956                 :            :                     fourth_chunk_size, 4);
+     957                 :            : 
+     958                 :          1 :     chunk_handle = (uint8_t) spdm_test_context->case_id; /* Any number is fine */
+     959                 :          1 :     chunk_seq_no = 3; /* 3 == 4th chunk */
+     960                 :          1 :     spdm_context->chunk_context.get.chunk_in_use = true;
+     961                 :          1 :     spdm_context->chunk_context.get.chunk_handle = chunk_handle;
+     962                 :          1 :     spdm_context->chunk_context.get.chunk_seq_no = chunk_seq_no;
+     963                 :          1 :     spdm_context->chunk_context.get.large_message = scratch_buffer;
+     964                 :          1 :     spdm_context->chunk_context.get.large_message_size = total_chunk_size;
+     965                 :          1 :     spdm_context->chunk_context.get.chunk_bytes_transferred =
+     966                 :          1 :         first_chunk_size + second_chunk_size + third_chunk_size;
+     967                 :            : 
+     968                 :          1 :     libspdm_zero_mem(&spdm_request, sizeof(spdm_request));
+     969                 :          1 :     spdm_request.header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     970                 :          1 :     spdm_request.header.request_response_code = SPDM_CHUNK_GET;
+     971                 :          1 :     spdm_request.header.param1 = 0;
+     972                 :          1 :     spdm_request.header.param2 = chunk_handle;
+     973                 :          1 :     spdm_request.chunk_seq_no = chunk_seq_no;
+     974                 :            : 
+     975                 :          1 :     response_size = sizeof(response);
+     976                 :          1 :     status = libspdm_get_response_chunk_get(
+     977                 :            :         spdm_context,
+     978                 :            :         sizeof(spdm_request), &spdm_request,
+     979                 :            :         &response_size, response);
+     980                 :            : 
+     981                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     982                 :          1 :     assert_int_equal(response_size, expected_response_size);
+     983                 :            : 
+     984                 :          1 :     spdm_response = (spdm_chunk_response_response_t*) response;
+     985                 :          1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+     986                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_CHUNK_RESPONSE);
+     987                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_CHUNK_GET_RESPONSE_ATTRIBUTE_LAST_CHUNK);
+     988                 :          1 :     assert_int_equal(spdm_response->header.param2, chunk_handle);
+     989                 :          1 :     assert_int_equal(spdm_response->chunk_seq_no, chunk_seq_no);
+     990                 :          1 :     assert_int_equal(spdm_response->chunk_size, fourth_chunk_size);
+     991                 :            : 
+     992                 :            :     /* Verify the 4th chunk is filled with 4 */
+     993                 :          1 :     chunk_ptr = (uint8_t*)(spdm_response + 1);
+     994         [ +  + ]:          2 :     for (i = 0; i < spdm_response->chunk_size; i++) {
+     995                 :          1 :         assert_int_equal(chunk_ptr[i], 4);
+     996                 :            :     }
+     997                 :          1 : }
+     998                 :            : 
+     999                 :            : 
+    1000                 :            : libspdm_test_context_t m_libspdm_responder_chunk_get_rsp_test_context = {
+    1001                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+    1002                 :            :     false,
+    1003                 :            : };
+    1004                 :            : 
+    1005                 :          1 : int libspdm_responder_chunk_get_rsp_test_main(void)
+    1006                 :            : {
+    1007                 :          1 :     const struct CMUnitTest spdm_responder_chunk_get_tests[] = {
+    1008                 :            :         /* Responder has no response flag chunk cap */
+    1009                 :            :         cmocka_unit_test(libspdm_test_responder_chunk_get_rsp_case1),
+    1010                 :            :         /* Responder has response state != NORMAL */
+    1011                 :            :         cmocka_unit_test(libspdm_test_responder_chunk_get_rsp_case2),
+    1012                 :            :         /* Responder has connection state <= NOT_START */
+    1013                 :            :         cmocka_unit_test(libspdm_test_responder_chunk_get_rsp_case3),
+    1014                 :            :         /* Request has wrong size */
+    1015                 :            :         cmocka_unit_test(libspdm_test_responder_chunk_get_rsp_case4),
+    1016                 :            :         /* Request has wrong SPDM version */
+    1017                 :            :         cmocka_unit_test(libspdm_test_responder_chunk_get_rsp_case5),
+    1018                 :            :         /* Responder has no chunk saved to get */
+    1019                 :            :         cmocka_unit_test(libspdm_test_responder_chunk_get_rsp_case6),
+    1020                 :            :         /* Responder has handle that does not match request */
+    1021                 :            :         cmocka_unit_test(libspdm_test_responder_chunk_get_rsp_case7),
+    1022                 :            :         /* Responder has earlier sequence number than request */
+    1023                 :            :         cmocka_unit_test(libspdm_test_responder_chunk_get_rsp_case8),
+    1024                 :            :         /* Responder has later sequence number than request*/
+    1025                 :            :         cmocka_unit_test(libspdm_test_responder_chunk_get_rsp_case9),
+    1026                 :            :         /* Successful request of first chunk */
+    1027                 :            :         cmocka_unit_test(libspdm_test_responder_chunk_get_rsp_case10),
+    1028                 :            :         /* Successful request of middle chunk */
+    1029                 :            :         cmocka_unit_test(libspdm_test_responder_chunk_get_rsp_case11),
+    1030                 :            :         /* Succesful request of last chunk, where size is exactly max chunk size */
+    1031                 :            :         cmocka_unit_test(libspdm_test_responder_chunk_get_rsp_case12),
+    1032                 :            :         /* Successful request of last chunk where chunk size is exactly 1 byte */
+    1033                 :            :         cmocka_unit_test(libspdm_test_responder_chunk_get_rsp_case13),
+    1034                 :            :     };
+    1035                 :            : 
+    1036                 :          1 :     libspdm_setup_test_context(&m_libspdm_responder_chunk_get_rsp_test_context);
+    1037                 :            : 
+    1038                 :          1 :     return cmocka_run_group_tests(spdm_responder_chunk_get_tests,
+    1039                 :            :                                   libspdm_unit_test_group_setup,
+    1040                 :            :                                   libspdm_unit_test_group_teardown);
+    1041                 :            : }
+    1042                 :            : 
+    1043                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/chunk_send_ack.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_responder/chunk_send_ack.c.func-sort-c.html new file mode 100644 index 00000000000..f9070b4c867 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/chunk_send_ack.c.func-sort-c.html @@ -0,0 +1,173 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/chunk_send_ack.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - chunk_send_ack.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:780780100.0 %
Date:2024-09-22 08:21:07Functions:2323100.0 %
Branches:5683.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_chunk_send_ack_test_main1
libspdm_test_responder_chunk_send_ack_rsp_case01
libspdm_test_responder_chunk_send_ack_rsp_case11
libspdm_test_responder_chunk_send_ack_rsp_case101
libspdm_test_responder_chunk_send_ack_rsp_case111
libspdm_test_responder_chunk_send_ack_rsp_case121
libspdm_test_responder_chunk_send_ack_rsp_case131
libspdm_test_responder_chunk_send_ack_rsp_case141
libspdm_test_responder_chunk_send_ack_rsp_case151
libspdm_test_responder_chunk_send_ack_rsp_case161
libspdm_test_responder_chunk_send_ack_rsp_case171
libspdm_test_responder_chunk_send_ack_rsp_case181
libspdm_test_responder_chunk_send_ack_rsp_case191
libspdm_test_responder_chunk_send_ack_rsp_case21
libspdm_test_responder_chunk_send_ack_rsp_case31
libspdm_test_responder_chunk_send_ack_rsp_case41
libspdm_test_responder_chunk_send_ack_rsp_case51
libspdm_test_responder_chunk_send_ack_rsp_case61
libspdm_test_responder_chunk_send_ack_rsp_case71
libspdm_test_responder_chunk_send_ack_rsp_case81
libspdm_test_responder_chunk_send_ack_rsp_case91
libspdm_test_responder_chunk_send_ack_reset_send_state7
libspdm_test_responder_chunk_send_ack_setup_algo_state20
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/chunk_send_ack.c.func.html b/coverage_log/unit_test/test_spdm_responder/chunk_send_ack.c.func.html new file mode 100644 index 00000000000..b88f5af6fc2 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/chunk_send_ack.c.func.html @@ -0,0 +1,173 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/chunk_send_ack.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - chunk_send_ack.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:780780100.0 %
Date:2024-09-22 08:21:07Functions:2323100.0 %
Branches:5683.3 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_chunk_send_ack_test_main1
libspdm_test_responder_chunk_send_ack_reset_send_state7
libspdm_test_responder_chunk_send_ack_rsp_case01
libspdm_test_responder_chunk_send_ack_rsp_case11
libspdm_test_responder_chunk_send_ack_rsp_case101
libspdm_test_responder_chunk_send_ack_rsp_case111
libspdm_test_responder_chunk_send_ack_rsp_case121
libspdm_test_responder_chunk_send_ack_rsp_case131
libspdm_test_responder_chunk_send_ack_rsp_case141
libspdm_test_responder_chunk_send_ack_rsp_case151
libspdm_test_responder_chunk_send_ack_rsp_case161
libspdm_test_responder_chunk_send_ack_rsp_case171
libspdm_test_responder_chunk_send_ack_rsp_case181
libspdm_test_responder_chunk_send_ack_rsp_case191
libspdm_test_responder_chunk_send_ack_rsp_case21
libspdm_test_responder_chunk_send_ack_rsp_case31
libspdm_test_responder_chunk_send_ack_rsp_case41
libspdm_test_responder_chunk_send_ack_rsp_case51
libspdm_test_responder_chunk_send_ack_rsp_case61
libspdm_test_responder_chunk_send_ack_rsp_case71
libspdm_test_responder_chunk_send_ack_rsp_case81
libspdm_test_responder_chunk_send_ack_rsp_case91
libspdm_test_responder_chunk_send_ack_setup_algo_state20
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/chunk_send_ack.c.gcov.html b/coverage_log/unit_test/test_spdm_responder/chunk_send_ack.c.gcov.html new file mode 100644 index 00000000000..66c472d0bad --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/chunk_send_ack.c.gcov.html @@ -0,0 +1,1852 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/chunk_send_ack.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - chunk_send_ack.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:780780100.0 %
Date:2024-09-22 08:21:07Functions:2323100.0 %
Branches:5683.3 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_responder_lib.h"
+       9                 :            : 
+      10                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
+      11                 :            : 
+      12                 :            : #define CHUNK_SEND_ACK_RESPONDER_UNIT_TEST_DATA_TRANSFER_SIZE (42)
+      13                 :            : 
+      14                 :            : typedef struct {
+      15                 :            :     spdm_negotiate_algorithms_request_t spdm_request_version10;
+      16                 :            :     spdm_negotiate_algorithms_common_struct_table_t struct_table[4];
+      17                 :            : } libspdm_negotiate_algorithms_request_spdm_tables_t;
+      18                 :            : 
+      19                 :            : libspdm_negotiate_algorithms_request_spdm_tables_t
+      20                 :            :     m_libspdm_chunk_send_negotiate_algorithm_request1 =
+      21                 :            : {
+      22                 :            :     {
+      23                 :            :         {
+      24                 :            :             SPDM_MESSAGE_VERSION_12,
+      25                 :            :             SPDM_NEGOTIATE_ALGORITHMS,
+      26                 :            :             4,
+      27                 :            :             0
+      28                 :            :         },
+      29                 :            :         sizeof(libspdm_negotiate_algorithms_request_spdm_tables_t),
+      30                 :            :         SPDM_MEASUREMENT_SPECIFICATION_DMTF,
+      31                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1,
+      32                 :            :     },
+      33                 :            :     {
+      34                 :            :         {
+      35                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE,
+      36                 :            :             0x20,
+      37                 :            :             SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_256_R1
+      38                 :            :         },
+      39                 :            :         {
+      40                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD,
+      41                 :            :             0x20,
+      42                 :            :             SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_256_GCM
+      43                 :            :         },
+      44                 :            :         {
+      45                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG,
+      46                 :            :             0x20,
+      47                 :            :             SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048
+      48                 :            :         },
+      49                 :            :         {
+      50                 :            :             SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE,
+      51                 :            :             0x20,
+      52                 :            :             SPDM_ALGORITHMS_KEY_SCHEDULE_HMAC_HASH
+      53                 :            :         }
+      54                 :            :     }
+      55                 :            : };
+      56                 :            : 
+      57                 :            : size_t m_libspdm_chunk_send_negotiate_algorithm_request1_size =
+      58                 :            :     sizeof(m_libspdm_chunk_send_negotiate_algorithm_request1);
+      59                 :            : 
+      60                 :         20 : void libspdm_test_responder_chunk_send_ack_setup_algo_state(libspdm_context_t* spdm_context)
+      61                 :            : {
+      62                 :            :     /* This state is copied form Algorithms test case 22 */
+      63                 :         20 :     m_libspdm_chunk_send_negotiate_algorithm_request1.spdm_request_version10.base_hash_algo =
+      64                 :            :         m_libspdm_use_hash_algo;
+      65                 :         20 :     m_libspdm_chunk_send_negotiate_algorithm_request1.spdm_request_version10.base_asym_algo =
+      66                 :            :         m_libspdm_use_asym_algo;
+      67                 :            : 
+      68                 :         20 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+      69                 :         20 :     spdm_context->connection_info.connection_state =
+      70                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
+      71                 :            : 
+      72                 :         20 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+      73                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+      74                 :         20 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+      75                 :         20 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+      76                 :         20 :     spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+      77                 :         20 :     spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+      78                 :         20 :     spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+      79                 :         20 :     spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+      80                 :         20 :     spdm_context->local_context.algorithm.other_params_support =
+      81                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
+      82                 :            :     /* spdm_context->connection_info.algorithm.other_params_support = SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1; */
+      83                 :         20 :     libspdm_reset_message_a(spdm_context);
+      84                 :         20 :     spdm_context->local_context.capability.flags = 0;
+      85                 :         20 :     spdm_context->connection_info.capability.flags = 0;
+      86                 :         20 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+      87                 :         20 :     spdm_context->connection_info.capability.flags |=
+      88                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+      89                 :            : 
+      90                 :         20 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+      91                 :         20 :     spdm_context->connection_info.capability.flags |=
+      92                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+      93                 :            : 
+      94                 :         20 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+      95                 :         20 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+      96                 :            : 
+      97                 :         20 :     spdm_context->local_context.capability.flags |=
+      98                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
+      99                 :         20 :     spdm_context->connection_info.capability.flags |=
+     100                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
+     101                 :            : 
+     102                 :         20 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     103                 :         20 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     104                 :            : 
+     105                 :         20 :     spdm_context->local_context.capability.data_transfer_size =
+     106                 :            :         CHUNK_SEND_ACK_RESPONDER_UNIT_TEST_DATA_TRANSFER_SIZE;
+     107                 :            : 
+     108                 :         20 :     spdm_context->local_context.capability.flags |=
+     109                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP;
+     110                 :         20 :     spdm_context->connection_info.capability.flags |=
+     111                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP;
+     112                 :         20 : }
+     113                 :            : 
+     114                 :            : /* Test sending large NegAlg Request in multiple chunks. */
+     115                 :          1 : void libspdm_test_responder_chunk_send_ack_rsp_case0(void** state)
+     116                 :            : {
+     117                 :            :     libspdm_return_t status;
+     118                 :            : 
+     119                 :            :     libspdm_test_context_t* spdm_test_context;
+     120                 :            :     libspdm_context_t* spdm_context;
+     121                 :            : 
+     122                 :            :     size_t request_size;
+     123                 :            :     size_t response_size;
+     124                 :            : 
+     125                 :            :     uint8_t request[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     126                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     127                 :            : 
+     128                 :            :     spdm_chunk_send_request_t *chunk_send_request;
+     129                 :            :     spdm_chunk_send_ack_response_t* chunk_send_ack_response;
+     130                 :            :     spdm_algorithms_response_t *algorithms_response;
+     131                 :            :     size_t algorithms_response_size;
+     132                 :            : 
+     133                 :            :     const uint8_t* chunk_src;
+     134                 :            :     uint8_t* chunk_dst;
+     135                 :            :     uint16_t chunk_num;
+     136                 :            :     uint32_t bytes_sent;
+     137                 :            :     uint32_t bytes_total;
+     138                 :            : 
+     139                 :          1 :     spdm_test_context = *state;
+     140                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     141                 :          1 :     spdm_test_context->case_id = 0;
+     142                 :            : 
+     143                 :          1 :     libspdm_test_responder_chunk_send_ack_setup_algo_state(spdm_context);
+     144                 :            : 
+     145                 :          1 :     chunk_num = 0;
+     146                 :          1 :     bytes_sent = 0;
+     147                 :          1 :     bytes_total = sizeof(m_libspdm_chunk_send_negotiate_algorithm_request1);
+     148                 :          1 :     chunk_src = (const uint8_t *)&m_libspdm_chunk_send_negotiate_algorithm_request1;
+     149                 :            : 
+     150                 :            :     do {
+     151                 :          2 :         libspdm_zero_mem(request, sizeof(request));
+     152                 :          2 :         chunk_send_request = (spdm_chunk_send_request_t*)request;
+     153                 :            : 
+     154                 :          2 :         chunk_send_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     155                 :          2 :         chunk_send_request->header.request_response_code = SPDM_CHUNK_SEND;
+     156                 :          2 :         chunk_send_request->header.param1 = 0;
+     157                 :          2 :         chunk_send_request->header.param2 = (uint8_t) spdm_test_context->case_id; /* chunk_handle */
+     158                 :          2 :         chunk_send_request->chunk_seq_no = chunk_num;
+     159                 :            : 
+     160         [ +  + ]:          2 :         if (chunk_num == 0) {
+     161                 :          1 :             *((uint32_t*) (chunk_send_request + 1)) = bytes_total;
+     162                 :          1 :             chunk_send_request->chunk_size =
+     163                 :          1 :                 spdm_context->local_context.capability.data_transfer_size
+     164                 :          1 :                 - sizeof(spdm_chunk_send_request_t) - sizeof(uint32_t);
+     165                 :            : 
+     166                 :          1 :             chunk_dst = ((uint8_t*) (chunk_send_request + 1)) + sizeof(uint32_t);
+     167                 :            : 
+     168                 :          1 :             request_size = sizeof(spdm_chunk_send_request_t)
+     169                 :            :                            + sizeof(uint32_t)
+     170                 :          1 :                            + chunk_send_request->chunk_size;
+     171                 :            :         } else {
+     172                 :          1 :             chunk_send_request->chunk_size =
+     173                 :          1 :                 LIBSPDM_MIN(
+     174                 :            :                     spdm_context->local_context.capability.data_transfer_size
+     175                 :            :                     - sizeof(spdm_chunk_send_request_t),
+     176                 :            :                     bytes_total - bytes_sent);
+     177                 :            : 
+     178                 :          1 :             chunk_dst = ((uint8_t*) (chunk_send_request + 1));
+     179                 :            : 
+     180                 :          1 :             request_size = sizeof(spdm_chunk_send_request_t)
+     181                 :          1 :                            + chunk_send_request->chunk_size;
+     182                 :            : 
+     183         [ +  - ]:          1 :             if (bytes_total - bytes_sent == chunk_send_request->chunk_size) {
+     184                 :          1 :                 chunk_send_request->header.param1 = SPDM_CHUNK_SEND_REQUEST_ATTRIBUTE_LAST_CHUNK;
+     185                 :            :             }
+     186                 :            :         }
+     187                 :            : 
+     188                 :          2 :         libspdm_copy_mem(chunk_dst, chunk_send_request->chunk_size,
+     189                 :          2 :                          chunk_src, chunk_send_request->chunk_size);
+     190                 :            : 
+     191                 :          2 :         chunk_src += chunk_send_request->chunk_size;
+     192                 :          2 :         bytes_sent += chunk_send_request->chunk_size;
+     193                 :          2 :         chunk_num++;
+     194                 :            : 
+     195                 :          2 :         response_size = sizeof(response);
+     196                 :          2 :         status = libspdm_get_response_chunk_send(
+     197                 :            :             spdm_context,
+     198                 :            :             request_size, request,
+     199                 :            :             &response_size, response);
+     200                 :            : 
+     201                 :          2 :         assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     202                 :          2 :         assert_true(response_size >= sizeof(spdm_chunk_send_ack_response_t));
+     203                 :            : 
+     204                 :          2 :         chunk_send_ack_response = (spdm_chunk_send_ack_response_t*) response;
+     205                 :          2 :         assert_int_equal(chunk_send_ack_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+     206                 :          2 :         assert_int_equal(chunk_send_ack_response->header.request_response_code,
+     207                 :            :                          SPDM_CHUNK_SEND_ACK);
+     208                 :          2 :         assert_int_equal(chunk_send_ack_response->header.param1, 0);
+     209                 :          2 :         assert_int_equal(chunk_send_ack_response->header.param2, spdm_test_context->case_id);
+     210                 :          2 :         assert_int_equal(chunk_send_ack_response->chunk_seq_no, chunk_send_request->chunk_seq_no);
+     211                 :            : 
+     212         [ +  + ]:          2 :     } while (bytes_sent < bytes_total);
+     213                 :            : 
+     214                 :          1 :     algorithms_response = (spdm_algorithms_response_t*) (chunk_send_ack_response + 1);
+     215                 :          1 :     algorithms_response_size = response_size - sizeof(spdm_chunk_send_ack_response_t);
+     216                 :          1 :     assert_int_equal(algorithms_response->header.request_response_code, SPDM_ALGORITHMS);
+     217                 :            : 
+     218                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     219                 :          1 :     assert_int_equal(algorithms_response_size,
+     220                 :            :                      sizeof(spdm_algorithms_response_t) + 4 *
+     221                 :            :                      sizeof(spdm_negotiate_algorithms_common_struct_table_t));
+     222                 :          1 :     assert_int_equal(algorithms_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+     223                 :          1 :     assert_int_equal(algorithms_response->header.request_response_code, SPDM_ALGORITHMS);
+     224                 :          1 :     assert_int_equal(algorithms_response->header.param1, 4);
+     225                 :          1 : }
+     226                 :            : 
+     227                 :            : /**
+     228                 :            :  * Test 1: Responder receives a CHUNK_SEND request without chunk capabilities.
+     229                 :            :  * Expected Behavior: Returns ERROR response message with an error code.
+     230                 :            :  **/
+     231                 :          1 : void libspdm_test_responder_chunk_send_ack_rsp_case1(void** state)
+     232                 :            : {
+     233                 :            :     libspdm_return_t status;
+     234                 :            : 
+     235                 :            :     libspdm_test_context_t* spdm_test_context;
+     236                 :            :     libspdm_context_t* spdm_context;
+     237                 :            : 
+     238                 :            :     size_t request_size;
+     239                 :            :     size_t response_size;
+     240                 :            : 
+     241                 :            :     uint8_t request[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     242                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     243                 :            : 
+     244                 :            :     spdm_chunk_send_request_t* chunk_send_request;
+     245                 :            :     spdm_error_response_t* error_response;
+     246                 :            : 
+     247                 :            :     const uint8_t* chunk_src;
+     248                 :            :     uint8_t* chunk_dst;
+     249                 :            :     uint16_t chunk_num;
+     250                 :            :     uint32_t bytes_total;
+     251                 :            : 
+     252                 :          1 :     spdm_test_context = *state;
+     253                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     254                 :          1 :     spdm_test_context->case_id = 1;
+     255                 :            : 
+     256                 :          1 :     libspdm_test_responder_chunk_send_ack_setup_algo_state(spdm_context);
+     257                 :            : 
+     258                 :          1 :     spdm_context->local_context.capability.flags &=
+     259                 :            :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP;
+     260                 :          1 :     spdm_context->connection_info.capability.flags |=
+     261                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP;
+     262                 :            : 
+     263                 :          1 :     chunk_num = 0;
+     264                 :          1 :     bytes_total = sizeof(m_libspdm_chunk_send_negotiate_algorithm_request1);
+     265                 :          1 :     chunk_src = (const uint8_t*) &m_libspdm_chunk_send_negotiate_algorithm_request1;
+     266                 :            : 
+     267                 :          1 :     libspdm_zero_mem(request, sizeof(request));
+     268                 :          1 :     chunk_send_request = (spdm_chunk_send_request_t*) request;
+     269                 :            : 
+     270                 :          1 :     chunk_send_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     271                 :          1 :     chunk_send_request->header.request_response_code = SPDM_CHUNK_SEND;
+     272                 :          1 :     chunk_send_request->header.param1 = 0;
+     273                 :          1 :     chunk_send_request->header.param2 = (uint8_t) spdm_test_context->case_id; /* chunk_handle */
+     274                 :          1 :     chunk_send_request->chunk_seq_no = chunk_num;
+     275                 :            : 
+     276                 :          1 :     *((uint32_t*) (chunk_send_request + 1)) = bytes_total;
+     277                 :          1 :     chunk_send_request->chunk_size =
+     278                 :          1 :         spdm_context->local_context.capability.data_transfer_size
+     279                 :          1 :         - sizeof(spdm_chunk_send_request_t) - sizeof(uint32_t);
+     280                 :            : 
+     281                 :          1 :     chunk_dst = ((uint8_t*) (chunk_send_request + 1)) + sizeof(uint32_t);
+     282                 :            : 
+     283                 :          1 :     request_size = sizeof(spdm_chunk_send_request_t)
+     284                 :            :                    + sizeof(uint32_t)
+     285                 :          1 :                    + chunk_send_request->chunk_size;
+     286                 :            : 
+     287                 :          1 :     libspdm_copy_mem(chunk_dst, chunk_send_request->chunk_size,
+     288                 :          1 :                      chunk_src, chunk_send_request->chunk_size);
+     289                 :            : 
+     290                 :          1 :     response_size = sizeof(response);
+     291                 :          1 :     status = libspdm_get_response_chunk_send(
+     292                 :            :         spdm_context,
+     293                 :            :         request_size, request,
+     294                 :            :         &response_size, response);
+     295                 :            : 
+     296                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     297                 :          1 :     assert_true(response_size == sizeof(spdm_error_response_t));
+     298                 :            : 
+     299                 :          1 :     error_response = (spdm_error_response_t*) response;
+     300                 :          1 :     assert_int_equal(error_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+     301                 :          1 :     assert_int_equal(error_response->header.request_response_code, SPDM_ERROR);
+     302                 :          1 :     assert_int_equal(error_response->header.param1, SPDM_ERROR_CODE_UNEXPECTED_REQUEST);
+     303                 :          1 :     assert_int_equal(error_response->header.param2, 0);
+     304                 :          1 : }
+     305                 :            : 
+     306                 :            : /**
+     307                 :            :  * Test 2: Responder receives a CHUNK_SEND request with bad response state.
+     308                 :            :  * Expected Behavior: Returns ERROR response message
+     309                 :            :  * with request_response_code as error code.
+     310                 :            :  **/
+     311                 :          1 : void libspdm_test_responder_chunk_send_ack_rsp_case2(void** state)
+     312                 :            : {
+     313                 :            :     libspdm_return_t status;
+     314                 :            : 
+     315                 :            :     libspdm_test_context_t* spdm_test_context;
+     316                 :            :     libspdm_context_t* spdm_context;
+     317                 :            : 
+     318                 :            :     size_t request_size;
+     319                 :            :     size_t response_size;
+     320                 :            : 
+     321                 :            :     uint8_t request[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     322                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     323                 :            : 
+     324                 :            :     spdm_chunk_send_request_t* chunk_send_request;
+     325                 :            :     spdm_error_response_t* error_response;
+     326                 :            : 
+     327                 :            :     const uint8_t* chunk_src;
+     328                 :            :     uint8_t* chunk_dst;
+     329                 :            :     uint16_t chunk_num;
+     330                 :            :     uint32_t bytes_total;
+     331                 :            : 
+     332                 :          1 :     spdm_test_context = *state;
+     333                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     334                 :          1 :     spdm_test_context->case_id = 2;
+     335                 :            : 
+     336                 :          1 :     libspdm_test_responder_chunk_send_ack_setup_algo_state(spdm_context);
+     337                 :            : 
+     338                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_BUSY;
+     339                 :            : 
+     340                 :          1 :     chunk_num = 0;
+     341                 :          1 :     bytes_total = sizeof(m_libspdm_chunk_send_negotiate_algorithm_request1);
+     342                 :          1 :     chunk_src = (const uint8_t*) &m_libspdm_chunk_send_negotiate_algorithm_request1;
+     343                 :            : 
+     344                 :          1 :     libspdm_zero_mem(request, sizeof(request));
+     345                 :          1 :     chunk_send_request = (spdm_chunk_send_request_t*) request;
+     346                 :            : 
+     347                 :          1 :     chunk_send_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     348                 :          1 :     chunk_send_request->header.request_response_code = SPDM_CHUNK_SEND;
+     349                 :          1 :     chunk_send_request->header.param1 = 0;
+     350                 :          1 :     chunk_send_request->header.param2 = (uint8_t)spdm_test_context->case_id; /* chunk_handle */
+     351                 :          1 :     chunk_send_request->chunk_seq_no = chunk_num;
+     352                 :            : 
+     353                 :          1 :     *((uint32_t*) (chunk_send_request + 1)) = bytes_total;
+     354                 :          1 :     chunk_send_request->chunk_size =
+     355                 :          1 :         spdm_context->local_context.capability.data_transfer_size
+     356                 :          1 :         - sizeof(spdm_chunk_send_request_t) - sizeof(uint32_t);
+     357                 :            : 
+     358                 :          1 :     chunk_dst = ((uint8_t*) (chunk_send_request + 1)) + sizeof(uint32_t);
+     359                 :            : 
+     360                 :          1 :     request_size = sizeof(spdm_chunk_send_request_t)
+     361                 :            :                    + sizeof(uint32_t)
+     362                 :          1 :                    + chunk_send_request->chunk_size;
+     363                 :            : 
+     364                 :          1 :     libspdm_copy_mem(chunk_dst, chunk_send_request->chunk_size,
+     365                 :          1 :                      chunk_src, chunk_send_request->chunk_size);
+     366                 :            : 
+     367                 :          1 :     response_size = sizeof(response);
+     368                 :          1 :     status = libspdm_get_response_chunk_send(
+     369                 :            :         spdm_context,
+     370                 :            :         request_size, request,
+     371                 :            :         &response_size, response);
+     372                 :            : 
+     373                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     374                 :          1 :     assert_true(response_size == sizeof(spdm_error_response_t));
+     375                 :            : 
+     376                 :          1 :     error_response = (spdm_error_response_t*) response;
+     377                 :          1 :     assert_int_equal(error_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+     378                 :          1 :     assert_int_equal(error_response->header.request_response_code, SPDM_ERROR);
+     379                 :          1 :     assert_int_equal(error_response->header.param1, SPDM_ERROR_CODE_BUSY);
+     380                 :          1 :     assert_int_equal(error_response->header.param2, 0);
+     381                 :          1 : }
+     382                 :            : 
+     383                 :            : /**
+     384                 :            :  * Test 3: Responder receives a CHUNK_SEND request with bad connection state.
+     385                 :            :  * Expected Behavior: Returns ERROR response message
+     386                 :            :  * with SPDM_ERROR_CODE_UNEXPECTED_REQUEST error code.
+     387                 :            :  **/
+     388                 :          1 : void libspdm_test_responder_chunk_send_ack_rsp_case3(void** state)
+     389                 :            : {
+     390                 :            :     libspdm_return_t status;
+     391                 :            : 
+     392                 :            :     libspdm_test_context_t* spdm_test_context;
+     393                 :            :     libspdm_context_t* spdm_context;
+     394                 :            : 
+     395                 :            :     size_t request_size;
+     396                 :            :     size_t response_size;
+     397                 :            : 
+     398                 :            :     uint8_t request[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     399                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     400                 :            : 
+     401                 :            :     spdm_chunk_send_request_t* chunk_send_request;
+     402                 :            :     spdm_error_response_t* error_response;
+     403                 :            : 
+     404                 :            :     const uint8_t* chunk_src;
+     405                 :            :     uint8_t* chunk_dst;
+     406                 :            :     uint16_t chunk_num;
+     407                 :            :     uint32_t bytes_total;
+     408                 :            : 
+     409                 :          1 :     spdm_test_context = *state;
+     410                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     411                 :          1 :     spdm_test_context->case_id = 3;
+     412                 :            : 
+     413                 :          1 :     libspdm_test_responder_chunk_send_ack_setup_algo_state(spdm_context);
+     414                 :            : 
+     415                 :            :     spdm_context->connection_info.connection_state
+     416                 :          1 :         = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES - 1;
+     417                 :            : 
+     418                 :          1 :     chunk_num = 0;
+     419                 :          1 :     bytes_total = sizeof(m_libspdm_chunk_send_negotiate_algorithm_request1);
+     420                 :          1 :     chunk_src = (const uint8_t*) &m_libspdm_chunk_send_negotiate_algorithm_request1;
+     421                 :            : 
+     422                 :          1 :     libspdm_zero_mem(request, sizeof(request));
+     423                 :          1 :     chunk_send_request = (spdm_chunk_send_request_t*) request;
+     424                 :            : 
+     425                 :          1 :     chunk_send_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     426                 :          1 :     chunk_send_request->header.request_response_code = SPDM_CHUNK_SEND;
+     427                 :          1 :     chunk_send_request->header.param1 = 0;
+     428                 :          1 :     chunk_send_request->header.param2 = (uint8_t) spdm_test_context->case_id; /* chunk_handle */
+     429                 :          1 :     chunk_send_request->chunk_seq_no = chunk_num;
+     430                 :            : 
+     431                 :          1 :     *((uint32_t*) (chunk_send_request + 1)) = bytes_total;
+     432                 :          1 :     chunk_send_request->chunk_size =
+     433                 :          1 :         spdm_context->local_context.capability.data_transfer_size
+     434                 :          1 :         - sizeof(spdm_chunk_send_request_t) - sizeof(uint32_t);
+     435                 :            : 
+     436                 :          1 :     chunk_dst = ((uint8_t*) (chunk_send_request + 1)) + sizeof(uint32_t);
+     437                 :            : 
+     438                 :          1 :     request_size = sizeof(spdm_chunk_send_request_t)
+     439                 :            :                    + sizeof(uint32_t)
+     440                 :          1 :                    + chunk_send_request->chunk_size;
+     441                 :            : 
+     442                 :          1 :     libspdm_copy_mem(chunk_dst, chunk_send_request->chunk_size,
+     443                 :          1 :                      chunk_src, chunk_send_request->chunk_size);
+     444                 :            : 
+     445                 :          1 :     response_size = sizeof(response);
+     446                 :          1 :     status = libspdm_get_response_chunk_send(
+     447                 :            :         spdm_context,
+     448                 :            :         request_size, request,
+     449                 :            :         &response_size, response);
+     450                 :            : 
+     451                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     452                 :          1 :     assert_true(response_size == sizeof(spdm_error_response_t));
+     453                 :            : 
+     454                 :          1 :     error_response = (spdm_error_response_t*) response;
+     455                 :          1 :     assert_int_equal(error_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+     456                 :          1 :     assert_int_equal(error_response->header.request_response_code, SPDM_ERROR);
+     457                 :          1 :     assert_int_equal(error_response->header.param1, SPDM_ERROR_CODE_UNEXPECTED_REQUEST);
+     458                 :          1 :     assert_int_equal(error_response->header.param2, 0);
+     459                 :          1 : }
+     460                 :            : 
+     461                 :            : 
+     462                 :            : /**
+     463                 :            :  * Test 4: Responder receives a CHUNK_SEND request with bad size.
+     464                 :            :  * Expected Behavior: Returns ERROR response message
+     465                 :            :  * with SPDM_ERROR_CODE_INVALID_REQUEST error code.
+     466                 :            :  **/
+     467                 :          1 : void libspdm_test_responder_chunk_send_ack_rsp_case4(void** state)
+     468                 :            : {
+     469                 :            :     libspdm_return_t status;
+     470                 :            : 
+     471                 :            :     libspdm_test_context_t* spdm_test_context;
+     472                 :            :     libspdm_context_t* spdm_context;
+     473                 :            : 
+     474                 :            :     size_t request_size;
+     475                 :            :     size_t response_size;
+     476                 :            : 
+     477                 :            :     uint8_t request[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     478                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     479                 :            : 
+     480                 :            :     spdm_chunk_send_request_t* chunk_send_request;
+     481                 :            :     spdm_error_response_t* error_response;
+     482                 :            : 
+     483                 :            :     const uint8_t* chunk_src;
+     484                 :            :     uint8_t* chunk_dst;
+     485                 :            :     uint16_t chunk_num;
+     486                 :            :     uint32_t bytes_total;
+     487                 :            : 
+     488                 :          1 :     spdm_test_context = *state;
+     489                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     490                 :          1 :     spdm_test_context->case_id = 4;
+     491                 :            : 
+     492                 :          1 :     libspdm_test_responder_chunk_send_ack_setup_algo_state(spdm_context);
+     493                 :            : 
+     494                 :          1 :     chunk_num = 0;
+     495                 :          1 :     bytes_total = sizeof(m_libspdm_chunk_send_negotiate_algorithm_request1);
+     496                 :          1 :     chunk_src = (const uint8_t*) &m_libspdm_chunk_send_negotiate_algorithm_request1;
+     497                 :            : 
+     498                 :          1 :     libspdm_zero_mem(request, sizeof(request));
+     499                 :          1 :     chunk_send_request = (spdm_chunk_send_request_t*) request;
+     500                 :            : 
+     501                 :          1 :     chunk_send_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     502                 :          1 :     chunk_send_request->header.request_response_code = SPDM_CHUNK_SEND;
+     503                 :          1 :     chunk_send_request->header.param1 = 0;
+     504                 :          1 :     chunk_send_request->header.param2 = (uint8_t) spdm_test_context->case_id; /* chunk_handle */
+     505                 :          1 :     chunk_send_request->chunk_seq_no = chunk_num;
+     506                 :            : 
+     507                 :          1 :     *((uint32_t*) (chunk_send_request + 1)) = bytes_total;
+     508                 :          1 :     chunk_send_request->chunk_size =
+     509                 :          1 :         spdm_context->local_context.capability.data_transfer_size
+     510                 :          1 :         - sizeof(spdm_chunk_send_request_t) - sizeof(uint32_t);
+     511                 :            : 
+     512                 :          1 :     chunk_dst = ((uint8_t*) (chunk_send_request + 1)) + sizeof(uint32_t);
+     513                 :            : 
+     514                 :          1 :     request_size = sizeof(spdm_chunk_send_request_t)
+     515                 :            :                    + sizeof(uint32_t)
+     516                 :          1 :                    + chunk_send_request->chunk_size;
+     517                 :            : 
+     518                 :          1 :     libspdm_copy_mem(chunk_dst, chunk_send_request->chunk_size,
+     519                 :          1 :                      chunk_src, chunk_send_request->chunk_size);
+     520                 :            : 
+     521                 :          1 :     response_size = sizeof(response);
+     522                 :          1 :     request_size = sizeof(spdm_chunk_send_request_t) - 1;
+     523                 :          1 :     status = libspdm_get_response_chunk_send(
+     524                 :            :         spdm_context,
+     525                 :            :         request_size, request,
+     526                 :            :         &response_size, response);
+     527                 :            : 
+     528                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     529                 :          1 :     assert_true(response_size == sizeof(spdm_error_response_t));
+     530                 :            : 
+     531                 :          1 :     error_response = (spdm_error_response_t*) response;
+     532                 :          1 :     assert_int_equal(error_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+     533                 :          1 :     assert_int_equal(error_response->header.request_response_code, SPDM_ERROR);
+     534                 :          1 :     assert_int_equal(error_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+     535                 :          1 :     assert_int_equal(error_response->header.param2, 0);
+     536                 :          1 : }
+     537                 :            : /**
+     538                 :            :  * Test 5: Responder receives a CHUNK_SEND request SPDM version less than 1.2.
+     539                 :            :  * Expected Behavior: Returns ERROR response message
+     540                 :            :  * with SPDM_ERROR_CODE_UNSUPPORTED_REQUEST error code.
+     541                 :            :  **/
+     542                 :          1 : void libspdm_test_responder_chunk_send_ack_rsp_case5(void** state)
+     543                 :            : {
+     544                 :            :     libspdm_return_t status;
+     545                 :            : 
+     546                 :            :     libspdm_test_context_t* spdm_test_context;
+     547                 :            :     libspdm_context_t* spdm_context;
+     548                 :            : 
+     549                 :            :     size_t request_size;
+     550                 :            :     size_t response_size;
+     551                 :            : 
+     552                 :            :     uint8_t request[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     553                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     554                 :            : 
+     555                 :            :     spdm_chunk_send_request_t* chunk_send_request;
+     556                 :            :     spdm_error_response_t* error_response;
+     557                 :            : 
+     558                 :            :     const uint8_t* chunk_src;
+     559                 :            :     uint8_t* chunk_dst;
+     560                 :            :     uint16_t chunk_num;
+     561                 :            :     uint32_t bytes_total;
+     562                 :            : 
+     563                 :          1 :     spdm_test_context = *state;
+     564                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     565                 :          1 :     spdm_test_context->case_id = 5;
+     566                 :            : 
+     567                 :          1 :     libspdm_test_responder_chunk_send_ack_setup_algo_state(spdm_context);
+     568                 :            : 
+     569                 :          1 :     chunk_num = 0;
+     570                 :          1 :     bytes_total = sizeof(m_libspdm_chunk_send_negotiate_algorithm_request1);
+     571                 :          1 :     chunk_src = (const uint8_t*) &m_libspdm_chunk_send_negotiate_algorithm_request1;
+     572                 :            : 
+     573                 :          1 :     libspdm_zero_mem(request, sizeof(request));
+     574                 :          1 :     chunk_send_request = (spdm_chunk_send_request_t*) request;
+     575                 :            : 
+     576                 :          1 :     chunk_send_request->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     577                 :          1 :     chunk_send_request->header.request_response_code = SPDM_CHUNK_SEND;
+     578                 :          1 :     chunk_send_request->header.param1 = 0;
+     579                 :          1 :     chunk_send_request->header.param2 = (uint8_t) spdm_test_context->case_id; /* chunk_handle */
+     580                 :          1 :     chunk_send_request->chunk_seq_no = chunk_num;
+     581                 :            : 
+     582                 :          1 :     *((uint32_t*) (chunk_send_request + 1)) = bytes_total;
+     583                 :          1 :     chunk_send_request->chunk_size =
+     584                 :          1 :         spdm_context->local_context.capability.data_transfer_size
+     585                 :          1 :         - sizeof(spdm_chunk_send_request_t) - sizeof(uint32_t);
+     586                 :            : 
+     587                 :          1 :     chunk_dst = ((uint8_t*) (chunk_send_request + 1)) + sizeof(uint32_t);
+     588                 :            : 
+     589                 :          1 :     request_size = sizeof(spdm_chunk_send_request_t)
+     590                 :            :                    + sizeof(uint32_t)
+     591                 :          1 :                    + chunk_send_request->chunk_size;
+     592                 :            : 
+     593                 :          1 :     libspdm_copy_mem(chunk_dst, chunk_send_request->chunk_size,
+     594                 :          1 :                      chunk_src, chunk_send_request->chunk_size);
+     595                 :            : 
+     596                 :          1 :     response_size = sizeof(response);
+     597                 :          1 :     status = libspdm_get_response_chunk_send(
+     598                 :            :         spdm_context,
+     599                 :            :         request_size, request,
+     600                 :            :         &response_size, response);
+     601                 :            : 
+     602                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     603                 :          1 :     assert_true(response_size == sizeof(spdm_error_response_t));
+     604                 :            : 
+     605                 :          1 :     error_response = (spdm_error_response_t*) response;
+     606                 :          1 :     assert_int_equal(error_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+     607                 :          1 :     assert_int_equal(error_response->header.request_response_code, SPDM_ERROR);
+     608                 :          1 :     assert_int_equal(error_response->header.param1, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST);
+     609                 :          1 :     assert_int_equal(error_response->header.param2, SPDM_CHUNK_SEND);
+     610                 :          1 : }
+     611                 :            : /**
+     612                 :            :  * Test 6: Responder receives a CHUNK_SEND request with wrong SPDM version.
+     613                 :            :  * Expected Behavior: Returns ERROR response message
+     614                 :            :  * with SPDM_ERROR_CODE_VERSION_MISMATCH error code.
+     615                 :            :  **/
+     616                 :          1 : void libspdm_test_responder_chunk_send_ack_rsp_case6(void** state)
+     617                 :            : {
+     618                 :            :     libspdm_return_t status;
+     619                 :            : 
+     620                 :            :     libspdm_test_context_t* spdm_test_context;
+     621                 :            :     libspdm_context_t* spdm_context;
+     622                 :            : 
+     623                 :            :     size_t request_size;
+     624                 :            :     size_t response_size;
+     625                 :            : 
+     626                 :            :     uint8_t request[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     627                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     628                 :            : 
+     629                 :            :     spdm_chunk_send_request_t* chunk_send_request;
+     630                 :            :     spdm_error_response_t* error_response;
+     631                 :            : 
+     632                 :            :     const uint8_t* chunk_src;
+     633                 :            :     uint8_t* chunk_dst;
+     634                 :            :     uint16_t chunk_num;
+     635                 :            :     uint32_t bytes_total;
+     636                 :            : 
+     637                 :          1 :     spdm_test_context = *state;
+     638                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     639                 :          1 :     spdm_test_context->case_id = 6;
+     640                 :            : 
+     641                 :          1 :     libspdm_test_responder_chunk_send_ack_setup_algo_state(spdm_context);
+     642                 :            : 
+     643                 :          1 :     chunk_num = 0;
+     644                 :          1 :     bytes_total = sizeof(m_libspdm_chunk_send_negotiate_algorithm_request1);
+     645                 :          1 :     chunk_src = (const uint8_t*) &m_libspdm_chunk_send_negotiate_algorithm_request1;
+     646                 :            : 
+     647                 :          1 :     libspdm_zero_mem(request, sizeof(request));
+     648                 :          1 :     chunk_send_request = (spdm_chunk_send_request_t*) request;
+     649                 :            : 
+     650                 :          1 :     chunk_send_request->header.spdm_version = 0x13;
+     651                 :          1 :     chunk_send_request->header.request_response_code = SPDM_CHUNK_SEND;
+     652                 :          1 :     chunk_send_request->header.param1 = 0;
+     653                 :          1 :     chunk_send_request->header.param2 = (uint8_t) spdm_test_context->case_id; /* chunk_handle */
+     654                 :          1 :     chunk_send_request->chunk_seq_no = chunk_num;
+     655                 :            : 
+     656                 :          1 :     *((uint32_t*) (chunk_send_request + 1)) = bytes_total;
+     657                 :          1 :     chunk_send_request->chunk_size =
+     658                 :          1 :         spdm_context->local_context.capability.data_transfer_size
+     659                 :          1 :         - sizeof(spdm_chunk_send_request_t) - sizeof(uint32_t);
+     660                 :            : 
+     661                 :          1 :     chunk_dst = ((uint8_t*) (chunk_send_request + 1)) + sizeof(uint32_t);
+     662                 :            : 
+     663                 :          1 :     request_size = sizeof(spdm_chunk_send_request_t)
+     664                 :            :                    + sizeof(uint32_t)
+     665                 :          1 :                    + chunk_send_request->chunk_size;
+     666                 :            : 
+     667                 :          1 :     libspdm_copy_mem(chunk_dst, chunk_send_request->chunk_size,
+     668                 :          1 :                      chunk_src, chunk_send_request->chunk_size);
+     669                 :            : 
+     670                 :          1 :     response_size = sizeof(response);
+     671                 :          1 :     status = libspdm_get_response_chunk_send(
+     672                 :            :         spdm_context,
+     673                 :            :         request_size, request,
+     674                 :            :         &response_size, response);
+     675                 :            : 
+     676                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     677                 :          1 :     assert_true(response_size == sizeof(spdm_error_response_t));
+     678                 :            : 
+     679                 :          1 :     error_response = (spdm_error_response_t*) response;
+     680                 :          1 :     assert_int_equal(error_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+     681                 :          1 :     assert_int_equal(error_response->header.request_response_code, SPDM_ERROR);
+     682                 :          1 :     assert_int_equal(error_response->header.param1, SPDM_ERROR_CODE_VERSION_MISMATCH);
+     683                 :          1 :     assert_int_equal(error_response->header.param2, 0);
+     684                 :          1 : }
+     685                 :            : 
+     686                 :            : /**
+     687                 :            :  * Test 7: Responder gets chunk send when chunk get already in use.
+     688                 :            :  **/
+     689                 :          1 : void libspdm_test_responder_chunk_send_ack_rsp_case7(void** state)
+     690                 :            : {
+     691                 :            :     libspdm_return_t status;
+     692                 :            : 
+     693                 :            :     libspdm_test_context_t* spdm_test_context;
+     694                 :            :     libspdm_context_t* spdm_context;
+     695                 :            : 
+     696                 :            :     size_t request_size;
+     697                 :            :     size_t response_size;
+     698                 :            : 
+     699                 :            :     uint8_t request[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     700                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     701                 :            : 
+     702                 :            :     spdm_chunk_send_request_t* chunk_send_request;
+     703                 :            :     spdm_error_response_t* error_response;
+     704                 :            : 
+     705                 :            :     const uint8_t* chunk_src;
+     706                 :            :     uint8_t* chunk_dst;
+     707                 :            :     uint16_t chunk_num;
+     708                 :            :     uint32_t bytes_total;
+     709                 :            : 
+     710                 :          1 :     spdm_test_context = *state;
+     711                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     712                 :          1 :     spdm_test_context->case_id = 7;
+     713                 :            : 
+     714                 :          1 :     libspdm_test_responder_chunk_send_ack_setup_algo_state(spdm_context);
+     715                 :          1 :     spdm_context->chunk_context.get.chunk_in_use = true;
+     716                 :            : 
+     717                 :          1 :     chunk_num = 0;
+     718                 :          1 :     bytes_total = sizeof(m_libspdm_chunk_send_negotiate_algorithm_request1);
+     719                 :          1 :     chunk_src = (const uint8_t*) &m_libspdm_chunk_send_negotiate_algorithm_request1;
+     720                 :            : 
+     721                 :          1 :     libspdm_zero_mem(request, sizeof(request));
+     722                 :          1 :     chunk_send_request = (spdm_chunk_send_request_t*) request;
+     723                 :            : 
+     724                 :          1 :     chunk_send_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     725                 :          1 :     chunk_send_request->header.request_response_code = SPDM_CHUNK_SEND;
+     726                 :          1 :     chunk_send_request->header.param1 = 0;
+     727                 :          1 :     chunk_send_request->header.param2 = (uint8_t) spdm_test_context->case_id; /* chunk_handle */
+     728                 :          1 :     chunk_send_request->chunk_seq_no = chunk_num;
+     729                 :            : 
+     730                 :          1 :     *((uint32_t*) (chunk_send_request + 1)) = bytes_total;
+     731                 :          1 :     chunk_send_request->chunk_size =
+     732                 :          1 :         spdm_context->local_context.capability.data_transfer_size
+     733                 :          1 :         - sizeof(spdm_chunk_send_request_t) - sizeof(uint32_t);
+     734                 :            : 
+     735                 :          1 :     chunk_dst = ((uint8_t*) (chunk_send_request + 1)) + sizeof(uint32_t);
+     736                 :            : 
+     737                 :          1 :     request_size = sizeof(spdm_chunk_send_request_t)
+     738                 :            :                    + sizeof(uint32_t)
+     739                 :          1 :                    + chunk_send_request->chunk_size;
+     740                 :            : 
+     741                 :          1 :     libspdm_copy_mem(chunk_dst, chunk_send_request->chunk_size,
+     742                 :          1 :                      chunk_src, chunk_send_request->chunk_size);
+     743                 :            : 
+     744                 :          1 :     response_size = sizeof(response);
+     745                 :          1 :     status = libspdm_get_response_chunk_send(
+     746                 :            :         spdm_context,
+     747                 :            :         request_size, request,
+     748                 :            :         &response_size, response);
+     749                 :            : 
+     750                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     751                 :          1 :     assert_true(response_size == sizeof(spdm_error_response_t));
+     752                 :            : 
+     753                 :          1 :     error_response = (spdm_error_response_t*) response;
+     754                 :          1 :     assert_int_equal(error_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+     755                 :          1 :     assert_int_equal(error_response->header.request_response_code, SPDM_ERROR);
+     756                 :          1 :     assert_int_equal(error_response->header.param1, SPDM_ERROR_CODE_UNEXPECTED_REQUEST);
+     757                 :          1 :     assert_int_equal(error_response->header.param2, 0);
+     758                 :            : 
+     759                 :          1 :     spdm_context->chunk_context.get.chunk_in_use = false;
+     760                 :          1 : }
+     761                 :            : 
+     762                 :            : /**
+     763                 :            :  * Test 8: First request has bad sequence number.
+     764                 :            :  **/
+     765                 :          1 : void libspdm_test_responder_chunk_send_ack_rsp_case8(void** state)
+     766                 :            : {
+     767                 :            :     libspdm_return_t status;
+     768                 :            : 
+     769                 :            :     libspdm_test_context_t* spdm_test_context;
+     770                 :            :     libspdm_context_t* spdm_context;
+     771                 :            : 
+     772                 :            :     size_t request_size;
+     773                 :            :     size_t response_size;
+     774                 :            : 
+     775                 :            :     uint8_t request[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     776                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     777                 :            : 
+     778                 :            :     spdm_chunk_send_request_t *chunk_send_request;
+     779                 :            :     spdm_chunk_send_ack_response_t *chunk_send_ack_response;
+     780                 :            :     spdm_error_response_t *error_response;
+     781                 :            : 
+     782                 :            :     const uint8_t *chunk_src;
+     783                 :            :     uint8_t *chunk_dst;
+     784                 :            :     uint32_t bytes_total;
+     785                 :            : 
+     786                 :          1 :     spdm_test_context = *state;
+     787                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     788                 :          1 :     spdm_test_context->case_id = 8;
+     789                 :            : 
+     790                 :          1 :     libspdm_test_responder_chunk_send_ack_setup_algo_state(spdm_context);
+     791                 :            : 
+     792                 :          1 :     bytes_total = sizeof(m_libspdm_chunk_send_negotiate_algorithm_request1);
+     793                 :          1 :     chunk_src = (const uint8_t*) &m_libspdm_chunk_send_negotiate_algorithm_request1;
+     794                 :            : 
+     795                 :          1 :     libspdm_zero_mem(request, sizeof(request));
+     796                 :          1 :     chunk_send_request = (spdm_chunk_send_request_t*) request;
+     797                 :            : 
+     798                 :          1 :     chunk_send_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     799                 :          1 :     chunk_send_request->header.request_response_code = SPDM_CHUNK_SEND;
+     800                 :          1 :     chunk_send_request->header.param1 = 0;
+     801                 :          1 :     chunk_send_request->header.param2 = (uint8_t) spdm_test_context->case_id; /* chunk_handle */
+     802                 :          1 :     chunk_send_request->chunk_seq_no = 1; /* Bad seq num */
+     803                 :            : 
+     804                 :          1 :     *((uint32_t*) (chunk_send_request + 1)) = bytes_total;
+     805                 :          1 :     chunk_send_request->chunk_size =
+     806                 :          1 :         spdm_context->local_context.capability.data_transfer_size
+     807                 :          1 :         - sizeof(spdm_chunk_send_request_t) - sizeof(uint32_t);
+     808                 :            : 
+     809                 :          1 :     chunk_dst = ((uint8_t*) (chunk_send_request + 1)) + sizeof(uint32_t);
+     810                 :            : 
+     811                 :          1 :     request_size = sizeof(spdm_chunk_send_request_t)
+     812                 :            :                    + sizeof(uint32_t)
+     813                 :          1 :                    + chunk_send_request->chunk_size;
+     814                 :            : 
+     815                 :          1 :     libspdm_copy_mem(chunk_dst, chunk_send_request->chunk_size,
+     816                 :          1 :                      chunk_src, chunk_send_request->chunk_size);
+     817                 :            : 
+     818                 :          1 :     response_size = sizeof(response);
+     819                 :          1 :     status = libspdm_get_response_chunk_send(
+     820                 :            :         spdm_context,
+     821                 :            :         request_size, request,
+     822                 :            :         &response_size, response);
+     823                 :            : 
+     824                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+     825                 :          1 :     assert_true(response_size == sizeof(spdm_chunk_send_ack_response_t)
+     826                 :            :                 + sizeof(spdm_error_response_t));
+     827                 :            : 
+     828                 :          1 :     chunk_send_ack_response = (spdm_chunk_send_ack_response_t*) response;
+     829                 :          1 :     assert_int_equal(chunk_send_ack_response->header.param1,
+     830                 :            :                      SPDM_CHUNK_SEND_ACK_RESPONSE_ATTRIBUTE_EARLY_ERROR_DETECTED);
+     831                 :            : 
+     832                 :          1 :     error_response = (spdm_error_response_t*) (chunk_send_ack_response + 1);
+     833                 :          1 :     assert_int_equal(error_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+     834                 :          1 :     assert_int_equal(error_response->header.request_response_code, SPDM_ERROR);
+     835                 :          1 :     assert_int_equal(error_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+     836                 :          1 :     assert_int_equal(error_response->header.param2, 0);
+     837                 :          1 : }
+     838                 :            : 
+     839                 :            : /**
+     840                 :            :  * Test 9: First request has chunk size too large.
+     841                 :            :  **/
+     842                 :          1 : void libspdm_test_responder_chunk_send_ack_rsp_case9(void** state)
+     843                 :            : {
+     844                 :            :     libspdm_return_t status;
+     845                 :            : 
+     846                 :            :     libspdm_test_context_t* spdm_test_context;
+     847                 :            :     libspdm_context_t* spdm_context;
+     848                 :            : 
+     849                 :            :     size_t request_size;
+     850                 :            :     size_t response_size;
+     851                 :            : 
+     852                 :            :     uint8_t request[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     853                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     854                 :            : 
+     855                 :            :     spdm_chunk_send_request_t* chunk_send_request;
+     856                 :            :     spdm_chunk_send_ack_response_t* chunk_send_ack_response;
+     857                 :            :     spdm_error_response_t* error_response;
+     858                 :            : 
+     859                 :            :     const uint8_t* chunk_src;
+     860                 :            :     uint8_t* chunk_dst;
+     861                 :            :     uint32_t bytes_total;
+     862                 :            : 
+     863                 :          1 :     spdm_test_context = *state;
+     864                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     865                 :          1 :     spdm_test_context->case_id = 9;
+     866                 :            : 
+     867                 :          1 :     libspdm_test_responder_chunk_send_ack_setup_algo_state(spdm_context);
+     868                 :            : 
+     869                 :          1 :     bytes_total = sizeof(m_libspdm_chunk_send_negotiate_algorithm_request1);
+     870                 :          1 :     chunk_src = (const uint8_t*) &m_libspdm_chunk_send_negotiate_algorithm_request1;
+     871                 :            : 
+     872                 :          1 :     libspdm_zero_mem(request, sizeof(request));
+     873                 :          1 :     chunk_send_request = (spdm_chunk_send_request_t*) request;
+     874                 :            : 
+     875                 :          1 :     chunk_send_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     876                 :          1 :     chunk_send_request->header.request_response_code = SPDM_CHUNK_SEND;
+     877                 :          1 :     chunk_send_request->header.param1 = 0;
+     878                 :          1 :     chunk_send_request->header.param2 = (uint8_t) spdm_test_context->case_id; /* chunk_handle */
+     879                 :          1 :     chunk_send_request->chunk_seq_no = 0;
+     880                 :            : 
+     881                 :          1 :     *((uint32_t*) (chunk_send_request + 1)) = bytes_total;
+     882                 :          1 :     chunk_send_request->chunk_size =
+     883                 :          1 :         spdm_context->local_context.capability.data_transfer_size
+     884                 :          1 :         - sizeof(spdm_chunk_send_request_t) - sizeof(uint32_t);
+     885                 :            : 
+     886                 :          1 :     chunk_dst = ((uint8_t*) (chunk_send_request + 1)) + sizeof(uint32_t);
+     887                 :            : 
+     888                 :          1 :     request_size = sizeof(spdm_chunk_send_request_t)
+     889                 :            :                    + sizeof(uint32_t)
+     890                 :          1 :                    + chunk_send_request->chunk_size;
+     891                 :            : 
+     892                 :          1 :     libspdm_copy_mem(chunk_dst, chunk_send_request->chunk_size,
+     893                 :          1 :                      chunk_src, chunk_send_request->chunk_size);
+     894                 :            : 
+     895                 :          1 :     chunk_send_request->chunk_size += 1; /* chunk size too large */
+     896                 :            : 
+     897                 :          1 :     response_size = sizeof(response);
+     898                 :          1 :     status = libspdm_get_response_chunk_send(
+     899                 :            :         spdm_context,
+     900                 :            :         request_size, request,
+     901                 :            :         &response_size, response);
+     902                 :            : 
+     903                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+     904                 :          1 :     assert_true(response_size == sizeof(spdm_chunk_send_ack_response_t)
+     905                 :            :                 + sizeof(spdm_error_response_t));
+     906                 :            : 
+     907                 :          1 :     chunk_send_ack_response = (spdm_chunk_send_ack_response_t*) response;
+     908                 :          1 :     assert_int_equal(chunk_send_ack_response->header.param1,
+     909                 :            :                      SPDM_CHUNK_SEND_ACK_RESPONSE_ATTRIBUTE_EARLY_ERROR_DETECTED);
+     910                 :            : 
+     911                 :          1 :     error_response = (spdm_error_response_t*) (chunk_send_ack_response + 1);
+     912                 :          1 :     assert_int_equal(error_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+     913                 :          1 :     assert_int_equal(error_response->header.request_response_code, SPDM_ERROR);
+     914                 :          1 :     assert_int_equal(error_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+     915                 :          1 :     assert_int_equal(error_response->header.param2, 0);
+     916                 :          1 : }
+     917                 :            : 
+     918                 :            : /**
+     919                 :            :  * Test 10: First request has size larger than data transfer size.
+     920                 :            :  **/
+     921                 :          1 : void libspdm_test_responder_chunk_send_ack_rsp_case10(void** state)
+     922                 :            : {
+     923                 :            :     libspdm_return_t status;
+     924                 :            : 
+     925                 :            :     libspdm_test_context_t* spdm_test_context;
+     926                 :            :     libspdm_context_t* spdm_context;
+     927                 :            : 
+     928                 :            :     size_t request_size;
+     929                 :            :     size_t response_size;
+     930                 :            : 
+     931                 :            :     uint8_t request[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     932                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     933                 :            : 
+     934                 :            :     spdm_chunk_send_request_t* chunk_send_request;
+     935                 :            :     spdm_chunk_send_ack_response_t* chunk_send_ack_response;
+     936                 :            :     spdm_error_response_t* error_response;
+     937                 :            : 
+     938                 :            :     const uint8_t* chunk_src;
+     939                 :            :     uint8_t* chunk_dst;
+     940                 :            :     uint32_t bytes_total;
+     941                 :            : 
+     942                 :          1 :     spdm_test_context = *state;
+     943                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     944                 :          1 :     spdm_test_context->case_id = 10;
+     945                 :            : 
+     946                 :          1 :     libspdm_test_responder_chunk_send_ack_setup_algo_state(spdm_context);
+     947                 :            : 
+     948                 :          1 :     bytes_total = sizeof(m_libspdm_chunk_send_negotiate_algorithm_request1);
+     949                 :          1 :     chunk_src = (const uint8_t*) &m_libspdm_chunk_send_negotiate_algorithm_request1;
+     950                 :            : 
+     951                 :          1 :     libspdm_zero_mem(request, sizeof(request));
+     952                 :          1 :     chunk_send_request = (spdm_chunk_send_request_t*) request;
+     953                 :            : 
+     954                 :          1 :     chunk_send_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     955                 :          1 :     chunk_send_request->header.request_response_code = SPDM_CHUNK_SEND;
+     956                 :          1 :     chunk_send_request->header.param1 = 0;
+     957                 :          1 :     chunk_send_request->header.param2 = (uint8_t) spdm_test_context->case_id; /* chunk_handle */
+     958                 :          1 :     chunk_send_request->chunk_seq_no = 0;
+     959                 :            : 
+     960                 :          1 :     *((uint32_t*) (chunk_send_request + 1)) = bytes_total;
+     961                 :          1 :     chunk_send_request->chunk_size =
+     962                 :          1 :         spdm_context->local_context.capability.data_transfer_size
+     963                 :          1 :         - sizeof(spdm_chunk_send_request_t) - sizeof(uint32_t);
+     964                 :            : 
+     965                 :          1 :     chunk_dst = ((uint8_t*) (chunk_send_request + 1)) + sizeof(uint32_t);
+     966                 :            : 
+     967                 :          1 :     request_size = sizeof(spdm_chunk_send_request_t)
+     968                 :            :                    + sizeof(uint32_t)
+     969                 :          1 :                    + chunk_send_request->chunk_size
+     970                 :            :                    + 1; /* Request size too large */
+     971                 :            : 
+     972                 :          1 :     libspdm_copy_mem(chunk_dst, chunk_send_request->chunk_size,
+     973                 :          1 :                      chunk_src, chunk_send_request->chunk_size);
+     974                 :            : 
+     975                 :          1 :     response_size = sizeof(response);
+     976                 :          1 :     status = libspdm_get_response_chunk_send(
+     977                 :            :         spdm_context,
+     978                 :            :         request_size, request,
+     979                 :            :         &response_size, response);
+     980                 :            : 
+     981                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+     982                 :          1 :     assert_true(response_size == sizeof(spdm_chunk_send_ack_response_t)
+     983                 :            :                 + sizeof(spdm_error_response_t));
+     984                 :            : 
+     985                 :          1 :     chunk_send_ack_response = (spdm_chunk_send_ack_response_t*) response;
+     986                 :          1 :     assert_int_equal(chunk_send_ack_response->header.param1,
+     987                 :            :                      SPDM_CHUNK_SEND_ACK_RESPONSE_ATTRIBUTE_EARLY_ERROR_DETECTED);
+     988                 :            : 
+     989                 :          1 :     error_response = (spdm_error_response_t*) (chunk_send_ack_response + 1);
+     990                 :          1 :     assert_int_equal(error_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+     991                 :          1 :     assert_int_equal(error_response->header.request_response_code, SPDM_ERROR);
+     992                 :          1 :     assert_int_equal(error_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+     993                 :          1 :     assert_int_equal(error_response->header.param2, 0);
+     994                 :          1 : }
+     995                 :            : 
+     996                 :            : /**
+     997                 :            :  * Test 11: First request has LAST CHUNK bit set.
+     998                 :            :  **/
+     999                 :          1 : void libspdm_test_responder_chunk_send_ack_rsp_case11(void** state)
+    1000                 :            : {
+    1001                 :            :     libspdm_return_t status;
+    1002                 :            : 
+    1003                 :            :     libspdm_test_context_t* spdm_test_context;
+    1004                 :            :     libspdm_context_t* spdm_context;
+    1005                 :            : 
+    1006                 :            :     size_t request_size;
+    1007                 :            :     size_t response_size;
+    1008                 :            : 
+    1009                 :            :     uint8_t request[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1010                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1011                 :            : 
+    1012                 :            :     spdm_chunk_send_request_t* chunk_send_request;
+    1013                 :            :     spdm_chunk_send_ack_response_t* chunk_send_ack_response;
+    1014                 :            :     spdm_error_response_t* error_response;
+    1015                 :            : 
+    1016                 :            :     const uint8_t* chunk_src;
+    1017                 :            :     uint8_t* chunk_dst;
+    1018                 :            : 
+    1019                 :          1 :     spdm_test_context = *state;
+    1020                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1021                 :          1 :     spdm_test_context->case_id = 11;
+    1022                 :            : 
+    1023                 :          1 :     libspdm_test_responder_chunk_send_ack_setup_algo_state(spdm_context);
+    1024                 :            : 
+    1025                 :          1 :     chunk_src = (const uint8_t*) &m_libspdm_chunk_send_negotiate_algorithm_request1;
+    1026                 :            : 
+    1027                 :          1 :     libspdm_zero_mem(request, sizeof(request));
+    1028                 :          1 :     chunk_send_request = (spdm_chunk_send_request_t*) request;
+    1029                 :            : 
+    1030                 :          1 :     chunk_send_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+    1031                 :          1 :     chunk_send_request->header.request_response_code = SPDM_CHUNK_SEND;
+    1032                 :          1 :     chunk_send_request->header.param1 = 0;
+    1033                 :          1 :     chunk_send_request->header.param2 = (uint8_t) spdm_test_context->case_id; /* chunk_handle */
+    1034                 :          1 :     chunk_send_request->chunk_seq_no = 0;
+    1035                 :            : 
+    1036                 :          1 :     *((uint32_t*) (chunk_send_request + 1)) = LIBSPDM_MAX_SPDM_MSG_SIZE + 1;
+    1037                 :            : 
+    1038                 :          1 :     chunk_send_request->chunk_size =
+    1039                 :          1 :         spdm_context->local_context.capability.data_transfer_size
+    1040                 :          1 :         - sizeof(spdm_chunk_send_request_t) - sizeof(uint32_t);
+    1041                 :            : 
+    1042                 :          1 :     chunk_dst = ((uint8_t*) (chunk_send_request + 1)) + sizeof(uint32_t);
+    1043                 :            : 
+    1044                 :          1 :     request_size = sizeof(spdm_chunk_send_request_t)
+    1045                 :            :                    + sizeof(uint32_t)
+    1046                 :          1 :                    + chunk_send_request->chunk_size;
+    1047                 :            : 
+    1048                 :          1 :     libspdm_copy_mem(chunk_dst, chunk_send_request->chunk_size,
+    1049                 :          1 :                      chunk_src, chunk_send_request->chunk_size);
+    1050                 :            : 
+    1051                 :          1 :     response_size = sizeof(response);
+    1052                 :          1 :     status = libspdm_get_response_chunk_send(
+    1053                 :            :         spdm_context,
+    1054                 :            :         request_size, request,
+    1055                 :            :         &response_size, response);
+    1056                 :            : 
+    1057                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1058                 :          1 :     assert_true(response_size == sizeof(spdm_chunk_send_ack_response_t)
+    1059                 :            :                 + sizeof(spdm_error_response_t));
+    1060                 :            : 
+    1061                 :          1 :     chunk_send_ack_response = (spdm_chunk_send_ack_response_t*) response;
+    1062                 :          1 :     assert_int_equal(chunk_send_ack_response->header.param1,
+    1063                 :            :                      SPDM_CHUNK_SEND_ACK_RESPONSE_ATTRIBUTE_EARLY_ERROR_DETECTED);
+    1064                 :            : 
+    1065                 :          1 :     error_response = (spdm_error_response_t*) (chunk_send_ack_response + 1);
+    1066                 :          1 :     assert_int_equal(error_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+    1067                 :          1 :     assert_int_equal(error_response->header.request_response_code, SPDM_ERROR);
+    1068                 :          1 :     assert_int_equal(error_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+    1069                 :          1 :     assert_int_equal(error_response->header.param2, 0);
+    1070                 :          1 : }
+    1071                 :            : 
+    1072                 :            : /**
+    1073                 :            :  * Test 12: First request has LAST CHUNK bit set.
+    1074                 :            :  **/
+    1075                 :          1 : void libspdm_test_responder_chunk_send_ack_rsp_case12(void** state)
+    1076                 :            : {
+    1077                 :            :     libspdm_return_t status;
+    1078                 :            : 
+    1079                 :            :     libspdm_test_context_t* spdm_test_context;
+    1080                 :            :     libspdm_context_t* spdm_context;
+    1081                 :            : 
+    1082                 :            :     size_t request_size;
+    1083                 :            :     size_t response_size;
+    1084                 :            : 
+    1085                 :            :     uint8_t request[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1086                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1087                 :            : 
+    1088                 :            :     spdm_chunk_send_request_t* chunk_send_request;
+    1089                 :            :     spdm_chunk_send_ack_response_t* chunk_send_ack_response;
+    1090                 :            :     spdm_error_response_t* error_response;
+    1091                 :            : 
+    1092                 :            :     const uint8_t* chunk_src;
+    1093                 :            :     uint8_t* chunk_dst;
+    1094                 :            :     uint32_t bytes_total;
+    1095                 :            : 
+    1096                 :          1 :     spdm_test_context = *state;
+    1097                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1098                 :          1 :     spdm_test_context->case_id = 12;
+    1099                 :            : 
+    1100                 :          1 :     libspdm_test_responder_chunk_send_ack_setup_algo_state(spdm_context);
+    1101                 :            : 
+    1102                 :          1 :     bytes_total = sizeof(m_libspdm_chunk_send_negotiate_algorithm_request1);
+    1103                 :          1 :     chunk_src = (const uint8_t*) &m_libspdm_chunk_send_negotiate_algorithm_request1;
+    1104                 :            : 
+    1105                 :          1 :     libspdm_zero_mem(request, sizeof(request));
+    1106                 :          1 :     chunk_send_request = (spdm_chunk_send_request_t*) request;
+    1107                 :            : 
+    1108                 :          1 :     chunk_send_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+    1109                 :          1 :     chunk_send_request->header.request_response_code = SPDM_CHUNK_SEND;
+    1110                 :          1 :     chunk_send_request->header.param1 = SPDM_CHUNK_SEND_REQUEST_ATTRIBUTE_LAST_CHUNK;
+    1111                 :          1 :     chunk_send_request->header.param2 = (uint8_t) spdm_test_context->case_id; /* chunk_handle */
+    1112                 :          1 :     chunk_send_request->chunk_seq_no = 0;
+    1113                 :            : 
+    1114                 :          1 :     *((uint32_t*) (chunk_send_request + 1)) = bytes_total;
+    1115                 :            : 
+    1116                 :          1 :     chunk_send_request->chunk_size =
+    1117                 :          1 :         spdm_context->local_context.capability.data_transfer_size
+    1118                 :          1 :         - sizeof(spdm_chunk_send_request_t) - sizeof(uint32_t);
+    1119                 :            : 
+    1120                 :          1 :     chunk_dst = ((uint8_t*) (chunk_send_request + 1)) + sizeof(uint32_t);
+    1121                 :            : 
+    1122                 :          1 :     request_size = sizeof(spdm_chunk_send_request_t)
+    1123                 :            :                    + sizeof(uint32_t)
+    1124                 :          1 :                    + chunk_send_request->chunk_size;
+    1125                 :            : 
+    1126                 :          1 :     libspdm_copy_mem(chunk_dst, chunk_send_request->chunk_size,
+    1127                 :          1 :                      chunk_src, chunk_send_request->chunk_size);
+    1128                 :            : 
+    1129                 :          1 :     response_size = sizeof(response);
+    1130                 :          1 :     status = libspdm_get_response_chunk_send(
+    1131                 :            :         spdm_context,
+    1132                 :            :         request_size, request,
+    1133                 :            :         &response_size, response);
+    1134                 :            : 
+    1135                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1136                 :          1 :     assert_true(response_size == sizeof(spdm_chunk_send_ack_response_t)
+    1137                 :            :                 + sizeof(spdm_error_response_t));
+    1138                 :            : 
+    1139                 :          1 :     chunk_send_ack_response = (spdm_chunk_send_ack_response_t*) response;
+    1140                 :          1 :     assert_int_equal(chunk_send_ack_response->header.param1,
+    1141                 :            :                      SPDM_CHUNK_SEND_ACK_RESPONSE_ATTRIBUTE_EARLY_ERROR_DETECTED);
+    1142                 :            : 
+    1143                 :          1 :     error_response = (spdm_error_response_t*) (chunk_send_ack_response + 1);
+    1144                 :          1 :     assert_int_equal(error_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+    1145                 :          1 :     assert_int_equal(error_response->header.request_response_code, SPDM_ERROR);
+    1146                 :          1 :     assert_int_equal(error_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+    1147                 :          1 :     assert_int_equal(error_response->header.param2, 0);
+    1148                 :          1 : }
+    1149                 :            : 
+    1150                 :          7 : void libspdm_test_responder_chunk_send_ack_reset_send_state(libspdm_context_t* spdm_context)
+    1151                 :            : {
+    1152                 :            :     libspdm_chunk_info_t* send_info;
+    1153                 :            : 
+    1154                 :          7 :     send_info = &spdm_context->chunk_context.send;
+    1155                 :          7 :     send_info->chunk_in_use = false;
+    1156                 :          7 :     send_info->chunk_handle = 0;
+    1157                 :          7 :     send_info->chunk_seq_no = 0;
+    1158                 :          7 :     send_info->chunk_bytes_transferred = 0;
+    1159                 :          7 :     send_info->large_message = NULL;
+    1160                 :          7 :     send_info->large_message_size = 0;
+    1161                 :          7 : }
+    1162                 :            : 
+    1163                 :            : /**
+    1164                 :            :  * Test 13: Request has bad sequence number.
+    1165                 :            :  **/
+    1166                 :          1 : void libspdm_test_responder_chunk_send_ack_rsp_case13(void** state)
+    1167                 :            : {
+    1168                 :            :     libspdm_return_t status;
+    1169                 :            : 
+    1170                 :            :     libspdm_test_context_t* spdm_test_context;
+    1171                 :            :     libspdm_context_t* spdm_context;
+    1172                 :            : 
+    1173                 :            :     size_t request_size;
+    1174                 :            :     size_t response_size;
+    1175                 :            : 
+    1176                 :            :     uint8_t request[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1177                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1178                 :            : 
+    1179                 :            :     spdm_chunk_send_request_t* chunk_send_request;
+    1180                 :            :     spdm_chunk_send_ack_response_t* chunk_send_ack_response;
+    1181                 :            :     spdm_error_response_t* error_response;
+    1182                 :            : 
+    1183                 :            :     const uint8_t* chunk_src;
+    1184                 :            :     uint8_t* chunk_dst;
+    1185                 :            : 
+    1186                 :          1 :     spdm_test_context = *state;
+    1187                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1188                 :          1 :     spdm_test_context->case_id = 13;
+    1189                 :            : 
+    1190                 :          1 :     libspdm_test_responder_chunk_send_ack_setup_algo_state(spdm_context);
+    1191                 :          1 :     spdm_context->chunk_context.send.chunk_in_use = true;
+    1192                 :          1 :     spdm_context->chunk_context.send.chunk_handle = (uint8_t) spdm_test_context->case_id;
+    1193                 :          1 :     spdm_context->chunk_context.send.chunk_seq_no = 0;
+    1194                 :            : 
+    1195                 :          1 :     chunk_src = (const uint8_t*) &m_libspdm_chunk_send_negotiate_algorithm_request1;
+    1196                 :            : 
+    1197                 :          1 :     libspdm_zero_mem(request, sizeof(request));
+    1198                 :          1 :     chunk_send_request = (spdm_chunk_send_request_t*) request;
+    1199                 :            : 
+    1200                 :          1 :     chunk_send_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+    1201                 :          1 :     chunk_send_request->header.request_response_code = SPDM_CHUNK_SEND;
+    1202                 :          1 :     chunk_send_request->header.param1 = 0;
+    1203                 :          1 :     chunk_send_request->header.param2 = (uint8_t) spdm_test_context->case_id; /* chunk_handle */
+    1204                 :          1 :     chunk_send_request->chunk_seq_no = 2; /* Bad seq num */
+    1205                 :            : 
+    1206                 :          1 :     chunk_send_request->chunk_size =
+    1207                 :          1 :         spdm_context->local_context.capability.data_transfer_size
+    1208                 :          1 :         - sizeof(spdm_chunk_send_request_t);
+    1209                 :            : 
+    1210                 :          1 :     chunk_dst = ((uint8_t*) (chunk_send_request + 1));
+    1211                 :            : 
+    1212                 :          1 :     request_size = sizeof(spdm_chunk_send_request_t)
+    1213                 :          1 :                    + chunk_send_request->chunk_size;
+    1214                 :            : 
+    1215                 :          1 :     libspdm_copy_mem(chunk_dst, chunk_send_request->chunk_size,
+    1216                 :          1 :                      chunk_src, chunk_send_request->chunk_size);
+    1217                 :            : 
+    1218                 :          1 :     response_size = sizeof(response);
+    1219                 :          1 :     status = libspdm_get_response_chunk_send(
+    1220                 :            :         spdm_context,
+    1221                 :            :         request_size, request,
+    1222                 :            :         &response_size, response);
+    1223                 :            : 
+    1224                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1225                 :          1 :     assert_true(response_size == sizeof(spdm_chunk_send_ack_response_t)
+    1226                 :            :                 + sizeof(spdm_error_response_t));
+    1227                 :            : 
+    1228                 :          1 :     chunk_send_ack_response = (spdm_chunk_send_ack_response_t*) response;
+    1229                 :          1 :     assert_int_equal(chunk_send_ack_response->header.param1,
+    1230                 :            :                      SPDM_CHUNK_SEND_ACK_RESPONSE_ATTRIBUTE_EARLY_ERROR_DETECTED);
+    1231                 :            : 
+    1232                 :          1 :     error_response = (spdm_error_response_t*) (chunk_send_ack_response + 1);
+    1233                 :          1 :     assert_int_equal(error_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+    1234                 :          1 :     assert_int_equal(error_response->header.request_response_code, SPDM_ERROR);
+    1235                 :          1 :     assert_int_equal(error_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+    1236                 :          1 :     assert_int_equal(error_response->header.param2, 0);
+    1237                 :            : 
+    1238                 :          1 :     libspdm_test_responder_chunk_send_ack_reset_send_state(spdm_context);
+    1239                 :          1 : }
+    1240                 :            : 
+    1241                 :            : /**
+    1242                 :            :  * Test 14: Request has bad chunk handle.
+    1243                 :            :  **/
+    1244                 :          1 : void libspdm_test_responder_chunk_send_ack_rsp_case14(void** state)
+    1245                 :            : {
+    1246                 :            :     libspdm_return_t status;
+    1247                 :            : 
+    1248                 :            :     libspdm_test_context_t* spdm_test_context;
+    1249                 :            :     libspdm_context_t* spdm_context;
+    1250                 :            : 
+    1251                 :            :     size_t request_size;
+    1252                 :            :     size_t response_size;
+    1253                 :            : 
+    1254                 :            :     uint8_t request[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1255                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1256                 :            : 
+    1257                 :            :     spdm_chunk_send_request_t* chunk_send_request;
+    1258                 :            :     spdm_chunk_send_ack_response_t* chunk_send_ack_response;
+    1259                 :            :     spdm_error_response_t* error_response;
+    1260                 :            : 
+    1261                 :            :     const uint8_t* chunk_src;
+    1262                 :            :     uint8_t* chunk_dst;
+    1263                 :            : 
+    1264                 :          1 :     spdm_test_context = *state;
+    1265                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1266                 :          1 :     spdm_test_context->case_id = 14;
+    1267                 :            : 
+    1268                 :          1 :     libspdm_test_responder_chunk_send_ack_setup_algo_state(spdm_context);
+    1269                 :          1 :     spdm_context->chunk_context.send.chunk_in_use = true;
+    1270                 :          1 :     spdm_context->chunk_context.send.chunk_handle = (uint8_t) spdm_test_context->case_id;
+    1271                 :          1 :     spdm_context->chunk_context.send.chunk_seq_no = 0;
+    1272                 :            : 
+    1273                 :          1 :     chunk_src = (const uint8_t*) &m_libspdm_chunk_send_negotiate_algorithm_request1;
+    1274                 :            : 
+    1275                 :          1 :     libspdm_zero_mem(request, sizeof(request));
+    1276                 :          1 :     chunk_send_request = (spdm_chunk_send_request_t*) request;
+    1277                 :            : 
+    1278                 :          1 :     chunk_send_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+    1279                 :          1 :     chunk_send_request->header.request_response_code = SPDM_CHUNK_SEND;
+    1280                 :          1 :     chunk_send_request->header.param1 = 0;
+    1281                 :          1 :     chunk_send_request->header.param2 = (uint8_t) spdm_test_context->case_id + 1; /* bad chunk_handle */
+    1282                 :          1 :     chunk_send_request->chunk_seq_no = 1;
+    1283                 :          1 :     chunk_send_request->chunk_size =
+    1284                 :          1 :         spdm_context->local_context.capability.data_transfer_size
+    1285                 :          1 :         - sizeof(spdm_chunk_send_request_t);
+    1286                 :            : 
+    1287                 :          1 :     chunk_dst = ((uint8_t*) (chunk_send_request + 1));
+    1288                 :            : 
+    1289                 :          1 :     request_size = sizeof(spdm_chunk_send_request_t)
+    1290                 :          1 :                    + chunk_send_request->chunk_size;
+    1291                 :            : 
+    1292                 :          1 :     libspdm_copy_mem(chunk_dst, chunk_send_request->chunk_size,
+    1293                 :          1 :                      chunk_src, chunk_send_request->chunk_size);
+    1294                 :            : 
+    1295                 :          1 :     response_size = sizeof(response);
+    1296                 :          1 :     status = libspdm_get_response_chunk_send(
+    1297                 :            :         spdm_context,
+    1298                 :            :         request_size, request,
+    1299                 :            :         &response_size, response);
+    1300                 :            : 
+    1301                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1302                 :          1 :     assert_true(response_size == sizeof(spdm_chunk_send_ack_response_t)
+    1303                 :            :                 + sizeof(spdm_error_response_t));
+    1304                 :            : 
+    1305                 :          1 :     chunk_send_ack_response = (spdm_chunk_send_ack_response_t*) response;
+    1306                 :          1 :     assert_int_equal(chunk_send_ack_response->header.param1,
+    1307                 :            :                      SPDM_CHUNK_SEND_ACK_RESPONSE_ATTRIBUTE_EARLY_ERROR_DETECTED);
+    1308                 :            : 
+    1309                 :          1 :     error_response = (spdm_error_response_t*) (chunk_send_ack_response + 1);
+    1310                 :          1 :     assert_int_equal(error_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+    1311                 :          1 :     assert_int_equal(error_response->header.request_response_code, SPDM_ERROR);
+    1312                 :          1 :     assert_int_equal(error_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+    1313                 :          1 :     assert_int_equal(error_response->header.param2, 0);
+    1314                 :            : 
+    1315                 :          1 :     libspdm_test_responder_chunk_send_ack_reset_send_state(spdm_context);
+    1316                 :          1 : }
+    1317                 :            : 
+    1318                 :            : /**
+    1319                 :            :  * Test 15: Request has size larger than data transfer size.
+    1320                 :            :  **/
+    1321                 :          1 : void libspdm_test_responder_chunk_send_ack_rsp_case15(void** state)
+    1322                 :            : {
+    1323                 :            :     libspdm_return_t status;
+    1324                 :            : 
+    1325                 :            :     libspdm_test_context_t* spdm_test_context;
+    1326                 :            :     libspdm_context_t* spdm_context;
+    1327                 :            : 
+    1328                 :            :     size_t request_size;
+    1329                 :            :     size_t response_size;
+    1330                 :            : 
+    1331                 :            :     uint8_t request[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1332                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1333                 :            : 
+    1334                 :            :     spdm_chunk_send_request_t* chunk_send_request;
+    1335                 :            :     spdm_chunk_send_ack_response_t* chunk_send_ack_response;
+    1336                 :            :     spdm_error_response_t* error_response;
+    1337                 :            : 
+    1338                 :            :     const uint8_t* chunk_src;
+    1339                 :            :     uint8_t* chunk_dst;
+    1340                 :            : 
+    1341                 :          1 :     spdm_test_context = *state;
+    1342                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1343                 :          1 :     spdm_test_context->case_id = 15;
+    1344                 :            : 
+    1345                 :          1 :     libspdm_test_responder_chunk_send_ack_setup_algo_state(spdm_context);
+    1346                 :          1 :     spdm_context->chunk_context.send.chunk_in_use = true;
+    1347                 :          1 :     spdm_context->chunk_context.send.chunk_handle = (uint8_t) spdm_test_context->case_id;
+    1348                 :          1 :     spdm_context->chunk_context.send.chunk_seq_no = 0;
+    1349                 :            : 
+    1350                 :          1 :     chunk_src = (const uint8_t*) &m_libspdm_chunk_send_negotiate_algorithm_request1;
+    1351                 :            : 
+    1352                 :          1 :     libspdm_zero_mem(request, sizeof(request));
+    1353                 :          1 :     chunk_send_request = (spdm_chunk_send_request_t*) request;
+    1354                 :            : 
+    1355                 :          1 :     chunk_send_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+    1356                 :          1 :     chunk_send_request->header.request_response_code = SPDM_CHUNK_SEND;
+    1357                 :          1 :     chunk_send_request->header.param1 = 0;
+    1358                 :          1 :     chunk_send_request->header.param2 = (uint8_t) spdm_test_context->case_id; /* chunk_handle */
+    1359                 :          1 :     chunk_send_request->chunk_seq_no = 1;
+    1360                 :            : 
+    1361                 :          1 :     chunk_send_request->chunk_size =
+    1362                 :          1 :         spdm_context->local_context.capability.data_transfer_size
+    1363                 :          1 :         - sizeof(spdm_chunk_send_request_t);
+    1364                 :            : 
+    1365                 :          1 :     chunk_dst = ((uint8_t*) (chunk_send_request + 1));
+    1366                 :            : 
+    1367                 :          1 :     request_size = sizeof(spdm_chunk_send_request_t)
+    1368                 :          1 :                    + chunk_send_request->chunk_size
+    1369                 :            :                    + 1; /* Request size too large */
+    1370                 :            : 
+    1371                 :          1 :     libspdm_copy_mem(chunk_dst, chunk_send_request->chunk_size,
+    1372                 :          1 :                      chunk_src, chunk_send_request->chunk_size);
+    1373                 :            : 
+    1374                 :          1 :     response_size = sizeof(response);
+    1375                 :          1 :     status = libspdm_get_response_chunk_send(
+    1376                 :            :         spdm_context,
+    1377                 :            :         request_size, request,
+    1378                 :            :         &response_size, response);
+    1379                 :            : 
+    1380                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1381                 :          1 :     assert_true(response_size == sizeof(spdm_chunk_send_ack_response_t)
+    1382                 :            :                 + sizeof(spdm_error_response_t));
+    1383                 :            : 
+    1384                 :          1 :     chunk_send_ack_response = (spdm_chunk_send_ack_response_t*) response;
+    1385                 :          1 :     assert_int_equal(chunk_send_ack_response->header.param1,
+    1386                 :            :                      SPDM_CHUNK_SEND_ACK_RESPONSE_ATTRIBUTE_EARLY_ERROR_DETECTED);
+    1387                 :            : 
+    1388                 :          1 :     error_response = (spdm_error_response_t*) (chunk_send_ack_response + 1);
+    1389                 :          1 :     assert_int_equal(error_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+    1390                 :          1 :     assert_int_equal(error_response->header.request_response_code, SPDM_ERROR);
+    1391                 :          1 :     assert_int_equal(error_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+    1392                 :          1 :     assert_int_equal(error_response->header.param2, 0);
+    1393                 :            : 
+    1394                 :          1 :     libspdm_test_responder_chunk_send_ack_reset_send_state(spdm_context);
+    1395                 :          1 : }
+    1396                 :            : 
+    1397                 :            : /**
+    1398                 :            :  * Test 16: Request has chunk size + transferred size > large message size
+    1399                 :            :  **/
+    1400                 :          1 : void libspdm_test_responder_chunk_send_ack_rsp_case16(void** state)
+    1401                 :            : {
+    1402                 :            :     libspdm_return_t status;
+    1403                 :            : 
+    1404                 :            :     libspdm_test_context_t* spdm_test_context;
+    1405                 :            :     libspdm_context_t* spdm_context;
+    1406                 :            : 
+    1407                 :            :     size_t request_size;
+    1408                 :            :     size_t response_size;
+    1409                 :            : 
+    1410                 :            :     uint8_t request[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1411                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1412                 :            : 
+    1413                 :            :     spdm_chunk_send_request_t* chunk_send_request;
+    1414                 :            :     spdm_chunk_send_ack_response_t* chunk_send_ack_response;
+    1415                 :            :     spdm_error_response_t* error_response;
+    1416                 :            : 
+    1417                 :            :     const uint8_t* chunk_src;
+    1418                 :            :     uint8_t* chunk_dst;
+    1419                 :            : 
+    1420                 :          1 :     spdm_test_context = *state;
+    1421                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1422                 :          1 :     spdm_test_context->case_id = 16;
+    1423                 :            : 
+    1424                 :          1 :     libspdm_test_responder_chunk_send_ack_setup_algo_state(spdm_context);
+    1425                 :          1 :     spdm_context->chunk_context.send.chunk_in_use = true;
+    1426                 :          1 :     spdm_context->chunk_context.send.chunk_handle = (uint8_t) spdm_test_context->case_id;
+    1427                 :          1 :     spdm_context->chunk_context.send.chunk_seq_no = 0;
+    1428                 :          1 :     spdm_context->chunk_context.send.large_message_size = 1024;
+    1429                 :          1 :     spdm_context->chunk_context.send.chunk_bytes_transferred = 1023;
+    1430                 :            : 
+    1431                 :          1 :     chunk_src = (const uint8_t*) &m_libspdm_chunk_send_negotiate_algorithm_request1;
+    1432                 :            : 
+    1433                 :          1 :     libspdm_zero_mem(request, sizeof(request));
+    1434                 :          1 :     chunk_send_request = (spdm_chunk_send_request_t*) request;
+    1435                 :            : 
+    1436                 :          1 :     chunk_send_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+    1437                 :          1 :     chunk_send_request->header.request_response_code = SPDM_CHUNK_SEND;
+    1438                 :          1 :     chunk_send_request->header.param1 = 0;
+    1439                 :          1 :     chunk_send_request->header.param2 = (uint8_t) spdm_test_context->case_id; /* chunk_handle */
+    1440                 :          1 :     chunk_send_request->chunk_seq_no = 1;
+    1441                 :          1 :     chunk_send_request->chunk_size = 2; /* Bad size. Over large message size */
+    1442                 :            : 
+    1443                 :          1 :     chunk_dst = ((uint8_t*) (chunk_send_request + 1));
+    1444                 :            : 
+    1445                 :          1 :     request_size = sizeof(spdm_chunk_send_request_t)
+    1446                 :          1 :                    + chunk_send_request->chunk_size;
+    1447                 :            : 
+    1448                 :          1 :     libspdm_copy_mem(chunk_dst, chunk_send_request->chunk_size,
+    1449                 :          1 :                      chunk_src, chunk_send_request->chunk_size);
+    1450                 :            : 
+    1451                 :          1 :     response_size = sizeof(response);
+    1452                 :          1 :     status = libspdm_get_response_chunk_send(
+    1453                 :            :         spdm_context,
+    1454                 :            :         request_size, request,
+    1455                 :            :         &response_size, response);
+    1456                 :            : 
+    1457                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1458                 :          1 :     assert_true(response_size == sizeof(spdm_chunk_send_ack_response_t)
+    1459                 :            :                 + sizeof(spdm_error_response_t));
+    1460                 :            : 
+    1461                 :          1 :     chunk_send_ack_response = (spdm_chunk_send_ack_response_t*) response;
+    1462                 :          1 :     assert_int_equal(chunk_send_ack_response->header.param1,
+    1463                 :            :                      SPDM_CHUNK_SEND_ACK_RESPONSE_ATTRIBUTE_EARLY_ERROR_DETECTED);
+    1464                 :            : 
+    1465                 :          1 :     error_response = (spdm_error_response_t*) (chunk_send_ack_response + 1);
+    1466                 :          1 :     assert_int_equal(error_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+    1467                 :          1 :     assert_int_equal(error_response->header.request_response_code, SPDM_ERROR);
+    1468                 :          1 :     assert_int_equal(error_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+    1469                 :          1 :     assert_int_equal(error_response->header.param2, 0);
+    1470                 :            : 
+    1471                 :          1 :     libspdm_test_responder_chunk_send_ack_reset_send_state(spdm_context);
+    1472                 :          1 : }
+    1473                 :            : 
+    1474                 :            : /**
+    1475                 :            :  * Test 17: Request has LAST_CHUNK indicated before all bytes transferred.
+    1476                 :            :  **/
+    1477                 :          1 : void libspdm_test_responder_chunk_send_ack_rsp_case17(void** state)
+    1478                 :            : {
+    1479                 :            :     libspdm_return_t status;
+    1480                 :            : 
+    1481                 :            :     libspdm_test_context_t* spdm_test_context;
+    1482                 :            :     libspdm_context_t* spdm_context;
+    1483                 :            : 
+    1484                 :            :     size_t request_size;
+    1485                 :            :     size_t response_size;
+    1486                 :            : 
+    1487                 :            :     uint8_t request[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1488                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1489                 :            : 
+    1490                 :            :     spdm_chunk_send_request_t* chunk_send_request;
+    1491                 :            :     spdm_chunk_send_ack_response_t* chunk_send_ack_response;
+    1492                 :            :     spdm_error_response_t* error_response;
+    1493                 :            : 
+    1494                 :            :     const uint8_t* chunk_src;
+    1495                 :            :     uint8_t* chunk_dst;
+    1496                 :            : 
+    1497                 :          1 :     spdm_test_context = *state;
+    1498                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1499                 :          1 :     spdm_test_context->case_id = 17;
+    1500                 :            : 
+    1501                 :          1 :     libspdm_test_responder_chunk_send_ack_setup_algo_state(spdm_context);
+    1502                 :          1 :     spdm_context->chunk_context.send.chunk_in_use = true;
+    1503                 :          1 :     spdm_context->chunk_context.send.chunk_handle = (uint8_t) spdm_test_context->case_id;
+    1504                 :          1 :     spdm_context->chunk_context.send.chunk_seq_no = 0;
+    1505                 :          1 :     spdm_context->chunk_context.send.large_message_size = 1024;
+    1506                 :          1 :     spdm_context->chunk_context.send.chunk_bytes_transferred = 1023;
+    1507                 :            : 
+    1508                 :          1 :     chunk_src = (const uint8_t*) &m_libspdm_chunk_send_negotiate_algorithm_request1;
+    1509                 :            : 
+    1510                 :          1 :     libspdm_zero_mem(request, sizeof(request));
+    1511                 :          1 :     chunk_send_request = (spdm_chunk_send_request_t*) request;
+    1512                 :            : 
+    1513                 :          1 :     chunk_send_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+    1514                 :          1 :     chunk_send_request->header.request_response_code = SPDM_CHUNK_SEND;
+    1515                 :          1 :     chunk_send_request->header.param1 = 0;
+    1516                 :          1 :     chunk_send_request->header.param2 = (uint8_t) spdm_test_context->case_id; /* chunk_handle */
+    1517                 :          1 :     chunk_send_request->chunk_seq_no = 0;
+    1518                 :          1 :     chunk_send_request->chunk_size = 1;
+    1519                 :            : 
+    1520                 :          1 :     chunk_dst = ((uint8_t*) (chunk_send_request + 1));
+    1521                 :            : 
+    1522                 :          1 :     request_size = sizeof(spdm_chunk_send_request_t)
+    1523                 :          1 :                    + chunk_send_request->chunk_size;
+    1524                 :            : 
+    1525                 :          1 :     libspdm_copy_mem(chunk_dst, chunk_send_request->chunk_size,
+    1526                 :          1 :                      chunk_src, chunk_send_request->chunk_size);
+    1527                 :            : 
+    1528                 :          1 :     response_size = sizeof(response);
+    1529                 :          1 :     status = libspdm_get_response_chunk_send(
+    1530                 :            :         spdm_context,
+    1531                 :            :         request_size, request,
+    1532                 :            :         &response_size, response);
+    1533                 :            : 
+    1534                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1535                 :          1 :     assert_true(response_size == sizeof(spdm_chunk_send_ack_response_t)
+    1536                 :            :                 + sizeof(spdm_error_response_t));
+    1537                 :            : 
+    1538                 :          1 :     chunk_send_ack_response = (spdm_chunk_send_ack_response_t*) response;
+    1539                 :          1 :     assert_int_equal(chunk_send_ack_response->header.param1,
+    1540                 :            :                      SPDM_CHUNK_SEND_ACK_RESPONSE_ATTRIBUTE_EARLY_ERROR_DETECTED);
+    1541                 :            : 
+    1542                 :          1 :     error_response = (spdm_error_response_t*) (chunk_send_ack_response + 1);
+    1543                 :          1 :     assert_int_equal(error_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+    1544                 :          1 :     assert_int_equal(error_response->header.request_response_code, SPDM_ERROR);
+    1545                 :          1 :     assert_int_equal(error_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+    1546                 :          1 :     assert_int_equal(error_response->header.param2, 0);
+    1547                 :            : 
+    1548                 :          1 :     libspdm_test_responder_chunk_send_ack_reset_send_state(spdm_context);
+    1549                 :          1 : }
+    1550                 :            : 
+    1551                 :            : /**
+    1552                 :            :  * Test 18: Request missing LAST_CHUNK after all bytes transferred.
+    1553                 :            :  **/
+    1554                 :          1 : void libspdm_test_responder_chunk_send_ack_rsp_case18(void** state)
+    1555                 :            : {
+    1556                 :            :     libspdm_return_t status;
+    1557                 :            : 
+    1558                 :            :     libspdm_test_context_t* spdm_test_context;
+    1559                 :            :     libspdm_context_t* spdm_context;
+    1560                 :            : 
+    1561                 :            :     size_t request_size;
+    1562                 :            :     size_t response_size;
+    1563                 :            : 
+    1564                 :            :     uint8_t request[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1565                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1566                 :            : 
+    1567                 :            :     spdm_chunk_send_request_t* chunk_send_request;
+    1568                 :            :     spdm_chunk_send_ack_response_t* chunk_send_ack_response;
+    1569                 :            :     spdm_error_response_t* error_response;
+    1570                 :            : 
+    1571                 :            :     const uint8_t* chunk_src;
+    1572                 :            :     uint8_t* chunk_dst;
+    1573                 :            : 
+    1574                 :          1 :     spdm_test_context = *state;
+    1575                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1576                 :          1 :     spdm_test_context->case_id = 18;
+    1577                 :            : 
+    1578                 :          1 :     libspdm_test_responder_chunk_send_ack_setup_algo_state(spdm_context);
+    1579                 :          1 :     spdm_context->chunk_context.send.chunk_in_use = true;
+    1580                 :          1 :     spdm_context->chunk_context.send.chunk_handle = (uint8_t) spdm_test_context->case_id;
+    1581                 :          1 :     spdm_context->chunk_context.send.chunk_seq_no = 0;
+    1582                 :          1 :     spdm_context->chunk_context.send.large_message_size = 1024;
+    1583                 :          1 :     spdm_context->chunk_context.send.chunk_bytes_transferred = 1022;
+    1584                 :            : 
+    1585                 :          1 :     chunk_src = (const uint8_t*) &m_libspdm_chunk_send_negotiate_algorithm_request1;
+    1586                 :            : 
+    1587                 :          1 :     libspdm_zero_mem(request, sizeof(request));
+    1588                 :          1 :     chunk_send_request = (spdm_chunk_send_request_t*) request;
+    1589                 :            : 
+    1590                 :          1 :     chunk_send_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+    1591                 :          1 :     chunk_send_request->header.request_response_code = SPDM_CHUNK_SEND;
+    1592                 :          1 :     chunk_send_request->header.param1 = 0;
+    1593                 :          1 :     chunk_send_request->header.param2 = (uint8_t) spdm_test_context->case_id; /* chunk_handle */
+    1594                 :          1 :     chunk_send_request->chunk_seq_no = 0;
+    1595                 :          1 :     chunk_send_request->chunk_size = 2;
+    1596                 :            : 
+    1597                 :          1 :     chunk_dst = ((uint8_t*) (chunk_send_request + 1));
+    1598                 :            : 
+    1599                 :          1 :     request_size = sizeof(spdm_chunk_send_request_t)
+    1600                 :          1 :                    + chunk_send_request->chunk_size;
+    1601                 :            : 
+    1602                 :          1 :     libspdm_copy_mem(chunk_dst, chunk_send_request->chunk_size,
+    1603                 :          1 :                      chunk_src, chunk_send_request->chunk_size);
+    1604                 :            : 
+    1605                 :          1 :     response_size = sizeof(response);
+    1606                 :          1 :     status = libspdm_get_response_chunk_send(
+    1607                 :            :         spdm_context,
+    1608                 :            :         request_size, request,
+    1609                 :            :         &response_size, response);
+    1610                 :            : 
+    1611                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1612                 :          1 :     assert_true(response_size == sizeof(spdm_chunk_send_ack_response_t)
+    1613                 :            :                 + sizeof(spdm_error_response_t));
+    1614                 :            : 
+    1615                 :          1 :     chunk_send_ack_response = (spdm_chunk_send_ack_response_t*) response;
+    1616                 :          1 :     assert_int_equal(chunk_send_ack_response->header.param1,
+    1617                 :            :                      SPDM_CHUNK_SEND_ACK_RESPONSE_ATTRIBUTE_EARLY_ERROR_DETECTED);
+    1618                 :            : 
+    1619                 :          1 :     error_response = (spdm_error_response_t*) (chunk_send_ack_response + 1);
+    1620                 :          1 :     assert_int_equal(error_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+    1621                 :          1 :     assert_int_equal(error_response->header.request_response_code, SPDM_ERROR);
+    1622                 :          1 :     assert_int_equal(error_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+    1623                 :          1 :     assert_int_equal(error_response->header.param2, 0);
+    1624                 :            : 
+    1625                 :          1 :     libspdm_test_responder_chunk_send_ack_reset_send_state(spdm_context);
+    1626                 :          1 : }
+    1627                 :            : 
+    1628                 :            : /**
+    1629                 :            :  *  Test 19: Request missing LAST_CHUNK when request size != data transfer size.
+    1630                 :            :  **/
+    1631                 :          1 : void libspdm_test_responder_chunk_send_ack_rsp_case19(void** state)
+    1632                 :            : {
+    1633                 :            :     libspdm_return_t status;
+    1634                 :            : 
+    1635                 :            :     libspdm_test_context_t* spdm_test_context;
+    1636                 :            :     libspdm_context_t* spdm_context;
+    1637                 :            : 
+    1638                 :            :     size_t request_size;
+    1639                 :            :     size_t response_size;
+    1640                 :            : 
+    1641                 :            :     uint8_t request[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1642                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1643                 :            : 
+    1644                 :            :     spdm_chunk_send_request_t* chunk_send_request;
+    1645                 :            :     spdm_chunk_send_ack_response_t* chunk_send_ack_response;
+    1646                 :            :     spdm_error_response_t* error_response;
+    1647                 :            : 
+    1648                 :            :     const uint8_t* chunk_src;
+    1649                 :            :     uint8_t* chunk_dst;
+    1650                 :            : 
+    1651                 :          1 :     spdm_test_context = *state;
+    1652                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1653                 :          1 :     spdm_test_context->case_id = 19;
+    1654                 :            : 
+    1655                 :          1 :     libspdm_test_responder_chunk_send_ack_setup_algo_state(spdm_context);
+    1656                 :          1 :     spdm_context->chunk_context.send.chunk_in_use = true;
+    1657                 :          1 :     spdm_context->chunk_context.send.chunk_handle = (uint8_t) spdm_test_context->case_id;
+    1658                 :          1 :     spdm_context->chunk_context.send.chunk_seq_no = 0;
+    1659                 :          1 :     spdm_context->chunk_context.send.large_message_size = 1024;
+    1660                 :          1 :     spdm_context->chunk_context.send.chunk_bytes_transferred = 0;
+    1661                 :            : 
+    1662                 :          1 :     chunk_src = (const uint8_t*) &m_libspdm_chunk_send_negotiate_algorithm_request1;
+    1663                 :            : 
+    1664                 :          1 :     libspdm_zero_mem(request, sizeof(request));
+    1665                 :          1 :     chunk_send_request = (spdm_chunk_send_request_t*) request;
+    1666                 :            : 
+    1667                 :          1 :     chunk_send_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+    1668                 :          1 :     chunk_send_request->header.request_response_code = SPDM_CHUNK_SEND;
+    1669                 :          1 :     chunk_send_request->header.param1 = 0;
+    1670                 :          1 :     chunk_send_request->header.param2 = (uint8_t) spdm_test_context->case_id; /* chunk_handle */
+    1671                 :          1 :     chunk_send_request->chunk_seq_no = 0;
+    1672                 :          1 :     chunk_send_request->chunk_size =
+    1673                 :          1 :         spdm_context->local_context.capability.data_transfer_size
+    1674                 :            :         - sizeof(spdm_chunk_send_request_t)
+    1675                 :          1 :         - 1; /* Chunk size too small. */
+    1676                 :            : 
+    1677                 :          1 :     chunk_dst = ((uint8_t*) (chunk_send_request + 1));
+    1678                 :            : 
+    1679                 :          1 :     request_size = sizeof(spdm_chunk_send_request_t)
+    1680                 :          1 :                    + chunk_send_request->chunk_size;
+    1681                 :            : 
+    1682                 :          1 :     libspdm_copy_mem(chunk_dst, chunk_send_request->chunk_size,
+    1683                 :          1 :                      chunk_src, chunk_send_request->chunk_size);
+    1684                 :            : 
+    1685                 :          1 :     response_size = sizeof(response);
+    1686                 :          1 :     status = libspdm_get_response_chunk_send(
+    1687                 :            :         spdm_context,
+    1688                 :            :         request_size, request,
+    1689                 :            :         &response_size, response);
+    1690                 :            : 
+    1691                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+    1692                 :          1 :     assert_true(response_size == sizeof(spdm_chunk_send_ack_response_t)
+    1693                 :            :                 + sizeof(spdm_error_response_t));
+    1694                 :            : 
+    1695                 :          1 :     chunk_send_ack_response = (spdm_chunk_send_ack_response_t*) response;
+    1696                 :          1 :     assert_int_equal(chunk_send_ack_response->header.param1,
+    1697                 :            :                      SPDM_CHUNK_SEND_ACK_RESPONSE_ATTRIBUTE_EARLY_ERROR_DETECTED);
+    1698                 :            : 
+    1699                 :          1 :     error_response = (spdm_error_response_t*) (chunk_send_ack_response + 1);
+    1700                 :          1 :     assert_int_equal(error_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+    1701                 :          1 :     assert_int_equal(error_response->header.request_response_code, SPDM_ERROR);
+    1702                 :          1 :     assert_int_equal(error_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+    1703                 :          1 :     assert_int_equal(error_response->header.param2, 0);
+    1704                 :            : 
+    1705                 :          1 :     libspdm_test_responder_chunk_send_ack_reset_send_state(spdm_context);
+    1706                 :          1 : }
+    1707                 :            : 
+    1708                 :            : libspdm_test_context_t m_libspdm_responder_chunk_send_ack_rsp_test_context = {
+    1709                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+    1710                 :            :     false,
+    1711                 :            : };
+    1712                 :            : 
+    1713                 :          1 : int libspdm_responder_chunk_send_ack_test_main(void)
+    1714                 :            : {
+    1715                 :          1 :     const struct CMUnitTest spdm_responder_chunk_send_ack_tests[] = {
+    1716                 :            :         /* Responder sent multiple chunks and processed correctly */
+    1717                 :            :         cmocka_unit_test(libspdm_test_responder_chunk_send_ack_rsp_case0),
+    1718                 :            :         /* Responder has no response flag chunk cap */
+    1719                 :            :         cmocka_unit_test(libspdm_test_responder_chunk_send_ack_rsp_case1),
+    1720                 :            :         /* Responder has bad response state */
+    1721                 :            :         cmocka_unit_test(libspdm_test_responder_chunk_send_ack_rsp_case2),
+    1722                 :            :         /* Responder has connection state <= NOT_START */
+    1723                 :            :         cmocka_unit_test(libspdm_test_responder_chunk_send_ack_rsp_case3),
+    1724                 :            :         /* Request has wrong size */
+    1725                 :            :         cmocka_unit_test(libspdm_test_responder_chunk_send_ack_rsp_case4),
+    1726                 :            :         /* Request has SPDM version less than 1.2*/
+    1727                 :            :         cmocka_unit_test(libspdm_test_responder_chunk_send_ack_rsp_case5),
+    1728                 :            :         /* Request has SPDM version not matching connection */
+    1729                 :            :         cmocka_unit_test(libspdm_test_responder_chunk_send_ack_rsp_case6),
+    1730                 :            :         /* Responder is already in chunking mode */
+    1731                 :            :         cmocka_unit_test(libspdm_test_responder_chunk_send_ack_rsp_case7),
+    1732                 :            : 
+    1733                 :            :         /* First request has bad sequence number */
+    1734                 :            :         cmocka_unit_test(libspdm_test_responder_chunk_send_ack_rsp_case8),
+    1735                 :            :         /* First request has chunk size too large */
+    1736                 :            :         cmocka_unit_test(libspdm_test_responder_chunk_send_ack_rsp_case9),
+    1737                 :            :         /* First request has size larger than data transfer size */
+    1738                 :            :         cmocka_unit_test(libspdm_test_responder_chunk_send_ack_rsp_case10),
+    1739                 :            :         /* Large message size larger than max SPDM message size. */
+    1740                 :            :         cmocka_unit_test(libspdm_test_responder_chunk_send_ack_rsp_case11),
+    1741                 :            :         /* First request has LAST CHUNK bit set. */
+    1742                 :            :         cmocka_unit_test(libspdm_test_responder_chunk_send_ack_rsp_case12),
+    1743                 :            : 
+    1744                 :            :         /* Request has bad sequence number */
+    1745                 :            :         cmocka_unit_test(libspdm_test_responder_chunk_send_ack_rsp_case13),
+    1746                 :            :         /* Request has bad chunk handle */
+    1747                 :            :         cmocka_unit_test(libspdm_test_responder_chunk_send_ack_rsp_case14),
+    1748                 :            :         /* Request has chunk size too large for request*/
+    1749                 :            :         cmocka_unit_test(libspdm_test_responder_chunk_send_ack_rsp_case15),
+    1750                 :            :         /* Request has chunk size + transferred size > large message size */
+    1751                 :            :         cmocka_unit_test(libspdm_test_responder_chunk_send_ack_rsp_case16),
+    1752                 :            :         /* Request has LAST_CHUNK indicated before all bytes transferred. */
+    1753                 :            :         cmocka_unit_test(libspdm_test_responder_chunk_send_ack_rsp_case17),
+    1754                 :            :         /* Request missing LAST_CHUNK after all bytes transferred. */
+    1755                 :            :         cmocka_unit_test(libspdm_test_responder_chunk_send_ack_rsp_case18),
+    1756                 :            :         /* Request missing LAST_CHUNK when request size != data transfer size. */
+    1757                 :            :         cmocka_unit_test(libspdm_test_responder_chunk_send_ack_rsp_case19),
+    1758                 :            :     };
+    1759                 :            : 
+    1760                 :          1 :     libspdm_setup_test_context(&m_libspdm_responder_chunk_send_ack_rsp_test_context);
+    1761                 :            : 
+    1762                 :          1 :     return cmocka_run_group_tests(spdm_responder_chunk_send_ack_tests,
+    1763                 :            :                                   libspdm_unit_test_group_setup,
+    1764                 :            :                                   libspdm_unit_test_group_teardown);
+    1765                 :            : }
+    1766                 :            : 
+    1767                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/csr.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_responder/csr.c.func-sort-c.html new file mode 100644 index 00000000000..06116cce901 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/csr.c.func-sort-c.html @@ -0,0 +1,181 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/csr.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - csr.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:85287697.3 %
Date:2024-09-22 08:21:07Functions:2525100.0 %
Branches:396460.9 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_clear_cached_csr1
libspdm_gen_req_info1
libspdm_responder_csr_test_main1
libspdm_test_responder_csr_case11
libspdm_test_responder_csr_case101
libspdm_test_responder_csr_case111
libspdm_test_responder_csr_case121
libspdm_test_responder_csr_case131
libspdm_test_responder_csr_case141
libspdm_test_responder_csr_case151
libspdm_test_responder_csr_case161
libspdm_test_responder_csr_case21
libspdm_test_responder_csr_case31
libspdm_test_responder_csr_case41
libspdm_test_responder_csr_case51
libspdm_test_responder_csr_case61
libspdm_test_responder_csr_case71
libspdm_test_responder_csr_case81
libspdm_test_responder_csr_case91
libspdm_check_csr_basic_constraints2
libspdm_set_csr_after_reset5
libspdm_set_csr_before_reset5
libspdm_test_clear_cached_last_request6
libspdm_test_read_cached_csr6
libspdm_find_buffer7
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/csr.c.func.html b/coverage_log/unit_test/test_spdm_responder/csr.c.func.html new file mode 100644 index 00000000000..979d74e7c23 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/csr.c.func.html @@ -0,0 +1,181 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/csr.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - csr.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:85287697.3 %
Date:2024-09-22 08:21:07Functions:2525100.0 %
Branches:396460.9 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_check_csr_basic_constraints2
libspdm_clear_cached_csr1
libspdm_find_buffer7
libspdm_gen_req_info1
libspdm_responder_csr_test_main1
libspdm_set_csr_after_reset5
libspdm_set_csr_before_reset5
libspdm_test_clear_cached_last_request6
libspdm_test_read_cached_csr6
libspdm_test_responder_csr_case11
libspdm_test_responder_csr_case101
libspdm_test_responder_csr_case111
libspdm_test_responder_csr_case121
libspdm_test_responder_csr_case131
libspdm_test_responder_csr_case141
libspdm_test_responder_csr_case151
libspdm_test_responder_csr_case161
libspdm_test_responder_csr_case21
libspdm_test_responder_csr_case31
libspdm_test_responder_csr_case41
libspdm_test_responder_csr_case51
libspdm_test_responder_csr_case61
libspdm_test_responder_csr_case71
libspdm_test_responder_csr_case81
libspdm_test_responder_csr_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/csr.c.gcov.html b/coverage_log/unit_test/test_spdm_responder/csr.c.gcov.html new file mode 100644 index 00000000000..7740f6cd41f --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/csr.c.gcov.html @@ -0,0 +1,2123 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/csr.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - csr.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:85287697.3 %
Date:2024-09-22 08:21:07Functions:2525100.0 %
Branches:396460.9 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_responder_lib.h"
+       9                 :            : 
+      10                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CSR_CAP
+      11                 :            : 
+      12                 :            : #define LIBSPDM_MAX_CSR_SIZE 0x1000
+      13                 :            : 
+      14                 :            : /*refer to https://github.com/Mbed-TLS/mbedtls/blob/3048c8c90654eb116a6b17c0d2d27c3ccbe6782c/programs/x509/cert_req.c#L119-L129*/
+      15                 :            : #define LIBSPDM_MAX_REQ_INFO_BUFFER_SIZE 4096
+      16                 :            : 
+      17                 :            : uint8_t m_csr_opaque_data[8] = "libspdm";
+      18                 :            : 
+      19                 :            : /*ECC 256 req_info(include right req_info attribute)*/
+      20                 :            : uint8_t req_info_sequence[] = {0x30, 0x81, 0xBF,};
+      21                 :            : uint8_t req_info_version[] = {0x02, 0x01, 0x00,};
+      22                 :            : uint8_t req_info_subject[] = {
+      23                 :            :     0x30, 0x45, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x41, 0x55, 0x31,
+      24                 :            :     0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0C, 0x0A, 0x53, 0x6F, 0x6D, 0x65, 0x2D, 0x53,
+      25                 :            :     0x74, 0x61, 0x74, 0x65, 0x31, 0x21, 0x30, 0x1F, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C, 0x18, 0x49,
+      26                 :            :     0x6E, 0x74, 0x65, 0x72, 0x6E, 0x65, 0x74, 0x20, 0x57, 0x69, 0x64, 0x67, 0x69, 0x74, 0x73, 0x20,
+      27                 :            :     0x50, 0x74, 0x79, 0x20, 0x4C, 0x74, 0x64,
+      28                 :            : };
+      29                 :            : uint8_t req_info_right_attributes[] = {
+      30                 :            :     /*[0]: attributes*/
+      31                 :            :     0xA0, 0x18, 0x30, 0x16,
+      32                 :            :     /*OID*/
+      33                 :            :     0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09, 0x07,
+      34                 :            :     /*attributes*/
+      35                 :            :     0x31, 0x09, 0x0C, 0x07, 0x74, 0x65, 0x73, 0x74, 0x31, 0x32, 0x33
+      36                 :            : };
+      37                 :            : 
+      38                 :            : /*the unique attribute from right_req_info*/
+      39                 :            : uint8_t right_req_info_string[] = {0x74, 0x65, 0x73, 0x74, 0x31, 0x32, 0x33};
+      40                 :            : /*the default subject without req_info*/
+      41                 :            : uint8_t default_subject1[] = {
+      42                 :            :     0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4E, 0x4C,
+      43                 :            : };
+      44                 :            : 
+      45                 :            : uint8_t default_subject2[] = {
+      46                 :            :     0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C, 0x08, 0x50, 0x6F, 0x6C, 0x61, 0x72, 0x53, 0x53, 0x4C,
+      47                 :            : };
+      48                 :            : uint8_t default_subject3[] = {
+      49                 :            :     0x0C, 0x11, 0x50, 0x6F, 0x6C, 0x61, 0x72, 0x53, 0x53, 0x4C, 0x20, 0x53, 0x65, 0x72, 0x76,
+      50                 :            :     0x65, 0x72, 0x20, 0x31
+      51                 :            : };
+      52                 :            : 
+      53                 :            : static uint8_t right_req_info[LIBSPDM_MAX_REQ_INFO_BUFFER_SIZE];
+      54                 :            : static uint8_t wrong_req_info[LIBSPDM_MAX_REQ_INFO_BUFFER_SIZE];
+      55                 :            : static uint16_t req_info_len;
+      56                 :            : 
+      57                 :            : /*gen right_req_info and wrong_req_info*/
+      58                 :          1 : void libspdm_gen_req_info()
+      59                 :            : {
+      60                 :            :     uint8_t *req_info_p;
+      61                 :            :     void *req_info_pkinfo;
+      62                 :            :     size_t req_info_pkinfo_len;
+      63                 :            : 
+      64                 :          1 :     libspdm_zero_mem(right_req_info, sizeof(right_req_info));
+      65                 :          1 :     libspdm_zero_mem(wrong_req_info, sizeof(wrong_req_info));
+      66                 :            : 
+      67                 :          1 :     req_info_p = right_req_info;
+      68                 :          1 :     req_info_len = sizeof(right_req_info);
+      69                 :            : 
+      70                 :          1 :     libspdm_read_responder_public_key(m_libspdm_use_asym_algo,
+      71                 :            :                                       &req_info_pkinfo, &req_info_pkinfo_len);
+      72                 :            : 
+      73                 :            :     /*concat right_req_info*/
+      74                 :          1 :     libspdm_copy_mem(req_info_p, req_info_len, req_info_sequence, sizeof(req_info_sequence));
+      75                 :          1 :     req_info_p += sizeof(req_info_sequence);
+      76                 :          1 :     req_info_len -= sizeof(req_info_sequence);
+      77                 :            : 
+      78                 :          1 :     libspdm_copy_mem(req_info_p, req_info_len, req_info_version, sizeof(req_info_version));
+      79                 :          1 :     req_info_p += sizeof(req_info_version);
+      80                 :          1 :     req_info_len -= sizeof(req_info_version);
+      81                 :            : 
+      82                 :          1 :     libspdm_copy_mem(req_info_p, req_info_len, req_info_subject, sizeof(req_info_subject));
+      83                 :          1 :     req_info_p += sizeof(req_info_subject);
+      84                 :          1 :     req_info_len -= sizeof(req_info_subject);
+      85                 :            : 
+      86                 :          1 :     libspdm_copy_mem(req_info_p, req_info_len, req_info_pkinfo, req_info_pkinfo_len);
+      87                 :          1 :     req_info_p += req_info_pkinfo_len;
+      88                 :          1 :     req_info_len = (uint16_t)(req_info_len - req_info_pkinfo_len);
+      89                 :            : 
+      90                 :          1 :     libspdm_copy_mem(req_info_p, req_info_len,
+      91                 :            :                      req_info_right_attributes, sizeof(req_info_right_attributes));
+      92                 :          1 :     req_info_p += sizeof(req_info_right_attributes);
+      93                 :          1 :     req_info_len -= sizeof(req_info_right_attributes);
+      94                 :            : 
+      95                 :          1 :     req_info_len = sizeof(right_req_info) - req_info_len;
+      96                 :            : 
+      97                 :            :     /*concat wrong_req_info*/
+      98                 :          1 :     libspdm_copy_mem(wrong_req_info, sizeof(wrong_req_info), right_req_info, req_info_len);
+      99                 :            :     /*make the wrong_req_info is wrong*/
+     100                 :          1 :     *wrong_req_info = '1';
+     101                 :            : 
+     102                 :          1 :     free(req_info_pkinfo);
+     103                 :          1 : }
+     104                 :            : 
+     105                 :            : /*find destination buffer from source buffer*/
+     106                 :          7 : bool libspdm_find_buffer(uint8_t *src, size_t src_len, uint8_t *dst, size_t dst_len)
+     107                 :            : {
+     108                 :            :     size_t index;
+     109                 :            : 
+     110   [ +  -  -  + ]:          7 :     if ((src == NULL) || (dst == NULL)) {
+     111                 :          0 :         return false;
+     112                 :            :     }
+     113                 :            : 
+     114         [ -  + ]:          7 :     if (src_len < dst_len) {
+     115                 :          0 :         return false;
+     116                 :            :     }
+     117                 :            : 
+     118         [ +  - ]:        552 :     for (index = 0; index < src_len - dst_len; index++) {
+     119   [ +  +  +  + ]:        580 :         if ((*(src + index) == *dst) &&
+     120                 :         28 :             libspdm_consttime_is_mem_equal(src + index, dst, dst_len)) {
+     121                 :          7 :             return true;
+     122                 :            :         }
+     123                 :            :     }
+     124                 :            : 
+     125                 :          0 :     return false;
+     126                 :            : }
+     127                 :            : 
+     128                 :            : /*get the cached csr*/
+     129                 :          6 : bool libspdm_test_read_cached_csr(uint8_t **csr_pointer, size_t *csr_len)
+     130                 :            : {
+     131                 :            :     bool res;
+     132                 :            :     char *file;
+     133                 :            : 
+     134                 :          6 :     file = "test_csr/cached.csr";
+     135                 :            : 
+     136                 :          6 :     res = libspdm_read_input_file(file, (void **)csr_pointer, csr_len);
+     137                 :          6 :     return res;
+     138                 :            : }
+     139                 :            : 
+     140                 :            : /*
+     141                 :            :  * If device need reset to set csr, the function simulates the CSR state before device reset.
+     142                 :            :  * The returned status indicates whether the setting was successful or unsuccessful.
+     143                 :            :  **/
+     144                 :          5 : bool libspdm_set_csr_before_reset()
+     145                 :            : {
+     146                 :          5 :     char *file_name = "test_csr/cached.csr";
+     147                 :          5 :     char *new_name = "test_csr/cached.staging";
+     148                 :            : 
+     149         [ -  + ]:          5 :     if (rename(file_name, new_name) != 0) {
+     150                 :          0 :         return false;
+     151                 :            :     }
+     152                 :            : 
+     153                 :          5 :     return true;
+     154                 :            : }
+     155                 :            : 
+     156                 :            : /*
+     157                 :            :  * If device need reset to set csr, the function simulates the CSR state after device reset.
+     158                 :            :  * The returned status indicates whether the setting was successful or unsuccessful.
+     159                 :            :  **/
+     160                 :          5 : bool libspdm_set_csr_after_reset()
+     161                 :            : {
+     162                 :          5 :     char *file_name = "test_csr/cached.csr";
+     163                 :          5 :     char *new_name = "test_csr/cached.staging";
+     164                 :            : 
+     165         [ -  + ]:          5 :     if (rename(new_name, file_name) != 0) {
+     166                 :          0 :         return false;
+     167                 :            :     }
+     168                 :            : 
+     169                 :          5 :     return true;
+     170                 :            : }
+     171                 :            : 
+     172                 :            : /*ensure that cached.csr exists in test_csr at the beginning*/
+     173                 :          1 : void libspdm_clear_cached_csr()
+     174                 :            : {
+     175                 :          1 :     char *new_name = "test_csr/cached.csr";
+     176                 :          1 :     char *file_name = "test_csr/cached.staging";
+     177                 :            : 
+     178                 :          1 :     rename(file_name, new_name);
+     179                 :          1 : }
+     180                 :            : 
+     181                 :            : /*clean the cached last SPDM csr request*/
+     182                 :          6 : void libspdm_test_clear_cached_last_request()
+     183                 :            : {
+     184                 :            :     uint8_t index;
+     185                 :            : 
+     186                 :          6 :     char file[] = "cached_last_csr_x_request";
+     187                 :            : 
+     188         [ +  + ]:         48 :     for (index = 1; index <= SPDM_MAX_CSR_TRACKING_TAG; index++) {
+     189                 :         42 :         file[16] = (char)(index + '0');
+     190                 :         42 :         libspdm_write_output_file(file, NULL, 0);
+     191                 :            :     }
+     192                 :          6 : }
+     193                 :            : 
+     194                 :            : /*check the csr is consistent with the is_device_cert_model*/
+     195                 :          2 : bool libspdm_check_csr_basic_constraints(uint8_t *csr, uint16_t csr_len, bool is_device_cert_model)
+     196                 :            : {
+     197                 :            :     bool result;
+     198                 :            :     uint8_t *ptr;
+     199                 :            :     uint16_t length;
+     200                 :            :     size_t obj_len;
+     201                 :            :     uint8_t *end;
+     202                 :            : 
+     203                 :            :     /*basic_constraints: CA: false */
+     204                 :            :     #define BASIC_CONSTRAINTS_STRING_FALSE {0x30, 0x00}
+     205                 :          2 :     uint8_t basic_constraints_false[] = BASIC_CONSTRAINTS_STRING_FALSE;
+     206                 :            : 
+     207                 :            :     /*basic_constraints: CA: true */
+     208                 :            :     #define BASIC_CONSTRAINTS_STRING_TRUE {0x30, 0x03, 0x01, 0x01, 0xFF}
+     209                 :          2 :     uint8_t basic_constraints_true[] = BASIC_CONSTRAINTS_STRING_TRUE;
+     210                 :            : 
+     211                 :          2 :     length = csr_len;
+     212                 :          2 :     ptr = (uint8_t*)csr;
+     213                 :          2 :     obj_len = 0;
+     214                 :          2 :     end = ptr + length;
+     215                 :            : 
+     216                 :          2 :     result = libspdm_asn1_get_tag(&ptr, end, &obj_len,
+     217                 :            :                                   LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
+     218         [ -  + ]:          2 :     if (!result) {
+     219                 :          0 :         return false;
+     220                 :            :     }
+     221                 :            : 
+     222                 :          2 :     result = libspdm_asn1_get_tag(&ptr, end, &obj_len,
+     223                 :            :                                   LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
+     224         [ -  + ]:          2 :     if (!result) {
+     225                 :          0 :         return false;
+     226                 :            :     }
+     227                 :            : 
+     228                 :          2 :     end = ptr + obj_len;
+     229                 :            : 
+     230                 :            :     /*version*/
+     231                 :          2 :     result = libspdm_asn1_get_tag(&ptr, end, &obj_len, LIBSPDM_CRYPTO_ASN1_INTEGER);
+     232         [ -  + ]:          2 :     if (!result) {
+     233                 :          0 :         return false;
+     234                 :            :     }
+     235                 :          2 :     ptr += obj_len;
+     236                 :            : 
+     237                 :            :     /*subject*/
+     238                 :          2 :     result = libspdm_asn1_get_tag(&ptr, end, &obj_len,
+     239                 :            :                                   LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
+     240         [ -  + ]:          2 :     if (!result) {
+     241                 :          0 :         return false;
+     242                 :            :     }
+     243                 :          2 :     ptr += obj_len;
+     244                 :            : 
+     245                 :            :     /*PKinfo*/
+     246                 :          2 :     result = libspdm_asn1_get_tag(&ptr, end, &obj_len,
+     247                 :            :                                   LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
+     248         [ -  + ]:          2 :     if (!result) {
+     249                 :          0 :         return false;
+     250                 :            :     }
+     251                 :          2 :     ptr += obj_len;
+     252                 :            : 
+     253                 :            :     /*attribute*/
+     254                 :          2 :     result = libspdm_asn1_get_tag(&ptr, end, &obj_len,
+     255                 :            :                                   LIBSPDM_CRYPTO_ASN1_CONTEXT_SPECIFIC |
+     256                 :            :                                   LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
+     257         [ -  + ]:          2 :     if (!result) {
+     258                 :          0 :         return false;
+     259                 :            :     }
+     260                 :            : 
+     261                 :          2 :     result = libspdm_asn1_get_tag(&ptr, end, &obj_len,
+     262                 :            :                                   LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
+     263         [ -  + ]:          2 :     if (!result) {
+     264                 :          0 :         return false;
+     265                 :            :     }
+     266                 :          2 :     result = libspdm_asn1_get_tag(&ptr, end, &obj_len, LIBSPDM_CRYPTO_ASN1_OID);
+     267         [ -  + ]:          2 :     if (!result) {
+     268                 :          0 :         return false;
+     269                 :            :     }
+     270                 :          2 :     ptr += obj_len;
+     271                 :            : 
+     272                 :          2 :     result = libspdm_asn1_get_tag(&ptr, end, &obj_len,
+     273                 :            :                                   LIBSPDM_CRYPTO_ASN1_SET | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
+     274         [ -  + ]:          2 :     if (!result) {
+     275                 :          0 :         return false;
+     276                 :            :     }
+     277                 :          2 :     result = libspdm_asn1_get_tag(&ptr, end, &obj_len,
+     278                 :            :                                   LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
+     279         [ -  + ]:          2 :     if (!result) {
+     280                 :          0 :         return false;
+     281                 :            :     }
+     282                 :          2 :     result = libspdm_asn1_get_tag(&ptr, end, &obj_len,
+     283                 :            :                                   LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
+     284         [ -  + ]:          2 :     if (!result) {
+     285                 :          0 :         return false;
+     286                 :            :     }
+     287                 :            :     /*basic constriants oid*/
+     288                 :          2 :     result = libspdm_asn1_get_tag(&ptr, end, &obj_len, LIBSPDM_CRYPTO_ASN1_OID);
+     289         [ -  + ]:          2 :     if (!result) {
+     290                 :          0 :         return false;
+     291                 :            :     }
+     292                 :          2 :     ptr += obj_len;
+     293                 :            : 
+     294                 :            :     /*basic constriants*/
+     295                 :          2 :     result = libspdm_asn1_get_tag(&ptr, end, &obj_len, LIBSPDM_CRYPTO_ASN1_OCTET_STRING);
+     296         [ -  + ]:          2 :     if (!result) {
+     297                 :          0 :         return false;
+     298                 :            :     }
+     299                 :            : 
+     300         [ +  + ]:          2 :     if (is_device_cert_model) {
+     301                 :          1 :         result = libspdm_consttime_is_mem_equal(
+     302                 :            :             ptr, basic_constraints_false, sizeof(basic_constraints_false));
+     303                 :            :     } else {
+     304                 :          1 :         result = libspdm_consttime_is_mem_equal(
+     305                 :            :             ptr, basic_constraints_true, sizeof(basic_constraints_true));
+     306                 :            :     }
+     307                 :            : 
+     308                 :          2 :     return result;
+     309                 :            : }
+     310                 :            : 
+     311                 :            : /**
+     312                 :            :  * Test 1: receives a valid GET_CSR request message from Requester
+     313                 :            :  * Expected Behavior: produces a valid CSR response message with device_cert mode
+     314                 :            :  **/
+     315                 :          1 : void libspdm_test_responder_csr_case1(void **state)
+     316                 :            : {
+     317                 :            :     libspdm_return_t status;
+     318                 :            :     libspdm_test_context_t *spdm_test_context;
+     319                 :            :     libspdm_context_t *spdm_context;
+     320                 :            :     size_t response_size;
+     321                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     322                 :            :     spdm_csr_response_t *spdm_response;
+     323                 :            :     spdm_get_csr_request_t *m_libspdm_get_csr_request;
+     324                 :            :     uint8_t wrong_csr[LIBSPDM_MAX_CSR_SIZE];
+     325                 :            :     bool result;
+     326                 :            :     bool is_device_cert_model;
+     327                 :            : 
+     328                 :          1 :     libspdm_zero_mem(wrong_csr, LIBSPDM_MAX_CSR_SIZE);
+     329                 :            : 
+     330                 :          1 :     spdm_test_context = *state;
+     331                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     332                 :          1 :     spdm_test_context->case_id = 0x1;
+     333                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     334                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     335                 :            : 
+     336                 :          1 :     spdm_context->connection_info.connection_state =
+     337                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     338                 :          1 :     spdm_context->local_context.capability.flags |=
+     339                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CSR_CAP;
+     340                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     341                 :            :         m_libspdm_use_hash_algo;
+     342                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     343                 :            :         m_libspdm_use_asym_algo;
+     344                 :            : 
+     345                 :          1 :     is_device_cert_model = true;
+     346                 :          1 :     spdm_context->local_context.capability.flags &=
+     347                 :            :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ALIAS_CERT_CAP;
+     348                 :            : 
+     349                 :          1 :     m_libspdm_get_csr_request = malloc(sizeof(spdm_get_csr_request_t));
+     350                 :            : 
+     351                 :          1 :     m_libspdm_get_csr_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     352                 :          1 :     m_libspdm_get_csr_request->header.request_response_code = SPDM_GET_CSR;
+     353                 :          1 :     m_libspdm_get_csr_request->header.param1 = 0;
+     354                 :          1 :     m_libspdm_get_csr_request->header.param2 = 0;
+     355                 :            : 
+     356                 :          1 :     m_libspdm_get_csr_request->opaque_data_length = 0;
+     357                 :          1 :     m_libspdm_get_csr_request->requester_info_length = 0;
+     358                 :            : 
+     359                 :          1 :     size_t m_libspdm_get_csr_request_size = sizeof(spdm_get_csr_request_t);
+     360                 :            : 
+     361                 :            :     /*init req_info*/
+     362                 :          1 :     libspdm_gen_req_info();
+     363                 :            : 
+     364                 :          1 :     response_size = sizeof(response);
+     365                 :          1 :     status = libspdm_get_response_csr(spdm_context,
+     366                 :            :                                       m_libspdm_get_csr_request_size,
+     367                 :            :                                       m_libspdm_get_csr_request,
+     368                 :            :                                       &response_size, response);
+     369                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     370                 :            : 
+     371                 :          1 :     spdm_response = (void *)response;
+     372                 :          1 :     assert_int_equal(response_size, sizeof(spdm_csr_response_t) + spdm_response->csr_length);
+     373                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     374                 :            :                      SPDM_CSR);
+     375                 :            : 
+     376                 :            :     /*check returned CSR not zero */
+     377                 :          1 :     assert_memory_not_equal(spdm_response + 1, wrong_csr, spdm_response->csr_length);
+     378                 :            : 
+     379                 :            :     /*check the resulting CSR shall be for a Device Certificate*/
+     380                 :          1 :     result = libspdm_check_csr_basic_constraints((uint8_t *)(spdm_response + 1),
+     381                 :          1 :                                                  spdm_response->csr_length, is_device_cert_model);
+     382                 :          1 :     assert_true(result);
+     383                 :            : 
+     384                 :            :     /*check that returned CSR contains default subject*/
+     385                 :          1 :     assert_true(libspdm_find_buffer((uint8_t *)(spdm_response + 1), spdm_response->csr_length,
+     386                 :            :                                     default_subject1, sizeof(default_subject1)));
+     387                 :          1 :     assert_true(libspdm_find_buffer((uint8_t *)(spdm_response + 1), spdm_response->csr_length,
+     388                 :            :                                     default_subject2, sizeof(default_subject2)));
+     389                 :          1 :     assert_true(libspdm_find_buffer((uint8_t *)(spdm_response + 1), spdm_response->csr_length,
+     390                 :            :                                     default_subject3, sizeof(default_subject3)));
+     391                 :          1 :     free(m_libspdm_get_csr_request);
+     392                 :          1 : }
+     393                 :            : 
+     394                 :            : /**
+     395                 :            :  * Test 2: Wrong GET_CSR message size (larger than expected)
+     396                 :            :  * Expected Behavior: generate an ERROR_RESPONSE with code SPDM_ERROR_CODE_INVALID_REQUEST
+     397                 :            :  **/
+     398                 :          1 : void libspdm_test_responder_csr_case2(void **state)
+     399                 :            : {
+     400                 :            :     libspdm_return_t status;
+     401                 :            :     libspdm_test_context_t *spdm_test_context;
+     402                 :            :     libspdm_context_t *spdm_context;
+     403                 :            :     size_t response_size;
+     404                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     405                 :            :     spdm_csr_response_t *spdm_response;
+     406                 :            :     spdm_get_csr_request_t *m_libspdm_get_csr_request;
+     407                 :            : 
+     408                 :          1 :     spdm_test_context = *state;
+     409                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     410                 :          1 :     spdm_test_context->case_id = 0x2;
+     411                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     412                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     413                 :            : 
+     414                 :          1 :     spdm_context->connection_info.connection_state =
+     415                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     416                 :          1 :     spdm_context->local_context.capability.flags |=
+     417                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CSR_CAP;
+     418                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     419                 :            :         m_libspdm_use_hash_algo;
+     420                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     421                 :            :         m_libspdm_use_asym_algo;
+     422                 :            : 
+     423                 :            : 
+     424                 :          1 :     m_libspdm_get_csr_request = malloc(sizeof(spdm_get_csr_request_t));
+     425                 :            : 
+     426                 :          1 :     m_libspdm_get_csr_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     427                 :          1 :     m_libspdm_get_csr_request->header.request_response_code = SPDM_GET_CSR;
+     428                 :          1 :     m_libspdm_get_csr_request->header.param1 = 0;
+     429                 :          1 :     m_libspdm_get_csr_request->header.param2 = 0;
+     430                 :            : 
+     431                 :          1 :     m_libspdm_get_csr_request->opaque_data_length = 0;
+     432                 :          1 :     m_libspdm_get_csr_request->requester_info_length = 0;
+     433                 :            : 
+     434                 :            :     /* Bad request size*/
+     435                 :          1 :     size_t m_libspdm_get_csr_request_size = sizeof(spdm_get_csr_request_t) - 1;
+     436                 :            : 
+     437                 :          1 :     response_size = sizeof(response);
+     438                 :          1 :     status = libspdm_get_response_csr(spdm_context,
+     439                 :            :                                       m_libspdm_get_csr_request_size,
+     440                 :            :                                       m_libspdm_get_csr_request,
+     441                 :            :                                       &response_size, response);
+     442                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     443                 :            : 
+     444                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     445                 :          1 :     spdm_response = (void *)response;
+     446                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     447                 :            :                      SPDM_ERROR);
+     448                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     449                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+     450                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     451                 :            : 
+     452                 :          1 :     free(m_libspdm_get_csr_request);
+     453                 :          1 : }
+     454                 :            : 
+     455                 :            : /**
+     456                 :            :  * Test 3: receives a valid GET_CSR request message from Requester with non-null right req_info
+     457                 :            :  * Expected Behavior: produces a valid CSR response message
+     458                 :            :  **/
+     459                 :          1 : void libspdm_test_responder_csr_case3(void **state)
+     460                 :            : {
+     461                 :            :     libspdm_return_t status;
+     462                 :            :     libspdm_test_context_t *spdm_test_context;
+     463                 :            :     libspdm_context_t *spdm_context;
+     464                 :            :     size_t response_size;
+     465                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     466                 :            :     spdm_csr_response_t *spdm_response;
+     467                 :            :     spdm_get_csr_request_t *m_libspdm_get_csr_request;
+     468                 :            :     uint8_t wrong_csr[LIBSPDM_MAX_CSR_SIZE];
+     469                 :          1 :     libspdm_zero_mem(wrong_csr, LIBSPDM_MAX_CSR_SIZE);
+     470                 :            :     uint8_t *csr;
+     471                 :            : 
+     472                 :          1 :     spdm_test_context = *state;
+     473                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     474                 :          1 :     spdm_test_context->case_id = 0x3;
+     475                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     476                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     477                 :            : 
+     478                 :          1 :     spdm_context->connection_info.connection_state =
+     479                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     480                 :          1 :     spdm_context->local_context.capability.flags |=
+     481                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CSR_CAP;
+     482                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     483                 :            :         m_libspdm_use_hash_algo;
+     484                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     485                 :            :         m_libspdm_use_asym_algo;
+     486                 :            : 
+     487                 :          1 :     m_libspdm_get_csr_request = malloc(sizeof(spdm_get_csr_request_t) +
+     488                 :            :                                        req_info_len);
+     489                 :            : 
+     490                 :          1 :     m_libspdm_get_csr_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     491                 :          1 :     m_libspdm_get_csr_request->header.request_response_code = SPDM_GET_CSR;
+     492                 :          1 :     m_libspdm_get_csr_request->header.param1 = 0;
+     493                 :          1 :     m_libspdm_get_csr_request->header.param2 = 0;
+     494                 :            : 
+     495                 :          1 :     m_libspdm_get_csr_request->opaque_data_length = 0;
+     496                 :          1 :     m_libspdm_get_csr_request->requester_info_length = req_info_len;
+     497                 :            : 
+     498                 :          1 :     libspdm_copy_mem(m_libspdm_get_csr_request + 1, req_info_len,
+     499                 :            :                      right_req_info, req_info_len);
+     500                 :            : 
+     501                 :          1 :     size_t m_libspdm_get_csr_request_size = sizeof(spdm_get_csr_request_t) +
+     502                 :            :                                             req_info_len;
+     503                 :            : 
+     504                 :          1 :     response_size = sizeof(response);
+     505                 :          1 :     status = libspdm_get_response_csr(spdm_context,
+     506                 :            :                                       m_libspdm_get_csr_request_size,
+     507                 :            :                                       m_libspdm_get_csr_request,
+     508                 :            :                                       &response_size, response);
+     509                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     510                 :            : 
+     511                 :          1 :     spdm_response = (void *)response;
+     512                 :          1 :     assert_int_equal(response_size, sizeof(spdm_csr_response_t) + spdm_response->csr_length);
+     513                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     514                 :            :                      SPDM_CSR);
+     515                 :            : 
+     516                 :            :     /*check returned CSR not zero */
+     517                 :          1 :     assert_memory_not_equal(spdm_response + 1, wrong_csr, spdm_response->csr_length);
+     518                 :            : 
+     519                 :          1 :     csr = (uint8_t *)(spdm_response + 1);
+     520                 :            :     /*check that returned CSR contains req_info attribute*/
+     521                 :          1 :     assert_true(libspdm_find_buffer(csr, spdm_response->csr_length,
+     522                 :            :                                     right_req_info_string, sizeof(right_req_info_string)));
+     523                 :            : 
+     524                 :            :     /*check that returned CSR contains req_info subject*/
+     525                 :          1 :     assert_true(libspdm_find_buffer(csr, spdm_response->csr_length,
+     526                 :            :                                     req_info_subject, sizeof(req_info_subject)));
+     527                 :            : 
+     528                 :          1 :     free(m_libspdm_get_csr_request);
+     529                 :          1 : }
+     530                 :            : 
+     531                 :            : /**
+     532                 :            :  * Test 4: receives a valid GET_CSR request message from Requester with non-null opaque_data
+     533                 :            :  * Expected Behavior: produces a valid CSR response message
+     534                 :            :  **/
+     535                 :          1 : void libspdm_test_responder_csr_case4(void **state)
+     536                 :            : {
+     537                 :            :     libspdm_return_t status;
+     538                 :            :     libspdm_test_context_t *spdm_test_context;
+     539                 :            :     libspdm_context_t *spdm_context;
+     540                 :            :     size_t response_size;
+     541                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     542                 :            :     spdm_csr_response_t *spdm_response;
+     543                 :            :     spdm_get_csr_request_t *m_libspdm_get_csr_request;
+     544                 :            :     uint8_t wrong_csr[LIBSPDM_MAX_CSR_SIZE];
+     545                 :          1 :     libspdm_zero_mem(wrong_csr, LIBSPDM_MAX_CSR_SIZE);
+     546                 :            : 
+     547                 :          1 :     spdm_test_context = *state;
+     548                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     549                 :          1 :     spdm_test_context->case_id = 0x4;
+     550                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     551                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     552                 :            : 
+     553                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     554                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CSR_CAP;
+     555                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     556                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     557                 :          1 :     spdm_context->connection_info.algorithm.other_params_support =
+     558                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_0;
+     559                 :            : 
+     560                 :          1 :     m_libspdm_get_csr_request = malloc(sizeof(spdm_get_csr_request_t) +
+     561                 :            :                                        sizeof(m_csr_opaque_data));
+     562                 :            : 
+     563                 :          1 :     m_libspdm_get_csr_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     564                 :          1 :     m_libspdm_get_csr_request->header.request_response_code = SPDM_GET_CSR;
+     565                 :          1 :     m_libspdm_get_csr_request->header.param1 = 0;
+     566                 :          1 :     m_libspdm_get_csr_request->header.param2 = 0;
+     567                 :            : 
+     568                 :          1 :     m_libspdm_get_csr_request->opaque_data_length = sizeof(m_csr_opaque_data);
+     569                 :          1 :     m_libspdm_get_csr_request->requester_info_length = 0;
+     570                 :            : 
+     571                 :          1 :     libspdm_copy_mem(m_libspdm_get_csr_request + 1, sizeof(m_csr_opaque_data),
+     572                 :            :                      m_csr_opaque_data, sizeof(m_csr_opaque_data));
+     573                 :            : 
+     574                 :          1 :     size_t m_libspdm_get_csr_request_size = sizeof(spdm_get_csr_request_t) +
+     575                 :            :                                             sizeof(m_csr_opaque_data);
+     576                 :            : 
+     577                 :          1 :     response_size = sizeof(response);
+     578                 :          1 :     status = libspdm_get_response_csr(spdm_context,
+     579                 :            :                                       m_libspdm_get_csr_request_size,
+     580                 :            :                                       m_libspdm_get_csr_request,
+     581                 :            :                                       &response_size, response);
+     582                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     583                 :            : 
+     584                 :          1 :     spdm_response = (void *)response;
+     585                 :          1 :     assert_int_equal(response_size, sizeof(spdm_csr_response_t) + spdm_response->csr_length);
+     586                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_CSR);
+     587                 :            : 
+     588                 :            :     /*check returned CSR not zero */
+     589                 :          1 :     assert_memory_not_equal(spdm_response + 1, wrong_csr, spdm_response->csr_length);
+     590                 :            : 
+     591                 :          1 :     free(m_libspdm_get_csr_request);
+     592                 :          1 : }
+     593                 :            : 
+     594                 :            : /**
+     595                 :            :  * Test 5: receives a valid GET_CSR request message from Requester with non-null wrong req_info
+     596                 :            :  * Expected Behavior: generate an ERROR_RESPONSE with code SPDM_ERROR_CODE_INVALID_REQUEST
+     597                 :            :  **/
+     598                 :          1 : void libspdm_test_responder_csr_case5(void **state)
+     599                 :            : {
+     600                 :            :     libspdm_return_t status;
+     601                 :            :     libspdm_test_context_t *spdm_test_context;
+     602                 :            :     libspdm_context_t *spdm_context;
+     603                 :            :     size_t response_size;
+     604                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     605                 :            :     spdm_csr_response_t *spdm_response;
+     606                 :            :     spdm_get_csr_request_t *m_libspdm_get_csr_request;
+     607                 :            :     uint8_t wrong_csr[LIBSPDM_MAX_CSR_SIZE];
+     608                 :          1 :     libspdm_zero_mem(wrong_csr, LIBSPDM_MAX_CSR_SIZE);
+     609                 :            : 
+     610                 :          1 :     spdm_test_context = *state;
+     611                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     612                 :          1 :     spdm_test_context->case_id = 0x5;
+     613                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     614                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     615                 :            : 
+     616                 :          1 :     spdm_context->connection_info.connection_state =
+     617                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     618                 :          1 :     spdm_context->local_context.capability.flags |=
+     619                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CSR_CAP;
+     620                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     621                 :            :         m_libspdm_use_hash_algo;
+     622                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     623                 :            :         m_libspdm_use_asym_algo;
+     624                 :            : 
+     625                 :          1 :     m_libspdm_get_csr_request = malloc(sizeof(spdm_get_csr_request_t) +
+     626                 :            :                                        req_info_len);
+     627                 :            : 
+     628                 :          1 :     m_libspdm_get_csr_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     629                 :          1 :     m_libspdm_get_csr_request->header.request_response_code = SPDM_GET_CSR;
+     630                 :          1 :     m_libspdm_get_csr_request->header.param1 = 0;
+     631                 :          1 :     m_libspdm_get_csr_request->header.param2 = 0;
+     632                 :            : 
+     633                 :          1 :     m_libspdm_get_csr_request->opaque_data_length = 0;
+     634                 :          1 :     m_libspdm_get_csr_request->requester_info_length = req_info_len;
+     635                 :            : 
+     636                 :          1 :     libspdm_copy_mem(m_libspdm_get_csr_request + 1, req_info_len,
+     637                 :            :                      wrong_req_info, req_info_len);
+     638                 :            : 
+     639                 :          1 :     size_t m_libspdm_get_csr_request_size = sizeof(spdm_get_csr_request_t) +
+     640                 :            :                                             req_info_len;
+     641                 :            : 
+     642                 :          1 :     response_size = sizeof(response);
+     643                 :          1 :     status = libspdm_get_response_csr(spdm_context,
+     644                 :            :                                       m_libspdm_get_csr_request_size,
+     645                 :            :                                       m_libspdm_get_csr_request,
+     646                 :            :                                       &response_size, response);
+     647                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     648                 :            : 
+     649                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     650                 :          1 :     spdm_response = (void *)response;
+     651                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     652                 :            :                      SPDM_ERROR);
+     653                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     654                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+     655                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     656                 :            : 
+     657                 :          1 :     free(m_libspdm_get_csr_request);
+     658                 :          1 : }
+     659                 :            : 
+     660                 :            : /**
+     661                 :            :  * Test 6: receives a valid GET_CSR request message from Requester with need_reset
+     662                 :            :  * Expected Behavior: the first get_csr: responder return need reset;
+     663                 :            :  *                    the second get_csr after device reset: get the cached valid csr;
+     664                 :            :  **/
+     665                 :          1 : void libspdm_test_responder_csr_case6(void **state)
+     666                 :            : {
+     667                 :            :     libspdm_return_t status;
+     668                 :            :     libspdm_test_context_t *spdm_test_context;
+     669                 :            :     libspdm_context_t *spdm_context;
+     670                 :            :     size_t response_size;
+     671                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     672                 :            :     spdm_csr_response_t *spdm_response;
+     673                 :            :     spdm_get_csr_request_t *m_libspdm_get_csr_request;
+     674                 :            :     uint8_t cached_csr[LIBSPDM_MAX_CSR_SIZE];
+     675                 :          1 :     libspdm_zero_mem(cached_csr, LIBSPDM_MAX_CSR_SIZE);
+     676                 :            : 
+     677                 :            :     uint8_t *csr_pointer;
+     678                 :            :     size_t csr_len;
+     679                 :            : 
+     680         [ -  + ]:          1 :     if (!libspdm_test_read_cached_csr(&csr_pointer, &csr_len)) {
+     681                 :          0 :         assert_false(true);
+     682                 :            :     }
+     683                 :            : 
+     684                 :          1 :     libspdm_copy_mem(cached_csr, LIBSPDM_MAX_CSR_SIZE, csr_pointer, csr_len);
+     685                 :          1 :     free(csr_pointer);
+     686                 :            : 
+     687                 :          1 :     spdm_test_context = *state;
+     688                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     689                 :          1 :     spdm_test_context->case_id = 0x6;
+     690                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     691                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     692                 :            : 
+     693                 :          1 :     spdm_context->connection_info.connection_state =
+     694                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     695                 :          1 :     spdm_context->local_context.capability.flags |=
+     696                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CSR_CAP;
+     697                 :            : 
+     698                 :            :     /*set responder need reset*/
+     699                 :          1 :     spdm_context->local_context.capability.flags |=
+     700                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_INSTALL_RESET_CAP;
+     701                 :            : 
+     702                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     703                 :            :         m_libspdm_use_hash_algo;
+     704                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     705                 :            :         m_libspdm_use_asym_algo;
+     706                 :            : 
+     707                 :            :     /*set csr before reset*/
+     708                 :          1 :     assert_true(libspdm_set_csr_before_reset());
+     709                 :            : 
+     710                 :          1 :     m_libspdm_get_csr_request = malloc(sizeof(spdm_get_csr_request_t) +
+     711                 :            :                                        req_info_len);
+     712                 :            : 
+     713                 :          1 :     m_libspdm_get_csr_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     714                 :          1 :     m_libspdm_get_csr_request->header.request_response_code = SPDM_GET_CSR;
+     715                 :          1 :     m_libspdm_get_csr_request->header.param1 = 0;
+     716                 :          1 :     m_libspdm_get_csr_request->header.param2 = 0;
+     717                 :            : 
+     718                 :          1 :     m_libspdm_get_csr_request->opaque_data_length = 0;
+     719                 :          1 :     m_libspdm_get_csr_request->requester_info_length = req_info_len;
+     720                 :            : 
+     721                 :          1 :     libspdm_copy_mem(m_libspdm_get_csr_request + 1, req_info_len,
+     722                 :            :                      right_req_info, req_info_len);
+     723                 :            : 
+     724                 :          1 :     size_t m_libspdm_get_csr_request_size = sizeof(spdm_get_csr_request_t) +
+     725                 :            :                                             req_info_len;
+     726                 :            : 
+     727                 :          1 :     response_size = sizeof(response);
+     728                 :            : 
+     729                 :          1 :     status = libspdm_get_response_csr(spdm_context,
+     730                 :            :                                       m_libspdm_get_csr_request_size,
+     731                 :            :                                       m_libspdm_get_csr_request,
+     732                 :            :                                       &response_size, response);
+     733                 :            :     /*first get_csr: the responder need reset*/
+     734                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     735                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     736                 :          1 :     spdm_response = (void *)response;
+     737                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     738                 :            :                      SPDM_ERROR);
+     739                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     740                 :            :                      SPDM_ERROR_CODE_RESET_REQUIRED);
+     741                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     742                 :            : 
+     743                 :            :     /*set csr after reset*/
+     744                 :          1 :     assert_true(libspdm_set_csr_after_reset());
+     745                 :            : 
+     746                 :          1 :     m_libspdm_get_csr_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     747                 :          1 :     m_libspdm_get_csr_request->header.request_response_code = SPDM_GET_CSR;
+     748                 :          1 :     m_libspdm_get_csr_request->header.param1 = 0;
+     749                 :          1 :     m_libspdm_get_csr_request->header.param2 = 0;
+     750                 :            : 
+     751                 :          1 :     m_libspdm_get_csr_request->opaque_data_length = 0;
+     752                 :          1 :     m_libspdm_get_csr_request->requester_info_length = req_info_len;
+     753                 :          1 :     libspdm_copy_mem(m_libspdm_get_csr_request + 1, req_info_len,
+     754                 :            :                      right_req_info, req_info_len);
+     755                 :            : 
+     756                 :          1 :     response_size = sizeof(response);
+     757                 :          1 :     status = libspdm_get_response_csr(spdm_context,
+     758                 :            :                                       m_libspdm_get_csr_request_size,
+     759                 :            :                                       m_libspdm_get_csr_request,
+     760                 :            :                                       &response_size, response);
+     761                 :            :     /*second get_csr after device reset: get the responder cached csr*/
+     762                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     763                 :            : 
+     764                 :          1 :     spdm_response = (void *)response;
+     765                 :          1 :     assert_int_equal(response_size, sizeof(spdm_csr_response_t) + spdm_response->csr_length);
+     766                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     767                 :            :                      SPDM_CSR);
+     768                 :            : 
+     769                 :            :     /*check returned CSR is equal the cached CSR */
+     770                 :          1 :     assert_memory_equal(spdm_response + 1, cached_csr, spdm_response->csr_length);
+     771                 :            : 
+     772                 :            :     /*clear cached req_info*/
+     773                 :          1 :     libspdm_test_clear_cached_last_request();
+     774                 :          1 :     free(m_libspdm_get_csr_request);
+     775                 :          1 : }
+     776                 :            : 
+     777                 :            : /**
+     778                 :            :  * Test 7: receives a valid GET_CSR request message from Requester with non-null right req_info and opaque_data
+     779                 :            :  * Expected Behavior: produces a valid CSR response message
+     780                 :            :  **/
+     781                 :          1 : void libspdm_test_responder_csr_case7(void **state)
+     782                 :            : {
+     783                 :            :     libspdm_return_t status;
+     784                 :            :     libspdm_test_context_t *spdm_test_context;
+     785                 :            :     libspdm_context_t *spdm_context;
+     786                 :            :     size_t response_size;
+     787                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     788                 :            :     spdm_csr_response_t *spdm_response;
+     789                 :            :     spdm_get_csr_request_t *libspdm_get_csr_request;
+     790                 :            :     uint8_t wrong_csr[LIBSPDM_MAX_CSR_SIZE];
+     791                 :          1 :     libspdm_zero_mem(wrong_csr, LIBSPDM_MAX_CSR_SIZE);
+     792                 :            :     uint8_t *csr;
+     793                 :            : 
+     794                 :          1 :     spdm_test_context = *state;
+     795                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     796                 :          1 :     spdm_test_context->case_id = 0x7;
+     797                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     798                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     799                 :            : 
+     800                 :          1 :     spdm_context->connection_info.connection_state =
+     801                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     802                 :          1 :     spdm_context->local_context.capability.flags = 0;
+     803                 :          1 :     spdm_context->local_context.capability.flags |=
+     804                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CSR_CAP;
+     805                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     806                 :            :         m_libspdm_use_hash_algo;
+     807                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     808                 :            :         m_libspdm_use_asym_algo;
+     809                 :            : 
+     810                 :          1 :     libspdm_get_csr_request = malloc(sizeof(spdm_get_csr_request_t) +
+     811                 :            :                                      sizeof(m_csr_opaque_data) +
+     812                 :            :                                      req_info_len);
+     813                 :            : 
+     814                 :          1 :     libspdm_get_csr_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     815                 :          1 :     libspdm_get_csr_request->header.request_response_code = SPDM_GET_CSR;
+     816                 :          1 :     libspdm_get_csr_request->header.param1 = 0;
+     817                 :          1 :     libspdm_get_csr_request->header.param2 = 0;
+     818                 :          1 :     libspdm_get_csr_request->opaque_data_length = sizeof(m_csr_opaque_data);
+     819                 :          1 :     libspdm_get_csr_request->requester_info_length = req_info_len;
+     820                 :            : 
+     821                 :          1 :     libspdm_copy_mem(libspdm_get_csr_request + 1, req_info_len,
+     822                 :            :                      right_req_info, req_info_len);
+     823                 :            : 
+     824                 :          1 :     libspdm_copy_mem((uint8_t *)(libspdm_get_csr_request + 1) + req_info_len,
+     825                 :            :                      sizeof(m_csr_opaque_data),
+     826                 :            :                      m_csr_opaque_data, sizeof(m_csr_opaque_data));
+     827                 :            : 
+     828                 :          1 :     size_t libspdm_get_csr_request_size = sizeof(spdm_get_csr_request_t) +
+     829                 :          1 :                                           sizeof(m_csr_opaque_data) +
+     830                 :            :                                           req_info_len;
+     831                 :            : 
+     832                 :          1 :     response_size = sizeof(response);
+     833                 :          1 :     status = libspdm_get_response_csr(spdm_context,
+     834                 :            :                                       libspdm_get_csr_request_size,
+     835                 :            :                                       libspdm_get_csr_request,
+     836                 :            :                                       &response_size, response);
+     837                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     838                 :            : 
+     839                 :          1 :     spdm_response = (void *)response;
+     840                 :          1 :     assert_int_equal(response_size, sizeof(spdm_csr_response_t) + spdm_response->csr_length);
+     841                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     842                 :            :                      SPDM_CSR);
+     843                 :            : 
+     844                 :            :     /*check returned CSR not zero */
+     845                 :          1 :     assert_memory_not_equal(spdm_response + 1, wrong_csr, spdm_response->csr_length);
+     846                 :            : 
+     847                 :          1 :     csr = (uint8_t *)(spdm_response + 1);
+     848                 :          1 :     assert_true(libspdm_find_buffer(csr, spdm_response->csr_length,
+     849                 :            :                                     right_req_info_string, sizeof(right_req_info_string)));
+     850                 :            :     /*check that returned CSR contains req_info subject*/
+     851                 :          1 :     assert_true(libspdm_find_buffer(csr, spdm_response->csr_length,
+     852                 :            :                                     req_info_subject, sizeof(req_info_subject)));
+     853                 :            : 
+     854                 :          1 :     free(libspdm_get_csr_request);
+     855                 :          1 : }
+     856                 :            : 
+     857                 :            : /**
+     858                 :            :  * Test 8: receives a invalid GET_CSR request message from Requester With chaotic req_info and opaque_data
+     859                 :            :  * Expected Behavior: generate an ERROR_RESPONSE with code SPDM_ERROR_CODE_INVALID_REQUEST
+     860                 :            :  **/
+     861                 :          1 : void libspdm_test_responder_csr_case8(void **state)
+     862                 :            : {
+     863                 :            :     libspdm_return_t status;
+     864                 :            :     libspdm_test_context_t *spdm_test_context;
+     865                 :            :     libspdm_context_t *spdm_context;
+     866                 :            :     size_t response_size;
+     867                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     868                 :            :     spdm_csr_response_t *spdm_response;
+     869                 :            :     spdm_get_csr_request_t *libspdm_get_csr_request;
+     870                 :            :     uint8_t wrong_csr[LIBSPDM_MAX_CSR_SIZE];
+     871                 :          1 :     libspdm_zero_mem(wrong_csr, LIBSPDM_MAX_CSR_SIZE);
+     872                 :            : 
+     873                 :          1 :     spdm_test_context = *state;
+     874                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     875                 :          1 :     spdm_test_context->case_id = 0x8;
+     876                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     877                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     878                 :            : 
+     879                 :          1 :     spdm_context->connection_info.connection_state =
+     880                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     881                 :          1 :     spdm_context->local_context.capability.flags = 0;
+     882                 :          1 :     spdm_context->local_context.capability.flags |=
+     883                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CSR_CAP;
+     884                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     885                 :            :         m_libspdm_use_hash_algo;
+     886                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     887                 :            :         m_libspdm_use_asym_algo;
+     888                 :            : 
+     889                 :          1 :     libspdm_get_csr_request = malloc(LIBSPDM_RECEIVER_BUFFER_SIZE);
+     890                 :          1 :     libspdm_get_csr_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     891                 :          1 :     libspdm_get_csr_request->header.request_response_code = SPDM_GET_CSR;
+     892                 :          1 :     libspdm_get_csr_request->header.param1 = 0;
+     893                 :          1 :     libspdm_get_csr_request->header.param2 = 0;
+     894                 :            : 
+     895                 :            :     /* Swap right_req_info and m_csr_opaque_data */
+     896                 :          1 :     libspdm_get_csr_request->opaque_data_length = req_info_len;
+     897                 :          1 :     libspdm_get_csr_request->requester_info_length = sizeof(m_csr_opaque_data);
+     898                 :          1 :     libspdm_copy_mem(libspdm_get_csr_request + 1, sizeof(m_csr_opaque_data),
+     899                 :            :                      m_csr_opaque_data, sizeof(m_csr_opaque_data));
+     900                 :          1 :     libspdm_copy_mem((uint8_t *)(libspdm_get_csr_request + 1) + req_info_len,
+     901                 :            :                      req_info_len,
+     902                 :            :                      right_req_info, req_info_len);
+     903                 :            : 
+     904                 :          1 :     size_t libspdm_get_csr_request_size = sizeof(spdm_get_csr_request_t) +
+     905                 :          1 :                                           sizeof(m_csr_opaque_data) +
+     906                 :            :                                           req_info_len;
+     907                 :            : 
+     908                 :          1 :     response_size = sizeof(response);
+     909                 :          1 :     status = libspdm_get_response_csr(spdm_context,
+     910                 :            :                                       libspdm_get_csr_request_size,
+     911                 :            :                                       libspdm_get_csr_request,
+     912                 :            :                                       &response_size, response);
+     913                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     914                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     915                 :          1 :     spdm_response = (void *)response;
+     916                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     917                 :            :                      SPDM_ERROR);
+     918                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     919                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+     920                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     921                 :          1 :     free(libspdm_get_csr_request);
+     922                 :          1 : }
+     923                 :            : 
+     924                 :            : /**
+     925                 :            :  * Test 9: receives a valid GET_CSR request message from Requester with non-null opaque_data
+     926                 :            :  * the OpaqueDataFmt1 bit is selected in OtherParamsSelection of ALGORITHMS ,
+     927                 :            :  * Expected Behavior: produces a valid CSR response message
+     928                 :            :  **/
+     929                 :          1 : void libspdm_test_responder_csr_case9(void **state)
+     930                 :            : {
+     931                 :            :     libspdm_return_t status;
+     932                 :            :     libspdm_test_context_t *spdm_test_context;
+     933                 :            :     libspdm_context_t *spdm_context;
+     934                 :            :     size_t response_size;
+     935                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     936                 :            :     spdm_csr_response_t *spdm_response;
+     937                 :            :     spdm_get_csr_request_t *m_libspdm_get_csr_request;
+     938                 :            :     uint8_t wrong_csr[LIBSPDM_MAX_CSR_SIZE];
+     939                 :          1 :     libspdm_zero_mem(wrong_csr, LIBSPDM_MAX_CSR_SIZE);
+     940                 :            :     spdm_general_opaque_data_table_header_t
+     941                 :            :     *spdm_general_opaque_data_table_header;
+     942                 :            :     opaque_element_table_header_t
+     943                 :            :     *opaque_element_table_header;
+     944                 :            :     uint8_t *ptr;
+     945                 :            :     size_t opaque_data_size;
+     946                 :            :     uint8_t element_num;
+     947                 :            :     uint8_t element_index;
+     948                 :            :     size_t current_element_len;
+     949                 :            :     uint16_t opaque_element_data_len;
+     950                 :            : 
+     951                 :          1 :     spdm_test_context = *state;
+     952                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     953                 :          1 :     spdm_test_context->case_id = 0x9;
+     954                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     955                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     956                 :            : 
+     957                 :          1 :     spdm_context->connection_info.connection_state =
+     958                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     959                 :          1 :     spdm_context->local_context.capability.flags |=
+     960                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CSR_CAP;
+     961                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     962                 :            :         m_libspdm_use_hash_algo;
+     963                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     964                 :            :         m_libspdm_use_asym_algo;
+     965                 :          1 :     spdm_context->connection_info.algorithm.other_params_support =
+     966                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
+     967                 :            : 
+     968                 :          1 :     m_libspdm_get_csr_request = malloc(sizeof(spdm_get_csr_request_t) + SPDM_MAX_OPAQUE_DATA_SIZE);
+     969                 :            : 
+     970                 :          1 :     m_libspdm_get_csr_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     971                 :          1 :     m_libspdm_get_csr_request->header.request_response_code = SPDM_GET_CSR;
+     972                 :          1 :     m_libspdm_get_csr_request->header.param1 = 0;
+     973                 :          1 :     m_libspdm_get_csr_request->header.param2 = 0;
+     974                 :            : 
+     975                 :          1 :     spdm_general_opaque_data_table_header = (void *)(m_libspdm_get_csr_request + 1);
+     976                 :          1 :     spdm_general_opaque_data_table_header->total_elements = 1;
+     977                 :          1 :     opaque_element_table_header = (void *)(spdm_general_opaque_data_table_header + 1);
+     978                 :            : 
+     979                 :          1 :     element_num = spdm_general_opaque_data_table_header->total_elements;
+     980                 :          1 :     opaque_data_size = sizeof(spdm_general_opaque_data_table_header_t);
+     981                 :            : 
+     982         [ +  + ]:          2 :     for (element_index = 0; element_index < element_num; element_index++) {
+     983                 :          1 :         opaque_element_table_header->id = SPDM_REGISTRY_ID_MAX;
+     984                 :          1 :         opaque_element_table_header->vendor_len = 0;
+     985                 :          1 :         opaque_element_data_len = 8;
+     986                 :            : 
+     987                 :          1 :         ptr = (void *)(opaque_element_table_header + 1);
+     988                 :          1 :         ptr += opaque_element_table_header->vendor_len;
+     989                 :            : 
+     990                 :          1 :         libspdm_copy_mem((uint16_t *)ptr,
+     991                 :            :                          sizeof(opaque_element_data_len),
+     992                 :            :                          &opaque_element_data_len,
+     993                 :            :                          sizeof(opaque_element_data_len));
+     994                 :            : 
+     995                 :          1 :         libspdm_copy_mem(ptr + sizeof(opaque_element_data_len),
+     996                 :            :                          SPDM_MAX_OPAQUE_DATA_SIZE -
+     997                 :            :                          sizeof(opaque_element_table_header_t), "libspdm",
+     998                 :            :                          strlen("libspdm"));
+     999                 :            : 
+    1000                 :          1 :         current_element_len = sizeof(opaque_element_table_header_t) +
+    1001                 :          1 :                               opaque_element_table_header->vendor_len +
+    1002                 :          1 :                               sizeof(opaque_element_data_len) +
+    1003                 :            :                               opaque_element_data_len;
+    1004                 :            : 
+    1005                 :          1 :         current_element_len = (current_element_len + 3) & ~3;
+    1006                 :            : 
+    1007                 :            :         /*move to next element*/
+    1008                 :          1 :         opaque_element_table_header =
+    1009                 :            :             (opaque_element_table_header_t *)
+    1010                 :            :             ((uint8_t *)opaque_element_table_header +
+    1011                 :            :              current_element_len);
+    1012                 :            : 
+    1013                 :          1 :         opaque_data_size += current_element_len;
+    1014                 :            :     }
+    1015                 :            : 
+    1016                 :          1 :     m_libspdm_get_csr_request->opaque_data_length = (uint16_t)opaque_data_size;
+    1017                 :          1 :     m_libspdm_get_csr_request->requester_info_length = 0;
+    1018                 :            : 
+    1019                 :          1 :     size_t m_libspdm_get_csr_request_size = sizeof(spdm_get_csr_request_t) + opaque_data_size;
+    1020                 :            : 
+    1021                 :          1 :     response_size = sizeof(response);
+    1022                 :          1 :     status = libspdm_get_response_csr(spdm_context,
+    1023                 :            :                                       m_libspdm_get_csr_request_size,
+    1024                 :            :                                       m_libspdm_get_csr_request,
+    1025                 :            :                                       &response_size, response);
+    1026                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1027                 :            : 
+    1028                 :          1 :     spdm_response = (void *)response;
+    1029                 :          1 :     assert_int_equal(response_size, sizeof(spdm_csr_response_t) + spdm_response->csr_length);
+    1030                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1031                 :            :                      SPDM_CSR);
+    1032                 :            : 
+    1033                 :            :     /*check returned CSR not zero */
+    1034                 :          1 :     assert_memory_not_equal(spdm_response + 1, wrong_csr, spdm_response->csr_length);
+    1035                 :            : 
+    1036                 :          1 :     free(m_libspdm_get_csr_request);
+    1037                 :          1 : }
+    1038                 :            : 
+    1039                 :            : /**
+    1040                 :            :  * Test 10: receives a invalid GET_CSR request message from Requester with non-null alignPadding in opaque_data is not zero
+    1041                 :            :  * the OpaqueDataFmt1 bit is selected in OtherParamsSelection of ALGORITHMS
+    1042                 :            :  * Expected Behavior: generate an ERROR_RESPONSE with code SPDM_ERROR_CODE_INVALID_REQUEST
+    1043                 :            :  **/
+    1044                 :          1 : void libspdm_test_responder_csr_case10(void **state)
+    1045                 :            : {
+    1046                 :            :     libspdm_return_t status;
+    1047                 :            :     libspdm_test_context_t *spdm_test_context;
+    1048                 :            :     libspdm_context_t *spdm_context;
+    1049                 :            :     size_t response_size;
+    1050                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1051                 :            :     spdm_csr_response_t *spdm_response;
+    1052                 :            :     spdm_get_csr_request_t *m_libspdm_get_csr_request;
+    1053                 :            :     uint8_t wrong_csr[LIBSPDM_MAX_CSR_SIZE];
+    1054                 :          1 :     libspdm_zero_mem(wrong_csr, LIBSPDM_MAX_CSR_SIZE);
+    1055                 :            :     spdm_general_opaque_data_table_header_t
+    1056                 :            :     *spdm_general_opaque_data_table_header;
+    1057                 :            :     opaque_element_table_header_t
+    1058                 :            :     *opaque_element_table_header;
+    1059                 :            :     uint8_t *ptr;
+    1060                 :            :     size_t opaque_data_size;
+    1061                 :            :     uint8_t element_num;
+    1062                 :            :     uint8_t element_index;
+    1063                 :            :     size_t current_element_len;
+    1064                 :            :     uint16_t opaque_element_data_len;
+    1065                 :            : 
+    1066                 :          1 :     spdm_test_context = *state;
+    1067                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1068                 :          1 :     spdm_test_context->case_id = 0xA;
+    1069                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    1070                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1071                 :            : 
+    1072                 :          1 :     spdm_context->connection_info.connection_state =
+    1073                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1074                 :          1 :     spdm_context->local_context.capability.flags |=
+    1075                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CSR_CAP;
+    1076                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1077                 :            :         m_libspdm_use_hash_algo;
+    1078                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1079                 :            :         m_libspdm_use_asym_algo;
+    1080                 :          1 :     spdm_context->connection_info.algorithm.other_params_support =
+    1081                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
+    1082                 :            : 
+    1083                 :          1 :     m_libspdm_get_csr_request = malloc(sizeof(spdm_get_csr_request_t) + SPDM_MAX_OPAQUE_DATA_SIZE);
+    1084                 :            : 
+    1085                 :          1 :     m_libspdm_get_csr_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+    1086                 :          1 :     m_libspdm_get_csr_request->header.request_response_code = SPDM_GET_CSR;
+    1087                 :          1 :     m_libspdm_get_csr_request->header.param1 = 0;
+    1088                 :          1 :     m_libspdm_get_csr_request->header.param2 = 0;
+    1089                 :            : 
+    1090                 :          1 :     spdm_general_opaque_data_table_header = (void *)(m_libspdm_get_csr_request + 1);
+    1091                 :          1 :     spdm_general_opaque_data_table_header->total_elements = 1;
+    1092                 :          1 :     opaque_element_table_header = (void *)(spdm_general_opaque_data_table_header + 1);
+    1093                 :            : 
+    1094                 :          1 :     element_num = spdm_general_opaque_data_table_header->total_elements;
+    1095                 :          1 :     opaque_data_size = sizeof(spdm_general_opaque_data_table_header_t);
+    1096                 :            : 
+    1097         [ +  + ]:          2 :     for (element_index = 0; element_index < element_num; element_index++) {
+    1098                 :          1 :         opaque_element_table_header->id = SPDM_REGISTRY_ID_MAX;
+    1099                 :          1 :         opaque_element_table_header->vendor_len = 0;
+    1100                 :          1 :         opaque_element_data_len = (uint16_t)strlen("libspdm");
+    1101                 :            : 
+    1102                 :          1 :         ptr = (void *)(opaque_element_table_header + 1);
+    1103                 :          1 :         ptr += opaque_element_table_header->vendor_len;
+    1104                 :            : 
+    1105                 :          1 :         libspdm_copy_mem((uint16_t *)ptr,
+    1106                 :            :                          sizeof(opaque_element_data_len),
+    1107                 :            :                          &opaque_element_data_len,
+    1108                 :            :                          sizeof(opaque_element_data_len));
+    1109                 :            : 
+    1110                 :          1 :         libspdm_copy_mem(ptr + sizeof(opaque_element_data_len),
+    1111                 :            :                          SPDM_MAX_OPAQUE_DATA_SIZE -
+    1112                 :            :                          sizeof(opaque_element_table_header_t), "libspdm",
+    1113                 :            :                          strlen("libspdm"));
+    1114                 :            : 
+    1115                 :          1 :         current_element_len = sizeof(opaque_element_table_header_t) +
+    1116                 :          1 :                               opaque_element_table_header->vendor_len +
+    1117                 :          1 :                               sizeof(opaque_element_data_len) +
+    1118                 :            :                               opaque_element_data_len;
+    1119                 :            : 
+    1120                 :          1 :         *(uint8_t *)((size_t)(opaque_element_table_header) + current_element_len) = 0xFF;
+    1121                 :            : 
+    1122                 :          1 :         current_element_len += 1;
+    1123                 :          1 :         current_element_len = (current_element_len + 3) & ~3;
+    1124                 :            : 
+    1125                 :            :         /*move to next element*/
+    1126                 :          1 :         opaque_element_table_header =
+    1127                 :            :             (opaque_element_table_header_t *)
+    1128                 :            :             ((uint8_t *)opaque_element_table_header +
+    1129                 :            :              current_element_len);
+    1130                 :            : 
+    1131                 :          1 :         opaque_data_size += current_element_len;
+    1132                 :            :     }
+    1133                 :            : 
+    1134                 :          1 :     m_libspdm_get_csr_request->opaque_data_length = (uint16_t)opaque_data_size;
+    1135                 :          1 :     m_libspdm_get_csr_request->requester_info_length = 0;
+    1136                 :            : 
+    1137                 :          1 :     size_t m_libspdm_get_csr_request_size = sizeof(spdm_get_csr_request_t) + opaque_data_size;
+    1138                 :            : 
+    1139                 :          1 :     response_size = sizeof(response);
+    1140                 :          1 :     status = libspdm_get_response_csr(spdm_context,
+    1141                 :            :                                       m_libspdm_get_csr_request_size,
+    1142                 :            :                                       m_libspdm_get_csr_request,
+    1143                 :            :                                       &response_size, response);
+    1144                 :            : 
+    1145                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1146                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1147                 :          1 :     spdm_response = (void *)response;
+    1148                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1149                 :            :                      SPDM_ERROR);
+    1150                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1151                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+    1152                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1153                 :            : 
+    1154                 :          1 :     free(m_libspdm_get_csr_request);
+    1155                 :          1 : }
+    1156                 :            : 
+    1157                 :            : /**
+    1158                 :            :  * Test 11: receives a valid GET_CSR request message from Requester
+    1159                 :            :  * Expected Behavior: produces a valid CSR response message with alias_cert mode
+    1160                 :            :  **/
+    1161                 :          1 : void libspdm_test_responder_csr_case11(void **state)
+    1162                 :            : {
+    1163                 :            :     libspdm_return_t status;
+    1164                 :            :     libspdm_test_context_t *spdm_test_context;
+    1165                 :            :     libspdm_context_t *spdm_context;
+    1166                 :            :     size_t response_size;
+    1167                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1168                 :            :     spdm_csr_response_t *spdm_response;
+    1169                 :            :     spdm_get_csr_request_t *m_libspdm_get_csr_request;
+    1170                 :            :     uint8_t wrong_csr[LIBSPDM_MAX_CSR_SIZE];
+    1171                 :            :     bool result;
+    1172                 :            :     bool is_device_cert_model;
+    1173                 :            : 
+    1174                 :          1 :     libspdm_zero_mem(wrong_csr, LIBSPDM_MAX_CSR_SIZE);
+    1175                 :            : 
+    1176                 :          1 :     spdm_test_context = *state;
+    1177                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1178                 :          1 :     spdm_test_context->case_id = 0xB;
+    1179                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    1180                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1181                 :            : 
+    1182                 :          1 :     spdm_context->connection_info.connection_state =
+    1183                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1184                 :          1 :     spdm_context->local_context.capability.flags |=
+    1185                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CSR_CAP;
+    1186                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1187                 :            :         m_libspdm_use_hash_algo;
+    1188                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1189                 :            :         m_libspdm_use_asym_algo;
+    1190                 :            : 
+    1191                 :            :     /*set alias cert mode*/
+    1192                 :          1 :     spdm_context->local_context.capability.flags |=
+    1193                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ALIAS_CERT_CAP;
+    1194                 :          1 :     is_device_cert_model = false;
+    1195                 :            : 
+    1196                 :          1 :     m_libspdm_get_csr_request = malloc(sizeof(spdm_get_csr_request_t));
+    1197                 :            : 
+    1198                 :          1 :     m_libspdm_get_csr_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+    1199                 :          1 :     m_libspdm_get_csr_request->header.request_response_code = SPDM_GET_CSR;
+    1200                 :          1 :     m_libspdm_get_csr_request->header.param1 = 0;
+    1201                 :          1 :     m_libspdm_get_csr_request->header.param2 = 0;
+    1202                 :            : 
+    1203                 :          1 :     m_libspdm_get_csr_request->opaque_data_length = 0;
+    1204                 :          1 :     m_libspdm_get_csr_request->requester_info_length = 0;
+    1205                 :            : 
+    1206                 :          1 :     size_t m_libspdm_get_csr_request_size = sizeof(spdm_get_csr_request_t);
+    1207                 :            : 
+    1208                 :          1 :     response_size = sizeof(response);
+    1209                 :          1 :     status = libspdm_get_response_csr(spdm_context,
+    1210                 :            :                                       m_libspdm_get_csr_request_size,
+    1211                 :            :                                       m_libspdm_get_csr_request,
+    1212                 :            :                                       &response_size, response);
+    1213                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1214                 :            : 
+    1215                 :          1 :     spdm_response = (void *)response;
+    1216                 :          1 :     assert_int_equal(response_size, sizeof(spdm_csr_response_t) + spdm_response->csr_length);
+    1217                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1218                 :            :                      SPDM_CSR);
+    1219                 :            : 
+    1220                 :            :     /*check returned CSR not zero */
+    1221                 :          1 :     assert_memory_not_equal(spdm_response + 1, wrong_csr, spdm_response->csr_length);
+    1222                 :            : 
+    1223                 :            :     /*check the resulting CSR shall be for a Device Certificate CA.*/
+    1224                 :          1 :     result = libspdm_check_csr_basic_constraints((uint8_t *)(spdm_response + 1),
+    1225                 :          1 :                                                  spdm_response->csr_length, is_device_cert_model);
+    1226                 :          1 :     assert_true(result);
+    1227                 :            : 
+    1228                 :          1 :     free(m_libspdm_get_csr_request);
+    1229                 :          1 : }
+    1230                 :            : 
+    1231                 :            : /**
+    1232                 :            :  * Test 12: receives a valid GET_CSR request message from Requester with need_reset
+    1233                 :            :  * Expected Behavior: the first get_csr: responder return need reset;
+    1234                 :            :  *                    the second get_csr without device reset: responder return need reset;
+    1235                 :            :  **/
+    1236                 :          1 : void libspdm_test_responder_csr_case12(void **state)
+    1237                 :            : {
+    1238                 :            :     libspdm_return_t status;
+    1239                 :            :     libspdm_test_context_t *spdm_test_context;
+    1240                 :            :     libspdm_context_t *spdm_context;
+    1241                 :            :     size_t response_size;
+    1242                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1243                 :            :     spdm_csr_response_t *spdm_response;
+    1244                 :            :     spdm_get_csr_request_t *m_libspdm_get_csr_request;
+    1245                 :            :     uint8_t cached_csr[LIBSPDM_MAX_CSR_SIZE];
+    1246                 :          1 :     libspdm_zero_mem(cached_csr, LIBSPDM_MAX_CSR_SIZE);
+    1247                 :            : 
+    1248                 :            :     uint8_t *csr_pointer;
+    1249                 :            :     size_t csr_len;
+    1250                 :            : 
+    1251         [ -  + ]:          1 :     if (!libspdm_test_read_cached_csr(&csr_pointer, &csr_len)) {
+    1252                 :          0 :         assert_false(true);
+    1253                 :            :     }
+    1254                 :            : 
+    1255                 :          1 :     libspdm_copy_mem(cached_csr, LIBSPDM_MAX_CSR_SIZE, csr_pointer, csr_len);
+    1256                 :          1 :     free(csr_pointer);
+    1257                 :            : 
+    1258                 :          1 :     spdm_test_context = *state;
+    1259                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1260                 :          1 :     spdm_test_context->case_id = 0xC;
+    1261                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    1262                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1263                 :            : 
+    1264                 :          1 :     spdm_context->connection_info.connection_state =
+    1265                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1266                 :          1 :     spdm_context->local_context.capability.flags |=
+    1267                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CSR_CAP;
+    1268                 :            : 
+    1269                 :            :     /*set responder need reset*/
+    1270                 :          1 :     spdm_context->local_context.capability.flags |=
+    1271                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_INSTALL_RESET_CAP;
+    1272                 :            : 
+    1273                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1274                 :            :         m_libspdm_use_hash_algo;
+    1275                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1276                 :            :         m_libspdm_use_asym_algo;
+    1277                 :            : 
+    1278                 :            :     /*set csr before reset*/
+    1279                 :          1 :     assert_true(libspdm_set_csr_before_reset());
+    1280                 :            : 
+    1281                 :          1 :     m_libspdm_get_csr_request = malloc(sizeof(spdm_get_csr_request_t) +
+    1282                 :            :                                        req_info_len);
+    1283                 :            : 
+    1284                 :          1 :     m_libspdm_get_csr_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+    1285                 :          1 :     m_libspdm_get_csr_request->header.request_response_code = SPDM_GET_CSR;
+    1286                 :          1 :     m_libspdm_get_csr_request->header.param1 = 0;
+    1287                 :          1 :     m_libspdm_get_csr_request->header.param2 = 0;
+    1288                 :            : 
+    1289                 :          1 :     m_libspdm_get_csr_request->opaque_data_length = 0;
+    1290                 :          1 :     m_libspdm_get_csr_request->requester_info_length = req_info_len;
+    1291                 :            : 
+    1292                 :          1 :     libspdm_copy_mem(m_libspdm_get_csr_request + 1, req_info_len,
+    1293                 :            :                      right_req_info, req_info_len);
+    1294                 :            : 
+    1295                 :          1 :     size_t m_libspdm_get_csr_request_size = sizeof(spdm_get_csr_request_t) +
+    1296                 :            :                                             req_info_len;
+    1297                 :            : 
+    1298                 :          1 :     response_size = sizeof(response);
+    1299                 :            : 
+    1300                 :          1 :     status = libspdm_get_response_csr(spdm_context,
+    1301                 :            :                                       m_libspdm_get_csr_request_size,
+    1302                 :            :                                       m_libspdm_get_csr_request,
+    1303                 :            :                                       &response_size, response);
+    1304                 :            :     /*first get_csr: the responder need reset*/
+    1305                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1306                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1307                 :          1 :     spdm_response = (void *)response;
+    1308                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1309                 :            :                      SPDM_ERROR);
+    1310                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1311                 :            :                      SPDM_ERROR_CODE_RESET_REQUIRED);
+    1312                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1313                 :            : 
+    1314                 :          1 :     m_libspdm_get_csr_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+    1315                 :          1 :     m_libspdm_get_csr_request->header.request_response_code = SPDM_GET_CSR;
+    1316                 :          1 :     m_libspdm_get_csr_request->header.param1 = 0;
+    1317                 :          1 :     m_libspdm_get_csr_request->header.param2 = 0;
+    1318                 :            : 
+    1319                 :          1 :     m_libspdm_get_csr_request->opaque_data_length = 0;
+    1320                 :          1 :     m_libspdm_get_csr_request->requester_info_length = req_info_len;
+    1321                 :          1 :     libspdm_copy_mem(m_libspdm_get_csr_request + 1, req_info_len,
+    1322                 :            :                      right_req_info, req_info_len);
+    1323                 :            : 
+    1324                 :          1 :     response_size = sizeof(response);
+    1325                 :            : 
+    1326                 :          1 :     status = libspdm_get_response_csr(spdm_context,
+    1327                 :            :                                       m_libspdm_get_csr_request_size,
+    1328                 :            :                                       m_libspdm_get_csr_request,
+    1329                 :            :                                       &response_size, response);
+    1330                 :            :     /*second get_csr without device reset: get the responder cached csr*/
+    1331                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1332                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1333                 :          1 :     spdm_response = (void *)response;
+    1334                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1335                 :            :                      SPDM_ERROR);
+    1336                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1337                 :            :                      SPDM_ERROR_CODE_RESET_REQUIRED);
+    1338                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1339                 :            : 
+    1340                 :            :     /*clear cached req_info*/
+    1341                 :          1 :     libspdm_test_clear_cached_last_request();
+    1342                 :          1 :     free(m_libspdm_get_csr_request);
+    1343                 :            : 
+    1344                 :            :     /*set csr to the origin state*/
+    1345                 :          1 :     assert_true(libspdm_set_csr_after_reset());
+    1346                 :          1 : }
+    1347                 :            : 
+    1348                 :            : /**
+    1349                 :            :  * Test 13: receives a valid GET_CSR request message from Requester with need_reset for SPDM 1.3
+    1350                 :            :  * Expected Behavior: the first get_csr with csr_tracking_tag 0: responder return need reset and available csr_tracking_tag;
+    1351                 :            :  *                    After reset, the second get_csr with returned available csr_tracking_tag: after device reset: get the cached valid csr;
+    1352                 :            :  **/
+    1353                 :          1 : void libspdm_test_responder_csr_case13(void **state)
+    1354                 :            : {
+    1355                 :            :     libspdm_return_t status;
+    1356                 :            :     libspdm_test_context_t *spdm_test_context;
+    1357                 :            :     libspdm_context_t *spdm_context;
+    1358                 :            :     size_t response_size;
+    1359                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1360                 :            :     spdm_csr_response_t *spdm_response;
+    1361                 :            :     spdm_get_csr_request_t *m_libspdm_get_csr_request;
+    1362                 :            :     uint8_t cached_csr[LIBSPDM_MAX_CSR_SIZE];
+    1363                 :          1 :     libspdm_zero_mem(cached_csr, LIBSPDM_MAX_CSR_SIZE);
+    1364                 :            : 
+    1365                 :            :     uint8_t *csr_pointer;
+    1366                 :            :     size_t csr_len;
+    1367                 :            :     uint8_t csr_tracking_tag;
+    1368                 :            : 
+    1369                 :          1 :     csr_tracking_tag = 0;
+    1370                 :            : 
+    1371         [ -  + ]:          1 :     if (!libspdm_test_read_cached_csr(&csr_pointer, &csr_len)) {
+    1372                 :          0 :         assert_false(true);
+    1373                 :            :     }
+    1374                 :            : 
+    1375                 :          1 :     libspdm_copy_mem(cached_csr, LIBSPDM_MAX_CSR_SIZE, csr_pointer, csr_len);
+    1376                 :          1 :     free(csr_pointer);
+    1377                 :            : 
+    1378                 :          1 :     spdm_test_context = *state;
+    1379                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1380                 :          1 :     spdm_test_context->case_id = 0xD;
+    1381                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+    1382                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1383                 :            : 
+    1384                 :          1 :     spdm_context->connection_info.connection_state =
+    1385                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1386                 :          1 :     spdm_context->local_context.capability.flags |=
+    1387                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CSR_CAP;
+    1388                 :            : 
+    1389                 :          1 :     spdm_context->connection_info.multi_key_conn_rsp = true;
+    1390                 :            :     /*set responder need reset*/
+    1391                 :          1 :     spdm_context->local_context.capability.flags |=
+    1392                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_INSTALL_RESET_CAP;
+    1393                 :            : 
+    1394                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1395                 :            :         m_libspdm_use_hash_algo;
+    1396                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1397                 :            :         m_libspdm_use_asym_algo;
+    1398                 :            : 
+    1399                 :            :     /*set csr before reset*/
+    1400                 :          1 :     assert_true(libspdm_set_csr_before_reset());
+    1401                 :            : 
+    1402                 :          1 :     m_libspdm_get_csr_request = malloc(sizeof(spdm_get_csr_request_t) +
+    1403                 :            :                                        req_info_len);
+    1404                 :            : 
+    1405                 :          1 :     m_libspdm_get_csr_request->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+    1406                 :          1 :     m_libspdm_get_csr_request->header.request_response_code = SPDM_GET_CSR;
+    1407                 :          1 :     m_libspdm_get_csr_request->header.param1 = 1;
+    1408                 :          1 :     m_libspdm_get_csr_request->header.param2 =
+    1409                 :          1 :         SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT |
+    1410                 :          1 :         (csr_tracking_tag << SPDM_GET_CSR_REQUEST_ATTRIBUTES_CSR_TRACKING_TAG_OFFSET);
+    1411                 :            : 
+    1412                 :          1 :     m_libspdm_get_csr_request->opaque_data_length = 0;
+    1413                 :          1 :     m_libspdm_get_csr_request->requester_info_length = req_info_len;
+    1414                 :            : 
+    1415                 :          1 :     libspdm_copy_mem(m_libspdm_get_csr_request + 1, req_info_len,
+    1416                 :            :                      right_req_info, req_info_len);
+    1417                 :            : 
+    1418                 :          1 :     size_t m_libspdm_get_csr_request_size = sizeof(spdm_get_csr_request_t) +
+    1419                 :            :                                             req_info_len;
+    1420                 :            : 
+    1421                 :          1 :     response_size = sizeof(response);
+    1422                 :          1 :     status = libspdm_get_response_csr(spdm_context,
+    1423                 :            :                                       m_libspdm_get_csr_request_size,
+    1424                 :            :                                       m_libspdm_get_csr_request,
+    1425                 :            :                                       &response_size, response);
+    1426                 :            : 
+    1427                 :            :     /*set csr after reset*/
+    1428                 :          1 :     assert_true(libspdm_set_csr_after_reset());
+    1429                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CSR_CAP_EX
+    1430                 :            :     /*first get_csr: the responder need reset*/
+    1431                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1432                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1433                 :          1 :     spdm_response = (void *)response;
+    1434                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1435                 :            :                      SPDM_ERROR);
+    1436                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1437                 :            :                      SPDM_ERROR_CODE_RESET_REQUIRED);
+    1438                 :          1 :     assert_int_equal(spdm_response->header.param2, 1);
+    1439                 :            : 
+    1440                 :          1 :     csr_tracking_tag = spdm_response->header.param2;
+    1441                 :          1 :     m_libspdm_get_csr_request->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+    1442                 :          1 :     m_libspdm_get_csr_request->header.request_response_code = SPDM_GET_CSR;
+    1443                 :          1 :     m_libspdm_get_csr_request->header.param1 = 1;
+    1444                 :          1 :     m_libspdm_get_csr_request->header.param2 =
+    1445                 :          1 :         SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT |
+    1446                 :          1 :         (csr_tracking_tag << SPDM_GET_CSR_REQUEST_ATTRIBUTES_CSR_TRACKING_TAG_OFFSET);
+    1447                 :            : 
+    1448                 :          1 :     m_libspdm_get_csr_request->opaque_data_length = 0;
+    1449                 :          1 :     m_libspdm_get_csr_request->requester_info_length = req_info_len;
+    1450                 :          1 :     libspdm_copy_mem(m_libspdm_get_csr_request + 1, req_info_len,
+    1451                 :            :                      right_req_info, req_info_len);
+    1452                 :            : 
+    1453                 :          1 :     response_size = sizeof(response);
+    1454                 :          1 :     status = libspdm_get_response_csr(spdm_context,
+    1455                 :            :                                       m_libspdm_get_csr_request_size,
+    1456                 :            :                                       m_libspdm_get_csr_request,
+    1457                 :            :                                       &response_size, response);
+    1458                 :            :     /*second get_csr after device reset: get the responder cached csr*/
+    1459                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1460                 :            : 
+    1461                 :          1 :     spdm_response = (void *)response;
+    1462                 :          1 :     assert_int_equal(response_size, sizeof(spdm_csr_response_t) + spdm_response->csr_length);
+    1463                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1464                 :            :                      SPDM_CSR);
+    1465                 :            : 
+    1466                 :            :     /*check returned CSR is equal the cached CSR */
+    1467                 :          1 :     assert_memory_equal(spdm_response + 1, cached_csr, spdm_response->csr_length);
+    1468                 :            : #else
+    1469                 :            :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1470                 :            :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1471                 :            :     spdm_response = (void *)response;
+    1472                 :            :     assert_int_equal(spdm_response->header.request_response_code,
+    1473                 :            :                      SPDM_ERROR);
+    1474                 :            :     assert_int_equal(spdm_response->header.param1,
+    1475                 :            :                      SPDM_ERROR_CODE_UNEXPECTED_REQUEST);
+    1476                 :            :     assert_int_equal(spdm_response->header.param2, 0);
+    1477                 :            : #endif /*LIBSPDM_ENABLE_CAPABILITY_CSR_CAP_EX*/
+    1478                 :            :     /*clear cached req_info*/
+    1479                 :          1 :     libspdm_test_clear_cached_last_request();
+    1480                 :          1 :     free(m_libspdm_get_csr_request);
+    1481                 :          1 : }
+    1482                 :            : 
+    1483                 :            : /**
+    1484                 :            :  * Test 14: receives a valid GET_CSR request message from Requester with need_reset for SPDM 1.3
+    1485                 :            :  * Expected Behavior: the first get_csr with csr_tracking_tag 0: responder return need reset and available csr_tracking_tag;
+    1486                 :            :  *                    Afer reset, then send get_csr with csr_tracking_tag 0 six times: responder return need reset and available csr_tracking_tag;
+    1487                 :            :  *                    Then send get_csr with csr_tracking_tag 0: responder return busy error;
+    1488                 :            :  **/
+    1489                 :          1 : void libspdm_test_responder_csr_case14(void **state)
+    1490                 :            : {
+    1491                 :            :     libspdm_return_t status;
+    1492                 :            :     libspdm_test_context_t *spdm_test_context;
+    1493                 :            :     libspdm_context_t *spdm_context;
+    1494                 :            :     size_t response_size;
+    1495                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1496                 :            :     spdm_csr_response_t *spdm_response;
+    1497                 :            :     spdm_get_csr_request_t *m_libspdm_get_csr_request;
+    1498                 :            :     uint8_t cached_csr[LIBSPDM_MAX_CSR_SIZE];
+    1499                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CSR_CAP_EX
+    1500                 :            :     uint8_t index;
+    1501                 :            : #endif /*LIBSPDM_ENABLE_CAPABILITY_CSR_CAP_EX*/
+    1502                 :          1 :     libspdm_zero_mem(cached_csr, LIBSPDM_MAX_CSR_SIZE);
+    1503                 :            : 
+    1504                 :            :     uint8_t *csr_pointer;
+    1505                 :            :     size_t csr_len;
+    1506                 :            :     uint8_t csr_tracking_tag;
+    1507                 :            : 
+    1508                 :          1 :     csr_tracking_tag = 0;
+    1509                 :            : 
+    1510         [ -  + ]:          1 :     if (!libspdm_test_read_cached_csr(&csr_pointer, &csr_len)) {
+    1511                 :          0 :         assert_false(true);
+    1512                 :            :     }
+    1513                 :            : 
+    1514                 :          1 :     libspdm_copy_mem(cached_csr, LIBSPDM_MAX_CSR_SIZE, csr_pointer, csr_len);
+    1515                 :          1 :     free(csr_pointer);
+    1516                 :            : 
+    1517                 :          1 :     spdm_test_context = *state;
+    1518                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1519                 :          1 :     spdm_test_context->case_id = 0xE;
+    1520                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+    1521                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1522                 :            : 
+    1523                 :          1 :     spdm_context->connection_info.connection_state =
+    1524                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1525                 :          1 :     spdm_context->local_context.capability.flags |=
+    1526                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CSR_CAP;
+    1527                 :            : 
+    1528                 :          1 :     spdm_context->connection_info.multi_key_conn_rsp = true;
+    1529                 :            :     /*set responder need reset*/
+    1530                 :          1 :     spdm_context->local_context.capability.flags |=
+    1531                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_INSTALL_RESET_CAP;
+    1532                 :            : 
+    1533                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1534                 :            :         m_libspdm_use_hash_algo;
+    1535                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1536                 :            :         m_libspdm_use_asym_algo;
+    1537                 :            : 
+    1538                 :            :     /*set csr before reset*/
+    1539                 :          1 :     assert_true(libspdm_set_csr_before_reset());
+    1540                 :            : 
+    1541                 :          1 :     m_libspdm_get_csr_request = malloc(sizeof(spdm_get_csr_request_t) +
+    1542                 :            :                                        req_info_len);
+    1543                 :            : 
+    1544                 :          1 :     m_libspdm_get_csr_request->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+    1545                 :          1 :     m_libspdm_get_csr_request->header.request_response_code = SPDM_GET_CSR;
+    1546                 :          1 :     m_libspdm_get_csr_request->header.param1 = 1;
+    1547                 :          1 :     m_libspdm_get_csr_request->header.param2 =
+    1548                 :          1 :         SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT |
+    1549                 :          1 :         (csr_tracking_tag << SPDM_GET_CSR_REQUEST_ATTRIBUTES_CSR_TRACKING_TAG_OFFSET);
+    1550                 :            : 
+    1551                 :          1 :     m_libspdm_get_csr_request->opaque_data_length = 0;
+    1552                 :          1 :     m_libspdm_get_csr_request->requester_info_length = req_info_len;
+    1553                 :            : 
+    1554                 :          1 :     libspdm_copy_mem(m_libspdm_get_csr_request + 1, req_info_len,
+    1555                 :            :                      right_req_info, req_info_len);
+    1556                 :            : 
+    1557                 :          1 :     size_t m_libspdm_get_csr_request_size = sizeof(spdm_get_csr_request_t) +
+    1558                 :            :                                             req_info_len;
+    1559                 :            : 
+    1560                 :          1 :     response_size = sizeof(response);
+    1561                 :          1 :     status = libspdm_get_response_csr(spdm_context,
+    1562                 :            :                                       m_libspdm_get_csr_request_size,
+    1563                 :            :                                       m_libspdm_get_csr_request,
+    1564                 :            :                                       &response_size, response);
+    1565                 :            : 
+    1566                 :            :     /*set csr after reset*/
+    1567                 :          1 :     assert_true(libspdm_set_csr_after_reset());
+    1568                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CSR_CAP_EX
+    1569                 :            :     /*first get_csr: the responder need reset*/
+    1570                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1571                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1572                 :          1 :     spdm_response = (void *)response;
+    1573                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1574                 :            :                      SPDM_ERROR);
+    1575                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1576                 :            :                      SPDM_ERROR_CODE_RESET_REQUIRED);
+    1577                 :          1 :     assert_int_equal(spdm_response->header.param2, 1);
+    1578                 :            : 
+    1579         [ +  + ]:          7 :     for (index = 1; index < SPDM_MAX_CSR_TRACKING_TAG; index++) {
+    1580                 :          6 :         csr_tracking_tag = 0;
+    1581                 :          6 :         m_libspdm_get_csr_request->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+    1582                 :          6 :         m_libspdm_get_csr_request->header.request_response_code = SPDM_GET_CSR;
+    1583                 :          6 :         m_libspdm_get_csr_request->header.param1 = 1;
+    1584                 :          6 :         m_libspdm_get_csr_request->header.param2 =
+    1585                 :          6 :             SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT |
+    1586                 :          6 :             (csr_tracking_tag << SPDM_GET_CSR_REQUEST_ATTRIBUTES_CSR_TRACKING_TAG_OFFSET);
+    1587                 :            : 
+    1588                 :          6 :         m_libspdm_get_csr_request->opaque_data_length = 0;
+    1589                 :          6 :         m_libspdm_get_csr_request->requester_info_length = req_info_len;
+    1590                 :          6 :         libspdm_copy_mem(m_libspdm_get_csr_request + 1, req_info_len,
+    1591                 :            :                          right_req_info, req_info_len);
+    1592                 :            : 
+    1593                 :          6 :         response_size = sizeof(response);
+    1594                 :          6 :         status = libspdm_get_response_csr(spdm_context,
+    1595                 :            :                                           m_libspdm_get_csr_request_size,
+    1596                 :            :                                           m_libspdm_get_csr_request,
+    1597                 :            :                                           &response_size, response);
+    1598                 :            :         /*second get_csr after device reset: get the responder cached csr*/
+    1599                 :          6 :         assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1600                 :          6 :         assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1601                 :          6 :         spdm_response = (void *)response;
+    1602                 :          6 :         assert_int_equal(spdm_response->header.request_response_code,
+    1603                 :            :                          SPDM_ERROR);
+    1604                 :          6 :         assert_int_equal(spdm_response->header.param1,
+    1605                 :            :                          SPDM_ERROR_CODE_RESET_REQUIRED);
+    1606                 :          6 :         assert_int_equal(spdm_response->header.param2, index + 1);
+    1607                 :            :     }
+    1608                 :            : 
+    1609                 :          1 :     csr_tracking_tag = 0;
+    1610                 :          1 :     m_libspdm_get_csr_request->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+    1611                 :          1 :     m_libspdm_get_csr_request->header.request_response_code = SPDM_GET_CSR;
+    1612                 :          1 :     m_libspdm_get_csr_request->header.param1 = 1;
+    1613                 :          1 :     m_libspdm_get_csr_request->header.param2 =
+    1614                 :          1 :         SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT |
+    1615                 :          1 :         (csr_tracking_tag << SPDM_GET_CSR_REQUEST_ATTRIBUTES_CSR_TRACKING_TAG_OFFSET);
+    1616                 :            : 
+    1617                 :          1 :     m_libspdm_get_csr_request->opaque_data_length = 0;
+    1618                 :          1 :     m_libspdm_get_csr_request->requester_info_length = req_info_len;
+    1619                 :          1 :     libspdm_copy_mem(m_libspdm_get_csr_request + 1, req_info_len,
+    1620                 :            :                      right_req_info, req_info_len);
+    1621                 :            : 
+    1622                 :          1 :     response_size = sizeof(response);
+    1623                 :          1 :     status = libspdm_get_response_csr(spdm_context,
+    1624                 :            :                                       m_libspdm_get_csr_request_size,
+    1625                 :            :                                       m_libspdm_get_csr_request,
+    1626                 :            :                                       &response_size, response);
+    1627                 :            :     /*second get_csr after device reset: get the responder cached csr*/
+    1628                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1629                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1630                 :          1 :     spdm_response = (void *)response;
+    1631                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1632                 :            :                      SPDM_ERROR);
+    1633                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1634                 :            :                      SPDM_ERROR_CODE_BUSY);
+    1635                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1636                 :            : #else
+    1637                 :            :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1638                 :            :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1639                 :            :     spdm_response = (void *)response;
+    1640                 :            :     assert_int_equal(spdm_response->header.request_response_code,
+    1641                 :            :                      SPDM_ERROR);
+    1642                 :            :     assert_int_equal(spdm_response->header.param1,
+    1643                 :            :                      SPDM_ERROR_CODE_UNEXPECTED_REQUEST);
+    1644                 :            :     assert_int_equal(spdm_response->header.param2, 0);
+    1645                 :            : #endif /*LIBSPDM_ENABLE_CAPABILITY_CSR_CAP_EX*/
+    1646                 :            :     /*clear cached req_info*/
+    1647                 :          1 :     libspdm_test_clear_cached_last_request();
+    1648                 :          1 :     free(m_libspdm_get_csr_request);
+    1649                 :          1 : }
+    1650                 :            : 
+    1651                 :            : /**
+    1652                 :            :  * Test 15: receives a valid GET_CSR request message from Requester with need_reset for SPDM 1.3
+    1653                 :            :  * Expected Behavior: the first get_csr with csr_tracking_tag 0: responder return need reset and available csr_tracking_tag;
+    1654                 :            :  *                    Without reset, then send get_csr with unmatched csr_tracking_tag:responder return unexpected error;
+    1655                 :            :  *                    Without reset, then send get_csr with matched csr_tracking_tag:responder return busy error;
+    1656                 :            :  *                    Without reset, then send get_csr with non-0 csr_tracking_tag, and overwrite is set:responder return invalid error;
+    1657                 :            :  *                    After reset, then send get_csr with unmatched csr_tracking_tag:responder return unexpected error;
+    1658                 :            :  *                    After reset, then send get_csr with csr_tracking_tag 0, and overwrite is set:responder return need reset and available csr_tracking_tag;
+    1659                 :            :  **/
+    1660                 :          1 : void libspdm_test_responder_csr_case15(void **state)
+    1661                 :            : {
+    1662                 :            :     libspdm_return_t status;
+    1663                 :            :     libspdm_test_context_t *spdm_test_context;
+    1664                 :            :     libspdm_context_t *spdm_context;
+    1665                 :            :     size_t response_size;
+    1666                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1667                 :            :     spdm_csr_response_t *spdm_response;
+    1668                 :            :     spdm_get_csr_request_t *m_libspdm_get_csr_request;
+    1669                 :            :     uint8_t cached_csr[LIBSPDM_MAX_CSR_SIZE];
+    1670                 :          1 :     libspdm_zero_mem(cached_csr, LIBSPDM_MAX_CSR_SIZE);
+    1671                 :            : 
+    1672                 :            :     uint8_t *csr_pointer;
+    1673                 :            :     size_t csr_len;
+    1674                 :            :     uint8_t csr_tracking_tag;
+    1675                 :            : 
+    1676                 :          1 :     csr_tracking_tag = 0;
+    1677                 :            : 
+    1678         [ -  + ]:          1 :     if (!libspdm_test_read_cached_csr(&csr_pointer, &csr_len)) {
+    1679                 :          0 :         assert_false(true);
+    1680                 :            :     }
+    1681                 :            : 
+    1682                 :          1 :     libspdm_copy_mem(cached_csr, LIBSPDM_MAX_CSR_SIZE, csr_pointer, csr_len);
+    1683                 :          1 :     free(csr_pointer);
+    1684                 :            : 
+    1685                 :          1 :     spdm_test_context = *state;
+    1686                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1687                 :          1 :     spdm_test_context->case_id = 0xF;
+    1688                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+    1689                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1690                 :            : 
+    1691                 :          1 :     spdm_context->connection_info.connection_state =
+    1692                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1693                 :          1 :     spdm_context->local_context.capability.flags |=
+    1694                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CSR_CAP;
+    1695                 :            : 
+    1696                 :          1 :     spdm_context->connection_info.multi_key_conn_rsp = true;
+    1697                 :            :     /*set responder need reset*/
+    1698                 :          1 :     spdm_context->local_context.capability.flags |=
+    1699                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_INSTALL_RESET_CAP;
+    1700                 :            : 
+    1701                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1702                 :            :         m_libspdm_use_hash_algo;
+    1703                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1704                 :            :         m_libspdm_use_asym_algo;
+    1705                 :            : 
+    1706                 :            :     /*set csr before reset*/
+    1707                 :          1 :     assert_true(libspdm_set_csr_before_reset());
+    1708                 :            : 
+    1709                 :          1 :     m_libspdm_get_csr_request = malloc(sizeof(spdm_get_csr_request_t) +
+    1710                 :            :                                        req_info_len);
+    1711                 :            : 
+    1712                 :          1 :     m_libspdm_get_csr_request->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+    1713                 :          1 :     m_libspdm_get_csr_request->header.request_response_code = SPDM_GET_CSR;
+    1714                 :          1 :     m_libspdm_get_csr_request->header.param1 = 1;
+    1715                 :          1 :     m_libspdm_get_csr_request->header.param2 =
+    1716                 :          1 :         SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT |
+    1717                 :          1 :         (csr_tracking_tag << SPDM_GET_CSR_REQUEST_ATTRIBUTES_CSR_TRACKING_TAG_OFFSET);
+    1718                 :            : 
+    1719                 :          1 :     m_libspdm_get_csr_request->opaque_data_length = 0;
+    1720                 :          1 :     m_libspdm_get_csr_request->requester_info_length = req_info_len;
+    1721                 :            : 
+    1722                 :          1 :     libspdm_copy_mem(m_libspdm_get_csr_request + 1, req_info_len,
+    1723                 :            :                      right_req_info, req_info_len);
+    1724                 :            : 
+    1725                 :          1 :     size_t m_libspdm_get_csr_request_size = sizeof(spdm_get_csr_request_t) +
+    1726                 :            :                                             req_info_len;
+    1727                 :            : 
+    1728                 :          1 :     response_size = sizeof(response);
+    1729                 :          1 :     status = libspdm_get_response_csr(spdm_context,
+    1730                 :            :                                       m_libspdm_get_csr_request_size,
+    1731                 :            :                                       m_libspdm_get_csr_request,
+    1732                 :            :                                       &response_size, response);
+    1733                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CSR_CAP_EX
+    1734                 :            :     /*first get_csr: the responder need reset*/
+    1735                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1736                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1737                 :          1 :     spdm_response = (void *)response;
+    1738                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1739                 :            :                      SPDM_ERROR);
+    1740                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1741                 :            :                      SPDM_ERROR_CODE_RESET_REQUIRED);
+    1742                 :          1 :     assert_int_equal(spdm_response->header.param2, 1);
+    1743                 :            : 
+    1744                 :            :     /*unmatched csr_tracking_tag*/
+    1745                 :          1 :     csr_tracking_tag = 3;
+    1746                 :          1 :     m_libspdm_get_csr_request->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+    1747                 :          1 :     m_libspdm_get_csr_request->header.request_response_code = SPDM_GET_CSR;
+    1748                 :          1 :     m_libspdm_get_csr_request->header.param1 = 1;
+    1749                 :          1 :     m_libspdm_get_csr_request->header.param2 =
+    1750                 :          1 :         SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT |
+    1751                 :          1 :         (csr_tracking_tag << SPDM_GET_CSR_REQUEST_ATTRIBUTES_CSR_TRACKING_TAG_OFFSET);
+    1752                 :            : 
+    1753                 :          1 :     m_libspdm_get_csr_request->opaque_data_length = 0;
+    1754                 :          1 :     m_libspdm_get_csr_request->requester_info_length = req_info_len;
+    1755                 :          1 :     libspdm_copy_mem(m_libspdm_get_csr_request + 1, req_info_len,
+    1756                 :            :                      right_req_info, req_info_len);
+    1757                 :            : 
+    1758                 :          1 :     response_size = sizeof(response);
+    1759                 :          1 :     status = libspdm_get_response_csr(spdm_context,
+    1760                 :            :                                       m_libspdm_get_csr_request_size,
+    1761                 :            :                                       m_libspdm_get_csr_request,
+    1762                 :            :                                       &response_size, response);
+    1763                 :            :     /*second get_csr after device reset: get the responder cached csr*/
+    1764                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1765                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1766                 :          1 :     spdm_response = (void *)response;
+    1767                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1768                 :            :                      SPDM_ERROR);
+    1769                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1770                 :            :                      SPDM_ERROR_CODE_UNEXPECTED_REQUEST);
+    1771                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1772                 :            : 
+    1773                 :            :     /*matched csr_tracking_tag without overwrite*/
+    1774                 :          1 :     csr_tracking_tag = 1;
+    1775                 :          1 :     m_libspdm_get_csr_request->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+    1776                 :          1 :     m_libspdm_get_csr_request->header.request_response_code = SPDM_GET_CSR;
+    1777                 :          1 :     m_libspdm_get_csr_request->header.param1 = 1;
+    1778                 :          1 :     m_libspdm_get_csr_request->header.param2 =
+    1779                 :          1 :         SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT |
+    1780                 :          1 :         (csr_tracking_tag << SPDM_GET_CSR_REQUEST_ATTRIBUTES_CSR_TRACKING_TAG_OFFSET);
+    1781                 :            : 
+    1782                 :          1 :     m_libspdm_get_csr_request->opaque_data_length = 0;
+    1783                 :          1 :     m_libspdm_get_csr_request->requester_info_length = req_info_len;
+    1784                 :          1 :     libspdm_copy_mem(m_libspdm_get_csr_request + 1, req_info_len,
+    1785                 :            :                      right_req_info, req_info_len);
+    1786                 :            : 
+    1787                 :          1 :     response_size = sizeof(response);
+    1788                 :          1 :     status = libspdm_get_response_csr(spdm_context,
+    1789                 :            :                                       m_libspdm_get_csr_request_size,
+    1790                 :            :                                       m_libspdm_get_csr_request,
+    1791                 :            :                                       &response_size, response);
+    1792                 :            :     /*second get_csr after device reset: get the responder cached csr*/
+    1793                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1794                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1795                 :          1 :     spdm_response = (void *)response;
+    1796                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1797                 :            :                      SPDM_ERROR);
+    1798                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1799                 :            :                      SPDM_ERROR_CODE_BUSY);
+    1800                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1801                 :            : 
+    1802                 :            : 
+    1803                 :            :     /*matched csr_tracking_tag with overwrite*/
+    1804                 :          1 :     csr_tracking_tag = 1;
+    1805                 :          1 :     m_libspdm_get_csr_request->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+    1806                 :          1 :     m_libspdm_get_csr_request->header.request_response_code = SPDM_GET_CSR;
+    1807                 :          1 :     m_libspdm_get_csr_request->header.param1 = 1;
+    1808                 :          1 :     m_libspdm_get_csr_request->header.param2 =
+    1809                 :          1 :         (csr_tracking_tag << SPDM_GET_CSR_REQUEST_ATTRIBUTES_CSR_TRACKING_TAG_OFFSET) |
+    1810                 :            :         SPDM_GET_CSR_REQUEST_ATTRIBUTES_OVERWRITE;
+    1811                 :            : 
+    1812                 :          1 :     m_libspdm_get_csr_request->opaque_data_length = 0;
+    1813                 :          1 :     m_libspdm_get_csr_request->requester_info_length = req_info_len;
+    1814                 :          1 :     libspdm_copy_mem(m_libspdm_get_csr_request + 1, req_info_len,
+    1815                 :            :                      right_req_info, req_info_len);
+    1816                 :            : 
+    1817                 :          1 :     response_size = sizeof(response);
+    1818                 :          1 :     status = libspdm_get_response_csr(spdm_context,
+    1819                 :            :                                       m_libspdm_get_csr_request_size,
+    1820                 :            :                                       m_libspdm_get_csr_request,
+    1821                 :            :                                       &response_size, response);
+    1822                 :            :     /*second get_csr after device reset: get the responder cached csr*/
+    1823                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1824                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1825                 :          1 :     spdm_response = (void *)response;
+    1826                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1827                 :            :                      SPDM_ERROR);
+    1828                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1829                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+    1830                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1831                 :            : 
+    1832                 :            :     /*set csr after reset*/
+    1833                 :          1 :     assert_true(libspdm_set_csr_after_reset());
+    1834                 :            : 
+    1835                 :            :     /*unmatched csr_tracking_tag*/
+    1836                 :          1 :     csr_tracking_tag = 3;
+    1837                 :          1 :     m_libspdm_get_csr_request->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+    1838                 :          1 :     m_libspdm_get_csr_request->header.request_response_code = SPDM_GET_CSR;
+    1839                 :          1 :     m_libspdm_get_csr_request->header.param1 = 1;
+    1840                 :          1 :     m_libspdm_get_csr_request->header.param2 =
+    1841                 :          1 :         SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT |
+    1842                 :          1 :         (csr_tracking_tag << SPDM_GET_CSR_REQUEST_ATTRIBUTES_CSR_TRACKING_TAG_OFFSET);
+    1843                 :            : 
+    1844                 :          1 :     m_libspdm_get_csr_request->opaque_data_length = 0;
+    1845                 :          1 :     m_libspdm_get_csr_request->requester_info_length = req_info_len;
+    1846                 :          1 :     libspdm_copy_mem(m_libspdm_get_csr_request + 1, req_info_len,
+    1847                 :            :                      right_req_info, req_info_len);
+    1848                 :            : 
+    1849                 :          1 :     response_size = sizeof(response);
+    1850                 :          1 :     status = libspdm_get_response_csr(spdm_context,
+    1851                 :            :                                       m_libspdm_get_csr_request_size,
+    1852                 :            :                                       m_libspdm_get_csr_request,
+    1853                 :            :                                       &response_size, response);
+    1854                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1855                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1856                 :          1 :     spdm_response = (void *)response;
+    1857                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1858                 :            :                      SPDM_ERROR);
+    1859                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1860                 :            :                      SPDM_ERROR_CODE_UNEXPECTED_REQUEST);
+    1861                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1862                 :            : 
+    1863                 :            :     /*csr_tracking_tag 0 and overwrite*/
+    1864                 :          1 :     csr_tracking_tag = 0;
+    1865                 :          1 :     m_libspdm_get_csr_request->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+    1866                 :          1 :     m_libspdm_get_csr_request->header.request_response_code = SPDM_GET_CSR;
+    1867                 :          1 :     m_libspdm_get_csr_request->header.param1 = 1;
+    1868                 :          1 :     m_libspdm_get_csr_request->header.param2 =
+    1869                 :            :         SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT |
+    1870                 :          1 :         (csr_tracking_tag << SPDM_GET_CSR_REQUEST_ATTRIBUTES_CSR_TRACKING_TAG_OFFSET) |
+    1871                 :            :         SPDM_GET_CSR_REQUEST_ATTRIBUTES_OVERWRITE;
+    1872                 :            : 
+    1873                 :          1 :     m_libspdm_get_csr_request->opaque_data_length = 0;
+    1874                 :          1 :     m_libspdm_get_csr_request->requester_info_length = req_info_len;
+    1875                 :          1 :     libspdm_copy_mem(m_libspdm_get_csr_request + 1, req_info_len,
+    1876                 :            :                      right_req_info, req_info_len);
+    1877                 :            : 
+    1878                 :          1 :     response_size = sizeof(response);
+    1879                 :          1 :     status = libspdm_get_response_csr(spdm_context,
+    1880                 :            :                                       m_libspdm_get_csr_request_size,
+    1881                 :            :                                       m_libspdm_get_csr_request,
+    1882                 :            :                                       &response_size, response);
+    1883                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1884                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1885                 :          1 :     spdm_response = (void *)response;
+    1886                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1887                 :            :                      SPDM_ERROR);
+    1888                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1889                 :            :                      SPDM_ERROR_CODE_RESET_REQUIRED);
+    1890                 :          1 :     assert_int_equal(spdm_response->header.param2, 1);
+    1891                 :            : 
+    1892                 :            : #else
+    1893                 :            :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1894                 :            :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1895                 :            :     spdm_response = (void *)response;
+    1896                 :            :     assert_int_equal(spdm_response->header.request_response_code,
+    1897                 :            :                      SPDM_ERROR);
+    1898                 :            :     assert_int_equal(spdm_response->header.param1,
+    1899                 :            :                      SPDM_ERROR_CODE_UNEXPECTED_REQUEST);
+    1900                 :            :     assert_int_equal(spdm_response->header.param2, 0);
+    1901                 :            :     /*set csr after reset*/
+    1902                 :            :     assert_true(libspdm_set_csr_after_reset());
+    1903                 :            : #endif /*LIBSPDM_ENABLE_CAPABILITY_CSR_CAP_EX*/
+    1904                 :            :     /*clear cached req_info*/
+    1905                 :          1 :     libspdm_test_clear_cached_last_request();
+    1906                 :          1 :     free(m_libspdm_get_csr_request);
+    1907                 :          1 : }
+    1908                 :            : 
+    1909                 :            : /**
+    1910                 :            :  * Test 16: Illegal combination of MULTI_KEY_CONN_RSP = true and CSRCertModel = 0.
+    1911                 :            :  * Expected Behavior: produces SPDM_ERROR_CODE_INVALID_REQUEST message.
+    1912                 :            :  **/
+    1913                 :          1 : void libspdm_test_responder_csr_case16(void **state)
+    1914                 :            : {
+    1915                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CSR_CAP_EX
+    1916                 :            :     libspdm_return_t status;
+    1917                 :            :     libspdm_test_context_t *spdm_test_context;
+    1918                 :            :     libspdm_context_t *spdm_context;
+    1919                 :            :     size_t response_size;
+    1920                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1921                 :            :     spdm_csr_response_t *spdm_response;
+    1922                 :            :     spdm_get_csr_request_t *m_libspdm_get_csr_request;
+    1923                 :            :     uint8_t cached_csr[LIBSPDM_MAX_CSR_SIZE];
+    1924                 :          1 :     libspdm_zero_mem(cached_csr, LIBSPDM_MAX_CSR_SIZE);
+    1925                 :            : 
+    1926                 :            :     uint8_t *csr_pointer;
+    1927                 :            :     size_t csr_len;
+    1928                 :            :     uint8_t csr_tracking_tag;
+    1929                 :            : 
+    1930                 :          1 :     csr_tracking_tag = 0;
+    1931                 :            : 
+    1932         [ -  + ]:          1 :     if (!libspdm_test_read_cached_csr(&csr_pointer, &csr_len)) {
+    1933                 :          0 :         assert_false(true);
+    1934                 :            :     }
+    1935                 :            : 
+    1936                 :          1 :     libspdm_copy_mem(cached_csr, LIBSPDM_MAX_CSR_SIZE, csr_pointer, csr_len);
+    1937                 :          1 :     free(csr_pointer);
+    1938                 :            : 
+    1939                 :          1 :     spdm_test_context = *state;
+    1940                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1941                 :          1 :     spdm_test_context->case_id = 0x10;
+    1942                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+    1943                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1944                 :            : 
+    1945                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1946                 :          1 :     spdm_context->local_context.capability.flags = SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CSR_CAP;
+    1947                 :            : 
+    1948                 :          1 :     spdm_context->connection_info.multi_key_conn_rsp = true;
+    1949                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1950                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1951                 :            : 
+    1952                 :          1 :     m_libspdm_get_csr_request = malloc(sizeof(spdm_get_csr_request_t) + req_info_len);
+    1953                 :            : 
+    1954                 :          1 :     m_libspdm_get_csr_request->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+    1955                 :          1 :     m_libspdm_get_csr_request->header.request_response_code = SPDM_GET_CSR;
+    1956                 :          1 :     m_libspdm_get_csr_request->header.param1 = 1;
+    1957                 :          1 :     m_libspdm_get_csr_request->header.param2 =
+    1958                 :          1 :         SPDM_CERTIFICATE_INFO_CERT_MODEL_NONE |
+    1959                 :            :         (csr_tracking_tag << SPDM_GET_CSR_REQUEST_ATTRIBUTES_CSR_TRACKING_TAG_OFFSET);
+    1960                 :            : 
+    1961                 :          1 :     m_libspdm_get_csr_request->opaque_data_length = 0;
+    1962                 :          1 :     m_libspdm_get_csr_request->requester_info_length = req_info_len;
+    1963                 :            : 
+    1964                 :          1 :     libspdm_copy_mem(m_libspdm_get_csr_request + 1, req_info_len, right_req_info, req_info_len);
+    1965                 :            : 
+    1966                 :          1 :     size_t m_libspdm_get_csr_request_size = sizeof(spdm_get_csr_request_t) + req_info_len;
+    1967                 :            : 
+    1968                 :          1 :     response_size = sizeof(response);
+    1969                 :          1 :     status = libspdm_get_response_csr(spdm_context,
+    1970                 :            :                                       m_libspdm_get_csr_request_size,
+    1971                 :            :                                       m_libspdm_get_csr_request,
+    1972                 :            :                                       &response_size, response);
+    1973                 :            : 
+    1974                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1975                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1976                 :          1 :     spdm_response = (void *)response;
+    1977                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
+    1978                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+    1979                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1980                 :            : 
+    1981                 :            :     /*clear cached req_info*/
+    1982                 :          1 :     libspdm_test_clear_cached_last_request();
+    1983                 :          1 :     free(m_libspdm_get_csr_request);
+    1984                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CSR_CAP_EX */
+    1985                 :          1 : }
+    1986                 :            : 
+    1987                 :            : libspdm_test_context_t m_libspdm_responder_csr_test_context = {
+    1988                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+    1989                 :            :     false,
+    1990                 :            : };
+    1991                 :            : 
+    1992                 :          1 : int libspdm_responder_csr_test_main(void)
+    1993                 :            : {
+    1994                 :          1 :     const struct CMUnitTest spdm_responder_csr_tests[] = {
+    1995                 :            :         /* Success Case for csr response with device_cert mode */
+    1996                 :            :         cmocka_unit_test(libspdm_test_responder_csr_case1),
+    1997                 :            :         /* Bad request size*/
+    1998                 :            :         cmocka_unit_test(libspdm_test_responder_csr_case2),
+    1999                 :            :         /* Success Case for csr response with non-null right req_info */
+    2000                 :            :         cmocka_unit_test(libspdm_test_responder_csr_case3),
+    2001                 :            :         /* Success Case for csr response with non-null opaque_data */
+    2002                 :            :         cmocka_unit_test(libspdm_test_responder_csr_case4),
+    2003                 :            :         /* Failed Case for csr response with non-null wrong req_info */
+    2004                 :            :         cmocka_unit_test(libspdm_test_responder_csr_case5),
+    2005                 :            :         /* Responder need reset to gen csr, the second send after device reset*/
+    2006                 :            :         cmocka_unit_test(libspdm_test_responder_csr_case6),
+    2007                 :            :         /* Success Case for csr response with non-null right req_info and opaque_data */
+    2008                 :            :         cmocka_unit_test(libspdm_test_responder_csr_case7),
+    2009                 :            :         /* Failed Case for csr response  With chaotic req_info and opaque_data */
+    2010                 :            :         cmocka_unit_test(libspdm_test_responder_csr_case8),
+    2011                 :            :         /* the OpaqueDataFmt1 bit is selected in OtherParamsSelection of ALGORITHMS*/
+    2012                 :            :         cmocka_unit_test(libspdm_test_responder_csr_case9),
+    2013                 :            :         /* Failed Case  OpaqueDataFmt1, When AlignPadding is not zero*/
+    2014                 :            :         cmocka_unit_test(libspdm_test_responder_csr_case10),
+    2015                 :            :         /* Success Case for csr response with alias_cert mode */
+    2016                 :            :         cmocka_unit_test(libspdm_test_responder_csr_case11),
+    2017                 :            :         /* Responder need reset to gen csr, the second send without device reset*/
+    2018                 :            :         cmocka_unit_test(libspdm_test_responder_csr_case12),
+    2019                 :            :         /* Success Case: Responder need reset to gen csr for SPDM1.3, the second send with matched csr_tracking_tag after device reset*/
+    2020                 :            :         cmocka_unit_test(libspdm_test_responder_csr_case13),
+    2021                 :            :         /* Failed Case: Responder need reset to gen csr for SPDM1.3, test for busy error*/
+    2022                 :            :         cmocka_unit_test(libspdm_test_responder_csr_case14),
+    2023                 :            :         /* Failed Case: Responder need reset to gen csr for SPDM1.3, test for unmatched csr_tracking_tag and overwrite*/
+    2024                 :            :         cmocka_unit_test(libspdm_test_responder_csr_case15),
+    2025                 :            :         cmocka_unit_test(libspdm_test_responder_csr_case16),
+    2026                 :            :     };
+    2027                 :            : 
+    2028                 :          1 :     libspdm_setup_test_context(&m_libspdm_responder_csr_test_context);
+    2029                 :            : 
+    2030                 :            :     /*ensure that cached.csr exists in test_csr at the beginning*/
+    2031                 :          1 :     libspdm_clear_cached_csr();
+    2032                 :            : 
+    2033                 :          1 :     return cmocka_run_group_tests(spdm_responder_csr_tests,
+    2034                 :            :                                   libspdm_unit_test_group_setup,
+    2035                 :            :                                   libspdm_unit_test_group_teardown);
+    2036                 :            : }
+    2037                 :            : 
+    2038                 :            : #endif /*LIBSPDM_ENABLE_CAPABILITY_CSR_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/digests.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_responder/digests.c.func-sort-c.html new file mode 100644 index 00000000000..475846c072a --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/digests.c.func-sort-c.html @@ -0,0 +1,125 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/digests.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - digests.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:230230100.0 %
Date:2024-09-22 08:21:07Functions:1111100.0 %
Branches:66100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_digests_test_main1
libspdm_test_responder_digests_case11
libspdm_test_responder_digests_case101
libspdm_test_responder_digests_case21
libspdm_test_responder_digests_case31
libspdm_test_responder_digests_case41
libspdm_test_responder_digests_case51
libspdm_test_responder_digests_case61
libspdm_test_responder_digests_case71
libspdm_test_responder_digests_case81
libspdm_test_responder_digests_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/digests.c.func.html b/coverage_log/unit_test/test_spdm_responder/digests.c.func.html new file mode 100644 index 00000000000..76bab437388 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/digests.c.func.html @@ -0,0 +1,125 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/digests.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - digests.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:230230100.0 %
Date:2024-09-22 08:21:07Functions:1111100.0 %
Branches:66100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_digests_test_main1
libspdm_test_responder_digests_case11
libspdm_test_responder_digests_case101
libspdm_test_responder_digests_case21
libspdm_test_responder_digests_case31
libspdm_test_responder_digests_case41
libspdm_test_responder_digests_case51
libspdm_test_responder_digests_case61
libspdm_test_responder_digests_case71
libspdm_test_responder_digests_case81
libspdm_test_responder_digests_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/digests.c.gcov.html b/coverage_log/unit_test/test_spdm_responder/digests.c.gcov.html new file mode 100644 index 00000000000..0c4dd5f764b --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/digests.c.gcov.html @@ -0,0 +1,722 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/digests.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - digests.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:230230100.0 %
Date:2024-09-22 08:21:07Functions:1111100.0 %
Branches:66100.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_responder_lib.h"
+       9                 :            : 
+      10                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CERT_CAP
+      11                 :            : 
+      12                 :            : spdm_get_digest_request_t m_libspdm_get_digests_request1 = {
+      13                 :            :     {
+      14                 :            :         SPDM_MESSAGE_VERSION_10,
+      15                 :            :         SPDM_GET_DIGESTS,
+      16                 :            :     },
+      17                 :            : };
+      18                 :            : size_t m_libspdm_get_digests_request1_size = sizeof(m_libspdm_get_digests_request1);
+      19                 :            : 
+      20                 :            : spdm_get_digest_request_t m_libspdm_get_digests_request2 = {
+      21                 :            :     {
+      22                 :            :         SPDM_MESSAGE_VERSION_13,
+      23                 :            :         SPDM_GET_DIGESTS,
+      24                 :            :     },
+      25                 :            : };
+      26                 :            : size_t m_libspdm_get_digests_request2_size = sizeof(m_libspdm_get_digests_request2);
+      27                 :            : 
+      28                 :            : static uint8_t m_libspdm_local_certificate_chain[LIBSPDM_MAX_CERT_CHAIN_SIZE];
+      29                 :            : 
+      30                 :            : /**
+      31                 :            :  * Test 1: receives a valid GET_DIGESTS request message from Requester
+      32                 :            :  * Expected Behavior: produces a valid DIGESTS response message
+      33                 :            :  **/
+      34                 :          1 : void libspdm_test_responder_digests_case1(void **state)
+      35                 :            : {
+      36                 :            :     libspdm_return_t status;
+      37                 :            :     libspdm_test_context_t *spdm_test_context;
+      38                 :            :     libspdm_context_t *spdm_context;
+      39                 :            :     size_t response_size;
+      40                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+      41                 :            :     spdm_digest_response_t *spdm_response;
+      42                 :            : 
+      43                 :          1 :     spdm_test_context = *state;
+      44                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+      45                 :          1 :     spdm_test_context->case_id = 0x1;
+      46                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+      47                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+      48                 :          1 :     spdm_context->connection_info.connection_state =
+      49                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+      50                 :          1 :     spdm_context->local_context.capability.flags |=
+      51                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+      52                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+      53                 :            :         m_libspdm_use_hash_algo;
+      54                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] =
+      55                 :            :         m_libspdm_local_certificate_chain;
+      56                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+      57                 :            :         sizeof(m_libspdm_local_certificate_chain);
+      58                 :          1 :     libspdm_set_mem(m_libspdm_local_certificate_chain,
+      59                 :            :                     sizeof(m_libspdm_local_certificate_chain),
+      60                 :            :                     (uint8_t)(0xFF));
+      61                 :            : 
+      62                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+      63                 :            :     spdm_context->transcript.message_m.buffer_size =
+      64                 :            :         spdm_context->transcript.message_m.max_buffer_size;
+      65                 :            : #endif
+      66                 :            : 
+      67                 :          1 :     response_size = sizeof(response);
+      68                 :          1 :     status = libspdm_get_response_digests(spdm_context,
+      69                 :            :                                           m_libspdm_get_digests_request1_size,
+      70                 :            :                                           &m_libspdm_get_digests_request1,
+      71                 :            :                                           &response_size, response);
+      72                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+      73                 :          1 :     assert_int_equal(
+      74                 :            :         response_size,
+      75                 :            :         sizeof(spdm_digest_response_t) +
+      76                 :            :         libspdm_get_hash_size(spdm_context->connection_info
+      77                 :            :                               .algorithm.base_hash_algo));
+      78                 :          1 :     spdm_response = (void *)response;
+      79                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+      80                 :            :                      SPDM_DIGESTS);
+      81                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+      82                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
+      83                 :            :                      0);
+      84                 :            : #endif
+      85                 :          1 : }
+      86                 :            : 
+      87                 :            : /**
+      88                 :            :  * Test 2:
+      89                 :            :  * Expected Behavior:
+      90                 :            :  **/
+      91                 :          1 : void libspdm_test_responder_digests_case2(void **state)
+      92                 :            : {
+      93                 :          1 : }
+      94                 :            : 
+      95                 :            : /**
+      96                 :            :  * Test 3: receives a valid GET_DIGESTS request message from Requester, but Responder is not ready to accept the new
+      97                 :            :  * request message (is busy) and may be able to process the request message if it is sent again in the future
+      98                 :            :  * Expected Behavior: produces an ERROR response message with error code = Busy
+      99                 :            :  **/
+     100                 :          1 : void libspdm_test_responder_digests_case3(void **state)
+     101                 :            : {
+     102                 :            :     libspdm_return_t status;
+     103                 :            :     libspdm_test_context_t *spdm_test_context;
+     104                 :            :     libspdm_context_t *spdm_context;
+     105                 :            :     size_t response_size;
+     106                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     107                 :            :     spdm_digest_response_t *spdm_response;
+     108                 :            : 
+     109                 :          1 :     spdm_test_context = *state;
+     110                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     111                 :          1 :     spdm_test_context->case_id = 0x3;
+     112                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+     113                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     114                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_BUSY;
+     115                 :          1 :     spdm_context->connection_info.connection_state =
+     116                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     117                 :          1 :     spdm_context->local_context.capability.flags |=
+     118                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     119                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     120                 :            :         m_libspdm_use_hash_algo;
+     121                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] =
+     122                 :            :         m_libspdm_local_certificate_chain;
+     123                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     124                 :            :         sizeof(m_libspdm_local_certificate_chain);
+     125                 :          1 :     libspdm_set_mem(m_libspdm_local_certificate_chain,
+     126                 :            :                     sizeof(m_libspdm_local_certificate_chain),
+     127                 :            :                     (uint8_t)(0xFF));
+     128                 :            : 
+     129                 :          1 :     response_size = sizeof(response);
+     130                 :          1 :     status = libspdm_get_response_digests(spdm_context,
+     131                 :            :                                           m_libspdm_get_digests_request1_size,
+     132                 :            :                                           &m_libspdm_get_digests_request1,
+     133                 :            :                                           &response_size, response);
+     134                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     135                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     136                 :          1 :     spdm_response = (void *)response;
+     137                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     138                 :            :                      SPDM_ERROR);
+     139                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_BUSY);
+     140                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     141                 :          1 :     assert_int_equal(spdm_context->response_state,
+     142                 :            :                      LIBSPDM_RESPONSE_STATE_BUSY);
+     143                 :          1 : }
+     144                 :            : 
+     145                 :            : /**
+     146                 :            :  * Test 4: receives a valid GET_DIGESTS request message from Requester, but Responder needs the Requester to reissue GET_VERSION to resynchronize
+     147                 :            :  * Expected Behavior: produces an ERROR response message with error code = RequestResynch
+     148                 :            :  **/
+     149                 :          1 : void libspdm_test_responder_digests_case4(void **state)
+     150                 :            : {
+     151                 :            :     libspdm_return_t status;
+     152                 :            :     libspdm_test_context_t *spdm_test_context;
+     153                 :            :     libspdm_context_t *spdm_context;
+     154                 :            :     size_t response_size;
+     155                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     156                 :            :     spdm_digest_response_t *spdm_response;
+     157                 :            : 
+     158                 :          1 :     spdm_test_context = *state;
+     159                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     160                 :          1 :     spdm_test_context->case_id = 0x4;
+     161                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+     162                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     163                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NEED_RESYNC;
+     164                 :          1 :     spdm_context->connection_info.connection_state =
+     165                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     166                 :          1 :     spdm_context->local_context.capability.flags |=
+     167                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     168                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     169                 :            :         m_libspdm_use_hash_algo;
+     170                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] =
+     171                 :            :         m_libspdm_local_certificate_chain;
+     172                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     173                 :            :         sizeof(m_libspdm_local_certificate_chain);
+     174                 :          1 :     libspdm_set_mem(m_libspdm_local_certificate_chain,
+     175                 :            :                     sizeof(m_libspdm_local_certificate_chain),
+     176                 :            :                     (uint8_t)(0xFF));
+     177                 :            : 
+     178                 :          1 :     response_size = sizeof(response);
+     179                 :          1 :     status = libspdm_get_response_digests(spdm_context,
+     180                 :            :                                           m_libspdm_get_digests_request1_size,
+     181                 :            :                                           &m_libspdm_get_digests_request1,
+     182                 :            :                                           &response_size, response);
+     183                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     184                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     185                 :          1 :     spdm_response = (void *)response;
+     186                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     187                 :            :                      SPDM_ERROR);
+     188                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     189                 :            :                      SPDM_ERROR_CODE_REQUEST_RESYNCH);
+     190                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     191                 :          1 :     assert_int_equal(spdm_context->response_state,
+     192                 :            :                      LIBSPDM_RESPONSE_STATE_NEED_RESYNC);
+     193                 :          1 : }
+     194                 :            : 
+     195                 :            : #if LIBSPDM_RESPOND_IF_READY_SUPPORT
+     196                 :            : /**
+     197                 :            :  * Test 5: receives a valid GET_DIGESTS request message from Requester, but Responder cannot produce the response message in time
+     198                 :            :  * Expected Behavior: produces an ERROR response message with error code = ResponseNotReady
+     199                 :            :  **/
+     200                 :          1 : void libspdm_test_responder_digests_case5(void **state)
+     201                 :            : {
+     202                 :            :     libspdm_return_t status;
+     203                 :            :     libspdm_test_context_t *spdm_test_context;
+     204                 :            :     libspdm_context_t *spdm_context;
+     205                 :            :     size_t response_size;
+     206                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     207                 :            :     spdm_digest_response_t *spdm_response;
+     208                 :            :     spdm_error_data_response_not_ready_t *error_data;
+     209                 :            : 
+     210                 :          1 :     spdm_test_context = *state;
+     211                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     212                 :          1 :     spdm_test_context->case_id = 0x5;
+     213                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+     214                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     215                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NOT_READY;
+     216                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     217                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     218                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     219                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] =
+     220                 :            :         m_libspdm_local_certificate_chain;
+     221                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     222                 :            :         sizeof(m_libspdm_local_certificate_chain);
+     223                 :          1 :     libspdm_set_mem(m_libspdm_local_certificate_chain,
+     224                 :            :                     sizeof(m_libspdm_local_certificate_chain),
+     225                 :            :                     (uint8_t)(0xFF));
+     226                 :            : 
+     227                 :          1 :     response_size = sizeof(response);
+     228                 :          1 :     status = libspdm_get_response_digests(spdm_context,
+     229                 :            :                                           m_libspdm_get_digests_request1_size,
+     230                 :            :                                           &m_libspdm_get_digests_request1,
+     231                 :            :                                           &response_size, response);
+     232                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     233                 :          1 :     assert_int_equal(response_size,
+     234                 :            :                      sizeof(spdm_error_response_t) +
+     235                 :            :                      sizeof(spdm_error_data_response_not_ready_t));
+     236                 :          1 :     spdm_response = (void *)response;
+     237                 :          1 :     error_data = (spdm_error_data_response_not_ready_t *)(spdm_response + 1);
+     238                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     239                 :            :                      SPDM_ERROR);
+     240                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     241                 :            :                      SPDM_ERROR_CODE_RESPONSE_NOT_READY);
+     242                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     243                 :          1 :     assert_int_equal(spdm_context->response_state,
+     244                 :            :                      LIBSPDM_RESPONSE_STATE_NOT_READY);
+     245                 :          1 :     assert_int_equal(error_data->request_code, SPDM_GET_DIGESTS);
+     246                 :          1 : }
+     247                 :            : #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
+     248                 :            : 
+     249                 :            : /**
+     250                 :            :  * Test 6: receives a valid GET_DIGESTS request message from Requester, but connection_state equals to zero and makes the check fail,
+     251                 :            :  * meaning that steps GET_CAPABILITIES-CAPABILITIES and NEGOTIATE_ALGORITHMS-ALGORITHMS of the protocol were not previously completed
+     252                 :            :  * Expected Behavior: produces an ERROR response message with error code = UnexpectedRequest
+     253                 :            :  **/
+     254                 :          1 : void libspdm_test_responder_digests_case6(void **state)
+     255                 :            : {
+     256                 :            :     libspdm_return_t status;
+     257                 :            :     libspdm_test_context_t *spdm_test_context;
+     258                 :            :     libspdm_context_t *spdm_context;
+     259                 :            :     size_t response_size;
+     260                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     261                 :            :     spdm_digest_response_t *spdm_response;
+     262                 :            : 
+     263                 :          1 :     spdm_test_context = *state;
+     264                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     265                 :          1 :     spdm_test_context->case_id = 0x6;
+     266                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+     267                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     268                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+     269                 :          1 :     spdm_context->connection_info.connection_state =
+     270                 :            :         LIBSPDM_CONNECTION_STATE_NOT_STARTED;
+     271                 :          1 :     spdm_context->local_context.capability.flags |=
+     272                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     273                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     274                 :            :         m_libspdm_use_hash_algo;
+     275                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] =
+     276                 :            :         m_libspdm_local_certificate_chain;
+     277                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     278                 :            :         sizeof(m_libspdm_local_certificate_chain);
+     279                 :          1 :     libspdm_set_mem(m_libspdm_local_certificate_chain,
+     280                 :            :                     sizeof(m_libspdm_local_certificate_chain),
+     281                 :            :                     (uint8_t)(0xFF));
+     282                 :            : 
+     283                 :          1 :     response_size = sizeof(response);
+     284                 :          1 :     status = libspdm_get_response_digests(spdm_context,
+     285                 :            :                                           m_libspdm_get_digests_request1_size,
+     286                 :            :                                           &m_libspdm_get_digests_request1,
+     287                 :            :                                           &response_size, response);
+     288                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     289                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     290                 :          1 :     spdm_response = (void *)response;
+     291                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     292                 :            :                      SPDM_ERROR);
+     293                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     294                 :            :                      SPDM_ERROR_CODE_UNEXPECTED_REQUEST);
+     295                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     296                 :          1 : }
+     297                 :            : 
+     298                 :            : /**
+     299                 :            :  * Test 7: receives a valid GET_DIGESTS request message from Requester, but there is no local certificate chain, i.e. there is no digest to send
+     300                 :            :  * Expected Behavior: produces an ERROR response message with error code = Unspecified
+     301                 :            :  **/
+     302                 :          1 : void libspdm_test_responder_digests_case7(void **state)
+     303                 :            : {
+     304                 :            :     libspdm_return_t status;
+     305                 :            :     libspdm_test_context_t *spdm_test_context;
+     306                 :            :     libspdm_context_t *spdm_context;
+     307                 :            :     size_t response_size;
+     308                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     309                 :            :     spdm_digest_response_t *spdm_response;
+     310                 :            :     size_t index;
+     311                 :            : 
+     312                 :          1 :     spdm_test_context = *state;
+     313                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     314                 :          1 :     spdm_test_context->case_id = 0x7;
+     315                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+     316                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     317                 :          1 :     spdm_context->connection_info.connection_state =
+     318                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     319                 :          1 :     spdm_context->local_context.capability.flags |=
+     320                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     321                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     322                 :            :         m_libspdm_use_hash_algo;
+     323                 :            : 
+     324         [ +  + ]:          9 :     for (index = 0; index < SPDM_MAX_SLOT_COUNT; index++) {
+     325                 :          8 :         spdm_context->local_context.local_cert_chain_provision[index] =
+     326                 :            :             NULL;
+     327                 :            :         spdm_context->local_context
+     328                 :          8 :         .local_cert_chain_provision_size[index] = 0;
+     329                 :            :     }
+     330                 :            : 
+     331                 :          1 :     response_size = sizeof(response);
+     332                 :          1 :     libspdm_reset_message_b(spdm_context);
+     333                 :          1 :     status = libspdm_get_response_digests(spdm_context,
+     334                 :            :                                           m_libspdm_get_digests_request1_size,
+     335                 :            :                                           &m_libspdm_get_digests_request1,
+     336                 :            :                                           &response_size, response);
+     337                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     338                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     339                 :          1 :     spdm_response = (void *)response;
+     340                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     341                 :            :                      SPDM_ERROR);
+     342                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     343                 :            :                      SPDM_ERROR_CODE_UNSPECIFIED);
+     344                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     345                 :          1 : }
+     346                 :            : 
+     347                 :            : /**
+     348                 :            :  * Test 08: receives a valid GET_DIGESTS request message from Requester in a session
+     349                 :            :  * Expected Behavior: produces a valid DIGESTS response message
+     350                 :            :  **/
+     351                 :          1 : void libspdm_test_responder_digests_case8(void **state)
+     352                 :            : {
+     353                 :            :     libspdm_return_t status;
+     354                 :            :     libspdm_test_context_t *spdm_test_context;
+     355                 :            :     libspdm_context_t *spdm_context;
+     356                 :            :     size_t response_size;
+     357                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     358                 :            :     spdm_digest_response_t *spdm_response;
+     359                 :            :     libspdm_session_info_t *session_info;
+     360                 :            :     uint32_t session_id;
+     361                 :            : 
+     362                 :          1 :     spdm_test_context = *state;
+     363                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     364                 :          1 :     spdm_test_context->case_id = 0x8;
+     365                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+     366                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     367                 :          1 :     spdm_context->connection_info.connection_state =
+     368                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     369                 :          1 :     spdm_context->local_context.capability.flags |=
+     370                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     371                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     372                 :            :         m_libspdm_use_hash_algo;
+     373                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] =
+     374                 :            :         m_libspdm_local_certificate_chain;
+     375                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     376                 :            :         sizeof(m_libspdm_local_certificate_chain);
+     377                 :            : 
+     378                 :          1 :     session_id = 0xFFFFFFFF;
+     379                 :          1 :     spdm_context->latest_session_id = session_id;
+     380                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+     381                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+     382                 :          1 :     session_info = &spdm_context->session_info[0];
+     383                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+     384                 :          1 :     libspdm_secured_message_set_session_state(
+     385                 :            :         session_info->secured_message_context,
+     386                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+     387                 :            : 
+     388                 :          1 :     libspdm_set_mem(m_libspdm_local_certificate_chain,
+     389                 :            :                     sizeof(m_libspdm_local_certificate_chain),
+     390                 :            :                     (uint8_t)(0xFF));
+     391                 :            : 
+     392                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     393                 :            :     session_info->session_transcript.message_m.buffer_size =
+     394                 :            :         session_info->session_transcript.message_m.max_buffer_size;
+     395                 :            : #endif
+     396                 :            : 
+     397                 :          1 :     response_size = sizeof(response);
+     398                 :          1 :     status = libspdm_get_response_digests(spdm_context,
+     399                 :            :                                           m_libspdm_get_digests_request1_size,
+     400                 :            :                                           &m_libspdm_get_digests_request1,
+     401                 :            :                                           &response_size, response);
+     402                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     403                 :          1 :     assert_int_equal(
+     404                 :            :         response_size,
+     405                 :            :         sizeof(spdm_digest_response_t) +
+     406                 :            :         libspdm_get_hash_size(spdm_context->connection_info
+     407                 :            :                               .algorithm.base_hash_algo));
+     408                 :          1 :     spdm_response = (void *)response;
+     409                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     410                 :            :                      SPDM_DIGESTS);
+     411                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     412                 :            :     assert_int_equal(session_info->session_transcript.message_m.buffer_size,
+     413                 :            :                      0);
+     414                 :            : #endif
+     415                 :          1 : }
+     416                 :            : 
+     417                 :            : /**
+     418                 :            :  * Test 9: receives a valid GET_DIGESTS request message from Requester , set multi_key_conn_rsp to check if it responds correctly
+     419                 :            :  * Expected Behavior: produces a valid DIGESTS response message
+     420                 :            :  **/
+     421                 :          1 : void libspdm_test_responder_digests_case9(void **state)
+     422                 :            : {
+     423                 :            :     libspdm_return_t status;
+     424                 :            :     libspdm_test_context_t *spdm_test_context;
+     425                 :            :     libspdm_context_t *spdm_context;
+     426                 :            :     size_t response_size;
+     427                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     428                 :            :     spdm_digest_response_t *spdm_response;
+     429                 :            : 
+     430                 :          1 :     spdm_test_context = *state;
+     431                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     432                 :          1 :     spdm_test_context->case_id = 0x9;
+     433                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+     434                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     435                 :          1 :     spdm_context->connection_info.connection_state =
+     436                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     437                 :          1 :     spdm_context->local_context.capability.flags = 0;
+     438                 :          1 :     spdm_context->last_spdm_request_session_id_valid = false;
+     439                 :          1 :     spdm_context->local_context.capability.flags |=
+     440                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     441                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     442                 :            :         m_libspdm_use_hash_algo;
+     443                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] =
+     444                 :            :         m_libspdm_local_certificate_chain;
+     445                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     446                 :            :         sizeof(m_libspdm_local_certificate_chain);
+     447                 :          1 :     libspdm_set_mem(m_libspdm_local_certificate_chain,
+     448                 :            :                     sizeof(m_libspdm_local_certificate_chain),
+     449                 :            :                     (uint8_t)(0xFF));
+     450                 :            : 
+     451                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     452                 :            :     spdm_context->transcript.message_m.buffer_size =
+     453                 :            :         spdm_context->transcript.message_m.max_buffer_size;
+     454                 :            : #endif
+     455                 :            :     /* Sub Case 1: Set multi_key_conn_rsp to true*/
+     456                 :          1 :     spdm_context->connection_info.multi_key_conn_rsp = true;
+     457                 :          1 :     libspdm_reset_message_d(spdm_context);
+     458                 :            : 
+     459                 :          1 :     response_size = sizeof(response);
+     460                 :          1 :     status = libspdm_get_response_digests(spdm_context,
+     461                 :            :                                           m_libspdm_get_digests_request2_size,
+     462                 :            :                                           &m_libspdm_get_digests_request2,
+     463                 :            :                                           &response_size, response);
+     464                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     465                 :          1 :     assert_int_equal(
+     466                 :            :         response_size,
+     467                 :            :         sizeof(spdm_digest_response_t) + sizeof(spdm_key_pair_id_t) +
+     468                 :            :         sizeof(spdm_certificate_info_t) +
+     469                 :            :         sizeof(spdm_key_usage_bit_mask_t) +
+     470                 :            :         libspdm_get_hash_size(spdm_context->connection_info
+     471                 :            :                               .algorithm.base_hash_algo));
+     472                 :          1 :     spdm_response = (void *)response;
+     473                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     474                 :            :                      SPDM_DIGESTS);
+     475                 :          1 :     assert_int_equal(spdm_context->transcript.message_d.buffer_size,
+     476                 :            :                      sizeof(spdm_digest_response_t) +
+     477                 :            :                      sizeof(spdm_key_pair_id_t) +
+     478                 :            :                      sizeof(spdm_certificate_info_t) +
+     479                 :            :                      sizeof(spdm_key_usage_bit_mask_t) +
+     480                 :            :                      libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo));
+     481                 :            : 
+     482                 :            :     /* Sub Case 2: Set multi_key_conn_rsp to false*/
+     483                 :          1 :     spdm_context->connection_info.multi_key_conn_rsp = false;
+     484                 :          1 :     libspdm_reset_message_d(spdm_context);
+     485                 :            : 
+     486                 :          1 :     response_size = sizeof(response);
+     487                 :          1 :     status = libspdm_get_response_digests(spdm_context,
+     488                 :            :                                           m_libspdm_get_digests_request2_size,
+     489                 :            :                                           &m_libspdm_get_digests_request2,
+     490                 :            :                                           &response_size, response);
+     491                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     492                 :          1 :     assert_int_equal(
+     493                 :            :         response_size,
+     494                 :            :         sizeof(spdm_digest_response_t) +
+     495                 :            :         libspdm_get_hash_size(spdm_context->connection_info
+     496                 :            :                               .algorithm.base_hash_algo));
+     497                 :          1 :     spdm_response = (void *)response;
+     498                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     499                 :            :                      SPDM_DIGESTS);
+     500                 :          1 :     assert_int_equal(spdm_context->transcript.message_d.buffer_size, 0);
+     501                 :          1 : }
+     502                 :            : 
+     503                 :            : /**
+     504                 :            :  * Test10: a response message is successfully sent ,
+     505                 :            :  * Check KeyPairID CertificateInfo and KeyUsageMask
+     506                 :            :  * Expected Behavior: requester returns the status LIBSPDM_STATUS_SUCCESS
+     507                 :            :  **/
+     508                 :          1 : void libspdm_test_responder_digests_case10(void **state)
+     509                 :            : {
+     510                 :            :     libspdm_return_t status;
+     511                 :            :     libspdm_test_context_t *spdm_test_context;
+     512                 :            :     libspdm_context_t *spdm_context;
+     513                 :            :     size_t response_size;
+     514                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     515                 :            :     spdm_digest_response_t *spdm_response;
+     516                 :            :     uint8_t *digest;
+     517                 :            :     spdm_key_pair_id_t *key_pair_id;
+     518                 :            :     spdm_certificate_info_t *cert_info;
+     519                 :            :     spdm_key_usage_bit_mask_t *key_usage_bit_mask;
+     520                 :            :     uint32_t hash_size;
+     521                 :            :     uint8_t slot_count;
+     522                 :            :     size_t additional_size;
+     523                 :            : 
+     524                 :          1 :     slot_count = SPDM_MAX_SLOT_COUNT;
+     525                 :          1 :     additional_size = sizeof(spdm_key_pair_id_t) + sizeof(spdm_certificate_info_t) +
+     526                 :            :                       sizeof(spdm_key_usage_bit_mask_t);
+     527                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     528                 :            : 
+     529                 :          1 :     spdm_test_context = *state;
+     530                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     531                 :          1 :     spdm_test_context->case_id = 0x0A;
+     532                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+     533                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     534                 :          1 :     spdm_context->connection_info.connection_state =
+     535                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     536                 :          1 :     spdm_context->local_context.capability.flags = 0;
+     537                 :          1 :     spdm_context->last_spdm_request_session_id_valid = false;
+     538                 :          1 :     spdm_context->local_context.capability.flags |=
+     539                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     540                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     541                 :            :         m_libspdm_use_hash_algo;
+     542                 :            : 
+     543         [ +  + ]:          9 :     for (uint8_t index = 0; index < SPDM_MAX_SLOT_COUNT; index++) {
+     544                 :          8 :         spdm_context->local_context.local_cert_chain_provision[index] =
+     545                 :          8 :             &m_libspdm_local_certificate_chain[hash_size *index];
+     546                 :          8 :         spdm_context->local_context.local_cert_chain_provision_size[index] = hash_size;
+     547                 :            :     }
+     548                 :            : 
+     549                 :          1 :     libspdm_set_mem(m_libspdm_local_certificate_chain,
+     550                 :            :                     sizeof(m_libspdm_local_certificate_chain),
+     551                 :            :                     (uint8_t)(0xFF));
+     552                 :            : 
+     553                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     554                 :            :     spdm_context->transcript.message_m.buffer_size =
+     555                 :            :         spdm_context->transcript.message_m.max_buffer_size;
+     556                 :            : #endif
+     557                 :          1 :     spdm_context->connection_info.multi_key_conn_rsp = true;
+     558                 :          1 :     libspdm_reset_message_d(spdm_context);
+     559                 :            : 
+     560                 :          1 :     response_size = sizeof(response);
+     561                 :          1 :     status = libspdm_get_response_digests(spdm_context,
+     562                 :            :                                           m_libspdm_get_digests_request2_size,
+     563                 :            :                                           &m_libspdm_get_digests_request2,
+     564                 :            :                                           &response_size, response);
+     565                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     566                 :          1 :     assert_int_equal(response_size,
+     567                 :            :                      sizeof(spdm_digest_response_t) +
+     568                 :            :                      (hash_size + additional_size) *
+     569                 :            :                      slot_count);
+     570                 :            : 
+     571                 :          1 :     spdm_response = (void *)response;
+     572                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     573                 :            :                      SPDM_DIGESTS);
+     574                 :          1 :     assert_int_equal(spdm_context->transcript.message_d.buffer_size,
+     575                 :            :                      sizeof(spdm_digest_response_t) + (hash_size + additional_size) * slot_count);
+     576                 :            : 
+     577                 :          1 :     digest = (void *)(spdm_response + 1);
+     578                 :          1 :     libspdm_zero_mem (digest, hash_size * slot_count);
+     579                 :          1 :     key_pair_id = (spdm_key_pair_id_t *)((uint8_t *)digest + (hash_size * slot_count));
+     580                 :          1 :     cert_info = (spdm_certificate_info_t *)((uint8_t *)key_pair_id +
+     581                 :          1 :                                             sizeof(spdm_key_pair_id_t) * slot_count);
+     582                 :          1 :     key_usage_bit_mask = (spdm_key_usage_bit_mask_t *)((uint8_t *)cert_info +
+     583                 :          1 :                                                        sizeof(spdm_certificate_info_t) *
+     584                 :            :                                                        slot_count);
+     585         [ +  + ]:          9 :     for (uint8_t index = 0; index < SPDM_MAX_SLOT_COUNT; index++) {
+     586                 :          8 :         assert_memory_equal((void *)&key_pair_id[index],
+     587                 :            :                             (void *)&spdm_context->local_context.local_key_pair_id[index],
+     588                 :            :                             sizeof(spdm_key_pair_id_t));
+     589                 :          8 :         assert_memory_equal((void *)&cert_info[index],
+     590                 :            :                             (void *)&spdm_context->local_context.local_cert_info[index],
+     591                 :            :                             sizeof(spdm_certificate_info_t));
+     592                 :          8 :         assert_memory_equal((void *)&key_usage_bit_mask[index],
+     593                 :            :                             (void *)&spdm_context->local_context.local_key_usage_bit_mask[index],
+     594                 :            :                             sizeof(spdm_key_usage_bit_mask_t));
+     595                 :            :     }
+     596                 :          1 : }
+     597                 :            : 
+     598                 :            : libspdm_test_context_t m_libspdm_responder_digests_test_context = {
+     599                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+     600                 :            :     false,
+     601                 :            : };
+     602                 :            : 
+     603                 :          1 : int libspdm_responder_digests_test_main(void)
+     604                 :            : {
+     605                 :          1 :     const struct CMUnitTest spdm_responder_digests_tests[] = {
+     606                 :            :         /* Success Case*/
+     607                 :            :         cmocka_unit_test(libspdm_test_responder_digests_case1),
+     608                 :            :         /* Can be populated with new test.*/
+     609                 :            :         cmocka_unit_test(libspdm_test_responder_digests_case2),
+     610                 :            :         /* response_state: SPDM_RESPONSE_STATE_BUSY*/
+     611                 :            :         cmocka_unit_test(libspdm_test_responder_digests_case3),
+     612                 :            :         /* response_state: LIBSPDM_RESPONSE_STATE_NEED_RESYNC*/
+     613                 :            :         cmocka_unit_test(libspdm_test_responder_digests_case4),
+     614                 :            :         #if LIBSPDM_RESPOND_IF_READY_SUPPORT
+     615                 :            :         /* response_state: LIBSPDM_RESPONSE_STATE_NOT_READY*/
+     616                 :            :         cmocka_unit_test(libspdm_test_responder_digests_case5),
+     617                 :            :         #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
+     618                 :            :         /* connection_state Check*/
+     619                 :            :         cmocka_unit_test(libspdm_test_responder_digests_case6),
+     620                 :            :         /* No digest to send*/
+     621                 :            :         cmocka_unit_test(libspdm_test_responder_digests_case7),
+     622                 :            :         /* Success Case in a session*/
+     623                 :            :         cmocka_unit_test(libspdm_test_responder_digests_case8),
+     624                 :            :         /* Set multi_key_conn_rsp to check if it responds correctly */
+     625                 :            :         cmocka_unit_test(libspdm_test_responder_digests_case9),
+     626                 :            :         /* Check KeyPairID CertificateInfo and KeyUsageMask*/
+     627                 :            :         cmocka_unit_test(libspdm_test_responder_digests_case10),
+     628                 :            :     };
+     629                 :            : 
+     630                 :          1 :     libspdm_setup_test_context(&m_libspdm_responder_digests_test_context);
+     631                 :            : 
+     632                 :          1 :     return cmocka_run_group_tests(spdm_responder_digests_tests,
+     633                 :            :                                   libspdm_unit_test_group_setup,
+     634                 :            :                                   libspdm_unit_test_group_teardown);
+     635                 :            : }
+     636                 :            : 
+     637                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CERT_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/encap_challenge.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_responder/encap_challenge.c.func-sort-c.html new file mode 100644 index 00000000000..07a55f15893 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/encap_challenge.c.func-sort-c.html @@ -0,0 +1,109 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/encap_challenge.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - encap_challenge.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:224224100.0 %
Date:2024-09-22 08:21:07Functions:77100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_encap_challenge_auth_test_main1
libspdm_test_responder_encap_challenge_case11
libspdm_test_responder_encap_challenge_case21
libspdm_test_responder_encap_challenge_case31
libspdm_test_responder_encap_challenge_case41
libspdm_test_responder_encap_challenge_case51
libspdm_test_responder_encap_challenge_case61
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/encap_challenge.c.func.html b/coverage_log/unit_test/test_spdm_responder/encap_challenge.c.func.html new file mode 100644 index 00000000000..759513136b1 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/encap_challenge.c.func.html @@ -0,0 +1,109 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/encap_challenge.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - encap_challenge.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:224224100.0 %
Date:2024-09-22 08:21:07Functions:77100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_encap_challenge_auth_test_main1
libspdm_test_responder_encap_challenge_case11
libspdm_test_responder_encap_challenge_case21
libspdm_test_responder_encap_challenge_case31
libspdm_test_responder_encap_challenge_case41
libspdm_test_responder_encap_challenge_case51
libspdm_test_responder_encap_challenge_case61
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/encap_challenge.c.gcov.html b/coverage_log/unit_test/test_spdm_responder/encap_challenge.c.gcov.html new file mode 100644 index 00000000000..148d5b059c9 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/encap_challenge.c.gcov.html @@ -0,0 +1,593 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/encap_challenge.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - encap_challenge.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:224224100.0 %
Date:2024-09-22 08:21:07Functions:77100.0 %
Branches:00-
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_responder_lib.h"
+       9                 :            : 
+      10                 :            : #if (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP) && \
+      11                 :            :     (LIBSPDM_SEND_CHALLENGE_SUPPORT)
+      12                 :            : 
+      13                 :            : static uint8_t m_requester_context[SPDM_REQ_CONTEXT_SIZE];
+      14                 :            : 
+      15                 :          1 : void libspdm_test_responder_encap_challenge_case1(void **state)
+      16                 :            : {
+      17                 :            :     libspdm_return_t status;
+      18                 :            :     libspdm_test_context_t *spdm_test_context;
+      19                 :            :     libspdm_context_t *spdm_context;
+      20                 :            :     spdm_challenge_auth_response_t *spdm_response;
+      21                 :            :     uint8_t temp_buf[LIBSPDM_SENDER_BUFFER_SIZE];
+      22                 :            :     uint8_t *ptr;
+      23                 :            :     size_t response_size;
+      24                 :            :     size_t sig_size;
+      25                 :            :     bool need_continue;
+      26                 :            :     void *data;
+      27                 :            :     size_t data_size;
+      28                 :            : 
+      29                 :          1 :     spdm_test_context = *state;
+      30                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+      31                 :            : 
+      32                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+      33                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+      34                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+      35                 :          1 :     spdm_context->connection_info.capability.flags = 0;
+      36                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
+      37                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+      38                 :          1 :     spdm_context->connection_info.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+      39                 :          1 :     libspdm_read_requester_public_certificate_chain(m_libspdm_use_hash_algo,
+      40                 :            :                                                     m_libspdm_use_req_asym_algo, &data,
+      41                 :            :                                                     &data_size,
+      42                 :            :                                                     NULL, NULL);
+      43                 :          1 :     libspdm_reset_message_mut_c(spdm_context);
+      44                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+      45                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
+      46                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+      47                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+      48                 :            :                      data, data_size);
+      49                 :            : #else
+      50                 :          1 :     libspdm_hash_all(
+      51                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+      52                 :            :         data, data_size,
+      53                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+      54                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+      55                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+      56                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+      57                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+      58                 :          1 :         spdm_context->connection_info.algorithm.req_base_asym_alg,
+      59                 :            :         data, data_size,
+      60                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+      61                 :            : #endif
+      62                 :          1 :     spdm_context->encap_context.req_slot_id = 0;
+      63                 :            : 
+      64                 :          1 :     sig_size = libspdm_get_asym_signature_size(m_libspdm_use_req_asym_algo);
+      65                 :          1 :     response_size = sizeof(spdm_challenge_auth_response_t) +
+      66                 :          1 :                     libspdm_get_hash_size(m_libspdm_use_hash_algo) +
+      67                 :          1 :                     SPDM_NONCE_SIZE + 0 + sizeof(uint16_t) + 0 + sig_size;
+      68                 :          1 :     spdm_response = (void *)temp_buf;
+      69                 :          1 :     spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+      70                 :          1 :     spdm_response->header.request_response_code = SPDM_CHALLENGE_AUTH;
+      71                 :          1 :     spdm_response->header.param1 = 0;
+      72                 :          1 :     spdm_response->header.param2 = (1 << 0);
+      73                 :            : 
+      74                 :          1 :     ptr = (void *)(spdm_response + 1);
+      75                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, data, data_size, ptr);
+      76                 :          1 :     ptr += libspdm_get_hash_size(m_libspdm_use_hash_algo);
+      77                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
+      78                 :          1 :     ptr += SPDM_NONCE_SIZE;
+      79                 :            : 
+      80                 :          1 :     *(uint16_t *)ptr = 0;
+      81                 :          1 :     ptr += sizeof(uint16_t);
+      82                 :            : 
+      83                 :          1 :     libspdm_requester_data_sign(
+      84                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+      85                 :            :         spdm_context,
+      86                 :            : #endif
+      87                 :          1 :         spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+      88                 :            :             SPDM_CHALLENGE_AUTH,
+      89                 :            :             m_libspdm_use_req_asym_algo, m_libspdm_use_hash_algo,
+      90                 :            :             false, (uint8_t*)spdm_response, response_size - sig_size,
+      91                 :            :             ptr, &sig_size);
+      92                 :            : 
+      93                 :          1 :     status =  libspdm_process_encap_response_challenge_auth(spdm_context, response_size,
+      94                 :            :                                                             spdm_response,
+      95                 :            :                                                             &need_continue);
+      96                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+      97                 :            :     /* Completion of CHALLENGE sets M1/M2 to null. */
+      98                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+      99                 :            :     assert_int_equal(spdm_context->transcript.message_mut_c.buffer_size, 0);
+     100                 :            : #else
+     101                 :          1 :     assert_null(spdm_context->transcript.digest_context_mut_m1m2);
+     102                 :            : #endif
+     103                 :          1 :     free(data);
+     104                 :          1 : }
+     105                 :            : 
+     106                 :          1 : void libspdm_test_responder_encap_challenge_case2(void **state)
+     107                 :            : {
+     108                 :            :     libspdm_return_t status;
+     109                 :            :     libspdm_test_context_t *spdm_test_context;
+     110                 :            :     libspdm_context_t *spdm_context;
+     111                 :            :     spdm_error_response_t *spdm_response;
+     112                 :            :     uint8_t temp_buf[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     113                 :            :     size_t response_size;
+     114                 :            :     void *data;
+     115                 :            :     size_t data_size;
+     116                 :            : 
+     117                 :          1 :     spdm_test_context = *state;
+     118                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     119                 :            : 
+     120                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     121                 :          1 :     spdm_context->connection_info.capability.flags = 0;
+     122                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
+     123                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     124                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     125                 :            :                                                     &data_size,
+     126                 :            :                                                     NULL, NULL);
+     127                 :          1 :     libspdm_reset_message_a(spdm_context);
+     128                 :          1 :     libspdm_reset_message_b(spdm_context);
+     129                 :          1 :     libspdm_reset_message_c(spdm_context);
+     130                 :            : 
+     131                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     132                 :          1 :     spdm_context->connection_info.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+     133                 :            : 
+     134                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     135                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     136                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     137                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
+     138                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+     139                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+     140                 :            :                      data, data_size);
+     141                 :            : #else
+     142                 :          1 :     libspdm_hash_all(
+     143                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+     144                 :            :         data, data_size,
+     145                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+     146                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+     147                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+     148                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+     149                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+     150                 :          1 :         spdm_context->connection_info.algorithm.req_base_asym_alg,
+     151                 :            :         data, data_size,
+     152                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+     153                 :            : #endif
+     154                 :          1 :     spdm_context->encap_context.req_slot_id = 0;
+     155                 :            : 
+     156                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
+     157                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     158                 :            : 
+     159                 :          1 :     response_size = sizeof(spdm_error_response_t);
+     160                 :          1 :     spdm_response = (void *)temp_buf;
+     161                 :          1 :     spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     162                 :          1 :     spdm_response->header.request_response_code = SPDM_ERROR;
+     163                 :          1 :     spdm_response->header.param1 = 0;
+     164                 :          1 :     spdm_response->header.param2 = 0;
+     165                 :            : 
+     166                 :          1 :     status =   libspdm_process_encap_response_challenge_auth(spdm_context, response_size,
+     167                 :            :                                                              spdm_response,
+     168                 :            :                                                              NULL);
+     169                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_UNSUPPORTED_CAP);
+     170                 :          1 :     free(data);
+     171                 :          1 : }
+     172                 :            : 
+     173                 :            : 
+     174                 :          1 : void libspdm_test_responder_encap_challenge_case3(void **state)
+     175                 :            : {
+     176                 :            :     libspdm_return_t status;
+     177                 :            :     libspdm_test_context_t *spdm_test_context;
+     178                 :            :     libspdm_context_t *spdm_context;
+     179                 :            :     spdm_challenge_auth_response_t *spdm_response;
+     180                 :            :     uint8_t temp_buf[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     181                 :            :     size_t response_size;
+     182                 :            :     void *data;
+     183                 :            :     size_t data_size;
+     184                 :            : 
+     185                 :          1 :     spdm_test_context = *state;
+     186                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     187                 :            : 
+     188                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     189                 :          1 :     spdm_context->connection_info.capability.flags = 0;
+     190                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
+     191                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     192                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     193                 :            :                                                     &data_size,
+     194                 :            :                                                     NULL, NULL);
+     195                 :          1 :     libspdm_reset_message_a(spdm_context);
+     196                 :          1 :     libspdm_reset_message_b(spdm_context);
+     197                 :          1 :     libspdm_reset_message_c(spdm_context);
+     198                 :            : 
+     199                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     200                 :          1 :     spdm_context->connection_info.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+     201                 :            : 
+     202                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     203                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     204                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     205                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
+     206                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+     207                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+     208                 :            :                      data, data_size);
+     209                 :            : #else
+     210                 :          1 :     libspdm_hash_all(
+     211                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+     212                 :            :         data, data_size,
+     213                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+     214                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+     215                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+     216                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+     217                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+     218                 :          1 :         spdm_context->connection_info.algorithm.req_base_asym_alg,
+     219                 :            :         data, data_size,
+     220                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+     221                 :            : #endif
+     222                 :          1 :     spdm_context->encap_context.req_slot_id = 0;
+     223                 :            : 
+     224                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
+     225                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     226                 :            : 
+     227                 :          1 :     response_size = sizeof(spdm_error_response_t);
+     228                 :          1 :     spdm_response = (void *)temp_buf;
+     229                 :          1 :     spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     230                 :          1 :     spdm_response->header.request_response_code = SPDM_CERTIFICATE;
+     231                 :          1 :     spdm_response->header.param1 = 0;
+     232                 :          1 :     spdm_response->header.param2 = 0;
+     233                 :            : 
+     234                 :          1 :     status =   libspdm_process_encap_response_challenge_auth(spdm_context, response_size,
+     235                 :            :                                                              spdm_response,
+     236                 :            :                                                              NULL);
+     237                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+     238                 :          1 :     free(data);
+     239                 :          1 : }
+     240                 :            : 
+     241                 :          1 : void libspdm_test_responder_encap_challenge_case4(void **state)
+     242                 :            : {
+     243                 :            :     libspdm_return_t status;
+     244                 :            :     libspdm_test_context_t *spdm_test_context;
+     245                 :            :     libspdm_context_t *spdm_context;
+     246                 :            :     spdm_challenge_auth_response_t *spdm_response;
+     247                 :            :     uint8_t temp_buf[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     248                 :            :     size_t response_size;
+     249                 :            :     void *data;
+     250                 :            :     size_t data_size;
+     251                 :            : 
+     252                 :          1 :     spdm_test_context = *state;
+     253                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     254                 :            : 
+     255                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     256                 :          1 :     spdm_context->connection_info.capability.flags = 0;
+     257                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
+     258                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     259                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     260                 :            :                                                     &data_size,
+     261                 :            :                                                     NULL, NULL);
+     262                 :          1 :     libspdm_reset_message_a(spdm_context);
+     263                 :          1 :     libspdm_reset_message_b(spdm_context);
+     264                 :          1 :     libspdm_reset_message_c(spdm_context);
+     265                 :            : 
+     266                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     267                 :          1 :     spdm_context->connection_info.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+     268                 :            : 
+     269                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     270                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     271                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     272                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
+     273                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+     274                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+     275                 :            :                      data, data_size);
+     276                 :            : #else
+     277                 :          1 :     libspdm_hash_all(
+     278                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+     279                 :            :         data, data_size,
+     280                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+     281                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+     282                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+     283                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+     284                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+     285                 :          1 :         spdm_context->connection_info.algorithm.req_base_asym_alg,
+     286                 :            :         data, data_size,
+     287                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+     288                 :            : #endif
+     289                 :          1 :     spdm_context->encap_context.req_slot_id = 0;
+     290                 :            : 
+     291                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
+     292                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     293                 :            : 
+     294                 :          1 :     response_size = sizeof(spdm_error_response_t);
+     295                 :          1 :     spdm_response = (void *)temp_buf;
+     296                 :          1 :     spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     297                 :          1 :     spdm_response->header.request_response_code = SPDM_CHALLENGE_AUTH;
+     298                 :          1 :     spdm_response->header.param1 = 0;
+     299                 :          1 :     spdm_response->header.param2 = 0;
+     300                 :            : 
+     301                 :          1 :     status =   libspdm_process_encap_response_challenge_auth(spdm_context, response_size,
+     302                 :            :                                                              spdm_response,
+     303                 :            :                                                              NULL);
+     304                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+     305                 :          1 :     free(data);
+     306                 :          1 : }
+     307                 :            : 
+     308                 :          1 : void libspdm_test_responder_encap_challenge_case5(void **state)
+     309                 :            : {
+     310                 :            :     libspdm_return_t status;
+     311                 :            :     libspdm_test_context_t *spdm_test_context;
+     312                 :            :     libspdm_context_t *spdm_context;
+     313                 :            :     spdm_challenge_auth_response_t *spdm_response;
+     314                 :            :     uint8_t temp_buf[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     315                 :            :     size_t response_size;
+     316                 :            :     size_t sig_size;
+     317                 :            :     uint8_t *ptr;
+     318                 :            :     bool need_continue;
+     319                 :            :     void *data;
+     320                 :            :     size_t data_size;
+     321                 :            : 
+     322                 :          1 :     spdm_test_context = *state;
+     323                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     324                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     325                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     326                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     327                 :          1 :     spdm_context->connection_info.capability.flags = 0;
+     328                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
+     329                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     330                 :          1 :     spdm_context->connection_info.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+     331                 :            : 
+     332                 :          1 :     libspdm_read_requester_public_key(m_libspdm_use_req_asym_algo, &data, &data_size);
+     333                 :          1 :     spdm_context->local_context.peer_public_key_provision = data;
+     334                 :          1 :     spdm_context->local_context.peer_public_key_provision_size = data_size;
+     335                 :            : 
+     336                 :          1 :     spdm_context->encap_context.req_slot_id = 0xFF;
+     337                 :            : 
+     338                 :          1 :     libspdm_reset_message_a(spdm_context);
+     339                 :          1 :     libspdm_reset_message_b(spdm_context);
+     340                 :          1 :     libspdm_reset_message_c(spdm_context);
+     341                 :            : 
+     342                 :          1 :     sig_size = libspdm_get_asym_signature_size(m_libspdm_use_req_asym_algo);
+     343                 :          1 :     response_size = sizeof(spdm_challenge_auth_response_t) +
+     344                 :          1 :                     libspdm_get_hash_size(m_libspdm_use_hash_algo) +
+     345                 :          1 :                     SPDM_NONCE_SIZE + 0 + sizeof(uint16_t) + 0 + sig_size;
+     346                 :          1 :     spdm_response = (void *)temp_buf;
+     347                 :          1 :     spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     348                 :          1 :     spdm_response->header.request_response_code = SPDM_CHALLENGE_AUTH;
+     349                 :          1 :     spdm_response->header.param1 = (0xFF & SPDM_CHALLENGE_AUTH_RESPONSE_ATTRIBUTE_SLOT_ID_MASK);
+     350                 :          1 :     spdm_response->header.param2 = 0;
+     351                 :            : 
+     352                 :          1 :     ptr = (void *)(spdm_response + 1);
+     353                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, data, data_size, ptr);
+     354                 :          1 :     ptr += libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     355                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
+     356                 :          1 :     ptr += SPDM_NONCE_SIZE;
+     357                 :            : 
+     358                 :          1 :     *(uint16_t *)ptr = 0;
+     359                 :          1 :     ptr += sizeof(uint16_t);
+     360                 :            : 
+     361                 :          1 :     libspdm_requester_data_sign(
+     362                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+     363                 :            :         spdm_context,
+     364                 :            : #endif
+     365                 :          1 :         spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     366                 :            :             SPDM_CHALLENGE_AUTH,
+     367                 :            :             m_libspdm_use_req_asym_algo, m_libspdm_use_hash_algo,
+     368                 :            :             false, (uint8_t*)spdm_response, response_size - sig_size,
+     369                 :            :             ptr, &sig_size);
+     370                 :            : 
+     371                 :          1 :     status = libspdm_process_encap_response_challenge_auth(spdm_context, response_size,
+     372                 :            :                                                            spdm_response,
+     373                 :            :                                                            &need_continue);
+     374                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     375                 :          1 :     free(data);
+     376                 :          1 : }
+     377                 :            : 
+     378                 :            : /**
+     379                 :            :  * Test 6: Successful case , With the correct challenge context field
+     380                 :            :  * Expected Behavior: client returns a status of RETURN_SUCCESS.
+     381                 :            :  **/
+     382                 :          1 : void libspdm_test_responder_encap_challenge_case6(void **state)
+     383                 :            : {
+     384                 :            :     libspdm_return_t status;
+     385                 :            :     libspdm_test_context_t *spdm_test_context;
+     386                 :            :     libspdm_context_t *spdm_context;
+     387                 :            :     spdm_challenge_auth_response_t *spdm_response;
+     388                 :            :     uint8_t temp_buf[LIBSPDM_SENDER_BUFFER_SIZE];
+     389                 :            :     uint8_t *ptr;
+     390                 :            :     size_t response_size;
+     391                 :            :     size_t sig_size;
+     392                 :            :     bool need_continue;
+     393                 :            :     void *data;
+     394                 :            :     size_t data_size;
+     395                 :            : 
+     396                 :          1 :     spdm_test_context = *state;
+     397                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     398                 :            : 
+     399                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+     400                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     401                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     402                 :          1 :     spdm_context->connection_info.capability.flags = 0;
+     403                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
+     404                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     405                 :          1 :     spdm_context->connection_info.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
+     406                 :          1 :     libspdm_read_requester_public_certificate_chain(m_libspdm_use_hash_algo,
+     407                 :            :                                                     m_libspdm_use_req_asym_algo, &data,
+     408                 :            :                                                     &data_size,
+     409                 :            :                                                     NULL, NULL);
+     410                 :          1 :     libspdm_reset_message_mut_c(spdm_context);
+     411                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     412                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
+     413                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+     414                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+     415                 :            :                      data, data_size);
+     416                 :            : #else
+     417                 :          1 :     libspdm_hash_all(
+     418                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+     419                 :            :         data, data_size,
+     420                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+     421                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+     422                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+     423                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+     424                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+     425                 :          1 :         spdm_context->connection_info.algorithm.req_base_asym_alg,
+     426                 :            :         data, data_size,
+     427                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+     428                 :            : #endif
+     429                 :          1 :     spdm_context->encap_context.req_slot_id = 0;
+     430                 :          1 :     libspdm_set_mem(m_requester_context, SPDM_REQ_CONTEXT_SIZE, 0xAA);
+     431                 :          1 :     libspdm_copy_mem(spdm_context->encap_context.req_context, SPDM_REQ_CONTEXT_SIZE,
+     432                 :            :                      m_requester_context, SPDM_REQ_CONTEXT_SIZE);
+     433                 :            : 
+     434                 :            : 
+     435                 :          1 :     sig_size = libspdm_get_asym_signature_size(m_libspdm_use_req_asym_algo);
+     436                 :          1 :     response_size = sizeof(spdm_challenge_auth_response_t) +
+     437                 :          1 :                     libspdm_get_hash_size(m_libspdm_use_hash_algo) +
+     438                 :          1 :                     SPDM_NONCE_SIZE + 0 + sizeof(uint16_t) + 0 + SPDM_REQ_CONTEXT_SIZE + sig_size;
+     439                 :          1 :     spdm_response = (void *)temp_buf;
+     440                 :          1 :     spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+     441                 :          1 :     spdm_response->header.request_response_code = SPDM_CHALLENGE_AUTH;
+     442                 :          1 :     spdm_response->header.param1 = 0;
+     443                 :          1 :     spdm_response->header.param2 = (1 << 0);
+     444                 :            : 
+     445                 :          1 :     ptr = (void *)(spdm_response + 1);
+     446                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, data, data_size, ptr);
+     447                 :          1 :     ptr += libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     448                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
+     449                 :          1 :     ptr += SPDM_NONCE_SIZE;
+     450                 :            : 
+     451                 :          1 :     *(uint16_t *)ptr = 0;
+     452                 :          1 :     ptr += sizeof(uint16_t);
+     453                 :            : 
+     454                 :          1 :     libspdm_set_mem(ptr, SPDM_REQ_CONTEXT_SIZE, 0xAA);
+     455                 :          1 :     ptr += SPDM_REQ_CONTEXT_SIZE;
+     456                 :            : 
+     457                 :          1 :     libspdm_requester_data_sign(
+     458                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+     459                 :            :         spdm_context,
+     460                 :            : #endif
+     461                 :          1 :         spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+     462                 :            :             SPDM_CHALLENGE_AUTH,
+     463                 :            :             m_libspdm_use_req_asym_algo, m_libspdm_use_hash_algo,
+     464                 :            :             false, (uint8_t*)spdm_response, response_size - sig_size,
+     465                 :            :             ptr, &sig_size);
+     466                 :            : 
+     467                 :          1 :     status =  libspdm_process_encap_response_challenge_auth(spdm_context, response_size,
+     468                 :            :                                                             spdm_response,
+     469                 :            :                                                             &need_continue);
+     470                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     471                 :            : 
+     472                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     473                 :            :     assert_int_equal(spdm_context->transcript.message_mut_c.buffer_size, 0);
+     474                 :            : #else
+     475                 :          1 :     assert_null(spdm_context->transcript.digest_context_mut_m1m2);
+     476                 :            : #endif
+     477                 :          1 :     free(data);
+     478                 :          1 : }
+     479                 :            : 
+     480                 :            : libspdm_test_context_t m_libspdm_responder_encap_challenge_test_context = {
+     481                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+     482                 :            :     false,
+     483                 :            : };
+     484                 :            : 
+     485                 :          1 : int libspdm_responder_encap_challenge_auth_test_main(void)
+     486                 :            : {
+     487                 :          1 :     const struct CMUnitTest spdm_responder_challenge_tests[] = {
+     488                 :            :         cmocka_unit_test(libspdm_test_responder_encap_challenge_case1),
+     489                 :            :         /* Error response: SPDM_ERROR*/
+     490                 :            :         cmocka_unit_test(libspdm_test_responder_encap_challenge_case2),
+     491                 :            :         /* Error request_response_code  : SPDM_CERTIFICATE */
+     492                 :            :         cmocka_unit_test(libspdm_test_responder_encap_challenge_case3),
+     493                 :            :         /* Error spdm_response_size */
+     494                 :            :         cmocka_unit_test(libspdm_test_responder_encap_challenge_case4),
+     495                 :            :         /* Success Case, use provisioned public key (slot 0xFF) */
+     496                 :            :         cmocka_unit_test(libspdm_test_responder_encap_challenge_case5),
+     497                 :            :         /* Success Case, V1.3 With the correct challenge context field */
+     498                 :            :         cmocka_unit_test(libspdm_test_responder_encap_challenge_case6),
+     499                 :            :     };
+     500                 :            : 
+     501                 :          1 :     libspdm_setup_test_context(&m_libspdm_responder_encap_challenge_test_context);
+     502                 :            : 
+     503                 :          1 :     return cmocka_run_group_tests(spdm_responder_challenge_tests,
+     504                 :            :                                   libspdm_unit_test_group_setup,
+     505                 :            :                                   libspdm_unit_test_group_teardown);
+     506                 :            : }
+     507                 :            : 
+     508                 :            : #endif /* (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (...) */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/encap_get_certificate.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_responder/encap_get_certificate.c.func-sort-c.html new file mode 100644 index 00000000000..d6bb97f58c6 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/encap_get_certificate.c.func-sort-c.html @@ -0,0 +1,105 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/encap_get_certificate.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - encap_get_certificate.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:262262100.0 %
Date:2024-09-22 08:21:07Functions:66100.0 %
Branches:3650.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
spdm_responder_encap_get_certificate_test_main1
test_spdm_responder_encap_get_certificate_case11
test_spdm_responder_encap_get_certificate_case31
test_spdm_responder_encap_get_certificate_case41
test_spdm_responder_encap_get_certificate_case51
test_spdm_responder_encap_get_certificate_case22
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/encap_get_certificate.c.func.html b/coverage_log/unit_test/test_spdm_responder/encap_get_certificate.c.func.html new file mode 100644 index 00000000000..dbd71a567ad --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/encap_get_certificate.c.func.html @@ -0,0 +1,105 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/encap_get_certificate.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - encap_get_certificate.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:262262100.0 %
Date:2024-09-22 08:21:07Functions:66100.0 %
Branches:3650.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
spdm_responder_encap_get_certificate_test_main1
test_spdm_responder_encap_get_certificate_case11
test_spdm_responder_encap_get_certificate_case22
test_spdm_responder_encap_get_certificate_case31
test_spdm_responder_encap_get_certificate_case41
test_spdm_responder_encap_get_certificate_case51
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/encap_get_certificate.c.gcov.html b/coverage_log/unit_test/test_spdm_responder/encap_get_certificate.c.gcov.html new file mode 100644 index 00000000000..723c78b9ecd --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/encap_get_certificate.c.gcov.html @@ -0,0 +1,689 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/encap_get_certificate.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - encap_get_certificate.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:262262100.0 %
Date:2024-09-22 08:21:07Functions:66100.0 %
Branches:3650.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 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                 :            : #include "spdm_unit_test.h"
+       7                 :            : #include "internal/libspdm_responder_lib.h"
+       8                 :            : 
+       9                 :            : #if (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP) && \
+      10                 :            :     (LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT)
+      11                 :            : 
+      12                 :            : static void *m_libspdm_local_certificate_chain;
+      13                 :            : static size_t m_libspdm_local_certificate_chain_size;
+      14                 :            : 
+      15                 :            : spdm_certificate_response_t m_spdm_get_certificate_response1;
+      16                 :            : size_t m_spdm_get_certificate_response1_size;
+      17                 :            : 
+      18                 :            : spdm_certificate_response_t m_spdm_get_certificate_response2 = {
+      19                 :            :     {SPDM_MESSAGE_VERSION_10, SPDM_ERROR, SPDM_ERROR_CODE_INVALID_REQUEST, 0},
+      20                 :            :     0,
+      21                 :            :     0
+      22                 :            : };
+      23                 :            : size_t m_spdm_get_certificate_response2_size = sizeof(m_spdm_get_certificate_response2);
+      24                 :            : 
+      25                 :            : /**
+      26                 :            :  * Test 1: Normal case, request a certificate chain
+      27                 :            :  * Expected Behavior: receives a valid certificate chain with the correct number of Certificate messages
+      28                 :            :  **/
+      29                 :          1 : void test_spdm_responder_encap_get_certificate_case1(void **state)
+      30                 :            : {
+      31                 :            :     libspdm_return_t status;
+      32                 :            :     libspdm_test_context_t *spdm_test_context;
+      33                 :            :     libspdm_context_t *spdm_context;
+      34                 :            :     void *data;
+      35                 :            :     size_t data_size;
+      36                 :            :     void *hash;
+      37                 :            :     size_t hash_size;
+      38                 :            :     const uint8_t *root_cert;
+      39                 :            :     size_t root_cert_size;
+      40                 :            :     bool need_continue;
+      41                 :            :     spdm_certificate_response_t *spdm_response;
+      42                 :            :     uint8_t temp_buf[LIBSPDM_MAX_SPDM_MSG_SIZE];
+      43                 :            :     size_t temp_buf_size;
+      44                 :            :     uint16_t portion_length;
+      45                 :            :     uint16_t remainder_length;
+      46                 :            :     static size_t calling_index = 0;
+      47                 :            :     size_t spdm_response_size;
+      48                 :            : 
+      49                 :          1 :     spdm_test_context = *state;
+      50                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+      51                 :          1 :     spdm_test_context->case_id = 0x1;
+      52                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+      53                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+      54                 :          1 :     spdm_context->connection_info.capability.flags |=
+      55                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+      56                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+      57                 :            :                                                     m_libspdm_use_asym_algo, &data,
+      58                 :            :                                                     &data_size, &hash, &hash_size);
+      59                 :          1 :     libspdm_x509_get_cert_from_cert_chain((uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size,
+      60                 :          1 :                                           data_size - sizeof(spdm_cert_chain_t) - hash_size, 0,
+      61                 :            :                                           &root_cert, &root_cert_size);
+      62                 :          1 :     libspdm_dump_hex(
+      63                 :            :         root_cert,
+      64                 :            :         root_cert_size);
+      65                 :          1 :     spdm_context->local_context.peer_root_cert_provision_size[0] =
+      66                 :            :         root_cert_size;
+      67                 :          1 :     spdm_context->local_context.peer_root_cert_provision[0] = root_cert;
+      68                 :          1 :     libspdm_reset_message_b(spdm_context);
+      69                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+      70                 :            :         m_libspdm_use_hash_algo;
+      71                 :            : 
+      72                 :          1 :     spdm_context->connection_info.algorithm.req_base_asym_alg =
+      73                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256;
+      74                 :            : 
+      75         [ +  - ]:          1 :     if (m_libspdm_local_certificate_chain == NULL) {
+      76                 :          1 :         libspdm_read_responder_public_certificate_chain(
+      77                 :            :             m_libspdm_use_hash_algo, m_libspdm_use_asym_algo,
+      78                 :            :             &m_libspdm_local_certificate_chain,
+      79                 :            :             &m_libspdm_local_certificate_chain_size, NULL, NULL);
+      80                 :            :     }
+      81                 :            : 
+      82                 :          1 :     portion_length = LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN;
+      83                 :          1 :     remainder_length =
+      84                 :          1 :         (uint16_t)(m_libspdm_local_certificate_chain_size -
+      85                 :            :                    LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN *
+      86                 :          1 :                    (calling_index + 1));
+      87                 :            : 
+      88                 :          1 :     temp_buf_size =
+      89                 :          1 :         sizeof(spdm_certificate_response_t) + portion_length;
+      90                 :          1 :     spdm_response_size = temp_buf_size;
+      91                 :          1 :     spdm_response = (void *)temp_buf;
+      92                 :            : 
+      93                 :          1 :     spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+      94                 :          1 :     spdm_response->header.request_response_code = SPDM_CERTIFICATE;
+      95                 :          1 :     spdm_response->header.param1 = 0;
+      96                 :          1 :     spdm_response->header.param2 = 0;
+      97                 :          1 :     spdm_response->portion_length = portion_length;
+      98                 :          1 :     spdm_response->remainder_length = remainder_length;
+      99                 :          1 :     libspdm_copy_mem(spdm_response + 1,
+     100                 :            :                      sizeof(temp_buf) - sizeof(*spdm_response),
+     101                 :          1 :                      (uint8_t *)m_libspdm_local_certificate_chain +
+     102                 :          1 :                      LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN * calling_index,
+     103                 :            :                      portion_length);
+     104                 :            : 
+     105                 :          1 :     free(m_libspdm_local_certificate_chain);
+     106                 :          1 :     m_libspdm_local_certificate_chain = NULL;
+     107                 :          1 :     m_libspdm_local_certificate_chain_size = 0;
+     108                 :            : 
+     109                 :          1 :     status = libspdm_process_encap_response_certificate(spdm_context, spdm_response_size,
+     110                 :            :                                                         spdm_response,
+     111                 :            :                                                         &need_continue);
+     112                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     113                 :            : 
+     114                 :          1 :     spdm_context->mut_auth_cert_chain_buffer_size = 0;
+     115                 :          1 :     free(data);
+     116                 :          1 : }
+     117                 :            : 
+     118                 :            : 
+     119                 :            : /**
+     120                 :            :  * Test 2: force responder to send an ERROR message with code SPDM_ERROR_CODE_INVALID_REQUEST
+     121                 :            :  * Expected Behavior: get a RETURN_DEVICE_ERROR, with no CERTIFICATE messages received (checked in transcript.message_b buffer)
+     122                 :            :  **/
+     123                 :          2 : void test_spdm_responder_encap_get_certificate_case2(void **state)
+     124                 :            : {
+     125                 :            :     libspdm_return_t status;
+     126                 :            :     libspdm_test_context_t *spdm_test_context;
+     127                 :            :     libspdm_context_t *spdm_context;
+     128                 :            : 
+     129                 :            :     void *data;
+     130                 :            :     size_t data_size;
+     131                 :            :     void *hash;
+     132                 :            :     size_t hash_size;
+     133                 :            :     const uint8_t *root_cert;
+     134                 :            :     size_t root_cert_size;
+     135                 :            :     bool need_continue;
+     136                 :            : 
+     137                 :          2 :     spdm_test_context = *state;
+     138                 :          2 :     spdm_context = spdm_test_context->spdm_context;
+     139                 :          2 :     spdm_test_context->case_id = 0x2;
+     140                 :          2 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+     141                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     142                 :          2 :     spdm_context->connection_info.connection_state =
+     143                 :            :         LIBSPDM_CONNECTION_STATE_AFTER_DIGESTS;
+     144                 :          2 :     spdm_context->connection_info.capability.flags |=
+     145                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     146                 :          2 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     147                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     148                 :            :                                                     &data_size, &hash, &hash_size);
+     149                 :          2 :     libspdm_x509_get_cert_from_cert_chain((uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size,
+     150                 :          2 :                                           data_size - sizeof(spdm_cert_chain_t) - hash_size, 0,
+     151                 :            :                                           &root_cert, &root_cert_size);
+     152                 :          2 :     spdm_context->local_context.peer_root_cert_provision_size[0] =
+     153                 :            :         root_cert_size;
+     154                 :          2 :     spdm_context->local_context.peer_root_cert_provision[0] = root_cert;
+     155                 :          2 :     libspdm_reset_message_b(spdm_context);
+     156                 :          2 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     157                 :            :         m_libspdm_use_hash_algo;
+     158                 :            : 
+     159                 :          2 :     spdm_context->connection_info.algorithm.req_base_asym_alg =
+     160                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256;
+     161                 :            : 
+     162                 :          2 :     status = libspdm_process_encap_response_certificate(spdm_context,
+     163                 :            :                                                         m_spdm_get_certificate_response2_size,
+     164                 :            :                                                         &m_spdm_get_certificate_response2,
+     165                 :            :                                                         &need_continue);
+     166                 :          2 :     assert_int_equal(status, LIBSPDM_STATUS_UNSUPPORTED_CAP);
+     167                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     168                 :            :     assert_int_equal(spdm_context->transcript.message_b.buffer_size, 0);
+     169                 :            : #endif
+     170                 :            : 
+     171                 :          2 :     spdm_context->mut_auth_cert_chain_buffer_size = 0;
+     172                 :          2 :     free(data);
+     173                 :          2 : }
+     174                 :            : 
+     175                 :            : /**
+     176                 :            :  * Test 3: Fail case, request a certificate chain,
+     177                 :            :  * spdm_request.offset + spdm_response.portion_length + spdm_response.remainder_length !=
+     178                 :            :  * total_responder_cert_chain_buffer_length.
+     179                 :            :  * Expected Behavior:returns a status of RETURN_DEVICE_ERROR.
+     180                 :            :  **/
+     181                 :          1 : void test_spdm_responder_encap_get_certificate_case3(void **state)
+     182                 :            : {
+     183                 :            :     libspdm_return_t status;
+     184                 :            :     libspdm_test_context_t *spdm_test_context;
+     185                 :            :     libspdm_context_t *spdm_context;
+     186                 :            :     void *data;
+     187                 :            :     size_t data_size;
+     188                 :            :     void *hash;
+     189                 :            :     size_t hash_size;
+     190                 :            :     const uint8_t *root_cert;
+     191                 :            :     size_t root_cert_size;
+     192                 :            :     bool need_continue;
+     193                 :            :     spdm_certificate_response_t *spdm_response;
+     194                 :            :     uint8_t temp_buf[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     195                 :            :     size_t temp_buf_size;
+     196                 :            :     uint16_t portion_length;
+     197                 :            :     uint16_t remainder_length;
+     198                 :            :     static size_t calling_index = 0;
+     199                 :            :     size_t spdm_response_size;
+     200                 :            : 
+     201                 :          1 :     spdm_test_context = *state;
+     202                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     203                 :          1 :     spdm_test_context->case_id = 0x3;
+     204                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+     205                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     206                 :          1 :     spdm_context->connection_info.capability.flags |=
+     207                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     208                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     209                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     210                 :            :                                                     &data_size, &hash, &hash_size);
+     211                 :          1 :     libspdm_x509_get_cert_from_cert_chain((uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size,
+     212                 :          1 :                                           data_size - sizeof(spdm_cert_chain_t) - hash_size, 0,
+     213                 :            :                                           &root_cert, &root_cert_size);
+     214                 :          1 :     libspdm_dump_hex(
+     215                 :            :         root_cert,
+     216                 :            :         root_cert_size);
+     217                 :          1 :     spdm_context->local_context.peer_root_cert_provision_size[0] =
+     218                 :            :         root_cert_size;
+     219                 :          1 :     spdm_context->local_context.peer_root_cert_provision[0] = root_cert;
+     220                 :          1 :     libspdm_reset_message_b(spdm_context);
+     221                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     222                 :            :         m_libspdm_use_hash_algo;
+     223                 :            : 
+     224                 :            : 
+     225                 :          1 :     spdm_context->connection_info.algorithm.req_base_asym_alg =
+     226                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256;
+     227                 :            : 
+     228         [ +  - ]:          1 :     if (m_libspdm_local_certificate_chain == NULL) {
+     229                 :          1 :         libspdm_read_responder_public_certificate_chain(
+     230                 :            :             m_libspdm_use_hash_algo, m_libspdm_use_asym_algo,
+     231                 :            :             &m_libspdm_local_certificate_chain,
+     232                 :            :             &m_libspdm_local_certificate_chain_size, NULL, NULL);
+     233                 :            :     }
+     234                 :            : 
+     235                 :          1 :     portion_length = 0;
+     236                 :            :     /* Fail response: spdm_request.offset + spdm_response.portion_length + spdm_response.remainder_length !=
+     237                 :            :      * total_responder_cert_chain_buffer_length.*/
+     238                 :          1 :     remainder_length =
+     239                 :          1 :         (uint16_t)(m_libspdm_local_certificate_chain_size - 1 -
+     240                 :          1 :                    LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN * (calling_index + 1));
+     241                 :            : 
+     242                 :          1 :     temp_buf_size =
+     243                 :          1 :         sizeof(spdm_certificate_response_t) + portion_length;
+     244                 :          1 :     spdm_response_size = temp_buf_size;
+     245                 :          1 :     spdm_response = (void *)temp_buf;
+     246                 :            : 
+     247                 :          1 :     spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     248                 :          1 :     spdm_response->header.request_response_code = SPDM_CERTIFICATE;
+     249                 :          1 :     spdm_response->header.param1 = 0;
+     250                 :          1 :     spdm_response->header.param2 = 0;
+     251                 :          1 :     spdm_response->portion_length = portion_length;
+     252                 :          1 :     spdm_response->remainder_length = remainder_length;
+     253                 :          1 :     libspdm_copy_mem(spdm_response + 1,
+     254                 :            :                      sizeof(temp_buf) - sizeof(*spdm_response),
+     255                 :          1 :                      (uint8_t *)m_libspdm_local_certificate_chain +
+     256                 :          1 :                      LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN * calling_index,
+     257                 :            :                      portion_length);
+     258                 :            : 
+     259                 :          1 :     free(m_libspdm_local_certificate_chain);
+     260                 :          1 :     m_libspdm_local_certificate_chain = NULL;
+     261                 :          1 :     m_libspdm_local_certificate_chain_size = 0;
+     262                 :            : 
+     263                 :          1 :     status = libspdm_process_encap_response_certificate(spdm_context, spdm_response_size,
+     264                 :            :                                                         spdm_response,
+     265                 :            :                                                         &need_continue);
+     266                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+     267                 :            : 
+     268                 :          1 :     spdm_context->mut_auth_cert_chain_buffer_size = 0;
+     269                 :          1 :     free(data);
+     270                 :          1 : }
+     271                 :            : 
+     272                 :            : /**
+     273                 :            :  * Test 4: Fail case, request a certificate chain, responder return portion_length > spdm_request.length.
+     274                 :            :  * Expected Behavior:returns a status of RETURN_DEVICE_ERROR.
+     275                 :            :  **/
+     276                 :          1 : void test_spdm_responder_encap_get_certificate_case4(void **state)
+     277                 :            : {
+     278                 :            :     libspdm_return_t status;
+     279                 :            :     libspdm_test_context_t *spdm_test_context;
+     280                 :            :     libspdm_context_t *spdm_context;
+     281                 :            :     void *data;
+     282                 :            :     size_t data_size;
+     283                 :            :     void *hash;
+     284                 :            :     size_t hash_size;
+     285                 :            :     const uint8_t *root_cert;
+     286                 :            :     size_t root_cert_size;
+     287                 :            :     bool need_continue;
+     288                 :            :     spdm_certificate_response_t *spdm_response;
+     289                 :            :     uint8_t temp_buf[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     290                 :            :     size_t temp_buf_size;
+     291                 :            :     uint16_t portion_length;
+     292                 :            :     uint16_t remainder_length;
+     293                 :            :     static size_t calling_index = 0;
+     294                 :            :     size_t spdm_response_size;
+     295                 :            : 
+     296                 :          1 :     spdm_test_context = *state;
+     297                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     298                 :          1 :     spdm_test_context->case_id = 0x4;
+     299                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+     300                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     301                 :          1 :     spdm_context->connection_info.capability.flags |=
+     302                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     303                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     304                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     305                 :            :                                                     &data_size, &hash, &hash_size);
+     306                 :          1 :     libspdm_x509_get_cert_from_cert_chain((uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size,
+     307                 :          1 :                                           data_size - sizeof(spdm_cert_chain_t) - hash_size, 0,
+     308                 :            :                                           &root_cert, &root_cert_size);
+     309                 :          1 :     libspdm_dump_hex(
+     310                 :            :         root_cert,
+     311                 :            :         root_cert_size);
+     312                 :          1 :     spdm_context->local_context.peer_root_cert_provision_size[0] =
+     313                 :            :         root_cert_size;
+     314                 :          1 :     spdm_context->local_context.peer_root_cert_provision[0] = root_cert;
+     315                 :          1 :     libspdm_reset_message_b(spdm_context);
+     316                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     317                 :            :         m_libspdm_use_hash_algo;
+     318                 :            : 
+     319                 :          1 :     spdm_context->connection_info.algorithm.req_base_asym_alg =
+     320                 :            :         SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256;
+     321                 :            : 
+     322         [ +  - ]:          1 :     if (m_libspdm_local_certificate_chain == NULL) {
+     323                 :          1 :         libspdm_read_responder_public_certificate_chain(
+     324                 :            :             m_libspdm_use_hash_algo, m_libspdm_use_asym_algo,
+     325                 :            :             &m_libspdm_local_certificate_chain,
+     326                 :            :             &m_libspdm_local_certificate_chain_size, NULL, NULL);
+     327                 :            :     }
+     328                 :            : 
+     329                 :          1 :     portion_length = LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN + 1; /* Fail response: responder return portion_length > spdm_request.length*/
+     330                 :          1 :     remainder_length =
+     331                 :          1 :         (uint16_t)(m_libspdm_local_certificate_chain_size - 1 -
+     332                 :          1 :                    LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN * (calling_index + 1));
+     333                 :            : 
+     334                 :          1 :     temp_buf_size =
+     335                 :          1 :         sizeof(spdm_certificate_response_t) + portion_length;
+     336                 :          1 :     spdm_response_size = temp_buf_size;
+     337                 :          1 :     spdm_response = (void *)temp_buf;
+     338                 :            : 
+     339                 :          1 :     spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     340                 :          1 :     spdm_response->header.request_response_code = SPDM_CERTIFICATE;
+     341                 :          1 :     spdm_response->header.param1 = 0;
+     342                 :          1 :     spdm_response->header.param2 = 0;
+     343                 :          1 :     spdm_response->portion_length = portion_length;
+     344                 :          1 :     spdm_response->remainder_length = remainder_length;
+     345                 :          1 :     libspdm_copy_mem(spdm_response + 1,
+     346                 :            :                      sizeof(temp_buf) - sizeof(*spdm_response),
+     347                 :          1 :                      (uint8_t *)m_libspdm_local_certificate_chain +
+     348                 :          1 :                      LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN * calling_index,
+     349                 :            :                      portion_length);
+     350                 :            : 
+     351                 :          1 :     free(m_libspdm_local_certificate_chain);
+     352                 :          1 :     m_libspdm_local_certificate_chain = NULL;
+     353                 :          1 :     m_libspdm_local_certificate_chain_size = 0;
+     354                 :            : 
+     355                 :          1 :     status = libspdm_process_encap_response_certificate(spdm_context, spdm_response_size,
+     356                 :            :                                                         spdm_response,
+     357                 :            :                                                         &need_continue);
+     358                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+     359                 :            : 
+     360                 :          1 :     spdm_context->mut_auth_cert_chain_buffer_size = 0;
+     361                 :          1 :     free(data);
+     362                 :          1 : }
+     363                 :            : 
+     364                 :            : /**
+     365                 :            :  * Test 5: check request attributes and response attributes ,
+     366                 :            :  * Set CertModel to determine whether it meets expectations
+     367                 :            :  * Expected Behavior: requester returns the status LIBSPDM_STATUS_SUCCESS
+     368                 :            :  * Expected Behavior: CertModel is GenericCert model and slot 0 , returns a status of RETURN_DEVICE_ERROR.
+     369                 :            :  * Expected Behavior: CertModel Value of 0 and certificate chain is valid, returns a status of RETURN_DEVICE_ERROR.
+     370                 :            :  **/
+     371                 :          1 : void test_spdm_responder_encap_get_certificate_case5(void **state)
+     372                 :            : {
+     373                 :            :     libspdm_return_t status;
+     374                 :            :     libspdm_test_context_t *spdm_test_context;
+     375                 :            :     libspdm_context_t *spdm_context;
+     376                 :            :     void *data;
+     377                 :            :     size_t data_size;
+     378                 :            :     void *hash;
+     379                 :            :     size_t hash_size;
+     380                 :            :     const uint8_t *root_cert;
+     381                 :            :     size_t root_cert_size;
+     382                 :            :     bool need_continue;
+     383                 :            :     spdm_certificate_response_t *spdm_response;
+     384                 :            :     uint8_t temp_buf[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     385                 :            :     size_t temp_buf_size;
+     386                 :            :     uint8_t cert_chain[LIBSPDM_MAX_CERT_CHAIN_SIZE];
+     387                 :            :     uint16_t portion_length;
+     388                 :            :     uint16_t remainder_length;
+     389                 :            :     size_t spdm_response_size;
+     390                 :            : 
+     391                 :          1 :     spdm_test_context = *state;
+     392                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     393                 :          1 :     spdm_test_context->case_id = 0x5;
+     394                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+     395                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     396                 :          1 :     spdm_context->connection_info.capability.flags = 0;
+     397                 :          1 :     spdm_context->connection_info.capability.flags |=
+     398                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     399                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     400                 :            :         m_libspdm_use_hash_algo;
+     401                 :          1 :     spdm_context->connection_info.algorithm.req_base_asym_alg =
+     402                 :            :         m_libspdm_use_req_asym_algo;
+     403                 :            : 
+     404                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     405                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     406                 :            :                                                     &data_size, &hash, &hash_size);
+     407                 :          1 :     libspdm_x509_get_cert_from_cert_chain((uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size,
+     408                 :          1 :                                           data_size - sizeof(spdm_cert_chain_t) - hash_size, 0,
+     409                 :            :                                           &root_cert, &root_cert_size);
+     410                 :            : 
+     411                 :          1 :     spdm_context->local_context.peer_root_cert_provision_size[0] = root_cert_size;
+     412                 :          1 :     spdm_context->local_context.peer_root_cert_provision[0] = root_cert;
+     413                 :            : 
+     414                 :          1 :     libspdm_read_responder_public_certificate_chain(
+     415                 :            :         m_libspdm_use_hash_algo, m_libspdm_use_asym_algo,
+     416                 :            :         &m_libspdm_local_certificate_chain,
+     417                 :            :         &m_libspdm_local_certificate_chain_size, NULL, NULL);
+     418                 :            : 
+     419                 :          1 :     portion_length = LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN;
+     420                 :          1 :     remainder_length =
+     421                 :          1 :         (uint16_t)(m_libspdm_local_certificate_chain_size -
+     422                 :            :                    LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN);
+     423                 :            : 
+     424                 :          1 :     temp_buf_size =
+     425                 :          1 :         sizeof(spdm_certificate_response_t) + portion_length;
+     426                 :          1 :     spdm_response_size = temp_buf_size;
+     427                 :          1 :     spdm_response = (void *)temp_buf;
+     428                 :            : 
+     429                 :          1 :     spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+     430                 :          1 :     spdm_response->header.request_response_code = SPDM_CERTIFICATE;
+     431                 :          1 :     spdm_response->header.param1 = 0;
+     432                 :          1 :     spdm_response->header.param2 = 0;
+     433                 :          1 :     spdm_response->portion_length = portion_length;
+     434                 :          1 :     spdm_response->remainder_length = remainder_length;
+     435                 :          1 :     libspdm_copy_mem(spdm_response + 1,
+     436                 :            :                      sizeof(temp_buf) - sizeof(*spdm_response),
+     437                 :            :                      (uint8_t *)m_libspdm_local_certificate_chain,
+     438                 :            :                      portion_length);
+     439                 :            : 
+     440                 :            :     /* Sub Case 1: CertModel Value of 1 , DeviceCert model*/
+     441                 :          1 :     spdm_context->connection_info.multi_key_conn_req = true;
+     442                 :          1 :     spdm_context->encap_context.req_slot_id = 0;
+     443                 :          1 :     spdm_context->connection_info.peer_cert_info[0] = 0;
+     444                 :          1 :     spdm_context->mut_auth_cert_chain_buffer_size = 0;
+     445                 :          1 :     spdm_response->header.param2 = SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT;
+     446                 :          1 :     libspdm_reset_message_mut_b(spdm_context);
+     447                 :            : 
+     448                 :          1 :     status = libspdm_process_encap_response_certificate(spdm_context, spdm_response_size,
+     449                 :            :                                                         spdm_response,
+     450                 :            :                                                         &need_continue);
+     451                 :            : 
+     452                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     453                 :          1 :     assert_int_equal(spdm_context->connection_info.peer_cert_info[0],
+     454                 :            :                      SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT);
+     455                 :          1 :     assert_int_equal(spdm_context->mut_auth_cert_chain_buffer_size,
+     456                 :            :                      LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN);
+     457                 :          1 :     assert_memory_equal(spdm_context->mut_auth_cert_chain_buffer, m_libspdm_local_certificate_chain,
+     458                 :            :                         LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN);
+     459                 :            : 
+     460                 :            :     /* Sub Case 2: CertModel Value of 2 , AliasCert model*/
+     461                 :          1 :     spdm_context->connection_info.multi_key_conn_req = true;
+     462                 :          1 :     spdm_context->encap_context.req_slot_id = 0;
+     463                 :          1 :     spdm_context->connection_info.peer_cert_info[0] = 0;
+     464                 :          1 :     spdm_response->header.param2 = SPDM_CERTIFICATE_INFO_CERT_MODEL_ALIAS_CERT;
+     465                 :          1 :     libspdm_reset_message_mut_b(spdm_context);
+     466                 :          1 :     libspdm_zero_mem(cert_chain, sizeof(cert_chain));
+     467                 :          1 :     spdm_context->mut_auth_cert_chain_buffer_size = 0;
+     468                 :          1 :     spdm_context->mut_auth_cert_chain_buffer = cert_chain;
+     469                 :            : 
+     470                 :          1 :     status = libspdm_process_encap_response_certificate(spdm_context, spdm_response_size,
+     471                 :            :                                                         spdm_response,
+     472                 :            :                                                         &need_continue);
+     473                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     474                 :          1 :     assert_int_equal(spdm_context->connection_info.peer_cert_info[0],
+     475                 :            :                      SPDM_CERTIFICATE_INFO_CERT_MODEL_ALIAS_CERT);
+     476                 :          1 :     assert_int_equal(spdm_context->mut_auth_cert_chain_buffer_size,
+     477                 :            :                      LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN);
+     478                 :          1 :     assert_memory_equal(spdm_context->mut_auth_cert_chain_buffer, m_libspdm_local_certificate_chain,
+     479                 :            :                         LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN);
+     480                 :            : 
+     481                 :            :     /* Sub Case 3: CertModel Value of 3 GenericCert model , slot_id set 1
+     482                 :            :      * In all cases, the certificate model for slot 0 shall be either the device certificate model or the alias certificate model*/
+     483                 :          1 :     spdm_context->connection_info.multi_key_conn_req = true;
+     484                 :          1 :     spdm_context->encap_context.req_slot_id = 1;
+     485                 :          1 :     spdm_context->connection_info.peer_cert_info[1] = 0;
+     486                 :          1 :     spdm_context->mut_auth_cert_chain_buffer_size = 0;
+     487                 :          1 :     spdm_response->header.param1 = 1;
+     488                 :          1 :     spdm_response->header.param2 = SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT;
+     489                 :          1 :     libspdm_reset_message_mut_b(spdm_context);
+     490                 :          1 :     libspdm_zero_mem(cert_chain, sizeof(cert_chain));
+     491                 :          1 :     spdm_context->mut_auth_cert_chain_buffer_size = 0;
+     492                 :          1 :     spdm_context->mut_auth_cert_chain_buffer = cert_chain;
+     493                 :            : 
+     494                 :          1 :     status = libspdm_process_encap_response_certificate(spdm_context, spdm_response_size,
+     495                 :            :                                                         spdm_response,
+     496                 :            :                                                         &need_continue);
+     497                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     498                 :          1 :     assert_int_equal(spdm_context->connection_info.peer_cert_info[1],
+     499                 :            :                      SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT);
+     500                 :          1 :     assert_int_equal(spdm_context->mut_auth_cert_chain_buffer_size,
+     501                 :            :                      LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN);
+     502                 :          1 :     assert_memory_equal(spdm_context->mut_auth_cert_chain_buffer, m_libspdm_local_certificate_chain,
+     503                 :            :                         LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN);
+     504                 :            : 
+     505                 :            :     /* Sub Case 4: CertModel Value of 3 , GenericCert model ,slot_id set 0
+     506                 :            :      * In all cases, the certificate model for slot 0 shall be either the device certificate model or the alias certificate model*/
+     507                 :          1 :     spdm_context->connection_info.multi_key_conn_req = true;
+     508                 :          1 :     spdm_context->encap_context.req_slot_id = 0;
+     509                 :          1 :     spdm_context->connection_info.peer_cert_info[0] = 0;
+     510                 :          1 :     spdm_context->mut_auth_cert_chain_buffer_size = 0;
+     511                 :          1 :     spdm_response->header.param1 = 0;
+     512                 :          1 :     spdm_response->header.param2 = SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT;
+     513                 :          1 :     libspdm_reset_message_mut_b(spdm_context);
+     514                 :          1 :     libspdm_zero_mem(cert_chain, sizeof(cert_chain));
+     515                 :          1 :     spdm_context->mut_auth_cert_chain_buffer_size = 0;
+     516                 :          1 :     spdm_context->mut_auth_cert_chain_buffer = cert_chain;
+     517                 :            : 
+     518                 :          1 :     status = libspdm_process_encap_response_certificate(spdm_context, spdm_response_size,
+     519                 :            :                                                         spdm_response,
+     520                 :            :                                                         &need_continue);
+     521                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+     522                 :          1 :     assert_int_equal(spdm_context->connection_info.peer_cert_info[0], 0);
+     523                 :            : 
+     524                 :            :     /* Sub Case 5: CertModel Value of 0 , MULTI_KEY_CONN_REQ is true*/
+     525                 :            :     /* Value of 0 indicates either that the certificate slot does not contain any certificates or that the corresponding
+     526                 :            :      * MULTI_KEY_CONN_REQ or MULTI_KEY_CONN_RSP is false. */
+     527                 :          1 :     spdm_context->connection_info.multi_key_conn_req = true;
+     528                 :          1 :     spdm_context->encap_context.req_slot_id = 0;
+     529                 :          1 :     spdm_context->connection_info.peer_cert_info[0] = 0;
+     530                 :          1 :     spdm_context->mut_auth_cert_chain_buffer_size = 0;
+     531                 :          1 :     spdm_response->header.param2 = SPDM_CERTIFICATE_INFO_CERT_MODEL_NONE;
+     532                 :          1 :     libspdm_reset_message_mut_b(spdm_context);
+     533                 :          1 :     libspdm_zero_mem(cert_chain, sizeof(cert_chain));
+     534                 :          1 :     spdm_context->mut_auth_cert_chain_buffer_size = 0;
+     535                 :          1 :     spdm_context->mut_auth_cert_chain_buffer = cert_chain;
+     536                 :            : 
+     537                 :          1 :     status = libspdm_process_encap_response_certificate(spdm_context, spdm_response_size,
+     538                 :            :                                                         spdm_response,
+     539                 :            :                                                         &need_continue);
+     540                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+     541                 :          1 :     assert_int_equal(spdm_context->connection_info.peer_cert_info[0],
+     542                 :            :                      SPDM_CERTIFICATE_INFO_CERT_MODEL_NONE);
+     543                 :            : 
+     544                 :            :     /* Sub Case 6: CertModel Value of 0 , MULTI_KEY_CONN_REQ is false*/
+     545                 :            :     /* Value of 0 indicates either that the certificate slot does not contain any certificates or that the corresponding
+     546                 :            :      * MULTI_KEY_CONN_REQ or MULTI_KEY_CONN_RSP is false. */
+     547                 :          1 :     spdm_context->connection_info.multi_key_conn_req = false;
+     548                 :          1 :     spdm_context->encap_context.req_slot_id = 0;
+     549                 :          1 :     spdm_context->connection_info.peer_cert_info[0] = 0;
+     550                 :          1 :     spdm_context->mut_auth_cert_chain_buffer_size = 0;
+     551                 :          1 :     spdm_response->header.param2 = SPDM_CERTIFICATE_INFO_CERT_MODEL_NONE;
+     552                 :          1 :     libspdm_reset_message_mut_b(spdm_context);
+     553                 :          1 :     libspdm_zero_mem(cert_chain, sizeof(cert_chain));
+     554                 :          1 :     spdm_context->mut_auth_cert_chain_buffer_size = 0;
+     555                 :          1 :     spdm_context->mut_auth_cert_chain_buffer = cert_chain;
+     556                 :            : 
+     557                 :          1 :     status = libspdm_process_encap_response_certificate(spdm_context, spdm_response_size,
+     558                 :            :                                                         spdm_response,
+     559                 :            :                                                         &need_continue);
+     560                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     561                 :          1 :     assert_int_equal(spdm_context->connection_info.peer_cert_info[0],
+     562                 :            :                      SPDM_CERTIFICATE_INFO_CERT_MODEL_NONE);
+     563                 :          1 :     assert_int_equal(spdm_context->mut_auth_cert_chain_buffer_size,
+     564                 :            :                      LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN);
+     565                 :          1 :     assert_memory_equal(spdm_context->mut_auth_cert_chain_buffer, m_libspdm_local_certificate_chain,
+     566                 :            :                         LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN);
+     567                 :            : 
+     568                 :          1 :     free(data);
+     569                 :          1 :     free(m_libspdm_local_certificate_chain);
+     570                 :          1 :     m_libspdm_local_certificate_chain = NULL;
+     571                 :          1 :     m_libspdm_local_certificate_chain_size = 0;
+     572                 :          1 : }
+     573                 :            : 
+     574                 :            : libspdm_test_context_t m_spdm_responder_encap_get_certificate_test_context = {
+     575                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+     576                 :            :     false,
+     577                 :            : };
+     578                 :            : 
+     579                 :          1 : int spdm_responder_encap_get_certificate_test_main(void)
+     580                 :            : {
+     581                 :          1 :     const struct CMUnitTest spdm_responder_certificate_tests[] = {
+     582                 :            :         /* Success Case*/
+     583                 :            :         cmocka_unit_test(test_spdm_responder_encap_get_certificate_case1),
+     584                 :            :         /* Bad request size ,remaining length is 0*/
+     585                 :            :         cmocka_unit_test(test_spdm_responder_encap_get_certificate_case2),
+     586                 :            :         /* Error response: SPDM_ERROR_CODE_INVALID_REQUEST*/
+     587                 :            :         cmocka_unit_test(test_spdm_responder_encap_get_certificate_case2),
+     588                 :            :         /* Fail response: spdm_request.offset + spdm_response.portion_length + spdm_response.remainder_length !=
+     589                 :            :          * total_responder_cert_chain_buffer_length.*/
+     590                 :            :         cmocka_unit_test(test_spdm_responder_encap_get_certificate_case3),
+     591                 :            :         /* Fail response: responder return portion_length > spdm_request.length*/
+     592                 :            :         cmocka_unit_test(test_spdm_responder_encap_get_certificate_case4),
+     593                 :            :         /* check request attributes and response attributes*/
+     594                 :            :         cmocka_unit_test(test_spdm_responder_encap_get_certificate_case5),
+     595                 :            :     };
+     596                 :            : 
+     597                 :          1 :     libspdm_setup_test_context(&m_spdm_responder_encap_get_certificate_test_context);
+     598                 :            : 
+     599                 :          1 :     return cmocka_run_group_tests(spdm_responder_certificate_tests,
+     600                 :            :                                   libspdm_unit_test_group_setup,
+     601                 :            :                                   libspdm_unit_test_group_teardown);
+     602                 :            : }
+     603                 :            : 
+     604                 :            : #endif /* (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (...) */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/encap_get_digests.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_responder/encap_get_digests.c.func-sort-c.html new file mode 100644 index 00000000000..5eaae2acda2 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/encap_get_digests.c.func-sort-c.html @@ -0,0 +1,113 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/encap_get_digests.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - encap_get_digests.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:221221100.0 %
Date:2024-09-22 08:21:07Functions:88100.0 %
Branches:44100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
spdm_responder_encap_get_digests_test_main1
test_spdm_responder_encap_get_digests_case11
test_spdm_responder_encap_get_digests_case21
test_spdm_responder_encap_get_digests_case31
test_spdm_responder_encap_get_digests_case41
test_spdm_responder_encap_get_digests_case51
test_spdm_responder_encap_get_digests_case61
test_spdm_responder_encap_get_digests_case71
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/encap_get_digests.c.func.html b/coverage_log/unit_test/test_spdm_responder/encap_get_digests.c.func.html new file mode 100644 index 00000000000..57921663730 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/encap_get_digests.c.func.html @@ -0,0 +1,113 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/encap_get_digests.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - encap_get_digests.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:221221100.0 %
Date:2024-09-22 08:21:07Functions:88100.0 %
Branches:44100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
spdm_responder_encap_get_digests_test_main1
test_spdm_responder_encap_get_digests_case11
test_spdm_responder_encap_get_digests_case21
test_spdm_responder_encap_get_digests_case31
test_spdm_responder_encap_get_digests_case41
test_spdm_responder_encap_get_digests_case51
test_spdm_responder_encap_get_digests_case61
test_spdm_responder_encap_get_digests_case71
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/encap_get_digests.c.gcov.html b/coverage_log/unit_test/test_spdm_responder/encap_get_digests.c.gcov.html new file mode 100644 index 00000000000..fed2c332eee --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/encap_get_digests.c.gcov.html @@ -0,0 +1,592 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/encap_get_digests.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - encap_get_digests.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:221221100.0 %
Date:2024-09-22 08:21:07Functions:88100.0 %
Branches:44100.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link:
+       5                 :            :  * https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       6                 :            :  **/
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_responder_lib.h"
+       9                 :            : 
+      10                 :            : #if (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP) && \
+      11                 :            :     (LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT)
+      12                 :            : 
+      13                 :            : uint8_t m_local_digests_chain[LIBSPDM_MAX_CERT_CHAIN_SIZE];
+      14                 :            : static uint8_t m_libspdm_local_certificate_chain[LIBSPDM_MAX_CERT_CHAIN_SIZE];
+      15                 :            : 
+      16                 :            : /**
+      17                 :            :  * Test 1: Response message received successfully
+      18                 :            :  * Expected Behavior: requester returns the status RETURN_SUCCESS and a DIGESTS message is received
+      19                 :            :  **/
+      20                 :          1 : void test_spdm_responder_encap_get_digests_case1(void **state)
+      21                 :            : {
+      22                 :            :     libspdm_return_t status;
+      23                 :            :     libspdm_test_context_t *spdm_test_context;
+      24                 :            :     libspdm_context_t *spdm_context;
+      25                 :            :     spdm_digest_response_t *spdm_response;
+      26                 :            :     uint8_t *digest;
+      27                 :            :     uint8_t temp_buf[LIBSPDM_MAX_SPDM_MSG_SIZE];
+      28                 :            :     size_t spdm_response_size;
+      29                 :            :     bool need_continue;
+      30                 :            : 
+      31                 :          1 :     spdm_test_context = *state;
+      32                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+      33                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+      34                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+      35                 :          1 :     spdm_context->connection_info.connection_state =
+      36                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+      37                 :          1 :     spdm_context->connection_info.capability.flags |=
+      38                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
+      39                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+      40                 :            :         m_libspdm_use_hash_algo;
+      41                 :          1 :     libspdm_set_mem(m_libspdm_local_certificate_chain,
+      42                 :            :                     sizeof(m_libspdm_local_certificate_chain),
+      43                 :            :                     (uint8_t)(0xFF));
+      44                 :          1 :     libspdm_reset_message_b(spdm_context);
+      45                 :            : 
+      46                 :            :     ((libspdm_context_t *)spdm_context)
+      47                 :          1 :     ->connection_info.algorithm.base_hash_algo =
+      48                 :            :         m_libspdm_use_hash_algo;
+      49                 :          1 :     spdm_response_size = sizeof(spdm_digest_response_t) +
+      50                 :          1 :                          libspdm_get_hash_size(m_libspdm_use_hash_algo);
+      51                 :          1 :     spdm_response = (void *)temp_buf;
+      52                 :          1 :     spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+      53                 :          1 :     spdm_response->header.param1 = 0;
+      54                 :          1 :     spdm_response->header.request_response_code = SPDM_DIGESTS;
+      55                 :          1 :     spdm_response->header.param2 = 0;
+      56                 :          1 :     libspdm_set_mem(m_libspdm_local_certificate_chain,
+      57                 :            :                     sizeof(m_libspdm_local_certificate_chain),
+      58                 :            :                     (uint8_t)(0xFF));
+      59                 :            : 
+      60                 :          1 :     digest = (void *)(spdm_response + 1);
+      61                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
+      62                 :            :                      sizeof(m_libspdm_local_certificate_chain), &digest[0]);
+      63                 :          1 :     spdm_response->header.param2 |= (0x01 << 0);
+      64                 :            : 
+      65                 :          1 :     status = libspdm_process_encap_response_digest(spdm_context, spdm_response_size,
+      66                 :            :                                                    spdm_response, &need_continue);
+      67                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+      68                 :          1 : }
+      69                 :            : 
+      70                 :            : /**
+      71                 :            :  * Test 2: Error response message with error code busy
+      72                 :            :  * Expected Behavior: requester returns the status RETURN_DEVICE_ERROR, with no DIGESTS message received
+      73                 :            :  **/
+      74                 :          1 : void test_spdm_responder_encap_get_digests_case2(void **state)
+      75                 :            : {
+      76                 :            :     libspdm_return_t status;
+      77                 :            :     libspdm_test_context_t *spdm_test_context;
+      78                 :            :     libspdm_context_t *spdm_context;
+      79                 :            :     spdm_error_response_t spdm_response;
+      80                 :            :     size_t spdm_response_size;
+      81                 :            :     bool need_continue;
+      82                 :            : 
+      83                 :          1 :     spdm_test_context = *state;
+      84                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+      85                 :          1 :     spdm_test_context->case_id = 0x2;
+      86                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+      87                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+      88                 :          1 :     spdm_context->connection_info.connection_state =
+      89                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+      90                 :          1 :     spdm_context->connection_info.capability.flags |=
+      91                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
+      92                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+      93                 :            :         m_libspdm_use_hash_algo;
+      94                 :          1 :     libspdm_set_mem(m_libspdm_local_certificate_chain,
+      95                 :            :                     sizeof(m_libspdm_local_certificate_chain),
+      96                 :            :                     (uint8_t)(0xFF));
+      97                 :          1 :     libspdm_reset_message_b(spdm_context);
+      98                 :            : 
+      99                 :          1 :     spdm_response_size = sizeof(spdm_error_response_t);
+     100                 :          1 :     spdm_response.header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     101                 :          1 :     spdm_response.header.request_response_code = SPDM_ERROR;
+     102                 :          1 :     spdm_response.header.param1 = SPDM_ERROR_CODE_INVALID_REQUEST;
+     103                 :          1 :     spdm_response.header.param2 = 0;
+     104                 :            : 
+     105                 :          1 :     status = libspdm_process_encap_response_digest(spdm_context, spdm_response_size,
+     106                 :            :                                                    &spdm_response, &need_continue);
+     107                 :            : 
+     108                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_UNSUPPORTED_CAP);
+     109                 :          1 : }
+     110                 :            : 
+     111                 :            : /**
+     112                 :            :  * Test 3: Error response message with error code busy reponse seize incorrect
+     113                 :            :  * Expected Behavior:  Expected Behavior: requester returns the status RETURN_DEVICE_ERROR, with no DIGESTS message received
+     114                 :            :  **/
+     115                 :          1 : void test_spdm_responder_encap_get_digests_case3(void **state)
+     116                 :            : {
+     117                 :            :     libspdm_return_t status;
+     118                 :            :     libspdm_test_context_t *spdm_test_context;
+     119                 :            :     libspdm_context_t *spdm_context;
+     120                 :            :     bool need_continue;
+     121                 :            : 
+     122                 :          1 :     spdm_test_context = *state;
+     123                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     124                 :          1 :     spdm_test_context->case_id = 0x3;
+     125                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+     126                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     127                 :          1 :     spdm_context->connection_info.connection_state =
+     128                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     129                 :          1 :     spdm_context->connection_info.capability.flags |=
+     130                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
+     131                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     132                 :            :         m_libspdm_use_hash_algo;
+     133                 :          1 :     libspdm_set_mem(m_libspdm_local_certificate_chain,
+     134                 :            :                     sizeof(m_libspdm_local_certificate_chain),
+     135                 :            :                     (uint8_t)(0xFF));
+     136                 :          1 :     libspdm_reset_message_b(spdm_context);
+     137                 :            : 
+     138                 :            :     spdm_digest_response_t *spdm_response;
+     139                 :          1 :     uint8_t temp_buf[LIBSPDM_MAX_SPDM_MSG_SIZE] = {0};
+     140                 :            :     size_t spdm_response_size;
+     141                 :            : 
+     142                 :          1 :     spdm_response_size = 0;
+     143                 :          1 :     spdm_response = (void *)temp_buf;
+     144                 :            : 
+     145                 :          1 :     status = libspdm_process_encap_response_digest(spdm_context, spdm_response_size,
+     146                 :            :                                                    spdm_response, &need_continue);
+     147                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
+     148                 :          1 : }
+     149                 :            : 
+     150                 :            : /**
+     151                 :            :  * Test 4: The code of the request_response_code  summary in the response message is different
+     152                 :            :  * Expected Behavior: requester returns the status RETURN_DEVICE_ERROR, with no DIGESTS message received
+     153                 :            :  **/
+     154                 :          1 : void test_spdm_responder_encap_get_digests_case4(void **state)
+     155                 :            : {
+     156                 :            :     libspdm_return_t status;
+     157                 :            :     libspdm_test_context_t *spdm_test_context;
+     158                 :            :     libspdm_context_t *spdm_context;
+     159                 :            :     bool need_continue;
+     160                 :            : 
+     161                 :          1 :     spdm_test_context = *state;
+     162                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     163                 :          1 :     spdm_test_context->case_id = 0x4;
+     164                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+     165                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     166                 :          1 :     spdm_context->connection_info.connection_state =
+     167                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     168                 :          1 :     spdm_context->connection_info.capability.flags |=
+     169                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     170                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     171                 :            :         m_libspdm_use_hash_algo;
+     172                 :            : 
+     173                 :            :     spdm_digest_response_t *spdm_response;
+     174                 :            :     uint8_t *digest;
+     175                 :            :     uint8_t temp_buf[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     176                 :            :     size_t spdm_response_size;
+     177                 :            : 
+     178                 :          1 :     spdm_response_size = sizeof(spdm_digest_response_t) +
+     179                 :          1 :                          libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     180                 :          1 :     spdm_response = (void *)temp_buf;
+     181                 :            : 
+     182                 :          1 :     spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     183                 :          1 :     spdm_response->header.request_response_code = SPDM_CERTIFICATE;
+     184                 :          1 :     spdm_response->header.param1 = 0;
+     185                 :          1 :     spdm_response->header.param2 = 0;
+     186                 :          1 :     libspdm_set_mem(m_libspdm_local_certificate_chain,
+     187                 :            :                     sizeof(m_libspdm_local_certificate_chain),
+     188                 :            :                     (uint8_t)(0xFF));
+     189                 :            : 
+     190                 :          1 :     digest = (void *)(spdm_response + 1);
+     191                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
+     192                 :            :                      sizeof(m_libspdm_local_certificate_chain), &digest[0]);
+     193                 :          1 :     spdm_response->header.param2 |= (1 << 0);
+     194                 :            : 
+     195                 :          1 :     status = libspdm_process_encap_response_digest(spdm_context, spdm_response_size,
+     196                 :            :                                                    spdm_response, &need_continue);
+     197                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+     198                 :          1 : }
+     199                 :            : 
+     200                 :            : /**
+     201                 :            :  * Test 5: flag cert_cap from CAPABILITIES is not setted meaning the Requester does not support DIGESTS and
+     202                 :            :  * CERTIFICATE response messages
+     203                 :            :  * Expected Behavior: requester returns the status RETURN_DEVICE_ERROR, with no DIGESTS message received
+     204                 :            :  **/
+     205                 :          1 : void test_spdm_responder_encap_get_digests_case5(void **state)
+     206                 :            : {
+     207                 :            :     libspdm_return_t status;
+     208                 :            :     libspdm_test_context_t *spdm_test_context;
+     209                 :            :     libspdm_context_t *spdm_context;
+     210                 :            :     spdm_digest_response_t *spdm_response;
+     211                 :          1 :     uint8_t temp_buf[LIBSPDM_MAX_SPDM_MSG_SIZE] = {0};
+     212                 :            :     size_t spdm_response_size;
+     213                 :            :     bool need_continue;
+     214                 :            : 
+     215                 :          1 :     spdm_test_context = *state;
+     216                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     217                 :          1 :     spdm_test_context->case_id = 0x5;
+     218                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+     219                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     220                 :          1 :     spdm_context->connection_info.capability.flags |=
+     221                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
+     222                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     223                 :            :         m_libspdm_use_hash_algo;
+     224                 :          1 :     libspdm_set_mem(m_libspdm_local_certificate_chain,
+     225                 :            :                     sizeof(m_libspdm_local_certificate_chain),
+     226                 :            :                     (uint8_t)(0xFF));
+     227                 :          1 :     libspdm_reset_message_b(spdm_context);
+     228                 :            : 
+     229                 :          1 :     spdm_response_size = sizeof(spdm_digest_response_t);
+     230                 :          1 :     spdm_response = (void *)temp_buf;
+     231                 :            : 
+     232                 :          1 :     status = libspdm_process_encap_response_digest(spdm_context, spdm_response_size,
+     233                 :            :                                                    spdm_response, &need_continue);
+     234                 :            : 
+     235                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+     236                 :          1 : }
+     237                 :            : 
+     238                 :            : /**
+     239                 :            :  * Test 6: a response message is successfully sent , Set multi_key_conn_req to check if it responds correctly
+     240                 :            :  * Expected Behavior: requester returns the status RETURN_SUCCESS
+     241                 :            :  **/
+     242                 :          1 : void test_spdm_responder_encap_get_digests_case6(void **state)
+     243                 :            : {
+     244                 :            :     libspdm_return_t status;
+     245                 :            :     libspdm_test_context_t *spdm_test_context;
+     246                 :            :     libspdm_context_t *spdm_context;
+     247                 :            :     spdm_digest_response_t *spdm_response;
+     248                 :            :     uint8_t *digest;
+     249                 :            :     size_t hash_size;
+     250                 :            :     uint8_t temp_buf[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     251                 :            :     size_t spdm_response_size;
+     252                 :            :     bool need_continue;
+     253                 :            :     uint32_t session_id;
+     254                 :            :     libspdm_session_info_t *session_info;
+     255                 :            :     spdm_key_pair_id_t *key_pair_id;
+     256                 :            :     spdm_certificate_info_t *cert_info;
+     257                 :            :     spdm_key_usage_bit_mask_t *key_usage_bit_mask;
+     258                 :            : 
+     259                 :          1 :     spdm_test_context = *state;
+     260                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     261                 :          1 :     spdm_test_context->case_id = 0x6;
+     262                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+     263                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     264                 :          1 :     spdm_context->connection_info.connection_state =
+     265                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     266                 :          1 :     spdm_context->connection_info.capability.flags |=
+     267                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
+     268                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     269                 :            :         m_libspdm_use_hash_algo;
+     270                 :            : 
+     271                 :          1 :     libspdm_reset_message_b(spdm_context);
+     272                 :            : 
+     273                 :          1 :     spdm_response = (void *)temp_buf;
+     274                 :          1 :     libspdm_zero_mem(temp_buf, sizeof(temp_buf));
+     275                 :          1 :     spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+     276                 :          1 :     spdm_response->header.request_response_code = SPDM_DIGESTS;
+     277                 :          1 :     spdm_response->header.param1 = (0x01 << 0);
+     278                 :          1 :     spdm_response->header.param2 = 0;
+     279                 :          1 :     spdm_response->header.param2 |= (0x01 << 0);
+     280                 :          1 :     libspdm_set_mem(m_libspdm_local_certificate_chain,
+     281                 :            :                     sizeof(m_libspdm_local_certificate_chain),
+     282                 :            :                     (uint8_t)(0xFF));
+     283                 :            : 
+     284                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     285                 :          1 :     digest = (void *)(spdm_response + 1);
+     286                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
+     287                 :            :                      sizeof(m_libspdm_local_certificate_chain), &digest[0]);
+     288                 :          1 :     key_pair_id = (spdm_key_pair_id_t *)((uint8_t *)digest + hash_size);
+     289                 :          1 :     cert_info = (spdm_certificate_info_t *)((uint8_t *)key_pair_id +
+     290                 :            :                                             sizeof(spdm_key_pair_id_t));
+     291                 :          1 :     key_usage_bit_mask = (spdm_key_usage_bit_mask_t *)((uint8_t *)cert_info +
+     292                 :            :                                                        sizeof(spdm_certificate_info_t));
+     293                 :          1 :     *key_pair_id = 0;
+     294                 :          1 :     *cert_info = SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT;
+     295                 :          1 :     *key_usage_bit_mask = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE |
+     296                 :            :                           SPDM_KEY_USAGE_BIT_MASK_CHALLENGE_USE |
+     297                 :            :                           SPDM_KEY_USAGE_BIT_MASK_MEASUREMENT_USE |
+     298                 :            :                           SPDM_KEY_USAGE_BIT_MASK_ENDPOINT_INFO_USE;
+     299                 :            : 
+     300                 :          1 :     session_id = 0xFFFFFFFF;
+     301                 :          1 :     spdm_context->latest_session_id = session_id;
+     302                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+     303                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+     304                 :          1 :     session_info = &spdm_context->session_info[0];
+     305                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+     306                 :          1 :     libspdm_secured_message_set_session_state(
+     307                 :            :         session_info->secured_message_context,
+     308                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+     309                 :            : 
+     310                 :            :     /* Sub Case 1: Set multi_key_conn_req to true*/
+     311                 :          1 :     spdm_context->connection_info.multi_key_conn_req = true;
+     312                 :          1 :     libspdm_reset_message_encap_d(spdm_context, session_info);
+     313                 :            : 
+     314                 :          1 :     spdm_response_size = sizeof(spdm_digest_response_t) + sizeof(spdm_key_pair_id_t) +
+     315                 :            :                          sizeof(spdm_certificate_info_t) +
+     316                 :            :                          sizeof(spdm_key_usage_bit_mask_t) +
+     317                 :          1 :                          libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     318                 :            : 
+     319                 :          1 :     status = libspdm_process_encap_response_digest(spdm_context, spdm_response_size,
+     320                 :            :                                                    spdm_response, &need_continue);
+     321                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     322                 :          1 :     assert_int_equal(session_info->session_transcript.message_encap_d.buffer_size,
+     323                 :            :                      spdm_response_size);
+     324                 :            : 
+     325                 :            :     /* Sub Case 2: Set multi_key_conn_req to false*/
+     326                 :          1 :     spdm_context->connection_info.multi_key_conn_req = false;
+     327                 :          1 :     libspdm_reset_message_encap_d(spdm_context, session_info);
+     328                 :            : 
+     329                 :          1 :     spdm_response_size = sizeof(spdm_digest_response_t) + sizeof(spdm_key_pair_id_t) +
+     330                 :            :                          sizeof(spdm_certificate_info_t) +
+     331                 :            :                          sizeof(spdm_key_usage_bit_mask_t) +
+     332                 :          1 :                          libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     333                 :          1 :     status = libspdm_process_encap_response_digest(spdm_context, spdm_response_size,
+     334                 :            :                                                    spdm_response, &need_continue);
+     335                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     336                 :          1 :     assert_int_equal(session_info->session_transcript.message_encap_d.buffer_size, 0);
+     337                 :          1 : }
+     338                 :            : 
+     339                 :            : /**
+     340                 :            :  * Test 7: a response message is successfully sent ,
+     341                 :            :  * Check KeyPairID CertificateInfo and KeyUsageMask
+     342                 :            :  * Expected Behavior: requester returns the status RETURN_SUCCESS
+     343                 :            :  **/
+     344                 :          1 : void test_spdm_responder_encap_get_digests_case7(void **state)
+     345                 :            : {
+     346                 :            :     libspdm_return_t status;
+     347                 :            :     libspdm_test_context_t *spdm_test_context;
+     348                 :            :     libspdm_context_t *spdm_context;
+     349                 :            :     spdm_digest_response_t *spdm_response;
+     350                 :            :     uint8_t *digest;
+     351                 :            :     uint8_t temp_buf[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     352                 :            :     size_t spdm_response_size;
+     353                 :            :     bool need_continue;
+     354                 :            :     uint32_t session_id;
+     355                 :            :     libspdm_session_info_t *session_info;
+     356                 :            :     spdm_key_pair_id_t *key_pair_id;
+     357                 :            :     spdm_certificate_info_t *cert_info;
+     358                 :            :     spdm_key_usage_bit_mask_t *key_usage_bit_mask;
+     359                 :            :     uint32_t hash_size;
+     360                 :            :     uint8_t slot_count;
+     361                 :            :     size_t additional_size;
+     362                 :            : 
+     363                 :          1 :     spdm_test_context = *state;
+     364                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     365                 :          1 :     spdm_test_context->case_id = 0x7;
+     366                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+     367                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     368                 :          1 :     spdm_context->connection_info.connection_state =
+     369                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     370                 :          1 :     spdm_context->connection_info.capability.flags |=
+     371                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
+     372                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     373                 :            :         m_libspdm_use_hash_algo;
+     374                 :            : 
+     375                 :          1 :     libspdm_reset_message_b(spdm_context);
+     376                 :            : 
+     377                 :          1 :     spdm_response = (void *)temp_buf;
+     378                 :          1 :     libspdm_zero_mem(temp_buf, sizeof(temp_buf));
+     379                 :          1 :     spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+     380                 :          1 :     spdm_response->header.request_response_code = SPDM_DIGESTS;
+     381                 :          1 :     spdm_response->header.param1 = 0;
+     382                 :          1 :     spdm_response->header.param2 = 0;
+     383                 :          1 :     libspdm_set_mem(m_libspdm_local_certificate_chain,
+     384                 :            :                     sizeof(m_libspdm_local_certificate_chain),
+     385                 :            :                     (uint8_t)(0xFF));
+     386                 :            : 
+     387                 :          1 :     slot_count = SPDM_MAX_SLOT_COUNT;
+     388                 :          1 :     additional_size = sizeof(spdm_key_pair_id_t) + sizeof(spdm_certificate_info_t) +
+     389                 :            :                       sizeof(spdm_key_usage_bit_mask_t);
+     390                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     391                 :            : 
+     392                 :          1 :     digest = (void *)(spdm_response + 1);
+     393                 :          1 :     libspdm_zero_mem (digest, hash_size * slot_count);
+     394                 :          1 :     key_pair_id = (spdm_key_pair_id_t *)((uint8_t *)digest + (hash_size * slot_count));
+     395                 :          1 :     cert_info = (spdm_certificate_info_t *)((uint8_t *)key_pair_id +
+     396                 :          1 :                                             sizeof(spdm_key_pair_id_t) * slot_count);
+     397                 :          1 :     key_usage_bit_mask = (spdm_key_usage_bit_mask_t *)((uint8_t *)cert_info +
+     398                 :          1 :                                                        sizeof(spdm_certificate_info_t) *
+     399                 :            :                                                        slot_count);
+     400                 :            : 
+     401         [ +  + ]:          9 :     for (uint8_t index = 0; index < slot_count; index++)
+     402                 :            :     {
+     403                 :          8 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
+     404                 :          8 :                          sizeof(m_libspdm_local_certificate_chain), &digest[hash_size * index]);
+     405                 :            : 
+     406                 :          8 :         spdm_response->header.param1 |= (1 << index);
+     407                 :          8 :         spdm_response->header.param2 |= (1 << index);
+     408                 :            :     }
+     409                 :          1 :     key_pair_id[0] = 0x00;
+     410                 :          1 :     cert_info[0] = SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT;
+     411                 :          1 :     key_usage_bit_mask[0] = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+     412                 :            : 
+     413                 :          1 :     key_pair_id[1] = 0x01;
+     414                 :          1 :     cert_info[1] = SPDM_CERTIFICATE_INFO_CERT_MODEL_ALIAS_CERT;
+     415                 :          1 :     key_usage_bit_mask[1] = SPDM_KEY_USAGE_BIT_MASK_CHALLENGE_USE;
+     416                 :            : 
+     417                 :          1 :     key_pair_id[2] = 0x02;
+     418                 :          1 :     cert_info[2] = SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT;
+     419                 :          1 :     key_usage_bit_mask[2] = SPDM_KEY_USAGE_BIT_MASK_MEASUREMENT_USE;
+     420                 :            : 
+     421                 :          1 :     key_pair_id[3] = 0x03;
+     422                 :          1 :     cert_info[3] = SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT;
+     423                 :          1 :     key_usage_bit_mask[3] = SPDM_KEY_USAGE_BIT_MASK_ENDPOINT_INFO_USE;
+     424                 :            : 
+     425                 :          1 :     key_pair_id[4] = 0x04;
+     426                 :          1 :     cert_info[4] = SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT;
+     427                 :          1 :     key_usage_bit_mask[4] = SPDM_KEY_USAGE_BIT_MASK_STANDARDS_KEY_USE;
+     428                 :            : 
+     429                 :          1 :     key_pair_id[5] = 0x05;
+     430                 :          1 :     cert_info[5] = SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT;
+     431                 :          1 :     key_usage_bit_mask[5] = SPDM_KEY_USAGE_BIT_MASK_VENDOR_KEY_USE;
+     432                 :            : 
+     433                 :          1 :     key_pair_id[6] = 0x06;
+     434                 :          1 :     cert_info[6] = SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT;
+     435                 :          1 :     key_usage_bit_mask[6] = SPDM_KEY_USAGE_BIT_MASK_VENDOR_KEY_USE;
+     436                 :            : 
+     437                 :          1 :     key_pair_id[7] = 0x07;
+     438                 :          1 :     cert_info[7] = SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT;
+     439                 :          1 :     key_usage_bit_mask[7] = SPDM_KEY_USAGE_BIT_MASK_VENDOR_KEY_USE;
+     440                 :            : 
+     441                 :          1 :     session_id = 0xFFFFFFFF;
+     442                 :          1 :     spdm_context->latest_session_id = session_id;
+     443                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+     444                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+     445                 :          1 :     session_info = &spdm_context->session_info[0];
+     446                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+     447                 :          1 :     libspdm_secured_message_set_session_state(
+     448                 :            :         session_info->secured_message_context,
+     449                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+     450                 :            : 
+     451                 :          1 :     spdm_context->connection_info.multi_key_conn_req = true;
+     452                 :          1 :     libspdm_reset_message_encap_d(spdm_context, session_info);
+     453                 :            : 
+     454                 :          1 :     spdm_response_size = sizeof(spdm_digest_response_t) +
+     455                 :          1 :                          (hash_size + additional_size) * slot_count;
+     456                 :            : 
+     457                 :          1 :     status = libspdm_process_encap_response_digest(spdm_context, spdm_response_size,
+     458                 :            :                                                    spdm_response, &need_continue);
+     459                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     460                 :          1 :     assert_int_equal(session_info->session_transcript.message_encap_d.buffer_size,
+     461                 :            :                      spdm_response_size);
+     462                 :            : 
+     463         [ +  + ]:          9 :     for (uint8_t index = 0; index < SPDM_MAX_SLOT_COUNT; index++) {
+     464                 :          8 :         assert_memory_equal((void *)&key_pair_id[index],
+     465                 :            :                             (void *)&spdm_context->connection_info.peer_key_pair_id[index],
+     466                 :            :                             sizeof(spdm_key_pair_id_t));
+     467                 :          8 :         assert_memory_equal((void *)&cert_info[index],
+     468                 :            :                             (void *)&spdm_context->connection_info.peer_cert_info[index],
+     469                 :            :                             sizeof(spdm_certificate_info_t));
+     470                 :          8 :         assert_memory_equal((void *)&key_usage_bit_mask[index],
+     471                 :            :                             (void *)&spdm_context->connection_info.peer_key_usage_bit_mask[index],
+     472                 :            :                             sizeof(spdm_key_usage_bit_mask_t));
+     473                 :            :     }
+     474                 :          1 : }
+     475                 :            : 
+     476                 :            : libspdm_test_context_t m_spdm_responder_encap_get_digests_test_context = {
+     477                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+     478                 :            :     false,
+     479                 :            : };
+     480                 :            : 
+     481                 :          1 : int spdm_responder_encap_get_digests_test_main(void)
+     482                 :            : {
+     483                 :          1 :     const struct CMUnitTest spdm_responder_digests_tests[] = {
+     484                 :            :         /* Success Case*/
+     485                 :            :         cmocka_unit_test(test_spdm_responder_encap_get_digests_case1),
+     486                 :            :         /* Error response: SPDM_ERROR*/
+     487                 :            :         cmocka_unit_test(test_spdm_responder_encap_get_digests_case2),
+     488                 :            :         /* Error response: RETURN_DEVICE_ERROR*/
+     489                 :            :         cmocka_unit_test(test_spdm_responder_encap_get_digests_case3),
+     490                 :            :         /* request_response_code wrong in response*/
+     491                 :            :         cmocka_unit_test(test_spdm_responder_encap_get_digests_case4),
+     492                 :            :         /* capability flags check failed*/
+     493                 :            :         cmocka_unit_test(test_spdm_responder_encap_get_digests_case5),
+     494                 :            :         /* Set multi_key_conn_req to check if it responds correctly */
+     495                 :            :         cmocka_unit_test(test_spdm_responder_encap_get_digests_case6),
+     496                 :            :         /* Check KeyPairID CertificateInfo and KeyUsageMask*/
+     497                 :            :         cmocka_unit_test(test_spdm_responder_encap_get_digests_case7),
+     498                 :            :     };
+     499                 :            : 
+     500                 :          1 :     libspdm_setup_test_context(&m_spdm_responder_encap_get_digests_test_context);
+     501                 :            : 
+     502                 :          1 :     return cmocka_run_group_tests(spdm_responder_digests_tests,
+     503                 :            :                                   libspdm_unit_test_group_setup,
+     504                 :            :                                   libspdm_unit_test_group_teardown);
+     505                 :            : }
+     506                 :            : 
+     507                 :            : #endif /* (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (...) */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/encap_key_update.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_responder/encap_key_update.c.func-sort-c.html new file mode 100644 index 00000000000..19dbc6f22bc --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/encap_key_update.c.func-sort-c.html @@ -0,0 +1,109 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/encap_key_update.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - encap_key_update.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:114114100.0 %
Date:2024-09-22 08:21:07Functions:77100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_encap_key_update_test_main1
libspdm_test_responder_encap_key_update_case11
libspdm_test_responder_encap_key_update_case21
libspdm_test_responder_encap_key_update_case31
libspdm_test_responder_encap_key_update_case41
libspdm_test_responder_encap_key_update_case51
libspdm_set_standard_key_update_test_state5
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/encap_key_update.c.func.html b/coverage_log/unit_test/test_spdm_responder/encap_key_update.c.func.html new file mode 100644 index 00000000000..87be0fb0cb8 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/encap_key_update.c.func.html @@ -0,0 +1,109 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/encap_key_update.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - encap_key_update.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:114114100.0 %
Date:2024-09-22 08:21:07Functions:77100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_encap_key_update_test_main1
libspdm_set_standard_key_update_test_state5
libspdm_test_responder_encap_key_update_case11
libspdm_test_responder_encap_key_update_case21
libspdm_test_responder_encap_key_update_case31
libspdm_test_responder_encap_key_update_case41
libspdm_test_responder_encap_key_update_case51
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/encap_key_update.c.gcov.html b/coverage_log/unit_test/test_spdm_responder/encap_key_update.c.gcov.html new file mode 100644 index 00000000000..f84ee24ac5f --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/encap_key_update.c.gcov.html @@ -0,0 +1,359 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/encap_key_update.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - encap_key_update.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:114114100.0 %
Date:2024-09-22 08:21:07Functions:77100.0 %
Branches:00-
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 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                 :            : #include "spdm_unit_test.h"
+       7                 :            : #include "internal/libspdm_secured_message_lib.h"
+       8                 :            : #include "internal/libspdm_responder_lib.h"
+       9                 :            : 
+      10                 :            : #if LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP
+      11                 :            : 
+      12                 :          5 : static void libspdm_set_standard_key_update_test_state(libspdm_context_t *spdm_context,
+      13                 :            :                                                        uint32_t *session_id)
+      14                 :            : {
+      15                 :            :     libspdm_session_info_t *session_info;
+      16                 :            : 
+      17                 :          5 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+      18                 :          5 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+      19                 :          5 :     spdm_context->connection_info.capability.flags |=
+      20                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_UPD_CAP;
+      21                 :          5 :     spdm_context->connection_info.capability.flags |=
+      22                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+      23                 :          5 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+      24                 :          5 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP;
+      25                 :          5 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+      26                 :          5 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+      27                 :            : 
+      28                 :          5 :     spdm_context->transcript.message_a.buffer_size = 0;
+      29                 :          5 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+      30                 :          5 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+      31                 :          5 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+      32                 :          5 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+      33                 :            : 
+      34                 :          5 :     *session_id = 0xFFFFFFFF;
+      35                 :          5 :     spdm_context->latest_session_id = *session_id;
+      36                 :          5 :     spdm_context->last_spdm_request_session_id = *session_id;
+      37                 :          5 :     session_info = &spdm_context->session_info[0];
+      38                 :          5 :     libspdm_session_info_init(spdm_context, session_info, *session_id, true);
+      39                 :          5 :     libspdm_secured_message_set_session_state(session_info->secured_message_context,
+      40                 :            :                                               LIBSPDM_SESSION_STATE_ESTABLISHED);
+      41                 :          5 : }
+      42                 :            : 
+      43                 :            : /**
+      44                 :            :  * Test 1: receiving a correct UPDATE_KEY_ACK message for updating
+      45                 :            :  * only the request data key.
+      46                 :            :  * Expected behavior: client returns a Status of RETURN_SUCCESS,Communication needs to continue.
+      47                 :            :  **/
+      48                 :          1 : void libspdm_test_responder_encap_key_update_case1(void **state)
+      49                 :            : {
+      50                 :            :     libspdm_return_t status;
+      51                 :            :     libspdm_test_context_t *spdm_test_context;
+      52                 :            :     libspdm_context_t *spdm_context;
+      53                 :            :     uint32_t session_id;
+      54                 :            :     bool need_continue;
+      55                 :            : 
+      56                 :          1 :     spdm_test_context = *state;
+      57                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+      58                 :            : 
+      59                 :          1 :     spdm_test_context->case_id = 0x1;
+      60                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+      61                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+      62                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+      63                 :          1 :     libspdm_set_standard_key_update_test_state(
+      64                 :            :         spdm_context, &session_id);
+      65                 :            : 
+      66                 :          1 :     spdm_context->encap_context.last_encap_request_header.spdm_version = SPDM_MESSAGE_VERSION_11;
+      67                 :          1 :     spdm_context->encap_context.last_encap_request_header.request_response_code =
+      68                 :            :         SPDM_KEY_UPDATE_ACK;
+      69                 :          1 :     spdm_context->encap_context.last_encap_request_header.param1 =
+      70                 :            :         SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY;
+      71                 :          1 :     spdm_context->encap_context.last_encap_request_header.param2 = 0;
+      72                 :            : 
+      73                 :            :     spdm_key_update_response_t spdm_response;
+      74                 :          1 :     size_t spdm_response_size = sizeof(spdm_key_update_response_t);
+      75                 :            : 
+      76                 :          1 :     spdm_response.header.spdm_version = SPDM_MESSAGE_VERSION_11;
+      77                 :          1 :     spdm_response.header.request_response_code = SPDM_KEY_UPDATE_ACK;
+      78                 :          1 :     spdm_response.header.param1 = SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY;
+      79                 :          1 :     spdm_response.header.param2 = 0;
+      80                 :            : 
+      81                 :          1 :     status = libspdm_process_encap_response_key_update(spdm_context, spdm_response_size,
+      82                 :            :                                                        &spdm_response, &need_continue);
+      83                 :            : 
+      84                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+      85                 :          1 :     assert_int_equal(need_continue, true);
+      86                 :          1 : }
+      87                 :            : 
+      88                 :            : /**
+      89                 :            :  * Test 2: receiving a correct UPDATE_KEY_ACK message for updating
+      90                 :            :  * only the request data key.
+      91                 :            :  * Expected behavior: client returns a Status of RETURN_SUCCESS,Communication needs to continue.
+      92                 :            :  **/
+      93                 :          1 : void libspdm_test_responder_encap_key_update_case2(void **state)
+      94                 :            : {
+      95                 :            :     libspdm_return_t status;
+      96                 :            :     libspdm_test_context_t *spdm_test_context;
+      97                 :            :     libspdm_context_t *spdm_context;
+      98                 :            :     uint32_t session_id;
+      99                 :            :     bool need_continue;
+     100                 :            : 
+     101                 :          1 :     spdm_test_context = *state;
+     102                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     103                 :            : 
+     104                 :          1 :     spdm_test_context->case_id = 0x2;
+     105                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+     106                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     107                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     108                 :          1 :     libspdm_set_standard_key_update_test_state(
+     109                 :            :         spdm_context, &session_id);
+     110                 :            : 
+     111                 :          1 :     spdm_context->encap_context.last_encap_request_header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     112                 :          1 :     spdm_context->encap_context.last_encap_request_header.request_response_code =
+     113                 :            :         SPDM_KEY_UPDATE_ACK;
+     114                 :          1 :     spdm_context->encap_context.last_encap_request_header.param1 =
+     115                 :            :         SPDM_KEY_UPDATE_OPERATIONS_TABLE_VERIFY_NEW_KEY;
+     116                 :          1 :     spdm_context->encap_context.last_encap_request_header.param2 = 0;
+     117                 :            : 
+     118                 :            :     spdm_key_update_response_t spdm_response;
+     119                 :          1 :     size_t spdm_response_size = sizeof(spdm_key_update_response_t);
+     120                 :            : 
+     121                 :          1 :     spdm_response.header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     122                 :          1 :     spdm_response.header.request_response_code = SPDM_KEY_UPDATE_ACK;
+     123                 :          1 :     spdm_response.header.param1 = SPDM_KEY_UPDATE_OPERATIONS_TABLE_VERIFY_NEW_KEY;
+     124                 :          1 :     spdm_response.header.param2 = 0;
+     125                 :            : 
+     126                 :          1 :     status = libspdm_process_encap_response_key_update(spdm_context, spdm_response_size,
+     127                 :            :                                                        &spdm_response, &need_continue);
+     128                 :            : 
+     129                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     130                 :          1 :     assert_int_equal(need_continue, false);
+     131                 :          1 : }
+     132                 :            : /**
+     133                 :            :  * Test 3: receiving a correct UPDATE_KEY_ACK message for updating
+     134                 :            :  * only the request data key. last_spdm_request_session_id_valid invalid
+     135                 :            :  * Expected behavior: client returns a Status of RETURN_UNSUPPORTED,No further communication is required.
+     136                 :            :  **/
+     137                 :          1 : void libspdm_test_responder_encap_key_update_case3(void **state)
+     138                 :            : {
+     139                 :            :     libspdm_return_t status;
+     140                 :            :     libspdm_test_context_t *spdm_test_context;
+     141                 :            :     libspdm_context_t *spdm_context;
+     142                 :            :     uint32_t session_id;
+     143                 :            :     bool need_continue;
+     144                 :            : 
+     145                 :          1 :     spdm_test_context = *state;
+     146                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     147                 :            : 
+     148                 :          1 :     spdm_test_context->case_id = 0x3;
+     149                 :          1 :     spdm_context->last_spdm_request_session_id_valid = false;
+     150                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     151                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     152                 :          1 :     libspdm_set_standard_key_update_test_state(
+     153                 :            :         spdm_context, &session_id);
+     154                 :            : 
+     155                 :            :     spdm_key_update_response_t spdm_response;
+     156                 :          1 :     size_t spdm_response_size = sizeof(spdm_key_update_response_t);
+     157                 :            : 
+     158                 :          1 :     spdm_response.header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     159                 :          1 :     spdm_response.header.request_response_code =    SPDM_KEY_UPDATE_ACK;
+     160                 :          1 :     spdm_response.header.param1 = 0;
+     161                 :          1 :     spdm_response.header.param2 = 0;
+     162                 :            : 
+     163                 :          1 :     status = libspdm_process_encap_response_key_update(spdm_context, spdm_response_size,
+     164                 :            :                                                        &spdm_response, &need_continue);
+     165                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_UNSUPPORTED_CAP);
+     166                 :          1 : }
+     167                 :            : 
+     168                 :            : /**
+     169                 :            :  * Test 4: receives an ERROR message indicating InvalidParameters when updating key.
+     170                 :            :  * Expected behavior: client returns a Status of RETURN_SECURITY_VIOLATION, and
+     171                 :            :  * no keys should be updated.
+     172                 :            :  **/
+     173                 :          1 : void libspdm_test_responder_encap_key_update_case4(void **state)
+     174                 :            : {
+     175                 :            :     libspdm_return_t status;
+     176                 :            :     libspdm_test_context_t *spdm_test_context;
+     177                 :            :     libspdm_context_t *spdm_context;
+     178                 :            :     uint32_t session_id;
+     179                 :            :     bool need_continue;
+     180                 :            : 
+     181                 :          1 :     spdm_test_context = *state;
+     182                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     183                 :            : 
+     184                 :          1 :     spdm_test_context->case_id = 0x4;
+     185                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+     186                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     187                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     188                 :          1 :     libspdm_set_standard_key_update_test_state(
+     189                 :            :         spdm_context, &session_id);
+     190                 :            : 
+     191                 :            :     spdm_key_update_response_t spdm_response;
+     192                 :          1 :     size_t spdm_response_size = sizeof(spdm_key_update_response_t);
+     193                 :            : 
+     194                 :          1 :     spdm_response.header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     195                 :          1 :     spdm_response.header.request_response_code = SPDM_ERROR;
+     196                 :          1 :     spdm_response.header.param1 = SPDM_ERROR_CODE_DECRYPT_ERROR;
+     197                 :          1 :     spdm_response.header.param2 = 0;
+     198                 :            : 
+     199                 :          1 :     status = libspdm_process_encap_response_key_update(spdm_context, spdm_response_size,
+     200                 :            :                                                        &spdm_response, &need_continue);
+     201                 :            : 
+     202                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SESSION_MSG_ERROR);
+     203                 :          1 : }
+     204                 :            : 
+     205                 :            : /**
+     206                 :            :  * Test 5: spdm_response message is correct but does not match last_encap_request_header error message
+     207                 :            :  * Expected behavior: client returns a Status of RETURN_DEVICE_ERROR
+     208                 :            :  **/
+     209                 :          1 : void libspdm_test_responder_encap_key_update_case5(void **state)
+     210                 :            : {
+     211                 :            :     libspdm_return_t status;
+     212                 :            :     libspdm_test_context_t *spdm_test_context;
+     213                 :            :     libspdm_context_t *spdm_context;
+     214                 :            :     uint32_t session_id;
+     215                 :            :     bool need_continue;
+     216                 :            : 
+     217                 :          1 :     spdm_test_context = *state;
+     218                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     219                 :            : 
+     220                 :          1 :     spdm_test_context->case_id = 0x5;
+     221                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+     222                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     223                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     224                 :          1 :     libspdm_set_standard_key_update_test_state(
+     225                 :            :         spdm_context, &session_id);
+     226                 :            : 
+     227                 :          1 :     spdm_context->encap_context.last_encap_request_header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     228                 :          1 :     spdm_context->encap_context.last_encap_request_header.request_response_code =
+     229                 :            :         SPDM_KEY_UPDATE_ACK;
+     230                 :          1 :     spdm_context->encap_context.last_encap_request_header.param1 = SPDM_ERROR_CODE_DECRYPT_ERROR;
+     231                 :          1 :     spdm_context->encap_context.last_encap_request_header.param2 = 0;
+     232                 :            : 
+     233                 :            :     spdm_key_update_response_t spdm_response;
+     234                 :          1 :     size_t spdm_response_size = sizeof(spdm_key_update_response_t);
+     235                 :            : 
+     236                 :          1 :     spdm_response.header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     237                 :          1 :     spdm_response.header.request_response_code = SPDM_KEY_UPDATE_ACK;
+     238                 :          1 :     spdm_response.header.param1 = 0;
+     239                 :          1 :     spdm_response.header.param2 = 0;
+     240                 :            : 
+     241                 :          1 :     status = libspdm_process_encap_response_key_update(spdm_context, spdm_response_size,
+     242                 :            :                                                        &spdm_response, &need_continue);
+     243                 :            : 
+     244                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
+     245                 :          1 : }
+     246                 :            : 
+     247                 :            : libspdm_test_context_t m_libspdm_responder_encap_key_update_test_context = {
+     248                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+     249                 :            :     false,
+     250                 :            : };
+     251                 :            : 
+     252                 :          1 : int libspdm_responder_encap_key_update_test_main(void)
+     253                 :            : {
+     254                 :          1 :     const struct CMUnitTest spdm_responder_key_update_tests[] = {
+     255                 :            :         /* Successful response*/
+     256                 :            :         cmocka_unit_test(libspdm_test_responder_encap_key_update_case1),
+     257                 :            :         /* Successful response,No further communication is required.*/
+     258                 :            :         cmocka_unit_test(libspdm_test_responder_encap_key_update_case2),
+     259                 :            :         /* last_spdm_request_session_id_valid : false */
+     260                 :            :         cmocka_unit_test(libspdm_test_responder_encap_key_update_case3),
+     261                 :            :         /* Error response: RETURN_SECURITY_VIOLATION */
+     262                 :            :         cmocka_unit_test(libspdm_test_responder_encap_key_update_case4),
+     263                 :            :         /* Error response: RETURN_DEVICE_ERROR */
+     264                 :            :         cmocka_unit_test(libspdm_test_responder_encap_key_update_case5),
+     265                 :            :     };
+     266                 :            : 
+     267                 :          1 :     libspdm_setup_test_context(&m_libspdm_responder_encap_key_update_test_context);
+     268                 :            : 
+     269                 :          1 :     return cmocka_run_group_tests(spdm_responder_key_update_tests,
+     270                 :            :                                   libspdm_unit_test_group_setup,
+     271                 :            :                                   libspdm_unit_test_group_teardown);
+     272                 :            : }
+     273                 :            : 
+     274                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/encap_response.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_responder/encap_response.c.func-sort-c.html new file mode 100644 index 00000000000..20949466ab8 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/encap_response.c.func-sort-c.html @@ -0,0 +1,145 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/encap_response.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - encap_response.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:503503100.0 %
Date:2024-09-22 08:21:07Functions:1616100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_encapsulated_response_test_main1
libspdm_test_get_response_encapsulated_request_case11
libspdm_test_get_response_encapsulated_request_case21
libspdm_test_get_response_encapsulated_request_case31
libspdm_test_get_response_encapsulated_request_case41
libspdm_test_get_response_encapsulated_request_case51
libspdm_test_get_response_encapsulated_request_case61
libspdm_test_get_response_encapsulated_response_ack_case11
libspdm_test_get_response_encapsulated_response_ack_case21
libspdm_test_get_response_encapsulated_response_ack_case31
libspdm_test_get_response_encapsulated_response_ack_case41
libspdm_test_get_response_encapsulated_response_ack_case51
libspdm_test_get_response_encapsulated_response_ack_case61
libspdm_test_get_response_encapsulated_response_ack_case71
libspdm_test_get_response_encapsulated_response_ack_case81
libspdm_test_get_response_encapsulated_response_ack_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/encap_response.c.func.html b/coverage_log/unit_test/test_spdm_responder/encap_response.c.func.html new file mode 100644 index 00000000000..15f2357a95c --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/encap_response.c.func.html @@ -0,0 +1,145 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/encap_response.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - encap_response.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:503503100.0 %
Date:2024-09-22 08:21:07Functions:1616100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_encapsulated_response_test_main1
libspdm_test_get_response_encapsulated_request_case11
libspdm_test_get_response_encapsulated_request_case21
libspdm_test_get_response_encapsulated_request_case31
libspdm_test_get_response_encapsulated_request_case41
libspdm_test_get_response_encapsulated_request_case51
libspdm_test_get_response_encapsulated_request_case61
libspdm_test_get_response_encapsulated_response_ack_case11
libspdm_test_get_response_encapsulated_response_ack_case21
libspdm_test_get_response_encapsulated_response_ack_case31
libspdm_test_get_response_encapsulated_response_ack_case41
libspdm_test_get_response_encapsulated_response_ack_case51
libspdm_test_get_response_encapsulated_response_ack_case61
libspdm_test_get_response_encapsulated_response_ack_case71
libspdm_test_get_response_encapsulated_response_ack_case81
libspdm_test_get_response_encapsulated_response_ack_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/encap_response.c.gcov.html b/coverage_log/unit_test/test_spdm_responder/encap_response.c.gcov.html new file mode 100644 index 00000000000..b3385cf2020 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/encap_response.c.gcov.html @@ -0,0 +1,1183 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/encap_response.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - encap_response.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:503503100.0 %
Date:2024-09-22 08:21:07Functions:1616100.0 %
Branches:00-
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_responder_lib.h"
+       9                 :            : 
+      10                 :            : #if LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP
+      11                 :            : 
+      12                 :            : spdm_get_encapsulated_request_request_t m_libspdm_encapsulated_request_t1 = {
+      13                 :            :     {SPDM_MESSAGE_VERSION_11, SPDM_GET_ENCAPSULATED_REQUEST, 0, 0}
+      14                 :            : };
+      15                 :            : size_t m_libspdm_encapsulated_request_t1_size = sizeof(m_libspdm_encapsulated_request_t1);
+      16                 :            : 
+      17                 :            : spdm_deliver_encapsulated_response_request_t m_libspdm_m_deliver_encapsulated_response_request_t1 =
+      18                 :            : {
+      19                 :            :     {SPDM_MESSAGE_VERSION_11, SPDM_DELIVER_ENCAPSULATED_RESPONSE, 0, 0}
+      20                 :            : };
+      21                 :            : size_t m_libspdm_m_deliver_encapsulated_response_request_t1_size =
+      22                 :            :     sizeof(m_libspdm_m_deliver_encapsulated_response_request_t1);
+      23                 :            : 
+      24                 :            : static uint8_t m_libspdm_local_certificate_chain[LIBSPDM_MAX_CERT_CHAIN_SIZE];
+      25                 :            : 
+      26                 :            : spdm_deliver_encapsulated_response_request_t m_libspdm_m_deliver_encapsulated_response_request_t2 =
+      27                 :            : {
+      28                 :            :     {SPDM_MESSAGE_VERSION_12, SPDM_DELIVER_ENCAPSULATED_RESPONSE, 0xFF, 0}
+      29                 :            : };
+      30                 :            : size_t m_libspdm_m_deliver_encapsulated_response_request_t2_size =
+      31                 :            :     sizeof(m_libspdm_m_deliver_encapsulated_response_request_t2);
+      32                 :            : 
+      33                 :            : #if (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT)
+      34                 :            : 
+      35                 :          1 : void libspdm_test_get_response_encapsulated_request_case1(void **State)
+      36                 :            : {
+      37                 :            :     libspdm_return_t status;
+      38                 :            :     libspdm_test_context_t *spdm_test_context;
+      39                 :            :     spdm_encapsulated_request_response_t *spdm_response_requester;
+      40                 :            :     libspdm_context_t *spdm_context;
+      41                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+      42                 :            :     size_t data_size;
+      43                 :            :     void *data;
+      44                 :            :     size_t response_size;
+      45                 :            : 
+      46                 :          1 :     spdm_test_context = *State;
+      47                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+      48                 :          1 :     spdm_test_context->case_id = 0x1;
+      49                 :            : 
+      50                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_PROCESSING_ENCAP;
+      51                 :            : 
+      52                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
+      53                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
+      54                 :          1 :     spdm_context->encap_context.request_op_code_count =
+      55                 :            :         LIBSPDM_MAX_ENCAP_REQUEST_OP_CODE_SEQUENCE_COUNT;
+      56                 :          1 :     spdm_context->encap_context.current_request_op_code = 0;
+      57                 :          1 :     spdm_context->encap_context.request_op_code_sequence[0] = SPDM_GET_DIGESTS;
+      58                 :          1 :     spdm_context->encap_context.request_id = 0;
+      59                 :            : 
+      60                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+      61                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+      62                 :            : 
+      63                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+      64                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
+      65                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+      66                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+      67                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+      68                 :            :                                                     m_libspdm_use_asym_algo, &data,
+      69                 :            :                                                     &data_size,
+      70                 :            :                                                     NULL, NULL);
+      71                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
+      72                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+      73                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+      74                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+      75                 :          1 :     libspdm_reset_message_b(spdm_context);
+      76                 :            : 
+      77                 :          1 :     response_size = sizeof(response);
+      78                 :          1 :     status = libspdm_get_response_encapsulated_request(spdm_context,
+      79                 :            :                                                        m_libspdm_encapsulated_request_t1_size,
+      80                 :            :                                                        &m_libspdm_encapsulated_request_t1,
+      81                 :            :                                                        &response_size,
+      82                 :            :                                                        response);
+      83                 :            : 
+      84                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+      85                 :          1 :     assert_int_equal(response_size,
+      86                 :            :                      sizeof(spdm_encapsulated_request_response_t) + sizeof(spdm_digest_response_t));
+      87                 :          1 :     spdm_response_requester = (void *)response;
+      88                 :          1 :     assert_int_equal(spdm_response_requester->header.request_response_code,
+      89                 :            :                      SPDM_ENCAPSULATED_REQUEST);
+      90                 :          1 :     assert_int_equal(spdm_response_requester->header.param1,
+      91                 :            :                      0x1);
+      92                 :          1 :     assert_int_equal(spdm_response_requester->header.param2, 0);
+      93                 :          1 :     free(data);
+      94                 :          1 : }
+      95                 :            : 
+      96                 :          1 : void libspdm_test_get_response_encapsulated_request_case2(void **State)
+      97                 :            : {
+      98                 :            :     libspdm_return_t status;
+      99                 :            :     libspdm_test_context_t *spdm_test_context;
+     100                 :            :     spdm_encapsulated_request_response_t *spdm_response_requester;
+     101                 :            :     libspdm_context_t *spdm_context;
+     102                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     103                 :            :     size_t data_size;
+     104                 :            :     void *data;
+     105                 :            :     size_t response_size;
+     106                 :            : 
+     107                 :          1 :     spdm_test_context = *State;
+     108                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     109                 :          1 :     spdm_test_context->case_id = 0x2;
+     110                 :            : 
+     111                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_PROCESSING_ENCAP;
+     112                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
+     113                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
+     114                 :          1 :     spdm_context->encap_context.request_op_code_count =
+     115                 :            :         LIBSPDM_MAX_ENCAP_REQUEST_OP_CODE_SEQUENCE_COUNT;
+     116                 :          1 :     spdm_context->encap_context.current_request_op_code = 0;
+     117                 :          1 :     spdm_context->encap_context.request_op_code_sequence[0] = SPDM_GET_CERTIFICATE;
+     118                 :          1 :     spdm_context->encap_context.request_id = 0;
+     119                 :            : 
+     120                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     121                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
+     122                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     123                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     124                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     125                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     126                 :            :                                                     &data_size,
+     127                 :            :                                                     NULL, NULL);
+     128                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
+     129                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     130                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     131                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     132                 :          1 :     libspdm_reset_message_b(spdm_context);
+     133                 :            : 
+     134                 :          1 :     response_size = sizeof(response);
+     135                 :            : 
+     136                 :          1 :     status = libspdm_get_response_encapsulated_request(spdm_context,
+     137                 :            :                                                        m_libspdm_encapsulated_request_t1_size,
+     138                 :            :                                                        &m_libspdm_encapsulated_request_t1,
+     139                 :            :                                                        &response_size,
+     140                 :            :                                                        response);
+     141                 :            : 
+     142                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     143                 :          1 :     assert_int_equal(response_size,
+     144                 :            :                      sizeof(spdm_encapsulated_request_response_t) +
+     145                 :            :                      sizeof(spdm_certificate_response_t));
+     146                 :          1 :     spdm_response_requester = (void *)response;
+     147                 :          1 :     assert_int_equal(spdm_response_requester->header.request_response_code,
+     148                 :            :                      SPDM_ENCAPSULATED_REQUEST);
+     149                 :          1 :     assert_int_equal(spdm_response_requester->header.param1,
+     150                 :            :                      0x1);
+     151                 :          1 :     assert_int_equal(spdm_response_requester->header.param2, 0);
+     152                 :          1 :     free(data);
+     153                 :          1 : }
+     154                 :            : 
+     155                 :          1 : void libspdm_test_get_response_encapsulated_request_case3(void **State)
+     156                 :            : {
+     157                 :            :     libspdm_return_t status;
+     158                 :            :     libspdm_test_context_t *spdm_test_context;
+     159                 :            :     spdm_encapsulated_request_response_t *spdm_response_requester;
+     160                 :            :     libspdm_context_t *spdm_context;
+     161                 :            :     size_t response_size;
+     162                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     163                 :            :     uint8_t m_local_certificate_chain[LIBSPDM_MAX_CERT_CHAIN_SIZE];
+     164                 :            : 
+     165                 :          1 :     spdm_test_context = *State;
+     166                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     167                 :          1 :     spdm_test_context->case_id = 0x3;
+     168                 :            : 
+     169                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+     170                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
+     171                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
+     172                 :            : 
+     173                 :          1 :     spdm_context->encap_context.current_request_op_code = 0;
+     174                 :          1 :     spdm_context->encap_context.request_id = 0;
+     175                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     176                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     177                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     178                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = m_local_certificate_chain;
+     179                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     180                 :            :         sizeof(m_local_certificate_chain);
+     181                 :          1 :     libspdm_set_mem(m_local_certificate_chain, sizeof(m_local_certificate_chain), (uint8_t)(0xFF));
+     182                 :            : 
+     183                 :          1 :     response_size = sizeof(response);
+     184                 :          1 :     status = libspdm_get_response_encapsulated_request(spdm_context,
+     185                 :            :                                                        m_libspdm_encapsulated_request_t1_size,
+     186                 :            :                                                        &m_libspdm_encapsulated_request_t1,
+     187                 :            :                                                        &response_size,
+     188                 :            :                                                        response);
+     189                 :            : 
+     190                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     191                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     192                 :          1 :     spdm_response_requester = (void *)response;
+     193                 :          1 :     assert_int_equal(spdm_response_requester->header.request_response_code,
+     194                 :            :                      SPDM_ERROR);
+     195                 :          1 :     assert_int_equal(spdm_response_requester->header.param1,
+     196                 :            :                      SPDM_ERROR_CODE_UNEXPECTED_REQUEST);
+     197                 :          1 :     assert_int_equal(spdm_response_requester->header.param2, 0);
+     198                 :          1 : }
+     199                 :            : 
+     200                 :          1 : void libspdm_test_get_response_encapsulated_request_case4(void **State)
+     201                 :            : {
+     202                 :            :     libspdm_return_t status;
+     203                 :            :     libspdm_test_context_t *spdm_test_context;
+     204                 :            :     spdm_encapsulated_request_response_t *spdm_response_requester;
+     205                 :            :     libspdm_context_t *spdm_context;
+     206                 :            :     size_t response_size;
+     207                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     208                 :            :     uint8_t m_local_certificate_chain[LIBSPDM_MAX_CERT_CHAIN_SIZE];
+     209                 :            : 
+     210                 :          1 :     spdm_test_context = *State;
+     211                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     212                 :          1 :     spdm_test_context->case_id = 0x4;
+     213                 :            : 
+     214                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NEED_RESYNC;
+     215                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
+     216                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
+     217                 :            : 
+     218                 :          1 :     spdm_context->encap_context.current_request_op_code = SPDM_GET_DIGESTS;
+     219                 :            : 
+     220                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     221                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     222                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     223                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = m_local_certificate_chain;
+     224                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     225                 :            :         sizeof(m_local_certificate_chain);
+     226                 :          1 :     libspdm_set_mem(m_local_certificate_chain, sizeof(m_local_certificate_chain), (uint8_t)(0xFF));
+     227                 :            : 
+     228                 :          1 :     response_size = sizeof(response);
+     229                 :          1 :     status = libspdm_get_response_encapsulated_request(spdm_context,
+     230                 :            :                                                        m_libspdm_encapsulated_request_t1_size,
+     231                 :            :                                                        &m_libspdm_encapsulated_request_t1,
+     232                 :            :                                                        &response_size,
+     233                 :            :                                                        response);
+     234                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     235                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     236                 :          1 :     spdm_response_requester = (void *)response;
+     237                 :          1 :     assert_int_equal(spdm_response_requester->header.request_response_code,
+     238                 :            :                      SPDM_ERROR);
+     239                 :          1 :     assert_int_equal(spdm_response_requester->header.param1,
+     240                 :            :                      SPDM_ERROR_CODE_REQUEST_RESYNCH);
+     241                 :          1 :     assert_int_equal(spdm_response_requester->header.param2, 0);
+     242                 :          1 : }
+     243                 :            : #endif /* (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT) */
+     244                 :            : #if (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_SEND_CHALLENGE_SUPPORT)
+     245                 :          1 : void libspdm_test_get_response_encapsulated_request_case5(void **State)
+     246                 :            : {
+     247                 :            :     libspdm_return_t status;
+     248                 :            :     libspdm_test_context_t *spdm_test_context;
+     249                 :            :     spdm_encapsulated_request_response_t *spdm_response_requester;
+     250                 :            :     libspdm_context_t *spdm_context;
+     251                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     252                 :            :     size_t data_size;
+     253                 :            :     void *data;
+     254                 :            :     size_t response_size;
+     255                 :            : 
+     256                 :          1 :     spdm_test_context = *State;
+     257                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     258                 :          1 :     spdm_test_context->case_id = 0x5;
+     259                 :            : 
+     260                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_PROCESSING_ENCAP;
+     261                 :          1 :     spdm_context->connection_info.capability.flags = 0;
+     262                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
+     263                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
+     264                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
+     265                 :          1 :     spdm_context->encap_context.request_op_code_count =
+     266                 :            :         LIBSPDM_MAX_ENCAP_REQUEST_OP_CODE_SEQUENCE_COUNT;
+     267                 :          1 :     spdm_context->encap_context.current_request_op_code = 0;
+     268                 :          1 :     spdm_context->encap_context.request_op_code_sequence[0] = SPDM_CHALLENGE;
+     269                 :          1 :     spdm_context->encap_context.request_id = 0;
+     270                 :            : 
+     271                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     272                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
+     273                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     274                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     275                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     276                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     277                 :            :                                                     &data_size,
+     278                 :            :                                                     NULL, NULL);
+     279                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
+     280                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     281                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     282                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     283                 :          1 :     libspdm_reset_message_b(spdm_context);
+     284                 :            : 
+     285                 :          1 :     response_size = sizeof(response);
+     286                 :          1 :     status = libspdm_get_response_encapsulated_request(spdm_context,
+     287                 :            :                                                        m_libspdm_encapsulated_request_t1_size,
+     288                 :            :                                                        &m_libspdm_encapsulated_request_t1,
+     289                 :            :                                                        &response_size,
+     290                 :            :                                                        response);
+     291                 :            : 
+     292                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     293                 :          1 :     assert_int_equal(response_size,
+     294                 :            :                      sizeof(spdm_encapsulated_request_response_t) +
+     295                 :            :                      sizeof(spdm_challenge_request_t));
+     296                 :          1 :     spdm_response_requester = (void *)response;
+     297                 :          1 :     assert_int_equal(spdm_response_requester->header.request_response_code,
+     298                 :            :                      SPDM_ENCAPSULATED_REQUEST);
+     299                 :          1 :     assert_int_equal(spdm_response_requester->header.param1,
+     300                 :            :                      0x1);
+     301                 :          1 :     assert_int_equal(spdm_response_requester->header.param2, 0);
+     302                 :          1 :     free(data);
+     303                 :          1 : }
+     304                 :            : 
+     305                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_SEND_CHALLENGE_SUPPORT) */
+     306                 :            : 
+     307                 :          1 : void libspdm_test_get_response_encapsulated_request_case6(void **State)
+     308                 :            : {
+     309                 :            :     libspdm_return_t status;
+     310                 :            :     libspdm_test_context_t *spdm_test_context;
+     311                 :            :     spdm_encapsulated_request_response_t *spdm_response_requester;
+     312                 :            :     libspdm_context_t *spdm_context;
+     313                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     314                 :            :     size_t data_size;
+     315                 :            :     void *data;
+     316                 :            :     size_t response_size;
+     317                 :            :     uint32_t session_id;
+     318                 :            :     libspdm_session_info_t *session_info;
+     319                 :            : 
+     320                 :          1 :     spdm_test_context = *State;
+     321                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     322                 :          1 :     spdm_test_context->case_id = 0x6;
+     323                 :            : 
+     324                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_PROCESSING_ENCAP;
+     325                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     326                 :          1 :     spdm_context->connection_info.capability.flags |=
+     327                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP;
+     328                 :          1 :     spdm_context->local_context.capability.flags |=
+     329                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_UPD_CAP;
+     330                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
+     331                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
+     332                 :          1 :     spdm_context->encap_context.request_op_code_count =
+     333                 :            :         LIBSPDM_MAX_ENCAP_REQUEST_OP_CODE_SEQUENCE_COUNT;
+     334                 :          1 :     spdm_context->encap_context.current_request_op_code = 0;
+     335                 :          1 :     spdm_context->encap_context.request_op_code_sequence[0] = SPDM_KEY_UPDATE;
+     336                 :          1 :     spdm_context->encap_context.request_id = 0;
+     337                 :            : 
+     338                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     339                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
+     340                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     341                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     342                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     343                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     344                 :            :                                                     &data_size,
+     345                 :            :                                                     NULL, NULL);
+     346                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
+     347                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     348                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     349                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     350                 :          1 :     libspdm_reset_message_b(spdm_context);
+     351                 :            : 
+     352                 :          1 :     session_id = 0xFFFFFFFF;
+     353                 :          1 :     spdm_context->latest_session_id = session_id;
+     354                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+     355                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+     356                 :          1 :     session_info = &spdm_context->session_info[0];
+     357                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+     358                 :          1 :     libspdm_secured_message_set_session_state(session_info->secured_message_context,
+     359                 :            :                                               LIBSPDM_SESSION_STATE_ESTABLISHED);
+     360                 :            : 
+     361                 :          1 :     response_size = sizeof(response);
+     362                 :          1 :     status = libspdm_get_response_encapsulated_request(spdm_context,
+     363                 :            :                                                        m_libspdm_encapsulated_request_t1_size,
+     364                 :            :                                                        &m_libspdm_encapsulated_request_t1,
+     365                 :            :                                                        &response_size,
+     366                 :            :                                                        response);
+     367                 :            : 
+     368                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     369                 :          1 :     assert_int_equal(response_size,
+     370                 :            :                      sizeof(spdm_encapsulated_request_response_t) +
+     371                 :            :                      sizeof(spdm_key_update_response_t));
+     372                 :          1 :     spdm_response_requester = (void *)response;
+     373                 :          1 :     assert_int_equal(spdm_response_requester->header.request_response_code,
+     374                 :            :                      SPDM_ENCAPSULATED_REQUEST);
+     375                 :          1 :     assert_int_equal(spdm_response_requester->header.param1,
+     376                 :            :                      0x1);
+     377                 :          1 :     assert_int_equal(spdm_response_requester->header.param2, 0);
+     378                 :          1 :     free(data);
+     379                 :          1 : }
+     380                 :            : 
+     381                 :          1 : void libspdm_test_get_response_encapsulated_response_ack_case1(void **State)
+     382                 :            : {
+     383                 :            :     libspdm_return_t status;
+     384                 :            :     libspdm_test_context_t *spdm_test_context;
+     385                 :            :     libspdm_context_t *spdm_context;
+     386                 :            :     spdm_deliver_encapsulated_response_request_t *spdm_response_requester;
+     387                 :            :     spdm_digest_response_t *spdm_response_requester_digest;
+     388                 :            :     uint8_t temp_buf[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     389                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     390                 :            :     size_t spdm_response_requester_size;
+     391                 :            :     size_t spdm_response_requester_digest_size;
+     392                 :            :     size_t data_size;
+     393                 :            :     size_t response_size;
+     394                 :            :     uint8_t *digest;
+     395                 :            :     void *data;
+     396                 :            : 
+     397                 :          1 :     spdm_test_context = *State;
+     398                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     399                 :            : 
+     400                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_PROCESSING_ENCAP;
+     401                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
+     402                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
+     403                 :          1 :     spdm_context->encap_context.request_op_code_count =
+     404                 :            :         LIBSPDM_MAX_ENCAP_REQUEST_OP_CODE_SEQUENCE_COUNT;
+     405                 :            : 
+     406                 :          1 :     spdm_context->encap_context.current_request_op_code = SPDM_GET_DIGESTS;
+     407                 :          1 :     spdm_context->encap_context.request_op_code_sequence[0] = SPDM_GET_DIGESTS;
+     408                 :            : 
+     409                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     410                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
+     411                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     412                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     413                 :          1 :     spdm_context->encap_context.request_id = 0;
+     414                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     415                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     416                 :            :                                                     &data_size,
+     417                 :            :                                                     NULL, NULL);
+     418                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
+     419                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     420                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     421                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     422                 :          1 :     libspdm_reset_message_b(spdm_context);
+     423                 :            : 
+     424                 :          1 :     spdm_response_requester_size = sizeof(spdm_digest_response_t) +
+     425                 :          1 :                                    libspdm_get_hash_size(m_libspdm_use_hash_algo) +
+     426                 :            :                                    sizeof(spdm_deliver_encapsulated_response_request_t);
+     427                 :            : 
+     428                 :          1 :     spdm_response_requester = (void *)temp_buf;
+     429                 :          1 :     libspdm_copy_mem(spdm_response_requester,
+     430                 :            :                      sizeof(temp_buf),
+     431                 :            :                      &m_libspdm_m_deliver_encapsulated_response_request_t1,
+     432                 :            :                      m_libspdm_m_deliver_encapsulated_response_request_t1_size);
+     433                 :            : 
+     434                 :          1 :     spdm_response_requester_digest_size = sizeof(spdm_digest_response_t) +
+     435                 :          1 :                                           libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     436                 :          1 :     spdm_response_requester_digest =
+     437                 :            :         (void *)(temp_buf + sizeof(spdm_deliver_encapsulated_response_request_t));
+     438                 :          1 :     spdm_response_requester_digest->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     439                 :          1 :     spdm_response_requester_digest->header.param1 = 0;
+     440                 :          1 :     spdm_response_requester_digest->header.request_response_code = SPDM_DIGESTS;
+     441                 :          1 :     spdm_response_requester_digest->header.param2 = 0;
+     442                 :            : 
+     443                 :          1 :     digest = (void *)(spdm_response_requester_digest + 1);
+     444                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
+     445                 :            :                      sizeof(m_libspdm_local_certificate_chain), &digest[0]);
+     446                 :          1 :     spdm_response_requester_digest->header.param2 |= (0x01 << 0);
+     447                 :            : 
+     448                 :          1 :     libspdm_set_mem(m_libspdm_local_certificate_chain,
+     449                 :            :                     sizeof(m_libspdm_local_certificate_chain),
+     450                 :            :                     (uint8_t)(0xFF));
+     451                 :            : 
+     452                 :          1 :     libspdm_copy_mem(spdm_response_requester + 1,
+     453                 :            :                      spdm_response_requester_digest_size,
+     454                 :            :                      spdm_response_requester_digest,
+     455                 :            :                      spdm_response_requester_digest_size);
+     456                 :            : 
+     457                 :          1 :     response_size = sizeof(response);
+     458                 :          1 :     status = libspdm_get_response_encapsulated_response_ack(spdm_context,
+     459                 :            :                                                             spdm_response_requester_size,
+     460                 :            :                                                             spdm_response_requester, &response_size,
+     461                 :            :                                                             response);
+     462                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     463                 :          1 :     free(data);
+     464                 :          1 : }
+     465                 :            : 
+     466                 :          1 : void libspdm_test_get_response_encapsulated_response_ack_case2(void **State)
+     467                 :            : {
+     468                 :            :     libspdm_return_t status;
+     469                 :            :     libspdm_test_context_t *spdm_test_context;
+     470                 :            :     libspdm_context_t *spdm_context;
+     471                 :            :     spdm_deliver_encapsulated_response_request_t *spdm_response_requester;
+     472                 :            :     spdm_certificate_response_t *spdm_response_requester_certificate;
+     473                 :            :     uint8_t temp_buf[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     474                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     475                 :            :     size_t spdm_response_requester_size;
+     476                 :            :     size_t data_size;
+     477                 :            :     size_t response_size;
+     478                 :            :     void *data;
+     479                 :            :     uint16_t portion_length;
+     480                 :            :     uint16_t remainder_length;
+     481                 :            :     static size_t calling_index = 0;
+     482                 :            : 
+     483                 :            :     static void *libspdm_local_certificate_chain;
+     484                 :            :     static size_t libspdm_local_certificate_chain_size;
+     485                 :            : 
+     486                 :          1 :     spdm_test_context = *State;
+     487                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     488                 :            : 
+     489                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_PROCESSING_ENCAP;
+     490                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
+     491                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
+     492                 :          1 :     spdm_context->encap_context.request_op_code_count =
+     493                 :            :         LIBSPDM_MAX_ENCAP_REQUEST_OP_CODE_SEQUENCE_COUNT;
+     494                 :            : 
+     495                 :          1 :     spdm_context->encap_context.current_request_op_code = SPDM_GET_CERTIFICATE;
+     496                 :          1 :     spdm_context->encap_context.request_op_code_sequence[0] = SPDM_GET_CERTIFICATE;
+     497                 :            : 
+     498                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     499                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
+     500                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     501                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     502                 :          1 :     spdm_context->encap_context.request_id = 0;
+     503                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     504                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     505                 :            :                                                     &data_size,
+     506                 :            :                                                     NULL, NULL);
+     507                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
+     508                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     509                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     510                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     511                 :          1 :     libspdm_reset_message_b(spdm_context);
+     512                 :            : 
+     513                 :          1 :     spdm_response_requester = (void *)temp_buf;
+     514                 :          1 :     libspdm_copy_mem(spdm_response_requester,
+     515                 :            :                      sizeof(temp_buf),
+     516                 :            :                      &m_libspdm_m_deliver_encapsulated_response_request_t1,
+     517                 :            :                      m_libspdm_m_deliver_encapsulated_response_request_t1_size);
+     518                 :            : 
+     519                 :          1 :     spdm_response_requester_certificate =
+     520                 :            :         (void *)(temp_buf + sizeof(spdm_deliver_encapsulated_response_request_t));
+     521                 :            : 
+     522                 :          1 :     libspdm_read_responder_public_certificate_chain(
+     523                 :            :         m_libspdm_use_hash_algo, m_libspdm_use_asym_algo,
+     524                 :            :         &libspdm_local_certificate_chain,
+     525                 :            :         &libspdm_local_certificate_chain_size, NULL, NULL);
+     526                 :            : 
+     527                 :          1 :     portion_length = LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN;
+     528                 :          1 :     remainder_length =
+     529                 :          1 :         (uint16_t)(libspdm_local_certificate_chain_size -
+     530                 :            :                    LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN *
+     531                 :          1 :                    (calling_index + 1));
+     532                 :            : 
+     533                 :          1 :     spdm_response_requester_certificate->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     534                 :          1 :     spdm_response_requester_certificate->header.request_response_code = SPDM_CERTIFICATE;
+     535                 :          1 :     spdm_response_requester_certificate->header.param1 = 0;
+     536                 :          1 :     spdm_response_requester_certificate->header.param2 = 0;
+     537                 :          1 :     spdm_response_requester_certificate->portion_length = portion_length;
+     538                 :          1 :     spdm_response_requester_certificate->remainder_length = remainder_length;
+     539                 :            : 
+     540                 :          1 :     libspdm_copy_mem(spdm_response_requester_certificate + 1,
+     541                 :            :                      sizeof(temp_buf) - sizeof(*spdm_response_requester_certificate),
+     542                 :          1 :                      (uint8_t *)libspdm_local_certificate_chain +
+     543                 :          1 :                      LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN * calling_index,
+     544                 :            :                      portion_length);
+     545                 :            : 
+     546                 :          1 :     free(libspdm_local_certificate_chain);
+     547                 :            : 
+     548                 :          1 :     response_size = sizeof(response);
+     549                 :          1 :     spdm_response_requester_size = sizeof(spdm_certificate_response_t) + portion_length +
+     550                 :            :                                    sizeof(spdm_deliver_encapsulated_response_request_t);
+     551                 :          1 :     status = libspdm_get_response_encapsulated_response_ack(spdm_context,
+     552                 :            :                                                             spdm_response_requester_size,
+     553                 :            :                                                             spdm_response_requester, &response_size,
+     554                 :            :                                                             response);
+     555                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     556                 :          1 :     free(data);
+     557                 :          1 : }
+     558                 :            : 
+     559                 :          1 : void libspdm_test_get_response_encapsulated_response_ack_case3(void **State)
+     560                 :            : {
+     561                 :            :     libspdm_return_t status;
+     562                 :            :     libspdm_test_context_t *spdm_test_context;
+     563                 :            :     libspdm_context_t *spdm_context;
+     564                 :            :     spdm_deliver_encapsulated_response_request_t *spdm_response_requester;
+     565                 :            :     spdm_key_update_response_t *spdm_response_requester_key_update;
+     566                 :            :     uint8_t temp_buf[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     567                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     568                 :            :     size_t spdm_response_requester_size;
+     569                 :            :     size_t data_size;
+     570                 :            :     size_t response_size;
+     571                 :            :     void *data;
+     572                 :            :     uint32_t session_id;
+     573                 :            :     libspdm_session_info_t *session_info;
+     574                 :            : 
+     575                 :          1 :     spdm_test_context = *State;
+     576                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     577                 :            : 
+     578                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+     579                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_PROCESSING_ENCAP;
+     580                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
+     581                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
+     582                 :          1 :     spdm_context->encap_context.request_op_code_count =
+     583                 :            :         LIBSPDM_MAX_ENCAP_REQUEST_OP_CODE_SEQUENCE_COUNT;
+     584                 :            : 
+     585                 :          1 :     spdm_context->encap_context.current_request_op_code = SPDM_KEY_UPDATE;
+     586                 :          1 :     spdm_context->encap_context.request_op_code_sequence[0] = SPDM_KEY_UPDATE;
+     587                 :            : 
+     588                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     589                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
+     590                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     591                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     592                 :          1 :     spdm_context->encap_context.request_id = 0;
+     593                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     594                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     595                 :            :                                                     &data_size,
+     596                 :            :                                                     NULL, NULL);
+     597                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
+     598                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     599                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     600                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     601                 :            : 
+     602                 :          1 :     libspdm_reset_message_b(spdm_context);
+     603                 :            : 
+     604                 :          1 :     session_id = 0xFFFFFFFF;
+     605                 :          1 :     spdm_context->latest_session_id = session_id;
+     606                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+     607                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+     608                 :          1 :     session_info = &spdm_context->session_info[0];
+     609                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+     610                 :          1 :     libspdm_secured_message_set_session_state(session_info->secured_message_context,
+     611                 :            :                                               LIBSPDM_SESSION_STATE_ESTABLISHED);
+     612                 :            : 
+     613                 :          1 :     spdm_context->encap_context.last_encap_request_header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     614                 :          1 :     spdm_context->encap_context.last_encap_request_header.request_response_code =
+     615                 :            :         SPDM_KEY_UPDATE_ACK;
+     616                 :          1 :     spdm_context->encap_context.last_encap_request_header.param1 =
+     617                 :            :         SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY;
+     618                 :          1 :     spdm_context->encap_context.last_encap_request_header.param2 = 0;
+     619                 :            : 
+     620                 :          1 :     spdm_response_requester = (void *)temp_buf;
+     621                 :          1 :     libspdm_copy_mem(spdm_response_requester,
+     622                 :            :                      sizeof(temp_buf),
+     623                 :            :                      &m_libspdm_m_deliver_encapsulated_response_request_t1,
+     624                 :            :                      m_libspdm_m_deliver_encapsulated_response_request_t1_size);
+     625                 :            : 
+     626                 :          1 :     spdm_response_requester_key_update =
+     627                 :            :         (void *)(temp_buf + sizeof(spdm_deliver_encapsulated_response_request_t));
+     628                 :            : 
+     629                 :          1 :     spdm_response_requester_key_update->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     630                 :          1 :     spdm_response_requester_key_update->header.request_response_code =
+     631                 :            :         SPDM_KEY_UPDATE_ACK;
+     632                 :          1 :     spdm_response_requester_key_update->header.param1 =
+     633                 :            :         SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY;
+     634                 :          1 :     spdm_response_requester_key_update->header.param2 = 0;
+     635                 :            : 
+     636                 :          1 :     response_size = sizeof(response);
+     637                 :          1 :     spdm_response_requester_size = sizeof(spdm_key_update_response_t) +
+     638                 :            :                                    sizeof(spdm_deliver_encapsulated_response_request_t);
+     639                 :          1 :     status = libspdm_get_response_encapsulated_response_ack(spdm_context,
+     640                 :            :                                                             spdm_response_requester_size,
+     641                 :            :                                                             spdm_response_requester, &response_size,
+     642                 :            :                                                             response);
+     643                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     644                 :          1 :     free(data);
+     645                 :          1 : }
+     646                 :            : 
+     647                 :          1 : void libspdm_test_get_response_encapsulated_response_ack_case4(void **State)
+     648                 :            : {
+     649                 :            :     libspdm_return_t status;
+     650                 :            :     spdm_encapsulated_request_response_t *spdm_response_requester;
+     651                 :            :     libspdm_test_context_t *spdm_test_context;
+     652                 :            :     libspdm_context_t *spdm_context;
+     653                 :            :     size_t response_size;
+     654                 :          1 :     spdm_test_context = *State;
+     655                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     656                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     657                 :            : 
+     658                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_PROCESSING_ENCAP;
+     659                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
+     660                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
+     661                 :          1 :     spdm_context->encap_context.request_op_code_count =
+     662                 :            :         LIBSPDM_MAX_ENCAP_REQUEST_OP_CODE_SEQUENCE_COUNT;
+     663                 :          1 :     spdm_context->encap_context.current_request_op_code = 0;
+     664                 :          1 :     libspdm_reset_message_b(spdm_context);
+     665                 :            : 
+     666                 :          1 :     response_size = sizeof(response);
+     667                 :          1 :     status = libspdm_get_response_encapsulated_response_ack(spdm_context,
+     668                 :            :                                                             m_libspdm_m_deliver_encapsulated_response_request_t1_size,
+     669                 :            :                                                             &m_libspdm_m_deliver_encapsulated_response_request_t1, &response_size,
+     670                 :            :                                                             response);
+     671                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     672                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     673                 :          1 :     spdm_response_requester = (void *)response;
+     674                 :          1 :     assert_int_equal(spdm_response_requester->header.request_response_code,
+     675                 :            :                      SPDM_ERROR);
+     676                 :          1 :     assert_int_equal(spdm_response_requester->header.param1,
+     677                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+     678                 :          1 :     assert_int_equal(spdm_response_requester->header.param2, 0);
+     679                 :          1 : }
+     680                 :            : 
+     681                 :          1 : void libspdm_test_get_response_encapsulated_response_ack_case5(void **State)
+     682                 :            : {
+     683                 :            :     libspdm_return_t status;
+     684                 :            :     spdm_encapsulated_request_response_t *spdm_response_requester;
+     685                 :            :     libspdm_test_context_t *spdm_test_context;
+     686                 :            :     libspdm_context_t *spdm_context;
+     687                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     688                 :            :     size_t response_size;
+     689                 :          1 :     spdm_test_context = *State;
+     690                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     691                 :            : 
+     692                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+     693                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
+     694                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
+     695                 :          1 :     spdm_context->encap_context.request_op_code_count =
+     696                 :            :         LIBSPDM_MAX_ENCAP_REQUEST_OP_CODE_SEQUENCE_COUNT;
+     697                 :          1 :     spdm_context->encap_context.current_request_op_code = 0;
+     698                 :            : 
+     699                 :          1 :     response_size = sizeof(response);
+     700                 :          1 :     status = libspdm_get_response_encapsulated_response_ack(spdm_context,
+     701                 :            :                                                             m_libspdm_m_deliver_encapsulated_response_request_t1_size,
+     702                 :            :                                                             &m_libspdm_m_deliver_encapsulated_response_request_t1, &response_size,
+     703                 :            :                                                             response);
+     704                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     705                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     706                 :          1 :     spdm_response_requester = (void *)response;
+     707                 :          1 :     assert_int_equal(spdm_response_requester->header.request_response_code,
+     708                 :            :                      SPDM_ERROR);
+     709                 :          1 :     assert_int_equal(spdm_response_requester->header.param1,
+     710                 :            :                      SPDM_ERROR_CODE_UNEXPECTED_REQUEST);
+     711                 :          1 :     assert_int_equal(spdm_response_requester->header.param2, 0);
+     712                 :          1 : }
+     713                 :            : 
+     714                 :          1 : void libspdm_test_get_response_encapsulated_response_ack_case6(void **State)
+     715                 :            : {
+     716                 :            :     libspdm_return_t status;
+     717                 :            :     spdm_encapsulated_request_response_t *spdm_response_requester;
+     718                 :            :     libspdm_test_context_t *spdm_test_context;
+     719                 :            :     libspdm_context_t *spdm_context;
+     720                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     721                 :            :     size_t response_size;
+     722                 :            :     size_t data_size;
+     723                 :            :     void *data;
+     724                 :            : 
+     725                 :          1 :     spdm_test_context = *State;
+     726                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     727                 :            : 
+     728                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NEED_RESYNC;
+     729                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     730                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
+     731                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
+     732                 :          1 :     spdm_context->encap_context.request_op_code_count =
+     733                 :            :         LIBSPDM_MAX_ENCAP_REQUEST_OP_CODE_SEQUENCE_COUNT;
+     734                 :            : 
+     735                 :          1 :     status = libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     736                 :            :                                                              m_libspdm_use_asym_algo, &data,
+     737                 :            :                                                              &data_size,
+     738                 :            :                                                              NULL, NULL);
+     739                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
+     740                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     741                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     742                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     743                 :            : 
+     744                 :          1 :     response_size = sizeof(response);
+     745                 :          1 :     status = libspdm_get_response_encapsulated_response_ack(spdm_context,
+     746                 :            :                                                             m_libspdm_m_deliver_encapsulated_response_request_t1_size,
+     747                 :            :                                                             &m_libspdm_m_deliver_encapsulated_response_request_t1, &response_size,
+     748                 :            :                                                             response);
+     749                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     750                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     751                 :          1 :     spdm_response_requester = (void *)response;
+     752                 :          1 :     assert_int_equal(spdm_response_requester->header.request_response_code,
+     753                 :            :                      SPDM_ERROR);
+     754                 :          1 :     assert_int_equal(spdm_response_requester->header.param1,
+     755                 :            :                      SPDM_ERROR_CODE_REQUEST_RESYNCH);
+     756                 :          1 :     assert_int_equal(spdm_response_requester->header.param2, 0);
+     757                 :          1 : }
+     758                 :            : 
+     759                 :          1 : void libspdm_test_get_response_encapsulated_response_ack_case7(void **State)
+     760                 :            : {
+     761                 :            :     libspdm_return_t status;
+     762                 :            :     libspdm_test_context_t *spdm_test_context;
+     763                 :            :     libspdm_context_t *spdm_context;
+     764                 :            :     spdm_deliver_encapsulated_response_request_t *spdm_response_requester;
+     765                 :            :     spdm_certificate_response_t *spdm_response_requester_certificate;
+     766                 :            :     uint8_t temp_buf[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     767                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     768                 :            :     size_t spdm_response_requester_size;
+     769                 :            :     size_t data_size;
+     770                 :            :     size_t response_size;
+     771                 :            :     void *data;
+     772                 :            :     uint16_t portion_length;
+     773                 :            :     uint16_t remainder_length;
+     774                 :            :     static size_t calling_index = 0;
+     775                 :            : 
+     776                 :            :     static void *libspdm_local_certificate_chain;
+     777                 :            :     static size_t libspdm_local_certificate_chain_size;
+     778                 :            : 
+     779                 :          1 :     spdm_test_context = *State;
+     780                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     781                 :            : 
+     782                 :          1 :     spdm_context->encap_context.request_id = 0xFF;
+     783                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_PROCESSING_ENCAP;
+     784                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
+     785                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
+     786                 :          1 :     spdm_context->encap_context.request_op_code_count =
+     787                 :            :         LIBSPDM_MAX_ENCAP_REQUEST_OP_CODE_SEQUENCE_COUNT;
+     788                 :            : 
+     789                 :          1 :     spdm_context->encap_context.current_request_op_code = SPDM_GET_CERTIFICATE;
+     790                 :          1 :     spdm_context->encap_context.request_op_code_sequence[0] = SPDM_GET_CERTIFICATE;
+     791                 :            : 
+     792                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     793                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
+     794                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     795                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     796                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     797                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     798                 :            :                                                     &data_size,
+     799                 :            :                                                     NULL, NULL);
+     800                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
+     801                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     802                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     803                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     804                 :          1 :     libspdm_reset_message_b(spdm_context);
+     805                 :            : 
+     806                 :          1 :     spdm_response_requester = (void *)temp_buf;
+     807                 :          1 :     libspdm_copy_mem(spdm_response_requester,
+     808                 :            :                      sizeof(temp_buf),
+     809                 :            :                      &m_libspdm_m_deliver_encapsulated_response_request_t1,
+     810                 :            :                      m_libspdm_m_deliver_encapsulated_response_request_t1_size);
+     811                 :            : 
+     812                 :          1 :     spdm_response_requester_certificate =
+     813                 :            :         (void *)(temp_buf + sizeof(spdm_deliver_encapsulated_response_request_t));
+     814                 :            : 
+     815                 :          1 :     libspdm_read_responder_public_certificate_chain(
+     816                 :            :         m_libspdm_use_hash_algo, m_libspdm_use_asym_algo,
+     817                 :            :         &libspdm_local_certificate_chain,
+     818                 :            :         &libspdm_local_certificate_chain_size, NULL, NULL);
+     819                 :            : 
+     820                 :          1 :     portion_length = LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN;
+     821                 :          1 :     remainder_length =
+     822                 :          1 :         (uint16_t)(libspdm_local_certificate_chain_size -
+     823                 :            :                    LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN *
+     824                 :          1 :                    (calling_index + 1));
+     825                 :            : 
+     826                 :          1 :     spdm_response_requester_certificate->header.spdm_version = SPDM_MESSAGE_VERSION_11;
+     827                 :          1 :     spdm_response_requester_certificate->header.request_response_code = SPDM_CERTIFICATE;
+     828                 :          1 :     spdm_response_requester_certificate->header.param1 = 0;
+     829                 :          1 :     spdm_response_requester_certificate->header.param2 = 0;
+     830                 :          1 :     spdm_response_requester_certificate->portion_length = portion_length;
+     831                 :          1 :     spdm_response_requester_certificate->remainder_length = remainder_length;
+     832                 :            : 
+     833                 :          1 :     libspdm_copy_mem(spdm_response_requester_certificate + 1,
+     834                 :            :                      sizeof(temp_buf) - sizeof(*spdm_response_requester_certificate),
+     835                 :          1 :                      (uint8_t *)libspdm_local_certificate_chain +
+     836                 :          1 :                      LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN * calling_index,
+     837                 :            :                      portion_length);
+     838                 :            : 
+     839                 :          1 :     free(libspdm_local_certificate_chain);
+     840                 :            : 
+     841                 :          1 :     response_size = sizeof(response);
+     842                 :          1 :     spdm_response_requester_size = sizeof(spdm_certificate_response_t) + portion_length +
+     843                 :            :                                    sizeof(spdm_deliver_encapsulated_response_request_t);
+     844                 :          1 :     status = libspdm_get_response_encapsulated_response_ack(spdm_context,
+     845                 :            :                                                             spdm_response_requester_size,
+     846                 :            :                                                             spdm_response_requester, &response_size,
+     847                 :            :                                                             response);
+     848                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     849                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     850                 :          1 :     spdm_response_requester = (void *)response;
+     851                 :          1 :     assert_int_equal(spdm_response_requester->header.request_response_code,
+     852                 :            :                      SPDM_ERROR);
+     853                 :          1 :     assert_int_equal(spdm_response_requester->header.param1,
+     854                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+     855                 :          1 :     assert_int_equal(spdm_response_requester->header.param2, 0);
+     856                 :          1 :     free(data);
+     857                 :          1 : }
+     858                 :            : 
+     859                 :          1 : void libspdm_test_get_response_encapsulated_response_ack_case8(void **State)
+     860                 :            : {
+     861                 :            :     libspdm_return_t status;
+     862                 :            :     libspdm_test_context_t *spdm_test_context;
+     863                 :            :     libspdm_context_t *spdm_context;
+     864                 :            :     spdm_encapsulated_response_ack_response_t *spdm_response;
+     865                 :            :     spdm_deliver_encapsulated_response_request_t *spdm_response_requester;
+     866                 :            :     spdm_digest_response_t *spdm_response_requester_digest;
+     867                 :            :     uint8_t temp_buf[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     868                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     869                 :            :     size_t spdm_response_requester_size;
+     870                 :            :     size_t spdm_response_requester_digest_size;
+     871                 :            :     size_t data_size;
+     872                 :            :     size_t response_size;
+     873                 :            :     uint8_t *digest;
+     874                 :            :     void *data;
+     875                 :            : 
+     876                 :          1 :     spdm_test_context = *State;
+     877                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     878                 :            : 
+     879                 :          1 :     spdm_context->encap_context.request_id = 0xFF;
+     880                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_PROCESSING_ENCAP;
+     881                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
+     882                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
+     883                 :          1 :     spdm_context->encap_context.request_op_code_count =
+     884                 :            :         LIBSPDM_MAX_ENCAP_REQUEST_OP_CODE_SEQUENCE_COUNT;
+     885                 :            : 
+     886                 :          1 :     spdm_context->encap_context.current_request_op_code = SPDM_GET_DIGESTS;
+     887                 :          1 :     spdm_context->encap_context.request_op_code_sequence[0] = SPDM_GET_DIGESTS;
+     888                 :            : 
+     889                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     890                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
+     891                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     892                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     893                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     894                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     895                 :            :                                                     &data_size,
+     896                 :            :                                                     NULL, NULL);
+     897                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
+     898                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     899                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     900                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     901                 :          1 :     libspdm_reset_message_b(spdm_context);
+     902                 :            : 
+     903                 :          1 :     spdm_response_requester_size = sizeof(spdm_digest_response_t) +
+     904                 :          1 :                                    libspdm_get_hash_size(m_libspdm_use_hash_algo) +
+     905                 :            :                                    sizeof(spdm_deliver_encapsulated_response_request_t);
+     906                 :            : 
+     907                 :          1 :     spdm_response_requester = (void *)temp_buf;
+     908                 :          1 :     libspdm_copy_mem(spdm_response_requester,
+     909                 :            :                      sizeof(temp_buf),
+     910                 :            :                      &m_libspdm_m_deliver_encapsulated_response_request_t2,
+     911                 :            :                      m_libspdm_m_deliver_encapsulated_response_request_t2_size);
+     912                 :            : 
+     913                 :          1 :     spdm_response_requester_digest_size = sizeof(spdm_digest_response_t) +
+     914                 :          1 :                                           libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     915                 :          1 :     spdm_response_requester_digest =
+     916                 :            :         (void *)(temp_buf + sizeof(spdm_deliver_encapsulated_response_request_t));
+     917                 :          1 :     spdm_response_requester_digest->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     918                 :          1 :     spdm_response_requester_digest->header.param1 = 0;
+     919                 :          1 :     spdm_response_requester_digest->header.request_response_code = SPDM_DIGESTS;
+     920                 :          1 :     spdm_response_requester_digest->header.param2 = 0;
+     921                 :            : 
+     922                 :          1 :     digest = (void *)(spdm_response_requester_digest + 1);
+     923                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
+     924                 :            :                      sizeof(m_libspdm_local_certificate_chain), &digest[0]);
+     925                 :          1 :     spdm_response_requester_digest->header.param2 |= (0x01 << 0);
+     926                 :            : 
+     927                 :          1 :     libspdm_set_mem(m_libspdm_local_certificate_chain,
+     928                 :            :                     sizeof(m_libspdm_local_certificate_chain),
+     929                 :            :                     (uint8_t)(0xFF));
+     930                 :            : 
+     931                 :          1 :     libspdm_copy_mem(spdm_response_requester + 1,
+     932                 :            :                      spdm_response_requester_digest_size,
+     933                 :            :                      spdm_response_requester_digest,
+     934                 :            :                      spdm_response_requester_digest_size);
+     935                 :            : 
+     936                 :          1 :     response_size = sizeof(response);
+     937                 :          1 :     status = libspdm_get_response_encapsulated_response_ack(spdm_context,
+     938                 :            :                                                             spdm_response_requester_size,
+     939                 :            :                                                             spdm_response_requester, &response_size,
+     940                 :            :                                                             response);
+     941                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     942                 :          1 :     assert_int_equal(response_size, sizeof(spdm_encapsulated_response_ack_response_t));
+     943                 :          1 :     spdm_response = (void *)response;
+     944                 :          1 :     assert_int_equal(spdm_response->header.spdm_version,
+     945                 :            :                      SPDM_MESSAGE_VERSION_12);
+     946                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     947                 :            :                      SPDM_ENCAPSULATED_RESPONSE_ACK);
+     948                 :          1 :     assert_int_equal(spdm_response->header.param1, 0);
+     949                 :          1 :     assert_int_equal(spdm_response->header.param2,
+     950                 :            :                      SPDM_ENCAPSULATED_RESPONSE_ACK_RESPONSE_PAYLOAD_TYPE_ABSENT);
+     951                 :          1 :     assert_int_equal(spdm_response->ack_request_id,
+     952                 :            :                      m_libspdm_m_deliver_encapsulated_response_request_t2.header.param1);
+     953                 :          1 :     free(data);
+     954                 :          1 : }
+     955                 :            : 
+     956                 :            : /**
+     957                 :            :  * Test 9: In an encapsulated request flow, a Responder issue an encapsulated request that can take up to CT time to
+     958                 :            :  * fulfill, then the Requester deliver an encapsulated ERROR message with a ResponseNotReady error code.
+     959                 :            :  * Expected behavior: the Responder shall not encapsulate another request by setting Param2 in ENCAPSULATED_RESPONSE_ACK
+     960                 :            :  * to a value of zero.
+     961                 :            :  **/
+     962                 :          1 : void libspdm_test_get_response_encapsulated_response_ack_case9(void **State)
+     963                 :            : {
+     964                 :            :     libspdm_return_t status;
+     965                 :            :     libspdm_test_context_t *spdm_test_context;
+     966                 :            :     libspdm_context_t *spdm_context;
+     967                 :            :     spdm_encapsulated_response_ack_response_t *spdm_response;
+     968                 :            :     spdm_deliver_encapsulated_response_request_t *spdm_request;
+     969                 :            :     spdm_error_response_data_response_not_ready_t *EncapsulatedResponse;
+     970                 :            :     uint8_t temp_buf[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     971                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     972                 :            :     size_t spdm_request_size;
+     973                 :            :     size_t EncapsulatedResponse_size;
+     974                 :            :     size_t response_size;
+     975                 :            : 
+     976                 :          1 :     spdm_test_context = *State;
+     977                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     978                 :            : 
+     979                 :          1 :     spdm_context->encap_context.request_id = 0xFF;
+     980                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_PROCESSING_ENCAP;
+     981                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
+     982                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
+     983                 :          1 :     spdm_context->encap_context.request_op_code_count =
+     984                 :            :         LIBSPDM_MAX_ENCAP_REQUEST_OP_CODE_SEQUENCE_COUNT;
+     985                 :            : 
+     986                 :          1 :     spdm_context->encap_context.current_request_op_code = SPDM_GET_DIGESTS;
+     987                 :          1 :     spdm_context->encap_context.request_op_code_sequence[0] = SPDM_GET_DIGESTS;
+     988                 :            : 
+     989                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     990                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
+     991                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     992                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     993                 :          1 :     libspdm_reset_message_b(spdm_context);
+     994                 :            : 
+     995                 :          1 :     spdm_request_size = sizeof(spdm_deliver_encapsulated_response_request_t) +
+     996                 :            :                         sizeof(spdm_error_response_data_response_not_ready_t);
+     997                 :            : 
+     998                 :          1 :     spdm_request = (void *)temp_buf;
+     999                 :          1 :     libspdm_copy_mem(spdm_request,
+    1000                 :            :                      sizeof(temp_buf),
+    1001                 :            :                      &m_libspdm_m_deliver_encapsulated_response_request_t2,
+    1002                 :            :                      m_libspdm_m_deliver_encapsulated_response_request_t2_size);
+    1003                 :            : 
+    1004                 :          1 :     EncapsulatedResponse_size = sizeof(spdm_error_response_data_response_not_ready_t);
+    1005                 :          1 :     EncapsulatedResponse =
+    1006                 :            :         (void *)(temp_buf + sizeof(spdm_deliver_encapsulated_response_request_t));
+    1007                 :          1 :     EncapsulatedResponse->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+    1008                 :          1 :     EncapsulatedResponse->header.request_response_code = SPDM_ERROR;
+    1009                 :          1 :     EncapsulatedResponse->header.param1 =
+    1010                 :            :         SPDM_ERROR_CODE_RESPONSE_NOT_READY;
+    1011                 :          1 :     EncapsulatedResponse->header.param2 = 0;
+    1012                 :          1 :     EncapsulatedResponse->extend_error_data.rd_exponent = 1;
+    1013                 :          1 :     EncapsulatedResponse->extend_error_data.rd_tm = 1;
+    1014                 :          1 :     EncapsulatedResponse->extend_error_data.request_code =
+    1015                 :            :         SPDM_GET_DIGESTS;
+    1016                 :          1 :     EncapsulatedResponse->extend_error_data.token = 0;
+    1017                 :            : 
+    1018                 :          1 :     libspdm_copy_mem(spdm_request + 1,
+    1019                 :            :                      EncapsulatedResponse_size,
+    1020                 :            :                      EncapsulatedResponse,
+    1021                 :            :                      EncapsulatedResponse_size);
+    1022                 :            : 
+    1023                 :          1 :     response_size = sizeof(response);
+    1024                 :          1 :     status = libspdm_get_response_encapsulated_response_ack(spdm_context,
+    1025                 :            :                                                             spdm_request_size,
+    1026                 :            :                                                             spdm_request, &response_size,
+    1027                 :            :                                                             response);
+    1028                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1029                 :          1 :     assert_int_equal(response_size, sizeof(spdm_encapsulated_response_ack_response_t));
+    1030                 :          1 :     spdm_response = (void *)response;
+    1031                 :          1 :     assert_int_equal(spdm_response->header.spdm_version,
+    1032                 :            :                      SPDM_MESSAGE_VERSION_12);
+    1033                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1034                 :            :                      SPDM_ENCAPSULATED_RESPONSE_ACK);
+    1035                 :          1 :     assert_int_equal(spdm_response->header.param1, 0);
+    1036                 :          1 :     assert_int_equal(spdm_response->header.param2,
+    1037                 :            :                      SPDM_ENCAPSULATED_RESPONSE_ACK_RESPONSE_PAYLOAD_TYPE_ABSENT);
+    1038                 :          1 :     assert_int_equal(spdm_response->ack_request_id,
+    1039                 :            :                      m_libspdm_m_deliver_encapsulated_response_request_t2.header.param1);
+    1040                 :          1 : }
+    1041                 :            : 
+    1042                 :            : libspdm_test_context_t m_libspdm_response_encapsulated_request_test_context = {
+    1043                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+    1044                 :            :     false,
+    1045                 :            : };
+    1046                 :            : 
+    1047                 :          1 : int libspdm_responder_encapsulated_response_test_main(void)
+    1048                 :            : {
+    1049                 :            : 
+    1050                 :          1 :     const struct CMUnitTest spdm_responder_encapsulated_response_tests[] = {
+    1051                 :            : #if (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT)
+    1052                 :            :         /*Success Case request_op_code_sequence: SPDM_GET_DIGESTS*/
+    1053                 :            :         cmocka_unit_test(libspdm_test_get_response_encapsulated_request_case1),
+    1054                 :            :         /*Success Case current_request_op_code: SPDM_GET_CERTIFICATE */
+    1055                 :            :         cmocka_unit_test(libspdm_test_get_response_encapsulated_request_case2),
+    1056                 :            :         /*response_state : LIBSPDM_RESPONSE_STATE_NORMAL */
+    1057                 :            :         cmocka_unit_test(libspdm_test_get_response_encapsulated_request_case3),
+    1058                 :            :         /*response_state : LIBSPDM_RESPONSE_STATE_NEED_RESYNC */
+    1059                 :            :         cmocka_unit_test(libspdm_test_get_response_encapsulated_request_case4),
+    1060                 :            : #endif /* (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT) */
+    1061                 :            : #if (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_SEND_CHALLENGE_SUPPORT)
+    1062                 :            :         /*Success Case current_request_op_code: SPDM_CHALLENGE */
+    1063                 :            :         cmocka_unit_test(libspdm_test_get_response_encapsulated_request_case5),
+    1064                 :            : #endif
+    1065                 :            :         /* Success Case current_request_op_code: SPDM_KEY_UPDATE */
+    1066                 :            :         cmocka_unit_test(libspdm_test_get_response_encapsulated_request_case6),
+    1067                 :            : #if (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT)
+    1068                 :            :         /*Success Case current_request_op_code: SPDM_GET_DIGESTS*/
+    1069                 :            :         cmocka_unit_test(libspdm_test_get_response_encapsulated_response_ack_case1),
+    1070                 :            :         /*Success Case current_request_op_code: SPDM_GET_CERTIFICATE*/
+    1071                 :            :         cmocka_unit_test(libspdm_test_get_response_encapsulated_response_ack_case2),
+    1072                 :            : #endif
+    1073                 :            :         /* Success Case current_request_op_code: SPDM_KEY_UPDATE */
+    1074                 :            :         cmocka_unit_test(libspdm_test_get_response_encapsulated_response_ack_case3),
+    1075                 :            :         /* current_request_op_code: NULL */
+    1076                 :            :         cmocka_unit_test(libspdm_test_get_response_encapsulated_response_ack_case4),
+    1077                 :            :         /*response_state : LIBSPDM_RESPONSE_STATE_NORMAL */
+    1078                 :            :         cmocka_unit_test(libspdm_test_get_response_encapsulated_response_ack_case5),
+    1079                 :            :         /*response_state : LIBSPDM_RESPONSE_STATE_NEED_RESYNC */
+    1080                 :            :         cmocka_unit_test(libspdm_test_get_response_encapsulated_response_ack_case6),
+    1081                 :            : #if (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT)
+    1082                 :            :         /*spdm_request->header.param1 != spdm_context->encap_context.request_id */
+    1083                 :            :         cmocka_unit_test(libspdm_test_get_response_encapsulated_response_ack_case7),
+    1084                 :            :         /*Success Case  When version is greater than V1.2 */
+    1085                 :            :         cmocka_unit_test(libspdm_test_get_response_encapsulated_response_ack_case8),
+    1086                 :            : #endif
+    1087                 :            :         /*When the Requester delivers an encapsulated ERROR message with a ResponseNotReady error code*/
+    1088                 :            :         cmocka_unit_test(libspdm_test_get_response_encapsulated_response_ack_case9),
+    1089                 :            :     };
+    1090                 :            : 
+    1091                 :          1 :     libspdm_setup_test_context(&m_libspdm_response_encapsulated_request_test_context);
+    1092                 :            : 
+    1093                 :          1 :     return cmocka_run_group_tests(spdm_responder_encapsulated_response_tests,
+    1094                 :            :                                   libspdm_unit_test_group_setup,
+    1095                 :            :                                   libspdm_unit_test_group_teardown);
+    1096                 :            : }
+    1097                 :            : 
+    1098                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/end_session.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_responder/end_session.c.func-sort-c.html new file mode 100644 index 00000000000..d39fe68ffb5 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/end_session.c.func-sort-c.html @@ -0,0 +1,117 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/end_session.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - end_session.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:312312100.0 %
Date:2024-09-22 08:21:07Functions:99100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_end_session_test_main1
libspdm_test_responder_end_session_case11
libspdm_test_responder_end_session_case21
libspdm_test_responder_end_session_case31
libspdm_test_responder_end_session_case41
libspdm_test_responder_end_session_case51
libspdm_test_responder_end_session_case61
libspdm_test_responder_end_session_case71
libspdm_test_responder_end_session_case81
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/end_session.c.func.html b/coverage_log/unit_test/test_spdm_responder/end_session.c.func.html new file mode 100644 index 00000000000..3541f1cec44 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/end_session.c.func.html @@ -0,0 +1,117 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/end_session.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - end_session.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:312312100.0 %
Date:2024-09-22 08:21:07Functions:99100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_end_session_test_main1
libspdm_test_responder_end_session_case11
libspdm_test_responder_end_session_case21
libspdm_test_responder_end_session_case31
libspdm_test_responder_end_session_case41
libspdm_test_responder_end_session_case51
libspdm_test_responder_end_session_case61
libspdm_test_responder_end_session_case71
libspdm_test_responder_end_session_case81
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/end_session.c.gcov.html b/coverage_log/unit_test/test_spdm_responder/end_session.c.gcov.html new file mode 100644 index 00000000000..bf3ae82ea24 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/end_session.c.gcov.html @@ -0,0 +1,757 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/end_session.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - end_session.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:312312100.0 %
Date:2024-09-22 08:21:07Functions:99100.0 %
Branches:00-
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_responder_lib.h"
+       9                 :            : #include "internal/libspdm_secured_message_lib.h"
+      10                 :            : 
+      11                 :            : #if (LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP) || (LIBSPDM_ENABLE_CAPABILITY_PSK_CAP)
+      12                 :            : 
+      13                 :            : spdm_end_session_request_t m_libspdm_end_session_request1 = {
+      14                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_END_SESSION, 0, 0 }
+      15                 :            : };
+      16                 :            : size_t m_libspdm_end_session_request1_size = sizeof(m_libspdm_end_session_request1);
+      17                 :            : 
+      18                 :            : spdm_end_session_request_t m_libspdm_end_session_request2 = {
+      19                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_END_SESSION, 0, 0 }
+      20                 :            : };
+      21                 :            : size_t m_libspdm_end_session_request2_size = LIBSPDM_MAX_SPDM_MSG_SIZE;
+      22                 :            : 
+      23                 :            : spdm_end_session_request_t m_libspdm_end_session_request3 = {
+      24                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_END_SESSION,
+      25                 :            :       SPDM_END_SESSION_REQUEST_ATTRIBUTES_PRESERVE_NEGOTIATED_STATE_CLEAR, 0 }
+      26                 :            : };
+      27                 :            : size_t m_libspdm_end_session_request3_size = sizeof(m_libspdm_end_session_request1);
+      28                 :            : 
+      29                 :          1 : void libspdm_test_responder_end_session_case1(void **state)
+      30                 :            : {
+      31                 :            :     libspdm_return_t status;
+      32                 :            :     libspdm_test_context_t *spdm_test_context;
+      33                 :            :     libspdm_context_t *spdm_context;
+      34                 :            :     size_t response_size;
+      35                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+      36                 :            :     spdm_end_session_response_t *spdm_response;
+      37                 :            :     void *data1;
+      38                 :            :     size_t data_size1;
+      39                 :            :     libspdm_session_info_t *session_info;
+      40                 :            :     uint32_t session_id;
+      41                 :            : 
+      42                 :          1 :     spdm_test_context = *state;
+      43                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+      44                 :          1 :     spdm_test_context->case_id = 0x1;
+      45                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+      46                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+      47                 :          1 :     spdm_context->connection_info.connection_state =
+      48                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+      49                 :          1 :     spdm_context->connection_info.capability.flags |=
+      50                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+      51                 :          1 :     spdm_context->local_context.capability.flags |=
+      52                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+      53                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+      54                 :            :         m_libspdm_use_hash_algo;
+      55                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+      56                 :            :         m_libspdm_use_asym_algo;
+      57                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+      58                 :            :         m_libspdm_use_measurement_spec;
+      59                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+      60                 :            :         m_libspdm_use_measurement_hash_algo;
+      61                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+      62                 :            :         m_libspdm_use_dhe_algo;
+      63                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+      64                 :            :         m_libspdm_use_aead_algo;
+      65                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+      66                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+      67                 :            :                                                     &data_size1, NULL, NULL);
+      68                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+      69                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+      70                 :            :         data_size1;
+      71                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+      72                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+      73                 :            :         data_size1;
+      74                 :            : 
+      75                 :          1 :     libspdm_reset_message_a(spdm_context);
+      76                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+      77                 :            : 
+      78                 :          1 :     session_id = 0xFFFFFFFF;
+      79                 :          1 :     spdm_context->latest_session_id = session_id;
+      80                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+      81                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+      82                 :          1 :     session_info = &spdm_context->session_info[0];
+      83                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+      84                 :          1 :     libspdm_secured_message_set_session_state(
+      85                 :            :         session_info->secured_message_context,
+      86                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+      87                 :            : 
+      88                 :          1 :     response_size = sizeof(response);
+      89                 :          1 :     status = libspdm_get_response_end_session(spdm_context,
+      90                 :            :                                               m_libspdm_end_session_request1_size,
+      91                 :            :                                               &m_libspdm_end_session_request1,
+      92                 :            :                                               &response_size, response);
+      93                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+      94                 :          1 :     assert_int_equal(response_size, sizeof(spdm_end_session_response_t));
+      95                 :          1 :     spdm_response = (void *)response;
+      96                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+      97                 :            :                      SPDM_END_SESSION_ACK);
+      98                 :          1 :     free(data1);
+      99                 :          1 : }
+     100                 :            : 
+     101                 :          1 : void libspdm_test_responder_end_session_case2(void **state)
+     102                 :            : {
+     103                 :            :     libspdm_return_t status;
+     104                 :            :     libspdm_test_context_t *spdm_test_context;
+     105                 :            :     libspdm_context_t *spdm_context;
+     106                 :            :     size_t response_size;
+     107                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     108                 :            :     spdm_end_session_response_t *spdm_response;
+     109                 :            :     void *data1;
+     110                 :            :     size_t data_size1;
+     111                 :            :     libspdm_session_info_t *session_info;
+     112                 :            :     uint32_t session_id;
+     113                 :            : 
+     114                 :          1 :     spdm_test_context = *state;
+     115                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     116                 :          1 :     spdm_test_context->case_id = 0x2;
+     117                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     118                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     119                 :          1 :     spdm_context->connection_info.connection_state =
+     120                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     121                 :          1 :     spdm_context->connection_info.capability.flags |=
+     122                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     123                 :          1 :     spdm_context->local_context.capability.flags |=
+     124                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     125                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     126                 :            :         m_libspdm_use_hash_algo;
+     127                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     128                 :            :         m_libspdm_use_asym_algo;
+     129                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     130                 :            :         m_libspdm_use_measurement_spec;
+     131                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     132                 :            :         m_libspdm_use_measurement_hash_algo;
+     133                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     134                 :            :         m_libspdm_use_dhe_algo;
+     135                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     136                 :            :         m_libspdm_use_aead_algo;
+     137                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     138                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     139                 :            :                                                     &data_size1, NULL, NULL);
+     140                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     141                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     142                 :            :         data_size1;
+     143                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+     144                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+     145                 :            :         data_size1;
+     146                 :            : 
+     147                 :          1 :     libspdm_reset_message_a(spdm_context);
+     148                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     149                 :            : 
+     150                 :          1 :     session_id = 0xFFFFFFFF;
+     151                 :          1 :     spdm_context->latest_session_id = session_id;
+     152                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+     153                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+     154                 :          1 :     session_info = &spdm_context->session_info[0];
+     155                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+     156                 :          1 :     libspdm_secured_message_set_session_state(
+     157                 :            :         session_info->secured_message_context,
+     158                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+     159                 :            : 
+     160                 :          1 :     response_size = sizeof(response);
+     161                 :          1 :     status = libspdm_get_response_end_session(spdm_context,
+     162                 :            :                                               m_libspdm_end_session_request2_size,
+     163                 :            :                                               &m_libspdm_end_session_request2,
+     164                 :            :                                               &response_size, response);
+     165                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     166                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     167                 :          1 :     spdm_response = (void *)response;
+     168                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     169                 :            :                      SPDM_ERROR);
+     170                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     171                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+     172                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     173                 :          1 :     free(data1);
+     174                 :          1 : }
+     175                 :            : 
+     176                 :          1 : void libspdm_test_responder_end_session_case3(void **state)
+     177                 :            : {
+     178                 :            :     libspdm_return_t status;
+     179                 :            :     libspdm_test_context_t *spdm_test_context;
+     180                 :            :     libspdm_context_t *spdm_context;
+     181                 :            :     size_t response_size;
+     182                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     183                 :            :     spdm_end_session_response_t *spdm_response;
+     184                 :            :     void *data1;
+     185                 :            :     size_t data_size1;
+     186                 :            :     libspdm_session_info_t *session_info;
+     187                 :            :     uint32_t session_id;
+     188                 :            : 
+     189                 :          1 :     spdm_test_context = *state;
+     190                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     191                 :          1 :     spdm_test_context->case_id = 0x3;
+     192                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     193                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     194                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_BUSY;
+     195                 :          1 :     spdm_context->connection_info.connection_state =
+     196                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     197                 :          1 :     spdm_context->connection_info.capability.flags |=
+     198                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     199                 :          1 :     spdm_context->local_context.capability.flags |=
+     200                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     201                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     202                 :            :         m_libspdm_use_hash_algo;
+     203                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     204                 :            :         m_libspdm_use_asym_algo;
+     205                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     206                 :            :         m_libspdm_use_measurement_spec;
+     207                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     208                 :            :         m_libspdm_use_measurement_hash_algo;
+     209                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     210                 :            :         m_libspdm_use_dhe_algo;
+     211                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     212                 :            :         m_libspdm_use_aead_algo;
+     213                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     214                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     215                 :            :                                                     &data_size1, NULL, NULL);
+     216                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     217                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     218                 :            :         data_size1;
+     219                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+     220                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+     221                 :            :         data_size1;
+     222                 :            : 
+     223                 :          1 :     libspdm_reset_message_a(spdm_context);
+     224                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     225                 :            : 
+     226                 :          1 :     session_id = 0xFFFFFFFF;
+     227                 :          1 :     spdm_context->latest_session_id = session_id;
+     228                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+     229                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+     230                 :          1 :     session_info = &spdm_context->session_info[0];
+     231                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+     232                 :          1 :     libspdm_secured_message_set_session_state(
+     233                 :            :         session_info->secured_message_context,
+     234                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+     235                 :            : 
+     236                 :          1 :     response_size = sizeof(response);
+     237                 :          1 :     status = libspdm_get_response_end_session(spdm_context,
+     238                 :            :                                               m_libspdm_end_session_request1_size,
+     239                 :            :                                               &m_libspdm_end_session_request1,
+     240                 :            :                                               &response_size, response);
+     241                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     242                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     243                 :          1 :     spdm_response = (void *)response;
+     244                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     245                 :            :                      SPDM_ERROR);
+     246                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_BUSY);
+     247                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     248                 :          1 :     assert_int_equal(spdm_context->response_state,
+     249                 :            :                      LIBSPDM_RESPONSE_STATE_BUSY);
+     250                 :          1 :     free(data1);
+     251                 :          1 : }
+     252                 :            : 
+     253                 :          1 : void libspdm_test_responder_end_session_case4(void **state)
+     254                 :            : {
+     255                 :            :     libspdm_return_t status;
+     256                 :            :     libspdm_test_context_t *spdm_test_context;
+     257                 :            :     libspdm_context_t *spdm_context;
+     258                 :            :     size_t response_size;
+     259                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     260                 :            :     spdm_end_session_response_t *spdm_response;
+     261                 :            :     void *data1;
+     262                 :            :     size_t data_size1;
+     263                 :            :     libspdm_session_info_t *session_info;
+     264                 :            :     uint32_t session_id;
+     265                 :            : 
+     266                 :          1 :     spdm_test_context = *state;
+     267                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     268                 :          1 :     spdm_test_context->case_id = 0x4;
+     269                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     270                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     271                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NEED_RESYNC;
+     272                 :          1 :     spdm_context->connection_info.connection_state =
+     273                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     274                 :          1 :     spdm_context->connection_info.capability.flags |=
+     275                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     276                 :          1 :     spdm_context->local_context.capability.flags |=
+     277                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     278                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     279                 :            :         m_libspdm_use_hash_algo;
+     280                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     281                 :            :         m_libspdm_use_asym_algo;
+     282                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     283                 :            :         m_libspdm_use_measurement_spec;
+     284                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     285                 :            :         m_libspdm_use_measurement_hash_algo;
+     286                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     287                 :            :         m_libspdm_use_dhe_algo;
+     288                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     289                 :            :         m_libspdm_use_aead_algo;
+     290                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     291                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     292                 :            :                                                     &data_size1, NULL, NULL);
+     293                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     294                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     295                 :            :         data_size1;
+     296                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+     297                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+     298                 :            :         data_size1;
+     299                 :            : 
+     300                 :          1 :     libspdm_reset_message_a(spdm_context);
+     301                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     302                 :            : 
+     303                 :          1 :     session_id = 0xFFFFFFFF;
+     304                 :          1 :     spdm_context->latest_session_id = session_id;
+     305                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+     306                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+     307                 :          1 :     session_info = &spdm_context->session_info[0];
+     308                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+     309                 :          1 :     libspdm_secured_message_set_session_state(
+     310                 :            :         session_info->secured_message_context,
+     311                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+     312                 :            : 
+     313                 :          1 :     response_size = sizeof(response);
+     314                 :          1 :     status = libspdm_get_response_end_session(spdm_context,
+     315                 :            :                                               m_libspdm_end_session_request1_size,
+     316                 :            :                                               &m_libspdm_end_session_request1,
+     317                 :            :                                               &response_size, response);
+     318                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     319                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     320                 :          1 :     spdm_response = (void *)response;
+     321                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     322                 :            :                      SPDM_ERROR);
+     323                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     324                 :            :                      SPDM_ERROR_CODE_REQUEST_RESYNCH);
+     325                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     326                 :          1 :     assert_int_equal(spdm_context->response_state,
+     327                 :            :                      LIBSPDM_RESPONSE_STATE_NEED_RESYNC);
+     328                 :          1 :     free(data1);
+     329                 :          1 : }
+     330                 :            : 
+     331                 :            : #if LIBSPDM_RESPOND_IF_READY_SUPPORT
+     332                 :          1 : void libspdm_test_responder_end_session_case5(void **state)
+     333                 :            : {
+     334                 :            :     libspdm_return_t status;
+     335                 :            :     libspdm_test_context_t *spdm_test_context;
+     336                 :            :     libspdm_context_t *spdm_context;
+     337                 :            :     size_t response_size;
+     338                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     339                 :            :     spdm_end_session_response_t *spdm_response;
+     340                 :            :     void *data1;
+     341                 :            :     size_t data_size1;
+     342                 :            :     libspdm_session_info_t *session_info;
+     343                 :            :     uint32_t session_id;
+     344                 :            :     spdm_error_data_response_not_ready_t *error_data;
+     345                 :            : 
+     346                 :          1 :     spdm_test_context = *state;
+     347                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     348                 :          1 :     spdm_test_context->case_id = 0x5;
+     349                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     350                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     351                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NOT_READY;
+     352                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     353                 :          1 :     spdm_context->connection_info.capability.flags |=
+     354                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     355                 :          1 :     spdm_context->local_context.capability.flags |=
+     356                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     357                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     358                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     359                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+     360                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     361                 :            :         m_libspdm_use_measurement_hash_algo;
+     362                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+     363                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+     364                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     365                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     366                 :            :                                                     &data_size1, NULL, NULL);
+     367                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     368                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
+     369                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+     370                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size = data_size1;
+     371                 :            : 
+     372                 :          1 :     libspdm_reset_message_a(spdm_context);
+     373                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     374                 :            : 
+     375                 :          1 :     session_id = 0xFFFFFFFF;
+     376                 :          1 :     spdm_context->latest_session_id = session_id;
+     377                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+     378                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+     379                 :          1 :     session_info = &spdm_context->session_info[0];
+     380                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+     381                 :          1 :     libspdm_secured_message_set_session_state(
+     382                 :            :         session_info->secured_message_context,
+     383                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+     384                 :            : 
+     385                 :          1 :     response_size = sizeof(response);
+     386                 :          1 :     status = libspdm_get_response_end_session(spdm_context,
+     387                 :            :                                               m_libspdm_end_session_request1_size,
+     388                 :            :                                               &m_libspdm_end_session_request1,
+     389                 :            :                                               &response_size, response);
+     390                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     391                 :          1 :     assert_int_equal(response_size,
+     392                 :            :                      sizeof(spdm_error_response_t) +
+     393                 :            :                      sizeof(spdm_error_data_response_not_ready_t));
+     394                 :          1 :     spdm_response = (void *)response;
+     395                 :          1 :     error_data = (spdm_error_data_response_not_ready_t *)(spdm_response + 1);
+     396                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
+     397                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_RESPONSE_NOT_READY);
+     398                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     399                 :          1 :     assert_int_equal(spdm_context->response_state, LIBSPDM_RESPONSE_STATE_NOT_READY);
+     400                 :          1 :     assert_int_equal(error_data->request_code, SPDM_END_SESSION);
+     401                 :          1 :     free(data1);
+     402                 :          1 : }
+     403                 :            : #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
+     404                 :            : 
+     405                 :          1 : void libspdm_test_responder_end_session_case6(void **state)
+     406                 :            : {
+     407                 :            :     libspdm_return_t status;
+     408                 :            :     libspdm_test_context_t *spdm_test_context;
+     409                 :            :     libspdm_context_t *spdm_context;
+     410                 :            :     size_t response_size;
+     411                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     412                 :            :     spdm_end_session_response_t *spdm_response;
+     413                 :            :     void *data1;
+     414                 :            :     size_t data_size1;
+     415                 :            :     libspdm_session_info_t *session_info;
+     416                 :            :     uint32_t session_id;
+     417                 :            : 
+     418                 :          1 :     spdm_test_context = *state;
+     419                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     420                 :          1 :     spdm_test_context->case_id = 0x6;
+     421                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     422                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     423                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+     424                 :          1 :     spdm_context->connection_info.connection_state =
+     425                 :            :         LIBSPDM_CONNECTION_STATE_NOT_STARTED;
+     426                 :          1 :     spdm_context->connection_info.capability.flags |=
+     427                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     428                 :          1 :     spdm_context->local_context.capability.flags |=
+     429                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     430                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     431                 :            :         m_libspdm_use_hash_algo;
+     432                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     433                 :            :         m_libspdm_use_asym_algo;
+     434                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     435                 :            :         m_libspdm_use_measurement_spec;
+     436                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     437                 :            :         m_libspdm_use_measurement_hash_algo;
+     438                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     439                 :            :         m_libspdm_use_dhe_algo;
+     440                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     441                 :            :         m_libspdm_use_aead_algo;
+     442                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     443                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     444                 :            :                                                     &data_size1, NULL, NULL);
+     445                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     446                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     447                 :            :         data_size1;
+     448                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+     449                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+     450                 :            :         data_size1;
+     451                 :            : 
+     452                 :          1 :     libspdm_reset_message_a(spdm_context);
+     453                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     454                 :            : 
+     455                 :          1 :     session_id = 0xFFFFFFFF;
+     456                 :          1 :     spdm_context->latest_session_id = session_id;
+     457                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+     458                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+     459                 :          1 :     session_info = &spdm_context->session_info[0];
+     460                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+     461                 :          1 :     libspdm_secured_message_set_session_state(
+     462                 :            :         session_info->secured_message_context,
+     463                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+     464                 :            : 
+     465                 :          1 :     response_size = sizeof(response);
+     466                 :          1 :     status = libspdm_get_response_end_session(spdm_context,
+     467                 :            :                                               m_libspdm_end_session_request1_size,
+     468                 :            :                                               &m_libspdm_end_session_request1,
+     469                 :            :                                               &response_size, response);
+     470                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     471                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     472                 :          1 :     spdm_response = (void *)response;
+     473                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     474                 :            :                      SPDM_ERROR);
+     475                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     476                 :            :                      SPDM_ERROR_CODE_UNEXPECTED_REQUEST);
+     477                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     478                 :          1 :     free(data1);
+     479                 :          1 : }
+     480                 :            : 
+     481                 :          1 : void libspdm_test_responder_end_session_case7(void **state)
+     482                 :            : {
+     483                 :            :     libspdm_return_t status;
+     484                 :            :     libspdm_test_context_t *spdm_test_context;
+     485                 :            :     libspdm_context_t *spdm_context;
+     486                 :            :     size_t response_size;
+     487                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     488                 :            :     spdm_end_session_response_t *spdm_response;
+     489                 :            :     void *data1;
+     490                 :            :     size_t data_size1;
+     491                 :            :     libspdm_session_info_t *session_info;
+     492                 :            :     uint32_t session_id;
+     493                 :            : 
+     494                 :          1 :     spdm_test_context = *state;
+     495                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     496                 :          1 :     spdm_test_context->case_id = 0x7;
+     497                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     498                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     499                 :          1 :     spdm_context->connection_info.connection_state =
+     500                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     501                 :          1 :     spdm_context->connection_info.capability.flags |=
+     502                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     503                 :          1 :     spdm_context->local_context.capability.flags |=
+     504                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     505                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     506                 :            :         m_libspdm_use_hash_algo;
+     507                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     508                 :            :         m_libspdm_use_asym_algo;
+     509                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     510                 :            :         m_libspdm_use_measurement_spec;
+     511                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     512                 :            :         m_libspdm_use_measurement_hash_algo;
+     513                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     514                 :            :         m_libspdm_use_dhe_algo;
+     515                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     516                 :            :         m_libspdm_use_aead_algo;
+     517                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     518                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     519                 :            :                                                     &data_size1, NULL, NULL);
+     520                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     521                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     522                 :            :         data_size1;
+     523                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+     524                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+     525                 :            :         data_size1;
+     526                 :            : 
+     527                 :          1 :     libspdm_reset_message_a(spdm_context);
+     528                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     529                 :            : 
+     530                 :          1 :     session_id = 0xFFFFFFFF;
+     531                 :          1 :     spdm_context->latest_session_id = session_id;
+     532                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+     533                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+     534                 :          1 :     session_info = &spdm_context->session_info[0];
+     535                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+     536                 :          1 :     libspdm_secured_message_set_session_state(
+     537                 :            :         session_info->secured_message_context,
+     538                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+     539                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     540                 :            :     session_info->session_transcript.message_m.buffer_size =
+     541                 :            :         session_info->session_transcript.message_m.max_buffer_size;
+     542                 :            :     spdm_context->transcript.message_b.buffer_size =
+     543                 :            :         spdm_context->transcript.message_b.max_buffer_size;
+     544                 :            :     spdm_context->transcript.message_c.buffer_size =
+     545                 :            :         spdm_context->transcript.message_c.max_buffer_size;
+     546                 :            :     spdm_context->transcript.message_mut_b.buffer_size =
+     547                 :            :         spdm_context->transcript.message_mut_b.max_buffer_size;
+     548                 :            :     spdm_context->transcript.message_mut_c.buffer_size =
+     549                 :            :         spdm_context->transcript.message_mut_c.max_buffer_size;
+     550                 :            : #endif
+     551                 :            : 
+     552                 :          1 :     response_size = sizeof(response);
+     553                 :          1 :     status = libspdm_get_response_end_session(spdm_context,
+     554                 :            :                                               m_libspdm_end_session_request1_size,
+     555                 :            :                                               &m_libspdm_end_session_request1,
+     556                 :            :                                               &response_size, response);
+     557                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     558                 :          1 :     assert_int_equal(response_size, sizeof(spdm_end_session_response_t));
+     559                 :          1 :     spdm_response = (void *)response;
+     560                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     561                 :            :                      SPDM_END_SESSION_ACK);
+     562                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     563                 :            :     assert_int_equal(session_info->session_transcript.message_m.buffer_size, 0);
+     564                 :            :     assert_int_equal(spdm_context->transcript.message_b.buffer_size, 0);
+     565                 :            :     assert_int_equal(spdm_context->transcript.message_c.buffer_size, 0);
+     566                 :            :     assert_int_equal(spdm_context->transcript.message_mut_b.buffer_size, 0);
+     567                 :            :     assert_int_equal(spdm_context->transcript.message_mut_c.buffer_size, 0);
+     568                 :            : #endif
+     569                 :            : 
+     570                 :          1 :     free(data1);
+     571                 :          1 : }
+     572                 :            : 
+     573                 :          1 : void libspdm_test_responder_end_session_case8(void **state)
+     574                 :            : {
+     575                 :            :     libspdm_return_t status;
+     576                 :            :     libspdm_test_context_t *spdm_test_context;
+     577                 :            :     libspdm_context_t *spdm_context;
+     578                 :            :     size_t response_size;
+     579                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     580                 :            :     spdm_end_session_response_t *spdm_response;
+     581                 :            :     void *data1;
+     582                 :            :     size_t data_size1;
+     583                 :            :     libspdm_session_info_t *session_info;
+     584                 :            :     uint32_t session_id;
+     585                 :            : 
+     586                 :          1 :     spdm_test_context = *state;
+     587                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     588                 :          1 :     spdm_test_context->case_id = 0x1;
+     589                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     590                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     591                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     592                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     593                 :          1 :     spdm_context->local_context.capability.flags |=
+     594                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     595                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     596                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     597                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+     598                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     599                 :            :         m_libspdm_use_measurement_hash_algo;
+     600                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+     601                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+     602                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     603                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     604                 :            :                                                     &data_size1, NULL, NULL);
+     605                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     606                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
+     607                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+     608                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size = data_size1;
+     609                 :            : 
+     610                 :          1 :     libspdm_reset_message_a(spdm_context);
+     611                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     612                 :            : 
+     613                 :          1 :     session_id = 0xFFFFFFFF;
+     614                 :          1 :     spdm_context->latest_session_id = session_id;
+     615                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+     616                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+     617                 :          1 :     session_info = &spdm_context->session_info[0];
+     618                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+     619                 :          1 :     libspdm_secured_message_set_session_state(
+     620                 :            :         session_info->secured_message_context,
+     621                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+     622                 :            : 
+     623                 :          1 :     response_size = sizeof(response);
+     624                 :          1 :     status = libspdm_get_response_end_session(spdm_context,
+     625                 :            :                                               m_libspdm_end_session_request3_size,
+     626                 :            :                                               &m_libspdm_end_session_request3,
+     627                 :            :                                               &response_size, response);
+     628                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     629                 :          1 :     assert_int_equal(response_size, sizeof(spdm_end_session_response_t));
+     630                 :          1 :     spdm_response = (void *)response;
+     631                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_END_SESSION_ACK);
+     632                 :          1 :     assert_int_not_equal(spdm_context->connection_info.end_session_attributes &
+     633                 :            :                          SPDM_END_SESSION_REQUEST_ATTRIBUTES_PRESERVE_NEGOTIATED_STATE_CLEAR, 0);
+     634                 :          1 :     free(data1);
+     635                 :          1 : }
+     636                 :            : 
+     637                 :            : libspdm_test_context_t m_libspdm_responder_end_session_test_context = {
+     638                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+     639                 :            :     false,
+     640                 :            : };
+     641                 :            : 
+     642                 :          1 : int libspdm_responder_end_session_test_main(void)
+     643                 :            : {
+     644                 :          1 :     const struct CMUnitTest spdm_responder_end_session_tests[] = {
+     645                 :            :         /* Success Case*/
+     646                 :            :         cmocka_unit_test(libspdm_test_responder_end_session_case1),
+     647                 :            :         /* Bad request size*/
+     648                 :            :         cmocka_unit_test(libspdm_test_responder_end_session_case2),
+     649                 :            :         /* response_state: SPDM_RESPONSE_STATE_BUSY*/
+     650                 :            :         cmocka_unit_test(libspdm_test_responder_end_session_case3),
+     651                 :            :         /* response_state: LIBSPDM_RESPONSE_STATE_NEED_RESYNC*/
+     652                 :            :         cmocka_unit_test(libspdm_test_responder_end_session_case4),
+     653                 :            :         #if LIBSPDM_RESPOND_IF_READY_SUPPORT
+     654                 :            :         /* response_state: LIBSPDM_RESPONSE_STATE_NOT_READY*/
+     655                 :            :         cmocka_unit_test(libspdm_test_responder_end_session_case5),
+     656                 :            :         #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
+     657                 :            :         /* connection_state Check*/
+     658                 :            :         cmocka_unit_test(libspdm_test_responder_end_session_case6),
+     659                 :            :         /* Buffer reset*/
+     660                 :            :         cmocka_unit_test(libspdm_test_responder_end_session_case7),
+     661                 :            :         /* Success Case with end_session_attribute set */
+     662                 :            :         cmocka_unit_test(libspdm_test_responder_end_session_case8),
+     663                 :            :     };
+     664                 :            : 
+     665                 :          1 :     libspdm_setup_test_context(&m_libspdm_responder_end_session_test_context);
+     666                 :            : 
+     667                 :          1 :     return cmocka_run_group_tests(spdm_responder_end_session_tests,
+     668                 :            :                                   libspdm_unit_test_group_setup,
+     669                 :            :                                   libspdm_unit_test_group_teardown);
+     670                 :            : }
+     671                 :            : 
+     672                 :            : #endif /* (LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP) || (LIBSPDM_ENABLE_CAPABILITY_PSK_CAP) */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/error_test/index-sort-b.html b/coverage_log/unit_test/test_spdm_responder/error_test/index-sort-b.html new file mode 100644 index 00000000000..eac88219174 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/error_test/index-sort-b.html @@ -0,0 +1,131 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/error_test + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder/error_testHitTotalCoverage
Test:coverage.infoLines:15316294.4 %
Date:2024-09-22 08:21:07Functions:91090.0 %
Branches:040.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
vendor_response_err.c +
79.5%79.5%
+
79.5 %35 / 4466.7 %2 / 30.0 %0 / 4
supported_event_types_err.c +
100.0%
+
100.0 %49 / 49100.0 %3 / 3-0 / 0
subscribe_event_types_ack_err.c +
100.0%
+
100.0 %69 / 69100.0 %4 / 4-0 / 0
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/error_test/index-sort-f.html b/coverage_log/unit_test/test_spdm_responder/error_test/index-sort-f.html new file mode 100644 index 00000000000..94e00a83a64 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/error_test/index-sort-f.html @@ -0,0 +1,131 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/error_test + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder/error_testHitTotalCoverage
Test:coverage.infoLines:15316294.4 %
Date:2024-09-22 08:21:07Functions:91090.0 %
Branches:040.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
vendor_response_err.c +
79.5%79.5%
+
79.5 %35 / 4466.7 %2 / 30.0 %0 / 4
supported_event_types_err.c +
100.0%
+
100.0 %49 / 49100.0 %3 / 3-0 / 0
subscribe_event_types_ack_err.c +
100.0%
+
100.0 %69 / 69100.0 %4 / 4-0 / 0
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/error_test/index-sort-l.html b/coverage_log/unit_test/test_spdm_responder/error_test/index-sort-l.html new file mode 100644 index 00000000000..515bac15806 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/error_test/index-sort-l.html @@ -0,0 +1,131 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/error_test + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder/error_testHitTotalCoverage
Test:coverage.infoLines:15316294.4 %
Date:2024-09-22 08:21:07Functions:91090.0 %
Branches:040.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
vendor_response_err.c +
79.5%79.5%
+
79.5 %35 / 4466.7 %2 / 30.0 %0 / 4
supported_event_types_err.c +
100.0%
+
100.0 %49 / 49100.0 %3 / 3-0 / 0
subscribe_event_types_ack_err.c +
100.0%
+
100.0 %69 / 69100.0 %4 / 4-0 / 0
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/error_test/index.html b/coverage_log/unit_test/test_spdm_responder/error_test/index.html new file mode 100644 index 00000000000..8435c50b2e8 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/error_test/index.html @@ -0,0 +1,131 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/error_test + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder/error_testHitTotalCoverage
Test:coverage.infoLines:15316294.4 %
Date:2024-09-22 08:21:07Functions:91090.0 %
Branches:040.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
subscribe_event_types_ack_err.c +
100.0%
+
100.0 %69 / 69100.0 %4 / 4-0 / 0
supported_event_types_err.c +
100.0%
+
100.0 %49 / 49100.0 %3 / 3-0 / 0
vendor_response_err.c +
79.5%79.5%
+
79.5 %35 / 4466.7 %2 / 30.0 %0 / 4
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/error_test/subscribe_event_types_ack_err.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_responder/error_test/subscribe_event_types_ack_err.c.func-sort-c.html new file mode 100644 index 00000000000..3fdaa3ca268 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/error_test/subscribe_event_types_ack_err.c.func-sort-c.html @@ -0,0 +1,97 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/error_test/subscribe_event_types_ack_err.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder/error_test - subscribe_event_types_ack_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:6969100.0 %
Date:2024-09-22 08:21:07Functions:44100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_subscribe_event_types_ack_error_test_main1
libspdm_test_responder_subscribe_event_types_ack_err_case11
libspdm_test_responder_subscribe_event_types_ack_err_case21
set_standard_state2
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/error_test/subscribe_event_types_ack_err.c.func.html b/coverage_log/unit_test/test_spdm_responder/error_test/subscribe_event_types_ack_err.c.func.html new file mode 100644 index 00000000000..c72086fb83d --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/error_test/subscribe_event_types_ack_err.c.func.html @@ -0,0 +1,97 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/error_test/subscribe_event_types_ack_err.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder/error_test - subscribe_event_types_ack_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:6969100.0 %
Date:2024-09-22 08:21:07Functions:44100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_subscribe_event_types_ack_error_test_main1
libspdm_test_responder_subscribe_event_types_ack_err_case11
libspdm_test_responder_subscribe_event_types_ack_err_case21
set_standard_state2
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/error_test/subscribe_event_types_ack_err.c.gcov.html b/coverage_log/unit_test/test_spdm_responder/error_test/subscribe_event_types_ack_err.c.gcov.html new file mode 100644 index 00000000000..b2405dedbc5 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/error_test/subscribe_event_types_ack_err.c.gcov.html @@ -0,0 +1,246 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/error_test/subscribe_event_types_ack_err.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder/error_test - subscribe_event_types_ack_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:6969100.0 %
Date:2024-09-22 08:21:07Functions:44100.0 %
Branches:00-
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2024 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_responder_lib.h"
+       9                 :            : 
+      10                 :            : #if LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP
+      11                 :            : 
+      12                 :          2 : static void set_standard_state(libspdm_context_t *spdm_context)
+      13                 :            : {
+      14                 :            :     libspdm_session_info_t *session_info;
+      15                 :            :     uint32_t session_id;
+      16                 :            : 
+      17                 :          2 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+      18                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+      19                 :          2 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+      20                 :          2 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+      21                 :            : 
+      22                 :          2 :     spdm_context->connection_info.capability.flags |=
+      23                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EVENT_CAP;
+      24                 :          2 :     spdm_context->connection_info.capability.flags |=
+      25                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+      26                 :          2 :     spdm_context->connection_info.capability.flags |=
+      27                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+      28                 :          2 :     spdm_context->connection_info.capability.flags |=
+      29                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+      30                 :            : 
+      31                 :          2 :     spdm_context->local_context.capability.flags |=
+      32                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+      33                 :          2 :     spdm_context->local_context.capability.flags |=
+      34                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+      35                 :          2 :     spdm_context->local_context.capability.flags |=
+      36                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+      37                 :          2 :     spdm_context->local_context.capability.flags |=
+      38                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EVENT_CAP;
+      39                 :            : 
+      40                 :          2 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+      41                 :          2 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+      42                 :          2 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+      43                 :          2 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+      44                 :            : 
+      45                 :          2 :     session_id = 0xFFFFFFFF;
+      46                 :          2 :     spdm_context->latest_session_id = session_id;
+      47                 :          2 :     spdm_context->last_spdm_request_session_id_valid = true;
+      48                 :          2 :     spdm_context->last_spdm_request_session_id = session_id;
+      49                 :          2 :     session_info = &spdm_context->session_info[0];
+      50                 :          2 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+      51                 :          2 :     libspdm_secured_message_set_session_state(
+      52                 :            :         session_info->secured_message_context,
+      53                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+      54                 :          2 : }
+      55                 :            : 
+      56                 :            : /**
+      57                 :            :  * Test 1: Responder does not support event mechanism.
+      58                 :            :  * Expected Behavior: Returns SPDM_ERROR_CODE_UNSUPPORTED_REQUEST.
+      59                 :            :  **/
+      60                 :          1 : static void libspdm_test_responder_subscribe_event_types_ack_err_case1(void **state)
+      61                 :            : {
+      62                 :            :     libspdm_return_t status;
+      63                 :            :     libspdm_test_context_t *spdm_test_context;
+      64                 :            :     libspdm_context_t *spdm_context;
+      65                 :            :     spdm_subscribe_event_types_request_t spdm_request;
+      66                 :            :     size_t spdm_request_size;
+      67                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+      68                 :          1 :     size_t response_size = sizeof(response);
+      69                 :            :     spdm_subscribe_event_types_ack_response_t *spdm_response;
+      70                 :            : 
+      71                 :          1 :     spdm_test_context = *state;
+      72                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+      73                 :          1 :     spdm_test_context->case_id = 1;
+      74                 :            : 
+      75                 :          1 :     set_standard_state(spdm_context);
+      76                 :            : 
+      77                 :            :     /* Responder does not support event mechanism. */
+      78                 :          1 :     spdm_context->local_context.capability.flags &= ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EVENT_CAP;
+      79                 :            : 
+      80                 :          1 :     spdm_request.header.spdm_version = SPDM_MESSAGE_VERSION_13;
+      81                 :          1 :     spdm_request.header.request_response_code = SPDM_SUBSCRIBE_EVENT_TYPES;
+      82                 :          1 :     spdm_request.header.param1 = 0;
+      83                 :          1 :     spdm_request.header.param2 = 0;
+      84                 :            : 
+      85                 :          1 :     spdm_request_size = sizeof(spdm_message_header_t);
+      86                 :            : 
+      87                 :          1 :     status = libspdm_get_response_subscribe_event_types_ack(spdm_context,
+      88                 :            :                                                             spdm_request_size, &spdm_request,
+      89                 :            :                                                             &response_size, response);
+      90                 :          1 :     spdm_response = (spdm_subscribe_event_types_ack_response_t *)response;
+      91                 :            : 
+      92                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+      93                 :          1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_13);
+      94                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
+      95                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST);
+      96                 :          1 :     assert_int_equal(spdm_response->header.param2, SPDM_SUBSCRIBE_EVENT_TYPES);
+      97                 :          1 : }
+      98                 :            : 
+      99                 :            : /**
+     100                 :            :  * Test 2: Negotiated version is less than 1.3.
+     101                 :            :  * Expected Behavior: Returns SPDM_ERROR_CODE_UNSUPPORTED_REQUEST.
+     102                 :            :  **/
+     103                 :          1 : static void libspdm_test_responder_subscribe_event_types_ack_err_case2(void **state)
+     104                 :            : {
+     105                 :            :     libspdm_return_t status;
+     106                 :            :     libspdm_test_context_t *spdm_test_context;
+     107                 :            :     libspdm_context_t *spdm_context;
+     108                 :            :     spdm_subscribe_event_types_request_t spdm_request;
+     109                 :            :     size_t spdm_request_size;
+     110                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     111                 :          1 :     size_t response_size = sizeof(response);
+     112                 :            :     spdm_subscribe_event_types_ack_response_t *spdm_response;
+     113                 :            : 
+     114                 :          1 :     spdm_test_context = *state;
+     115                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     116                 :          1 :     spdm_test_context->case_id = 1;
+     117                 :            : 
+     118                 :          1 :     set_standard_state(spdm_context);
+     119                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     120                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     121                 :            : 
+     122                 :            :     /* Unsupported version for subscribe event types. */
+     123                 :          1 :     spdm_request.header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     124                 :          1 :     spdm_request.header.request_response_code = SPDM_SUBSCRIBE_EVENT_TYPES;
+     125                 :          1 :     spdm_request.header.param1 = 0;
+     126                 :          1 :     spdm_request.header.param2 = 0;
+     127                 :            : 
+     128                 :          1 :     spdm_request_size = sizeof(spdm_message_header_t);
+     129                 :            : 
+     130                 :          1 :     status = libspdm_get_response_subscribe_event_types_ack(spdm_context,
+     131                 :            :                                                             spdm_request_size, &spdm_request,
+     132                 :            :                                                             &response_size, response);
+     133                 :          1 :     spdm_response = (spdm_subscribe_event_types_ack_response_t *)response;
+     134                 :            : 
+     135                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     136                 :          1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+     137                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
+     138                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST);
+     139                 :          1 :     assert_int_equal(spdm_response->header.param2, SPDM_SUBSCRIBE_EVENT_TYPES);
+     140                 :          1 : }
+     141                 :            : 
+     142                 :          1 : int libspdm_responder_subscribe_event_types_ack_error_test_main(void)
+     143                 :            : {
+     144                 :          1 :     libspdm_test_context_t m_test_context = {
+     145                 :            :         LIBSPDM_TEST_CONTEXT_VERSION,
+     146                 :            :         false,
+     147                 :            :     };
+     148                 :            : 
+     149                 :          1 :     const struct CMUnitTest spdm_responder_supported_event_types_err_tests[] = {
+     150                 :            :         cmocka_unit_test(libspdm_test_responder_subscribe_event_types_ack_err_case1),
+     151                 :            :         cmocka_unit_test(libspdm_test_responder_subscribe_event_types_ack_err_case2)
+     152                 :            :     };
+     153                 :            : 
+     154                 :          1 :     libspdm_setup_test_context(&m_test_context);
+     155                 :            : 
+     156                 :          1 :     return cmocka_run_group_tests(spdm_responder_supported_event_types_err_tests,
+     157                 :            :                                   libspdm_unit_test_group_setup,
+     158                 :            :                                   libspdm_unit_test_group_teardown);
+     159                 :            : }
+     160                 :            : 
+     161                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/error_test/supported_event_types_err.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_responder/error_test/supported_event_types_err.c.func-sort-c.html new file mode 100644 index 00000000000..a547e97214e --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/error_test/supported_event_types_err.c.func-sort-c.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/error_test/supported_event_types_err.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder/error_test - supported_event_types_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:4949100.0 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_supported_event_types_error_test_main1
libspdm_test_responder_supported_event_types_err_case11
set_standard_state1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/error_test/supported_event_types_err.c.func.html b/coverage_log/unit_test/test_spdm_responder/error_test/supported_event_types_err.c.func.html new file mode 100644 index 00000000000..8abebac4019 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/error_test/supported_event_types_err.c.func.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/error_test/supported_event_types_err.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder/error_test - supported_event_types_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:4949100.0 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_supported_event_types_error_test_main1
libspdm_test_responder_supported_event_types_err_case11
set_standard_state1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/error_test/supported_event_types_err.c.gcov.html b/coverage_log/unit_test/test_spdm_responder/error_test/supported_event_types_err.c.gcov.html new file mode 100644 index 00000000000..e0aaa7d2cbe --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/error_test/supported_event_types_err.c.gcov.html @@ -0,0 +1,200 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/error_test/supported_event_types_err.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder/error_test - supported_event_types_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:4949100.0 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:00-
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2024 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_responder_lib.h"
+       9                 :            : 
+      10                 :            : #if LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP
+      11                 :            : 
+      12                 :          1 : static void set_standard_state(libspdm_context_t *spdm_context)
+      13                 :            : {
+      14                 :            :     libspdm_session_info_t *session_info;
+      15                 :            :     uint32_t session_id;
+      16                 :            : 
+      17                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+      18                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+      19                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+      20                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+      21                 :            : 
+      22                 :          1 :     spdm_context->connection_info.capability.flags |=
+      23                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EVENT_CAP;
+      24                 :          1 :     spdm_context->connection_info.capability.flags |=
+      25                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+      26                 :          1 :     spdm_context->connection_info.capability.flags |=
+      27                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+      28                 :          1 :     spdm_context->connection_info.capability.flags |=
+      29                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+      30                 :            : 
+      31                 :          1 :     spdm_context->local_context.capability.flags |=
+      32                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+      33                 :          1 :     spdm_context->local_context.capability.flags |=
+      34                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+      35                 :          1 :     spdm_context->local_context.capability.flags |=
+      36                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+      37                 :          1 :     spdm_context->local_context.capability.flags |=
+      38                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EVENT_CAP;
+      39                 :            : 
+      40                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+      41                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+      42                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+      43                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+      44                 :            : 
+      45                 :          1 :     session_id = 0xFFFFFFFF;
+      46                 :          1 :     spdm_context->latest_session_id = session_id;
+      47                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+      48                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+      49                 :          1 :     session_info = &spdm_context->session_info[0];
+      50                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+      51                 :          1 :     libspdm_secured_message_set_session_state(
+      52                 :            :         session_info->secured_message_context,
+      53                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+      54                 :          1 : }
+      55                 :            : 
+      56                 :            : /**
+      57                 :            :  * Test 1: Responder has not set EVENT_CAP.
+      58                 :            :  * Expected Behavior: Responder returns SPDM_ERROR_CODE_UNSUPPORTED_REQUEST.
+      59                 :            :  **/
+      60                 :          1 : static void libspdm_test_responder_supported_event_types_err_case1(void **state)
+      61                 :            : {
+      62                 :            :     libspdm_return_t status;
+      63                 :            :     libspdm_test_context_t *spdm_test_context;
+      64                 :            :     libspdm_context_t *spdm_context;
+      65                 :            :     spdm_get_supported_event_types_request_t spdm_request;
+      66                 :          1 :     size_t spdm_request_size = sizeof(spdm_request);
+      67                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+      68                 :          1 :     size_t response_size = sizeof(response);
+      69                 :            :     spdm_error_response_t *spdm_response;
+      70                 :            : 
+      71                 :          1 :     spdm_test_context = *state;
+      72                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+      73                 :          1 :     spdm_test_context->case_id = 1;
+      74                 :            : 
+      75                 :          1 :     set_standard_state(spdm_context);
+      76                 :            : 
+      77                 :            :     /* Responder is not an event notifier. */
+      78                 :          1 :     spdm_context->local_context.capability.flags &= ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EVENT_CAP;
+      79                 :            : 
+      80                 :          1 :     spdm_request.header.spdm_version = SPDM_MESSAGE_VERSION_13;
+      81                 :          1 :     spdm_request.header.request_response_code = SPDM_GET_SUPPORTED_EVENT_TYPES;
+      82                 :          1 :     spdm_request.header.param1 = 0;
+      83                 :          1 :     spdm_request.header.param2 = 0;
+      84                 :            : 
+      85                 :          1 :     status = libspdm_get_response_supported_event_types(spdm_context,
+      86                 :            :                                                         spdm_request_size, &spdm_request,
+      87                 :            :                                                         &response_size, response);
+      88                 :          1 :     spdm_response = (spdm_error_response_t *)response;
+      89                 :            : 
+      90                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+      91                 :          1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_13);
+      92                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
+      93                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST);
+      94                 :          1 :     assert_int_equal(spdm_response->header.param2, SPDM_GET_SUPPORTED_EVENT_TYPES);
+      95                 :          1 : }
+      96                 :            : 
+      97                 :          1 : int libspdm_responder_supported_event_types_error_test_main(void)
+      98                 :            : {
+      99                 :          1 :     libspdm_test_context_t m_test_context = {
+     100                 :            :         LIBSPDM_TEST_CONTEXT_VERSION,
+     101                 :            :         false,
+     102                 :            :     };
+     103                 :            : 
+     104                 :          1 :     const struct CMUnitTest spdm_responder_supported_event_types_err_tests[] = {
+     105                 :            :         cmocka_unit_test(libspdm_test_responder_supported_event_types_err_case1),
+     106                 :            :     };
+     107                 :            : 
+     108                 :          1 :     libspdm_setup_test_context(&m_test_context);
+     109                 :            : 
+     110                 :          1 :     return cmocka_run_group_tests(spdm_responder_supported_event_types_err_tests,
+     111                 :            :                                   libspdm_unit_test_group_setup,
+     112                 :            :                                   libspdm_unit_test_group_teardown);
+     113                 :            : }
+     114                 :            : 
+     115                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/error_test/vendor_response_err.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_responder/error_test/vendor_response_err.c.func-sort-c.html new file mode 100644 index 00000000000..fb2bc4453be --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/error_test/vendor_response_err.c.func-sort-c.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/error_test/vendor_response_err.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder/error_test - vendor_response_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:354479.5 %
Date:2024-09-22 08:21:07Functions:2366.7 %
Branches:040.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_vendor_response_func_err_test0
libspdm_responder_vendor_cmds_error_test_main1
libspdm_test_responder_vendor_cmds_err_case11
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/error_test/vendor_response_err.c.func.html b/coverage_log/unit_test/test_spdm_responder/error_test/vendor_response_err.c.func.html new file mode 100644 index 00000000000..e6aafa384cf --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/error_test/vendor_response_err.c.func.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/error_test/vendor_response_err.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder/error_test - vendor_response_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:354479.5 %
Date:2024-09-22 08:21:07Functions:2366.7 %
Branches:040.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_vendor_cmds_error_test_main1
libspdm_test_responder_vendor_cmds_err_case11
libspdm_vendor_response_func_err_test0
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/error_test/vendor_response_err.c.gcov.html b/coverage_log/unit_test/test_spdm_responder/error_test/vendor_response_err.c.gcov.html new file mode 100644 index 00000000000..bd753c37c9d --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/error_test/vendor_response_err.c.gcov.html @@ -0,0 +1,226 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/error_test/vendor_response_err.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder/error_test - vendor_response_err.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:354479.5 %
Date:2024-09-22 08:21:07Functions:2366.7 %
Branches:040.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2023-2024 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                 :            : 
+       8                 :            : #include "spdm_unit_test.h"
+       9                 :            : #include "internal/libspdm_requester_lib.h"
+      10                 :            : #include "internal/libspdm_responder_lib.h"
+      11                 :            : 
+      12                 :            : #if LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES
+      13                 :            : 
+      14                 :            : #pragma pack(1)
+      15                 :            : typedef struct {
+      16                 :            :     spdm_message_header_t header;
+      17                 :            :     uint16_t standard_id;
+      18                 :            :     uint8_t vendor_id_len;
+      19                 :            :     uint8_t vendor_id[SPDM_MAX_VENDOR_ID_LENGTH];
+      20                 :            :     uint16_t data_len;
+      21                 :            :     uint8_t data[16];
+      22                 :            : } libspdm_vendor_request_test;
+      23                 :            : 
+      24                 :            : typedef struct {
+      25                 :            :     spdm_message_header_t header;
+      26                 :            :     uint16_t standard_id;
+      27                 :            :     uint8_t vendor_id_len;
+      28                 :            :     uint8_t vendor_id[SPDM_MAX_VENDOR_ID_LENGTH];
+      29                 :            :     uint16_t data_len;
+      30                 :            :     uint8_t data[64];
+      31                 :            : } libspdm_vendor_response_test;
+      32                 :            : #pragma pack()
+      33                 :            : 
+      34                 :          0 : libspdm_return_t libspdm_vendor_response_func_err_test(
+      35                 :            :     void *spdm_context,
+      36                 :            :     uint16_t req_standard_id,
+      37                 :            :     uint8_t req_vendor_id_len,
+      38                 :            :     const void *req_vendor_id,
+      39                 :            :     uint16_t req_size,
+      40                 :            :     const void *req_data,
+      41                 :            :     uint16_t *resp_size,
+      42                 :            :     void *resp_data)
+      43                 :            : {
+      44                 :            :     libspdm_vendor_response_test test_response;
+      45                 :            :     /* get pointer to response data payload and populate */
+      46                 :          0 :     uint8_t *resp_payload = (uint8_t *)resp_data;
+      47                 :            :     /* get pointer to response length and populate */
+      48                 :          0 :     *resp_size = sizeof(test_response.data);
+      49                 :            :     /* store length of response */
+      50                 :          0 :     libspdm_set_mem(resp_payload, *resp_size, 0xFF);
+      51                 :            : 
+      52   [ #  #  #  # ]:          0 :     if (resp_size == NULL || *resp_size == 0)
+      53                 :          0 :         return LIBSPDM_STATUS_INVALID_PARAMETER;
+      54                 :            : 
+      55                 :            :     /* TBD make an error here, like response len 65000, but different this time. */
+      56                 :            : 
+      57                 :          0 :     printf("Got request 0x%x, sent response 0x%x\n",
+      58                 :          0 :            ((const uint8_t*)req_data)[0], ((uint8_t*)resp_data)[0]);
+      59                 :            : 
+      60                 :          0 :     return LIBSPDM_STATUS_SUCCESS;
+      61                 :            : }
+      62                 :            : 
+      63                 :            : /**
+      64                 :            :  * Test 1: Sending a vendor defined request with one parameter NULL
+      65                 :            :  * Expected behavior: client returns a status of LIBSPDM_STATUS_INVALID_PARAMETER
+      66                 :            :  **/
+      67                 :          1 : static void libspdm_test_responder_vendor_cmds_err_case1(void **state)
+      68                 :            : {
+      69                 :            :     libspdm_return_t status;
+      70                 :            :     libspdm_test_context_t *spdm_test_context;
+      71                 :            :     libspdm_context_t *spdm_context;
+      72                 :          1 :     uint8_t request_buffer[LIBSPDM_MAX_SPDM_MSG_SIZE] = {0};
+      73                 :            :     libspdm_vendor_request_test request;
+      74                 :          1 :     libspdm_vendor_response_test response = {0};
+      75                 :          1 :     response.vendor_id_len = sizeof(response.vendor_id);
+      76                 :          1 :     response.data_len = sizeof(response.data);
+      77                 :          1 :     size_t response_len = 0;
+      78                 :            : 
+      79                 :          1 :     spdm_test_context = *state;
+      80                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+      81                 :          1 :     spdm_test_context->case_id = 0x1;
+      82                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+      83                 :            :         SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256;
+      84                 :          1 :     request.header.spdm_version = SPDM_MESSAGE_VERSION_10;
+      85                 :          1 :     spdm_context->connection_info.version = request.header.spdm_version <<
+      86                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+      87                 :          1 :     spdm_context->connection_info.connection_state =
+      88                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+      89                 :          1 :     spdm_context->local_context.is_requester = true;
+      90                 :            : 
+      91                 :          1 :     status = libspdm_register_vendor_callback_func(spdm_context,
+      92                 :            :                                                    libspdm_vendor_response_func_err_test);
+      93                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+      94                 :            : 
+      95                 :          1 :     request.standard_id = 6;
+      96                 :          1 :     request.vendor_id_len = sizeof(request.vendor_id);
+      97                 :          1 :     libspdm_set_mem(request.vendor_id, sizeof(request.vendor_id), 0xAA);
+      98                 :          1 :     request.data_len = sizeof(request.data);
+      99                 :          1 :     libspdm_set_mem(request.data, sizeof(request.data), 0xAA);
+     100                 :            : 
+     101                 :          1 :     response_len = sizeof(response);
+     102                 :            : 
+     103                 :            :     /* copy header of request structure to buffer */
+     104                 :          1 :     libspdm_copy_mem(request_buffer, sizeof(request_buffer), &request,
+     105                 :          1 :                      sizeof(request.header) + 3 + request.vendor_id_len);
+     106                 :            :     /* copy the request data to the correct offset in the request_buffer */
+     107                 :          1 :     libspdm_copy_mem(request_buffer + sizeof(request.header) + 3 + request.vendor_id_len,
+     108                 :          1 :                      request.data_len + 2, &request.data_len, request.data_len + 2);
+     109                 :            : 
+     110                 :            :     /* requires correctly encoded spdm vendor request message */
+     111                 :          1 :     status = libspdm_get_vendor_defined_response(spdm_context, sizeof(request),
+     112                 :            :                                                  request_buffer, &response_len, NULL);
+     113                 :            : 
+     114                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_PARAMETER);
+     115                 :          1 :     assert_int_equal(
+     116                 :            :         spdm_context->connection_info.version >> SPDM_VERSION_NUMBER_SHIFT_BIT,
+     117                 :            :         SPDM_MESSAGE_VERSION_10);
+     118                 :            : 
+     119                 :          1 :     response.data_len = (uint16_t)response_len;
+     120                 :          1 : }
+     121                 :            : 
+     122                 :            : libspdm_test_context_t m_libspdm_responder_vendor_cmds_err_test_context = {
+     123                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+     124                 :            :     true,
+     125                 :            : };
+     126                 :            : 
+     127                 :          1 : int libspdm_responder_vendor_cmds_error_test_main(void)
+     128                 :            : {
+     129                 :          1 :     const struct CMUnitTest spdm_responder_vendor_cmds_tests[] = {
+     130                 :            :         cmocka_unit_test(libspdm_test_responder_vendor_cmds_err_case1),
+     131                 :            :     };
+     132                 :            : 
+     133                 :          1 :     libspdm_setup_test_context(&m_libspdm_responder_vendor_cmds_err_test_context);
+     134                 :            : 
+     135                 :          1 :     return cmocka_run_group_tests(spdm_responder_vendor_cmds_tests,
+     136                 :            :                                   libspdm_unit_test_group_setup,
+     137                 :            :                                   libspdm_unit_test_group_teardown);
+     138                 :            : }
+     139                 :            : 
+     140                 :            : 
+     141                 :            : #endif /* LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/finish.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_responder/finish.c.func-sort-c.html new file mode 100644 index 00000000000..808cd3b0f92 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/finish.c.func-sort-c.html @@ -0,0 +1,205 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/finish.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - finish.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:17331733100.0 %
Date:2024-09-22 08:21:07Functions:3131100.0 %
Branches:1250.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_finish_test_main1
libspdm_test_responder_finish_case11
libspdm_test_responder_finish_case101
libspdm_test_responder_finish_case111
libspdm_test_responder_finish_case121
libspdm_test_responder_finish_case131
libspdm_test_responder_finish_case141
libspdm_test_responder_finish_case151
libspdm_test_responder_finish_case161
libspdm_test_responder_finish_case171
libspdm_test_responder_finish_case181
libspdm_test_responder_finish_case191
libspdm_test_responder_finish_case21
libspdm_test_responder_finish_case201
libspdm_test_responder_finish_case211
libspdm_test_responder_finish_case221
libspdm_test_responder_finish_case231
libspdm_test_responder_finish_case241
libspdm_test_responder_finish_case251
libspdm_test_responder_finish_case261
libspdm_test_responder_finish_case271
libspdm_test_responder_finish_case281
libspdm_test_responder_finish_case291
libspdm_test_responder_finish_case31
libspdm_test_responder_finish_case41
libspdm_test_responder_finish_case51
libspdm_test_responder_finish_case61
libspdm_test_responder_finish_case71
libspdm_test_responder_finish_case81
libspdm_test_responder_finish_case91
libspdm_secured_message_set_request_finished_key27
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/finish.c.func.html b/coverage_log/unit_test/test_spdm_responder/finish.c.func.html new file mode 100644 index 00000000000..dfec568ef54 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/finish.c.func.html @@ -0,0 +1,205 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/finish.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - finish.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:17331733100.0 %
Date:2024-09-22 08:21:07Functions:3131100.0 %
Branches:1250.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_finish_test_main1
libspdm_secured_message_set_request_finished_key27
libspdm_test_responder_finish_case11
libspdm_test_responder_finish_case101
libspdm_test_responder_finish_case111
libspdm_test_responder_finish_case121
libspdm_test_responder_finish_case131
libspdm_test_responder_finish_case141
libspdm_test_responder_finish_case151
libspdm_test_responder_finish_case161
libspdm_test_responder_finish_case171
libspdm_test_responder_finish_case181
libspdm_test_responder_finish_case191
libspdm_test_responder_finish_case21
libspdm_test_responder_finish_case201
libspdm_test_responder_finish_case211
libspdm_test_responder_finish_case221
libspdm_test_responder_finish_case231
libspdm_test_responder_finish_case241
libspdm_test_responder_finish_case251
libspdm_test_responder_finish_case261
libspdm_test_responder_finish_case271
libspdm_test_responder_finish_case281
libspdm_test_responder_finish_case291
libspdm_test_responder_finish_case31
libspdm_test_responder_finish_case41
libspdm_test_responder_finish_case51
libspdm_test_responder_finish_case61
libspdm_test_responder_finish_case71
libspdm_test_responder_finish_case81
libspdm_test_responder_finish_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/finish.c.gcov.html b/coverage_log/unit_test/test_spdm_responder/finish.c.gcov.html new file mode 100644 index 00000000000..afa71d17f52 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/finish.c.gcov.html @@ -0,0 +1,3995 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/finish.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - finish.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:17331733100.0 %
Date:2024-09-22 08:21:07Functions:3131100.0 %
Branches:1250.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_responder_lib.h"
+       9                 :            : #include "internal/libspdm_secured_message_lib.h"
+      10                 :            : 
+      11                 :            : #pragma pack(1)
+      12                 :            : 
+      13                 :            : typedef struct {
+      14                 :            :     spdm_message_header_t header;
+      15                 :            :     uint8_t signature[LIBSPDM_MAX_ASYM_KEY_SIZE];
+      16                 :            :     uint8_t verify_data[LIBSPDM_MAX_HASH_SIZE];
+      17                 :            : } libspdm_finish_request_mine_t;
+      18                 :            : 
+      19                 :            : #pragma pack()
+      20                 :            : 
+      21                 :            : libspdm_finish_request_mine_t m_libspdm_finish_request1 = {
+      22                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_FINISH, 0, 0 },
+      23                 :            : };
+      24                 :            : size_t m_libspdm_finish_request1_size = sizeof(m_libspdm_finish_request1);
+      25                 :            : 
+      26                 :            : libspdm_finish_request_mine_t m_libspdm_finish_request3 = {
+      27                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_FINISH, 1, 0 },
+      28                 :            : };
+      29                 :            : size_t m_libspdm_finish_request3_size = sizeof(m_libspdm_finish_request3);
+      30                 :            : 
+      31                 :            : libspdm_finish_request_mine_t m_libspdm_finish_request4 = {
+      32                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_FINISH, 1, 0xFF },
+      33                 :            : };
+      34                 :            : size_t m_libspdm_finish_request4_size = sizeof(m_libspdm_finish_request4);
+      35                 :            : 
+      36                 :            : libspdm_finish_request_mine_t m_libspdm_finish_request5 = {
+      37                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_FINISH, 1, 10 },
+      38                 :            : };
+      39                 :            : size_t m_libspdm_finish_request5_size = sizeof(m_libspdm_finish_request5);
+      40                 :            : 
+      41                 :            : libspdm_finish_request_mine_t m_libspdm_finish_request6 = {
+      42                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_FINISH, 6, 10 },
+      43                 :            : };
+      44                 :            : size_t m_libspdm_finish_request6_size = sizeof(m_libspdm_finish_request6);
+      45                 :            : 
+      46                 :            : libspdm_finish_request_mine_t m_libspdm_finish_request7 = {
+      47                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_FINISH, 1, 3 },
+      48                 :            : };
+      49                 :            : size_t m_libspdm_finish_request7_size = sizeof(m_libspdm_finish_request7);
+      50                 :            : 
+      51                 :            : uint8_t m_dummy_buffer[LIBSPDM_MAX_HASH_SIZE];
+      52                 :            : 
+      53                 :            : #if LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP
+      54                 :            : 
+      55                 :            : static libspdm_th_managed_buffer_t th_curr;
+      56                 :            : 
+      57                 :         27 : void libspdm_secured_message_set_request_finished_key(
+      58                 :            :     void *spdm_secured_message_context, const void *key, size_t key_size)
+      59                 :            : {
+      60                 :            :     libspdm_secured_message_context_t *secured_message_context;
+      61                 :            : 
+      62                 :         27 :     secured_message_context = spdm_secured_message_context;
+      63         [ -  + ]:         27 :     LIBSPDM_ASSERT(key_size == secured_message_context->hash_size);
+      64                 :         27 :     libspdm_copy_mem(secured_message_context->handshake_secret.request_finished_key,
+      65                 :            :                      sizeof(secured_message_context->handshake_secret.request_finished_key),
+      66                 :            :                      key, secured_message_context->hash_size);
+      67                 :         27 : }
+      68                 :            : 
+      69                 :            : /**
+      70                 :            :  * Test 1: receiving a correct FINISH message from the requester with a
+      71                 :            :  * correct MAC, no signature (no mutual authentication), and 'handshake in
+      72                 :            :  * the clear'.
+      73                 :            :  * Expected behavior: the responder accepts the request and produces a valid
+      74                 :            :  * FINISH_RSP response message.
+      75                 :            :  **/
+      76                 :          1 : void libspdm_test_responder_finish_case1(void **state)
+      77                 :            : {
+      78                 :            :     libspdm_return_t status;
+      79                 :            :     libspdm_test_context_t *spdm_test_context;
+      80                 :            :     libspdm_context_t *spdm_context;
+      81                 :            :     size_t response_size;
+      82                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+      83                 :            :     spdm_finish_response_t *spdm_response;
+      84                 :            :     void *data1;
+      85                 :            :     size_t data_size1;
+      86                 :            :     uint8_t *ptr;
+      87                 :            :     uint8_t *cert_buffer;
+      88                 :            :     size_t cert_buffer_size;
+      89                 :            :     uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+      90                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+      91                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+      92                 :            :     libspdm_session_info_t *session_info;
+      93                 :            :     uint32_t session_id;
+      94                 :            :     uint32_t hash_size;
+      95                 :            :     uint32_t hmac_size;
+      96                 :            : 
+      97                 :          1 :     spdm_test_context = *state;
+      98                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+      99                 :          1 :     spdm_test_context->case_id = 0x1;
+     100                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     101                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     102                 :          1 :     spdm_context->connection_info.connection_state =
+     103                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     104                 :          1 :     spdm_context->connection_info.capability.flags |=
+     105                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+     106                 :          1 :     spdm_context->local_context.capability.flags |=
+     107                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+     108                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     109                 :            :         m_libspdm_use_hash_algo;
+     110                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     111                 :            :         m_libspdm_use_asym_algo;
+     112                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     113                 :            :         m_libspdm_use_measurement_spec;
+     114                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     115                 :            :         m_libspdm_use_measurement_hash_algo;
+     116                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     117                 :            :         m_libspdm_use_dhe_algo;
+     118                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     119                 :            :         m_libspdm_use_aead_algo;
+     120                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     121                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     122                 :            :                                                     &data_size1, NULL, NULL);
+     123                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     124                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     125                 :            :         data_size1;
+     126                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+     127                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+     128                 :            :         data_size1;
+     129                 :            : 
+     130                 :          1 :     libspdm_reset_message_a(spdm_context);
+     131                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     132                 :            : 
+     133                 :          1 :     session_id = 0xFFFFFFFF;
+     134                 :          1 :     spdm_context->latest_session_id = session_id;
+     135                 :          1 :     session_info = &spdm_context->session_info[0];
+     136                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, false);
+     137                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     138                 :          1 :     libspdm_set_mem(m_dummy_buffer, hash_size, (uint8_t)(0xFF));
+     139                 :          1 :     libspdm_secured_message_set_request_finished_key(
+     140                 :            :         session_info->secured_message_context, m_dummy_buffer,
+     141                 :            :         hash_size);
+     142                 :          1 :     libspdm_secured_message_set_session_state(
+     143                 :            :         session_info->secured_message_context,
+     144                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+     145                 :            : 
+     146                 :          1 :     spdm_context->connection_info.capability.flags |=
+     147                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+     148                 :          1 :     spdm_context->local_context.capability.flags |=
+     149                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+     150                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     151                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     152                 :          1 :     ptr = m_libspdm_finish_request1.signature;
+     153                 :          1 :     libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+     154                 :          1 :     cert_buffer = (uint8_t *)data1;
+     155                 :          1 :     cert_buffer_size = data_size1;
+     156                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+     157                 :            :                      cert_buffer_hash);
+     158                 :            :     /* transcript.message_a size is 0*/
+     159                 :          1 :     libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+     160                 :            :     /* session_transcript.message_k is 0*/
+     161                 :          1 :     libspdm_append_managed_buffer(&th_curr, (uint8_t *)&m_libspdm_finish_request1,
+     162                 :            :                                   sizeof(spdm_finish_request_t));
+     163                 :          1 :     libspdm_set_mem(request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+     164                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+     165                 :            :                      libspdm_get_managed_buffer_size(&th_curr), hash_data);
+     166                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+     167                 :            :                      request_finished_key, hash_size, ptr);
+     168                 :          1 :     m_libspdm_finish_request1_size = sizeof(spdm_finish_request_t) + hmac_size;
+     169                 :          1 :     response_size = sizeof(response);
+     170                 :          1 :     status = libspdm_get_response_finish(spdm_context,
+     171                 :            :                                          m_libspdm_finish_request1_size,
+     172                 :            :                                          &m_libspdm_finish_request1,
+     173                 :            :                                          &response_size, response);
+     174                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     175                 :          1 :     assert_int_equal(response_size,
+     176                 :            :                      sizeof(spdm_finish_response_t) + hmac_size);
+     177                 :          1 :     spdm_response = (void *)response;
+     178                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     179                 :            :                      SPDM_FINISH_RSP);
+     180                 :          1 :     free(data1);
+     181                 :          1 : }
+     182                 :            : 
+     183                 :            : /**
+     184                 :            :  * Test 2:
+     185                 :            :  * Expected behavior:
+     186                 :            :  **/
+     187                 :          1 : void libspdm_test_responder_finish_case2(void **state)
+     188                 :            : {
+     189                 :          1 : }
+     190                 :            : 
+     191                 :            : /**
+     192                 :            :  * Test 3: receiving a correct FINISH from the requester, but the
+     193                 :            :  * responder is in a Busy state.
+     194                 :            :  * Expected behavior: the responder accepts the request, but produces an
+     195                 :            :  * ERROR message indicating the Busy state.
+     196                 :            :  **/
+     197                 :          1 : void libspdm_test_responder_finish_case3(void **state)
+     198                 :            : {
+     199                 :            :     libspdm_return_t status;
+     200                 :            :     libspdm_test_context_t *spdm_test_context;
+     201                 :            :     libspdm_context_t *spdm_context;
+     202                 :            :     size_t response_size;
+     203                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     204                 :            :     spdm_finish_response_t *spdm_response;
+     205                 :            :     void *data1;
+     206                 :            :     size_t data_size1;
+     207                 :            :     uint8_t *ptr;
+     208                 :            :     uint8_t *cert_buffer;
+     209                 :            :     size_t cert_buffer_size;
+     210                 :            :     uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+     211                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     212                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+     213                 :            :     libspdm_session_info_t *session_info;
+     214                 :            :     uint32_t session_id;
+     215                 :            :     uint32_t hash_size;
+     216                 :            :     uint32_t hmac_size;
+     217                 :            : 
+     218                 :          1 :     spdm_test_context = *state;
+     219                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     220                 :          1 :     spdm_test_context->case_id = 0x3;
+     221                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     222                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     223                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_BUSY;
+     224                 :          1 :     spdm_context->connection_info.connection_state =
+     225                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     226                 :          1 :     spdm_context->connection_info.capability.flags |=
+     227                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+     228                 :          1 :     spdm_context->local_context.capability.flags |=
+     229                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+     230                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     231                 :            :         m_libspdm_use_hash_algo;
+     232                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     233                 :            :         m_libspdm_use_asym_algo;
+     234                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     235                 :            :         m_libspdm_use_measurement_spec;
+     236                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     237                 :            :         m_libspdm_use_measurement_hash_algo;
+     238                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     239                 :            :         m_libspdm_use_dhe_algo;
+     240                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     241                 :            :         m_libspdm_use_aead_algo;
+     242                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     243                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     244                 :            :                                                     &data_size1, NULL, NULL);
+     245                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     246                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     247                 :            :         data_size1;
+     248                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+     249                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+     250                 :            :         data_size1;
+     251                 :            : 
+     252                 :          1 :     libspdm_reset_message_a(spdm_context);
+     253                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     254                 :            : 
+     255                 :          1 :     session_id = 0xFFFFFFFF;
+     256                 :          1 :     spdm_context->latest_session_id = session_id;
+     257                 :          1 :     session_info = &spdm_context->session_info[0];
+     258                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, false);
+     259                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     260                 :          1 :     libspdm_set_mem(m_dummy_buffer, hash_size, (uint8_t)(0xFF));
+     261                 :          1 :     libspdm_secured_message_set_request_finished_key(
+     262                 :            :         session_info->secured_message_context, m_dummy_buffer,
+     263                 :            :         hash_size);
+     264                 :          1 :     libspdm_secured_message_set_session_state(
+     265                 :            :         session_info->secured_message_context,
+     266                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+     267                 :            : 
+     268                 :          1 :     spdm_context->connection_info.capability.flags |=
+     269                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+     270                 :          1 :     spdm_context->local_context.capability.flags |=
+     271                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+     272                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     273                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     274                 :          1 :     ptr = m_libspdm_finish_request1.signature;
+     275                 :          1 :     libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+     276                 :          1 :     cert_buffer = (uint8_t *)data1;
+     277                 :          1 :     cert_buffer_size = data_size1;
+     278                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+     279                 :            :                      cert_buffer_hash);
+     280                 :            :     /* transcript.message_a size is 0*/
+     281                 :          1 :     libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+     282                 :            :     /* session_transcript.message_k is 0*/
+     283                 :          1 :     libspdm_append_managed_buffer(&th_curr, (uint8_t *)&m_libspdm_finish_request1,
+     284                 :            :                                   sizeof(spdm_finish_request_t));
+     285                 :          1 :     libspdm_set_mem(request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+     286                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+     287                 :            :                      libspdm_get_managed_buffer_size(&th_curr), hash_data);
+     288                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+     289                 :            :                      request_finished_key, hash_size, ptr);
+     290                 :          1 :     m_libspdm_finish_request1_size = sizeof(spdm_finish_request_t) + hmac_size;
+     291                 :          1 :     response_size = sizeof(response);
+     292                 :          1 :     status = libspdm_get_response_finish(spdm_context,
+     293                 :            :                                          m_libspdm_finish_request1_size,
+     294                 :            :                                          &m_libspdm_finish_request1,
+     295                 :            :                                          &response_size, response);
+     296                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     297                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     298                 :          1 :     spdm_response = (void *)response;
+     299                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     300                 :            :                      SPDM_ERROR);
+     301                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_BUSY);
+     302                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     303                 :          1 :     assert_int_equal(spdm_context->response_state,
+     304                 :            :                      LIBSPDM_RESPONSE_STATE_BUSY);
+     305                 :          1 :     free(data1);
+     306                 :          1 : }
+     307                 :            : 
+     308                 :            : /**
+     309                 :            :  * Test 4: receiving a correct FINISH from the requester, but the responder
+     310                 :            :  * requires resynchronization with the requester.
+     311                 :            :  * Expected behavior: the responder accepts the request, but produces an
+     312                 :            :  * ERROR message indicating the NeedResynch state.
+     313                 :            :  **/
+     314                 :          1 : void libspdm_test_responder_finish_case4(void **state)
+     315                 :            : {
+     316                 :            :     libspdm_return_t status;
+     317                 :            :     libspdm_test_context_t *spdm_test_context;
+     318                 :            :     libspdm_context_t *spdm_context;
+     319                 :            :     size_t response_size;
+     320                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     321                 :            :     spdm_finish_response_t *spdm_response;
+     322                 :            :     void *data1;
+     323                 :            :     size_t data_size1;
+     324                 :            :     uint8_t *ptr;
+     325                 :            :     uint8_t *cert_buffer;
+     326                 :            :     size_t cert_buffer_size;
+     327                 :            :     uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+     328                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     329                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+     330                 :            :     libspdm_session_info_t *session_info;
+     331                 :            :     uint32_t session_id;
+     332                 :            :     uint32_t hash_size;
+     333                 :            :     uint32_t hmac_size;
+     334                 :            : 
+     335                 :          1 :     spdm_test_context = *state;
+     336                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     337                 :          1 :     spdm_test_context->case_id = 0x4;
+     338                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     339                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     340                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NEED_RESYNC;
+     341                 :          1 :     spdm_context->connection_info.connection_state =
+     342                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     343                 :          1 :     spdm_context->connection_info.capability.flags |=
+     344                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+     345                 :          1 :     spdm_context->local_context.capability.flags |=
+     346                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+     347                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     348                 :            :         m_libspdm_use_hash_algo;
+     349                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     350                 :            :         m_libspdm_use_asym_algo;
+     351                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     352                 :            :         m_libspdm_use_measurement_spec;
+     353                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     354                 :            :         m_libspdm_use_measurement_hash_algo;
+     355                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     356                 :            :         m_libspdm_use_dhe_algo;
+     357                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     358                 :            :         m_libspdm_use_aead_algo;
+     359                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     360                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     361                 :            :                                                     &data_size1, NULL, NULL);
+     362                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     363                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     364                 :            :         data_size1;
+     365                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+     366                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+     367                 :            :         data_size1;
+     368                 :            : 
+     369                 :          1 :     libspdm_reset_message_a(spdm_context);
+     370                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     371                 :            : 
+     372                 :          1 :     session_id = 0xFFFFFFFF;
+     373                 :          1 :     spdm_context->latest_session_id = session_id;
+     374                 :          1 :     session_info = &spdm_context->session_info[0];
+     375                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, false);
+     376                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     377                 :          1 :     libspdm_set_mem(m_dummy_buffer, hash_size, (uint8_t)(0xFF));
+     378                 :          1 :     libspdm_secured_message_set_request_finished_key(
+     379                 :            :         session_info->secured_message_context, m_dummy_buffer,
+     380                 :            :         hash_size);
+     381                 :          1 :     libspdm_secured_message_set_session_state(
+     382                 :            :         session_info->secured_message_context,
+     383                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+     384                 :            : 
+     385                 :          1 :     spdm_context->connection_info.capability.flags |=
+     386                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+     387                 :          1 :     spdm_context->local_context.capability.flags |=
+     388                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+     389                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     390                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     391                 :          1 :     ptr = m_libspdm_finish_request1.signature;
+     392                 :          1 :     libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+     393                 :          1 :     cert_buffer = (uint8_t *)data1;
+     394                 :          1 :     cert_buffer_size = data_size1;
+     395                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+     396                 :            :                      cert_buffer_hash);
+     397                 :            :     /* transcript.message_a size is 0*/
+     398                 :          1 :     libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+     399                 :            :     /* session_transcript.message_k is 0*/
+     400                 :          1 :     libspdm_append_managed_buffer(&th_curr, (uint8_t *)&m_libspdm_finish_request1,
+     401                 :            :                                   sizeof(spdm_finish_request_t));
+     402                 :          1 :     libspdm_set_mem(request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+     403                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+     404                 :            :                      libspdm_get_managed_buffer_size(&th_curr), hash_data);
+     405                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+     406                 :            :                      request_finished_key, hash_size, ptr);
+     407                 :          1 :     m_libspdm_finish_request1_size = sizeof(spdm_finish_request_t) + hmac_size;
+     408                 :          1 :     response_size = sizeof(response);
+     409                 :          1 :     status = libspdm_get_response_finish(spdm_context,
+     410                 :            :                                          m_libspdm_finish_request1_size,
+     411                 :            :                                          &m_libspdm_finish_request1,
+     412                 :            :                                          &response_size, response);
+     413                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     414                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     415                 :          1 :     spdm_response = (void *)response;
+     416                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     417                 :            :                      SPDM_ERROR);
+     418                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     419                 :            :                      SPDM_ERROR_CODE_REQUEST_RESYNCH);
+     420                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     421                 :          1 :     assert_int_equal(spdm_context->response_state,
+     422                 :            :                      LIBSPDM_RESPONSE_STATE_NEED_RESYNC);
+     423                 :          1 :     free(data1);
+     424                 :          1 : }
+     425                 :            : 
+     426                 :            : #if LIBSPDM_RESPOND_IF_READY_SUPPORT
+     427                 :            : /**
+     428                 :            :  * Test 5: receiving a correct FINISH from the requester, but the responder
+     429                 :            :  * could not produce the response in time.
+     430                 :            :  * Expected behavior: the responder accepts the request, but produces an
+     431                 :            :  * ERROR message indicating the ResponseNotReady state.
+     432                 :            :  **/
+     433                 :          1 : void libspdm_test_responder_finish_case5(void **state)
+     434                 :            : {
+     435                 :            :     libspdm_return_t status;
+     436                 :            :     libspdm_test_context_t *spdm_test_context;
+     437                 :            :     libspdm_context_t *spdm_context;
+     438                 :            :     size_t response_size;
+     439                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     440                 :            :     spdm_finish_response_t *spdm_response;
+     441                 :            :     void *data1;
+     442                 :            :     size_t data_size1;
+     443                 :            :     uint8_t *ptr;
+     444                 :            :     uint8_t *cert_buffer;
+     445                 :            :     size_t cert_buffer_size;
+     446                 :            :     uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+     447                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     448                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+     449                 :            :     libspdm_session_info_t *session_info;
+     450                 :            :     uint32_t session_id;
+     451                 :            :     uint32_t hash_size;
+     452                 :            :     uint32_t hmac_size;
+     453                 :            :     spdm_error_data_response_not_ready_t *error_data;
+     454                 :            : 
+     455                 :          1 :     spdm_test_context = *state;
+     456                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     457                 :          1 :     spdm_test_context->case_id = 0x5;
+     458                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     459                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     460                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NOT_READY;
+     461                 :          1 :     spdm_context->connection_info.connection_state =
+     462                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     463                 :          1 :     spdm_context->connection_info.capability.flags |=
+     464                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+     465                 :          1 :     spdm_context->local_context.capability.flags |=
+     466                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+     467                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     468                 :            :         m_libspdm_use_hash_algo;
+     469                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     470                 :            :         m_libspdm_use_asym_algo;
+     471                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     472                 :            :         m_libspdm_use_measurement_spec;
+     473                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     474                 :            :         m_libspdm_use_measurement_hash_algo;
+     475                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     476                 :            :         m_libspdm_use_dhe_algo;
+     477                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     478                 :            :         m_libspdm_use_aead_algo;
+     479                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     480                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     481                 :            :                                                     &data_size1, NULL, NULL);
+     482                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     483                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     484                 :            :         data_size1;
+     485                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+     486                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+     487                 :            :         data_size1;
+     488                 :            : 
+     489                 :          1 :     libspdm_reset_message_a(spdm_context);
+     490                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     491                 :            : 
+     492                 :          1 :     session_id = 0xFFFFFFFF;
+     493                 :          1 :     spdm_context->latest_session_id = session_id;
+     494                 :          1 :     session_info = &spdm_context->session_info[0];
+     495                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, false);
+     496                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     497                 :          1 :     libspdm_set_mem(m_dummy_buffer, hash_size, (uint8_t)(0xFF));
+     498                 :          1 :     libspdm_secured_message_set_request_finished_key(
+     499                 :            :         session_info->secured_message_context, m_dummy_buffer,
+     500                 :            :         hash_size);
+     501                 :          1 :     libspdm_secured_message_set_session_state(
+     502                 :            :         session_info->secured_message_context,
+     503                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+     504                 :            : 
+     505                 :          1 :     spdm_context->connection_info.capability.flags |=
+     506                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+     507                 :          1 :     spdm_context->local_context.capability.flags |=
+     508                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+     509                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     510                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     511                 :          1 :     ptr = m_libspdm_finish_request1.signature;
+     512                 :          1 :     libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+     513                 :          1 :     cert_buffer = (uint8_t *)data1;
+     514                 :          1 :     cert_buffer_size = data_size1;
+     515                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+     516                 :            :                      cert_buffer_hash);
+     517                 :            :     /* transcript.message_a size is 0*/
+     518                 :          1 :     libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+     519                 :            :     /* session_transcript.message_k is 0*/
+     520                 :          1 :     libspdm_append_managed_buffer(&th_curr, (uint8_t *)&m_libspdm_finish_request1,
+     521                 :            :                                   sizeof(spdm_finish_request_t));
+     522                 :          1 :     libspdm_set_mem(request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+     523                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+     524                 :            :                      libspdm_get_managed_buffer_size(&th_curr), hash_data);
+     525                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+     526                 :            :                      request_finished_key, hash_size, ptr);
+     527                 :          1 :     m_libspdm_finish_request1_size = sizeof(spdm_finish_request_t) + hmac_size;
+     528                 :          1 :     response_size = sizeof(response);
+     529                 :          1 :     status = libspdm_get_response_finish(spdm_context,
+     530                 :            :                                          m_libspdm_finish_request1_size,
+     531                 :            :                                          &m_libspdm_finish_request1,
+     532                 :            :                                          &response_size, response);
+     533                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     534                 :          1 :     assert_int_equal(response_size,
+     535                 :            :                      sizeof(spdm_error_response_t) +
+     536                 :            :                      sizeof(spdm_error_data_response_not_ready_t));
+     537                 :          1 :     spdm_response = (void *)response;
+     538                 :          1 :     error_data =
+     539                 :            :         (spdm_error_data_response_not_ready_t *)(spdm_response + 1);
+     540                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     541                 :            :                      SPDM_ERROR);
+     542                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     543                 :            :                      SPDM_ERROR_CODE_RESPONSE_NOT_READY);
+     544                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     545                 :          1 :     assert_int_equal(spdm_context->response_state,
+     546                 :            :                      LIBSPDM_RESPONSE_STATE_NOT_READY);
+     547                 :          1 :     assert_int_equal(error_data->request_code, SPDM_FINISH);
+     548                 :          1 :     free(data1);
+     549                 :          1 : }
+     550                 :            : #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
+     551                 :            : 
+     552                 :            : /**
+     553                 :            :  * Test 6: receiving a correct FINISH from the requester, but the responder
+     554                 :            :  * is not set no receive a FINISH message because previous messages (namely,
+     555                 :            :  * GET_CAPABILITIES, NEGOTIATE_ALGORITHMS or GET_DIGESTS) have not been
+     556                 :            :  * received.
+     557                 :            :  * Expected behavior: the responder rejects the request, and produces an
+     558                 :            :  * ERROR message indicating the UnexpectedRequest.
+     559                 :            :  **/
+     560                 :          1 : void libspdm_test_responder_finish_case6(void **state)
+     561                 :            : {
+     562                 :            :     libspdm_return_t status;
+     563                 :            :     libspdm_test_context_t *spdm_test_context;
+     564                 :            :     libspdm_context_t *spdm_context;
+     565                 :            :     size_t response_size;
+     566                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     567                 :            :     spdm_finish_response_t *spdm_response;
+     568                 :            :     void *data1;
+     569                 :            :     size_t data_size1;
+     570                 :            :     uint8_t *ptr;
+     571                 :            :     uint8_t *cert_buffer;
+     572                 :            :     size_t cert_buffer_size;
+     573                 :            :     uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+     574                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     575                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+     576                 :            :     libspdm_session_info_t *session_info;
+     577                 :            :     uint32_t session_id;
+     578                 :            :     uint32_t hash_size;
+     579                 :            :     uint32_t hmac_size;
+     580                 :            : 
+     581                 :          1 :     spdm_test_context = *state;
+     582                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     583                 :          1 :     spdm_test_context->case_id = 0x6;
+     584                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     585                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     586                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+     587                 :          1 :     spdm_context->connection_info.connection_state =
+     588                 :            :         LIBSPDM_CONNECTION_STATE_NOT_STARTED;
+     589                 :          1 :     spdm_context->connection_info.capability.flags |=
+     590                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+     591                 :          1 :     spdm_context->local_context.capability.flags |=
+     592                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+     593                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     594                 :            :         m_libspdm_use_hash_algo;
+     595                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     596                 :            :         m_libspdm_use_asym_algo;
+     597                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     598                 :            :         m_libspdm_use_measurement_spec;
+     599                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     600                 :            :         m_libspdm_use_measurement_hash_algo;
+     601                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     602                 :            :         m_libspdm_use_dhe_algo;
+     603                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     604                 :            :         m_libspdm_use_aead_algo;
+     605                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     606                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     607                 :            :                                                     &data_size1, NULL, NULL);
+     608                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     609                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     610                 :            :         data_size1;
+     611                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+     612                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+     613                 :            :         data_size1;
+     614                 :            : 
+     615                 :          1 :     libspdm_reset_message_a(spdm_context);
+     616                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     617                 :            : 
+     618                 :          1 :     session_id = 0xFFFFFFFF;
+     619                 :          1 :     spdm_context->latest_session_id = session_id;
+     620                 :          1 :     session_info = &spdm_context->session_info[0];
+     621                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, false);
+     622                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     623                 :          1 :     libspdm_set_mem(m_dummy_buffer, hash_size, (uint8_t)(0xFF));
+     624                 :          1 :     libspdm_secured_message_set_request_finished_key(
+     625                 :            :         session_info->secured_message_context, m_dummy_buffer,
+     626                 :            :         hash_size);
+     627                 :          1 :     libspdm_secured_message_set_session_state(
+     628                 :            :         session_info->secured_message_context,
+     629                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+     630                 :            : 
+     631                 :          1 :     spdm_context->connection_info.capability.flags |=
+     632                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+     633                 :          1 :     spdm_context->local_context.capability.flags |=
+     634                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+     635                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     636                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     637                 :          1 :     ptr = m_libspdm_finish_request1.signature;
+     638                 :          1 :     libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+     639                 :          1 :     cert_buffer = (uint8_t *)data1;
+     640                 :          1 :     cert_buffer_size = data_size1;
+     641                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+     642                 :            :                      cert_buffer_hash);
+     643                 :            :     /* transcript.message_a size is 0*/
+     644                 :          1 :     libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+     645                 :            :     /* session_transcript.message_k is 0*/
+     646                 :          1 :     libspdm_append_managed_buffer(&th_curr, (uint8_t *)&m_libspdm_finish_request1,
+     647                 :            :                                   sizeof(spdm_finish_request_t));
+     648                 :          1 :     libspdm_set_mem(request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+     649                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+     650                 :            :                      libspdm_get_managed_buffer_size(&th_curr), hash_data);
+     651                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+     652                 :            :                      request_finished_key, hash_size, ptr);
+     653                 :          1 :     m_libspdm_finish_request1_size = sizeof(spdm_finish_request_t) + hmac_size;
+     654                 :          1 :     response_size = sizeof(response);
+     655                 :          1 :     status = libspdm_get_response_finish(spdm_context,
+     656                 :            :                                          m_libspdm_finish_request1_size,
+     657                 :            :                                          &m_libspdm_finish_request1,
+     658                 :            :                                          &response_size, response);
+     659                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     660                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     661                 :          1 :     spdm_response = (void *)response;
+     662                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     663                 :            :                      SPDM_ERROR);
+     664                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     665                 :            :                      SPDM_ERROR_CODE_UNEXPECTED_REQUEST);
+     666                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     667                 :          1 :     free(data1);
+     668                 :          1 : }
+     669                 :            : 
+     670                 :          1 : void libspdm_test_responder_finish_case7(void **state)
+     671                 :            : {
+     672                 :            :     libspdm_return_t status;
+     673                 :            :     libspdm_test_context_t *spdm_test_context;
+     674                 :            :     libspdm_context_t *spdm_context;
+     675                 :            :     size_t response_size;
+     676                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     677                 :            :     spdm_finish_response_t *spdm_response;
+     678                 :            :     void *data1;
+     679                 :            :     size_t data_size1;
+     680                 :            :     uint8_t *ptr;
+     681                 :            :     uint8_t *cert_buffer;
+     682                 :            :     size_t cert_buffer_size;
+     683                 :            :     uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+     684                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     685                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+     686                 :            :     libspdm_session_info_t *session_info;
+     687                 :            :     uint32_t session_id;
+     688                 :            :     uint32_t hash_size;
+     689                 :            :     uint32_t hmac_size;
+     690                 :            : 
+     691                 :          1 :     spdm_test_context = *state;
+     692                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     693                 :          1 :     spdm_test_context->case_id = 0x7;
+     694                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     695                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     696                 :          1 :     spdm_context->connection_info.connection_state =
+     697                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     698                 :          1 :     spdm_context->connection_info.capability.flags |=
+     699                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+     700                 :          1 :     spdm_context->local_context.capability.flags |=
+     701                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+     702                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     703                 :            :         m_libspdm_use_hash_algo;
+     704                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     705                 :            :         m_libspdm_use_asym_algo;
+     706                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     707                 :            :         m_libspdm_use_measurement_spec;
+     708                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     709                 :            :         m_libspdm_use_measurement_hash_algo;
+     710                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     711                 :            :         m_libspdm_use_dhe_algo;
+     712                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     713                 :            :         m_libspdm_use_aead_algo;
+     714                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     715                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     716                 :            :                                                     &data_size1, NULL, NULL);
+     717                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     718                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     719                 :            :         data_size1;
+     720                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+     721                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+     722                 :            :         data_size1;
+     723                 :            : 
+     724                 :          1 :     libspdm_reset_message_a(spdm_context);
+     725                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     726                 :            : 
+     727                 :          1 :     session_id = 0xFFFFFFFF;
+     728                 :          1 :     spdm_context->latest_session_id = session_id;
+     729                 :          1 :     session_info = &spdm_context->session_info[0];
+     730                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, false);
+     731                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     732                 :          1 :     libspdm_set_mem(m_dummy_buffer, hash_size, (uint8_t)(0xFF));
+     733                 :          1 :     libspdm_secured_message_set_request_finished_key(
+     734                 :            :         session_info->secured_message_context, m_dummy_buffer,
+     735                 :            :         hash_size);
+     736                 :          1 :     libspdm_secured_message_set_session_state(
+     737                 :            :         session_info->secured_message_context,
+     738                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+     739                 :            : 
+     740                 :          1 :     spdm_context->connection_info.capability.flags |=
+     741                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+     742                 :          1 :     spdm_context->local_context.capability.flags |=
+     743                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+     744                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     745                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     746                 :          1 :     ptr = m_libspdm_finish_request1.signature;
+     747                 :          1 :     libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+     748                 :          1 :     cert_buffer = (uint8_t *)data1;
+     749                 :          1 :     cert_buffer_size = data_size1;
+     750                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     751                 :            :     session_info->session_transcript.message_m.buffer_size =
+     752                 :            :         session_info->session_transcript.message_m.max_buffer_size;
+     753                 :            :     spdm_context->transcript.message_b.buffer_size =
+     754                 :            :         spdm_context->transcript.message_b.max_buffer_size;
+     755                 :            :     spdm_context->transcript.message_c.buffer_size =
+     756                 :            :         spdm_context->transcript.message_c.max_buffer_size;
+     757                 :            :     spdm_context->transcript.message_mut_b.buffer_size =
+     758                 :            :         spdm_context->transcript.message_mut_b.max_buffer_size;
+     759                 :            :     spdm_context->transcript.message_mut_c.buffer_size =
+     760                 :            :         spdm_context->transcript.message_mut_c.max_buffer_size;
+     761                 :            : #endif
+     762                 :            : 
+     763                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+     764                 :            :                      cert_buffer_hash);
+     765                 :            :     /* transcript.message_a size is 0*/
+     766                 :          1 :     libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+     767                 :            :     /* session_transcript.message_k is 0*/
+     768                 :          1 :     libspdm_append_managed_buffer(&th_curr, (uint8_t *)&m_libspdm_finish_request1,
+     769                 :            :                                   sizeof(spdm_finish_request_t));
+     770                 :          1 :     libspdm_set_mem(request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+     771                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+     772                 :            :                      libspdm_get_managed_buffer_size(&th_curr), hash_data);
+     773                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+     774                 :            :                      request_finished_key, hash_size, ptr);
+     775                 :          1 :     m_libspdm_finish_request1_size = sizeof(spdm_finish_request_t) + hmac_size;
+     776                 :          1 :     response_size = sizeof(response);
+     777                 :          1 :     status = libspdm_get_response_finish(spdm_context,
+     778                 :            :                                          m_libspdm_finish_request1_size,
+     779                 :            :                                          &m_libspdm_finish_request1,
+     780                 :            :                                          &response_size, response);
+     781                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     782                 :          1 :     assert_int_equal(response_size,
+     783                 :            :                      sizeof(spdm_finish_response_t) + hmac_size);
+     784                 :          1 :     spdm_response = (void *)response;
+     785                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     786                 :            :                      SPDM_FINISH_RSP);
+     787                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     788                 :            :     assert_int_equal(session_info->session_transcript.message_m.buffer_size, 0);
+     789                 :            :     assert_int_equal(spdm_context->transcript.message_b.buffer_size, 0);
+     790                 :            :     assert_int_equal(spdm_context->transcript.message_c.buffer_size, 0);
+     791                 :            :     assert_int_equal(spdm_context->transcript.message_mut_b.buffer_size, 0);
+     792                 :            :     assert_int_equal(spdm_context->transcript.message_mut_c.buffer_size, 0);
+     793                 :            : #endif
+     794                 :            : 
+     795                 :          1 :     free(data1);
+     796                 :          1 : }
+     797                 :            : 
+     798                 :            : /**
+     799                 :            :  * Test 8: receiving a correct FINISH message from the requester with
+     800                 :            :  * correct MAC and signature (with mutual authentication), and 'handshake in
+     801                 :            :  * the clear'.
+     802                 :            :  * Expected behavior: the responder accepts the request and produces a valid
+     803                 :            :  * FINISH_RSP response message.
+     804                 :            :  **/
+     805                 :          1 : void libspdm_test_responder_finish_case8(void **state)
+     806                 :            : {
+     807                 :            :     libspdm_return_t status;
+     808                 :            :     libspdm_test_context_t *spdm_test_context;
+     809                 :            :     libspdm_context_t *spdm_context;
+     810                 :            :     size_t response_size;
+     811                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     812                 :            :     spdm_finish_response_t *spdm_response;
+     813                 :            :     void *data1;
+     814                 :            :     size_t data_size1;
+     815                 :            :     void *data2;
+     816                 :            :     size_t data_size2;
+     817                 :            :     uint8_t *ptr;
+     818                 :            :     uint8_t *cert_buffer;
+     819                 :            :     size_t cert_buffer_size;
+     820                 :            :     uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+     821                 :            :     uint8_t req_cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+     822                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     823                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+     824                 :            :     libspdm_session_info_t *session_info;
+     825                 :            :     uint32_t session_id;
+     826                 :            :     uint32_t hash_size;
+     827                 :            :     uint32_t hmac_size;
+     828                 :            :     size_t req_asym_signature_size;
+     829                 :            : 
+     830                 :          1 :     spdm_test_context = *state;
+     831                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     832                 :          1 :     spdm_test_context->case_id = 0x8;
+     833                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     834                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     835                 :          1 :     spdm_context->connection_info.connection_state =
+     836                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     837                 :          1 :     spdm_context->connection_info.capability.flags |=
+     838                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+     839                 :          1 :     spdm_context->local_context.capability.flags |=
+     840                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+     841                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     842                 :            :         m_libspdm_use_hash_algo;
+     843                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     844                 :            :         m_libspdm_use_asym_algo;
+     845                 :          1 :     spdm_context->connection_info.algorithm.req_base_asym_alg =
+     846                 :            :         m_libspdm_use_req_asym_algo;
+     847                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     848                 :            :         m_libspdm_use_measurement_spec;
+     849                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     850                 :            :         m_libspdm_use_measurement_hash_algo;
+     851                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     852                 :            :         m_libspdm_use_dhe_algo;
+     853                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     854                 :            :         m_libspdm_use_aead_algo;
+     855                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     856                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     857                 :            :                                                     &data_size1, NULL, NULL);
+     858                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     859                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     860                 :            :         data_size1;
+     861                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+     862                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+     863                 :            :         data_size1;
+     864                 :            : 
+     865                 :          1 :     libspdm_reset_message_a(spdm_context);
+     866                 :          1 :     spdm_context->local_context.mut_auth_requested = 1;
+     867                 :          1 :     libspdm_read_requester_public_certificate_chain(m_libspdm_use_hash_algo,
+     868                 :            :                                                     m_libspdm_use_req_asym_algo, &data2,
+     869                 :            :                                                     &data_size2, NULL, NULL);
+     870                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     871                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+     872                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+     873                 :            :                      data2, data_size2);
+     874                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+     875                 :            :         data_size2;
+     876                 :            : #else
+     877                 :          1 :     libspdm_hash_all(
+     878                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+     879                 :            :         data2, data_size2,
+     880                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+     881                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+     882                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+     883                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+     884                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+     885                 :          1 :         spdm_context->connection_info.algorithm.req_base_asym_alg,
+     886                 :            :         data2,
+     887                 :            :         data_size2,
+     888                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+     889                 :            : #endif
+     890                 :          1 :     spdm_context->connection_info.peer_used_cert_chain_slot_id = 0;
+     891                 :            : 
+     892                 :          1 :     session_id = 0xFFFFFFFF;
+     893                 :          1 :     spdm_context->latest_session_id = session_id;
+     894                 :          1 :     session_info = &spdm_context->session_info[0];
+     895                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, false);
+     896                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     897                 :          1 :     libspdm_set_mem(m_dummy_buffer, hash_size, (uint8_t)(0xFF));
+     898                 :          1 :     libspdm_secured_message_set_request_finished_key(
+     899                 :            :         session_info->secured_message_context, m_dummy_buffer,
+     900                 :            :         hash_size);
+     901                 :          1 :     libspdm_secured_message_set_session_state(
+     902                 :            :         session_info->secured_message_context,
+     903                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+     904                 :          1 :     session_info->mut_auth_requested = 1;
+     905                 :            : 
+     906                 :          1 :     spdm_context->connection_info.capability.flags |=
+     907                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+     908                 :          1 :     spdm_context->local_context.capability.flags |=
+     909                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+     910                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     911                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     912                 :          1 :     req_asym_signature_size =
+     913                 :          1 :         libspdm_get_req_asym_signature_size(m_libspdm_use_req_asym_algo);
+     914                 :          1 :     ptr = m_libspdm_finish_request3.signature;
+     915                 :          1 :     libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+     916                 :          1 :     cert_buffer = (uint8_t *)data1;
+     917                 :          1 :     cert_buffer_size = data_size1;
+     918                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+     919                 :            :                      cert_buffer_hash);
+     920                 :          1 :     cert_buffer = (uint8_t *)data2;
+     921                 :          1 :     cert_buffer_size = data_size2;
+     922                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+     923                 :            :                      req_cert_buffer_hash);
+     924                 :            :     /* transcript.message_a size is 0*/
+     925                 :          1 :     libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+     926                 :            :     /* session_transcript.message_k is 0*/
+     927                 :          1 :     libspdm_append_managed_buffer(&th_curr, req_cert_buffer_hash, hash_size);
+     928                 :          1 :     libspdm_append_managed_buffer(&th_curr, (uint8_t *)&m_libspdm_finish_request3,
+     929                 :            :                                   sizeof(spdm_finish_request_t));
+     930                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP
+     931                 :          1 :     libspdm_requester_data_sign(
+     932                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+     933                 :            :         spdm_context,
+     934                 :            : #endif
+     935                 :          1 :         m_libspdm_finish_request3.header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT, SPDM_FINISH,
+     936                 :            :             m_libspdm_use_req_asym_algo, m_libspdm_use_hash_algo,
+     937                 :          1 :             false, libspdm_get_managed_buffer(&th_curr),
+     938                 :            :             libspdm_get_managed_buffer_size(&th_curr),
+     939                 :            :             ptr, &req_asym_signature_size);
+     940                 :            : #endif
+     941                 :          1 :     libspdm_append_managed_buffer(&th_curr, ptr, req_asym_signature_size);
+     942                 :          1 :     ptr += req_asym_signature_size;
+     943                 :          1 :     libspdm_set_mem(request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+     944                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+     945                 :            :                      libspdm_get_managed_buffer_size(&th_curr), hash_data);
+     946                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+     947                 :            :                      request_finished_key, hash_size, ptr);
+     948                 :          1 :     m_libspdm_finish_request3_size = sizeof(spdm_finish_request_t) +
+     949                 :          1 :                                      req_asym_signature_size + hmac_size;
+     950                 :          1 :     response_size = sizeof(response);
+     951                 :          1 :     status = libspdm_get_response_finish(spdm_context,
+     952                 :            :                                          m_libspdm_finish_request3_size,
+     953                 :            :                                          &m_libspdm_finish_request3,
+     954                 :            :                                          &response_size, response);
+     955                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     956                 :          1 :     assert_int_equal(response_size,
+     957                 :            :                      sizeof(spdm_finish_response_t) + hmac_size);
+     958                 :          1 :     spdm_response = (void *)response;
+     959                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     960                 :            :                      SPDM_FINISH_RSP);
+     961                 :          1 :     free(data1);
+     962                 :          1 :     free(data2);
+     963                 :          1 : }
+     964                 :            : 
+     965                 :            : /**
+     966                 :            :  * Test 9: receiving a correct FINISH message from the requester, but the
+     967                 :            :  * responder has no capabilities for key exchange.
+     968                 :            :  * Expected behavior: the responder refuses the FINISH message and produces
+     969                 :            :  * an ERROR message indicating the UnsupportedRequest.
+     970                 :            :  **/
+     971                 :          1 : void libspdm_test_responder_finish_case9(void **state)
+     972                 :            : {
+     973                 :            :     libspdm_return_t status;
+     974                 :            :     libspdm_test_context_t *spdm_test_context;
+     975                 :            :     libspdm_context_t *spdm_context;
+     976                 :            :     size_t response_size;
+     977                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     978                 :            :     spdm_finish_response_t *spdm_response;
+     979                 :            :     void *data1;
+     980                 :            :     size_t data_size1;
+     981                 :            :     uint8_t *ptr;
+     982                 :            :     uint8_t *cert_buffer;
+     983                 :            :     size_t cert_buffer_size;
+     984                 :            :     uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+     985                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     986                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+     987                 :            :     libspdm_session_info_t *session_info;
+     988                 :            :     uint32_t session_id;
+     989                 :            :     uint32_t hash_size;
+     990                 :            :     uint32_t hmac_size;
+     991                 :            : 
+     992                 :          1 :     spdm_test_context = *state;
+     993                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     994                 :          1 :     spdm_test_context->case_id = 0x9;
+     995                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     996                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     997                 :          1 :     spdm_context->connection_info.connection_state =
+     998                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     999                 :          1 :     spdm_context->connection_info.capability.flags = 0;
+    1000                 :          1 :     spdm_context->local_context.capability.flags = 0;
+    1001                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1002                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    1003                 :            :     /* no key exchange capabilities (responder)*/
+    1004                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1005                 :            :         m_libspdm_use_hash_algo;
+    1006                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1007                 :            :         m_libspdm_use_asym_algo;
+    1008                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    1009                 :            :         m_libspdm_use_measurement_spec;
+    1010                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1011                 :            :         m_libspdm_use_measurement_hash_algo;
+    1012                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1013                 :            :         m_libspdm_use_dhe_algo;
+    1014                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1015                 :            :         m_libspdm_use_aead_algo;
+    1016                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1017                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    1018                 :            :                                                     &data_size1, NULL, NULL);
+    1019                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    1020                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    1021                 :            :         data_size1;
+    1022                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+    1023                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+    1024                 :            :         data_size1;
+    1025                 :            : 
+    1026                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1027                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+    1028                 :            : 
+    1029                 :          1 :     session_id = 0xFFFFFFFF;
+    1030                 :          1 :     spdm_context->latest_session_id = session_id;
+    1031                 :          1 :     session_info = &spdm_context->session_info[0];
+    1032                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, false);
+    1033                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1034                 :          1 :     libspdm_set_mem(m_dummy_buffer, hash_size, (uint8_t)(0xFF));
+    1035                 :          1 :     libspdm_secured_message_set_request_finished_key(
+    1036                 :            :         session_info->secured_message_context, m_dummy_buffer,
+    1037                 :            :         hash_size);
+    1038                 :          1 :     libspdm_secured_message_set_session_state(
+    1039                 :            :         session_info->secured_message_context,
+    1040                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    1041                 :            : 
+    1042                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1043                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    1044                 :          1 :     spdm_context->local_context.capability.flags |=
+    1045                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    1046                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1047                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1048                 :          1 :     ptr = m_libspdm_finish_request1.signature;
+    1049                 :          1 :     libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    1050                 :          1 :     cert_buffer = (uint8_t *)data1;
+    1051                 :          1 :     cert_buffer_size = data_size1;
+    1052                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    1053                 :            :                      cert_buffer_hash);
+    1054                 :            :     /* transcript.message_a size is 0*/
+    1055                 :          1 :     libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    1056                 :            :     /* session_transcript.message_k is 0*/
+    1057                 :          1 :     libspdm_append_managed_buffer(&th_curr, (uint8_t *)&m_libspdm_finish_request1,
+    1058                 :            :                                   sizeof(spdm_finish_request_t));
+    1059                 :          1 :     libspdm_set_mem(request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+    1060                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1061                 :            :                      libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1062                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    1063                 :            :                      request_finished_key, hash_size, ptr);
+    1064                 :          1 :     m_libspdm_finish_request1_size = sizeof(spdm_finish_request_t) + hmac_size;
+    1065                 :          1 :     response_size = sizeof(response);
+    1066                 :          1 :     status = libspdm_get_response_finish(spdm_context,
+    1067                 :            :                                          m_libspdm_finish_request1_size,
+    1068                 :            :                                          &m_libspdm_finish_request1,
+    1069                 :            :                                          &response_size, response);
+    1070                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1071                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1072                 :          1 :     spdm_response = (void *)response;
+    1073                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1074                 :            :                      SPDM_ERROR);
+    1075                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1076                 :            :                      SPDM_ERROR_CODE_UNSUPPORTED_REQUEST);
+    1077                 :          1 :     assert_int_equal(spdm_response->header.param2, SPDM_FINISH);
+    1078                 :          1 :     free(data1);
+    1079                 :          1 : }
+    1080                 :            : 
+    1081                 :            : /**
+    1082                 :            :  * Test 10: receiving a correct FINISH message from the requester, but the
+    1083                 :            :  * responder is not correctly setup by not initializing a session during
+    1084                 :            :  * KEY_EXCHANGE.
+    1085                 :            :  * Expected behavior: the responder refuses the FINISH message and produces
+    1086                 :            :  * an ERROR message indicating the UnsupportedRequest.
+    1087                 :            :  **/
+    1088                 :          1 : void libspdm_test_responder_finish_case10(void **state)
+    1089                 :            : {
+    1090                 :            :     libspdm_return_t status;
+    1091                 :            :     libspdm_test_context_t *spdm_test_context;
+    1092                 :            :     libspdm_context_t *spdm_context;
+    1093                 :            :     size_t response_size;
+    1094                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1095                 :            :     spdm_finish_response_t *spdm_response;
+    1096                 :            :     void *data1;
+    1097                 :            :     size_t data_size1;
+    1098                 :            :     uint8_t *ptr;
+    1099                 :            :     uint8_t *cert_buffer;
+    1100                 :            :     size_t cert_buffer_size;
+    1101                 :            :     uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    1102                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1103                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    1104                 :            :     libspdm_session_info_t *session_info;
+    1105                 :            :     uint32_t session_id;
+    1106                 :            :     uint32_t hash_size;
+    1107                 :            :     uint32_t hmac_size;
+    1108                 :            : 
+    1109                 :          1 :     spdm_test_context = *state;
+    1110                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1111                 :          1 :     spdm_test_context->case_id = 0xA;
+    1112                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1113                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1114                 :          1 :     spdm_context->connection_info.connection_state =
+    1115                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1116                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1117                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    1118                 :          1 :     spdm_context->local_context.capability.flags |=
+    1119                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    1120                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1121                 :            :         m_libspdm_use_hash_algo;
+    1122                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1123                 :            :         m_libspdm_use_asym_algo;
+    1124                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    1125                 :            :         m_libspdm_use_measurement_spec;
+    1126                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1127                 :            :         m_libspdm_use_measurement_hash_algo;
+    1128                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1129                 :            :         m_libspdm_use_dhe_algo;
+    1130                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1131                 :            :         m_libspdm_use_aead_algo;
+    1132                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1133                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    1134                 :            :                                                     &data_size1, NULL, NULL);
+    1135                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    1136                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    1137                 :            :         data_size1;
+    1138                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+    1139                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+    1140                 :            :         data_size1;
+    1141                 :            : 
+    1142                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1143                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+    1144                 :            : 
+    1145                 :          1 :     session_id = 0xFFFFFFFF;
+    1146                 :          1 :     spdm_context->latest_session_id = session_id;
+    1147                 :          1 :     session_info = &spdm_context->session_info[0];
+    1148                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, false);
+    1149                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1150                 :          1 :     libspdm_set_mem(m_dummy_buffer, hash_size, (uint8_t)(0xFF));
+    1151                 :          1 :     libspdm_secured_message_set_request_finished_key(
+    1152                 :            :         session_info->secured_message_context, m_dummy_buffer,
+    1153                 :            :         hash_size);
+    1154                 :          1 :     libspdm_secured_message_set_session_state(
+    1155                 :            :         session_info->secured_message_context,
+    1156                 :            :         LIBSPDM_SESSION_STATE_NOT_STARTED);
+    1157                 :            : 
+    1158                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1159                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    1160                 :          1 :     spdm_context->local_context.capability.flags |=
+    1161                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    1162                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1163                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1164                 :          1 :     ptr = m_libspdm_finish_request1.signature;
+    1165                 :          1 :     libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    1166                 :          1 :     cert_buffer = (uint8_t *)data1;
+    1167                 :          1 :     cert_buffer_size = data_size1;
+    1168                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    1169                 :            :                      cert_buffer_hash);
+    1170                 :            :     /* transcript.message_a size is 0*/
+    1171                 :          1 :     libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    1172                 :            :     /* session_transcript.message_k is 0*/
+    1173                 :          1 :     libspdm_append_managed_buffer(&th_curr, (uint8_t *)&m_libspdm_finish_request1,
+    1174                 :            :                                   sizeof(spdm_finish_request_t));
+    1175                 :          1 :     libspdm_set_mem(request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+    1176                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1177                 :            :                      libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1178                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    1179                 :            :                      request_finished_key, hash_size, ptr);
+    1180                 :          1 :     m_libspdm_finish_request1_size = sizeof(spdm_finish_request_t) + hmac_size;
+    1181                 :          1 :     response_size = sizeof(response);
+    1182                 :          1 :     status = libspdm_get_response_finish(spdm_context,
+    1183                 :            :                                          m_libspdm_finish_request1_size,
+    1184                 :            :                                          &m_libspdm_finish_request1,
+    1185                 :            :                                          &response_size, response);
+    1186                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1187                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1188                 :          1 :     spdm_response = (void *)response;
+    1189                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1190                 :            :                      SPDM_ERROR);
+    1191                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1192                 :            :                      SPDM_ERROR_CODE_UNEXPECTED_REQUEST);
+    1193                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1194                 :          1 :     free(data1);
+    1195                 :          1 : }
+    1196                 :            : 
+    1197                 :            : /**
+    1198                 :            :  * Test 11: receiving a FINISH message from the requester with an incorrect
+    1199                 :            :  * MAC (all-zero).
+    1200                 :            :  * Expected behavior: the responder refuses the FINISH message and produces
+    1201                 :            :  * an ERROR message indicating the DecryptError.
+    1202                 :            :  **/
+    1203                 :          1 : void libspdm_test_responder_finish_case11(void **state)
+    1204                 :            : {
+    1205                 :            :     libspdm_return_t status;
+    1206                 :            :     libspdm_test_context_t *spdm_test_context;
+    1207                 :            :     libspdm_context_t *spdm_context;
+    1208                 :            :     size_t response_size;
+    1209                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1210                 :            :     spdm_finish_response_t *spdm_response;
+    1211                 :            :     void *data1;
+    1212                 :            :     size_t data_size1;
+    1213                 :            :     uint8_t *ptr;
+    1214                 :            :     libspdm_session_info_t *session_info;
+    1215                 :            :     uint32_t session_id;
+    1216                 :            :     uint32_t hash_size;
+    1217                 :            :     uint32_t hmac_size;
+    1218                 :            : 
+    1219                 :          1 :     spdm_test_context = *state;
+    1220                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1221                 :          1 :     spdm_test_context->case_id = 0xB;
+    1222                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1223                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1224                 :          1 :     spdm_context->connection_info.connection_state =
+    1225                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1226                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1227                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    1228                 :          1 :     spdm_context->local_context.capability.flags |=
+    1229                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    1230                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1231                 :            :         m_libspdm_use_hash_algo;
+    1232                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1233                 :            :         m_libspdm_use_asym_algo;
+    1234                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    1235                 :            :         m_libspdm_use_measurement_spec;
+    1236                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1237                 :            :         m_libspdm_use_measurement_hash_algo;
+    1238                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1239                 :            :         m_libspdm_use_dhe_algo;
+    1240                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1241                 :            :         m_libspdm_use_aead_algo;
+    1242                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1243                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    1244                 :            :                                                     &data_size1, NULL, NULL);
+    1245                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    1246                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    1247                 :            :         data_size1;
+    1248                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+    1249                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+    1250                 :            :         data_size1;
+    1251                 :            : 
+    1252                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1253                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+    1254                 :            : 
+    1255                 :          1 :     session_id = 0xFFFFFFFF;
+    1256                 :          1 :     spdm_context->latest_session_id = session_id;
+    1257                 :          1 :     session_info = &spdm_context->session_info[0];
+    1258                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, false);
+    1259                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1260                 :          1 :     libspdm_set_mem(m_dummy_buffer, hash_size, (uint8_t)(0xFF));
+    1261                 :          1 :     libspdm_secured_message_set_request_finished_key(
+    1262                 :            :         session_info->secured_message_context, m_dummy_buffer,
+    1263                 :            :         hash_size);
+    1264                 :          1 :     libspdm_secured_message_set_session_state(
+    1265                 :            :         session_info->secured_message_context,
+    1266                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    1267                 :            : 
+    1268                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1269                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    1270                 :          1 :     spdm_context->local_context.capability.flags |=
+    1271                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    1272                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1273                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1274                 :          1 :     ptr = m_libspdm_finish_request1.signature;
+    1275                 :          1 :     libspdm_set_mem(ptr, hmac_size, (uint8_t)(0x00)); /*all-zero MAC*/
+    1276                 :          1 :     m_libspdm_finish_request1_size = sizeof(spdm_finish_request_t) + hmac_size;
+    1277                 :          1 :     response_size = sizeof(response);
+    1278                 :          1 :     status = libspdm_get_response_finish(spdm_context,
+    1279                 :            :                                          m_libspdm_finish_request1_size,
+    1280                 :            :                                          &m_libspdm_finish_request1,
+    1281                 :            :                                          &response_size, response);
+    1282                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1283                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1284                 :          1 :     spdm_response = (void *)response;
+    1285                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1286                 :            :                      SPDM_ERROR);
+    1287                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1288                 :            :                      SPDM_ERROR_CODE_DECRYPT_ERROR);
+    1289                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1290                 :          1 :     free(data1);
+    1291                 :          1 : }
+    1292                 :            : 
+    1293                 :            : /**
+    1294                 :            :  * Test 12: receiving a FINISH message from the requester with an incorrect
+    1295                 :            :  * MAC (arbitrary).
+    1296                 :            :  * Expected behavior: the responder refuses the FINISH message and produces
+    1297                 :            :  * an ERROR message indicating the DecryptError.
+    1298                 :            :  **/
+    1299                 :          1 : void libspdm_test_responder_finish_case12(void **state)
+    1300                 :            : {
+    1301                 :            :     libspdm_return_t status;
+    1302                 :            :     libspdm_test_context_t *spdm_test_context;
+    1303                 :            :     libspdm_context_t *spdm_context;
+    1304                 :            :     size_t response_size;
+    1305                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1306                 :            :     spdm_finish_response_t *spdm_response;
+    1307                 :            :     void *data1;
+    1308                 :            :     size_t data_size1;
+    1309                 :            :     uint8_t *ptr;
+    1310                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    1311                 :            :     uint8_t zero_data[LIBSPDM_MAX_HASH_SIZE];
+    1312                 :            :     libspdm_session_info_t *session_info;
+    1313                 :            :     uint32_t session_id;
+    1314                 :            :     uint32_t hash_size;
+    1315                 :            :     uint32_t hmac_size;
+    1316                 :            : 
+    1317                 :          1 :     spdm_test_context = *state;
+    1318                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1319                 :          1 :     spdm_test_context->case_id = 0xC;
+    1320                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1321                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1322                 :          1 :     spdm_context->connection_info.connection_state =
+    1323                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1324                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1325                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    1326                 :          1 :     spdm_context->local_context.capability.flags |=
+    1327                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    1328                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1329                 :            :         m_libspdm_use_hash_algo;
+    1330                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1331                 :            :         m_libspdm_use_asym_algo;
+    1332                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    1333                 :            :         m_libspdm_use_measurement_spec;
+    1334                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1335                 :            :         m_libspdm_use_measurement_hash_algo;
+    1336                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1337                 :            :         m_libspdm_use_dhe_algo;
+    1338                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1339                 :            :         m_libspdm_use_aead_algo;
+    1340                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1341                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    1342                 :            :                                                     &data_size1, NULL, NULL);
+    1343                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    1344                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    1345                 :            :         data_size1;
+    1346                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+    1347                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+    1348                 :            :         data_size1;
+    1349                 :            : 
+    1350                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1351                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+    1352                 :            : 
+    1353                 :          1 :     session_id = 0xFFFFFFFF;
+    1354                 :          1 :     spdm_context->latest_session_id = session_id;
+    1355                 :          1 :     session_info = &spdm_context->session_info[0];
+    1356                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, false);
+    1357                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1358                 :          1 :     libspdm_set_mem(m_dummy_buffer, hash_size, (uint8_t)(0xFF));
+    1359                 :          1 :     libspdm_secured_message_set_request_finished_key(
+    1360                 :            :         session_info->secured_message_context, m_dummy_buffer,
+    1361                 :            :         hash_size);
+    1362                 :          1 :     libspdm_secured_message_set_session_state(
+    1363                 :            :         session_info->secured_message_context,
+    1364                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    1365                 :            : 
+    1366                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1367                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    1368                 :          1 :     spdm_context->local_context.capability.flags |=
+    1369                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    1370                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1371                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1372                 :          1 :     ptr = m_libspdm_finish_request1.signature;
+    1373                 :            :     /*arbitrary MAC*/
+    1374                 :          1 :     libspdm_set_mem(request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+    1375                 :          1 :     libspdm_set_mem(zero_data, hash_size, (uint8_t)(0x00));
+    1376                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, zero_data, hash_size,
+    1377                 :            :                      request_finished_key, hash_size, ptr);
+    1378                 :          1 :     m_libspdm_finish_request1_size = sizeof(spdm_finish_request_t) + hmac_size;
+    1379                 :          1 :     response_size = sizeof(response);
+    1380                 :          1 :     status = libspdm_get_response_finish(spdm_context,
+    1381                 :            :                                          m_libspdm_finish_request1_size,
+    1382                 :            :                                          &m_libspdm_finish_request1,
+    1383                 :            :                                          &response_size, response);
+    1384                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1385                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1386                 :          1 :     spdm_response = (void *)response;
+    1387                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1388                 :            :                      SPDM_ERROR);
+    1389                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1390                 :            :                      SPDM_ERROR_CODE_DECRYPT_ERROR);
+    1391                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1392                 :          1 :     free(data1);
+    1393                 :          1 : }
+    1394                 :            : 
+    1395                 :            : /**
+    1396                 :            :  * Test 13:
+    1397                 :            :  * Expected behavior:
+    1398                 :            :  **/
+    1399                 :          1 : void libspdm_test_responder_finish_case13(void **state)
+    1400                 :            : {
+    1401                 :          1 : }
+    1402                 :            : 
+    1403                 :            : /**
+    1404                 :            :  * Test 14: receiving a FINISH message from the requester with an incorrect
+    1405                 :            :  * MAC size (only the correct first half of the MAC).
+    1406                 :            :  * Expected behavior: the responder refuses the FINISH message and produces
+    1407                 :            :  * an ERROR message indicating the InvalidRequest.
+    1408                 :            :  **/
+    1409                 :          1 : void libspdm_test_responder_finish_case14(void **state)
+    1410                 :            : {
+    1411                 :            :     libspdm_return_t status;
+    1412                 :            :     libspdm_test_context_t *spdm_test_context;
+    1413                 :            :     libspdm_context_t *spdm_context;
+    1414                 :            :     size_t response_size;
+    1415                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1416                 :            :     spdm_finish_response_t *spdm_response;
+    1417                 :            :     void *data1;
+    1418                 :            :     size_t data_size1;
+    1419                 :            :     uint8_t *ptr;
+    1420                 :            :     uint8_t *cert_buffer;
+    1421                 :            :     size_t cert_buffer_size;
+    1422                 :            :     uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    1423                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1424                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    1425                 :            :     libspdm_session_info_t *session_info;
+    1426                 :            :     uint32_t session_id;
+    1427                 :            :     uint32_t hash_size;
+    1428                 :            :     uint32_t hmac_size;
+    1429                 :            : 
+    1430                 :          1 :     spdm_test_context = *state;
+    1431                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1432                 :          1 :     spdm_test_context->case_id = 0xE;
+    1433                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1434                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1435                 :          1 :     spdm_context->connection_info.connection_state =
+    1436                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1437                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1438                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    1439                 :          1 :     spdm_context->local_context.capability.flags |=
+    1440                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    1441                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1442                 :            :         m_libspdm_use_hash_algo;
+    1443                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1444                 :            :         m_libspdm_use_asym_algo;
+    1445                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    1446                 :            :         m_libspdm_use_measurement_spec;
+    1447                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1448                 :            :         m_libspdm_use_measurement_hash_algo;
+    1449                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1450                 :            :         m_libspdm_use_dhe_algo;
+    1451                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1452                 :            :         m_libspdm_use_aead_algo;
+    1453                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1454                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    1455                 :            :                                                     &data_size1, NULL, NULL);
+    1456                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    1457                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    1458                 :            :         data_size1;
+    1459                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+    1460                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+    1461                 :            :         data_size1;
+    1462                 :            : 
+    1463                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1464                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+    1465                 :            : 
+    1466                 :          1 :     session_id = 0xFFFFFFFF;
+    1467                 :          1 :     spdm_context->latest_session_id = session_id;
+    1468                 :          1 :     session_info = &spdm_context->session_info[0];
+    1469                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, false);
+    1470                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1471                 :          1 :     libspdm_set_mem(m_dummy_buffer, hash_size, (uint8_t)(0xFF));
+    1472                 :          1 :     libspdm_secured_message_set_request_finished_key(
+    1473                 :            :         session_info->secured_message_context, m_dummy_buffer,
+    1474                 :            :         hash_size);
+    1475                 :          1 :     libspdm_secured_message_set_session_state(
+    1476                 :            :         session_info->secured_message_context,
+    1477                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    1478                 :            : 
+    1479                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1480                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    1481                 :          1 :     spdm_context->local_context.capability.flags |=
+    1482                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    1483                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1484                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1485                 :          1 :     ptr = m_libspdm_finish_request1.signature;
+    1486                 :          1 :     libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    1487                 :          1 :     cert_buffer = (uint8_t *)data1;
+    1488                 :          1 :     cert_buffer_size = data_size1;
+    1489                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    1490                 :            :                      cert_buffer_hash);
+    1491                 :            :     /* transcript.message_a size is 0*/
+    1492                 :          1 :     libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    1493                 :            :     /* session_transcript.message_k is 0*/
+    1494                 :          1 :     libspdm_append_managed_buffer(&th_curr, (uint8_t *)&m_libspdm_finish_request1,
+    1495                 :            :                                   sizeof(spdm_finish_request_t));
+    1496                 :          1 :     libspdm_set_mem(request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+    1497                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1498                 :            :                      libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1499                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    1500                 :            :                      request_finished_key, hash_size, ptr);
+    1501                 :          1 :     libspdm_set_mem(ptr + hmac_size/2, hmac_size/2, (uint8_t) 0x00); /* half HMAC size*/
+    1502                 :          1 :     m_libspdm_finish_request1_size = sizeof(spdm_finish_request_t) + hmac_size/2;
+    1503                 :          1 :     response_size = sizeof(response);
+    1504                 :          1 :     status = libspdm_get_response_finish(spdm_context,
+    1505                 :            :                                          m_libspdm_finish_request1_size,
+    1506                 :            :                                          &m_libspdm_finish_request1,
+    1507                 :            :                                          &response_size, response);
+    1508                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1509                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1510                 :          1 :     spdm_response = (void *)response;
+    1511                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1512                 :            :                      SPDM_ERROR);
+    1513                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1514                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+    1515                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1516                 :          1 :     free(data1);
+    1517                 :          1 : }
+    1518                 :            : 
+    1519                 :            : /**
+    1520                 :            :  * Test 15: receiving a FINISH message from the requester with an incorrect
+    1521                 :            :  * signature (all-zero), but a correct MAC.
+    1522                 :            :  * Expected behavior: the responder refuses the FINISH message and produces
+    1523                 :            :  * an ERROR message indicating the DecryptError.
+    1524                 :            :  **/
+    1525                 :          1 : void libspdm_test_responder_finish_case15(void **state)
+    1526                 :            : {
+    1527                 :            :     libspdm_return_t status;
+    1528                 :            :     libspdm_test_context_t *spdm_test_context;
+    1529                 :            :     libspdm_context_t *spdm_context;
+    1530                 :            :     size_t response_size;
+    1531                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1532                 :            :     spdm_finish_response_t *spdm_response;
+    1533                 :            :     void *data1;
+    1534                 :            :     size_t data_size1;
+    1535                 :            :     void *data2;
+    1536                 :            :     size_t data_size2;
+    1537                 :            :     uint8_t *ptr;
+    1538                 :            :     uint8_t *cert_buffer;
+    1539                 :            :     size_t cert_buffer_size;
+    1540                 :            :     uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    1541                 :            :     uint8_t req_cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    1542                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1543                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    1544                 :            :     libspdm_session_info_t *session_info;
+    1545                 :            :     uint32_t session_id;
+    1546                 :            :     uint32_t hash_size;
+    1547                 :            :     uint32_t hmac_size;
+    1548                 :            :     size_t req_asym_signature_size;
+    1549                 :            : 
+    1550                 :          1 :     spdm_test_context = *state;
+    1551                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1552                 :          1 :     spdm_test_context->case_id = 0xF;
+    1553                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1554                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1555                 :          1 :     spdm_context->connection_info.connection_state =
+    1556                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1557                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1558                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    1559                 :          1 :     spdm_context->local_context.capability.flags |=
+    1560                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    1561                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1562                 :            :         m_libspdm_use_hash_algo;
+    1563                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1564                 :            :         m_libspdm_use_asym_algo;
+    1565                 :          1 :     spdm_context->connection_info.algorithm.req_base_asym_alg =
+    1566                 :            :         m_libspdm_use_req_asym_algo;
+    1567                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    1568                 :            :         m_libspdm_use_measurement_spec;
+    1569                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1570                 :            :         m_libspdm_use_measurement_hash_algo;
+    1571                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1572                 :            :         m_libspdm_use_dhe_algo;
+    1573                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1574                 :            :         m_libspdm_use_aead_algo;
+    1575                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1576                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    1577                 :            :                                                     &data_size1, NULL, NULL);
+    1578                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    1579                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    1580                 :            :         data_size1;
+    1581                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+    1582                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+    1583                 :            :         data_size1;
+    1584                 :            : 
+    1585                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1586                 :          1 :     spdm_context->local_context.mut_auth_requested = 1;
+    1587                 :          1 :     libspdm_read_requester_public_certificate_chain(m_libspdm_use_hash_algo,
+    1588                 :            :                                                     m_libspdm_use_req_asym_algo, &data2,
+    1589                 :            :                                                     &data_size2, NULL, NULL);
+    1590                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1591                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    1592                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    1593                 :            :                      data2, data_size2);
+    1594                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    1595                 :            :         data_size2;
+    1596                 :            : #endif
+    1597                 :            : 
+    1598                 :          1 :     session_id = 0xFFFFFFFF;
+    1599                 :          1 :     spdm_context->latest_session_id = session_id;
+    1600                 :          1 :     session_info = &spdm_context->session_info[0];
+    1601                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, false);
+    1602                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1603                 :          1 :     libspdm_set_mem(m_dummy_buffer, hash_size, (uint8_t)(0xFF));
+    1604                 :          1 :     libspdm_secured_message_set_request_finished_key(
+    1605                 :            :         session_info->secured_message_context, m_dummy_buffer,
+    1606                 :            :         hash_size);
+    1607                 :          1 :     libspdm_secured_message_set_session_state(
+    1608                 :            :         session_info->secured_message_context,
+    1609                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    1610                 :          1 :     session_info->mut_auth_requested = 1;
+    1611                 :            : 
+    1612                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1613                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    1614                 :          1 :     spdm_context->local_context.capability.flags |=
+    1615                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    1616                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1617                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1618                 :          1 :     req_asym_signature_size =
+    1619                 :          1 :         libspdm_get_req_asym_signature_size(m_libspdm_use_req_asym_algo);
+    1620                 :          1 :     ptr = m_libspdm_finish_request3.signature;
+    1621                 :          1 :     libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    1622                 :          1 :     cert_buffer = (uint8_t *)data1;
+    1623                 :          1 :     cert_buffer_size = data_size1;
+    1624                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    1625                 :            :                      cert_buffer_hash);
+    1626                 :          1 :     cert_buffer = (uint8_t *)data2;
+    1627                 :          1 :     cert_buffer_size = data_size2;
+    1628                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    1629                 :            :                      req_cert_buffer_hash);
+    1630                 :            :     /* transcript.message_a size is 0*/
+    1631                 :          1 :     libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    1632                 :            :     /* session_transcript.message_k is 0*/
+    1633                 :          1 :     libspdm_append_managed_buffer(&th_curr, req_cert_buffer_hash, hash_size);
+    1634                 :          1 :     libspdm_append_managed_buffer(&th_curr, (uint8_t *)&m_libspdm_finish_request3,
+    1635                 :            :                                   sizeof(spdm_finish_request_t));
+    1636                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP
+    1637                 :          1 :     libspdm_requester_data_sign(
+    1638                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    1639                 :            :         spdm_context,
+    1640                 :            : #endif
+    1641                 :          1 :         m_libspdm_finish_request3.header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT, SPDM_FINISH,
+    1642                 :            :             m_libspdm_use_req_asym_algo, m_libspdm_use_hash_algo,
+    1643                 :          1 :             false, libspdm_get_managed_buffer(&th_curr),
+    1644                 :            :             libspdm_get_managed_buffer_size(&th_curr),
+    1645                 :            :             ptr, &req_asym_signature_size);
+    1646                 :            : #endif
+    1647                 :          1 :     libspdm_append_managed_buffer(&th_curr, ptr, req_asym_signature_size);
+    1648                 :          1 :     ptr += req_asym_signature_size;
+    1649                 :          1 :     libspdm_set_mem(request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+    1650                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1651                 :            :                      libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1652                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    1653                 :            :                      request_finished_key, hash_size, ptr);
+    1654                 :          1 :     libspdm_set_mem(m_libspdm_finish_request3.signature,
+    1655                 :            :                     req_asym_signature_size, (uint8_t) 0x00); /*zero signature*/
+    1656                 :          1 :     m_libspdm_finish_request3_size = sizeof(spdm_finish_request_t) +
+    1657                 :          1 :                                      req_asym_signature_size + hmac_size;
+    1658                 :          1 :     response_size = sizeof(response);
+    1659                 :          1 :     status = libspdm_get_response_finish(spdm_context,
+    1660                 :            :                                          m_libspdm_finish_request3_size,
+    1661                 :            :                                          &m_libspdm_finish_request3,
+    1662                 :            :                                          &response_size, response);
+    1663                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1664                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1665                 :          1 :     spdm_response = (void *)response;
+    1666                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1667                 :            :                      SPDM_ERROR);
+    1668                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1669                 :            :                      SPDM_ERROR_CODE_DECRYPT_ERROR);
+    1670                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1671                 :          1 :     free(data1);
+    1672                 :          1 :     free(data2);
+    1673                 :          1 : }
+    1674                 :            : 
+    1675                 :            : /**
+    1676                 :            :  * Test 16: receiving a FINISH message from the requester with an incorrect
+    1677                 :            :  * signature (arbitrary), but a correct MAC.
+    1678                 :            :  * Expected behavior: the responder refuses the FINISH message and produces
+    1679                 :            :  * an ERROR message indicating the DecryptError.
+    1680                 :            :  **/
+    1681                 :          1 : void libspdm_test_responder_finish_case16(void **state)
+    1682                 :            : {
+    1683                 :            :     libspdm_return_t status;
+    1684                 :            :     libspdm_test_context_t *spdm_test_context;
+    1685                 :            :     libspdm_context_t *spdm_context;
+    1686                 :            :     size_t response_size;
+    1687                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1688                 :            :     spdm_finish_response_t *spdm_response;
+    1689                 :            :     void *data1;
+    1690                 :            :     size_t data_size1;
+    1691                 :            :     void *data2;
+    1692                 :            :     size_t data_size2;
+    1693                 :            :     uint8_t *ptr;
+    1694                 :            :     uint8_t *cert_buffer;
+    1695                 :            :     size_t cert_buffer_size;
+    1696                 :            :     uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    1697                 :            :     uint8_t req_cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    1698                 :            :     uint8_t random_buffer[LIBSPDM_MAX_HASH_SIZE];
+    1699                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1700                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    1701                 :            :     libspdm_session_info_t *session_info;
+    1702                 :            :     uint32_t session_id;
+    1703                 :            :     uint32_t hash_size;
+    1704                 :            :     uint32_t hmac_size;
+    1705                 :            :     size_t req_asym_signature_size;
+    1706                 :            : 
+    1707                 :          1 :     spdm_test_context = *state;
+    1708                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1709                 :          1 :     spdm_test_context->case_id = 0x10;
+    1710                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1711                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1712                 :          1 :     spdm_context->connection_info.connection_state =
+    1713                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1714                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1715                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    1716                 :          1 :     spdm_context->local_context.capability.flags |=
+    1717                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    1718                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1719                 :            :         m_libspdm_use_hash_algo;
+    1720                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1721                 :            :         m_libspdm_use_asym_algo;
+    1722                 :          1 :     spdm_context->connection_info.algorithm.req_base_asym_alg =
+    1723                 :            :         m_libspdm_use_req_asym_algo;
+    1724                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    1725                 :            :         m_libspdm_use_measurement_spec;
+    1726                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1727                 :            :         m_libspdm_use_measurement_hash_algo;
+    1728                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1729                 :            :         m_libspdm_use_dhe_algo;
+    1730                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1731                 :            :         m_libspdm_use_aead_algo;
+    1732                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1733                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    1734                 :            :                                                     &data_size1, NULL, NULL);
+    1735                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    1736                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    1737                 :            :         data_size1;
+    1738                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+    1739                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+    1740                 :            :         data_size1;
+    1741                 :            : 
+    1742                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1743                 :          1 :     spdm_context->local_context.mut_auth_requested = 1;
+    1744                 :          1 :     libspdm_read_requester_public_certificate_chain(m_libspdm_use_hash_algo,
+    1745                 :            :                                                     m_libspdm_use_req_asym_algo, &data2,
+    1746                 :            :                                                     &data_size2, NULL, NULL);
+    1747                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1748                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    1749                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    1750                 :            :                      data2, data_size2);
+    1751                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    1752                 :            :         data_size2;
+    1753                 :            : #endif
+    1754                 :            : 
+    1755                 :          1 :     session_id = 0xFFFFFFFF;
+    1756                 :          1 :     spdm_context->latest_session_id = session_id;
+    1757                 :          1 :     session_info = &spdm_context->session_info[0];
+    1758                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, false);
+    1759                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1760                 :          1 :     libspdm_set_mem(m_dummy_buffer, hash_size, (uint8_t)(0xFF));
+    1761                 :          1 :     libspdm_secured_message_set_request_finished_key(
+    1762                 :            :         session_info->secured_message_context, m_dummy_buffer,
+    1763                 :            :         hash_size);
+    1764                 :          1 :     libspdm_secured_message_set_session_state(
+    1765                 :            :         session_info->secured_message_context,
+    1766                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    1767                 :          1 :     session_info->mut_auth_requested = 1;
+    1768                 :            : 
+    1769                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1770                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    1771                 :          1 :     spdm_context->local_context.capability.flags |=
+    1772                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    1773                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1774                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1775                 :          1 :     req_asym_signature_size =
+    1776                 :          1 :         libspdm_get_req_asym_signature_size(m_libspdm_use_req_asym_algo);
+    1777                 :          1 :     ptr = m_libspdm_finish_request3.signature;
+    1778                 :          1 :     libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    1779                 :          1 :     cert_buffer = (uint8_t *)data1;
+    1780                 :          1 :     cert_buffer_size = data_size1;
+    1781                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    1782                 :            :                      cert_buffer_hash);
+    1783                 :          1 :     cert_buffer = (uint8_t *)data2;
+    1784                 :          1 :     cert_buffer_size = data_size2;
+    1785                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    1786                 :            :                      req_cert_buffer_hash);
+    1787                 :            :     /* transcript.message_a size is 0*/
+    1788                 :          1 :     libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    1789                 :            :     /* session_transcript.message_k is 0*/
+    1790                 :          1 :     libspdm_append_managed_buffer(&th_curr, req_cert_buffer_hash, hash_size);
+    1791                 :          1 :     libspdm_append_managed_buffer(&th_curr, (uint8_t *)&m_libspdm_finish_request3,
+    1792                 :            :                                   sizeof(spdm_finish_request_t));
+    1793                 :            :     /*randomize signature*/
+    1794                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1795                 :            :                      libspdm_get_managed_buffer_size(&th_curr), random_buffer);
+    1796                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP
+    1797                 :          1 :     libspdm_requester_data_sign(
+    1798                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    1799                 :            :         spdm_context,
+    1800                 :            : #endif
+    1801                 :          1 :         m_libspdm_finish_request3.header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT, SPDM_FINISH,
+    1802                 :            :             m_libspdm_use_req_asym_algo, m_libspdm_use_hash_algo,
+    1803                 :            :             false, random_buffer, hash_size, ptr, &req_asym_signature_size);
+    1804                 :            : #endif
+    1805                 :          1 :     libspdm_append_managed_buffer(&th_curr, ptr, req_asym_signature_size);
+    1806                 :          1 :     ptr += req_asym_signature_size;
+    1807                 :          1 :     libspdm_set_mem(request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+    1808                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1809                 :            :                      libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1810                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    1811                 :            :                      request_finished_key, hash_size, ptr);
+    1812                 :          1 :     m_libspdm_finish_request3_size = sizeof(spdm_finish_request_t) +
+    1813                 :          1 :                                      req_asym_signature_size + hmac_size;
+    1814                 :          1 :     response_size = sizeof(response);
+    1815                 :          1 :     status = libspdm_get_response_finish(spdm_context,
+    1816                 :            :                                          m_libspdm_finish_request3_size,
+    1817                 :            :                                          &m_libspdm_finish_request3,
+    1818                 :            :                                          &response_size, response);
+    1819                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1820                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1821                 :          1 :     spdm_response = (void *)response;
+    1822                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1823                 :            :                      SPDM_ERROR);
+    1824                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1825                 :            :                      SPDM_ERROR_CODE_DECRYPT_ERROR);
+    1826                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1827                 :          1 :     free(data1);
+    1828                 :          1 :     free(data2);
+    1829                 :          1 : }
+    1830                 :            : 
+    1831                 :            : /**
+    1832                 :            :  * Test 17: receiving a correct FINISH from the requester.
+    1833                 :            :  * Expected behavior: the responder accepts the request and produces a valid FINISH
+    1834                 :            :  * response message, and buffer F receives the exchanged FINISH and FINISH_RSP messages.
+    1835                 :            :  **/
+    1836                 :          1 : void libspdm_test_responder_finish_case17(void **state)
+    1837                 :            : {
+    1838                 :            :     libspdm_return_t status;
+    1839                 :            :     libspdm_test_context_t *spdm_test_context;
+    1840                 :            :     libspdm_context_t *spdm_context;
+    1841                 :            :     size_t response_size;
+    1842                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1843                 :            :     spdm_finish_response_t *spdm_response;
+    1844                 :            :     void *data1;
+    1845                 :            :     size_t data_size1;
+    1846                 :            :     uint8_t *ptr;
+    1847                 :            :     uint8_t *cert_buffer;
+    1848                 :            :     size_t cert_buffer_size;
+    1849                 :            :     uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    1850                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1851                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    1852                 :            :     libspdm_session_info_t *session_info;
+    1853                 :            :     uint32_t session_id;
+    1854                 :            :     uint32_t hash_size;
+    1855                 :            :     uint32_t hmac_size;
+    1856                 :            : 
+    1857                 :          1 :     spdm_test_context = *state;
+    1858                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1859                 :          1 :     spdm_test_context->case_id = 0x11;
+    1860                 :          1 :     spdm_context->connection_info.connection_state =
+    1861                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1862                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1863                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    1864                 :          1 :     spdm_context->local_context.capability.flags |=
+    1865                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    1866                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1867                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1868                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+    1869                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1870                 :            :         m_libspdm_use_measurement_hash_algo;
+    1871                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    1872                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    1873                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1874                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    1875                 :            :                                                     &data_size1, NULL, NULL);
+    1876                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    1877                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
+    1878                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+    1879                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size = data_size1;
+    1880                 :            : 
+    1881                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1882                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+    1883                 :            : 
+    1884                 :          1 :     session_id = 0xFFFFFFFF;
+    1885                 :          1 :     spdm_context->latest_session_id = session_id;
+    1886                 :          1 :     session_info = &spdm_context->session_info[0];
+    1887                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, false);
+    1888                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1889                 :          1 :     libspdm_set_mem(m_dummy_buffer, hash_size, (uint8_t)(0xFF));
+    1890                 :          1 :     libspdm_secured_message_set_request_finished_key(
+    1891                 :            :         session_info->secured_message_context, m_dummy_buffer, hash_size);
+    1892                 :          1 :     libspdm_secured_message_set_session_state(
+    1893                 :            :         session_info->secured_message_context, LIBSPDM_SESSION_STATE_HANDSHAKING);
+    1894                 :            : 
+    1895                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1896                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    1897                 :          1 :     spdm_context->local_context.capability.flags |=
+    1898                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    1899                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1900                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1901                 :          1 :     ptr = m_libspdm_finish_request1.signature;
+    1902                 :          1 :     libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    1903                 :          1 :     cert_buffer = (uint8_t *)data1;
+    1904                 :          1 :     cert_buffer_size = data_size1;
+    1905                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size, cert_buffer_hash);
+    1906                 :            :     /* transcript.message_a size is 0*/
+    1907                 :          1 :     libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    1908                 :            :     /* session_transcript.message_k is 0*/
+    1909                 :          1 :     libspdm_append_managed_buffer(&th_curr, (uint8_t *)&m_libspdm_finish_request1,
+    1910                 :            :                                   sizeof(spdm_finish_request_t));
+    1911                 :          1 :     libspdm_set_mem(request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+    1912                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1913                 :            :                      libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1914                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    1915                 :            :                      request_finished_key, hash_size, ptr);
+    1916                 :          1 :     m_libspdm_finish_request1_size = sizeof(spdm_finish_request_t) + hmac_size;
+    1917                 :          1 :     response_size = sizeof(response);
+    1918                 :          1 :     status = libspdm_get_response_finish(
+    1919                 :            :         spdm_context, m_libspdm_finish_request1_size, &m_libspdm_finish_request1,
+    1920                 :            :         &response_size, response);
+    1921                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1922                 :          1 :     assert_int_equal(response_size, sizeof(spdm_finish_response_t) + hmac_size);
+    1923                 :          1 :     spdm_response = (void *)response;
+    1924                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_FINISH_RSP);
+    1925                 :            : 
+    1926                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1927                 :            :     assert_int_equal(spdm_context->session_info[0].session_transcript.message_f.buffer_size,
+    1928                 :            :                      m_libspdm_finish_request1_size + response_size);
+    1929                 :            :     assert_memory_equal(spdm_context->session_info[0].session_transcript.message_f.buffer,
+    1930                 :            :                         &m_libspdm_finish_request1, m_libspdm_finish_request1_size);
+    1931                 :            :     assert_memory_equal(spdm_context->session_info[0].session_transcript.message_f.buffer +
+    1932                 :            :                         m_libspdm_finish_request1_size,
+    1933                 :            :                         response, response_size);
+    1934                 :            : #endif
+    1935                 :            : 
+    1936                 :          1 :     free(data1);
+    1937                 :          1 : }
+    1938                 :            : 
+    1939                 :            : /**
+    1940                 :            :  * Test 18: receiving a correct FINISH message from the requester with
+    1941                 :            :  * correct MAC and signature (with mutual authentication), and 'handshake in
+    1942                 :            :  * the clear'. The slot_id for requester mutual authentication is 0xFF.
+    1943                 :            :  * Expected behavior: the responder accepts the request and produces a valid
+    1944                 :            :  * FINISH_RSP response message.
+    1945                 :            :  **/
+    1946                 :          1 : void libspdm_test_responder_finish_case18(void **state)
+    1947                 :            : {
+    1948                 :            :     libspdm_return_t status;
+    1949                 :            :     libspdm_test_context_t *spdm_test_context;
+    1950                 :            :     libspdm_context_t *spdm_context;
+    1951                 :            :     size_t response_size;
+    1952                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1953                 :            :     spdm_finish_response_t *spdm_response;
+    1954                 :            :     void *data1;
+    1955                 :            :     size_t data_size1;
+    1956                 :            :     void *data2;
+    1957                 :            :     size_t data_size2;
+    1958                 :            :     uint8_t *ptr;
+    1959                 :            :     uint8_t *cert_buffer;
+    1960                 :            :     size_t cert_buffer_size;
+    1961                 :            :     uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    1962                 :            :     uint8_t req_cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    1963                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1964                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    1965                 :            :     libspdm_session_info_t *session_info;
+    1966                 :            :     uint32_t session_id;
+    1967                 :            :     uint32_t hash_size;
+    1968                 :            :     uint32_t hmac_size;
+    1969                 :            :     size_t req_asym_signature_size;
+    1970                 :            : 
+    1971                 :          1 :     spdm_test_context = *state;
+    1972                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1973                 :          1 :     spdm_test_context->case_id = 0x12;
+    1974                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1975                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1976                 :          1 :     spdm_context->connection_info.connection_state =
+    1977                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1978                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1979                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    1980                 :          1 :     spdm_context->local_context.capability.flags |=
+    1981                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    1982                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1983                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PUB_KEY_ID_CAP;
+    1984                 :          1 :     spdm_context->local_context.capability.flags |=
+    1985                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PUB_KEY_ID_CAP;
+    1986                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1987                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    1988                 :          1 :     spdm_context->local_context.capability.flags |=
+    1989                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    1990                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1991                 :            :         m_libspdm_use_hash_algo;
+    1992                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1993                 :            :         m_libspdm_use_asym_algo;
+    1994                 :          1 :     spdm_context->connection_info.algorithm.req_base_asym_alg =
+    1995                 :            :         m_libspdm_use_req_asym_algo;
+    1996                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1997                 :            :         m_libspdm_use_dhe_algo;
+    1998                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1999                 :            :         m_libspdm_use_aead_algo;
+    2000                 :          1 :     libspdm_read_responder_public_key(m_libspdm_use_asym_algo, &data1, &data_size1);
+    2001                 :          1 :     spdm_context->local_context.local_public_key_provision = data1;
+    2002                 :          1 :     spdm_context->local_context.local_public_key_provision_size = data_size1;
+    2003                 :          1 :     spdm_context->local_context.mut_auth_requested = SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED;
+    2004                 :          1 :     libspdm_read_requester_public_key(m_libspdm_use_req_asym_algo, &data2, &data_size2);
+    2005                 :          1 :     spdm_context->local_context.peer_public_key_provision = data2;
+    2006                 :          1 :     spdm_context->local_context.peer_public_key_provision_size = data_size2;
+    2007                 :            : 
+    2008                 :          1 :     spdm_context->encap_context.req_slot_id = 0xFF;
+    2009                 :          1 :     spdm_context->connection_info.peer_used_cert_chain_slot_id = 0xFF;
+    2010                 :          1 :     spdm_context->connection_info.local_used_cert_chain_slot_id = 0xFF;
+    2011                 :            : 
+    2012                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2013                 :            : 
+    2014                 :          1 :     session_id = 0xFFFFFFFF;
+    2015                 :          1 :     spdm_context->latest_session_id = session_id;
+    2016                 :          1 :     session_info = &spdm_context->session_info[0];
+    2017                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, false);
+    2018                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2019                 :          1 :     libspdm_set_mem(m_dummy_buffer, hash_size, (uint8_t)(0xFF));
+    2020                 :          1 :     libspdm_secured_message_set_request_finished_key(
+    2021                 :            :         session_info->secured_message_context, m_dummy_buffer,
+    2022                 :            :         hash_size);
+    2023                 :          1 :     libspdm_secured_message_set_session_state(
+    2024                 :            :         session_info->secured_message_context,
+    2025                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    2026                 :          1 :     session_info->mut_auth_requested = 1;
+    2027                 :            : 
+    2028                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2029                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2030                 :          1 :     req_asym_signature_size =
+    2031                 :          1 :         libspdm_get_req_asym_signature_size(m_libspdm_use_req_asym_algo);
+    2032                 :          1 :     ptr = m_libspdm_finish_request4.signature;
+    2033                 :          1 :     libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    2034                 :          1 :     cert_buffer = (uint8_t *)data1;
+    2035                 :          1 :     cert_buffer_size = data_size1;
+    2036                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    2037                 :            :                      cert_buffer_hash);
+    2038                 :          1 :     cert_buffer = (uint8_t *)data2;
+    2039                 :          1 :     cert_buffer_size = data_size2;
+    2040                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    2041                 :            :                      req_cert_buffer_hash);
+    2042                 :            :     /* transcript.message_a size is 0*/
+    2043                 :          1 :     libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    2044                 :            :     /* session_transcript.message_k is 0*/
+    2045                 :          1 :     libspdm_append_managed_buffer(&th_curr, req_cert_buffer_hash, hash_size);
+    2046                 :          1 :     libspdm_append_managed_buffer(&th_curr, (uint8_t *)&m_libspdm_finish_request4,
+    2047                 :            :                                   sizeof(spdm_finish_request_t));
+    2048                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP
+    2049                 :          1 :     libspdm_requester_data_sign(
+    2050                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    2051                 :            :         spdm_context,
+    2052                 :            : #endif
+    2053                 :          1 :         m_libspdm_finish_request4.header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
+    2054                 :            :             SPDM_FINISH,
+    2055                 :            :             m_libspdm_use_req_asym_algo, m_libspdm_use_hash_algo,
+    2056                 :          1 :             false, libspdm_get_managed_buffer(&th_curr),
+    2057                 :            :             libspdm_get_managed_buffer_size(&th_curr),
+    2058                 :            :             ptr, &req_asym_signature_size);
+    2059                 :            : #endif
+    2060                 :          1 :     libspdm_append_managed_buffer(&th_curr, ptr, req_asym_signature_size);
+    2061                 :          1 :     ptr += req_asym_signature_size;
+    2062                 :            : 
+    2063                 :          1 :     libspdm_set_mem(request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+    2064                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2065                 :            :                      libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2066                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    2067                 :            :                      request_finished_key, hash_size, ptr);
+    2068                 :          1 :     m_libspdm_finish_request4_size = sizeof(spdm_finish_request_t) +
+    2069                 :          1 :                                      req_asym_signature_size + hmac_size;
+    2070                 :          1 :     response_size = sizeof(response);
+    2071                 :          1 :     status = libspdm_get_response_finish(spdm_context,
+    2072                 :            :                                          m_libspdm_finish_request4_size,
+    2073                 :            :                                          &m_libspdm_finish_request4,
+    2074                 :            :                                          &response_size, response);
+    2075                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2076                 :          1 :     assert_int_equal(response_size,
+    2077                 :            :                      sizeof(spdm_finish_response_t) + hmac_size);
+    2078                 :          1 :     spdm_response = (void *)response;
+    2079                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    2080                 :            :                      SPDM_FINISH_RSP);
+    2081                 :          1 :     free(data1);
+    2082                 :          1 :     free(data2);
+    2083                 :          1 : }
+    2084                 :            : 
+    2085                 :            : /**
+    2086                 :            :  * Test 19: receiving a invalid FINISH request message, enable mutual authentication without using the encapsulated request flow,
+    2087                 :            :  * that is KEY_EXCHANGE_RSP.MutAuthRequested equals 0x01.
+    2088                 :            :  * SlotID in FINISH request message is 10, but it shall be 0xFF or between 0 and 7 inclusive.
+    2089                 :            :  * Expected behavior: generate an ERROR_RESPONSE with code SPDM_ERROR_CODE_INVALID_REQUEST.
+    2090                 :            :  **/
+    2091                 :          1 : void libspdm_test_responder_finish_case19(void **state)
+    2092                 :            : {
+    2093                 :            :     libspdm_return_t status;
+    2094                 :            :     libspdm_test_context_t *spdm_test_context;
+    2095                 :            :     libspdm_context_t *spdm_context;
+    2096                 :            :     size_t response_size;
+    2097                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    2098                 :            :     spdm_finish_response_t *spdm_response;
+    2099                 :            :     void *data1;
+    2100                 :            :     size_t data_size1;
+    2101                 :            :     void *data2;
+    2102                 :            :     size_t data_size2;
+    2103                 :            :     uint8_t *ptr;
+    2104                 :            :     uint8_t *cert_buffer;
+    2105                 :            :     size_t cert_buffer_size;
+    2106                 :            :     uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    2107                 :            :     uint8_t req_cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    2108                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2109                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    2110                 :            :     libspdm_session_info_t *session_info;
+    2111                 :            :     uint32_t session_id;
+    2112                 :            :     uint32_t hash_size;
+    2113                 :            :     uint32_t hmac_size;
+    2114                 :            :     size_t req_asym_signature_size;
+    2115                 :            : 
+    2116                 :          1 :     spdm_test_context = *state;
+    2117                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2118                 :          1 :     spdm_test_context->case_id = 0x13;
+    2119                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    2120                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2121                 :          1 :     spdm_context->connection_info.connection_state =
+    2122                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    2123                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2124                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    2125                 :          1 :     spdm_context->local_context.capability.flags |=
+    2126                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    2127                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    2128                 :            :         m_libspdm_use_hash_algo;
+    2129                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    2130                 :            :         m_libspdm_use_asym_algo;
+    2131                 :          1 :     spdm_context->connection_info.algorithm.req_base_asym_alg =
+    2132                 :            :         m_libspdm_use_req_asym_algo;
+    2133                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    2134                 :            :         m_libspdm_use_measurement_spec;
+    2135                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    2136                 :            :         m_libspdm_use_measurement_hash_algo;
+    2137                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    2138                 :            :         m_libspdm_use_dhe_algo;
+    2139                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    2140                 :            :         m_libspdm_use_aead_algo;
+    2141                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    2142                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    2143                 :            :                                                     &data_size1, NULL, NULL);
+    2144                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    2145                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    2146                 :            :         data_size1;
+    2147                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+    2148                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+    2149                 :            :         data_size1;
+    2150                 :            : 
+    2151                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2152                 :          1 :     spdm_context->local_context.mut_auth_requested = SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED;
+    2153                 :          1 :     libspdm_read_requester_public_certificate_chain(m_libspdm_use_hash_algo,
+    2154                 :            :                                                     m_libspdm_use_req_asym_algo, &data2,
+    2155                 :            :                                                     &data_size2, NULL, NULL);
+    2156                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    2157                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    2158                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    2159                 :            :                      data2, data_size2);
+    2160                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    2161                 :            :         data_size2;
+    2162                 :            : #else
+    2163                 :          1 :     libspdm_hash_all(
+    2164                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    2165                 :            :         data2, data_size2,
+    2166                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    2167                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    2168                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    2169                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    2170                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    2171                 :          1 :         spdm_context->connection_info.algorithm.req_base_asym_alg,
+    2172                 :            :         data2,
+    2173                 :            :         data_size2,
+    2174                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    2175                 :            : #endif
+    2176                 :          1 :     spdm_context->connection_info.peer_used_cert_chain_slot_id = 0;
+    2177                 :            : 
+    2178                 :          1 :     session_id = 0xFFFFFFFF;
+    2179                 :          1 :     spdm_context->latest_session_id = session_id;
+    2180                 :          1 :     session_info = &spdm_context->session_info[0];
+    2181                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, false);
+    2182                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2183                 :          1 :     libspdm_set_mem(m_dummy_buffer, hash_size, (uint8_t)(0xFF));
+    2184                 :          1 :     libspdm_secured_message_set_request_finished_key(
+    2185                 :            :         session_info->secured_message_context, m_dummy_buffer,
+    2186                 :            :         hash_size);
+    2187                 :          1 :     libspdm_secured_message_set_session_state(
+    2188                 :            :         session_info->secured_message_context,
+    2189                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    2190                 :          1 :     session_info->mut_auth_requested = SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED;
+    2191                 :            : 
+    2192                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2193                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    2194                 :          1 :     spdm_context->local_context.capability.flags |=
+    2195                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    2196                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2197                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2198                 :          1 :     req_asym_signature_size =
+    2199                 :          1 :         libspdm_get_req_asym_signature_size(m_libspdm_use_req_asym_algo);
+    2200                 :          1 :     ptr = m_libspdm_finish_request5.signature;
+    2201                 :          1 :     libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    2202                 :          1 :     cert_buffer = (uint8_t *)data1;
+    2203                 :          1 :     cert_buffer_size = data_size1;
+    2204                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    2205                 :            :                      cert_buffer_hash);
+    2206                 :          1 :     cert_buffer = (uint8_t *)data2;
+    2207                 :          1 :     cert_buffer_size = data_size2;
+    2208                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    2209                 :            :                      req_cert_buffer_hash);
+    2210                 :            :     /* transcript.message_a size is 0*/
+    2211                 :          1 :     libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    2212                 :            :     /* session_transcript.message_k is 0*/
+    2213                 :          1 :     libspdm_append_managed_buffer(&th_curr, req_cert_buffer_hash, hash_size);
+    2214                 :          1 :     libspdm_append_managed_buffer(&th_curr, (uint8_t *)&m_libspdm_finish_request5,
+    2215                 :            :                                   sizeof(spdm_finish_request_t));
+    2216                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP
+    2217                 :          1 :     libspdm_requester_data_sign(
+    2218                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    2219                 :            :         spdm_context,
+    2220                 :            : #endif
+    2221                 :          1 :         m_libspdm_finish_request5.header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT, SPDM_FINISH,
+    2222                 :            :             m_libspdm_use_req_asym_algo, m_libspdm_use_hash_algo,
+    2223                 :          1 :             false, libspdm_get_managed_buffer(&th_curr),
+    2224                 :            :             libspdm_get_managed_buffer_size(&th_curr),
+    2225                 :            :             ptr, &req_asym_signature_size);
+    2226                 :            : #endif
+    2227                 :          1 :     libspdm_append_managed_buffer(&th_curr, ptr, req_asym_signature_size);
+    2228                 :          1 :     ptr += req_asym_signature_size;
+    2229                 :          1 :     libspdm_set_mem(request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+    2230                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2231                 :            :                      libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2232                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    2233                 :            :                      request_finished_key, hash_size, ptr);
+    2234                 :          1 :     m_libspdm_finish_request5_size = sizeof(spdm_finish_request_t) +
+    2235                 :          1 :                                      req_asym_signature_size + hmac_size;
+    2236                 :          1 :     response_size = sizeof(response);
+    2237                 :          1 :     status = libspdm_get_response_finish(spdm_context,
+    2238                 :            :                                          m_libspdm_finish_request5_size,
+    2239                 :            :                                          &m_libspdm_finish_request5,
+    2240                 :            :                                          &response_size, response);
+    2241                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2242                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    2243                 :          1 :     spdm_response = (void *)response;
+    2244                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    2245                 :            :                      SPDM_ERROR);
+    2246                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    2247                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+    2248                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    2249                 :          1 :     free(data1);
+    2250                 :          1 :     free(data2);
+    2251                 :          1 : }
+    2252                 :            : 
+    2253                 :            : /**
+    2254                 :            :  * Test 20: receiving a invalid FINISH request message, enable mutual authentication with using the encapsulated request flow,
+    2255                 :            :  * that is KEY_EXCHANGE_RSP.MutAuthRequested equals 0x02.
+    2256                 :            :  * SlotID in FINISH request message is 3, but it shall match the value 0 in final ENCAPSULATED_RESPONSE_ACK.EncapsulatedRequest.
+    2257                 :            :  * Expected behavior: generate an ERROR_RESPONSE with code SPDM_ERROR_CODE_INVALID_REQUEST.
+    2258                 :            :  **/
+    2259                 :          1 : void libspdm_test_responder_finish_case20(void **state)
+    2260                 :            : {
+    2261                 :            :     libspdm_return_t status;
+    2262                 :            :     libspdm_test_context_t *spdm_test_context;
+    2263                 :            :     libspdm_context_t *spdm_context;
+    2264                 :            :     size_t response_size;
+    2265                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    2266                 :            :     spdm_finish_response_t *spdm_response;
+    2267                 :            :     void *data1;
+    2268                 :            :     size_t data_size1;
+    2269                 :            :     void *data2;
+    2270                 :            :     size_t data_size2;
+    2271                 :            :     uint8_t *ptr;
+    2272                 :            :     uint8_t *cert_buffer;
+    2273                 :            :     size_t cert_buffer_size;
+    2274                 :            :     uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    2275                 :            :     uint8_t req_cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    2276                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2277                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    2278                 :            :     libspdm_session_info_t *session_info;
+    2279                 :            :     uint32_t session_id;
+    2280                 :            :     uint32_t hash_size;
+    2281                 :            :     uint32_t hmac_size;
+    2282                 :            :     size_t req_asym_signature_size;
+    2283                 :            : 
+    2284                 :          1 :     spdm_test_context = *state;
+    2285                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2286                 :          1 :     spdm_test_context->case_id = 0x14;
+    2287                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    2288                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2289                 :          1 :     spdm_context->connection_info.connection_state =
+    2290                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    2291                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2292                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    2293                 :          1 :     spdm_context->local_context.capability.flags |=
+    2294                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    2295                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    2296                 :            :         m_libspdm_use_hash_algo;
+    2297                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    2298                 :            :         m_libspdm_use_asym_algo;
+    2299                 :          1 :     spdm_context->connection_info.algorithm.req_base_asym_alg =
+    2300                 :            :         m_libspdm_use_req_asym_algo;
+    2301                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    2302                 :            :         m_libspdm_use_measurement_spec;
+    2303                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    2304                 :            :         m_libspdm_use_measurement_hash_algo;
+    2305                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    2306                 :            :         m_libspdm_use_dhe_algo;
+    2307                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    2308                 :            :         m_libspdm_use_aead_algo;
+    2309                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    2310                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    2311                 :            :                                                     &data_size1, NULL, NULL);
+    2312                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    2313                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    2314                 :            :         data_size1;
+    2315                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+    2316                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+    2317                 :            :         data_size1;
+    2318                 :            : 
+    2319                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2320                 :          1 :     spdm_context->local_context.mut_auth_requested =
+    2321                 :            :         SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_ENCAP_REQUEST;
+    2322                 :          1 :     libspdm_read_requester_public_certificate_chain(m_libspdm_use_hash_algo,
+    2323                 :            :                                                     m_libspdm_use_req_asym_algo, &data2,
+    2324                 :            :                                                     &data_size2, NULL, NULL);
+    2325                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    2326                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    2327                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    2328                 :            :                      data2, data_size2);
+    2329                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    2330                 :            :         data_size2;
+    2331                 :            : #else
+    2332                 :          1 :     libspdm_hash_all(
+    2333                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    2334                 :            :         data2, data_size2,
+    2335                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    2336                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    2337                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    2338                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    2339                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    2340                 :          1 :         spdm_context->connection_info.algorithm.req_base_asym_alg,
+    2341                 :            :         data2,
+    2342                 :            :         data_size2,
+    2343                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    2344                 :            : #endif
+    2345                 :          1 :     spdm_context->connection_info.peer_used_cert_chain_slot_id = 0;
+    2346                 :            : 
+    2347                 :          1 :     session_id = 0xFFFFFFFF;
+    2348                 :          1 :     spdm_context->latest_session_id = session_id;
+    2349                 :          1 :     session_info = &spdm_context->session_info[0];
+    2350                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, false);
+    2351                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2352                 :          1 :     libspdm_set_mem(m_dummy_buffer, hash_size, (uint8_t)(0xFF));
+    2353                 :          1 :     libspdm_secured_message_set_request_finished_key(
+    2354                 :            :         session_info->secured_message_context, m_dummy_buffer,
+    2355                 :            :         hash_size);
+    2356                 :          1 :     libspdm_secured_message_set_session_state(
+    2357                 :            :         session_info->secured_message_context,
+    2358                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    2359                 :          1 :     session_info->mut_auth_requested =
+    2360                 :            :         SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_ENCAP_REQUEST;
+    2361                 :            : 
+    2362                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2363                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    2364                 :          1 :     spdm_context->local_context.capability.flags |=
+    2365                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    2366                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2367                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2368                 :          1 :     req_asym_signature_size =
+    2369                 :          1 :         libspdm_get_req_asym_signature_size(m_libspdm_use_req_asym_algo);
+    2370                 :          1 :     ptr = m_libspdm_finish_request7.signature;
+    2371                 :          1 :     libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    2372                 :          1 :     cert_buffer = (uint8_t *)data1;
+    2373                 :          1 :     cert_buffer_size = data_size1;
+    2374                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    2375                 :            :                      cert_buffer_hash);
+    2376                 :          1 :     cert_buffer = (uint8_t *)data2;
+    2377                 :          1 :     cert_buffer_size = data_size2;
+    2378                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    2379                 :            :                      req_cert_buffer_hash);
+    2380                 :            :     /* transcript.message_a size is 0*/
+    2381                 :          1 :     libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    2382                 :            :     /* session_transcript.message_k is 0*/
+    2383                 :          1 :     libspdm_append_managed_buffer(&th_curr, req_cert_buffer_hash, hash_size);
+    2384                 :          1 :     libspdm_append_managed_buffer(&th_curr, (uint8_t *)&m_libspdm_finish_request7,
+    2385                 :            :                                   sizeof(spdm_finish_request_t));
+    2386                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP
+    2387                 :          1 :     libspdm_requester_data_sign(
+    2388                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    2389                 :            :         spdm_context,
+    2390                 :            : #endif
+    2391                 :          1 :         m_libspdm_finish_request7.header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT, SPDM_FINISH,
+    2392                 :            :             m_libspdm_use_req_asym_algo, m_libspdm_use_hash_algo,
+    2393                 :          1 :             false, libspdm_get_managed_buffer(&th_curr),
+    2394                 :            :             libspdm_get_managed_buffer_size(&th_curr),
+    2395                 :            :             ptr, &req_asym_signature_size);
+    2396                 :            : #endif
+    2397                 :          1 :     libspdm_append_managed_buffer(&th_curr, ptr, req_asym_signature_size);
+    2398                 :          1 :     ptr += req_asym_signature_size;
+    2399                 :          1 :     libspdm_set_mem(request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+    2400                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2401                 :            :                      libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2402                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    2403                 :            :                      request_finished_key, hash_size, ptr);
+    2404                 :          1 :     m_libspdm_finish_request7_size = sizeof(spdm_finish_request_t) +
+    2405                 :          1 :                                      req_asym_signature_size + hmac_size;
+    2406                 :          1 :     response_size = sizeof(response);
+    2407                 :          1 :     status = libspdm_get_response_finish(spdm_context,
+    2408                 :            :                                          m_libspdm_finish_request7_size,
+    2409                 :            :                                          &m_libspdm_finish_request7,
+    2410                 :            :                                          &response_size, response);
+    2411                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2412                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    2413                 :          1 :     spdm_response = (void *)response;
+    2414                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    2415                 :            :                      SPDM_ERROR);
+    2416                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    2417                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+    2418                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    2419                 :          1 :     free(data1);
+    2420                 :          1 :     free(data2);
+    2421                 :          1 : }
+    2422                 :            : 
+    2423                 :            : /**
+    2424                 :            :  * Test 21: receiving a valid FINISH request message, due to disable mutual authentication,
+    2425                 :            :  * although SlotID in FINISH request message is 10, it shall be ignored when read.
+    2426                 :            :  * Expected behavior: the responder accepts the request and produces a valid
+    2427                 :            :  * FINISH_RSP response message.
+    2428                 :            :  **/
+    2429                 :          1 : void libspdm_test_responder_finish_case21(void **state)
+    2430                 :            : {
+    2431                 :            :     libspdm_return_t status;
+    2432                 :            :     libspdm_test_context_t *spdm_test_context;
+    2433                 :            :     libspdm_context_t *spdm_context;
+    2434                 :            :     size_t response_size;
+    2435                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    2436                 :            :     spdm_finish_response_t *spdm_response;
+    2437                 :            :     void *data1;
+    2438                 :            :     size_t data_size1;
+    2439                 :            :     uint8_t *ptr;
+    2440                 :            :     uint8_t *cert_buffer;
+    2441                 :            :     size_t cert_buffer_size;
+    2442                 :            :     uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    2443                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2444                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    2445                 :            :     libspdm_session_info_t *session_info;
+    2446                 :            :     uint32_t session_id;
+    2447                 :            :     uint32_t hash_size;
+    2448                 :            :     uint32_t hmac_size;
+    2449                 :            : 
+    2450                 :          1 :     spdm_test_context = *state;
+    2451                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2452                 :          1 :     spdm_test_context->case_id = 0x15;
+    2453                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    2454                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2455                 :          1 :     spdm_context->connection_info.connection_state =
+    2456                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    2457                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2458                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    2459                 :          1 :     spdm_context->local_context.capability.flags |=
+    2460                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    2461                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    2462                 :            :         m_libspdm_use_hash_algo;
+    2463                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    2464                 :            :         m_libspdm_use_asym_algo;
+    2465                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    2466                 :            :         m_libspdm_use_measurement_spec;
+    2467                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    2468                 :            :         m_libspdm_use_measurement_hash_algo;
+    2469                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    2470                 :            :         m_libspdm_use_dhe_algo;
+    2471                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    2472                 :            :         m_libspdm_use_aead_algo;
+    2473                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    2474                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    2475                 :            :                                                     &data_size1, NULL, NULL);
+    2476                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    2477                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    2478                 :            :         data_size1;
+    2479                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+    2480                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+    2481                 :            :         data_size1;
+    2482                 :            : 
+    2483                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2484                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+    2485                 :            : 
+    2486                 :          1 :     session_id = 0xFFFFFFFF;
+    2487                 :          1 :     spdm_context->latest_session_id = session_id;
+    2488                 :          1 :     session_info = &spdm_context->session_info[0];
+    2489                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, false);
+    2490                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2491                 :          1 :     libspdm_set_mem(m_dummy_buffer, hash_size, (uint8_t)(0xFF));
+    2492                 :          1 :     libspdm_secured_message_set_request_finished_key(
+    2493                 :            :         session_info->secured_message_context, m_dummy_buffer,
+    2494                 :            :         hash_size);
+    2495                 :          1 :     libspdm_secured_message_set_session_state(
+    2496                 :            :         session_info->secured_message_context,
+    2497                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    2498                 :          1 :     session_info->mut_auth_requested = 0;
+    2499                 :            : 
+    2500                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2501                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    2502                 :          1 :     spdm_context->local_context.capability.flags |=
+    2503                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    2504                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2505                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2506                 :          1 :     ptr = m_libspdm_finish_request6.signature;
+    2507                 :          1 :     libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    2508                 :          1 :     cert_buffer = (uint8_t *)data1;
+    2509                 :          1 :     cert_buffer_size = data_size1;
+    2510                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    2511                 :            :                      cert_buffer_hash);
+    2512                 :            :     /* transcript.message_a size is 0*/
+    2513                 :          1 :     libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    2514                 :            :     /* session_transcript.message_k is 0*/
+    2515                 :          1 :     libspdm_append_managed_buffer(&th_curr, (uint8_t *)&m_libspdm_finish_request6,
+    2516                 :            :                                   sizeof(spdm_finish_request_t));
+    2517                 :          1 :     libspdm_set_mem(request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+    2518                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2519                 :            :                      libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2520                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    2521                 :            :                      request_finished_key, hash_size, ptr);
+    2522                 :          1 :     m_libspdm_finish_request6_size = sizeof(spdm_finish_request_t) + hmac_size;
+    2523                 :          1 :     response_size = sizeof(response);
+    2524                 :          1 :     status = libspdm_get_response_finish(spdm_context,
+    2525                 :            :                                          m_libspdm_finish_request6_size,
+    2526                 :            :                                          &m_libspdm_finish_request6,
+    2527                 :            :                                          &response_size, response);
+    2528                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2529                 :          1 :     spdm_response = (void *)response;
+    2530                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    2531                 :            :                      SPDM_FINISH_RSP);
+    2532                 :          1 :     assert_int_equal(response_size,
+    2533                 :            :                      sizeof(spdm_finish_response_t) + hmac_size);
+    2534                 :          1 :     free(data1);
+    2535                 :          1 : }
+    2536                 :            : 
+    2537                 :            : /**
+    2538                 :            :  * Test 22: receiving a valid FINISH request message, enable mutual authentication without using the encapsulated request flow,
+    2539                 :            :  * that is KEY_EXCHANGE_RSP.MutAuthRequested equals 0x01.
+    2540                 :            :  * although SlotID in FINISH request message is 3, it no need match the value 0 in final ENCAPSULATED_RESPONSE_ACK.EncapsulatedRequest.
+    2541                 :            :  * Expected behavior: the responder accepts the request and produces a valid
+    2542                 :            :  * FINISH_RSP response message.
+    2543                 :            :  **/
+    2544                 :          1 : void libspdm_test_responder_finish_case22(void **state)
+    2545                 :            : {
+    2546                 :            :     libspdm_return_t status;
+    2547                 :            :     libspdm_test_context_t *spdm_test_context;
+    2548                 :            :     libspdm_context_t *spdm_context;
+    2549                 :            :     size_t response_size;
+    2550                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    2551                 :            :     spdm_finish_response_t *spdm_response;
+    2552                 :            :     void *data1;
+    2553                 :            :     size_t data_size1;
+    2554                 :            :     void *data2;
+    2555                 :            :     size_t data_size2;
+    2556                 :            :     uint8_t *ptr;
+    2557                 :            :     uint8_t *cert_buffer;
+    2558                 :            :     size_t cert_buffer_size;
+    2559                 :            :     uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    2560                 :            :     uint8_t req_cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    2561                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2562                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    2563                 :            :     libspdm_session_info_t *session_info;
+    2564                 :            :     uint32_t session_id;
+    2565                 :            :     uint32_t hash_size;
+    2566                 :            :     uint32_t hmac_size;
+    2567                 :            :     size_t req_asym_signature_size;
+    2568                 :            : 
+    2569                 :          1 :     spdm_test_context = *state;
+    2570                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2571                 :          1 :     spdm_test_context->case_id = 0x16;
+    2572                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    2573                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2574                 :          1 :     spdm_context->connection_info.connection_state =
+    2575                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    2576                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2577                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    2578                 :          1 :     spdm_context->local_context.capability.flags |=
+    2579                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    2580                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    2581                 :            :         m_libspdm_use_hash_algo;
+    2582                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    2583                 :            :         m_libspdm_use_asym_algo;
+    2584                 :          1 :     spdm_context->connection_info.algorithm.req_base_asym_alg =
+    2585                 :            :         m_libspdm_use_req_asym_algo;
+    2586                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    2587                 :            :         m_libspdm_use_measurement_spec;
+    2588                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    2589                 :            :         m_libspdm_use_measurement_hash_algo;
+    2590                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    2591                 :            :         m_libspdm_use_dhe_algo;
+    2592                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    2593                 :            :         m_libspdm_use_aead_algo;
+    2594                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    2595                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    2596                 :            :                                                     &data_size1, NULL, NULL);
+    2597                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    2598                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    2599                 :            :         data_size1;
+    2600                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+    2601                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+    2602                 :            :         data_size1;
+    2603                 :            : 
+    2604                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2605                 :          1 :     spdm_context->local_context.mut_auth_requested = SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED;
+    2606                 :          1 :     libspdm_read_requester_public_certificate_chain(m_libspdm_use_hash_algo,
+    2607                 :            :                                                     m_libspdm_use_req_asym_algo, &data2,
+    2608                 :            :                                                     &data_size2, NULL, NULL);
+    2609                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    2610                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    2611                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    2612                 :            :                      data2, data_size2);
+    2613                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    2614                 :            :         data_size2;
+    2615                 :            : #else
+    2616                 :          1 :     libspdm_hash_all(
+    2617                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    2618                 :            :         data2, data_size2,
+    2619                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    2620                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    2621                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    2622                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    2623                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    2624                 :          1 :         spdm_context->connection_info.algorithm.req_base_asym_alg,
+    2625                 :            :         data2,
+    2626                 :            :         data_size2,
+    2627                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    2628                 :            : #endif
+    2629                 :          1 :     spdm_context->connection_info.peer_used_cert_chain_slot_id = 0;
+    2630                 :            : 
+    2631                 :          1 :     session_id = 0xFFFFFFFF;
+    2632                 :          1 :     spdm_context->latest_session_id = session_id;
+    2633                 :          1 :     session_info = &spdm_context->session_info[0];
+    2634                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, false);
+    2635                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2636                 :          1 :     libspdm_set_mem(m_dummy_buffer, hash_size, (uint8_t)(0xFF));
+    2637                 :          1 :     libspdm_secured_message_set_request_finished_key(
+    2638                 :            :         session_info->secured_message_context, m_dummy_buffer,
+    2639                 :            :         hash_size);
+    2640                 :          1 :     libspdm_secured_message_set_session_state(
+    2641                 :            :         session_info->secured_message_context,
+    2642                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    2643                 :          1 :     session_info->mut_auth_requested = SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED;
+    2644                 :            : 
+    2645                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2646                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    2647                 :          1 :     spdm_context->local_context.capability.flags |=
+    2648                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    2649                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2650                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2651                 :          1 :     req_asym_signature_size =
+    2652                 :          1 :         libspdm_get_req_asym_signature_size(m_libspdm_use_req_asym_algo);
+    2653                 :          1 :     ptr = m_libspdm_finish_request7.signature;
+    2654                 :          1 :     libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    2655                 :          1 :     cert_buffer = (uint8_t *)data1;
+    2656                 :          1 :     cert_buffer_size = data_size1;
+    2657                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    2658                 :            :                      cert_buffer_hash);
+    2659                 :          1 :     cert_buffer = (uint8_t *)data2;
+    2660                 :          1 :     cert_buffer_size = data_size2;
+    2661                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    2662                 :            :                      req_cert_buffer_hash);
+    2663                 :            :     /* transcript.message_a size is 0*/
+    2664                 :          1 :     libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    2665                 :            :     /* session_transcript.message_k is 0*/
+    2666                 :          1 :     libspdm_append_managed_buffer(&th_curr, req_cert_buffer_hash, hash_size);
+    2667                 :          1 :     libspdm_append_managed_buffer(&th_curr, (uint8_t *)&m_libspdm_finish_request7,
+    2668                 :            :                                   sizeof(spdm_finish_request_t));
+    2669                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP
+    2670                 :          1 :     libspdm_requester_data_sign(
+    2671                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    2672                 :            :         spdm_context,
+    2673                 :            : #endif
+    2674                 :          1 :         m_libspdm_finish_request7.header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT, SPDM_FINISH,
+    2675                 :            :             m_libspdm_use_req_asym_algo, m_libspdm_use_hash_algo,
+    2676                 :          1 :             false, libspdm_get_managed_buffer(&th_curr),
+    2677                 :            :             libspdm_get_managed_buffer_size(&th_curr),
+    2678                 :            :             ptr, &req_asym_signature_size);
+    2679                 :            : #endif
+    2680                 :          1 :     libspdm_append_managed_buffer(&th_curr, ptr, req_asym_signature_size);
+    2681                 :          1 :     ptr += req_asym_signature_size;
+    2682                 :          1 :     libspdm_set_mem(request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+    2683                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2684                 :            :                      libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2685                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    2686                 :            :                      request_finished_key, hash_size, ptr);
+    2687                 :          1 :     m_libspdm_finish_request7_size = sizeof(spdm_finish_request_t) +
+    2688                 :          1 :                                      req_asym_signature_size + hmac_size;
+    2689                 :          1 :     response_size = sizeof(response);
+    2690                 :          1 :     status = libspdm_get_response_finish(spdm_context,
+    2691                 :            :                                          m_libspdm_finish_request7_size,
+    2692                 :            :                                          &m_libspdm_finish_request7,
+    2693                 :            :                                          &response_size, response);
+    2694                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2695                 :          1 :     spdm_response = (void *)response;
+    2696                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    2697                 :            :                      SPDM_FINISH_RSP);
+    2698                 :          1 :     assert_int_equal(response_size,
+    2699                 :            :                      sizeof(spdm_finish_response_t) + hmac_size);
+    2700                 :          1 :     free(data1);
+    2701                 :          1 :     free(data2);
+    2702                 :          1 : }
+    2703                 :            : 
+    2704                 :            : /**
+    2705                 :            :  * Test 23: Same as test case 22 but test signature endianness.
+    2706                 :            :  * Big-Endian Sign. Little-Endian Verify.
+    2707                 :            :  * Expecting signature to fail.
+    2708                 :            :  **/
+    2709                 :          1 : void libspdm_test_responder_finish_case23(void** state)
+    2710                 :            : {
+    2711                 :            :     libspdm_return_t status;
+    2712                 :            :     libspdm_test_context_t* spdm_test_context;
+    2713                 :            :     libspdm_context_t* spdm_context;
+    2714                 :            :     size_t response_size;
+    2715                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    2716                 :            :     spdm_finish_response_t* spdm_response;
+    2717                 :            :     void* data1;
+    2718                 :            :     size_t data_size1;
+    2719                 :            :     void* data2;
+    2720                 :            :     size_t data_size2;
+    2721                 :            :     uint8_t* ptr;
+    2722                 :            :     uint8_t* cert_buffer;
+    2723                 :            :     size_t cert_buffer_size;
+    2724                 :            :     uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    2725                 :            :     uint8_t req_cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    2726                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2727                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    2728                 :            :     libspdm_session_info_t* session_info;
+    2729                 :            :     uint32_t session_id;
+    2730                 :            :     uint32_t hash_size;
+    2731                 :            :     uint32_t hmac_size;
+    2732                 :            :     size_t req_asym_signature_size;
+    2733                 :            : 
+    2734                 :          1 :     spdm_test_context = *state;
+    2735                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2736                 :          1 :     spdm_test_context->case_id = 23;
+    2737                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    2738                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2739                 :          1 :     spdm_context->connection_info.connection_state =
+    2740                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    2741                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2742                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    2743                 :          1 :     spdm_context->local_context.capability.flags |=
+    2744                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    2745                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    2746                 :            :         m_libspdm_use_hash_algo;
+    2747                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    2748                 :            :         m_libspdm_use_asym_algo;
+    2749                 :          1 :     spdm_context->connection_info.algorithm.req_base_asym_alg =
+    2750                 :            :         m_libspdm_use_req_asym_algo;
+    2751                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    2752                 :            :         m_libspdm_use_measurement_spec;
+    2753                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    2754                 :            :         m_libspdm_use_measurement_hash_algo;
+    2755                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    2756                 :            :         m_libspdm_use_dhe_algo;
+    2757                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    2758                 :            :         m_libspdm_use_aead_algo;
+    2759                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    2760                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    2761                 :            :                                                     &data_size1, NULL, NULL);
+    2762                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    2763                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    2764                 :            :         data_size1;
+    2765                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+    2766                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+    2767                 :            :         data_size1;
+    2768                 :          1 :     spdm_context->spdm_10_11_verify_signature_endian =
+    2769                 :            :         LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_LITTLE_ONLY;
+    2770                 :            : 
+    2771                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2772                 :          1 :     spdm_context->local_context.mut_auth_requested = SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED;
+    2773                 :          1 :     libspdm_read_requester_public_certificate_chain(m_libspdm_use_hash_algo,
+    2774                 :            :                                                     m_libspdm_use_req_asym_algo, &data2,
+    2775                 :            :                                                     &data_size2, NULL, NULL);
+    2776                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    2777                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    2778                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    2779                 :            :                      data2, data_size2);
+    2780                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    2781                 :            :         data_size2;
+    2782                 :            : #else
+    2783                 :          1 :     libspdm_hash_all(
+    2784                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    2785                 :            :         data2, data_size2,
+    2786                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    2787                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    2788                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    2789                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    2790                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    2791                 :          1 :         spdm_context->connection_info.algorithm.req_base_asym_alg,
+    2792                 :            :         data2,
+    2793                 :            :         data_size2,
+    2794                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    2795                 :            : #endif
+    2796                 :          1 :     spdm_context->connection_info.peer_used_cert_chain_slot_id = 0;
+    2797                 :            : 
+    2798                 :          1 :     session_id = 0xFFFFFFFF;
+    2799                 :          1 :     spdm_context->latest_session_id = session_id;
+    2800                 :          1 :     session_info = &spdm_context->session_info[0];
+    2801                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, false);
+    2802                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2803                 :          1 :     libspdm_set_mem(m_dummy_buffer, hash_size, (uint8_t)(0xFF));
+    2804                 :          1 :     libspdm_secured_message_set_request_finished_key(
+    2805                 :            :         session_info->secured_message_context, m_dummy_buffer,
+    2806                 :            :         hash_size);
+    2807                 :          1 :     libspdm_secured_message_set_session_state(
+    2808                 :            :         session_info->secured_message_context,
+    2809                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    2810                 :          1 :     session_info->mut_auth_requested = SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED;
+    2811                 :            : 
+    2812                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2813                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    2814                 :          1 :     spdm_context->local_context.capability.flags |=
+    2815                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    2816                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2817                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2818                 :          1 :     req_asym_signature_size =
+    2819                 :          1 :         libspdm_get_req_asym_signature_size(m_libspdm_use_req_asym_algo);
+    2820                 :          1 :     ptr = m_libspdm_finish_request7.signature;
+    2821                 :          1 :     libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    2822                 :          1 :     cert_buffer = (uint8_t*)data1;
+    2823                 :          1 :     cert_buffer_size = data_size1;
+    2824                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    2825                 :            :                      cert_buffer_hash);
+    2826                 :          1 :     cert_buffer = (uint8_t*)data2;
+    2827                 :          1 :     cert_buffer_size = data_size2;
+    2828                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    2829                 :            :                      req_cert_buffer_hash);
+    2830                 :            :     /* transcript.message_a size is 0*/
+    2831                 :          1 :     libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    2832                 :            :     /* session_transcript.message_k is 0*/
+    2833                 :          1 :     libspdm_append_managed_buffer(&th_curr, req_cert_buffer_hash, hash_size);
+    2834                 :          1 :     libspdm_append_managed_buffer(&th_curr, (uint8_t*)&m_libspdm_finish_request7,
+    2835                 :            :                                   sizeof(spdm_finish_request_t));
+    2836                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP
+    2837                 :          1 :     libspdm_requester_data_sign(
+    2838                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    2839                 :            :         spdm_context,
+    2840                 :            : #endif
+    2841                 :          1 :         m_libspdm_finish_request7.header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT, SPDM_FINISH,
+    2842                 :            :             m_libspdm_use_req_asym_algo, m_libspdm_use_hash_algo,
+    2843                 :          1 :             false, libspdm_get_managed_buffer(&th_curr),
+    2844                 :            :             libspdm_get_managed_buffer_size(&th_curr),
+    2845                 :            :             ptr, &req_asym_signature_size);
+    2846                 :            : #endif
+    2847                 :          1 :     libspdm_append_managed_buffer(&th_curr, ptr, req_asym_signature_size);
+    2848                 :          1 :     ptr += req_asym_signature_size;
+    2849                 :          1 :     libspdm_set_mem(request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+    2850                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    2851                 :            :                      libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    2852                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    2853                 :            :                      request_finished_key, hash_size, ptr);
+    2854                 :          1 :     m_libspdm_finish_request7_size = sizeof(spdm_finish_request_t) +
+    2855                 :          1 :                                      req_asym_signature_size + hmac_size;
+    2856                 :          1 :     response_size = sizeof(response);
+    2857                 :          1 :     status = libspdm_get_response_finish(spdm_context,
+    2858                 :            :                                          m_libspdm_finish_request7_size,
+    2859                 :            :                                          &m_libspdm_finish_request7,
+    2860                 :            :                                          &response_size, response);
+    2861                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2862                 :          1 :     spdm_response = (void*)response;
+    2863                 :            : 
+    2864                 :            :     /* Expecting failure on little-endian signature */
+    2865                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
+    2866                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    2867                 :          1 :     free(data1);
+    2868                 :          1 :     free(data2);
+    2869                 :          1 : }
+    2870                 :            : 
+    2871                 :            : /**
+    2872                 :            :  * Test 24: Same as test case 22 but test signature endianness.
+    2873                 :            :  * Big-Endian Sign. Big-Endian Verify.
+    2874                 :            :  * Expecting signature to PASS.
+    2875                 :            :  **/
+    2876                 :          1 : void libspdm_test_responder_finish_case24(void** state)
+    2877                 :            : {
+    2878                 :            :     libspdm_return_t status;
+    2879                 :            :     libspdm_test_context_t* spdm_test_context;
+    2880                 :            :     libspdm_context_t* spdm_context;
+    2881                 :            :     size_t response_size;
+    2882                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    2883                 :            :     spdm_finish_response_t* spdm_response;
+    2884                 :            :     void* data1;
+    2885                 :            :     size_t data_size1;
+    2886                 :            :     void* data2;
+    2887                 :            :     size_t data_size2;
+    2888                 :            :     uint8_t* ptr;
+    2889                 :            :     uint8_t* cert_buffer;
+    2890                 :            :     size_t cert_buffer_size;
+    2891                 :            :     uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    2892                 :            :     uint8_t req_cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    2893                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    2894                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    2895                 :            :     libspdm_session_info_t* session_info;
+    2896                 :            :     uint32_t session_id;
+    2897                 :            :     uint32_t hash_size;
+    2898                 :            :     uint32_t hmac_size;
+    2899                 :            :     size_t req_asym_signature_size;
+    2900                 :            : 
+    2901                 :          1 :     spdm_test_context = *state;
+    2902                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2903                 :          1 :     spdm_test_context->case_id = 24;
+    2904                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    2905                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2906                 :          1 :     spdm_context->connection_info.connection_state =
+    2907                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    2908                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2909                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    2910                 :          1 :     spdm_context->local_context.capability.flags |=
+    2911                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    2912                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    2913                 :            :         m_libspdm_use_hash_algo;
+    2914                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    2915                 :            :         m_libspdm_use_asym_algo;
+    2916                 :          1 :     spdm_context->connection_info.algorithm.req_base_asym_alg =
+    2917                 :            :         m_libspdm_use_req_asym_algo;
+    2918                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    2919                 :            :         m_libspdm_use_measurement_spec;
+    2920                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    2921                 :            :         m_libspdm_use_measurement_hash_algo;
+    2922                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    2923                 :            :         m_libspdm_use_dhe_algo;
+    2924                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    2925                 :            :         m_libspdm_use_aead_algo;
+    2926                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    2927                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    2928                 :            :                                                     &data_size1, NULL, NULL);
+    2929                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    2930                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    2931                 :            :         data_size1;
+    2932                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+    2933                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+    2934                 :            :         data_size1;
+    2935                 :          1 :     spdm_context->spdm_10_11_verify_signature_endian =
+    2936                 :            :         LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_ONLY;
+    2937                 :            : 
+    2938                 :          1 :     libspdm_reset_message_a(spdm_context);
+    2939                 :          1 :     spdm_context->local_context.mut_auth_requested = SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED;
+    2940                 :          1 :     libspdm_read_requester_public_certificate_chain(m_libspdm_use_hash_algo,
+    2941                 :            :                                                     m_libspdm_use_req_asym_algo, &data2,
+    2942                 :            :                                                     &data_size2, NULL, NULL);
+    2943                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    2944                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    2945                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    2946                 :            :                      data2, data_size2);
+    2947                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    2948                 :            :         data_size2;
+    2949                 :            : #else
+    2950                 :          1 :     libspdm_hash_all(
+    2951                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    2952                 :            :         data2, data_size2,
+    2953                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    2954                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    2955                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    2956                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    2957                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    2958                 :          1 :         spdm_context->connection_info.algorithm.req_base_asym_alg,
+    2959                 :            :         data2,
+    2960                 :            :         data_size2,
+    2961                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    2962                 :            : #endif
+    2963                 :          1 :     spdm_context->connection_info.peer_used_cert_chain_slot_id = 0;
+    2964                 :            : 
+    2965                 :          1 :     session_id = 0xFFFFFFFF;
+    2966                 :          1 :     spdm_context->latest_session_id = session_id;
+    2967                 :          1 :     session_info = &spdm_context->session_info[0];
+    2968                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, false);
+    2969                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2970                 :          1 :     libspdm_set_mem(m_dummy_buffer, hash_size, (uint8_t)(0xFF));
+    2971                 :          1 :     libspdm_secured_message_set_request_finished_key(
+    2972                 :            :         session_info->secured_message_context, m_dummy_buffer,
+    2973                 :            :         hash_size);
+    2974                 :          1 :     libspdm_secured_message_set_session_state(
+    2975                 :            :         session_info->secured_message_context,
+    2976                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    2977                 :          1 :     session_info->mut_auth_requested = SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED;
+    2978                 :            : 
+    2979                 :          1 :     spdm_context->connection_info.capability.flags |=
+    2980                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    2981                 :          1 :     spdm_context->local_context.capability.flags |=
+    2982                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    2983                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2984                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    2985                 :          1 :     req_asym_signature_size =
+    2986                 :          1 :         libspdm_get_req_asym_signature_size(m_libspdm_use_req_asym_algo);
+    2987                 :          1 :     ptr = m_libspdm_finish_request7.signature;
+    2988                 :          1 :     libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    2989                 :          1 :     cert_buffer = (uint8_t*)data1;
+    2990                 :          1 :     cert_buffer_size = data_size1;
+    2991                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    2992                 :            :                      cert_buffer_hash);
+    2993                 :          1 :     cert_buffer = (uint8_t*)data2;
+    2994                 :          1 :     cert_buffer_size = data_size2;
+    2995                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    2996                 :            :                      req_cert_buffer_hash);
+    2997                 :            :     /* transcript.message_a size is 0*/
+    2998                 :          1 :     libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    2999                 :            :     /* session_transcript.message_k is 0*/
+    3000                 :          1 :     libspdm_append_managed_buffer(&th_curr, req_cert_buffer_hash, hash_size);
+    3001                 :          1 :     libspdm_append_managed_buffer(&th_curr, (uint8_t*)&m_libspdm_finish_request7,
+    3002                 :            :                                   sizeof(spdm_finish_request_t));
+    3003                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP
+    3004                 :          1 :     libspdm_requester_data_sign(
+    3005                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    3006                 :            :         spdm_context,
+    3007                 :            : #endif
+    3008                 :          1 :         m_libspdm_finish_request7.header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT, SPDM_FINISH,
+    3009                 :            :             m_libspdm_use_req_asym_algo, m_libspdm_use_hash_algo,
+    3010                 :          1 :             false, libspdm_get_managed_buffer(&th_curr),
+    3011                 :            :             libspdm_get_managed_buffer_size(&th_curr),
+    3012                 :            :             ptr, &req_asym_signature_size);
+    3013                 :            : #endif
+    3014                 :          1 :     libspdm_append_managed_buffer(&th_curr, ptr, req_asym_signature_size);
+    3015                 :          1 :     ptr += req_asym_signature_size;
+    3016                 :          1 :     libspdm_set_mem(request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+    3017                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3018                 :            :                      libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    3019                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    3020                 :            :                      request_finished_key, hash_size, ptr);
+    3021                 :          1 :     m_libspdm_finish_request7_size = sizeof(spdm_finish_request_t) +
+    3022                 :          1 :                                      req_asym_signature_size + hmac_size;
+    3023                 :          1 :     response_size = sizeof(response);
+    3024                 :          1 :     status = libspdm_get_response_finish(spdm_context,
+    3025                 :            :                                          m_libspdm_finish_request7_size,
+    3026                 :            :                                          &m_libspdm_finish_request7,
+    3027                 :            :                                          &response_size, response);
+    3028                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    3029                 :          1 :     spdm_response = (void*)response;
+    3030                 :            : 
+    3031                 :            :     /* Expecting pass on big-endian signature */
+    3032                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_FINISH_RSP);
+    3033                 :          1 :     assert_int_equal(response_size, sizeof(spdm_finish_response_t) + hmac_size);
+    3034                 :          1 :     free(data1);
+    3035                 :          1 :     free(data2);
+    3036                 :          1 : }
+    3037                 :            : 
+    3038                 :            : /**
+    3039                 :            :  * Test 25: Same as test case 22, but test signature endianness.
+    3040                 :            :  * Big Endian Sign. Big or Little Endian Verify.
+    3041                 :            :  * Expecting signature to PASS.
+    3042                 :            :  **/
+    3043                 :          1 : void libspdm_test_responder_finish_case25(void** state)
+    3044                 :            : {
+    3045                 :            :     libspdm_return_t status;
+    3046                 :            :     libspdm_test_context_t* spdm_test_context;
+    3047                 :            :     libspdm_context_t* spdm_context;
+    3048                 :            :     size_t response_size;
+    3049                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    3050                 :            :     spdm_finish_response_t* spdm_response;
+    3051                 :            :     void* data1;
+    3052                 :            :     size_t data_size1;
+    3053                 :            :     void* data2;
+    3054                 :            :     size_t data_size2;
+    3055                 :            :     uint8_t* ptr;
+    3056                 :            :     uint8_t* cert_buffer;
+    3057                 :            :     size_t cert_buffer_size;
+    3058                 :            :     uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    3059                 :            :     uint8_t req_cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    3060                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    3061                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    3062                 :            :     libspdm_session_info_t* session_info;
+    3063                 :            :     uint32_t session_id;
+    3064                 :            :     uint32_t hash_size;
+    3065                 :            :     uint32_t hmac_size;
+    3066                 :            :     size_t req_asym_signature_size;
+    3067                 :            : 
+    3068                 :          1 :     spdm_test_context = *state;
+    3069                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    3070                 :          1 :     spdm_test_context->case_id = 25;
+    3071                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    3072                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3073                 :          1 :     spdm_context->connection_info.connection_state =
+    3074                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    3075                 :          1 :     spdm_context->connection_info.capability.flags |=
+    3076                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    3077                 :          1 :     spdm_context->local_context.capability.flags |=
+    3078                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    3079                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    3080                 :            :         m_libspdm_use_hash_algo;
+    3081                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    3082                 :            :         m_libspdm_use_asym_algo;
+    3083                 :          1 :     spdm_context->connection_info.algorithm.req_base_asym_alg =
+    3084                 :            :         m_libspdm_use_req_asym_algo;
+    3085                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    3086                 :            :         m_libspdm_use_measurement_spec;
+    3087                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    3088                 :            :         m_libspdm_use_measurement_hash_algo;
+    3089                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    3090                 :            :         m_libspdm_use_dhe_algo;
+    3091                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    3092                 :            :         m_libspdm_use_aead_algo;
+    3093                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3094                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    3095                 :            :                                                     &data_size1, NULL, NULL);
+    3096                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    3097                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    3098                 :            :         data_size1;
+    3099                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+    3100                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+    3101                 :            :         data_size1;
+    3102                 :          1 :     spdm_context->spdm_10_11_verify_signature_endian =
+    3103                 :            :         LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_OR_LITTLE;
+    3104                 :            : 
+    3105                 :          1 :     libspdm_reset_message_a(spdm_context);
+    3106                 :          1 :     spdm_context->local_context.mut_auth_requested = SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED;
+    3107                 :          1 :     libspdm_read_requester_public_certificate_chain(m_libspdm_use_hash_algo,
+    3108                 :            :                                                     m_libspdm_use_req_asym_algo, &data2,
+    3109                 :            :                                                     &data_size2, NULL, NULL);
+    3110                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    3111                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    3112                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    3113                 :            :                      data2, data_size2);
+    3114                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    3115                 :            :         data_size2;
+    3116                 :            : #else
+    3117                 :          1 :     libspdm_hash_all(
+    3118                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    3119                 :            :         data2, data_size2,
+    3120                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    3121                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    3122                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    3123                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    3124                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    3125                 :          1 :         spdm_context->connection_info.algorithm.req_base_asym_alg,
+    3126                 :            :         data2,
+    3127                 :            :         data_size2,
+    3128                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    3129                 :            : #endif
+    3130                 :          1 :     spdm_context->connection_info.peer_used_cert_chain_slot_id = 0;
+    3131                 :            : 
+    3132                 :          1 :     session_id = 0xFFFFFFFF;
+    3133                 :          1 :     spdm_context->latest_session_id = session_id;
+    3134                 :          1 :     session_info = &spdm_context->session_info[0];
+    3135                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, false);
+    3136                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3137                 :          1 :     libspdm_set_mem(m_dummy_buffer, hash_size, (uint8_t)(0xFF));
+    3138                 :          1 :     libspdm_secured_message_set_request_finished_key(
+    3139                 :            :         session_info->secured_message_context, m_dummy_buffer,
+    3140                 :            :         hash_size);
+    3141                 :          1 :     libspdm_secured_message_set_session_state(
+    3142                 :            :         session_info->secured_message_context,
+    3143                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    3144                 :          1 :     session_info->mut_auth_requested = SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED;
+    3145                 :            : 
+    3146                 :          1 :     spdm_context->connection_info.capability.flags |=
+    3147                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    3148                 :          1 :     spdm_context->local_context.capability.flags |=
+    3149                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    3150                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3151                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3152                 :          1 :     req_asym_signature_size =
+    3153                 :          1 :         libspdm_get_req_asym_signature_size(m_libspdm_use_req_asym_algo);
+    3154                 :          1 :     ptr = m_libspdm_finish_request7.signature;
+    3155                 :          1 :     libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    3156                 :          1 :     cert_buffer = (uint8_t*)data1;
+    3157                 :          1 :     cert_buffer_size = data_size1;
+    3158                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    3159                 :            :                      cert_buffer_hash);
+    3160                 :          1 :     cert_buffer = (uint8_t*)data2;
+    3161                 :          1 :     cert_buffer_size = data_size2;
+    3162                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    3163                 :            :                      req_cert_buffer_hash);
+    3164                 :            :     /* transcript.message_a size is 0*/
+    3165                 :          1 :     libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    3166                 :            :     /* session_transcript.message_k is 0*/
+    3167                 :          1 :     libspdm_append_managed_buffer(&th_curr, req_cert_buffer_hash, hash_size);
+    3168                 :          1 :     libspdm_append_managed_buffer(&th_curr, (uint8_t*)&m_libspdm_finish_request7,
+    3169                 :            :                                   sizeof(spdm_finish_request_t));
+    3170                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP
+    3171                 :          1 :     libspdm_requester_data_sign(
+    3172                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    3173                 :            :         spdm_context,
+    3174                 :            : #endif
+    3175                 :          1 :         m_libspdm_finish_request7.header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT, SPDM_FINISH,
+    3176                 :            :             m_libspdm_use_req_asym_algo, m_libspdm_use_hash_algo,
+    3177                 :          1 :             false, libspdm_get_managed_buffer(&th_curr),
+    3178                 :            :             libspdm_get_managed_buffer_size(&th_curr),
+    3179                 :            :             ptr, &req_asym_signature_size);
+    3180                 :            : #endif
+    3181                 :          1 :     libspdm_append_managed_buffer(&th_curr, ptr, req_asym_signature_size);
+    3182                 :          1 :     ptr += req_asym_signature_size;
+    3183                 :          1 :     libspdm_set_mem(request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+    3184                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3185                 :            :                      libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    3186                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    3187                 :            :                      request_finished_key, hash_size, ptr);
+    3188                 :          1 :     m_libspdm_finish_request7_size = sizeof(spdm_finish_request_t) +
+    3189                 :          1 :                                      req_asym_signature_size + hmac_size;
+    3190                 :          1 :     response_size = sizeof(response);
+    3191                 :          1 :     status = libspdm_get_response_finish(spdm_context,
+    3192                 :            :                                          m_libspdm_finish_request7_size,
+    3193                 :            :                                          &m_libspdm_finish_request7,
+    3194                 :            :                                          &response_size, response);
+    3195                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    3196                 :          1 :     spdm_response = (void*)response;
+    3197                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_FINISH_RSP);
+    3198                 :          1 :     assert_int_equal(response_size, sizeof(spdm_finish_response_t) + hmac_size);
+    3199                 :          1 :     free(data1);
+    3200                 :          1 :     free(data2);
+    3201                 :          1 : }
+    3202                 :            : 
+    3203                 :            : /**
+    3204                 :            :  * Test 26: Same as test case 22, but test endian verification.
+    3205                 :            :  * Sign as Little Endian, Verify as Little.
+    3206                 :            :  * Expecting signature to PASS.
+    3207                 :            :  **/
+    3208                 :          1 : void libspdm_test_responder_finish_case26(void** state)
+    3209                 :            : {
+    3210                 :            :     libspdm_return_t status;
+    3211                 :            :     libspdm_test_context_t* spdm_test_context;
+    3212                 :            :     libspdm_context_t* spdm_context;
+    3213                 :            :     size_t response_size;
+    3214                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    3215                 :            :     spdm_finish_response_t* spdm_response;
+    3216                 :            :     void* data1;
+    3217                 :            :     size_t data_size1;
+    3218                 :            :     void* data2;
+    3219                 :            :     size_t data_size2;
+    3220                 :            :     uint8_t* ptr;
+    3221                 :            :     uint8_t* cert_buffer;
+    3222                 :            :     size_t cert_buffer_size;
+    3223                 :            :     uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    3224                 :            :     uint8_t req_cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    3225                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    3226                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    3227                 :            :     libspdm_session_info_t* session_info;
+    3228                 :            :     uint32_t session_id;
+    3229                 :            :     uint32_t hash_size;
+    3230                 :            :     uint32_t hmac_size;
+    3231                 :            :     size_t req_asym_signature_size;
+    3232                 :            : 
+    3233                 :          1 :     spdm_test_context = *state;
+    3234                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    3235                 :          1 :     spdm_test_context->case_id = 26;
+    3236                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    3237                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3238                 :          1 :     spdm_context->connection_info.connection_state =
+    3239                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    3240                 :          1 :     spdm_context->connection_info.capability.flags |=
+    3241                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    3242                 :          1 :     spdm_context->local_context.capability.flags |=
+    3243                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    3244                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    3245                 :            :         m_libspdm_use_hash_algo;
+    3246                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    3247                 :            :         m_libspdm_use_asym_algo;
+    3248                 :          1 :     spdm_context->connection_info.algorithm.req_base_asym_alg =
+    3249                 :            :         m_libspdm_use_req_asym_algo;
+    3250                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    3251                 :            :         m_libspdm_use_measurement_spec;
+    3252                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    3253                 :            :         m_libspdm_use_measurement_hash_algo;
+    3254                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    3255                 :            :         m_libspdm_use_dhe_algo;
+    3256                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    3257                 :            :         m_libspdm_use_aead_algo;
+    3258                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3259                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    3260                 :            :                                                     &data_size1, NULL, NULL);
+    3261                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    3262                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    3263                 :            :         data_size1;
+    3264                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+    3265                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+    3266                 :            :         data_size1;
+    3267                 :          1 :     spdm_context->spdm_10_11_verify_signature_endian =
+    3268                 :            :         LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_LITTLE_ONLY;
+    3269                 :            : 
+    3270                 :          1 :     libspdm_reset_message_a(spdm_context);
+    3271                 :          1 :     spdm_context->local_context.mut_auth_requested = SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED;
+    3272                 :          1 :     libspdm_read_requester_public_certificate_chain(m_libspdm_use_hash_algo,
+    3273                 :            :                                                     m_libspdm_use_req_asym_algo, &data2,
+    3274                 :            :                                                     &data_size2, NULL, NULL);
+    3275                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    3276                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    3277                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    3278                 :            :                      data2, data_size2);
+    3279                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    3280                 :            :         data_size2;
+    3281                 :            : #else
+    3282                 :          1 :     libspdm_hash_all(
+    3283                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    3284                 :            :         data2, data_size2,
+    3285                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    3286                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    3287                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    3288                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    3289                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    3290                 :          1 :         spdm_context->connection_info.algorithm.req_base_asym_alg,
+    3291                 :            :         data2,
+    3292                 :            :         data_size2,
+    3293                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    3294                 :            : #endif
+    3295                 :          1 :     spdm_context->connection_info.peer_used_cert_chain_slot_id = 0;
+    3296                 :            : 
+    3297                 :          1 :     session_id = 0xFFFFFFFF;
+    3298                 :          1 :     spdm_context->latest_session_id = session_id;
+    3299                 :          1 :     session_info = &spdm_context->session_info[0];
+    3300                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, false);
+    3301                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3302                 :          1 :     libspdm_set_mem(m_dummy_buffer, hash_size, (uint8_t)(0xFF));
+    3303                 :          1 :     libspdm_secured_message_set_request_finished_key(
+    3304                 :            :         session_info->secured_message_context, m_dummy_buffer,
+    3305                 :            :         hash_size);
+    3306                 :          1 :     libspdm_secured_message_set_session_state(
+    3307                 :            :         session_info->secured_message_context,
+    3308                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    3309                 :          1 :     session_info->mut_auth_requested = SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED;
+    3310                 :            : 
+    3311                 :          1 :     spdm_context->connection_info.capability.flags |=
+    3312                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    3313                 :          1 :     spdm_context->local_context.capability.flags |=
+    3314                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    3315                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3316                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3317                 :          1 :     req_asym_signature_size =
+    3318                 :          1 :         libspdm_get_req_asym_signature_size(m_libspdm_use_req_asym_algo);
+    3319                 :          1 :     ptr = m_libspdm_finish_request7.signature;
+    3320                 :          1 :     libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    3321                 :          1 :     cert_buffer = (uint8_t*)data1;
+    3322                 :          1 :     cert_buffer_size = data_size1;
+    3323                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    3324                 :            :                      cert_buffer_hash);
+    3325                 :          1 :     cert_buffer = (uint8_t*)data2;
+    3326                 :          1 :     cert_buffer_size = data_size2;
+    3327                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    3328                 :            :                      req_cert_buffer_hash);
+    3329                 :            :     /* transcript.message_a size is 0*/
+    3330                 :          1 :     libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    3331                 :            :     /* session_transcript.message_k is 0*/
+    3332                 :          1 :     libspdm_append_managed_buffer(&th_curr, req_cert_buffer_hash, hash_size);
+    3333                 :          1 :     libspdm_append_managed_buffer(&th_curr, (uint8_t*)&m_libspdm_finish_request7,
+    3334                 :            :                                   sizeof(spdm_finish_request_t));
+    3335                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP
+    3336                 :          1 :     libspdm_requester_data_sign(
+    3337                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    3338                 :            :         spdm_context,
+    3339                 :            : #endif
+    3340                 :          1 :         m_libspdm_finish_request7.header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT, SPDM_FINISH,
+    3341                 :            :             m_libspdm_use_req_asym_algo, m_libspdm_use_hash_algo,
+    3342                 :          1 :             false, libspdm_get_managed_buffer(&th_curr),
+    3343                 :            :             libspdm_get_managed_buffer_size(&th_curr),
+    3344                 :            :             ptr, &req_asym_signature_size);
+    3345                 :            : 
+    3346                 :            :     /* Switch signature to little endian */
+    3347                 :          1 :     libspdm_copy_signature_swap_endian(
+    3348                 :            :         m_libspdm_use_req_asym_algo,
+    3349                 :            :         ptr, req_asym_signature_size,
+    3350                 :            :         ptr, req_asym_signature_size);
+    3351                 :            : #endif
+    3352                 :          1 :     libspdm_append_managed_buffer(&th_curr, ptr, req_asym_signature_size);
+    3353                 :          1 :     ptr += req_asym_signature_size;
+    3354                 :          1 :     libspdm_set_mem(request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+    3355                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3356                 :            :                      libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    3357                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    3358                 :            :                      request_finished_key, hash_size, ptr);
+    3359                 :          1 :     m_libspdm_finish_request7_size = sizeof(spdm_finish_request_t) +
+    3360                 :          1 :                                      req_asym_signature_size + hmac_size;
+    3361                 :          1 :     response_size = sizeof(response);
+    3362                 :          1 :     status = libspdm_get_response_finish(spdm_context,
+    3363                 :            :                                          m_libspdm_finish_request7_size,
+    3364                 :            :                                          &m_libspdm_finish_request7,
+    3365                 :            :                                          &response_size, response);
+    3366                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    3367                 :          1 :     spdm_response = (void*)response;
+    3368                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_FINISH_RSP);
+    3369                 :          1 :     assert_int_equal(response_size, sizeof(spdm_finish_response_t) + hmac_size);
+    3370                 :          1 :     free(data1);
+    3371                 :          1 :     free(data2);
+    3372                 :          1 : }
+    3373                 :            : 
+    3374                 :            : /**
+    3375                 :            :  * Test 27: Same as test case 22, but test endian verification.
+    3376                 :            :  * Sign as Little Endian, Verify as Big.
+    3377                 :            :  * Expecting signature to FAIL.
+    3378                 :            :  **/
+    3379                 :          1 : void libspdm_test_responder_finish_case27(void** state)
+    3380                 :            : {
+    3381                 :            :     libspdm_return_t status;
+    3382                 :            :     libspdm_test_context_t* spdm_test_context;
+    3383                 :            :     libspdm_context_t* spdm_context;
+    3384                 :            :     size_t response_size;
+    3385                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    3386                 :            :     spdm_finish_response_t* spdm_response;
+    3387                 :            :     void* data1;
+    3388                 :            :     size_t data_size1;
+    3389                 :            :     void* data2;
+    3390                 :            :     size_t data_size2;
+    3391                 :            :     uint8_t* ptr;
+    3392                 :            :     uint8_t* cert_buffer;
+    3393                 :            :     size_t cert_buffer_size;
+    3394                 :            :     uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    3395                 :            :     uint8_t req_cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    3396                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    3397                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    3398                 :            :     libspdm_session_info_t* session_info;
+    3399                 :            :     uint32_t session_id;
+    3400                 :            :     uint32_t hash_size;
+    3401                 :            :     uint32_t hmac_size;
+    3402                 :            :     size_t req_asym_signature_size;
+    3403                 :            : 
+    3404                 :          1 :     spdm_test_context = *state;
+    3405                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    3406                 :          1 :     spdm_test_context->case_id = 27;
+    3407                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    3408                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3409                 :          1 :     spdm_context->connection_info.connection_state =
+    3410                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    3411                 :          1 :     spdm_context->connection_info.capability.flags |=
+    3412                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    3413                 :          1 :     spdm_context->local_context.capability.flags |=
+    3414                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    3415                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    3416                 :            :         m_libspdm_use_hash_algo;
+    3417                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    3418                 :            :         m_libspdm_use_asym_algo;
+    3419                 :          1 :     spdm_context->connection_info.algorithm.req_base_asym_alg =
+    3420                 :            :         m_libspdm_use_req_asym_algo;
+    3421                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    3422                 :            :         m_libspdm_use_measurement_spec;
+    3423                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    3424                 :            :         m_libspdm_use_measurement_hash_algo;
+    3425                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    3426                 :            :         m_libspdm_use_dhe_algo;
+    3427                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    3428                 :            :         m_libspdm_use_aead_algo;
+    3429                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3430                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    3431                 :            :                                                     &data_size1, NULL, NULL);
+    3432                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    3433                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    3434                 :            :         data_size1;
+    3435                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+    3436                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+    3437                 :            :         data_size1;
+    3438                 :          1 :     spdm_context->spdm_10_11_verify_signature_endian =
+    3439                 :            :         LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_ONLY;
+    3440                 :            : 
+    3441                 :          1 :     libspdm_reset_message_a(spdm_context);
+    3442                 :          1 :     spdm_context->local_context.mut_auth_requested = SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED;
+    3443                 :          1 :     libspdm_read_requester_public_certificate_chain(m_libspdm_use_hash_algo,
+    3444                 :            :                                                     m_libspdm_use_req_asym_algo, &data2,
+    3445                 :            :                                                     &data_size2, NULL, NULL);
+    3446                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    3447                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    3448                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    3449                 :            :                      data2, data_size2);
+    3450                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    3451                 :            :         data_size2;
+    3452                 :            : #else
+    3453                 :          1 :     libspdm_hash_all(
+    3454                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    3455                 :            :         data2, data_size2,
+    3456                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    3457                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    3458                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    3459                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    3460                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    3461                 :          1 :         spdm_context->connection_info.algorithm.req_base_asym_alg,
+    3462                 :            :         data2,
+    3463                 :            :         data_size2,
+    3464                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    3465                 :            : #endif
+    3466                 :          1 :     spdm_context->connection_info.peer_used_cert_chain_slot_id = 0;
+    3467                 :            : 
+    3468                 :          1 :     session_id = 0xFFFFFFFF;
+    3469                 :          1 :     spdm_context->latest_session_id = session_id;
+    3470                 :          1 :     session_info = &spdm_context->session_info[0];
+    3471                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, false);
+    3472                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3473                 :          1 :     libspdm_set_mem(m_dummy_buffer, hash_size, (uint8_t)(0xFF));
+    3474                 :          1 :     libspdm_secured_message_set_request_finished_key(
+    3475                 :            :         session_info->secured_message_context, m_dummy_buffer,
+    3476                 :            :         hash_size);
+    3477                 :          1 :     libspdm_secured_message_set_session_state(
+    3478                 :            :         session_info->secured_message_context,
+    3479                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    3480                 :          1 :     session_info->mut_auth_requested = SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED;
+    3481                 :            : 
+    3482                 :          1 :     spdm_context->connection_info.capability.flags |=
+    3483                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    3484                 :          1 :     spdm_context->local_context.capability.flags |=
+    3485                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    3486                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3487                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3488                 :          1 :     req_asym_signature_size =
+    3489                 :          1 :         libspdm_get_req_asym_signature_size(m_libspdm_use_req_asym_algo);
+    3490                 :          1 :     ptr = m_libspdm_finish_request7.signature;
+    3491                 :          1 :     libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    3492                 :          1 :     cert_buffer = (uint8_t*)data1;
+    3493                 :          1 :     cert_buffer_size = data_size1;
+    3494                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    3495                 :            :                      cert_buffer_hash);
+    3496                 :          1 :     cert_buffer = (uint8_t*)data2;
+    3497                 :          1 :     cert_buffer_size = data_size2;
+    3498                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    3499                 :            :                      req_cert_buffer_hash);
+    3500                 :            :     /* transcript.message_a size is 0*/
+    3501                 :          1 :     libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    3502                 :            :     /* session_transcript.message_k is 0*/
+    3503                 :          1 :     libspdm_append_managed_buffer(&th_curr, req_cert_buffer_hash, hash_size);
+    3504                 :          1 :     libspdm_append_managed_buffer(&th_curr, (uint8_t*)&m_libspdm_finish_request7,
+    3505                 :            :                                   sizeof(spdm_finish_request_t));
+    3506                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP
+    3507                 :          1 :     libspdm_requester_data_sign(
+    3508                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    3509                 :            :         spdm_context,
+    3510                 :            : #endif
+    3511                 :          1 :         m_libspdm_finish_request7.header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT, SPDM_FINISH,
+    3512                 :            :             m_libspdm_use_req_asym_algo, m_libspdm_use_hash_algo,
+    3513                 :          1 :             false, libspdm_get_managed_buffer(&th_curr),
+    3514                 :            :             libspdm_get_managed_buffer_size(&th_curr),
+    3515                 :            :             ptr, &req_asym_signature_size);
+    3516                 :            : 
+    3517                 :            :     /* Switch signature to little endian */
+    3518                 :          1 :     libspdm_copy_signature_swap_endian(
+    3519                 :            :         m_libspdm_use_req_asym_algo,
+    3520                 :            :         ptr, req_asym_signature_size,
+    3521                 :            :         ptr, req_asym_signature_size);
+    3522                 :            : #endif
+    3523                 :          1 :     libspdm_append_managed_buffer(&th_curr, ptr, req_asym_signature_size);
+    3524                 :          1 :     ptr += req_asym_signature_size;
+    3525                 :          1 :     libspdm_set_mem(request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+    3526                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3527                 :            :                      libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    3528                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    3529                 :            :                      request_finished_key, hash_size, ptr);
+    3530                 :          1 :     m_libspdm_finish_request7_size = sizeof(spdm_finish_request_t) +
+    3531                 :          1 :                                      req_asym_signature_size + hmac_size;
+    3532                 :          1 :     response_size = sizeof(response);
+    3533                 :          1 :     status = libspdm_get_response_finish(spdm_context,
+    3534                 :            :                                          m_libspdm_finish_request7_size,
+    3535                 :            :                                          &m_libspdm_finish_request7,
+    3536                 :            :                                          &response_size, response);
+    3537                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    3538                 :          1 :     spdm_response = (void*)response;
+    3539                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
+    3540                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    3541                 :          1 :     free(data1);
+    3542                 :          1 :     free(data2);
+    3543                 :          1 : }
+    3544                 :            : 
+    3545                 :            : /**
+    3546                 :            :  * Test 28: Same as test case 22, but test endian verification.
+    3547                 :            :  * Sign as Little Endian, Verify as Big Or Little.
+    3548                 :            :  * Expecting signature to PASS.
+    3549                 :            :  **/
+    3550                 :          1 : void libspdm_test_responder_finish_case28(void** state)
+    3551                 :            : {
+    3552                 :            :     libspdm_return_t status;
+    3553                 :            :     libspdm_test_context_t* spdm_test_context;
+    3554                 :            :     libspdm_context_t* spdm_context;
+    3555                 :            :     size_t response_size;
+    3556                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    3557                 :            :     spdm_finish_response_t* spdm_response;
+    3558                 :            :     void* data1;
+    3559                 :            :     size_t data_size1;
+    3560                 :            :     void* data2;
+    3561                 :            :     size_t data_size2;
+    3562                 :            :     uint8_t* ptr;
+    3563                 :            :     uint8_t* cert_buffer;
+    3564                 :            :     size_t cert_buffer_size;
+    3565                 :            :     uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    3566                 :            :     uint8_t req_cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    3567                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    3568                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    3569                 :            :     libspdm_session_info_t* session_info;
+    3570                 :            :     uint32_t session_id;
+    3571                 :            :     uint32_t hash_size;
+    3572                 :            :     uint32_t hmac_size;
+    3573                 :            :     size_t req_asym_signature_size;
+    3574                 :            : 
+    3575                 :          1 :     spdm_test_context = *state;
+    3576                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    3577                 :          1 :     spdm_test_context->case_id = 28;
+    3578                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    3579                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3580                 :          1 :     spdm_context->connection_info.connection_state =
+    3581                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    3582                 :          1 :     spdm_context->connection_info.capability.flags |=
+    3583                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    3584                 :          1 :     spdm_context->local_context.capability.flags |=
+    3585                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    3586                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    3587                 :            :         m_libspdm_use_hash_algo;
+    3588                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    3589                 :            :         m_libspdm_use_asym_algo;
+    3590                 :          1 :     spdm_context->connection_info.algorithm.req_base_asym_alg =
+    3591                 :            :         m_libspdm_use_req_asym_algo;
+    3592                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    3593                 :            :         m_libspdm_use_measurement_spec;
+    3594                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    3595                 :            :         m_libspdm_use_measurement_hash_algo;
+    3596                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    3597                 :            :         m_libspdm_use_dhe_algo;
+    3598                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    3599                 :            :         m_libspdm_use_aead_algo;
+    3600                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3601                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    3602                 :            :                                                     &data_size1, NULL, NULL);
+    3603                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    3604                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    3605                 :            :         data_size1;
+    3606                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+    3607                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+    3608                 :            :         data_size1;
+    3609                 :          1 :     spdm_context->spdm_10_11_verify_signature_endian =
+    3610                 :            :         LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_LITTLE_ONLY;
+    3611                 :            : 
+    3612                 :          1 :     libspdm_reset_message_a(spdm_context);
+    3613                 :          1 :     spdm_context->local_context.mut_auth_requested = SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED;
+    3614                 :          1 :     libspdm_read_requester_public_certificate_chain(m_libspdm_use_hash_algo,
+    3615                 :            :                                                     m_libspdm_use_req_asym_algo, &data2,
+    3616                 :            :                                                     &data_size2, NULL, NULL);
+    3617                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    3618                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    3619                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    3620                 :            :                      data2, data_size2);
+    3621                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    3622                 :            :         data_size2;
+    3623                 :            : #else
+    3624                 :          1 :     libspdm_hash_all(
+    3625                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    3626                 :            :         data2, data_size2,
+    3627                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    3628                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    3629                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    3630                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    3631                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    3632                 :          1 :         spdm_context->connection_info.algorithm.req_base_asym_alg,
+    3633                 :            :         data2,
+    3634                 :            :         data_size2,
+    3635                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    3636                 :            : #endif
+    3637                 :          1 :     spdm_context->connection_info.peer_used_cert_chain_slot_id = 0;
+    3638                 :            : 
+    3639                 :          1 :     session_id = 0xFFFFFFFF;
+    3640                 :          1 :     spdm_context->latest_session_id = session_id;
+    3641                 :          1 :     session_info = &spdm_context->session_info[0];
+    3642                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, false);
+    3643                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3644                 :          1 :     libspdm_set_mem(m_dummy_buffer, hash_size, (uint8_t)(0xFF));
+    3645                 :          1 :     libspdm_secured_message_set_request_finished_key(
+    3646                 :            :         session_info->secured_message_context, m_dummy_buffer,
+    3647                 :            :         hash_size);
+    3648                 :          1 :     libspdm_secured_message_set_session_state(
+    3649                 :            :         session_info->secured_message_context,
+    3650                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    3651                 :          1 :     session_info->mut_auth_requested = SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED;
+    3652                 :            : 
+    3653                 :          1 :     spdm_context->connection_info.capability.flags |=
+    3654                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    3655                 :          1 :     spdm_context->local_context.capability.flags |=
+    3656                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    3657                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3658                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3659                 :          1 :     req_asym_signature_size =
+    3660                 :          1 :         libspdm_get_req_asym_signature_size(m_libspdm_use_req_asym_algo);
+    3661                 :          1 :     ptr = m_libspdm_finish_request7.signature;
+    3662                 :          1 :     libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    3663                 :          1 :     cert_buffer = (uint8_t*)data1;
+    3664                 :          1 :     cert_buffer_size = data_size1;
+    3665                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    3666                 :            :                      cert_buffer_hash);
+    3667                 :          1 :     cert_buffer = (uint8_t*)data2;
+    3668                 :          1 :     cert_buffer_size = data_size2;
+    3669                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    3670                 :            :                      req_cert_buffer_hash);
+    3671                 :            :     /* transcript.message_a size is 0*/
+    3672                 :          1 :     libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    3673                 :            :     /* session_transcript.message_k is 0*/
+    3674                 :          1 :     libspdm_append_managed_buffer(&th_curr, req_cert_buffer_hash, hash_size);
+    3675                 :          1 :     libspdm_append_managed_buffer(&th_curr, (uint8_t*)&m_libspdm_finish_request7,
+    3676                 :            :                                   sizeof(spdm_finish_request_t));
+    3677                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP
+    3678                 :          1 :     libspdm_requester_data_sign(
+    3679                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    3680                 :            :         spdm_context,
+    3681                 :            : #endif
+    3682                 :          1 :         m_libspdm_finish_request7.header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT, SPDM_FINISH,
+    3683                 :            :             m_libspdm_use_req_asym_algo, m_libspdm_use_hash_algo,
+    3684                 :          1 :             false, libspdm_get_managed_buffer(&th_curr),
+    3685                 :            :             libspdm_get_managed_buffer_size(&th_curr),
+    3686                 :            :             ptr, &req_asym_signature_size);
+    3687                 :            : 
+    3688                 :            :     /* Switch signature to little endian */
+    3689                 :          1 :     libspdm_copy_signature_swap_endian(
+    3690                 :            :         m_libspdm_use_req_asym_algo,
+    3691                 :            :         ptr, req_asym_signature_size,
+    3692                 :            :         ptr, req_asym_signature_size);
+    3693                 :            : #endif
+    3694                 :          1 :     libspdm_append_managed_buffer(&th_curr, ptr, req_asym_signature_size);
+    3695                 :          1 :     ptr += req_asym_signature_size;
+    3696                 :          1 :     libspdm_set_mem(request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+    3697                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3698                 :            :                      libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    3699                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    3700                 :            :                      request_finished_key, hash_size, ptr);
+    3701                 :          1 :     m_libspdm_finish_request7_size = sizeof(spdm_finish_request_t) +
+    3702                 :          1 :                                      req_asym_signature_size + hmac_size;
+    3703                 :          1 :     response_size = sizeof(response);
+    3704                 :          1 :     status = libspdm_get_response_finish(spdm_context,
+    3705                 :            :                                          m_libspdm_finish_request7_size,
+    3706                 :            :                                          &m_libspdm_finish_request7,
+    3707                 :            :                                          &response_size, response);
+    3708                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    3709                 :          1 :     spdm_response = (void*)response;
+    3710                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_FINISH_RSP);
+    3711                 :          1 :     assert_int_equal(response_size, sizeof(spdm_finish_response_t) + hmac_size);
+    3712                 :          1 :     free(data1);
+    3713                 :          1 :     free(data2);
+    3714                 :          1 : }
+    3715                 :            : 
+    3716                 :            : /**
+    3717                 :            :  * Test 29: Receive the correct FINISH from the requester, and
+    3718                 :            :  * the requester and responder have not set HANDSHAKE_IN_THE_CLEAR.
+    3719                 :            :  * Expected behavior: the responder accepts the request and produces a valid
+    3720                 :            :  * FINISH_RSP response message, and The ResponderVerifyData field is absent.
+    3721                 :            :  **/
+    3722                 :          1 : void libspdm_test_responder_finish_case29(void **state)
+    3723                 :            : {
+    3724                 :            :     libspdm_return_t status;
+    3725                 :            :     libspdm_test_context_t *spdm_test_context;
+    3726                 :            :     libspdm_context_t *spdm_context;
+    3727                 :            :     size_t response_size;
+    3728                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    3729                 :            :     spdm_finish_response_t *spdm_response;
+    3730                 :            :     void *data1;
+    3731                 :            :     size_t data_size1;
+    3732                 :            :     uint8_t *ptr;
+    3733                 :            :     uint8_t *cert_buffer;
+    3734                 :            :     size_t cert_buffer_size;
+    3735                 :            :     uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+    3736                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    3737                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    3738                 :            :     libspdm_session_info_t *session_info;
+    3739                 :            :     uint32_t session_id;
+    3740                 :            :     uint32_t hash_size;
+    3741                 :            :     uint32_t hmac_size;
+    3742                 :            : 
+    3743                 :          1 :     spdm_test_context = *state;
+    3744                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    3745                 :          1 :     spdm_test_context->case_id = 29;
+    3746                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    3747                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    3748                 :          1 :     spdm_context->connection_info.connection_state =
+    3749                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    3750                 :          1 :     spdm_context->connection_info.capability.flags |=
+    3751                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    3752                 :          1 :     spdm_context->local_context.capability.flags |=
+    3753                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    3754                 :            : 
+    3755                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    3756                 :            :         m_libspdm_use_hash_algo;
+    3757                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    3758                 :            :         m_libspdm_use_asym_algo;
+    3759                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    3760                 :            :         m_libspdm_use_measurement_spec;
+    3761                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    3762                 :            :         m_libspdm_use_measurement_hash_algo;
+    3763                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    3764                 :            :         m_libspdm_use_dhe_algo;
+    3765                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    3766                 :            :         m_libspdm_use_aead_algo;
+    3767                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    3768                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    3769                 :            :                                                     &data_size1, NULL, NULL);
+    3770                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    3771                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    3772                 :            :         data_size1;
+    3773                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+    3774                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+    3775                 :            :         data_size1;
+    3776                 :            : 
+    3777                 :          1 :     libspdm_reset_message_a(spdm_context);
+    3778                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+    3779                 :            : 
+    3780                 :            :     /* The requester and responder have not set HANDSHAKE_IN_THE_CLEAR*/
+    3781                 :          1 :     spdm_context->connection_info.capability.flags &=
+    3782                 :            :         ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    3783                 :          1 :     spdm_context->local_context.capability.flags &=
+    3784                 :            :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    3785                 :            : 
+    3786                 :          1 :     session_id = 0xFFFFFFFF;
+    3787                 :          1 :     spdm_context->latest_session_id = session_id;
+    3788                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+    3789                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+    3790                 :          1 :     session_info = &spdm_context->session_info[0];
+    3791                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, false);
+    3792                 :            : 
+    3793                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3794                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3795                 :            : 
+    3796                 :          1 :     libspdm_set_mem(m_dummy_buffer, hash_size, (uint8_t)(0xFF));
+    3797                 :          1 :     libspdm_secured_message_set_request_finished_key(
+    3798                 :            :         session_info->secured_message_context, m_dummy_buffer,
+    3799                 :            :         hash_size);
+    3800                 :          1 :     libspdm_secured_message_set_session_state(
+    3801                 :            :         session_info->secured_message_context,
+    3802                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    3803                 :            : 
+    3804                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    3805                 :          1 :     ptr = m_libspdm_finish_request1.signature;
+    3806                 :          1 :     libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    3807                 :          1 :     cert_buffer = (uint8_t *)data1;
+    3808                 :          1 :     cert_buffer_size = data_size1;
+    3809                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
+    3810                 :            :                      cert_buffer_hash);
+    3811                 :            :     /* transcript.message_a size is 0*/
+    3812                 :          1 :     libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
+    3813                 :            :     /* session_transcript.message_k is 0*/
+    3814                 :          1 :     libspdm_append_managed_buffer(&th_curr, (uint8_t *)&m_libspdm_finish_request1,
+    3815                 :            :                                   sizeof(spdm_finish_request_t));
+    3816                 :          1 :     libspdm_set_mem(request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+    3817                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    3818                 :            :                      libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    3819                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    3820                 :            :                      request_finished_key, hash_size, ptr);
+    3821                 :          1 :     m_libspdm_finish_request1_size = sizeof(spdm_finish_request_t) + hmac_size;
+    3822                 :          1 :     response_size = sizeof(response);
+    3823                 :          1 :     status = libspdm_get_response_finish(spdm_context,
+    3824                 :            :                                          m_libspdm_finish_request1_size,
+    3825                 :            :                                          &m_libspdm_finish_request1,
+    3826                 :            :                                          &response_size, response);
+    3827                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    3828                 :            :     /* The ResponderVerifyData field shall be absent.*/
+    3829                 :          1 :     assert_int_equal(response_size,
+    3830                 :            :                      sizeof(spdm_finish_response_t));
+    3831                 :          1 :     spdm_response = (void *)response;
+    3832                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    3833                 :            :                      SPDM_FINISH_RSP);
+    3834                 :          1 :     free(data1);
+    3835                 :          1 : }
+    3836                 :            : 
+    3837                 :            : libspdm_test_context_t m_libspdm_responder_finish_test_context = {
+    3838                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+    3839                 :            :     false,
+    3840                 :            : };
+    3841                 :            : 
+    3842                 :          1 : int libspdm_responder_finish_test_main(void)
+    3843                 :            : {
+    3844                 :          1 :     const struct CMUnitTest spdm_responder_finish_tests[] = {
+    3845                 :            :         /* Success Case*/
+    3846                 :            :         cmocka_unit_test(libspdm_test_responder_finish_case1),
+    3847                 :            :         /* Can be populated with new test.*/
+    3848                 :            :         cmocka_unit_test(libspdm_test_responder_finish_case2),
+    3849                 :            :         /* response_state: SPDM_RESPONSE_STATE_BUSY*/
+    3850                 :            :         cmocka_unit_test(libspdm_test_responder_finish_case3),
+    3851                 :            :         /* response_state: SPDM_RESPONSE_STATE_NEED_RESYNC*/
+    3852                 :            :         cmocka_unit_test(libspdm_test_responder_finish_case4),
+    3853                 :            :         #if LIBSPDM_RESPOND_IF_READY_SUPPORT
+    3854                 :            :         /* response_state: LIBSPDM_RESPONSE_STATE_NOT_READY*/
+    3855                 :            :         cmocka_unit_test(libspdm_test_responder_finish_case5),
+    3856                 :            :         #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
+    3857                 :            :         /* connection_state Check*/
+    3858                 :            :         cmocka_unit_test(libspdm_test_responder_finish_case6),
+    3859                 :            :         /* Buffer reset*/
+    3860                 :            :         cmocka_unit_test(libspdm_test_responder_finish_case7),
+    3861                 :            :         /* Success Case*/
+    3862                 :            :         cmocka_unit_test(libspdm_test_responder_finish_case8),
+    3863                 :            :         /* Unsupported KEY_EX capabilities*/
+    3864                 :            :         cmocka_unit_test(libspdm_test_responder_finish_case9),
+    3865                 :            :         /* Uninitialized session*/
+    3866                 :            :         cmocka_unit_test(libspdm_test_responder_finish_case10),
+    3867                 :            :         /* Incorrect MAC*/
+    3868                 :            :         cmocka_unit_test(libspdm_test_responder_finish_case11),
+    3869                 :            :         cmocka_unit_test(libspdm_test_responder_finish_case12),
+    3870                 :            :         /* Can be populated with new test.*/
+    3871                 :            :         cmocka_unit_test(libspdm_test_responder_finish_case13),
+    3872                 :            :         cmocka_unit_test(libspdm_test_responder_finish_case14),
+    3873                 :            :         /* Incorrect signature*/
+    3874                 :            :         cmocka_unit_test(libspdm_test_responder_finish_case15),
+    3875                 :            :         cmocka_unit_test(libspdm_test_responder_finish_case16),
+    3876                 :            :         /* Buffer verification*/
+    3877                 :            :         cmocka_unit_test(libspdm_test_responder_finish_case17),
+    3878                 :            :         /* Success Case, enable mutual authentication and use slot_id 0xFF */
+    3879                 :            :         cmocka_unit_test(libspdm_test_responder_finish_case18),
+    3880                 :            :         /* Invalid SlotID in FINISH request message when mutual authentication */
+    3881                 :            :         cmocka_unit_test_setup(libspdm_test_responder_finish_case19, libspdm_unit_test_group_setup),
+    3882                 :            :         cmocka_unit_test_setup(libspdm_test_responder_finish_case20, libspdm_unit_test_group_setup),
+    3883                 :            :         /* If FINISH.Param1 != 0x01, then FINISH.Param2 is reserved, shall be ignored when read */
+    3884                 :            :         cmocka_unit_test_setup(libspdm_test_responder_finish_case21, libspdm_unit_test_group_setup),
+    3885                 :            :         /* If KEY_EXCHANGE_RSP.MutAuthRequested equals neither 0x02 nor 0x04, FINISH.Param2 no need match ENCAPSULATED_RESPONSE_ACK.EncapsulatedRequest */
+    3886                 :            :         cmocka_unit_test_setup(libspdm_test_responder_finish_case22, libspdm_unit_test_group_setup),
+    3887                 :            :         /* Big Endian Sign - Little Endian Verify */
+    3888                 :            :         cmocka_unit_test_setup(libspdm_test_responder_finish_case23, libspdm_unit_test_group_setup),
+    3889                 :            :         /* Big Endian Sign - Big Endian Verify */
+    3890                 :            :         cmocka_unit_test_setup(libspdm_test_responder_finish_case24, libspdm_unit_test_group_setup),
+    3891                 :            :         /* Big Endian Sign - Big or Little Endian Verify */
+    3892                 :            :         cmocka_unit_test_setup(libspdm_test_responder_finish_case25, libspdm_unit_test_group_setup),
+    3893                 :            :         /* Little Endian Sign - Little Endian Verify*/
+    3894                 :            :         cmocka_unit_test_setup(libspdm_test_responder_finish_case26, libspdm_unit_test_group_setup),
+    3895                 :            :         /* Little Endian Sign - Big Endian Verify */
+    3896                 :            :         cmocka_unit_test_setup(libspdm_test_responder_finish_case27, libspdm_unit_test_group_setup),
+    3897                 :            :         /* Little Endian Sign - Big or Little Endian Verify */
+    3898                 :            :         cmocka_unit_test_setup(libspdm_test_responder_finish_case28, libspdm_unit_test_group_setup),
+    3899                 :            :         /* The requester and responder have not set HANDSHAKE_IN_THE_CLEAR*/
+    3900                 :            :         cmocka_unit_test(libspdm_test_responder_finish_case29),
+    3901                 :            :     };
+    3902                 :            : 
+    3903                 :          1 :     libspdm_setup_test_context(&m_libspdm_responder_finish_test_context);
+    3904                 :            : 
+    3905                 :          1 :     return cmocka_run_group_tests(spdm_responder_finish_tests,
+    3906                 :            :                                   libspdm_unit_test_group_setup,
+    3907                 :            :                                   libspdm_unit_test_group_teardown);
+    3908                 :            : }
+    3909                 :            : 
+    3910                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/heartbeat.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_responder/heartbeat.c.func-sort-c.html new file mode 100644 index 00000000000..be4707a265b --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/heartbeat.c.func-sort-c.html @@ -0,0 +1,117 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/heartbeat.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - heartbeat.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:310310100.0 %
Date:2024-09-22 08:21:07Functions:99100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_heartbeat_test_main1
libspdm_test_responder_heartbeat_case11
libspdm_test_responder_heartbeat_case21
libspdm_test_responder_heartbeat_case31
libspdm_test_responder_heartbeat_case41
libspdm_test_responder_heartbeat_case51
libspdm_test_responder_heartbeat_case61
libspdm_test_responder_heartbeat_case71
libspdm_test_responder_heartbeat_case81
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/heartbeat.c.func.html b/coverage_log/unit_test/test_spdm_responder/heartbeat.c.func.html new file mode 100644 index 00000000000..590d001204a --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/heartbeat.c.func.html @@ -0,0 +1,117 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/heartbeat.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - heartbeat.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:310310100.0 %
Date:2024-09-22 08:21:07Functions:99100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_heartbeat_test_main1
libspdm_test_responder_heartbeat_case11
libspdm_test_responder_heartbeat_case21
libspdm_test_responder_heartbeat_case31
libspdm_test_responder_heartbeat_case41
libspdm_test_responder_heartbeat_case51
libspdm_test_responder_heartbeat_case61
libspdm_test_responder_heartbeat_case71
libspdm_test_responder_heartbeat_case81
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/heartbeat.c.gcov.html b/coverage_log/unit_test/test_spdm_responder/heartbeat.c.gcov.html new file mode 100644 index 00000000000..d85f601c6b5 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/heartbeat.c.gcov.html @@ -0,0 +1,747 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/heartbeat.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - heartbeat.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:310310100.0 %
Date:2024-09-22 08:21:07Functions:99100.0 %
Branches:00-
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_responder_lib.h"
+       9                 :            : #include "internal/libspdm_secured_message_lib.h"
+      10                 :            : 
+      11                 :            : #if (LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP) || (LIBSPDM_ENABLE_CAPABILITY_PSK_CAP)
+      12                 :            : 
+      13                 :            : spdm_heartbeat_request_t m_libspdm_heartbeat_request1 = {
+      14                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_HEARTBEAT, 0, 0 }
+      15                 :            : };
+      16                 :            : size_t m_libspdm_heartbeat_request1_size = sizeof(m_libspdm_heartbeat_request1);
+      17                 :            : 
+      18                 :            : spdm_heartbeat_request_t m_libspdm_heartbeat_request2 = {
+      19                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_HEARTBEAT, 0, 0 }
+      20                 :            : };
+      21                 :            : size_t m_libspdm_heartbeat_request2_size = LIBSPDM_MAX_SPDM_MSG_SIZE;
+      22                 :            : 
+      23                 :            : 
+      24                 :          1 : void libspdm_test_responder_heartbeat_case1(void **state)
+      25                 :            : {
+      26                 :            :     libspdm_return_t status;
+      27                 :            :     libspdm_test_context_t *spdm_test_context;
+      28                 :            :     libspdm_context_t *spdm_context;
+      29                 :            :     size_t response_size;
+      30                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+      31                 :            :     spdm_heartbeat_response_t *spdm_response;
+      32                 :            :     void *data1;
+      33                 :            :     size_t data_size1;
+      34                 :            :     libspdm_session_info_t *session_info;
+      35                 :            :     uint32_t session_id;
+      36                 :            : 
+      37                 :          1 :     spdm_test_context = *state;
+      38                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+      39                 :          1 :     spdm_test_context->case_id = 0x1;
+      40                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+      41                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+      42                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+      43                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP;
+      44                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP;
+      45                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+      46                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+      47                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+      48                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+      49                 :            :         m_libspdm_use_measurement_hash_algo;
+      50                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+      51                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+      52                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+      53                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+      54                 :            :                                                     &data_size1, NULL, NULL);
+      55                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+      56                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
+      57                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+      58                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size = data_size1;
+      59                 :            : 
+      60                 :          1 :     libspdm_reset_message_a(spdm_context);
+      61                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+      62                 :            : 
+      63                 :          1 :     session_id = 0xFFFFFFFF;
+      64                 :          1 :     spdm_context->latest_session_id = session_id;
+      65                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+      66                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+      67                 :          1 :     session_info = &spdm_context->session_info[0];
+      68                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+      69                 :          1 :     libspdm_secured_message_set_session_state(
+      70                 :            :         session_info->secured_message_context,
+      71                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+      72                 :          1 :     session_info->heartbeat_period = 1;
+      73                 :            : 
+      74                 :          1 :     response_size = sizeof(response);
+      75                 :          1 :     status = libspdm_get_response_heartbeat(spdm_context,
+      76                 :            :                                             m_libspdm_heartbeat_request1_size,
+      77                 :            :                                             &m_libspdm_heartbeat_request1,
+      78                 :            :                                             &response_size, response);
+      79                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+      80                 :          1 :     assert_int_equal(response_size, sizeof(spdm_heartbeat_response_t));
+      81                 :          1 :     spdm_response = (void *)response;
+      82                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_HEARTBEAT_ACK);
+      83                 :          1 :     free(data1);
+      84                 :          1 : }
+      85                 :            : 
+      86                 :          1 : void libspdm_test_responder_heartbeat_case2(void **state)
+      87                 :            : {
+      88                 :            :     libspdm_return_t status;
+      89                 :            :     libspdm_test_context_t *spdm_test_context;
+      90                 :            :     libspdm_context_t *spdm_context;
+      91                 :            :     size_t response_size;
+      92                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+      93                 :            :     spdm_heartbeat_response_t *spdm_response;
+      94                 :            :     void *data1;
+      95                 :            :     size_t data_size1;
+      96                 :            :     libspdm_session_info_t *session_info;
+      97                 :            :     uint32_t session_id;
+      98                 :            : 
+      99                 :          1 :     spdm_test_context = *state;
+     100                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     101                 :          1 :     spdm_test_context->case_id = 0x2;
+     102                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     103                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     104                 :          1 :     spdm_context->connection_info.connection_state =
+     105                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     106                 :          1 :     spdm_context->connection_info.capability.flags |=
+     107                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP;
+     108                 :          1 :     spdm_context->local_context.capability.flags |=
+     109                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP;
+     110                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     111                 :            :         m_libspdm_use_hash_algo;
+     112                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     113                 :            :         m_libspdm_use_asym_algo;
+     114                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     115                 :            :         m_libspdm_use_measurement_spec;
+     116                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     117                 :            :         m_libspdm_use_measurement_hash_algo;
+     118                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     119                 :            :         m_libspdm_use_dhe_algo;
+     120                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     121                 :            :         m_libspdm_use_aead_algo;
+     122                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     123                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     124                 :            :                                                     &data_size1, NULL, NULL);
+     125                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     126                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     127                 :            :         data_size1;
+     128                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+     129                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+     130                 :            :         data_size1;
+     131                 :            : 
+     132                 :          1 :     libspdm_reset_message_a(spdm_context);
+     133                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     134                 :            : 
+     135                 :          1 :     session_id = 0xFFFFFFFF;
+     136                 :          1 :     spdm_context->latest_session_id = session_id;
+     137                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+     138                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+     139                 :          1 :     session_info = &spdm_context->session_info[0];
+     140                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+     141                 :          1 :     libspdm_secured_message_set_session_state(
+     142                 :            :         session_info->secured_message_context,
+     143                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+     144                 :            : 
+     145                 :          1 :     response_size = sizeof(response);
+     146                 :          1 :     status = libspdm_get_response_heartbeat(spdm_context,
+     147                 :            :                                             m_libspdm_heartbeat_request2_size,
+     148                 :            :                                             &m_libspdm_heartbeat_request2,
+     149                 :            :                                             &response_size, response);
+     150                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     151                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     152                 :          1 :     spdm_response = (void *)response;
+     153                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     154                 :            :                      SPDM_ERROR);
+     155                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     156                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+     157                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     158                 :          1 :     free(data1);
+     159                 :          1 : }
+     160                 :            : 
+     161                 :          1 : void libspdm_test_responder_heartbeat_case3(void **state)
+     162                 :            : {
+     163                 :            :     libspdm_return_t status;
+     164                 :            :     libspdm_test_context_t *spdm_test_context;
+     165                 :            :     libspdm_context_t *spdm_context;
+     166                 :            :     size_t response_size;
+     167                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     168                 :            :     spdm_heartbeat_response_t *spdm_response;
+     169                 :            :     void *data1;
+     170                 :            :     size_t data_size1;
+     171                 :            :     libspdm_session_info_t *session_info;
+     172                 :            :     uint32_t session_id;
+     173                 :            : 
+     174                 :          1 :     spdm_test_context = *state;
+     175                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     176                 :          1 :     spdm_test_context->case_id = 0x3;
+     177                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     178                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     179                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_BUSY;
+     180                 :          1 :     spdm_context->connection_info.connection_state =
+     181                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     182                 :          1 :     spdm_context->connection_info.capability.flags |=
+     183                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP;
+     184                 :          1 :     spdm_context->local_context.capability.flags |=
+     185                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP;
+     186                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     187                 :            :         m_libspdm_use_hash_algo;
+     188                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     189                 :            :         m_libspdm_use_asym_algo;
+     190                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     191                 :            :         m_libspdm_use_measurement_spec;
+     192                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     193                 :            :         m_libspdm_use_measurement_hash_algo;
+     194                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     195                 :            :         m_libspdm_use_dhe_algo;
+     196                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     197                 :            :         m_libspdm_use_aead_algo;
+     198                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     199                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     200                 :            :                                                     &data_size1, NULL, NULL);
+     201                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     202                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     203                 :            :         data_size1;
+     204                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+     205                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+     206                 :            :         data_size1;
+     207                 :            : 
+     208                 :          1 :     libspdm_reset_message_a(spdm_context);
+     209                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     210                 :            : 
+     211                 :          1 :     session_id = 0xFFFFFFFF;
+     212                 :          1 :     spdm_context->latest_session_id = session_id;
+     213                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+     214                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+     215                 :          1 :     session_info = &spdm_context->session_info[0];
+     216                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+     217                 :          1 :     libspdm_secured_message_set_session_state(
+     218                 :            :         session_info->secured_message_context,
+     219                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+     220                 :            : 
+     221                 :          1 :     response_size = sizeof(response);
+     222                 :          1 :     status = libspdm_get_response_heartbeat(spdm_context,
+     223                 :            :                                             m_libspdm_heartbeat_request1_size,
+     224                 :            :                                             &m_libspdm_heartbeat_request1,
+     225                 :            :                                             &response_size, response);
+     226                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     227                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     228                 :          1 :     spdm_response = (void *)response;
+     229                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     230                 :            :                      SPDM_ERROR);
+     231                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_BUSY);
+     232                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     233                 :          1 :     assert_int_equal(spdm_context->response_state,
+     234                 :            :                      LIBSPDM_RESPONSE_STATE_BUSY);
+     235                 :          1 :     free(data1);
+     236                 :          1 : }
+     237                 :            : 
+     238                 :          1 : void libspdm_test_responder_heartbeat_case4(void **state)
+     239                 :            : {
+     240                 :            :     libspdm_return_t status;
+     241                 :            :     libspdm_test_context_t *spdm_test_context;
+     242                 :            :     libspdm_context_t *spdm_context;
+     243                 :            :     size_t response_size;
+     244                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     245                 :            :     spdm_heartbeat_response_t *spdm_response;
+     246                 :            :     void *data1;
+     247                 :            :     size_t data_size1;
+     248                 :            :     libspdm_session_info_t *session_info;
+     249                 :            :     uint32_t session_id;
+     250                 :            : 
+     251                 :          1 :     spdm_test_context = *state;
+     252                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     253                 :          1 :     spdm_test_context->case_id = 0x4;
+     254                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     255                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     256                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NEED_RESYNC;
+     257                 :          1 :     spdm_context->connection_info.connection_state =
+     258                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     259                 :          1 :     spdm_context->connection_info.capability.flags |=
+     260                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP;
+     261                 :          1 :     spdm_context->local_context.capability.flags |=
+     262                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP;
+     263                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     264                 :            :         m_libspdm_use_hash_algo;
+     265                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     266                 :            :         m_libspdm_use_asym_algo;
+     267                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     268                 :            :         m_libspdm_use_measurement_spec;
+     269                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     270                 :            :         m_libspdm_use_measurement_hash_algo;
+     271                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     272                 :            :         m_libspdm_use_dhe_algo;
+     273                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     274                 :            :         m_libspdm_use_aead_algo;
+     275                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     276                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     277                 :            :                                                     &data_size1, NULL, NULL);
+     278                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     279                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     280                 :            :         data_size1;
+     281                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+     282                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+     283                 :            :         data_size1;
+     284                 :            : 
+     285                 :          1 :     libspdm_reset_message_a(spdm_context);
+     286                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     287                 :            : 
+     288                 :          1 :     session_id = 0xFFFFFFFF;
+     289                 :          1 :     spdm_context->latest_session_id = session_id;
+     290                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+     291                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+     292                 :          1 :     session_info = &spdm_context->session_info[0];
+     293                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+     294                 :          1 :     libspdm_secured_message_set_session_state(
+     295                 :            :         session_info->secured_message_context,
+     296                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+     297                 :            : 
+     298                 :          1 :     response_size = sizeof(response);
+     299                 :          1 :     status = libspdm_get_response_heartbeat(spdm_context,
+     300                 :            :                                             m_libspdm_heartbeat_request1_size,
+     301                 :            :                                             &m_libspdm_heartbeat_request1,
+     302                 :            :                                             &response_size, response);
+     303                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     304                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     305                 :          1 :     spdm_response = (void *)response;
+     306                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     307                 :            :                      SPDM_ERROR);
+     308                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     309                 :            :                      SPDM_ERROR_CODE_REQUEST_RESYNCH);
+     310                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     311                 :          1 :     assert_int_equal(spdm_context->response_state,
+     312                 :            :                      LIBSPDM_RESPONSE_STATE_NEED_RESYNC);
+     313                 :          1 :     free(data1);
+     314                 :          1 : }
+     315                 :            : 
+     316                 :            : #if LIBSPDM_RESPOND_IF_READY_SUPPORT
+     317                 :          1 : void libspdm_test_responder_heartbeat_case5(void **state)
+     318                 :            : {
+     319                 :            :     libspdm_return_t status;
+     320                 :            :     libspdm_test_context_t *spdm_test_context;
+     321                 :            :     libspdm_context_t *spdm_context;
+     322                 :            :     size_t response_size;
+     323                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     324                 :            :     spdm_heartbeat_response_t *spdm_response;
+     325                 :            :     void *data1;
+     326                 :            :     size_t data_size1;
+     327                 :            :     libspdm_session_info_t *session_info;
+     328                 :            :     uint32_t session_id;
+     329                 :            :     spdm_error_data_response_not_ready_t *error_data;
+     330                 :            : 
+     331                 :          1 :     spdm_test_context = *state;
+     332                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     333                 :          1 :     spdm_test_context->case_id = 0x5;
+     334                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     335                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     336                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NOT_READY;
+     337                 :          1 :     spdm_context->connection_info.connection_state =
+     338                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     339                 :          1 :     spdm_context->connection_info.capability.flags |=
+     340                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP;
+     341                 :          1 :     spdm_context->local_context.capability.flags |=
+     342                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP;
+     343                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     344                 :            :         m_libspdm_use_hash_algo;
+     345                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     346                 :            :         m_libspdm_use_asym_algo;
+     347                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     348                 :            :         m_libspdm_use_measurement_spec;
+     349                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     350                 :            :         m_libspdm_use_measurement_hash_algo;
+     351                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     352                 :            :         m_libspdm_use_dhe_algo;
+     353                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     354                 :            :         m_libspdm_use_aead_algo;
+     355                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     356                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     357                 :            :                                                     &data_size1, NULL, NULL);
+     358                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     359                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     360                 :            :         data_size1;
+     361                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+     362                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+     363                 :            :         data_size1;
+     364                 :            : 
+     365                 :          1 :     libspdm_reset_message_a(spdm_context);
+     366                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     367                 :            : 
+     368                 :          1 :     session_id = 0xFFFFFFFF;
+     369                 :          1 :     spdm_context->latest_session_id = session_id;
+     370                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+     371                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+     372                 :          1 :     session_info = &spdm_context->session_info[0];
+     373                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+     374                 :          1 :     libspdm_secured_message_set_session_state(
+     375                 :            :         session_info->secured_message_context,
+     376                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+     377                 :            : 
+     378                 :          1 :     response_size = sizeof(response);
+     379                 :          1 :     status = libspdm_get_response_heartbeat(spdm_context,
+     380                 :            :                                             m_libspdm_heartbeat_request1_size,
+     381                 :            :                                             &m_libspdm_heartbeat_request1,
+     382                 :            :                                             &response_size, response);
+     383                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     384                 :          1 :     assert_int_equal(response_size,
+     385                 :            :                      sizeof(spdm_error_response_t) +
+     386                 :            :                      sizeof(spdm_error_data_response_not_ready_t));
+     387                 :          1 :     spdm_response = (void *)response;
+     388                 :          1 :     error_data =
+     389                 :            :         (spdm_error_data_response_not_ready_t *)(spdm_response + 1);
+     390                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     391                 :            :                      SPDM_ERROR);
+     392                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     393                 :            :                      SPDM_ERROR_CODE_RESPONSE_NOT_READY);
+     394                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     395                 :          1 :     assert_int_equal(spdm_context->response_state,
+     396                 :            :                      LIBSPDM_RESPONSE_STATE_NOT_READY);
+     397                 :          1 :     assert_int_equal(error_data->request_code, SPDM_HEARTBEAT);
+     398                 :          1 :     free(data1);
+     399                 :          1 : }
+     400                 :            : #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
+     401                 :            : 
+     402                 :          1 : void libspdm_test_responder_heartbeat_case6(void **state)
+     403                 :            : {
+     404                 :            :     libspdm_return_t status;
+     405                 :            :     libspdm_test_context_t *spdm_test_context;
+     406                 :            :     libspdm_context_t *spdm_context;
+     407                 :            :     size_t response_size;
+     408                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     409                 :            :     spdm_heartbeat_response_t *spdm_response;
+     410                 :            :     void *data1;
+     411                 :            :     size_t data_size1;
+     412                 :            :     libspdm_session_info_t *session_info;
+     413                 :            :     uint32_t session_id;
+     414                 :            : 
+     415                 :          1 :     spdm_test_context = *state;
+     416                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     417                 :          1 :     spdm_test_context->case_id = 0x6;
+     418                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     419                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     420                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+     421                 :          1 :     spdm_context->connection_info.connection_state =
+     422                 :            :         LIBSPDM_CONNECTION_STATE_NOT_STARTED;
+     423                 :          1 :     spdm_context->connection_info.capability.flags |=
+     424                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP;
+     425                 :          1 :     spdm_context->local_context.capability.flags |=
+     426                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP;
+     427                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     428                 :            :         m_libspdm_use_hash_algo;
+     429                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     430                 :            :         m_libspdm_use_asym_algo;
+     431                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     432                 :            :         m_libspdm_use_measurement_spec;
+     433                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     434                 :            :         m_libspdm_use_measurement_hash_algo;
+     435                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     436                 :            :         m_libspdm_use_dhe_algo;
+     437                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     438                 :            :         m_libspdm_use_aead_algo;
+     439                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     440                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     441                 :            :                                                     &data_size1, NULL, NULL);
+     442                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     443                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     444                 :            :         data_size1;
+     445                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+     446                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+     447                 :            :         data_size1;
+     448                 :            : 
+     449                 :          1 :     libspdm_reset_message_a(spdm_context);
+     450                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     451                 :            : 
+     452                 :          1 :     session_id = 0xFFFFFFFF;
+     453                 :          1 :     spdm_context->latest_session_id = session_id;
+     454                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+     455                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+     456                 :          1 :     session_info = &spdm_context->session_info[0];
+     457                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+     458                 :          1 :     libspdm_secured_message_set_session_state(
+     459                 :            :         session_info->secured_message_context,
+     460                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+     461                 :            : 
+     462                 :          1 :     response_size = sizeof(response);
+     463                 :          1 :     status = libspdm_get_response_heartbeat(spdm_context,
+     464                 :            :                                             m_libspdm_heartbeat_request1_size,
+     465                 :            :                                             &m_libspdm_heartbeat_request1,
+     466                 :            :                                             &response_size, response);
+     467                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     468                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     469                 :          1 :     spdm_response = (void *)response;
+     470                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     471                 :            :                      SPDM_ERROR);
+     472                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     473                 :            :                      SPDM_ERROR_CODE_UNEXPECTED_REQUEST);
+     474                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     475                 :          1 :     free(data1);
+     476                 :          1 : }
+     477                 :            : 
+     478                 :          1 : void libspdm_test_responder_heartbeat_case7(void **state)
+     479                 :            : {
+     480                 :            :     libspdm_return_t status;
+     481                 :            :     libspdm_test_context_t *spdm_test_context;
+     482                 :            :     libspdm_context_t *spdm_context;
+     483                 :            :     size_t response_size;
+     484                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     485                 :            :     spdm_heartbeat_response_t *spdm_response;
+     486                 :            :     void *data1;
+     487                 :            :     size_t data_size1;
+     488                 :            :     libspdm_session_info_t *session_info;
+     489                 :            :     uint32_t session_id;
+     490                 :            : 
+     491                 :          1 :     spdm_test_context = *state;
+     492                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     493                 :          1 :     spdm_test_context->case_id = 0x7;
+     494                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     495                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     496                 :          1 :     spdm_context->connection_info.connection_state =
+     497                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     498                 :          1 :     spdm_context->connection_info.capability.flags |=
+     499                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP;
+     500                 :          1 :     spdm_context->local_context.capability.flags |=
+     501                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP;
+     502                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     503                 :            :         m_libspdm_use_hash_algo;
+     504                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     505                 :            :         m_libspdm_use_asym_algo;
+     506                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     507                 :            :         m_libspdm_use_measurement_spec;
+     508                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     509                 :            :         m_libspdm_use_measurement_hash_algo;
+     510                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     511                 :            :         m_libspdm_use_dhe_algo;
+     512                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     513                 :            :         m_libspdm_use_aead_algo;
+     514                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     515                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     516                 :            :                                                     &data_size1, NULL, NULL);
+     517                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     518                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     519                 :            :         data_size1;
+     520                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+     521                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+     522                 :            :         data_size1;
+     523                 :            : 
+     524                 :          1 :     libspdm_reset_message_a(spdm_context);
+     525                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     526                 :            : 
+     527                 :          1 :     session_id = 0xFFFFFFFF;
+     528                 :          1 :     spdm_context->latest_session_id = session_id;
+     529                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+     530                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+     531                 :          1 :     session_info = &spdm_context->session_info[0];
+     532                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+     533                 :          1 :     libspdm_secured_message_set_session_state(
+     534                 :            :         session_info->secured_message_context,
+     535                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+     536                 :          1 :     session_info->heartbeat_period = 1;
+     537                 :            : 
+     538                 :          1 :     response_size = sizeof(response);
+     539                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     540                 :            :     session_info->session_transcript.message_m.buffer_size =
+     541                 :            :         session_info->session_transcript.message_m.max_buffer_size;
+     542                 :            :     spdm_context->transcript.message_b.buffer_size =
+     543                 :            :         spdm_context->transcript.message_b.max_buffer_size;
+     544                 :            :     spdm_context->transcript.message_c.buffer_size =
+     545                 :            :         spdm_context->transcript.message_c.max_buffer_size;
+     546                 :            :     spdm_context->transcript.message_mut_b.buffer_size =
+     547                 :            :         spdm_context->transcript.message_mut_b.max_buffer_size;
+     548                 :            :     spdm_context->transcript.message_mut_c.buffer_size =
+     549                 :            :         spdm_context->transcript.message_mut_c.max_buffer_size;
+     550                 :            : #endif
+     551                 :          1 :     status = libspdm_get_response_heartbeat(spdm_context,
+     552                 :            :                                             m_libspdm_heartbeat_request1_size,
+     553                 :            :                                             &m_libspdm_heartbeat_request1,
+     554                 :            :                                             &response_size, response);
+     555                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     556                 :          1 :     assert_int_equal(response_size, sizeof(spdm_heartbeat_response_t));
+     557                 :          1 :     spdm_response = (void *)response;
+     558                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_HEARTBEAT_ACK);
+     559                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     560                 :            :     assert_int_equal(session_info->session_transcript.message_m.buffer_size, 0);
+     561                 :            :     assert_int_equal(spdm_context->transcript.message_b.buffer_size, 0);
+     562                 :            :     assert_int_equal(spdm_context->transcript.message_c.buffer_size, 0);
+     563                 :            :     assert_int_equal(spdm_context->transcript.message_mut_b.buffer_size, 0);
+     564                 :            :     assert_int_equal(spdm_context->transcript.message_mut_c.buffer_size, 0);
+     565                 :            : #endif
+     566                 :            : 
+     567                 :          1 :     free(data1);
+     568                 :          1 : }
+     569                 :            : /**
+     570                 :            :  * Test 2: Responder has set HeartbeatPeriod to a value of 0 but Requester sends
+     571                 :            :  *         HEARTBEAT request anyways.
+     572                 :            :  * Expected behavior: Responder returns UnexpectedRequest ERROR message.
+     573                 :            :  **/
+     574                 :          1 : void libspdm_test_responder_heartbeat_case8(void **state)
+     575                 :            : {
+     576                 :            :     libspdm_return_t status;
+     577                 :            :     libspdm_test_context_t *spdm_test_context;
+     578                 :            :     libspdm_context_t *spdm_context;
+     579                 :            :     size_t response_size;
+     580                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     581                 :            :     spdm_heartbeat_response_t *spdm_response;
+     582                 :            :     libspdm_session_info_t *session_info;
+     583                 :            :     uint32_t session_id;
+     584                 :            : 
+     585                 :          1 :     spdm_test_context = *state;
+     586                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     587                 :          1 :     spdm_test_context->case_id = 0x1;
+     588                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     589                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     590                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     591                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP;
+     592                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP;
+     593                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     594                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     595                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+     596                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     597                 :            :         m_libspdm_use_measurement_hash_algo;
+     598                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+     599                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+     600                 :            : 
+     601                 :          1 :     libspdm_reset_message_a(spdm_context);
+     602                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     603                 :            : 
+     604                 :          1 :     session_id = 0xFFFFFFFF;
+     605                 :          1 :     spdm_context->latest_session_id = session_id;
+     606                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+     607                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+     608                 :          1 :     session_info = &spdm_context->session_info[0];
+     609                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+     610                 :          1 :     libspdm_secured_message_set_session_state(
+     611                 :            :         session_info->secured_message_context,
+     612                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+     613                 :          1 :     session_info->heartbeat_period = 0;
+     614                 :            : 
+     615                 :          1 :     response_size = sizeof(response);
+     616                 :          1 :     status = libspdm_get_response_heartbeat(spdm_context,
+     617                 :            :                                             m_libspdm_heartbeat_request1_size,
+     618                 :            :                                             &m_libspdm_heartbeat_request1,
+     619                 :            :                                             &response_size, response);
+     620                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     621                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     622                 :          1 :     spdm_response = (void *)response;
+     623                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
+     624                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_UNEXPECTED_REQUEST);
+     625                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     626                 :          1 : }
+     627                 :            : 
+     628                 :            : libspdm_test_context_t m_libspdm_responder_heartbeat_test_context = {
+     629                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+     630                 :            :     false,
+     631                 :            : };
+     632                 :            : 
+     633                 :          1 : int libspdm_responder_heartbeat_test_main(void)
+     634                 :            : {
+     635                 :          1 :     const struct CMUnitTest spdm_responder_heartbeat_tests[] = {
+     636                 :            :         /* Success Case*/
+     637                 :            :         cmocka_unit_test(libspdm_test_responder_heartbeat_case1),
+     638                 :            :         /* Bad request size*/
+     639                 :            :         cmocka_unit_test(libspdm_test_responder_heartbeat_case2),
+     640                 :            :         /* response_state: SPDM_RESPONSE_STATE_BUSY*/
+     641                 :            :         cmocka_unit_test(libspdm_test_responder_heartbeat_case3),
+     642                 :            :         /* response_state: SPDM_RESPONSE_STATE_NEED_RESYNC*/
+     643                 :            :         cmocka_unit_test(libspdm_test_responder_heartbeat_case4),
+     644                 :            :         #if LIBSPDM_RESPOND_IF_READY_SUPPORT
+     645                 :            :         /* response_state: SPDM_RESPONSE_STATE_NOT_READY*/
+     646                 :            :         cmocka_unit_test(libspdm_test_responder_heartbeat_case5),
+     647                 :            :         #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
+     648                 :            :         /* connection_state Check*/
+     649                 :            :         cmocka_unit_test(libspdm_test_responder_heartbeat_case6),
+     650                 :            :         /* Buffer reset*/
+     651                 :            :         cmocka_unit_test(libspdm_test_responder_heartbeat_case7),
+     652                 :            :         cmocka_unit_test(libspdm_test_responder_heartbeat_case8),
+     653                 :            :     };
+     654                 :            : 
+     655                 :          1 :     libspdm_setup_test_context(&m_libspdm_responder_heartbeat_test_context);
+     656                 :            : 
+     657                 :          1 :     return cmocka_run_group_tests(spdm_responder_heartbeat_tests,
+     658                 :            :                                   libspdm_unit_test_group_setup,
+     659                 :            :                                   libspdm_unit_test_group_teardown);
+     660                 :            : }
+     661                 :            : 
+     662                 :            : #endif /* (LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP) || (LIBSPDM_ENABLE_CAPABILITY_PSK_CAP) */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/index-sort-b.html b/coverage_log/unit_test/test_spdm_responder/index-sort-b.html new file mode 100644 index 00000000000..498a429b0e2 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/index-sort-b.html @@ -0,0 +1,479 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responderHitTotalCoverage
Test:coverage.infoLines:146471472799.5 %
Date:2024-09-22 08:21:07Functions:457457100.0 %
Branches:18228663.6 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
psk_finish.c +
100.0%
+
100.0 %732 / 732100.0 %16 / 1650.0 %1 / 2
respond_if_ready.c +
100.0%
+
100.0 %554 / 554100.0 %16 / 1650.0 %1 / 2
finish.c +
100.0%
+
100.0 %1733 / 1733100.0 %31 / 3150.0 %1 / 2
set_certificate_rsp.c +
99.3%99.3%
+
99.3 %423 / 426100.0 %13 / 1350.0 %2 / 4
encap_get_certificate.c +
100.0%
+
100.0 %262 / 262100.0 %6 / 650.0 %3 / 6
vendor_response.c +
95.5%95.5%
+
95.5 %64 / 67100.0 %4 / 450.0 %7 / 14
psk_exchange.c +
99.7%99.7%
+
99.7 %782 / 784100.0 %18 / 1850.0 %8 / 16
test_spdm_responder.c +
52.1%52.1%
+
52.1 %37 / 71100.0 %1 / 150.0 %34 / 68
key_exchange.c +
99.7%99.7%
+
99.7 %928 / 931100.0 %20 / 2056.2 %9 / 16
csr.c +
97.3%97.3%
+
97.3 %852 / 876100.0 %25 / 2560.9 %39 / 64
chunk_get.c +
100.0%
+
100.0 %498 / 498100.0 %14 / 1475.0 %12 / 16
certificate.c +
98.2%98.2%
+
98.2 %485 / 494100.0 %19 / 1976.3 %29 / 38
chunk_send_ack.c +
100.0%
+
100.0 %780 / 780100.0 %23 / 2383.3 %5 / 6
measurements.c +
99.8%99.8%
+
99.8 %1025 / 1027100.0 %36 / 3692.9 %13 / 14
algorithms.c +
100.0%
+
100.0 %1115 / 1115100.0 %32 / 32-0 / 0
measurement_extension_log.c +
100.0%
+
100.0 %136 / 136100.0 %6 / 6-0 / 0
key_update.c +
100.0%
+
100.0 %689 / 689100.0 %31 / 31-0 / 0
encap_response.c +
100.0%
+
100.0 %503 / 503100.0 %16 / 16-0 / 0
subscribe_event_types_ack.c +
100.0%
+
100.0 %73 / 73100.0 %4 / 4-0 / 0
end_session.c +
100.0%
+
100.0 %312 / 312100.0 %9 / 9-0 / 0
version.c +
100.0%
+
100.0 %82 / 82100.0 %8 / 8-0 / 0
encap_challenge.c +
100.0%
+
100.0 %224 / 224100.0 %7 / 7-0 / 0
set_key_pair_info_ack.c +
100.0%
+
100.0 %245 / 245100.0 %4 / 4-0 / 0
capabilities.c +
100.0%
+
100.0 %359 / 359100.0 %27 / 27-0 / 0
encap_key_update.c +
100.0%
+
100.0 %114 / 114100.0 %7 / 7-0 / 0
key_pair_info.c +
100.0%
+
100.0 %79 / 79100.0 %5 / 5-0 / 0
receive_send.c +
100.0%
+
100.0 %194 / 194100.0 %8 / 8-0 / 0
heartbeat.c +
100.0%
+
100.0 %310 / 310100.0 %9 / 9-0 / 0
supported_event_types.c +
100.0%
+
100.0 %53 / 53100.0 %3 / 3100.0 %2 / 2
encap_get_digests.c +
100.0%
+
100.0 %221 / 221100.0 %8 / 8100.0 %4 / 4
challenge_auth.c +
100.0%
+
100.0 %553 / 553100.0 %20 / 20100.0 %6 / 6
digests.c +
100.0%
+
100.0 %230 / 230100.0 %11 / 11100.0 %6 / 6
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/index-sort-f.html b/coverage_log/unit_test/test_spdm_responder/index-sort-f.html new file mode 100644 index 00000000000..6a291cf8da9 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/index-sort-f.html @@ -0,0 +1,479 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responderHitTotalCoverage
Test:coverage.infoLines:146471472799.5 %
Date:2024-09-22 08:21:07Functions:457457100.0 %
Branches:18228663.6 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
test_spdm_responder.c +
52.1%52.1%
+
52.1 %37 / 71100.0 %1 / 150.0 %34 / 68
supported_event_types.c +
100.0%
+
100.0 %53 / 53100.0 %3 / 3100.0 %2 / 2
vendor_response.c +
95.5%95.5%
+
95.5 %64 / 67100.0 %4 / 450.0 %7 / 14
subscribe_event_types_ack.c +
100.0%
+
100.0 %73 / 73100.0 %4 / 4-0 / 0
set_key_pair_info_ack.c +
100.0%
+
100.0 %245 / 245100.0 %4 / 4-0 / 0
key_pair_info.c +
100.0%
+
100.0 %79 / 79100.0 %5 / 5-0 / 0
measurement_extension_log.c +
100.0%
+
100.0 %136 / 136100.0 %6 / 6-0 / 0
encap_get_certificate.c +
100.0%
+
100.0 %262 / 262100.0 %6 / 650.0 %3 / 6
encap_challenge.c +
100.0%
+
100.0 %224 / 224100.0 %7 / 7-0 / 0
encap_key_update.c +
100.0%
+
100.0 %114 / 114100.0 %7 / 7-0 / 0
version.c +
100.0%
+
100.0 %82 / 82100.0 %8 / 8-0 / 0
encap_get_digests.c +
100.0%
+
100.0 %221 / 221100.0 %8 / 8100.0 %4 / 4
receive_send.c +
100.0%
+
100.0 %194 / 194100.0 %8 / 8-0 / 0
end_session.c +
100.0%
+
100.0 %312 / 312100.0 %9 / 9-0 / 0
heartbeat.c +
100.0%
+
100.0 %310 / 310100.0 %9 / 9-0 / 0
digests.c +
100.0%
+
100.0 %230 / 230100.0 %11 / 11100.0 %6 / 6
set_certificate_rsp.c +
99.3%99.3%
+
99.3 %423 / 426100.0 %13 / 1350.0 %2 / 4
chunk_get.c +
100.0%
+
100.0 %498 / 498100.0 %14 / 1475.0 %12 / 16
psk_finish.c +
100.0%
+
100.0 %732 / 732100.0 %16 / 1650.0 %1 / 2
respond_if_ready.c +
100.0%
+
100.0 %554 / 554100.0 %16 / 1650.0 %1 / 2
encap_response.c +
100.0%
+
100.0 %503 / 503100.0 %16 / 16-0 / 0
psk_exchange.c +
99.7%99.7%
+
99.7 %782 / 784100.0 %18 / 1850.0 %8 / 16
certificate.c +
98.2%98.2%
+
98.2 %485 / 494100.0 %19 / 1976.3 %29 / 38
key_exchange.c +
99.7%99.7%
+
99.7 %928 / 931100.0 %20 / 2056.2 %9 / 16
challenge_auth.c +
100.0%
+
100.0 %553 / 553100.0 %20 / 20100.0 %6 / 6
chunk_send_ack.c +
100.0%
+
100.0 %780 / 780100.0 %23 / 2383.3 %5 / 6
csr.c +
97.3%97.3%
+
97.3 %852 / 876100.0 %25 / 2560.9 %39 / 64
capabilities.c +
100.0%
+
100.0 %359 / 359100.0 %27 / 27-0 / 0
key_update.c +
100.0%
+
100.0 %689 / 689100.0 %31 / 31-0 / 0
finish.c +
100.0%
+
100.0 %1733 / 1733100.0 %31 / 3150.0 %1 / 2
algorithms.c +
100.0%
+
100.0 %1115 / 1115100.0 %32 / 32-0 / 0
measurements.c +
99.8%99.8%
+
99.8 %1025 / 1027100.0 %36 / 3692.9 %13 / 14
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/index-sort-l.html b/coverage_log/unit_test/test_spdm_responder/index-sort-l.html new file mode 100644 index 00000000000..2135b38f926 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/index-sort-l.html @@ -0,0 +1,479 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responderHitTotalCoverage
Test:coverage.infoLines:146471472799.5 %
Date:2024-09-22 08:21:07Functions:457457100.0 %
Branches:18228663.6 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
test_spdm_responder.c +
52.1%52.1%
+
52.1 %37 / 71100.0 %1 / 150.0 %34 / 68
vendor_response.c +
95.5%95.5%
+
95.5 %64 / 67100.0 %4 / 450.0 %7 / 14
csr.c +
97.3%97.3%
+
97.3 %852 / 876100.0 %25 / 2560.9 %39 / 64
certificate.c +
98.2%98.2%
+
98.2 %485 / 494100.0 %19 / 1976.3 %29 / 38
set_certificate_rsp.c +
99.3%99.3%
+
99.3 %423 / 426100.0 %13 / 1350.0 %2 / 4
key_exchange.c +
99.7%99.7%
+
99.7 %928 / 931100.0 %20 / 2056.2 %9 / 16
psk_exchange.c +
99.7%99.7%
+
99.7 %782 / 784100.0 %18 / 1850.0 %8 / 16
measurements.c +
99.8%99.8%
+
99.8 %1025 / 1027100.0 %36 / 3692.9 %13 / 14
supported_event_types.c +
100.0%
+
100.0 %53 / 53100.0 %3 / 3100.0 %2 / 2
subscribe_event_types_ack.c +
100.0%
+
100.0 %73 / 73100.0 %4 / 4-0 / 0
key_pair_info.c +
100.0%
+
100.0 %79 / 79100.0 %5 / 5-0 / 0
version.c +
100.0%
+
100.0 %82 / 82100.0 %8 / 8-0 / 0
encap_key_update.c +
100.0%
+
100.0 %114 / 114100.0 %7 / 7-0 / 0
measurement_extension_log.c +
100.0%
+
100.0 %136 / 136100.0 %6 / 6-0 / 0
receive_send.c +
100.0%
+
100.0 %194 / 194100.0 %8 / 8-0 / 0
encap_get_digests.c +
100.0%
+
100.0 %221 / 221100.0 %8 / 8100.0 %4 / 4
encap_challenge.c +
100.0%
+
100.0 %224 / 224100.0 %7 / 7-0 / 0
digests.c +
100.0%
+
100.0 %230 / 230100.0 %11 / 11100.0 %6 / 6
set_key_pair_info_ack.c +
100.0%
+
100.0 %245 / 245100.0 %4 / 4-0 / 0
encap_get_certificate.c +
100.0%
+
100.0 %262 / 262100.0 %6 / 650.0 %3 / 6
heartbeat.c +
100.0%
+
100.0 %310 / 310100.0 %9 / 9-0 / 0
end_session.c +
100.0%
+
100.0 %312 / 312100.0 %9 / 9-0 / 0
capabilities.c +
100.0%
+
100.0 %359 / 359100.0 %27 / 27-0 / 0
chunk_get.c +
100.0%
+
100.0 %498 / 498100.0 %14 / 1475.0 %12 / 16
encap_response.c +
100.0%
+
100.0 %503 / 503100.0 %16 / 16-0 / 0
challenge_auth.c +
100.0%
+
100.0 %553 / 553100.0 %20 / 20100.0 %6 / 6
respond_if_ready.c +
100.0%
+
100.0 %554 / 554100.0 %16 / 1650.0 %1 / 2
key_update.c +
100.0%
+
100.0 %689 / 689100.0 %31 / 31-0 / 0
psk_finish.c +
100.0%
+
100.0 %732 / 732100.0 %16 / 1650.0 %1 / 2
chunk_send_ack.c +
100.0%
+
100.0 %780 / 780100.0 %23 / 2383.3 %5 / 6
algorithms.c +
100.0%
+
100.0 %1115 / 1115100.0 %32 / 32-0 / 0
finish.c +
100.0%
+
100.0 %1733 / 1733100.0 %31 / 3150.0 %1 / 2
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/index.html b/coverage_log/unit_test/test_spdm_responder/index.html new file mode 100644 index 00000000000..60c2a47b97d --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/index.html @@ -0,0 +1,479 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responderHitTotalCoverage
Test:coverage.infoLines:146471472799.5 %
Date:2024-09-22 08:21:07Functions:457457100.0 %
Branches:18228663.6 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
algorithms.c +
100.0%
+
100.0 %1115 / 1115100.0 %32 / 32-0 / 0
capabilities.c +
100.0%
+
100.0 %359 / 359100.0 %27 / 27-0 / 0
certificate.c +
98.2%98.2%
+
98.2 %485 / 494100.0 %19 / 1976.3 %29 / 38
challenge_auth.c +
100.0%
+
100.0 %553 / 553100.0 %20 / 20100.0 %6 / 6
chunk_get.c +
100.0%
+
100.0 %498 / 498100.0 %14 / 1475.0 %12 / 16
chunk_send_ack.c +
100.0%
+
100.0 %780 / 780100.0 %23 / 2383.3 %5 / 6
csr.c +
97.3%97.3%
+
97.3 %852 / 876100.0 %25 / 2560.9 %39 / 64
digests.c +
100.0%
+
100.0 %230 / 230100.0 %11 / 11100.0 %6 / 6
encap_challenge.c +
100.0%
+
100.0 %224 / 224100.0 %7 / 7-0 / 0
encap_get_certificate.c +
100.0%
+
100.0 %262 / 262100.0 %6 / 650.0 %3 / 6
encap_get_digests.c +
100.0%
+
100.0 %221 / 221100.0 %8 / 8100.0 %4 / 4
encap_key_update.c +
100.0%
+
100.0 %114 / 114100.0 %7 / 7-0 / 0
encap_response.c +
100.0%
+
100.0 %503 / 503100.0 %16 / 16-0 / 0
end_session.c +
100.0%
+
100.0 %312 / 312100.0 %9 / 9-0 / 0
finish.c +
100.0%
+
100.0 %1733 / 1733100.0 %31 / 3150.0 %1 / 2
heartbeat.c +
100.0%
+
100.0 %310 / 310100.0 %9 / 9-0 / 0
key_exchange.c +
99.7%99.7%
+
99.7 %928 / 931100.0 %20 / 2056.2 %9 / 16
key_pair_info.c +
100.0%
+
100.0 %79 / 79100.0 %5 / 5-0 / 0
key_update.c +
100.0%
+
100.0 %689 / 689100.0 %31 / 31-0 / 0
measurement_extension_log.c +
100.0%
+
100.0 %136 / 136100.0 %6 / 6-0 / 0
measurements.c +
99.8%99.8%
+
99.8 %1025 / 1027100.0 %36 / 3692.9 %13 / 14
psk_exchange.c +
99.7%99.7%
+
99.7 %782 / 784100.0 %18 / 1850.0 %8 / 16
psk_finish.c +
100.0%
+
100.0 %732 / 732100.0 %16 / 1650.0 %1 / 2
receive_send.c +
100.0%
+
100.0 %194 / 194100.0 %8 / 8-0 / 0
respond_if_ready.c +
100.0%
+
100.0 %554 / 554100.0 %16 / 1650.0 %1 / 2
set_certificate_rsp.c +
99.3%99.3%
+
99.3 %423 / 426100.0 %13 / 1350.0 %2 / 4
set_key_pair_info_ack.c +
100.0%
+
100.0 %245 / 245100.0 %4 / 4-0 / 0
subscribe_event_types_ack.c +
100.0%
+
100.0 %73 / 73100.0 %4 / 4-0 / 0
supported_event_types.c +
100.0%
+
100.0 %53 / 53100.0 %3 / 3100.0 %2 / 2
test_spdm_responder.c +
52.1%52.1%
+
52.1 %37 / 71100.0 %1 / 150.0 %34 / 68
vendor_response.c +
95.5%95.5%
+
95.5 %64 / 67100.0 %4 / 450.0 %7 / 14
version.c +
100.0%
+
100.0 %82 / 82100.0 %8 / 8-0 / 0
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/key_exchange.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_responder/key_exchange.c.func-sort-c.html new file mode 100644 index 00000000000..aee5a603980 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/key_exchange.c.func-sort-c.html @@ -0,0 +1,161 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/key_exchange.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - key_exchange.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:92893199.7 %
Date:2024-09-22 08:21:07Functions:2020100.0 %
Branches:91656.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_key_exchange_test_main1
libspdm_test_responder_key_exchange_case11
libspdm_test_responder_key_exchange_case101
libspdm_test_responder_key_exchange_case111
libspdm_test_responder_key_exchange_case141
libspdm_test_responder_key_exchange_case151
libspdm_test_responder_key_exchange_case161
libspdm_test_responder_key_exchange_case171
libspdm_test_responder_key_exchange_case181
libspdm_test_responder_key_exchange_case191
libspdm_test_responder_key_exchange_case21
libspdm_test_responder_key_exchange_case201
libspdm_test_responder_key_exchange_case211
libspdm_test_responder_key_exchange_case31
libspdm_test_responder_key_exchange_case41
libspdm_test_responder_key_exchange_case51
libspdm_test_responder_key_exchange_case61
libspdm_test_responder_key_exchange_case71
libspdm_test_responder_key_exchange_case81
libspdm_test_responder_key_exchange_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/key_exchange.c.func.html b/coverage_log/unit_test/test_spdm_responder/key_exchange.c.func.html new file mode 100644 index 00000000000..a63aef4e86e --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/key_exchange.c.func.html @@ -0,0 +1,161 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/key_exchange.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - key_exchange.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:92893199.7 %
Date:2024-09-22 08:21:07Functions:2020100.0 %
Branches:91656.2 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_key_exchange_test_main1
libspdm_test_responder_key_exchange_case11
libspdm_test_responder_key_exchange_case101
libspdm_test_responder_key_exchange_case111
libspdm_test_responder_key_exchange_case141
libspdm_test_responder_key_exchange_case151
libspdm_test_responder_key_exchange_case161
libspdm_test_responder_key_exchange_case171
libspdm_test_responder_key_exchange_case181
libspdm_test_responder_key_exchange_case191
libspdm_test_responder_key_exchange_case21
libspdm_test_responder_key_exchange_case201
libspdm_test_responder_key_exchange_case211
libspdm_test_responder_key_exchange_case31
libspdm_test_responder_key_exchange_case41
libspdm_test_responder_key_exchange_case51
libspdm_test_responder_key_exchange_case61
libspdm_test_responder_key_exchange_case71
libspdm_test_responder_key_exchange_case81
libspdm_test_responder_key_exchange_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/key_exchange.c.gcov.html b/coverage_log/unit_test/test_spdm_responder/key_exchange.c.gcov.html new file mode 100644 index 00000000000..73ea45a48d5 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/key_exchange.c.gcov.html @@ -0,0 +1,2046 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/key_exchange.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - key_exchange.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:92893199.7 %
Date:2024-09-22 08:21:07Functions:2020100.0 %
Branches:91656.2 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_responder_lib.h"
+       9                 :            : #include "internal/libspdm_requester_lib.h"
+      10                 :            : 
+      11                 :            : #if LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP
+      12                 :            : 
+      13                 :            : #pragma pack(1)
+      14                 :            : typedef struct {
+      15                 :            :     spdm_message_header_t header;
+      16                 :            :     uint16_t req_session_id;
+      17                 :            :     uint8_t session_policy;
+      18                 :            :     uint8_t reserved;
+      19                 :            :     uint8_t random_data[SPDM_RANDOM_DATA_SIZE];
+      20                 :            :     uint8_t exchange_data[LIBSPDM_MAX_DHE_KEY_SIZE];
+      21                 :            :     uint16_t opaque_length;
+      22                 :            :     uint8_t opaque_data[SPDM_MAX_OPAQUE_DATA_SIZE];
+      23                 :            : } libspdm_key_exchange_request_mine_t;
+      24                 :            : #pragma pack()
+      25                 :            : 
+      26                 :            : libspdm_key_exchange_request_mine_t m_libspdm_key_exchange_request1 = {
+      27                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_KEY_EXCHANGE,
+      28                 :            :       SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0 },
+      29                 :            : };
+      30                 :            : size_t m_libspdm_key_exchange_request1_size = sizeof(m_libspdm_key_exchange_request1);
+      31                 :            : 
+      32                 :            : libspdm_key_exchange_request_mine_t m_libspdm_key_exchange_request2 = {
+      33                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_KEY_EXCHANGE,
+      34                 :            :       SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0 },
+      35                 :            : };
+      36                 :            : size_t m_libspdm_key_exchange_request2_size = sizeof(spdm_key_exchange_request_t);
+      37                 :            : 
+      38                 :            : /* Request TCB measurement hash */
+      39                 :            : libspdm_key_exchange_request_mine_t m_libspdm_key_exchange_request3 = {
+      40                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_KEY_EXCHANGE,
+      41                 :            :       SPDM_KEY_EXCHANGE_REQUEST_TCB_COMPONENT_MEASUREMENT_HASH, 0 },
+      42                 :            : };
+      43                 :            : size_t m_libspdm_key_exchange_request3_size = sizeof(m_libspdm_key_exchange_request3);
+      44                 :            : 
+      45                 :            : /* Request all measurement hash */
+      46                 :            : libspdm_key_exchange_request_mine_t m_libspdm_key_exchange_request4 = {
+      47                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_KEY_EXCHANGE,
+      48                 :            :       SPDM_KEY_EXCHANGE_REQUEST_ALL_MEASUREMENTS_HASH, 0 },
+      49                 :            : };
+      50                 :            : size_t m_libspdm_key_exchange_request4_size = sizeof(m_libspdm_key_exchange_request4);
+      51                 :            : 
+      52                 :            : /* Uses a reserved value in measurement hash */
+      53                 :            : libspdm_key_exchange_request_mine_t m_libspdm_key_exchange_request5 = {
+      54                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_KEY_EXCHANGE,
+      55                 :            :       0x50, 0 },
+      56                 :            : };
+      57                 :            : size_t m_libspdm_key_exchange_request5_size = sizeof(m_libspdm_key_exchange_request5);
+      58                 :            : 
+      59                 :            : /* Asks for certificate in slot 1 */
+      60                 :            : libspdm_key_exchange_request_mine_t m_libspdm_key_exchange_request6 = {
+      61                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_KEY_EXCHANGE,
+      62                 :            :       SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 1 },
+      63                 :            : };
+      64                 :            : size_t m_libspdm_key_exchange_request6_size = sizeof(m_libspdm_key_exchange_request6);
+      65                 :            : 
+      66                 :            : /* Asks for previously provisioned raw public key */
+      67                 :            : libspdm_key_exchange_request_mine_t m_libspdm_key_exchange_request7 = {
+      68                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_KEY_EXCHANGE,
+      69                 :            :       SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0xFF },
+      70                 :            : };
+      71                 :            : size_t m_libspdm_key_exchange_request7_size = sizeof(m_libspdm_key_exchange_request7);
+      72                 :            : 
+      73                 :            : libspdm_key_exchange_request_mine_t m_libspdm_key_exchange_request8 = {
+      74                 :            :     { SPDM_MESSAGE_VERSION_12, SPDM_KEY_EXCHANGE,
+      75                 :            :       SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0 },
+      76                 :            : };
+      77                 :            : size_t m_libspdm_key_exchange_request8_size = sizeof(m_libspdm_key_exchange_request8);
+      78                 :            : 
+      79                 :            : libspdm_key_exchange_request_mine_t m_libspdm_key_exchange_request9 = {
+      80                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_KEY_EXCHANGE,
+      81                 :            :       SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 9 },
+      82                 :            : };
+      83                 :            : size_t m_libspdm_key_exchange_request9_size = sizeof(m_libspdm_key_exchange_request9);
+      84                 :            : 
+      85                 :            : libspdm_key_exchange_request_mine_t m_libspdm_key_exchange_request10 = {
+      86                 :            :     { SPDM_MESSAGE_VERSION_13, SPDM_KEY_EXCHANGE,
+      87                 :            :       SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0 },
+      88                 :            : };
+      89                 :            : size_t m_libspdm_key_exchange_request10_size = sizeof(m_libspdm_key_exchange_request10);
+      90                 :            : 
+      91                 :          1 : void libspdm_test_responder_key_exchange_case1(void **state)
+      92                 :            : {
+      93                 :            :     libspdm_return_t status;
+      94                 :            :     libspdm_test_context_t *spdm_test_context;
+      95                 :            :     libspdm_context_t *spdm_context;
+      96                 :            :     size_t response_size;
+      97                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+      98                 :            :     spdm_key_exchange_response_t *spdm_response;
+      99                 :            :     void *data1;
+     100                 :            :     size_t data_size1;
+     101                 :            :     uint8_t *ptr;
+     102                 :            :     size_t dhe_key_size;
+     103                 :            :     void *dhe_context;
+     104                 :            :     size_t opaque_key_exchange_req_size;
+     105                 :            :     uint32_t session_id;
+     106                 :            : 
+     107                 :          1 :     spdm_test_context = *state;
+     108                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     109                 :          1 :     spdm_test_context->case_id = 0x1;
+     110                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     111                 :          1 :     spdm_context->connection_info.capability.flags |=
+     112                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+     113                 :          1 :     spdm_context->local_context.capability.flags |=
+     114                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
+     115                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     116                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     117                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     118                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+     119                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     120                 :            :         m_libspdm_use_measurement_hash_algo;
+     121                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+     122                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+     123                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     124                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     125                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     126                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     127                 :            :                                                     &data_size1, NULL, NULL);
+     128                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     129                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
+     130                 :            : 
+     131                 :          1 :     libspdm_reset_message_a(spdm_context);
+     132                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     133                 :            : 
+     134                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
+     135                 :            : 
+     136                 :          1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+     137                 :            :                               m_libspdm_key_exchange_request1.random_data);
+     138                 :          1 :     m_libspdm_key_exchange_request1.req_session_id = 0xFFFF;
+     139                 :          1 :     m_libspdm_key_exchange_request1.reserved = 0;
+     140                 :          1 :     ptr = m_libspdm_key_exchange_request1.exchange_data;
+     141                 :          1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+     142                 :          1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
+     143                 :            :                                   false);
+     144                 :          1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
+     145                 :          1 :     ptr += dhe_key_size;
+     146                 :          1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+     147                 :          1 :     opaque_key_exchange_req_size =
+     148                 :          1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
+     149                 :          1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
+     150                 :          1 :     ptr += sizeof(uint16_t);
+     151                 :          1 :     libspdm_build_opaque_data_supported_version_data(
+     152                 :            :         spdm_context, &opaque_key_exchange_req_size, ptr);
+     153                 :          1 :     ptr += opaque_key_exchange_req_size;
+     154                 :          1 :     response_size = sizeof(response);
+     155                 :          1 :     status = libspdm_get_response_key_exchange(
+     156                 :            :         spdm_context, m_libspdm_key_exchange_request1_size,
+     157                 :            :         &m_libspdm_key_exchange_request1, &response_size, response);
+     158                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     159                 :          1 :     assert_int_equal(
+     160                 :            :         libspdm_secured_message_get_session_state(
+     161                 :            :             spdm_context->session_info[0].secured_message_context),
+     162                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+     163                 :          1 :     spdm_response = (void *)response;
+     164                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_KEY_EXCHANGE_RSP);
+     165                 :          1 :     assert_int_equal(spdm_response->rsp_session_id, 0xFFFF);
+     166                 :            : 
+     167                 :          1 :     session_id = (m_libspdm_key_exchange_request1.req_session_id << 16) |
+     168                 :          1 :                  spdm_response->rsp_session_id;
+     169                 :          1 :     libspdm_free_session_id(spdm_context, session_id);
+     170                 :          1 :     free(data1);
+     171                 :          1 : }
+     172                 :            : 
+     173                 :          1 : void libspdm_test_responder_key_exchange_case2(void **state)
+     174                 :            : {
+     175                 :            :     libspdm_return_t status;
+     176                 :            :     libspdm_test_context_t *spdm_test_context;
+     177                 :            :     libspdm_context_t *spdm_context;
+     178                 :            :     size_t response_size;
+     179                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     180                 :            :     spdm_key_exchange_response_t *spdm_response;
+     181                 :            :     void *data1;
+     182                 :            :     size_t data_size1;
+     183                 :            :     uint8_t *ptr;
+     184                 :            :     size_t dhe_key_size;
+     185                 :            :     void *dhe_context;
+     186                 :            :     size_t opaque_key_exchange_req_size;
+     187                 :            : 
+     188                 :          1 :     spdm_test_context = *state;
+     189                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     190                 :          1 :     spdm_test_context->case_id = 0x2;
+     191                 :          1 :     spdm_context->connection_info.connection_state =
+     192                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     193                 :          1 :     spdm_context->connection_info.capability.flags |=
+     194                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+     195                 :          1 :     spdm_context->local_context.capability.flags |=
+     196                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+     197                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     198                 :            :         m_libspdm_use_hash_algo;
+     199                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     200                 :            :         m_libspdm_use_asym_algo;
+     201                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     202                 :            :         m_libspdm_use_measurement_spec;
+     203                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     204                 :            :         m_libspdm_use_measurement_hash_algo;
+     205                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     206                 :            :         m_libspdm_use_dhe_algo;
+     207                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     208                 :            :         m_libspdm_use_aead_algo;
+     209                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     210                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     211                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     212                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     213                 :            :                                                     &data_size1, NULL, NULL);
+     214                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     215                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     216                 :            :         data_size1;
+     217                 :            : 
+     218                 :          1 :     libspdm_reset_message_a(spdm_context);
+     219                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     220                 :            : 
+     221                 :          1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+     222                 :            :                               m_libspdm_key_exchange_request2.random_data);
+     223                 :          1 :     m_libspdm_key_exchange_request2.req_session_id = 0xFFFF;
+     224                 :          1 :     m_libspdm_key_exchange_request2.reserved = 0;
+     225                 :          1 :     ptr = m_libspdm_key_exchange_request2.exchange_data;
+     226                 :          1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+     227                 :          1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
+     228                 :            :                                   false);
+     229                 :          1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
+     230                 :          1 :     ptr += dhe_key_size;
+     231                 :          1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+     232                 :          1 :     opaque_key_exchange_req_size =
+     233                 :          1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
+     234                 :          1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
+     235                 :          1 :     ptr += sizeof(uint16_t);
+     236                 :          1 :     libspdm_build_opaque_data_supported_version_data(
+     237                 :            :         spdm_context, &opaque_key_exchange_req_size, ptr);
+     238                 :          1 :     ptr += opaque_key_exchange_req_size;
+     239                 :          1 :     response_size = sizeof(response);
+     240                 :          1 :     status = libspdm_get_response_key_exchange(
+     241                 :            :         spdm_context, m_libspdm_key_exchange_request2_size,
+     242                 :            :         &m_libspdm_key_exchange_request2, &response_size, response);
+     243                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     244                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     245                 :          1 :     spdm_response = (void *)response;
+     246                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     247                 :            :                      SPDM_ERROR);
+     248                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     249                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+     250                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     251                 :          1 :     free(data1);
+     252                 :          1 : }
+     253                 :            : 
+     254                 :          1 : void libspdm_test_responder_key_exchange_case3(void **state)
+     255                 :            : {
+     256                 :            :     libspdm_return_t status;
+     257                 :            :     libspdm_test_context_t *spdm_test_context;
+     258                 :            :     libspdm_context_t *spdm_context;
+     259                 :            :     size_t response_size;
+     260                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     261                 :            :     spdm_key_exchange_response_t *spdm_response;
+     262                 :            :     void *data1;
+     263                 :            :     size_t data_size1;
+     264                 :            :     uint8_t *ptr;
+     265                 :            :     size_t dhe_key_size;
+     266                 :            :     void *dhe_context;
+     267                 :            :     size_t opaque_key_exchange_req_size;
+     268                 :            : 
+     269                 :          1 :     spdm_test_context = *state;
+     270                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     271                 :          1 :     spdm_test_context->case_id = 0x3;
+     272                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_BUSY;
+     273                 :          1 :     spdm_context->connection_info.connection_state =
+     274                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     275                 :          1 :     spdm_context->connection_info.capability.flags |=
+     276                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+     277                 :          1 :     spdm_context->local_context.capability.flags |=
+     278                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+     279                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     280                 :            :         m_libspdm_use_hash_algo;
+     281                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     282                 :            :         m_libspdm_use_asym_algo;
+     283                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     284                 :            :         m_libspdm_use_measurement_spec;
+     285                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     286                 :            :         m_libspdm_use_measurement_hash_algo;
+     287                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     288                 :            :         m_libspdm_use_dhe_algo;
+     289                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     290                 :            :         m_libspdm_use_aead_algo;
+     291                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     292                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     293                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     294                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     295                 :            :                                                     &data_size1, NULL, NULL);
+     296                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     297                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     298                 :            :         data_size1;
+     299                 :            : 
+     300                 :          1 :     libspdm_reset_message_a(spdm_context);
+     301                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     302                 :            : 
+     303                 :          1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+     304                 :            :                               m_libspdm_key_exchange_request1.random_data);
+     305                 :          1 :     m_libspdm_key_exchange_request1.req_session_id = 0xFFFF;
+     306                 :          1 :     m_libspdm_key_exchange_request1.reserved = 0;
+     307                 :          1 :     ptr = m_libspdm_key_exchange_request1.exchange_data;
+     308                 :          1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+     309                 :          1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
+     310                 :            :                                   false);
+     311                 :          1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
+     312                 :          1 :     ptr += dhe_key_size;
+     313                 :          1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+     314                 :          1 :     opaque_key_exchange_req_size =
+     315                 :          1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
+     316                 :          1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
+     317                 :          1 :     ptr += sizeof(uint16_t);
+     318                 :          1 :     libspdm_build_opaque_data_supported_version_data(
+     319                 :            :         spdm_context, &opaque_key_exchange_req_size, ptr);
+     320                 :          1 :     ptr += opaque_key_exchange_req_size;
+     321                 :          1 :     response_size = sizeof(response);
+     322                 :          1 :     status = libspdm_get_response_key_exchange(
+     323                 :            :         spdm_context, m_libspdm_key_exchange_request1_size,
+     324                 :            :         &m_libspdm_key_exchange_request1, &response_size, response);
+     325                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     326                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     327                 :          1 :     spdm_response = (void *)response;
+     328                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     329                 :            :                      SPDM_ERROR);
+     330                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_BUSY);
+     331                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     332                 :          1 :     assert_int_equal(spdm_context->response_state,
+     333                 :            :                      LIBSPDM_RESPONSE_STATE_BUSY);
+     334                 :          1 :     free(data1);
+     335                 :          1 : }
+     336                 :            : 
+     337                 :          1 : void libspdm_test_responder_key_exchange_case4(void **state)
+     338                 :            : {
+     339                 :            :     libspdm_return_t status;
+     340                 :            :     libspdm_test_context_t *spdm_test_context;
+     341                 :            :     libspdm_context_t *spdm_context;
+     342                 :            :     size_t response_size;
+     343                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     344                 :            :     spdm_key_exchange_response_t *spdm_response;
+     345                 :            :     void *data1;
+     346                 :            :     size_t data_size1;
+     347                 :            :     uint8_t *ptr;
+     348                 :            :     size_t dhe_key_size;
+     349                 :            :     void *dhe_context;
+     350                 :            :     size_t opaque_key_exchange_req_size;
+     351                 :            : 
+     352                 :          1 :     spdm_test_context = *state;
+     353                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     354                 :          1 :     spdm_test_context->case_id = 0x4;
+     355                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NEED_RESYNC;
+     356                 :          1 :     spdm_context->connection_info.connection_state =
+     357                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     358                 :          1 :     spdm_context->connection_info.capability.flags |=
+     359                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+     360                 :          1 :     spdm_context->local_context.capability.flags |=
+     361                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+     362                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     363                 :            :         m_libspdm_use_hash_algo;
+     364                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     365                 :            :         m_libspdm_use_asym_algo;
+     366                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     367                 :            :         m_libspdm_use_measurement_spec;
+     368                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     369                 :            :         m_libspdm_use_measurement_hash_algo;
+     370                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     371                 :            :         m_libspdm_use_dhe_algo;
+     372                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     373                 :            :         m_libspdm_use_aead_algo;
+     374                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     375                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     376                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     377                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     378                 :            :                                                     &data_size1, NULL, NULL);
+     379                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     380                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     381                 :            :         data_size1;
+     382                 :            : 
+     383                 :          1 :     libspdm_reset_message_a(spdm_context);
+     384                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     385                 :            : 
+     386                 :          1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+     387                 :            :                               m_libspdm_key_exchange_request1.random_data);
+     388                 :          1 :     m_libspdm_key_exchange_request1.req_session_id = 0xFFFF;
+     389                 :          1 :     m_libspdm_key_exchange_request1.reserved = 0;
+     390                 :          1 :     ptr = m_libspdm_key_exchange_request1.exchange_data;
+     391                 :          1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+     392                 :          1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
+     393                 :            :                                   false);
+     394                 :          1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
+     395                 :          1 :     ptr += dhe_key_size;
+     396                 :          1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+     397                 :          1 :     opaque_key_exchange_req_size =
+     398                 :          1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
+     399                 :          1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
+     400                 :          1 :     ptr += sizeof(uint16_t);
+     401                 :          1 :     libspdm_build_opaque_data_supported_version_data(
+     402                 :            :         spdm_context, &opaque_key_exchange_req_size, ptr);
+     403                 :          1 :     ptr += opaque_key_exchange_req_size;
+     404                 :          1 :     response_size = sizeof(response);
+     405                 :          1 :     status = libspdm_get_response_key_exchange(
+     406                 :            :         spdm_context, m_libspdm_key_exchange_request1_size,
+     407                 :            :         &m_libspdm_key_exchange_request1, &response_size, response);
+     408                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     409                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     410                 :          1 :     spdm_response = (void *)response;
+     411                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     412                 :            :                      SPDM_ERROR);
+     413                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     414                 :            :                      SPDM_ERROR_CODE_REQUEST_RESYNCH);
+     415                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     416                 :          1 :     assert_int_equal(spdm_context->response_state,
+     417                 :            :                      LIBSPDM_RESPONSE_STATE_NEED_RESYNC);
+     418                 :          1 :     free(data1);
+     419                 :          1 : }
+     420                 :            : 
+     421                 :            : #if LIBSPDM_RESPOND_IF_READY_SUPPORT
+     422                 :          1 : void libspdm_test_responder_key_exchange_case5(void **state)
+     423                 :            : {
+     424                 :            :     libspdm_return_t status;
+     425                 :            :     libspdm_test_context_t *spdm_test_context;
+     426                 :            :     libspdm_context_t *spdm_context;
+     427                 :            :     size_t response_size;
+     428                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     429                 :            :     spdm_key_exchange_response_t *spdm_response;
+     430                 :            :     void *data1;
+     431                 :            :     size_t data_size1;
+     432                 :            :     spdm_error_data_response_not_ready_t *error_data;
+     433                 :            :     uint8_t *ptr;
+     434                 :            :     size_t dhe_key_size;
+     435                 :            :     void *dhe_context;
+     436                 :            :     size_t opaque_key_exchange_req_size;
+     437                 :            : 
+     438                 :          1 :     spdm_test_context = *state;
+     439                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     440                 :          1 :     spdm_test_context->case_id = 0x5;
+     441                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NOT_READY;
+     442                 :          1 :     spdm_context->connection_info.connection_state =
+     443                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     444                 :          1 :     spdm_context->connection_info.capability.flags |=
+     445                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+     446                 :          1 :     spdm_context->local_context.capability.flags |=
+     447                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+     448                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     449                 :            :         m_libspdm_use_hash_algo;
+     450                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     451                 :            :         m_libspdm_use_asym_algo;
+     452                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     453                 :            :         m_libspdm_use_measurement_spec;
+     454                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     455                 :            :         m_libspdm_use_measurement_hash_algo;
+     456                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     457                 :            :         m_libspdm_use_dhe_algo;
+     458                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     459                 :            :         m_libspdm_use_aead_algo;
+     460                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     461                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     462                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     463                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     464                 :            :                                                     &data_size1, NULL, NULL);
+     465                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     466                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     467                 :            :         data_size1;
+     468                 :            : 
+     469                 :          1 :     libspdm_reset_message_a(spdm_context);
+     470                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     471                 :            : 
+     472                 :          1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+     473                 :            :                               m_libspdm_key_exchange_request1.random_data);
+     474                 :          1 :     m_libspdm_key_exchange_request1.req_session_id = 0xFFFF;
+     475                 :          1 :     m_libspdm_key_exchange_request1.reserved = 0;
+     476                 :          1 :     ptr = m_libspdm_key_exchange_request1.exchange_data;
+     477                 :          1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+     478                 :          1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
+     479                 :            :                                   false);
+     480                 :          1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
+     481                 :          1 :     ptr += dhe_key_size;
+     482                 :          1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+     483                 :          1 :     opaque_key_exchange_req_size =
+     484                 :          1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
+     485                 :          1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
+     486                 :          1 :     ptr += sizeof(uint16_t);
+     487                 :          1 :     libspdm_build_opaque_data_supported_version_data(
+     488                 :            :         spdm_context, &opaque_key_exchange_req_size, ptr);
+     489                 :          1 :     ptr += opaque_key_exchange_req_size;
+     490                 :          1 :     response_size = sizeof(response);
+     491                 :          1 :     status = libspdm_get_response_key_exchange(
+     492                 :            :         spdm_context, m_libspdm_key_exchange_request1_size,
+     493                 :            :         &m_libspdm_key_exchange_request1, &response_size, response);
+     494                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     495                 :          1 :     assert_int_equal(response_size,
+     496                 :            :                      sizeof(spdm_error_response_t) +
+     497                 :            :                      sizeof(spdm_error_data_response_not_ready_t));
+     498                 :          1 :     spdm_response = (void *)response;
+     499                 :          1 :     error_data = (spdm_error_data_response_not_ready_t
+     500                 :            :                   *)(&spdm_response->rsp_session_id);
+     501                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     502                 :            :                      SPDM_ERROR);
+     503                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     504                 :            :                      SPDM_ERROR_CODE_RESPONSE_NOT_READY);
+     505                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     506                 :          1 :     assert_int_equal(spdm_context->response_state,
+     507                 :            :                      LIBSPDM_RESPONSE_STATE_NOT_READY);
+     508                 :          1 :     assert_int_equal(error_data->request_code, SPDM_KEY_EXCHANGE);
+     509                 :          1 :     free(data1);
+     510                 :          1 : }
+     511                 :            : #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
+     512                 :            : 
+     513                 :          1 : void libspdm_test_responder_key_exchange_case6(void **state)
+     514                 :            : {
+     515                 :            :     libspdm_return_t status;
+     516                 :            :     libspdm_test_context_t *spdm_test_context;
+     517                 :            :     libspdm_context_t *spdm_context;
+     518                 :            :     size_t response_size;
+     519                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     520                 :            :     spdm_key_exchange_response_t *spdm_response;
+     521                 :            :     void *data1;
+     522                 :            :     size_t data_size1;
+     523                 :            :     uint8_t *ptr;
+     524                 :            :     size_t dhe_key_size;
+     525                 :            :     void *dhe_context;
+     526                 :            :     size_t opaque_key_exchange_req_size;
+     527                 :            : 
+     528                 :          1 :     spdm_test_context = *state;
+     529                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     530                 :          1 :     spdm_test_context->case_id = 0x6;
+     531                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+     532                 :          1 :     spdm_context->connection_info.connection_state =
+     533                 :            :         LIBSPDM_CONNECTION_STATE_NOT_STARTED;
+     534                 :          1 :     spdm_context->connection_info.capability.flags |=
+     535                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+     536                 :          1 :     spdm_context->local_context.capability.flags |=
+     537                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+     538                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     539                 :            :         m_libspdm_use_hash_algo;
+     540                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     541                 :            :         m_libspdm_use_asym_algo;
+     542                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     543                 :            :         m_libspdm_use_measurement_spec;
+     544                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     545                 :            :         m_libspdm_use_measurement_hash_algo;
+     546                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     547                 :            :         m_libspdm_use_dhe_algo;
+     548                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     549                 :            :         m_libspdm_use_aead_algo;
+     550                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     551                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     552                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     553                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     554                 :            :                                                     &data_size1, NULL, NULL);
+     555                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     556                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     557                 :            :         data_size1;
+     558                 :            : 
+     559                 :          1 :     libspdm_reset_message_a(spdm_context);
+     560                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     561                 :            : 
+     562                 :          1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+     563                 :            :                               m_libspdm_key_exchange_request1.random_data);
+     564                 :          1 :     m_libspdm_key_exchange_request1.req_session_id = 0xFFFF;
+     565                 :          1 :     m_libspdm_key_exchange_request1.reserved = 0;
+     566                 :          1 :     ptr = m_libspdm_key_exchange_request1.exchange_data;
+     567                 :          1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+     568                 :          1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
+     569                 :            :                                   false);
+     570                 :          1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
+     571                 :          1 :     ptr += dhe_key_size;
+     572                 :          1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+     573                 :          1 :     opaque_key_exchange_req_size =
+     574                 :          1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
+     575                 :          1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
+     576                 :          1 :     ptr += sizeof(uint16_t);
+     577                 :          1 :     libspdm_build_opaque_data_supported_version_data(
+     578                 :            :         spdm_context, &opaque_key_exchange_req_size, ptr);
+     579                 :          1 :     ptr += opaque_key_exchange_req_size;
+     580                 :          1 :     response_size = sizeof(response);
+     581                 :          1 :     status = libspdm_get_response_key_exchange(
+     582                 :            :         spdm_context, m_libspdm_key_exchange_request1_size,
+     583                 :            :         &m_libspdm_key_exchange_request1, &response_size, response);
+     584                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     585                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     586                 :          1 :     spdm_response = (void *)response;
+     587                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     588                 :            :                      SPDM_ERROR);
+     589                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     590                 :            :                      SPDM_ERROR_CODE_UNEXPECTED_REQUEST);
+     591                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     592                 :          1 :     free(data1);
+     593                 :          1 : }
+     594                 :            : 
+     595                 :          1 : void libspdm_test_responder_key_exchange_case7(void **state)
+     596                 :            : {
+     597                 :            :     libspdm_return_t status;
+     598                 :            :     libspdm_test_context_t *spdm_test_context;
+     599                 :            :     libspdm_context_t *spdm_context;
+     600                 :            :     size_t response_size;
+     601                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     602                 :            :     spdm_key_exchange_response_t *spdm_response;
+     603                 :            :     void *data1;
+     604                 :            :     size_t data_size1;
+     605                 :            :     uint8_t *ptr;
+     606                 :            :     size_t dhe_key_size;
+     607                 :            :     void *dhe_context;
+     608                 :            :     size_t opaque_key_exchange_req_size;
+     609                 :            : 
+     610                 :          1 :     spdm_test_context = *state;
+     611                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     612                 :          1 :     spdm_test_context->case_id = 0x1;
+     613                 :          1 :     spdm_context->connection_info.connection_state =
+     614                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     615                 :          1 :     spdm_context->connection_info.capability.flags |=
+     616                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+     617                 :          1 :     spdm_context->local_context.capability.flags |=
+     618                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+     619                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     620                 :            :         m_libspdm_use_hash_algo;
+     621                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     622                 :            :         m_libspdm_use_asym_algo;
+     623                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     624                 :            :         m_libspdm_use_measurement_spec;
+     625                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     626                 :            :         m_libspdm_use_measurement_hash_algo;
+     627                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     628                 :            :         m_libspdm_use_dhe_algo;
+     629                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     630                 :            :         m_libspdm_use_aead_algo;
+     631                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     632                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     633                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     634                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     635                 :            :                                                     &data_size1, NULL, NULL);
+     636                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     637                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     638                 :            :         data_size1;
+     639                 :            : 
+     640                 :          1 :     libspdm_reset_message_a(spdm_context);
+     641                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     642                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     643                 :            :     spdm_context->transcript.message_m.buffer_size =
+     644                 :            :         spdm_context->transcript.message_m.max_buffer_size;
+     645                 :            :     spdm_context->transcript.message_b.buffer_size =
+     646                 :            :         spdm_context->transcript.message_b.max_buffer_size;
+     647                 :            :     spdm_context->transcript.message_c.buffer_size =
+     648                 :            :         spdm_context->transcript.message_c.max_buffer_size;
+     649                 :            :     spdm_context->transcript.message_mut_b.buffer_size =
+     650                 :            :         spdm_context->transcript.message_mut_b.max_buffer_size;
+     651                 :            :     spdm_context->transcript.message_mut_c.buffer_size =
+     652                 :            :         spdm_context->transcript.message_mut_c.max_buffer_size;
+     653                 :            : #endif
+     654                 :            : 
+     655                 :          1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+     656                 :            :                               m_libspdm_key_exchange_request1.random_data);
+     657                 :          1 :     m_libspdm_key_exchange_request1.req_session_id = 0xFFFF;
+     658                 :          1 :     m_libspdm_key_exchange_request1.reserved = 0;
+     659                 :          1 :     ptr = m_libspdm_key_exchange_request1.exchange_data;
+     660                 :          1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+     661                 :          1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
+     662                 :            :                                   false);
+     663                 :          1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
+     664                 :          1 :     ptr += dhe_key_size;
+     665                 :          1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+     666                 :          1 :     opaque_key_exchange_req_size =
+     667                 :          1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
+     668                 :          1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
+     669                 :          1 :     ptr += sizeof(uint16_t);
+     670                 :          1 :     libspdm_build_opaque_data_supported_version_data(
+     671                 :            :         spdm_context, &opaque_key_exchange_req_size, ptr);
+     672                 :          1 :     ptr += opaque_key_exchange_req_size;
+     673                 :          1 :     response_size = sizeof(response);
+     674                 :          1 :     status = libspdm_get_response_key_exchange(
+     675                 :            :         spdm_context, m_libspdm_key_exchange_request1_size,
+     676                 :            :         &m_libspdm_key_exchange_request1, &response_size, response);
+     677                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     678                 :          1 :     assert_int_equal(
+     679                 :            :         libspdm_secured_message_get_session_state(
+     680                 :            :             spdm_context->session_info[0].secured_message_context),
+     681                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+     682                 :          1 :     spdm_response = (void *)response;
+     683                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     684                 :            :                      SPDM_KEY_EXCHANGE_RSP);
+     685                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     686                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+     687                 :            :     assert_int_equal(spdm_context->transcript.message_b.buffer_size, 0);
+     688                 :            :     assert_int_equal(spdm_context->transcript.message_c.buffer_size, 0);
+     689                 :            :     assert_int_equal(spdm_context->transcript.message_mut_b.buffer_size, 0);
+     690                 :            :     assert_int_equal(spdm_context->transcript.message_mut_c.buffer_size, 0);
+     691                 :            : #endif
+     692                 :            : 
+     693                 :          1 :     free(data1);
+     694                 :          1 : }
+     695                 :            : 
+     696                 :          1 : void libspdm_test_responder_key_exchange_case8(void **state)
+     697                 :            : {
+     698                 :            :     libspdm_return_t status;
+     699                 :            :     libspdm_test_context_t *spdm_test_context;
+     700                 :            :     libspdm_context_t *spdm_context;
+     701                 :            :     size_t response_size;
+     702                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     703                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
+     704                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+     705                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP */
+     706                 :            :     uint32_t measurement_summary_hash_size;
+     707                 :            :     spdm_key_exchange_response_t *spdm_response;
+     708                 :            :     void *data1;
+     709                 :            :     size_t data_size1;
+     710                 :            :     uint8_t *ptr;
+     711                 :            :     size_t dhe_key_size;
+     712                 :            :     void *dhe_context;
+     713                 :            :     size_t opaque_key_exchange_req_size;
+     714                 :            : 
+     715                 :          1 :     spdm_test_context = *state;
+     716                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     717                 :          1 :     spdm_test_context->case_id = 0x8;
+     718                 :            : 
+     719                 :            :     /* Clear previous sessions */
+     720         [ +  - ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+     721                 :          1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+     722                 :            :     }
+     723                 :            : 
+     724                 :          1 :     spdm_context->connection_info.connection_state =
+     725                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     726                 :          1 :     spdm_context->connection_info.capability.flags |=
+     727                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+     728                 :          1 :     spdm_context->local_context.capability.flags |=
+     729                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+     730                 :          1 :     spdm_context->local_context.capability.flags |=
+     731                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP;
+     732                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     733                 :            :         m_libspdm_use_hash_algo;
+     734                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     735                 :            :         m_libspdm_use_asym_algo;
+     736                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     737                 :            :         m_libspdm_use_measurement_spec;
+     738                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     739                 :            :         m_libspdm_use_measurement_hash_algo;
+     740                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     741                 :            :         m_libspdm_use_dhe_algo;
+     742                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     743                 :            :         m_libspdm_use_aead_algo;
+     744                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     745                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     746                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     747                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     748                 :            :                                                     &data_size1, NULL, NULL);
+     749                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     750                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     751                 :            :         data_size1;
+     752                 :            : 
+     753                 :          1 :     libspdm_reset_message_a(spdm_context);
+     754                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     755                 :            : 
+     756                 :          1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+     757                 :            :                               m_libspdm_key_exchange_request3.random_data);
+     758                 :          1 :     m_libspdm_key_exchange_request3.req_session_id = 0xFFFF;
+     759                 :          1 :     m_libspdm_key_exchange_request3.reserved = 0;
+     760                 :          1 :     ptr = m_libspdm_key_exchange_request3.exchange_data;
+     761                 :          1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+     762                 :          1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
+     763                 :            :                                   false);
+     764                 :          1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
+     765                 :          1 :     ptr += dhe_key_size;
+     766                 :          1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+     767                 :          1 :     opaque_key_exchange_req_size =
+     768                 :          1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
+     769                 :          1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
+     770                 :          1 :     ptr += sizeof(uint16_t);
+     771                 :          1 :     libspdm_build_opaque_data_supported_version_data(
+     772                 :            :         spdm_context, &opaque_key_exchange_req_size, ptr);
+     773                 :          1 :     ptr += opaque_key_exchange_req_size;
+     774                 :          1 :     response_size = sizeof(response);
+     775                 :          1 :     status = libspdm_get_response_key_exchange(
+     776                 :            :         spdm_context, m_libspdm_key_exchange_request3_size,
+     777                 :            :         &m_libspdm_key_exchange_request3, &response_size, response);
+     778                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     779                 :          1 :     assert_int_equal(
+     780                 :            :         libspdm_secured_message_get_session_state(
+     781                 :            :             spdm_context->session_info[0].secured_message_context),
+     782                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+     783                 :          1 :     spdm_response = (void *)response;
+     784                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     785                 :            :                      SPDM_KEY_EXCHANGE_RSP);
+     786                 :          1 :     assert_int_equal(spdm_response->rsp_session_id, 0xFFFF);
+     787                 :            : 
+     788                 :          1 :     measurement_summary_hash_size = libspdm_get_measurement_summary_hash_size(
+     789                 :          1 :         spdm_context, false, m_libspdm_key_exchange_request3.header.param1);
+     790                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
+     791                 :          1 :     libspdm_generate_measurement_summary_hash(
+     792                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+     793                 :            :         spdm_context,
+     794                 :            : #endif
+     795                 :          1 :         spdm_context->connection_info.version,
+     796                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+     797                 :          1 :         spdm_context->connection_info.algorithm.measurement_spec,
+     798                 :            :         spdm_context->connection_info.algorithm.measurement_hash_algo,
+     799                 :          1 :         m_libspdm_key_exchange_request3.header.param1,
+     800                 :            :         measurement_hash,
+     801                 :            :         measurement_summary_hash_size);
+     802                 :            : 
+     803                 :          1 :     assert_memory_equal(
+     804                 :            :         (uint8_t *)response +
+     805                 :            :         sizeof(spdm_key_exchange_response_t) +
+     806                 :            :         dhe_key_size,
+     807                 :            :         measurement_hash,
+     808                 :            :         measurement_summary_hash_size);
+     809                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP */
+     810                 :          1 :     free(data1);
+     811                 :          1 : }
+     812                 :            : 
+     813                 :          1 : void libspdm_test_responder_key_exchange_case9(void **state)
+     814                 :            : {
+     815                 :            :     libspdm_return_t status;
+     816                 :            :     libspdm_test_context_t *spdm_test_context;
+     817                 :            :     libspdm_context_t *spdm_context;
+     818                 :            :     size_t response_size;
+     819                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     820                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
+     821                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+     822                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP */
+     823                 :            :     uint32_t measurement_summary_hash_size;
+     824                 :            :     spdm_key_exchange_response_t *spdm_response;
+     825                 :            :     void *data1;
+     826                 :            :     size_t data_size1;
+     827                 :            :     uint8_t *ptr;
+     828                 :            :     size_t dhe_key_size;
+     829                 :            :     void *dhe_context;
+     830                 :            :     size_t opaque_key_exchange_req_size;
+     831                 :            :     uint32_t session_id;
+     832                 :            : 
+     833                 :          1 :     spdm_test_context = *state;
+     834                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     835                 :          1 :     spdm_test_context->case_id = 0x9;
+     836                 :            : 
+     837                 :            :     /* Clear previous sessions */
+     838         [ +  - ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+     839                 :          1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+     840                 :            :     }
+     841                 :            : 
+     842                 :          1 :     spdm_context->connection_info.connection_state =
+     843                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     844                 :          1 :     spdm_context->connection_info.capability.flags |=
+     845                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+     846                 :          1 :     spdm_context->local_context.capability.flags |=
+     847                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+     848                 :          1 :     spdm_context->local_context.capability.flags |=
+     849                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP;
+     850                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     851                 :            :         m_libspdm_use_hash_algo;
+     852                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     853                 :            :         m_libspdm_use_asym_algo;
+     854                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     855                 :            :         m_libspdm_use_measurement_spec;
+     856                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     857                 :            :         m_libspdm_use_measurement_hash_algo;
+     858                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     859                 :            :         m_libspdm_use_dhe_algo;
+     860                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     861                 :            :         m_libspdm_use_aead_algo;
+     862                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     863                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     864                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     865                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     866                 :            :                                                     &data_size1, NULL, NULL);
+     867                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     868                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     869                 :            :         data_size1;
+     870                 :            : 
+     871                 :          1 :     libspdm_reset_message_a(spdm_context);
+     872                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     873                 :            : 
+     874                 :          1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+     875                 :            :                               m_libspdm_key_exchange_request4.random_data);
+     876                 :          1 :     m_libspdm_key_exchange_request4.req_session_id = 0xFFFF;
+     877                 :          1 :     m_libspdm_key_exchange_request4.reserved = 0;
+     878                 :          1 :     ptr = m_libspdm_key_exchange_request4.exchange_data;
+     879                 :          1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+     880                 :          1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
+     881                 :            :                                   false);
+     882                 :          1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
+     883                 :          1 :     ptr += dhe_key_size;
+     884                 :          1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+     885                 :          1 :     opaque_key_exchange_req_size =
+     886                 :          1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
+     887                 :          1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
+     888                 :          1 :     ptr += sizeof(uint16_t);
+     889                 :          1 :     libspdm_build_opaque_data_supported_version_data(
+     890                 :            :         spdm_context, &opaque_key_exchange_req_size, ptr);
+     891                 :          1 :     ptr += opaque_key_exchange_req_size;
+     892                 :          1 :     response_size = sizeof(response);
+     893                 :          1 :     status = libspdm_get_response_key_exchange(
+     894                 :            :         spdm_context, m_libspdm_key_exchange_request4_size,
+     895                 :            :         &m_libspdm_key_exchange_request4, &response_size, response);
+     896                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     897                 :          1 :     assert_int_equal(
+     898                 :            :         libspdm_secured_message_get_session_state(
+     899                 :            :             spdm_context->session_info[0].secured_message_context),
+     900                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+     901                 :          1 :     spdm_response = (void *)response;
+     902                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     903                 :            :                      SPDM_KEY_EXCHANGE_RSP);
+     904                 :          1 :     assert_int_equal(spdm_response->rsp_session_id, 0xFFFF);
+     905                 :            : 
+     906                 :          1 :     measurement_summary_hash_size = libspdm_get_measurement_summary_hash_size(
+     907                 :          1 :         spdm_context, false, m_libspdm_key_exchange_request4.header.param1);
+     908                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
+     909                 :          1 :     libspdm_generate_measurement_summary_hash(
+     910                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+     911                 :            :         spdm_context,
+     912                 :            : #endif
+     913                 :          1 :         spdm_context->connection_info.version,
+     914                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+     915                 :          1 :         spdm_context->connection_info.algorithm.measurement_spec,
+     916                 :            :         spdm_context->connection_info.algorithm.measurement_hash_algo,
+     917                 :          1 :         m_libspdm_key_exchange_request4.header.param1,
+     918                 :            :         measurement_hash,
+     919                 :            :         measurement_summary_hash_size);
+     920                 :            : 
+     921                 :          1 :     assert_memory_equal(
+     922                 :            :         (uint8_t *)response +
+     923                 :            :         sizeof(spdm_key_exchange_response_t) +
+     924                 :            :         dhe_key_size,
+     925                 :            :         measurement_hash,
+     926                 :            :         measurement_summary_hash_size);
+     927                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP */
+     928                 :            : 
+     929                 :          1 :     session_id = (m_libspdm_key_exchange_request4.req_session_id << 16) |
+     930                 :          1 :                  spdm_response->rsp_session_id;
+     931                 :          1 :     libspdm_free_session_id(spdm_context, session_id);
+     932                 :            : 
+     933                 :          1 :     free(data1);
+     934                 :          1 : }
+     935                 :            : 
+     936                 :          1 : void libspdm_test_responder_key_exchange_case10(void **state)
+     937                 :            : {
+     938                 :            :     libspdm_return_t status;
+     939                 :            :     libspdm_test_context_t *spdm_test_context;
+     940                 :            :     libspdm_context_t *spdm_context;
+     941                 :            :     size_t response_size;
+     942                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     943                 :            :     spdm_key_exchange_response_t *spdm_response;
+     944                 :            :     void *data1;
+     945                 :            :     size_t data_size1;
+     946                 :            :     uint8_t *ptr;
+     947                 :            :     size_t dhe_key_size;
+     948                 :            :     void *dhe_context;
+     949                 :            :     size_t opaque_key_exchange_req_size;
+     950                 :            : 
+     951                 :          1 :     spdm_test_context = *state;
+     952                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     953                 :          1 :     spdm_test_context->case_id = 0xA;
+     954                 :            : 
+     955                 :            :     /* Clear previous sessions */
+     956         [ -  + ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+     957                 :          0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+     958                 :            :     }
+     959                 :            : 
+     960                 :          1 :     spdm_context->connection_info.connection_state =
+     961                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     962                 :          1 :     spdm_context->connection_info.capability.flags |=
+     963                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+     964                 :          1 :     spdm_context->local_context.capability.flags |=
+     965                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+     966                 :          1 :     spdm_context->local_context.capability.flags |=
+     967                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP;
+     968                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     969                 :            :         m_libspdm_use_hash_algo;
+     970                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     971                 :            :         m_libspdm_use_asym_algo;
+     972                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     973                 :            :         m_libspdm_use_measurement_spec;
+     974                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     975                 :            :         m_libspdm_use_measurement_hash_algo;
+     976                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     977                 :            :         m_libspdm_use_dhe_algo;
+     978                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     979                 :            :         m_libspdm_use_aead_algo;
+     980                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     981                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     982                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     983                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     984                 :            :                                                     &data_size1, NULL, NULL);
+     985                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     986                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     987                 :            :         data_size1;
+     988                 :            : 
+     989                 :          1 :     libspdm_reset_message_a(spdm_context);
+     990                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     991                 :            : 
+     992                 :          1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+     993                 :            :                               m_libspdm_key_exchange_request5.random_data);
+     994                 :          1 :     m_libspdm_key_exchange_request5.req_session_id = 0xFFFF;
+     995                 :          1 :     m_libspdm_key_exchange_request5.reserved = 0;
+     996                 :          1 :     ptr = m_libspdm_key_exchange_request5.exchange_data;
+     997                 :          1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+     998                 :          1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
+     999                 :            :                                   false);
+    1000                 :          1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
+    1001                 :          1 :     ptr += dhe_key_size;
+    1002                 :          1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    1003                 :          1 :     opaque_key_exchange_req_size =
+    1004                 :          1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
+    1005                 :          1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
+    1006                 :          1 :     ptr += sizeof(uint16_t);
+    1007                 :          1 :     libspdm_build_opaque_data_supported_version_data(
+    1008                 :            :         spdm_context, &opaque_key_exchange_req_size, ptr);
+    1009                 :          1 :     ptr += opaque_key_exchange_req_size;
+    1010                 :          1 :     response_size = sizeof(response);
+    1011                 :          1 :     status = libspdm_get_response_key_exchange(
+    1012                 :            :         spdm_context, m_libspdm_key_exchange_request5_size,
+    1013                 :            :         &m_libspdm_key_exchange_request5, &response_size, response);
+    1014                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1015                 :            : 
+    1016                 :          1 :     spdm_response = (void *)response;
+    1017                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1018                 :            :                      SPDM_ERROR);
+    1019                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+    1020                 :            : 
+    1021                 :          1 :     free(data1);
+    1022                 :          1 : }
+    1023                 :            : 
+    1024                 :          1 : void libspdm_test_responder_key_exchange_case11(void **state)
+    1025                 :            : {
+    1026                 :            :     libspdm_return_t status;
+    1027                 :            :     libspdm_test_context_t *spdm_test_context;
+    1028                 :            :     libspdm_context_t *spdm_context;
+    1029                 :            :     size_t response_size;
+    1030                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1031                 :            :     spdm_key_exchange_response_t *spdm_response;
+    1032                 :            :     void *data1;
+    1033                 :            :     size_t data_size1;
+    1034                 :            :     uint8_t *ptr;
+    1035                 :            :     size_t dhe_key_size;
+    1036                 :            :     void *dhe_context;
+    1037                 :            :     size_t opaque_key_exchange_req_size;
+    1038                 :            : 
+    1039                 :          1 :     spdm_test_context = *state;
+    1040                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1041                 :          1 :     spdm_test_context->case_id = 0xB;
+    1042                 :            : 
+    1043                 :            :     /* Clear previous sessions */
+    1044         [ -  + ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    1045                 :          0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    1046                 :            :     }
+    1047                 :            : 
+    1048                 :          1 :     spdm_context->connection_info.connection_state =
+    1049                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1050                 :            : 
+    1051                 :            :     /* Clear capabilities flag */
+    1052                 :          1 :     spdm_context->local_context.capability.flags &=
+    1053                 :            :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP;
+    1054                 :            : 
+    1055                 :            :     /*set capabilities flags */
+    1056                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1057                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    1058                 :          1 :     spdm_context->local_context.capability.flags |=
+    1059                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    1060                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1061                 :            :         m_libspdm_use_hash_algo;
+    1062                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1063                 :            :         m_libspdm_use_asym_algo;
+    1064                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    1065                 :            :         m_libspdm_use_measurement_spec;
+    1066                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1067                 :            :         m_libspdm_use_measurement_hash_algo;
+    1068                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1069                 :            :         m_libspdm_use_dhe_algo;
+    1070                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1071                 :            :         m_libspdm_use_aead_algo;
+    1072                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1073                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1074                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1075                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    1076                 :            :                                                     &data_size1, NULL, NULL);
+    1077                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    1078                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    1079                 :            :         data_size1;
+    1080                 :            : 
+    1081                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1082                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+    1083                 :            : 
+    1084                 :          1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    1085                 :            :                               m_libspdm_key_exchange_request3.random_data);
+    1086                 :          1 :     m_libspdm_key_exchange_request3.req_session_id = 0xFFFF;
+    1087                 :          1 :     m_libspdm_key_exchange_request3.reserved = 0;
+    1088                 :          1 :     ptr = m_libspdm_key_exchange_request3.exchange_data;
+    1089                 :          1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    1090                 :          1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
+    1091                 :            :                                   false);
+    1092                 :          1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
+    1093                 :          1 :     ptr += dhe_key_size;
+    1094                 :          1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    1095                 :          1 :     opaque_key_exchange_req_size =
+    1096                 :          1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
+    1097                 :          1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
+    1098                 :          1 :     ptr += sizeof(uint16_t);
+    1099                 :          1 :     libspdm_build_opaque_data_supported_version_data(
+    1100                 :            :         spdm_context, &opaque_key_exchange_req_size, ptr);
+    1101                 :          1 :     ptr += opaque_key_exchange_req_size;
+    1102                 :          1 :     response_size = sizeof(response);
+    1103                 :          1 :     status = libspdm_get_response_key_exchange(
+    1104                 :            :         spdm_context, m_libspdm_key_exchange_request3_size,
+    1105                 :            :         &m_libspdm_key_exchange_request3, &response_size, response);
+    1106                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1107                 :            : 
+    1108                 :          1 :     spdm_response = (void *)response;
+    1109                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1110                 :            :                      SPDM_ERROR);
+    1111                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+    1112                 :            : 
+    1113                 :          1 :     free(data1);
+    1114                 :          1 : }
+    1115                 :            : 
+    1116                 :          1 : void libspdm_test_responder_key_exchange_case14(void **state)
+    1117                 :            : {
+    1118                 :            :     libspdm_return_t status;
+    1119                 :            :     libspdm_test_context_t *spdm_test_context;
+    1120                 :            :     libspdm_context_t *spdm_context;
+    1121                 :            :     size_t response_size;
+    1122                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1123                 :            :     spdm_key_exchange_response_t *spdm_response;
+    1124                 :            :     void *data1;
+    1125                 :            :     size_t data_size1;
+    1126                 :            :     void *data2;
+    1127                 :            :     size_t data_size2;
+    1128                 :            :     uint8_t *ptr;
+    1129                 :            :     size_t dhe_key_size;
+    1130                 :            :     void *dhe_context;
+    1131                 :            :     size_t opaque_key_exchange_req_size;
+    1132                 :            : 
+    1133                 :          1 :     spdm_test_context = *state;
+    1134                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1135                 :          1 :     spdm_test_context->case_id = 0xE;
+    1136                 :            : 
+    1137                 :            :     /* Clear previous sessions */
+    1138         [ -  + ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    1139                 :          0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    1140                 :            :     }
+    1141                 :            : 
+    1142                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1143                 :          1 :     spdm_context->connection_info.capability.flags =
+    1144                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    1145                 :          1 :     spdm_context->local_context.capability.flags =
+    1146                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    1147                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1148                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PUB_KEY_ID_CAP;
+    1149                 :          1 :     spdm_context->local_context.capability.flags |=
+    1150                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PUB_KEY_ID_CAP;
+    1151                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1152                 :            :         m_libspdm_use_hash_algo;
+    1153                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1154                 :            :         m_libspdm_use_asym_algo;
+    1155                 :          1 :     spdm_context->connection_info.algorithm.req_base_asym_alg =
+    1156                 :            :         m_libspdm_use_req_asym_algo;
+    1157                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    1158                 :            :         m_libspdm_use_measurement_spec;
+    1159                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1160                 :            :         m_libspdm_use_measurement_hash_algo;
+    1161                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1162                 :            :         m_libspdm_use_dhe_algo;
+    1163                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1164                 :            :         m_libspdm_use_aead_algo;
+    1165                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1166                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1167                 :          1 :     libspdm_read_responder_public_key(m_libspdm_use_asym_algo, &data1, &data_size1);
+    1168                 :          1 :     spdm_context->local_context.local_public_key_provision = data1;
+    1169                 :          1 :     spdm_context->local_context.local_public_key_provision_size = data_size1;
+    1170                 :          1 :     libspdm_read_requester_public_key(m_libspdm_use_req_asym_algo, &data2, &data_size2);
+    1171                 :          1 :     spdm_context->local_context.peer_public_key_provision = data2;
+    1172                 :          1 :     spdm_context->local_context.peer_public_key_provision_size = data_size2;
+    1173                 :            : 
+    1174                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1175                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+    1176                 :            : 
+    1177                 :          1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    1178                 :            :                               m_libspdm_key_exchange_request7.random_data);
+    1179                 :          1 :     m_libspdm_key_exchange_request7.req_session_id = 0xFFFF;
+    1180                 :          1 :     m_libspdm_key_exchange_request7.reserved = 0;
+    1181                 :          1 :     ptr = m_libspdm_key_exchange_request7.exchange_data;
+    1182                 :          1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    1183                 :          1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
+    1184                 :            :                                   false);
+    1185                 :          1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
+    1186                 :          1 :     ptr += dhe_key_size;
+    1187                 :          1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    1188                 :          1 :     opaque_key_exchange_req_size =
+    1189                 :          1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
+    1190                 :          1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
+    1191                 :          1 :     ptr += sizeof(uint16_t);
+    1192                 :          1 :     libspdm_build_opaque_data_supported_version_data(
+    1193                 :            :         spdm_context, &opaque_key_exchange_req_size, ptr);
+    1194                 :          1 :     ptr += opaque_key_exchange_req_size;
+    1195                 :          1 :     response_size = sizeof(response);
+    1196                 :          1 :     status = libspdm_get_response_key_exchange(
+    1197                 :            :         spdm_context, m_libspdm_key_exchange_request7_size,
+    1198                 :            :         &m_libspdm_key_exchange_request7, &response_size, response);
+    1199                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1200                 :          1 :     assert_int_equal(
+    1201                 :            :         libspdm_secured_message_get_session_state(
+    1202                 :            :             spdm_context->session_info[0].secured_message_context),
+    1203                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    1204                 :          1 :     spdm_response = (void *)response;
+    1205                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1206                 :            :                      SPDM_KEY_EXCHANGE_RSP);
+    1207                 :          1 :     assert_int_equal(spdm_response->rsp_session_id, 0xFFFF);
+    1208                 :          1 :     free(data1);
+    1209                 :          1 :     free(data2);
+    1210                 :          1 : }
+    1211                 :            : 
+    1212                 :          1 : void libspdm_test_responder_key_exchange_case15(void **state)
+    1213                 :            : {
+    1214                 :            :     libspdm_return_t status;
+    1215                 :            :     libspdm_test_context_t *spdm_test_context;
+    1216                 :            :     libspdm_context_t *spdm_context;
+    1217                 :            :     size_t response_size;
+    1218                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1219                 :            :     spdm_key_exchange_response_t *spdm_response;
+    1220                 :            :     void *data1;
+    1221                 :            :     size_t data_size1;
+    1222                 :            :     uint8_t *ptr;
+    1223                 :            :     size_t dhe_key_size;
+    1224                 :            :     void *dhe_context;
+    1225                 :            :     size_t opaque_key_exchange_req_size;
+    1226                 :            :     size_t opaque_key_exchange_rsp_size;
+    1227                 :            : 
+    1228                 :          1 :     spdm_test_context = *state;
+    1229                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1230                 :          1 :     spdm_test_context->case_id = 0xF;
+    1231                 :            : 
+    1232                 :            :     /* Clear previous sessions */
+    1233         [ +  - ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    1234                 :          1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    1235                 :            :     }
+    1236                 :            : 
+    1237                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1238                 :          1 :     spdm_context->connection_info.capability.flags =
+    1239                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    1240                 :          1 :     spdm_context->local_context.capability.flags =
+    1241                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    1242                 :            : 
+    1243                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1244                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+    1245                 :          1 :     spdm_context->local_context.capability.flags |=
+    1246                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP |
+    1247                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+    1248                 :            : 
+    1249                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1250                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1251                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+    1252                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1253                 :            :         m_libspdm_use_measurement_hash_algo;
+    1254                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    1255                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    1256                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1257                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1258                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1259                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    1260                 :            :                                                     &data_size1, NULL, NULL);
+    1261                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    1262                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
+    1263                 :            : 
+    1264                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1265                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+    1266                 :            : 
+    1267                 :          1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    1268                 :            :                               m_libspdm_key_exchange_request1.random_data);
+    1269                 :          1 :     m_libspdm_key_exchange_request1.req_session_id = 0xFFFF;
+    1270                 :          1 :     m_libspdm_key_exchange_request1.reserved = 0;
+    1271                 :          1 :     ptr = m_libspdm_key_exchange_request1.exchange_data;
+    1272                 :          1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    1273                 :          1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
+    1274                 :            :                                   false);
+    1275                 :          1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
+    1276                 :          1 :     ptr += dhe_key_size;
+    1277                 :          1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    1278                 :          1 :     opaque_key_exchange_req_size =
+    1279                 :          1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
+    1280                 :          1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
+    1281                 :          1 :     ptr += sizeof(uint16_t);
+    1282                 :          1 :     libspdm_build_opaque_data_supported_version_data(
+    1283                 :            :         spdm_context, &opaque_key_exchange_req_size, ptr);
+    1284                 :          1 :     ptr += opaque_key_exchange_req_size;
+    1285                 :          1 :     response_size = sizeof(response);
+    1286                 :            : 
+    1287                 :            :     /* Required to compute response size independently */
+    1288                 :            :     opaque_key_exchange_rsp_size =
+    1289                 :          1 :         libspdm_get_opaque_data_version_selection_data_size(spdm_context);
+    1290                 :            : 
+    1291                 :          1 :     status = libspdm_get_response_key_exchange(
+    1292                 :            :         spdm_context, m_libspdm_key_exchange_request1_size,
+    1293                 :            :         &m_libspdm_key_exchange_request1, &response_size, response);
+    1294                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1295                 :          1 :     assert_int_equal(
+    1296                 :            :         libspdm_secured_message_get_session_state(
+    1297                 :            :             spdm_context->session_info[0].secured_message_context),
+    1298                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    1299                 :          1 :     spdm_response = (void *)response;
+    1300                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_KEY_EXCHANGE_RSP);
+    1301                 :          1 :     assert_int_equal(spdm_response->rsp_session_id, 0xFFFF);
+    1302                 :          1 :     assert_int_equal(response_size,
+    1303                 :            :                      sizeof(spdm_key_exchange_response_t) +
+    1304                 :            :                      dhe_key_size +
+    1305                 :            :                      sizeof(uint16_t) +
+    1306                 :            :                      opaque_key_exchange_rsp_size +
+    1307                 :            :                      libspdm_get_asym_signature_size(
+    1308                 :            :                          spdm_context->connection_info.algorithm.base_asym_algo)
+    1309                 :            :                      );
+    1310                 :            : 
+    1311                 :          1 :     free(data1);
+    1312                 :          1 : }
+    1313                 :            : 
+    1314                 :          1 : void libspdm_test_responder_key_exchange_case16(void **state)
+    1315                 :            : {
+    1316                 :            :     libspdm_return_t status;
+    1317                 :            :     libspdm_test_context_t *spdm_test_context;
+    1318                 :            :     libspdm_context_t *spdm_context;
+    1319                 :            :     size_t current_request_size;
+    1320                 :            :     size_t response_size;
+    1321                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1322                 :            :     spdm_key_exchange_response_t *spdm_response;
+    1323                 :            :     void *data1;
+    1324                 :            :     size_t data_size1;
+    1325                 :            :     uint8_t *ptr;
+    1326                 :            :     size_t dhe_key_size;
+    1327                 :            :     void *dhe_context;
+    1328                 :            :     size_t opaque_key_exchange_req_size;
+    1329                 :            : 
+    1330                 :          1 :     spdm_test_context = *state;
+    1331                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1332                 :          1 :     spdm_test_context->case_id = 0x10;
+    1333                 :            : 
+    1334         [ +  - ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    1335                 :          1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    1336                 :            :     }
+    1337                 :            : 
+    1338                 :          1 :     spdm_context->connection_info.connection_state =
+    1339                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1340                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1341                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    1342                 :          1 :     spdm_context->local_context.capability.flags |=
+    1343                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    1344                 :            : 
+    1345                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1346                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1347                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+    1348                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1349                 :            :         m_libspdm_use_measurement_hash_algo;
+    1350                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    1351                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    1352                 :            : 
+    1353                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1354                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1355                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1356                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    1357                 :            :                                                     &data_size1, NULL, NULL);
+    1358                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    1359                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
+    1360                 :            : 
+    1361                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1362                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+    1363                 :            : 
+    1364                 :          1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, m_libspdm_key_exchange_request1.random_data);
+    1365                 :          1 :     m_libspdm_key_exchange_request1.req_session_id = 0xFFFF;
+    1366                 :          1 :     m_libspdm_key_exchange_request1.reserved = 0;
+    1367                 :          1 :     ptr = m_libspdm_key_exchange_request1.exchange_data;
+    1368                 :          1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    1369                 :          1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
+    1370                 :            :                                   false);
+    1371                 :          1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
+    1372                 :          1 :     ptr += dhe_key_size;
+    1373                 :          1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    1374                 :          1 :     opaque_key_exchange_req_size =
+    1375                 :          1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
+    1376                 :          1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
+    1377                 :          1 :     ptr += sizeof(uint16_t);
+    1378                 :          1 :     libspdm_build_opaque_data_supported_version_data(
+    1379                 :            :         spdm_context, &opaque_key_exchange_req_size, ptr);
+    1380                 :          1 :     ptr += opaque_key_exchange_req_size;
+    1381                 :            : 
+    1382                 :          1 :     current_request_size = sizeof(spdm_key_exchange_request_t) + dhe_key_size +
+    1383                 :          1 :                            sizeof(uint16_t) + opaque_key_exchange_req_size;
+    1384                 :          1 :     response_size = sizeof(response);
+    1385                 :          1 :     status = libspdm_get_response_key_exchange(
+    1386                 :            :         spdm_context, current_request_size, &m_libspdm_key_exchange_request1,
+    1387                 :            :         &response_size, response);
+    1388                 :            : 
+    1389                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1390                 :          1 :     assert_int_equal(
+    1391                 :            :         libspdm_secured_message_get_session_state(
+    1392                 :            :             spdm_context->session_info[0].secured_message_context),
+    1393                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    1394                 :          1 :     spdm_response = (void *)response;
+    1395                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_KEY_EXCHANGE_RSP);
+    1396                 :          1 :     assert_int_equal(spdm_response->rsp_session_id, 0xFFFF);
+    1397                 :            : 
+    1398                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1399                 :            :     assert_int_equal(spdm_context->session_info[0].session_transcript.message_k.buffer_size,
+    1400                 :            :                      current_request_size + response_size);
+    1401                 :            :     assert_memory_equal(spdm_context->session_info[0].session_transcript.message_k.buffer,
+    1402                 :            :                         &m_libspdm_key_exchange_request1, current_request_size);
+    1403                 :            :     assert_memory_equal(spdm_context->session_info[0].session_transcript.message_k.buffer +
+    1404                 :            :                         current_request_size,
+    1405                 :            :                         response, response_size);
+    1406                 :            : #endif
+    1407                 :          1 :     free(data1);
+    1408                 :          1 : }
+    1409                 :            : 
+    1410                 :          1 : void libspdm_test_responder_key_exchange_case17(void **state)
+    1411                 :            : {
+    1412                 :            :     libspdm_return_t status;
+    1413                 :            :     libspdm_test_context_t *spdm_test_context;
+    1414                 :            :     libspdm_context_t *spdm_context;
+    1415                 :            :     size_t response_size;
+    1416                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1417                 :            :     spdm_key_exchange_response_t *spdm_response;
+    1418                 :            :     void *data1;
+    1419                 :            :     size_t data_size1;
+    1420                 :            :     uint8_t *ptr;
+    1421                 :            :     size_t dhe_key_size;
+    1422                 :            :     void *dhe_context;
+    1423                 :            :     size_t opaque_key_exchange_req_size;
+    1424                 :            : 
+    1425                 :          1 :     spdm_test_context = *state;
+    1426                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1427                 :          1 :     spdm_test_context->case_id = 0x11;
+    1428                 :          1 :     spdm_context->connection_info.connection_state =
+    1429                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1430                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1431                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    1432                 :          1 :     spdm_context->local_context.capability.flags |=
+    1433                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    1434                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1435                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1436                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+    1437                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1438                 :            :         m_libspdm_use_measurement_hash_algo;
+    1439                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    1440                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    1441                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    1442                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1443                 :          1 :     spdm_context->connection_info.algorithm.other_params_support =
+    1444                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
+    1445                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
+    1446                 :            : 
+    1447                 :          1 :     libspdm_session_info_init(spdm_context,
+    1448                 :          1 :                               spdm_context->session_info,
+    1449                 :            :                               INVALID_SESSION_ID, false);
+    1450                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1451                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    1452                 :            :                                                     &data_size1, NULL, NULL);
+    1453                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    1454                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
+    1455                 :            : 
+    1456                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1457                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+    1458                 :            : 
+    1459                 :          1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, m_libspdm_key_exchange_request8.random_data);
+    1460                 :          1 :     m_libspdm_key_exchange_request8.req_session_id = 0xFFFF;
+    1461                 :          1 :     m_libspdm_key_exchange_request8.reserved = 0;
+    1462                 :          1 :     m_libspdm_key_exchange_request8.session_policy = 0xFF;
+    1463                 :          1 :     ptr = m_libspdm_key_exchange_request8.exchange_data;
+    1464                 :          1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    1465                 :          1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
+    1466                 :            :                                   false);
+    1467                 :          1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
+    1468                 :          1 :     ptr += dhe_key_size;
+    1469                 :          1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    1470                 :          1 :     opaque_key_exchange_req_size =
+    1471                 :          1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
+    1472                 :          1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
+    1473                 :          1 :     ptr += sizeof(uint16_t);
+    1474                 :          1 :     libspdm_build_opaque_data_supported_version_data(
+    1475                 :            :         spdm_context, &opaque_key_exchange_req_size, ptr);
+    1476                 :          1 :     ptr += opaque_key_exchange_req_size;
+    1477                 :          1 :     response_size = sizeof(response);
+    1478                 :          1 :     status = libspdm_get_response_key_exchange(
+    1479                 :            :         spdm_context, m_libspdm_key_exchange_request8_size,
+    1480                 :            :         &m_libspdm_key_exchange_request8, &response_size, response);
+    1481                 :          1 :     assert_int_equal(spdm_context->session_info[0].session_policy,
+    1482                 :            :                      m_libspdm_key_exchange_request8.session_policy);
+    1483                 :          1 :     spdm_response = (void *)response;
+    1484                 :          1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+    1485                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1486                 :          1 :     assert_int_equal(
+    1487                 :            :         libspdm_secured_message_get_session_state(
+    1488                 :            :             spdm_context->session_info[0].secured_message_context),
+    1489                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    1490                 :          1 :     spdm_response = (void *)response;
+    1491                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_KEY_EXCHANGE_RSP);
+    1492                 :          1 :     assert_int_equal(spdm_response->rsp_session_id, 0xFFFF);
+    1493                 :          1 :     free(data1);
+    1494                 :          1 : }
+    1495                 :            : 
+    1496                 :            : /**
+    1497                 :            :  * Test 18: SlotID in KEY_EXCHANGE request message is 9, but it should be 0xFF or between 0 and 7 inclusive.
+    1498                 :            :  * Expected Behavior: generate an ERROR_RESPONSE with code SPDM_ERROR_CODE_INVALID_REQUEST.
+    1499                 :            :  **/
+    1500                 :          1 : void libspdm_test_responder_key_exchange_case18(void **state)
+    1501                 :            : {
+    1502                 :            :     libspdm_return_t status;
+    1503                 :            :     libspdm_test_context_t *spdm_test_context;
+    1504                 :            :     libspdm_context_t *spdm_context;
+    1505                 :            :     size_t response_size;
+    1506                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1507                 :            :     spdm_key_exchange_response_t *spdm_response;
+    1508                 :            :     void *data1;
+    1509                 :            :     size_t data_size1;
+    1510                 :            :     uint8_t *ptr;
+    1511                 :            :     size_t dhe_key_size;
+    1512                 :            :     void *dhe_context;
+    1513                 :            :     size_t opaque_key_exchange_req_size;
+    1514                 :            : 
+    1515                 :          1 :     spdm_test_context = *state;
+    1516                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1517                 :          1 :     spdm_test_context->case_id = 0x12;
+    1518                 :          1 :     spdm_context->connection_info.connection_state =
+    1519                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1520                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1521                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    1522                 :          1 :     spdm_context->local_context.capability.flags |=
+    1523                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    1524                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1525                 :            :         m_libspdm_use_hash_algo;
+    1526                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1527                 :            :         m_libspdm_use_asym_algo;
+    1528                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    1529                 :            :         m_libspdm_use_measurement_spec;
+    1530                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1531                 :            :         m_libspdm_use_measurement_hash_algo;
+    1532                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1533                 :            :         m_libspdm_use_dhe_algo;
+    1534                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1535                 :            :         m_libspdm_use_aead_algo;
+    1536                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1537                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1538                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1539                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    1540                 :            :                                                     &data_size1, NULL, NULL);
+    1541                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    1542                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    1543                 :            :         data_size1;
+    1544                 :            : 
+    1545                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1546                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+    1547                 :            : 
+    1548                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
+    1549                 :            : 
+    1550                 :          1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    1551                 :            :                               m_libspdm_key_exchange_request9.random_data);
+    1552                 :          1 :     m_libspdm_key_exchange_request9.req_session_id = 0xFFFF;
+    1553                 :          1 :     m_libspdm_key_exchange_request9.reserved = 0;
+    1554                 :          1 :     ptr = m_libspdm_key_exchange_request9.exchange_data;
+    1555                 :          1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    1556                 :          1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
+    1557                 :            :                                   false);
+    1558                 :          1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
+    1559                 :          1 :     ptr += dhe_key_size;
+    1560                 :          1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    1561                 :          1 :     opaque_key_exchange_req_size =
+    1562                 :          1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
+    1563                 :          1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
+    1564                 :          1 :     ptr += sizeof(uint16_t);
+    1565                 :          1 :     libspdm_build_opaque_data_supported_version_data(
+    1566                 :            :         spdm_context, &opaque_key_exchange_req_size, ptr);
+    1567                 :          1 :     ptr += opaque_key_exchange_req_size;
+    1568                 :          1 :     response_size = sizeof(response);
+    1569                 :          1 :     status = libspdm_get_response_key_exchange(
+    1570                 :            :         spdm_context, m_libspdm_key_exchange_request9_size,
+    1571                 :            :         &m_libspdm_key_exchange_request9, &response_size, response);
+    1572                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1573                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1574                 :          1 :     spdm_response = (void *)response;
+    1575                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1576                 :            :                      SPDM_ERROR);
+    1577                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1578                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+    1579                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1580                 :          1 :     free(data1);
+    1581                 :          1 : }
+    1582                 :            : 
+    1583                 :          1 : void libspdm_test_responder_key_exchange_case19(void **state)
+    1584                 :            : {
+    1585                 :            :     libspdm_return_t status;
+    1586                 :            :     libspdm_test_context_t *spdm_test_context;
+    1587                 :            :     libspdm_context_t *spdm_context;
+    1588                 :            :     size_t response_size;
+    1589                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1590                 :            :     spdm_key_exchange_response_t *spdm_response;
+    1591                 :            :     void *data1;
+    1592                 :            :     size_t data_size1;
+    1593                 :            :     uint8_t *ptr;
+    1594                 :            :     size_t dhe_key_size;
+    1595                 :            :     void *dhe_context;
+    1596                 :            : 
+    1597                 :          1 :     spdm_test_context = *state;
+    1598                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1599                 :          1 :     spdm_test_context->case_id = 0x13;
+    1600                 :          1 :     spdm_context->response_state = 0;
+    1601                 :          1 :     spdm_context->connection_info.connection_state =
+    1602                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1603                 :          1 :     spdm_context->connection_info.capability.flags = 0;
+    1604                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1605                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    1606                 :          1 :     spdm_context->local_context.capability.flags = 0;
+    1607                 :          1 :     spdm_context->local_context.capability.flags |=
+    1608                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    1609                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1610                 :            :         m_libspdm_use_hash_algo;
+    1611                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1612                 :            :         m_libspdm_use_asym_algo;
+    1613                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    1614                 :            :         m_libspdm_use_measurement_spec;
+    1615                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1616                 :            :         m_libspdm_use_measurement_hash_algo;
+    1617                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1618                 :            :         m_libspdm_use_dhe_algo;
+    1619                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1620                 :            :         m_libspdm_use_aead_algo;
+    1621                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    1622                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1623                 :          1 :     spdm_context->connection_info.algorithm.other_params_support =
+    1624                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
+    1625                 :            : 
+    1626                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1627                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    1628                 :            :                                                     &data_size1, NULL, NULL);
+    1629                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    1630                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    1631                 :            :         data_size1;
+    1632                 :            : 
+    1633                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1634                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+    1635                 :            : 
+    1636                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
+    1637                 :            : 
+    1638                 :          1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    1639                 :            :                               m_libspdm_key_exchange_request8.random_data);
+    1640                 :          1 :     m_libspdm_key_exchange_request8.req_session_id = 0xFFFF;
+    1641                 :          1 :     m_libspdm_key_exchange_request8.reserved = 0;
+    1642                 :          1 :     ptr = m_libspdm_key_exchange_request8.exchange_data;
+    1643                 :          1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    1644                 :          1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
+    1645                 :            :                                   false);
+    1646                 :          1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
+    1647                 :          1 :     ptr += dhe_key_size;
+    1648                 :          1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    1649                 :            : 
+    1650                 :            :     size_t opaque_data_size;
+    1651                 :            :     spdm_general_opaque_data_table_header_t
+    1652                 :            :     *spdm_general_opaque_data_table_header;
+    1653                 :            :     secured_message_opaque_element_table_header_t
+    1654                 :            :     *opaque_element_table_header;
+    1655                 :            :     secured_message_opaque_element_header_t
+    1656                 :            :     * secured_message_element_header;
+    1657                 :            :     uint8_t element_num;
+    1658                 :            :     uint8_t element_index;
+    1659                 :            :     size_t current_element_len;
+    1660                 :            : 
+    1661                 :          1 :     spdm_general_opaque_data_table_header =
+    1662                 :            :         (spdm_general_opaque_data_table_header_t *)(ptr + sizeof(uint16_t));
+    1663                 :          1 :     spdm_general_opaque_data_table_header->total_elements = 2;
+    1664                 :          1 :     opaque_element_table_header = (void *)(spdm_general_opaque_data_table_header + 1);
+    1665                 :            : 
+    1666                 :          1 :     element_num = spdm_general_opaque_data_table_header->total_elements;
+    1667                 :          1 :     opaque_data_size = sizeof(spdm_general_opaque_data_table_header_t);
+    1668                 :            : 
+    1669         [ +  + ]:          3 :     for (element_index = 0; element_index < element_num; element_index++) {
+    1670                 :          2 :         opaque_element_table_header->id = SPDM_REGISTRY_ID_DMTF;
+    1671                 :          2 :         opaque_element_table_header->vendor_len = 0;
+    1672                 :            :         /* When opaque_element_data_len is not four byte aligned*/
+    1673                 :          2 :         opaque_element_table_header->opaque_element_data_len = 0xF;
+    1674                 :            : 
+    1675                 :          2 :         secured_message_element_header = (void *)(opaque_element_table_header + 1);
+    1676                 :          2 :         secured_message_element_header->sm_data_id =
+    1677                 :            :             SECURED_MESSAGE_OPAQUE_ELEMENT_SMDATA_ID_SUPPORTED_VERSION;
+    1678                 :          2 :         secured_message_element_header->sm_data_version =
+    1679                 :            :             SECURED_MESSAGE_OPAQUE_ELEMENT_SMDATA_DATA_VERSION;
+    1680                 :            : 
+    1681                 :          2 :         current_element_len = sizeof(secured_message_opaque_element_table_header_t) +
+    1682                 :          2 :                               opaque_element_table_header->vendor_len +
+    1683                 :          2 :                               sizeof(opaque_element_table_header->opaque_element_data_len) +
+    1684                 :          2 :                               opaque_element_table_header->opaque_element_data_len;
+    1685                 :            : 
+    1686                 :            :         /*move to next element*/
+    1687                 :          2 :         opaque_element_table_header =
+    1688                 :            :             (secured_message_opaque_element_table_header_t *)
+    1689                 :            :             ((uint8_t *)opaque_element_table_header +
+    1690                 :            :              current_element_len);
+    1691                 :            : 
+    1692                 :          2 :         opaque_data_size += current_element_len;
+    1693                 :            :     }
+    1694                 :            : 
+    1695                 :          1 :     *(uint16_t *)ptr = (uint16_t)opaque_data_size;
+    1696                 :            : 
+    1697                 :          1 :     response_size = sizeof(response);
+    1698                 :          1 :     status = libspdm_get_response_key_exchange(
+    1699                 :            :         spdm_context, m_libspdm_key_exchange_request8_size,
+    1700                 :            :         &m_libspdm_key_exchange_request8, &response_size, response);
+    1701                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1702                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1703                 :          1 :     spdm_response = (void *)response;
+    1704                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1705                 :            :                      SPDM_ERROR);
+    1706                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1707                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+    1708                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1709                 :          1 :     free(data1);
+    1710                 :          1 : }
+    1711                 :            : 
+    1712                 :          1 : void libspdm_test_responder_key_exchange_case20(void **state)
+    1713                 :            : {
+    1714                 :            :     libspdm_return_t status;
+    1715                 :            :     libspdm_test_context_t *spdm_test_context;
+    1716                 :            :     libspdm_context_t *spdm_context;
+    1717                 :            :     size_t response_size;
+    1718                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1719                 :            :     spdm_key_exchange_response_t *spdm_response;
+    1720                 :            :     void *data1;
+    1721                 :            :     size_t data_size1;
+    1722                 :            :     uint8_t *ptr;
+    1723                 :            :     size_t dhe_key_size;
+    1724                 :            :     void *dhe_context;
+    1725                 :            :     size_t opaque_key_exchange_req_size;
+    1726                 :            : 
+    1727                 :          1 :     spdm_test_context = *state;
+    1728                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1729                 :          1 :     spdm_test_context->case_id = 0x14;
+    1730                 :          1 :     spdm_context->connection_info.connection_state =
+    1731                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1732                 :          1 :     spdm_context->connection_info.capability.flags =
+    1733                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    1734                 :          1 :     spdm_context->local_context.capability.flags =
+    1735                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
+    1736                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+    1737                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1738                 :            :         m_libspdm_use_hash_algo;
+    1739                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1740                 :            :         m_libspdm_use_asym_algo;
+    1741                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    1742                 :            :         m_libspdm_use_measurement_spec;
+    1743                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1744                 :            :         m_libspdm_use_measurement_hash_algo;
+    1745                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1746                 :            :         m_libspdm_use_dhe_algo;
+    1747                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1748                 :            :         m_libspdm_use_aead_algo;
+    1749                 :          1 :     spdm_context->connection_info.algorithm.other_params_support =
+    1750                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
+    1751                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    1752                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1753                 :            : 
+    1754                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
+    1755                 :            : 
+    1756                 :          1 :     libspdm_session_info_init(spdm_context,
+    1757                 :          1 :                               spdm_context->session_info,
+    1758                 :            :                               INVALID_SESSION_ID, false);
+    1759                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1760                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    1761                 :            :                                                     &data_size1, NULL, NULL);
+    1762                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    1763                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
+    1764                 :            : 
+    1765                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1766                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+    1767                 :            : 
+    1768                 :          1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
+    1769                 :            :                               m_libspdm_key_exchange_request8.random_data);
+    1770                 :          1 :     m_libspdm_key_exchange_request8.req_session_id = 0xFFFF;
+    1771                 :          1 :     m_libspdm_key_exchange_request8.reserved = 0;
+    1772                 :          1 :     m_libspdm_key_exchange_request8.session_policy = 0xFF;
+    1773                 :          1 :     ptr = m_libspdm_key_exchange_request8.exchange_data;
+    1774                 :          1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    1775                 :          1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
+    1776                 :            :                                   false);
+    1777                 :          1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
+    1778                 :          1 :     ptr += dhe_key_size;
+    1779                 :          1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    1780                 :          1 :     opaque_key_exchange_req_size =
+    1781                 :          1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
+    1782                 :          1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
+    1783                 :          1 :     ptr += sizeof(uint16_t);
+    1784                 :          1 :     libspdm_build_opaque_data_supported_version_data(
+    1785                 :            :         spdm_context, &opaque_key_exchange_req_size, ptr);
+    1786                 :          1 :     ptr += opaque_key_exchange_req_size;
+    1787                 :          1 :     response_size = sizeof(response);
+    1788                 :          1 :     status = libspdm_get_response_key_exchange(
+    1789                 :            :         spdm_context, m_libspdm_key_exchange_request8_size,
+    1790                 :            :         &m_libspdm_key_exchange_request8, &response_size, response);
+    1791                 :          1 :     assert_int_equal(spdm_context->session_info[0].session_policy,
+    1792                 :            :                      m_libspdm_key_exchange_request8.session_policy);
+    1793                 :          1 :     spdm_response = (void *)response;
+    1794                 :          1 :     assert_int_equal(spdm_response->header.spdm_version,
+    1795                 :            :                      SPDM_MESSAGE_VERSION_12);
+    1796                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1797                 :          1 :     assert_int_equal(
+    1798                 :            :         libspdm_secured_message_get_session_state(
+    1799                 :            :             spdm_context->session_info[0].secured_message_context),
+    1800                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    1801                 :          1 :     spdm_response = (void *)response;
+    1802                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1803                 :            :                      SPDM_KEY_EXCHANGE_RSP);
+    1804                 :          1 :     assert_int_equal(spdm_response->rsp_session_id, 0xFFFF);
+    1805                 :          1 :     free(data1);
+    1806                 :          1 : }
+    1807                 :            : 
+    1808                 :            : /**
+    1809                 :            :  * Test 36: The key usage bit mask is not set, the SlotID fields in KEY_EXCHANGE and KEY_EXCHANGE_RSP shall not specify this certificate slot
+    1810                 :            :  * Expected Behavior: get a SPDM_ERROR_CODE_INVALID_REQUEST return code
+    1811                 :            :  **/
+    1812                 :          1 : void libspdm_test_responder_key_exchange_case21(void **state)
+    1813                 :            : {
+    1814                 :            :     libspdm_return_t status;
+    1815                 :            :     libspdm_test_context_t *spdm_test_context;
+    1816                 :            :     libspdm_context_t *spdm_context;
+    1817                 :            :     size_t response_size;
+    1818                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1819                 :            :     spdm_key_exchange_response_t *spdm_response;
+    1820                 :            :     void *data1;
+    1821                 :            :     size_t data_size1;
+    1822                 :            :     uint8_t *ptr;
+    1823                 :            :     size_t dhe_key_size;
+    1824                 :            :     void *dhe_context;
+    1825                 :            :     size_t opaque_key_exchange_req_size;
+    1826                 :            :     uint8_t slot_id;
+    1827                 :            : 
+    1828                 :          1 :     spdm_test_context = *state;
+    1829                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1830                 :          1 :     spdm_test_context->case_id = 0x15;
+    1831                 :          1 :     spdm_context->connection_info.connection_state =
+    1832                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1833                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1834                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+    1835                 :          1 :     spdm_context->local_context.capability.flags |=
+    1836                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+    1837                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1838                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1839                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+    1840                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1841                 :            :         m_libspdm_use_measurement_hash_algo;
+    1842                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    1843                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    1844                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+    1845                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1846                 :          1 :     spdm_context->connection_info.algorithm.other_params_support =
+    1847                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
+    1848                 :          1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
+    1849                 :          1 :     spdm_context->connection_info.multi_key_conn_rsp = true;
+    1850                 :            : 
+    1851                 :          1 :     libspdm_session_info_init(spdm_context,
+    1852                 :          1 :                               spdm_context->session_info,
+    1853                 :            :                               INVALID_SESSION_ID, false);
+    1854                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1855                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    1856                 :            :                                                     &data_size1, NULL, NULL);
+    1857                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    1858                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
+    1859                 :            : 
+    1860                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1861                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+    1862                 :            : 
+    1863                 :            :     /* If set, the SlotID fields in KEY_EXCHANGE and KEY_EXCHANGE_RSP can specify this certificate slot. If not set,
+    1864                 :            :      * the SlotID fields in KEY_EXCHANGE and KEY_EXCHANGE_RSP shall not specify this certificate slot */
+    1865                 :          1 :     slot_id = 0;
+    1866                 :          1 :     m_libspdm_key_exchange_request10.header.param2 = slot_id;
+    1867                 :          1 :     spdm_context->local_context.local_key_usage_bit_mask[slot_id] =
+    1868                 :            :         SPDM_KEY_USAGE_BIT_MASK_CHALLENGE_USE |
+    1869                 :            :         SPDM_KEY_USAGE_BIT_MASK_MEASUREMENT_USE;
+    1870                 :            : 
+    1871                 :          1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, m_libspdm_key_exchange_request10.random_data);
+    1872                 :          1 :     m_libspdm_key_exchange_request10.req_session_id = 0xFFFF;
+    1873                 :          1 :     m_libspdm_key_exchange_request10.reserved = 0;
+    1874                 :          1 :     m_libspdm_key_exchange_request10.session_policy = 0xFF;
+    1875                 :          1 :     ptr = m_libspdm_key_exchange_request10.exchange_data;
+    1876                 :          1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
+    1877                 :          1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
+    1878                 :            :                                   false);
+    1879                 :          1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
+    1880                 :          1 :     ptr += dhe_key_size;
+    1881                 :          1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
+    1882                 :          1 :     opaque_key_exchange_req_size =
+    1883                 :          1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
+    1884                 :          1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
+    1885                 :          1 :     ptr += sizeof(uint16_t);
+    1886                 :          1 :     libspdm_build_opaque_data_supported_version_data(
+    1887                 :            :         spdm_context, &opaque_key_exchange_req_size, ptr);
+    1888                 :          1 :     ptr += opaque_key_exchange_req_size;
+    1889                 :          1 :     response_size = sizeof(response);
+    1890                 :          1 :     status = libspdm_get_response_key_exchange(
+    1891                 :            :         spdm_context, m_libspdm_key_exchange_request10_size,
+    1892                 :            :         &m_libspdm_key_exchange_request10, &response_size, response);
+    1893                 :            : 
+    1894                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1895                 :          1 :     assert_int_equal (response_size, sizeof(spdm_error_response_t));
+    1896                 :          1 :     spdm_response = (void *)response;
+    1897                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_ERROR);
+    1898                 :          1 :     assert_int_equal (spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+    1899                 :          1 :     assert_int_equal (spdm_response->header.param2, 0);
+    1900                 :            : 
+    1901                 :          1 :     free(data1);
+    1902                 :          1 : }
+    1903                 :            : 
+    1904                 :            : libspdm_test_context_t m_libspdm_responder_key_exchange_test_context = {
+    1905                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+    1906                 :            :     false,
+    1907                 :            : };
+    1908                 :            : 
+    1909                 :          1 : int libspdm_responder_key_exchange_test_main(void)
+    1910                 :            : {
+    1911                 :          1 :     const struct CMUnitTest spdm_responder_key_exchange_tests[] = {
+    1912                 :            :         /* Success Case*/
+    1913                 :            :         cmocka_unit_test(libspdm_test_responder_key_exchange_case1),
+    1914                 :            :         /* Bad request size*/
+    1915                 :            :         cmocka_unit_test(libspdm_test_responder_key_exchange_case2),
+    1916                 :            :         /* response_state: SPDM_RESPONSE_STATE_BUSY*/
+    1917                 :            :         cmocka_unit_test(libspdm_test_responder_key_exchange_case3),
+    1918                 :            :         /* response_state: SPDM_RESPONSE_STATE_NEED_RESYNC*/
+    1919                 :            :         cmocka_unit_test(libspdm_test_responder_key_exchange_case4),
+    1920                 :            :         #if LIBSPDM_RESPOND_IF_READY_SUPPORT
+    1921                 :            :         /* response_state: SPDM_RESPONSE_STATE_NOT_READY*/
+    1922                 :            :         cmocka_unit_test(libspdm_test_responder_key_exchange_case5),
+    1923                 :            :         #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
+    1924                 :            :         /* connection_state Check*/
+    1925                 :            :         cmocka_unit_test(libspdm_test_responder_key_exchange_case6),
+    1926                 :            :         /* Buffer reset*/
+    1927                 :            :         cmocka_unit_test(libspdm_test_responder_key_exchange_case7),
+    1928                 :            :         /* TCB measurement hash requested */
+    1929                 :            :         cmocka_unit_test(libspdm_test_responder_key_exchange_case8),
+    1930                 :            :         /* All measurement hash requested */
+    1931                 :            :         cmocka_unit_test(libspdm_test_responder_key_exchange_case9),
+    1932                 :            :         /* Reserved value in Measurement summary. Error + Invalid */
+    1933                 :            :         cmocka_unit_test(libspdm_test_responder_key_exchange_case10),
+    1934                 :            :         /* TCB measurement hash requested, measurement flag not set */
+    1935                 :            :         cmocka_unit_test(libspdm_test_responder_key_exchange_case11),
+    1936                 :            :         /* Request previously provisioned public key, slot 0xFF */
+    1937                 :            :         cmocka_unit_test(libspdm_test_responder_key_exchange_case14),
+    1938                 :            :         /* HANDSHAKE_IN_THE_CLEAR set for requester and responder */
+    1939                 :            :         cmocka_unit_test(libspdm_test_responder_key_exchange_case15),
+    1940                 :            :         /* Buffer verification*/
+    1941                 :            :         cmocka_unit_test(libspdm_test_responder_key_exchange_case16),
+    1942                 :            :         /* Successful response V1.2*/
+    1943                 :            :         cmocka_unit_test(libspdm_test_responder_key_exchange_case17),
+    1944                 :            :         /* Invalid SlotID in KEY_EXCHANGE request message*/
+    1945                 :            :         cmocka_unit_test(libspdm_test_responder_key_exchange_case18),
+    1946                 :            :         /* Only OpaqueDataFmt1 is supported, Bytes not aligned*/
+    1947                 :            :         cmocka_unit_test(libspdm_test_responder_key_exchange_case19),
+    1948                 :            :         /* OpaqueData only supports OpaqueDataFmt1, Success Case */
+    1949                 :            :         cmocka_unit_test(libspdm_test_responder_key_exchange_case20),
+    1950                 :            :         /* The key usage bit mask is not set, failed Case*/
+    1951                 :            :         cmocka_unit_test(libspdm_test_responder_key_exchange_case21),
+    1952                 :            :     };
+    1953                 :            : 
+    1954                 :          1 :     libspdm_setup_test_context(&m_libspdm_responder_key_exchange_test_context);
+    1955                 :            : 
+    1956                 :          1 :     return cmocka_run_group_tests(spdm_responder_key_exchange_tests,
+    1957                 :            :                                   libspdm_unit_test_group_setup,
+    1958                 :            :                                   libspdm_unit_test_group_teardown);
+    1959                 :            : }
+    1960                 :            : 
+    1961                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/key_pair_info.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_responder/key_pair_info.c.func-sort-c.html new file mode 100644 index 00000000000..dc28f5a18cb --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/key_pair_info.c.func-sort-c.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/key_pair_info.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - key_pair_info.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:7979100.0 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_key_pair_info_test_main1
libspdm_test_responder_key_pair_info_case11
libspdm_test_responder_key_pair_info_case21
libspdm_test_responder_key_pair_info_case31
libspdm_test_responder_key_pair_info_case41
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/key_pair_info.c.func.html b/coverage_log/unit_test/test_spdm_responder/key_pair_info.c.func.html new file mode 100644 index 00000000000..ae95f02437e --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/key_pair_info.c.func.html @@ -0,0 +1,101 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/key_pair_info.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - key_pair_info.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:7979100.0 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_key_pair_info_test_main1
libspdm_test_responder_key_pair_info_case11
libspdm_test_responder_key_pair_info_case21
libspdm_test_responder_key_pair_info_case31
libspdm_test_responder_key_pair_info_case41
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/key_pair_info.c.gcov.html b/coverage_log/unit_test/test_spdm_responder/key_pair_info.c.gcov.html new file mode 100644 index 00000000000..c8da5843b22 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/key_pair_info.c.gcov.html @@ -0,0 +1,308 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/key_pair_info.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - key_pair_info.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:7979100.0 %
Date:2024-09-22 08:21:07Functions:55100.0 %
Branches:00-
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2024 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_responder_lib.h"
+       9                 :            : #include "internal/libspdm_requester_lib.h"
+      10                 :            : 
+      11                 :            : #if LIBSPDM_ENABLE_CAPABILITY_GET_KEY_PAIR_INFO_CAP
+      12                 :            : 
+      13                 :            : spdm_get_key_pair_info_request_t m_libspdm_get_key_pair_info_request1 = {
+      14                 :            :     { SPDM_MESSAGE_VERSION_13, SPDM_GET_KEY_PAIR_INFO, 0, 0 },
+      15                 :            :     4
+      16                 :            : };
+      17                 :            : size_t m_libspdm_get_key_pair_info_request1_size = sizeof(m_libspdm_get_key_pair_info_request1);
+      18                 :            : 
+      19                 :            : /**
+      20                 :            :  * Test 1: Successful response to get key pair info with key pair id 4
+      21                 :            :  * Expected Behavior: get a LIBSPDM_STATUS_SUCCESS return code, and correct response message size and fields
+      22                 :            :  **/
+      23                 :          1 : void libspdm_test_responder_key_pair_info_case1(void **state)
+      24                 :            : {
+      25                 :            :     libspdm_return_t status;
+      26                 :            :     libspdm_test_context_t *spdm_test_context;
+      27                 :            :     libspdm_context_t *spdm_context;
+      28                 :            :     size_t response_size;
+      29                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+      30                 :            :     spdm_key_pair_info_response_t *spdm_response;
+      31                 :            :     uint8_t key_pair_id;
+      32                 :            :     uint16_t public_key_info_len;
+      33                 :          1 :     uint8_t public_key_info_ecp256[] = {0x30, 0x13, 0x06, 0x07, 0x2A, 0x86, 0x48, 0xCE, 0x3D,
+      34                 :            :                                         0x02, 0x01, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D,
+      35                 :            :                                         0x03, 0x01, 0x07};
+      36                 :            : 
+      37                 :          1 :     spdm_test_context = *state;
+      38                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+      39                 :          1 :     spdm_test_context->case_id = 0x1;
+      40                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+      41                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+      42                 :          1 :     spdm_context->connection_info.connection_state =
+      43                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+      44                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+      45                 :            :         m_libspdm_use_asym_algo;
+      46                 :          1 :     spdm_context->local_context.capability.flags |=
+      47                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_GET_KEY_PAIR_INFO_CAP;
+      48                 :          1 :     spdm_context->local_context.total_key_pairs = 16;
+      49                 :            : 
+      50                 :          1 :     key_pair_id = 4;
+      51                 :          1 :     public_key_info_len = sizeof(public_key_info_ecp256);
+      52                 :            : 
+      53                 :          1 :     response_size = sizeof(response);
+      54                 :            : 
+      55                 :          1 :     status = libspdm_get_response_key_pair_info(
+      56                 :            :         spdm_context, m_libspdm_get_key_pair_info_request1_size,
+      57                 :            :         &m_libspdm_get_key_pair_info_request1, &response_size, response);
+      58                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+      59                 :          1 :     assert_int_equal(response_size,
+      60                 :            :                      sizeof(spdm_key_pair_info_response_t) + public_key_info_len);
+      61                 :          1 :     spdm_response = (void *)response;
+      62                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+      63                 :            :                      SPDM_KEY_PAIR_INFO);
+      64                 :          1 :     assert_int_equal(spdm_response->key_pair_id,
+      65                 :            :                      key_pair_id);
+      66                 :          1 : }
+      67                 :            : 
+      68                 :            : /**
+      69                 :            :  * Test 2:
+      70                 :            :  * An SPDM endpoint shall contain KeyPairID s starting from 1 to TotalKeyPairs inclusive and without gaps.
+      71                 :            :  * KeyPairID is set to 0.
+      72                 :            :  * Expected Behavior:  Generate error response message
+      73                 :            :  **/
+      74                 :          1 : void libspdm_test_responder_key_pair_info_case2(void **state)
+      75                 :            : {
+      76                 :            :     libspdm_return_t status;
+      77                 :            :     libspdm_test_context_t *spdm_test_context;
+      78                 :            :     libspdm_context_t *spdm_context;
+      79                 :            :     size_t response_size;
+      80                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+      81                 :            :     spdm_key_pair_info_response_t *spdm_response;
+      82                 :            :     uint8_t key_pair_id;
+      83                 :            : 
+      84                 :          1 :     spdm_test_context = *state;
+      85                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+      86                 :          1 :     spdm_test_context->case_id = 0x2;
+      87                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+      88                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+      89                 :          1 :     spdm_context->connection_info.connection_state =
+      90                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+      91                 :          1 :     spdm_context->local_context.capability.flags |=
+      92                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_GET_KEY_PAIR_INFO_CAP;
+      93                 :            : 
+      94                 :            :     /* An SPDM endpoint shall contain KeyPairID s starting from 1 to TotalKeyPairs inclusive and without gaps.
+      95                 :            :      * KeyPairID is set to 0.*/
+      96                 :          1 :     key_pair_id = 0;
+      97                 :          1 :     m_libspdm_get_key_pair_info_request1.key_pair_id = key_pair_id;
+      98                 :            : 
+      99                 :          1 :     spdm_context->local_context.total_key_pairs = 1;
+     100                 :            : 
+     101                 :          1 :     response_size = sizeof(response);
+     102                 :            : 
+     103                 :          1 :     status = libspdm_get_response_key_pair_info(
+     104                 :            :         spdm_context, m_libspdm_get_key_pair_info_request1_size,
+     105                 :            :         &m_libspdm_get_key_pair_info_request1, &response_size, response);
+     106                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     107                 :          1 :     spdm_response = (void *)response;
+     108                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     109                 :            :                      SPDM_ERROR);
+     110                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+     111                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     112                 :          1 : }
+     113                 :            : 
+     114                 :            : /**
+     115                 :            :  * Test 3: The key_pair_id is greater than the total key pairs
+     116                 :            :  * Expected Behavior:  Generate error response message
+     117                 :            :  **/
+     118                 :          1 : void libspdm_test_responder_key_pair_info_case3(void **state)
+     119                 :            : {
+     120                 :            :     libspdm_return_t status;
+     121                 :            :     libspdm_test_context_t *spdm_test_context;
+     122                 :            :     libspdm_context_t *spdm_context;
+     123                 :            :     size_t response_size;
+     124                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     125                 :            :     spdm_key_pair_info_response_t *spdm_response;
+     126                 :            :     uint8_t key_pair_id;
+     127                 :            : 
+     128                 :          1 :     spdm_test_context = *state;
+     129                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     130                 :          1 :     spdm_test_context->case_id = 0x3;
+     131                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+     132                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     133                 :          1 :     spdm_context->connection_info.connection_state =
+     134                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     135                 :          1 :     spdm_context->local_context.capability.flags |=
+     136                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_GET_KEY_PAIR_INFO_CAP;
+     137                 :            : 
+     138                 :            :     /* key_pair_id > total_key_pairs*/
+     139                 :          1 :     key_pair_id = 2;
+     140                 :          1 :     m_libspdm_get_key_pair_info_request1.key_pair_id = key_pair_id;
+     141                 :          1 :     spdm_context->local_context.total_key_pairs = 1;
+     142                 :            : 
+     143                 :          1 :     response_size = sizeof(response);
+     144                 :            : 
+     145                 :          1 :     status = libspdm_get_response_key_pair_info(
+     146                 :            :         spdm_context, m_libspdm_get_key_pair_info_request1_size,
+     147                 :            :         &m_libspdm_get_key_pair_info_request1, &response_size, response);
+     148                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     149                 :          1 :     spdm_response = (void *)response;
+     150                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     151                 :            :                      SPDM_ERROR);
+     152                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+     153                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     154                 :          1 : }
+     155                 :            : 
+     156                 :            : /**
+     157                 :            :  * Test 4: not set KEY_PAIR_INFO
+     158                 :            :  * Expected Behavior:  Generate error response message
+     159                 :            :  **/
+     160                 :          1 : void libspdm_test_responder_key_pair_info_case4(void **state)
+     161                 :            : {
+     162                 :            :     libspdm_return_t status;
+     163                 :            :     libspdm_test_context_t *spdm_test_context;
+     164                 :            :     libspdm_context_t *spdm_context;
+     165                 :            :     size_t response_size;
+     166                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     167                 :            :     spdm_key_pair_info_response_t *spdm_response;
+     168                 :            :     uint8_t key_pair_id;
+     169                 :            : 
+     170                 :          1 :     spdm_test_context = *state;
+     171                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     172                 :          1 :     spdm_test_context->case_id = 0x4;
+     173                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+     174                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     175                 :          1 :     spdm_context->connection_info.connection_state =
+     176                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     177                 :            :     /* not set KEY_PAIR_INFO*/
+     178                 :          1 :     spdm_context->local_context.capability.flags &=
+     179                 :            :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_GET_KEY_PAIR_INFO_CAP;
+     180                 :            : 
+     181                 :          1 :     key_pair_id = 1;
+     182                 :          1 :     m_libspdm_get_key_pair_info_request1.key_pair_id = key_pair_id;
+     183                 :            : 
+     184                 :          1 :     spdm_context->local_context.total_key_pairs = key_pair_id;
+     185                 :            : 
+     186                 :          1 :     response_size = sizeof(response);
+     187                 :            : 
+     188                 :          1 :     status = libspdm_get_response_key_pair_info(
+     189                 :            :         spdm_context, m_libspdm_get_key_pair_info_request1_size,
+     190                 :            :         &m_libspdm_get_key_pair_info_request1, &response_size, response);
+     191                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     192                 :          1 :     spdm_response = (void *)response;
+     193                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     194                 :            :                      SPDM_ERROR);
+     195                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST);
+     196                 :          1 :     assert_int_equal(spdm_response->header.param2, SPDM_GET_KEY_PAIR_INFO);
+     197                 :          1 : }
+     198                 :            : 
+     199                 :          1 : int libspdm_responder_key_pair_info_test_main(void)
+     200                 :            : {
+     201                 :          1 :     const struct CMUnitTest spdm_responder_key_pair_info_tests[] = {
+     202                 :            :         /* Success Case to get key pair info*/
+     203                 :            :         cmocka_unit_test(libspdm_test_responder_key_pair_info_case1),
+     204                 :            :         /* The KeyPairID is at least 1 , KeyPairID is set to 0.*/
+     205                 :            :         cmocka_unit_test(libspdm_test_responder_key_pair_info_case2),
+     206                 :            :         /* KeyPairID > total_key_pairs*/
+     207                 :            :         cmocka_unit_test(libspdm_test_responder_key_pair_info_case3),
+     208                 :            :         /* capability not set KEY_PAIR_INFO*/
+     209                 :            :         cmocka_unit_test(libspdm_test_responder_key_pair_info_case4),
+     210                 :            :     };
+     211                 :            : 
+     212                 :          1 :     libspdm_test_context_t test_context = {
+     213                 :            :         LIBSPDM_TEST_CONTEXT_VERSION,
+     214                 :            :         false,
+     215                 :            :     };
+     216                 :          1 :     libspdm_setup_test_context(&test_context);
+     217                 :            : 
+     218                 :          1 :     return cmocka_run_group_tests(spdm_responder_key_pair_info_tests,
+     219                 :            :                                   libspdm_unit_test_group_setup,
+     220                 :            :                                   libspdm_unit_test_group_teardown);
+     221                 :            : }
+     222                 :            : 
+     223                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_GET_KEY_PAIR_INFO_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/key_update.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_responder/key_update.c.func-sort-c.html new file mode 100644 index 00000000000..a6e4a2416b2 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/key_update.c.func-sort-c.html @@ -0,0 +1,205 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/key_update.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - key_update.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:689689100.0 %
Date:2024-09-22 08:21:07Functions:3131100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_key_update_test_main1
libspdm_test_responder_key_update_case11
libspdm_test_responder_key_update_case101
libspdm_test_responder_key_update_case111
libspdm_test_responder_key_update_case121
libspdm_test_responder_key_update_case131
libspdm_test_responder_key_update_case141
libspdm_test_responder_key_update_case151
libspdm_test_responder_key_update_case161
libspdm_test_responder_key_update_case171
libspdm_test_responder_key_update_case181
libspdm_test_responder_key_update_case191
libspdm_test_responder_key_update_case21
libspdm_test_responder_key_update_case201
libspdm_test_responder_key_update_case211
libspdm_test_responder_key_update_case221
libspdm_test_responder_key_update_case231
libspdm_test_responder_key_update_case241
libspdm_test_responder_key_update_case251
libspdm_test_responder_key_update_case261
libspdm_test_responder_key_update_case271
libspdm_test_responder_key_update_case31
libspdm_test_responder_key_update_case41
libspdm_test_responder_key_update_case51
libspdm_test_responder_key_update_case61
libspdm_test_responder_key_update_case71
libspdm_test_responder_key_update_case81
libspdm_test_responder_key_update_case91
libspdm_set_standard_key_update_test_secrets27
libspdm_set_standard_key_update_test_state27
libspdm_compute_secret_update30
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/key_update.c.func.html b/coverage_log/unit_test/test_spdm_responder/key_update.c.func.html new file mode 100644 index 00000000000..3999f5d2757 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/key_update.c.func.html @@ -0,0 +1,205 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/key_update.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - key_update.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:689689100.0 %
Date:2024-09-22 08:21:07Functions:3131100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_compute_secret_update30
libspdm_responder_key_update_test_main1
libspdm_set_standard_key_update_test_secrets27
libspdm_set_standard_key_update_test_state27
libspdm_test_responder_key_update_case11
libspdm_test_responder_key_update_case101
libspdm_test_responder_key_update_case111
libspdm_test_responder_key_update_case121
libspdm_test_responder_key_update_case131
libspdm_test_responder_key_update_case141
libspdm_test_responder_key_update_case151
libspdm_test_responder_key_update_case161
libspdm_test_responder_key_update_case171
libspdm_test_responder_key_update_case181
libspdm_test_responder_key_update_case191
libspdm_test_responder_key_update_case21
libspdm_test_responder_key_update_case201
libspdm_test_responder_key_update_case211
libspdm_test_responder_key_update_case221
libspdm_test_responder_key_update_case231
libspdm_test_responder_key_update_case241
libspdm_test_responder_key_update_case251
libspdm_test_responder_key_update_case261
libspdm_test_responder_key_update_case271
libspdm_test_responder_key_update_case31
libspdm_test_responder_key_update_case41
libspdm_test_responder_key_update_case51
libspdm_test_responder_key_update_case61
libspdm_test_responder_key_update_case71
libspdm_test_responder_key_update_case81
libspdm_test_responder_key_update_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/key_update.c.gcov.html b/coverage_log/unit_test/test_spdm_responder/key_update.c.gcov.html new file mode 100644 index 00000000000..14435220b77 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/key_update.c.gcov.html @@ -0,0 +1,2317 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/key_update.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - key_update.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:689689100.0 %
Date:2024-09-22 08:21:07Functions:3131100.0 %
Branches:00-
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_responder_lib.h"
+       9                 :            : #include "internal/libspdm_secured_message_lib.h"
+      10                 :            : 
+      11                 :            : #if (LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP) || (LIBSPDM_ENABLE_CAPABILITY_PSK_CAP)
+      12                 :            : 
+      13                 :            : spdm_key_update_request_t m_libspdm_key_update_request1 = {
+      14                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_KEY_UPDATE,
+      15                 :            :       SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY, 0x3 }
+      16                 :            : };
+      17                 :            : size_t m_libspdm_key_update_request1_size = sizeof(m_libspdm_key_update_request1);
+      18                 :            : 
+      19                 :            : spdm_key_update_request_t m_libspdm_key_update_request2 = {
+      20                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_KEY_UPDATE,
+      21                 :            :       SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY, 0x3 }
+      22                 :            : };
+      23                 :            : size_t m_libspdm_key_update_request2_size = LIBSPDM_MAX_SPDM_MSG_SIZE;
+      24                 :            : 
+      25                 :            : spdm_key_update_request_t m_libspdm_key_update_request3 = {
+      26                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_KEY_UPDATE,
+      27                 :            :       SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_ALL_KEYS, 0x71 }
+      28                 :            : };
+      29                 :            : size_t m_libspdm_key_update_request3_size = sizeof(m_libspdm_key_update_request3);
+      30                 :            : 
+      31                 :            : spdm_key_update_request_t m_libspdm_key_update_request4 = {
+      32                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_KEY_UPDATE,
+      33                 :            :       SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_ALL_KEYS, 0x71 }
+      34                 :            : };
+      35                 :            : size_t m_libspdm_key_update_request4_size = LIBSPDM_MAX_SPDM_MSG_SIZE;
+      36                 :            : 
+      37                 :            : spdm_key_update_request_t m_libspdm_key_update_request5 = {
+      38                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_KEY_UPDATE,
+      39                 :            :       SPDM_KEY_UPDATE_OPERATIONS_TABLE_VERIFY_NEW_KEY, 0x4A }
+      40                 :            : };
+      41                 :            : size_t m_libspdm_key_update_request5_size = sizeof(m_libspdm_key_update_request5);
+      42                 :            : 
+      43                 :            : spdm_key_update_request_t m_libspdm_key_update_request6 = {
+      44                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_KEY_UPDATE,
+      45                 :            :       SPDM_KEY_UPDATE_OPERATIONS_TABLE_VERIFY_NEW_KEY, 0x4A }
+      46                 :            : };
+      47                 :            : size_t m_libspdm_key_update_request6_size = LIBSPDM_MAX_SPDM_MSG_SIZE;
+      48                 :            : 
+      49                 :            : spdm_key_update_request_t m_libspdm_key_update_request7 = {
+      50                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_KEY_UPDATE,
+      51                 :            :       SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY, 0x92 }
+      52                 :            : };
+      53                 :            : size_t m_libspdm_key_update_request7_size = sizeof(m_libspdm_key_update_request7);
+      54                 :            : 
+      55                 :            : spdm_key_update_request_t m_libspdm_key_update_request8 = {
+      56                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_KEY_UPDATE,
+      57                 :            :       SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_ALL_KEYS, 0x13 }
+      58                 :            : };
+      59                 :            : size_t m_libspdm_key_update_request8_size = sizeof(m_libspdm_key_update_request8);
+      60                 :            : 
+      61                 :            : spdm_key_update_request_t m_libspdm_key_update_request9 = {
+      62                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_KEY_UPDATE,
+      63                 :            :       SPDM_KEY_UPDATE_OPERATIONS_TABLE_VERIFY_NEW_KEY, 0x22 }
+      64                 :            : };
+      65                 :            : size_t m_libspdm_key_update_request9_size = sizeof(m_libspdm_key_update_request9);
+      66                 :            : 
+      67                 :            : spdm_key_update_request_t m_libspdm_key_update_request10 = {
+      68                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_KEY_UPDATE, 0xFF, 0x12 }
+      69                 :            : };
+      70                 :            : size_t m_libspdm_key_update_request10_size = sizeof(m_libspdm_key_update_request10);
+      71                 :            : 
+      72                 :         27 : static void libspdm_set_standard_key_update_test_state(
+      73                 :            :     libspdm_context_t *spdm_context, uint32_t *session_id)
+      74                 :            : {
+      75                 :            :     libspdm_session_info_t    *session_info;
+      76                 :            : 
+      77                 :         27 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+      78                 :         27 :     spdm_context->connection_info.connection_state =
+      79                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+      80                 :         27 :     spdm_context->connection_info.capability.flags |=
+      81                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_UPD_CAP;
+      82                 :         27 :     spdm_context->connection_info.capability.flags |=
+      83                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+      84                 :         27 :     spdm_context->connection_info.capability.flags |=
+      85                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+      86                 :         27 :     spdm_context->local_context.capability.flags |=
+      87                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP;
+      88                 :         27 :     spdm_context->local_context.capability.flags |=
+      89                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
+      90                 :         27 :     spdm_context->local_context.capability.flags |=
+      91                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
+      92                 :            : 
+      93                 :         27 :     spdm_context->transcript.message_a.buffer_size = 0;
+      94                 :         27 :     spdm_context->connection_info.algorithm.base_hash_algo =
+      95                 :            :         m_libspdm_use_hash_algo;
+      96                 :         27 :     spdm_context->connection_info.algorithm.base_asym_algo =
+      97                 :            :         m_libspdm_use_asym_algo;
+      98                 :         27 :     spdm_context->connection_info.algorithm.dhe_named_group =
+      99                 :            :         m_libspdm_use_dhe_algo;
+     100                 :         27 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     101                 :            :         m_libspdm_use_aead_algo;
+     102                 :            : 
+     103                 :         27 :     *session_id = 0xFFFFFFFF;
+     104                 :         27 :     spdm_context->latest_session_id = *session_id;
+     105                 :         27 :     spdm_context->last_spdm_request_session_id_valid = true;
+     106                 :         27 :     spdm_context->last_spdm_request_session_id = *session_id;
+     107                 :         27 :     session_info = &spdm_context->session_info[0];
+     108                 :         27 :     libspdm_session_info_init(spdm_context, session_info, *session_id, true);
+     109                 :         27 :     libspdm_secured_message_set_session_state(
+     110                 :            :         session_info->secured_message_context,
+     111                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+     112                 :         27 : }
+     113                 :            : 
+     114                 :         27 : static void libspdm_set_standard_key_update_test_secrets(
+     115                 :            :     libspdm_secured_message_context_t *secured_message_context,
+     116                 :            :     uint8_t *m_rsp_secret_buffer, uint8_t rsp_secret_fill,
+     117                 :            :     uint8_t *m_req_secret_buffer, uint8_t req_secret_fill)
+     118                 :            : {
+     119                 :         27 :     libspdm_set_mem(m_rsp_secret_buffer, secured_message_context
+     120                 :            :                     ->hash_size, rsp_secret_fill);
+     121                 :         27 :     libspdm_set_mem(m_req_secret_buffer, secured_message_context
+     122                 :            :                     ->hash_size, req_secret_fill);
+     123                 :            : 
+     124                 :         27 :     libspdm_copy_mem(secured_message_context->application_secret.response_data_secret,
+     125                 :            :                      sizeof(secured_message_context->application_secret.response_data_secret),
+     126                 :            :                      m_rsp_secret_buffer, secured_message_context->aead_key_size);
+     127                 :         27 :     libspdm_copy_mem(secured_message_context->application_secret.request_data_secret,
+     128                 :            :                      sizeof(secured_message_context->application_secret.request_data_secret),
+     129                 :            :                      m_req_secret_buffer, secured_message_context->aead_key_size);
+     130                 :            : 
+     131                 :         27 :     libspdm_set_mem(secured_message_context->application_secret
+     132                 :         27 :                     .response_data_encryption_key,
+     133                 :            :                     secured_message_context->aead_key_size, (uint8_t)(0xFF));
+     134                 :         27 :     libspdm_set_mem(secured_message_context->application_secret
+     135                 :         27 :                     .response_data_salt,
+     136                 :            :                     secured_message_context->aead_iv_size, (uint8_t)(0xFF));
+     137                 :            : 
+     138                 :            : 
+     139                 :         27 :     libspdm_set_mem(secured_message_context->application_secret
+     140                 :         27 :                     .request_data_encryption_key,
+     141                 :            :                     secured_message_context->aead_key_size, (uint8_t)(0xEE));
+     142                 :         27 :     libspdm_set_mem(secured_message_context->application_secret
+     143                 :         27 :                     .request_data_salt,
+     144                 :            :                     secured_message_context->aead_iv_size, (uint8_t)(0xEE));
+     145                 :            : 
+     146                 :            :     secured_message_context->application_secret.
+     147                 :         27 :     response_data_sequence_number = 0;
+     148                 :            :     secured_message_context->application_secret.
+     149                 :         27 :     request_data_sequence_number = 0;
+     150                 :         27 : }
+     151                 :            : 
+     152                 :         30 : static void libspdm_compute_secret_update(spdm_version_number_t spdm_version,
+     153                 :            :                                           size_t hash_size,
+     154                 :            :                                           const uint8_t *in_secret, uint8_t *out_secret,
+     155                 :            :                                           size_t out_secret_size)
+     156                 :            : {
+     157                 :            :     uint8_t bin_str9[128];
+     158                 :            :     size_t bin_str9_size;
+     159                 :            : 
+     160                 :         30 :     bin_str9_size = sizeof(bin_str9);
+     161                 :         30 :     libspdm_bin_concat(spdm_version,
+     162                 :            :                        SPDM_BIN_STR_9_LABEL, sizeof(SPDM_BIN_STR_9_LABEL) - 1,
+     163                 :         30 :                        NULL, (uint16_t)hash_size, hash_size, bin_str9,
+     164                 :            :                        &bin_str9_size);
+     165                 :            : 
+     166                 :         30 :     libspdm_hkdf_expand(m_libspdm_use_hash_algo, in_secret, hash_size, bin_str9,
+     167                 :            :                         bin_str9_size, out_secret, out_secret_size);
+     168                 :         30 : }
+     169                 :            : 
+     170                 :            : /**
+     171                 :            :  * Test 1: receiving a correct KEY_UPDATE message from the requester with
+     172                 :            :  * the UpdateKey operation.
+     173                 :            :  * Expected behavior: the responder accepts the request, produces a valid
+     174                 :            :  * KEY_UPDATE_ACK response message, and the request data key is updated.
+     175                 :            :  **/
+     176                 :          1 : void libspdm_test_responder_key_update_case1(void **state)
+     177                 :            : {
+     178                 :            :     libspdm_return_t status;
+     179                 :            :     libspdm_test_context_t            *spdm_test_context;
+     180                 :            :     libspdm_context_t                 *spdm_context;
+     181                 :            :     uint32_t session_id;
+     182                 :            :     libspdm_session_info_t            *session_info;
+     183                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     184                 :            : 
+     185                 :            :     size_t response_size;
+     186                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     187                 :            :     spdm_key_update_response_t *spdm_response;
+     188                 :            : 
+     189                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     190                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     191                 :            : 
+     192                 :          1 :     spdm_test_context = *state;
+     193                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     194                 :          1 :     spdm_test_context->case_id = 0x1;
+     195                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     196                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     197                 :            : 
+     198                 :          1 :     libspdm_set_standard_key_update_test_state(
+     199                 :            :         spdm_context, &session_id);
+     200                 :            : 
+     201                 :          1 :     session_info = &spdm_context->session_info[0];
+     202                 :          1 :     secured_message_context = session_info->secured_message_context;
+     203                 :            : 
+     204                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+     205                 :          1 :         session_info->secured_message_context,
+     206                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+     207                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+     208                 :            : 
+     209                 :            :     /*request side updated*/
+     210                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+     211                 :            :                                   secured_message_context->hash_size,
+     212                 :            :                                   m_req_secret_buffer, m_req_secret_buffer,
+     213                 :            :                                   secured_message_context->hash_size);
+     214                 :            :     /*response side *not* updated*/
+     215                 :            : 
+     216                 :          1 :     response_size = sizeof(response);
+     217                 :          1 :     status = libspdm_get_response_key_update(spdm_context,
+     218                 :            :                                              m_libspdm_key_update_request1_size,
+     219                 :            :                                              &m_libspdm_key_update_request1,
+     220                 :            :                                              &response_size, response);
+     221                 :            : 
+     222                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     223                 :          1 :     assert_int_equal(response_size, sizeof(spdm_key_update_response_t));
+     224                 :          1 :     spdm_response = (void *)response;
+     225                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     226                 :            :                      SPDM_KEY_UPDATE_ACK);
+     227                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     228                 :            :                      SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY);
+     229                 :          1 :     assert_int_equal(spdm_response->header.param2,
+     230                 :            :                      m_libspdm_key_update_request1.header.param2);
+     231                 :          1 :     assert_memory_equal(secured_message_context
+     232                 :            :                         ->application_secret.request_data_secret,
+     233                 :            :                         m_req_secret_buffer, secured_message_context->hash_size);
+     234                 :          1 :     assert_memory_equal(secured_message_context
+     235                 :            :                         ->application_secret.response_data_secret,
+     236                 :            :                         m_rsp_secret_buffer, secured_message_context->hash_size);
+     237                 :          1 : }
+     238                 :            : 
+     239                 :            : /**
+     240                 :            :  * Test 2: receiving a KEY_UPDATE message larger than specified, with the
+     241                 :            :  * UpdateKey operation.
+     242                 :            :  * Expected behavior: the responder refuses the KEY_UPDATE message and
+     243                 :            :  * produces an ERROR message indicating the InvalidRequest. No keys
+     244                 :            :  * are updated.
+     245                 :            :  **/
+     246                 :          1 : void libspdm_test_responder_key_update_case2(void **state)
+     247                 :            : {
+     248                 :            :     libspdm_return_t status;
+     249                 :            :     libspdm_test_context_t            *spdm_test_context;
+     250                 :            :     libspdm_context_t                 *spdm_context;
+     251                 :            :     uint32_t session_id;
+     252                 :            :     libspdm_session_info_t            *session_info;
+     253                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     254                 :            : 
+     255                 :            :     size_t response_size;
+     256                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     257                 :            :     spdm_key_update_response_t *spdm_response;
+     258                 :            : 
+     259                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     260                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     261                 :            : 
+     262                 :          1 :     spdm_test_context = *state;
+     263                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     264                 :          1 :     spdm_test_context->case_id = 0x2;
+     265                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     266                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     267                 :            : 
+     268                 :          1 :     libspdm_set_standard_key_update_test_state(
+     269                 :            :         spdm_context, &session_id);
+     270                 :            : 
+     271                 :          1 :     session_info = &spdm_context->session_info[0];
+     272                 :          1 :     secured_message_context = session_info->secured_message_context;
+     273                 :            : 
+     274                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+     275                 :          1 :         session_info->secured_message_context,
+     276                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+     277                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+     278                 :            : 
+     279                 :            :     /*no keys are updated*/
+     280                 :            : 
+     281                 :          1 :     response_size = sizeof(response);
+     282                 :          1 :     status = libspdm_get_response_key_update(spdm_context,
+     283                 :            :                                              m_libspdm_key_update_request2_size,
+     284                 :            :                                              &m_libspdm_key_update_request2,
+     285                 :            :                                              &response_size, response);
+     286                 :            : 
+     287                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     288                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     289                 :          1 :     spdm_response = (void *)response;
+     290                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     291                 :            :                      SPDM_ERROR);
+     292                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     293                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+     294                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     295                 :          1 :     assert_memory_equal(secured_message_context
+     296                 :            :                         ->application_secret.request_data_secret,
+     297                 :            :                         m_req_secret_buffer, secured_message_context->hash_size);
+     298                 :          1 :     assert_memory_equal(secured_message_context
+     299                 :            :                         ->application_secret.response_data_secret,
+     300                 :            :                         m_rsp_secret_buffer, secured_message_context->hash_size);
+     301                 :          1 : }
+     302                 :            : 
+     303                 :            : /**
+     304                 :            :  * Test 3: receiving a correct KEY_UPDATE from the requester, but the
+     305                 :            :  * responder is in a Busy state.
+     306                 :            :  * Expected behavior: the responder accepts the request, but produces an
+     307                 :            :  * ERROR message indicating the Busy state. No keys are updated.
+     308                 :            :  **/
+     309                 :          1 : void libspdm_test_responder_key_update_case3(void **state)
+     310                 :            : {
+     311                 :            :     libspdm_return_t status;
+     312                 :            :     libspdm_test_context_t            *spdm_test_context;
+     313                 :            :     libspdm_context_t                 *spdm_context;
+     314                 :            :     uint32_t session_id;
+     315                 :            :     libspdm_session_info_t            *session_info;
+     316                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     317                 :            : 
+     318                 :            :     size_t response_size;
+     319                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     320                 :            :     spdm_key_update_response_t *spdm_response;
+     321                 :            : 
+     322                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     323                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     324                 :            : 
+     325                 :          1 :     spdm_test_context = *state;
+     326                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     327                 :          1 :     spdm_test_context->case_id = 0x3;
+     328                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     329                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     330                 :            : 
+     331                 :          1 :     libspdm_set_standard_key_update_test_state(
+     332                 :            :         spdm_context, &session_id);
+     333                 :            : 
+     334                 :            :     /*busy state*/
+     335                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_BUSY;
+     336                 :            : 
+     337                 :          1 :     session_info = &spdm_context->session_info[0];
+     338                 :          1 :     secured_message_context = session_info->secured_message_context;
+     339                 :            : 
+     340                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+     341                 :          1 :         session_info->secured_message_context,
+     342                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+     343                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+     344                 :            : 
+     345                 :            :     /*no keys are updated*/
+     346                 :            : 
+     347                 :          1 :     response_size = sizeof(response);
+     348                 :          1 :     status = libspdm_get_response_key_update(spdm_context,
+     349                 :            :                                              m_libspdm_key_update_request1_size,
+     350                 :            :                                              &m_libspdm_key_update_request1,
+     351                 :            :                                              &response_size, response);
+     352                 :            : 
+     353                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     354                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     355                 :          1 :     spdm_response = (void *)response;
+     356                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     357                 :            :                      SPDM_ERROR);
+     358                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_BUSY);
+     359                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     360                 :          1 :     assert_int_equal(spdm_context->response_state,
+     361                 :            :                      LIBSPDM_RESPONSE_STATE_BUSY);
+     362                 :          1 :     assert_memory_equal(secured_message_context
+     363                 :            :                         ->application_secret.request_data_secret,
+     364                 :            :                         m_req_secret_buffer, secured_message_context->hash_size);
+     365                 :          1 :     assert_memory_equal(secured_message_context
+     366                 :            :                         ->application_secret.response_data_secret,
+     367                 :            :                         m_rsp_secret_buffer, secured_message_context->hash_size);
+     368                 :          1 : }
+     369                 :            : 
+     370                 :            : /**
+     371                 :            :  * Test 4: receiving a correct KEY_UPDATE message from the requester, but
+     372                 :            :  * the responder requires resynchronization with the requester.
+     373                 :            :  * Expected behavior: the responder accepts the request, but produces an
+     374                 :            :  * ERROR message indicating the NeedResynch state. No keys are updated.
+     375                 :            :  **/
+     376                 :          1 : void libspdm_test_responder_key_update_case4(void **state)
+     377                 :            : {
+     378                 :            :     libspdm_return_t status;
+     379                 :            :     libspdm_test_context_t            *spdm_test_context;
+     380                 :            :     libspdm_context_t                 *spdm_context;
+     381                 :            :     uint32_t session_id;
+     382                 :            :     libspdm_session_info_t            *session_info;
+     383                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     384                 :            : 
+     385                 :            :     size_t response_size;
+     386                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     387                 :            :     spdm_key_update_response_t *spdm_response;
+     388                 :            : 
+     389                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     390                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     391                 :            : 
+     392                 :          1 :     spdm_test_context = *state;
+     393                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     394                 :          1 :     spdm_test_context->case_id = 0x4;
+     395                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     396                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     397                 :            : 
+     398                 :          1 :     libspdm_set_standard_key_update_test_state(
+     399                 :            :         spdm_context, &session_id);
+     400                 :            : 
+     401                 :            :     /*need resync state*/
+     402                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NEED_RESYNC;
+     403                 :            : 
+     404                 :          1 :     session_info = &spdm_context->session_info[0];
+     405                 :          1 :     secured_message_context = session_info->secured_message_context;
+     406                 :            : 
+     407                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+     408                 :          1 :         session_info->secured_message_context,
+     409                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+     410                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+     411                 :            : 
+     412                 :            :     /*no keys are updated*/
+     413                 :            : 
+     414                 :          1 :     response_size = sizeof(response);
+     415                 :          1 :     status = libspdm_get_response_key_update(spdm_context,
+     416                 :            :                                              m_libspdm_key_update_request1_size,
+     417                 :            :                                              &m_libspdm_key_update_request1,
+     418                 :            :                                              &response_size, response);
+     419                 :            : 
+     420                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     421                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     422                 :          1 :     spdm_response = (void *)response;
+     423                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     424                 :            :                      SPDM_ERROR);
+     425                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     426                 :            :                      SPDM_ERROR_CODE_REQUEST_RESYNCH);
+     427                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     428                 :          1 :     assert_int_equal(spdm_context->response_state,
+     429                 :            :                      LIBSPDM_RESPONSE_STATE_NEED_RESYNC);
+     430                 :          1 :     assert_memory_equal(secured_message_context
+     431                 :            :                         ->application_secret.request_data_secret,
+     432                 :            :                         m_req_secret_buffer, secured_message_context->hash_size);
+     433                 :          1 :     assert_memory_equal(secured_message_context
+     434                 :            :                         ->application_secret.response_data_secret,
+     435                 :            :                         m_rsp_secret_buffer, secured_message_context->hash_size);
+     436                 :          1 : }
+     437                 :            : 
+     438                 :            : #if LIBSPDM_RESPOND_IF_READY_SUPPORT
+     439                 :            : /**
+     440                 :            :  * Test 5: receiving a correct KEY_UPDATE from the requester, but the
+     441                 :            :  * responder could not produce the response in time.
+     442                 :            :  * Expected behavior: the responder accepts the request, but produces an
+     443                 :            :  * ERROR message indicating the ResponseNotReady state. No keys are
+     444                 :            :  * updated.
+     445                 :            :  **/
+     446                 :          1 : void libspdm_test_responder_key_update_case5(void **state)
+     447                 :            : {
+     448                 :            :     libspdm_return_t status;
+     449                 :            :     libspdm_test_context_t            *spdm_test_context;
+     450                 :            :     libspdm_context_t                 *spdm_context;
+     451                 :            :     uint32_t session_id;
+     452                 :            :     libspdm_session_info_t            *session_info;
+     453                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     454                 :            : 
+     455                 :            :     size_t response_size;
+     456                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     457                 :            :     spdm_key_update_response_t *spdm_response;
+     458                 :            :     spdm_error_data_response_not_ready_t *error_data;
+     459                 :            : 
+     460                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     461                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     462                 :            : 
+     463                 :          1 :     spdm_test_context = *state;
+     464                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     465                 :          1 :     spdm_test_context->case_id = 0x5;
+     466                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     467                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     468                 :            : 
+     469                 :          1 :     libspdm_set_standard_key_update_test_state(
+     470                 :            :         spdm_context, &session_id);
+     471                 :            : 
+     472                 :            :     /*not ready state*/
+     473                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NOT_READY;
+     474                 :            : 
+     475                 :          1 :     session_info = &spdm_context->session_info[0];
+     476                 :          1 :     secured_message_context = session_info->secured_message_context;
+     477                 :            : 
+     478                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+     479                 :          1 :         session_info->secured_message_context,
+     480                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+     481                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+     482                 :            : 
+     483                 :            :     /*no keys are updated*/
+     484                 :            : 
+     485                 :          1 :     response_size = sizeof(response);
+     486                 :          1 :     status = libspdm_get_response_key_update(spdm_context,
+     487                 :            :                                              m_libspdm_key_update_request1_size,
+     488                 :            :                                              &m_libspdm_key_update_request1,
+     489                 :            :                                              &response_size, response);
+     490                 :            : 
+     491                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     492                 :          1 :     assert_int_equal(response_size,
+     493                 :            :                      sizeof(spdm_error_response_t) +
+     494                 :            :                      sizeof(spdm_error_data_response_not_ready_t));
+     495                 :          1 :     spdm_response = (void *)response;
+     496                 :          1 :     error_data =
+     497                 :            :         (spdm_error_data_response_not_ready_t *)(spdm_response + 1);
+     498                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     499                 :            :                      SPDM_ERROR);
+     500                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     501                 :            :                      SPDM_ERROR_CODE_RESPONSE_NOT_READY);
+     502                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     503                 :          1 :     assert_int_equal(spdm_context->response_state,
+     504                 :            :                      LIBSPDM_RESPONSE_STATE_NOT_READY);
+     505                 :          1 :     assert_int_equal(error_data->request_code, SPDM_KEY_UPDATE);
+     506                 :          1 :     assert_memory_equal(secured_message_context
+     507                 :            :                         ->application_secret.request_data_secret,
+     508                 :            :                         m_req_secret_buffer, secured_message_context->hash_size);
+     509                 :          1 :     assert_memory_equal(secured_message_context
+     510                 :            :                         ->application_secret.response_data_secret,
+     511                 :            :                         m_rsp_secret_buffer, secured_message_context->hash_size);
+     512                 :          1 : }
+     513                 :            : #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
+     514                 :            : 
+     515                 :            : /**
+     516                 :            :  * Test 6: receiving a correct KEY_UPDATE from the requester, but the
+     517                 :            :  * responder is not set no receive a FINISH message because previous messages
+     518                 :            :  * (namely, GET_CAPABILITIES, NEGOTIATE_ALGORITHMS or GET_DIGESTS) have not
+     519                 :            :  * been received.
+     520                 :            :  * Expected behavior: the responder rejects the request, and produces an
+     521                 :            :  * ERROR message indicating the UnexpectedRequest. No keys are updated.
+     522                 :            :  **/
+     523                 :          1 : void libspdm_test_responder_key_update_case6(void **state)
+     524                 :            : {
+     525                 :            :     libspdm_return_t status;
+     526                 :            :     libspdm_test_context_t            *spdm_test_context;
+     527                 :            :     libspdm_context_t                 *spdm_context;
+     528                 :            :     uint32_t session_id;
+     529                 :            :     libspdm_session_info_t            *session_info;
+     530                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     531                 :            : 
+     532                 :            :     size_t response_size;
+     533                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     534                 :            :     spdm_key_update_response_t *spdm_response;
+     535                 :            : 
+     536                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     537                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     538                 :            : 
+     539                 :          1 :     spdm_test_context = *state;
+     540                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     541                 :          1 :     spdm_test_context->case_id = 0x6;
+     542                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     543                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     544                 :            : 
+     545                 :          1 :     libspdm_set_standard_key_update_test_state(
+     546                 :            :         spdm_context, &session_id);
+     547                 :            : 
+     548                 :            :     /*not negotiated state*/
+     549                 :          1 :     spdm_context->connection_info.connection_state =
+     550                 :            :         LIBSPDM_CONNECTION_STATE_NOT_STARTED;
+     551                 :            : 
+     552                 :          1 :     session_info = &spdm_context->session_info[0];
+     553                 :          1 :     secured_message_context = session_info->secured_message_context;
+     554                 :            : 
+     555                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+     556                 :          1 :         session_info->secured_message_context,
+     557                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+     558                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+     559                 :            : 
+     560                 :            :     /*no keys are updated*/
+     561                 :            : 
+     562                 :          1 :     response_size = sizeof(response);
+     563                 :          1 :     status = libspdm_get_response_key_update(spdm_context,
+     564                 :            :                                              m_libspdm_key_update_request1_size,
+     565                 :            :                                              &m_libspdm_key_update_request1,
+     566                 :            :                                              &response_size, response);
+     567                 :            : 
+     568                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     569                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     570                 :          1 :     spdm_response = (void *)response;
+     571                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     572                 :            :                      SPDM_ERROR);
+     573                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     574                 :            :                      SPDM_ERROR_CODE_UNEXPECTED_REQUEST);
+     575                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     576                 :          1 :     assert_memory_equal(secured_message_context
+     577                 :            :                         ->application_secret.request_data_secret,
+     578                 :            :                         m_req_secret_buffer, secured_message_context->hash_size);
+     579                 :          1 :     assert_memory_equal(secured_message_context
+     580                 :            :                         ->application_secret.response_data_secret,
+     581                 :            :                         m_rsp_secret_buffer, secured_message_context->hash_size);
+     582                 :          1 : }
+     583                 :            : 
+     584                 :          1 : void libspdm_test_responder_key_update_case7(void **state)
+     585                 :            : {
+     586                 :            :     libspdm_return_t status;
+     587                 :            :     libspdm_test_context_t            *spdm_test_context;
+     588                 :            :     libspdm_context_t                 *spdm_context;
+     589                 :            :     uint32_t session_id;
+     590                 :            :     libspdm_session_info_t            *session_info;
+     591                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     592                 :            : 
+     593                 :            :     size_t response_size;
+     594                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     595                 :            :     spdm_key_update_response_t *spdm_response;
+     596                 :            : 
+     597                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     598                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     599                 :            : 
+     600                 :          1 :     spdm_test_context = *state;
+     601                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     602                 :          1 :     spdm_test_context->case_id = 0x7;
+     603                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     604                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     605                 :            : 
+     606                 :          1 :     libspdm_set_standard_key_update_test_state(
+     607                 :            :         spdm_context, &session_id);
+     608                 :            : 
+     609                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     610                 :            :     /*"filling" buffers*/
+     611                 :            :     spdm_context->transcript.message_m.buffer_size =
+     612                 :            :         spdm_context->transcript.message_m.max_buffer_size;
+     613                 :            :     spdm_context->transcript.message_b.buffer_size =
+     614                 :            :         spdm_context->transcript.message_b.max_buffer_size;
+     615                 :            :     spdm_context->transcript.message_c.buffer_size =
+     616                 :            :         spdm_context->transcript.message_c.max_buffer_size;
+     617                 :            :     spdm_context->transcript.message_mut_b.buffer_size =
+     618                 :            :         spdm_context->transcript.message_mut_b.max_buffer_size;
+     619                 :            :     spdm_context->transcript.message_mut_c.buffer_size =
+     620                 :            :         spdm_context->transcript.message_mut_c.max_buffer_size;
+     621                 :            : #endif
+     622                 :            : 
+     623                 :          1 :     session_info = &spdm_context->session_info[0];
+     624                 :          1 :     secured_message_context = session_info->secured_message_context;
+     625                 :            : 
+     626                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+     627                 :          1 :         session_info->secured_message_context,
+     628                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+     629                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+     630                 :            : 
+     631                 :            :     /*request side updated*/
+     632                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+     633                 :            :                                   secured_message_context->hash_size,
+     634                 :            :                                   m_req_secret_buffer, m_req_secret_buffer,
+     635                 :            :                                   secured_message_context->hash_size);
+     636                 :            :     /*response side *not* updated*/
+     637                 :            : 
+     638                 :          1 :     response_size = sizeof(response);
+     639                 :          1 :     status = libspdm_get_response_key_update(spdm_context,
+     640                 :            :                                              m_libspdm_key_update_request1_size,
+     641                 :            :                                              &m_libspdm_key_update_request1,
+     642                 :            :                                              &response_size, response);
+     643                 :            : 
+     644                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     645                 :          1 :     assert_int_equal(response_size, sizeof(spdm_key_update_response_t));
+     646                 :          1 :     spdm_response = (void *)response;
+     647                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     648                 :            :                      SPDM_KEY_UPDATE_ACK);
+     649                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     650                 :            :                      SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY);
+     651                 :          1 :     assert_int_equal(spdm_response->header.param2,
+     652                 :            :                      m_libspdm_key_update_request1.header.param2);
+     653                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     654                 :            :     assert_int_equal(session_info->session_transcript.message_m.buffer_size, 0);
+     655                 :            :     assert_int_equal(spdm_context->transcript.message_b.buffer_size, 0);
+     656                 :            :     assert_int_equal(spdm_context->transcript.message_c.buffer_size, 0);
+     657                 :            :     assert_int_equal(spdm_context->transcript.message_mut_b.buffer_size, 0);
+     658                 :            :     assert_int_equal(spdm_context->transcript.message_mut_c.buffer_size, 0);
+     659                 :            : #endif
+     660                 :          1 :     assert_memory_equal(secured_message_context
+     661                 :            :                         ->application_secret.request_data_secret,
+     662                 :            :                         m_req_secret_buffer, secured_message_context->hash_size);
+     663                 :          1 :     assert_memory_equal(secured_message_context
+     664                 :            :                         ->application_secret.response_data_secret,
+     665                 :            :                         m_rsp_secret_buffer, secured_message_context->hash_size);
+     666                 :          1 : }
+     667                 :            : 
+     668                 :            : /**
+     669                 :            :  * Test 8: receiving a correct KEY_UPDATE message from the requester, but the
+     670                 :            :  * responder has no capabilities for key update.
+     671                 :            :  * Expected behavior: the responder refuses the KEY_UPDATE message and
+     672                 :            :  * produces an ERROR message indicating the UnsupportedRequest. No keys are
+     673                 :            :  * updated.
+     674                 :            :  **/
+     675                 :          1 : void libspdm_test_responder_key_update_case8(void **state)
+     676                 :            : {
+     677                 :            :     libspdm_return_t status;
+     678                 :            :     libspdm_test_context_t            *spdm_test_context;
+     679                 :            :     libspdm_context_t                 *spdm_context;
+     680                 :            :     uint32_t session_id;
+     681                 :            :     libspdm_session_info_t            *session_info;
+     682                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     683                 :            : 
+     684                 :            :     size_t response_size;
+     685                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     686                 :            :     spdm_key_update_response_t *spdm_response;
+     687                 :            : 
+     688                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     689                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     690                 :            : 
+     691                 :          1 :     spdm_test_context = *state;
+     692                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     693                 :          1 :     spdm_test_context->case_id = 0x8;
+     694                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     695                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     696                 :            : 
+     697                 :          1 :     libspdm_set_standard_key_update_test_state(
+     698                 :            :         spdm_context, &session_id);
+     699                 :            : 
+     700                 :            :     /*no capabilities*/
+     701                 :          1 :     spdm_context->connection_info.capability.flags &=
+     702                 :            :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_UPD_CAP;
+     703                 :          1 :     spdm_context->local_context.capability.flags &=
+     704                 :            :         ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP;
+     705                 :            : 
+     706                 :          1 :     session_info = &spdm_context->session_info[0];
+     707                 :          1 :     secured_message_context = session_info->secured_message_context;
+     708                 :            : 
+     709                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+     710                 :          1 :         session_info->secured_message_context,
+     711                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+     712                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+     713                 :            : 
+     714                 :            :     /*no keys are updated*/
+     715                 :            : 
+     716                 :          1 :     response_size = sizeof(response);
+     717                 :          1 :     status = libspdm_get_response_key_update(spdm_context,
+     718                 :            :                                              m_libspdm_key_update_request1_size,
+     719                 :            :                                              &m_libspdm_key_update_request1,
+     720                 :            :                                              &response_size, response);
+     721                 :            : 
+     722                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     723                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     724                 :          1 :     spdm_response = (void *)response;
+     725                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     726                 :            :                      SPDM_ERROR);
+     727                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     728                 :            :                      SPDM_ERROR_CODE_UNSUPPORTED_REQUEST);
+     729                 :          1 :     assert_int_equal(spdm_response->header.param2, SPDM_KEY_UPDATE);
+     730                 :          1 :     assert_memory_equal(secured_message_context
+     731                 :            :                         ->application_secret.request_data_secret,
+     732                 :            :                         m_req_secret_buffer, secured_message_context->hash_size);
+     733                 :          1 :     assert_memory_equal(secured_message_context
+     734                 :            :                         ->application_secret.response_data_secret,
+     735                 :            :                         m_rsp_secret_buffer, secured_message_context->hash_size);
+     736                 :          1 : }
+     737                 :            : 
+     738                 :            : /**
+     739                 :            :  * Test 9: receiving a correct KEY_UPDATE message from the requester, but the
+     740                 :            :  * responder is not correctly setup by not initializing a session during
+     741                 :            :  * KEY_EXCHANGE.
+     742                 :            :  * Expected behavior: the responder refuses the KEY_UPDATE message and produces
+     743                 :            :  * an ERROR message indicating the UnsupportedRequest. No keys are updated.
+     744                 :            :  **/
+     745                 :          1 : void libspdm_test_responder_key_update_case9(void **state)
+     746                 :            : {
+     747                 :            :     libspdm_return_t status;
+     748                 :            :     libspdm_test_context_t            *spdm_test_context;
+     749                 :            :     libspdm_context_t                 *spdm_context;
+     750                 :            :     uint32_t session_id;
+     751                 :            :     libspdm_session_info_t            *session_info;
+     752                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     753                 :            : 
+     754                 :            :     size_t response_size;
+     755                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     756                 :            :     spdm_key_update_response_t *spdm_response;
+     757                 :            : 
+     758                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     759                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     760                 :            : 
+     761                 :          1 :     spdm_test_context = *state;
+     762                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     763                 :          1 :     spdm_test_context->case_id = 0x9;
+     764                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     765                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     766                 :            : 
+     767                 :          1 :     libspdm_set_standard_key_update_test_state(
+     768                 :            :         spdm_context, &session_id);
+     769                 :            : 
+     770                 :          1 :     session_info = &spdm_context->session_info[0];
+     771                 :          1 :     secured_message_context = session_info->secured_message_context;
+     772                 :            : 
+     773                 :            :     /*uninitialized session*/
+     774                 :          1 :     libspdm_secured_message_set_session_state(
+     775                 :            :         session_info->secured_message_context,
+     776                 :            :         LIBSPDM_SESSION_STATE_NOT_STARTED);
+     777                 :            : 
+     778                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+     779                 :          1 :         session_info->secured_message_context,
+     780                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+     781                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+     782                 :            : 
+     783                 :            :     /*no keys are updated*/
+     784                 :            : 
+     785                 :          1 :     response_size = sizeof(response);
+     786                 :          1 :     status = libspdm_get_response_key_update(spdm_context,
+     787                 :            :                                              m_libspdm_key_update_request1_size,
+     788                 :            :                                              &m_libspdm_key_update_request1,
+     789                 :            :                                              &response_size, response);
+     790                 :            : 
+     791                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     792                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     793                 :          1 :     spdm_response = (void *)response;
+     794                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     795                 :            :                      SPDM_ERROR);
+     796                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     797                 :            :                      SPDM_ERROR_CODE_UNEXPECTED_REQUEST);
+     798                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     799                 :          1 :     assert_memory_equal(secured_message_context
+     800                 :            :                         ->application_secret.request_data_secret,
+     801                 :            :                         m_req_secret_buffer, secured_message_context->hash_size);
+     802                 :          1 :     assert_memory_equal(secured_message_context
+     803                 :            :                         ->application_secret.response_data_secret,
+     804                 :            :                         m_rsp_secret_buffer, secured_message_context->hash_size);
+     805                 :          1 : }
+     806                 :            : 
+     807                 :            : /**
+     808                 :            :  * Test 10: receiving a correct KEY_UPDATE message from the requester with
+     809                 :            :  * the UpdateAllKeys operation.
+     810                 :            :  * Expected behavior: the responder accepts the request, produces a valid
+     811                 :            :  * KEY_UPDATE_ACK response message, and both the request data key and the
+     812                 :            :  * response data key are updated.
+     813                 :            :  **/
+     814                 :          1 : void libspdm_test_responder_key_update_case10(void **state)
+     815                 :            : {
+     816                 :            :     libspdm_return_t status;
+     817                 :            :     libspdm_test_context_t            *spdm_test_context;
+     818                 :            :     libspdm_context_t                 *spdm_context;
+     819                 :            :     uint32_t session_id;
+     820                 :            :     libspdm_session_info_t            *session_info;
+     821                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     822                 :            : 
+     823                 :            :     size_t response_size;
+     824                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     825                 :            :     spdm_key_update_response_t *spdm_response;
+     826                 :            : 
+     827                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     828                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     829                 :            : 
+     830                 :          1 :     spdm_test_context = *state;
+     831                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     832                 :          1 :     spdm_test_context->case_id = 0xA;
+     833                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     834                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     835                 :            : 
+     836                 :          1 :     libspdm_set_standard_key_update_test_state(
+     837                 :            :         spdm_context, &session_id);
+     838                 :            : 
+     839                 :          1 :     session_info = &spdm_context->session_info[0];
+     840                 :          1 :     secured_message_context = session_info->secured_message_context;
+     841                 :            : 
+     842                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+     843                 :          1 :         session_info->secured_message_context,
+     844                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+     845                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+     846                 :            : 
+     847                 :            :     /*request side updated*/
+     848                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+     849                 :            :                                   secured_message_context->hash_size,
+     850                 :            :                                   m_req_secret_buffer, m_req_secret_buffer,
+     851                 :            :                                   secured_message_context->hash_size);
+     852                 :            :     /*response side updated*/
+     853                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+     854                 :            :                                   secured_message_context->hash_size,
+     855                 :            :                                   m_rsp_secret_buffer, m_rsp_secret_buffer,
+     856                 :            :                                   secured_message_context->hash_size);
+     857                 :            : 
+     858                 :          1 :     response_size = sizeof(response);
+     859                 :          1 :     status = libspdm_get_response_key_update(spdm_context,
+     860                 :            :                                              m_libspdm_key_update_request3_size,
+     861                 :            :                                              &m_libspdm_key_update_request3,
+     862                 :            :                                              &response_size, response);
+     863                 :            : 
+     864                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     865                 :          1 :     assert_int_equal(response_size, sizeof(spdm_key_update_response_t));
+     866                 :          1 :     spdm_response = (void *)response;
+     867                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     868                 :            :                      SPDM_KEY_UPDATE_ACK);
+     869                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     870                 :            :                      SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_ALL_KEYS);
+     871                 :          1 :     assert_int_equal(spdm_response->header.param2,
+     872                 :            :                      m_libspdm_key_update_request3.header.param2);
+     873                 :          1 :     assert_memory_equal(secured_message_context
+     874                 :            :                         ->application_secret.request_data_secret,
+     875                 :            :                         m_req_secret_buffer, secured_message_context->hash_size);
+     876                 :          1 :     assert_memory_equal(secured_message_context
+     877                 :            :                         ->application_secret.response_data_secret,
+     878                 :            :                         m_rsp_secret_buffer, secured_message_context->hash_size);
+     879                 :          1 : }
+     880                 :            : 
+     881                 :            : /**
+     882                 :            :  * Test 11: receiving a KEY_UPDATE message larger than specified, with the
+     883                 :            :  * UpdateAllKeys operation.
+     884                 :            :  * Expected behavior: the responder refuses the KEY_UPDATE message and
+     885                 :            :  * produces an ERROR message indicating the InvalidRequest. No keys
+     886                 :            :  * are updated.
+     887                 :            :  **/
+     888                 :          1 : void libspdm_test_responder_key_update_case11(void **state)
+     889                 :            : {
+     890                 :            :     libspdm_return_t status;
+     891                 :            :     libspdm_test_context_t            *spdm_test_context;
+     892                 :            :     libspdm_context_t                 *spdm_context;
+     893                 :            :     uint32_t session_id;
+     894                 :            :     libspdm_session_info_t            *session_info;
+     895                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     896                 :            : 
+     897                 :            :     size_t response_size;
+     898                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     899                 :            :     spdm_key_update_response_t *spdm_response;
+     900                 :            : 
+     901                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     902                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     903                 :            : 
+     904                 :          1 :     spdm_test_context = *state;
+     905                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     906                 :          1 :     spdm_test_context->case_id = 0xB;
+     907                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     908                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     909                 :            : 
+     910                 :          1 :     libspdm_set_standard_key_update_test_state(
+     911                 :            :         spdm_context, &session_id);
+     912                 :            : 
+     913                 :          1 :     session_info = &spdm_context->session_info[0];
+     914                 :          1 :     secured_message_context = session_info->secured_message_context;
+     915                 :            : 
+     916                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+     917                 :          1 :         session_info->secured_message_context,
+     918                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+     919                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+     920                 :            : 
+     921                 :            :     /*no keys are updated*/
+     922                 :            : 
+     923                 :          1 :     response_size = sizeof(response);
+     924                 :          1 :     status = libspdm_get_response_key_update(spdm_context,
+     925                 :            :                                              m_libspdm_key_update_request4_size,
+     926                 :            :                                              &m_libspdm_key_update_request4,
+     927                 :            :                                              &response_size, response);
+     928                 :            : 
+     929                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     930                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     931                 :          1 :     spdm_response = (void *)response;
+     932                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     933                 :            :                      SPDM_ERROR);
+     934                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     935                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+     936                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     937                 :          1 :     assert_memory_equal(secured_message_context
+     938                 :            :                         ->application_secret.request_data_secret,
+     939                 :            :                         m_req_secret_buffer, secured_message_context->hash_size);
+     940                 :          1 :     assert_memory_equal(secured_message_context
+     941                 :            :                         ->application_secret.response_data_secret,
+     942                 :            :                         m_rsp_secret_buffer, secured_message_context->hash_size);
+     943                 :          1 : }
+     944                 :            : 
+     945                 :            : /**
+     946                 :            :  * Test 12: receiving a correct KEY_UPDATE message from the requester with
+     947                 :            :  * the VerifyNewKey operation. The responder is setup as if a valid
+     948                 :            :  * KEY_UPDATE request with the UpdateKey has been previously received.
+     949                 :            :  * Expected behavior: the responder accepts the request, produces a valid
+     950                 :            :  * KEY_UPDATE_ACK response message, and the request data key is updated.
+     951                 :            :  **/
+     952                 :          1 : void libspdm_test_responder_key_update_case12(void **state)
+     953                 :            : {
+     954                 :            :     libspdm_return_t status;
+     955                 :            :     libspdm_test_context_t            *spdm_test_context;
+     956                 :            :     libspdm_context_t                 *spdm_context;
+     957                 :            :     uint32_t session_id;
+     958                 :            :     libspdm_session_info_t            *session_info;
+     959                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     960                 :            : 
+     961                 :            :     size_t response_size;
+     962                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     963                 :            :     spdm_key_update_response_t *spdm_response;
+     964                 :            : 
+     965                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     966                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+     967                 :            : 
+     968                 :          1 :     spdm_test_context = *state;
+     969                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     970                 :          1 :     spdm_test_context->case_id = 0xC;
+     971                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     972                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     973                 :            : 
+     974                 :          1 :     libspdm_set_standard_key_update_test_state(
+     975                 :            :         spdm_context, &session_id);
+     976                 :            : 
+     977                 :          1 :     session_info = &spdm_context->session_info[0];
+     978                 :          1 :     secured_message_context = session_info->secured_message_context;
+     979                 :            : 
+     980                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+     981                 :          1 :         session_info->secured_message_context,
+     982                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+     983                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+     984                 :            : 
+     985                 :            :     /*last request: UpdateKey*/
+     986                 :          1 :     session_info->last_key_update_request = m_libspdm_key_update_request1;
+     987                 :            : 
+     988                 :            :     /*mocked major secret update*/
+     989                 :          1 :     libspdm_copy_mem(&secured_message_context->application_secret_backup.request_data_secret,
+     990                 :            :                      sizeof(secured_message_context->application_secret_backup.request_data_secret),
+     991                 :          1 :                      &secured_message_context->application_secret.request_data_secret,
+     992                 :            :                      LIBSPDM_MAX_HASH_SIZE);
+     993                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+     994                 :            :                                   secured_message_context->hash_size,
+     995                 :            :                                   secured_message_context->application_secret
+     996                 :          1 :                                   .request_data_secret,
+     997                 :            :                                   secured_message_context->application_secret
+     998                 :          1 :                                   .request_data_secret,
+     999                 :            :                                   secured_message_context->hash_size);
+    1000                 :            : 
+    1001                 :            :     /*request side updated*/
+    1002                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    1003                 :            :                                   secured_message_context->hash_size,
+    1004                 :            :                                   m_req_secret_buffer, m_req_secret_buffer,
+    1005                 :            :                                   secured_message_context->hash_size);
+    1006                 :            :     /*response side *not* updated*/
+    1007                 :            : 
+    1008                 :          1 :     response_size = sizeof(response);
+    1009                 :          1 :     status = libspdm_get_response_key_update(spdm_context,
+    1010                 :            :                                              m_libspdm_key_update_request5_size,
+    1011                 :            :                                              &m_libspdm_key_update_request5,
+    1012                 :            :                                              &response_size, response);
+    1013                 :            : 
+    1014                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1015                 :          1 :     assert_int_equal(response_size, sizeof(spdm_key_update_response_t));
+    1016                 :          1 :     spdm_response = (void *)response;
+    1017                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1018                 :            :                      SPDM_KEY_UPDATE_ACK);
+    1019                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1020                 :            :                      SPDM_KEY_UPDATE_OPERATIONS_TABLE_VERIFY_NEW_KEY);
+    1021                 :          1 :     assert_int_equal(spdm_response->header.param2,
+    1022                 :            :                      m_libspdm_key_update_request5.header.param2);
+    1023                 :          1 :     assert_memory_equal(secured_message_context
+    1024                 :            :                         ->application_secret.request_data_secret,
+    1025                 :            :                         m_req_secret_buffer, secured_message_context->hash_size);
+    1026                 :          1 :     assert_memory_equal(secured_message_context
+    1027                 :            :                         ->application_secret.response_data_secret,
+    1028                 :            :                         m_rsp_secret_buffer, secured_message_context->hash_size);
+    1029                 :          1 : }
+    1030                 :            : 
+    1031                 :            : /**
+    1032                 :            :  * Test 13: receiving a KEY_UPDATE message larger than specified, with the
+    1033                 :            :  * VerifyNewKey operation. The responder is setup as if a valid KEY_UPDATE
+    1034                 :            :  * request with the UpdateKey has been previously received.
+    1035                 :            :  * Expected behavior: the responder refuses the KEY_UPDATE message and
+    1036                 :            :  * produces an ERROR message indicating the InvalidRequest. The request
+    1037                 :            :  * data key is not rolled back to before the UpdateKey.
+    1038                 :            :  **/
+    1039                 :          1 : void libspdm_test_responder_key_update_case13(void **state)
+    1040                 :            : {
+    1041                 :            :     libspdm_return_t status;
+    1042                 :            :     libspdm_test_context_t            *spdm_test_context;
+    1043                 :            :     libspdm_context_t                 *spdm_context;
+    1044                 :            :     uint32_t session_id;
+    1045                 :            :     libspdm_session_info_t            *session_info;
+    1046                 :            :     libspdm_secured_message_context_t *secured_message_context;
+    1047                 :            : 
+    1048                 :            :     size_t response_size;
+    1049                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1050                 :            :     spdm_key_update_response_t *spdm_response;
+    1051                 :            : 
+    1052                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    1053                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    1054                 :            : 
+    1055                 :          1 :     spdm_test_context = *state;
+    1056                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1057                 :          1 :     spdm_test_context->case_id = 0xD;
+    1058                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1059                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1060                 :            : 
+    1061                 :          1 :     libspdm_set_standard_key_update_test_state(
+    1062                 :            :         spdm_context, &session_id);
+    1063                 :            : 
+    1064                 :          1 :     session_info = &spdm_context->session_info[0];
+    1065                 :          1 :     secured_message_context = session_info->secured_message_context;
+    1066                 :            : 
+    1067                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    1068                 :          1 :         session_info->secured_message_context,
+    1069                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    1070                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    1071                 :            : 
+    1072                 :            :     /*last request: UpdateKey*/
+    1073                 :          1 :     session_info->last_key_update_request = m_libspdm_key_update_request1;
+    1074                 :            : 
+    1075                 :            :     /*mocked major secret update*/
+    1076                 :          1 :     libspdm_copy_mem(&secured_message_context->application_secret_backup.request_data_secret,
+    1077                 :            :                      sizeof(secured_message_context->application_secret_backup.request_data_secret),
+    1078                 :          1 :                      &secured_message_context->application_secret.request_data_secret,
+    1079                 :            :                      LIBSPDM_MAX_HASH_SIZE);
+    1080                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    1081                 :            :                                   secured_message_context->hash_size,
+    1082                 :            :                                   secured_message_context->application_secret
+    1083                 :          1 :                                   .request_data_secret,
+    1084                 :            :                                   secured_message_context->application_secret
+    1085                 :          1 :                                   .request_data_secret,
+    1086                 :            :                                   secured_message_context->hash_size);
+    1087                 :            : 
+    1088                 :            :     /*request side updated*/
+    1089                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    1090                 :            :                                   secured_message_context->hash_size,
+    1091                 :            :                                   m_req_secret_buffer, m_req_secret_buffer,
+    1092                 :            :                                   secured_message_context->hash_size);
+    1093                 :            :     /*response side *not* updated*/
+    1094                 :            : 
+    1095                 :          1 :     response_size = sizeof(response);
+    1096                 :          1 :     status = libspdm_get_response_key_update(spdm_context,
+    1097                 :            :                                              m_libspdm_key_update_request6_size,
+    1098                 :            :                                              &m_libspdm_key_update_request6,
+    1099                 :            :                                              &response_size, response);
+    1100                 :            : 
+    1101                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1102                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1103                 :          1 :     spdm_response = (void *)response;
+    1104                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1105                 :            :                      SPDM_ERROR);
+    1106                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1107                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+    1108                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1109                 :          1 :     assert_memory_equal(secured_message_context
+    1110                 :            :                         ->application_secret.request_data_secret,
+    1111                 :            :                         m_req_secret_buffer, secured_message_context->hash_size);
+    1112                 :          1 :     assert_memory_equal(secured_message_context
+    1113                 :            :                         ->application_secret.response_data_secret,
+    1114                 :            :                         m_rsp_secret_buffer, secured_message_context->hash_size);
+    1115                 :          1 : }
+    1116                 :            : 
+    1117                 :            : /**
+    1118                 :            :  * Test 14: receiving a correct KEY_UPDATE message from the requester with
+    1119                 :            :  * the VerifyNewKey operation. The responder is setup as if a valid
+    1120                 :            :  * KEY_UPDATE request with the UpdateAllKeys has been previously received.
+    1121                 :            :  * Expected behavior: the responder accepts the request, produces a valid
+    1122                 :            :  * KEY_UPDATE_ACK response message, and both the request data key and the
+    1123                 :            :  * response data key are updated.
+    1124                 :            :  **/
+    1125                 :          1 : void libspdm_test_responder_key_update_case14(void **state)
+    1126                 :            : {
+    1127                 :            :     libspdm_return_t status;
+    1128                 :            :     libspdm_test_context_t            *spdm_test_context;
+    1129                 :            :     libspdm_context_t                 *spdm_context;
+    1130                 :            :     uint32_t session_id;
+    1131                 :            :     libspdm_session_info_t            *session_info;
+    1132                 :            :     libspdm_secured_message_context_t *secured_message_context;
+    1133                 :            : 
+    1134                 :            :     size_t response_size;
+    1135                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1136                 :            :     spdm_key_update_response_t *spdm_response;
+    1137                 :            : 
+    1138                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    1139                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    1140                 :            : 
+    1141                 :          1 :     spdm_test_context = *state;
+    1142                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1143                 :          1 :     spdm_test_context->case_id = 0xE;
+    1144                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1145                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1146                 :            : 
+    1147                 :          1 :     libspdm_set_standard_key_update_test_state(
+    1148                 :            :         spdm_context, &session_id);
+    1149                 :            : 
+    1150                 :          1 :     session_info = &spdm_context->session_info[0];
+    1151                 :          1 :     secured_message_context = session_info->secured_message_context;
+    1152                 :            : 
+    1153                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    1154                 :          1 :         session_info->secured_message_context,
+    1155                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    1156                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    1157                 :            : 
+    1158                 :            :     /*last request: UpdateallKeys*/
+    1159                 :          1 :     session_info->last_key_update_request = m_libspdm_key_update_request3;
+    1160                 :            : 
+    1161                 :            :     /*mocked major secret update*/
+    1162                 :          1 :     libspdm_copy_mem(&secured_message_context->application_secret_backup.request_data_secret,
+    1163                 :            :                      sizeof(secured_message_context->application_secret_backup.request_data_secret),
+    1164                 :          1 :                      &secured_message_context->application_secret.request_data_secret,
+    1165                 :            :                      LIBSPDM_MAX_HASH_SIZE);
+    1166                 :          1 :     libspdm_copy_mem(&secured_message_context->application_secret_backup.response_data_secret,
+    1167                 :            :                      sizeof(secured_message_context->application_secret_backup.response_data_secret),
+    1168                 :          1 :                      &secured_message_context->application_secret.response_data_secret,
+    1169                 :            :                      LIBSPDM_MAX_HASH_SIZE);
+    1170                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    1171                 :            :                                   secured_message_context->hash_size,
+    1172                 :            :                                   secured_message_context->application_secret
+    1173                 :          1 :                                   .request_data_secret,
+    1174                 :            :                                   secured_message_context->application_secret
+    1175                 :          1 :                                   .request_data_secret,
+    1176                 :            :                                   secured_message_context->hash_size);
+    1177                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    1178                 :            :                                   secured_message_context->hash_size,
+    1179                 :            :                                   secured_message_context->application_secret
+    1180                 :          1 :                                   .response_data_secret,
+    1181                 :            :                                   secured_message_context->application_secret
+    1182                 :          1 :                                   .response_data_secret,
+    1183                 :            :                                   secured_message_context->hash_size);
+    1184                 :            : 
+    1185                 :            :     /*request side updated*/
+    1186                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    1187                 :            :                                   secured_message_context->hash_size,
+    1188                 :            :                                   m_req_secret_buffer, m_req_secret_buffer,
+    1189                 :            :                                   secured_message_context->hash_size);
+    1190                 :            :     /*response side updated*/
+    1191                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    1192                 :            :                                   secured_message_context->hash_size,
+    1193                 :            :                                   m_rsp_secret_buffer, m_rsp_secret_buffer,
+    1194                 :            :                                   secured_message_context->hash_size);
+    1195                 :            : 
+    1196                 :          1 :     response_size = sizeof(response);
+    1197                 :          1 :     status = libspdm_get_response_key_update(spdm_context,
+    1198                 :            :                                              m_libspdm_key_update_request5_size,
+    1199                 :            :                                              &m_libspdm_key_update_request5,
+    1200                 :            :                                              &response_size, response);
+    1201                 :            : 
+    1202                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1203                 :          1 :     assert_int_equal(response_size, sizeof(spdm_key_update_response_t));
+    1204                 :          1 :     spdm_response = (void *)response;
+    1205                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1206                 :            :                      SPDM_KEY_UPDATE_ACK);
+    1207                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1208                 :            :                      SPDM_KEY_UPDATE_OPERATIONS_TABLE_VERIFY_NEW_KEY);
+    1209                 :          1 :     assert_int_equal(spdm_response->header.param2,
+    1210                 :            :                      m_libspdm_key_update_request5.header.param2);
+    1211                 :          1 :     assert_memory_equal(secured_message_context
+    1212                 :            :                         ->application_secret.request_data_secret,
+    1213                 :            :                         m_req_secret_buffer, secured_message_context->hash_size);
+    1214                 :          1 :     assert_memory_equal(secured_message_context
+    1215                 :            :                         ->application_secret.response_data_secret,
+    1216                 :            :                         m_rsp_secret_buffer, secured_message_context->hash_size);
+    1217                 :          1 : }
+    1218                 :            : 
+    1219                 :            : /**
+    1220                 :            :  * Test 15: receiving a KEY_UPDATE message larger than specified, with the
+    1221                 :            :  * VerifyNewKey operation. The responder is setup as if a valid KEY_UPDATE
+    1222                 :            :  * request with the UpdateAllKeys has been previously received.
+    1223                 :            :  * Expected behavior: the responder refuses the KEY_UPDATE message and
+    1224                 :            :  * produces an ERROR message indicating the InvalidRequest. Neither the
+    1225                 :            :  * request data key nor the response data key are rolled back to before
+    1226                 :            :  * the UpdateAllKeys.
+    1227                 :            :  **/
+    1228                 :          1 : void libspdm_test_responder_key_update_case15(void **state)
+    1229                 :            : {
+    1230                 :            :     libspdm_return_t status;
+    1231                 :            :     libspdm_test_context_t            *spdm_test_context;
+    1232                 :            :     libspdm_context_t                 *spdm_context;
+    1233                 :            :     uint32_t session_id;
+    1234                 :            :     libspdm_session_info_t            *session_info;
+    1235                 :            :     libspdm_secured_message_context_t *secured_message_context;
+    1236                 :            : 
+    1237                 :            :     size_t response_size;
+    1238                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1239                 :            :     spdm_key_update_response_t *spdm_response;
+    1240                 :            : 
+    1241                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    1242                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    1243                 :            : 
+    1244                 :          1 :     spdm_test_context = *state;
+    1245                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1246                 :          1 :     spdm_test_context->case_id = 0xF;
+    1247                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1248                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1249                 :            : 
+    1250                 :          1 :     libspdm_set_standard_key_update_test_state(
+    1251                 :            :         spdm_context, &session_id);
+    1252                 :            : 
+    1253                 :          1 :     session_info = &spdm_context->session_info[0];
+    1254                 :          1 :     secured_message_context = session_info->secured_message_context;
+    1255                 :            : 
+    1256                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    1257                 :          1 :         session_info->secured_message_context,
+    1258                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    1259                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    1260                 :            : 
+    1261                 :            :     /*last request: UpdateAllKeys*/
+    1262                 :          1 :     session_info->last_key_update_request = m_libspdm_key_update_request3;
+    1263                 :            : 
+    1264                 :            :     /*mocked major secret update*/
+    1265                 :          1 :     libspdm_copy_mem(&secured_message_context->application_secret_backup.request_data_secret,
+    1266                 :            :                      sizeof(secured_message_context->application_secret_backup.request_data_secret),
+    1267                 :          1 :                      &secured_message_context->application_secret.request_data_secret,
+    1268                 :            :                      LIBSPDM_MAX_HASH_SIZE);
+    1269                 :          1 :     libspdm_copy_mem(&secured_message_context->application_secret_backup.response_data_secret,
+    1270                 :            :                      sizeof(secured_message_context->application_secret_backup.response_data_secret),
+    1271                 :          1 :                      &secured_message_context->application_secret.response_data_secret,
+    1272                 :            :                      LIBSPDM_MAX_HASH_SIZE);
+    1273                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    1274                 :            :                                   secured_message_context->hash_size,
+    1275                 :            :                                   secured_message_context->application_secret
+    1276                 :          1 :                                   .request_data_secret,
+    1277                 :            :                                   secured_message_context->application_secret
+    1278                 :          1 :                                   .request_data_secret,
+    1279                 :            :                                   secured_message_context->hash_size);
+    1280                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    1281                 :            :                                   secured_message_context->hash_size,
+    1282                 :            :                                   secured_message_context->application_secret
+    1283                 :          1 :                                   .response_data_secret,
+    1284                 :            :                                   secured_message_context->application_secret
+    1285                 :          1 :                                   .response_data_secret,
+    1286                 :            :                                   secured_message_context->hash_size);
+    1287                 :            : 
+    1288                 :            :     /*request side updated*/
+    1289                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    1290                 :            :                                   secured_message_context->hash_size,
+    1291                 :            :                                   m_req_secret_buffer, m_req_secret_buffer,
+    1292                 :            :                                   secured_message_context->hash_size);
+    1293                 :            :     /*response side updated*/
+    1294                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    1295                 :            :                                   secured_message_context->hash_size,
+    1296                 :            :                                   m_rsp_secret_buffer, m_rsp_secret_buffer,
+    1297                 :            :                                   secured_message_context->hash_size);
+    1298                 :            : 
+    1299                 :          1 :     response_size = sizeof(response);
+    1300                 :          1 :     status = libspdm_get_response_key_update(spdm_context,
+    1301                 :            :                                              m_libspdm_key_update_request6_size,
+    1302                 :            :                                              &m_libspdm_key_update_request6,
+    1303                 :            :                                              &response_size, response);
+    1304                 :            : 
+    1305                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1306                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1307                 :          1 :     spdm_response = (void *)response;
+    1308                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1309                 :            :                      SPDM_ERROR);
+    1310                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1311                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+    1312                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1313                 :          1 :     assert_memory_equal(secured_message_context
+    1314                 :            :                         ->application_secret.request_data_secret,
+    1315                 :            :                         m_req_secret_buffer, secured_message_context->hash_size);
+    1316                 :          1 :     assert_memory_equal(secured_message_context
+    1317                 :            :                         ->application_secret.response_data_secret,
+    1318                 :            :                         m_rsp_secret_buffer, secured_message_context->hash_size);
+    1319                 :          1 : }
+    1320                 :            : 
+    1321                 :            : /**
+    1322                 :            :  * Test 16: receiving a invalid KEY_UPDATE message from the requester with
+    1323                 :            :  * the VerifyNewKey operation. The responder is setup as if no valid
+    1324                 :            :  * KEY_UPDATE request with either the UpdateKey or UpdateAllKeys has been
+    1325                 :            :  * previously received.
+    1326                 :            :  * Expected behavior: the responder refuses the KEY_UPDATE message and
+    1327                 :            :  * produces an ERROR message indicating the InvalidRequest. No keys are
+    1328                 :            :  * updated.
+    1329                 :            :  **/
+    1330                 :          1 : void libspdm_test_responder_key_update_case16(void **state)
+    1331                 :            : {
+    1332                 :            :     libspdm_return_t status;
+    1333                 :            :     libspdm_test_context_t            *spdm_test_context;
+    1334                 :            :     libspdm_context_t                 *spdm_context;
+    1335                 :            :     uint32_t session_id;
+    1336                 :            :     libspdm_session_info_t            *session_info;
+    1337                 :            :     libspdm_secured_message_context_t *secured_message_context;
+    1338                 :            : 
+    1339                 :            :     size_t response_size;
+    1340                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1341                 :            :     spdm_key_update_response_t *spdm_response;
+    1342                 :            : 
+    1343                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    1344                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    1345                 :            : 
+    1346                 :          1 :     spdm_test_context = *state;
+    1347                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1348                 :          1 :     spdm_test_context->case_id = 0x10;
+    1349                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1350                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1351                 :            : 
+    1352                 :          1 :     libspdm_set_standard_key_update_test_state(
+    1353                 :            :         spdm_context, &session_id);
+    1354                 :            : 
+    1355                 :          1 :     session_info = &spdm_context->session_info[0];
+    1356                 :          1 :     secured_message_context = session_info->secured_message_context;
+    1357                 :            : 
+    1358                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    1359                 :          1 :         session_info->secured_message_context,
+    1360                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    1361                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    1362                 :            : 
+    1363                 :            :     /*no mocked major secret update*/
+    1364                 :            : 
+    1365                 :            :     /*no keys are updated*/
+    1366                 :            : 
+    1367                 :          1 :     response_size = sizeof(response);
+    1368                 :          1 :     status = libspdm_get_response_key_update(spdm_context,
+    1369                 :            :                                              m_libspdm_key_update_request5_size,
+    1370                 :            :                                              &m_libspdm_key_update_request5,
+    1371                 :            :                                              &response_size, response);
+    1372                 :            : 
+    1373                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1374                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1375                 :          1 :     spdm_response = (void *)response;
+    1376                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1377                 :            :                      SPDM_ERROR);
+    1378                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1379                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+    1380                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1381                 :          1 :     assert_memory_equal(secured_message_context
+    1382                 :            :                         ->application_secret.request_data_secret,
+    1383                 :            :                         m_req_secret_buffer, secured_message_context->hash_size);
+    1384                 :          1 :     assert_memory_equal(secured_message_context
+    1385                 :            :                         ->application_secret.response_data_secret,
+    1386                 :            :                         m_rsp_secret_buffer, secured_message_context->hash_size);
+    1387                 :          1 : }
+    1388                 :            : 
+    1389                 :            : /**
+    1390                 :            :  * Test 17: UpdateKey + UpdateKey, last key operation is update key, current key operation is update key
+    1391                 :            :  * Expected behavior: the responder refuses the KEY_UPDATE message and
+    1392                 :            :  * produces an ERROR message indicating the InvalidRequest. No keys are
+    1393                 :            :  * updated.
+    1394                 :            :  **/
+    1395                 :          1 : void libspdm_test_responder_key_update_case17(void **state)
+    1396                 :            : {
+    1397                 :            :     libspdm_return_t status;
+    1398                 :            :     libspdm_test_context_t            *spdm_test_context;
+    1399                 :            :     libspdm_context_t                 *spdm_context;
+    1400                 :            :     uint32_t session_id;
+    1401                 :            :     libspdm_session_info_t            *session_info;
+    1402                 :            :     libspdm_secured_message_context_t *secured_message_context;
+    1403                 :            : 
+    1404                 :            :     size_t response_size;
+    1405                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1406                 :            :     spdm_key_update_response_t *spdm_response;
+    1407                 :            : 
+    1408                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    1409                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    1410                 :            : 
+    1411                 :          1 :     spdm_test_context = *state;
+    1412                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1413                 :          1 :     spdm_test_context->case_id = 0x11;
+    1414                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1415                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1416                 :            : 
+    1417                 :          1 :     libspdm_set_standard_key_update_test_state(
+    1418                 :            :         spdm_context, &session_id);
+    1419                 :            : 
+    1420                 :          1 :     session_info = &spdm_context->session_info[0];
+    1421                 :          1 :     secured_message_context = session_info->secured_message_context;
+    1422                 :            : 
+    1423                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    1424                 :          1 :         session_info->secured_message_context,
+    1425                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    1426                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    1427                 :            : 
+    1428                 :            :     /*last request: UpdateKey*/
+    1429                 :          1 :     session_info->last_key_update_request = m_libspdm_key_update_request1;
+    1430                 :            : 
+    1431                 :            :     /*mocked major secret update*/
+    1432                 :          1 :     libspdm_copy_mem(&secured_message_context->application_secret_backup.request_data_secret,
+    1433                 :            :                      sizeof(secured_message_context->application_secret_backup.request_data_secret),
+    1434                 :          1 :                      &secured_message_context->application_secret.request_data_secret,
+    1435                 :            :                      LIBSPDM_MAX_HASH_SIZE);
+    1436                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    1437                 :            :                                   secured_message_context->hash_size,
+    1438                 :            :                                   secured_message_context->application_secret
+    1439                 :          1 :                                   .request_data_secret,
+    1440                 :            :                                   secured_message_context->application_secret
+    1441                 :          1 :                                   .request_data_secret,
+    1442                 :            :                                   secured_message_context->hash_size);
+    1443                 :            : 
+    1444                 :            :     /*request side updated (once)*/
+    1445                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    1446                 :            :                                   secured_message_context->hash_size,
+    1447                 :            :                                   m_req_secret_buffer, m_req_secret_buffer,
+    1448                 :            :                                   secured_message_context->hash_size);
+    1449                 :            :     /*response side *not* updated*/
+    1450                 :            : 
+    1451                 :          1 :     response_size = sizeof(response);
+    1452                 :          1 :     status = libspdm_get_response_key_update(spdm_context,
+    1453                 :            :                                              m_libspdm_key_update_request1_size,
+    1454                 :            :                                              &m_libspdm_key_update_request1,
+    1455                 :            :                                              &response_size, response);
+    1456                 :            : 
+    1457                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1458                 :          1 :     assert_int_equal(response_size, sizeof(spdm_key_update_response_t));
+    1459                 :          1 :     spdm_response = (void *)response;
+    1460                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1461                 :            :                      SPDM_ERROR);
+    1462                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1463                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+    1464                 :          1 : }
+    1465                 :            : 
+    1466                 :            : /**
+    1467                 :            :  * Test 18: UpdateKey + UpdateAllKeys, last key operation is update key, current key operation is update all key
+    1468                 :            :  * Expected behavior: the responder refuses the KEY_UPDATE message and
+    1469                 :            :  * produces an ERROR message indicating the InvalidRequest. No keys are
+    1470                 :            :  * updated.
+    1471                 :            :  **/
+    1472                 :          1 : void libspdm_test_responder_key_update_case18(void **state)
+    1473                 :            : {
+    1474                 :            :     libspdm_return_t status;
+    1475                 :            :     libspdm_test_context_t            *spdm_test_context;
+    1476                 :            :     libspdm_context_t                 *spdm_context;
+    1477                 :            :     uint32_t session_id;
+    1478                 :            :     libspdm_session_info_t            *session_info;
+    1479                 :            :     libspdm_secured_message_context_t *secured_message_context;
+    1480                 :            : 
+    1481                 :            :     size_t response_size;
+    1482                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1483                 :            :     spdm_key_update_response_t *spdm_response;
+    1484                 :            : 
+    1485                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    1486                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    1487                 :            : 
+    1488                 :          1 :     spdm_test_context = *state;
+    1489                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1490                 :          1 :     spdm_test_context->case_id = 0x12;
+    1491                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1492                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1493                 :            : 
+    1494                 :          1 :     libspdm_set_standard_key_update_test_state(
+    1495                 :            :         spdm_context, &session_id);
+    1496                 :            : 
+    1497                 :          1 :     session_info = &spdm_context->session_info[0];
+    1498                 :          1 :     secured_message_context = session_info->secured_message_context;
+    1499                 :            : 
+    1500                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    1501                 :          1 :         session_info->secured_message_context,
+    1502                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    1503                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    1504                 :            : 
+    1505                 :            :     /*last request: UpdateKey*/
+    1506                 :          1 :     session_info->last_key_update_request = m_libspdm_key_update_request1;
+    1507                 :            : 
+    1508                 :            :     /*mocked major secret update*/
+    1509                 :          1 :     libspdm_copy_mem(&secured_message_context->application_secret_backup.request_data_secret,
+    1510                 :            :                      sizeof(secured_message_context->application_secret_backup.request_data_secret),
+    1511                 :          1 :                      &secured_message_context->application_secret.request_data_secret,
+    1512                 :            :                      LIBSPDM_MAX_HASH_SIZE);
+    1513                 :          1 :     libspdm_copy_mem(&secured_message_context->application_secret_backup.response_data_secret,
+    1514                 :            :                      sizeof(secured_message_context->application_secret_backup.response_data_secret),
+    1515                 :          1 :                      &secured_message_context->application_secret.response_data_secret,
+    1516                 :            :                      LIBSPDM_MAX_HASH_SIZE);
+    1517                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    1518                 :            :                                   secured_message_context->hash_size,
+    1519                 :            :                                   secured_message_context->application_secret
+    1520                 :          1 :                                   .request_data_secret,
+    1521                 :            :                                   secured_message_context->application_secret
+    1522                 :          1 :                                   .request_data_secret,
+    1523                 :            :                                   secured_message_context->hash_size);
+    1524                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    1525                 :            :                                   secured_message_context->hash_size,
+    1526                 :            :                                   secured_message_context->application_secret
+    1527                 :          1 :                                   .response_data_secret,
+    1528                 :            :                                   secured_message_context->application_secret
+    1529                 :          1 :                                   .response_data_secret,
+    1530                 :            :                                   secured_message_context->hash_size);
+    1531                 :            : 
+    1532                 :            :     /*request side updated (once)*/
+    1533                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    1534                 :            :                                   secured_message_context->hash_size,
+    1535                 :            :                                   m_req_secret_buffer, m_req_secret_buffer,
+    1536                 :            :                                   secured_message_context->hash_size);
+    1537                 :            :     /*response side updated (once)*/
+    1538                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    1539                 :            :                                   secured_message_context->hash_size,
+    1540                 :            :                                   m_rsp_secret_buffer, m_rsp_secret_buffer,
+    1541                 :            :                                   secured_message_context->hash_size);
+    1542                 :            : 
+    1543                 :          1 :     response_size = sizeof(response);
+    1544                 :            :     /*UpdateAllKeys*/
+    1545                 :          1 :     status = libspdm_get_response_key_update(spdm_context,
+    1546                 :            :                                              m_libspdm_key_update_request3_size,
+    1547                 :            :                                              &m_libspdm_key_update_request3,
+    1548                 :            :                                              &response_size, response);
+    1549                 :            : 
+    1550                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1551                 :          1 :     assert_int_equal(response_size, sizeof(spdm_key_update_response_t));
+    1552                 :          1 :     spdm_response = (void *)response;
+    1553                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1554                 :            :                      SPDM_ERROR);
+    1555                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1556                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+    1557                 :          1 : }
+    1558                 :            : 
+    1559                 :            : /**
+    1560                 :            :  * Test 19:UpdateAllKeys + UpdateKey, last key operation is update all key, current key operation is update key
+    1561                 :            :  * Expected behavior: the responder refuses the KEY_UPDATE message and
+    1562                 :            :  * produces an ERROR message indicating the InvalidRequest. No keys are
+    1563                 :            :  * updated.
+    1564                 :            :  **/
+    1565                 :          1 : void libspdm_test_responder_key_update_case19(void **state)
+    1566                 :            : {
+    1567                 :            :     libspdm_return_t status;
+    1568                 :            :     libspdm_test_context_t            *spdm_test_context;
+    1569                 :            :     libspdm_context_t                 *spdm_context;
+    1570                 :            :     uint32_t session_id;
+    1571                 :            :     libspdm_session_info_t            *session_info;
+    1572                 :            : 
+    1573                 :            :     size_t response_size;
+    1574                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1575                 :            :     spdm_key_update_response_t *spdm_response;
+    1576                 :            : 
+    1577                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    1578                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    1579                 :            : 
+    1580                 :          1 :     spdm_test_context = *state;
+    1581                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1582                 :          1 :     spdm_test_context->case_id = 0x13;
+    1583                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1584                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1585                 :            : 
+    1586                 :          1 :     libspdm_set_standard_key_update_test_state(
+    1587                 :            :         spdm_context, &session_id);
+    1588                 :            : 
+    1589                 :          1 :     session_info = &spdm_context->session_info[0];
+    1590                 :            : 
+    1591                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    1592                 :          1 :         session_info->secured_message_context,
+    1593                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    1594                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    1595                 :            : 
+    1596                 :            :     /*last request: UpdateAllKeys*/
+    1597                 :          1 :     session_info->last_key_update_request = m_libspdm_key_update_request3;
+    1598                 :            : 
+    1599                 :            :     /*UpdateKey*/
+    1600                 :          1 :     response_size = sizeof(response);
+    1601                 :          1 :     status = libspdm_get_response_key_update(spdm_context,
+    1602                 :            :                                              m_libspdm_key_update_request1_size,
+    1603                 :            :                                              &m_libspdm_key_update_request1,
+    1604                 :            :                                              &response_size, response);
+    1605                 :            : 
+    1606                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1607                 :          1 :     assert_int_equal(response_size, sizeof(spdm_key_update_response_t));
+    1608                 :          1 :     spdm_response = (void *)response;
+    1609                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1610                 :            :                      SPDM_ERROR);
+    1611                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1612                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+    1613                 :          1 : }
+    1614                 :            : 
+    1615                 :            : /**
+    1616                 :            :  * Test 20:UpdateAllKeys + UpdateALlKeys, last key operation is update all key, current key operation is update all key
+    1617                 :            :  * Expected behavior: the responder refuses the KEY_UPDATE message and
+    1618                 :            :  * produces an ERROR message indicating the InvalidRequest. No keys are
+    1619                 :            :  * updated.
+    1620                 :            :  **/
+    1621                 :          1 : void libspdm_test_responder_key_update_case20(void **state)
+    1622                 :            : {
+    1623                 :            :     libspdm_return_t status;
+    1624                 :            :     libspdm_test_context_t            *spdm_test_context;
+    1625                 :            :     libspdm_context_t                 *spdm_context;
+    1626                 :            :     uint32_t session_id;
+    1627                 :            :     libspdm_session_info_t            *session_info;
+    1628                 :            : 
+    1629                 :            :     size_t response_size;
+    1630                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1631                 :            :     spdm_key_update_response_t *spdm_response;
+    1632                 :            : 
+    1633                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    1634                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    1635                 :            : 
+    1636                 :          1 :     spdm_test_context = *state;
+    1637                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1638                 :          1 :     spdm_test_context->case_id = 0x14;
+    1639                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1640                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1641                 :            : 
+    1642                 :          1 :     libspdm_set_standard_key_update_test_state(
+    1643                 :            :         spdm_context, &session_id);
+    1644                 :            : 
+    1645                 :          1 :     session_info = &spdm_context->session_info[0];
+    1646                 :            : 
+    1647                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    1648                 :          1 :         session_info->secured_message_context,
+    1649                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    1650                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    1651                 :            : 
+    1652                 :            :     /*last request: UpdateAllKeys*/
+    1653                 :          1 :     session_info->last_key_update_request = m_libspdm_key_update_request3;
+    1654                 :            : 
+    1655                 :            :     /*UpdateAllKeys*/
+    1656                 :          1 :     response_size = sizeof(response);
+    1657                 :          1 :     status = libspdm_get_response_key_update(spdm_context,
+    1658                 :            :                                              m_libspdm_key_update_request3_size,
+    1659                 :            :                                              &m_libspdm_key_update_request3,
+    1660                 :            :                                              &response_size, response);
+    1661                 :            : 
+    1662                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1663                 :          1 :     assert_int_equal(response_size, sizeof(spdm_key_update_response_t));
+    1664                 :          1 :     spdm_response = (void *)response;
+    1665                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1666                 :            :                      SPDM_ERROR);
+    1667                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1668                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+    1669                 :          1 : }
+    1670                 :            : 
+    1671                 :            : /**
+    1672                 :            :  * Test 21: :VerifyNewKey + UpdateKey, last key operation is verify key, current key operation is update key
+    1673                 :            :  * Expected behavior: the responder accepts the request, produces a valid
+    1674                 :            :  * KEY_UPDATE_ACK response message, and the request data key is updated.
+    1675                 :            :  **/
+    1676                 :          1 : void libspdm_test_responder_key_update_case21(void **state)
+    1677                 :            : {
+    1678                 :            :     libspdm_return_t status;
+    1679                 :            :     libspdm_test_context_t            *spdm_test_context;
+    1680                 :            :     libspdm_context_t                 *spdm_context;
+    1681                 :            :     uint32_t session_id;
+    1682                 :            :     libspdm_session_info_t            *session_info;
+    1683                 :            :     libspdm_secured_message_context_t *secured_message_context;
+    1684                 :            : 
+    1685                 :            :     size_t response_size;
+    1686                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1687                 :            :     spdm_key_update_response_t *spdm_response;
+    1688                 :            : 
+    1689                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    1690                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    1691                 :            : 
+    1692                 :          1 :     spdm_test_context = *state;
+    1693                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1694                 :          1 :     spdm_test_context->case_id = 0x15;
+    1695                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1696                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1697                 :            : 
+    1698                 :          1 :     libspdm_set_standard_key_update_test_state(
+    1699                 :            :         spdm_context, &session_id);
+    1700                 :            : 
+    1701                 :          1 :     session_info = &spdm_context->session_info[0];
+    1702                 :          1 :     secured_message_context = session_info->secured_message_context;
+    1703                 :            : 
+    1704                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    1705                 :          1 :         session_info->secured_message_context,
+    1706                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    1707                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    1708                 :            : 
+    1709                 :            :     /*request side updated*/
+    1710                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    1711                 :            :                                   secured_message_context->hash_size,
+    1712                 :            :                                   m_req_secret_buffer, m_req_secret_buffer,
+    1713                 :            :                                   secured_message_context->hash_size);
+    1714                 :            :     /*response side *not* updated*/
+    1715                 :            : 
+    1716                 :            :     /*last request: verify new key*/
+    1717                 :          1 :     session_info->last_key_update_request = m_libspdm_key_update_request5;
+    1718                 :            :     /*verify new key clear last_key_update_request*/
+    1719                 :          1 :     libspdm_zero_mem (&(session_info->last_key_update_request), sizeof(spdm_key_update_request_t));
+    1720                 :            : 
+    1721                 :            :     /*updatekey*/
+    1722                 :          1 :     response_size = sizeof(response);
+    1723                 :          1 :     status = libspdm_get_response_key_update(spdm_context,
+    1724                 :            :                                              m_libspdm_key_update_request1_size,
+    1725                 :            :                                              &m_libspdm_key_update_request1,
+    1726                 :            :                                              &response_size, response);
+    1727                 :            : 
+    1728                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1729                 :          1 :     assert_int_equal(response_size, sizeof(spdm_key_update_response_t));
+    1730                 :          1 :     spdm_response = (void *)response;
+    1731                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1732                 :            :                      SPDM_KEY_UPDATE_ACK);
+    1733                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1734                 :            :                      SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY);
+    1735                 :          1 :     assert_int_equal(spdm_response->header.param2,
+    1736                 :            :                      m_libspdm_key_update_request1.header.param2);
+    1737                 :          1 :     assert_memory_equal(secured_message_context
+    1738                 :            :                         ->application_secret.request_data_secret,
+    1739                 :            :                         m_req_secret_buffer, secured_message_context->hash_size);
+    1740                 :          1 :     assert_memory_equal(secured_message_context
+    1741                 :            :                         ->application_secret.response_data_secret,
+    1742                 :            :                         m_rsp_secret_buffer, secured_message_context->hash_size);
+    1743                 :          1 : }
+    1744                 :            : 
+    1745                 :            : /**
+    1746                 :            :  * Test 22: :VerifyNewKey + UpdateAllKeys, last key operation is verify key, current key operation is update all key
+    1747                 :            :  * Expected behavior: the responder accepts the request, produces a valid
+    1748                 :            :  * KEY_UPDATE_ACK response message, and the request data key is updated.
+    1749                 :            :  **/
+    1750                 :          1 : void libspdm_test_responder_key_update_case22(void **state)
+    1751                 :            : {
+    1752                 :            :     libspdm_return_t status;
+    1753                 :            :     libspdm_test_context_t            *spdm_test_context;
+    1754                 :            :     libspdm_context_t                 *spdm_context;
+    1755                 :            :     uint32_t session_id;
+    1756                 :            :     libspdm_session_info_t            *session_info;
+    1757                 :            :     libspdm_secured_message_context_t *secured_message_context;
+    1758                 :            : 
+    1759                 :            :     size_t response_size;
+    1760                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1761                 :            :     spdm_key_update_response_t *spdm_response;
+    1762                 :            : 
+    1763                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    1764                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    1765                 :            : 
+    1766                 :          1 :     spdm_test_context = *state;
+    1767                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1768                 :          1 :     spdm_test_context->case_id = 0x16;
+    1769                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1770                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1771                 :            : 
+    1772                 :          1 :     libspdm_set_standard_key_update_test_state(
+    1773                 :            :         spdm_context, &session_id);
+    1774                 :            : 
+    1775                 :          1 :     session_info = &spdm_context->session_info[0];
+    1776                 :          1 :     secured_message_context = session_info->secured_message_context;
+    1777                 :            : 
+    1778                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    1779                 :          1 :         session_info->secured_message_context,
+    1780                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    1781                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    1782                 :            : 
+    1783                 :            :     /*request side updated*/
+    1784                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    1785                 :            :                                   secured_message_context->hash_size,
+    1786                 :            :                                   m_req_secret_buffer, m_req_secret_buffer,
+    1787                 :            :                                   secured_message_context->hash_size);
+    1788                 :            :     /*response side updated*/
+    1789                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    1790                 :            :                                   secured_message_context->hash_size,
+    1791                 :            :                                   m_rsp_secret_buffer, m_rsp_secret_buffer,
+    1792                 :            :                                   secured_message_context->hash_size);
+    1793                 :            : 
+    1794                 :            :     /*last request: verify new key*/
+    1795                 :          1 :     session_info->last_key_update_request = m_libspdm_key_update_request5;
+    1796                 :            :     /*clear last_key_update_request*/
+    1797                 :          1 :     libspdm_zero_mem (&(session_info->last_key_update_request), sizeof(spdm_key_update_request_t));
+    1798                 :            : 
+    1799                 :          1 :     response_size = sizeof(response);
+    1800                 :          1 :     status = libspdm_get_response_key_update(spdm_context,
+    1801                 :            :                                              m_libspdm_key_update_request3_size,
+    1802                 :            :                                              &m_libspdm_key_update_request3,
+    1803                 :            :                                              &response_size, response);
+    1804                 :            : 
+    1805                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1806                 :          1 :     assert_int_equal(response_size, sizeof(spdm_key_update_response_t));
+    1807                 :          1 :     spdm_response = (void *)response;
+    1808                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1809                 :            :                      SPDM_KEY_UPDATE_ACK);
+    1810                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1811                 :            :                      SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_ALL_KEYS);
+    1812                 :          1 :     assert_int_equal(spdm_response->header.param2,
+    1813                 :            :                      m_libspdm_key_update_request3.header.param2);
+    1814                 :          1 :     assert_memory_equal(secured_message_context
+    1815                 :            :                         ->application_secret.request_data_secret,
+    1816                 :            :                         m_req_secret_buffer, secured_message_context->hash_size);
+    1817                 :          1 :     assert_memory_equal(secured_message_context
+    1818                 :            :                         ->application_secret.response_data_secret,
+    1819                 :            :                         m_rsp_secret_buffer, secured_message_context->hash_size);
+    1820                 :          1 : }
+    1821                 :            : 
+    1822                 :            : /**
+    1823                 :            :  * Test 23: VerifyNewKey + VerifyNewKey, last key operation is verify key, current key operation is verify key
+    1824                 :            :  * Expected behavior: the responder refuses the KEY_UPDATE message and
+    1825                 :            :  * produces an ERROR message indicating the InvalidRequest. No keys are
+    1826                 :            :  * updated.
+    1827                 :            :  **/
+    1828                 :          1 : void libspdm_test_responder_key_update_case23(void **state)
+    1829                 :            : {
+    1830                 :            :     libspdm_return_t status;
+    1831                 :            :     libspdm_test_context_t            *spdm_test_context;
+    1832                 :            :     libspdm_context_t                 *spdm_context;
+    1833                 :            :     uint32_t session_id;
+    1834                 :            :     libspdm_session_info_t            *session_info;
+    1835                 :            : 
+    1836                 :            :     size_t response_size;
+    1837                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1838                 :            :     spdm_key_update_response_t *spdm_response;
+    1839                 :            : 
+    1840                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    1841                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    1842                 :            : 
+    1843                 :          1 :     spdm_test_context = *state;
+    1844                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1845                 :          1 :     spdm_test_context->case_id = 0x17;
+    1846                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1847                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1848                 :            : 
+    1849                 :          1 :     libspdm_set_standard_key_update_test_state(
+    1850                 :            :         spdm_context, &session_id);
+    1851                 :            : 
+    1852                 :          1 :     session_info = &spdm_context->session_info[0];
+    1853                 :            : 
+    1854                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    1855                 :          1 :         session_info->secured_message_context,
+    1856                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    1857                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    1858                 :            : 
+    1859                 :            :     /*last request: VerifyNewKey*/
+    1860                 :          1 :     session_info->last_key_update_request = m_libspdm_key_update_request5;
+    1861                 :            :     /*clear last_key_update_request*/
+    1862                 :          1 :     libspdm_zero_mem (&(session_info->last_key_update_request), sizeof(spdm_key_update_request_t));
+    1863                 :            : 
+    1864                 :            :     /*VerifyNewKey*/
+    1865                 :          1 :     response_size = sizeof(response);
+    1866                 :          1 :     status = libspdm_get_response_key_update(spdm_context,
+    1867                 :            :                                              m_libspdm_key_update_request5_size,
+    1868                 :            :                                              &m_libspdm_key_update_request5,
+    1869                 :            :                                              &response_size, response);
+    1870                 :            : 
+    1871                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1872                 :          1 :     assert_int_equal(response_size, sizeof(spdm_key_update_response_t));
+    1873                 :          1 :     spdm_response = (void *)response;
+    1874                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1875                 :            :                      SPDM_ERROR);
+    1876                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1877                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+    1878                 :          1 : }
+    1879                 :            : 
+    1880                 :            : /**
+    1881                 :            :  * Test 24: :other command + UpdateKey, last requeset is not key_update command, current key operation is update key
+    1882                 :            :  * Expected behavior: the responder accepts the request, produces a valid
+    1883                 :            :  * KEY_UPDATE_ACK response message, and the request data key is updated.
+    1884                 :            :  **/
+    1885                 :          1 : void libspdm_test_responder_key_update_case24(void **state)
+    1886                 :            : {
+    1887                 :            :     libspdm_return_t status;
+    1888                 :            :     libspdm_test_context_t            *spdm_test_context;
+    1889                 :            :     libspdm_context_t                 *spdm_context;
+    1890                 :            :     uint32_t session_id;
+    1891                 :            :     libspdm_session_info_t            *session_info;
+    1892                 :            :     libspdm_secured_message_context_t *secured_message_context;
+    1893                 :            : 
+    1894                 :            :     size_t response_size;
+    1895                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1896                 :            :     spdm_key_update_response_t *spdm_response;
+    1897                 :            : 
+    1898                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    1899                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    1900                 :            : 
+    1901                 :          1 :     spdm_test_context = *state;
+    1902                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1903                 :          1 :     spdm_test_context->case_id = 0x18;
+    1904                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1905                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1906                 :            : 
+    1907                 :          1 :     libspdm_set_standard_key_update_test_state(
+    1908                 :            :         spdm_context, &session_id);
+    1909                 :            : 
+    1910                 :          1 :     session_info = &spdm_context->session_info[0];
+    1911                 :          1 :     secured_message_context = session_info->secured_message_context;
+    1912                 :            : 
+    1913                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    1914                 :          1 :         session_info->secured_message_context,
+    1915                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    1916                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    1917                 :            : 
+    1918                 :            :     /*request side updated*/
+    1919                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    1920                 :            :                                   secured_message_context->hash_size,
+    1921                 :            :                                   m_req_secret_buffer, m_req_secret_buffer,
+    1922                 :            :                                   secured_message_context->hash_size);
+    1923                 :            :     /*response side *not* updated*/
+    1924                 :            : 
+    1925                 :            :     /*ohter command with cleared last_key_update_request*/
+    1926                 :          1 :     libspdm_zero_mem (&(session_info->last_key_update_request), sizeof(spdm_key_update_request_t));
+    1927                 :            : 
+    1928                 :            :     /*updatekey*/
+    1929                 :          1 :     response_size = sizeof(response);
+    1930                 :          1 :     status = libspdm_get_response_key_update(spdm_context,
+    1931                 :            :                                              m_libspdm_key_update_request1_size,
+    1932                 :            :                                              &m_libspdm_key_update_request1,
+    1933                 :            :                                              &response_size, response);
+    1934                 :            : 
+    1935                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1936                 :          1 :     assert_int_equal(response_size, sizeof(spdm_key_update_response_t));
+    1937                 :          1 :     spdm_response = (void *)response;
+    1938                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1939                 :            :                      SPDM_KEY_UPDATE_ACK);
+    1940                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1941                 :            :                      SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY);
+    1942                 :          1 :     assert_int_equal(spdm_response->header.param2,
+    1943                 :            :                      m_libspdm_key_update_request1.header.param2);
+    1944                 :          1 :     assert_memory_equal(secured_message_context
+    1945                 :            :                         ->application_secret.request_data_secret,
+    1946                 :            :                         m_req_secret_buffer, secured_message_context->hash_size);
+    1947                 :          1 :     assert_memory_equal(secured_message_context
+    1948                 :            :                         ->application_secret.response_data_secret,
+    1949                 :            :                         m_rsp_secret_buffer, secured_message_context->hash_size);
+    1950                 :          1 : }
+    1951                 :            : 
+    1952                 :            : /**
+    1953                 :            :  * Test 25: :other command + UpdateAllKeys, last requeset is not key_update command, current key operation is update all key
+    1954                 :            :  * Expected behavior: the responder accepts the request, produces a valid
+    1955                 :            :  * KEY_UPDATE_ACK response message, and the request data key is updated.
+    1956                 :            :  **/
+    1957                 :          1 : void libspdm_test_responder_key_update_case25(void **state)
+    1958                 :            : {
+    1959                 :            :     libspdm_return_t status;
+    1960                 :            :     libspdm_test_context_t            *spdm_test_context;
+    1961                 :            :     libspdm_context_t                 *spdm_context;
+    1962                 :            :     uint32_t session_id;
+    1963                 :            :     libspdm_session_info_t            *session_info;
+    1964                 :            :     libspdm_secured_message_context_t *secured_message_context;
+    1965                 :            : 
+    1966                 :            :     size_t response_size;
+    1967                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1968                 :            :     spdm_key_update_response_t *spdm_response;
+    1969                 :            : 
+    1970                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    1971                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    1972                 :            : 
+    1973                 :          1 :     spdm_test_context = *state;
+    1974                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1975                 :          1 :     spdm_test_context->case_id = 0x19;
+    1976                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1977                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1978                 :            : 
+    1979                 :          1 :     libspdm_set_standard_key_update_test_state(
+    1980                 :            :         spdm_context, &session_id);
+    1981                 :            : 
+    1982                 :          1 :     session_info = &spdm_context->session_info[0];
+    1983                 :          1 :     secured_message_context = session_info->secured_message_context;
+    1984                 :            : 
+    1985                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    1986                 :          1 :         session_info->secured_message_context,
+    1987                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    1988                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    1989                 :            : 
+    1990                 :            :     /*request side updated*/
+    1991                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    1992                 :            :                                   secured_message_context->hash_size,
+    1993                 :            :                                   m_req_secret_buffer, m_req_secret_buffer,
+    1994                 :            :                                   secured_message_context->hash_size);
+    1995                 :            :     /*response side updated*/
+    1996                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    1997                 :            :                                   secured_message_context->hash_size,
+    1998                 :            :                                   m_rsp_secret_buffer, m_rsp_secret_buffer,
+    1999                 :            :                                   secured_message_context->hash_size);
+    2000                 :            : 
+    2001                 :            :     /*ohter command with cleared last_key_update_request*/
+    2002                 :          1 :     libspdm_zero_mem (&(session_info->last_key_update_request), sizeof(spdm_key_update_request_t));
+    2003                 :            : 
+    2004                 :          1 :     response_size = sizeof(response);
+    2005                 :          1 :     status = libspdm_get_response_key_update(spdm_context,
+    2006                 :            :                                              m_libspdm_key_update_request3_size,
+    2007                 :            :                                              &m_libspdm_key_update_request3,
+    2008                 :            :                                              &response_size, response);
+    2009                 :            : 
+    2010                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2011                 :          1 :     assert_int_equal(response_size, sizeof(spdm_key_update_response_t));
+    2012                 :          1 :     spdm_response = (void *)response;
+    2013                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    2014                 :            :                      SPDM_KEY_UPDATE_ACK);
+    2015                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    2016                 :            :                      SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_ALL_KEYS);
+    2017                 :          1 :     assert_int_equal(spdm_response->header.param2,
+    2018                 :            :                      m_libspdm_key_update_request3.header.param2);
+    2019                 :          1 :     assert_memory_equal(secured_message_context
+    2020                 :            :                         ->application_secret.request_data_secret,
+    2021                 :            :                         m_req_secret_buffer, secured_message_context->hash_size);
+    2022                 :          1 :     assert_memory_equal(secured_message_context
+    2023                 :            :                         ->application_secret.response_data_secret,
+    2024                 :            :                         m_rsp_secret_buffer, secured_message_context->hash_size);
+    2025                 :          1 : }
+    2026                 :            : 
+    2027                 :            : /**
+    2028                 :            :  * Test 26: :other command + VerifyNewKey, last requeset is not key_update command, current key operation is verify key
+    2029                 :            :  * Expected behavior: the responder refuses the KEY_UPDATE message and
+    2030                 :            :  * produces an ERROR message indicating the InvalidRequest. No keys are
+    2031                 :            :  * updated.
+    2032                 :            :  **/
+    2033                 :          1 : void libspdm_test_responder_key_update_case26(void **state)
+    2034                 :            : {
+    2035                 :            :     libspdm_return_t status;
+    2036                 :            :     libspdm_test_context_t            *spdm_test_context;
+    2037                 :            :     libspdm_context_t                 *spdm_context;
+    2038                 :            :     uint32_t session_id;
+    2039                 :            :     libspdm_session_info_t            *session_info;
+    2040                 :            :     libspdm_secured_message_context_t *secured_message_context;
+    2041                 :            : 
+    2042                 :            :     size_t response_size;
+    2043                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    2044                 :            :     spdm_key_update_response_t *spdm_response;
+    2045                 :            : 
+    2046                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    2047                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    2048                 :            : 
+    2049                 :          1 :     spdm_test_context = *state;
+    2050                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2051                 :          1 :     spdm_test_context->case_id = 0x1A;
+    2052                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    2053                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2054                 :            : 
+    2055                 :          1 :     libspdm_set_standard_key_update_test_state(
+    2056                 :            :         spdm_context, &session_id);
+    2057                 :            : 
+    2058                 :          1 :     session_info = &spdm_context->session_info[0];
+    2059                 :          1 :     secured_message_context = session_info->secured_message_context;
+    2060                 :            : 
+    2061                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    2062                 :          1 :         session_info->secured_message_context,
+    2063                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    2064                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    2065                 :            : 
+    2066                 :            :     /*request side updated*/
+    2067                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    2068                 :            :                                   secured_message_context->hash_size,
+    2069                 :            :                                   m_req_secret_buffer, m_req_secret_buffer,
+    2070                 :            :                                   secured_message_context->hash_size);
+    2071                 :            :     /*response side updated*/
+    2072                 :          1 :     libspdm_compute_secret_update(spdm_context->connection_info.version,
+    2073                 :            :                                   secured_message_context->hash_size,
+    2074                 :            :                                   m_rsp_secret_buffer, m_rsp_secret_buffer,
+    2075                 :            :                                   secured_message_context->hash_size);
+    2076                 :            : 
+    2077                 :            :     /*ohter command with cleared last_key_update_request*/
+    2078                 :          1 :     libspdm_zero_mem (&(session_info->last_key_update_request), sizeof(spdm_key_update_request_t));
+    2079                 :            : 
+    2080                 :            :     /*VerifyNewKey*/
+    2081                 :          1 :     response_size = sizeof(response);
+    2082                 :          1 :     status = libspdm_get_response_key_update(spdm_context,
+    2083                 :            :                                              m_libspdm_key_update_request5_size,
+    2084                 :            :                                              &m_libspdm_key_update_request5,
+    2085                 :            :                                              &response_size, response);
+    2086                 :            : 
+    2087                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2088                 :          1 :     assert_int_equal(response_size, sizeof(spdm_key_update_response_t));
+    2089                 :          1 :     spdm_response = (void *)response;
+    2090                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    2091                 :            :                      SPDM_ERROR);
+    2092                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    2093                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+    2094                 :          1 : }
+    2095                 :            : 
+    2096                 :            : /**
+    2097                 :            :  * Test 27: receiving a KEY_UPDATE message with a reserved operation code.
+    2098                 :            :  * Expected behavior: the responder refuses the KEY_UPDATE message and
+    2099                 :            :  * produces an ERROR message indicating the InvalidRequest. No keys
+    2100                 :            :  * are updated.
+    2101                 :            :  **/
+    2102                 :          1 : void libspdm_test_responder_key_update_case27(void **state)
+    2103                 :            : {
+    2104                 :            :     libspdm_return_t status;
+    2105                 :            :     libspdm_test_context_t            *spdm_test_context;
+    2106                 :            :     libspdm_context_t                 *spdm_context;
+    2107                 :            :     uint32_t session_id;
+    2108                 :            :     libspdm_session_info_t            *session_info;
+    2109                 :            :     libspdm_secured_message_context_t *secured_message_context;
+    2110                 :            : 
+    2111                 :            :     size_t response_size;
+    2112                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    2113                 :            :     spdm_key_update_response_t *spdm_response;
+    2114                 :            : 
+    2115                 :            :     uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    2116                 :            :     uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
+    2117                 :            : 
+    2118                 :          1 :     spdm_test_context = *state;
+    2119                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2120                 :          1 :     spdm_test_context->case_id = 0x1B;
+    2121                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    2122                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2123                 :            : 
+    2124                 :          1 :     libspdm_set_standard_key_update_test_state(
+    2125                 :            :         spdm_context, &session_id);
+    2126                 :            : 
+    2127                 :          1 :     session_info = &spdm_context->session_info[0];
+    2128                 :          1 :     secured_message_context = session_info->secured_message_context;
+    2129                 :            : 
+    2130                 :          1 :     libspdm_set_standard_key_update_test_secrets(
+    2131                 :          1 :         session_info->secured_message_context,
+    2132                 :            :         m_rsp_secret_buffer, (uint8_t)(0xFF),
+    2133                 :            :         m_req_secret_buffer, (uint8_t)(0xEE));
+    2134                 :            : 
+    2135                 :            :     /*no keys are updated*/
+    2136                 :            : 
+    2137                 :          1 :     response_size = sizeof(response);
+    2138                 :          1 :     status = libspdm_get_response_key_update(spdm_context,
+    2139                 :            :                                              m_libspdm_key_update_request10_size,
+    2140                 :            :                                              &m_libspdm_key_update_request10,
+    2141                 :            :                                              &response_size, response);
+    2142                 :            : 
+    2143                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2144                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    2145                 :          1 :     spdm_response = (void *)response;
+    2146                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    2147                 :            :                      SPDM_ERROR);
+    2148                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    2149                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+    2150                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    2151                 :          1 :     assert_memory_equal(secured_message_context
+    2152                 :            :                         ->application_secret.request_data_secret,
+    2153                 :            :                         m_req_secret_buffer, secured_message_context->hash_size);
+    2154                 :          1 :     assert_memory_equal(secured_message_context
+    2155                 :            :                         ->application_secret.response_data_secret,
+    2156                 :            :                         m_rsp_secret_buffer, secured_message_context->hash_size);
+    2157                 :          1 : }
+    2158                 :            : 
+    2159                 :            : libspdm_test_context_t m_libspdm_responder_key_update_test_context = {
+    2160                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+    2161                 :            :     false,
+    2162                 :            : };
+    2163                 :            : 
+    2164                 :          1 : int libspdm_responder_key_update_test_main(void)
+    2165                 :            : {
+    2166                 :          1 :     const struct CMUnitTest spdm_responder_key_update_tests[] = {
+    2167                 :            :         /* Success Case -- UpdateKey*/
+    2168                 :            :         cmocka_unit_test(libspdm_test_responder_key_update_case1),
+    2169                 :            :         /* Bad request size*/
+    2170                 :            :         cmocka_unit_test(libspdm_test_responder_key_update_case2),
+    2171                 :            :         /* response_state: SPDM_RESPONSE_STATE_BUSY*/
+    2172                 :            :         cmocka_unit_test(libspdm_test_responder_key_update_case3),
+    2173                 :            :         /* response_state: SPDM_RESPONSE_STATE_NEED_RESYNC*/
+    2174                 :            :         cmocka_unit_test(libspdm_test_responder_key_update_case4),
+    2175                 :            :         #if LIBSPDM_RESPOND_IF_READY_SUPPORT
+    2176                 :            :         /* response_state: SPDM_RESPONSE_STATE_NOT_READY*/
+    2177                 :            :         cmocka_unit_test(libspdm_test_responder_key_update_case5),
+    2178                 :            :         #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
+    2179                 :            :         /* connection_state Check*/
+    2180                 :            :         cmocka_unit_test(libspdm_test_responder_key_update_case6),
+    2181                 :            :         /* Buffer reset*/
+    2182                 :            :         cmocka_unit_test(libspdm_test_responder_key_update_case7),
+    2183                 :            :         /* Unsupported KEY_UPD capabilities*/
+    2184                 :            :         cmocka_unit_test(libspdm_test_responder_key_update_case8),
+    2185                 :            :         /* Uninitialized session*/
+    2186                 :            :         cmocka_unit_test(libspdm_test_responder_key_update_case9),
+    2187                 :            :         /* Success Case -- UpdateAllKeys*/
+    2188                 :            :         cmocka_unit_test(libspdm_test_responder_key_update_case10),
+    2189                 :            :         /* Bad request size*/
+    2190                 :            :         cmocka_unit_test(libspdm_test_responder_key_update_case11),
+    2191                 :            :         /* UpdateKey + VerifyNewKey: Success*/
+    2192                 :            :         cmocka_unit_test(libspdm_test_responder_key_update_case12),
+    2193                 :            :         /* Bad request size*/
+    2194                 :            :         cmocka_unit_test(libspdm_test_responder_key_update_case13),
+    2195                 :            :         /* UpdateALLKeys + VerifyNewKey: Success*/
+    2196                 :            :         cmocka_unit_test(libspdm_test_responder_key_update_case14),
+    2197                 :            :         /* Bad request size*/
+    2198                 :            :         cmocka_unit_test(libspdm_test_responder_key_update_case15),
+    2199                 :            :         /* Uninitialized key update*/
+    2200                 :            :         cmocka_unit_test(libspdm_test_responder_key_update_case16),
+    2201                 :            :         /* UpdateKey + UpdateKey: failed*/
+    2202                 :            :         cmocka_unit_test(libspdm_test_responder_key_update_case17),
+    2203                 :            :         /* UpdateKey + UpdateAllKeys: failed*/
+    2204                 :            :         cmocka_unit_test(libspdm_test_responder_key_update_case18),
+    2205                 :            :         /* UpdateALLKeys + UpdateKey: failed*/
+    2206                 :            :         cmocka_unit_test(libspdm_test_responder_key_update_case19),
+    2207                 :            :         /* UpdateALLKeys + UpdateALLKeys: failed*/
+    2208                 :            :         cmocka_unit_test(libspdm_test_responder_key_update_case20),
+    2209                 :            :         /* VerifyNewKey + UpdateKey: success*/
+    2210                 :            :         cmocka_unit_test(libspdm_test_responder_key_update_case21),
+    2211                 :            :         /* VerifyNewKey + UpdateAllKeys: success*/
+    2212                 :            :         cmocka_unit_test(libspdm_test_responder_key_update_case22),
+    2213                 :            :         /* VerifyNewKey + VerifyNewKey: failed*/
+    2214                 :            :         cmocka_unit_test(libspdm_test_responder_key_update_case23),
+    2215                 :            :         /* ohter command + UpdateKey: success*/
+    2216                 :            :         cmocka_unit_test(libspdm_test_responder_key_update_case24),
+    2217                 :            :         /* ohter command + UpdateAllKeys: success*/
+    2218                 :            :         cmocka_unit_test(libspdm_test_responder_key_update_case25),
+    2219                 :            :         /* ohter command + VerifyNewKey: failed*/
+    2220                 :            :         cmocka_unit_test(libspdm_test_responder_key_update_case26),
+    2221                 :            :         /* Invalid operation,other key_update operation: failed*/
+    2222                 :            :         cmocka_unit_test(libspdm_test_responder_key_update_case27),
+    2223                 :            :     };
+    2224                 :            : 
+    2225                 :          1 :     libspdm_setup_test_context(&m_libspdm_responder_key_update_test_context);
+    2226                 :            : 
+    2227                 :          1 :     return cmocka_run_group_tests(spdm_responder_key_update_tests,
+    2228                 :            :                                   libspdm_unit_test_group_setup,
+    2229                 :            :                                   libspdm_unit_test_group_teardown);
+    2230                 :            : }
+    2231                 :            : 
+    2232                 :            : #endif /* (LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP) || (LIBSPDM_ENABLE_CAPABILITY_PSK_CAP) */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/measurement_extension_log.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_responder/measurement_extension_log.c.func-sort-c.html new file mode 100644 index 00000000000..3b238d7f481 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/measurement_extension_log.c.func-sort-c.html @@ -0,0 +1,105 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/measurement_extension_log.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - measurement_extension_log.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:136136100.0 %
Date:2024-09-22 08:21:07Functions:66100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_measurement_extension_log_test_main1
libspdm_test_responder_measurement_extension_log_case11
libspdm_test_responder_measurement_extension_log_case21
libspdm_test_responder_measurement_extension_log_case31
libspdm_test_responder_measurement_extension_log_case41
libspdm_test_responder_measurement_extension_log_case51
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/measurement_extension_log.c.func.html b/coverage_log/unit_test/test_spdm_responder/measurement_extension_log.c.func.html new file mode 100644 index 00000000000..73c356ca8aa --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/measurement_extension_log.c.func.html @@ -0,0 +1,105 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/measurement_extension_log.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - measurement_extension_log.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:136136100.0 %
Date:2024-09-22 08:21:07Functions:66100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_measurement_extension_log_test_main1
libspdm_test_responder_measurement_extension_log_case11
libspdm_test_responder_measurement_extension_log_case21
libspdm_test_responder_measurement_extension_log_case31
libspdm_test_responder_measurement_extension_log_case41
libspdm_test_responder_measurement_extension_log_case51
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/measurement_extension_log.c.gcov.html b/coverage_log/unit_test/test_spdm_responder/measurement_extension_log.c.gcov.html new file mode 100644 index 00000000000..c5ceb1866e5 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/measurement_extension_log.c.gcov.html @@ -0,0 +1,470 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/measurement_extension_log.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - measurement_extension_log.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:136136100.0 %
Date:2024-09-22 08:21:07Functions:66100.0 %
Branches:00-
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2024 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_responder_lib.h"
+       9                 :            : 
+      10                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MEL_CAP
+      11                 :            : 
+      12                 :            : spdm_get_measurement_extension_log_request_t m_libspdm_get_measurement_extension_log_request1 = {
+      13                 :            :     { SPDM_MESSAGE_VERSION_13, SPDM_GET_MEASUREMENT_EXTENSION_LOG, 0, 0 },
+      14                 :            :     0,
+      15                 :            :     LIBSPDM_MAX_MEL_BLOCK_LEN
+      16                 :            : };
+      17                 :            : size_t m_libspdm_get_measurement_extension_log_request1_size =
+      18                 :            :     sizeof(m_libspdm_get_measurement_extension_log_request1);
+      19                 :            : 
+      20                 :            : spdm_get_measurement_extension_log_request_t m_libspdm_get_measurement_extension_log_request2 = {
+      21                 :            :     { SPDM_MESSAGE_VERSION_13, SPDM_GET_MEASUREMENT_EXTENSION_LOG, 0, 0 },
+      22                 :            :     0,
+      23                 :            :     0
+      24                 :            : };
+      25                 :            : size_t m_libspdm_get_measurement_extension_log_request2_size =
+      26                 :            :     sizeof(m_libspdm_get_measurement_extension_log_request2);
+      27                 :            : 
+      28                 :            : spdm_get_measurement_extension_log_request_t m_libspdm_get_measurement_extension_log_request3 = {
+      29                 :            :     { SPDM_MESSAGE_VERSION_13, SPDM_GET_MEASUREMENT_EXTENSION_LOG, 0, 0 },
+      30                 :            :     0,
+      31                 :            :     LIBSPDM_MAX_MEL_BLOCK_LEN + 1
+      32                 :            : };
+      33                 :            : size_t m_libspdm_get_measurement_extension_log_request3_size =
+      34                 :            :     sizeof(m_libspdm_get_measurement_extension_log_request3);
+      35                 :            : 
+      36                 :            : spdm_get_measurement_extension_log_request_t m_libspdm_get_measurement_extension_log_request4 = {
+      37                 :            :     { SPDM_MESSAGE_VERSION_13, SPDM_GET_MEASUREMENT_EXTENSION_LOG, 0, 0 },
+      38                 :            :     LIBSPDM_MAX_MEL_BLOCK_LEN,
+      39                 :            :     LIBSPDM_MAX_MEL_BLOCK_LEN
+      40                 :            : };
+      41                 :            : size_t m_libspdm_get_measurement_extension_log_request4_size =
+      42                 :            :     sizeof(m_libspdm_get_measurement_extension_log_request4);
+      43                 :            : 
+      44                 :            : /**
+      45                 :            :  * Test 1: request the first LIBSPDM_MAX_MEL_BLOCK_LEN bytes of the MEL
+      46                 :            :  * Expected Behavior: generate a correctly formed MEL message, including its portion_length and remainder_length fields
+      47                 :            :  **/
+      48                 :          1 : void libspdm_test_responder_measurement_extension_log_case1(void **state)
+      49                 :            : {
+      50                 :            :     libspdm_return_t status;
+      51                 :            :     libspdm_test_context_t *spdm_test_context;
+      52                 :            :     libspdm_context_t *spdm_context;
+      53                 :            :     size_t response_size;
+      54                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+      55                 :            :     spdm_measurement_extension_log_response_t *spdm_response;
+      56                 :            :     spdm_measurement_extension_log_dmtf_t *spdm_mel;
+      57                 :            :     size_t spdm_mel_len;
+      58                 :            : 
+      59                 :          1 :     spdm_test_context = *state;
+      60                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+      61                 :          1 :     spdm_test_context->case_id = 0x1;
+      62                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+      63                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+      64                 :          1 :     spdm_context->connection_info.connection_state =
+      65                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+      66                 :          1 :     spdm_context->local_context.capability.flags |=
+      67                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEL_CAP;
+      68                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+      69                 :            :         m_libspdm_use_hash_algo;
+      70                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+      71                 :            :         m_libspdm_use_asym_algo;
+      72                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+      73                 :            :         m_libspdm_use_measurement_spec;
+      74                 :          1 :     spdm_context->connection_info.algorithm.mel_spec =
+      75                 :            :         m_libspdm_use_mel_spec;
+      76                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+      77                 :            :         m_libspdm_use_measurement_hash_algo;
+      78                 :            : 
+      79                 :          1 :     response_size = sizeof(response);
+      80                 :          1 :     status = libspdm_get_response_measurement_extension_log(
+      81                 :            :         spdm_context, m_libspdm_get_measurement_extension_log_request1_size,
+      82                 :            :         &m_libspdm_get_measurement_extension_log_request1, &response_size, response);
+      83                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+      84                 :            : 
+      85                 :          1 :     spdm_mel = NULL;
+      86                 :          1 :     spdm_mel_len = 0;
+      87                 :          1 :     libspdm_measurement_extension_log_collection(
+      88                 :            :         spdm_context,
+      89                 :            :         m_libspdm_use_mel_spec,
+      90                 :            :         m_libspdm_use_measurement_spec,
+      91                 :            :         m_libspdm_use_measurement_hash_algo,
+      92                 :            :         (void **)&spdm_mel, &spdm_mel_len);
+      93                 :            : 
+      94                 :          1 :     assert_int_equal(response_size,
+      95                 :            :                      sizeof(spdm_measurement_extension_log_response_t) +
+      96                 :            :                      spdm_mel_len);
+      97                 :          1 :     spdm_response = (void *)response;
+      98                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+      99                 :            :                      SPDM_MEASUREMENT_EXTENSION_LOG);
+     100                 :          1 :     assert_int_equal(spdm_response->header.param1, 0);
+     101                 :          1 :     assert_int_equal(spdm_response->portion_length, spdm_mel_len);
+     102                 :          1 :     assert_int_equal(spdm_response->remainder_length, 0);
+     103                 :          1 :     assert_memory_equal(spdm_response + 1, spdm_mel, spdm_mel_len);
+     104                 :          1 : }
+     105                 :            : 
+     106                 :            : /**
+     107                 :            :  * Test 2: request.length is less than the MEL len
+     108                 :            :  * Expected Behavior: generate a correctly formed MEL message, including its portion_length and remainder_length fields
+     109                 :            :  **/
+     110                 :          1 : void libspdm_test_responder_measurement_extension_log_case2(void **state)
+     111                 :            : {
+     112                 :            :     libspdm_return_t status;
+     113                 :            :     libspdm_test_context_t *spdm_test_context;
+     114                 :            :     libspdm_context_t *spdm_context;
+     115                 :            :     size_t response_size;
+     116                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     117                 :            :     spdm_measurement_extension_log_response_t  *spdm_response;
+     118                 :            :     spdm_measurement_extension_log_dmtf_t *spdm_mel;
+     119                 :            :     size_t spdm_mel_len;
+     120                 :            : 
+     121                 :          1 :     spdm_test_context = *state;
+     122                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     123                 :          1 :     spdm_test_context->case_id = 0x2;
+     124                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+     125                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     126                 :          1 :     spdm_context->connection_info.connection_state =
+     127                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     128                 :          1 :     spdm_context->local_context.capability.flags |=
+     129                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEL_CAP;
+     130                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     131                 :            :         m_libspdm_use_hash_algo;
+     132                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     133                 :            :         m_libspdm_use_asym_algo;
+     134                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     135                 :            :         m_libspdm_use_measurement_spec;
+     136                 :          1 :     spdm_context->connection_info.algorithm.mel_spec =
+     137                 :            :         m_libspdm_use_mel_spec;
+     138                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     139                 :            :         m_libspdm_use_measurement_hash_algo;
+     140                 :            : 
+     141                 :          1 :     spdm_mel = NULL;
+     142                 :          1 :     spdm_mel_len = 0;
+     143                 :          1 :     libspdm_measurement_extension_log_collection(spdm_context,
+     144                 :            :                                                  m_libspdm_use_mel_spec,
+     145                 :            :                                                  m_libspdm_use_measurement_spec,
+     146                 :            :                                                  m_libspdm_use_measurement_hash_algo,
+     147                 :            :                                                  (void **)&spdm_mel, &spdm_mel_len);
+     148                 :            : 
+     149                 :            :     /* Test the validity of the request.length.*/
+     150                 :          1 :     m_libspdm_get_measurement_extension_log_request2.length = (uint32_t)spdm_mel_len / 2;
+     151                 :            : 
+     152                 :          1 :     response_size = sizeof(response);
+     153                 :          1 :     status = libspdm_get_response_measurement_extension_log(
+     154                 :            :         spdm_context, m_libspdm_get_measurement_extension_log_request2_size,
+     155                 :            :         &m_libspdm_get_measurement_extension_log_request2, &response_size, response);
+     156                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     157                 :            : 
+     158                 :          1 :     assert_int_equal(response_size,
+     159                 :            :                      sizeof(spdm_measurement_extension_log_response_t) +
+     160                 :            :                      spdm_mel_len / 2);
+     161                 :          1 :     spdm_response = (void *)response;
+     162                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     163                 :            :                      SPDM_MEASUREMENT_EXTENSION_LOG);
+     164                 :          1 :     assert_int_equal(spdm_response->header.param1, 0);
+     165                 :          1 :     assert_int_equal(spdm_response->portion_length, spdm_mel_len / 2);
+     166                 :          1 :     assert_int_equal(spdm_response->remainder_length, spdm_mel_len / 2 + 1);
+     167                 :          1 :     assert_memory_equal(spdm_response + 1, (void *)spdm_mel,
+     168                 :            :                         response_size - sizeof(spdm_measurement_extension_log_response_t));
+     169                 :          1 : }
+     170                 :            : 
+     171                 :            : /**
+     172                 :            :  * Test 3: When the request.length is greater than LIBSPDM_MAX_MEL_BLOCK_LEN.
+     173                 :            :  * Expected Behavior: generate a correctly formed MEL message, including its portion_length and remainder_length fields
+     174                 :            :  **/
+     175                 :          1 : void libspdm_test_responder_measurement_extension_log_case3(void **state)
+     176                 :            : {
+     177                 :            :     libspdm_return_t status;
+     178                 :            :     libspdm_test_context_t *spdm_test_context;
+     179                 :            :     libspdm_context_t *spdm_context;
+     180                 :            :     size_t response_size;
+     181                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     182                 :            :     spdm_measurement_extension_log_response_t *spdm_response;
+     183                 :            :     spdm_measurement_extension_log_dmtf_t *spdm_mel;
+     184                 :            :     size_t spdm_mel_len;
+     185                 :            : 
+     186                 :          1 :     spdm_test_context = *state;
+     187                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     188                 :          1 :     spdm_test_context->case_id = 0x3;
+     189                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+     190                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     191                 :          1 :     spdm_context->connection_info.connection_state =
+     192                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     193                 :          1 :     spdm_context->local_context.capability.flags |=
+     194                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEL_CAP;
+     195                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     196                 :            :         m_libspdm_use_hash_algo;
+     197                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     198                 :            :         m_libspdm_use_asym_algo;
+     199                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     200                 :            :         m_libspdm_use_measurement_spec;
+     201                 :          1 :     spdm_context->connection_info.algorithm.mel_spec =
+     202                 :            :         m_libspdm_use_mel_spec;
+     203                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     204                 :            :         m_libspdm_use_measurement_hash_algo;
+     205                 :            : 
+     206                 :          1 :     response_size = sizeof(response);
+     207                 :          1 :     status = libspdm_get_response_measurement_extension_log(
+     208                 :            :         spdm_context, m_libspdm_get_measurement_extension_log_request3_size,
+     209                 :            :         &m_libspdm_get_measurement_extension_log_request3, &response_size, response);
+     210                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     211                 :            : 
+     212                 :          1 :     spdm_mel = NULL;
+     213                 :          1 :     spdm_mel_len = 0;
+     214                 :          1 :     libspdm_measurement_extension_log_collection(spdm_context,
+     215                 :            :                                                  m_libspdm_use_mel_spec,
+     216                 :            :                                                  m_libspdm_use_measurement_spec,
+     217                 :            :                                                  m_libspdm_use_measurement_hash_algo,
+     218                 :            :                                                  (void **)&spdm_mel, &spdm_mel_len);
+     219                 :            : 
+     220                 :          1 :     assert_int_equal(response_size,
+     221                 :            :                      sizeof(spdm_measurement_extension_log_response_t) +
+     222                 :            :                      spdm_mel_len);
+     223                 :          1 :     spdm_response = (void *)response;
+     224                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     225                 :            :                      SPDM_MEASUREMENT_EXTENSION_LOG);
+     226                 :          1 :     assert_int_equal(spdm_response->header.param1, 0);
+     227                 :          1 :     assert_int_equal(spdm_response->portion_length, spdm_mel_len);
+     228                 :          1 :     assert_int_equal(spdm_response->remainder_length, 0);
+     229                 :          1 :     assert_memory_equal(spdm_response + 1, (void *)spdm_mel,
+     230                 :            :                         response_size - sizeof(spdm_measurement_extension_log_response_t));
+     231                 :          1 : }
+     232                 :            : 
+     233                 :            : /**
+     234                 :            :  * Test 4: request.offset > spdm mel len , wrong request message
+     235                 :            :  * Expected Behavior: Generate error response message
+     236                 :            :  **/
+     237                 :          1 : void libspdm_test_responder_measurement_extension_log_case4(void **state)
+     238                 :            : {
+     239                 :            :     libspdm_return_t status;
+     240                 :            :     libspdm_test_context_t *spdm_test_context;
+     241                 :            :     libspdm_context_t *spdm_context;
+     242                 :            :     size_t response_size;
+     243                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     244                 :            :     spdm_measurement_extension_log_response_t *spdm_response;
+     245                 :            :     spdm_measurement_extension_log_dmtf_t *spdm_mel;
+     246                 :            :     size_t spdm_mel_len;
+     247                 :            : 
+     248                 :          1 :     spdm_test_context = *state;
+     249                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     250                 :          1 :     spdm_test_context->case_id = 0x4;
+     251                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+     252                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     253                 :          1 :     spdm_context->connection_info.connection_state =
+     254                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     255                 :          1 :     spdm_context->local_context.capability.flags |=
+     256                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEL_CAP;
+     257                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     258                 :            :         m_libspdm_use_hash_algo;
+     259                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     260                 :            :         m_libspdm_use_asym_algo;
+     261                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     262                 :            :         m_libspdm_use_measurement_spec;
+     263                 :          1 :     spdm_context->connection_info.algorithm.mel_spec =
+     264                 :            :         m_libspdm_use_mel_spec;
+     265                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     266                 :            :         m_libspdm_use_measurement_hash_algo;
+     267                 :            : 
+     268                 :          1 :     spdm_mel = NULL;
+     269                 :          1 :     spdm_mel_len = 0;
+     270                 :          1 :     libspdm_measurement_extension_log_collection(spdm_context,
+     271                 :            :                                                  m_libspdm_use_mel_spec,
+     272                 :            :                                                  m_libspdm_use_measurement_spec,
+     273                 :            :                                                  m_libspdm_use_measurement_hash_algo,
+     274                 :            :                                                  (void **)&spdm_mel, &spdm_mel_len);
+     275                 :            :     /* request.offset > total MEL len*/
+     276                 :          1 :     m_libspdm_get_measurement_extension_log_request4.offset = (uint32_t)spdm_mel_len +
+     277                 :            :                                                               LIBSPDM_MAX_MEL_BLOCK_LEN;
+     278                 :            : 
+     279                 :          1 :     response_size = sizeof(response);
+     280                 :          1 :     status = libspdm_get_response_measurement_extension_log(
+     281                 :            :         spdm_context, m_libspdm_get_measurement_extension_log_request4_size,
+     282                 :            :         &m_libspdm_get_measurement_extension_log_request4, &response_size, response);
+     283                 :            : 
+     284                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     285                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     286                 :          1 :     spdm_response = (void *)response;
+     287                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
+     288                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+     289                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     290                 :          1 : }
+     291                 :            : 
+     292                 :            : /**
+     293                 :            :  * Test 5: A correct and not zero request.offset.
+     294                 :            :  * Expected Behavior: generate a correctly formed MEL message, including its portion_length and remainder_length fields
+     295                 :            :  **/
+     296                 :          1 : void libspdm_test_responder_measurement_extension_log_case5(void **state)
+     297                 :            : {
+     298                 :            :     libspdm_return_t status;
+     299                 :            :     libspdm_test_context_t *spdm_test_context;
+     300                 :            :     libspdm_context_t *spdm_context;
+     301                 :            :     size_t response_size;
+     302                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     303                 :            :     spdm_measurement_extension_log_response_t  *spdm_response;
+     304                 :            :     spdm_measurement_extension_log_dmtf_t *spdm_mel;
+     305                 :            :     size_t spdm_mel_len;
+     306                 :            : 
+     307                 :          1 :     spdm_test_context = *state;
+     308                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     309                 :          1 :     spdm_test_context->case_id = 0x5;
+     310                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+     311                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     312                 :          1 :     spdm_context->connection_info.connection_state =
+     313                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     314                 :          1 :     spdm_context->local_context.capability.flags |=
+     315                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEL_CAP;
+     316                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     317                 :            :         m_libspdm_use_hash_algo;
+     318                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     319                 :            :         m_libspdm_use_asym_algo;
+     320                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     321                 :            :         m_libspdm_use_measurement_spec;
+     322                 :          1 :     spdm_context->connection_info.algorithm.mel_spec =
+     323                 :            :         m_libspdm_use_mel_spec;
+     324                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     325                 :            :         m_libspdm_use_measurement_hash_algo;
+     326                 :            : 
+     327                 :          1 :     spdm_mel = NULL;
+     328                 :          1 :     spdm_mel_len = 0;
+     329                 :          1 :     libspdm_measurement_extension_log_collection(spdm_context,
+     330                 :            :                                                  m_libspdm_use_mel_spec,
+     331                 :            :                                                  m_libspdm_use_measurement_spec,
+     332                 :            :                                                  m_libspdm_use_measurement_hash_algo,
+     333                 :            :                                                  (void **)&spdm_mel, &spdm_mel_len);
+     334                 :            : 
+     335                 :            :     /* Test the validity of the request.offset.*/
+     336                 :          1 :     m_libspdm_get_measurement_extension_log_request2.offset = (uint32_t)spdm_mel_len / 2;
+     337                 :          1 :     m_libspdm_get_measurement_extension_log_request2.length = LIBSPDM_MAX_MEL_BLOCK_LEN;
+     338                 :            : 
+     339                 :          1 :     response_size = sizeof(response);
+     340                 :          1 :     status = libspdm_get_response_measurement_extension_log(
+     341                 :            :         spdm_context, m_libspdm_get_measurement_extension_log_request2_size,
+     342                 :            :         &m_libspdm_get_measurement_extension_log_request2, &response_size, response);
+     343                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     344                 :            : 
+     345                 :          1 :     assert_int_equal(response_size,
+     346                 :            :                      sizeof(spdm_measurement_extension_log_response_t) +
+     347                 :            :                      spdm_mel_len / 2 + 1);
+     348                 :          1 :     spdm_response = (void *)response;
+     349                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     350                 :            :                      SPDM_MEASUREMENT_EXTENSION_LOG);
+     351                 :          1 :     assert_int_equal(spdm_response->header.param1, 0);
+     352                 :          1 :     assert_int_equal(spdm_response->portion_length, spdm_mel_len / 2 + 1);
+     353                 :          1 :     assert_int_equal(spdm_response->remainder_length, 0);
+     354                 :          1 :     assert_memory_equal(spdm_response + 1, (void *)((uint8_t *)spdm_mel + spdm_mel_len / 2),
+     355                 :            :                         response_size - sizeof(spdm_measurement_extension_log_response_t));
+     356                 :          1 : }
+     357                 :            : 
+     358                 :            : libspdm_test_context_t m_libspdm_responder_measurement_extension_log_test_context = {
+     359                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+     360                 :            :     false,
+     361                 :            : };
+     362                 :            : 
+     363                 :          1 : int libspdm_responder_measurement_extension_log_test_main(void)
+     364                 :            : {
+     365                 :          1 :     const struct CMUnitTest spdm_responder_measurement_extension_log_tests[] = {
+     366                 :            :         /* Success Case*/
+     367                 :            :         cmocka_unit_test(libspdm_test_responder_measurement_extension_log_case1),
+     368                 :            :         /* Success Case, request.length < total MEL len*/
+     369                 :            :         cmocka_unit_test(libspdm_test_responder_measurement_extension_log_case2),
+     370                 :            :         /* Success Case, request.length > LIBSPDM_MAX_MEL_BLOCK_LEN*/
+     371                 :            :         cmocka_unit_test(libspdm_test_responder_measurement_extension_log_case3),
+     372                 :            :         /* failed Case,  request.offset > total MEL len*/
+     373                 :            :         cmocka_unit_test(libspdm_test_responder_measurement_extension_log_case4),
+     374                 :            :         /* Success Case, request.offset < total MEL len*/
+     375                 :            :         cmocka_unit_test(libspdm_test_responder_measurement_extension_log_case5),
+     376                 :            :     };
+     377                 :            : 
+     378                 :          1 :     libspdm_setup_test_context(&m_libspdm_responder_measurement_extension_log_test_context);
+     379                 :            : 
+     380                 :          1 :     return cmocka_run_group_tests(spdm_responder_measurement_extension_log_tests,
+     381                 :            :                                   libspdm_unit_test_group_setup,
+     382                 :            :                                   libspdm_unit_test_group_teardown);
+     383                 :            : }
+     384                 :            : 
+     385                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEL_CAP */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/measurements.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_responder/measurements.c.func-sort-c.html new file mode 100644 index 00000000000..094cd8b1513 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/measurements.c.func-sort-c.html @@ -0,0 +1,225 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/measurements.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - measurements.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:1025102799.8 %
Date:2024-09-22 08:21:07Functions:3636100.0 %
Branches:131492.9 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_measurements_test_main1
libspdm_test_responder_measurements_case11
libspdm_test_responder_measurements_case101
libspdm_test_responder_measurements_case111
libspdm_test_responder_measurements_case121
libspdm_test_responder_measurements_case131
libspdm_test_responder_measurements_case141
libspdm_test_responder_measurements_case151
libspdm_test_responder_measurements_case161
libspdm_test_responder_measurements_case171
libspdm_test_responder_measurements_case181
libspdm_test_responder_measurements_case191
libspdm_test_responder_measurements_case21
libspdm_test_responder_measurements_case211
libspdm_test_responder_measurements_case221
libspdm_test_responder_measurements_case231
libspdm_test_responder_measurements_case241
libspdm_test_responder_measurements_case251
libspdm_test_responder_measurements_case261
libspdm_test_responder_measurements_case271
libspdm_test_responder_measurements_case281
libspdm_test_responder_measurements_case291
libspdm_test_responder_measurements_case31
libspdm_test_responder_measurements_case301
libspdm_test_responder_measurements_case311
libspdm_test_responder_measurements_case321
libspdm_test_responder_measurements_case331
libspdm_test_responder_measurements_case341
libspdm_test_responder_measurements_case351
libspdm_test_responder_measurements_case361
libspdm_test_responder_measurements_case41
libspdm_test_responder_measurements_case51
libspdm_test_responder_measurements_case61
libspdm_test_responder_measurements_case71
libspdm_test_responder_measurements_case81
libspdm_test_responder_measurements_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/measurements.c.func.html b/coverage_log/unit_test/test_spdm_responder/measurements.c.func.html new file mode 100644 index 00000000000..9af88a8ada1 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/measurements.c.func.html @@ -0,0 +1,225 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/measurements.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - measurements.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:1025102799.8 %
Date:2024-09-22 08:21:07Functions:3636100.0 %
Branches:131492.9 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_measurements_test_main1
libspdm_test_responder_measurements_case11
libspdm_test_responder_measurements_case101
libspdm_test_responder_measurements_case111
libspdm_test_responder_measurements_case121
libspdm_test_responder_measurements_case131
libspdm_test_responder_measurements_case141
libspdm_test_responder_measurements_case151
libspdm_test_responder_measurements_case161
libspdm_test_responder_measurements_case171
libspdm_test_responder_measurements_case181
libspdm_test_responder_measurements_case191
libspdm_test_responder_measurements_case21
libspdm_test_responder_measurements_case211
libspdm_test_responder_measurements_case221
libspdm_test_responder_measurements_case231
libspdm_test_responder_measurements_case241
libspdm_test_responder_measurements_case251
libspdm_test_responder_measurements_case261
libspdm_test_responder_measurements_case271
libspdm_test_responder_measurements_case281
libspdm_test_responder_measurements_case291
libspdm_test_responder_measurements_case31
libspdm_test_responder_measurements_case301
libspdm_test_responder_measurements_case311
libspdm_test_responder_measurements_case321
libspdm_test_responder_measurements_case331
libspdm_test_responder_measurements_case341
libspdm_test_responder_measurements_case351
libspdm_test_responder_measurements_case361
libspdm_test_responder_measurements_case41
libspdm_test_responder_measurements_case51
libspdm_test_responder_measurements_case61
libspdm_test_responder_measurements_case71
libspdm_test_responder_measurements_case81
libspdm_test_responder_measurements_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/measurements.c.gcov.html b/coverage_log/unit_test/test_spdm_responder/measurements.c.gcov.html new file mode 100644 index 00000000000..a78af47f4ce --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/measurements.c.gcov.html @@ -0,0 +1,2910 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/measurements.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - measurements.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:1025102799.8 %
Date:2024-09-22 08:21:07Functions:3636100.0 %
Branches:131492.9 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_responder_lib.h"
+       9                 :            : #include "internal/libspdm_requester_lib.h"
+      10                 :            : 
+      11                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
+      12                 :            : 
+      13                 :            : spdm_get_measurements_request_t m_libspdm_get_measurements_request1 = {
+      14                 :            :     { SPDM_MESSAGE_VERSION_10, SPDM_GET_MEASUREMENTS, 0,
+      15                 :            :       SPDM_GET_MEASUREMENTS_REQUEST_MEASUREMENT_OPERATION_TOTAL_NUMBER_OF_MEASUREMENTS },
+      16                 :            : };
+      17                 :            : size_t m_libspdm_get_measurements_request1_size = sizeof(spdm_message_header_t);
+      18                 :            : 
+      19                 :            : spdm_get_measurements_request_t m_libspdm_get_measurements_request3 = {
+      20                 :            :     { SPDM_MESSAGE_VERSION_10, SPDM_GET_MEASUREMENTS,
+      21                 :            :       SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE, 1 },
+      22                 :            : };
+      23                 :            : size_t m_libspdm_get_measurements_request3_size =
+      24                 :            :     sizeof(m_libspdm_get_measurements_request3) - sizeof(uint8_t);
+      25                 :            : 
+      26                 :            : spdm_get_measurements_request_t m_libspdm_get_measurements_request4 = {
+      27                 :            :     { SPDM_MESSAGE_VERSION_10, SPDM_GET_MEASUREMENTS,
+      28                 :            :       SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE, 1 },
+      29                 :            : };
+      30                 :            : size_t m_libspdm_get_measurements_request4_size = sizeof(spdm_message_header_t);
+      31                 :            : 
+      32                 :            : spdm_get_measurements_request_t m_libspdm_get_measurements_request5 = {
+      33                 :            :     { SPDM_MESSAGE_VERSION_10, SPDM_GET_MEASUREMENTS,
+      34                 :            :       SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE,
+      35                 :            :       SPDM_GET_MEASUREMENTS_REQUEST_MEASUREMENT_OPERATION_TOTAL_NUMBER_OF_MEASUREMENTS },
+      36                 :            : };
+      37                 :            : size_t m_libspdm_get_measurements_request5_size =
+      38                 :            :     sizeof(m_libspdm_get_measurements_request5) - sizeof(uint8_t);
+      39                 :            : 
+      40                 :            : spdm_get_measurements_request_t m_libspdm_get_measurements_request6 = {
+      41                 :            :     { SPDM_MESSAGE_VERSION_10, SPDM_GET_MEASUREMENTS, 0, 1 },
+      42                 :            : };
+      43                 :            : size_t m_libspdm_get_measurements_request6_size = sizeof(spdm_message_header_t);
+      44                 :            : 
+      45                 :            : spdm_get_measurements_request_t m_libspdm_get_measurements_request7 = {
+      46                 :            :     { SPDM_MESSAGE_VERSION_10, SPDM_GET_MEASUREMENTS, 0,
+      47                 :            :       SPDM_GET_MEASUREMENTS_REQUEST_MEASUREMENT_OPERATION_ALL_MEASUREMENTS },
+      48                 :            : };
+      49                 :            : size_t m_libspdm_get_measurements_request7_size = sizeof(spdm_message_header_t);
+      50                 :            : 
+      51                 :            : spdm_get_measurements_request_t m_libspdm_get_measurements_request8 = {
+      52                 :            :     { SPDM_MESSAGE_VERSION_10, SPDM_GET_MEASUREMENTS,
+      53                 :            :       SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE,
+      54                 :            :       SPDM_GET_MEASUREMENTS_REQUEST_MEASUREMENT_OPERATION_ALL_MEASUREMENTS },
+      55                 :            : };
+      56                 :            : size_t m_libspdm_get_measurements_request8_size =
+      57                 :            :     sizeof(m_libspdm_get_measurements_request8) - sizeof(uint8_t);
+      58                 :            : 
+      59                 :            : spdm_get_measurements_request_t m_libspdm_get_measurements_request9 = {
+      60                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_GET_MEASUREMENTS, 0, 1 },
+      61                 :            : };
+      62                 :            : size_t m_libspdm_get_measurements_request9_size = sizeof(spdm_message_header_t);
+      63                 :            : 
+      64                 :            : spdm_get_measurements_request_t m_libspdm_get_measurements_request10 = {
+      65                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_GET_MEASUREMENTS,
+      66                 :            :       SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE, 1 },
+      67                 :            : };
+      68                 :            : size_t m_libspdm_get_measurements_request10_size =
+      69                 :            :     sizeof(m_libspdm_get_measurements_request10);
+      70                 :            : 
+      71                 :            : spdm_get_measurements_request_t m_libspdm_get_measurements_request11 = {
+      72                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_GET_MEASUREMENTS,
+      73                 :            :       SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE, 1 },
+      74                 :            :     /* nonce
+      75                 :            :      * SlotId != 0*/
+      76                 :            : };
+      77                 :            : size_t m_libspdm_get_measurements_request11_size =
+      78                 :            :     sizeof(m_libspdm_get_measurements_request11);
+      79                 :            : 
+      80                 :            : spdm_get_measurements_request_t m_libspdm_get_measurements_request12 = {
+      81                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_GET_MEASUREMENTS,
+      82                 :            :       SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE, 1 },
+      83                 :            :     /* nonce
+      84                 :            :      * SlotId >= SPDM_MAX_SLOT_COUNT*/
+      85                 :            : };
+      86                 :            : size_t m_libspdm_get_measurements_request12_size =
+      87                 :            :     sizeof(m_libspdm_get_measurements_request12);
+      88                 :            : 
+      89                 :            : spdm_get_measurements_request_t m_libspdm_get_measurements_request13 = {
+      90                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_GET_MEASUREMENTS, 0, 0xF0 },
+      91                 :            : };
+      92                 :            : size_t m_libspdm_get_measurements_request13_size = sizeof(spdm_message_header_t);
+      93                 :            : 
+      94                 :            : spdm_get_measurements_request_t m_libspdm_get_measurements_request14 = {
+      95                 :            :     { SPDM_MESSAGE_VERSION_12, SPDM_GET_MEASUREMENTS,
+      96                 :            :       SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_RAW_BIT_STREAM_REQUESTED, 1},
+      97                 :            : };
+      98                 :            : size_t m_libspdm_get_measurements_request14_size = sizeof(spdm_message_header_t);
+      99                 :            : 
+     100                 :            : spdm_get_measurements_request_t m_libspdm_get_measurements_request15 = {
+     101                 :            :     { SPDM_MESSAGE_VERSION_12, SPDM_GET_MEASUREMENTS,
+     102                 :            :       SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE, 1},
+     103                 :            : };
+     104                 :            : size_t m_libspdm_get_measurements_request15_size = sizeof(m_libspdm_get_measurements_request14);
+     105                 :            : 
+     106                 :            : spdm_get_measurements_request_t m_libspdm_get_measurements_request16 = {
+     107                 :            :     { SPDM_MESSAGE_VERSION_12, SPDM_GET_MEASUREMENTS,
+     108                 :            :       SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE, 1 },
+     109                 :            : };
+     110                 :            : size_t m_libspdm_get_measurements_request16_size = sizeof(m_libspdm_get_measurements_request16);
+     111                 :            : 
+     112                 :            : spdm_get_measurements_request_t m_libspdm_get_measurements_request17 = {
+     113                 :            :     { SPDM_MESSAGE_VERSION_13, SPDM_GET_MEASUREMENTS, 0,
+     114                 :            :       SPDM_GET_MEASUREMENTS_REQUEST_MEASUREMENT_OPERATION_TOTAL_NUMBER_OF_MEASUREMENTS },
+     115                 :            : };
+     116                 :            : size_t m_libspdm_get_measurements_request17_size = sizeof(spdm_message_header_t);
+     117                 :            : 
+     118                 :            : extern size_t libspdm_secret_lib_meas_opaque_data_size;
+     119                 :            : 
+     120                 :            : /**
+     121                 :            :  * Test 1: Successful response to get a number of measurements without signature
+     122                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code, correct transcript.message_m size, and correct response message size and fields
+     123                 :            :  **/
+     124                 :          1 : void libspdm_test_responder_measurements_case1(void **state)
+     125                 :            : {
+     126                 :            :     libspdm_return_t status;
+     127                 :            :     libspdm_test_context_t *spdm_test_context;
+     128                 :            :     libspdm_context_t *spdm_context;
+     129                 :            :     size_t response_size;
+     130                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     131                 :            :     spdm_measurements_response_t *spdm_response;
+     132                 :            : 
+     133                 :          1 :     spdm_test_context = *state;
+     134                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     135                 :          1 :     spdm_test_context->case_id = 0x1;
+     136                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+     137                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     138                 :          1 :     spdm_context->connection_info.connection_state =
+     139                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     140                 :          1 :     spdm_context->local_context.capability.flags |=
+     141                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+     142                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     143                 :            :         m_libspdm_use_hash_algo;
+     144                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     145                 :            :         m_libspdm_use_asym_algo;
+     146                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     147                 :            :         m_libspdm_use_measurement_spec;
+     148                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     149                 :            :         m_libspdm_use_measurement_hash_algo;
+     150                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+     151                 :            : 
+     152                 :          1 :     libspdm_secret_lib_meas_opaque_data_size = 0;
+     153                 :            : 
+     154                 :          1 :     response_size = sizeof(response);
+     155                 :            : 
+     156                 :          1 :     status = libspdm_get_response_measurements(
+     157                 :            :         spdm_context, m_libspdm_get_measurements_request1_size,
+     158                 :            :         &m_libspdm_get_measurements_request1, &response_size, response);
+     159                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     160                 :          1 :     assert_int_equal(response_size,
+     161                 :            :                      sizeof(spdm_measurements_response_t) + SPDM_NONCE_SIZE + sizeof(uint16_t));
+     162                 :          1 :     spdm_response = (void *)response;
+     163                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     164                 :            :                      SPDM_MEASUREMENTS);
+     165                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     166                 :            :                      LIBSPDM_MEASUREMENT_BLOCK_NUMBER);
+     167                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     168                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
+     169                 :            :                      m_libspdm_get_measurements_request1_size +
+     170                 :            :                      sizeof(spdm_measurements_response_t) +
+     171                 :            :                      SPDM_NONCE_SIZE +
+     172                 :            :                      sizeof(uint16_t));
+     173                 :            : #endif
+     174                 :          1 : }
+     175                 :            : 
+     176                 :            : /**
+     177                 :            :  * Test 2:
+     178                 :            :  * Expected Behavior:
+     179                 :            :  **/
+     180                 :          1 : void libspdm_test_responder_measurements_case2(void **state)
+     181                 :            : {
+     182                 :          1 : }
+     183                 :            : 
+     184                 :            : /**
+     185                 :            :  * Test 3: Force response_state = SPDM_RESPONSE_STATE_BUSY when asked GET_MEASUREMENTS
+     186                 :            :  * Expected Behavior: generate an ERROR_RESPONSE with code SPDM_ERROR_CODE_BUSY
+     187                 :            :  **/
+     188                 :          1 : void libspdm_test_responder_measurements_case3(void **state)
+     189                 :            : {
+     190                 :            :     libspdm_return_t status;
+     191                 :            :     libspdm_test_context_t *spdm_test_context;
+     192                 :            :     libspdm_context_t *spdm_context;
+     193                 :            :     size_t response_size;
+     194                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     195                 :            :     spdm_measurements_response_t *spdm_response;
+     196                 :            : 
+     197                 :          1 :     spdm_test_context = *state;
+     198                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     199                 :          1 :     spdm_test_context->case_id = 0x3;
+     200                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+     201                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     202                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_BUSY;
+     203                 :          1 :     spdm_context->connection_info.connection_state =
+     204                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     205                 :          1 :     spdm_context->local_context.capability.flags |=
+     206                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+     207                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     208                 :            :         m_libspdm_use_hash_algo;
+     209                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     210                 :            :         m_libspdm_use_asym_algo;
+     211                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     212                 :            :         m_libspdm_use_measurement_spec;
+     213                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     214                 :            :         m_libspdm_use_measurement_hash_algo;
+     215                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+     216                 :          1 :     libspdm_secret_lib_meas_opaque_data_size = 0;
+     217                 :            : 
+     218                 :          1 :     response_size = sizeof(response);
+     219                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
+     220                 :            :                               m_libspdm_get_measurements_request1.nonce);
+     221                 :          1 :     status = libspdm_get_response_measurements(
+     222                 :            :         spdm_context, m_libspdm_get_measurements_request1_size,
+     223                 :            :         &m_libspdm_get_measurements_request1, &response_size, response);
+     224                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     225                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     226                 :          1 :     spdm_response = (void *)response;
+     227                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     228                 :            :                      SPDM_ERROR);
+     229                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_BUSY);
+     230                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     231                 :          1 :     assert_int_equal(spdm_context->response_state,
+     232                 :            :                      LIBSPDM_RESPONSE_STATE_BUSY);
+     233                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     234                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+     235                 :            : #endif
+     236                 :          1 : }
+     237                 :            : 
+     238                 :            : /**
+     239                 :            :  * Test 4: Force response_state = SPDM_RESPONSE_STATE_NEED_RESYNC when asked GET_MEASUREMENTS
+     240                 :            :  * Expected Behavior: generate an ERROR_RESPONSE with code SPDM_ERROR_CODE_REQUEST_RESYNCH
+     241                 :            :  **/
+     242                 :          1 : void libspdm_test_responder_measurements_case4(void **state)
+     243                 :            : {
+     244                 :            :     libspdm_return_t status;
+     245                 :            :     libspdm_test_context_t *spdm_test_context;
+     246                 :            :     libspdm_context_t *spdm_context;
+     247                 :            :     size_t response_size;
+     248                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     249                 :            :     spdm_measurements_response_t *spdm_response;
+     250                 :            : 
+     251                 :          1 :     spdm_test_context = *state;
+     252                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     253                 :          1 :     spdm_test_context->case_id = 0x4;
+     254                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+     255                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     256                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NEED_RESYNC;
+     257                 :          1 :     spdm_context->connection_info.connection_state =
+     258                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     259                 :          1 :     spdm_context->local_context.capability.flags |=
+     260                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+     261                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     262                 :            :         m_libspdm_use_hash_algo;
+     263                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     264                 :            :         m_libspdm_use_asym_algo;
+     265                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     266                 :            :         m_libspdm_use_measurement_spec;
+     267                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     268                 :            :         m_libspdm_use_measurement_hash_algo;
+     269                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+     270                 :          1 :     libspdm_secret_lib_meas_opaque_data_size = 0;
+     271                 :            : 
+     272                 :          1 :     response_size = sizeof(response);
+     273                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
+     274                 :            :                               m_libspdm_get_measurements_request1.nonce);
+     275                 :          1 :     status = libspdm_get_response_measurements(
+     276                 :            :         spdm_context, m_libspdm_get_measurements_request1_size,
+     277                 :            :         &m_libspdm_get_measurements_request1, &response_size, response);
+     278                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     279                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     280                 :          1 :     spdm_response = (void *)response;
+     281                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     282                 :            :                      SPDM_ERROR);
+     283                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     284                 :            :                      SPDM_ERROR_CODE_REQUEST_RESYNCH);
+     285                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     286                 :          1 :     assert_int_equal(spdm_context->response_state,
+     287                 :            :                      LIBSPDM_RESPONSE_STATE_NEED_RESYNC);
+     288                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     289                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+     290                 :            : #endif
+     291                 :          1 : }
+     292                 :            : 
+     293                 :            : #if LIBSPDM_RESPOND_IF_READY_SUPPORT
+     294                 :            : /**
+     295                 :            :  * Test 5: Force response_state = SPDM_RESPONSE_STATE_NOT_READY when asked GET_MEASUREMENTS
+     296                 :            :  * Expected Behavior: generate an ERROR_RESPONSE with code SPDM_ERROR_CODE_RESPONSE_NOT_READY
+     297                 :            :  **/
+     298                 :          1 : void libspdm_test_responder_measurements_case5(void **state)
+     299                 :            : {
+     300                 :            :     libspdm_return_t status;
+     301                 :            :     libspdm_test_context_t *spdm_test_context;
+     302                 :            :     libspdm_context_t *spdm_context;
+     303                 :            :     size_t response_size;
+     304                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     305                 :            :     spdm_measurements_response_t *spdm_response;
+     306                 :            :     spdm_error_data_response_not_ready_t *error_data;
+     307                 :            : 
+     308                 :          1 :     spdm_test_context = *state;
+     309                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     310                 :          1 :     spdm_test_context->case_id = 0x5;
+     311                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+     312                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     313                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NOT_READY;
+     314                 :          1 :     spdm_context->connection_info.connection_state =
+     315                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     316                 :          1 :     spdm_context->local_context.capability.flags |=
+     317                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+     318                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     319                 :            :         m_libspdm_use_hash_algo;
+     320                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     321                 :            :         m_libspdm_use_asym_algo;
+     322                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     323                 :            :         m_libspdm_use_measurement_spec;
+     324                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     325                 :            :         m_libspdm_use_measurement_hash_algo;
+     326                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+     327                 :          1 :     libspdm_secret_lib_meas_opaque_data_size = 0;
+     328                 :            : 
+     329                 :          1 :     response_size = sizeof(response);
+     330                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
+     331                 :            :                               m_libspdm_get_measurements_request1.nonce);
+     332                 :          1 :     status = libspdm_get_response_measurements(
+     333                 :            :         spdm_context, m_libspdm_get_measurements_request1_size,
+     334                 :            :         &m_libspdm_get_measurements_request1, &response_size, response);
+     335                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     336                 :          1 :     assert_int_equal(response_size,
+     337                 :            :                      sizeof(spdm_error_response_t) +
+     338                 :            :                      sizeof(spdm_error_data_response_not_ready_t));
+     339                 :          1 :     spdm_response = (void *)response;
+     340                 :          1 :     error_data = (spdm_error_data_response_not_ready_t
+     341                 :            :                   *)(&spdm_response->number_of_blocks);
+     342                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     343                 :            :                      SPDM_ERROR);
+     344                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     345                 :            :                      SPDM_ERROR_CODE_RESPONSE_NOT_READY);
+     346                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     347                 :          1 :     assert_int_equal(spdm_context->response_state,
+     348                 :            :                      LIBSPDM_RESPONSE_STATE_NOT_READY);
+     349                 :          1 :     assert_int_equal(error_data->request_code, SPDM_GET_MEASUREMENTS);
+     350                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     351                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+     352                 :            : #endif
+     353                 :          1 : }
+     354                 :            : #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
+     355                 :            : 
+     356                 :            : /**
+     357                 :            :  * Test 6: simulate wrong connection_state when asked GET_MEASUREMENTS
+     358                 :            :  *        (missing SPDM_GET_DIGESTS_RECEIVE_FLAG, SPDM_GET_CAPABILITIES_RECEIVE_FLAG and SPDM_NEGOTIATE_ALGORITHMS_RECEIVE_FLAG)
+     359                 :            :  * Expected Behavior: generate an ERROR_RESPONSE with code SPDM_ERROR_CODE_UNEXPECTED_REQUEST
+     360                 :            :  **/
+     361                 :          1 : void libspdm_test_responder_measurements_case6(void **state)
+     362                 :            : {
+     363                 :            :     libspdm_return_t status;
+     364                 :            :     libspdm_test_context_t *spdm_test_context;
+     365                 :            :     libspdm_context_t *spdm_context;
+     366                 :            :     size_t response_size;
+     367                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     368                 :            :     spdm_measurements_response_t *spdm_response;
+     369                 :            : 
+     370                 :          1 :     spdm_test_context = *state;
+     371                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     372                 :          1 :     spdm_test_context->case_id = 0x6;
+     373                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+     374                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     375                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+     376                 :          1 :     spdm_context->connection_info.connection_state =
+     377                 :            :         LIBSPDM_CONNECTION_STATE_NOT_STARTED;
+     378                 :          1 :     spdm_context->local_context.capability.flags |=
+     379                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+     380                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     381                 :            :         m_libspdm_use_hash_algo;
+     382                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     383                 :            :         m_libspdm_use_asym_algo;
+     384                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     385                 :            :         m_libspdm_use_measurement_spec;
+     386                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     387                 :            :         m_libspdm_use_measurement_hash_algo;
+     388                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+     389                 :          1 :     libspdm_secret_lib_meas_opaque_data_size = 0;
+     390                 :            : 
+     391                 :          1 :     response_size = sizeof(response);
+     392                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
+     393                 :            :                               m_libspdm_get_measurements_request1.nonce);
+     394                 :          1 :     status = libspdm_get_response_measurements(
+     395                 :            :         spdm_context, m_libspdm_get_measurements_request1_size,
+     396                 :            :         &m_libspdm_get_measurements_request1, &response_size, response);
+     397                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     398                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     399                 :          1 :     spdm_response = (void *)response;
+     400                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     401                 :            :                      SPDM_ERROR);
+     402                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     403                 :            :                      SPDM_ERROR_CODE_UNEXPECTED_REQUEST);
+     404                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     405                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     406                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+     407                 :            : #endif
+     408                 :          1 : }
+     409                 :            : 
+     410                 :            : /**
+     411                 :            :  * Test 7: Successful response to get a number of measurements with signature
+     412                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code, empty transcript.message_m, and correct response message size and fields
+     413                 :            :  **/
+     414                 :          1 : void libspdm_test_responder_measurements_case7(void **state)
+     415                 :            : {
+     416                 :            :     libspdm_return_t status;
+     417                 :            :     libspdm_test_context_t *spdm_test_context;
+     418                 :            :     libspdm_context_t *spdm_context;
+     419                 :            :     size_t response_size;
+     420                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     421                 :            :     spdm_measurements_response_t *spdm_response;
+     422                 :            :     size_t measurment_sig_size;
+     423                 :            : 
+     424                 :            :     bool result;
+     425                 :            :     uint32_t measurement_record_data_length;
+     426                 :            :     uint8_t *measurement_record_data;
+     427                 :            :     uint8_t *ptr;
+     428                 :            :     uint16_t opaque_length;
+     429                 :            :     void *signature;
+     430                 :            :     size_t signature_size;
+     431                 :            :     libspdm_session_info_t *session_info;
+     432                 :            :     void *data;
+     433                 :            :     size_t data_size;
+     434                 :            :     void *hash;
+     435                 :            :     size_t hash_size;
+     436                 :            : 
+     437                 :          1 :     spdm_test_context = *state;
+     438                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     439                 :          1 :     spdm_test_context->case_id = 0x7;
+     440                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+     441                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     442                 :          1 :     spdm_context->connection_info.connection_state =
+     443                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     444                 :          1 :     spdm_context->local_context.capability.flags |=
+     445                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+     446                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     447                 :            :         m_libspdm_use_hash_algo;
+     448                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     449                 :            :         m_libspdm_use_asym_algo;
+     450                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     451                 :            :         m_libspdm_use_measurement_spec;
+     452                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     453                 :            :         m_libspdm_use_measurement_hash_algo;
+     454                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+     455                 :          1 :     libspdm_secret_lib_meas_opaque_data_size = 0;
+     456                 :          1 :     measurment_sig_size = SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
+     457                 :          1 :                           libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+     458                 :            : 
+     459                 :          1 :     response_size = sizeof(response);
+     460                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
+     461                 :            :                               m_libspdm_get_measurements_request5.nonce);
+     462                 :          1 :     status = libspdm_get_response_measurements(
+     463                 :            :         spdm_context, m_libspdm_get_measurements_request5_size,
+     464                 :            :         &m_libspdm_get_measurements_request5, &response_size, response);
+     465                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     466                 :          1 :     assert_int_equal(response_size, sizeof(spdm_measurements_response_t) +
+     467                 :            :                      measurment_sig_size);
+     468                 :          1 :     spdm_response = (void *)response;
+     469                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     470                 :            :                      SPDM_MEASUREMENTS);
+     471                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     472                 :            :                      LIBSPDM_MEASUREMENT_BLOCK_NUMBER);
+     473                 :            : 
+     474                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     475                 :            :                                                     m_libspdm_use_asym_algo, &data,
+     476                 :            :                                                     &data_size,
+     477                 :            :                                                     &hash, &hash_size);
+     478                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     479                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+     480                 :            :         data_size;
+     481                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+     482                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+     483                 :            :                      data, data_size);
+     484                 :            : #else
+     485                 :          1 :     libspdm_hash_all(
+     486                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+     487                 :            :         data, data_size,
+     488                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+     489                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+     490                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+     491                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+     492                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+     493                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+     494                 :            :         data, data_size,
+     495                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+     496                 :            : #endif
+     497                 :            : 
+     498                 :          1 :     measurement_record_data_length = libspdm_read_uint24(spdm_response->measurement_record_length);
+     499                 :          1 :     measurement_record_data = (void *)(spdm_response + 1);
+     500                 :          1 :     ptr = measurement_record_data + measurement_record_data_length;
+     501                 :          1 :     ptr += SPDM_NONCE_SIZE;
+     502                 :          1 :     opaque_length = libspdm_read_uint16((const uint8_t *)ptr);
+     503                 :          1 :     ptr += sizeof(uint16_t);
+     504                 :          1 :     ptr += opaque_length;
+     505                 :          1 :     signature = ptr;
+     506                 :          1 :     signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+     507                 :          1 :     session_info = NULL;
+     508                 :            : 
+     509                 :          1 :     status = libspdm_append_message_m(spdm_context, session_info,
+     510                 :            :                                       &m_libspdm_get_measurements_request5,
+     511                 :            :                                       m_libspdm_get_measurements_request5_size);
+     512                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     513                 :            : 
+     514                 :          1 :     status = libspdm_append_message_m(spdm_context, session_info, spdm_response,
+     515                 :            :                                       response_size - signature_size);
+     516                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     517                 :            : 
+     518                 :          1 :     result = libspdm_verify_measurement_signature(
+     519                 :            :         spdm_context, session_info, signature, signature_size);
+     520                 :          1 :     assert_true(result);
+     521                 :            : 
+     522                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     523                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+     524                 :            : #endif
+     525                 :          1 : }
+     526                 :            : 
+     527                 :            : /**
+     528                 :            :  * Test 8: Successful response to get one measurement with signature
+     529                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code, empty transcript.message_m, and correct response message size and fields
+     530                 :            :  **/
+     531                 :          1 : void libspdm_test_responder_measurements_case8(void **state)
+     532                 :            : {
+     533                 :            :     libspdm_return_t status;
+     534                 :            :     libspdm_test_context_t *spdm_test_context;
+     535                 :            :     libspdm_context_t *spdm_context;
+     536                 :            :     size_t response_size;
+     537                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     538                 :            :     spdm_measurements_response_t *spdm_response;
+     539                 :            :     size_t measurment_sig_size;
+     540                 :            : 
+     541                 :          1 :     spdm_test_context = *state;
+     542                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     543                 :          1 :     spdm_test_context->case_id = 0x8;
+     544                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+     545                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     546                 :          1 :     spdm_context->connection_info.connection_state =
+     547                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     548                 :          1 :     spdm_context->local_context.capability.flags |=
+     549                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+     550                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     551                 :            :         m_libspdm_use_hash_algo;
+     552                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     553                 :            :         m_libspdm_use_asym_algo;
+     554                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     555                 :            :         m_libspdm_use_measurement_spec;
+     556                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     557                 :            :         m_libspdm_use_measurement_hash_algo;
+     558                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+     559                 :          1 :     libspdm_secret_lib_meas_opaque_data_size = 0;
+     560                 :          1 :     measurment_sig_size = SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
+     561                 :          1 :                           libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+     562                 :          1 :     response_size = sizeof(response);
+     563                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
+     564                 :            :                               m_libspdm_get_measurements_request3.nonce);
+     565                 :          1 :     status = libspdm_get_response_measurements(
+     566                 :            :         spdm_context, m_libspdm_get_measurements_request3_size,
+     567                 :            :         &m_libspdm_get_measurements_request3, &response_size, response);
+     568                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     569                 :          1 :     assert_int_equal(response_size,
+     570                 :            :                      sizeof(spdm_measurements_response_t) +
+     571                 :            :                      sizeof(spdm_measurement_block_dmtf_t) +
+     572                 :            :                      libspdm_get_measurement_hash_size(
+     573                 :            :                          m_libspdm_use_measurement_hash_algo) +
+     574                 :            :                      measurment_sig_size);
+     575                 :          1 :     spdm_response = (void *)response;
+     576                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     577                 :            :                      SPDM_MEASUREMENTS);
+     578                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     579                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+     580                 :            : #endif
+     581                 :          1 : }
+     582                 :            : 
+     583                 :            : /**
+     584                 :            :  * Test 9: Error case, Bad request size (sizeof(spdm_message_header_t)x) to get measurement number with signature
+     585                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code, empty transcript.message_m size, and Error message as response
+     586                 :            :  **/
+     587                 :          1 : void libspdm_test_responder_measurements_case9(void **state)
+     588                 :            : {
+     589                 :            :     libspdm_return_t status;
+     590                 :            :     libspdm_test_context_t *spdm_test_context;
+     591                 :            :     libspdm_context_t *spdm_context;
+     592                 :            :     size_t response_size;
+     593                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     594                 :            :     spdm_measurements_response_t *spdm_response;
+     595                 :            : 
+     596                 :          1 :     spdm_test_context = *state;
+     597                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     598                 :          1 :     spdm_test_context->case_id = 0x9;
+     599                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+     600                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     601                 :          1 :     spdm_context->connection_info.connection_state =
+     602                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     603                 :          1 :     spdm_context->local_context.capability.flags |=
+     604                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+     605                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     606                 :            :         m_libspdm_use_hash_algo;
+     607                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     608                 :            :         m_libspdm_use_asym_algo;
+     609                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     610                 :            :         m_libspdm_use_measurement_spec;
+     611                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     612                 :            :         m_libspdm_use_measurement_hash_algo;
+     613                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+     614                 :          1 :     libspdm_secret_lib_meas_opaque_data_size = 0;
+     615                 :            : 
+     616                 :          1 :     response_size = sizeof(response);
+     617                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
+     618                 :            :                               m_libspdm_get_measurements_request4.nonce);
+     619                 :          1 :     status = libspdm_get_response_measurements(
+     620                 :            :         spdm_context, m_libspdm_get_measurements_request4_size,
+     621                 :            :         &m_libspdm_get_measurements_request4, &response_size, response);
+     622                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     623                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     624                 :          1 :     spdm_response = (void *)response;
+     625                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     626                 :            :                      SPDM_ERROR);
+     627                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     628                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+     629                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     630                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     631                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+     632                 :            : #endif
+     633                 :          1 : }
+     634                 :            : 
+     635                 :            : /**
+     636                 :            :  * Test 10: Successful response to get one measurement without signature
+     637                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code, correct transcript.message_m size, and correct response message size and fields
+     638                 :            :  **/
+     639                 :          1 : void libspdm_test_responder_measurements_case10(void **state)
+     640                 :            : {
+     641                 :            :     libspdm_return_t status;
+     642                 :            :     libspdm_test_context_t *spdm_test_context;
+     643                 :            :     libspdm_context_t *spdm_context;
+     644                 :            :     size_t response_size;
+     645                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     646                 :            :     spdm_measurements_response_t *spdm_response;
+     647                 :            : 
+     648                 :          1 :     spdm_test_context = *state;
+     649                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     650                 :          1 :     spdm_test_context->case_id = 0xA;
+     651                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+     652                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     653                 :          1 :     spdm_context->connection_info.connection_state =
+     654                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     655                 :          1 :     spdm_context->local_context.capability.flags |=
+     656                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+     657                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     658                 :            :         m_libspdm_use_hash_algo;
+     659                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     660                 :            :         m_libspdm_use_asym_algo;
+     661                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     662                 :            :         m_libspdm_use_measurement_spec;
+     663                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     664                 :            :         m_libspdm_use_measurement_hash_algo;
+     665                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+     666                 :          1 :     libspdm_secret_lib_meas_opaque_data_size = 0;
+     667                 :            : 
+     668                 :          1 :     response_size = sizeof(response);
+     669                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
+     670                 :            :                               m_libspdm_get_measurements_request6.nonce);
+     671                 :          1 :     status = libspdm_get_response_measurements(
+     672                 :            :         spdm_context, m_libspdm_get_measurements_request6_size,
+     673                 :            :         &m_libspdm_get_measurements_request6, &response_size, response);
+     674                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     675                 :          1 :     assert_int_equal(response_size,
+     676                 :            :                      sizeof(spdm_measurements_response_t) +
+     677                 :            :                      sizeof(spdm_measurement_block_dmtf_t) +
+     678                 :            :                      libspdm_get_measurement_hash_size(
+     679                 :            :                          m_libspdm_use_measurement_hash_algo) + SPDM_NONCE_SIZE +
+     680                 :            :                      sizeof(uint16_t));
+     681                 :          1 :     spdm_response = (void *)response;
+     682                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     683                 :            :                      SPDM_MEASUREMENTS);
+     684                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     685                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
+     686                 :            :                      m_libspdm_get_measurements_request6_size +
+     687                 :            :                      sizeof(spdm_measurements_response_t) +
+     688                 :            :                      sizeof(spdm_measurement_block_dmtf_t) +
+     689                 :            :                      libspdm_get_measurement_hash_size(
+     690                 :            :                          m_libspdm_use_measurement_hash_algo) + SPDM_NONCE_SIZE +
+     691                 :            :                      sizeof(uint16_t));
+     692                 :            : #endif
+     693                 :          1 : }
+     694                 :            : 
+     695                 :            : /**
+     696                 :            :  * Test 11: Successful response to get all measurements with signature
+     697                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code, empty transcript.message_m, and correct response message size and fields
+     698                 :            :  **/
+     699                 :          1 : void libspdm_test_responder_measurements_case11(void **state)
+     700                 :            : {
+     701                 :            :     libspdm_return_t status;
+     702                 :            :     libspdm_test_context_t *spdm_test_context;
+     703                 :            :     libspdm_context_t *spdm_context;
+     704                 :            :     size_t response_size;
+     705                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     706                 :            :     spdm_measurements_response_t *spdm_response;
+     707                 :            :     size_t measurment_sig_size;
+     708                 :            : 
+     709                 :          1 :     spdm_test_context = *state;
+     710                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     711                 :          1 :     spdm_test_context->case_id = 0xB;
+     712                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+     713                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     714                 :          1 :     spdm_context->connection_info.connection_state =
+     715                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     716                 :          1 :     spdm_context->local_context.capability.flags |=
+     717                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+     718                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     719                 :            :         m_libspdm_use_hash_algo;
+     720                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     721                 :            :         m_libspdm_use_asym_algo;
+     722                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     723                 :            :         m_libspdm_use_measurement_spec;
+     724                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     725                 :            :         m_libspdm_use_measurement_hash_algo;
+     726                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+     727                 :          1 :     libspdm_secret_lib_meas_opaque_data_size = 0;
+     728                 :          1 :     measurment_sig_size = SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
+     729                 :          1 :                           libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+     730                 :            : 
+     731                 :          1 :     response_size = sizeof(response);
+     732                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
+     733                 :            :                               m_libspdm_get_measurements_request8.nonce);
+     734                 :          1 :     status = libspdm_get_response_measurements(
+     735                 :            :         spdm_context, m_libspdm_get_measurements_request8_size,
+     736                 :            :         &m_libspdm_get_measurements_request8, &response_size, response);
+     737                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     738                 :          1 :     assert_int_equal(response_size,
+     739                 :            :                      sizeof(spdm_measurements_response_t) +
+     740                 :            :                      LIBSPDM_MEASUREMENT_BLOCK_HASH_NUMBER *
+     741                 :            :                      (sizeof(spdm_measurement_block_dmtf_t) +
+     742                 :            :                       libspdm_get_measurement_hash_size(
+     743                 :            :                           m_libspdm_use_measurement_hash_algo)) +
+     744                 :            :                      (sizeof(spdm_measurement_block_dmtf_t) +
+     745                 :            :                       sizeof(spdm_measurements_secure_version_number_t)) +
+     746                 :            :                      (sizeof(spdm_measurement_block_dmtf_t) +
+     747                 :            :                       libspdm_get_measurement_hash_size(
+     748                 :            :                           m_libspdm_use_measurement_hash_algo)) +
+     749                 :            :                      (sizeof(spdm_measurement_block_dmtf_t) +
+     750                 :            :                       LIBSPDM_MEASUREMENT_MANIFEST_SIZE) +
+     751                 :            :                      (sizeof(spdm_measurement_block_dmtf_t) +
+     752                 :            :                       sizeof(spdm_measurements_device_mode_t)) +
+     753                 :            :                      measurment_sig_size);
+     754                 :          1 :     spdm_response = (void *)response;
+     755                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     756                 :            :                      SPDM_MEASUREMENTS);
+     757                 :          1 :     assert_int_equal(spdm_response->number_of_blocks,
+     758                 :            :                      LIBSPDM_MEASUREMENT_BLOCK_NUMBER);
+     759                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     760                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+     761                 :            : #endif
+     762                 :          1 : }
+     763                 :            : 
+     764                 :            : /**
+     765                 :            :  * Test 12: Successful response to get all measurements without signature
+     766                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code, correct transcript.message_m size, and correct response message size and fields
+     767                 :            :  **/
+     768                 :          1 : void libspdm_test_responder_measurements_case12(void **state)
+     769                 :            : {
+     770                 :            :     libspdm_return_t status;
+     771                 :            :     libspdm_test_context_t *spdm_test_context;
+     772                 :            :     libspdm_context_t *spdm_context;
+     773                 :            :     size_t response_size;
+     774                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     775                 :            :     spdm_measurements_response_t *spdm_response;
+     776                 :            : 
+     777                 :          1 :     spdm_test_context = *state;
+     778                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     779                 :          1 :     spdm_test_context->case_id = 0xC;
+     780                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+     781                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     782                 :          1 :     spdm_context->connection_info.connection_state =
+     783                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     784                 :          1 :     spdm_context->local_context.capability.flags |=
+     785                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+     786                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     787                 :            :         m_libspdm_use_hash_algo;
+     788                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     789                 :            :         m_libspdm_use_asym_algo;
+     790                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     791                 :            :         m_libspdm_use_measurement_spec;
+     792                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     793                 :            :         m_libspdm_use_measurement_hash_algo;
+     794                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+     795                 :          1 :     libspdm_secret_lib_meas_opaque_data_size = 0;
+     796                 :            : 
+     797                 :          1 :     response_size = sizeof(response);
+     798                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
+     799                 :            :                               m_libspdm_get_measurements_request7.nonce);
+     800                 :          1 :     status = libspdm_get_response_measurements(
+     801                 :            :         spdm_context, m_libspdm_get_measurements_request7_size,
+     802                 :            :         &m_libspdm_get_measurements_request7, &response_size, response);
+     803                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     804                 :          1 :     assert_int_equal(response_size,
+     805                 :            :                      sizeof(spdm_measurements_response_t) +
+     806                 :            :                      LIBSPDM_MEASUREMENT_BLOCK_HASH_NUMBER *
+     807                 :            :                      (sizeof(spdm_measurement_block_dmtf_t) +
+     808                 :            :                       libspdm_get_measurement_hash_size(
+     809                 :            :                           m_libspdm_use_measurement_hash_algo)) +
+     810                 :            :                      (sizeof(spdm_measurement_block_dmtf_t) +
+     811                 :            :                       sizeof(spdm_measurements_secure_version_number_t)) +
+     812                 :            :                      (sizeof(spdm_measurement_block_dmtf_t) +
+     813                 :            :                       libspdm_get_measurement_hash_size(
+     814                 :            :                           m_libspdm_use_measurement_hash_algo)) +
+     815                 :            :                      (sizeof(spdm_measurement_block_dmtf_t) +
+     816                 :            :                       LIBSPDM_MEASUREMENT_MANIFEST_SIZE) +
+     817                 :            :                      (sizeof(spdm_measurement_block_dmtf_t) +
+     818                 :            :                       sizeof(spdm_measurements_device_mode_t)) +
+     819                 :            :                      SPDM_NONCE_SIZE + sizeof(uint16_t));
+     820                 :          1 :     spdm_response = (void *)response;
+     821                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     822                 :            :                      SPDM_MEASUREMENTS);
+     823                 :          1 :     assert_int_equal(spdm_response->number_of_blocks,
+     824                 :            :                      LIBSPDM_MEASUREMENT_BLOCK_NUMBER);
+     825                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     826                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
+     827                 :            :                      m_libspdm_get_measurements_request7_size +
+     828                 :            :                      sizeof(spdm_measurements_response_t) +
+     829                 :            :                      LIBSPDM_MEASUREMENT_BLOCK_HASH_NUMBER *
+     830                 :            :                      (sizeof(spdm_measurement_block_dmtf_t) +
+     831                 :            :                       libspdm_get_measurement_hash_size(
+     832                 :            :                           m_libspdm_use_measurement_hash_algo)) +
+     833                 :            :                      (sizeof(spdm_measurement_block_dmtf_t) +
+     834                 :            :                       sizeof(spdm_measurements_secure_version_number_t)) +
+     835                 :            :                      (sizeof(spdm_measurement_block_dmtf_t) +
+     836                 :            :                       libspdm_get_measurement_hash_size(
+     837                 :            :                           m_libspdm_use_measurement_hash_algo)) +
+     838                 :            :                      (sizeof(spdm_measurement_block_dmtf_t) +
+     839                 :            :                       LIBSPDM_MEASUREMENT_MANIFEST_SIZE) +
+     840                 :            :                      (sizeof(spdm_measurement_block_dmtf_t) +
+     841                 :            :                       sizeof(spdm_measurements_device_mode_t)) +
+     842                 :            :                      SPDM_NONCE_SIZE + sizeof(uint16_t));
+     843                 :            : #endif
+     844                 :          1 : }
+     845                 :            : 
+     846                 :            : /**
+     847                 :            :  * Test 13:
+     848                 :            :  * Expected Behavior:
+     849                 :            :  **/
+     850                 :          1 : void libspdm_test_responder_measurements_case13(void **state)
+     851                 :            : {
+     852                 :          1 : }
+     853                 :            : 
+     854                 :            : /**
+     855                 :            :  * Test 14: Error case, signature was required, but there is no nonce and/or slotID
+     856                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code, empty transcript.message_m size, and Error message as response
+     857                 :            :  **/
+     858                 :          1 : void libspdm_test_responder_measurements_case14(void **state)
+     859                 :            : {
+     860                 :            :     libspdm_return_t status;
+     861                 :            :     libspdm_test_context_t *spdm_test_context;
+     862                 :            :     libspdm_context_t *spdm_context;
+     863                 :            :     size_t response_size;
+     864                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     865                 :            :     spdm_measurements_response_t *spdm_response;
+     866                 :            :     uint16_t TestMsgSizes[3];
+     867                 :            : 
+     868                 :          1 :     TestMsgSizes[0] =
+     869                 :          1 :         (uint16_t)(m_libspdm_get_measurements_request10_size -
+     870                 :            :                    sizeof(m_libspdm_get_measurements_request10.slot_id_param) -
+     871                 :            :                    sizeof(m_libspdm_get_measurements_request10.nonce));
+     872                 :          1 :     TestMsgSizes[1] =
+     873                 :          1 :         (uint16_t)(m_libspdm_get_measurements_request10_size -
+     874                 :            :                    sizeof(m_libspdm_get_measurements_request10.slot_id_param));
+     875                 :          1 :     TestMsgSizes[2] =
+     876                 :          1 :         (uint16_t)(m_libspdm_get_measurements_request10_size -
+     877                 :            :                    sizeof(m_libspdm_get_measurements_request10.nonce));
+     878                 :            : 
+     879                 :          1 :     spdm_test_context = *state;
+     880                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     881                 :          1 :     spdm_test_context->case_id = 0xE;
+     882                 :          1 :     spdm_context->connection_info.connection_state =
+     883                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     884                 :          1 :     spdm_context->local_context.capability.flags = 0;
+     885                 :          1 :     spdm_context->local_context.capability.flags |=
+     886                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+     887                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     888                 :            :         m_libspdm_use_hash_algo;
+     889                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     890                 :            :         m_libspdm_use_asym_algo;
+     891                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     892                 :            :         m_libspdm_use_measurement_hash_algo;
+     893                 :            : 
+     894                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     895                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     896                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+     897                 :          1 :     libspdm_secret_lib_meas_opaque_data_size = 0;
+     898                 :            : 
+     899                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
+     900                 :            :                               m_libspdm_get_measurements_request10.nonce);
+     901         [ +  + ]:          4 :     for (int i = 0; i < sizeof(TestMsgSizes) / sizeof(TestMsgSizes[0]);
+     902                 :          3 :          i++) {
+     903                 :          3 :         response_size = sizeof(response);
+     904                 :          3 :         status = libspdm_get_response_measurements(
+     905                 :          3 :             spdm_context, TestMsgSizes[i],
+     906                 :            :             &m_libspdm_get_measurements_request10, &response_size,
+     907                 :            :             response);
+     908                 :          3 :         assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     909                 :          3 :         assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     910                 :          3 :         spdm_response = (void *)response;
+     911                 :          3 :         assert_int_equal(spdm_response->header.request_response_code,
+     912                 :            :                          SPDM_ERROR);
+     913                 :          3 :         assert_int_equal(spdm_response->header.param1,
+     914                 :            :                          SPDM_ERROR_CODE_INVALID_REQUEST);
+     915                 :          3 :         assert_int_equal(spdm_response->header.param2, 0);
+     916                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     917                 :            :         assert_int_equal(spdm_context->transcript.message_m.buffer_size,
+     918                 :            :                          0);
+     919                 :            : #endif
+     920                 :            :     }
+     921                 :          1 : }
+     922                 :            : 
+     923                 :            : /**
+     924                 :            :  * Test 15: Error case, meas_cap = 01b, but signature was requested (request message includes nonce and slotID)
+     925                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code, empty transcript.message_m size, and Error message as response
+     926                 :            :  **/
+     927                 :          1 : void libspdm_test_responder_measurements_case15(void **state)
+     928                 :            : {
+     929                 :            :     libspdm_return_t status;
+     930                 :            :     libspdm_test_context_t *spdm_test_context;
+     931                 :            :     libspdm_context_t *spdm_context;
+     932                 :            :     size_t response_size;
+     933                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     934                 :            :     spdm_measurements_response_t *spdm_response;
+     935                 :            :     /* size_t                measurment_sig_size;*/
+     936                 :            : 
+     937                 :          1 :     spdm_test_context = *state;
+     938                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     939                 :          1 :     spdm_test_context->case_id = 0xF;
+     940                 :          1 :     spdm_context->connection_info.connection_state =
+     941                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     942                 :          1 :     spdm_context->local_context.capability.flags = 0;
+     943                 :          1 :     spdm_context->local_context.capability.flags |=
+     944                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG;
+     945                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     946                 :            :         m_libspdm_use_hash_algo;
+     947                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     948                 :            :         m_libspdm_use_asym_algo;
+     949                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     950                 :            :         m_libspdm_use_measurement_hash_algo;
+     951                 :            : 
+     952                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     953                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     954                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+     955                 :          1 :     libspdm_secret_lib_meas_opaque_data_size = 0;
+     956                 :            :     /* measurment_sig_size = SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 + libspdm_get_asym_signature_size (m_libspdm_use_asym_algo);*/
+     957                 :            : 
+     958                 :          1 :     response_size = sizeof(response);
+     959                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
+     960                 :            :                               m_libspdm_get_measurements_request10.nonce);
+     961                 :          1 :     status = libspdm_get_response_measurements(
+     962                 :            :         spdm_context, m_libspdm_get_measurements_request10_size,
+     963                 :            :         &m_libspdm_get_measurements_request10, &response_size, response);
+     964                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     965                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     966                 :          1 :     spdm_response = (void *)response;
+     967                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     968                 :            :                      SPDM_ERROR);
+     969                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     970                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+     971                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     972                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     973                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+     974                 :            : #endif
+     975                 :          1 : }
+     976                 :            : 
+     977                 :            : /**
+     978                 :            :  * Test 16: Error case, meas_cap = 01b, but signature was requested (request message does not include nonce and slotID)
+     979                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code, empty transcript.message_m size, and Error message as response
+     980                 :            :  **/
+     981                 :          1 : void libspdm_test_responder_measurements_case16(void **state)
+     982                 :            : {
+     983                 :            :     libspdm_return_t status;
+     984                 :            :     libspdm_test_context_t *spdm_test_context;
+     985                 :            :     libspdm_context_t *spdm_context;
+     986                 :            :     size_t response_size;
+     987                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     988                 :            :     spdm_measurements_response_t *spdm_response;
+     989                 :            :     /* size_t                measurment_sig_size;*/
+     990                 :            : 
+     991                 :          1 :     spdm_test_context = *state;
+     992                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     993                 :          1 :     spdm_test_context->case_id = 0x10;
+     994                 :          1 :     spdm_context->connection_info.connection_state =
+     995                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     996                 :          1 :     spdm_context->local_context.capability.flags = 0;
+     997                 :          1 :     spdm_context->local_context.capability.flags |=
+     998                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG;
+     999                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1000                 :            :         m_libspdm_use_hash_algo;
+    1001                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1002                 :            :         m_libspdm_use_asym_algo;
+    1003                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1004                 :            :         m_libspdm_use_measurement_hash_algo;
+    1005                 :            : 
+    1006                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1007                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1008                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    1009                 :          1 :     libspdm_secret_lib_meas_opaque_data_size = 0;
+    1010                 :            :     /* measurment_sig_size = SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 + libspdm_get_asym_signature_size (m_libspdm_use_asym_algo);*/
+    1011                 :            : 
+    1012                 :          1 :     response_size = sizeof(response);
+    1013                 :          1 :     status = libspdm_get_response_measurements(
+    1014                 :            :         spdm_context, m_libspdm_get_measurements_request9_size,
+    1015                 :            :         &m_libspdm_get_measurements_request10, &response_size, response);
+    1016                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1017                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1018                 :          1 :     spdm_response = (void *)response;
+    1019                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1020                 :            :                      SPDM_ERROR);
+    1021                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1022                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+    1023                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1024                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1025                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+    1026                 :            : #endif
+    1027                 :          1 : }
+    1028                 :            : 
+    1029                 :            : /**
+    1030                 :            :  * Test 17: Error case, meas_cap = 00
+    1031                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code, empty transcript.message_m size, and Error message as response
+    1032                 :            :  **/
+    1033                 :          1 : void libspdm_test_responder_measurements_case17(void **state)
+    1034                 :            : {
+    1035                 :            :     libspdm_return_t status;
+    1036                 :            :     libspdm_test_context_t *spdm_test_context;
+    1037                 :            :     libspdm_context_t *spdm_context;
+    1038                 :            :     size_t response_size;
+    1039                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1040                 :            :     spdm_measurements_response_t *spdm_response;
+    1041                 :            :     /* size_t                measurment_sig_size;*/
+    1042                 :            : 
+    1043                 :          1 :     spdm_test_context = *state;
+    1044                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1045                 :          1 :     spdm_test_context->case_id = 0x11;
+    1046                 :          1 :     spdm_context->connection_info.connection_state =
+    1047                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    1048                 :          1 :     spdm_context->local_context.capability.flags = 0;
+    1049                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1050                 :            :         m_libspdm_use_hash_algo;
+    1051                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1052                 :            :         m_libspdm_use_asym_algo;
+    1053                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1054                 :            :         m_libspdm_use_measurement_hash_algo;
+    1055                 :            : 
+    1056                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1057                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1058                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    1059                 :          1 :     libspdm_secret_lib_meas_opaque_data_size = 0;
+    1060                 :            :     /* measurment_sig_size = SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 + libspdm_get_asym_signature_size (m_libspdm_use_asym_algo);*/
+    1061                 :            : 
+    1062                 :          1 :     response_size = sizeof(response);
+    1063                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
+    1064                 :            :                               m_libspdm_get_measurements_request9.nonce);
+    1065                 :          1 :     status = libspdm_get_response_measurements(
+    1066                 :            :         spdm_context, m_libspdm_get_measurements_request9_size,
+    1067                 :            :         &m_libspdm_get_measurements_request9, &response_size, response);
+    1068                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1069                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1070                 :          1 :     spdm_response = (void *)response;
+    1071                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1072                 :            :                      SPDM_ERROR);
+    1073                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1074                 :            :                      SPDM_ERROR_CODE_UNSUPPORTED_REQUEST);
+    1075                 :          1 :     assert_int_equal(
+    1076                 :            :         spdm_response->header.param2,
+    1077                 :            :         m_libspdm_get_measurements_request10.header.request_response_code);
+    1078                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1079                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+    1080                 :            : #endif
+    1081                 :          1 : }
+    1082                 :            : 
+    1083                 :            : /**
+    1084                 :            :  * Test 18: Successful response to get one measurement with signature, SlotId different from default
+    1085                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code, empty transcript.message_m, and correct response message size and fields
+    1086                 :            :  **/
+    1087                 :          1 : void libspdm_test_responder_measurements_case18(void **state)
+    1088                 :            : {
+    1089                 :            :     libspdm_return_t status;
+    1090                 :            :     libspdm_test_context_t *spdm_test_context;
+    1091                 :            :     libspdm_context_t *spdm_context;
+    1092                 :            :     size_t response_size;
+    1093                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1094                 :            :     spdm_measurements_response_t *spdm_response;
+    1095                 :            :     void *data;
+    1096                 :            :     size_t data_size;
+    1097                 :            :     size_t measurment_sig_size;
+    1098                 :            : 
+    1099                 :          1 :     spdm_test_context = *state;
+    1100                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1101                 :          1 :     spdm_test_context->case_id = 0x12;
+    1102                 :          1 :     spdm_context->connection_info.connection_state =
+    1103                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    1104                 :          1 :     spdm_context->local_context.capability.flags |=
+    1105                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    1106                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1107                 :            :         m_libspdm_use_hash_algo;
+    1108                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1109                 :            :         m_libspdm_use_asym_algo;
+    1110                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1111                 :            :         m_libspdm_use_measurement_hash_algo;
+    1112                 :            : 
+    1113                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1114                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1115                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    1116                 :          1 :     libspdm_secret_lib_meas_opaque_data_size = 0;
+    1117                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1118                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    1119                 :            :                                                     &data_size, NULL, NULL);
+    1120                 :          1 :     measurment_sig_size = SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
+    1121                 :          1 :                           libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    1122         [ +  + ]:          9 :     for (int i = 0; i < SPDM_MAX_SLOT_COUNT; i++) {
+    1123                 :          8 :         spdm_context->local_context.local_cert_chain_provision_size[i] =
+    1124                 :            :             data_size;
+    1125                 :          8 :         spdm_context->local_context.local_cert_chain_provision[i] =
+    1126                 :            :             data;
+    1127                 :            :     }
+    1128                 :            : 
+    1129                 :          1 :     response_size = sizeof(response);
+    1130                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
+    1131                 :            :                               m_libspdm_get_measurements_request11.nonce);
+    1132                 :          1 :     status = libspdm_get_response_measurements(
+    1133                 :            :         spdm_context, m_libspdm_get_measurements_request11_size,
+    1134                 :            :         &m_libspdm_get_measurements_request11, &response_size, response);
+    1135                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1136                 :          1 :     assert_int_equal(response_size,
+    1137                 :            :                      sizeof(spdm_measurements_response_t) +
+    1138                 :            :                      sizeof(spdm_measurement_block_dmtf_t) +
+    1139                 :            :                      libspdm_get_measurement_hash_size(
+    1140                 :            :                          m_libspdm_use_measurement_hash_algo) +
+    1141                 :            :                      measurment_sig_size);
+    1142                 :          1 :     spdm_response = (void *)response;
+    1143                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1144                 :            :                      SPDM_MEASUREMENTS);
+    1145                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1146                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+    1147                 :            : #endif
+    1148                 :          1 :     assert_int_equal(m_libspdm_get_measurements_request11.slot_id_param,
+    1149                 :            :                      spdm_response->header.param2);
+    1150                 :            : 
+    1151                 :          1 :     free(data);
+    1152                 :          1 : }
+    1153                 :            : 
+    1154                 :            : /**
+    1155                 :            :  * Test 19: Error case, invalid SlotId parameter (SlotId >= SPDM_MAX_SLOT_COUNT)
+    1156                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code, empty transcript.message_m size, and Error message as response
+    1157                 :            :  **/
+    1158                 :          1 : void libspdm_test_responder_measurements_case19(void **state)
+    1159                 :            : {
+    1160                 :            :     libspdm_return_t status;
+    1161                 :            :     libspdm_test_context_t *spdm_test_context;
+    1162                 :            :     libspdm_context_t *spdm_context;
+    1163                 :            :     size_t response_size;
+    1164                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1165                 :            :     spdm_measurements_response_t *spdm_response;
+    1166                 :            :     /* size_t                measurment_sig_size;*/
+    1167                 :            : 
+    1168                 :          1 :     spdm_test_context = *state;
+    1169                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1170                 :          1 :     spdm_test_context->case_id = 0x13;
+    1171                 :          1 :     spdm_context->connection_info.connection_state =
+    1172                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    1173                 :          1 :     spdm_context->local_context.capability.flags |=
+    1174                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    1175                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1176                 :            :         m_libspdm_use_hash_algo;
+    1177                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1178                 :            :         m_libspdm_use_asym_algo;
+    1179                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1180                 :            :         m_libspdm_use_measurement_hash_algo;
+    1181                 :            : 
+    1182                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1183                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1184                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    1185                 :          1 :     libspdm_secret_lib_meas_opaque_data_size = 0;
+    1186                 :            :     /* measurment_sig_size = SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 + libspdm_get_asym_signature_size (m_libspdm_use_asym_algo);*/
+    1187                 :            : 
+    1188                 :          1 :     response_size = sizeof(response);
+    1189                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
+    1190                 :            :                               m_libspdm_get_measurements_request12.nonce);
+    1191                 :          1 :     status = libspdm_get_response_measurements(
+    1192                 :            :         spdm_context, m_libspdm_get_measurements_request12_size,
+    1193                 :            :         &m_libspdm_get_measurements_request12, &response_size, response);
+    1194                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1195                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1196                 :          1 :     spdm_response = (void *)response;
+    1197                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1198                 :            :                      SPDM_ERROR);
+    1199                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1200                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+    1201                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1202                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1203                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+    1204                 :            : #endif
+    1205                 :          1 : }
+    1206                 :            : 
+    1207                 :            : /**
+    1208                 :            :  * Test 21: Error case, request a measurement index not found
+    1209                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code, empty transcript.message_m size, and Error message as response
+    1210                 :            :  **/
+    1211                 :          1 : void libspdm_test_responder_measurements_case21(void **state)
+    1212                 :            : {
+    1213                 :            :     libspdm_return_t status;
+    1214                 :            :     libspdm_test_context_t *spdm_test_context;
+    1215                 :            :     libspdm_context_t *spdm_context;
+    1216                 :            :     size_t response_size;
+    1217                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1218                 :            :     spdm_measurements_response_t *spdm_response;
+    1219                 :            : 
+    1220                 :          1 :     spdm_test_context = *state;
+    1221                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1222                 :          1 :     spdm_test_context->case_id = 0x15;
+    1223                 :          1 :     spdm_context->connection_info.connection_state =
+    1224                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    1225                 :          1 :     spdm_context->local_context.capability.flags |=
+    1226                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    1227                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1228                 :            :         m_libspdm_use_hash_algo;
+    1229                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1230                 :            :         m_libspdm_use_asym_algo;
+    1231                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1232                 :            :         m_libspdm_use_measurement_hash_algo;
+    1233                 :            : 
+    1234                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1235                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1236                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    1237                 :          1 :     libspdm_secret_lib_meas_opaque_data_size = 0;
+    1238                 :            : 
+    1239                 :          1 :     response_size = sizeof(response);
+    1240                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
+    1241                 :            :                               m_libspdm_get_measurements_request13.nonce);
+    1242                 :          1 :     status = libspdm_get_response_measurements(
+    1243                 :            :         spdm_context, m_libspdm_get_measurements_request13_size,
+    1244                 :            :         &m_libspdm_get_measurements_request13, &response_size, response);
+    1245                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1246                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1247                 :          1 :     spdm_response = (void *)response;
+    1248                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1249                 :            :                      SPDM_ERROR);
+    1250                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1251                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+    1252                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1253                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1254                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+    1255                 :            : #endif
+    1256                 :          1 : }
+    1257                 :            : 
+    1258                 :            : /**
+    1259                 :            :  * Test 22: request a large number of measurements before requesting a singed response
+    1260                 :            :  * Expected Behavior: while transcript.message_m is not full, get a RETURN_SUCCESS return code, empty transcript.message_m, and correct response message size and fields
+    1261                 :            :  *                    if transcript.message_m has no more room, an error response is expected
+    1262                 :            :  **/
+    1263                 :          1 : void libspdm_test_responder_measurements_case22(void **state)
+    1264                 :            : {
+    1265                 :            :     libspdm_return_t status;
+    1266                 :            :     libspdm_test_context_t *spdm_test_context;
+    1267                 :            :     libspdm_context_t *spdm_context;
+    1268                 :            :     size_t response_size;
+    1269                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1270                 :            :     spdm_measurements_response_t *spdm_response;
+    1271                 :            :     size_t NumberOfMessages;
+    1272                 :            : #define TOTAL_MESSAGES 100
+    1273                 :            : 
+    1274                 :          1 :     spdm_test_context = *state;
+    1275                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1276                 :          1 :     spdm_test_context->case_id = 0x16;
+    1277                 :          1 :     spdm_context->connection_info.connection_state =
+    1278                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    1279                 :          1 :     spdm_context->local_context.capability.flags |=
+    1280                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    1281                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1282                 :            :         m_libspdm_use_hash_algo;
+    1283                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1284                 :            :         m_libspdm_use_asym_algo;
+    1285                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1286                 :            :         m_libspdm_use_measurement_hash_algo;
+    1287                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    1288                 :            :         m_libspdm_use_measurement_spec;
+    1289                 :            : 
+    1290                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1291                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1292                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    1293                 :          1 :     libspdm_secret_lib_meas_opaque_data_size = 0;
+    1294                 :            : 
+    1295         [ +  + ]:        101 :     for (NumberOfMessages = 1; NumberOfMessages <= TOTAL_MESSAGES; NumberOfMessages++) {
+    1296                 :        100 :         libspdm_get_random_number(SPDM_NONCE_SIZE,
+    1297                 :            :                                   m_libspdm_get_measurements_request9.nonce);
+    1298                 :        100 :         response_size = sizeof(response);
+    1299                 :        100 :         status = libspdm_get_response_measurements(
+    1300                 :            :             spdm_context, m_libspdm_get_measurements_request9_size,
+    1301                 :            :             &m_libspdm_get_measurements_request9, &response_size,
+    1302                 :            :             response);
+    1303                 :        100 :         assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1304                 :        100 :         spdm_response = (void *)response;
+    1305         [ +  - ]:        100 :         if (spdm_response->header.request_response_code ==
+    1306                 :            :             SPDM_MEASUREMENTS) {
+    1307                 :        100 :             assert_int_equal(
+    1308                 :            :                 spdm_response->header.request_response_code,
+    1309                 :            :                 SPDM_MEASUREMENTS);
+    1310                 :        100 :             assert_int_equal(
+    1311                 :            :                 response_size,
+    1312                 :            :                 sizeof(spdm_measurements_response_t) +
+    1313                 :            :                 sizeof(spdm_measurement_block_dmtf_t) +
+    1314                 :            :                 libspdm_get_measurement_hash_size(
+    1315                 :            :                     m_libspdm_use_measurement_hash_algo) + SPDM_NONCE_SIZE +
+    1316                 :            :                 sizeof(uint16_t));
+    1317                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1318                 :            :             assert_int_equal(
+    1319                 :            :                 spdm_context->transcript.message_m.buffer_size,
+    1320                 :            :                 NumberOfMessages *
+    1321                 :            :                 (m_libspdm_get_measurements_request9_size +
+    1322                 :            :                  sizeof(spdm_measurements_response_t) +
+    1323                 :            :                  sizeof(spdm_measurement_block_dmtf_t) +
+    1324                 :            :                  libspdm_get_measurement_hash_size(
+    1325                 :            :                      m_libspdm_use_measurement_hash_algo) + SPDM_NONCE_SIZE +
+    1326                 :            :                  sizeof(uint16_t)));
+    1327                 :            : #endif
+    1328                 :            :         } else {
+    1329                 :          0 :             assert_int_equal(
+    1330                 :            :                 spdm_response->header.request_response_code,
+    1331                 :            :                 SPDM_ERROR);
+    1332                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1333                 :            :             assert_int_equal(
+    1334                 :            :                 spdm_context->transcript.message_m.buffer_size,
+    1335                 :            :                 0);
+    1336                 :            : #endif
+    1337                 :          0 :             break;
+    1338                 :            :         }
+    1339                 :            :     }
+    1340                 :          1 : }
+    1341                 :            : 
+    1342                 :            : /**
+    1343                 :            :  * Test 23: Successful response to get a session based measurement with signature
+    1344                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code, with an empty session_transcript.message_m
+    1345                 :            :  **/
+    1346                 :          1 : void libspdm_test_responder_measurements_case23(void **state)
+    1347                 :            : {
+    1348                 :            :     libspdm_return_t status;
+    1349                 :            :     libspdm_test_context_t *spdm_test_context;
+    1350                 :            :     libspdm_context_t *spdm_context;
+    1351                 :            :     size_t response_size;
+    1352                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1353                 :            :     spdm_measurements_response_t *spdm_response;
+    1354                 :            :     size_t measurment_sig_size;
+    1355                 :            :     libspdm_session_info_t *session_info;
+    1356                 :            :     uint32_t session_id;
+    1357                 :            : 
+    1358                 :          1 :     spdm_test_context = *state;
+    1359                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1360                 :          1 :     spdm_test_context->case_id = 0x17;
+    1361                 :          1 :     spdm_context->connection_info.connection_state =
+    1362                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    1363                 :          1 :     spdm_context->local_context.capability.flags |=
+    1364                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    1365                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1366                 :            :         m_libspdm_use_hash_algo;
+    1367                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1368                 :            :         m_libspdm_use_asym_algo;
+    1369                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    1370                 :            :         m_libspdm_use_measurement_spec;
+    1371                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1372                 :            :         m_libspdm_use_measurement_hash_algo;
+    1373                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1374                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1375                 :          1 :     libspdm_secret_lib_meas_opaque_data_size = 0;
+    1376                 :          1 :     measurment_sig_size = SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
+    1377                 :          1 :                           libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    1378                 :            : 
+    1379                 :          1 :     response_size = sizeof(response);
+    1380                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
+    1381                 :            :                               m_libspdm_get_measurements_request5.nonce);
+    1382                 :            : 
+    1383                 :            : 
+    1384                 :          1 :     session_id = 0xFFFFFFFF;
+    1385                 :          1 :     spdm_context->latest_session_id = session_id;
+    1386                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+    1387                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+    1388                 :          1 :     session_info = &spdm_context->session_info[0];
+    1389                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+    1390                 :          1 :     libspdm_secured_message_set_session_state(
+    1391                 :            :         session_info->secured_message_context,
+    1392                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+    1393                 :          1 :     status = libspdm_get_response_measurements(
+    1394                 :            :         spdm_context, m_libspdm_get_measurements_request5_size,
+    1395                 :            :         &m_libspdm_get_measurements_request5, &response_size, response);
+    1396                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1397                 :          1 :     assert_int_equal(response_size, sizeof(spdm_measurements_response_t) +
+    1398                 :            :                      measurment_sig_size);
+    1399                 :          1 :     spdm_response = (void *)response;
+    1400                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1401                 :            :                      SPDM_MEASUREMENTS);
+    1402                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1403                 :            :                      LIBSPDM_MEASUREMENT_BLOCK_NUMBER);
+    1404                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1405                 :            :     assert_int_equal(session_info->session_transcript.message_m.buffer_size, 0);
+    1406                 :            : #endif
+    1407                 :          1 : }
+    1408                 :            : 
+    1409                 :            : /**
+    1410                 :            :  * Test 24: receiving a correct GET_MEASUREMENTS from the requester that does not request a
+    1411                 :            :  * signature. Buffer M already has arbitrary data.
+    1412                 :            :  * Expected behavior: the responder accepts the request and produces a valid
+    1413                 :            :  * MEASUREMENTS response message, and buffer M appends the exchanged GET_MEASUREMENTS and MEASUREMENTS
+    1414                 :            :  * messages.
+    1415                 :            :  **/
+    1416                 :          1 : void libspdm_test_responder_measurements_case24(void **state)
+    1417                 :            : {
+    1418                 :            :     libspdm_return_t status;
+    1419                 :            :     libspdm_test_context_t *spdm_test_context;
+    1420                 :            :     libspdm_context_t *spdm_context;
+    1421                 :            :     size_t response_size;
+    1422                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1423                 :            :     spdm_measurements_response_t *spdm_response;
+    1424                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1425                 :            :     size_t arbitrary_size;
+    1426                 :            : #endif
+    1427                 :            : 
+    1428                 :          1 :     spdm_test_context = *state;
+    1429                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1430                 :          1 :     spdm_test_context->case_id = 0x18;
+    1431                 :          1 :     spdm_context->connection_info.connection_state =
+    1432                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    1433                 :          1 :     spdm_context->local_context.capability.flags |=
+    1434                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    1435                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1436                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1437                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+    1438                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1439                 :            :         m_libspdm_use_measurement_hash_algo;
+    1440                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    1441                 :          1 :     libspdm_secret_lib_meas_opaque_data_size = 0;
+    1442                 :          1 :     spdm_context->last_spdm_request_session_id_valid = 0;
+    1443                 :            : 
+    1444                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1445                 :            :     /*filling M buffer with arbitrary data*/
+    1446                 :            :     arbitrary_size = 18;
+    1447                 :            :     libspdm_set_mem(spdm_context->transcript.message_m.buffer, arbitrary_size, (uint8_t) 0xFF);
+    1448                 :            :     spdm_context->transcript.message_m.buffer_size = arbitrary_size;
+    1449                 :            : #endif
+    1450                 :            : 
+    1451                 :          1 :     response_size = sizeof(response);
+    1452                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE, m_libspdm_get_measurements_request7.nonce);
+    1453                 :          1 :     status = libspdm_get_response_measurements(
+    1454                 :            :         spdm_context, m_libspdm_get_measurements_request7_size,
+    1455                 :            :         &m_libspdm_get_measurements_request7, &response_size, response);
+    1456                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1457                 :          1 :     assert_int_equal(response_size,
+    1458                 :            :                      sizeof(spdm_measurements_response_t) + LIBSPDM_MEASUREMENT_BLOCK_HASH_NUMBER*
+    1459                 :            :                      (sizeof(spdm_measurement_block_dmtf_t) +
+    1460                 :            :                       libspdm_get_measurement_hash_size(m_libspdm_use_measurement_hash_algo)) +
+    1461                 :            :                      (sizeof(spdm_measurement_block_dmtf_t) +
+    1462                 :            :                       sizeof(spdm_measurements_secure_version_number_t)) +
+    1463                 :            :                      (sizeof(spdm_measurement_block_dmtf_t) +
+    1464                 :            :                       libspdm_get_measurement_hash_size(m_libspdm_use_measurement_hash_algo)) +
+    1465                 :            :                      (sizeof(spdm_measurement_block_dmtf_t) + LIBSPDM_MEASUREMENT_MANIFEST_SIZE) +
+    1466                 :            :                      (sizeof(spdm_measurement_block_dmtf_t) +
+    1467                 :            :                       sizeof(spdm_measurements_device_mode_t)) +
+    1468                 :            :                      SPDM_NONCE_SIZE + sizeof(uint16_t));
+    1469                 :          1 :     spdm_response = (void *)response;
+    1470                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_MEASUREMENTS);
+    1471                 :          1 :     assert_int_equal(spdm_response->number_of_blocks, LIBSPDM_MEASUREMENT_BLOCK_NUMBER);
+    1472                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1473                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
+    1474                 :            :                      arbitrary_size + m_libspdm_get_measurements_request7_size +
+    1475                 :            :                      sizeof(spdm_measurements_response_t) + LIBSPDM_MEASUREMENT_BLOCK_HASH_NUMBER*
+    1476                 :            :                      (sizeof(spdm_measurement_block_dmtf_t) +
+    1477                 :            :                       libspdm_get_measurement_hash_size(m_libspdm_use_measurement_hash_algo)) +
+    1478                 :            :                      (sizeof(spdm_measurement_block_dmtf_t) +
+    1479                 :            :                       sizeof(spdm_measurements_secure_version_number_t)) +
+    1480                 :            :                      (sizeof(spdm_measurement_block_dmtf_t) +
+    1481                 :            :                       libspdm_get_measurement_hash_size(m_libspdm_use_measurement_hash_algo)) +
+    1482                 :            :                      (sizeof(spdm_measurement_block_dmtf_t) + LIBSPDM_MEASUREMENT_MANIFEST_SIZE) +
+    1483                 :            :                      (sizeof(spdm_measurement_block_dmtf_t) +
+    1484                 :            :                       sizeof(spdm_measurements_device_mode_t)) +
+    1485                 :            :                      SPDM_NONCE_SIZE + sizeof(uint16_t));
+    1486                 :            : 
+    1487                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
+    1488                 :            :                      arbitrary_size + m_libspdm_get_measurements_request7_size + response_size);
+    1489                 :            :     assert_memory_equal(spdm_context->transcript.message_m.buffer + arbitrary_size,
+    1490                 :            :                         &m_libspdm_get_measurements_request7,
+    1491                 :            :                         m_libspdm_get_measurements_request7_size);
+    1492                 :            :     assert_memory_equal(spdm_context->transcript.message_m.buffer + arbitrary_size
+    1493                 :            :                         + m_libspdm_get_measurements_request7_size,
+    1494                 :            :                         response, response_size);
+    1495                 :            : #endif
+    1496                 :          1 : }
+    1497                 :            : 
+    1498                 :          1 : void libspdm_test_responder_measurements_case25(void **state)
+    1499                 :            : {
+    1500                 :            :     libspdm_return_t status;
+    1501                 :            :     libspdm_test_context_t *spdm_test_context;
+    1502                 :            :     libspdm_context_t *spdm_context;
+    1503                 :            :     size_t response_size;
+    1504                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1505                 :            :     spdm_measurements_response_t *spdm_response;
+    1506                 :            : 
+    1507                 :          1 :     spdm_test_context = *state;
+    1508                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1509                 :          1 :     spdm_test_context->case_id = 0x19;
+    1510                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    1511                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1512                 :          1 :     spdm_context->connection_info.connection_state =
+    1513                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    1514                 :          1 :     spdm_context->local_context.capability.flags |=
+    1515                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    1516                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1517                 :            :         m_libspdm_use_hash_algo;
+    1518                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1519                 :            :         m_libspdm_use_asym_algo;
+    1520                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    1521                 :            :         m_libspdm_use_measurement_spec;
+    1522                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1523                 :            :         m_libspdm_use_measurement_hash_algo;
+    1524                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    1525                 :          1 :     libspdm_secret_lib_meas_opaque_data_size = 0;
+    1526                 :            : 
+    1527                 :          1 :     response_size = sizeof(response);
+    1528                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
+    1529                 :            :                               m_libspdm_get_measurements_request14.nonce);
+    1530                 :          1 :     status = libspdm_get_response_measurements(
+    1531                 :            :         spdm_context, m_libspdm_get_measurements_request14_size,
+    1532                 :            :         &m_libspdm_get_measurements_request14, &response_size, response);
+    1533                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1534                 :          1 :     assert_int_equal(response_size,
+    1535                 :            :                      sizeof(spdm_measurements_response_t) +
+    1536                 :            :                      sizeof(spdm_measurement_block_dmtf_t) +
+    1537                 :            :                      LIBSPDM_MEASUREMENT_RAW_DATA_SIZE + SPDM_NONCE_SIZE +
+    1538                 :            :                      sizeof(uint16_t));
+    1539                 :          1 :     spdm_response = (void *)response;
+    1540                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1541                 :            :                      SPDM_MEASUREMENTS);
+    1542                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1543                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
+    1544                 :            :                      m_libspdm_get_measurements_request14_size +
+    1545                 :            :                      sizeof(spdm_measurements_response_t) +
+    1546                 :            :                      sizeof(spdm_measurement_block_dmtf_t) +
+    1547                 :            :                      LIBSPDM_MEASUREMENT_RAW_DATA_SIZE + SPDM_NONCE_SIZE +
+    1548                 :            :                      sizeof(uint16_t));
+    1549                 :            : #endif
+    1550                 :          1 : }
+    1551                 :            : 
+    1552                 :          1 : void libspdm_test_responder_measurements_case26(void **state)
+    1553                 :            : {
+    1554                 :            :     libspdm_return_t status;
+    1555                 :            :     libspdm_test_context_t *spdm_test_context;
+    1556                 :            :     libspdm_context_t *spdm_context;
+    1557                 :            :     size_t response_size;
+    1558                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1559                 :            :     spdm_measurements_response_t *spdm_response;
+    1560                 :            :     void *data;
+    1561                 :            :     size_t data_size;
+    1562                 :            :     size_t measurment_sig_size;
+    1563                 :            : 
+    1564                 :          1 :     spdm_test_context = *state;
+    1565                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1566                 :          1 :     spdm_test_context->case_id = 0x1A;
+    1567                 :          1 :     spdm_context->connection_info.connection_state =
+    1568                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    1569                 :          1 :     spdm_context->local_context.capability.flags |=
+    1570                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    1571                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1572                 :            :         m_libspdm_use_hash_algo;
+    1573                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1574                 :            :         m_libspdm_use_asym_algo;
+    1575                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1576                 :            :         m_libspdm_use_measurement_hash_algo;
+    1577                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1578                 :            :         m_libspdm_use_hash_algo;
+    1579                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    1580                 :            :         m_libspdm_use_measurement_spec;
+    1581                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    1582                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1583                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    1584                 :          1 :     libspdm_secret_lib_meas_opaque_data_size = 0;
+    1585                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1586                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    1587                 :            :                                                     &data_size, NULL, NULL);
+    1588                 :          1 :     measurment_sig_size = SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
+    1589                 :          1 :                           libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    1590         [ +  + ]:          9 :     for (int i = 0; i < SPDM_MAX_SLOT_COUNT; i++) {
+    1591                 :          8 :         spdm_context->local_context.local_cert_chain_provision_size[i] =
+    1592                 :            :             data_size;
+    1593                 :          8 :         spdm_context->local_context.local_cert_chain_provision[i] =
+    1594                 :            :             data;
+    1595                 :            :     }
+    1596                 :            : 
+    1597                 :          1 :     response_size = sizeof(response);
+    1598                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
+    1599                 :            :                               m_libspdm_get_measurements_request15.nonce);
+    1600                 :          1 :     status = libspdm_get_response_measurements(
+    1601                 :            :         spdm_context, m_libspdm_get_measurements_request15_size,
+    1602                 :            :         &m_libspdm_get_measurements_request15, &response_size, response);
+    1603                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1604                 :          1 :     assert_int_equal(response_size,
+    1605                 :            :                      sizeof(spdm_measurements_response_t) +
+    1606                 :            :                      sizeof(spdm_measurement_block_dmtf_t) +
+    1607                 :            :                      libspdm_get_measurement_hash_size(
+    1608                 :            :                          m_libspdm_use_measurement_hash_algo) +
+    1609                 :            :                      measurment_sig_size);
+    1610                 :          1 :     spdm_response = (void *)response;
+    1611                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1612                 :            :                      SPDM_MEASUREMENTS);
+    1613                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1614                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+    1615                 :            : #endif
+    1616                 :          1 :     assert_int_equal(spdm_response->header.param2, m_libspdm_get_measurements_request15.slot_id_param|
+    1617                 :            :                      (SPDM_MEASUREMENTS_RESPONSE_CONTENT_NO_CHANGE_DETECTED &
+    1618                 :            :                       SPDM_MEASUREMENTS_RESPONSE_CONTENT_CHANGE_MASK));
+    1619                 :            : 
+    1620                 :          1 :     free(data);
+    1621                 :          1 : }
+    1622                 :            : 
+    1623                 :          1 : void libspdm_test_responder_measurements_case27(void **state)
+    1624                 :            : {
+    1625                 :            :     libspdm_return_t status;
+    1626                 :            :     libspdm_test_context_t *spdm_test_context;
+    1627                 :            :     libspdm_context_t *spdm_context;
+    1628                 :            :     size_t response_size;
+    1629                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1630                 :            :     spdm_measurements_response_t *spdm_response;
+    1631                 :            :     void *data;
+    1632                 :            :     size_t data_size;
+    1633                 :            :     size_t measurment_sig_size;
+    1634                 :            :     uint8_t content_changed;
+    1635                 :            :     uint8_t measurements_count;
+    1636                 :            :     uint8_t *measurement_record_data;
+    1637                 :            :     size_t measurement_record_data_length;
+    1638                 :            :     uint8_t expect_measurement_record_data[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
+    1639                 :            :     size_t expect_measurement_record_data_length;
+    1640                 :            :     uint8_t *opaque_data;
+    1641                 :            :     uint16_t *opaque_data_size;
+    1642                 :            :     uint8_t expect_opaque_data[SPDM_MAX_OPAQUE_DATA_SIZE];
+    1643                 :            :     size_t expect_opaque_data_size;
+    1644                 :            : 
+    1645                 :          1 :     spdm_test_context = *state;
+    1646                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1647                 :          1 :     spdm_test_context->case_id = 0x1B;
+    1648                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    1649                 :          1 :     spdm_context->local_context.capability.flags |=
+    1650                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    1651                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1652                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1653                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1654                 :            :         m_libspdm_use_measurement_hash_algo;
+    1655                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1656                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+    1657                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    1658                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1659                 :          1 :     spdm_context->connection_info.algorithm.other_params_support =
+    1660                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
+    1661                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    1662                 :            : 
+    1663                 :            :     /*opaque data*/
+    1664                 :          1 :     libspdm_secret_lib_meas_opaque_data_size = 0x20;
+    1665                 :            : 
+    1666                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1667                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    1668                 :            :                                                     &data_size, NULL, NULL);
+    1669                 :          1 :     measurment_sig_size = SPDM_NONCE_SIZE + sizeof(uint16_t) +
+    1670                 :          1 :                           libspdm_secret_lib_meas_opaque_data_size +
+    1671                 :          1 :                           libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    1672         [ +  + ]:          9 :     for (int i = 0; i < SPDM_MAX_SLOT_COUNT; i++) {
+    1673                 :          8 :         spdm_context->local_context.local_cert_chain_provision_size[i] = data_size;
+    1674                 :          8 :         spdm_context->local_context.local_cert_chain_provision[i] = data;
+    1675                 :            :     }
+    1676                 :            : 
+    1677                 :          1 :     response_size = sizeof(response);
+    1678                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE, m_libspdm_get_measurements_request15.nonce);
+    1679                 :          1 :     status = libspdm_get_response_measurements(
+    1680                 :            :         spdm_context, m_libspdm_get_measurements_request15_size,
+    1681                 :            :         &m_libspdm_get_measurements_request15, &response_size, response);
+    1682                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1683                 :          1 :     assert_int_equal(response_size,
+    1684                 :            :                      sizeof(spdm_measurements_response_t) +
+    1685                 :            :                      sizeof(spdm_measurement_block_dmtf_t) +
+    1686                 :            :                      libspdm_get_measurement_hash_size(m_libspdm_use_measurement_hash_algo) +
+    1687                 :            :                      measurment_sig_size);
+    1688                 :          1 :     spdm_response = (void *)response;
+    1689                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1690                 :            :                      SPDM_MEASUREMENTS);
+    1691                 :            : 
+    1692                 :          1 :     expect_measurement_record_data_length = sizeof(expect_measurement_record_data);
+    1693                 :          1 :     expect_opaque_data_size = sizeof(expect_opaque_data);
+    1694                 :            : 
+    1695                 :          1 :     libspdm_measurement_collection(
+    1696                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    1697                 :            :         spdm_context,
+    1698                 :            : #endif
+    1699                 :          1 :         spdm_context->connection_info.version,
+    1700                 :          1 :         spdm_context->connection_info.algorithm.measurement_spec,
+    1701                 :            :         spdm_context->connection_info.algorithm.measurement_hash_algo,
+    1702                 :          1 :         m_libspdm_get_measurements_request15.header.param2,
+    1703                 :          1 :         m_libspdm_get_measurements_request15.header.param1,
+    1704                 :            :         &content_changed,
+    1705                 :            :         &measurements_count,
+    1706                 :            :         expect_measurement_record_data,
+    1707                 :            :         &expect_measurement_record_data_length);
+    1708                 :            : 
+    1709                 :          1 :     libspdm_measurement_opaque_data(
+    1710                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    1711                 :            :         spdm_context,
+    1712                 :            : #endif
+    1713                 :          1 :         spdm_context->connection_info.version,
+    1714                 :          1 :         spdm_context->connection_info.algorithm.measurement_spec,
+    1715                 :            :         spdm_context->connection_info.algorithm.measurement_hash_algo,
+    1716                 :          1 :         m_libspdm_get_measurements_request15.header.param2,
+    1717                 :          1 :         m_libspdm_get_measurements_request15.header.param1,
+    1718                 :            :         expect_opaque_data,
+    1719                 :            :         &expect_opaque_data_size);
+    1720                 :            : 
+    1721                 :          1 :     measurement_record_data = (uint8_t *)response + sizeof(spdm_measurements_response_t);
+    1722                 :          1 :     opaque_data_size =
+    1723                 :            :         (uint16_t *)(measurement_record_data + sizeof(spdm_measurement_block_dmtf_t) +
+    1724                 :          1 :                      libspdm_get_measurement_hash_size(
+    1725                 :          1 :                          m_libspdm_use_measurement_hash_algo) +
+    1726                 :            :                      SPDM_NONCE_SIZE);
+    1727                 :          1 :     opaque_data = (uint8_t *)opaque_data_size + sizeof(uint16_t);
+    1728                 :            : 
+    1729                 :          1 :     measurement_record_data_length = libspdm_read_uint24(spdm_response->measurement_record_length);
+    1730                 :            : 
+    1731                 :          1 :     assert_int_equal(measurement_record_data_length, expect_measurement_record_data_length );
+    1732                 :          1 :     assert_memory_equal(measurement_record_data, expect_measurement_record_data,
+    1733                 :            :                         expect_measurement_record_data_length);
+    1734                 :          1 :     assert_int_equal(*opaque_data_size, libspdm_secret_lib_meas_opaque_data_size);
+    1735                 :          1 :     assert_memory_equal(opaque_data, expect_opaque_data, libspdm_secret_lib_meas_opaque_data_size);
+    1736                 :            : 
+    1737                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1738                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+    1739                 :            : #endif
+    1740                 :          1 :     assert_int_equal(spdm_response->header.param2, m_libspdm_get_measurements_request15.slot_id_param|
+    1741                 :            :                      (SPDM_MEASUREMENTS_RESPONSE_CONTENT_NO_CHANGE_DETECTED &
+    1742                 :            :                       SPDM_MEASUREMENTS_RESPONSE_CONTENT_CHANGE_MASK));
+    1743                 :            : 
+    1744                 :          1 :     free(data);
+    1745                 :          1 : }
+    1746                 :            : 
+    1747                 :            : /**
+    1748                 :            :  * Test 28: Successful response to get all measurements with signature using slot_id 0xFF
+    1749                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code, empty transcript.message_m, and correct response message size and fields
+    1750                 :            :  **/
+    1751                 :          1 : void libspdm_test_responder_measurements_case28(void **state)
+    1752                 :            : {
+    1753                 :            :     libspdm_return_t status;
+    1754                 :            :     libspdm_test_context_t *spdm_test_context;
+    1755                 :            :     libspdm_context_t *spdm_context;
+    1756                 :            :     size_t response_size;
+    1757                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1758                 :            :     spdm_measurements_response_t *spdm_response;
+    1759                 :            :     void *data;
+    1760                 :            :     size_t data_size;
+    1761                 :            :     size_t measurment_sig_size;
+    1762                 :            : 
+    1763                 :          1 :     spdm_test_context = *state;
+    1764                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1765                 :          1 :     spdm_test_context->case_id = 0x1C;
+    1766                 :          1 :     spdm_context->connection_info.connection_state =
+    1767                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    1768                 :          1 :     spdm_context->local_context.capability.flags |=
+    1769                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    1770                 :          1 :     spdm_context->local_context.capability.flags |=
+    1771                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PUB_KEY_ID_CAP;
+    1772                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1773                 :            :         m_libspdm_use_hash_algo;
+    1774                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1775                 :            :         m_libspdm_use_asym_algo;
+    1776                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1777                 :            :         m_libspdm_use_measurement_hash_algo;
+    1778                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1779                 :            :         m_libspdm_use_hash_algo;
+    1780                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    1781                 :            :         m_libspdm_use_measurement_spec;
+    1782                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    1783                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1784                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    1785                 :            : 
+    1786                 :            :     /*opaque data*/
+    1787                 :          1 :     libspdm_secret_lib_meas_opaque_data_size = 0x20;
+    1788                 :            : 
+    1789                 :          1 :     libspdm_read_responder_public_key(m_libspdm_use_asym_algo, &data, &data_size);
+    1790                 :          1 :     spdm_context->local_context.local_public_key_provision = data;
+    1791                 :          1 :     spdm_context->local_context.local_public_key_provision_size = data_size;
+    1792                 :            : 
+    1793                 :          1 :     measurment_sig_size = SPDM_NONCE_SIZE + sizeof(uint16_t) +
+    1794                 :          1 :                           libspdm_secret_lib_meas_opaque_data_size +
+    1795                 :          1 :                           libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    1796                 :          1 :     response_size = sizeof(response);
+    1797                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
+    1798                 :            :                               m_libspdm_get_measurements_request16.nonce);
+    1799                 :          1 :     m_libspdm_get_measurements_request16.slot_id_param = 0xF;
+    1800                 :          1 :     status = libspdm_get_response_measurements(
+    1801                 :            :         spdm_context, m_libspdm_get_measurements_request16_size,
+    1802                 :            :         &m_libspdm_get_measurements_request16, &response_size, response);
+    1803                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1804                 :          1 :     assert_int_equal(response_size,
+    1805                 :            :                      sizeof(spdm_measurements_response_t) + sizeof(spdm_measurement_block_dmtf_t) +
+    1806                 :            :                      libspdm_get_measurement_hash_size(m_libspdm_use_measurement_hash_algo) +
+    1807                 :            :                      measurment_sig_size);
+    1808                 :          1 :     spdm_response = (void *)response;
+    1809                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1810                 :            :                      SPDM_MEASUREMENTS);
+    1811                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1812                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+    1813                 :            : #endif
+    1814                 :          1 :     assert_int_equal(spdm_response->header.param2,
+    1815                 :            :                      m_libspdm_get_measurements_request16.slot_id_param |
+    1816                 :            :                      (SPDM_MEASUREMENTS_RESPONSE_CONTENT_NO_CHANGE_DETECTED &
+    1817                 :            :                       SPDM_MEASUREMENTS_RESPONSE_CONTENT_CHANGE_MASK));
+    1818                 :            : 
+    1819                 :          1 :     free(data);
+    1820                 :          1 : }
+    1821                 :            : 
+    1822                 :            : /**
+    1823                 :            :  * Test 29: Based of Test Case 7  Successful response to get a number of measurements
+    1824                 :            :  * with signature.
+    1825                 :            :  * Signature test with signing in big endian but verification in little endian.
+    1826                 :            :  *
+    1827                 :            :  * Expected Behavior: Failing signature verification
+    1828                 :            :  **/
+    1829                 :          1 : void libspdm_test_responder_measurements_case29(void** state)
+    1830                 :            : {
+    1831                 :            :     libspdm_return_t status;
+    1832                 :            :     libspdm_test_context_t* spdm_test_context;
+    1833                 :            :     libspdm_context_t* spdm_context;
+    1834                 :            :     size_t response_size;
+    1835                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1836                 :            :     spdm_measurements_response_t* spdm_response;
+    1837                 :            :     size_t measurment_sig_size;
+    1838                 :            : 
+    1839                 :            :     bool result;
+    1840                 :            :     uint32_t measurement_record_data_length;
+    1841                 :            :     uint8_t* measurement_record_data;
+    1842                 :            :     uint8_t* ptr;
+    1843                 :            :     uint16_t opaque_length;
+    1844                 :            :     void* signature;
+    1845                 :            :     size_t signature_size;
+    1846                 :            :     libspdm_session_info_t* session_info;
+    1847                 :            :     void* data;
+    1848                 :            :     size_t data_size;
+    1849                 :            :     void* hash;
+    1850                 :            :     size_t hash_size;
+    1851                 :            : 
+    1852                 :          1 :     spdm_test_context = *state;
+    1853                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1854                 :          1 :     spdm_test_context->case_id = 29;
+    1855                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1856                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1857                 :          1 :     spdm_context->connection_info.connection_state =
+    1858                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    1859                 :          1 :     spdm_context->local_context.capability.flags |=
+    1860                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    1861                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1862                 :            :         m_libspdm_use_hash_algo;
+    1863                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1864                 :            :         m_libspdm_use_asym_algo;
+    1865                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    1866                 :            :         m_libspdm_use_measurement_spec;
+    1867                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1868                 :            :         m_libspdm_use_measurement_hash_algo;
+    1869                 :          1 :     spdm_context->spdm_10_11_verify_signature_endian =
+    1870                 :            :         LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_LITTLE_ONLY;
+    1871                 :            : 
+    1872                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    1873                 :          1 :     libspdm_secret_lib_meas_opaque_data_size = 0;
+    1874                 :          1 :     measurment_sig_size = SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
+    1875                 :          1 :                           libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    1876                 :            : 
+    1877                 :          1 :     response_size = sizeof(response);
+    1878                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
+    1879                 :            :                               m_libspdm_get_measurements_request5.nonce);
+    1880                 :          1 :     status = libspdm_get_response_measurements(
+    1881                 :            :         spdm_context, m_libspdm_get_measurements_request5_size,
+    1882                 :            :         &m_libspdm_get_measurements_request5, &response_size, response);
+    1883                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1884                 :          1 :     assert_int_equal(response_size, sizeof(spdm_measurements_response_t) +
+    1885                 :            :                      measurment_sig_size);
+    1886                 :          1 :     spdm_response = (void*)response;
+    1887                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1888                 :            :                      SPDM_MEASUREMENTS);
+    1889                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1890                 :            :                      LIBSPDM_MEASUREMENT_BLOCK_NUMBER);
+    1891                 :            : 
+    1892                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1893                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    1894                 :            :                                                     &data_size,
+    1895                 :            :                                                     &hash, &hash_size);
+    1896                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1897                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    1898                 :            :         data_size;
+    1899                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    1900                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    1901                 :            :                      data, data_size);
+    1902                 :            : #else
+    1903                 :          1 :     libspdm_hash_all(
+    1904                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    1905                 :            :         data, data_size,
+    1906                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    1907                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    1908                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    1909                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    1910                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    1911                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    1912                 :            :         data, data_size,
+    1913                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    1914                 :            : #endif
+    1915                 :            : 
+    1916                 :          1 :     measurement_record_data_length = libspdm_read_uint24(spdm_response->measurement_record_length);
+    1917                 :          1 :     measurement_record_data = (void*)(spdm_response + 1);
+    1918                 :          1 :     ptr = measurement_record_data + measurement_record_data_length;
+    1919                 :          1 :     ptr += SPDM_NONCE_SIZE;
+    1920                 :          1 :     opaque_length = libspdm_read_uint16((const uint8_t*)ptr);
+    1921                 :          1 :     ptr += sizeof(uint16_t);
+    1922                 :          1 :     ptr += opaque_length;
+    1923                 :          1 :     signature = ptr;
+    1924                 :          1 :     signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    1925                 :          1 :     session_info = NULL;
+    1926                 :            : 
+    1927                 :          1 :     status = libspdm_append_message_m(spdm_context, session_info,
+    1928                 :            :                                       &m_libspdm_get_measurements_request5,
+    1929                 :            :                                       m_libspdm_get_measurements_request5_size);
+    1930                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1931                 :            : 
+    1932                 :          1 :     status = libspdm_append_message_m(spdm_context, session_info, spdm_response,
+    1933                 :            :                                       response_size - signature_size);
+    1934                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1935                 :            : 
+    1936                 :          1 :     result = libspdm_verify_measurement_signature(
+    1937                 :            :         spdm_context, session_info, signature, signature_size);
+    1938                 :          1 :     assert_true(result == false);
+    1939                 :            : 
+    1940                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1941                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+    1942                 :            : #endif
+    1943                 :          1 : }
+    1944                 :            : 
+    1945                 :            : /**
+    1946                 :            :  * Test 30: Based of Test Case 7  Successful response to get a number of measurements
+    1947                 :            :  * with signature.
+    1948                 :            :  * Signature test with signing in big endian but verification in little endian.
+    1949                 :            :  *
+    1950                 :            :  * Expected Behavior: Failing signature verification
+    1951                 :            :  **/
+    1952                 :          1 : void libspdm_test_responder_measurements_case30(void** state)
+    1953                 :            : {
+    1954                 :            :     libspdm_return_t status;
+    1955                 :            :     libspdm_test_context_t* spdm_test_context;
+    1956                 :            :     libspdm_context_t* spdm_context;
+    1957                 :            :     size_t response_size;
+    1958                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1959                 :            :     spdm_measurements_response_t* spdm_response;
+    1960                 :            :     size_t measurment_sig_size;
+    1961                 :            : 
+    1962                 :            :     bool result;
+    1963                 :            :     uint32_t measurement_record_data_length;
+    1964                 :            :     uint8_t* measurement_record_data;
+    1965                 :            :     uint8_t* ptr;
+    1966                 :            :     uint16_t opaque_length;
+    1967                 :            :     void* signature;
+    1968                 :            :     size_t signature_size;
+    1969                 :            :     libspdm_session_info_t* session_info;
+    1970                 :            :     void* data;
+    1971                 :            :     size_t data_size;
+    1972                 :            :     void* hash;
+    1973                 :            :     size_t hash_size;
+    1974                 :            : 
+    1975                 :          1 :     spdm_test_context = *state;
+    1976                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1977                 :          1 :     spdm_test_context->case_id = 30;
+    1978                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    1979                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1980                 :          1 :     spdm_context->connection_info.connection_state =
+    1981                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    1982                 :          1 :     spdm_context->local_context.capability.flags |=
+    1983                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    1984                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1985                 :            :         m_libspdm_use_hash_algo;
+    1986                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1987                 :            :         m_libspdm_use_asym_algo;
+    1988                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    1989                 :            :         m_libspdm_use_measurement_spec;
+    1990                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1991                 :            :         m_libspdm_use_measurement_hash_algo;
+    1992                 :          1 :     spdm_context->spdm_10_11_verify_signature_endian =
+    1993                 :            :         LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_ONLY;
+    1994                 :            : 
+    1995                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    1996                 :          1 :     libspdm_secret_lib_meas_opaque_data_size = 0;
+    1997                 :          1 :     measurment_sig_size = SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
+    1998                 :          1 :                           libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    1999                 :            : 
+    2000                 :          1 :     response_size = sizeof(response);
+    2001                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
+    2002                 :            :                               m_libspdm_get_measurements_request5.nonce);
+    2003                 :          1 :     status = libspdm_get_response_measurements(
+    2004                 :            :         spdm_context, m_libspdm_get_measurements_request5_size,
+    2005                 :            :         &m_libspdm_get_measurements_request5, &response_size, response);
+    2006                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2007                 :          1 :     assert_int_equal(response_size, sizeof(spdm_measurements_response_t) +
+    2008                 :            :                      measurment_sig_size);
+    2009                 :          1 :     spdm_response = (void*)response;
+    2010                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    2011                 :            :                      SPDM_MEASUREMENTS);
+    2012                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    2013                 :            :                      LIBSPDM_MEASUREMENT_BLOCK_NUMBER);
+    2014                 :            : 
+    2015                 :          1 :     libspdm_read_responder_public_certificate_chain(
+    2016                 :            :         m_libspdm_use_hash_algo, m_libspdm_use_asym_algo,
+    2017                 :            :         &data, &data_size,
+    2018                 :            :         &hash, &hash_size);
+    2019                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    2020                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    2021                 :            :         data_size;
+    2022                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    2023                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    2024                 :            :                      data, data_size);
+    2025                 :            : #else
+    2026                 :          1 :     libspdm_hash_all(
+    2027                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    2028                 :            :         data, data_size,
+    2029                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    2030                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    2031                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    2032                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    2033                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    2034                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    2035                 :            :         data, data_size,
+    2036                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    2037                 :            : #endif
+    2038                 :            : 
+    2039                 :          1 :     measurement_record_data_length = libspdm_read_uint24(spdm_response->measurement_record_length);
+    2040                 :          1 :     measurement_record_data = (void*)(spdm_response + 1);
+    2041                 :          1 :     ptr = measurement_record_data + measurement_record_data_length;
+    2042                 :          1 :     ptr += SPDM_NONCE_SIZE;
+    2043                 :          1 :     opaque_length = libspdm_read_uint16((const uint8_t*)ptr);
+    2044                 :          1 :     ptr += sizeof(uint16_t);
+    2045                 :          1 :     ptr += opaque_length;
+    2046                 :          1 :     signature = ptr;
+    2047                 :          1 :     signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    2048                 :          1 :     session_info = NULL;
+    2049                 :            : 
+    2050                 :          1 :     status = libspdm_append_message_m(
+    2051                 :            :         spdm_context, session_info,
+    2052                 :            :         &m_libspdm_get_measurements_request5,
+    2053                 :            :         m_libspdm_get_measurements_request5_size);
+    2054                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2055                 :            : 
+    2056                 :          1 :     status = libspdm_append_message_m(
+    2057                 :            :         spdm_context, session_info, spdm_response,
+    2058                 :            :         response_size - signature_size);
+    2059                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2060                 :            : 
+    2061                 :          1 :     result = libspdm_verify_measurement_signature(
+    2062                 :            :         spdm_context, session_info, signature, signature_size);
+    2063                 :          1 :     assert_true(result == true);
+    2064                 :            : 
+    2065                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    2066                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+    2067                 :            : #endif
+    2068                 :          1 : }
+    2069                 :            : 
+    2070                 :            : /**
+    2071                 :            :  * Test 31: Based of Test Case 7  Successful response to get a number of measurements
+    2072                 :            :  * with signature.
+    2073                 :            :  * Signature test with signing in big endian but verification in big or little endian.
+    2074                 :            :  *
+    2075                 :            :  * Expected Behavior: Passing signature verification
+    2076                 :            :  **/
+    2077                 :          1 : void libspdm_test_responder_measurements_case31(void** state)
+    2078                 :            : {
+    2079                 :            :     libspdm_return_t status;
+    2080                 :            :     libspdm_test_context_t* spdm_test_context;
+    2081                 :            :     libspdm_context_t* spdm_context;
+    2082                 :            :     size_t response_size;
+    2083                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    2084                 :            :     spdm_measurements_response_t* spdm_response;
+    2085                 :            :     size_t measurment_sig_size;
+    2086                 :            : 
+    2087                 :            :     bool result;
+    2088                 :            :     uint32_t measurement_record_data_length;
+    2089                 :            :     uint8_t* measurement_record_data;
+    2090                 :            :     uint8_t* ptr;
+    2091                 :            :     uint16_t opaque_length;
+    2092                 :            :     void* signature;
+    2093                 :            :     size_t signature_size;
+    2094                 :            :     libspdm_session_info_t* session_info;
+    2095                 :            :     void* data;
+    2096                 :            :     size_t data_size;
+    2097                 :            :     void* hash;
+    2098                 :            :     size_t hash_size;
+    2099                 :            : 
+    2100                 :          1 :     spdm_test_context = *state;
+    2101                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2102                 :          1 :     spdm_test_context->case_id = 31;
+    2103                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    2104                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2105                 :          1 :     spdm_context->connection_info.connection_state =
+    2106                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    2107                 :          1 :     spdm_context->local_context.capability.flags |=
+    2108                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    2109                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    2110                 :            :         m_libspdm_use_hash_algo;
+    2111                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    2112                 :            :         m_libspdm_use_asym_algo;
+    2113                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    2114                 :            :         m_libspdm_use_measurement_spec;
+    2115                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    2116                 :            :         m_libspdm_use_measurement_hash_algo;
+    2117                 :          1 :     spdm_context->spdm_10_11_verify_signature_endian =
+    2118                 :            :         LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_OR_LITTLE;
+    2119                 :            : 
+    2120                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    2121                 :          1 :     libspdm_secret_lib_meas_opaque_data_size = 0;
+    2122                 :          1 :     measurment_sig_size = SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
+    2123                 :          1 :                           libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    2124                 :            : 
+    2125                 :          1 :     response_size = sizeof(response);
+    2126                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
+    2127                 :            :                               m_libspdm_get_measurements_request5.nonce);
+    2128                 :          1 :     status = libspdm_get_response_measurements(
+    2129                 :            :         spdm_context, m_libspdm_get_measurements_request5_size,
+    2130                 :            :         &m_libspdm_get_measurements_request5, &response_size, response);
+    2131                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2132                 :          1 :     assert_int_equal(response_size, sizeof(spdm_measurements_response_t) +
+    2133                 :            :                      measurment_sig_size);
+    2134                 :          1 :     spdm_response = (void*)response;
+    2135                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    2136                 :            :                      SPDM_MEASUREMENTS);
+    2137                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    2138                 :            :                      LIBSPDM_MEASUREMENT_BLOCK_NUMBER);
+    2139                 :            : 
+    2140                 :          1 :     libspdm_read_responder_public_certificate_chain(
+    2141                 :            :         m_libspdm_use_hash_algo, m_libspdm_use_asym_algo,
+    2142                 :            :         &data, &data_size,
+    2143                 :            :         &hash, &hash_size);
+    2144                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    2145                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    2146                 :            :         data_size;
+    2147                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    2148                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    2149                 :            :                      data, data_size);
+    2150                 :            : #else
+    2151                 :          1 :     libspdm_hash_all(
+    2152                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    2153                 :            :         data, data_size,
+    2154                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    2155                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    2156                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    2157                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    2158                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    2159                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    2160                 :            :         data, data_size,
+    2161                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    2162                 :            : #endif
+    2163                 :            : 
+    2164                 :          1 :     measurement_record_data_length = libspdm_read_uint24(spdm_response->measurement_record_length);
+    2165                 :          1 :     measurement_record_data = (void*)(spdm_response + 1);
+    2166                 :          1 :     ptr = measurement_record_data + measurement_record_data_length;
+    2167                 :          1 :     ptr += SPDM_NONCE_SIZE;
+    2168                 :          1 :     opaque_length = libspdm_read_uint16((const uint8_t*)ptr);
+    2169                 :          1 :     ptr += sizeof(uint16_t);
+    2170                 :          1 :     ptr += opaque_length;
+    2171                 :          1 :     signature = ptr;
+    2172                 :          1 :     signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    2173                 :          1 :     session_info = NULL;
+    2174                 :            : 
+    2175                 :          1 :     status = libspdm_append_message_m(
+    2176                 :            :         spdm_context, session_info,
+    2177                 :            :         &m_libspdm_get_measurements_request5,
+    2178                 :            :         m_libspdm_get_measurements_request5_size);
+    2179                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2180                 :            : 
+    2181                 :          1 :     status = libspdm_append_message_m(
+    2182                 :            :         spdm_context, session_info, spdm_response,
+    2183                 :            :         response_size - signature_size);
+    2184                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2185                 :            : 
+    2186                 :          1 :     result = libspdm_verify_measurement_signature(
+    2187                 :            :         spdm_context, session_info, signature, signature_size);
+    2188                 :          1 :     assert_true(result == true);
+    2189                 :            : 
+    2190                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    2191                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+    2192                 :            : #endif
+    2193                 :          1 : }
+    2194                 :            : 
+    2195                 :            : /**
+    2196                 :            :  * Test 32: Based of Test Case 7  Successful response to get a number of measurements
+    2197                 :            :  * with signature.
+    2198                 :            :  * Signature test with signing in little endian but verification in little endian.
+    2199                 :            :  *
+    2200                 :            :  * Expected Behavior: Failing signature verification
+    2201                 :            :  **/
+    2202                 :          1 : void libspdm_test_responder_measurements_case32(void** state)
+    2203                 :            : {
+    2204                 :            :     libspdm_return_t status;
+    2205                 :            :     libspdm_test_context_t* spdm_test_context;
+    2206                 :            :     libspdm_context_t* spdm_context;
+    2207                 :            :     size_t response_size;
+    2208                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    2209                 :            :     spdm_measurements_response_t* spdm_response;
+    2210                 :            :     size_t measurment_sig_size;
+    2211                 :            : 
+    2212                 :            :     bool result;
+    2213                 :            :     uint32_t measurement_record_data_length;
+    2214                 :            :     uint8_t* measurement_record_data;
+    2215                 :            :     uint8_t* ptr;
+    2216                 :            :     uint16_t opaque_length;
+    2217                 :            :     void* signature;
+    2218                 :            :     size_t signature_size;
+    2219                 :            :     libspdm_session_info_t* session_info;
+    2220                 :            :     void* data;
+    2221                 :            :     size_t data_size;
+    2222                 :            :     void* hash;
+    2223                 :            :     size_t hash_size;
+    2224                 :            : 
+    2225                 :          1 :     spdm_test_context = *state;
+    2226                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2227                 :          1 :     spdm_test_context->case_id = 32;
+    2228                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    2229                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2230                 :          1 :     spdm_context->connection_info.connection_state =
+    2231                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    2232                 :          1 :     spdm_context->local_context.capability.flags |=
+    2233                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    2234                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    2235                 :            :         m_libspdm_use_hash_algo;
+    2236                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    2237                 :            :         m_libspdm_use_asym_algo;
+    2238                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    2239                 :            :         m_libspdm_use_measurement_spec;
+    2240                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    2241                 :            :         m_libspdm_use_measurement_hash_algo;
+    2242                 :          1 :     spdm_context->spdm_10_11_verify_signature_endian =
+    2243                 :            :         LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_LITTLE_ONLY;
+    2244                 :            : 
+    2245                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    2246                 :          1 :     libspdm_secret_lib_meas_opaque_data_size = 0;
+    2247                 :          1 :     measurment_sig_size = SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
+    2248                 :          1 :                           libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    2249                 :            : 
+    2250                 :          1 :     response_size = sizeof(response);
+    2251                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
+    2252                 :            :                               m_libspdm_get_measurements_request5.nonce);
+    2253                 :          1 :     status = libspdm_get_response_measurements(
+    2254                 :            :         spdm_context, m_libspdm_get_measurements_request5_size,
+    2255                 :            :         &m_libspdm_get_measurements_request5, &response_size, response);
+    2256                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2257                 :          1 :     assert_int_equal(response_size, sizeof(spdm_measurements_response_t) +
+    2258                 :            :                      measurment_sig_size);
+    2259                 :          1 :     spdm_response = (void*)response;
+    2260                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    2261                 :            :                      SPDM_MEASUREMENTS);
+    2262                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    2263                 :            :                      LIBSPDM_MEASUREMENT_BLOCK_NUMBER);
+    2264                 :            : 
+    2265                 :          1 :     libspdm_read_responder_public_certificate_chain(
+    2266                 :            :         m_libspdm_use_hash_algo, m_libspdm_use_asym_algo,
+    2267                 :            :         &data, &data_size,
+    2268                 :            :         &hash, &hash_size);
+    2269                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    2270                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    2271                 :            :         data_size;
+    2272                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    2273                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    2274                 :            :                      data, data_size);
+    2275                 :            : #else
+    2276                 :          1 :     libspdm_hash_all(
+    2277                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    2278                 :            :         data, data_size,
+    2279                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    2280                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    2281                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    2282                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    2283                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    2284                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    2285                 :            :         data, data_size,
+    2286                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    2287                 :            : #endif
+    2288                 :            : 
+    2289                 :          1 :     measurement_record_data_length = libspdm_read_uint24(spdm_response->measurement_record_length);
+    2290                 :          1 :     measurement_record_data = (void*)(spdm_response + 1);
+    2291                 :          1 :     ptr = measurement_record_data + measurement_record_data_length;
+    2292                 :          1 :     ptr += SPDM_NONCE_SIZE;
+    2293                 :          1 :     opaque_length = libspdm_read_uint16((const uint8_t*)ptr);
+    2294                 :          1 :     ptr += sizeof(uint16_t);
+    2295                 :          1 :     ptr += opaque_length;
+    2296                 :          1 :     signature = ptr;
+    2297                 :          1 :     signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    2298                 :            : 
+    2299                 :          1 :     libspdm_copy_signature_swap_endian(
+    2300                 :            :         m_libspdm_use_asym_algo,
+    2301                 :            :         signature, signature_size, signature, signature_size);
+    2302                 :            : 
+    2303                 :          1 :     session_info = NULL;
+    2304                 :            : 
+    2305                 :          1 :     status = libspdm_append_message_m(
+    2306                 :            :         spdm_context, session_info,
+    2307                 :            :         &m_libspdm_get_measurements_request5,
+    2308                 :            :         m_libspdm_get_measurements_request5_size);
+    2309                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2310                 :            : 
+    2311                 :          1 :     status = libspdm_append_message_m(
+    2312                 :            :         spdm_context, session_info, spdm_response,
+    2313                 :            :         response_size - signature_size);
+    2314                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2315                 :            : 
+    2316                 :          1 :     result = libspdm_verify_measurement_signature(
+    2317                 :            :         spdm_context, session_info, signature, signature_size);
+    2318                 :          1 :     assert_true(result == true);
+    2319                 :            : 
+    2320                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    2321                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+    2322                 :            : #endif
+    2323                 :          1 : }
+    2324                 :            : 
+    2325                 :            : /**
+    2326                 :            :  * Test 33: Based of Test Case 7  Successful response to get a number of measurements
+    2327                 :            :  * with signature.
+    2328                 :            :  * Signature test with signing in little endian but verification in big endian.
+    2329                 :            :  *
+    2330                 :            :  * Expected Behavior: Failing signature verification
+    2331                 :            :  **/
+    2332                 :          1 : void libspdm_test_responder_measurements_case33(void** state)
+    2333                 :            : {
+    2334                 :            :     libspdm_return_t status;
+    2335                 :            :     libspdm_test_context_t* spdm_test_context;
+    2336                 :            :     libspdm_context_t* spdm_context;
+    2337                 :            :     size_t response_size;
+    2338                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    2339                 :            :     spdm_measurements_response_t* spdm_response;
+    2340                 :            :     size_t measurment_sig_size;
+    2341                 :            : 
+    2342                 :            :     bool result;
+    2343                 :            :     uint32_t measurement_record_data_length;
+    2344                 :            :     uint8_t* measurement_record_data;
+    2345                 :            :     uint8_t* ptr;
+    2346                 :            :     uint16_t opaque_length;
+    2347                 :            :     void* signature;
+    2348                 :            :     size_t signature_size;
+    2349                 :            :     libspdm_session_info_t* session_info;
+    2350                 :            :     void* data;
+    2351                 :            :     size_t data_size;
+    2352                 :            :     void* hash;
+    2353                 :            :     size_t hash_size;
+    2354                 :            : 
+    2355                 :          1 :     spdm_test_context = *state;
+    2356                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2357                 :          1 :     spdm_test_context->case_id = 33;
+    2358                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    2359                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2360                 :          1 :     spdm_context->connection_info.connection_state =
+    2361                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    2362                 :          1 :     spdm_context->local_context.capability.flags |=
+    2363                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    2364                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    2365                 :            :         m_libspdm_use_hash_algo;
+    2366                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    2367                 :            :         m_libspdm_use_asym_algo;
+    2368                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    2369                 :            :         m_libspdm_use_measurement_spec;
+    2370                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    2371                 :            :         m_libspdm_use_measurement_hash_algo;
+    2372                 :          1 :     spdm_context->spdm_10_11_verify_signature_endian =
+    2373                 :            :         LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_ONLY;
+    2374                 :            : 
+    2375                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    2376                 :          1 :     libspdm_secret_lib_meas_opaque_data_size = 0;
+    2377                 :          1 :     measurment_sig_size = SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
+    2378                 :          1 :                           libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    2379                 :            : 
+    2380                 :          1 :     response_size = sizeof(response);
+    2381                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
+    2382                 :            :                               m_libspdm_get_measurements_request5.nonce);
+    2383                 :          1 :     status = libspdm_get_response_measurements(
+    2384                 :            :         spdm_context, m_libspdm_get_measurements_request5_size,
+    2385                 :            :         &m_libspdm_get_measurements_request5, &response_size, response);
+    2386                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2387                 :          1 :     assert_int_equal(response_size, sizeof(spdm_measurements_response_t) +
+    2388                 :            :                      measurment_sig_size);
+    2389                 :          1 :     spdm_response = (void*)response;
+    2390                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    2391                 :            :                      SPDM_MEASUREMENTS);
+    2392                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    2393                 :            :                      LIBSPDM_MEASUREMENT_BLOCK_NUMBER);
+    2394                 :            : 
+    2395                 :          1 :     libspdm_read_responder_public_certificate_chain(
+    2396                 :            :         m_libspdm_use_hash_algo, m_libspdm_use_asym_algo,
+    2397                 :            :         &data, &data_size,
+    2398                 :            :         &hash, &hash_size);
+    2399                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    2400                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    2401                 :            :         data_size;
+    2402                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    2403                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    2404                 :            :                      data, data_size);
+    2405                 :            : #else
+    2406                 :          1 :     libspdm_hash_all(
+    2407                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    2408                 :            :         data, data_size,
+    2409                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    2410                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    2411                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    2412                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    2413                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    2414                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    2415                 :            :         data, data_size,
+    2416                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    2417                 :            : #endif
+    2418                 :            : 
+    2419                 :          1 :     measurement_record_data_length = libspdm_read_uint24(spdm_response->measurement_record_length);
+    2420                 :          1 :     measurement_record_data = (void*)(spdm_response + 1);
+    2421                 :          1 :     ptr = measurement_record_data + measurement_record_data_length;
+    2422                 :          1 :     ptr += SPDM_NONCE_SIZE;
+    2423                 :          1 :     opaque_length = libspdm_read_uint16((const uint8_t*)ptr);
+    2424                 :          1 :     ptr += sizeof(uint16_t);
+    2425                 :          1 :     ptr += opaque_length;
+    2426                 :          1 :     signature = ptr;
+    2427                 :          1 :     signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    2428                 :            : 
+    2429                 :          1 :     libspdm_copy_signature_swap_endian(
+    2430                 :            :         m_libspdm_use_asym_algo,
+    2431                 :            :         signature, signature_size, signature, signature_size);
+    2432                 :            : 
+    2433                 :          1 :     session_info = NULL;
+    2434                 :            : 
+    2435                 :          1 :     status = libspdm_append_message_m(
+    2436                 :            :         spdm_context, session_info,
+    2437                 :            :         &m_libspdm_get_measurements_request5,
+    2438                 :            :         m_libspdm_get_measurements_request5_size);
+    2439                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2440                 :            : 
+    2441                 :          1 :     status = libspdm_append_message_m(
+    2442                 :            :         spdm_context, session_info, spdm_response,
+    2443                 :            :         response_size - signature_size);
+    2444                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2445                 :            : 
+    2446                 :          1 :     result = libspdm_verify_measurement_signature(
+    2447                 :            :         spdm_context, session_info, signature, signature_size);
+    2448                 :          1 :     assert_true(result == false);
+    2449                 :            : 
+    2450                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    2451                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+    2452                 :            : #endif
+    2453                 :          1 : }
+    2454                 :            : 
+    2455                 :            : 
+    2456                 :            : /**
+    2457                 :            :  * Test 34: Based of Test Case 7  Successful response to get a number of measurements
+    2458                 :            :  * with signature.
+    2459                 :            :  * Signature test with signing in little endian but verification in big or little endian.
+    2460                 :            :  *
+    2461                 :            :  * Expected Behavior: Passing signature verification
+    2462                 :            :  **/
+    2463                 :          1 : void libspdm_test_responder_measurements_case34(void** state)
+    2464                 :            : {
+    2465                 :            :     libspdm_return_t status;
+    2466                 :            :     libspdm_test_context_t* spdm_test_context;
+    2467                 :            :     libspdm_context_t* spdm_context;
+    2468                 :            :     size_t response_size;
+    2469                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    2470                 :            :     spdm_measurements_response_t* spdm_response;
+    2471                 :            :     size_t measurment_sig_size;
+    2472                 :            : 
+    2473                 :            :     bool result;
+    2474                 :            :     uint32_t measurement_record_data_length;
+    2475                 :            :     uint8_t* measurement_record_data;
+    2476                 :            :     uint8_t* ptr;
+    2477                 :            :     uint16_t opaque_length;
+    2478                 :            :     void* signature;
+    2479                 :            :     size_t signature_size;
+    2480                 :            :     libspdm_session_info_t* session_info;
+    2481                 :            :     void* data;
+    2482                 :            :     size_t data_size;
+    2483                 :            :     void* hash;
+    2484                 :            :     size_t hash_size;
+    2485                 :            : 
+    2486                 :          1 :     spdm_test_context = *state;
+    2487                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2488                 :          1 :     spdm_test_context->case_id = 34;
+    2489                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
+    2490                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2491                 :          1 :     spdm_context->connection_info.connection_state =
+    2492                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    2493                 :          1 :     spdm_context->local_context.capability.flags |=
+    2494                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    2495                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    2496                 :            :         m_libspdm_use_hash_algo;
+    2497                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    2498                 :            :         m_libspdm_use_asym_algo;
+    2499                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    2500                 :            :         m_libspdm_use_measurement_spec;
+    2501                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    2502                 :            :         m_libspdm_use_measurement_hash_algo;
+    2503                 :          1 :     spdm_context->spdm_10_11_verify_signature_endian =
+    2504                 :            :         LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_OR_LITTLE;
+    2505                 :            : 
+    2506                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    2507                 :          1 :     libspdm_secret_lib_meas_opaque_data_size = 0;
+    2508                 :          1 :     measurment_sig_size = SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
+    2509                 :          1 :                           libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    2510                 :            : 
+    2511                 :          1 :     response_size = sizeof(response);
+    2512                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
+    2513                 :            :                               m_libspdm_get_measurements_request5.nonce);
+    2514                 :          1 :     status = libspdm_get_response_measurements(
+    2515                 :            :         spdm_context, m_libspdm_get_measurements_request5_size,
+    2516                 :            :         &m_libspdm_get_measurements_request5, &response_size, response);
+    2517                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2518                 :          1 :     assert_int_equal(response_size, sizeof(spdm_measurements_response_t) +
+    2519                 :            :                      measurment_sig_size);
+    2520                 :          1 :     spdm_response = (void*)response;
+    2521                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    2522                 :            :                      SPDM_MEASUREMENTS);
+    2523                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    2524                 :            :                      LIBSPDM_MEASUREMENT_BLOCK_NUMBER);
+    2525                 :            : 
+    2526                 :          1 :     libspdm_read_responder_public_certificate_chain(
+    2527                 :            :         m_libspdm_use_hash_algo, m_libspdm_use_asym_algo,
+    2528                 :            :         &data, &data_size,
+    2529                 :            :         &hash, &hash_size);
+    2530                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    2531                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
+    2532                 :            :         data_size;
+    2533                 :            :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+    2534                 :            :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+    2535                 :            :                      data, data_size);
+    2536                 :            : #else
+    2537                 :          1 :     libspdm_hash_all(
+    2538                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    2539                 :            :         data, data_size,
+    2540                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+    2541                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+    2542                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+    2543                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+    2544                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    2545                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+    2546                 :            :         data, data_size,
+    2547                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+    2548                 :            : #endif
+    2549                 :            : 
+    2550                 :          1 :     measurement_record_data_length = libspdm_read_uint24(spdm_response->measurement_record_length);
+    2551                 :          1 :     measurement_record_data = (void*)(spdm_response + 1);
+    2552                 :          1 :     ptr = measurement_record_data + measurement_record_data_length;
+    2553                 :          1 :     ptr += SPDM_NONCE_SIZE;
+    2554                 :          1 :     opaque_length = libspdm_read_uint16((const uint8_t*)ptr);
+    2555                 :          1 :     ptr += sizeof(uint16_t);
+    2556                 :          1 :     ptr += opaque_length;
+    2557                 :          1 :     signature = ptr;
+    2558                 :          1 :     signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
+    2559                 :          1 :     libspdm_copy_signature_swap_endian(
+    2560                 :            :         m_libspdm_use_asym_algo,
+    2561                 :            :         signature, signature_size, signature, signature_size);
+    2562                 :            : 
+    2563                 :          1 :     session_info = NULL;
+    2564                 :            : 
+    2565                 :          1 :     status = libspdm_append_message_m(
+    2566                 :            :         spdm_context, session_info,
+    2567                 :            :         &m_libspdm_get_measurements_request5,
+    2568                 :            :         m_libspdm_get_measurements_request5_size);
+    2569                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2570                 :            : 
+    2571                 :          1 :     status = libspdm_append_message_m(
+    2572                 :            :         spdm_context, session_info, spdm_response,
+    2573                 :            :         response_size - signature_size);
+    2574                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2575                 :            : 
+    2576                 :          1 :     result = libspdm_verify_measurement_signature(
+    2577                 :            :         spdm_context, session_info, signature, signature_size);
+    2578                 :          1 :     assert_true(result == true);
+    2579                 :            : 
+    2580                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    2581                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+    2582                 :            : #endif
+    2583                 :          1 : }
+    2584                 :            : 
+    2585                 :            : /**
+    2586                 :            :  * Test 35: Successful response V1.3 to get a number of measurements without signature
+    2587                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code, correct context field
+    2588                 :            :  **/
+    2589                 :          1 : void libspdm_test_responder_measurements_case35(void **state)
+    2590                 :            : {
+    2591                 :            :     libspdm_return_t status;
+    2592                 :            :     libspdm_test_context_t *spdm_test_context;
+    2593                 :            :     libspdm_context_t *spdm_context;
+    2594                 :            :     size_t response_size;
+    2595                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    2596                 :            :     spdm_measurements_response_t *spdm_response;
+    2597                 :            :     uint8_t *requester_context;
+    2598                 :            :     uint8_t *responder_context;
+    2599                 :            : 
+    2600                 :          1 :     spdm_test_context = *state;
+    2601                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2602                 :          1 :     spdm_test_context->case_id = 35;
+    2603                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+    2604                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2605                 :          1 :     spdm_context->connection_info.connection_state =
+    2606                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    2607                 :          1 :     spdm_context->local_context.capability.flags |=
+    2608                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    2609                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    2610                 :            :         m_libspdm_use_hash_algo;
+    2611                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    2612                 :            :         m_libspdm_use_asym_algo;
+    2613                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    2614                 :            :         m_libspdm_use_measurement_spec;
+    2615                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    2616                 :            :         m_libspdm_use_measurement_hash_algo;
+    2617                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    2618                 :            : 
+    2619                 :          1 :     libspdm_secret_lib_meas_opaque_data_size = 0;
+    2620                 :            : 
+    2621                 :          1 :     response_size = sizeof(response);
+    2622                 :            : 
+    2623                 :          1 :     requester_context = ((uint8_t *)&m_libspdm_get_measurements_request17) +
+    2624                 :            :                         m_libspdm_get_measurements_request17_size;
+    2625                 :          1 :     libspdm_set_mem(requester_context, SPDM_REQ_CONTEXT_SIZE, 0xAA);
+    2626                 :          1 :     m_libspdm_get_measurements_request17_size += SPDM_REQ_CONTEXT_SIZE;
+    2627                 :            : 
+    2628                 :          1 :     status = libspdm_get_response_measurements(
+    2629                 :            :         spdm_context, m_libspdm_get_measurements_request17_size,
+    2630                 :            :         &m_libspdm_get_measurements_request17, &response_size, response);
+    2631                 :            : 
+    2632                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2633                 :          1 :     assert_int_equal(response_size,
+    2634                 :            :                      sizeof(spdm_measurements_response_t) + SPDM_NONCE_SIZE + sizeof(uint16_t) +
+    2635                 :            :                      SPDM_REQ_CONTEXT_SIZE);
+    2636                 :          1 :     spdm_response = (void *)response;
+    2637                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    2638                 :            :                      SPDM_MEASUREMENTS);
+    2639                 :          1 :     responder_context = (void *)response;
+    2640                 :          1 :     responder_context += sizeof(spdm_measurements_response_t) + SPDM_NONCE_SIZE + sizeof(uint16_t);
+    2641                 :          1 :     assert_memory_equal((void *)requester_context, responder_context, SPDM_REQ_CONTEXT_SIZE);
+    2642                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    2643                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
+    2644                 :            :                      m_libspdm_get_measurements_request17_size +
+    2645                 :            :                      sizeof(spdm_measurements_response_t) +
+    2646                 :            :                      SPDM_NONCE_SIZE +
+    2647                 :            :                      sizeof(uint16_t) +
+    2648                 :            :                      SPDM_REQ_CONTEXT_SIZE);
+    2649                 :            : #endif
+    2650                 :          1 : }
+    2651                 :            : 
+    2652                 :            : /**
+    2653                 :            :  * Test 36: The key usage bit mask is not set, the SlotID fields in GET_MEASUREMENTS and MEASUREMENTS shall not specify this certificate slot
+    2654                 :            :  * Expected Behavior: get a SPDM_ERROR_CODE_INVALID_REQUEST return code
+    2655                 :            :  **/
+    2656                 :          1 : void libspdm_test_responder_measurements_case36(void **state)
+    2657                 :            : {
+    2658                 :            :     libspdm_return_t status;
+    2659                 :            :     libspdm_test_context_t *spdm_test_context;
+    2660                 :            :     libspdm_context_t *spdm_context;
+    2661                 :            :     size_t response_size;
+    2662                 :            :     uint8_t request[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    2663                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    2664                 :            :     spdm_get_measurements_request_t *spdm_request;
+    2665                 :            :     spdm_measurements_response_t *spdm_response;
+    2666                 :            :     uint8_t *requester_context;
+    2667                 :            :     uint8_t slot_id;
+    2668                 :            :     void *data;
+    2669                 :            :     size_t data_size;
+    2670                 :            :     size_t request_size;
+    2671                 :            : 
+    2672                 :          1 :     spdm_test_context = *state;
+    2673                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    2674                 :          1 :     spdm_test_context->case_id = 36;
+    2675                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+    2676                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    2677                 :          1 :     spdm_context->connection_info.connection_state =
+    2678                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+    2679                 :          1 :     spdm_context->local_context.capability.flags |=
+    2680                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+    2681                 :          1 :     spdm_context->local_context.capability.flags |=
+    2682                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PUB_KEY_ID_CAP;
+    2683                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    2684                 :            :         m_libspdm_use_hash_algo;
+    2685                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    2686                 :            :         m_libspdm_use_asym_algo;
+    2687                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    2688                 :            :         m_libspdm_use_measurement_hash_algo;
+    2689                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    2690                 :            :         m_libspdm_use_hash_algo;
+    2691                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    2692                 :            :         m_libspdm_use_measurement_spec;
+    2693                 :          1 :     spdm_context->connection_info.multi_key_conn_rsp = true;
+    2694                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+    2695                 :            : 
+    2696                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    2697                 :            :                                                     m_libspdm_use_asym_algo, &data,
+    2698                 :            :                                                     &data_size, NULL, NULL);
+    2699         [ +  + ]:          9 :     for (int i = 0; i < SPDM_MAX_SLOT_COUNT; i++) {
+    2700                 :          8 :         spdm_context->local_context.local_cert_chain_provision_size[i] = data_size;
+    2701                 :          8 :         spdm_context->local_context.local_cert_chain_provision[i] = data;
+    2702                 :            :     }
+    2703                 :            : 
+    2704                 :          1 :     spdm_request = (void *)request;
+    2705                 :          1 :     spdm_request->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+    2706                 :          1 :     spdm_request->header.request_response_code = SPDM_GET_MEASUREMENTS;
+    2707                 :          1 :     spdm_request->header.param1 = SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
+    2708                 :          1 :     spdm_request->header.param2 = 1;
+    2709                 :          1 :     libspdm_get_random_number(SPDM_NONCE_SIZE, spdm_request->nonce);
+    2710                 :            :     /* If set, the SlotID fields in GET_MEASUREMENTS and MEASUREMENTS can specify this certificate slot. If not set,
+    2711                 :            :      * the SlotID fields in GET_MEASUREMENTS and MEASUREMENTS shall not specify this certificate slot. */
+    2712                 :          1 :     slot_id = 0;
+    2713                 :          1 :     spdm_request->slot_id_param = slot_id;
+    2714                 :          1 :     spdm_context->local_context.local_key_usage_bit_mask[slot_id] =
+    2715                 :            :         SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE |
+    2716                 :            :         SPDM_KEY_USAGE_BIT_MASK_CHALLENGE_USE;
+    2717                 :          1 :     requester_context = ((uint8_t *)spdm_request) + sizeof(spdm_get_measurements_request_t);
+    2718                 :          1 :     libspdm_set_mem(requester_context, SPDM_REQ_CONTEXT_SIZE, 0xAA);
+    2719                 :          1 :     request_size = sizeof(spdm_get_measurements_request_t) + SPDM_REQ_CONTEXT_SIZE;
+    2720                 :            : 
+    2721                 :          1 :     response_size = sizeof(response);
+    2722                 :          1 :     status = libspdm_get_response_measurements(
+    2723                 :            :         spdm_context, request_size,
+    2724                 :            :         (void *)spdm_request, &response_size, response);
+    2725                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    2726                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    2727                 :          1 :     spdm_response = (void *)response;
+    2728                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
+    2729                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+    2730                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    2731                 :          1 : }
+    2732                 :            : 
+    2733                 :            : libspdm_test_context_t m_libspdm_responder_measurements_test_context = {
+    2734                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+    2735                 :            :     false,
+    2736                 :            : };
+    2737                 :            : 
+    2738                 :          1 : int libspdm_responder_measurements_test_main(void)
+    2739                 :            : {
+    2740                 :          1 :     m_libspdm_get_measurements_request11.slot_id_param = SPDM_MAX_SLOT_COUNT - 1;
+    2741                 :          1 :     m_libspdm_get_measurements_request12.slot_id_param = SPDM_MAX_SLOT_COUNT + 1;
+    2742                 :            : 
+    2743                 :          1 :     const struct CMUnitTest spdm_responder_measurements_tests[] = {
+    2744                 :            :         /* Success Case to get measurement number without signature*/
+    2745                 :            :         cmocka_unit_test(libspdm_test_responder_measurements_case1),
+    2746                 :            :         /* Can be populated with new test.*/
+    2747                 :            :         cmocka_unit_test(libspdm_test_responder_measurements_case2),
+    2748                 :            :         /* response_state: SPDM_RESPONSE_STATE_BUSY*/
+    2749                 :            :         cmocka_unit_test(libspdm_test_responder_measurements_case3),
+    2750                 :            :         /* response_state: SPDM_RESPONSE_STATE_NEED_RESYNC*/
+    2751                 :            :         cmocka_unit_test(libspdm_test_responder_measurements_case4),
+    2752                 :            :         #if LIBSPDM_RESPOND_IF_READY_SUPPORT
+    2753                 :            :         /* response_state: SPDM_RESPONSE_STATE_NOT_READY*/
+    2754                 :            :         cmocka_unit_test(libspdm_test_responder_measurements_case5),
+    2755                 :            :         #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
+    2756                 :            :         /* connection_state Check*/
+    2757                 :            :         cmocka_unit_test(libspdm_test_responder_measurements_case6),
+    2758                 :            :         /* Success Case to get measurement number with signature*/
+    2759                 :            :         cmocka_unit_test(libspdm_test_responder_measurements_case7),
+    2760                 :            :         /* Success Case to get one measurement with signature*/
+    2761                 :            :         cmocka_unit_test(libspdm_test_responder_measurements_case8),
+    2762                 :            :         /* Bad request size to get one measurement with signature*/
+    2763                 :            :         cmocka_unit_test(libspdm_test_responder_measurements_case9),
+    2764                 :            :         /* Success Case to get one measurement without signature*/
+    2765                 :            :         cmocka_unit_test(libspdm_test_responder_measurements_case10),
+    2766                 :            :         /* Success Case to get all measurements with signature*/
+    2767                 :            :         cmocka_unit_test(libspdm_test_responder_measurements_case11),
+    2768                 :            :         /* Success Case to get all measurements without signature*/
+    2769                 :            :         cmocka_unit_test(libspdm_test_responder_measurements_case12),
+    2770                 :            :         /* Can be populated with new test.*/
+    2771                 :            :         cmocka_unit_test(libspdm_test_responder_measurements_case13),
+    2772                 :            :         /* Error Case: sig required, but no nonce and/or SlotID*/
+    2773                 :            :         cmocka_unit_test(libspdm_test_responder_measurements_case14),
+    2774                 :            :         /* Error Case: sig required, but meas_cap = 01b (including nonce and SlotId on request)*/
+    2775                 :            :         cmocka_unit_test(libspdm_test_responder_measurements_case15),
+    2776                 :            :         /* Error Case: sig required, but meas_cap = 01b (not including nonce and SlotId on request)*/
+    2777                 :            :         cmocka_unit_test(libspdm_test_responder_measurements_case16),
+    2778                 :            :         /* Error Case: meas_cap = 00b*/
+    2779                 :            :         cmocka_unit_test(libspdm_test_responder_measurements_case17),
+    2780                 :            :         /* Success Case: SlotId different from default*/
+    2781                 :            :         cmocka_unit_test(libspdm_test_responder_measurements_case18),
+    2782                 :            :         /* Bad SlotId parameter (>= SPDM_MAX_SLOT_COUNT)*/
+    2783                 :            :         cmocka_unit_test(libspdm_test_responder_measurements_case19),
+    2784                 :            :         /* Error Case: request a measurement out of bounds*/
+    2785                 :            :         cmocka_unit_test(libspdm_test_responder_measurements_case21),
+    2786                 :            :         /* Large number of requests before requiring a signature*/
+    2787                 :            :         cmocka_unit_test(libspdm_test_responder_measurements_case22),
+    2788                 :            :         /* Successful response to get a session based measurement with signature*/
+    2789                 :            :         cmocka_unit_test(libspdm_test_responder_measurements_case23),
+    2790                 :            :         /* Buffer verification */
+    2791                 :            :         cmocka_unit_test(libspdm_test_responder_measurements_case24),
+    2792                 :            :         /* Success Case V1.2 to get one measurement without signature*/
+    2793                 :            :         cmocka_unit_test(libspdm_test_responder_measurements_case25),
+    2794                 :            :         /* Successful response V1.2 to get one measurement with signature and without opqaue data*/
+    2795                 :            :         cmocka_unit_test(libspdm_test_responder_measurements_case26),
+    2796                 :            :         /* Successful response V1.2 to get one measurement with signature and with opqaue data*/
+    2797                 :            :         cmocka_unit_test(libspdm_test_responder_measurements_case27),
+    2798                 :            :         /* Success Case to get measurement with signature using slot_id 0xFF */
+    2799                 :            :         cmocka_unit_test(libspdm_test_responder_measurements_case28),
+    2800                 :            :         /* Error Case: Big Endian Signature. Little Endian Verify */
+    2801                 :            :         cmocka_unit_test(libspdm_test_responder_measurements_case29),
+    2802                 :            :         /* Success Case: Big Endian Signature. Big Endian Verify */
+    2803                 :            :         cmocka_unit_test(libspdm_test_responder_measurements_case30),
+    2804                 :            :         /* Success Case: Big Endian Signature. Big or Little Endian Verify */
+    2805                 :            :         cmocka_unit_test(libspdm_test_responder_measurements_case31),
+    2806                 :            :         /* Success Case: Little Endian Signature. Little Endian Verify */
+    2807                 :            :         cmocka_unit_test(libspdm_test_responder_measurements_case32),
+    2808                 :            :         /* Error Case: Little Endian Signature. Big Endian Verify */
+    2809                 :            :         cmocka_unit_test(libspdm_test_responder_measurements_case33),
+    2810                 :            :         /* Success Case: Little Endian Signature. Big or Little Endian Verify */
+    2811                 :            :         cmocka_unit_test(libspdm_test_responder_measurements_case34),
+    2812                 :            :         /* Success Case: V1.3 get a correct context field */
+    2813                 :            :         cmocka_unit_test(libspdm_test_responder_measurements_case35),
+    2814                 :            :         /* The key usage bit mask is not set, failed Case*/
+    2815                 :            :         cmocka_unit_test(libspdm_test_responder_measurements_case36),
+    2816                 :            :     };
+    2817                 :            : 
+    2818                 :          1 :     libspdm_setup_test_context(&m_libspdm_responder_measurements_test_context);
+    2819                 :            : 
+    2820                 :          1 :     return cmocka_run_group_tests(spdm_responder_measurements_tests,
+    2821                 :            :                                   libspdm_unit_test_group_setup,
+    2822                 :            :                                   libspdm_unit_test_group_teardown);
+    2823                 :            : }
+    2824                 :            : 
+    2825                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/psk_exchange.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_responder/psk_exchange.c.func-sort-c.html new file mode 100644 index 00000000000..eaf015edf80 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/psk_exchange.c.func-sort-c.html @@ -0,0 +1,153 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/psk_exchange.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - psk_exchange.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:78278499.7 %
Date:2024-09-22 08:21:07Functions:1818100.0 %
Branches:81650.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_psk_exchange_test_main1
libspdm_test_responder_psk_exchange_case11
libspdm_test_responder_psk_exchange_case101
libspdm_test_responder_psk_exchange_case111
libspdm_test_responder_psk_exchange_case121
libspdm_test_responder_psk_exchange_case131
libspdm_test_responder_psk_exchange_case141
libspdm_test_responder_psk_exchange_case151
libspdm_test_responder_psk_exchange_case161
libspdm_test_responder_psk_exchange_case171
libspdm_test_responder_psk_exchange_case21
libspdm_test_responder_psk_exchange_case31
libspdm_test_responder_psk_exchange_case41
libspdm_test_responder_psk_exchange_case51
libspdm_test_responder_psk_exchange_case61
libspdm_test_responder_psk_exchange_case71
libspdm_test_responder_psk_exchange_case81
libspdm_test_responder_psk_exchange_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/psk_exchange.c.func.html b/coverage_log/unit_test/test_spdm_responder/psk_exchange.c.func.html new file mode 100644 index 00000000000..5b77c0498fa --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/psk_exchange.c.func.html @@ -0,0 +1,153 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/psk_exchange.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - psk_exchange.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:78278499.7 %
Date:2024-09-22 08:21:07Functions:1818100.0 %
Branches:81650.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_psk_exchange_test_main1
libspdm_test_responder_psk_exchange_case11
libspdm_test_responder_psk_exchange_case101
libspdm_test_responder_psk_exchange_case111
libspdm_test_responder_psk_exchange_case121
libspdm_test_responder_psk_exchange_case131
libspdm_test_responder_psk_exchange_case141
libspdm_test_responder_psk_exchange_case151
libspdm_test_responder_psk_exchange_case161
libspdm_test_responder_psk_exchange_case171
libspdm_test_responder_psk_exchange_case21
libspdm_test_responder_psk_exchange_case31
libspdm_test_responder_psk_exchange_case41
libspdm_test_responder_psk_exchange_case51
libspdm_test_responder_psk_exchange_case61
libspdm_test_responder_psk_exchange_case71
libspdm_test_responder_psk_exchange_case81
libspdm_test_responder_psk_exchange_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/psk_exchange.c.gcov.html b/coverage_log/unit_test/test_spdm_responder/psk_exchange.c.gcov.html new file mode 100644 index 00000000000..02867958409 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/psk_exchange.c.gcov.html @@ -0,0 +1,1863 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/psk_exchange.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - psk_exchange.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:78278499.7 %
Date:2024-09-22 08:21:07Functions:1818100.0 %
Branches:81650.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_responder_lib.h"
+       9                 :            : #include "internal/libspdm_requester_lib.h"
+      10                 :            : 
+      11                 :            : #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
+      12                 :            : 
+      13                 :            : #pragma pack(1)
+      14                 :            : 
+      15                 :            : typedef struct {
+      16                 :            :     spdm_message_header_t header;
+      17                 :            :     uint16_t req_session_id;
+      18                 :            :     uint16_t psk_hint_length;
+      19                 :            :     uint16_t context_length;
+      20                 :            :     uint16_t opaque_length;
+      21                 :            :     uint8_t psk_hint[LIBSPDM_PSK_MAX_HINT_LENGTH];
+      22                 :            :     uint8_t context[LIBSPDM_PSK_CONTEXT_LENGTH];
+      23                 :            :     uint8_t opaque_data[SPDM_MAX_OPAQUE_DATA_SIZE];
+      24                 :            : } libspdm_psk_exchange_request_mine_t;
+      25                 :            : 
+      26                 :            : typedef struct {
+      27                 :            :     spdm_message_header_t header;
+      28                 :            :     uint16_t req_session_id;
+      29                 :            :     uint16_t psk_hint_length;
+      30                 :            :     uint16_t context_length;
+      31                 :            :     uint16_t opaque_length;
+      32                 :            :     uint8_t context[LIBSPDM_PSK_CONTEXT_LENGTH];
+      33                 :            :     uint8_t opaque_data[SPDM_MAX_OPAQUE_DATA_SIZE];
+      34                 :            : } libspdm_psk_exchange_request_mine_t_noPSKHINT;
+      35                 :            : 
+      36                 :            : typedef struct {
+      37                 :            :     spdm_message_header_t header;
+      38                 :            :     uint16_t req_session_id;
+      39                 :            :     uint16_t psk_hint_length;
+      40                 :            :     uint16_t context_length;
+      41                 :            :     uint16_t opaque_length;
+      42                 :            :     uint8_t psk_hint[LIBSPDM_PSK_MAX_HINT_LENGTH];
+      43                 :            :     uint8_t context[LIBSPDM_PSK_CONTEXT_LENGTH];
+      44                 :            : } libspdm_psk_exchange_request_mine_t_noOPAQUE;
+      45                 :            : 
+      46                 :            : typedef struct {
+      47                 :            :     spdm_message_header_t header;
+      48                 :            :     uint16_t req_session_id;
+      49                 :            :     uint16_t psk_hint_length;
+      50                 :            :     uint16_t context_length;
+      51                 :            :     uint16_t opaque_length;
+      52                 :            :     uint8_t context[LIBSPDM_PSK_CONTEXT_LENGTH];
+      53                 :            : } libspdm_psk_exchange_request_mine_t_noPSKHINT_noOPAQUE;
+      54                 :            : 
+      55                 :            : #pragma pack()
+      56                 :            : 
+      57                 :            : 
+      58                 :            : libspdm_psk_exchange_request_mine_t m_libspdm_psk_exchange_request1 = {
+      59                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_PSK_EXCHANGE,
+      60                 :            :       SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0 },
+      61                 :            : };
+      62                 :            : size_t m_libspdm_psk_exchange_request1_size = sizeof(m_libspdm_psk_exchange_request1);
+      63                 :            : 
+      64                 :            : libspdm_psk_exchange_request_mine_t m_libspdm_psk_exchange_request2 = {
+      65                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_PSK_EXCHANGE,
+      66                 :            :       SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0 },
+      67                 :            : };
+      68                 :            : size_t m_libspdm_psk_exchange_request2_size = sizeof(spdm_psk_exchange_request_t);
+      69                 :            : 
+      70                 :            : libspdm_psk_exchange_request_mine_t m_libspdm_psk_exchange_request3 = {
+      71                 :            :     { SPDM_MESSAGE_VERSION_12, SPDM_PSK_EXCHANGE,
+      72                 :            :       SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0 },
+      73                 :            : };
+      74                 :            : size_t m_libspdm_psk_exchange_request3_size = sizeof(m_libspdm_psk_exchange_request3);
+      75                 :            : 
+      76                 :            : /* Request TCB measurement hash */
+      77                 :            : libspdm_psk_exchange_request_mine_t m_libspdm_psk_exchange_request4 = {
+      78                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_PSK_EXCHANGE,
+      79                 :            :       SPDM_PSK_EXCHANGE_REQUEST_TCB_COMPONENT_MEASUREMENT_HASH, 0 },
+      80                 :            : };
+      81                 :            : size_t m_libspdm_psk_exchange_request4_size = sizeof(m_libspdm_psk_exchange_request4);
+      82                 :            : 
+      83                 :            : /* Request all measurement hash */
+      84                 :            : libspdm_psk_exchange_request_mine_t m_libspdm_psk_exchange_request5 = {
+      85                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_PSK_EXCHANGE,
+      86                 :            :       SPDM_PSK_EXCHANGE_REQUEST_ALL_MEASUREMENTS_HASH, 0 },
+      87                 :            : };
+      88                 :            : size_t m_libspdm_psk_exchange_request5_size = sizeof(m_libspdm_psk_exchange_request5);
+      89                 :            : 
+      90                 :            : /* Uses a reserved value in measurement hash */
+      91                 :            : libspdm_psk_exchange_request_mine_t m_libspdm_psk_exchange_request6 = {
+      92                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_PSK_EXCHANGE,
+      93                 :            :       0x50, 0 },
+      94                 :            : };
+      95                 :            : size_t m_libspdm_psk_exchange_request6_size = sizeof(m_libspdm_psk_exchange_request6);
+      96                 :            : 
+      97                 :            : libspdm_psk_exchange_request_mine_t_noPSKHINT m_libspdm_psk_exchange_request7 = {
+      98                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_PSK_EXCHANGE,
+      99                 :            :       SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0 },
+     100                 :            : };
+     101                 :            : size_t m_libspdm_psk_exchange_request7_size = sizeof(m_libspdm_psk_exchange_request7);
+     102                 :            : 
+     103                 :            : libspdm_psk_exchange_request_mine_t_noOPAQUE m_libspdm_psk_exchange_request8 = {
+     104                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_PSK_EXCHANGE,
+     105                 :            :       SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0 },
+     106                 :            : };
+     107                 :            : size_t m_libspdm_psk_exchange_request8_size = sizeof(m_libspdm_psk_exchange_request8);
+     108                 :            : 
+     109                 :            : libspdm_psk_exchange_request_mine_t_noPSKHINT_noOPAQUE m_libspdm_psk_exchange_request9 = {
+     110                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_PSK_EXCHANGE,
+     111                 :            :       SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0 },
+     112                 :            : };
+     113                 :            : size_t m_libspdm_psk_exchange_request9_size = sizeof(m_libspdm_psk_exchange_request9);
+     114                 :            : 
+     115                 :          1 : void libspdm_test_responder_psk_exchange_case1(void **state)
+     116                 :            : {
+     117                 :            :     libspdm_return_t status;
+     118                 :            :     libspdm_test_context_t *spdm_test_context;
+     119                 :            :     libspdm_context_t *spdm_context;
+     120                 :            :     size_t response_size;
+     121                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     122                 :            :     spdm_psk_exchange_response_t *spdm_response;
+     123                 :            :     void *data1;
+     124                 :            :     size_t data_size1;
+     125                 :            :     uint8_t *ptr;
+     126                 :            :     size_t opaque_psk_exchange_req_size;
+     127                 :            : 
+     128                 :          1 :     spdm_test_context = *state;
+     129                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     130                 :          1 :     spdm_test_context->case_id = 0x1;
+     131                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     132                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     133                 :          1 :     spdm_context->connection_info.connection_state =
+     134                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     135                 :          1 :     spdm_context->connection_info.capability.flags |=
+     136                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     137                 :          1 :     spdm_context->local_context.capability.flags |=
+     138                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     139                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     140                 :            :         m_libspdm_use_hash_algo;
+     141                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     142                 :            :         m_libspdm_use_measurement_spec;
+     143                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     144                 :            :         m_libspdm_use_measurement_hash_algo;
+     145                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     146                 :            :         m_libspdm_use_dhe_algo;
+     147                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     148                 :            :         m_libspdm_use_aead_algo;
+     149                 :          1 :     spdm_context->connection_info.algorithm.key_schedule =
+     150                 :            :         m_libspdm_use_key_schedule_algo;
+     151                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     152                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     153                 :            :                                                     &data_size1, NULL, NULL);
+     154                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     155                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     156                 :            :         data_size1;
+     157                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+     158                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+     159                 :            :         data_size1;
+     160                 :            : 
+     161                 :          1 :     libspdm_reset_message_a(spdm_context);
+     162                 :            : 
+     163                 :          1 :     m_libspdm_psk_exchange_request1.psk_hint_length =
+     164                 :            :         (uint16_t)sizeof(LIBSPDM_TEST_PSK_HINT_STRING);
+     165                 :          1 :     m_libspdm_psk_exchange_request1.context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
+     166                 :          1 :     opaque_psk_exchange_req_size =
+     167                 :          1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
+     168                 :          1 :     m_libspdm_psk_exchange_request1.opaque_length =
+     169                 :          1 :         (uint16_t)opaque_psk_exchange_req_size;
+     170                 :          1 :     m_libspdm_psk_exchange_request1.req_session_id = 0xFFFF;
+     171                 :          1 :     ptr = m_libspdm_psk_exchange_request1.psk_hint;
+     172                 :          1 :     libspdm_copy_mem(ptr, sizeof(m_libspdm_psk_exchange_request1.psk_hint),
+     173                 :            :                      LIBSPDM_TEST_PSK_HINT_STRING,
+     174                 :            :                      sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+     175                 :          1 :     ptr += m_libspdm_psk_exchange_request1.psk_hint_length;
+     176                 :          1 :     libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
+     177                 :          1 :     ptr += m_libspdm_psk_exchange_request1.context_length;
+     178                 :          1 :     libspdm_build_opaque_data_supported_version_data(
+     179                 :            :         spdm_context, &opaque_psk_exchange_req_size, ptr);
+     180                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     181                 :            :     spdm_context->transcript.message_m.buffer_size =
+     182                 :            :         spdm_context->transcript.message_m.max_buffer_size;
+     183                 :            : #endif
+     184                 :          1 :     ptr += opaque_psk_exchange_req_size;
+     185                 :          1 :     response_size = sizeof(response);
+     186                 :          1 :     status = libspdm_get_response_psk_exchange(
+     187                 :            :         spdm_context, m_libspdm_psk_exchange_request1_size,
+     188                 :            :         &m_libspdm_psk_exchange_request1, &response_size, response);
+     189                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     190                 :          1 :     assert_int_equal(
+     191                 :            :         libspdm_secured_message_get_session_state(
+     192                 :            :             spdm_context->session_info[0].secured_message_context),
+     193                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+     194                 :          1 :     spdm_response = (void *)response;
+     195                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     196                 :            :                      SPDM_PSK_EXCHANGE_RSP);
+     197                 :          1 :     assert_int_equal(spdm_response->rsp_session_id, 0xFFFF);
+     198                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     199                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
+     200                 :            :                      0);
+     201                 :            : #endif
+     202                 :          1 :     free(data1);
+     203                 :          1 : }
+     204                 :            : 
+     205                 :          1 : void libspdm_test_responder_psk_exchange_case2(void **state)
+     206                 :            : {
+     207                 :            :     libspdm_return_t status;
+     208                 :            :     libspdm_test_context_t *spdm_test_context;
+     209                 :            :     libspdm_context_t *spdm_context;
+     210                 :            :     size_t response_size;
+     211                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     212                 :            :     spdm_psk_exchange_response_t *spdm_response;
+     213                 :            :     void *data1;
+     214                 :            :     size_t data_size1;
+     215                 :            :     uint8_t *ptr;
+     216                 :            :     size_t opaque_psk_exchange_req_size;
+     217                 :            : 
+     218                 :          1 :     spdm_test_context = *state;
+     219                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     220                 :          1 :     spdm_test_context->case_id = 0x2;
+     221                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     222                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     223                 :          1 :     spdm_context->connection_info.connection_state =
+     224                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     225                 :          1 :     spdm_context->connection_info.capability.flags |=
+     226                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     227                 :          1 :     spdm_context->local_context.capability.flags |=
+     228                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     229                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     230                 :            :         m_libspdm_use_hash_algo;
+     231                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     232                 :            :         m_libspdm_use_measurement_spec;
+     233                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     234                 :            :         m_libspdm_use_measurement_hash_algo;
+     235                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     236                 :            :         m_libspdm_use_dhe_algo;
+     237                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     238                 :            :         m_libspdm_use_aead_algo;
+     239                 :          1 :     spdm_context->connection_info.algorithm.key_schedule =
+     240                 :            :         m_libspdm_use_key_schedule_algo;
+     241                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     242                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     243                 :            :                                                     &data_size1, NULL, NULL);
+     244                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     245                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     246                 :            :         data_size1;
+     247                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+     248                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+     249                 :            :         data_size1;
+     250                 :            : 
+     251                 :          1 :     libspdm_reset_message_a(spdm_context);
+     252                 :            : 
+     253                 :          1 :     m_libspdm_psk_exchange_request2.psk_hint_length =
+     254                 :            :         (uint16_t)sizeof(LIBSPDM_TEST_PSK_HINT_STRING);
+     255                 :          1 :     m_libspdm_psk_exchange_request2.context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
+     256                 :          1 :     opaque_psk_exchange_req_size =
+     257                 :          1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
+     258                 :          1 :     m_libspdm_psk_exchange_request2.opaque_length =
+     259                 :          1 :         (uint16_t)opaque_psk_exchange_req_size;
+     260                 :          1 :     m_libspdm_psk_exchange_request2.req_session_id = 0xFFFF;
+     261                 :          1 :     ptr = m_libspdm_psk_exchange_request2.psk_hint;
+     262                 :          1 :     libspdm_copy_mem(ptr, sizeof(m_libspdm_psk_exchange_request2.psk_hint),
+     263                 :            :                      LIBSPDM_TEST_PSK_HINT_STRING,
+     264                 :            :                      sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+     265                 :          1 :     ptr += m_libspdm_psk_exchange_request2.psk_hint_length;
+     266                 :          1 :     libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
+     267                 :          1 :     ptr += m_libspdm_psk_exchange_request2.context_length;
+     268                 :          1 :     libspdm_build_opaque_data_supported_version_data(
+     269                 :            :         spdm_context, &opaque_psk_exchange_req_size, ptr);
+     270                 :          1 :     ptr += opaque_psk_exchange_req_size;
+     271                 :          1 :     response_size = sizeof(response);
+     272                 :          1 :     status = libspdm_get_response_psk_exchange(
+     273                 :            :         spdm_context, m_libspdm_psk_exchange_request2_size,
+     274                 :            :         &m_libspdm_psk_exchange_request2, &response_size, response);
+     275                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     276                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     277                 :          1 :     spdm_response = (void *)response;
+     278                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     279                 :            :                      SPDM_ERROR);
+     280                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     281                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+     282                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     283                 :          1 :     free(data1);
+     284                 :          1 : }
+     285                 :            : 
+     286                 :          1 : void libspdm_test_responder_psk_exchange_case3(void **state)
+     287                 :            : {
+     288                 :            :     libspdm_return_t status;
+     289                 :            :     libspdm_test_context_t *spdm_test_context;
+     290                 :            :     libspdm_context_t *spdm_context;
+     291                 :            :     size_t response_size;
+     292                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     293                 :            :     spdm_psk_exchange_response_t *spdm_response;
+     294                 :            :     void *data1;
+     295                 :            :     size_t data_size1;
+     296                 :            :     uint8_t *ptr;
+     297                 :            :     size_t opaque_psk_exchange_req_size;
+     298                 :            : 
+     299                 :          1 :     spdm_test_context = *state;
+     300                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     301                 :          1 :     spdm_test_context->case_id = 0x3;
+     302                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     303                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     304                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_BUSY;
+     305                 :          1 :     spdm_context->connection_info.connection_state =
+     306                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     307                 :          1 :     spdm_context->connection_info.capability.flags |=
+     308                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     309                 :          1 :     spdm_context->local_context.capability.flags |=
+     310                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     311                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     312                 :            :         m_libspdm_use_hash_algo;
+     313                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     314                 :            :         m_libspdm_use_measurement_spec;
+     315                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     316                 :            :         m_libspdm_use_measurement_hash_algo;
+     317                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     318                 :            :         m_libspdm_use_dhe_algo;
+     319                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     320                 :            :         m_libspdm_use_aead_algo;
+     321                 :          1 :     spdm_context->connection_info.algorithm.key_schedule =
+     322                 :            :         m_libspdm_use_key_schedule_algo;
+     323                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     324                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     325                 :            :                                                     &data_size1, NULL, NULL);
+     326                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     327                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     328                 :            :         data_size1;
+     329                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+     330                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+     331                 :            :         data_size1;
+     332                 :            : 
+     333                 :          1 :     libspdm_reset_message_a(spdm_context);
+     334                 :            : 
+     335                 :          1 :     m_libspdm_psk_exchange_request1.psk_hint_length =
+     336                 :            :         (uint16_t)sizeof(LIBSPDM_TEST_PSK_HINT_STRING);
+     337                 :          1 :     m_libspdm_psk_exchange_request1.context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
+     338                 :          1 :     opaque_psk_exchange_req_size =
+     339                 :          1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
+     340                 :          1 :     m_libspdm_psk_exchange_request1.opaque_length =
+     341                 :          1 :         (uint16_t)opaque_psk_exchange_req_size;
+     342                 :          1 :     m_libspdm_psk_exchange_request1.req_session_id = 0xFFFF;
+     343                 :          1 :     ptr = m_libspdm_psk_exchange_request1.psk_hint;
+     344                 :          1 :     libspdm_copy_mem(ptr, sizeof(m_libspdm_psk_exchange_request1.psk_hint),
+     345                 :            :                      LIBSPDM_TEST_PSK_HINT_STRING,
+     346                 :            :                      sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+     347                 :          1 :     ptr += m_libspdm_psk_exchange_request1.psk_hint_length;
+     348                 :          1 :     libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
+     349                 :          1 :     ptr += m_libspdm_psk_exchange_request1.context_length;
+     350                 :          1 :     libspdm_build_opaque_data_supported_version_data(
+     351                 :            :         spdm_context, &opaque_psk_exchange_req_size, ptr);
+     352                 :          1 :     ptr += opaque_psk_exchange_req_size;
+     353                 :          1 :     response_size = sizeof(response);
+     354                 :          1 :     status = libspdm_get_response_psk_exchange(
+     355                 :            :         spdm_context, m_libspdm_psk_exchange_request1_size,
+     356                 :            :         &m_libspdm_psk_exchange_request1, &response_size, response);
+     357                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     358                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     359                 :          1 :     spdm_response = (void *)response;
+     360                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     361                 :            :                      SPDM_ERROR);
+     362                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_BUSY);
+     363                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     364                 :          1 :     assert_int_equal(spdm_context->response_state,
+     365                 :            :                      LIBSPDM_RESPONSE_STATE_BUSY);
+     366                 :          1 :     free(data1);
+     367                 :          1 : }
+     368                 :            : 
+     369                 :          1 : void libspdm_test_responder_psk_exchange_case4(void **state)
+     370                 :            : {
+     371                 :            :     libspdm_return_t status;
+     372                 :            :     libspdm_test_context_t *spdm_test_context;
+     373                 :            :     libspdm_context_t *spdm_context;
+     374                 :            :     size_t response_size;
+     375                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     376                 :            :     spdm_psk_exchange_response_t *spdm_response;
+     377                 :            :     void *data1;
+     378                 :            :     size_t data_size1;
+     379                 :            :     uint8_t *ptr;
+     380                 :            :     size_t opaque_psk_exchange_req_size;
+     381                 :            : 
+     382                 :          1 :     spdm_test_context = *state;
+     383                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     384                 :          1 :     spdm_test_context->case_id = 0x4;
+     385                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     386                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     387                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NEED_RESYNC;
+     388                 :          1 :     spdm_context->connection_info.connection_state =
+     389                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     390                 :          1 :     spdm_context->connection_info.capability.flags |=
+     391                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     392                 :          1 :     spdm_context->local_context.capability.flags |=
+     393                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     394                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     395                 :            :         m_libspdm_use_hash_algo;
+     396                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     397                 :            :         m_libspdm_use_measurement_spec;
+     398                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     399                 :            :         m_libspdm_use_measurement_hash_algo;
+     400                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     401                 :            :         m_libspdm_use_dhe_algo;
+     402                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     403                 :            :         m_libspdm_use_aead_algo;
+     404                 :          1 :     spdm_context->connection_info.algorithm.key_schedule =
+     405                 :            :         m_libspdm_use_key_schedule_algo;
+     406                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     407                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     408                 :            :                                                     &data_size1, NULL, NULL);
+     409                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     410                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     411                 :            :         data_size1;
+     412                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+     413                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+     414                 :            :         data_size1;
+     415                 :            : 
+     416                 :          1 :     libspdm_reset_message_a(spdm_context);
+     417                 :            : 
+     418                 :          1 :     m_libspdm_psk_exchange_request1.psk_hint_length =
+     419                 :            :         (uint16_t)sizeof(LIBSPDM_TEST_PSK_HINT_STRING);
+     420                 :          1 :     m_libspdm_psk_exchange_request1.context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
+     421                 :          1 :     opaque_psk_exchange_req_size =
+     422                 :          1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
+     423                 :          1 :     m_libspdm_psk_exchange_request1.opaque_length =
+     424                 :          1 :         (uint16_t)opaque_psk_exchange_req_size;
+     425                 :          1 :     m_libspdm_psk_exchange_request1.req_session_id = 0xFFFF;
+     426                 :          1 :     ptr = m_libspdm_psk_exchange_request1.psk_hint;
+     427                 :          1 :     libspdm_copy_mem(ptr, sizeof(m_libspdm_psk_exchange_request1.psk_hint),
+     428                 :            :                      LIBSPDM_TEST_PSK_HINT_STRING,
+     429                 :            :                      sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+     430                 :          1 :     ptr += m_libspdm_psk_exchange_request1.psk_hint_length;
+     431                 :          1 :     libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
+     432                 :          1 :     ptr += m_libspdm_psk_exchange_request1.context_length;
+     433                 :          1 :     libspdm_build_opaque_data_supported_version_data(
+     434                 :            :         spdm_context, &opaque_psk_exchange_req_size, ptr);
+     435                 :          1 :     ptr += opaque_psk_exchange_req_size;
+     436                 :          1 :     response_size = sizeof(response);
+     437                 :          1 :     status = libspdm_get_response_psk_exchange(
+     438                 :            :         spdm_context, m_libspdm_psk_exchange_request1_size,
+     439                 :            :         &m_libspdm_psk_exchange_request1, &response_size, response);
+     440                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     441                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     442                 :          1 :     spdm_response = (void *)response;
+     443                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     444                 :            :                      SPDM_ERROR);
+     445                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     446                 :            :                      SPDM_ERROR_CODE_REQUEST_RESYNCH);
+     447                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     448                 :          1 :     assert_int_equal(spdm_context->response_state,
+     449                 :            :                      LIBSPDM_RESPONSE_STATE_NEED_RESYNC);
+     450                 :          1 :     free(data1);
+     451                 :          1 : }
+     452                 :            : 
+     453                 :            : #if LIBSPDM_RESPOND_IF_READY_SUPPORT
+     454                 :          1 : void libspdm_test_responder_psk_exchange_case5(void **state)
+     455                 :            : {
+     456                 :            :     libspdm_return_t status;
+     457                 :            :     libspdm_test_context_t *spdm_test_context;
+     458                 :            :     libspdm_context_t *spdm_context;
+     459                 :            :     size_t response_size;
+     460                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     461                 :            :     spdm_psk_exchange_response_t *spdm_response;
+     462                 :            :     void *data1;
+     463                 :            :     size_t data_size1;
+     464                 :            :     uint8_t *ptr;
+     465                 :            :     size_t opaque_psk_exchange_req_size;
+     466                 :            :     spdm_error_data_response_not_ready_t *error_data;
+     467                 :            : 
+     468                 :          1 :     spdm_test_context = *state;
+     469                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     470                 :          1 :     spdm_test_context->case_id = 0x5;
+     471                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     472                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     473                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NOT_READY;
+     474                 :          1 :     spdm_context->connection_info.connection_state =
+     475                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     476                 :          1 :     spdm_context->connection_info.capability.flags |=
+     477                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     478                 :          1 :     spdm_context->local_context.capability.flags |=
+     479                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     480                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     481                 :            :         m_libspdm_use_hash_algo;
+     482                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     483                 :            :         m_libspdm_use_measurement_spec;
+     484                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     485                 :            :         m_libspdm_use_measurement_hash_algo;
+     486                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     487                 :            :         m_libspdm_use_dhe_algo;
+     488                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     489                 :            :         m_libspdm_use_aead_algo;
+     490                 :          1 :     spdm_context->connection_info.algorithm.key_schedule =
+     491                 :            :         m_libspdm_use_key_schedule_algo;
+     492                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     493                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     494                 :            :                                                     &data_size1, NULL, NULL);
+     495                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     496                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     497                 :            :         data_size1;
+     498                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+     499                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+     500                 :            :         data_size1;
+     501                 :            : 
+     502                 :          1 :     libspdm_reset_message_a(spdm_context);
+     503                 :            : 
+     504                 :          1 :     m_libspdm_psk_exchange_request1.psk_hint_length =
+     505                 :            :         (uint16_t)sizeof(LIBSPDM_TEST_PSK_HINT_STRING);
+     506                 :          1 :     m_libspdm_psk_exchange_request1.context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
+     507                 :          1 :     opaque_psk_exchange_req_size =
+     508                 :          1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
+     509                 :          1 :     m_libspdm_psk_exchange_request1.opaque_length =
+     510                 :          1 :         (uint16_t)opaque_psk_exchange_req_size;
+     511                 :          1 :     m_libspdm_psk_exchange_request1.req_session_id = 0xFFFF;
+     512                 :          1 :     ptr = m_libspdm_psk_exchange_request1.psk_hint;
+     513                 :          1 :     libspdm_copy_mem(ptr, sizeof(m_libspdm_psk_exchange_request1.psk_hint),
+     514                 :            :                      LIBSPDM_TEST_PSK_HINT_STRING,
+     515                 :            :                      sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+     516                 :          1 :     ptr += m_libspdm_psk_exchange_request1.psk_hint_length;
+     517                 :          1 :     libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
+     518                 :          1 :     ptr += m_libspdm_psk_exchange_request1.context_length;
+     519                 :          1 :     libspdm_build_opaque_data_supported_version_data(
+     520                 :            :         spdm_context, &opaque_psk_exchange_req_size, ptr);
+     521                 :          1 :     ptr += opaque_psk_exchange_req_size;
+     522                 :          1 :     response_size = sizeof(response);
+     523                 :          1 :     status = libspdm_get_response_psk_exchange(
+     524                 :            :         spdm_context, m_libspdm_psk_exchange_request1_size,
+     525                 :            :         &m_libspdm_psk_exchange_request1, &response_size, response);
+     526                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     527                 :          1 :     assert_int_equal(response_size,
+     528                 :            :                      sizeof(spdm_error_response_t) +
+     529                 :            :                      sizeof(spdm_error_data_response_not_ready_t));
+     530                 :          1 :     spdm_response = (void *)response;
+     531                 :          1 :     error_data = (spdm_error_data_response_not_ready_t
+     532                 :            :                   *)(&spdm_response->rsp_session_id);
+     533                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     534                 :            :                      SPDM_ERROR);
+     535                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     536                 :            :                      SPDM_ERROR_CODE_RESPONSE_NOT_READY);
+     537                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     538                 :          1 :     assert_int_equal(spdm_context->response_state,
+     539                 :            :                      LIBSPDM_RESPONSE_STATE_NOT_READY);
+     540                 :          1 :     assert_int_equal(error_data->request_code, SPDM_PSK_EXCHANGE);
+     541                 :          1 :     free(data1);
+     542                 :          1 : }
+     543                 :            : #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
+     544                 :            : 
+     545                 :          1 : void libspdm_test_responder_psk_exchange_case6(void **state)
+     546                 :            : {
+     547                 :            :     libspdm_return_t status;
+     548                 :            :     libspdm_test_context_t *spdm_test_context;
+     549                 :            :     libspdm_context_t *spdm_context;
+     550                 :            :     size_t response_size;
+     551                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     552                 :            :     spdm_psk_exchange_response_t *spdm_response;
+     553                 :            :     void *data1;
+     554                 :            :     size_t data_size1;
+     555                 :            :     uint8_t *ptr;
+     556                 :            :     size_t opaque_psk_exchange_req_size;
+     557                 :            : 
+     558                 :          1 :     spdm_test_context = *state;
+     559                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     560                 :          1 :     spdm_test_context->case_id = 0x6;
+     561                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     562                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     563                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+     564                 :          1 :     spdm_context->connection_info.connection_state =
+     565                 :            :         LIBSPDM_CONNECTION_STATE_NOT_STARTED;
+     566                 :          1 :     spdm_context->connection_info.capability.flags |=
+     567                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     568                 :          1 :     spdm_context->local_context.capability.flags |=
+     569                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     570                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     571                 :            :         m_libspdm_use_hash_algo;
+     572                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     573                 :            :         m_libspdm_use_measurement_spec;
+     574                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     575                 :            :         m_libspdm_use_measurement_hash_algo;
+     576                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     577                 :            :         m_libspdm_use_dhe_algo;
+     578                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     579                 :            :         m_libspdm_use_aead_algo;
+     580                 :          1 :     spdm_context->connection_info.algorithm.key_schedule =
+     581                 :            :         m_libspdm_use_key_schedule_algo;
+     582                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     583                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     584                 :            :                                                     &data_size1, NULL, NULL);
+     585                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     586                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     587                 :            :         data_size1;
+     588                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+     589                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+     590                 :            :         data_size1;
+     591                 :            : 
+     592                 :          1 :     libspdm_reset_message_a(spdm_context);
+     593                 :            : 
+     594                 :          1 :     m_libspdm_psk_exchange_request1.psk_hint_length =
+     595                 :            :         (uint16_t)sizeof(LIBSPDM_TEST_PSK_HINT_STRING);
+     596                 :          1 :     m_libspdm_psk_exchange_request1.context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
+     597                 :          1 :     opaque_psk_exchange_req_size =
+     598                 :          1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
+     599                 :          1 :     m_libspdm_psk_exchange_request1.opaque_length =
+     600                 :          1 :         (uint16_t)opaque_psk_exchange_req_size;
+     601                 :          1 :     m_libspdm_psk_exchange_request1.req_session_id = 0xFFFF;
+     602                 :          1 :     ptr = m_libspdm_psk_exchange_request1.psk_hint;
+     603                 :          1 :     libspdm_copy_mem(ptr, sizeof(m_libspdm_psk_exchange_request1.psk_hint),
+     604                 :            :                      LIBSPDM_TEST_PSK_HINT_STRING,
+     605                 :            :                      sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+     606                 :          1 :     ptr += m_libspdm_psk_exchange_request1.psk_hint_length;
+     607                 :          1 :     libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
+     608                 :          1 :     ptr += m_libspdm_psk_exchange_request1.context_length;
+     609                 :          1 :     libspdm_build_opaque_data_supported_version_data(
+     610                 :            :         spdm_context, &opaque_psk_exchange_req_size, ptr);
+     611                 :          1 :     ptr += opaque_psk_exchange_req_size;
+     612                 :          1 :     response_size = sizeof(response);
+     613                 :          1 :     status = libspdm_get_response_psk_exchange(
+     614                 :            :         spdm_context, m_libspdm_psk_exchange_request1_size,
+     615                 :            :         &m_libspdm_psk_exchange_request1, &response_size, response);
+     616                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     617                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     618                 :          1 :     spdm_response = (void *)response;
+     619                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     620                 :            :                      SPDM_ERROR);
+     621                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     622                 :            :                      SPDM_ERROR_CODE_UNEXPECTED_REQUEST);
+     623                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     624                 :          1 :     free(data1);
+     625                 :          1 : }
+     626                 :            : 
+     627                 :          1 : void libspdm_test_responder_psk_exchange_case7(void **state)
+     628                 :            : {
+     629                 :            :     libspdm_return_t status;
+     630                 :            :     libspdm_test_context_t *spdm_test_context;
+     631                 :            :     libspdm_context_t *spdm_context;
+     632                 :            :     size_t response_size;
+     633                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     634                 :            :     spdm_psk_exchange_response_t *spdm_response;
+     635                 :            :     void *data1;
+     636                 :            :     size_t data_size1;
+     637                 :            :     uint8_t *ptr;
+     638                 :            :     size_t opaque_psk_exchange_req_size;
+     639                 :            : 
+     640                 :          1 :     spdm_test_context = *state;
+     641                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     642                 :          1 :     spdm_test_context->case_id = 0x7;
+     643                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     644                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     645                 :          1 :     spdm_context->connection_info.connection_state =
+     646                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     647                 :          1 :     spdm_context->connection_info.capability.flags |=
+     648                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     649                 :          1 :     spdm_context->local_context.capability.flags |=
+     650                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     651                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     652                 :            :         m_libspdm_use_hash_algo;
+     653                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     654                 :            :         m_libspdm_use_measurement_spec;
+     655                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     656                 :            :         m_libspdm_use_measurement_hash_algo;
+     657                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     658                 :            :         m_libspdm_use_dhe_algo;
+     659                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     660                 :            :         m_libspdm_use_aead_algo;
+     661                 :          1 :     spdm_context->connection_info.algorithm.key_schedule =
+     662                 :            :         m_libspdm_use_key_schedule_algo;
+     663                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     664                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     665                 :            :                                                     &data_size1, NULL, NULL);
+     666                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     667                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     668                 :            :         data_size1;
+     669                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+     670                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+     671                 :            :         data_size1;
+     672                 :            : 
+     673                 :          1 :     libspdm_reset_message_a(spdm_context);
+     674                 :            : 
+     675                 :          1 :     m_libspdm_psk_exchange_request1.psk_hint_length =
+     676                 :            :         (uint16_t)sizeof(LIBSPDM_TEST_PSK_HINT_STRING);
+     677                 :          1 :     m_libspdm_psk_exchange_request1.context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
+     678                 :          1 :     opaque_psk_exchange_req_size =
+     679                 :          1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
+     680                 :          1 :     m_libspdm_psk_exchange_request1.opaque_length =
+     681                 :          1 :         (uint16_t)opaque_psk_exchange_req_size;
+     682                 :          1 :     m_libspdm_psk_exchange_request1.req_session_id = 0xFFFF;
+     683                 :          1 :     ptr = m_libspdm_psk_exchange_request1.psk_hint;
+     684                 :          1 :     libspdm_copy_mem(ptr, sizeof(m_libspdm_psk_exchange_request1.psk_hint),
+     685                 :            :                      LIBSPDM_TEST_PSK_HINT_STRING,
+     686                 :            :                      sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+     687                 :          1 :     ptr += m_libspdm_psk_exchange_request1.psk_hint_length;
+     688                 :          1 :     libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
+     689                 :          1 :     ptr += m_libspdm_psk_exchange_request1.context_length;
+     690                 :          1 :     libspdm_build_opaque_data_supported_version_data(
+     691                 :            :         spdm_context, &opaque_psk_exchange_req_size, ptr);
+     692                 :          1 :     ptr += opaque_psk_exchange_req_size;
+     693                 :            : 
+     694                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     695                 :            :     spdm_context->transcript.message_m.buffer_size =
+     696                 :            :         spdm_context->transcript.message_m.max_buffer_size;
+     697                 :            :     spdm_context->transcript.message_b.buffer_size =
+     698                 :            :         spdm_context->transcript.message_b.max_buffer_size;
+     699                 :            :     spdm_context->transcript.message_c.buffer_size =
+     700                 :            :         spdm_context->transcript.message_c.max_buffer_size;
+     701                 :            :     spdm_context->transcript.message_mut_b.buffer_size =
+     702                 :            :         spdm_context->transcript.message_mut_b.max_buffer_size;
+     703                 :            :     spdm_context->transcript.message_mut_c.buffer_size =
+     704                 :            :         spdm_context->transcript.message_mut_c.max_buffer_size;
+     705                 :            : #endif
+     706                 :            : 
+     707                 :          1 :     response_size = sizeof(response);
+     708                 :          1 :     status = libspdm_get_response_psk_exchange(
+     709                 :            :         spdm_context, m_libspdm_psk_exchange_request1_size,
+     710                 :            :         &m_libspdm_psk_exchange_request1, &response_size, response);
+     711                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     712                 :          1 :     assert_int_equal(
+     713                 :            :         libspdm_secured_message_get_session_state(
+     714                 :            :             spdm_context->session_info[0].secured_message_context),
+     715                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+     716                 :          1 :     spdm_response = (void *)response;
+     717                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     718                 :            :                      SPDM_PSK_EXCHANGE_RSP);
+     719                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     720                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+     721                 :            :     assert_int_equal(spdm_context->transcript.message_b.buffer_size, 0);
+     722                 :            :     assert_int_equal(spdm_context->transcript.message_c.buffer_size, 0);
+     723                 :            :     assert_int_equal(spdm_context->transcript.message_mut_b.buffer_size, 0);
+     724                 :            :     assert_int_equal(spdm_context->transcript.message_mut_c.buffer_size, 0);
+     725                 :            : #endif
+     726                 :            : 
+     727                 :          1 :     free(data1);
+     728                 :          1 : }
+     729                 :            : 
+     730                 :          1 : void libspdm_test_responder_psk_exchange_case8(void **state)
+     731                 :            : {
+     732                 :            :     libspdm_return_t status;
+     733                 :            :     libspdm_test_context_t *spdm_test_context;
+     734                 :            :     libspdm_context_t *spdm_context;
+     735                 :            :     size_t current_request_size;
+     736                 :            :     size_t response_size;
+     737                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     738                 :            :     spdm_psk_exchange_response_t *spdm_response;
+     739                 :            :     void *data1;
+     740                 :            :     size_t data_size1;
+     741                 :            :     uint8_t *ptr;
+     742                 :            :     size_t opaque_psk_exchange_req_size;
+     743                 :            : 
+     744                 :          1 :     spdm_test_context = *state;
+     745                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     746                 :            : 
+     747         [ +  - ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+     748                 :          1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+     749                 :            :     }
+     750                 :            : 
+     751                 :          1 :     spdm_test_context->case_id = 0x8;
+     752                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     753                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     754                 :          1 :     spdm_context->connection_info.connection_state =
+     755                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     756                 :          1 :     spdm_context->connection_info.capability.flags |=
+     757                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     758                 :          1 :     spdm_context->local_context.capability.flags |=
+     759                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     760                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     761                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+     762                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     763                 :            :         m_libspdm_use_measurement_hash_algo;
+     764                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+     765                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+     766                 :          1 :     spdm_context->connection_info.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+     767                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     768                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     769                 :            :                                                     &data_size1, NULL, NULL);
+     770                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     771                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
+     772                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+     773                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size = data_size1;
+     774                 :            : 
+     775                 :          1 :     libspdm_reset_message_a(spdm_context);
+     776                 :            : 
+     777                 :          1 :     m_libspdm_psk_exchange_request1.psk_hint_length =
+     778                 :            :         (uint16_t)sizeof(LIBSPDM_TEST_PSK_HINT_STRING);
+     779                 :          1 :     m_libspdm_psk_exchange_request1.context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
+     780                 :          1 :     opaque_psk_exchange_req_size =
+     781                 :          1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
+     782                 :          1 :     m_libspdm_psk_exchange_request1.opaque_length =
+     783                 :          1 :         (uint16_t)opaque_psk_exchange_req_size;
+     784                 :          1 :     m_libspdm_psk_exchange_request1.req_session_id = 0xFFFF;
+     785                 :          1 :     ptr = m_libspdm_psk_exchange_request1.psk_hint;
+     786                 :          1 :     libspdm_copy_mem(ptr, sizeof(m_libspdm_psk_exchange_request1.psk_hint),
+     787                 :            :                      LIBSPDM_TEST_PSK_HINT_STRING,
+     788                 :            :                      sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+     789                 :          1 :     ptr += m_libspdm_psk_exchange_request1.psk_hint_length;
+     790                 :          1 :     libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
+     791                 :          1 :     ptr += m_libspdm_psk_exchange_request1.context_length;
+     792                 :          1 :     libspdm_build_opaque_data_supported_version_data(
+     793                 :            :         spdm_context, &opaque_psk_exchange_req_size, ptr);
+     794                 :          1 :     ptr += opaque_psk_exchange_req_size;
+     795                 :            : 
+     796                 :          1 :     current_request_size = sizeof(spdm_psk_exchange_request_t) +
+     797                 :          1 :                            m_libspdm_psk_exchange_request1.psk_hint_length +
+     798                 :          1 :                            m_libspdm_psk_exchange_request1.context_length +
+     799                 :            :                            opaque_psk_exchange_req_size;
+     800                 :          1 :     response_size = sizeof(response);
+     801                 :          1 :     status = libspdm_get_response_psk_exchange(
+     802                 :            :         spdm_context, current_request_size, &m_libspdm_psk_exchange_request1,
+     803                 :            :         &response_size, response);
+     804                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     805                 :          1 :     assert_int_equal(libspdm_secured_message_get_session_state(
+     806                 :            :                          spdm_context->session_info[0].secured_message_context),
+     807                 :            :                      LIBSPDM_SESSION_STATE_HANDSHAKING);
+     808                 :          1 :     spdm_response = (void *)response;
+     809                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_PSK_EXCHANGE_RSP);
+     810                 :          1 :     assert_int_equal(spdm_response->rsp_session_id, 0xFFFF);
+     811                 :            : 
+     812                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     813                 :            :     assert_int_equal(spdm_context->session_info[0].session_transcript.message_k.buffer_size,
+     814                 :            :                      current_request_size + response_size);
+     815                 :            :     assert_memory_equal(spdm_context->session_info[0].session_transcript.message_k.buffer,
+     816                 :            :                         &m_libspdm_psk_exchange_request1, current_request_size);
+     817                 :            :     assert_memory_equal(spdm_context->session_info[0].session_transcript.message_k.buffer +
+     818                 :            :                         current_request_size, response, response_size);
+     819                 :            : #endif
+     820                 :          1 :     free(data1);
+     821                 :          1 : }
+     822                 :            : 
+     823                 :          1 : void libspdm_test_responder_psk_exchange_case9(void **state)
+     824                 :            : {
+     825                 :            :     libspdm_return_t status;
+     826                 :            :     libspdm_test_context_t *spdm_test_context;
+     827                 :            :     libspdm_context_t *spdm_context;
+     828                 :            :     size_t response_size;
+     829                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     830                 :            :     spdm_psk_exchange_response_t *spdm_response;
+     831                 :            :     void *data1;
+     832                 :            :     size_t data_size1;
+     833                 :            :     uint8_t *ptr;
+     834                 :            :     size_t opaque_psk_exchange_req_size;
+     835                 :            : 
+     836                 :          1 :     spdm_test_context = *state;
+     837                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     838                 :          1 :     spdm_test_context->case_id = 0x9;
+     839                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     840                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     841                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     842                 :          1 :     spdm_context->connection_info.capability.flags |=
+     843                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     844                 :          1 :     spdm_context->local_context.capability.flags |=
+     845                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     846                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     847                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+     848                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     849                 :            :         m_libspdm_use_measurement_hash_algo;
+     850                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+     851                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+     852                 :          1 :     spdm_context->connection_info.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+     853                 :          1 :     spdm_context->connection_info.algorithm.other_params_support =
+     854                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
+     855                 :          1 :     libspdm_session_info_init(spdm_context,
+     856                 :          1 :                               spdm_context->session_info,
+     857                 :            :                               INVALID_SESSION_ID, false);
+     858                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     859                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     860                 :            :                                                     &data_size1, NULL, NULL);
+     861                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     862                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
+     863                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+     864                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size = data_size1;
+     865                 :            : 
+     866                 :          1 :     libspdm_reset_message_a(spdm_context);
+     867                 :            : 
+     868                 :          1 :     m_libspdm_psk_exchange_request3.psk_hint_length =
+     869                 :            :         (uint16_t)sizeof(LIBSPDM_TEST_PSK_HINT_STRING);
+     870                 :          1 :     m_libspdm_psk_exchange_request3.context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
+     871                 :          1 :     opaque_psk_exchange_req_size =
+     872                 :          1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
+     873                 :          1 :     m_libspdm_psk_exchange_request3.opaque_length = (uint16_t)opaque_psk_exchange_req_size;
+     874                 :          1 :     m_libspdm_psk_exchange_request3.req_session_id = 0xFFFF;
+     875                 :          1 :     ptr = m_libspdm_psk_exchange_request3.psk_hint;
+     876                 :          1 :     libspdm_copy_mem(ptr, sizeof(m_libspdm_psk_exchange_request3.psk_hint),
+     877                 :            :                      LIBSPDM_TEST_PSK_HINT_STRING,
+     878                 :            :                      sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+     879                 :          1 :     ptr += m_libspdm_psk_exchange_request3.psk_hint_length;
+     880                 :          1 :     libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
+     881                 :          1 :     ptr += m_libspdm_psk_exchange_request3.context_length;
+     882                 :          1 :     libspdm_build_opaque_data_supported_version_data(
+     883                 :            :         spdm_context, &opaque_psk_exchange_req_size, ptr);
+     884                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     885                 :            :     spdm_context->transcript.message_m.buffer_size =
+     886                 :            :         spdm_context->transcript.message_m.max_buffer_size;
+     887                 :            : #endif
+     888                 :          1 :     ptr += opaque_psk_exchange_req_size;
+     889                 :          1 :     response_size = sizeof(response);
+     890                 :          1 :     status = libspdm_get_response_psk_exchange(
+     891                 :            :         spdm_context, m_libspdm_psk_exchange_request3_size,
+     892                 :            :         &m_libspdm_psk_exchange_request3, &response_size, response);
+     893                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     894                 :          1 :     assert_int_equal(
+     895                 :            :         libspdm_secured_message_get_session_state(
+     896                 :            :             spdm_context->session_info[0].secured_message_context),
+     897                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+     898                 :          1 :     assert_int_equal(spdm_context->session_info[0].session_policy, 0);
+     899                 :          1 :     spdm_response = (void *)response;
+     900                 :          1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+     901                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_PSK_EXCHANGE_RSP);
+     902                 :          1 :     assert_int_equal(spdm_response->rsp_session_id, 0xFFFF);
+     903                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     904                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
+     905                 :            : #endif
+     906                 :          1 :     free(data1);
+     907                 :          1 : }
+     908                 :            : 
+     909                 :          1 : void libspdm_test_responder_psk_exchange_case10(void **state)
+     910                 :            : {
+     911                 :            :     libspdm_return_t status;
+     912                 :            :     libspdm_test_context_t *spdm_test_context;
+     913                 :            :     libspdm_context_t *spdm_context;
+     914                 :            :     size_t response_size;
+     915                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     916                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
+     917                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+     918                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP */
+     919                 :            :     uint32_t measurement_summary_hash_size;
+     920                 :            :     spdm_psk_exchange_response_t *spdm_response;
+     921                 :            :     void *data1;
+     922                 :            :     size_t data_size1;
+     923                 :            :     uint8_t *ptr;
+     924                 :            :     size_t opaque_psk_exchange_req_size;
+     925                 :            : 
+     926                 :          1 :     spdm_test_context = *state;
+     927                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     928                 :          1 :     spdm_test_context->case_id = 0xA;
+     929                 :            : 
+     930                 :            :     /* Clear previous sessions */
+     931         [ +  - ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+     932                 :          1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+     933                 :            :     }
+     934                 :            : 
+     935                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     936                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     937                 :          1 :     spdm_context->connection_info.connection_state =
+     938                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     939                 :          1 :     spdm_context->connection_info.capability.flags |=
+     940                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     941                 :          1 :     spdm_context->local_context.capability.flags |=
+     942                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     943                 :          1 :     spdm_context->local_context.capability.flags |=
+     944                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP;
+     945                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     946                 :            :         m_libspdm_use_hash_algo;
+     947                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     948                 :            :         m_libspdm_use_measurement_spec;
+     949                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     950                 :            :         m_libspdm_use_measurement_hash_algo;
+     951                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     952                 :            :         m_libspdm_use_dhe_algo;
+     953                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     954                 :            :         m_libspdm_use_aead_algo;
+     955                 :          1 :     spdm_context->connection_info.algorithm.key_schedule =
+     956                 :            :         m_libspdm_use_key_schedule_algo;
+     957                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     958                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     959                 :            :                                                     &data_size1, NULL, NULL);
+     960                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     961                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     962                 :            :         data_size1;
+     963                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+     964                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+     965                 :            :         data_size1;
+     966                 :            : 
+     967                 :          1 :     libspdm_reset_message_a(spdm_context);
+     968                 :            : 
+     969                 :          1 :     m_libspdm_psk_exchange_request4.psk_hint_length =
+     970                 :            :         (uint16_t)sizeof(LIBSPDM_TEST_PSK_HINT_STRING);
+     971                 :          1 :     m_libspdm_psk_exchange_request4.context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
+     972                 :          1 :     opaque_psk_exchange_req_size =
+     973                 :          1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
+     974                 :          1 :     m_libspdm_psk_exchange_request4.opaque_length =
+     975                 :          1 :         (uint16_t)opaque_psk_exchange_req_size;
+     976                 :          1 :     m_libspdm_psk_exchange_request4.req_session_id = 0xFFFF;
+     977                 :          1 :     ptr = m_libspdm_psk_exchange_request4.psk_hint;
+     978                 :          1 :     libspdm_copy_mem(ptr, sizeof(m_libspdm_psk_exchange_request4.psk_hint),
+     979                 :            :                      LIBSPDM_TEST_PSK_HINT_STRING,
+     980                 :            :                      sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+     981                 :          1 :     ptr += m_libspdm_psk_exchange_request4.psk_hint_length;
+     982                 :          1 :     libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
+     983                 :          1 :     ptr += m_libspdm_psk_exchange_request4.context_length;
+     984                 :          1 :     libspdm_build_opaque_data_supported_version_data(
+     985                 :            :         spdm_context, &opaque_psk_exchange_req_size, ptr);
+     986                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     987                 :            :     spdm_context->transcript.message_m.buffer_size =
+     988                 :            :         spdm_context->transcript.message_m.max_buffer_size;
+     989                 :            : #endif
+     990                 :          1 :     ptr += opaque_psk_exchange_req_size;
+     991                 :          1 :     response_size = sizeof(response);
+     992                 :          1 :     status = libspdm_get_response_psk_exchange(
+     993                 :            :         spdm_context, m_libspdm_psk_exchange_request4_size,
+     994                 :            :         &m_libspdm_psk_exchange_request4, &response_size, response);
+     995                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     996                 :          1 :     assert_int_equal(
+     997                 :            :         libspdm_secured_message_get_session_state(
+     998                 :            :             spdm_context->session_info[0].secured_message_context),
+     999                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    1000                 :          1 :     spdm_response = (void *)response;
+    1001                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1002                 :            :                      SPDM_PSK_EXCHANGE_RSP);
+    1003                 :          1 :     assert_int_equal(spdm_response->rsp_session_id, 0xFFFF);
+    1004                 :            : 
+    1005                 :          1 :     measurement_summary_hash_size = libspdm_get_measurement_summary_hash_size(
+    1006                 :          1 :         spdm_context, false, m_libspdm_psk_exchange_request4.header.param1);
+    1007                 :            : 
+    1008                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
+    1009                 :          1 :     libspdm_generate_measurement_summary_hash(
+    1010                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    1011                 :            :         spdm_context,
+    1012                 :            : #endif
+    1013                 :          1 :         spdm_context->connection_info.version,
+    1014                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    1015                 :          1 :         spdm_context->connection_info.algorithm.measurement_spec,
+    1016                 :            :         spdm_context->connection_info.algorithm.measurement_hash_algo,
+    1017                 :          1 :         m_libspdm_psk_exchange_request4.header.param1,
+    1018                 :            :         measurement_hash,
+    1019                 :            :         measurement_summary_hash_size);
+    1020                 :            : 
+    1021                 :          1 :     assert_memory_equal(
+    1022                 :            :         (uint8_t *)response +
+    1023                 :            :         sizeof(spdm_psk_exchange_response_t),
+    1024                 :            :         measurement_hash,
+    1025                 :            :         measurement_summary_hash_size);
+    1026                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP */
+    1027                 :            : 
+    1028                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1029                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
+    1030                 :            :                      0);
+    1031                 :            : #endif
+    1032                 :          1 :     free(data1);
+    1033                 :          1 : }
+    1034                 :            : 
+    1035                 :          1 : void libspdm_test_responder_psk_exchange_case11(void **state)
+    1036                 :            : {
+    1037                 :            :     libspdm_return_t status;
+    1038                 :            :     libspdm_test_context_t *spdm_test_context;
+    1039                 :            :     libspdm_context_t *spdm_context;
+    1040                 :            :     size_t response_size;
+    1041                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1042                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
+    1043                 :            :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
+    1044                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP */
+    1045                 :            :     uint32_t measurement_summary_hash_size;
+    1046                 :            :     spdm_psk_exchange_response_t *spdm_response;
+    1047                 :            :     void *data1;
+    1048                 :            :     size_t data_size1;
+    1049                 :            :     uint8_t *ptr;
+    1050                 :            :     size_t opaque_psk_exchange_req_size;
+    1051                 :            : 
+    1052                 :          1 :     spdm_test_context = *state;
+    1053                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1054                 :          1 :     spdm_test_context->case_id = 0xB;
+    1055                 :            : 
+    1056                 :            :     /* Clear previous sessions */
+    1057         [ +  - ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    1058                 :          1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    1059                 :            :     }
+    1060                 :            : 
+    1061                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1062                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1063                 :          1 :     spdm_context->connection_info.connection_state =
+    1064                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1065                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1066                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1067                 :          1 :     spdm_context->local_context.capability.flags |=
+    1068                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1069                 :          1 :     spdm_context->local_context.capability.flags |=
+    1070                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP;
+    1071                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1072                 :            :         m_libspdm_use_hash_algo;
+    1073                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    1074                 :            :         m_libspdm_use_measurement_spec;
+    1075                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1076                 :            :         m_libspdm_use_measurement_hash_algo;
+    1077                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1078                 :            :         m_libspdm_use_dhe_algo;
+    1079                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1080                 :            :         m_libspdm_use_aead_algo;
+    1081                 :          1 :     spdm_context->connection_info.algorithm.key_schedule =
+    1082                 :            :         m_libspdm_use_key_schedule_algo;
+    1083                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1084                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    1085                 :            :                                                     &data_size1, NULL, NULL);
+    1086                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    1087                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    1088                 :            :         data_size1;
+    1089                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+    1090                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+    1091                 :            :         data_size1;
+    1092                 :            : 
+    1093                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1094                 :            : 
+    1095                 :          1 :     m_libspdm_psk_exchange_request5.psk_hint_length =
+    1096                 :            :         (uint16_t)sizeof(LIBSPDM_TEST_PSK_HINT_STRING);
+    1097                 :          1 :     m_libspdm_psk_exchange_request5.context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
+    1098                 :          1 :     opaque_psk_exchange_req_size =
+    1099                 :          1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
+    1100                 :          1 :     m_libspdm_psk_exchange_request5.opaque_length =
+    1101                 :          1 :         (uint16_t)opaque_psk_exchange_req_size;
+    1102                 :          1 :     m_libspdm_psk_exchange_request5.req_session_id = 0xFFFF;
+    1103                 :          1 :     ptr = m_libspdm_psk_exchange_request5.psk_hint;
+    1104                 :          1 :     libspdm_copy_mem(ptr, sizeof(m_libspdm_psk_exchange_request5.psk_hint),
+    1105                 :            :                      LIBSPDM_TEST_PSK_HINT_STRING,
+    1106                 :            :                      sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+    1107                 :          1 :     ptr += m_libspdm_psk_exchange_request5.psk_hint_length;
+    1108                 :          1 :     libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
+    1109                 :          1 :     ptr += m_libspdm_psk_exchange_request5.context_length;
+    1110                 :          1 :     libspdm_build_opaque_data_supported_version_data(
+    1111                 :            :         spdm_context, &opaque_psk_exchange_req_size, ptr);
+    1112                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1113                 :            :     spdm_context->transcript.message_m.buffer_size =
+    1114                 :            :         spdm_context->transcript.message_m.max_buffer_size;
+    1115                 :            : #endif
+    1116                 :          1 :     ptr += opaque_psk_exchange_req_size;
+    1117                 :          1 :     response_size = sizeof(response);
+    1118                 :          1 :     status = libspdm_get_response_psk_exchange(
+    1119                 :            :         spdm_context, m_libspdm_psk_exchange_request5_size,
+    1120                 :            :         &m_libspdm_psk_exchange_request5, &response_size, response);
+    1121                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1122                 :          1 :     assert_int_equal(
+    1123                 :            :         libspdm_secured_message_get_session_state(
+    1124                 :            :             spdm_context->session_info[0].secured_message_context),
+    1125                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    1126                 :          1 :     spdm_response = (void *)response;
+    1127                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1128                 :            :                      SPDM_PSK_EXCHANGE_RSP);
+    1129                 :          1 :     assert_int_equal(spdm_response->rsp_session_id, 0xFFFF);
+    1130                 :            : 
+    1131                 :          1 :     measurement_summary_hash_size = libspdm_get_measurement_summary_hash_size(
+    1132                 :          1 :         spdm_context, false, m_libspdm_psk_exchange_request5.header.param1);
+    1133                 :            : 
+    1134                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
+    1135                 :          1 :     libspdm_generate_measurement_summary_hash(
+    1136                 :            : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
+    1137                 :            :         spdm_context,
+    1138                 :            : #endif
+    1139                 :          1 :         spdm_context->connection_info.version,
+    1140                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+    1141                 :          1 :         spdm_context->connection_info.algorithm.measurement_spec,
+    1142                 :            :         spdm_context->connection_info.algorithm.measurement_hash_algo,
+    1143                 :          1 :         m_libspdm_psk_exchange_request5.header.param1,
+    1144                 :            :         measurement_hash,
+    1145                 :            :         measurement_summary_hash_size);
+    1146                 :            : 
+    1147                 :          1 :     assert_memory_equal(
+    1148                 :            :         (uint8_t *)response +
+    1149                 :            :         sizeof(spdm_psk_exchange_response_t),
+    1150                 :            :         measurement_hash,
+    1151                 :            :         measurement_summary_hash_size);
+    1152                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP */
+    1153                 :            : 
+    1154                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1155                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
+    1156                 :            :                      0);
+    1157                 :            : #endif
+    1158                 :          1 :     free(data1);
+    1159                 :          1 : }
+    1160                 :            : 
+    1161                 :          1 : void libspdm_test_responder_psk_exchange_case12(void **state)
+    1162                 :            : {
+    1163                 :            :     libspdm_return_t status;
+    1164                 :            :     libspdm_test_context_t *spdm_test_context;
+    1165                 :            :     libspdm_context_t *spdm_context;
+    1166                 :            :     size_t response_size;
+    1167                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1168                 :            :     spdm_psk_exchange_response_t *spdm_response;
+    1169                 :            :     void *data1;
+    1170                 :            :     size_t data_size1;
+    1171                 :            :     uint8_t *ptr;
+    1172                 :            :     size_t opaque_psk_exchange_req_size;
+    1173                 :            : 
+    1174                 :          1 :     spdm_test_context = *state;
+    1175                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1176                 :          1 :     spdm_test_context->case_id = 0xC;
+    1177                 :            : 
+    1178                 :            :     /* Clear previous sessions */
+    1179         [ +  - ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    1180                 :          1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    1181                 :            :     }
+    1182                 :            : 
+    1183                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1184                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1185                 :          1 :     spdm_context->connection_info.connection_state =
+    1186                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1187                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1188                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1189                 :          1 :     spdm_context->local_context.capability.flags |=
+    1190                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1191                 :          1 :     spdm_context->local_context.capability.flags |=
+    1192                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP;
+    1193                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1194                 :            :         m_libspdm_use_hash_algo;
+    1195                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    1196                 :            :         m_libspdm_use_measurement_spec;
+    1197                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1198                 :            :         m_libspdm_use_measurement_hash_algo;
+    1199                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1200                 :            :         m_libspdm_use_dhe_algo;
+    1201                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1202                 :            :         m_libspdm_use_aead_algo;
+    1203                 :          1 :     spdm_context->connection_info.algorithm.key_schedule =
+    1204                 :            :         m_libspdm_use_key_schedule_algo;
+    1205                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1206                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    1207                 :            :                                                     &data_size1, NULL, NULL);
+    1208                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    1209                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    1210                 :            :         data_size1;
+    1211                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+    1212                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+    1213                 :            :         data_size1;
+    1214                 :            : 
+    1215                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1216                 :            : 
+    1217                 :          1 :     m_libspdm_psk_exchange_request6.psk_hint_length =
+    1218                 :            :         (uint16_t)sizeof(LIBSPDM_TEST_PSK_HINT_STRING);
+    1219                 :          1 :     m_libspdm_psk_exchange_request6.context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
+    1220                 :          1 :     opaque_psk_exchange_req_size =
+    1221                 :          1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
+    1222                 :          1 :     m_libspdm_psk_exchange_request6.opaque_length =
+    1223                 :          1 :         (uint16_t)opaque_psk_exchange_req_size;
+    1224                 :          1 :     m_libspdm_psk_exchange_request6.req_session_id = 0xFFFF;
+    1225                 :          1 :     ptr = m_libspdm_psk_exchange_request6.psk_hint;
+    1226                 :          1 :     libspdm_copy_mem(ptr, sizeof(m_libspdm_psk_exchange_request6.psk_hint),
+    1227                 :            :                      LIBSPDM_TEST_PSK_HINT_STRING,
+    1228                 :            :                      sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+    1229                 :          1 :     ptr += m_libspdm_psk_exchange_request6.psk_hint_length;
+    1230                 :          1 :     libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
+    1231                 :          1 :     ptr += m_libspdm_psk_exchange_request6.context_length;
+    1232                 :          1 :     libspdm_build_opaque_data_supported_version_data(
+    1233                 :            :         spdm_context, &opaque_psk_exchange_req_size, ptr);
+    1234                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1235                 :            :     spdm_context->transcript.message_m.buffer_size =
+    1236                 :            :         spdm_context->transcript.message_m.max_buffer_size;
+    1237                 :            : #endif
+    1238                 :          1 :     ptr += opaque_psk_exchange_req_size;
+    1239                 :          1 :     response_size = sizeof(response);
+    1240                 :          1 :     status = libspdm_get_response_psk_exchange(
+    1241                 :            :         spdm_context, m_libspdm_psk_exchange_request6_size,
+    1242                 :            :         &m_libspdm_psk_exchange_request6, &response_size, response);
+    1243                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1244                 :            : 
+    1245                 :          1 :     spdm_response = (void *)response;
+    1246                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1247                 :            :                      SPDM_ERROR);
+    1248                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+    1249                 :            : 
+    1250                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1251                 :            :     /* Error before libspdm_reset_message_buffer_via_request_code, so will not libspdm_reset_message_m */
+    1252                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
+    1253                 :            :                      spdm_context->transcript.message_m.max_buffer_size);
+    1254                 :            : #endif
+    1255                 :          1 :     free(data1);
+    1256                 :          1 : }
+    1257                 :            : 
+    1258                 :          1 : void libspdm_test_responder_psk_exchange_case13(void **state)
+    1259                 :            : {
+    1260                 :            :     libspdm_return_t status;
+    1261                 :            :     libspdm_test_context_t *spdm_test_context;
+    1262                 :            :     libspdm_context_t *spdm_context;
+    1263                 :            :     size_t response_size;
+    1264                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1265                 :            :     spdm_psk_exchange_response_t *spdm_response;
+    1266                 :            :     void *data1;
+    1267                 :            :     size_t data_size1;
+    1268                 :            :     uint8_t *ptr;
+    1269                 :            :     size_t opaque_psk_exchange_req_size;
+    1270                 :            : 
+    1271                 :          1 :     spdm_test_context = *state;
+    1272                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1273                 :          1 :     spdm_test_context->case_id = 0xD;
+    1274                 :            : 
+    1275                 :            :     /* Clear previous sessions */
+    1276         [ -  + ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    1277                 :          0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    1278                 :            :     }
+    1279                 :            : 
+    1280                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1281                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1282                 :          1 :     spdm_context->connection_info.connection_state =
+    1283                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1284                 :            : 
+    1285                 :          1 :     spdm_context->local_context.capability.flags &=
+    1286                 :            :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP;
+    1287                 :            : 
+    1288                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1289                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1290                 :          1 :     spdm_context->local_context.capability.flags |=
+    1291                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1292                 :            : 
+    1293                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1294                 :            :         m_libspdm_use_hash_algo;
+    1295                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    1296                 :            :         m_libspdm_use_measurement_spec;
+    1297                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1298                 :            :         m_libspdm_use_measurement_hash_algo;
+    1299                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1300                 :            :         m_libspdm_use_dhe_algo;
+    1301                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1302                 :            :         m_libspdm_use_aead_algo;
+    1303                 :          1 :     spdm_context->connection_info.algorithm.key_schedule =
+    1304                 :            :         m_libspdm_use_key_schedule_algo;
+    1305                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1306                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    1307                 :            :                                                     &data_size1, NULL, NULL);
+    1308                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    1309                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    1310                 :            :         data_size1;
+    1311                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+    1312                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+    1313                 :            :         data_size1;
+    1314                 :            : 
+    1315                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1316                 :            : 
+    1317                 :          1 :     m_libspdm_psk_exchange_request4.psk_hint_length =
+    1318                 :            :         (uint16_t)sizeof(LIBSPDM_TEST_PSK_HINT_STRING);
+    1319                 :          1 :     m_libspdm_psk_exchange_request4.context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
+    1320                 :          1 :     opaque_psk_exchange_req_size =
+    1321                 :          1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
+    1322                 :          1 :     m_libspdm_psk_exchange_request4.opaque_length =
+    1323                 :          1 :         (uint16_t)opaque_psk_exchange_req_size;
+    1324                 :          1 :     m_libspdm_psk_exchange_request4.req_session_id = 0xFFFF;
+    1325                 :          1 :     ptr = m_libspdm_psk_exchange_request4.psk_hint;
+    1326                 :          1 :     libspdm_copy_mem(ptr, sizeof(m_libspdm_psk_exchange_request4.psk_hint),
+    1327                 :            :                      LIBSPDM_TEST_PSK_HINT_STRING,
+    1328                 :            :                      sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+    1329                 :          1 :     ptr += m_libspdm_psk_exchange_request4.psk_hint_length;
+    1330                 :          1 :     libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
+    1331                 :          1 :     ptr += m_libspdm_psk_exchange_request4.context_length;
+    1332                 :          1 :     libspdm_build_opaque_data_supported_version_data(
+    1333                 :            :         spdm_context, &opaque_psk_exchange_req_size, ptr);
+    1334                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1335                 :            :     spdm_context->transcript.message_m.buffer_size =
+    1336                 :            :         spdm_context->transcript.message_m.max_buffer_size;
+    1337                 :            : #endif
+    1338                 :          1 :     ptr += opaque_psk_exchange_req_size;
+    1339                 :          1 :     response_size = sizeof(response);
+    1340                 :          1 :     status = libspdm_get_response_psk_exchange(
+    1341                 :            :         spdm_context, m_libspdm_psk_exchange_request4_size,
+    1342                 :            :         &m_libspdm_psk_exchange_request4, &response_size, response);
+    1343                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1344                 :            : 
+    1345                 :          1 :     spdm_response = (void *)response;
+    1346                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1347                 :            :                      SPDM_ERROR);
+    1348                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+    1349                 :            : 
+    1350                 :          1 :     free(data1);
+    1351                 :          1 : }
+    1352                 :            : 
+    1353                 :          1 : void libspdm_test_responder_psk_exchange_case14(void **state)
+    1354                 :            : {
+    1355                 :            :     libspdm_return_t status;
+    1356                 :            :     libspdm_test_context_t *spdm_test_context;
+    1357                 :            :     libspdm_context_t *spdm_context;
+    1358                 :            :     size_t response_size;
+    1359                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1360                 :            :     spdm_psk_exchange_response_t *spdm_response;
+    1361                 :            :     void *data1;
+    1362                 :            :     size_t data_size1;
+    1363                 :            :     uint8_t *ptr;
+    1364                 :            :     size_t opaque_psk_exchange_req_size;
+    1365                 :            : 
+    1366                 :          1 :     spdm_test_context = *state;
+    1367                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1368                 :          1 :     spdm_test_context->case_id = 0xE;
+    1369                 :            : 
+    1370                 :            :     /* Clear previous sessions */
+    1371         [ -  + ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    1372                 :          0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    1373                 :            :     }
+    1374                 :            : 
+    1375                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1376                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1377                 :          1 :     spdm_context->connection_info.connection_state =
+    1378                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1379                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1380                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1381                 :          1 :     spdm_context->local_context.capability.flags |=
+    1382                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1383                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1384                 :            :         m_libspdm_use_hash_algo;
+    1385                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    1386                 :            :         m_libspdm_use_measurement_spec;
+    1387                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1388                 :            :         m_libspdm_use_measurement_hash_algo;
+    1389                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1390                 :            :         m_libspdm_use_dhe_algo;
+    1391                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1392                 :            :         m_libspdm_use_aead_algo;
+    1393                 :          1 :     spdm_context->connection_info.algorithm.key_schedule =
+    1394                 :            :         m_libspdm_use_key_schedule_algo;
+    1395                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1396                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    1397                 :            :                                                     &data_size1, NULL, NULL);
+    1398                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    1399                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    1400                 :            :         data_size1;
+    1401                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+    1402                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+    1403                 :            :         data_size1;
+    1404                 :            : 
+    1405                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1406                 :            : 
+    1407                 :          1 :     m_libspdm_psk_exchange_request7.psk_hint_length = 0;
+    1408                 :          1 :     m_libspdm_psk_exchange_request7.context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
+    1409                 :          1 :     opaque_psk_exchange_req_size =
+    1410                 :          1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
+    1411                 :          1 :     m_libspdm_psk_exchange_request7.opaque_length =
+    1412                 :          1 :         (uint16_t)opaque_psk_exchange_req_size;
+    1413                 :          1 :     m_libspdm_psk_exchange_request7.req_session_id = 0xFFFF;
+    1414                 :          1 :     ptr = m_libspdm_psk_exchange_request7.context;
+    1415                 :          1 :     libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
+    1416                 :          1 :     ptr += m_libspdm_psk_exchange_request7.context_length;
+    1417                 :          1 :     libspdm_build_opaque_data_supported_version_data(
+    1418                 :            :         spdm_context, &opaque_psk_exchange_req_size, ptr);
+    1419                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1420                 :            :     spdm_context->transcript.message_m.buffer_size =
+    1421                 :            :         spdm_context->transcript.message_m.max_buffer_size;
+    1422                 :            : #endif
+    1423                 :          1 :     ptr += opaque_psk_exchange_req_size;
+    1424                 :          1 :     response_size = sizeof(response);
+    1425                 :          1 :     status = libspdm_get_response_psk_exchange(
+    1426                 :            :         spdm_context, m_libspdm_psk_exchange_request7_size,
+    1427                 :            :         &m_libspdm_psk_exchange_request7, &response_size, response);
+    1428                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1429                 :          1 :     assert_int_equal(
+    1430                 :            :         libspdm_secured_message_get_session_state(
+    1431                 :            :             spdm_context->session_info[0].secured_message_context),
+    1432                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    1433                 :          1 :     spdm_response = (void *)response;
+    1434                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1435                 :            :                      SPDM_PSK_EXCHANGE_RSP);
+    1436                 :          1 :     assert_int_equal(spdm_response->rsp_session_id, 0xFFFF);
+    1437                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1438                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
+    1439                 :            :                      0);
+    1440                 :            : #endif
+    1441                 :          1 :     free(data1);
+    1442                 :          1 : }
+    1443                 :            : 
+    1444                 :          1 : void libspdm_test_responder_psk_exchange_case15(void **state)
+    1445                 :            : {
+    1446                 :            :     libspdm_return_t status;
+    1447                 :            :     libspdm_test_context_t *spdm_test_context;
+    1448                 :            :     libspdm_context_t *spdm_context;
+    1449                 :            :     size_t response_size;
+    1450                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1451                 :            :     spdm_psk_exchange_response_t *spdm_response;
+    1452                 :            :     void *data1;
+    1453                 :            :     size_t data_size1;
+    1454                 :            :     uint8_t *ptr;
+    1455                 :            :     size_t opaque_psk_exchange_req_size;
+    1456                 :            : 
+    1457                 :          1 :     spdm_test_context = *state;
+    1458                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1459                 :          1 :     spdm_test_context->case_id = 0xF;
+    1460                 :            : 
+    1461                 :            :     /* Clear previous sessions */
+    1462         [ +  - ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    1463                 :          1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    1464                 :            :     }
+    1465                 :            : 
+    1466                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1467                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1468                 :          1 :     spdm_context->connection_info.connection_state =
+    1469                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1470                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1471                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1472                 :          1 :     spdm_context->local_context.capability.flags |=
+    1473                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1474                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1475                 :            :         m_libspdm_use_hash_algo;
+    1476                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    1477                 :            :         m_libspdm_use_measurement_spec;
+    1478                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1479                 :            :         m_libspdm_use_measurement_hash_algo;
+    1480                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1481                 :            :         m_libspdm_use_dhe_algo;
+    1482                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1483                 :            :         m_libspdm_use_aead_algo;
+    1484                 :          1 :     spdm_context->connection_info.algorithm.key_schedule =
+    1485                 :            :         m_libspdm_use_key_schedule_algo;
+    1486                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1487                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    1488                 :            :                                                     &data_size1, NULL, NULL);
+    1489                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    1490                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    1491                 :            :         data_size1;
+    1492                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+    1493                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+    1494                 :            :         data_size1;
+    1495                 :            : 
+    1496                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1497                 :            : 
+    1498                 :          1 :     m_libspdm_psk_exchange_request8.psk_hint_length =
+    1499                 :            :         (uint16_t)sizeof(LIBSPDM_TEST_PSK_HINT_STRING);
+    1500                 :          1 :     m_libspdm_psk_exchange_request8.context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
+    1501                 :          1 :     opaque_psk_exchange_req_size = 0;
+    1502                 :          1 :     m_libspdm_psk_exchange_request8.opaque_length =
+    1503                 :          1 :         (uint16_t)opaque_psk_exchange_req_size;
+    1504                 :          1 :     m_libspdm_psk_exchange_request8.req_session_id = 0xFFFF;
+    1505                 :          1 :     ptr = m_libspdm_psk_exchange_request8.psk_hint;
+    1506                 :          1 :     libspdm_copy_mem(ptr, sizeof(m_libspdm_psk_exchange_request8.psk_hint),
+    1507                 :            :                      LIBSPDM_TEST_PSK_HINT_STRING,
+    1508                 :            :                      sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+    1509                 :          1 :     ptr += m_libspdm_psk_exchange_request8.psk_hint_length;
+    1510                 :          1 :     libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
+    1511                 :          1 :     ptr += m_libspdm_psk_exchange_request8.context_length;
+    1512                 :            : 
+    1513                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1514                 :            :     spdm_context->transcript.message_m.buffer_size =
+    1515                 :            :         spdm_context->transcript.message_m.max_buffer_size;
+    1516                 :            : #endif
+    1517                 :          1 :     ptr += opaque_psk_exchange_req_size;
+    1518                 :          1 :     response_size = sizeof(response);
+    1519                 :          1 :     status = libspdm_get_response_psk_exchange(
+    1520                 :            :         spdm_context, m_libspdm_psk_exchange_request8_size,
+    1521                 :            :         &m_libspdm_psk_exchange_request8, &response_size, response);
+    1522                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1523                 :          1 :     assert_int_equal(
+    1524                 :            :         libspdm_secured_message_get_session_state(
+    1525                 :            :             spdm_context->session_info[0].secured_message_context),
+    1526                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    1527                 :          1 :     spdm_response = (void *)response;
+    1528                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1529                 :            :                      SPDM_PSK_EXCHANGE_RSP);
+    1530                 :          1 :     assert_int_equal(spdm_response->rsp_session_id, 0xFFFF);
+    1531                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1532                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
+    1533                 :            :                      0);
+    1534                 :            : #endif
+    1535                 :          1 :     free(data1);
+    1536                 :          1 : }
+    1537                 :            : 
+    1538                 :          1 : void libspdm_test_responder_psk_exchange_case16(void **state)
+    1539                 :            : {
+    1540                 :            :     libspdm_return_t status;
+    1541                 :            :     libspdm_test_context_t *spdm_test_context;
+    1542                 :            :     libspdm_context_t *spdm_context;
+    1543                 :            :     size_t response_size;
+    1544                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1545                 :            :     spdm_psk_exchange_response_t *spdm_response;
+    1546                 :            :     void *data1;
+    1547                 :            :     size_t data_size1;
+    1548                 :            :     uint8_t *ptr;
+    1549                 :            :     size_t opaque_psk_exchange_req_size;
+    1550                 :            : 
+    1551                 :          1 :     spdm_test_context = *state;
+    1552                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1553                 :          1 :     spdm_test_context->case_id = 0x10;
+    1554                 :            : 
+    1555                 :            :     /* Clear previous sessions */
+    1556         [ +  - ]:          1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
+    1557                 :          1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
+    1558                 :            :     }
+    1559                 :            : 
+    1560                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1561                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1562                 :          1 :     spdm_context->connection_info.connection_state =
+    1563                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1564                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1565                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1566                 :          1 :     spdm_context->local_context.capability.flags |=
+    1567                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1568                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1569                 :            :         m_libspdm_use_hash_algo;
+    1570                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    1571                 :            :         m_libspdm_use_measurement_spec;
+    1572                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1573                 :            :         m_libspdm_use_measurement_hash_algo;
+    1574                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1575                 :            :         m_libspdm_use_dhe_algo;
+    1576                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1577                 :            :         m_libspdm_use_aead_algo;
+    1578                 :          1 :     spdm_context->connection_info.algorithm.key_schedule =
+    1579                 :            :         m_libspdm_use_key_schedule_algo;
+    1580                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1581                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    1582                 :            :                                                     &data_size1, NULL, NULL);
+    1583                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    1584                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    1585                 :            :         data_size1;
+    1586                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+    1587                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+    1588                 :            :         data_size1;
+    1589                 :            : 
+    1590                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1591                 :            : 
+    1592                 :          1 :     m_libspdm_psk_exchange_request9.psk_hint_length = 0;
+    1593                 :          1 :     m_libspdm_psk_exchange_request9.context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
+    1594                 :          1 :     opaque_psk_exchange_req_size = 0;
+    1595                 :          1 :     m_libspdm_psk_exchange_request9.opaque_length =
+    1596                 :          1 :         (uint16_t)opaque_psk_exchange_req_size;
+    1597                 :          1 :     m_libspdm_psk_exchange_request9.req_session_id = 0xFFFF;
+    1598                 :          1 :     ptr = m_libspdm_psk_exchange_request9.context;
+    1599                 :          1 :     libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
+    1600                 :          1 :     ptr += m_libspdm_psk_exchange_request9.context_length;
+    1601                 :            : 
+    1602                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1603                 :            :     spdm_context->transcript.message_m.buffer_size =
+    1604                 :            :         spdm_context->transcript.message_m.max_buffer_size;
+    1605                 :            : #endif
+    1606                 :          1 :     ptr += opaque_psk_exchange_req_size;
+    1607                 :          1 :     response_size = sizeof(response);
+    1608                 :          1 :     status = libspdm_get_response_psk_exchange(
+    1609                 :            :         spdm_context, m_libspdm_psk_exchange_request9_size,
+    1610                 :            :         &m_libspdm_psk_exchange_request9, &response_size, response);
+    1611                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1612                 :          1 :     assert_int_equal(
+    1613                 :            :         libspdm_secured_message_get_session_state(
+    1614                 :            :             spdm_context->session_info[0].secured_message_context),
+    1615                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    1616                 :          1 :     spdm_response = (void *)response;
+    1617                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1618                 :            :                      SPDM_PSK_EXCHANGE_RSP);
+    1619                 :          1 :     assert_int_equal(spdm_response->rsp_session_id, 0xFFFF);
+    1620                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1621                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
+    1622                 :            :                      0);
+    1623                 :            : #endif
+    1624                 :          1 :     free(data1);
+    1625                 :          1 : }
+    1626                 :            : 
+    1627                 :          1 : void libspdm_test_responder_psk_exchange_case17(void **state)
+    1628                 :            : {
+    1629                 :            :     libspdm_return_t status;
+    1630                 :            :     libspdm_test_context_t *spdm_test_context;
+    1631                 :            :     libspdm_context_t *spdm_context;
+    1632                 :            :     size_t response_size;
+    1633                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1634                 :            :     spdm_psk_exchange_response_t *spdm_response;
+    1635                 :            :     void *data1;
+    1636                 :            :     size_t data_size1;
+    1637                 :            :     uint8_t *ptr;
+    1638                 :            :     size_t opaque_psk_exchange_req_size;
+    1639                 :            : 
+    1640                 :          1 :     spdm_test_context = *state;
+    1641                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1642                 :          1 :     spdm_test_context->case_id = 0x11;
+    1643                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+    1644                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1645                 :          1 :     spdm_context->connection_info.connection_state =
+    1646                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1647                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1648                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1649                 :          1 :     spdm_context->local_context.capability.flags |=
+    1650                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1651                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1652                 :            :         m_libspdm_use_hash_algo;
+    1653                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    1654                 :            :         m_libspdm_use_measurement_spec;
+    1655                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1656                 :            :         m_libspdm_use_measurement_hash_algo;
+    1657                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1658                 :            :         m_libspdm_use_dhe_algo;
+    1659                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1660                 :            :         m_libspdm_use_aead_algo;
+    1661                 :          1 :     spdm_context->connection_info.algorithm.key_schedule =
+    1662                 :            :         m_libspdm_use_key_schedule_algo;
+    1663                 :          1 :     spdm_context->connection_info.algorithm.other_params_support =
+    1664                 :            :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
+    1665                 :          1 :     libspdm_session_info_init(spdm_context,
+    1666                 :          1 :                               spdm_context->session_info,
+    1667                 :            :                               INVALID_SESSION_ID, false);
+    1668                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1669                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    1670                 :            :                                                     &data_size1, NULL, NULL);
+    1671                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    1672                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    1673                 :            :         data_size1;
+    1674                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+    1675                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+    1676                 :            :         data_size1;
+    1677                 :            : 
+    1678                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1679                 :            : 
+    1680                 :          1 :     m_libspdm_psk_exchange_request3.psk_hint_length =
+    1681                 :            :         (uint16_t)sizeof(LIBSPDM_TEST_PSK_HINT_STRING);
+    1682                 :          1 :     m_libspdm_psk_exchange_request3.context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
+    1683                 :          1 :     opaque_psk_exchange_req_size =
+    1684                 :          1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
+    1685                 :          1 :     m_libspdm_psk_exchange_request3.opaque_length =
+    1686                 :          1 :         (uint16_t)opaque_psk_exchange_req_size;
+    1687                 :          1 :     m_libspdm_psk_exchange_request3.req_session_id = 0xFFFF;
+    1688                 :          1 :     ptr = m_libspdm_psk_exchange_request3.psk_hint;
+    1689                 :          1 :     libspdm_copy_mem(ptr, sizeof(m_libspdm_psk_exchange_request3.psk_hint),
+    1690                 :            :                      LIBSPDM_TEST_PSK_HINT_STRING,
+    1691                 :            :                      sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+    1692                 :          1 :     ptr += m_libspdm_psk_exchange_request3.psk_hint_length;
+    1693                 :          1 :     libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
+    1694                 :          1 :     ptr += m_libspdm_psk_exchange_request3.context_length;
+    1695                 :          1 :     libspdm_build_opaque_data_supported_version_data(
+    1696                 :            :         spdm_context, &opaque_psk_exchange_req_size, ptr);
+    1697                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1698                 :            :     spdm_context->transcript.message_m.buffer_size =
+    1699                 :            :         spdm_context->transcript.message_m.max_buffer_size;
+    1700                 :            : #endif
+    1701                 :          1 :     ptr += opaque_psk_exchange_req_size;
+    1702                 :          1 :     response_size = sizeof(response);
+    1703                 :          1 :     status = libspdm_get_response_psk_exchange(
+    1704                 :            :         spdm_context, m_libspdm_psk_exchange_request3_size,
+    1705                 :            :         &m_libspdm_psk_exchange_request3, &response_size, response);
+    1706                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1707                 :          1 :     assert_int_equal(
+    1708                 :            :         libspdm_secured_message_get_session_state(
+    1709                 :            :             spdm_context->session_info[0].secured_message_context),
+    1710                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    1711                 :          1 :     assert_int_equal(spdm_context->session_info[0].session_policy, 0);
+    1712                 :          1 :     spdm_response = (void *)response;
+    1713                 :          1 :     assert_int_equal(spdm_response->header.spdm_version,
+    1714                 :            :                      SPDM_MESSAGE_VERSION_12);
+    1715                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1716                 :            :                      SPDM_PSK_EXCHANGE_RSP);
+    1717                 :          1 :     assert_int_equal(spdm_response->rsp_session_id, 0xFFFF);
+    1718                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1719                 :            :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
+    1720                 :            :                      0);
+    1721                 :            : #endif
+    1722                 :          1 :     free(data1);
+    1723                 :          1 : }
+    1724                 :            : 
+    1725                 :            : libspdm_test_context_t m_libspdm_responder_psk_exchange_test_context = {
+    1726                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+    1727                 :            :     false,
+    1728                 :            : };
+    1729                 :            : 
+    1730                 :          1 : int libspdm_responder_psk_exchange_test_main(void)
+    1731                 :            : {
+    1732                 :          1 :     const struct CMUnitTest spdm_responder_psk_exchange_tests[] = {
+    1733                 :            :         /* Success Case*/
+    1734                 :            :         cmocka_unit_test(libspdm_test_responder_psk_exchange_case1),
+    1735                 :            :         /* Bad request size*/
+    1736                 :            :         cmocka_unit_test(libspdm_test_responder_psk_exchange_case2),
+    1737                 :            :         /* response_state: SPDM_RESPONSE_STATE_BUSY*/
+    1738                 :            :         cmocka_unit_test(libspdm_test_responder_psk_exchange_case3),
+    1739                 :            :         /* response_state: SPDM_RESPONSE_STATE_NEED_RESYNC*/
+    1740                 :            :         cmocka_unit_test(libspdm_test_responder_psk_exchange_case4),
+    1741                 :            :         #if LIBSPDM_RESPOND_IF_READY_SUPPORT
+    1742                 :            :         /* response_state: SPDM_RESPONSE_STATE_NOT_READY*/
+    1743                 :            :         cmocka_unit_test(libspdm_test_responder_psk_exchange_case5),
+    1744                 :            :         #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
+    1745                 :            :         /* connection_state Check*/
+    1746                 :            :         cmocka_unit_test(libspdm_test_responder_psk_exchange_case6),
+    1747                 :            :         /* Buffer reset*/
+    1748                 :            :         cmocka_unit_test(libspdm_test_responder_psk_exchange_case7),
+    1749                 :            :         /* Buffer verification*/
+    1750                 :            :         cmocka_unit_test(libspdm_test_responder_psk_exchange_case8),
+    1751                 :            :         /* Successful response V1.2*/
+    1752                 :            :         cmocka_unit_test(libspdm_test_responder_psk_exchange_case9),
+    1753                 :            :         /* TCB measurement hash requested */
+    1754                 :            :         cmocka_unit_test(libspdm_test_responder_psk_exchange_case10),
+    1755                 :            :         /* All measurement hash requested */
+    1756                 :            :         cmocka_unit_test(libspdm_test_responder_psk_exchange_case11),
+    1757                 :            :         /* Reserved value in Measurement summary. Error + Invalid */
+    1758                 :            :         cmocka_unit_test(libspdm_test_responder_psk_exchange_case12),
+    1759                 :            :         /* TCB measurement hash requested, measurement flag not set */
+    1760                 :            :         cmocka_unit_test(libspdm_test_responder_psk_exchange_case13),
+    1761                 :            :         /* No PSKHint*/
+    1762                 :            :         cmocka_unit_test(libspdm_test_responder_psk_exchange_case14),
+    1763                 :            :         /* No OpaqueData*/
+    1764                 :            :         cmocka_unit_test(libspdm_test_responder_psk_exchange_case15),
+    1765                 :            :         /* No PSKHint and no OpaqueData*/
+    1766                 :            :         cmocka_unit_test(libspdm_test_responder_psk_exchange_case16),
+    1767                 :            :         /* OpaqueData only supports OpaqueDataFmt1, Success Case */
+    1768                 :            :         cmocka_unit_test(libspdm_test_responder_psk_exchange_case17),
+    1769                 :            :     };
+    1770                 :            : 
+    1771                 :          1 :     libspdm_setup_test_context(&m_libspdm_responder_psk_exchange_test_context);
+    1772                 :            : 
+    1773                 :          1 :     return cmocka_run_group_tests(spdm_responder_psk_exchange_tests,
+    1774                 :            :                                   libspdm_unit_test_group_setup,
+    1775                 :            :                                   libspdm_unit_test_group_teardown);
+    1776                 :            : }
+    1777                 :            : 
+    1778                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/psk_finish.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_responder/psk_finish.c.func-sort-c.html new file mode 100644 index 00000000000..313bd14ab97 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/psk_finish.c.func-sort-c.html @@ -0,0 +1,145 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/psk_finish.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - psk_finish.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:732732100.0 %
Date:2024-09-22 08:21:07Functions:1616100.0 %
Branches:1250.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_psk_finish_test_main1
libspdm_test_responder_psk_finish_case11
libspdm_test_responder_psk_finish_case101
libspdm_test_responder_psk_finish_case111
libspdm_test_responder_psk_finish_case121
libspdm_test_responder_psk_finish_case131
libspdm_test_responder_psk_finish_case141
libspdm_test_responder_psk_finish_case21
libspdm_test_responder_psk_finish_case31
libspdm_test_responder_psk_finish_case41
libspdm_test_responder_psk_finish_case51
libspdm_test_responder_psk_finish_case61
libspdm_test_responder_psk_finish_case71
libspdm_test_responder_psk_finish_case81
libspdm_test_responder_psk_finish_case91
libspdm_secured_message_set_request_finished_key14
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/psk_finish.c.func.html b/coverage_log/unit_test/test_spdm_responder/psk_finish.c.func.html new file mode 100644 index 00000000000..a04aad24124 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/psk_finish.c.func.html @@ -0,0 +1,145 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/psk_finish.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - psk_finish.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:732732100.0 %
Date:2024-09-22 08:21:07Functions:1616100.0 %
Branches:1250.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_psk_finish_test_main1
libspdm_secured_message_set_request_finished_key14
libspdm_test_responder_psk_finish_case11
libspdm_test_responder_psk_finish_case101
libspdm_test_responder_psk_finish_case111
libspdm_test_responder_psk_finish_case121
libspdm_test_responder_psk_finish_case131
libspdm_test_responder_psk_finish_case141
libspdm_test_responder_psk_finish_case21
libspdm_test_responder_psk_finish_case31
libspdm_test_responder_psk_finish_case41
libspdm_test_responder_psk_finish_case51
libspdm_test_responder_psk_finish_case61
libspdm_test_responder_psk_finish_case71
libspdm_test_responder_psk_finish_case81
libspdm_test_responder_psk_finish_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/psk_finish.c.gcov.html b/coverage_log/unit_test/test_spdm_responder/psk_finish.c.gcov.html new file mode 100644 index 00000000000..46184068d93 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/psk_finish.c.gcov.html @@ -0,0 +1,1705 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/psk_finish.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - psk_finish.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:732732100.0 %
Date:2024-09-22 08:21:07Functions:1616100.0 %
Branches:1250.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_responder_lib.h"
+       9                 :            : #include "internal/libspdm_secured_message_lib.h"
+      10                 :            : 
+      11                 :            : #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
+      12                 :            : #pragma pack(1)
+      13                 :            : typedef struct {
+      14                 :            :     spdm_message_header_t header;
+      15                 :            :     uint8_t verify_data[LIBSPDM_MAX_HASH_SIZE];
+      16                 :            : } libspdm_psk_finish_request_mine_t;
+      17                 :            : #pragma pack()
+      18                 :            : 
+      19                 :            : static libspdm_th_managed_buffer_t th_curr;
+      20                 :            : 
+      21                 :            : libspdm_psk_finish_request_mine_t m_libspdm_psk_finish_request1 = {
+      22                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_PSK_FINISH, 0, 0 },
+      23                 :            : };
+      24                 :            : size_t m_libspdm_psk_finish_request1_size = sizeof(m_libspdm_psk_finish_request1);
+      25                 :            : 
+      26                 :            : libspdm_psk_finish_request_mine_t m_libspdm_psk_finish_request2 = {
+      27                 :            :     { SPDM_MESSAGE_VERSION_11, SPDM_PSK_FINISH, 0, 0 },
+      28                 :            : };
+      29                 :            : size_t m_libspdm_psk_finish_request2_size = LIBSPDM_MAX_SPDM_MSG_SIZE;
+      30                 :            : 
+      31                 :            : static uint8_t m_libspdm_dummy_buffer[LIBSPDM_MAX_HASH_SIZE];
+      32                 :            : 
+      33                 :         14 : static void libspdm_secured_message_set_request_finished_key(
+      34                 :            :     void *spdm_secured_message_context, const void *key, size_t key_size)
+      35                 :            : {
+      36                 :            :     libspdm_secured_message_context_t *secured_message_context;
+      37                 :            : 
+      38                 :         14 :     secured_message_context = spdm_secured_message_context;
+      39         [ -  + ]:         14 :     LIBSPDM_ASSERT(key_size == secured_message_context->hash_size);
+      40                 :         14 :     libspdm_copy_mem(secured_message_context->handshake_secret.request_finished_key,
+      41                 :            :                      sizeof(secured_message_context->handshake_secret.request_finished_key),
+      42                 :            :                      key, secured_message_context->hash_size);
+      43                 :         14 : }
+      44                 :            : 
+      45                 :            : /**
+      46                 :            :  * Test 1: receiving a correct PSK_FINISH message from the requester with a
+      47                 :            :  * correct MAC.
+      48                 :            :  * Expected behavior: the responder accepts the request and produces a valid
+      49                 :            :  * PSK_FINISH_RSP response message.
+      50                 :            :  **/
+      51                 :          1 : void libspdm_test_responder_psk_finish_case1(void **state)
+      52                 :            : {
+      53                 :            :     libspdm_return_t status;
+      54                 :            :     libspdm_test_context_t *spdm_test_context;
+      55                 :            :     libspdm_context_t *spdm_context;
+      56                 :            :     size_t response_size;
+      57                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+      58                 :            :     spdm_psk_finish_response_t *spdm_response;
+      59                 :            :     void *data1;
+      60                 :            :     size_t data_size1;
+      61                 :            :     uint8_t *ptr;
+      62                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+      63                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+      64                 :            :     libspdm_session_info_t *session_info;
+      65                 :            :     uint32_t session_id;
+      66                 :            :     uint32_t hash_size;
+      67                 :            :     uint32_t hmac_size;
+      68                 :            : 
+      69                 :          1 :     spdm_test_context = *state;
+      70                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+      71                 :          1 :     spdm_test_context->case_id = 0x1;
+      72                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+      73                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+      74                 :          1 :     spdm_context->connection_info.connection_state =
+      75                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+      76                 :          1 :     spdm_context->connection_info.capability.flags |=
+      77                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+      78                 :          1 :     spdm_context->local_context.capability.flags |=
+      79                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+      80                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+      81                 :            :         m_libspdm_use_hash_algo;
+      82                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+      83                 :            :         m_libspdm_use_asym_algo;
+      84                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+      85                 :            :         m_libspdm_use_measurement_spec;
+      86                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+      87                 :            :         m_libspdm_use_measurement_hash_algo;
+      88                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+      89                 :            :         m_libspdm_use_dhe_algo;
+      90                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+      91                 :            :         m_libspdm_use_aead_algo;
+      92                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+      93                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+      94                 :            :                                                     &data_size1, NULL, NULL);
+      95                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+      96                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+      97                 :            :         data_size1;
+      98                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+      99                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+     100                 :            :         data_size1;
+     101                 :            : 
+     102                 :          1 :     libspdm_reset_message_a(spdm_context);
+     103                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     104                 :            : 
+     105                 :          1 :     session_id = 0xFFFFFFFF;
+     106                 :          1 :     spdm_context->latest_session_id = session_id;
+     107                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+     108                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+     109                 :          1 :     session_info = &spdm_context->session_info[0];
+     110                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+     111                 :          1 :     libspdm_session_info_set_psk_hint(session_info,
+     112                 :            :                                       LIBSPDM_TEST_PSK_HINT_STRING,
+     113                 :            :                                       sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+     114                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     115                 :          1 :     libspdm_set_mem(m_libspdm_dummy_buffer, hash_size, (uint8_t)(0xFF));
+     116                 :          1 :     libspdm_secured_message_set_request_finished_key(
+     117                 :            :         session_info->secured_message_context, m_libspdm_dummy_buffer,
+     118                 :            :         hash_size);
+     119                 :          1 :     libspdm_secured_message_set_session_state(
+     120                 :            :         session_info->secured_message_context,
+     121                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+     122                 :            : 
+     123                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     124                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     125                 :          1 :     ptr = m_libspdm_psk_finish_request1.verify_data;
+     126                 :          1 :     libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+     127                 :            :     /* transcript.message_a size is 0
+     128                 :            :      * session_transcript.message_k is 0*/
+     129                 :          1 :     libspdm_append_managed_buffer(&th_curr, (uint8_t *)&m_libspdm_psk_finish_request1,
+     130                 :            :                                   sizeof(spdm_psk_finish_request_t));
+     131                 :          1 :     libspdm_set_mem(request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+     132                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+     133                 :            :                      libspdm_get_managed_buffer_size(&th_curr), hash_data);
+     134                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+     135                 :            :                      request_finished_key, hash_size, ptr);
+     136                 :          1 :     m_libspdm_psk_finish_request1_size =
+     137                 :          1 :         sizeof(spdm_psk_finish_request_t) + hmac_size;
+     138                 :          1 :     response_size = sizeof(response);
+     139                 :          1 :     status = libspdm_get_response_psk_finish(spdm_context,
+     140                 :            :                                              m_libspdm_psk_finish_request1_size,
+     141                 :            :                                              &m_libspdm_psk_finish_request1,
+     142                 :            :                                              &response_size, response);
+     143                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     144                 :          1 :     assert_int_equal(response_size, sizeof(spdm_psk_finish_response_t));
+     145                 :          1 :     spdm_response = (void *)response;
+     146                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     147                 :            :                      SPDM_PSK_FINISH_RSP);
+     148                 :          1 :     free(data1);
+     149                 :          1 : }
+     150                 :            : 
+     151                 :            : /**
+     152                 :            :  * Test 2: receiving a PSK_FINISH message larger than specified.
+     153                 :            :  * Expected behavior: the responder refuses the PSK_FINISH message and
+     154                 :            :  * produces an ERROR message indicating the InvalidRequest.
+     155                 :            :  **/
+     156                 :          1 : void libspdm_test_responder_psk_finish_case2(void **state)
+     157                 :            : {
+     158                 :            :     libspdm_return_t status;
+     159                 :            :     libspdm_test_context_t *spdm_test_context;
+     160                 :            :     libspdm_context_t *spdm_context;
+     161                 :            :     size_t response_size;
+     162                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     163                 :            :     spdm_psk_finish_response_t *spdm_response;
+     164                 :            :     void *data1;
+     165                 :            :     size_t data_size1;
+     166                 :            :     uint8_t *ptr;
+     167                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     168                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+     169                 :            :     libspdm_session_info_t *session_info;
+     170                 :            :     uint32_t session_id;
+     171                 :            :     uint32_t hash_size;
+     172                 :            : 
+     173                 :          1 :     spdm_test_context = *state;
+     174                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     175                 :          1 :     spdm_test_context->case_id = 0x2;
+     176                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     177                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     178                 :          1 :     spdm_context->connection_info.connection_state =
+     179                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     180                 :          1 :     spdm_context->connection_info.capability.flags |=
+     181                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     182                 :          1 :     spdm_context->local_context.capability.flags |=
+     183                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     184                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     185                 :            :         m_libspdm_use_hash_algo;
+     186                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     187                 :            :         m_libspdm_use_asym_algo;
+     188                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     189                 :            :         m_libspdm_use_measurement_spec;
+     190                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     191                 :            :         m_libspdm_use_measurement_hash_algo;
+     192                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     193                 :            :         m_libspdm_use_dhe_algo;
+     194                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     195                 :            :         m_libspdm_use_aead_algo;
+     196                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     197                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     198                 :            :                                                     &data_size1, NULL, NULL);
+     199                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     200                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     201                 :            :         data_size1;
+     202                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+     203                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+     204                 :            :         data_size1;
+     205                 :            : 
+     206                 :          1 :     libspdm_reset_message_a(spdm_context);
+     207                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     208                 :            : 
+     209                 :          1 :     session_id = 0xFFFFFFFF;
+     210                 :          1 :     spdm_context->latest_session_id = session_id;
+     211                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+     212                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+     213                 :          1 :     session_info = &spdm_context->session_info[0];
+     214                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+     215                 :          1 :     libspdm_session_info_set_psk_hint(session_info,
+     216                 :            :                                       LIBSPDM_TEST_PSK_HINT_STRING,
+     217                 :            :                                       sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+     218                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     219                 :          1 :     libspdm_set_mem(m_libspdm_dummy_buffer, hash_size, (uint8_t)(0xFF));
+     220                 :          1 :     libspdm_secured_message_set_request_finished_key(
+     221                 :            :         session_info->secured_message_context, m_libspdm_dummy_buffer,
+     222                 :            :         hash_size);
+     223                 :          1 :     libspdm_secured_message_set_session_state(
+     224                 :            :         session_info->secured_message_context,
+     225                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+     226                 :            : 
+     227                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     228                 :          1 :     ptr = m_libspdm_psk_finish_request2.verify_data;
+     229                 :          1 :     libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+     230                 :            :     /* transcript.message_a size is 0
+     231                 :            :      * session_transcript.message_k is 0*/
+     232                 :          1 :     libspdm_append_managed_buffer(&th_curr, (uint8_t *)&m_libspdm_psk_finish_request2,
+     233                 :            :                                   sizeof(spdm_psk_finish_request_t));
+     234                 :          1 :     libspdm_set_mem(request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+     235                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+     236                 :            :                      libspdm_get_managed_buffer_size(&th_curr), hash_data);
+     237                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+     238                 :            :                      request_finished_key, hash_size, ptr);
+     239                 :          1 :     response_size = sizeof(response);
+     240                 :          1 :     status = libspdm_get_response_psk_finish(spdm_context,
+     241                 :            :                                              m_libspdm_psk_finish_request2_size,
+     242                 :            :                                              &m_libspdm_psk_finish_request2,
+     243                 :            :                                              &response_size, response);
+     244                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     245                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     246                 :          1 :     spdm_response = (void *)response;
+     247                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     248                 :            :                      SPDM_ERROR);
+     249                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     250                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+     251                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     252                 :          1 :     free(data1);
+     253                 :          1 : }
+     254                 :            : 
+     255                 :            : /**
+     256                 :            :  * Test 3: receiving a correct PSK_FINISH from the requester, but the
+     257                 :            :  * responder is in a Busy state.
+     258                 :            :  * Expected behavior: the responder accepts the request, but produces an
+     259                 :            :  * ERROR message indicating the Busy state.
+     260                 :            :  **/
+     261                 :          1 : void libspdm_test_responder_psk_finish_case3(void **state)
+     262                 :            : {
+     263                 :            :     libspdm_return_t status;
+     264                 :            :     libspdm_test_context_t *spdm_test_context;
+     265                 :            :     libspdm_context_t *spdm_context;
+     266                 :            :     size_t response_size;
+     267                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     268                 :            :     spdm_psk_finish_response_t *spdm_response;
+     269                 :            :     void *data1;
+     270                 :            :     size_t data_size1;
+     271                 :            :     uint8_t *ptr;
+     272                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     273                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+     274                 :            :     libspdm_session_info_t *session_info;
+     275                 :            :     uint32_t session_id;
+     276                 :            :     uint32_t hash_size;
+     277                 :            :     uint32_t hmac_size;
+     278                 :            : 
+     279                 :          1 :     spdm_test_context = *state;
+     280                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     281                 :          1 :     spdm_test_context->case_id = 0x3;
+     282                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     283                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     284                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_BUSY;
+     285                 :          1 :     spdm_context->connection_info.connection_state =
+     286                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     287                 :          1 :     spdm_context->connection_info.capability.flags |=
+     288                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     289                 :          1 :     spdm_context->local_context.capability.flags |=
+     290                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     291                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     292                 :            :         m_libspdm_use_hash_algo;
+     293                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     294                 :            :         m_libspdm_use_asym_algo;
+     295                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     296                 :            :         m_libspdm_use_measurement_spec;
+     297                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     298                 :            :         m_libspdm_use_measurement_hash_algo;
+     299                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     300                 :            :         m_libspdm_use_dhe_algo;
+     301                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     302                 :            :         m_libspdm_use_aead_algo;
+     303                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     304                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     305                 :            :                                                     &data_size1, NULL, NULL);
+     306                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     307                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     308                 :            :         data_size1;
+     309                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+     310                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+     311                 :            :         data_size1;
+     312                 :            : 
+     313                 :          1 :     libspdm_reset_message_a(spdm_context);
+     314                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     315                 :            : 
+     316                 :          1 :     session_id = 0xFFFFFFFF;
+     317                 :          1 :     spdm_context->latest_session_id = session_id;
+     318                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+     319                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+     320                 :          1 :     session_info = &spdm_context->session_info[0];
+     321                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+     322                 :          1 :     libspdm_session_info_set_psk_hint(session_info,
+     323                 :            :                                       LIBSPDM_TEST_PSK_HINT_STRING,
+     324                 :            :                                       sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+     325                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     326                 :          1 :     libspdm_set_mem(m_libspdm_dummy_buffer, hash_size, (uint8_t)(0xFF));
+     327                 :          1 :     libspdm_secured_message_set_request_finished_key(
+     328                 :            :         session_info->secured_message_context, m_libspdm_dummy_buffer,
+     329                 :            :         hash_size);
+     330                 :          1 :     libspdm_secured_message_set_session_state(
+     331                 :            :         session_info->secured_message_context,
+     332                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+     333                 :            : 
+     334                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     335                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     336                 :          1 :     ptr = m_libspdm_psk_finish_request1.verify_data;
+     337                 :          1 :     libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+     338                 :            :     /* transcript.message_a size is 0
+     339                 :            :      * session_transcript.message_k is 0*/
+     340                 :          1 :     libspdm_append_managed_buffer(&th_curr, (uint8_t *)&m_libspdm_psk_finish_request1,
+     341                 :            :                                   sizeof(spdm_psk_finish_request_t));
+     342                 :          1 :     libspdm_set_mem(request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+     343                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+     344                 :            :                      libspdm_get_managed_buffer_size(&th_curr), hash_data);
+     345                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+     346                 :            :                      request_finished_key, hash_size, ptr);
+     347                 :          1 :     m_libspdm_psk_finish_request1_size =
+     348                 :          1 :         sizeof(spdm_psk_finish_request_t) + hmac_size;
+     349                 :          1 :     response_size = sizeof(response);
+     350                 :          1 :     status = libspdm_get_response_psk_finish(spdm_context,
+     351                 :            :                                              m_libspdm_psk_finish_request1_size,
+     352                 :            :                                              &m_libspdm_psk_finish_request1,
+     353                 :            :                                              &response_size, response);
+     354                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     355                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     356                 :          1 :     spdm_response = (void *)response;
+     357                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     358                 :            :                      SPDM_ERROR);
+     359                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_BUSY);
+     360                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     361                 :          1 :     assert_int_equal(spdm_context->response_state,
+     362                 :            :                      LIBSPDM_RESPONSE_STATE_BUSY);
+     363                 :          1 :     free(data1);
+     364                 :          1 : }
+     365                 :            : 
+     366                 :            : /**
+     367                 :            :  * Test 4: receiving a correct PSK_FINISH from the requester, but the
+     368                 :            :  * responder requires resynchronization with the requester.
+     369                 :            :  * Expected behavior: the responder accepts the request, but produces an
+     370                 :            :  * ERROR message indicating the NeedResynch state.
+     371                 :            :  **/
+     372                 :          1 : void libspdm_test_responder_psk_finish_case4(void **state)
+     373                 :            : {
+     374                 :            :     libspdm_return_t status;
+     375                 :            :     libspdm_test_context_t *spdm_test_context;
+     376                 :            :     libspdm_context_t *spdm_context;
+     377                 :            :     size_t response_size;
+     378                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     379                 :            :     spdm_psk_finish_response_t *spdm_response;
+     380                 :            :     void *data1;
+     381                 :            :     size_t data_size1;
+     382                 :            :     uint8_t *ptr;
+     383                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     384                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+     385                 :            :     libspdm_session_info_t *session_info;
+     386                 :            :     uint32_t session_id;
+     387                 :            :     uint32_t hash_size;
+     388                 :            :     uint32_t hmac_size;
+     389                 :            : 
+     390                 :          1 :     spdm_test_context = *state;
+     391                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     392                 :          1 :     spdm_test_context->case_id = 0x4;
+     393                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     394                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     395                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NEED_RESYNC;
+     396                 :          1 :     spdm_context->connection_info.connection_state =
+     397                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     398                 :          1 :     spdm_context->connection_info.capability.flags |=
+     399                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     400                 :          1 :     spdm_context->local_context.capability.flags |=
+     401                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     402                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     403                 :            :         m_libspdm_use_hash_algo;
+     404                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     405                 :            :         m_libspdm_use_asym_algo;
+     406                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     407                 :            :         m_libspdm_use_measurement_spec;
+     408                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     409                 :            :         m_libspdm_use_measurement_hash_algo;
+     410                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     411                 :            :         m_libspdm_use_dhe_algo;
+     412                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     413                 :            :         m_libspdm_use_aead_algo;
+     414                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     415                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     416                 :            :                                                     &data_size1, NULL, NULL);
+     417                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     418                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     419                 :            :         data_size1;
+     420                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+     421                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+     422                 :            :         data_size1;
+     423                 :            : 
+     424                 :          1 :     libspdm_reset_message_a(spdm_context);
+     425                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     426                 :            : 
+     427                 :          1 :     session_id = 0xFFFFFFFF;
+     428                 :          1 :     spdm_context->latest_session_id = session_id;
+     429                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+     430                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+     431                 :          1 :     session_info = &spdm_context->session_info[0];
+     432                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+     433                 :          1 :     libspdm_session_info_set_psk_hint(session_info,
+     434                 :            :                                       LIBSPDM_TEST_PSK_HINT_STRING,
+     435                 :            :                                       sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+     436                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     437                 :          1 :     libspdm_set_mem(m_libspdm_dummy_buffer, hash_size, (uint8_t)(0xFF));
+     438                 :          1 :     libspdm_secured_message_set_request_finished_key(
+     439                 :            :         session_info->secured_message_context, m_libspdm_dummy_buffer,
+     440                 :            :         hash_size);
+     441                 :          1 :     libspdm_secured_message_set_session_state(
+     442                 :            :         session_info->secured_message_context,
+     443                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+     444                 :            : 
+     445                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     446                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     447                 :          1 :     ptr = m_libspdm_psk_finish_request1.verify_data;
+     448                 :          1 :     libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+     449                 :            :     /* transcript.message_a size is 0
+     450                 :            :      * session_transcript.message_k is 0*/
+     451                 :          1 :     libspdm_append_managed_buffer(&th_curr, (uint8_t *)&m_libspdm_psk_finish_request1,
+     452                 :            :                                   sizeof(spdm_psk_finish_request_t));
+     453                 :          1 :     libspdm_set_mem(request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+     454                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+     455                 :            :                      libspdm_get_managed_buffer_size(&th_curr), hash_data);
+     456                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+     457                 :            :                      request_finished_key, hash_size, ptr);
+     458                 :          1 :     m_libspdm_psk_finish_request1_size =
+     459                 :          1 :         sizeof(spdm_psk_finish_request_t) + hmac_size;
+     460                 :          1 :     response_size = sizeof(response);
+     461                 :          1 :     status = libspdm_get_response_psk_finish(spdm_context,
+     462                 :            :                                              m_libspdm_psk_finish_request1_size,
+     463                 :            :                                              &m_libspdm_psk_finish_request1,
+     464                 :            :                                              &response_size, response);
+     465                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     466                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     467                 :          1 :     spdm_response = (void *)response;
+     468                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     469                 :            :                      SPDM_ERROR);
+     470                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     471                 :            :                      SPDM_ERROR_CODE_REQUEST_RESYNCH);
+     472                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     473                 :          1 :     assert_int_equal(spdm_context->response_state,
+     474                 :            :                      LIBSPDM_RESPONSE_STATE_NEED_RESYNC);
+     475                 :          1 :     free(data1);
+     476                 :          1 : }
+     477                 :            : 
+     478                 :            : #if LIBSPDM_RESPOND_IF_READY_SUPPORT
+     479                 :            : /**
+     480                 :            :  * Test 5: receiving a correct PSK_FINISH from the requester, but the
+     481                 :            :  * responder could not produce the response in time.
+     482                 :            :  * Expected behavior: the responder accepts the request, but produces an
+     483                 :            :  * ERROR message indicating the ResponseNotReady state.
+     484                 :            :  **/
+     485                 :          1 : void libspdm_test_responder_psk_finish_case5(void **state)
+     486                 :            : {
+     487                 :            :     libspdm_return_t status;
+     488                 :            :     libspdm_test_context_t *spdm_test_context;
+     489                 :            :     libspdm_context_t *spdm_context;
+     490                 :            :     size_t response_size;
+     491                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     492                 :            :     spdm_psk_finish_response_t *spdm_response;
+     493                 :            :     void *data1;
+     494                 :            :     size_t data_size1;
+     495                 :            :     uint8_t *ptr;
+     496                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     497                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+     498                 :            :     libspdm_session_info_t *session_info;
+     499                 :            :     uint32_t session_id;
+     500                 :            :     uint32_t hash_size;
+     501                 :            :     uint32_t hmac_size;
+     502                 :            :     spdm_error_data_response_not_ready_t *error_data;
+     503                 :            : 
+     504                 :          1 :     spdm_test_context = *state;
+     505                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     506                 :          1 :     spdm_test_context->case_id = 0x5;
+     507                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     508                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     509                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NOT_READY;
+     510                 :          1 :     spdm_context->connection_info.connection_state =
+     511                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     512                 :          1 :     spdm_context->connection_info.capability.flags |=
+     513                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     514                 :          1 :     spdm_context->local_context.capability.flags |=
+     515                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     516                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     517                 :            :         m_libspdm_use_hash_algo;
+     518                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     519                 :            :         m_libspdm_use_asym_algo;
+     520                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     521                 :            :         m_libspdm_use_measurement_spec;
+     522                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     523                 :            :         m_libspdm_use_measurement_hash_algo;
+     524                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     525                 :            :         m_libspdm_use_dhe_algo;
+     526                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     527                 :            :         m_libspdm_use_aead_algo;
+     528                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     529                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     530                 :            :                                                     &data_size1, NULL, NULL);
+     531                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     532                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     533                 :            :         data_size1;
+     534                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+     535                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+     536                 :            :         data_size1;
+     537                 :            : 
+     538                 :          1 :     libspdm_reset_message_a(spdm_context);
+     539                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     540                 :            : 
+     541                 :          1 :     session_id = 0xFFFFFFFF;
+     542                 :          1 :     spdm_context->latest_session_id = session_id;
+     543                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+     544                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+     545                 :          1 :     session_info = &spdm_context->session_info[0];
+     546                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+     547                 :          1 :     libspdm_session_info_set_psk_hint(session_info,
+     548                 :            :                                       LIBSPDM_TEST_PSK_HINT_STRING,
+     549                 :            :                                       sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+     550                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     551                 :          1 :     libspdm_set_mem(m_libspdm_dummy_buffer, hash_size, (uint8_t)(0xFF));
+     552                 :          1 :     libspdm_secured_message_set_request_finished_key(
+     553                 :            :         session_info->secured_message_context, m_libspdm_dummy_buffer,
+     554                 :            :         hash_size);
+     555                 :          1 :     libspdm_secured_message_set_session_state(
+     556                 :            :         session_info->secured_message_context,
+     557                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+     558                 :            : 
+     559                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     560                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     561                 :          1 :     ptr = m_libspdm_psk_finish_request1.verify_data;
+     562                 :          1 :     libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+     563                 :            :     /* transcript.message_a size is 0
+     564                 :            :      * session_transcript.message_k is 0*/
+     565                 :          1 :     libspdm_append_managed_buffer(&th_curr, (uint8_t *)&m_libspdm_psk_finish_request1,
+     566                 :            :                                   sizeof(spdm_psk_finish_request_t));
+     567                 :          1 :     libspdm_set_mem(request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+     568                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+     569                 :            :                      libspdm_get_managed_buffer_size(&th_curr), hash_data);
+     570                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+     571                 :            :                      request_finished_key, hash_size, ptr);
+     572                 :          1 :     m_libspdm_psk_finish_request1_size =
+     573                 :          1 :         sizeof(spdm_psk_finish_request_t) + hmac_size;
+     574                 :          1 :     response_size = sizeof(response);
+     575                 :          1 :     status = libspdm_get_response_psk_finish(spdm_context,
+     576                 :            :                                              m_libspdm_psk_finish_request1_size,
+     577                 :            :                                              &m_libspdm_psk_finish_request1,
+     578                 :            :                                              &response_size, response);
+     579                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     580                 :          1 :     assert_int_equal(response_size,
+     581                 :            :                      sizeof(spdm_error_response_t) +
+     582                 :            :                      sizeof(spdm_error_data_response_not_ready_t));
+     583                 :          1 :     spdm_response = (void *)response;
+     584                 :          1 :     error_data =
+     585                 :            :         (spdm_error_data_response_not_ready_t *)(spdm_response + 1);
+     586                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     587                 :            :                      SPDM_ERROR);
+     588                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     589                 :            :                      SPDM_ERROR_CODE_RESPONSE_NOT_READY);
+     590                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     591                 :          1 :     assert_int_equal(spdm_context->response_state,
+     592                 :            :                      LIBSPDM_RESPONSE_STATE_NOT_READY);
+     593                 :          1 :     assert_int_equal(error_data->request_code, SPDM_PSK_FINISH);
+     594                 :          1 :     free(data1);
+     595                 :          1 : }
+     596                 :            : #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
+     597                 :            : 
+     598                 :            : /**
+     599                 :            :  * Test 6: receiving a correct PSK_FINISH from the requester, but the
+     600                 :            :  * responder is not set no receive a PSK-FINISH message because previous
+     601                 :            :  * messages (namely, GET_CAPABILITIES, NEGOTIATE_ALGORITHMS or
+     602                 :            :  * GET_DIGESTS) have not been received.
+     603                 :            :  * Expected behavior: the responder rejects the request, and produces an
+     604                 :            :  * ERROR message indicating the UnexpectedRequest.
+     605                 :            :  **/
+     606                 :          1 : void libspdm_test_responder_psk_finish_case6(void **state)
+     607                 :            : {
+     608                 :            :     libspdm_return_t status;
+     609                 :            :     libspdm_test_context_t *spdm_test_context;
+     610                 :            :     libspdm_context_t *spdm_context;
+     611                 :            :     size_t response_size;
+     612                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     613                 :            :     spdm_psk_finish_response_t *spdm_response;
+     614                 :            :     void *data1;
+     615                 :            :     size_t data_size1;
+     616                 :            :     uint8_t *ptr;
+     617                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     618                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+     619                 :            :     libspdm_session_info_t *session_info;
+     620                 :            :     uint32_t session_id;
+     621                 :            :     uint32_t hash_size;
+     622                 :            :     uint32_t hmac_size;
+     623                 :            : 
+     624                 :          1 :     spdm_test_context = *state;
+     625                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     626                 :          1 :     spdm_test_context->case_id = 0x6;
+     627                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     628                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     629                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+     630                 :          1 :     spdm_context->connection_info.connection_state =
+     631                 :            :         LIBSPDM_CONNECTION_STATE_NOT_STARTED;
+     632                 :          1 :     spdm_context->connection_info.capability.flags |=
+     633                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     634                 :          1 :     spdm_context->local_context.capability.flags |=
+     635                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     636                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     637                 :            :         m_libspdm_use_hash_algo;
+     638                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     639                 :            :         m_libspdm_use_asym_algo;
+     640                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     641                 :            :         m_libspdm_use_measurement_spec;
+     642                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     643                 :            :         m_libspdm_use_measurement_hash_algo;
+     644                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     645                 :            :         m_libspdm_use_dhe_algo;
+     646                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     647                 :            :         m_libspdm_use_aead_algo;
+     648                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     649                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     650                 :            :                                                     &data_size1, NULL, NULL);
+     651                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     652                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     653                 :            :         data_size1;
+     654                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+     655                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+     656                 :            :         data_size1;
+     657                 :            : 
+     658                 :          1 :     libspdm_reset_message_a(spdm_context);
+     659                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     660                 :            : 
+     661                 :          1 :     session_id = 0xFFFFFFFF;
+     662                 :          1 :     spdm_context->latest_session_id = session_id;
+     663                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+     664                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+     665                 :          1 :     session_info = &spdm_context->session_info[0];
+     666                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+     667                 :          1 :     libspdm_session_info_set_psk_hint(session_info,
+     668                 :            :                                       LIBSPDM_TEST_PSK_HINT_STRING,
+     669                 :            :                                       sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+     670                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     671                 :          1 :     libspdm_set_mem(m_libspdm_dummy_buffer, hash_size, (uint8_t)(0xFF));
+     672                 :          1 :     libspdm_secured_message_set_request_finished_key(
+     673                 :            :         session_info->secured_message_context, m_libspdm_dummy_buffer,
+     674                 :            :         hash_size);
+     675                 :          1 :     libspdm_secured_message_set_session_state(
+     676                 :            :         session_info->secured_message_context,
+     677                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+     678                 :            : 
+     679                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     680                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     681                 :          1 :     ptr = m_libspdm_psk_finish_request1.verify_data;
+     682                 :          1 :     libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+     683                 :            :     /* transcript.message_a size is 0
+     684                 :            :      * session_transcript.message_k is 0*/
+     685                 :          1 :     libspdm_append_managed_buffer(&th_curr, (uint8_t *)&m_libspdm_psk_finish_request1,
+     686                 :            :                                   sizeof(spdm_psk_finish_request_t));
+     687                 :          1 :     libspdm_set_mem(request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+     688                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+     689                 :            :                      libspdm_get_managed_buffer_size(&th_curr), hash_data);
+     690                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+     691                 :            :                      request_finished_key, hash_size, ptr);
+     692                 :          1 :     m_libspdm_psk_finish_request1_size =
+     693                 :          1 :         sizeof(spdm_psk_finish_request_t) + hmac_size;
+     694                 :          1 :     response_size = sizeof(response);
+     695                 :          1 :     status = libspdm_get_response_psk_finish(spdm_context,
+     696                 :            :                                              m_libspdm_psk_finish_request1_size,
+     697                 :            :                                              &m_libspdm_psk_finish_request1,
+     698                 :            :                                              &response_size, response);
+     699                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     700                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     701                 :          1 :     spdm_response = (void *)response;
+     702                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     703                 :            :                      SPDM_ERROR);
+     704                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     705                 :            :                      SPDM_ERROR_CODE_UNEXPECTED_REQUEST);
+     706                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     707                 :          1 :     free(data1);
+     708                 :          1 : }
+     709                 :            : 
+     710                 :          1 : void libspdm_test_responder_psk_finish_case7(void **state)
+     711                 :            : {
+     712                 :            :     libspdm_return_t status;
+     713                 :            :     libspdm_test_context_t *spdm_test_context;
+     714                 :            :     libspdm_context_t *spdm_context;
+     715                 :            :     size_t response_size;
+     716                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     717                 :            :     spdm_psk_finish_response_t *spdm_response;
+     718                 :            :     void *data1;
+     719                 :            :     size_t data_size1;
+     720                 :            :     uint8_t *ptr;
+     721                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     722                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+     723                 :            :     libspdm_session_info_t *session_info;
+     724                 :            :     uint32_t session_id;
+     725                 :            :     uint32_t hash_size;
+     726                 :            :     uint32_t hmac_size;
+     727                 :            : 
+     728                 :          1 :     spdm_test_context = *state;
+     729                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     730                 :          1 :     spdm_test_context->case_id = 0x7;
+     731                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     732                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     733                 :          1 :     spdm_context->connection_info.connection_state =
+     734                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     735                 :          1 :     spdm_context->connection_info.capability.flags |=
+     736                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     737                 :          1 :     spdm_context->local_context.capability.flags |=
+     738                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     739                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     740                 :            :         m_libspdm_use_hash_algo;
+     741                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     742                 :            :         m_libspdm_use_asym_algo;
+     743                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     744                 :            :         m_libspdm_use_measurement_spec;
+     745                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     746                 :            :         m_libspdm_use_measurement_hash_algo;
+     747                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     748                 :            :         m_libspdm_use_dhe_algo;
+     749                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     750                 :            :         m_libspdm_use_aead_algo;
+     751                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     752                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     753                 :            :                                                     &data_size1, NULL, NULL);
+     754                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     755                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     756                 :            :         data_size1;
+     757                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+     758                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+     759                 :            :         data_size1;
+     760                 :            : 
+     761                 :          1 :     libspdm_reset_message_a(spdm_context);
+     762                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     763                 :            : 
+     764                 :          1 :     session_id = 0xFFFFFFFF;
+     765                 :          1 :     spdm_context->latest_session_id = session_id;
+     766                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+     767                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+     768                 :          1 :     session_info = &spdm_context->session_info[0];
+     769                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+     770                 :          1 :     libspdm_session_info_set_psk_hint(session_info,
+     771                 :            :                                       LIBSPDM_TEST_PSK_HINT_STRING,
+     772                 :            :                                       sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+     773                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     774                 :          1 :     libspdm_set_mem(m_libspdm_dummy_buffer, hash_size, (uint8_t)(0xFF));
+     775                 :          1 :     libspdm_secured_message_set_request_finished_key(
+     776                 :            :         session_info->secured_message_context, m_libspdm_dummy_buffer,
+     777                 :            :         hash_size);
+     778                 :          1 :     libspdm_secured_message_set_session_state(
+     779                 :            :         session_info->secured_message_context,
+     780                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+     781                 :            : 
+     782                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     783                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     784                 :          1 :     ptr = m_libspdm_psk_finish_request1.verify_data;
+     785                 :          1 :     libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+     786                 :            :     /* transcript.message_a size is 0
+     787                 :            :      * session_transcript.message_k is 0*/
+     788                 :          1 :     libspdm_append_managed_buffer(&th_curr, (uint8_t *)&m_libspdm_psk_finish_request1,
+     789                 :            :                                   sizeof(spdm_psk_finish_request_t));
+     790                 :            : 
+     791                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     792                 :            :     session_info->session_transcript.message_m.buffer_size =
+     793                 :            :         session_info->session_transcript.message_m.max_buffer_size;
+     794                 :            :     spdm_context->transcript.message_b.buffer_size =
+     795                 :            :         spdm_context->transcript.message_b.max_buffer_size;
+     796                 :            :     spdm_context->transcript.message_c.buffer_size =
+     797                 :            :         spdm_context->transcript.message_c.max_buffer_size;
+     798                 :            :     spdm_context->transcript.message_mut_b.buffer_size =
+     799                 :            :         spdm_context->transcript.message_mut_b.max_buffer_size;
+     800                 :            :     spdm_context->transcript.message_mut_c.buffer_size =
+     801                 :            :         spdm_context->transcript.message_mut_c.max_buffer_size;
+     802                 :            : #endif
+     803                 :            : 
+     804                 :          1 :     libspdm_set_mem(request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+     805                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+     806                 :            :                      libspdm_get_managed_buffer_size(&th_curr), hash_data);
+     807                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+     808                 :            :                      request_finished_key, hash_size, ptr);
+     809                 :          1 :     m_libspdm_psk_finish_request1_size =
+     810                 :          1 :         sizeof(spdm_psk_finish_request_t) + hmac_size;
+     811                 :          1 :     response_size = sizeof(response);
+     812                 :          1 :     status = libspdm_get_response_psk_finish(spdm_context,
+     813                 :            :                                              m_libspdm_psk_finish_request1_size,
+     814                 :            :                                              &m_libspdm_psk_finish_request1,
+     815                 :            :                                              &response_size, response);
+     816                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     817                 :          1 :     assert_int_equal(response_size, sizeof(spdm_psk_finish_response_t));
+     818                 :          1 :     spdm_response = (void *)response;
+     819                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     820                 :            :                      SPDM_PSK_FINISH_RSP);
+     821                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     822                 :            :     assert_int_equal(session_info->session_transcript.message_m.buffer_size, 0);
+     823                 :            :     assert_int_equal(spdm_context->transcript.message_b.buffer_size, 0);
+     824                 :            :     assert_int_equal(spdm_context->transcript.message_c.buffer_size, 0);
+     825                 :            :     assert_int_equal(spdm_context->transcript.message_mut_b.buffer_size, 0);
+     826                 :            :     assert_int_equal(spdm_context->transcript.message_mut_c.buffer_size, 0);
+     827                 :            : #endif
+     828                 :            : 
+     829                 :          1 :     free(data1);
+     830                 :          1 : }
+     831                 :            : 
+     832                 :            : /**
+     833                 :            :  * Test 8: receiving a correct PSK_FINISH message from the requester, but
+     834                 :            :  * the responder has no capabilities for pre-shared keys.
+     835                 :            :  * Expected behavior: the responder refuses the PSK_FINISH message and
+     836                 :            :  * produces an ERROR message indicating the UnsupportedRequest.
+     837                 :            :  **/
+     838                 :          1 : void libspdm_test_responder_psk_finish_case8(void **state)
+     839                 :            : {
+     840                 :            :     libspdm_return_t status;
+     841                 :            :     libspdm_test_context_t *spdm_test_context;
+     842                 :            :     libspdm_context_t *spdm_context;
+     843                 :            :     size_t response_size;
+     844                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     845                 :            :     spdm_psk_finish_response_t *spdm_response;
+     846                 :            :     void *data1;
+     847                 :            :     size_t data_size1;
+     848                 :            :     uint8_t *ptr;
+     849                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     850                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+     851                 :            :     libspdm_session_info_t *session_info;
+     852                 :            :     uint32_t session_id;
+     853                 :            :     uint32_t hash_size;
+     854                 :            :     uint32_t hmac_size;
+     855                 :            : 
+     856                 :          1 :     spdm_test_context = *state;
+     857                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     858                 :          1 :     spdm_test_context->case_id = 0x8;
+     859                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     860                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     861                 :          1 :     spdm_context->connection_info.connection_state =
+     862                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     863                 :          1 :     spdm_context->connection_info.capability.flags &=
+     864                 :            :         ~(SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP);
+     865                 :          1 :     spdm_context->local_context.capability.flags &=
+     866                 :            :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
+     867                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     868                 :            :         m_libspdm_use_hash_algo;
+     869                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     870                 :            :         m_libspdm_use_asym_algo;
+     871                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     872                 :            :         m_libspdm_use_measurement_spec;
+     873                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     874                 :            :         m_libspdm_use_measurement_hash_algo;
+     875                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     876                 :            :         m_libspdm_use_dhe_algo;
+     877                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     878                 :            :         m_libspdm_use_aead_algo;
+     879                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     880                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     881                 :            :                                                     &data_size1, NULL, NULL);
+     882                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     883                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     884                 :            :         data_size1;
+     885                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+     886                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+     887                 :            :         data_size1;
+     888                 :            : 
+     889                 :          1 :     spdm_context->transcript.message_a.buffer_size = 0;
+     890                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     891                 :            : 
+     892                 :          1 :     session_id = 0xFFFFFFFF;
+     893                 :          1 :     spdm_context->latest_session_id = session_id;
+     894                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+     895                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+     896                 :          1 :     session_info = &spdm_context->session_info[0];
+     897                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+     898                 :          1 :     libspdm_session_info_set_psk_hint(session_info,
+     899                 :            :                                       LIBSPDM_TEST_PSK_HINT_STRING,
+     900                 :            :                                       sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+     901                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     902                 :          1 :     libspdm_set_mem(m_libspdm_dummy_buffer, hash_size, (uint8_t)(0xFF));
+     903                 :          1 :     libspdm_secured_message_set_request_finished_key(
+     904                 :            :         session_info->secured_message_context, m_libspdm_dummy_buffer,
+     905                 :            :         hash_size);
+     906                 :          1 :     libspdm_secured_message_set_session_state(
+     907                 :            :         session_info->secured_message_context,
+     908                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+     909                 :            : 
+     910                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     911                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+     912                 :          1 :     ptr = m_libspdm_psk_finish_request1.verify_data;
+     913                 :          1 :     libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+     914                 :            :     /* transcript.message_a size is 0
+     915                 :            :      * session_transcript.message_k is 0*/
+     916                 :          1 :     libspdm_append_managed_buffer(&th_curr, (uint8_t *)&m_libspdm_psk_finish_request1,
+     917                 :            :                                   sizeof(spdm_psk_finish_request_t));
+     918                 :          1 :     libspdm_set_mem(request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+     919                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+     920                 :            :                      libspdm_get_managed_buffer_size(&th_curr), hash_data);
+     921                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+     922                 :            :                      request_finished_key, hash_size, ptr);
+     923                 :          1 :     m_libspdm_psk_finish_request1_size =
+     924                 :          1 :         sizeof(spdm_psk_finish_request_t) + hmac_size;
+     925                 :          1 :     response_size = sizeof(response);
+     926                 :          1 :     status = libspdm_get_response_psk_finish(spdm_context,
+     927                 :            :                                              m_libspdm_psk_finish_request1_size,
+     928                 :            :                                              &m_libspdm_psk_finish_request1,
+     929                 :            :                                              &response_size, response);
+     930                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     931                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     932                 :          1 :     spdm_response = (void *)response;
+     933                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     934                 :            :                      SPDM_ERROR);
+     935                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     936                 :            :                      SPDM_ERROR_CODE_UNSUPPORTED_REQUEST);
+     937                 :          1 :     assert_int_equal(spdm_response->header.param2, SPDM_PSK_FINISH);
+     938                 :          1 :     free(data1);
+     939                 :          1 : }
+     940                 :            : 
+     941                 :            : /**
+     942                 :            :  * Test 9: receiving a correct PSK_FINISH message from the requester, but
+     943                 :            :  * the responder is not correctly setup by not initializing a session during
+     944                 :            :  * PSK_EXCHANGE.
+     945                 :            :  * Expected behavior: the responder refuses the PSK_FINISH message and
+     946                 :            :  * produces an ERROR message indicating the InvalidRequest.
+     947                 :            :  **/
+     948                 :          1 : void libspdm_test_responder_psk_finish_case9(void **state)
+     949                 :            : {
+     950                 :            :     libspdm_return_t status;
+     951                 :            :     libspdm_test_context_t *spdm_test_context;
+     952                 :            :     libspdm_context_t *spdm_context;
+     953                 :            :     size_t response_size;
+     954                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     955                 :            :     spdm_psk_finish_response_t *spdm_response;
+     956                 :            :     void *data1;
+     957                 :            :     size_t data_size1;
+     958                 :            :     uint8_t *ptr;
+     959                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     960                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+     961                 :            :     libspdm_session_info_t *session_info;
+     962                 :            :     uint32_t session_id;
+     963                 :            :     uint32_t hash_size;
+     964                 :            :     uint32_t hmac_size;
+     965                 :            : 
+     966                 :          1 :     spdm_test_context = *state;
+     967                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     968                 :          1 :     spdm_test_context->case_id = 0x9;
+     969                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     970                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     971                 :          1 :     spdm_context->connection_info.connection_state =
+     972                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     973                 :          1 :     spdm_context->connection_info.capability.flags |=
+     974                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     975                 :          1 :     spdm_context->local_context.capability.flags |=
+     976                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     977                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     978                 :            :         m_libspdm_use_hash_algo;
+     979                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     980                 :            :         m_libspdm_use_asym_algo;
+     981                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     982                 :            :         m_libspdm_use_measurement_spec;
+     983                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     984                 :            :         m_libspdm_use_measurement_hash_algo;
+     985                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+     986                 :            :         m_libspdm_use_dhe_algo;
+     987                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+     988                 :            :         m_libspdm_use_aead_algo;
+     989                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     990                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+     991                 :            :                                                     &data_size1, NULL, NULL);
+     992                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+     993                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     994                 :            :         data_size1;
+     995                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+     996                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+     997                 :            :         data_size1;
+     998                 :            : 
+     999                 :          1 :     spdm_context->transcript.message_a.buffer_size = 0;
+    1000                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+    1001                 :            : 
+    1002                 :          1 :     session_id = 0xFFFFFFFF;
+    1003                 :          1 :     spdm_context->latest_session_id = session_id;
+    1004                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+    1005                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+    1006                 :          1 :     session_info = &spdm_context->session_info[0];
+    1007                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+    1008                 :          1 :     libspdm_session_info_set_psk_hint(session_info,
+    1009                 :            :                                       LIBSPDM_TEST_PSK_HINT_STRING,
+    1010                 :            :                                       sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+    1011                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1012                 :          1 :     libspdm_set_mem(m_libspdm_dummy_buffer, hash_size, (uint8_t)(0xFF));
+    1013                 :          1 :     libspdm_secured_message_set_request_finished_key(
+    1014                 :            :         session_info->secured_message_context, m_libspdm_dummy_buffer,
+    1015                 :            :         hash_size);
+    1016                 :          1 :     libspdm_secured_message_set_session_state(
+    1017                 :            :         session_info->secured_message_context,
+    1018                 :            :         LIBSPDM_SESSION_STATE_NOT_STARTED);
+    1019                 :            : 
+    1020                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1021                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1022                 :          1 :     ptr = m_libspdm_psk_finish_request1.verify_data;
+    1023                 :          1 :     libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    1024                 :            :     /* transcript.message_a size is 0
+    1025                 :            :      * session_transcript.message_k is 0*/
+    1026                 :          1 :     libspdm_append_managed_buffer(&th_curr, (uint8_t *)&m_libspdm_psk_finish_request1,
+    1027                 :            :                                   sizeof(spdm_psk_finish_request_t));
+    1028                 :          1 :     libspdm_set_mem(request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+    1029                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1030                 :            :                      libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1031                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    1032                 :            :                      request_finished_key, hash_size, ptr);
+    1033                 :          1 :     m_libspdm_psk_finish_request1_size =
+    1034                 :          1 :         sizeof(spdm_psk_finish_request_t) + hmac_size;
+    1035                 :          1 :     response_size = sizeof(response);
+    1036                 :          1 :     status = libspdm_get_response_psk_finish(spdm_context,
+    1037                 :            :                                              m_libspdm_psk_finish_request1_size,
+    1038                 :            :                                              &m_libspdm_psk_finish_request1,
+    1039                 :            :                                              &response_size, response);
+    1040                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1041                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1042                 :          1 :     spdm_response = (void *)response;
+    1043                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1044                 :            :                      SPDM_ERROR);
+    1045                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1046                 :            :                      SPDM_ERROR_CODE_UNEXPECTED_REQUEST);
+    1047                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1048                 :          1 :     free(data1);
+    1049                 :          1 : }
+    1050                 :            : 
+    1051                 :            : /**
+    1052                 :            :  * Test 10: receiving a PSK_FINISH message from the requester with an
+    1053                 :            :  * incorrect MAC (all-zero).
+    1054                 :            :  * Expected behavior: the responder refuses the PSK_FINISH message and
+    1055                 :            :  * produces an ERROR message indicating the DecryptError.
+    1056                 :            :  **/
+    1057                 :          1 : void libspdm_test_responder_psk_finish_case10(void **state)
+    1058                 :            : {
+    1059                 :            :     libspdm_return_t status;
+    1060                 :            :     libspdm_test_context_t *spdm_test_context;
+    1061                 :            :     libspdm_context_t *spdm_context;
+    1062                 :            :     size_t response_size;
+    1063                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1064                 :            :     spdm_psk_finish_response_t *spdm_response;
+    1065                 :            :     void *data1;
+    1066                 :            :     size_t data_size1;
+    1067                 :            :     uint8_t *ptr;
+    1068                 :            :     libspdm_session_info_t *session_info;
+    1069                 :            :     uint32_t session_id;
+    1070                 :            :     uint32_t hash_size;
+    1071                 :            :     uint32_t hmac_size;
+    1072                 :            : 
+    1073                 :          1 :     spdm_test_context = *state;
+    1074                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1075                 :          1 :     spdm_test_context->case_id = 0xA;
+    1076                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1077                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1078                 :          1 :     spdm_context->connection_info.connection_state =
+    1079                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1080                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1081                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1082                 :          1 :     spdm_context->local_context.capability.flags |=
+    1083                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1084                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1085                 :            :         m_libspdm_use_hash_algo;
+    1086                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1087                 :            :         m_libspdm_use_asym_algo;
+    1088                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    1089                 :            :         m_libspdm_use_measurement_spec;
+    1090                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1091                 :            :         m_libspdm_use_measurement_hash_algo;
+    1092                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1093                 :            :         m_libspdm_use_dhe_algo;
+    1094                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1095                 :            :         m_libspdm_use_aead_algo;
+    1096                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1097                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    1098                 :            :                                                     &data_size1, NULL, NULL);
+    1099                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    1100                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    1101                 :            :         data_size1;
+    1102                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+    1103                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+    1104                 :            :         data_size1;
+    1105                 :            : 
+    1106                 :          1 :     spdm_context->transcript.message_a.buffer_size = 0;
+    1107                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+    1108                 :            : 
+    1109                 :          1 :     session_id = 0xFFFFFFFF;
+    1110                 :          1 :     spdm_context->latest_session_id = session_id;
+    1111                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+    1112                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+    1113                 :          1 :     session_info = &spdm_context->session_info[0];
+    1114                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+    1115                 :          1 :     libspdm_session_info_set_psk_hint(session_info,
+    1116                 :            :                                       LIBSPDM_TEST_PSK_HINT_STRING,
+    1117                 :            :                                       sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+    1118                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1119                 :          1 :     libspdm_set_mem(m_libspdm_dummy_buffer, hash_size, (uint8_t)(0xFF));
+    1120                 :          1 :     libspdm_secured_message_set_request_finished_key(
+    1121                 :            :         session_info->secured_message_context, m_libspdm_dummy_buffer,
+    1122                 :            :         hash_size);
+    1123                 :          1 :     libspdm_secured_message_set_session_state(
+    1124                 :            :         session_info->secured_message_context,
+    1125                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    1126                 :            : 
+    1127                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1128                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1129                 :          1 :     ptr = m_libspdm_psk_finish_request1.verify_data;
+    1130                 :          1 :     libspdm_set_mem(ptr, hmac_size, (uint8_t)(0x00)); /*all-zero MAC*/
+    1131                 :          1 :     m_libspdm_psk_finish_request1_size =
+    1132                 :          1 :         sizeof(spdm_psk_finish_request_t) + hmac_size;
+    1133                 :          1 :     response_size = sizeof(response);
+    1134                 :          1 :     status = libspdm_get_response_psk_finish(spdm_context,
+    1135                 :            :                                              m_libspdm_psk_finish_request1_size,
+    1136                 :            :                                              &m_libspdm_psk_finish_request1,
+    1137                 :            :                                              &response_size, response);
+    1138                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1139                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1140                 :          1 :     spdm_response = (void *)response;
+    1141                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1142                 :            :                      SPDM_ERROR);
+    1143                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1144                 :            :                      SPDM_ERROR_CODE_DECRYPT_ERROR);
+    1145                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1146                 :          1 :     free(data1);
+    1147                 :          1 : }
+    1148                 :            : 
+    1149                 :            : /**
+    1150                 :            :  * Test 11: receiving a PSK_FINISH message from the requester with an
+    1151                 :            :  * incorrect MAC (arbitrary).
+    1152                 :            :  * Expected behavior: the responder refuses the PSK_FINISH message and
+    1153                 :            :  * produces an ERROR message indicating the DecryptError.
+    1154                 :            :  **/
+    1155                 :          1 : void libspdm_test_responder_psk_finish_case11(void **state)
+    1156                 :            : {
+    1157                 :            :     libspdm_return_t status;
+    1158                 :            :     libspdm_test_context_t *spdm_test_context;
+    1159                 :            :     libspdm_context_t *spdm_context;
+    1160                 :            :     size_t response_size;
+    1161                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1162                 :            :     spdm_psk_finish_response_t *spdm_response;
+    1163                 :            :     void *data1;
+    1164                 :            :     size_t data_size1;
+    1165                 :            :     uint8_t *ptr;
+    1166                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    1167                 :            :     uint8_t zero_data[LIBSPDM_MAX_HASH_SIZE];
+    1168                 :            :     libspdm_session_info_t *session_info;
+    1169                 :            :     uint32_t session_id;
+    1170                 :            :     uint32_t hash_size;
+    1171                 :            :     uint32_t hmac_size;
+    1172                 :            : 
+    1173                 :          1 :     spdm_test_context = *state;
+    1174                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1175                 :          1 :     spdm_test_context->case_id = 0xB;
+    1176                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1177                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1178                 :          1 :     spdm_context->connection_info.connection_state =
+    1179                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1180                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1181                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1182                 :          1 :     spdm_context->local_context.capability.flags |=
+    1183                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1184                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1185                 :            :         m_libspdm_use_hash_algo;
+    1186                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1187                 :            :         m_libspdm_use_asym_algo;
+    1188                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    1189                 :            :         m_libspdm_use_measurement_spec;
+    1190                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1191                 :            :         m_libspdm_use_measurement_hash_algo;
+    1192                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1193                 :            :         m_libspdm_use_dhe_algo;
+    1194                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1195                 :            :         m_libspdm_use_aead_algo;
+    1196                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1197                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    1198                 :            :                                                     &data_size1, NULL, NULL);
+    1199                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    1200                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    1201                 :            :         data_size1;
+    1202                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+    1203                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+    1204                 :            :         data_size1;
+    1205                 :            : 
+    1206                 :          1 :     spdm_context->transcript.message_a.buffer_size = 0;
+    1207                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+    1208                 :            : 
+    1209                 :          1 :     session_id = 0xFFFFFFFF;
+    1210                 :          1 :     spdm_context->latest_session_id = session_id;
+    1211                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+    1212                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+    1213                 :          1 :     session_info = &spdm_context->session_info[0];
+    1214                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+    1215                 :          1 :     libspdm_session_info_set_psk_hint(session_info,
+    1216                 :            :                                       LIBSPDM_TEST_PSK_HINT_STRING,
+    1217                 :            :                                       sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+    1218                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1219                 :          1 :     libspdm_set_mem(m_libspdm_dummy_buffer, hash_size, (uint8_t)(0xFF));
+    1220                 :          1 :     libspdm_secured_message_set_request_finished_key(
+    1221                 :            :         session_info->secured_message_context, m_libspdm_dummy_buffer,
+    1222                 :            :         hash_size);
+    1223                 :          1 :     libspdm_secured_message_set_session_state(
+    1224                 :            :         session_info->secured_message_context,
+    1225                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    1226                 :            : 
+    1227                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1228                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1229                 :          1 :     ptr = m_libspdm_psk_finish_request1.verify_data;
+    1230                 :            :     /*arbitrary MAC*/
+    1231                 :          1 :     libspdm_set_mem(request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+    1232                 :          1 :     libspdm_set_mem(zero_data, hash_size, (uint8_t)(0x00));
+    1233                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, zero_data, hash_size,
+    1234                 :            :                      request_finished_key, hash_size, ptr);
+    1235                 :          1 :     m_libspdm_psk_finish_request1_size =
+    1236                 :          1 :         sizeof(spdm_psk_finish_request_t) + hmac_size;
+    1237                 :          1 :     response_size = sizeof(response);
+    1238                 :          1 :     status = libspdm_get_response_psk_finish(spdm_context,
+    1239                 :            :                                              m_libspdm_psk_finish_request1_size,
+    1240                 :            :                                              &m_libspdm_psk_finish_request1,
+    1241                 :            :                                              &response_size, response);
+    1242                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1243                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1244                 :          1 :     spdm_response = (void *)response;
+    1245                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1246                 :            :                      SPDM_ERROR);
+    1247                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1248                 :            :                      SPDM_ERROR_CODE_DECRYPT_ERROR);
+    1249                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1250                 :          1 :     free(data1);
+    1251                 :          1 : }
+    1252                 :            : 
+    1253                 :            : /**
+    1254                 :            :  * Test 12: receiving a PSK_FINISH message from the requester with an
+    1255                 :            :  * incorrect MAC size (a correct MAC repeated twice).
+    1256                 :            :  * Expected behavior: the responder refuses the PSK_FINISH message and
+    1257                 :            :  * produces an ERROR message indicating the InvalidRequest.
+    1258                 :            :  **/
+    1259                 :          1 : void libspdm_test_responder_psk_finish_case12(void **state)
+    1260                 :            : {
+    1261                 :            :     libspdm_return_t status;
+    1262                 :            :     libspdm_test_context_t *spdm_test_context;
+    1263                 :            :     libspdm_context_t *spdm_context;
+    1264                 :            :     size_t response_size;
+    1265                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1266                 :            :     spdm_psk_finish_response_t *spdm_response;
+    1267                 :            :     void *data1;
+    1268                 :            :     size_t data_size1;
+    1269                 :            :     uint8_t *ptr;
+    1270                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1271                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    1272                 :            :     libspdm_session_info_t *session_info;
+    1273                 :            :     uint32_t session_id;
+    1274                 :            :     uint32_t hash_size;
+    1275                 :            :     uint32_t hmac_size;
+    1276                 :            : 
+    1277                 :          1 :     spdm_test_context = *state;
+    1278                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1279                 :          1 :     spdm_test_context->case_id = 0xC;
+    1280                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1281                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1282                 :          1 :     spdm_context->connection_info.connection_state =
+    1283                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1284                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1285                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1286                 :          1 :     spdm_context->local_context.capability.flags |=
+    1287                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1288                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1289                 :            :         m_libspdm_use_hash_algo;
+    1290                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1291                 :            :         m_libspdm_use_asym_algo;
+    1292                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    1293                 :            :         m_libspdm_use_measurement_spec;
+    1294                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1295                 :            :         m_libspdm_use_measurement_hash_algo;
+    1296                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1297                 :            :         m_libspdm_use_dhe_algo;
+    1298                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1299                 :            :         m_libspdm_use_aead_algo;
+    1300                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1301                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    1302                 :            :                                                     &data_size1, NULL, NULL);
+    1303                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    1304                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    1305                 :            :         data_size1;
+    1306                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+    1307                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+    1308                 :            :         data_size1;
+    1309                 :            : 
+    1310                 :          1 :     spdm_context->transcript.message_a.buffer_size = 0;
+    1311                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+    1312                 :            : 
+    1313                 :          1 :     session_id = 0xFFFFFFFF;
+    1314                 :          1 :     spdm_context->latest_session_id = session_id;
+    1315                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+    1316                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+    1317                 :          1 :     session_info = &spdm_context->session_info[0];
+    1318                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+    1319                 :          1 :     libspdm_session_info_set_psk_hint(session_info,
+    1320                 :            :                                       LIBSPDM_TEST_PSK_HINT_STRING,
+    1321                 :            :                                       sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+    1322                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1323                 :          1 :     libspdm_set_mem(m_libspdm_dummy_buffer, hash_size, (uint8_t)(0xFF));
+    1324                 :          1 :     libspdm_secured_message_set_request_finished_key(
+    1325                 :            :         session_info->secured_message_context, m_libspdm_dummy_buffer,
+    1326                 :            :         hash_size);
+    1327                 :          1 :     libspdm_secured_message_set_session_state(
+    1328                 :            :         session_info->secured_message_context,
+    1329                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    1330                 :            : 
+    1331                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1332                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1333                 :          1 :     ptr = m_libspdm_psk_finish_request1.verify_data;
+    1334                 :          1 :     libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    1335                 :            :     /* transcript.message_a size is 0
+    1336                 :            :      * session_transcript.message_k is 0*/
+    1337                 :          1 :     libspdm_append_managed_buffer(&th_curr, (uint8_t *)&m_libspdm_psk_finish_request1,
+    1338                 :            :                                   sizeof(spdm_psk_finish_request_t));
+    1339                 :          1 :     libspdm_set_mem(request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+    1340                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1341                 :            :                      libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1342                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    1343                 :            :                      request_finished_key, hash_size, ptr);
+    1344                 :          1 :     libspdm_copy_mem(ptr, sizeof(m_libspdm_psk_finish_request1.verify_data),
+    1345                 :          1 :                      ptr + hmac_size, hmac_size); /* 2x HMAC size*/
+    1346                 :          1 :     m_libspdm_psk_finish_request1_size =
+    1347                 :          1 :         sizeof(spdm_psk_finish_request_t) + 2*hmac_size;
+    1348                 :          1 :     response_size = sizeof(response);
+    1349                 :          1 :     status = libspdm_get_response_psk_finish(spdm_context,
+    1350                 :            :                                              m_libspdm_psk_finish_request1_size,
+    1351                 :            :                                              &m_libspdm_psk_finish_request1,
+    1352                 :            :                                              &response_size, response);
+    1353                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1354                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1355                 :          1 :     spdm_response = (void *)response;
+    1356                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1357                 :            :                      SPDM_ERROR);
+    1358                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1359                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+    1360                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1361                 :          1 :     free(data1);
+    1362                 :          1 : }
+    1363                 :            : 
+    1364                 :            : /**
+    1365                 :            :  * Test 13: receiving a PSK_FINISH message from the requester with an
+    1366                 :            :  * incorrect MAC size (only the correct first half of the MAC).
+    1367                 :            :  * Expected behavior: the responder refuses the PSK_FINISH message and
+    1368                 :            :  * produces an ERROR message indicating the InvalidRequest.
+    1369                 :            :  **/
+    1370                 :          1 : void libspdm_test_responder_psk_finish_case13(void **state)
+    1371                 :            : {
+    1372                 :            :     libspdm_return_t status;
+    1373                 :            :     libspdm_test_context_t *spdm_test_context;
+    1374                 :            :     libspdm_context_t *spdm_context;
+    1375                 :            :     size_t response_size;
+    1376                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1377                 :            :     spdm_psk_finish_response_t *spdm_response;
+    1378                 :            :     void *data1;
+    1379                 :            :     size_t data_size1;
+    1380                 :            :     uint8_t *ptr;
+    1381                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1382                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    1383                 :            :     libspdm_session_info_t *session_info;
+    1384                 :            :     uint32_t session_id;
+    1385                 :            :     uint32_t hash_size;
+    1386                 :            :     uint32_t hmac_size;
+    1387                 :            : 
+    1388                 :          1 :     spdm_test_context = *state;
+    1389                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1390                 :          1 :     spdm_test_context->case_id = 0xD;
+    1391                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+    1392                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+    1393                 :          1 :     spdm_context->connection_info.connection_state =
+    1394                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1395                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1396                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1397                 :          1 :     spdm_context->local_context.capability.flags |=
+    1398                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1399                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+    1400                 :            :         m_libspdm_use_hash_algo;
+    1401                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+    1402                 :            :         m_libspdm_use_asym_algo;
+    1403                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+    1404                 :            :         m_libspdm_use_measurement_spec;
+    1405                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1406                 :            :         m_libspdm_use_measurement_hash_algo;
+    1407                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group =
+    1408                 :            :         m_libspdm_use_dhe_algo;
+    1409                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
+    1410                 :            :         m_libspdm_use_aead_algo;
+    1411                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1412                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    1413                 :            :                                                     &data_size1, NULL, NULL);
+    1414                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    1415                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    1416                 :            :         data_size1;
+    1417                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+    1418                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size =
+    1419                 :            :         data_size1;
+    1420                 :            : 
+    1421                 :          1 :     spdm_context->transcript.message_a.buffer_size = 0;
+    1422                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+    1423                 :            : 
+    1424                 :          1 :     session_id = 0xFFFFFFFF;
+    1425                 :          1 :     spdm_context->latest_session_id = session_id;
+    1426                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+    1427                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+    1428                 :          1 :     session_info = &spdm_context->session_info[0];
+    1429                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+    1430                 :          1 :     libspdm_session_info_set_psk_hint(session_info,
+    1431                 :            :                                       LIBSPDM_TEST_PSK_HINT_STRING,
+    1432                 :            :                                       sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+    1433                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1434                 :          1 :     libspdm_set_mem(m_libspdm_dummy_buffer, hash_size, (uint8_t)(0xFF));
+    1435                 :          1 :     libspdm_secured_message_set_request_finished_key(
+    1436                 :            :         session_info->secured_message_context, m_libspdm_dummy_buffer,
+    1437                 :            :         hash_size);
+    1438                 :          1 :     libspdm_secured_message_set_session_state(
+    1439                 :            :         session_info->secured_message_context,
+    1440                 :            :         LIBSPDM_SESSION_STATE_HANDSHAKING);
+    1441                 :            : 
+    1442                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1443                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1444                 :          1 :     ptr = m_libspdm_psk_finish_request1.verify_data;
+    1445                 :          1 :     libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    1446                 :            :     /* transcript.message_a size is 0
+    1447                 :            :      * session_transcript.message_k is 0*/
+    1448                 :          1 :     libspdm_append_managed_buffer(&th_curr, (uint8_t *)&m_libspdm_psk_finish_request1,
+    1449                 :            :                                   sizeof(spdm_psk_finish_request_t));
+    1450                 :          1 :     libspdm_set_mem(request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+    1451                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1452                 :            :                      libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1453                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    1454                 :            :                      request_finished_key, hash_size, ptr);
+    1455                 :          1 :     libspdm_set_mem(ptr + hmac_size/2, hmac_size/2, (uint8_t) 0x00); /* half HMAC size*/
+    1456                 :          1 :     m_libspdm_psk_finish_request1_size =
+    1457                 :          1 :         sizeof(spdm_psk_finish_request_t) + hmac_size/2;
+    1458                 :          1 :     response_size = sizeof(response);
+    1459                 :          1 :     status = libspdm_get_response_psk_finish(spdm_context,
+    1460                 :            :                                              m_libspdm_psk_finish_request1_size,
+    1461                 :            :                                              &m_libspdm_psk_finish_request1,
+    1462                 :            :                                              &response_size, response);
+    1463                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1464                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1465                 :          1 :     spdm_response = (void *)response;
+    1466                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+    1467                 :            :                      SPDM_ERROR);
+    1468                 :          1 :     assert_int_equal(spdm_response->header.param1,
+    1469                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+    1470                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1471                 :          1 :     free(data1);
+    1472                 :          1 : }
+    1473                 :            : 
+    1474                 :            : /**
+    1475                 :            :  * Test 14: receiving a correct PSK_FINISH from the requester.
+    1476                 :            :  * Expected behavior: the responder accepts the request and produces a valid PSK_FINISH
+    1477                 :            :  * response message, and buffer F receives the exchanged PSK_FINISH and PSK_FINISH_RSP messages.
+    1478                 :            :  **/
+    1479                 :          1 : void libspdm_test_responder_psk_finish_case14(void **state)
+    1480                 :            : {
+    1481                 :            :     libspdm_return_t status;
+    1482                 :            :     libspdm_test_context_t *spdm_test_context;
+    1483                 :            :     libspdm_context_t *spdm_context;
+    1484                 :            :     size_t response_size;
+    1485                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1486                 :            :     spdm_psk_finish_response_t *spdm_response;
+    1487                 :            :     void *data1;
+    1488                 :            :     size_t data_size1;
+    1489                 :            :     uint8_t *ptr;
+    1490                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+    1491                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+    1492                 :            :     libspdm_session_info_t *session_info;
+    1493                 :            :     uint32_t session_id;
+    1494                 :            :     uint32_t hash_size;
+    1495                 :            :     uint32_t hmac_size;
+    1496                 :            : 
+    1497                 :          1 :     spdm_test_context = *state;
+    1498                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1499                 :          1 :     spdm_test_context->case_id = 0xE;
+    1500                 :          1 :     spdm_context->connection_info.connection_state =
+    1501                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1502                 :          1 :     spdm_context->connection_info.capability.flags |=
+    1503                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+    1504                 :          1 :     spdm_context->local_context.capability.flags |=
+    1505                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+    1506                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1507                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1508                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+    1509                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+    1510                 :            :         m_libspdm_use_measurement_hash_algo;
+    1511                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+    1512                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+    1513                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1514                 :            :                                                     m_libspdm_use_asym_algo, &data1,
+    1515                 :            :                                                     &data_size1, NULL, NULL);
+    1516                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
+    1517                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
+    1518                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data1;
+    1519                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size = data_size1;
+    1520                 :            : 
+    1521                 :          1 :     libspdm_reset_message_a(spdm_context);
+    1522                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+    1523                 :            : 
+    1524                 :          1 :     session_id = 0xFFFFFFFF;
+    1525                 :          1 :     spdm_context->latest_session_id = session_id;
+    1526                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+    1527                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+    1528                 :          1 :     session_info = &spdm_context->session_info[0];
+    1529                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+    1530                 :          1 :     libspdm_session_info_set_psk_hint(session_info,
+    1531                 :            :                                       LIBSPDM_TEST_PSK_HINT_STRING,
+    1532                 :            :                                       sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+    1533                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1534                 :          1 :     libspdm_set_mem(m_libspdm_dummy_buffer, hash_size, (uint8_t)(0xFF));
+    1535                 :          1 :     libspdm_secured_message_set_request_finished_key(
+    1536                 :            :         session_info->secured_message_context, m_libspdm_dummy_buffer, hash_size);
+    1537                 :          1 :     libspdm_secured_message_set_session_state(
+    1538                 :            :         session_info->secured_message_context, LIBSPDM_SESSION_STATE_HANDSHAKING);
+    1539                 :            : 
+    1540                 :          1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1541                 :          1 :     hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
+    1542                 :          1 :     ptr = m_libspdm_psk_finish_request1.verify_data;
+    1543                 :          1 :     libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+    1544                 :            :     /* transcript.message_a size is 0
+    1545                 :            :      * session_transcript.message_k is 0*/
+    1546                 :          1 :     libspdm_append_managed_buffer(&th_curr, (uint8_t *)&m_libspdm_psk_finish_request1,
+    1547                 :            :                                   sizeof(spdm_psk_finish_request_t));
+    1548                 :          1 :     libspdm_set_mem(request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+    1549                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+    1550                 :            :                      libspdm_get_managed_buffer_size(&th_curr), hash_data);
+    1551                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    1552                 :            :                      request_finished_key, hash_size, ptr);
+    1553                 :          1 :     m_libspdm_psk_finish_request1_size = sizeof(spdm_psk_finish_request_t) + hmac_size;
+    1554                 :          1 :     response_size = sizeof(response);
+    1555                 :          1 :     status = libspdm_get_response_psk_finish(
+    1556                 :            :         spdm_context, m_libspdm_psk_finish_request1_size, &m_libspdm_psk_finish_request1,
+    1557                 :            :         &response_size, response);
+    1558                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1559                 :          1 :     assert_int_equal(response_size, sizeof(spdm_psk_finish_response_t));
+    1560                 :          1 :     spdm_response = (void *)response;
+    1561                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_PSK_FINISH_RSP);
+    1562                 :            : 
+    1563                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+    1564                 :            :     assert_int_equal(spdm_context->session_info[0].session_transcript.message_f.buffer_size,
+    1565                 :            :                      m_libspdm_psk_finish_request1_size + response_size);
+    1566                 :            :     assert_memory_equal(spdm_context->session_info[0].session_transcript.message_f.buffer,
+    1567                 :            :                         &m_libspdm_psk_finish_request1, m_libspdm_psk_finish_request1_size);
+    1568                 :            :     assert_memory_equal(spdm_context->session_info[0].session_transcript.message_f.buffer +
+    1569                 :            :                         m_libspdm_psk_finish_request1_size, response, response_size);
+    1570                 :            : #endif
+    1571                 :            : 
+    1572                 :          1 :     free(data1);
+    1573                 :          1 : }
+    1574                 :            : 
+    1575                 :            : libspdm_test_context_t m_libspdm_responder_psk_finish_test_context = {
+    1576                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+    1577                 :            :     false,
+    1578                 :            : };
+    1579                 :            : 
+    1580                 :          1 : int libspdm_responder_psk_finish_test_main(void)
+    1581                 :            : {
+    1582                 :          1 :     const struct CMUnitTest spdm_responder_psk_finish_tests[] = {
+    1583                 :            :         /* Success Case*/
+    1584                 :            :         cmocka_unit_test(libspdm_test_responder_psk_finish_case1),
+    1585                 :            :         /* Bad request size*/
+    1586                 :            :         cmocka_unit_test(libspdm_test_responder_psk_finish_case2),
+    1587                 :            :         /* response_state: SPDM_RESPONSE_STATE_BUSY*/
+    1588                 :            :         cmocka_unit_test(libspdm_test_responder_psk_finish_case3),
+    1589                 :            :         /* response_state: SPDM_RESPONSE_STATE_NEED_RESYNC*/
+    1590                 :            :         cmocka_unit_test(libspdm_test_responder_psk_finish_case4),
+    1591                 :            :         #if LIBSPDM_RESPOND_IF_READY_SUPPORT
+    1592                 :            :         /* response_state: SPDM_RESPONSE_STATE_NOT_READY*/
+    1593                 :            :         cmocka_unit_test(libspdm_test_responder_psk_finish_case5),
+    1594                 :            :         #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
+    1595                 :            :         /* connection_state Check*/
+    1596                 :            :         cmocka_unit_test(libspdm_test_responder_psk_finish_case6),
+    1597                 :            :         /* Buffer reset*/
+    1598                 :            :         cmocka_unit_test(libspdm_test_responder_psk_finish_case7),
+    1599                 :            :         /* Unsupported PSK capabilities*/
+    1600                 :            :         cmocka_unit_test(libspdm_test_responder_psk_finish_case8),
+    1601                 :            :         /* Uninitialized session*/
+    1602                 :            :         cmocka_unit_test(libspdm_test_responder_psk_finish_case9),
+    1603                 :            :         /* Incorrect MAC*/
+    1604                 :            :         cmocka_unit_test(libspdm_test_responder_psk_finish_case10),
+    1605                 :            :         cmocka_unit_test(libspdm_test_responder_psk_finish_case11),
+    1606                 :            :         /* Incorrect MAC size*/
+    1607                 :            :         cmocka_unit_test(libspdm_test_responder_psk_finish_case12),
+    1608                 :            :         cmocka_unit_test(libspdm_test_responder_psk_finish_case13),
+    1609                 :            :         /* Buffer verification*/
+    1610                 :            :         cmocka_unit_test(libspdm_test_responder_psk_finish_case14),
+    1611                 :            :     };
+    1612                 :            : 
+    1613                 :          1 :     libspdm_setup_test_context(&m_libspdm_responder_psk_finish_test_context);
+    1614                 :            : 
+    1615                 :          1 :     return cmocka_run_group_tests(spdm_responder_psk_finish_tests,
+    1616                 :            :                                   libspdm_unit_test_group_setup,
+    1617                 :            :                                   libspdm_unit_test_group_teardown);
+    1618                 :            : }
+    1619                 :            : 
+    1620                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/receive_send.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_responder/receive_send.c.func-sort-c.html new file mode 100644 index 00000000000..e30bc41fd95 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/receive_send.c.func-sort-c.html @@ -0,0 +1,113 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/receive_send.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - receive_send.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:194194100.0 %
Date:2024-09-22 08:21:07Functions:88100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_receive_send_test_main1
libspdm_test_responder_receive_send_rsp_case11
libspdm_test_responder_receive_send_rsp_case21
libspdm_test_responder_receive_send_rsp_case31
libspdm_test_responder_receive_send_rsp_case41
my_test_get_response_func1
my_test_get_response_func21
my_test_get_vendor_id_func1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/receive_send.c.func.html b/coverage_log/unit_test/test_spdm_responder/receive_send.c.func.html new file mode 100644 index 00000000000..1443b6350c0 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/receive_send.c.func.html @@ -0,0 +1,113 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/receive_send.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - receive_send.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:194194100.0 %
Date:2024-09-22 08:21:07Functions:88100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_receive_send_test_main1
libspdm_test_responder_receive_send_rsp_case11
libspdm_test_responder_receive_send_rsp_case21
libspdm_test_responder_receive_send_rsp_case31
libspdm_test_responder_receive_send_rsp_case41
my_test_get_response_func1
my_test_get_response_func21
my_test_get_vendor_id_func1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/receive_send.c.gcov.html b/coverage_log/unit_test/test_spdm_responder/receive_send.c.gcov.html new file mode 100644 index 00000000000..1bc1fb466c4 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/receive_send.c.gcov.html @@ -0,0 +1,609 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/receive_send.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - receive_send.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:194194100.0 %
Date:2024-09-22 08:21:07Functions:88100.0 %
Branches:00-
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_responder_lib.h"
+       9                 :            : 
+      10                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
+      11                 :            : 
+      12                 :            : #define CHUNK_GET_UNIT_TEST_OVERRIDE_DATA_TRANSFER_SIZE (64)
+      13                 :            : 
+      14                 :            : typedef struct {
+      15                 :            :     spdm_message_header_t header;
+      16                 :            :     /* param1 == RSVD
+      17                 :            :      * param2 == RSVD*/
+      18                 :            :     uint16_t standard_id;
+      19                 :            :     uint8_t len;
+      20                 :            :     /*uint8_t                vendor_id[len];*/
+      21                 :            :     uint16_t payload_length;
+      22                 :            :     /* uint8_t                vendor_defined_payload[payload_length];*/
+      23                 :            : } my_spdm_vendor_defined_request_msg_t;
+      24                 :            : 
+      25                 :          1 : libspdm_return_t my_test_get_vendor_id_func(
+      26                 :            :     void *spdm_context,
+      27                 :            :     uint16_t *resp_standard_id,
+      28                 :            :     uint8_t *resp_vendor_id_len,
+      29                 :            :     void *resp_vendor_id)
+      30                 :            : {
+      31                 :          1 :     *resp_standard_id = 6;
+      32                 :          1 :     *resp_vendor_id_len = 2;
+      33                 :          1 :     ((uint8_t*)resp_vendor_id)[0] = 0xAA;
+      34                 :          1 :     ((uint8_t*)resp_vendor_id)[1] = 0xAA;
+      35                 :            : 
+      36                 :          1 :     return LIBSPDM_STATUS_SUCCESS;
+      37                 :            : }
+      38                 :            : 
+      39                 :          1 : libspdm_return_t my_test_get_response_func(
+      40                 :            :     void *spdm_context, const uint32_t *session_id, bool is_app_message,
+      41                 :            :     size_t request_size, const void *request, size_t *response_size,
+      42                 :            :     void *response)
+      43                 :            : {
+      44                 :            :     /* response message size is greater than the sending transmit buffer size of responder */
+      45                 :          1 :     *response_size = CHUNK_GET_UNIT_TEST_OVERRIDE_DATA_TRANSFER_SIZE + 1;
+      46                 :          1 :     return LIBSPDM_STATUS_SUCCESS;
+      47                 :            : }
+      48                 :            : 
+      49                 :          1 : libspdm_return_t my_test_get_response_func2(
+      50                 :            :     void *spdm_context,
+      51                 :            :     uint16_t req_standard_id,
+      52                 :            :     uint8_t req_vendor_id_len,
+      53                 :            :     const void *req_vendor_id,
+      54                 :            :     uint16_t req_size,
+      55                 :            :     const void *req_data,
+      56                 :            :     uint16_t *resp_size,
+      57                 :            :     void *resp_data)
+      58                 :            : {
+      59                 :            :     /* response message size is greater than the sending transmit buffer size of responder */
+      60                 :          1 :     *resp_size = CHUNK_GET_UNIT_TEST_OVERRIDE_DATA_TRANSFER_SIZE + 1;
+      61                 :          1 :     return LIBSPDM_STATUS_SUCCESS;
+      62                 :            : }
+      63                 :            : 
+      64                 :            : /**
+      65                 :            :  * Test 1: Test Responder Receive Send flow triggers chunk get mode
+      66                 :            :  * if response buffer is larger than requester data_transfer_size.
+      67                 :            :  **/
+      68                 :          1 : void libspdm_test_responder_receive_send_rsp_case1(void** state)
+      69                 :            : {
+      70                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
+      71                 :            :     /* This test case is partially copied from test_requester_get_measurement_case4 */
+      72                 :            :     libspdm_return_t status;
+      73                 :            :     libspdm_test_context_t* spdm_test_context;
+      74                 :            :     libspdm_context_t* spdm_context;
+      75                 :            :     size_t response_size;
+      76                 :            :     uint8_t* response;
+      77                 :            :     spdm_error_response_t* spdm_response;
+      78                 :            :     spdm_get_measurements_request_t spdm_request;
+      79                 :            :     void* message;
+      80                 :            :     size_t message_size;
+      81                 :            :     void* data;
+      82                 :            :     size_t data_size;
+      83                 :            :     void* hash;
+      84                 :            :     size_t hash_size;
+      85                 :            :     uint32_t transport_header_size;
+      86                 :            :     uint8_t chunk_handle;
+      87                 :            : 
+      88                 :          1 :     spdm_test_context = *state;
+      89                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+      90                 :          1 :     spdm_test_context->case_id = 1;
+      91                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+      92                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+      93                 :            : 
+      94                 :          1 :     spdm_context->connection_info.connection_state =
+      95                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+      96                 :            : 
+      97                 :          1 :     spdm_context->local_context.capability.flags |=
+      98                 :            :         (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP
+      99                 :            :          | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP);
+     100                 :          1 :     spdm_context->connection_info.capability.flags |=
+     101                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP;
+     102                 :            : 
+     103                 :          1 :     libspdm_read_responder_public_certificate_chain(
+     104                 :            :         m_libspdm_use_hash_algo,
+     105                 :            :         m_libspdm_use_asym_algo, &data,
+     106                 :            :         &data_size,
+     107                 :            :         &hash, &hash_size);
+     108                 :            : 
+     109                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
+     110                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     111                 :            : 
+     112                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+     113                 :            : 
+     114                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     115                 :            :         m_libspdm_use_measurement_spec;
+     116                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     117                 :            :         m_libspdm_use_measurement_hash_algo;
+     118                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     119                 :            :         m_libspdm_use_hash_algo;
+     120                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     121                 :            :         m_libspdm_use_asym_algo;
+     122                 :            : 
+     123                 :            :     #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     124                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
+     125                 :            :     libspdm_copy_mem(
+     126                 :            :         spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+     127                 :            :         sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+     128                 :            :         data, data_size);
+     129                 :            :     #else
+     130                 :          1 :     libspdm_hash_all(
+     131                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+     132                 :            :         data, data_size,
+     133                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+     134                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+     135                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+     136                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+     137                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+     138                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+     139                 :            :         data, data_size,
+     140                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+     141                 :            :     #endif
+     142                 :            : 
+     143                 :          1 :     spdm_context->connection_info.capability.data_transfer_size =
+     144                 :            :         CHUNK_GET_UNIT_TEST_OVERRIDE_DATA_TRANSFER_SIZE;
+     145                 :            : 
+     146                 :          1 :     spdm_context->connection_info.capability.max_spdm_msg_size =
+     147                 :            :         LIBSPDM_MAX_SPDM_MSG_SIZE;
+     148                 :            : 
+     149                 :          1 :     libspdm_zero_mem(&spdm_request, sizeof(spdm_request));
+     150                 :          1 :     spdm_request.header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     151                 :          1 :     spdm_request.header.request_response_code = SPDM_GET_MEASUREMENTS;
+     152                 :          1 :     spdm_request.header.param1 =
+     153                 :            :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
+     154                 :          1 :     spdm_request.header.param2 =
+     155                 :            :         SPDM_GET_MEASUREMENTS_REQUEST_MEASUREMENT_OPERATION_ALL_MEASUREMENTS;
+     156                 :          1 :     spdm_request.slot_id_param = 0;
+     157                 :            : 
+     158                 :          1 :     libspdm_copy_mem(spdm_context->last_spdm_request,
+     159                 :          1 :                      libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context),
+     160                 :            :                      &spdm_request, sizeof(spdm_request));
+     161                 :          1 :     spdm_context->last_spdm_request_size = sizeof(spdm_request);
+     162                 :            : 
+     163                 :          1 :     assert_int_equal(spdm_context->chunk_context.get.chunk_in_use, false);
+     164                 :          1 :     libspdm_acquire_sender_buffer(spdm_context, &message_size, (void**) &message);
+     165                 :          1 :     response = message;
+     166                 :          1 :     response_size = message_size;
+     167                 :          1 :     libspdm_zero_mem(response, response_size);
+     168                 :            : 
+     169                 :          1 :     status = libspdm_build_response(spdm_context, NULL, false,
+     170                 :            :                                     &response_size, (void**)&response);
+     171                 :            : 
+     172                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     173                 :          1 :     transport_header_size = spdm_context->local_context.capability.transport_header_size;
+     174                 :            : 
+     175                 :            :     /* Verify responder returned error large response with chunk_handle == 1
+     176                 :            :      * and responder is in chunking mode (get.chunk_in_use). */
+     177                 :          1 :     spdm_response = (spdm_error_response_t*) ((uint8_t*)message + transport_header_size);
+     178                 :          1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+     179                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
+     180                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_LARGE_RESPONSE);
+     181                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     182                 :            : 
+     183                 :          1 :     chunk_handle = *(uint8_t*)(spdm_response + 1);
+     184                 :          1 :     assert_int_equal(chunk_handle, spdm_context->chunk_context.get.chunk_handle);
+     185                 :          1 :     assert_int_equal(spdm_context->chunk_context.get.chunk_in_use, true);
+     186                 :          1 :     libspdm_release_sender_buffer(spdm_context);
+     187                 :            : 
+     188                 :          1 :     free(data);
+     189                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+     190                 :            :     #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     191                 :            :     #else
+     192                 :          1 :     libspdm_asym_free(spdm_context->connection_info.algorithm.base_asym_algo,
+     193                 :            :                       spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+     194                 :            :     #endif
+     195                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP */
+     196                 :          1 : }
+     197                 :            : 
+     198                 :            : /**
+     199                 :            :  * Test 2: Test Responder Receive Send flow triggers chunk get mode
+     200                 :            :  * if response message size is larger than responder sending transmit buffer size.
+     201                 :            :  **/
+     202                 :          1 : void libspdm_test_responder_receive_send_rsp_case2(void** state)
+     203                 :            : {
+     204                 :            :     libspdm_return_t status;
+     205                 :            :     libspdm_test_context_t* spdm_test_context;
+     206                 :            :     libspdm_context_t* spdm_context;
+     207                 :            :     size_t response_size;
+     208                 :            :     uint8_t* response;
+     209                 :            :     spdm_error_response_t* spdm_response;
+     210                 :            :     my_spdm_vendor_defined_request_msg_t spdm_request;
+     211                 :            :     void* message;
+     212                 :            :     size_t message_size;
+     213                 :            :     uint32_t transport_header_size;
+     214                 :            :     uint8_t chunk_handle;
+     215                 :            : 
+     216                 :          1 :     spdm_test_context = *state;
+     217                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     218                 :          1 :     spdm_test_context->case_id = 2;
+     219                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     220                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     221                 :            : 
+     222                 :          1 :     spdm_context->connection_info.connection_state =
+     223                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     224                 :            : 
+     225                 :          1 :     spdm_context->local_context.capability.flags |=
+     226                 :            :         (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP
+     227                 :            :          | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP);
+     228                 :          1 :     spdm_context->connection_info.capability.flags |=
+     229                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP;
+     230                 :            : 
+     231                 :            :     /* The local Responder transmit buffer size for sending a single and complete SPDM message */
+     232                 :          1 :     spdm_context->local_context.capability.sender_data_transfer_size =
+     233                 :            :         CHUNK_GET_UNIT_TEST_OVERRIDE_DATA_TRANSFER_SIZE;
+     234                 :            :     /* The peer Requester buffer size for receiving a single and complete SPDM message */
+     235                 :          1 :     spdm_context->connection_info.capability.data_transfer_size =
+     236                 :            :         LIBSPDM_DATA_TRANSFER_SIZE;
+     237                 :            : 
+     238                 :          1 :     spdm_context->connection_info.capability.max_spdm_msg_size =
+     239                 :            :         LIBSPDM_MAX_SPDM_MSG_SIZE;
+     240                 :            : 
+     241                 :          1 :     libspdm_zero_mem(&spdm_request, sizeof(spdm_request));
+     242                 :          1 :     spdm_request.header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     243                 :          1 :     spdm_request.header.request_response_code = SPDM_VENDOR_DEFINED_REQUEST;
+     244                 :            : 
+     245                 :          1 :     libspdm_copy_mem(spdm_context->last_spdm_request,
+     246                 :          1 :                      libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context),
+     247                 :            :                      &spdm_request, sizeof(spdm_request));
+     248                 :          1 :     spdm_context->last_spdm_request_size = sizeof(spdm_request);
+     249                 :            : 
+     250                 :          1 :     assert_int_equal(spdm_context->chunk_context.get.chunk_in_use, false);
+     251                 :          1 :     libspdm_acquire_sender_buffer(spdm_context, &message_size, (void**) &message);
+     252                 :            : 
+     253                 :          1 :     response = message;
+     254                 :          1 :     response_size = message_size;
+     255                 :          1 :     libspdm_zero_mem(response, response_size);
+     256                 :            : 
+     257                 :            :     /* Make response message size greater than the sending transmit buffer size of responder */
+     258                 :          1 :     spdm_context->get_response_func = (void *)my_test_get_response_func;
+     259                 :            : 
+     260                 :          1 :     status = libspdm_build_response(spdm_context, NULL, false,
+     261                 :            :                                     &response_size, (void**)&response);
+     262                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     263                 :          1 :     transport_header_size = spdm_context->local_context.capability.transport_header_size;
+     264                 :            : 
+     265                 :            :     /* Verify responder returned error large response with chunk_handle == 1
+     266                 :            :      * and responder is in chunking mode (get.chunk_in_use). */
+     267                 :          1 :     spdm_response = (spdm_error_response_t*) ((uint8_t*)message + transport_header_size);
+     268                 :          1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+     269                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
+     270                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_LARGE_RESPONSE);
+     271                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     272                 :            : 
+     273                 :          1 :     chunk_handle = *(uint8_t*)(spdm_response + 1);
+     274                 :          1 :     assert_int_equal(chunk_handle, spdm_context->chunk_context.get.chunk_handle);
+     275                 :          1 :     assert_int_equal(spdm_context->chunk_context.get.chunk_in_use, true);
+     276                 :          1 :     libspdm_release_sender_buffer(spdm_context);
+     277                 :          1 : }
+     278                 :            : 
+     279                 :            : /**
+     280                 :            :  * Test 3: Test Responder Receive Send flow triggers chunk get mode
+     281                 :            :  * if response message size is larger than responder sending transmit buffer size.
+     282                 :            :  **/
+     283                 :          1 : void libspdm_test_responder_receive_send_rsp_case3(void** state)
+     284                 :            : {
+     285                 :            :     libspdm_return_t status;
+     286                 :            :     libspdm_test_context_t* spdm_test_context;
+     287                 :            :     libspdm_context_t* spdm_context;
+     288                 :            :     size_t response_size;
+     289                 :            :     uint8_t* response;
+     290                 :            :     spdm_error_response_t* spdm_response;
+     291                 :            :     my_spdm_vendor_defined_request_msg_t spdm_request;
+     292                 :            :     void* message;
+     293                 :            :     size_t message_size;
+     294                 :            :     uint32_t transport_header_size;
+     295                 :            :     uint8_t chunk_handle;
+     296                 :            : 
+     297                 :          1 :     spdm_test_context = *state;
+     298                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     299                 :          1 :     spdm_test_context->case_id = 2;
+     300                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     301                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     302                 :            : 
+     303                 :          1 :     spdm_context->connection_info.connection_state =
+     304                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     305                 :            : 
+     306                 :          1 :     spdm_context->local_context.capability.flags |=
+     307                 :            :         (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP
+     308                 :            :          | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP);
+     309                 :          1 :     spdm_context->connection_info.capability.flags |=
+     310                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP;
+     311                 :            : 
+     312                 :            :     /* The local Responder transmit buffer size for sending a single and complete SPDM message */
+     313                 :          1 :     spdm_context->local_context.capability.sender_data_transfer_size =
+     314                 :            :         CHUNK_GET_UNIT_TEST_OVERRIDE_DATA_TRANSFER_SIZE;
+     315                 :            :     /* The peer Requester buffer size for receiving a single and complete SPDM message */
+     316                 :          1 :     spdm_context->connection_info.capability.data_transfer_size =
+     317                 :            :         LIBSPDM_DATA_TRANSFER_SIZE;
+     318                 :            : 
+     319                 :          1 :     spdm_context->connection_info.capability.max_spdm_msg_size =
+     320                 :            :         LIBSPDM_MAX_SPDM_MSG_SIZE;
+     321                 :            : 
+     322                 :          1 :     libspdm_zero_mem(&spdm_request, sizeof(spdm_request));
+     323                 :          1 :     spdm_request.header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     324                 :          1 :     spdm_request.header.request_response_code = SPDM_VENDOR_DEFINED_REQUEST;
+     325                 :            : 
+     326                 :          1 :     libspdm_copy_mem(spdm_context->last_spdm_request,
+     327                 :          1 :                      libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context),
+     328                 :            :                      &spdm_request, sizeof(spdm_request));
+     329                 :          1 :     spdm_context->last_spdm_request_size = sizeof(spdm_request);
+     330                 :            : 
+     331                 :          1 :     assert_int_equal(spdm_context->chunk_context.get.chunk_in_use, false);
+     332                 :          1 :     libspdm_acquire_sender_buffer(spdm_context, &message_size, (void**) &message);
+     333                 :            : 
+     334                 :          1 :     response = message;
+     335                 :          1 :     response_size = message_size;
+     336                 :          1 :     libspdm_zero_mem(response, response_size);
+     337                 :            : 
+     338                 :            :     /* Make response message size greater than the sending transmit buffer size of responder */
+     339                 :          1 :     libspdm_register_vendor_get_id_callback_func(spdm_context, my_test_get_vendor_id_func);
+     340                 :          1 :     libspdm_register_vendor_callback_func(spdm_context, my_test_get_response_func2);
+     341                 :            : 
+     342                 :          1 :     status = libspdm_build_response(spdm_context, NULL, false,
+     343                 :            :                                     &response_size, (void**)&response);
+     344                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     345                 :          1 :     transport_header_size = spdm_context->local_context.capability.transport_header_size;
+     346                 :            : 
+     347                 :            :     /* Verify responder returned error large response with chunk_handle == 1
+     348                 :            :      * and responder is in chunking mode (get.chunk_in_use). */
+     349                 :          1 :     spdm_response = (spdm_error_response_t*) ((uint8_t*)message + transport_header_size);
+     350                 :          1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+     351                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
+     352                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_LARGE_RESPONSE);
+     353                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     354                 :            : 
+     355                 :          1 :     chunk_handle = *(uint8_t*)(spdm_response + 1);
+     356                 :          1 :     assert_int_equal(chunk_handle, spdm_context->chunk_context.get.chunk_handle);
+     357                 :          1 :     assert_int_equal(spdm_context->chunk_context.get.chunk_in_use, true);
+     358                 :          1 :     libspdm_release_sender_buffer(spdm_context);
+     359                 :          1 : }
+     360                 :            : 
+     361                 :            : /**
+     362                 :            :  * Test 4: Test Responder Receive Send flow triggers chunk get mode
+     363                 :            :  * if response buffer is larger than requester max_spdm_msg_size.
+     364                 :            :  * expect: SPDM_ERROR_CODE_RESPONSE_TOO_LARGE
+     365                 :            :  **/
+     366                 :          1 : void libspdm_test_responder_receive_send_rsp_case4(void** state)
+     367                 :            : {
+     368                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
+     369                 :            :     /* This test case is partially copied from test_requester_get_measurement_case4 */
+     370                 :            :     libspdm_return_t status;
+     371                 :            :     libspdm_test_context_t* spdm_test_context;
+     372                 :            :     libspdm_context_t* spdm_context;
+     373                 :            :     size_t response_size;
+     374                 :            :     uint8_t* response;
+     375                 :            :     spdm_error_response_t* spdm_response;
+     376                 :            :     spdm_get_measurements_request_t spdm_request;
+     377                 :            :     void* message;
+     378                 :            :     size_t message_size;
+     379                 :            :     void* data;
+     380                 :            :     size_t data_size;
+     381                 :            :     void* hash;
+     382                 :            :     size_t hash_size;
+     383                 :            :     uint32_t transport_header_size;
+     384                 :            : 
+     385                 :          1 :     spdm_test_context = *state;
+     386                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     387                 :          1 :     spdm_test_context->case_id = 3;
+     388                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     389                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     390                 :            : 
+     391                 :          1 :     spdm_context->connection_info.connection_state =
+     392                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     393                 :            : 
+     394                 :          1 :     spdm_context->local_context.capability.flags |=
+     395                 :            :         (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP
+     396                 :            :          | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP);
+     397                 :          1 :     spdm_context->connection_info.capability.flags |=
+     398                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP;
+     399                 :            : 
+     400                 :          1 :     libspdm_read_responder_public_certificate_chain(
+     401                 :            :         m_libspdm_use_hash_algo,
+     402                 :            :         m_libspdm_use_asym_algo, &data,
+     403                 :            :         &data_size,
+     404                 :            :         &hash, &hash_size);
+     405                 :            : 
+     406                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
+     407                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     408                 :            : 
+     409                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+     410                 :            : 
+     411                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec =
+     412                 :            :         m_libspdm_use_measurement_spec;
+     413                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     414                 :            :         m_libspdm_use_measurement_hash_algo;
+     415                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     416                 :            :         m_libspdm_use_hash_algo;
+     417                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     418                 :            :         m_libspdm_use_asym_algo;
+     419                 :            : 
+     420                 :            :     #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     421                 :            :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
+     422                 :            :     libspdm_copy_mem(
+     423                 :            :         spdm_context->connection_info.peer_used_cert_chain[0].buffer,
+     424                 :            :         sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
+     425                 :            :         data, data_size);
+     426                 :            :     #else
+     427                 :          1 :     libspdm_hash_all(
+     428                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+     429                 :            :         data, data_size,
+     430                 :          1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
+     431                 :          1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
+     432                 :          1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
+     433                 :          1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
+     434                 :            :         spdm_context->connection_info.algorithm.base_hash_algo,
+     435                 :            :         spdm_context->connection_info.algorithm.base_asym_algo,
+     436                 :            :         data, data_size,
+     437                 :            :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+     438                 :            :     #endif
+     439                 :            : 
+     440                 :          1 :     spdm_context->connection_info.capability.data_transfer_size =
+     441                 :            :         CHUNK_GET_UNIT_TEST_OVERRIDE_DATA_TRANSFER_SIZE;
+     442                 :            : 
+     443                 :            :     /*set requester small max_spdm_msg_size*/
+     444                 :          1 :     spdm_context->connection_info.capability.max_spdm_msg_size = 100;
+     445                 :            : 
+     446                 :          1 :     libspdm_zero_mem(&spdm_request, sizeof(spdm_request));
+     447                 :          1 :     spdm_request.header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     448                 :          1 :     spdm_request.header.request_response_code = SPDM_GET_MEASUREMENTS;
+     449                 :          1 :     spdm_request.header.param1 =
+     450                 :            :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
+     451                 :          1 :     spdm_request.header.param2 =
+     452                 :            :         SPDM_GET_MEASUREMENTS_REQUEST_MEASUREMENT_OPERATION_ALL_MEASUREMENTS;
+     453                 :          1 :     spdm_request.slot_id_param = 0;
+     454                 :            : 
+     455                 :          1 :     libspdm_copy_mem(spdm_context->last_spdm_request,
+     456                 :          1 :                      libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context),
+     457                 :            :                      &spdm_request, sizeof(spdm_request));
+     458                 :          1 :     spdm_context->last_spdm_request_size = sizeof(spdm_request);
+     459                 :            : 
+     460                 :          1 :     assert_int_equal(spdm_context->chunk_context.get.chunk_in_use, false);
+     461                 :          1 :     libspdm_acquire_sender_buffer(spdm_context, &message_size, (void**) &message);
+     462                 :          1 :     response = message;
+     463                 :          1 :     response_size = message_size;
+     464                 :          1 :     libspdm_zero_mem(response, response_size);
+     465                 :            : 
+     466                 :          1 :     status = libspdm_build_response(spdm_context, NULL, false,
+     467                 :            :                                     &response_size, (void**)&response);
+     468                 :            : 
+     469                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     470                 :          1 :     transport_header_size = spdm_context->local_context.capability.transport_header_size;
+     471                 :            : 
+     472                 :            :     /* Verify responder returned SPDM_ERROR_CODE_RESPONSE_TOO_LARGE response with chunk_handle == 0
+     473                 :            :      * and responder is not in chunking mode (get.chunk_in_use). */
+     474                 :          1 :     spdm_response = (spdm_error_response_t*) ((uint8_t*)message + transport_header_size);
+     475                 :          1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
+     476                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
+     477                 :            : 
+     478                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_RESPONSE_TOO_LARGE);
+     479                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     480                 :          1 :     assert_int_equal(0, spdm_context->chunk_context.get.chunk_handle);
+     481                 :          1 :     assert_int_equal(spdm_context->chunk_context.get.chunk_in_use, false);
+     482                 :          1 :     libspdm_release_sender_buffer(spdm_context);
+     483                 :            : 
+     484                 :          1 :     free(data);
+     485                 :          1 :     libspdm_reset_message_m(spdm_context, NULL);
+     486                 :            :     #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     487                 :            :     #else
+     488                 :          1 :     libspdm_asym_free(spdm_context->connection_info.algorithm.base_asym_algo,
+     489                 :            :                       spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
+     490                 :            :     #endif
+     491                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP */
+     492                 :          1 : }
+     493                 :            : 
+     494                 :            : 
+     495                 :            : libspdm_test_context_t m_libspdm_responder_receive_send_test_context = {
+     496                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+     497                 :            :     false,
+     498                 :            : };
+     499                 :            : 
+     500                 :          1 : int libspdm_responder_receive_send_test_main(void)
+     501                 :            : {
+     502                 :          1 :     const struct CMUnitTest spdm_responder_receive_send_tests[] = {
+     503                 :            :         /* response message size is larger than requester data_transfer_size */
+     504                 :            :         cmocka_unit_test(libspdm_test_responder_receive_send_rsp_case1),
+     505                 :            :         /* response message size is larger than responder sending transmit buffer size */
+     506                 :            :         cmocka_unit_test_setup(libspdm_test_responder_receive_send_rsp_case2,
+     507                 :            :                                libspdm_unit_test_group_setup),
+     508                 :            :         /* response message size is larger than responder sending transmit buffer size
+     509                 :            :          * using the new Vendor Defined Message API */
+     510                 :            :         cmocka_unit_test_setup(libspdm_test_responder_receive_send_rsp_case3,
+     511                 :            :                                libspdm_unit_test_group_setup),
+     512                 :            :         /* response message size is larger than requester max_spdm_msg_size */
+     513                 :            :         cmocka_unit_test_setup(libspdm_test_responder_receive_send_rsp_case4,
+     514                 :            :                                libspdm_unit_test_group_setup),
+     515                 :            :     };
+     516                 :            : 
+     517                 :          1 :     libspdm_setup_test_context(&m_libspdm_responder_receive_send_test_context);
+     518                 :            : 
+     519                 :          1 :     return cmocka_run_group_tests(spdm_responder_receive_send_tests,
+     520                 :            :                                   libspdm_unit_test_group_setup,
+     521                 :            :                                   libspdm_unit_test_group_teardown);
+     522                 :            : }
+     523                 :            : 
+     524                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/respond_if_ready.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_responder/respond_if_ready.c.func-sort-c.html new file mode 100644 index 00000000000..c1ac8fe8973 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/respond_if_ready.c.func-sort-c.html @@ -0,0 +1,145 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/respond_if_ready.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - respond_if_ready.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:554554100.0 %
Date:2024-09-22 08:21:07Functions:1616100.0 %
Branches:1250.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_respond_if_ready_test_main1
libspdm_test_responder_respond_if_ready_case11
libspdm_test_responder_respond_if_ready_case101
libspdm_test_responder_respond_if_ready_case111
libspdm_test_responder_respond_if_ready_case121
libspdm_test_responder_respond_if_ready_case131
libspdm_test_responder_respond_if_ready_case141
libspdm_test_responder_respond_if_ready_case21
libspdm_test_responder_respond_if_ready_case31
libspdm_test_responder_respond_if_ready_case41
libspdm_test_responder_respond_if_ready_case51
libspdm_test_responder_respond_if_ready_case61
libspdm_test_responder_respond_if_ready_case71
libspdm_test_responder_respond_if_ready_case81
libspdm_test_responder_respond_if_ready_case91
libspdm_secured_message_set_request_finished_key2
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/respond_if_ready.c.func.html b/coverage_log/unit_test/test_spdm_responder/respond_if_ready.c.func.html new file mode 100644 index 00000000000..bcdf845432d --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/respond_if_ready.c.func.html @@ -0,0 +1,145 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/respond_if_ready.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - respond_if_ready.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:554554100.0 %
Date:2024-09-22 08:21:07Functions:1616100.0 %
Branches:1250.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_respond_if_ready_test_main1
libspdm_secured_message_set_request_finished_key2
libspdm_test_responder_respond_if_ready_case11
libspdm_test_responder_respond_if_ready_case101
libspdm_test_responder_respond_if_ready_case111
libspdm_test_responder_respond_if_ready_case121
libspdm_test_responder_respond_if_ready_case131
libspdm_test_responder_respond_if_ready_case141
libspdm_test_responder_respond_if_ready_case21
libspdm_test_responder_respond_if_ready_case31
libspdm_test_responder_respond_if_ready_case41
libspdm_test_responder_respond_if_ready_case51
libspdm_test_responder_respond_if_ready_case61
libspdm_test_responder_respond_if_ready_case71
libspdm_test_responder_respond_if_ready_case81
libspdm_test_responder_respond_if_ready_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/respond_if_ready.c.gcov.html b/coverage_log/unit_test/test_spdm_responder/respond_if_ready.c.gcov.html new file mode 100644 index 00000000000..2ffd5f728e1 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/respond_if_ready.c.gcov.html @@ -0,0 +1,1496 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/respond_if_ready.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - respond_if_ready.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:554554100.0 %
Date:2024-09-22 08:21:07Functions:1616100.0 %
Branches:1250.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_responder_lib.h"
+       9                 :            : #include "internal/libspdm_requester_lib.h"
+      10                 :            : #include "internal/libspdm_secured_message_lib.h"
+      11                 :            : 
+      12                 :            : #if LIBSPDM_RESPOND_IF_READY_SUPPORT
+      13                 :            : 
+      14                 :            : #if (LIBSPDM_ENABLE_CAPABILITY_CERT_CAP || LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP || \
+      15                 :            :      LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP || LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP || \
+      16                 :            :      LIBSPDM_ENABLE_CAPABILITY_PSK_CAP)
+      17                 :            : 
+      18                 :            : #define LIBSPDM_MY_TEST_TOKEN            0x30
+      19                 :            : #define LIBSPDM_MY_WRONG_TEST_TOKEN      0x2F
+      20                 :            : 
+      21                 :            : static libspdm_th_managed_buffer_t th_curr;
+      22                 :            : 
+      23                 :            : extern size_t libspdm_secret_lib_challenge_opaque_data_size;
+      24                 :            : 
+      25                 :            : spdm_response_if_ready_request_t m_libspdm_respond_if_ready_request1 = {
+      26                 :            :     {
+      27                 :            :         SPDM_MESSAGE_VERSION_11,
+      28                 :            :         SPDM_RESPOND_IF_READY,
+      29                 :            :         SPDM_GET_DIGESTS,
+      30                 :            :         LIBSPDM_MY_TEST_TOKEN
+      31                 :            :     },
+      32                 :            : };
+      33                 :            : size_t m_libspdm_respond_if_ready_request1_size = sizeof(spdm_message_header_t);
+      34                 :            : 
+      35                 :            : spdm_response_if_ready_request_t m_libspdm_respond_if_ready_request2 = {
+      36                 :            :     {
+      37                 :            :         SPDM_MESSAGE_VERSION_11,
+      38                 :            :         SPDM_RESPOND_IF_READY,
+      39                 :            :         SPDM_GET_CERTIFICATE,
+      40                 :            :         LIBSPDM_MY_TEST_TOKEN
+      41                 :            :     },
+      42                 :            : };
+      43                 :            : size_t m_libspdm_respond_if_ready_request2_size = sizeof(spdm_message_header_t);
+      44                 :            : 
+      45                 :            : spdm_response_if_ready_request_t m_libspdm_respond_if_ready_request3 = {
+      46                 :            :     {
+      47                 :            :         SPDM_MESSAGE_VERSION_11,
+      48                 :            :         SPDM_RESPOND_IF_READY,
+      49                 :            :         SPDM_CHALLENGE,
+      50                 :            :         LIBSPDM_MY_TEST_TOKEN
+      51                 :            :     },
+      52                 :            : };
+      53                 :            : size_t m_libspdm_respond_if_ready_request3_size = sizeof(spdm_message_header_t);
+      54                 :            : 
+      55                 :            : spdm_response_if_ready_request_t m_libspdm_respond_if_ready_request4 = {
+      56                 :            :     {
+      57                 :            :         SPDM_MESSAGE_VERSION_11,
+      58                 :            :         SPDM_RESPOND_IF_READY,
+      59                 :            :         SPDM_GET_MEASUREMENTS,
+      60                 :            :         LIBSPDM_MY_TEST_TOKEN
+      61                 :            :     },
+      62                 :            : };
+      63                 :            : size_t m_libspdm_respond_if_ready_request4_size = sizeof(spdm_message_header_t);
+      64                 :            : 
+      65                 :            : spdm_response_if_ready_request_t m_libspdm_respond_if_ready_request5 = {
+      66                 :            :     {
+      67                 :            :         SPDM_MESSAGE_VERSION_11,
+      68                 :            :         SPDM_RESPOND_IF_READY,
+      69                 :            :         SPDM_KEY_EXCHANGE,
+      70                 :            :         LIBSPDM_MY_TEST_TOKEN
+      71                 :            :     },
+      72                 :            : };
+      73                 :            : size_t m_libspdm_respond_if_ready_request5_size = sizeof(spdm_message_header_t);
+      74                 :            : 
+      75                 :            : spdm_response_if_ready_request_t m_libspdm_respond_if_ready_request6 = {
+      76                 :            :     {
+      77                 :            :         SPDM_MESSAGE_VERSION_11,
+      78                 :            :         SPDM_RESPOND_IF_READY,
+      79                 :            :         SPDM_FINISH,
+      80                 :            :         LIBSPDM_MY_TEST_TOKEN
+      81                 :            :     },
+      82                 :            : };
+      83                 :            : size_t m_libspdm_respond_if_ready_request6_size = sizeof(spdm_message_header_t);
+      84                 :            : 
+      85                 :            : spdm_response_if_ready_request_t m_libspdm_respond_if_ready_request7 = {
+      86                 :            :     {
+      87                 :            :         SPDM_MESSAGE_VERSION_11,
+      88                 :            :         SPDM_RESPOND_IF_READY,
+      89                 :            :         SPDM_PSK_EXCHANGE,
+      90                 :            :         LIBSPDM_MY_TEST_TOKEN
+      91                 :            :     },
+      92                 :            : };
+      93                 :            : size_t m_libspdm_respond_if_ready_request7_size = sizeof(spdm_message_header_t);
+      94                 :            : 
+      95                 :            : spdm_response_if_ready_request_t m_libspdm_respond_if_ready_request8 = {
+      96                 :            :     {
+      97                 :            :         SPDM_MESSAGE_VERSION_11,
+      98                 :            :         SPDM_RESPOND_IF_READY,
+      99                 :            :         SPDM_PSK_FINISH,
+     100                 :            :         LIBSPDM_MY_TEST_TOKEN
+     101                 :            :     },
+     102                 :            : };
+     103                 :            : size_t m_libspdm_respond_if_ready_request8_size = sizeof(spdm_message_header_t);
+     104                 :            : 
+     105                 :            : spdm_response_if_ready_request_t m_libspdm_respond_if_ready_request10 = {
+     106                 :            :     {
+     107                 :            :         SPDM_MESSAGE_VERSION_11,
+     108                 :            :         SPDM_RESPOND_IF_READY,
+     109                 :            :         SPDM_GET_DIGESTS,
+     110                 :            :         LIBSPDM_MY_WRONG_TEST_TOKEN /*wrong token*/
+     111                 :            :     },
+     112                 :            : };
+     113                 :            : size_t m_libspdm_respond_if_ready_request10_size = sizeof(spdm_message_header_t);
+     114                 :            : 
+     115                 :            : spdm_response_if_ready_request_t m_libspdm_respond_if_ready_request11 = {
+     116                 :            :     {
+     117                 :            :         SPDM_MESSAGE_VERSION_11,
+     118                 :            :         SPDM_RESPOND_IF_READY,
+     119                 :            :         SPDM_GET_CERTIFICATE, /*wrong original request code*/
+     120                 :            :         LIBSPDM_MY_TEST_TOKEN
+     121                 :            :     },
+     122                 :            : };
+     123                 :            : size_t m_libspdm_respond_if_ready_request11_size = sizeof(spdm_message_header_t);
+     124                 :            : 
+     125                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CERT_CAP
+     126                 :            : spdm_get_digest_request_t m_libspdm_get_digest_request = {
+     127                 :            :     {
+     128                 :            :         SPDM_MESSAGE_VERSION_11,
+     129                 :            :         SPDM_GET_DIGESTS,
+     130                 :            :         0,
+     131                 :            :         0
+     132                 :            :     },
+     133                 :            : };
+     134                 :            : size_t m_libspdm_get_digest_request_size = sizeof(spdm_message_header_t);
+     135                 :            : 
+     136                 :            : spdm_get_certificate_request_t m_libspdm_get_certificate_request = {
+     137                 :            :     {
+     138                 :            :         SPDM_MESSAGE_VERSION_11,
+     139                 :            :         SPDM_GET_CERTIFICATE,
+     140                 :            :         0,
+     141                 :            :         0
+     142                 :            :     },
+     143                 :            :     0,
+     144                 :            :     LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN
+     145                 :            : };
+     146                 :            : size_t m_libspdm_get_certificate_request_size = sizeof(m_libspdm_get_certificate_request);
+     147                 :            : 
+     148                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CERT_CAP*/
+     149                 :            : 
+     150                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP
+     151                 :            : 
+     152                 :            : spdm_challenge_request_t m_libspdm_challenge_request = {
+     153                 :            :     {
+     154                 :            :         SPDM_MESSAGE_VERSION_11,
+     155                 :            :         SPDM_CHALLENGE,
+     156                 :            :         0,
+     157                 :            :         SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH
+     158                 :            :     },
+     159                 :            : };
+     160                 :            : size_t m_libspdm_challenge_request_size = sizeof(m_libspdm_challenge_request);
+     161                 :            : 
+     162                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP*/
+     163                 :            : 
+     164                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
+     165                 :            : spdm_get_measurements_request_t m_libspdm_get_measurements_request = {
+     166                 :            :     {
+     167                 :            :         SPDM_MESSAGE_VERSION_11,
+     168                 :            :         SPDM_GET_MEASUREMENTS,
+     169                 :            :         0,
+     170                 :            :         SPDM_GET_MEASUREMENTS_REQUEST_MEASUREMENT_OPERATION_TOTAL_NUMBER_OF_MEASUREMENTS
+     171                 :            :     },
+     172                 :            : };
+     173                 :            : size_t m_libspdm_get_measurements_request_size = sizeof(spdm_message_header_t);
+     174                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP*/
+     175                 :            : 
+     176                 :            : #pragma pack(1)
+     177                 :            : 
+     178                 :            : typedef struct {
+     179                 :            :     spdm_message_header_t header;
+     180                 :            :     uint16_t req_session_id;
+     181                 :            :     uint8_t session_policy;
+     182                 :            :     uint8_t reserved;
+     183                 :            :     uint8_t random_data[SPDM_RANDOM_DATA_SIZE];
+     184                 :            :     uint8_t exchange_data[LIBSPDM_MAX_DHE_KEY_SIZE];
+     185                 :            :     uint16_t opaque_length;
+     186                 :            :     uint8_t opaque_data[SPDM_MAX_OPAQUE_DATA_SIZE];
+     187                 :            : } libspdm_key_exchange_request_mine_t;
+     188                 :            : 
+     189                 :            : typedef struct {
+     190                 :            :     spdm_message_header_t header;
+     191                 :            :     uint8_t signature[LIBSPDM_MAX_ASYM_KEY_SIZE];
+     192                 :            :     uint8_t verify_data[LIBSPDM_MAX_HASH_SIZE];
+     193                 :            : } libspdm_finish_request_mine_t;
+     194                 :            : 
+     195                 :            : #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
+     196                 :            : typedef struct {
+     197                 :            :     spdm_message_header_t header;
+     198                 :            :     uint16_t req_session_id;
+     199                 :            :     uint16_t psk_hint_length;
+     200                 :            :     uint16_t requester_context_length;
+     201                 :            :     uint16_t opaque_length;
+     202                 :            :     uint8_t psk_hint[LIBSPDM_PSK_MAX_HINT_LENGTH];
+     203                 :            :     uint8_t requester_context[LIBSPDM_PSK_CONTEXT_LENGTH];
+     204                 :            :     uint8_t opaque_data[SPDM_MAX_OPAQUE_DATA_SIZE];
+     205                 :            : } libspdm_psk_exchange_request_mine_t;
+     206                 :            : 
+     207                 :            : typedef struct {
+     208                 :            :     spdm_message_header_t header;
+     209                 :            :     uint8_t verify_data[LIBSPDM_MAX_HASH_SIZE];
+     210                 :            : } libspdm_psk_finish_request_mine_t;
+     211                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP */
+     212                 :            : 
+     213                 :            : #pragma pack()
+     214                 :            : 
+     215                 :            : libspdm_key_exchange_request_mine_t m_libspdm_key_exchange_request = {
+     216                 :            :     {
+     217                 :            :         SPDM_MESSAGE_VERSION_11,
+     218                 :            :         SPDM_KEY_EXCHANGE,
+     219                 :            :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
+     220                 :            :         0
+     221                 :            :     },
+     222                 :            : };
+     223                 :            : size_t m_libspdm_key_exchange_request_size = sizeof(m_libspdm_key_exchange_request);
+     224                 :            : 
+     225                 :            : libspdm_finish_request_mine_t m_libspdm_finish_request = {
+     226                 :            :     {
+     227                 :            :         SPDM_MESSAGE_VERSION_11,
+     228                 :            :         SPDM_FINISH,
+     229                 :            :         0,
+     230                 :            :         0
+     231                 :            :     },
+     232                 :            : };
+     233                 :            : size_t m_libspdm_finish_request_size = sizeof(m_libspdm_finish_request);
+     234                 :            : 
+     235                 :            : #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
+     236                 :            : libspdm_psk_exchange_request_mine_t m_libspdm_psk_exchange_request = {
+     237                 :            :     {
+     238                 :            :         SPDM_MESSAGE_VERSION_11,
+     239                 :            :         SPDM_PSK_EXCHANGE,
+     240                 :            :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
+     241                 :            :         0
+     242                 :            :     },
+     243                 :            : };
+     244                 :            : size_t m_libspdm_psk_exchange_request_size = sizeof(m_libspdm_psk_exchange_request);
+     245                 :            : 
+     246                 :            : libspdm_psk_finish_request_mine_t m_libspdm_psk_finish_request = {
+     247                 :            :     {
+     248                 :            :         SPDM_MESSAGE_VERSION_11,
+     249                 :            :         SPDM_PSK_FINISH,
+     250                 :            :         0,
+     251                 :            :         0
+     252                 :            :     },
+     253                 :            : };
+     254                 :            : size_t m_libspdm_psk_finish_request_size = sizeof(m_libspdm_psk_finish_request);
+     255                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP */
+     256                 :            : 
+     257                 :            : spdm_end_session_request_t m_libspdm_end_session_request = {
+     258                 :            :     {
+     259                 :            :         SPDM_MESSAGE_VERSION_11,
+     260                 :            :         SPDM_END_SESSION,
+     261                 :            :         0,
+     262                 :            :         0
+     263                 :            :     }
+     264                 :            : };
+     265                 :            : size_t m_libspdm_end_session_request_size = sizeof(m_libspdm_end_session_request);
+     266                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CERT_CAP
+     267                 :            : static uint8_t m_libspdm_local_certificate_chain[LIBSPDM_MAX_CERT_CHAIN_SIZE];
+     268                 :            : #endif
+     269                 :          2 : static void libspdm_secured_message_set_request_finished_key(
+     270                 :            :     void *spdm_secured_message_context, const void *key, size_t key_size)
+     271                 :            : {
+     272                 :            :     libspdm_secured_message_context_t *secured_message_context;
+     273                 :            : 
+     274                 :          2 :     secured_message_context = spdm_secured_message_context;
+     275         [ -  + ]:          2 :     LIBSPDM_ASSERT(key_size == secured_message_context->hash_size);
+     276                 :          2 :     libspdm_copy_mem(secured_message_context->handshake_secret.request_finished_key,
+     277                 :            :                      sizeof(secured_message_context->handshake_secret.request_finished_key),
+     278                 :            :                      key, secured_message_context->hash_size);
+     279                 :          2 : }
+     280                 :            : 
+     281                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CERT_CAP
+     282                 :            : /**
+     283                 :            :  * Test 1: receiving a correct RESPOND_IF_READY from the requester, after a
+     284                 :            :  * GET_DIGESTS could not be processed.
+     285                 :            :  * Expected behavior: the responder accepts the request and produces a valid DIGESTS
+     286                 :            :  * response message.
+     287                 :            :  **/
+     288                 :          1 : void libspdm_test_responder_respond_if_ready_case1(void **state) {
+     289                 :            :     libspdm_return_t status;
+     290                 :            :     libspdm_test_context_t    *spdm_test_context;
+     291                 :            :     libspdm_context_t  *spdm_context;
+     292                 :            :     size_t response_size;
+     293                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     294                 :            :     spdm_digest_response_t *spdm_response; /*response to the original request (DIGESTS)*/
+     295                 :            : 
+     296                 :          1 :     spdm_test_context = *state;
+     297                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     298                 :          1 :     spdm_test_context->case_id = 0x1;
+     299                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+     300                 :            : 
+     301                 :            :     /*state for the the original request (GET_DIGESTS)*/
+     302                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     303                 :          1 :     spdm_context->local_context.capability.flags = 0;
+     304                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     305                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     306                 :            : 
+     307                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     308                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     309                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = m_libspdm_local_certificate_chain;
+     310                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+     311                 :            :         sizeof(m_libspdm_local_certificate_chain);
+     312                 :          1 :     libspdm_set_mem (m_libspdm_local_certificate_chain, sizeof(m_libspdm_local_certificate_chain),
+     313                 :            :                      (uint8_t)(0xFF));
+     314                 :            : 
+     315                 :          1 :     spdm_context->last_spdm_request_size = m_libspdm_get_digest_request_size;
+     316                 :          1 :     libspdm_copy_mem(spdm_context->last_spdm_request,
+     317                 :          1 :                      libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context),
+     318                 :            :                      &m_libspdm_get_digest_request, m_libspdm_get_digest_request_size);
+     319                 :            : 
+     320                 :            :     /*RESPOND_IF_READY specific data*/
+     321                 :          1 :     spdm_context->cache_spdm_request_size = spdm_context->last_spdm_request_size;
+     322                 :          1 :     libspdm_copy_mem(spdm_context->cache_spdm_request,
+     323                 :          1 :                      libspdm_get_scratch_buffer_cache_spdm_request_capacity(spdm_context),
+     324                 :          1 :                      spdm_context->last_spdm_request, spdm_context->last_spdm_request_size);
+     325                 :          1 :     spdm_context->error_data.rd_exponent = 1;
+     326                 :          1 :     spdm_context->error_data.rd_tm        = 1;
+     327                 :          1 :     spdm_context->error_data.request_code = SPDM_GET_DIGESTS;
+     328                 :          1 :     spdm_context->error_data.token       = LIBSPDM_MY_TEST_TOKEN;
+     329                 :            : 
+     330                 :            :     /*check DIGESTS response*/
+     331                 :          1 :     response_size = sizeof(response);
+     332                 :          1 :     status = libspdm_get_response_respond_if_ready(spdm_context,
+     333                 :            :                                                    m_libspdm_respond_if_ready_request1_size,
+     334                 :            :                                                    &m_libspdm_respond_if_ready_request1,
+     335                 :            :                                                    &response_size,
+     336                 :            :                                                    response);
+     337                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+     338                 :          1 :     assert_int_equal (response_size,
+     339                 :            :                       sizeof(spdm_digest_response_t) +
+     340                 :            :                       libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo));
+     341                 :          1 :     spdm_response = (void *)response;
+     342                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_DIGESTS);
+     343                 :          1 : }
+     344                 :            : 
+     345                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CERT_CAP*/
+     346                 :            : 
+     347                 :            : /**
+     348                 :            :  * Test 2: receiving a correct RESPOND_IF_READY from the requester, after a
+     349                 :            :  * GET_CERTIFICATE could not be processed.
+     350                 :            :  * Expected behavior: the responder accepts the request and produces a valid CERTIFICATE
+     351                 :            :  * response message.
+     352                 :            :  **/
+     353                 :            : 
+     354                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CERT_CAP
+     355                 :            : 
+     356                 :          1 : void libspdm_test_responder_respond_if_ready_case2(void **state) {
+     357                 :            :     libspdm_return_t status;
+     358                 :            :     libspdm_test_context_t    *spdm_test_context;
+     359                 :            :     libspdm_context_t  *spdm_context;
+     360                 :            :     size_t response_size;
+     361                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     362                 :            :     spdm_certificate_response_t *spdm_response; /*response to the original request (CERTIFICATE)*/
+     363                 :            :     void                 *data;
+     364                 :            :     size_t data_size;
+     365                 :            : 
+     366                 :          1 :     spdm_test_context = *state;
+     367                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     368                 :          1 :     spdm_test_context->case_id = 0x2;
+     369                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+     370                 :            : 
+     371                 :            :     /*state for the the original request (GET_CERTIFICATE)*/
+     372                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_DIGESTS;
+     373                 :          1 :     spdm_context->local_context.capability.flags = 0;
+     374                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     375                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     376                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     377                 :            : 
+     378                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     379                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     380                 :          1 :     libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
+     381                 :            :                                                      m_libspdm_use_asym_algo,
+     382                 :            :                                                      &data, &data_size,
+     383                 :            :                                                      NULL, NULL);
+     384                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     385                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
+     386                 :            : 
+     387                 :          1 :     spdm_context->last_spdm_request_size = m_libspdm_get_certificate_request_size;
+     388                 :          1 :     libspdm_copy_mem(spdm_context->last_spdm_request,
+     389                 :          1 :                      libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context),
+     390                 :            :                      &m_libspdm_get_certificate_request, m_libspdm_get_certificate_request_size);
+     391                 :            : 
+     392                 :            :     /*RESPOND_IF_READY specific data*/
+     393                 :          1 :     spdm_context->cache_spdm_request_size = spdm_context->last_spdm_request_size;
+     394                 :          1 :     libspdm_copy_mem(spdm_context->cache_spdm_request,
+     395                 :          1 :                      libspdm_get_scratch_buffer_cache_spdm_request_capacity(spdm_context),
+     396                 :          1 :                      spdm_context->last_spdm_request, spdm_context->last_spdm_request_size);
+     397                 :          1 :     spdm_context->error_data.rd_exponent = 1;
+     398                 :          1 :     spdm_context->error_data.rd_tm        = 1;
+     399                 :          1 :     spdm_context->error_data.request_code = SPDM_GET_CERTIFICATE;
+     400                 :          1 :     spdm_context->error_data.token       = LIBSPDM_MY_TEST_TOKEN;
+     401                 :            : 
+     402                 :            :     /*check CERTIFICATE response*/
+     403                 :          1 :     response_size = sizeof(response);
+     404                 :          1 :     status = libspdm_get_response_respond_if_ready(spdm_context,
+     405                 :            :                                                    m_libspdm_respond_if_ready_request2_size,
+     406                 :            :                                                    &m_libspdm_respond_if_ready_request2,
+     407                 :            :                                                    &response_size,
+     408                 :            :                                                    response);
+     409                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+     410                 :          1 :     assert_int_equal (response_size,
+     411                 :            :                       sizeof(spdm_certificate_response_t) + LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN);
+     412                 :          1 :     spdm_response = (void *)response;
+     413                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_CERTIFICATE);
+     414                 :          1 :     assert_int_equal (spdm_response->header.param1, 0);
+     415                 :          1 :     assert_int_equal (spdm_response->portion_length, LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN);
+     416                 :          1 :     assert_int_equal (spdm_response->remainder_length,
+     417                 :            :                       data_size - LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN);
+     418                 :          1 :     free(data);
+     419                 :          1 : }
+     420                 :            : 
+     421                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CERT_CAP*/
+     422                 :            : 
+     423                 :            : /**
+     424                 :            :  * Test 3: receiving a correct RESPOND_IF_READY from the requester, after a
+     425                 :            :  * CHALLENGE could not be processed.
+     426                 :            :  * Expected behavior: the responder accepts the request and produces a valid CHALLENGE_AUTH
+     427                 :            :  * response message.
+     428                 :            :  **/
+     429                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP
+     430                 :          1 : void libspdm_test_responder_respond_if_ready_case3(void **state) {
+     431                 :            :     libspdm_return_t status;
+     432                 :            :     libspdm_test_context_t    *spdm_test_context;
+     433                 :            :     libspdm_context_t  *spdm_context;
+     434                 :            :     size_t response_size;
+     435                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     436                 :            :     spdm_challenge_auth_response_t *spdm_response; /*response to the original request (CHALLENGE_AUTH)*/
+     437                 :            :     void                 *data;
+     438                 :            :     size_t data_size;
+     439                 :            : 
+     440                 :          1 :     spdm_test_context = *state;
+     441                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     442                 :          1 :     spdm_test_context->case_id = 0x3;
+     443                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+     444                 :            : 
+     445                 :            :     /*state for the the original request (CHALLENGE)*/
+     446                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     447                 :          1 :     spdm_context->local_context.capability.flags = 0;
+     448                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     449                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
+     450                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     451                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     452                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+     453                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     454                 :            :         m_libspdm_use_measurement_hash_algo;
+     455                 :            : 
+     456                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     457                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     458                 :          1 :     libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
+     459                 :            :                                                      m_libspdm_use_asym_algo,
+     460                 :            :                                                      &data, &data_size,
+     461                 :            :                                                      NULL, NULL);
+     462                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     463                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
+     464                 :            : 
+     465                 :          1 :     libspdm_secret_lib_challenge_opaque_data_size = 0;
+     466                 :            : 
+     467                 :          1 :     spdm_context->last_spdm_request_size = m_libspdm_challenge_request_size;
+     468                 :          1 :     libspdm_copy_mem(spdm_context->last_spdm_request,
+     469                 :          1 :                      libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context),
+     470                 :            :                      &m_libspdm_challenge_request, m_libspdm_challenge_request_size);
+     471                 :            : 
+     472                 :            :     /*RESPOND_IF_READY specific data*/
+     473                 :          1 :     spdm_context->cache_spdm_request_size = spdm_context->last_spdm_request_size;
+     474                 :          1 :     libspdm_copy_mem(spdm_context->cache_spdm_request,
+     475                 :          1 :                      libspdm_get_scratch_buffer_cache_spdm_request_capacity(spdm_context),
+     476                 :          1 :                      spdm_context->last_spdm_request, spdm_context->last_spdm_request_size);
+     477                 :          1 :     spdm_context->error_data.rd_exponent = 1;
+     478                 :          1 :     spdm_context->error_data.rd_tm        = 1;
+     479                 :          1 :     spdm_context->error_data.request_code = SPDM_CHALLENGE;
+     480                 :          1 :     spdm_context->error_data.token       = LIBSPDM_MY_TEST_TOKEN;
+     481                 :            : 
+     482                 :            :     /*check CHALLENGE response*/
+     483                 :          1 :     response_size = sizeof(response);
+     484                 :          1 :     libspdm_get_random_number (SPDM_NONCE_SIZE, m_libspdm_challenge_request.nonce);
+     485                 :          1 :     status = libspdm_get_response_respond_if_ready(spdm_context,
+     486                 :            :                                                    m_libspdm_respond_if_ready_request3_size,
+     487                 :            :                                                    &m_libspdm_respond_if_ready_request3,
+     488                 :            :                                                    &response_size,
+     489                 :            :                                                    response);
+     490                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+     491                 :          1 :     assert_int_equal (response_size, sizeof(spdm_challenge_auth_response_t) + libspdm_get_hash_size (
+     492                 :            :                           m_libspdm_use_hash_algo) + SPDM_NONCE_SIZE + 0 + sizeof(uint16_t) + 0 + libspdm_get_asym_signature_size (
+     493                 :            :                           m_libspdm_use_asym_algo));
+     494                 :          1 :     spdm_response = (void *)response;
+     495                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_CHALLENGE_AUTH);
+     496                 :          1 :     assert_int_equal (spdm_response->header.param1, 0);
+     497                 :          1 :     assert_int_equal (spdm_response->header.param2, 1 << 0);
+     498                 :          1 :     free(data);
+     499                 :          1 : }
+     500                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP*/
+     501                 :            : 
+     502                 :            : /**
+     503                 :            :  * Test 4: receiving a correct RESPOND_IF_READY from the requester, after a
+     504                 :            :  * GET_MEASUREMENTS could not be processed.
+     505                 :            :  * Expected behavior: the responder accepts the request and produces a valid MEASUREMENTS
+     506                 :            :  * response message.
+     507                 :            :  **/
+     508                 :            : 
+     509                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
+     510                 :            : 
+     511                 :            : extern size_t libspdm_secret_lib_meas_opaque_data_size;
+     512                 :            : 
+     513                 :          1 : void libspdm_test_responder_respond_if_ready_case4(void **state) {
+     514                 :            :     libspdm_return_t status;
+     515                 :            :     libspdm_test_context_t    *spdm_test_context;
+     516                 :            :     libspdm_context_t  *spdm_context;
+     517                 :            :     size_t response_size;
+     518                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     519                 :            :     spdm_measurements_response_t *spdm_response; /*response to the original request (MEASUREMENTS)*/
+     520                 :            : 
+     521                 :          1 :     spdm_test_context = *state;
+     522                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     523                 :          1 :     spdm_test_context->case_id = 0x4;
+     524                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+     525                 :            : 
+     526                 :            :     /*state for the the original request (GET_MEASUREMENTS)*/
+     527                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     528                 :          1 :     spdm_context->local_context.capability.flags = 0;
+     529                 :          1 :     spdm_context->local_context.capability.flags |=
+     530                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+     531                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     532                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     533                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+     534                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     535                 :            :         m_libspdm_use_measurement_hash_algo;
+     536                 :            : 
+     537                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     538                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     539                 :          1 :     libspdm_secret_lib_meas_opaque_data_size = 0;
+     540                 :            : 
+     541                 :          1 :     spdm_context->last_spdm_request_size = m_libspdm_get_measurements_request_size;
+     542                 :          1 :     libspdm_copy_mem(spdm_context->last_spdm_request,
+     543                 :          1 :                      libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context),
+     544                 :            :                      &m_libspdm_get_measurements_request, m_libspdm_get_measurements_request_size);
+     545                 :            : 
+     546                 :            :     /*RESPOND_IF_READY specific data*/
+     547                 :          1 :     spdm_context->cache_spdm_request_size = spdm_context->last_spdm_request_size;
+     548                 :          1 :     libspdm_copy_mem(spdm_context->cache_spdm_request,
+     549                 :          1 :                      libspdm_get_scratch_buffer_cache_spdm_request_capacity(spdm_context),
+     550                 :          1 :                      spdm_context->last_spdm_request, spdm_context->last_spdm_request_size);
+     551                 :          1 :     spdm_context->error_data.rd_exponent = 1;
+     552                 :          1 :     spdm_context->error_data.rd_tm        = 1;
+     553                 :          1 :     spdm_context->error_data.request_code = SPDM_GET_MEASUREMENTS;
+     554                 :          1 :     spdm_context->error_data.token       = LIBSPDM_MY_TEST_TOKEN;
+     555                 :            : 
+     556                 :            :     /*check MEASUREMENT response*/
+     557                 :          1 :     response_size = sizeof(response);
+     558                 :          1 :     libspdm_get_random_number (SPDM_NONCE_SIZE, m_libspdm_get_measurements_request.nonce);
+     559                 :          1 :     status = libspdm_get_response_respond_if_ready(spdm_context,
+     560                 :            :                                                    m_libspdm_respond_if_ready_request4_size,
+     561                 :            :                                                    &m_libspdm_respond_if_ready_request4,
+     562                 :            :                                                    &response_size,
+     563                 :            :                                                    response);
+     564                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+     565                 :          1 :     assert_int_equal (response_size,
+     566                 :            :                       sizeof(spdm_measurements_response_t) + sizeof(uint16_t) + SPDM_NONCE_SIZE);
+     567                 :          1 :     spdm_response = (void *)response;
+     568                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_MEASUREMENTS);
+     569                 :          1 :     assert_int_equal (spdm_response->header.param1, LIBSPDM_MEASUREMENT_BLOCK_NUMBER);
+     570                 :          1 : }
+     571                 :            : 
+     572                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP*/
+     573                 :            : 
+     574                 :            : /**
+     575                 :            :  * Test 5: receiving a correct RESPOND_IF_READY from the requester, after a
+     576                 :            :  * KEY_EXCHANGE could not be processed.
+     577                 :            :  * Expected behavior: the responder accepts the request and produces a valid KEY_EXCHANGE_RSP
+     578                 :            :  * response message.
+     579                 :            :  **/
+     580                 :            : #if LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP
+     581                 :            : 
+     582                 :          1 : void libspdm_test_responder_respond_if_ready_case5(void **state) {
+     583                 :            :     libspdm_return_t status;
+     584                 :            :     libspdm_test_context_t    *spdm_test_context;
+     585                 :            :     libspdm_context_t  *spdm_context;
+     586                 :            :     size_t response_size;
+     587                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     588                 :            :     spdm_key_exchange_response_t *spdm_response; /*response to the original request (KEY_EXCHANGE_RSP)*/
+     589                 :            :     void                 *data;
+     590                 :            :     size_t data_size;
+     591                 :            :     uint8_t                *ptr;
+     592                 :            :     size_t dhe_key_size;
+     593                 :            :     void                 *dhe_context;
+     594                 :            :     size_t opaque_key_exchange_req_size;
+     595                 :            : 
+     596                 :          1 :     spdm_test_context = *state;
+     597                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     598                 :          1 :     spdm_test_context->case_id = 0x5;
+     599                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+     600                 :            : 
+     601                 :            :     /*state for the the original request (KEY_EXCHANGE)*/
+     602                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     603                 :          1 :     spdm_context->connection_info.capability.flags |=
+     604                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+     605                 :          1 :     spdm_context->local_context.capability.flags = SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
+     606                 :            :                                                    SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+     607                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     608                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     609                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+     610                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     611                 :            :         m_libspdm_use_measurement_hash_algo;
+     612                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+     613                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+     614                 :            : 
+     615                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     616                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     617                 :          1 :     libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
+     618                 :            :                                                      m_libspdm_use_asym_algo,
+     619                 :            :                                                      &data, &data_size,
+     620                 :            :                                                      NULL, NULL);
+     621                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     622                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
+     623                 :            : 
+     624                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     625                 :            : 
+     626                 :          1 :     m_libspdm_key_exchange_request.req_session_id = 0xFFFF;
+     627                 :          1 :     m_libspdm_key_exchange_request.reserved = 0;
+     628                 :          1 :     ptr = m_libspdm_key_exchange_request.random_data;
+     629                 :          1 :     libspdm_get_random_number (SPDM_RANDOM_DATA_SIZE, ptr);
+     630                 :          1 :     ptr += SPDM_RANDOM_DATA_SIZE;
+     631                 :          1 :     dhe_key_size = libspdm_get_dhe_pub_key_size (m_libspdm_use_dhe_algo);
+     632                 :          1 :     dhe_context = libspdm_dhe_new (spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
+     633                 :            :                                    false);
+     634                 :          1 :     libspdm_dhe_generate_key (m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
+     635                 :          1 :     ptr += dhe_key_size;
+     636                 :          1 :     libspdm_dhe_free (m_libspdm_use_dhe_algo, dhe_context);
+     637                 :          1 :     opaque_key_exchange_req_size =
+     638                 :          1 :         libspdm_get_opaque_data_supported_version_data_size (spdm_context);
+     639                 :          1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
+     640                 :          1 :     ptr += sizeof(uint16_t);
+     641                 :          1 :     libspdm_build_opaque_data_supported_version_data (spdm_context, &opaque_key_exchange_req_size,
+     642                 :            :                                                       ptr);
+     643                 :          1 :     ptr += opaque_key_exchange_req_size;
+     644                 :            : 
+     645                 :          1 :     spdm_context->last_spdm_request_size = m_libspdm_key_exchange_request_size;
+     646                 :          1 :     libspdm_copy_mem(spdm_context->last_spdm_request,
+     647                 :          1 :                      libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context),
+     648                 :            :                      &m_libspdm_key_exchange_request, m_libspdm_key_exchange_request_size);
+     649                 :            : 
+     650                 :            :     /*RESPOND_IF_READY specific data*/
+     651                 :          1 :     spdm_context->cache_spdm_request_size = spdm_context->last_spdm_request_size;
+     652                 :          1 :     libspdm_copy_mem(spdm_context->cache_spdm_request,
+     653                 :          1 :                      libspdm_get_scratch_buffer_cache_spdm_request_capacity(spdm_context),
+     654                 :          1 :                      spdm_context->last_spdm_request, spdm_context->last_spdm_request_size);
+     655                 :          1 :     spdm_context->error_data.rd_exponent = 1;
+     656                 :          1 :     spdm_context->error_data.rd_tm        = 1;
+     657                 :          1 :     spdm_context->error_data.request_code = SPDM_KEY_EXCHANGE;
+     658                 :          1 :     spdm_context->error_data.token       = LIBSPDM_MY_TEST_TOKEN;
+     659                 :            : 
+     660                 :            :     /*check KEY_EXCHANGE_RSP response*/
+     661                 :          1 :     response_size = sizeof(response);
+     662                 :          1 :     status = libspdm_get_response_respond_if_ready(spdm_context,
+     663                 :            :                                                    m_libspdm_respond_if_ready_request5_size,
+     664                 :            :                                                    &m_libspdm_respond_if_ready_request5,
+     665                 :            :                                                    &response_size,
+     666                 :            :                                                    response);
+     667                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+     668                 :          1 :     assert_int_equal (response_size, sizeof(spdm_key_exchange_response_t) + dhe_key_size + 2 + libspdm_get_opaque_data_version_selection_data_size(
+     669                 :            :                           spdm_context) + libspdm_get_asym_signature_size (
+     670                 :            :                           m_libspdm_use_asym_algo) +
+     671                 :            :                       libspdm_get_hash_size (m_libspdm_use_hash_algo));
+     672                 :          1 :     assert_int_equal (libspdm_secured_message_get_session_state (spdm_context->session_info[0].
+     673                 :            :                                                                  secured_message_context),
+     674                 :            :                       LIBSPDM_SESSION_STATE_HANDSHAKING);
+     675                 :          1 :     spdm_response = (void *)response;
+     676                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_KEY_EXCHANGE_RSP);
+     677                 :          1 :     assert_int_equal (spdm_response->rsp_session_id, 0xFFFF);
+     678                 :          1 :     free(data);
+     679                 :          1 :     libspdm_free_session_id (spdm_context, (0xFFFFFFFF));
+     680                 :          1 : }
+     681                 :            : 
+     682                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP*/
+     683                 :            : 
+     684                 :            : /**
+     685                 :            :  * Test 6: receiving a correct RESPOND_IF_READY from the requester, after a
+     686                 :            :  * FINISH could not be processed.
+     687                 :            :  * Expected behavior: the responder accepts the request and produces a valid FINISH_RSP
+     688                 :            :  * response message.
+     689                 :            :  **/
+     690                 :            : #if LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP
+     691                 :            : 
+     692                 :          1 : void libspdm_test_responder_respond_if_ready_case6(void **state) {
+     693                 :            :     libspdm_return_t status;
+     694                 :            :     libspdm_test_context_t    *spdm_test_context;
+     695                 :            :     libspdm_context_t  *spdm_context;
+     696                 :            :     size_t response_size;
+     697                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     698                 :            :     spdm_finish_response_t *spdm_response; /*response to the original request (FINISH_RSP)*/
+     699                 :            :     void                 *data;
+     700                 :            :     size_t data_size;
+     701                 :            :     uint8_t                *ptr;
+     702                 :            :     uint8_t dummy_buffer[LIBSPDM_MAX_HASH_SIZE];
+     703                 :            :     uint8_t                *cert_buffer;
+     704                 :            :     size_t cert_buffer_size;
+     705                 :            :     uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
+     706                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     707                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+     708                 :            :     libspdm_session_info_t    *session_info;
+     709                 :            :     uint32_t session_id;
+     710                 :            :     uint32_t hash_size;
+     711                 :            :     uint32_t hmac_size;
+     712                 :            : 
+     713                 :          1 :     spdm_test_context = *state;
+     714                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     715                 :          1 :     spdm_test_context->case_id = 0x6;
+     716                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+     717                 :            : 
+     718                 :            :     /*state for the the original request (FINISH)*/
+     719                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     720                 :          1 :     spdm_context->local_context.capability.flags = 0;
+     721                 :          1 :     spdm_context->connection_info.capability.flags |=
+     722                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
+     723                 :          1 :     spdm_context->connection_info.capability.flags |=
+     724                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+     725                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+     726                 :          1 :     spdm_context->local_context.capability.flags |=
+     727                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+     728                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     729                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     730                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+     731                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     732                 :            :         m_libspdm_use_measurement_hash_algo;
+     733                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+     734                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+     735                 :            : 
+     736                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     737                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     738                 :          1 :     libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
+     739                 :            :                                                      m_libspdm_use_asym_algo,
+     740                 :            :                                                      &data, &data_size,
+     741                 :            :                                                      NULL, NULL);
+     742                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     743                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
+     744                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data;
+     745                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size = data_size;
+     746                 :            : 
+     747                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     748                 :            : 
+     749                 :          1 :     session_id = 0xFFFFFFFF;
+     750                 :          1 :     spdm_context->latest_session_id = session_id;
+     751                 :          1 :     session_info = &spdm_context->session_info[0];
+     752                 :          1 :     libspdm_session_info_init (spdm_context, session_info, session_id, false);
+     753                 :          1 :     hash_size = libspdm_get_hash_size (m_libspdm_use_hash_algo);
+     754                 :          1 :     libspdm_set_mem (dummy_buffer, hash_size, (uint8_t)(0xFF));
+     755                 :          1 :     libspdm_secured_message_set_request_finished_key (session_info->secured_message_context,
+     756                 :            :                                                       dummy_buffer, hash_size);
+     757                 :          1 :     libspdm_secured_message_set_session_state (session_info->secured_message_context,
+     758                 :            :                                                LIBSPDM_SESSION_STATE_HANDSHAKING);
+     759                 :            : 
+     760                 :          1 :     hash_size = libspdm_get_hash_size (m_libspdm_use_hash_algo);
+     761                 :          1 :     hmac_size = libspdm_get_hash_size (m_libspdm_use_hash_algo);
+     762                 :          1 :     ptr = m_libspdm_finish_request.signature;
+     763                 :          1 :     libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+     764                 :          1 :     cert_buffer = (uint8_t *)data;
+     765                 :          1 :     cert_buffer_size = data_size;
+     766                 :          1 :     libspdm_hash_all (m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size, cert_buffer_hash);
+     767                 :            :     /* Transcript.MessageA size is 0*/
+     768                 :          1 :     libspdm_append_managed_buffer (&th_curr, cert_buffer_hash, hash_size);
+     769                 :            :     /* SessionTranscript.MessageK is 0*/
+     770                 :          1 :     libspdm_append_managed_buffer (&th_curr, (uint8_t *)&m_libspdm_finish_request,
+     771                 :            :                                    sizeof(spdm_finish_request_t));
+     772                 :          1 :     libspdm_set_mem (request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+     773                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+     774                 :            :                      libspdm_get_managed_buffer_size(&th_curr), hash_data);
+     775                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+     776                 :            :                      request_finished_key, hash_size, ptr);
+     777                 :            : 
+     778                 :          1 :     spdm_context->last_spdm_request_size = sizeof(spdm_finish_request_t) + hmac_size;
+     779                 :          1 :     libspdm_copy_mem(spdm_context->last_spdm_request,
+     780                 :          1 :                      libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context),
+     781                 :            :                      &m_libspdm_finish_request, m_libspdm_finish_request_size);
+     782                 :            : 
+     783                 :            :     /*RESPOND_IF_READY specific data*/
+     784                 :          1 :     spdm_context->cache_spdm_request_size = spdm_context->last_spdm_request_size;
+     785                 :          1 :     libspdm_copy_mem(spdm_context->cache_spdm_request,
+     786                 :          1 :                      libspdm_get_scratch_buffer_cache_spdm_request_capacity(spdm_context),
+     787                 :          1 :                      spdm_context->last_spdm_request, spdm_context->last_spdm_request_size);
+     788                 :          1 :     spdm_context->error_data.rd_exponent = 1;
+     789                 :          1 :     spdm_context->error_data.rd_tm        = 1;
+     790                 :          1 :     spdm_context->error_data.request_code = SPDM_FINISH;
+     791                 :          1 :     spdm_context->error_data.token       = LIBSPDM_MY_TEST_TOKEN;
+     792                 :            : 
+     793                 :            :     /*check FINISH_RSP response*/
+     794                 :          1 :     response_size = sizeof(response);
+     795                 :          1 :     status = libspdm_get_response_respond_if_ready(spdm_context,
+     796                 :            :                                                    m_libspdm_respond_if_ready_request6_size,
+     797                 :            :                                                    &m_libspdm_respond_if_ready_request6,
+     798                 :            :                                                    &response_size,
+     799                 :            :                                                    response);
+     800                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+     801                 :          1 :     assert_int_equal (response_size, sizeof(spdm_finish_response_t) + hmac_size);
+     802                 :          1 :     spdm_response = (void *)response;
+     803                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_FINISH_RSP);
+     804                 :          1 :     free(data);
+     805                 :          1 :     libspdm_free_session_id (spdm_context, (0xFFFFFFFF));
+     806                 :          1 : }
+     807                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP*/
+     808                 :            : 
+     809                 :            : /**
+     810                 :            :  * Test 7: receiving a correct RESPOND_IF_READY from the requester, after a
+     811                 :            :  * PSK_EXCHANGE could not be processed.
+     812                 :            :  * Expected behavior: the responder accepts the request and produces a valid PSK_EXCHANGE_RSP
+     813                 :            :  * response message.
+     814                 :            :  **/
+     815                 :            : #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
+     816                 :            : 
+     817                 :          1 : void libspdm_test_responder_respond_if_ready_case7(void **state) {
+     818                 :            :     libspdm_return_t status;
+     819                 :            :     libspdm_test_context_t    *spdm_test_context;
+     820                 :            :     libspdm_context_t  *spdm_context;
+     821                 :            :     size_t response_size;
+     822                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     823                 :            :     spdm_psk_exchange_response_t *spdm_response; /*response to the original request (PSK_EXCHANGE_RSP)*/
+     824                 :            :     void                 *data;
+     825                 :            :     size_t data_size;
+     826                 :            :     uint8_t                *ptr;
+     827                 :            :     size_t opaque_psk_exchange_req_size;
+     828                 :            : 
+     829                 :          1 :     spdm_test_context = *state;
+     830                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     831                 :          1 :     spdm_test_context->case_id = 0x7;
+     832                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+     833                 :            : 
+     834                 :            :     /*state for the the original request (PSK_EXCHANGE)*/
+     835                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     836                 :          1 :     spdm_context->local_context.capability.flags = 0;
+     837                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     838                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     839                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     840                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     841                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+     842                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     843                 :            :         m_libspdm_use_measurement_hash_algo;
+     844                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+     845                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+     846                 :          1 :     spdm_context->connection_info.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
+     847                 :            : 
+     848                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     849                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     850                 :          1 :     libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
+     851                 :            :                                                      m_libspdm_use_asym_algo,
+     852                 :            :                                                      &data, &data_size,
+     853                 :            :                                                      NULL, NULL);
+     854                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     855                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
+     856                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data;
+     857                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size = data_size;
+     858                 :            : 
+     859                 :          1 :     m_libspdm_psk_exchange_request.psk_hint_length =
+     860                 :            :         (uint16_t)sizeof(LIBSPDM_TEST_PSK_HINT_STRING);
+     861                 :          1 :     m_libspdm_psk_exchange_request.requester_context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
+     862                 :          1 :     opaque_psk_exchange_req_size =
+     863                 :          1 :         libspdm_get_opaque_data_supported_version_data_size (spdm_context);
+     864                 :          1 :     m_libspdm_psk_exchange_request.opaque_length = (uint16_t)opaque_psk_exchange_req_size;
+     865                 :          1 :     m_libspdm_psk_exchange_request.req_session_id = 0xFFFF;
+     866                 :          1 :     ptr = m_libspdm_psk_exchange_request.psk_hint;
+     867                 :          1 :     libspdm_copy_mem(ptr, sizeof(m_libspdm_psk_exchange_request.psk_hint),
+     868                 :            :                      LIBSPDM_TEST_PSK_HINT_STRING,
+     869                 :            :                      sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+     870                 :          1 :     ptr += m_libspdm_psk_exchange_request.psk_hint_length;
+     871                 :          1 :     libspdm_get_random_number (LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
+     872                 :          1 :     ptr += m_libspdm_psk_exchange_request.requester_context_length;
+     873                 :          1 :     libspdm_build_opaque_data_supported_version_data (spdm_context, &opaque_psk_exchange_req_size,
+     874                 :            :                                                       ptr);
+     875                 :          1 :     ptr += opaque_psk_exchange_req_size;
+     876                 :            : 
+     877                 :          1 :     spdm_context->last_spdm_request_size = m_libspdm_psk_exchange_request_size;
+     878                 :          1 :     libspdm_copy_mem(spdm_context->last_spdm_request,
+     879                 :          1 :                      libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context),
+     880                 :            :                      &m_libspdm_psk_exchange_request, m_libspdm_psk_exchange_request_size);
+     881                 :            : 
+     882                 :            :     /*RESPOND_IF_READY specific data*/
+     883                 :          1 :     spdm_context->cache_spdm_request_size = spdm_context->last_spdm_request_size;
+     884                 :          1 :     libspdm_copy_mem(spdm_context->cache_spdm_request,
+     885                 :          1 :                      libspdm_get_scratch_buffer_cache_spdm_request_capacity(spdm_context),
+     886                 :          1 :                      spdm_context->last_spdm_request, spdm_context->last_spdm_request_size);
+     887                 :          1 :     spdm_context->error_data.rd_exponent = 1;
+     888                 :          1 :     spdm_context->error_data.rd_tm        = 1;
+     889                 :          1 :     spdm_context->error_data.request_code = SPDM_PSK_EXCHANGE;
+     890                 :          1 :     spdm_context->error_data.token       = LIBSPDM_MY_TEST_TOKEN;
+     891                 :            : 
+     892                 :            :     /*check PSK_EXCHANGE_RSP response*/
+     893                 :          1 :     response_size = sizeof(response);
+     894                 :          1 :     status = libspdm_get_response_respond_if_ready(spdm_context,
+     895                 :            :                                                    m_libspdm_respond_if_ready_request7_size,
+     896                 :            :                                                    &m_libspdm_respond_if_ready_request7,
+     897                 :            :                                                    &response_size,
+     898                 :            :                                                    response);
+     899                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+     900                 :          1 :     assert_int_equal (response_size, sizeof(spdm_psk_exchange_response_t) + LIBSPDM_PSK_CONTEXT_LENGTH + libspdm_get_opaque_data_version_selection_data_size(
+     901                 :            :                           spdm_context) + libspdm_get_hash_size (m_libspdm_use_hash_algo));
+     902                 :          1 :     assert_int_equal (libspdm_secured_message_get_session_state (spdm_context->session_info[0].
+     903                 :            :                                                                  secured_message_context),
+     904                 :            :                       LIBSPDM_SESSION_STATE_HANDSHAKING);
+     905                 :          1 :     spdm_response = (void *)response;
+     906                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_PSK_EXCHANGE_RSP);
+     907                 :          1 :     assert_int_equal (spdm_response->rsp_session_id, 0xFFFF);
+     908                 :          1 :     free(data);
+     909                 :          1 :     libspdm_free_session_id (spdm_context, (0xFFFFFFFF));
+     910                 :          1 : }
+     911                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP*/
+     912                 :            : 
+     913                 :            : /**
+     914                 :            :  * Test 8: receiving a correct RESPOND_IF_READY from the requester, after a
+     915                 :            :  * PSK_FINISH could not be processed.
+     916                 :            :  * Expected behavior: the responder accepts the request and produces a valid PSK_FINISH_RSP
+     917                 :            :  * response message.
+     918                 :            :  **/
+     919                 :            : #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
+     920                 :          1 : void libspdm_test_responder_respond_if_ready_case8(void **state) {
+     921                 :            :     libspdm_return_t status;
+     922                 :            :     libspdm_test_context_t    *spdm_test_context;
+     923                 :            :     libspdm_context_t  *spdm_context;
+     924                 :            :     size_t response_size;
+     925                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     926                 :            :     spdm_psk_finish_response_t *spdm_response; /*response to the original request (FINISH_PSK_RSP)*/
+     927                 :            :     void                 *data;
+     928                 :            :     size_t data_size;
+     929                 :            :     uint8_t                *ptr;
+     930                 :            :     uint8_t dummy_buffer[LIBSPDM_MAX_HASH_SIZE];
+     931                 :            :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
+     932                 :            :     uint8_t request_finished_key[LIBSPDM_MAX_HASH_SIZE];
+     933                 :            :     libspdm_session_info_t    *session_info;
+     934                 :            :     uint32_t session_id;
+     935                 :            :     uint32_t hash_size;
+     936                 :            :     uint32_t hmac_size;
+     937                 :            : 
+     938                 :          1 :     spdm_test_context = *state;
+     939                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     940                 :          1 :     spdm_test_context->case_id = 0x8;
+     941                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+     942                 :            : 
+     943                 :            :     /*state for the the original request (FINISH)*/
+     944                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     945                 :          1 :     spdm_context->local_context.capability.flags = 0;
+     946                 :          1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
+     947                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
+     948                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+     949                 :          1 :     spdm_context->local_context.capability.flags |=
+     950                 :            :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
+     951                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     952                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     953                 :          1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
+     954                 :          1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
+     955                 :            :         m_libspdm_use_measurement_hash_algo;
+     956                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+     957                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+     958                 :            : 
+     959                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
+     960                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     961                 :          1 :     libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
+     962                 :            :                                                      m_libspdm_use_asym_algo,
+     963                 :            :                                                      &data, &data_size,
+     964                 :            :                                                      NULL, NULL);
+     965                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
+     966                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
+     967                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer = data;
+     968                 :          1 :     spdm_context->connection_info.local_used_cert_chain_buffer_size = data_size;
+     969                 :            : 
+     970                 :          1 :     spdm_context->local_context.mut_auth_requested = 0;
+     971                 :            : 
+     972                 :          1 :     session_id = 0xFFFFFFFF;
+     973                 :          1 :     spdm_context->latest_session_id = session_id;
+     974                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+     975                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+     976                 :          1 :     session_info = &spdm_context->session_info[0];
+     977                 :          1 :     libspdm_session_info_init (spdm_context, session_info, session_id, true);
+     978                 :          1 :     libspdm_session_info_set_psk_hint(session_info,
+     979                 :            :                                       LIBSPDM_TEST_PSK_HINT_STRING,
+     980                 :            :                                       sizeof(LIBSPDM_TEST_PSK_HINT_STRING));
+     981                 :          1 :     hash_size = libspdm_get_hash_size (m_libspdm_use_hash_algo);
+     982                 :          1 :     libspdm_set_mem (dummy_buffer, hash_size, (uint8_t)(0xFF));
+     983                 :          1 :     libspdm_secured_message_set_request_finished_key (session_info->secured_message_context,
+     984                 :            :                                                       dummy_buffer, hash_size);
+     985                 :          1 :     libspdm_secured_message_set_session_state (session_info->secured_message_context,
+     986                 :            :                                                LIBSPDM_SESSION_STATE_HANDSHAKING);
+     987                 :            : 
+     988                 :          1 :     hash_size = libspdm_get_hash_size (m_libspdm_use_hash_algo);
+     989                 :          1 :     hmac_size = libspdm_get_hash_size (m_libspdm_use_hash_algo);
+     990                 :          1 :     ptr = m_libspdm_psk_finish_request.verify_data;
+     991                 :          1 :     libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
+     992                 :            :     /* Transcript.MessageA size is 0
+     993                 :            :      * SessionTranscript.MessageK is 0*/
+     994                 :          1 :     libspdm_append_managed_buffer (&th_curr, (uint8_t *)&m_libspdm_psk_finish_request,
+     995                 :            :                                    sizeof(spdm_psk_finish_request_t));
+     996                 :          1 :     libspdm_set_mem (request_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
+     997                 :          1 :     libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
+     998                 :            :                      libspdm_get_managed_buffer_size(&th_curr), hash_data);
+     999                 :          1 :     libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
+    1000                 :            :                      request_finished_key, hash_size, ptr);
+    1001                 :            : 
+    1002                 :          1 :     spdm_context->last_spdm_request_size = sizeof(spdm_psk_finish_request_t) + hmac_size;
+    1003                 :          1 :     libspdm_copy_mem(spdm_context->last_spdm_request,
+    1004                 :          1 :                      libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context),
+    1005                 :            :                      &m_libspdm_psk_finish_request, m_libspdm_psk_finish_request_size);
+    1006                 :            : 
+    1007                 :            :     /*RESPOND_IF_READY specific data*/
+    1008                 :          1 :     spdm_context->cache_spdm_request_size = spdm_context->last_spdm_request_size;
+    1009                 :          1 :     libspdm_copy_mem(spdm_context->cache_spdm_request,
+    1010                 :          1 :                      libspdm_get_scratch_buffer_cache_spdm_request_capacity(spdm_context),
+    1011                 :          1 :                      spdm_context->last_spdm_request, spdm_context->last_spdm_request_size);
+    1012                 :          1 :     spdm_context->error_data.rd_exponent = 1;
+    1013                 :          1 :     spdm_context->error_data.rd_tm        = 1;
+    1014                 :          1 :     spdm_context->error_data.request_code = SPDM_PSK_FINISH;
+    1015                 :          1 :     spdm_context->error_data.token       = LIBSPDM_MY_TEST_TOKEN;
+    1016                 :            : 
+    1017                 :            :     /*check FINISH_PSK_RSP response*/
+    1018                 :          1 :     response_size = sizeof(response);
+    1019                 :          1 :     status = libspdm_get_response_respond_if_ready(spdm_context,
+    1020                 :            :                                                    m_libspdm_respond_if_ready_request8_size,
+    1021                 :            :                                                    &m_libspdm_respond_if_ready_request8,
+    1022                 :            :                                                    &response_size,
+    1023                 :            :                                                    response);
+    1024                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+    1025                 :          1 :     assert_int_equal (response_size, sizeof(spdm_psk_finish_response_t));
+    1026                 :          1 :     spdm_response = (void *)response;
+    1027                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_PSK_FINISH_RSP);
+    1028                 :          1 :     free(data);
+    1029                 :          1 :     libspdm_free_session_id (spdm_context, (0xFFFFFFFF));
+    1030                 :          1 : }
+    1031                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP*/
+    1032                 :            : 
+    1033                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CERT_CAP
+    1034                 :            : 
+    1035                 :            : /**
+    1036                 :            :  * Test 9:
+    1037                 :            :  * Expected behavior:
+    1038                 :            :  **/
+    1039                 :          1 : void libspdm_test_responder_respond_if_ready_case9(void **state) {
+    1040                 :          1 : }
+    1041                 :            : 
+    1042                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CERT_CAP*/
+    1043                 :            : 
+    1044                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CERT_CAP
+    1045                 :            : /**
+    1046                 :            :  * Test 10: receiving a correct RESPOND_IF_READY from the requester, but the responder is in
+    1047                 :            :  * a Busy state.
+    1048                 :            :  * Expected behavior: the responder accepts the request, but produces an ERROR message
+    1049                 :            :  * indicating the Busy state.
+    1050                 :            :  **/
+    1051                 :          1 : void libspdm_test_responder_respond_if_ready_case10(void **state) {
+    1052                 :            :     libspdm_return_t status;
+    1053                 :            :     libspdm_test_context_t    *spdm_test_context;
+    1054                 :            :     libspdm_context_t  *spdm_context;
+    1055                 :            :     size_t response_size;
+    1056                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1057                 :            :     spdm_digest_response_t *spdm_response; /*response to the original request (DIGESTS)*/
+    1058                 :            : 
+    1059                 :          1 :     spdm_test_context = *state;
+    1060                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1061                 :          1 :     spdm_test_context->case_id = 0xA;
+    1062                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_BUSY;
+    1063                 :            : 
+    1064                 :            :     /*state for the the original request (GET_DIGESTS)*/
+    1065                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1066                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+    1067                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1068                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = m_libspdm_local_certificate_chain;
+    1069                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    1070                 :            :         sizeof(m_libspdm_local_certificate_chain);
+    1071                 :          1 :     libspdm_set_mem (m_libspdm_local_certificate_chain, sizeof(m_libspdm_local_certificate_chain),
+    1072                 :            :                      (uint8_t)(0xFF));
+    1073                 :            : 
+    1074                 :          1 :     spdm_context->last_spdm_request_size = m_libspdm_get_digest_request_size;
+    1075                 :          1 :     libspdm_copy_mem(spdm_context->last_spdm_request,
+    1076                 :          1 :                      libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context),
+    1077                 :            :                      &m_libspdm_get_digest_request, m_libspdm_get_digest_request_size);
+    1078                 :            : 
+    1079                 :            :     /*RESPOND_IF_READY specific data*/
+    1080                 :          1 :     spdm_context->cache_spdm_request_size = spdm_context->last_spdm_request_size;
+    1081                 :          1 :     libspdm_copy_mem(spdm_context->cache_spdm_request,
+    1082                 :          1 :                      libspdm_get_scratch_buffer_cache_spdm_request_capacity(spdm_context),
+    1083                 :          1 :                      spdm_context->last_spdm_request, spdm_context->last_spdm_request_size);
+    1084                 :          1 :     spdm_context->error_data.rd_exponent = 1;
+    1085                 :          1 :     spdm_context->error_data.rd_tm        = 1;
+    1086                 :          1 :     spdm_context->error_data.request_code = SPDM_GET_DIGESTS;
+    1087                 :          1 :     spdm_context->error_data.token       = LIBSPDM_MY_TEST_TOKEN;
+    1088                 :            : 
+    1089                 :            :     /*check ERROR response*/
+    1090                 :          1 :     response_size = sizeof(response);
+    1091                 :          1 :     status = libspdm_get_response_respond_if_ready(spdm_context,
+    1092                 :            :                                                    m_libspdm_respond_if_ready_request1_size,
+    1093                 :            :                                                    &m_libspdm_respond_if_ready_request1,
+    1094                 :            :                                                    &response_size,
+    1095                 :            :                                                    response);
+    1096                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+    1097                 :          1 :     assert_int_equal (response_size, sizeof(spdm_error_response_t));
+    1098                 :          1 :     spdm_response = (void *)response;
+    1099                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_ERROR);
+    1100                 :          1 :     assert_int_equal (spdm_response->header.param1, SPDM_ERROR_CODE_BUSY);
+    1101                 :          1 :     assert_int_equal (spdm_response->header.param2, 0);
+    1102                 :          1 :     assert_int_equal (spdm_context->response_state, LIBSPDM_RESPONSE_STATE_BUSY);
+    1103                 :          1 : }
+    1104                 :            : 
+    1105                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CERT_CAP*/
+    1106                 :            : 
+    1107                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CERT_CAP
+    1108                 :            : /**
+    1109                 :            :  * Test 11: receiving a correct RESPOND_IF_READY from the requester, but the responder requires
+    1110                 :            :  * resynchronization with the requester.
+    1111                 :            :  * Expected behavior: the responder accepts the request, but produces an ERROR message
+    1112                 :            :  * indicating the NeedResynch state.
+    1113                 :            :  **/
+    1114                 :          1 : void libspdm_test_responder_respond_if_ready_case11(void **state) {
+    1115                 :            :     libspdm_return_t status;
+    1116                 :            :     libspdm_test_context_t    *spdm_test_context;
+    1117                 :            :     libspdm_context_t  *spdm_context;
+    1118                 :            :     size_t response_size;
+    1119                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1120                 :            :     spdm_digest_response_t *spdm_response; /*response to the original request (DIGESTS)*/
+    1121                 :            : 
+    1122                 :          1 :     spdm_test_context = *state;
+    1123                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1124                 :          1 :     spdm_test_context->case_id = 0xB;
+    1125                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NEED_RESYNC;
+    1126                 :            : 
+    1127                 :            :     /*state for the the original request (GET_DIGESTS)*/
+    1128                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1129                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+    1130                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1131                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = m_libspdm_local_certificate_chain;
+    1132                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    1133                 :            :         sizeof(m_libspdm_local_certificate_chain);
+    1134                 :          1 :     libspdm_set_mem (m_libspdm_local_certificate_chain, sizeof(m_libspdm_local_certificate_chain),
+    1135                 :            :                      (uint8_t)(0xFF));
+    1136                 :            : 
+    1137                 :          1 :     spdm_context->last_spdm_request_size = m_libspdm_get_digest_request_size;
+    1138                 :          1 :     libspdm_copy_mem(spdm_context->last_spdm_request,
+    1139                 :          1 :                      libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context),
+    1140                 :            :                      &m_libspdm_get_digest_request, m_libspdm_get_digest_request_size);
+    1141                 :            : 
+    1142                 :            :     /*RESPOND_IF_READY specific data*/
+    1143                 :          1 :     spdm_context->cache_spdm_request_size = spdm_context->last_spdm_request_size;
+    1144                 :          1 :     libspdm_copy_mem(spdm_context->cache_spdm_request,
+    1145                 :          1 :                      libspdm_get_scratch_buffer_cache_spdm_request_capacity(spdm_context),
+    1146                 :          1 :                      spdm_context->last_spdm_request, spdm_context->last_spdm_request_size);
+    1147                 :          1 :     spdm_context->error_data.rd_exponent = 1;
+    1148                 :          1 :     spdm_context->error_data.rd_tm        = 1;
+    1149                 :          1 :     spdm_context->error_data.request_code = SPDM_GET_DIGESTS;
+    1150                 :          1 :     spdm_context->error_data.token       = LIBSPDM_MY_TEST_TOKEN;
+    1151                 :            : 
+    1152                 :            :     /*check ERROR response*/
+    1153                 :          1 :     response_size = sizeof(response);
+    1154                 :          1 :     status = libspdm_get_response_respond_if_ready(spdm_context,
+    1155                 :            :                                                    m_libspdm_respond_if_ready_request1_size,
+    1156                 :            :                                                    &m_libspdm_respond_if_ready_request1,
+    1157                 :            :                                                    &response_size,
+    1158                 :            :                                                    response);
+    1159                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+    1160                 :          1 :     assert_int_equal (response_size, sizeof(spdm_error_response_t));
+    1161                 :          1 :     spdm_response = (void *)response;
+    1162                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_ERROR);
+    1163                 :          1 :     assert_int_equal (spdm_response->header.param1, SPDM_ERROR_CODE_REQUEST_RESYNCH);
+    1164                 :          1 :     assert_int_equal (spdm_response->header.param2, 0);
+    1165                 :          1 :     assert_int_equal (spdm_context->response_state, LIBSPDM_RESPONSE_STATE_NEED_RESYNC);
+    1166                 :          1 : }
+    1167                 :            : 
+    1168                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CERT_CAP*/
+    1169                 :            : 
+    1170                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CERT_CAP
+    1171                 :            : 
+    1172                 :            : /**
+    1173                 :            :  * Test 12: receiving a correct RESPOND_IF_READY from the requester, but the responder could not
+    1174                 :            :  * produce the response in time.
+    1175                 :            :  * Expected behavior: the responder accepts the request, but produces an ERROR message
+    1176                 :            :  * indicating the ResponseNotReady state, with the same token as the request.
+    1177                 :            :  **/
+    1178                 :          1 : void libspdm_test_responder_respond_if_ready_case12(void **state) {
+    1179                 :            :     libspdm_return_t status;
+    1180                 :            :     libspdm_test_context_t    *spdm_test_context;
+    1181                 :            :     libspdm_context_t  *spdm_context;
+    1182                 :            :     size_t response_size;
+    1183                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1184                 :            :     spdm_digest_response_t *spdm_response; /*response to the original request (DIGESTS)*/
+    1185                 :            :     spdm_error_data_response_not_ready_t *error_data;
+    1186                 :            : 
+    1187                 :          1 :     spdm_test_context = *state;
+    1188                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1189                 :          1 :     spdm_test_context->case_id = 0xC;
+    1190                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NOT_READY;
+    1191                 :            : 
+    1192                 :            :     /*state for the the original request (GET_DIGESTS)*/
+    1193                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1194                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+    1195                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1196                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = m_libspdm_local_certificate_chain;
+    1197                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    1198                 :            :         sizeof(m_libspdm_local_certificate_chain);
+    1199                 :          1 :     libspdm_set_mem (m_libspdm_local_certificate_chain, sizeof(m_libspdm_local_certificate_chain),
+    1200                 :            :                      (uint8_t)(0xFF));
+    1201                 :            : 
+    1202                 :          1 :     spdm_context->last_spdm_request_size = m_libspdm_get_digest_request_size;
+    1203                 :          1 :     libspdm_copy_mem(spdm_context->last_spdm_request,
+    1204                 :          1 :                      libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context),
+    1205                 :            :                      &m_libspdm_get_digest_request, m_libspdm_get_digest_request_size);
+    1206                 :            : 
+    1207                 :            :     /*RESPOND_IF_READY specific data*/
+    1208                 :          1 :     spdm_context->cache_spdm_request_size = spdm_context->last_spdm_request_size;
+    1209                 :          1 :     libspdm_copy_mem(spdm_context->cache_spdm_request,
+    1210                 :          1 :                      libspdm_get_scratch_buffer_cache_spdm_request_capacity(spdm_context),
+    1211                 :          1 :                      spdm_context->last_spdm_request, spdm_context->last_spdm_request_size);
+    1212                 :          1 :     spdm_context->error_data.rd_exponent = 1;
+    1213                 :          1 :     spdm_context->error_data.rd_tm        = 1;
+    1214                 :          1 :     spdm_context->error_data.request_code = SPDM_GET_DIGESTS;
+    1215                 :          1 :     spdm_context->error_data.token       = LIBSPDM_MY_TEST_TOKEN;
+    1216                 :            : 
+    1217                 :            :     /*check ERROR response*/
+    1218                 :          1 :     response_size = sizeof(response);
+    1219                 :          1 :     status = libspdm_get_response_respond_if_ready(spdm_context,
+    1220                 :            :                                                    m_libspdm_respond_if_ready_request1_size,
+    1221                 :            :                                                    &m_libspdm_respond_if_ready_request1,
+    1222                 :            :                                                    &response_size,
+    1223                 :            :                                                    response);
+    1224                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+    1225                 :          1 :     assert_int_equal (response_size,
+    1226                 :            :                       sizeof(spdm_error_response_t) + sizeof(spdm_error_data_response_not_ready_t));
+    1227                 :          1 :     spdm_response = (void *)response;
+    1228                 :          1 :     error_data = (spdm_error_data_response_not_ready_t*)(spdm_response + 1);
+    1229                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_ERROR);
+    1230                 :          1 :     assert_int_equal (spdm_response->header.param1, SPDM_ERROR_CODE_RESPONSE_NOT_READY);
+    1231                 :          1 :     assert_int_equal (spdm_response->header.param2, 0);
+    1232                 :          1 :     assert_int_equal (spdm_context->response_state, LIBSPDM_RESPONSE_STATE_NOT_READY);
+    1233                 :          1 :     assert_int_equal (error_data->request_code, SPDM_GET_DIGESTS);
+    1234                 :          1 :     assert_int_equal (error_data->token, LIBSPDM_MY_TEST_TOKEN);
+    1235                 :          1 : }
+    1236                 :            : 
+    1237                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CERT_CAP*/
+    1238                 :            : 
+    1239                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CERT_CAP
+    1240                 :            : 
+    1241                 :            : /**
+    1242                 :            :  * Test 13: receiving a correct RESPOND_IF_READY from the requester, with the correct original
+    1243                 :            :  * request code, but with a token different from the expected.
+    1244                 :            :  * Expected behavior: the responder refuses the RESPOND_IF_READY message and produces an
+    1245                 :            :  * ERROR message indicating the InvalidRequest.
+    1246                 :            :  **/
+    1247                 :          1 : void libspdm_test_responder_respond_if_ready_case13(void **state) {
+    1248                 :            :     libspdm_return_t status;
+    1249                 :            :     libspdm_test_context_t    *spdm_test_context;
+    1250                 :            :     libspdm_context_t  *spdm_context;
+    1251                 :            :     size_t response_size;
+    1252                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1253                 :            :     spdm_digest_response_t *spdm_response; /*response to the original request (DIGESTS)*/
+    1254                 :            : 
+    1255                 :          1 :     spdm_test_context = *state;
+    1256                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1257                 :          1 :     spdm_test_context->case_id = 0xD;
+    1258                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+    1259                 :            : 
+    1260                 :            :     /*state for the the original request (GET_DIGESTS)*/
+    1261                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1262                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+    1263                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1264                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = m_libspdm_local_certificate_chain;
+    1265                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    1266                 :            :         sizeof(m_libspdm_local_certificate_chain);
+    1267                 :          1 :     libspdm_set_mem (m_libspdm_local_certificate_chain, sizeof(m_libspdm_local_certificate_chain),
+    1268                 :            :                      (uint8_t)(0xFF));
+    1269                 :            : 
+    1270                 :          1 :     spdm_context->last_spdm_request_size = m_libspdm_get_digest_request_size;
+    1271                 :          1 :     libspdm_copy_mem(spdm_context->last_spdm_request,
+    1272                 :          1 :                      libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context),
+    1273                 :            :                      &m_libspdm_get_digest_request, m_libspdm_get_digest_request_size);
+    1274                 :            : 
+    1275                 :            :     /*RESPOND_IF_READY specific data*/
+    1276                 :          1 :     spdm_context->cache_spdm_request_size = spdm_context->last_spdm_request_size;
+    1277                 :          1 :     libspdm_copy_mem(spdm_context->cache_spdm_request,
+    1278                 :          1 :                      libspdm_get_scratch_buffer_cache_spdm_request_capacity(spdm_context),
+    1279                 :          1 :                      spdm_context->last_spdm_request, spdm_context->last_spdm_request_size);
+    1280                 :          1 :     spdm_context->error_data.rd_exponent = 1;
+    1281                 :          1 :     spdm_context->error_data.rd_tm        = 1;
+    1282                 :          1 :     spdm_context->error_data.request_code = SPDM_GET_DIGESTS;
+    1283                 :          1 :     spdm_context->error_data.token       = LIBSPDM_MY_TEST_TOKEN;
+    1284                 :            : 
+    1285                 :            :     /*check ERROR response*/
+    1286                 :          1 :     response_size = sizeof(response);
+    1287                 :          1 :     status = libspdm_get_response_respond_if_ready(spdm_context,
+    1288                 :            :                                                    m_libspdm_respond_if_ready_request10_size,
+    1289                 :            :                                                    &m_libspdm_respond_if_ready_request10,
+    1290                 :            :                                                    &response_size,
+    1291                 :            :                                                    response);
+    1292                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+    1293                 :          1 :     assert_int_equal (response_size, sizeof(spdm_error_response_t));
+    1294                 :          1 :     spdm_response = (void *)response;
+    1295                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_ERROR);
+    1296                 :          1 :     assert_int_equal (spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+    1297                 :          1 :     assert_int_equal (spdm_response->header.param2, 0);
+    1298                 :          1 : }
+    1299                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CERT_CAP*/
+    1300                 :            : 
+    1301                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CERT_CAP
+    1302                 :            : /**
+    1303                 :            :  * Test 14: receiving a correct RESPOND_IF_READY from the requester, with the correct token,
+    1304                 :            :  * but with a request code different from the expected.
+    1305                 :            :  * Expected behavior: the responder refuses the RESPOND_IF_READY message and produces an
+    1306                 :            :  * ERROR message indicating the InvalidRequest.
+    1307                 :            :  **/
+    1308                 :          1 : void libspdm_test_responder_respond_if_ready_case14(void **state) {
+    1309                 :            :     libspdm_return_t status;
+    1310                 :            :     libspdm_test_context_t    *spdm_test_context;
+    1311                 :            :     libspdm_context_t  *spdm_context;
+    1312                 :            :     size_t response_size;
+    1313                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+    1314                 :            :     spdm_digest_response_t *spdm_response; /*response to the original request (DIGESTS)*/
+    1315                 :            : 
+    1316                 :          1 :     spdm_test_context = *state;
+    1317                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+    1318                 :          1 :     spdm_test_context->case_id = 0xE;
+    1319                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+    1320                 :            : 
+    1321                 :            :     /*state for the the original request (GET_DIGESTS)*/
+    1322                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+    1323                 :          1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
+    1324                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1325                 :          1 :     spdm_context->local_context.local_cert_chain_provision[0] = m_libspdm_local_certificate_chain;
+    1326                 :          1 :     spdm_context->local_context.local_cert_chain_provision_size[0] =
+    1327                 :            :         sizeof(m_libspdm_local_certificate_chain);
+    1328                 :          1 :     libspdm_set_mem (m_libspdm_local_certificate_chain, sizeof(m_libspdm_local_certificate_chain),
+    1329                 :            :                      (uint8_t)(0xFF));
+    1330                 :            : 
+    1331                 :          1 :     spdm_context->last_spdm_request_size = m_libspdm_get_digest_request_size;
+    1332                 :          1 :     libspdm_copy_mem(spdm_context->last_spdm_request,
+    1333                 :          1 :                      libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context),
+    1334                 :            :                      &m_libspdm_get_digest_request, m_libspdm_get_digest_request_size);
+    1335                 :            : 
+    1336                 :            :     /*RESPOND_IF_READY specific data*/
+    1337                 :          1 :     spdm_context->cache_spdm_request_size = spdm_context->last_spdm_request_size;
+    1338                 :          1 :     libspdm_copy_mem(spdm_context->cache_spdm_request,
+    1339                 :          1 :                      libspdm_get_scratch_buffer_cache_spdm_request_capacity(spdm_context),
+    1340                 :          1 :                      spdm_context->last_spdm_request, spdm_context->last_spdm_request_size);
+    1341                 :          1 :     spdm_context->error_data.rd_exponent = 1;
+    1342                 :          1 :     spdm_context->error_data.rd_tm        = 1;
+    1343                 :          1 :     spdm_context->error_data.request_code = SPDM_GET_DIGESTS;
+    1344                 :          1 :     spdm_context->error_data.token       = LIBSPDM_MY_TEST_TOKEN;
+    1345                 :            : 
+    1346                 :            :     /*check ERROR response*/
+    1347                 :          1 :     response_size = sizeof(response);
+    1348                 :          1 :     status = libspdm_get_response_respond_if_ready(spdm_context,
+    1349                 :            :                                                    m_libspdm_respond_if_ready_request11_size,
+    1350                 :            :                                                    &m_libspdm_respond_if_ready_request11,
+    1351                 :            :                                                    &response_size,
+    1352                 :            :                                                    response);
+    1353                 :          1 :     assert_int_equal (status, LIBSPDM_STATUS_SUCCESS);
+    1354                 :          1 :     assert_int_equal (response_size, sizeof(spdm_error_response_t));
+    1355                 :          1 :     spdm_response = (void *)response;
+    1356                 :          1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_ERROR);
+    1357                 :          1 :     assert_int_equal (spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+    1358                 :          1 :     assert_int_equal (spdm_response->header.param2, 0);
+    1359                 :          1 : }
+    1360                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CERT_CAP*/
+    1361                 :            : 
+    1362                 :            : libspdm_test_context_t m_libspdm_responder_respond_if_ready_test_context = {
+    1363                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+    1364                 :            :     false,
+    1365                 :            : };
+    1366                 :            : 
+    1367                 :          1 : int libspdm_responder_respond_if_ready_test_main(void) {
+    1368                 :          1 :     const struct CMUnitTest spdm_responder_respond_if_ready_tests[] = {
+    1369                 :            :         /* Success Case*/
+    1370                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_CERT_CAP
+    1371                 :            :         cmocka_unit_test(libspdm_test_responder_respond_if_ready_case1),
+    1372                 :            :         cmocka_unit_test(libspdm_test_responder_respond_if_ready_case2),
+    1373                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_CERT_CAP*/
+    1374                 :            : 
+    1375                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP
+    1376                 :            :         cmocka_unit_test(libspdm_test_responder_respond_if_ready_case3),
+    1377                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP*/
+    1378                 :            : 
+    1379                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
+    1380                 :            :         cmocka_unit_test(libspdm_test_responder_respond_if_ready_case4),
+    1381                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP*/
+    1382                 :            : 
+    1383                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP
+    1384                 :            :         cmocka_unit_test(libspdm_test_responder_respond_if_ready_case5),
+    1385                 :            :         cmocka_unit_test(libspdm_test_responder_respond_if_ready_case6),
+    1386                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP*/
+    1387                 :            : 
+    1388                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
+    1389                 :            :         cmocka_unit_test(libspdm_test_responder_respond_if_ready_case7),
+    1390                 :            :         cmocka_unit_test(libspdm_test_responder_respond_if_ready_case8),
+    1391                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP*/
+    1392                 :            : 
+    1393                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_CERT_CAP
+    1394                 :            :         cmocka_unit_test(libspdm_test_responder_respond_if_ready_case9),
+    1395                 :            :         cmocka_unit_test(libspdm_test_responder_respond_if_ready_case10),
+    1396                 :            :         cmocka_unit_test(libspdm_test_responder_respond_if_ready_case11),
+    1397                 :            :         cmocka_unit_test(libspdm_test_responder_respond_if_ready_case12),
+    1398                 :            :         cmocka_unit_test(libspdm_test_responder_respond_if_ready_case13),
+    1399                 :            :         cmocka_unit_test(libspdm_test_responder_respond_if_ready_case14),
+    1400                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_CERT_CAP*/
+    1401                 :            : 
+    1402                 :            :     };
+    1403                 :            : 
+    1404                 :          1 :     libspdm_setup_test_context (&m_libspdm_responder_respond_if_ready_test_context);
+    1405                 :            : 
+    1406                 :          1 :     return cmocka_run_group_tests(spdm_responder_respond_if_ready_tests,
+    1407                 :            :                                   libspdm_unit_test_group_setup,
+    1408                 :            :                                   libspdm_unit_test_group_teardown);
+    1409                 :            : }
+    1410                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_*_CAP */
+    1411                 :            : #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/set_certificate_rsp.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_responder/set_certificate_rsp.c.func-sort-c.html new file mode 100644 index 00000000000..56e1a1ed3ca --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/set_certificate_rsp.c.func-sort-c.html @@ -0,0 +1,133 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/set_certificate_rsp.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - set_certificate_rsp.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:42342699.3 %
Date:2024-09-22 08:21:07Functions:1313100.0 %
Branches:2450.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_set_certificate_rsp_test_main1
libspdm_test_responder_set_certificate_rsp_case121
libspdm_test_responder_set_cetificate_rsp_case11
libspdm_test_responder_set_cetificate_rsp_case101
libspdm_test_responder_set_cetificate_rsp_case111
libspdm_test_responder_set_cetificate_rsp_case21
libspdm_test_responder_set_cetificate_rsp_case31
libspdm_test_responder_set_cetificate_rsp_case41
libspdm_test_responder_set_cetificate_rsp_case51
libspdm_test_responder_set_cetificate_rsp_case61
libspdm_test_responder_set_cetificate_rsp_case71
libspdm_test_responder_set_cetificate_rsp_case81
libspdm_test_responder_set_cetificate_rsp_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/set_certificate_rsp.c.func.html b/coverage_log/unit_test/test_spdm_responder/set_certificate_rsp.c.func.html new file mode 100644 index 00000000000..e268f4c0953 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/set_certificate_rsp.c.func.html @@ -0,0 +1,133 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/set_certificate_rsp.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - set_certificate_rsp.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:42342699.3 %
Date:2024-09-22 08:21:07Functions:1313100.0 %
Branches:2450.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_set_certificate_rsp_test_main1
libspdm_test_responder_set_certificate_rsp_case121
libspdm_test_responder_set_cetificate_rsp_case11
libspdm_test_responder_set_cetificate_rsp_case101
libspdm_test_responder_set_cetificate_rsp_case111
libspdm_test_responder_set_cetificate_rsp_case21
libspdm_test_responder_set_cetificate_rsp_case31
libspdm_test_responder_set_cetificate_rsp_case41
libspdm_test_responder_set_cetificate_rsp_case51
libspdm_test_responder_set_cetificate_rsp_case61
libspdm_test_responder_set_cetificate_rsp_case71
libspdm_test_responder_set_cetificate_rsp_case81
libspdm_test_responder_set_cetificate_rsp_case91
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/set_certificate_rsp.c.gcov.html b/coverage_log/unit_test/test_spdm_responder/set_certificate_rsp.c.gcov.html new file mode 100644 index 00000000000..b65fa8fd758 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/set_certificate_rsp.c.gcov.html @@ -0,0 +1,1167 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/set_certificate_rsp.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - set_certificate_rsp.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:42342699.3 %
Date:2024-09-22 08:21:07Functions:1313100.0 %
Branches:2450.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2024 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_responder_lib.h"
+       9                 :            : 
+      10                 :            : #if defined(_WIN32) || (defined(__clang__) && (defined (LIBSPDM_CPU_AARCH64) || \
+      11                 :            :     defined(LIBSPDM_CPU_ARM)))
+      12                 :            : #else
+      13                 :            :     #include <fcntl.h>
+      14                 :            :     #include <unistd.h>
+      15                 :            :     #include <sys/stat.h>
+      16                 :            : #endif
+      17                 :            : 
+      18                 :            : #if LIBSPDM_ENABLE_CAPABILITY_SET_CERT_CAP
+      19                 :            : 
+      20                 :            : extern bool g_in_trusted_environment;
+      21                 :            : 
+      22                 :            : /**
+      23                 :            :  * Test 1: receives a valid SET_CERTIFICATE request message from Requester to set cert in slot_id:0 with device_cert model
+      24                 :            :  * Expected Behavior: produces a valid SET_CERTIFICATE_RSP response message
+      25                 :            :  **/
+      26                 :          1 : void libspdm_test_responder_set_cetificate_rsp_case1(void **state)
+      27                 :            : {
+      28                 :            :     libspdm_return_t status;
+      29                 :            :     libspdm_test_context_t *spdm_test_context;
+      30                 :            :     libspdm_context_t *spdm_context;
+      31                 :            :     size_t response_size;
+      32                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+      33                 :            :     spdm_set_certificate_response_t *spdm_response;
+      34                 :            :     void *cert_chain;
+      35                 :            :     size_t cert_chain_size;
+      36                 :            :     spdm_set_certificate_request_t *m_libspdm_set_certificate_request;
+      37                 :            : 
+      38                 :            :     void *cert_chain_slot_1;
+      39                 :            :     uint8_t *new_cert_chain;
+      40                 :            :     size_t new_cert_chain_size;
+      41                 :            :     size_t root_cert_hash_size;
+      42                 :            : 
+      43                 :          1 :     spdm_test_context = *state;
+      44                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+      45                 :          1 :     spdm_test_context->case_id = 0x1;
+      46                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+      47                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+      48                 :            : 
+      49                 :          1 :     spdm_context->connection_info.connection_state =
+      50                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+      51                 :          1 :     spdm_context->local_context.capability.flags |=
+      52                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_CERT_CAP;
+      53                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+      54                 :            :         m_libspdm_use_hash_algo;
+      55                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+      56                 :            :         m_libspdm_use_asym_algo;
+      57                 :            : 
+      58                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo =
+      59                 :            :         m_libspdm_use_hash_algo;
+      60                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo =
+      61                 :            :         m_libspdm_use_asym_algo;
+      62                 :            : 
+      63                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+      64                 :            :                                                     m_libspdm_use_asym_algo, &cert_chain,
+      65                 :            :                                                     &cert_chain_size, NULL, NULL);
+      66                 :            : 
+      67                 :          1 :     m_libspdm_set_certificate_request = malloc(sizeof(spdm_set_certificate_request_t) +
+      68                 :            :                                                cert_chain_size);
+      69                 :            : 
+      70                 :          1 :     m_libspdm_set_certificate_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+      71                 :          1 :     m_libspdm_set_certificate_request->header.request_response_code = SPDM_SET_CERTIFICATE;
+      72                 :          1 :     m_libspdm_set_certificate_request->header.param1 = 0;
+      73                 :          1 :     m_libspdm_set_certificate_request->header.param2 = 0;
+      74                 :            : 
+      75                 :          1 :     libspdm_copy_mem(m_libspdm_set_certificate_request + 1,
+      76                 :            :                      LIBSPDM_MAX_CERT_CHAIN_SIZE,
+      77                 :            :                      (uint8_t *)cert_chain, cert_chain_size);
+      78                 :            : 
+      79                 :          1 :     size_t m_libspdm_set_certificate_request_size = sizeof(spdm_set_certificate_request_t) +
+      80                 :            :                                                     cert_chain_size;
+      81                 :            : 
+      82                 :          1 :     response_size = sizeof(response);
+      83                 :          1 :     status = libspdm_get_response_set_certificate(spdm_context,
+      84                 :            :                                                   m_libspdm_set_certificate_request_size,
+      85                 :            :                                                   m_libspdm_set_certificate_request,
+      86                 :            :                                                   &response_size, response);
+      87                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+      88                 :          1 :     assert_int_equal(response_size, sizeof(spdm_set_certificate_response_t));
+      89                 :          1 :     spdm_response = (void *)response;
+      90                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+      91                 :            :                      SPDM_SET_CERTIFICATE_RSP);
+      92                 :            : 
+      93                 :          1 :     free(cert_chain);
+      94                 :          1 :     free(m_libspdm_set_certificate_request);
+      95                 :            : 
+      96                 :            :     /*test overwirte same slot_id cert*/
+      97                 :            : 
+      98                 :            :     /*read a different cert_chain*/
+      99                 :          1 :     libspdm_read_responder_public_certificate_chain_per_slot(1, m_libspdm_use_hash_algo,
+     100                 :            :                                                              m_libspdm_use_asym_algo,
+     101                 :            :                                                              &cert_chain_slot_1,
+     102                 :            :                                                              &cert_chain_size, NULL, NULL);
+     103                 :            : 
+     104                 :          1 :     m_libspdm_set_certificate_request = malloc(sizeof(spdm_set_certificate_request_t) +
+     105                 :            :                                                cert_chain_size);
+     106                 :            : 
+     107                 :          1 :     m_libspdm_set_certificate_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     108                 :          1 :     m_libspdm_set_certificate_request->header.request_response_code = SPDM_SET_CERTIFICATE;
+     109                 :            :     /*write the same slot_id 0*/
+     110                 :          1 :     m_libspdm_set_certificate_request->header.param1 = 0;
+     111                 :          1 :     m_libspdm_set_certificate_request->header.param2 = 0;
+     112                 :            : 
+     113                 :          1 :     libspdm_copy_mem(m_libspdm_set_certificate_request + 1,
+     114                 :            :                      LIBSPDM_MAX_CERT_CHAIN_SIZE,
+     115                 :            :                      (uint8_t *)cert_chain_slot_1, cert_chain_size);
+     116                 :            : 
+     117                 :          1 :     m_libspdm_set_certificate_request_size = sizeof(spdm_set_certificate_request_t) +
+     118                 :            :                                              cert_chain_size;
+     119                 :            : 
+     120                 :          1 :     response_size = sizeof(response);
+     121                 :          1 :     status = libspdm_get_response_set_certificate(spdm_context,
+     122                 :            :                                                   m_libspdm_set_certificate_request_size,
+     123                 :            :                                                   m_libspdm_set_certificate_request,
+     124                 :            :                                                   &response_size, response);
+     125                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     126                 :          1 :     assert_int_equal(response_size, sizeof(spdm_set_certificate_response_t));
+     127                 :          1 :     spdm_response = (void *)response;
+     128                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     129                 :            :                      SPDM_SET_CERTIFICATE_RSP);
+     130                 :            : 
+     131                 :            :     /*check that the cert_chain is overwritten*/
+     132                 :          1 :     libspdm_read_input_file("slot_id_0_cert_chain.der",
+     133                 :            :                             (void **)&new_cert_chain, &new_cert_chain_size);
+     134                 :            : 
+     135                 :            :     /*get actual cert_chain size*/
+     136                 :          1 :     root_cert_hash_size = libspdm_get_hash_size(
+     137                 :            :         spdm_context->local_context.algorithm.base_hash_algo);
+     138                 :          1 :     cert_chain_size = cert_chain_size - sizeof(spdm_cert_chain_t) - root_cert_hash_size;
+     139                 :            : 
+     140                 :            :     /*point to actual cert_chain*/
+     141                 :          1 :     cert_chain_slot_1 = (void*)((uint8_t *)cert_chain_slot_1
+     142                 :          1 :                                 + sizeof(spdm_cert_chain_t) + root_cert_hash_size);
+     143                 :            : 
+     144                 :          1 :     assert_memory_equal(cert_chain_slot_1, new_cert_chain, cert_chain_size);
+     145                 :            : 
+     146                 :          1 :     free(new_cert_chain);
+     147                 :            : 
+     148                 :            :     /*point to total cert_chain_slot_1: it is important*/
+     149                 :          1 :     cert_chain_slot_1 = (void*)((uint8_t *)cert_chain_slot_1
+     150                 :          1 :                                 - sizeof(spdm_cert_chain_t) - root_cert_hash_size);
+     151                 :          1 :     free(cert_chain_slot_1);
+     152                 :          1 :     free(m_libspdm_set_certificate_request);
+     153                 :          1 : }
+     154                 :            : 
+     155                 :            : /**
+     156                 :            :  * Test 2: Wrong SET_CERTIFICATE message size (larger than expected)
+     157                 :            :  * Expected Behavior: generate an ERROR_RESPONSE with code SPDM_ERROR_CODE_INVALID_REQUEST
+     158                 :            :  **/
+     159                 :          1 : void libspdm_test_responder_set_cetificate_rsp_case2(void **state)
+     160                 :            : {
+     161                 :            :     libspdm_return_t status;
+     162                 :            :     libspdm_test_context_t *spdm_test_context;
+     163                 :            :     libspdm_context_t *spdm_context;
+     164                 :            :     size_t response_size;
+     165                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     166                 :            :     spdm_set_certificate_response_t *spdm_response;
+     167                 :            :     void *cert_chain;
+     168                 :            :     size_t cert_chain_size;
+     169                 :            : 
+     170                 :          1 :     spdm_test_context = *state;
+     171                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     172                 :          1 :     spdm_test_context->case_id = 0x2;
+     173                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     174                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     175                 :            : 
+     176                 :          1 :     spdm_context->connection_info.connection_state =
+     177                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     178                 :          1 :     spdm_context->local_context.capability.flags |=
+     179                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_CERT_CAP;
+     180                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     181                 :            :         m_libspdm_use_hash_algo;
+     182                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     183                 :            :         m_libspdm_use_asym_algo;
+     184                 :            : 
+     185                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo =
+     186                 :            :         m_libspdm_use_hash_algo;
+     187                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo =
+     188                 :            :         m_libspdm_use_asym_algo;
+     189                 :            : 
+     190                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     191                 :            :                                                     m_libspdm_use_asym_algo, &cert_chain,
+     192                 :            :                                                     &cert_chain_size, NULL, NULL);
+     193                 :            : 
+     194                 :            :     spdm_set_certificate_request_t *m_libspdm_set_certificate_request;
+     195                 :          1 :     m_libspdm_set_certificate_request = malloc(sizeof(spdm_set_certificate_request_t) +
+     196                 :            :                                                cert_chain_size);
+     197                 :            : 
+     198                 :          1 :     m_libspdm_set_certificate_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     199                 :          1 :     m_libspdm_set_certificate_request->header.request_response_code = SPDM_SET_CERTIFICATE;
+     200                 :          1 :     m_libspdm_set_certificate_request->header.param1 = 0;
+     201                 :          1 :     m_libspdm_set_certificate_request->header.param2 = 0;
+     202                 :            : 
+     203                 :          1 :     libspdm_copy_mem(m_libspdm_set_certificate_request + 1,
+     204                 :            :                      LIBSPDM_MAX_CERT_CHAIN_SIZE,
+     205                 :            :                      (uint8_t *)cert_chain, cert_chain_size);
+     206                 :            : 
+     207                 :            :     /* Bad request size: only have header size*/
+     208                 :          1 :     size_t m_libspdm_set_certificate_request_size = sizeof(spdm_set_certificate_request_t);
+     209                 :            : 
+     210                 :          1 :     response_size = sizeof(response);
+     211                 :          1 :     status = libspdm_get_response_set_certificate(spdm_context,
+     212                 :            :                                                   m_libspdm_set_certificate_request_size,
+     213                 :            :                                                   m_libspdm_set_certificate_request,
+     214                 :            :                                                   &response_size, response);
+     215                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     216                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     217                 :          1 :     spdm_response = (void *)response;
+     218                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     219                 :            :                      SPDM_ERROR);
+     220                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     221                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+     222                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     223                 :            : 
+     224                 :          1 :     free(cert_chain);
+     225                 :          1 :     free(m_libspdm_set_certificate_request);
+     226                 :          1 : }
+     227                 :            : 
+     228                 :            : 
+     229                 :            : /**
+     230                 :            :  * Test 3: Force response_state = LIBSPDM_RESPONSE_STATE_BUSY when asked SET_CERTIFICATE
+     231                 :            :  * Expected Behavior: generate an ERROR_RESPONSE with code SPDM_ERROR_CODE_BUSY
+     232                 :            :  **/
+     233                 :          1 : void libspdm_test_responder_set_cetificate_rsp_case3(void **state)
+     234                 :            : {
+     235                 :            :     libspdm_return_t status;
+     236                 :            :     libspdm_test_context_t *spdm_test_context;
+     237                 :            :     libspdm_context_t *spdm_context;
+     238                 :            :     size_t response_size;
+     239                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     240                 :            :     spdm_set_certificate_response_t *spdm_response;
+     241                 :            :     void *cert_chain;
+     242                 :            :     size_t cert_chain_size;
+     243                 :            : 
+     244                 :          1 :     spdm_test_context = *state;
+     245                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     246                 :          1 :     spdm_test_context->case_id = 0x3;
+     247                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     248                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     249                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_BUSY;
+     250                 :            : 
+     251                 :          1 :     spdm_context->connection_info.connection_state =
+     252                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     253                 :          1 :     spdm_context->local_context.capability.flags |=
+     254                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_CERT_CAP;
+     255                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     256                 :            :         m_libspdm_use_hash_algo;
+     257                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     258                 :            :         m_libspdm_use_asym_algo;
+     259                 :            : 
+     260                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo =
+     261                 :            :         m_libspdm_use_hash_algo;
+     262                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo =
+     263                 :            :         m_libspdm_use_asym_algo;
+     264                 :            : 
+     265                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     266                 :            :                                                     m_libspdm_use_asym_algo, &cert_chain,
+     267                 :            :                                                     &cert_chain_size, NULL, NULL);
+     268                 :            : 
+     269                 :            :     spdm_set_certificate_request_t *m_libspdm_set_certificate_request;
+     270                 :          1 :     m_libspdm_set_certificate_request = malloc(sizeof(spdm_set_certificate_request_t) +
+     271                 :            :                                                cert_chain_size);
+     272                 :            : 
+     273                 :          1 :     m_libspdm_set_certificate_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     274                 :          1 :     m_libspdm_set_certificate_request->header.request_response_code = SPDM_SET_CERTIFICATE;
+     275                 :          1 :     m_libspdm_set_certificate_request->header.param1 = 0;
+     276                 :          1 :     m_libspdm_set_certificate_request->header.param2 = 0;
+     277                 :            : 
+     278                 :          1 :     libspdm_copy_mem(m_libspdm_set_certificate_request + 1,
+     279                 :            :                      LIBSPDM_MAX_CERT_CHAIN_SIZE,
+     280                 :            :                      (uint8_t *)cert_chain, cert_chain_size);
+     281                 :            : 
+     282                 :            :     /* Bad request size: right request size + 1*/
+     283                 :          1 :     size_t m_libspdm_set_certificate_request_size = sizeof(spdm_set_certificate_request_t) +
+     284                 :          1 :                                                     cert_chain_size + 1;
+     285                 :            : 
+     286                 :          1 :     response_size = sizeof(response);
+     287                 :          1 :     status = libspdm_get_response_set_certificate(spdm_context,
+     288                 :            :                                                   m_libspdm_set_certificate_request_size,
+     289                 :            :                                                   m_libspdm_set_certificate_request,
+     290                 :            :                                                   &response_size, response);
+     291                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     292                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     293                 :          1 :     spdm_response = (void *)response;
+     294                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     295                 :            :                      SPDM_ERROR);
+     296                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_BUSY);
+     297                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     298                 :          1 :     assert_int_equal(spdm_context->response_state,
+     299                 :            :                      LIBSPDM_RESPONSE_STATE_BUSY);
+     300                 :            : 
+     301                 :          1 :     free(cert_chain);
+     302                 :          1 :     free(m_libspdm_set_certificate_request);
+     303                 :          1 : }
+     304                 :            : 
+     305                 :            : 
+     306                 :            : /**
+     307                 :            :  * Test 4: Force response_state = LIBSPDM_RESPONSE_STATE_NEED_RESYNC when asked SET_CERTIFICATE
+     308                 :            :  * Expected Behavior: generate an ERROR_RESPONSE with code SPDM_ERROR_CODE_REQUEST_RESYNCH
+     309                 :            :  **/
+     310                 :          1 : void libspdm_test_responder_set_cetificate_rsp_case4(void **state)
+     311                 :            : {
+     312                 :            :     libspdm_return_t status;
+     313                 :            :     libspdm_test_context_t *spdm_test_context;
+     314                 :            :     libspdm_context_t *spdm_context;
+     315                 :            :     size_t response_size;
+     316                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     317                 :            :     spdm_set_certificate_response_t *spdm_response;
+     318                 :            :     void *cert_chain;
+     319                 :            :     size_t cert_chain_size;
+     320                 :            :     spdm_set_certificate_request_t *m_libspdm_set_certificate_request;
+     321                 :            : 
+     322                 :          1 :     spdm_test_context = *state;
+     323                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     324                 :          1 :     spdm_test_context->case_id = 0x4;
+     325                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     326                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     327                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NEED_RESYNC;
+     328                 :            : 
+     329                 :          1 :     spdm_context->connection_info.connection_state =
+     330                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     331                 :          1 :     spdm_context->local_context.capability.flags |=
+     332                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_CERT_CAP;
+     333                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     334                 :            :         m_libspdm_use_hash_algo;
+     335                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     336                 :            :         m_libspdm_use_asym_algo;
+     337                 :            : 
+     338                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo =
+     339                 :            :         m_libspdm_use_hash_algo;
+     340                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo =
+     341                 :            :         m_libspdm_use_asym_algo;
+     342                 :            : 
+     343                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     344                 :            :                                                     m_libspdm_use_asym_algo, &cert_chain,
+     345                 :            :                                                     &cert_chain_size, NULL, NULL);
+     346                 :            : 
+     347                 :          1 :     m_libspdm_set_certificate_request = malloc(sizeof(spdm_set_certificate_request_t) +
+     348                 :            :                                                cert_chain_size);
+     349                 :            : 
+     350                 :          1 :     m_libspdm_set_certificate_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     351                 :          1 :     m_libspdm_set_certificate_request->header.request_response_code = SPDM_SET_CERTIFICATE;
+     352                 :          1 :     m_libspdm_set_certificate_request->header.param1 = 0;
+     353                 :          1 :     m_libspdm_set_certificate_request->header.param2 = 0;
+     354                 :            : 
+     355                 :          1 :     libspdm_copy_mem(m_libspdm_set_certificate_request + 1,
+     356                 :            :                      LIBSPDM_MAX_CERT_CHAIN_SIZE,
+     357                 :            :                      (uint8_t *)cert_chain, cert_chain_size);
+     358                 :            : 
+     359                 :          1 :     size_t m_libspdm_set_certificate_request_size = sizeof(spdm_set_certificate_request_t) +
+     360                 :            :                                                     cert_chain_size;
+     361                 :            : 
+     362                 :          1 :     response_size = sizeof(response);
+     363                 :          1 :     status = libspdm_get_response_set_certificate(spdm_context,
+     364                 :            :                                                   m_libspdm_set_certificate_request_size,
+     365                 :            :                                                   m_libspdm_set_certificate_request,
+     366                 :            :                                                   &response_size, response);
+     367                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     368                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     369                 :          1 :     spdm_response = (void *)response;
+     370                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     371                 :            :                      SPDM_ERROR);
+     372                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     373                 :            :                      SPDM_ERROR_CODE_REQUEST_RESYNCH);
+     374                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     375                 :          1 :     assert_int_equal(spdm_context->response_state,
+     376                 :            :                      LIBSPDM_RESPONSE_STATE_NEED_RESYNC);
+     377                 :            : 
+     378                 :          1 :     free(cert_chain);
+     379                 :          1 :     free(m_libspdm_set_certificate_request);
+     380                 :          1 : }
+     381                 :            : 
+     382                 :            : /**
+     383                 :            :  * Test 5: receives a valid SET_CERTIFICATE request message from Requester to set cert in slot_id:1 with session
+     384                 :            :  * Expected Behavior: produces a valid SET_CERTIFICATE_RSP response message
+     385                 :            :  **/
+     386                 :          1 : void libspdm_test_responder_set_cetificate_rsp_case5(void **state)
+     387                 :            : {
+     388                 :            :     libspdm_return_t status;
+     389                 :            :     libspdm_test_context_t *spdm_test_context;
+     390                 :            :     libspdm_context_t *spdm_context;
+     391                 :            :     size_t response_size;
+     392                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     393                 :            :     spdm_set_certificate_response_t *spdm_response;
+     394                 :            :     void *cert_chain;
+     395                 :            :     size_t cert_chain_size;
+     396                 :            :     spdm_set_certificate_request_t *m_libspdm_set_certificate_request;
+     397                 :            : 
+     398                 :            :     libspdm_session_info_t *session_info;
+     399                 :            :     uint32_t session_id;
+     400                 :            : 
+     401                 :          1 :     spdm_test_context = *state;
+     402                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     403                 :          1 :     spdm_test_context->case_id = 0x5;
+     404                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     405                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     406                 :            :     /*responset_state need to set normal*/
+     407                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+     408                 :          1 :     spdm_context->connection_info.connection_state =
+     409                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     410                 :          1 :     spdm_context->local_context.capability.flags |=
+     411                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_CERT_CAP;
+     412                 :          1 :     spdm_context->local_context.capability.flags |=
+     413                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+     414                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     415                 :            :         m_libspdm_use_hash_algo;
+     416                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     417                 :            :         m_libspdm_use_asym_algo;
+     418                 :            : 
+     419                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo =
+     420                 :            :         m_libspdm_use_hash_algo;
+     421                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo =
+     422                 :            :         m_libspdm_use_asym_algo;
+     423                 :            : 
+     424                 :          1 :     session_id = 0xFFFFFFFF;
+     425                 :          1 :     spdm_context->latest_session_id = session_id;
+     426                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+     427                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+     428                 :          1 :     session_info = &spdm_context->session_info[0];
+     429                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+     430                 :          1 :     libspdm_secured_message_set_session_state(
+     431                 :            :         session_info->secured_message_context,
+     432                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+     433                 :            : 
+     434                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     435                 :            :                                                     m_libspdm_use_asym_algo, &cert_chain,
+     436                 :            :                                                     &cert_chain_size, NULL, NULL);
+     437                 :            : 
+     438                 :          1 :     m_libspdm_set_certificate_request = malloc(sizeof(spdm_set_certificate_request_t) +
+     439                 :            :                                                cert_chain_size);
+     440                 :            : 
+     441                 :          1 :     m_libspdm_set_certificate_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     442                 :          1 :     m_libspdm_set_certificate_request->header.request_response_code = SPDM_SET_CERTIFICATE;
+     443                 :          1 :     m_libspdm_set_certificate_request->header.param1 = 1;
+     444                 :          1 :     m_libspdm_set_certificate_request->header.param2 = 0;
+     445                 :            : 
+     446                 :          1 :     libspdm_copy_mem(m_libspdm_set_certificate_request + 1,
+     447                 :            :                      LIBSPDM_MAX_CERT_CHAIN_SIZE,
+     448                 :            :                      (uint8_t *)cert_chain, cert_chain_size);
+     449                 :            : 
+     450                 :          1 :     size_t m_libspdm_set_certificate_request_size = sizeof(spdm_set_certificate_request_t) +
+     451                 :            :                                                     cert_chain_size;
+     452                 :            : 
+     453                 :          1 :     response_size = sizeof(response);
+     454                 :          1 :     status = libspdm_get_response_set_certificate(spdm_context,
+     455                 :            :                                                   m_libspdm_set_certificate_request_size,
+     456                 :            :                                                   m_libspdm_set_certificate_request,
+     457                 :            :                                                   &response_size, response);
+     458                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     459                 :          1 :     assert_int_equal(response_size, sizeof(spdm_set_certificate_response_t));
+     460                 :          1 :     spdm_response = (void *)response;
+     461                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     462                 :            :                      SPDM_SET_CERTIFICATE_RSP);
+     463                 :            : 
+     464                 :          1 :     free(cert_chain);
+     465                 :          1 :     free(m_libspdm_set_certificate_request);
+     466                 :          1 : }
+     467                 :            : 
+     468                 :            : /**
+     469                 :            :  * Test 6: receives a valid SET_CERTIFICATE request message from Requester with need_reset
+     470                 :            :  * Expected Behavior: The Responder return need reset
+     471                 :            :  **/
+     472                 :          1 : void libspdm_test_responder_set_cetificate_rsp_case6(void **state)
+     473                 :            : {
+     474                 :            :     libspdm_return_t status;
+     475                 :            :     libspdm_test_context_t *spdm_test_context;
+     476                 :            :     libspdm_context_t *spdm_context;
+     477                 :            :     size_t response_size;
+     478                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     479                 :            :     spdm_set_certificate_response_t *spdm_response;
+     480                 :            :     void *cert_chain;
+     481                 :            :     size_t cert_chain_size;
+     482                 :            :     spdm_set_certificate_request_t *m_libspdm_set_certificate_request;
+     483                 :            : 
+     484                 :          1 :     spdm_test_context = *state;
+     485                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     486                 :          1 :     spdm_test_context->case_id = 0x6;
+     487                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     488                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     489                 :            : 
+     490                 :          1 :     spdm_context->connection_info.connection_state =
+     491                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     492                 :          1 :     spdm_context->local_context.capability.flags |=
+     493                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_CERT_CAP;
+     494                 :          1 :     spdm_context->local_context.capability.flags |=
+     495                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_INSTALL_RESET_CAP;
+     496                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     497                 :            :         m_libspdm_use_hash_algo;
+     498                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     499                 :            :         m_libspdm_use_asym_algo;
+     500                 :            : 
+     501                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo =
+     502                 :            :         m_libspdm_use_hash_algo;
+     503                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo =
+     504                 :            :         m_libspdm_use_asym_algo;
+     505                 :            : 
+     506                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     507                 :            :                                                     m_libspdm_use_asym_algo, &cert_chain,
+     508                 :            :                                                     &cert_chain_size, NULL, NULL);
+     509                 :            : 
+     510                 :          1 :     m_libspdm_set_certificate_request = malloc(sizeof(spdm_set_certificate_request_t) +
+     511                 :            :                                                cert_chain_size);
+     512                 :            : 
+     513                 :          1 :     m_libspdm_set_certificate_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     514                 :          1 :     m_libspdm_set_certificate_request->header.request_response_code = SPDM_SET_CERTIFICATE;
+     515                 :          1 :     m_libspdm_set_certificate_request->header.param1 = 0;
+     516                 :          1 :     m_libspdm_set_certificate_request->header.param2 = 0;
+     517                 :            : 
+     518                 :          1 :     libspdm_copy_mem(m_libspdm_set_certificate_request + 1,
+     519                 :            :                      LIBSPDM_MAX_CERT_CHAIN_SIZE,
+     520                 :            :                      (uint8_t *)cert_chain, cert_chain_size);
+     521                 :            : 
+     522                 :          1 :     size_t m_libspdm_set_certificate_request_size = sizeof(spdm_set_certificate_request_t) +
+     523                 :            :                                                     cert_chain_size;
+     524                 :            : 
+     525                 :          1 :     response_size = sizeof(response);
+     526                 :          1 :     status = libspdm_get_response_set_certificate(spdm_context,
+     527                 :            :                                                   m_libspdm_set_certificate_request_size,
+     528                 :            :                                                   m_libspdm_set_certificate_request,
+     529                 :            :                                                   &response_size, response);
+     530                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     531                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     532                 :          1 :     spdm_response = (void *)response;
+     533                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     534                 :            :                      SPDM_ERROR);
+     535                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     536                 :            :                      SPDM_ERROR_CODE_RESET_REQUIRED);
+     537                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     538                 :            : 
+     539                 :          1 :     free(cert_chain);
+     540                 :          1 :     free(m_libspdm_set_certificate_request);
+     541                 :          1 : }
+     542                 :            : 
+     543                 :            : /**
+     544                 :            :  * Test 7: receives a valid SET_CERTIFICATE request message from Requester to set cert in slot_id:0 with alias_cert model
+     545                 :            :  * Expected Behavior: produces a valid SET_CERTIFICATE_RSP response message
+     546                 :            :  **/
+     547                 :          1 : void libspdm_test_responder_set_cetificate_rsp_case7(void **state)
+     548                 :            : {
+     549                 :            :     libspdm_return_t status;
+     550                 :            :     libspdm_test_context_t *spdm_test_context;
+     551                 :            :     libspdm_context_t *spdm_context;
+     552                 :            :     size_t response_size;
+     553                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     554                 :            :     spdm_set_certificate_response_t *spdm_response;
+     555                 :            :     void *cert_chain;
+     556                 :            :     size_t cert_chain_size;
+     557                 :            :     spdm_set_certificate_request_t *m_libspdm_set_certificate_request;
+     558                 :            : 
+     559                 :          1 :     spdm_test_context = *state;
+     560                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     561                 :          1 :     spdm_test_context->case_id = 0x7;
+     562                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     563                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     564                 :            : 
+     565                 :          1 :     spdm_context->connection_info.connection_state =
+     566                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     567                 :          1 :     spdm_context->local_context.capability.flags |=
+     568                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_CERT_CAP;
+     569                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     570                 :            :         m_libspdm_use_hash_algo;
+     571                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     572                 :            :         m_libspdm_use_asym_algo;
+     573                 :          1 :     spdm_context->local_context.capability.flags &=
+     574                 :            :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_INSTALL_RESET_CAP;
+     575                 :            : 
+     576                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo =
+     577                 :            :         m_libspdm_use_hash_algo;
+     578                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo =
+     579                 :            :         m_libspdm_use_asym_algo;
+     580                 :            : 
+     581                 :            :     /*set alias cert mode*/
+     582                 :          1 :     spdm_context->local_context.capability.flags |=
+     583                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ALIAS_CERT_CAP;
+     584                 :            :     /*read alias cert(alias cert chain is partial)*/
+     585                 :          1 :     libspdm_read_responder_public_certificate_chain_alias_cert_till_dev_cert_ca(
+     586                 :            :         m_libspdm_use_hash_algo, m_libspdm_use_asym_algo,
+     587                 :            :         &cert_chain, &cert_chain_size, NULL, NULL);
+     588                 :            : 
+     589                 :          1 :     m_libspdm_set_certificate_request = malloc(sizeof(spdm_set_certificate_request_t) +
+     590                 :            :                                                cert_chain_size);
+     591                 :            : 
+     592                 :          1 :     m_libspdm_set_certificate_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     593                 :          1 :     m_libspdm_set_certificate_request->header.request_response_code = SPDM_SET_CERTIFICATE;
+     594                 :          1 :     m_libspdm_set_certificate_request->header.param1 = 0;
+     595                 :          1 :     m_libspdm_set_certificate_request->header.param2 = 0;
+     596                 :            : 
+     597                 :          1 :     libspdm_copy_mem(m_libspdm_set_certificate_request + 1,
+     598                 :            :                      LIBSPDM_MAX_CERT_CHAIN_SIZE,
+     599                 :            :                      (uint8_t *)cert_chain, cert_chain_size);
+     600                 :            : 
+     601                 :          1 :     size_t m_libspdm_set_certificate_request_size = sizeof(spdm_set_certificate_request_t) +
+     602                 :            :                                                     cert_chain_size;
+     603                 :            : 
+     604                 :          1 :     response_size = sizeof(response);
+     605                 :          1 :     status = libspdm_get_response_set_certificate(spdm_context,
+     606                 :            :                                                   m_libspdm_set_certificate_request_size,
+     607                 :            :                                                   m_libspdm_set_certificate_request,
+     608                 :            :                                                   &response_size, response);
+     609                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     610                 :          1 :     assert_int_equal(response_size, sizeof(spdm_set_certificate_response_t));
+     611                 :          1 :     spdm_response = (void *)response;
+     612                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     613                 :            :                      SPDM_SET_CERTIFICATE_RSP);
+     614                 :            : 
+     615                 :          1 :     free(cert_chain);
+     616                 :          1 :     free(m_libspdm_set_certificate_request);
+     617                 :          1 : }
+     618                 :            : 
+     619                 :            : /**
+     620                 :            :  * Test 8: receives a SET_CERTIFICATE request message to set cert in slot_id:1 without session and with trusted environment
+     621                 :            :  * Expected Behavior: produces a valid SET_CERTIFICATE_RSP response message
+     622                 :            :  **/
+     623                 :          1 : void libspdm_test_responder_set_cetificate_rsp_case8(void **state)
+     624                 :            : {
+     625                 :            :     libspdm_return_t status;
+     626                 :            :     libspdm_test_context_t *spdm_test_context;
+     627                 :            :     libspdm_context_t *spdm_context;
+     628                 :            :     size_t response_size;
+     629                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     630                 :            :     spdm_set_certificate_response_t *spdm_response;
+     631                 :            :     void *cert_chain;
+     632                 :            :     size_t cert_chain_size;
+     633                 :            :     spdm_set_certificate_request_t *m_libspdm_set_certificate_request;
+     634                 :            : 
+     635                 :          1 :     spdm_test_context = *state;
+     636                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     637                 :          1 :     spdm_test_context->case_id = 0x8;
+     638                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     639                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     640                 :            :     /*responset_state need to set normal*/
+     641                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+     642                 :          1 :     spdm_context->connection_info.connection_state =
+     643                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     644                 :          1 :     spdm_context->local_context.capability.flags |=
+     645                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_CERT_CAP;
+     646                 :          1 :     spdm_context->local_context.capability.flags &=
+     647                 :            :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_INSTALL_RESET_CAP;
+     648                 :          1 :     spdm_context->local_context.capability.flags &=
+     649                 :            :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ALIAS_CERT_CAP;
+     650                 :          1 :     spdm_context->local_context.capability.flags |=
+     651                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+     652                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     653                 :            :         m_libspdm_use_hash_algo;
+     654                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     655                 :            :         m_libspdm_use_asym_algo;
+     656                 :            : 
+     657                 :          1 :     spdm_context->last_spdm_request_session_id_valid = false;
+     658                 :          1 :     g_in_trusted_environment = true;
+     659                 :            : 
+     660                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     661                 :            :                                                     m_libspdm_use_asym_algo, &cert_chain,
+     662                 :            :                                                     &cert_chain_size, NULL, NULL);
+     663                 :            : 
+     664                 :          1 :     m_libspdm_set_certificate_request = malloc(sizeof(spdm_set_certificate_request_t) +
+     665                 :            :                                                cert_chain_size);
+     666                 :            : 
+     667                 :          1 :     m_libspdm_set_certificate_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     668                 :          1 :     m_libspdm_set_certificate_request->header.request_response_code = SPDM_SET_CERTIFICATE;
+     669                 :          1 :     m_libspdm_set_certificate_request->header.param1 = 1;
+     670                 :          1 :     m_libspdm_set_certificate_request->header.param2 = 0;
+     671                 :            : 
+     672                 :          1 :     libspdm_copy_mem(m_libspdm_set_certificate_request + 1,
+     673                 :            :                      LIBSPDM_MAX_CERT_CHAIN_SIZE,
+     674                 :            :                      (uint8_t *)cert_chain, cert_chain_size);
+     675                 :            : 
+     676                 :          1 :     size_t m_libspdm_set_certificate_request_size = sizeof(spdm_set_certificate_request_t) +
+     677                 :            :                                                     cert_chain_size;
+     678                 :            : 
+     679                 :          1 :     response_size = sizeof(response);
+     680                 :          1 :     status = libspdm_get_response_set_certificate(spdm_context,
+     681                 :            :                                                   m_libspdm_set_certificate_request_size,
+     682                 :            :                                                   m_libspdm_set_certificate_request,
+     683                 :            :                                                   &response_size, response);
+     684                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     685                 :          1 :     assert_int_equal(response_size, sizeof(spdm_set_certificate_response_t));
+     686                 :          1 :     spdm_response = (void *)response;
+     687                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     688                 :            :                      SPDM_SET_CERTIFICATE_RSP);
+     689                 :            : 
+     690                 :          1 :     free(cert_chain);
+     691                 :          1 :     free(m_libspdm_set_certificate_request);
+     692                 :          1 : }
+     693                 :            : 
+     694                 :            : /**
+     695                 :            :  * Test 9: receives a SET_CERTIFICATE request message to set cert in slot_id:1 without session and without trusted environment
+     696                 :            :  * Expected Behavior: produces a valid ERROR response message
+     697                 :            :  **/
+     698                 :          1 : void libspdm_test_responder_set_cetificate_rsp_case9(void **state)
+     699                 :            : {
+     700                 :            :     libspdm_return_t status;
+     701                 :            :     libspdm_test_context_t *spdm_test_context;
+     702                 :            :     libspdm_context_t *spdm_context;
+     703                 :            :     size_t response_size;
+     704                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     705                 :            :     spdm_set_certificate_response_t *spdm_response;
+     706                 :            :     void *cert_chain;
+     707                 :            :     size_t cert_chain_size;
+     708                 :            :     spdm_set_certificate_request_t *m_libspdm_set_certificate_request;
+     709                 :            : 
+     710                 :          1 :     spdm_test_context = *state;
+     711                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     712                 :          1 :     spdm_test_context->case_id = 0x9;
+     713                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
+     714                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     715                 :            :     /*responset_state need to set normal*/
+     716                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+     717                 :          1 :     spdm_context->connection_info.connection_state =
+     718                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     719                 :          1 :     spdm_context->local_context.capability.flags |=
+     720                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_CERT_CAP;
+     721                 :          1 :     spdm_context->local_context.capability.flags &=
+     722                 :            :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_INSTALL_RESET_CAP;
+     723                 :          1 :     spdm_context->local_context.capability.flags &=
+     724                 :            :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ALIAS_CERT_CAP;
+     725                 :          1 :     spdm_context->local_context.capability.flags |=
+     726                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+     727                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     728                 :            :         m_libspdm_use_hash_algo;
+     729                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     730                 :            :         m_libspdm_use_asym_algo;
+     731                 :            : 
+     732                 :          1 :     spdm_context->last_spdm_request_session_id_valid = false;
+     733                 :          1 :     g_in_trusted_environment = false;
+     734                 :            : 
+     735                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     736                 :            :                                                     m_libspdm_use_asym_algo, &cert_chain,
+     737                 :            :                                                     &cert_chain_size, NULL, NULL);
+     738                 :            : 
+     739                 :          1 :     m_libspdm_set_certificate_request = malloc(sizeof(spdm_set_certificate_request_t) +
+     740                 :            :                                                cert_chain_size);
+     741                 :            : 
+     742                 :          1 :     m_libspdm_set_certificate_request->header.spdm_version = SPDM_MESSAGE_VERSION_12;
+     743                 :          1 :     m_libspdm_set_certificate_request->header.request_response_code = SPDM_SET_CERTIFICATE;
+     744                 :          1 :     m_libspdm_set_certificate_request->header.param1 = 1;
+     745                 :          1 :     m_libspdm_set_certificate_request->header.param2 = 0;
+     746                 :            : 
+     747                 :          1 :     libspdm_copy_mem(m_libspdm_set_certificate_request + 1,
+     748                 :            :                      LIBSPDM_MAX_CERT_CHAIN_SIZE,
+     749                 :            :                      (uint8_t *)cert_chain, cert_chain_size);
+     750                 :            : 
+     751                 :          1 :     size_t m_libspdm_set_certificate_request_size = sizeof(spdm_set_certificate_request_t) +
+     752                 :            :                                                     cert_chain_size;
+     753                 :            : 
+     754                 :          1 :     response_size = sizeof(response);
+     755                 :          1 :     status = libspdm_get_response_set_certificate(spdm_context,
+     756                 :            :                                                   m_libspdm_set_certificate_request_size,
+     757                 :            :                                                   m_libspdm_set_certificate_request,
+     758                 :            :                                                   &response_size, response);
+     759                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     760                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     761                 :          1 :     spdm_response = (void *)response;
+     762                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     763                 :            :                      SPDM_ERROR);
+     764                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     765                 :            :                      SPDM_ERROR_CODE_UNEXPECTED_REQUEST);
+     766                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     767                 :            : 
+     768                 :          1 :     free(cert_chain);
+     769                 :          1 :     free(m_libspdm_set_certificate_request);
+     770                 :          1 : }
+     771                 :            : 
+     772                 :            : /**
+     773                 :            :  * Test 10: receives a valid SET_CERTIFICATE request message from Requester to erase cert in slot_id:1 with session
+     774                 :            :  * Expected Behavior: produces a valid SET_CERTIFICATE_RSP response message
+     775                 :            :  **/
+     776                 :          1 : void libspdm_test_responder_set_cetificate_rsp_case10(void **state)
+     777                 :            : {
+     778                 :            :     libspdm_return_t status;
+     779                 :            :     libspdm_test_context_t *spdm_test_context;
+     780                 :            :     libspdm_context_t *spdm_context;
+     781                 :            :     size_t response_size;
+     782                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     783                 :            :     spdm_set_certificate_response_t *spdm_response;
+     784                 :            :     spdm_set_certificate_request_t *m_libspdm_set_certificate_request;
+     785                 :            : 
+     786                 :            :     libspdm_session_info_t *session_info;
+     787                 :            :     uint32_t session_id;
+     788                 :            :     uint8_t slot_id;
+     789                 :            : #if defined(_WIN32) || (defined(__clang__) && (defined (LIBSPDM_CPU_AARCH64) || \
+     790                 :            :     defined(LIBSPDM_CPU_ARM)))
+     791                 :            :     FILE *fp_out;
+     792                 :            : #else
+     793                 :            :     int64_t fp_out;
+     794                 :            :     struct stat file_stat;
+     795                 :            : #endif
+     796                 :            :     size_t cert_file_size;
+     797                 :            : 
+     798                 :          1 :     char file_name[] = "slot_id_0_cert_chain.der";
+     799                 :          1 :     slot_id = 1;
+     800                 :            : 
+     801                 :          1 :     spdm_test_context = *state;
+     802                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     803                 :          1 :     spdm_test_context->case_id = 0xA;
+     804                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+     805                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     806                 :            :     /*responset_state need to set normal*/
+     807                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+     808                 :          1 :     spdm_context->connection_info.connection_state =
+     809                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     810                 :          1 :     spdm_context->local_context.capability.flags |=
+     811                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_CERT_CAP;
+     812                 :          1 :     spdm_context->local_context.capability.flags |=
+     813                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
+     814                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     815                 :            :         m_libspdm_use_hash_algo;
+     816                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     817                 :            :         m_libspdm_use_asym_algo;
+     818                 :            : 
+     819                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo =
+     820                 :            :         m_libspdm_use_hash_algo;
+     821                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo =
+     822                 :            :         m_libspdm_use_asym_algo;
+     823                 :            : 
+     824                 :          1 :     session_id = 0xFFFFFFFF;
+     825                 :          1 :     spdm_context->latest_session_id = session_id;
+     826                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+     827                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+     828                 :          1 :     session_info = &spdm_context->session_info[0];
+     829                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+     830                 :          1 :     libspdm_secured_message_set_session_state(
+     831                 :            :         session_info->secured_message_context,
+     832                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+     833                 :            : 
+     834                 :          1 :     m_libspdm_set_certificate_request = malloc(sizeof(spdm_set_certificate_request_t));
+     835                 :            : 
+     836                 :          1 :     m_libspdm_set_certificate_request->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+     837                 :          1 :     m_libspdm_set_certificate_request->header.request_response_code = SPDM_SET_CERTIFICATE;
+     838                 :          1 :     m_libspdm_set_certificate_request->header.param1 = slot_id |
+     839                 :            :                                                        SPDM_SET_CERTIFICATE_REQUEST_ATTRIBUTES_ERASE;
+     840                 :          1 :     m_libspdm_set_certificate_request->header.param2 = 0;
+     841                 :            : 
+     842                 :          1 :     size_t m_libspdm_set_certificate_request_size = sizeof(spdm_set_certificate_request_t);
+     843                 :            : 
+     844                 :          1 :     response_size = sizeof(response);
+     845                 :          1 :     status = libspdm_get_response_set_certificate(spdm_context,
+     846                 :            :                                                   m_libspdm_set_certificate_request_size,
+     847                 :            :                                                   m_libspdm_set_certificate_request,
+     848                 :            :                                                   &response_size, response);
+     849                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     850                 :          1 :     assert_int_equal(response_size, sizeof(spdm_set_certificate_response_t));
+     851                 :          1 :     spdm_response = (void *)response;
+     852                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     853                 :            :                      SPDM_SET_CERTIFICATE_RSP);
+     854                 :          1 :     assert_int_equal(spdm_response->header.param1, slot_id);
+     855                 :            : 
+     856                 :            :     /*change the file name, for example: slot_id_1_cert_chain.der*/
+     857                 :          1 :     file_name[8] = (char)(slot_id + '0');
+     858                 :            : 
+     859                 :            : #if defined(_WIN32) || (defined(__clang__) && (defined (LIBSPDM_CPU_AARCH64) || \
+     860                 :            :     defined(LIBSPDM_CPU_ARM)))
+     861                 :            :     if ((fp_out = fopen(file_name, "r")) == NULL) {
+     862                 :            :         printf("Unable to open file %s\n", file_name);
+     863                 :            :         assert_false(true);
+     864                 :            :     }
+     865                 :            : 
+     866                 :            :     /*check the cert is erased*/
+     867                 :            :     fseek(fp_out, 0, SEEK_END);
+     868                 :            :     cert_file_size = ftell(fp_out);
+     869                 :            :     assert_int_equal(cert_file_size, 0);
+     870                 :            : 
+     871                 :            :     fclose(fp_out);
+     872                 :            : #else
+     873         [ -  + ]:          1 :     if ((fp_out = open(file_name, O_RDONLY)) == -1) {
+     874                 :          0 :         printf("Unable to open file %s\n", file_name);
+     875                 :          0 :         assert_false(true);
+     876                 :            :     }
+     877                 :            : 
+     878         [ -  + ]:          1 :     if (fstat(fp_out, &file_stat) != 0) {
+     879                 :          0 :         assert_false(true);
+     880                 :            :     }
+     881                 :            : 
+     882                 :          1 :     cert_file_size = file_stat.st_size;
+     883                 :          1 :     assert_int_equal(cert_file_size, 0);
+     884                 :            : 
+     885                 :          1 :     close(fp_out);
+     886                 :            : #endif
+     887                 :            : 
+     888                 :          1 :     free(m_libspdm_set_certificate_request);
+     889                 :          1 : }
+     890                 :            : 
+     891                 :            : /**
+     892                 :            :  * Test 11: receives a valid SET_CERTIFICATE request message from Requester to set cert in slot_id:1 with key_pair_id
+     893                 :            :  * Expected Behavior: produces a valid SET_CERTIFICATE_RSP response message
+     894                 :            :  **/
+     895                 :          1 : void libspdm_test_responder_set_cetificate_rsp_case11(void **state)
+     896                 :            : {
+     897                 :            :     libspdm_return_t status;
+     898                 :            :     libspdm_test_context_t *spdm_test_context;
+     899                 :            :     libspdm_context_t *spdm_context;
+     900                 :            :     size_t response_size;
+     901                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     902                 :            :     spdm_set_certificate_response_t *spdm_response;
+     903                 :            :     void *cert_chain;
+     904                 :            :     size_t cert_chain_size;
+     905                 :            :     spdm_set_certificate_request_t *m_libspdm_set_certificate_request;
+     906                 :            :     uint8_t slot_id;
+     907                 :            :     uint8_t key_pair_id;
+     908                 :            : 
+     909                 :          1 :     spdm_test_context = *state;
+     910                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     911                 :          1 :     spdm_test_context->case_id = 0xB;
+     912                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+     913                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     914                 :          1 :     slot_id = 1;
+     915                 :          1 :     key_pair_id = 1;
+     916                 :            : 
+     917                 :          1 :     spdm_context->connection_info.connection_state =
+     918                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     919                 :          1 :     spdm_context->local_context.capability.flags |=
+     920                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_CERT_CAP;
+     921                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     922                 :            :         m_libspdm_use_hash_algo;
+     923                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     924                 :            :         m_libspdm_use_asym_algo;
+     925                 :          1 :     spdm_context->connection_info.multi_key_conn_rsp = true;
+     926                 :            : 
+     927                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo =
+     928                 :            :         m_libspdm_use_hash_algo;
+     929                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo =
+     930                 :            :         m_libspdm_use_asym_algo;
+     931                 :            : 
+     932                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+     933                 :            :                                                     m_libspdm_use_asym_algo, &cert_chain,
+     934                 :            :                                                     &cert_chain_size, NULL, NULL);
+     935                 :            : 
+     936                 :          1 :     m_libspdm_set_certificate_request = malloc(sizeof(spdm_set_certificate_request_t) +
+     937                 :            :                                                cert_chain_size);
+     938                 :            : 
+     939                 :          1 :     m_libspdm_set_certificate_request->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+     940                 :          1 :     m_libspdm_set_certificate_request->header.request_response_code = SPDM_SET_CERTIFICATE;
+     941                 :          1 :     m_libspdm_set_certificate_request->header.param1 =
+     942                 :            :         slot_id | (SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT <<
+     943                 :            :                    SPDM_SET_CERTIFICATE_REQUEST_ATTRIBUTES_CERT_MODEL_OFFSET);
+     944                 :          1 :     m_libspdm_set_certificate_request->header.param2 = key_pair_id;
+     945                 :            : 
+     946                 :          1 :     libspdm_copy_mem(m_libspdm_set_certificate_request + 1,
+     947                 :            :                      LIBSPDM_MAX_CERT_CHAIN_SIZE,
+     948                 :            :                      (uint8_t *)cert_chain, cert_chain_size);
+     949                 :            : 
+     950                 :          1 :     size_t m_libspdm_set_certificate_request_size = sizeof(spdm_set_certificate_request_t) +
+     951                 :            :                                                     cert_chain_size;
+     952                 :            : 
+     953                 :          1 :     response_size = sizeof(response);
+     954                 :          1 :     status = libspdm_get_response_set_certificate(spdm_context,
+     955                 :            :                                                   m_libspdm_set_certificate_request_size,
+     956                 :            :                                                   m_libspdm_set_certificate_request,
+     957                 :            :                                                   &response_size, response);
+     958                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     959                 :          1 :     assert_int_equal(response_size, sizeof(spdm_set_certificate_response_t));
+     960                 :          1 :     spdm_response = (void *)response;
+     961                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     962                 :            :                      SPDM_SET_CERTIFICATE_RSP);
+     963                 :            : 
+     964                 :          1 :     free(cert_chain);
+     965                 :          1 :     free(m_libspdm_set_certificate_request);
+     966                 :          1 : }
+     967                 :            : 
+     968                 :            : /**
+     969                 :            :  * Test 12: Illegal combination of MULTI_KEY_CONN_RSP = true, Erase = false, and SetCertModel = 0.
+     970                 :            :  * Expected Behavior: produces SPDM_ERROR_CODE_INVALID_REQUEST message.
+     971                 :            :  **/
+     972                 :          1 : void libspdm_test_responder_set_certificate_rsp_case12(void **state)
+     973                 :            : {
+     974                 :            :     libspdm_return_t status;
+     975                 :            :     libspdm_test_context_t *spdm_test_context;
+     976                 :            :     libspdm_context_t *spdm_context;
+     977                 :            :     size_t response_size;
+     978                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     979                 :            :     spdm_set_certificate_response_t *spdm_response;
+     980                 :            :     void *cert_chain;
+     981                 :            :     size_t cert_chain_size;
+     982                 :            :     spdm_set_certificate_request_t *m_libspdm_set_certificate_request;
+     983                 :            :     uint8_t slot_id;
+     984                 :            :     uint8_t key_pair_id;
+     985                 :            : 
+     986                 :          1 :     spdm_test_context = *state;
+     987                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     988                 :          1 :     spdm_test_context->case_id = 0xc;
+     989                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+     990                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     991                 :          1 :     slot_id = 1;
+     992                 :          1 :     key_pair_id = 1;
+     993                 :            : 
+     994                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     995                 :          1 :     spdm_context->local_context.capability.flags |=
+     996                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_CERT_CAP;
+     997                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+     998                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+     999                 :          1 :     spdm_context->connection_info.multi_key_conn_rsp = true;
+    1000                 :            : 
+    1001                 :          1 :     spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+    1002                 :          1 :     spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+    1003                 :            : 
+    1004                 :          1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
+    1005                 :            :                                                     m_libspdm_use_asym_algo, &cert_chain,
+    1006                 :            :                                                     &cert_chain_size, NULL, NULL);
+    1007                 :            : 
+    1008                 :          1 :     m_libspdm_set_certificate_request = malloc(sizeof(spdm_set_certificate_request_t) +
+    1009                 :            :                                                cert_chain_size);
+    1010                 :            : 
+    1011                 :          1 :     m_libspdm_set_certificate_request->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+    1012                 :          1 :     m_libspdm_set_certificate_request->header.request_response_code = SPDM_SET_CERTIFICATE;
+    1013                 :          1 :     m_libspdm_set_certificate_request->header.param1 =
+    1014                 :            :         slot_id | (SPDM_CERTIFICATE_INFO_CERT_MODEL_NONE <<
+    1015                 :            :                    SPDM_SET_CERTIFICATE_REQUEST_ATTRIBUTES_CERT_MODEL_OFFSET);
+    1016                 :          1 :     m_libspdm_set_certificate_request->header.param2 = key_pair_id;
+    1017                 :            : 
+    1018                 :          1 :     libspdm_copy_mem(m_libspdm_set_certificate_request + 1,
+    1019                 :            :                      LIBSPDM_MAX_CERT_CHAIN_SIZE,
+    1020                 :            :                      (uint8_t *)cert_chain, cert_chain_size);
+    1021                 :            : 
+    1022                 :          1 :     size_t m_libspdm_set_certificate_request_size = sizeof(spdm_set_certificate_request_t) +
+    1023                 :            :                                                     cert_chain_size;
+    1024                 :            : 
+    1025                 :          1 :     response_size = sizeof(response);
+    1026                 :          1 :     status = libspdm_get_response_set_certificate(spdm_context,
+    1027                 :            :                                                   m_libspdm_set_certificate_request_size,
+    1028                 :            :                                                   m_libspdm_set_certificate_request,
+    1029                 :            :                                                   &response_size, response);
+    1030                 :            : 
+    1031                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+    1032                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+    1033                 :          1 :     spdm_response = (void *)response;
+    1034                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
+    1035                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
+    1036                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+    1037                 :            : 
+    1038                 :          1 :     free(cert_chain);
+    1039                 :          1 :     free(m_libspdm_set_certificate_request);
+    1040                 :          1 : }
+    1041                 :            : 
+    1042                 :            : libspdm_test_context_t m_libspdm_responder_set_certificate_rsp_test_context = {
+    1043                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+    1044                 :            :     false,
+    1045                 :            : };
+    1046                 :            : 
+    1047                 :          1 : int libspdm_responder_set_certificate_rsp_test_main(void)
+    1048                 :            : {
+    1049                 :          1 :     const struct CMUnitTest spdm_responder_set_cetificate_tests[] = {
+    1050                 :            :         /* Success Case for set_certificate to slot_id:0 with device_cert mode*/
+    1051                 :            :         cmocka_unit_test(libspdm_test_responder_set_cetificate_rsp_case1),
+    1052                 :            :         /* Bad request size*/
+    1053                 :            :         cmocka_unit_test(libspdm_test_responder_set_cetificate_rsp_case2),
+    1054                 :            :         /* response_state: LIBSPDM_RESPONSE_STATE_BUSY*/
+    1055                 :            :         cmocka_unit_test(libspdm_test_responder_set_cetificate_rsp_case3),
+    1056                 :            :         /* response_state: LIBSPDM_RESPONSE_STATE_NEED_RESYNC*/
+    1057                 :            :         cmocka_unit_test(libspdm_test_responder_set_cetificate_rsp_case4),
+    1058                 :            :         /* Success Case for set_certificate to slot_id:1 with session*/
+    1059                 :            :         cmocka_unit_test(libspdm_test_responder_set_cetificate_rsp_case5),
+    1060                 :            :         /* Responder requires a reset to complete the SET_CERTIFICATE request */
+    1061                 :            :         cmocka_unit_test(libspdm_test_responder_set_cetificate_rsp_case6),
+    1062                 :            :         /* Success Case for set_certificate to slot_id:0 with alias_cert mode*/
+    1063                 :            :         cmocka_unit_test(libspdm_test_responder_set_cetificate_rsp_case7),
+    1064                 :            :         /* Success Case for set_certificate to slot_id:1 without session and with trusted environment */
+    1065                 :            :         cmocka_unit_test(libspdm_test_responder_set_cetificate_rsp_case8),
+    1066                 :            :         /* Error Case for set_certificate to slot_id:1 without session and without trusted environment */
+    1067                 :            :         cmocka_unit_test(libspdm_test_responder_set_cetificate_rsp_case9),
+    1068                 :            :         /* Success Case for erase certificate to slot_id:1 with session*/
+    1069                 :            :         cmocka_unit_test(libspdm_test_responder_set_cetificate_rsp_case10),
+    1070                 :            :         /* Success Case for set_certificate to slot_id:1 with key_pair_id*/
+    1071                 :            :         cmocka_unit_test(libspdm_test_responder_set_cetificate_rsp_case11),
+    1072                 :            :         cmocka_unit_test(libspdm_test_responder_set_certificate_rsp_case12),
+    1073                 :            :     };
+    1074                 :            : 
+    1075                 :          1 :     libspdm_setup_test_context(&m_libspdm_responder_set_certificate_rsp_test_context);
+    1076                 :            : 
+    1077                 :          1 :     return cmocka_run_group_tests(spdm_responder_set_cetificate_tests,
+    1078                 :            :                                   libspdm_unit_test_group_setup,
+    1079                 :            :                                   libspdm_unit_test_group_teardown);
+    1080                 :            : }
+    1081                 :            : 
+    1082                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_SET_CERT_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/set_key_pair_info_ack.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_responder/set_key_pair_info_ack.c.func-sort-c.html new file mode 100644 index 00000000000..3ad414f598c --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/set_key_pair_info_ack.c.func-sort-c.html @@ -0,0 +1,97 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/set_key_pair_info_ack.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - set_key_pair_info_ack.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:245245100.0 %
Date:2024-09-22 08:21:07Functions:44100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_set_key_pair_info_ack_test_main1
libspdm_test_responder_set_key_pair_info_ack_case11
libspdm_test_responder_set_key_pair_info_ack_case21
libspdm_test_responder_set_key_pair_info_ack_case31
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/set_key_pair_info_ack.c.func.html b/coverage_log/unit_test/test_spdm_responder/set_key_pair_info_ack.c.func.html new file mode 100644 index 00000000000..1543c430bfa --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/set_key_pair_info_ack.c.func.html @@ -0,0 +1,97 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/set_key_pair_info_ack.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - set_key_pair_info_ack.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:245245100.0 %
Date:2024-09-22 08:21:07Functions:44100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_set_key_pair_info_ack_test_main1
libspdm_test_responder_set_key_pair_info_ack_case11
libspdm_test_responder_set_key_pair_info_ack_case21
libspdm_test_responder_set_key_pair_info_ack_case31
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/set_key_pair_info_ack.c.gcov.html b/coverage_log/unit_test/test_spdm_responder/set_key_pair_info_ack.c.gcov.html new file mode 100644 index 00000000000..5d8118057ba --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/set_key_pair_info_ack.c.gcov.html @@ -0,0 +1,588 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/set_key_pair_info_ack.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - set_key_pair_info_ack.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:245245100.0 %
Date:2024-09-22 08:21:07Functions:44100.0 %
Branches:00-
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2024 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_responder_lib.h"
+       9                 :            : #include "internal/libspdm_requester_lib.h"
+      10                 :            : 
+      11                 :            : #if LIBSPDM_ENABLE_CAPABILITY_SET_KEY_PAIR_INFO_CAP
+      12                 :            : 
+      13                 :            : /**
+      14                 :            :  * Test 1: Successful response to set key pair info with key pair id 4
+      15                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code, and correct response message size and fields
+      16                 :            :  **/
+      17                 :          1 : void libspdm_test_responder_set_key_pair_info_ack_case1(void **state)
+      18                 :            : {
+      19                 :            :     libspdm_return_t status;
+      20                 :            :     libspdm_test_context_t *spdm_test_context;
+      21                 :            :     libspdm_context_t *spdm_context;
+      22                 :            :     size_t response_size;
+      23                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+      24                 :            :     spdm_set_key_pair_info_ack_response_t *spdm_response;
+      25                 :            : 
+      26                 :            :     uint8_t key_pair_id;
+      27                 :            :     size_t set_key_pair_info_request_size;
+      28                 :            :     spdm_set_key_pair_info_request_t *set_key_pair_info_request;
+      29                 :            :     uint8_t *ptr;
+      30                 :            :     uint16_t desired_key_usage;
+      31                 :            :     uint32_t desired_asym_algo;
+      32                 :            :     uint8_t desired_assoc_cert_slot_mask;
+      33                 :            : 
+      34                 :          1 :     set_key_pair_info_request = malloc(sizeof(spdm_set_key_pair_info_request_t) +
+      35                 :            :                                        sizeof(uint8_t) + sizeof(uint16_t) + sizeof(uint32_t) +
+      36                 :            :                                        sizeof(uint8_t));
+      37                 :            : 
+      38                 :          1 :     spdm_test_context = *state;
+      39                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+      40                 :          1 :     spdm_test_context->case_id = 0x1;
+      41                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+      42                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+      43                 :          1 :     spdm_context->connection_info.connection_state =
+      44                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+      45                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+      46                 :            :         m_libspdm_use_asym_algo;
+      47                 :          1 :     spdm_context->local_context.capability.flags |=
+      48                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_KEY_PAIR_INFO_CAP;
+      49                 :          1 :     spdm_context->local_context.total_key_pairs = 16;
+      50                 :          1 :     key_pair_id = 4;
+      51                 :            : 
+      52                 :          1 :     response_size = sizeof(response);
+      53                 :            : 
+      54                 :            :     /*change: remove an association with slot*/
+      55                 :          1 :     set_key_pair_info_request_size =
+      56                 :            :         sizeof(spdm_set_key_pair_info_request_t) +
+      57                 :            :         sizeof(uint8_t) + sizeof(uint16_t) + sizeof(uint32_t) + sizeof(uint8_t);
+      58                 :            : 
+      59                 :          1 :     libspdm_zero_mem(set_key_pair_info_request, set_key_pair_info_request_size);
+      60                 :          1 :     set_key_pair_info_request->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+      61                 :          1 :     set_key_pair_info_request->header.request_response_code = SPDM_SET_KEY_PAIR_INFO;
+      62                 :          1 :     set_key_pair_info_request->header.param1 = SPDM_SET_KEY_PAIR_INFO_CHANGE_OPERATION;
+      63                 :          1 :     set_key_pair_info_request->header.param2 = 0;
+      64                 :          1 :     set_key_pair_info_request->key_pair_id = key_pair_id;
+      65                 :            : 
+      66                 :          1 :     status = libspdm_get_response_set_key_pair_info_ack(
+      67                 :            :         spdm_context, set_key_pair_info_request_size,
+      68                 :            :         set_key_pair_info_request, &response_size, response);
+      69                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+      70                 :          1 :     assert_int_equal(response_size,
+      71                 :            :                      sizeof(spdm_set_key_pair_info_ack_response_t));
+      72                 :          1 :     spdm_response = (void *)response;
+      73                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+      74                 :            :                      SPDM_SET_KEY_PAIR_INFO_ACK);
+      75                 :            : 
+      76                 :            :     /*erase: erase the keyusage and asymalgo*/
+      77                 :          1 :     set_key_pair_info_request->header.param1 = SPDM_SET_KEY_PAIR_INFO_ERASE_OPERATION;
+      78                 :          1 :     set_key_pair_info_request_size =
+      79                 :            :         sizeof(spdm_set_key_pair_info_request_t);
+      80                 :          1 :     status = libspdm_get_response_set_key_pair_info_ack(
+      81                 :            :         spdm_context, set_key_pair_info_request_size,
+      82                 :            :         set_key_pair_info_request, &response_size, response);
+      83                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+      84                 :          1 :     assert_int_equal(response_size,
+      85                 :            :                      sizeof(spdm_set_key_pair_info_ack_response_t));
+      86                 :          1 :     spdm_response = (void *)response;
+      87                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+      88                 :            :                      SPDM_SET_KEY_PAIR_INFO_ACK);
+      89                 :            : 
+      90                 :            :     /*generate: generate a new key pair*/
+      91                 :          1 :     desired_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+      92                 :          1 :     desired_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_ECC256;
+      93                 :          1 :     desired_assoc_cert_slot_mask = 0x08;
+      94                 :          1 :     set_key_pair_info_request_size =
+      95                 :            :         sizeof(spdm_set_key_pair_info_request_t) +
+      96                 :            :         sizeof(uint8_t) + sizeof(uint16_t) + sizeof(uint32_t) + sizeof(uint8_t);
+      97                 :            : 
+      98                 :          1 :     libspdm_zero_mem(set_key_pair_info_request, set_key_pair_info_request_size);
+      99                 :          1 :     set_key_pair_info_request->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+     100                 :          1 :     set_key_pair_info_request->header.request_response_code = SPDM_SET_KEY_PAIR_INFO;
+     101                 :          1 :     set_key_pair_info_request->header.param1 = SPDM_SET_KEY_PAIR_INFO_CHANGE_OPERATION;
+     102                 :          1 :     set_key_pair_info_request->header.param2 = 0;
+     103                 :          1 :     set_key_pair_info_request->key_pair_id = key_pair_id;
+     104                 :            : 
+     105                 :          1 :     ptr = (uint8_t*)(set_key_pair_info_request + 1);
+     106                 :          1 :     ptr += sizeof(uint8_t);
+     107                 :            : 
+     108                 :          1 :     libspdm_write_uint16(ptr, desired_key_usage);
+     109                 :          1 :     ptr += sizeof(uint16_t);
+     110                 :            : 
+     111                 :          1 :     libspdm_write_uint32(ptr, desired_asym_algo);
+     112                 :          1 :     ptr += sizeof(uint32_t);
+     113                 :            : 
+     114                 :          1 :     *ptr = desired_assoc_cert_slot_mask;
+     115                 :            : 
+     116                 :          1 :     status = libspdm_get_response_set_key_pair_info_ack(
+     117                 :            :         spdm_context, set_key_pair_info_request_size,
+     118                 :            :         set_key_pair_info_request, &response_size, response);
+     119                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     120                 :          1 :     assert_int_equal(response_size,
+     121                 :            :                      sizeof(spdm_set_key_pair_info_ack_response_t));
+     122                 :          1 :     spdm_response = (void *)response;
+     123                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     124                 :            :                      SPDM_SET_KEY_PAIR_INFO_ACK);
+     125                 :          1 :     free(set_key_pair_info_request);
+     126                 :          1 : }
+     127                 :            : 
+     128                 :            : /**
+     129                 :            :  * Test 2: Successful response to set key pair info with key pair id 4: need reset
+     130                 :            :  * Expected Behavior: get a RETURN_SUCCESS return code, and correct response message size and fields
+     131                 :            :  **/
+     132                 :          1 : void libspdm_test_responder_set_key_pair_info_ack_case2(void **state)
+     133                 :            : {
+     134                 :            :     libspdm_return_t status;
+     135                 :            :     libspdm_test_context_t *spdm_test_context;
+     136                 :            :     libspdm_context_t *spdm_context;
+     137                 :            :     size_t response_size;
+     138                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     139                 :            :     spdm_set_key_pair_info_ack_response_t *spdm_response;
+     140                 :            : 
+     141                 :            :     uint8_t key_pair_id;
+     142                 :            :     size_t set_key_pair_info_request_size;
+     143                 :            :     spdm_set_key_pair_info_request_t *set_key_pair_info_request;
+     144                 :            :     uint8_t *ptr;
+     145                 :            :     uint16_t desired_key_usage;
+     146                 :            :     uint32_t desired_asym_algo;
+     147                 :            :     uint8_t desired_assoc_cert_slot_mask;
+     148                 :            : 
+     149                 :          1 :     set_key_pair_info_request = malloc(sizeof(spdm_set_key_pair_info_request_t) +
+     150                 :            :                                        sizeof(uint8_t) + sizeof(uint16_t) + sizeof(uint32_t) +
+     151                 :            :                                        sizeof(uint8_t));
+     152                 :            : 
+     153                 :          1 :     spdm_test_context = *state;
+     154                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     155                 :          1 :     spdm_test_context->case_id = 0x2;
+     156                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+     157                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     158                 :          1 :     spdm_context->connection_info.connection_state =
+     159                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     160                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     161                 :            :         m_libspdm_use_asym_algo;
+     162                 :          1 :     spdm_context->local_context.capability.flags |=
+     163                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_KEY_PAIR_INFO_CAP;
+     164                 :          1 :     spdm_context->local_context.total_key_pairs = 16;
+     165                 :          1 :     key_pair_id = 4;
+     166                 :            : 
+     167                 :            :     /*set responder need reset*/
+     168                 :          1 :     spdm_context->local_context.capability.flags |=
+     169                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_INSTALL_RESET_CAP;
+     170                 :            : 
+     171                 :          1 :     response_size = sizeof(response);
+     172                 :            : 
+     173                 :            :     /*Before reset, change: remove an association with slot*/
+     174                 :          1 :     set_key_pair_info_request_size =
+     175                 :            :         sizeof(spdm_set_key_pair_info_request_t) +
+     176                 :            :         sizeof(uint8_t) + sizeof(uint16_t) + sizeof(uint32_t) + sizeof(uint8_t);
+     177                 :            : 
+     178                 :          1 :     libspdm_zero_mem(set_key_pair_info_request, set_key_pair_info_request_size);
+     179                 :          1 :     set_key_pair_info_request->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+     180                 :          1 :     set_key_pair_info_request->header.request_response_code = SPDM_SET_KEY_PAIR_INFO;
+     181                 :          1 :     set_key_pair_info_request->header.param1 = SPDM_SET_KEY_PAIR_INFO_CHANGE_OPERATION;
+     182                 :          1 :     set_key_pair_info_request->header.param2 = 0;
+     183                 :          1 :     set_key_pair_info_request->key_pair_id = key_pair_id;
+     184                 :            : 
+     185                 :          1 :     status = libspdm_get_response_set_key_pair_info_ack(
+     186                 :            :         spdm_context, set_key_pair_info_request_size,
+     187                 :            :         set_key_pair_info_request, &response_size, response);
+     188                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     189                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     190                 :          1 :     spdm_response = (void *)response;
+     191                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     192                 :            :                      SPDM_ERROR);
+     193                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     194                 :            :                      SPDM_ERROR_CODE_RESET_REQUIRED);
+     195                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     196                 :            : 
+     197                 :            :     /*After reset, change: remove an association with slot*/
+     198                 :          1 :     status = libspdm_get_response_set_key_pair_info_ack(
+     199                 :            :         spdm_context, set_key_pair_info_request_size,
+     200                 :            :         set_key_pair_info_request, &response_size, response);
+     201                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     202                 :          1 :     assert_int_equal(response_size,
+     203                 :            :                      sizeof(spdm_set_key_pair_info_ack_response_t));
+     204                 :          1 :     spdm_response = (void *)response;
+     205                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     206                 :            :                      SPDM_SET_KEY_PAIR_INFO_ACK);
+     207                 :            : 
+     208                 :            :     /*Before reset, erase: erase the keyusage and asymalgo*/
+     209                 :          1 :     set_key_pair_info_request->header.param1 = SPDM_SET_KEY_PAIR_INFO_ERASE_OPERATION;
+     210                 :          1 :     set_key_pair_info_request_size =
+     211                 :            :         sizeof(spdm_set_key_pair_info_request_t);
+     212                 :          1 :     status = libspdm_get_response_set_key_pair_info_ack(
+     213                 :            :         spdm_context, set_key_pair_info_request_size,
+     214                 :            :         set_key_pair_info_request, &response_size, response);
+     215                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     216                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     217                 :          1 :     spdm_response = (void *)response;
+     218                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     219                 :            :                      SPDM_ERROR);
+     220                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     221                 :            :                      SPDM_ERROR_CODE_RESET_REQUIRED);
+     222                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     223                 :            : 
+     224                 :            :     /*After reset, erase: erase the keyusage and asymalgo*/
+     225                 :          1 :     status = libspdm_get_response_set_key_pair_info_ack(
+     226                 :            :         spdm_context, set_key_pair_info_request_size,
+     227                 :            :         set_key_pair_info_request, &response_size, response);
+     228                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     229                 :          1 :     assert_int_equal(response_size,
+     230                 :            :                      sizeof(spdm_set_key_pair_info_ack_response_t));
+     231                 :          1 :     spdm_response = (void *)response;
+     232                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     233                 :            :                      SPDM_SET_KEY_PAIR_INFO_ACK);
+     234                 :            : 
+     235                 :            : 
+     236                 :            :     /*Before reset, generate: generate a new key pair*/
+     237                 :          1 :     desired_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+     238                 :          1 :     desired_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_ECC256;
+     239                 :          1 :     desired_assoc_cert_slot_mask = 0x08;
+     240                 :          1 :     set_key_pair_info_request_size =
+     241                 :            :         sizeof(spdm_set_key_pair_info_request_t) +
+     242                 :            :         sizeof(uint8_t) + sizeof(uint16_t) + sizeof(uint32_t) + sizeof(uint8_t);
+     243                 :            : 
+     244                 :          1 :     libspdm_zero_mem(set_key_pair_info_request, set_key_pair_info_request_size);
+     245                 :          1 :     set_key_pair_info_request->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+     246                 :          1 :     set_key_pair_info_request->header.request_response_code = SPDM_SET_KEY_PAIR_INFO;
+     247                 :          1 :     set_key_pair_info_request->header.param1 = SPDM_SET_KEY_PAIR_INFO_CHANGE_OPERATION;
+     248                 :          1 :     set_key_pair_info_request->header.param2 = 0;
+     249                 :          1 :     set_key_pair_info_request->key_pair_id = key_pair_id;
+     250                 :            : 
+     251                 :          1 :     ptr = (uint8_t*)(set_key_pair_info_request + 1);
+     252                 :          1 :     ptr += sizeof(uint8_t);
+     253                 :            : 
+     254                 :          1 :     libspdm_write_uint16(ptr, desired_key_usage);
+     255                 :          1 :     ptr += sizeof(uint16_t);
+     256                 :            : 
+     257                 :          1 :     libspdm_write_uint32(ptr, desired_asym_algo);
+     258                 :          1 :     ptr += sizeof(uint32_t);
+     259                 :            : 
+     260                 :          1 :     *ptr = desired_assoc_cert_slot_mask;
+     261                 :            : 
+     262                 :          1 :     status = libspdm_get_response_set_key_pair_info_ack(
+     263                 :            :         spdm_context, set_key_pair_info_request_size,
+     264                 :            :         set_key_pair_info_request, &response_size, response);
+     265                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     266                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     267                 :          1 :     spdm_response = (void *)response;
+     268                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     269                 :            :                      SPDM_ERROR);
+     270                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     271                 :            :                      SPDM_ERROR_CODE_RESET_REQUIRED);
+     272                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     273                 :            : 
+     274                 :            :     /*After reset, generate: generate a new key pair*/
+     275                 :          1 :     status = libspdm_get_response_set_key_pair_info_ack(
+     276                 :            :         spdm_context, set_key_pair_info_request_size,
+     277                 :            :         set_key_pair_info_request, &response_size, response);
+     278                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     279                 :          1 :     assert_int_equal(response_size,
+     280                 :            :                      sizeof(spdm_set_key_pair_info_ack_response_t));
+     281                 :          1 :     spdm_response = (void *)response;
+     282                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     283                 :            :                      SPDM_SET_KEY_PAIR_INFO_ACK);
+     284                 :          1 :     free(set_key_pair_info_request);
+     285                 :          1 : }
+     286                 :            : 
+     287                 :            : /**
+     288                 :            :  * Test 2: The collection of multiple sub-cases.
+     289                 :            :  **/
+     290                 :          1 : void libspdm_test_responder_set_key_pair_info_ack_case3(void **state)
+     291                 :            : {
+     292                 :            :     libspdm_return_t status;
+     293                 :            :     libspdm_test_context_t *spdm_test_context;
+     294                 :            :     libspdm_context_t *spdm_context;
+     295                 :            :     size_t response_size;
+     296                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     297                 :            :     spdm_set_key_pair_info_ack_response_t *spdm_response;
+     298                 :            : 
+     299                 :            :     uint8_t key_pair_id;
+     300                 :            :     size_t set_key_pair_info_request_size;
+     301                 :            :     spdm_set_key_pair_info_request_t *set_key_pair_info_request;
+     302                 :            :     uint8_t *ptr;
+     303                 :            :     uint16_t desired_key_usage;
+     304                 :            :     uint32_t desired_asym_algo;
+     305                 :            :     uint8_t desired_assoc_cert_slot_mask;
+     306                 :            : 
+     307                 :            :     uint8_t temp_buf[LIBSPDM_RECEIVER_BUFFER_SIZE];
+     308                 :          1 :     set_key_pair_info_request = (spdm_set_key_pair_info_request_t *)temp_buf;
+     309                 :            : 
+     310                 :          1 :     spdm_test_context = *state;
+     311                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     312                 :          1 :     spdm_test_context->case_id = 0x3;
+     313                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+     314                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     315                 :          1 :     spdm_context->connection_info.connection_state =
+     316                 :            :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     317                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo =
+     318                 :            :         m_libspdm_use_asym_algo;
+     319                 :          1 :     spdm_context->local_context.capability.flags |=
+     320                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_KEY_PAIR_INFO_CAP;
+     321                 :          1 :     spdm_context->local_context.total_key_pairs = 16;
+     322                 :          1 :     key_pair_id = 4;
+     323                 :            : 
+     324                 :            :     /*set responder need reset*/
+     325                 :          1 :     spdm_context->local_context.capability.flags |=
+     326                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_INSTALL_RESET_CAP;
+     327                 :            : 
+     328                 :            :     /*Before reset, change: remove an association with slot*/
+     329                 :          1 :     set_key_pair_info_request_size =
+     330                 :            :         sizeof(spdm_set_key_pair_info_request_t) +
+     331                 :            :         sizeof(uint8_t) + sizeof(uint16_t) + sizeof(uint32_t) + sizeof(uint8_t);
+     332                 :            : 
+     333                 :          1 :     libspdm_zero_mem(set_key_pair_info_request, set_key_pair_info_request_size);
+     334                 :          1 :     set_key_pair_info_request->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+     335                 :          1 :     set_key_pair_info_request->header.request_response_code = SPDM_SET_KEY_PAIR_INFO;
+     336                 :          1 :     set_key_pair_info_request->header.param1 = SPDM_SET_KEY_PAIR_INFO_CHANGE_OPERATION;
+     337                 :          1 :     set_key_pair_info_request->header.param2 = 0;
+     338                 :          1 :     set_key_pair_info_request->key_pair_id = key_pair_id;
+     339                 :            : 
+     340                 :          1 :     response_size = sizeof(response);
+     341                 :          1 :     status = libspdm_get_response_set_key_pair_info_ack(
+     342                 :            :         spdm_context, set_key_pair_info_request_size,
+     343                 :            :         set_key_pair_info_request, &response_size, response);
+     344                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     345                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     346                 :          1 :     spdm_response = (void *)response;
+     347                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     348                 :            :                      SPDM_ERROR);
+     349                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     350                 :            :                      SPDM_ERROR_CODE_RESET_REQUIRED);
+     351                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     352                 :            : 
+     353                 :            :     /* Sub Case 1: If KeyPairErase is set, all fields after the KeyPairID field in this request should not exist. */
+     354                 :          1 :     desired_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+     355                 :          1 :     desired_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_ECC256;
+     356                 :          1 :     desired_assoc_cert_slot_mask = 0x08;
+     357                 :          1 :     set_key_pair_info_request_size =
+     358                 :            :         sizeof(spdm_set_key_pair_info_request_t) +
+     359                 :            :         sizeof(uint8_t) + sizeof(uint16_t) + sizeof(uint32_t) + sizeof(uint8_t);
+     360                 :            : 
+     361                 :          1 :     libspdm_zero_mem(set_key_pair_info_request, set_key_pair_info_request_size);
+     362                 :          1 :     set_key_pair_info_request->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+     363                 :          1 :     set_key_pair_info_request->header.request_response_code = SPDM_SET_KEY_PAIR_INFO;
+     364                 :          1 :     set_key_pair_info_request->header.param1 = SPDM_SET_KEY_PAIR_INFO_ERASE_OPERATION;
+     365                 :          1 :     set_key_pair_info_request->header.param2 = 0;
+     366                 :          1 :     set_key_pair_info_request->key_pair_id = key_pair_id;
+     367                 :            : 
+     368                 :          1 :     ptr = (uint8_t*)(set_key_pair_info_request + 1);
+     369                 :          1 :     ptr += sizeof(uint8_t);
+     370                 :            : 
+     371                 :          1 :     libspdm_write_uint16(ptr, desired_key_usage);
+     372                 :          1 :     ptr += sizeof(uint16_t);
+     373                 :            : 
+     374                 :          1 :     libspdm_write_uint32(ptr, desired_asym_algo);
+     375                 :          1 :     ptr += sizeof(uint32_t);
+     376                 :            : 
+     377                 :          1 :     *ptr = desired_assoc_cert_slot_mask;
+     378                 :            : 
+     379                 :          1 :     response_size = sizeof(response);
+     380                 :          1 :     status = libspdm_get_response_set_key_pair_info_ack(
+     381                 :            :         spdm_context, set_key_pair_info_request_size,
+     382                 :            :         set_key_pair_info_request, &response_size, response);
+     383                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     384                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     385                 :          1 :     spdm_response = (void *)response;
+     386                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     387                 :            :                      SPDM_ERROR);
+     388                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     389                 :            :                      SPDM_ERROR_CODE_OPERATION_FAILED);
+     390                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     391                 :            : 
+     392                 :            :     /*Sub Case 2: When GenerateKeyPair is set, the fields of DesiredKeyUsage, DesiredAsymAlgo and DesiredAssocCertSlotMask should exist. */
+     393                 :          1 :     set_key_pair_info_request_size =
+     394                 :            :         sizeof(spdm_set_key_pair_info_request_t);
+     395                 :            : 
+     396                 :          1 :     libspdm_zero_mem(set_key_pair_info_request, set_key_pair_info_request_size);
+     397                 :          1 :     set_key_pair_info_request->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+     398                 :          1 :     set_key_pair_info_request->header.request_response_code = SPDM_SET_KEY_PAIR_INFO;
+     399                 :          1 :     set_key_pair_info_request->header.param1 = SPDM_SET_KEY_PAIR_INFO_GENERATE_OPERATION;
+     400                 :          1 :     set_key_pair_info_request->header.param2 = 0;
+     401                 :          1 :     set_key_pair_info_request->key_pair_id = key_pair_id;
+     402                 :            : 
+     403                 :          1 :     response_size = sizeof(response);
+     404                 :          1 :     status = libspdm_get_response_set_key_pair_info_ack(
+     405                 :            :         spdm_context, set_key_pair_info_request_size,
+     406                 :            :         set_key_pair_info_request, &response_size, response);
+     407                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     408                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     409                 :          1 :     spdm_response = (void *)response;
+     410                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     411                 :            :                      SPDM_ERROR);
+     412                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     413                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+     414                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     415                 :            : 
+     416                 :            :     /*Sub Case 3: key_pair_id = 0 */
+     417                 :          1 :     set_key_pair_info_request_size =
+     418                 :            :         sizeof(spdm_set_key_pair_info_request_t);
+     419                 :            : 
+     420                 :          1 :     libspdm_zero_mem(set_key_pair_info_request, set_key_pair_info_request_size);
+     421                 :          1 :     set_key_pair_info_request->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+     422                 :          1 :     set_key_pair_info_request->header.request_response_code = SPDM_SET_KEY_PAIR_INFO;
+     423                 :          1 :     set_key_pair_info_request->header.param1 = SPDM_SET_KEY_PAIR_INFO_GENERATE_OPERATION;
+     424                 :          1 :     set_key_pair_info_request->header.param2 = 0;
+     425                 :          1 :     set_key_pair_info_request->key_pair_id = 0;
+     426                 :            : 
+     427                 :          1 :     response_size = sizeof(response);
+     428                 :          1 :     status = libspdm_get_response_set_key_pair_info_ack(
+     429                 :            :         spdm_context, set_key_pair_info_request_size,
+     430                 :            :         set_key_pair_info_request, &response_size, response);
+     431                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     432                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     433                 :          1 :     spdm_response = (void *)response;
+     434                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     435                 :            :                      SPDM_ERROR);
+     436                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     437                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+     438                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     439                 :            : 
+     440                 :            :     /* Sub Case 4: DesiredAsymAlgo must not have multiple bits set. */
+     441                 :          1 :     desired_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
+     442                 :          1 :     desired_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_ECC256 |
+     443                 :            :                         SPDM_KEY_PAIR_ASYM_ALGO_CAP_ECC384;
+     444                 :          1 :     desired_assoc_cert_slot_mask = 0x08;
+     445                 :          1 :     set_key_pair_info_request_size =
+     446                 :            :         sizeof(spdm_set_key_pair_info_request_t) +
+     447                 :            :         sizeof(uint8_t) + sizeof(uint16_t) + sizeof(uint32_t) + sizeof(uint8_t);
+     448                 :            : 
+     449                 :          1 :     libspdm_zero_mem(set_key_pair_info_request, set_key_pair_info_request_size);
+     450                 :          1 :     set_key_pair_info_request->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+     451                 :          1 :     set_key_pair_info_request->header.request_response_code = SPDM_SET_KEY_PAIR_INFO;
+     452                 :          1 :     set_key_pair_info_request->header.param1 = SPDM_SET_KEY_PAIR_INFO_CHANGE_OPERATION;
+     453                 :          1 :     set_key_pair_info_request->header.param2 = 0;
+     454                 :          1 :     set_key_pair_info_request->key_pair_id = key_pair_id;
+     455                 :            : 
+     456                 :          1 :     ptr = (uint8_t*)(set_key_pair_info_request + 1);
+     457                 :          1 :     ptr += sizeof(uint8_t);
+     458                 :            : 
+     459                 :          1 :     libspdm_write_uint16(ptr, desired_key_usage);
+     460                 :          1 :     ptr += sizeof(uint16_t);
+     461                 :            : 
+     462                 :          1 :     libspdm_write_uint32(ptr, desired_asym_algo);
+     463                 :          1 :     ptr += sizeof(uint32_t);
+     464                 :            : 
+     465                 :          1 :     *ptr = desired_assoc_cert_slot_mask;
+     466                 :            : 
+     467                 :          1 :     response_size = sizeof(response);
+     468                 :          1 :     status = libspdm_get_response_set_key_pair_info_ack(
+     469                 :            :         spdm_context, set_key_pair_info_request_size,
+     470                 :            :         set_key_pair_info_request, &response_size, response);
+     471                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     472                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     473                 :          1 :     spdm_response = (void *)response;
+     474                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     475                 :            :                      SPDM_ERROR);
+     476                 :          1 :     assert_int_equal(spdm_response->header.param1,
+     477                 :            :                      SPDM_ERROR_CODE_INVALID_REQUEST);
+     478                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     479                 :          1 : }
+     480                 :            : 
+     481                 :          1 : int libspdm_responder_set_key_pair_info_ack_test_main(void)
+     482                 :            : {
+     483                 :          1 :     const struct CMUnitTest spdm_responder_set_key_pair_info_ack_tests[] = {
+     484                 :            :         /* Success Case to set key pair info*/
+     485                 :            :         cmocka_unit_test(libspdm_test_responder_set_key_pair_info_ack_case1),
+     486                 :            :         /* Success Case to set key pair info with reset*/
+     487                 :            :         cmocka_unit_test(libspdm_test_responder_set_key_pair_info_ack_case2),
+     488                 :            :         /* The collection of multiple sub-cases.*/
+     489                 :            :         cmocka_unit_test(libspdm_test_responder_set_key_pair_info_ack_case3),
+     490                 :            :     };
+     491                 :            : 
+     492                 :          1 :     libspdm_test_context_t test_context = {
+     493                 :            :         LIBSPDM_TEST_CONTEXT_VERSION,
+     494                 :            :         false,
+     495                 :            :     };
+     496                 :          1 :     libspdm_setup_test_context(&test_context);
+     497                 :            : 
+     498                 :          1 :     return cmocka_run_group_tests(spdm_responder_set_key_pair_info_ack_tests,
+     499                 :            :                                   libspdm_unit_test_group_setup,
+     500                 :            :                                   libspdm_unit_test_group_teardown);
+     501                 :            : }
+     502                 :            : 
+     503                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_SET_KEY_PAIR_INFO_CAP*/
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/subscribe_event_types_ack.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_responder/subscribe_event_types_ack.c.func-sort-c.html new file mode 100644 index 00000000000..9247539e6a4 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/subscribe_event_types_ack.c.func-sort-c.html @@ -0,0 +1,97 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/subscribe_event_types_ack.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - subscribe_event_types_ack.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:7373100.0 %
Date:2024-09-22 08:21:07Functions:44100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_subscribe_event_types_ack_test_main1
libspdm_test_responder_subscribe_event_types_ack_case11
libspdm_test_responder_subscribe_event_types_ack_case21
set_standard_state2
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/subscribe_event_types_ack.c.func.html b/coverage_log/unit_test/test_spdm_responder/subscribe_event_types_ack.c.func.html new file mode 100644 index 00000000000..63d075a1a67 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/subscribe_event_types_ack.c.func.html @@ -0,0 +1,97 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/subscribe_event_types_ack.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - subscribe_event_types_ack.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:7373100.0 %
Date:2024-09-22 08:21:07Functions:44100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_subscribe_event_types_ack_test_main1
libspdm_test_responder_subscribe_event_types_ack_case11
libspdm_test_responder_subscribe_event_types_ack_case21
set_standard_state2
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/subscribe_event_types_ack.c.gcov.html b/coverage_log/unit_test/test_spdm_responder/subscribe_event_types_ack.c.gcov.html new file mode 100644 index 00000000000..9b235f12e93 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/subscribe_event_types_ack.c.gcov.html @@ -0,0 +1,250 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/subscribe_event_types_ack.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - subscribe_event_types_ack.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:7373100.0 %
Date:2024-09-22 08:21:07Functions:44100.0 %
Branches:00-
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2024 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_responder_lib.h"
+       9                 :            : 
+      10                 :            : #if LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP
+      11                 :            : 
+      12                 :          2 : static void set_standard_state(libspdm_context_t *spdm_context)
+      13                 :            : {
+      14                 :            :     libspdm_session_info_t *session_info;
+      15                 :            :     uint32_t session_id;
+      16                 :            : 
+      17                 :          2 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+      18                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+      19                 :          2 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+      20                 :          2 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+      21                 :            : 
+      22                 :          2 :     spdm_context->connection_info.capability.flags |=
+      23                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EVENT_CAP;
+      24                 :          2 :     spdm_context->connection_info.capability.flags |=
+      25                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+      26                 :          2 :     spdm_context->connection_info.capability.flags |=
+      27                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+      28                 :          2 :     spdm_context->connection_info.capability.flags |=
+      29                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+      30                 :            : 
+      31                 :          2 :     spdm_context->local_context.capability.flags |=
+      32                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+      33                 :          2 :     spdm_context->local_context.capability.flags |=
+      34                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+      35                 :          2 :     spdm_context->local_context.capability.flags |=
+      36                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+      37                 :          2 :     spdm_context->local_context.capability.flags |=
+      38                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EVENT_CAP;
+      39                 :            : 
+      40                 :          2 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+      41                 :          2 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+      42                 :          2 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+      43                 :          2 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+      44                 :            : 
+      45                 :          2 :     session_id = 0xFFFFFFFF;
+      46                 :          2 :     spdm_context->latest_session_id = session_id;
+      47                 :          2 :     spdm_context->last_spdm_request_session_id_valid = true;
+      48                 :          2 :     spdm_context->last_spdm_request_session_id = session_id;
+      49                 :          2 :     session_info = &spdm_context->session_info[0];
+      50                 :          2 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+      51                 :          2 :     libspdm_secured_message_set_session_state(
+      52                 :            :         session_info->secured_message_context,
+      53                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+      54                 :          2 : }
+      55                 :            : 
+      56                 :            : /**
+      57                 :            :  * Test 1: Successful response to subscribe event types that clears all events.
+      58                 :            :  * Expected Behavior: Returns LIBSPDM_STATUS_SUCCESS with the expected values.
+      59                 :            :  **/
+      60                 :          1 : static void libspdm_test_responder_subscribe_event_types_ack_case1(void **state)
+      61                 :            : {
+      62                 :            :     libspdm_return_t status;
+      63                 :            :     libspdm_test_context_t *spdm_test_context;
+      64                 :            :     libspdm_context_t *spdm_context;
+      65                 :            :     spdm_subscribe_event_types_request_t spdm_request;
+      66                 :            :     size_t spdm_request_size;
+      67                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+      68                 :          1 :     size_t response_size = sizeof(response);
+      69                 :            :     spdm_subscribe_event_types_ack_response_t *spdm_response;
+      70                 :            : 
+      71                 :          1 :     spdm_test_context = *state;
+      72                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+      73                 :          1 :     spdm_test_context->case_id = 1;
+      74                 :            : 
+      75                 :          1 :     set_standard_state(spdm_context);
+      76                 :            : 
+      77                 :          1 :     spdm_request.header.spdm_version = SPDM_MESSAGE_VERSION_13;
+      78                 :          1 :     spdm_request.header.request_response_code = SPDM_SUBSCRIBE_EVENT_TYPES;
+      79                 :          1 :     spdm_request.header.param1 = 0;
+      80                 :          1 :     spdm_request.header.param2 = 0;
+      81                 :            : 
+      82                 :          1 :     spdm_request_size = sizeof(spdm_message_header_t);
+      83                 :            : 
+      84                 :          1 :     status = libspdm_get_response_subscribe_event_types_ack(spdm_context,
+      85                 :            :                                                             spdm_request_size, &spdm_request,
+      86                 :            :                                                             &response_size, response);
+      87                 :          1 :     spdm_response = (spdm_subscribe_event_types_ack_response_t *)response;
+      88                 :            : 
+      89                 :          1 :     assert_int_equal(response_size, sizeof(spdm_subscribe_event_types_ack_response_t));
+      90                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+      91                 :          1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_13);
+      92                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_SUBSCRIBE_EVENT_TYPES_ACK);
+      93                 :          1 :     assert_int_equal(spdm_response->header.param1, 0);
+      94                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+      95                 :          1 : }
+      96                 :            : 
+      97                 :            : /**
+      98                 :            :  * Test 2: Successful response to subscribe event types that subscribes to two events.
+      99                 :            :  * Expected Behavior: Returns LIBSPDM_STATUS_SUCCESS with the expected values.
+     100                 :            :  **/
+     101                 :          1 : static void libspdm_test_responder_subscribe_event_types_ack_case2(void **state)
+     102                 :            : {
+     103                 :            :     libspdm_return_t status;
+     104                 :            :     libspdm_test_context_t *spdm_test_context;
+     105                 :            :     libspdm_context_t *spdm_context;
+     106                 :            :     spdm_subscribe_event_types_request_t *spdm_request;
+     107                 :            :     uint8_t request[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     108                 :            :     size_t spdm_request_size;
+     109                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     110                 :          1 :     size_t response_size = sizeof(response);
+     111                 :            :     spdm_subscribe_event_types_ack_response_t *spdm_response;
+     112                 :            : 
+     113                 :          1 :     spdm_test_context = *state;
+     114                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     115                 :          1 :     spdm_test_context->case_id = 2;
+     116                 :            : 
+     117                 :          1 :     set_standard_state(spdm_context);
+     118                 :            : 
+     119                 :          1 :     spdm_request = (spdm_subscribe_event_types_request_t *)request;
+     120                 :            : 
+     121                 :          1 :     spdm_request->header.spdm_version = SPDM_MESSAGE_VERSION_13;
+     122                 :          1 :     spdm_request->header.request_response_code = SPDM_SUBSCRIBE_EVENT_TYPES;
+     123                 :          1 :     spdm_request->header.param1 = 1;
+     124                 :          1 :     spdm_request->header.param2 = 0;
+     125                 :          1 :     spdm_request->subscribe_list_len = 0;
+     126                 :            : 
+     127                 :          1 :     generate_dmtf_event_group(spdm_request + 1, (uint8_t *)&spdm_request->subscribe_list_len,
+     128                 :            :                               0, true, true, false, false);
+     129                 :            : 
+     130                 :          1 :     spdm_request_size = sizeof(spdm_subscribe_event_types_request_t) +
+     131                 :          1 :                         spdm_request->subscribe_list_len;
+     132                 :            : 
+     133                 :          1 :     status = libspdm_get_response_subscribe_event_types_ack(spdm_context,
+     134                 :            :                                                             spdm_request_size, spdm_request,
+     135                 :            :                                                             &response_size, response);
+     136                 :          1 :     spdm_response = (spdm_subscribe_event_types_ack_response_t *)response;
+     137                 :            : 
+     138                 :          1 :     assert_int_equal(response_size, sizeof(spdm_subscribe_event_types_ack_response_t));
+     139                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     140                 :          1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_13);
+     141                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_SUBSCRIBE_EVENT_TYPES_ACK);
+     142                 :          1 :     assert_int_equal(spdm_response->header.param1, 0);
+     143                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     144                 :          1 : }
+     145                 :            : 
+     146                 :          1 : int libspdm_responder_subscribe_event_types_ack_test_main(void)
+     147                 :            : {
+     148                 :          1 :     libspdm_test_context_t test_context = {
+     149                 :            :         LIBSPDM_TEST_CONTEXT_VERSION,
+     150                 :            :         false,
+     151                 :            :     };
+     152                 :            : 
+     153                 :          1 :     const struct CMUnitTest spdm_responder_subscribe_event_types_ack_tests[] = {
+     154                 :            :         cmocka_unit_test(libspdm_test_responder_subscribe_event_types_ack_case1),
+     155                 :            :         cmocka_unit_test(libspdm_test_responder_subscribe_event_types_ack_case2)
+     156                 :            :     };
+     157                 :            : 
+     158                 :          1 :     libspdm_setup_test_context(&test_context);
+     159                 :            : 
+     160                 :          1 :     return cmocka_run_group_tests(spdm_responder_subscribe_event_types_ack_tests,
+     161                 :            :                                   libspdm_unit_test_group_setup,
+     162                 :            :                                   libspdm_unit_test_group_teardown);
+     163                 :            : }
+     164                 :            : 
+     165                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/supported_event_types.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_responder/supported_event_types.c.func-sort-c.html new file mode 100644 index 00000000000..66d979793a5 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/supported_event_types.c.func-sort-c.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/supported_event_types.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - supported_event_types.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:5353100.0 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:22100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_supported_event_types_test_main1
libspdm_test_responder_supported_event_types_case11
set_standard_state1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/supported_event_types.c.func.html b/coverage_log/unit_test/test_spdm_responder/supported_event_types.c.func.html new file mode 100644 index 00000000000..9dd6257e97f --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/supported_event_types.c.func.html @@ -0,0 +1,93 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/supported_event_types.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - supported_event_types.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:5353100.0 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:22100.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_supported_event_types_test_main1
libspdm_test_responder_supported_event_types_case11
set_standard_state1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/supported_event_types.c.gcov.html b/coverage_log/unit_test/test_spdm_responder/supported_event_types.c.gcov.html new file mode 100644 index 00000000000..c604452cac5 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/supported_event_types.c.gcov.html @@ -0,0 +1,209 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/supported_event_types.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - supported_event_types.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:5353100.0 %
Date:2024-09-22 08:21:07Functions:33100.0 %
Branches:22100.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2024 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_responder_lib.h"
+       9                 :            : 
+      10                 :            : #if LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP
+      11                 :            : 
+      12                 :            : extern uint32_t g_supported_event_groups_list_len;
+      13                 :            : extern uint8_t g_event_group_count;
+      14                 :            : 
+      15                 :          1 : static void set_standard_state(libspdm_context_t *spdm_context)
+      16                 :            : {
+      17                 :            :     libspdm_session_info_t *session_info;
+      18                 :            :     uint32_t session_id;
+      19                 :            : 
+      20                 :          1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
+      21                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+      22                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+      23                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+      24                 :            : 
+      25                 :          1 :     spdm_context->connection_info.capability.flags |=
+      26                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EVENT_CAP;
+      27                 :          1 :     spdm_context->connection_info.capability.flags |=
+      28                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+      29                 :          1 :     spdm_context->connection_info.capability.flags |=
+      30                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+      31                 :          1 :     spdm_context->connection_info.capability.flags |=
+      32                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+      33                 :            : 
+      34                 :          1 :     spdm_context->local_context.capability.flags |=
+      35                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
+      36                 :          1 :     spdm_context->local_context.capability.flags |=
+      37                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
+      38                 :          1 :     spdm_context->local_context.capability.flags |=
+      39                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
+      40                 :          1 :     spdm_context->local_context.capability.flags |=
+      41                 :            :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EVENT_CAP;
+      42                 :            : 
+      43                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
+      44                 :          1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
+      45                 :          1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
+      46                 :          1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
+      47                 :            : 
+      48                 :          1 :     session_id = 0xFFFFFFFF;
+      49                 :          1 :     spdm_context->latest_session_id = session_id;
+      50                 :          1 :     spdm_context->last_spdm_request_session_id_valid = true;
+      51                 :          1 :     spdm_context->last_spdm_request_session_id = session_id;
+      52                 :          1 :     session_info = &spdm_context->session_info[0];
+      53                 :          1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
+      54                 :          1 :     libspdm_secured_message_set_session_state(
+      55                 :            :         session_info->secured_message_context,
+      56                 :            :         LIBSPDM_SESSION_STATE_ESTABLISHED);
+      57                 :          1 : }
+      58                 :            : 
+      59                 :            : /**
+      60                 :            :  * Test 1: Successful response to get supported event types.
+      61                 :            :  * Expected Behavior: Returns LIBSPDM_STATUS_SUCCESS with the expected values.
+      62                 :            :  **/
+      63                 :          1 : static void libspdm_test_responder_supported_event_types_case1(void **state)
+      64                 :            : {
+      65                 :            :     libspdm_return_t status;
+      66                 :            :     libspdm_test_context_t *spdm_test_context;
+      67                 :            :     libspdm_context_t *spdm_context;
+      68                 :            :     spdm_get_supported_event_types_request_t spdm_request;
+      69                 :          1 :     size_t spdm_request_size = sizeof(spdm_request);
+      70                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+      71                 :          1 :     size_t response_size = sizeof(response);
+      72                 :            :     spdm_supported_event_types_response_t *spdm_response;
+      73                 :            : 
+      74                 :          1 :     spdm_test_context = *state;
+      75                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+      76                 :          1 :     spdm_test_context->case_id = 1;
+      77                 :            : 
+      78                 :          1 :     set_standard_state(spdm_context);
+      79                 :            : 
+      80                 :          1 :     spdm_request.header.spdm_version = SPDM_MESSAGE_VERSION_13;
+      81                 :          1 :     spdm_request.header.request_response_code = SPDM_GET_SUPPORTED_EVENT_TYPES;
+      82                 :          1 :     spdm_request.header.param1 = 0;
+      83                 :          1 :     spdm_request.header.param2 = 0;
+      84                 :            : 
+      85                 :          1 :     status = libspdm_get_response_supported_event_types(spdm_context,
+      86                 :            :                                                         spdm_request_size, &spdm_request,
+      87                 :            :                                                         &response_size, response);
+      88                 :          1 :     spdm_response = (spdm_supported_event_types_response_t *)response;
+      89                 :            : 
+      90                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+      91                 :          1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_13);
+      92                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_SUPPORTED_EVENT_TYPES);
+      93                 :          1 :     assert_int_equal(spdm_response->header.param1, g_event_group_count);
+      94                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+      95                 :          1 :     assert_int_equal(spdm_response->supported_event_groups_list_len,
+      96                 :            :                      g_supported_event_groups_list_len);
+      97         [ +  + ]:          9 :     for (uint32_t index = 0; index < spdm_response->supported_event_groups_list_len; index++)
+      98                 :            :     {
+      99                 :          8 :         assert_int_equal(((char *)(spdm_response + 1))[index], (char)index);
+     100                 :            :     }
+     101                 :            : 
+     102                 :          1 :     libspdm_dump_data(response, response_size);
+     103                 :          1 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
+     104                 :          1 : }
+     105                 :            : 
+     106                 :          1 : int libspdm_responder_supported_event_types_test_main(void)
+     107                 :            : {
+     108                 :          1 :     libspdm_test_context_t m_test_context = {
+     109                 :            :         LIBSPDM_TEST_CONTEXT_VERSION,
+     110                 :            :         false,
+     111                 :            :     };
+     112                 :            : 
+     113                 :          1 :     const struct CMUnitTest spdm_responder_supported_event_types_tests[] = {
+     114                 :            :         cmocka_unit_test(libspdm_test_responder_supported_event_types_case1),
+     115                 :            :     };
+     116                 :            : 
+     117                 :          1 :     libspdm_setup_test_context(&m_test_context);
+     118                 :            : 
+     119                 :          1 :     return cmocka_run_group_tests(spdm_responder_supported_event_types_tests,
+     120                 :            :                                   libspdm_unit_test_group_setup,
+     121                 :            :                                   libspdm_unit_test_group_teardown);
+     122                 :            : }
+     123                 :            : 
+     124                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/test_spdm_responder.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_responder/test_spdm_responder.c.func-sort-c.html new file mode 100644 index 00000000000..51d4aa1779c --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/test_spdm_responder.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/test_spdm_responder.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - test_spdm_responder.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:377152.1 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:346850.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
main1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/test_spdm_responder.c.func.html b/coverage_log/unit_test/test_spdm_responder/test_spdm_responder.c.func.html new file mode 100644 index 00000000000..d8275e3b7aa --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/test_spdm_responder.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/test_spdm_responder.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - test_spdm_responder.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:377152.1 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:346850.0 %
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
main1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/test_spdm_responder.c.gcov.html b/coverage_log/unit_test/test_spdm_responder/test_spdm_responder.c.gcov.html new file mode 100644 index 00000000000..e47892a996d --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/test_spdm_responder.c.gcov.html @@ -0,0 +1,360 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/test_spdm_responder.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - test_spdm_responder.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:377152.1 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:346850.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_responder_lib.h"
+       9                 :            : 
+      10                 :            : int libspdm_responder_version_test_main(void);
+      11                 :            : int libspdm_responder_capabilities_test_main(void);
+      12                 :            : int libspdm_responder_algorithms_test_main(void);
+      13                 :            : 
+      14                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CERT_CAP
+      15                 :            : int libspdm_responder_digests_test_main(void);
+      16                 :            : int libspdm_responder_certificate_test_main(void);
+      17                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CERT_CAP*/
+      18                 :            : 
+      19                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP
+      20                 :            : int libspdm_responder_challenge_auth_test_main(void);
+      21                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CERT_CAP*/
+      22                 :            : 
+      23                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
+      24                 :            : int libspdm_responder_measurements_test_main(void);
+      25                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP*/
+      26                 :            : 
+      27                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MEL_CAP
+      28                 :            : int libspdm_responder_measurement_extension_log_test_main(void);
+      29                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEL_CAP*/
+      30                 :            : 
+      31                 :            : #if LIBSPDM_ENABLE_CAPABILITY_GET_KEY_PAIR_INFO_CAP
+      32                 :            : int libspdm_responder_key_pair_info_test_main(void);
+      33                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_GET_KEY_PAIR_INFO_CAP*/
+      34                 :            : 
+      35                 :            : #if LIBSPDM_ENABLE_CAPABILITY_SET_KEY_PAIR_INFO_CAP
+      36                 :            : int libspdm_responder_set_key_pair_info_ack_test_main(void);
+      37                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_SET_KEY_PAIR_INFO_CAP*/
+      38                 :            : 
+      39                 :            : #if LIBSPDM_RESPOND_IF_READY_SUPPORT
+      40                 :            : #if (LIBSPDM_ENABLE_CAPABILITY_CERT_CAP || LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP || \
+      41                 :            :      LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP || LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP || \
+      42                 :            :      LIBSPDM_ENABLE_CAPABILITY_PSK_CAP)
+      43                 :            : int libspdm_responder_respond_if_ready_test_main (void);
+      44                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_*_CAP */
+      45                 :            : #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
+      46                 :            : 
+      47                 :            : #if LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP
+      48                 :            : int libspdm_responder_key_exchange_test_main(void);
+      49                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP*/
+      50                 :            : 
+      51                 :            : int libspdm_responder_finish_test_main(void);
+      52                 :            : 
+      53                 :            : #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
+      54                 :            : int libspdm_responder_psk_exchange_test_main(void);
+      55                 :            : int libspdm_responder_psk_finish_test_main(void);
+      56                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP */
+      57                 :            : 
+      58                 :            : #if (LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP) || (LIBSPDM_ENABLE_CAPABILITY_PSK_CAP)
+      59                 :            : int libspdm_responder_heartbeat_test_main(void);
+      60                 :            : int libspdm_responder_key_update_test_main(void);
+      61                 :            : int libspdm_responder_end_session_test_main(void);
+      62                 :            : #endif /* (LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP) || (LIBSPDM_ENABLE_CAPABILITY_PSK_CAP) */
+      63                 :            : 
+      64                 :            : #if LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP
+      65                 :            : #if LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP
+      66                 :            : #if LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT
+      67                 :            : int spdm_responder_encap_get_digests_test_main(void);
+      68                 :            : int spdm_responder_encap_get_certificate_test_main(void);
+      69                 :            : #endif /* LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT */
+      70                 :            : #if LIBSPDM_SEND_CHALLENGE_SUPPORT
+      71                 :            : int libspdm_responder_encap_challenge_auth_test_main(void);
+      72                 :            : #endif /* LIBSPDM_SEND_CHALLENGE_SUPPORT */
+      73                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP */
+      74                 :            : int libspdm_responder_encapsulated_response_test_main(void);
+      75                 :            : int libspdm_responder_encap_key_update_test_main(void);
+      76                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP*/
+      77                 :            : 
+      78                 :            : int libspdm_responder_set_certificate_rsp_test_main(void);
+      79                 :            : int libspdm_responder_csr_test_main(void);
+      80                 :            : 
+      81                 :            : #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
+      82                 :            : int libspdm_responder_chunk_get_rsp_test_main(void);
+      83                 :            : int libspdm_responder_receive_send_test_main(void);
+      84                 :            : int libspdm_responder_chunk_send_ack_test_main(void);
+      85                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP */
+      86                 :            : 
+      87                 :            : #if LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP
+      88                 :            : int libspdm_responder_supported_event_types_test_main(void);
+      89                 :            : int libspdm_responder_supported_event_types_error_test_main(void);
+      90                 :            : int libspdm_responder_subscribe_event_types_ack_test_main(void);
+      91                 :            : int libspdm_responder_subscribe_event_types_ack_error_test_main(void);
+      92                 :            : #endif /* LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP */
+      93                 :            : 
+      94                 :            : #if LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES
+      95                 :            : int libspdm_responder_vendor_cmds_test_main(void);
+      96                 :            : int libspdm_responder_vendor_cmds_error_test_main(void);
+      97                 :            : #endif /* LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES */
+      98                 :            : 
+      99                 :          1 : int main(void)
+     100                 :            : {
+     101                 :          1 :     int return_value = 0;
+     102                 :            : 
+     103         [ -  + ]:          1 :     if (libspdm_responder_version_test_main() != 0) {
+     104                 :          0 :         return_value = 1;
+     105                 :            :     }
+     106                 :            : 
+     107         [ -  + ]:          1 :     if (libspdm_responder_capabilities_test_main() != 0) {
+     108                 :          0 :         return_value = 1;
+     109                 :            :     }
+     110                 :            : 
+     111         [ -  + ]:          1 :     if (libspdm_responder_algorithms_test_main() != 0) {
+     112                 :          0 :         return_value = 1;
+     113                 :            :     }
+     114                 :            : 
+     115                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_CERT_CAP
+     116         [ -  + ]:          1 :     if (libspdm_responder_digests_test_main() != 0) {
+     117                 :          0 :         return_value = 1;
+     118                 :            :     }
+     119         [ -  + ]:          1 :     if (libspdm_responder_certificate_test_main() != 0) {
+     120                 :          0 :         return_value = 1;
+     121                 :            :     }
+     122                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_CERT_CAP*/
+     123                 :            : 
+     124                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP
+     125         [ -  + ]:          1 :     if (libspdm_responder_challenge_auth_test_main() != 0) {
+     126                 :          0 :         return_value = 1;
+     127                 :            :     }
+     128                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP*/
+     129                 :            : 
+     130                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
+     131         [ -  + ]:          1 :     if (libspdm_responder_measurements_test_main() != 0) {
+     132                 :          0 :         return_value = 1;
+     133                 :            :     }
+     134                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP*/
+     135                 :            : 
+     136                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_MEL_CAP
+     137         [ -  + ]:          1 :     if (libspdm_responder_measurement_extension_log_test_main() != 0) {
+     138                 :          0 :         return_value = 1;
+     139                 :            :     }
+     140                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_MEL_CAP*/
+     141                 :            : 
+     142                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_GET_KEY_PAIR_INFO_CAP
+     143         [ -  + ]:          1 :     if (libspdm_responder_key_pair_info_test_main() != 0) {
+     144                 :          0 :         return_value = 1;
+     145                 :            :     }
+     146                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_GET_KEY_PAIR_INFO_CAP*/
+     147                 :            : 
+     148                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_SET_KEY_PAIR_INFO_CAP
+     149         [ -  + ]:          1 :     if (libspdm_responder_set_key_pair_info_ack_test_main() != 0) {
+     150                 :          0 :         return_value = 1;
+     151                 :            :     }
+     152                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_SET_KEY_PAIR_INFO_CAP*/
+     153                 :            : 
+     154                 :            :     #if LIBSPDM_RESPOND_IF_READY_SUPPORT
+     155                 :            :     #if (LIBSPDM_ENABLE_CAPABILITY_CERT_CAP || LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP || \
+     156                 :            :          LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP || LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP || \
+     157                 :            :          LIBSPDM_ENABLE_CAPABILITY_PSK_CAP)
+     158         [ -  + ]:          1 :     if (libspdm_responder_respond_if_ready_test_main() != 0) {
+     159                 :          0 :         return_value = 1;
+     160                 :            :     }
+     161                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_*_CAP */
+     162                 :            :     #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
+     163                 :            : 
+     164                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP
+     165         [ -  + ]:          1 :     if (libspdm_responder_key_exchange_test_main() != 0) {
+     166                 :          0 :         return_value = 1;
+     167                 :            :     }
+     168                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP*/
+     169                 :            : 
+     170                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP
+     171         [ -  + ]:          1 :     if (libspdm_responder_finish_test_main() != 0) {
+     172                 :          0 :         return_value = 1;
+     173                 :            :     }
+     174                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP*/
+     175                 :            : 
+     176                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
+     177         [ -  + ]:          1 :     if (libspdm_responder_psk_exchange_test_main() != 0) {
+     178                 :          0 :         return_value = 1;
+     179                 :            :     }
+     180                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP*/
+     181                 :            : 
+     182                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
+     183         [ -  + ]:          1 :     if (libspdm_responder_psk_finish_test_main() != 0) {
+     184                 :          0 :         return_value = 1;
+     185                 :            :     }
+     186                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP*/
+     187                 :            : 
+     188                 :            :     #if (LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP) || (LIBSPDM_ENABLE_CAPABILITY_PSK_CAP)
+     189         [ -  + ]:          1 :     if (libspdm_responder_heartbeat_test_main() != 0) {
+     190                 :          0 :         return_value = 1;
+     191                 :            :     }
+     192         [ -  + ]:          1 :     if (libspdm_responder_key_update_test_main() != 0) {
+     193                 :          0 :         return_value = 1;
+     194                 :            :     }
+     195         [ -  + ]:          1 :     if (libspdm_responder_end_session_test_main() != 0) {
+     196                 :          0 :         return_value = 1;
+     197                 :            :     }
+     198                 :            :     #endif /* (LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP) || (LIBSPDM_ENABLE_CAPABILITY_PSK_CAP) */
+     199                 :            : 
+     200                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP
+     201                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP
+     202                 :            :     #if LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT
+     203         [ -  + ]:          1 :     if (spdm_responder_encap_get_digests_test_main() != 0) {
+     204                 :          0 :         return_value = 1;
+     205                 :            :     }
+     206         [ -  + ]:          1 :     if (spdm_responder_encap_get_certificate_test_main() != 0) {
+     207                 :          0 :         return_value = 1;
+     208                 :            :     }
+     209                 :            :     #endif /* LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT */
+     210                 :            :     #if LIBSPDM_SEND_CHALLENGE_SUPPORT
+     211         [ -  + ]:          1 :     if (libspdm_responder_encap_challenge_auth_test_main() != 0) {
+     212                 :          0 :         return_value = 1;
+     213                 :            :     }
+     214                 :            :     #endif /* LIBSPDM_SEND_CHALLENGE_SUPPORT */
+     215                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP */
+     216         [ -  + ]:          1 :     if (libspdm_responder_encapsulated_response_test_main() != 0) {
+     217                 :          0 :         return_value = 1;
+     218                 :            :     }
+     219         [ -  + ]:          1 :     if (libspdm_responder_encap_key_update_test_main() != 0) {
+     220                 :          0 :         return_value = 1;
+     221                 :            :     }
+     222                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP*/
+     223                 :            : 
+     224                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_SET_CERT_CAP
+     225         [ -  + ]:          1 :     if (libspdm_responder_set_certificate_rsp_test_main() != 0) {
+     226                 :          0 :         return_value = 1;
+     227                 :            :     }
+     228                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_SET_CERT_CAP */
+     229                 :            : 
+     230                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_CSR_CAP
+     231         [ -  + ]:          1 :     if (libspdm_responder_csr_test_main() != 0) {
+     232                 :          0 :         return_value = 1;
+     233                 :            :     }
+     234                 :            :     #endif /*LIBSPDM_ENABLE_CAPABILITY_CSR_CAP*/
+     235                 :            : 
+     236                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
+     237         [ -  + ]:          1 :     if (libspdm_responder_chunk_get_rsp_test_main() != 0) {
+     238                 :          0 :         return_value = 1;
+     239                 :            :     }
+     240                 :            : 
+     241         [ -  + ]:          1 :     if (libspdm_responder_receive_send_test_main() != 0) {
+     242                 :          0 :         return_value = 1;
+     243                 :            :     }
+     244                 :            : 
+     245         [ -  + ]:          1 :     if (libspdm_responder_chunk_send_ack_test_main() != 0) {
+     246                 :          0 :         return_value = 1;
+     247                 :            :     }
+     248                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP */
+     249                 :            : 
+     250                 :            :     #if LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP
+     251         [ -  + ]:          1 :     if (libspdm_responder_supported_event_types_test_main() != 0) {
+     252                 :          0 :         return_value = 1;
+     253                 :            :     }
+     254         [ -  + ]:          1 :     if (libspdm_responder_supported_event_types_error_test_main() != 0) {
+     255                 :          0 :         return_value = 1;
+     256                 :            :     }
+     257         [ -  + ]:          1 :     if (libspdm_responder_subscribe_event_types_ack_test_main() != 0) {
+     258                 :          0 :         return_value = 1;
+     259                 :            :     }
+     260         [ -  + ]:          1 :     if (libspdm_responder_subscribe_event_types_ack_error_test_main() != 0) {
+     261                 :          0 :         return_value = 1;
+     262                 :            :     }
+     263                 :            :     #endif /* LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP */
+     264                 :            : 
+     265                 :            :     #if LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES
+     266         [ -  + ]:          1 :     if (libspdm_responder_vendor_cmds_test_main() != 0) {
+     267                 :          0 :         return_value = 1;
+     268                 :            :     }
+     269         [ -  + ]:          1 :     if (libspdm_responder_vendor_cmds_error_test_main() != 0) {
+     270                 :          0 :         return_value = 1;
+     271                 :            :     }
+     272                 :            :     #endif /* LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES */
+     273                 :            : 
+     274                 :          1 :     return return_value;
+     275                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/vendor_response.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_responder/vendor_response.c.func-sort-c.html new file mode 100644 index 00000000000..96f3c4a211a --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/vendor_response.c.func-sort-c.html @@ -0,0 +1,97 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/vendor_response.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - vendor_response.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:646795.5 %
Date:2024-09-22 08:21:07Functions:44100.0 %
Branches:71450.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_vendor_cmds_test_main1
libspdm_test_responder_vendor_cmds_case11
libspdm_vendor_get_id_func_test1
libspdm_vendor_response_func_test1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/vendor_response.c.func.html b/coverage_log/unit_test/test_spdm_responder/vendor_response.c.func.html new file mode 100644 index 00000000000..e798bd18516 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/vendor_response.c.func.html @@ -0,0 +1,97 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/vendor_response.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - vendor_response.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:646795.5 %
Date:2024-09-22 08:21:07Functions:44100.0 %
Branches:71450.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_vendor_cmds_test_main1
libspdm_test_responder_vendor_cmds_case11
libspdm_vendor_get_id_func_test1
libspdm_vendor_response_func_test1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/vendor_response.c.gcov.html b/coverage_log/unit_test/test_spdm_responder/vendor_response.c.gcov.html new file mode 100644 index 00000000000..3bdb56c0f80 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/vendor_response.c.gcov.html @@ -0,0 +1,263 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/vendor_response.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - vendor_response.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:646795.5 %
Date:2024-09-22 08:21:07Functions:44100.0 %
Branches:71450.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2023-2024 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_responder_lib.h"
+       9                 :            : 
+      10                 :            : #if LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES
+      11                 :            : 
+      12                 :            : #pragma pack(1)
+      13                 :            : typedef struct {
+      14                 :            :     spdm_message_header_t header;
+      15                 :            :     uint16_t standard_id;
+      16                 :            :     uint8_t vendor_id_len;
+      17                 :            :     uint8_t vendor_id[SPDM_MAX_VENDOR_ID_LENGTH];
+      18                 :            :     uint16_t data_len;
+      19                 :            :     uint8_t data[16];
+      20                 :            : } libspdm_vendor_request_test;
+      21                 :            : 
+      22                 :            : typedef struct {
+      23                 :            :     spdm_message_header_t header;
+      24                 :            :     uint16_t standard_id;
+      25                 :            :     uint8_t vendor_id_len;
+      26                 :            :     uint8_t vendor_id[SPDM_MAX_VENDOR_ID_LENGTH];
+      27                 :            :     uint16_t data_len;
+      28                 :            :     uint8_t data[64];
+      29                 :            : } libspdm_vendor_response_test;
+      30                 :            : #pragma pack()
+      31                 :            : 
+      32                 :            : 
+      33                 :          1 : libspdm_return_t libspdm_vendor_get_id_func_test(
+      34                 :            :     void *spdm_context,
+      35                 :            :     uint16_t *resp_standard_id,
+      36                 :            :     uint8_t *resp_vendor_id_len,
+      37                 :            :     void *resp_vendor_id)
+      38                 :            : {
+      39   [ +  -  +  - ]:          1 :     if (resp_standard_id == NULL ||
+      40         [ -  + ]:          1 :         resp_vendor_id_len == NULL ||
+      41                 :            :         resp_vendor_id == NULL)
+      42                 :          0 :         return LIBSPDM_STATUS_INVALID_PARAMETER;
+      43                 :            : 
+      44                 :            :     /* vendor id length in bytes */
+      45         [ -  + ]:          1 :     if (*resp_vendor_id_len < 2)
+      46                 :          0 :         return LIBSPDM_STATUS_INVALID_PARAMETER;
+      47                 :            : 
+      48                 :          1 :     *resp_standard_id = 6;
+      49                 :            :     /* vendor id length in bytes */
+      50                 :          1 :     *resp_vendor_id_len = 2;
+      51                 :          1 :     ((uint8_t*)resp_vendor_id)[0] = 0xAA;
+      52                 :          1 :     ((uint8_t*)resp_vendor_id)[1] = 0xAA;
+      53                 :            : 
+      54                 :          1 :     return LIBSPDM_STATUS_SUCCESS;
+      55                 :            : }
+      56                 :            : 
+      57                 :          1 : libspdm_return_t libspdm_vendor_response_func_test(
+      58                 :            :     void *spdm_context,
+      59                 :            :     uint16_t req_standard_id,
+      60                 :            :     uint8_t req_vendor_id_len,
+      61                 :            :     const void *req_vendor_id,
+      62                 :            :     uint16_t req_size,
+      63                 :            :     const void *req_data,
+      64                 :            :     uint16_t *resp_size,
+      65                 :            :     void *resp_data)
+      66                 :            : {
+      67   [ +  -  +  - ]:          1 :     if (req_data == NULL ||
+      68         [ -  + ]:          1 :         resp_size == NULL ||
+      69                 :            :         resp_data == NULL)
+      70                 :          0 :         return LIBSPDM_STATUS_INVALID_PARAMETER;
+      71                 :            : 
+      72                 :            :     libspdm_vendor_response_test test_response;
+      73                 :            :     /* get pointer to response data payload and populate */
+      74                 :          1 :     uint8_t *resp_payload = (uint8_t *)resp_data;
+      75                 :            :     /* get pointer to response length and populate */
+      76                 :          1 :     *resp_size = sizeof(test_response.data);
+      77                 :            :     /* store length of response */
+      78                 :          1 :     libspdm_set_mem(resp_payload, *resp_size, 0xFF);
+      79                 :            : 
+      80                 :          1 :     printf("Got request 0x%x, sent response 0x%x\n",
+      81                 :          1 :            ((const uint8_t*)req_data)[0], ((uint8_t*)resp_data)[0]);
+      82                 :            : 
+      83                 :          1 :     return LIBSPDM_STATUS_SUCCESS;
+      84                 :            : }
+      85                 :            : 
+      86                 :            : /**
+      87                 :            :  * Test 1: Sending a vendor defined request using the internal response handler
+      88                 :            :  * Expected behavior: client returns a status of LIBSPDM_STATUS_SUCCESS and expected response
+      89                 :            :  **/
+      90                 :          1 : static void libspdm_test_responder_vendor_cmds_case1(void **state)
+      91                 :            : {
+      92                 :            :     libspdm_return_t status;
+      93                 :            :     libspdm_test_context_t *spdm_test_context;
+      94                 :            :     libspdm_context_t *spdm_context;
+      95                 :          1 :     uint8_t request_buffer[LIBSPDM_MAX_SPDM_MSG_SIZE] = {0};
+      96                 :          1 :     uint8_t response_buffer[LIBSPDM_MAX_SPDM_MSG_SIZE] = {0};
+      97                 :          1 :     libspdm_vendor_request_test request = {0};
+      98                 :          1 :     libspdm_vendor_response_test response = {0};
+      99                 :          1 :     size_t response_len = 0;
+     100                 :          1 :     response.vendor_id_len = sizeof(response.vendor_id);
+     101                 :          1 :     response.data_len = sizeof(response.data);
+     102                 :            : 
+     103                 :          1 :     spdm_test_context = *state;
+     104                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     105                 :          1 :     spdm_test_context->case_id = 0x1;
+     106                 :          1 :     spdm_context->connection_info.algorithm.base_hash_algo =
+     107                 :            :         SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256;
+     108                 :          1 :     request.header.spdm_version = SPDM_MESSAGE_VERSION_10;
+     109                 :          1 :     spdm_context->connection_info.version = request.header.spdm_version <<
+     110                 :            :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
+     111                 :          1 :     spdm_context->connection_info.connection_state =
+     112                 :            :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
+     113                 :          1 :     spdm_context->local_context.is_requester = true;
+     114                 :            : 
+     115                 :          1 :     status = libspdm_register_vendor_get_id_callback_func(spdm_context,
+     116                 :            :                                                           libspdm_vendor_get_id_func_test);
+     117                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     118                 :          1 :     status = libspdm_register_vendor_callback_func(spdm_context,
+     119                 :            :                                                    libspdm_vendor_response_func_test);
+     120                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     121                 :            : 
+     122                 :          1 :     request.standard_id = 6;
+     123                 :          1 :     request.vendor_id_len = sizeof(request.vendor_id);
+     124                 :          1 :     libspdm_set_mem(request.vendor_id, sizeof(request.vendor_id), 0xAA);
+     125                 :          1 :     request.data_len = sizeof(request.data);
+     126                 :          1 :     libspdm_set_mem(request.data, sizeof(request.data), 0xAA);
+     127                 :            : 
+     128                 :          1 :     response_len = sizeof(response);
+     129                 :            : 
+     130                 :            :     /* copy header of request structure to buffer */
+     131                 :          1 :     libspdm_copy_mem(request_buffer, sizeof(request_buffer), &request,
+     132                 :          1 :                      sizeof(request.header) + 3 + request.vendor_id_len);
+     133                 :            :     /* copy the request data to the correct offset in the request_buffer */
+     134                 :          1 :     libspdm_copy_mem(request_buffer + sizeof(request.header) + 3 + request.vendor_id_len,
+     135                 :          1 :                      request.data_len + 2, &request.data_len, request.data_len + 2);
+     136                 :            : 
+     137                 :            :     /* requires correctly encoded spdm vendor request message */
+     138                 :          1 :     status = libspdm_get_vendor_defined_response(spdm_context, sizeof(request),
+     139                 :            :                                                  request_buffer, &response_len, response_buffer);
+     140                 :            : 
+     141                 :            :     /* copy to response data structure in the same way as for request */
+     142                 :          1 :     response.vendor_id_len = response_buffer[sizeof(response.header) + 2];
+     143                 :          1 :     response.data_len =
+     144                 :          1 :         *((uint16_t*)(response_buffer + sizeof(response.header) + 3 + response.vendor_id_len));
+     145                 :            :     /* copy header of response structure from buffer */
+     146                 :          1 :     libspdm_copy_mem(&response, sizeof(response), response_buffer,
+     147                 :          1 :                      sizeof(response.header) + 3 + response.vendor_id_len);
+     148                 :            :     /* copy the response data from the correct offset in the response_buffer */
+     149                 :          1 :     libspdm_copy_mem(&response.data, response.data_len,
+     150                 :          1 :                      response_buffer + sizeof(response.header) + 3 + response.vendor_id_len + 2,
+     151                 :          1 :                      response.data_len);
+     152                 :            : 
+     153                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     154                 :          1 :     assert_int_equal(
+     155                 :            :         spdm_context->connection_info.version >> SPDM_VERSION_NUMBER_SHIFT_BIT,
+     156                 :            :         SPDM_MESSAGE_VERSION_10);
+     157                 :          1 : }
+     158                 :            : 
+     159                 :            : libspdm_test_context_t m_libspdm_responder_vendor_cmds_test_context = {
+     160                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+     161                 :            :     true,
+     162                 :            : };
+     163                 :            : 
+     164                 :          1 : int libspdm_responder_vendor_cmds_test_main(void)
+     165                 :            : {
+     166                 :          1 :     const struct CMUnitTest spdm_responder_vendor_cmds_tests[] = {
+     167                 :            :         cmocka_unit_test(libspdm_test_responder_vendor_cmds_case1),
+     168                 :            :     };
+     169                 :            : 
+     170                 :          1 :     libspdm_setup_test_context(&m_libspdm_responder_vendor_cmds_test_context);
+     171                 :            : 
+     172                 :          1 :     return cmocka_run_group_tests(spdm_responder_vendor_cmds_tests,
+     173                 :            :                                   libspdm_unit_test_group_setup,
+     174                 :            :                                   libspdm_unit_test_group_teardown);
+     175                 :            : }
+     176                 :            : 
+     177                 :            : 
+     178                 :            : #endif /* LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/version.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_responder/version.c.func-sort-c.html new file mode 100644 index 00000000000..2c23a7a3f47 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/version.c.func-sort-c.html @@ -0,0 +1,113 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/version.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - version.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:8282100.0 %
Date:2024-09-22 08:21:07Functions:88100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_version_test_main1
libspdm_test_responder_version_case11
libspdm_test_responder_version_case21
libspdm_test_responder_version_case31
libspdm_test_responder_version_case41
libspdm_test_responder_version_case61
libspdm_test_responder_version_case71
libspdm_test_responder_version_case81
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/version.c.func.html b/coverage_log/unit_test/test_spdm_responder/version.c.func.html new file mode 100644 index 00000000000..e4f73bb64e0 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/version.c.func.html @@ -0,0 +1,113 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/version.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - version.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:8282100.0 %
Date:2024-09-22 08:21:07Functions:88100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
libspdm_responder_version_test_main1
libspdm_test_responder_version_case11
libspdm_test_responder_version_case21
libspdm_test_responder_version_case31
libspdm_test_responder_version_case41
libspdm_test_responder_version_case61
libspdm_test_responder_version_case71
libspdm_test_responder_version_case81
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_responder/version.c.gcov.html b/coverage_log/unit_test/test_spdm_responder/version.c.gcov.html new file mode 100644 index 00000000000..6896b093f96 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_responder/version.c.gcov.html @@ -0,0 +1,372 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_responder/version.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_responder - version.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:8282100.0 %
Date:2024-09-22 08:21:07Functions:88100.0 %
Branches:00-
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2021-2022 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_responder_lib.h"
+       9                 :            : 
+      10                 :            : #define LIBSPDM_DEFAULT_SPDM_VERSION_ENTRY_COUNT SPDM_MAX_VERSION_COUNT
+      11                 :            : 
+      12                 :            : #pragma pack(1)
+      13                 :            : typedef struct {
+      14                 :            :     spdm_message_header_t header;
+      15                 :            :     uint8_t reserved;
+      16                 :            :     uint8_t version_number_entry_count;
+      17                 :            :     spdm_version_number_t version_number_entry[LIBSPDM_MAX_VERSION_COUNT];
+      18                 :            : } libspdm_version_response_mine_t;
+      19                 :            : #pragma pack()
+      20                 :            : 
+      21                 :            : spdm_get_version_request_t m_libspdm_get_version_request1 = {
+      22                 :            :     {
+      23                 :            :         SPDM_MESSAGE_VERSION_10,
+      24                 :            :         SPDM_GET_VERSION,
+      25                 :            :     },
+      26                 :            : };
+      27                 :            : size_t m_libspdm_get_version_request1_size = sizeof(m_libspdm_get_version_request1);
+      28                 :            : 
+      29                 :            : spdm_get_version_request_t m_libspdm_get_version_request3 = {
+      30                 :            :     {
+      31                 :            :         SPDM_MESSAGE_VERSION_11,
+      32                 :            :         SPDM_GET_VERSION,
+      33                 :            :     },
+      34                 :            : };
+      35                 :            : size_t m_libspdm_get_version_request3_size = sizeof(m_libspdm_get_version_request3);
+      36                 :            : 
+      37                 :            : spdm_get_version_request_t m_libspdm_get_version_request4 = {
+      38                 :            :     {
+      39                 :            :         SPDM_MESSAGE_VERSION_10,
+      40                 :            :         SPDM_VERSION,
+      41                 :            :     },
+      42                 :            : };
+      43                 :            : size_t m_libspdm_get_version_request4_size = sizeof(m_libspdm_get_version_request4);
+      44                 :            : 
+      45                 :            : /**
+      46                 :            :  * Test 1: receiving a correct GET_VERSION from the requester.
+      47                 :            :  * Expected behavior: the responder accepts the request, produces a valid VERSION
+      48                 :            :  * response message, and then resets the connection state.
+      49                 :            :  **/
+      50                 :          1 : void libspdm_test_responder_version_case1(void **state)
+      51                 :            : {
+      52                 :            :     libspdm_return_t status;
+      53                 :            :     libspdm_test_context_t *spdm_test_context;
+      54                 :            :     libspdm_context_t *spdm_context;
+      55                 :            :     size_t response_size;
+      56                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+      57                 :            :     spdm_version_response_t *spdm_response;
+      58                 :            : 
+      59                 :          1 :     spdm_test_context = *state;
+      60                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+      61                 :          1 :     spdm_test_context->case_id = 0x1;
+      62                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NOT_STARTED;
+      63                 :            : 
+      64                 :          1 :     response_size = sizeof(response);
+      65                 :          1 :     status = libspdm_get_response_version(spdm_context,
+      66                 :            :                                           m_libspdm_get_version_request1_size,
+      67                 :            :                                           &m_libspdm_get_version_request1,
+      68                 :            :                                           &response_size, response);
+      69                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+      70                 :          1 :     assert_int_equal(response_size,
+      71                 :            :                      sizeof(spdm_version_response_t) +
+      72                 :            :                      LIBSPDM_DEFAULT_SPDM_VERSION_ENTRY_COUNT *
+      73                 :            :                      sizeof(spdm_version_number_t));
+      74                 :          1 :     spdm_response = (void *)response;
+      75                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+      76                 :            :                      SPDM_VERSION);
+      77                 :          1 :     assert_int_equal(spdm_context->connection_info.connection_state,
+      78                 :            :                      LIBSPDM_CONNECTION_STATE_AFTER_VERSION);
+      79                 :          1 : }
+      80                 :            : 
+      81                 :            : /**
+      82                 :            :  * Test 2:
+      83                 :            :  * Expected behavior:
+      84                 :            :  **/
+      85                 :          1 : void libspdm_test_responder_version_case2(void **state)
+      86                 :            : {
+      87                 :          1 : }
+      88                 :            : 
+      89                 :            : /**
+      90                 :            :  * Test 3: receiving a correct GET_VERSION from the requester, but the responder is in
+      91                 :            :  * a Busy state.
+      92                 :            :  * Expected behavior: the responder accepts the request, but produces an ERROR message
+      93                 :            :  * indicating the Buse state.
+      94                 :            :  **/
+      95                 :          1 : void libspdm_test_responder_version_case3(void **state)
+      96                 :            : {
+      97                 :            :     libspdm_return_t status;
+      98                 :            :     libspdm_test_context_t *spdm_test_context;
+      99                 :            :     libspdm_context_t *spdm_context;
+     100                 :            :     size_t response_size;
+     101                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     102                 :            :     spdm_version_response_t *spdm_response;
+     103                 :            : 
+     104                 :          1 :     spdm_test_context = *state;
+     105                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     106                 :          1 :     spdm_test_context->case_id = 0x3;
+     107                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_BUSY;
+     108                 :            : 
+     109                 :          1 :     response_size = sizeof(response);
+     110                 :          1 :     status = libspdm_get_response_version(spdm_context,
+     111                 :            :                                           m_libspdm_get_version_request1_size,
+     112                 :            :                                           &m_libspdm_get_version_request1,
+     113                 :            :                                           &response_size, response);
+     114                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     115                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     116                 :          1 :     spdm_response = (void *)response;
+     117                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     118                 :            :                      SPDM_ERROR);
+     119                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_BUSY);
+     120                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     121                 :          1 :     assert_int_equal(spdm_context->response_state,
+     122                 :            :                      LIBSPDM_RESPONSE_STATE_BUSY);
+     123                 :          1 : }
+     124                 :            : 
+     125                 :            : /**
+     126                 :            :  * Test 4: receiving a correct GET_VERSION from the requester, but the responder requires
+     127                 :            :  * resynchronization with the requester.
+     128                 :            :  * Expected behavior: the requester resets the communication upon receiving the GET_VERSION
+     129                 :            :  * message, fulfilling the resynchronization. A valid VERSION message is produced.
+     130                 :            :  **/
+     131                 :          1 : void libspdm_test_responder_version_case4(void **state)
+     132                 :            : {
+     133                 :            :     libspdm_return_t status;
+     134                 :            :     libspdm_test_context_t *spdm_test_context;
+     135                 :            :     libspdm_context_t *spdm_context;
+     136                 :            :     size_t response_size;
+     137                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     138                 :            :     spdm_version_response_t *spdm_response;
+     139                 :            : 
+     140                 :          1 :     spdm_test_context = *state;
+     141                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     142                 :          1 :     spdm_test_context->case_id = 0x4;
+     143                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NEED_RESYNC;
+     144                 :            : 
+     145                 :          1 :     response_size = sizeof(response);
+     146                 :          1 :     status = libspdm_get_response_version(spdm_context,
+     147                 :            :                                           m_libspdm_get_version_request1_size,
+     148                 :            :                                           &m_libspdm_get_version_request1,
+     149                 :            :                                           &response_size, response);
+     150                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     151                 :          1 :     assert_int_equal(response_size,
+     152                 :            :                      sizeof(spdm_version_response_t) +
+     153                 :            :                      LIBSPDM_DEFAULT_SPDM_VERSION_ENTRY_COUNT *
+     154                 :            :                      sizeof(spdm_version_number_t));
+     155                 :          1 :     spdm_response = (void *)response;
+     156                 :          1 :     assert_int_equal(spdm_response->header.request_response_code,
+     157                 :            :                      SPDM_VERSION);
+     158                 :          1 :     assert_int_equal(spdm_context->response_state,
+     159                 :            :                      LIBSPDM_RESPONSE_STATE_NORMAL);
+     160                 :          1 : }
+     161                 :            : 
+     162                 :            : /**
+     163                 :            :  * Test 6: receiving a GET_VERSION message in SPDM version 1.1 (in the header), but correct
+     164                 :            :  * 1.0-version format.
+     165                 :            :  * Expected behavior: the responder refuses the GET_VERSION message, produces an
+     166                 :            :  * ERROR message indicating the VersionMismatch, and will not reset the connection state.
+     167                 :            :  **/
+     168                 :          1 : void libspdm_test_responder_version_case6(void **state)
+     169                 :            : {
+     170                 :            :     libspdm_return_t status;
+     171                 :            :     libspdm_test_context_t *spdm_test_context;
+     172                 :            :     libspdm_context_t *spdm_context;
+     173                 :            :     size_t response_size;
+     174                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     175                 :            :     spdm_version_response_t *spdm_response;
+     176                 :            : 
+     177                 :          1 :     spdm_test_context = *state;
+     178                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     179                 :          1 :     spdm_test_context->case_id = 0x6;
+     180                 :          1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
+     181                 :          1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
+     182                 :            : 
+     183                 :          1 :     response_size = sizeof(response);
+     184                 :          1 :     status = libspdm_get_response_version(spdm_context,
+     185                 :            :                                           m_libspdm_get_version_request3_size,
+     186                 :            :                                           &m_libspdm_get_version_request3,
+     187                 :            :                                           &response_size, response);
+     188                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     189                 :          1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
+     190                 :          1 :     spdm_response = (void *)response;
+     191                 :          1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_10);
+     192                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
+     193                 :          1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_VERSION_MISMATCH);
+     194                 :          1 :     assert_int_equal(spdm_response->header.param2, 0);
+     195                 :          1 :     assert_int_equal(spdm_context->connection_info.connection_state,
+     196                 :            :                      LIBSPDM_CONNECTION_STATE_AUTHENTICATED);
+     197                 :          1 : }
+     198                 :            : 
+     199                 :            : /**
+     200                 :            :  * Test 7: can be populated with new test.
+     201                 :            :  **/
+     202                 :          1 : void libspdm_test_responder_version_case7(void **state)
+     203                 :            : {
+     204                 :          1 : }
+     205                 :            : 
+     206                 :            : /**
+     207                 :            :  * Test 8: receiving a correct GET_VERSION from the requester. Buffers A, B and C
+     208                 :            :  * already have arbitrary data.
+     209                 :            :  * Expected behavior: the responder accepts the request and produces a valid VERSION
+     210                 :            :  * response message, buffers A, B and C should be first reset, and then buffer A
+     211                 :            :  * receives only the exchanged GET_VERSION and VERSION messages.
+     212                 :            :  **/
+     213                 :          1 : void libspdm_test_responder_version_case8(void **state)
+     214                 :            : {
+     215                 :            :     libspdm_return_t status;
+     216                 :            :     libspdm_test_context_t *spdm_test_context;
+     217                 :            :     libspdm_context_t *spdm_context;
+     218                 :            :     size_t response_size;
+     219                 :            :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
+     220                 :            :     spdm_version_response_t *spdm_response;
+     221                 :            : 
+     222                 :          1 :     spdm_test_context = *state;
+     223                 :          1 :     spdm_context = spdm_test_context->spdm_context;
+     224                 :          1 :     spdm_test_context->case_id = 0x8;
+     225                 :            : 
+     226                 :            :     /*filling buffers with arbitrary data*/
+     227                 :          1 :     libspdm_set_mem(spdm_context->transcript.message_a.buffer, 10, (uint8_t) 0xFF);
+     228                 :          1 :     spdm_context->transcript.message_a.buffer_size = 10;
+     229                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     230                 :            :     libspdm_set_mem(spdm_context->transcript.message_b.buffer, 8, (uint8_t) 0xEE);
+     231                 :            :     spdm_context->transcript.message_b.buffer_size = 8;
+     232                 :            :     libspdm_set_mem(spdm_context->transcript.message_c.buffer, 12, (uint8_t) 0xDD);
+     233                 :            :     spdm_context->transcript.message_c.buffer_size = 12;
+     234                 :            : #endif
+     235                 :            : 
+     236                 :          1 :     response_size = sizeof(response);
+     237                 :          1 :     status = libspdm_get_response_version(
+     238                 :            :         spdm_context, m_libspdm_get_version_request1_size, &m_libspdm_get_version_request1,
+     239                 :            :         &response_size, response);
+     240                 :          1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
+     241                 :          1 :     assert_int_equal(response_size, sizeof(spdm_version_response_t) +
+     242                 :            :                      LIBSPDM_DEFAULT_SPDM_VERSION_ENTRY_COUNT * sizeof(spdm_version_number_t));
+     243                 :          1 :     spdm_response = (void *)response;
+     244                 :          1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_VERSION);
+     245                 :            : 
+     246                 :          1 :     assert_int_equal(spdm_context->transcript.message_a.buffer_size,
+     247                 :            :                      m_libspdm_get_version_request1_size + response_size);
+     248                 :          1 :     assert_memory_equal(spdm_context->transcript.message_a.buffer,
+     249                 :            :                         &m_libspdm_get_version_request1, m_libspdm_get_version_request1_size);
+     250                 :          1 :     assert_memory_equal(
+     251                 :            :         spdm_context->transcript.message_a.buffer + m_libspdm_get_version_request1_size,
+     252                 :            :         response, response_size);
+     253                 :            : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
+     254                 :            :     assert_int_equal(spdm_context->transcript.message_b.buffer_size, 0);
+     255                 :            :     assert_int_equal(spdm_context->transcript.message_c.buffer_size, 0);
+     256                 :            : #endif
+     257                 :          1 : }
+     258                 :            : 
+     259                 :            : libspdm_test_context_t m_libspdm_responder_version_test_context = {
+     260                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+     261                 :            :     false,
+     262                 :            : };
+     263                 :            : 
+     264                 :          1 : int libspdm_responder_version_test_main(void)
+     265                 :            : {
+     266                 :          1 :     const struct CMUnitTest spdm_responder_version_tests[] = {
+     267                 :            :         cmocka_unit_test(libspdm_test_responder_version_case1),
+     268                 :            :         /* Invalid request*/
+     269                 :            :         cmocka_unit_test(libspdm_test_responder_version_case2),
+     270                 :            :         /* response_state: SPDM_RESPONSE_STATE_BUSY*/
+     271                 :            :         cmocka_unit_test(libspdm_test_responder_version_case3),
+     272                 :            :         /* response_state: SPDM_RESPONSE_STATE_NEED_RESYNC*/
+     273                 :            :         cmocka_unit_test(libspdm_test_responder_version_case4),
+     274                 :            :         /* Invalid request*/
+     275                 :            :         cmocka_unit_test(libspdm_test_responder_version_case6),
+     276                 :            :         /* Invalid request*/
+     277                 :            :         cmocka_unit_test(libspdm_test_responder_version_case7),
+     278                 :            :         /* Buffer verification*/
+     279                 :            :         cmocka_unit_test(libspdm_test_responder_version_case8),
+     280                 :            :     };
+     281                 :            : 
+     282                 :          1 :     libspdm_setup_test_context(&m_libspdm_responder_version_test_context);
+     283                 :            : 
+     284                 :          1 :     return cmocka_run_group_tests(spdm_responder_version_tests,
+     285                 :            :                                   libspdm_unit_test_group_setup,
+     286                 :            :                                   libspdm_unit_test_group_teardown);
+     287                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_secured_message/encode_decode.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_secured_message/encode_decode.c.func-sort-c.html new file mode 100644 index 00000000000..ff8f4099c76 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_secured_message/encode_decode.c.func-sort-c.html @@ -0,0 +1,149 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_secured_message/encode_decode.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_secured_message - encode_decode.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:03310.0 %
Date:2024-09-22 08:21:07Functions:0170.0 %
Branches:0720.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
get_max_random_number_count0
get_secured_spdm_version0
get_sequence_number0
initialize_secured_message_context0
libspdm_secured_message_encode_decode_test_main0
libspdm_test_secured_message_encode_case10
libspdm_test_secured_message_encode_case100
libspdm_test_secured_message_encode_case110
libspdm_test_secured_message_encode_case120
libspdm_test_secured_message_encode_case20
libspdm_test_secured_message_encode_case30
libspdm_test_secured_message_encode_case40
libspdm_test_secured_message_encode_case50
libspdm_test_secured_message_encode_case60
libspdm_test_secured_message_encode_case70
libspdm_test_secured_message_encode_case80
libspdm_test_secured_message_encode_case90
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_secured_message/encode_decode.c.func.html b/coverage_log/unit_test/test_spdm_secured_message/encode_decode.c.func.html new file mode 100644 index 00000000000..3668c9ca8f9 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_secured_message/encode_decode.c.func.html @@ -0,0 +1,149 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_secured_message/encode_decode.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_secured_message - encode_decode.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:03310.0 %
Date:2024-09-22 08:21:07Functions:0170.0 %
Branches:0720.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
get_max_random_number_count0
get_secured_spdm_version0
get_sequence_number0
initialize_secured_message_context0
libspdm_secured_message_encode_decode_test_main0
libspdm_test_secured_message_encode_case10
libspdm_test_secured_message_encode_case100
libspdm_test_secured_message_encode_case110
libspdm_test_secured_message_encode_case120
libspdm_test_secured_message_encode_case20
libspdm_test_secured_message_encode_case30
libspdm_test_secured_message_encode_case40
libspdm_test_secured_message_encode_case50
libspdm_test_secured_message_encode_case60
libspdm_test_secured_message_encode_case70
libspdm_test_secured_message_encode_case80
libspdm_test_secured_message_encode_case90
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_secured_message/encode_decode.c.gcov.html b/coverage_log/unit_test/test_spdm_secured_message/encode_decode.c.gcov.html new file mode 100644 index 00000000000..b616259752b --- /dev/null +++ b/coverage_log/unit_test/test_spdm_secured_message/encode_decode.c.gcov.html @@ -0,0 +1,1016 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_secured_message/encode_decode.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_secured_message - encode_decode.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:03310.0 %
Date:2024-09-22 08:21:07Functions:0170.0 %
Branches:0720.0 %
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2023 DMTF. All rights reserved.
+       4                 :            :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
+       5                 :            :  **/
+       6                 :            : 
+       7                 :            : #include "spdm_unit_test.h"
+       8                 :            : #include "internal/libspdm_secured_message_lib.h"
+       9                 :            : 
+      10                 :            : #if LIBSPDM_AEAD_AES_256_GCM_SUPPORT
+      11                 :            : 
+      12                 :            : static uint8_t m_secured_message[0x1000];
+      13                 :            : static uint8_t m_app_message[0x1000];
+      14                 :            : static libspdm_secured_message_context_t m_secured_message_context;
+      15                 :            : static libspdm_secured_message_callbacks_t m_secured_message_callbacks;
+      16                 :            : 
+      17                 :            : #define PARTIAL_SEQ_NUM_SIZE 8
+      18                 :            : 
+      19                 :          0 : static uint8_t get_sequence_number(uint64_t sequence_number,
+      20                 :            :                                    uint8_t *sequence_number_buffer)
+      21                 :            : {
+      22                 :          0 :     libspdm_copy_mem(sequence_number_buffer, (size_t)8,
+      23                 :            :                      &sequence_number, (size_t)PARTIAL_SEQ_NUM_SIZE);
+      24                 :            : 
+      25                 :          0 :     return PARTIAL_SEQ_NUM_SIZE;
+      26                 :            : }
+      27                 :            : 
+      28                 :          0 : static uint32_t get_max_random_number_count(void)
+      29                 :            : {
+      30                 :          0 :     return 0;
+      31                 :            : }
+      32                 :            : 
+      33                 :          0 : static spdm_version_number_t get_secured_spdm_version(spdm_version_number_t secured_message_version)
+      34                 :            : {
+      35                 :          0 :     return SECURED_SPDM_VERSION_11;
+      36                 :            : }
+      37                 :            : 
+      38                 :          0 : static void initialize_secured_message_context(void)
+      39                 :            : {
+      40                 :          0 :     m_secured_message_context.secured_message_version = SECURED_SPDM_VERSION_11;
+      41                 :          0 :     m_secured_message_context.aead_cipher_suite = SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_256_GCM;
+      42                 :          0 :     m_secured_message_context.session_type = LIBSPDM_SESSION_TYPE_ENC_MAC;
+      43                 :          0 :     m_secured_message_context.session_state = LIBSPDM_SESSION_STATE_ESTABLISHED;
+      44                 :          0 :     m_secured_message_context.aead_tag_size = 16;
+      45                 :          0 :     m_secured_message_context.aead_key_size = 32;
+      46                 :          0 :     m_secured_message_context.aead_iv_size = 12;
+      47         [ #  # ]:          0 :     for (uint8_t index = 0; index < 32; index++) {
+      48                 :          0 :         m_secured_message_context.application_secret.request_data_encryption_key[index] = index;
+      49                 :          0 :         m_secured_message_context.application_secret.response_data_encryption_key[index] =
+      50                 :          0 :             32 - index;
+      51                 :            :     }
+      52         [ #  # ]:          0 :     for (uint8_t index = 0; index < 12; index++) {
+      53                 :          0 :         m_secured_message_context.application_secret.request_data_salt[index] = index * 2;
+      54                 :          0 :         m_secured_message_context.application_secret.response_data_salt[index] = index * 4;
+      55                 :            :     }
+      56                 :          0 :     m_secured_message_context.application_secret.request_data_sequence_number = 0;
+      57                 :          0 :     m_secured_message_context.application_secret.response_data_sequence_number = 0;
+      58                 :          0 :     m_secured_message_context.max_spdm_session_sequence_number = UINT64_MAX;
+      59                 :          0 :     m_secured_message_context.sequence_number_endian =
+      60                 :            :         LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_LITTLE_DEC_BOTH;
+      61                 :          0 :     m_secured_message_callbacks.get_secured_spdm_version = get_secured_spdm_version;
+      62                 :          0 :     m_secured_message_callbacks.get_max_random_number_count = get_max_random_number_count;
+      63                 :          0 :     m_secured_message_callbacks.get_sequence_number = get_sequence_number;
+      64                 :          0 : }
+      65                 :            : 
+      66                 :            : /**
+      67                 :            :  * Test 1: Test basic encryption with sequence number set to all zeroes and little endianness.
+      68                 :            :  **/
+      69                 :          0 : static void libspdm_test_secured_message_encode_case1(void **state)
+      70                 :            : {
+      71                 :            :     libspdm_return_t status;
+      72                 :            :     uint8_t app_message[16];
+      73                 :          0 :     size_t secured_message_size = sizeof(m_secured_message);
+      74                 :          0 :     const uint32_t session_id = 0x00112233;
+      75                 :            :     uint8_t *ptr;
+      76                 :            : 
+      77                 :          0 :     initialize_secured_message_context();
+      78                 :            : 
+      79         [ #  # ]:          0 :     for (uint8_t index = 0; index < 16; index++) {
+      80                 :          0 :         app_message[index] = index;
+      81                 :            :     }
+      82                 :            : 
+      83                 :          0 :     status = libspdm_encode_secured_message(
+      84                 :            :         &m_secured_message_context, session_id, true,
+      85                 :            :         sizeof(app_message), app_message, &secured_message_size, &m_secured_message,
+      86                 :            :         &m_secured_message_callbacks);
+      87                 :            : 
+      88                 :          0 :     assert_int_equal(LIBSPDM_STATUS_SUCCESS, status);
+      89                 :          0 :     assert_memory_equal(&session_id, &m_secured_message, 4);
+      90                 :            : 
+      91                 :            :     /* Sequence number is all zeroes. */
+      92         [ #  # ]:          0 :     for (int index = 4; index < 4 + PARTIAL_SEQ_NUM_SIZE; index++) {
+      93                 :          0 :         assert_int_equal(0, m_secured_message[index]);
+      94                 :            :     }
+      95                 :            : 
+      96                 :          0 :     assert_int_equal(0x0022, *(uint16_t*)&m_secured_message[4 + PARTIAL_SEQ_NUM_SIZE]);
+      97                 :            : 
+      98                 :          0 :     ptr = (uint8_t *)&m_secured_message + 6 + PARTIAL_SEQ_NUM_SIZE;
+      99                 :            : 
+     100                 :            :     /* Expected values generated from https://tinyurl.com/yrx9w78w */
+     101                 :          0 :     uint8_t expected_cipher_text[] = {0x9b, 0xfe, 0xd3, 0xb7, 0x04, 0x3d, 0x32, 0x86, 0x60, 0x3d,
+     102                 :            :                                       0x86, 0x17, 0x33, 0xd6, 0x7f, 0x95, 0x9a, 0x20};
+     103                 :          0 :     uint8_t expected_mac[] = {0x3d, 0x4f, 0xac, 0x58, 0xcb, 0x70, 0x6c, 0xf5, 0xa0, 0x27, 0x0a,
+     104                 :            :                               0xf6, 0x73, 0xf0, 0xfe, 0x36};
+     105                 :            : 
+     106                 :          0 :     assert_memory_equal(expected_cipher_text, ptr, sizeof(expected_cipher_text));
+     107                 :          0 :     ptr += sizeof(expected_cipher_text);
+     108                 :          0 :     assert_memory_equal(expected_mac, ptr, sizeof(expected_mac));
+     109                 :            : 
+     110                 :            :     /* Sequence number is incremented by one after operation. */
+     111                 :          0 :     assert_int_equal(1, m_secured_message_context.application_secret.request_data_sequence_number);
+     112                 :          0 : }
+     113                 :            : 
+     114                 :            : /**
+     115                 :            :  * Test 2: Test basic encryption with sequence number set to alternating zeroes and ones and
+     116                 :            :  *         little endianness.
+     117                 :            :  **/
+     118                 :          0 : static void libspdm_test_secured_message_encode_case2(void **state)
+     119                 :            : {
+     120                 :            :     libspdm_return_t status;
+     121                 :            :     uint8_t app_message[16];
+     122                 :          0 :     size_t secured_message_size = sizeof(m_secured_message);
+     123                 :          0 :     const uint32_t session_id = 0x00112233;
+     124                 :            :     uint8_t *ptr;
+     125                 :            : 
+     126                 :          0 :     initialize_secured_message_context();
+     127                 :          0 :     m_secured_message_context.application_secret.request_data_sequence_number = 0xaa55aa55aa55aa55;
+     128                 :            : 
+     129         [ #  # ]:          0 :     for (uint8_t index = 0; index < 16; index++) {
+     130                 :          0 :         app_message[index] = index;
+     131                 :            :     }
+     132                 :            : 
+     133                 :          0 :     status = libspdm_encode_secured_message(
+     134                 :            :         &m_secured_message_context, session_id, true,
+     135                 :            :         sizeof(app_message), app_message, &secured_message_size, &m_secured_message,
+     136                 :            :         &m_secured_message_callbacks);
+     137                 :            : 
+     138                 :          0 :     assert_int_equal(LIBSPDM_STATUS_SUCCESS, status);
+     139                 :          0 :     assert_memory_equal(&session_id, &m_secured_message, 4);
+     140                 :            : 
+     141                 :            :     /* Sequence number is alternating 0x55 and 0xaa. */
+     142         [ #  # ]:          0 :     for (int index = 4; index < 4 + PARTIAL_SEQ_NUM_SIZE; index++) {
+     143         [ #  # ]:          0 :         if (index % 2 == 0) {
+     144                 :          0 :             assert_int_equal(0x55, m_secured_message[index]);
+     145                 :            :         } else {
+     146                 :          0 :             assert_int_equal(0xaa, m_secured_message[index]);
+     147                 :            :         }
+     148                 :            :     }
+     149                 :            : 
+     150                 :          0 :     assert_int_equal(0x0022, *(uint16_t*)&m_secured_message[4 + PARTIAL_SEQ_NUM_SIZE]);
+     151                 :            : 
+     152                 :          0 :     ptr = (uint8_t *)&m_secured_message + 6 + PARTIAL_SEQ_NUM_SIZE;
+     153                 :            : 
+     154                 :            :     /* Expected values generated from https://tinyurl.com/2amhw53e */
+     155                 :          0 :     uint8_t expected_cipher_text[] = {0x0d, 0xea, 0x75, 0xea, 0xc6, 0x91, 0x37, 0x49, 0x94, 0x97,
+     156                 :            :                                       0x52, 0x63, 0xf8, 0xc0, 0x8f, 0x6c, 0x1a, 0xa4};
+     157                 :          0 :     uint8_t expected_mac[] = {0x0d, 0xcd, 0xb4, 0x8a, 0xd6, 0xfa, 0x24, 0x04, 0x79, 0xd5, 0xd8,
+     158                 :            :                               0xd2, 0xfe, 0x28, 0x19, 0x14};
+     159                 :            : 
+     160                 :          0 :     assert_memory_equal(expected_cipher_text, ptr, sizeof(expected_cipher_text));
+     161                 :          0 :     ptr += sizeof(expected_cipher_text);
+     162                 :          0 :     assert_memory_equal(expected_mac, ptr, sizeof(expected_mac));
+     163                 :            : 
+     164                 :            :     /* Sequence number is incremented by one after operation. */
+     165                 :          0 :     assert_int_equal(0xaa55aa55aa55aa56,
+     166                 :            :                      m_secured_message_context.application_secret.request_data_sequence_number);
+     167                 :          0 : }
+     168                 :            : 
+     169                 :            : /**
+     170                 :            :  * Test 3: Test basic encryption with sequence number set to all zeroes and big endianness.
+     171                 :            :  *         This has the same result as test 1 since the sequence number is all zeroes.
+     172                 :            :  **/
+     173                 :          0 : static void libspdm_test_secured_message_encode_case3(void **state)
+     174                 :            : {
+     175                 :            :     libspdm_return_t status;
+     176                 :            :     uint8_t app_message[16];
+     177                 :          0 :     size_t secured_message_size = sizeof(m_secured_message);
+     178                 :          0 :     const uint32_t session_id = 0x00112233;
+     179                 :            :     uint8_t *ptr;
+     180                 :            : 
+     181                 :          0 :     initialize_secured_message_context();
+     182                 :          0 :     m_secured_message_context.sequence_number_endian =
+     183                 :            :         LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_BIG_DEC_BOTH;
+     184                 :            : 
+     185         [ #  # ]:          0 :     for (uint8_t index = 0; index < 16; index++) {
+     186                 :          0 :         app_message[index] = index;
+     187                 :            :     }
+     188                 :            : 
+     189                 :          0 :     status = libspdm_encode_secured_message(
+     190                 :            :         &m_secured_message_context, session_id, true,
+     191                 :            :         sizeof(app_message), app_message, &secured_message_size, &m_secured_message,
+     192                 :            :         &m_secured_message_callbacks);
+     193                 :            : 
+     194                 :          0 :     assert_int_equal(LIBSPDM_STATUS_SUCCESS, status);
+     195                 :          0 :     assert_memory_equal(&session_id, &m_secured_message, 4);
+     196                 :            : 
+     197                 :            :     /* Sequence number is all zeroes. */
+     198         [ #  # ]:          0 :     for (int index = 4; index < 4 + PARTIAL_SEQ_NUM_SIZE; index++) {
+     199                 :          0 :         assert_int_equal(0, m_secured_message[index]);
+     200                 :            :     }
+     201                 :            : 
+     202                 :          0 :     assert_int_equal(0x0022, *(uint16_t*)&m_secured_message[4 + PARTIAL_SEQ_NUM_SIZE]);
+     203                 :            : 
+     204                 :          0 :     ptr = (uint8_t *)&m_secured_message + 6 + PARTIAL_SEQ_NUM_SIZE;
+     205                 :            : 
+     206                 :            :     /* Expected values generated from https://tinyurl.com/yrx9w78w */
+     207                 :          0 :     uint8_t expected_cipher_text[] = {0x9b, 0xfe, 0xd3, 0xb7, 0x04, 0x3d, 0x32, 0x86, 0x60, 0x3d,
+     208                 :            :                                       0x86, 0x17, 0x33, 0xd6, 0x7f, 0x95, 0x9a, 0x20};
+     209                 :          0 :     uint8_t expected_mac[] = {0x3d, 0x4f, 0xac, 0x58, 0xcb, 0x70, 0x6c, 0xf5, 0xa0, 0x27, 0x0a,
+     210                 :            :                               0xf6, 0x73, 0xf0, 0xfe, 0x36};
+     211                 :            : 
+     212                 :          0 :     assert_memory_equal(expected_cipher_text, ptr, sizeof(expected_cipher_text));
+     213                 :          0 :     ptr += sizeof(expected_cipher_text);
+     214                 :          0 :     assert_memory_equal(expected_mac, ptr, sizeof(expected_mac));
+     215                 :            : 
+     216                 :            :     /* Sequence number is incremented by one after operation. */
+     217                 :          0 :     assert_int_equal(1, m_secured_message_context.application_secret.request_data_sequence_number);
+     218                 :          0 : }
+     219                 :            : 
+     220                 :            : /**
+     221                 :            :  * Test 4: Test basic encryption with sequence number set to alternating zeroes and ones and
+     222                 :            :  *         big endianness.
+     223                 :            :  **/
+     224                 :          0 : static void libspdm_test_secured_message_encode_case4(void **state)
+     225                 :            : {
+     226                 :            :     libspdm_return_t status;
+     227                 :            :     uint8_t app_message[16];
+     228                 :          0 :     size_t secured_message_size = sizeof(m_secured_message);
+     229                 :          0 :     const uint32_t session_id = 0x00112233;
+     230                 :            :     uint8_t *ptr;
+     231                 :            : 
+     232                 :          0 :     initialize_secured_message_context();
+     233                 :          0 :     m_secured_message_context.application_secret.request_data_sequence_number = 0xaa55aa55aa55aa55;
+     234                 :          0 :     m_secured_message_context.sequence_number_endian =
+     235                 :            :         LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_BIG_DEC_BOTH;
+     236                 :            : 
+     237         [ #  # ]:          0 :     for (uint8_t index = 0; index < 16; index++) {
+     238                 :          0 :         app_message[index] = index;
+     239                 :            :     }
+     240                 :            : 
+     241                 :          0 :     status = libspdm_encode_secured_message(
+     242                 :            :         &m_secured_message_context, session_id, true,
+     243                 :            :         sizeof(app_message), app_message, &secured_message_size, &m_secured_message,
+     244                 :            :         &m_secured_message_callbacks);
+     245                 :            : 
+     246                 :          0 :     assert_int_equal(LIBSPDM_STATUS_SUCCESS, status);
+     247                 :          0 :     assert_memory_equal(&session_id, &m_secured_message, 4);
+     248                 :            : 
+     249                 :            :     /* Sequence number is alternating 0x55 and 0xaa. */
+     250         [ #  # ]:          0 :     for (int index = 4; index < 4 + PARTIAL_SEQ_NUM_SIZE; index++) {
+     251         [ #  # ]:          0 :         if (index % 2 == 0) {
+     252                 :          0 :             assert_int_equal(0x55, m_secured_message[index]);
+     253                 :            :         } else {
+     254                 :          0 :             assert_int_equal(0xaa, m_secured_message[index]);
+     255                 :            :         }
+     256                 :            :     }
+     257                 :            : 
+     258                 :          0 :     assert_int_equal(0x0022, *(uint16_t*)&m_secured_message[4 + PARTIAL_SEQ_NUM_SIZE]);
+     259                 :            : 
+     260                 :          0 :     ptr = (uint8_t *)&m_secured_message + 6 + PARTIAL_SEQ_NUM_SIZE;
+     261                 :            : 
+     262                 :            :     /* Expected values generated from https://tinyurl.com/azaw5bab */
+     263                 :          0 :     uint8_t expected_cipher_text[] = {0xf6, 0x4d, 0x6b, 0x94, 0x37, 0x7a, 0x18, 0x61, 0x01, 0xce,
+     264                 :            :                                       0xfe, 0xa0, 0x8d, 0x91, 0x79, 0x8a, 0x89, 0x88};
+     265                 :          0 :     uint8_t expected_mac[] = {0xb6, 0x8e, 0xd3, 0x06, 0x4a, 0x95, 0x70, 0x89, 0xd4, 0xd8, 0xb9,
+     266                 :            :                               0x02, 0x9e, 0x9d, 0x72, 0x0b};
+     267                 :            : 
+     268                 :          0 :     assert_memory_equal(expected_cipher_text, ptr, sizeof(expected_cipher_text));
+     269                 :          0 :     ptr += sizeof(expected_cipher_text);
+     270                 :          0 :     assert_memory_equal(expected_mac, ptr, sizeof(expected_mac));
+     271                 :            : 
+     272                 :            :     /* Sequence number is incremented by one after operation. */
+     273                 :          0 :     assert_int_equal(0xaa55aa55aa55aa56,
+     274                 :            :                      m_secured_message_context.application_secret.request_data_sequence_number);
+     275                 :          0 : }
+     276                 :            : 
+     277                 :            : /**
+     278                 :            :  * Test 5: Test basic decryption with sequence number set to all zeroes and little endianness.
+     279                 :            :  *         This uses the same plaintext as test 1.
+     280                 :            :  **/
+     281                 :          0 : static void libspdm_test_secured_message_encode_case5(void **state)
+     282                 :            : {
+     283                 :            :     libspdm_return_t status;
+     284                 :          0 :     size_t app_message_size = sizeof(m_app_message);
+     285                 :          0 :     void *app_message = m_app_message;
+     286                 :          0 :     const uint32_t session_id = 0x00112233;
+     287                 :            : 
+     288                 :          0 :     uint8_t secured_message[] = {
+     289                 :            :         /* Session id. */
+     290                 :            :         0x33, 0x22, 0x11, 0x00,
+     291                 :            :         /* Sequence number. */
+     292                 :            :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+     293                 :            :         /* Total length. */
+     294                 :            :         0x22, 0x00,
+     295                 :            :         /* Encrypted application data length. */
+     296                 :            :         0x9b, 0xfe,
+     297                 :            :         /* Encrypted application data. */
+     298                 :            :         0xd3, 0xb7, 0x04, 0x3d, 0x32, 0x86, 0x60, 0x3d,
+     299                 :            :         0x86, 0x17, 0x33, 0xd6, 0x7f, 0x95, 0x9a, 0x20,
+     300                 :            :         /* MAC. */
+     301                 :            :         0x3d, 0x4f, 0xac, 0x58, 0xcb, 0x70, 0x6c, 0xf5,
+     302                 :            :         0xa0, 0x27, 0x0a, 0xf6, 0x73, 0xf0, 0xfe, 0x36
+     303                 :            :     };
+     304                 :            : 
+     305                 :          0 :     initialize_secured_message_context();
+     306                 :          0 :     m_secured_message_context.sequence_number_endian =
+     307                 :            :         LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_LITTLE_DEC_LITTLE;
+     308                 :            : 
+     309                 :          0 :     libspdm_copy_mem(m_secured_message, sizeof(m_secured_message),
+     310                 :            :                      secured_message, sizeof(secured_message));
+     311                 :            : 
+     312                 :          0 :     status = libspdm_decode_secured_message(
+     313                 :            :         &m_secured_message_context, session_id, true,
+     314                 :            :         sizeof(m_secured_message), m_secured_message, &app_message_size, &app_message,
+     315                 :            :         &m_secured_message_callbacks);
+     316                 :            : 
+     317                 :          0 :     assert_int_equal(LIBSPDM_STATUS_SUCCESS, status);
+     318                 :            : 
+     319         [ #  # ]:          0 :     for (int index = 0; index < 16; index++) {
+     320                 :          0 :         assert_int_equal(index, ((uint8_t *)app_message)[index]);
+     321                 :            :     }
+     322                 :            : 
+     323                 :            :     /* Sequence number is incremented by one after operation. */
+     324                 :          0 :     assert_int_equal(1, m_secured_message_context.application_secret.request_data_sequence_number);
+     325                 :          0 : }
+     326                 :            : 
+     327                 :            : /**
+     328                 :            :  * Test 6: Test basic decryption with sequence number set to all zeroes and big endianness.
+     329                 :            :  *         This uses the same plaintext as test 1.
+     330                 :            :  **/
+     331                 :          0 : static void libspdm_test_secured_message_encode_case6(void **state)
+     332                 :            : {
+     333                 :            :     libspdm_return_t status;
+     334                 :          0 :     size_t app_message_size = sizeof(m_app_message);
+     335                 :          0 :     void *app_message = m_app_message;
+     336                 :          0 :     const uint32_t session_id = 0x00112233;
+     337                 :            : 
+     338                 :          0 :     uint8_t secured_message[] = {
+     339                 :            :         /* Session id. */
+     340                 :            :         0x33, 0x22, 0x11, 0x00,
+     341                 :            :         /* Sequence number. */
+     342                 :            :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+     343                 :            :         /* Total length. */
+     344                 :            :         0x22, 0x00,
+     345                 :            :         /* Encrypted application data length. */
+     346                 :            :         0x9b, 0xfe,
+     347                 :            :         /* Encrypted application data. */
+     348                 :            :         0xd3, 0xb7, 0x04, 0x3d, 0x32, 0x86, 0x60, 0x3d,
+     349                 :            :         0x86, 0x17, 0x33, 0xd6, 0x7f, 0x95, 0x9a, 0x20,
+     350                 :            :         /* MAC. */
+     351                 :            :         0x3d, 0x4f, 0xac, 0x58, 0xcb, 0x70, 0x6c, 0xf5,
+     352                 :            :         0xa0, 0x27, 0x0a, 0xf6, 0x73, 0xf0, 0xfe, 0x36
+     353                 :            :     };
+     354                 :            : 
+     355                 :          0 :     initialize_secured_message_context();
+     356                 :          0 :     m_secured_message_context.sequence_number_endian =
+     357                 :            :         LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_BIG_DEC_BIG;
+     358                 :            : 
+     359                 :          0 :     libspdm_copy_mem(m_secured_message, sizeof(m_secured_message),
+     360                 :            :                      secured_message, sizeof(secured_message));
+     361                 :            : 
+     362                 :          0 :     status = libspdm_decode_secured_message(
+     363                 :            :         &m_secured_message_context, session_id, true,
+     364                 :            :         sizeof(m_secured_message), m_secured_message, &app_message_size, &app_message,
+     365                 :            :         &m_secured_message_callbacks);
+     366                 :            : 
+     367                 :          0 :     assert_int_equal(LIBSPDM_STATUS_SUCCESS, status);
+     368                 :            : 
+     369         [ #  # ]:          0 :     for (int index = 0; index < 16; index++) {
+     370                 :          0 :         assert_int_equal(index, ((uint8_t *)app_message)[index]);
+     371                 :            :     }
+     372                 :            : 
+     373                 :            :     /* Sequence number is incremented by one after operation. */
+     374                 :          0 :     assert_int_equal(1, m_secured_message_context.application_secret.request_data_sequence_number);
+     375                 :          0 : }
+     376                 :            : 
+     377                 :            : /**
+     378                 :            :  * Test 7: Test try-fail decryption.
+     379                 :            :  *         The message is encrypted with big-endian sequence number but decoder is set to try
+     380                 :            :  *         little-endian first. The first decryption with sequence number == 0 will pass regardless
+     381                 :            :  *         of endianness. Endianness will be detected when sequence number == 1.
+     382                 :            :  *         This uses the same plaintext as test 1.
+     383                 :            :  **/
+     384                 :          0 : static void libspdm_test_secured_message_encode_case7(void **state)
+     385                 :            : {
+     386                 :            :     libspdm_return_t status;
+     387                 :          0 :     size_t app_message_size = sizeof(m_app_message);
+     388                 :          0 :     void *app_message = m_app_message;
+     389                 :          0 :     const uint32_t session_id = 0x00112233;
+     390                 :            : 
+     391                 :          0 :     uint8_t secured_message_0[] = {
+     392                 :            :         /* Session id. */
+     393                 :            :         0x33, 0x22, 0x11, 0x00,
+     394                 :            :         /* Sequence number. */
+     395                 :            :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+     396                 :            :         /* Total length. */
+     397                 :            :         0x22, 0x00,
+     398                 :            :         /* Encrypted application data length. */
+     399                 :            :         0x9b, 0xfe,
+     400                 :            :         /* Encrypted application data. */
+     401                 :            :         0xd3, 0xb7, 0x04, 0x3d, 0x32, 0x86, 0x60, 0x3d,
+     402                 :            :         0x86, 0x17, 0x33, 0xd6, 0x7f, 0x95, 0x9a, 0x20,
+     403                 :            :         /* MAC. */
+     404                 :            :         0x3d, 0x4f, 0xac, 0x58, 0xcb, 0x70, 0x6c, 0xf5,
+     405                 :            :         0xa0, 0x27, 0x0a, 0xf6, 0x73, 0xf0, 0xfe, 0x36
+     406                 :            :     };
+     407                 :            : 
+     408                 :          0 :     initialize_secured_message_context();
+     409                 :          0 :     m_secured_message_context.sequence_number_endian =
+     410                 :            :         LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_LITTLE_DEC_BOTH;
+     411                 :            : 
+     412                 :          0 :     libspdm_copy_mem(m_secured_message, sizeof(m_secured_message),
+     413                 :            :                      secured_message_0, sizeof(secured_message_0));
+     414                 :            : 
+     415                 :          0 :     status = libspdm_decode_secured_message(
+     416                 :            :         &m_secured_message_context, session_id, true,
+     417                 :            :         sizeof(m_secured_message), m_secured_message, &app_message_size, &app_message,
+     418                 :            :         &m_secured_message_callbacks);
+     419                 :            : 
+     420                 :          0 :     assert_int_equal(LIBSPDM_STATUS_SUCCESS, status);
+     421                 :            : 
+     422         [ #  # ]:          0 :     for (int index = 0; index < 16; index++) {
+     423                 :          0 :         assert_int_equal(index, ((uint8_t *)app_message)[index]);
+     424                 :            :     }
+     425                 :            : 
+     426                 :            :     /* Sequence number is incremented by one after operation. */
+     427                 :          0 :     assert_int_equal(0x1,
+     428                 :            :                      m_secured_message_context.application_secret.request_data_sequence_number);
+     429                 :            : 
+     430                 :            :     /* Context should stay undetermined. */
+     431                 :          0 :     assert_int_equal(LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_LITTLE_DEC_BOTH,
+     432                 :            :                      m_secured_message_context.sequence_number_endian);
+     433                 :            : 
+     434                 :            :     /* Increment sequence number to 1. The endianness can now be determined.
+     435                 :            :      * Generated from https://tinyurl.com/yztzj7f4 */
+     436                 :          0 :     uint8_t secured_message_1[] = {
+     437                 :            :         /* Session id. */
+     438                 :            :         0x33, 0x22, 0x11, 0x00,
+     439                 :            :         /* Sequence number. */
+     440                 :            :         0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+     441                 :            :         /* Total length. */
+     442                 :            :         0x22, 0x00,
+     443                 :            :         /* Encrypted application data length. */
+     444                 :            :         0x07, 0x82,
+     445                 :            :         /* Encrypted application data. */
+     446                 :            :         0x8a, 0x2d, 0xb9, 0xbf, 0x37, 0x87, 0x0f, 0xc5,
+     447                 :            :         0xb1, 0xe9, 0xb7, 0x03, 0xee, 0x1d, 0x14, 0xb4,
+     448                 :            :         /* MAC. */
+     449                 :            :         0x50, 0xa1, 0x5c, 0x3e, 0xee, 0x27, 0x8f, 0xed,
+     450                 :            :         0xed, 0xa6, 0x86, 0xaf, 0x31, 0x07, 0xd8, 0x6f
+     451                 :            :     };
+     452                 :            : 
+     453                 :          0 :     libspdm_copy_mem(m_secured_message, sizeof(m_secured_message),
+     454                 :            :                      secured_message_1, sizeof(secured_message_1));
+     455                 :            : 
+     456                 :          0 :     app_message_size = sizeof(m_app_message);
+     457                 :          0 :     app_message = m_app_message;
+     458                 :            : 
+     459                 :          0 :     status = libspdm_decode_secured_message(
+     460                 :            :         &m_secured_message_context, session_id, true,
+     461                 :            :         sizeof(m_secured_message), m_secured_message, &app_message_size, &app_message,
+     462                 :            :         &m_secured_message_callbacks);
+     463                 :            : 
+     464                 :          0 :     assert_int_equal(LIBSPDM_STATUS_SUCCESS, status);
+     465                 :            : 
+     466         [ #  # ]:          0 :     for (int index = 0; index < 16; index++) {
+     467                 :          0 :         assert_int_equal(index, ((uint8_t *)app_message)[index]);
+     468                 :            :     }
+     469                 :            : 
+     470                 :            :     /* Sequence number is incremented by one after operation. */
+     471                 :          0 :     assert_int_equal(0x2,
+     472                 :            :                      m_secured_message_context.application_secret.request_data_sequence_number);
+     473                 :            : 
+     474                 :            :     /* Context should change to big-endian only. */
+     475                 :          0 :     assert_int_equal(LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_BIG_DEC_BIG,
+     476                 :            :                      m_secured_message_context.sequence_number_endian);
+     477                 :          0 : }
+     478                 :            : 
+     479                 :            : /**
+     480                 :            :  * Test 8: Test try-fail decryption.
+     481                 :            :  *         The message is encrypted with little-endian sequence number but decoder is set to try
+     482                 :            :  *         big-endian first. The first decryption with sequence number == 0 will pass regardless
+     483                 :            :  *         of endianness. Endianness will be detected when sequence number == 1.
+     484                 :            :  *         This uses the same plaintext as test 1.
+     485                 :            :  **/
+     486                 :          0 : static void libspdm_test_secured_message_encode_case8(void **state)
+     487                 :            : {
+     488                 :            :     libspdm_return_t status;
+     489                 :          0 :     size_t app_message_size = sizeof(m_app_message);
+     490                 :          0 :     void *app_message = m_app_message;
+     491                 :          0 :     const uint32_t session_id = 0x00112233;
+     492                 :            : 
+     493                 :          0 :     uint8_t secured_message_0[] = {
+     494                 :            :         /* Session id. */
+     495                 :            :         0x33, 0x22, 0x11, 0x00,
+     496                 :            :         /* Sequence number. */
+     497                 :            :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+     498                 :            :         /* Total length. */
+     499                 :            :         0x22, 0x00,
+     500                 :            :         /* Encrypted application data length. */
+     501                 :            :         0x9b, 0xfe,
+     502                 :            :         /* Encrypted application data. */
+     503                 :            :         0xd3, 0xb7, 0x04, 0x3d, 0x32, 0x86, 0x60, 0x3d,
+     504                 :            :         0x86, 0x17, 0x33, 0xd6, 0x7f, 0x95, 0x9a, 0x20,
+     505                 :            :         /* MAC. */
+     506                 :            :         0x3d, 0x4f, 0xac, 0x58, 0xcb, 0x70, 0x6c, 0xf5,
+     507                 :            :         0xa0, 0x27, 0x0a, 0xf6, 0x73, 0xf0, 0xfe, 0x36
+     508                 :            :     };
+     509                 :            : 
+     510                 :          0 :     initialize_secured_message_context();
+     511                 :          0 :     m_secured_message_context.sequence_number_endian =
+     512                 :            :         LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_BIG_DEC_BOTH;
+     513                 :            : 
+     514                 :          0 :     libspdm_copy_mem(m_secured_message, sizeof(m_secured_message),
+     515                 :            :                      secured_message_0, sizeof(secured_message_0));
+     516                 :            : 
+     517                 :          0 :     status = libspdm_decode_secured_message(
+     518                 :            :         &m_secured_message_context, session_id, true,
+     519                 :            :         sizeof(m_secured_message), m_secured_message, &app_message_size, &app_message,
+     520                 :            :         &m_secured_message_callbacks);
+     521                 :            : 
+     522                 :          0 :     assert_int_equal(LIBSPDM_STATUS_SUCCESS, status);
+     523                 :            : 
+     524         [ #  # ]:          0 :     for (int index = 0; index < 16; index++) {
+     525                 :          0 :         assert_int_equal(index, ((uint8_t *)app_message)[index]);
+     526                 :            :     }
+     527                 :            : 
+     528                 :            :     /* Sequence number is incremented by one after operation. */
+     529                 :          0 :     assert_int_equal(0x1,
+     530                 :            :                      m_secured_message_context.application_secret.request_data_sequence_number);
+     531                 :            : 
+     532                 :            :     /* Context should stay undetermined. */
+     533                 :          0 :     assert_int_equal(LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_BIG_DEC_BOTH,
+     534                 :            :                      m_secured_message_context.sequence_number_endian);
+     535                 :            : 
+     536                 :            :     /* Increment sequence number to 1. The endianness can now be determined. */
+     537                 :          0 :     uint8_t secured_message_1[] = {
+     538                 :            :         /* Session id. */
+     539                 :            :         0x33, 0x22, 0x11, 0x00,
+     540                 :            :         /* Sequence number. */
+     541                 :            :         0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+     542                 :            :         /* Total length. */
+     543                 :            :         0x22, 0x00,
+     544                 :            :         /* Encrypted application data length. */
+     545                 :            :         0xf4, 0x19,
+     546                 :            :         /* Encrypted application data. */
+     547                 :            :         0x96, 0xdc, 0xc6, 0x78, 0x5e, 0x8c, 0x74, 0x72,
+     548                 :            :         0x59, 0xf4, 0x27, 0x22, 0xb9, 0x1b, 0x1f, 0x56,
+     549                 :            :         /* MAC. */
+     550                 :            :         0x1d, 0xca, 0x9f, 0x09, 0xd8, 0x80, 0x3a, 0x9a,
+     551                 :            :         0x54, 0x8e, 0xf0, 0x9b, 0x53, 0xb9, 0xab, 0x1f
+     552                 :            :     };
+     553                 :            : 
+     554                 :          0 :     libspdm_copy_mem(m_secured_message, sizeof(m_secured_message),
+     555                 :            :                      secured_message_1, sizeof(secured_message_1));
+     556                 :            : 
+     557                 :          0 :     app_message_size = sizeof(m_app_message);
+     558                 :          0 :     app_message = m_app_message;
+     559                 :            : 
+     560                 :          0 :     status = libspdm_decode_secured_message(
+     561                 :            :         &m_secured_message_context, session_id, true,
+     562                 :            :         sizeof(m_secured_message), m_secured_message, &app_message_size, &app_message,
+     563                 :            :         &m_secured_message_callbacks);
+     564                 :            : 
+     565                 :          0 :     assert_int_equal(LIBSPDM_STATUS_SUCCESS, status);
+     566                 :            : 
+     567         [ #  # ]:          0 :     for (int index = 0; index < 16; index++) {
+     568                 :          0 :         assert_int_equal(index, ((uint8_t *)app_message)[index]);
+     569                 :            :     }
+     570                 :            : 
+     571                 :            :     /* Sequence number is incremented by one after operation. */
+     572                 :          0 :     assert_int_equal(0x2,
+     573                 :            :                      m_secured_message_context.application_secret.request_data_sequence_number);
+     574                 :            : 
+     575                 :            :     /* Context should change to little-endian only. */
+     576                 :          0 :     assert_int_equal(LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_LITTLE_DEC_LITTLE,
+     577                 :            :                      m_secured_message_context.sequence_number_endian);
+     578                 :          0 : }
+     579                 :            : 
+     580                 :            : /**
+     581                 :            :  * Test 9: Test basic encryption with sequence number set to alternating zeroes and ones
+     582                 :            :  *         encode :  little endianness.
+     583                 :            :  *         decode :  little endianness.
+     584                 :            :  **/
+     585                 :          0 : static void libspdm_test_secured_message_encode_case9(void **state) {
+     586                 :            :     libspdm_return_t status;
+     587                 :            :     uint8_t encode_app_message[16];
+     588                 :          0 :     size_t secured_message_size = sizeof(m_secured_message);
+     589                 :            :     libspdm_secured_message_context_t encode_secured_message_context;
+     590                 :            : 
+     591                 :          0 :     const uint32_t session_id = 0x00112233;
+     592                 :            : 
+     593                 :          0 :     initialize_secured_message_context();
+     594                 :          0 :     libspdm_copy_mem(&encode_secured_message_context, sizeof(encode_secured_message_context),
+     595                 :            :                      &m_secured_message_context, sizeof(m_secured_message_context));
+     596                 :          0 :     m_secured_message_context.sequence_number_endian =
+     597                 :            :         LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_LITTLE_DEC_BOTH;
+     598                 :          0 :     encode_secured_message_context.application_secret.request_data_sequence_number =
+     599                 :            :         0xaa55aa55aa55aa55;
+     600                 :            : 
+     601         [ #  # ]:          0 :     for (uint8_t index = 0; index < 16; index++) {
+     602                 :          0 :         encode_app_message[index] = index;
+     603                 :            :     }
+     604                 :            : 
+     605                 :          0 :     libspdm_zero_mem(m_secured_message, sizeof(m_secured_message));
+     606                 :          0 :     status = libspdm_encode_secured_message(
+     607                 :            :         &encode_secured_message_context, session_id, true,
+     608                 :            :         sizeof(encode_app_message), encode_app_message, &secured_message_size, m_secured_message,
+     609                 :            :         &m_secured_message_callbacks);
+     610                 :            : 
+     611                 :          0 :     assert_int_equal(LIBSPDM_STATUS_SUCCESS, status);
+     612                 :          0 :     assert_memory_equal(&session_id, m_secured_message, 4);
+     613                 :            : 
+     614                 :            :     /* Sequence number is alternating 0x55 and 0xaa. */
+     615         [ #  # ]:          0 :     for (int index = 4; index < 4 + PARTIAL_SEQ_NUM_SIZE; index++) {
+     616         [ #  # ]:          0 :         if (index % 2 == 0) {
+     617                 :          0 :             assert_int_equal(0x55, m_secured_message[index]);
+     618                 :            :         } else {
+     619                 :          0 :             assert_int_equal(0xaa, m_secured_message[index]);
+     620                 :            :         }
+     621                 :            :     }
+     622                 :            : 
+     623                 :          0 :     assert_int_equal(0x0022, *(uint16_t*)&m_secured_message[4 + PARTIAL_SEQ_NUM_SIZE]);
+     624                 :          0 :     assert_int_equal(0xaa55aa55aa55aa56,
+     625                 :            :                      encode_secured_message_context.application_secret.request_data_sequence_number);
+     626                 :            : 
+     627                 :          0 :     void *decode_app_message = m_app_message;
+     628                 :          0 :     size_t decode_app_message_size = sizeof(m_app_message);
+     629                 :            :     libspdm_secured_message_context_t decode_secured_message_context;
+     630                 :            : 
+     631                 :          0 :     initialize_secured_message_context();
+     632                 :          0 :     libspdm_copy_mem(&decode_secured_message_context, sizeof(decode_secured_message_context),
+     633                 :            :                      &m_secured_message_context, sizeof(m_secured_message_context));
+     634                 :          0 :     decode_secured_message_context.sequence_number_endian =
+     635                 :            :         LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_LITTLE_DEC_LITTLE;
+     636                 :          0 :     decode_secured_message_context.application_secret.request_data_sequence_number =
+     637                 :            :         0xaa55aa55aa55aa55;
+     638                 :            : 
+     639                 :          0 :     status = libspdm_decode_secured_message(
+     640                 :            :         &decode_secured_message_context, session_id, true,
+     641                 :            :         sizeof(m_secured_message), m_secured_message, &decode_app_message_size, &decode_app_message,
+     642                 :            :         &m_secured_message_callbacks);
+     643                 :            : 
+     644                 :          0 :     assert_int_equal(LIBSPDM_STATUS_SUCCESS, status);
+     645                 :            : 
+     646         [ #  # ]:          0 :     for (int index = 0; index < 16; index++) {
+     647                 :          0 :         assert_int_equal(index, ((uint8_t *)decode_app_message)[index]);
+     648                 :            :     }
+     649                 :            : 
+     650                 :            :     /* Sequence number is incremented by one after operation. */
+     651                 :          0 :     assert_int_equal(0xaa55aa55aa55aa56,
+     652                 :            :                      decode_secured_message_context.application_secret.request_data_sequence_number);
+     653                 :          0 : }
+     654                 :            : 
+     655                 :            : /**
+     656                 :            :  * Test 10: Test basic encryption with sequence number one and little endianness.
+     657                 :            :  *          encode : big endianness.
+     658                 :            :  *          decode : little endianness.
+     659                 :            :  **/
+     660                 :          0 : static void libspdm_test_secured_message_encode_case10(void **state)
+     661                 :            : {
+     662                 :            :     libspdm_return_t status;
+     663                 :            :     uint8_t encode_app_message[16];
+     664                 :          0 :     size_t secured_message_size = sizeof(m_secured_message);
+     665                 :            :     libspdm_secured_message_context_t encode_secured_message_context;
+     666                 :            : 
+     667                 :          0 :     const uint32_t session_id = 0x00112233;
+     668                 :            : 
+     669                 :          0 :     initialize_secured_message_context();
+     670                 :          0 :     libspdm_copy_mem(&encode_secured_message_context, sizeof(encode_secured_message_context),
+     671                 :            :                      &m_secured_message_context, sizeof(m_secured_message_context));
+     672                 :            : 
+     673                 :          0 :     encode_secured_message_context.sequence_number_endian =
+     674                 :            :         LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_BIG_DEC_BOTH;
+     675                 :          0 :     encode_secured_message_context.application_secret.request_data_sequence_number =
+     676                 :            :         0x0000000000000001;
+     677                 :            : 
+     678         [ #  # ]:          0 :     for (uint8_t index = 0; index < 16; index++) {
+     679                 :          0 :         encode_app_message[index] = index;
+     680                 :            :     }
+     681                 :            : 
+     682                 :          0 :     libspdm_zero_mem(m_secured_message, sizeof(m_secured_message));
+     683                 :          0 :     status = libspdm_encode_secured_message(
+     684                 :            :         &encode_secured_message_context, session_id, true,
+     685                 :            :         sizeof(encode_app_message), encode_app_message, &secured_message_size, m_secured_message,
+     686                 :            :         &m_secured_message_callbacks);
+     687                 :            : 
+     688                 :          0 :     assert_int_equal(LIBSPDM_STATUS_SUCCESS, status);
+     689                 :          0 :     assert_memory_equal(&session_id, m_secured_message, 4);
+     690                 :            : 
+     691         [ #  # ]:          0 :     for (int index = 4; index < 4 + PARTIAL_SEQ_NUM_SIZE; index++) {
+     692         [ #  # ]:          0 :         if (index == 4) {
+     693                 :          0 :             assert_int_equal(0x01, m_secured_message[index]);
+     694                 :            :         } else {
+     695                 :          0 :             assert_int_equal(0x00, m_secured_message[index]);
+     696                 :            :         }
+     697                 :            :     }
+     698                 :            : 
+     699                 :          0 :     assert_int_equal(0x0022, *(uint16_t*)&m_secured_message[4 + PARTIAL_SEQ_NUM_SIZE]);
+     700                 :          0 :     assert_int_equal(0x000000000000002,
+     701                 :            :                      encode_secured_message_context.application_secret.request_data_sequence_number);
+     702                 :            : 
+     703                 :          0 :     void *decode_app_message = m_app_message;
+     704                 :          0 :     size_t decode_app_message_size = sizeof(m_app_message);
+     705                 :            :     libspdm_secured_message_context_t decode_secured_message_context;
+     706                 :            : 
+     707                 :          0 :     libspdm_copy_mem(&decode_secured_message_context, sizeof(decode_secured_message_context),
+     708                 :            :                      &m_secured_message_context, sizeof(m_secured_message_context));
+     709                 :          0 :     decode_secured_message_context.application_secret.request_data_sequence_number =
+     710                 :            :         0x0000000000000001;
+     711                 :          0 :     decode_secured_message_context.sequence_number_endian =
+     712                 :            :         LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_LITTLE_DEC_BOTH;
+     713                 :            : 
+     714                 :          0 :     status = libspdm_decode_secured_message(
+     715                 :            :         &decode_secured_message_context, session_id, true,
+     716                 :            :         sizeof(m_secured_message), m_secured_message, &decode_app_message_size, &decode_app_message,
+     717                 :            :         &m_secured_message_callbacks);
+     718                 :            : 
+     719                 :          0 :     assert_int_equal(LIBSPDM_STATUS_SUCCESS, status);
+     720                 :            : 
+     721         [ #  # ]:          0 :     for (int index = 0; index < 16; index++) {
+     722                 :          0 :         assert_int_equal(index, ((uint8_t *)decode_app_message)[index]);
+     723                 :            :     }
+     724                 :            : 
+     725                 :            :     /* Sequence number is incremented by one after operation. */
+     726                 :          0 :     assert_int_equal(0x0000000000000002,
+     727                 :            :                      decode_secured_message_context.application_secret.request_data_sequence_number);
+     728                 :          0 : }
+     729                 :            : 
+     730                 :            : /**
+     731                 :            :  * Test 11: Test a message authentication only session with the sequence number set to zeroes and ones.
+     732                 :            :  *          encode :  big endianness.
+     733                 :            :  *          decode :  big endianness.
+     734                 :            :  **/
+     735                 :          0 : static void libspdm_test_secured_message_encode_case11(void **state)
+     736                 :            : {
+     737                 :            :     libspdm_return_t status;
+     738                 :            :     uint8_t encode_app_message[16];
+     739                 :          0 :     size_t secured_message_size = sizeof(m_secured_message);
+     740                 :            :     libspdm_secured_message_context_t encode_secured_message_context;
+     741                 :            : 
+     742                 :          0 :     const uint32_t session_id = 0x00112233;
+     743                 :            :     uint8_t *ptr;
+     744                 :            : 
+     745                 :          0 :     initialize_secured_message_context();
+     746                 :          0 :     libspdm_copy_mem(&encode_secured_message_context, sizeof(encode_secured_message_context),
+     747                 :            :                      &m_secured_message_context, sizeof(encode_secured_message_context));
+     748                 :            : 
+     749                 :          0 :     encode_secured_message_context.sequence_number_endian =
+     750                 :            :         LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_BIG_DEC_BOTH;
+     751                 :          0 :     encode_secured_message_context.session_type = LIBSPDM_SESSION_TYPE_MAC_ONLY;
+     752                 :          0 :     encode_secured_message_context.application_secret.request_data_sequence_number =
+     753                 :            :         0xaa55aa55aa55aa55;
+     754                 :            : 
+     755         [ #  # ]:          0 :     for (uint8_t index = 0; index < 16; index++) {
+     756                 :          0 :         encode_app_message[index] = index;
+     757                 :            :     }
+     758                 :            : 
+     759                 :          0 :     libspdm_zero_mem(m_secured_message, sizeof(m_secured_message));
+     760                 :          0 :     status = libspdm_encode_secured_message(
+     761                 :            :         &encode_secured_message_context, session_id, true,
+     762                 :            :         sizeof(encode_app_message), encode_app_message, &secured_message_size, m_secured_message,
+     763                 :            :         &m_secured_message_callbacks);
+     764                 :            : 
+     765                 :          0 :     assert_int_equal(LIBSPDM_STATUS_SUCCESS, status);
+     766                 :          0 :     assert_memory_equal(&session_id, m_secured_message, 4);
+     767                 :            : 
+     768                 :            :     /* Sequence number is alternating 0x55 and 0xaa. */
+     769         [ #  # ]:          0 :     for (int index = 4; index < 4 + PARTIAL_SEQ_NUM_SIZE; index++) {
+     770         [ #  # ]:          0 :         if (index % 2 == 0) {
+     771                 :          0 :             assert_int_equal(0x55, m_secured_message[index]);
+     772                 :            :         } else {
+     773                 :          0 :             assert_int_equal(0xaa, m_secured_message[index]);
+     774                 :            :         }
+     775                 :            :     }
+     776                 :            : 
+     777                 :          0 :     assert_int_equal(0x0020, *(uint16_t*)&m_secured_message[4 + PARTIAL_SEQ_NUM_SIZE]);
+     778                 :          0 :     assert_int_equal(0xaa55aa55aa55aa56,
+     779                 :            :                      encode_secured_message_context.application_secret.request_data_sequence_number);
+     780                 :            : 
+     781                 :          0 :     ptr = (uint8_t *)&m_secured_message + 6 + PARTIAL_SEQ_NUM_SIZE;
+     782         [ #  # ]:          0 :     for (int index = 0; index < 16; index++) {
+     783                 :          0 :         assert_int_equal(index, ((uint8_t *)ptr)[index]);
+     784                 :            :     }
+     785                 :            : 
+     786                 :          0 :     void *decode_app_message = m_app_message;
+     787                 :          0 :     size_t decode_app_message_size = sizeof(m_app_message);
+     788                 :            :     libspdm_secured_message_context_t decode_secured_message_context;
+     789                 :          0 :     libspdm_copy_mem(
+     790                 :            :         &decode_secured_message_context, sizeof(encode_secured_message_context),
+     791                 :            :         &m_secured_message_context, sizeof(m_secured_message_context));
+     792                 :            : 
+     793                 :          0 :     decode_secured_message_context.sequence_number_endian =
+     794                 :            :         LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_BIG_DEC_BOTH;
+     795                 :          0 :     decode_secured_message_context.session_type = LIBSPDM_SESSION_TYPE_MAC_ONLY;
+     796                 :          0 :     decode_secured_message_context.application_secret.request_data_sequence_number =
+     797                 :            :         0xaa55aa55aa55aa55;
+     798                 :            : 
+     799                 :          0 :     status = libspdm_decode_secured_message(
+     800                 :            :         &decode_secured_message_context, session_id, true,
+     801                 :            :         sizeof(m_secured_message), m_secured_message, &decode_app_message_size, &decode_app_message,
+     802                 :            :         &m_secured_message_callbacks);
+     803                 :            : 
+     804                 :          0 :     assert_int_equal(LIBSPDM_STATUS_SUCCESS, status);
+     805                 :            : 
+     806         [ #  # ]:          0 :     for (int index = 0; index < 16; index++) {
+     807                 :          0 :         assert_int_equal(index, ((uint8_t *)decode_app_message)[index]);
+     808                 :            :     }
+     809                 :            : 
+     810                 :            :     /* Sequence number is incremented by one after operation. */
+     811                 :          0 :     assert_int_equal(0xaa55aa55aa55aa56,
+     812                 :            :                      decode_secured_message_context.application_secret.request_data_sequence_number);
+     813                 :          0 : }
+     814                 :            : 
+     815                 :            : /**
+     816                 :            :  * Test 12: Test a message authentication only session with the sequence number one.
+     817                 :            :  *          encode :  little endianness.
+     818                 :            :  *          decode :  big endianness.
+     819                 :            :  **/
+     820                 :          0 : static void libspdm_test_secured_message_encode_case12(void **state)
+     821                 :            : {
+     822                 :            :     libspdm_return_t status;
+     823                 :            :     uint8_t encode_app_message[16];
+     824                 :          0 :     size_t secured_message_size = sizeof(m_secured_message);
+     825                 :            :     libspdm_secured_message_context_t encode_secured_message_context;
+     826                 :            : 
+     827                 :          0 :     const uint32_t session_id = 0x00112233;
+     828                 :            :     uint8_t *ptr;
+     829                 :            : 
+     830                 :          0 :     initialize_secured_message_context();
+     831                 :          0 :     libspdm_copy_mem(&encode_secured_message_context, sizeof(encode_secured_message_context),
+     832                 :            :                      &m_secured_message_context, sizeof(encode_secured_message_context));
+     833                 :            : 
+     834                 :          0 :     encode_secured_message_context.sequence_number_endian =
+     835                 :            :         LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_LITTLE_DEC_BOTH;
+     836                 :          0 :     encode_secured_message_context.session_type = LIBSPDM_SESSION_TYPE_MAC_ONLY;
+     837                 :          0 :     encode_secured_message_context.application_secret.request_data_sequence_number =
+     838                 :            :         0x0000000000000001;
+     839                 :            : 
+     840         [ #  # ]:          0 :     for (uint8_t index = 0; index < 16; index++) {
+     841                 :          0 :         encode_app_message[index] = index;
+     842                 :            :     }
+     843                 :            : 
+     844                 :          0 :     libspdm_zero_mem(m_secured_message, sizeof(m_secured_message));
+     845                 :          0 :     status = libspdm_encode_secured_message(
+     846                 :            :         &encode_secured_message_context, session_id, true,
+     847                 :            :         sizeof(encode_app_message), encode_app_message, &secured_message_size, m_secured_message,
+     848                 :            :         &m_secured_message_callbacks);
+     849                 :            : 
+     850                 :          0 :     assert_int_equal(LIBSPDM_STATUS_SUCCESS, status);
+     851                 :          0 :     assert_memory_equal(&session_id, m_secured_message, 4);
+     852                 :            : 
+     853                 :            :     /* Sequence number is alternating 0x55 and 0xaa. */
+     854         [ #  # ]:          0 :     for (int index = 4; index < 4 + PARTIAL_SEQ_NUM_SIZE; index++) {
+     855         [ #  # ]:          0 :         if (index == 4) {
+     856                 :          0 :             assert_int_equal(0x01, m_secured_message[index]);
+     857                 :            :         } else {
+     858                 :          0 :             assert_int_equal(0x00, m_secured_message[index]);
+     859                 :            :         }
+     860                 :            :     }
+     861                 :            : 
+     862                 :          0 :     assert_int_equal(0x0020, *(uint16_t*)&m_secured_message[4 + PARTIAL_SEQ_NUM_SIZE]);
+     863                 :          0 :     assert_int_equal(0x0000000000000002,
+     864                 :            :                      encode_secured_message_context.application_secret.request_data_sequence_number);
+     865                 :            : 
+     866                 :          0 :     ptr = (uint8_t *)&m_secured_message + 6 + PARTIAL_SEQ_NUM_SIZE;
+     867         [ #  # ]:          0 :     for (int index = 0; index < 16; index++) {
+     868                 :          0 :         assert_int_equal(index, ((uint8_t *)ptr)[index]);
+     869                 :            :     }
+     870                 :            : 
+     871                 :          0 :     void *decode_app_message = m_app_message;
+     872                 :          0 :     size_t decode_app_message_size = sizeof(m_app_message);
+     873                 :            :     libspdm_secured_message_context_t decode_secured_message_context;
+     874                 :          0 :     libspdm_copy_mem(
+     875                 :            :         &decode_secured_message_context, sizeof(encode_secured_message_context),
+     876                 :            :         &m_secured_message_context, sizeof(m_secured_message_context));
+     877                 :            : 
+     878                 :          0 :     decode_secured_message_context.sequence_number_endian =
+     879                 :            :         LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_BIG_DEC_BOTH;
+     880                 :          0 :     decode_secured_message_context.session_type = LIBSPDM_SESSION_TYPE_MAC_ONLY;
+     881                 :          0 :     decode_secured_message_context.application_secret.request_data_sequence_number =
+     882                 :            :         0x0000000000000001;
+     883                 :            : 
+     884                 :          0 :     status = libspdm_decode_secured_message(
+     885                 :            :         &decode_secured_message_context, session_id, true,
+     886                 :            :         sizeof(m_secured_message), m_secured_message, &decode_app_message_size, &decode_app_message,
+     887                 :            :         &m_secured_message_callbacks);
+     888                 :            : 
+     889                 :          0 :     assert_int_equal(LIBSPDM_STATUS_SUCCESS, status);
+     890                 :            : 
+     891         [ #  # ]:          0 :     for (int index = 0; index < 16; index++) {
+     892                 :          0 :         assert_int_equal(index, ((uint8_t *)decode_app_message)[index]);
+     893                 :            :     }
+     894                 :            : 
+     895                 :            :     /* Sequence number is incremented by one after operation. */
+     896                 :          0 :     assert_int_equal(0x0000000000000002,
+     897                 :            :                      decode_secured_message_context.application_secret.request_data_sequence_number);
+     898                 :          0 : }
+     899                 :            : 
+     900                 :            : libspdm_test_context_t m_libspdm_common_context_data_test_context = {
+     901                 :            :     LIBSPDM_TEST_CONTEXT_VERSION,
+     902                 :            :     true,
+     903                 :            :     NULL,
+     904                 :            :     NULL,
+     905                 :            : };
+     906                 :            : 
+     907                 :          0 : int libspdm_secured_message_encode_decode_test_main(void)
+     908                 :            : {
+     909                 :          0 :     const struct CMUnitTest spdm_secured_message_encode_decode_tests[] = {
+     910                 :            :         cmocka_unit_test(libspdm_test_secured_message_encode_case1),
+     911                 :            :         cmocka_unit_test(libspdm_test_secured_message_encode_case2),
+     912                 :            :         cmocka_unit_test(libspdm_test_secured_message_encode_case3),
+     913                 :            :         cmocka_unit_test(libspdm_test_secured_message_encode_case4),
+     914                 :            :         cmocka_unit_test(libspdm_test_secured_message_encode_case5),
+     915                 :            :         cmocka_unit_test(libspdm_test_secured_message_encode_case6),
+     916                 :            :         cmocka_unit_test(libspdm_test_secured_message_encode_case7),
+     917                 :            :         cmocka_unit_test(libspdm_test_secured_message_encode_case8),
+     918                 :            :         cmocka_unit_test(libspdm_test_secured_message_encode_case9),
+     919                 :            :         cmocka_unit_test(libspdm_test_secured_message_encode_case10),
+     920                 :            :         cmocka_unit_test(libspdm_test_secured_message_encode_case11),
+     921                 :            :         cmocka_unit_test(libspdm_test_secured_message_encode_case12),
+     922                 :            :     };
+     923                 :            : 
+     924                 :          0 :     libspdm_setup_test_context(&m_libspdm_common_context_data_test_context);
+     925                 :            : 
+     926                 :          0 :     return cmocka_run_group_tests(spdm_secured_message_encode_decode_tests,
+     927                 :            :                                   libspdm_unit_test_group_setup,
+     928                 :            :                                   libspdm_unit_test_group_teardown);
+     929                 :            : }
+     930                 :            : 
+     931                 :            : #endif /* LIBSPDM_AEAD_AES_256_GCM_SUPPORT */
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_secured_message/index-sort-b.html b/coverage_log/unit_test/test_spdm_secured_message/index-sort-b.html new file mode 100644 index 00000000000..85368b51acf --- /dev/null +++ b/coverage_log/unit_test/test_spdm_secured_message/index-sort-b.html @@ -0,0 +1,119 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_secured_message + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_secured_messageHitTotalCoverage
Test:coverage.infoLines:33340.9 %
Date:2024-09-22 08:21:07Functions:1185.6 %
Branches:0720.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
encode_decode.c +
0.0%
+
0.0 %0 / 3310.0 %0 / 170.0 %0 / 72
test_spdm_secured_message.c +
100.0%
+
100.0 %3 / 3100.0 %1 / 1-0 / 0
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_secured_message/index-sort-f.html b/coverage_log/unit_test/test_spdm_secured_message/index-sort-f.html new file mode 100644 index 00000000000..c3347b73029 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_secured_message/index-sort-f.html @@ -0,0 +1,119 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_secured_message + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_secured_messageHitTotalCoverage
Test:coverage.infoLines:33340.9 %
Date:2024-09-22 08:21:07Functions:1185.6 %
Branches:0720.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
encode_decode.c +
0.0%
+
0.0 %0 / 3310.0 %0 / 170.0 %0 / 72
test_spdm_secured_message.c +
100.0%
+
100.0 %3 / 3100.0 %1 / 1-0 / 0
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_secured_message/index-sort-l.html b/coverage_log/unit_test/test_spdm_secured_message/index-sort-l.html new file mode 100644 index 00000000000..1da25ac2949 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_secured_message/index-sort-l.html @@ -0,0 +1,119 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_secured_message + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_secured_messageHitTotalCoverage
Test:coverage.infoLines:33340.9 %
Date:2024-09-22 08:21:07Functions:1185.6 %
Branches:0720.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
encode_decode.c +
0.0%
+
0.0 %0 / 3310.0 %0 / 170.0 %0 / 72
test_spdm_secured_message.c +
100.0%
+
100.0 %3 / 3100.0 %1 / 1-0 / 0
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_secured_message/index.html b/coverage_log/unit_test/test_spdm_secured_message/index.html new file mode 100644 index 00000000000..453e33117d8 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_secured_message/index.html @@ -0,0 +1,119 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_secured_message + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_secured_messageHitTotalCoverage
Test:coverage.infoLines:33340.9 %
Date:2024-09-22 08:21:07Functions:1185.6 %
Branches:0720.0 %
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Filename Sort by nameLine Coverage Sort by line coverageFunctions Sort by function coverageBranches Sort by branch coverage
encode_decode.c +
0.0%
+
0.0 %0 / 3310.0 %0 / 170.0 %0 / 72
test_spdm_secured_message.c +
100.0%
+
100.0 %3 / 3100.0 %1 / 1-0 / 0
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_secured_message/test_spdm_secured_message.c.func-sort-c.html b/coverage_log/unit_test/test_spdm_secured_message/test_spdm_secured_message.c.func-sort-c.html new file mode 100644 index 00000000000..8667b040ff3 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_secured_message/test_spdm_secured_message.c.func-sort-c.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_secured_message/test_spdm_secured_message.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_secured_message - test_spdm_secured_message.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:33100.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
main1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_secured_message/test_spdm_secured_message.c.func.html b/coverage_log/unit_test/test_spdm_secured_message/test_spdm_secured_message.c.func.html new file mode 100644 index 00000000000..e4b5d7184e5 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_secured_message/test_spdm_secured_message.c.func.html @@ -0,0 +1,85 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_secured_message/test_spdm_secured_message.c - functions + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_secured_message - test_spdm_secured_message.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:33100.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:00-
+
+ +
+ + + + + + + + + + +

Function Name Sort by function nameHit count Sort by hit count
main1
+
+
+ + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/unit_test/test_spdm_secured_message/test_spdm_secured_message.c.gcov.html b/coverage_log/unit_test/test_spdm_secured_message/test_spdm_secured_message.c.gcov.html new file mode 100644 index 00000000000..9990c7d84a4 --- /dev/null +++ b/coverage_log/unit_test/test_spdm_secured_message/test_spdm_secured_message.c.gcov.html @@ -0,0 +1,105 @@ + + + + + + + LCOV - coverage.info - unit_test/test_spdm_secured_message/test_spdm_secured_message.c + + + + + + + + + + + + + + +
LCOV - code coverage report
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Current view:top level - unit_test/test_spdm_secured_message - test_spdm_secured_message.c (source / functions)HitTotalCoverage
Test:coverage.infoLines:33100.0 %
Date:2024-09-22 08:21:07Functions:11100.0 %
Branches:00-
+
+ + + + + + + + +

+
           Branch data     Line data    Source code
+
+       1                 :            : /**
+       2                 :            :  *  Copyright Notice:
+       3                 :            :  *  Copyright 2023 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                 :            : extern int libspdm_secured_message_encode_decode_test_main(void);
+       8                 :            : 
+       9                 :          1 : int main(void)
+      10                 :            : {
+      11                 :          1 :     int return_value = 0;
+      12                 :            : 
+      13                 :            : #if LIBSPDM_AEAD_AES_256_GCM_SUPPORT
+      14                 :            :     if (libspdm_secured_message_encode_decode_test_main() != 0) {
+      15                 :            :         return_value = 1;
+      16                 :            :     }
+      17                 :            : #endif
+      18                 :            : 
+      19                 :          1 :     return return_value;
+      20                 :            : }
+
+
+
+ + + + +
Generated by: LCOV version 1.14
+
+ + + diff --git a/coverage_log/updown.png b/coverage_log/updown.png new file mode 100644 index 0000000000000000000000000000000000000000..aa56a238b3e6c435265250f9266cd1b8caba0f20 GIT binary patch literal 117 zcmeAS@N?(olHy`uVBq!ia0vp^AT}Qd8;}%R+`Ae`*?77*hG?8mPH5^{)z4*}Q$iB}huR`+ literal 0 HcmV?d00001